smsc-ircc2.c 59.4 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6
/*********************************************************************
 * $Id: smsc-ircc2.c,v 1.19.2.5 2002/10/27 11:34:26 dip Exp $
 *
 * Description:   Driver for the SMC Infrared Communications Controller
 * Status:        Experimental.
 * Author:        Daniele Peri (peri@csai.unipa.it)
7 8 9 10
 * Created at:
 * Modified at:
 * Modified by:
 *
L
Linus Torvalds 已提交
11 12 13 14 15 16 17 18 19
 *     Copyright (c) 2002      Daniele Peri
 *     All Rights Reserved.
 *     Copyright (c) 2002      Jean Tourrilhes
 *
 *
 * Based on smc-ircc.c:
 *
 *     Copyright (c) 2001      Stefani Seibold
 *     Copyright (c) 1999-2001 Dag Brattli
20
 *     Copyright (c) 1998-1999 Thomas Davis,
L
Linus Torvalds 已提交
21 22 23 24 25
 *
 *	and irport.c:
 *
 *     Copyright (c) 1997, 1998, 1999-2000 Dag Brattli, All Rights Reserved.
 *
26 27 28 29
 *
 *     This program is free software; you can redistribute it and/or
 *     modify it under the terms of the GNU General Public License as
 *     published by the Free Software Foundation; either version 2 of
L
Linus Torvalds 已提交
30
 *     the License, or (at your option) any later version.
31
 *
L
Linus Torvalds 已提交
32 33 34 35
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *     GNU General Public License for more details.
36 37 38 39
 *
 *     You should have received a copy of the GNU General Public License
 *     along with this program; if not, write to the Free Software
 *     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
L
Linus Torvalds 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
 *     MA 02111-1307 USA
 *
 ********************************************************************/

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/rtnetlink.h>
#include <linux/serial_reg.h>
#include <linux/dma-mapping.h>
56
#include <linux/platform_device.h>
L
Linus Torvalds 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71

#include <asm/io.h>
#include <asm/dma.h>
#include <asm/byteorder.h>

#include <linux/spinlock.h>
#include <linux/pm.h>

#include <net/irda/wrapper.h>
#include <net/irda/irda.h>
#include <net/irda/irda_device.h>

#include "smsc-ircc2.h"
#include "smsc-sio.h"

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100

MODULE_AUTHOR("Daniele Peri <peri@csai.unipa.it>");
MODULE_DESCRIPTION("SMC IrCC SIR/FIR controller driver");
MODULE_LICENSE("GPL");

static int ircc_dma = 255;
module_param(ircc_dma, int, 0);
MODULE_PARM_DESC(ircc_dma, "DMA channel");

static int ircc_irq = 255;
module_param(ircc_irq, int, 0);
MODULE_PARM_DESC(ircc_irq, "IRQ line");

static int ircc_fir;
module_param(ircc_fir, int, 0);
MODULE_PARM_DESC(ircc_fir, "FIR Base Address");

static int ircc_sir;
module_param(ircc_sir, int, 0);
MODULE_PARM_DESC(ircc_sir, "SIR Base Address");

static int ircc_cfg;
module_param(ircc_cfg, int, 0);
MODULE_PARM_DESC(ircc_cfg, "Configuration register base address");

static int ircc_transceiver;
module_param(ircc_transceiver, int, 0);
MODULE_PARM_DESC(ircc_transceiver, "Transceiver type");

L
Linus Torvalds 已提交
101 102 103 104
/* Types */

struct smsc_transceiver {
	char *name;
105
	void (*set_for_speed)(int fir_base, u32 speed);
L
Linus Torvalds 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
	int  (*probe)(int fir_base);
};

struct smsc_chip {
	char *name;
	#if 0
	u8	type;
	#endif
	u16 flags;
	u8 devid;
	u8 rev;
};

struct smsc_chip_address {
	unsigned int cfg_base;
	unsigned int type;
};

/* Private data for each instance */
struct smsc_ircc_cb {
	struct net_device *netdev;     /* Yes! we are some kind of netdevice */
	struct net_device_stats stats;
	struct irlap_cb    *irlap; /* The link layer we are binded to */
129

L
Linus Torvalds 已提交
130 131 132 133 134 135 136 137 138
	chipio_t io;               /* IrDA controller information */
	iobuff_t tx_buff;          /* Transmit buffer */
	iobuff_t rx_buff;          /* Receive buffer */
	dma_addr_t tx_buff_dma;
	dma_addr_t rx_buff_dma;

	struct qos_info qos;       /* QoS capabilities for this device */

	spinlock_t lock;           /* For serializing operations */
139

L
Linus Torvalds 已提交
140 141 142 143 144 145 146
	__u32 new_speed;
	__u32 flags;               /* Interface flags */

	int tx_buff_offsets[10];   /* Offsets between frames in tx_buff */
	int tx_len;                /* Number of frames in tx_buff */

	int transceiver;
147
	struct platform_device *pldev;
L
Linus Torvalds 已提交
148 149 150 151
};

/* Constants */

152 153
#define SMSC_IRCC2_DRIVER_NAME			"smsc-ircc2"

L
Linus Torvalds 已提交
154 155
#define SMSC_IRCC2_C_IRDA_FALLBACK_SPEED	9600
#define SMSC_IRCC2_C_DEFAULT_TRANSCEIVER	1
156
#define SMSC_IRCC2_C_NET_TIMEOUT		0
L
Linus Torvalds 已提交
157 158
#define SMSC_IRCC2_C_SIR_STOP			0

159 160
static const char *driver_name = SMSC_IRCC2_DRIVER_NAME;

L
Linus Torvalds 已提交
161 162 163 164 165 166 167 168
/* Prototypes */

static int smsc_ircc_open(unsigned int firbase, unsigned int sirbase, u8 dma, u8 irq);
static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base);
static void smsc_ircc_setup_io(struct smsc_ircc_cb *self, unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq);
static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self);
static void smsc_ircc_init_chip(struct smsc_ircc_cb *self);
static int __exit smsc_ircc_close(struct smsc_ircc_cb *self);
169 170
static int  smsc_ircc_dma_receive(struct smsc_ircc_cb *self);
static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self);
L
Linus Torvalds 已提交
171 172 173
static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self);
static int  smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev);
static int  smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev);
174 175
static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs);
static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self);
176 177
static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed);
static void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, u32 speed);
L
Linus Torvalds 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs);
static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev);
static void smsc_ircc_sir_start(struct smsc_ircc_cb *self);
#if SMSC_IRCC2_C_SIR_STOP
static void smsc_ircc_sir_stop(struct smsc_ircc_cb *self);
#endif
static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self);
static int  smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len);
static int  smsc_ircc_net_open(struct net_device *dev);
static int  smsc_ircc_net_close(struct net_device *dev);
static int  smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
#if SMSC_IRCC2_C_NET_TIMEOUT
static void smsc_ircc_timeout(struct net_device *dev);
#endif
static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev);
static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self);
static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self);
static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed);
static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self);

/* Probing */
static int __init smsc_ircc_look_for_chips(void);
200 201 202
static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type);
static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type);
L
Linus Torvalds 已提交
203 204 205 206 207 208 209 210 211 212 213 214 215 216
static int __init smsc_superio_fdc(unsigned short cfg_base);
static int __init smsc_superio_lpc(unsigned short cfg_base);

/* Transceivers specific functions */

static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed);
static int  smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base);
static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed);
static int  smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base);
static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed);
static int  smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base);

/* Power Management */

217 218
static int smsc_ircc_suspend(struct device *dev, pm_message_t state);
static int smsc_ircc_resume(struct device *dev);
L
Linus Torvalds 已提交
219

220 221 222 223 224 225
static struct device_driver smsc_ircc_driver = {
	.name		= SMSC_IRCC2_DRIVER_NAME,
	.bus		= &platform_bus_type,
	.suspend	= smsc_ircc_suspend,
	.resume		= smsc_ircc_resume,
};
L
Linus Torvalds 已提交
226 227 228

/* Transceivers for SMSC-ircc */

229
static struct smsc_transceiver smsc_transceivers[] =
L
Linus Torvalds 已提交
230
{
231 232 233 234
	{ "Toshiba Satellite 1800 (GP data pin select)", smsc_ircc_set_transceiver_toshiba_sat1800, smsc_ircc_probe_transceiver_toshiba_sat1800 },
	{ "Fast pin select", smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select, smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select },
	{ "ATC IRMode", smsc_ircc_set_transceiver_smsc_ircc_atc, smsc_ircc_probe_transceiver_smsc_ircc_atc },
	{ NULL, NULL }
L
Linus Torvalds 已提交
235
};
236
#define SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS (ARRAY_SIZE(smsc_transceivers) - 1)
L
Linus Torvalds 已提交
237 238 239 240 241 242 243 244 245 246

/*  SMC SuperIO chipsets definitions */

#define	KEY55_1	0	/* SuperIO Configuration mode with Key <0x55> */
#define	KEY55_2	1	/* SuperIO Configuration mode with Key <0x55,0x55> */
#define	NoIRDA	2	/* SuperIO Chip has no IRDA Port */
#define	SIR	0	/* SuperIO Chip has only slow IRDA */
#define	FIR	4	/* SuperIO Chip has fast IRDA */
#define	SERx4	8	/* SuperIO Chip supports 115,2 KBaud * 4=460,8 KBaud */

247
static struct smsc_chip __initdata fdc_chips_flat[] =
L
Linus Torvalds 已提交
248 249 250 251 252 253 254 255 256 257 258 259 260
{
	/* Base address 0x3f0 or 0x370 */
	{ "37C44",	KEY55_1|NoIRDA,		0x00, 0x00 }, /* This chip cannot be detected */
	{ "37C665GT",	KEY55_2|NoIRDA,		0x65, 0x01 },
	{ "37C665GT",	KEY55_2|NoIRDA,		0x66, 0x01 },
	{ "37C669",	KEY55_2|SIR|SERx4,	0x03, 0x02 },
	{ "37C669",	KEY55_2|SIR|SERx4,	0x04, 0x02 }, /* ID? */
	{ "37C78",	KEY55_2|NoIRDA,		0x78, 0x00 },
	{ "37N769",	KEY55_1|FIR|SERx4,	0x28, 0x00 },
	{ "37N869",	KEY55_1|FIR|SERx4,	0x29, 0x00 },
	{ NULL }
};

261
static struct smsc_chip __initdata fdc_chips_paged[] =
L
Linus Torvalds 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
{
	/* Base address 0x3f0 or 0x370 */
	{ "37B72X",	KEY55_1|SIR|SERx4,	0x4c, 0x00 },
	{ "37B77X",	KEY55_1|SIR|SERx4,	0x43, 0x00 },
	{ "37B78X",	KEY55_1|SIR|SERx4,	0x44, 0x00 },
	{ "37B80X",	KEY55_1|SIR|SERx4,	0x42, 0x00 },
	{ "37C67X",	KEY55_1|FIR|SERx4,	0x40, 0x00 },
	{ "37C93X",	KEY55_2|SIR|SERx4,	0x02, 0x01 },
	{ "37C93XAPM",	KEY55_1|SIR|SERx4,	0x30, 0x01 },
	{ "37C93XFR",	KEY55_2|FIR|SERx4,	0x03, 0x01 },
	{ "37M707",	KEY55_1|SIR|SERx4,	0x42, 0x00 },
	{ "37M81X",	KEY55_1|SIR|SERx4,	0x4d, 0x00 },
	{ "37N958FR",	KEY55_1|FIR|SERx4,	0x09, 0x04 },
	{ "37N971",	KEY55_1|FIR|SERx4,	0x0a, 0x00 },
	{ "37N972",	KEY55_1|FIR|SERx4,	0x0b, 0x00 },
	{ NULL }
};

280
static struct smsc_chip __initdata lpc_chips_flat[] =
L
Linus Torvalds 已提交
281 282 283 284 285 286 287
{
	/* Base address 0x2E or 0x4E */
	{ "47N227",	KEY55_1|FIR|SERx4,	0x5a, 0x00 },
	{ "47N267",	KEY55_1|FIR|SERx4,	0x5e, 0x00 },
	{ NULL }
};

