1 /*********************************************************************
3 * Description: Driver for the SMC Infrared Communications Controller
4 * Author: Daniele Peri (peri@csai.unipa.it)
9 * Copyright (c) 2002 Daniele Peri
10 * All Rights Reserved.
11 * Copyright (c) 2002 Jean Tourrilhes
12 * Copyright (c) 2006 Linus Walleij
15 * Based on smc-ircc.c:
17 * Copyright (c) 2001 Stefani Seibold
18 * Copyright (c) 1999-2001 Dag Brattli
19 * Copyright (c) 1998-1999 Thomas Davis,
23 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
26 * This program is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU General Public License as
28 * published by the Free Software Foundation; either version 2 of
29 * the License, or (at your option) any later version.
31 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, see <http://www.gnu.org/licenses/>.
39 ********************************************************************/
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/types.h>
44 #include <linux/skbuff.h>
45 #include <linux/netdevice.h>
46 #include <linux/ioport.h>
47 #include <linux/delay.h>
48 #include <linux/init.h>
49 #include <linux/interrupt.h>
50 #include <linux/rtnetlink.h>
51 #include <linux/serial_reg.h>
52 #include <linux/dma-mapping.h>
53 #include <linux/pnp.h>
54 #include <linux/platform_device.h>
55 #include <linux/gfp.h>
59 #include <asm/byteorder.h>
61 #include <linux/spinlock.h>
64 #include <linux/pci.h>
67 #include <net/irda/wrapper.h>
68 #include <net/irda/irda.h>
69 #include <net/irda/irda_device.h>
71 #include "smsc-ircc2.h"
75 MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
76 MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
77 MODULE_LICENSE("GPL");
79 static bool smsc_nopnp
= true;
80 module_param_named(nopnp
, smsc_nopnp
, bool, 0);
81 MODULE_PARM_DESC(nopnp
, "Do not use PNP to detect controller settings, defaults to true");
84 static int ircc_dma
= DMA_INVAL
;
85 module_param(ircc_dma
, int, 0);
86 MODULE_PARM_DESC(ircc_dma
, "DMA channel");
89 static int ircc_irq
= IRQ_INVAL
;
90 module_param(ircc_irq
, int, 0);
91 MODULE_PARM_DESC(ircc_irq
, "IRQ line");
94 module_param(ircc_fir
, int, 0);
95 MODULE_PARM_DESC(ircc_fir
, "FIR Base Address");
98 module_param(ircc_sir
, int, 0);
99 MODULE_PARM_DESC(ircc_sir
, "SIR Base Address");
102 module_param(ircc_cfg
, int, 0);
103 MODULE_PARM_DESC(ircc_cfg
, "Configuration register base address");
105 static int ircc_transceiver
;
106 module_param(ircc_transceiver
, int, 0);
107 MODULE_PARM_DESC(ircc_transceiver
, "Transceiver type");
112 struct smsc_ircc_subsystem_configuration
{
113 unsigned short vendor
; /* PCI vendor ID */
114 unsigned short device
; /* PCI vendor ID */
115 unsigned short subvendor
; /* PCI subsystem vendor ID */
116 unsigned short subdevice
; /* PCI subsystem device ID */
117 unsigned short sir_io
; /* I/O port for SIR */
118 unsigned short fir_io
; /* I/O port for FIR */
119 unsigned char fir_irq
; /* FIR IRQ */
120 unsigned char fir_dma
; /* FIR DMA */
121 unsigned short cfg_base
; /* I/O port for chip configuration */
122 int (*preconfigure
)(struct pci_dev
*dev
, struct smsc_ircc_subsystem_configuration
*conf
); /* Preconfig function */
123 const char *name
; /* name shown as info */
127 struct smsc_transceiver
{
129 void (*set_for_speed
)(int fir_base
, u32 speed
);
130 int (*probe
)(int fir_base
);
143 struct smsc_chip_address
{
144 unsigned int cfg_base
;
148 /* Private data for each instance */
149 struct smsc_ircc_cb
{
150 struct net_device
*netdev
; /* Yes! we are some kind of netdevice */
151 struct irlap_cb
*irlap
; /* The link layer we are binded to */
153 chipio_t io
; /* IrDA controller information */
154 iobuff_t tx_buff
; /* Transmit buffer */
155 iobuff_t rx_buff
; /* Receive buffer */
156 dma_addr_t tx_buff_dma
;
157 dma_addr_t rx_buff_dma
;
159 struct qos_info qos
; /* QoS capabilities for this device */
161 spinlock_t lock
; /* For serializing operations */
164 __u32 flags
; /* Interface flags */
166 int tx_buff_offsets
[10]; /* Offsets between frames in tx_buff */
167 int tx_len
; /* Number of frames in tx_buff */
170 struct platform_device
*pldev
;
175 #define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
177 #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
178 #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
179 #define SMSC_IRCC2_C_NET_TIMEOUT 0
180 #define SMSC_IRCC2_C_SIR_STOP 0
182 static const char *driver_name
= SMSC_IRCC2_DRIVER_NAME
;
186 static int smsc_ircc_open(unsigned int firbase
, unsigned int sirbase
, u8 dma
, u8 irq
);
187 static int smsc_ircc_present(unsigned int fir_base
, unsigned int sir_base
);
188 static void smsc_ircc_setup_io(struct smsc_ircc_cb
*self
, unsigned int fir_base
, unsigned int sir_base
, u8 dma
, u8 irq
);
189 static void smsc_ircc_setup_qos(struct smsc_ircc_cb
*self
);
190 static void smsc_ircc_init_chip(struct smsc_ircc_cb
*self
);
191 static int __exit
smsc_ircc_close(struct smsc_ircc_cb
*self
);
192 static int smsc_ircc_dma_receive(struct smsc_ircc_cb
*self
);
193 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb
*self
);
194 static void smsc_ircc_sir_receive(struct smsc_ircc_cb
*self
);
195 static netdev_tx_t
smsc_ircc_hard_xmit_sir(struct sk_buff
*skb
,
196 struct net_device
*dev
);
197 static netdev_tx_t
smsc_ircc_hard_xmit_fir(struct sk_buff
*skb
,
198 struct net_device
*dev
);
199 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb
*self
, int bofs
);
200 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb
*self
);
201 static void smsc_ircc_change_speed(struct smsc_ircc_cb
*self
, u32 speed
);
202 static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb
*self
, u32 speed
);
203 static irqreturn_t
smsc_ircc_interrupt(int irq
, void *dev_id
);
204 static irqreturn_t
smsc_ircc_interrupt_sir(struct net_device
*dev
);
205 static void smsc_ircc_sir_start(struct smsc_ircc_cb
*self
);
206 #if SMSC_IRCC2_C_SIR_STOP
207 static void smsc_ircc_sir_stop(struct smsc_ircc_cb
*self
);
209 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb
*self
);
210 static int smsc_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
);
211 static int smsc_ircc_net_open(struct net_device
*dev
);
212 static int smsc_ircc_net_close(struct net_device
*dev
);
213 static int smsc_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
214 #if SMSC_IRCC2_C_NET_TIMEOUT
215 static void smsc_ircc_timeout(struct net_device
*dev
);
217 static int smsc_ircc_is_receiving(struct smsc_ircc_cb
*self
);
218 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb
*self
);
219 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb
*self
, u32 speed
);
220 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb
*self
);
223 static int __init
smsc_ircc_look_for_chips(void);
224 static const struct smsc_chip
* __init
smsc_ircc_probe(unsigned short cfg_base
, u8 reg
, const struct smsc_chip
*chip
, char *type
);
225 static int __init
smsc_superio_flat(const struct smsc_chip
*chips
, unsigned short cfg_base
, char *type
);
226 static int __init
smsc_superio_paged(const struct smsc_chip
*chips
, unsigned short cfg_base
, char *type
);
227 static int __init
smsc_superio_fdc(unsigned short cfg_base
);
228 static int __init
smsc_superio_lpc(unsigned short cfg_base
);
230 static int __init
preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration
*conf
);
231 static int __init
preconfigure_through_82801(struct pci_dev
*dev
, struct smsc_ircc_subsystem_configuration
*conf
);
232 static void __init
preconfigure_ali_port(struct pci_dev
*dev
,
233 unsigned short port
);
234 static int __init
preconfigure_through_ali(struct pci_dev
*dev
, struct smsc_ircc_subsystem_configuration
*conf
);
235 static int __init
smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg
,
236 unsigned short ircc_fir
,
237 unsigned short ircc_sir
,
238 unsigned char ircc_dma
,
239 unsigned char ircc_irq
);
242 /* Transceivers specific functions */
244 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base
, u32 speed
);
245 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base
);
246 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base
, u32 speed
);
247 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base
);
248 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base
, u32 speed
);
249 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base
);
251 /* Power Management */
253 static int smsc_ircc_suspend(struct platform_device
*dev
, pm_message_t state
);
254 static int smsc_ircc_resume(struct platform_device
*dev
);
256 static struct platform_driver smsc_ircc_driver
= {
257 .suspend
= smsc_ircc_suspend
,
258 .resume
= smsc_ircc_resume
,
260 .name
= SMSC_IRCC2_DRIVER_NAME
,
264 /* Transceivers for SMSC-ircc */
266 static struct smsc_transceiver smsc_transceivers
[] =
268 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800
, smsc_ircc_probe_transceiver_toshiba_sat1800
},
269 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select
, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select
},
270 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc
, smsc_ircc_probe_transceiver_smsc_ircc_atc
},
273 #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
275 /* SMC SuperIO chipsets definitions */
277 #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
278 #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
279 #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
280 #define SIR 0 /* SuperIO Chip has only slow IRDA */
281 #define FIR 4 /* SuperIO Chip has fast IRDA */
282 #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
284 static struct smsc_chip __initdata fdc_chips_flat
[] =
286 /* Base address 0x3f0 or 0x370 */
287 { "37C44", KEY55_1
|NoIRDA
, 0x00, 0x00 }, /* This chip cannot be detected */
288 { "37C665GT", KEY55_2
|NoIRDA
, 0x65, 0x01 },
289 { "37C665GT", KEY55_2
|NoIRDA
, 0x66, 0x01 },
290 { "37C669", KEY55_2
|SIR
|SERx4
, 0x03, 0x02 },
291 { "37C669", KEY55_2
|SIR
|SERx4
, 0x04, 0x02 }, /* ID? */
292 { "37C78", KEY55_2
|NoIRDA
, 0x78, 0x00 },
293 { "37N769", KEY55_1
|FIR
|SERx4
, 0x28, 0x00 },
294 { "37N869", KEY55_1
|FIR
|SERx4
, 0x29, 0x00 },
298 static struct smsc_chip __initdata fdc_chips_paged
[] =
300 /* Base address 0x3f0 or 0x370 */
301 { "37B72X", KEY55_1
|SIR
|SERx4
, 0x4c, 0x00 },
302 { "37B77X", KEY55_1
|SIR
|SERx4
, 0x43, 0x00 },
303 { "37B78X", KEY55_1
|SIR
|SERx4
, 0x44, 0x00 },
304 { "37B80X", KEY55_1
|SIR
|SERx4
, 0x42, 0x00 },
305 { "37C67X", KEY55_1
|FIR
|SERx4
, 0x40, 0x00 },
306 { "37C93X", KEY55_2
|SIR
|SERx4
, 0x02, 0x01 },
307 { "37C93XAPM", KEY55_1
|SIR
|SERx4
, 0x30, 0x01 },
308 { "37C93XFR", KEY55_2
|FIR
|SERx4
, 0x03, 0x01 },
309 { "37M707", KEY55_1
|SIR
|SERx4
, 0x42, 0x00 },
310 { "37M81X", KEY55_1
|SIR
|SERx4
, 0x4d, 0x00 },
311 { "37N958FR", KEY55_1
|FIR
|SERx4
, 0x09, 0x04 },
312 { "37N971", KEY55_1
|FIR
|SERx4
, 0x0a, 0x00 },
313 { "37N972", KEY55_1
|FIR
|SERx4
, 0x0b, 0x00 },
317 static struct smsc_chip __initdata lpc_chips_flat
[] =
319 /* Base address 0x2E or 0x4E */
320 { "47N227", KEY55_1
|FIR
|SERx4
, 0x5a, 0x00 },
321 { "47N227", KEY55_1
|FIR
|SERx4
, 0x7a, 0x00 },
322 { "47N267", KEY55_1
|FIR
|SERx4
, 0x5e, 0x00 },
326 static struct smsc_chip __initdata lpc_chips_paged
[] =
328 /* Base address 0x2E or 0x4E */
329 { "47B27X", KEY55_1
|SIR
|SERx4
, 0x51, 0x00 },
330 { "47B37X", KEY55_1
|SIR
|SERx4
, 0x52, 0x00 },
331 { "47M10X", KEY55_1
|SIR
|SERx4
, 0x59, 0x00 },
332 { "47M120", KEY55_1
|NoIRDA
|SERx4
, 0x5c, 0x00 },
333 { "47M13X", KEY55_1
|SIR
|SERx4
, 0x59, 0x00 },
334 { "47M14X", KEY55_1
|SIR
|SERx4
, 0x5f, 0x00 },
335 { "47N252", KEY55_1
|FIR
|SERx4
, 0x0e, 0x00 },
336 { "47S42X", KEY55_1
|SIR
|SERx4
, 0x57, 0x00 },
340 #define SMSCSIO_TYPE_FDC 1
341 #define SMSCSIO_TYPE_LPC 2
342 #define SMSCSIO_TYPE_FLAT 4
343 #define SMSCSIO_TYPE_PAGED 8
345 static struct smsc_chip_address __initdata possible_addresses
[] =
347 { 0x3f0, SMSCSIO_TYPE_FDC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
348 { 0x370, SMSCSIO_TYPE_FDC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
349 { 0xe0, SMSCSIO_TYPE_FDC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
350 { 0x2e, SMSCSIO_TYPE_LPC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
351 { 0x4e, SMSCSIO_TYPE_LPC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
357 static struct smsc_ircc_cb
*dev_self
[] = { NULL
, NULL
};
358 static unsigned short dev_count
;
360 static inline void register_bank(int iobase
, int bank
)
362 outb(((inb(iobase
+ IRCC_MASTER
) & 0xf0) | (bank
& 0x07)),
363 iobase
+ IRCC_MASTER
);
366 /* PNP hotplug support */
367 static const struct pnp_device_id smsc_ircc_pnp_table
[] = {
368 { .id
= "SMCf010", .driver_data
= 0 },
369 /* and presumably others */
372 MODULE_DEVICE_TABLE(pnp
, smsc_ircc_pnp_table
);
374 static int pnp_driver_registered
;
377 static int smsc_ircc_pnp_probe(struct pnp_dev
*dev
,
378 const struct pnp_device_id
*dev_id
)
380 unsigned int firbase
, sirbase
;
383 if (!(pnp_port_valid(dev
, 0) && pnp_port_valid(dev
, 1) &&
384 pnp_dma_valid(dev
, 0) && pnp_irq_valid(dev
, 0)))
387 sirbase
= pnp_port_start(dev
, 0);
388 firbase
= pnp_port_start(dev
, 1);
389 dma
= pnp_dma(dev
, 0);
390 irq
= pnp_irq(dev
, 0);
392 if (smsc_ircc_open(firbase
, sirbase
, dma
, irq
))
398 static struct pnp_driver smsc_ircc_pnp_driver
= {
399 .name
= "smsc-ircc2",
400 .id_table
= smsc_ircc_pnp_table
,
401 .probe
= smsc_ircc_pnp_probe
,
403 #else /* CONFIG_PNP */
404 static struct pnp_driver smsc_ircc_pnp_driver
;
407 /*******************************************************************************
413 *******************************************************************************/
415 static int __init
smsc_ircc_legacy_probe(void)
420 if (smsc_ircc_preconfigure_subsystems(ircc_cfg
, ircc_fir
, ircc_sir
, ircc_dma
, ircc_irq
) < 0) {
421 /* Ignore errors from preconfiguration */
422 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name
);
426 if (ircc_fir
> 0 && ircc_sir
> 0) {
427 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir
);
428 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir
);
430 if (smsc_ircc_open(ircc_fir
, ircc_sir
, ircc_dma
, ircc_irq
))
435 /* try user provided configuration register base address */
437 IRDA_MESSAGE(" Overriding configuration address "
438 "0x%04x\n", ircc_cfg
);
439 if (!smsc_superio_fdc(ircc_cfg
))
441 if (!smsc_superio_lpc(ircc_cfg
))
445 if (smsc_ircc_look_for_chips() > 0)
452 * Function smsc_ircc_init ()
454 * Initialize chip. Just try to find out how many chips we are dealing with
457 static int __init
smsc_ircc_init(void)
461 IRDA_DEBUG(1, "%s\n", __func__
);
463 ret
= platform_driver_register(&smsc_ircc_driver
);
465 IRDA_ERROR("%s, Can't register driver!\n", driver_name
);
471 if (smsc_nopnp
|| !pnp_platform_devices
||
472 ircc_cfg
|| ircc_fir
|| ircc_sir
||
473 ircc_dma
!= DMA_INVAL
|| ircc_irq
!= IRQ_INVAL
) {
474 ret
= smsc_ircc_legacy_probe();
476 if (pnp_register_driver(&smsc_ircc_pnp_driver
) == 0)
477 pnp_driver_registered
= 1;
481 if (pnp_driver_registered
)
482 pnp_unregister_driver(&smsc_ircc_pnp_driver
);
483 platform_driver_unregister(&smsc_ircc_driver
);
489 static netdev_tx_t
smsc_ircc_net_xmit(struct sk_buff
*skb
,
490 struct net_device
*dev
)
492 struct smsc_ircc_cb
*self
= netdev_priv(dev
);
494 if (self
->io
.speed
> 115200)
495 return smsc_ircc_hard_xmit_fir(skb
, dev
);
497 return smsc_ircc_hard_xmit_sir(skb
, dev
);
500 static const struct net_device_ops smsc_ircc_netdev_ops
= {
501 .ndo_open
= smsc_ircc_net_open
,
502 .ndo_stop
= smsc_ircc_net_close
,
503 .ndo_do_ioctl
= smsc_ircc_net_ioctl
,
504 .ndo_start_xmit
= smsc_ircc_net_xmit
,
505 #if SMSC_IRCC2_C_NET_TIMEOUT
506 .ndo_tx_timeout
= smsc_ircc_timeout
,
511 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
513 * Try to open driver instance
516 static int smsc_ircc_open(unsigned int fir_base
, unsigned int sir_base
, u8 dma
, u8 irq
)
518 struct smsc_ircc_cb
*self
;
519 struct net_device
*dev
;
522 IRDA_DEBUG(1, "%s\n", __func__
);
524 err
= smsc_ircc_present(fir_base
, sir_base
);
529 if (dev_count
>= ARRAY_SIZE(dev_self
)) {
530 IRDA_WARNING("%s(), too many devices!\n", __func__
);
535 * Allocate new instance of the driver
537 dev
= alloc_irdadev(sizeof(struct smsc_ircc_cb
));
539 IRDA_WARNING("%s() can't allocate net device\n", __func__
);
543 #if SMSC_IRCC2_C_NET_TIMEOUT
544 dev
->watchdog_timeo
= HZ
* 2; /* Allow enough time for speed change */
546 dev
->netdev_ops
= &smsc_ircc_netdev_ops
;
548 self
= netdev_priv(dev
);
551 /* Make ifconfig display some details */
552 dev
->base_addr
= self
->io
.fir_base
= fir_base
;
553 dev
->irq
= self
->io
.irq
= irq
;
555 /* Need to store self somewhere */
556 dev_self
[dev_count
] = self
;
557 spin_lock_init(&self
->lock
);
559 self
->rx_buff
.truesize
= SMSC_IRCC2_RX_BUFF_TRUESIZE
;
560 self
->tx_buff
.truesize
= SMSC_IRCC2_TX_BUFF_TRUESIZE
;
563 dma_zalloc_coherent(NULL
, self
->rx_buff
.truesize
,
564 &self
->rx_buff_dma
, GFP_KERNEL
);
565 if (self
->rx_buff
.head
== NULL
)
569 dma_zalloc_coherent(NULL
, self
->tx_buff
.truesize
,
570 &self
->tx_buff_dma
, GFP_KERNEL
);
571 if (self
->tx_buff
.head
== NULL
)
574 self
->rx_buff
.in_frame
= FALSE
;
575 self
->rx_buff
.state
= OUTSIDE_FRAME
;
576 self
->tx_buff
.data
= self
->tx_buff
.head
;
577 self
->rx_buff
.data
= self
->rx_buff
.head
;
579 smsc_ircc_setup_io(self
, fir_base
, sir_base
, dma
, irq
);
580 smsc_ircc_setup_qos(self
);
581 smsc_ircc_init_chip(self
);
583 if (ircc_transceiver
> 0 &&
584 ircc_transceiver
< SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS
)
585 self
->transceiver
= ircc_transceiver
;
587 smsc_ircc_probe_transceiver(self
);
589 err
= register_netdev(self
->netdev
);
591 IRDA_ERROR("%s, Network device registration failed!\n",
596 self
->pldev
= platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME
,
598 if (IS_ERR(self
->pldev
)) {
599 err
= PTR_ERR(self
->pldev
);
602 platform_set_drvdata(self
->pldev
, self
);
604 IRDA_MESSAGE("IrDA: Registered device %s\n", dev
->name
);
610 unregister_netdev(self
->netdev
);
613 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
614 self
->tx_buff
.head
, self
->tx_buff_dma
);
616 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
617 self
->rx_buff
.head
, self
->rx_buff_dma
);
619 free_netdev(self
->netdev
);
620 dev_self
[dev_count
] = NULL
;
622 release_region(fir_base
, SMSC_IRCC2_FIR_CHIP_IO_EXTENT
);
623 release_region(sir_base
, SMSC_IRCC2_SIR_CHIP_IO_EXTENT
);
629 * Function smsc_ircc_present(fir_base, sir_base)
631 * Check the smsc-ircc chip presence
634 static int smsc_ircc_present(unsigned int fir_base
, unsigned int sir_base
)
636 unsigned char low
, high
, chip
, config
, dma
, irq
, version
;
638 if (!request_region(fir_base
, SMSC_IRCC2_FIR_CHIP_IO_EXTENT
,
640 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
645 if (!request_region(sir_base
, SMSC_IRCC2_SIR_CHIP_IO_EXTENT
,
647 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
652 register_bank(fir_base
, 3);
654 high
= inb(fir_base
+ IRCC_ID_HIGH
);
655 low
= inb(fir_base
+ IRCC_ID_LOW
);
656 chip
= inb(fir_base
+ IRCC_CHIP_ID
);
657 version
= inb(fir_base
+ IRCC_VERSION
);
658 config
= inb(fir_base
+ IRCC_INTERFACE
);
659 dma
= config
& IRCC_INTERFACE_DMA_MASK
;
660 irq
= (config
& IRCC_INTERFACE_IRQ_MASK
) >> 4;
662 if (high
!= 0x10 || low
!= 0xb8 || (chip
!= 0xf1 && chip
!= 0xf2)) {
663 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
667 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
668 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
669 chip
& 0x0f, version
, fir_base
, sir_base
, dma
, irq
);
674 release_region(sir_base
, SMSC_IRCC2_SIR_CHIP_IO_EXTENT
);
676 release_region(fir_base
, SMSC_IRCC2_FIR_CHIP_IO_EXTENT
);
682 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
687 static void smsc_ircc_setup_io(struct smsc_ircc_cb
*self
,
688 unsigned int fir_base
, unsigned int sir_base
,
691 unsigned char config
, chip_dma
, chip_irq
;
693 register_bank(fir_base
, 3);
694 config
= inb(fir_base
+ IRCC_INTERFACE
);
695 chip_dma
= config
& IRCC_INTERFACE_DMA_MASK
;
696 chip_irq
= (config
& IRCC_INTERFACE_IRQ_MASK
) >> 4;
698 self
->io
.fir_base
= fir_base
;
699 self
->io
.sir_base
= sir_base
;
700 self
->io
.fir_ext
= SMSC_IRCC2_FIR_CHIP_IO_EXTENT
;
701 self
->io
.sir_ext
= SMSC_IRCC2_SIR_CHIP_IO_EXTENT
;
702 self
->io
.fifo_size
= SMSC_IRCC2_FIFO_SIZE
;
703 self
->io
.speed
= SMSC_IRCC2_C_IRDA_FALLBACK_SPEED
;
705 if (irq
!= IRQ_INVAL
) {
707 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
708 driver_name
, chip_irq
, irq
);
711 self
->io
.irq
= chip_irq
;
713 if (dma
!= DMA_INVAL
) {
715 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
716 driver_name
, chip_dma
, dma
);
719 self
->io
.dma
= chip_dma
;
724 * Function smsc_ircc_setup_qos(self)
729 static void smsc_ircc_setup_qos(struct smsc_ircc_cb
*self
)
731 /* Initialize QoS for this device */
732 irda_init_max_qos_capabilies(&self
->qos
);
734 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
735 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8);
737 self
->qos
.min_turn_time
.bits
= SMSC_IRCC2_MIN_TURN_TIME
;
738 self
->qos
.window_size
.bits
= SMSC_IRCC2_WINDOW_SIZE
;
739 irda_qos_bits_to_value(&self
->qos
);
743 * Function smsc_ircc_init_chip(self)
748 static void smsc_ircc_init_chip(struct smsc_ircc_cb
*self
)
750 int iobase
= self
->io
.fir_base
;
752 register_bank(iobase
, 0);
753 outb(IRCC_MASTER_RESET
, iobase
+ IRCC_MASTER
);
754 outb(0x00, iobase
+ IRCC_MASTER
);
756 register_bank(iobase
, 1);
757 outb(((inb(iobase
+ IRCC_SCE_CFGA
) & 0x87) | IRCC_CFGA_IRDA_SIR_A
),
758 iobase
+ IRCC_SCE_CFGA
);
760 #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
761 outb(((inb(iobase
+ IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_COM
),
762 iobase
+ IRCC_SCE_CFGB
);
764 outb(((inb(iobase
+ IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_IR
),
765 iobase
+ IRCC_SCE_CFGB
);
767 (void) inb(iobase
+ IRCC_FIFO_THRESHOLD
);
768 outb(SMSC_IRCC2_FIFO_THRESHOLD
, iobase
+ IRCC_FIFO_THRESHOLD
);
770 register_bank(iobase
, 4);
771 outb((inb(iobase
+ IRCC_CONTROL
) & 0x30), iobase
+ IRCC_CONTROL
);
773 register_bank(iobase
, 0);
774 outb(0, iobase
+ IRCC_LCR_A
);
776 smsc_ircc_set_sir_speed(self
, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED
);
778 /* Power on device */
779 outb(0x00, iobase
+ IRCC_MASTER
);
783 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
785 * Process IOCTL commands for this device
788 static int smsc_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
790 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
791 struct smsc_ircc_cb
*self
;
795 IRDA_ASSERT(dev
!= NULL
, return -1;);
797 self
= netdev_priv(dev
);
799 IRDA_ASSERT(self
!= NULL
, return -1;);
801 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__
, dev
->name
, cmd
);
804 case SIOCSBANDWIDTH
: /* Set bandwidth */
805 if (!capable(CAP_NET_ADMIN
))
808 /* Make sure we are the only one touching
809 * self->io.speed and the hardware - Jean II */
810 spin_lock_irqsave(&self
->lock
, flags
);
811 smsc_ircc_change_speed(self
, irq
->ifr_baudrate
);
812 spin_unlock_irqrestore(&self
->lock
, flags
);
815 case SIOCSMEDIABUSY
: /* Set media busy */
816 if (!capable(CAP_NET_ADMIN
)) {
821 irda_device_set_media_busy(self
->netdev
, TRUE
);
823 case SIOCGRECEIVING
: /* Check if we are receiving right now */
824 irq
->ifr_receiving
= smsc_ircc_is_receiving(self
);
828 if (!capable(CAP_NET_ADMIN
)) {
832 smsc_ircc_sir_set_dtr_rts(dev
, irq
->ifr_dtr
, irq
->ifr_rts
);
842 #if SMSC_IRCC2_C_NET_TIMEOUT
844 * Function smsc_ircc_timeout (struct net_device *dev)
846 * The networking timeout management.
850 static void smsc_ircc_timeout(struct net_device
*dev
)
852 struct smsc_ircc_cb
*self
= netdev_priv(dev
);
855 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
856 dev
->name
, self
->io
.speed
);
857 spin_lock_irqsave(&self
->lock
, flags
);
858 smsc_ircc_sir_start(self
);
859 smsc_ircc_change_speed(self
, self
->io
.speed
);
860 dev
->trans_start
= jiffies
; /* prevent tx timeout */
861 netif_wake_queue(dev
);
862 spin_unlock_irqrestore(&self
->lock
, flags
);
867 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
869 * Transmits the current frame until FIFO is full, then
870 * waits until the next transmit interrupt, and continues until the
871 * frame is transmitted.
873 static netdev_tx_t
smsc_ircc_hard_xmit_sir(struct sk_buff
*skb
,
874 struct net_device
*dev
)
876 struct smsc_ircc_cb
*self
;
880 IRDA_DEBUG(1, "%s\n", __func__
);
882 IRDA_ASSERT(dev
!= NULL
, return NETDEV_TX_OK
;);
884 self
= netdev_priv(dev
);
885 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
887 netif_stop_queue(dev
);
889 /* Make sure test of self->io.speed & speed change are atomic */
890 spin_lock_irqsave(&self
->lock
, flags
);
892 /* Check if we need to change the speed */
893 speed
= irda_get_next_speed(skb
);
894 if (speed
!= self
->io
.speed
&& speed
!= -1) {
895 /* Check for empty frame */
898 * We send frames one by one in SIR mode (no
899 * pipelining), so at this point, if we were sending
900 * a previous frame, we just received the interrupt
901 * telling us it is finished (UART_IIR_THRI).
902 * Therefore, waiting for the transmitter to really
903 * finish draining the fifo won't take too long.
904 * And the interrupt handler is not expected to run.
906 smsc_ircc_sir_wait_hw_transmitter_finish(self
);
907 smsc_ircc_change_speed(self
, speed
);
908 spin_unlock_irqrestore(&self
->lock
, flags
);
912 self
->new_speed
= speed
;
916 self
->tx_buff
.data
= self
->tx_buff
.head
;
918 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
919 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
920 self
->tx_buff
.truesize
);
922 dev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
924 /* Turn on transmit finished interrupt. Will fire immediately! */
925 outb(UART_IER_THRI
, self
->io
.sir_base
+ UART_IER
);
927 spin_unlock_irqrestore(&self
->lock
, flags
);
935 * Function smsc_ircc_set_fir_speed (self, baud)
937 * Change the speed of the device
940 static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb
*self
, u32 speed
)
942 int fir_base
, ir_mode
, ctrl
, fast
;
944 IRDA_ASSERT(self
!= NULL
, return;);
945 fir_base
= self
->io
.fir_base
;
947 self
->io
.speed
= speed
;
952 ir_mode
= IRCC_CFGA_IRDA_HDLC
;
955 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __func__
);
958 ir_mode
= IRCC_CFGA_IRDA_HDLC
;
959 ctrl
= IRCC_1152
| IRCC_CRC
;
960 fast
= IRCC_LCR_A_FAST
| IRCC_LCR_A_GP_DATA
;
961 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
965 ir_mode
= IRCC_CFGA_IRDA_4PPM
;
967 fast
= IRCC_LCR_A_FAST
;
968 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
974 /* This causes an interrupt */
975 register_bank(fir_base
, 0);
976 outb((inb(fir_base
+ IRCC_LCR_A
) & 0xbf) | fast
, fir_base
+ IRCC_LCR_A
);
979 register_bank(fir_base
, 1);
980 outb(((inb(fir_base
+ IRCC_SCE_CFGA
) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK
) | ir_mode
), fir_base
+ IRCC_SCE_CFGA
);
982 register_bank(fir_base
, 4);
983 outb((inb(fir_base
+ IRCC_CONTROL
) & 0x30) | ctrl
, fir_base
+ IRCC_CONTROL
);
987 * Function smsc_ircc_fir_start(self)
989 * Change the speed of the device
992 static void smsc_ircc_fir_start(struct smsc_ircc_cb
*self
)
994 struct net_device
*dev
;
997 IRDA_DEBUG(1, "%s\n", __func__
);
999 IRDA_ASSERT(self
!= NULL
, return;);
1001 IRDA_ASSERT(dev
!= NULL
, return;);
1003 fir_base
= self
->io
.fir_base
;
1005 /* Reset everything */
1008 outb(inb(fir_base
+ IRCC_LCR_A
) | IRCC_LCR_A_FIFO_RESET
, fir_base
+ IRCC_LCR_A
);
1010 /* Enable interrupt */
1011 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
1013 register_bank(fir_base
, 1);
1015 /* Select the TX/RX interface */
1016 #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
1017 outb(((inb(fir_base
+ IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_COM
),
1018 fir_base
+ IRCC_SCE_CFGB
);
1020 outb(((inb(fir_base
+ IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_IR
),
1021 fir_base
+ IRCC_SCE_CFGB
);
1023 (void) inb(fir_base
+ IRCC_FIFO_THRESHOLD
);
1025 /* Enable SCE interrupts */
1026 outb(0, fir_base
+ IRCC_MASTER
);
1027 register_bank(fir_base
, 0);
1028 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, fir_base
+ IRCC_IER
);
1029 outb(IRCC_MASTER_INT_EN
, fir_base
+ IRCC_MASTER
);
1033 * Function smsc_ircc_fir_stop(self, baud)
1035 * Change the speed of the device
1038 static void smsc_ircc_fir_stop(struct smsc_ircc_cb
*self
)
1042 IRDA_DEBUG(1, "%s\n", __func__
);
1044 IRDA_ASSERT(self
!= NULL
, return;);
1046 fir_base
= self
->io
.fir_base
;
1047 register_bank(fir_base
, 0);
1048 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1049 outb(inb(fir_base
+ IRCC_LCR_B
) & IRCC_LCR_B_SIP_ENABLE
, fir_base
+ IRCC_LCR_B
);
1054 * Function smsc_ircc_change_speed(self, baud)
1056 * Change the speed of the device
1058 * This function *must* be called with spinlock held, because it may
1059 * be called from the irq handler. - Jean II
1061 static void smsc_ircc_change_speed(struct smsc_ircc_cb
*self
, u32 speed
)
1063 struct net_device
*dev
;
1064 int last_speed_was_sir
;
1066 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __func__
, speed
);
1068 IRDA_ASSERT(self
!= NULL
, return;);
1071 last_speed_was_sir
= self
->io
.speed
<= SMSC_IRCC2_MAX_SIR_SPEED
;
1076 self
->io
.speed
= speed
;
1077 last_speed_was_sir
= 0;
1078 smsc_ircc_fir_start(self
);
1081 if (self
->io
.speed
== 0)
1082 smsc_ircc_sir_start(self
);
1085 if (!last_speed_was_sir
) speed
= self
->io
.speed
;
1088 if (self
->io
.speed
!= speed
)
1089 smsc_ircc_set_transceiver_for_speed(self
, speed
);
1091 self
->io
.speed
= speed
;
1093 if (speed
<= SMSC_IRCC2_MAX_SIR_SPEED
) {
1094 if (!last_speed_was_sir
) {
1095 smsc_ircc_fir_stop(self
);
1096 smsc_ircc_sir_start(self
);
1098 smsc_ircc_set_sir_speed(self
, speed
);
1100 if (last_speed_was_sir
) {
1101 #if SMSC_IRCC2_C_SIR_STOP
1102 smsc_ircc_sir_stop(self
);
1104 smsc_ircc_fir_start(self
);
1106 smsc_ircc_set_fir_speed(self
, speed
);
1109 self
->tx_buff
.len
= 10;
1110 self
->tx_buff
.data
= self
->tx_buff
.head
;
1112 smsc_ircc_dma_xmit(self
, 4000);
1114 /* Be ready for incoming frames */
1115 smsc_ircc_dma_receive(self
);
1118 netif_wake_queue(dev
);
1122 * Function smsc_ircc_set_sir_speed (self, speed)
1124 * Set speed of IrDA port to specified baudrate
1127 static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb
*self
, __u32 speed
)
1130 int fcr
; /* FIFO control reg */
1131 int lcr
; /* Line control reg */
1134 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __func__
, speed
);
1136 IRDA_ASSERT(self
!= NULL
, return;);
1137 iobase
= self
->io
.sir_base
;
1139 /* Update accounting for new speed */
1140 self
->io
.speed
= speed
;
1142 /* Turn off interrupts */
1143 outb(0, iobase
+ UART_IER
);
1145 divisor
= SMSC_IRCC2_MAX_SIR_SPEED
/ speed
;
1147 fcr
= UART_FCR_ENABLE_FIFO
;
1150 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1151 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1152 * about this timeout since it will always be fast enough.
1154 fcr
|= self
->io
.speed
< 38400 ?
1155 UART_FCR_TRIGGER_1
: UART_FCR_TRIGGER_14
;
1157 /* IrDA ports use 8N1 */
1158 lcr
= UART_LCR_WLEN8
;
1160 outb(UART_LCR_DLAB
| lcr
, iobase
+ UART_LCR
); /* Set DLAB */
1161 outb(divisor
& 0xff, iobase
+ UART_DLL
); /* Set speed */
1162 outb(divisor
>> 8, iobase
+ UART_DLM
);
1163 outb(lcr
, iobase
+ UART_LCR
); /* Set 8N1 */
1164 outb(fcr
, iobase
+ UART_FCR
); /* Enable FIFO's */
1166 /* Turn on interrups */
1167 outb(UART_IER_RLSI
| UART_IER_RDI
| UART_IER_THRI
, iobase
+ UART_IER
);
1169 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __func__
, speed
);
1174 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1176 * Transmit the frame!
1179 static netdev_tx_t
smsc_ircc_hard_xmit_fir(struct sk_buff
*skb
,
1180 struct net_device
*dev
)
1182 struct smsc_ircc_cb
*self
;
1183 unsigned long flags
;
1187 IRDA_ASSERT(dev
!= NULL
, return NETDEV_TX_OK
;);
1188 self
= netdev_priv(dev
);
1189 IRDA_ASSERT(self
!= NULL
, return NETDEV_TX_OK
;);
1191 netif_stop_queue(dev
);
1193 /* Make sure test of self->io.speed & speed change are atomic */
1194 spin_lock_irqsave(&self
->lock
, flags
);
1196 /* Check if we need to change the speed after this frame */
1197 speed
= irda_get_next_speed(skb
);
1198 if (speed
!= self
->io
.speed
&& speed
!= -1) {
1199 /* Check for empty frame */
1201 /* Note : you should make sure that speed changes
1202 * are not going to corrupt any outgoing frame.
1203 * Look at nsc-ircc for the gory details - Jean II */
1204 smsc_ircc_change_speed(self
, speed
);
1205 spin_unlock_irqrestore(&self
->lock
, flags
);
1207 return NETDEV_TX_OK
;
1210 self
->new_speed
= speed
;
1213 skb_copy_from_linear_data(skb
, self
->tx_buff
.head
, skb
->len
);
1215 self
->tx_buff
.len
= skb
->len
;
1216 self
->tx_buff
.data
= self
->tx_buff
.head
;
1218 mtt
= irda_get_mtt(skb
);
1223 * Compute how many BOFs (STA or PA's) we need to waste the
1224 * min turn time given the speed of the link.
1226 bofs
= mtt
* (self
->io
.speed
/ 1000) / 8000;
1230 smsc_ircc_dma_xmit(self
, bofs
);
1232 /* Transmit frame */
1233 smsc_ircc_dma_xmit(self
, 0);
1236 spin_unlock_irqrestore(&self
->lock
, flags
);
1239 return NETDEV_TX_OK
;
1243 * Function smsc_ircc_dma_xmit (self, bofs)
1245 * Transmit data using DMA
1248 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb
*self
, int bofs
)
1250 int iobase
= self
->io
.fir_base
;
1253 IRDA_DEBUG(3, "%s\n", __func__
);
1256 register_bank(iobase
, 0);
1257 outb(0x00, iobase
+ IRCC_LCR_B
);
1259 register_bank(iobase
, 1);
1260 outb(inb(iobase
+ IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1261 iobase
+ IRCC_SCE_CFGB
);
1263 self
->io
.direction
= IO_XMIT
;
1265 /* Set BOF additional count for generating the min turn time */
1266 register_bank(iobase
, 4);
1267 outb(bofs
& 0xff, iobase
+ IRCC_BOF_COUNT_LO
);
1268 ctrl
= inb(iobase
+ IRCC_CONTROL
) & 0xf0;
1269 outb(ctrl
| ((bofs
>> 8) & 0x0f), iobase
+ IRCC_BOF_COUNT_HI
);
1271 /* Set max Tx frame size */
1272 outb(self
->tx_buff
.len
>> 8, iobase
+ IRCC_TX_SIZE_HI
);
1273 outb(self
->tx_buff
.len
& 0xff, iobase
+ IRCC_TX_SIZE_LO
);
1275 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1277 /* Enable burst mode chip Tx DMA */
1278 register_bank(iobase
, 1);
1279 outb(inb(iobase
+ IRCC_SCE_CFGB
) | IRCC_CFGB_DMA_ENABLE
|
1280 IRCC_CFGB_DMA_BURST
, iobase
+ IRCC_SCE_CFGB
);
1282 /* Setup DMA controller (must be done after enabling chip DMA) */
1283 irda_setup_dma(self
->io
.dma
, self
->tx_buff_dma
, self
->tx_buff
.len
,
1286 /* Enable interrupt */
1288 register_bank(iobase
, 0);
1289 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, iobase
+ IRCC_IER
);
1290 outb(IRCC_MASTER_INT_EN
, iobase
+ IRCC_MASTER
);
1292 /* Enable transmit */
1293 outb(IRCC_LCR_B_SCE_TRANSMIT
| IRCC_LCR_B_SIP_ENABLE
, iobase
+ IRCC_LCR_B
);
1297 * Function smsc_ircc_dma_xmit_complete (self)
1299 * The transfer of a frame in finished. This function will only be called
1300 * by the interrupt handler
1303 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb
*self
)
1305 int iobase
= self
->io
.fir_base
;
1307 IRDA_DEBUG(3, "%s\n", __func__
);
1310 register_bank(iobase
, 0);
1311 outb(0x00, iobase
+ IRCC_LCR_B
);
1313 register_bank(iobase
, 1);
1314 outb(inb(iobase
+ IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1315 iobase
+ IRCC_SCE_CFGB
);
1317 /* Check for underrun! */
1318 register_bank(iobase
, 0);
1319 if (inb(iobase
+ IRCC_LSR
) & IRCC_LSR_UNDERRUN
) {
1320 self
->netdev
->stats
.tx_errors
++;
1321 self
->netdev
->stats
.tx_fifo_errors
++;
1323 /* Reset error condition */
1324 register_bank(iobase
, 0);
1325 outb(IRCC_MASTER_ERROR_RESET
, iobase
+ IRCC_MASTER
);
1326 outb(0x00, iobase
+ IRCC_MASTER
);
1328 self
->netdev
->stats
.tx_packets
++;
1329 self
->netdev
->stats
.tx_bytes
+= self
->tx_buff
.len
;
1332 /* Check if it's time to change the speed */
1333 if (self
->new_speed
) {
1334 smsc_ircc_change_speed(self
, self
->new_speed
);
1335 self
->new_speed
= 0;
1338 netif_wake_queue(self
->netdev
);
1342 * Function smsc_ircc_dma_receive(self)
1344 * Get ready for receiving a frame. The device will initiate a DMA
1345 * if it starts to receive a frame.
1348 static int smsc_ircc_dma_receive(struct smsc_ircc_cb
*self
)
1350 int iobase
= self
->io
.fir_base
;
1352 /* Turn off chip DMA */
1353 register_bank(iobase
, 1);
1354 outb(inb(iobase
+ IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1355 iobase
+ IRCC_SCE_CFGB
);
1359 register_bank(iobase
, 0);
1360 outb(0x00, iobase
+ IRCC_LCR_B
);
1362 /* Turn off chip DMA */
1363 register_bank(iobase
, 1);
1364 outb(inb(iobase
+ IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1365 iobase
+ IRCC_SCE_CFGB
);
1367 self
->io
.direction
= IO_RECV
;
1368 self
->rx_buff
.data
= self
->rx_buff
.head
;
1370 /* Set max Rx frame size */
1371 register_bank(iobase
, 4);
1372 outb((2050 >> 8) & 0x0f, iobase
+ IRCC_RX_SIZE_HI
);
1373 outb(2050 & 0xff, iobase
+ IRCC_RX_SIZE_LO
);
1375 /* Setup DMA controller */
1376 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1379 /* Enable burst mode chip Rx DMA */
1380 register_bank(iobase
, 1);
1381 outb(inb(iobase
+ IRCC_SCE_CFGB
) | IRCC_CFGB_DMA_ENABLE
|
1382 IRCC_CFGB_DMA_BURST
, iobase
+ IRCC_SCE_CFGB
);
1384 /* Enable interrupt */
1385 register_bank(iobase
, 0);
1386 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, iobase
+ IRCC_IER
);
1387 outb(IRCC_MASTER_INT_EN
, iobase
+ IRCC_MASTER
);
1389 /* Enable receiver */
1390 register_bank(iobase
, 0);
1391 outb(IRCC_LCR_B_SCE_RECEIVE
| IRCC_LCR_B_SIP_ENABLE
,
1392 iobase
+ IRCC_LCR_B
);
1398 * Function smsc_ircc_dma_receive_complete(self)
1400 * Finished with receiving frames
1403 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb
*self
)
1405 struct sk_buff
*skb
;
1406 int len
, msgcnt
, lsr
;
1407 int iobase
= self
->io
.fir_base
;
1409 register_bank(iobase
, 0);
1411 IRDA_DEBUG(3, "%s\n", __func__
);
1414 register_bank(iobase
, 0);
1415 outb(0x00, iobase
+ IRCC_LCR_B
);
1417 register_bank(iobase
, 0);
1418 outb(inb(iobase
+ IRCC_LSAR
) & ~IRCC_LSAR_ADDRESS_MASK
, iobase
+ IRCC_LSAR
);
1419 lsr
= inb(iobase
+ IRCC_LSR
);
1420 msgcnt
= inb(iobase
+ IRCC_LCR_B
) & 0x08;
1422 IRDA_DEBUG(2, "%s: dma count = %d\n", __func__
,
1423 get_dma_residue(self
->io
.dma
));
1425 len
= self
->rx_buff
.truesize
- get_dma_residue(self
->io
.dma
);
1427 /* Look for errors */
1428 if (lsr
& (IRCC_LSR_FRAME_ERROR
| IRCC_LSR_CRC_ERROR
| IRCC_LSR_SIZE_ERROR
)) {
1429 self
->netdev
->stats
.rx_errors
++;
1430 if (lsr
& IRCC_LSR_FRAME_ERROR
)
1431 self
->netdev
->stats
.rx_frame_errors
++;
1432 if (lsr
& IRCC_LSR_CRC_ERROR
)
1433 self
->netdev
->stats
.rx_crc_errors
++;
1434 if (lsr
& IRCC_LSR_SIZE_ERROR
)
1435 self
->netdev
->stats
.rx_length_errors
++;
1436 if (lsr
& (IRCC_LSR_UNDERRUN
| IRCC_LSR_OVERRUN
))
1437 self
->netdev
->stats
.rx_length_errors
++;
1442 len
-= self
->io
.speed
< 4000000 ? 2 : 4;
1444 if (len
< 2 || len
> 2050) {
1445 IRDA_WARNING("%s(), bogus len=%d\n", __func__
, len
);
1448 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __func__
, msgcnt
, len
);
1450 skb
= dev_alloc_skb(len
+ 1);
1452 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1456 /* Make sure IP header gets aligned */
1457 skb_reserve(skb
, 1);
1459 memcpy(skb_put(skb
, len
), self
->rx_buff
.data
, len
);
1460 self
->netdev
->stats
.rx_packets
++;
1461 self
->netdev
->stats
.rx_bytes
+= len
;
1463 skb
->dev
= self
->netdev
;
1464 skb_reset_mac_header(skb
);
1465 skb
->protocol
= htons(ETH_P_IRDA
);
1470 * Function smsc_ircc_sir_receive (self)
1472 * Receive one frame from the infrared port
1475 static void smsc_ircc_sir_receive(struct smsc_ircc_cb
*self
)
1480 IRDA_ASSERT(self
!= NULL
, return;);
1482 iobase
= self
->io
.sir_base
;
1485 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1486 * async_unwrap_char will deliver all found frames
1489 async_unwrap_char(self
->netdev
, &self
->netdev
->stats
, &self
->rx_buff
,
1490 inb(iobase
+ UART_RX
));
1492 /* Make sure we don't stay here to long */
1493 if (boguscount
++ > 32) {
1494 IRDA_DEBUG(2, "%s(), breaking!\n", __func__
);
1497 } while (inb(iobase
+ UART_LSR
) & UART_LSR_DR
);
1502 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1504 * An interrupt from the chip has arrived. Time to do some work
1507 static irqreturn_t
smsc_ircc_interrupt(int dummy
, void *dev_id
)
1509 struct net_device
*dev
= dev_id
;
1510 struct smsc_ircc_cb
*self
= netdev_priv(dev
);
1511 int iobase
, iir
, lcra
, lsr
;
1512 irqreturn_t ret
= IRQ_NONE
;
1514 /* Serialise the interrupt handler in various CPUs, stop Tx path */
1515 spin_lock(&self
->lock
);
1517 /* Check if we should use the SIR interrupt handler */
1518 if (self
->io
.speed
<= SMSC_IRCC2_MAX_SIR_SPEED
) {
1519 ret
= smsc_ircc_interrupt_sir(dev
);
1520 goto irq_ret_unlock
;
1523 iobase
= self
->io
.fir_base
;
1525 register_bank(iobase
, 0);
1526 iir
= inb(iobase
+ IRCC_IIR
);
1528 goto irq_ret_unlock
;
1531 /* Disable interrupts */
1532 outb(0, iobase
+ IRCC_IER
);
1533 lcra
= inb(iobase
+ IRCC_LCR_A
);
1534 lsr
= inb(iobase
+ IRCC_LSR
);
1536 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __func__
, iir
);
1538 if (iir
& IRCC_IIR_EOM
) {
1539 if (self
->io
.direction
== IO_RECV
)
1540 smsc_ircc_dma_receive_complete(self
);
1542 smsc_ircc_dma_xmit_complete(self
);
1544 smsc_ircc_dma_receive(self
);
1547 if (iir
& IRCC_IIR_ACTIVE_FRAME
) {
1548 /*printk(KERN_WARNING "%s(): Active Frame\n", __func__);*/
1551 /* Enable interrupts again */
1553 register_bank(iobase
, 0);
1554 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, iobase
+ IRCC_IER
);
1557 spin_unlock(&self
->lock
);
1563 * Function irport_interrupt_sir (irq, dev_id)
1565 * Interrupt handler for SIR modes
1567 static irqreturn_t
smsc_ircc_interrupt_sir(struct net_device
*dev
)
1569 struct smsc_ircc_cb
*self
= netdev_priv(dev
);
1574 /* Already locked coming here in smsc_ircc_interrupt() */
1575 /*spin_lock(&self->lock);*/
1577 iobase
= self
->io
.sir_base
;
1579 iir
= inb(iobase
+ UART_IIR
) & UART_IIR_ID
;
1583 /* Clear interrupt */
1584 lsr
= inb(iobase
+ UART_LSR
);
1586 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
1587 __func__
, iir
, lsr
, iobase
);
1591 IRDA_DEBUG(2, "%s(), RLSI\n", __func__
);
1594 /* Receive interrupt */
1595 smsc_ircc_sir_receive(self
);
1598 if (lsr
& UART_LSR_THRE
)
1599 /* Transmitter ready for data */
1600 smsc_ircc_sir_write_wakeup(self
);
1603 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1608 /* Make sure we don't stay here to long */
1609 if (boguscount
++ > 100)
1612 iir
= inb(iobase
+ UART_IIR
) & UART_IIR_ID
;
1614 /*spin_unlock(&self->lock);*/
1621 * Function ircc_is_receiving (self)
1623 * Return TRUE is we are currently receiving a frame
1626 static int ircc_is_receiving(struct smsc_ircc_cb
*self
)
1631 IRDA_DEBUG(1, "%s\n", __func__
);
1633 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
1635 IRDA_DEBUG(0, "%s: dma count = %d\n", __func__
,
1636 get_dma_residue(self
->io
.dma
));
1638 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
1644 static int smsc_ircc_request_irq(struct smsc_ircc_cb
*self
)
1648 error
= request_irq(self
->io
.irq
, smsc_ircc_interrupt
, 0,
1649 self
->netdev
->name
, self
->netdev
);
1651 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
1652 __func__
, self
->io
.irq
, error
);
1657 static void smsc_ircc_start_interrupts(struct smsc_ircc_cb
*self
)
1659 unsigned long flags
;
1661 spin_lock_irqsave(&self
->lock
, flags
);
1664 smsc_ircc_change_speed(self
, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED
);
1666 spin_unlock_irqrestore(&self
->lock
, flags
);
1669 static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb
*self
)
1671 int iobase
= self
->io
.fir_base
;
1672 unsigned long flags
;
1674 spin_lock_irqsave(&self
->lock
, flags
);
1676 register_bank(iobase
, 0);
1677 outb(0, iobase
+ IRCC_IER
);
1678 outb(IRCC_MASTER_RESET
, iobase
+ IRCC_MASTER
);
1679 outb(0x00, iobase
+ IRCC_MASTER
);
1681 spin_unlock_irqrestore(&self
->lock
, flags
);
1686 * Function smsc_ircc_net_open (dev)
1691 static int smsc_ircc_net_open(struct net_device
*dev
)
1693 struct smsc_ircc_cb
*self
;
1696 IRDA_DEBUG(1, "%s\n", __func__
);
1698 IRDA_ASSERT(dev
!= NULL
, return -1;);
1699 self
= netdev_priv(dev
);
1700 IRDA_ASSERT(self
!= NULL
, return 0;);
1702 if (self
->io
.suspended
) {
1703 IRDA_DEBUG(0, "%s(), device is suspended\n", __func__
);
1707 if (request_irq(self
->io
.irq
, smsc_ircc_interrupt
, 0, dev
->name
,
1709 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1710 __func__
, self
->io
.irq
);
1714 smsc_ircc_start_interrupts(self
);
1716 /* Give self a hardware name */
1717 /* It would be cool to offer the chip revision here - Jean II */
1718 sprintf(hwname
, "SMSC @ 0x%03x", self
->io
.fir_base
);
1721 * Open new IrLAP layer instance, now that everything should be
1722 * initialized properly
1724 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1727 * Always allocate the DMA channel after the IRQ,
1728 * and clean up on failure.
1730 if (request_dma(self
->io
.dma
, dev
->name
)) {
1731 smsc_ircc_net_close(dev
);
1733 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1734 __func__
, self
->io
.dma
);
1738 netif_start_queue(dev
);
1744 * Function smsc_ircc_net_close (dev)
1749 static int smsc_ircc_net_close(struct net_device
*dev
)
1751 struct smsc_ircc_cb
*self
;
1753 IRDA_DEBUG(1, "%s\n", __func__
);
1755 IRDA_ASSERT(dev
!= NULL
, return -1;);
1756 self
= netdev_priv(dev
);
1757 IRDA_ASSERT(self
!= NULL
, return 0;);
1760 netif_stop_queue(dev
);
1762 /* Stop and remove instance of IrLAP */
1764 irlap_close(self
->irlap
);
1767 smsc_ircc_stop_interrupts(self
);
1769 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1770 if (!self
->io
.suspended
)
1771 free_irq(self
->io
.irq
, dev
);
1773 disable_dma(self
->io
.dma
);
1774 free_dma(self
->io
.dma
);
1779 static int smsc_ircc_suspend(struct platform_device
*dev
, pm_message_t state
)
1781 struct smsc_ircc_cb
*self
= platform_get_drvdata(dev
);
1783 if (!self
->io
.suspended
) {
1784 IRDA_DEBUG(1, "%s, Suspending\n", driver_name
);
1787 if (netif_running(self
->netdev
)) {
1788 netif_device_detach(self
->netdev
);
1789 smsc_ircc_stop_interrupts(self
);
1790 free_irq(self
->io
.irq
, self
->netdev
);
1791 disable_dma(self
->io
.dma
);
1793 self
->io
.suspended
= 1;
1800 static int smsc_ircc_resume(struct platform_device
*dev
)
1802 struct smsc_ircc_cb
*self
= platform_get_drvdata(dev
);
1804 if (self
->io
.suspended
) {
1805 IRDA_DEBUG(1, "%s, Waking up\n", driver_name
);
1808 smsc_ircc_init_chip(self
);
1809 if (netif_running(self
->netdev
)) {
1810 if (smsc_ircc_request_irq(self
)) {
1812 * Don't fail resume process, just kill this
1815 unregister_netdevice(self
->netdev
);
1817 enable_dma(self
->io
.dma
);
1818 smsc_ircc_start_interrupts(self
);
1819 netif_device_attach(self
->netdev
);
1822 self
->io
.suspended
= 0;
1829 * Function smsc_ircc_close (self)
1831 * Close driver instance
1834 static int __exit
smsc_ircc_close(struct smsc_ircc_cb
*self
)
1836 IRDA_DEBUG(1, "%s\n", __func__
);
1838 IRDA_ASSERT(self
!= NULL
, return -1;);
1840 platform_device_unregister(self
->pldev
);
1842 /* Remove netdevice */
1843 unregister_netdev(self
->netdev
);
1845 smsc_ircc_stop_interrupts(self
);
1847 /* Release the PORTS that this driver is using */
1848 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__
,
1851 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
1853 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__
,
1856 release_region(self
->io
.sir_base
, self
->io
.sir_ext
);
1858 if (self
->tx_buff
.head
)
1859 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
1860 self
->tx_buff
.head
, self
->tx_buff_dma
);
1862 if (self
->rx_buff
.head
)
1863 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
1864 self
->rx_buff
.head
, self
->rx_buff_dma
);
1866 free_netdev(self
->netdev
);
1871 static void __exit
smsc_ircc_cleanup(void)
1875 IRDA_DEBUG(1, "%s\n", __func__
);
1877 for (i
= 0; i
< 2; i
++) {
1879 smsc_ircc_close(dev_self
[i
]);
1882 if (pnp_driver_registered
)
1883 pnp_unregister_driver(&smsc_ircc_pnp_driver
);
1885 platform_driver_unregister(&smsc_ircc_driver
);
1889 * Start SIR operations
1891 * This function *must* be called with spinlock held, because it may
1892 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1894 static void smsc_ircc_sir_start(struct smsc_ircc_cb
*self
)
1896 struct net_device
*dev
;
1897 int fir_base
, sir_base
;
1899 IRDA_DEBUG(3, "%s\n", __func__
);
1901 IRDA_ASSERT(self
!= NULL
, return;);
1903 IRDA_ASSERT(dev
!= NULL
, return;);
1905 fir_base
= self
->io
.fir_base
;
1906 sir_base
= self
->io
.sir_base
;
1908 /* Reset everything */
1909 outb(IRCC_MASTER_RESET
, fir_base
+ IRCC_MASTER
);
1911 #if SMSC_IRCC2_C_SIR_STOP
1912 /*smsc_ircc_sir_stop(self);*/
1915 register_bank(fir_base
, 1);
1916 outb(((inb(fir_base
+ IRCC_SCE_CFGA
) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK
) | IRCC_CFGA_IRDA_SIR_A
), fir_base
+ IRCC_SCE_CFGA
);
1918 /* Initialize UART */
1919 outb(UART_LCR_WLEN8
, sir_base
+ UART_LCR
); /* Reset DLAB */
1920 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), sir_base
+ UART_MCR
);
1922 /* Turn on interrups */
1923 outb(UART_IER_RLSI
| UART_IER_RDI
|UART_IER_THRI
, sir_base
+ UART_IER
);
1925 IRDA_DEBUG(3, "%s() - exit\n", __func__
);
1927 outb(0x00, fir_base
+ IRCC_MASTER
);
1930 #if SMSC_IRCC2_C_SIR_STOP
1931 void smsc_ircc_sir_stop(struct smsc_ircc_cb
*self
)
1935 IRDA_DEBUG(3, "%s\n", __func__
);
1936 iobase
= self
->io
.sir_base
;
1939 outb(0, iobase
+ UART_MCR
);
1941 /* Turn off interrupts */
1942 outb(0, iobase
+ UART_IER
);
1947 * Function smsc_sir_write_wakeup (self)
1949 * Called by the SIR interrupt handler when there's room for more data.
1950 * If we have more packets to send, we send them here.
1953 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb
*self
)
1959 IRDA_ASSERT(self
!= NULL
, return;);
1961 IRDA_DEBUG(4, "%s\n", __func__
);
1963 iobase
= self
->io
.sir_base
;
1965 /* Finished with frame? */
1966 if (self
->tx_buff
.len
> 0) {
1967 /* Write data left in transmit buffer */
1968 actual
= smsc_ircc_sir_write(iobase
, self
->io
.fifo_size
,
1969 self
->tx_buff
.data
, self
->tx_buff
.len
);
1970 self
->tx_buff
.data
+= actual
;
1971 self
->tx_buff
.len
-= actual
;
1974 /*if (self->tx_buff.len ==0) {*/
1977 * Now serial buffer is almost free & we can start
1978 * transmission of another packet. But first we must check
1979 * if we need to change the speed of the hardware
1981 if (self
->new_speed
) {
1982 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1983 __func__
, self
->new_speed
);
1984 smsc_ircc_sir_wait_hw_transmitter_finish(self
);
1985 smsc_ircc_change_speed(self
, self
->new_speed
);
1986 self
->new_speed
= 0;
1988 /* Tell network layer that we want more frames */
1989 netif_wake_queue(self
->netdev
);
1991 self
->netdev
->stats
.tx_packets
++;
1993 if (self
->io
.speed
<= 115200) {
1995 * Reset Rx FIFO to make sure that all reflected transmit data
1996 * is discarded. This is needed for half duplex operation
1998 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
;
1999 fcr
|= self
->io
.speed
< 38400 ?
2000 UART_FCR_TRIGGER_1
: UART_FCR_TRIGGER_14
;
2002 outb(fcr
, iobase
+ UART_FCR
);
2004 /* Turn on receive interrupts */
2005 outb(UART_IER_RDI
, iobase
+ UART_IER
);
2011 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
2013 * Fill Tx FIFO with transmit data
2016 static int smsc_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
2020 /* Tx FIFO should be empty! */
2021 if (!(inb(iobase
+ UART_LSR
) & UART_LSR_THRE
)) {
2022 IRDA_WARNING("%s(), failed, fifo not empty!\n", __func__
);
2026 /* Fill FIFO with current frame */
2027 while (fifo_size
-- > 0 && actual
< len
) {
2028 /* Transmit next byte */
2029 outb(buf
[actual
], iobase
+ UART_TX
);
2036 * Function smsc_ircc_is_receiving (self)
2038 * Returns true is we are currently receiving data
2041 static int smsc_ircc_is_receiving(struct smsc_ircc_cb
*self
)
2043 return self
->rx_buff
.state
!= OUTSIDE_FRAME
;
2048 * Function smsc_ircc_probe_transceiver(self)
2050 * Tries to find the used Transceiver
2053 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb
*self
)
2057 IRDA_ASSERT(self
!= NULL
, return;);
2059 for (i
= 0; smsc_transceivers
[i
].name
!= NULL
; i
++)
2060 if (smsc_transceivers
[i
].probe(self
->io
.fir_base
)) {
2061 IRDA_MESSAGE(" %s transceiver found\n",
2062 smsc_transceivers
[i
].name
);
2063 self
->transceiver
= i
+ 1;
2067 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2068 smsc_transceivers
[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER
].name
);
2070 self
->transceiver
= SMSC_IRCC2_C_DEFAULT_TRANSCEIVER
;
2075 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2077 * Set the transceiver according to the speed
2080 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb
*self
, u32 speed
)
2084 trx
= self
->transceiver
;
2086 smsc_transceivers
[trx
- 1].set_for_speed(self
->io
.fir_base
, speed
);
2090 * Function smsc_ircc_wait_hw_transmitter_finish ()
2092 * Wait for the real end of HW transmission
2094 * The UART is a strict FIFO, and we get called only when we have finished
2095 * pushing data to the FIFO, so the maximum amount of time we must wait
2096 * is only for the FIFO to drain out.
2098 * We use a simple calibrated loop. We may need to adjust the loop
2099 * delay (udelay) to balance I/O traffic and latency. And we also need to
2100 * adjust the maximum timeout.
2101 * It would probably be better to wait for the proper interrupt,
2102 * but it doesn't seem to be available.
2104 * We can't use jiffies or kernel timers because :
2105 * 1) We are called from the interrupt handler, which disable softirqs,
2106 * so jiffies won't be increased
2107 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2108 * want to wait that long to detect stuck hardware.
2112 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb
*self
)
2114 int iobase
= self
->io
.sir_base
;
2115 int count
= SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US
;
2117 /* Calibrated busy loop */
2118 while (count
-- > 0 && !(inb(iobase
+ UART_LSR
) & UART_LSR_TEMT
))
2122 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __func__
);
2128 * REVISIT we can be told about the device by PNP, and should use that info
2129 * instead of probing hardware and creating a platform_device ...
2132 static int __init
smsc_ircc_look_for_chips(void)
2134 struct smsc_chip_address
*address
;
2136 unsigned int cfg_base
, found
;
2139 address
= possible_addresses
;
2141 while (address
->cfg_base
) {
2142 cfg_base
= address
->cfg_base
;
2144 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __func__, cfg_base, address->type);*/
2146 if (address
->type
& SMSCSIO_TYPE_FDC
) {
2148 if (address
->type
& SMSCSIO_TYPE_FLAT
)
2149 if (!smsc_superio_flat(fdc_chips_flat
, cfg_base
, type
))
2152 if (address
->type
& SMSCSIO_TYPE_PAGED
)
2153 if (!smsc_superio_paged(fdc_chips_paged
, cfg_base
, type
))
2156 if (address
->type
& SMSCSIO_TYPE_LPC
) {
2158 if (address
->type
& SMSCSIO_TYPE_FLAT
)
2159 if (!smsc_superio_flat(lpc_chips_flat
, cfg_base
, type
))
2162 if (address
->type
& SMSCSIO_TYPE_PAGED
)
2163 if (!smsc_superio_paged(lpc_chips_paged
, cfg_base
, type
))
2172 * Function smsc_superio_flat (chip, base, type)
2174 * Try to get configuration of a smc SuperIO chip with flat register model
2177 static int __init
smsc_superio_flat(const struct smsc_chip
*chips
, unsigned short cfgbase
, char *type
)
2179 unsigned short firbase
, sirbase
;
2183 IRDA_DEBUG(1, "%s\n", __func__
);
2185 if (smsc_ircc_probe(cfgbase
, SMSCSIOFLAT_DEVICEID_REG
, chips
, type
) == NULL
)
2188 outb(SMSCSIOFLAT_UARTMODE0C_REG
, cfgbase
);
2189 mode
= inb(cfgbase
+ 1);
2191 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __func__, mode);*/
2193 if (!(mode
& SMSCSIOFLAT_UART2MODE_VAL_IRDA
))
2194 IRDA_WARNING("%s(): IrDA not enabled\n", __func__
);
2196 outb(SMSCSIOFLAT_UART2BASEADDR_REG
, cfgbase
);
2197 sirbase
= inb(cfgbase
+ 1) << 2;
2200 outb(SMSCSIOFLAT_FIRBASEADDR_REG
, cfgbase
);
2201 firbase
= inb(cfgbase
+ 1) << 3;
2204 outb(SMSCSIOFLAT_FIRDMASELECT_REG
, cfgbase
);
2205 dma
= inb(cfgbase
+ 1) & SMSCSIOFLAT_FIRDMASELECT_MASK
;
2208 outb(SMSCSIOFLAT_UARTIRQSELECT_REG
, cfgbase
);
2209 irq
= inb(cfgbase
+ 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK
;
2211 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __func__
, firbase
, sirbase
, dma
, irq
, mode
);
2213 if (firbase
&& smsc_ircc_open(firbase
, sirbase
, dma
, irq
) == 0)
2216 /* Exit configuration */
2217 outb(SMSCSIO_CFGEXITKEY
, cfgbase
);
2223 * Function smsc_superio_paged (chip, base, type)
2225 * Try to get configuration of a smc SuperIO chip with paged register model
2228 static int __init
smsc_superio_paged(const struct smsc_chip
*chips
, unsigned short cfg_base
, char *type
)
2230 unsigned short fir_io
, sir_io
;
2233 IRDA_DEBUG(1, "%s\n", __func__
);
2235 if (smsc_ircc_probe(cfg_base
, 0x20, chips
, type
) == NULL
)
2238 /* Select logical device (UART2) */
2239 outb(0x07, cfg_base
);
2240 outb(0x05, cfg_base
+ 1);
2243 outb(0x60, cfg_base
);
2244 sir_io
= inb(cfg_base
+ 1) << 8;
2245 outb(0x61, cfg_base
);
2246 sir_io
|= inb(cfg_base
+ 1);
2249 outb(0x62, cfg_base
);
2250 fir_io
= inb(cfg_base
+ 1) << 8;
2251 outb(0x63, cfg_base
);
2252 fir_io
|= inb(cfg_base
+ 1);
2253 outb(0x2b, cfg_base
); /* ??? */
2255 if (fir_io
&& smsc_ircc_open(fir_io
, sir_io
, ircc_dma
, ircc_irq
) == 0)
2258 /* Exit configuration */
2259 outb(SMSCSIO_CFGEXITKEY
, cfg_base
);
2265 static int __init
smsc_access(unsigned short cfg_base
, unsigned char reg
)
2267 IRDA_DEBUG(1, "%s\n", __func__
);
2269 outb(reg
, cfg_base
);
2270 return inb(cfg_base
) != reg
? -1 : 0;
2273 static const struct smsc_chip
* __init
smsc_ircc_probe(unsigned short cfg_base
, u8 reg
, const struct smsc_chip
*chip
, char *type
)
2275 u8 devid
, xdevid
, rev
;
2277 IRDA_DEBUG(1, "%s\n", __func__
);
2279 /* Leave configuration */
2281 outb(SMSCSIO_CFGEXITKEY
, cfg_base
);
2283 if (inb(cfg_base
) == SMSCSIO_CFGEXITKEY
) /* not a smc superio chip */
2286 outb(reg
, cfg_base
);
2288 xdevid
= inb(cfg_base
+ 1);
2290 /* Enter configuration */
2292 outb(SMSCSIO_CFGACCESSKEY
, cfg_base
);
2295 if (smsc_access(cfg_base
,0x55)) /* send second key and check */
2299 /* probe device ID */
2301 if (smsc_access(cfg_base
, reg
))
2304 devid
= inb(cfg_base
+ 1);
2306 if (devid
== 0 || devid
== 0xff) /* typical values for unused port */
2309 /* probe revision ID */
2311 if (smsc_access(cfg_base
, reg
+ 1))
2314 rev
= inb(cfg_base
+ 1);
2316 if (rev
>= 128) /* i think this will make no sense */
2319 if (devid
== xdevid
) /* protection against false positives */
2322 /* Check for expected device ID; are there others? */
2324 while (chip
->devid
!= devid
) {
2328 if (chip
->name
== NULL
)
2332 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2333 devid
, rev
, cfg_base
, type
, chip
->name
);
2335 if (chip
->rev
> rev
) {
2336 IRDA_MESSAGE("Revision higher than expected\n");
2340 if (chip
->flags
& NoIRDA
)
2341 IRDA_MESSAGE("chipset does not support IRDA\n");
2346 static int __init
smsc_superio_fdc(unsigned short cfg_base
)
2350 if (!request_region(cfg_base
, 2, driver_name
)) {
2351 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2352 __func__
, cfg_base
);
2354 if (!smsc_superio_flat(fdc_chips_flat
, cfg_base
, "FDC") ||
2355 !smsc_superio_paged(fdc_chips_paged
, cfg_base
, "FDC"))
2358 release_region(cfg_base
, 2);
2364 static int __init
smsc_superio_lpc(unsigned short cfg_base
)
2368 if (!request_region(cfg_base
, 2, driver_name
)) {
2369 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2370 __func__
, cfg_base
);
2372 if (!smsc_superio_flat(lpc_chips_flat
, cfg_base
, "LPC") ||
2373 !smsc_superio_paged(lpc_chips_paged
, cfg_base
, "LPC"))
2376 release_region(cfg_base
, 2);
2382 * Look for some specific subsystem setups that need
2383 * pre-configuration not properly done by the BIOS (especially laptops)
2384 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2385 * and tosh2450-smcinit.c. The table lists the device entries
2386 * for ISA bridges with an LPC (Low Pin Count) controller which
2387 * handles the communication with the SMSC device. After the LPC
2388 * controller is initialized through PCI, the SMSC device is initialized
2389 * through a dedicated port in the ISA port-mapped I/O area, this latter
2390 * area is used to configure the SMSC device with default
2391 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2392 * used different sets of parameters and different control port
2393 * addresses making a subsystem device table necessary.
2396 static struct smsc_ircc_subsystem_configuration subsystem_configurations
[] __initdata
= {
2398 * Subsystems needing entries:
2399 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2400 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2401 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2405 .vendor
= PCI_VENDOR_ID_INTEL
, /* Intel 82801DBM LPC bridge */
2407 .subvendor
= 0x103c,
2408 .subdevice
= 0x08bc,
2414 .preconfigure
= preconfigure_through_82801
,
2415 .name
= "HP nx5000 family",
2418 .vendor
= PCI_VENDOR_ID_INTEL
, /* Intel 82801DBM LPC bridge */
2420 .subvendor
= 0x103c,
2421 .subdevice
= 0x088c,
2422 /* Quite certain these are the same for nc8000 as for nc6000 */
2428 .preconfigure
= preconfigure_through_82801
,
2429 .name
= "HP nc8000 family",
2432 .vendor
= PCI_VENDOR_ID_INTEL
, /* Intel 82801DBM LPC bridge */
2434 .subvendor
= 0x103c,
2435 .subdevice
= 0x0890,
2441 .preconfigure
= preconfigure_through_82801
,
2442 .name
= "HP nc6000 family",
2445 .vendor
= PCI_VENDOR_ID_INTEL
, /* Intel 82801DBM LPC bridge */
2447 .subvendor
= 0x0e11,
2448 .subdevice
= 0x0860,
2449 /* I assume these are the same for x1000 as for the others */
2455 .preconfigure
= preconfigure_through_82801
,
2456 .name
= "Compaq x1000 family",
2459 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
2460 .vendor
= PCI_VENDOR_ID_INTEL
,
2462 .subvendor
= 0x1179,
2463 .subdevice
= 0xffff, /* 0xffff is "any" */
2469 .preconfigure
= preconfigure_through_82801
,
2470 .name
= "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
2473 .vendor
= PCI_VENDOR_ID_INTEL
, /* Intel 82801CAM ISA bridge */
2475 .subvendor
= 0x1179,
2476 .subdevice
= 0xffff, /* 0xffff is "any" */
2482 .preconfigure
= preconfigure_through_82801
,
2483 .name
= "Toshiba laptop with Intel 82801CAM ISA bridge",
2486 /* 82801DBM (ICH4-M) LPC Interface Bridge */
2487 .vendor
= PCI_VENDOR_ID_INTEL
,
2489 .subvendor
= 0x1179,
2490 .subdevice
= 0xffff, /* 0xffff is "any" */
2496 .preconfigure
= preconfigure_through_82801
,
2497 .name
= "Toshiba laptop with Intel 8281DBM LPC bridge",
2500 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
2501 .vendor
= PCI_VENDOR_ID_AL
,
2503 .subvendor
= 0x1179,
2504 .subdevice
= 0xffff, /* 0xffff is "any" */
2510 .preconfigure
= preconfigure_through_ali
,
2511 .name
= "Toshiba laptop with ALi ISA bridge",
2518 * This sets up the basic SMSC parameters
2519 * (FIR port, SIR port, FIR DMA, FIR IRQ)
2520 * through the chip configuration port.
2522 static int __init
preconfigure_smsc_chip(struct
2523 smsc_ircc_subsystem_configuration
2526 unsigned short iobase
= conf
->cfg_base
;
2527 unsigned char tmpbyte
;
2529 outb(LPC47N227_CFGACCESSKEY
, iobase
); // enter configuration state
2530 outb(SMSCSIOFLAT_DEVICEID_REG
, iobase
); // set for device ID
2531 tmpbyte
= inb(iobase
+1); // Read device ID
2533 "Detected Chip id: 0x%02x, setting up registers...\n",
2536 /* Disable UART1 and set up SIR I/O port */
2537 outb(0x24, iobase
); // select CR24 - UART1 base addr
2538 outb(0x00, iobase
+ 1); // disable UART1
2539 outb(SMSCSIOFLAT_UART2BASEADDR_REG
, iobase
); // select CR25 - UART2 base addr
2540 outb( (conf
->sir_io
>> 2), iobase
+ 1); // bits 2-9 of 0x3f8
2541 tmpbyte
= inb(iobase
+ 1);
2542 if (tmpbyte
!= (conf
->sir_io
>> 2) ) {
2543 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
2544 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
2548 /* Set up FIR IRQ channel for UART2 */
2549 outb(SMSCSIOFLAT_UARTIRQSELECT_REG
, iobase
); // select CR28 - UART1,2 IRQ select
2550 tmpbyte
= inb(iobase
+ 1);
2551 tmpbyte
&= SMSCSIOFLAT_UART1IRQSELECT_MASK
; // Do not touch the UART1 portion
2552 tmpbyte
|= (conf
->fir_irq
& SMSCSIOFLAT_UART2IRQSELECT_MASK
);
2553 outb(tmpbyte
, iobase
+ 1);
2554 tmpbyte
= inb(iobase
+ 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK
;
2555 if (tmpbyte
!= conf
->fir_irq
) {
2556 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2560 /* Set up FIR I/O port */
2561 outb(SMSCSIOFLAT_FIRBASEADDR_REG
, iobase
); // CR2B - SCE (FIR) base addr
2562 outb((conf
->fir_io
>> 3), iobase
+ 1);
2563 tmpbyte
= inb(iobase
+ 1);
2564 if (tmpbyte
!= (conf
->fir_io
>> 3) ) {
2565 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2569 /* Set up FIR DMA channel */
2570 outb(SMSCSIOFLAT_FIRDMASELECT_REG
, iobase
); // CR2C - SCE (FIR) DMA select
2571 outb((conf
->fir_dma
& LPC47N227_FIRDMASELECT_MASK
), iobase
+ 1); // DMA
2572 tmpbyte
= inb(iobase
+ 1) & LPC47N227_FIRDMASELECT_MASK
;
2573 if (tmpbyte
!= (conf
->fir_dma
& LPC47N227_FIRDMASELECT_MASK
)) {
2574 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2578 outb(SMSCSIOFLAT_UARTMODE0C_REG
, iobase
); // CR0C - UART mode
2579 tmpbyte
= inb(iobase
+ 1);
2580 tmpbyte
&= ~SMSCSIOFLAT_UART2MODE_MASK
|
2581 SMSCSIOFLAT_UART2MODE_VAL_IRDA
;
2582 outb(tmpbyte
, iobase
+ 1); // enable IrDA (HPSIR) mode, high speed
2584 outb(LPC47N227_APMBOOTDRIVE_REG
, iobase
); // CR07 - Auto Pwr Mgt/boot drive sel
2585 tmpbyte
= inb(iobase
+ 1);
2586 outb(tmpbyte
| LPC47N227_UART2AUTOPWRDOWN_MASK
, iobase
+ 1); // enable UART2 autopower down
2588 /* This one was not part of tosh1800 */
2589 outb(0x0a, iobase
); // CR0a - ecp fifo / ir mux
2590 tmpbyte
= inb(iobase
+ 1);
2591 outb(tmpbyte
| 0x40, iobase
+ 1); // send active device to ir port
2593 outb(LPC47N227_UART12POWER_REG
, iobase
); // CR02 - UART 1,2 power
2594 tmpbyte
= inb(iobase
+ 1);
2595 outb(tmpbyte
| LPC47N227_UART2POWERDOWN_MASK
, iobase
+ 1); // UART2 power up mode, UART1 power down
2597 outb(LPC47N227_FDCPOWERVALIDCONF_REG
, iobase
); // CR00 - FDC Power/valid config cycle
2598 tmpbyte
= inb(iobase
+ 1);
2599 outb(tmpbyte
| LPC47N227_VALID_MASK
, iobase
+ 1); // valid config cycle done
2601 outb(LPC47N227_CFGEXITKEY
, iobase
); // Exit configuration
2606 /* 82801CAM generic registers */
2609 #define PIRQ_A_D_ROUT 0x60
2610 #define SIRQ_CNTL 0x64
2611 #define PIRQ_E_H_ROUT 0x68
2612 #define PCI_DMA_C 0x90
2613 /* LPC-specific registers */
2614 #define COM_DEC 0xe0
2615 #define GEN1_DEC 0xe4
2617 #define GEN2_DEC 0xec
2619 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2620 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2621 * They all work the same way!
2623 static int __init
preconfigure_through_82801(struct pci_dev
*dev
,
2625 smsc_ircc_subsystem_configuration
2628 unsigned short tmpword
;
2629 unsigned char tmpbyte
;
2631 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2633 * Select the range for the COMA COM port (SIR)
2636 * Bit 6-4, COMB decode range
2638 * Bit 2-0, COMA decode range
2641 * 000 = 0x3f8-0x3ff (COM1)
2642 * 001 = 0x2f8-0x2ff (COM2)
2646 * 101 = 0x2e8-0x2ef (COM4)
2648 * 111 = 0x3e8-0x3ef (COM3)
2650 pci_read_config_byte(dev
, COM_DEC
, &tmpbyte
);
2651 tmpbyte
&= 0xf8; /* mask COMA bits */
2652 switch(conf
->sir_io
) {
2678 tmpbyte
|= 0x01; /* COM2 default */
2680 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte
);
2681 pci_write_config_byte(dev
, COM_DEC
, tmpbyte
);
2683 /* Enable Low Pin Count interface */
2684 pci_read_config_word(dev
, LPC_EN
, &tmpword
);
2685 /* These seem to be set up at all times,
2686 * just make sure it is properly set.
2688 switch(conf
->cfg_base
) {
2702 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2706 tmpword
&= 0xfffd; /* disable LPC COMB */
2707 tmpword
|= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2708 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword
);
2709 pci_write_config_word(dev
, LPC_EN
, tmpword
);
2712 * Configure LPC DMA channel
2714 * Bit 15-14: DMA channel 7 select
2715 * Bit 13-12: DMA channel 6 select
2716 * Bit 11-10: DMA channel 5 select
2718 * Bit 7-6: DMA channel 3 select
2719 * Bit 5-4: DMA channel 2 select
2720 * Bit 3-2: DMA channel 1 select
2721 * Bit 1-0: DMA channel 0 select
2722 * 00 = Reserved value
2724 * 10 = Reserved value
2727 pci_read_config_word(dev
, PCI_DMA_C
, &tmpword
);
2728 switch(conf
->fir_dma
) {
2751 break; /* do not change settings */
2753 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword
);
2754 pci_write_config_word(dev
, PCI_DMA_C
, tmpword
);
2758 * Bit 15-4: Generic I/O range
2759 * Bit 3-1: reserved (read as 0)
2760 * Bit 0: enable GEN2 range on LPC I/F
2762 tmpword
= conf
->fir_io
& 0xfff8;
2764 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword
);
2765 pci_write_config_word(dev
, GEN2_DEC
, tmpword
);
2767 /* Pre-configure chip */
2768 return preconfigure_smsc_chip(conf
);
2772 * Pre-configure a certain port on the ALi 1533 bridge.
2773 * This is based on reverse-engineering since ALi does not
2774 * provide any data sheet for the 1533 chip.
2776 static void __init
preconfigure_ali_port(struct pci_dev
*dev
,
2777 unsigned short port
)
2780 /* These bits obviously control the different ports */
2782 unsigned char tmpbyte
;
2803 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port
);
2807 pci_read_config_byte(dev
, reg
, &tmpbyte
);
2808 /* Turn on the right bits */
2810 pci_write_config_byte(dev
, reg
, tmpbyte
);
2811 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port
);
2814 static int __init
preconfigure_through_ali(struct pci_dev
*dev
,
2816 smsc_ircc_subsystem_configuration
2819 /* Configure the two ports on the ALi 1533 */
2820 preconfigure_ali_port(dev
, conf
->sir_io
);
2821 preconfigure_ali_port(dev
, conf
->fir_io
);
2823 /* Pre-configure chip */
2824 return preconfigure_smsc_chip(conf
);
2827 static int __init
smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg
,
2828 unsigned short ircc_fir
,
2829 unsigned short ircc_sir
,
2830 unsigned char ircc_dma
,
2831 unsigned char ircc_irq
)
2833 struct pci_dev
*dev
= NULL
;
2834 unsigned short ss_vendor
= 0x0000;
2835 unsigned short ss_device
= 0x0000;
2838 for_each_pci_dev(dev
) {
2839 struct smsc_ircc_subsystem_configuration
*conf
;
2842 * Cache the subsystem vendor/device:
2843 * some manufacturers fail to set this for all components,
2844 * so we save it in case there is just 0x0000 0x0000 on the
2845 * device we want to check.
2847 if (dev
->subsystem_vendor
!= 0x0000U
) {
2848 ss_vendor
= dev
->subsystem_vendor
;
2849 ss_device
= dev
->subsystem_device
;
2851 conf
= subsystem_configurations
;
2852 for( ; conf
->subvendor
; conf
++) {
2853 if(conf
->vendor
== dev
->vendor
&&
2854 conf
->device
== dev
->device
&&
2855 conf
->subvendor
== ss_vendor
&&
2856 /* Sometimes these are cached values */
2857 (conf
->subdevice
== ss_device
||
2858 conf
->subdevice
== 0xffff)) {
2859 struct smsc_ircc_subsystem_configuration
2862 memcpy(&tmpconf
, conf
,
2863 sizeof(struct smsc_ircc_subsystem_configuration
));
2866 * Override the default values with anything
2867 * passed in as parameter
2870 tmpconf
.cfg_base
= ircc_cfg
;
2872 tmpconf
.fir_io
= ircc_fir
;
2874 tmpconf
.sir_io
= ircc_sir
;
2875 if (ircc_dma
!= DMA_INVAL
)
2876 tmpconf
.fir_dma
= ircc_dma
;
2877 if (ircc_irq
!= IRQ_INVAL
)
2878 tmpconf
.fir_irq
= ircc_irq
;
2880 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf
->name
);
2881 if (conf
->preconfigure
)
2882 ret
= conf
->preconfigure(dev
, &tmpconf
);
2891 #endif // CONFIG_PCI
2893 /************************************************
2895 * Transceivers specific functions
2897 ************************************************/
2901 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2903 * Program transceiver through smsc-ircc ATC circuitry
2907 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base
, u32 speed
)
2909 unsigned long jiffies_now
, jiffies_timeout
;
2912 jiffies_now
= jiffies
;
2913 jiffies_timeout
= jiffies
+ SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES
;
2916 register_bank(fir_base
, 4);
2917 outb((inb(fir_base
+ IRCC_ATC
) & IRCC_ATC_MASK
) | IRCC_ATC_nPROGREADY
|IRCC_ATC_ENABLE
,
2918 fir_base
+ IRCC_ATC
);
2920 while ((val
= (inb(fir_base
+ IRCC_ATC
) & IRCC_ATC_nPROGREADY
)) &&
2921 !time_after(jiffies
, jiffies_timeout
))
2925 IRDA_WARNING("%s(): ATC: 0x%02x\n", __func__
,
2926 inb(fir_base
+ IRCC_ATC
));
2930 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2932 * Probe transceiver smsc-ircc ATC circuitry
2936 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base
)
2942 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2948 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base
, u32 speed
)
2959 fast_mode
= IRCC_LCR_A_FAST
;
2962 register_bank(fir_base
, 0);
2963 outb((inb(fir_base
+ IRCC_LCR_A
) & 0xbf) | fast_mode
, fir_base
+ IRCC_LCR_A
);
2967 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2973 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base
)
2979 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2985 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base
, u32 speed
)
2996 fast_mode
= /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA
;
3000 /* This causes an interrupt */
3001 register_bank(fir_base
, 0);
3002 outb((inb(fir_base
+ IRCC_LCR_A
) & 0xbf) | fast_mode
, fir_base
+ IRCC_LCR_A
);
3006 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
3012 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base
)
3018 module_init(smsc_ircc_init
);
3019 module_exit(smsc_ircc_cleanup
);