sedlbauer_cs.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*======================================================================
  2. A Sedlbauer PCMCIA client driver
  3. This driver is for the Sedlbauer Speed Star and Speed Star II,
  4. which are ISDN PCMCIA Cards.
  5. The contents of this file are subject to the Mozilla Public
  6. License Version 1.1 (the "License"); you may not use this file
  7. except in compliance with the License. You may obtain a copy of
  8. the License at http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS
  10. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. implied. See the License for the specific language governing
  12. rights and limitations under the License.
  13. The initial developer of the original code is David A. Hinds
  14. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  15. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  16. Modifications from dummy_cs.c are Copyright (C) 1999-2001 Marcus Niemann
  17. <maniemann@users.sourceforge.net>. All Rights Reserved.
  18. Alternatively, the contents of this file may be used under the
  19. terms of the GNU General Public License version 2 (the "GPL"), in
  20. which case the provisions of the GPL are applicable instead of the
  21. above. If you wish to allow the use of your version of this file
  22. only under the terms of the GPL and not to allow others to use
  23. your version of this file under the MPL, indicate your decision
  24. by deleting the provisions above and replace them with the notice
  25. and other provisions required by the GPL. If you do not delete
  26. the provisions above, a recipient may use your version of this
  27. file under either the MPL or the GPL.
  28. ======================================================================*/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/ptrace.h>
  33. #include <linux/slab.h>
  34. #include <linux/string.h>
  35. #include <linux/timer.h>
  36. #include <linux/ioport.h>
  37. #include <asm/io.h>
  38. #include <asm/system.h>
  39. #include <pcmcia/cs_types.h>
  40. #include <pcmcia/cs.h>
  41. #include <pcmcia/cistpl.h>
  42. #include <pcmcia/cisreg.h>
  43. #include <pcmcia/ds.h>
  44. #include "hisax_cfg.h"
  45. MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Sedlbauer cards");
  46. MODULE_AUTHOR("Marcus Niemann");
  47. MODULE_LICENSE("Dual MPL/GPL");
  48. /*====================================================================*/
  49. /* Parameters that can be set with 'insmod' */
  50. static int protocol = 2; /* EURO-ISDN Default */
  51. module_param(protocol, int, 0);
  52. /*====================================================================*/
  53. /*
  54. The event() function is this driver's Card Services event handler.
  55. It will be called by Card Services when an appropriate card status
  56. event is received. The config() and release() entry points are
  57. used to configure or release a socket, in response to card
  58. insertion and ejection events. They are invoked from the sedlbauer
  59. event handler.
  60. */
  61. static int sedlbauer_config(struct pcmcia_device *link);
  62. static void sedlbauer_release(struct pcmcia_device *link);
  63. /*
  64. The attach() and detach() entry points are used to create and destroy
  65. "instances" of the driver, where each instance represents everything
  66. needed to manage one actual PCMCIA card.
  67. */
  68. static void sedlbauer_detach(struct pcmcia_device *p_dev);
  69. /*
  70. You'll also need to prototype all the functions that will actually
  71. be used to talk to your device. See 'memory_cs' for a good example
  72. of a fully self-sufficient driver; the other drivers rely more or
  73. less on other parts of the kernel.
  74. */
  75. /*
  76. A driver needs to provide a dev_node_t structure for each device
  77. on a card. In some cases, there is only one device per card (for
  78. example, ethernet cards, modems). In other cases, there may be
  79. many actual or logical devices (SCSI adapters, memory cards with
  80. multiple partitions). The dev_node_t structures need to be kept
  81. in a linked list starting at the 'dev' field of a struct pcmcia_device
  82. structure. We allocate them in the card's private data structure,
  83. because they generally shouldn't be allocated dynamically.
  84. In this case, we also provide a flag to indicate if a device is
  85. "stopped" due to a power management event, or card ejection. The
  86. device IO routines can use a flag like this to throttle IO to a
  87. card that is not ready to accept it.
  88. */
  89. typedef struct local_info_t {
  90. struct pcmcia_device *p_dev;
  91. dev_node_t node;
  92. int stop;
  93. int cardnr;
  94. } local_info_t;
  95. /*======================================================================
  96. sedlbauer_attach() creates an "instance" of the driver, allocating
  97. local data structures for one device. The device is registered
  98. with Card Services.
  99. The dev_link structure is initialized, but we don't actually
  100. configure the card at this point -- we wait until we receive a
  101. card insertion event.
  102. ======================================================================*/
  103. static int sedlbauer_probe(struct pcmcia_device *link)
  104. {
  105. local_info_t *local;
  106. dev_dbg(&link->dev, "sedlbauer_attach()\n");
  107. /* Allocate space for private device-specific data */
  108. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  109. if (!local) return -ENOMEM;
  110. local->cardnr = -1;
  111. local->p_dev = link;
  112. link->priv = local;
  113. /* Interrupt setup */
  114. link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
  115. link->irq.Handler = NULL;
  116. /*
  117. General socket configuration defaults can go here. In this
  118. client, we assume very little, and rely on the CIS for almost
  119. everything. In most clients, many details (i.e., number, sizes,
  120. and attributes of IO windows) are fixed by the nature of the
  121. device, and can be hard-wired here.
  122. */
  123. /* from old sedl_cs
  124. */
  125. /* The io structure describes IO port mapping */
  126. link->io.NumPorts1 = 8;
  127. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  128. link->io.IOAddrLines = 3;
  129. link->conf.Attributes = 0;
  130. link->conf.IntType = INT_MEMORY_AND_IO;
  131. return sedlbauer_config(link);
  132. } /* sedlbauer_attach */
  133. /*======================================================================
  134. This deletes a driver "instance". The device is de-registered
  135. with Card Services. If it has been released, all local data
  136. structures are freed. Otherwise, the structures will be freed
  137. when the device is released.
  138. ======================================================================*/
  139. static void sedlbauer_detach(struct pcmcia_device *link)
  140. {
  141. dev_dbg(&link->dev, "sedlbauer_detach(0x%p)\n", link);
  142. ((local_info_t *)link->priv)->stop = 1;
  143. sedlbauer_release(link);
  144. /* This points to the parent local_info_t struct */
  145. kfree(link->priv);
  146. } /* sedlbauer_detach */
  147. /*======================================================================
  148. sedlbauer_config() is scheduled to run after a CARD_INSERTION event
  149. is received, to configure the PCMCIA socket, and to make the
  150. device available to the system.
  151. ======================================================================*/
  152. static int sedlbauer_config_check(struct pcmcia_device *p_dev,
  153. cistpl_cftable_entry_t *cfg,
  154. cistpl_cftable_entry_t *dflt,
  155. unsigned int vcc,
  156. void *priv_data)
  157. {
  158. win_req_t *req = priv_data;
  159. if (cfg->index == 0)
  160. return -ENODEV;
  161. /* Does this card need audio output? */
  162. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  163. p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
  164. p_dev->conf.Status = CCSR_AUDIO_ENA;
  165. }
  166. /* Use power settings for Vcc and Vpp if present */
  167. /* Note that the CIS values need to be rescaled */
  168. if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  169. if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
  170. return -ENODEV;
  171. } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  172. if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
  173. return -ENODEV;
  174. }
  175. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  176. p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  177. else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
  178. p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
  179. /* Do we need to allocate an interrupt? */
  180. if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
  181. p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
  182. /* IO window settings */
  183. p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
  184. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  185. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  186. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  187. if (!(io->flags & CISTPL_IO_8BIT))
  188. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  189. if (!(io->flags & CISTPL_IO_16BIT))
  190. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  191. p_dev->io.BasePort1 = io->win[0].base;
  192. p_dev->io.NumPorts1 = io->win[0].len;
  193. if (io->nwin > 1) {
  194. p_dev->io.Attributes2 = p_dev->io.Attributes1;
  195. p_dev->io.BasePort2 = io->win[1].base;
  196. p_dev->io.NumPorts2 = io->win[1].len;
  197. }
  198. /* This reserves IO space but doesn't actually enable it */
  199. if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
  200. return -ENODEV;
  201. }
  202. /*
  203. Now set up a common memory window, if needed. There is room
  204. in the struct pcmcia_device structure for one memory window handle,
  205. but if the base addresses need to be saved, or if multiple
  206. windows are needed, the info should go in the private data
  207. structure for this device.
  208. Note that the memory window base is a physical address, and
  209. needs to be mapped to virtual space with ioremap() before it
  210. is used.
  211. */
  212. if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
  213. cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
  214. memreq_t map;
  215. req->Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
  216. req->Attributes |= WIN_ENABLE;
  217. req->Base = mem->win[0].host_addr;
  218. req->Size = mem->win[0].len;
  219. req->AccessSpeed = 0;
  220. if (pcmcia_request_window(p_dev, req, &p_dev->win) != 0)
  221. return -ENODEV;
  222. map.Page = 0;
  223. map.CardOffset = mem->win[0].card_addr;
  224. if (pcmcia_map_mem_page(p_dev, p_dev->win, &map) != 0)
  225. return -ENODEV;
  226. }
  227. return 0;
  228. }
  229. static int sedlbauer_config(struct pcmcia_device *link)
  230. {
  231. local_info_t *dev = link->priv;
  232. win_req_t *req;
  233. int ret;
  234. IsdnCard_t icard;
  235. dev_dbg(&link->dev, "sedlbauer_config(0x%p)\n", link);
  236. req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
  237. if (!req)
  238. return -ENOMEM;
  239. /*
  240. In this loop, we scan the CIS for configuration table entries,
  241. each of which describes a valid card configuration, including
  242. voltage, IO window, memory window, and interrupt settings.
  243. We make no assumptions about the card to be configured: we use
  244. just the information available in the CIS. In an ideal world,
  245. this would work for any PCMCIA card, but it requires a complete
  246. and accurate CIS. In practice, a driver usually "knows" most of
  247. these things without consulting the CIS, and most client drivers
  248. will only use the CIS to fill in implementation-defined details.
  249. */
  250. ret = pcmcia_loop_config(link, sedlbauer_config_check, req);
  251. if (ret)
  252. goto failed;
  253. /*
  254. Allocate an interrupt line. Note that this does not assign a
  255. handler to the interrupt, unless the 'Handler' member of the
  256. irq structure is initialized.
  257. */
  258. if (link->conf.Attributes & CONF_ENABLE_IRQ) {
  259. ret = pcmcia_request_irq(link, &link->irq);
  260. if (ret)
  261. goto failed;
  262. }
  263. /*
  264. This actually configures the PCMCIA socket -- setting up
  265. the I/O windows and the interrupt mapping, and putting the
  266. card and host interface into "Memory and IO" mode.
  267. */
  268. ret = pcmcia_request_configuration(link, &link->conf);
  269. if (ret)
  270. goto failed;
  271. /*
  272. At this point, the dev_node_t structure(s) need to be
  273. initialized and arranged in a linked list at link->dev.
  274. */
  275. sprintf(dev->node.dev_name, "sedlbauer");
  276. dev->node.major = dev->node.minor = 0;
  277. link->dev_node = &dev->node;
  278. /* Finally, report what we've done */
  279. printk(KERN_INFO "%s: index 0x%02x:",
  280. dev->node.dev_name, link->conf.ConfigIndex);
  281. if (link->conf.Vpp)
  282. printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
  283. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  284. printk(", irq %d", link->irq.AssignedIRQ);
  285. if (link->io.NumPorts1)
  286. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  287. link->io.BasePort1+link->io.NumPorts1-1);
  288. if (link->io.NumPorts2)
  289. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  290. link->io.BasePort2+link->io.NumPorts2-1);
  291. if (link->win)
  292. printk(", mem 0x%06lx-0x%06lx", req->Base,
  293. req->Base+req->Size-1);
  294. printk("\n");
  295. icard.para[0] = link->irq.AssignedIRQ;
  296. icard.para[1] = link->io.BasePort1;
  297. icard.protocol = protocol;
  298. icard.typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
  299. ret = hisax_init_pcmcia(link,
  300. &(((local_info_t *)link->priv)->stop), &icard);
  301. if (ret < 0) {
  302. printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
  303. ret, link->io.BasePort1);
  304. sedlbauer_release(link);
  305. return -ENODEV;
  306. } else
  307. ((local_info_t *)link->priv)->cardnr = ret;
  308. return 0;
  309. failed:
  310. sedlbauer_release(link);
  311. return -ENODEV;
  312. } /* sedlbauer_config */
  313. /*======================================================================
  314. After a card is removed, sedlbauer_release() will unregister the
  315. device, and release the PCMCIA configuration. If the device is
  316. still open, this will be postponed until it is closed.
  317. ======================================================================*/
  318. static void sedlbauer_release(struct pcmcia_device *link)
  319. {
  320. local_info_t *local = link->priv;
  321. dev_dbg(&link->dev, "sedlbauer_release(0x%p)\n", link);
  322. if (local) {
  323. if (local->cardnr >= 0) {
  324. /* no unregister function with hisax */
  325. HiSax_closecard(local->cardnr);
  326. }
  327. }
  328. pcmcia_disable_device(link);
  329. } /* sedlbauer_release */
  330. static int sedlbauer_suspend(struct pcmcia_device *link)
  331. {
  332. local_info_t *dev = link->priv;
  333. dev->stop = 1;
  334. return 0;
  335. }
  336. static int sedlbauer_resume(struct pcmcia_device *link)
  337. {
  338. local_info_t *dev = link->priv;
  339. dev->stop = 0;
  340. return 0;
  341. }
  342. static struct pcmcia_device_id sedlbauer_ids[] = {
  343. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "speed star II", "V 3.1", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a),
  344. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
  345. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
  346. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
  347. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
  348. PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
  349. /* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
  350. PCMCIA_DEVICE_NULL
  351. };
  352. MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
  353. static struct pcmcia_driver sedlbauer_driver = {
  354. .owner = THIS_MODULE,
  355. .drv = {
  356. .name = "sedlbauer_cs",
  357. },
  358. .probe = sedlbauer_probe,
  359. .remove = sedlbauer_detach,
  360. .id_table = sedlbauer_ids,
  361. .suspend = sedlbauer_suspend,
  362. .resume = sedlbauer_resume,
  363. };
  364. static int __init init_sedlbauer_cs(void)
  365. {
  366. return pcmcia_register_driver(&sedlbauer_driver);
  367. }
  368. static void __exit exit_sedlbauer_cs(void)
  369. {
  370. pcmcia_unregister_driver(&sedlbauer_driver);
  371. }
  372. module_init(init_sedlbauer_cs);
  373. module_exit(exit_sedlbauer_cs);