288
static struct smsc_chip __initdata lpc_chips_paged[] =
L
Linus Torvalds 已提交
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
{
	/* Base address 0x2E or 0x4E */
	{ "47B27X",	KEY55_1|SIR|SERx4,	0x51, 0x00 },
	{ "47B37X",	KEY55_1|SIR|SERx4,	0x52, 0x00 },
	{ "47M10X",	KEY55_1|SIR|SERx4,	0x59, 0x00 },
	{ "47M120",	KEY55_1|NoIRDA|SERx4,	0x5c, 0x00 },
	{ "47M13X",	KEY55_1|SIR|SERx4,	0x59, 0x00 },
	{ "47M14X",	KEY55_1|SIR|SERx4,	0x5f, 0x00 },
	{ "47N252",	KEY55_1|FIR|SERx4,	0x0e, 0x00 },
	{ "47S42X",	KEY55_1|SIR|SERx4,	0x57, 0x00 },
	{ NULL }
};

#define SMSCSIO_TYPE_FDC	1
#define SMSCSIO_TYPE_LPC	2
#define SMSCSIO_TYPE_FLAT	4
#define SMSCSIO_TYPE_PAGED	8

307
static struct smsc_chip_address __initdata possible_addresses[] =
L
Linus Torvalds 已提交
308
{
309 310 311 312 313 314
	{ 0x3f0, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
	{ 0x370, SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
	{ 0xe0,  SMSCSIO_TYPE_FDC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
	{ 0x2e,  SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
	{ 0x4e,  SMSCSIO_TYPE_LPC|SMSCSIO_TYPE_FLAT|SMSCSIO_TYPE_PAGED },
	{ 0, 0 }
L
Linus Torvalds 已提交
315 316 317 318
};

/* Globals */

319 320
static struct smsc_ircc_cb *dev_self[] = { NULL, NULL };
static unsigned short dev_count;
L
Linus Torvalds 已提交
321 322 323

static inline void register_bank(int iobase, int bank)
{
324 325
        outb(((inb(iobase + IRCC_MASTER) & 0xf0) | (bank & 0x07)),
               iobase + IRCC_MASTER);
L
Linus Torvalds 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
}


/*******************************************************************************
 *
 *
 * SMSC-ircc stuff
 *
 *
 *******************************************************************************/

/*
 * Function smsc_ircc_init ()
 *
 *    Initialize chip. Just try to find out how many chips we are dealing with
 *    and where they are
 */
static int __init smsc_ircc_init(void)
{
345
	int ret;
L
Linus Torvalds 已提交
346 347 348

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

349 350 351 352 353 354
	ret = driver_register(&smsc_ircc_driver);
	if (ret) {
		IRDA_ERROR("%s, Can't register driver!\n", driver_name);
		return ret;
	}

355
	dev_count = 0;
356

357
	if (ircc_fir > 0 && ircc_sir > 0) {
L
Linus Torvalds 已提交
358 359 360
		IRDA_MESSAGE(" Overriding FIR address 0x%04x\n", ircc_fir);
		IRDA_MESSAGE(" Overriding SIR address 0x%04x\n", ircc_sir);

361 362 363
		if (smsc_ircc_open(ircc_fir, ircc_sir, ircc_dma, ircc_irq))
			ret = -ENODEV;
	} else {
364
		ret = -ENODEV;
L
Linus Torvalds 已提交
365

366 367 368 369 370 371 372 373 374
		/* try user provided configuration register base address */
		if (ircc_cfg > 0) {
			IRDA_MESSAGE(" Overriding configuration address "
				     "0x%04x\n", ircc_cfg);
			if (!smsc_superio_fdc(ircc_cfg))
				ret = 0;
			if (!smsc_superio_lpc(ircc_cfg))
				ret = 0;
		}
L
Linus Torvalds 已提交
375

376
		if (smsc_ircc_look_for_chips() > 0)
L
Linus Torvalds 已提交
377 378
			ret = 0;
	}
379

380 381
	if (ret)
		driver_unregister(&smsc_ircc_driver);
382

L
Linus Torvalds 已提交
383 384 385 386 387 388 389 390 391 392 393 394 395 396
	return ret;
}

/*
 * Function smsc_ircc_open (firbase, sirbase, dma, irq)
 *
 *    Try to open driver instance
 *
 */
static int __init smsc_ircc_open(unsigned int fir_base, unsigned int sir_base, u8 dma, u8 irq)
{
	struct smsc_ircc_cb *self;
	struct net_device *dev;
	int err;
397

L
Linus Torvalds 已提交
398 399 400
	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	err = smsc_ircc_present(fir_base, sir_base);
401
	if (err)
L
Linus Torvalds 已提交
402
		goto err_out;
403

L
Linus Torvalds 已提交
404
	err = -ENOMEM;
405
	if (dev_count >= ARRAY_SIZE(dev_self)) {
L
Linus Torvalds 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
	        IRDA_WARNING("%s(), too many devices!\n", __FUNCTION__);
		goto err_out1;
	}

	/*
	 *  Allocate new instance of the driver
	 */
	dev = alloc_irdadev(sizeof(struct smsc_ircc_cb));
	if (!dev) {
		IRDA_WARNING("%s() can't allocate net device\n", __FUNCTION__);
		goto err_out1;
	}

	SET_MODULE_OWNER(dev);

	dev->hard_start_xmit = smsc_ircc_hard_xmit_sir;
#if SMSC_IRCC2_C_NET_TIMEOUT
	dev->tx_timeout	     = smsc_ircc_timeout;
424
	dev->watchdog_timeo  = HZ * 2;  /* Allow enough time for speed change */
L
Linus Torvalds 已提交
425 426 427 428 429
#endif
	dev->open            = smsc_ircc_net_open;
	dev->stop            = smsc_ircc_net_close;
	dev->do_ioctl        = smsc_ircc_net_ioctl;
	dev->get_stats	     = smsc_ircc_net_get_stats;
430

431
	self = netdev_priv(dev);
L
Linus Torvalds 已提交
432 433 434 435 436 437 438
	self->netdev = dev;

	/* Make ifconfig display some details */
	dev->base_addr = self->io.fir_base = fir_base;
	dev->irq = self->io.irq = irq;

	/* Need to store self somewhere */
439
	dev_self[dev_count] = self;
L
Linus Torvalds 已提交
440 441
	spin_lock_init(&self->lock);

442
	self->rx_buff.truesize = SMSC_IRCC2_RX_BUFF_TRUESIZE;
L
Linus Torvalds 已提交
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
	self->tx_buff.truesize = SMSC_IRCC2_TX_BUFF_TRUESIZE;

	self->rx_buff.head =
		dma_alloc_coherent(NULL, self->rx_buff.truesize,
				   &self->rx_buff_dma, GFP_KERNEL);
	if (self->rx_buff.head == NULL) {
		IRDA_ERROR("%s, Can't allocate memory for receive buffer!\n",
			   driver_name);
		goto err_out2;
	}

	self->tx_buff.head =
		dma_alloc_coherent(NULL, self->tx_buff.truesize,
				   &self->tx_buff_dma, GFP_KERNEL);
	if (self->tx_buff.head == NULL) {
		IRDA_ERROR("%s, Can't allocate memory for transmit buffer!\n",
			   driver_name);
		goto err_out3;
	}

	memset(self->rx_buff.head, 0, self->rx_buff.truesize);
	memset(self->tx_buff.head, 0, self->tx_buff.truesize);

	self->rx_buff.in_frame = FALSE;
	self->rx_buff.state = OUTSIDE_FRAME;
	self->tx_buff.data = self->tx_buff.head;
	self->rx_buff.data = self->rx_buff.head;
470

L
Linus Torvalds 已提交
471 472 473
	smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq);
	smsc_ircc_setup_qos(self);
	smsc_ircc_init_chip(self);
474

475 476
	if (ircc_transceiver > 0  &&
	    ircc_transceiver < SMSC_IRCC2_C_NUMBER_OF_TRANSCEIVERS)
L
Linus Torvalds 已提交
477 478 479 480 481
		self->transceiver = ircc_transceiver;
	else
		smsc_ircc_probe_transceiver(self);

	err = register_netdev(self->netdev);
482
	if (err) {
L
Linus Torvalds 已提交
483 484 485 486 487
		IRDA_ERROR("%s, Network device registration failed!\n",
			   driver_name);
		goto err_out4;
	}

488 489 490 491 492 493 494
	self->pldev = platform_device_register_simple(SMSC_IRCC2_DRIVER_NAME,
						      dev_count, NULL, 0);
	if (IS_ERR(self->pldev)) {
		err = PTR_ERR(self->pldev);
		goto err_out5;
	}
	dev_set_drvdata(&self->pldev->dev, self);
L
Linus Torvalds 已提交
495 496

	IRDA_MESSAGE("IrDA: Registered device %s\n", dev->name);
497
	dev_count++;
L
Linus Torvalds 已提交
498 499

	return 0;
500

501 502 503
 err_out5:
	unregister_netdev(self->netdev);

L
Linus Torvalds 已提交
504 505 506 507 508 509 510 511
 err_out4:
	dma_free_coherent(NULL, self->tx_buff.truesize,
			  self->tx_buff.head, self->tx_buff_dma);
 err_out3:
	dma_free_coherent(NULL, self->rx_buff.truesize,
			  self->rx_buff.head, self->rx_buff_dma);
 err_out2:
	free_netdev(self->netdev);
512
	dev_self[dev_count] = NULL;
L
Linus Torvalds 已提交
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
 err_out1:
	release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
	release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
 err_out:
	return err;
}

/*
 * Function smsc_ircc_present(fir_base, sir_base)
 *
 *    Check the smsc-ircc chip presence
 *
 */
static int smsc_ircc_present(unsigned int fir_base, unsigned int sir_base)
{
	unsigned char low, high, chip, config, dma, irq, version;

	if (!request_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT,
			    driver_name)) {
		IRDA_WARNING("%s: can't get fir_base of 0x%03x\n",
			     __FUNCTION__, fir_base);
		goto out1;
	}

	if (!request_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT,
			    driver_name)) {
		IRDA_WARNING("%s: can't get sir_base of 0x%03x\n",
			     __FUNCTION__, sir_base);
		goto out2;
	}

	register_bank(fir_base, 3);

546 547 548 549 550
	high    = inb(fir_base + IRCC_ID_HIGH);
	low     = inb(fir_base + IRCC_ID_LOW);
	chip    = inb(fir_base + IRCC_CHIP_ID);
	version = inb(fir_base + IRCC_VERSION);
	config  = inb(fir_base + IRCC_INTERFACE);
L
Linus Torvalds 已提交
551 552 553
	dma     = config & IRCC_INTERFACE_DMA_MASK;
	irq     = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;

554
	if (high != 0x10 || low != 0xb8 || (chip != 0xf1 && chip != 0xf2)) {
555
		IRDA_WARNING("%s(), addr 0x%04x - no device found!\n",
L
Linus Torvalds 已提交
556 557 558 559 560 561 562 563
			     __FUNCTION__, fir_base);
		goto out3;
	}
	IRDA_MESSAGE("SMsC IrDA Controller found\n IrCC version %d.%d, "
		     "firport 0x%03x, sirport 0x%03x dma=%d, irq=%d\n",
		     chip & 0x0f, version, fir_base, sir_base, dma, irq);

	return 0;
564

L
Linus Torvalds 已提交
565 566 567 568 569 570 571 572 573 574 575 576 577 578
 out3:
	release_region(sir_base, SMSC_IRCC2_SIR_CHIP_IO_EXTENT);
 out2:
	release_region(fir_base, SMSC_IRCC2_FIR_CHIP_IO_EXTENT);
 out1:
	return -ENODEV;
}

/*
 * Function smsc_ircc_setup_io(self, fir_base, sir_base, dma, irq)
 *
 *    Setup I/O
 *
 */
579 580
static void smsc_ircc_setup_io(struct smsc_ircc_cb *self,
			       unsigned int fir_base, unsigned int sir_base,
L
Linus Torvalds 已提交
581 582 583 584 585
			       u8 dma, u8 irq)
{
	unsigned char config, chip_dma, chip_irq;

	register_bank(fir_base, 3);
586 587 588
	config = inb(fir_base + IRCC_INTERFACE);
	chip_dma = config & IRCC_INTERFACE_DMA_MASK;
	chip_irq = (config & IRCC_INTERFACE_IRQ_MASK) >> 4;
L
Linus Torvalds 已提交
589 590 591 592 593 594 595 596 597 598 599 600 601

	self->io.fir_base  = fir_base;
	self->io.sir_base  = sir_base;
	self->io.fir_ext   = SMSC_IRCC2_FIR_CHIP_IO_EXTENT;
	self->io.sir_ext   = SMSC_IRCC2_SIR_CHIP_IO_EXTENT;
	self->io.fifo_size = SMSC_IRCC2_FIFO_SIZE;
	self->io.speed = SMSC_IRCC2_C_IRDA_FALLBACK_SPEED;

	if (irq < 255) {
		if (irq != chip_irq)
			IRDA_MESSAGE("%s, Overriding IRQ - chip says %d, using %d\n",
				     driver_name, chip_irq, irq);
		self->io.irq = irq;
602
	} else
L
Linus Torvalds 已提交
603
		self->io.irq = chip_irq;
604

L
Linus Torvalds 已提交
605 606 607 608 609
	if (dma < 255) {
		if (dma != chip_dma)
			IRDA_MESSAGE("%s, Overriding DMA - chip says %d, using %d\n",
				     driver_name, chip_dma, dma);
		self->io.dma = dma;
610
	} else
L
Linus Torvalds 已提交
611 612 613 614 615 616 617 618 619 620 621 622 623 624
		self->io.dma = chip_dma;

}

/*
 * Function smsc_ircc_setup_qos(self)
 *
 *    Setup qos
 *
 */
static void smsc_ircc_setup_qos(struct smsc_ircc_cb *self)
{
	/* Initialize QoS for this device */
	irda_init_max_qos_capabilies(&self->qos);
625

L
Linus Torvalds 已提交
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641
	self->qos.baud_rate.bits = IR_9600|IR_19200|IR_38400|IR_57600|
		IR_115200|IR_576000|IR_1152000|(IR_4000000 << 8);

	self->qos.min_turn_time.bits = SMSC_IRCC2_MIN_TURN_TIME;
	self->qos.window_size.bits = SMSC_IRCC2_WINDOW_SIZE;
	irda_qos_bits_to_value(&self->qos);
}

/*
 * Function smsc_ircc_init_chip(self)
 *
 *    Init chip
 *
 */
static void smsc_ircc_init_chip(struct smsc_ircc_cb *self)
{
642 643
	int iobase, ir_mode, ctrl, fast;

644
	IRDA_ASSERT(self != NULL, return;);
L
Linus Torvalds 已提交
645

646
	iobase = self->io.fir_base;
L
Linus Torvalds 已提交
647 648 649 650 651
	ir_mode = IRCC_CFGA_IRDA_SIR_A;
	ctrl = 0;
	fast = 0;

	register_bank(iobase, 0);
652 653
	outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
	outb(0x00, iobase + IRCC_MASTER);
L
Linus Torvalds 已提交
654 655

	register_bank(iobase, 1);
656 657
	outb(((inb(iobase + IRCC_SCE_CFGA) & 0x87) | ir_mode),
	     iobase + IRCC_SCE_CFGA);
L
Linus Torvalds 已提交
658 659

#ifdef smsc_669 /* Uses pin 88/89 for Rx/Tx */
660 661
	outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
	     iobase + IRCC_SCE_CFGB);
662
#else
663 664
	outb(((inb(iobase + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
	     iobase + IRCC_SCE_CFGB);
665
#endif
666 667
	(void) inb(iobase + IRCC_FIFO_THRESHOLD);
	outb(SMSC_IRCC2_FIFO_THRESHOLD, iobase + IRCC_FIFO_THRESHOLD);
668

L
Linus Torvalds 已提交
669
	register_bank(iobase, 4);
670
	outb((inb(iobase + IRCC_CONTROL) & 0x30) | ctrl, iobase + IRCC_CONTROL);
671

L
Linus Torvalds 已提交
672
	register_bank(iobase, 0);
673
	outb(fast, iobase + IRCC_LCR_A);
L
Linus Torvalds 已提交
674 675

	smsc_ircc_set_sir_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
676

L
Linus Torvalds 已提交
677
	/* Power on device */
678
	outb(0x00, iobase + IRCC_MASTER);
L
Linus Torvalds 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695
}

/*
 * Function smsc_ircc_net_ioctl (dev, rq, cmd)
 *
 *    Process IOCTL commands for this device
 *
 */
static int smsc_ircc_net_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
	struct if_irda_req *irq = (struct if_irda_req *) rq;
	struct smsc_ircc_cb *self;
	unsigned long flags;
	int ret = 0;

	IRDA_ASSERT(dev != NULL, return -1;);

696
	self = netdev_priv(dev);
L
Linus Torvalds 已提交
697 698 699 700

	IRDA_ASSERT(self != NULL, return -1;);

	IRDA_DEBUG(2, "%s(), %s, (cmd=0x%X)\n", __FUNCTION__, dev->name, cmd);
701

L
Linus Torvalds 已提交
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
	switch (cmd) {
	case SIOCSBANDWIDTH: /* Set bandwidth */
		if (!capable(CAP_NET_ADMIN))
			ret = -EPERM;
                else {
			/* Make sure we are the only one touching
			 * self->io.speed and the hardware - Jean II */
			spin_lock_irqsave(&self->lock, flags);
			smsc_ircc_change_speed(self, irq->ifr_baudrate);
			spin_unlock_irqrestore(&self->lock, flags);
		}
		break;
	case SIOCSMEDIABUSY: /* Set media busy */
		if (!capable(CAP_NET_ADMIN)) {
			ret = -EPERM;
			break;
		}

		irda_device_set_media_busy(self->netdev, TRUE);
		break;
	case SIOCGRECEIVING: /* Check if we are receiving right now */
		irq->ifr_receiving = smsc_ircc_is_receiving(self);
		break;
	#if 0
	case SIOCSDTRRTS:
		if (!capable(CAP_NET_ADMIN)) {
			ret = -EPERM;
			break;
		}
		smsc_ircc_sir_set_dtr_rts(dev, irq->ifr_dtr, irq->ifr_rts);
		break;
	#endif
	default:
		ret = -EOPNOTSUPP;
	}
737

L
Linus Torvalds 已提交
738 739 740 741 742
	return ret;
}

static struct net_device_stats *smsc_ircc_net_get_stats(struct net_device *dev)
{
743
	struct smsc_ircc_cb *self = netdev_priv(dev);
744

L
Linus Torvalds 已提交
745 746 747 748 749 750 751 752 753 754 755 756 757
	return &self->stats;
}

#if SMSC_IRCC2_C_NET_TIMEOUT
/*
 * Function smsc_ircc_timeout (struct net_device *dev)
 *
 *    The networking timeout management.
 *
 */

static void smsc_ircc_timeout(struct net_device *dev)
{
758
	struct smsc_ircc_cb *self = netdev_priv(dev);
L
Linus Torvalds 已提交
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787
	unsigned long flags;

	IRDA_WARNING("%s: transmit timed out, changing speed to: %d\n",
		     dev->name, self->io.speed);
	spin_lock_irqsave(&self->lock, flags);
	smsc_ircc_sir_start(self);
	smsc_ircc_change_speed(self, self->io.speed);
	dev->trans_start = jiffies;
	netif_wake_queue(dev);
	spin_unlock_irqrestore(&self->lock, flags);
}
#endif

/*
 * Function smsc_ircc_hard_xmit_sir (struct sk_buff *skb, struct net_device *dev)
 *
 *    Transmits the current frame until FIFO is full, then
 *    waits until the next transmit interrupt, and continues until the
 *    frame is transmitted.
 */
int smsc_ircc_hard_xmit_sir(struct sk_buff *skb, struct net_device *dev)
{
	struct smsc_ircc_cb *self;
	unsigned long flags;
	s32 speed;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	IRDA_ASSERT(dev != NULL, return 0;);
788

789
	self = netdev_priv(dev);
L
Linus Torvalds 已提交
790 791 792
	IRDA_ASSERT(self != NULL, return 0;);

	netif_stop_queue(dev);
793

L
Linus Torvalds 已提交
794 795 796 797 798
	/* Make sure test of self->io.speed & speed change are atomic */
	spin_lock_irqsave(&self->lock, flags);

	/* Check if we need to change the speed */
	speed = irda_get_next_speed(skb);
799
	if (speed != self->io.speed && speed != -1) {
L
Linus Torvalds 已提交
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
		/* Check for empty frame */
		if (!skb->len) {
			/*
			 * We send frames one by one in SIR mode (no
			 * pipelining), so at this point, if we were sending
			 * a previous frame, we just received the interrupt
			 * telling us it is finished (UART_IIR_THRI).
			 * Therefore, waiting for the transmitter to really
			 * finish draining the fifo won't take too long.
			 * And the interrupt handler is not expected to run.
			 * - Jean II */
			smsc_ircc_sir_wait_hw_transmitter_finish(self);
			smsc_ircc_change_speed(self, speed);
			spin_unlock_irqrestore(&self->lock, flags);
			dev_kfree_skb(skb);
			return 0;
		}
817
		self->new_speed = speed;
L
Linus Torvalds 已提交
818 819 820 821 822 823
	}

	/* Init tx buffer */
	self->tx_buff.data = self->tx_buff.head;

	/* Copy skb to tx_buff while wrapping, stuffing and making CRC */
824
	self->tx_buff.len = async_wrap_skb(skb, self->tx_buff.data,
L
Linus Torvalds 已提交
825
					   self->tx_buff.truesize);
826

L
Linus Torvalds 已提交
827 828 829
	self->stats.tx_bytes += self->tx_buff.len;

	/* Turn on transmit finished interrupt. Will fire immediately!  */
830
	outb(UART_IER_THRI, self->io.sir_base + UART_IER);
L
Linus Torvalds 已提交
831 832 833 834

	spin_unlock_irqrestore(&self->lock, flags);

	dev_kfree_skb(skb);
835

L
Linus Torvalds 已提交
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853
	return 0;
}

/*
 * Function smsc_ircc_set_fir_speed (self, baud)
 *
 *    Change the speed of the device
 *
 */
static void smsc_ircc_set_fir_speed(struct smsc_ircc_cb *self, u32 speed)
{
	int fir_base, ir_mode, ctrl, fast;

	IRDA_ASSERT(self != NULL, return;);
	fir_base = self->io.fir_base;

	self->io.speed = speed;

854
	switch (speed) {
L
Linus Torvalds 已提交
855
	default:
856
	case 576000:
L
Linus Torvalds 已提交
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880
		ir_mode = IRCC_CFGA_IRDA_HDLC;
		ctrl = IRCC_CRC;
		fast = 0;
		IRDA_DEBUG(0, "%s(), handling baud of 576000\n", __FUNCTION__);
		break;
	case 1152000:
		ir_mode = IRCC_CFGA_IRDA_HDLC;
		ctrl = IRCC_1152 | IRCC_CRC;
		fast = IRCC_LCR_A_FAST | IRCC_LCR_A_GP_DATA;
		IRDA_DEBUG(0, "%s(), handling baud of 1152000\n",
			   __FUNCTION__);
		break;
	case 4000000:
		ir_mode = IRCC_CFGA_IRDA_4PPM;
		ctrl = IRCC_CRC;
		fast = IRCC_LCR_A_FAST;
		IRDA_DEBUG(0, "%s(), handling baud of 4000000\n",
			   __FUNCTION__);
		break;
	}
	#if 0
	Now in tranceiver!
	/* This causes an interrupt */
	register_bank(fir_base, 0);
881
	outb((inb(fir_base + IRCC_LCR_A) &  0xbf) | fast, fir_base + IRCC_LCR_A);
L
Linus Torvalds 已提交
882
	#endif
883

L
Linus Torvalds 已提交
884
	register_bank(fir_base, 1);
885
	outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | ir_mode), fir_base + IRCC_SCE_CFGA);
886

L
Linus Torvalds 已提交
887
	register_bank(fir_base, 4);
888
	outb((inb(fir_base + IRCC_CONTROL) & 0x30) | ctrl, fir_base + IRCC_CONTROL);
L
Linus Torvalds 已提交
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
}

