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
14 * Copyright (c) 2006 Linus Walleij
17 * Based on smc-ircc.c:
19 * Copyright (c) 2001 Stefani Seibold
20 * Copyright (c) 1999-2001 Dag Brattli
21 * Copyright (c) 1998-1999 Thomas Davis,
25 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
28 * This program is free software; you can redistribute it and/or
29 * modify it under the terms of the GNU General Public License as
30 * published by the Free Software Foundation; either version 2 of
31 * the License, or (at your option) any later version.
33 * This program is distributed in the hope that it will be useful,
34 * but WITHOUT ANY WARRANTY; without even the implied warranty of
35 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
36 * GNU General Public License for more details.
38 * You should have received a copy of the GNU General Public License
39 * along with this program; if not, write to the Free Software
40 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
43 ********************************************************************/
45 #include <linux/module.h>
46 #include <linux/kernel.h>
47 #include <linux/types.h>
48 #include <linux/skbuff.h>
49 #include <linux/netdevice.h>
50 #include <linux/ioport.h>
51 #include <linux/delay.h>
52 #include <linux/slab.h>
53 #include <linux/init.h>
54 #include <linux/rtnetlink.h>
55 #include <linux/serial_reg.h>
56 #include <linux/dma-mapping.h>
57 #include <linux/pnp.h>
58 #include <linux/platform_device.h>
62 #include <asm/byteorder.h>
64 #include <linux/spinlock.h>
67 #include <linux/pci.h>
70 #include <net/irda/wrapper.h>
71 #include <net/irda/irda.h>
72 #include <net/irda/irda_device.h>
74 #include "smsc-ircc2.h"
78 MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
79 MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
80 MODULE_LICENSE("GPL");
83 static int ircc_dma = DMA_INVAL;
84 module_param(ircc_dma, int, 0);
85 MODULE_PARM_DESC(ircc_dma, "DMA channel");
88 static int ircc_irq = IRQ_INVAL;
89 module_param(ircc_irq, int, 0);
90 MODULE_PARM_DESC(ircc_irq, "IRQ line");
93 module_param(ircc_fir, int, 0);
94 MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
97 module_param(ircc_sir, int, 0);
98 MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
101 module_param(ircc_cfg, int, 0);
102 MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
104 static int ircc_transceiver;
105 module_param(ircc_transceiver, int, 0);
106 MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
111 struct smsc_ircc_subsystem_configuration {
112 unsigned short vendor; /* PCI vendor ID */
113 unsigned short device; /* PCI vendor ID */
114 unsigned short subvendor; /* PCI subsystem vendor ID */
115 unsigned short subdevice; /* PCI sybsystem device ID */
116 unsigned short sir_io; /* I/O port for SIR */
117 unsigned short fir_io; /* I/O port for FIR */
118 unsigned char fir_irq; /* FIR IRQ */
119 unsigned char fir_dma; /* FIR DMA */
120 unsigned short cfg_base; /* I/O port for chip configuration */
121 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
122 const char *name; /* name shown as info */
126 struct smsc_transceiver {
128 void (*set_for_speed)(int fir_base, u32 speed);
129 int (*probe)(int fir_base);
142 struct smsc_chip_address {
143 unsigned int cfg_base;
147 /* Private data for each instance */
148 struct smsc_ircc_cb {
149 struct net_device *netdev; /* Yes! we are some kind of netdevice */
150 struct net_device_stats stats;
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 int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
196 static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
197 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
198 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
199 static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
200 static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
201 static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id);
202 static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
203 static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
204 #if SMSC_IRCC2_C_SIR_STOP
205 static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
207 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
208 static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
209 static int smsc_ircc_net_open(struct net_device *dev);
210 static int smsc_ircc_net_close(struct net_device *dev);
211 static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
212 #if SMSC_IRCC2_C_NET_TIMEOUT
213 static void smsc_ircc_timeout(struct net_device *dev);
215 static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
216 static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
217 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
218 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
219 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
222 static int __init smsc_ircc_look_for_chips(void);
223 static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
224 static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
225 static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
226 static int __init smsc_superio_fdc(unsigned short cfg_base);
227 static int __init smsc_superio_lpc(unsigned short cfg_base);
229 static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
230 static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
231 static void __init preconfigure_ali_port(struct pci_dev *dev,
232 unsigned short port);
233 static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
234 static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
235 unsigned short ircc_fir,
236 unsigned short ircc_sir,
237 unsigned char ircc_dma,
238 unsigned char ircc_irq);
241 /* Transceivers specific functions */
243 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
244 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
245 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
246 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
247 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
248 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
250 /* Power Management */
252 static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
253 static int smsc_ircc_resume(struct platform_device *dev);
255 static struct platform_driver smsc_ircc_driver = {
256 .suspend = smsc_ircc_suspend,
257 .resume = smsc_ircc_resume,
259 .name = SMSC_IRCC2_DRIVER_NAME,
263 /* Transceivers for SMSC-ircc */
265 static struct smsc_transceiver smsc_transceivers[] =
267 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
268 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
269 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
272 #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
274 /* SMC SuperIO chipsets definitions */
276 #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
277 #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
278 #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
279 #define SIR 0 /* SuperIO Chip has only slow IRDA */
280 #define FIR 4 /* SuperIO Chip has fast IRDA */
281 #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
283 static struct smsc_chip __initdata fdc_chips_flat[] =
285 /* Base address 0x3f0 or 0x370 */
286 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
287 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
288 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
289 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
290 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
291 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
292 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
293 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
297 static struct smsc_chip __initdata fdc_chips_paged[] =
299 /* Base address 0x3f0 or 0x370 */
300 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
301 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
302 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
303 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
304 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
305 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
306 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
307 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
308 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
309 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
310 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
311 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
312 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
316 static struct smsc_chip __initdata lpc_chips_flat[] =
318 /* Base address 0x2E or 0x4E */
319 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
320 { "47N227", KEY55_1|FIR|SERx4, 0x7a, 0x00 },
321 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
325 static struct smsc_chip __initdata lpc_chips_paged[] =
327 /* Base address 0x2E or 0x4E */
328 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
329 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
330 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
331 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
332 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
333 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
334 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
335 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
339 #define SMSCSIO_TYPE_FDC 1
340 #define SMSCSIO_TYPE_LPC 2
341 #define SMSCSIO_TYPE_FLAT 4
342 #define SMSCSIO_TYPE_PAGED 8
344 static struct smsc_chip_address __initdata possible_addresses[] =
346 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
347 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
348 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
349 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
350 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
356 static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
357 static unsigned short dev_count;
359 static inline void register_bank(int iobase, int bank)
361 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
362 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);
376 /*******************************************************************************
382 *******************************************************************************/
385 * Function smsc_ircc_init ()
387 * Initialize chip. Just try to find out how many chips we are dealing with
390 static int __init smsc_ircc_init(void)
394 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
396 ret = platform_driver_register(&smsc_ircc_driver);
398 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
403 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
404 /* Ignore errors from preconfiguration */
405 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
411 if (ircc_fir > 0 && ircc_sir > 0) {
412 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
413 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
415 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
420 /* try user provided configuration register base address */
422 IRDA_MESSAGE(" Overriding configuration address "
423 "0x%04x\n", ircc_cfg);
424 if (!smsc_superio_fdc(ircc_cfg))
426 if (!smsc_superio_lpc(ircc_cfg))
430 if (smsc_ircc_look_for_chips() > 0)
435 platform_driver_unregister(&smsc_ircc_driver);
441 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
443 * Try to open driver instance
446 static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
448 struct smsc_ircc_cb *self;
449 struct net_device *dev;
452 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
454 err = smsc_ircc_present(fir_base, sir_base);
459 if (dev_count >= ARRAY_SIZE(dev_self)) {
460 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
465 * Allocate new instance of the driver
467 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
469 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
473 SET_MODULE_OWNER(dev);
475 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
476 #if SMSC_IRCC2_C_NET_TIMEOUT
477 dev->tx_timeout = smsc_ircc_timeout;
478 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
480 dev->open = smsc_ircc_net_open;
481 dev->stop = smsc_ircc_net_close;
482 dev->do_ioctl = smsc_ircc_net_ioctl;
483 dev->get_stats = smsc_ircc_net_get_stats;
485 self = netdev_priv(dev);
488 /* Make ifconfig display some details */
489 dev->base_addr = self->io.fir_base = fir_base;
490 dev->irq = self->io.irq = irq;
492 /* Need to store self somewhere */
493 dev_self[dev_count] = self;
494 spin_lock_init(&self->lock);
496 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
497 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
500 dma_alloc_coherent(NULL, self->rx_buff.truesize,
501 &self->rx_buff_dma, GFP_KERNEL);
502 if (self->rx_buff.head == NULL) {
503 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
509 dma_alloc_coherent(NULL, self->tx_buff.truesize,
510 &self->tx_buff_dma, GFP_KERNEL);
511 if (self->tx_buff.head == NULL) {
512 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
517 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
518 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
520 self->rx_buff.in_frame = FALSE;
521 self->rx_buff.state = OUTSIDE_FRAME;
522 self->tx_buff.data = self->tx_buff.head;
523 self->rx_buff.data = self->rx_buff.head;
525 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
526 smsc_ircc_setup_qos(self);
527 smsc_ircc_init_chip(self);
529 if (ircc_transceiver > 0 &&
530 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
531 self->transceiver = ircc_transceiver;
533 smsc_ircc_probe_transceiver(self);
535 err = register_netdev(self->netdev);
537 IRDA_ERROR("%s, Network device registration failed!\n",
542 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
544 if (IS_ERR(self->pldev)) {
545 err = PTR_ERR(self->pldev);
548 platform_set_drvdata(self->pldev, self);
550 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
556 unregister_netdev(self->netdev);
559 dma_free_coherent(NULL, self->tx_buff.truesize,
560 self->tx_buff.head, self->tx_buff_dma);
562 dma_free_coherent(NULL, self->rx_buff.truesize,
563 self->rx_buff.head, self->rx_buff_dma);
565 free_netdev(self->netdev);
566 dev_self[dev_count] = NULL;
568 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
569 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
575 * Function smsc_ircc_present(fir_base, sir_base)
577 * Check the smsc-ircc chip presence
580 static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
582 unsigned char low, high, chip, config, dma, irq, version;
584 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
586 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
587 __FUNCTION__, fir_base);
591 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
593 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
594 __FUNCTION__, sir_base);
598 register_bank(fir_base, 3);
600 high = inb(fir_base + IRCC_ID_HIGH);
601 low = inb(fir_base + IRCC_ID_LOW);
602 chip = inb(fir_base + IRCC_CHIP_ID);
603 version = inb(fir_base + IRCC_VERSION);
604 config = inb(fir_base + IRCC_INTERFACE);
605 dma = config & IRCC_INTERFACE_DMA_MASK;
606 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
608 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
609 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
610 __FUNCTION__, fir_base);
613 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
614 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
615 chip & 0x0f, version, fir_base, sir_base, dma, irq);
620 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
622 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
628 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
633 static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
634 unsigned int fir_base, unsigned int sir_base,
637 unsigned char config, chip_dma, chip_irq;
639 register_bank(fir_base, 3);
640 config = inb(fir_base + IRCC_INTERFACE);
641 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
642 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
644 self->io.fir_base = fir_base;
645 self->io.sir_base = sir_base;
646 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
647 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
648 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
649 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
651 if (irq != IRQ_INVAL) {
653 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
654 driver_name, chip_irq, irq);
657 self->io.irq = chip_irq;
659 if (dma != DMA_INVAL) {
661 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
662 driver_name, chip_dma, dma);
665 self->io.dma = chip_dma;
670 * Function smsc_ircc_setup_qos(self)
675 static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
677 /* Initialize QoS for this device */
678 irda_init_max_qos_capabilies(&self->qos);
680 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
681 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
683 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
684 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
685 irda_qos_bits_to_value(&self->qos);
689 * Function smsc_ircc_init_chip(self)
694 static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
696 int iobase = self->io.fir_base;
698 register_bank(iobase, 0);
699 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
700 outb(0x00, iobase + IRCC_MASTER);
702 register_bank(iobase, 1);
703 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
704 iobase + IRCC_SCE_CFGA);
706 #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
707 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
708 iobase + IRCC_SCE_CFGB);
710 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
711 iobase + IRCC_SCE_CFGB);
713 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
714 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
716 register_bank(iobase, 4);
717 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
719 register_bank(iobase, 0);
720 outb(0, iobase + IRCC_LCR_A);
722 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
724 /* Power on device */
725 outb(0x00, iobase + IRCC_MASTER);
729 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
731 * Process IOCTL commands for this device
734 static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
736 struct if_irda_req *irq = (struct if_irda_req *) rq;
737 struct smsc_ircc_cb *self;
741 IRDA_ASSERT(dev != NULL, return -1;);
743 self = netdev_priv(dev);
745 IRDA_ASSERT(self != NULL, return -1;);
747 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
750 case SIOCSBANDWIDTH: /* Set bandwidth */
751 if (!capable(CAP_NET_ADMIN))
754 /* Make sure we are the only one touching
755 * self->io.speed and the hardware - Jean II */
756 spin_lock_irqsave(&self->lock, flags);
757 smsc_ircc_change_speed(self, irq->ifr_baudrate);
758 spin_unlock_irqrestore(&self->lock, flags);
761 case SIOCSMEDIABUSY: /* Set media busy */
762 if (!capable(CAP_NET_ADMIN)) {
767 irda_device_set_media_busy(self->netdev, TRUE);
769 case SIOCGRECEIVING: /* Check if we are receiving right now */
770 irq->ifr_receiving = smsc_ircc_is_receiving(self);
774 if (!capable(CAP_NET_ADMIN)) {
778 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
788 static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
790 struct smsc_ircc_cb *self = netdev_priv(dev);
795 #if SMSC_IRCC2_C_NET_TIMEOUT
797 * Function smsc_ircc_timeout (struct net_device *dev)
799 * The networking timeout management.
803 static void smsc_ircc_timeout(struct net_device *dev)
805 struct smsc_ircc_cb *self = netdev_priv(dev);
808 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
809 dev->name, self->io.speed);
810 spin_lock_irqsave(&self->lock, flags);
811 smsc_ircc_sir_start(self);
812 smsc_ircc_change_speed(self, self->io.speed);
813 dev->trans_start = jiffies;
814 netif_wake_queue(dev);
815 spin_unlock_irqrestore(&self->lock, flags);
820 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
822 * Transmits the current frame until FIFO is full, then
823 * waits until the next transmit interrupt, and continues until the
824 * frame is transmitted.
826 int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
828 struct smsc_ircc_cb *self;
832 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
834 IRDA_ASSERT(dev != NULL, return 0;);
836 self = netdev_priv(dev);
837 IRDA_ASSERT(self != NULL, return 0;);
839 netif_stop_queue(dev);
841 /* Make sure test of self->io.speed & speed change are atomic */
842 spin_lock_irqsave(&self->lock, flags);
844 /* Check if we need to change the speed */
845 speed = irda_get_next_speed(skb);
846 if (speed != self->io.speed && speed != -1) {
847 /* Check for empty frame */
850 * We send frames one by one in SIR mode (no
851 * pipelining), so at this point, if we were sending
852 * a previous frame, we just received the interrupt
853 * telling us it is finished (UART_IIR_THRI).
854 * Therefore, waiting for the transmitter to really
855 * finish draining the fifo won't take too long.
856 * And the interrupt handler is not expected to run.
858 smsc_ircc_sir_wait_hw_transmitter_finish(self);
859 smsc_ircc_change_speed(self, speed);
860 spin_unlock_irqrestore(&self->lock, flags);
864 self->new_speed = speed;
868 self->tx_buff.data = self->tx_buff.head;
870 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
871 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
872 self->tx_buff.truesize);
874 self->stats.tx_bytes += self->tx_buff.len;
876 /* Turn on transmit finished interrupt. Will fire immediately! */
877 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
879 spin_unlock_irqrestore(&self->lock, flags);
887 * Function smsc_ircc_set_fir_speed (self, baud)
889 * Change the speed of the device
892 static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
894 int fir_base, ir_mode, ctrl, fast;
896 IRDA_ASSERT(self != NULL, return;);
897 fir_base = self->io.fir_base;
899 self->io.speed = speed;
904 ir_mode = IRCC_CFGA_IRDA_HDLC;
907 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
910 ir_mode = IRCC_CFGA_IRDA_HDLC;
911 ctrl = IRCC_1152 | IRCC_CRC;
912 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
913 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
917 ir_mode = IRCC_CFGA_IRDA_4PPM;
919 fast = IRCC_LCR_A_FAST;
920 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
926 /* This causes an interrupt */
927 register_bank(fir_base, 0);
928 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
931 register_bank(fir_base, 1);
932 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
934 register_bank(fir_base, 4);
935 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
939 * Function smsc_ircc_fir_start(self)
941 * Change the speed of the device
944 static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
946 struct net_device *dev;
949 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
951 IRDA_ASSERT(self != NULL, return;);
953 IRDA_ASSERT(dev != NULL, return;);
955 fir_base = self->io.fir_base;
957 /* Reset everything */
959 /* Install FIR transmit handler */
960 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
963 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
965 /* Enable interrupt */
966 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
968 register_bank(fir_base, 1);
970 /* Select the TX/RX interface */
971 #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
972 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
973 fir_base + IRCC_SCE_CFGB);
975 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
976 fir_base + IRCC_SCE_CFGB);
978 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
980 /* Enable SCE interrupts */
981 outb(0, fir_base + IRCC_MASTER);
982 register_bank(fir_base, 0);
983 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
984 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
988 * Function smsc_ircc_fir_stop(self, baud)
990 * Change the speed of the device
993 static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
997 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
999 IRDA_ASSERT(self != NULL, return;);
1001 fir_base = self->io.fir_base;
1002 register_bank(fir_base, 0);
1003 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1004 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
1009 * Function smsc_ircc_change_speed(self, baud)
1011 * Change the speed of the device
1013 * This function *must* be called with spinlock held, because it may
1014 * be called from the irq handler. - Jean II
1016 static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
1018 struct net_device *dev;
1019 int last_speed_was_sir;
1021 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
1023 IRDA_ASSERT(self != NULL, return;);
1026 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1031 self->io.speed = speed;
1032 last_speed_was_sir = 0;
1033 smsc_ircc_fir_start(self);
1036 if (self->io.speed == 0)
1037 smsc_ircc_sir_start(self);
1040 if (!last_speed_was_sir) speed = self->io.speed;
1043 if (self->io.speed != speed)
1044 smsc_ircc_set_transceiver_for_speed(self, speed);
1046 self->io.speed = speed;
1048 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1049 if (!last_speed_was_sir) {
1050 smsc_ircc_fir_stop(self);
1051 smsc_ircc_sir_start(self);
1053 smsc_ircc_set_sir_speed(self, speed);
1055 if (last_speed_was_sir) {
1056 #if SMSC_IRCC2_C_SIR_STOP
1057 smsc_ircc_sir_stop(self);
1059 smsc_ircc_fir_start(self);
1061 smsc_ircc_set_fir_speed(self, speed);
1064 self->tx_buff.len = 10;
1065 self->tx_buff.data = self->tx_buff.head;
1067 smsc_ircc_dma_xmit(self, 4000);
1069 /* Be ready for incoming frames */
1070 smsc_ircc_dma_receive(self);
1073 netif_wake_queue(dev);
1077 * Function smsc_ircc_set_sir_speed (self, speed)
1079 * Set speed of IrDA port to specified baudrate
1082 void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
1085 int fcr; /* FIFO control reg */
1086 int lcr; /* Line control reg */
1089 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1091 IRDA_ASSERT(self != NULL, return;);
1092 iobase = self->io.sir_base;
1094 /* Update accounting for new speed */
1095 self->io.speed = speed;
1097 /* Turn off interrupts */
1098 outb(0, iobase + UART_IER);
1100 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
1102 fcr = UART_FCR_ENABLE_FIFO;
1105 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1106 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1107 * about this timeout since it will always be fast enough.
1109 fcr |= self->io.speed < 38400 ?
1110 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1112 /* IrDA ports use 8N1 */
1113 lcr = UART_LCR_WLEN8;
1115 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1116 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1117 outb(divisor >> 8, iobase + UART_DLM);
1118 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1119 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
1121 /* Turn on interrups */
1122 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
1124 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1129 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1131 * Transmit the frame!
1134 static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1136 struct smsc_ircc_cb *self;
1137 unsigned long flags;
1141 IRDA_ASSERT(dev != NULL, return 0;);
1142 self = netdev_priv(dev);
1143 IRDA_ASSERT(self != NULL, return 0;);
1145 netif_stop_queue(dev);
1147 /* Make sure test of self->io.speed & speed change are atomic */
1148 spin_lock_irqsave(&self->lock, flags);
1150 /* Check if we need to change the speed after this frame */
1151 speed = irda_get_next_speed(skb);
1152 if (speed != self->io.speed && speed != -1) {
1153 /* Check for empty frame */
1155 /* Note : you should make sure that speed changes
1156 * are not going to corrupt any outgoing frame.
1157 * Look at nsc-ircc for the gory details - Jean II */
1158 smsc_ircc_change_speed(self, speed);
1159 spin_unlock_irqrestore(&self->lock, flags);
1164 self->new_speed = speed;
1167 skb_copy_from_linear_data(skb, self->tx_buff.head, skb->len);
1169 self->tx_buff.len = skb->len;
1170 self->tx_buff.data = self->tx_buff.head;
1172 mtt = irda_get_mtt(skb);
1177 * Compute how many BOFs (STA or PA's) we need to waste the
1178 * min turn time given the speed of the link.
1180 bofs = mtt * (self->io.speed / 1000) / 8000;
1184 smsc_ircc_dma_xmit(self, bofs);
1186 /* Transmit frame */
1187 smsc_ircc_dma_xmit(self, 0);
1190 spin_unlock_irqrestore(&self->lock, flags);
1197 * Function smsc_ircc_dma_xmit (self, bofs)
1199 * Transmit data using DMA
1202 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
1204 int iobase = self->io.fir_base;
1207 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1210 register_bank(iobase, 0);
1211 outb(0x00, iobase + IRCC_LCR_B);
1213 register_bank(iobase, 1);
1214 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1215 iobase + IRCC_SCE_CFGB);
1217 self->io.direction = IO_XMIT;
1219 /* Set BOF additional count for generating the min turn time */
1220 register_bank(iobase, 4);
1221 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1222 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1223 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
1225 /* Set max Tx frame size */
1226 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1227 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
1229 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1231 /* Enable burst mode chip Tx DMA */
1232 register_bank(iobase, 1);
1233 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1234 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1236 /* Setup DMA controller (must be done after enabling chip DMA) */
1237 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1240 /* Enable interrupt */
1242 register_bank(iobase, 0);
1243 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1244 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1246 /* Enable transmit */
1247 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
1251 * Function smsc_ircc_dma_xmit_complete (self)
1253 * The transfer of a frame in finished. This function will only be called
1254 * by the interrupt handler
1257 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
1259 int iobase = self->io.fir_base;
1261 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1264 register_bank(iobase, 0);
1265 outb(0x00, iobase + IRCC_LCR_B);
1267 register_bank(iobase, 1);
1268 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1269 iobase + IRCC_SCE_CFGB);
1271 /* Check for underrun! */
1272 register_bank(iobase, 0);
1273 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
1274 self->stats.tx_errors++;
1275 self->stats.tx_fifo_errors++;
1277 /* Reset error condition */
1278 register_bank(iobase, 0);
1279 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1280 outb(0x00, iobase + IRCC_MASTER);
1282 self->stats.tx_packets++;
1283 self->stats.tx_bytes += self->tx_buff.len;
1286 /* Check if it's time to change the speed */
1287 if (self->new_speed) {
1288 smsc_ircc_change_speed(self, self->new_speed);
1289 self->new_speed = 0;
1292 netif_wake_queue(self->netdev);
1296 * Function smsc_ircc_dma_receive(self)
1298 * Get ready for receiving a frame. The device will initiate a DMA
1299 * if it starts to receive a frame.
1302 static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
1304 int iobase = self->io.fir_base;
1306 /* Turn off chip DMA */
1307 register_bank(iobase, 1);
1308 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1309 iobase + IRCC_SCE_CFGB);
1313 register_bank(iobase, 0);
1314 outb(0x00, iobase + IRCC_LCR_B);
1316 /* Turn off chip DMA */
1317 register_bank(iobase, 1);
1318 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1319 iobase + IRCC_SCE_CFGB);
1321 self->io.direction = IO_RECV;
1322 self->rx_buff.data = self->rx_buff.head;
1324 /* Set max Rx frame size */
1325 register_bank(iobase, 4);
1326 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1327 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
1329 /* Setup DMA controller */
1330 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1333 /* Enable burst mode chip Rx DMA */
1334 register_bank(iobase, 1);
1335 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1336 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1338 /* Enable interrupt */
1339 register_bank(iobase, 0);
1340 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1341 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1343 /* Enable receiver */
1344 register_bank(iobase, 0);
1345 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
1346 iobase + IRCC_LCR_B);
1352 * Function smsc_ircc_dma_receive_complete(self)
1354 * Finished with receiving frames
1357 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
1359 struct sk_buff *skb;
1360 int len, msgcnt, lsr;
1361 int iobase = self->io.fir_base;
1363 register_bank(iobase, 0);
1365 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1368 register_bank(iobase, 0);
1369 outb(0x00, iobase + IRCC_LCR_B);
1371 register_bank(iobase, 0);
1372 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1373 lsr= inb(iobase + IRCC_LSR);
1374 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
1376 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1377 get_dma_residue(self->io.dma));
1379 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1381 /* Look for errors */
1382 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
1383 self->stats.rx_errors++;
1384 if (lsr & IRCC_LSR_FRAME_ERROR)
1385 self->stats.rx_frame_errors++;
1386 if (lsr & IRCC_LSR_CRC_ERROR)
1387 self->stats.rx_crc_errors++;
1388 if (lsr & IRCC_LSR_SIZE_ERROR)
1389 self->stats.rx_length_errors++;
1390 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1391 self->stats.rx_length_errors++;
1396 len -= self->io.speed < 4000000 ? 2 : 4;
1398 if (len < 2 || len > 2050) {
1399 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1402 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1404 skb = dev_alloc_skb(len + 1);
1406 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1410 /* Make sure IP header gets aligned */
1411 skb_reserve(skb, 1);
1413 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1414 self->stats.rx_packets++;
1415 self->stats.rx_bytes += len;
1417 skb->dev = self->netdev;
1418 skb_reset_mac_header(skb);
1419 skb->protocol = htons(ETH_P_IRDA);
1424 * Function smsc_ircc_sir_receive (self)
1426 * Receive one frame from the infrared port
1429 static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
1434 IRDA_ASSERT(self != NULL, return;);
1436 iobase = self->io.sir_base;
1439 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1440 * async_unwrap_char will deliver all found frames
1443 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
1444 inb(iobase + UART_RX));
1446 /* Make sure we don't stay here to long */
1447 if (boguscount++ > 32) {
1448 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1451 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
1456 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1458 * An interrupt from the chip has arrived. Time to do some work
1461 static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id)
1463 struct net_device *dev = (struct net_device *) dev_id;
1464 struct smsc_ircc_cb *self;
1465 int iobase, iir, lcra, lsr;
1466 irqreturn_t ret = IRQ_NONE;
1469 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
1474 self = netdev_priv(dev);
1475 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1477 /* Serialise the interrupt handler in various CPUs, stop Tx path */
1478 spin_lock(&self->lock);
1480 /* Check if we should use the SIR interrupt handler */
1481 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1482 ret = smsc_ircc_interrupt_sir(dev);
1483 goto irq_ret_unlock;
1486 iobase = self->io.fir_base;
1488 register_bank(iobase, 0);
1489 iir = inb(iobase + IRCC_IIR);
1491 goto irq_ret_unlock;
1494 /* Disable interrupts */
1495 outb(0, iobase + IRCC_IER);
1496 lcra = inb(iobase + IRCC_LCR_A);
1497 lsr = inb(iobase + IRCC_LSR);
1499 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1501 if (iir & IRCC_IIR_EOM) {
1502 if (self->io.direction == IO_RECV)
1503 smsc_ircc_dma_receive_complete(self);
1505 smsc_ircc_dma_xmit_complete(self);
1507 smsc_ircc_dma_receive(self);
1510 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1511 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1514 /* Enable interrupts again */
1516 register_bank(iobase, 0);
1517 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1520 spin_unlock(&self->lock);
1526 * Function irport_interrupt_sir (irq, dev_id)
1528 * Interrupt handler for SIR modes
1530 static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1532 struct smsc_ircc_cb *self = netdev_priv(dev);
1537 /* Already locked comming here in smsc_ircc_interrupt() */
1538 /*spin_lock(&self->lock);*/
1540 iobase = self->io.sir_base;
1542 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1546 /* Clear interrupt */
1547 lsr = inb(iobase + UART_LSR);
1549 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
1550 __FUNCTION__, iir, lsr, iobase);
1554 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1557 /* Receive interrupt */
1558 smsc_ircc_sir_receive(self);
1561 if (lsr & UART_LSR_THRE)
1562 /* Transmitter ready for data */
1563 smsc_ircc_sir_write_wakeup(self);
1566 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1571 /* Make sure we don't stay here to long */
1572 if (boguscount++ > 100)
1575 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1577 /*spin_unlock(&self->lock);*/
1584 * Function ircc_is_receiving (self)
1586 * Return TRUE is we are currently receiving a frame
1589 static int ircc_is_receiving(struct smsc_ircc_cb *self)
1594 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1596 IRDA_ASSERT(self != NULL, return FALSE;);
1598 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1599 get_dma_residue(self->io.dma));
1601 status = (self->rx_buff.state != OUTSIDE_FRAME);
1607 static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1611 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1612 self->netdev->name, self->netdev);
1614 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
1615 __FUNCTION__, self->io.irq, error);
1620 static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1622 unsigned long flags;
1624 spin_lock_irqsave(&self->lock, flags);
1627 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1629 spin_unlock_irqrestore(&self->lock, flags);
1632 static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1634 int iobase = self->io.fir_base;
1635 unsigned long flags;
1637 spin_lock_irqsave(&self->lock, flags);
1639 register_bank(iobase, 0);
1640 outb(0, iobase + IRCC_IER);
1641 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1642 outb(0x00, iobase + IRCC_MASTER);
1644 spin_unlock_irqrestore(&self->lock, flags);
1649 * Function smsc_ircc_net_open (dev)
1654 static int smsc_ircc_net_open(struct net_device *dev)
1656 struct smsc_ircc_cb *self;
1659 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1661 IRDA_ASSERT(dev != NULL, return -1;);
1662 self = netdev_priv(dev);
1663 IRDA_ASSERT(self != NULL, return 0;);
1665 if (self->io.suspended) {
1666 IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
1670 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
1672 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1673 __FUNCTION__, self->io.irq);
1677 smsc_ircc_start_interrupts(self);
1679 /* Give self a hardware name */
1680 /* It would be cool to offer the chip revision here - Jean II */
1681 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1684 * Open new IrLAP layer instance, now that everything should be
1685 * initialized properly
1687 self->irlap = irlap_open(dev, &self->qos, hwname);
1690 * Always allocate the DMA channel after the IRQ,
1691 * and clean up on failure.
1693 if (request_dma(self->io.dma, dev->name)) {
1694 smsc_ircc_net_close(dev);
1696 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1697 __FUNCTION__, self->io.dma);
1701 netif_start_queue(dev);
1707 * Function smsc_ircc_net_close (dev)
1712 static int smsc_ircc_net_close(struct net_device *dev)
1714 struct smsc_ircc_cb *self;
1716 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1718 IRDA_ASSERT(dev != NULL, return -1;);
1719 self = netdev_priv(dev);
1720 IRDA_ASSERT(self != NULL, return 0;);
1723 netif_stop_queue(dev);
1725 /* Stop and remove instance of IrLAP */
1727 irlap_close(self->irlap);
1730 smsc_ircc_stop_interrupts(self);
1732 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1733 if (!self->io.suspended)
1734 free_irq(self->io.irq, dev);
1736 disable_dma(self->io.dma);
1737 free_dma(self->io.dma);
1742 static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
1744 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
1746 if (!self->io.suspended) {
1747 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1750 if (netif_running(self->netdev)) {
1751 netif_device_detach(self->netdev);
1752 smsc_ircc_stop_interrupts(self);
1753 free_irq(self->io.irq, self->netdev);
1754 disable_dma(self->io.dma);
1756 self->io.suspended = 1;
1763 static int smsc_ircc_resume(struct platform_device *dev)
1765 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
1767 if (self->io.suspended) {
1768 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
1771 smsc_ircc_init_chip(self);
1772 if (netif_running(self->netdev)) {
1773 if (smsc_ircc_request_irq(self)) {
1775 * Don't fail resume process, just kill this
1778 unregister_netdevice(self->netdev);
1780 enable_dma(self->io.dma);
1781 smsc_ircc_start_interrupts(self);
1782 netif_device_attach(self->netdev);
1785 self->io.suspended = 0;
1792 * Function smsc_ircc_close (self)
1794 * Close driver instance
1797 static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1799 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1801 IRDA_ASSERT(self != NULL, return -1;);
1803 platform_device_unregister(self->pldev);
1805 /* Remove netdevice */
1806 unregister_netdev(self->netdev);
1808 smsc_ircc_stop_interrupts(self);
1810 /* Release the PORTS that this driver is using */
1811 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1814 release_region(self->io.fir_base, self->io.fir_ext);
1816 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1819 release_region(self->io.sir_base, self->io.sir_ext);
1821 if (self->tx_buff.head)
1822 dma_free_coherent(NULL, self->tx_buff.truesize,
1823 self->tx_buff.head, self->tx_buff_dma);
1825 if (self->rx_buff.head)
1826 dma_free_coherent(NULL, self->rx_buff.truesize,
1827 self->rx_buff.head, self->rx_buff_dma);
1829 free_netdev(self->netdev);
1834 static void __exit smsc_ircc_cleanup(void)
1838 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1840 for (i = 0; i < 2; i++) {
1842 smsc_ircc_close(dev_self[i]);
1845 platform_driver_unregister(&smsc_ircc_driver);
1849 * Start SIR operations
1851 * This function *must* be called with spinlock held, because it may
1852 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1854 void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1856 struct net_device *dev;
1857 int fir_base, sir_base;
1859 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1861 IRDA_ASSERT(self != NULL, return;);
1863 IRDA_ASSERT(dev != NULL, return;);
1864 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1866 fir_base = self->io.fir_base;
1867 sir_base = self->io.sir_base;
1869 /* Reset everything */
1870 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
1872 #if SMSC_IRCC2_C_SIR_STOP
1873 /*smsc_ircc_sir_stop(self);*/
1876 register_bank(fir_base, 1);
1877 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
1879 /* Initialize UART */
1880 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1881 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
1883 /* Turn on interrups */
1884 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
1886 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1888 outb(0x00, fir_base + IRCC_MASTER);
1891 #if SMSC_IRCC2_C_SIR_STOP
1892 void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1896 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1897 iobase = self->io.sir_base;
1900 outb(0, iobase + UART_MCR);
1902 /* Turn off interrupts */
1903 outb(0, iobase + UART_IER);
1908 * Function smsc_sir_write_wakeup (self)
1910 * Called by the SIR interrupt handler when there's room for more data.
1911 * If we have more packets to send, we send them here.
1914 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1920 IRDA_ASSERT(self != NULL, return;);
1922 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1924 iobase = self->io.sir_base;
1926 /* Finished with frame? */
1927 if (self->tx_buff.len > 0) {
1928 /* Write data left in transmit buffer */
1929 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
1930 self->tx_buff.data, self->tx_buff.len);
1931 self->tx_buff.data += actual;
1932 self->tx_buff.len -= actual;
1935 /*if (self->tx_buff.len ==0) {*/
1938 * Now serial buffer is almost free & we can start
1939 * transmission of another packet. But first we must check
1940 * if we need to change the speed of the hardware
1942 if (self->new_speed) {
1943 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1944 __FUNCTION__, self->new_speed);
1945 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1946 smsc_ircc_change_speed(self, self->new_speed);
1947 self->new_speed = 0;
1949 /* Tell network layer that we want more frames */
1950 netif_wake_queue(self->netdev);
1952 self->stats.tx_packets++;
1954 if (self->io.speed <= 115200) {
1956 * Reset Rx FIFO to make sure that all reflected transmit data
1957 * is discarded. This is needed for half duplex operation
1959 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1960 fcr |= self->io.speed < 38400 ?
1961 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1963 outb(fcr, iobase + UART_FCR);
1965 /* Turn on receive interrupts */
1966 outb(UART_IER_RDI, iobase + UART_IER);
1972 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1974 * Fill Tx FIFO with transmit data
1977 static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1981 /* Tx FIFO should be empty! */
1982 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
1983 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1987 /* Fill FIFO with current frame */
1988 while (fifo_size-- > 0 && actual < len) {
1989 /* Transmit next byte */
1990 outb(buf[actual], iobase + UART_TX);
1997 * Function smsc_ircc_is_receiving (self)
1999 * Returns true is we are currently receiving data
2002 static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
2004 return (self->rx_buff.state != OUTSIDE_FRAME);
2009 * Function smsc_ircc_probe_transceiver(self)
2011 * Tries to find the used Transceiver
2014 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2018 IRDA_ASSERT(self != NULL, return;);
2020 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2021 if (smsc_transceivers[i].probe(self->io.fir_base)) {
2022 IRDA_MESSAGE(" %s transceiver found\n",
2023 smsc_transceivers[i].name);
2024 self->transceiver= i + 1;
2028 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2029 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
2031 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
2036 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2038 * Set the transceiver according to the speed
2041 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2045 trx = self->transceiver;
2047 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
2051 * Function smsc_ircc_wait_hw_transmitter_finish ()
2053 * Wait for the real end of HW transmission
2055 * The UART is a strict FIFO, and we get called only when we have finished
2056 * pushing data to the FIFO, so the maximum amount of time we must wait
2057 * is only for the FIFO to drain out.
2059 * We use a simple calibrated loop. We may need to adjust the loop
2060 * delay (udelay) to balance I/O traffic and latency. And we also need to
2061 * adjust the maximum timeout.
2062 * It would probably be better to wait for the proper interrupt,
2063 * but it doesn't seem to be available.
2065 * We can't use jiffies or kernel timers because :
2066 * 1) We are called from the interrupt handler, which disable softirqs,
2067 * so jiffies won't be increased
2068 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2069 * want to wait that long to detect stuck hardware.
2073 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2075 int iobase = self->io.sir_base;
2076 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
2078 /* Calibrated busy loop */
2079 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
2083 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
2089 * REVISIT we can be told about the device by PNP, and should use that info
2090 * instead of probing hardware and creating a platform_device ...
2093 static int __init smsc_ircc_look_for_chips(void)
2095 struct smsc_chip_address *address;
2097 unsigned int cfg_base, found;
2100 address = possible_addresses;
2102 while (address->cfg_base) {
2103 cfg_base = address->cfg_base;
2105 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
2107 if (address->type & SMSCSIO_TYPE_FDC) {
2109 if (address->type & SMSCSIO_TYPE_FLAT)
2110 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2113 if (address->type & SMSCSIO_TYPE_PAGED)
2114 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2117 if (address->type & SMSCSIO_TYPE_LPC) {
2119 if (address->type & SMSCSIO_TYPE_FLAT)
2120 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2123 if (address->type & SMSCSIO_TYPE_PAGED)
2124 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2133 * Function smsc_superio_flat (chip, base, type)
2135 * Try to get configuration of a smc SuperIO chip with flat register model
2138 static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
2140 unsigned short firbase, sirbase;
2144 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2146 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
2149 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
2150 mode = inb(cfgbase + 1);
2152 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
2154 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
2155 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2157 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
2158 sirbase = inb(cfgbase + 1) << 2;
2161 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
2162 firbase = inb(cfgbase + 1) << 3;
2165 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
2166 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
2169 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
2170 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2172 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2174 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2177 /* Exit configuration */
2178 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2184 * Function smsc_superio_paged (chip, base, type)
2186 * Try to get configuration of a smc SuperIO chip with paged register model
2189 static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
2191 unsigned short fir_io, sir_io;
2194 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2196 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
2199 /* Select logical device (UART2) */
2200 outb(0x07, cfg_base);
2201 outb(0x05, cfg_base + 1);
2204 outb(0x60, cfg_base);
2205 sir_io = inb(cfg_base + 1) << 8;
2206 outb(0x61, cfg_base);
2207 sir_io |= inb(cfg_base + 1);
2210 outb(0x62, cfg_base);
2211 fir_io = inb(cfg_base + 1) << 8;
2212 outb(0x63, cfg_base);
2213 fir_io |= inb(cfg_base + 1);
2214 outb(0x2b, cfg_base); /* ??? */
2216 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2219 /* Exit configuration */
2220 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2226 static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
2228 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2230 outb(reg, cfg_base);
2231 return inb(cfg_base) != reg ? -1 : 0;
2234 static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
2236 u8 devid, xdevid, rev;
2238 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2240 /* Leave configuration */
2242 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2244 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2247 outb(reg, cfg_base);
2249 xdevid = inb(cfg_base + 1);
2251 /* Enter configuration */
2253 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2256 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2260 /* probe device ID */
2262 if (smsc_access(cfg_base, reg))
2265 devid = inb(cfg_base + 1);
2267 if (devid == 0 || devid == 0xff) /* typical values for unused port */
2270 /* probe revision ID */
2272 if (smsc_access(cfg_base, reg + 1))
2275 rev = inb(cfg_base + 1);
2277 if (rev >= 128) /* i think this will make no sense */
2280 if (devid == xdevid) /* protection against false positives */
2283 /* Check for expected device ID; are there others? */
2285 while (chip->devid != devid) {
2289 if (chip->name == NULL)
2293 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2294 devid, rev, cfg_base, type, chip->name);
2296 if (chip->rev > rev) {
2297 IRDA_MESSAGE("Revision higher than expected\n");
2301 if (chip->flags & NoIRDA)
2302 IRDA_MESSAGE("chipset does not support IRDA\n");
2307 static int __init smsc_superio_fdc(unsigned short cfg_base)
2311 if (!request_region(cfg_base, 2, driver_name)) {
2312 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2313 __FUNCTION__, cfg_base);
2315 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2316 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
2319 release_region(cfg_base, 2);
2325 static int __init smsc_superio_lpc(unsigned short cfg_base)
2329 if (!request_region(cfg_base, 2, driver_name)) {
2330 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2331 __FUNCTION__, cfg_base);
2333 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2334 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
2337 release_region(cfg_base, 2);
2343 * Look for some specific subsystem setups that need
2344 * pre-configuration not properly done by the BIOS (especially laptops)
2345 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2346 * and tosh2450-smcinit.c. The table lists the device entries
2347 * for ISA bridges with an LPC (Low Pin Count) controller which
2348 * handles the communication with the SMSC device. After the LPC
2349 * controller is initialized through PCI, the SMSC device is initialized
2350 * through a dedicated port in the ISA port-mapped I/O area, this latter
2351 * area is used to configure the SMSC device with default
2352 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2353 * used different sets of parameters and different control port
2354 * addresses making a subsystem device table necessary.
2357 #define PCIID_VENDOR_INTEL 0x8086
2358 #define PCIID_VENDOR_ALI 0x10b9
2359 static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
2361 * Subsystems needing entries:
2362 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2363 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2364 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2368 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2370 .subvendor = 0x103c,
2371 .subdevice = 0x08bc,
2377 .preconfigure = preconfigure_through_82801,
2378 .name = "HP nx5000 family",
2381 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2383 .subvendor = 0x103c,
2384 .subdevice = 0x088c,
2385 /* Quite certain these are the same for nc8000 as for nc6000 */
2391 .preconfigure = preconfigure_through_82801,
2392 .name = "HP nc8000 family",
2395 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2397 .subvendor = 0x103c,
2398 .subdevice = 0x0890,
2404 .preconfigure = preconfigure_through_82801,
2405 .name = "HP nc6000 family",
2408 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2410 .subvendor = 0x0e11,
2411 .subdevice = 0x0860,
2412 /* I assume these are the same for x1000 as for the others */
2418 .preconfigure = preconfigure_through_82801,
2419 .name = "Compaq x1000 family",
2422 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
2423 .vendor = PCIID_VENDOR_INTEL,
2425 .subvendor = 0x1179,
2426 .subdevice = 0xffff, /* 0xffff is "any" */
2432 .preconfigure = preconfigure_through_82801,
2433 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
2436 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801CAM ISA bridge */
2438 .subvendor = 0x1179,
2439 .subdevice = 0xffff, /* 0xffff is "any" */
2445 .preconfigure = preconfigure_through_82801,
2446 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
2449 /* 82801DBM (ICH4-M) LPC Interface Bridge */
2450 .vendor = PCIID_VENDOR_INTEL,
2452 .subvendor = 0x1179,
2453 .subdevice = 0xffff, /* 0xffff is "any" */
2459 .preconfigure = preconfigure_through_82801,
2460 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2463 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
2464 .vendor = PCIID_VENDOR_ALI,
2466 .subvendor = 0x1179,
2467 .subdevice = 0xffff, /* 0xffff is "any" */
2473 .preconfigure = preconfigure_through_ali,
2474 .name = "Toshiba laptop with ALi ISA bridge",
2481 * This sets up the basic SMSC parameters
2482 * (FIR port, SIR port, FIR DMA, FIR IRQ)
2483 * through the chip configuration port.
2485 static int __init preconfigure_smsc_chip(struct
2486 smsc_ircc_subsystem_configuration
2489 unsigned short iobase = conf->cfg_base;
2490 unsigned char tmpbyte;
2492 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2493 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2494 tmpbyte = inb(iobase +1); // Read device ID
2496 "Detected Chip id: 0x%02x, setting up registers...\n",
2499 /* Disable UART1 and set up SIR I/O port */
2500 outb(0x24, iobase); // select CR24 - UART1 base addr
2501 outb(0x00, iobase + 1); // disable UART1
2502 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2503 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2504 tmpbyte = inb(iobase + 1);
2505 if (tmpbyte != (conf->sir_io >> 2) ) {
2506 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
2507 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
2511 /* Set up FIR IRQ channel for UART2 */
2512 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2513 tmpbyte = inb(iobase + 1);
2514 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2515 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2516 outb(tmpbyte, iobase + 1);
2517 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2518 if (tmpbyte != conf->fir_irq) {
2519 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2523 /* Set up FIR I/O port */
2524 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2525 outb((conf->fir_io >> 3), iobase + 1);
2526 tmpbyte = inb(iobase + 1);
2527 if (tmpbyte != (conf->fir_io >> 3) ) {
2528 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2532 /* Set up FIR DMA channel */
2533 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2534 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2535 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2536 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2537 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2541 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2542 tmpbyte = inb(iobase + 1);
2543 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2544 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
2545 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2547 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2548 tmpbyte = inb(iobase + 1);
2549 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2551 /* This one was not part of tosh1800 */
2552 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2553 tmpbyte = inb(iobase + 1);
2554 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2556 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2557 tmpbyte = inb(iobase + 1);
2558 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2560 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2561 tmpbyte = inb(iobase + 1);
2562 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2564 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2569 /* 82801CAM generic registers */
2572 #define PIRQ_A_D_ROUT 0x60
2573 #define SIRQ_CNTL 0x64
2574 #define PIRQ_E_H_ROUT 0x68
2575 #define PCI_DMA_C 0x90
2576 /* LPC-specific registers */
2577 #define COM_DEC 0xe0
2578 #define GEN1_DEC 0xe4
2580 #define GEN2_DEC 0xec
2582 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2583 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2584 * They all work the same way!
2586 static int __init preconfigure_through_82801(struct pci_dev *dev,
2588 smsc_ircc_subsystem_configuration
2591 unsigned short tmpword;
2592 unsigned char tmpbyte;
2594 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2596 * Select the range for the COMA COM port (SIR)
2599 * Bit 6-4, COMB decode range
2601 * Bit 2-0, COMA decode range
2604 * 000 = 0x3f8-0x3ff (COM1)
2605 * 001 = 0x2f8-0x2ff (COM2)
2609 * 101 = 0x2e8-0x2ef (COM4)
2611 * 111 = 0x3e8-0x3ef (COM3)
2613 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2614 tmpbyte &= 0xf8; /* mask COMA bits */
2615 switch(conf->sir_io) {
2641 tmpbyte |= 0x01; /* COM2 default */
2643 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2644 pci_write_config_byte(dev, COM_DEC, tmpbyte);
2646 /* Enable Low Pin Count interface */
2647 pci_read_config_word(dev, LPC_EN, &tmpword);
2648 /* These seem to be set up at all times,
2649 * just make sure it is properly set.
2651 switch(conf->cfg_base) {
2665 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2669 tmpword &= 0xfffd; /* disable LPC COMB */
2670 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2671 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
2672 pci_write_config_word(dev, LPC_EN, tmpword);
2675 * Configure LPC DMA channel
2677 * Bit 15-14: DMA channel 7 select
2678 * Bit 13-12: DMA channel 6 select
2679 * Bit 11-10: DMA channel 5 select
2681 * Bit 7-6: DMA channel 3 select
2682 * Bit 5-4: DMA channel 2 select
2683 * Bit 3-2: DMA channel 1 select
2684 * Bit 1-0: DMA channel 0 select
2685 * 00 = Reserved value
2687 * 10 = Reserved value
2690 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2691 switch(conf->fir_dma) {
2714 break; /* do not change settings */
2716 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2717 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2721 * Bit 15-4: Generic I/O range
2722 * Bit 3-1: reserved (read as 0)
2723 * Bit 0: enable GEN2 range on LPC I/F
2725 tmpword = conf->fir_io & 0xfff8;
2727 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2728 pci_write_config_word(dev, GEN2_DEC, tmpword);
2730 /* Pre-configure chip */
2731 return preconfigure_smsc_chip(conf);
2735 * Pre-configure a certain port on the ALi 1533 bridge.
2736 * This is based on reverse-engineering since ALi does not
2737 * provide any data sheet for the 1533 chip.
2739 static void __init preconfigure_ali_port(struct pci_dev *dev,
2740 unsigned short port)
2743 /* These bits obviously control the different ports */
2745 unsigned char tmpbyte;
2766 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2770 pci_read_config_byte(dev, reg, &tmpbyte);
2771 /* Turn on the right bits */
2773 pci_write_config_byte(dev, reg, tmpbyte);
2774 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
2778 static int __init preconfigure_through_ali(struct pci_dev *dev,
2780 smsc_ircc_subsystem_configuration
2783 /* Configure the two ports on the ALi 1533 */
2784 preconfigure_ali_port(dev, conf->sir_io);
2785 preconfigure_ali_port(dev, conf->fir_io);
2787 /* Pre-configure chip */
2788 return preconfigure_smsc_chip(conf);
2791 static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
2792 unsigned short ircc_fir,
2793 unsigned short ircc_sir,
2794 unsigned char ircc_dma,
2795 unsigned char ircc_irq)
2797 struct pci_dev *dev = NULL;
2798 unsigned short ss_vendor = 0x0000;
2799 unsigned short ss_device = 0x0000;
2802 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2804 while (dev != NULL) {
2805 struct smsc_ircc_subsystem_configuration *conf;
2808 * Cache the subsystem vendor/device:
2809 * some manufacturers fail to set this for all components,
2810 * so we save it in case there is just 0x0000 0x0000 on the
2811 * device we want to check.
2813 if (dev->subsystem_vendor != 0x0000U) {
2814 ss_vendor = dev->subsystem_vendor;
2815 ss_device = dev->subsystem_device;
2817 conf = subsystem_configurations;
2818 for( ; conf->subvendor; conf++) {
2819 if(conf->vendor == dev->vendor &&
2820 conf->device == dev->device &&
2821 conf->subvendor == ss_vendor &&
2822 /* Sometimes these are cached values */
2823 (conf->subdevice == ss_device ||
2824 conf->subdevice == 0xffff)) {
2825 struct smsc_ircc_subsystem_configuration
2828 memcpy(&tmpconf, conf,
2829 sizeof(struct smsc_ircc_subsystem_configuration));
2832 * Override the default values with anything
2833 * passed in as parameter
2836 tmpconf.cfg_base = ircc_cfg;
2838 tmpconf.fir_io = ircc_fir;
2840 tmpconf.sir_io = ircc_sir;
2841 if (ircc_dma != DMA_INVAL)
2842 tmpconf.fir_dma = ircc_dma;
2843 if (ircc_irq != IRQ_INVAL)
2844 tmpconf.fir_irq = ircc_irq;
2846 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2847 if (conf->preconfigure)
2848 ret = conf->preconfigure(dev, &tmpconf);
2853 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2858 #endif // CONFIG_PCI
2860 /************************************************
2862 * Transceivers specific functions
2864 ************************************************/
2868 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2870 * Program transceiver through smsc-ircc ATC circuitry
2874 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2876 unsigned long jiffies_now, jiffies_timeout;
2879 jiffies_now = jiffies;
2880 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
2883 register_bank(fir_base, 4);
2884 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2885 fir_base + IRCC_ATC);
2887 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2888 !time_after(jiffies, jiffies_timeout))
2892 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
2893 inb(fir_base + IRCC_ATC));
2897 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2899 * Probe transceiver smsc-ircc ATC circuitry
2903 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2909 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2915 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2926 fast_mode = IRCC_LCR_A_FAST;
2929 register_bank(fir_base, 0);
2930 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2934 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2940 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2946 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2952 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2963 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2967 /* This causes an interrupt */
2968 register_bank(fir_base, 0);
2969 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2973 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2979 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2985 module_init(smsc_ircc_init);
2986 module_exit(smsc_ircc_cleanup);