sl811_cs.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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/init.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/cs.h>
  22. #include <pcmcia/cistpl.h>
  23. #include <pcmcia/cisreg.h>
  24. #include <pcmcia/ds.h>
  25. #include <linux/usb/sl811.h>
  26. MODULE_AUTHOR("Botond Botyanszki");
  27. MODULE_DESCRIPTION("REX-CFU1U PCMCIA driver for 2.6");
  28. MODULE_LICENSE("GPL");
  29. /*====================================================================*/
  30. /* MACROS */
  31. /*====================================================================*/
  32. #define INFO(args...) printk(KERN_INFO "sl811_cs: " args)
  33. /*====================================================================*/
  34. /* VARIABLES */
  35. /*====================================================================*/
  36. typedef struct local_info_t {
  37. struct pcmcia_device *p_dev;
  38. } local_info_t;
  39. static void sl811_cs_release(struct pcmcia_device * link);
  40. /*====================================================================*/
  41. static void release_platform_dev(struct device * dev)
  42. {
  43. dev_dbg(dev, "sl811_cs platform_dev release\n");
  44. dev->parent = NULL;
  45. }
  46. static struct sl811_platform_data platform_data = {
  47. .potpg = 100,
  48. .power = 50, /* == 100mA */
  49. // .reset = ... FIXME: invoke CF reset on the card
  50. };
  51. static struct resource resources[] = {
  52. [0] = {
  53. .flags = IORESOURCE_IRQ,
  54. },
  55. [1] = {
  56. // .name = "address",
  57. .flags = IORESOURCE_IO,
  58. },
  59. [2] = {
  60. // .name = "data",
  61. .flags = IORESOURCE_IO,
  62. },
  63. };
  64. extern struct platform_driver sl811h_driver;
  65. static struct platform_device platform_dev = {
  66. .id = -1,
  67. .dev = {
  68. .platform_data = &platform_data,
  69. .release = release_platform_dev,
  70. },
  71. .resource = resources,
  72. .num_resources = ARRAY_SIZE(resources),
  73. };
  74. static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
  75. int irq)
  76. {
  77. if (platform_dev.dev.parent)
  78. return -EBUSY;
  79. platform_dev.dev.parent = parent;
  80. /* finish seting up the platform device */
  81. resources[0].start = irq;
  82. resources[1].start = base_addr;
  83. resources[1].end = base_addr;
  84. resources[2].start = base_addr + 1;
  85. resources[2].end = base_addr + 1;
  86. /* The driver core will probe for us. We know sl811-hcd has been
  87. * initialized already because of the link order dependency created
  88. * by referencing "sl811h_driver".
  89. */
  90. platform_dev.name = sl811h_driver.driver.name;
  91. return platform_device_register(&platform_dev);
  92. }
  93. /*====================================================================*/
  94. static void sl811_cs_detach(struct pcmcia_device *link)
  95. {
  96. dev_dbg(&link->dev, "sl811_cs_detach\n");
  97. sl811_cs_release(link);
  98. /* This points to the parent local_info_t struct */
  99. kfree(link->priv);
  100. }
  101. static void sl811_cs_release(struct pcmcia_device * link)
  102. {
  103. dev_dbg(&link->dev, "sl811_cs_release\n");
  104. pcmcia_disable_device(link);
  105. platform_device_unregister(&platform_dev);
  106. }
  107. static int sl811_cs_config_check(struct pcmcia_device *p_dev,
  108. cistpl_cftable_entry_t *cfg,
  109. cistpl_cftable_entry_t *dflt,
  110. unsigned int vcc,
  111. void *priv_data)
  112. {
  113. if (cfg->index == 0)
  114. return -ENODEV;
  115. /* Use power settings for Vcc and Vpp if present */
  116. /* Note that the CIS values need to be rescaled */
  117. if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  118. if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
  119. return -ENODEV;
  120. } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  121. if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
  122. return -ENODEV;
  123. }
  124. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  125. p_dev->conf.Vpp =
  126. cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  127. else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
  128. p_dev->conf.Vpp =
  129. dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
  130. /* we need an interrupt */
  131. p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
  132. /* IO window settings */
  133. p_dev->resource[0]->end = p_dev->resource[1]->end = 0;
  134. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  135. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  136. p_dev->io_lines = io->flags & CISTPL_IO_LINES_MASK;
  137. p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
  138. p_dev->resource[0]->start = io->win[0].base;
  139. p_dev->resource[0]->end = io->win[0].len;
  140. return pcmcia_request_io(p_dev);
  141. }
  142. pcmcia_disable_device(p_dev);
  143. return -ENODEV;
  144. }
  145. static int sl811_cs_config(struct pcmcia_device *link)
  146. {
  147. struct device *parent = &link->dev;
  148. int ret;
  149. dev_dbg(&link->dev, "sl811_cs_config\n");
  150. if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
  151. goto failed;
  152. /* require an IRQ and two registers */
  153. if (resource_size(link->resource[0]) < 2)
  154. goto failed;
  155. if (!link->irq)
  156. goto failed;
  157. ret = pcmcia_request_configuration(link, &link->conf);
  158. if (ret)
  159. goto failed;
  160. dev_info(&link->dev, "index 0x%02x: ",
  161. link->conf.ConfigIndex);
  162. if (link->conf.Vpp)
  163. printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
  164. printk(", irq %d", link->irq);
  165. printk(", io %pR", link->resource[0]);
  166. printk("\n");
  167. if (sl811_hc_init(parent, link->resource[0]->start, link->irq)
  168. < 0) {
  169. failed:
  170. printk(KERN_WARNING "sl811_cs_config failed\n");
  171. sl811_cs_release(link);
  172. return -ENODEV;
  173. }
  174. return 0;
  175. }
  176. static int sl811_cs_probe(struct pcmcia_device *link)
  177. {
  178. local_info_t *local;
  179. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  180. if (!local)
  181. return -ENOMEM;
  182. local->p_dev = link;
  183. link->priv = local;
  184. link->conf.Attributes = 0;
  185. link->conf.IntType = INT_MEMORY_AND_IO;
  186. return sl811_cs_config(link);
  187. }
  188. static struct pcmcia_device_id sl811_ids[] = {
  189. PCMCIA_DEVICE_MANF_CARD(0xc015, 0x0001), /* RATOC USB HOST CF+ Card */
  190. PCMCIA_DEVICE_NULL,
  191. };
  192. MODULE_DEVICE_TABLE(pcmcia, sl811_ids);
  193. static struct pcmcia_driver sl811_cs_driver = {
  194. .owner = THIS_MODULE,
  195. .drv = {
  196. .name = "sl811_cs",
  197. },
  198. .probe = sl811_cs_probe,
  199. .remove = sl811_cs_detach,
  200. .id_table = sl811_ids,
  201. };
  202. /*====================================================================*/
  203. static int __init init_sl811_cs(void)
  204. {
  205. return pcmcia_register_driver(&sl811_cs_driver);
  206. }
  207. module_init(init_sl811_cs);
  208. static void __exit exit_sl811_cs(void)
  209. {
  210. pcmcia_unregister_driver(&sl811_cs_driver);
  211. }
  212. module_exit(exit_sl811_cs);