/*
 * Function smsc_ircc_fir_start(self)
 *
 *    Change the speed of the device
 *
 */
static void smsc_ircc_fir_start(struct smsc_ircc_cb *self)
{
	struct net_device *dev;
	int fir_base;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return;);
	dev = self->netdev;
	IRDA_ASSERT(dev != NULL, return;);

	fir_base = self->io.fir_base;

	/* Reset everything */

	/* Install FIR transmit handler */
913
	dev->hard_start_xmit = smsc_ircc_hard_xmit_fir;
L
Linus Torvalds 已提交
914 915

	/* Clear FIFO */
916
	outb(inb(fir_base + IRCC_LCR_A) | IRCC_LCR_A_FIFO_RESET, fir_base + IRCC_LCR_A);
L
Linus Torvalds 已提交
917 918

	/* Enable interrupt */
919
	/*outb(IRCC_IER_ACTIVE_FRAME|IRCC_IER_EOM, fir_base + IRCC_IER);*/
L
Linus Torvalds 已提交
920 921 922

	register_bank(fir_base, 1);

923
	/* Select the TX/RX interface */
L
Linus Torvalds 已提交
924
#ifdef SMSC_669 /* Uses pin 88/89 for Rx/Tx */
925 926
	outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_COM),
	     fir_base + IRCC_SCE_CFGB);
