teles_cs.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /* $Id: teles_cs.c,v 1.1.2.2 2004/01/25 15:07:06 keil Exp $ */
  2. /*======================================================================
  3. A teles S0 PCMCIA client driver
  4. Based on skeleton by David Hinds, dhinds@allegro.stanford.edu
  5. Written by Christof Petig, christof.petig@wtal.de
  6. Also inspired by ELSA PCMCIA driver
  7. by Klaus Lichtenwalder <Lichtenwalder@ACM.org>
  8. Extentions to new hisax_pcmcia by Karsten Keil
  9. minor changes to be compatible with kernel 2.4.x
  10. by Jan.Schubert@GMX.li
  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 <asm/io.h>
  21. #include <asm/system.h>
  22. #include <pcmcia/cs_types.h>
  23. #include <pcmcia/cs.h>
  24. #include <pcmcia/cistpl.h>
  25. #include <pcmcia/cisreg.h>
  26. #include <pcmcia/ds.h>
  27. #include "hisax_cfg.h"
  28. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
  29. MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
  30. MODULE_LICENSE("GPL");
  31. /*====================================================================*/
  32. /* Parameters that can be set with 'insmod' */
  33. static int protocol = 2; /* EURO-ISDN Default */
  34. module_param(protocol, int, 0);
  35. /*====================================================================*/
  36. /*
  37. The event() function is this driver's Card Services event handler.
  38. It will be called by Card Services when an appropriate card status
  39. event is received. The config() and release() entry points are
  40. used to configure or release a socket, in response to card insertion
  41. and ejection events. They are invoked from the teles_cs event
  42. handler.
  43. */
  44. static int teles_cs_config(struct pcmcia_device *link);
  45. static void teles_cs_release(struct pcmcia_device *link);
  46. /*
  47. The attach() and detach() entry points are used to create and destroy
  48. "instances" of the driver, where each instance represents everything
  49. needed to manage one actual PCMCIA card.
  50. */
  51. static void teles_detach(struct pcmcia_device *p_dev);
  52. /*
  53. A linked list of "instances" of the teles_cs device. Each actual
  54. PCMCIA card corresponds to one device instance, and is described
  55. by one struct pcmcia_device structure (defined in ds.h).
  56. You may not want to use a linked list for this -- for example, the
  57. memory card driver uses an array of struct pcmcia_device pointers, where minor
  58. device numbers are used to derive the corresponding array index.
  59. */
  60. /*
  61. A driver needs to provide a dev_node_t structure for each device
  62. on a card. In some cases, there is only one device per card (for
  63. example, ethernet cards, modems). In other cases, there may be
  64. many actual or logical devices (SCSI adapters, memory cards with
  65. multiple partitions). The dev_node_t structures need to be kept
  66. in a linked list starting at the 'dev' field of a struct pcmcia_device
  67. structure. We allocate them in the card's private data structure,
  68. because they generally shouldn't be allocated dynamically.
  69. In this case, we also provide a flag to indicate if a device is
  70. "stopped" due to a power management event, or card ejection. The
  71. device IO routines can use a flag like this to throttle IO to a
  72. card that is not ready to accept it.
  73. */
  74. typedef struct local_info_t {
  75. struct pcmcia_device *p_dev;
  76. dev_node_t node;
  77. int busy;
  78. int cardnr;
  79. } local_info_t;
  80. /*======================================================================
  81. teles_attach() creates an "instance" of the driver, allocatingx
  82. local data structures for one device. The device is registered
  83. with Card Services.
  84. The dev_link structure is initialized, but we don't actually
  85. configure the card at this point -- we wait until we receive a
  86. card insertion event.
  87. ======================================================================*/
  88. static int teles_probe(struct pcmcia_device *link)
  89. {
  90. local_info_t *local;
  91. dev_dbg(&link->dev, "teles_attach()\n");
  92. /* Allocate space for private device-specific data */
  93. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  94. if (!local) return -ENOMEM;
  95. local->cardnr = -1;
  96. local->p_dev = link;
  97. link->priv = local;
  98. /* Interrupt setup */
  99. link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
  100. link->irq.Handler = NULL;
  101. /*
  102. General socket configuration defaults can go here. In this
  103. client, we assume very little, and rely on the CIS for almost
  104. everything. In most clients, many details (i.e., number, sizes,
  105. and attributes of IO windows) are fixed by the nature of the
  106. device, and can be hard-wired here.
  107. */
  108. link->io.NumPorts1 = 96;
  109. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  110. link->io.IOAddrLines = 5;
  111. link->conf.Attributes = CONF_ENABLE_IRQ;
  112. link->conf.IntType = INT_MEMORY_AND_IO;
  113. return teles_cs_config(link);
  114. } /* teles_attach */
  115. /*======================================================================
  116. This deletes a driver "instance". The device is de-registered
  117. with Card Services. If it has been released, all local data
  118. structures are freed. Otherwise, the structures will be freed
  119. when the device is released.
  120. ======================================================================*/
  121. static void teles_detach(struct pcmcia_device *link)
  122. {
  123. local_info_t *info = link->priv;
  124. dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
  125. info->busy = 1;
  126. teles_cs_release(link);
  127. kfree(info);
  128. } /* teles_detach */
  129. /*======================================================================
  130. teles_cs_config() is scheduled to run after a CARD_INSERTION event
  131. is received, to configure the PCMCIA socket, and to make the
  132. device available to the system.
  133. ======================================================================*/
  134. static int teles_cs_configcheck(struct pcmcia_device *p_dev,
  135. cistpl_cftable_entry_t *cf,
  136. cistpl_cftable_entry_t *dflt,
  137. unsigned int vcc,
  138. void *priv_data)
  139. {
  140. int j;
  141. if ((cf->io.nwin > 0) && cf->io.win[0].base) {
  142. printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
  143. p_dev->io.BasePort1 = cf->io.win[0].base;
  144. if (!pcmcia_request_io(p_dev, &p_dev->io))
  145. return 0;
  146. } else {
  147. printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
  148. for (j = 0x2f0; j > 0x100; j -= 0x10) {
  149. p_dev->io.BasePort1 = j;
  150. if (!pcmcia_request_io(p_dev, &p_dev->io))
  151. return 0;
  152. }
  153. }
  154. return -ENODEV;
  155. }
  156. static int teles_cs_config(struct pcmcia_device *link)
  157. {
  158. local_info_t *dev;
  159. int i;
  160. IsdnCard_t icard;
  161. dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
  162. dev = link->priv;
  163. i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
  164. if (i != 0)
  165. goto cs_failed;
  166. i = pcmcia_request_irq(link, &link->irq);
  167. if (i != 0) {
  168. link->irq.AssignedIRQ = 0;
  169. goto cs_failed;
  170. }
  171. i = pcmcia_request_configuration(link, &link->conf);
  172. if (i != 0)
  173. goto cs_failed;
  174. /* At this point, the dev_node_t structure(s) should be
  175. initialized and arranged in a linked list at link->dev. *//* */
  176. sprintf(dev->node.dev_name, "teles");
  177. dev->node.major = dev->node.minor = 0x0;
  178. link->dev_node = &dev->node;
  179. /* Finally, report what we've done */
  180. printk(KERN_INFO "%s: index 0x%02x:",
  181. dev->node.dev_name, link->conf.ConfigIndex);
  182. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  183. printk(", irq %d", link->irq.AssignedIRQ);
  184. if (link->io.NumPorts1)
  185. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  186. link->io.BasePort1+link->io.NumPorts1-1);
  187. if (link->io.NumPorts2)
  188. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  189. link->io.BasePort2+link->io.NumPorts2-1);
  190. printk("\n");
  191. icard.para[0] = link->irq.AssignedIRQ;
  192. icard.para[1] = link->io.BasePort1;
  193. icard.protocol = protocol;
  194. icard.typ = ISDN_CTYPE_TELESPCMCIA;
  195. i = hisax_init_pcmcia(link, &(((local_info_t*)link->priv)->busy), &icard);
  196. if (i < 0) {
  197. printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
  198. i, link->io.BasePort1);
  199. teles_cs_release(link);
  200. return -ENODEV;
  201. }
  202. ((local_info_t*)link->priv)->cardnr = i;
  203. return 0;
  204. cs_failed:
  205. teles_cs_release(link);
  206. return -ENODEV;
  207. } /* teles_cs_config */
  208. /*======================================================================
  209. After a card is removed, teles_cs_release() will unregister the net
  210. device, and release the PCMCIA configuration. If the device is
  211. still open, this will be postponed until it is closed.
  212. ======================================================================*/
  213. static void teles_cs_release(struct pcmcia_device *link)
  214. {
  215. local_info_t *local = link->priv;
  216. dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
  217. if (local) {
  218. if (local->cardnr >= 0) {
  219. /* no unregister function with hisax */
  220. HiSax_closecard(local->cardnr);
  221. }
  222. }
  223. pcmcia_disable_device(link);
  224. } /* teles_cs_release */
  225. static int teles_suspend(struct pcmcia_device *link)
  226. {
  227. local_info_t *dev = link->priv;
  228. dev->busy = 1;
  229. return 0;
  230. }
  231. static int teles_resume(struct pcmcia_device *link)
  232. {
  233. local_info_t *dev = link->priv;
  234. dev->busy = 0;
  235. return 0;
  236. }
  237. static struct pcmcia_device_id teles_ids[] = {
  238. PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
  239. PCMCIA_DEVICE_NULL,
  240. };
  241. MODULE_DEVICE_TABLE(pcmcia, teles_ids);
  242. static struct pcmcia_driver teles_cs_driver = {
  243. .owner = THIS_MODULE,
  244. .drv = {
  245. .name = "teles_cs",
  246. },
  247. .probe = teles_probe,
  248. .remove = teles_detach,
  249. .id_table = teles_ids,
  250. .suspend = teles_suspend,
  251. .resume = teles_resume,
  252. };
  253. static int __init init_teles_cs(void)
  254. {
  255. return pcmcia_register_driver(&teles_cs_driver);
  256. }
  257. static void __exit exit_teles_cs(void)
  258. {
  259. pcmcia_unregister_driver(&teles_cs_driver);
  260. }
  261. module_init(init_teles_cs);
  262. module_exit(exit_teles_cs);