blob: 2c9d3309314c97261fd01e9d167fa9d1a3a2df71 [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
Dmitry Torokhov98b77772005-09-06 15:19:19 -070076static int ircc_dma = 255;
77module_param(ircc_dma, int, 0);
78MODULE_PARM_DESC(ircc_dma, "DMA channel");
79
80static int ircc_irq = 255;
81module_param(ircc_irq, int, 0);
82MODULE_PARM_DESC(ircc_irq, "IRQ line");
83
84static int ircc_fir;
85module_param(ircc_fir, int, 0);
86MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
87
88static int ircc_sir;
89module_param(ircc_sir, int, 0);
90MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
91
92static int ircc_cfg;
93module_param(ircc_cfg, int, 0);
94MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
95
96static int ircc_transceiver;
97module_param(ircc_transceiver, int, 0);
98MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100/* Types */
101
102struct smsc_transceiver {
103 char *name;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700104 void (*set_for_speed)(int fir_base, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 int (*probe)(int fir_base);
106};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108struct smsc_chip {
109 char *name;
110 #if 0
111 u8 type;
112 #endif
113 u16 flags;
114 u8 devid;
115 u8 rev;
116};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118struct smsc_chip_address {
119 unsigned int cfg_base;
120 unsigned int type;
121};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/* Private data for each instance */
124struct smsc_ircc_cb {
125 struct net_device *netdev; /* Yes! we are some kind of netdevice */
126 struct net_device_stats stats;
127 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 chipio_t io; /* IrDA controller information */
130 iobuff_t tx_buff; /* Transmit buffer */
131 iobuff_t rx_buff; /* Receive buffer */
132 dma_addr_t tx_buff_dma;
133 dma_addr_t rx_buff_dma;
134
135 struct qos_info qos; /* QoS capabilities for this device */
136
137 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 __u32 new_speed;
140 __u32 flags; /* Interface flags */
141
142 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
143 int tx_len; /* Number of frames in tx_buff */
144
145 int transceiver;
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700146 struct platform_device *pldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147};
148
149/* Constants */
150
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700151#define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
152
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
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700158static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160/* Prototypes */
161
162static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
163static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
164static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
165static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
166static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
167static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700168static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
169static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
171static int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
172static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700173static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
174static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -0700175static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
176static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
178static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
179static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
180#if SMSC_IRCC2_C_SIR_STOP
181static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
182#endif
183static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
184static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
185static int smsc_ircc_net_open(struct net_device *dev);
186static int smsc_ircc_net_close(struct net_device *dev);
187static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
188#if SMSC_IRCC2_C_NET_TIMEOUT
189static void smsc_ircc_timeout(struct net_device *dev);
190#endif
191static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
193static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
194static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
195static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
196
197/* Probing */
198static int __init smsc_ircc_look_for_chips(void);
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700199static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
200static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
201static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202static int __init smsc_superio_fdc(unsigned short cfg_base);
203static int __init smsc_superio_lpc(unsigned short cfg_base);
204
205/* Transceivers specific functions */
206
207static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
208static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
209static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
210static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
211static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
212static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
213
214/* Power Management */
215
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700216static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level);
217static int smsc_ircc_resume(struct device *dev, u32 level);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700219static struct device_driver smsc_ircc_driver = {
220 .name = SMSC_IRCC2_DRIVER_NAME,
221 .bus = &platform_bus_type,
222 .suspend = smsc_ircc_suspend,
223 .resume = smsc_ircc_resume,
224};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226/* Transceivers for SMSC-ircc */
227
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700228static struct smsc_transceiver smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700230 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
231 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
232 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
233 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700235#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237/* SMC SuperIO chipsets definitions */
238
239#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
240#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
241#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
242#define SIR 0 /* SuperIO Chip has only slow IRDA */
243#define FIR 4 /* SuperIO Chip has fast IRDA */
244#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
245
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700246static struct smsc_chip __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 /* Base address 0x3f0 or 0x370 */
249 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
250 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
251 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
252 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
253 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
254 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
255 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
256 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
257 { NULL }
258};
259
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700260static struct smsc_chip __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 /* Base address 0x3f0 or 0x370 */
263 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
264 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
265 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
266 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
267 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
268 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
269 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
270 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
271 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
272 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
273 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
274 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
275 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
276 { NULL }
277};
278
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700279static struct smsc_chip __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 /* Base address 0x2E or 0x4E */
282 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
283 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
284 { NULL }
285};
286
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700287static struct smsc_chip __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 /* Base address 0x2E or 0x4E */
290 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
291 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
292 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
293 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
294 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
295 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
296 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
297 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
298 { NULL }
299};
300
301#define SMSCSIO_TYPE_FDC 1
302#define SMSCSIO_TYPE_LPC 2
303#define SMSCSIO_TYPE_FLAT 4
304#define SMSCSIO_TYPE_PAGED 8
305
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700306static struct smsc_chip_address __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700308 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
309 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
310 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
311 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
312 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
313 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314};
315
316/* Globals */
317
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700318static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
319static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321static inline void register_bank(int iobase, int bank)
322{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700323 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
324 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325}
326
327
328/*******************************************************************************
329 *
330 *
331 * SMSC-ircc stuff
332 *
333 *
334 *******************************************************************************/
335
336/*
337 * Function smsc_ircc_init ()
338 *
339 * Initialize chip. Just try to find out how many chips we are dealing with
340 * and where they are
341 */
342static int __init smsc_ircc_init(void)
343{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700344 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
347
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700348 ret = driver_register(&smsc_ircc_driver);
349 if (ret) {
350 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
351 return ret;
352 }
353
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700354 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700355
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700356 if (ircc_fir > 0 && ircc_sir > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
358 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
359
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700360 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
361 ret = -ENODEV;
362 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700364 /* try user provided configuration register base address */
365 if (ircc_cfg > 0) {
366 IRDA_MESSAGE(" Overriding configuration address "
367 "0x%04x\n", ircc_cfg);
368 if (!smsc_superio_fdc(ircc_cfg))
369 ret = 0;
370 if (!smsc_superio_lpc(ircc_cfg))
371 ret = 0;
372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700374 if (smsc_ircc_look_for_chips() > 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 ret = 0;
376 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700377
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700378 if (ret)
379 driver_unregister(&smsc_ircc_driver);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 return ret;
382}
383
384/*
385 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
386 *
387 * Try to open driver instance
388 *
389 */
390static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
391{
392 struct smsc_ircc_cb *self;
393 struct net_device *dev;
394 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700395
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
397
398 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700399 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700403 if (dev_count >= ARRAY_SIZE(dev_self)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
405 goto err_out1;
406 }
407
408 /*
409 * Allocate new instance of the driver
410 */
411 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
412 if (!dev) {
413 IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
414 goto err_out1;
415 }
416
417 SET_MODULE_OWNER(dev);
418
419 dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
420#if SMSC_IRCC2_C_NET_TIMEOUT
421 dev->tx_timeout = smsc_ircc_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700422 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423#endif
424 dev->open = smsc_ircc_net_open;
425 dev->stop = smsc_ircc_net_close;
426 dev->do_ioctl = smsc_ircc_net_ioctl;
427 dev->get_stats = smsc_ircc_net_get_stats;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700428
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700429 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 self->netdev = dev;
431
432 /* Make ifconfig display some details */
433 dev->base_addr = self->io.fir_base = fir_base;
434 dev->irq = self->io.irq = irq;
435
436 /* Need to store self somewhere */
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700437 dev_self[dev_count] = self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 spin_lock_init(&self->lock);
439
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700440 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
442
443 self->rx_buff.head =
444 dma_alloc_coherent(NULL, self->rx_buff.truesize,
445 &self->rx_buff_dma, GFP_KERNEL);
446 if (self->rx_buff.head == NULL) {
447 IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
448 driver_name);
449 goto err_out2;
450 }
451
452 self->tx_buff.head =
453 dma_alloc_coherent(NULL, self->tx_buff.truesize,
454 &self->tx_buff_dma, GFP_KERNEL);
455 if (self->tx_buff.head == NULL) {
456 IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
457 driver_name);
458 goto err_out3;
459 }
460
461 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
462 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
463
464 self->rx_buff.in_frame = FALSE;
465 self->rx_buff.state = OUTSIDE_FRAME;
466 self->tx_buff.data = self->tx_buff.head;
467 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700472
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700473 if (ircc_transceiver > 0 &&
474 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 self->transceiver = ircc_transceiver;
476 else
477 smsc_ircc_probe_transceiver(self);
478
479 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700480 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 IRDA_ERROR("%s, Network device registration failed!\n",
482 driver_name);
483 goto err_out4;
484 }
485
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700486 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
487 dev_count, NULL, 0);
488 if (IS_ERR(self->pldev)) {
489 err = PTR_ERR(self->pldev);
490 goto err_out5;
491 }
492 dev_set_drvdata(&self->pldev->dev, self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700495 dev_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
497 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700498
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700499 err_out5:
500 unregister_netdev(self->netdev);
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 err_out4:
503 dma_free_coherent(NULL, self->tx_buff.truesize,
504 self->tx_buff.head, self->tx_buff_dma);
505 err_out3:
506 dma_free_coherent(NULL, self->rx_buff.truesize,
507 self->rx_buff.head, self->rx_buff_dma);
508 err_out2:
509 free_netdev(self->netdev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700510 dev_self[dev_count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 err_out1:
512 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
513 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
514 err_out:
515 return err;
516}
517
518/*
519 * Function smsc_ircc_present(fir_base, sir_base)
520 *
521 * Check the smsc-ircc chip presence
522 *
523 */
524static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
525{
526 unsigned char low, high, chip, config, dma, irq, version;
527
528 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
529 driver_name)) {
530 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
531 __FUNCTION__, fir_base);
532 goto out1;
533 }
534
535 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
536 driver_name)) {
537 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
538 __FUNCTION__, sir_base);
539 goto out2;
540 }
541
542 register_bank(fir_base, 3);
543
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700544 high = inb(fir_base + IRCC_ID_HIGH);
545 low = inb(fir_base + IRCC_ID_LOW);
546 chip = inb(fir_base + IRCC_CHIP_ID);
547 version = inb(fir_base + IRCC_VERSION);
548 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 dma = config & IRCC_INTERFACE_DMA_MASK;
550 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
551
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700552 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700553 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 __FUNCTION__, fir_base);
555 goto out3;
556 }
557 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
558 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
559 chip & 0x0f, version, fir_base, sir_base, dma, irq);
560
561 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 out3:
564 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
565 out2:
566 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
567 out1:
568 return -ENODEV;
569}
570
571/*
572 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
573 *
574 * Setup I/O
575 *
576 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700577static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
578 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 u8 dma, u8 irq)
580{
581 unsigned char config, chip_dma, chip_irq;
582
583 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700584 config = inb(fir_base + IRCC_INTERFACE);
585 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
586 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 self->io.fir_base = fir_base;
589 self->io.sir_base = sir_base;
590 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
591 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
592 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
593 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
594
595 if (irq < 255) {
596 if (irq != chip_irq)
597 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
598 driver_name, chip_irq, irq);
599 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700600 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700602
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 if (dma < 255) {
604 if (dma != chip_dma)
605 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
606 driver_name, chip_dma, dma);
607 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700608 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 self->io.dma = chip_dma;
610
611}
612
613/*
614 * Function smsc_ircc_setup_qos(self)
615 *
616 * Setup qos
617 *
618 */
619static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
620{
621 /* Initialize QoS for this device */
622 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
625 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
626
627 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
628 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
629 irda_qos_bits_to_value(&self->qos);
630}
631
632/*
633 * Function smsc_ircc_init_chip(self)
634 *
635 * Init chip
636 *
637 */
638static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
639{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700640 int iobase, ir_mode, ctrl, fast;
641
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700642 IRDA_ASSERT(self != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700644 iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 ir_mode = IRCC_CFGA_IRDA_SIR_A;
646 ctrl = 0;
647 fast = 0;
648
649 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700650 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
651 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
653 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700654 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode),
655 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
657#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700658 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
659 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700660#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700661 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
662 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700663#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700664 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
665 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700668 outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700669
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700671 outb(fast, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700676 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
679/*
680 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
681 *
682 * Process IOCTL commands for this device
683 *
684 */
685static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
686{
687 struct if_irda_req *irq = (struct if_irda_req *) rq;
688 struct smsc_ircc_cb *self;
689 unsigned long flags;
690 int ret = 0;
691
692 IRDA_ASSERT(dev != NULL, return -1;);
693
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700694 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
696 IRDA_ASSERT(self != NULL, return -1;);
697
698 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700699
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 switch (cmd) {
701 case SIOCSBANDWIDTH: /* Set bandwidth */
702 if (!capable(CAP_NET_ADMIN))
703 ret = -EPERM;
704 else {
705 /* Make sure we are the only one touching
706 * self->io.speed and the hardware - Jean II */
707 spin_lock_irqsave(&self->lock, flags);
708 smsc_ircc_change_speed(self, irq->ifr_baudrate);
709 spin_unlock_irqrestore(&self->lock, flags);
710 }
711 break;
712 case SIOCSMEDIABUSY: /* Set media busy */
713 if (!capable(CAP_NET_ADMIN)) {
714 ret = -EPERM;
715 break;
716 }
717
718 irda_device_set_media_busy(self->netdev, TRUE);
719 break;
720 case SIOCGRECEIVING: /* Check if we are receiving right now */
721 irq->ifr_receiving = smsc_ircc_is_receiving(self);
722 break;
723 #if 0
724 case SIOCSDTRRTS:
725 if (!capable(CAP_NET_ADMIN)) {
726 ret = -EPERM;
727 break;
728 }
729 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
730 break;
731 #endif
732 default:
733 ret = -EOPNOTSUPP;
734 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 return ret;
737}
738
739static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
740{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700741 struct smsc_ircc_cb *self = netdev_priv(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 return &self->stats;
744}
745
746#if SMSC_IRCC2_C_NET_TIMEOUT
747/*
748 * Function smsc_ircc_timeout (struct net_device *dev)
749 *
750 * The networking timeout management.
751 *
752 */
753
754static void smsc_ircc_timeout(struct net_device *dev)
755{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700756 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 unsigned long flags;
758
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
760 dev->name, self->io.speed);
761 spin_lock_irqsave(&self->lock, flags);
762 smsc_ircc_sir_start(self);
763 smsc_ircc_change_speed(self, self->io.speed);
764 dev->trans_start = jiffies;
765 netif_wake_queue(dev);
766 spin_unlock_irqrestore(&self->lock, flags);
767}
768#endif
769
770/*
771 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
772 *
773 * Transmits the current frame until FIFO is full, then
774 * waits until the next transmit interrupt, and continues until the
775 * frame is transmitted.
776 */
777int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
778{
779 struct smsc_ircc_cb *self;
780 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781 s32 speed;
782
783 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
784
785 IRDA_ASSERT(dev != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700786
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700787 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 IRDA_ASSERT(self != NULL, return 0;);
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700791
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 /* Make sure test of self->io.speed & speed change are atomic */
793 spin_lock_irqsave(&self->lock, flags);
794
795 /* Check if we need to change the speed */
796 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700797 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 /* Check for empty frame */
799 if (!skb->len) {
800 /*
801 * We send frames one by one in SIR mode (no
802 * pipelining), so at this point, if we were sending
803 * a previous frame, we just received the interrupt
804 * telling us it is finished (UART_IIR_THRI).
805 * Therefore, waiting for the transmitter to really
806 * finish draining the fifo won't take too long.
807 * And the interrupt handler is not expected to run.
808 * - Jean II */
809 smsc_ircc_sir_wait_hw_transmitter_finish(self);
810 smsc_ircc_change_speed(self, speed);
811 spin_unlock_irqrestore(&self->lock, flags);
812 dev_kfree_skb(skb);
813 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700815 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817
818 /* Init tx buffer */
819 self->tx_buff.data = self->tx_buff.head;
820
821 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700822 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825 self->stats.tx_bytes += self->tx_buff.len;
826
827 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700828 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 spin_unlock_irqrestore(&self->lock, flags);
831
832 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 return 0;
835}
836
837/*
838 * Function smsc_ircc_set_fir_speed (self, baud)
839 *
840 * Change the speed of the device
841 *
842 */
843static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
844{
845 int fir_base, ir_mode, ctrl, fast;
846
847 IRDA_ASSERT(self != NULL, return;);
848 fir_base = self->io.fir_base;
849
850 self->io.speed = speed;
851
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700852 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700854 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 ir_mode = IRCC_CFGA_IRDA_HDLC;
856 ctrl = IRCC_CRC;
857 fast = 0;
858 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
859 break;
860 case 1152000:
861 ir_mode = IRCC_CFGA_IRDA_HDLC;
862 ctrl = IRCC_1152 | IRCC_CRC;
863 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
864 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
865 __FUNCTION__);
866 break;
867 case 4000000:
868 ir_mode = IRCC_CFGA_IRDA_4PPM;
869 ctrl = IRCC_CRC;
870 fast = IRCC_LCR_A_FAST;
871 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
872 __FUNCTION__);
873 break;
874 }
875 #if 0
876 Now in tranceiver!
877 /* This causes an interrupt */
878 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700879 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700881
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700883 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 -0700884
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700886 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887}
888
889/*
890 * Function smsc_ircc_fir_start(self)
891 *
892 * Change the speed of the device
893 *
894 */
895static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
896{
897 struct net_device *dev;
898 int fir_base;
899
900 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
901
902 IRDA_ASSERT(self != NULL, return;);
903 dev = self->netdev;
904 IRDA_ASSERT(dev != NULL, return;);
905
906 fir_base = self->io.fir_base;
907
908 /* Reset everything */
909
910 /* Install FIR transmit handler */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700911 dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700914 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700917 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 register_bank(fir_base, 1);
920
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700921 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700923 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
924 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700925#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700926 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
927 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700928#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700929 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700932 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700934 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
935 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938/*
939 * Function smsc_ircc_fir_stop(self, baud)
940 *
941 * Change the speed of the device
942 *
943 */
944static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
945{
946 int fir_base;
947
948 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 IRDA_ASSERT(self != NULL, return;);
951
952 fir_base = self->io.fir_base;
953 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700954 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
955 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956}
957
958
959/*
960 * Function smsc_ircc_change_speed(self, baud)
961 *
962 * Change the speed of the device
963 *
964 * This function *must* be called with spinlock held, because it may
965 * be called from the irq handler. - Jean II
966 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -0700967static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700971
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);
973
974 IRDA_ASSERT(self != NULL, return;);
975 dev = self->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976
977 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
978
979 #if 0
980 /* Temp Hack */
981 speed= 1152000;
982 self->io.speed = speed;
983 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700984 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700986
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700987 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 smsc_ircc_sir_start(self);
989
990 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700991 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 #endif
993
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700994 if (self->io.speed != speed)
995 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
997 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700998
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700999 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1000 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 smsc_ircc_fir_stop(self);
1002 smsc_ircc_sir_start(self);
1003 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001004 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001005 } else {
1006 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001007 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 smsc_ircc_sir_stop(self);
1009 #endif
1010 smsc_ircc_fir_start(self);
1011 }
1012 smsc_ircc_set_fir_speed(self, speed);
1013
1014 #if 0
1015 self->tx_buff.len = 10;
1016 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001017
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001018 smsc_ircc_dma_xmit(self, 4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 #endif
1020 /* Be ready for incoming frames */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001021 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001023
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 netif_wake_queue(dev);
1025}
1026
1027/*
1028 * Function smsc_ircc_set_sir_speed (self, speed)
1029 *
1030 * Set speed of IrDA port to specified baudrate
1031 *
1032 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -07001033void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001035 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 int fcr; /* FIFO control reg */
1037 int lcr; /* Line control reg */
1038 int divisor;
1039
1040 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);
1041
1042 IRDA_ASSERT(self != NULL, return;);
1043 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001044
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 /* Update accounting for new speed */
1046 self->io.speed = speed;
1047
1048 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001049 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001051 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001052
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053 fcr = UART_FCR_ENABLE_FIFO;
1054
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001055 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1057 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001058 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001060 fcr |= self->io.speed < 38400 ?
1061 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001062
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 /* IrDA ports use 8N1 */
1064 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001065
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001066 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1067 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1068 outb(divisor >> 8, iobase + UART_DLM);
1069 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1070 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001073 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
1076}
1077
1078
1079/*
1080 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1081 *
1082 * Transmit the frame!
1083 *
1084 */
1085static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
1086{
1087 struct smsc_ircc_cb *self;
1088 unsigned long flags;
1089 s32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090 int mtt;
1091
1092 IRDA_ASSERT(dev != NULL, return 0;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001093 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001094 IRDA_ASSERT(self != NULL, return 0;);
1095
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 netif_stop_queue(dev);
1097
1098 /* Make sure test of self->io.speed & speed change are atomic */
1099 spin_lock_irqsave(&self->lock, flags);
1100
1101 /* Check if we need to change the speed after this frame */
1102 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001103 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 /* Check for empty frame */
1105 if (!skb->len) {
1106 /* Note : you should make sure that speed changes
1107 * are not going to corrupt any outgoing frame.
1108 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001109 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 spin_unlock_irqrestore(&self->lock, flags);
1111 dev_kfree_skb(skb);
1112 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001113 }
1114
1115 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 memcpy(self->tx_buff.head, skb->data, skb->len);
1119
1120 self->tx_buff.len = skb->len;
1121 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001122
1123 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124 if (mtt) {
1125 int bofs;
1126
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001127 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 * Compute how many BOFs (STA or PA's) we need to waste the
1129 * min turn time given the speed of the link.
1130 */
1131 bofs = mtt * (self->io.speed / 1000) / 8000;
1132 if (bofs > 4095)
1133 bofs = 4095;
1134
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001135 smsc_ircc_dma_xmit(self, bofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136 } else {
1137 /* Transmit frame */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001138 smsc_ircc_dma_xmit(self, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 spin_unlock_irqrestore(&self->lock, flags);
1142 dev_kfree_skb(skb);
1143
1144 return 0;
1145}
1146
1147/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001148 * Function smsc_ircc_dma_xmit (self, bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 *
1150 * Transmit data using DMA
1151 *
1152 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001153static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001155 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156 u8 ctrl;
1157
1158 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1159#if 1
1160 /* Disable Rx */
1161 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001162 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163#endif
1164 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001165 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1166 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 self->io.direction = IO_XMIT;
1169
1170 /* Set BOF additional count for generating the min turn time */
1171 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001172 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1173 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1174 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
1176 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001177 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1178 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179
1180 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001181
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 /* Enable burst mode chip Tx DMA */
1183 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001184 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1185 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187 /* Setup DMA controller (must be done after enabling chip DMA) */
1188 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1189 DMA_TX_MODE);
1190
1191 /* Enable interrupt */
1192
1193 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001194 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1195 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001196
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001198 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199}
1200
1201/*
1202 * Function smsc_ircc_dma_xmit_complete (self)
1203 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001204 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 * by the interrupt handler
1206 *
1207 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001208static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001210 int iobase = self->io.fir_base;
1211
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1213#if 0
1214 /* Disable Tx */
1215 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001216 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217#endif
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001218 register_bank(iobase, 1);
1219 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1220 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 /* Check for underrun! */
1223 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001224 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 self->stats.tx_errors++;
1226 self->stats.tx_fifo_errors++;
1227
1228 /* Reset error condition */
1229 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001230 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1231 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 } else {
1233 self->stats.tx_packets++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001234 self->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 }
1236
1237 /* Check if it's time to change the speed */
1238 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001239 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 self->new_speed = 0;
1241 }
1242
1243 netif_wake_queue(self->netdev);
1244}
1245
1246/*
1247 * Function smsc_ircc_dma_receive(self)
1248 *
1249 * Get ready for receiving a frame. The device will initiate a DMA
1250 * if it starts to receive a frame.
1251 *
1252 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001253static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001255 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256#if 0
1257 /* Turn off chip DMA */
1258 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001259 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1260 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 /* Disable Tx */
1264 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001265 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 /* Turn off chip DMA */
1268 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001269 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1270 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 self->io.direction = IO_RECV;
1273 self->rx_buff.data = self->rx_buff.head;
1274
1275 /* Set max Rx frame size */
1276 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001277 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1278 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 /* Setup DMA controller */
1281 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1282 DMA_RX_MODE);
1283
1284 /* Enable burst mode chip Rx DMA */
1285 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001286 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1287 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001288
1289 /* Enable interrupt */
1290 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001291 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1292 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 /* Enable receiver */
1295 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001296 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001297 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001298
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 return 0;
1300}
1301
1302/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001303 * Function smsc_ircc_dma_receive_complete(self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 *
1305 * Finished with receiving frames
1306 *
1307 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001308static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
1310 struct sk_buff *skb;
1311 int len, msgcnt, lsr;
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001312 int iobase = self->io.fir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001315
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1317#if 0
1318 /* Disable Rx */
1319 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001320 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321#endif
1322 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001323 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1324 lsr= inb(iobase + IRCC_LSR);
1325 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
1327 IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
1328 get_dma_residue(self->io.dma));
1329
1330 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1331
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001332 /* Look for errors */
1333 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 self->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001335 if (lsr & IRCC_LSR_FRAME_ERROR)
1336 self->stats.rx_frame_errors++;
1337 if (lsr & IRCC_LSR_CRC_ERROR)
1338 self->stats.rx_crc_errors++;
1339 if (lsr & IRCC_LSR_SIZE_ERROR)
1340 self->stats.rx_length_errors++;
1341 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
1342 self->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 return;
1344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001346 /* Remove CRC */
1347 len -= self->io.speed < 4000000 ? 2 : 4;
1348
1349 if (len < 2 || len > 2050) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
1351 return;
1352 }
1353 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);
1354
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001355 skb = dev_alloc_skb(len + 1);
1356 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
1358 __FUNCTION__);
1359 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001360 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001362 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364 memcpy(skb_put(skb, len), self->rx_buff.data, len);
1365 self->stats.rx_packets++;
1366 self->stats.rx_bytes += len;
1367
1368 skb->dev = self->netdev;
1369 skb->mac.raw = skb->data;
1370 skb->protocol = htons(ETH_P_IRDA);
1371 netif_rx(skb);
1372}
1373
1374/*
1375 * Function smsc_ircc_sir_receive (self)
1376 *
1377 * Receive one frame from the infrared port
1378 *
1379 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001380static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381{
1382 int boguscount = 0;
1383 int iobase;
1384
1385 IRDA_ASSERT(self != NULL, return;);
1386
1387 iobase = self->io.sir_base;
1388
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001389 /*
1390 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1391 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 */
1393 do {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001394 async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001395 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396
1397 /* Make sure we don't stay here to long */
1398 if (boguscount++ > 32) {
1399 IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
1400 break;
1401 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001402 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403}
1404
1405
1406/*
1407 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1408 *
1409 * An interrupt from the chip has arrived. Time to do some work
1410 *
1411 */
1412static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1413{
1414 struct net_device *dev = (struct net_device *) dev_id;
1415 struct smsc_ircc_cb *self;
1416 int iobase, iir, lcra, lsr;
1417 irqreturn_t ret = IRQ_NONE;
1418
1419 if (dev == NULL) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001420 printk(KERN_WARNING "%s: irq %d for unknown device.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 driver_name, irq);
1422 goto irq_ret;
1423 }
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001424
1425 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 IRDA_ASSERT(self != NULL, return IRQ_NONE;);
1427
1428 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001429 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
1431 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001432 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 ret = smsc_ircc_interrupt_sir(dev);
1434 goto irq_ret_unlock;
1435 }
1436
1437 iobase = self->io.fir_base;
1438
1439 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001440 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001441 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 goto irq_ret_unlock;
1443 ret = IRQ_HANDLED;
1444
1445 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001446 outb(0, iobase + IRCC_IER);
1447 lcra = inb(iobase + IRCC_LCR_A);
1448 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);
1451
1452 if (iir & IRCC_IIR_EOM) {
1453 if (self->io.direction == IO_RECV)
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001454 smsc_ircc_dma_receive_complete(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 else
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001456 smsc_ircc_dma_xmit_complete(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001457
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001458 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 }
1460
1461 if (iir & IRCC_IIR_ACTIVE_FRAME) {
1462 /*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
1463 }
1464
1465 /* Enable interrupts again */
1466
1467 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001468 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469
1470 irq_ret_unlock:
1471 spin_unlock(&self->lock);
1472 irq_ret:
1473 return ret;
1474}
1475
1476/*
1477 * Function irport_interrupt_sir (irq, dev_id, regs)
1478 *
1479 * Interrupt handler for SIR modes
1480 */
1481static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1482{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001483 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 int boguscount = 0;
1485 int iobase;
1486 int iir, lsr;
1487
1488 /* Already locked comming here in smsc_ircc_interrupt() */
1489 /*spin_lock(&self->lock);*/
1490
1491 iobase = self->io.sir_base;
1492
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001493 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 if (iir == 0)
1495 return IRQ_NONE;
1496 while (iir) {
1497 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001498 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001500 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 __FUNCTION__, iir, lsr, iobase);
1502
1503 switch (iir) {
1504 case UART_IIR_RLSI:
1505 IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
1506 break;
1507 case UART_IIR_RDI:
1508 /* Receive interrupt */
1509 smsc_ircc_sir_receive(self);
1510 break;
1511 case UART_IIR_THRI:
1512 if (lsr & UART_LSR_THRE)
1513 /* Transmitter ready for data */
1514 smsc_ircc_sir_write_wakeup(self);
1515 break;
1516 default:
1517 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
1518 __FUNCTION__, iir);
1519 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001520 }
1521
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 /* Make sure we don't stay here to long */
1523 if (boguscount++ > 100)
1524 break;
1525
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001526 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 }
1528 /*spin_unlock(&self->lock);*/
1529 return IRQ_HANDLED;
1530}
1531
1532
1533#if 0 /* unused */
1534/*
1535 * Function ircc_is_receiving (self)
1536 *
1537 * Return TRUE is we are currently receiving a frame
1538 *
1539 */
1540static int ircc_is_receiving(struct smsc_ircc_cb *self)
1541{
1542 int status = FALSE;
1543 /* int iobase; */
1544
1545 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1546
1547 IRDA_ASSERT(self != NULL, return FALSE;);
1548
1549 IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
1550 get_dma_residue(self->io.dma));
1551
1552 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001553
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 return status;
1555}
1556#endif /* unused */
1557
1558
1559/*
1560 * Function smsc_ircc_net_open (dev)
1561 *
1562 * Start the device
1563 *
1564 */
1565static int smsc_ircc_net_open(struct net_device *dev)
1566{
1567 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 char hwname[16];
1569 unsigned long flags;
1570
1571 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001572
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001574 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001576
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001577 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 (void *) dev)) {
1579 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
1580 __FUNCTION__, self->io.irq);
1581 return -EAGAIN;
1582 }
1583
1584 spin_lock_irqsave(&self->lock, flags);
1585 /*smsc_ircc_sir_start(self);*/
1586 self->io.speed = 0;
1587 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1588 spin_unlock_irqrestore(&self->lock, flags);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001589
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 /* Give self a hardware name */
1591 /* It would be cool to offer the chip revision here - Jean II */
1592 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1593
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001594 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001596 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 */
1598 self->irlap = irlap_open(dev, &self->qos, hwname);
1599
1600 /*
1601 * Always allocate the DMA channel after the IRQ,
1602 * and clean up on failure.
1603 */
1604 if (request_dma(self->io.dma, dev->name)) {
1605 smsc_ircc_net_close(dev);
1606
1607 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
1608 __FUNCTION__, self->io.dma);
1609 return -EAGAIN;
1610 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001611
Linus Torvalds1da177e2005-04-16 15:20:36 -07001612 netif_start_queue(dev);
1613
1614 return 0;
1615}
1616
1617/*
1618 * Function smsc_ircc_net_close (dev)
1619 *
1620 * Stop the device
1621 *
1622 */
1623static int smsc_ircc_net_close(struct net_device *dev)
1624{
1625 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
1627 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001630 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001632
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 /* Stop device */
1634 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001635
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 /* Stop and remove instance of IrLAP */
1637 if (self->irlap)
1638 irlap_close(self->irlap);
1639 self->irlap = NULL;
1640
1641 free_irq(self->io.irq, dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643 free_dma(self->io.dma);
1644
1645 return 0;
1646}
1647
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001648static int smsc_ircc_suspend(struct device *dev, pm_message_t state, u32 level)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001650 struct smsc_ircc_cb *self = dev_get_drvdata(dev);
1651
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 IRDA_MESSAGE("%s, Suspending\n", driver_name);
1653
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001654 if (level == SUSPEND_DISABLE && !self->io.suspended) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001655 smsc_ircc_net_close(self->netdev);
1656 self->io.suspended = 1;
1657 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001658
1659 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001662static int smsc_ircc_resume(struct device *dev, u32 level)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001664 struct smsc_ircc_cb *self = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001666 if (level == RESUME_ENABLE && self->io.suspended) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001668 smsc_ircc_net_open(self->netdev);
1669 self->io.suspended = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001670
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001671 IRDA_MESSAGE("%s, Waking up\n", driver_name);
1672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 return 0;
1674}
1675
1676/*
1677 * Function smsc_ircc_close (self)
1678 *
1679 * Close driver instance
1680 *
1681 */
1682static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1683{
1684 int iobase;
1685 unsigned long flags;
1686
1687 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1688
1689 IRDA_ASSERT(self != NULL, return -1;);
1690
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001691 platform_device_unregister(self->pldev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692
1693 /* Remove netdevice */
1694 unregister_netdev(self->netdev);
1695
1696 /* Make sure the irq handler is not exectuting */
1697 spin_lock_irqsave(&self->lock, flags);
1698
1699 /* Stop interrupts */
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001700 iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001702 outb(0, iobase + IRCC_IER);
1703 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1704 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705#if 0
1706 /* Reset to SIR mode */
1707 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001708 outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
1709 outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710#endif
1711 spin_unlock_irqrestore(&self->lock, flags);
1712
1713 /* Release the PORTS that this driver is using */
1714 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
1715 self->io.fir_base);
1716
1717 release_region(self->io.fir_base, self->io.fir_ext);
1718
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001719 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 self->io.sir_base);
1721
1722 release_region(self->io.sir_base, self->io.sir_ext);
1723
1724 if (self->tx_buff.head)
1725 dma_free_coherent(NULL, self->tx_buff.truesize,
1726 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001727
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 if (self->rx_buff.head)
1729 dma_free_coherent(NULL, self->rx_buff.truesize,
1730 self->rx_buff.head, self->rx_buff_dma);
1731
1732 free_netdev(self->netdev);
1733
1734 return 0;
1735}
1736
1737static void __exit smsc_ircc_cleanup(void)
1738{
1739 int i;
1740
1741 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1742
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001743 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 if (dev_self[i])
1745 smsc_ircc_close(dev_self[i]);
1746 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001747
1748 driver_unregister(&smsc_ircc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001749}
1750
1751/*
1752 * Start SIR operations
1753 *
1754 * This function *must* be called with spinlock held, because it may
1755 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1756 */
1757void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
1758{
1759 struct net_device *dev;
1760 int fir_base, sir_base;
1761
1762 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1763
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001764 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001765 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001766 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;
1768
1769 fir_base = self->io.fir_base;
1770 sir_base = self->io.sir_base;
1771
1772 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001773 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 #if SMSC_IRCC2_C_SIR_STOP
1776 /*smsc_ircc_sir_stop(self);*/
1777 #endif
1778
1779 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001780 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 -07001781
1782 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001783 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1784 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001785
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001787 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);
1790
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001791 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792}
1793
1794#if SMSC_IRCC2_C_SIR_STOP
1795void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1796{
1797 int iobase;
1798
1799 IRDA_DEBUG(3, "%s\n", __FUNCTION__);
1800 iobase = self->io.sir_base;
1801
1802 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001803 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001804
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001806 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807}
1808#endif
1809
1810/*
1811 * Function smsc_sir_write_wakeup (self)
1812 *
1813 * Called by the SIR interrupt handler when there's room for more data.
1814 * If we have more packets to send, we send them here.
1815 *
1816 */
1817static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1818{
1819 int actual = 0;
1820 int iobase;
1821 int fcr;
1822
1823 IRDA_ASSERT(self != NULL, return;);
1824
1825 IRDA_DEBUG(4, "%s\n", __FUNCTION__);
1826
1827 iobase = self->io.sir_base;
1828
1829 /* Finished with frame? */
1830 if (self->tx_buff.len > 0) {
1831 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001832 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 self->tx_buff.data, self->tx_buff.len);
1834 self->tx_buff.data += actual;
1835 self->tx_buff.len -= actual;
1836 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001839
1840 /*
1841 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842 * transmission of another packet. But first we must check
1843 * if we need to change the speed of the hardware
1844 */
1845 if (self->new_speed) {
1846 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
1847 __FUNCTION__, self->new_speed);
1848 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1849 smsc_ircc_change_speed(self, self->new_speed);
1850 self->new_speed = 0;
1851 } else {
1852 /* Tell network layer that we want more frames */
1853 netif_wake_queue(self->netdev);
1854 }
1855 self->stats.tx_packets++;
1856
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001857 if (self->io.speed <= 115200) {
1858 /*
1859 * Reset Rx FIFO to make sure that all reflected transmit data
1860 * is discarded. This is needed for half duplex operation
1861 */
1862 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1863 fcr |= self->io.speed < 38400 ?
1864 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001866 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001868 /* Turn on receive interrupts */
1869 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 }
1871 }
1872}
1873
1874/*
1875 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
1876 *
1877 * Fill Tx FIFO with transmit data
1878 *
1879 */
1880static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
1881{
1882 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001883
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001885 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
1887 return 0;
1888 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001889
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001891 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001893 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 actual++;
1895 }
1896 return actual;
1897}
1898
1899/*
1900 * Function smsc_ircc_is_receiving (self)
1901 *
1902 * Returns true is we are currently receiving data
1903 *
1904 */
1905static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
1906{
1907 return (self->rx_buff.state != OUTSIDE_FRAME);
1908}
1909
1910
1911/*
1912 * Function smsc_ircc_probe_transceiver(self)
1913 *
1914 * Tries to find the used Transceiver
1915 *
1916 */
1917static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
1918{
1919 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001920
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001922
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001923 for (i = 0; smsc_transceivers[i].name != NULL; i++)
1924 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 IRDA_MESSAGE(" %s transceiver found\n",
1926 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001927 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 return;
1929 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001930
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
1932 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001933
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001934 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935}
1936
1937
1938/*
1939 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
1940 *
1941 * Set the transceiver according to the speed
1942 *
1943 */
1944static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
1945{
1946 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001947
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001949 if (trx > 0)
1950 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
1953/*
1954 * Function smsc_ircc_wait_hw_transmitter_finish ()
1955 *
1956 * Wait for the real end of HW transmission
1957 *
1958 * The UART is a strict FIFO, and we get called only when we have finished
1959 * pushing data to the FIFO, so the maximum amount of time we must wait
1960 * is only for the FIFO to drain out.
1961 *
1962 * We use a simple calibrated loop. We may need to adjust the loop
1963 * delay (udelay) to balance I/O traffic and latency. And we also need to
1964 * adjust the maximum timeout.
1965 * It would probably be better to wait for the proper interrupt,
1966 * but it doesn't seem to be available.
1967 *
1968 * We can't use jiffies or kernel timers because :
1969 * 1) We are called from the interrupt handler, which disable softirqs,
1970 * so jiffies won't be increased
1971 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
1972 * want to wait that long to detect stuck hardware.
1973 * Jean II
1974 */
1975
1976static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
1977{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001978 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001980
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001982 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 udelay(1);
1984
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001985 if (count == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
1987}
1988
1989
1990/* PROBING
1991 *
1992 *
1993 */
1994
1995static int __init smsc_ircc_look_for_chips(void)
1996{
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07001997 struct smsc_chip_address *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001998 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002000
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 found = 0;
2002 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002003
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002004 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002006
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002008
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002009 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002011 if (address->type & SMSCSIO_TYPE_FLAT)
2012 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2013 found++;
2014
2015 if (address->type & SMSCSIO_TYPE_PAGED)
2016 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2017 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002019 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002021 if (address->type & SMSCSIO_TYPE_FLAT)
2022 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2023 found++;
2024
2025 if (address->type & SMSCSIO_TYPE_PAGED)
2026 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2027 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 }
2029 address++;
2030 }
2031 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002032}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
2034/*
2035 * Function smsc_superio_flat (chip, base, type)
2036 *
2037 * Try to get configuration of a smc SuperIO chip with flat register model
2038 *
2039 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002040static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041{
2042 unsigned short firbase, sirbase;
2043 u8 mode, dma, irq;
2044 int ret = -ENODEV;
2045
2046 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2047
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002048 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return ret;
2050
2051 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002052 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002055
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002056 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);
2058
2059 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002060 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002062 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002064 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
2066 /* DMA */
2067 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002068 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002069
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 /* IRQ */
2071 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002072 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073
2074 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);
2075
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002076 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2077 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002078
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 /* Exit configuration */
2080 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2081
2082 return ret;
2083}
2084
2085/*
2086 * Function smsc_superio_paged (chip, base, type)
2087 *
2088 * Try to get configuration of a smc SuperIO chip with paged register model
2089 *
2090 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002091static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092{
2093 unsigned short fir_io, sir_io;
2094 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002095
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2097
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002098 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 /* Select logical device (UART2) */
2102 outb(0x07, cfg_base);
2103 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 /* SIR iobase */
2106 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002107 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 outb(0x61, cfg_base);
2109 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 /* Read FIR base */
2112 outb(0x62, cfg_base);
2113 fir_io = inb(cfg_base + 1) << 8;
2114 outb(0x63, cfg_base);
2115 fir_io |= inb(cfg_base + 1);
2116 outb(0x2b, cfg_base); /* ??? */
2117
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002118 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2119 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002120
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 /* Exit configuration */
2122 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2123
2124 return ret;
2125}
2126
2127
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002128static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2131
2132 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002133 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002136static 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 -07002137{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002138 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 IRDA_DEBUG(1, "%s\n", __FUNCTION__);
2141
2142 /* Leave configuration */
2143
2144 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2145
2146 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2147 return NULL;
2148
2149 outb(reg, cfg_base);
2150
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002151 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 /* Enter configuration */
2154
2155 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2156
2157 #if 0
2158 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2159 return NULL;
2160 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002161
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 /* probe device ID */
2163
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002164 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 return NULL;
2166
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002167 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002168
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002169 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 return NULL;
2171
2172 /* probe revision ID */
2173
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002174 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 return NULL;
2176
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002177 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002179 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 return NULL;
2181
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002182 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 return NULL;
2184
2185 /* Check for expected device ID; are there others? */
2186
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002187 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189 chip++;
2190
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002191 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 return NULL;
2193 }
2194
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002195 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2196 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002198 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002199 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 return NULL;
2201 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002202
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002203 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 IRDA_MESSAGE("chipset does not support IRDA\n");
2205
2206 return chip;
2207}
2208
2209static int __init smsc_superio_fdc(unsigned short cfg_base)
2210{
2211 int ret = -1;
2212
2213 if (!request_region(cfg_base, 2, driver_name)) {
2214 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2215 __FUNCTION__, cfg_base);
2216 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002217 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2218 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 ret = 0;
2220
2221 release_region(cfg_base, 2);
2222 }
2223
2224 return ret;
2225}
2226
2227static int __init smsc_superio_lpc(unsigned short cfg_base)
2228{
2229 int ret = -1;
2230
2231 if (!request_region(cfg_base, 2, driver_name)) {
2232 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
2233 __FUNCTION__, cfg_base);
2234 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002235 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2236 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002238
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 release_region(cfg_base, 2);
2240 }
2241 return ret;
2242}
2243
2244/************************************************
2245 *
2246 * Transceivers specific functions
2247 *
2248 ************************************************/
2249
2250
2251/*
2252 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2253 *
2254 * Program transceiver through smsc-ircc ATC circuitry
2255 *
2256 */
2257
2258static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2259{
2260 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002261 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002262
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002263 jiffies_now = jiffies;
2264 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 /* ATC */
2267 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002268 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2269 fir_base + IRCC_ATC);
2270
2271 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2272 !time_after(jiffies, jiffies_timeout))
2273 /* empty */;
2274
2275 if (val)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002277 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278}
2279
2280/*
2281 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2282 *
2283 * Probe transceiver smsc-ircc ATC circuitry
2284 *
2285 */
2286
2287static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2288{
2289 return 0;
2290}
2291
2292/*
2293 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2294 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002295 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 *
2297 */
2298
2299static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2300{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002301 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002302
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002303 switch (speed) {
2304 default:
2305 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002306 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002308 case 1152000 :
2309 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 fast_mode = IRCC_LCR_A_FAST;
2311 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 }
2313 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002314 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315}
2316
2317/*
2318 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2319 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002320 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 *
2322 */
2323
2324static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2325{
2326 return 0;
2327}
2328
2329/*
2330 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2331 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002332 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 *
2334 */
2335
2336static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2337{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002338 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002339
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002340 switch (speed) {
2341 default:
2342 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002343 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002345 case 1152000 :
2346 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002347 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2348 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002349
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 }
2351 /* This causes an interrupt */
2352 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002353 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354}
2355
2356/*
2357 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
2358 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002359 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 *
2361 */
2362
2363static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
2364{
2365 return 0;
2366}
2367
2368
2369module_init(smsc_ircc_init);
2370module_exit(smsc_ircc_cleanup);