sedlbauer_cs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
  50. you do not define PCMCIA_DEBUG at all, all the debug code will be
  51. left out. If you compile with PCMCIA_DEBUG=0, the debug code will
  52. be present but disabled -- but it can then be enabled for specific
  53. modules at load time with a 'pc_debug=#' option to insmod.
  54. */
  55. #ifdef PCMCIA_DEBUG
  56. static int pc_debug = PCMCIA_DEBUG;
  57. module_param(pc_debug, int, 0);
  58. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args);
  59. static char *version =
  60. "sedlbauer_cs.c 1.1a 2001/01/28 15:04:04 (M.Niemann)";
  61. #else
  62. #define DEBUG(n, args...)
  63. #endif
  64. /*====================================================================*/
  65. /* Parameters that can be set with 'insmod' */
  66. static int protocol = 2; /* EURO-ISDN Default */
  67. module_param(protocol, int, 0);
  68. /*====================================================================*/
  69. /*
  70. The event() function is this driver's Card Services event handler.
  71. It will be called by Card Services when an appropriate card status
  72. event is received. The config() and release() entry points are
  73. used to configure or release a socket, in response to card
  74. insertion and ejection events. They are invoked from the sedlbauer
  75. event handler.
  76. */
  77. static int sedlbauer_config(struct pcmcia_device *link);
  78. static void sedlbauer_release(struct pcmcia_device *link);
  79. /*
  80. The attach() and detach() entry points are used to create and destroy
  81. "instances" of the driver, where each instance represents everything
  82. needed to manage one actual PCMCIA card.
  83. */
  84. static void sedlbauer_detach(struct pcmcia_device *p_dev);
  85. /*
  86. You'll also need to prototype all the functions that will actually
  87. be used to talk to your device. See 'memory_cs' for a good example
  88. of a fully self-sufficient driver; the other drivers rely more or
  89. less on other parts of the kernel.
  90. */
  91. /*
  92. A driver needs to provide a dev_node_t structure for each device
  93. on a card. In some cases, there is only one device per card (for
  94. example, ethernet cards, modems). In other cases, there may be
  95. many actual or logical devices (SCSI adapters, memory cards with
  96. multiple partitions). The dev_node_t structures need to be kept
  97. in a linked list starting at the 'dev' field of a struct pcmcia_device
  98. structure. We allocate them in the card's private data structure,
  99. because they generally shouldn't be allocated dynamically.
  100. In this case, we also provide a flag to indicate if a device is
  101. "stopped" due to a power management event, or card ejection. The
  102. device IO routines can use a flag like this to throttle IO to a
  103. card that is not ready to accept it.
  104. */
  105. typedef struct local_info_t {
  106. struct pcmcia_device *p_dev;
  107. dev_node_t node;
  108. int stop;
  109. int cardnr;
  110. } local_info_t;
  111. /*======================================================================
  112. sedlbauer_attach() creates an "instance" of the driver, allocating
  113. local data structures for one device. The device is registered
  114. with Card Services.
  115. The dev_link structure is initialized, but we don't actually
  116. configure the card at this point -- we wait until we receive a
  117. card insertion event.
  118. ======================================================================*/
  119. static int sedlbauer_probe(struct pcmcia_device *link)
  120. {
  121. local_info_t *local;
  122. DEBUG(0, "sedlbauer_attach()\n");
  123. /* Allocate space for private device-specific data */
  124. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  125. if (!local) return -ENOMEM;
  126. local->cardnr = -1;
  127. local->p_dev = link;
  128. link->priv = local;
  129. /* Interrupt setup */
  130. link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
  131. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  132. link->irq.Handler = NULL;
  133. /*
  134. General socket configuration defaults can go here. In this
  135. client, we assume very little, and rely on the CIS for almost
  136. everything. In most clients, many details (i.e., number, sizes,
  137. and attributes of IO windows) are fixed by the nature of the
  138. device, and can be hard-wired here.
  139. */
  140. /* from old sedl_cs
  141. */
  142. /* The io structure describes IO port mapping */
  143. link->io.NumPorts1 = 8;
  144. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  145. link->io.IOAddrLines = 3;
  146. link->conf.Attributes = 0;
  147. link->conf.IntType = INT_MEMORY_AND_IO;
  148. return sedlbauer_config(link);
  149. } /* sedlbauer_attach */
  150. /*======================================================================
  151. This deletes a driver "instance". The device is de-registered
  152. with Card Services. If it has been released, all local data
  153. structures are freed. Otherwise, the structures will be freed
  154. when the device is released.
  155. ======================================================================*/
  156. static void sedlbauer_detach(struct pcmcia_device *link)
  157. {
  158. DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
  159. ((local_info_t *)link->priv)->stop = 1;
  160. sedlbauer_release(link);
  161. /* This points to the parent local_info_t struct */
  162. kfree(link->priv);
  163. } /* sedlbauer_detach */
  164. /*======================================================================
  165. sedlbauer_config() is scheduled to run after a CARD_INSERTION event
  166. is received, to configure the PCMCIA socket, and to make the
  167. device available to the system.
  168. ======================================================================*/
  169. #define CS_CHECK(fn, ret) \
  170. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  171. static int sedlbauer_config(struct pcmcia_device *link)
  172. {
  173. local_info_t *dev = link->priv;
  174. tuple_t tuple;
  175. cisparse_t parse;
  176. int last_fn, last_ret;
  177. u8 buf[64];
  178. config_info_t conf;
  179. win_req_t req;
  180. memreq_t map;
  181. IsdnCard_t icard;
  182. DEBUG(0, "sedlbauer_config(0x%p)\n", link);
  183. tuple.Attributes = 0;
  184. tuple.TupleData = buf;
  185. tuple.TupleDataMax = sizeof(buf);
  186. tuple.TupleOffset = 0;
  187. CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
  188. /*
  189. In this loop, we scan the CIS for configuration table entries,
  190. each of which describes a valid card configuration, including
  191. voltage, IO window, memory window, and interrupt settings.
  192. We make no assumptions about the card to be configured: we use
  193. just the information available in the CIS. In an ideal world,
  194. this would work for any PCMCIA card, but it requires a complete
  195. and accurate CIS. In practice, a driver usually "knows" most of
  196. these things without consulting the CIS, and most client drivers
  197. will only use the CIS to fill in implementation-defined details.
  198. */
  199. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  200. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  201. while (1) {
  202. cistpl_cftable_entry_t dflt = { 0 };
  203. cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
  204. if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
  205. pcmcia_parse_tuple(link, &tuple, &parse) != 0)
  206. goto next_entry;
  207. if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
  208. if (cfg->index == 0) goto next_entry;
  209. link->conf.ConfigIndex = cfg->index;
  210. /* Does this card need audio output? */
  211. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  212. link->conf.Attributes |= CONF_ENABLE_SPKR;
  213. link->conf.Status = CCSR_AUDIO_ENA;
  214. }
  215. /* Use power settings for Vcc and Vpp if present */
  216. /* Note that the CIS values need to be rescaled */
  217. if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  218. if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
  219. goto next_entry;
  220. } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
  221. if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000)
  222. goto next_entry;
  223. }
  224. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  225. link->conf.Vpp =
  226. cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  227. else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
  228. link->conf.Vpp =
  229. dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
  230. /* Do we need to allocate an interrupt? */
  231. if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
  232. link->conf.Attributes |= CONF_ENABLE_IRQ;
  233. /* IO window settings */
  234. link->io.NumPorts1 = link->io.NumPorts2 = 0;
  235. if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
  236. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
  237. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  238. if (!(io->flags & CISTPL_IO_8BIT))
  239. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  240. if (!(io->flags & CISTPL_IO_16BIT))
  241. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  242. /* new in dummy.cs 2001/01/28 MN
  243. link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
  244. */
  245. link->io.BasePort1 = io->win[0].base;
  246. link->io.NumPorts1 = io->win[0].len;
  247. if (io->nwin > 1) {
  248. link->io.Attributes2 = link->io.Attributes1;
  249. link->io.BasePort2 = io->win[1].base;
  250. link->io.NumPorts2 = io->win[1].len;
  251. }
  252. /* This reserves IO space but doesn't actually enable it */
  253. if (pcmcia_request_io(link, &link->io) != 0)
  254. goto next_entry;
  255. }
  256. /*
  257. Now set up a common memory window, if needed. There is room
  258. in the struct pcmcia_device structure for one memory window handle,
  259. but if the base addresses need to be saved, or if multiple
  260. windows are needed, the info should go in the private data
  261. structure for this device.
  262. Note that the memory window base is a physical address, and
  263. needs to be mapped to virtual space with ioremap() before it
  264. is used.
  265. */
  266. if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
  267. cistpl_mem_t *mem =
  268. (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
  269. req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
  270. req.Attributes |= WIN_ENABLE;
  271. req.Base = mem->win[0].host_addr;
  272. req.Size = mem->win[0].len;
  273. /* new in dummy.cs 2001/01/28 MN
  274. if (req.Size < 0x1000)
  275. req.Size = 0x1000;
  276. */
  277. req.AccessSpeed = 0;
  278. if (pcmcia_request_window(&link, &req, &link->win) != 0)
  279. goto next_entry;
  280. map.Page = 0; map.CardOffset = mem->win[0].card_addr;
  281. if (pcmcia_map_mem_page(link->win, &map) != 0)
  282. goto next_entry;
  283. }
  284. /* If we got this far, we're cool! */
  285. break;
  286. next_entry:
  287. CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
  288. }
  289. /*
  290. Allocate an interrupt line. Note that this does not assign a
  291. handler to the interrupt, unless the 'Handler' member of the
  292. irq structure is initialized.
  293. */
  294. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  295. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  296. /*
  297. This actually configures the PCMCIA socket -- setting up
  298. the I/O windows and the interrupt mapping, and putting the
  299. card and host interface into "Memory and IO" mode.
  300. */
  301. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  302. /*
  303. At this point, the dev_node_t structure(s) need to be
  304. initialized and arranged in a linked list at link->dev.
  305. */
  306. sprintf(dev->node.dev_name, "sedlbauer");
  307. dev->node.major = dev->node.minor = 0;
  308. link->dev_node = &dev->node;
  309. /* Finally, report what we've done */
  310. printk(KERN_INFO "%s: index 0x%02x:",
  311. dev->node.dev_name, link->conf.ConfigIndex);
  312. if (link->conf.Vpp)
  313. printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
  314. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  315. printk(", irq %d", link->irq.AssignedIRQ);
  316. if (link->io.NumPorts1)
  317. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  318. link->io.BasePort1+link->io.NumPorts1-1);
  319. if (link->io.NumPorts2)
  320. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  321. link->io.BasePort2+link->io.NumPorts2-1);
  322. if (link->win)
  323. printk(", mem 0x%06lx-0x%06lx", req.Base,
  324. req.Base+req.Size-1);
  325. printk("\n");
  326. icard.para[0] = link->irq.AssignedIRQ;
  327. icard.para[1] = link->io.BasePort1;
  328. icard.protocol = protocol;
  329. icard.typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
  330. last_ret = hisax_init_pcmcia(link, &(((local_info_t*)link->priv)->stop), &icard);
  331. if (last_ret < 0) {
  332. printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
  333. last_ret, link->io.BasePort1);
  334. sedlbauer_release(link);
  335. return -ENODEV;
  336. } else
  337. ((local_info_t*)link->priv)->cardnr = last_ret;
  338. return 0;
  339. cs_failed:
  340. cs_error(link, last_fn, last_ret);
  341. sedlbauer_release(link);
  342. return -ENODEV;
  343. } /* sedlbauer_config */
  344. /*======================================================================
  345. After a card is removed, sedlbauer_release() will unregister the
  346. device, and release the PCMCIA configuration. If the device is
  347. still open, this will be postponed until it is closed.
  348. ======================================================================*/
  349. static void sedlbauer_release(struct pcmcia_device *link)
  350. {
  351. local_info_t *local = link->priv;
  352. DEBUG(0, "sedlbauer_release(0x%p)\n", link);
  353. if (local) {
  354. if (local->cardnr >= 0) {
  355. /* no unregister function with hisax */
  356. HiSax_closecard(local->cardnr);
  357. }
  358. }
  359. pcmcia_disable_device(link);
  360. } /* sedlbauer_release */
  361. static int sedlbauer_suspend(struct pcmcia_device *link)
  362. {
  363. local_info_t *dev = link->priv;
  364. dev->stop = 1;
  365. return 0;
  366. }
  367. static int sedlbauer_resume(struct pcmcia_device *link)
  368. {
  369. local_info_t *dev = link->priv;
  370. dev->stop = 0;
  371. return 0;
  372. }
  373. static struct pcmcia_device_id sedlbauer_ids[] = {
  374. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "speed star II", "V 3.1", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a),
  375. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
  376. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
  377. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
  378. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
  379. PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
  380. /* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
  381. PCMCIA_DEVICE_NULL
  382. };
  383. MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
  384. static struct pcmcia_driver sedlbauer_driver = {
  385. .owner = THIS_MODULE,
  386. .drv = {
  387. .name = "sedlbauer_cs",
  388. },
  389. .probe = sedlbauer_probe,
  390. .remove = sedlbauer_detach,
  391. .id_table = sedlbauer_ids,
  392. .suspend = sedlbauer_suspend,
  393. .resume = sedlbauer_resume,
  394. };
  395. static int __init init_sedlbauer_cs(void)
  396. {
  397. return pcmcia_register_driver(&sedlbauer_driver);
  398. }
  399. static void __exit exit_sedlbauer_cs(void)
  400. {
  401. pcmcia_unregister_driver(&sedlbauer_driver);
  402. }
  403. module_init(init_sedlbauer_cs);
  404. module_exit(exit_sedlbauer_cs);