blob: 59b45c10adbce11e975c5ef62881a362b328809b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Description: Driver for the SMC Infrared Communications Controller
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Author: Daniele Peri (peri@csai.unipa.it)
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07005 * Created at:
6 * Modified at:
7 * Modified by:
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Copyright (c) 2002 Daniele Peri
10 * All Rights Reserved.
11 * Copyright (c) 2002 Jean Tourrilhes
Linus Walleijc1e14a62006-04-05 22:33:59 -070012 * Copyright (c) 2006 Linus Walleij
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
14 *
15 * Based on smc-ircc.c:
16 *
17 * Copyright (c) 2001 Stefani Seibold
18 * Copyright (c) 1999-2001 Dag Brattli
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070019 * Copyright (c) 1998-1999 Thomas Davis,
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 *
21 * and irport.c:
22 *
23 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
24 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070025 *
26 * This program is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU General Public License as
28 * published by the Free Software Foundation; either version 2 of
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * the License, or (at your option) any later version.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070035 *
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * MA 02111-1307 USA
40 *
41 ********************************************************************/
42
43#include <linux/module.h>
44#include <linux/kernel.h>
45#include <linux/types.h>
46#include <linux/skbuff.h>
47#include <linux/netdevice.h>
48#include <linux/ioport.h>
49#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000051#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/rtnetlink.h>
53#include <linux/serial_reg.h>
54#include <linux/dma-mapping.h>
David Brownelld94c77b2006-05-09 15:26:11 -070055#include <linux/pnp.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010056#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090057#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#include <asm/io.h>
60#include <asm/dma.h>
61#include <asm/byteorder.h>
62
63#include <linux/spinlock.h>
64#include <linux/pm.h>
Linus Walleijc1e14a62006-04-05 22:33:59 -070065#ifdef CONFIG_PCI
66#include <linux/pci.h>
67#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include <net/irda/wrapper.h>
70#include <net/irda/irda.h>
71#include <net/irda/irda_device.h>
72
73#include "smsc-ircc2.h"
74#include "smsc-sio.h"
75
Dmitry Torokhov98b77772005-09-06 15:19:19 -070076
77MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
78MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
79MODULE_LICENSE("GPL");
80
Rusty Russelleb939922011-12-19 14:08:01 +000081static bool smsc_nopnp = true;
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -070082module_param_named(nopnp, smsc_nopnp, bool, 0);
Jonathan Bastien-Filiatrault32db9272007-09-26 22:34:25 -070083MODULE_PARM_DESC(nopnp, "Do not use PNP to detect controller settings, defaults to true");
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -070084
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070085#define DMA_INVAL 255
86static int ircc_dma = DMA_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070087module_param(ircc_dma, int, 0);
88MODULE_PARM_DESC(ircc_dma, "DMA channel");
89
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070090#define IRQ_INVAL 255
91static int ircc_irq = IRQ_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070092module_param(ircc_irq, int, 0);
93MODULE_PARM_DESC(ircc_irq, "IRQ line");
94
95static int ircc_fir;
96module_param(ircc_fir, int, 0);
97MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
98
99static int ircc_sir;
100module_param(ircc_sir, int, 0);
101MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
102
103static int ircc_cfg;
104module_param(ircc_cfg, int, 0);
105MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
106
107static int ircc_transceiver;
108module_param(ircc_transceiver, int, 0);
109MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/* Types */
112
Linus Walleijc1e14a62006-04-05 22:33:59 -0700113#ifdef CONFIG_PCI
114struct smsc_ircc_subsystem_configuration {
115 unsigned short vendor; /* PCI vendor ID */
116 unsigned short device; /* PCI vendor ID */
117 unsigned short subvendor; /* PCI subsystem vendor ID */
Jean Delvare83cf0a92009-10-20 11:11:52 +0200118 unsigned short subdevice; /* PCI subsystem device ID */
Linus Walleijc1e14a62006-04-05 22:33:59 -0700119 unsigned short sir_io; /* I/O port for SIR */
120 unsigned short fir_io; /* I/O port for FIR */
121 unsigned char fir_irq; /* FIR IRQ */
122 unsigned char fir_dma; /* FIR DMA */
123 unsigned short cfg_base; /* I/O port for chip configuration */
124 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
125 const char *name; /* name shown as info */
126};
127#endif
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129struct smsc_transceiver {
130 char *name;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700131 void (*set_for_speed)(int fir_base, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 int (*probe)(int fir_base);
133};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135struct smsc_chip {
136 char *name;
137 #if 0
138 u8 type;
139 #endif
140 u16 flags;
141 u8 devid;
142 u8 rev;
143};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145struct smsc_chip_address {
146 unsigned int cfg_base;
147 unsigned int type;
148};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/* Private data for each instance */
151struct smsc_ircc_cb {
152 struct net_device *netdev; /* Yes! we are some kind of netdevice */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 chipio_t io; /* IrDA controller information */
156 iobuff_t tx_buff; /* Transmit buffer */
157 iobuff_t rx_buff; /* Receive buffer */
158 dma_addr_t tx_buff_dma;
159 dma_addr_t rx_buff_dma;
160
161 struct qos_info qos; /* QoS capabilities for this device */
162
163 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 __u32 new_speed;
166 __u32 flags; /* Interface flags */
167
168 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
169 int tx_len; /* Number of frames in tx_buff */
170
171 int transceiver;
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700172 struct platform_device *pldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175/* Constants */
176
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700177#define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
180#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700181#define SMSC_IRCC2_C_NET_TIMEOUT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#define SMSC_IRCC2_C_SIR_STOP 0
183
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700184static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/* Prototypes */
187
188static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
189static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
190static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
191static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
192static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
193static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700194static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
195static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000197static netdev_tx_t smsc_ircc_hard_xmit_sir(struct sk_buff *skb,
198 struct net_device *dev);
199static netdev_tx_t smsc_ircc_hard_xmit_fir(struct sk_buff *skb,
200 struct net_device *dev);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700201static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
202static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -0700203static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
204static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
David Howells7d12e782006-10-05 14:55:46 +0100205static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
207static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
208#if SMSC_IRCC2_C_SIR_STOP
209static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
210#endif
211static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
212static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
213static int smsc_ircc_net_open(struct net_device *dev);
214static int smsc_ircc_net_close(struct net_device *dev);
215static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
216#if SMSC_IRCC2_C_NET_TIMEOUT
217static void smsc_ircc_timeout(struct net_device *dev);
218#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
220static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
221static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
222static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
223
224/* Probing */
David S. Miller948252c2011-05-31 19:27:48 -0700225static int __init smsc_ircc_look_for_chips(void);
226static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
227static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
228static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
229static int __init smsc_superio_fdc(unsigned short cfg_base);
230static int __init smsc_superio_lpc(unsigned short cfg_base);
Linus Walleijc1e14a62006-04-05 22:33:59 -0700231#ifdef CONFIG_PCI
David S. Miller948252c2011-05-31 19:27:48 -0700232static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
233static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
234static void __init preconfigure_ali_port(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -0700235 unsigned short port);
David S. Miller948252c2011-05-31 19:27:48 -0700236static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
237static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
Linus Walleijc1e14a62006-04-05 22:33:59 -0700238 unsigned short ircc_fir,
239 unsigned short ircc_sir,
240 unsigned char ircc_dma,
241 unsigned char ircc_irq);
242#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244/* Transceivers specific functions */
245
246static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
247static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
248static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
249static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
250static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
251static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
252
253/* Power Management */
254
Russell King3ae5eae2005-11-09 22:32:44 +0000255static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
256static int smsc_ircc_resume(struct platform_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Russell King3ae5eae2005-11-09 22:32:44 +0000258static struct platform_driver smsc_ircc_driver = {
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700259 .suspend = smsc_ircc_suspend,
260 .resume = smsc_ircc_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000261 .driver = {
262 .name = SMSC_IRCC2_DRIVER_NAME,
263 },
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700264};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266/* Transceivers for SMSC-ircc */
267
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700268static struct smsc_transceiver smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700270 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
271 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
272 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
273 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700275#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277/* SMC SuperIO chipsets definitions */
278
279#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
280#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
281#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
282#define SIR 0 /* SuperIO Chip has only slow IRDA */
283#define FIR 4 /* SuperIO Chip has fast IRDA */
284#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
285
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700286static struct smsc_chip __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 /* Base address 0x3f0 or 0x370 */
289 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
290 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
291 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
292 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
293 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
294 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
295 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
296 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
297 { NULL }
298};
299
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700300static struct smsc_chip __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 /* Base address 0x3f0 or 0x370 */
303 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
304 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
305 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
306 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
307 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
308 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
309 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
310 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
311 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
312 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
313 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
314 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
315 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
316 { NULL }
317};
318
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700319static struct smsc_chip __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 /* Base address 0x2E or 0x4E */
322 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
Peter Kovarafdf27c2007-03-16 20:39:25 -0700323 { "47N227", KEY55_1|FIR|SERx4, 0x7a, 0x00 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
325 { NULL }
326};
327
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700328static struct smsc_chip __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 /* Base address 0x2E or 0x4E */
331 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
332 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
333 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
334 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
335 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
336 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
337 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
338 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
339 { NULL }
340};
341
342#define SMSCSIO_TYPE_FDC 1
343#define SMSCSIO_TYPE_LPC 2
344#define SMSCSIO_TYPE_FLAT 4
345#define SMSCSIO_TYPE_PAGED 8
346
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700347static struct smsc_chip_address __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700349 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
350 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
351 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
352 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
353 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
354 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355};
356
357/* Globals */
358
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700359static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
360static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362static inline void register_bank(int iobase, int bank)
363{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700364 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
365 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
David Brownelld94c77b2006-05-09 15:26:11 -0700368/* PNP hotplug support */
David S. Miller948252c2011-05-31 19:27:48 -0700369static const struct pnp_device_id smsc_ircc_pnp_table[] = {
David Brownelld94c77b2006-05-09 15:26:11 -0700370 { .id = "SMCf010", .driver_data = 0 },
371 /* and presumably others */
372 { }
373};
374MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700375
376static int pnp_driver_registered;
377
Ingo Molnar7a1aa302008-05-05 01:06:54 -0700378#ifdef CONFIG_PNP
Bill Pemberton45ac9362012-12-03 09:24:13 -0500379static int smsc_ircc_pnp_probe(struct pnp_dev *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000380 const struct pnp_device_id *dev_id)
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700381{
382 unsigned int firbase, sirbase;
383 u8 dma, irq;
384
385 if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
386 pnp_dma_valid(dev, 0) && pnp_irq_valid(dev, 0)))
387 return -EINVAL;
388
389 sirbase = pnp_port_start(dev, 0);
390 firbase = pnp_port_start(dev, 1);
391 dma = pnp_dma(dev, 0);
392 irq = pnp_irq(dev, 0);
393
394 if (smsc_ircc_open(firbase, sirbase, dma, irq))
395 return -ENODEV;
396
397 return 0;
398}
399
400static struct pnp_driver smsc_ircc_pnp_driver = {
401 .name = "smsc-ircc2",
402 .id_table = smsc_ircc_pnp_table,
403 .probe = smsc_ircc_pnp_probe,
404};
Ingo Molnar7a1aa302008-05-05 01:06:54 -0700405#else /* CONFIG_PNP */
406static struct pnp_driver smsc_ircc_pnp_driver;
407#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409/*******************************************************************************
410 *
411 *
412 * SMSC-ircc stuff
413 *
414 *
415 *******************************************************************************/
416
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700417static int __init smsc_ircc_legacy_probe(void)
418{
419 int ret = 0;
420
Bjorn Helgaas7c31d2f2007-06-27 14:09:50 -0700421#ifdef CONFIG_PCI
422 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
423 /* Ignore errors from preconfiguration */
424 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
425 }
426#endif
427
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700428 if (ircc_fir > 0 && ircc_sir > 0) {
429 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
430 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
431
432 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
433 ret = -ENODEV;
434 } else {
435 ret = -ENODEV;
436
437 /* try user provided configuration register base address */
438 if (ircc_cfg > 0) {
439 IRDA_MESSAGE(" Overriding configuration address "
440 "0x%04x\n", ircc_cfg);
441 if (!smsc_superio_fdc(ircc_cfg))
442 ret = 0;
443 if (!smsc_superio_lpc(ircc_cfg))
444 ret = 0;
445 }
446
447 if (smsc_ircc_look_for_chips() > 0)
448 ret = 0;
449 }
450 return ret;
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*
454 * Function smsc_ircc_init ()
455 *
456 * Initialize chip. Just try to find out how many chips we are dealing with
457 * and where they are
458 */
459static int __init smsc_ircc_init(void)
460{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700461 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700463 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Russell King3ae5eae2005-11-09 22:32:44 +0000465 ret = platform_driver_register(&smsc_ircc_driver);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700466 if (ret) {
467 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
468 return ret;
469 }
470
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700471 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700472
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700473 if (smsc_nopnp || !pnp_platform_devices ||
474 ircc_cfg || ircc_fir || ircc_sir ||
475 ircc_dma != DMA_INVAL || ircc_irq != IRQ_INVAL) {
476 ret = smsc_ircc_legacy_probe();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700477 } else {
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700478 if (pnp_register_driver(&smsc_ircc_pnp_driver) == 0)
479 pnp_driver_registered = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700481
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700482 if (ret) {
483 if (pnp_driver_registered)
484 pnp_unregister_driver(&smsc_ircc_pnp_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000485 platform_driver_unregister(&smsc_ircc_driver);
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700486 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return ret;
489}
490
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000491static netdev_tx_t smsc_ircc_net_xmit(struct sk_buff *skb,
492 struct net_device *dev)
Stephen Hemminger02087be2009-03-20 19:35:42 +0000493{
494 struct smsc_ircc_cb *self = netdev_priv(dev);
495
496 if (self->io.speed > 115200)
497 return smsc_ircc_hard_xmit_fir(skb, dev);
498 else
499 return smsc_ircc_hard_xmit_sir(skb, dev);
500}
501
502static const struct net_device_ops smsc_ircc_netdev_ops = {
503 .ndo_open = smsc_ircc_net_open,
504 .ndo_stop = smsc_ircc_net_close,
505 .ndo_do_ioctl = smsc_ircc_net_ioctl,
506 .ndo_start_xmit = smsc_ircc_net_xmit,
507#if SMSC_IRCC2_C_NET_TIMEOUT
508 .ndo_tx_timeout = smsc_ircc_timeout,
509#endif
510};
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512/*
513 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
514 *
515 * Try to open driver instance
516 *
517 */
Bill Pemberton45ac9362012-12-03 09:24:13 -0500518static int smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
520 struct smsc_ircc_cb *self;
521 struct net_device *dev;
522 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700523
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700524 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700527 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700531 if (dev_count >= ARRAY_SIZE(dev_self)) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700532 IRDA_WARNING("%s(), too many devices!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 goto err_out1;
534 }
535
536 /*
537 * Allocate new instance of the driver
538 */
539 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
540 if (!dev) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700541 IRDA_WARNING("%s() can't allocate net device\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 goto err_out1;
543 }
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#if SMSC_IRCC2_C_NET_TIMEOUT
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700546 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#endif
Stephen Hemminger02087be2009-03-20 19:35:42 +0000548 dev->netdev_ops = &smsc_ircc_netdev_ops;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700549
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700550 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 self->netdev = dev;
552
553 /* Make ifconfig display some details */
554 dev->base_addr = self->io.fir_base = fir_base;
555 dev->irq = self->io.irq = irq;
556
557 /* Need to store self somewhere */
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700558 dev_self[dev_count] = self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 spin_lock_init(&self->lock);
560
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700561 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
563
564 self->rx_buff.head =
565 dma_alloc_coherent(NULL, self->rx_buff.truesize,
566 &self->rx_buff_dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000567 if (self->rx_buff.head == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 goto err_out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 self->tx_buff.head =
571 dma_alloc_coherent(NULL, self->tx_buff.truesize,
572 &self->tx_buff_dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000573 if (self->tx_buff.head == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 goto err_out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 memset(self->rx_buff.head, 0, self->rx_buff.truesize);
577 memset(self->tx_buff.head, 0, self->tx_buff.truesize);
578
579 self->rx_buff.in_frame = FALSE;
580 self->rx_buff.state = OUTSIDE_FRAME;
581 self->tx_buff.data = self->tx_buff.head;
582 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700587
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700588 if (ircc_transceiver > 0 &&
589 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 self->transceiver = ircc_transceiver;
591 else
592 smsc_ircc_probe_transceiver(self);
593
594 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700595 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 IRDA_ERROR("%s, Network device registration failed!\n",
597 driver_name);
598 goto err_out4;
599 }
600
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700601 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
602 dev_count, NULL, 0);
603 if (IS_ERR(self->pldev)) {
604 err = PTR_ERR(self->pldev);
605 goto err_out5;
606 }
Russell King3ae5eae2005-11-09 22:32:44 +0000607 platform_set_drvdata(self->pldev, self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700610 dev_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700613
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700614 err_out5:
615 unregister_netdev(self->netdev);
616
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 err_out4:
618 dma_free_coherent(NULL, self->tx_buff.truesize,
619 self->tx_buff.head, self->tx_buff_dma);
620 err_out3:
621 dma_free_coherent(NULL, self->rx_buff.truesize,
622 self->rx_buff.head, self->rx_buff_dma);
623 err_out2:
624 free_netdev(self->netdev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700625 dev_self[dev_count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 err_out1:
627 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
628 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
629 err_out:
630 return err;
631}
632
633/*
634 * Function smsc_ircc_present(fir_base, sir_base)
635 *
636 * Check the smsc-ircc chip presence
637 *
638 */
639static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
640{
641 unsigned char low, high, chip, config, dma, irq, version;
642
643 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
644 driver_name)) {
645 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700646 __func__, fir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 goto out1;
648 }
649
650 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
651 driver_name)) {
652 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700653 __func__, sir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 goto out2;
655 }
656
657 register_bank(fir_base, 3);
658
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700659 high = inb(fir_base + IRCC_ID_HIGH);
660 low = inb(fir_base + IRCC_ID_LOW);
661 chip = inb(fir_base + IRCC_CHIP_ID);
662 version = inb(fir_base + IRCC_VERSION);
663 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 dma = config & IRCC_INTERFACE_DMA_MASK;
665 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
666
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700667 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700668 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700669 __func__, fir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 goto out3;
671 }
672 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
673 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
674 chip & 0x0f, version, fir_base, sir_base, dma, irq);
675
676 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 out3:
679 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
680 out2:
681 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
682 out1:
683 return -ENODEV;
684}
685
686/*
687 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
688 *
689 * Setup I/O
690 *
691 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700692static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
693 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 u8 dma, u8 irq)
695{
696 unsigned char config, chip_dma, chip_irq;
697
698 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700699 config = inb(fir_base + IRCC_INTERFACE);
700 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
701 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 self->io.fir_base = fir_base;
704 self->io.sir_base = sir_base;
705 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
706 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
707 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
708 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
709
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700710 if (irq != IRQ_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 if (irq != chip_irq)
712 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
713 driver_name, chip_irq, irq);
714 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700715 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700717
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700718 if (dma != DMA_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 if (dma != chip_dma)
720 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
721 driver_name, chip_dma, dma);
722 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700723 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 self->io.dma = chip_dma;
725
726}
727
728/*
729 * Function smsc_ircc_setup_qos(self)
730 *
731 * Setup qos
732 *
733 */
734static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
735{
736 /* Initialize QoS for this device */
737 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700738
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
740 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
741
742 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
743 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
744 irda_qos_bits_to_value(&self->qos);
745}
746
747/*
748 * Function smsc_ircc_init_chip(self)
749 *
750 * Init chip
751 *
752 */
753static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
754{
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800755 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756
757 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700758 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
759 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760
761 register_bank(iobase, 1);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800762 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700763 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700766 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
767 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700768#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700769 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
770 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700771#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700772 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
773 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 register_bank(iobase, 4);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800776 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 register_bank(iobase, 0);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800779 outb(0, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700784 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785}
786
787/*
788 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
789 *
790 * Process IOCTL commands for this device
791 *
792 */
793static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
794{
795 struct if_irda_req *irq = (struct if_irda_req *) rq;
796 struct smsc_ircc_cb *self;
797 unsigned long flags;
798 int ret = 0;
799
800 IRDA_ASSERT(dev != NULL, return -1;);
801
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700802 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 IRDA_ASSERT(self != NULL, return -1;);
805
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700806 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700807
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 switch (cmd) {
809 case SIOCSBANDWIDTH: /* Set bandwidth */
810 if (!capable(CAP_NET_ADMIN))
811 ret = -EPERM;
812 else {
813 /* Make sure we are the only one touching
814 * self->io.speed and the hardware - Jean II */
815 spin_lock_irqsave(&self->lock, flags);
816 smsc_ircc_change_speed(self, irq->ifr_baudrate);
817 spin_unlock_irqrestore(&self->lock, flags);
818 }
819 break;
820 case SIOCSMEDIABUSY: /* Set media busy */
821 if (!capable(CAP_NET_ADMIN)) {
822 ret = -EPERM;
823 break;
824 }
825
826 irda_device_set_media_busy(self->netdev, TRUE);
827 break;
828 case SIOCGRECEIVING: /* Check if we are receiving right now */
829 irq->ifr_receiving = smsc_ircc_is_receiving(self);
830 break;
831 #if 0
832 case SIOCSDTRRTS:
833 if (!capable(CAP_NET_ADMIN)) {
834 ret = -EPERM;
835 break;
836 }
837 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
838 break;
839 #endif
840 default:
841 ret = -EOPNOTSUPP;
842 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 return ret;
845}
846
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847#if SMSC_IRCC2_C_NET_TIMEOUT
848/*
849 * Function smsc_ircc_timeout (struct net_device *dev)
850 *
851 * The networking timeout management.
852 *
853 */
854
855static void smsc_ircc_timeout(struct net_device *dev)
856{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700857 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858 unsigned long flags;
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
861 dev->name, self->io.speed);
862 spin_lock_irqsave(&self->lock, flags);
863 smsc_ircc_sir_start(self);
864 smsc_ircc_change_speed(self, self->io.speed);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700865 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 netif_wake_queue(dev);
867 spin_unlock_irqrestore(&self->lock, flags);
868}
869#endif
870
871/*
872 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
873 *
874 * Transmits the current frame until FIFO is full, then
875 * waits until the next transmit interrupt, and continues until the
876 * frame is transmitted.
877 */
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000878static netdev_tx_t smsc_ircc_hard_xmit_sir(struct sk_buff *skb,
879 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880{
881 struct smsc_ircc_cb *self;
882 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 s32 speed;
884
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700885 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Patrick McHardyec634fe2009-07-05 19:23:38 -0700887 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700888
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700889 self = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700890 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /* Make sure test of self->io.speed & speed change are atomic */
895 spin_lock_irqsave(&self->lock, flags);
896
897 /* Check if we need to change the speed */
898 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700899 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 /* Check for empty frame */
901 if (!skb->len) {
902 /*
903 * We send frames one by one in SIR mode (no
904 * pipelining), so at this point, if we were sending
905 * a previous frame, we just received the interrupt
906 * telling us it is finished (UART_IIR_THRI).
907 * Therefore, waiting for the transmitter to really
908 * finish draining the fifo won't take too long.
909 * And the interrupt handler is not expected to run.
910 * - Jean II */
911 smsc_ircc_sir_wait_hw_transmitter_finish(self);
912 smsc_ircc_change_speed(self, speed);
913 spin_unlock_irqrestore(&self->lock, flags);
914 dev_kfree_skb(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700915 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700917 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 }
919
920 /* Init tx buffer */
921 self->tx_buff.data = self->tx_buff.head;
922
923 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700924 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700926
Stephen Hemmingeraf049082009-01-06 10:40:43 -0800927 dev->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700930 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932 spin_unlock_irqrestore(&self->lock, flags);
933
934 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700935
Patrick McHardyec634fe2009-07-05 19:23:38 -0700936 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
939/*
940 * Function smsc_ircc_set_fir_speed (self, baud)
941 *
942 * Change the speed of the device
943 *
944 */
945static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
946{
947 int fir_base, ir_mode, ctrl, fast;
948
949 IRDA_ASSERT(self != NULL, return;);
950 fir_base = self->io.fir_base;
951
952 self->io.speed = speed;
953
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700954 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700956 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 ir_mode = IRCC_CFGA_IRDA_HDLC;
958 ctrl = IRCC_CRC;
959 fast = 0;
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700960 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 break;
962 case 1152000:
963 ir_mode = IRCC_CFGA_IRDA_HDLC;
964 ctrl = IRCC_1152 | IRCC_CRC;
965 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
966 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700967 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 break;
969 case 4000000:
970 ir_mode = IRCC_CFGA_IRDA_4PPM;
971 ctrl = IRCC_CRC;
972 fast = IRCC_LCR_A_FAST;
973 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700974 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 break;
976 }
977 #if 0
978 Now in tranceiver!
979 /* This causes an interrupt */
980 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700981 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700985 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 -0700986
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700988 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989}
990
991/*
992 * Function smsc_ircc_fir_start(self)
993 *
994 * Change the speed of the device
995 *
996 */
997static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
998{
999 struct net_device *dev;
1000 int fir_base;
1001
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001002 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
1004 IRDA_ASSERT(self != NULL, return;);
1005 dev = self->netdev;
1006 IRDA_ASSERT(dev != NULL, return;);
1007
1008 fir_base = self->io.fir_base;
1009
1010 /* Reset everything */
1011
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001013 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001016 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 register_bank(fir_base, 1);
1019
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001020 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001022 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
1023 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001024#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001025 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
1026 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001027#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001028 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001031 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001033 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
1034 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035}
1036
1037/*
1038 * Function smsc_ircc_fir_stop(self, baud)
1039 *
1040 * Change the speed of the device
1041 *
1042 */
1043static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
1044{
1045 int fir_base;
1046
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001047 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001048
Linus Torvalds1da177e2005-04-16 15:20:36 -07001049 IRDA_ASSERT(self != NULL, return;);
1050
1051 fir_base = self->io.fir_base;
1052 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001053 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1054 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055}
1056
1057
1058/*
1059 * Function smsc_ircc_change_speed(self, baud)
1060 *
1061 * Change the speed of the device
1062 *
1063 * This function *must* be called with spinlock held, because it may
1064 * be called from the irq handler. - Jean II
1065 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -07001066static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001070
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001071 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 IRDA_ASSERT(self != NULL, return;);
1074 dev = self->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001075
1076 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1077
1078 #if 0
1079 /* Temp Hack */
1080 speed= 1152000;
1081 self->io.speed = speed;
1082 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001083 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001085
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001086 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 smsc_ircc_sir_start(self);
1088
1089 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001090 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 #endif
1092
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001093 if (self->io.speed != speed)
1094 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095
1096 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001097
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001098 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1099 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 smsc_ircc_fir_stop(self);
1101 smsc_ircc_sir_start(self);
1102 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001103 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001104 } else {
1105 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001106 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107 smsc_ircc_sir_stop(self);
1108 #endif
1109 smsc_ircc_fir_start(self);
1110 }
1111 smsc_ircc_set_fir_speed(self, speed);
1112
1113 #if 0
1114 self->tx_buff.len = 10;
1115 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001116
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001117 smsc_ircc_dma_xmit(self, 4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 #endif
1119 /* Be ready for incoming frames */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001120 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001122
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 netif_wake_queue(dev);
1124}
1125
1126/*
1127 * Function smsc_ircc_set_sir_speed (self, speed)
1128 *
1129 * Set speed of IrDA port to specified baudrate
1130 *
1131 */
Hannes Eder0e49e642008-12-26 00:03:19 -08001132static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001134 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 int fcr; /* FIFO control reg */
1136 int lcr; /* Line control reg */
1137 int divisor;
1138
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001139 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140
1141 IRDA_ASSERT(self != NULL, return;);
1142 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001143
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 /* Update accounting for new speed */
1145 self->io.speed = speed;
1146
1147 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001148 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001150 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 fcr = UART_FCR_ENABLE_FIFO;
1153
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001154 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1156 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001157 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001158 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001159 fcr |= self->io.speed < 38400 ?
1160 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001161
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 /* IrDA ports use 8N1 */
1163 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001164
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001165 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1166 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1167 outb(divisor >> 8, iobase + UART_DLM);
1168 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1169 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
1171 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001172 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001174 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175}
1176
1177
1178/*
1179 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1180 *
1181 * Transmit the frame!
1182 *
1183 */
Stephen Hemminger6518bbb2009-08-31 19:50:50 +00001184static netdev_tx_t smsc_ircc_hard_xmit_fir(struct sk_buff *skb,
1185 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186{
1187 struct smsc_ircc_cb *self;
1188 unsigned long flags;
1189 s32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 int mtt;
1191
Patrick McHardyec634fe2009-07-05 19:23:38 -07001192 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001193 self = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001194 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 netif_stop_queue(dev);
1197
1198 /* Make sure test of self->io.speed & speed change are atomic */
1199 spin_lock_irqsave(&self->lock, flags);
1200
1201 /* Check if we need to change the speed after this frame */
1202 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001203 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001204 /* Check for empty frame */
1205 if (!skb->len) {
1206 /* Note : you should make sure that speed changes
1207 * are not going to corrupt any outgoing frame.
1208 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001209 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 spin_unlock_irqrestore(&self->lock, flags);
1211 dev_kfree_skb(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001212 return NETDEV_TX_OK;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001213 }
1214
1215 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001217
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001218 skb_copy_from_linear_data(skb, self->tx_buff.head, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 self->tx_buff.len = skb->len;
1221 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001222
1223 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 if (mtt) {
1225 int bofs;
1226
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001227 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 * Compute how many BOFs (STA or PA's) we need to waste the
1229 * min turn time given the speed of the link.
1230 */
1231 bofs = mtt * (self->io.speed / 1000) / 8000;
1232 if (bofs > 4095)
1233 bofs = 4095;
1234
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001235 smsc_ircc_dma_xmit(self, bofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 } else {
1237 /* Transmit frame */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001238 smsc_ircc_dma_xmit(self, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 spin_unlock_irqrestore(&self->lock, flags);
1242 dev_kfree_skb(skb);
1243
Patrick McHardyec634fe2009-07-05 19:23:38 -07001244 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
1247/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001248 * Function smsc_ircc_dma_xmit (self, bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 *
1250 * Transmit data using DMA
1251 *
1252 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001253static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
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 u8 ctrl;
1257
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001258 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259#if 1
1260 /* Disable Rx */
1261 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001262 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263#endif
1264 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001265 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1266 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 self->io.direction = IO_XMIT;
1269
1270 /* Set BOF additional count for generating the min turn time */
1271 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001272 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1273 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1274 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001277 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1278 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279
1280 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001281
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282 /* Enable burst mode chip Tx DMA */
1283 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001284 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1285 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286
1287 /* Setup DMA controller (must be done after enabling chip DMA) */
1288 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1289 DMA_TX_MODE);
1290
1291 /* Enable interrupt */
1292
1293 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001294 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1295 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001298 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299}
1300
1301/*
1302 * Function smsc_ircc_dma_xmit_complete (self)
1303 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001304 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 * by the interrupt handler
1306 *
1307 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001308static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001310 int iobase = self->io.fir_base;
1311
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001312 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313#if 0
1314 /* Disable Tx */
1315 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001316 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317#endif
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001318 register_bank(iobase, 1);
1319 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1320 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
1322 /* Check for underrun! */
1323 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001324 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001325 self->netdev->stats.tx_errors++;
1326 self->netdev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 /* Reset error condition */
1329 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001330 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1331 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 } else {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001333 self->netdev->stats.tx_packets++;
1334 self->netdev->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 }
1336
1337 /* Check if it's time to change the speed */
1338 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001339 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 self->new_speed = 0;
1341 }
1342
1343 netif_wake_queue(self->netdev);
1344}
1345
1346/*
1347 * Function smsc_ircc_dma_receive(self)
1348 *
1349 * Get ready for receiving a frame. The device will initiate a DMA
1350 * if it starts to receive a frame.
1351 *
1352 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001353static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001355 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356#if 0
1357 /* Turn off chip DMA */
1358 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001359 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1360 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001362
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 /* Disable Tx */
1364 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001365 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 /* Turn off chip DMA */
1368 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001369 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1370 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371
1372 self->io.direction = IO_RECV;
1373 self->rx_buff.data = self->rx_buff.head;
1374
1375 /* Set max Rx frame size */
1376 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001377 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1378 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379
1380 /* Setup DMA controller */
1381 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1382 DMA_RX_MODE);
1383
1384 /* Enable burst mode chip Rx DMA */
1385 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001386 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1387 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 /* Enable interrupt */
1390 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001391 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1392 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394 /* Enable receiver */
1395 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001396 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001397 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001398
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 return 0;
1400}
1401
1402/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001403 * Function smsc_ircc_dma_receive_complete(self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 *
1405 * Finished with receiving frames
1406 *
1407 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001408static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409{
1410 struct sk_buff *skb;
1411 int len, msgcnt, lsr;
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001412 int iobase = self->io.fir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001413
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001415
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001416 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417#if 0
1418 /* Disable Rx */
1419 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001420 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421#endif
1422 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001423 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1424 lsr= inb(iobase + IRCC_LSR);
1425 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001427 IRDA_DEBUG(2, "%s: dma count = %d\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 get_dma_residue(self->io.dma));
1429
1430 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1431
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001432 /* Look for errors */
1433 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001434 self->netdev->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001435 if (lsr & IRCC_LSR_FRAME_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001436 self->netdev->stats.rx_frame_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001437 if (lsr & IRCC_LSR_CRC_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001438 self->netdev->stats.rx_crc_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001439 if (lsr & IRCC_LSR_SIZE_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001440 self->netdev->stats.rx_length_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001441 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001442 self->netdev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443 return;
1444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001446 /* Remove CRC */
1447 len -= self->io.speed < 4000000 ? 2 : 4;
1448
1449 if (len < 2 || len > 2050) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001450 IRDA_WARNING("%s(), bogus len=%d\n", __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451 return;
1452 }
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001453 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __func__, msgcnt, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001455 skb = dev_alloc_skb(len + 1);
1456 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001458 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001460 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001462 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463
1464 memcpy(skb_put(skb, len), self->rx_buff.data, len);
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001465 self->netdev->stats.rx_packets++;
1466 self->netdev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 skb->dev = self->netdev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001469 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001470 skb->protocol = htons(ETH_P_IRDA);
1471 netif_rx(skb);
1472}
1473
1474/*
1475 * Function smsc_ircc_sir_receive (self)
1476 *
1477 * Receive one frame from the infrared port
1478 *
1479 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001480static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481{
1482 int boguscount = 0;
1483 int iobase;
1484
1485 IRDA_ASSERT(self != NULL, return;);
1486
1487 iobase = self->io.sir_base;
1488
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001489 /*
1490 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1491 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 */
1493 do {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001494 async_unwrap_char(self->netdev, &self->netdev->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001495 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497 /* Make sure we don't stay here to long */
1498 if (boguscount++ > 32) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001499 IRDA_DEBUG(2, "%s(), breaking!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 break;
1501 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001502 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503}
1504
1505
1506/*
1507 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1508 *
1509 * An interrupt from the chip has arrived. Time to do some work
1510 *
1511 */
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001512static irqreturn_t smsc_ircc_interrupt(int dummy, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513{
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001514 struct net_device *dev = dev_id;
1515 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 int iobase, iir, lcra, lsr;
1517 irqreturn_t ret = IRQ_NONE;
1518
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001520 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521
1522 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001523 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524 ret = smsc_ircc_interrupt_sir(dev);
1525 goto irq_ret_unlock;
1526 }
1527
1528 iobase = self->io.fir_base;
1529
1530 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001531 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001532 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001533 goto irq_ret_unlock;
1534 ret = IRQ_HANDLED;
1535
1536 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001537 outb(0, iobase + IRCC_IER);
1538 lcra = inb(iobase + IRCC_LCR_A);
1539 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001540
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001541 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __func__, iir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 if (iir & IRCC_IIR_EOM) {
1544 if (self->io.direction == IO_RECV)
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001545 smsc_ircc_dma_receive_complete(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 else
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001547 smsc_ircc_dma_xmit_complete(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001548
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001549 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 }
1551
1552 if (iir & IRCC_IIR_ACTIVE_FRAME) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001553 /*printk(KERN_WARNING "%s(): Active Frame\n", __func__);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 }
1555
1556 /* Enable interrupts again */
1557
1558 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001559 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 irq_ret_unlock:
1562 spin_unlock(&self->lock);
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001563
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 return ret;
1565}
1566
1567/*
David Howells7d12e782006-10-05 14:55:46 +01001568 * Function irport_interrupt_sir (irq, dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 *
1570 * Interrupt handler for SIR modes
1571 */
1572static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1573{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001574 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 int boguscount = 0;
1576 int iobase;
1577 int iir, lsr;
1578
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001579 /* Already locked coming here in smsc_ircc_interrupt() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 /*spin_lock(&self->lock);*/
1581
1582 iobase = self->io.sir_base;
1583
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001584 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 if (iir == 0)
1586 return IRQ_NONE;
1587 while (iir) {
1588 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001589 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001591 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001592 __func__, iir, lsr, iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 switch (iir) {
1595 case UART_IIR_RLSI:
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001596 IRDA_DEBUG(2, "%s(), RLSI\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597 break;
1598 case UART_IIR_RDI:
1599 /* Receive interrupt */
1600 smsc_ircc_sir_receive(self);
1601 break;
1602 case UART_IIR_THRI:
1603 if (lsr & UART_LSR_THRE)
1604 /* Transmitter ready for data */
1605 smsc_ircc_sir_write_wakeup(self);
1606 break;
1607 default:
1608 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001609 __func__, iir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001611 }
1612
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 /* Make sure we don't stay here to long */
1614 if (boguscount++ > 100)
1615 break;
1616
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001617 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 }
1619 /*spin_unlock(&self->lock);*/
1620 return IRQ_HANDLED;
1621}
1622
1623
1624#if 0 /* unused */
1625/*
1626 * Function ircc_is_receiving (self)
1627 *
1628 * Return TRUE is we are currently receiving a frame
1629 *
1630 */
1631static int ircc_is_receiving(struct smsc_ircc_cb *self)
1632{
1633 int status = FALSE;
1634 /* int iobase; */
1635
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001636 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
1638 IRDA_ASSERT(self != NULL, return FALSE;);
1639
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001640 IRDA_DEBUG(0, "%s: dma count = %d\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 get_dma_residue(self->io.dma));
1642
1643 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001644
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 return status;
1646}
1647#endif /* unused */
1648
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001649static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1650{
1651 int error;
1652
1653 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1654 self->netdev->name, self->netdev);
1655 if (error)
1656 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001657 __func__, self->io.irq, error);
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001658
1659 return error;
1660}
1661
1662static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1663{
1664 unsigned long flags;
1665
1666 spin_lock_irqsave(&self->lock, flags);
1667
1668 self->io.speed = 0;
1669 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1670
1671 spin_unlock_irqrestore(&self->lock, flags);
1672}
1673
1674static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1675{
1676 int iobase = self->io.fir_base;
1677 unsigned long flags;
1678
1679 spin_lock_irqsave(&self->lock, flags);
1680
1681 register_bank(iobase, 0);
1682 outb(0, iobase + IRCC_IER);
1683 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1684 outb(0x00, iobase + IRCC_MASTER);
1685
1686 spin_unlock_irqrestore(&self->lock, flags);
1687}
1688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689
1690/*
1691 * Function smsc_ircc_net_open (dev)
1692 *
1693 * Start the device
1694 *
1695 */
1696static int smsc_ircc_net_open(struct net_device *dev)
1697{
1698 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 char hwname[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001701 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001704 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001706
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001707 if (self->io.suspended) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001708 IRDA_DEBUG(0, "%s(), device is suspended\n", __func__);
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001709 return -EAGAIN;
1710 }
1711
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001712 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 (void *) dev)) {
1714 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001715 __func__, self->io.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 return -EAGAIN;
1717 }
1718
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001719 smsc_ircc_start_interrupts(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001720
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 /* Give self a hardware name */
1722 /* It would be cool to offer the chip revision here - Jean II */
1723 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1724
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001725 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001727 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 */
1729 self->irlap = irlap_open(dev, &self->qos, hwname);
1730
1731 /*
1732 * Always allocate the DMA channel after the IRQ,
1733 * and clean up on failure.
1734 */
1735 if (request_dma(self->io.dma, dev->name)) {
1736 smsc_ircc_net_close(dev);
1737
1738 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001739 __func__, self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 return -EAGAIN;
1741 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001742
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 netif_start_queue(dev);
1744
1745 return 0;
1746}
1747
1748/*
1749 * Function smsc_ircc_net_close (dev)
1750 *
1751 * Stop the device
1752 *
1753 */
1754static int smsc_ircc_net_close(struct net_device *dev)
1755{
1756 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001758 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001761 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 /* Stop device */
1765 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001766
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 /* Stop and remove instance of IrLAP */
1768 if (self->irlap)
1769 irlap_close(self->irlap);
1770 self->irlap = NULL;
1771
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001772 smsc_ircc_stop_interrupts(self);
1773
1774 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1775 if (!self->io.suspended)
1776 free_irq(self->io.irq, dev);
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 free_dma(self->io.dma);
1780
1781 return 0;
1782}
1783
Russell King3ae5eae2005-11-09 22:32:44 +00001784static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785{
Russell King3ae5eae2005-11-09 22:32:44 +00001786 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001787
Russell King9480e302005-10-28 09:52:56 -07001788 if (!self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001789 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1790
1791 rtnl_lock();
1792 if (netif_running(self->netdev)) {
1793 netif_device_detach(self->netdev);
1794 smsc_ircc_stop_interrupts(self);
1795 free_irq(self->io.irq, self->netdev);
1796 disable_dma(self->io.dma);
1797 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001798 self->io.suspended = 1;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001799 rtnl_unlock();
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001800 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001801
1802 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803}
1804
Russell King3ae5eae2005-11-09 22:32:44 +00001805static int smsc_ircc_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806{
Russell King3ae5eae2005-11-09 22:32:44 +00001807 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Russell King9480e302005-10-28 09:52:56 -07001809 if (self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001810 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001812 rtnl_lock();
1813 smsc_ircc_init_chip(self);
1814 if (netif_running(self->netdev)) {
1815 if (smsc_ircc_request_irq(self)) {
1816 /*
1817 * Don't fail resume process, just kill this
1818 * network interface
1819 */
1820 unregister_netdevice(self->netdev);
1821 } else {
1822 enable_dma(self->io.dma);
1823 smsc_ircc_start_interrupts(self);
1824 netif_device_attach(self->netdev);
1825 }
1826 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001827 self->io.suspended = 0;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001828 rtnl_unlock();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001829 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 return 0;
1831}
1832
1833/*
1834 * Function smsc_ircc_close (self)
1835 *
1836 * Close driver instance
1837 *
1838 */
1839static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1840{
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001841 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842
1843 IRDA_ASSERT(self != NULL, return -1;);
1844
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001845 platform_device_unregister(self->pldev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 /* Remove netdevice */
1848 unregister_netdev(self->netdev);
1849
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001850 smsc_ircc_stop_interrupts(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852 /* Release the PORTS that this driver is using */
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001853 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 self->io.fir_base);
1855
1856 release_region(self->io.fir_base, self->io.fir_ext);
1857
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001858 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 self->io.sir_base);
1860
1861 release_region(self->io.sir_base, self->io.sir_ext);
1862
1863 if (self->tx_buff.head)
1864 dma_free_coherent(NULL, self->tx_buff.truesize,
1865 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 if (self->rx_buff.head)
1868 dma_free_coherent(NULL, self->rx_buff.truesize,
1869 self->rx_buff.head, self->rx_buff_dma);
1870
1871 free_netdev(self->netdev);
1872
1873 return 0;
1874}
1875
1876static void __exit smsc_ircc_cleanup(void)
1877{
1878 int i;
1879
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001880 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001882 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883 if (dev_self[i])
1884 smsc_ircc_close(dev_self[i]);
1885 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001886
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -07001887 if (pnp_driver_registered)
1888 pnp_unregister_driver(&smsc_ircc_pnp_driver);
1889
Russell King3ae5eae2005-11-09 22:32:44 +00001890 platform_driver_unregister(&smsc_ircc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891}
1892
1893/*
1894 * Start SIR operations
1895 *
1896 * This function *must* be called with spinlock held, because it may
1897 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1898 */
Hannes Eder0e49e642008-12-26 00:03:19 -08001899static void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900{
1901 struct net_device *dev;
1902 int fir_base, sir_base;
1903
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001904 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001906 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001907 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001908 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 fir_base = self->io.fir_base;
1911 sir_base = self->io.sir_base;
1912
1913 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001914 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915
1916 #if SMSC_IRCC2_C_SIR_STOP
1917 /*smsc_ircc_sir_stop(self);*/
1918 #endif
1919
1920 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001921 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 -07001922
1923 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001924 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1925 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001926
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001928 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001930 IRDA_DEBUG(3, "%s() - exit\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001932 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933}
1934
1935#if SMSC_IRCC2_C_SIR_STOP
1936void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1937{
1938 int iobase;
1939
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001940 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 iobase = self->io.sir_base;
1942
1943 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001944 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001945
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001947 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948}
1949#endif
1950
1951/*
1952 * Function smsc_sir_write_wakeup (self)
1953 *
1954 * Called by the SIR interrupt handler when there's room for more data.
1955 * If we have more packets to send, we send them here.
1956 *
1957 */
1958static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1959{
1960 int actual = 0;
1961 int iobase;
1962 int fcr;
1963
1964 IRDA_ASSERT(self != NULL, return;);
1965
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001966 IRDA_DEBUG(4, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967
1968 iobase = self->io.sir_base;
1969
1970 /* Finished with frame? */
1971 if (self->tx_buff.len > 0) {
1972 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001973 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 self->tx_buff.data, self->tx_buff.len);
1975 self->tx_buff.data += actual;
1976 self->tx_buff.len -= actual;
1977 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001978
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001980
1981 /*
1982 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 * transmission of another packet. But first we must check
1984 * if we need to change the speed of the hardware
1985 */
1986 if (self->new_speed) {
1987 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001988 __func__, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1990 smsc_ircc_change_speed(self, self->new_speed);
1991 self->new_speed = 0;
1992 } else {
1993 /* Tell network layer that we want more frames */
1994 netif_wake_queue(self->netdev);
1995 }
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001996 self->netdev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001998 if (self->io.speed <= 115200) {
1999 /*
2000 * Reset Rx FIFO to make sure that all reflected transmit data
2001 * is discarded. This is needed for half duplex operation
2002 */
2003 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
2004 fcr |= self->io.speed < 38400 ?
2005 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002007 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002009 /* Turn on receive interrupts */
2010 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 }
2012 }
2013}
2014
2015/*
2016 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
2017 *
2018 * Fill Tx FIFO with transmit data
2019 *
2020 */
2021static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
2022{
2023 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002026 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002027 IRDA_WARNING("%s(), failed, fifo not empty!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return 0;
2029 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002032 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002034 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 actual++;
2036 }
2037 return actual;
2038}
2039
2040/*
2041 * Function smsc_ircc_is_receiving (self)
2042 *
2043 * Returns true is we are currently receiving data
2044 *
2045 */
2046static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
2047{
Eric Dumazet807540b2010-09-23 05:40:09 +00002048 return self->rx_buff.state != OUTSIDE_FRAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
2051
2052/*
2053 * Function smsc_ircc_probe_transceiver(self)
2054 *
2055 * Tries to find the used Transceiver
2056 *
2057 */
2058static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2059{
2060 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002063
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002064 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2065 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 IRDA_MESSAGE(" %s transceiver found\n",
2067 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002068 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 return;
2070 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2073 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002074
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002075 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076}
2077
2078
2079/*
2080 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2081 *
2082 * Set the transceiver according to the speed
2083 *
2084 */
2085static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2086{
2087 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002088
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002090 if (trx > 0)
2091 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092}
2093
2094/*
2095 * Function smsc_ircc_wait_hw_transmitter_finish ()
2096 *
2097 * Wait for the real end of HW transmission
2098 *
2099 * The UART is a strict FIFO, and we get called only when we have finished
2100 * pushing data to the FIFO, so the maximum amount of time we must wait
2101 * is only for the FIFO to drain out.
2102 *
2103 * We use a simple calibrated loop. We may need to adjust the loop
2104 * delay (udelay) to balance I/O traffic and latency. And we also need to
2105 * adjust the maximum timeout.
2106 * It would probably be better to wait for the proper interrupt,
2107 * but it doesn't seem to be available.
2108 *
2109 * We can't use jiffies or kernel timers because :
2110 * 1) We are called from the interrupt handler, which disable softirqs,
2111 * so jiffies won't be increased
2112 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2113 * want to wait that long to detect stuck hardware.
2114 * Jean II
2115 */
2116
2117static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2118{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002119 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002121
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002123 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 udelay(1);
2125
Roel Kluinadbf7f02009-06-05 12:54:44 +02002126 if (count < 0)
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002127 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128}
2129
2130
2131/* PROBING
2132 *
David Brownelld94c77b2006-05-09 15:26:11 -07002133 * REVISIT we can be told about the device by PNP, and should use that info
2134 * instead of probing hardware and creating a platform_device ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 */
2136
2137static int __init smsc_ircc_look_for_chips(void)
2138{
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002139 struct smsc_chip_address *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002140 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002142
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 found = 0;
2144 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002145
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002146 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002148
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002149 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __func__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002150
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002151 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002153 if (address->type & SMSCSIO_TYPE_FLAT)
2154 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2155 found++;
2156
2157 if (address->type & SMSCSIO_TYPE_PAGED)
2158 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2159 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002161 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002163 if (address->type & SMSCSIO_TYPE_FLAT)
2164 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2165 found++;
2166
2167 if (address->type & SMSCSIO_TYPE_PAGED)
2168 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2169 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 }
2171 address++;
2172 }
2173 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002174}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176/*
2177 * Function smsc_superio_flat (chip, base, type)
2178 *
2179 * Try to get configuration of a smc SuperIO chip with flat register model
2180 *
2181 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002182static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
2184 unsigned short firbase, sirbase;
2185 u8 mode, dma, irq;
2186 int ret = -ENODEV;
2187
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002188 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002190 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 return ret;
2192
2193 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002194 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002195
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002196 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __func__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002197
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002198 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002199 IRDA_WARNING("%s(): IrDA not enabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
2201 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002202 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002204 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002206 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
2208 /* DMA */
2209 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002210 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002211
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 /* IRQ */
2213 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002214 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002216 IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __func__, firbase, sirbase, dma, irq, mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002218 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2219 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002220
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 /* Exit configuration */
2222 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2223
2224 return ret;
2225}
2226
2227/*
2228 * Function smsc_superio_paged (chip, base, type)
2229 *
2230 * Try to get configuration of a smc SuperIO chip with paged register model
2231 *
2232 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002233static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234{
2235 unsigned short fir_io, sir_io;
2236 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002237
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002238 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002240 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002242
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 /* Select logical device (UART2) */
2244 outb(0x07, cfg_base);
2245 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002246
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 /* SIR iobase */
2248 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002249 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 outb(0x61, cfg_base);
2251 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002252
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 /* Read FIR base */
2254 outb(0x62, cfg_base);
2255 fir_io = inb(cfg_base + 1) << 8;
2256 outb(0x63, cfg_base);
2257 fir_io |= inb(cfg_base + 1);
2258 outb(0x2b, cfg_base); /* ??? */
2259
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002260 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2261 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 /* Exit configuration */
2264 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2265
2266 return ret;
2267}
2268
2269
David S. Miller948252c2011-05-31 19:27:48 -07002270static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271{
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002272 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273
2274 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002275 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276}
2277
David S. Miller948252c2011-05-31 19:27:48 -07002278static 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 -07002279{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002280 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002282 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
2284 /* Leave configuration */
2285
2286 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2287
2288 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2289 return NULL;
2290
2291 outb(reg, cfg_base);
2292
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002293 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294
2295 /* Enter configuration */
2296
2297 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2298
2299 #if 0
2300 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2301 return NULL;
2302 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002303
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 /* probe device ID */
2305
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002306 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 return NULL;
2308
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002309 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002310
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002311 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 return NULL;
2313
2314 /* probe revision ID */
2315
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002316 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 return NULL;
2318
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002319 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002321 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 return NULL;
2323
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002324 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 return NULL;
2326
2327 /* Check for expected device ID; are there others? */
2328
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002329 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
2331 chip++;
2332
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002333 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 return NULL;
2335 }
2336
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002337 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2338 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002340 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002341 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 return NULL;
2343 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002344
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002345 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 IRDA_MESSAGE("chipset does not support IRDA\n");
2347
2348 return chip;
2349}
2350
2351static int __init smsc_superio_fdc(unsigned short cfg_base)
2352{
2353 int ret = -1;
2354
2355 if (!request_region(cfg_base, 2, driver_name)) {
2356 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002357 __func__, cfg_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002359 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2360 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 ret = 0;
2362
2363 release_region(cfg_base, 2);
2364 }
2365
2366 return ret;
2367}
2368
2369static int __init smsc_superio_lpc(unsigned short cfg_base)
2370{
2371 int ret = -1;
2372
2373 if (!request_region(cfg_base, 2, driver_name)) {
2374 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002375 __func__, cfg_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002377 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2378 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002380
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 release_region(cfg_base, 2);
2382 }
2383 return ret;
2384}
2385
Linus Walleijc1e14a62006-04-05 22:33:59 -07002386/*
2387 * Look for some specific subsystem setups that need
2388 * pre-configuration not properly done by the BIOS (especially laptops)
2389 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2390 * and tosh2450-smcinit.c. The table lists the device entries
Linus Walleij08d09992006-04-14 16:03:33 -07002391 * for ISA bridges with an LPC (Low Pin Count) controller which
2392 * handles the communication with the SMSC device. After the LPC
2393 * controller is initialized through PCI, the SMSC device is initialized
2394 * through a dedicated port in the ISA port-mapped I/O area, this latter
2395 * area is used to configure the SMSC device with default
2396 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2397 * used different sets of parameters and different control port
2398 * addresses making a subsystem device table necessary.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002399 */
2400#ifdef CONFIG_PCI
David S. Miller948252c2011-05-31 19:27:48 -07002401static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002402 /*
2403 * Subsystems needing entries:
2404 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2405 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2406 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2407 */
2408 {
2409 /* Guessed entry */
Jon Mason5ee5a072011-08-03 06:42:42 +00002410 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002411 .device = 0x24cc,
2412 .subvendor = 0x103c,
2413 .subdevice = 0x08bc,
2414 .sir_io = 0x02f8,
2415 .fir_io = 0x0130,
2416 .fir_irq = 0x05,
2417 .fir_dma = 0x03,
2418 .cfg_base = 0x004e,
2419 .preconfigure = preconfigure_through_82801,
2420 .name = "HP nx5000 family",
2421 },
Linus Walleijc1e14a62006-04-05 22:33:59 -07002422 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002423 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002424 .device = 0x24cc,
2425 .subvendor = 0x103c,
2426 .subdevice = 0x088c,
Linus Walleij08d09992006-04-14 16:03:33 -07002427 /* Quite certain these are the same for nc8000 as for nc6000 */
2428 .sir_io = 0x02f8,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002429 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002430 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002431 .fir_dma = 0x03,
2432 .cfg_base = 0x004e,
2433 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002434 .name = "HP nc8000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002435 },
2436 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002437 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002438 .device = 0x24cc,
2439 .subvendor = 0x103c,
2440 .subdevice = 0x0890,
2441 .sir_io = 0x02f8,
2442 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002443 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002444 .fir_dma = 0x03,
2445 .cfg_base = 0x004e,
2446 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002447 .name = "HP nc6000 family",
2448 },
2449 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002450 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002451 .device = 0x24cc,
2452 .subvendor = 0x0e11,
2453 .subdevice = 0x0860,
2454 /* I assume these are the same for x1000 as for the others */
2455 .sir_io = 0x02e8,
2456 .fir_io = 0x02f8,
2457 .fir_irq = 0x07,
2458 .fir_dma = 0x03,
2459 .cfg_base = 0x002e,
2460 .preconfigure = preconfigure_through_82801,
2461 .name = "Compaq x1000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002462 },
2463 {
Linus Walleij08d09992006-04-14 16:03:33 -07002464 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
Jon Mason5ee5a072011-08-03 06:42:42 +00002465 .vendor = PCI_VENDOR_ID_INTEL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002466 .device = 0x24c0,
2467 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002468 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002469 .sir_io = 0x03f8,
2470 .fir_io = 0x0130,
2471 .fir_irq = 0x07,
2472 .fir_dma = 0x01,
2473 .cfg_base = 0x002e,
2474 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002475 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002476 },
2477 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002478 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801CAM ISA bridge */
Linus Walleij08d09992006-04-14 16:03:33 -07002479 .device = 0x248c,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002480 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002481 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002482 .sir_io = 0x03f8,
2483 .fir_io = 0x0130,
2484 .fir_irq = 0x03,
2485 .fir_dma = 0x03,
2486 .cfg_base = 0x002e,
2487 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002488 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002489 },
2490 {
Linus Walleij08d09992006-04-14 16:03:33 -07002491 /* 82801DBM (ICH4-M) LPC Interface Bridge */
Jon Mason5ee5a072011-08-03 06:42:42 +00002492 .vendor = PCI_VENDOR_ID_INTEL,
Linus Walleij08d09992006-04-14 16:03:33 -07002493 .device = 0x24cc,
2494 .subvendor = 0x1179,
2495 .subdevice = 0xffff, /* 0xffff is "any" */
2496 .sir_io = 0x03f8,
2497 .fir_io = 0x0130,
2498 .fir_irq = 0x03,
2499 .fir_dma = 0x03,
2500 .cfg_base = 0x002e,
2501 .preconfigure = preconfigure_through_82801,
2502 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2503 },
2504 {
2505 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
Jon Mason5ee5a072011-08-03 06:42:42 +00002506 .vendor = PCI_VENDOR_ID_AL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002507 .device = 0x1533,
2508 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002509 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002510 .sir_io = 0x02e8,
2511 .fir_io = 0x02f8,
2512 .fir_irq = 0x07,
2513 .fir_dma = 0x03,
2514 .cfg_base = 0x002e,
2515 .preconfigure = preconfigure_through_ali,
Linus Walleij08d09992006-04-14 16:03:33 -07002516 .name = "Toshiba laptop with ALi ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002517 },
2518 { } // Terminator
2519};
2520
2521
2522/*
Linus Walleij08d09992006-04-14 16:03:33 -07002523 * This sets up the basic SMSC parameters
2524 * (FIR port, SIR port, FIR DMA, FIR IRQ)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002525 * through the chip configuration port.
2526 */
David S. Miller948252c2011-05-31 19:27:48 -07002527static int __init preconfigure_smsc_chip(struct
Linus Walleij08d09992006-04-14 16:03:33 -07002528 smsc_ircc_subsystem_configuration
2529 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002530{
2531 unsigned short iobase = conf->cfg_base;
2532 unsigned char tmpbyte;
2533
2534 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2535 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2536 tmpbyte = inb(iobase +1); // Read device ID
Linus Walleij08d09992006-04-14 16:03:33 -07002537 IRDA_DEBUG(0,
2538 "Detected Chip id: 0x%02x, setting up registers...\n",
2539 tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002540
2541 /* Disable UART1 and set up SIR I/O port */
2542 outb(0x24, iobase); // select CR24 - UART1 base addr
2543 outb(0x00, iobase + 1); // disable UART1
2544 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2545 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2546 tmpbyte = inb(iobase + 1);
2547 if (tmpbyte != (conf->sir_io >> 2) ) {
2548 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
Linus Walleij08d09992006-04-14 16:03:33 -07002549 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
Linus Walleijc1e14a62006-04-05 22:33:59 -07002550 return -ENXIO;
2551 }
2552
2553 /* Set up FIR IRQ channel for UART2 */
2554 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2555 tmpbyte = inb(iobase + 1);
2556 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2557 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2558 outb(tmpbyte, iobase + 1);
2559 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2560 if (tmpbyte != conf->fir_irq) {
2561 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2562 return -ENXIO;
2563 }
2564
2565 /* Set up FIR I/O port */
2566 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2567 outb((conf->fir_io >> 3), iobase + 1);
2568 tmpbyte = inb(iobase + 1);
2569 if (tmpbyte != (conf->fir_io >> 3) ) {
2570 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2571 return -ENXIO;
2572 }
2573
2574 /* Set up FIR DMA channel */
2575 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2576 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2577 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2578 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2579 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2580 return -ENXIO;
2581 }
2582
2583 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2584 tmpbyte = inb(iobase + 1);
Linus Walleij08d09992006-04-14 16:03:33 -07002585 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2586 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002587 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2588
2589 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2590 tmpbyte = inb(iobase + 1);
2591 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2592
2593 /* This one was not part of tosh1800 */
2594 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2595 tmpbyte = inb(iobase + 1);
2596 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2597
2598 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2599 tmpbyte = inb(iobase + 1);
2600 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2601
2602 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2603 tmpbyte = inb(iobase + 1);
2604 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2605
2606 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2607
2608 return 0;
2609}
2610
Linus Walleij08d09992006-04-14 16:03:33 -07002611/* 82801CAM generic registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002612#define VID 0x00
2613#define DID 0x02
Linus Walleij08d09992006-04-14 16:03:33 -07002614#define PIRQ_A_D_ROUT 0x60
2615#define SIRQ_CNTL 0x64
2616#define PIRQ_E_H_ROUT 0x68
Linus Walleijc1e14a62006-04-05 22:33:59 -07002617#define PCI_DMA_C 0x90
Linus Walleij08d09992006-04-14 16:03:33 -07002618/* LPC-specific registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002619#define COM_DEC 0xe0
Linus Walleij08d09992006-04-14 16:03:33 -07002620#define GEN1_DEC 0xe4
Linus Walleijc1e14a62006-04-05 22:33:59 -07002621#define LPC_EN 0xe6
2622#define GEN2_DEC 0xec
2623/*
Linus Walleij08d09992006-04-14 16:03:33 -07002624 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2625 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2626 * They all work the same way!
Linus Walleijc1e14a62006-04-05 22:33:59 -07002627 */
David S. Miller948252c2011-05-31 19:27:48 -07002628static int __init preconfigure_through_82801(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002629 struct
2630 smsc_ircc_subsystem_configuration
2631 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002632{
2633 unsigned short tmpword;
Linus Walleij08d09992006-04-14 16:03:33 -07002634 unsigned char tmpbyte;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002635
Linus Walleij08d09992006-04-14 16:03:33 -07002636 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2637 /*
2638 * Select the range for the COMA COM port (SIR)
2639 * Register COM_DEC:
2640 * Bit 7: reserved
2641 * Bit 6-4, COMB decode range
2642 * Bit 3: reserved
2643 * Bit 2-0, COMA decode range
2644 *
2645 * Decode ranges:
2646 * 000 = 0x3f8-0x3ff (COM1)
2647 * 001 = 0x2f8-0x2ff (COM2)
2648 * 010 = 0x220-0x227
2649 * 011 = 0x228-0x22f
2650 * 100 = 0x238-0x23f
2651 * 101 = 0x2e8-0x2ef (COM4)
2652 * 110 = 0x338-0x33f
2653 * 111 = 0x3e8-0x3ef (COM3)
2654 */
2655 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2656 tmpbyte &= 0xf8; /* mask COMA bits */
2657 switch(conf->sir_io) {
2658 case 0x3f8:
2659 tmpbyte |= 0x00;
2660 break;
2661 case 0x2f8:
2662 tmpbyte |= 0x01;
2663 break;
2664 case 0x220:
2665 tmpbyte |= 0x02;
2666 break;
2667 case 0x228:
2668 tmpbyte |= 0x03;
2669 break;
2670 case 0x238:
2671 tmpbyte |= 0x04;
2672 break;
2673 case 0x2e8:
2674 tmpbyte |= 0x05;
2675 break;
2676 case 0x338:
2677 tmpbyte |= 0x06;
2678 break;
2679 case 0x3e8:
2680 tmpbyte |= 0x07;
2681 break;
2682 default:
2683 tmpbyte |= 0x01; /* COM2 default */
2684 }
2685 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2686 pci_write_config_byte(dev, COM_DEC, tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002687
Linus Walleij08d09992006-04-14 16:03:33 -07002688 /* Enable Low Pin Count interface */
2689 pci_read_config_word(dev, LPC_EN, &tmpword);
2690 /* These seem to be set up at all times,
2691 * just make sure it is properly set.
2692 */
2693 switch(conf->cfg_base) {
2694 case 0x04e:
2695 tmpword |= 0x2000;
2696 break;
2697 case 0x02e:
2698 tmpword |= 0x1000;
2699 break;
2700 case 0x062:
2701 tmpword |= 0x0800;
2702 break;
2703 case 0x060:
2704 tmpword |= 0x0400;
2705 break;
2706 default:
2707 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2708 conf->cfg_base);
2709 break;
2710 }
2711 tmpword &= 0xfffd; /* disable LPC COMB */
2712 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2713 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002714 pci_write_config_word(dev, LPC_EN, tmpword);
2715
Linus Walleij08d09992006-04-14 16:03:33 -07002716 /*
2717 * Configure LPC DMA channel
2718 * PCI_DMA_C bits:
2719 * Bit 15-14: DMA channel 7 select
2720 * Bit 13-12: DMA channel 6 select
2721 * Bit 11-10: DMA channel 5 select
2722 * Bit 9-8: Reserved
2723 * Bit 7-6: DMA channel 3 select
2724 * Bit 5-4: DMA channel 2 select
2725 * Bit 3-2: DMA channel 1 select
2726 * Bit 1-0: DMA channel 0 select
2727 * 00 = Reserved value
2728 * 01 = PC/PCI DMA
2729 * 10 = Reserved value
2730 * 11 = LPC I/F DMA
2731 */
2732 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2733 switch(conf->fir_dma) {
2734 case 0x07:
2735 tmpword |= 0xc000;
2736 break;
2737 case 0x06:
2738 tmpword |= 0x3000;
2739 break;
2740 case 0x05:
2741 tmpword |= 0x0c00;
2742 break;
2743 case 0x03:
2744 tmpword |= 0x00c0;
2745 break;
2746 case 0x02:
2747 tmpword |= 0x0030;
2748 break;
2749 case 0x01:
2750 tmpword |= 0x000c;
2751 break;
2752 case 0x00:
2753 tmpword |= 0x0003;
2754 break;
2755 default:
2756 break; /* do not change settings */
2757 }
2758 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2759 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2760
2761 /*
2762 * GEN2_DEC bits:
2763 * Bit 15-4: Generic I/O range
2764 * Bit 3-1: reserved (read as 0)
2765 * Bit 0: enable GEN2 range on LPC I/F
2766 */
2767 tmpword = conf->fir_io & 0xfff8;
2768 tmpword |= 0x0001;
2769 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2770 pci_write_config_word(dev, GEN2_DEC, tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002771
2772 /* Pre-configure chip */
Linus Walleij08d09992006-04-14 16:03:33 -07002773 return preconfigure_smsc_chip(conf);
2774}
Linus Walleijc1e14a62006-04-05 22:33:59 -07002775
Linus Walleij08d09992006-04-14 16:03:33 -07002776/*
2777 * Pre-configure a certain port on the ALi 1533 bridge.
2778 * This is based on reverse-engineering since ALi does not
2779 * provide any data sheet for the 1533 chip.
2780 */
David S. Miller948252c2011-05-31 19:27:48 -07002781static void __init preconfigure_ali_port(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002782 unsigned short port)
2783{
2784 unsigned char reg;
2785 /* These bits obviously control the different ports */
2786 unsigned char mask;
2787 unsigned char tmpbyte;
2788
2789 switch(port) {
2790 case 0x0130:
2791 case 0x0178:
2792 reg = 0xb0;
2793 mask = 0x80;
2794 break;
2795 case 0x03f8:
2796 reg = 0xb4;
2797 mask = 0x80;
2798 break;
2799 case 0x02f8:
2800 reg = 0xb4;
2801 mask = 0x30;
2802 break;
2803 case 0x02e8:
2804 reg = 0xb4;
2805 mask = 0x08;
2806 break;
2807 default:
2808 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2809 return;
2810 }
2811
2812 pci_read_config_byte(dev, reg, &tmpbyte);
2813 /* Turn on the right bits */
2814 tmpbyte |= mask;
2815 pci_write_config_byte(dev, reg, tmpbyte);
2816 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002817}
2818
David S. Miller948252c2011-05-31 19:27:48 -07002819static int __init preconfigure_through_ali(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002820 struct
2821 smsc_ircc_subsystem_configuration
2822 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002823{
Linus Walleij08d09992006-04-14 16:03:33 -07002824 /* Configure the two ports on the ALi 1533 */
2825 preconfigure_ali_port(dev, conf->sir_io);
2826 preconfigure_ali_port(dev, conf->fir_io);
2827
2828 /* Pre-configure chip */
2829 return preconfigure_smsc_chip(conf);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002830}
2831
David S. Miller948252c2011-05-31 19:27:48 -07002832static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002833 unsigned short ircc_fir,
2834 unsigned short ircc_sir,
2835 unsigned char ircc_dma,
2836 unsigned char ircc_irq)
2837{
2838 struct pci_dev *dev = NULL;
2839 unsigned short ss_vendor = 0x0000;
2840 unsigned short ss_device = 0x0000;
2841 int ret = 0;
2842
Kulikov Vasiliy2e4e7a92010-07-03 06:04:15 +00002843 for_each_pci_dev(dev) {
David S. Miller948252c2011-05-31 19:27:48 -07002844 struct smsc_ircc_subsystem_configuration *conf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002845
2846 /*
Linus Walleij08d09992006-04-14 16:03:33 -07002847 * Cache the subsystem vendor/device:
2848 * some manufacturers fail to set this for all components,
2849 * so we save it in case there is just 0x0000 0x0000 on the
2850 * device we want to check.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002851 */
2852 if (dev->subsystem_vendor != 0x0000U) {
2853 ss_vendor = dev->subsystem_vendor;
2854 ss_device = dev->subsystem_device;
2855 }
2856 conf = subsystem_configurations;
2857 for( ; conf->subvendor; conf++) {
2858 if(conf->vendor == dev->vendor &&
2859 conf->device == dev->device &&
Linus Walleij08d09992006-04-14 16:03:33 -07002860 conf->subvendor == ss_vendor &&
2861 /* Sometimes these are cached values */
2862 (conf->subdevice == ss_device ||
2863 conf->subdevice == 0xffff)) {
2864 struct smsc_ircc_subsystem_configuration
2865 tmpconf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002866
Linus Walleij08d09992006-04-14 16:03:33 -07002867 memcpy(&tmpconf, conf,
2868 sizeof(struct smsc_ircc_subsystem_configuration));
Linus Walleijc1e14a62006-04-05 22:33:59 -07002869
Linus Walleij08d09992006-04-14 16:03:33 -07002870 /*
2871 * Override the default values with anything
2872 * passed in as parameter
2873 */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002874 if (ircc_cfg != 0)
2875 tmpconf.cfg_base = ircc_cfg;
2876 if (ircc_fir != 0)
2877 tmpconf.fir_io = ircc_fir;
2878 if (ircc_sir != 0)
2879 tmpconf.sir_io = ircc_sir;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002880 if (ircc_dma != DMA_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002881 tmpconf.fir_dma = ircc_dma;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002882 if (ircc_irq != IRQ_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002883 tmpconf.fir_irq = ircc_irq;
2884
2885 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2886 if (conf->preconfigure)
2887 ret = conf->preconfigure(dev, &tmpconf);
2888 else
2889 ret = -ENODEV;
2890 }
2891 }
Linus Walleijc1e14a62006-04-05 22:33:59 -07002892 }
2893
2894 return ret;
2895}
2896#endif // CONFIG_PCI
2897
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898/************************************************
2899 *
2900 * Transceivers specific functions
2901 *
2902 ************************************************/
2903
2904
2905/*
2906 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2907 *
2908 * Program transceiver through smsc-ircc ATC circuitry
2909 *
2910 */
2911
2912static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2913{
2914 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002915 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002916
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002917 jiffies_now = jiffies;
2918 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002919
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 /* ATC */
2921 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002922 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2923 fir_base + IRCC_ATC);
2924
2925 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2926 !time_after(jiffies, jiffies_timeout))
2927 /* empty */;
2928
2929 if (val)
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002930 IRDA_WARNING("%s(): ATC: 0x%02x\n", __func__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002931 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932}
2933
2934/*
2935 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2936 *
2937 * Probe transceiver smsc-ircc ATC circuitry
2938 *
2939 */
2940
2941static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2942{
2943 return 0;
2944}
2945
2946/*
2947 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2948 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002949 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950 *
2951 */
2952
2953static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2954{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002955 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002956
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002957 switch (speed) {
2958 default:
2959 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002960 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002962 case 1152000 :
2963 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 fast_mode = IRCC_LCR_A_FAST;
2965 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 }
2967 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002968 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969}
2970
2971/*
2972 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2973 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002974 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 *
2976 */
2977
2978static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2979{
2980 return 0;
2981}
2982
2983/*
2984 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2985 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002986 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 *
2988 */
2989
2990static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2991{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002992 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002993
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002994 switch (speed) {
2995 default:
2996 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002997 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002999 case 1152000 :
3000 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
3002 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07003003
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 }
3005 /* This causes an interrupt */
3006 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07003007 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008}
3009
3010/*
3011 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
3012 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07003013 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 *
3015 */
3016
3017static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
3018{
3019 return 0;
3020}
3021
3022
3023module_init(smsc_ircc_init);
3024module_exit(smsc_ircc_cleanup);