icside.c 16.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Copyright (c) 1996-2004 Russell King.
 *
 * Please note that this platform does not support 32-bit IDE IO.
 */

#include <linux/string.h>
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/slab.h>
#include <linux/blkdev.h>
#include <linux/errno.h>
#include <linux/ide.h>
#include <linux/dma-mapping.h>
#include <linux/device.h>
#include <linux/init.h>
#include <linux/scatterlist.h>
18
#include <linux/io.h>
L
Linus Torvalds 已提交
19 20 21 22

#include <asm/dma.h>
#include <asm/ecard.h>

23 24
#define DRV_NAME "icside"

L
Linus Torvalds 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#define ICS_IDENT_OFFSET		0x2280

#define ICS_ARCIN_V5_INTRSTAT		0x0000
#define ICS_ARCIN_V5_INTROFFSET		0x0004
#define ICS_ARCIN_V5_IDEOFFSET		0x2800
#define ICS_ARCIN_V5_IDEALTOFFSET	0x2b80
#define ICS_ARCIN_V5_IDESTEPPING	6

#define ICS_ARCIN_V6_IDEOFFSET_1	0x2000
#define ICS_ARCIN_V6_INTROFFSET_1	0x2200
#define ICS_ARCIN_V6_INTRSTAT_1		0x2290
#define ICS_ARCIN_V6_IDEALTOFFSET_1	0x2380
#define ICS_ARCIN_V6_IDEOFFSET_2	0x3000
#define ICS_ARCIN_V6_INTROFFSET_2	0x3200
#define ICS_ARCIN_V6_INTRSTAT_2		0x3290
#define ICS_ARCIN_V6_IDEALTOFFSET_2	0x3380
#define ICS_ARCIN_V6_IDESTEPPING	6

struct cardinfo {
	unsigned int dataoffset;
	unsigned int ctrloffset;
	unsigned int stepping;
};

static struct cardinfo icside_cardinfo_v5 = {
	.dataoffset	= ICS_ARCIN_V5_IDEOFFSET,
	.ctrloffset	= ICS_ARCIN_V5_IDEALTOFFSET,
	.stepping	= ICS_ARCIN_V5_IDESTEPPING,
};

static struct cardinfo icside_cardinfo_v6_1 = {
	.dataoffset	= ICS_ARCIN_V6_IDEOFFSET_1,
	.ctrloffset	= ICS_ARCIN_V6_IDEALTOFFSET_1,
	.stepping	= ICS_ARCIN_V6_IDESTEPPING,
};

static struct cardinfo icside_cardinfo_v6_2 = {
	.dataoffset	= ICS_ARCIN_V6_IDEOFFSET_2,
	.ctrloffset	= ICS_ARCIN_V6_IDEALTOFFSET_2,
	.stepping	= ICS_ARCIN_V6_IDESTEPPING,
};

struct icside_state {
	unsigned int channel;
	unsigned int enabled;
	void __iomem *irq_port;
	void __iomem *ioc_base;
72
	unsigned int sel;
L
Linus Torvalds 已提交
73
	unsigned int type;
74
	struct ide_host *host;
L
Linus Torvalds 已提交
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
};

#define ICS_TYPE_A3IN	0
#define ICS_TYPE_A3USER	1
#define ICS_TYPE_V6	3
#define ICS_TYPE_V5	15
#define ICS_TYPE_NOTYPE	((unsigned int)-1)

/* ---------------- Version 5 PCB Support Functions --------------------- */
/* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
 * Purpose  : enable interrupts from card
 */
static void icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
{
	struct icside_state *state = ec->irq_data;

	writeb(0, state->irq_port + ICS_ARCIN_V5_INTROFFSET);
}

/* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
 * Purpose  : disable interrupts from card
 */
static void icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
{
	struct icside_state *state = ec->irq_data;

	readb(state->irq_port + ICS_ARCIN_V5_INTROFFSET);
}

static const expansioncard_ops_t icside_ops_arcin_v5 = {
	.irqenable	= icside_irqenable_arcin_v5,
	.irqdisable	= icside_irqdisable_arcin_v5,
};


