Advertisement
Guest User

Untitled

a guest
Jan 31st, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 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/of.h>
  15.  
  16. #include <linux/interrupt.h>
  17. #include <linux/irq.h>
  18. #include <linux/spi/spi.h>
  19. #include <linux/gpio.h>
  20. #include <linux/pinctrl/consumer.h>
  21.  
  22. #include "r0005spi.h"
  23.  
  24. #define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
  25.  
  26. const char this_driver_name[] = "r0005spi";
  27.  
  28. static int r0005spi_probe(struct spi_device *pdev);
  29. static int r0005spi_remove(struct spi_device *pdev);
  30.  
  31. static const struct of_device_id db_r0005spi_of_ids[] = {
  32. {
  33. .compatible = "dbbroadcast,r0005spi",
  34. },
  35. { },
  36. };
  37. MODULE_DEVICE_TABLE(of, db_r0005spi_of_ids);
  38.  
  39. static struct spi_driver r0005spi_driver =
  40. {
  41. .driver = {
  42. .name = this_driver_name,
  43. .owner = THIS_MODULE,
  44. .of_match_table = db_r0005spi_of_ids,
  45. },
  46. .probe = r0005spi_probe,
  47. .remove = r0005spi_remove,
  48. };
  49.  
  50. static struct card_config cards[] =
  51. {
  52. {
  53. .cardPosition = 0,
  54. .readLatch = GPIO_TO_PIN(1,16),
  55. .writeLatch = GPIO_TO_PIN(1,17),
  56. .bus = 2,
  57. .interrupt = 60,
  58. },
  59. {
  60. .cardPosition = 1,
  61. .readLatch = GPIO_TO_PIN(3,21),
  62. .writeLatch = GPIO_TO_PIN(3,19),
  63. .bus = 2,
  64. },
  65. {
  66. .cardPosition = 2,
  67. .readLatch = GPIO_TO_PIN(1,6),
  68. .writeLatch = GPIO_TO_PIN(1,15),
  69. .bus = 1,
  70. },
  71. };
  72.  
  73. /****************
  74. * IRQ Handling *
  75. ***************/
  76.  
  77. static irqreturn_t r0005spi_irq_handler(int irq, void* devID)
  78. {
  79. pr_debug("%s: IRQ: %d\n", __func__, irq);
  80.  
  81. return IRQ_HANDLED;
  82. }
  83. /***********
  84. * Probing *
  85. * ********/
  86.  
  87. static int r0005spi_probe(struct spi_device *spi)
  88. {
  89. struct device_node *np = spi->dev.of_node;
  90. struct device_node *nc;
  91.  
  92. pr_debug("%s: SPI Bus: %d probed\n", __func__, spi->master->bus_num);
  93.  
  94. if (IS_ERR(np))
  95. {
  96.  
  97. pr_debug("%s: Failed to get parent node\n", __func__);
  98.  
  99. }
  100.  
  101. pr_debug("%s: Got node %s\n", __func__, np->name);
  102.  
  103. for_each_child_of_node(np, nc)
  104. {
  105.  
  106. pr_debug("%s: Found node\n", __func__);
  107.  
  108. }
  109.  
  110. return 0;
  111. }
  112.  
  113. static int r0005spi_remove(struct spi_device *pdev)
  114. {
  115. pr_debug("%s: Removed\n", __func__);
  116.  
  117. return 0;
  118. }
  119.  
  120. /*****************************************
  121. * Module Intialisation/Deinitialisation *
  122. *****************************************/
  123.  
  124. static int r0005spi_init(void)
  125. {
  126. pr_debug("%s: Inititialising Driver r0005spi\n", __func__);
  127. return spi_register_driver(&r0005spi_driver);
  128. }
  129.  
  130. static void r0005spi_exit(void)
  131. {
  132. spi_unregister_driver(&r0005spi_driver);
  133. pr_debug("%s: Exiting Driver r0005spi\n", __func__);
  134. }
  135.  
  136. module_init(r0005spi_init);
  137. module_exit(r0005spi_exit);
  138.  
  139. MODULE_LICENSE("GPL");
  140. MODULE_AUTHOR("Jack Mitchell <jack.mitchell@dbbroadcast.co.uk>");
  141. MODULE_DESCRIPTION("r0005spi driver");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement