blob: 12cbb5d07f61daf4d7d0e2db2973ab52d87a5556 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/ide/arm/icside.c
3 *
4 * Copyright (c) 1996-2004 Russell King.
5 *
6 * Please note that this platform does not support 32-bit IDE IO.
7 */
8
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <linux/string.h>
10#include <linux/module.h>
11#include <linux/ioport.h>
12#include <linux/slab.h>
13#include <linux/blkdev.h>
14#include <linux/errno.h>
15#include <linux/hdreg.h>
16#include <linux/ide.h>
17#include <linux/dma-mapping.h>
18#include <linux/device.h>
19#include <linux/init.h>
20#include <linux/scatterlist.h>
Al Viroba5b55d2007-07-15 21:01:32 +010021#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23#include <asm/dma.h>
24#include <asm/ecard.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26#define ICS_IDENT_OFFSET 0x2280
27
28#define ICS_ARCIN_V5_INTRSTAT 0x0000
29#define ICS_ARCIN_V5_INTROFFSET 0x0004
30#define ICS_ARCIN_V5_IDEOFFSET 0x2800
31#define ICS_ARCIN_V5_IDEALTOFFSET 0x2b80
32#define ICS_ARCIN_V5_IDESTEPPING 6
33
34#define ICS_ARCIN_V6_IDEOFFSET_1 0x2000
35#define ICS_ARCIN_V6_INTROFFSET_1 0x2200
36#define ICS_ARCIN_V6_INTRSTAT_1 0x2290
37#define ICS_ARCIN_V6_IDEALTOFFSET_1 0x2380
38#define ICS_ARCIN_V6_IDEOFFSET_2 0x3000
39#define ICS_ARCIN_V6_INTROFFSET_2 0x3200
40#define ICS_ARCIN_V6_INTRSTAT_2 0x3290
41#define ICS_ARCIN_V6_IDEALTOFFSET_2 0x3380
42#define ICS_ARCIN_V6_IDESTEPPING 6
43
44struct cardinfo {
45 unsigned int dataoffset;
46 unsigned int ctrloffset;
47 unsigned int stepping;
48};
49
50static struct cardinfo icside_cardinfo_v5 = {
51 .dataoffset = ICS_ARCIN_V5_IDEOFFSET,
52 .ctrloffset = ICS_ARCIN_V5_IDEALTOFFSET,
53 .stepping = ICS_ARCIN_V5_IDESTEPPING,
54};
55
56static struct cardinfo icside_cardinfo_v6_1 = {
57 .dataoffset = ICS_ARCIN_V6_IDEOFFSET_1,
58 .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_1,
59 .stepping = ICS_ARCIN_V6_IDESTEPPING,
60};
61
62static struct cardinfo icside_cardinfo_v6_2 = {
63 .dataoffset = ICS_ARCIN_V6_IDEOFFSET_2,
64 .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_2,
65 .stepping = ICS_ARCIN_V6_IDESTEPPING,
66};
67
68struct icside_state {
69 unsigned int channel;
70 unsigned int enabled;
71 void __iomem *irq_port;
72 void __iomem *ioc_base;
73 unsigned int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 ide_hwif_t *hwif[2];
75};
76
77#define ICS_TYPE_A3IN 0
78#define ICS_TYPE_A3USER 1
79#define ICS_TYPE_V6 3
80#define ICS_TYPE_V5 15
81#define ICS_TYPE_NOTYPE ((unsigned int)-1)
82
83/* ---------------- Version 5 PCB Support Functions --------------------- */
84/* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
85 * Purpose : enable interrupts from card
86 */
87static void icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
88{
89 struct icside_state *state = ec->irq_data;
90
91 writeb(0, state->irq_port + ICS_ARCIN_V5_INTROFFSET);
92}
93
94/* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
95 * Purpose : disable interrupts from card
96 */
97static void icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
98{
99 struct icside_state *state = ec->irq_data;
100
101 readb(state->irq_port + ICS_ARCIN_V5_INTROFFSET);
102}
103
104static const expansioncard_ops_t icside_ops_arcin_v5 = {
105 .irqenable = icside_irqenable_arcin_v5,
106 .irqdisable = icside_irqdisable_arcin_v5,
107};
108
109
110/* ---------------- Version 6 PCB Support Functions --------------------- */
111/* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
112 * Purpose : enable interrupts from card
113 */
114static void icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
115{
116 struct icside_state *state = ec->irq_data;
117 void __iomem *base = state->irq_port;
118
119 state->enabled = 1;
120
121 switch (state->channel) {
122 case 0:
123 writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1);
124 readb(base + ICS_ARCIN_V6_INTROFFSET_2);
125 break;
126 case 1:
127 writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2);
128 readb(base + ICS_ARCIN_V6_INTROFFSET_1);
129 break;
130 }
131}
132
133/* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
134 * Purpose : disable interrupts from card
135 */
136static void icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
137{
138 struct icside_state *state = ec->irq_data;
139
140 state->enabled = 0;
141
142 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
143 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
144}
145
146/* Prototype: icside_irqprobe(struct expansion_card *ec)
147 * Purpose : detect an active interrupt from card
148 */
149static int icside_irqpending_arcin_v6(struct expansion_card *ec)
150{
151 struct icside_state *state = ec->irq_data;
152
153 return readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 ||
154 readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1;
155}
156
157static const expansioncard_ops_t icside_ops_arcin_v6 = {
158 .irqenable = icside_irqenable_arcin_v6,
159 .irqdisable = icside_irqdisable_arcin_v6,
160 .irqpending = icside_irqpending_arcin_v6,
161};
162
163/*
164 * Handle routing of interrupts. This is called before
165 * we write the command to the drive.
166 */
167static void icside_maskproc(ide_drive_t *drive, int mask)
168{
169 ide_hwif_t *hwif = HWIF(drive);
170 struct icside_state *state = hwif->hwif_data;
171 unsigned long flags;
172
173 local_irq_save(flags);
174
175 state->channel = hwif->channel;
176
177 if (state->enabled && !mask) {
178 switch (hwif->channel) {
179 case 0:
180 writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
181 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
182 break;
183 case 1:
184 writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
185 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
186 break;
187 }
188 } else {
189 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
190 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
191 }
192
193 local_irq_restore(flags);
194}
195
196#ifdef CONFIG_BLK_DEV_IDEDMA_ICS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/*
198 * SG-DMA support.
199 *
200 * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers.
201 * There is only one DMA controller per card, which means that only
202 * one drive can be accessed at one time. NOTE! We do not enforce that
203 * here, but we rely on the main IDE driver spotting that both
204 * interfaces use the same IRQ, which should guarantee this.
205 */
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207/*
208 * Configure the IOMD to give the appropriate timings for the transfer
209 * mode being requested. We take the advice of the ATA standards, and
210 * calculate the cycle time based on the transfer mode, and the EIDE
211 * MW DMA specs that the drive provides in the IDENTIFY command.
212 *
213 * We have the following IOMD DMA modes to choose from:
214 *
215 * Type Active Recovery Cycle
216 * A 250 (250) 312 (550) 562 (800)
217 * B 187 250 437
218 * C 125 (125) 125 (375) 250 (500)
219 * D 62 125 187
220 *
221 * (figures in brackets are actual measured timings)
222 *
223 * However, we also need to take care of the read/write active and
224 * recovery timings:
225 *
226 * Read Write
227 * Mode Active -- Recovery -- Cycle IOMD type
228 * MW0 215 50 215 480 A
229 * MW1 80 50 50 150 C
230 * MW2 70 25 25 120 C
231 */
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200232static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233{
Bartlomiej Zolnierkiewiczf44ae582007-10-11 23:54:00 +0200234 int cycle_time, use_dma_info = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 switch (xfer_mode) {
237 case XFER_MW_DMA_2:
238 cycle_time = 250;
239 use_dma_info = 1;
240 break;
241
242 case XFER_MW_DMA_1:
243 cycle_time = 250;
244 use_dma_info = 1;
245 break;
246
247 case XFER_MW_DMA_0:
248 cycle_time = 480;
249 break;
250
251 case XFER_SW_DMA_2:
252 case XFER_SW_DMA_1:
253 case XFER_SW_DMA_0:
254 cycle_time = 480;
255 break;
256 }
257
258 /*
259 * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
260 * take care to note the values in the ID...
261 */
262 if (use_dma_info && drive->id->eide_dma_time > cycle_time)
263 cycle_time = drive->id->eide_dma_time;
264
265 drive->drive_data = cycle_time;
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 printk("%s: %s selected (peak %dMB/s)\n", drive->name,
268 ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269}
270
Bartlomiej Zolnierkiewicz15ce9262008-01-26 20:13:03 +0100271static void icside_dma_host_set(ide_drive_t *drive, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275static int icside_dma_end(ide_drive_t *drive)
276{
277 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100278 struct expansion_card *ec = ECARD_DEV(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
280 drive->waiting_for_dma = 0;
281
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100282 disable_dma(ec->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
284 /* Teardown mappings after DMA has completed. */
Bartlomiej Zolnierkiewicz062f9f02008-02-01 23:09:32 +0100285 ide_destroy_dmatable(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100287 return get_dma_residue(ec->dma) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288}
289
290static void icside_dma_start(ide_drive_t *drive)
291{
292 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100293 struct expansion_card *ec = ECARD_DEV(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
295 /* We can not enable DMA on both channels simultaneously. */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100296 BUG_ON(dma_channel_active(ec->dma));
297 enable_dma(ec->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298}
299
300static int icside_dma_setup(ide_drive_t *drive)
301{
302 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100303 struct expansion_card *ec = ECARD_DEV(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 struct request *rq = hwif->hwgroup->rq;
305 unsigned int dma_mode;
306
307 if (rq_data_dir(rq))
308 dma_mode = DMA_MODE_WRITE;
309 else
310 dma_mode = DMA_MODE_READ;
311
312 /*
313 * We can not enable DMA on both channels.
314 */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100315 BUG_ON(dma_channel_active(ec->dma));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
Bartlomiej Zolnierkiewicz062f9f02008-02-01 23:09:32 +0100317 hwif->sg_nents = ide_build_sglist(drive, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319 /*
320 * Ensure that we have the right interrupt routed.
321 */
322 icside_maskproc(drive, 0);
323
324 /*
325 * Route the DMA signals to the correct interface.
326 */
327 writeb(hwif->select_data, hwif->config_data);
328
329 /*
330 * Select the correct timing for this drive.
331 */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100332 set_dma_speed(ec->dma, drive->drive_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334 /*
335 * Tell the DMA engine about the SG table and
336 * data direction.
337 */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100338 set_dma_sg(ec->dma, hwif->sg_table, hwif->sg_nents);
339 set_dma_mode(ec->dma, dma_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 drive->waiting_for_dma = 1;
342
343 return 0;
344}
345
346static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
347{
348 /* issue cmd to drive */
349 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL);
350}
351
352static int icside_dma_test_irq(ide_drive_t *drive)
353{
354 ide_hwif_t *hwif = HWIF(drive);
355 struct icside_state *state = hwif->hwif_data;
356
357 return readb(state->irq_port +
358 (hwif->channel ?
359 ICS_ARCIN_V6_INTRSTAT_2 :
360 ICS_ARCIN_V6_INTRSTAT_1)) & 1;
361}
362
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200363static void icside_dma_timeout(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
366
367 if (icside_dma_test_irq(drive))
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200368 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200370 ide_dump_status(drive, "DMA timeout", HWIF(drive)->INB(IDE_STATUS_REG));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200372 icside_dma_end(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Sergei Shtylyov841d2a92007-07-09 23:17:54 +0200375static void icside_dma_lost_irq(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
377 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
380static void icside_dma_init(ide_hwif_t *hwif)
381{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 hwif->mwdma_mask = 7; /* MW0..2 */
383 hwif->swdma_mask = 7; /* SW0..2 */
384
385 hwif->dmatable_cpu = NULL;
386 hwif->dmatable_dma = 0;
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200387 hwif->set_dma_mode = icside_set_dma_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Bartlomiej Zolnierkiewicz15ce9262008-01-26 20:13:03 +0100389 hwif->dma_host_set = icside_dma_host_set;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 hwif->dma_setup = icside_dma_setup;
391 hwif->dma_exec_cmd = icside_dma_exec_cmd;
392 hwif->dma_start = icside_dma_start;
393 hwif->ide_dma_end = icside_dma_end;
394 hwif->ide_dma_test_irq = icside_dma_test_irq;
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200395 hwif->dma_timeout = icside_dma_timeout;
Sergei Shtylyov841d2a92007-07-09 23:17:54 +0200396 hwif->dma_lost_irq = icside_dma_lost_irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
398#else
399#define icside_dma_init(hwif) (0)
400#endif
401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402static ide_hwif_t *
403icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *ec)
404{
405 unsigned long port = (unsigned long)base + info->dataoffset;
406 ide_hwif_t *hwif;
407
Bartlomiej Zolnierkiewiczbaa8f3e2007-10-20 00:32:31 +0200408 hwif = ide_find_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 if (hwif) {
410 int i;
411
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 /*
413 * Ensure we're using MMIO
414 */
415 default_hwif_mmiops(hwif);
Bartlomiej Zolnierkiewicz2ad1e552007-02-17 02:40:25 +0100416 hwif->mmio = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
418 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 hwif->io_ports[i] = port;
420 port += 1 << info->stepping;
421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)base + info->ctrloffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 hwif->irq = ec->irq;
424 hwif->noprobe = 0;
425 hwif->chipset = ide_acorn;
426 hwif->gendev.parent = &ec->dev;
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100427 hwif->dev = &ec->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 }
429
430 return hwif;
431}
432
433static int __init
434icside_register_v5(struct icside_state *state, struct expansion_card *ec)
435{
436 ide_hwif_t *hwif;
437 void __iomem *base;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200438 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Russell King10bdaaa2007-05-10 18:40:51 +0100440 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 if (!base)
442 return -ENOMEM;
443
444 state->irq_port = base;
445
446 ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT;
447 ec->irqmask = 1;
Russell Kingc7b87f32007-05-10 16:46:13 +0100448
449 ecard_setirq(ec, &icside_ops_arcin_v5, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451 /*
452 * Be on the safe side - disable interrupts
453 */
454 icside_irqdisable_arcin_v5(ec, 0);
455
456 hwif = icside_setup(base, &icside_cardinfo_v5, ec);
Russell King10bdaaa2007-05-10 18:40:51 +0100457 if (!hwif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 state->hwif[0] = hwif;
461
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200462 idx[0] = hwif->index;
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200463
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200464 ide_device_add(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
466 return 0;
467}
468
469static int __init
470icside_register_v6(struct icside_state *state, struct expansion_card *ec)
471{
472 ide_hwif_t *hwif, *mate;
473 void __iomem *ioc_base, *easi_base;
474 unsigned int sel = 0;
475 int ret;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200476 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477
Russell King10bdaaa2007-05-10 18:40:51 +0100478 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 if (!ioc_base) {
480 ret = -ENOMEM;
481 goto out;
482 }
483
484 easi_base = ioc_base;
485
486 if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
Russell King10bdaaa2007-05-10 18:40:51 +0100487 easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 if (!easi_base) {
489 ret = -ENOMEM;
Russell King10bdaaa2007-05-10 18:40:51 +0100490 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
493 /*
494 * Enable access to the EASI region.
495 */
496 sel = 1 << 5;
497 }
498
499 writeb(sel, ioc_base);
500
Russell Kingc7b87f32007-05-10 16:46:13 +0100501 ecard_setirq(ec, &icside_ops_arcin_v6, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
503 state->irq_port = easi_base;
504 state->ioc_base = ioc_base;
505
506 /*
507 * Be on the safe side - disable interrupts
508 */
509 icside_irqdisable_arcin_v6(ec, 0);
510
511 /*
512 * Find and register the interfaces.
513 */
514 hwif = icside_setup(easi_base, &icside_cardinfo_v6_1, ec);
515 mate = icside_setup(easi_base, &icside_cardinfo_v6_2, ec);
516
517 if (!hwif || !mate) {
518 ret = -ENODEV;
Russell King10bdaaa2007-05-10 18:40:51 +0100519 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521
522 state->hwif[0] = hwif;
523 state->hwif[1] = mate;
524
525 hwif->maskproc = icside_maskproc;
526 hwif->channel = 0;
527 hwif->hwif_data = state;
528 hwif->mate = mate;
529 hwif->serialized = 1;
530 hwif->config_data = (unsigned long)ioc_base;
531 hwif->select_data = sel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 mate->maskproc = icside_maskproc;
534 mate->channel = 1;
535 mate->hwif_data = state;
536 mate->mate = hwif;
537 mate->serialized = 1;
538 mate->config_data = (unsigned long)ioc_base;
539 mate->select_data = sel | 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541 if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) {
542 icside_dma_init(hwif);
543 icside_dma_init(mate);
544 }
545
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200546 idx[0] = hwif->index;
547 idx[1] = mate->index;
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200548
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200549 ide_device_add(idx);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 return 0;
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 out:
554 return ret;
555}
556
557static int __devinit
558icside_probe(struct expansion_card *ec, const struct ecard_id *id)
559{
560 struct icside_state *state;
561 void __iomem *idmem;
562 int ret;
563
564 ret = ecard_request_resources(ec);
565 if (ret)
566 goto out;
567
Mariusz Kozlowskicc60d8b2007-08-01 23:46:44 +0200568 state = kzalloc(sizeof(struct icside_state), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (!state) {
570 ret = -ENOMEM;
571 goto release;
572 }
573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 state->type = ICS_TYPE_NOTYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Russell King10bdaaa2007-05-10 18:40:51 +0100576 idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 if (idmem) {
578 unsigned int type;
579
580 type = readb(idmem + ICS_IDENT_OFFSET) & 1;
581 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
582 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
583 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
Russell King10bdaaa2007-05-10 18:40:51 +0100584 ecardm_iounmap(ec, idmem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
586 state->type = type;
587 }
588
589 switch (state->type) {
590 case ICS_TYPE_A3IN:
591 dev_warn(&ec->dev, "A3IN unsupported\n");
592 ret = -ENODEV;
593 break;
594
595 case ICS_TYPE_A3USER:
596 dev_warn(&ec->dev, "A3USER unsupported\n");
597 ret = -ENODEV;
598 break;
599
600 case ICS_TYPE_V5:
601 ret = icside_register_v5(state, ec);
602 break;
603
604 case ICS_TYPE_V6:
605 ret = icside_register_v6(state, ec);
606 break;
607
608 default:
609 dev_warn(&ec->dev, "unknown interface type\n");
610 ret = -ENODEV;
611 break;
612 }
613
614 if (ret == 0) {
615 ecard_set_drvdata(ec, state);
616 goto out;
617 }
618
619 kfree(state);
620 release:
621 ecard_release_resources(ec);
622 out:
623 return ret;
624}
625
626static void __devexit icside_remove(struct expansion_card *ec)
627{
628 struct icside_state *state = ecard_get_drvdata(ec);
629
630 switch (state->type) {
631 case ICS_TYPE_V5:
632 /* FIXME: tell IDE to stop using the interface */
633
634 /* Disable interrupts */
635 icside_irqdisable_arcin_v5(ec, 0);
636 break;
637
638 case ICS_TYPE_V6:
639 /* FIXME: tell IDE to stop using the interface */
640 if (ec->dma != NO_DMA)
641 free_dma(ec->dma);
642
643 /* Disable interrupts */
644 icside_irqdisable_arcin_v6(ec, 0);
645
646 /* Reset the ROM pointer/EASI selection */
647 writeb(0, state->ioc_base);
648 break;
649 }
650
651 ecard_set_drvdata(ec, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 kfree(state);
654 ecard_release_resources(ec);
655}
656
657static void icside_shutdown(struct expansion_card *ec)
658{
659 struct icside_state *state = ecard_get_drvdata(ec);
660 unsigned long flags;
661
662 /*
663 * Disable interrupts from this card. We need to do
664 * this before disabling EASI since we may be accessing
665 * this register via that region.
666 */
667 local_irq_save(flags);
668 ec->ops->irqdisable(ec, 0);
669 local_irq_restore(flags);
670
671 /*
672 * Reset the ROM pointer so that we can read the ROM
673 * after a soft reboot. This also disables access to
674 * the IDE taskfile via the EASI region.
675 */
676 if (state->ioc_base)
677 writeb(0, state->ioc_base);
678}
679
680static const struct ecard_id icside_ids[] = {
681 { MANU_ICS, PROD_ICS_IDE },
682 { MANU_ICS2, PROD_ICS2_IDE },
683 { 0xffff, 0xffff }
684};
685
686static struct ecard_driver icside_driver = {
687 .probe = icside_probe,
688 .remove = __devexit_p(icside_remove),
689 .shutdown = icside_shutdown,
690 .id_table = icside_ids,
691 .drv = {
692 .name = "icside",
693 },
694};
695
696static int __init icside_init(void)
697{
698 return ecard_register_driver(&icside_driver);
699}
700
701MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
702MODULE_LICENSE("GPL");
703MODULE_DESCRIPTION("ICS IDE driver");
704
705module_init(icside_init);