sl811_cs.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * PCMCIA driver for SL811HS (as found in REX-CFU1U)
  3. * Filename: sl811_cs.c
  4. * Author: Yukio Yamamoto
  5. *
  6. * Port to sl811-hcd and 2.6.x by
  7. * Botond Botyanszki <boti@rocketmail.com>
  8. * Simon Pickering
  9. *
  10. * Last update: 2005-05-12
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/ptrace.h>
  15. #include <linux/slab.h>
  16. #include <linux/string.h>
  17. #include <linux/timer.h>
  18. #include <linux/ioport.h>
  19. #include <linux/platform_device.h>
  20. #include <pcmcia/cistpl.h>
  21. #include <pcmcia/cisreg.h>
  22. #include <pcmcia/ds.h>
  23. #include <linux/usb/sl811.h>
  24. MODULE_AUTHOR("Botond Botyanszki");
  25. MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
  26. MODULE_LICENSE("GPL");
  27. /*====================================================================*/
  28. /* MACROS */
  29. /*====================================================================*/
  30. #define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
  31. /*====================================================================*/
  32. /* VARIABLES */
  33. /*====================================================================*/
  34. typedef struct local_info_t {
  35. struct pcmcia_device *p_dev;
  36. } local_info_t;
  37. static void sl811_cs_release(struct pcmcia_device * link);
  38. /*====================================================================*/
  39. static void release_platform_dev(struct device * dev)
  40. {
  41. dev_dbg(dev, "sl811_cs platform_dev release\n");
  42. dev->parent = NULL;
  43. }
  44. static struct sl811_platform_data platform_data = {
  45. .potpg = 100,
  46. .power = 50, /* == 100mA */
  47. // .reset = ... FIXME: invoke CF reset on the card
  48. };
  49. static struct resource resources[] = {
  50. [0] = {
  51. .flags = IORESOURCE_IRQ,
  52. },
  53. [1] = {
  54. // .name = "address",
  55. .flags = IORESOURCE_IO,
  56. },
  57. [2] = {
  58. // .name = "data",
  59. .flags = IORESOURCE_IO,
  60. },
  61. };
  62. extern struct platform_driver sl811h_driver;
  63. static struct platform_device platform_dev = {
  64. .id = -1,
  65. .dev = {
  66. .platform_data = &platform_data,
  67. .release = release_platform_dev,
  68. },
  69. .resource = resources,
  70. .num_resources = ARRAY_SIZE(resources),
  71. };
  72. static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
  73. int irq)
  74. {
  75. if (platform_dev.dev.parent)
  76. return -EBUSY;
  77. platform_dev.dev.parent = parent;
  78. /* finish seting up the platform device */
  79. resources[0].start = irq;
  80. resources[1].start = base_addr;
  81. resources[1].end = base_addr;
  82. resources[2].start = base_addr + 1;
  83. resources[2].end = base_addr + 1;
  84. /* The driver core will probe for us. We know sl811-hcd has been
  85. * initialized already because of the link order dependency created
  86. * by referencing "sl811h_driver".
  87. */
  88. platform_dev.name = sl811h_driver.driver.name;
  89. return platform_device_register(&platform_dev);
  90. }
  91. /*====================================================================*/
  92. static void sl811_cs_detach(struct pcmcia_device *link)
  93. {
  94. dev_dbg(&link->dev, "sl811_cs_detach\n");
  95. sl811_cs_release(link);
  96. /* This points to the parent local_info_t struct */
  97. kfree(link->priv);
  98. }
  99. static void sl811_cs_release(struct pcmcia_device * link)
  100. {
  101. dev_dbg(&link->dev, "sl811_cs_release\n");
  102. pcmcia_disable_device(link);
  103. platform_device_unregister(&platform_dev);
  104. }
  105. static int sl811_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
  106. {
  107. if (p_dev->config_index == 0)
  108. return -EINVAL;
  109. return pcmcia_request_io(p_dev);
  110. }
  111. static int sl811_cs_config(struct pcmcia_device *link)
  112. {
  113. struct device *parent = &link->dev;
  114. int ret;
  115. dev_dbg(&link->dev, "sl811_cs_config\n");
  116. link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_VPP |
  117. CONF_AUTO_CHECK_VCC | CONF_AUTO_SET_IO;
  118. if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
  119. goto failed;
  120. /* require an IRQ and two registers */
  121. if (resource_size(link->resource[0]) < 2)
  122. goto failed;
  123. if (!link->irq)
  124. goto failed;
  125. ret = pcmcia_enable_device(link);
  126. if (ret)
  127. goto failed;
  128. if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
  129. < 0) {
  130. failed:
  131. printk(KERN_WARNING "sl811_cs_config failed\n");
  132. sl811_cs_release(link);
  133. return -ENODEV;
  134. }
  135. return 0;
  136. }
  137. static int sl811_cs_probe(struct pcmcia_device *link)
  138. {
  139. local_info_t *local;
  140. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  141. if (!local)
  142. return -ENOMEM;
  143. local->p_dev = link;
  144. link->priv = local;
  145. return sl811_cs_config(link);
  146. }
  147. static const struct pcmcia_device_id sl811_ids[] = {
  148. PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
  149. PCMCIA_DEVICE_NULL,
  150. };
  151. MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
  152. static struct pcmcia_driver sl811_cs_driver = {
  153. .owner = THIS_MODULE,
  154. .name = "sl811_cs",
  155. .probe = sl811_cs_probe,
  156. .remove = sl811_cs_detach,
  157. .id_table = sl811_ids,
  158. };
  159. module_pcmcia_driver(sl811_cs_driver);