sedlbauer_cs.c 19 KB

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