blob: aa05dad75335f4cbbd986758a4230ad5050d49c4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*********************************************************************
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * Description: Driver for the SMC Infrared Communications Controller
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Author: Daniele Peri (peri@csai.unipa.it)
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07005 * Created at:
6 * Modified at:
7 * Modified by:
8 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * Copyright (c) 2002 Daniele Peri
10 * All Rights Reserved.
11 * Copyright (c) 2002 Jean Tourrilhes
Linus Walleijc1e14a62006-04-05 22:33:59 -070012 * Copyright (c) 2006 Linus Walleij
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
14 *
15 * Based on smc-ircc.c:
16 *
17 * Copyright (c) 2001 Stefani Seibold
18 * Copyright (c) 1999-2001 Dag Brattli
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070019 * Copyright (c) 1998-1999 Thomas Davis,
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 *
21 * and irport.c:
22 *
23 * Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
24 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070025 *
26 * This program is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU General Public License as
28 * published by the Free Software Foundation; either version 2 of
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 * the License, or (at your option) any later version.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070030 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070031 * This program is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34 * GNU General Public License for more details.
Dmitry Torokhov527b6af2005-09-06 15:19:17 -070035 *
36 * You should have received a copy of the GNU General Public License
37 * along with this program; if not, write to the Free Software
38 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 * MA 02111-1307 USA
40 *
41 ********************************************************************/
42
43#include <linux/module.h>
44#include <linux/kernel.h>
45#include <linux/types.h>
46#include <linux/skbuff.h>
47#include <linux/netdevice.h>
48#include <linux/ioport.h>
49#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#include <linux/init.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000051#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#include <linux/rtnetlink.h>
53#include <linux/serial_reg.h>
54#include <linux/dma-mapping.h>
David Brownelld94c77b2006-05-09 15:26:11 -070055#include <linux/pnp.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010056#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090057#include <linux/gfp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59#include <asm/io.h>
60#include <asm/dma.h>
61#include <asm/byteorder.h>
62
63#include <linux/spinlock.h>
64#include <linux/pm.h>
Linus Walleijc1e14a62006-04-05 22:33:59 -070065#ifdef CONFIG_PCI
66#include <linux/pci.h>
67#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69#include <net/irda/wrapper.h>
70#include <net/irda/irda.h>
71#include <net/irda/irda_device.h>
72
73#include "smsc-ircc2.h"
74#include "smsc-sio.h"
75
Dmitry Torokhov98b77772005-09-06 15:19:19 -070076
77MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
78MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
79MODULE_LICENSE("GPL");
80
Rusty Russelleb939922011-12-19 14:08:01 +000081static bool smsc_nopnp = true;
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -070082module_param_named(nopnp, smsc_nopnp, bool, 0);
Jonathan Bastien-Filiatrault32db9272007-09-26 22:34:25 -070083MODULE_PARM_DESC(nopnp, "Do not use PNP to detect controller settings, defaults to true");
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -070084
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070085#define DMA_INVAL 255
86static int ircc_dma = DMA_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070087module_param(ircc_dma, int, 0);
88MODULE_PARM_DESC(ircc_dma, "DMA channel");
89
Bjorn Helgaas916f11c2007-05-08 00:36:02 -070090#define IRQ_INVAL 255
91static int ircc_irq = IRQ_INVAL;
Dmitry Torokhov98b77772005-09-06 15:19:19 -070092module_param(ircc_irq, int, 0);
93MODULE_PARM_DESC(ircc_irq, "IRQ line");
94
95static int ircc_fir;
96module_param(ircc_fir, int, 0);
97MODULE_PARM_DESC(ircc_fir, "FIR Base Address");
98
99static int ircc_sir;
100module_param(ircc_sir, int, 0);
101MODULE_PARM_DESC(ircc_sir, "SIR Base Address");
102
103static int ircc_cfg;
104module_param(ircc_cfg, int, 0);
105MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");
106
107static int ircc_transceiver;
108module_param(ircc_transceiver, int, 0);
109MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111/* Types */
112
Linus Walleijc1e14a62006-04-05 22:33:59 -0700113#ifdef CONFIG_PCI
114struct smsc_ircc_subsystem_configuration {
115 unsigned short vendor; /* PCI vendor ID */
116 unsigned short device; /* PCI vendor ID */
117 unsigned short subvendor; /* PCI subsystem vendor ID */
Jean Delvare83cf0a92009-10-20 11:11:52 +0200118 unsigned short subdevice; /* PCI subsystem device ID */
Linus Walleijc1e14a62006-04-05 22:33:59 -0700119 unsigned short sir_io; /* I/O port for SIR */
120 unsigned short fir_io; /* I/O port for FIR */
121 unsigned char fir_irq; /* FIR IRQ */
122 unsigned char fir_dma; /* FIR DMA */
123 unsigned short cfg_base; /* I/O port for chip configuration */
124 int (*preconfigure)(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf); /* Preconfig function */
125 const char *name; /* name shown as info */
126};
127#endif
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129struct smsc_transceiver {
130 char *name;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700131 void (*set_for_speed)(int fir_base, u32 speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 int (*probe)(int fir_base);
133};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135struct smsc_chip {
136 char *name;
137 #if 0
138 u8 type;
139 #endif
140 u16 flags;
141 u8 devid;
142 u8 rev;
143};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145struct smsc_chip_address {
146 unsigned int cfg_base;
147 unsigned int type;
148};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150/* Private data for each instance */
151struct smsc_ircc_cb {
152 struct net_device *netdev; /* Yes! we are some kind of netdevice */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 struct irlap_cb *irlap; /* The link layer we are binded to */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 chipio_t io; /* IrDA controller information */
156 iobuff_t tx_buff; /* Transmit buffer */
157 iobuff_t rx_buff; /* Receive buffer */
158 dma_addr_t tx_buff_dma;
159 dma_addr_t rx_buff_dma;
160
161 struct qos_info qos; /* QoS capabilities for this device */
162
163 spinlock_t lock; /* For serializing operations */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 __u32 new_speed;
166 __u32 flags; /* Interface flags */
167
168 int tx_buff_offsets[10]; /* Offsets between frames in tx_buff */
169 int tx_len; /* Number of frames in tx_buff */
170
171 int transceiver;
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700172 struct platform_device *pldev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173};
174
175/* Constants */
176
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700177#define SMSC_IRCC2_DRIVER_NAME "smsc-ircc2"
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED 9600
180#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER 1
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700181#define SMSC_IRCC2_C_NET_TIMEOUT 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182#define SMSC_IRCC2_C_SIR_STOP 0
183
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700184static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186/* Prototypes */
187
188static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
189static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
190static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
191static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
192static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
193static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700194static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
195static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000197static netdev_tx_t smsc_ircc_hard_xmit_sir(struct sk_buff *skb,
198 struct net_device *dev);
199static netdev_tx_t smsc_ircc_hard_xmit_fir(struct sk_buff *skb,
200 struct net_device *dev);
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700201static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
202static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -0700203static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
204static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
David Howells7d12e782006-10-05 14:55:46 +0100205static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
207static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
208#if SMSC_IRCC2_C_SIR_STOP
209static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
210#endif
211static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
212static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
213static int smsc_ircc_net_open(struct net_device *dev);
214static int smsc_ircc_net_close(struct net_device *dev);
215static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
216#if SMSC_IRCC2_C_NET_TIMEOUT
217static void smsc_ircc_timeout(struct net_device *dev);
218#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
220static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
221static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
222static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);
223
224/* Probing */
David S. Miller948252c2011-05-31 19:27:48 -0700225static int __init smsc_ircc_look_for_chips(void);
226static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
227static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
228static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
229static int __init smsc_superio_fdc(unsigned short cfg_base);
230static int __init smsc_superio_lpc(unsigned short cfg_base);
Linus Walleijc1e14a62006-04-05 22:33:59 -0700231#ifdef CONFIG_PCI
David S. Miller948252c2011-05-31 19:27:48 -0700232static int __init preconfigure_smsc_chip(struct smsc_ircc_subsystem_configuration *conf);
233static int __init preconfigure_through_82801(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
234static void __init preconfigure_ali_port(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -0700235 unsigned short port);
David S. Miller948252c2011-05-31 19:27:48 -0700236static int __init preconfigure_through_ali(struct pci_dev *dev, struct smsc_ircc_subsystem_configuration *conf);
237static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
Linus Walleijc1e14a62006-04-05 22:33:59 -0700238 unsigned short ircc_fir,
239 unsigned short ircc_sir,
240 unsigned char ircc_dma,
241 unsigned char ircc_irq);
242#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
244/* Transceivers specific functions */
245
246static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
247static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
248static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
249static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
250static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
251static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);
252
253/* Power Management */
254
Russell King3ae5eae2005-11-09 22:32:44 +0000255static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state);
256static int smsc_ircc_resume(struct platform_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Russell King3ae5eae2005-11-09 22:32:44 +0000258static struct platform_driver smsc_ircc_driver = {
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700259 .suspend = smsc_ircc_suspend,
260 .resume = smsc_ircc_resume,
Russell King3ae5eae2005-11-09 22:32:44 +0000261 .driver = {
262 .name = SMSC_IRCC2_DRIVER_NAME,
263 },
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700264};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
266/* Transceivers for SMSC-ircc */
267
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700268static struct smsc_transceiver smsc_transceivers[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700270 { "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
271 { "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
272 { "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
273 { NULL, NULL }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274};
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700275#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277/* SMC SuperIO chipsets definitions */
278
279#define KEY55_1 0 /* SuperIO Configuration mode with Key <0x55> */
280#define KEY55_2 1 /* SuperIO Configuration mode with Key <0x55,0x55> */
281#define NoIRDA 2 /* SuperIO Chip has no IRDA Port */
282#define SIR 0 /* SuperIO Chip has only slow IRDA */
283#define FIR 4 /* SuperIO Chip has fast IRDA */
284#define SERx4 8 /* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */
285
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700286static struct smsc_chip __initdata fdc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 /* Base address 0x3f0 or 0x370 */
289 { "37C44", KEY55_1|NoIRDA, 0x00, 0x00 }, /* This chip cannot be detected */
290 { "37C665GT", KEY55_2|NoIRDA, 0x65, 0x01 },
291 { "37C665GT", KEY55_2|NoIRDA, 0x66, 0x01 },
292 { "37C669", KEY55_2|SIR|SERx4, 0x03, 0x02 },
293 { "37C669", KEY55_2|SIR|SERx4, 0x04, 0x02 }, /* ID? */
294 { "37C78", KEY55_2|NoIRDA, 0x78, 0x00 },
295 { "37N769", KEY55_1|FIR|SERx4, 0x28, 0x00 },
296 { "37N869", KEY55_1|FIR|SERx4, 0x29, 0x00 },
297 { NULL }
298};
299
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700300static struct smsc_chip __initdata fdc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301{
302 /* Base address 0x3f0 or 0x370 */
303 { "37B72X", KEY55_1|SIR|SERx4, 0x4c, 0x00 },
304 { "37B77X", KEY55_1|SIR|SERx4, 0x43, 0x00 },
305 { "37B78X", KEY55_1|SIR|SERx4, 0x44, 0x00 },
306 { "37B80X", KEY55_1|SIR|SERx4, 0x42, 0x00 },
307 { "37C67X", KEY55_1|FIR|SERx4, 0x40, 0x00 },
308 { "37C93X", KEY55_2|SIR|SERx4, 0x02, 0x01 },
309 { "37C93XAPM", KEY55_1|SIR|SERx4, 0x30, 0x01 },
310 { "37C93XFR", KEY55_2|FIR|SERx4, 0x03, 0x01 },
311 { "37M707", KEY55_1|SIR|SERx4, 0x42, 0x00 },
312 { "37M81X", KEY55_1|SIR|SERx4, 0x4d, 0x00 },
313 { "37N958FR", KEY55_1|FIR|SERx4, 0x09, 0x04 },
314 { "37N971", KEY55_1|FIR|SERx4, 0x0a, 0x00 },
315 { "37N972", KEY55_1|FIR|SERx4, 0x0b, 0x00 },
316 { NULL }
317};
318
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700319static struct smsc_chip __initdata lpc_chips_flat[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
321 /* Base address 0x2E or 0x4E */
322 { "47N227", KEY55_1|FIR|SERx4, 0x5a, 0x00 },
Peter Kovarafdf27c2007-03-16 20:39:25 -0700323 { "47N227", KEY55_1|FIR|SERx4, 0x7a, 0x00 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 { "47N267", KEY55_1|FIR|SERx4, 0x5e, 0x00 },
325 { NULL }
326};
327
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700328static struct smsc_chip __initdata lpc_chips_paged[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 /* Base address 0x2E or 0x4E */
331 { "47B27X", KEY55_1|SIR|SERx4, 0x51, 0x00 },
332 { "47B37X", KEY55_1|SIR|SERx4, 0x52, 0x00 },
333 { "47M10X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
334 { "47M120", KEY55_1|NoIRDA|SERx4, 0x5c, 0x00 },
335 { "47M13X", KEY55_1|SIR|SERx4, 0x59, 0x00 },
336 { "47M14X", KEY55_1|SIR|SERx4, 0x5f, 0x00 },
337 { "47N252", KEY55_1|FIR|SERx4, 0x0e, 0x00 },
338 { "47S42X", KEY55_1|SIR|SERx4, 0x57, 0x00 },
339 { NULL }
340};
341
342#define SMSCSIO_TYPE_FDC 1
343#define SMSCSIO_TYPE_LPC 2
344#define SMSCSIO_TYPE_FLAT 4
345#define SMSCSIO_TYPE_PAGED 8
346
Dmitry Torokhovb6158d22005-09-06 15:19:20 -0700347static struct smsc_chip_address __initdata possible_addresses[] =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700349 { 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
350 { 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
351 { 0xe0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
352 { 0x2e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
353 { 0x4e, SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
354 { 0, 0 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355};
356
357/* Globals */
358
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700359static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
360static unsigned short dev_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362static inline void register_bank(int iobase, int bank)
363{
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700364 outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
365 iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366}
367
David Brownelld94c77b2006-05-09 15:26:11 -0700368/* PNP hotplug support */
David S. Miller948252c2011-05-31 19:27:48 -0700369static const struct pnp_device_id smsc_ircc_pnp_table[] = {
David Brownelld94c77b2006-05-09 15:26:11 -0700370 { .id = "SMCf010", .driver_data = 0 },
371 /* and presumably others */
372 { }
373};
374MODULE_DEVICE_TABLE(pnp, smsc_ircc_pnp_table);
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700375
376static int pnp_driver_registered;
377
Ingo Molnar7a1aa302008-05-05 01:06:54 -0700378#ifdef CONFIG_PNP
Bill Pemberton45ac9362012-12-03 09:24:13 -0500379static int smsc_ircc_pnp_probe(struct pnp_dev *dev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000380 const struct pnp_device_id *dev_id)
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700381{
382 unsigned int firbase, sirbase;
383 u8 dma, irq;
384
385 if (!(pnp_port_valid(dev, 0) && pnp_port_valid(dev, 1) &&
386 pnp_dma_valid(dev, 0) && pnp_irq_valid(dev, 0)))
387 return -EINVAL;
388
389 sirbase = pnp_port_start(dev, 0);
390 firbase = pnp_port_start(dev, 1);
391 dma = pnp_dma(dev, 0);
392 irq = pnp_irq(dev, 0);
393
394 if (smsc_ircc_open(firbase, sirbase, dma, irq))
395 return -ENODEV;
396
397 return 0;
398}
399
400static struct pnp_driver smsc_ircc_pnp_driver = {
401 .name = "smsc-ircc2",
402 .id_table = smsc_ircc_pnp_table,
403 .probe = smsc_ircc_pnp_probe,
404};
Ingo Molnar7a1aa302008-05-05 01:06:54 -0700405#else /* CONFIG_PNP */
406static struct pnp_driver smsc_ircc_pnp_driver;
407#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
409/*******************************************************************************
410 *
411 *
412 * SMSC-ircc stuff
413 *
414 *
415 *******************************************************************************/
416
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700417static int __init smsc_ircc_legacy_probe(void)
418{
419 int ret = 0;
420
Bjorn Helgaas7c31d2f2007-06-27 14:09:50 -0700421#ifdef CONFIG_PCI
422 if (smsc_ircc_preconfigure_subsystems(ircc_cfg, ircc_fir, ircc_sir, ircc_dma, ircc_irq) < 0) {
423 /* Ignore errors from preconfiguration */
424 IRDA_ERROR("%s, Preconfiguration failed !\n", driver_name);
425 }
426#endif
427
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700428 if (ircc_fir > 0 && ircc_sir > 0) {
429 IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
430 IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);
431
432 if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
433 ret = -ENODEV;
434 } else {
435 ret = -ENODEV;
436
437 /* try user provided configuration register base address */
438 if (ircc_cfg > 0) {
439 IRDA_MESSAGE(" Overriding configuration address "
440 "0x%04x\n", ircc_cfg);
441 if (!smsc_superio_fdc(ircc_cfg))
442 ret = 0;
443 if (!smsc_superio_lpc(ircc_cfg))
444 ret = 0;
445 }
446
447 if (smsc_ircc_look_for_chips() > 0)
448 ret = 0;
449 }
450 return ret;
451}
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453/*
454 * Function smsc_ircc_init ()
455 *
456 * Initialize chip. Just try to find out how many chips we are dealing with
457 * and where they are
458 */
459static int __init smsc_ircc_init(void)
460{
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700461 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700463 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464
Russell King3ae5eae2005-11-09 22:32:44 +0000465 ret = platform_driver_register(&smsc_ircc_driver);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700466 if (ret) {
467 IRDA_ERROR("%s, Can't register driver!\n", driver_name);
468 return ret;
469 }
470
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700471 dev_count = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700472
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700473 if (smsc_nopnp || !pnp_platform_devices ||
474 ircc_cfg || ircc_fir || ircc_sir ||
475 ircc_dma != DMA_INVAL || ircc_irq != IRQ_INVAL) {
476 ret = smsc_ircc_legacy_probe();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700477 } else {
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700478 if (pnp_register_driver(&smsc_ircc_pnp_driver) == 0)
479 pnp_driver_registered = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700481
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700482 if (ret) {
483 if (pnp_driver_registered)
484 pnp_unregister_driver(&smsc_ircc_pnp_driver);
Russell King3ae5eae2005-11-09 22:32:44 +0000485 platform_driver_unregister(&smsc_ircc_driver);
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -0700486 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return ret;
489}
490
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000491static netdev_tx_t smsc_ircc_net_xmit(struct sk_buff *skb,
492 struct net_device *dev)
Stephen Hemminger02087be2009-03-20 19:35:42 +0000493{
494 struct smsc_ircc_cb *self = netdev_priv(dev);
495
496 if (self->io.speed > 115200)
497 return smsc_ircc_hard_xmit_fir(skb, dev);
498 else
499 return smsc_ircc_hard_xmit_sir(skb, dev);
500}
501
502static const struct net_device_ops smsc_ircc_netdev_ops = {
503 .ndo_open = smsc_ircc_net_open,
504 .ndo_stop = smsc_ircc_net_close,
505 .ndo_do_ioctl = smsc_ircc_net_ioctl,
506 .ndo_start_xmit = smsc_ircc_net_xmit,
507#if SMSC_IRCC2_C_NET_TIMEOUT
508 .ndo_tx_timeout = smsc_ircc_timeout,
509#endif
510};
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512/*
513 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
514 *
515 * Try to open driver instance
516 *
517 */
Bill Pemberton45ac9362012-12-03 09:24:13 -0500518static int smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
520 struct smsc_ircc_cb *self;
521 struct net_device *dev;
522 int err;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700523
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700524 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
526 err = smsc_ircc_present(fir_base, sir_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700527 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 goto err_out;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 err = -ENOMEM;
Dmitry Torokhova956f4c2005-09-06 15:19:20 -0700531 if (dev_count >= ARRAY_SIZE(dev_self)) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700532 IRDA_WARNING("%s(), too many devices!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 goto err_out1;
534 }
535
536 /*
537 * Allocate new instance of the driver
538 */
539 dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
540 if (!dev) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700541 IRDA_WARNING("%s() can't allocate net device\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 goto err_out1;
543 }
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545#if SMSC_IRCC2_C_NET_TIMEOUT
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700546 dev->watchdog_timeo = HZ * 2; /* Allow enough time for speed change */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547#endif
Stephen Hemminger02087be2009-03-20 19:35:42 +0000548 dev->netdev_ops = &smsc_ircc_netdev_ops;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700549
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700550 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 self->netdev = dev;
552
553 /* Make ifconfig display some details */
554 dev->base_addr = self->io.fir_base = fir_base;
555 dev->irq = self->io.irq = irq;
556
557 /* Need to store self somewhere */
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700558 dev_self[dev_count] = self;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 spin_lock_init(&self->lock);
560
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700561 self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;
563
564 self->rx_buff.head =
565 dma_alloc_coherent(NULL, self->rx_buff.truesize,
Joe Perches1f9061d22013-03-15 07:23:58 +0000566 &self->rx_buff_dma, GFP_KERNEL | __GFP_ZERO);
Joe Perchesd0320f72013-03-14 13:07:21 +0000567 if (self->rx_buff.head == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 goto err_out2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
570 self->tx_buff.head =
571 dma_alloc_coherent(NULL, self->tx_buff.truesize,
Joe Perches1f9061d22013-03-15 07:23:58 +0000572 &self->tx_buff_dma, GFP_KERNEL | __GFP_ZERO);
Joe Perchesd0320f72013-03-14 13:07:21 +0000573 if (self->tx_buff.head == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 goto err_out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 self->rx_buff.in_frame = FALSE;
577 self->rx_buff.state = OUTSIDE_FRAME;
578 self->tx_buff.data = self->tx_buff.head;
579 self->rx_buff.data = self->rx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700580
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 smsc_ircc_setup_qos(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 smsc_ircc_init_chip(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700584
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700585 if (ircc_transceiver > 0 &&
586 ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 self->transceiver = ircc_transceiver;
588 else
589 smsc_ircc_probe_transceiver(self);
590
591 err = register_netdev(self->netdev);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700592 if (err) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 IRDA_ERROR("%s, Network device registration failed!\n",
594 driver_name);
595 goto err_out4;
596 }
597
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700598 self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
599 dev_count, NULL, 0);
600 if (IS_ERR(self->pldev)) {
601 err = PTR_ERR(self->pldev);
602 goto err_out5;
603 }
Russell King3ae5eae2005-11-09 22:32:44 +0000604 platform_set_drvdata(self->pldev, self);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
606 IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700607 dev_count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700610
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700611 err_out5:
612 unregister_netdev(self->netdev);
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 err_out4:
615 dma_free_coherent(NULL, self->tx_buff.truesize,
616 self->tx_buff.head, self->tx_buff_dma);
617 err_out3:
618 dma_free_coherent(NULL, self->rx_buff.truesize,
619 self->rx_buff.head, self->rx_buff_dma);
620 err_out2:
621 free_netdev(self->netdev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -0700622 dev_self[dev_count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 err_out1:
624 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
625 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
626 err_out:
627 return err;
628}
629
630/*
631 * Function smsc_ircc_present(fir_base, sir_base)
632 *
633 * Check the smsc-ircc chip presence
634 *
635 */
636static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
637{
638 unsigned char low, high, chip, config, dma, irq, version;
639
640 if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
641 driver_name)) {
642 IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700643 __func__, fir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 goto out1;
645 }
646
647 if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
648 driver_name)) {
649 IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700650 __func__, sir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 goto out2;
652 }
653
654 register_bank(fir_base, 3);
655
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700656 high = inb(fir_base + IRCC_ID_HIGH);
657 low = inb(fir_base + IRCC_ID_LOW);
658 chip = inb(fir_base + IRCC_CHIP_ID);
659 version = inb(fir_base + IRCC_VERSION);
660 config = inb(fir_base + IRCC_INTERFACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 dma = config & IRCC_INTERFACE_DMA_MASK;
662 irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
663
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700664 if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700665 IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700666 __func__, fir_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 goto out3;
668 }
669 IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
670 "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
671 chip & 0x0f, version, fir_base, sir_base, dma, irq);
672
673 return 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700674
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 out3:
676 release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
677 out2:
678 release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
679 out1:
680 return -ENODEV;
681}
682
683/*
684 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
685 *
686 * Setup I/O
687 *
688 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700689static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
690 unsigned int fir_base, unsigned int sir_base,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 u8 dma, u8 irq)
692{
693 unsigned char config, chip_dma, chip_irq;
694
695 register_bank(fir_base, 3);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700696 config = inb(fir_base + IRCC_INTERFACE);
697 chip_dma = config & IRCC_INTERFACE_DMA_MASK;
698 chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700 self->io.fir_base = fir_base;
701 self->io.sir_base = sir_base;
702 self->io.fir_ext = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
703 self->io.sir_ext = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
704 self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
705 self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;
706
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700707 if (irq != IRQ_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 if (irq != chip_irq)
709 IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
710 driver_name, chip_irq, irq);
711 self->io.irq = irq;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700712 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 self->io.irq = chip_irq;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700714
Bjorn Helgaas916f11c2007-05-08 00:36:02 -0700715 if (dma != DMA_INVAL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 if (dma != chip_dma)
717 IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
718 driver_name, chip_dma, dma);
719 self->io.dma = dma;
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700720 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 self->io.dma = chip_dma;
722
723}
724
725/*
726 * Function smsc_ircc_setup_qos(self)
727 *
728 * Setup qos
729 *
730 */
731static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
732{
733 /* Initialize QoS for this device */
734 irda_init_max_qos_capabilies(&self->qos);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
737 IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);
738
739 self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
740 self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
741 irda_qos_bits_to_value(&self->qos);
742}
743
744/*
745 * Function smsc_ircc_init_chip(self)
746 *
747 * Init chip
748 *
749 */
750static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
751{
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800752 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
754 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700755 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
756 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
758 register_bank(iobase, 1);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800759 outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | IRCC_CFGA_IRDA_SIR_A),
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700760 iobase + IRCC_SCE_CFGA);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
762#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700763 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
764 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700765#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700766 outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
767 iobase + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700768#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700769 (void) inb(iobase + IRCC_FIFO_THRESHOLD);
770 outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 register_bank(iobase, 4);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800773 outb((inb(iobase + IRCC_CONTROL) & 0x30), iobase + IRCC_CONTROL);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700774
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 register_bank(iobase, 0);
Dmitry Torokhove812cb52005-10-30 15:00:14 -0800776 outb(0, iobase + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700779
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 /* Power on device */
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700781 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
784/*
785 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
786 *
787 * Process IOCTL commands for this device
788 *
789 */
790static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
791{
792 struct if_irda_req *irq = (struct if_irda_req *) rq;
793 struct smsc_ircc_cb *self;
794 unsigned long flags;
795 int ret = 0;
796
797 IRDA_ASSERT(dev != NULL, return -1;);
798
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700799 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800
801 IRDA_ASSERT(self != NULL, return -1;);
802
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700803 IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __func__, dev->name, cmd);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700804
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 switch (cmd) {
806 case SIOCSBANDWIDTH: /* Set bandwidth */
807 if (!capable(CAP_NET_ADMIN))
808 ret = -EPERM;
809 else {
810 /* Make sure we are the only one touching
811 * self->io.speed and the hardware - Jean II */
812 spin_lock_irqsave(&self->lock, flags);
813 smsc_ircc_change_speed(self, irq->ifr_baudrate);
814 spin_unlock_irqrestore(&self->lock, flags);
815 }
816 break;
817 case SIOCSMEDIABUSY: /* Set media busy */
818 if (!capable(CAP_NET_ADMIN)) {
819 ret = -EPERM;
820 break;
821 }
822
823 irda_device_set_media_busy(self->netdev, TRUE);
824 break;
825 case SIOCGRECEIVING: /* Check if we are receiving right now */
826 irq->ifr_receiving = smsc_ircc_is_receiving(self);
827 break;
828 #if 0
829 case SIOCSDTRRTS:
830 if (!capable(CAP_NET_ADMIN)) {
831 ret = -EPERM;
832 break;
833 }
834 smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
835 break;
836 #endif
837 default:
838 ret = -EOPNOTSUPP;
839 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 return ret;
842}
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844#if SMSC_IRCC2_C_NET_TIMEOUT
845/*
846 * Function smsc_ircc_timeout (struct net_device *dev)
847 *
848 * The networking timeout management.
849 *
850 */
851
852static void smsc_ircc_timeout(struct net_device *dev)
853{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700854 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 unsigned long flags;
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
858 dev->name, self->io.speed);
859 spin_lock_irqsave(&self->lock, flags);
860 smsc_ircc_sir_start(self);
861 smsc_ircc_change_speed(self, self->io.speed);
Eric Dumazet1ae5dc32010-05-10 05:01:31 -0700862 dev->trans_start = jiffies; /* prevent tx timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 netif_wake_queue(dev);
864 spin_unlock_irqrestore(&self->lock, flags);
865}
866#endif
867
868/*
869 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
870 *
871 * Transmits the current frame until FIFO is full, then
872 * waits until the next transmit interrupt, and continues until the
873 * frame is transmitted.
874 */
Stephen Hemminger6518bbb2009-08-31 19:50:50 +0000875static netdev_tx_t smsc_ircc_hard_xmit_sir(struct sk_buff *skb,
876 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
878 struct smsc_ircc_cb *self;
879 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 s32 speed;
881
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700882 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883
Patrick McHardyec634fe2009-07-05 19:23:38 -0700884 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700885
Dmitry Torokhovda0841a2005-09-06 15:19:23 -0700886 self = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700887 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 /* Make sure test of self->io.speed & speed change are atomic */
892 spin_lock_irqsave(&self->lock, flags);
893
894 /* Check if we need to change the speed */
895 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700896 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 /* Check for empty frame */
898 if (!skb->len) {
899 /*
900 * We send frames one by one in SIR mode (no
901 * pipelining), so at this point, if we were sending
902 * a previous frame, we just received the interrupt
903 * telling us it is finished (UART_IIR_THRI).
904 * Therefore, waiting for the transmitter to really
905 * finish draining the fifo won't take too long.
906 * And the interrupt handler is not expected to run.
907 * - Jean II */
908 smsc_ircc_sir_wait_hw_transmitter_finish(self);
909 smsc_ircc_change_speed(self, speed);
910 spin_unlock_irqrestore(&self->lock, flags);
911 dev_kfree_skb(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -0700912 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700914 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 }
916
917 /* Init tx buffer */
918 self->tx_buff.data = self->tx_buff.head;
919
920 /* Copy skb to tx_buff while wrapping, stuffing and making CRC */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700921 self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 self->tx_buff.truesize);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700923
Stephen Hemmingeraf049082009-01-06 10:40:43 -0800924 dev->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925
926 /* Turn on transmit finished interrupt. Will fire immediately! */
Dmitry Torokhov80a90582005-09-06 15:19:21 -0700927 outb(UART_IER_THRI, self->io.sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
929 spin_unlock_irqrestore(&self->lock, flags);
930
931 dev_kfree_skb(skb);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700932
Patrick McHardyec634fe2009-07-05 19:23:38 -0700933 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934}
935
936/*
937 * Function smsc_ircc_set_fir_speed (self, baud)
938 *
939 * Change the speed of the device
940 *
941 */
942static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
943{
944 int fir_base, ir_mode, ctrl, fast;
945
946 IRDA_ASSERT(self != NULL, return;);
947 fir_base = self->io.fir_base;
948
949 self->io.speed = speed;
950
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700951 switch (speed) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952 default:
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700953 case 576000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 ir_mode = IRCC_CFGA_IRDA_HDLC;
955 ctrl = IRCC_CRC;
956 fast = 0;
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700957 IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 break;
959 case 1152000:
960 ir_mode = IRCC_CFGA_IRDA_HDLC;
961 ctrl = IRCC_1152 | IRCC_CRC;
962 fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
963 IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700964 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 break;
966 case 4000000:
967 ir_mode = IRCC_CFGA_IRDA_4PPM;
968 ctrl = IRCC_CRC;
969 fast = IRCC_LCR_A_FAST;
970 IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700971 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972 break;
973 }
974 #if 0
975 Now in tranceiver!
976 /* This causes an interrupt */
977 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700978 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -0700980
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700982 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 -0700983
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -0700985 outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986}
987
988/*
989 * Function smsc_ircc_fir_start(self)
990 *
991 * Change the speed of the device
992 *
993 */
994static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
995{
996 struct net_device *dev;
997 int fir_base;
998
Harvey Harrisona97a6f12008-07-30 17:20:18 -0700999 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 IRDA_ASSERT(self != NULL, return;);
1002 dev = self->netdev;
1003 IRDA_ASSERT(dev != NULL, return;);
1004
1005 fir_base = self->io.fir_base;
1006
1007 /* Reset everything */
1008
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009 /* Clear FIFO */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001010 outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011
1012 /* Enable interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001013 /*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 register_bank(fir_base, 1);
1016
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001017 /* Select the TX/RX interface */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001019 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
1020 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001021#else
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001022 outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
1023 fir_base + IRCC_SCE_CFGB);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001024#endif
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001025 (void) inb(fir_base + IRCC_FIFO_THRESHOLD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
1027 /* Enable SCE interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001028 outb(0, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001030 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
1031 outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032}
1033
1034/*
1035 * Function smsc_ircc_fir_stop(self, baud)
1036 *
1037 * Change the speed of the device
1038 *
1039 */
1040static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
1041{
1042 int fir_base;
1043
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001044 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 IRDA_ASSERT(self != NULL, return;);
1047
1048 fir_base = self->io.fir_base;
1049 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001050 /*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
1051 outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052}
1053
1054
1055/*
1056 * Function smsc_ircc_change_speed(self, baud)
1057 *
1058 * Change the speed of the device
1059 *
1060 * This function *must* be called with spinlock held, because it may
1061 * be called from the irq handler. - Jean II
1062 */
Dmitry Torokhov0fa2f492005-09-06 15:19:24 -07001063static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066 int last_speed_was_sir;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001067
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001068 IRDA_DEBUG(0, "%s() changing speed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 IRDA_ASSERT(self != NULL, return;);
1071 dev = self->netdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;
1074
1075 #if 0
1076 /* Temp Hack */
1077 speed= 1152000;
1078 self->io.speed = speed;
1079 last_speed_was_sir = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001080 smsc_ircc_fir_start(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001082
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001083 if (self->io.speed == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 smsc_ircc_sir_start(self);
1085
1086 #if 0
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001087 if (!last_speed_was_sir) speed = self->io.speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 #endif
1089
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001090 if (self->io.speed != speed)
1091 smsc_ircc_set_transceiver_for_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092
1093 self->io.speed = speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001094
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001095 if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
1096 if (!last_speed_was_sir) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 smsc_ircc_fir_stop(self);
1098 smsc_ircc_sir_start(self);
1099 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001100 smsc_ircc_set_sir_speed(self, speed);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001101 } else {
1102 if (last_speed_was_sir) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001103 #if SMSC_IRCC2_C_SIR_STOP
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 smsc_ircc_sir_stop(self);
1105 #endif
1106 smsc_ircc_fir_start(self);
1107 }
1108 smsc_ircc_set_fir_speed(self, speed);
1109
1110 #if 0
1111 self->tx_buff.len = 10;
1112 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001113
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001114 smsc_ircc_dma_xmit(self, 4000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115 #endif
1116 /* Be ready for incoming frames */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001117 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001119
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120 netif_wake_queue(dev);
1121}
1122
1123/*
1124 * Function smsc_ircc_set_sir_speed (self, speed)
1125 *
1126 * Set speed of IrDA port to specified baudrate
1127 *
1128 */
Hannes Eder0e49e642008-12-26 00:03:19 -08001129static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130{
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001131 int iobase;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132 int fcr; /* FIFO control reg */
1133 int lcr; /* Line control reg */
1134 int divisor;
1135
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001136 IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137
1138 IRDA_ASSERT(self != NULL, return;);
1139 iobase = self->io.sir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 /* Update accounting for new speed */
1142 self->io.speed = speed;
1143
1144 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001145 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001147 divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001148
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 fcr = UART_FCR_ENABLE_FIFO;
1150
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001151 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
1153 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001154 * about this timeout since it will always be fast enough.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001156 fcr |= self->io.speed < 38400 ?
1157 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001158
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159 /* IrDA ports use 8N1 */
1160 lcr = UART_LCR_WLEN8;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001161
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001162 outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
1163 outb(divisor & 0xff, iobase + UART_DLL); /* Set speed */
1164 outb(divisor >> 8, iobase + UART_DLM);
1165 outb(lcr, iobase + UART_LCR); /* Set 8N1 */
1166 outb(fcr, iobase + UART_FCR); /* Enable FIFO's */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167
1168 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001169 outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001171 IRDA_DEBUG(2, "%s() speed changed to: %d\n", __func__, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172}
1173
1174
1175/*
1176 * Function smsc_ircc_hard_xmit_fir (skb, dev)
1177 *
1178 * Transmit the frame!
1179 *
1180 */
Stephen Hemminger6518bbb2009-08-31 19:50:50 +00001181static netdev_tx_t smsc_ircc_hard_xmit_fir(struct sk_buff *skb,
1182 struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183{
1184 struct smsc_ircc_cb *self;
1185 unsigned long flags;
1186 s32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 int mtt;
1188
Patrick McHardyec634fe2009-07-05 19:23:38 -07001189 IRDA_ASSERT(dev != NULL, return NETDEV_TX_OK;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001190 self = netdev_priv(dev);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001191 IRDA_ASSERT(self != NULL, return NETDEV_TX_OK;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001192
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 netif_stop_queue(dev);
1194
1195 /* Make sure test of self->io.speed & speed change are atomic */
1196 spin_lock_irqsave(&self->lock, flags);
1197
1198 /* Check if we need to change the speed after this frame */
1199 speed = irda_get_next_speed(skb);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001200 if (speed != self->io.speed && speed != -1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201 /* Check for empty frame */
1202 if (!skb->len) {
1203 /* Note : you should make sure that speed changes
1204 * are not going to corrupt any outgoing frame.
1205 * Look at nsc-ircc for the gory details - Jean II */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001206 smsc_ircc_change_speed(self, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 spin_unlock_irqrestore(&self->lock, flags);
1208 dev_kfree_skb(skb);
Patrick McHardyec634fe2009-07-05 19:23:38 -07001209 return NETDEV_TX_OK;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001210 }
1211
1212 self->new_speed = speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001213 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001214
Arnaldo Carvalho de Melod626f622007-03-27 18:55:52 -03001215 skb_copy_from_linear_data(skb, self->tx_buff.head, skb->len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 self->tx_buff.len = skb->len;
1218 self->tx_buff.data = self->tx_buff.head;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001219
1220 mtt = irda_get_mtt(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221 if (mtt) {
1222 int bofs;
1223
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001224 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225 * Compute how many BOFs (STA or PA's) we need to waste the
1226 * min turn time given the speed of the link.
1227 */
1228 bofs = mtt * (self->io.speed / 1000) / 8000;
1229 if (bofs > 4095)
1230 bofs = 4095;
1231
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001232 smsc_ircc_dma_xmit(self, bofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 } else {
1234 /* Transmit frame */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001235 smsc_ircc_dma_xmit(self, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 spin_unlock_irqrestore(&self->lock, flags);
1239 dev_kfree_skb(skb);
1240
Patrick McHardyec634fe2009-07-05 19:23:38 -07001241 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242}
1243
1244/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001245 * Function smsc_ircc_dma_xmit (self, bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 *
1247 * Transmit data using DMA
1248 *
1249 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001250static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001252 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 u8 ctrl;
1254
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001255 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256#if 1
1257 /* Disable Rx */
1258 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001259 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260#endif
1261 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001262 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1263 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
1265 self->io.direction = IO_XMIT;
1266
1267 /* Set BOF additional count for generating the min turn time */
1268 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001269 outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
1270 ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
1271 outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 /* Set max Tx frame size */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001274 outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
1275 outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276
1277 /*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001278
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 /* Enable burst mode chip Tx DMA */
1280 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001281 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1282 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 /* Setup DMA controller (must be done after enabling chip DMA) */
1285 irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
1286 DMA_TX_MODE);
1287
1288 /* Enable interrupt */
1289
1290 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001291 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1292 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001293
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294 /* Enable transmit */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001295 outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296}
1297
1298/*
1299 * Function smsc_ircc_dma_xmit_complete (self)
1300 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001301 * The transfer of a frame in finished. This function will only be called
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 * by the interrupt handler
1303 *
1304 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001305static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001307 int iobase = self->io.fir_base;
1308
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001309 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310#if 0
1311 /* Disable Tx */
1312 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001313 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314#endif
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001315 register_bank(iobase, 1);
1316 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1317 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
1319 /* Check for underrun! */
1320 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001321 if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001322 self->netdev->stats.tx_errors++;
1323 self->netdev->stats.tx_fifo_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
1325 /* Reset error condition */
1326 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001327 outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
1328 outb(0x00, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 } else {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001330 self->netdev->stats.tx_packets++;
1331 self->netdev->stats.tx_bytes += self->tx_buff.len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333
1334 /* Check if it's time to change the speed */
1335 if (self->new_speed) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001336 smsc_ircc_change_speed(self, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 self->new_speed = 0;
1338 }
1339
1340 netif_wake_queue(self->netdev);
1341}
1342
1343/*
1344 * Function smsc_ircc_dma_receive(self)
1345 *
1346 * Get ready for receiving a frame. The device will initiate a DMA
1347 * if it starts to receive a frame.
1348 *
1349 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001350static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001352 int iobase = self->io.fir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353#if 0
1354 /* Turn off chip DMA */
1355 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001356 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1357 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358#endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 /* Disable Tx */
1361 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001362 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363
1364 /* Turn off chip DMA */
1365 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001366 outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
1367 iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368
1369 self->io.direction = IO_RECV;
1370 self->rx_buff.data = self->rx_buff.head;
1371
1372 /* Set max Rx frame size */
1373 register_bank(iobase, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001374 outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
1375 outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
1377 /* Setup DMA controller */
1378 irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
1379 DMA_RX_MODE);
1380
1381 /* Enable burst mode chip Rx DMA */
1382 register_bank(iobase, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001383 outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
1384 IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
1386 /* Enable interrupt */
1387 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001388 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
1389 outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390
1391 /* Enable receiver */
1392 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001393 outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001394 iobase + IRCC_LCR_B);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001395
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 return 0;
1397}
1398
1399/*
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001400 * Function smsc_ircc_dma_receive_complete(self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 *
1402 * Finished with receiving frames
1403 *
1404 */
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001405static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406{
1407 struct sk_buff *skb;
1408 int len, msgcnt, lsr;
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001409 int iobase = self->io.fir_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001410
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 register_bank(iobase, 0);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001412
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001413 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414#if 0
1415 /* Disable Rx */
1416 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001417 outb(0x00, iobase + IRCC_LCR_B);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418#endif
1419 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001420 outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
1421 lsr= inb(iobase + IRCC_LSR);
1422 msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001424 IRDA_DEBUG(2, "%s: dma count = %d\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 get_dma_residue(self->io.dma));
1426
1427 len = self->rx_buff.truesize - get_dma_residue(self->io.dma);
1428
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001429 /* Look for errors */
1430 if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001431 self->netdev->stats.rx_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001432 if (lsr & IRCC_LSR_FRAME_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001433 self->netdev->stats.rx_frame_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001434 if (lsr & IRCC_LSR_CRC_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001435 self->netdev->stats.rx_crc_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001436 if (lsr & IRCC_LSR_SIZE_ERROR)
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001437 self->netdev->stats.rx_length_errors++;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001438 if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001439 self->netdev->stats.rx_length_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 return;
1441 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001443 /* Remove CRC */
1444 len -= self->io.speed < 4000000 ? 2 : 4;
1445
1446 if (len < 2 || len > 2050) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001447 IRDA_WARNING("%s(), bogus len=%d\n", __func__, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 return;
1449 }
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001450 IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __func__, msgcnt, len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001452 skb = dev_alloc_skb(len + 1);
1453 if (!skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001454 IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001455 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 return;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001457 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458 /* Make sure IP header gets aligned */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001459 skb_reserve(skb, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 memcpy(skb_put(skb, len), self->rx_buff.data, len);
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001462 self->netdev->stats.rx_packets++;
1463 self->netdev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464
1465 skb->dev = self->netdev;
Arnaldo Carvalho de Melo459a98e2007-03-19 15:30:44 -07001466 skb_reset_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 skb->protocol = htons(ETH_P_IRDA);
1468 netif_rx(skb);
1469}
1470
1471/*
1472 * Function smsc_ircc_sir_receive (self)
1473 *
1474 * Receive one frame from the infrared port
1475 *
1476 */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001477static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478{
1479 int boguscount = 0;
1480 int iobase;
1481
1482 IRDA_ASSERT(self != NULL, return;);
1483
1484 iobase = self->io.sir_base;
1485
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001486 /*
1487 * Receive all characters in Rx FIFO, unwrap and unstuff them.
1488 * async_unwrap_char will deliver all found frames
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 */
1490 do {
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001491 async_unwrap_char(self->netdev, &self->netdev->stats, &self->rx_buff,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001492 inb(iobase + UART_RX));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493
1494 /* Make sure we don't stay here to long */
1495 if (boguscount++ > 32) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001496 IRDA_DEBUG(2, "%s(), breaking!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 break;
1498 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001499 } while (inb(iobase + UART_LSR) & UART_LSR_DR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500}
1501
1502
1503/*
1504 * Function smsc_ircc_interrupt (irq, dev_id, regs)
1505 *
1506 * An interrupt from the chip has arrived. Time to do some work
1507 *
1508 */
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001509static irqreturn_t smsc_ircc_interrupt(int dummy, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510{
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001511 struct net_device *dev = dev_id;
1512 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 int iobase, iir, lcra, lsr;
1514 irqreturn_t ret = IRQ_NONE;
1515
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 /* Serialise the interrupt handler in various CPUs, stop Tx path */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001517 spin_lock(&self->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
1519 /* Check if we should use the SIR interrupt handler */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001520 if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 ret = smsc_ircc_interrupt_sir(dev);
1522 goto irq_ret_unlock;
1523 }
1524
1525 iobase = self->io.fir_base;
1526
1527 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001528 iir = inb(iobase + IRCC_IIR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001529 if (iir == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 goto irq_ret_unlock;
1531 ret = IRQ_HANDLED;
1532
1533 /* Disable interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001534 outb(0, iobase + IRCC_IER);
1535 lcra = inb(iobase + IRCC_LCR_A);
1536 lsr = inb(iobase + IRCC_LSR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001537
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001538 IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __func__, iir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
1540 if (iir & IRCC_IIR_EOM) {
1541 if (self->io.direction == IO_RECV)
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001542 smsc_ircc_dma_receive_complete(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 else
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001544 smsc_ircc_dma_xmit_complete(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001545
Dmitry Torokhov80a90582005-09-06 15:19:21 -07001546 smsc_ircc_dma_receive(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
1548
1549 if (iir & IRCC_IIR_ACTIVE_FRAME) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001550 /*printk(KERN_WARNING "%s(): Active Frame\n", __func__);*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 }
1552
1553 /* Enable interrupts again */
1554
1555 register_bank(iobase, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001556 outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
1558 irq_ret_unlock:
1559 spin_unlock(&self->lock);
Jeff Garzik28fc1f52007-10-29 05:46:16 -04001560
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 return ret;
1562}
1563
1564/*
David Howells7d12e782006-10-05 14:55:46 +01001565 * Function irport_interrupt_sir (irq, dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 *
1567 * Interrupt handler for SIR modes
1568 */
1569static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
1570{
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001571 struct smsc_ircc_cb *self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 int boguscount = 0;
1573 int iobase;
1574 int iir, lsr;
1575
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001576 /* Already locked coming here in smsc_ircc_interrupt() */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 /*spin_lock(&self->lock);*/
1578
1579 iobase = self->io.sir_base;
1580
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001581 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 if (iir == 0)
1583 return IRQ_NONE;
1584 while (iir) {
1585 /* Clear interrupt */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001586 lsr = inb(iobase + UART_LSR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001588 IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001589 __func__, iir, lsr, iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
1591 switch (iir) {
1592 case UART_IIR_RLSI:
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001593 IRDA_DEBUG(2, "%s(), RLSI\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 break;
1595 case UART_IIR_RDI:
1596 /* Receive interrupt */
1597 smsc_ircc_sir_receive(self);
1598 break;
1599 case UART_IIR_THRI:
1600 if (lsr & UART_LSR_THRE)
1601 /* Transmitter ready for data */
1602 smsc_ircc_sir_write_wakeup(self);
1603 break;
1604 default:
1605 IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001606 __func__, iir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001608 }
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 /* Make sure we don't stay here to long */
1611 if (boguscount++ > 100)
1612 break;
1613
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001614 iir = inb(iobase + UART_IIR) & UART_IIR_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 }
1616 /*spin_unlock(&self->lock);*/
1617 return IRQ_HANDLED;
1618}
1619
1620
1621#if 0 /* unused */
1622/*
1623 * Function ircc_is_receiving (self)
1624 *
1625 * Return TRUE is we are currently receiving a frame
1626 *
1627 */
1628static int ircc_is_receiving(struct smsc_ircc_cb *self)
1629{
1630 int status = FALSE;
1631 /* int iobase; */
1632
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001633 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634
1635 IRDA_ASSERT(self != NULL, return FALSE;);
1636
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001637 IRDA_DEBUG(0, "%s: dma count = %d\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 get_dma_residue(self->io.dma));
1639
1640 status = (self->rx_buff.state != OUTSIDE_FRAME);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001641
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 return status;
1643}
1644#endif /* unused */
1645
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001646static int smsc_ircc_request_irq(struct smsc_ircc_cb *self)
1647{
1648 int error;
1649
1650 error = request_irq(self->io.irq, smsc_ircc_interrupt, 0,
1651 self->netdev->name, self->netdev);
1652 if (error)
1653 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d, err=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001654 __func__, self->io.irq, error);
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001655
1656 return error;
1657}
1658
1659static void smsc_ircc_start_interrupts(struct smsc_ircc_cb *self)
1660{
1661 unsigned long flags;
1662
1663 spin_lock_irqsave(&self->lock, flags);
1664
1665 self->io.speed = 0;
1666 smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
1667
1668 spin_unlock_irqrestore(&self->lock, flags);
1669}
1670
1671static void smsc_ircc_stop_interrupts(struct smsc_ircc_cb *self)
1672{
1673 int iobase = self->io.fir_base;
1674 unsigned long flags;
1675
1676 spin_lock_irqsave(&self->lock, flags);
1677
1678 register_bank(iobase, 0);
1679 outb(0, iobase + IRCC_IER);
1680 outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
1681 outb(0x00, iobase + IRCC_MASTER);
1682
1683 spin_unlock_irqrestore(&self->lock, flags);
1684}
1685
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
1687/*
1688 * Function smsc_ircc_net_open (dev)
1689 *
1690 * Start the device
1691 *
1692 */
1693static int smsc_ircc_net_open(struct net_device *dev)
1694{
1695 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 char hwname[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001698 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001699
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001701 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001703
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001704 if (self->io.suspended) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001705 IRDA_DEBUG(0, "%s(), device is suspended\n", __func__);
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001706 return -EAGAIN;
1707 }
1708
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001709 if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 (void *) dev)) {
1711 IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001712 __func__, self->io.irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 return -EAGAIN;
1714 }
1715
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001716 smsc_ircc_start_interrupts(self);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001717
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 /* Give self a hardware name */
1719 /* It would be cool to offer the chip revision here - Jean II */
1720 sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);
1721
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001722 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 * Open new IrLAP layer instance, now that everything should be
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001724 * initialized properly
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 */
1726 self->irlap = irlap_open(dev, &self->qos, hwname);
1727
1728 /*
1729 * Always allocate the DMA channel after the IRQ,
1730 * and clean up on failure.
1731 */
1732 if (request_dma(self->io.dma, dev->name)) {
1733 smsc_ircc_net_close(dev);
1734
1735 IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001736 __func__, self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737 return -EAGAIN;
1738 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001739
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 netif_start_queue(dev);
1741
1742 return 0;
1743}
1744
1745/*
1746 * Function smsc_ircc_net_close (dev)
1747 *
1748 * Stop the device
1749 *
1750 */
1751static int smsc_ircc_net_close(struct net_device *dev)
1752{
1753 struct smsc_ircc_cb *self;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001755 IRDA_DEBUG(1, "%s\n", __func__);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001756
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 IRDA_ASSERT(dev != NULL, return -1;);
Dmitry Torokhovda0841a2005-09-06 15:19:23 -07001758 self = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 IRDA_ASSERT(self != NULL, return 0;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001760
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 /* Stop device */
1762 netif_stop_queue(dev);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001763
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 /* Stop and remove instance of IrLAP */
1765 if (self->irlap)
1766 irlap_close(self->irlap);
1767 self->irlap = NULL;
1768
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001769 smsc_ircc_stop_interrupts(self);
1770
1771 /* if we are called from smsc_ircc_resume we don't have IRQ reserved */
1772 if (!self->io.suspended)
1773 free_irq(self->io.irq, dev);
1774
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 disable_dma(self->io.dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776 free_dma(self->io.dma);
1777
1778 return 0;
1779}
1780
Russell King3ae5eae2005-11-09 22:32:44 +00001781static int smsc_ircc_suspend(struct platform_device *dev, pm_message_t state)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782{
Russell King3ae5eae2005-11-09 22:32:44 +00001783 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001784
Russell King9480e302005-10-28 09:52:56 -07001785 if (!self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001786 IRDA_DEBUG(1, "%s, Suspending\n", driver_name);
1787
1788 rtnl_lock();
1789 if (netif_running(self->netdev)) {
1790 netif_device_detach(self->netdev);
1791 smsc_ircc_stop_interrupts(self);
1792 free_irq(self->io.irq, self->netdev);
1793 disable_dma(self->io.dma);
1794 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001795 self->io.suspended = 1;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001796 rtnl_unlock();
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001797 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001798
1799 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
Russell King3ae5eae2005-11-09 22:32:44 +00001802static int smsc_ircc_resume(struct platform_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803{
Russell King3ae5eae2005-11-09 22:32:44 +00001804 struct smsc_ircc_cb *self = platform_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805
Russell King9480e302005-10-28 09:52:56 -07001806 if (self->io.suspended) {
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001807 IRDA_DEBUG(1, "%s, Waking up\n", driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001809 rtnl_lock();
1810 smsc_ircc_init_chip(self);
1811 if (netif_running(self->netdev)) {
1812 if (smsc_ircc_request_irq(self)) {
1813 /*
1814 * Don't fail resume process, just kill this
1815 * network interface
1816 */
1817 unregister_netdevice(self->netdev);
1818 } else {
1819 enable_dma(self->io.dma);
1820 smsc_ircc_start_interrupts(self);
1821 netif_device_attach(self->netdev);
1822 }
1823 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001824 self->io.suspended = 0;
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001825 rtnl_unlock();
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 return 0;
1828}
1829
1830/*
1831 * Function smsc_ircc_close (self)
1832 *
1833 * Close driver instance
1834 *
1835 */
1836static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
1837{
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001838 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001839
1840 IRDA_ASSERT(self != NULL, return -1;);
1841
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001842 platform_device_unregister(self->pldev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843
1844 /* Remove netdevice */
1845 unregister_netdev(self->netdev);
1846
Dmitry Torokhove812cb52005-10-30 15:00:14 -08001847 smsc_ircc_stop_interrupts(self);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848
1849 /* Release the PORTS that this driver is using */
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001850 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 self->io.fir_base);
1852
1853 release_region(self->io.fir_base, self->io.fir_ext);
1854
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001855 IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 self->io.sir_base);
1857
1858 release_region(self->io.sir_base, self->io.sir_ext);
1859
1860 if (self->tx_buff.head)
1861 dma_free_coherent(NULL, self->tx_buff.truesize,
1862 self->tx_buff.head, self->tx_buff_dma);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001863
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 if (self->rx_buff.head)
1865 dma_free_coherent(NULL, self->rx_buff.truesize,
1866 self->rx_buff.head, self->rx_buff_dma);
1867
1868 free_netdev(self->netdev);
1869
1870 return 0;
1871}
1872
1873static void __exit smsc_ircc_cleanup(void)
1874{
1875 int i;
1876
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001877 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001879 for (i = 0; i < 2; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 if (dev_self[i])
1881 smsc_ircc_close(dev_self[i]);
1882 }
Dmitry Torokhov6bb3b2c2005-09-06 15:19:22 -07001883
Bjorn Helgaasd0d4f692007-05-08 00:36:05 -07001884 if (pnp_driver_registered)
1885 pnp_unregister_driver(&smsc_ircc_pnp_driver);
1886
Russell King3ae5eae2005-11-09 22:32:44 +00001887 platform_driver_unregister(&smsc_ircc_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888}
1889
1890/*
1891 * Start SIR operations
1892 *
1893 * This function *must* be called with spinlock held, because it may
1894 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
1895 */
Hannes Eder0e49e642008-12-26 00:03:19 -08001896static void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897{
1898 struct net_device *dev;
1899 int fir_base, sir_base;
1900
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001901 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001903 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001904 dev = self->netdev;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001905 IRDA_ASSERT(dev != NULL, return;);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
1907 fir_base = self->io.fir_base;
1908 sir_base = self->io.sir_base;
1909
1910 /* Reset everything */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001911 outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 #if SMSC_IRCC2_C_SIR_STOP
1914 /*smsc_ircc_sir_stop(self);*/
1915 #endif
1916
1917 register_bank(fir_base, 1);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001918 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 -07001919
1920 /* Initialize UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001921 outb(UART_LCR_WLEN8, sir_base + UART_LCR); /* Reset DLAB */
1922 outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001923
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 /* Turn on interrups */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001925 outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001927 IRDA_DEBUG(3, "%s() - exit\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001929 outb(0x00, fir_base + IRCC_MASTER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930}
1931
1932#if SMSC_IRCC2_C_SIR_STOP
1933void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
1934{
1935 int iobase;
1936
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001937 IRDA_DEBUG(3, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 iobase = self->io.sir_base;
1939
1940 /* Reset UART */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001941 outb(0, iobase + UART_MCR);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001942
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 /* Turn off interrupts */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001944 outb(0, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945}
1946#endif
1947
1948/*
1949 * Function smsc_sir_write_wakeup (self)
1950 *
1951 * Called by the SIR interrupt handler when there's room for more data.
1952 * If we have more packets to send, we send them here.
1953 *
1954 */
1955static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
1956{
1957 int actual = 0;
1958 int iobase;
1959 int fcr;
1960
1961 IRDA_ASSERT(self != NULL, return;);
1962
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001963 IRDA_DEBUG(4, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964
1965 iobase = self->io.sir_base;
1966
1967 /* Finished with frame? */
1968 if (self->tx_buff.len > 0) {
1969 /* Write data left in transmit buffer */
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001970 actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 self->tx_buff.data, self->tx_buff.len);
1972 self->tx_buff.data += actual;
1973 self->tx_buff.len -= actual;
1974 } else {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001975
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976 /*if (self->tx_buff.len ==0) {*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07001977
1978 /*
1979 * Now serial buffer is almost free & we can start
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980 * transmission of another packet. But first we must check
1981 * if we need to change the speed of the hardware
1982 */
1983 if (self->new_speed) {
1984 IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07001985 __func__, self->new_speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 smsc_ircc_sir_wait_hw_transmitter_finish(self);
1987 smsc_ircc_change_speed(self, self->new_speed);
1988 self->new_speed = 0;
1989 } else {
1990 /* Tell network layer that we want more frames */
1991 netif_wake_queue(self->netdev);
1992 }
Stephen Hemmingeraf049082009-01-06 10:40:43 -08001993 self->netdev->stats.tx_packets++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
Dmitry Torokhov98b77772005-09-06 15:19:19 -07001995 if (self->io.speed <= 115200) {
1996 /*
1997 * Reset Rx FIFO to make sure that all reflected transmit data
1998 * is discarded. This is needed for half duplex operation
1999 */
2000 fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
2001 fcr |= self->io.speed < 38400 ?
2002 UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002004 outb(fcr, iobase + UART_FCR);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002006 /* Turn on receive interrupts */
2007 outb(UART_IER_RDI, iobase + UART_IER);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 }
2009 }
2010}
2011
2012/*
2013 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
2014 *
2015 * Fill Tx FIFO with transmit data
2016 *
2017 */
2018static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
2019{
2020 int actual = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002021
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 /* Tx FIFO should be empty! */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002023 if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002024 IRDA_WARNING("%s(), failed, fifo not empty!\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 return 0;
2026 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002027
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 /* Fill FIFO with current frame */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002029 while (fifo_size-- > 0 && actual < len) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 /* Transmit next byte */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002031 outb(buf[actual], iobase + UART_TX);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 actual++;
2033 }
2034 return actual;
2035}
2036
2037/*
2038 * Function smsc_ircc_is_receiving (self)
2039 *
2040 * Returns true is we are currently receiving data
2041 *
2042 */
2043static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
2044{
Eric Dumazet807540b2010-09-23 05:40:09 +00002045 return self->rx_buff.state != OUTSIDE_FRAME;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
2048
2049/*
2050 * Function smsc_ircc_probe_transceiver(self)
2051 *
2052 * Tries to find the used Transceiver
2053 *
2054 */
2055static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
2056{
2057 unsigned int i;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002058
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 IRDA_ASSERT(self != NULL, return;);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002060
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002061 for (i = 0; smsc_transceivers[i].name != NULL; i++)
2062 if (smsc_transceivers[i].probe(self->io.fir_base)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 IRDA_MESSAGE(" %s transceiver found\n",
2064 smsc_transceivers[i].name);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002065 self->transceiver= i + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 return;
2067 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
2070 smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002071
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002072 self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073}
2074
2075
2076/*
2077 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
2078 *
2079 * Set the transceiver according to the speed
2080 *
2081 */
2082static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
2083{
2084 unsigned int trx;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 trx = self->transceiver;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002087 if (trx > 0)
2088 smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
2091/*
2092 * Function smsc_ircc_wait_hw_transmitter_finish ()
2093 *
2094 * Wait for the real end of HW transmission
2095 *
2096 * The UART is a strict FIFO, and we get called only when we have finished
2097 * pushing data to the FIFO, so the maximum amount of time we must wait
2098 * is only for the FIFO to drain out.
2099 *
2100 * We use a simple calibrated loop. We may need to adjust the loop
2101 * delay (udelay) to balance I/O traffic and latency. And we also need to
2102 * adjust the maximum timeout.
2103 * It would probably be better to wait for the proper interrupt,
2104 * but it doesn't seem to be available.
2105 *
2106 * We can't use jiffies or kernel timers because :
2107 * 1) We are called from the interrupt handler, which disable softirqs,
2108 * so jiffies won't be increased
2109 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
2110 * want to wait that long to detect stuck hardware.
2111 * Jean II
2112 */
2113
2114static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
2115{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002116 int iobase = self->io.sir_base;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002118
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 /* Calibrated busy loop */
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002120 while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 udelay(1);
2122
Roel Kluinadbf7f02009-06-05 12:54:44 +02002123 if (count < 0)
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002124 IRDA_DEBUG(0, "%s(): stuck transmitter\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
2127
2128/* PROBING
2129 *
David Brownelld94c77b2006-05-09 15:26:11 -07002130 * REVISIT we can be told about the device by PNP, and should use that info
2131 * instead of probing hardware and creating a platform_device ...
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 */
2133
2134static int __init smsc_ircc_look_for_chips(void)
2135{
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002136 struct smsc_chip_address *address;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002137 char *type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 unsigned int cfg_base, found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002139
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 found = 0;
2141 address = possible_addresses;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002142
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002143 while (address->cfg_base) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 cfg_base = address->cfg_base;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002145
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002146 /*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __func__, cfg_base, address->type);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002147
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002148 if (address->type & SMSCSIO_TYPE_FDC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 type = "FDC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002150 if (address->type & SMSCSIO_TYPE_FLAT)
2151 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
2152 found++;
2153
2154 if (address->type & SMSCSIO_TYPE_PAGED)
2155 if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
2156 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157 }
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002158 if (address->type & SMSCSIO_TYPE_LPC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 type = "LPC";
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002160 if (address->type & SMSCSIO_TYPE_FLAT)
2161 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
2162 found++;
2163
2164 if (address->type & SMSCSIO_TYPE_PAGED)
2165 if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
2166 found++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 }
2168 address++;
2169 }
2170 return found;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002171}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173/*
2174 * Function smsc_superio_flat (chip, base, type)
2175 *
2176 * Try to get configuration of a smc SuperIO chip with flat register model
2177 *
2178 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002179static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
2181 unsigned short firbase, sirbase;
2182 u8 mode, dma, irq;
2183 int ret = -ENODEV;
2184
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002185 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002187 if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 return ret;
2189
2190 outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002191 mode = inb(cfgbase + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002192
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002193 /*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __func__, mode);*/
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002194
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002195 if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002196 IRDA_WARNING("%s(): IrDA not enabled\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
2198 outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002199 sirbase = inb(cfgbase + 1) << 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002201 /* FIR iobase */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002203 firbase = inb(cfgbase + 1) << 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
2205 /* DMA */
2206 outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002207 dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002208
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 /* IRQ */
2210 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002211 irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002213 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 -07002214
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002215 if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
2216 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002217
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 /* Exit configuration */
2219 outb(SMSCSIO_CFGEXITKEY, cfgbase);
2220
2221 return ret;
2222}
2223
2224/*
2225 * Function smsc_superio_paged (chip, base, type)
2226 *
2227 * Try to get configuration of a smc SuperIO chip with paged register model
2228 *
2229 */
Dmitry Torokhovb6158d22005-09-06 15:19:20 -07002230static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231{
2232 unsigned short fir_io, sir_io;
2233 int ret = -ENODEV;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002234
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002235 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002237 if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 return ret;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 /* Select logical device (UART2) */
2241 outb(0x07, cfg_base);
2242 outb(0x05, cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002243
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 /* SIR iobase */
2245 outb(0x60, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002246 sir_io = inb(cfg_base + 1) << 8;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 outb(0x61, cfg_base);
2248 sir_io |= inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002249
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 /* Read FIR base */
2251 outb(0x62, cfg_base);
2252 fir_io = inb(cfg_base + 1) << 8;
2253 outb(0x63, cfg_base);
2254 fir_io |= inb(cfg_base + 1);
2255 outb(0x2b, cfg_base); /* ??? */
2256
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002257 if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
2258 ret = 0;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002259
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260 /* Exit configuration */
2261 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2262
2263 return ret;
2264}
2265
2266
David S. Miller948252c2011-05-31 19:27:48 -07002267static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268{
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002269 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270
2271 outb(reg, cfg_base);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002272 return inb(cfg_base) != reg ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273}
2274
David S. Miller948252c2011-05-31 19:27:48 -07002275static 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 -07002276{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002277 u8 devid, xdevid, rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002279 IRDA_DEBUG(1, "%s\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
2281 /* Leave configuration */
2282
2283 outb(SMSCSIO_CFGEXITKEY, cfg_base);
2284
2285 if (inb(cfg_base) == SMSCSIO_CFGEXITKEY) /* not a smc superio chip */
2286 return NULL;
2287
2288 outb(reg, cfg_base);
2289
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002290 xdevid = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
2292 /* Enter configuration */
2293
2294 outb(SMSCSIO_CFGACCESSKEY, cfg_base);
2295
2296 #if 0
2297 if (smsc_access(cfg_base,0x55)) /* send second key and check */
2298 return NULL;
2299 #endif
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002300
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 /* probe device ID */
2302
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002303 if (smsc_access(cfg_base, reg))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 return NULL;
2305
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002306 devid = inb(cfg_base + 1);
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002307
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002308 if (devid == 0 || devid == 0xff) /* typical values for unused port */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 return NULL;
2310
2311 /* probe revision ID */
2312
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002313 if (smsc_access(cfg_base, reg + 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 return NULL;
2315
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002316 rev = inb(cfg_base + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002318 if (rev >= 128) /* i think this will make no sense */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 return NULL;
2320
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002321 if (devid == xdevid) /* protection against false positives */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 return NULL;
2323
2324 /* Check for expected device ID; are there others? */
2325
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002326 while (chip->devid != devid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
2328 chip++;
2329
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002330 if (chip->name == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 return NULL;
2332 }
2333
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002334 IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
2335 devid, rev, cfg_base, type, chip->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002337 if (chip->rev > rev) {
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002338 IRDA_MESSAGE("Revision higher than expected\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 return NULL;
2340 }
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002341
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002342 if (chip->flags & NoIRDA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 IRDA_MESSAGE("chipset does not support IRDA\n");
2344
2345 return chip;
2346}
2347
2348static int __init smsc_superio_fdc(unsigned short cfg_base)
2349{
2350 int ret = -1;
2351
2352 if (!request_region(cfg_base, 2, driver_name)) {
2353 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002354 __func__, cfg_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002356 if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
2357 !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 ret = 0;
2359
2360 release_region(cfg_base, 2);
2361 }
2362
2363 return ret;
2364}
2365
2366static int __init smsc_superio_lpc(unsigned short cfg_base)
2367{
2368 int ret = -1;
2369
2370 if (!request_region(cfg_base, 2, driver_name)) {
2371 IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002372 __func__, cfg_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 } else {
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002374 if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
2375 !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 ret = 0;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 release_region(cfg_base, 2);
2379 }
2380 return ret;
2381}
2382
Linus Walleijc1e14a62006-04-05 22:33:59 -07002383/*
2384 * Look for some specific subsystem setups that need
2385 * pre-configuration not properly done by the BIOS (especially laptops)
2386 * This code is based in part on smcinit.c, tosh1800-smcinit.c
2387 * and tosh2450-smcinit.c. The table lists the device entries
Linus Walleij08d09992006-04-14 16:03:33 -07002388 * for ISA bridges with an LPC (Low Pin Count) controller which
2389 * handles the communication with the SMSC device. After the LPC
2390 * controller is initialized through PCI, the SMSC device is initialized
2391 * through a dedicated port in the ISA port-mapped I/O area, this latter
2392 * area is used to configure the SMSC device with default
2393 * SIR and FIR I/O ports, DMA and IRQ. Different vendors have
2394 * used different sets of parameters and different control port
2395 * addresses making a subsystem device table necessary.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002396 */
2397#ifdef CONFIG_PCI
David S. Miller948252c2011-05-31 19:27:48 -07002398static struct smsc_ircc_subsystem_configuration subsystem_configurations[] __initdata = {
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002399 /*
2400 * Subsystems needing entries:
2401 * 0x10b9:0x1533 0x103c:0x0850 HP nx9010 family
2402 * 0x10b9:0x1533 0x0e11:0x005a Compaq nc4000 family
2403 * 0x8086:0x24cc 0x0e11:0x002a HP nx9000 family
2404 */
2405 {
2406 /* Guessed entry */
Jon Mason5ee5a072011-08-03 06:42:42 +00002407 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002408 .device = 0x24cc,
2409 .subvendor = 0x103c,
2410 .subdevice = 0x08bc,
2411 .sir_io = 0x02f8,
2412 .fir_io = 0x0130,
2413 .fir_irq = 0x05,
2414 .fir_dma = 0x03,
2415 .cfg_base = 0x004e,
2416 .preconfigure = preconfigure_through_82801,
2417 .name = "HP nx5000 family",
2418 },
Linus Walleijc1e14a62006-04-05 22:33:59 -07002419 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002420 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002421 .device = 0x24cc,
2422 .subvendor = 0x103c,
2423 .subdevice = 0x088c,
Linus Walleij08d09992006-04-14 16:03:33 -07002424 /* Quite certain these are the same for nc8000 as for nc6000 */
2425 .sir_io = 0x02f8,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002426 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002427 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002428 .fir_dma = 0x03,
2429 .cfg_base = 0x004e,
2430 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002431 .name = "HP nc8000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002432 },
2433 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002434 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002435 .device = 0x24cc,
2436 .subvendor = 0x103c,
2437 .subdevice = 0x0890,
2438 .sir_io = 0x02f8,
2439 .fir_io = 0x0130,
Linus Walleij08d09992006-04-14 16:03:33 -07002440 .fir_irq = 0x05,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002441 .fir_dma = 0x03,
2442 .cfg_base = 0x004e,
2443 .preconfigure = preconfigure_through_82801,
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002444 .name = "HP nc6000 family",
2445 },
2446 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002447 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801DBM LPC bridge */
Linus Walleij (LD/EAB895de092006-09-27 22:49:23 -07002448 .device = 0x24cc,
2449 .subvendor = 0x0e11,
2450 .subdevice = 0x0860,
2451 /* I assume these are the same for x1000 as for the others */
2452 .sir_io = 0x02e8,
2453 .fir_io = 0x02f8,
2454 .fir_irq = 0x07,
2455 .fir_dma = 0x03,
2456 .cfg_base = 0x002e,
2457 .preconfigure = preconfigure_through_82801,
2458 .name = "Compaq x1000 family",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002459 },
2460 {
Linus Walleij08d09992006-04-14 16:03:33 -07002461 /* Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge */
Jon Mason5ee5a072011-08-03 06:42:42 +00002462 .vendor = PCI_VENDOR_ID_INTEL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002463 .device = 0x24c0,
2464 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002465 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002466 .sir_io = 0x03f8,
2467 .fir_io = 0x0130,
2468 .fir_irq = 0x07,
2469 .fir_dma = 0x01,
2470 .cfg_base = 0x002e,
2471 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002472 .name = "Toshiba laptop with Intel 82801DB/DBL LPC bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002473 },
2474 {
Jon Mason5ee5a072011-08-03 06:42:42 +00002475 .vendor = PCI_VENDOR_ID_INTEL, /* Intel 82801CAM ISA bridge */
Linus Walleij08d09992006-04-14 16:03:33 -07002476 .device = 0x248c,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002477 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002478 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002479 .sir_io = 0x03f8,
2480 .fir_io = 0x0130,
2481 .fir_irq = 0x03,
2482 .fir_dma = 0x03,
2483 .cfg_base = 0x002e,
2484 .preconfigure = preconfigure_through_82801,
Linus Walleij08d09992006-04-14 16:03:33 -07002485 .name = "Toshiba laptop with Intel 82801CAM ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002486 },
2487 {
Linus Walleij08d09992006-04-14 16:03:33 -07002488 /* 82801DBM (ICH4-M) LPC Interface Bridge */
Jon Mason5ee5a072011-08-03 06:42:42 +00002489 .vendor = PCI_VENDOR_ID_INTEL,
Linus Walleij08d09992006-04-14 16:03:33 -07002490 .device = 0x24cc,
2491 .subvendor = 0x1179,
2492 .subdevice = 0xffff, /* 0xffff is "any" */
2493 .sir_io = 0x03f8,
2494 .fir_io = 0x0130,
2495 .fir_irq = 0x03,
2496 .fir_dma = 0x03,
2497 .cfg_base = 0x002e,
2498 .preconfigure = preconfigure_through_82801,
2499 .name = "Toshiba laptop with Intel 8281DBM LPC bridge",
2500 },
2501 {
2502 /* ALi M1533/M1535 PCI to ISA Bridge [Aladdin IV/V/V+] */
Jon Mason5ee5a072011-08-03 06:42:42 +00002503 .vendor = PCI_VENDOR_ID_AL,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002504 .device = 0x1533,
2505 .subvendor = 0x1179,
Linus Walleij08d09992006-04-14 16:03:33 -07002506 .subdevice = 0xffff, /* 0xffff is "any" */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002507 .sir_io = 0x02e8,
2508 .fir_io = 0x02f8,
2509 .fir_irq = 0x07,
2510 .fir_dma = 0x03,
2511 .cfg_base = 0x002e,
2512 .preconfigure = preconfigure_through_ali,
Linus Walleij08d09992006-04-14 16:03:33 -07002513 .name = "Toshiba laptop with ALi ISA bridge",
Linus Walleijc1e14a62006-04-05 22:33:59 -07002514 },
2515 { } // Terminator
2516};
2517
2518
2519/*
Linus Walleij08d09992006-04-14 16:03:33 -07002520 * This sets up the basic SMSC parameters
2521 * (FIR port, SIR port, FIR DMA, FIR IRQ)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002522 * through the chip configuration port.
2523 */
David S. Miller948252c2011-05-31 19:27:48 -07002524static int __init preconfigure_smsc_chip(struct
Linus Walleij08d09992006-04-14 16:03:33 -07002525 smsc_ircc_subsystem_configuration
2526 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002527{
2528 unsigned short iobase = conf->cfg_base;
2529 unsigned char tmpbyte;
2530
2531 outb(LPC47N227_CFGACCESSKEY, iobase); // enter configuration state
2532 outb(SMSCSIOFLAT_DEVICEID_REG, iobase); // set for device ID
2533 tmpbyte = inb(iobase +1); // Read device ID
Linus Walleij08d09992006-04-14 16:03:33 -07002534 IRDA_DEBUG(0,
2535 "Detected Chip id: 0x%02x, setting up registers...\n",
2536 tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002537
2538 /* Disable UART1 and set up SIR I/O port */
2539 outb(0x24, iobase); // select CR24 - UART1 base addr
2540 outb(0x00, iobase + 1); // disable UART1
2541 outb(SMSCSIOFLAT_UART2BASEADDR_REG, iobase); // select CR25 - UART2 base addr
2542 outb( (conf->sir_io >> 2), iobase + 1); // bits 2-9 of 0x3f8
2543 tmpbyte = inb(iobase + 1);
2544 if (tmpbyte != (conf->sir_io >> 2) ) {
2545 IRDA_WARNING("ERROR: could not configure SIR ioport.\n");
Linus Walleij08d09992006-04-14 16:03:33 -07002546 IRDA_WARNING("Try to supply ircc_cfg argument.\n");
Linus Walleijc1e14a62006-04-05 22:33:59 -07002547 return -ENXIO;
2548 }
2549
2550 /* Set up FIR IRQ channel for UART2 */
2551 outb(SMSCSIOFLAT_UARTIRQSELECT_REG, iobase); // select CR28 - UART1,2 IRQ select
2552 tmpbyte = inb(iobase + 1);
2553 tmpbyte &= SMSCSIOFLAT_UART1IRQSELECT_MASK; // Do not touch the UART1 portion
2554 tmpbyte |= (conf->fir_irq & SMSCSIOFLAT_UART2IRQSELECT_MASK);
2555 outb(tmpbyte, iobase + 1);
2556 tmpbyte = inb(iobase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
2557 if (tmpbyte != conf->fir_irq) {
2558 IRDA_WARNING("ERROR: could not configure FIR IRQ channel.\n");
2559 return -ENXIO;
2560 }
2561
2562 /* Set up FIR I/O port */
2563 outb(SMSCSIOFLAT_FIRBASEADDR_REG, iobase); // CR2B - SCE (FIR) base addr
2564 outb((conf->fir_io >> 3), iobase + 1);
2565 tmpbyte = inb(iobase + 1);
2566 if (tmpbyte != (conf->fir_io >> 3) ) {
2567 IRDA_WARNING("ERROR: could not configure FIR I/O port.\n");
2568 return -ENXIO;
2569 }
2570
2571 /* Set up FIR DMA channel */
2572 outb(SMSCSIOFLAT_FIRDMASELECT_REG, iobase); // CR2C - SCE (FIR) DMA select
2573 outb((conf->fir_dma & LPC47N227_FIRDMASELECT_MASK), iobase + 1); // DMA
2574 tmpbyte = inb(iobase + 1) & LPC47N227_FIRDMASELECT_MASK;
2575 if (tmpbyte != (conf->fir_dma & LPC47N227_FIRDMASELECT_MASK)) {
2576 IRDA_WARNING("ERROR: could not configure FIR DMA channel.\n");
2577 return -ENXIO;
2578 }
2579
2580 outb(SMSCSIOFLAT_UARTMODE0C_REG, iobase); // CR0C - UART mode
2581 tmpbyte = inb(iobase + 1);
Linus Walleij08d09992006-04-14 16:03:33 -07002582 tmpbyte &= ~SMSCSIOFLAT_UART2MODE_MASK |
2583 SMSCSIOFLAT_UART2MODE_VAL_IRDA;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002584 outb(tmpbyte, iobase + 1); // enable IrDA (HPSIR) mode, high speed
2585
2586 outb(LPC47N227_APMBOOTDRIVE_REG, iobase); // CR07 - Auto Pwr Mgt/boot drive sel
2587 tmpbyte = inb(iobase + 1);
2588 outb(tmpbyte | LPC47N227_UART2AUTOPWRDOWN_MASK, iobase + 1); // enable UART2 autopower down
2589
2590 /* This one was not part of tosh1800 */
2591 outb(0x0a, iobase); // CR0a - ecp fifo / ir mux
2592 tmpbyte = inb(iobase + 1);
2593 outb(tmpbyte | 0x40, iobase + 1); // send active device to ir port
2594
2595 outb(LPC47N227_UART12POWER_REG, iobase); // CR02 - UART 1,2 power
2596 tmpbyte = inb(iobase + 1);
2597 outb(tmpbyte | LPC47N227_UART2POWERDOWN_MASK, iobase + 1); // UART2 power up mode, UART1 power down
2598
2599 outb(LPC47N227_FDCPOWERVALIDCONF_REG, iobase); // CR00 - FDC Power/valid config cycle
2600 tmpbyte = inb(iobase + 1);
2601 outb(tmpbyte | LPC47N227_VALID_MASK, iobase + 1); // valid config cycle done
2602
2603 outb(LPC47N227_CFGEXITKEY, iobase); // Exit configuration
2604
2605 return 0;
2606}
2607
Linus Walleij08d09992006-04-14 16:03:33 -07002608/* 82801CAM generic registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002609#define VID 0x00
2610#define DID 0x02
Linus Walleij08d09992006-04-14 16:03:33 -07002611#define PIRQ_A_D_ROUT 0x60
2612#define SIRQ_CNTL 0x64
2613#define PIRQ_E_H_ROUT 0x68
Linus Walleijc1e14a62006-04-05 22:33:59 -07002614#define PCI_DMA_C 0x90
Linus Walleij08d09992006-04-14 16:03:33 -07002615/* LPC-specific registers */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002616#define COM_DEC 0xe0
Linus Walleij08d09992006-04-14 16:03:33 -07002617#define GEN1_DEC 0xe4
Linus Walleijc1e14a62006-04-05 22:33:59 -07002618#define LPC_EN 0xe6
2619#define GEN2_DEC 0xec
2620/*
Linus Walleij08d09992006-04-14 16:03:33 -07002621 * Sets up the I/O range using the 82801CAM ISA bridge, 82801DBM LPC bridge
2622 * or Intel 82801DB/DBL (ICH4/ICH4-L) LPC Interface Bridge.
2623 * They all work the same way!
Linus Walleijc1e14a62006-04-05 22:33:59 -07002624 */
David S. Miller948252c2011-05-31 19:27:48 -07002625static int __init preconfigure_through_82801(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002626 struct
2627 smsc_ircc_subsystem_configuration
2628 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002629{
2630 unsigned short tmpword;
Linus Walleij08d09992006-04-14 16:03:33 -07002631 unsigned char tmpbyte;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002632
Linus Walleij08d09992006-04-14 16:03:33 -07002633 IRDA_MESSAGE("Setting up Intel 82801 controller and SMSC device\n");
2634 /*
2635 * Select the range for the COMA COM port (SIR)
2636 * Register COM_DEC:
2637 * Bit 7: reserved
2638 * Bit 6-4, COMB decode range
2639 * Bit 3: reserved
2640 * Bit 2-0, COMA decode range
2641 *
2642 * Decode ranges:
2643 * 000 = 0x3f8-0x3ff (COM1)
2644 * 001 = 0x2f8-0x2ff (COM2)
2645 * 010 = 0x220-0x227
2646 * 011 = 0x228-0x22f
2647 * 100 = 0x238-0x23f
2648 * 101 = 0x2e8-0x2ef (COM4)
2649 * 110 = 0x338-0x33f
2650 * 111 = 0x3e8-0x3ef (COM3)
2651 */
2652 pci_read_config_byte(dev, COM_DEC, &tmpbyte);
2653 tmpbyte &= 0xf8; /* mask COMA bits */
2654 switch(conf->sir_io) {
2655 case 0x3f8:
2656 tmpbyte |= 0x00;
2657 break;
2658 case 0x2f8:
2659 tmpbyte |= 0x01;
2660 break;
2661 case 0x220:
2662 tmpbyte |= 0x02;
2663 break;
2664 case 0x228:
2665 tmpbyte |= 0x03;
2666 break;
2667 case 0x238:
2668 tmpbyte |= 0x04;
2669 break;
2670 case 0x2e8:
2671 tmpbyte |= 0x05;
2672 break;
2673 case 0x338:
2674 tmpbyte |= 0x06;
2675 break;
2676 case 0x3e8:
2677 tmpbyte |= 0x07;
2678 break;
2679 default:
2680 tmpbyte |= 0x01; /* COM2 default */
2681 }
2682 IRDA_DEBUG(1, "COM_DEC (write): 0x%02x\n", tmpbyte);
2683 pci_write_config_byte(dev, COM_DEC, tmpbyte);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002684
Linus Walleij08d09992006-04-14 16:03:33 -07002685 /* Enable Low Pin Count interface */
2686 pci_read_config_word(dev, LPC_EN, &tmpword);
2687 /* These seem to be set up at all times,
2688 * just make sure it is properly set.
2689 */
2690 switch(conf->cfg_base) {
2691 case 0x04e:
2692 tmpword |= 0x2000;
2693 break;
2694 case 0x02e:
2695 tmpword |= 0x1000;
2696 break;
2697 case 0x062:
2698 tmpword |= 0x0800;
2699 break;
2700 case 0x060:
2701 tmpword |= 0x0400;
2702 break;
2703 default:
2704 IRDA_WARNING("Uncommon I/O base address: 0x%04x\n",
2705 conf->cfg_base);
2706 break;
2707 }
2708 tmpword &= 0xfffd; /* disable LPC COMB */
2709 tmpword |= 0x0001; /* set bit 0 : enable LPC COMA addr range (GEN2) */
2710 IRDA_DEBUG(1, "LPC_EN (write): 0x%04x\n", tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002711 pci_write_config_word(dev, LPC_EN, tmpword);
2712
Linus Walleij08d09992006-04-14 16:03:33 -07002713 /*
2714 * Configure LPC DMA channel
2715 * PCI_DMA_C bits:
2716 * Bit 15-14: DMA channel 7 select
2717 * Bit 13-12: DMA channel 6 select
2718 * Bit 11-10: DMA channel 5 select
2719 * Bit 9-8: Reserved
2720 * Bit 7-6: DMA channel 3 select
2721 * Bit 5-4: DMA channel 2 select
2722 * Bit 3-2: DMA channel 1 select
2723 * Bit 1-0: DMA channel 0 select
2724 * 00 = Reserved value
2725 * 01 = PC/PCI DMA
2726 * 10 = Reserved value
2727 * 11 = LPC I/F DMA
2728 */
2729 pci_read_config_word(dev, PCI_DMA_C, &tmpword);
2730 switch(conf->fir_dma) {
2731 case 0x07:
2732 tmpword |= 0xc000;
2733 break;
2734 case 0x06:
2735 tmpword |= 0x3000;
2736 break;
2737 case 0x05:
2738 tmpword |= 0x0c00;
2739 break;
2740 case 0x03:
2741 tmpword |= 0x00c0;
2742 break;
2743 case 0x02:
2744 tmpword |= 0x0030;
2745 break;
2746 case 0x01:
2747 tmpword |= 0x000c;
2748 break;
2749 case 0x00:
2750 tmpword |= 0x0003;
2751 break;
2752 default:
2753 break; /* do not change settings */
2754 }
2755 IRDA_DEBUG(1, "PCI_DMA_C (write): 0x%04x\n", tmpword);
2756 pci_write_config_word(dev, PCI_DMA_C, tmpword);
2757
2758 /*
2759 * GEN2_DEC bits:
2760 * Bit 15-4: Generic I/O range
2761 * Bit 3-1: reserved (read as 0)
2762 * Bit 0: enable GEN2 range on LPC I/F
2763 */
2764 tmpword = conf->fir_io & 0xfff8;
2765 tmpword |= 0x0001;
2766 IRDA_DEBUG(1, "GEN2_DEC (write): 0x%04x\n", tmpword);
2767 pci_write_config_word(dev, GEN2_DEC, tmpword);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002768
2769 /* Pre-configure chip */
Linus Walleij08d09992006-04-14 16:03:33 -07002770 return preconfigure_smsc_chip(conf);
2771}
Linus Walleijc1e14a62006-04-05 22:33:59 -07002772
Linus Walleij08d09992006-04-14 16:03:33 -07002773/*
2774 * Pre-configure a certain port on the ALi 1533 bridge.
2775 * This is based on reverse-engineering since ALi does not
2776 * provide any data sheet for the 1533 chip.
2777 */
David S. Miller948252c2011-05-31 19:27:48 -07002778static void __init preconfigure_ali_port(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002779 unsigned short port)
2780{
2781 unsigned char reg;
2782 /* These bits obviously control the different ports */
2783 unsigned char mask;
2784 unsigned char tmpbyte;
2785
2786 switch(port) {
2787 case 0x0130:
2788 case 0x0178:
2789 reg = 0xb0;
2790 mask = 0x80;
2791 break;
2792 case 0x03f8:
2793 reg = 0xb4;
2794 mask = 0x80;
2795 break;
2796 case 0x02f8:
2797 reg = 0xb4;
2798 mask = 0x30;
2799 break;
2800 case 0x02e8:
2801 reg = 0xb4;
2802 mask = 0x08;
2803 break;
2804 default:
2805 IRDA_ERROR("Failed to configure unsupported port on ALi 1533 bridge: 0x%04x\n", port);
2806 return;
2807 }
2808
2809 pci_read_config_byte(dev, reg, &tmpbyte);
2810 /* Turn on the right bits */
2811 tmpbyte |= mask;
2812 pci_write_config_byte(dev, reg, tmpbyte);
2813 IRDA_MESSAGE("Activated ALi 1533 ISA bridge port 0x%04x.\n", port);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002814}
2815
David S. Miller948252c2011-05-31 19:27:48 -07002816static int __init preconfigure_through_ali(struct pci_dev *dev,
Linus Walleij08d09992006-04-14 16:03:33 -07002817 struct
2818 smsc_ircc_subsystem_configuration
2819 *conf)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002820{
Linus Walleij08d09992006-04-14 16:03:33 -07002821 /* Configure the two ports on the ALi 1533 */
2822 preconfigure_ali_port(dev, conf->sir_io);
2823 preconfigure_ali_port(dev, conf->fir_io);
2824
2825 /* Pre-configure chip */
2826 return preconfigure_smsc_chip(conf);
Linus Walleijc1e14a62006-04-05 22:33:59 -07002827}
2828
David S. Miller948252c2011-05-31 19:27:48 -07002829static int __init smsc_ircc_preconfigure_subsystems(unsigned short ircc_cfg,
Linus Walleijc1e14a62006-04-05 22:33:59 -07002830 unsigned short ircc_fir,
2831 unsigned short ircc_sir,
2832 unsigned char ircc_dma,
2833 unsigned char ircc_irq)
2834{
2835 struct pci_dev *dev = NULL;
2836 unsigned short ss_vendor = 0x0000;
2837 unsigned short ss_device = 0x0000;
2838 int ret = 0;
2839
Kulikov Vasiliy2e4e7a92010-07-03 06:04:15 +00002840 for_each_pci_dev(dev) {
David S. Miller948252c2011-05-31 19:27:48 -07002841 struct smsc_ircc_subsystem_configuration *conf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002842
2843 /*
Linus Walleij08d09992006-04-14 16:03:33 -07002844 * Cache the subsystem vendor/device:
2845 * some manufacturers fail to set this for all components,
2846 * so we save it in case there is just 0x0000 0x0000 on the
2847 * device we want to check.
Linus Walleijc1e14a62006-04-05 22:33:59 -07002848 */
2849 if (dev->subsystem_vendor != 0x0000U) {
2850 ss_vendor = dev->subsystem_vendor;
2851 ss_device = dev->subsystem_device;
2852 }
2853 conf = subsystem_configurations;
2854 for( ; conf->subvendor; conf++) {
2855 if(conf->vendor == dev->vendor &&
2856 conf->device == dev->device &&
Linus Walleij08d09992006-04-14 16:03:33 -07002857 conf->subvendor == ss_vendor &&
2858 /* Sometimes these are cached values */
2859 (conf->subdevice == ss_device ||
2860 conf->subdevice == 0xffff)) {
2861 struct smsc_ircc_subsystem_configuration
2862 tmpconf;
Linus Walleijc1e14a62006-04-05 22:33:59 -07002863
Linus Walleij08d09992006-04-14 16:03:33 -07002864 memcpy(&tmpconf, conf,
2865 sizeof(struct smsc_ircc_subsystem_configuration));
Linus Walleijc1e14a62006-04-05 22:33:59 -07002866
Linus Walleij08d09992006-04-14 16:03:33 -07002867 /*
2868 * Override the default values with anything
2869 * passed in as parameter
2870 */
Linus Walleijc1e14a62006-04-05 22:33:59 -07002871 if (ircc_cfg != 0)
2872 tmpconf.cfg_base = ircc_cfg;
2873 if (ircc_fir != 0)
2874 tmpconf.fir_io = ircc_fir;
2875 if (ircc_sir != 0)
2876 tmpconf.sir_io = ircc_sir;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002877 if (ircc_dma != DMA_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002878 tmpconf.fir_dma = ircc_dma;
Bjorn Helgaas916f11c2007-05-08 00:36:02 -07002879 if (ircc_irq != IRQ_INVAL)
Linus Walleijc1e14a62006-04-05 22:33:59 -07002880 tmpconf.fir_irq = ircc_irq;
2881
2882 IRDA_MESSAGE("Detected unconfigured %s SMSC IrDA chip, pre-configuring device.\n", conf->name);
2883 if (conf->preconfigure)
2884 ret = conf->preconfigure(dev, &tmpconf);
2885 else
2886 ret = -ENODEV;
2887 }
2888 }
Linus Walleijc1e14a62006-04-05 22:33:59 -07002889 }
2890
2891 return ret;
2892}
2893#endif // CONFIG_PCI
2894
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895/************************************************
2896 *
2897 * Transceivers specific functions
2898 *
2899 ************************************************/
2900
2901
2902/*
2903 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
2904 *
2905 * Program transceiver through smsc-ircc ATC circuitry
2906 *
2907 */
2908
2909static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
2910{
2911 unsigned long jiffies_now, jiffies_timeout;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002912 u8 val;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002913
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002914 jiffies_now = jiffies;
2915 jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002916
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917 /* ATC */
2918 register_bank(fir_base, 4);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002919 outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
2920 fir_base + IRCC_ATC);
2921
2922 while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
2923 !time_after(jiffies, jiffies_timeout))
2924 /* empty */;
2925
2926 if (val)
Harvey Harrisona97a6f12008-07-30 17:20:18 -07002927 IRDA_WARNING("%s(): ATC: 0x%02x\n", __func__,
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002928 inb(fir_base + IRCC_ATC));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929}
2930
2931/*
2932 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
2933 *
2934 * Probe transceiver smsc-ircc ATC circuitry
2935 *
2936 */
2937
2938static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
2939{
2940 return 0;
2941}
2942
2943/*
2944 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
2945 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002946 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 *
2948 */
2949
2950static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
2951{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002952 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002953
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002954 switch (speed) {
2955 default:
2956 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002957 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002958 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002959 case 1152000 :
2960 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 fast_mode = IRCC_LCR_A_FAST;
2962 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002963 }
2964 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002965 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966}
2967
2968/*
2969 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
2970 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002971 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 *
2973 */
2974
2975static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
2976{
2977 return 0;
2978}
2979
2980/*
2981 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
2982 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002983 * Set transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 *
2985 */
2986
2987static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
2988{
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002989 u8 fast_mode;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002990
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002991 switch (speed) {
2992 default:
2993 case 576000 :
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07002994 fast_mode = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 break;
Dmitry Torokhov98b77772005-09-06 15:19:19 -07002996 case 1152000 :
2997 case 4000000 :
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
2999 break;
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07003000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 }
3002 /* This causes an interrupt */
3003 register_bank(fir_base, 0);
Dmitry Torokhov98b77772005-09-06 15:19:19 -07003004 outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005}
3006
3007/*
3008 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
3009 *
Dmitry Torokhov527b6af2005-09-06 15:19:17 -07003010 * Probe transceiver
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011 *
3012 */
3013
3014static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
3015{
3016 return 0;
3017}
3018
3019
3020module_init(smsc_ircc_init);
3021module_exit(smsc_ircc_cleanup);