blob: 1d249737f96ff17e5128f4311bc5faed2369e513 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
2 * $Id: smsc-ircc2.c,v 1.19.2.5 2002/10/27 11:34:26 dip Exp $
3 *
4 * Description: Driver for the SMC Infrared Communications Controller
5 * Status: Experimental.
6 * Author: Daniele Peri (peri@csai.unipa.it)
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07007 * Created at:
8 * Modified at:
9 * Modified by:
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * Copyright (c) 2002 Daniele Peri
12 * All Rights Reserved.
13 * Copyright (c) 2002 Jean Tourrilhes
Linus Walleijc1e14a62006-04-05 22:33:59 -070014 * Copyright (c) 2006 Linus Walleij
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 *
16 *
17 * Based on smc-ircc.c:
18 *
19 * Copyright (c) 2001 Stefani Seibold
20 * Copyright (c) 1999-2001 Dag Brattli
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070021 * Copyright (c) 1998-1999 Thomas Davis,
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 *
23 * and irport.c:
24 *
25 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
26 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070027 *
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * the License, or (at your option) any later version.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070032 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 * 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.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070037 *
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,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * MA 02111-1307 USA
42 *
43 ********************************************************************/
44
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>
David Brownelld94c77b2006-05-09 15:26:11 -070057#include <linux/pnp.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010058#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60#include <asm/io.h>
61#include <asm/dma.h>
62#include <asm/byteorder.h>
63
64#include <linux/spinlock.h>
65#include <linux/pm.h>
Linus Walleijc1e14a62006-04-05 22:33:59 -070066#ifdef CONFIG_PCI
67#include <linux/pci.h>
68#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
70#include <net/irda/wrapper.h>
71#include <net/irda/irda.h>
72#include <net/irda/irda_device.h>
73
74#include "smsc-ircc2.h"
75#include "smsc-sio.h"
76
Dmitry Torokhov98b77772005-09-06 15:19:19 -070077
78MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
79MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
80MODULE_LICENSE("GPL");
81
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070082#define DMA_INVAL 255
83static int ircc_dma = DMA_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070084module_param(ircc_dma, int, 0);
85MODULE_PARM_DESC(ircc_dma, "DMA channel");
86
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070087#define IRQ_INVAL 255
88static int ircc_irq = IRQ_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070089module_param(ircc_irq, int, 0);
90MODULE_PARM_DESC(ircc_irq, "IRQ line");
91
92static int ircc_fir;
93module_param(ircc_fir, int, 0);
94MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
95
96static int ircc_sir;
97module_param(ircc_sir, int, 0);
98MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
99
100static int ircc_cfg;
101module_param(ircc_cfg, int, 0);
102MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
103
104static int ircc_transceiver;
105module_param(ircc_transceiver, int, 0);
106MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108/* Types */
109
Linus Walleijc1e14a62006-04-05 22:33:59 -0700110#ifdef CONFIG_PCI
111struct smsc_ircc_subsystem_configuration {
112 unsigned short vendor; /* PCI vendor ID */
113 unsigned short device; /* PCI vendor ID */
114 unsigned short subvendor; /* PCI subsystem vendor ID */
115 unsigned short subdevice; /* PCI sybsystem device ID */
116 unsigned short sir_io; /* I/O port for SIR */
117 unsigned short fir_io; /* I/O port for FIR */
118 unsigned char fir_irq; /* FIR IRQ */
119 unsigned char fir_dma; /* FIR DMA */
120 unsigned short cfg_base; /* I/O port for chip configuration */
121 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
122 const char *name; /* name shown as info */
123};
124#endif
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126struct smsc_transceiver {
127 char *name;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700128 void (*set_for_speed)(int fir_base, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 int (*probe)(int fir_base);
130};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132struct smsc_chip {
133 char *name;
134 #if 0
135 u8 type;
136 #endif
137 u16 flags;
138 u8 devid;
139 u8 rev;
140};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142struct smsc_chip_address {
143 unsigned int cfg_base;
144 unsigned int type;
145};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147/* Private data for each instance */
148struct smsc_ircc_cb {
149 struct net_device *netdev; /* Yes! we are some kind of netdevice */
150 struct net_device_stats stats;
151 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 chipio_t io; /* IrDA controller information */
154 iobuff_t tx_buff; /* Transmit buffer */
155 iobuff_t rx_buff; /* Receive buffer */
156 dma_addr_t tx_buff_dma;
157 dma_addr_t rx_buff_dma;
158
159 struct qos_info qos; /* QoS capabilities for this device */
160
161 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 __u32 new_speed;
164 __u32 flags; /* Interface flags */
165
166 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
167 int tx_len; /* Number of frames in tx_buff */
168
169 int transceiver;
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700170 struct platform_device *pldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173/* Constants */
174
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700175#define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
178#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700179#define SMSC_IRCC2_C_NET_TIMEOUT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#define SMSC_IRCC2_C_SIR_STOP 0
181
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700182static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* Prototypes */
185
186static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
187static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
188static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
189static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
190static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
191static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700192static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
193static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
195static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
196static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700197static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
198static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -0700199static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
200static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
David Howells7d12e782006-10-05 14:55:46 +0100201static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
203static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
204#if SMSC_IRCC2_C_SIR_STOP
205static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
206#endif
207static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
208static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
209static int smsc_ircc_net_open(struct net_device *dev);
210static int smsc_ircc_net_close(struct net_device *dev);
211static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
212#if SMSC_IRCC2_C_NET_TIMEOUT
213static void smsc_ircc_timeout(struct net_device *dev);
214#endif
215static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
217static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
218static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
219static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
220
221/* Probing */
222static int __init smsc_ircc_look_for_chips(void);
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700223static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
224static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
225static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226static int __init smsc_superio_fdc(unsigned short cfg_base);
227static int __init smsc_superio_lpc(unsigned short cfg_base);
Linus Walleijc1e14a62006-04-05 22:33:59 -0700228#ifdef CONFIG_PCI
229static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
230static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
Linus Walleij08d09992006-04-14 16:03:33 -0700231static void __init preconfigure_ali_port(struct pci_dev *dev,
232 unsigned short port);
Linus Walleijc1e14a62006-04-05 22:33:59 -0700233static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
234static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
235 unsigned short ircc_fir,
236 unsigned short ircc_sir,
237 unsigned char ircc_dma,
238 unsigned char ircc_irq);
239#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
241/* Transceivers specific functions */
242
243static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
244static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
245static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
246static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
247static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
248static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
249
250/* Power Management */
251
Russell King3ae5eae2005-11-09 22:32:44 +0000252static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
253static int smsc_ircc_resume(struct platform_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Russell King3ae5eae2005-11-09 22:32:44 +0000255static struct platform_driver smsc_ircc_driver = {
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700256 .suspend = smsc_ircc_suspend,
257 .resume = smsc_ircc_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000258 .driver = {
259 .name = SMSC_IRCC2_DRIVER_NAME,
260 },
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700261};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263/* Transceivers for SMSC-ircc */
264
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700265static struct smsc_transceiver smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700267 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
268 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
269 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
270 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700272#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
274/* SMC SuperIO chipsets definitions */
275
276#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
277#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
278#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
279#define SIR 0 /* SuperIO Chip has only slow IRDA */
280#define FIR 4 /* SuperIO Chip has fast IRDA */
281#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
282
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700283static struct smsc_chip __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
285 /* Base address 0x3f0 or 0x370 */
286 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
287 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
288 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
289 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
290 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
291 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
292 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
293 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
294 { NULL }
295};
296
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700297static struct smsc_chip __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
299 /* Base address 0x3f0 or 0x370 */
300 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
301 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
302 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
303 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
304 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
305 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
306 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
307 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
308 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
309 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
310 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
311 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
312 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
313 { NULL }
314};
315
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700316static struct smsc_chip __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
318 /* Base address 0x2E or 0x4E */
319 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
Peter Kovarafdf27c2007-03-16 20:39:25 -0700320 { "47N227", KEY55_1|FIR|SERx4, 0x7a, 0x00 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
322 { NULL }
323};
324
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700325static struct smsc_chip __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 /* Base address 0x2E or 0x4E */
328 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
329 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
330 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
331 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
332 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
333 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
334 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
335 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
336 { NULL }
337};
338
339#define SMSCSIO_TYPE_FDC 1
340#define SMSCSIO_TYPE_LPC 2
341#define SMSCSIO_TYPE_FLAT 4
342#define SMSCSIO_TYPE_PAGED 8
343
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700344static struct smsc_chip_address __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700346 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
347 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
348 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
349 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
350 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
351 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352};
353
354/* Globals */
355
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700356static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
357static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359static inline void register_bank(int iobase, int bank)
360{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700361 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
362 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363}
364
David Brownelld94c77b2006-05-09 15:26:11 -0700365#ifdef CONFIG_PNP
366/* PNP hotplug support */
367static const struct pnp_device_id smsc_ircc_pnp_table[] = {
368 { .id = "SMCf010", .driver_data = 0 },
369 /* and presumably others */
370 { }
371};
372MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
373#endif
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376/*******************************************************************************
377 *
378 *
379 * SMSC-ircc stuff
380 *
381 *
382 *******************************************************************************/
383
384/*
385 * Function smsc_ircc_init ()
386 *
387 * Initialize chip. Just try to find out how many chips we are dealing with
388 * and where they are
389 */
390static int __init smsc_ircc_init(void)
391{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700392 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
394 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
395
Russell King3ae5eae2005-11-09 22:32:44 +0000396 ret = platform_driver_register(&smsc_ircc_driver);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700397 if (ret) {
398 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
399 return ret;
400 }
401
Linus Walleijc1e14a62006-04-05 22:33:59 -0700402#ifdef CONFIG_PCI
403 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
404 /* Ignore errors from preconfiguration */
405 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
406 }
407#endif
408
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700409 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700410
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700411 if (ircc_fir > 0 && ircc_sir > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
413 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
414
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700415 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
416 ret = -ENODEV;
417 } else {
Brice Goglin505db032005-09-06 15:19:25 -0700418 ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700420 /* try user provided configuration register base address */
421 if (ircc_cfg > 0) {
422 IRDA_MESSAGE(" Overriding configuration address "
423 "0x%04x\n", ircc_cfg);
424 if (!smsc_superio_fdc(ircc_cfg))
425 ret = 0;
426 if (!smsc_superio_lpc(ircc_cfg))
427 ret = 0;
428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700430 if (smsc_ircc_look_for_chips() > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 ret = 0;
432 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700433
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700434 if (ret)
Russell King3ae5eae2005-11-09 22:32:44 +0000435 platform_driver_unregister(&smsc_ircc_driver);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 return ret;
438}
439
440/*
441 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
442 *
443 * Try to open driver instance
444 *
445 */
446static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
447{
448 struct smsc_ircc_cb *self;
449 struct net_device *dev;
450 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700451
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
453
454 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700455 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700459 if (dev_count >= ARRAY_SIZE(dev_self)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
461 goto err_out1;
462 }
463
464 /*
465 * Allocate new instance of the driver
466 */
467 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
468 if (!dev) {
469 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
470 goto err_out1;
471 }
472
473 SET_MODULE_OWNER(dev);
474
475 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
476#if SMSC_IRCC2_C_NET_TIMEOUT
477 dev->tx_timeout = smsc_ircc_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700478 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479#endif
480 dev->open = smsc_ircc_net_open;
481 dev->stop = smsc_ircc_net_close;
482 dev->do_ioctl = smsc_ircc_net_ioctl;
483 dev->get_stats = smsc_ircc_net_get_stats;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700484
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700485 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 self->netdev = dev;
487
488 /* Make ifconfig display some details */
489 dev->base_addr = self->io.fir_base = fir_base;
490 dev->irq = self->io.irq = irq;
491
492 /* Need to store self somewhere */
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700493 dev_self[dev_count] = self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 spin_lock_init(&self->lock);
495
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700496 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
498
499 self->rx_buff.head =
500 dma_alloc_coherent(NULL, self->rx_buff.truesize,
501 &self->rx_buff_dma, GFP_KERNEL);
502 if (self->rx_buff.head == NULL) {
503 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
504 driver_name);
505 goto err_out2;
506 }
507
508 self->tx_buff.head =
509 dma_alloc_coherent(NULL, self->tx_buff.truesize,
510 &self->tx_buff_dma, GFP_KERNEL);
511 if (self->tx_buff.head == NULL) {
512 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
513 driver_name);
514 goto err_out3;
515 }
516
517 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
518 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
519
520 self->rx_buff.in_frame = FALSE;
521 self->rx_buff.state = OUTSIDE_FRAME;
522 self->tx_buff.data = self->tx_buff.head;
523 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700524
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700528
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700529 if (ircc_transceiver > 0 &&
530 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 self->transceiver = ircc_transceiver;
532 else
533 smsc_ircc_probe_transceiver(self);
534
535 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700536 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 IRDA_ERROR("%s, Network device registration failed!\n",
538 driver_name);
539 goto err_out4;
540 }
541
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700542 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
543 dev_count, NULL, 0);
544 if (IS_ERR(self->pldev)) {
545 err = PTR_ERR(self->pldev);
546 goto err_out5;
547 }
Russell King3ae5eae2005-11-09 22:32:44 +0000548 platform_set_drvdata(self->pldev, self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
550 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700551 dev_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700554
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700555 err_out5:
556 unregister_netdev(self->netdev);
557
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 err_out4:
559 dma_free_coherent(NULL, self->tx_buff.truesize,
560 self->tx_buff.head, self->tx_buff_dma);
561 err_out3:
562 dma_free_coherent(NULL, self->rx_buff.truesize,
563 self->rx_buff.head, self->rx_buff_dma);
564 err_out2:
565 free_netdev(self->netdev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700566 dev_self[dev_count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 err_out1:
568 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
569 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
570 err_out:
571 return err;
572}
573
574/*
575 * Function smsc_ircc_present(fir_base, sir_base)
576 *
577 * Check the smsc-ircc chip presence
578 *
579 */
580static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
581{
582 unsigned char low, high, chip, config, dma, irq, version;
583
584 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
585 driver_name)) {
586 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
587 __FUNCTION__, fir_base);
588 goto out1;
589 }
590
591 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
592 driver_name)) {
593 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
594 __FUNCTION__, sir_base);
595 goto out2;
596 }
597
598 register_bank(fir_base, 3);
599
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700600 high = inb(fir_base + IRCC_ID_HIGH);
601 low = inb(fir_base + IRCC_ID_LOW);
602 chip = inb(fir_base + IRCC_CHIP_ID);
603 version = inb(fir_base + IRCC_VERSION);
604 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 dma = config & IRCC_INTERFACE_DMA_MASK;
606 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
607
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700608 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700609 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 __FUNCTION__, fir_base);
611 goto out3;
612 }
613 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
614 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
615 chip & 0x0f, version, fir_base, sir_base, dma, irq);
616
617 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 out3:
620 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
621 out2:
622 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
623 out1:
624 return -ENODEV;
625}
626
627/*
628 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
629 *
630 * Setup I/O
631 *
632 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700633static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
634 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 u8 dma, u8 irq)
636{
637 unsigned char config, chip_dma, chip_irq;
638
639 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700640 config = inb(fir_base + IRCC_INTERFACE);
641 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
642 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 self->io.fir_base = fir_base;
645 self->io.sir_base = sir_base;
646 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
647 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
648 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
649 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
650
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700651 if (irq != IRQ_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (irq != chip_irq)
653 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
654 driver_name, chip_irq, irq);
655 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700656 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700658
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700659 if (dma != DMA_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 if (dma != chip_dma)
661 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
662 driver_name, chip_dma, dma);
663 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700664 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 self->io.dma = chip_dma;
666
667}
668
669/*
670 * Function smsc_ircc_setup_qos(self)
671 *
672 * Setup qos
673 *
674 */
675static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
676{
677 /* Initialize QoS for this device */
678 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700679
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
681 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
682
683 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
684 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
685 irda_qos_bits_to_value(&self->qos);
686}
687
688/*
689 * Function smsc_ircc_init_chip(self)
690 *
691 * Init chip
692 *
693 */
694static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
695{
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800696 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700699 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
700 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
702 register_bank(iobase, 1);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800703 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700704 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
706#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700707 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
708 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700709#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700710 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
711 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700712#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700713 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
714 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700715
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 register_bank(iobase, 4);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800717 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 register_bank(iobase, 0);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800720 outb(0, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
722 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700725 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
727
728/*
729 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
730 *
731 * Process IOCTL commands for this device
732 *
733 */
734static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
735{
736 struct if_irda_req *irq = (struct if_irda_req *) rq;
737 struct smsc_ircc_cb *self;
738 unsigned long flags;
739 int ret = 0;
740
741 IRDA_ASSERT(dev != NULL, return -1;);
742
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700743 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744
745 IRDA_ASSERT(self != NULL, return -1;);
746
747 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700748
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 switch (cmd) {
750 case SIOCSBANDWIDTH: /* Set bandwidth */
751 if (!capable(CAP_NET_ADMIN))
752 ret = -EPERM;
753 else {
754 /* Make sure we are the only one touching
755 * self->io.speed and the hardware - Jean II */
756 spin_lock_irqsave(&self->lock, flags);
757 smsc_ircc_change_speed(self, irq->ifr_baudrate);
758 spin_unlock_irqrestore(&self->lock, flags);
759 }
760 break;
761 case SIOCSMEDIABUSY: /* Set media busy */
762 if (!capable(CAP_NET_ADMIN)) {
763 ret = -EPERM;
764 break;
765 }
766
767 irda_device_set_media_busy(self->netdev, TRUE);
768 break;
769 case SIOCGRECEIVING: /* Check if we are receiving right now */
770 irq->ifr_receiving = smsc_ircc_is_receiving(self);
771 break;
772 #if 0
773 case SIOCSDTRRTS:
774 if (!capable(CAP_NET_ADMIN)) {
775 ret = -EPERM;
776 break;
777 }
778 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
779 break;
780 #endif
781 default:
782 ret = -EOPNOTSUPP;
783 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return ret;
786}
787
788static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
789{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700790 struct smsc_ircc_cb *self = netdev_priv(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 return &self->stats;
793}
794
795#if SMSC_IRCC2_C_NET_TIMEOUT
796/*
797 * Function smsc_ircc_timeout (struct net_device *dev)
798 *
799 * The networking timeout management.
800 *
801 */
802
803static void smsc_ircc_timeout(struct net_device *dev)
804{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700805 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 unsigned long flags;
807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
809 dev->name, self->io.speed);
810 spin_lock_irqsave(&self->lock, flags);
811 smsc_ircc_sir_start(self);
812 smsc_ircc_change_speed(self, self->io.speed);
813 dev->trans_start = jiffies;
814 netif_wake_queue(dev);
815 spin_unlock_irqrestore(&self->lock, flags);
816}
817#endif
818
819/*
820 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
821 *
822 * Transmits the current frame until FIFO is full, then
823 * waits until the next transmit interrupt, and continues until the
824 * frame is transmitted.
825 */
826int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
827{
828 struct smsc_ircc_cb *self;
829 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 s32 speed;
831
832 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
833
834 IRDA_ASSERT(dev != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700835
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700836 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 IRDA_ASSERT(self != NULL, return 0;);
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 /* Make sure test of self->io.speed & speed change are atomic */
842 spin_lock_irqsave(&self->lock, flags);
843
844 /* Check if we need to change the speed */
845 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700846 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 /* Check for empty frame */
848 if (!skb->len) {
849 /*
850 * We send frames one by one in SIR mode (no
851 * pipelining), so at this point, if we were sending
852 * a previous frame, we just received the interrupt
853 * telling us it is finished (UART_IIR_THRI).
854 * Therefore, waiting for the transmitter to really
855 * finish draining the fifo won't take too long.
856 * And the interrupt handler is not expected to run.
857 * - Jean II */
858 smsc_ircc_sir_wait_hw_transmitter_finish(self);
859 smsc_ircc_change_speed(self, speed);
860 spin_unlock_irqrestore(&self->lock, flags);
861 dev_kfree_skb(skb);
862 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700864 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 }
866
867 /* Init tx buffer */
868 self->tx_buff.data = self->tx_buff.head;
869
870 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700871 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700873
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 self->stats.tx_bytes += self->tx_buff.len;
875
876 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700877 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878
879 spin_unlock_irqrestore(&self->lock, flags);
880
881 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 return 0;
884}
885
886/*
887 * Function smsc_ircc_set_fir_speed (self, baud)
888 *
889 * Change the speed of the device
890 *
891 */
892static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
893{
894 int fir_base, ir_mode, ctrl, fast;
895
896 IRDA_ASSERT(self != NULL, return;);
897 fir_base = self->io.fir_base;
898
899 self->io.speed = speed;
900
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700901 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700903 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 ir_mode = IRCC_CFGA_IRDA_HDLC;
905 ctrl = IRCC_CRC;
906 fast = 0;
907 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
908 break;
909 case 1152000:
910 ir_mode = IRCC_CFGA_IRDA_HDLC;
911 ctrl = IRCC_1152 | IRCC_CRC;
912 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
913 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
914 __FUNCTION__);
915 break;
916 case 4000000:
917 ir_mode = IRCC_CFGA_IRDA_4PPM;
918 ctrl = IRCC_CRC;
919 fast = IRCC_LCR_A_FAST;
920 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
921 __FUNCTION__);
922 break;
923 }
924 #if 0
925 Now in tranceiver!
926 /* This causes an interrupt */
927 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700928 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700930
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700932 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700933
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700935 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938/*
939 * Function smsc_ircc_fir_start(self)
940 *
941 * Change the speed of the device
942 *
943 */
944static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
945{
946 struct net_device *dev;
947 int fir_base;
948
949 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
950
951 IRDA_ASSERT(self != NULL, return;);
952 dev = self->netdev;
953 IRDA_ASSERT(dev != NULL, return;);
954
955 fir_base = self->io.fir_base;
956
957 /* Reset everything */
958
959 /* Install FIR transmit handler */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700960 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961
962 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700963 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700966 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
968 register_bank(fir_base, 1);
969
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700970 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700972 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
973 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700974#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700975 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
976 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700977#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700978 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
980 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700981 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700983 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
984 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985}
986
987/*
988 * Function smsc_ircc_fir_stop(self, baud)
989 *
990 * Change the speed of the device
991 *
992 */
993static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
994{
995 int fir_base;
996
997 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 IRDA_ASSERT(self != NULL, return;);
1000
1001 fir_base = self->io.fir_base;
1002 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001003 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1004 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001005}
1006
1007
1008/*
1009 * Function smsc_ircc_change_speed(self, baud)
1010 *
1011 * Change the speed of the device
1012 *
1013 * This function *must* be called with spinlock held, because it may
1014 * be called from the irq handler. - Jean II
1015 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -07001016static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
1022
1023 IRDA_ASSERT(self != NULL, return;);
1024 dev = self->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
1026 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1027
1028 #if 0
1029 /* Temp Hack */
1030 speed= 1152000;
1031 self->io.speed = speed;
1032 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001033 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001035
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001036 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 smsc_ircc_sir_start(self);
1038
1039 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001040 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 #endif
1042
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001043 if (self->io.speed != speed)
1044 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
1046 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001047
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001048 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1049 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 smsc_ircc_fir_stop(self);
1051 smsc_ircc_sir_start(self);
1052 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001053 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001054 } else {
1055 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001056 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057 smsc_ircc_sir_stop(self);
1058 #endif
1059 smsc_ircc_fir_start(self);
1060 }
1061 smsc_ircc_set_fir_speed(self, speed);
1062
1063 #if 0
1064 self->tx_buff.len = 10;
1065 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001066
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001067 smsc_ircc_dma_xmit(self, 4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 #endif
1069 /* Be ready for incoming frames */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001070 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001072
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073 netif_wake_queue(dev);
1074}
1075
1076/*
1077 * Function smsc_ircc_set_sir_speed (self, speed)
1078 *
1079 * Set speed of IrDA port to specified baudrate
1080 *
1081 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -07001082void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001084 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 int fcr; /* FIFO control reg */
1086 int lcr; /* Line control reg */
1087 int divisor;
1088
1089 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1090
1091 IRDA_ASSERT(self != NULL, return;);
1092 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001093
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 /* Update accounting for new speed */
1095 self->io.speed = speed;
1096
1097 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001098 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001100 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 fcr = UART_FCR_ENABLE_FIFO;
1103
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001104 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1106 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001107 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001109 fcr |= self->io.speed < 38400 ?
1110 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001111
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 /* IrDA ports use 8N1 */
1113 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001114
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001115 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1116 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1117 outb(divisor >> 8, iobase + UART_DLM);
1118 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1119 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001122 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1125}
1126
1127
1128/*
1129 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1130 *
1131 * Transmit the frame!
1132 *
1133 */
1134static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1135{
1136 struct smsc_ircc_cb *self;
1137 unsigned long flags;
1138 s32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 int mtt;
1140
1141 IRDA_ASSERT(dev != NULL, return 0;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001142 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 IRDA_ASSERT(self != NULL, return 0;);
1144
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 netif_stop_queue(dev);
1146
1147 /* Make sure test of self->io.speed & speed change are atomic */
1148 spin_lock_irqsave(&self->lock, flags);
1149
1150 /* Check if we need to change the speed after this frame */
1151 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001152 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 /* Check for empty frame */
1154 if (!skb->len) {
1155 /* Note : you should make sure that speed changes
1156 * are not going to corrupt any outgoing frame.
1157 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001158 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 spin_unlock_irqrestore(&self->lock, flags);
1160 dev_kfree_skb(skb);
1161 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001162 }
1163
1164 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001166
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001167 skb_copy_from_linear_data(skb, self->tx_buff.head, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 self->tx_buff.len = skb->len;
1170 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001171
1172 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 if (mtt) {
1174 int bofs;
1175
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001176 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 * Compute how many BOFs (STA or PA's) we need to waste the
1178 * min turn time given the speed of the link.
1179 */
1180 bofs = mtt * (self->io.speed / 1000) / 8000;
1181 if (bofs > 4095)
1182 bofs = 4095;
1183
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001184 smsc_ircc_dma_xmit(self, bofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 } else {
1186 /* Transmit frame */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001187 smsc_ircc_dma_xmit(self, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 spin_unlock_irqrestore(&self->lock, flags);
1191 dev_kfree_skb(skb);
1192
1193 return 0;
1194}
1195
1196/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001197 * Function smsc_ircc_dma_xmit (self, bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 *
1199 * Transmit data using DMA
1200 *
1201 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001202static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001204 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 u8 ctrl;
1206
1207 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1208#if 1
1209 /* Disable Rx */
1210 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001211 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212#endif
1213 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001214 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1215 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 self->io.direction = IO_XMIT;
1218
1219 /* Set BOF additional count for generating the min turn time */
1220 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001221 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1222 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1223 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224
1225 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001226 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1227 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
1229 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001230
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 /* Enable burst mode chip Tx DMA */
1232 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001233 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1234 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235
1236 /* Setup DMA controller (must be done after enabling chip DMA) */
1237 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1238 DMA_TX_MODE);
1239
1240 /* Enable interrupt */
1241
1242 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001243 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1244 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001247 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248}
1249
1250/*
1251 * Function smsc_ircc_dma_xmit_complete (self)
1252 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001253 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 * by the interrupt handler
1255 *
1256 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001257static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001259 int iobase = self->io.fir_base;
1260
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1262#if 0
1263 /* Disable Tx */
1264 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001265 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266#endif
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001267 register_bank(iobase, 1);
1268 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1269 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 /* Check for underrun! */
1272 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001273 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 self->stats.tx_errors++;
1275 self->stats.tx_fifo_errors++;
1276
1277 /* Reset error condition */
1278 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001279 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1280 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 } else {
1282 self->stats.tx_packets++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001283 self->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284 }
1285
1286 /* Check if it's time to change the speed */
1287 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001288 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 self->new_speed = 0;
1290 }
1291
1292 netif_wake_queue(self->netdev);
1293}
1294
1295/*
1296 * Function smsc_ircc_dma_receive(self)
1297 *
1298 * Get ready for receiving a frame. The device will initiate a DMA
1299 * if it starts to receive a frame.
1300 *
1301 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001302static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001304 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305#if 0
1306 /* Turn off chip DMA */
1307 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001308 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1309 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001311
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 /* Disable Tx */
1313 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001314 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315
1316 /* Turn off chip DMA */
1317 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001318 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1319 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320
1321 self->io.direction = IO_RECV;
1322 self->rx_buff.data = self->rx_buff.head;
1323
1324 /* Set max Rx frame size */
1325 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001326 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1327 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328
1329 /* Setup DMA controller */
1330 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1331 DMA_RX_MODE);
1332
1333 /* Enable burst mode chip Rx DMA */
1334 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001335 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1336 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 /* Enable interrupt */
1339 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001340 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1341 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342
1343 /* Enable receiver */
1344 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001345 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001346 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001347
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 return 0;
1349}
1350
1351/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001352 * Function smsc_ircc_dma_receive_complete(self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353 *
1354 * Finished with receiving frames
1355 *
1356 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001357static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358{
1359 struct sk_buff *skb;
1360 int len, msgcnt, lsr;
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001361 int iobase = self->io.fir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001364
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1366#if 0
1367 /* Disable Rx */
1368 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001369 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370#endif
1371 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001372 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1373 lsr= inb(iobase + IRCC_LSR);
1374 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1377 get_dma_residue(self->io.dma));
1378
1379 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1380
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001381 /* Look for errors */
1382 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 self->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001384 if (lsr & IRCC_LSR_FRAME_ERROR)
1385 self->stats.rx_frame_errors++;
1386 if (lsr & IRCC_LSR_CRC_ERROR)
1387 self->stats.rx_crc_errors++;
1388 if (lsr & IRCC_LSR_SIZE_ERROR)
1389 self->stats.rx_length_errors++;
1390 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1391 self->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 return;
1393 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001395 /* Remove CRC */
1396 len -= self->io.speed < 4000000 ? 2 : 4;
1397
1398 if (len < 2 || len > 2050) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1400 return;
1401 }
1402 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1403
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001404 skb = dev_alloc_skb(len + 1);
1405 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1407 __FUNCTION__);
1408 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001411 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412
1413 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1414 self->stats.rx_packets++;
1415 self->stats.rx_bytes += len;
1416
1417 skb->dev = self->netdev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001418 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 skb->protocol = htons(ETH_P_IRDA);
1420 netif_rx(skb);
1421}
1422
1423/*
1424 * Function smsc_ircc_sir_receive (self)
1425 *
1426 * Receive one frame from the infrared port
1427 *
1428 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001429static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430{
1431 int boguscount = 0;
1432 int iobase;
1433
1434 IRDA_ASSERT(self != NULL, return;);
1435
1436 iobase = self->io.sir_base;
1437
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001438 /*
1439 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1440 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 */
1442 do {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001443 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001444 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 /* Make sure we don't stay here to long */
1447 if (boguscount++ > 32) {
1448 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1449 break;
1450 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001451 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452}
1453
1454
1455/*
1456 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1457 *
1458 * An interrupt from the chip has arrived. Time to do some work
1459 *
1460 */
David Howells7d12e782006-10-05 14:55:46 +01001461static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
1463 struct net_device *dev = (struct net_device *) dev_id;
1464 struct smsc_ircc_cb *self;
1465 int iobase, iir, lcra, lsr;
1466 irqreturn_t ret = IRQ_NONE;
1467
1468 if (dev == NULL) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001469 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 driver_name, irq);
1471 goto irq_ret;
1472 }
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001473
1474 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1476
1477 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001478 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001481 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 ret = smsc_ircc_interrupt_sir(dev);
1483 goto irq_ret_unlock;
1484 }
1485
1486 iobase = self->io.fir_base;
1487
1488 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001489 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001490 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 goto irq_ret_unlock;
1492 ret = IRQ_HANDLED;
1493
1494 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001495 outb(0, iobase + IRCC_IER);
1496 lcra = inb(iobase + IRCC_LCR_A);
1497 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001498
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1500
1501 if (iir & IRCC_IIR_EOM) {
1502 if (self->io.direction == IO_RECV)
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001503 smsc_ircc_dma_receive_complete(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 else
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001505 smsc_ircc_dma_xmit_complete(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001506
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001507 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508 }
1509
1510 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1511 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1512 }
1513
1514 /* Enable interrupts again */
1515
1516 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001517 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 irq_ret_unlock:
1520 spin_unlock(&self->lock);
1521 irq_ret:
1522 return ret;
1523}
1524
1525/*
David Howells7d12e782006-10-05 14:55:46 +01001526 * Function irport_interrupt_sir (irq, dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 *
1528 * Interrupt handler for SIR modes
1529 */
1530static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1531{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001532 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 int boguscount = 0;
1534 int iobase;
1535 int iir, lsr;
1536
1537 /* Already locked comming here in smsc_ircc_interrupt() */
1538 /*spin_lock(&self->lock);*/
1539
1540 iobase = self->io.sir_base;
1541
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001542 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 if (iir == 0)
1544 return IRQ_NONE;
1545 while (iir) {
1546 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001547 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001549 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 __FUNCTION__, iir, lsr, iobase);
1551
1552 switch (iir) {
1553 case UART_IIR_RLSI:
1554 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1555 break;
1556 case UART_IIR_RDI:
1557 /* Receive interrupt */
1558 smsc_ircc_sir_receive(self);
1559 break;
1560 case UART_IIR_THRI:
1561 if (lsr & UART_LSR_THRE)
1562 /* Transmitter ready for data */
1563 smsc_ircc_sir_write_wakeup(self);
1564 break;
1565 default:
1566 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1567 __FUNCTION__, iir);
1568 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001569 }
1570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 /* Make sure we don't stay here to long */
1572 if (boguscount++ > 100)
1573 break;
1574
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001575 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 }
1577 /*spin_unlock(&self->lock);*/
1578 return IRQ_HANDLED;
1579}
1580
1581
1582#if 0 /* unused */
1583/*
1584 * Function ircc_is_receiving (self)
1585 *
1586 * Return TRUE is we are currently receiving a frame
1587 *
1588 */
1589static int ircc_is_receiving(struct smsc_ircc_cb *self)
1590{
1591 int status = FALSE;
1592 /* int iobase; */
1593
1594 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1595
1596 IRDA_ASSERT(self != NULL, return FALSE;);
1597
1598 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1599 get_dma_residue(self->io.dma));
1600
1601 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001602
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 return status;
1604}
1605#endif /* unused */
1606
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001607static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1608{
1609 int error;
1610
1611 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1612 self->netdev->name, self->netdev);
1613 if (error)
1614 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
1615 __FUNCTION__, self->io.irq, error);
1616
1617 return error;
1618}
1619
1620static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1621{
1622 unsigned long flags;
1623
1624 spin_lock_irqsave(&self->lock, flags);
1625
1626 self->io.speed = 0;
1627 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1628
1629 spin_unlock_irqrestore(&self->lock, flags);
1630}
1631
1632static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1633{
1634 int iobase = self->io.fir_base;
1635 unsigned long flags;
1636
1637 spin_lock_irqsave(&self->lock, flags);
1638
1639 register_bank(iobase, 0);
1640 outb(0, iobase + IRCC_IER);
1641 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1642 outb(0x00, iobase + IRCC_MASTER);
1643
1644 spin_unlock_irqrestore(&self->lock, flags);
1645}
1646
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647
1648/*
1649 * Function smsc_ircc_net_open (dev)
1650 *
1651 * Start the device
1652 *
1653 */
1654static int smsc_ircc_net_open(struct net_device *dev)
1655{
1656 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657 char hwname[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001662 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001664
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001665 if (self->io.suspended) {
1666 IRDA_DEBUG(0, "%s(), device is suspended\n", __FUNCTION__);
1667 return -EAGAIN;
1668 }
1669
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001670 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 (void *) dev)) {
1672 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1673 __FUNCTION__, self->io.irq);
1674 return -EAGAIN;
1675 }
1676
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001677 smsc_ircc_start_interrupts(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001678
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 /* Give self a hardware name */
1680 /* It would be cool to offer the chip revision here - Jean II */
1681 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1682
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001683 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001685 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 */
1687 self->irlap = irlap_open(dev, &self->qos, hwname);
1688
1689 /*
1690 * Always allocate the DMA channel after the IRQ,
1691 * and clean up on failure.
1692 */
1693 if (request_dma(self->io.dma, dev->name)) {
1694 smsc_ircc_net_close(dev);
1695
1696 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1697 __FUNCTION__, self->io.dma);
1698 return -EAGAIN;
1699 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001700
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 netif_start_queue(dev);
1702
1703 return 0;
1704}
1705
1706/*
1707 * Function smsc_ircc_net_close (dev)
1708 *
1709 * Stop the device
1710 *
1711 */
1712static int smsc_ircc_net_close(struct net_device *dev)
1713{
1714 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715
1716 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001719 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001721
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 /* Stop device */
1723 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001724
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 /* Stop and remove instance of IrLAP */
1726 if (self->irlap)
1727 irlap_close(self->irlap);
1728 self->irlap = NULL;
1729
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001730 smsc_ircc_stop_interrupts(self);
1731
1732 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1733 if (!self->io.suspended)
1734 free_irq(self->io.irq, dev);
1735
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 free_dma(self->io.dma);
1738
1739 return 0;
1740}
1741
Russell King3ae5eae2005-11-09 22:32:44 +00001742static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
Russell King3ae5eae2005-11-09 22:32:44 +00001744 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001745
Russell King9480e302005-10-28 09:52:56 -07001746 if (!self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001747 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1748
1749 rtnl_lock();
1750 if (netif_running(self->netdev)) {
1751 netif_device_detach(self->netdev);
1752 smsc_ircc_stop_interrupts(self);
1753 free_irq(self->io.irq, self->netdev);
1754 disable_dma(self->io.dma);
1755 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001756 self->io.suspended = 1;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001757 rtnl_unlock();
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001758 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001759
1760 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761}
1762
Russell King3ae5eae2005-11-09 22:32:44 +00001763static int smsc_ircc_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
Russell King3ae5eae2005-11-09 22:32:44 +00001765 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766
Russell King9480e302005-10-28 09:52:56 -07001767 if (self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001768 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001770 rtnl_lock();
1771 smsc_ircc_init_chip(self);
1772 if (netif_running(self->netdev)) {
1773 if (smsc_ircc_request_irq(self)) {
1774 /*
1775 * Don't fail resume process, just kill this
1776 * network interface
1777 */
1778 unregister_netdevice(self->netdev);
1779 } else {
1780 enable_dma(self->io.dma);
1781 smsc_ircc_start_interrupts(self);
1782 netif_device_attach(self->netdev);
1783 }
1784 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001785 self->io.suspended = 0;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001786 rtnl_unlock();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 return 0;
1789}
1790
1791/*
1792 * Function smsc_ircc_close (self)
1793 *
1794 * Close driver instance
1795 *
1796 */
1797static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1798{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1800
1801 IRDA_ASSERT(self != NULL, return -1;);
1802
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001803 platform_device_unregister(self->pldev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 /* Remove netdevice */
1806 unregister_netdev(self->netdev);
1807
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001808 smsc_ircc_stop_interrupts(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
1810 /* Release the PORTS that this driver is using */
1811 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1812 self->io.fir_base);
1813
1814 release_region(self->io.fir_base, self->io.fir_ext);
1815
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001816 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001817 self->io.sir_base);
1818
1819 release_region(self->io.sir_base, self->io.sir_ext);
1820
1821 if (self->tx_buff.head)
1822 dma_free_coherent(NULL, self->tx_buff.truesize,
1823 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001824
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 if (self->rx_buff.head)
1826 dma_free_coherent(NULL, self->rx_buff.truesize,
1827 self->rx_buff.head, self->rx_buff_dma);
1828
1829 free_netdev(self->netdev);
1830
1831 return 0;
1832}
1833
1834static void __exit smsc_ircc_cleanup(void)
1835{
1836 int i;
1837
1838 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1839
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001840 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 if (dev_self[i])
1842 smsc_ircc_close(dev_self[i]);
1843 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001844
Russell King3ae5eae2005-11-09 22:32:44 +00001845 platform_driver_unregister(&smsc_ircc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846}
1847
1848/*
1849 * Start SIR operations
1850 *
1851 * This function *must* be called with spinlock held, because it may
1852 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1853 */
1854void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1855{
1856 struct net_device *dev;
1857 int fir_base, sir_base;
1858
1859 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1860
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001861 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001862 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001863 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1865
1866 fir_base = self->io.fir_base;
1867 sir_base = self->io.sir_base;
1868
1869 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001870 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871
1872 #if SMSC_IRCC2_C_SIR_STOP
1873 /*smsc_ircc_sir_stop(self);*/
1874 #endif
1875
1876 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001877 outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
1879 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001880 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1881 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001882
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001884 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1887
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001888 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
1890
1891#if SMSC_IRCC2_C_SIR_STOP
1892void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1893{
1894 int iobase;
1895
1896 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1897 iobase = self->io.sir_base;
1898
1899 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001900 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001901
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001903 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904}
1905#endif
1906
1907/*
1908 * Function smsc_sir_write_wakeup (self)
1909 *
1910 * Called by the SIR interrupt handler when there's room for more data.
1911 * If we have more packets to send, we send them here.
1912 *
1913 */
1914static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1915{
1916 int actual = 0;
1917 int iobase;
1918 int fcr;
1919
1920 IRDA_ASSERT(self != NULL, return;);
1921
1922 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1923
1924 iobase = self->io.sir_base;
1925
1926 /* Finished with frame? */
1927 if (self->tx_buff.len > 0) {
1928 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001929 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 self->tx_buff.data, self->tx_buff.len);
1931 self->tx_buff.data += actual;
1932 self->tx_buff.len -= actual;
1933 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001934
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001936
1937 /*
1938 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 * transmission of another packet. But first we must check
1940 * if we need to change the speed of the hardware
1941 */
1942 if (self->new_speed) {
1943 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1944 __FUNCTION__, self->new_speed);
1945 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1946 smsc_ircc_change_speed(self, self->new_speed);
1947 self->new_speed = 0;
1948 } else {
1949 /* Tell network layer that we want more frames */
1950 netif_wake_queue(self->netdev);
1951 }
1952 self->stats.tx_packets++;
1953
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001954 if (self->io.speed <= 115200) {
1955 /*
1956 * Reset Rx FIFO to make sure that all reflected transmit data
1957 * is discarded. This is needed for half duplex operation
1958 */
1959 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1960 fcr |= self->io.speed < 38400 ?
1961 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001963 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001965 /* Turn on receive interrupts */
1966 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 }
1968 }
1969}
1970
1971/*
1972 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1973 *
1974 * Fill Tx FIFO with transmit data
1975 *
1976 */
1977static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1978{
1979 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001980
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001982 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1984 return 0;
1985 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001986
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001988 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001990 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 actual++;
1992 }
1993 return actual;
1994}
1995
1996/*
1997 * Function smsc_ircc_is_receiving (self)
1998 *
1999 * Returns true is we are currently receiving data
2000 *
2001 */
2002static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
2003{
2004 return (self->rx_buff.state != OUTSIDE_FRAME);
2005}
2006
2007
2008/*
2009 * Function smsc_ircc_probe_transceiver(self)
2010 *
2011 * Tries to find the used Transceiver
2012 *
2013 */
2014static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2015{
2016 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002017
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002019
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002020 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2021 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 IRDA_MESSAGE(" %s transceiver found\n",
2023 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002024 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 return;
2026 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002027
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2029 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002030
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002031 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032}
2033
2034
2035/*
2036 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2037 *
2038 * Set the transceiver according to the speed
2039 *
2040 */
2041static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2042{
2043 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002044
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002046 if (trx > 0)
2047 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048}
2049
2050/*
2051 * Function smsc_ircc_wait_hw_transmitter_finish ()
2052 *
2053 * Wait for the real end of HW transmission
2054 *
2055 * The UART is a strict FIFO, and we get called only when we have finished
2056 * pushing data to the FIFO, so the maximum amount of time we must wait
2057 * is only for the FIFO to drain out.
2058 *
2059 * We use a simple calibrated loop. We may need to adjust the loop
2060 * delay (udelay) to balance I/O traffic and latency. And we also need to
2061 * adjust the maximum timeout.
2062 * It would probably be better to wait for the proper interrupt,
2063 * but it doesn't seem to be available.
2064 *
2065 * We can't use jiffies or kernel timers because :
2066 * 1) We are called from the interrupt handler, which disable softirqs,
2067 * so jiffies won't be increased
2068 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2069 * want to wait that long to detect stuck hardware.
2070 * Jean II
2071 */
2072
2073static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2074{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002075 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002079 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 udelay(1);
2081
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002082 if (count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
2084}
2085
2086
2087/* PROBING
2088 *
David Brownelld94c77b2006-05-09 15:26:11 -07002089 * REVISIT we can be told about the device by PNP, and should use that info
2090 * instead of probing hardware and creating a platform_device ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 */
2092
2093static int __init smsc_ircc_look_for_chips(void)
2094{
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002095 struct smsc_chip_address *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002096 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 found = 0;
2100 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002101
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002102 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002106
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002107 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002109 if (address->type & SMSCSIO_TYPE_FLAT)
2110 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2111 found++;
2112
2113 if (address->type & SMSCSIO_TYPE_PAGED)
2114 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2115 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002117 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002119 if (address->type & SMSCSIO_TYPE_FLAT)
2120 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2121 found++;
2122
2123 if (address->type & SMSCSIO_TYPE_PAGED)
2124 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2125 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 }
2127 address++;
2128 }
2129 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002130}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131
2132/*
2133 * Function smsc_superio_flat (chip, base, type)
2134 *
2135 * Try to get configuration of a smc SuperIO chip with flat register model
2136 *
2137 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002138static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139{
2140 unsigned short firbase, sirbase;
2141 u8 mode, dma, irq;
2142 int ret = -ENODEV;
2143
2144 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2145
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002146 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 return ret;
2148
2149 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002150 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002151
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002153
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002154 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2156
2157 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002158 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002160 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002162 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
2164 /* DMA */
2165 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002166 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 /* IRQ */
2169 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002170 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
2172 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2173
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002174 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2175 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002176
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 /* Exit configuration */
2178 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2179
2180 return ret;
2181}
2182
2183/*
2184 * Function smsc_superio_paged (chip, base, type)
2185 *
2186 * Try to get configuration of a smc SuperIO chip with paged register model
2187 *
2188 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002189static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190{
2191 unsigned short fir_io, sir_io;
2192 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002193
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2195
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002196 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002198
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 /* Select logical device (UART2) */
2200 outb(0x07, cfg_base);
2201 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002202
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 /* SIR iobase */
2204 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002205 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 outb(0x61, cfg_base);
2207 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 /* Read FIR base */
2210 outb(0x62, cfg_base);
2211 fir_io = inb(cfg_base + 1) << 8;
2212 outb(0x63, cfg_base);
2213 fir_io |= inb(cfg_base + 1);
2214 outb(0x2b, cfg_base); /* ??? */
2215
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002216 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2217 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002218
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 /* Exit configuration */
2220 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2221
2222 return ret;
2223}
2224
2225
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002226static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227{
2228 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2229
2230 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002231 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232}
2233
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002234static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002236 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237
2238 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2239
2240 /* Leave configuration */
2241
2242 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2243
2244 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2245 return NULL;
2246
2247 outb(reg, cfg_base);
2248
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002249 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250
2251 /* Enter configuration */
2252
2253 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2254
2255 #if 0
2256 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2257 return NULL;
2258 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 /* probe device ID */
2261
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002262 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 return NULL;
2264
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002265 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002266
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002267 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 return NULL;
2269
2270 /* probe revision ID */
2271
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002272 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 return NULL;
2274
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002275 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002277 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 return NULL;
2279
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002280 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 return NULL;
2282
2283 /* Check for expected device ID; are there others? */
2284
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002285 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286
2287 chip++;
2288
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002289 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 return NULL;
2291 }
2292
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002293 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2294 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002296 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002297 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 return NULL;
2299 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002300
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002301 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 IRDA_MESSAGE("chipset does not support IRDA\n");
2303
2304 return chip;
2305}
2306
2307static int __init smsc_superio_fdc(unsigned short cfg_base)
2308{
2309 int ret = -1;
2310
2311 if (!request_region(cfg_base, 2, driver_name)) {
2312 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2313 __FUNCTION__, cfg_base);
2314 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002315 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2316 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 ret = 0;
2318
2319 release_region(cfg_base, 2);
2320 }
2321
2322 return ret;
2323}
2324
2325static int __init smsc_superio_lpc(unsigned short cfg_base)
2326{
2327 int ret = -1;
2328
2329 if (!request_region(cfg_base, 2, driver_name)) {
2330 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2331 __FUNCTION__, cfg_base);
2332 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002333 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2334 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 release_region(cfg_base, 2);
2338 }
2339 return ret;
2340}
2341
Linus Walleijc1e14a62006-04-05 22:33:59 -07002342/*
2343 * Look for some specific subsystem setups that need
2344 * pre-configuration not properly done by the BIOS (especially laptops)
2345 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2346 * and tosh2450-smcinit.c. The table lists the device entries
Linus Walleij08d09992006-04-14 16:03:33 -07002347 * for ISA bridges with an LPC (Low Pin Count) controller which
2348 * handles the communication with the SMSC device. After the LPC
2349 * controller is initialized through PCI, the SMSC device is initialized
2350 * through a dedicated port in the ISA port-mapped I/O area, this latter
2351 * area is used to configure the SMSC device with default
2352 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2353 * used different sets of parameters and different control port
2354 * addresses making a subsystem device table necessary.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002355 */
2356#ifdef CONFIG_PCI
2357#define PCIID_VENDOR_INTEL 0x8086
2358#define PCIID_VENDOR_ALI 0x10b9
Dmitry Torokhovc5d965c2006-07-06 23:58:27 -07002359static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002360 /*
2361 * Subsystems needing entries:
2362 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2363 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2364 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2365 */
2366 {
2367 /* Guessed entry */
2368 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2369 .device = 0x24cc,
2370 .subvendor = 0x103c,
2371 .subdevice = 0x08bc,
2372 .sir_io = 0x02f8,
2373 .fir_io = 0x0130,
2374 .fir_irq = 0x05,
2375 .fir_dma = 0x03,
2376 .cfg_base = 0x004e,
2377 .preconfigure = preconfigure_through_82801,
2378 .name = "HP nx5000 family",
2379 },
Linus Walleijc1e14a62006-04-05 22:33:59 -07002380 {
2381 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2382 .device = 0x24cc,
2383 .subvendor = 0x103c,
2384 .subdevice = 0x088c,
Linus Walleij08d09992006-04-14 16:03:33 -07002385 /* Quite certain these are the same for nc8000 as for nc6000 */
2386 .sir_io = 0x02f8,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002387 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002388 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002389 .fir_dma = 0x03,
2390 .cfg_base = 0x004e,
2391 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002392 .name = "HP nc8000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002393 },
2394 {
2395 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2396 .device = 0x24cc,
2397 .subvendor = 0x103c,
2398 .subdevice = 0x0890,
2399 .sir_io = 0x02f8,
2400 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002401 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002402 .fir_dma = 0x03,
2403 .cfg_base = 0x004e,
2404 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002405 .name = "HP nc6000 family",
2406 },
2407 {
2408 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801DBM LPC bridge */
2409 .device = 0x24cc,
2410 .subvendor = 0x0e11,
2411 .subdevice = 0x0860,
2412 /* I assume these are the same for x1000 as for the others */
2413 .sir_io = 0x02e8,
2414 .fir_io = 0x02f8,
2415 .fir_irq = 0x07,
2416 .fir_dma = 0x03,
2417 .cfg_base = 0x002e,
2418 .preconfigure = preconfigure_through_82801,
2419 .name = "Compaq x1000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002420 },
2421 {
Linus Walleij08d09992006-04-14 16:03:33 -07002422 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
2423 .vendor = PCIID_VENDOR_INTEL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002424 .device = 0x24c0,
2425 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002426 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002427 .sir_io = 0x03f8,
2428 .fir_io = 0x0130,
2429 .fir_irq = 0x07,
2430 .fir_dma = 0x01,
2431 .cfg_base = 0x002e,
2432 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002433 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002434 },
2435 {
2436 .vendor = PCIID_VENDOR_INTEL, /* Intel 82801CAM ISA bridge */
Linus Walleij08d09992006-04-14 16:03:33 -07002437 .device = 0x248c,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002438 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002439 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002440 .sir_io = 0x03f8,
2441 .fir_io = 0x0130,
2442 .fir_irq = 0x03,
2443 .fir_dma = 0x03,
2444 .cfg_base = 0x002e,
2445 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002446 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002447 },
2448 {
Linus Walleij08d09992006-04-14 16:03:33 -07002449 /* 82801DBM (ICH4-M) LPC Interface Bridge */
2450 .vendor = PCIID_VENDOR_INTEL,
2451 .device = 0x24cc,
2452 .subvendor = 0x1179,
2453 .subdevice = 0xffff, /* 0xffff is "any" */
2454 .sir_io = 0x03f8,
2455 .fir_io = 0x0130,
2456 .fir_irq = 0x03,
2457 .fir_dma = 0x03,
2458 .cfg_base = 0x002e,
2459 .preconfigure = preconfigure_through_82801,
2460 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2461 },
2462 {
2463 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
2464 .vendor = PCIID_VENDOR_ALI,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002465 .device = 0x1533,
2466 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002467 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002468 .sir_io = 0x02e8,
2469 .fir_io = 0x02f8,
2470 .fir_irq = 0x07,
2471 .fir_dma = 0x03,
2472 .cfg_base = 0x002e,
2473 .preconfigure = preconfigure_through_ali,
Linus Walleij08d09992006-04-14 16:03:33 -07002474 .name = "Toshiba laptop with ALi ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002475 },
2476 { } // Terminator
2477};
2478
2479
2480/*
Linus Walleij08d09992006-04-14 16:03:33 -07002481 * This sets up the basic SMSC parameters
2482 * (FIR port, SIR port, FIR DMA, FIR IRQ)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002483 * through the chip configuration port.
2484 */
Linus Walleij08d09992006-04-14 16:03:33 -07002485static int __init preconfigure_smsc_chip(struct
2486 smsc_ircc_subsystem_configuration
2487 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002488{
2489 unsigned short iobase = conf->cfg_base;
2490 unsigned char tmpbyte;
2491
2492 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2493 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2494 tmpbyte = inb(iobase +1); // Read device ID
Linus Walleij08d09992006-04-14 16:03:33 -07002495 IRDA_DEBUG(0,
2496 "Detected Chip id: 0x%02x, setting up registers...\n",
2497 tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002498
2499 /* Disable UART1 and set up SIR I/O port */
2500 outb(0x24, iobase); // select CR24 - UART1 base addr
2501 outb(0x00, iobase + 1); // disable UART1
2502 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2503 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2504 tmpbyte = inb(iobase + 1);
2505 if (tmpbyte != (conf->sir_io >> 2) ) {
2506 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
Linus Walleij08d09992006-04-14 16:03:33 -07002507 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
Linus Walleijc1e14a62006-04-05 22:33:59 -07002508 return -ENXIO;
2509 }
2510
2511 /* Set up FIR IRQ channel for UART2 */
2512 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2513 tmpbyte = inb(iobase + 1);
2514 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2515 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2516 outb(tmpbyte, iobase + 1);
2517 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2518 if (tmpbyte != conf->fir_irq) {
2519 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2520 return -ENXIO;
2521 }
2522
2523 /* Set up FIR I/O port */
2524 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2525 outb((conf->fir_io >> 3), iobase + 1);
2526 tmpbyte = inb(iobase + 1);
2527 if (tmpbyte != (conf->fir_io >> 3) ) {
2528 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2529 return -ENXIO;
2530 }
2531
2532 /* Set up FIR DMA channel */
2533 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2534 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2535 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2536 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2537 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2538 return -ENXIO;
2539 }
2540
2541 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2542 tmpbyte = inb(iobase + 1);
Linus Walleij08d09992006-04-14 16:03:33 -07002543 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2544 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002545 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2546
2547 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2548 tmpbyte = inb(iobase + 1);
2549 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2550
2551 /* This one was not part of tosh1800 */
2552 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2553 tmpbyte = inb(iobase + 1);
2554 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2555
2556 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2557 tmpbyte = inb(iobase + 1);
2558 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2559
2560 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2561 tmpbyte = inb(iobase + 1);
2562 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2563
2564 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2565
2566 return 0;
2567}
2568
Linus Walleij08d09992006-04-14 16:03:33 -07002569/* 82801CAM generic registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002570#define VID 0x00
2571#define DID 0x02
Linus Walleij08d09992006-04-14 16:03:33 -07002572#define PIRQ_A_D_ROUT 0x60
2573#define SIRQ_CNTL 0x64
2574#define PIRQ_E_H_ROUT 0x68
Linus Walleijc1e14a62006-04-05 22:33:59 -07002575#define PCI_DMA_C 0x90
Linus Walleij08d09992006-04-14 16:03:33 -07002576/* LPC-specific registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002577#define COM_DEC 0xe0
Linus Walleij08d09992006-04-14 16:03:33 -07002578#define GEN1_DEC 0xe4
Linus Walleijc1e14a62006-04-05 22:33:59 -07002579#define LPC_EN 0xe6
2580#define GEN2_DEC 0xec
2581/*
Linus Walleij08d09992006-04-14 16:03:33 -07002582 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2583 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2584 * They all work the same way!
Linus Walleijc1e14a62006-04-05 22:33:59 -07002585 */
2586static int __init preconfigure_through_82801(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002587 struct
2588 smsc_ircc_subsystem_configuration
2589 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002590{
2591 unsigned short tmpword;
Linus Walleij08d09992006-04-14 16:03:33 -07002592 unsigned char tmpbyte;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002593
Linus Walleij08d09992006-04-14 16:03:33 -07002594 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2595 /*
2596 * Select the range for the COMA COM port (SIR)
2597 * Register COM_DEC:
2598 * Bit 7: reserved
2599 * Bit 6-4, COMB decode range
2600 * Bit 3: reserved
2601 * Bit 2-0, COMA decode range
2602 *
2603 * Decode ranges:
2604 * 000 = 0x3f8-0x3ff (COM1)
2605 * 001 = 0x2f8-0x2ff (COM2)
2606 * 010 = 0x220-0x227
2607 * 011 = 0x228-0x22f
2608 * 100 = 0x238-0x23f
2609 * 101 = 0x2e8-0x2ef (COM4)
2610 * 110 = 0x338-0x33f
2611 * 111 = 0x3e8-0x3ef (COM3)
2612 */
2613 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2614 tmpbyte &= 0xf8; /* mask COMA bits */
2615 switch(conf->sir_io) {
2616 case 0x3f8:
2617 tmpbyte |= 0x00;
2618 break;
2619 case 0x2f8:
2620 tmpbyte |= 0x01;
2621 break;
2622 case 0x220:
2623 tmpbyte |= 0x02;
2624 break;
2625 case 0x228:
2626 tmpbyte |= 0x03;
2627 break;
2628 case 0x238:
2629 tmpbyte |= 0x04;
2630 break;
2631 case 0x2e8:
2632 tmpbyte |= 0x05;
2633 break;
2634 case 0x338:
2635 tmpbyte |= 0x06;
2636 break;
2637 case 0x3e8:
2638 tmpbyte |= 0x07;
2639 break;
2640 default:
2641 tmpbyte |= 0x01; /* COM2 default */
2642 }
2643 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2644 pci_write_config_byte(dev, COM_DEC, tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002645
Linus Walleij08d09992006-04-14 16:03:33 -07002646 /* Enable Low Pin Count interface */
2647 pci_read_config_word(dev, LPC_EN, &tmpword);
2648 /* These seem to be set up at all times,
2649 * just make sure it is properly set.
2650 */
2651 switch(conf->cfg_base) {
2652 case 0x04e:
2653 tmpword |= 0x2000;
2654 break;
2655 case 0x02e:
2656 tmpword |= 0x1000;
2657 break;
2658 case 0x062:
2659 tmpword |= 0x0800;
2660 break;
2661 case 0x060:
2662 tmpword |= 0x0400;
2663 break;
2664 default:
2665 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2666 conf->cfg_base);
2667 break;
2668 }
2669 tmpword &= 0xfffd; /* disable LPC COMB */
2670 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2671 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002672 pci_write_config_word(dev, LPC_EN, tmpword);
2673
Linus Walleij08d09992006-04-14 16:03:33 -07002674 /*
2675 * Configure LPC DMA channel
2676 * PCI_DMA_C bits:
2677 * Bit 15-14: DMA channel 7 select
2678 * Bit 13-12: DMA channel 6 select
2679 * Bit 11-10: DMA channel 5 select
2680 * Bit 9-8: Reserved
2681 * Bit 7-6: DMA channel 3 select
2682 * Bit 5-4: DMA channel 2 select
2683 * Bit 3-2: DMA channel 1 select
2684 * Bit 1-0: DMA channel 0 select
2685 * 00 = Reserved value
2686 * 01 = PC/PCI DMA
2687 * 10 = Reserved value
2688 * 11 = LPC I/F DMA
2689 */
2690 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2691 switch(conf->fir_dma) {
2692 case 0x07:
2693 tmpword |= 0xc000;
2694 break;
2695 case 0x06:
2696 tmpword |= 0x3000;
2697 break;
2698 case 0x05:
2699 tmpword |= 0x0c00;
2700 break;
2701 case 0x03:
2702 tmpword |= 0x00c0;
2703 break;
2704 case 0x02:
2705 tmpword |= 0x0030;
2706 break;
2707 case 0x01:
2708 tmpword |= 0x000c;
2709 break;
2710 case 0x00:
2711 tmpword |= 0x0003;
2712 break;
2713 default:
2714 break; /* do not change settings */
2715 }
2716 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2717 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2718
2719 /*
2720 * GEN2_DEC bits:
2721 * Bit 15-4: Generic I/O range
2722 * Bit 3-1: reserved (read as 0)
2723 * Bit 0: enable GEN2 range on LPC I/F
2724 */
2725 tmpword = conf->fir_io & 0xfff8;
2726 tmpword |= 0x0001;
2727 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2728 pci_write_config_word(dev, GEN2_DEC, tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002729
2730 /* Pre-configure chip */
Linus Walleij08d09992006-04-14 16:03:33 -07002731 return preconfigure_smsc_chip(conf);
2732}
Linus Walleijc1e14a62006-04-05 22:33:59 -07002733
Linus Walleij08d09992006-04-14 16:03:33 -07002734/*
2735 * Pre-configure a certain port on the ALi 1533 bridge.
2736 * This is based on reverse-engineering since ALi does not
2737 * provide any data sheet for the 1533 chip.
2738 */
2739static void __init preconfigure_ali_port(struct pci_dev *dev,
2740 unsigned short port)
2741{
2742 unsigned char reg;
2743 /* These bits obviously control the different ports */
2744 unsigned char mask;
2745 unsigned char tmpbyte;
2746
2747 switch(port) {
2748 case 0x0130:
2749 case 0x0178:
2750 reg = 0xb0;
2751 mask = 0x80;
2752 break;
2753 case 0x03f8:
2754 reg = 0xb4;
2755 mask = 0x80;
2756 break;
2757 case 0x02f8:
2758 reg = 0xb4;
2759 mask = 0x30;
2760 break;
2761 case 0x02e8:
2762 reg = 0xb4;
2763 mask = 0x08;
2764 break;
2765 default:
2766 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2767 return;
2768 }
2769
2770 pci_read_config_byte(dev, reg, &tmpbyte);
2771 /* Turn on the right bits */
2772 tmpbyte |= mask;
2773 pci_write_config_byte(dev, reg, tmpbyte);
2774 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
2775 return;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002776}
2777
2778static int __init preconfigure_through_ali(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002779 struct
2780 smsc_ircc_subsystem_configuration
2781 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002782{
Linus Walleij08d09992006-04-14 16:03:33 -07002783 /* Configure the two ports on the ALi 1533 */
2784 preconfigure_ali_port(dev, conf->sir_io);
2785 preconfigure_ali_port(dev, conf->fir_io);
2786
2787 /* Pre-configure chip */
2788 return preconfigure_smsc_chip(conf);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002789}
2790
2791static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
2792 unsigned short ircc_fir,
2793 unsigned short ircc_sir,
2794 unsigned char ircc_dma,
2795 unsigned char ircc_irq)
2796{
2797 struct pci_dev *dev = NULL;
2798 unsigned short ss_vendor = 0x0000;
2799 unsigned short ss_device = 0x0000;
2800 int ret = 0;
2801
2802 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2803
2804 while (dev != NULL) {
2805 struct smsc_ircc_subsystem_configuration *conf;
2806
2807 /*
Linus Walleij08d09992006-04-14 16:03:33 -07002808 * Cache the subsystem vendor/device:
2809 * some manufacturers fail to set this for all components,
2810 * so we save it in case there is just 0x0000 0x0000 on the
2811 * device we want to check.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002812 */
2813 if (dev->subsystem_vendor != 0x0000U) {
2814 ss_vendor = dev->subsystem_vendor;
2815 ss_device = dev->subsystem_device;
2816 }
2817 conf = subsystem_configurations;
2818 for( ; conf->subvendor; conf++) {
2819 if(conf->vendor == dev->vendor &&
2820 conf->device == dev->device &&
Linus Walleij08d09992006-04-14 16:03:33 -07002821 conf->subvendor == ss_vendor &&
2822 /* Sometimes these are cached values */
2823 (conf->subdevice == ss_device ||
2824 conf->subdevice == 0xffff)) {
2825 struct smsc_ircc_subsystem_configuration
2826 tmpconf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002827
Linus Walleij08d09992006-04-14 16:03:33 -07002828 memcpy(&tmpconf, conf,
2829 sizeof(struct smsc_ircc_subsystem_configuration));
Linus Walleijc1e14a62006-04-05 22:33:59 -07002830
Linus Walleij08d09992006-04-14 16:03:33 -07002831 /*
2832 * Override the default values with anything
2833 * passed in as parameter
2834 */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002835 if (ircc_cfg != 0)
2836 tmpconf.cfg_base = ircc_cfg;
2837 if (ircc_fir != 0)
2838 tmpconf.fir_io = ircc_fir;
2839 if (ircc_sir != 0)
2840 tmpconf.sir_io = ircc_sir;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002841 if (ircc_dma != DMA_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002842 tmpconf.fir_dma = ircc_dma;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002843 if (ircc_irq != IRQ_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002844 tmpconf.fir_irq = ircc_irq;
2845
2846 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2847 if (conf->preconfigure)
2848 ret = conf->preconfigure(dev, &tmpconf);
2849 else
2850 ret = -ENODEV;
2851 }
2852 }
2853 dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
2854 }
2855
2856 return ret;
2857}
2858#endif // CONFIG_PCI
2859
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860/************************************************
2861 *
2862 * Transceivers specific functions
2863 *
2864 ************************************************/
2865
2866
2867/*
2868 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2869 *
2870 * Program transceiver through smsc-ircc ATC circuitry
2871 *
2872 */
2873
2874static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2875{
2876 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002877 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002878
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002879 jiffies_now = jiffies;
2880 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002881
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 /* ATC */
2883 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002884 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2885 fir_base + IRCC_ATC);
2886
2887 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2888 !time_after(jiffies, jiffies_timeout))
2889 /* empty */;
2890
2891 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002893 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894}
2895
2896/*
2897 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2898 *
2899 * Probe transceiver smsc-ircc ATC circuitry
2900 *
2901 */
2902
2903static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2904{
2905 return 0;
2906}
2907
2908/*
2909 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2910 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002911 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912 *
2913 */
2914
2915static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2916{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002917 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002918
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002919 switch (speed) {
2920 default:
2921 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002922 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002924 case 1152000 :
2925 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 fast_mode = IRCC_LCR_A_FAST;
2927 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 }
2929 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002930 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931}
2932
2933/*
2934 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2935 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002936 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 *
2938 */
2939
2940static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2941{
2942 return 0;
2943}
2944
2945/*
2946 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2947 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002948 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 *
2950 */
2951
2952static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2953{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002954 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002955
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002956 switch (speed) {
2957 default:
2958 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002959 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002961 case 1152000 :
2962 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2964 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002965
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967 /* This causes an interrupt */
2968 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002969 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970}
2971
2972/*
2973 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2974 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002975 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002976 *
2977 */
2978
2979static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2980{
2981 return 0;
2982}
2983
2984
2985module_init(smsc_ircc_init);
2986module_exit(smsc_ircc_cleanup);