blob: 282120430f1271bfbfb4ea06b301d4560ef1daf0 [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
Jeff Kirshere8478de2013-12-06 06:28:44 -080037 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 *
39 ********************************************************************/
40
41#include <linux/module.h>
42#include <linux/kernel.h>
43#include <linux/types.h>
44#include <linux/skbuff.h>
45#include <linux/netdevice.h>
46#include <linux/ioport.h>
47#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000049#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/rtnetlink.h>
51#include <linux/serial_reg.h>
52#include <linux/dma-mapping.h>
David Brownelld94c77b2006-05-09 15:26:11 -070053#include <linux/pnp.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010054#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090055#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57#include <asm/io.h>
58#include <asm/dma.h>
59#include <asm/byteorder.h>
60
61#include <linux/spinlock.h>
62#include <linux/pm.h>
Linus Walleijc1e14a62006-04-05 22:33:59 -070063#ifdef CONFIG_PCI
64#include <linux/pci.h>
65#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67#include <net/irda/wrapper.h>
68#include <net/irda/irda.h>
69#include <net/irda/irda_device.h>
70
71#include "smsc-ircc2.h"
72#include "smsc-sio.h"
73
Dmitry Torokhov98b77772005-09-06 15:19:19 -070074
75MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
76MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
77MODULE_LICENSE("GPL");
78
Rusty Russelleb939922011-12-19 14:08:01 +000079static bool smsc_nopnp = true;
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -070080module_param_named(nopnp, smsc_nopnp, bool, 0);
Jonathan Bastien-Filiatrault32db9272007-09-26 22:34:25 -070081MODULE_PARM_DESC(nopnp, "Do not use PNP to detect controller settings, defaults to true");
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -070082
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070083#define DMA_INVAL 255
84static int ircc_dma = DMA_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070085module_param(ircc_dma, int, 0);
86MODULE_PARM_DESC(ircc_dma, "DMA channel");
87
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070088#define IRQ_INVAL 255
89static int ircc_irq = IRQ_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070090module_param(ircc_irq, int, 0);
91MODULE_PARM_DESC(ircc_irq, "IRQ line");
92
93static int ircc_fir;
94module_param(ircc_fir, int, 0);
95MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
96
97static int ircc_sir;
98module_param(ircc_sir, int, 0);
99MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
100
101static int ircc_cfg;
102module_param(ircc_cfg, int, 0);
103MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
104
105static int ircc_transceiver;
106module_param(ircc_transceiver, int, 0);
107MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* Types */
110
Linus Walleijc1e14a62006-04-05 22:33:59 -0700111#ifdef CONFIG_PCI
112struct smsc_ircc_subsystem_configuration {
113 unsigned short vendor; /* PCI vendor ID */
114 unsigned short device; /* PCI vendor ID */
115 unsigned short subvendor; /* PCI subsystem vendor ID */
Jean Delvare83cf0a92009-10-20 11:11:52 +0200116 unsigned short subdevice; /* PCI subsystem device ID */
Linus Walleijc1e14a62006-04-05 22:33:59 -0700117 unsigned short sir_io; /* I/O port for SIR */
118 unsigned short fir_io; /* I/O port for FIR */
119 unsigned char fir_irq; /* FIR IRQ */
120 unsigned char fir_dma; /* FIR DMA */
121 unsigned short cfg_base; /* I/O port for chip configuration */
122 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
123 const char *name; /* name shown as info */
124};
125#endif
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127struct smsc_transceiver {
128 char *name;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700129 void (*set_for_speed)(int fir_base, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 int (*probe)(int fir_base);
131};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133struct smsc_chip {
134 char *name;
135 #if 0
136 u8 type;
137 #endif
138 u16 flags;
139 u8 devid;
140 u8 rev;
141};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143struct smsc_chip_address {
144 unsigned int cfg_base;
145 unsigned int type;
146};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147
148/* Private data for each instance */
149struct smsc_ircc_cb {
150 struct net_device *netdev; /* Yes! we are some kind of netdevice */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 chipio_t io; /* IrDA controller information */
154 iobuff_t tx_buff; /* Transmit buffer */
155 iobuff_t rx_buff; /* Receive buffer */
156 dma_addr_t tx_buff_dma;
157 dma_addr_t rx_buff_dma;
158
159 struct qos_info qos; /* QoS capabilities for this device */
160
161 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 __u32 new_speed;
164 __u32 flags; /* Interface flags */
165
166 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
167 int tx_len; /* Number of frames in tx_buff */
168
169 int transceiver;
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700170 struct platform_device *pldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171};
172
173/* Constants */
174
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700175#define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
178#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700179#define SMSC_IRCC2_C_NET_TIMEOUT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#define SMSC_IRCC2_C_SIR_STOP 0
181
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700182static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184/* Prototypes */
185
186static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
187static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
188static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
189static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
190static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
191static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700192static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
193static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000195static netdev_tx_t smsc_ircc_hard_xmit_sir(struct sk_buff *skb,
196 struct net_device *dev);
197static netdev_tx_t smsc_ircc_hard_xmit_fir(struct sk_buff *skb,
198 struct net_device *dev);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700199static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
200static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -0700201static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
202static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
David Howells7d12e782006-10-05 14:55:46 +0100203static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
205static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
206#if SMSC_IRCC2_C_SIR_STOP
207static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
208#endif
209static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
210static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
211static int smsc_ircc_net_open(struct net_device *dev);
212static int smsc_ircc_net_close(struct net_device *dev);
213static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
214#if SMSC_IRCC2_C_NET_TIMEOUT
215static void smsc_ircc_timeout(struct net_device *dev);
216#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
218static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
219static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
220static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
221
222/* Probing */
David S. Miller948252c2011-05-31 19:27:48 -0700223static int __init smsc_ircc_look_for_chips(void);
224static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
225static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
226static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
227static int __init smsc_superio_fdc(unsigned short cfg_base);
228static int __init smsc_superio_lpc(unsigned short cfg_base);
Linus Walleijc1e14a62006-04-05 22:33:59 -0700229#ifdef CONFIG_PCI
David S. Miller948252c2011-05-31 19:27:48 -0700230static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
231static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
232static void __init preconfigure_ali_port(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -0700233 unsigned short port);
David S. Miller948252c2011-05-31 19:27:48 -0700234static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
235static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
Linus Walleijc1e14a62006-04-05 22:33:59 -0700236 unsigned short ircc_fir,
237 unsigned short ircc_sir,
238 unsigned char ircc_dma,
239 unsigned char ircc_irq);
240#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241
242/* Transceivers specific functions */
243
244static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
245static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
246static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
247static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
248static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
249static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
250
251/* Power Management */
252
Russell King3ae5eae2005-11-09 22:32:44 +0000253static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
254static int smsc_ircc_resume(struct platform_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Russell King3ae5eae2005-11-09 22:32:44 +0000256static struct platform_driver smsc_ircc_driver = {
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700257 .suspend = smsc_ircc_suspend,
258 .resume = smsc_ircc_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000259 .driver = {
260 .name = SMSC_IRCC2_DRIVER_NAME,
261 },
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700262};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264/* Transceivers for SMSC-ircc */
265
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700266static struct smsc_transceiver smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700268 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
269 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
270 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
271 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700273#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275/* SMC SuperIO chipsets definitions */
276
277#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
278#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
279#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
280#define SIR 0 /* SuperIO Chip has only slow IRDA */
281#define FIR 4 /* SuperIO Chip has fast IRDA */
282#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
283
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700284static struct smsc_chip __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
286 /* Base address 0x3f0 or 0x370 */
287 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
288 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
289 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
290 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
291 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
292 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
293 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
294 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
295 { NULL }
296};
297
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700298static struct smsc_chip __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
300 /* Base address 0x3f0 or 0x370 */
301 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
302 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
303 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
304 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
305 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
306 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
307 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
308 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
309 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
310 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
311 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
312 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
313 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
314 { NULL }
315};
316
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700317static struct smsc_chip __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318{
319 /* Base address 0x2E or 0x4E */
320 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
Peter Kovarafdf27c2007-03-16 20:39:25 -0700321 { "47N227", KEY55_1|FIR|SERx4, 0x7a, 0x00 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
323 { NULL }
324};
325
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700326static struct smsc_chip __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
328 /* Base address 0x2E or 0x4E */
329 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
330 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
331 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
332 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
333 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
334 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
335 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
336 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
337 { NULL }
338};
339
340#define SMSCSIO_TYPE_FDC 1
341#define SMSCSIO_TYPE_LPC 2
342#define SMSCSIO_TYPE_FLAT 4
343#define SMSCSIO_TYPE_PAGED 8
344
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700345static struct smsc_chip_address __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700347 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
348 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
349 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
350 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
351 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
352 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353};
354
355/* Globals */
356
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700357static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
358static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360static inline void register_bank(int iobase, int bank)
361{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700362 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
363 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
David Brownelld94c77b2006-05-09 15:26:11 -0700366/* PNP hotplug support */
David S. Miller948252c2011-05-31 19:27:48 -0700367static const struct pnp_device_id smsc_ircc_pnp_table[] = {
David Brownelld94c77b2006-05-09 15:26:11 -0700368 { .id = "SMCf010", .driver_data = 0 },
369 /* and presumably others */
370 { }
371};
372MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700373
374static int pnp_driver_registered;
375
Ingo Molnar7a1aa302008-05-05 01:06:54 -0700376#ifdef CONFIG_PNP
Bill Pemberton45ac9362012-12-03 09:24:13 -0500377static int smsc_ircc_pnp_probe(struct pnp_dev *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000378 const struct pnp_device_id *dev_id)
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700379{
380 unsigned int firbase, sirbase;
381 u8 dma, irq;
382
383 if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
384 pnp_dma_valid(dev, 0) && pnp_irq_valid(dev, 0)))
385 return -EINVAL;
386
387 sirbase = pnp_port_start(dev, 0);
388 firbase = pnp_port_start(dev, 1);
389 dma = pnp_dma(dev, 0);
390 irq = pnp_irq(dev, 0);
391
392 if (smsc_ircc_open(firbase, sirbase, dma, irq))
393 return -ENODEV;
394
395 return 0;
396}
397
398static struct pnp_driver smsc_ircc_pnp_driver = {
399 .name = "smsc-ircc2",
400 .id_table = smsc_ircc_pnp_table,
401 .probe = smsc_ircc_pnp_probe,
402};
Ingo Molnar7a1aa302008-05-05 01:06:54 -0700403#else /* CONFIG_PNP */
404static struct pnp_driver smsc_ircc_pnp_driver;
405#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
407/*******************************************************************************
408 *
409 *
410 * SMSC-ircc stuff
411 *
412 *
413 *******************************************************************************/
414
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700415static int __init smsc_ircc_legacy_probe(void)
416{
417 int ret = 0;
418
Bjorn Helgaas7c31d2f2007-06-27 14:09:50 -0700419#ifdef CONFIG_PCI
420 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
421 /* Ignore errors from preconfiguration */
422 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
423 }
424#endif
425
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700426 if (ircc_fir > 0 && ircc_sir > 0) {
427 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
428 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
429
430 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
431 ret = -ENODEV;
432 } else {
433 ret = -ENODEV;
434
435 /* try user provided configuration register base address */
436 if (ircc_cfg > 0) {
437 IRDA_MESSAGE(" Overriding configuration address "
438 "0x%04x\n", ircc_cfg);
439 if (!smsc_superio_fdc(ircc_cfg))
440 ret = 0;
441 if (!smsc_superio_lpc(ircc_cfg))
442 ret = 0;
443 }
444
445 if (smsc_ircc_look_for_chips() > 0)
446 ret = 0;
447 }
448 return ret;
449}
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451/*
452 * Function smsc_ircc_init ()
453 *
454 * Initialize chip. Just try to find out how many chips we are dealing with
455 * and where they are
456 */
457static int __init smsc_ircc_init(void)
458{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700459 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700461 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Russell King3ae5eae2005-11-09 22:32:44 +0000463 ret = platform_driver_register(&smsc_ircc_driver);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700464 if (ret) {
465 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
466 return ret;
467 }
468
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700469 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700470
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700471 if (smsc_nopnp || !pnp_platform_devices ||
472 ircc_cfg || ircc_fir || ircc_sir ||
473 ircc_dma != DMA_INVAL || ircc_irq != IRQ_INVAL) {
474 ret = smsc_ircc_legacy_probe();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700475 } else {
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700476 if (pnp_register_driver(&smsc_ircc_pnp_driver) == 0)
477 pnp_driver_registered = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700479
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700480 if (ret) {
481 if (pnp_driver_registered)
482 pnp_unregister_driver(&smsc_ircc_pnp_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000483 platform_driver_unregister(&smsc_ircc_driver);
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700484 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700485
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 return ret;
487}
488
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000489static netdev_tx_t smsc_ircc_net_xmit(struct sk_buff *skb,
490 struct net_device *dev)
Stephen Hemminger02087be2009-03-20 19:35:42 +0000491{
492 struct smsc_ircc_cb *self = netdev_priv(dev);
493
494 if (self->io.speed > 115200)
495 return smsc_ircc_hard_xmit_fir(skb, dev);
496 else
497 return smsc_ircc_hard_xmit_sir(skb, dev);
498}
499
500static const struct net_device_ops smsc_ircc_netdev_ops = {
501 .ndo_open = smsc_ircc_net_open,
502 .ndo_stop = smsc_ircc_net_close,
503 .ndo_do_ioctl = smsc_ircc_net_ioctl,
504 .ndo_start_xmit = smsc_ircc_net_xmit,
505#if SMSC_IRCC2_C_NET_TIMEOUT
506 .ndo_tx_timeout = smsc_ircc_timeout,
507#endif
508};
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510/*
511 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
512 *
513 * Try to open driver instance
514 *
515 */
Bill Pemberton45ac9362012-12-03 09:24:13 -0500516static int smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517{
518 struct smsc_ircc_cb *self;
519 struct net_device *dev;
520 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700521
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700522 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700525 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700529 if (dev_count >= ARRAY_SIZE(dev_self)) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700530 IRDA_WARNING("%s(), too many devices!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 goto err_out1;
532 }
533
534 /*
535 * Allocate new instance of the driver
536 */
537 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
538 if (!dev) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700539 IRDA_WARNING("%s() can't allocate net device\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 goto err_out1;
541 }
542
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543#if SMSC_IRCC2_C_NET_TIMEOUT
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700544 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#endif
Stephen Hemminger02087be2009-03-20 19:35:42 +0000546 dev->netdev_ops = &smsc_ircc_netdev_ops;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700547
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700548 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 self->netdev = dev;
550
551 /* Make ifconfig display some details */
552 dev->base_addr = self->io.fir_base = fir_base;
553 dev->irq = self->io.irq = irq;
554
555 /* Need to store self somewhere */
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700556 dev_self[dev_count] = self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 spin_lock_init(&self->lock);
558
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700559 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
561
562 self->rx_buff.head =
Joe Perchesede23fa2013-08-26 22:45:23 -0700563 dma_zalloc_coherent(NULL, self->rx_buff.truesize,
564 &self->rx_buff_dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000565 if (self->rx_buff.head == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 goto err_out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 self->tx_buff.head =
Joe Perchesede23fa2013-08-26 22:45:23 -0700569 dma_zalloc_coherent(NULL, self->tx_buff.truesize,
570 &self->tx_buff_dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +0000571 if (self->tx_buff.head == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 goto err_out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 self->rx_buff.in_frame = FALSE;
575 self->rx_buff.state = OUTSIDE_FRAME;
576 self->tx_buff.data = self->tx_buff.head;
577 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700582
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700583 if (ircc_transceiver > 0 &&
584 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 self->transceiver = ircc_transceiver;
586 else
587 smsc_ircc_probe_transceiver(self);
588
589 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700590 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 IRDA_ERROR("%s, Network device registration failed!\n",
592 driver_name);
593 goto err_out4;
594 }
595
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700596 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
597 dev_count, NULL, 0);
598 if (IS_ERR(self->pldev)) {
599 err = PTR_ERR(self->pldev);
600 goto err_out5;
601 }
Russell King3ae5eae2005-11-09 22:32:44 +0000602 platform_set_drvdata(self->pldev, self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700605 dev_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
607 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700608
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700609 err_out5:
610 unregister_netdev(self->netdev);
611
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 err_out4:
613 dma_free_coherent(NULL, self->tx_buff.truesize,
614 self->tx_buff.head, self->tx_buff_dma);
615 err_out3:
616 dma_free_coherent(NULL, self->rx_buff.truesize,
617 self->rx_buff.head, self->rx_buff_dma);
618 err_out2:
619 free_netdev(self->netdev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700620 dev_self[dev_count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 err_out1:
622 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
623 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
624 err_out:
625 return err;
626}
627
628/*
629 * Function smsc_ircc_present(fir_base, sir_base)
630 *
631 * Check the smsc-ircc chip presence
632 *
633 */
634static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
635{
636 unsigned char low, high, chip, config, dma, irq, version;
637
638 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
639 driver_name)) {
640 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700641 __func__, fir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 goto out1;
643 }
644
645 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
646 driver_name)) {
647 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700648 __func__, sir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 goto out2;
650 }
651
652 register_bank(fir_base, 3);
653
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700654 high = inb(fir_base + IRCC_ID_HIGH);
655 low = inb(fir_base + IRCC_ID_LOW);
656 chip = inb(fir_base + IRCC_CHIP_ID);
657 version = inb(fir_base + IRCC_VERSION);
658 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 dma = config & IRCC_INTERFACE_DMA_MASK;
660 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
661
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700662 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700663 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700664 __func__, fir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 goto out3;
666 }
667 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
668 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
669 chip & 0x0f, version, fir_base, sir_base, dma, irq);
670
671 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 out3:
674 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
675 out2:
676 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
677 out1:
678 return -ENODEV;
679}
680
681/*
682 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
683 *
684 * Setup I/O
685 *
686 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700687static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
688 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 u8 dma, u8 irq)
690{
691 unsigned char config, chip_dma, chip_irq;
692
693 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700694 config = inb(fir_base + IRCC_INTERFACE);
695 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
696 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697
698 self->io.fir_base = fir_base;
699 self->io.sir_base = sir_base;
700 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
701 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
702 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
703 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
704
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700705 if (irq != IRQ_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706 if (irq != chip_irq)
707 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
708 driver_name, chip_irq, irq);
709 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700710 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700712
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700713 if (dma != DMA_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 if (dma != chip_dma)
715 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
716 driver_name, chip_dma, dma);
717 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700718 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 self->io.dma = chip_dma;
720
721}
722
723/*
724 * Function smsc_ircc_setup_qos(self)
725 *
726 * Setup qos
727 *
728 */
729static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
730{
731 /* Initialize QoS for this device */
732 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700733
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
735 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
736
737 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
738 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
739 irda_qos_bits_to_value(&self->qos);
740}
741
742/*
743 * Function smsc_ircc_init_chip(self)
744 *
745 * Init chip
746 *
747 */
748static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
749{
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800750 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
752 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700753 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
754 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755
756 register_bank(iobase, 1);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800757 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700758 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759
760#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700761 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
762 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700763#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700764 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
765 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700766#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700767 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
768 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 register_bank(iobase, 4);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800771 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700772
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 register_bank(iobase, 0);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800774 outb(0, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775
776 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700777
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700779 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780}
781
782/*
783 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
784 *
785 * Process IOCTL commands for this device
786 *
787 */
788static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
789{
790 struct if_irda_req *irq = (struct if_irda_req *) rq;
791 struct smsc_ircc_cb *self;
792 unsigned long flags;
793 int ret = 0;
794
795 IRDA_ASSERT(dev != NULL, return -1;);
796
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700797 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 IRDA_ASSERT(self != NULL, return -1;);
800
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700801 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700802
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 switch (cmd) {
804 case SIOCSBANDWIDTH: /* Set bandwidth */
805 if (!capable(CAP_NET_ADMIN))
806 ret = -EPERM;
807 else {
808 /* Make sure we are the only one touching
809 * self->io.speed and the hardware - Jean II */
810 spin_lock_irqsave(&self->lock, flags);
811 smsc_ircc_change_speed(self, irq->ifr_baudrate);
812 spin_unlock_irqrestore(&self->lock, flags);
813 }
814 break;
815 case SIOCSMEDIABUSY: /* Set media busy */
816 if (!capable(CAP_NET_ADMIN)) {
817 ret = -EPERM;
818 break;
819 }
820
821 irda_device_set_media_busy(self->netdev, TRUE);
822 break;
823 case SIOCGRECEIVING: /* Check if we are receiving right now */
824 irq->ifr_receiving = smsc_ircc_is_receiving(self);
825 break;
826 #if 0
827 case SIOCSDTRRTS:
828 if (!capable(CAP_NET_ADMIN)) {
829 ret = -EPERM;
830 break;
831 }
832 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
833 break;
834 #endif
835 default:
836 ret = -EOPNOTSUPP;
837 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 return ret;
840}
841
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842#if SMSC_IRCC2_C_NET_TIMEOUT
843/*
844 * Function smsc_ircc_timeout (struct net_device *dev)
845 *
846 * The networking timeout management.
847 *
848 */
849
850static void smsc_ircc_timeout(struct net_device *dev)
851{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700852 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 unsigned long flags;
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
856 dev->name, self->io.speed);
857 spin_lock_irqsave(&self->lock, flags);
858 smsc_ircc_sir_start(self);
859 smsc_ircc_change_speed(self, self->io.speed);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700860 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 netif_wake_queue(dev);
862 spin_unlock_irqrestore(&self->lock, flags);
863}
864#endif
865
866/*
867 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
868 *
869 * Transmits the current frame until FIFO is full, then
870 * waits until the next transmit interrupt, and continues until the
871 * frame is transmitted.
872 */
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000873static netdev_tx_t smsc_ircc_hard_xmit_sir(struct sk_buff *skb,
874 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875{
876 struct smsc_ircc_cb *self;
877 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878 s32 speed;
879
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700880 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Patrick McHardyec634fe2009-07-05 19:23:38 -0700882 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700883
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700884 self = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700885 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 /* Make sure test of self->io.speed & speed change are atomic */
890 spin_lock_irqsave(&self->lock, flags);
891
892 /* Check if we need to change the speed */
893 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700894 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 /* Check for empty frame */
896 if (!skb->len) {
897 /*
898 * We send frames one by one in SIR mode (no
899 * pipelining), so at this point, if we were sending
900 * a previous frame, we just received the interrupt
901 * telling us it is finished (UART_IIR_THRI).
902 * Therefore, waiting for the transmitter to really
903 * finish draining the fifo won't take too long.
904 * And the interrupt handler is not expected to run.
905 * - Jean II */
906 smsc_ircc_sir_wait_hw_transmitter_finish(self);
907 smsc_ircc_change_speed(self, speed);
908 spin_unlock_irqrestore(&self->lock, flags);
909 dev_kfree_skb(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700910 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700912 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
914
915 /* Init tx buffer */
916 self->tx_buff.data = self->tx_buff.head;
917
918 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700919 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700921
Stephen Hemmingeraf049082009-01-06 10:40:43 -0800922 dev->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700925 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 spin_unlock_irqrestore(&self->lock, flags);
928
929 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700930
Patrick McHardyec634fe2009-07-05 19:23:38 -0700931 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932}
933
934/*
935 * Function smsc_ircc_set_fir_speed (self, baud)
936 *
937 * Change the speed of the device
938 *
939 */
940static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
941{
942 int fir_base, ir_mode, ctrl, fast;
943
944 IRDA_ASSERT(self != NULL, return;);
945 fir_base = self->io.fir_base;
946
947 self->io.speed = speed;
948
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700949 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700951 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 ir_mode = IRCC_CFGA_IRDA_HDLC;
953 ctrl = IRCC_CRC;
954 fast = 0;
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700955 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 break;
957 case 1152000:
958 ir_mode = IRCC_CFGA_IRDA_HDLC;
959 ctrl = IRCC_1152 | IRCC_CRC;
960 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
961 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700962 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 break;
964 case 4000000:
965 ir_mode = IRCC_CFGA_IRDA_4PPM;
966 ctrl = IRCC_CRC;
967 fast = IRCC_LCR_A_FAST;
968 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700969 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 break;
971 }
972 #if 0
973 Now in tranceiver!
974 /* This causes an interrupt */
975 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700976 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700978
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700980 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 -0700981
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700983 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984}
985
986/*
987 * Function smsc_ircc_fir_start(self)
988 *
989 * Change the speed of the device
990 *
991 */
992static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
993{
994 struct net_device *dev;
995 int fir_base;
996
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700997 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
999 IRDA_ASSERT(self != NULL, return;);
1000 dev = self->netdev;
1001 IRDA_ASSERT(dev != NULL, return;);
1002
1003 fir_base = self->io.fir_base;
1004
1005 /* Reset everything */
1006
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001008 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009
1010 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001011 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
1013 register_bank(fir_base, 1);
1014
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001015 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001017 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
1018 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001019#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001020 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
1021 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001022#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001023 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024
1025 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001026 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001028 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
1029 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030}
1031
1032/*
1033 * Function smsc_ircc_fir_stop(self, baud)
1034 *
1035 * Change the speed of the device
1036 *
1037 */
1038static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
1039{
1040 int fir_base;
1041
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001042 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001043
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044 IRDA_ASSERT(self != NULL, return;);
1045
1046 fir_base = self->io.fir_base;
1047 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001048 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1049 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050}
1051
1052
1053/*
1054 * Function smsc_ircc_change_speed(self, baud)
1055 *
1056 * Change the speed of the device
1057 *
1058 * This function *must* be called with spinlock held, because it may
1059 * be called from the irq handler. - Jean II
1060 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -07001061static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001065
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001066 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 IRDA_ASSERT(self != NULL, return;);
1069 dev = self->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1072
1073 #if 0
1074 /* Temp Hack */
1075 speed= 1152000;
1076 self->io.speed = speed;
1077 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001078 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001080
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001081 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 smsc_ircc_sir_start(self);
1083
1084 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001085 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 #endif
1087
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001088 if (self->io.speed != speed)
1089 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001090
1091 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001092
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001093 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1094 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 smsc_ircc_fir_stop(self);
1096 smsc_ircc_sir_start(self);
1097 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001098 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001099 } else {
1100 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001101 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 smsc_ircc_sir_stop(self);
1103 #endif
1104 smsc_ircc_fir_start(self);
1105 }
1106 smsc_ircc_set_fir_speed(self, speed);
1107
1108 #if 0
1109 self->tx_buff.len = 10;
1110 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001111
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001112 smsc_ircc_dma_xmit(self, 4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113 #endif
1114 /* Be ready for incoming frames */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001115 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001117
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 netif_wake_queue(dev);
1119}
1120
1121/*
1122 * Function smsc_ircc_set_sir_speed (self, speed)
1123 *
1124 * Set speed of IrDA port to specified baudrate
1125 *
1126 */
Hannes Eder0e49e642008-12-26 00:03:19 -08001127static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001129 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 int fcr; /* FIFO control reg */
1131 int lcr; /* Line control reg */
1132 int divisor;
1133
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001134 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
1136 IRDA_ASSERT(self != NULL, return;);
1137 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 /* Update accounting for new speed */
1140 self->io.speed = speed;
1141
1142 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001143 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001145 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 fcr = UART_FCR_ENABLE_FIFO;
1148
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001149 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1151 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001152 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001154 fcr |= self->io.speed < 38400 ?
1155 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001156
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 /* IrDA ports use 8N1 */
1158 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001159
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001160 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1161 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1162 outb(divisor >> 8, iobase + UART_DLM);
1163 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1164 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
1166 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001167 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001169 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170}
1171
1172
1173/*
1174 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1175 *
1176 * Transmit the frame!
1177 *
1178 */
Stephen Hemminger6518bbb2009-08-31 19:50:50 +00001179static netdev_tx_t smsc_ircc_hard_xmit_fir(struct sk_buff *skb,
1180 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
1182 struct smsc_ircc_cb *self;
1183 unsigned long flags;
1184 s32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 int mtt;
1186
Patrick McHardyec634fe2009-07-05 19:23:38 -07001187 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001188 self = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001189 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 netif_stop_queue(dev);
1192
1193 /* Make sure test of self->io.speed & speed change are atomic */
1194 spin_lock_irqsave(&self->lock, flags);
1195
1196 /* Check if we need to change the speed after this frame */
1197 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001198 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 /* Check for empty frame */
1200 if (!skb->len) {
1201 /* Note : you should make sure that speed changes
1202 * are not going to corrupt any outgoing frame.
1203 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001204 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 spin_unlock_irqrestore(&self->lock, flags);
1206 dev_kfree_skb(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001207 return NETDEV_TX_OK;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001208 }
1209
1210 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001212
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001213 skb_copy_from_linear_data(skb, self->tx_buff.head, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214
1215 self->tx_buff.len = skb->len;
1216 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001217
1218 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219 if (mtt) {
1220 int bofs;
1221
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001222 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 * Compute how many BOFs (STA or PA's) we need to waste the
1224 * min turn time given the speed of the link.
1225 */
1226 bofs = mtt * (self->io.speed / 1000) / 8000;
1227 if (bofs > 4095)
1228 bofs = 4095;
1229
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001230 smsc_ircc_dma_xmit(self, bofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001231 } else {
1232 /* Transmit frame */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001233 smsc_ircc_dma_xmit(self, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 spin_unlock_irqrestore(&self->lock, flags);
1237 dev_kfree_skb(skb);
1238
Patrick McHardyec634fe2009-07-05 19:23:38 -07001239 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240}
1241
1242/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001243 * Function smsc_ircc_dma_xmit (self, bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 *
1245 * Transmit data using DMA
1246 *
1247 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001248static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001250 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 u8 ctrl;
1252
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001253 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254#if 1
1255 /* Disable Rx */
1256 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001257 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258#endif
1259 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001260 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1261 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 self->io.direction = IO_XMIT;
1264
1265 /* Set BOF additional count for generating the min turn time */
1266 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001267 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1268 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1269 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001272 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1273 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274
1275 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001276
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 /* Enable burst mode chip Tx DMA */
1278 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001279 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1280 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 /* Setup DMA controller (must be done after enabling chip DMA) */
1283 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1284 DMA_TX_MODE);
1285
1286 /* Enable interrupt */
1287
1288 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001289 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1290 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001291
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001293 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294}
1295
1296/*
1297 * Function smsc_ircc_dma_xmit_complete (self)
1298 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001299 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 * by the interrupt handler
1301 *
1302 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001303static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001305 int iobase = self->io.fir_base;
1306
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001307 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308#if 0
1309 /* Disable Tx */
1310 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001311 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312#endif
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001313 register_bank(iobase, 1);
1314 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1315 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316
1317 /* Check for underrun! */
1318 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001319 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001320 self->netdev->stats.tx_errors++;
1321 self->netdev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 /* Reset error condition */
1324 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001325 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1326 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 } else {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001328 self->netdev->stats.tx_packets++;
1329 self->netdev->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331
1332 /* Check if it's time to change the speed */
1333 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001334 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 self->new_speed = 0;
1336 }
1337
1338 netif_wake_queue(self->netdev);
1339}
1340
1341/*
1342 * Function smsc_ircc_dma_receive(self)
1343 *
1344 * Get ready for receiving a frame. The device will initiate a DMA
1345 * if it starts to receive a frame.
1346 *
1347 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001348static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001350 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351#if 0
1352 /* Turn off chip DMA */
1353 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001354 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1355 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 /* Disable Tx */
1359 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001360 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361
1362 /* Turn off chip DMA */
1363 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001364 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1365 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366
1367 self->io.direction = IO_RECV;
1368 self->rx_buff.data = self->rx_buff.head;
1369
1370 /* Set max Rx frame size */
1371 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001372 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1373 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374
1375 /* Setup DMA controller */
1376 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1377 DMA_RX_MODE);
1378
1379 /* Enable burst mode chip Rx DMA */
1380 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001381 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1382 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
1384 /* Enable interrupt */
1385 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001386 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1387 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 /* Enable receiver */
1390 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001391 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001392 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001393
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 return 0;
1395}
1396
1397/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001398 * Function smsc_ircc_dma_receive_complete(self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 *
1400 * Finished with receiving frames
1401 *
1402 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001403static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404{
1405 struct sk_buff *skb;
1406 int len, msgcnt, lsr;
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001407 int iobase = self->io.fir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001408
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001410
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001411 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412#if 0
1413 /* Disable Rx */
1414 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001415 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416#endif
1417 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001418 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1419 lsr= inb(iobase + IRCC_LSR);
1420 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001422 IRDA_DEBUG(2, "%s: dma count = %d\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 get_dma_residue(self->io.dma));
1424
1425 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1426
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001427 /* Look for errors */
1428 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001429 self->netdev->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001430 if (lsr & IRCC_LSR_FRAME_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001431 self->netdev->stats.rx_frame_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001432 if (lsr & IRCC_LSR_CRC_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001433 self->netdev->stats.rx_crc_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001434 if (lsr & IRCC_LSR_SIZE_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001435 self->netdev->stats.rx_length_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001436 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001437 self->netdev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 return;
1439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001441 /* Remove CRC */
1442 len -= self->io.speed < 4000000 ? 2 : 4;
1443
1444 if (len < 2 || len > 2050) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001445 IRDA_WARNING("%s(), bogus len=%d\n", __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 return;
1447 }
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001448 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __func__, msgcnt, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001450 skb = dev_alloc_skb(len + 1);
1451 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001453 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001457 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
1459 memcpy(skb_put(skb, len), self->rx_buff.data, len);
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001460 self->netdev->stats.rx_packets++;
1461 self->netdev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
1463 skb->dev = self->netdev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001464 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 skb->protocol = htons(ETH_P_IRDA);
1466 netif_rx(skb);
1467}
1468
1469/*
1470 * Function smsc_ircc_sir_receive (self)
1471 *
1472 * Receive one frame from the infrared port
1473 *
1474 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001475static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476{
1477 int boguscount = 0;
1478 int iobase;
1479
1480 IRDA_ASSERT(self != NULL, return;);
1481
1482 iobase = self->io.sir_base;
1483
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001484 /*
1485 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1486 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 */
1488 do {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001489 async_unwrap_char(self->netdev, &self->netdev->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001490 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492 /* Make sure we don't stay here to long */
1493 if (boguscount++ > 32) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001494 IRDA_DEBUG(2, "%s(), breaking!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 break;
1496 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001497 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498}
1499
1500
1501/*
1502 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1503 *
1504 * An interrupt from the chip has arrived. Time to do some work
1505 *
1506 */
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001507static irqreturn_t smsc_ircc_interrupt(int dummy, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508{
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001509 struct net_device *dev = dev_id;
1510 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 int iobase, iir, lcra, lsr;
1512 irqreturn_t ret = IRQ_NONE;
1513
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001515 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516
1517 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001518 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 ret = smsc_ircc_interrupt_sir(dev);
1520 goto irq_ret_unlock;
1521 }
1522
1523 iobase = self->io.fir_base;
1524
1525 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001526 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001527 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 goto irq_ret_unlock;
1529 ret = IRQ_HANDLED;
1530
1531 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001532 outb(0, iobase + IRCC_IER);
1533 lcra = inb(iobase + IRCC_LCR_A);
1534 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001535
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001536 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __func__, iir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 if (iir & IRCC_IIR_EOM) {
1539 if (self->io.direction == IO_RECV)
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001540 smsc_ircc_dma_receive_complete(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 else
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001542 smsc_ircc_dma_xmit_complete(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001543
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001544 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 }
1546
1547 if (iir & IRCC_IIR_ACTIVE_FRAME) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001548 /*printk(KERN_WARNING "%s(): Active Frame\n", __func__);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 }
1550
1551 /* Enable interrupts again */
1552
1553 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001554 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
1556 irq_ret_unlock:
1557 spin_unlock(&self->lock);
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001558
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 return ret;
1560}
1561
1562/*
David Howells7d12e782006-10-05 14:55:46 +01001563 * Function irport_interrupt_sir (irq, dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 *
1565 * Interrupt handler for SIR modes
1566 */
1567static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1568{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001569 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 int boguscount = 0;
1571 int iobase;
1572 int iir, lsr;
1573
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001574 /* Already locked coming here in smsc_ircc_interrupt() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 /*spin_lock(&self->lock);*/
1576
1577 iobase = self->io.sir_base;
1578
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001579 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580 if (iir == 0)
1581 return IRQ_NONE;
1582 while (iir) {
1583 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001584 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001586 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001587 __func__, iir, lsr, iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588
1589 switch (iir) {
1590 case UART_IIR_RLSI:
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001591 IRDA_DEBUG(2, "%s(), RLSI\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 break;
1593 case UART_IIR_RDI:
1594 /* Receive interrupt */
1595 smsc_ircc_sir_receive(self);
1596 break;
1597 case UART_IIR_THRI:
1598 if (lsr & UART_LSR_THRE)
1599 /* Transmitter ready for data */
1600 smsc_ircc_sir_write_wakeup(self);
1601 break;
1602 default:
1603 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001604 __func__, iir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001606 }
1607
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 /* Make sure we don't stay here to long */
1609 if (boguscount++ > 100)
1610 break;
1611
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001612 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 }
1614 /*spin_unlock(&self->lock);*/
1615 return IRQ_HANDLED;
1616}
1617
1618
1619#if 0 /* unused */
1620/*
1621 * Function ircc_is_receiving (self)
1622 *
1623 * Return TRUE is we are currently receiving a frame
1624 *
1625 */
1626static int ircc_is_receiving(struct smsc_ircc_cb *self)
1627{
1628 int status = FALSE;
1629 /* int iobase; */
1630
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001631 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
1633 IRDA_ASSERT(self != NULL, return FALSE;);
1634
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001635 IRDA_DEBUG(0, "%s: dma count = %d\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 get_dma_residue(self->io.dma));
1637
1638 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001639
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640 return status;
1641}
1642#endif /* unused */
1643
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001644static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1645{
1646 int error;
1647
1648 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1649 self->netdev->name, self->netdev);
1650 if (error)
1651 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001652 __func__, self->io.irq, error);
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001653
1654 return error;
1655}
1656
1657static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1658{
1659 unsigned long flags;
1660
1661 spin_lock_irqsave(&self->lock, flags);
1662
1663 self->io.speed = 0;
1664 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1665
1666 spin_unlock_irqrestore(&self->lock, flags);
1667}
1668
1669static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1670{
1671 int iobase = self->io.fir_base;
1672 unsigned long flags;
1673
1674 spin_lock_irqsave(&self->lock, flags);
1675
1676 register_bank(iobase, 0);
1677 outb(0, iobase + IRCC_IER);
1678 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1679 outb(0x00, iobase + IRCC_MASTER);
1680
1681 spin_unlock_irqrestore(&self->lock, flags);
1682}
1683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
1685/*
1686 * Function smsc_ircc_net_open (dev)
1687 *
1688 * Start the device
1689 *
1690 */
1691static int smsc_ircc_net_open(struct net_device *dev)
1692{
1693 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 char hwname[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001696 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001697
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001699 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001701
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001702 if (self->io.suspended) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001703 IRDA_DEBUG(0, "%s(), device is suspended\n", __func__);
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001704 return -EAGAIN;
1705 }
1706
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001707 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 (void *) dev)) {
1709 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001710 __func__, self->io.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 return -EAGAIN;
1712 }
1713
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001714 smsc_ircc_start_interrupts(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001715
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716 /* Give self a hardware name */
1717 /* It would be cool to offer the chip revision here - Jean II */
1718 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1719
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001720 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001722 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 */
1724 self->irlap = irlap_open(dev, &self->qos, hwname);
1725
1726 /*
1727 * Always allocate the DMA channel after the IRQ,
1728 * and clean up on failure.
1729 */
1730 if (request_dma(self->io.dma, dev->name)) {
1731 smsc_ircc_net_close(dev);
1732
1733 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001734 __func__, self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 return -EAGAIN;
1736 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001737
Linus Torvalds1da177e2005-04-16 15:20:36 -07001738 netif_start_queue(dev);
1739
1740 return 0;
1741}
1742
1743/*
1744 * Function smsc_ircc_net_close (dev)
1745 *
1746 * Stop the device
1747 *
1748 */
1749static int smsc_ircc_net_close(struct net_device *dev)
1750{
1751 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001753 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001754
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001756 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 /* Stop device */
1760 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001761
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762 /* Stop and remove instance of IrLAP */
1763 if (self->irlap)
1764 irlap_close(self->irlap);
1765 self->irlap = NULL;
1766
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001767 smsc_ircc_stop_interrupts(self);
1768
1769 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1770 if (!self->io.suspended)
1771 free_irq(self->io.irq, dev);
1772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 free_dma(self->io.dma);
1775
1776 return 0;
1777}
1778
Russell King3ae5eae2005-11-09 22:32:44 +00001779static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Russell King3ae5eae2005-11-09 22:32:44 +00001781 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001782
Russell King9480e302005-10-28 09:52:56 -07001783 if (!self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001784 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1785
1786 rtnl_lock();
1787 if (netif_running(self->netdev)) {
1788 netif_device_detach(self->netdev);
1789 smsc_ircc_stop_interrupts(self);
1790 free_irq(self->io.irq, self->netdev);
1791 disable_dma(self->io.dma);
1792 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001793 self->io.suspended = 1;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001794 rtnl_unlock();
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001795 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001796
1797 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798}
1799
Russell King3ae5eae2005-11-09 22:32:44 +00001800static int smsc_ircc_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801{
Russell King3ae5eae2005-11-09 22:32:44 +00001802 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
Russell King9480e302005-10-28 09:52:56 -07001804 if (self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001805 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001807 rtnl_lock();
1808 smsc_ircc_init_chip(self);
1809 if (netif_running(self->netdev)) {
1810 if (smsc_ircc_request_irq(self)) {
1811 /*
1812 * Don't fail resume process, just kill this
1813 * network interface
1814 */
1815 unregister_netdevice(self->netdev);
1816 } else {
1817 enable_dma(self->io.dma);
1818 smsc_ircc_start_interrupts(self);
1819 netif_device_attach(self->netdev);
1820 }
1821 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001822 self->io.suspended = 0;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001823 rtnl_unlock();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825 return 0;
1826}
1827
1828/*
1829 * Function smsc_ircc_close (self)
1830 *
1831 * Close driver instance
1832 *
1833 */
1834static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1835{
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001836 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838 IRDA_ASSERT(self != NULL, return -1;);
1839
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001840 platform_device_unregister(self->pldev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 /* Remove netdevice */
1843 unregister_netdev(self->netdev);
1844
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001845 smsc_ircc_stop_interrupts(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846
1847 /* Release the PORTS that this driver is using */
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001848 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 self->io.fir_base);
1850
1851 release_region(self->io.fir_base, self->io.fir_ext);
1852
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.sir_base);
1855
1856 release_region(self->io.sir_base, self->io.sir_ext);
1857
1858 if (self->tx_buff.head)
1859 dma_free_coherent(NULL, self->tx_buff.truesize,
1860 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001861
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 if (self->rx_buff.head)
1863 dma_free_coherent(NULL, self->rx_buff.truesize,
1864 self->rx_buff.head, self->rx_buff_dma);
1865
1866 free_netdev(self->netdev);
1867
1868 return 0;
1869}
1870
1871static void __exit smsc_ircc_cleanup(void)
1872{
1873 int i;
1874
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001875 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001877 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 if (dev_self[i])
1879 smsc_ircc_close(dev_self[i]);
1880 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001881
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -07001882 if (pnp_driver_registered)
1883 pnp_unregister_driver(&smsc_ircc_pnp_driver);
1884
Russell King3ae5eae2005-11-09 22:32:44 +00001885 platform_driver_unregister(&smsc_ircc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886}
1887
1888/*
1889 * Start SIR operations
1890 *
1891 * This function *must* be called with spinlock held, because it may
1892 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1893 */
Hannes Eder0e49e642008-12-26 00:03:19 -08001894static void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895{
1896 struct net_device *dev;
1897 int fir_base, sir_base;
1898
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001899 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001901 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001902 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001903 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
1905 fir_base = self->io.fir_base;
1906 sir_base = self->io.sir_base;
1907
1908 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001909 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
1911 #if SMSC_IRCC2_C_SIR_STOP
1912 /*smsc_ircc_sir_stop(self);*/
1913 #endif
1914
1915 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001916 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 -07001917
1918 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001919 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1920 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001921
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001923 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001925 IRDA_DEBUG(3, "%s() - exit\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001927 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928}
1929
1930#if SMSC_IRCC2_C_SIR_STOP
1931void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1932{
1933 int iobase;
1934
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001935 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 iobase = self->io.sir_base;
1937
1938 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001939 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001940
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001942 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943}
1944#endif
1945
1946/*
1947 * Function smsc_sir_write_wakeup (self)
1948 *
1949 * Called by the SIR interrupt handler when there's room for more data.
1950 * If we have more packets to send, we send them here.
1951 *
1952 */
1953static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1954{
1955 int actual = 0;
1956 int iobase;
1957 int fcr;
1958
1959 IRDA_ASSERT(self != NULL, return;);
1960
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001961 IRDA_DEBUG(4, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962
1963 iobase = self->io.sir_base;
1964
1965 /* Finished with frame? */
1966 if (self->tx_buff.len > 0) {
1967 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001968 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 self->tx_buff.data, self->tx_buff.len);
1970 self->tx_buff.data += actual;
1971 self->tx_buff.len -= actual;
1972 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001973
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001975
1976 /*
1977 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 * transmission of another packet. But first we must check
1979 * if we need to change the speed of the hardware
1980 */
1981 if (self->new_speed) {
1982 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001983 __func__, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1985 smsc_ircc_change_speed(self, self->new_speed);
1986 self->new_speed = 0;
1987 } else {
1988 /* Tell network layer that we want more frames */
1989 netif_wake_queue(self->netdev);
1990 }
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001991 self->netdev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001993 if (self->io.speed <= 115200) {
1994 /*
1995 * Reset Rx FIFO to make sure that all reflected transmit data
1996 * is discarded. This is needed for half duplex operation
1997 */
1998 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
1999 fcr |= self->io.speed < 38400 ?
2000 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002002 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002004 /* Turn on receive interrupts */
2005 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006 }
2007 }
2008}
2009
2010/*
2011 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
2012 *
2013 * Fill Tx FIFO with transmit data
2014 *
2015 */
2016static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
2017{
2018 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002019
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002021 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002022 IRDA_WARNING("%s(), failed, fifo not empty!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 return 0;
2024 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002027 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002029 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 actual++;
2031 }
2032 return actual;
2033}
2034
2035/*
2036 * Function smsc_ircc_is_receiving (self)
2037 *
2038 * Returns true is we are currently receiving data
2039 *
2040 */
2041static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
2042{
Eric Dumazet807540b2010-09-23 05:40:09 +00002043 return self->rx_buff.state != OUTSIDE_FRAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044}
2045
2046
2047/*
2048 * Function smsc_ircc_probe_transceiver(self)
2049 *
2050 * Tries to find the used Transceiver
2051 *
2052 */
2053static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2054{
2055 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002056
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002058
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002059 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2060 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 IRDA_MESSAGE(" %s transceiver found\n",
2062 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002063 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 return;
2065 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2068 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002069
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002070 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071}
2072
2073
2074/*
2075 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2076 *
2077 * Set the transceiver according to the speed
2078 *
2079 */
2080static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2081{
2082 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002083
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002085 if (trx > 0)
2086 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
2089/*
2090 * Function smsc_ircc_wait_hw_transmitter_finish ()
2091 *
2092 * Wait for the real end of HW transmission
2093 *
2094 * The UART is a strict FIFO, and we get called only when we have finished
2095 * pushing data to the FIFO, so the maximum amount of time we must wait
2096 * is only for the FIFO to drain out.
2097 *
2098 * We use a simple calibrated loop. We may need to adjust the loop
2099 * delay (udelay) to balance I/O traffic and latency. And we also need to
2100 * adjust the maximum timeout.
2101 * It would probably be better to wait for the proper interrupt,
2102 * but it doesn't seem to be available.
2103 *
2104 * We can't use jiffies or kernel timers because :
2105 * 1) We are called from the interrupt handler, which disable softirqs,
2106 * so jiffies won't be increased
2107 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2108 * want to wait that long to detect stuck hardware.
2109 * Jean II
2110 */
2111
2112static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2113{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002114 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002116
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002118 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 udelay(1);
2120
Roel Kluinadbf7f02009-06-05 12:54:44 +02002121 if (count < 0)
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002122 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123}
2124
2125
2126/* PROBING
2127 *
David Brownelld94c77b2006-05-09 15:26:11 -07002128 * REVISIT we can be told about the device by PNP, and should use that info
2129 * instead of probing hardware and creating a platform_device ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 */
2131
2132static int __init smsc_ircc_look_for_chips(void)
2133{
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002134 struct smsc_chip_address *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002135 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002137
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 found = 0;
2139 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002140
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002141 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002143
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002144 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __func__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002145
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002146 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002148 if (address->type & SMSCSIO_TYPE_FLAT)
2149 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2150 found++;
2151
2152 if (address->type & SMSCSIO_TYPE_PAGED)
2153 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2154 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002156 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002158 if (address->type & SMSCSIO_TYPE_FLAT)
2159 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2160 found++;
2161
2162 if (address->type & SMSCSIO_TYPE_PAGED)
2163 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2164 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 }
2166 address++;
2167 }
2168 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002169}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
2171/*
2172 * Function smsc_superio_flat (chip, base, type)
2173 *
2174 * Try to get configuration of a smc SuperIO chip with flat register model
2175 *
2176 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002177static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 unsigned short firbase, sirbase;
2180 u8 mode, dma, irq;
2181 int ret = -ENODEV;
2182
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002183 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002185 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 return ret;
2187
2188 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002189 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002190
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002191 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __func__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002192
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002193 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002194 IRDA_WARNING("%s(): IrDA not enabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002197 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002199 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002201 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203 /* DMA */
2204 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002205 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 /* IRQ */
2208 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002209 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002211 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 -07002212
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002213 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2214 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002215
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 /* Exit configuration */
2217 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2218
2219 return ret;
2220}
2221
2222/*
2223 * Function smsc_superio_paged (chip, base, type)
2224 *
2225 * Try to get configuration of a smc SuperIO chip with paged register model
2226 *
2227 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002228static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229{
2230 unsigned short fir_io, sir_io;
2231 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002232
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002233 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002235 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002237
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 /* Select logical device (UART2) */
2239 outb(0x07, cfg_base);
2240 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 /* SIR iobase */
2243 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002244 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 outb(0x61, cfg_base);
2246 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002247
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 /* Read FIR base */
2249 outb(0x62, cfg_base);
2250 fir_io = inb(cfg_base + 1) << 8;
2251 outb(0x63, cfg_base);
2252 fir_io |= inb(cfg_base + 1);
2253 outb(0x2b, cfg_base); /* ??? */
2254
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002255 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2256 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002257
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 /* Exit configuration */
2259 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2260
2261 return ret;
2262}
2263
2264
David S. Miller948252c2011-05-31 19:27:48 -07002265static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266{
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002267 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002270 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271}
2272
David S. Miller948252c2011-05-31 19:27:48 -07002273static 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 -07002274{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002275 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002277 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
2279 /* Leave configuration */
2280
2281 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2282
2283 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2284 return NULL;
2285
2286 outb(reg, cfg_base);
2287
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002288 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
2290 /* Enter configuration */
2291
2292 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2293
2294 #if 0
2295 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2296 return NULL;
2297 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002298
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 /* probe device ID */
2300
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002301 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 return NULL;
2303
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002304 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002305
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002306 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 return NULL;
2308
2309 /* probe revision ID */
2310
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002311 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 return NULL;
2313
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002314 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002316 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 return NULL;
2318
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002319 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 return NULL;
2321
2322 /* Check for expected device ID; are there others? */
2323
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002324 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325
2326 chip++;
2327
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002328 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 return NULL;
2330 }
2331
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002332 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2333 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002335 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002336 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 return NULL;
2338 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002339
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002340 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 IRDA_MESSAGE("chipset does not support IRDA\n");
2342
2343 return chip;
2344}
2345
2346static int __init smsc_superio_fdc(unsigned short cfg_base)
2347{
2348 int ret = -1;
2349
2350 if (!request_region(cfg_base, 2, driver_name)) {
2351 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002352 __func__, cfg_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002354 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2355 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 ret = 0;
2357
2358 release_region(cfg_base, 2);
2359 }
2360
2361 return ret;
2362}
2363
2364static int __init smsc_superio_lpc(unsigned short cfg_base)
2365{
2366 int ret = -1;
2367
2368 if (!request_region(cfg_base, 2, driver_name)) {
2369 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002370 __func__, cfg_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002372 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2373 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002375
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 release_region(cfg_base, 2);
2377 }
2378 return ret;
2379}
2380
Linus Walleijc1e14a62006-04-05 22:33:59 -07002381/*
2382 * Look for some specific subsystem setups that need
2383 * pre-configuration not properly done by the BIOS (especially laptops)
2384 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2385 * and tosh2450-smcinit.c. The table lists the device entries
Linus Walleij08d09992006-04-14 16:03:33 -07002386 * for ISA bridges with an LPC (Low Pin Count) controller which
2387 * handles the communication with the SMSC device. After the LPC
2388 * controller is initialized through PCI, the SMSC device is initialized
2389 * through a dedicated port in the ISA port-mapped I/O area, this latter
2390 * area is used to configure the SMSC device with default
2391 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2392 * used different sets of parameters and different control port
2393 * addresses making a subsystem device table necessary.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002394 */
2395#ifdef CONFIG_PCI
David S. Miller948252c2011-05-31 19:27:48 -07002396static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002397 /*
2398 * Subsystems needing entries:
2399 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2400 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2401 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2402 */
2403 {
2404 /* Guessed entry */
Jon Mason5ee5a072011-08-03 06:42:42 +00002405 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002406 .device = 0x24cc,
2407 .subvendor = 0x103c,
2408 .subdevice = 0x08bc,
2409 .sir_io = 0x02f8,
2410 .fir_io = 0x0130,
2411 .fir_irq = 0x05,
2412 .fir_dma = 0x03,
2413 .cfg_base = 0x004e,
2414 .preconfigure = preconfigure_through_82801,
2415 .name = "HP nx5000 family",
2416 },
Linus Walleijc1e14a62006-04-05 22:33:59 -07002417 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002418 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002419 .device = 0x24cc,
2420 .subvendor = 0x103c,
2421 .subdevice = 0x088c,
Linus Walleij08d09992006-04-14 16:03:33 -07002422 /* Quite certain these are the same for nc8000 as for nc6000 */
2423 .sir_io = 0x02f8,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002424 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002425 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002426 .fir_dma = 0x03,
2427 .cfg_base = 0x004e,
2428 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002429 .name = "HP nc8000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002430 },
2431 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002432 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002433 .device = 0x24cc,
2434 .subvendor = 0x103c,
2435 .subdevice = 0x0890,
2436 .sir_io = 0x02f8,
2437 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002438 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002439 .fir_dma = 0x03,
2440 .cfg_base = 0x004e,
2441 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002442 .name = "HP nc6000 family",
2443 },
2444 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002445 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002446 .device = 0x24cc,
2447 .subvendor = 0x0e11,
2448 .subdevice = 0x0860,
2449 /* I assume these are the same for x1000 as for the others */
2450 .sir_io = 0x02e8,
2451 .fir_io = 0x02f8,
2452 .fir_irq = 0x07,
2453 .fir_dma = 0x03,
2454 .cfg_base = 0x002e,
2455 .preconfigure = preconfigure_through_82801,
2456 .name = "Compaq x1000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002457 },
2458 {
Linus Walleij08d09992006-04-14 16:03:33 -07002459 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
Jon Mason5ee5a072011-08-03 06:42:42 +00002460 .vendor = PCI_VENDOR_ID_INTEL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002461 .device = 0x24c0,
2462 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002463 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002464 .sir_io = 0x03f8,
2465 .fir_io = 0x0130,
2466 .fir_irq = 0x07,
2467 .fir_dma = 0x01,
2468 .cfg_base = 0x002e,
2469 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002470 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002471 },
2472 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002473 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801CAM ISA bridge */
Linus Walleij08d09992006-04-14 16:03:33 -07002474 .device = 0x248c,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002475 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002476 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002477 .sir_io = 0x03f8,
2478 .fir_io = 0x0130,
2479 .fir_irq = 0x03,
2480 .fir_dma = 0x03,
2481 .cfg_base = 0x002e,
2482 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002483 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002484 },
2485 {
Linus Walleij08d09992006-04-14 16:03:33 -07002486 /* 82801DBM (ICH4-M) LPC Interface Bridge */
Jon Mason5ee5a072011-08-03 06:42:42 +00002487 .vendor = PCI_VENDOR_ID_INTEL,
Linus Walleij08d09992006-04-14 16:03:33 -07002488 .device = 0x24cc,
2489 .subvendor = 0x1179,
2490 .subdevice = 0xffff, /* 0xffff is "any" */
2491 .sir_io = 0x03f8,
2492 .fir_io = 0x0130,
2493 .fir_irq = 0x03,
2494 .fir_dma = 0x03,
2495 .cfg_base = 0x002e,
2496 .preconfigure = preconfigure_through_82801,
2497 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2498 },
2499 {
2500 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
Jon Mason5ee5a072011-08-03 06:42:42 +00002501 .vendor = PCI_VENDOR_ID_AL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002502 .device = 0x1533,
2503 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002504 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002505 .sir_io = 0x02e8,
2506 .fir_io = 0x02f8,
2507 .fir_irq = 0x07,
2508 .fir_dma = 0x03,
2509 .cfg_base = 0x002e,
2510 .preconfigure = preconfigure_through_ali,
Linus Walleij08d09992006-04-14 16:03:33 -07002511 .name = "Toshiba laptop with ALi ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002512 },
2513 { } // Terminator
2514};
2515
2516
2517/*
Linus Walleij08d09992006-04-14 16:03:33 -07002518 * This sets up the basic SMSC parameters
2519 * (FIR port, SIR port, FIR DMA, FIR IRQ)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002520 * through the chip configuration port.
2521 */
David S. Miller948252c2011-05-31 19:27:48 -07002522static int __init preconfigure_smsc_chip(struct
Linus Walleij08d09992006-04-14 16:03:33 -07002523 smsc_ircc_subsystem_configuration
2524 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002525{
2526 unsigned short iobase = conf->cfg_base;
2527 unsigned char tmpbyte;
2528
2529 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2530 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2531 tmpbyte = inb(iobase +1); // Read device ID
Linus Walleij08d09992006-04-14 16:03:33 -07002532 IRDA_DEBUG(0,
2533 "Detected Chip id: 0x%02x, setting up registers...\n",
2534 tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002535
2536 /* Disable UART1 and set up SIR I/O port */
2537 outb(0x24, iobase); // select CR24 - UART1 base addr
2538 outb(0x00, iobase + 1); // disable UART1
2539 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2540 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2541 tmpbyte = inb(iobase + 1);
2542 if (tmpbyte != (conf->sir_io >> 2) ) {
2543 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
Linus Walleij08d09992006-04-14 16:03:33 -07002544 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
Linus Walleijc1e14a62006-04-05 22:33:59 -07002545 return -ENXIO;
2546 }
2547
2548 /* Set up FIR IRQ channel for UART2 */
2549 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2550 tmpbyte = inb(iobase + 1);
2551 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2552 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2553 outb(tmpbyte, iobase + 1);
2554 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2555 if (tmpbyte != conf->fir_irq) {
2556 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2557 return -ENXIO;
2558 }
2559
2560 /* Set up FIR I/O port */
2561 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2562 outb((conf->fir_io >> 3), iobase + 1);
2563 tmpbyte = inb(iobase + 1);
2564 if (tmpbyte != (conf->fir_io >> 3) ) {
2565 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2566 return -ENXIO;
2567 }
2568
2569 /* Set up FIR DMA channel */
2570 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2571 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2572 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2573 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2574 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2575 return -ENXIO;
2576 }
2577
2578 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2579 tmpbyte = inb(iobase + 1);
Linus Walleij08d09992006-04-14 16:03:33 -07002580 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2581 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002582 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2583
2584 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2585 tmpbyte = inb(iobase + 1);
2586 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2587
2588 /* This one was not part of tosh1800 */
2589 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2590 tmpbyte = inb(iobase + 1);
2591 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2592
2593 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2594 tmpbyte = inb(iobase + 1);
2595 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2596
2597 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2598 tmpbyte = inb(iobase + 1);
2599 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2600
2601 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2602
2603 return 0;
2604}
2605
Linus Walleij08d09992006-04-14 16:03:33 -07002606/* 82801CAM generic registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002607#define VID 0x00
2608#define DID 0x02
Linus Walleij08d09992006-04-14 16:03:33 -07002609#define PIRQ_A_D_ROUT 0x60
2610#define SIRQ_CNTL 0x64
2611#define PIRQ_E_H_ROUT 0x68
Linus Walleijc1e14a62006-04-05 22:33:59 -07002612#define PCI_DMA_C 0x90
Linus Walleij08d09992006-04-14 16:03:33 -07002613/* LPC-specific registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002614#define COM_DEC 0xe0
Linus Walleij08d09992006-04-14 16:03:33 -07002615#define GEN1_DEC 0xe4
Linus Walleijc1e14a62006-04-05 22:33:59 -07002616#define LPC_EN 0xe6
2617#define GEN2_DEC 0xec
2618/*
Linus Walleij08d09992006-04-14 16:03:33 -07002619 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2620 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2621 * They all work the same way!
Linus Walleijc1e14a62006-04-05 22:33:59 -07002622 */
David S. Miller948252c2011-05-31 19:27:48 -07002623static int __init preconfigure_through_82801(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002624 struct
2625 smsc_ircc_subsystem_configuration
2626 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002627{
2628 unsigned short tmpword;
Linus Walleij08d09992006-04-14 16:03:33 -07002629 unsigned char tmpbyte;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002630
Linus Walleij08d09992006-04-14 16:03:33 -07002631 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2632 /*
2633 * Select the range for the COMA COM port (SIR)
2634 * Register COM_DEC:
2635 * Bit 7: reserved
2636 * Bit 6-4, COMB decode range
2637 * Bit 3: reserved
2638 * Bit 2-0, COMA decode range
2639 *
2640 * Decode ranges:
2641 * 000 = 0x3f8-0x3ff (COM1)
2642 * 001 = 0x2f8-0x2ff (COM2)
2643 * 010 = 0x220-0x227
2644 * 011 = 0x228-0x22f
2645 * 100 = 0x238-0x23f
2646 * 101 = 0x2e8-0x2ef (COM4)
2647 * 110 = 0x338-0x33f
2648 * 111 = 0x3e8-0x3ef (COM3)
2649 */
2650 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2651 tmpbyte &= 0xf8; /* mask COMA bits */
2652 switch(conf->sir_io) {
2653 case 0x3f8:
2654 tmpbyte |= 0x00;
2655 break;
2656 case 0x2f8:
2657 tmpbyte |= 0x01;
2658 break;
2659 case 0x220:
2660 tmpbyte |= 0x02;
2661 break;
2662 case 0x228:
2663 tmpbyte |= 0x03;
2664 break;
2665 case 0x238:
2666 tmpbyte |= 0x04;
2667 break;
2668 case 0x2e8:
2669 tmpbyte |= 0x05;
2670 break;
2671 case 0x338:
2672 tmpbyte |= 0x06;
2673 break;
2674 case 0x3e8:
2675 tmpbyte |= 0x07;
2676 break;
2677 default:
2678 tmpbyte |= 0x01; /* COM2 default */
2679 }
2680 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2681 pci_write_config_byte(dev, COM_DEC, tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002682
Linus Walleij08d09992006-04-14 16:03:33 -07002683 /* Enable Low Pin Count interface */
2684 pci_read_config_word(dev, LPC_EN, &tmpword);
2685 /* These seem to be set up at all times,
2686 * just make sure it is properly set.
2687 */
2688 switch(conf->cfg_base) {
2689 case 0x04e:
2690 tmpword |= 0x2000;
2691 break;
2692 case 0x02e:
2693 tmpword |= 0x1000;
2694 break;
2695 case 0x062:
2696 tmpword |= 0x0800;
2697 break;
2698 case 0x060:
2699 tmpword |= 0x0400;
2700 break;
2701 default:
2702 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2703 conf->cfg_base);
2704 break;
2705 }
2706 tmpword &= 0xfffd; /* disable LPC COMB */
2707 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2708 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002709 pci_write_config_word(dev, LPC_EN, tmpword);
2710
Linus Walleij08d09992006-04-14 16:03:33 -07002711 /*
2712 * Configure LPC DMA channel
2713 * PCI_DMA_C bits:
2714 * Bit 15-14: DMA channel 7 select
2715 * Bit 13-12: DMA channel 6 select
2716 * Bit 11-10: DMA channel 5 select
2717 * Bit 9-8: Reserved
2718 * Bit 7-6: DMA channel 3 select
2719 * Bit 5-4: DMA channel 2 select
2720 * Bit 3-2: DMA channel 1 select
2721 * Bit 1-0: DMA channel 0 select
2722 * 00 = Reserved value
2723 * 01 = PC/PCI DMA
2724 * 10 = Reserved value
2725 * 11 = LPC I/F DMA
2726 */
2727 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2728 switch(conf->fir_dma) {
2729 case 0x07:
2730 tmpword |= 0xc000;
2731 break;
2732 case 0x06:
2733 tmpword |= 0x3000;
2734 break;
2735 case 0x05:
2736 tmpword |= 0x0c00;
2737 break;
2738 case 0x03:
2739 tmpword |= 0x00c0;
2740 break;
2741 case 0x02:
2742 tmpword |= 0x0030;
2743 break;
2744 case 0x01:
2745 tmpword |= 0x000c;
2746 break;
2747 case 0x00:
2748 tmpword |= 0x0003;
2749 break;
2750 default:
2751 break; /* do not change settings */
2752 }
2753 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2754 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2755
2756 /*
2757 * GEN2_DEC bits:
2758 * Bit 15-4: Generic I/O range
2759 * Bit 3-1: reserved (read as 0)
2760 * Bit 0: enable GEN2 range on LPC I/F
2761 */
2762 tmpword = conf->fir_io & 0xfff8;
2763 tmpword |= 0x0001;
2764 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2765 pci_write_config_word(dev, GEN2_DEC, tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002766
2767 /* Pre-configure chip */
Linus Walleij08d09992006-04-14 16:03:33 -07002768 return preconfigure_smsc_chip(conf);
2769}
Linus Walleijc1e14a62006-04-05 22:33:59 -07002770
Linus Walleij08d09992006-04-14 16:03:33 -07002771/*
2772 * Pre-configure a certain port on the ALi 1533 bridge.
2773 * This is based on reverse-engineering since ALi does not
2774 * provide any data sheet for the 1533 chip.
2775 */
David S. Miller948252c2011-05-31 19:27:48 -07002776static void __init preconfigure_ali_port(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002777 unsigned short port)
2778{
2779 unsigned char reg;
2780 /* These bits obviously control the different ports */
2781 unsigned char mask;
2782 unsigned char tmpbyte;
2783
2784 switch(port) {
2785 case 0x0130:
2786 case 0x0178:
2787 reg = 0xb0;
2788 mask = 0x80;
2789 break;
2790 case 0x03f8:
2791 reg = 0xb4;
2792 mask = 0x80;
2793 break;
2794 case 0x02f8:
2795 reg = 0xb4;
2796 mask = 0x30;
2797 break;
2798 case 0x02e8:
2799 reg = 0xb4;
2800 mask = 0x08;
2801 break;
2802 default:
2803 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2804 return;
2805 }
2806
2807 pci_read_config_byte(dev, reg, &tmpbyte);
2808 /* Turn on the right bits */
2809 tmpbyte |= mask;
2810 pci_write_config_byte(dev, reg, tmpbyte);
2811 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002812}
2813
David S. Miller948252c2011-05-31 19:27:48 -07002814static int __init preconfigure_through_ali(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002815 struct
2816 smsc_ircc_subsystem_configuration
2817 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002818{
Linus Walleij08d09992006-04-14 16:03:33 -07002819 /* Configure the two ports on the ALi 1533 */
2820 preconfigure_ali_port(dev, conf->sir_io);
2821 preconfigure_ali_port(dev, conf->fir_io);
2822
2823 /* Pre-configure chip */
2824 return preconfigure_smsc_chip(conf);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002825}
2826
David S. Miller948252c2011-05-31 19:27:48 -07002827static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002828 unsigned short ircc_fir,
2829 unsigned short ircc_sir,
2830 unsigned char ircc_dma,
2831 unsigned char ircc_irq)
2832{
2833 struct pci_dev *dev = NULL;
2834 unsigned short ss_vendor = 0x0000;
2835 unsigned short ss_device = 0x0000;
2836 int ret = 0;
2837
Kulikov Vasiliy2e4e7a92010-07-03 06:04:15 +00002838 for_each_pci_dev(dev) {
David S. Miller948252c2011-05-31 19:27:48 -07002839 struct smsc_ircc_subsystem_configuration *conf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002840
2841 /*
Linus Walleij08d09992006-04-14 16:03:33 -07002842 * Cache the subsystem vendor/device:
2843 * some manufacturers fail to set this for all components,
2844 * so we save it in case there is just 0x0000 0x0000 on the
2845 * device we want to check.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002846 */
2847 if (dev->subsystem_vendor != 0x0000U) {
2848 ss_vendor = dev->subsystem_vendor;
2849 ss_device = dev->subsystem_device;
2850 }
2851 conf = subsystem_configurations;
2852 for( ; conf->subvendor; conf++) {
2853 if(conf->vendor == dev->vendor &&
2854 conf->device == dev->device &&
Linus Walleij08d09992006-04-14 16:03:33 -07002855 conf->subvendor == ss_vendor &&
2856 /* Sometimes these are cached values */
2857 (conf->subdevice == ss_device ||
2858 conf->subdevice == 0xffff)) {
2859 struct smsc_ircc_subsystem_configuration
2860 tmpconf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002861
Linus Walleij08d09992006-04-14 16:03:33 -07002862 memcpy(&tmpconf, conf,
2863 sizeof(struct smsc_ircc_subsystem_configuration));
Linus Walleijc1e14a62006-04-05 22:33:59 -07002864
Linus Walleij08d09992006-04-14 16:03:33 -07002865 /*
2866 * Override the default values with anything
2867 * passed in as parameter
2868 */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002869 if (ircc_cfg != 0)
2870 tmpconf.cfg_base = ircc_cfg;
2871 if (ircc_fir != 0)
2872 tmpconf.fir_io = ircc_fir;
2873 if (ircc_sir != 0)
2874 tmpconf.sir_io = ircc_sir;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002875 if (ircc_dma != DMA_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002876 tmpconf.fir_dma = ircc_dma;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002877 if (ircc_irq != IRQ_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002878 tmpconf.fir_irq = ircc_irq;
2879
2880 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2881 if (conf->preconfigure)
2882 ret = conf->preconfigure(dev, &tmpconf);
2883 else
2884 ret = -ENODEV;
2885 }
2886 }
Linus Walleijc1e14a62006-04-05 22:33:59 -07002887 }
2888
2889 return ret;
2890}
2891#endif // CONFIG_PCI
2892
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893/************************************************
2894 *
2895 * Transceivers specific functions
2896 *
2897 ************************************************/
2898
2899
2900/*
2901 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2902 *
2903 * Program transceiver through smsc-ircc ATC circuitry
2904 *
2905 */
2906
2907static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2908{
2909 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002910 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002911
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002912 jiffies_now = jiffies;
2913 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002914
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 /* ATC */
2916 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002917 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2918 fir_base + IRCC_ATC);
2919
2920 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2921 !time_after(jiffies, jiffies_timeout))
2922 /* empty */;
2923
2924 if (val)
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002925 IRDA_WARNING("%s(): ATC: 0x%02x\n", __func__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002926 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927}
2928
2929/*
2930 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2931 *
2932 * Probe transceiver smsc-ircc ATC circuitry
2933 *
2934 */
2935
2936static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2937{
2938 return 0;
2939}
2940
2941/*
2942 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2943 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002944 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 *
2946 */
2947
2948static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2949{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002950 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002951
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002952 switch (speed) {
2953 default:
2954 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002955 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002957 case 1152000 :
2958 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 fast_mode = IRCC_LCR_A_FAST;
2960 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 }
2962 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002963 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964}
2965
2966/*
2967 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2968 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002969 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 *
2971 */
2972
2973static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2974{
2975 return 0;
2976}
2977
2978/*
2979 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2980 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002981 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 *
2983 */
2984
2985static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2986{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002987 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002988
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002989 switch (speed) {
2990 default:
2991 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002992 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002994 case 1152000 :
2995 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2997 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002998
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 }
3000 /* This causes an interrupt */
3001 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07003002 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003}
3004
3005/*
3006 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
3007 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07003008 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 *
3010 */
3011
3012static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
3013{
3014 return 0;
3015}
3016
3017
3018module_init(smsc_ircc_init);
3019module_exit(smsc_ircc_cleanup);