blob: 743958044278eb5e9326bd4a6f89d2f2a2b1f442 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 1996-2004 Russell King.
3 *
4 * Please note that this platform does not support 32-bit IDE IO.
5 */
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007#include <linux/string.h>
8#include <linux/module.h>
9#include <linux/ioport.h>
10#include <linux/slab.h>
11#include <linux/blkdev.h>
12#include <linux/errno.h>
13#include <linux/hdreg.h>
14#include <linux/ide.h>
15#include <linux/dma-mapping.h>
16#include <linux/device.h>
17#include <linux/init.h>
18#include <linux/scatterlist.h>
Al Viroba5b55d2007-07-15 21:01:32 +010019#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21#include <asm/dma.h>
22#include <asm/ecard.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24#define ICS_IDENT_OFFSET 0x2280
25
26#define ICS_ARCIN_V5_INTRSTAT 0x0000
27#define ICS_ARCIN_V5_INTROFFSET 0x0004
28#define ICS_ARCIN_V5_IDEOFFSET 0x2800
29#define ICS_ARCIN_V5_IDEALTOFFSET 0x2b80
30#define ICS_ARCIN_V5_IDESTEPPING 6
31
32#define ICS_ARCIN_V6_IDEOFFSET_1 0x2000
33#define ICS_ARCIN_V6_INTROFFSET_1 0x2200
34#define ICS_ARCIN_V6_INTRSTAT_1 0x2290
35#define ICS_ARCIN_V6_IDEALTOFFSET_1 0x2380
36#define ICS_ARCIN_V6_IDEOFFSET_2 0x3000
37#define ICS_ARCIN_V6_INTROFFSET_2 0x3200
38#define ICS_ARCIN_V6_INTRSTAT_2 0x3290
39#define ICS_ARCIN_V6_IDEALTOFFSET_2 0x3380
40#define ICS_ARCIN_V6_IDESTEPPING 6
41
42struct cardinfo {
43 unsigned int dataoffset;
44 unsigned int ctrloffset;
45 unsigned int stepping;
46};
47
48static struct cardinfo icside_cardinfo_v5 = {
49 .dataoffset = ICS_ARCIN_V5_IDEOFFSET,
50 .ctrloffset = ICS_ARCIN_V5_IDEALTOFFSET,
51 .stepping = ICS_ARCIN_V5_IDESTEPPING,
52};
53
54static struct cardinfo icside_cardinfo_v6_1 = {
55 .dataoffset = ICS_ARCIN_V6_IDEOFFSET_1,
56 .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_1,
57 .stepping = ICS_ARCIN_V6_IDESTEPPING,
58};
59
60static struct cardinfo icside_cardinfo_v6_2 = {
61 .dataoffset = ICS_ARCIN_V6_IDEOFFSET_2,
62 .ctrloffset = ICS_ARCIN_V6_IDEALTOFFSET_2,
63 .stepping = ICS_ARCIN_V6_IDESTEPPING,
64};
65
66struct icside_state {
67 unsigned int channel;
68 unsigned int enabled;
69 void __iomem *irq_port;
70 void __iomem *ioc_base;
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +020071 unsigned int sel;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 unsigned int type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 ide_hwif_t *hwif[2];
74};
75
76#define ICS_TYPE_A3IN 0
77#define ICS_TYPE_A3USER 1
78#define ICS_TYPE_V6 3
79#define ICS_TYPE_V5 15
80#define ICS_TYPE_NOTYPE ((unsigned int)-1)
81
82/* ---------------- Version 5 PCB Support Functions --------------------- */
83/* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
84 * Purpose : enable interrupts from card
85 */
86static void icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
87{
88 struct icside_state *state = ec->irq_data;
89
90 writeb(0, state->irq_port + ICS_ARCIN_V5_INTROFFSET);
91}
92
93/* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
94 * Purpose : disable interrupts from card
95 */
96static void icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
97{
98 struct icside_state *state = ec->irq_data;
99
100 readb(state->irq_port + ICS_ARCIN_V5_INTROFFSET);
101}
102
103static const expansioncard_ops_t icside_ops_arcin_v5 = {
104 .irqenable = icside_irqenable_arcin_v5,
105 .irqdisable = icside_irqdisable_arcin_v5,
106};
107
108
109/* ---------------- Version 6 PCB Support Functions --------------------- */
110/* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
111 * Purpose : enable interrupts from card
112 */
113static void icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
114{
115 struct icside_state *state = ec->irq_data;
116 void __iomem *base = state->irq_port;
117
118 state->enabled = 1;
119
120 switch (state->channel) {
121 case 0:
122 writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1);
123 readb(base + ICS_ARCIN_V6_INTROFFSET_2);
124 break;
125 case 1:
126 writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2);
127 readb(base + ICS_ARCIN_V6_INTROFFSET_1);
128 break;
129 }
130}
131
132/* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
133 * Purpose : disable interrupts from card
134 */
135static void icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
136{
137 struct icside_state *state = ec->irq_data;
138
139 state->enabled = 0;
140
141 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);
142 readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);
143}
144
145/* Prototype: icside_irqprobe(struct expansion_card *ec)
146 * Purpose : detect an active interrupt from card
147 */
148static int icside_irqpending_arcin_v6(struct expansion_card *ec)
149{
150 struct icside_state *state = ec->irq_data;
151
152 return readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 ||
153 readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1;
154}
155
156static const expansioncard_ops_t icside_ops_arcin_v6 = {
157 .irqenable = icside_irqenable_arcin_v6,
158 .irqdisable = icside_irqdisable_arcin_v6,
159 .irqpending = icside_irqpending_arcin_v6,
160};
161
162/*
163 * Handle routing of interrupts. This is called before
164 * we write the command to the drive.
165 */
166static void icside_maskproc(ide_drive_t *drive, int mask)
167{
168 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200169 struct expansion_card *ec = ECARD_DEV(hwif->dev);
170 struct icside_state *state = ecard_get_drvdata(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 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
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200196static const struct ide_port_ops icside_v6_no_dma_port_ops = {
197 .maskproc = icside_maskproc,
198};
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#ifdef CONFIG_BLK_DEV_IDEDMA_ICS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201/*
202 * SG-DMA support.
203 *
204 * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers.
205 * There is only one DMA controller per card, which means that only
206 * one drive can be accessed at one time. NOTE! We do not enforce that
207 * here, but we rely on the main IDE driver spotting that both
208 * interfaces use the same IRQ, which should guarantee this.
209 */
210
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211/*
212 * Configure the IOMD to give the appropriate timings for the transfer
213 * mode being requested. We take the advice of the ATA standards, and
214 * calculate the cycle time based on the transfer mode, and the EIDE
215 * MW DMA specs that the drive provides in the IDENTIFY command.
216 *
217 * We have the following IOMD DMA modes to choose from:
218 *
219 * Type Active Recovery Cycle
220 * A 250 (250) 312 (550) 562 (800)
221 * B 187 250 437
222 * C 125 (125) 125 (375) 250 (500)
223 * D 62 125 187
224 *
225 * (figures in brackets are actual measured timings)
226 *
227 * However, we also need to take care of the read/write active and
228 * recovery timings:
229 *
230 * Read Write
231 * Mode Active -- Recovery -- Cycle IOMD type
232 * MW0 215 50 215 480 A
233 * MW1 80 50 50 150 C
234 * MW2 70 25 25 120 C
235 */
Bartlomiej Zolnierkiewicz88b2b322007-10-13 17:47:51 +0200236static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Bartlomiej Zolnierkiewiczf44ae582007-10-11 23:54:00 +0200238 int cycle_time, use_dma_info = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 switch (xfer_mode) {
241 case XFER_MW_DMA_2:
242 cycle_time = 250;
243 use_dma_info = 1;
244 break;
245
246 case XFER_MW_DMA_1:
247 cycle_time = 250;
248 use_dma_info = 1;
249 break;
250
251 case XFER_MW_DMA_0:
252 cycle_time = 480;
253 break;
254
255 case XFER_SW_DMA_2:
256 case XFER_SW_DMA_1:
257 case XFER_SW_DMA_0:
258 cycle_time = 480;
259 break;
260 }
261
262 /*
263 * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
264 * take care to note the values in the ID...
265 */
266 if (use_dma_info && drive->id->eide_dma_time > cycle_time)
267 cycle_time = drive->id->eide_dma_time;
268
269 drive->drive_data = cycle_time;
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 printk("%s: %s selected (peak %dMB/s)\n", drive->name,
272 ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200275static const struct ide_port_ops icside_v6_port_ops = {
276 .set_dma_mode = icside_set_dma_mode,
277 .maskproc = icside_maskproc,
278};
279
Bartlomiej Zolnierkiewicz15ce9262008-01-26 20:13:03 +0100280static void icside_dma_host_set(ide_drive_t *drive, int on)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}
283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284static int icside_dma_end(ide_drive_t *drive)
285{
286 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100287 struct expansion_card *ec = ECARD_DEV(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 drive->waiting_for_dma = 0;
290
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100291 disable_dma(ec->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
293 /* Teardown mappings after DMA has completed. */
Bartlomiej Zolnierkiewicz062f9f02008-02-01 23:09:32 +0100294 ide_destroy_dmatable(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100296 return get_dma_residue(ec->dma) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298
299static void icside_dma_start(ide_drive_t *drive)
300{
301 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100302 struct expansion_card *ec = ECARD_DEV(hwif->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
304 /* We can not enable DMA on both channels simultaneously. */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100305 BUG_ON(dma_channel_active(ec->dma));
306 enable_dma(ec->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307}
308
309static int icside_dma_setup(ide_drive_t *drive)
310{
311 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100312 struct expansion_card *ec = ECARD_DEV(hwif->dev);
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200313 struct icside_state *state = ecard_get_drvdata(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 struct request *rq = hwif->hwgroup->rq;
315 unsigned int dma_mode;
316
317 if (rq_data_dir(rq))
318 dma_mode = DMA_MODE_WRITE;
319 else
320 dma_mode = DMA_MODE_READ;
321
322 /*
323 * We can not enable DMA on both channels.
324 */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100325 BUG_ON(dma_channel_active(ec->dma));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
Bartlomiej Zolnierkiewicz062f9f02008-02-01 23:09:32 +0100327 hwif->sg_nents = ide_build_sglist(drive, rq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328
329 /*
330 * Ensure that we have the right interrupt routed.
331 */
332 icside_maskproc(drive, 0);
333
334 /*
335 * Route the DMA signals to the correct interface.
336 */
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200337 writeb(state->sel | hwif->channel, state->ioc_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /*
340 * Select the correct timing for this drive.
341 */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100342 set_dma_speed(ec->dma, drive->drive_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 /*
345 * Tell the DMA engine about the SG table and
346 * data direction.
347 */
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100348 set_dma_sg(ec->dma, hwif->sg_table, hwif->sg_nents);
349 set_dma_mode(ec->dma, dma_mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
351 drive->waiting_for_dma = 1;
352
353 return 0;
354}
355
356static void icside_dma_exec_cmd(ide_drive_t *drive, u8 cmd)
357{
358 /* issue cmd to drive */
359 ide_execute_command(drive, cmd, ide_dma_intr, 2 * WAIT_CMD, NULL);
360}
361
362static int icside_dma_test_irq(ide_drive_t *drive)
363{
364 ide_hwif_t *hwif = HWIF(drive);
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200365 struct expansion_card *ec = ECARD_DEV(hwif->dev);
366 struct icside_state *state = ecard_get_drvdata(ec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
368 return readb(state->irq_port +
369 (hwif->channel ?
370 ICS_ARCIN_V6_INTRSTAT_2 :
371 ICS_ARCIN_V6_INTRSTAT_1)) & 1;
372}
373
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200374static void icside_dma_timeout(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375{
376 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
377
378 if (icside_dma_test_irq(drive))
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200379 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380
Bartlomiej Zolnierkiewiczc47137a2008-02-06 02:57:51 +0100381 ide_dump_status(drive, "DMA timeout", ide_read_status(drive));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Sergei Shtylyovc283f5d2007-07-09 23:17:54 +0200383 icside_dma_end(drive);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384}
385
Sergei Shtylyov841d2a92007-07-09 23:17:54 +0200386static void icside_dma_lost_irq(ide_drive_t *drive)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
388 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389}
390
Bartlomiej Zolnierkiewicz91432f42008-04-26 22:25:23 +0200391static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 hwif->dmatable_cpu = NULL;
394 hwif->dmatable_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Bartlomiej Zolnierkiewicz91432f42008-04-26 22:25:23 +0200396 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397}
Bartlomiej Zolnierkiewicz5e37bdc2008-04-26 22:25:24 +0200398
Bartlomiej Zolnierkiewiczf37afda2008-04-26 22:25:24 +0200399static const struct ide_dma_ops icside_v6_dma_ops = {
Bartlomiej Zolnierkiewicz5e37bdc2008-04-26 22:25:24 +0200400 .dma_host_set = icside_dma_host_set,
401 .dma_setup = icside_dma_setup,
402 .dma_exec_cmd = icside_dma_exec_cmd,
403 .dma_start = icside_dma_start,
404 .dma_end = icside_dma_end,
405 .dma_test_irq = icside_dma_test_irq,
406 .dma_timeout = icside_dma_timeout,
407 .dma_lost_irq = icside_dma_lost_irq,
408};
409#else
410#define icside_v6_dma_ops NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#endif
412
Bartlomiej Zolnierkiewicz91432f42008-04-26 22:25:23 +0200413static int icside_dma_off_init(ide_hwif_t *hwif, const struct ide_port_info *d)
414{
415 return -EOPNOTSUPP;
416}
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418static ide_hwif_t *
419icside_setup(void __iomem *base, struct cardinfo *info, struct expansion_card *ec)
420{
421 unsigned long port = (unsigned long)base + info->dataoffset;
422 ide_hwif_t *hwif;
423
Bartlomiej Zolnierkiewicz59bff5b2008-04-26 17:36:32 +0200424 hwif = ide_find_port();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 if (hwif) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /*
427 * Ensure we're using MMIO
428 */
429 default_hwif_mmiops(hwif);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Al Viro7d896e02008-04-28 06:59:25 +0100431 hwif->io_ports.data_addr = port;
432 hwif->io_ports.error_addr = port + (1 << info->stepping);
433 hwif->io_ports.nsect_addr = port + (2 << info->stepping);
434 hwif->io_ports.lbal_addr = port + (3 << info->stepping);
435 hwif->io_ports.lbam_addr = port + (4 << info->stepping);
436 hwif->io_ports.lbah_addr = port + (5 << info->stepping);
437 hwif->io_ports.device_addr = port + (6 << info->stepping);
438 hwif->io_ports.status_addr = port + (7 << info->stepping);
Bartlomiej Zolnierkiewicz4c3032d2008-04-27 15:38:32 +0200439 hwif->io_ports.ctl_addr =
440 (unsigned long)base + info->ctrloffset;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 hwif->irq = ec->irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 hwif->chipset = ide_acorn;
443 hwif->gendev.parent = &ec->dev;
Bartlomiej Zolnierkiewiczf8341c12008-02-01 23:09:32 +0100444 hwif->dev = &ec->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
447 return hwif;
448}
449
450static int __init
451icside_register_v5(struct icside_state *state, struct expansion_card *ec)
452{
453 ide_hwif_t *hwif;
454 void __iomem *base;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200455 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Russell King10bdaaa2007-05-10 18:40:51 +0100457 base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if (!base)
459 return -ENOMEM;
460
461 state->irq_port = base;
462
463 ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT;
464 ec->irqmask = 1;
Russell Kingc7b87f32007-05-10 16:46:13 +0100465
466 ecard_setirq(ec, &icside_ops_arcin_v5, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468 /*
469 * Be on the safe side - disable interrupts
470 */
471 icside_irqdisable_arcin_v5(ec, 0);
472
473 hwif = icside_setup(base, &icside_cardinfo_v5, ec);
Russell King10bdaaa2007-05-10 18:40:51 +0100474 if (!hwif)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
477 state->hwif[0] = hwif;
478
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200479 ecard_set_drvdata(ec, state);
480
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200481 idx[0] = hwif->index;
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200482
Bartlomiej Zolnierkiewiczc413b9b2008-02-02 19:56:31 +0100483 ide_device_add(idx, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 return 0;
486}
487
Bartlomiej Zolnierkiewiczc413b9b2008-02-02 19:56:31 +0100488static const struct ide_port_info icside_v6_port_info __initdata = {
Bartlomiej Zolnierkiewicz91432f42008-04-26 22:25:23 +0200489 .init_dma = icside_dma_off_init,
Bartlomiej Zolnierkiewiczac95bee2008-04-26 22:25:14 +0200490 .port_ops = &icside_v6_no_dma_port_ops,
Bartlomiej Zolnierkiewicz5e37bdc2008-04-26 22:25:24 +0200491 .dma_ops = &icside_v6_dma_ops,
Bartlomiej Zolnierkiewiczc5dd43e2008-04-28 23:44:37 +0200492 .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_MMIO,
Bartlomiej Zolnierkiewiczc413b9b2008-02-02 19:56:31 +0100493 .mwdma_mask = ATA_MWDMA2,
494 .swdma_mask = ATA_SWDMA2,
495};
496
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497static int __init
498icside_register_v6(struct icside_state *state, struct expansion_card *ec)
499{
500 ide_hwif_t *hwif, *mate;
501 void __iomem *ioc_base, *easi_base;
502 unsigned int sel = 0;
503 int ret;
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200504 u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
Bartlomiej Zolnierkiewiczc413b9b2008-02-02 19:56:31 +0100505 struct ide_port_info d = icside_v6_port_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
Russell King10bdaaa2007-05-10 18:40:51 +0100507 ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 if (!ioc_base) {
509 ret = -ENOMEM;
510 goto out;
511 }
512
513 easi_base = ioc_base;
514
515 if (ecard_resource_flags(ec, ECARD_RES_EASI)) {
Russell King10bdaaa2007-05-10 18:40:51 +0100516 easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (!easi_base) {
518 ret = -ENOMEM;
Russell King10bdaaa2007-05-10 18:40:51 +0100519 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 }
521
522 /*
523 * Enable access to the EASI region.
524 */
525 sel = 1 << 5;
526 }
527
528 writeb(sel, ioc_base);
529
Russell Kingc7b87f32007-05-10 16:46:13 +0100530 ecard_setirq(ec, &icside_ops_arcin_v6, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 state->irq_port = easi_base;
533 state->ioc_base = ioc_base;
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200534 state->sel = sel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
536 /*
537 * Be on the safe side - disable interrupts
538 */
539 icside_irqdisable_arcin_v6(ec, 0);
540
541 /*
542 * Find and register the interfaces.
543 */
544 hwif = icside_setup(easi_base, &icside_cardinfo_v6_1, ec);
545 mate = icside_setup(easi_base, &icside_cardinfo_v6_2, ec);
546
547 if (!hwif || !mate) {
548 ret = -ENODEV;
Russell King10bdaaa2007-05-10 18:40:51 +0100549 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 }
551
552 state->hwif[0] = hwif;
553 state->hwif[1] = mate;
554
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200555 ecard_set_drvdata(ec, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) {
Bartlomiej Zolnierkiewicz91432f42008-04-26 22:25:23 +0200558 d.init_dma = icside_dma_init;
Al Viro9c391ba2008-04-27 15:38:23 +0200559 d.port_ops = &icside_v6_port_ops;
Bartlomiej Zolnierkiewicz5e37bdc2008-04-26 22:25:24 +0200560 d.dma_ops = NULL;
Bartlomiej Zolnierkiewicz91432f42008-04-26 22:25:23 +0200561 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Bartlomiej Zolnierkiewicz8447d9d2007-10-20 00:32:31 +0200563 idx[0] = hwif->index;
564 idx[1] = mate->index;
Bartlomiej Zolnierkiewicz5cbf79c2007-05-10 00:01:11 +0200565
Bartlomiej Zolnierkiewiczc413b9b2008-02-02 19:56:31 +0100566 ide_device_add(idx, &d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
568 return 0;
569
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 out:
571 return ret;
572}
573
574static int __devinit
575icside_probe(struct expansion_card *ec, const struct ecard_id *id)
576{
577 struct icside_state *state;
578 void __iomem *idmem;
579 int ret;
580
581 ret = ecard_request_resources(ec);
582 if (ret)
583 goto out;
584
Mariusz Kozlowskicc60d8b2007-08-01 23:46:44 +0200585 state = kzalloc(sizeof(struct icside_state), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586 if (!state) {
587 ret = -ENOMEM;
588 goto release;
589 }
590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 state->type = ICS_TYPE_NOTYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Russell King10bdaaa2007-05-10 18:40:51 +0100593 idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 if (idmem) {
595 unsigned int type;
596
597 type = readb(idmem + ICS_IDENT_OFFSET) & 1;
598 type |= (readb(idmem + ICS_IDENT_OFFSET + 4) & 1) << 1;
599 type |= (readb(idmem + ICS_IDENT_OFFSET + 8) & 1) << 2;
600 type |= (readb(idmem + ICS_IDENT_OFFSET + 12) & 1) << 3;
Russell King10bdaaa2007-05-10 18:40:51 +0100601 ecardm_iounmap(ec, idmem);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 state->type = type;
604 }
605
606 switch (state->type) {
607 case ICS_TYPE_A3IN:
608 dev_warn(&ec->dev, "A3IN unsupported\n");
609 ret = -ENODEV;
610 break;
611
612 case ICS_TYPE_A3USER:
613 dev_warn(&ec->dev, "A3USER unsupported\n");
614 ret = -ENODEV;
615 break;
616
617 case ICS_TYPE_V5:
618 ret = icside_register_v5(state, ec);
619 break;
620
621 case ICS_TYPE_V6:
622 ret = icside_register_v6(state, ec);
623 break;
624
625 default:
626 dev_warn(&ec->dev, "unknown interface type\n");
627 ret = -ENODEV;
628 break;
629 }
630
Bartlomiej Zolnierkiewicz26839f02008-07-16 20:33:40 +0200631 if (ret == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633
634 kfree(state);
635 release:
636 ecard_release_resources(ec);
637 out:
638 return ret;
639}
640
641static void __devexit icside_remove(struct expansion_card *ec)
642{
643 struct icside_state *state = ecard_get_drvdata(ec);
644
645 switch (state->type) {
646 case ICS_TYPE_V5:
647 /* FIXME: tell IDE to stop using the interface */
648
649 /* Disable interrupts */
650 icside_irqdisable_arcin_v5(ec, 0);
651 break;
652
653 case ICS_TYPE_V6:
654 /* FIXME: tell IDE to stop using the interface */
655 if (ec->dma != NO_DMA)
656 free_dma(ec->dma);
657
658 /* Disable interrupts */
659 icside_irqdisable_arcin_v6(ec, 0);
660
661 /* Reset the ROM pointer/EASI selection */
662 writeb(0, state->ioc_base);
663 break;
664 }
665
666 ecard_set_drvdata(ec, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 kfree(state);
669 ecard_release_resources(ec);
670}
671
672static void icside_shutdown(struct expansion_card *ec)
673{
674 struct icside_state *state = ecard_get_drvdata(ec);
675 unsigned long flags;
676
677 /*
678 * Disable interrupts from this card. We need to do
679 * this before disabling EASI since we may be accessing
680 * this register via that region.
681 */
682 local_irq_save(flags);
683 ec->ops->irqdisable(ec, 0);
684 local_irq_restore(flags);
685
686 /*
687 * Reset the ROM pointer so that we can read the ROM
688 * after a soft reboot. This also disables access to
689 * the IDE taskfile via the EASI region.
690 */
691 if (state->ioc_base)
692 writeb(0, state->ioc_base);
693}
694
695static const struct ecard_id icside_ids[] = {
696 { MANU_ICS, PROD_ICS_IDE },
697 { MANU_ICS2, PROD_ICS2_IDE },
698 { 0xffff, 0xffff }
699};
700
701static struct ecard_driver icside_driver = {
702 .probe = icside_probe,
703 .remove = __devexit_p(icside_remove),
704 .shutdown = icside_shutdown,
705 .id_table = icside_ids,
706 .drv = {
707 .name = "icside",
708 },
709};
710
711static int __init icside_init(void)
712{
713 return ecard_register_driver(&icside_driver);
714}
715
716MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
717MODULE_LICENSE("GPL");
718MODULE_DESCRIPTION("ICS IDE driver");
719
720module_init(icside_init);