blob: 6c6747d2b00dac87b1600838baf177caa6d65944 [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};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109struct smsc_chip {
110 char *name;
111 #if 0
112 u8 type;
113 #endif
114 u16 flags;
115 u8 devid;
116 u8 rev;
117};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119struct smsc_chip_address {
120 unsigned int cfg_base;
121 unsigned int type;
122};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124/* Private data for each instance */
125struct smsc_ircc_cb {
126 struct net_device *netdev; /* Yes! we are some kind of netdevice */
127 struct net_device_stats stats;
128 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 chipio_t io; /* IrDA controller information */
131 iobuff_t tx_buff; /* Transmit buffer */
132 iobuff_t rx_buff; /* Receive buffer */
133 dma_addr_t tx_buff_dma;
134 dma_addr_t rx_buff_dma;
135
136 struct qos_info qos; /* QoS capabilities for this device */
137
138 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 __u32 new_speed;
141 __u32 flags; /* Interface flags */
142
143 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
144 int tx_len; /* Number of frames in tx_buff */
145
146 int transceiver;
147 struct pm_dev *pmdev;
148};
149
150/* Constants */
151
152static const char *driver_name = "smsc-ircc2";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
154#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700155#define SMSC_IRCC2_C_NET_TIMEOUT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156#define SMSC_IRCC2_C_SIR_STOP 0
157
158/* Prototypes */
159
160static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
161static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
162static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
163static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
164static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
165static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700166static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase);
168static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
169static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
170static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
171static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs);
172static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase);
173static void smsc_ircc_change_speed(void *priv, u32 speed);
174static void smsc_ircc_set_sir_speed(void *priv, u32 speed);
175static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
176static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
177static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
178#if SMSC_IRCC2_C_SIR_STOP
179static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
180#endif
181static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
182static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
183static int smsc_ircc_net_open(struct net_device *dev);
184static int smsc_ircc_net_close(struct net_device *dev);
185static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
186#if SMSC_IRCC2_C_NET_TIMEOUT
187static void smsc_ircc_timeout(struct net_device *dev);
188#endif
189static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
190static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
191static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
192static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
193static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
194static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
195
196/* Probing */
197static int __init smsc_ircc_look_for_chips(void);
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700198static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
199static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
200static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201static int __init smsc_superio_fdc(unsigned short cfg_base);
202static int __init smsc_superio_lpc(unsigned short cfg_base);
203
204/* Transceivers specific functions */
205
206static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
207static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
208static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
209static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
210static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
211static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
212
213/* Power Management */
214
215static void smsc_ircc_suspend(struct smsc_ircc_cb *self);
216static void smsc_ircc_wakeup(struct smsc_ircc_cb *self);
217static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data);
218
219
220/* Transceivers for SMSC-ircc */
221
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700222static struct smsc_transceiver smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700224 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
225 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
226 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
227 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700229#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231/* SMC SuperIO chipsets definitions */
232
233#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
234#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
235#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
236#define SIR 0 /* SuperIO Chip has only slow IRDA */
237#define FIR 4 /* SuperIO Chip has fast IRDA */
238#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
239
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700240static struct smsc_chip __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241{
242 /* Base address 0x3f0 or 0x370 */
243 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
244 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
245 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
246 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
247 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
248 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
249 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
250 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
251 { NULL }
252};
253
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700254static struct smsc_chip __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 /* Base address 0x3f0 or 0x370 */
257 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
258 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
259 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
260 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
261 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
262 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
263 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
264 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
265 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
266 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
267 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
268 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
269 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
270 { NULL }
271};
272
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700273static struct smsc_chip __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
275 /* Base address 0x2E or 0x4E */
276 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
277 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
278 { NULL }
279};
280
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700281static struct smsc_chip __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
283 /* Base address 0x2E or 0x4E */
284 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
285 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
286 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
287 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
288 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
289 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
290 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
291 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
292 { NULL }
293};
294
295#define SMSCSIO_TYPE_FDC 1
296#define SMSCSIO_TYPE_LPC 2
297#define SMSCSIO_TYPE_FLAT 4
298#define SMSCSIO_TYPE_PAGED 8
299
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700300static struct smsc_chip_address __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700302 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
303 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
304 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
305 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
306 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
307 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308};
309
310/* Globals */
311
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700312static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
313static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314
315static inline void register_bank(int iobase, int bank)
316{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700317 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
318 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319}
320
321
322/*******************************************************************************
323 *
324 *
325 * SMSC-ircc stuff
326 *
327 *
328 *******************************************************************************/
329
330/*
331 * Function smsc_ircc_init ()
332 *
333 * Initialize chip. Just try to find out how many chips we are dealing with
334 * and where they are
335 */
336static int __init smsc_ircc_init(void)
337{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700338 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
341
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700342 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700343
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700344 if (ircc_fir > 0 && ircc_sir > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
346 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
347
348 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq) == 0)
349 return 0;
350
351 return -ENODEV;
352 }
353
354 /* try user provided configuration register base address */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700355 if (ircc_cfg > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 IRDA_MESSAGE(" Overriding configuration address 0x%04x\n",
357 ircc_cfg);
358 if (!smsc_superio_fdc(ircc_cfg))
359 ret = 0;
360 if (!smsc_superio_lpc(ircc_cfg))
361 ret = 0;
362 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700363
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700364 if (smsc_ircc_look_for_chips() > 0)
365 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 return ret;
368}
369
370/*
371 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
372 *
373 * Try to open driver instance
374 *
375 */
376static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
377{
378 struct smsc_ircc_cb *self;
379 struct net_device *dev;
380 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
383
384 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700385 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700389 if (dev_count >= ARRAY_SIZE(dev_self)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
391 goto err_out1;
392 }
393
394 /*
395 * Allocate new instance of the driver
396 */
397 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
398 if (!dev) {
399 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
400 goto err_out1;
401 }
402
403 SET_MODULE_OWNER(dev);
404
405 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
406#if SMSC_IRCC2_C_NET_TIMEOUT
407 dev->tx_timeout = smsc_ircc_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700408 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#endif
410 dev->open = smsc_ircc_net_open;
411 dev->stop = smsc_ircc_net_close;
412 dev->do_ioctl = smsc_ircc_net_ioctl;
413 dev->get_stats = smsc_ircc_net_get_stats;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 self = dev->priv;
416 self->netdev = dev;
417
418 /* Make ifconfig display some details */
419 dev->base_addr = self->io.fir_base = fir_base;
420 dev->irq = self->io.irq = irq;
421
422 /* Need to store self somewhere */
423 dev_self[dev_count++] = self;
424 spin_lock_init(&self->lock);
425
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700426 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
428
429 self->rx_buff.head =
430 dma_alloc_coherent(NULL, self->rx_buff.truesize,
431 &self->rx_buff_dma, GFP_KERNEL);
432 if (self->rx_buff.head == NULL) {
433 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
434 driver_name);
435 goto err_out2;
436 }
437
438 self->tx_buff.head =
439 dma_alloc_coherent(NULL, self->tx_buff.truesize,
440 &self->tx_buff_dma, GFP_KERNEL);
441 if (self->tx_buff.head == NULL) {
442 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
443 driver_name);
444 goto err_out3;
445 }
446
447 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
448 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
449
450 self->rx_buff.in_frame = FALSE;
451 self->rx_buff.state = OUTSIDE_FRAME;
452 self->tx_buff.data = self->tx_buff.head;
453 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700458
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700459 if (ircc_transceiver > 0 &&
460 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 self->transceiver = ircc_transceiver;
462 else
463 smsc_ircc_probe_transceiver(self);
464
465 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700466 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 IRDA_ERROR("%s, Network device registration failed!\n",
468 driver_name);
469 goto err_out4;
470 }
471
472 self->pmdev = pm_register(PM_SYS_DEV, PM_SYS_IRDA, smsc_ircc_pmproc);
473 if (self->pmdev)
474 self->pmdev->data = self;
475
476 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
477
478 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 err_out4:
481 dma_free_coherent(NULL, self->tx_buff.truesize,
482 self->tx_buff.head, self->tx_buff_dma);
483 err_out3:
484 dma_free_coherent(NULL, self->rx_buff.truesize,
485 self->rx_buff.head, self->rx_buff_dma);
486 err_out2:
487 free_netdev(self->netdev);
488 dev_self[--dev_count] = NULL;
489 err_out1:
490 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
491 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
492 err_out:
493 return err;
494}
495
496/*
497 * Function smsc_ircc_present(fir_base, sir_base)
498 *
499 * Check the smsc-ircc chip presence
500 *
501 */
502static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
503{
504 unsigned char low, high, chip, config, dma, irq, version;
505
506 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
507 driver_name)) {
508 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
509 __FUNCTION__, fir_base);
510 goto out1;
511 }
512
513 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
514 driver_name)) {
515 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
516 __FUNCTION__, sir_base);
517 goto out2;
518 }
519
520 register_bank(fir_base, 3);
521
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700522 high = inb(fir_base + IRCC_ID_HIGH);
523 low = inb(fir_base + IRCC_ID_LOW);
524 chip = inb(fir_base + IRCC_CHIP_ID);
525 version = inb(fir_base + IRCC_VERSION);
526 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 dma = config & IRCC_INTERFACE_DMA_MASK;
528 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
529
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700530 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700531 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 __FUNCTION__, fir_base);
533 goto out3;
534 }
535 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
536 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
537 chip & 0x0f, version, fir_base, sir_base, dma, irq);
538
539 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 out3:
542 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
543 out2:
544 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
545 out1:
546 return -ENODEV;
547}
548
549/*
550 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
551 *
552 * Setup I/O
553 *
554 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700555static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
556 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 u8 dma, u8 irq)
558{
559 unsigned char config, chip_dma, chip_irq;
560
561 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700562 config = inb(fir_base + IRCC_INTERFACE);
563 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
564 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 self->io.fir_base = fir_base;
567 self->io.sir_base = sir_base;
568 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
569 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
570 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
571 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
572
573 if (irq < 255) {
574 if (irq != chip_irq)
575 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
576 driver_name, chip_irq, irq);
577 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700578 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 if (dma < 255) {
582 if (dma != chip_dma)
583 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
584 driver_name, chip_dma, dma);
585 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700586 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 self->io.dma = chip_dma;
588
589}
590
591/*
592 * Function smsc_ircc_setup_qos(self)
593 *
594 * Setup qos
595 *
596 */
597static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
598{
599 /* Initialize QoS for this device */
600 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
603 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
604
605 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
606 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
607 irda_qos_bits_to_value(&self->qos);
608}
609
610/*
611 * Function smsc_ircc_init_chip(self)
612 *
613 * Init chip
614 *
615 */
616static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
617{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700618 int iobase, ir_mode, ctrl, fast;
619
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700620 IRDA_ASSERT(self != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700622 iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 ir_mode = IRCC_CFGA_IRDA_SIR_A;
624 ctrl = 0;
625 fast = 0;
626
627 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700628 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
629 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630
631 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700632 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode),
633 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
635#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700636 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
637 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700638#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700639 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
640 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700641#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700642 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
643 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700644
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700646 outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700649 outb(fast, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650
651 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700654 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
657/*
658 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
659 *
660 * Process IOCTL commands for this device
661 *
662 */
663static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
664{
665 struct if_irda_req *irq = (struct if_irda_req *) rq;
666 struct smsc_ircc_cb *self;
667 unsigned long flags;
668 int ret = 0;
669
670 IRDA_ASSERT(dev != NULL, return -1;);
671
672 self = dev->priv;
673
674 IRDA_ASSERT(self != NULL, return -1;);
675
676 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 switch (cmd) {
679 case SIOCSBANDWIDTH: /* Set bandwidth */
680 if (!capable(CAP_NET_ADMIN))
681 ret = -EPERM;
682 else {
683 /* Make sure we are the only one touching
684 * self->io.speed and the hardware - Jean II */
685 spin_lock_irqsave(&self->lock, flags);
686 smsc_ircc_change_speed(self, irq->ifr_baudrate);
687 spin_unlock_irqrestore(&self->lock, flags);
688 }
689 break;
690 case SIOCSMEDIABUSY: /* Set media busy */
691 if (!capable(CAP_NET_ADMIN)) {
692 ret = -EPERM;
693 break;
694 }
695
696 irda_device_set_media_busy(self->netdev, TRUE);
697 break;
698 case SIOCGRECEIVING: /* Check if we are receiving right now */
699 irq->ifr_receiving = smsc_ircc_is_receiving(self);
700 break;
701 #if 0
702 case SIOCSDTRRTS:
703 if (!capable(CAP_NET_ADMIN)) {
704 ret = -EPERM;
705 break;
706 }
707 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
708 break;
709 #endif
710 default:
711 ret = -EOPNOTSUPP;
712 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700713
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 return ret;
715}
716
717static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
718{
719 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) dev->priv;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700720
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 return &self->stats;
722}
723
724#if SMSC_IRCC2_C_NET_TIMEOUT
725/*
726 * Function smsc_ircc_timeout (struct net_device *dev)
727 *
728 * The networking timeout management.
729 *
730 */
731
732static void smsc_ircc_timeout(struct net_device *dev)
733{
734 struct smsc_ircc_cb *self;
735 unsigned long flags;
736
737 self = (struct smsc_ircc_cb *) dev->priv;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
740 dev->name, self->io.speed);
741 spin_lock_irqsave(&self->lock, flags);
742 smsc_ircc_sir_start(self);
743 smsc_ircc_change_speed(self, self->io.speed);
744 dev->trans_start = jiffies;
745 netif_wake_queue(dev);
746 spin_unlock_irqrestore(&self->lock, flags);
747}
748#endif
749
750/*
751 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
752 *
753 * Transmits the current frame until FIFO is full, then
754 * waits until the next transmit interrupt, and continues until the
755 * frame is transmitted.
756 */
757int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
758{
759 struct smsc_ircc_cb *self;
760 unsigned long flags;
761 int iobase;
762 s32 speed;
763
764 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
765
766 IRDA_ASSERT(dev != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700767
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768 self = (struct smsc_ircc_cb *) dev->priv;
769 IRDA_ASSERT(self != NULL, return 0;);
770
771 iobase = self->io.sir_base;
772
773 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 /* Make sure test of self->io.speed & speed change are atomic */
776 spin_lock_irqsave(&self->lock, flags);
777
778 /* Check if we need to change the speed */
779 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700780 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 /* Check for empty frame */
782 if (!skb->len) {
783 /*
784 * We send frames one by one in SIR mode (no
785 * pipelining), so at this point, if we were sending
786 * a previous frame, we just received the interrupt
787 * telling us it is finished (UART_IIR_THRI).
788 * Therefore, waiting for the transmitter to really
789 * finish draining the fifo won't take too long.
790 * And the interrupt handler is not expected to run.
791 * - Jean II */
792 smsc_ircc_sir_wait_hw_transmitter_finish(self);
793 smsc_ircc_change_speed(self, speed);
794 spin_unlock_irqrestore(&self->lock, flags);
795 dev_kfree_skb(skb);
796 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700798 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 }
800
801 /* Init tx buffer */
802 self->tx_buff.data = self->tx_buff.head;
803
804 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700805 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 self->stats.tx_bytes += self->tx_buff.len;
809
810 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700811 outb(UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 spin_unlock_irqrestore(&self->lock, flags);
814
815 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700816
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 return 0;
818}
819
820/*
821 * Function smsc_ircc_set_fir_speed (self, baud)
822 *
823 * Change the speed of the device
824 *
825 */
826static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
827{
828 int fir_base, ir_mode, ctrl, fast;
829
830 IRDA_ASSERT(self != NULL, return;);
831 fir_base = self->io.fir_base;
832
833 self->io.speed = speed;
834
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700835 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700837 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 ir_mode = IRCC_CFGA_IRDA_HDLC;
839 ctrl = IRCC_CRC;
840 fast = 0;
841 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
842 break;
843 case 1152000:
844 ir_mode = IRCC_CFGA_IRDA_HDLC;
845 ctrl = IRCC_1152 | IRCC_CRC;
846 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
847 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
848 __FUNCTION__);
849 break;
850 case 4000000:
851 ir_mode = IRCC_CFGA_IRDA_4PPM;
852 ctrl = IRCC_CRC;
853 fast = IRCC_LCR_A_FAST;
854 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
855 __FUNCTION__);
856 break;
857 }
858 #if 0
859 Now in tranceiver!
860 /* This causes an interrupt */
861 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700862 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700864
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700866 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 -0700867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700869 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870}
871
872/*
873 * Function smsc_ircc_fir_start(self)
874 *
875 * Change the speed of the device
876 *
877 */
878static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
879{
880 struct net_device *dev;
881 int fir_base;
882
883 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
884
885 IRDA_ASSERT(self != NULL, return;);
886 dev = self->netdev;
887 IRDA_ASSERT(dev != NULL, return;);
888
889 fir_base = self->io.fir_base;
890
891 /* Reset everything */
892
893 /* Install FIR transmit handler */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700894 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700897 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700900 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 register_bank(fir_base, 1);
903
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700904 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700906 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
907 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700908#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700909 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
910 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700911#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700912 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
914 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700915 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700917 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
918 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919}
920
921/*
922 * Function smsc_ircc_fir_stop(self, baud)
923 *
924 * Change the speed of the device
925 *
926 */
927static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
928{
929 int fir_base;
930
931 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700932
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 IRDA_ASSERT(self != NULL, return;);
934
935 fir_base = self->io.fir_base;
936 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700937 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
938 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
941
942/*
943 * Function smsc_ircc_change_speed(self, baud)
944 *
945 * Change the speed of the device
946 *
947 * This function *must* be called with spinlock held, because it may
948 * be called from the irq handler. - Jean II
949 */
950static void smsc_ircc_change_speed(void *priv, u32 speed)
951{
952 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv;
953 struct net_device *dev;
954 int iobase;
955 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700956
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
958
959 IRDA_ASSERT(self != NULL, return;);
960 dev = self->netdev;
961 iobase = self->io.fir_base;
962
963 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
964
965 #if 0
966 /* Temp Hack */
967 speed= 1152000;
968 self->io.speed = speed;
969 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700970 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700972
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700973 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 smsc_ircc_sir_start(self);
975
976 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700977 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 #endif
979
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700980 if (self->io.speed != speed)
981 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700984
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700985 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
986 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 smsc_ircc_fir_stop(self);
988 smsc_ircc_sir_start(self);
989 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700990 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700991 } else {
992 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700993 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 smsc_ircc_sir_stop(self);
995 #endif
996 smsc_ircc_fir_start(self);
997 }
998 smsc_ircc_set_fir_speed(self, speed);
999
1000 #if 0
1001 self->tx_buff.len = 10;
1002 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 smsc_ircc_dma_xmit(self, iobase, 4000);
1005 #endif
1006 /* Be ready for incoming frames */
1007 smsc_ircc_dma_receive(self, iobase);
1008 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001009
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 netif_wake_queue(dev);
1011}
1012
1013/*
1014 * Function smsc_ircc_set_sir_speed (self, speed)
1015 *
1016 * Set speed of IrDA port to specified baudrate
1017 *
1018 */
1019void smsc_ircc_set_sir_speed(void *priv, __u32 speed)
1020{
1021 struct smsc_ircc_cb *self = (struct smsc_ircc_cb *) priv;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001022 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 int fcr; /* FIFO control reg */
1024 int lcr; /* Line control reg */
1025 int divisor;
1026
1027 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1028
1029 IRDA_ASSERT(self != NULL, return;);
1030 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001031
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 /* Update accounting for new speed */
1033 self->io.speed = speed;
1034
1035 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001036 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001038 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001039
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040 fcr = UART_FCR_ENABLE_FIFO;
1041
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001042 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001043 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1044 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001045 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001047 fcr |= self->io.speed < 38400 ?
1048 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001049
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 /* IrDA ports use 8N1 */
1051 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001052
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001053 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1054 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1055 outb(divisor >> 8, iobase + UART_DLM);
1056 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1057 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
1059 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001060 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1063}
1064
1065
1066/*
1067 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1068 *
1069 * Transmit the frame!
1070 *
1071 */
1072static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1073{
1074 struct smsc_ircc_cb *self;
1075 unsigned long flags;
1076 s32 speed;
1077 int iobase;
1078 int mtt;
1079
1080 IRDA_ASSERT(dev != NULL, return 0;);
1081 self = (struct smsc_ircc_cb *) dev->priv;
1082 IRDA_ASSERT(self != NULL, return 0;);
1083
1084 iobase = self->io.fir_base;
1085
1086 netif_stop_queue(dev);
1087
1088 /* Make sure test of self->io.speed & speed change are atomic */
1089 spin_lock_irqsave(&self->lock, flags);
1090
1091 /* Check if we need to change the speed after this frame */
1092 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001093 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 /* Check for empty frame */
1095 if (!skb->len) {
1096 /* Note : you should make sure that speed changes
1097 * are not going to corrupt any outgoing frame.
1098 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001099 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 spin_unlock_irqrestore(&self->lock, flags);
1101 dev_kfree_skb(skb);
1102 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001103 }
1104
1105 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001107
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 memcpy(self->tx_buff.head, skb->data, skb->len);
1109
1110 self->tx_buff.len = skb->len;
1111 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001112
1113 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (mtt) {
1115 int bofs;
1116
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001117 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 * Compute how many BOFs (STA or PA's) we need to waste the
1119 * min turn time given the speed of the link.
1120 */
1121 bofs = mtt * (self->io.speed / 1000) / 8000;
1122 if (bofs > 4095)
1123 bofs = 4095;
1124
1125 smsc_ircc_dma_xmit(self, iobase, bofs);
1126 } else {
1127 /* Transmit frame */
1128 smsc_ircc_dma_xmit(self, iobase, 0);
1129 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001130
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131 spin_unlock_irqrestore(&self->lock, flags);
1132 dev_kfree_skb(skb);
1133
1134 return 0;
1135}
1136
1137/*
1138 * Function smsc_ircc_dma_xmit (self, iobase)
1139 *
1140 * Transmit data using DMA
1141 *
1142 */
1143static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int iobase, int bofs)
1144{
1145 u8 ctrl;
1146
1147 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1148#if 1
1149 /* Disable Rx */
1150 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001151 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152#endif
1153 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001154 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1155 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 self->io.direction = IO_XMIT;
1158
1159 /* Set BOF additional count for generating the min turn time */
1160 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001161 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1162 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1163 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001166 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1167 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
1169 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001170
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 /* Enable burst mode chip Tx DMA */
1172 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001173 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1174 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 /* Setup DMA controller (must be done after enabling chip DMA) */
1177 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1178 DMA_TX_MODE);
1179
1180 /* Enable interrupt */
1181
1182 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001183 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1184 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001185
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001187 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188}
1189
1190/*
1191 * Function smsc_ircc_dma_xmit_complete (self)
1192 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001193 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 * by the interrupt handler
1195 *
1196 */
1197static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self, int iobase)
1198{
1199 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1200#if 0
1201 /* Disable Tx */
1202 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001203 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204#endif
1205 register_bank(self->io.fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001206 outb(inb(self->io.fir_base + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1207 self->io.fir_base + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
1209 /* Check for underrun! */
1210 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001211 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 self->stats.tx_errors++;
1213 self->stats.tx_fifo_errors++;
1214
1215 /* Reset error condition */
1216 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001217 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1218 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 } else {
1220 self->stats.tx_packets++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001221 self->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222 }
1223
1224 /* Check if it's time to change the speed */
1225 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001226 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227 self->new_speed = 0;
1228 }
1229
1230 netif_wake_queue(self->netdev);
1231}
1232
1233/*
1234 * Function smsc_ircc_dma_receive(self)
1235 *
1236 * Get ready for receiving a frame. The device will initiate a DMA
1237 * if it starts to receive a frame.
1238 *
1239 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001240static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self, int iobase)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241{
1242#if 0
1243 /* Turn off chip DMA */
1244 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001245 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1246 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 /* Disable Tx */
1250 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001251 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252
1253 /* Turn off chip DMA */
1254 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001255 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1256 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257
1258 self->io.direction = IO_RECV;
1259 self->rx_buff.data = self->rx_buff.head;
1260
1261 /* Set max Rx frame size */
1262 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001263 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1264 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265
1266 /* Setup DMA controller */
1267 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1268 DMA_RX_MODE);
1269
1270 /* Enable burst mode chip Rx DMA */
1271 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001272 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1273 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
1275 /* Enable interrupt */
1276 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001277 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1278 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 /* Enable receiver */
1281 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001282 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001283 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001284
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 return 0;
1286}
1287
1288/*
1289 * Function smsc_ircc_dma_receive_complete(self, iobase)
1290 *
1291 * Finished with receiving frames
1292 *
1293 */
1294static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self, int iobase)
1295{
1296 struct sk_buff *skb;
1297 int len, msgcnt, lsr;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001300
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1302#if 0
1303 /* Disable Rx */
1304 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001305 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306#endif
1307 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001308 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1309 lsr= inb(iobase + IRCC_LSR);
1310 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1313 get_dma_residue(self->io.dma));
1314
1315 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1316
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001317 /* Look for errors */
1318 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319 self->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001320 if (lsr & IRCC_LSR_FRAME_ERROR)
1321 self->stats.rx_frame_errors++;
1322 if (lsr & IRCC_LSR_CRC_ERROR)
1323 self->stats.rx_crc_errors++;
1324 if (lsr & IRCC_LSR_SIZE_ERROR)
1325 self->stats.rx_length_errors++;
1326 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1327 self->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 return;
1329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001331 /* Remove CRC */
1332 len -= self->io.speed < 4000000 ? 2 : 4;
1333
1334 if (len < 2 || len > 2050) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1336 return;
1337 }
1338 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1339
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001340 skb = dev_alloc_skb(len + 1);
1341 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1343 __FUNCTION__);
1344 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001347 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1350 self->stats.rx_packets++;
1351 self->stats.rx_bytes += len;
1352
1353 skb->dev = self->netdev;
1354 skb->mac.raw = skb->data;
1355 skb->protocol = htons(ETH_P_IRDA);
1356 netif_rx(skb);
1357}
1358
1359/*
1360 * Function smsc_ircc_sir_receive (self)
1361 *
1362 * Receive one frame from the infrared port
1363 *
1364 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001365static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 int boguscount = 0;
1368 int iobase;
1369
1370 IRDA_ASSERT(self != NULL, return;);
1371
1372 iobase = self->io.sir_base;
1373
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001374 /*
1375 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1376 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 */
1378 do {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001379 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001380 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381
1382 /* Make sure we don't stay here to long */
1383 if (boguscount++ > 32) {
1384 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1385 break;
1386 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001387 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388}
1389
1390
1391/*
1392 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1393 *
1394 * An interrupt from the chip has arrived. Time to do some work
1395 *
1396 */
1397static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1398{
1399 struct net_device *dev = (struct net_device *) dev_id;
1400 struct smsc_ircc_cb *self;
1401 int iobase, iir, lcra, lsr;
1402 irqreturn_t ret = IRQ_NONE;
1403
1404 if (dev == NULL) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001405 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 driver_name, irq);
1407 goto irq_ret;
1408 }
1409 self = (struct smsc_ircc_cb *) dev->priv;
1410 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1411
1412 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001413 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414
1415 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001416 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 ret = smsc_ircc_interrupt_sir(dev);
1418 goto irq_ret_unlock;
1419 }
1420
1421 iobase = self->io.fir_base;
1422
1423 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001424 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001425 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 goto irq_ret_unlock;
1427 ret = IRQ_HANDLED;
1428
1429 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001430 outb(0, iobase + IRCC_IER);
1431 lcra = inb(iobase + IRCC_LCR_A);
1432 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001433
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1435
1436 if (iir & IRCC_IIR_EOM) {
1437 if (self->io.direction == IO_RECV)
1438 smsc_ircc_dma_receive_complete(self, iobase);
1439 else
1440 smsc_ircc_dma_xmit_complete(self, iobase);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001441
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 smsc_ircc_dma_receive(self, iobase);
1443 }
1444
1445 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1446 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1447 }
1448
1449 /* Enable interrupts again */
1450
1451 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001452 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453
1454 irq_ret_unlock:
1455 spin_unlock(&self->lock);
1456 irq_ret:
1457 return ret;
1458}
1459
1460/*
1461 * Function irport_interrupt_sir (irq, dev_id, regs)
1462 *
1463 * Interrupt handler for SIR modes
1464 */
1465static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1466{
1467 struct smsc_ircc_cb *self = dev->priv;
1468 int boguscount = 0;
1469 int iobase;
1470 int iir, lsr;
1471
1472 /* Already locked comming here in smsc_ircc_interrupt() */
1473 /*spin_lock(&self->lock);*/
1474
1475 iobase = self->io.sir_base;
1476
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001477 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 if (iir == 0)
1479 return IRQ_NONE;
1480 while (iir) {
1481 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001482 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001484 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 __FUNCTION__, iir, lsr, iobase);
1486
1487 switch (iir) {
1488 case UART_IIR_RLSI:
1489 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1490 break;
1491 case UART_IIR_RDI:
1492 /* Receive interrupt */
1493 smsc_ircc_sir_receive(self);
1494 break;
1495 case UART_IIR_THRI:
1496 if (lsr & UART_LSR_THRE)
1497 /* Transmitter ready for data */
1498 smsc_ircc_sir_write_wakeup(self);
1499 break;
1500 default:
1501 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1502 __FUNCTION__, iir);
1503 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001504 }
1505
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506 /* Make sure we don't stay here to long */
1507 if (boguscount++ > 100)
1508 break;
1509
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001510 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 }
1512 /*spin_unlock(&self->lock);*/
1513 return IRQ_HANDLED;
1514}
1515
1516
1517#if 0 /* unused */
1518/*
1519 * Function ircc_is_receiving (self)
1520 *
1521 * Return TRUE is we are currently receiving a frame
1522 *
1523 */
1524static int ircc_is_receiving(struct smsc_ircc_cb *self)
1525{
1526 int status = FALSE;
1527 /* int iobase; */
1528
1529 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1530
1531 IRDA_ASSERT(self != NULL, return FALSE;);
1532
1533 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1534 get_dma_residue(self->io.dma));
1535
1536 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 return status;
1539}
1540#endif /* unused */
1541
1542
1543/*
1544 * Function smsc_ircc_net_open (dev)
1545 *
1546 * Start the device
1547 *
1548 */
1549static int smsc_ircc_net_open(struct net_device *dev)
1550{
1551 struct smsc_ircc_cb *self;
1552 int iobase;
1553 char hwname[16];
1554 unsigned long flags;
1555
1556 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001557
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 IRDA_ASSERT(dev != NULL, return -1;);
1559 self = (struct smsc_ircc_cb *) dev->priv;
1560 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001561
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 iobase = self->io.fir_base;
1563
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001564 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 (void *) dev)) {
1566 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1567 __FUNCTION__, self->io.irq);
1568 return -EAGAIN;
1569 }
1570
1571 spin_lock_irqsave(&self->lock, flags);
1572 /*smsc_ircc_sir_start(self);*/
1573 self->io.speed = 0;
1574 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1575 spin_unlock_irqrestore(&self->lock, flags);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001576
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 /* Give self a hardware name */
1578 /* It would be cool to offer the chip revision here - Jean II */
1579 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1580
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001581 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001583 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 */
1585 self->irlap = irlap_open(dev, &self->qos, hwname);
1586
1587 /*
1588 * Always allocate the DMA channel after the IRQ,
1589 * and clean up on failure.
1590 */
1591 if (request_dma(self->io.dma, dev->name)) {
1592 smsc_ircc_net_close(dev);
1593
1594 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1595 __FUNCTION__, self->io.dma);
1596 return -EAGAIN;
1597 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001598
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599 netif_start_queue(dev);
1600
1601 return 0;
1602}
1603
1604/*
1605 * Function smsc_ircc_net_close (dev)
1606 *
1607 * Stop the device
1608 *
1609 */
1610static int smsc_ircc_net_close(struct net_device *dev)
1611{
1612 struct smsc_ircc_cb *self;
1613 int iobase;
1614
1615 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001616
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001618 self = (struct smsc_ircc_cb *) dev->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621 iobase = self->io.fir_base;
1622
1623 /* Stop device */
1624 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 /* Stop and remove instance of IrLAP */
1627 if (self->irlap)
1628 irlap_close(self->irlap);
1629 self->irlap = NULL;
1630
1631 free_irq(self->io.irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 free_dma(self->io.dma);
1634
1635 return 0;
1636}
1637
1638
1639static void smsc_ircc_suspend(struct smsc_ircc_cb *self)
1640{
1641 IRDA_MESSAGE("%s, Suspending\n", driver_name);
1642
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001643 if (!self->io.suspended) {
1644 smsc_ircc_net_close(self->netdev);
1645 self->io.suspended = 1;
1646 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647}
1648
1649static void smsc_ircc_wakeup(struct smsc_ircc_cb *self)
1650{
1651 if (!self->io.suspended)
1652 return;
1653
1654 /* The code was doing a "cli()" here, but this can't be right.
1655 * If you need protection, do it in net_open with a spinlock
1656 * or give a good reason. - Jean II */
1657
1658 smsc_ircc_net_open(self->netdev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 IRDA_MESSAGE("%s, Waking up\n", driver_name);
1661}
1662
1663static int smsc_ircc_pmproc(struct pm_dev *dev, pm_request_t rqst, void *data)
1664{
1665 struct smsc_ircc_cb *self = (struct smsc_ircc_cb*) dev->data;
1666 if (self) {
1667 switch (rqst) {
1668 case PM_SUSPEND:
1669 smsc_ircc_suspend(self);
1670 break;
1671 case PM_RESUME:
1672 smsc_ircc_wakeup(self);
1673 break;
1674 }
1675 }
1676 return 0;
1677}
1678
1679/*
1680 * Function smsc_ircc_close (self)
1681 *
1682 * Close driver instance
1683 *
1684 */
1685static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1686{
1687 int iobase;
1688 unsigned long flags;
1689
1690 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1691
1692 IRDA_ASSERT(self != NULL, return -1;);
1693
1694 iobase = self->io.fir_base;
1695
1696 if (self->pmdev)
1697 pm_unregister(self->pmdev);
1698
1699 /* Remove netdevice */
1700 unregister_netdev(self->netdev);
1701
1702 /* Make sure the irq handler is not exectuting */
1703 spin_lock_irqsave(&self->lock, flags);
1704
1705 /* Stop interrupts */
1706 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001707 outb(0, iobase + IRCC_IER);
1708 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1709 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710#if 0
1711 /* Reset to SIR mode */
1712 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001713 outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
1714 outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715#endif
1716 spin_unlock_irqrestore(&self->lock, flags);
1717
1718 /* Release the PORTS that this driver is using */
1719 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1720 self->io.fir_base);
1721
1722 release_region(self->io.fir_base, self->io.fir_ext);
1723
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001724 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 self->io.sir_base);
1726
1727 release_region(self->io.sir_base, self->io.sir_ext);
1728
1729 if (self->tx_buff.head)
1730 dma_free_coherent(NULL, self->tx_buff.truesize,
1731 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 if (self->rx_buff.head)
1734 dma_free_coherent(NULL, self->rx_buff.truesize,
1735 self->rx_buff.head, self->rx_buff_dma);
1736
1737 free_netdev(self->netdev);
1738
1739 return 0;
1740}
1741
1742static void __exit smsc_ircc_cleanup(void)
1743{
1744 int i;
1745
1746 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1747
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001748 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749 if (dev_self[i])
1750 smsc_ircc_close(dev_self[i]);
1751 }
1752}
1753
1754/*
1755 * Start SIR operations
1756 *
1757 * This function *must* be called with spinlock held, because it may
1758 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1759 */
1760void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1761{
1762 struct net_device *dev;
1763 int fir_base, sir_base;
1764
1765 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1766
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001767 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001768 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001769 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1771
1772 fir_base = self->io.fir_base;
1773 sir_base = self->io.sir_base;
1774
1775 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001776 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
1778 #if SMSC_IRCC2_C_SIR_STOP
1779 /*smsc_ircc_sir_stop(self);*/
1780 #endif
1781
1782 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001783 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 -07001784
1785 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001786 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1787 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001790 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791
1792 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1793
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001794 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795}
1796
1797#if SMSC_IRCC2_C_SIR_STOP
1798void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1799{
1800 int iobase;
1801
1802 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1803 iobase = self->io.sir_base;
1804
1805 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001806 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001807
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001809 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810}
1811#endif
1812
1813/*
1814 * Function smsc_sir_write_wakeup (self)
1815 *
1816 * Called by the SIR interrupt handler when there's room for more data.
1817 * If we have more packets to send, we send them here.
1818 *
1819 */
1820static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1821{
1822 int actual = 0;
1823 int iobase;
1824 int fcr;
1825
1826 IRDA_ASSERT(self != NULL, return;);
1827
1828 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1829
1830 iobase = self->io.sir_base;
1831
1832 /* Finished with frame? */
1833 if (self->tx_buff.len > 0) {
1834 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001835 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 self->tx_buff.data, self->tx_buff.len);
1837 self->tx_buff.data += actual;
1838 self->tx_buff.len -= actual;
1839 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001840
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001842
1843 /*
1844 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 * transmission of another packet. But first we must check
1846 * if we need to change the speed of the hardware
1847 */
1848 if (self->new_speed) {
1849 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1850 __FUNCTION__, self->new_speed);
1851 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1852 smsc_ircc_change_speed(self, self->new_speed);
1853 self->new_speed = 0;
1854 } else {
1855 /* Tell network layer that we want more frames */
1856 netif_wake_queue(self->netdev);
1857 }
1858 self->stats.tx_packets++;
1859
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001860 if (self->io.speed <= 115200) {
1861 /*
1862 * Reset Rx FIFO to make sure that all reflected transmit data
1863 * is discarded. This is needed for half duplex operation
1864 */
1865 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1866 fcr |= self->io.speed < 38400 ?
1867 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001869 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001871 /* Turn on receive interrupts */
1872 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 }
1874 }
1875}
1876
1877/*
1878 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1879 *
1880 * Fill Tx FIFO with transmit data
1881 *
1882 */
1883static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1884{
1885 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001888 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1890 return 0;
1891 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001892
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001894 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001896 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 actual++;
1898 }
1899 return actual;
1900}
1901
1902/*
1903 * Function smsc_ircc_is_receiving (self)
1904 *
1905 * Returns true is we are currently receiving data
1906 *
1907 */
1908static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
1909{
1910 return (self->rx_buff.state != OUTSIDE_FRAME);
1911}
1912
1913
1914/*
1915 * Function smsc_ircc_probe_transceiver(self)
1916 *
1917 * Tries to find the used Transceiver
1918 *
1919 */
1920static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
1921{
1922 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001923
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001925
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001926 for (i = 0; smsc_transceivers[i].name != NULL; i++)
1927 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 IRDA_MESSAGE(" %s transceiver found\n",
1929 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001930 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 return;
1932 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001933
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
1935 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001936
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001937 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938}
1939
1940
1941/*
1942 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
1943 *
1944 * Set the transceiver according to the speed
1945 *
1946 */
1947static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
1948{
1949 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001950
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001952 if (trx > 0)
1953 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954}
1955
1956/*
1957 * Function smsc_ircc_wait_hw_transmitter_finish ()
1958 *
1959 * Wait for the real end of HW transmission
1960 *
1961 * The UART is a strict FIFO, and we get called only when we have finished
1962 * pushing data to the FIFO, so the maximum amount of time we must wait
1963 * is only for the FIFO to drain out.
1964 *
1965 * We use a simple calibrated loop. We may need to adjust the loop
1966 * delay (udelay) to balance I/O traffic and latency. And we also need to
1967 * adjust the maximum timeout.
1968 * It would probably be better to wait for the proper interrupt,
1969 * but it doesn't seem to be available.
1970 *
1971 * We can't use jiffies or kernel timers because :
1972 * 1) We are called from the interrupt handler, which disable softirqs,
1973 * so jiffies won't be increased
1974 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
1975 * want to wait that long to detect stuck hardware.
1976 * Jean II
1977 */
1978
1979static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
1980{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001981 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001985 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 udelay(1);
1987
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001988 if (count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
1990}
1991
1992
1993/* PROBING
1994 *
1995 *
1996 */
1997
1998static int __init smsc_ircc_look_for_chips(void)
1999{
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002000 struct smsc_chip_address *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002001 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002003
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 found = 0;
2005 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002006
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002007 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002011
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002012 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002014 if (address->type & SMSCSIO_TYPE_FLAT)
2015 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2016 found++;
2017
2018 if (address->type & SMSCSIO_TYPE_PAGED)
2019 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2020 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002022 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002024 if (address->type & SMSCSIO_TYPE_FLAT)
2025 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2026 found++;
2027
2028 if (address->type & SMSCSIO_TYPE_PAGED)
2029 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2030 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 }
2032 address++;
2033 }
2034 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002035}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036
2037/*
2038 * Function smsc_superio_flat (chip, base, type)
2039 *
2040 * Try to get configuration of a smc SuperIO chip with flat register model
2041 *
2042 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002043static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 unsigned short firbase, sirbase;
2046 u8 mode, dma, irq;
2047 int ret = -ENODEV;
2048
2049 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2050
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002051 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 return ret;
2053
2054 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002055 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002056
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002058
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002059 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2061
2062 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002063 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002065 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002067 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 /* DMA */
2070 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002071 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002072
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 /* IRQ */
2074 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002075 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2078
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002079 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2080 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002081
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 /* Exit configuration */
2083 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2084
2085 return ret;
2086}
2087
2088/*
2089 * Function smsc_superio_paged (chip, base, type)
2090 *
2091 * Try to get configuration of a smc SuperIO chip with paged register model
2092 *
2093 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002094static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095{
2096 unsigned short fir_io, sir_io;
2097 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2100
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002101 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 /* Select logical device (UART2) */
2105 outb(0x07, cfg_base);
2106 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 /* SIR iobase */
2109 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002110 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 outb(0x61, cfg_base);
2112 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 /* Read FIR base */
2115 outb(0x62, cfg_base);
2116 fir_io = inb(cfg_base + 1) << 8;
2117 outb(0x63, cfg_base);
2118 fir_io |= inb(cfg_base + 1);
2119 outb(0x2b, cfg_base); /* ??? */
2120
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002121 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2122 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 /* Exit configuration */
2125 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2126
2127 return ret;
2128}
2129
2130
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002131static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
2133 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2134
2135 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002136 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137}
2138
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002139static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002141 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142
2143 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2144
2145 /* Leave configuration */
2146
2147 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2148
2149 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2150 return NULL;
2151
2152 outb(reg, cfg_base);
2153
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002154 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
2156 /* Enter configuration */
2157
2158 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2159
2160 #if 0
2161 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2162 return NULL;
2163 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002164
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 /* probe device ID */
2166
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002167 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 return NULL;
2169
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002170 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002171
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002172 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 return NULL;
2174
2175 /* probe revision ID */
2176
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002177 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 return NULL;
2179
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002180 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002182 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 return NULL;
2184
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002185 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 return NULL;
2187
2188 /* Check for expected device ID; are there others? */
2189
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002190 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191
2192 chip++;
2193
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002194 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 return NULL;
2196 }
2197
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002198 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2199 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002201 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002202 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 return NULL;
2204 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002205
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002206 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 IRDA_MESSAGE("chipset does not support IRDA\n");
2208
2209 return chip;
2210}
2211
2212static int __init smsc_superio_fdc(unsigned short cfg_base)
2213{
2214 int ret = -1;
2215
2216 if (!request_region(cfg_base, 2, driver_name)) {
2217 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2218 __FUNCTION__, cfg_base);
2219 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002220 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2221 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 ret = 0;
2223
2224 release_region(cfg_base, 2);
2225 }
2226
2227 return ret;
2228}
2229
2230static int __init smsc_superio_lpc(unsigned short cfg_base)
2231{
2232 int ret = -1;
2233
2234 if (!request_region(cfg_base, 2, driver_name)) {
2235 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2236 __FUNCTION__, cfg_base);
2237 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002238 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2239 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 release_region(cfg_base, 2);
2243 }
2244 return ret;
2245}
2246
2247/************************************************
2248 *
2249 * Transceivers specific functions
2250 *
2251 ************************************************/
2252
2253
2254/*
2255 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2256 *
2257 * Program transceiver through smsc-ircc ATC circuitry
2258 *
2259 */
2260
2261static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2262{
2263 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002264 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002265
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002266 jiffies_now = jiffies;
2267 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002268
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 /* ATC */
2270 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002271 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2272 fir_base + IRCC_ATC);
2273
2274 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2275 !time_after(jiffies, jiffies_timeout))
2276 /* empty */;
2277
2278 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002280 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281}
2282
2283/*
2284 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2285 *
2286 * Probe transceiver smsc-ircc ATC circuitry
2287 *
2288 */
2289
2290static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2291{
2292 return 0;
2293}
2294
2295/*
2296 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2297 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002298 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 *
2300 */
2301
2302static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2303{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002304 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002305
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002306 switch (speed) {
2307 default:
2308 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002309 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002311 case 1152000 :
2312 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 fast_mode = IRCC_LCR_A_FAST;
2314 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 }
2316 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002317 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318}
2319
2320/*
2321 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2322 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002323 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 *
2325 */
2326
2327static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2328{
2329 return 0;
2330}
2331
2332/*
2333 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2334 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002335 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 *
2337 */
2338
2339static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2340{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002341 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002342
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002343 switch (speed) {
2344 default:
2345 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002346 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002348 case 1152000 :
2349 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2351 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 }
2354 /* This causes an interrupt */
2355 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002356 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357}
2358
2359/*
2360 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2361 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002362 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 *
2364 */
2365
2366static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2367{
2368 return 0;
2369}
2370
2371
2372module_init(smsc_ircc_init);
2373module_exit(smsc_ircc_cleanup);