Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
awilliam
GitHub Repository: awilliam/linux-vfio
Path: blob/master/drivers/isdn/hardware/avm/avm_cs.c
15111 views
1
/* $Id: avm_cs.c,v 1.4.6.3 2001/09/23 22:24:33 kai Exp $
2
*
3
* A PCMCIA client driver for AVM B1/M1/M2
4
*
5
* Copyright 1999 by Carsten Paeth <[email protected]>
6
*
7
* This software may be used and distributed according to the terms
8
* of the GNU General Public License, incorporated herein by reference.
9
*
10
*/
11
12
#include <linux/module.h>
13
#include <linux/kernel.h>
14
#include <linux/init.h>
15
#include <linux/ptrace.h>
16
#include <linux/string.h>
17
#include <linux/tty.h>
18
#include <linux/serial.h>
19
#include <linux/major.h>
20
#include <asm/io.h>
21
#include <asm/system.h>
22
23
#include <pcmcia/cistpl.h>
24
#include <pcmcia/ciscode.h>
25
#include <pcmcia/ds.h>
26
#include <pcmcia/cisreg.h>
27
28
#include <linux/skbuff.h>
29
#include <linux/capi.h>
30
#include <linux/b1lli.h>
31
#include <linux/b1pcmcia.h>
32
33
/*====================================================================*/
34
35
MODULE_DESCRIPTION("CAPI4Linux: PCMCIA client driver for AVM B1/M1/M2");
36
MODULE_AUTHOR("Carsten Paeth");
37
MODULE_LICENSE("GPL");
38
39
/*====================================================================*/
40
41
static int avmcs_config(struct pcmcia_device *link);
42
static void avmcs_release(struct pcmcia_device *link);
43
static void avmcs_detach(struct pcmcia_device *p_dev);
44
45
static int avmcs_probe(struct pcmcia_device *p_dev)
46
{
47
/* General socket configuration */
48
p_dev->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_SET_IO;
49
p_dev->config_index = 1;
50
p_dev->config_regs = PRESENT_OPTION;
51
52
return avmcs_config(p_dev);
53
} /* avmcs_attach */
54
55
56
static void avmcs_detach(struct pcmcia_device *link)
57
{
58
avmcs_release(link);
59
} /* avmcs_detach */
60
61
static int avmcs_configcheck(struct pcmcia_device *p_dev, void *priv_data)
62
{
63
p_dev->resource[0]->end = 16;
64
p_dev->resource[0]->flags &= ~IO_DATA_PATH_WIDTH;
65
p_dev->resource[0]->flags |= IO_DATA_PATH_WIDTH_8;
66
67
return pcmcia_request_io(p_dev);
68
}
69
70
static int avmcs_config(struct pcmcia_device *link)
71
{
72
int i = -1;
73
char devname[128];
74
int cardtype;
75
int (*addcard)(unsigned int port, unsigned irq);
76
77
devname[0] = 0;
78
if (link->prod_id[1])
79
strlcpy(devname, link->prod_id[1], sizeof(devname));
80
81
/*
82
* find IO port
83
*/
84
if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
85
return -ENODEV;
86
87
do {
88
if (!link->irq) {
89
/* undo */
90
pcmcia_disable_device(link);
91
break;
92
}
93
94
/*
95
* configure the PCMCIA socket
96
*/
97
i = pcmcia_enable_device(link);
98
if (i != 0) {
99
pcmcia_disable_device(link);
100
break;
101
}
102
103
} while (0);
104
105
if (devname[0]) {
106
char *s = strrchr(devname, ' ');
107
if (!s)
108
s = devname;
109
else s++;
110
if (strcmp("M1", s) == 0) {
111
cardtype = AVM_CARDTYPE_M1;
112
} else if (strcmp("M2", s) == 0) {
113
cardtype = AVM_CARDTYPE_M2;
114
} else {
115
cardtype = AVM_CARDTYPE_B1;
116
}
117
} else
118
cardtype = AVM_CARDTYPE_B1;
119
120
/* If any step failed, release any partially configured state */
121
if (i != 0) {
122
avmcs_release(link);
123
return -ENODEV;
124
}
125
126
127
switch (cardtype) {
128
case AVM_CARDTYPE_M1: addcard = b1pcmcia_addcard_m1; break;
129
case AVM_CARDTYPE_M2: addcard = b1pcmcia_addcard_m2; break;
130
default:
131
case AVM_CARDTYPE_B1: addcard = b1pcmcia_addcard_b1; break;
132
}
133
if ((i = (*addcard)(link->resource[0]->start, link->irq)) < 0) {
134
dev_err(&link->dev,
135
"avm_cs: failed to add AVM-Controller at i/o %#x, irq %d\n",
136
(unsigned int) link->resource[0]->start, link->irq);
137
avmcs_release(link);
138
return -ENODEV;
139
}
140
return 0;
141
142
} /* avmcs_config */
143
144
145
static void avmcs_release(struct pcmcia_device *link)
146
{
147
b1pcmcia_delcard(link->resource[0]->start, link->irq);
148
pcmcia_disable_device(link);
149
} /* avmcs_release */
150
151
152
static const struct pcmcia_device_id avmcs_ids[] = {
153
PCMCIA_DEVICE_PROD_ID12("AVM", "ISDN-Controller B1", 0x95d42008, 0x845dc335),
154
PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M1", 0x95d42008, 0x81e10430),
155
PCMCIA_DEVICE_PROD_ID12("AVM", "Mobile ISDN-Controller M2", 0x95d42008, 0x18e8558a),
156
PCMCIA_DEVICE_NULL
157
};
158
MODULE_DEVICE_TABLE(pcmcia, avmcs_ids);
159
160
static struct pcmcia_driver avmcs_driver = {
161
.owner = THIS_MODULE,
162
.name = "avm_cs",
163
.probe = avmcs_probe,
164
.remove = avmcs_detach,
165
.id_table = avmcs_ids,
166
};
167
168
static int __init avmcs_init(void)
169
{
170
return pcmcia_register_driver(&avmcs_driver);
171
}
172
173
static void __exit avmcs_exit(void)
174
{
175
pcmcia_unregister_driver(&avmcs_driver);
176
}
177
178
module_init(avmcs_init);
179
module_exit(avmcs_exit);
180
181