sl811_cs.c 4.7 KB

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