sl811_cs.c 6.6 KB

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