treewide: Add SPDX license identifier for more missed files
[linux-2.6-block.git] / drivers / isdn / hisax / teles_cs.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /* $Id: teles_cs.c,v 1.1.2.2 2004/01/25 15:07:06 keil Exp $ */
3 /*======================================================================
4
5   A teles S0 PCMCIA client driver
6
7   Based on skeleton by David Hinds, dhinds@allegro.stanford.edu
8   Written by Christof Petig, christof.petig@wtal.de
9
10   Also inspired by ELSA PCMCIA driver
11   by Klaus Lichtenwalder <Lichtenwalder@ACM.org>
12
13   Extensions to new hisax_pcmcia by Karsten Keil
14
15   minor changes to be compatible with kernel 2.4.x
16   by Jan.Schubert@GMX.li
17
18   ======================================================================*/
19
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/ptrace.h>
24 #include <linux/slab.h>
25 #include <linux/string.h>
26 #include <linux/timer.h>
27 #include <linux/ioport.h>
28 #include <asm/io.h>
29
30 #include <pcmcia/cistpl.h>
31 #include <pcmcia/cisreg.h>
32 #include <pcmcia/ds.h>
33 #include "hisax_cfg.h"
34
35 MODULE_DESCRIPTION("ISDN4Linux: PCMCIA client driver for Teles PCMCIA cards");
36 MODULE_AUTHOR("Christof Petig, christof.petig@wtal.de, Karsten Keil, kkeil@suse.de");
37 MODULE_LICENSE("GPL");
38
39
40 /*====================================================================*/
41
42 /* Parameters that can be set with 'insmod' */
43
44 static int protocol = 2;        /* EURO-ISDN Default */
45 module_param(protocol, int, 0);
46
47 static int teles_cs_config(struct pcmcia_device *link);
48 static void teles_cs_release(struct pcmcia_device *link);
49 static void teles_detach(struct pcmcia_device *p_dev);
50
51 typedef struct local_info_t {
52         struct pcmcia_device    *p_dev;
53         int                 busy;
54         int                     cardnr;
55 } local_info_t;
56
57 static int teles_probe(struct pcmcia_device *link)
58 {
59         local_info_t *local;
60
61         dev_dbg(&link->dev, "teles_attach()\n");
62
63         /* Allocate space for private device-specific data */
64         local = kzalloc(sizeof(local_info_t), GFP_KERNEL);
65         if (!local) return -ENOMEM;
66         local->cardnr = -1;
67
68         local->p_dev = link;
69         link->priv = local;
70
71         link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
72
73         return teles_cs_config(link);
74 } /* teles_attach */
75
76 static void teles_detach(struct pcmcia_device *link)
77 {
78         local_info_t *info = link->priv;
79
80         dev_dbg(&link->dev, "teles_detach(0x%p)\n", link);
81
82         info->busy = 1;
83         teles_cs_release(link);
84
85         kfree(info);
86 } /* teles_detach */
87
88 static int teles_cs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
89 {
90         int j;
91
92         p_dev->io_lines = 5;
93         p_dev->resource[0]->end = 96;
94         p_dev->resource[0]->flags &= IO_DATA_PATH_WIDTH;
95         p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO;
96
97         if ((p_dev->resource[0]->end) && p_dev->resource[0]->start) {
98                 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
99                 if (!pcmcia_request_io(p_dev))
100                         return 0;
101         } else {
102                 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
103                 for (j = 0x2f0; j > 0x100; j -= 0x10) {
104                         p_dev->resource[0]->start = j;
105                         if (!pcmcia_request_io(p_dev))
106                                 return 0;
107                 }
108         }
109         return -ENODEV;
110 }
111
112 static int teles_cs_config(struct pcmcia_device *link)
113 {
114         int i;
115         IsdnCard_t icard;
116
117         dev_dbg(&link->dev, "teles_config(0x%p)\n", link);
118
119         i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
120         if (i != 0)
121                 goto cs_failed;
122
123         if (!link->irq)
124                 goto cs_failed;
125
126         i = pcmcia_enable_device(link);
127         if (i != 0)
128                 goto cs_failed;
129
130         icard.para[0] = link->irq;
131         icard.para[1] = link->resource[0]->start;
132         icard.protocol = protocol;
133         icard.typ = ISDN_CTYPE_TELESPCMCIA;
134
135         i = hisax_init_pcmcia(link, &(((local_info_t *)link->priv)->busy), &icard);
136         if (i < 0) {
137                 printk(KERN_ERR "teles_cs: failed to initialize Teles PCMCIA %d at i/o %#x\n",
138                        i, (unsigned int) link->resource[0]->start);
139                 teles_cs_release(link);
140                 return -ENODEV;
141         }
142
143         ((local_info_t *)link->priv)->cardnr = i;
144         return 0;
145
146 cs_failed:
147         teles_cs_release(link);
148         return -ENODEV;
149 } /* teles_cs_config */
150
151 static void teles_cs_release(struct pcmcia_device *link)
152 {
153         local_info_t *local = link->priv;
154
155         dev_dbg(&link->dev, "teles_cs_release(0x%p)\n", link);
156
157         if (local) {
158                 if (local->cardnr >= 0) {
159                         /* no unregister function with hisax */
160                         HiSax_closecard(local->cardnr);
161                 }
162         }
163
164         pcmcia_disable_device(link);
165 } /* teles_cs_release */
166
167 static int teles_suspend(struct pcmcia_device *link)
168 {
169         local_info_t *dev = link->priv;
170
171         dev->busy = 1;
172
173         return 0;
174 }
175
176 static int teles_resume(struct pcmcia_device *link)
177 {
178         local_info_t *dev = link->priv;
179
180         dev->busy = 0;
181
182         return 0;
183 }
184
185
186 static const struct pcmcia_device_id teles_ids[] = {
187         PCMCIA_DEVICE_PROD_ID12("TELES", "S0/PC", 0x67b50eae, 0xe9e70119),
188         PCMCIA_DEVICE_NULL,
189 };
190 MODULE_DEVICE_TABLE(pcmcia, teles_ids);
191
192 static struct pcmcia_driver teles_cs_driver = {
193         .owner          = THIS_MODULE,
194         .name           = "teles_cs",
195         .probe          = teles_probe,
196         .remove         = teles_detach,
197         .id_table       = teles_ids,
198         .suspend        = teles_suspend,
199         .resume         = teles_resume,
200 };
201 module_pcmcia_driver(teles_cs_driver);