/* ---------------- Version 6 PCB Support Functions --------------------- */
/* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
 * Purpose  : enable interrupts from card
 */
static void icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
{
	struct icside_state *state = ec->irq_data;
	void __iomem *base = state->irq_port;

	state->enabled = 1;

	switch (state->channel) {
	case 0:
		writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1);
		readb(base + ICS_ARCIN_V6_INTROFFSET_2);
		break;
	case 1:
		writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2);
		readb(base + ICS_ARCIN_V6_INTROFFSET_1);
		break;
	}
}

/* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
 * Purpose  : disable interrupts from card
 */
static void icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
{
	struct icside_state *state = ec->irq_data;

	state->enabled = 0;

	readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
	readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
}

/* Prototype: icside_irqprobe(struct expansion_card *ec)
 * Purpose  : detect an active interrupt from card
 */
static int icside_irqpending_arcin_v6(struct expansion_card *ec)
{
	struct icside_state *state = ec->irq_data;

	return readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 ||
	       readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1;
}

static const expansioncard_ops_t icside_ops_arcin_v6 = {
	.irqenable	= icside_irqenable_arcin_v6,
	.irqdisable	= icside_irqdisable_arcin_v6,
	.irqpending	= icside_irqpending_arcin_v6,
};

/*
 * Handle routing of interrupts.  This is called before
 * we write the command to the drive.
 */
static void icside_maskproc(ide_drive_t *drive, int mask)
{
169
	ide_hwif_t *hwif = drive->hwif;
170 171
	struct expansion_card *ec = ECARD_DEV(hwif->dev);
	struct icside_state *state = ecard_get_drvdata(ec);
L
Linus Torvalds 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
	unsigned long flags;

	local_irq_save(flags);

	state->channel = hwif->channel;

	if (state->enabled && !mask) {
		switch (hwif->channel) {
		case 0:
			writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
			readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
			break;
		case 1:
			writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
			readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
			break;
		}
	} else {
		readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
		readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
	}

	local_irq_restore(flags);
}

197 198 199 200
static const struct ide_port_ops icside_v6_no_dma_port_ops = {
	.maskproc		= icside_maskproc,
};

L
Linus Torvalds 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
#ifdef CONFIG_BLK_DEV_IDEDMA_ICS
/*
 * SG-DMA support.
 *
 * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers.
 * There is only one DMA controller per card, which means that only
 * one drive can be accessed at one time.  NOTE! We do not enforce that
 * here, but we rely on the main IDE driver spotting that both
 * interfaces use the same IRQ, which should guarantee this.
 */

/*
 * Configure the IOMD to give the appropriate timings for the transfer
 * mode being requested.  We take the advice of the ATA standards, and
 * calculate the cycle time based on the transfer mode, and the EIDE
 * MW DMA specs that the drive provides in the IDENTIFY command.
 *
 * We have the following IOMD DMA modes to choose from:
 *
 *	Type	Active		Recovery	Cycle
 *	A	250 (250)	312 (550)	562 (800)
 *	B	187		250		437
 *	C	125 (125)	125 (375)	250 (500)
 *	D	62		125		187
 *
 * (figures in brackets are actual measured timings)
 *
 * However, we also need to take care of the read/write active and
 * recovery timings:
 *
 *			Read	Write
 *  	Mode	Active	-- Recovery --	Cycle	IOMD type
 *	MW0	215	50	215	480	A
 *	MW1	80	50	50	150	C
 *	MW2	70	25	25	120	C
 */
