xref: /openbmc/linux/drivers/isdn/hardware/mISDN/mISDNinfineon.c (revision ad65ffd12dccf6d1031298eacc060327751084da)
1cae86d4aSKarsten Keil /*
2cae86d4aSKarsten Keil  * mISDNinfineon.c
3cae86d4aSKarsten Keil  *		Support for cards based on following Infineon ISDN chipsets
4cae86d4aSKarsten Keil  *		- ISAC + HSCX
5cae86d4aSKarsten Keil  *		- IPAC and IPAC-X
6cae86d4aSKarsten Keil  *		- ISAC-SX + HSCX
7cae86d4aSKarsten Keil  *
8cae86d4aSKarsten Keil  * Supported cards:
9cae86d4aSKarsten Keil  *		- Dialogic Diva 2.0
10cae86d4aSKarsten Keil  *		- Dialogic Diva 2.0U
11cae86d4aSKarsten Keil  *		- Dialogic Diva 2.01
12cae86d4aSKarsten Keil  *		- Dialogic Diva 2.02
13cae86d4aSKarsten Keil  *		- Sedlbauer Speedwin
14cae86d4aSKarsten Keil  *		- HST Saphir3
15cae86d4aSKarsten Keil  *		- Develo (former ELSA) Microlink PCI (Quickstep 1000)
16cae86d4aSKarsten Keil  *		- Develo (former ELSA) Quickstep 3000
17cae86d4aSKarsten Keil  *		- Berkom Scitel BRIX Quadro
18cae86d4aSKarsten Keil  *		- Dr.Neuhaus (Sagem) Niccy
19cae86d4aSKarsten Keil  *
20cae86d4aSKarsten Keil  *
21cae86d4aSKarsten Keil  *
22cae86d4aSKarsten Keil  * Author       Karsten Keil <keil@isdn4linux.de>
23cae86d4aSKarsten Keil  *
24cae86d4aSKarsten Keil  * Copyright 2009  by Karsten Keil <keil@isdn4linux.de>
25cae86d4aSKarsten Keil  *
26cae86d4aSKarsten Keil  * This program is free software; you can redistribute it and/or modify
27cae86d4aSKarsten Keil  * it under the terms of the GNU General Public License version 2 as
28cae86d4aSKarsten Keil  * published by the Free Software Foundation.
29cae86d4aSKarsten Keil  *
30cae86d4aSKarsten Keil  * This program is distributed in the hope that it will be useful,
31cae86d4aSKarsten Keil  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32cae86d4aSKarsten Keil  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33cae86d4aSKarsten Keil  * GNU General Public License for more details.
34cae86d4aSKarsten Keil  *
35cae86d4aSKarsten Keil  * You should have received a copy of the GNU General Public License
36cae86d4aSKarsten Keil  * along with this program; if not, write to the Free Software
37cae86d4aSKarsten Keil  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38cae86d4aSKarsten Keil  *
39cae86d4aSKarsten Keil  */
40cae86d4aSKarsten Keil 
41cae86d4aSKarsten Keil #include <linux/module.h>
42cae86d4aSKarsten Keil #include <linux/pci.h>
43cae86d4aSKarsten Keil #include <linux/delay.h>
44cae86d4aSKarsten Keil #include <linux/mISDNhw.h>
455a0e3ad6STejun Heo #include <linux/slab.h>
46cae86d4aSKarsten Keil #include "ipac.h"
47cae86d4aSKarsten Keil 
48cae86d4aSKarsten Keil #define INFINEON_REV	"1.0"
49cae86d4aSKarsten Keil 
50cae86d4aSKarsten Keil static int inf_cnt;
51cae86d4aSKarsten Keil static u32 debug;
52cae86d4aSKarsten Keil static u32 irqloops = 4;
53cae86d4aSKarsten Keil 
54cae86d4aSKarsten Keil enum inf_types {
55cae86d4aSKarsten Keil 	INF_NONE,
56cae86d4aSKarsten Keil 	INF_DIVA20,
57cae86d4aSKarsten Keil 	INF_DIVA20U,
58cae86d4aSKarsten Keil 	INF_DIVA201,
59cae86d4aSKarsten Keil 	INF_DIVA202,
60cae86d4aSKarsten Keil 	INF_SPEEDWIN,
61cae86d4aSKarsten Keil 	INF_SAPHIR3,
62cae86d4aSKarsten Keil 	INF_QS1000,
63cae86d4aSKarsten Keil 	INF_QS3000,
64cae86d4aSKarsten Keil 	INF_NICCY,
65cae86d4aSKarsten Keil 	INF_SCT_1,
66cae86d4aSKarsten Keil 	INF_SCT_2,
67cae86d4aSKarsten Keil 	INF_SCT_3,
68cae86d4aSKarsten Keil 	INF_SCT_4,
69cae86d4aSKarsten Keil 	INF_GAZEL_R685,
70cae86d4aSKarsten Keil 	INF_GAZEL_R753
71cae86d4aSKarsten Keil };
72cae86d4aSKarsten Keil 
73cae86d4aSKarsten Keil enum addr_mode {
74cae86d4aSKarsten Keil 	AM_NONE = 0,
75cae86d4aSKarsten Keil 	AM_IO,
76cae86d4aSKarsten Keil 	AM_MEMIO,
77cae86d4aSKarsten Keil 	AM_IND_IO,
78cae86d4aSKarsten Keil };
79cae86d4aSKarsten Keil 
80cae86d4aSKarsten Keil struct inf_cinfo {
81cae86d4aSKarsten Keil 	enum inf_types	typ;
82cae86d4aSKarsten Keil 	const char	*full;
83cae86d4aSKarsten Keil 	const char	*name;
84cae86d4aSKarsten Keil 	enum addr_mode	cfg_mode;
85cae86d4aSKarsten Keil 	enum addr_mode	addr_mode;
86cae86d4aSKarsten Keil 	u8		cfg_bar;
87cae86d4aSKarsten Keil 	u8		addr_bar;
88cae86d4aSKarsten Keil 	void		*irqfunc;
89cae86d4aSKarsten Keil };
90cae86d4aSKarsten Keil 
91cae86d4aSKarsten Keil struct _ioaddr {
92cae86d4aSKarsten Keil 	enum addr_mode	mode;
93cae86d4aSKarsten Keil 	union {
94cae86d4aSKarsten Keil 		void __iomem	*p;
95cae86d4aSKarsten Keil 		struct _ioport	io;
96cae86d4aSKarsten Keil 	} a;
97cae86d4aSKarsten Keil };
98cae86d4aSKarsten Keil 
99cae86d4aSKarsten Keil struct _iohandle {
100cae86d4aSKarsten Keil 	enum addr_mode	mode;
101cae86d4aSKarsten Keil 	resource_size_t	size;
102cae86d4aSKarsten Keil 	resource_size_t	start;
103cae86d4aSKarsten Keil 	void __iomem	*p;
104cae86d4aSKarsten Keil };
105cae86d4aSKarsten Keil 
106cae86d4aSKarsten Keil struct inf_hw {
107cae86d4aSKarsten Keil 	struct list_head	list;
108cae86d4aSKarsten Keil 	struct pci_dev		*pdev;
109cae86d4aSKarsten Keil 	const struct inf_cinfo	*ci;
110cae86d4aSKarsten Keil 	char			name[MISDN_MAX_IDLEN];
111cae86d4aSKarsten Keil 	u32			irq;
112cae86d4aSKarsten Keil 	u32			irqcnt;
113cae86d4aSKarsten Keil 	struct _iohandle	cfg;
114cae86d4aSKarsten Keil 	struct _iohandle	addr;
115cae86d4aSKarsten Keil 	struct _ioaddr		isac;
116cae86d4aSKarsten Keil 	struct _ioaddr		hscx;
117cae86d4aSKarsten Keil 	spinlock_t		lock;	/* HW access lock */
118cae86d4aSKarsten Keil 	struct ipac_hw		ipac;
119cae86d4aSKarsten Keil 	struct inf_hw		*sc[3];	/* slave cards */
120cae86d4aSKarsten Keil };
121cae86d4aSKarsten Keil 
122cae86d4aSKarsten Keil 
123cae86d4aSKarsten Keil #define PCI_SUBVENDOR_HST_SAPHIR3       0x52
124cae86d4aSKarsten Keil #define PCI_SUBVENDOR_SEDLBAUER_PCI     0x53
125cae86d4aSKarsten Keil #define PCI_SUB_ID_SEDLBAUER            0x01
126cae86d4aSKarsten Keil 
127cae86d4aSKarsten Keil static struct pci_device_id infineon_ids[] __devinitdata = {
128d930d1a1SPeter Huewe 	{ PCI_VDEVICE(EICON, PCI_DEVICE_ID_EICON_DIVA20), INF_DIVA20 },
129d930d1a1SPeter Huewe 	{ PCI_VDEVICE(EICON, PCI_DEVICE_ID_EICON_DIVA20_U), INF_DIVA20U },
130d930d1a1SPeter Huewe 	{ PCI_VDEVICE(EICON, PCI_DEVICE_ID_EICON_DIVA201), INF_DIVA201 },
131d930d1a1SPeter Huewe 	{ PCI_VDEVICE(EICON, PCI_DEVICE_ID_EICON_DIVA202), INF_DIVA202 },
132cae86d4aSKarsten Keil 	{ PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_100,
133cae86d4aSKarsten Keil 	  PCI_SUBVENDOR_SEDLBAUER_PCI, PCI_SUB_ID_SEDLBAUER, 0, 0,
134cae86d4aSKarsten Keil 	  INF_SPEEDWIN },
135cae86d4aSKarsten Keil 	{ PCI_VENDOR_ID_TIGERJET, PCI_DEVICE_ID_TIGERJET_100,
136cae86d4aSKarsten Keil 	  PCI_SUBVENDOR_HST_SAPHIR3, PCI_SUB_ID_SEDLBAUER, 0, 0, INF_SAPHIR3 },
137d930d1a1SPeter Huewe 	{ PCI_VDEVICE(ELSA, PCI_DEVICE_ID_ELSA_MICROLINK), INF_QS1000 },
138d930d1a1SPeter Huewe 	{ PCI_VDEVICE(ELSA, PCI_DEVICE_ID_ELSA_QS3000), INF_QS3000 },
139d930d1a1SPeter Huewe 	{ PCI_VDEVICE(SATSAGEM, PCI_DEVICE_ID_SATSAGEM_NICCY), INF_NICCY },
140cae86d4aSKarsten Keil 	{ PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
141cae86d4aSKarsten Keil 	  PCI_VENDOR_ID_BERKOM, PCI_DEVICE_ID_BERKOM_SCITEL_QUADRO, 0, 0,
142cae86d4aSKarsten Keil 	  INF_SCT_1 },
143d930d1a1SPeter Huewe 	{ PCI_VDEVICE(PLX, PCI_DEVICE_ID_PLX_R685), INF_GAZEL_R685 },
144d930d1a1SPeter Huewe 	{ PCI_VDEVICE(PLX, PCI_DEVICE_ID_PLX_R753), INF_GAZEL_R753 },
145d930d1a1SPeter Huewe 	{ PCI_VDEVICE(PLX, PCI_DEVICE_ID_PLX_DJINN_ITOO), INF_GAZEL_R753 },
146d930d1a1SPeter Huewe 	{ PCI_VDEVICE(PLX, PCI_DEVICE_ID_PLX_OLITEC), INF_GAZEL_R753 },
147cae86d4aSKarsten Keil 	{ }
148cae86d4aSKarsten Keil };
149cae86d4aSKarsten Keil MODULE_DEVICE_TABLE(pci, infineon_ids);
150cae86d4aSKarsten Keil 
151cae86d4aSKarsten Keil /* PCI interface specific defines */
152cae86d4aSKarsten Keil /* Diva 2.0/2.0U */
153cae86d4aSKarsten Keil #define DIVA_HSCX_PORT		0x00
154cae86d4aSKarsten Keil #define DIVA_HSCX_ALE		0x04
155cae86d4aSKarsten Keil #define DIVA_ISAC_PORT		0x08
156cae86d4aSKarsten Keil #define DIVA_ISAC_ALE		0x0C
157cae86d4aSKarsten Keil #define DIVA_PCI_CTRL           0x10
158cae86d4aSKarsten Keil 
159cae86d4aSKarsten Keil /* DIVA_PCI_CTRL bits */
160cae86d4aSKarsten Keil #define DIVA_IRQ_BIT		0x01
161cae86d4aSKarsten Keil #define DIVA_RESET_BIT		0x08
162cae86d4aSKarsten Keil #define DIVA_EEPROM_CLK		0x40
163cae86d4aSKarsten Keil #define DIVA_LED_A		0x10
164cae86d4aSKarsten Keil #define DIVA_LED_B		0x20
165cae86d4aSKarsten Keil #define DIVA_IRQ_CLR		0x80
166cae86d4aSKarsten Keil 
167cae86d4aSKarsten Keil /* Diva 2.01/2.02 */
168cae86d4aSKarsten Keil /* Siemens PITA */
169cae86d4aSKarsten Keil #define PITA_ICR_REG		0x00
170cae86d4aSKarsten Keil #define PITA_INT0_STATUS	0x02
171cae86d4aSKarsten Keil 
172cae86d4aSKarsten Keil #define PITA_MISC_REG		0x1c
173cae86d4aSKarsten Keil #define PITA_PARA_SOFTRESET	0x01000000
174cae86d4aSKarsten Keil #define PITA_SER_SOFTRESET	0x02000000
175cae86d4aSKarsten Keil #define PITA_PARA_MPX_MODE	0x04000000
176cae86d4aSKarsten Keil #define PITA_INT0_ENABLE	0x00020000
177cae86d4aSKarsten Keil 
178cae86d4aSKarsten Keil /* TIGER 100 Registers */
179cae86d4aSKarsten Keil #define TIGER_RESET_ADDR	0x00
180cae86d4aSKarsten Keil #define TIGER_EXTERN_RESET	0x01
181cae86d4aSKarsten Keil #define TIGER_AUX_CTRL		0x02
182cae86d4aSKarsten Keil #define TIGER_AUX_DATA		0x03
183cae86d4aSKarsten Keil #define TIGER_AUX_IRQMASK	0x05
184cae86d4aSKarsten Keil #define TIGER_AUX_STATUS	0x07
185cae86d4aSKarsten Keil 
186cae86d4aSKarsten Keil /* Tiger AUX BITs */
187cae86d4aSKarsten Keil #define TIGER_IOMASK		0xdd	/* 1 and 5 are inputs */
188cae86d4aSKarsten Keil #define TIGER_IRQ_BIT		0x02
189cae86d4aSKarsten Keil 
190cae86d4aSKarsten Keil #define TIGER_IPAC_ALE		0xC0
191cae86d4aSKarsten Keil #define TIGER_IPAC_PORT		0xC8
192cae86d4aSKarsten Keil 
193cae86d4aSKarsten Keil /* ELSA (now Develo) PCI cards */
194cae86d4aSKarsten Keil #define ELSA_IRQ_ADDR		0x4c
195cae86d4aSKarsten Keil #define ELSA_IRQ_MASK		0x04
196cae86d4aSKarsten Keil #define QS1000_IRQ_OFF		0x01
197cae86d4aSKarsten Keil #define QS3000_IRQ_OFF		0x03
198cae86d4aSKarsten Keil #define QS1000_IRQ_ON		0x41
199cae86d4aSKarsten Keil #define QS3000_IRQ_ON		0x43
200cae86d4aSKarsten Keil 
201cae86d4aSKarsten Keil /* Dr Neuhaus/Sagem Niccy */
202cae86d4aSKarsten Keil #define NICCY_ISAC_PORT		0x00
203cae86d4aSKarsten Keil #define NICCY_HSCX_PORT		0x01
204cae86d4aSKarsten Keil #define NICCY_ISAC_ALE		0x02
205cae86d4aSKarsten Keil #define NICCY_HSCX_ALE		0x03
206cae86d4aSKarsten Keil 
207cae86d4aSKarsten Keil #define NICCY_IRQ_CTRL_REG	0x38
208cae86d4aSKarsten Keil #define NICCY_IRQ_ENABLE	0x001f00
209cae86d4aSKarsten Keil #define NICCY_IRQ_DISABLE	0xff0000
210cae86d4aSKarsten Keil #define NICCY_IRQ_BIT		0x800000
211cae86d4aSKarsten Keil 
212cae86d4aSKarsten Keil 
213cae86d4aSKarsten Keil /* Scitel PLX */
214cae86d4aSKarsten Keil #define SCT_PLX_IRQ_ADDR	0x4c
215cae86d4aSKarsten Keil #define SCT_PLX_RESET_ADDR	0x50
216cae86d4aSKarsten Keil #define SCT_PLX_IRQ_ENABLE	0x41
217cae86d4aSKarsten Keil #define SCT_PLX_RESET_BIT	0x04
218cae86d4aSKarsten Keil 
219cae86d4aSKarsten Keil /* Gazel */
220cae86d4aSKarsten Keil #define	GAZEL_IPAC_DATA_PORT	0x04
221cae86d4aSKarsten Keil /* Gazel PLX */
222cae86d4aSKarsten Keil #define GAZEL_CNTRL		0x50
223cae86d4aSKarsten Keil #define GAZEL_RESET		0x04
224cae86d4aSKarsten Keil #define GAZEL_RESET_9050	0x40000000
225cae86d4aSKarsten Keil #define GAZEL_INCSR		0x4C
226cae86d4aSKarsten Keil #define GAZEL_ISAC_EN		0x08
227cae86d4aSKarsten Keil #define GAZEL_INT_ISAC		0x20
228cae86d4aSKarsten Keil #define GAZEL_HSCX_EN		0x01
229cae86d4aSKarsten Keil #define GAZEL_INT_HSCX		0x04
230cae86d4aSKarsten Keil #define GAZEL_PCI_EN		0x40
231cae86d4aSKarsten Keil #define GAZEL_IPAC_EN		0x03
232cae86d4aSKarsten Keil 
233cae86d4aSKarsten Keil 
234cae86d4aSKarsten Keil static LIST_HEAD(Cards);
235cae86d4aSKarsten Keil static DEFINE_RWLOCK(card_lock); /* protect Cards */
236cae86d4aSKarsten Keil 
237cae86d4aSKarsten Keil static void
238cae86d4aSKarsten Keil _set_debug(struct inf_hw *card)
239cae86d4aSKarsten Keil {
240cae86d4aSKarsten Keil 	card->ipac.isac.dch.debug = debug;
241cae86d4aSKarsten Keil 	card->ipac.hscx[0].bch.debug = debug;
242cae86d4aSKarsten Keil 	card->ipac.hscx[1].bch.debug = debug;
243cae86d4aSKarsten Keil }
244cae86d4aSKarsten Keil 
245cae86d4aSKarsten Keil static int
246cae86d4aSKarsten Keil set_debug(const char *val, struct kernel_param *kp)
247cae86d4aSKarsten Keil {
248cae86d4aSKarsten Keil 	int ret;
249cae86d4aSKarsten Keil 	struct inf_hw *card;
250cae86d4aSKarsten Keil 
251cae86d4aSKarsten Keil 	ret = param_set_uint(val, kp);
252cae86d4aSKarsten Keil 	if (!ret) {
253cae86d4aSKarsten Keil 		read_lock(&card_lock);
254cae86d4aSKarsten Keil 		list_for_each_entry(card, &Cards, list)
255cae86d4aSKarsten Keil 			_set_debug(card);
256cae86d4aSKarsten Keil 		read_unlock(&card_lock);
257cae86d4aSKarsten Keil 	}
258cae86d4aSKarsten Keil 	return ret;
259cae86d4aSKarsten Keil }
260cae86d4aSKarsten Keil 
261cae86d4aSKarsten Keil MODULE_AUTHOR("Karsten Keil");
262cae86d4aSKarsten Keil MODULE_LICENSE("GPL v2");
263cae86d4aSKarsten Keil MODULE_VERSION(INFINEON_REV);
264cae86d4aSKarsten Keil module_param_call(debug, set_debug, param_get_uint, &debug, S_IRUGO | S_IWUSR);
265cae86d4aSKarsten Keil MODULE_PARM_DESC(debug, "infineon debug mask");
266cae86d4aSKarsten Keil module_param(irqloops, uint, S_IRUGO | S_IWUSR);
267cae86d4aSKarsten Keil MODULE_PARM_DESC(irqloops, "infineon maximal irqloops (default 4)");
268cae86d4aSKarsten Keil 
269cae86d4aSKarsten Keil /* Interface functions */
270cae86d4aSKarsten Keil 
271cae86d4aSKarsten Keil IOFUNC_IO(ISAC, inf_hw, isac.a.io)
272cae86d4aSKarsten Keil IOFUNC_IO(IPAC, inf_hw, hscx.a.io)
273cae86d4aSKarsten Keil IOFUNC_IND(ISAC, inf_hw, isac.a.io)
274cae86d4aSKarsten Keil IOFUNC_IND(IPAC, inf_hw, hscx.a.io)
275cae86d4aSKarsten Keil IOFUNC_MEMIO(ISAC, inf_hw, u32, isac.a.p)
276cae86d4aSKarsten Keil IOFUNC_MEMIO(IPAC, inf_hw, u32, hscx.a.p)
277cae86d4aSKarsten Keil 
278cae86d4aSKarsten Keil static irqreturn_t
279cae86d4aSKarsten Keil diva_irq(int intno, void *dev_id)
280cae86d4aSKarsten Keil {
281cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
282cae86d4aSKarsten Keil 	u8 val;
283cae86d4aSKarsten Keil 
284cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
285cae86d4aSKarsten Keil 	val = inb((u32)hw->cfg.start + DIVA_PCI_CTRL);
286cae86d4aSKarsten Keil 	if (!(val & DIVA_IRQ_BIT)) { /* for us or shared ? */
287cae86d4aSKarsten Keil 		spin_unlock(&hw->lock);
288cae86d4aSKarsten Keil 		return IRQ_NONE; /* shared */
289cae86d4aSKarsten Keil 	}
290cae86d4aSKarsten Keil 	hw->irqcnt++;
291cae86d4aSKarsten Keil 	mISDNipac_irq(&hw->ipac, irqloops);
292cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
293cae86d4aSKarsten Keil 	return IRQ_HANDLED;
294cae86d4aSKarsten Keil }
295cae86d4aSKarsten Keil 
296cae86d4aSKarsten Keil static irqreturn_t
297cae86d4aSKarsten Keil diva20x_irq(int intno, void *dev_id)
298cae86d4aSKarsten Keil {
299cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
300cae86d4aSKarsten Keil 	u8 val;
301cae86d4aSKarsten Keil 
302cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
303cae86d4aSKarsten Keil 	val = readb(hw->cfg.p);
304cae86d4aSKarsten Keil 	if (!(val & PITA_INT0_STATUS)) { /* for us or shared ? */
305cae86d4aSKarsten Keil 		spin_unlock(&hw->lock);
306cae86d4aSKarsten Keil 		return IRQ_NONE; /* shared */
307cae86d4aSKarsten Keil 	}
308cae86d4aSKarsten Keil 	hw->irqcnt++;
309cae86d4aSKarsten Keil 	mISDNipac_irq(&hw->ipac, irqloops);
310cae86d4aSKarsten Keil 	writeb(PITA_INT0_STATUS, hw->cfg.p); /* ACK PITA INT0 */
311cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
312cae86d4aSKarsten Keil 	return IRQ_HANDLED;
313cae86d4aSKarsten Keil }
314cae86d4aSKarsten Keil 
315cae86d4aSKarsten Keil static irqreturn_t
316cae86d4aSKarsten Keil tiger_irq(int intno, void *dev_id)
317cae86d4aSKarsten Keil {
318cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
319cae86d4aSKarsten Keil 	u8 val;
320cae86d4aSKarsten Keil 
321cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
322cae86d4aSKarsten Keil 	val = inb((u32)hw->cfg.start + TIGER_AUX_STATUS);
323cae86d4aSKarsten Keil 	if (val & TIGER_IRQ_BIT) { /* for us or shared ? */
324cae86d4aSKarsten Keil 		spin_unlock(&hw->lock);
325cae86d4aSKarsten Keil 		return IRQ_NONE; /* shared */
326cae86d4aSKarsten Keil 	}
327cae86d4aSKarsten Keil 	hw->irqcnt++;
328cae86d4aSKarsten Keil 	mISDNipac_irq(&hw->ipac, irqloops);
329cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
330cae86d4aSKarsten Keil 	return IRQ_HANDLED;
331cae86d4aSKarsten Keil }
332cae86d4aSKarsten Keil 
333cae86d4aSKarsten Keil static irqreturn_t
334cae86d4aSKarsten Keil elsa_irq(int intno, void *dev_id)
335cae86d4aSKarsten Keil {
336cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
337cae86d4aSKarsten Keil 	u8 val;
338cae86d4aSKarsten Keil 
339cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
340cae86d4aSKarsten Keil 	val = inb((u32)hw->cfg.start + ELSA_IRQ_ADDR);
341cae86d4aSKarsten Keil 	if (!(val & ELSA_IRQ_MASK)) {
342cae86d4aSKarsten Keil 		spin_unlock(&hw->lock);
343cae86d4aSKarsten Keil 		return IRQ_NONE; /* shared */
344cae86d4aSKarsten Keil 	}
345cae86d4aSKarsten Keil 	hw->irqcnt++;
346cae86d4aSKarsten Keil 	mISDNipac_irq(&hw->ipac, irqloops);
347cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
348cae86d4aSKarsten Keil 	return IRQ_HANDLED;
349cae86d4aSKarsten Keil }
350cae86d4aSKarsten Keil 
351cae86d4aSKarsten Keil static irqreturn_t
352cae86d4aSKarsten Keil niccy_irq(int intno, void *dev_id)
353cae86d4aSKarsten Keil {
354cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
355cae86d4aSKarsten Keil 	u32 val;
356cae86d4aSKarsten Keil 
357cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
358cae86d4aSKarsten Keil 	val = inl((u32)hw->cfg.start + NICCY_IRQ_CTRL_REG);
359cae86d4aSKarsten Keil 	if (!(val & NICCY_IRQ_BIT)) { /* for us or shared ? */
360cae86d4aSKarsten Keil 		spin_unlock(&hw->lock);
361cae86d4aSKarsten Keil 		return IRQ_NONE; /* shared */
362cae86d4aSKarsten Keil 	}
363cae86d4aSKarsten Keil 	outl(val, (u32)hw->cfg.start + NICCY_IRQ_CTRL_REG);
364cae86d4aSKarsten Keil 	hw->irqcnt++;
365cae86d4aSKarsten Keil 	mISDNipac_irq(&hw->ipac, irqloops);
366cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
367cae86d4aSKarsten Keil 	return IRQ_HANDLED;
368cae86d4aSKarsten Keil }
369cae86d4aSKarsten Keil 
370cae86d4aSKarsten Keil static irqreturn_t
371cae86d4aSKarsten Keil gazel_irq(int intno, void *dev_id)
372cae86d4aSKarsten Keil {
373cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
374cae86d4aSKarsten Keil 	irqreturn_t ret;
375cae86d4aSKarsten Keil 
376cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
377cae86d4aSKarsten Keil 	ret = mISDNipac_irq(&hw->ipac, irqloops);
378cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
379cae86d4aSKarsten Keil 	return ret;
380cae86d4aSKarsten Keil }
381cae86d4aSKarsten Keil 
382cae86d4aSKarsten Keil static irqreturn_t
383cae86d4aSKarsten Keil ipac_irq(int intno, void *dev_id)
384cae86d4aSKarsten Keil {
385cae86d4aSKarsten Keil 	struct inf_hw *hw = dev_id;
386cae86d4aSKarsten Keil 	u8 val;
387cae86d4aSKarsten Keil 
388cae86d4aSKarsten Keil 	spin_lock(&hw->lock);
389cae86d4aSKarsten Keil 	val = hw->ipac.read_reg(hw, IPAC_ISTA);
390cae86d4aSKarsten Keil 	if (!(val & 0x3f)) {
391cae86d4aSKarsten Keil 		spin_unlock(&hw->lock);
392cae86d4aSKarsten Keil 		return IRQ_NONE; /* shared */
393cae86d4aSKarsten Keil 	}
394cae86d4aSKarsten Keil 	hw->irqcnt++;
395cae86d4aSKarsten Keil 	mISDNipac_irq(&hw->ipac, irqloops);
396cae86d4aSKarsten Keil 	spin_unlock(&hw->lock);
397cae86d4aSKarsten Keil 	return IRQ_HANDLED;
398cae86d4aSKarsten Keil }
399cae86d4aSKarsten Keil 
400cae86d4aSKarsten Keil static void
401cae86d4aSKarsten Keil enable_hwirq(struct inf_hw *hw)
402cae86d4aSKarsten Keil {
403cae86d4aSKarsten Keil 	u16 w;
404cae86d4aSKarsten Keil 	u32 val;
405cae86d4aSKarsten Keil 
406cae86d4aSKarsten Keil 	switch (hw->ci->typ) {
407cae86d4aSKarsten Keil 	case INF_DIVA201:
408cae86d4aSKarsten Keil 	case INF_DIVA202:
409cae86d4aSKarsten Keil 		writel(PITA_INT0_ENABLE, hw->cfg.p);
410cae86d4aSKarsten Keil 		break;
411cae86d4aSKarsten Keil 	case INF_SPEEDWIN:
412cae86d4aSKarsten Keil 	case INF_SAPHIR3:
413cae86d4aSKarsten Keil 		outb(TIGER_IRQ_BIT, (u32)hw->cfg.start + TIGER_AUX_IRQMASK);
414cae86d4aSKarsten Keil 		break;
415cae86d4aSKarsten Keil 	case INF_QS1000:
416cae86d4aSKarsten Keil 		outb(QS1000_IRQ_ON, (u32)hw->cfg.start + ELSA_IRQ_ADDR);
417cae86d4aSKarsten Keil 		break;
418cae86d4aSKarsten Keil 	case INF_QS3000:
419cae86d4aSKarsten Keil 		outb(QS3000_IRQ_ON, (u32)hw->cfg.start + ELSA_IRQ_ADDR);
420cae86d4aSKarsten Keil 		break;
421cae86d4aSKarsten Keil 	case INF_NICCY:
422cae86d4aSKarsten Keil 		val = inl((u32)hw->cfg.start + NICCY_IRQ_CTRL_REG);
423*ad65ffd1SJoe Perches 		val |= NICCY_IRQ_ENABLE;
424cae86d4aSKarsten Keil 		outl(val, (u32)hw->cfg.start + NICCY_IRQ_CTRL_REG);
425cae86d4aSKarsten Keil 		break;
426cae86d4aSKarsten Keil 	case INF_SCT_1:
427cae86d4aSKarsten Keil 		w = inw((u32)hw->cfg.start + SCT_PLX_IRQ_ADDR);
428cae86d4aSKarsten Keil 		w |= SCT_PLX_IRQ_ENABLE;
429cae86d4aSKarsten Keil 		outw(w, (u32)hw->cfg.start + SCT_PLX_IRQ_ADDR);
430cae86d4aSKarsten Keil 		break;
431cae86d4aSKarsten Keil 	case INF_GAZEL_R685:
432cae86d4aSKarsten Keil 		outb(GAZEL_ISAC_EN + GAZEL_HSCX_EN + GAZEL_PCI_EN,
433cae86d4aSKarsten Keil 			(u32)hw->cfg.start + GAZEL_INCSR);
434cae86d4aSKarsten Keil 		break;
435cae86d4aSKarsten Keil 	case INF_GAZEL_R753:
436cae86d4aSKarsten Keil 		outb(GAZEL_IPAC_EN + GAZEL_PCI_EN,
437cae86d4aSKarsten Keil 			(u32)hw->cfg.start + GAZEL_INCSR);
438cae86d4aSKarsten Keil 		break;
439cae86d4aSKarsten Keil 	default:
440cae86d4aSKarsten Keil 		break;
441cae86d4aSKarsten Keil 	}
442cae86d4aSKarsten Keil }
443cae86d4aSKarsten Keil 
444cae86d4aSKarsten Keil static void
445cae86d4aSKarsten Keil disable_hwirq(struct inf_hw *hw)
446cae86d4aSKarsten Keil {
447cae86d4aSKarsten Keil 	u16 w;
448cae86d4aSKarsten Keil 	u32 val;
449cae86d4aSKarsten Keil 
450cae86d4aSKarsten Keil 	switch (hw->ci->typ) {
451cae86d4aSKarsten Keil 	case INF_DIVA201:
452cae86d4aSKarsten Keil 	case INF_DIVA202:
453cae86d4aSKarsten Keil 		writel(0, hw->cfg.p);
454cae86d4aSKarsten Keil 		break;
455cae86d4aSKarsten Keil 	case INF_SPEEDWIN:
456cae86d4aSKarsten Keil 	case INF_SAPHIR3:
457cae86d4aSKarsten Keil 		outb(0, (u32)hw->cfg.start + TIGER_AUX_IRQMASK);
458cae86d4aSKarsten Keil 		break;
459cae86d4aSKarsten Keil 	case INF_QS1000:
460cae86d4aSKarsten Keil 		outb(QS1000_IRQ_OFF, (u32)hw->cfg.start + ELSA_IRQ_ADDR);
461cae86d4aSKarsten Keil 		break;
462cae86d4aSKarsten Keil 	case INF_QS3000:
463cae86d4aSKarsten Keil 		outb(QS3000_IRQ_OFF, (u32)hw->cfg.start + ELSA_IRQ_ADDR);
464cae86d4aSKarsten Keil 		break;
465cae86d4aSKarsten Keil 	case INF_NICCY:
466cae86d4aSKarsten Keil 		val = inl((u32)hw->cfg.start + NICCY_IRQ_CTRL_REG);
467cae86d4aSKarsten Keil 		val &= NICCY_IRQ_DISABLE;
468cae86d4aSKarsten Keil 		outl(val, (u32)hw->cfg.start + NICCY_IRQ_CTRL_REG);
469cae86d4aSKarsten Keil 		break;
470cae86d4aSKarsten Keil 	case INF_SCT_1:
471cae86d4aSKarsten Keil 		w = inw((u32)hw->cfg.start + SCT_PLX_IRQ_ADDR);
472cae86d4aSKarsten Keil 		w &= (~SCT_PLX_IRQ_ENABLE);
473cae86d4aSKarsten Keil 		outw(w, (u32)hw->cfg.start + SCT_PLX_IRQ_ADDR);
474cae86d4aSKarsten Keil 		break;
475cae86d4aSKarsten Keil 	case INF_GAZEL_R685:
476cae86d4aSKarsten Keil 	case INF_GAZEL_R753:
477cae86d4aSKarsten Keil 		outb(0, (u32)hw->cfg.start + GAZEL_INCSR);
478cae86d4aSKarsten Keil 		break;
479cae86d4aSKarsten Keil 	default:
480cae86d4aSKarsten Keil 		break;
481cae86d4aSKarsten Keil 	}
482cae86d4aSKarsten Keil }
483cae86d4aSKarsten Keil 
484cae86d4aSKarsten Keil static void
485cae86d4aSKarsten Keil ipac_chip_reset(struct inf_hw *hw)
486cae86d4aSKarsten Keil {
487cae86d4aSKarsten Keil 	hw->ipac.write_reg(hw, IPAC_POTA2, 0x20);
488cae86d4aSKarsten Keil 	mdelay(5);
489cae86d4aSKarsten Keil 	hw->ipac.write_reg(hw, IPAC_POTA2, 0x00);
490cae86d4aSKarsten Keil 	mdelay(5);
491cae86d4aSKarsten Keil 	hw->ipac.write_reg(hw, IPAC_CONF, hw->ipac.conf);
492cae86d4aSKarsten Keil 	hw->ipac.write_reg(hw, IPAC_MASK, 0xc0);
493cae86d4aSKarsten Keil }
494cae86d4aSKarsten Keil 
495cae86d4aSKarsten Keil static void
496cae86d4aSKarsten Keil reset_inf(struct inf_hw *hw)
497cae86d4aSKarsten Keil {
498cae86d4aSKarsten Keil 	u16 w;
499cae86d4aSKarsten Keil 	u32 val;
500cae86d4aSKarsten Keil 
501cae86d4aSKarsten Keil 	if (debug & DEBUG_HW)
502cae86d4aSKarsten Keil 		pr_notice("%s: resetting card\n", hw->name);
503cae86d4aSKarsten Keil 	switch (hw->ci->typ) {
504cae86d4aSKarsten Keil 	case INF_DIVA20:
505cae86d4aSKarsten Keil 	case INF_DIVA20U:
506cae86d4aSKarsten Keil 		outb(0, (u32)hw->cfg.start + DIVA_PCI_CTRL);
507cae86d4aSKarsten Keil 		mdelay(10);
508cae86d4aSKarsten Keil 		outb(DIVA_RESET_BIT, (u32)hw->cfg.start + DIVA_PCI_CTRL);
509cae86d4aSKarsten Keil 		mdelay(10);
510cae86d4aSKarsten Keil 		/* Workaround PCI9060 */
511cae86d4aSKarsten Keil 		outb(9, (u32)hw->cfg.start + 0x69);
512cae86d4aSKarsten Keil 		outb(DIVA_RESET_BIT | DIVA_LED_A,
513cae86d4aSKarsten Keil 			(u32)hw->cfg.start + DIVA_PCI_CTRL);
514cae86d4aSKarsten Keil 		break;
515cae86d4aSKarsten Keil 	case INF_DIVA201:
516cae86d4aSKarsten Keil 		writel(PITA_PARA_SOFTRESET | PITA_PARA_MPX_MODE,
517cae86d4aSKarsten Keil 			hw->cfg.p + PITA_MISC_REG);
518cae86d4aSKarsten Keil 		mdelay(1);
519cae86d4aSKarsten Keil 		writel(PITA_PARA_MPX_MODE, hw->cfg.p + PITA_MISC_REG);
520cae86d4aSKarsten Keil 		mdelay(10);
521cae86d4aSKarsten Keil 		break;
522cae86d4aSKarsten Keil 	case INF_DIVA202:
523cae86d4aSKarsten Keil 		writel(PITA_PARA_SOFTRESET | PITA_PARA_MPX_MODE,
524cae86d4aSKarsten Keil 			hw->cfg.p + PITA_MISC_REG);
525cae86d4aSKarsten Keil 		mdelay(1);
526cae86d4aSKarsten Keil 		writel(PITA_PARA_MPX_MODE | PITA_SER_SOFTRESET,
527cae86d4aSKarsten Keil 			hw->cfg.p + PITA_MISC_REG);
528cae86d4aSKarsten Keil 		mdelay(10);
529cae86d4aSKarsten Keil 		break;
530cae86d4aSKarsten Keil 	case INF_SPEEDWIN:
531cae86d4aSKarsten Keil 	case INF_SAPHIR3:
532cae86d4aSKarsten Keil 		ipac_chip_reset(hw);
533cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_ACFG, 0xff);
534cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_AOE, 0x00);
535cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_PCFG, 0x12);
536cae86d4aSKarsten Keil 		break;
537cae86d4aSKarsten Keil 	case INF_QS1000:
538cae86d4aSKarsten Keil 	case INF_QS3000:
539cae86d4aSKarsten Keil 		ipac_chip_reset(hw);
540cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_ACFG, 0x00);
541cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_AOE, 0x3c);
542cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_ATX, 0xff);
543cae86d4aSKarsten Keil 		break;
544cae86d4aSKarsten Keil 	case INF_NICCY:
545cae86d4aSKarsten Keil 		break;
546cae86d4aSKarsten Keil 	case INF_SCT_1:
547cae86d4aSKarsten Keil 		w = inw((u32)hw->cfg.start + SCT_PLX_RESET_ADDR);
548cae86d4aSKarsten Keil 		w &= (~SCT_PLX_RESET_BIT);
549cae86d4aSKarsten Keil 		outw(w, (u32)hw->cfg.start + SCT_PLX_RESET_ADDR);
550cae86d4aSKarsten Keil 		mdelay(10);
551cae86d4aSKarsten Keil 		w = inw((u32)hw->cfg.start + SCT_PLX_RESET_ADDR);
552cae86d4aSKarsten Keil 		w |= SCT_PLX_RESET_BIT;
553cae86d4aSKarsten Keil 		outw(w, (u32)hw->cfg.start + SCT_PLX_RESET_ADDR);
554cae86d4aSKarsten Keil 		mdelay(10);
555cae86d4aSKarsten Keil 		break;
556cae86d4aSKarsten Keil 	case INF_GAZEL_R685:
557cae86d4aSKarsten Keil 		val = inl((u32)hw->cfg.start + GAZEL_CNTRL);
558cae86d4aSKarsten Keil 		val |= (GAZEL_RESET_9050 + GAZEL_RESET);
559cae86d4aSKarsten Keil 		outl(val, (u32)hw->cfg.start + GAZEL_CNTRL);
560cae86d4aSKarsten Keil 		val &= ~(GAZEL_RESET_9050 + GAZEL_RESET);
561cae86d4aSKarsten Keil 		mdelay(4);
562cae86d4aSKarsten Keil 		outl(val, (u32)hw->cfg.start + GAZEL_CNTRL);
563cae86d4aSKarsten Keil 		mdelay(10);
564cae86d4aSKarsten Keil 		hw->ipac.isac.adf2 = 0x87;
565cae86d4aSKarsten Keil 		hw->ipac.hscx[0].slot = 0x1f;
5664101e976SJulia Lawall 		hw->ipac.hscx[1].slot = 0x23;
567cae86d4aSKarsten Keil 		break;
568cae86d4aSKarsten Keil 	case INF_GAZEL_R753:
569cae86d4aSKarsten Keil 		val = inl((u32)hw->cfg.start + GAZEL_CNTRL);
570cae86d4aSKarsten Keil 		val |= (GAZEL_RESET_9050 + GAZEL_RESET);
571cae86d4aSKarsten Keil 		outl(val, (u32)hw->cfg.start + GAZEL_CNTRL);
572cae86d4aSKarsten Keil 		val &= ~(GAZEL_RESET_9050 + GAZEL_RESET);
573cae86d4aSKarsten Keil 		mdelay(4);
574cae86d4aSKarsten Keil 		outl(val, (u32)hw->cfg.start + GAZEL_CNTRL);
575cae86d4aSKarsten Keil 		mdelay(10);
576cae86d4aSKarsten Keil 		ipac_chip_reset(hw);
577cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_ACFG, 0xff);
578cae86d4aSKarsten Keil 		hw->ipac.write_reg(hw, IPAC_AOE, 0x00);
579cae86d4aSKarsten Keil 		hw->ipac.conf = 0x01; /* IOM off */
580cae86d4aSKarsten Keil 		break;
581cae86d4aSKarsten Keil 	default:
582cae86d4aSKarsten Keil 		return;
583cae86d4aSKarsten Keil 	}
584cae86d4aSKarsten Keil 	enable_hwirq(hw);
585cae86d4aSKarsten Keil }
586cae86d4aSKarsten Keil 
587cae86d4aSKarsten Keil static int
588cae86d4aSKarsten Keil inf_ctrl(struct inf_hw *hw, u32 cmd, u_long arg)
589cae86d4aSKarsten Keil {
590cae86d4aSKarsten Keil 	int ret = 0;
591cae86d4aSKarsten Keil 
592cae86d4aSKarsten Keil 	switch (cmd) {
593cae86d4aSKarsten Keil 	case HW_RESET_REQ:
594cae86d4aSKarsten Keil 		reset_inf(hw);
595cae86d4aSKarsten Keil 		break;
596cae86d4aSKarsten Keil 	default:
597cae86d4aSKarsten Keil 		pr_info("%s: %s unknown command %x %lx\n",
598cae86d4aSKarsten Keil 			hw->name, __func__, cmd, arg);
599cae86d4aSKarsten Keil 		ret = -EINVAL;
600cae86d4aSKarsten Keil 		break;
601cae86d4aSKarsten Keil 	}
602cae86d4aSKarsten Keil 	return ret;
603cae86d4aSKarsten Keil }
604cae86d4aSKarsten Keil 
605cae86d4aSKarsten Keil static int __devinit
606cae86d4aSKarsten Keil init_irq(struct inf_hw *hw)
607cae86d4aSKarsten Keil {
608cae86d4aSKarsten Keil 	int	ret, cnt = 3;
609cae86d4aSKarsten Keil 	u_long	flags;
610cae86d4aSKarsten Keil 
611cae86d4aSKarsten Keil 	if (!hw->ci->irqfunc)
612cae86d4aSKarsten Keil 		return -EINVAL;
613cae86d4aSKarsten Keil 	ret = request_irq(hw->irq, hw->ci->irqfunc, IRQF_SHARED, hw->name, hw);
614cae86d4aSKarsten Keil 	if (ret) {
615cae86d4aSKarsten Keil 		pr_info("%s: couldn't get interrupt %d\n", hw->name, hw->irq);
616cae86d4aSKarsten Keil 		return ret;
617cae86d4aSKarsten Keil 	}
618cae86d4aSKarsten Keil 	while (cnt--) {
619cae86d4aSKarsten Keil 		spin_lock_irqsave(&hw->lock, flags);
620cae86d4aSKarsten Keil 		reset_inf(hw);
621cae86d4aSKarsten Keil 		ret = hw->ipac.init(&hw->ipac);
622cae86d4aSKarsten Keil 		if (ret) {
623cae86d4aSKarsten Keil 			spin_unlock_irqrestore(&hw->lock, flags);
624cae86d4aSKarsten Keil 			pr_info("%s: ISAC init failed with %d\n",
625cae86d4aSKarsten Keil 				hw->name, ret);
626cae86d4aSKarsten Keil 			break;
627cae86d4aSKarsten Keil 		}
628cae86d4aSKarsten Keil 		spin_unlock_irqrestore(&hw->lock, flags);
629cae86d4aSKarsten Keil 		msleep_interruptible(10);
630cae86d4aSKarsten Keil 		if (debug & DEBUG_HW)
631cae86d4aSKarsten Keil 			pr_notice("%s: IRQ %d count %d\n", hw->name,
632cae86d4aSKarsten Keil 				hw->irq, hw->irqcnt);
633cae86d4aSKarsten Keil 		if (!hw->irqcnt) {
634cae86d4aSKarsten Keil 			pr_info("%s: IRQ(%d) got no requests during init %d\n",
635cae86d4aSKarsten Keil 				hw->name, hw->irq, 3 - cnt);
636cae86d4aSKarsten Keil 		} else
637cae86d4aSKarsten Keil 			return 0;
638cae86d4aSKarsten Keil 	}
639cae86d4aSKarsten Keil 	free_irq(hw->irq, hw);
640cae86d4aSKarsten Keil 	return -EIO;
641cae86d4aSKarsten Keil }
642cae86d4aSKarsten Keil 
643cae86d4aSKarsten Keil static void
644cae86d4aSKarsten Keil release_io(struct inf_hw *hw)
645cae86d4aSKarsten Keil {
646cae86d4aSKarsten Keil 	if (hw->cfg.mode) {
647cae86d4aSKarsten Keil 		if (hw->cfg.p) {
648cae86d4aSKarsten Keil 			release_mem_region(hw->cfg.start, hw->cfg.size);
649cae86d4aSKarsten Keil 			iounmap(hw->cfg.p);
650cae86d4aSKarsten Keil 		} else
651cae86d4aSKarsten Keil 			release_region(hw->cfg.start, hw->cfg.size);
652cae86d4aSKarsten Keil 		hw->cfg.mode = AM_NONE;
653cae86d4aSKarsten Keil 	}
654cae86d4aSKarsten Keil 	if (hw->addr.mode) {
655cae86d4aSKarsten Keil 		if (hw->addr.p) {
656cae86d4aSKarsten Keil 			release_mem_region(hw->addr.start, hw->addr.size);
657cae86d4aSKarsten Keil 			iounmap(hw->addr.p);
658cae86d4aSKarsten Keil 		} else
659cae86d4aSKarsten Keil 			release_region(hw->addr.start, hw->addr.size);
660cae86d4aSKarsten Keil 		hw->addr.mode = AM_NONE;
661cae86d4aSKarsten Keil 	}
662cae86d4aSKarsten Keil }
663cae86d4aSKarsten Keil 
664cae86d4aSKarsten Keil static int __devinit
665cae86d4aSKarsten Keil setup_io(struct inf_hw *hw)
666cae86d4aSKarsten Keil {
667cae86d4aSKarsten Keil 	int err = 0;
668cae86d4aSKarsten Keil 
669cae86d4aSKarsten Keil 	if (hw->ci->cfg_mode) {
670cae86d4aSKarsten Keil 		hw->cfg.start = pci_resource_start(hw->pdev, hw->ci->cfg_bar);
671cae86d4aSKarsten Keil 		hw->cfg.size = pci_resource_len(hw->pdev, hw->ci->cfg_bar);
672cae86d4aSKarsten Keil 		if (hw->ci->cfg_mode == AM_MEMIO) {
673cae86d4aSKarsten Keil 			if (!request_mem_region(hw->cfg.start, hw->cfg.size,
674cae86d4aSKarsten Keil 			    hw->name))
675cae86d4aSKarsten Keil 				err = -EBUSY;
676cae86d4aSKarsten Keil 		} else {
677cae86d4aSKarsten Keil 			if (!request_region(hw->cfg.start, hw->cfg.size,
678cae86d4aSKarsten Keil 			    hw->name))
679cae86d4aSKarsten Keil 				err = -EBUSY;
680cae86d4aSKarsten Keil 		}
681cae86d4aSKarsten Keil 		if (err) {
682cae86d4aSKarsten Keil 			pr_info("mISDN: %s config port %lx (%lu bytes)"
683cae86d4aSKarsten Keil 				"already in use\n", hw->name,
684cae86d4aSKarsten Keil 				(ulong)hw->cfg.start, (ulong)hw->cfg.size);
685cae86d4aSKarsten Keil 			return err;
686cae86d4aSKarsten Keil 		}
687cae86d4aSKarsten Keil 		if (hw->ci->cfg_mode == AM_MEMIO)
688cae86d4aSKarsten Keil 			hw->cfg.p = ioremap(hw->cfg.start, hw->cfg.size);
689cae86d4aSKarsten Keil 		hw->cfg.mode = hw->ci->cfg_mode;
690cae86d4aSKarsten Keil 		if (debug & DEBUG_HW)
691cae86d4aSKarsten Keil 			pr_notice("%s: IO cfg %lx (%lu bytes) mode%d\n",
692cae86d4aSKarsten Keil 				hw->name, (ulong)hw->cfg.start,
693cae86d4aSKarsten Keil 				(ulong)hw->cfg.size, hw->ci->cfg_mode);
694cae86d4aSKarsten Keil 
695cae86d4aSKarsten Keil 	}
696cae86d4aSKarsten Keil 	if (hw->ci->addr_mode) {
697cae86d4aSKarsten Keil 		hw->addr.start = pci_resource_start(hw->pdev, hw->ci->addr_bar);
698cae86d4aSKarsten Keil 		hw->addr.size = pci_resource_len(hw->pdev, hw->ci->addr_bar);
699cae86d4aSKarsten Keil 		if (hw->ci->addr_mode == AM_MEMIO) {
700cae86d4aSKarsten Keil 			if (!request_mem_region(hw->addr.start, hw->addr.size,
701cae86d4aSKarsten Keil 			    hw->name))
702cae86d4aSKarsten Keil 				err = -EBUSY;
703cae86d4aSKarsten Keil 		} else {
704cae86d4aSKarsten Keil 			if (!request_region(hw->addr.start, hw->addr.size,
705cae86d4aSKarsten Keil 			    hw->name))
706cae86d4aSKarsten Keil 				err = -EBUSY;
707cae86d4aSKarsten Keil 		}
708cae86d4aSKarsten Keil 		if (err) {
709cae86d4aSKarsten Keil 			pr_info("mISDN: %s address port %lx (%lu bytes)"
710cae86d4aSKarsten Keil 				"already in use\n", hw->name,
711cae86d4aSKarsten Keil 				(ulong)hw->addr.start, (ulong)hw->addr.size);
712cae86d4aSKarsten Keil 			return err;
713cae86d4aSKarsten Keil 		}
714cae86d4aSKarsten Keil 		if (hw->ci->addr_mode == AM_MEMIO)
715cae86d4aSKarsten Keil 			hw->addr.p = ioremap(hw->addr.start, hw->addr.size);
716cae86d4aSKarsten Keil 		hw->addr.mode = hw->ci->addr_mode;
717cae86d4aSKarsten Keil 		if (debug & DEBUG_HW)
718cae86d4aSKarsten Keil 			pr_notice("%s: IO addr %lx (%lu bytes) mode%d\n",
719cae86d4aSKarsten Keil 				hw->name, (ulong)hw->addr.start,
720cae86d4aSKarsten Keil 				(ulong)hw->addr.size, hw->ci->addr_mode);
721cae86d4aSKarsten Keil 
722cae86d4aSKarsten Keil 	}
723cae86d4aSKarsten Keil 
724cae86d4aSKarsten Keil 	switch (hw->ci->typ) {
725cae86d4aSKarsten Keil 	case INF_DIVA20:
726cae86d4aSKarsten Keil 	case INF_DIVA20U:
727cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_ISAC | IPAC_TYPE_HSCX;
728cae86d4aSKarsten Keil 		hw->isac.mode = hw->cfg.mode;
729cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->cfg.start + DIVA_ISAC_ALE;
730cae86d4aSKarsten Keil 		hw->isac.a.io.port = (u32)hw->cfg.start + DIVA_ISAC_PORT;
731cae86d4aSKarsten Keil 		hw->hscx.mode = hw->cfg.mode;
732cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = (u32)hw->cfg.start + DIVA_HSCX_ALE;
733cae86d4aSKarsten Keil 		hw->hscx.a.io.port = (u32)hw->cfg.start + DIVA_HSCX_PORT;
734cae86d4aSKarsten Keil 		break;
735cae86d4aSKarsten Keil 	case INF_DIVA201:
736cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
737cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
738cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
739cae86d4aSKarsten Keil 		hw->isac.a.p = hw->addr.p;
740cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
741cae86d4aSKarsten Keil 		hw->hscx.a.p = hw->addr.p;
742cae86d4aSKarsten Keil 		break;
743cae86d4aSKarsten Keil 	case INF_DIVA202:
744cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPACX;
745cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
746cae86d4aSKarsten Keil 		hw->isac.a.p = hw->addr.p;
747cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
748cae86d4aSKarsten Keil 		hw->hscx.a.p = hw->addr.p;
749cae86d4aSKarsten Keil 		break;
750cae86d4aSKarsten Keil 	case INF_SPEEDWIN:
751cae86d4aSKarsten Keil 	case INF_SAPHIR3:
752cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
753cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
754cae86d4aSKarsten Keil 		hw->isac.mode = hw->cfg.mode;
755cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->cfg.start + TIGER_IPAC_ALE;
756cae86d4aSKarsten Keil 		hw->isac.a.io.port = (u32)hw->cfg.start + TIGER_IPAC_PORT;
757cae86d4aSKarsten Keil 		hw->hscx.mode = hw->cfg.mode;
758cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = (u32)hw->cfg.start + TIGER_IPAC_ALE;
759cae86d4aSKarsten Keil 		hw->hscx.a.io.port = (u32)hw->cfg.start + TIGER_IPAC_PORT;
760cae86d4aSKarsten Keil 		outb(0xff, (ulong)hw->cfg.start);
761cae86d4aSKarsten Keil 		mdelay(1);
762cae86d4aSKarsten Keil 		outb(0x00, (ulong)hw->cfg.start);
763cae86d4aSKarsten Keil 		mdelay(1);
764cae86d4aSKarsten Keil 		outb(TIGER_IOMASK, (ulong)hw->cfg.start + TIGER_AUX_CTRL);
765cae86d4aSKarsten Keil 		break;
766cae86d4aSKarsten Keil 	case INF_QS1000:
767cae86d4aSKarsten Keil 	case INF_QS3000:
768cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
769cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
770cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start;
771cae86d4aSKarsten Keil 		hw->isac.a.io.port = (u32)hw->addr.start + 1;
772cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
773cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = (u32)hw->addr.start;
774cae86d4aSKarsten Keil 		hw->hscx.a.io.port = (u32)hw->addr.start + 1;
775cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
776cae86d4aSKarsten Keil 		break;
777cae86d4aSKarsten Keil 	case INF_NICCY:
778cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_ISAC | IPAC_TYPE_HSCX;
779cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
780cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start + NICCY_ISAC_ALE;
781cae86d4aSKarsten Keil 		hw->isac.a.io.port = (u32)hw->addr.start + NICCY_ISAC_PORT;
782cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
783cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = (u32)hw->addr.start + NICCY_HSCX_ALE;
784cae86d4aSKarsten Keil 		hw->hscx.a.io.port = (u32)hw->addr.start + NICCY_HSCX_PORT;
785cae86d4aSKarsten Keil 		break;
786cae86d4aSKarsten Keil 	case INF_SCT_1:
787cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
788cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
789cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start;
790cae86d4aSKarsten Keil 		hw->isac.a.io.port = hw->isac.a.io.ale + 4;
791cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
792cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = hw->isac.a.io.ale;
793cae86d4aSKarsten Keil 		hw->hscx.a.io.port = hw->isac.a.io.port;
794cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
795cae86d4aSKarsten Keil 		break;
796cae86d4aSKarsten Keil 	case INF_SCT_2:
797cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
798cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
799cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start + 0x08;
800cae86d4aSKarsten Keil 		hw->isac.a.io.port = hw->isac.a.io.ale + 4;
801cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
802cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = hw->isac.a.io.ale;
803cae86d4aSKarsten Keil 		hw->hscx.a.io.port = hw->isac.a.io.port;
804cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
805cae86d4aSKarsten Keil 		break;
806cae86d4aSKarsten Keil 	case INF_SCT_3:
807cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
808cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
809cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start + 0x10;
810cae86d4aSKarsten Keil 		hw->isac.a.io.port = hw->isac.a.io.ale + 4;
811cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
812cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = hw->isac.a.io.ale;
813cae86d4aSKarsten Keil 		hw->hscx.a.io.port = hw->isac.a.io.port;
814cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
815cae86d4aSKarsten Keil 		break;
816cae86d4aSKarsten Keil 	case INF_SCT_4:
817cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
818cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
819cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start + 0x20;
820cae86d4aSKarsten Keil 		hw->isac.a.io.port = hw->isac.a.io.ale + 4;
821cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
822cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = hw->isac.a.io.ale;
823cae86d4aSKarsten Keil 		hw->hscx.a.io.port = hw->isac.a.io.port;
824cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
825cae86d4aSKarsten Keil 		break;
826cae86d4aSKarsten Keil 	case INF_GAZEL_R685:
827cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_ISAC | IPAC_TYPE_HSCX;
828cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
829cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
830cae86d4aSKarsten Keil 		hw->isac.a.io.port = (u32)hw->addr.start;
831cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
832cae86d4aSKarsten Keil 		hw->hscx.a.io.port = hw->isac.a.io.port;
833cae86d4aSKarsten Keil 		break;
834cae86d4aSKarsten Keil 	case INF_GAZEL_R753:
835cae86d4aSKarsten Keil 		hw->ipac.type = IPAC_TYPE_IPAC;
836cae86d4aSKarsten Keil 		hw->ipac.isac.off = 0x80;
837cae86d4aSKarsten Keil 		hw->isac.mode = hw->addr.mode;
838cae86d4aSKarsten Keil 		hw->isac.a.io.ale = (u32)hw->addr.start;
839cae86d4aSKarsten Keil 		hw->isac.a.io.port = (u32)hw->addr.start + GAZEL_IPAC_DATA_PORT;
840cae86d4aSKarsten Keil 		hw->hscx.mode = hw->addr.mode;
841cae86d4aSKarsten Keil 		hw->hscx.a.io.ale = hw->isac.a.io.ale;
842cae86d4aSKarsten Keil 		hw->hscx.a.io.port = hw->isac.a.io.port;
843cae86d4aSKarsten Keil 		break;
844cae86d4aSKarsten Keil 	default:
845cae86d4aSKarsten Keil 		return -EINVAL;
846cae86d4aSKarsten Keil 	}
847cae86d4aSKarsten Keil 	switch (hw->isac.mode) {
848cae86d4aSKarsten Keil 	case AM_MEMIO:
849cae86d4aSKarsten Keil 		ASSIGN_FUNC_IPAC(MIO, hw->ipac);
850cae86d4aSKarsten Keil 		break;
851cae86d4aSKarsten Keil 	case AM_IND_IO:
852cae86d4aSKarsten Keil 		ASSIGN_FUNC_IPAC(IND, hw->ipac);
853cae86d4aSKarsten Keil 		break;
854cae86d4aSKarsten Keil 	case AM_IO:
855cae86d4aSKarsten Keil 		ASSIGN_FUNC_IPAC(IO, hw->ipac);
856cae86d4aSKarsten Keil 		break;
857cae86d4aSKarsten Keil 	default:
858cae86d4aSKarsten Keil 		return -EINVAL;
859cae86d4aSKarsten Keil 	}
860cae86d4aSKarsten Keil 	return 0;
861cae86d4aSKarsten Keil }
862cae86d4aSKarsten Keil 
863cae86d4aSKarsten Keil static void
864cae86d4aSKarsten Keil release_card(struct inf_hw *card) {
865cae86d4aSKarsten Keil 	ulong	flags;
866cae86d4aSKarsten Keil 	int	i;
867cae86d4aSKarsten Keil 
868cae86d4aSKarsten Keil 	spin_lock_irqsave(&card->lock, flags);
869cae86d4aSKarsten Keil 	disable_hwirq(card);
870cae86d4aSKarsten Keil 	spin_unlock_irqrestore(&card->lock, flags);
871cae86d4aSKarsten Keil 	card->ipac.isac.release(&card->ipac.isac);
872cae86d4aSKarsten Keil 	free_irq(card->irq, card);
873cae86d4aSKarsten Keil 	mISDN_unregister_device(&card->ipac.isac.dch.dev);
874cae86d4aSKarsten Keil 	release_io(card);
875cae86d4aSKarsten Keil 	write_lock_irqsave(&card_lock, flags);
876cae86d4aSKarsten Keil 	list_del(&card->list);
877cae86d4aSKarsten Keil 	write_unlock_irqrestore(&card_lock, flags);
878cae86d4aSKarsten Keil 	switch (card->ci->typ) {
879cae86d4aSKarsten Keil 	case INF_SCT_2:
880cae86d4aSKarsten Keil 	case INF_SCT_3:
881cae86d4aSKarsten Keil 	case INF_SCT_4:
882cae86d4aSKarsten Keil 		break;
883cae86d4aSKarsten Keil 	case INF_SCT_1:
884cae86d4aSKarsten Keil 		for (i = 0; i < 3; i++) {
885cae86d4aSKarsten Keil 			if (card->sc[i])
886cae86d4aSKarsten Keil 				release_card(card->sc[i]);
887cae86d4aSKarsten Keil 			card->sc[i] = NULL;
888cae86d4aSKarsten Keil 		}
889cae86d4aSKarsten Keil 	default:
890cae86d4aSKarsten Keil 		pci_disable_device(card->pdev);
891cae86d4aSKarsten Keil 		pci_set_drvdata(card->pdev, NULL);
892cae86d4aSKarsten Keil 		break;
893cae86d4aSKarsten Keil 	}
894cae86d4aSKarsten Keil 	kfree(card);
895cae86d4aSKarsten Keil 	inf_cnt--;
896cae86d4aSKarsten Keil }
897cae86d4aSKarsten Keil 
898cae86d4aSKarsten Keil static int __devinit
899cae86d4aSKarsten Keil setup_instance(struct inf_hw *card)
900cae86d4aSKarsten Keil {
901cae86d4aSKarsten Keil 	int err;
902cae86d4aSKarsten Keil 	ulong flags;
903cae86d4aSKarsten Keil 
904cae86d4aSKarsten Keil 	snprintf(card->name, MISDN_MAX_IDLEN - 1, "%s.%d", card->ci->name,
905cae86d4aSKarsten Keil 		inf_cnt + 1);
906cae86d4aSKarsten Keil 	write_lock_irqsave(&card_lock, flags);
907cae86d4aSKarsten Keil 	list_add_tail(&card->list, &Cards);
908cae86d4aSKarsten Keil 	write_unlock_irqrestore(&card_lock, flags);
909cae86d4aSKarsten Keil 
910cae86d4aSKarsten Keil 	_set_debug(card);
911cae86d4aSKarsten Keil 	card->ipac.isac.name = card->name;
912cae86d4aSKarsten Keil 	card->ipac.name = card->name;
913cae86d4aSKarsten Keil 	card->ipac.owner = THIS_MODULE;
914cae86d4aSKarsten Keil 	spin_lock_init(&card->lock);
915cae86d4aSKarsten Keil 	card->ipac.isac.hwlock = &card->lock;
916cae86d4aSKarsten Keil 	card->ipac.hwlock = &card->lock;
917cae86d4aSKarsten Keil 	card->ipac.ctrl = (void *)&inf_ctrl;
918cae86d4aSKarsten Keil 
919cae86d4aSKarsten Keil 	err = setup_io(card);
920cae86d4aSKarsten Keil 	if (err)
921cae86d4aSKarsten Keil 		goto error_setup;
922cae86d4aSKarsten Keil 
923cae86d4aSKarsten Keil 	card->ipac.isac.dch.dev.Bprotocols =
924cae86d4aSKarsten Keil 		mISDNipac_init(&card->ipac, card);
925cae86d4aSKarsten Keil 
926cae86d4aSKarsten Keil 	if (card->ipac.isac.dch.dev.Bprotocols == 0)
927*ad65ffd1SJoe Perches 		goto error_setup;
928cae86d4aSKarsten Keil 
929cae86d4aSKarsten Keil 	err = mISDN_register_device(&card->ipac.isac.dch.dev,
930cae86d4aSKarsten Keil 		&card->pdev->dev, card->name);
931cae86d4aSKarsten Keil 	if (err)
932cae86d4aSKarsten Keil 		goto error;
933cae86d4aSKarsten Keil 
934cae86d4aSKarsten Keil 	err = init_irq(card);
935cae86d4aSKarsten Keil 	if (!err)  {
936cae86d4aSKarsten Keil 		inf_cnt++;
937cae86d4aSKarsten Keil 		pr_notice("Infineon %d cards installed\n", inf_cnt);
938cae86d4aSKarsten Keil 		return 0;
939cae86d4aSKarsten Keil 	}
940cae86d4aSKarsten Keil 	mISDN_unregister_device(&card->ipac.isac.dch.dev);
941cae86d4aSKarsten Keil error:
942cae86d4aSKarsten Keil 	card->ipac.release(&card->ipac);
943cae86d4aSKarsten Keil error_setup:
944cae86d4aSKarsten Keil 	release_io(card);
945cae86d4aSKarsten Keil 	write_lock_irqsave(&card_lock, flags);
946cae86d4aSKarsten Keil 	list_del(&card->list);
947cae86d4aSKarsten Keil 	write_unlock_irqrestore(&card_lock, flags);
948cae86d4aSKarsten Keil 	return err;
949cae86d4aSKarsten Keil }
950cae86d4aSKarsten Keil 
951cae86d4aSKarsten Keil static const struct inf_cinfo inf_card_info[] = {
952cae86d4aSKarsten Keil 	{
953cae86d4aSKarsten Keil 		INF_DIVA20,
954cae86d4aSKarsten Keil 		"Dialogic Diva 2.0",
955cae86d4aSKarsten Keil 		"diva20",
956cae86d4aSKarsten Keil 		AM_IND_IO, AM_NONE, 2, 0,
957cae86d4aSKarsten Keil 		&diva_irq
958cae86d4aSKarsten Keil 	},
959cae86d4aSKarsten Keil 	{
960cae86d4aSKarsten Keil 		INF_DIVA20U,
961cae86d4aSKarsten Keil 		"Dialogic Diva 2.0U",
962cae86d4aSKarsten Keil 		"diva20U",
963cae86d4aSKarsten Keil 		AM_IND_IO, AM_NONE, 2, 0,
964cae86d4aSKarsten Keil 		&diva_irq
965cae86d4aSKarsten Keil 	},
966cae86d4aSKarsten Keil 	{
967cae86d4aSKarsten Keil 		INF_DIVA201,
968cae86d4aSKarsten Keil 		"Dialogic Diva 2.01",
969cae86d4aSKarsten Keil 		"diva201",
970cae86d4aSKarsten Keil 		AM_MEMIO, AM_MEMIO, 0, 1,
971cae86d4aSKarsten Keil 		&diva20x_irq
972cae86d4aSKarsten Keil 	},
973cae86d4aSKarsten Keil 	{
974cae86d4aSKarsten Keil 		INF_DIVA202,
975cae86d4aSKarsten Keil 		"Dialogic Diva 2.02",
976cae86d4aSKarsten Keil 		"diva202",
977cae86d4aSKarsten Keil 		AM_MEMIO, AM_MEMIO, 0, 1,
978cae86d4aSKarsten Keil 		&diva20x_irq
979cae86d4aSKarsten Keil 	},
980cae86d4aSKarsten Keil 	{
981cae86d4aSKarsten Keil 		INF_SPEEDWIN,
982cae86d4aSKarsten Keil 		"Sedlbauer SpeedWin PCI",
983cae86d4aSKarsten Keil 		"speedwin",
984cae86d4aSKarsten Keil 		AM_IND_IO, AM_NONE, 0, 0,
985cae86d4aSKarsten Keil 		&tiger_irq
986cae86d4aSKarsten Keil 	},
987cae86d4aSKarsten Keil 	{
988cae86d4aSKarsten Keil 		INF_SAPHIR3,
989cae86d4aSKarsten Keil 		"HST Saphir 3",
990cae86d4aSKarsten Keil 		"saphir",
991cae86d4aSKarsten Keil 		AM_IND_IO, AM_NONE, 0, 0,
992cae86d4aSKarsten Keil 		&tiger_irq
993cae86d4aSKarsten Keil 	},
994cae86d4aSKarsten Keil 	{
995cae86d4aSKarsten Keil 		INF_QS1000,
996cae86d4aSKarsten Keil 		"Develo Microlink PCI",
997cae86d4aSKarsten Keil 		"qs1000",
998cae86d4aSKarsten Keil 		AM_IO, AM_IND_IO, 1, 3,
999cae86d4aSKarsten Keil 		&elsa_irq
1000cae86d4aSKarsten Keil 	},
1001cae86d4aSKarsten Keil 	{
1002cae86d4aSKarsten Keil 		INF_QS3000,
1003cae86d4aSKarsten Keil 		"Develo QuickStep 3000",
1004cae86d4aSKarsten Keil 		"qs3000",
1005cae86d4aSKarsten Keil 		AM_IO, AM_IND_IO, 1, 3,
1006cae86d4aSKarsten Keil 		&elsa_irq
1007cae86d4aSKarsten Keil 	},
1008cae86d4aSKarsten Keil 	{
1009cae86d4aSKarsten Keil 		INF_NICCY,
1010cae86d4aSKarsten Keil 		"Sagem NICCY",
1011cae86d4aSKarsten Keil 		"niccy",
1012cae86d4aSKarsten Keil 		AM_IO, AM_IND_IO, 0, 1,
1013cae86d4aSKarsten Keil 		&niccy_irq
1014cae86d4aSKarsten Keil 	},
1015cae86d4aSKarsten Keil 	{
1016cae86d4aSKarsten Keil 		INF_SCT_1,
1017cae86d4aSKarsten Keil 		"SciTel Quadro",
1018cae86d4aSKarsten Keil 		"p1_scitel",
1019cae86d4aSKarsten Keil 		AM_IO, AM_IND_IO, 1, 5,
1020cae86d4aSKarsten Keil 		&ipac_irq
1021cae86d4aSKarsten Keil 	},
1022cae86d4aSKarsten Keil 	{
1023cae86d4aSKarsten Keil 		INF_SCT_2,
1024cae86d4aSKarsten Keil 		"SciTel Quadro",
1025cae86d4aSKarsten Keil 		"p2_scitel",
1026cae86d4aSKarsten Keil 		AM_NONE, AM_IND_IO, 0, 4,
1027cae86d4aSKarsten Keil 		&ipac_irq
1028cae86d4aSKarsten Keil 	},
1029cae86d4aSKarsten Keil 	{
1030cae86d4aSKarsten Keil 		INF_SCT_3,
1031cae86d4aSKarsten Keil 		"SciTel Quadro",
1032cae86d4aSKarsten Keil 		"p3_scitel",
1033cae86d4aSKarsten Keil 		AM_NONE, AM_IND_IO, 0, 3,
1034cae86d4aSKarsten Keil 		&ipac_irq
1035cae86d4aSKarsten Keil 	},
1036cae86d4aSKarsten Keil 	{
1037cae86d4aSKarsten Keil 		INF_SCT_4,
1038cae86d4aSKarsten Keil 		"SciTel Quadro",
1039cae86d4aSKarsten Keil 		"p4_scitel",
1040cae86d4aSKarsten Keil 		AM_NONE, AM_IND_IO, 0, 2,
1041cae86d4aSKarsten Keil 		&ipac_irq
1042cae86d4aSKarsten Keil 	},
1043cae86d4aSKarsten Keil 	{
1044cae86d4aSKarsten Keil 		INF_GAZEL_R685,
1045cae86d4aSKarsten Keil 		"Gazel R685",
1046cae86d4aSKarsten Keil 		"gazel685",
1047cae86d4aSKarsten Keil 		AM_IO, AM_IO, 1, 2,
1048cae86d4aSKarsten Keil 		&gazel_irq
1049cae86d4aSKarsten Keil 	},
1050cae86d4aSKarsten Keil 	{
1051cae86d4aSKarsten Keil 		INF_GAZEL_R753,
1052cae86d4aSKarsten Keil 		"Gazel R753",
1053cae86d4aSKarsten Keil 		"gazel753",
1054cae86d4aSKarsten Keil 		AM_IO, AM_IND_IO, 1, 2,
1055cae86d4aSKarsten Keil 		&ipac_irq
1056cae86d4aSKarsten Keil 	},
1057cae86d4aSKarsten Keil 	{
1058cae86d4aSKarsten Keil 		INF_NONE,
1059cae86d4aSKarsten Keil 	}
1060cae86d4aSKarsten Keil };
1061cae86d4aSKarsten Keil 
1062cae86d4aSKarsten Keil static const struct inf_cinfo * __devinit
1063cae86d4aSKarsten Keil get_card_info(enum inf_types typ)
1064cae86d4aSKarsten Keil {
1065cae86d4aSKarsten Keil 	const struct inf_cinfo *ci = inf_card_info;
1066cae86d4aSKarsten Keil 
1067cae86d4aSKarsten Keil 	while (ci->typ != INF_NONE) {
1068cae86d4aSKarsten Keil 		if (ci->typ == typ)
1069cae86d4aSKarsten Keil 			return ci;
1070cae86d4aSKarsten Keil 		ci++;
1071cae86d4aSKarsten Keil 	}
1072cae86d4aSKarsten Keil 	return NULL;
1073cae86d4aSKarsten Keil }
1074cae86d4aSKarsten Keil 
1075cae86d4aSKarsten Keil static int __devinit
1076cae86d4aSKarsten Keil inf_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1077cae86d4aSKarsten Keil {
1078cae86d4aSKarsten Keil 	int err = -ENOMEM;
1079cae86d4aSKarsten Keil 	struct inf_hw *card;
1080cae86d4aSKarsten Keil 
1081cae86d4aSKarsten Keil 	card = kzalloc(sizeof(struct inf_hw), GFP_KERNEL);
1082cae86d4aSKarsten Keil 	if (!card) {
1083cae86d4aSKarsten Keil 		pr_info("No memory for Infineon ISDN card\n");
1084cae86d4aSKarsten Keil 		return err;
1085cae86d4aSKarsten Keil 	}
1086cae86d4aSKarsten Keil 	card->pdev = pdev;
1087cae86d4aSKarsten Keil 	err = pci_enable_device(pdev);
1088cae86d4aSKarsten Keil 	if (err) {
1089cae86d4aSKarsten Keil 		kfree(card);
1090cae86d4aSKarsten Keil 		return err;
1091cae86d4aSKarsten Keil 	}
1092cae86d4aSKarsten Keil 	card->ci = get_card_info(ent->driver_data);
1093cae86d4aSKarsten Keil 	if (!card->ci) {
1094cae86d4aSKarsten Keil 		pr_info("mISDN: do not have informations about adapter at %s\n",
1095cae86d4aSKarsten Keil 			pci_name(pdev));
1096cae86d4aSKarsten Keil 		kfree(card);
109706d88e4aSKulikov Vasiliy 		pci_disable_device(pdev);
1098cae86d4aSKarsten Keil 		return -EINVAL;
1099cae86d4aSKarsten Keil 	} else
1100cae86d4aSKarsten Keil 		pr_notice("mISDN: found adapter %s at %s\n",
1101cae86d4aSKarsten Keil 			card->ci->full, pci_name(pdev));
1102cae86d4aSKarsten Keil 
1103cae86d4aSKarsten Keil 	card->irq = pdev->irq;
1104cae86d4aSKarsten Keil 	pci_set_drvdata(pdev, card);
1105cae86d4aSKarsten Keil 	err = setup_instance(card);
1106cae86d4aSKarsten Keil 	if (err) {
110706d88e4aSKulikov Vasiliy 		pci_disable_device(pdev);
1108cae86d4aSKarsten Keil 		kfree(card);
1109cae86d4aSKarsten Keil 		pci_set_drvdata(pdev, NULL);
1110cae86d4aSKarsten Keil 	} else if (ent->driver_data == INF_SCT_1) {
1111cae86d4aSKarsten Keil 		int i;
1112cae86d4aSKarsten Keil 		struct inf_hw *sc;
1113cae86d4aSKarsten Keil 
1114cae86d4aSKarsten Keil 		for (i = 1; i < 4; i++) {
1115cae86d4aSKarsten Keil 			sc = kzalloc(sizeof(struct inf_hw), GFP_KERNEL);
1116cae86d4aSKarsten Keil 			if (!sc) {
1117cae86d4aSKarsten Keil 				release_card(card);
111806d88e4aSKulikov Vasiliy 				pci_disable_device(pdev);
1119cae86d4aSKarsten Keil 				return -ENOMEM;
1120cae86d4aSKarsten Keil 			}
1121cae86d4aSKarsten Keil 			sc->irq = card->irq;
1122cae86d4aSKarsten Keil 			sc->pdev = card->pdev;
1123cae86d4aSKarsten Keil 			sc->ci = card->ci + i;
1124cae86d4aSKarsten Keil 			err = setup_instance(sc);
1125cae86d4aSKarsten Keil 			if (err) {
112606d88e4aSKulikov Vasiliy 				pci_disable_device(pdev);
1127cae86d4aSKarsten Keil 				kfree(sc);
1128cae86d4aSKarsten Keil 				release_card(card);
1129f0f4d641SDarren Jenkins 				break;
1130cae86d4aSKarsten Keil 			} else
1131cae86d4aSKarsten Keil 				card->sc[i - 1] = sc;
1132cae86d4aSKarsten Keil 		}
1133cae86d4aSKarsten Keil 	}
1134cae86d4aSKarsten Keil 	return err;
1135cae86d4aSKarsten Keil }
1136cae86d4aSKarsten Keil 
1137cae86d4aSKarsten Keil static void __devexit
1138cae86d4aSKarsten Keil inf_remove(struct pci_dev *pdev)
1139cae86d4aSKarsten Keil {
1140cae86d4aSKarsten Keil 	struct inf_hw	*card = pci_get_drvdata(pdev);
1141cae86d4aSKarsten Keil 
1142cae86d4aSKarsten Keil 	if (card)
1143cae86d4aSKarsten Keil 		release_card(card);
1144cae86d4aSKarsten Keil 	else
1145698f9315SUwe Kleine-König 		pr_debug("%s: drvdata already removed\n", __func__);
1146cae86d4aSKarsten Keil }
1147cae86d4aSKarsten Keil 
1148cae86d4aSKarsten Keil static struct pci_driver infineon_driver = {
1149cae86d4aSKarsten Keil 	.name = "ISDN Infineon pci",
1150cae86d4aSKarsten Keil 	.probe = inf_probe,
1151cae86d4aSKarsten Keil 	.remove = __devexit_p(inf_remove),
1152cae86d4aSKarsten Keil 	.id_table = infineon_ids,
1153cae86d4aSKarsten Keil };
1154cae86d4aSKarsten Keil 
1155cae86d4aSKarsten Keil static int __init
1156cae86d4aSKarsten Keil infineon_init(void)
1157cae86d4aSKarsten Keil {
1158cae86d4aSKarsten Keil 	int err;
1159cae86d4aSKarsten Keil 
1160cae86d4aSKarsten Keil 	pr_notice("Infineon ISDN Driver Rev. %s\n", INFINEON_REV);
1161cae86d4aSKarsten Keil 	err = pci_register_driver(&infineon_driver);
1162cae86d4aSKarsten Keil 	return err;
1163cae86d4aSKarsten Keil }
1164cae86d4aSKarsten Keil 
1165cae86d4aSKarsten Keil static void __exit
1166cae86d4aSKarsten Keil infineon_cleanup(void)
1167cae86d4aSKarsten Keil {
1168cae86d4aSKarsten Keil 	pci_unregister_driver(&infineon_driver);
1169cae86d4aSKarsten Keil }
1170cae86d4aSKarsten Keil 
1171cae86d4aSKarsten Keil module_init(infineon_init);
1172cae86d4aSKarsten Keil module_exit(infineon_cleanup);
1173