927
#else
928 929
	outb(((inb(fir_base + IRCC_SCE_CFGB) & 0x3f) | IRCC_CFGB_MUX_IR),
	     fir_base + IRCC_SCE_CFGB);
930
#endif
931
	(void) inb(fir_base + IRCC_FIFO_THRESHOLD);
L
Linus Torvalds 已提交
932 933

	/* Enable SCE interrupts */
934
	outb(0, fir_base + IRCC_MASTER);
L
Linus Torvalds 已提交
935
	register_bank(fir_base, 0);
936 937
	outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, fir_base + IRCC_IER);
	outb(IRCC_MASTER_INT_EN, fir_base + IRCC_MASTER);
L
Linus Torvalds 已提交
938 939 940 941 942 943 944 945 946 947 948 949 950
}

/*
 * Function smsc_ircc_fir_stop(self, baud)
 *
 *    Change the speed of the device
 *
 */
static void smsc_ircc_fir_stop(struct smsc_ircc_cb *self)
{
	int fir_base;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);
951

L
Linus Torvalds 已提交
952 953 954 955
	IRDA_ASSERT(self != NULL, return;);

	fir_base = self->io.fir_base;
	register_bank(fir_base, 0);
956 957
	/*outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);*/
	outb(inb(fir_base + IRCC_LCR_B) & IRCC_LCR_B_SIP_ENABLE, fir_base + IRCC_LCR_B);
L
Linus Torvalds 已提交
958 959 960 961 962 963 964 965 966 967 968
}


/*
 * Function smsc_ircc_change_speed(self, baud)
 *
 *    Change the speed of the device
 *
 * This function *must* be called with spinlock held, because it may
 * be called from the irq handler. - Jean II
 */
969
static void smsc_ircc_change_speed(struct smsc_ircc_cb *self, u32 speed)
L
Linus Torvalds 已提交
970 971 972
{
	struct net_device *dev;
	int last_speed_was_sir;
973

L
Linus Torvalds 已提交
974 975 976 977 978 979 980 981 982 983 984 985
	IRDA_DEBUG(0, "%s() changing speed to: %d\n", __FUNCTION__, speed);

	IRDA_ASSERT(self != NULL, return;);
	dev = self->netdev;

	last_speed_was_sir = self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED;

	#if 0
	/* Temp Hack */
	speed= 1152000;
	self->io.speed = speed;
	last_speed_was_sir = 0;
986
	smsc_ircc_fir_start(self);
L
Linus Torvalds 已提交
987
	#endif
988

989
	if (self->io.speed == 0)
L
Linus Torvalds 已提交
990 991 992
		smsc_ircc_sir_start(self);

	#if 0
993
	if (!last_speed_was_sir) speed = self->io.speed;
L
Linus Torvalds 已提交
994 995
	#endif

996 997
	if (self->io.speed != speed)
		smsc_ircc_set_transceiver_for_speed(self, speed);
L
Linus Torvalds 已提交
998 999

	self->io.speed = speed;
1000

1001 1002
	if (speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
		if (!last_speed_was_sir) {
L
Linus Torvalds 已提交
1003 1004 1005
			smsc_ircc_fir_stop(self);
			smsc_ircc_sir_start(self);
		}
1006
		smsc_ircc_set_sir_speed(self, speed);
1007 1008
	} else {
		if (last_speed_was_sir) {
1009
			#if SMSC_IRCC2_C_SIR_STOP
L
Linus Torvalds 已提交
1010 1011 1012 1013 1014 1015 1016 1017 1018
			smsc_ircc_sir_stop(self);
			#endif
			smsc_ircc_fir_start(self);
		}
		smsc_ircc_set_fir_speed(self, speed);

		#if 0
		self->tx_buff.len = 10;
		self->tx_buff.data = self->tx_buff.head;
1019

1020
		smsc_ircc_dma_xmit(self, 4000);
L
Linus Torvalds 已提交
1021 1022
		#endif
		/* Be ready for incoming frames */
1023
		smsc_ircc_dma_receive(self);
L
Linus Torvalds 已提交
1024
	}
1025

L
Linus Torvalds 已提交
1026 1027 1028 1029 1030 1031 1032 1033 1034
	netif_wake_queue(dev);
}

/*
 * Function smsc_ircc_set_sir_speed (self, speed)
 *
 *    Set speed of IrDA port to specified baudrate
 *
 */
1035
void smsc_ircc_set_sir_speed(struct smsc_ircc_cb *self, __u32 speed)
L
Linus Torvalds 已提交
1036
{
1037
	int iobase;
L
Linus Torvalds 已提交
1038 1039 1040 1041 1042 1043 1044 1045
	int fcr;    /* FIFO control reg */
	int lcr;    /* Line control reg */
	int divisor;

	IRDA_DEBUG(0, "%s(), Setting speed to: %d\n", __FUNCTION__, speed);

	IRDA_ASSERT(self != NULL, return;);
	iobase = self->io.sir_base;
1046

L
Linus Torvalds 已提交
1047 1048 1049 1050
	/* Update accounting for new speed */
	self->io.speed = speed;

	/* Turn off interrupts */
1051
	outb(0, iobase + UART_IER);
L
Linus Torvalds 已提交
1052

1053
	divisor = SMSC_IRCC2_MAX_SIR_SPEED / speed;
1054

L
Linus Torvalds 已提交
1055 1056
	fcr = UART_FCR_ENABLE_FIFO;

1057
	/*
L
Linus Torvalds 已提交
1058 1059
	 * Use trigger level 1 to avoid 3 ms. timeout delay at 9600 bps, and
	 * almost 1,7 ms at 19200 bps. At speeds above that we can just forget
1060
	 * about this timeout since it will always be fast enough.
L
Linus Torvalds 已提交
1061
	 */
1062 1063
	fcr |= self->io.speed < 38400 ?
		UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
1064

L
Linus Torvalds 已提交
1065 1066
	/* IrDA ports use 8N1 */
	lcr = UART_LCR_WLEN8;
1067

1068 1069 1070 1071 1072
	outb(UART_LCR_DLAB | lcr, iobase + UART_LCR); /* Set DLAB */
	outb(divisor & 0xff,      iobase + UART_DLL); /* Set speed */
	outb(divisor >> 8,	  iobase + UART_DLM);
	outb(lcr,		  iobase + UART_LCR); /* Set 8N1 */
	outb(fcr,		  iobase + UART_FCR); /* Enable FIFO's */
L
Linus Torvalds 已提交
1073 1074

	/* Turn on interrups */
1075
	outb(UART_IER_RLSI | UART_IER_RDI | UART_IER_THRI, iobase + UART_IER);
L
Linus Torvalds 已提交
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094

	IRDA_DEBUG(2, "%s() speed changed to: %d\n", __FUNCTION__, speed);
}


/*
 * Function smsc_ircc_hard_xmit_fir (skb, dev)
 *
 *    Transmit the frame!
 *
 */
static int smsc_ircc_hard_xmit_fir(struct sk_buff *skb, struct net_device *dev)
{
	struct smsc_ircc_cb *self;
	unsigned long flags;
	s32 speed;
	int mtt;

	IRDA_ASSERT(dev != NULL, return 0;);
1095
	self = netdev_priv(dev);
L
Linus Torvalds 已提交
1096 1097 1098 1099 1100 1101 1102 1103 1104
	IRDA_ASSERT(self != NULL, return 0;);

	netif_stop_queue(dev);

	/* Make sure test of self->io.speed & speed change are atomic */
	spin_lock_irqsave(&self->lock, flags);

	/* Check if we need to change the speed after this frame */
	speed = irda_get_next_speed(skb);
1105
	if (speed != self->io.speed && speed != -1) {
L
Linus Torvalds 已提交
1106 1107 1108 1109 1110
		/* Check for empty frame */
		if (!skb->len) {
			/* Note : you should make sure that speed changes
			 * are not going to corrupt any outgoing frame.
			 * Look at nsc-ircc for the gory details - Jean II */
1111
			smsc_ircc_change_speed(self, speed);
L
Linus Torvalds 已提交
1112 1113 1114
			spin_unlock_irqrestore(&self->lock, flags);
			dev_kfree_skb(skb);
			return 0;
1115 1116 1117
		}

		self->new_speed = speed;
L
Linus Torvalds 已提交
1118
	}
1119

L
Linus Torvalds 已提交
1120 1121 1122 1123
	memcpy(self->tx_buff.head, skb->data, skb->len);

	self->tx_buff.len = skb->len;
	self->tx_buff.data = self->tx_buff.head;
1124 1125

	mtt = irda_get_mtt(skb);
L
Linus Torvalds 已提交
1126 1127 1128
	if (mtt) {
		int bofs;

1129
		/*
L
Linus Torvalds 已提交
1130 1131 1132 1133 1134 1135 1136
		 * Compute how many BOFs (STA or PA's) we need to waste the
		 * min turn time given the speed of the link.
		 */
		bofs = mtt * (self->io.speed / 1000) / 8000;
		if (bofs > 4095)
			bofs = 4095;

1137
		smsc_ircc_dma_xmit(self, bofs);
L
Linus Torvalds 已提交
1138 1139
	} else {
		/* Transmit frame */
1140
		smsc_ircc_dma_xmit(self, 0);
L
Linus Torvalds 已提交
1141
	}
1142

L
Linus Torvalds 已提交
1143 1144 1145 1146 1147 1148 1149
	spin_unlock_irqrestore(&self->lock, flags);
	dev_kfree_skb(skb);

	return 0;
}

/*
1150
 * Function smsc_ircc_dma_xmit (self, bofs)
L
Linus Torvalds 已提交
1151 1152 1153 1154
 *
 *    Transmit data using DMA
 *
 */
