Advertisement
Guest User

Untitled

a guest
Jan 30th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. #include <linux/module.h>
  2. #include <linux/kernel.h>
  3. #include <linux/types.h>
  4. #include <linux/kdev_t.h>
  5. #include <linux/fs.h>
  6. #include <linux/device.h>
  7. #include <linux/cdev.h>
  8. #include <asm/uaccess.h>
  9.  
  10. #include <linux/init.h>
  11. #include <linux/mutex.h>
  12. #include <linux/slab.h>
  13. #include <linux/string.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16.  
  17. #include <linux/spi/spi.h>
  18. #include <linux/gpio.h>
  19.  
  20. #include "fpgaSPI.h"
  21.  
  22. #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
  23.  
  24. const char this_driver_name[] = "fpgaSPI";
  25.  
  26. struct cardConfig
  27. {
  28.  
  29. int cardPosition;
  30. int readLatch;
  31. int writeLatch;
  32. int bus;
  33. unsigned int interrupt;
  34. unsigned int irq;
  35.  
  36. };
  37.  
  38. static struct cardConfig cards[] =
  39. {
  40.  
  41. {
  42. .cardPosition = 0,
  43. .readLatch = GPIO_TO_PIN(1,16),
  44. .writeLatch = GPIO_TO_PIN(1,17),
  45. .bus = 2,
  46. .interrupt = 60,
  47. },
  48.  
  49. {
  50. .cardPosition = 1,
  51. .readLatch = GPIO_TO_PIN(3,21),
  52. .writeLatch = GPIO_TO_PIN(3,19),
  53. .bus = 2,
  54. },
  55.  
  56. {
  57. .cardPosition = 2,
  58. .readLatch = GPIO_TO_PIN(1,6),
  59. .writeLatch = GPIO_TO_PIN(1,15),
  60. .bus = 1,
  61. },
  62.  
  63. };
  64.  
  65. /****************
  66. * IRQ Handling *
  67. ***************/
  68.  
  69. static irqreturn_t fpgaSPI_irqHandler(int irq, void* devID)
  70. {
  71.  
  72. pr_debug("%s: IRQ: %d\n", __func__, irq);
  73.  
  74. return IRQ_HANDLED;
  75.  
  76. }
  77.  
  78. /*****************************************
  79. * Module Intialisation/Deinitialisation *
  80. *****************************************/
  81.  
  82. static int __init fpgaSPI_init(void)
  83. {
  84.  
  85. unsigned int irq_num;
  86. int status = 0;
  87.  
  88. pr_debug("%s: Inititialising Driver fpgaSPI-v2\n", __func__);
  89.  
  90. status = gpio_request_one(cards[0].interrupt, GPIOF_IN, "Card 0 Interrupt");
  91.  
  92. if (status < 0)
  93. {
  94. pr_debug("%s: Failed to aquire gpio, bailing: -%d\n", __func__, status);
  95. return 0;
  96. }
  97.  
  98. gpio_direction_input(cards[0].interrupt);
  99.  
  100. irq_num = gpio_to_irq(cards[0].interrupt);
  101.  
  102. if (irq_num < 0)
  103. {
  104. pr_debug("%s: Failed to aquire irq_num: -%d\n", __func__, irq_num);
  105. goto err0;
  106. }
  107.  
  108. cards[0].irq = request_irq(irq_num, fpgaSPI_irqHandler, IRQF_SHARED | IRQF_TRIGGER_FALLING, "Card 0 Interrupt IRQ", NULL);
  109.  
  110. if (cards[0].irq < 0)
  111. {
  112. pr_debug("%s: Failed to requst irq: %d\n", __func__, cards[0].irq);
  113. goto err0;
  114. }
  115.  
  116. return 0;
  117.  
  118. err0:
  119. gpio_free(cards[0].interrupt);
  120.  
  121. return 0;
  122.  
  123. }
  124.  
  125. static void __exit fpgaSPI_exit(void)
  126. {
  127.  
  128. gpio_free(cards[0].interrupt);
  129.  
  130. if (cards[0].irq)
  131. {
  132. free_irq(cards[0].irq, NULL);
  133. }
  134.  
  135. pr_debug("%s: Exiting Driver fpgaSPI-v2\n", __func__);
  136.  
  137. }
  138.  
  139. module_init(fpgaSPI_init);
  140. module_exit(fpgaSPI_exit);
  141.  
  142. MODULE_LICENSE("GPL");
  143. MODULE_AUTHOR("Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>");
  144. MODULE_DESCRIPTION("fpgaSPI driver");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement