Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1da177e4 LT |
2 | * Copyright (c) 1996-2004 Russell King. |
3 | * | |
4 | * Please note that this platform does not support 32-bit IDE IO. | |
5 | */ | |
6 | ||
1da177e4 LT |
7 | #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> | |
ba5b55d0 | 19 | #include <linux/io.h> |
1da177e4 LT |
20 | |
21 | #include <asm/dma.h> | |
22 | #include <asm/ecard.h> | |
1da177e4 LT |
23 | |
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 | ||
42 | struct cardinfo { | |
43 | unsigned int dataoffset; | |
44 | unsigned int ctrloffset; | |
45 | unsigned int stepping; | |
46 | }; | |
47 | ||
48 | static 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 | ||
54 | static 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 | ||
60 | static 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 | ||
66 | struct icside_state { | |
67 | unsigned int channel; | |
68 | unsigned int enabled; | |
69 | void __iomem *irq_port; | |
70 | void __iomem *ioc_base; | |
26839f09 | 71 | unsigned int sel; |
1da177e4 | 72 | unsigned int type; |
1da177e4 LT |
73 | 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 | */ | |
86 | static 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 | */ | |
96 | static 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 | ||
103 | static 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 | */ | |
113 | static 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 | */ | |
135 | static 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 | */ | |
148 | static 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 | ||
156 | static 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 | */ | |
166 | static void icside_maskproc(ide_drive_t *drive, int mask) | |
167 | { | |
168 | ide_hwif_t *hwif = HWIF(drive); | |
26839f09 BZ |
169 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
170 | struct icside_state *state = ecard_get_drvdata(ec); | |
1da177e4 LT |
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 | ||
ac95beed BZ |
196 | static const struct ide_port_ops icside_v6_no_dma_port_ops = { |
197 | .maskproc = icside_maskproc, | |
198 | }; | |
199 | ||
1da177e4 | 200 | #ifdef CONFIG_BLK_DEV_IDEDMA_ICS |
1da177e4 LT |
201 | /* |
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 | ||
1da177e4 LT |
211 | /* |
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 | */ | |
88b2b32b | 236 | static void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode) |
1da177e4 | 237 | { |
f44ae58a | 238 | int cycle_time, use_dma_info = 0; |
1da177e4 | 239 | |
1da177e4 LT |
240 | 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 | ||
1da177e4 LT |
271 | printk("%s: %s selected (peak %dMB/s)\n", drive->name, |
272 | ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data); | |
1da177e4 LT |
273 | } |
274 | ||
ac95beed BZ |
275 | static const struct ide_port_ops icside_v6_port_ops = { |
276 | .set_dma_mode = icside_set_dma_mode, | |
277 | .maskproc = icside_maskproc, | |
278 | }; | |
279 | ||
15ce926a | 280 | static void icside_dma_host_set(ide_drive_t *drive, int on) |
1da177e4 | 281 | { |
1da177e4 LT |
282 | } |
283 | ||
1da177e4 LT |
284 | static int icside_dma_end(ide_drive_t *drive) |
285 | { | |
286 | ide_hwif_t *hwif = HWIF(drive); | |
f8341c1c | 287 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
1da177e4 LT |
288 | |
289 | drive->waiting_for_dma = 0; | |
290 | ||
f8341c1c | 291 | disable_dma(ec->dma); |
1da177e4 LT |
292 | |
293 | /* Teardown mappings after DMA has completed. */ | |
062f9f02 | 294 | ide_destroy_dmatable(drive); |
1da177e4 | 295 | |
f8341c1c | 296 | return get_dma_residue(ec->dma) != 0; |
1da177e4 LT |
297 | } |
298 | ||
299 | static void icside_dma_start(ide_drive_t *drive) | |
300 | { | |
301 | ide_hwif_t *hwif = HWIF(drive); | |
f8341c1c | 302 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
1da177e4 LT |
303 | |
304 | /* We can not enable DMA on both channels simultaneously. */ | |
f8341c1c BZ |
305 | BUG_ON(dma_channel_active(ec->dma)); |
306 | enable_dma(ec->dma); | |
1da177e4 LT |
307 | } |
308 | ||
309 | static int icside_dma_setup(ide_drive_t *drive) | |
310 | { | |
311 | ide_hwif_t *hwif = HWIF(drive); | |
f8341c1c | 312 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
26839f09 | 313 | struct icside_state *state = ecard_get_drvdata(ec); |
1da177e4 LT |
314 | 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 | */ | |
f8341c1c | 325 | BUG_ON(dma_channel_active(ec->dma)); |
1da177e4 | 326 | |
062f9f02 | 327 | hwif->sg_nents = ide_build_sglist(drive, rq); |
1da177e4 LT |
328 | |
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 | */ | |
26839f09 | 337 | writeb(state->sel | hwif->channel, state->ioc_base); |
1da177e4 LT |
338 | |
339 | /* | |
340 | * Select the correct timing for this drive. | |
341 | */ | |
f8341c1c | 342 | set_dma_speed(ec->dma, drive->drive_data); |
1da177e4 LT |
343 | |
344 | /* | |
345 | * Tell the DMA engine about the SG table and | |
346 | * data direction. | |
347 | */ | |
f8341c1c BZ |
348 | set_dma_sg(ec->dma, hwif->sg_table, hwif->sg_nents); |
349 | set_dma_mode(ec->dma, dma_mode); | |
1da177e4 LT |
350 | |
351 | drive->waiting_for_dma = 1; | |
352 | ||
353 | return 0; | |
354 | } | |
355 | ||
356 | static 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 | ||
362 | static int icside_dma_test_irq(ide_drive_t *drive) | |
363 | { | |
364 | ide_hwif_t *hwif = HWIF(drive); | |
26839f09 BZ |
365 | struct expansion_card *ec = ECARD_DEV(hwif->dev); |
366 | struct icside_state *state = ecard_get_drvdata(ec); | |
1da177e4 LT |
367 | |
368 | return readb(state->irq_port + | |
369 | (hwif->channel ? | |
370 | ICS_ARCIN_V6_INTRSTAT_2 : | |
371 | ICS_ARCIN_V6_INTRSTAT_1)) & 1; | |
372 | } | |
373 | ||
c283f5db | 374 | static void icside_dma_timeout(ide_drive_t *drive) |
1da177e4 LT |
375 | { |
376 | printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name); | |
377 | ||
378 | if (icside_dma_test_irq(drive)) | |
c283f5db | 379 | return; |
1da177e4 | 380 | |
c47137a9 | 381 | ide_dump_status(drive, "DMA timeout", ide_read_status(drive)); |
1da177e4 | 382 | |
c283f5db | 383 | icside_dma_end(drive); |
1da177e4 LT |
384 | } |
385 | ||
841d2a9b | 386 | static void icside_dma_lost_irq(ide_drive_t *drive) |
1da177e4 LT |
387 | { |
388 | printk(KERN_ERR "%s: IRQ lost\n", drive->name); | |
1da177e4 LT |
389 | } |
390 | ||
91432f48 | 391 | static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d) |
1da177e4 | 392 | { |
1da177e4 LT |
393 | hwif->dmatable_cpu = NULL; |
394 | hwif->dmatable_dma = 0; | |
1da177e4 | 395 | |
91432f48 | 396 | return 0; |
1da177e4 | 397 | } |
5e37bdc0 | 398 | |
f37afdac | 399 | static const struct ide_dma_ops icside_v6_dma_ops = { |
5e37bdc0 BZ |
400 | .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 | |
1da177e4 LT |
411 | #endif |
412 | ||
91432f48 BZ |
413 | static int icside_dma_off_init(ide_hwif_t *hwif, const struct ide_port_info *d) |
414 | { | |
415 | return -EOPNOTSUPP; | |
416 | } | |
417 | ||
1da177e4 LT |
418 | static ide_hwif_t * |
419 | icside_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 | ||
59bff5ba | 424 | hwif = ide_find_port(); |
1da177e4 | 425 | if (hwif) { |
1da177e4 LT |
426 | /* |
427 | * Ensure we're using MMIO | |
428 | */ | |
429 | default_hwif_mmiops(hwif); | |
1da177e4 | 430 | |
7d896e0b AV |
431 | 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); | |
4c3032d8 BZ |
439 | hwif->io_ports.ctl_addr = |
440 | (unsigned long)base + info->ctrloffset; | |
1da177e4 | 441 | hwif->irq = ec->irq; |
1da177e4 LT |
442 | hwif->chipset = ide_acorn; |
443 | hwif->gendev.parent = &ec->dev; | |
f8341c1c | 444 | hwif->dev = &ec->dev; |
1da177e4 LT |
445 | } |
446 | ||
447 | return hwif; | |
448 | } | |
449 | ||
450 | static int __init | |
451 | icside_register_v5(struct icside_state *state, struct expansion_card *ec) | |
452 | { | |
453 | ide_hwif_t *hwif; | |
454 | void __iomem *base; | |
8447d9d5 | 455 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
1da177e4 | 456 | |
10bdaaa0 | 457 | base = ecardm_iomap(ec, ECARD_RES_MEMC, 0, 0); |
1da177e4 LT |
458 | if (!base) |
459 | return -ENOMEM; | |
460 | ||
461 | state->irq_port = base; | |
462 | ||
463 | ec->irqaddr = base + ICS_ARCIN_V5_INTRSTAT; | |
464 | ec->irqmask = 1; | |
c7b87f3d RK |
465 | |
466 | ecard_setirq(ec, &icside_ops_arcin_v5, state); | |
1da177e4 LT |
467 | |
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); | |
10bdaaa0 | 474 | if (!hwif) |
1da177e4 | 475 | return -ENODEV; |
1da177e4 LT |
476 | |
477 | state->hwif[0] = hwif; | |
478 | ||
26839f09 BZ |
479 | ecard_set_drvdata(ec, state); |
480 | ||
8447d9d5 | 481 | idx[0] = hwif->index; |
5cbf79cd | 482 | |
c413b9b9 | 483 | ide_device_add(idx, NULL); |
1da177e4 LT |
484 | |
485 | return 0; | |
486 | } | |
487 | ||
c413b9b9 | 488 | static const struct ide_port_info icside_v6_port_info __initdata = { |
91432f48 | 489 | .init_dma = icside_dma_off_init, |
ac95beed | 490 | .port_ops = &icside_v6_no_dma_port_ops, |
5e37bdc0 | 491 | .dma_ops = &icside_v6_dma_ops, |
c5dd43ec | 492 | .host_flags = IDE_HFLAG_SERIALIZE | IDE_HFLAG_MMIO, |
c413b9b9 BZ |
493 | .mwdma_mask = ATA_MWDMA2, |
494 | .swdma_mask = ATA_SWDMA2, | |
495 | }; | |
496 | ||
1da177e4 LT |
497 | static int __init |
498 | icside_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; | |
8447d9d5 | 504 | u8 idx[4] = { 0xff, 0xff, 0xff, 0xff }; |
c413b9b9 | 505 | struct ide_port_info d = icside_v6_port_info; |
1da177e4 | 506 | |
10bdaaa0 | 507 | ioc_base = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); |
1da177e4 LT |
508 | 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)) { | |
10bdaaa0 | 516 | easi_base = ecardm_iomap(ec, ECARD_RES_EASI, 0, 0); |
1da177e4 LT |
517 | if (!easi_base) { |
518 | ret = -ENOMEM; | |
10bdaaa0 | 519 | goto out; |
1da177e4 LT |
520 | } |
521 | ||
522 | /* | |
523 | * Enable access to the EASI region. | |
524 | */ | |
525 | sel = 1 << 5; | |
526 | } | |
527 | ||
528 | writeb(sel, ioc_base); | |
529 | ||
c7b87f3d | 530 | ecard_setirq(ec, &icside_ops_arcin_v6, state); |
1da177e4 LT |
531 | |
532 | state->irq_port = easi_base; | |
533 | state->ioc_base = ioc_base; | |
26839f09 | 534 | state->sel = sel; |
1da177e4 LT |
535 | |
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; | |
10bdaaa0 | 549 | goto out; |
1da177e4 LT |
550 | } |
551 | ||
552 | state->hwif[0] = hwif; | |
553 | state->hwif[1] = mate; | |
554 | ||
26839f09 | 555 | ecard_set_drvdata(ec, state); |
1da177e4 LT |
556 | |
557 | if (ec->dma != NO_DMA && !request_dma(ec->dma, hwif->name)) { | |
91432f48 | 558 | d.init_dma = icside_dma_init; |
9c391bae | 559 | d.port_ops = &icside_v6_port_ops; |
5e37bdc0 | 560 | d.dma_ops = NULL; |
91432f48 | 561 | } |
1da177e4 | 562 | |
8447d9d5 BZ |
563 | idx[0] = hwif->index; |
564 | idx[1] = mate->index; | |
5cbf79cd | 565 | |
c413b9b9 | 566 | ide_device_add(idx, &d); |
1da177e4 LT |
567 | |
568 | return 0; | |
569 | ||
1da177e4 LT |
570 | out: |
571 | return ret; | |
572 | } | |
573 | ||
574 | static int __devinit | |
575 | icside_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 | ||
cc60d8ba | 585 | state = kzalloc(sizeof(struct icside_state), GFP_KERNEL); |
1da177e4 LT |
586 | if (!state) { |
587 | ret = -ENOMEM; | |
588 | goto release; | |
589 | } | |
590 | ||
1da177e4 | 591 | state->type = ICS_TYPE_NOTYPE; |
1da177e4 | 592 | |
10bdaaa0 | 593 | idmem = ecardm_iomap(ec, ECARD_RES_IOCFAST, 0, 0); |
1da177e4 LT |
594 | 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; | |
10bdaaa0 | 601 | ecardm_iounmap(ec, idmem); |
1da177e4 LT |
602 | |
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 | ||
26839f09 | 631 | if (ret == 0) |
1da177e4 | 632 | goto out; |
1da177e4 LT |
633 | |
634 | kfree(state); | |
635 | release: | |
636 | ecard_release_resources(ec); | |
637 | out: | |
638 | return ret; | |
639 | } | |
640 | ||
641 | static 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); | |
1da177e4 | 667 | |
1da177e4 LT |
668 | kfree(state); |
669 | ecard_release_resources(ec); | |
670 | } | |
671 | ||
672 | static 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 | ||
695 | static const struct ecard_id icside_ids[] = { | |
696 | { MANU_ICS, PROD_ICS_IDE }, | |
697 | { MANU_ICS2, PROD_ICS2_IDE }, | |
698 | { 0xffff, 0xffff } | |
699 | }; | |
700 | ||
701 | static 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 | ||
711 | static int __init icside_init(void) | |
712 | { | |
713 | return ecard_register_driver(&icside_driver); | |
714 | } | |
715 | ||
716 | MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>"); | |
717 | MODULE_LICENSE("GPL"); | |
718 | MODULE_DESCRIPTION("ICS IDE driver"); | |
719 | ||
720 | module_init(icside_init); |