1155
static void smsc_ircc_dma_xmit(struct smsc_ircc_cb *self, int bofs)
L
Linus Torvalds 已提交
1156
{
1157
	int iobase = self->io.fir_base;
L
Linus Torvalds 已提交
1158 1159 1160 1161 1162 1163
	u8 ctrl;

	IRDA_DEBUG(3, "%s\n", __FUNCTION__);
#if 1
	/* Disable Rx */
	register_bank(iobase, 0);
1164
	outb(0x00, iobase + IRCC_LCR_B);
L
Linus Torvalds 已提交
1165 1166
#endif
	register_bank(iobase, 1);
1167 1168
	outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
	     iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1169 1170 1171 1172 1173

	self->io.direction = IO_XMIT;

	/* Set BOF additional count for generating the min turn time */
	register_bank(iobase, 4);
1174 1175 1176
	outb(bofs & 0xff, iobase + IRCC_BOF_COUNT_LO);
	ctrl = inb(iobase + IRCC_CONTROL) & 0xf0;
	outb(ctrl | ((bofs >> 8) & 0x0f), iobase + IRCC_BOF_COUNT_HI);
L
Linus Torvalds 已提交
1177 1178

	/* Set max Tx frame size */
1179 1180
	outb(self->tx_buff.len >> 8, iobase + IRCC_TX_SIZE_HI);
	outb(self->tx_buff.len & 0xff, iobase + IRCC_TX_SIZE_LO);
L
Linus Torvalds 已提交
1181 1182

	/*outb(UART_MCR_OUT2, self->io.sir_base + UART_MCR);*/
1183

L
Linus Torvalds 已提交
1184 1185
	/* Enable burst mode chip Tx DMA */
	register_bank(iobase, 1);
1186 1187
	outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
	     IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1188 1189 1190 1191 1192 1193 1194 1195

	/* Setup DMA controller (must be done after enabling chip DMA) */
	irda_setup_dma(self->io.dma, self->tx_buff_dma, self->tx_buff.len,
		       DMA_TX_MODE);

	/* Enable interrupt */

	register_bank(iobase, 0);
1196 1197
	outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
	outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
1198

L
Linus Torvalds 已提交
1199
	/* Enable transmit */
1200
	outb(IRCC_LCR_B_SCE_TRANSMIT | IRCC_LCR_B_SIP_ENABLE, iobase + IRCC_LCR_B);
L
Linus Torvalds 已提交
1201 1202 1203 1204 1205
}

/*
 * Function smsc_ircc_dma_xmit_complete (self)
 *
1206
 *    The transfer of a frame in finished. This function will only be called
L
Linus Torvalds 已提交
1207 1208 1209
 *    by the interrupt handler
 *
 */
1210
static void smsc_ircc_dma_xmit_complete(struct smsc_ircc_cb *self)
L
Linus Torvalds 已提交
1211
{
1212 1213
	int iobase = self->io.fir_base;

L
Linus Torvalds 已提交
1214 1215 1216 1217
	IRDA_DEBUG(3, "%s\n", __FUNCTION__);
#if 0
	/* Disable Tx */
	register_bank(iobase, 0);
1218
	outb(0x00, iobase + IRCC_LCR_B);
L
Linus Torvalds 已提交
1219
#endif
1220 1221 1222
	register_bank(iobase, 1);
	outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
	     iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1223 1224 1225

	/* Check for underrun! */
	register_bank(iobase, 0);
1226
	if (inb(iobase + IRCC_LSR) & IRCC_LSR_UNDERRUN) {
L
Linus Torvalds 已提交
1227 1228 1229 1230 1231
		self->stats.tx_errors++;
		self->stats.tx_fifo_errors++;

		/* Reset error condition */
		register_bank(iobase, 0);
1232 1233
		outb(IRCC_MASTER_ERROR_RESET, iobase + IRCC_MASTER);
		outb(0x00, iobase + IRCC_MASTER);
L
Linus Torvalds 已提交
1234 1235
	} else {
		self->stats.tx_packets++;
1236
		self->stats.tx_bytes += self->tx_buff.len;
L
Linus Torvalds 已提交
1237 1238 1239 1240
	}

	/* Check if it's time to change the speed */
	if (self->new_speed) {
1241
		smsc_ircc_change_speed(self, self->new_speed);
L
Linus Torvalds 已提交
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254
		self->new_speed = 0;
	}

	netif_wake_queue(self->netdev);
}

/*
 * Function smsc_ircc_dma_receive(self)
 *
 *    Get ready for receiving a frame. The device will initiate a DMA
 *    if it starts to receive a frame.
 *
 */
1255
static int smsc_ircc_dma_receive(struct smsc_ircc_cb *self)
L
Linus Torvalds 已提交
1256
{
1257
	int iobase = self->io.fir_base;
L
Linus Torvalds 已提交
1258 1259 1260
#if 0
	/* Turn off chip DMA */
	register_bank(iobase, 1);
1261 1262
	outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
	     iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1263
#endif
1264

L
Linus Torvalds 已提交
1265 1266
	/* Disable Tx */
	register_bank(iobase, 0);
1267
	outb(0x00, iobase + IRCC_LCR_B);
L
Linus Torvalds 已提交
1268 1269 1270

	/* Turn off chip DMA */
	register_bank(iobase, 1);
1271 1272
	outb(inb(iobase + IRCC_SCE_CFGB) & ~IRCC_CFGB_DMA_ENABLE,
	     iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1273 1274 1275 1276 1277 1278

	self->io.direction = IO_RECV;
	self->rx_buff.data = self->rx_buff.head;

	/* Set max Rx frame size */
	register_bank(iobase, 4);
1279 1280
	outb((2050 >> 8) & 0x0f, iobase + IRCC_RX_SIZE_HI);
	outb(2050 & 0xff, iobase + IRCC_RX_SIZE_LO);
L
Linus Torvalds 已提交
1281 1282 1283 1284 1285 1286 1287

	/* Setup DMA controller */
	irda_setup_dma(self->io.dma, self->rx_buff_dma, self->rx_buff.truesize,
		       DMA_RX_MODE);

	/* Enable burst mode chip Rx DMA */
	register_bank(iobase, 1);
1288 1289
	outb(inb(iobase + IRCC_SCE_CFGB) | IRCC_CFGB_DMA_ENABLE |
	     IRCC_CFGB_DMA_BURST, iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1290 1291 1292

	/* Enable interrupt */
	register_bank(iobase, 0);
1293 1294
	outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
	outb(IRCC_MASTER_INT_EN, iobase + IRCC_MASTER);
L
Linus Torvalds 已提交
1295 1296 1297

	/* Enable receiver */
	register_bank(iobase, 0);
1298
	outb(IRCC_LCR_B_SCE_RECEIVE | IRCC_LCR_B_SIP_ENABLE,
1299
	     iobase + IRCC_LCR_B);
1300

L
Linus Torvalds 已提交
1301 1302 1303 1304
	return 0;
}

/*
1305
 * Function smsc_ircc_dma_receive_complete(self)
L
Linus Torvalds 已提交
1306 1307 1308 1309
 *
 *    Finished with receiving frames
 *
 */
1310
static void smsc_ircc_dma_receive_complete(struct smsc_ircc_cb *self)
L
Linus Torvalds 已提交
1311 1312 1313
{
	struct sk_buff *skb;
	int len, msgcnt, lsr;
1314
	int iobase = self->io.fir_base;
1315

L
Linus Torvalds 已提交
1316
	register_bank(iobase, 0);
1317

L
Linus Torvalds 已提交
1318 1319 1320 1321
	IRDA_DEBUG(3, "%s\n", __FUNCTION__);
#if 0
	/* Disable Rx */
	register_bank(iobase, 0);
1322
	outb(0x00, iobase + IRCC_LCR_B);
L
Linus Torvalds 已提交
1323 1324
#endif
	register_bank(iobase, 0);
1325 1326 1327
	outb(inb(iobase + IRCC_LSAR) & ~IRCC_LSAR_ADDRESS_MASK, iobase + IRCC_LSAR);
	lsr= inb(iobase + IRCC_LSR);
	msgcnt = inb(iobase + IRCC_LCR_B) & 0x08;
L
Linus Torvalds 已提交
1328 1329 1330 1331 1332 1333

	IRDA_DEBUG(2, "%s: dma count = %d\n", __FUNCTION__,
		   get_dma_residue(self->io.dma));

	len = self->rx_buff.truesize - get_dma_residue(self->io.dma);

1334 1335
	/* Look for errors */
	if (lsr & (IRCC_LSR_FRAME_ERROR | IRCC_LSR_CRC_ERROR | IRCC_LSR_SIZE_ERROR)) {
L
Linus Torvalds 已提交
1336
		self->stats.rx_errors++;
1337 1338 1339 1340 1341 1342 1343 1344
		if (lsr & IRCC_LSR_FRAME_ERROR)
			self->stats.rx_frame_errors++;
		if (lsr & IRCC_LSR_CRC_ERROR)
			self->stats.rx_crc_errors++;
		if (lsr & IRCC_LSR_SIZE_ERROR)
			self->stats.rx_length_errors++;
		if (lsr & (IRCC_LSR_UNDERRUN | IRCC_LSR_OVERRUN))
			self->stats.rx_length_errors++;
L
Linus Torvalds 已提交
1345 1346
		return;
	}
1347

L
Linus Torvalds 已提交
1348
	/* Remove CRC */
1349
	len -= self->io.speed < 4000000 ? 2 : 4;
L
Linus Torvalds 已提交
1350

1351
	if (len < 2 || len > 2050) {
L
Linus Torvalds 已提交
1352 1353 1354 1355 1356
		IRDA_WARNING("%s(), bogus len=%d\n", __FUNCTION__, len);
		return;
	}
	IRDA_DEBUG(2, "%s: msgcnt = %d, len=%d\n", __FUNCTION__, msgcnt, len);

1357 1358
	skb = dev_alloc_skb(len + 1);
	if (!skb) {
L
Linus Torvalds 已提交
1359 1360 1361
		IRDA_WARNING("%s(), memory squeeze, dropping frame.\n",
			     __FUNCTION__);
		return;
1362
	}
L
Linus Torvalds 已提交
1363
	/* Make sure IP header gets aligned */
1364
	skb_reserve(skb, 1);
L
Linus Torvalds 已提交
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381

	memcpy(skb_put(skb, len), self->rx_buff.data, len);
	self->stats.rx_packets++;
	self->stats.rx_bytes += len;

	skb->dev = self->netdev;
	skb->mac.raw  = skb->data;
	skb->protocol = htons(ETH_P_IRDA);
	netif_rx(skb);
}

/*
 * Function smsc_ircc_sir_receive (self)
 *
 *    Receive one frame from the infrared port
 *
 */
1382
static void smsc_ircc_sir_receive(struct smsc_ircc_cb *self)
L
Linus Torvalds 已提交
1383 1384 1385 1386 1387 1388 1389 1390
{
	int boguscount = 0;
	int iobase;

	IRDA_ASSERT(self != NULL, return;);

	iobase = self->io.sir_base;

1391 1392 1393
	/*
	 * Receive all characters in Rx FIFO, unwrap and unstuff them.
         * async_unwrap_char will deliver all found frames
L
Linus Torvalds 已提交
1394 1395
	 */
	do {
1396
		async_unwrap_char(self->netdev, &self->stats, &self->rx_buff,
1397
				  inb(iobase + UART_RX));
L
Linus Torvalds 已提交
1398 1399 1400 1401 1402 1403

		/* Make sure we don't stay here to long */
		if (boguscount++ > 32) {
			IRDA_DEBUG(2, "%s(), breaking!\n", __FUNCTION__);
			break;
		}
1404
	} while (inb(iobase + UART_LSR) & UART_LSR_DR);
L
Linus Torvalds 已提交
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
}


/*
 * Function smsc_ircc_interrupt (irq, dev_id, regs)
 *
 *    An interrupt from the chip has arrived. Time to do some work
 *
 */
static irqreturn_t smsc_ircc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
	struct net_device *dev = (struct net_device *) dev_id;
	struct smsc_ircc_cb *self;
	int iobase, iir, lcra, lsr;
	irqreturn_t ret = IRQ_NONE;

	if (dev == NULL) {
1422
		printk(KERN_WARNING "%s: irq %d for unknown device.\n",
L
Linus Torvalds 已提交
1423 1424 1425
		       driver_name, irq);
		goto irq_ret;
	}
1426 1427

	self = netdev_priv(dev);
L
Linus Torvalds 已提交
1428 1429 1430
	IRDA_ASSERT(self != NULL, return IRQ_NONE;);

	/* Serialise the interrupt handler in various CPUs, stop Tx path */
1431
	spin_lock(&self->lock);
L
Linus Torvalds 已提交
1432 1433

	/* Check if we should use the SIR interrupt handler */
1434
	if (self->io.speed <= SMSC_IRCC2_MAX_SIR_SPEED) {
L
Linus Torvalds 已提交
1435 1436 1437 1438 1439 1440 1441
		ret = smsc_ircc_interrupt_sir(dev);
		goto irq_ret_unlock;
	}

	iobase = self->io.fir_base;

	register_bank(iobase, 0);
1442
	iir = inb(iobase + IRCC_IIR);
1443
	if (iir == 0)
L
Linus Torvalds 已提交
1444 1445 1446 1447
		goto irq_ret_unlock;
	ret = IRQ_HANDLED;

	/* Disable interrupts */
1448 1449 1450
	outb(0, iobase + IRCC_IER);
	lcra = inb(iobase + IRCC_LCR_A);
	lsr = inb(iobase + IRCC_LSR);
1451

L
Linus Torvalds 已提交
1452 1453 1454 1455
	IRDA_DEBUG(2, "%s(), iir = 0x%02x\n", __FUNCTION__, iir);

	if (iir & IRCC_IIR_EOM) {
		if (self->io.direction == IO_RECV)
1456
			smsc_ircc_dma_receive_complete(self);
L
Linus Torvalds 已提交
1457
		else
1458
			smsc_ircc_dma_xmit_complete(self);
1459

1460
		smsc_ircc_dma_receive(self);
L
Linus Torvalds 已提交
1461 1462 1463 1464 1465 1466 1467 1468 1469
	}

	if (iir & IRCC_IIR_ACTIVE_FRAME) {
		/*printk(KERN_WARNING "%s(): Active Frame\n", __FUNCTION__);*/
	}

	/* Enable interrupts again */

	register_bank(iobase, 0);
1470
	outb(IRCC_IER_ACTIVE_FRAME | IRCC_IER_EOM, iobase + IRCC_IER);
L
Linus Torvalds 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484

 irq_ret_unlock:
	spin_unlock(&self->lock);
 irq_ret:
	return ret;
}

/*
 * Function irport_interrupt_sir (irq, dev_id, regs)
 *
 *    Interrupt handler for SIR modes
 */
static irqreturn_t smsc_ircc_interrupt_sir(struct net_device *dev)
{
1485
	struct smsc_ircc_cb *self = netdev_priv(dev);
L
Linus Torvalds 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494
	int boguscount = 0;
	int iobase;
	int iir, lsr;

	/* Already locked comming here in smsc_ircc_interrupt() */
	/*spin_lock(&self->lock);*/

	iobase = self->io.sir_base;

1495
	iir = inb(iobase + UART_IIR) & UART_IIR_ID;
L
Linus Torvalds 已提交
1496 1497 1498 1499
	if (iir == 0)
		return IRQ_NONE;
	while (iir) {
		/* Clear interrupt */
1500
		lsr = inb(iobase + UART_LSR);
L
Linus Torvalds 已提交
1501

1502
		IRDA_DEBUG(4, "%s(), iir=%02x, lsr=%02x, iobase=%#x\n",
L
Linus Torvalds 已提交
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
			    __FUNCTION__, iir, lsr, iobase);

		switch (iir) {
		case UART_IIR_RLSI:
			IRDA_DEBUG(2, "%s(), RLSI\n", __FUNCTION__);
			break;
		case UART_IIR_RDI:
			/* Receive interrupt */
			smsc_ircc_sir_receive(self);
			break;
		case UART_IIR_THRI:
			if (lsr & UART_LSR_THRE)
				/* Transmitter ready for data */
				smsc_ircc_sir_write_wakeup(self);
			break;
		default:
			IRDA_DEBUG(0, "%s(), unhandled IIR=%#x\n",
				   __FUNCTION__, iir);
			break;
1522 1523
		}

L
Linus Torvalds 已提交
1524 1525 1526 1527
		/* Make sure we don't stay here to long */
		if (boguscount++ > 100)
			break;

1528
	        iir = inb(iobase + UART_IIR) & UART_IIR_ID;
L
Linus Torvalds 已提交
1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554
	}
	/*spin_unlock(&self->lock);*/
	return IRQ_HANDLED;
}


#if 0 /* unused */
/*
 * Function ircc_is_receiving (self)
 *
 *    Return TRUE is we are currently receiving a frame
 *
 */
static int ircc_is_receiving(struct smsc_ircc_cb *self)
{
	int status = FALSE;
	/* int iobase; */

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return FALSE;);

	IRDA_DEBUG(0, "%s: dma count = %d\n", __FUNCTION__,
		   get_dma_residue(self->io.dma));

	status = (self->rx_buff.state != OUTSIDE_FRAME);
1555

L
Linus Torvalds 已提交
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
	return status;
}
#endif /* unused */