237
static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
L
Linus Torvalds 已提交
238
{
239
	int cycle_time, use_dma_info = 0;
L
Linus Torvalds 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266

	switch (xfer_mode) {
	case XFER_MW_DMA_2:
		cycle_time = 250;
		use_dma_info = 1;
		break;

	case XFER_MW_DMA_1:
		cycle_time = 250;
		use_dma_info = 1;
		break;

	case XFER_MW_DMA_0:
		cycle_time = 480;
		break;

	case XFER_SW_DMA_2:
	case XFER_SW_DMA_1:
	case XFER_SW_DMA_0:
		cycle_time = 480;
		break;
	}

	/*
	 * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
	 * take care to note the values in the ID...
	 */
267 268
	if (use_dma_info && drive->id[ATA_ID_EIDE_DMA_TIME] > cycle_time)
		cycle_time = drive->id[ATA_ID_EIDE_DMA_TIME];
L
Linus Torvalds 已提交
269 270 271 272 273 274 275

	drive->drive_data = cycle_time;

	printk("%s: %s selected (peak %dMB/s)\n", drive->name,
		ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data);
}

276 277 278 279 280
static const struct ide_port_ops icside_v6_port_ops = {
	.set_dma_mode		= icside_set_dma_mode,
	.maskproc		= icside_maskproc,
};

281
static void icside_dma_host_set(ide_drive_t *drive, int on)
L
Linus Torvalds 已提交
282 283 284 285 286
{
}

static int icside_dma_end(ide_drive_t *drive)
{
287
	ide_hwif_t *hwif = drive->hwif;
288
	struct expansion_card *ec = ECARD_DEV(hwif->dev);
L
Linus Torvalds 已提交
289 290 291

	drive->waiting_for_dma = 0;

292
	disable_dma(ec->dma);
L
Linus Torvalds 已提交
293 294

	/* Teardown mappings after DMA has completed. */
295
	ide_destroy_dmatable(drive);
L
Linus Torvalds 已提交
296

297
	return get_dma_residue(ec->dma) != 0;
L
Linus Torvalds 已提交
298 299 300 301
}

static void icside_dma_start(ide_drive_t *drive)
{
302
	ide_hwif_t *hwif = drive->hwif;
303
	struct expansion_card *ec = ECARD_DEV(hwif->dev);
L
Linus Torvalds 已提交
304 305

	/* We can not enable DMA on both channels simultaneously. */
306 307
	BUG_ON(dma_channel_active(ec->dma));
	enable_dma(ec->dma);
L
Linus Torvalds 已提交
308 309 310 311
}

static int icside_dma_setup(ide_drive_t *drive)
{
312
	ide_hwif_t *hwif = drive->hwif;
313
	struct expansion_card *ec = ECARD_DEV(hwif->dev);
314
	struct icside_state *state = ecard_get_drvdata(ec);
315
	struct request *rq = hwif->rq;
L
Linus Torvalds 已提交
316 317 318 319 320 321 322 323 324 325
	unsigned int dma_mode;

	if (rq_data_dir(rq))
		dma_mode = DMA_MODE_WRITE;
	else
		dma_mode = DMA_MODE_READ;

	/*
	 * We can not enable DMA on both channels.
	 */
326
	BUG_ON(dma_channel_active(ec->dma));
L
Linus Torvalds 已提交
327

328
	hwif->sg_nents = ide_build_sglist(drive, rq);
L
Linus Torvalds 已提交
329 330 331 332 333 334 335 336 337

	/*
	 * Ensure that we have the right interrupt routed.
	 */
	icside_maskproc(drive, 0);

	/*
	 * Route the DMA signals to the correct interface.
	 */
338
	writeb(state->sel | hwif->channel, state->ioc_base);
L
Linus Torvalds 已提交
339 340 341 342

	/*
	 * Select the correct timing for this drive.
	 */
343
	set_dma_speed(ec->dma, drive->drive_data);
L
Linus Torvalds 已提交
344 345 346 347 348

	/*
	 * Tell the DMA engine about the SG table and
	 * data direction.
	 */
349 350
	set_dma_sg(ec->dma, hwif->sg_table, hwif->sg_nents);
	set_dma_mode(ec->dma, dma_mode);
L
Linus Torvalds 已提交
351 352 353 354 355 356 357 358 359 360 361 362 363 364

	drive->waiting_for_dma = 1;

	return 0;
}

static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
{
	/* issue cmd to drive */
	ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL);
}

