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/platform_device.h>
61 #include <asm/byteorder.h>
63 #include <linux/spinlock.h>
66 #include <linux/pci.h>
69 #include <net/irda/wrapper.h>
70 #include <net/irda/irda.h>
71 #include <net/irda/irda_device.h>
73 #include "smsc-ircc2.h"
77 MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
78 MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
79 MODULE_LICENSE("GPL");
81 static int ircc_dma = 255;
82 module_param(ircc_dma, int, 0);
83 MODULE_PARM_DESC(ircc_dma, "DMA channel");
85 static int ircc_irq = 255;
86 module_param(ircc_irq, int, 0);
87 MODULE_PARM_DESC(ircc_irq, "IRQ line");
90 module_param(ircc_fir, int, 0);
91 MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
94 module_param(ircc_sir, int, 0);
95 MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
98 module_param(ircc_cfg, int, 0);
99 MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
101 static int ircc_transceiver;
102 module_param(ircc_transceiver, int, 0);
103 MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
108 struct smsc_ircc_subsystem_configuration {
109 unsigned short vendor; /* PCI vendor ID */
110 unsigned short device; /* PCI vendor ID */
111 unsigned short subvendor; /* PCI subsystem vendor ID */
112 unsigned short subdevice; /* PCI sybsystem device ID */
113 unsigned short sir_io; /* I/O port for SIR */
114 unsigned short fir_io; /* I/O port for FIR */
115 unsigned char fir_irq; /* FIR IRQ */
116 unsigned char fir_dma; /* FIR DMA */
117 unsigned short cfg_base; /* I/O port for chip configuration */
118 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
119 const char *name; /* name shown as info */
123 struct smsc_transceiver {
125 void (*set_for_speed)(int fir_base, u32 speed);
126 int (*probe)(int fir_base);
139 struct smsc_chip_address {
140 unsigned int cfg_base;
144 /* Private data for each instance */
145 struct smsc_ircc_cb {
146 struct net_device *netdev; /* Yes! we are some kind of netdevice */
147 struct net_device_stats stats;
148 struct irlap_cb *irlap; /* The link layer we are binded to */
150 chipio_t io; /* IrDA controller information */
151 iobuff_t tx_buff; /* Transmit buffer */
152 iobuff_t rx_buff; /* Receive buffer */
153 dma_addr_t tx_buff_dma;
154 dma_addr_t rx_buff_dma;
156 struct qos_info qos; /* QoS capabilities for this device */
158 spinlock_t lock; /* For serializing operations */
161 __u32 flags; /* Interface flags */
163 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
164 int tx_len; /* Number of frames in tx_buff */
167 struct platform_device *pldev;
172 #define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
174 #define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
175 #define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
176 #define SMSC_IRCC2_C_NET_TIMEOUT 0
177 #define SMSC_IRCC2_C_SIR_STOP 0
179 static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
183 static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
184 static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
185 static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
186 static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
187 static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
188 static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
189 static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
190 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
191 static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
192 static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
193 static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
194 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
195 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
196 static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
197 static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
198 static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
199 static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
200 static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
201 #if SMSC_IRCC2_C_SIR_STOP
202 static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
204 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
205 static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
206 static int smsc_ircc_net_open(struct net_device *dev);
207 static int smsc_ircc_net_close(struct net_device *dev);
208 static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
209 #if SMSC_IRCC2_C_NET_TIMEOUT
210 static void smsc_ircc_timeout(struct net_device *dev);
212 static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
213 static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
214 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
215 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
216 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
219 static int __init smsc_ircc_look_for_chips(void);
220 static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
221 static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
222 static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
223 static int __init smsc_superio_fdc(unsigned short cfg_base);
224 static int __init smsc_superio_lpc(unsigned short cfg_base);
226 static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
227 static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
228 static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
229 static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
230 unsigned short ircc_fir,
231 unsigned short ircc_sir,
232 unsigned char ircc_dma,
233 unsigned char ircc_irq);
236 /* Transceivers specific functions */
238 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
239 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
240 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
241 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
242 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
243 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
245 /* Power Management */
247 static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
248 static int smsc_ircc_resume(struct platform_device *dev);
250 static struct platform_driver smsc_ircc_driver = {
251 .suspend = smsc_ircc_suspend,
252 .resume = smsc_ircc_resume,
254 .name = SMSC_IRCC2_DRIVER_NAME,
258 /* Transceivers for SMSC-ircc */
260 static struct smsc_transceiver smsc_transceivers[] =
262 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
263 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
264 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
267 #define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
269 /* SMC SuperIO chipsets definitions */
271 #define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
272 #define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
273 #define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
274 #define SIR 0 /* SuperIO Chip has only slow IRDA */
275 #define FIR 4 /* SuperIO Chip has fast IRDA */
276 #define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
278 static struct smsc_chip __initdata fdc_chips_flat[] =
280 /* Base address 0x3f0 or 0x370 */
281 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
282 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
283 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
284 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
285 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
286 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
287 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
288 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
292 static struct smsc_chip __initdata fdc_chips_paged[] =
294 /* Base address 0x3f0 or 0x370 */
295 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
296 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
297 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
298 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
299 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
300 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
301 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
302 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
303 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
304 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
305 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
306 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
307 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
311 static struct smsc_chip __initdata lpc_chips_flat[] =
313 /* Base address 0x2E or 0x4E */
314 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
315 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
319 static struct smsc_chip __initdata lpc_chips_paged[] =
321 /* Base address 0x2E or 0x4E */
322 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
323 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
324 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
325 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
326 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
327 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
328 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
329 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
333 #define SMSCSIO_TYPE_FDC 1
334 #define SMSCSIO_TYPE_LPC 2
335 #define SMSCSIO_TYPE_FLAT 4
336 #define SMSCSIO_TYPE_PAGED 8
338 static struct smsc_chip_address __initdata possible_addresses[] =
340 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
341 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
342 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
343 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
344 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
350 static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
351 static unsigned short dev_count;
353 static inline void register_bank(int iobase, int bank)
355 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
356 iobase + IRCC_MASTER);
360 /*******************************************************************************
366 *******************************************************************************/
369 * Function smsc_ircc_init ()
371 * Initialize chip. Just try to find out how many chips we are dealing with
374 static int __init smsc_ircc_init(void)
378 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
380 ret = platform_driver_register(&smsc_ircc_driver);
382 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
387 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
388 /* Ignore errors from preconfiguration */
389 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
395 if (ircc_fir > 0 && ircc_sir > 0) {
396 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
397 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
399 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
404 /* try user provided configuration register base address */
406 IRDA_MESSAGE(" Overriding configuration address "
407 "0x%04x\n", ircc_cfg);
408 if (!smsc_superio_fdc(ircc_cfg))
410 if (!smsc_superio_lpc(ircc_cfg))
414 if (smsc_ircc_look_for_chips() > 0)
419 platform_driver_unregister(&smsc_ircc_driver);
425 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
427 * Try to open driver instance
430 static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
432 struct smsc_ircc_cb *self;
433 struct net_device *dev;
436 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
438 err = smsc_ircc_present(fir_base, sir_base);
443 if (dev_count >= ARRAY_SIZE(dev_self)) {
444 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
449 * Allocate new instance of the driver
451 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
453 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
457 SET_MODULE_OWNER(dev);
459 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
460 #if SMSC_IRCC2_C_NET_TIMEOUT
461 dev->tx_timeout = smsc_ircc_timeout;
462 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
464 dev->open = smsc_ircc_net_open;
465 dev->stop = smsc_ircc_net_close;
466 dev->do_ioctl = smsc_ircc_net_ioctl;
467 dev->get_stats = smsc_ircc_net_get_stats;
469 self = netdev_priv(dev);
472 /* Make ifconfig display some details */
473 dev->base_addr = self->io.fir_base = fir_base;
474 dev->irq = self->io.irq = irq;
476 /* Need to store self somewhere */
477 dev_self[dev_count] = self;
478 spin_lock_init(&self->lock);
480 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
481 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
484 dma_alloc_coherent(NULL, self->rx_buff.truesize,
485 &self->rx_buff_dma, GFP_KERNEL);
486 if (self->rx_buff.head == NULL) {
487 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
493 dma_alloc_coherent(NULL, self->tx_buff.truesize,
494 &self->tx_buff_dma, GFP_KERNEL);
495 if (self->tx_buff.head == NULL) {
496 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
501 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
502 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
504 self->rx_buff.in_frame = FALSE;
505 self->rx_buff.state = OUTSIDE_FRAME;
506 self->tx_buff.data = self->tx_buff.head;
507 self->rx_buff.data = self->rx_buff.head;
509 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
510 smsc_ircc_setup_qos(self);
511 smsc_ircc_init_chip(self);
513 if (ircc_transceiver > 0 &&
514 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
515 self->transceiver = ircc_transceiver;
517 smsc_ircc_probe_transceiver(self);
519 err = register_netdev(self->netdev);
521 IRDA_ERROR("%s, Network device registration failed!\n",
526 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
528 if (IS_ERR(self->pldev)) {
529 err = PTR_ERR(self->pldev);
532 platform_set_drvdata(self->pldev, self);
534 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
540 unregister_netdev(self->netdev);
543 dma_free_coherent(NULL, self->tx_buff.truesize,
544 self->tx_buff.head, self->tx_buff_dma);
546 dma_free_coherent(NULL, self->rx_buff.truesize,
547 self->rx_buff.head, self->rx_buff_dma);
549 free_netdev(self->netdev);
550 dev_self[dev_count] = NULL;
552 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
553 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
559 * Function smsc_ircc_present(fir_base, sir_base)
561 * Check the smsc-ircc chip presence
564 static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
566 unsigned char low, high, chip, config, dma, irq, version;
568 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
570 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
571 __FUNCTION__, fir_base);
575 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
577 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
578 __FUNCTION__, sir_base);
582 register_bank(fir_base, 3);
584 high = inb(fir_base + IRCC_ID_HIGH);
585 low = inb(fir_base + IRCC_ID_LOW);
586 chip = inb(fir_base + IRCC_CHIP_ID);
587 version = inb(fir_base + IRCC_VERSION);
588 config = inb(fir_base + IRCC_INTERFACE);
589 dma = config & IRCC_INTERFACE_DMA_MASK;
590 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
592 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
593 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
594 __FUNCTION__, fir_base);
597 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
598 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
599 chip & 0x0f, version, fir_base, sir_base, dma, irq);
604 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
606 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
612 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
617 static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
618 unsigned int fir_base, unsigned int sir_base,
621 unsigned char config, chip_dma, chip_irq;
623 register_bank(fir_base, 3);
624 config = inb(fir_base + IRCC_INTERFACE);
625 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
626 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
628 self->io.fir_base = fir_base;
629 self->io.sir_base = sir_base;
630 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
631 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
632 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
633 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
637 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
638 driver_name, chip_irq, irq);
641 self->io.irq = chip_irq;
645 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
646 driver_name, chip_dma, dma);
649 self->io.dma = chip_dma;
654 * Function smsc_ircc_setup_qos(self)
659 static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
661 /* Initialize QoS for this device */
662 irda_init_max_qos_capabilies(&self->qos);
664 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
665 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
667 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
668 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
669 irda_qos_bits_to_value(&self->qos);
673 * Function smsc_ircc_init_chip(self)
678 static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
680 int iobase = self->io.fir_base;
682 register_bank(iobase, 0);
683 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
684 outb(0x00, iobase + IRCC_MASTER);
686 register_bank(iobase, 1);
687 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
688 iobase + IRCC_SCE_CFGA);
690 #ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
691 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
692 iobase + IRCC_SCE_CFGB);
694 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
695 iobase + IRCC_SCE_CFGB);
697 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
698 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
700 register_bank(iobase, 4);
701 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
703 register_bank(iobase, 0);
704 outb(0, iobase + IRCC_LCR_A);
706 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
708 /* Power on device */
709 outb(0x00, iobase + IRCC_MASTER);
713 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
715 * Process IOCTL commands for this device
718 static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
720 struct if_irda_req *irq = (struct if_irda_req *) rq;
721 struct smsc_ircc_cb *self;
725 IRDA_ASSERT(dev != NULL, return -1;);
727 self = netdev_priv(dev);
729 IRDA_ASSERT(self != NULL, return -1;);
731 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
734 case SIOCSBANDWIDTH: /* Set bandwidth */
735 if (!capable(CAP_NET_ADMIN))
738 /* Make sure we are the only one touching
739 * self->io.speed and the hardware - Jean II */
740 spin_lock_irqsave(&self->lock, flags);
741 smsc_ircc_change_speed(self, irq->ifr_baudrate);
742 spin_unlock_irqrestore(&self->lock, flags);
745 case SIOCSMEDIABUSY: /* Set media busy */
746 if (!capable(CAP_NET_ADMIN)) {
751 irda_device_set_media_busy(self->netdev, TRUE);
753 case SIOCGRECEIVING: /* Check if we are receiving right now */
754 irq->ifr_receiving = smsc_ircc_is_receiving(self);
758 if (!capable(CAP_NET_ADMIN)) {
762 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
772 static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
774 struct smsc_ircc_cb *self = netdev_priv(dev);
779 #if SMSC_IRCC2_C_NET_TIMEOUT
781 * Function smsc_ircc_timeout (struct net_device *dev)
783 * The networking timeout management.
787 static void smsc_ircc_timeout(struct net_device *dev)
789 struct smsc_ircc_cb *self = netdev_priv(dev);
792 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
793 dev->name, self->io.speed);
794 spin_lock_irqsave(&self->lock, flags);
795 smsc_ircc_sir_start(self);
796 smsc_ircc_change_speed(self, self->io.speed);
797 dev->trans_start = jiffies;
798 netif_wake_queue(dev);
799 spin_unlock_irqrestore(&self->lock, flags);
804 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
806 * Transmits the current frame until FIFO is full, then
807 * waits until the next transmit interrupt, and continues until the
808 * frame is transmitted.
810 int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
812 struct smsc_ircc_cb *self;
816 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
818 IRDA_ASSERT(dev != NULL, return 0;);
820 self = netdev_priv(dev);
821 IRDA_ASSERT(self != NULL, return 0;);
823 netif_stop_queue(dev);
825 /* Make sure test of self->io.speed & speed change are atomic */
826 spin_lock_irqsave(&self->lock, flags);
828 /* Check if we need to change the speed */
829 speed = irda_get_next_speed(skb);
830 if (speed != self->io.speed && speed != -1) {
831 /* Check for empty frame */
834 * We send frames one by one in SIR mode (no
835 * pipelining), so at this point, if we were sending
836 * a previous frame, we just received the interrupt
837 * telling us it is finished (UART_IIR_THRI).
838 * Therefore, waiting for the transmitter to really
839 * finish draining the fifo won't take too long.
840 * And the interrupt handler is not expected to run.
842 smsc_ircc_sir_wait_hw_transmitter_finish(self);
843 smsc_ircc_change_speed(self, speed);
844 spin_unlock_irqrestore(&self->lock, flags);
848 self->new_speed = speed;
852 self->tx_buff.data = self->tx_buff.head;
854 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
855 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
856 self->tx_buff.truesize);
858 self->stats.tx_bytes += self->tx_buff.len;
860 /* Turn on transmit finished interrupt. Will fire immediately! */
861 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
863 spin_unlock_irqrestore(&self->lock, flags);
871 * Function smsc_ircc_set_fir_speed (self, baud)
873 * Change the speed of the device
876 static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
878 int fir_base, ir_mode, ctrl, fast;
880 IRDA_ASSERT(self != NULL, return;);
881 fir_base = self->io.fir_base;
883 self->io.speed = speed;
888 ir_mode = IRCC_CFGA_IRDA_HDLC;
891 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
894 ir_mode = IRCC_CFGA_IRDA_HDLC;
895 ctrl = IRCC_1152 | IRCC_CRC;
896 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
897 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
901 ir_mode = IRCC_CFGA_IRDA_4PPM;
903 fast = IRCC_LCR_A_FAST;
904 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
910 /* This causes an interrupt */
911 register_bank(fir_base, 0);
912 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
915 register_bank(fir_base, 1);
916 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
918 register_bank(fir_base, 4);
919 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
923 * Function smsc_ircc_fir_start(self)
925 * Change the speed of the device
928 static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
930 struct net_device *dev;
933 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
935 IRDA_ASSERT(self != NULL, return;);
937 IRDA_ASSERT(dev != NULL, return;);
939 fir_base = self->io.fir_base;
941 /* Reset everything */
943 /* Install FIR transmit handler */
944 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
947 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
949 /* Enable interrupt */
950 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
952 register_bank(fir_base, 1);
954 /* Select the TX/RX interface */
955 #ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
956 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
957 fir_base + IRCC_SCE_CFGB);
959 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
960 fir_base + IRCC_SCE_CFGB);
962 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
964 /* Enable SCE interrupts */
965 outb(0, fir_base + IRCC_MASTER);
966 register_bank(fir_base, 0);
967 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
968 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
972 * Function smsc_ircc_fir_stop(self, baud)
974 * Change the speed of the device
977 static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
981 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
983 IRDA_ASSERT(self != NULL, return;);
985 fir_base = self->io.fir_base;
986 register_bank(fir_base, 0);
987 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
988 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
993 * Function smsc_ircc_change_speed(self, baud)
995 * Change the speed of the device
997 * This function *must* be called with spinlock held, because it may
998 * be called from the irq handler. - Jean II
1000 static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
1002 struct net_device *dev;
1003 int last_speed_was_sir;
1005 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
1007 IRDA_ASSERT(self != NULL, return;);
1010 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1015 self->io.speed = speed;
1016 last_speed_was_sir = 0;
1017 smsc_ircc_fir_start(self);
1020 if (self->io.speed == 0)
1021 smsc_ircc_sir_start(self);
1024 if (!last_speed_was_sir) speed = self->io.speed;
1027 if (self->io.speed != speed)
1028 smsc_ircc_set_transceiver_for_speed(self, speed);
1030 self->io.speed = speed;
1032 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1033 if (!last_speed_was_sir) {
1034 smsc_ircc_fir_stop(self);
1035 smsc_ircc_sir_start(self);
1037 smsc_ircc_set_sir_speed(self, speed);
1039 if (last_speed_was_sir) {
1040 #if SMSC_IRCC2_C_SIR_STOP
1041 smsc_ircc_sir_stop(self);
1043 smsc_ircc_fir_start(self);
1045 smsc_ircc_set_fir_speed(self, speed);
1048 self->tx_buff.len = 10;
1049 self->tx_buff.data = self->tx_buff.head;
1051 smsc_ircc_dma_xmit(self, 4000);
1053 /* Be ready for incoming frames */
1054 smsc_ircc_dma_receive(self);
1057 netif_wake_queue(dev);
1061 * Function smsc_ircc_set_sir_speed (self, speed)
1063 * Set speed of IrDA port to specified baudrate
1066 void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
1069 int fcr; /* FIFO control reg */
1070 int lcr; /* Line control reg */
1073 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1075 IRDA_ASSERT(self != NULL, return;);
1076 iobase = self->io.sir_base;
1078 /* Update accounting for new speed */
1079 self->io.speed = speed;
1081 /* Turn off interrupts */
1082 outb(0, iobase + UART_IER);
1084 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
1086 fcr = UART_FCR_ENABLE_FIFO;
1089 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1090 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1091 * about this timeout since it will always be fast enough.
1093 fcr |= self->io.speed < 38400 ?
1094 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1096 /* IrDA ports use 8N1 */
1097 lcr = UART_LCR_WLEN8;
1099 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1100 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1101 outb(divisor >> 8, iobase + UART_DLM);
1102 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1103 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
1105 /* Turn on interrups */
1106 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
1108 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1113 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1115 * Transmit the frame!
1118 static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1120 struct smsc_ircc_cb *self;
1121 unsigned long flags;
1125 IRDA_ASSERT(dev != NULL, return 0;);
1126 self = netdev_priv(dev);
1127 IRDA_ASSERT(self != NULL, return 0;);
1129 netif_stop_queue(dev);
1131 /* Make sure test of self->io.speed & speed change are atomic */
1132 spin_lock_irqsave(&self->lock, flags);
1134 /* Check if we need to change the speed after this frame */
1135 speed = irda_get_next_speed(skb);
1136 if (speed != self->io.speed && speed != -1) {
1137 /* Check for empty frame */
1139 /* Note : you should make sure that speed changes
1140 * are not going to corrupt any outgoing frame.
1141 * Look at nsc-ircc for the gory details - Jean II */
1142 smsc_ircc_change_speed(self, speed);
1143 spin_unlock_irqrestore(&self->lock, flags);
1148 self->new_speed = speed;
1151 memcpy(self->tx_buff.head, skb->data, skb->len);
1153 self->tx_buff.len = skb->len;
1154 self->tx_buff.data = self->tx_buff.head;
1156 mtt = irda_get_mtt(skb);
1161 * Compute how many BOFs (STA or PA's) we need to waste the
1162 * min turn time given the speed of the link.
1164 bofs = mtt * (self->io.speed / 1000) / 8000;
1168 smsc_ircc_dma_xmit(self, bofs);
1170 /* Transmit frame */
1171 smsc_ircc_dma_xmit(self, 0);
1174 spin_unlock_irqrestore(&self->lock, flags);
1181 * Function smsc_ircc_dma_xmit (self, bofs)
1183 * Transmit data using DMA
1186 static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
1188 int iobase = self->io.fir_base;
1191 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1194 register_bank(iobase, 0);
1195 outb(0x00, iobase + IRCC_LCR_B);
1197 register_bank(iobase, 1);
1198 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1199 iobase + IRCC_SCE_CFGB);
1201 self->io.direction = IO_XMIT;
1203 /* Set BOF additional count for generating the min turn time */
1204 register_bank(iobase, 4);
1205 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1206 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1207 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
1209 /* Set max Tx frame size */
1210 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1211 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
1213 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1215 /* Enable burst mode chip Tx DMA */
1216 register_bank(iobase, 1);
1217 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1218 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1220 /* Setup DMA controller (must be done after enabling chip DMA) */
1221 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1224 /* Enable interrupt */
1226 register_bank(iobase, 0);
1227 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1228 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1230 /* Enable transmit */
1231 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
1235 * Function smsc_ircc_dma_xmit_complete (self)
1237 * The transfer of a frame in finished. This function will only be called
1238 * by the interrupt handler
1241 static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
1243 int iobase = self->io.fir_base;
1245 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1248 register_bank(iobase, 0);
1249 outb(0x00, iobase + IRCC_LCR_B);
1251 register_bank(iobase, 1);
1252 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1253 iobase + IRCC_SCE_CFGB);
1255 /* Check for underrun! */
1256 register_bank(iobase, 0);
1257 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
1258 self->stats.tx_errors++;
1259 self->stats.tx_fifo_errors++;
1261 /* Reset error condition */
1262 register_bank(iobase, 0);
1263 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1264 outb(0x00, iobase + IRCC_MASTER);
1266 self->stats.tx_packets++;
1267 self->stats.tx_bytes += self->tx_buff.len;
1270 /* Check if it's time to change the speed */
1271 if (self->new_speed) {
1272 smsc_ircc_change_speed(self, self->new_speed);
1273 self->new_speed = 0;
1276 netif_wake_queue(self->netdev);
1280 * Function smsc_ircc_dma_receive(self)
1282 * Get ready for receiving a frame. The device will initiate a DMA
1283 * if it starts to receive a frame.
1286 static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
1288 int iobase = self->io.fir_base;
1290 /* Turn off chip DMA */
1291 register_bank(iobase, 1);
1292 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1293 iobase + IRCC_SCE_CFGB);
1297 register_bank(iobase, 0);
1298 outb(0x00, iobase + IRCC_LCR_B);
1300 /* Turn off chip DMA */
1301 register_bank(iobase, 1);
1302 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1303 iobase + IRCC_SCE_CFGB);
1305 self->io.direction = IO_RECV;
1306 self->rx_buff.data = self->rx_buff.head;
1308 /* Set max Rx frame size */
1309 register_bank(iobase, 4);
1310 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1311 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
1313 /* Setup DMA controller */
1314 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1317 /* Enable burst mode chip Rx DMA */
1318 register_bank(iobase, 1);
1319 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1320 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
1322 /* Enable interrupt */
1323 register_bank(iobase, 0);
1324 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1325 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1327 /* Enable receiver */
1328 register_bank(iobase, 0);
1329 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
1330 iobase + IRCC_LCR_B);
1336 * Function smsc_ircc_dma_receive_complete(self)
1338 * Finished with receiving frames
1341 static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
1343 struct sk_buff *skb;
1344 int len, msgcnt, lsr;
1345 int iobase = self->io.fir_base;
1347 register_bank(iobase, 0);
1349 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1352 register_bank(iobase, 0);
1353 outb(0x00, iobase + IRCC_LCR_B);
1355 register_bank(iobase, 0);
1356 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1357 lsr= inb(iobase + IRCC_LSR);
1358 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
1360 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1361 get_dma_residue(self->io.dma));
1363 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1365 /* Look for errors */
1366 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
1367 self->stats.rx_errors++;
1368 if (lsr & IRCC_LSR_FRAME_ERROR)
1369 self->stats.rx_frame_errors++;
1370 if (lsr & IRCC_LSR_CRC_ERROR)
1371 self->stats.rx_crc_errors++;
1372 if (lsr & IRCC_LSR_SIZE_ERROR)
1373 self->stats.rx_length_errors++;
1374 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1375 self->stats.rx_length_errors++;
1380 len -= self->io.speed < 4000000 ? 2 : 4;
1382 if (len < 2 || len > 2050) {
1383 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1386 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1388 skb = dev_alloc_skb(len + 1);
1390 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1394 /* Make sure IP header gets aligned */
1395 skb_reserve(skb, 1);
1397 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1398 self->stats.rx_packets++;
1399 self->stats.rx_bytes += len;
1401 skb->dev = self->netdev;
1402 skb->mac.raw = skb->data;
1403 skb->protocol = htons(ETH_P_IRDA);
1408 * Function smsc_ircc_sir_receive (self)
1410 * Receive one frame from the infrared port
1413 static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
1418 IRDA_ASSERT(self != NULL, return;);
1420 iobase = self->io.sir_base;
1423 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1424 * async_unwrap_char will deliver all found frames
1427 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
1428 inb(iobase + UART_RX));
1430 /* Make sure we don't stay here to long */
1431 if (boguscount++ > 32) {
1432 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1435 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
1440 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1442 * An interrupt from the chip has arrived. Time to do some work
1445 static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1447 struct net_device *dev = (struct net_device *) dev_id;
1448 struct smsc_ircc_cb *self;
1449 int iobase, iir, lcra, lsr;
1450 irqreturn_t ret = IRQ_NONE;
1453 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
1458 self = netdev_priv(dev);
1459 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1461 /* Serialise the interrupt handler in various CPUs, stop Tx path */
1462 spin_lock(&self->lock);
1464 /* Check if we should use the SIR interrupt handler */
1465 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1466 ret = smsc_ircc_interrupt_sir(dev);
1467 goto irq_ret_unlock;
1470 iobase = self->io.fir_base;
1472 register_bank(iobase, 0);
1473 iir = inb(iobase + IRCC_IIR);
1475 goto irq_ret_unlock;
1478 /* Disable interrupts */
1479 outb(0, iobase + IRCC_IER);
1480 lcra = inb(iobase + IRCC_LCR_A);
1481 lsr = inb(iobase + IRCC_LSR);
1483 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1485 if (iir & IRCC_IIR_EOM) {
1486 if (self->io.direction == IO_RECV)
1487 smsc_ircc_dma_receive_complete(self);
1489 smsc_ircc_dma_xmit_complete(self);
1491 smsc_ircc_dma_receive(self);
1494 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1495 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1498 /* Enable interrupts again */
1500 register_bank(iobase, 0);
1501 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1504 spin_unlock(&self->lock);
1510 * Function irport_interrupt_sir (irq, dev_id, regs)
1512 * Interrupt handler for SIR modes
1514 static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1516 struct smsc_ircc_cb *self = netdev_priv(dev);
1521 /* Already locked comming here in smsc_ircc_interrupt() */
1522 /*spin_lock(&self->lock);*/
1524 iobase = self->io.sir_base;
1526 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1530 /* Clear interrupt */
1531 lsr = inb(iobase + UART_LSR);
1533 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
1534 __FUNCTION__, iir, lsr, iobase);
1538 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1541 /* Receive interrupt */
1542 smsc_ircc_sir_receive(self);
1545 if (lsr & UART_LSR_THRE)
1546 /* Transmitter ready for data */
1547 smsc_ircc_sir_write_wakeup(self);
1550 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1555 /* Make sure we don't stay here to long */
1556 if (boguscount++ > 100)
1559 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
1561 /*spin_unlock(&self->lock);*/
1568 * Function ircc_is_receiving (self)
1570 * Return TRUE is we are currently receiving a frame
1573 static int ircc_is_receiving(struct smsc_ircc_cb *self)
1578 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1580 IRDA_ASSERT(self != NULL, return FALSE;);
1582 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1583 get_dma_residue(self->io.dma));
1585 status = (self->rx_buff.state != OUTSIDE_FRAME);
1591 static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1595 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1596 self->netdev->name, self->netdev);
1598 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
1599 __FUNCTION__, self->io.irq, error);
1604 static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1606 unsigned long flags;
1608 spin_lock_irqsave(&self->lock, flags);
1611 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1613 spin_unlock_irqrestore(&self->lock, flags);
1616 static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1618 int iobase = self->io.fir_base;
1619 unsigned long flags;
1621 spin_lock_irqsave(&self->lock, flags);
1623 register_bank(iobase, 0);
1624 outb(0, iobase + IRCC_IER);
1625 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1626 outb(0x00, iobase + IRCC_MASTER);
1628 spin_unlock_irqrestore(&self->lock, flags);
1633 * Function smsc_ircc_net_open (dev)
1638 static int smsc_ircc_net_open(struct net_device *dev)
1640 struct smsc_ircc_cb *self;
1643 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1645 IRDA_ASSERT(dev != NULL, return -1;);
1646 self = netdev_priv(dev);
1647 IRDA_ASSERT(self != NULL, return 0;);
1649 if (self->io.suspended) {
1650 IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
1654 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
1656 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1657 __FUNCTION__, self->io.irq);
1661 smsc_ircc_start_interrupts(self);
1663 /* Give self a hardware name */
1664 /* It would be cool to offer the chip revision here - Jean II */
1665 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1668 * Open new IrLAP layer instance, now that everything should be
1669 * initialized properly
1671 self->irlap = irlap_open(dev, &self->qos, hwname);
1674 * Always allocate the DMA channel after the IRQ,
1675 * and clean up on failure.
1677 if (request_dma(self->io.dma, dev->name)) {
1678 smsc_ircc_net_close(dev);
1680 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1681 __FUNCTION__, self->io.dma);
1685 netif_start_queue(dev);
1691 * Function smsc_ircc_net_close (dev)
1696 static int smsc_ircc_net_close(struct net_device *dev)
1698 struct smsc_ircc_cb *self;
1700 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1702 IRDA_ASSERT(dev != NULL, return -1;);
1703 self = netdev_priv(dev);
1704 IRDA_ASSERT(self != NULL, return 0;);
1707 netif_stop_queue(dev);
1709 /* Stop and remove instance of IrLAP */
1711 irlap_close(self->irlap);
1714 smsc_ircc_stop_interrupts(self);
1716 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1717 if (!self->io.suspended)
1718 free_irq(self->io.irq, dev);
1720 disable_dma(self->io.dma);
1721 free_dma(self->io.dma);
1726 static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
1728 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
1730 if (!self->io.suspended) {
1731 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1734 if (netif_running(self->netdev)) {
1735 netif_device_detach(self->netdev);
1736 smsc_ircc_stop_interrupts(self);
1737 free_irq(self->io.irq, self->netdev);
1738 disable_dma(self->io.dma);
1740 self->io.suspended = 1;
1747 static int smsc_ircc_resume(struct platform_device *dev)
1749 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
1751 if (self->io.suspended) {
1752 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
1755 smsc_ircc_init_chip(self);
1756 if (netif_running(self->netdev)) {
1757 if (smsc_ircc_request_irq(self)) {
1759 * Don't fail resume process, just kill this
1762 unregister_netdevice(self->netdev);
1764 enable_dma(self->io.dma);
1765 smsc_ircc_start_interrupts(self);
1766 netif_device_attach(self->netdev);
1769 self->io.suspended = 0;
1776 * Function smsc_ircc_close (self)
1778 * Close driver instance
1781 static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1783 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1785 IRDA_ASSERT(self != NULL, return -1;);
1787 platform_device_unregister(self->pldev);
1789 /* Remove netdevice */
1790 unregister_netdev(self->netdev);
1792 smsc_ircc_stop_interrupts(self);
1794 /* Release the PORTS that this driver is using */
1795 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1798 release_region(self->io.fir_base, self->io.fir_ext);
1800 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1803 release_region(self->io.sir_base, self->io.sir_ext);
1805 if (self->tx_buff.head)
1806 dma_free_coherent(NULL, self->tx_buff.truesize,
1807 self->tx_buff.head, self->tx_buff_dma);
1809 if (self->rx_buff.head)
1810 dma_free_coherent(NULL, self->rx_buff.truesize,
1811 self->rx_buff.head, self->rx_buff_dma);
1813 free_netdev(self->netdev);
1818 static void __exit smsc_ircc_cleanup(void)
1822 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1824 for (i = 0; i < 2; i++) {
1826 smsc_ircc_close(dev_self[i]);
1829 platform_driver_unregister(&smsc_ircc_driver);
1833 * Start SIR operations
1835 * This function *must* be called with spinlock held, because it may
1836 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1838 void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1840 struct net_device *dev;
1841 int fir_base, sir_base;
1843 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1845 IRDA_ASSERT(self != NULL, return;);
1847 IRDA_ASSERT(dev != NULL, return;);
1848 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1850 fir_base = self->io.fir_base;
1851 sir_base = self->io.sir_base;
1853 /* Reset everything */
1854 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
1856 #if SMSC_IRCC2_C_SIR_STOP
1857 /*smsc_ircc_sir_stop(self);*/
1860 register_bank(fir_base, 1);
1861 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
1863 /* Initialize UART */
1864 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1865 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
1867 /* Turn on interrups */
1868 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
1870 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1872 outb(0x00, fir_base + IRCC_MASTER);
1875 #if SMSC_IRCC2_C_SIR_STOP
1876 void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1880 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1881 iobase = self->io.sir_base;
1884 outb(0, iobase + UART_MCR);
1886 /* Turn off interrupts */
1887 outb(0, iobase + UART_IER);
1892 * Function smsc_sir_write_wakeup (self)
1894 * Called by the SIR interrupt handler when there's room for more data.
1895 * If we have more packets to send, we send them here.
1898 static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1904 IRDA_ASSERT(self != NULL, return;);
1906 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1908 iobase = self->io.sir_base;
1910 /* Finished with frame? */
1911 if (self->tx_buff.len > 0) {
1912 /* Write data left in transmit buffer */
1913 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
1914 self->tx_buff.data, self->tx_buff.len);
1915 self->tx_buff.data += actual;
1916 self->tx_buff.len -= actual;
1919 /*if (self->tx_buff.len ==0) {*/
1922 * Now serial buffer is almost free & we can start
1923 * transmission of another packet. But first we must check
1924 * if we need to change the speed of the hardware
1926 if (self->new_speed) {
1927 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1928 __FUNCTION__, self->new_speed);
1929 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1930 smsc_ircc_change_speed(self, self->new_speed);
1931 self->new_speed = 0;
1933 /* Tell network layer that we want more frames */
1934 netif_wake_queue(self->netdev);
1936 self->stats.tx_packets++;
1938 if (self->io.speed <= 115200) {
1940 * Reset Rx FIFO to make sure that all reflected transmit data
1941 * is discarded. This is needed for half duplex operation
1943 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1944 fcr |= self->io.speed < 38400 ?
1945 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1947 outb(fcr, iobase + UART_FCR);
1949 /* Turn on receive interrupts */
1950 outb(UART_IER_RDI, iobase + UART_IER);
1956 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1958 * Fill Tx FIFO with transmit data
1961 static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1965 /* Tx FIFO should be empty! */
1966 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
1967 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1971 /* Fill FIFO with current frame */
1972 while (fifo_size-- > 0 && actual < len) {
1973 /* Transmit next byte */
1974 outb(buf[actual], iobase + UART_TX);
1981 * Function smsc_ircc_is_receiving (self)
1983 * Returns true is we are currently receiving data
1986 static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
1988 return (self->rx_buff.state != OUTSIDE_FRAME);
1993 * Function smsc_ircc_probe_transceiver(self)
1995 * Tries to find the used Transceiver
1998 static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2002 IRDA_ASSERT(self != NULL, return;);
2004 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2005 if (smsc_transceivers[i].probe(self->io.fir_base)) {
2006 IRDA_MESSAGE(" %s transceiver found\n",
2007 smsc_transceivers[i].name);
2008 self->transceiver= i + 1;
2012 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2013 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
2015 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
2020 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2022 * Set the transceiver according to the speed
2025 static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2029 trx = self->transceiver;
2031 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
2035 * Function smsc_ircc_wait_hw_transmitter_finish ()
2037 * Wait for the real end of HW transmission
2039 * The UART is a strict FIFO, and we get called only when we have finished
2040 * pushing data to the FIFO, so the maximum amount of time we must wait
2041 * is only for the FIFO to drain out.
2043 * We use a simple calibrated loop. We may need to adjust the loop
2044 * delay (udelay) to balance I/O traffic and latency. And we also need to
2045 * adjust the maximum timeout.
2046 * It would probably be better to wait for the proper interrupt,
2047 * but it doesn't seem to be available.
2049 * We can't use jiffies or kernel timers because :
2050 * 1) We are called from the interrupt handler, which disable softirqs,
2051 * so jiffies won't be increased
2052 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2053 * want to wait that long to detect stuck hardware.
2057 static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2059 int iobase = self->io.sir_base;
2060 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
2062 /* Calibrated busy loop */
2063 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
2067 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
2076 static int __init smsc_ircc_look_for_chips(void)
2078 struct smsc_chip_address *address;
2080 unsigned int cfg_base, found;
2083 address = possible_addresses;
2085 while (address->cfg_base) {
2086 cfg_base = address->cfg_base;
2088 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
2090 if (address->type & SMSCSIO_TYPE_FDC) {
2092 if (address->type & SMSCSIO_TYPE_FLAT)
2093 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2096 if (address->type & SMSCSIO_TYPE_PAGED)
2097 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2100 if (address->type & SMSCSIO_TYPE_LPC) {
2102 if (address->type & SMSCSIO_TYPE_FLAT)
2103 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2106 if (address->type & SMSCSIO_TYPE_PAGED)
2107 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2116 * Function smsc_superio_flat (chip, base, type)
2118 * Try to get configuration of a smc SuperIO chip with flat register model
2121 static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
2123 unsigned short firbase, sirbase;
2127 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2129 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
2132 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
2133 mode = inb(cfgbase + 1);
2135 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
2137 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
2138 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2140 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
2141 sirbase = inb(cfgbase + 1) << 2;
2144 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
2145 firbase = inb(cfgbase + 1) << 3;
2148 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
2149 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
2152 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
2153 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2155 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2157 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2160 /* Exit configuration */
2161 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2167 * Function smsc_superio_paged (chip, base, type)
2169 * Try to get configuration of a smc SuperIO chip with paged register model
2172 static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
2174 unsigned short fir_io, sir_io;
2177 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2179 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
2182 /* Select logical device (UART2) */
2183 outb(0x07, cfg_base);
2184 outb(0x05, cfg_base + 1);
2187 outb(0x60, cfg_base);
2188 sir_io = inb(cfg_base + 1) << 8;
2189 outb(0x61, cfg_base);
2190 sir_io |= inb(cfg_base + 1);
2193 outb(0x62, cfg_base);
2194 fir_io = inb(cfg_base + 1) << 8;
2195 outb(0x63, cfg_base);
2196 fir_io |= inb(cfg_base + 1);
2197 outb(0x2b, cfg_base); /* ??? */
2199 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2202 /* Exit configuration */
2203 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2209 static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
2211 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2213 outb(reg, cfg_base);
2214 return inb(cfg_base) != reg ? -1 : 0;
2217 static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
2219 u8 devid, xdevid, rev;
2221 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2223 /* Leave configuration */
2225 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2227 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2230 outb(reg, cfg_base);
2232 xdevid = inb(cfg_base + 1);
2234 /* Enter configuration */
2236 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2239 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2243 /* probe device ID */
2245 if (smsc_access(cfg_base, reg))
2248 devid = inb(cfg_base + 1);
2250 if (devid == 0 || devid == 0xff) /* typical values for unused port */
2253 /* probe revision ID */
2255 if (smsc_access(cfg_base, reg + 1))
2258 rev = inb(cfg_base + 1);
2260 if (rev >= 128) /* i think this will make no sense */
2263 if (devid == xdevid) /* protection against false positives */
2266 /* Check for expected device ID; are there others? */
2268 while (chip->devid != devid) {
2272 if (chip->name == NULL)
2276 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2277 devid, rev, cfg_base, type, chip->name);
2279 if (chip->rev > rev) {
2280 IRDA_MESSAGE("Revision higher than expected\n");
2284 if (chip->flags & NoIRDA)
2285 IRDA_MESSAGE("chipset does not support IRDA\n");
2290 static int __init smsc_superio_fdc(unsigned short cfg_base)
2294 if (!request_region(cfg_base, 2, driver_name)) {
2295 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2296 __FUNCTION__, cfg_base);
2298 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2299 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
2302 release_region(cfg_base, 2);
2308 static int __init smsc_superio_lpc(unsigned short cfg_base)
2312 if (!request_region(cfg_base, 2, driver_name)) {
2313 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2314 __FUNCTION__, cfg_base);
2316 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2317 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
2320 release_region(cfg_base, 2);
2326 * Look for some specific subsystem setups that need
2327 * pre-configuration not properly done by the BIOS (especially laptops)
2328 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2329 * and tosh2450-smcinit.c. The table lists the device entries
2330 * for ISA bridges with an LPC (Local Peripheral Configurator)
2331 * that are in turn used to configure the SMSC device with default
2332 * SIR and FIR I/O ports, DMA and IRQ.
2335 #define PCIID_VENDOR_INTEL 0x8086
2336 #define PCIID_VENDOR_ALI 0x10b9
2337 static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __devinitdata = {
2339 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2341 .subvendor = 0x103c,
2342 .subdevice = 0x088c,
2343 .sir_io = 0x02f8, /* Quite certain these are the same for nc8000 as for nc6000 */
2348 .preconfigure = preconfigure_through_82801,
2349 .name = "HP nc8000",
2352 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2354 .subvendor = 0x103c,
2355 .subdevice = 0x0890,
2361 .preconfigure = preconfigure_through_82801,
2362 .name = "HP nc6000",
2365 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
2367 .subvendor = 0x1179,
2368 .subdevice = 0xffff, /* 0xffff is "any", Not sure, 0x0001 or 0x0002 */
2374 .preconfigure = preconfigure_through_82801,
2375 .name = "Toshiba Satellite 2450",
2378 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801CAM ISA bridge */
2379 .device = 0x248c, /* Some use 24cc? */
2380 .subvendor = 0x1179,
2381 .subdevice = 0xffff, /* 0xffff is "any", Not sure, 0x0001 or 0x0002 */
2387 .preconfigure = preconfigure_through_82801,
2388 .name = "Toshiba Satellite 5100/5200, Tecra 9100",
2391 .vendor = PCIID_VENDOR_ALI, /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
2393 .subvendor = 0x1179,
2394 .subdevice = 0xffff, /* 0xffff is "any", Not sure, 0x0001 or 0x0002 */
2400 .preconfigure = preconfigure_through_ali,
2401 .name = "Toshiba Satellite 1800",
2408 * This sets up the basic SMSC parameters (FIR port, SIR port, FIR DMA, FIR IRQ)
2409 * through the chip configuration port.
2411 static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf)
2413 unsigned short iobase = conf->cfg_base;
2414 unsigned char tmpbyte;
2416 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2417 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2418 tmpbyte = inb(iobase +1); // Read device ID
2419 IRDA_DEBUG(0, "Detected Chip id: 0x%02x, setting up registers...\n",tmpbyte);
2421 /* Disable UART1 and set up SIR I/O port */
2422 outb(0x24, iobase); // select CR24 - UART1 base addr
2423 outb(0x00, iobase + 1); // disable UART1
2424 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2425 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2426 tmpbyte = inb(iobase + 1);
2427 if (tmpbyte != (conf->sir_io >> 2) ) {
2428 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
2432 /* Set up FIR IRQ channel for UART2 */
2433 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2434 tmpbyte = inb(iobase + 1);
2435 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2436 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2437 outb(tmpbyte, iobase + 1);
2438 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2439 if (tmpbyte != conf->fir_irq) {
2440 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2444 /* Set up FIR I/O port */
2445 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2446 outb((conf->fir_io >> 3), iobase + 1);
2447 tmpbyte = inb(iobase + 1);
2448 if (tmpbyte != (conf->fir_io >> 3) ) {
2449 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2453 /* Set up FIR DMA channel */
2454 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2455 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2456 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2457 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2458 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2462 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2463 tmpbyte = inb(iobase + 1);
2464 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK | SMSCSIOFLAT_UART2MODE_VAL_IRDA;
2465 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2467 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2468 tmpbyte = inb(iobase + 1);
2469 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2471 /* This one was not part of tosh1800 */
2472 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2473 tmpbyte = inb(iobase + 1);
2474 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2476 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2477 tmpbyte = inb(iobase + 1);
2478 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2480 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2481 tmpbyte = inb(iobase + 1);
2482 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2484 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2489 /* 82801CAM registers */
2492 #define PIRQA_ROUT 0x60
2493 #define PCI_DMA_C 0x90
2494 #define COM_DEC 0xe0
2496 #define GEN2_DEC 0xec
2498 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge or
2499 * Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge. They all work the same way!
2501 static int __init preconfigure_through_82801(struct pci_dev *dev,
2502 struct smsc_ircc_subsystem_configuration *conf)
2504 unsigned short tmpword;
2507 IRDA_MESSAGE("Setting up the SMSC device via the 82801 controller.\n");
2508 pci_write_config_byte(dev, COM_DEC, 0x10);
2511 pci_read_config_word(dev, LPC_EN, &tmpword); /* LPC_EN register */
2512 tmpword &= 0xfffd; /* mask bit 1 */
2513 tmpword |= 0x0001; /* set bit 0 : COMA addr range enable */
2514 pci_write_config_word(dev, LPC_EN, tmpword);
2517 pci_write_config_word(dev, PCI_DMA_C, 0xc0c0); /* LPC I/F DMA on, channel 3 -- rtm (?? PCI DMA ?) */
2518 pci_write_config_word(dev, GEN2_DEC, 0x131); /* LPC I/F 2nd decode range */
2520 /* Pre-configure chip */
2521 ret = preconfigure_smsc_chip(conf);
2524 pci_read_config_word(dev, LPC_EN, &tmpword); /* LPC_EN register */
2525 tmpword &= 0xfffc; /* mask bit 1 and bit 0, COMA addr range disable */
2526 pci_write_config_word(dev, LPC_EN, tmpword);
2530 static int __init preconfigure_through_ali(struct pci_dev *dev,
2531 struct smsc_ircc_subsystem_configuration *conf)
2533 /* TODO: put in ALi 1533 configuration here. */
2534 IRDA_MESSAGE("SORRY: %s has an unsupported bridge controller (ALi): not pre-configured.\n", conf->name);
2538 static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
2539 unsigned short ircc_fir,
2540 unsigned short ircc_sir,
2541 unsigned char ircc_dma,
2542 unsigned char ircc_irq)
2544 struct pci_dev *dev = NULL;
2545 unsigned short ss_vendor = 0x0000;
2546 unsigned short ss_device = 0x0000;
2549 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2551 while (dev != NULL) {
2552 struct smsc_ircc_subsystem_configuration *conf;
2555 * Cache the subsystem vendor/device: some manufacturers fail to set
2556 * this for all components, so we save it in case there is just
2557 * 0x0000 0x0000 on the device we want to check.
2559 if (dev->subsystem_vendor != 0x0000U) {
2560 ss_vendor = dev->subsystem_vendor;
2561 ss_device = dev->subsystem_device;
2563 conf = subsystem_configurations;
2564 for( ; conf->subvendor; conf++) {
2565 if(conf->vendor == dev->vendor &&
2566 conf->device == dev->device &&
2567 conf->subvendor == ss_vendor && /* Sometimes these are cached values */
2568 (conf->subdevice == ss_device || conf->subdevice == 0xffff)) {
2569 struct smsc_ircc_subsystem_configuration tmpconf;
2571 memcpy(&tmpconf, conf, sizeof(struct smsc_ircc_subsystem_configuration));
2573 /* Override the default values with anything passed in as parameter */
2575 tmpconf.cfg_base = ircc_cfg;
2577 tmpconf.fir_io = ircc_fir;
2579 tmpconf.sir_io = ircc_sir;
2580 if (ircc_dma != 0xff)
2581 tmpconf.fir_dma = ircc_dma;
2582 if (ircc_irq != 0xff)
2583 tmpconf.fir_irq = ircc_irq;
2585 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2586 if (conf->preconfigure)
2587 ret = conf->preconfigure(dev, &tmpconf);
2592 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2597 #endif // CONFIG_PCI
2599 /************************************************
2601 * Transceivers specific functions
2603 ************************************************/
2607 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2609 * Program transceiver through smsc-ircc ATC circuitry
2613 static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2615 unsigned long jiffies_now, jiffies_timeout;
2618 jiffies_now = jiffies;
2619 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
2622 register_bank(fir_base, 4);
2623 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2624 fir_base + IRCC_ATC);
2626 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2627 !time_after(jiffies, jiffies_timeout))
2631 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
2632 inb(fir_base + IRCC_ATC));
2636 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2638 * Probe transceiver smsc-ircc ATC circuitry
2642 static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2648 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2654 static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2665 fast_mode = IRCC_LCR_A_FAST;
2668 register_bank(fir_base, 0);
2669 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2673 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2679 static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2685 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2691 static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2702 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2706 /* This causes an interrupt */
2707 register_bank(fir_base, 0);
2708 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
2712 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2718 static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2724 module_init(smsc_ircc_init);
2725 module_exit(smsc_ircc_cleanup);