sedlbauer_cs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  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 int sedlbauer_config(struct pcmcia_device *link);
  79. static void sedlbauer_release(struct pcmcia_device *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 struct pcmcia_device
  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. struct pcmcia_device *p_dev;
  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_probe(struct pcmcia_device *link)
  121. {
  122. local_info_t *local;
  123. DEBUG(0, "sedlbauer_attach()\n");
  124. /* Allocate space for private device-specific data */
  125. local = kmalloc(sizeof(local_info_t), GFP_KERNEL);
  126. if (!local) return -ENOMEM;
  127. memset(local, 0, sizeof(local_info_t));
  128. local->cardnr = -1;
  129. local->p_dev = link;
  130. link->priv = local;
  131. /* Interrupt setup */
  132. link->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
  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.IntType = INT_MEMORY_AND_IO;
  150. return sedlbauer_config(link);
  151. } /* sedlbauer_attach */
  152. /*======================================================================
  153. This deletes a driver "instance". The device is de-registered
  154. with Card Services. If it has been released, all local data
  155. structures are freed. Otherwise, the structures will be freed
  156. when the device is released.
  157. ======================================================================*/
  158. static void sedlbauer_detach(struct pcmcia_device *link)
  159. {
  160. DEBUG(0, "sedlbauer_detach(0x%p)\n", link);
  161. ((local_info_t *)link->priv)->stop = 1;
  162. sedlbauer_release(link);
  163. /* This points to the parent local_info_t struct */
  164. kfree(link->priv);
  165. } /* sedlbauer_detach */
  166. /*======================================================================
  167. sedlbauer_config() is scheduled to run after a CARD_INSERTION event
  168. is received, to configure the PCMCIA socket, and to make the
  169. device available to the system.
  170. ======================================================================*/
  171. #define CS_CHECK(fn, ret) \
  172. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  173. static int sedlbauer_config(struct pcmcia_device *link)
  174. {
  175. local_info_t *dev = link->priv;
  176. tuple_t tuple;
  177. cisparse_t parse;
  178. int last_fn, last_ret;
  179. u8 buf[64];
  180. config_info_t conf;
  181. win_req_t req;
  182. memreq_t map;
  183. IsdnCard_t icard;
  184. DEBUG(0, "sedlbauer_config(0x%p)\n", link);
  185. /*
  186. This reads the card's CONFIG tuple to find its configuration
  187. registers.
  188. */
  189. tuple.DesiredTuple = CISTPL_CONFIG;
  190. tuple.Attributes = 0;
  191. tuple.TupleData = buf;
  192. tuple.TupleDataMax = sizeof(buf);
  193. tuple.TupleOffset = 0;
  194. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  195. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  196. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
  197. link->conf.ConfigBase = parse.config.base;
  198. link->conf.Present = parse.config.rmask[0];
  199. CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
  200. /*
  201. In this loop, we scan the CIS for configuration table entries,
  202. each of which describes a valid card configuration, including
  203. voltage, IO window, memory window, and interrupt settings.
  204. We make no assumptions about the card to be configured: we use
  205. just the information available in the CIS. In an ideal world,
  206. this would work for any PCMCIA card, but it requires a complete
  207. and accurate CIS. In practice, a driver usually "knows" most of
  208. these things without consulting the CIS, and most client drivers
  209. will only use the CIS to fill in implementation-defined details.
  210. */
  211. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  212. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  213. while (1) {
  214. cistpl_cftable_entry_t dflt = { 0 };
  215. cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
  216. if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
  217. pcmcia_parse_tuple(link, &tuple, &parse) != 0)
  218. goto next_entry;
  219. if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
  220. if (cfg->index == 0) goto next_entry;
  221. link->conf.ConfigIndex = cfg->index;
  222. /* Does this card need audio output? */
  223. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  224. link->conf.Attributes |= CONF_ENABLE_SPKR;
  225. link->conf.Status = CCSR_AUDIO_ENA;
  226. }
  227. /* Use power settings for Vcc and Vpp if present */
  228. /* Note that the CIS values need to be rescaled */
  229. if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  230. if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
  231. goto next_entry;
  232. } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
  233. if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000)
  234. goto next_entry;
  235. }
  236. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  237. link->conf.Vpp =
  238. cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  239. else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
  240. link->conf.Vpp =
  241. dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
  242. /* Do we need to allocate an interrupt? */
  243. if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
  244. link->conf.Attributes |= CONF_ENABLE_IRQ;
  245. /* IO window settings */
  246. link->io.NumPorts1 = link->io.NumPorts2 = 0;
  247. if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
  248. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
  249. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  250. if (!(io->flags & CISTPL_IO_8BIT))
  251. link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  252. if (!(io->flags & CISTPL_IO_16BIT))
  253. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  254. /* new in dummy.cs 2001/01/28 MN
  255. link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
  256. */
  257. link->io.BasePort1 = io->win[0].base;
  258. link->io.NumPorts1 = io->win[0].len;
  259. if (io->nwin > 1) {
  260. link->io.Attributes2 = link->io.Attributes1;
  261. link->io.BasePort2 = io->win[1].base;
  262. link->io.NumPorts2 = io->win[1].len;
  263. }
  264. /* This reserves IO space but doesn't actually enable it */
  265. if (pcmcia_request_io(link, &link->io) != 0)
  266. goto next_entry;
  267. }
  268. /*
  269. Now set up a common memory window, if needed. There is room
  270. in the struct pcmcia_device structure for one memory window handle,
  271. but if the base addresses need to be saved, or if multiple
  272. windows are needed, the info should go in the private data
  273. structure for this device.
  274. Note that the memory window base is a physical address, and
  275. needs to be mapped to virtual space with ioremap() before it
  276. is used.
  277. */
  278. if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
  279. cistpl_mem_t *mem =
  280. (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
  281. req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
  282. req.Attributes |= WIN_ENABLE;
  283. req.Base = mem->win[0].host_addr;
  284. req.Size = mem->win[0].len;
  285. /* new in dummy.cs 2001/01/28 MN
  286. if (req.Size < 0x1000)
  287. req.Size = 0x1000;
  288. */
  289. req.AccessSpeed = 0;
  290. if (pcmcia_request_window(&link, &req, &link->win) != 0)
  291. goto next_entry;
  292. map.Page = 0; map.CardOffset = mem->win[0].card_addr;
  293. if (pcmcia_map_mem_page(link->win, &map) != 0)
  294. goto next_entry;
  295. }
  296. /* If we got this far, we're cool! */
  297. break;
  298. next_entry:
  299. CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
  300. }
  301. /*
  302. Allocate an interrupt line. Note that this does not assign a
  303. handler to the interrupt, unless the 'Handler' member of the
  304. irq structure is initialized.
  305. */
  306. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  307. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  308. /*
  309. This actually configures the PCMCIA socket -- setting up
  310. the I/O windows and the interrupt mapping, and putting the
  311. card and host interface into "Memory and IO" mode.
  312. */
  313. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  314. /*
  315. At this point, the dev_node_t structure(s) need to be
  316. initialized and arranged in a linked list at link->dev.
  317. */
  318. sprintf(dev->node.dev_name, "sedlbauer");
  319. dev->node.major = dev->node.minor = 0;
  320. link->dev_node = &dev->node;
  321. /* Finally, report what we've done */
  322. printk(KERN_INFO "%s: index 0x%02x:",
  323. dev->node.dev_name, link->conf.ConfigIndex);
  324. if (link->conf.Vpp)
  325. printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
  326. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  327. printk(", irq %d", link->irq.AssignedIRQ);
  328. if (link->io.NumPorts1)
  329. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  330. link->io.BasePort1+link->io.NumPorts1-1);
  331. if (link->io.NumPorts2)
  332. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  333. link->io.BasePort2+link->io.NumPorts2-1);
  334. if (link->win)
  335. printk(", mem 0x%06lx-0x%06lx", req.Base,
  336. req.Base+req.Size-1);
  337. printk("\n");
  338. icard.para[0] = link->irq.AssignedIRQ;
  339. icard.para[1] = link->io.BasePort1;
  340. icard.protocol = protocol;
  341. icard.typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
  342. last_ret = hisax_init_pcmcia(link, &(((local_info_t*)link->priv)->stop), &icard);
  343. if (last_ret < 0) {
  344. printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
  345. last_ret, link->io.BasePort1);
  346. sedlbauer_release(link);
  347. return -ENODEV;
  348. } else
  349. ((local_info_t*)link->priv)->cardnr = last_ret;
  350. return 0;
  351. cs_failed:
  352. cs_error(link, last_fn, last_ret);
  353. sedlbauer_release(link);
  354. return -ENODEV;
  355. } /* sedlbauer_config */
  356. /*======================================================================
  357. After a card is removed, sedlbauer_release() will unregister the
  358. device, and release the PCMCIA configuration. If the device is
  359. still open, this will be postponed until it is closed.
  360. ======================================================================*/
  361. static void sedlbauer_release(struct pcmcia_device *link)
  362. {
  363. local_info_t *local = link->priv;
  364. DEBUG(0, "sedlbauer_release(0x%p)\n", link);
  365. if (local) {
  366. if (local->cardnr >= 0) {
  367. /* no unregister function with hisax */
  368. HiSax_closecard(local->cardnr);
  369. }
  370. }
  371. pcmcia_disable_device(link);
  372. } /* sedlbauer_release */
  373. static int sedlbauer_suspend(struct pcmcia_device *link)
  374. {
  375. local_info_t *dev = link->priv;
  376. dev->stop = 1;
  377. return 0;
  378. }
  379. static int sedlbauer_resume(struct pcmcia_device *link)
  380. {
  381. local_info_t *dev = link->priv;
  382. dev->stop = 0;
  383. return 0;
  384. }
  385. static struct pcmcia_device_id sedlbauer_ids[] = {
  386. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "speed star II", "V 3.1", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a),
  387. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
  388. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
  389. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
  390. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
  391. PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
  392. /* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
  393. PCMCIA_DEVICE_NULL
  394. };
  395. MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
  396. static struct pcmcia_driver sedlbauer_driver = {
  397. .owner = THIS_MODULE,
  398. .drv = {
  399. .name = "sedlbauer_cs",
  400. },
  401. .probe = sedlbauer_probe,
  402. .remove = sedlbauer_detach,
  403. .id_table = sedlbauer_ids,
  404. .suspend = sedlbauer_suspend,
  405. .resume = sedlbauer_resume,
  406. };
  407. static int __init init_sedlbauer_cs(void)
  408. {
  409. return pcmcia_register_driver(&sedlbauer_driver);
  410. }
  411. static void __exit exit_sedlbauer_cs(void)
  412. {
  413. pcmcia_unregister_driver(&sedlbauer_driver);
  414. }
  415. module_init(init_sedlbauer_cs);
  416. module_exit(exit_sedlbauer_cs);