hawxgamer

Untitled

Nov 10th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <linux/init.h>
  2. #include <linux/module.h>
  3. #include <linux/kernel.h>
  4. #include <linux/ioport.h>
  5. #include <linux/fs.h>
  6. #include <linux/cdev.h>
  7. #include <linux/device.h>
  8. #include <asm/io.h>
  9. #include "gpio_defs.h"
  10. #include "hwaccess.h"
  11.  
  12. MODULE_LICENSE("Dual BSD/GPL");
  13.  
  14.  
  15. static int sample_cdev_open(struct inode *inode, struct file *file) {
  16. printk(KERN_INFO "open sample char device\n");
  17. return 0;
  18. }
  19.  
  20. static int sample_cdev_release(struct inode *inode, struct file *file) {
  21. printk(KERN_INFO "release sample char device\n");
  22. return 0;
  23. }
  24.  
  25. static ssize_t sample_cdev_read(struct file *file, char __user *data, size_t size, loff_t *offset) {
  26. return size;
  27. }
  28.  
  29. static ssize_t sample_cdev_write(struct file *file, const char __user *data, size_t size, loff_t *offset) {
  30. return size;
  31. }
  32.  
  33.  
  34.  
  35. static struct file_operations sample_cdev_fops = {
  36. .owner = THIS_MODULE,
  37. .open = sample_cdev_open,
  38. .release = sample_cdev_release,
  39. .read = sample_cdev_read,
  40. .write = sample_cdev_write,
  41. };
  42.  
  43. static int my_init(void) {
  44. dev_t dev = 0;
  45. int PageSize = 4096;
  46. static struct cdev* sample_cdev;
  47. GpioRegs gpioRegs;
  48.  
  49. printk("<1> Hello world!\n");
  50. if(request_mem_region(GPIO_BASE, sizeof(GpioRegs), "Name") == 0)
  51. {
  52. // goto fail_request_mem_region;
  53. }
  54.  
  55. ioremap_nocache(GPIO_BASE, PageSize);
  56. if (alloc_chrdev_region(&dev,GPIO_FIRST_MINOR,1,"Name") < 0)
  57. {
  58. // goto fail_ioremap_nocache;
  59. }
  60.  
  61.  
  62. sample_cdev = cdev_alloc();
  63. if(!sample_cdev)
  64. {
  65. printk(KERN_ERR "failed to alloc cdev\n");
  66. return 1;
  67. }
  68. cdev_init(sample_cdev, &sample_cdev_fops);
  69.  
  70.  
  71. if(cdev_add(sample_cdev, dev, 1) < 0)
  72. {
  73. printk(KERN_ERR "failed to add cdev\n");
  74. goto fail_add_cdev;
  75. }
  76.  
  77. initLeds(&gpioRegs);
  78. initSwitches(&gpioRegs);
  79. return 0;
  80. /*
  81. fail_ioremap_cache:
  82. //TODO requestregion freigeben
  83. fail_request_region:
  84. return 1;*/
  85. }
  86.  
  87. static void my_exit(void) {
  88. printk("<1> Bye, cruel world\n");
  89. }
  90.  
  91. module_init(my_init);
  92. module_exit(my_exit);
Advertisement
Add Comment
Please, Sign In to add comment