/*
 * Function smsc_ircc_net_open (dev)
 *
 *    Start the device
 *
 */
static int smsc_ircc_net_open(struct net_device *dev)
{
	struct smsc_ircc_cb *self;
	char hwname[16];
	unsigned long flags;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1574

L
Linus Torvalds 已提交
1575
	IRDA_ASSERT(dev != NULL, return -1;);
1576
	self = netdev_priv(dev);
L
Linus Torvalds 已提交
1577
	IRDA_ASSERT(self != NULL, return 0;);
1578 1579

	if (request_irq(self->io.irq, smsc_ircc_interrupt, 0, dev->name,
L
Linus Torvalds 已提交
1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
			(void *) dev)) {
		IRDA_DEBUG(0, "%s(), unable to allocate irq=%d\n",
			   __FUNCTION__, self->io.irq);
		return -EAGAIN;
	}

	spin_lock_irqsave(&self->lock, flags);
	/*smsc_ircc_sir_start(self);*/
	self->io.speed = 0;
	smsc_ircc_change_speed(self, SMSC_IRCC2_C_IRDA_FALLBACK_SPEED);
	spin_unlock_irqrestore(&self->lock, flags);
1591

L
Linus Torvalds 已提交
1592 1593 1594 1595
	/* Give self a hardware name */
	/* It would be cool to offer the chip revision here - Jean II */
	sprintf(hwname, "SMSC @ 0x%03x", self->io.fir_base);

1596
	/*
L
Linus Torvalds 已提交
1597
	 * Open new IrLAP layer instance, now that everything should be
1598
	 * initialized properly
L
Linus Torvalds 已提交
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612
	 */
	self->irlap = irlap_open(dev, &self->qos, hwname);

	/*
	 * Always allocate the DMA channel after the IRQ,
	 * and clean up on failure.
	 */
	if (request_dma(self->io.dma, dev->name)) {
		smsc_ircc_net_close(dev);

		IRDA_WARNING("%s(), unable to allocate DMA=%d\n",
			     __FUNCTION__, self->io.dma);
		return -EAGAIN;
	}
1613

L
Linus Torvalds 已提交
1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629
	netif_start_queue(dev);

	return 0;
}

/*
 * Function smsc_ircc_net_close (dev)
 *
 *    Stop the device
 *
 */
static int smsc_ircc_net_close(struct net_device *dev)
{
	struct smsc_ircc_cb *self;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);
1630

L
Linus Torvalds 已提交
1631
	IRDA_ASSERT(dev != NULL, return -1;);
1632
	self = netdev_priv(dev);
L
Linus Torvalds 已提交
1633
	IRDA_ASSERT(self != NULL, return 0;);
1634

L
Linus Torvalds 已提交
1635 1636
	/* Stop device */
	netif_stop_queue(dev);
1637

L
Linus Torvalds 已提交
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
	/* Stop and remove instance of IrLAP */
	if (self->irlap)
		irlap_close(self->irlap);
	self->irlap = NULL;

	free_irq(self->io.irq, dev);
	disable_dma(self->io.dma);
	free_dma(self->io.dma);

	return 0;
}

1650
static int smsc_ircc_suspend(struct device *dev, pm_message_t state)
L
Linus Torvalds 已提交
1651
{
1652 1653
	struct smsc_ircc_cb *self = dev_get_drvdata(dev);

L
Linus Torvalds 已提交
1654 1655
	IRDA_MESSAGE("%s, Suspending\n", driver_name);

1656
	if (!self->io.suspended) {
1657 1658 1659
		smsc_ircc_net_close(self->netdev);
		self->io.suspended = 1;
	}
1660 1661

	return 0;
L
Linus Torvalds 已提交
1662 1663
}

1664
static int smsc_ircc_resume(struct device *dev)
L
Linus Torvalds 已提交
1665
{
1666
	struct smsc_ircc_cb *self = dev_get_drvdata(dev);
L
Linus Torvalds 已提交
1667

1668
	if (self->io.suspended) {
1669

1670 1671
		smsc_ircc_net_open(self->netdev);
		self->io.suspended = 0;
L
Linus Torvalds 已提交
1672

1673 1674
		IRDA_MESSAGE("%s, Waking up\n", driver_name);
	}
L
Linus Torvalds 已提交
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692
	return 0;
}

/*
 * Function smsc_ircc_close (self)
 *
 *    Close driver instance
 *
 */
static int __exit smsc_ircc_close(struct smsc_ircc_cb *self)
{
	int iobase;
	unsigned long flags;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	IRDA_ASSERT(self != NULL, return -1;);

1693
	platform_device_unregister(self->pldev);
L
Linus Torvalds 已提交
1694 1695 1696 1697 1698 1699 1700 1701

	/* Remove netdevice */
	unregister_netdev(self->netdev);

	/* Make sure the irq handler is not exectuting */
	spin_lock_irqsave(&self->lock, flags);

	/* Stop interrupts */
1702
	iobase = self->io.fir_base;
L
Linus Torvalds 已提交
1703
	register_bank(iobase, 0);
1704 1705 1706
	outb(0, iobase + IRCC_IER);
	outb(IRCC_MASTER_RESET, iobase + IRCC_MASTER);
	outb(0x00, iobase + IRCC_MASTER);
L
Linus Torvalds 已提交
1707 1708 1709
#if 0
	/* Reset to SIR mode */
	register_bank(iobase, 1);
1710 1711
        outb(IRCC_CFGA_IRDA_SIR_A|IRCC_CFGA_TX_POLARITY, iobase + IRCC_SCE_CFGA);
        outb(IRCC_CFGB_IR, iobase + IRCC_SCE_CFGB);
L
Linus Torvalds 已提交
1712 1713 1714 1715 1716 1717 1718 1719 1720
#endif
	spin_unlock_irqrestore(&self->lock, flags);

	/* Release the PORTS that this driver is using */
	IRDA_DEBUG(0, "%s(), releasing 0x%03x\n",  __FUNCTION__,
		   self->io.fir_base);

	release_region(self->io.fir_base, self->io.fir_ext);

1721
	IRDA_DEBUG(0, "%s(), releasing 0x%03x\n", __FUNCTION__,
L
Linus Torvalds 已提交
1722 1723 1724 1725 1726 1727 1728
		   self->io.sir_base);

	release_region(self->io.sir_base, self->io.sir_ext);

	if (self->tx_buff.head)
		dma_free_coherent(NULL, self->tx_buff.truesize,
				  self->tx_buff.head, self->tx_buff_dma);
1729

L
Linus Torvalds 已提交
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
	if (self->rx_buff.head)
		dma_free_coherent(NULL, self->rx_buff.truesize,
				  self->rx_buff.head, self->rx_buff_dma);

	free_netdev(self->netdev);

	return 0;
}

static void __exit smsc_ircc_cleanup(void)
{
	int i;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

1745
	for (i = 0; i < 2; i++) {
L
Linus Torvalds 已提交
1746 1747 1748
		if (dev_self[i])
			smsc_ircc_close(dev_self[i]);
	}
1749 1750

	driver_unregister(&smsc_ircc_driver);
L
Linus Torvalds 已提交
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
}

/*
 *	Start SIR operations
 *
 * This function *must* be called with spinlock held, because it may
 * be called from the irq handler (via smsc_ircc_change_speed()). - Jean II
 */