static int icside_dma_test_irq(ide_drive_t *drive)
{
365
	ide_hwif_t *hwif = drive->hwif;
366 367
	struct expansion_card *ec = ECARD_DEV(hwif->dev);
	struct icside_state *state = ecard_get_drvdata(ec);
L
Linus Torvalds 已提交
368 369 370 371 372 373 374

	return readb(state->irq_port +
		     (hwif->channel ?
			ICS_ARCIN_V6_INTRSTAT_2 :
			ICS_ARCIN_V6_INTRSTAT_1)) & 1;
}

375
static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
L
Linus Torvalds 已提交
376 377 378 379
{
	hwif->dmatable_cpu	= NULL;
	hwif->dmatable_dma	= 0;

380
	return 0;
L
Linus Torvalds 已提交
381
}
382

383
static const struct ide_dma_ops icside_v6_dma_ops = {
384 385 386 387 388 389
	.dma_host_set		= icside_dma_host_set,
	.dma_setup		= icside_dma_setup,
	.dma_exec_cmd		= icside_dma_exec_cmd,
	.dma_start		= icside_dma_start,
	.dma_end		= icside_dma_end,
	.dma_test_irq		= icside_dma_test_irq,
390
	.dma_timeout		= ide_dma_timeout,
391
	.dma_lost_irq		= ide_dma_lost_irq,
392 393 394
};
#else
#define icside_v6_dma_ops NULL
L
Linus Torvalds 已提交
395 396
#endif

397 398 399 400 401
static int icside_dma_off_init(ide_hwif_t *hwif, const struct ide_port_info *d)
{
	return -EOPNOTSUPP;
}

402 403
static void icside_setup_ports(hw_regs_t *hw, void __iomem *base,
			       struct cardinfo *info, struct expansion_card *ec)
L
Linus Torvalds 已提交
404 405 406
{
	unsigned long port = (unsigned long)base + info->dataoffset;

407 408 409 410 411 412 413 414 415 416 417 418 419
	hw->io_ports.data_addr	 = port;
	hw->io_ports.error_addr	 = port + (1 << info->stepping);
	hw->io_ports.nsect_addr	 = port + (2 << info->stepping);
	hw->io_ports.lbal_addr	 = port + (3 << info->stepping);
	hw->io_ports.lbam_addr	 = port + (4 << info->stepping);
	hw->io_ports.lbah_addr	 = port + (5 << info->stepping);
	hw->io_ports.device_addr = port + (6 << info->stepping);
	hw->io_ports.status_addr = port + (7 << info->stepping);
	hw->io_ports.ctl_addr	 = (unsigned long)base + info->ctrloffset;

	hw->irq = ec->irq;
	hw->dev = &ec->dev;
	hw->chipset = ide_acorn;
L
Linus Torvalds 已提交
420 421
}

422 423 424 425
static const struct ide_port_info icside_v5_port_info = {
	.host_flags		= IDE_HFLAG_NO_DMA,
};

A
Al Viro 已提交
426
static int __devinit
L
Linus Torvalds 已提交
427 428 429
icside_register_v5(struct icside_state *state, struct expansion_card *ec)
{
	void __iomem *base;
430
	struct ide_host *host;
431
	hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
432
	int ret;
L
Linus Torvalds 已提交
433

434
	base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
L
Linus Torvalds 已提交
435 436 437 438 439 440 441
	if (!base)
		return -ENOMEM;

	state->irq_port = base;

	ec->irqaddr  = base + ICS_ARCIN_V5_INTRSTAT;
	ec->irqmask  = 1;
442 443

	ecard_setirq(ec, &icside_ops_arcin_v5, state);
L
Linus Torvalds 已提交
444 445 446 447 448 449

	/*
	 * Be on the safe side - disable interrupts
	 */
	icside_irqdisable_arcin_v5(ec, 0);

450 451
	icside_setup_ports(&hw, base, &icside_cardinfo_v5, ec);

452
	host = ide_host_alloc(&icside_v5_port_info, hws);
453
	if (host == NULL)
L
Linus Torvalds 已提交
454 455
		return -ENODEV;

456
	state->host = host;
L
Linus Torvalds 已提交
457

458 459
	ecard_set_drvdata(ec, state);

460
	ret = ide_host_register(host, &icside_v5_port_info, hws);
461 462
	if (ret)
		goto err_free;
L
Linus Torvalds 已提交
463 464

	return 0;
465 466 467 468
err_free:
	ide_host_free(host);
	ecard_set_drvdata(ec, NULL);
	return ret;
L
Linus Torvalds 已提交
469 470
}

