1 /*********************************************************************
2 * $Id: smsc-ircc2.c,v 1.19.2.5 2002/10/27 11:34:26 dip Exp $
4 * Description: Driver for the SMC Infrared Communications Controller
5 * Status: Experimental.
6 * Author: Daniele Peri (peri@csai.unipa.it)
11 * Copyright (c) 2002 Daniele Peri
12 * All Rights Reserved.
13 * Copyright (c) 2002 Jean Tourrilhes
16 * Based on smc-ircc.c:
18 * Copyright (c) 2001 Stefani Seibold
19 * Copyright (c) 1999-2001 Dag Brattli
20 * Copyright (c) 1998-1999 Thomas Davis,
24 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
27 * This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License as
29 * published by the Free Software Foundation; either version 2 of
30 * the License, or (at your option) any later version.
32 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
37 * You should have received a copy of the GNU General Public License
38 * along with this program; if not, write to the Free Software
39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
42 ********************************************************************/
44 #include <linux/module.h>
45 #include <linux/kernel.h>
46 #include <linux/types.h>
47 #include <linux/skbuff.h>
48 #include <linux/netdevice.h>
49 #include <linux/ioport.h>
50 #include <linux/delay.h>
51 #include <linux/slab.h>
52 #include <linux/init.h>
53 #include <linux/rtnetlink.h>
54 #include <linux/serial_reg.h>
55 #include <linux/dma-mapping.h>
59 #include <asm/byteorder.h>
61 #include <linux/spinlock.h>
64 #include <net/irda/wrapper.h>
65 #include <net/irda/irda.h>
66 #include <net/irda/irda_device.h>
68 #include "smsc-ircc2.h"
73 struct smsc_transceiver
{
75 void (*set_for_speed
)(int fir_base
, u32 speed
);
76 int (*probe
)(int fir_base
);
78 typedef struct smsc_transceiver smsc_transceiver_t
;
87 typedef struct smc_chip smc_chip_t
;
99 typedef struct smsc_chip smsc_chip_t
;
101 struct smsc_chip_address
{
102 unsigned int cfg_base
;
105 typedef struct smsc_chip_address smsc_chip_address_t
;
107 /* Private data for each instance */
108 struct smsc_ircc_cb
{
109 struct net_device
*netdev
; /* Yes! we are some kind of netdevice */
110 struct net_device_stats stats
;
111 struct irlap_cb
*irlap
; /* The link layer we are binded to */
113 chipio_t io
; /* IrDA controller information */
114 iobuff_t tx_buff
; /* Transmit buffer */
115 iobuff_t rx_buff
; /* Receive buffer */
116 dma_addr_t tx_buff_dma
;
117 dma_addr_t rx_buff_dma
;
119 struct qos_info qos
; /* QoS capabilities for this device */
121 spinlock_t lock
; /* For serializing operations */
124 __u32 flags
; /* Interface flags */
126 int tx_buff_offsets
[10]; /* Offsets between frames in tx_buff */
127 int tx_len
; /* Number of frames in tx_buff */
130 struct pm_dev
*pmdev
;
135 static const char *driver_name
= "smsc-ircc2";
136 #define DIM(x) (sizeof(x)/(sizeof(*(x))))
137 #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
138 #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
139 #define SMSC_IRCC2_C_NET_TIMEOUT 0
140 #define SMSC_IRCC2_C_SIR_STOP 0
144 static int smsc_ircc_open(unsigned int firbase
, unsigned int sirbase
, u8 dma
, u8 irq
);
145 static int smsc_ircc_present(unsigned int fir_base
, unsigned int sir_base
);
146 static void smsc_ircc_setup_io(struct smsc_ircc_cb
*self
, unsigned int fir_base
, unsigned int sir_base
, u8 dma
, u8 irq
);
147 static void smsc_ircc_setup_qos(struct smsc_ircc_cb
*self
);
148 static void smsc_ircc_init_chip(struct smsc_ircc_cb
*self
);
149 static int __exit
smsc_ircc_close(struct smsc_ircc_cb
*self
);
150 static int smsc_ircc_dma_receive(struct smsc_ircc_cb
*self
, int iobase
);
151 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb
*self
, int iobase
);
152 static void smsc_ircc_sir_receive(struct smsc_ircc_cb
*self
);
153 static int smsc_ircc_hard_xmit_sir(struct sk_buff
*skb
, struct net_device
*dev
);
154 static int smsc_ircc_hard_xmit_fir(struct sk_buff
*skb
, struct net_device
*dev
);
155 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb
*self
, int iobase
, int bofs
);
156 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb
*self
, int iobase
);
157 static void smsc_ircc_change_speed(void *priv
, u32 speed
);
158 static void smsc_ircc_set_sir_speed(void *priv
, u32 speed
);
159 static irqreturn_t
smsc_ircc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
160 static irqreturn_t
smsc_ircc_interrupt_sir(struct net_device
*dev
);
161 static void smsc_ircc_sir_start(struct smsc_ircc_cb
*self
);
162 #if SMSC_IRCC2_C_SIR_STOP
163 static void smsc_ircc_sir_stop(struct smsc_ircc_cb
*self
);
165 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb
*self
);
166 static int smsc_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
);
167 static int smsc_ircc_net_open(struct net_device
*dev
);
168 static int smsc_ircc_net_close(struct net_device
*dev
);
169 static int smsc_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
170 #if SMSC_IRCC2_C_NET_TIMEOUT
171 static void smsc_ircc_timeout(struct net_device
*dev
);
173 static struct net_device_stats
*smsc_ircc_net_get_stats(struct net_device
*dev
);
174 static int smsc_ircc_pmproc(struct pm_dev
*dev
, pm_request_t rqst
, void *data
);
175 static int smsc_ircc_is_receiving(struct smsc_ircc_cb
*self
);
176 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb
*self
);
177 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb
*self
, u32 speed
);
178 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb
*self
);
181 static int __init
smsc_ircc_look_for_chips(void);
182 static const smsc_chip_t
* __init
smsc_ircc_probe(unsigned short cfg_base
,u8 reg
,const smsc_chip_t
*chip
,char *type
);
183 static int __init
smsc_superio_flat(const smsc_chip_t
*chips
, unsigned short cfg_base
, char *type
);
184 static int __init
smsc_superio_paged(const smsc_chip_t
*chips
, unsigned short cfg_base
, char *type
);
185 static int __init
smsc_superio_fdc(unsigned short cfg_base
);
186 static int __init
smsc_superio_lpc(unsigned short cfg_base
);
188 /* Transceivers specific functions */
190 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base
, u32 speed
);
191 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base
);
192 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base
, u32 speed
);
193 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base
);
194 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base
, u32 speed
);
195 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base
);
197 /* Power Management */
199 static void smsc_ircc_suspend(struct smsc_ircc_cb
*self
);
200 static void smsc_ircc_wakeup(struct smsc_ircc_cb
*self
);
201 static int smsc_ircc_pmproc(struct pm_dev
*dev
, pm_request_t rqst
, void *data
);
204 /* Transceivers for SMSC-ircc */
206 static smsc_transceiver_t smsc_transceivers
[]=
208 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800
, smsc_ircc_probe_transceiver_toshiba_sat1800
},
209 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select
, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select
},
210 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc
, smsc_ircc_probe_transceiver_smsc_ircc_atc
},
213 #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (DIM(smsc_transceivers)-1)
215 /* SMC SuperIO chipsets definitions */
217 #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
218 #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
219 #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
220 #define SIR 0 /* SuperIO Chip has only slow IRDA */
221 #define FIR 4 /* SuperIO Chip has fast IRDA */
222 #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
224 static smsc_chip_t __initdata fdc_chips_flat
[]=
226 /* Base address 0x3f0 or 0x370 */
227 { "37C44", KEY55_1
|NoIRDA
, 0x00, 0x00 }, /* This chip cannot be detected */
228 { "37C665GT", KEY55_2
|NoIRDA
, 0x65, 0x01 },
229 { "37C665GT", KEY55_2
|NoIRDA
, 0x66, 0x01 },
230 { "37C669", KEY55_2
|SIR
|SERx4
, 0x03, 0x02 },
231 { "37C669", KEY55_2
|SIR
|SERx4
, 0x04, 0x02 }, /* ID? */
232 { "37C78", KEY55_2
|NoIRDA
, 0x78, 0x00 },
233 { "37N769", KEY55_1
|FIR
|SERx4
, 0x28, 0x00 },
234 { "37N869", KEY55_1
|FIR
|SERx4
, 0x29, 0x00 },
238 static smsc_chip_t __initdata fdc_chips_paged
[]=
240 /* Base address 0x3f0 or 0x370 */
241 { "37B72X", KEY55_1
|SIR
|SERx4
, 0x4c, 0x00 },
242 { "37B77X", KEY55_1
|SIR
|SERx4
, 0x43, 0x00 },
243 { "37B78X", KEY55_1
|SIR
|SERx4
, 0x44, 0x00 },
244 { "37B80X", KEY55_1
|SIR
|SERx4
, 0x42, 0x00 },
245 { "37C67X", KEY55_1
|FIR
|SERx4
, 0x40, 0x00 },
246 { "37C93X", KEY55_2
|SIR
|SERx4
, 0x02, 0x01 },
247 { "37C93XAPM", KEY55_1
|SIR
|SERx4
, 0x30, 0x01 },
248 { "37C93XFR", KEY55_2
|FIR
|SERx4
, 0x03, 0x01 },
249 { "37M707", KEY55_1
|SIR
|SERx4
, 0x42, 0x00 },
250 { "37M81X", KEY55_1
|SIR
|SERx4
, 0x4d, 0x00 },
251 { "37N958FR", KEY55_1
|FIR
|SERx4
, 0x09, 0x04 },
252 { "37N971", KEY55_1
|FIR
|SERx4
, 0x0a, 0x00 },
253 { "37N972", KEY55_1
|FIR
|SERx4
, 0x0b, 0x00 },
257 static smsc_chip_t __initdata lpc_chips_flat
[]=
259 /* Base address 0x2E or 0x4E */
260 { "47N227", KEY55_1
|FIR
|SERx4
, 0x5a, 0x00 },
261 { "47N267", KEY55_1
|FIR
|SERx4
, 0x5e, 0x00 },
265 static smsc_chip_t __initdata lpc_chips_paged
[]=
267 /* Base address 0x2E or 0x4E */
268 { "47B27X", KEY55_1
|SIR
|SERx4
, 0x51, 0x00 },
269 { "47B37X", KEY55_1
|SIR
|SERx4
, 0x52, 0x00 },
270 { "47M10X", KEY55_1
|SIR
|SERx4
, 0x59, 0x00 },
271 { "47M120", KEY55_1
|NoIRDA
|SERx4
, 0x5c, 0x00 },
272 { "47M13X", KEY55_1
|SIR
|SERx4
, 0x59, 0x00 },
273 { "47M14X", KEY55_1
|SIR
|SERx4
, 0x5f, 0x00 },
274 { "47N252", KEY55_1
|FIR
|SERx4
, 0x0e, 0x00 },
275 { "47S42X", KEY55_1
|SIR
|SERx4
, 0x57, 0x00 },
279 #define SMSCSIO_TYPE_FDC 1
280 #define SMSCSIO_TYPE_LPC 2
281 #define SMSCSIO_TYPE_FLAT 4
282 #define SMSCSIO_TYPE_PAGED 8
284 static smsc_chip_address_t __initdata possible_addresses
[]=
286 {0x3f0, SMSCSIO_TYPE_FDC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
287 {0x370, SMSCSIO_TYPE_FDC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
288 {0xe0, SMSCSIO_TYPE_FDC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
289 {0x2e, SMSCSIO_TYPE_LPC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
290 {0x4e, SMSCSIO_TYPE_LPC
|SMSCSIO_TYPE_FLAT
|SMSCSIO_TYPE_PAGED
},
296 static struct smsc_ircc_cb
*dev_self
[] = { NULL
, NULL
};
298 static int ircc_irq
=255;
299 static int ircc_dma
=255;
300 static int ircc_fir
=0;
301 static int ircc_sir
=0;
302 static int ircc_cfg
=0;
303 static int ircc_transceiver
=0;
305 static unsigned short dev_count
=0;
307 static inline void register_bank(int iobase
, int bank
)
309 outb(((inb(iobase
+IRCC_MASTER
) & 0xf0) | (bank
& 0x07)),
314 /*******************************************************************************
320 *******************************************************************************/
323 * Function smsc_ircc_init ()
325 * Initialize chip. Just try to find out how many chips we are dealing with
328 static int __init
smsc_ircc_init(void)
332 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
336 if ((ircc_fir
>0)&&(ircc_sir
>0)) {
337 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir
);
338 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir
);
340 if (smsc_ircc_open(ircc_fir
, ircc_sir
, ircc_dma
, ircc_irq
) == 0)
346 /* try user provided configuration register base address */
348 IRDA_MESSAGE(" Overriding configuration address 0x%04x\n",
350 if (!smsc_superio_fdc(ircc_cfg
))
352 if (!smsc_superio_lpc(ircc_cfg
))
356 if(smsc_ircc_look_for_chips()>0) ret
= 0;
362 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
364 * Try to open driver instance
367 static int __init
smsc_ircc_open(unsigned int fir_base
, unsigned int sir_base
, u8 dma
, u8 irq
)
369 struct smsc_ircc_cb
*self
;
370 struct net_device
*dev
;
373 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
375 err
= smsc_ircc_present(fir_base
, sir_base
);
380 if (dev_count
> DIM(dev_self
)) {
381 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__
);
386 * Allocate new instance of the driver
388 dev
= alloc_irdadev(sizeof(struct smsc_ircc_cb
));
390 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__
);
394 SET_MODULE_OWNER(dev
);
396 dev
->hard_start_xmit
= smsc_ircc_hard_xmit_sir
;
397 #if SMSC_IRCC2_C_NET_TIMEOUT
398 dev
->tx_timeout
= smsc_ircc_timeout
;
399 dev
->watchdog_timeo
= HZ
*2; /* Allow enough time for speed change */
401 dev
->open
= smsc_ircc_net_open
;
402 dev
->stop
= smsc_ircc_net_close
;
403 dev
->do_ioctl
= smsc_ircc_net_ioctl
;
404 dev
->get_stats
= smsc_ircc_net_get_stats
;
409 /* Make ifconfig display some details */
410 dev
->base_addr
= self
->io
.fir_base
= fir_base
;
411 dev
->irq
= self
->io
.irq
= irq
;
413 /* Need to store self somewhere */
414 dev_self
[dev_count
++] = self
;
415 spin_lock_init(&self
->lock
);
417 self
->rx_buff
.truesize
= SMSC_IRCC2_RX_BUFF_TRUESIZE
;
418 self
->tx_buff
.truesize
= SMSC_IRCC2_TX_BUFF_TRUESIZE
;
421 dma_alloc_coherent(NULL
, self
->rx_buff
.truesize
,
422 &self
->rx_buff_dma
, GFP_KERNEL
);
423 if (self
->rx_buff
.head
== NULL
) {
424 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
430 dma_alloc_coherent(NULL
, self
->tx_buff
.truesize
,
431 &self
->tx_buff_dma
, GFP_KERNEL
);
432 if (self
->tx_buff
.head
== NULL
) {
433 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
438 memset(self
->rx_buff
.head
, 0, self
->rx_buff
.truesize
);
439 memset(self
->tx_buff
.head
, 0, self
->tx_buff
.truesize
);
441 self
->rx_buff
.in_frame
= FALSE
;
442 self
->rx_buff
.state
= OUTSIDE_FRAME
;
443 self
->tx_buff
.data
= self
->tx_buff
.head
;
444 self
->rx_buff
.data
= self
->rx_buff
.head
;
446 smsc_ircc_setup_io(self
, fir_base
, sir_base
, dma
, irq
);
448 smsc_ircc_setup_qos(self
);
450 smsc_ircc_init_chip(self
);
452 if(ircc_transceiver
> 0 &&
453 ircc_transceiver
< SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS
)
454 self
->transceiver
= ircc_transceiver
;
456 smsc_ircc_probe_transceiver(self
);
458 err
= register_netdev(self
->netdev
);
460 IRDA_ERROR("%s, Network device registration failed!\n",
465 self
->pmdev
= pm_register(PM_SYS_DEV
, PM_SYS_IRDA
, smsc_ircc_pmproc
);
467 self
->pmdev
->data
= self
;
469 IRDA_MESSAGE("IrDA: Registered device %s\n", dev
->name
);
473 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
474 self
->tx_buff
.head
, self
->tx_buff_dma
);
476 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
477 self
->rx_buff
.head
, self
->rx_buff_dma
);
479 free_netdev(self
->netdev
);
480 dev_self
[--dev_count
] = NULL
;
482 release_region(fir_base
, SMSC_IRCC2_FIR_CHIP_IO_EXTENT
);
483 release_region(sir_base
, SMSC_IRCC2_SIR_CHIP_IO_EXTENT
);
489 * Function smsc_ircc_present(fir_base, sir_base)
491 * Check the smsc-ircc chip presence
494 static int smsc_ircc_present(unsigned int fir_base
, unsigned int sir_base
)
496 unsigned char low
, high
, chip
, config
, dma
, irq
, version
;
498 if (!request_region(fir_base
, SMSC_IRCC2_FIR_CHIP_IO_EXTENT
,
500 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
501 __FUNCTION__
, fir_base
);
505 if (!request_region(sir_base
, SMSC_IRCC2_SIR_CHIP_IO_EXTENT
,
507 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
508 __FUNCTION__
, sir_base
);
512 register_bank(fir_base
, 3);
514 high
= inb(fir_base
+IRCC_ID_HIGH
);
515 low
= inb(fir_base
+IRCC_ID_LOW
);
516 chip
= inb(fir_base
+IRCC_CHIP_ID
);
517 version
= inb(fir_base
+IRCC_VERSION
);
518 config
= inb(fir_base
+IRCC_INTERFACE
);
519 dma
= config
& IRCC_INTERFACE_DMA_MASK
;
520 irq
= (config
& IRCC_INTERFACE_IRQ_MASK
) >> 4;
522 if (high
!= 0x10 || low
!= 0xb8 || (chip
!= 0xf1 && chip
!= 0xf2)) {
523 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
524 __FUNCTION__
, fir_base
);
527 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
528 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
529 chip
& 0x0f, version
, fir_base
, sir_base
, dma
, irq
);
533 release_region(sir_base
, SMSC_IRCC2_SIR_CHIP_IO_EXTENT
);
535 release_region(fir_base
, SMSC_IRCC2_FIR_CHIP_IO_EXTENT
);
541 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
546 static void smsc_ircc_setup_io(struct smsc_ircc_cb
*self
,
547 unsigned int fir_base
, unsigned int sir_base
,
550 unsigned char config
, chip_dma
, chip_irq
;
552 register_bank(fir_base
, 3);
553 config
= inb(fir_base
+IRCC_INTERFACE
);
554 chip_dma
= config
& IRCC_INTERFACE_DMA_MASK
;
555 chip_irq
= (config
& IRCC_INTERFACE_IRQ_MASK
) >> 4;
557 self
->io
.fir_base
= fir_base
;
558 self
->io
.sir_base
= sir_base
;
559 self
->io
.fir_ext
= SMSC_IRCC2_FIR_CHIP_IO_EXTENT
;
560 self
->io
.sir_ext
= SMSC_IRCC2_SIR_CHIP_IO_EXTENT
;
561 self
->io
.fifo_size
= SMSC_IRCC2_FIFO_SIZE
;
562 self
->io
.speed
= SMSC_IRCC2_C_IRDA_FALLBACK_SPEED
;
566 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
567 driver_name
, chip_irq
, irq
);
571 self
->io
.irq
= chip_irq
;
575 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
576 driver_name
, chip_dma
, dma
);
580 self
->io
.dma
= chip_dma
;
585 * Function smsc_ircc_setup_qos(self)
590 static void smsc_ircc_setup_qos(struct smsc_ircc_cb
*self
)
592 /* Initialize QoS for this device */
593 irda_init_max_qos_capabilies(&self
->qos
);
595 self
->qos
.baud_rate
.bits
= IR_9600
|IR_19200
|IR_38400
|IR_57600
|
596 IR_115200
|IR_576000
|IR_1152000
|(IR_4000000
<< 8);
598 self
->qos
.min_turn_time
.bits
= SMSC_IRCC2_MIN_TURN_TIME
;
599 self
->qos
.window_size
.bits
= SMSC_IRCC2_WINDOW_SIZE
;
600 irda_qos_bits_to_value(&self
->qos
);
604 * Function smsc_ircc_init_chip(self)
609 static void smsc_ircc_init_chip(struct smsc_ircc_cb
*self
)
611 int iobase
, ir_mode
, ctrl
, fast
;
613 IRDA_ASSERT( self
!= NULL
, return; );
614 iobase
= self
->io
.fir_base
;
616 ir_mode
= IRCC_CFGA_IRDA_SIR_A
;
620 register_bank(iobase
, 0);
621 outb(IRCC_MASTER_RESET
, iobase
+IRCC_MASTER
);
622 outb(0x00, iobase
+IRCC_MASTER
);
624 register_bank(iobase
, 1);
625 outb(((inb(iobase
+IRCC_SCE_CFGA
) & 0x87) | ir_mode
),
626 iobase
+IRCC_SCE_CFGA
);
628 #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
629 outb(((inb(iobase
+IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_COM
),
630 iobase
+IRCC_SCE_CFGB
);
632 outb(((inb(iobase
+IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_IR
),
633 iobase
+IRCC_SCE_CFGB
);
635 (void) inb(iobase
+IRCC_FIFO_THRESHOLD
);
636 outb(SMSC_IRCC2_FIFO_THRESHOLD
, iobase
+IRCC_FIFO_THRESHOLD
);
638 register_bank(iobase
, 4);
639 outb((inb(iobase
+IRCC_CONTROL
) & 0x30) | ctrl
, iobase
+IRCC_CONTROL
);
641 register_bank(iobase
, 0);
642 outb(fast
, iobase
+IRCC_LCR_A
);
644 smsc_ircc_set_sir_speed(self
, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED
);
646 /* Power on device */
647 outb(0x00, iobase
+IRCC_MASTER
);
651 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
653 * Process IOCTL commands for this device
656 static int smsc_ircc_net_ioctl(struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
658 struct if_irda_req
*irq
= (struct if_irda_req
*) rq
;
659 struct smsc_ircc_cb
*self
;
663 IRDA_ASSERT(dev
!= NULL
, return -1;);
667 IRDA_ASSERT(self
!= NULL
, return -1;);
669 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__
, dev
->name
, cmd
);
672 case SIOCSBANDWIDTH
: /* Set bandwidth */
673 if (!capable(CAP_NET_ADMIN
))
676 /* Make sure we are the only one touching
677 * self->io.speed and the hardware - Jean II */
678 spin_lock_irqsave(&self
->lock
, flags
);
679 smsc_ircc_change_speed(self
, irq
->ifr_baudrate
);
680 spin_unlock_irqrestore(&self
->lock
, flags
);
683 case SIOCSMEDIABUSY
: /* Set media busy */
684 if (!capable(CAP_NET_ADMIN
)) {
689 irda_device_set_media_busy(self
->netdev
, TRUE
);
691 case SIOCGRECEIVING
: /* Check if we are receiving right now */
692 irq
->ifr_receiving
= smsc_ircc_is_receiving(self
);
696 if (!capable(CAP_NET_ADMIN
)) {
700 smsc_ircc_sir_set_dtr_rts(dev
, irq
->ifr_dtr
, irq
->ifr_rts
);
710 static struct net_device_stats
*smsc_ircc_net_get_stats(struct net_device
*dev
)
712 struct smsc_ircc_cb
*self
= (struct smsc_ircc_cb
*) dev
->priv
;
717 #if SMSC_IRCC2_C_NET_TIMEOUT
719 * Function smsc_ircc_timeout (struct net_device *dev)
721 * The networking timeout management.
725 static void smsc_ircc_timeout(struct net_device
*dev
)
727 struct smsc_ircc_cb
*self
;
730 self
= (struct smsc_ircc_cb
*) dev
->priv
;
732 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
733 dev
->name
, self
->io
.speed
);
734 spin_lock_irqsave(&self
->lock
, flags
);
735 smsc_ircc_sir_start(self
);
736 smsc_ircc_change_speed(self
, self
->io
.speed
);
737 dev
->trans_start
= jiffies
;
738 netif_wake_queue(dev
);
739 spin_unlock_irqrestore(&self
->lock
, flags
);
744 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
746 * Transmits the current frame until FIFO is full, then
747 * waits until the next transmit interrupt, and continues until the
748 * frame is transmitted.
750 int smsc_ircc_hard_xmit_sir(struct sk_buff
*skb
, struct net_device
*dev
)
752 struct smsc_ircc_cb
*self
;
757 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
759 IRDA_ASSERT(dev
!= NULL
, return 0;);
761 self
= (struct smsc_ircc_cb
*) dev
->priv
;
762 IRDA_ASSERT(self
!= NULL
, return 0;);
764 iobase
= self
->io
.sir_base
;
766 netif_stop_queue(dev
);
768 /* Make sure test of self->io.speed & speed change are atomic */
769 spin_lock_irqsave(&self
->lock
, flags
);
771 /* Check if we need to change the speed */
772 speed
= irda_get_next_speed(skb
);
773 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
774 /* Check for empty frame */
777 * We send frames one by one in SIR mode (no
778 * pipelining), so at this point, if we were sending
779 * a previous frame, we just received the interrupt
780 * telling us it is finished (UART_IIR_THRI).
781 * Therefore, waiting for the transmitter to really
782 * finish draining the fifo won't take too long.
783 * And the interrupt handler is not expected to run.
785 smsc_ircc_sir_wait_hw_transmitter_finish(self
);
786 smsc_ircc_change_speed(self
, speed
);
787 spin_unlock_irqrestore(&self
->lock
, flags
);
791 self
->new_speed
= speed
;
796 self
->tx_buff
.data
= self
->tx_buff
.head
;
798 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
799 self
->tx_buff
.len
= async_wrap_skb(skb
, self
->tx_buff
.data
,
800 self
->tx_buff
.truesize
);
802 self
->stats
.tx_bytes
+= self
->tx_buff
.len
;
804 /* Turn on transmit finished interrupt. Will fire immediately! */
805 outb(UART_IER_THRI
, iobase
+UART_IER
);
807 spin_unlock_irqrestore(&self
->lock
, flags
);
815 * Function smsc_ircc_set_fir_speed (self, baud)
817 * Change the speed of the device
820 static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb
*self
, u32 speed
)
822 int fir_base
, ir_mode
, ctrl
, fast
;
824 IRDA_ASSERT(self
!= NULL
, return;);
825 fir_base
= self
->io
.fir_base
;
827 self
->io
.speed
= speed
;
832 ir_mode
= IRCC_CFGA_IRDA_HDLC
;
835 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__
);
838 ir_mode
= IRCC_CFGA_IRDA_HDLC
;
839 ctrl
= IRCC_1152
| IRCC_CRC
;
840 fast
= IRCC_LCR_A_FAST
| IRCC_LCR_A_GP_DATA
;
841 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
845 ir_mode
= IRCC_CFGA_IRDA_4PPM
;
847 fast
= IRCC_LCR_A_FAST
;
848 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
854 /* This causes an interrupt */
855 register_bank(fir_base
, 0);
856 outb((inb(fir_base
+IRCC_LCR_A
) & 0xbf) | fast
, fir_base
+IRCC_LCR_A
);
859 register_bank(fir_base
, 1);
860 outb(((inb(fir_base
+IRCC_SCE_CFGA
) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK
) | ir_mode
), fir_base
+IRCC_SCE_CFGA
);
862 register_bank(fir_base
, 4);
863 outb((inb(fir_base
+IRCC_CONTROL
) & 0x30) | ctrl
, fir_base
+IRCC_CONTROL
);
867 * Function smsc_ircc_fir_start(self)
869 * Change the speed of the device
872 static void smsc_ircc_fir_start(struct smsc_ircc_cb
*self
)
874 struct net_device
*dev
;
877 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
879 IRDA_ASSERT(self
!= NULL
, return;);
881 IRDA_ASSERT(dev
!= NULL
, return;);
883 fir_base
= self
->io
.fir_base
;
885 /* Reset everything */
887 /* Install FIR transmit handler */
888 dev
->hard_start_xmit
= smsc_ircc_hard_xmit_fir
;
891 outb(inb(fir_base
+IRCC_LCR_A
)|IRCC_LCR_A_FIFO_RESET
, fir_base
+IRCC_LCR_A
);
893 /* Enable interrupt */
894 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base+IRCC_IER);*/
896 register_bank(fir_base
, 1);
898 /* Select the TX/RX interface */
899 #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
900 outb(((inb(fir_base
+IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_COM
),
901 fir_base
+IRCC_SCE_CFGB
);
903 outb(((inb(fir_base
+IRCC_SCE_CFGB
) & 0x3f) | IRCC_CFGB_MUX_IR
),
904 fir_base
+IRCC_SCE_CFGB
);
906 (void) inb(fir_base
+IRCC_FIFO_THRESHOLD
);
908 /* Enable SCE interrupts */
909 outb(0, fir_base
+IRCC_MASTER
);
910 register_bank(fir_base
, 0);
911 outb(IRCC_IER_ACTIVE_FRAME
|IRCC_IER_EOM
, fir_base
+IRCC_IER
);
912 outb(IRCC_MASTER_INT_EN
, fir_base
+IRCC_MASTER
);
916 * Function smsc_ircc_fir_stop(self, baud)
918 * Change the speed of the device
921 static void smsc_ircc_fir_stop(struct smsc_ircc_cb
*self
)
925 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
927 IRDA_ASSERT(self
!= NULL
, return;);
929 fir_base
= self
->io
.fir_base
;
930 register_bank(fir_base
, 0);
931 /*outb(IRCC_MASTER_RESET, fir_base+IRCC_MASTER);*/
932 outb(inb(fir_base
+IRCC_LCR_B
) & IRCC_LCR_B_SIP_ENABLE
, fir_base
+IRCC_LCR_B
);
937 * Function smsc_ircc_change_speed(self, baud)
939 * Change the speed of the device
941 * This function *must* be called with spinlock held, because it may
942 * be called from the irq handler. - Jean II
944 static void smsc_ircc_change_speed(void *priv
, u32 speed
)
946 struct smsc_ircc_cb
*self
= (struct smsc_ircc_cb
*) priv
;
947 struct net_device
*dev
;
949 int last_speed_was_sir
;
951 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__
, speed
);
953 IRDA_ASSERT(self
!= NULL
, return;);
955 iobase
= self
->io
.fir_base
;
957 last_speed_was_sir
= self
->io
.speed
<= SMSC_IRCC2_MAX_SIR_SPEED
;
962 self
->io
.speed
= speed
;
963 last_speed_was_sir
= 0;
964 smsc_ircc_fir_start(self
);
967 if(self
->io
.speed
== 0)
968 smsc_ircc_sir_start(self
);
971 if(!last_speed_was_sir
) speed
= self
->io
.speed
;
974 if(self
->io
.speed
!= speed
) smsc_ircc_set_transceiver_for_speed(self
, speed
);
976 self
->io
.speed
= speed
;
978 if(speed
<= SMSC_IRCC2_MAX_SIR_SPEED
) {
979 if(!last_speed_was_sir
) {
980 smsc_ircc_fir_stop(self
);
981 smsc_ircc_sir_start(self
);
983 smsc_ircc_set_sir_speed(self
, speed
);
986 if(last_speed_was_sir
) {
987 #if SMSC_IRCC2_C_SIR_STOP
988 smsc_ircc_sir_stop(self
);
990 smsc_ircc_fir_start(self
);
992 smsc_ircc_set_fir_speed(self
, speed
);
995 self
->tx_buff
.len
= 10;
996 self
->tx_buff
.data
= self
->tx_buff
.head
;
998 smsc_ircc_dma_xmit(self
, iobase
, 4000);
1000 /* Be ready for incoming frames */
1001 smsc_ircc_dma_receive(self
, iobase
);
1004 netif_wake_queue(dev
);
1008 * Function smsc_ircc_set_sir_speed (self, speed)
1010 * Set speed of IrDA port to specified baudrate
1013 void smsc_ircc_set_sir_speed(void *priv
, __u32 speed
)
1015 struct smsc_ircc_cb
*self
= (struct smsc_ircc_cb
*) priv
;
1017 int fcr
; /* FIFO control reg */
1018 int lcr
; /* Line control reg */
1021 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__
, speed
);
1023 IRDA_ASSERT(self
!= NULL
, return;);
1024 iobase
= self
->io
.sir_base
;
1026 /* Update accounting for new speed */
1027 self
->io
.speed
= speed
;
1029 /* Turn off interrupts */
1030 outb(0, iobase
+UART_IER
);
1032 divisor
= SMSC_IRCC2_MAX_SIR_SPEED
/speed
;
1034 fcr
= UART_FCR_ENABLE_FIFO
;
1037 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1038 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1039 * about this timeout since it will always be fast enough.
1041 if (self
->io
.speed
< 38400)
1042 fcr
|= UART_FCR_TRIGGER_1
;
1044 fcr
|= UART_FCR_TRIGGER_14
;
1046 /* IrDA ports use 8N1 */
1047 lcr
= UART_LCR_WLEN8
;
1049 outb(UART_LCR_DLAB
| lcr
, iobase
+UART_LCR
); /* Set DLAB */
1050 outb(divisor
& 0xff, iobase
+UART_DLL
); /* Set speed */
1051 outb(divisor
>> 8, iobase
+UART_DLM
);
1052 outb(lcr
, iobase
+UART_LCR
); /* Set 8N1 */
1053 outb(fcr
, iobase
+UART_FCR
); /* Enable FIFO's */
1055 /* Turn on interrups */
1056 outb(UART_IER_RLSI
|UART_IER_RDI
|UART_IER_THRI
, iobase
+UART_IER
);
1058 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__
, speed
);
1063 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1065 * Transmit the frame!
1068 static int smsc_ircc_hard_xmit_fir(struct sk_buff
*skb
, struct net_device
*dev
)
1070 struct smsc_ircc_cb
*self
;
1071 unsigned long flags
;
1076 IRDA_ASSERT(dev
!= NULL
, return 0;);
1077 self
= (struct smsc_ircc_cb
*) dev
->priv
;
1078 IRDA_ASSERT(self
!= NULL
, return 0;);
1080 iobase
= self
->io
.fir_base
;
1082 netif_stop_queue(dev
);
1084 /* Make sure test of self->io.speed & speed change are atomic */
1085 spin_lock_irqsave(&self
->lock
, flags
);
1087 /* Check if we need to change the speed after this frame */
1088 speed
= irda_get_next_speed(skb
);
1089 if ((speed
!= self
->io
.speed
) && (speed
!= -1)) {
1090 /* Check for empty frame */
1092 /* Note : you should make sure that speed changes
1093 * are not going to corrupt any outgoing frame.
1094 * Look at nsc-ircc for the gory details - Jean II */
1095 smsc_ircc_change_speed(self
, speed
);
1096 spin_unlock_irqrestore(&self
->lock
, flags
);
1100 self
->new_speed
= speed
;
1103 memcpy(self
->tx_buff
.head
, skb
->data
, skb
->len
);
1105 self
->tx_buff
.len
= skb
->len
;
1106 self
->tx_buff
.data
= self
->tx_buff
.head
;
1108 mtt
= irda_get_mtt(skb
);
1113 * Compute how many BOFs (STA or PA's) we need to waste the
1114 * min turn time given the speed of the link.
1116 bofs
= mtt
* (self
->io
.speed
/ 1000) / 8000;
1120 smsc_ircc_dma_xmit(self
, iobase
, bofs
);
1122 /* Transmit frame */
1123 smsc_ircc_dma_xmit(self
, iobase
, 0);
1125 spin_unlock_irqrestore(&self
->lock
, flags
);
1132 * Function smsc_ircc_dma_xmit (self, iobase)
1134 * Transmit data using DMA
1137 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb
*self
, int iobase
, int bofs
)
1141 IRDA_DEBUG(3, "%s\n", __FUNCTION__
);
1144 register_bank(iobase
, 0);
1145 outb(0x00, iobase
+IRCC_LCR_B
);
1147 register_bank(iobase
, 1);
1148 outb(inb(iobase
+IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1149 iobase
+IRCC_SCE_CFGB
);
1151 self
->io
.direction
= IO_XMIT
;
1153 /* Set BOF additional count for generating the min turn time */
1154 register_bank(iobase
, 4);
1155 outb(bofs
& 0xff, iobase
+IRCC_BOF_COUNT_LO
);
1156 ctrl
= inb(iobase
+IRCC_CONTROL
) & 0xf0;
1157 outb(ctrl
| ((bofs
>> 8) & 0x0f), iobase
+IRCC_BOF_COUNT_HI
);
1159 /* Set max Tx frame size */
1160 outb(self
->tx_buff
.len
>> 8, iobase
+IRCC_TX_SIZE_HI
);
1161 outb(self
->tx_buff
.len
& 0xff, iobase
+IRCC_TX_SIZE_LO
);
1163 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1165 /* Enable burst mode chip Tx DMA */
1166 register_bank(iobase
, 1);
1167 outb(inb(iobase
+IRCC_SCE_CFGB
) | IRCC_CFGB_DMA_ENABLE
|
1168 IRCC_CFGB_DMA_BURST
, iobase
+IRCC_SCE_CFGB
);
1170 /* Setup DMA controller (must be done after enabling chip DMA) */
1171 irda_setup_dma(self
->io
.dma
, self
->tx_buff_dma
, self
->tx_buff
.len
,
1174 /* Enable interrupt */
1176 register_bank(iobase
, 0);
1177 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, iobase
+IRCC_IER
);
1178 outb(IRCC_MASTER_INT_EN
, iobase
+IRCC_MASTER
);
1180 /* Enable transmit */
1181 outb(IRCC_LCR_B_SCE_TRANSMIT
| IRCC_LCR_B_SIP_ENABLE
, iobase
+IRCC_LCR_B
);
1185 * Function smsc_ircc_dma_xmit_complete (self)
1187 * The transfer of a frame in finished. This function will only be called
1188 * by the interrupt handler
1191 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb
*self
, int iobase
)
1193 IRDA_DEBUG(3, "%s\n", __FUNCTION__
);
1196 register_bank(iobase
, 0);
1197 outb(0x00, iobase
+IRCC_LCR_B
);
1199 register_bank(self
->io
.fir_base
, 1);
1200 outb(inb(self
->io
.fir_base
+IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1201 self
->io
.fir_base
+IRCC_SCE_CFGB
);
1203 /* Check for underrun! */
1204 register_bank(iobase
, 0);
1205 if (inb(iobase
+IRCC_LSR
) & IRCC_LSR_UNDERRUN
) {
1206 self
->stats
.tx_errors
++;
1207 self
->stats
.tx_fifo_errors
++;
1209 /* Reset error condition */
1210 register_bank(iobase
, 0);
1211 outb(IRCC_MASTER_ERROR_RESET
, iobase
+IRCC_MASTER
);
1212 outb(0x00, iobase
+IRCC_MASTER
);
1214 self
->stats
.tx_packets
++;
1215 self
->stats
.tx_bytes
+= self
->tx_buff
.len
;
1218 /* Check if it's time to change the speed */
1219 if (self
->new_speed
) {
1220 smsc_ircc_change_speed(self
, self
->new_speed
);
1221 self
->new_speed
= 0;
1224 netif_wake_queue(self
->netdev
);
1228 * Function smsc_ircc_dma_receive(self)
1230 * Get ready for receiving a frame. The device will initiate a DMA
1231 * if it starts to receive a frame.
1234 static int smsc_ircc_dma_receive(struct smsc_ircc_cb
*self
, int iobase
)
1237 /* Turn off chip DMA */
1238 register_bank(iobase
, 1);
1239 outb(inb(iobase
+IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1240 iobase
+IRCC_SCE_CFGB
);
1244 register_bank(iobase
, 0);
1245 outb(0x00, iobase
+IRCC_LCR_B
);
1247 /* Turn off chip DMA */
1248 register_bank(iobase
, 1);
1249 outb(inb(iobase
+IRCC_SCE_CFGB
) & ~IRCC_CFGB_DMA_ENABLE
,
1250 iobase
+IRCC_SCE_CFGB
);
1252 self
->io
.direction
= IO_RECV
;
1253 self
->rx_buff
.data
= self
->rx_buff
.head
;
1255 /* Set max Rx frame size */
1256 register_bank(iobase
, 4);
1257 outb((2050 >> 8) & 0x0f, iobase
+IRCC_RX_SIZE_HI
);
1258 outb(2050 & 0xff, iobase
+IRCC_RX_SIZE_LO
);
1260 /* Setup DMA controller */
1261 irda_setup_dma(self
->io
.dma
, self
->rx_buff_dma
, self
->rx_buff
.truesize
,
1264 /* Enable burst mode chip Rx DMA */
1265 register_bank(iobase
, 1);
1266 outb(inb(iobase
+IRCC_SCE_CFGB
) | IRCC_CFGB_DMA_ENABLE
|
1267 IRCC_CFGB_DMA_BURST
, iobase
+IRCC_SCE_CFGB
);
1269 /* Enable interrupt */
1270 register_bank(iobase
, 0);
1271 outb(IRCC_IER_ACTIVE_FRAME
| IRCC_IER_EOM
, iobase
+IRCC_IER
);
1272 outb(IRCC_MASTER_INT_EN
, iobase
+IRCC_MASTER
);
1275 /* Enable receiver */
1276 register_bank(iobase
, 0);
1277 outb(IRCC_LCR_B_SCE_RECEIVE
| IRCC_LCR_B_SIP_ENABLE
,
1284 * Function smsc_ircc_dma_receive_complete(self, iobase)
1286 * Finished with receiving frames
1289 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb
*self
, int iobase
)
1291 struct sk_buff
*skb
;
1292 int len
, msgcnt
, lsr
;
1294 register_bank(iobase
, 0);
1296 IRDA_DEBUG(3, "%s\n", __FUNCTION__
);
1299 register_bank(iobase
, 0);
1300 outb(0x00, iobase
+IRCC_LCR_B
);
1302 register_bank(iobase
, 0);
1303 outb(inb(iobase
+IRCC_LSAR
) & ~IRCC_LSAR_ADDRESS_MASK
, iobase
+IRCC_LSAR
);
1304 lsr
= inb(iobase
+IRCC_LSR
);
1305 msgcnt
= inb(iobase
+IRCC_LCR_B
) & 0x08;
1307 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__
,
1308 get_dma_residue(self
->io
.dma
));
1310 len
= self
->rx_buff
.truesize
- get_dma_residue(self
->io
.dma
);
1315 if(lsr
& (IRCC_LSR_FRAME_ERROR
| IRCC_LSR_CRC_ERROR
| IRCC_LSR_SIZE_ERROR
)) {
1316 self
->stats
.rx_errors
++;
1317 if(lsr
& IRCC_LSR_FRAME_ERROR
) self
->stats
.rx_frame_errors
++;
1318 if(lsr
& IRCC_LSR_CRC_ERROR
) self
->stats
.rx_crc_errors
++;
1319 if(lsr
& IRCC_LSR_SIZE_ERROR
) self
->stats
.rx_length_errors
++;
1320 if(lsr
& (IRCC_LSR_UNDERRUN
| IRCC_LSR_OVERRUN
)) self
->stats
.rx_length_errors
++;
1324 if (self
->io
.speed
< 4000000)
1329 if ((len
< 2) || (len
> 2050)) {
1330 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__
, len
);
1333 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__
, msgcnt
, len
);
1335 skb
= dev_alloc_skb(len
+1);
1337 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1341 /* Make sure IP header gets aligned */
1342 skb_reserve(skb
, 1);
1344 memcpy(skb_put(skb
, len
), self
->rx_buff
.data
, len
);
1345 self
->stats
.rx_packets
++;
1346 self
->stats
.rx_bytes
+= len
;
1348 skb
->dev
= self
->netdev
;
1349 skb
->mac
.raw
= skb
->data
;
1350 skb
->protocol
= htons(ETH_P_IRDA
);
1355 * Function smsc_ircc_sir_receive (self)
1357 * Receive one frame from the infrared port
1360 static void smsc_ircc_sir_receive(struct smsc_ircc_cb
*self
)
1365 IRDA_ASSERT(self
!= NULL
, return;);
1367 iobase
= self
->io
.sir_base
;
1370 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1371 * async_unwrap_char will deliver all found frames
1374 async_unwrap_char(self
->netdev
, &self
->stats
, &self
->rx_buff
,
1375 inb(iobase
+UART_RX
));
1377 /* Make sure we don't stay here to long */
1378 if (boguscount
++ > 32) {
1379 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__
);
1382 } while (inb(iobase
+UART_LSR
) & UART_LSR_DR
);
1387 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1389 * An interrupt from the chip has arrived. Time to do some work
1392 static irqreturn_t
smsc_ircc_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1394 struct net_device
*dev
= (struct net_device
*) dev_id
;
1395 struct smsc_ircc_cb
*self
;
1396 int iobase
, iir
, lcra
, lsr
;
1397 irqreturn_t ret
= IRQ_NONE
;
1400 printk(KERN_WARNING
"%s: irq %d for unknown device.\n",
1404 self
= (struct smsc_ircc_cb
*) dev
->priv
;
1405 IRDA_ASSERT(self
!= NULL
, return IRQ_NONE
;);
1407 /* Serialise the interrupt handler in various CPUs, stop Tx path */
1408 spin_lock(&self
->lock
);
1410 /* Check if we should use the SIR interrupt handler */
1411 if (self
->io
.speed
<= SMSC_IRCC2_MAX_SIR_SPEED
) {
1412 ret
= smsc_ircc_interrupt_sir(dev
);
1413 goto irq_ret_unlock
;
1416 iobase
= self
->io
.fir_base
;
1418 register_bank(iobase
, 0);
1419 iir
= inb(iobase
+IRCC_IIR
);
1421 goto irq_ret_unlock
;
1424 /* Disable interrupts */
1425 outb(0, iobase
+IRCC_IER
);
1426 lcra
= inb(iobase
+IRCC_LCR_A
);
1427 lsr
= inb(iobase
+IRCC_LSR
);
1429 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__
, iir
);
1431 if (iir
& IRCC_IIR_EOM
) {
1432 if (self
->io
.direction
== IO_RECV
)
1433 smsc_ircc_dma_receive_complete(self
, iobase
);
1435 smsc_ircc_dma_xmit_complete(self
, iobase
);
1437 smsc_ircc_dma_receive(self
, iobase
);
1440 if (iir
& IRCC_IIR_ACTIVE_FRAME
) {
1441 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1444 /* Enable interrupts again */
1446 register_bank(iobase
, 0);
1447 outb(IRCC_IER_ACTIVE_FRAME
|IRCC_IER_EOM
, iobase
+IRCC_IER
);
1450 spin_unlock(&self
->lock
);
1456 * Function irport_interrupt_sir (irq, dev_id, regs)
1458 * Interrupt handler for SIR modes
1460 static irqreturn_t
smsc_ircc_interrupt_sir(struct net_device
*dev
)
1462 struct smsc_ircc_cb
*self
= dev
->priv
;
1467 /* Already locked comming here in smsc_ircc_interrupt() */
1468 /*spin_lock(&self->lock);*/
1470 iobase
= self
->io
.sir_base
;
1472 iir
= inb(iobase
+UART_IIR
) & UART_IIR_ID
;
1476 /* Clear interrupt */
1477 lsr
= inb(iobase
+UART_LSR
);
1479 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
1480 __FUNCTION__
, iir
, lsr
, iobase
);
1484 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__
);
1487 /* Receive interrupt */
1488 smsc_ircc_sir_receive(self
);
1491 if (lsr
& UART_LSR_THRE
)
1492 /* Transmitter ready for data */
1493 smsc_ircc_sir_write_wakeup(self
);
1496 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1501 /* Make sure we don't stay here to long */
1502 if (boguscount
++ > 100)
1505 iir
= inb(iobase
+ UART_IIR
) & UART_IIR_ID
;
1507 /*spin_unlock(&self->lock);*/
1514 * Function ircc_is_receiving (self)
1516 * Return TRUE is we are currently receiving a frame
1519 static int ircc_is_receiving(struct smsc_ircc_cb
*self
)
1524 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
1526 IRDA_ASSERT(self
!= NULL
, return FALSE
;);
1528 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__
,
1529 get_dma_residue(self
->io
.dma
));
1531 status
= (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
1539 * Function smsc_ircc_net_open (dev)
1544 static int smsc_ircc_net_open(struct net_device
*dev
)
1546 struct smsc_ircc_cb
*self
;
1549 unsigned long flags
;
1551 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
1553 IRDA_ASSERT(dev
!= NULL
, return -1;);
1554 self
= (struct smsc_ircc_cb
*) dev
->priv
;
1555 IRDA_ASSERT(self
!= NULL
, return 0;);
1557 iobase
= self
->io
.fir_base
;
1559 if (request_irq(self
->io
.irq
, smsc_ircc_interrupt
, 0, dev
->name
,
1561 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1562 __FUNCTION__
, self
->io
.irq
);
1566 spin_lock_irqsave(&self
->lock
, flags
);
1567 /*smsc_ircc_sir_start(self);*/
1569 smsc_ircc_change_speed(self
, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED
);
1570 spin_unlock_irqrestore(&self
->lock
, flags
);
1572 /* Give self a hardware name */
1573 /* It would be cool to offer the chip revision here - Jean II */
1574 sprintf(hwname
, "SMSC @ 0x%03x", self
->io
.fir_base
);
1577 * Open new IrLAP layer instance, now that everything should be
1578 * initialized properly
1580 self
->irlap
= irlap_open(dev
, &self
->qos
, hwname
);
1583 * Always allocate the DMA channel after the IRQ,
1584 * and clean up on failure.
1586 if (request_dma(self
->io
.dma
, dev
->name
)) {
1587 smsc_ircc_net_close(dev
);
1589 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1590 __FUNCTION__
, self
->io
.dma
);
1594 netif_start_queue(dev
);
1600 * Function smsc_ircc_net_close (dev)
1605 static int smsc_ircc_net_close(struct net_device
*dev
)
1607 struct smsc_ircc_cb
*self
;
1610 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
1612 IRDA_ASSERT(dev
!= NULL
, return -1;);
1613 self
= (struct smsc_ircc_cb
*) dev
->priv
;
1614 IRDA_ASSERT(self
!= NULL
, return 0;);
1616 iobase
= self
->io
.fir_base
;
1619 netif_stop_queue(dev
);
1621 /* Stop and remove instance of IrLAP */
1623 irlap_close(self
->irlap
);
1626 free_irq(self
->io
.irq
, dev
);
1628 disable_dma(self
->io
.dma
);
1630 free_dma(self
->io
.dma
);
1636 static void smsc_ircc_suspend(struct smsc_ircc_cb
*self
)
1638 IRDA_MESSAGE("%s, Suspending\n", driver_name
);
1640 if (self
->io
.suspended
)
1643 smsc_ircc_net_close(self
->netdev
);
1645 self
->io
.suspended
= 1;
1648 static void smsc_ircc_wakeup(struct smsc_ircc_cb
*self
)
1650 if (!self
->io
.suspended
)
1653 /* The code was doing a "cli()" here, but this can't be right.
1654 * If you need protection, do it in net_open with a spinlock
1655 * or give a good reason. - Jean II */
1657 smsc_ircc_net_open(self
->netdev
);
1659 IRDA_MESSAGE("%s, Waking up\n", driver_name
);
1662 static int smsc_ircc_pmproc(struct pm_dev
*dev
, pm_request_t rqst
, void *data
)
1664 struct smsc_ircc_cb
*self
= (struct smsc_ircc_cb
*) dev
->data
;
1668 smsc_ircc_suspend(self
);
1671 smsc_ircc_wakeup(self
);
1679 * Function smsc_ircc_close (self)
1681 * Close driver instance
1684 static int __exit
smsc_ircc_close(struct smsc_ircc_cb
*self
)
1687 unsigned long flags
;
1689 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
1691 IRDA_ASSERT(self
!= NULL
, return -1;);
1693 iobase
= self
->io
.fir_base
;
1696 pm_unregister(self
->pmdev
);
1698 /* Remove netdevice */
1699 unregister_netdev(self
->netdev
);
1701 /* Make sure the irq handler is not exectuting */
1702 spin_lock_irqsave(&self
->lock
, flags
);
1704 /* Stop interrupts */
1705 register_bank(iobase
, 0);
1706 outb(0, iobase
+IRCC_IER
);
1707 outb(IRCC_MASTER_RESET
, iobase
+IRCC_MASTER
);
1708 outb(0x00, iobase
+IRCC_MASTER
);
1710 /* Reset to SIR mode */
1711 register_bank(iobase
, 1);
1712 outb(IRCC_CFGA_IRDA_SIR_A
|IRCC_CFGA_TX_POLARITY
, iobase
+IRCC_SCE_CFGA
);
1713 outb(IRCC_CFGB_IR
, iobase
+IRCC_SCE_CFGB
);
1715 spin_unlock_irqrestore(&self
->lock
, flags
);
1717 /* Release the PORTS that this driver is using */
1718 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__
,
1721 release_region(self
->io
.fir_base
, self
->io
.fir_ext
);
1723 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__
,
1726 release_region(self
->io
.sir_base
, self
->io
.sir_ext
);
1728 if (self
->tx_buff
.head
)
1729 dma_free_coherent(NULL
, self
->tx_buff
.truesize
,
1730 self
->tx_buff
.head
, self
->tx_buff_dma
);
1732 if (self
->rx_buff
.head
)
1733 dma_free_coherent(NULL
, self
->rx_buff
.truesize
,
1734 self
->rx_buff
.head
, self
->rx_buff_dma
);
1736 free_netdev(self
->netdev
);
1741 static void __exit
smsc_ircc_cleanup(void)
1745 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
1747 for (i
=0; i
< 2; i
++) {
1749 smsc_ircc_close(dev_self
[i
]);
1754 * Start SIR operations
1756 * This function *must* be called with spinlock held, because it may
1757 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1759 void smsc_ircc_sir_start(struct smsc_ircc_cb
*self
)
1761 struct net_device
*dev
;
1762 int fir_base
, sir_base
;
1764 IRDA_DEBUG(3, "%s\n", __FUNCTION__
);
1766 IRDA_ASSERT(self
!= NULL
, return;);
1768 IRDA_ASSERT(dev
!= NULL
, return;);
1769 dev
->hard_start_xmit
= &smsc_ircc_hard_xmit_sir
;
1771 fir_base
= self
->io
.fir_base
;
1772 sir_base
= self
->io
.sir_base
;
1774 /* Reset everything */
1775 outb(IRCC_MASTER_RESET
, fir_base
+IRCC_MASTER
);
1777 #if SMSC_IRCC2_C_SIR_STOP
1778 /*smsc_ircc_sir_stop(self);*/
1781 register_bank(fir_base
, 1);
1782 outb(((inb(fir_base
+IRCC_SCE_CFGA
) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK
) | IRCC_CFGA_IRDA_SIR_A
), fir_base
+IRCC_SCE_CFGA
);
1784 /* Initialize UART */
1785 outb(UART_LCR_WLEN8
, sir_base
+UART_LCR
); /* Reset DLAB */
1786 outb((UART_MCR_DTR
| UART_MCR_RTS
| UART_MCR_OUT2
), sir_base
+UART_MCR
);
1788 /* Turn on interrups */
1789 outb(UART_IER_RLSI
| UART_IER_RDI
|UART_IER_THRI
, sir_base
+UART_IER
);
1791 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__
);
1793 outb(0x00, fir_base
+IRCC_MASTER
);
1796 #if SMSC_IRCC2_C_SIR_STOP
1797 void smsc_ircc_sir_stop(struct smsc_ircc_cb
*self
)
1801 IRDA_DEBUG(3, "%s\n", __FUNCTION__
);
1802 iobase
= self
->io
.sir_base
;
1805 outb(0, iobase
+UART_MCR
);
1807 /* Turn off interrupts */
1808 outb(0, iobase
+UART_IER
);
1813 * Function smsc_sir_write_wakeup (self)
1815 * Called by the SIR interrupt handler when there's room for more data.
1816 * If we have more packets to send, we send them here.
1819 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb
*self
)
1825 IRDA_ASSERT(self
!= NULL
, return;);
1827 IRDA_DEBUG(4, "%s\n", __FUNCTION__
);
1829 iobase
= self
->io
.sir_base
;
1831 /* Finished with frame? */
1832 if (self
->tx_buff
.len
> 0) {
1833 /* Write data left in transmit buffer */
1834 actual
= smsc_ircc_sir_write(iobase
, self
->io
.fifo_size
,
1835 self
->tx_buff
.data
, self
->tx_buff
.len
);
1836 self
->tx_buff
.data
+= actual
;
1837 self
->tx_buff
.len
-= actual
;
1840 /*if (self->tx_buff.len ==0) {*/
1843 * Now serial buffer is almost free & we can start
1844 * transmission of another packet. But first we must check
1845 * if we need to change the speed of the hardware
1847 if (self
->new_speed
) {
1848 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1849 __FUNCTION__
, self
->new_speed
);
1850 smsc_ircc_sir_wait_hw_transmitter_finish(self
);
1851 smsc_ircc_change_speed(self
, self
->new_speed
);
1852 self
->new_speed
= 0;
1854 /* Tell network layer that we want more frames */
1855 netif_wake_queue(self
->netdev
);
1857 self
->stats
.tx_packets
++;
1859 if(self
->io
.speed
<= 115200) {
1861 * Reset Rx FIFO to make sure that all reflected transmit data
1862 * is discarded. This is needed for half duplex operation
1864 fcr
= UART_FCR_ENABLE_FIFO
| UART_FCR_CLEAR_RCVR
;
1865 if (self
->io
.speed
< 38400)
1866 fcr
|= UART_FCR_TRIGGER_1
;
1868 fcr
|= UART_FCR_TRIGGER_14
;
1870 outb(fcr
, iobase
+UART_FCR
);
1872 /* Turn on receive interrupts */
1873 outb(UART_IER_RDI
, iobase
+UART_IER
);
1879 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1881 * Fill Tx FIFO with transmit data
1884 static int smsc_ircc_sir_write(int iobase
, int fifo_size
, __u8
*buf
, int len
)
1888 /* Tx FIFO should be empty! */
1889 if (!(inb(iobase
+UART_LSR
) & UART_LSR_THRE
)) {
1890 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__
);
1894 /* Fill FIFO with current frame */
1895 while ((fifo_size
-- > 0) && (actual
< len
)) {
1896 /* Transmit next byte */
1897 outb(buf
[actual
], iobase
+UART_TX
);
1904 * Function smsc_ircc_is_receiving (self)
1906 * Returns true is we are currently receiving data
1909 static int smsc_ircc_is_receiving(struct smsc_ircc_cb
*self
)
1911 return (self
->rx_buff
.state
!= OUTSIDE_FRAME
);
1916 * Function smsc_ircc_probe_transceiver(self)
1918 * Tries to find the used Transceiver
1921 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb
*self
)
1925 IRDA_ASSERT(self
!= NULL
, return;);
1927 for(i
=0; smsc_transceivers
[i
].name
!=NULL
; i
++)
1928 if((*smsc_transceivers
[i
].probe
)(self
->io
.fir_base
)) {
1929 IRDA_MESSAGE(" %s transceiver found\n",
1930 smsc_transceivers
[i
].name
);
1931 self
->transceiver
= i
+1;
1934 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
1935 smsc_transceivers
[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER
].name
);
1937 self
->transceiver
= SMSC_IRCC2_C_DEFAULT_TRANSCEIVER
;
1942 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
1944 * Set the transceiver according to the speed
1947 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb
*self
, u32 speed
)
1951 trx
= self
->transceiver
;
1952 if(trx
>0) (*smsc_transceivers
[trx
-1].set_for_speed
)(self
->io
.fir_base
, speed
);
1956 * Function smsc_ircc_wait_hw_transmitter_finish ()
1958 * Wait for the real end of HW transmission
1960 * The UART is a strict FIFO, and we get called only when we have finished
1961 * pushing data to the FIFO, so the maximum amount of time we must wait
1962 * is only for the FIFO to drain out.
1964 * We use a simple calibrated loop. We may need to adjust the loop
1965 * delay (udelay) to balance I/O traffic and latency. And we also need to
1966 * adjust the maximum timeout.
1967 * It would probably be better to wait for the proper interrupt,
1968 * but it doesn't seem to be available.
1970 * We can't use jiffies or kernel timers because :
1971 * 1) We are called from the interrupt handler, which disable softirqs,
1972 * so jiffies won't be increased
1973 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
1974 * want to wait that long to detect stuck hardware.
1978 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb
*self
)
1981 int count
= SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US
;
1983 iobase
= self
->io
.sir_base
;
1985 /* Calibrated busy loop */
1986 while((count
-- > 0) && !(inb(iobase
+UART_LSR
) & UART_LSR_TEMT
))
1990 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__
);
1999 static int __init
smsc_ircc_look_for_chips(void)
2001 smsc_chip_address_t
*address
;
2003 unsigned int cfg_base
, found
;
2006 address
= possible_addresses
;
2008 while(address
->cfg_base
){
2009 cfg_base
= address
->cfg_base
;
2011 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
2013 if( address
->type
& SMSCSIO_TYPE_FDC
){
2015 if((address
->type
) & SMSCSIO_TYPE_FLAT
) {
2016 if(!smsc_superio_flat(fdc_chips_flat
,cfg_base
, type
)) found
++;
2018 if((address
->type
) & SMSCSIO_TYPE_PAGED
) {
2019 if(!smsc_superio_paged(fdc_chips_paged
,cfg_base
, type
)) found
++;
2022 if( address
->type
& SMSCSIO_TYPE_LPC
){
2024 if((address
->type
) & SMSCSIO_TYPE_FLAT
) {
2025 if(!smsc_superio_flat(lpc_chips_flat
,cfg_base
,type
)) found
++;
2027 if((address
->type
) & SMSCSIO_TYPE_PAGED
) {
2028 if(!smsc_superio_paged(lpc_chips_paged
,cfg_base
,"LPC")) found
++;
2037 * Function smsc_superio_flat (chip, base, type)
2039 * Try to get configuration of a smc SuperIO chip with flat register model
2042 static int __init
smsc_superio_flat(const smsc_chip_t
*chips
, unsigned short cfgbase
, char *type
)
2044 unsigned short firbase
, sirbase
;
2048 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
2050 if (smsc_ircc_probe(cfgbase
, SMSCSIOFLAT_DEVICEID_REG
, chips
, type
)==NULL
)
2053 outb(SMSCSIOFLAT_UARTMODE0C_REG
, cfgbase
);
2054 mode
= inb(cfgbase
+1);
2056 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
2058 if(!(mode
& SMSCSIOFLAT_UART2MODE_VAL_IRDA
))
2059 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__
);
2061 outb(SMSCSIOFLAT_UART2BASEADDR_REG
, cfgbase
);
2062 sirbase
= inb(cfgbase
+1) << 2;
2065 outb(SMSCSIOFLAT_FIRBASEADDR_REG
, cfgbase
);
2066 firbase
= inb(cfgbase
+1) << 3;
2069 outb(SMSCSIOFLAT_FIRDMASELECT_REG
, cfgbase
);
2070 dma
= inb(cfgbase
+1) & SMSCSIOFLAT_FIRDMASELECT_MASK
;
2073 outb(SMSCSIOFLAT_UARTIRQSELECT_REG
, cfgbase
);
2074 irq
= inb(cfgbase
+1) & SMSCSIOFLAT_UART2IRQSELECT_MASK
;
2076 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__
, firbase
, sirbase
, dma
, irq
, mode
);
2079 if (smsc_ircc_open(firbase
, sirbase
, dma
, irq
) == 0)
2083 /* Exit configuration */
2084 outb(SMSCSIO_CFGEXITKEY
, cfgbase
);
2090 * Function smsc_superio_paged (chip, base, type)
2092 * Try to get configuration of a smc SuperIO chip with paged register model
2095 static int __init
smsc_superio_paged(const smsc_chip_t
*chips
, unsigned short cfg_base
, char *type
)
2097 unsigned short fir_io
, sir_io
;
2100 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
2102 if (smsc_ircc_probe(cfg_base
,0x20,chips
,type
)==NULL
)
2105 /* Select logical device (UART2) */
2106 outb(0x07, cfg_base
);
2107 outb(0x05, cfg_base
+ 1);
2110 outb(0x60, cfg_base
);
2111 sir_io
= inb(cfg_base
+ 1) << 8;
2112 outb(0x61, cfg_base
);
2113 sir_io
|= inb(cfg_base
+ 1);
2116 outb(0x62, cfg_base
);
2117 fir_io
= inb(cfg_base
+ 1) << 8;
2118 outb(0x63, cfg_base
);
2119 fir_io
|= inb(cfg_base
+ 1);
2120 outb(0x2b, cfg_base
); /* ??? */
2123 if (smsc_ircc_open(fir_io
, sir_io
, ircc_dma
, ircc_irq
) == 0)
2127 /* Exit configuration */
2128 outb(SMSCSIO_CFGEXITKEY
, cfg_base
);
2134 static int __init
smsc_access(unsigned short cfg_base
,unsigned char reg
)
2136 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
2138 outb(reg
, cfg_base
);
2140 if (inb(cfg_base
)!=reg
)
2146 static const smsc_chip_t
* __init
smsc_ircc_probe(unsigned short cfg_base
,u8 reg
,const smsc_chip_t
*chip
,char *type
)
2148 u8 devid
,xdevid
,rev
;
2150 IRDA_DEBUG(1, "%s\n", __FUNCTION__
);
2152 /* Leave configuration */
2154 outb(SMSCSIO_CFGEXITKEY
, cfg_base
);
2156 if (inb(cfg_base
) == SMSCSIO_CFGEXITKEY
) /* not a smc superio chip */
2159 outb(reg
, cfg_base
);
2161 xdevid
=inb(cfg_base
+1);
2163 /* Enter configuration */
2165 outb(SMSCSIO_CFGACCESSKEY
, cfg_base
);
2168 if (smsc_access(cfg_base
,0x55)) /* send second key and check */
2172 /* probe device ID */
2174 if (smsc_access(cfg_base
,reg
))
2177 devid
=inb(cfg_base
+1);
2179 if (devid
==0) /* typical value for unused port */
2182 if (devid
==0xff) /* typical value for unused port */
2185 /* probe revision ID */
2187 if (smsc_access(cfg_base
,reg
+1))
2190 rev
=inb(cfg_base
+1);
2192 if (rev
>=128) /* i think this will make no sense */
2195 if (devid
==xdevid
) /* protection against false positives */
2198 /* Check for expected device ID; are there others? */
2200 while(chip
->devid
!=devid
) {
2204 if (chip
->name
==NULL
)
2208 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",devid
,rev
,cfg_base
,type
,chip
->name
);
2211 IRDA_MESSAGE("Revision higher than expected\n");
2215 if (chip
->flags
&NoIRDA
)
2216 IRDA_MESSAGE("chipset does not support IRDA\n");
2221 static int __init
smsc_superio_fdc(unsigned short cfg_base
)
2225 if (!request_region(cfg_base
, 2, driver_name
)) {
2226 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2227 __FUNCTION__
, cfg_base
);
2229 if (!smsc_superio_flat(fdc_chips_flat
,cfg_base
,"FDC")
2230 ||!smsc_superio_paged(fdc_chips_paged
,cfg_base
,"FDC"))
2233 release_region(cfg_base
, 2);
2239 static int __init
smsc_superio_lpc(unsigned short cfg_base
)
2243 if (!request_region(cfg_base
, 2, driver_name
)) {
2244 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2245 __FUNCTION__
, cfg_base
);
2247 if (!smsc_superio_flat(lpc_chips_flat
,cfg_base
,"LPC")
2248 ||!smsc_superio_paged(lpc_chips_paged
,cfg_base
,"LPC"))
2250 release_region(cfg_base
, 2);
2255 /************************************************
2257 * Transceivers specific functions
2259 ************************************************/
2263 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2265 * Program transceiver through smsc-ircc ATC circuitry
2269 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base
, u32 speed
)
2271 unsigned long jiffies_now
, jiffies_timeout
;
2274 jiffies_now
= jiffies
;
2275 jiffies_timeout
= jiffies
+SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES
;
2278 register_bank(fir_base
, 4);
2279 outb((inb(fir_base
+IRCC_ATC
) & IRCC_ATC_MASK
) |IRCC_ATC_nPROGREADY
|IRCC_ATC_ENABLE
, fir_base
+IRCC_ATC
);
2280 while((val
=(inb(fir_base
+IRCC_ATC
) & IRCC_ATC_nPROGREADY
)) && !time_after(jiffies
, jiffies_timeout
));
2282 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__
,
2283 inb(fir_base
+IRCC_ATC
));
2287 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2289 * Probe transceiver smsc-ircc ATC circuitry
2293 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base
)
2299 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2305 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base
, u32 speed
)
2317 fast_mode
= IRCC_LCR_A_FAST
;
2321 register_bank(fir_base
, 0);
2322 outb((inb(fir_base
+IRCC_LCR_A
) & 0xbf) | fast_mode
, fir_base
+IRCC_LCR_A
);
2326 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2332 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base
)
2338 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2344 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base
, u32 speed
)
2356 fast_mode
= /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA
;
2360 /* This causes an interrupt */
2361 register_bank(fir_base
, 0);
2362 outb((inb(fir_base
+IRCC_LCR_A
) & 0xbf) | fast_mode
, fir_base
+IRCC_LCR_A
);
2366 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2372 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base
)
2378 module_init(smsc_ircc_init
);
2379 module_exit(smsc_ircc_cleanup
);
2381 MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
2382 MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
2383 MODULE_LICENSE("GPL");
2385 module_param(ircc_dma
, int, 0);
2386 MODULE_PARM_DESC(ircc_dma
, "DMA channel");
2387 module_param(ircc_irq
, int, 0);
2388 MODULE_PARM_DESC(ircc_irq
, "IRQ line");
2389 module_param(ircc_fir
, int, 0);
2390 MODULE_PARM_DESC(ircc_fir
, "FIR Base Address");
2391 module_param(ircc_sir
, int, 0);
2392 MODULE_PARM_DESC(ircc_sir
, "SIR Base Address");
2393 module_param(ircc_cfg
, int, 0);
2394 MODULE_PARM_DESC(ircc_cfg
, "Configuration register base address");
2395 module_param(ircc_transceiver
, int, 0);
2396 MODULE_PARM_DESC(ircc_transceiver
, "Transceiver type");