void smsc_ircc_sir_start(struct smsc_ircc_cb *self)
{
	struct net_device *dev;
	int fir_base, sir_base;

	IRDA_DEBUG(3, "%s\n", __FUNCTION__);

1766
	IRDA_ASSERT(self != NULL, return;);
1767
	dev = self->netdev;
1768
	IRDA_ASSERT(dev != NULL, return;);
L
Linus Torvalds 已提交
1769 1770 1771 1772 1773 1774
	dev->hard_start_xmit = &smsc_ircc_hard_xmit_sir;

	fir_base = self->io.fir_base;
	sir_base = self->io.sir_base;

	/* Reset everything */
1775
	outb(IRCC_MASTER_RESET, fir_base + IRCC_MASTER);
L
Linus Torvalds 已提交
1776 1777 1778 1779 1780 1781

	#if SMSC_IRCC2_C_SIR_STOP
	/*smsc_ircc_sir_stop(self);*/
	#endif

	register_bank(fir_base, 1);
1782
	outb(((inb(fir_base + IRCC_SCE_CFGA) & IRCC_SCE_CFGA_BLOCK_CTRL_BITS_MASK) | IRCC_CFGA_IRDA_SIR_A), fir_base + IRCC_SCE_CFGA);
L
Linus Torvalds 已提交
1783 1784

	/* Initialize UART */
1785 1786
	outb(UART_LCR_WLEN8, sir_base + UART_LCR);  /* Reset DLAB */
	outb((UART_MCR_DTR | UART_MCR_RTS | UART_MCR_OUT2), sir_base + UART_MCR);
1787

L
Linus Torvalds 已提交
1788
	/* Turn on interrups */
1789
	outb(UART_IER_RLSI | UART_IER_RDI |UART_IER_THRI, sir_base + UART_IER);
L
Linus Torvalds 已提交
1790 1791 1792

	IRDA_DEBUG(3, "%s() - exit\n", __FUNCTION__);

1793
	outb(0x00, fir_base + IRCC_MASTER);
L
Linus Torvalds 已提交
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804
}

#if SMSC_IRCC2_C_SIR_STOP
void smsc_ircc_sir_stop(struct smsc_ircc_cb *self)
{
	int iobase;

	IRDA_DEBUG(3, "%s\n", __FUNCTION__);
	iobase = self->io.sir_base;

	/* Reset UART */
1805
	outb(0, iobase + UART_MCR);
1806

L
Linus Torvalds 已提交
1807
	/* Turn off interrupts */
1808
	outb(0, iobase + UART_IER);
L
Linus Torvalds 已提交
1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833
}
#endif

/*
 * Function smsc_sir_write_wakeup (self)
 *
 *    Called by the SIR interrupt handler when there's room for more data.
 *    If we have more packets to send, we send them here.
 *
 */
static void smsc_ircc_sir_write_wakeup(struct smsc_ircc_cb *self)
{
	int actual = 0;
	int iobase;
	int fcr;

	IRDA_ASSERT(self != NULL, return;);

	IRDA_DEBUG(4, "%s\n", __FUNCTION__);

	iobase = self->io.sir_base;

	/* Finished with frame?  */
	if (self->tx_buff.len > 0)  {
		/* Write data left in transmit buffer */
1834
		actual = smsc_ircc_sir_write(iobase, self->io.fifo_size,
L
Linus Torvalds 已提交
1835 1836 1837 1838
				      self->tx_buff.data, self->tx_buff.len);
		self->tx_buff.data += actual;
		self->tx_buff.len  -= actual;
	} else {
1839

L
Linus Torvalds 已提交
1840
	/*if (self->tx_buff.len ==0)  {*/
1841 1842 1843

		/*
		 *  Now serial buffer is almost free & we can start
L
Linus Torvalds 已提交
1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858
		 *  transmission of another packet. But first we must check
		 *  if we need to change the speed of the hardware
		 */
		if (self->new_speed) {
			IRDA_DEBUG(5, "%s(), Changing speed to %d.\n",
				   __FUNCTION__, self->new_speed);
			smsc_ircc_sir_wait_hw_transmitter_finish(self);
			smsc_ircc_change_speed(self, self->new_speed);
			self->new_speed = 0;
		} else {
			/* Tell network layer that we want more frames */
			netif_wake_queue(self->netdev);
		}
		self->stats.tx_packets++;

1859 1860 1861 1862 1863 1864 1865 1866
		if (self->io.speed <= 115200) {
			/*
			 * Reset Rx FIFO to make sure that all reflected transmit data
			 * is discarded. This is needed for half duplex operation
			 */
			fcr = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR;
			fcr |= self->io.speed < 38400 ?
					UART_FCR_TRIGGER_1 : UART_FCR_TRIGGER_14;
L
Linus Torvalds 已提交
1867

1868
			outb(fcr, iobase + UART_FCR);
L
Linus Torvalds 已提交
1869

1870 1871
			/* Turn on receive interrupts */
			outb(UART_IER_RDI, iobase + UART_IER);
L
Linus Torvalds 已提交
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884
		}
	}
}

/*
 * Function smsc_ircc_sir_write (iobase, fifo_size, buf, len)
 *
 *    Fill Tx FIFO with transmit data
 *
 */
static int smsc_ircc_sir_write(int iobase, int fifo_size, __u8 *buf, int len)
{
	int actual = 0;
1885

L
Linus Torvalds 已提交
1886
	/* Tx FIFO should be empty! */
1887
	if (!(inb(iobase + UART_LSR) & UART_LSR_THRE)) {
L
Linus Torvalds 已提交
1888 1889 1890
		IRDA_WARNING("%s(), failed, fifo not empty!\n", __FUNCTION__);
		return 0;
	}
1891

L
Linus Torvalds 已提交
1892
	/* Fill FIFO with current frame */
1893
	while (fifo_size-- > 0 && actual < len) {
L
Linus Torvalds 已提交
1894
		/* Transmit next byte */
1895
		outb(buf[actual], iobase + UART_TX);
L
Linus Torvalds 已提交
1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
		actual++;
	}
	return actual;
}

/*
 * Function smsc_ircc_is_receiving (self)
 *
 *    Returns true is we are currently receiving data
 *
 */
static int smsc_ircc_is_receiving(struct smsc_ircc_cb *self)
{
	return (self->rx_buff.state != OUTSIDE_FRAME);
}


/*
 * Function smsc_ircc_probe_transceiver(self)
 *
 *    Tries to find the used Transceiver
 *
 */
static void smsc_ircc_probe_transceiver(struct smsc_ircc_cb *self)
{
	unsigned int	i;
1922

L
Linus Torvalds 已提交
1923
	IRDA_ASSERT(self != NULL, return;);
1924

1925 1926
	for (i = 0; smsc_transceivers[i].name != NULL; i++)
		if (smsc_transceivers[i].probe(self->io.fir_base)) {
L
Linus Torvalds 已提交
1927 1928
			IRDA_MESSAGE(" %s transceiver found\n",
				     smsc_transceivers[i].name);
1929
			self->transceiver= i + 1;
L
Linus Torvalds 已提交
1930 1931
			return;
		}
1932

L
Linus Torvalds 已提交
1933 1934
	IRDA_MESSAGE("No transceiver found. Defaulting to %s\n",
		     smsc_transceivers[SMSC_IRCC2_C_DEFAULT_TRANSCEIVER].name);
1935

1936
	self->transceiver = SMSC_IRCC2_C_DEFAULT_TRANSCEIVER;
L
Linus Torvalds 已提交
1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948
}


/*
 * Function smsc_ircc_set_transceiver_for_speed(self, speed)
 *
 *    Set the transceiver according to the speed
 *
 */
static void smsc_ircc_set_transceiver_for_speed(struct smsc_ircc_cb *self, u32 speed)
{
	unsigned int trx;
1949

L
Linus Torvalds 已提交
1950
	trx = self->transceiver;
1951 1952
	if (trx > 0)
		smsc_transceivers[trx - 1].set_for_speed(self->io.fir_base, speed);
L
Linus Torvalds 已提交
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979
}

/*
 * Function smsc_ircc_wait_hw_transmitter_finish ()
 *
 *    Wait for the real end of HW transmission
 *
 * The UART is a strict FIFO, and we get called only when we have finished
 * pushing data to the FIFO, so the maximum amount of time we must wait
 * is only for the FIFO to drain out.
 *
 * We use a simple calibrated loop. We may need to adjust the loop
 * delay (udelay) to balance I/O traffic and latency. And we also need to
 * adjust the maximum timeout.
 * It would probably be better to wait for the proper interrupt,
 * but it doesn't seem to be available.
 *
 * We can't use jiffies or kernel timers because :
 * 1) We are called from the interrupt handler, which disable softirqs,
 * so jiffies won't be increased
 * 2) Jiffies granularity is usually very coarse (10ms), and we don't
 * want to wait that long to detect stuck hardware.
 * Jean II
 */

static void smsc_ircc_sir_wait_hw_transmitter_finish(struct smsc_ircc_cb *self)
{
1980
	int iobase = self->io.sir_base;
L
Linus Torvalds 已提交
1981
	int count = SMSC_IRCC2_HW_TRANSMITTER_TIMEOUT_US;
1982

L
Linus Torvalds 已提交
1983
	/* Calibrated busy loop */
1984
	while (count-- > 0 && !(inb(iobase + UART_LSR) & UART_LSR_TEMT))
L
Linus Torvalds 已提交
1985 1986
		udelay(1);

1987
	if (count == 0)
L
Linus Torvalds 已提交
1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998
		IRDA_DEBUG(0, "%s(): stuck transmitter\n", __FUNCTION__);
}


/* PROBING
 *
 *
 */

static int __init smsc_ircc_look_for_chips(void)
{
1999
	struct smsc_chip_address *address;
2000
	char *type;
L
Linus Torvalds 已提交
2001
	unsigned int cfg_base, found;
2002

L
Linus Torvalds 已提交
2003 2004
	found = 0;
	address = possible_addresses;
2005

2006
	while (address->cfg_base) {
L
Linus Torvalds 已提交
2007
		cfg_base = address->cfg_base;
2008

L
Linus Torvalds 已提交
2009
		/*printk(KERN_WARNING "%s(): probing: 0x%02x for: 0x%02x\n", __FUNCTION__, cfg_base, address->type);*/
2010

2011
		if (address->type & SMSCSIO_TYPE_FDC) {
L
Linus Torvalds 已提交
2012
			type = "FDC";
2013 2014 2015 2016 2017 2018 2019
			if (address->type & SMSCSIO_TYPE_FLAT)
				if (!smsc_superio_flat(fdc_chips_flat, cfg_base, type))
					found++;

			if (address->type & SMSCSIO_TYPE_PAGED)
				if (!smsc_superio_paged(fdc_chips_paged, cfg_base, type))
					found++;
L
Linus Torvalds 已提交
2020
		}
2021
		if (address->type & SMSCSIO_TYPE_LPC) {
L
Linus Torvalds 已提交
2022
			type = "LPC";
2023 2024 2025 2026 2027 2028 2029
			if (address->type & SMSCSIO_TYPE_FLAT)
				if (!smsc_superio_flat(lpc_chips_flat, cfg_base, type))
					found++;

			if (address->type & SMSCSIO_TYPE_PAGED)
				if (!smsc_superio_paged(lpc_chips_paged, cfg_base, type))
					found++;
L
Linus Torvalds 已提交
2030 2031 2032 2033
		}
		address++;
	}
	return found;
2034
}
L
Linus Torvalds 已提交
2035 2036 2037 2038 2039 2040 2041

/*
 * Function smsc_superio_flat (chip, base, type)
 *
 *    Try to get configuration of a smc SuperIO chip with flat register model
 *
 */
