blob: f2476ffb04fda65d87d146b8729c1ac9080db153 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $Id: teles_cs.c,v 1.1.2.2 2004/01/25 15:07:06 keil Exp $ */
2/*======================================================================
3
Joe Perches475be4d2012-02-19 19:52:38 -08004 A teles S0 PCMCIA client driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07005
Joe Perches475be4d2012-02-19 19:52:38 -08006 Based on skeleton by David Hinds, dhinds@allegro.stanford.edu
7 Written by Christof Petig, christof.petig@wtal.de
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
Joe Perches475be4d2012-02-19 19:52:38 -08009 Also inspired by ELSA PCMCIA driver
10 by Klaus Lichtenwalder <Lichtenwalder@ACM.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
Joe Perches475be4d2012-02-19 19:52:38 -080012 Extensions to new hisax_pcmcia by Karsten Keil
13
14 minor changes to be compatible with kernel 2.4.x
15 by Jan.Schubert@GMX.li
16
17 ======================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/ptrace.h>
23#include <linux/slab.h>
24#include <linux/string.h>
25#include <linux/timer.h>
26#include <linux/ioport.h>
27#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Linus Torvalds1da177e2005-04-16 15:20:36 -070029#include <pcmcia/cistpl.h>
30#include <pcmcia/cisreg.h>
31#include <pcmcia/ds.h>
32#include "hisax_cfg.h"
33
34MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
35MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
36MODULE_LICENSE("GPL");
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39/*====================================================================*/
40
41/* Parameters that can be set with 'insmod' */
42
43static int protocol = 2; /* EURO-ISDN Default */
44module_param(protocol, int, 0);
45
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080046static int teles_cs_config(struct pcmcia_device *link);
Dominik Brodowskifba395e2006-03-31 17:21:06 +020047static void teles_cs_release(struct pcmcia_device *link);
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080048static void teles_detach(struct pcmcia_device *p_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050typedef struct local_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010051 struct pcmcia_device *p_dev;
Joe Perches475be4d2012-02-19 19:52:38 -080052 int busy;
53 int cardnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070054} local_info_t;
55
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080056static int teles_probe(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Joe Perches475be4d2012-02-19 19:52:38 -080058 local_info_t *local;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
Joe Perches475be4d2012-02-19 19:52:38 -080060 dev_dbg(&link->dev, "teles_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Joe Perches475be4d2012-02-19 19:52:38 -080062 /* Allocate space for private device-specific data */
63 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
64 if (!local) return -ENOMEM;
65 local->cardnr = -1;
Dominik Brodowskifd238232006-03-05 10:45:09 +010066
Joe Perches475be4d2012-02-19 19:52:38 -080067 local->p_dev = link;
68 link->priv = local;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Joe Perches475be4d2012-02-19 19:52:38 -080070 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
Joe Perches475be4d2012-02-19 19:52:38 -080072 return teles_cs_config(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070073} /* teles_attach */
74
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -080075static void teles_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Dominik Brodowskie2d40962006-03-02 00:09:29 +010077 local_info_t *info = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020079 dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Dominik Brodowskie2d40962006-03-02 00:09:29 +010081 info->busy = 1;
82 teles_cs_release(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Dominik Brodowskie2d40962006-03-02 00:09:29 +010084 kfree(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085} /* teles_detach */
86
Dominik Brodowski00990e72010-07-30 13:13:46 +020087static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070088{
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +020089 int j;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Dominik Brodowski90abdc32010-07-24 17:23:51 +020091 p_dev->io_lines = 5;
Dominik Brodowski00990e72010-07-30 13:13:46 +020092 p_dev->resource[0]->end = 96;
93 p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
94 p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
Dominik Brodowski90abdc32010-07-24 17:23:51 +020095
Dominik Brodowski00990e72010-07-30 13:13:46 +020096 if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +020097 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
Dominik Brodowski90abdc32010-07-24 17:23:51 +020098 if (!pcmcia_request_io(p_dev))
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +020099 return 0;
100 } else {
101 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200102 for (j = 0x2f0; j > 0x100; j -= 0x10) {
Dominik Brodowski90abdc32010-07-24 17:23:51 +0200103 p_dev->resource[0]->start = j;
104 if (!pcmcia_request_io(p_dev))
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200105 return 0;
106 }
107 }
108 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109}
110
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -0800111static int teles_cs_config(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Joe Perches475be4d2012-02-19 19:52:38 -0800113 int i;
114 IsdnCard_t icard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Joe Perches475be4d2012-02-19 19:52:38 -0800116 dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Joe Perches475be4d2012-02-19 19:52:38 -0800118 i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
119 if (i != 0)
120 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121
Joe Perches475be4d2012-02-19 19:52:38 -0800122 if (!link->irq)
123 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Joe Perches475be4d2012-02-19 19:52:38 -0800125 i = pcmcia_enable_device(link);
126 if (i != 0)
127 goto cs_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Joe Perches475be4d2012-02-19 19:52:38 -0800129 icard.para[0] = link->irq;
130 icard.para[1] = link->resource[0]->start;
131 icard.protocol = protocol;
132 icard.typ = ISDN_CTYPE_TELESPCMCIA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Joe Perches475be4d2012-02-19 19:52:38 -0800134 i = hisax_init_pcmcia(link, &(((local_info_t *)link->priv)->busy), &icard);
135 if (i < 0) {
136 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
137 i, (unsigned int) link->resource[0]->start);
138 teles_cs_release(link);
139 return -ENODEV;
140 }
141
142 ((local_info_t *)link->priv)->cardnr = i;
143 return 0;
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145cs_failed:
Joe Perches475be4d2012-02-19 19:52:38 -0800146 teles_cs_release(link);
147 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148} /* teles_cs_config */
149
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200150static void teles_cs_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151{
Joe Perches475be4d2012-02-19 19:52:38 -0800152 local_info_t *local = link->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Joe Perches475be4d2012-02-19 19:52:38 -0800154 dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Joe Perches475be4d2012-02-19 19:52:38 -0800156 if (local) {
157 if (local->cardnr >= 0) {
158 /* no unregister function with hisax */
159 HiSax_closecard(local->cardnr);
160 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Joe Perches475be4d2012-02-19 19:52:38 -0800163 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164} /* teles_cs_release */
165
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200166static int teles_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100167{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100168 local_info_t *dev = link->priv;
169
Joe Perches475be4d2012-02-19 19:52:38 -0800170 dev->busy = 1;
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100171
172 return 0;
173}
174
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200175static int teles_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100176{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100177 local_info_t *dev = link->priv;
178
Joe Perches475be4d2012-02-19 19:52:38 -0800179 dev->busy = 0;
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100180
181 return 0;
182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
Joe Perches25f8f542011-05-03 19:29:01 -0700185static const struct pcmcia_device_id teles_ids[] = {
Dominik Brodowski0a10d732005-06-27 16:28:24 -0700186 PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
187 PCMCIA_DEVICE_NULL,
188};
189MODULE_DEVICE_TABLE(pcmcia, teles_ids);
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191static struct pcmcia_driver teles_cs_driver = {
192 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200193 .name = "teles_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200194 .probe = teles_probe,
Greg Kroah-Hartmaned5a84c2012-12-21 13:13:05 -0800195 .remove = teles_detach,
Dominik Brodowski0a10d732005-06-27 16:28:24 -0700196 .id_table = teles_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100197 .suspend = teles_suspend,
198 .resume = teles_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199};
200
201static int __init init_teles_cs(void)
202{
203 return pcmcia_register_driver(&teles_cs_driver);
204}
205
206static void __exit exit_teles_cs(void)
207{
208 pcmcia_unregister_driver(&teles_cs_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209}
210
211module_init(init_teles_cs);
212module_exit(exit_teles_cs);