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");
82 static int ircc_dma = 255;
83 module_param(ircc_dma, int, 0);
84 MODULE_PARM_DESC(ircc_dma, "DMA channel");
86 static int ircc_irq = 255;
87 module_param(ircc_irq, int, 0);
88 MODULE_PARM_DESC(ircc_irq, "IRQ line");
91 module_param(ircc_fir, int, 0);
92 MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
95 module_param(ircc_sir, int, 0);
96 MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
99 module_param(ircc_cfg, int, 0);
100 MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
102 static int ircc_transceiver;
103 module_param(ircc_transceiver, int, 0);
104 MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
109 struct smsc_ircc_subsystem_configuration {
110 unsigned short vendor; /* PCI vendor ID */
111 unsigned short device; /* PCI vendor ID */
112 unsigned short subvendor; /* PCI subsystem vendor ID */
113 unsigned short subdevice; /* PCI sybsystem device ID */
114 unsigned short sir_io; /* I/O port for SIR */
115 unsigned short fir_io; /* I/O port for FIR */
116 unsigned char fir_irq; /* FIR IRQ */
117 unsigned char fir_dma; /* FIR DMA */
118 unsigned short cfg_base; /* I/O port for chip configuration */
119 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
120 const char *name; /* name shown as info */
124 struct smsc_transceiver {
126 void (*set_for_speed)(int fir_base, u32 speed);
127 int (*probe)(int fir_base);
140 struct smsc_chip_address {
141 unsigned int cfg_base;
145 /* Private data for each instance */
146 struct smsc_ircc_cb {
147 struct net_device *netdev; /* Yes! we are some kind of netdevice */
148 struct net_device_stats stats;
149 struct irlap_cb *irlap; /* The link layer we are binded to */
151 chipio_t io; /* IrDA controller information */
152 iobuff_t tx_buff; /* Transmit buffer */
153 iobuff_t rx_buff; /* Receive buffer */
154 dma_addr_t tx_buff_dma;
155 dma_addr_t rx_buff_dma;
157 struct qos_info qos; /* QoS capabilities for this device */
159 spinlock_t lock; /* For serializing operations */
162 __u32 flags; /* Interface flags */
164 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
165 int tx_len; /* Number of frames in tx_buff */
168 struct platform_device *pldev;
173 #define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
175 #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
176 #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
177 #define SMSC_IRCC2_C_NET_TIMEOUT 0
178 #define SMSC_IRCC2_C_SIR_STOP 0
180 static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
184 static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
185 static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
186 static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
187 static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
188 static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
189 static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
190 static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
191 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
192 static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
193 static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
194 static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
195 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
196 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
197 static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
198 static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
199 static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id);
200 static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
201 static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
202 #if SMSC_IRCC2_C_SIR_STOP
203 static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
205 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
206 static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
207 static int smsc_ircc_net_open(struct net_device *dev);
208 static int smsc_ircc_net_close(struct net_device *dev);
209 static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
210 #if SMSC_IRCC2_C_NET_TIMEOUT
211 static void smsc_ircc_timeout(struct net_device *dev);
213 static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
214 static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
215 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
216 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
217 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
220 static int __init smsc_ircc_look_for_chips(void);
221 static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
222 static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
223 static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
224 static int __init smsc_superio_fdc(unsigned short cfg_base);
225 static int __init smsc_superio_lpc(unsigned short cfg_base);
227 static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
228 static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
229 static void __init preconfigure_ali_port(struct pci_dev *dev,
230 unsigned short port);
231 static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
232 static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
233 unsigned short ircc_fir,
234 unsigned short ircc_sir,
235 unsigned char ircc_dma,
236 unsigned char ircc_irq);
239 /* Transceivers specific functions */
241 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
242 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
243 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
244 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
245 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
246 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
248 /* Power Management */
250 static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
251 static int smsc_ircc_resume(struct platform_device *dev);
253 static struct platform_driver smsc_ircc_driver = {
254 .suspend = smsc_ircc_suspend,
255 .resume = smsc_ircc_resume,
257 .name = SMSC_IRCC2_DRIVER_NAME,
261 /* Transceivers for SMSC-ircc */
263 static struct smsc_transceiver smsc_transceivers[] =
265 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
266 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
267 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
270 #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
272 /* SMC SuperIO chipsets definitions */
274 #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
275 #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
276 #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
277 #define SIR 0 /* SuperIO Chip has only slow IRDA */
278 #define FIR 4 /* SuperIO Chip has fast IRDA */
279 #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
281 static struct smsc_chip __initdata fdc_chips_flat[] =
283 /* Base address 0x3f0 or 0x370 */
284 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
285 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
286 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
287 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
288 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
289 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
290 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
291 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
295 static struct smsc_chip __initdata fdc_chips_paged[] =
297 /* Base address 0x3f0 or 0x370 */
298 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
299 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
300 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
301 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
302 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
303 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
304 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
305 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
306 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
307 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
308 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
309 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
310 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
314 static struct smsc_chip __initdata lpc_chips_flat[] =
316 /* Base address 0x2E or 0x4E */
317 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
318 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
322 static struct smsc_chip __initdata lpc_chips_paged[] =
324 /* Base address 0x2E or 0x4E */
325 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
326 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
327 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
328 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
329 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
330 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
331 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
332 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
336 #define SMSCSIO_TYPE_FDC 1
337 #define SMSCSIO_TYPE_LPC 2
338 #define SMSCSIO_TYPE_FLAT 4
339 #define SMSCSIO_TYPE_PAGED 8
341 static struct smsc_chip_address __initdata possible_addresses[] =
343 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
344 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
345 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
346 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
347 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
353 static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
354 static unsigned short dev_count;
356 static inline void register_bank(int iobase, int bank)
358 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
359 iobase + IRCC_MASTER);
363 /* PNP hotplug support */
364 static const struct pnp_device_id smsc_ircc_pnp_table[] = {
365 { .id = "SMCf010", .driver_data = 0 },
366 /* and presumably others */
369 MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
373 /*******************************************************************************
379 *******************************************************************************/
382 * Function smsc_ircc_init ()
384 * Initialize chip. Just try to find out how many chips we are dealing with
387 static int __init smsc_ircc_init(void)
391 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
393 ret = platform_driver_register(&smsc_ircc_driver);
395 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
400 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
401 /* Ignore errors from preconfiguration */
402 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
408 if (ircc_fir > 0 && ircc_sir > 0) {
409 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
410 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
412 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
417 /* try user provided configuration register base address */
419 IRDA_MESSAGE(" Overriding configuration address "
420 "0x%04x\n", ircc_cfg);
421 if (!smsc_superio_fdc(ircc_cfg))
423 if (!smsc_superio_lpc(ircc_cfg))
427 if (smsc_ircc_look_for_chips() > 0)
432 platform_driver_unregister(&smsc_ircc_driver);
438 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
440 * Try to open driver instance
443 static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
445 struct smsc_ircc_cb *self;
446 struct net_device *dev;
449 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
451 err = smsc_ircc_present(fir_base, sir_base);
456 if (dev_count >= ARRAY_SIZE(dev_self)) {
457 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
462 * Allocate new instance of the driver
464 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
466 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
470 SET_MODULE_OWNER(dev);
472 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
473 #if SMSC_IRCC2_C_NET_TIMEOUT
474 dev->tx_timeout = smsc_ircc_timeout;
475 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
477 dev->open = smsc_ircc_net_open;
478 dev->stop = smsc_ircc_net_close;
479 dev->do_ioctl = smsc_ircc_net_ioctl;
480 dev->get_stats = smsc_ircc_net_get_stats;
482 self = netdev_priv(dev);
485 /* Make ifconfig display some details */
486 dev->base_addr = self->io.fir_base = fir_base;
487 dev->irq = self->io.irq = irq;
489 /* Need to store self somewhere */
490 dev_self[dev_count] = self;
491 spin_lock_init(&self->lock);
493 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
494 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
497 dma_alloc_coherent(NULL, self->rx_buff.truesize,
498 &self->rx_buff_dma, GFP_KERNEL);
499 if (self->rx_buff.head == NULL) {
500 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
506 dma_alloc_coherent(NULL, self->tx_buff.truesize,
507 &self->tx_buff_dma, GFP_KERNEL);
508 if (self->tx_buff.head == NULL) {
509 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
514 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
515 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
517 self->rx_buff.in_frame = FALSE;
518 self->rx_buff.state = OUTSIDE_FRAME;
519 self->tx_buff.data = self->tx_buff.head;
520 self->rx_buff.data = self->rx_buff.head;
522 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
523 smsc_ircc_setup_qos(self);
524 smsc_ircc_init_chip(self);
526 if (ircc_transceiver > 0 &&
527 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
528 self->transceiver = ircc_transceiver;
530 smsc_ircc_probe_transceiver(self);
532 err = register_netdev(self->netdev);
534 IRDA_ERROR("%s, Network device registration failed!\n",
539 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
541 if (IS_ERR(self->pldev)) {
542 err = PTR_ERR(self->pldev);
545 platform_set_drvdata(self->pldev, self);
547 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
553 unregister_netdev(self->netdev);
556 dma_free_coherent(NULL, self->tx_buff.truesize,
557 self->tx_buff.head, self->tx_buff_dma);
559 dma_free_coherent(NULL, self->rx_buff.truesize,
560 self->rx_buff.head, self->rx_buff_dma);
562 free_netdev(self->netdev);
563 dev_self[dev_count] = NULL;
565 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
566 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
572 * Function smsc_ircc_present(fir_base, sir_base)
574 * Check the smsc-ircc chip presence
577 static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
579 unsigned char low, high, chip, config, dma, irq, version;
581 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
583 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
584 __FUNCTION__, fir_base);
588 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
590 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
591 __FUNCTION__, sir_base);
595 register_bank(fir_base, 3);
597 high = inb(fir_base + IRCC_ID_HIGH);
598 low = inb(fir_base + IRCC_ID_LOW);
599 chip = inb(fir_base + IRCC_CHIP_ID);
600 version = inb(fir_base + IRCC_VERSION);
601 config = inb(fir_base + IRCC_INTERFACE);
602 dma = config & IRCC_INTERFACE_DMA_MASK;
603 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
605 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
606 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
607 __FUNCTION__, fir_base);
610 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
611 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
612 chip & 0x0f, version, fir_base, sir_base, dma, irq);
617 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
619 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
625 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
630 static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
631 unsigned int fir_base, unsigned int sir_base,
634 unsigned char config, chip_dma, chip_irq;
636 register_bank(fir_base, 3);
637 config = inb(fir_base + IRCC_INTERFACE);
638 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
639 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
641 self->io.fir_base = fir_base;
642 self->io.sir_base = sir_base;
643 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
644 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
645 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
646 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
650 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
651 driver_name, chip_irq, irq);
654 self->io.irq = chip_irq;
658 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
659 driver_name, chip_dma, dma);
662 self->io.dma = chip_dma;
667 * Function smsc_ircc_setup_qos(self)
672 static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
674 /* Initialize QoS for this device */
675 irda_init_max_qos_capabilies(&self->qos);
677 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
678 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
680 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
681 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
682 irda_qos_bits_to_value(&self->qos);
686 * Function smsc_ircc_init_chip(self)
691 static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
693 int iobase = self->io.fir_base;
695 register_bank(iobase, 0);
696 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
697 outb(0x00, iobase + IRCC_MASTER);
699 register_bank(iobase, 1);
700 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
701 iobase + IRCC_SCE_CFGA);
703 #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
704 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
705 iobase + IRCC_SCE_CFGB);
707 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
708 iobase + IRCC_SCE_CFGB);
710 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
711 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
713 register_bank(iobase, 4);
714 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
716 register_bank(iobase, 0);
717 outb(0, iobase + IRCC_LCR_A);
719 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
721 /* Power on device */
722 outb(0x00, iobase + IRCC_MASTER);
726 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
728 * Process IOCTL commands for this device
731 static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
733 struct if_irda_req *irq = (struct if_irda_req *) rq;
734 struct smsc_ircc_cb *self;
738 IRDA_ASSERT(dev != NULL, return -1;);
740 self = netdev_priv(dev);
742 IRDA_ASSERT(self != NULL, return -1;);
744 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
747 case SIOCSBANDWIDTH: /* Set bandwidth */
748 if (!capable(CAP_NET_ADMIN))
751 /* Make sure we are the only one touching
752 * self->io.speed and the hardware - Jean II */
753 spin_lock_irqsave(&self->lock, flags);
754 smsc_ircc_change_speed(self, irq->ifr_baudrate);
755 spin_unlock_irqrestore(&self->lock, flags);
758 case SIOCSMEDIABUSY: /* Set media busy */
759 if (!capable(CAP_NET_ADMIN)) {
764 irda_device_set_media_busy(self->netdev, TRUE);
766 case SIOCGRECEIVING: /* Check if we are receiving right now */
767 irq->ifr_receiving = smsc_ircc_is_receiving(self);
771 if (!capable(CAP_NET_ADMIN)) {
775 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
785 static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
787 struct smsc_ircc_cb *self = netdev_priv(dev);
792 #if SMSC_IRCC2_C_NET_TIMEOUT
794 * Function smsc_ircc_timeout (struct net_device *dev)
796 * The networking timeout management.
800 static void smsc_ircc_timeout(struct net_device *dev)
802 struct smsc_ircc_cb *self = netdev_priv(dev);
805 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
806 dev->name, self->io.speed);
807 spin_lock_irqsave(&self->lock, flags);
808 smsc_ircc_sir_start(self);
809 smsc_ircc_change_speed(self, self->io.speed);
810 dev->trans_start = jiffies;
811 netif_wake_queue(dev);
812 spin_unlock_irqrestore(&self->lock, flags);
817 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
819 * Transmits the current frame until FIFO is full, then
820 * waits until the next transmit interrupt, and continues until the
821 * frame is transmitted.
823 int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
825 struct smsc_ircc_cb *self;
829 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
831 IRDA_ASSERT(dev != NULL, return 0;);
833 self = netdev_priv(dev);
834 IRDA_ASSERT(self != NULL, return 0;);
836 netif_stop_queue(dev);
838 /* Make sure test of self->io.speed & speed change are atomic */
839 spin_lock_irqsave(&self->lock, flags);
841 /* Check if we need to change the speed */
842 speed = irda_get_next_speed(skb);
843 if (speed != self->io.speed && speed != -1) {
844 /* Check for empty frame */
847 * We send frames one by one in SIR mode (no
848 * pipelining), so at this point, if we were sending
849 * a previous frame, we just received the interrupt
850 * telling us it is finished (UART_IIR_THRI).
851 * Therefore, waiting for the transmitter to really
852 * finish draining the fifo won't take too long.
853 * And the interrupt handler is not expected to run.
855 smsc_ircc_sir_wait_hw_transmitter_finish(self);
856 smsc_ircc_change_speed(self, speed);
857 spin_unlock_irqrestore(&self->lock, flags);
861 self->new_speed = speed;
865 self->tx_buff.data = self->tx_buff.head;
867 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
868 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
869 self->tx_buff.truesize);
871 self->stats.tx_bytes += self->tx_buff.len;
873 /* Turn on transmit finished interrupt. Will fire immediately! */
874 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
876 spin_unlock_irqrestore(&self->lock, flags);
884 * Function smsc_ircc_set_fir_speed (self, baud)
886 * Change the speed of the device
889 static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
891 int fir_base, ir_mode, ctrl, fast;
893 IRDA_ASSERT(self != NULL, return;);
894 fir_base = self->io.fir_base;
896 self->io.speed = speed;
901 ir_mode = IRCC_CFGA_IRDA_HDLC;
904 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
907 ir_mode = IRCC_CFGA_IRDA_HDLC;
908 ctrl = IRCC_1152 | IRCC_CRC;
909 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
910 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
914 ir_mode = IRCC_CFGA_IRDA_4PPM;
916 fast = IRCC_LCR_A_FAST;
917 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
923 /* This causes an interrupt */
924 register_bank(fir_base, 0);
925 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
928 register_bank(fir_base, 1);
929 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
931 register_bank(fir_base, 4);
932 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
936 * Function smsc_ircc_fir_start(self)
938 * Change the speed of the device
941 static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
943 struct net_device *dev;
946 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
948 IRDA_ASSERT(self != NULL, return;);
950 IRDA_ASSERT(dev != NULL, return;);
952 fir_base = self->io.fir_base;
954 /* Reset everything */
956 /* Install FIR transmit handler */
957 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
960 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
962 /* Enable interrupt */
963 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
965 register_bank(fir_base, 1);
967 /* Select the TX/RX interface */
968 #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
969 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
970 fir_base + IRCC_SCE_CFGB);
972 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
973 fir_base + IRCC_SCE_CFGB);
975 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
977 /* Enable SCE interrupts */
978 outb(0, fir_base + IRCC_MASTER);
979 register_bank(fir_base, 0);
980 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
981 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
985 * Function smsc_ircc_fir_stop(self, baud)
987 * Change the speed of the device
990 static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
994 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
996 IRDA_ASSERT(self != NULL, return;);
998 fir_base = self->io.fir_base;
999 register_bank(fir_base, 0);
1000 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1001 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
1006 * Function smsc_ircc_change_speed(self, baud)
1008 * Change the speed of the device
1010 * This function *must* be called with spinlock held, because it may
1011 * be called from the irq handler. - Jean II
1013 static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
1015 struct net_device *dev;
1016 int last_speed_was_sir;
1018 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
1020 IRDA_ASSERT(self != NULL, return;);
1023 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1028 self->io.speed = speed;
1029 last_speed_was_sir = 0;
1030 smsc_ircc_fir_start(self);
1033 if (self->io.speed == 0)
1034 smsc_ircc_sir_start(self);
1037 if (!last_speed_was_sir) speed = self->io.speed;
1040 if (self->io.speed != speed)
1041 smsc_ircc_set_transceiver_for_speed(self, speed);
1043 self->io.speed = speed;
1045 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1046 if (!last_speed_was_sir) {
1047 smsc_ircc_fir_stop(self);
1048 smsc_ircc_sir_start(self);
1050 smsc_ircc_set_sir_speed(self, speed);
1052 if (last_speed_was_sir) {
1053 #if SMSC_IRCC2_C_SIR_STOP
1054 smsc_ircc_sir_stop(self);
1056 smsc_ircc_fir_start(self);
1058 smsc_ircc_set_fir_speed(self, speed);
1061 self->tx_buff.len = 10;
1062 self->tx_buff.data = self->tx_buff.head;
1064 smsc_ircc_dma_xmit(self, 4000);
1066 /* Be ready for incoming frames */
1067 smsc_ircc_dma_receive(self);
1070 netif_wake_queue(dev);
1074 * Function smsc_ircc_set_sir_speed (self, speed)
1076 * Set speed of IrDA port to specified baudrate
1079 void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
1082 int fcr; /* FIFO control reg */
1083 int lcr; /* Line control reg */
1086 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1088 IRDA_ASSERT(self != NULL, return;);
1089 iobase = self->io.sir_base;
1091 /* Update accounting for new speed */
1092 self->io.speed = speed;
1094 /* Turn off interrupts */
1095 outb(0, iobase + UART_IER);
1097 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
1099 fcr = UART_FCR_ENABLE_FIFO;
1102 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1103 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1104 * about this timeout since it will always be fast enough.
1106 fcr |= self->io.speed < 38400 ?
1107 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1109 /* IrDA ports use 8N1 */
1110 lcr = UART_LCR_WLEN8;
1112 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1113 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1114 outb(divisor >> 8, iobase + UART_DLM);
1115 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1116 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
1118 /* Turn on interrups */
1119 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
1121 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1126 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1128 * Transmit the frame!
1131 static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1133 struct smsc_ircc_cb *self;
1134 unsigned long flags;
1138 IRDA_ASSERT(dev != NULL, return 0;);
1139 self = netdev_priv(dev);
1140 IRDA_ASSERT(self != NULL, return 0;);
1142 netif_stop_queue(dev);
1144 /* Make sure test of self->io.speed & speed change are atomic */
1145 spin_lock_irqsave(&self->lock, flags);
1147 /* Check if we need to change the speed after this frame */
1148 speed = irda_get_next_speed(skb);
1149 if (speed != self->io.speed && speed != -1) {
1150 /* Check for empty frame */
1152 /* Note : you should make sure that speed changes
1153 * are not going to corrupt any outgoing frame.
1154 * Look at nsc-ircc for the gory details - Jean II */
1155 smsc_ircc_change_speed(self, speed);
1156 spin_unlock_irqrestore(&self->lock, flags);
1161 self->new_speed = speed;
1164 memcpy(self->tx_buff.head, skb->data, skb->len);
1166 self->tx_buff.len = skb->len;
1167 self->tx_buff.data = self->tx_buff.head;
1169 mtt = irda_get_mtt(skb);
1174 * Compute how many BOFs (STA or PA's) we need to waste the
1175 * min turn time given the speed of the link.
1177 bofs = mtt * (self->io.speed / 1000) / 8000;
1181 smsc_ircc_dma_xmit(self, bofs);
1183 /* Transmit frame */
1184 smsc_ircc_dma_xmit(self, 0);
1187 spin_unlock_irqrestore(&self->lock, flags);
1194 * Function smsc_ircc_dma_xmit (self, bofs)
1196 * Transmit data using DMA
1199 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
1201 int iobase = self->io.fir_base;
1204 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1207 register_bank(iobase, 0);
1208 outb(0x00, iobase + IRCC_LCR_B);
1210 register_bank(iobase, 1);
1211 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1212 iobase + IRCC_SCE_CFGB);
1214 self->io.direction = IO_XMIT;
1216 /* Set BOF additional count for generating the min turn time */
1217 register_bank(iobase, 4);
1218 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1219 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1220 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
1222 /* Set max Tx frame size */
1223 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1224 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
1226 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1228 /* Enable burst mode chip Tx DMA */
1229 register_bank(iobase, 1);
1230 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1231 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1233 /* Setup DMA controller (must be done after enabling chip DMA) */
1234 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1237 /* Enable interrupt */
1239 register_bank(iobase, 0);
1240 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1241 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1243 /* Enable transmit */
1244 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
1248 * Function smsc_ircc_dma_xmit_complete (self)
1250 * The transfer of a frame in finished. This function will only be called
1251 * by the interrupt handler
1254 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
1256 int iobase = self->io.fir_base;
1258 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1261 register_bank(iobase, 0);
1262 outb(0x00, iobase + IRCC_LCR_B);
1264 register_bank(iobase, 1);
1265 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1266 iobase + IRCC_SCE_CFGB);
1268 /* Check for underrun! */
1269 register_bank(iobase, 0);
1270 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
1271 self->stats.tx_errors++;
1272 self->stats.tx_fifo_errors++;
1274 /* Reset error condition */
1275 register_bank(iobase, 0);
1276 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1277 outb(0x00, iobase + IRCC_MASTER);
1279 self->stats.tx_packets++;
1280 self->stats.tx_bytes += self->tx_buff.len;
1283 /* Check if it's time to change the speed */
1284 if (self->new_speed) {
1285 smsc_ircc_change_speed(self, self->new_speed);
1286 self->new_speed = 0;
1289 netif_wake_queue(self->netdev);
1293 * Function smsc_ircc_dma_receive(self)
1295 * Get ready for receiving a frame. The device will initiate a DMA
1296 * if it starts to receive a frame.
1299 static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
1301 int iobase = self->io.fir_base;
1303 /* Turn off chip DMA */
1304 register_bank(iobase, 1);
1305 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1306 iobase + IRCC_SCE_CFGB);
1310 register_bank(iobase, 0);
1311 outb(0x00, iobase + IRCC_LCR_B);
1313 /* Turn off chip DMA */
1314 register_bank(iobase, 1);
1315 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1316 iobase + IRCC_SCE_CFGB);
1318 self->io.direction = IO_RECV;
1319 self->rx_buff.data = self->rx_buff.head;
1321 /* Set max Rx frame size */
1322 register_bank(iobase, 4);
1323 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1324 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
1326 /* Setup DMA controller */
1327 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1330 /* Enable burst mode chip Rx DMA */
1331 register_bank(iobase, 1);
1332 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1333 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1335 /* Enable interrupt */
1336 register_bank(iobase, 0);
1337 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1338 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1340 /* Enable receiver */
1341 register_bank(iobase, 0);
1342 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
1343 iobase + IRCC_LCR_B);
1349 * Function smsc_ircc_dma_receive_complete(self)
1351 * Finished with receiving frames
1354 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
1356 struct sk_buff *skb;
1357 int len, msgcnt, lsr;
1358 int iobase = self->io.fir_base;
1360 register_bank(iobase, 0);
1362 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1365 register_bank(iobase, 0);
1366 outb(0x00, iobase + IRCC_LCR_B);
1368 register_bank(iobase, 0);
1369 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1370 lsr= inb(iobase + IRCC_LSR);
1371 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
1373 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1374 get_dma_residue(self->io.dma));
1376 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1378 /* Look for errors */
1379 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
1380 self->stats.rx_errors++;
1381 if (lsr & IRCC_LSR_FRAME_ERROR)
1382 self->stats.rx_frame_errors++;
1383 if (lsr & IRCC_LSR_CRC_ERROR)
1384 self->stats.rx_crc_errors++;
1385 if (lsr & IRCC_LSR_SIZE_ERROR)
1386 self->stats.rx_length_errors++;
1387 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1388 self->stats.rx_length_errors++;
1393 len -= self->io.speed < 4000000 ? 2 : 4;
1395 if (len < 2 || len > 2050) {
1396 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1399 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1401 skb = dev_alloc_skb(len + 1);
1403 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1407 /* Make sure IP header gets aligned */
1408 skb_reserve(skb, 1);
1410 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1411 self->stats.rx_packets++;
1412 self->stats.rx_bytes += len;
1414 skb->dev = self->netdev;
1415 skb->mac.raw = skb->data;
1416 skb->protocol = htons(ETH_P_IRDA);
1421 * Function smsc_ircc_sir_receive (self)
1423 * Receive one frame from the infrared port
1426 static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
1431 IRDA_ASSERT(self != NULL, return;);
1433 iobase = self->io.sir_base;
1436 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1437 * async_unwrap_char will deliver all found frames
1440 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
1441 inb(iobase + UART_RX));
1443 /* Make sure we don't stay here to long */
1444 if (boguscount++ > 32) {
1445 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1448 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
1453 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1455 * An interrupt from the chip has arrived. Time to do some work
1458 static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id)
1460 struct net_device *dev = (struct net_device *) dev_id;
1461 struct smsc_ircc_cb *self;
1462 int iobase, iir, lcra, lsr;
1463 irqreturn_t ret = IRQ_NONE;
1466 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
1471 self = netdev_priv(dev);
1472 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1474 /* Serialise the interrupt handler in various CPUs, stop Tx path */
1475 spin_lock(&self->lock);
1477 /* Check if we should use the SIR interrupt handler */
1478 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1479 ret = smsc_ircc_interrupt_sir(dev);
1480 goto irq_ret_unlock;
1483 iobase = self->io.fir_base;
1485 register_bank(iobase, 0);
1486 iir = inb(iobase + IRCC_IIR);
1488 goto irq_ret_unlock;
1491 /* Disable interrupts */
1492 outb(0, iobase + IRCC_IER);
1493 lcra = inb(iobase + IRCC_LCR_A);
1494 lsr = inb(iobase + IRCC_LSR);
1496 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1498 if (iir & IRCC_IIR_EOM) {
1499 if (self->io.direction == IO_RECV)
1500 smsc_ircc_dma_receive_complete(self);
1502 smsc_ircc_dma_xmit_complete(self);
1504 smsc_ircc_dma_receive(self);
1507 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1508 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1511 /* Enable interrupts again */
1513 register_bank(iobase, 0);
1514 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1517 spin_unlock(&self->lock);
1523 * Function irport_interrupt_sir (irq, dev_id)
1525 * Interrupt handler for SIR modes
1527 static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1529 struct smsc_ircc_cb *self = netdev_priv(dev);
1534 /* Already locked comming here in smsc_ircc_interrupt() */
1535 /*spin_lock(&self->lock);*/
1537 iobase = self->io.sir_base;
1539 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1543 /* Clear interrupt */
1544 lsr = inb(iobase + UART_LSR);
1546 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
1547 __FUNCTION__, iir, lsr, iobase);
1551 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1554 /* Receive interrupt */
1555 smsc_ircc_sir_receive(self);
1558 if (lsr & UART_LSR_THRE)
1559 /* Transmitter ready for data */
1560 smsc_ircc_sir_write_wakeup(self);
1563 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1568 /* Make sure we don't stay here to long */
1569 if (boguscount++ > 100)
1572 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1574 /*spin_unlock(&self->lock);*/
1581 * Function ircc_is_receiving (self)
1583 * Return TRUE is we are currently receiving a frame
1586 static int ircc_is_receiving(struct smsc_ircc_cb *self)
1591 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1593 IRDA_ASSERT(self != NULL, return FALSE;);
1595 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1596 get_dma_residue(self->io.dma));
1598 status = (self->rx_buff.state != OUTSIDE_FRAME);
1604 static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1608 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1609 self->netdev->name, self->netdev);
1611 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
1612 __FUNCTION__, self->io.irq, error);
1617 static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1619 unsigned long flags;
1621 spin_lock_irqsave(&self->lock, flags);
1624 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1626 spin_unlock_irqrestore(&self->lock, flags);
1629 static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1631 int iobase = self->io.fir_base;
1632 unsigned long flags;
1634 spin_lock_irqsave(&self->lock, flags);
1636 register_bank(iobase, 0);
1637 outb(0, iobase + IRCC_IER);
1638 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1639 outb(0x00, iobase + IRCC_MASTER);
1641 spin_unlock_irqrestore(&self->lock, flags);
1646 * Function smsc_ircc_net_open (dev)
1651 static int smsc_ircc_net_open(struct net_device *dev)
1653 struct smsc_ircc_cb *self;
1656 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1658 IRDA_ASSERT(dev != NULL, return -1;);
1659 self = netdev_priv(dev);
1660 IRDA_ASSERT(self != NULL, return 0;);
1662 if (self->io.suspended) {
1663 IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
1667 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
1669 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1670 __FUNCTION__, self->io.irq);
1674 smsc_ircc_start_interrupts(self);
1676 /* Give self a hardware name */
1677 /* It would be cool to offer the chip revision here - Jean II */
1678 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1681 * Open new IrLAP layer instance, now that everything should be
1682 * initialized properly
1684 self->irlap = irlap_open(dev, &self->qos, hwname);
1687 * Always allocate the DMA channel after the IRQ,
1688 * and clean up on failure.
1690 if (request_dma(self->io.dma, dev->name)) {
1691 smsc_ircc_net_close(dev);
1693 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1694 __FUNCTION__, self->io.dma);
1698 netif_start_queue(dev);
1704 * Function smsc_ircc_net_close (dev)
1709 static int smsc_ircc_net_close(struct net_device *dev)
1711 struct smsc_ircc_cb *self;
1713 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1715 IRDA_ASSERT(dev != NULL, return -1;);
1716 self = netdev_priv(dev);
1717 IRDA_ASSERT(self != NULL, return 0;);
1720 netif_stop_queue(dev);
1722 /* Stop and remove instance of IrLAP */
1724 irlap_close(self->irlap);
1727 smsc_ircc_stop_interrupts(self);
1729 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1730 if (!self->io.suspended)
1731 free_irq(self->io.irq, dev);
1733 disable_dma(self->io.dma);
1734 free_dma(self->io.dma);
1739 static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
1741 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
1743 if (!self->io.suspended) {
1744 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1747 if (netif_running(self->netdev)) {
1748 netif_device_detach(self->netdev);
1749 smsc_ircc_stop_interrupts(self);
1750 free_irq(self->io.irq, self->netdev);
1751 disable_dma(self->io.dma);
1753 self->io.suspended = 1;
1760 static int smsc_ircc_resume(struct platform_device *dev)
1762 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
1764 if (self->io.suspended) {
1765 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
1768 smsc_ircc_init_chip(self);
1769 if (netif_running(self->netdev)) {
1770 if (smsc_ircc_request_irq(self)) {
1772 * Don't fail resume process, just kill this
1775 unregister_netdevice(self->netdev);
1777 enable_dma(self->io.dma);
1778 smsc_ircc_start_interrupts(self);
1779 netif_device_attach(self->netdev);
1782 self->io.suspended = 0;
1789 * Function smsc_ircc_close (self)
1791 * Close driver instance
1794 static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1796 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1798 IRDA_ASSERT(self != NULL, return -1;);
1800 platform_device_unregister(self->pldev);
1802 /* Remove netdevice */
1803 unregister_netdev(self->netdev);
1805 smsc_ircc_stop_interrupts(self);
1807 /* Release the PORTS that this driver is using */
1808 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1811 release_region(self->io.fir_base, self->io.fir_ext);
1813 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1816 release_region(self->io.sir_base, self->io.sir_ext);
1818 if (self->tx_buff.head)
1819 dma_free_coherent(NULL, self->tx_buff.truesize,
1820 self->tx_buff.head, self->tx_buff_dma);
1822 if (self->rx_buff.head)
1823 dma_free_coherent(NULL, self->rx_buff.truesize,
1824 self->rx_buff.head, self->rx_buff_dma);
1826 free_netdev(self->netdev);
1831 static void __exit smsc_ircc_cleanup(void)
1835 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1837 for (i = 0; i < 2; i++) {
1839 smsc_ircc_close(dev_self[i]);
1842 platform_driver_unregister(&smsc_ircc_driver);
1846 * Start SIR operations
1848 * This function *must* be called with spinlock held, because it may
1849 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1851 void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1853 struct net_device *dev;
1854 int fir_base, sir_base;
1856 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1858 IRDA_ASSERT(self != NULL, return;);
1860 IRDA_ASSERT(dev != NULL, return;);
1861 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1863 fir_base = self->io.fir_base;
1864 sir_base = self->io.sir_base;
1866 /* Reset everything */
1867 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
1869 #if SMSC_IRCC2_C_SIR_STOP
1870 /*smsc_ircc_sir_stop(self);*/
1873 register_bank(fir_base, 1);
1874 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
1876 /* Initialize UART */
1877 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1878 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
1880 /* Turn on interrups */
1881 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
1883 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1885 outb(0x00, fir_base + IRCC_MASTER);
1888 #if SMSC_IRCC2_C_SIR_STOP
1889 void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1893 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1894 iobase = self->io.sir_base;
1897 outb(0, iobase + UART_MCR);
1899 /* Turn off interrupts */
1900 outb(0, iobase + UART_IER);
1905 * Function smsc_sir_write_wakeup (self)
1907 * Called by the SIR interrupt handler when there's room for more data.
1908 * If we have more packets to send, we send them here.
1911 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1917 IRDA_ASSERT(self != NULL, return;);
1919 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1921 iobase = self->io.sir_base;
1923 /* Finished with frame? */
1924 if (self->tx_buff.len > 0) {
1925 /* Write data left in transmit buffer */
1926 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
1927 self->tx_buff.data, self->tx_buff.len);
1928 self->tx_buff.data += actual;
1929 self->tx_buff.len -= actual;
1932 /*if (self->tx_buff.len ==0) {*/
1935 * Now serial buffer is almost free & we can start
1936 * transmission of another packet. But first we must check
1937 * if we need to change the speed of the hardware
1939 if (self->new_speed) {
1940 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1941 __FUNCTION__, self->new_speed);
1942 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1943 smsc_ircc_change_speed(self, self->new_speed);
1944 self->new_speed = 0;
1946 /* Tell network layer that we want more frames */
1947 netif_wake_queue(self->netdev);
1949 self->stats.tx_packets++;
1951 if (self->io.speed <= 115200) {
1953 * Reset Rx FIFO to make sure that all reflected transmit data
1954 * is discarded. This is needed for half duplex operation
1956 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1957 fcr |= self->io.speed < 38400 ?
1958 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1960 outb(fcr, iobase + UART_FCR);
1962 /* Turn on receive interrupts */
1963 outb(UART_IER_RDI, iobase + UART_IER);
1969 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1971 * Fill Tx FIFO with transmit data
1974 static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1978 /* Tx FIFO should be empty! */
1979 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
1980 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1984 /* Fill FIFO with current frame */
1985 while (fifo_size-- > 0 && actual < len) {
1986 /* Transmit next byte */
1987 outb(buf[actual], iobase + UART_TX);
1994 * Function smsc_ircc_is_receiving (self)
1996 * Returns true is we are currently receiving data
1999 static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
2001 return (self->rx_buff.state != OUTSIDE_FRAME);
2006 * Function smsc_ircc_probe_transceiver(self)
2008 * Tries to find the used Transceiver
2011 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2015 IRDA_ASSERT(self != NULL, return;);
2017 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2018 if (smsc_transceivers[i].probe(self->io.fir_base)) {
2019 IRDA_MESSAGE(" %s transceiver found\n",
2020 smsc_transceivers[i].name);
2021 self->transceiver= i + 1;
2025 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2026 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
2028 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
2033 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2035 * Set the transceiver according to the speed
2038 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2042 trx = self->transceiver;
2044 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
2048 * Function smsc_ircc_wait_hw_transmitter_finish ()
2050 * Wait for the real end of HW transmission
2052 * The UART is a strict FIFO, and we get called only when we have finished
2053 * pushing data to the FIFO, so the maximum amount of time we must wait
2054 * is only for the FIFO to drain out.
2056 * We use a simple calibrated loop. We may need to adjust the loop
2057 * delay (udelay) to balance I/O traffic and latency. And we also need to
2058 * adjust the maximum timeout.
2059 * It would probably be better to wait for the proper interrupt,
2060 * but it doesn't seem to be available.
2062 * We can't use jiffies or kernel timers because :
2063 * 1) We are called from the interrupt handler, which disable softirqs,
2064 * so jiffies won't be increased
2065 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2066 * want to wait that long to detect stuck hardware.
2070 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2072 int iobase = self->io.sir_base;
2073 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
2075 /* Calibrated busy loop */
2076 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
2080 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
2086 * REVISIT we can be told about the device by PNP, and should use that info
2087 * instead of probing hardware and creating a platform_device ...
2090 static int __init smsc_ircc_look_for_chips(void)
2092 struct smsc_chip_address *address;
2094 unsigned int cfg_base, found;
2097 address = possible_addresses;
2099 while (address->cfg_base) {
2100 cfg_base = address->cfg_base;
2102 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
2104 if (address->type & SMSCSIO_TYPE_FDC) {
2106 if (address->type & SMSCSIO_TYPE_FLAT)
2107 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2110 if (address->type & SMSCSIO_TYPE_PAGED)
2111 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2114 if (address->type & SMSCSIO_TYPE_LPC) {
2116 if (address->type & SMSCSIO_TYPE_FLAT)
2117 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2120 if (address->type & SMSCSIO_TYPE_PAGED)
2121 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2130 * Function smsc_superio_flat (chip, base, type)
2132 * Try to get configuration of a smc SuperIO chip with flat register model
2135 static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
2137 unsigned short firbase, sirbase;
2141 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2143 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
2146 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
2147 mode = inb(cfgbase + 1);
2149 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
2151 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
2152 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2154 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
2155 sirbase = inb(cfgbase + 1) << 2;
2158 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
2159 firbase = inb(cfgbase + 1) << 3;
2162 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
2163 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
2166 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
2167 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2169 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2171 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2174 /* Exit configuration */
2175 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2181 * Function smsc_superio_paged (chip, base, type)
2183 * Try to get configuration of a smc SuperIO chip with paged register model
2186 static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
2188 unsigned short fir_io, sir_io;
2191 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2193 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
2196 /* Select logical device (UART2) */
2197 outb(0x07, cfg_base);
2198 outb(0x05, cfg_base + 1);
2201 outb(0x60, cfg_base);
2202 sir_io = inb(cfg_base + 1) << 8;
2203 outb(0x61, cfg_base);
2204 sir_io |= inb(cfg_base + 1);
2207 outb(0x62, cfg_base);
2208 fir_io = inb(cfg_base + 1) << 8;
2209 outb(0x63, cfg_base);
2210 fir_io |= inb(cfg_base + 1);
2211 outb(0x2b, cfg_base); /* ??? */
2213 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2216 /* Exit configuration */
2217 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2223 static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
2225 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2227 outb(reg, cfg_base);
2228 return inb(cfg_base) != reg ? -1 : 0;
2231 static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
2233 u8 devid, xdevid, rev;
2235 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2237 /* Leave configuration */
2239 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2241 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2244 outb(reg, cfg_base);
2246 xdevid = inb(cfg_base + 1);
2248 /* Enter configuration */
2250 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2253 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2257 /* probe device ID */
2259 if (smsc_access(cfg_base, reg))
2262 devid = inb(cfg_base + 1);
2264 if (devid == 0 || devid == 0xff) /* typical values for unused port */
2267 /* probe revision ID */
2269 if (smsc_access(cfg_base, reg + 1))
2272 rev = inb(cfg_base + 1);
2274 if (rev >= 128) /* i think this will make no sense */
2277 if (devid == xdevid) /* protection against false positives */
2280 /* Check for expected device ID; are there others? */
2282 while (chip->devid != devid) {
2286 if (chip->name == NULL)
2290 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2291 devid, rev, cfg_base, type, chip->name);
2293 if (chip->rev > rev) {
2294 IRDA_MESSAGE("Revision higher than expected\n");
2298 if (chip->flags & NoIRDA)
2299 IRDA_MESSAGE("chipset does not support IRDA\n");
2304 static int __init smsc_superio_fdc(unsigned short cfg_base)
2308 if (!request_region(cfg_base, 2, driver_name)) {
2309 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2310 __FUNCTION__, cfg_base);
2312 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2313 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
2316 release_region(cfg_base, 2);
2322 static int __init smsc_superio_lpc(unsigned short cfg_base)
2326 if (!request_region(cfg_base, 2, driver_name)) {
2327 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2328 __FUNCTION__, cfg_base);
2330 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2331 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
2334 release_region(cfg_base, 2);
2340 * Look for some specific subsystem setups that need
2341 * pre-configuration not properly done by the BIOS (especially laptops)
2342 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2343 * and tosh2450-smcinit.c. The table lists the device entries
2344 * for ISA bridges with an LPC (Low Pin Count) controller which
2345 * handles the communication with the SMSC device. After the LPC
2346 * controller is initialized through PCI, the SMSC device is initialized
2347 * through a dedicated port in the ISA port-mapped I/O area, this latter
2348 * area is used to configure the SMSC device with default
2349 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2350 * used different sets of parameters and different control port
2351 * addresses making a subsystem device table necessary.
2354 #define PCIID_VENDOR_INTEL 0x8086
2355 #define PCIID_VENDOR_ALI 0x10b9
2356 static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
2358 * Subsystems needing entries:
2359 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2360 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2361 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2365 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2367 .subvendor = 0x103c,
2368 .subdevice = 0x08bc,
2374 .preconfigure = preconfigure_through_82801,
2375 .name = "HP nx5000 family",
2378 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2380 .subvendor = 0x103c,
2381 .subdevice = 0x088c,
2382 /* Quite certain these are the same for nc8000 as for nc6000 */
2388 .preconfigure = preconfigure_through_82801,
2389 .name = "HP nc8000 family",
2392 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2394 .subvendor = 0x103c,
2395 .subdevice = 0x0890,
2401 .preconfigure = preconfigure_through_82801,
2402 .name = "HP nc6000 family",
2405 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2407 .subvendor = 0x0e11,
2408 .subdevice = 0x0860,
2409 /* I assume these are the same for x1000 as for the others */
2415 .preconfigure = preconfigure_through_82801,
2416 .name = "Compaq x1000 family",
2419 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
2420 .vendor = PCIID_VENDOR_INTEL,
2422 .subvendor = 0x1179,
2423 .subdevice = 0xffff, /* 0xffff is "any" */
2429 .preconfigure = preconfigure_through_82801,
2430 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
2433 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801CAM ISA bridge */
2435 .subvendor = 0x1179,
2436 .subdevice = 0xffff, /* 0xffff is "any" */
2442 .preconfigure = preconfigure_through_82801,
2443 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
2446 /* 82801DBM (ICH4-M) LPC Interface Bridge */
2447 .vendor = PCIID_VENDOR_INTEL,
2449 .subvendor = 0x1179,
2450 .subdevice = 0xffff, /* 0xffff is "any" */
2456 .preconfigure = preconfigure_through_82801,
2457 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2460 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
2461 .vendor = PCIID_VENDOR_ALI,
2463 .subvendor = 0x1179,
2464 .subdevice = 0xffff, /* 0xffff is "any" */
2470 .preconfigure = preconfigure_through_ali,
2471 .name = "Toshiba laptop with ALi ISA bridge",
2478 * This sets up the basic SMSC parameters
2479 * (FIR port, SIR port, FIR DMA, FIR IRQ)
2480 * through the chip configuration port.
2482 static int __init preconfigure_smsc_chip(struct
2483 smsc_ircc_subsystem_configuration
2486 unsigned short iobase = conf->cfg_base;
2487 unsigned char tmpbyte;
2489 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2490 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2491 tmpbyte = inb(iobase +1); // Read device ID
2493 "Detected Chip id: 0x%02x, setting up registers...\n",
2496 /* Disable UART1 and set up SIR I/O port */
2497 outb(0x24, iobase); // select CR24 - UART1 base addr
2498 outb(0x00, iobase + 1); // disable UART1
2499 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2500 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2501 tmpbyte = inb(iobase + 1);
2502 if (tmpbyte != (conf->sir_io >> 2) ) {
2503 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
2504 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
2508 /* Set up FIR IRQ channel for UART2 */
2509 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2510 tmpbyte = inb(iobase + 1);
2511 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2512 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2513 outb(tmpbyte, iobase + 1);
2514 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2515 if (tmpbyte != conf->fir_irq) {
2516 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2520 /* Set up FIR I/O port */
2521 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2522 outb((conf->fir_io >> 3), iobase + 1);
2523 tmpbyte = inb(iobase + 1);
2524 if (tmpbyte != (conf->fir_io >> 3) ) {
2525 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2529 /* Set up FIR DMA channel */
2530 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2531 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2532 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2533 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2534 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2538 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2539 tmpbyte = inb(iobase + 1);
2540 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2541 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
2542 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2544 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2545 tmpbyte = inb(iobase + 1);
2546 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2548 /* This one was not part of tosh1800 */
2549 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2550 tmpbyte = inb(iobase + 1);
2551 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2553 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2554 tmpbyte = inb(iobase + 1);
2555 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2557 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2558 tmpbyte = inb(iobase + 1);
2559 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2561 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2566 /* 82801CAM generic registers */
2569 #define PIRQ_A_D_ROUT 0x60
2570 #define SIRQ_CNTL 0x64
2571 #define PIRQ_E_H_ROUT 0x68
2572 #define PCI_DMA_C 0x90
2573 /* LPC-specific registers */
2574 #define COM_DEC 0xe0
2575 #define GEN1_DEC 0xe4
2577 #define GEN2_DEC 0xec
2579 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2580 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2581 * They all work the same way!
2583 static int __init preconfigure_through_82801(struct pci_dev *dev,
2585 smsc_ircc_subsystem_configuration
2588 unsigned short tmpword;
2589 unsigned char tmpbyte;
2591 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2593 * Select the range for the COMA COM port (SIR)
2596 * Bit 6-4, COMB decode range
2598 * Bit 2-0, COMA decode range
2601 * 000 = 0x3f8-0x3ff (COM1)
2602 * 001 = 0x2f8-0x2ff (COM2)
2606 * 101 = 0x2e8-0x2ef (COM4)
2608 * 111 = 0x3e8-0x3ef (COM3)
2610 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2611 tmpbyte &= 0xf8; /* mask COMA bits */
2612 switch(conf->sir_io) {
2638 tmpbyte |= 0x01; /* COM2 default */
2640 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2641 pci_write_config_byte(dev, COM_DEC, tmpbyte);
2643 /* Enable Low Pin Count interface */
2644 pci_read_config_word(dev, LPC_EN, &tmpword);
2645 /* These seem to be set up at all times,
2646 * just make sure it is properly set.
2648 switch(conf->cfg_base) {
2662 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2666 tmpword &= 0xfffd; /* disable LPC COMB */
2667 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2668 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
2669 pci_write_config_word(dev, LPC_EN, tmpword);
2672 * Configure LPC DMA channel
2674 * Bit 15-14: DMA channel 7 select
2675 * Bit 13-12: DMA channel 6 select
2676 * Bit 11-10: DMA channel 5 select
2678 * Bit 7-6: DMA channel 3 select
2679 * Bit 5-4: DMA channel 2 select
2680 * Bit 3-2: DMA channel 1 select
2681 * Bit 1-0: DMA channel 0 select
2682 * 00 = Reserved value
2684 * 10 = Reserved value
2687 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2688 switch(conf->fir_dma) {
2711 break; /* do not change settings */
2713 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2714 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2718 * Bit 15-4: Generic I/O range
2719 * Bit 3-1: reserved (read as 0)
2720 * Bit 0: enable GEN2 range on LPC I/F
2722 tmpword = conf->fir_io & 0xfff8;
2724 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2725 pci_write_config_word(dev, GEN2_DEC, tmpword);
2727 /* Pre-configure chip */
2728 return preconfigure_smsc_chip(conf);
2732 * Pre-configure a certain port on the ALi 1533 bridge.
2733 * This is based on reverse-engineering since ALi does not
2734 * provide any data sheet for the 1533 chip.
2736 static void __init preconfigure_ali_port(struct pci_dev *dev,
2737 unsigned short port)
2740 /* These bits obviously control the different ports */
2742 unsigned char tmpbyte;
2763 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2767 pci_read_config_byte(dev, reg, &tmpbyte);
2768 /* Turn on the right bits */
2770 pci_write_config_byte(dev, reg, tmpbyte);
2771 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
2775 static int __init preconfigure_through_ali(struct pci_dev *dev,
2777 smsc_ircc_subsystem_configuration
2780 /* Configure the two ports on the ALi 1533 */
2781 preconfigure_ali_port(dev, conf->sir_io);
2782 preconfigure_ali_port(dev, conf->fir_io);
2784 /* Pre-configure chip */
2785 return preconfigure_smsc_chip(conf);
2788 static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
2789 unsigned short ircc_fir,
2790 unsigned short ircc_sir,
2791 unsigned char ircc_dma,
2792 unsigned char ircc_irq)
2794 struct pci_dev *dev = NULL;
2795 unsigned short ss_vendor = 0x0000;
2796 unsigned short ss_device = 0x0000;
2799 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2801 while (dev != NULL) {
2802 struct smsc_ircc_subsystem_configuration *conf;
2805 * Cache the subsystem vendor/device:
2806 * some manufacturers fail to set this for all components,
2807 * so we save it in case there is just 0x0000 0x0000 on the
2808 * device we want to check.
2810 if (dev->subsystem_vendor != 0x0000U) {
2811 ss_vendor = dev->subsystem_vendor;
2812 ss_device = dev->subsystem_device;
2814 conf = subsystem_configurations;
2815 for( ; conf->subvendor; conf++) {
2816 if(conf->vendor == dev->vendor &&
2817 conf->device == dev->device &&
2818 conf->subvendor == ss_vendor &&
2819 /* Sometimes these are cached values */
2820 (conf->subdevice == ss_device ||
2821 conf->subdevice == 0xffff)) {
2822 struct smsc_ircc_subsystem_configuration
2825 memcpy(&tmpconf, conf,
2826 sizeof(struct smsc_ircc_subsystem_configuration));
2829 * Override the default values with anything
2830 * passed in as parameter
2833 tmpconf.cfg_base = ircc_cfg;
2835 tmpconf.fir_io = ircc_fir;
2837 tmpconf.sir_io = ircc_sir;
2838 if (ircc_dma != 0xff)
2839 tmpconf.fir_dma = ircc_dma;
2840 if (ircc_irq != 0xff)
2841 tmpconf.fir_irq = ircc_irq;
2843 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2844 if (conf->preconfigure)
2845 ret = conf->preconfigure(dev, &tmpconf);
2850 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2855 #endif // CONFIG_PCI
2857 /************************************************
2859 * Transceivers specific functions
2861 ************************************************/
2865 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2867 * Program transceiver through smsc-ircc ATC circuitry
2871 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2873 unsigned long jiffies_now, jiffies_timeout;
2876 jiffies_now = jiffies;
2877 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
2880 register_bank(fir_base, 4);
2881 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2882 fir_base + IRCC_ATC);
2884 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2885 !time_after(jiffies, jiffies_timeout))
2889 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
2890 inb(fir_base + IRCC_ATC));
2894 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2896 * Probe transceiver smsc-ircc ATC circuitry
2900 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2906 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2912 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2923 fast_mode = IRCC_LCR_A_FAST;
2926 register_bank(fir_base, 0);
2927 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2931 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2937 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2943 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2949 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2960 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2964 /* This causes an interrupt */
2965 register_bank(fir_base, 0);
2966 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2970 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2976 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2982 module_init(smsc_ircc_init);
2983 module_exit(smsc_ircc_cleanup);