2042
static int __init smsc_superio_flat(const struct smsc_chip *chips, unsigned short cfgbase, char *type)
L
Linus Torvalds 已提交
2043 2044 2045 2046 2047 2048 2049
{
	unsigned short firbase, sirbase;
	u8 mode, dma, irq;
	int ret = -ENODEV;

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

2050
	if (smsc_ircc_probe(cfgbase, SMSCSIOFLAT_DEVICEID_REG, chips, type) == NULL)
L
Linus Torvalds 已提交
2051 2052 2053
		return ret;

	outb(SMSCSIOFLAT_UARTMODE0C_REG, cfgbase);
2054
	mode = inb(cfgbase + 1);
2055

L
Linus Torvalds 已提交
2056
	/*printk(KERN_WARNING "%s(): mode: 0x%02x\n", __FUNCTION__, mode);*/
2057

2058
	if (!(mode & SMSCSIOFLAT_UART2MODE_VAL_IRDA))
L
Linus Torvalds 已提交
2059 2060 2061
		IRDA_WARNING("%s(): IrDA not enabled\n", __FUNCTION__);

	outb(SMSCSIOFLAT_UART2BASEADDR_REG, cfgbase);
2062
	sirbase = inb(cfgbase + 1) << 2;
L
Linus Torvalds 已提交
2063

2064
	/* FIR iobase */
L
Linus Torvalds 已提交
2065
	outb(SMSCSIOFLAT_FIRBASEADDR_REG, cfgbase);
2066
	firbase = inb(cfgbase + 1) << 3;
L
Linus Torvalds 已提交
2067 2068 2069

	/* DMA */
	outb(SMSCSIOFLAT_FIRDMASELECT_REG, cfgbase);
2070
	dma = inb(cfgbase + 1) & SMSCSIOFLAT_FIRDMASELECT_MASK;
2071

L
Linus Torvalds 已提交
2072 2073
	/* IRQ */
	outb(SMSCSIOFLAT_UARTIRQSELECT_REG, cfgbase);
2074
	irq = inb(cfgbase + 1) & SMSCSIOFLAT_UART2IRQSELECT_MASK;
L
Linus Torvalds 已提交
2075 2076 2077

	IRDA_MESSAGE("%s(): fir: 0x%02x, sir: 0x%02x, dma: %02d, irq: %d, mode: 0x%02x\n", __FUNCTION__, firbase, sirbase, dma, irq, mode);

2078 2079
	if (firbase && smsc_ircc_open(firbase, sirbase, dma, irq) == 0)
		ret = 0;
2080

L
Linus Torvalds 已提交
2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
	/* Exit configuration */
	outb(SMSCSIO_CFGEXITKEY, cfgbase);

	return ret;
}

/*
 * Function smsc_superio_paged (chip, base, type)
 *
 *    Try  to get configuration of a smc SuperIO chip with paged register model
 *
 */
2093
static int __init smsc_superio_paged(const struct smsc_chip *chips, unsigned short cfg_base, char *type)
L
Linus Torvalds 已提交
2094 2095 2096
{
	unsigned short fir_io, sir_io;
	int ret = -ENODEV;
2097

L
Linus Torvalds 已提交
2098 2099
	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

2100
	if (smsc_ircc_probe(cfg_base, 0x20, chips, type) == NULL)
L
Linus Torvalds 已提交
2101
		return ret;
2102

L
Linus Torvalds 已提交
2103 2104 2105
	/* Select logical device (UART2) */
	outb(0x07, cfg_base);
	outb(0x05, cfg_base + 1);
2106

L
Linus Torvalds 已提交
2107 2108
	/* SIR iobase */
	outb(0x60, cfg_base);
2109
	sir_io = inb(cfg_base + 1) << 8;
L
Linus Torvalds 已提交
2110 2111
	outb(0x61, cfg_base);
	sir_io |= inb(cfg_base + 1);
2112

L
Linus Torvalds 已提交
2113 2114 2115 2116 2117 2118 2119
	/* Read FIR base */
	outb(0x62, cfg_base);
	fir_io = inb(cfg_base + 1) << 8;
	outb(0x63, cfg_base);
	fir_io |= inb(cfg_base + 1);
	outb(0x2b, cfg_base); /* ??? */

2120 2121
	if (fir_io && smsc_ircc_open(fir_io, sir_io, ircc_dma, ircc_irq) == 0)
		ret = 0;
2122

L
Linus Torvalds 已提交
2123 2124 2125 2126 2127 2128 2129
	/* Exit configuration */
	outb(SMSCSIO_CFGEXITKEY, cfg_base);

	return ret;
}


2130
static int __init smsc_access(unsigned short cfg_base, unsigned char reg)
L
Linus Torvalds 已提交
2131 2132 2133 2134
{
	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	outb(reg, cfg_base);
2135
	return inb(cfg_base) != reg ? -1 : 0;
L
Linus Torvalds 已提交
2136 2137
}

2138
static const struct smsc_chip * __init smsc_ircc_probe(unsigned short cfg_base, u8 reg, const struct smsc_chip *chip, char *type)
L
Linus Torvalds 已提交
2139
{
2140
	u8 devid, xdevid, rev;
L
Linus Torvalds 已提交
2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152

	IRDA_DEBUG(1, "%s\n", __FUNCTION__);

	/* Leave configuration */

	outb(SMSCSIO_CFGEXITKEY, cfg_base);

	if (inb(cfg_base) == SMSCSIO_CFGEXITKEY)	/* not a smc superio chip */
		return NULL;

	outb(reg, cfg_base);

2153
	xdevid = inb(cfg_base + 1);
L
Linus Torvalds 已提交
2154 2155 2156 2157 2158 2159 2160 2161 2162

	/* Enter configuration */

	outb(SMSCSIO_CFGACCESSKEY, cfg_base);

	#if 0
	if (smsc_access(cfg_base,0x55))	/* send second key and check */
		return NULL;
	#endif
2163

L
Linus Torvalds 已提交
2164 2165
	/* probe device ID */

2166
	if (smsc_access(cfg_base, reg))
L
Linus Torvalds 已提交
2167 2168
		return NULL;

2169
	devid = inb(cfg_base + 1);
2170

2171
	if (devid == 0 || devid == 0xff)	/* typical values for unused port */
L
Linus Torvalds 已提交
2172 2173 2174 2175
		return NULL;

	/* probe revision ID */

2176
	if (smsc_access(cfg_base, reg + 1))
L
Linus Torvalds 已提交
2177 2178
		return NULL;

2179
	rev = inb(cfg_base + 1);
L
Linus Torvalds 已提交
2180

2181
	if (rev >= 128)			/* i think this will make no sense */
L
Linus Torvalds 已提交
2182 2183
		return NULL;

2184
	if (devid == xdevid)		/* protection against false positives */
L
Linus Torvalds 已提交
2185 2186 2187 2188
		return NULL;

	/* Check for expected device ID; are there others? */

2189
	while (chip->devid != devid) {
L
Linus Torvalds 已提交
2190 2191 2192

		chip++;

2193
		if (chip->name == NULL)
L
Linus Torvalds 已提交
2194 2195 2196
			return NULL;
	}

2197 2198
	IRDA_MESSAGE("found SMC SuperIO Chip (devid=0x%02x rev=%02X base=0x%04x): %s%s\n",
		     devid, rev, cfg_base, type, chip->name);
L
Linus Torvalds 已提交
2199

2200
	if (chip->rev > rev) {
2201
		IRDA_MESSAGE("Revision higher than expected\n");
L
Linus Torvalds 已提交
2202 2203
		return NULL;
	}
2204

2205
	if (chip->flags & NoIRDA)
L
Linus Torvalds 已提交
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218
		IRDA_MESSAGE("chipset does not support IRDA\n");

	return chip;
}

static int __init smsc_superio_fdc(unsigned short cfg_base)
{
	int ret = -1;

	if (!request_region(cfg_base, 2, driver_name)) {
		IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
			     __FUNCTION__, cfg_base);
	} else {
2219 2220
		if (!smsc_superio_flat(fdc_chips_flat, cfg_base, "FDC") ||
		    !smsc_superio_paged(fdc_chips_paged, cfg_base, "FDC"))
L
Linus Torvalds 已提交
2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236
			ret =  0;

		release_region(cfg_base, 2);
	}

	return ret;
}

static int __init smsc_superio_lpc(unsigned short cfg_base)
{
	int ret = -1;

	if (!request_region(cfg_base, 2, driver_name)) {
		IRDA_WARNING("%s: can't get cfg_base of 0x%03x\n",
			     __FUNCTION__, cfg_base);
	} else {
2237 2238
		if (!smsc_superio_flat(lpc_chips_flat, cfg_base, "LPC") ||
		    !smsc_superio_paged(lpc_chips_paged, cfg_base, "LPC"))
L
Linus Torvalds 已提交
2239
			ret = 0;
2240

L
Linus Torvalds 已提交
2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
		release_region(cfg_base, 2);
	}
	return ret;
}

/************************************************
 *
 * Transceivers specific functions
 *
 ************************************************/


/*
 * Function smsc_ircc_set_transceiver_smsc_ircc_atc(fir_base, speed)
 *
 *    Program transceiver through smsc-ircc ATC circuitry
 *
 */

static void smsc_ircc_set_transceiver_smsc_ircc_atc(int fir_base, u32 speed)
{
	unsigned long jiffies_now, jiffies_timeout;
2263
	u8 val;
2264

2265 2266
	jiffies_now = jiffies;
	jiffies_timeout = jiffies + SMSC_IRCC2_ATC_PROGRAMMING_TIMEOUT_JIFFIES;
2267

L
Linus Torvalds 已提交
2268 2269
	/* ATC */
	register_bank(fir_base, 4);
2270 2271 2272 2273 2274 2275 2276 2277
	outb((inb(fir_base + IRCC_ATC) & IRCC_ATC_MASK) | IRCC_ATC_nPROGREADY|IRCC_ATC_ENABLE,
	     fir_base + IRCC_ATC);

	while ((val = (inb(fir_base + IRCC_ATC) & IRCC_ATC_nPROGREADY)) &&
		!time_after(jiffies, jiffies_timeout))
		/* empty */;

	if (val)
L
Linus Torvalds 已提交
2278
		IRDA_WARNING("%s(): ATC: 0x%02x\n", __FUNCTION__,
2279
			     inb(fir_base + IRCC_ATC));
L
Linus Torvalds 已提交
2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296
}

/*
 * Function smsc_ircc_probe_transceiver_smsc_ircc_atc(fir_base)
 *
 *    Probe transceiver smsc-ircc ATC circuitry
 *
 */

static int smsc_ircc_probe_transceiver_smsc_ircc_atc(int fir_base)
{
	return 0;
}

/*
 * Function smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(self, speed)
 *
2297
 *    Set transceiver
L
Linus Torvalds 已提交
2298 2299 2300 2301 2302
 *
 */

static void smsc_ircc_set_transceiver_smsc_ircc_fast_pin_select(int fir_base, u32 speed)
{
2303
	u8 fast_mode;
2304

2305 2306 2307
	switch (speed) {
	default:
	case 576000 :
2308
		fast_mode = 0;
L
Linus Torvalds 已提交
2309
		break;
2310 2311
	case 1152000 :
	case 4000000 :
L
Linus Torvalds 已提交
2312 2313 2314 2315
		fast_mode = IRCC_LCR_A_FAST;
		break;
	}
	register_bank(fir_base, 0);
2316
	outb((inb(fir_base + IRCC_LCR_A) & 0xbf) | fast_mode, fir_base + IRCC_LCR_A);
L
Linus Torvalds 已提交
2317 2318 2319 2320 2321
}

/*
 * Function smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(fir_base)
 *
2322
 *    Probe transceiver
L
Linus Torvalds 已提交
2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333
 *
 */

static int smsc_ircc_probe_transceiver_smsc_ircc_fast_pin_select(int fir_base)
{
	return 0;
}

/*
 * Function smsc_ircc_set_transceiver_toshiba_sat1800(fir_base, speed)
 *
2334
 *    Set transceiver
L
Linus Torvalds 已提交
2335 2336 2337 2338 2339
 *
 */

static void smsc_ircc_set_transceiver_toshiba_sat1800(int fir_base, u32 speed)
{
2340
	u8 fast_mode;
2341

2342 2343 2344
	switch (speed) {
	default:
	case 576000 :
2345
		fast_mode = 0;
L
Linus Torvalds 已提交
2346
		break;
2347 2348
	case 1152000 :
	case 4000000 :
L
Linus Torvalds 已提交
2349 2350
		fast_mode = /*IRCC_LCR_A_FAST |*/ IRCC_LCR_A_GP_DATA;
		break;
2351

L
Linus Torvalds 已提交
2352 2353 2354
	}
	/* This causes an interrupt */
	register_bank(fir_base, 0);
2355
	outb((inb(fir_base + IRCC_LCR_A) &  0xbf) | fast_mode, fir_base + IRCC_LCR_A);
L
Linus Torvalds 已提交
2356 2357 2358 2359 2360
}

/*
 * Function smsc_ircc_probe_transceiver_toshiba_sat1800(fir_base)
 *
2361
 *    Probe transceiver
L
Linus Torvalds 已提交
2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372
 *
 */

static int smsc_ircc_probe_transceiver_toshiba_sat1800(int fir_base)
{
	return 0;
}


module_init(smsc_ircc_init);
module_exit(smsc_ircc_cleanup);