blob: 68f50495d166b25deedab36a5ff7b477b631622f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*======================================================================
2
Joe Perches475be4d2012-02-19 19:52:38 -08003 A Sedlbauer PCMCIA client driver
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Joe Perches475be4d2012-02-19 19:52:38 -08005 This driver is for the Sedlbauer Speed Star and Speed Star II,
6 which are ISDN PCMCIA Cards.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
Joe Perches475be4d2012-02-19 19:52:38 -08008 The contents of this file are subject to the Mozilla Public
9 License Version 1.1 (the "License"); you may not use this file
10 except in compliance with the License. You may obtain a copy of
11 the License at http://www.mozilla.org/MPL/
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
Joe Perches475be4d2012-02-19 19:52:38 -080013 Software distributed under the License is distributed on an "AS
14 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 rights and limitations under the License.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Joe Perches475be4d2012-02-19 19:52:38 -080018 The initial developer of the original code is David A. Hinds
19 <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
20 are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Joe Perches475be4d2012-02-19 19:52:38 -080022 Modifications from dummy_cs.c are Copyright (C) 1999-2001 Marcus Niemann
23 <maniemann@users.sourceforge.net>. All Rights Reserved.
24
25 Alternatively, the contents of this file may be used under the
26 terms of the GNU General Public License version 2 (the "GPL"), in
27 which case the provisions of the GPL are applicable instead of the
28 above. If you wish to allow the use of your version of this file
29 only under the terms of the GPL and not to allow others to use
30 your version of this file under the MPL, indicate your decision
31 by deleting the provisions above and replace them with the notice
32 and other provisions required by the GPL. If you do not delete
33 the provisions above, a recipient may use your version of this
34 file under either the MPL or the GPL.
35
36 ======================================================================*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/ptrace.h>
42#include <linux/slab.h>
43#include <linux/string.h>
44#include <linux/timer.h>
45#include <linux/ioport.h>
46#include <asm/io.h>
47#include <asm/system.h>
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <pcmcia/cistpl.h>
50#include <pcmcia/cisreg.h>
51#include <pcmcia/ds.h>
52#include "hisax_cfg.h"
53
54MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Sedlbauer cards");
55MODULE_AUTHOR("Marcus Niemann");
56MODULE_LICENSE("Dual MPL/GPL");
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59/*====================================================================*/
60
61/* Parameters that can be set with 'insmod' */
62
63static int protocol = 2; /* EURO-ISDN Default */
64module_param(protocol, int, 0);
65
Joe Perches475be4d2012-02-19 19:52:38 -080066static int sedlbauer_config(struct pcmcia_device *link) __devinit;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020067static void sedlbauer_release(struct pcmcia_device *link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Henne93b39a02010-03-25 12:05:29 +000069static void sedlbauer_detach(struct pcmcia_device *p_dev) __devexit;
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071typedef struct local_info_t {
Dominik Brodowskifd238232006-03-05 10:45:09 +010072 struct pcmcia_device *p_dev;
Joe Perches475be4d2012-02-19 19:52:38 -080073 int stop;
74 int cardnr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075} local_info_t;
76
Henne93b39a02010-03-25 12:05:29 +000077static int __devinit sedlbauer_probe(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Joe Perches475be4d2012-02-19 19:52:38 -080079 local_info_t *local;
Dominik Brodowskifba395e2006-03-31 17:21:06 +020080
Joe Perches475be4d2012-02-19 19:52:38 -080081 dev_dbg(&link->dev, "sedlbauer_attach()\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Joe Perches475be4d2012-02-19 19:52:38 -080083 /* Allocate space for private device-specific data */
84 local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
85 if (!local) return -ENOMEM;
86 local->cardnr = -1;
Dominik Brodowskifd238232006-03-05 10:45:09 +010087
Joe Perches475be4d2012-02-19 19:52:38 -080088 local->p_dev = link;
89 link->priv = local;
Dominik Brodowskifd238232006-03-05 10:45:09 +010090
Joe Perches475be4d2012-02-19 19:52:38 -080091 return sedlbauer_config(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070092} /* sedlbauer_attach */
93
Henne93b39a02010-03-25 12:05:29 +000094static void __devexit sedlbauer_detach(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
Dominik Brodowskie773cfe2009-10-24 15:50:13 +020096 dev_dbg(&link->dev, "sedlbauer_detach(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Dominik Brodowskie2d40962006-03-02 00:09:29 +010098 ((local_info_t *)link->priv)->stop = 1;
99 sedlbauer_release(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Dominik Brodowskie2d40962006-03-02 00:09:29 +0100101 /* This points to the parent local_info_t struct */
102 kfree(link->priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103} /* sedlbauer_detach */
104
Dominik Brodowski00990e72010-07-30 13:13:46 +0200105static int sedlbauer_config_check(struct pcmcia_device *p_dev, void *priv_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
Dominik Brodowski00990e72010-07-30 13:13:46 +0200107 if (p_dev->config_index == 0)
108 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Dominik Brodowski00990e72010-07-30 13:13:46 +0200110 p_dev->io_lines = 3;
111 return pcmcia_request_io(p_dev);
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200112}
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100113
Henne93b39a02010-03-25 12:05:29 +0000114static int __devinit sedlbauer_config(struct pcmcia_device *link)
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200115{
Joe Perches475be4d2012-02-19 19:52:38 -0800116 int ret;
117 IsdnCard_t icard;
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200118
Joe Perches475be4d2012-02-19 19:52:38 -0800119 dev_dbg(&link->dev, "sedlbauer_config(0x%p)\n", link);
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200120
Joe Perches475be4d2012-02-19 19:52:38 -0800121 link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_CHECK_VCC |
122 CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO | CONF_AUTO_SET_IO;
Dominik Brodowski440eed42010-07-30 09:51:52 +0200123
Joe Perches475be4d2012-02-19 19:52:38 -0800124 ret = pcmcia_loop_config(link, sedlbauer_config_check, NULL);
125 if (ret)
126 goto failed;
Dominik Brodowski50db3fd2006-01-15 10:05:19 +0100127
Joe Perches475be4d2012-02-19 19:52:38 -0800128 ret = pcmcia_enable_device(link);
129 if (ret)
130 goto failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Joe Perches475be4d2012-02-19 19:52:38 -0800132 icard.para[0] = link->irq;
133 icard.para[1] = link->resource[0]->start;
134 icard.protocol = protocol;
135 icard.typ = ISDN_CTYPE_SEDLBAUER_PCMCIA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Joe Perches475be4d2012-02-19 19:52:38 -0800137 ret = hisax_init_pcmcia(link,
138 &(((local_info_t *)link->priv)->stop), &icard);
139 if (ret < 0) {
140 printk(KERN_ERR "sedlbauer_cs: failed to initialize SEDLBAUER PCMCIA %d with %pR\n",
141 ret, link->resource[0]);
142 sedlbauer_release(link);
143 return -ENODEV;
144 } else
145 ((local_info_t *)link->priv)->cardnr = ret;
146
147 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Dominik Brodowski5fcd4da2008-07-29 08:38:55 +0200149failed:
Joe Perches475be4d2012-02-19 19:52:38 -0800150 sedlbauer_release(link);
151 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153} /* sedlbauer_config */
154
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200155static void sedlbauer_release(struct pcmcia_device *link)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Joe Perches475be4d2012-02-19 19:52:38 -0800157 local_info_t *local = link->priv;
158 dev_dbg(&link->dev, "sedlbauer_release(0x%p)\n", link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159
Joe Perches475be4d2012-02-19 19:52:38 -0800160 if (local) {
161 if (local->cardnr >= 0) {
162 /* no unregister function with hisax */
163 HiSax_closecard(local->cardnr);
164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
Joe Perches475be4d2012-02-19 19:52:38 -0800167 pcmcia_disable_device(link);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168} /* sedlbauer_release */
169
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200170static int sedlbauer_suspend(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100171{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100172 local_info_t *dev = link->priv;
173
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100174 dev->stop = 1;
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100175
176 return 0;
177}
178
Dominik Brodowskifba395e2006-03-31 17:21:06 +0200179static int sedlbauer_resume(struct pcmcia_device *link)
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100180{
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100181 local_info_t *dev = link->priv;
182
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100183 dev->stop = 0;
184
185 return 0;
186}
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Joe Perches25f8f542011-05-03 19:29:01 -0700189static const struct pcmcia_device_id sedlbauer_ids[] = {
Karsten Keil84d370b2005-09-14 14:19:13 -0700190 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "speed star II", "V 3.1", 0x81fb79f5, 0xf3612e1d, 0x6b95c78a),
Dominik Brodowski70799732005-06-27 16:28:41 -0700191 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D67", 0x81fb79f5, 0xe4e9bc12, 0x397b7e90),
192 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", "4D98", 0x81fb79f5, 0xe4e9bc12, 0x2e5c7fce),
193 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (C) 93-94 VK", 0x81fb79f5, 0xe4e9bc12, 0x8db143fe),
194 PCMCIA_DEVICE_PROD_ID123("SEDLBAUER", "ISDN-Adapter", " (c) 93-95 VK", 0x81fb79f5, 0xe4e9bc12, 0xb391ab4c),
195 PCMCIA_DEVICE_PROD_ID12("HST High Soft Tech GmbH", "Saphir II B", 0xd79e0b84, 0x21d083ae),
196/* PCMCIA_DEVICE_PROD_ID1234("SEDLBAUER", 0x81fb79f5), */ /* too generic*/
197 PCMCIA_DEVICE_NULL
198};
199MODULE_DEVICE_TABLE(pcmcia, sedlbauer_ids);
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static struct pcmcia_driver sedlbauer_driver = {
202 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200203 .name = "sedlbauer_cs",
Dominik Brodowski15b99ac2006-03-31 17:26:06 +0200204 .probe = sedlbauer_probe,
Henne93b39a02010-03-25 12:05:29 +0000205 .remove = __devexit_p(sedlbauer_detach),
Dominik Brodowski70799732005-06-27 16:28:41 -0700206 .id_table = sedlbauer_ids,
Dominik Brodowski98e4c282005-11-14 21:21:18 +0100207 .suspend = sedlbauer_suspend,
208 .resume = sedlbauer_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209};
210
211static int __init init_sedlbauer_cs(void)
212{
213 return pcmcia_register_driver(&sedlbauer_driver);
214}
215
216static void __exit exit_sedlbauer_cs(void)
217{
218 pcmcia_unregister_driver(&sedlbauer_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219}
220
221module_init(init_sedlbauer_cs);
222module_exit(exit_sedlbauer_cs);