Guest User

uio_fpga.c

a guest
Mar 27th, 2013
2,627
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <linux/kernel.h>
  2. #include <linux/module.h>
  3. #include <linux/platform_device.h>
  4. #include <linux/uio_driver.h>
  5. #include <linux/irq.h>
  6.  
  7. MODULE_LICENSE("GPL");
  8.  
  9. #define SAV_IRQ 91
  10.  
  11. static struct resource uio_resource[] = {
  12.     {
  13.         .start = 0x1f400000,
  14.         .end   = 0x1fffffff,
  15.         .name = "sav_vdma_mem",
  16.         .flags = IORESOURCE_MEM
  17.     },
  18.     {
  19.         .start = 0x43000000,
  20.         .end   = 0x4300ffff,
  21.         .name = "sav_vdma_reg",
  22.         .flags = IORESOURCE_MEM
  23.     },
  24.     {
  25.         .start = 0x62200000,
  26.         .end   = 0x6220ffff,
  27.         .name = "sav_axi_reader",
  28.         .flags = IORESOURCE_MEM
  29.     },
  30.     {
  31.         .start = 0x7B200000,
  32.         .end   = 0x7B20ffff,
  33.         .name = "sav_axi_cfg",
  34.         .flags = IORESOURCE_MEM
  35.     },
  36. };
  37.  
  38.  
  39. static irqreturn_t irq_handler(int irq, struct uio_info *dev_info) {
  40.     switch(irq) {
  41.         case SAV_IRQ:
  42.             return IRQ_HANDLED;
  43.     }
  44.  
  45.     return IRQ_NONE;
  46. }
  47.  
  48.  
  49. static struct uio_info myfpga_uio_info = {
  50.     .name = "uio_fpga",
  51.     .version = "0.1",
  52.     .irq = SAV_IRQ,
  53.     .handler = irq_handler,
  54. };
  55.  
  56.  
  57. static struct platform_device uio_device = {
  58.     .name      = "uio_pdrv",
  59.     .id = -1,
  60.     .resource   = uio_resource,
  61.     .num_resources   = ARRAY_SIZE(uio_resource),
  62.     .dev.platform_data = &myfpga_uio_info,
  63. };
  64.  
  65.  
  66. static int __init mod_init(void)
  67. {
  68.     int ret;
  69.  
  70.     ret = platform_device_register(&uio_device);
  71.     irq_set_irq_type(SAV_IRQ, IRQ_TYPE_EDGE_RISING);
  72.  
  73.     printk(KERN_INFO "UIO Module loaded %d\n", ret);
  74.  
  75.         return 0;
  76. }
  77.  
  78. static void __exit mod_exit(void)
  79. {
  80.     platform_device_unregister(&uio_device);
  81. }
  82.  
  83. module_init(mod_init);
  84. module_exit(mod_exit);
RAW Paste Data