sedlbauer_cs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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) __devinit ;
  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) __devexit;
  69. typedef struct local_info_t {
  70. struct pcmcia_device *p_dev;
  71. int stop;
  72. int cardnr;
  73. } local_info_t;
  74. /*======================================================================
  75. sedlbauer_attach() creates an "instance" of the driver, allocating
  76. local data structures for one device. The device is registered
  77. with Card Services.
  78. The dev_link structure is initialized, but we don't actually
  79. configure the card at this point -- we wait until we receive a
  80. card insertion event.
  81. ======================================================================*/
  82. static int __devinit sedlbauer_probe(struct pcmcia_device *link)
  83. {
  84. local_info_t *local;
  85. dev_dbg(&link->dev, "sedlbauer_attach()\n");
  86. /* Allocate space for private device-specific data */
  87. local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
  88. if (!local) return -ENOMEM;
  89. local->cardnr = -1;
  90. local->p_dev = link;
  91. link->priv = local;
  92. /*
  93. General socket configuration defaults can go here. In this
  94. client, we assume very little, and rely on the CIS for almost
  95. everything. In most clients, many details (i.e., number, sizes,
  96. and attributes of IO windows) are fixed by the nature of the
  97. device, and can be hard-wired here.
  98. */
  99. /* from old sedl_cs
  100. */
  101. /* The io structure describes IO port mapping */
  102. link->io.NumPorts1 = 8;
  103. link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  104. link->io.IOAddrLines = 3;
  105. link->conf.Attributes = 0;
  106. link->conf.IntType = INT_MEMORY_AND_IO;
  107. return sedlbauer_config(link);
  108. } /* sedlbauer_attach */
  109. /*======================================================================
  110. This deletes a driver "instance". The device is de-registered
  111. with Card Services. If it has been released, all local data
  112. structures are freed. Otherwise, the structures will be freed
  113. when the device is released.
  114. ======================================================================*/
  115. static void __devexit sedlbauer_detach(struct pcmcia_device *link)
  116. {
  117. dev_dbg(&link->dev, "sedlbauer_detach(0x%p)\n", link);
  118. ((local_info_t *)link->priv)->stop = 1;
  119. sedlbauer_release(link);
  120. /* This points to the parent local_info_t struct */
  121. kfree(link->priv);
  122. } /* sedlbauer_detach */
  123. /*======================================================================
  124. sedlbauer_config() is scheduled to run after a CARD_INSERTION event
  125. is received, to configure the PCMCIA socket, and to make the
  126. device available to the system.
  127. ======================================================================*/
  128. static int sedlbauer_config_check(struct pcmcia_device *p_dev,
  129. cistpl_cftable_entry_t *cfg,
  130. cistpl_cftable_entry_t *dflt,
  131. unsigned int vcc,
  132. void *priv_data)
  133. {
  134. win_req_t *req = priv_data;
  135. if (cfg->index == 0)
  136. return -ENODEV;
  137. /* Does this card need audio output? */
  138. if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
  139. p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
  140. p_dev->conf.Status = CCSR_AUDIO_ENA;
  141. }
  142. /* Use power settings for Vcc and Vpp if present */
  143. /* Note that the CIS values need to be rescaled */
  144. if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  145. if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
  146. return -ENODEV;
  147. } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
  148. if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
  149. return -ENODEV;
  150. }
  151. if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
  152. p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
  153. else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
  154. p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
  155. p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
  156. /* IO window settings */
  157. p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
  158. if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
  159. cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
  160. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  161. if (!(io->flags & CISTPL_IO_8BIT))
  162. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
  163. if (!(io->flags & CISTPL_IO_16BIT))
  164. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  165. p_dev->io.BasePort1 = io->win[0].base;
  166. p_dev->io.NumPorts1 = io->win[0].len;
  167. if (io->nwin > 1) {
  168. p_dev->io.Attributes2 = p_dev->io.Attributes1;
  169. p_dev->io.BasePort2 = io->win[1].base;
  170. p_dev->io.NumPorts2 = io->win[1].len;
  171. }
  172. /* This reserves IO space but doesn't actually enable it */
  173. if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
  174. return -ENODEV;
  175. }
  176. /*
  177. Now set up a common memory window, if needed. There is room
  178. in the struct pcmcia_device structure for one memory window handle,
  179. but if the base addresses need to be saved, or if multiple
  180. windows are needed, the info should go in the private data
  181. structure for this device.
  182. Note that the memory window base is a physical address, and
  183. needs to be mapped to virtual space with ioremap() before it
  184. is used.
  185. */
  186. if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
  187. cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
  188. memreq_t map;
  189. req->Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
  190. req->Attributes |= WIN_ENABLE;
  191. req->Base = mem->win[0].host_addr;
  192. req->Size = mem->win[0].len;
  193. req->AccessSpeed = 0;
  194. if (pcmcia_request_window(p_dev, req, &p_dev->win) != 0)
  195. return -ENODEV;
  196. map.Page = 0;
  197. map.CardOffset = mem->win[0].card_addr;
  198. if (pcmcia_map_mem_page(p_dev, p_dev->win, &map) != 0)
  199. return -ENODEV;
  200. }
  201. return 0;
  202. }
  203. static int __devinit sedlbauer_config(struct pcmcia_device *link)
  204. {
  205. win_req_t *req;
  206. int ret;
  207. IsdnCard_t icard;
  208. dev_dbg(&link->dev, "sedlbauer_config(0x%p)\n", link);
  209. req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
  210. if (!req)
  211. return -ENOMEM;
  212. /*
  213. In this loop, we scan the CIS for configuration table entries,
  214. each of which describes a valid card configuration, including
  215. voltage, IO window, memory window, and interrupt settings.
  216. We make no assumptions about the card to be configured: we use
  217. just the information available in the CIS. In an ideal world,
  218. this would work for any PCMCIA card, but it requires a complete
  219. and accurate CIS. In practice, a driver usually "knows" most of
  220. these things without consulting the CIS, and most client drivers
  221. will only use the CIS to fill in implementation-defined details.
  222. */
  223. ret = pcmcia_loop_config(link, sedlbauer_config_check, req);
  224. if (ret)
  225. goto failed;
  226. /*
  227. This actually configures the PCMCIA socket -- setting up
  228. the I/O windows and the interrupt mapping, and putting the
  229. card and host interface into "Memory and IO" mode.
  230. */
  231. ret = pcmcia_request_configuration(link, &link->conf);
  232. if (ret)
  233. goto failed;
  234. /* Finally, report what we've done */
  235. dev_info(&link->dev, "index 0x%02x:",
  236. link->conf.ConfigIndex);
  237. if (link->conf.Vpp)
  238. printk(", Vpp %d.%d", link->conf.Vpp/10, link->conf.Vpp%10);
  239. if (link->conf.Attributes & CONF_ENABLE_IRQ)
  240. printk(", irq %d", link->irq);
  241. if (link->io.NumPorts1)
  242. printk(", io 0x%04x-0x%04x", link->io.BasePort1,
  243. link->io.BasePort1+link->io.NumPorts1-1);
  244. if (link->io.NumPorts2)
  245. printk(" & 0x%04x-0x%04x", link->io.BasePort2,
  246. link->io.BasePort2+link->io.NumPorts2-1);
  247. if (link->win)
  248. printk(", mem 0x%06lx-0x%06lx", req->Base,
  249. req->Base+req->Size-1);
  250. printk("\n");
  251. icard.para[0] = link->irq;
  252. icard.para[1] = link->io.BasePort1;
  253. icard.protocol = protocol;
  254. icard.typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
  255. ret = hisax_init_pcmcia(link,
  256. &(((local_info_t *)link->priv)->stop), &icard);
  257. if (ret < 0) {
  258. printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d at i/o %#x\n",
  259. ret, link->io.BasePort1);
  260. sedlbauer_release(link);
  261. return -ENODEV;
  262. } else
  263. ((local_info_t *)link->priv)->cardnr = ret;
  264. return 0;
  265. failed:
  266. sedlbauer_release(link);
  267. return -ENODEV;
  268. } /* sedlbauer_config */
  269. /*======================================================================
  270. After a card is removed, sedlbauer_release() will unregister the
  271. device, and release the PCMCIA configuration. If the device is
  272. still open, this will be postponed until it is closed.
  273. ======================================================================*/
  274. static void sedlbauer_release(struct pcmcia_device *link)
  275. {
  276. local_info_t *local = link->priv;
  277. dev_dbg(&link->dev, "sedlbauer_release(0x%p)\n", link);
  278. if (local) {
  279. if (local->cardnr >= 0) {
  280. /* no unregister function with hisax */
  281. HiSax_closecard(local->cardnr);
  282. }
  283. }
  284. pcmcia_disable_device(link);
  285. } /* sedlbauer_release */
  286. static int sedlbauer_suspend(struct pcmcia_device *link)
  287. {
  288. local_info_t *dev = link->priv;
  289. dev->stop = 1;
  290. return 0;
  291. }
  292. static int sedlbauer_resume(struct pcmcia_device *link)
  293. {
  294. local_info_t *dev = link->priv;
  295. dev->stop = 0;
  296. return 0;
  297. }
  298. static struct pcmcia_device_id sedlbauer_ids[] = {
  299. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "speed star II", "V 3.1", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a),
  300. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
  301. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
  302. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
  303. PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
  304. PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
  305. /* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
  306. PCMCIA_DEVICE_NULL
  307. };
  308. MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
  309. static struct pcmcia_driver sedlbauer_driver = {
  310. .owner = THIS_MODULE,
  311. .drv = {
  312. .name = "sedlbauer_cs",
  313. },
  314. .probe = sedlbauer_probe,
  315. .remove = __devexit_p(sedlbauer_detach),
  316. .id_table = sedlbauer_ids,
  317. .suspend = sedlbauer_suspend,
  318. .resume = sedlbauer_resume,
  319. };
  320. static int __init init_sedlbauer_cs(void)
  321. {
  322. return pcmcia_register_driver(&sedlbauer_driver);
  323. }
  324. static void __exit exit_sedlbauer_cs(void)
  325. {
  326. pcmcia_unregister_driver(&sedlbauer_driver);
  327. }
  328. module_init(init_sedlbauer_cs);
  329. module_exit(exit_sedlbauer_cs);