471
static const struct ide_port_info icside_v6_port_info __initdata = {
472
	.init_dma		= icside_dma_off_init,
473
	.port_ops		= &icside_v6_no_dma_port_ops,
474
	.dma_ops		= &icside_v6_dma_ops,
475
	.host_flags		= IDE_HFLAG_SERIALIZE | IDE_HFLAG_MMIO,
476 477 478 479
	.mwdma_mask		= ATA_MWDMA2,
	.swdma_mask		= ATA_SWDMA2,
};

A
Al Viro 已提交
480
static int __devinit
L
Linus Torvalds 已提交
481 482 483
icside_register_v6(struct icside_state *state, struct expansion_card *ec)
{
	void __iomem *ioc_base, *easi_base;
484
	struct ide_host *host;
L
Linus Torvalds 已提交
485 486
	unsigned int sel = 0;
	int ret;
487
	hw_regs_t hw[2], *hws[] = { &hw[0], NULL, NULL, NULL };
488
	struct ide_port_info d = icside_v6_port_info;
L
Linus Torvalds 已提交
489

490
	ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
L
Linus Torvalds 已提交
491 492 493 494 495 496 497 498
	if (!ioc_base) {
		ret = -ENOMEM;
		goto out;
	}

	easi_base = ioc_base;

	if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
499
		easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0);
L
Linus Torvalds 已提交
500 501
		if (!easi_base) {
			ret = -ENOMEM;
502
			goto out;
L
Linus Torvalds 已提交
503 504 505 506 507 508 509 510 511 512
		}

		/*
		 * Enable access to the EASI region.
		 */
		sel = 1 << 5;
	}

	writeb(sel, ioc_base);

513
	ecard_setirq(ec, &icside_ops_arcin_v6, state);
L
Linus Torvalds 已提交
514 515 516

	state->irq_port   = easi_base;
	state->ioc_base   = ioc_base;
517
	state->sel	  = sel;
L
Linus Torvalds 已提交
518 519 520 521 522 523

	/*
	 * Be on the safe side - disable interrupts
	 */
	icside_irqdisable_arcin_v6(ec, 0);

524 525 526
	icside_setup_ports(&hw[0], easi_base, &icside_cardinfo_v6_1, ec);
	icside_setup_ports(&hw[1], easi_base, &icside_cardinfo_v6_2, ec);

527 528
	host = ide_host_alloc(&d, hws);
	if (host == NULL)
529
		return -ENODEV;
L
Linus Torvalds 已提交
530

531
	state->host = host;
L
Linus Torvalds 已提交
532

533
	ecard_set_drvdata(ec, state);
L
Linus Torvalds 已提交
534

535
	if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) {
536
		d.init_dma = icside_dma_init;
A
Al Viro 已提交
537
		d.port_ops = &icside_v6_port_ops;
538
		d.dma_ops = NULL;
539
	}
L
Linus Torvalds 已提交
540

541
	ret = ide_host_register(host, &d, hws);
542 543
	if (ret)
		goto err_free;
L
Linus Torvalds 已提交
544 545

	return 0;
546 547 548 549 550 551
err_free:
	ide_host_free(host);
	if (d.dma_ops)
		free_dma(ec->dma);
	ecard_set_drvdata(ec, NULL);
out:
L
Linus Torvalds 已提交
552 553 554 555 556 557 558 559 560 561 562 563 564 565
	return ret;
}

