blob: a5090ddb0d0f5225d5a44a65da84ea234e45c6bc [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
14 *
15 *
16 * Based on smc-ircc.c:
17 *
18 * Copyright (c) 2001 Stefani Seibold
19 * Copyright (c) 1999-2001 Dag Brattli
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070020 * Copyright (c) 1998-1999 Thomas Davis,
Linus Torvalds1da177e2005-04-16 15:20:36 -070021 *
22 * and irport.c:
23 *
24 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
25 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070026 *
27 * This program is free software; you can redistribute it and/or
28 * modify it under the terms of the GNU General Public License as
29 * published by the Free Software Foundation; either version 2 of
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 * the License, or (at your option) any later version.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070031 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * This program is distributed in the hope that it will be useful,
33 * but WITHOUT ANY WARRANTY; without even the implied warranty of
34 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
35 * GNU General Public License for more details.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070036 *
37 * You should have received a copy of the GNU General Public License
38 * along with this program; if not, write to the Free Software
39 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 * MA 02111-1307 USA
41 *
42 ********************************************************************/
43
44#include <linux/module.h>
45#include <linux/kernel.h>
46#include <linux/types.h>
47#include <linux/skbuff.h>
48#include <linux/netdevice.h>
49#include <linux/ioport.h>
50#include <linux/delay.h>
51#include <linux/slab.h>
52#include <linux/init.h>
53#include <linux/rtnetlink.h>
54#include <linux/serial_reg.h>
55#include <linux/dma-mapping.h>
56
57#include <asm/io.h>
58#include <asm/dma.h>
59#include <asm/byteorder.h>
60
61#include <linux/spinlock.h>
62#include <linux/pm.h>
63
64#include <net/irda/wrapper.h>
65#include <net/irda/irda.h>
66#include <net/irda/irda_device.h>
67
68#include "smsc-ircc2.h"
69#include "smsc-sio.h"
70
Dmitry Torokhov98b77772005-09-06 15:19:19 -070071
72MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
73MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
74MODULE_LICENSE("GPL");
75
76
77static int ircc_dma = 255;
78module_param(ircc_dma, int, 0);
79MODULE_PARM_DESC(ircc_dma, "DMA channel");
80
81static int ircc_irq = 255;
82module_param(ircc_irq, int, 0);
83MODULE_PARM_DESC(ircc_irq, "IRQ line");
84
85static int ircc_fir;
86module_param(ircc_fir, int, 0);
87MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
88
89static int ircc_sir;
90module_param(ircc_sir, int, 0);
91MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
92
93static int ircc_cfg;
94module_param(ircc_cfg, int, 0);
95MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
96
97static int ircc_transceiver;
98module_param(ircc_transceiver, int, 0);
99MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/* Types */
102
103struct smsc_transceiver {
104 char *name;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700105 void (*set_for_speed)(int fir_base, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 int (*probe)(int fir_base);
107};
108typedef struct smsc_transceiver smsc_transceiver_t;
109
110#if 0
111struct smc_chip {
112 char *name;
113 u16 flags;
114 u8 devid;
115 u8 rev;
116};
117typedef struct smc_chip smc_chip_t;
118#endif
119
120struct smsc_chip {
121 char *name;
122 #if 0
123 u8 type;
124 #endif
125 u16 flags;
126 u8 devid;
127 u8 rev;
128};
129typedef struct smsc_chip smsc_chip_t;
130
131struct smsc_chip_address {
132 unsigned int cfg_base;
133 unsigned int type;
134};
135typedef struct smsc_chip_address smsc_chip_address_t;
136
137/* Private data for each instance */
138struct smsc_ircc_cb {
139 struct net_device *netdev; /* Yes! we are some kind of netdevice */
140 struct net_device_stats stats;
141 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 chipio_t io; /* IrDA controller information */
144 iobuff_t tx_buff; /* Transmit buffer */
145 iobuff_t rx_buff; /* Receive buffer */
146 dma_addr_t tx_buff_dma;
147 dma_addr_t rx_buff_dma;
148
149 struct qos_info qos; /* QoS capabilities for this device */
150
151 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 __u32 new_speed;
154 __u32 flags; /* Interface flags */
155
156 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
157 int tx_len; /* Number of frames in tx_buff */
158
159 int transceiver;
160 struct pm_dev *pmdev;
161};
162
163/* Constants */
164
165static const char *driver_name = "smsc-ircc2";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
167#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700168#define SMSC_IRCC2_C_NET_TIMEOUT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169#define SMSC_IRCC2_C_SIR_STOP 0
170
171/* Prototypes */
172
173static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
174static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
175static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
176static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
177static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
178static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700179static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase);
181static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
182static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
183static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
184static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs);
185static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase);
186static void smsc_ircc_change_speed(void *priv, u32 speed);
187static void smsc_ircc_set_sir_speed(void *priv, u32 speed);
188static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
189static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
190static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
191#if SMSC_IRCC2_C_SIR_STOP
192static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
193#endif
194static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
195static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
196static int smsc_ircc_net_open(struct net_device *dev);
197static int smsc_ircc_net_close(struct net_device *dev);
198static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
199#if SMSC_IRCC2_C_NET_TIMEOUT
200static void smsc_ircc_timeout(struct net_device *dev);
201#endif
202static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
203static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
204static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
205static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
206static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
207static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
208
209/* Probing */
210static int __init smsc_ircc_look_for_chips(void);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700211static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const smsc_chip_t *chip, char *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfg_base, char *type);
213static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cfg_base, char *type);
214static int __init smsc_superio_fdc(unsigned short cfg_base);
215static int __init smsc_superio_lpc(unsigned short cfg_base);
216
217/* Transceivers specific functions */
218
219static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
220static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
221static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
222static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
223static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
224static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
225
226/* Power Management */
227
228static void smsc_ircc_suspend(struct smsc_ircc_cb *self);
229static void smsc_ircc_wakeup(struct smsc_ircc_cb *self);
230static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
231
232
233/* Transceivers for SMSC-ircc */
234
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700235static smsc_transceiver_t smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700237 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
238 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
239 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
240 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700242#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244/* SMC SuperIO chipsets definitions */
245
246#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
247#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
248#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
249#define SIR 0 /* SuperIO Chip has only slow IRDA */
250#define FIR 4 /* SuperIO Chip has fast IRDA */
251#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
252
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700253static smsc_chip_t __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
255 /* Base address 0x3f0 or 0x370 */
256 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
257 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
258 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
259 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
260 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
261 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
262 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
263 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
264 { NULL }
265};
266
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700267static smsc_chip_t __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 /* Base address 0x3f0 or 0x370 */
270 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
271 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
272 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
273 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
274 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
275 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
276 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
277 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
278 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
279 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
280 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
281 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
282 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
283 { NULL }
284};
285
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700286static smsc_chip_t __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 /* Base address 0x2E or 0x4E */
289 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
290 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
291 { NULL }
292};
293
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700294static smsc_chip_t __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
296 /* Base address 0x2E or 0x4E */
297 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
298 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
299 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
300 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
301 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
302 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
303 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
304 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
305 { NULL }
306};
307
308#define SMSCSIO_TYPE_FDC 1
309#define SMSCSIO_TYPE_LPC 2
310#define SMSCSIO_TYPE_FLAT 4
311#define SMSCSIO_TYPE_PAGED 8
312
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700313static smsc_chip_address_t __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700315 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
316 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
317 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
318 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
319 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
320 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321};
322
323/* Globals */
324
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700325static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
326static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328static inline void register_bank(int iobase, int bank)
329{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700330 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
331 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332}
333
334
335/*******************************************************************************
336 *
337 *
338 * SMSC-ircc stuff
339 *
340 *
341 *******************************************************************************/
342
343/*
344 * Function smsc_ircc_init ()
345 *
346 * Initialize chip. Just try to find out how many chips we are dealing with
347 * and where they are
348 */
349static int __init smsc_ircc_init(void)
350{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700351 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
353 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
354
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700355 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700356
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700357 if (ircc_fir > 0 && ircc_sir > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
359 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
360
361 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq) == 0)
362 return 0;
363
364 return -ENODEV;
365 }
366
367 /* try user provided configuration register base address */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700368 if (ircc_cfg > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 IRDA_MESSAGE(" Overriding configuration address 0x%04x\n",
370 ircc_cfg);
371 if (!smsc_superio_fdc(ircc_cfg))
372 ret = 0;
373 if (!smsc_superio_lpc(ircc_cfg))
374 ret = 0;
375 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700376
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700377 if (smsc_ircc_look_for_chips() > 0)
378 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 return ret;
381}
382
383/*
384 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
385 *
386 * Try to open driver instance
387 *
388 */
389static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
390{
391 struct smsc_ircc_cb *self;
392 struct net_device *dev;
393 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700394
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
396
397 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700398 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700400
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700402 if (dev_count >= ARRAY_SIZE(dev_self)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
404 goto err_out1;
405 }
406
407 /*
408 * Allocate new instance of the driver
409 */
410 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
411 if (!dev) {
412 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
413 goto err_out1;
414 }
415
416 SET_MODULE_OWNER(dev);
417
418 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
419#if SMSC_IRCC2_C_NET_TIMEOUT
420 dev->tx_timeout = smsc_ircc_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700421 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#endif
423 dev->open = smsc_ircc_net_open;
424 dev->stop = smsc_ircc_net_close;
425 dev->do_ioctl = smsc_ircc_net_ioctl;
426 dev->get_stats = smsc_ircc_net_get_stats;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700427
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 self = dev->priv;
429 self->netdev = dev;
430
431 /* Make ifconfig display some details */
432 dev->base_addr = self->io.fir_base = fir_base;
433 dev->irq = self->io.irq = irq;
434
435 /* Need to store self somewhere */
436 dev_self[dev_count++] = self;
437 spin_lock_init(&self->lock);
438
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700439 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
441
442 self->rx_buff.head =
443 dma_alloc_coherent(NULL, self->rx_buff.truesize,
444 &self->rx_buff_dma, GFP_KERNEL);
445 if (self->rx_buff.head == NULL) {
446 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
447 driver_name);
448 goto err_out2;
449 }
450
451 self->tx_buff.head =
452 dma_alloc_coherent(NULL, self->tx_buff.truesize,
453 &self->tx_buff_dma, GFP_KERNEL);
454 if (self->tx_buff.head == NULL) {
455 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
456 driver_name);
457 goto err_out3;
458 }
459
460 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
461 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
462
463 self->rx_buff.in_frame = FALSE;
464 self->rx_buff.state = OUTSIDE_FRAME;
465 self->tx_buff.data = self->tx_buff.head;
466 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700471
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700472 if (ircc_transceiver > 0 &&
473 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 self->transceiver = ircc_transceiver;
475 else
476 smsc_ircc_probe_transceiver(self);
477
478 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700479 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 IRDA_ERROR("%s, Network device registration failed!\n",
481 driver_name);
482 goto err_out4;
483 }
484
485 self->pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, smsc_ircc_pmproc);
486 if (self->pmdev)
487 self->pmdev->data = self;
488
489 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
490
491 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 err_out4:
494 dma_free_coherent(NULL, self->tx_buff.truesize,
495 self->tx_buff.head, self->tx_buff_dma);
496 err_out3:
497 dma_free_coherent(NULL, self->rx_buff.truesize,
498 self->rx_buff.head, self->rx_buff_dma);
499 err_out2:
500 free_netdev(self->netdev);
501 dev_self[--dev_count] = NULL;
502 err_out1:
503 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
504 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
505 err_out:
506 return err;
507}
508
509/*
510 * Function smsc_ircc_present(fir_base, sir_base)
511 *
512 * Check the smsc-ircc chip presence
513 *
514 */
515static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
516{
517 unsigned char low, high, chip, config, dma, irq, version;
518
519 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
520 driver_name)) {
521 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
522 __FUNCTION__, fir_base);
523 goto out1;
524 }
525
526 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
527 driver_name)) {
528 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
529 __FUNCTION__, sir_base);
530 goto out2;
531 }
532
533 register_bank(fir_base, 3);
534
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700535 high = inb(fir_base + IRCC_ID_HIGH);
536 low = inb(fir_base + IRCC_ID_LOW);
537 chip = inb(fir_base + IRCC_CHIP_ID);
538 version = inb(fir_base + IRCC_VERSION);
539 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 dma = config & IRCC_INTERFACE_DMA_MASK;
541 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
542
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700543 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700544 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 __FUNCTION__, fir_base);
546 goto out3;
547 }
548 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
549 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
550 chip & 0x0f, version, fir_base, sir_base, dma, irq);
551
552 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700553
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 out3:
555 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
556 out2:
557 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
558 out1:
559 return -ENODEV;
560}
561
562/*
563 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
564 *
565 * Setup I/O
566 *
567 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700568static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
569 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 u8 dma, u8 irq)
571{
572 unsigned char config, chip_dma, chip_irq;
573
574 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700575 config = inb(fir_base + IRCC_INTERFACE);
576 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
577 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 self->io.fir_base = fir_base;
580 self->io.sir_base = sir_base;
581 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
582 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
583 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
584 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
585
586 if (irq < 255) {
587 if (irq != chip_irq)
588 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
589 driver_name, chip_irq, irq);
590 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700591 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (dma < 255) {
595 if (dma != chip_dma)
596 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
597 driver_name, chip_dma, dma);
598 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700599 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 self->io.dma = chip_dma;
601
602}
603
604/*
605 * Function smsc_ircc_setup_qos(self)
606 *
607 * Setup qos
608 *
609 */
610static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
611{
612 /* Initialize QoS for this device */
613 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700614
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
616 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
617
618 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
619 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
620 irda_qos_bits_to_value(&self->qos);
621}
622
623/*
624 * Function smsc_ircc_init_chip(self)
625 *
626 * Init chip
627 *
628 */
629static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
630{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700631 int iobase, ir_mode, ctrl, fast;
632
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700633 IRDA_ASSERT(self != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700635 iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 ir_mode = IRCC_CFGA_IRDA_SIR_A;
637 ctrl = 0;
638 fast = 0;
639
640 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700641 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
642 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700645 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode),
646 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700649 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
650 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700651#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700652 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
653 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700654#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700655 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
656 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700657
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700659 outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700660
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700662 outb(fast, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700665
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700667 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
670/*
671 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
672 *
673 * Process IOCTL commands for this device
674 *
675 */
676static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
677{
678 struct if_irda_req *irq = (struct if_irda_req *) rq;
679 struct smsc_ircc_cb *self;
680 unsigned long flags;
681 int ret = 0;
682
683 IRDA_ASSERT(dev != NULL, return -1;);
684
685 self = dev->priv;
686
687 IRDA_ASSERT(self != NULL, return -1;);
688
689 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700690
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 switch (cmd) {
692 case SIOCSBANDWIDTH: /* Set bandwidth */
693 if (!capable(CAP_NET_ADMIN))
694 ret = -EPERM;
695 else {
696 /* Make sure we are the only one touching
697 * self->io.speed and the hardware - Jean II */
698 spin_lock_irqsave(&self->lock, flags);
699 smsc_ircc_change_speed(self, irq->ifr_baudrate);
700 spin_unlock_irqrestore(&self->lock, flags);
701 }
702 break;
703 case SIOCSMEDIABUSY: /* Set media busy */
704 if (!capable(CAP_NET_ADMIN)) {
705 ret = -EPERM;
706 break;
707 }
708
709 irda_device_set_media_busy(self->netdev, TRUE);
710 break;
711 case SIOCGRECEIVING: /* Check if we are receiving right now */
712 irq->ifr_receiving = smsc_ircc_is_receiving(self);
713 break;
714 #if 0
715 case SIOCSDTRRTS:
716 if (!capable(CAP_NET_ADMIN)) {
717 ret = -EPERM;
718 break;
719 }
720 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
721 break;
722 #endif
723 default:
724 ret = -EOPNOTSUPP;
725 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 return ret;
728}
729
730static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
731{
732 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) dev->priv;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 return &self->stats;
735}
736
737#if SMSC_IRCC2_C_NET_TIMEOUT
738/*
739 * Function smsc_ircc_timeout (struct net_device *dev)
740 *
741 * The networking timeout management.
742 *
743 */
744
745static void smsc_ircc_timeout(struct net_device *dev)
746{
747 struct smsc_ircc_cb *self;
748 unsigned long flags;
749
750 self = (struct smsc_ircc_cb *) dev->priv;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700751
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
753 dev->name, self->io.speed);
754 spin_lock_irqsave(&self->lock, flags);
755 smsc_ircc_sir_start(self);
756 smsc_ircc_change_speed(self, self->io.speed);
757 dev->trans_start = jiffies;
758 netif_wake_queue(dev);
759 spin_unlock_irqrestore(&self->lock, flags);
760}
761#endif
762
763/*
764 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
765 *
766 * Transmits the current frame until FIFO is full, then
767 * waits until the next transmit interrupt, and continues until the
768 * frame is transmitted.
769 */
770int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
771{
772 struct smsc_ircc_cb *self;
773 unsigned long flags;
774 int iobase;
775 s32 speed;
776
777 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
778
779 IRDA_ASSERT(dev != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700780
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 self = (struct smsc_ircc_cb *) dev->priv;
782 IRDA_ASSERT(self != NULL, return 0;);
783
784 iobase = self->io.sir_base;
785
786 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700787
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 /* Make sure test of self->io.speed & speed change are atomic */
789 spin_lock_irqsave(&self->lock, flags);
790
791 /* Check if we need to change the speed */
792 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700793 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 /* Check for empty frame */
795 if (!skb->len) {
796 /*
797 * We send frames one by one in SIR mode (no
798 * pipelining), so at this point, if we were sending
799 * a previous frame, we just received the interrupt
800 * telling us it is finished (UART_IIR_THRI).
801 * Therefore, waiting for the transmitter to really
802 * finish draining the fifo won't take too long.
803 * And the interrupt handler is not expected to run.
804 * - Jean II */
805 smsc_ircc_sir_wait_hw_transmitter_finish(self);
806 smsc_ircc_change_speed(self, speed);
807 spin_unlock_irqrestore(&self->lock, flags);
808 dev_kfree_skb(skb);
809 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700811 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813
814 /* Init tx buffer */
815 self->tx_buff.data = self->tx_buff.head;
816
817 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700818 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821 self->stats.tx_bytes += self->tx_buff.len;
822
823 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700824 outb(UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825
826 spin_unlock_irqrestore(&self->lock, flags);
827
828 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 return 0;
831}
832
833/*
834 * Function smsc_ircc_set_fir_speed (self, baud)
835 *
836 * Change the speed of the device
837 *
838 */
839static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
840{
841 int fir_base, ir_mode, ctrl, fast;
842
843 IRDA_ASSERT(self != NULL, return;);
844 fir_base = self->io.fir_base;
845
846 self->io.speed = speed;
847
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700848 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700850 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 ir_mode = IRCC_CFGA_IRDA_HDLC;
852 ctrl = IRCC_CRC;
853 fast = 0;
854 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
855 break;
856 case 1152000:
857 ir_mode = IRCC_CFGA_IRDA_HDLC;
858 ctrl = IRCC_1152 | IRCC_CRC;
859 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
860 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
861 __FUNCTION__);
862 break;
863 case 4000000:
864 ir_mode = IRCC_CFGA_IRDA_4PPM;
865 ctrl = IRCC_CRC;
866 fast = IRCC_LCR_A_FAST;
867 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
868 __FUNCTION__);
869 break;
870 }
871 #if 0
872 Now in tranceiver!
873 /* This causes an interrupt */
874 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700875 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700877
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700879 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 -0700880
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700882 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883}
884
885/*
886 * Function smsc_ircc_fir_start(self)
887 *
888 * Change the speed of the device
889 *
890 */
891static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
892{
893 struct net_device *dev;
894 int fir_base;
895
896 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
897
898 IRDA_ASSERT(self != NULL, return;);
899 dev = self->netdev;
900 IRDA_ASSERT(dev != NULL, return;);
901
902 fir_base = self->io.fir_base;
903
904 /* Reset everything */
905
906 /* Install FIR transmit handler */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700907 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908
909 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700910 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
912 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700913 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 register_bank(fir_base, 1);
916
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700917 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700919 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
920 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700921#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700922 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
923 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700924#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700925 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700928 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700930 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
931 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
934/*
935 * Function smsc_ircc_fir_stop(self, baud)
936 *
937 * Change the speed of the device
938 *
939 */
940static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
941{
942 int fir_base;
943
944 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700945
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 IRDA_ASSERT(self != NULL, return;);
947
948 fir_base = self->io.fir_base;
949 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700950 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
951 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952}
953
954
955/*
956 * Function smsc_ircc_change_speed(self, baud)
957 *
958 * Change the speed of the device
959 *
960 * This function *must* be called with spinlock held, because it may
961 * be called from the irq handler. - Jean II
962 */
963static void smsc_ircc_change_speed(void *priv, u32 speed)
964{
965 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv;
966 struct net_device *dev;
967 int iobase;
968 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700969
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
971
972 IRDA_ASSERT(self != NULL, return;);
973 dev = self->netdev;
974 iobase = self->io.fir_base;
975
976 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
977
978 #if 0
979 /* Temp Hack */
980 speed= 1152000;
981 self->io.speed = speed;
982 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700983 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700985
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700986 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 smsc_ircc_sir_start(self);
988
989 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700990 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 #endif
992
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700993 if (self->io.speed != speed)
994 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995
996 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700997
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700998 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
999 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 smsc_ircc_fir_stop(self);
1001 smsc_ircc_sir_start(self);
1002 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001003 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001004 } else {
1005 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001006 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 smsc_ircc_sir_stop(self);
1008 #endif
1009 smsc_ircc_fir_start(self);
1010 }
1011 smsc_ircc_set_fir_speed(self, speed);
1012
1013 #if 0
1014 self->tx_buff.len = 10;
1015 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001016
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 smsc_ircc_dma_xmit(self, iobase, 4000);
1018 #endif
1019 /* Be ready for incoming frames */
1020 smsc_ircc_dma_receive(self, iobase);
1021 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001022
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 netif_wake_queue(dev);
1024}
1025
1026/*
1027 * Function smsc_ircc_set_sir_speed (self, speed)
1028 *
1029 * Set speed of IrDA port to specified baudrate
1030 *
1031 */
1032void smsc_ircc_set_sir_speed(void *priv, __u32 speed)
1033{
1034 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001035 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 int fcr; /* FIFO control reg */
1037 int lcr; /* Line control reg */
1038 int divisor;
1039
1040 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1041
1042 IRDA_ASSERT(self != NULL, return;);
1043 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 /* Update accounting for new speed */
1046 self->io.speed = speed;
1047
1048 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001049 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001051 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 fcr = UART_FCR_ENABLE_FIFO;
1054
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001055 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1057 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001058 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001060 fcr |= self->io.speed < 38400 ?
1061 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 /* IrDA ports use 8N1 */
1064 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001065
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001066 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1067 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1068 outb(divisor >> 8, iobase + UART_DLM);
1069 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1070 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001073 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1076}
1077
1078
1079/*
1080 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1081 *
1082 * Transmit the frame!
1083 *
1084 */
1085static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1086{
1087 struct smsc_ircc_cb *self;
1088 unsigned long flags;
1089 s32 speed;
1090 int iobase;
1091 int mtt;
1092
1093 IRDA_ASSERT(dev != NULL, return 0;);
1094 self = (struct smsc_ircc_cb *) dev->priv;
1095 IRDA_ASSERT(self != NULL, return 0;);
1096
1097 iobase = self->io.fir_base;
1098
1099 netif_stop_queue(dev);
1100
1101 /* Make sure test of self->io.speed & speed change are atomic */
1102 spin_lock_irqsave(&self->lock, flags);
1103
1104 /* Check if we need to change the speed after this frame */
1105 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001106 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 /* Check for empty frame */
1108 if (!skb->len) {
1109 /* Note : you should make sure that speed changes
1110 * are not going to corrupt any outgoing frame.
1111 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001112 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 spin_unlock_irqrestore(&self->lock, flags);
1114 dev_kfree_skb(skb);
1115 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001116 }
1117
1118 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001120
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 memcpy(self->tx_buff.head, skb->data, skb->len);
1122
1123 self->tx_buff.len = skb->len;
1124 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001125
1126 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 if (mtt) {
1128 int bofs;
1129
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001130 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 * Compute how many BOFs (STA or PA's) we need to waste the
1132 * min turn time given the speed of the link.
1133 */
1134 bofs = mtt * (self->io.speed / 1000) / 8000;
1135 if (bofs > 4095)
1136 bofs = 4095;
1137
1138 smsc_ircc_dma_xmit(self, iobase, bofs);
1139 } else {
1140 /* Transmit frame */
1141 smsc_ircc_dma_xmit(self, iobase, 0);
1142 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 spin_unlock_irqrestore(&self->lock, flags);
1145 dev_kfree_skb(skb);
1146
1147 return 0;
1148}
1149
1150/*
1151 * Function smsc_ircc_dma_xmit (self, iobase)
1152 *
1153 * Transmit data using DMA
1154 *
1155 */
1156static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs)
1157{
1158 u8 ctrl;
1159
1160 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1161#if 1
1162 /* Disable Rx */
1163 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001164 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165#endif
1166 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001167 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1168 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169
1170 self->io.direction = IO_XMIT;
1171
1172 /* Set BOF additional count for generating the min turn time */
1173 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001174 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1175 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1176 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001179 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1180 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
1182 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001183
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184 /* Enable burst mode chip Tx DMA */
1185 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001186 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1187 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 /* Setup DMA controller (must be done after enabling chip DMA) */
1190 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1191 DMA_TX_MODE);
1192
1193 /* Enable interrupt */
1194
1195 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001196 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1197 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001198
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001200 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201}
1202
1203/*
1204 * Function smsc_ircc_dma_xmit_complete (self)
1205 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001206 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 * by the interrupt handler
1208 *
1209 */
1210static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase)
1211{
1212 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1213#if 0
1214 /* Disable Tx */
1215 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001216 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217#endif
1218 register_bank(self->io.fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001219 outb(inb(self->io.fir_base + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1220 self->io.fir_base + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 /* Check for underrun! */
1223 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001224 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 self->stats.tx_errors++;
1226 self->stats.tx_fifo_errors++;
1227
1228 /* Reset error condition */
1229 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001230 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1231 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 } else {
1233 self->stats.tx_packets++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001234 self->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 }
1236
1237 /* Check if it's time to change the speed */
1238 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001239 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 self->new_speed = 0;
1241 }
1242
1243 netif_wake_queue(self->netdev);
1244}
1245
1246/*
1247 * Function smsc_ircc_dma_receive(self)
1248 *
1249 * Get ready for receiving a frame. The device will initiate a DMA
1250 * if it starts to receive a frame.
1251 *
1252 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001253static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
1255#if 0
1256 /* Turn off chip DMA */
1257 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001258 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1259 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001261
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 /* Disable Tx */
1263 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001264 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 /* Turn off chip DMA */
1267 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001268 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1269 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 self->io.direction = IO_RECV;
1272 self->rx_buff.data = self->rx_buff.head;
1273
1274 /* Set max Rx frame size */
1275 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001276 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1277 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
1279 /* Setup DMA controller */
1280 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1281 DMA_RX_MODE);
1282
1283 /* Enable burst mode chip Rx DMA */
1284 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001285 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1286 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288 /* Enable interrupt */
1289 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001290 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1291 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
1293 /* Enable receiver */
1294 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001295 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001296 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 return 0;
1299}
1300
1301/*
1302 * Function smsc_ircc_dma_receive_complete(self, iobase)
1303 *
1304 * Finished with receiving frames
1305 *
1306 */
1307static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase)
1308{
1309 struct sk_buff *skb;
1310 int len, msgcnt, lsr;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001311
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1315#if 0
1316 /* Disable Rx */
1317 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001318 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319#endif
1320 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001321 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1322 lsr= inb(iobase + IRCC_LSR);
1323 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1326 get_dma_residue(self->io.dma));
1327
1328 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1329
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001330 /* Look for errors */
1331 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 self->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001333 if (lsr & IRCC_LSR_FRAME_ERROR)
1334 self->stats.rx_frame_errors++;
1335 if (lsr & IRCC_LSR_CRC_ERROR)
1336 self->stats.rx_crc_errors++;
1337 if (lsr & IRCC_LSR_SIZE_ERROR)
1338 self->stats.rx_length_errors++;
1339 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1340 self->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 return;
1342 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001344 /* Remove CRC */
1345 len -= self->io.speed < 4000000 ? 2 : 4;
1346
1347 if (len < 2 || len > 2050) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1349 return;
1350 }
1351 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1352
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001353 skb = dev_alloc_skb(len + 1);
1354 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1356 __FUNCTION__);
1357 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001360 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1363 self->stats.rx_packets++;
1364 self->stats.rx_bytes += len;
1365
1366 skb->dev = self->netdev;
1367 skb->mac.raw = skb->data;
1368 skb->protocol = htons(ETH_P_IRDA);
1369 netif_rx(skb);
1370}
1371
1372/*
1373 * Function smsc_ircc_sir_receive (self)
1374 *
1375 * Receive one frame from the infrared port
1376 *
1377 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001378static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379{
1380 int boguscount = 0;
1381 int iobase;
1382
1383 IRDA_ASSERT(self != NULL, return;);
1384
1385 iobase = self->io.sir_base;
1386
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001387 /*
1388 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1389 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390 */
1391 do {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001392 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001393 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394
1395 /* Make sure we don't stay here to long */
1396 if (boguscount++ > 32) {
1397 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1398 break;
1399 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001400 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401}
1402
1403
1404/*
1405 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1406 *
1407 * An interrupt from the chip has arrived. Time to do some work
1408 *
1409 */
1410static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1411{
1412 struct net_device *dev = (struct net_device *) dev_id;
1413 struct smsc_ircc_cb *self;
1414 int iobase, iir, lcra, lsr;
1415 irqreturn_t ret = IRQ_NONE;
1416
1417 if (dev == NULL) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001418 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 driver_name, irq);
1420 goto irq_ret;
1421 }
1422 self = (struct smsc_ircc_cb *) dev->priv;
1423 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1424
1425 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001426 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
1428 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001429 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 ret = smsc_ircc_interrupt_sir(dev);
1431 goto irq_ret_unlock;
1432 }
1433
1434 iobase = self->io.fir_base;
1435
1436 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001437 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001438 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 goto irq_ret_unlock;
1440 ret = IRQ_HANDLED;
1441
1442 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001443 outb(0, iobase + IRCC_IER);
1444 lcra = inb(iobase + IRCC_LCR_A);
1445 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001446
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1448
1449 if (iir & IRCC_IIR_EOM) {
1450 if (self->io.direction == IO_RECV)
1451 smsc_ircc_dma_receive_complete(self, iobase);
1452 else
1453 smsc_ircc_dma_xmit_complete(self, iobase);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001454
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 smsc_ircc_dma_receive(self, iobase);
1456 }
1457
1458 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1459 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1460 }
1461
1462 /* Enable interrupts again */
1463
1464 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001465 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 irq_ret_unlock:
1468 spin_unlock(&self->lock);
1469 irq_ret:
1470 return ret;
1471}
1472
1473/*
1474 * Function irport_interrupt_sir (irq, dev_id, regs)
1475 *
1476 * Interrupt handler for SIR modes
1477 */
1478static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1479{
1480 struct smsc_ircc_cb *self = dev->priv;
1481 int boguscount = 0;
1482 int iobase;
1483 int iir, lsr;
1484
1485 /* Already locked comming here in smsc_ircc_interrupt() */
1486 /*spin_lock(&self->lock);*/
1487
1488 iobase = self->io.sir_base;
1489
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001490 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 if (iir == 0)
1492 return IRQ_NONE;
1493 while (iir) {
1494 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001495 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001497 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 __FUNCTION__, iir, lsr, iobase);
1499
1500 switch (iir) {
1501 case UART_IIR_RLSI:
1502 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1503 break;
1504 case UART_IIR_RDI:
1505 /* Receive interrupt */
1506 smsc_ircc_sir_receive(self);
1507 break;
1508 case UART_IIR_THRI:
1509 if (lsr & UART_LSR_THRE)
1510 /* Transmitter ready for data */
1511 smsc_ircc_sir_write_wakeup(self);
1512 break;
1513 default:
1514 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1515 __FUNCTION__, iir);
1516 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001517 }
1518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 /* Make sure we don't stay here to long */
1520 if (boguscount++ > 100)
1521 break;
1522
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001523 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 }
1525 /*spin_unlock(&self->lock);*/
1526 return IRQ_HANDLED;
1527}
1528
1529
1530#if 0 /* unused */
1531/*
1532 * Function ircc_is_receiving (self)
1533 *
1534 * Return TRUE is we are currently receiving a frame
1535 *
1536 */
1537static int ircc_is_receiving(struct smsc_ircc_cb *self)
1538{
1539 int status = FALSE;
1540 /* int iobase; */
1541
1542 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1543
1544 IRDA_ASSERT(self != NULL, return FALSE;);
1545
1546 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1547 get_dma_residue(self->io.dma));
1548
1549 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001550
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 return status;
1552}
1553#endif /* unused */
1554
1555
1556/*
1557 * Function smsc_ircc_net_open (dev)
1558 *
1559 * Start the device
1560 *
1561 */
1562static int smsc_ircc_net_open(struct net_device *dev)
1563{
1564 struct smsc_ircc_cb *self;
1565 int iobase;
1566 char hwname[16];
1567 unsigned long flags;
1568
1569 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001570
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 IRDA_ASSERT(dev != NULL, return -1;);
1572 self = (struct smsc_ircc_cb *) dev->priv;
1573 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001574
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 iobase = self->io.fir_base;
1576
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001577 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 (void *) dev)) {
1579 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1580 __FUNCTION__, self->io.irq);
1581 return -EAGAIN;
1582 }
1583
1584 spin_lock_irqsave(&self->lock, flags);
1585 /*smsc_ircc_sir_start(self);*/
1586 self->io.speed = 0;
1587 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1588 spin_unlock_irqrestore(&self->lock, flags);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 /* Give self a hardware name */
1591 /* It would be cool to offer the chip revision here - Jean II */
1592 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1593
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001594 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001596 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 */
1598 self->irlap = irlap_open(dev, &self->qos, hwname);
1599
1600 /*
1601 * Always allocate the DMA channel after the IRQ,
1602 * and clean up on failure.
1603 */
1604 if (request_dma(self->io.dma, dev->name)) {
1605 smsc_ircc_net_close(dev);
1606
1607 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1608 __FUNCTION__, self->io.dma);
1609 return -EAGAIN;
1610 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 netif_start_queue(dev);
1613
1614 return 0;
1615}
1616
1617/*
1618 * Function smsc_ircc_net_close (dev)
1619 *
1620 * Stop the device
1621 *
1622 */
1623static int smsc_ircc_net_close(struct net_device *dev)
1624{
1625 struct smsc_ircc_cb *self;
1626 int iobase;
1627
1628 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001631 self = (struct smsc_ircc_cb *) dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001633
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 iobase = self->io.fir_base;
1635
1636 /* Stop device */
1637 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /* Stop and remove instance of IrLAP */
1640 if (self->irlap)
1641 irlap_close(self->irlap);
1642 self->irlap = NULL;
1643
1644 free_irq(self->io.irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 free_dma(self->io.dma);
1647
1648 return 0;
1649}
1650
1651
1652static void smsc_ircc_suspend(struct smsc_ircc_cb *self)
1653{
1654 IRDA_MESSAGE("%s, Suspending\n", driver_name);
1655
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001656 if (!self->io.suspended) {
1657 smsc_ircc_net_close(self->netdev);
1658 self->io.suspended = 1;
1659 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
1662static void smsc_ircc_wakeup(struct smsc_ircc_cb *self)
1663{
1664 if (!self->io.suspended)
1665 return;
1666
1667 /* The code was doing a "cli()" here, but this can't be right.
1668 * If you need protection, do it in net_open with a spinlock
1669 * or give a good reason. - Jean II */
1670
1671 smsc_ircc_net_open(self->netdev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001672
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 IRDA_MESSAGE("%s, Waking up\n", driver_name);
1674}
1675
1676static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data)
1677{
1678 struct smsc_ircc_cb *self = (struct smsc_ircc_cb*) dev->data;
1679 if (self) {
1680 switch (rqst) {
1681 case PM_SUSPEND:
1682 smsc_ircc_suspend(self);
1683 break;
1684 case PM_RESUME:
1685 smsc_ircc_wakeup(self);
1686 break;
1687 }
1688 }
1689 return 0;
1690}
1691
1692/*
1693 * Function smsc_ircc_close (self)
1694 *
1695 * Close driver instance
1696 *
1697 */
1698static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1699{
1700 int iobase;
1701 unsigned long flags;
1702
1703 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1704
1705 IRDA_ASSERT(self != NULL, return -1;);
1706
1707 iobase = self->io.fir_base;
1708
1709 if (self->pmdev)
1710 pm_unregister(self->pmdev);
1711
1712 /* Remove netdevice */
1713 unregister_netdev(self->netdev);
1714
1715 /* Make sure the irq handler is not exectuting */
1716 spin_lock_irqsave(&self->lock, flags);
1717
1718 /* Stop interrupts */
1719 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001720 outb(0, iobase + IRCC_IER);
1721 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1722 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723#if 0
1724 /* Reset to SIR mode */
1725 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001726 outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
1727 outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728#endif
1729 spin_unlock_irqrestore(&self->lock, flags);
1730
1731 /* Release the PORTS that this driver is using */
1732 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1733 self->io.fir_base);
1734
1735 release_region(self->io.fir_base, self->io.fir_ext);
1736
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001737 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 self->io.sir_base);
1739
1740 release_region(self->io.sir_base, self->io.sir_ext);
1741
1742 if (self->tx_buff.head)
1743 dma_free_coherent(NULL, self->tx_buff.truesize,
1744 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 if (self->rx_buff.head)
1747 dma_free_coherent(NULL, self->rx_buff.truesize,
1748 self->rx_buff.head, self->rx_buff_dma);
1749
1750 free_netdev(self->netdev);
1751
1752 return 0;
1753}
1754
1755static void __exit smsc_ircc_cleanup(void)
1756{
1757 int i;
1758
1759 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1760
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001761 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 if (dev_self[i])
1763 smsc_ircc_close(dev_self[i]);
1764 }
1765}
1766
1767/*
1768 * Start SIR operations
1769 *
1770 * This function *must* be called with spinlock held, because it may
1771 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1772 */
1773void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1774{
1775 struct net_device *dev;
1776 int fir_base, sir_base;
1777
1778 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1779
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001780 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001781 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001782 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1784
1785 fir_base = self->io.fir_base;
1786 sir_base = self->io.sir_base;
1787
1788 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001789 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
1791 #if SMSC_IRCC2_C_SIR_STOP
1792 /*smsc_ircc_sir_stop(self);*/
1793 #endif
1794
1795 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001796 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 -07001797
1798 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001799 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1800 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001801
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001803 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1806
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001807 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808}
1809
1810#if SMSC_IRCC2_C_SIR_STOP
1811void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1812{
1813 int iobase;
1814
1815 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1816 iobase = self->io.sir_base;
1817
1818 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001819 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001820
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001822 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823}
1824#endif
1825
1826/*
1827 * Function smsc_sir_write_wakeup (self)
1828 *
1829 * Called by the SIR interrupt handler when there's room for more data.
1830 * If we have more packets to send, we send them here.
1831 *
1832 */
1833static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1834{
1835 int actual = 0;
1836 int iobase;
1837 int fcr;
1838
1839 IRDA_ASSERT(self != NULL, return;);
1840
1841 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1842
1843 iobase = self->io.sir_base;
1844
1845 /* Finished with frame? */
1846 if (self->tx_buff.len > 0) {
1847 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001848 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 self->tx_buff.data, self->tx_buff.len);
1850 self->tx_buff.data += actual;
1851 self->tx_buff.len -= actual;
1852 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001853
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001855
1856 /*
1857 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 * transmission of another packet. But first we must check
1859 * if we need to change the speed of the hardware
1860 */
1861 if (self->new_speed) {
1862 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1863 __FUNCTION__, self->new_speed);
1864 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1865 smsc_ircc_change_speed(self, self->new_speed);
1866 self->new_speed = 0;
1867 } else {
1868 /* Tell network layer that we want more frames */
1869 netif_wake_queue(self->netdev);
1870 }
1871 self->stats.tx_packets++;
1872
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001873 if (self->io.speed <= 115200) {
1874 /*
1875 * Reset Rx FIFO to make sure that all reflected transmit data
1876 * is discarded. This is needed for half duplex operation
1877 */
1878 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1879 fcr |= self->io.speed < 38400 ?
1880 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001882 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001884 /* Turn on receive interrupts */
1885 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
1887 }
1888}
1889
1890/*
1891 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1892 *
1893 * Fill Tx FIFO with transmit data
1894 *
1895 */
1896static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1897{
1898 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001899
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001901 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1903 return 0;
1904 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001907 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001909 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 actual++;
1911 }
1912 return actual;
1913}
1914
1915/*
1916 * Function smsc_ircc_is_receiving (self)
1917 *
1918 * Returns true is we are currently receiving data
1919 *
1920 */
1921static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
1922{
1923 return (self->rx_buff.state != OUTSIDE_FRAME);
1924}
1925
1926
1927/*
1928 * Function smsc_ircc_probe_transceiver(self)
1929 *
1930 * Tries to find the used Transceiver
1931 *
1932 */
1933static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
1934{
1935 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001936
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001938
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001939 for (i = 0; smsc_transceivers[i].name != NULL; i++)
1940 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 IRDA_MESSAGE(" %s transceiver found\n",
1942 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001943 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 return;
1945 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001946
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
1948 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001949
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001950 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
1953
1954/*
1955 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
1956 *
1957 * Set the transceiver according to the speed
1958 *
1959 */
1960static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
1961{
1962 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001963
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001965 if (trx > 0)
1966 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
1969/*
1970 * Function smsc_ircc_wait_hw_transmitter_finish ()
1971 *
1972 * Wait for the real end of HW transmission
1973 *
1974 * The UART is a strict FIFO, and we get called only when we have finished
1975 * pushing data to the FIFO, so the maximum amount of time we must wait
1976 * is only for the FIFO to drain out.
1977 *
1978 * We use a simple calibrated loop. We may need to adjust the loop
1979 * delay (udelay) to balance I/O traffic and latency. And we also need to
1980 * adjust the maximum timeout.
1981 * It would probably be better to wait for the proper interrupt,
1982 * but it doesn't seem to be available.
1983 *
1984 * We can't use jiffies or kernel timers because :
1985 * 1) We are called from the interrupt handler, which disable softirqs,
1986 * so jiffies won't be increased
1987 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
1988 * want to wait that long to detect stuck hardware.
1989 * Jean II
1990 */
1991
1992static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
1993{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001994 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001996
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001998 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 udelay(1);
2000
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002001 if (count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
2003}
2004
2005
2006/* PROBING
2007 *
2008 *
2009 */
2010
2011static int __init smsc_ircc_look_for_chips(void)
2012{
2013 smsc_chip_address_t *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002014 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002016
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 found = 0;
2018 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002019
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002020 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002022
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002024
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002025 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002027 if (address->type & SMSCSIO_TYPE_FLAT)
2028 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2029 found++;
2030
2031 if (address->type & SMSCSIO_TYPE_PAGED)
2032 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2033 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002035 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002037 if (address->type & SMSCSIO_TYPE_FLAT)
2038 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2039 found++;
2040
2041 if (address->type & SMSCSIO_TYPE_PAGED)
2042 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2043 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 }
2045 address++;
2046 }
2047 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002048}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050/*
2051 * Function smsc_superio_flat (chip, base, type)
2052 *
2053 * Try to get configuration of a smc SuperIO chip with flat register model
2054 *
2055 */
2056static int __init smsc_superio_flat(const smsc_chip_t *chips, unsigned short cfgbase, char *type)
2057{
2058 unsigned short firbase, sirbase;
2059 u8 mode, dma, irq;
2060 int ret = -ENODEV;
2061
2062 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2063
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002064 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 return ret;
2066
2067 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002068 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002071
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002072 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2074
2075 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002076 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002078 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002080 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
2082 /* DMA */
2083 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002084 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 /* IRQ */
2087 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002088 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089
2090 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2091
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002092 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2093 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002094
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 /* Exit configuration */
2096 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2097
2098 return ret;
2099}
2100
2101/*
2102 * Function smsc_superio_paged (chip, base, type)
2103 *
2104 * Try to get configuration of a smc SuperIO chip with paged register model
2105 *
2106 */
2107static int __init smsc_superio_paged(const smsc_chip_t *chips, unsigned short cfg_base, char *type)
2108{
2109 unsigned short fir_io, sir_io;
2110 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2113
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002114 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002116
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 /* Select logical device (UART2) */
2118 outb(0x07, cfg_base);
2119 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002120
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 /* SIR iobase */
2122 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002123 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 outb(0x61, cfg_base);
2125 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002126
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 /* Read FIR base */
2128 outb(0x62, cfg_base);
2129 fir_io = inb(cfg_base + 1) << 8;
2130 outb(0x63, cfg_base);
2131 fir_io |= inb(cfg_base + 1);
2132 outb(0x2b, cfg_base); /* ??? */
2133
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002134 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2135 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002136
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 /* Exit configuration */
2138 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2139
2140 return ret;
2141}
2142
2143
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002144static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
2146 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2147
2148 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002149 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150}
2151
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002152static const smsc_chip_t * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const smsc_chip_t *chip, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002154 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
2156 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2157
2158 /* Leave configuration */
2159
2160 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2161
2162 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2163 return NULL;
2164
2165 outb(reg, cfg_base);
2166
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002167 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 /* Enter configuration */
2170
2171 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2172
2173 #if 0
2174 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2175 return NULL;
2176 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002177
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 /* probe device ID */
2179
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002180 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 return NULL;
2182
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002183 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002184
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002185 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 return NULL;
2187
2188 /* probe revision ID */
2189
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002190 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 return NULL;
2192
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002193 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002195 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 return NULL;
2197
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002198 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 return NULL;
2200
2201 /* Check for expected device ID; are there others? */
2202
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002203 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
2205 chip++;
2206
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002207 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 return NULL;
2209 }
2210
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002211 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2212 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002214 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002215 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 return NULL;
2217 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002218
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002219 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 IRDA_MESSAGE("chipset does not support IRDA\n");
2221
2222 return chip;
2223}
2224
2225static int __init smsc_superio_fdc(unsigned short cfg_base)
2226{
2227 int ret = -1;
2228
2229 if (!request_region(cfg_base, 2, driver_name)) {
2230 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2231 __FUNCTION__, cfg_base);
2232 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002233 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2234 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 ret = 0;
2236
2237 release_region(cfg_base, 2);
2238 }
2239
2240 return ret;
2241}
2242
2243static int __init smsc_superio_lpc(unsigned short cfg_base)
2244{
2245 int ret = -1;
2246
2247 if (!request_region(cfg_base, 2, driver_name)) {
2248 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2249 __FUNCTION__, cfg_base);
2250 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002251 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2252 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002254
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 release_region(cfg_base, 2);
2256 }
2257 return ret;
2258}
2259
2260/************************************************
2261 *
2262 * Transceivers specific functions
2263 *
2264 ************************************************/
2265
2266
2267/*
2268 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2269 *
2270 * Program transceiver through smsc-ircc ATC circuitry
2271 *
2272 */
2273
2274static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2275{
2276 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002277 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002278
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002279 jiffies_now = jiffies;
2280 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002281
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 /* ATC */
2283 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002284 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2285 fir_base + IRCC_ATC);
2286
2287 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2288 !time_after(jiffies, jiffies_timeout))
2289 /* empty */;
2290
2291 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002293 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294}
2295
2296/*
2297 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2298 *
2299 * Probe transceiver smsc-ircc ATC circuitry
2300 *
2301 */
2302
2303static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2304{
2305 return 0;
2306}
2307
2308/*
2309 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2310 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002311 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 *
2313 */
2314
2315static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2316{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002317 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002318
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002319 switch (speed) {
2320 default:
2321 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002322 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002324 case 1152000 :
2325 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 fast_mode = IRCC_LCR_A_FAST;
2327 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 }
2329 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002330 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
2333/*
2334 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2335 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002336 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 *
2338 */
2339
2340static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2341{
2342 return 0;
2343}
2344
2345/*
2346 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2347 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002348 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 *
2350 */
2351
2352static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2353{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002354 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002355
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002356 switch (speed) {
2357 default:
2358 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002359 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002361 case 1152000 :
2362 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2364 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002365
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 }
2367 /* This causes an interrupt */
2368 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002369 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370}
2371
2372/*
2373 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2374 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002375 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 *
2377 */
2378
2379static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2380{
2381 return 0;
2382}
2383
2384
2385module_init(smsc_ircc_init);
2386module_exit(smsc_ircc_cleanup);