static int __devinit
icside_probe(struct expansion_card *ec, const struct ecard_id *id)
{
	struct icside_state *state;
	void __iomem *idmem;
	int ret;

	ret = ecard_request_resources(ec);
	if (ret)
		goto out;

566
	state = kzalloc(sizeof(struct icside_state), GFP_KERNEL);
L
Linus Torvalds 已提交
567 568 569 570 571 572 573
	if (!state) {
		ret = -ENOMEM;
		goto release;
	}

	state->type	= ICS_TYPE_NOTYPE;

574
	idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
L
Linus Torvalds 已提交
575 576 577 578 579 580 581
	if (idmem) {
		unsigned int type;

		type = readb(idmem + ICS_IDENT_OFFSET) & 1;
		type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
		type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
		type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
582
		ecardm_iounmap(ec, idmem);
L
Linus Torvalds 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611

		state->type = type;
	}

	switch (state->type) {
	case ICS_TYPE_A3IN:
		dev_warn(&ec->dev, "A3IN unsupported\n");
		ret = -ENODEV;
		break;

	case ICS_TYPE_A3USER:
		dev_warn(&ec->dev, "A3USER unsupported\n");
		ret = -ENODEV;
		break;

	case ICS_TYPE_V5:
		ret = icside_register_v5(state, ec);
		break;

	case ICS_TYPE_V6:
		ret = icside_register_v6(state, ec);
		break;

	default:
		dev_warn(&ec->dev, "unknown interface type\n");
		ret = -ENODEV;
		break;
	}

612
	if (ret == 0)
L
Linus Torvalds 已提交
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696
		goto out;

	kfree(state);
 release:
	ecard_release_resources(ec);
 out:
	return ret;
}

static void __devexit icside_remove(struct expansion_card *ec)
{
	struct icside_state *state = ecard_get_drvdata(ec);

	switch (state->type) {
	case ICS_TYPE_V5:
		/* FIXME: tell IDE to stop using the interface */

		/* Disable interrupts */
		icside_irqdisable_arcin_v5(ec, 0);
		break;

	case ICS_TYPE_V6:
		/* FIXME: tell IDE to stop using the interface */
		if (ec->dma != NO_DMA)
			free_dma(ec->dma);

		/* Disable interrupts */
		icside_irqdisable_arcin_v6(ec, 0);

		/* Reset the ROM pointer/EASI selection */
		writeb(0, state->ioc_base);
		break;
	}

	ecard_set_drvdata(ec, NULL);

	kfree(state);
	ecard_release_resources(ec);
}

static void icside_shutdown(struct expansion_card *ec)
{
	struct icside_state *state = ecard_get_drvdata(ec);
	unsigned long flags;

	/*
	 * Disable interrupts from this card.  We need to do
	 * this before disabling EASI since we may be accessing
	 * this register via that region.
	 */
	local_irq_save(flags);
	ec->ops->irqdisable(ec, 0);
	local_irq_restore(flags);

	/*
	 * Reset the ROM pointer so that we can read the ROM
	 * after a soft reboot.  This also disables access to
	 * the IDE taskfile via the EASI region.
	 */
	if (state->ioc_base)
		writeb(0, state->ioc_base);
}

static const struct ecard_id icside_ids[] = {
	{ MANU_ICS,  PROD_ICS_IDE  },
	{ MANU_ICS2, PROD_ICS2_IDE },
	{ 0xffff, 0xffff }
};

static struct ecard_driver icside_driver = {
	.probe		= icside_probe,
	.remove		= __devexit_p(icside_remove),
	.shutdown	= icside_shutdown,
	.id_table	= icside_ids,
	.drv = {
		.name	= "icside",
	},
};

static int __init icside_init(void)
{
	return ecard_register_driver(&icside_driver);
}

A
Al Viro 已提交
697
static void __exit icside_exit(void)
698
{
A
Al Viro 已提交
699
	ecard_remove_driver(&icside_driver);
700 701
}

L
Linus Torvalds 已提交
702 703 704 705 706
MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("ICS IDE driver");

module_init(icside_init);
707
module_exit(icside_exit);