2 * Copyright (c) 1996-2004 Russell King.
4 * Please note that this platform does not support 32-bit IDE IO.
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>
22 #include <asm/ecard.h>
24 #define ICS_IDENT_OFFSET 0x2280
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
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
43 unsigned int dataoffset
;
44 unsigned int ctrloffset
;
45 unsigned int stepping
;
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
,
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
,
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
,
69 void __iomem
*irq_port
;
70 void __iomem
*ioc_base
;
75 #define ICS_TYPE_A3IN 0
76 #define ICS_TYPE_A3USER 1
78 #define ICS_TYPE_V5 15
79 #define ICS_TYPE_NOTYPE ((unsigned int)-1)
81 /* ---------------- Version 5 PCB Support Functions --------------------- */
82 /* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr)
83 * Purpose : enable interrupts from card
85 static void icside_irqenable_arcin_v5 (struct expansion_card
*ec
, int irqnr
)
87 struct icside_state
*state
= ec
->irq_data
;
89 writeb(0, state
->irq_port
+ ICS_ARCIN_V5_INTROFFSET
);
92 /* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr)
93 * Purpose : disable interrupts from card
95 static void icside_irqdisable_arcin_v5 (struct expansion_card
*ec
, int irqnr
)
97 struct icside_state
*state
= ec
->irq_data
;
99 readb(state
->irq_port
+ ICS_ARCIN_V5_INTROFFSET
);
102 static const expansioncard_ops_t icside_ops_arcin_v5
= {
103 .irqenable
= icside_irqenable_arcin_v5
,
104 .irqdisable
= icside_irqdisable_arcin_v5
,
108 /* ---------------- Version 6 PCB Support Functions --------------------- */
109 /* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr)
110 * Purpose : enable interrupts from card
112 static void icside_irqenable_arcin_v6 (struct expansion_card
*ec
, int irqnr
)
114 struct icside_state
*state
= ec
->irq_data
;
115 void __iomem
*base
= state
->irq_port
;
119 switch (state
->channel
) {
121 writeb(0, base
+ ICS_ARCIN_V6_INTROFFSET_1
);
122 readb(base
+ ICS_ARCIN_V6_INTROFFSET_2
);
125 writeb(0, base
+ ICS_ARCIN_V6_INTROFFSET_2
);
126 readb(base
+ ICS_ARCIN_V6_INTROFFSET_1
);
131 /* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr)
132 * Purpose : disable interrupts from card
134 static void icside_irqdisable_arcin_v6 (struct expansion_card
*ec
, int irqnr
)
136 struct icside_state
*state
= ec
->irq_data
;
140 readb(state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_1
);
141 readb(state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_2
);
144 /* Prototype: icside_irqprobe(struct expansion_card *ec)
145 * Purpose : detect an active interrupt from card
147 static int icside_irqpending_arcin_v6(struct expansion_card
*ec
)
149 struct icside_state
*state
= ec
->irq_data
;
151 return readb(state
->irq_port
+ ICS_ARCIN_V6_INTRSTAT_1
) & 1 ||
152 readb(state
->irq_port
+ ICS_ARCIN_V6_INTRSTAT_2
) & 1;
155 static const expansioncard_ops_t icside_ops_arcin_v6
= {
156 .irqenable
= icside_irqenable_arcin_v6
,
157 .irqdisable
= icside_irqdisable_arcin_v6
,
158 .irqpending
= icside_irqpending_arcin_v6
,
162 * Handle routing of interrupts. This is called before
163 * we write the command to the drive.
165 static void icside_maskproc(ide_drive_t
*drive
, int mask
)
167 ide_hwif_t
*hwif
= HWIF(drive
);
168 struct icside_state
*state
= hwif
->hwif_data
;
171 local_irq_save(flags
);
173 state
->channel
= hwif
->channel
;
175 if (state
->enabled
&& !mask
) {
176 switch (hwif
->channel
) {
178 writeb(0, state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_1
);
179 readb(state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_2
);
182 writeb(0, state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_2
);
183 readb(state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_1
);
187 readb(state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_2
);
188 readb(state
->irq_port
+ ICS_ARCIN_V6_INTROFFSET_1
);
191 local_irq_restore(flags
);
194 #ifdef CONFIG_BLK_DEV_IDEDMA_ICS
198 * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers.
199 * There is only one DMA controller per card, which means that only
200 * one drive can be accessed at one time. NOTE! We do not enforce that
201 * here, but we rely on the main IDE driver spotting that both
202 * interfaces use the same IRQ, which should guarantee this.
206 * Configure the IOMD to give the appropriate timings for the transfer
207 * mode being requested. We take the advice of the ATA standards, and
208 * calculate the cycle time based on the transfer mode, and the EIDE
209 * MW DMA specs that the drive provides in the IDENTIFY command.
211 * We have the following IOMD DMA modes to choose from:
213 * Type Active Recovery Cycle
214 * A 250 (250) 312 (550) 562 (800)
216 * C 125 (125) 125 (375) 250 (500)
219 * (figures in brackets are actual measured timings)
221 * However, we also need to take care of the read/write active and
225 * Mode Active -- Recovery -- Cycle IOMD type
226 * MW0 215 50 215 480 A
230 static void icside_set_dma_mode(ide_drive_t
*drive
, const u8 xfer_mode
)
232 int cycle_time
, use_dma_info
= 0;
257 * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should
258 * take care to note the values in the ID...
260 if (use_dma_info
&& drive
->id
->eide_dma_time
> cycle_time
)
261 cycle_time
= drive
->id
->eide_dma_time
;
263 drive
->drive_data
= cycle_time
;
265 printk("%s: %s selected (peak %dMB/s)\n", drive
->name
,
266 ide_xfer_verbose(xfer_mode
), 2000 / drive
->drive_data
);
269 static void icside_dma_host_set(ide_drive_t
*drive
, int on
)
273 static int icside_dma_end(ide_drive_t
*drive
)
275 ide_hwif_t
*hwif
= HWIF(drive
);
276 struct expansion_card
*ec
= ECARD_DEV(hwif
->dev
);
278 drive
->waiting_for_dma
= 0;
280 disable_dma(ec
->dma
);
282 /* Teardown mappings after DMA has completed. */
283 ide_destroy_dmatable(drive
);
285 return get_dma_residue(ec
->dma
) != 0;
288 static void icside_dma_start(ide_drive_t
*drive
)
290 ide_hwif_t
*hwif
= HWIF(drive
);
291 struct expansion_card
*ec
= ECARD_DEV(hwif
->dev
);
293 /* We can not enable DMA on both channels simultaneously. */
294 BUG_ON(dma_channel_active(ec
->dma
));
298 static int icside_dma_setup(ide_drive_t
*drive
)
300 ide_hwif_t
*hwif
= HWIF(drive
);
301 struct expansion_card
*ec
= ECARD_DEV(hwif
->dev
);
302 struct request
*rq
= hwif
->hwgroup
->rq
;
303 unsigned int dma_mode
;
306 dma_mode
= DMA_MODE_WRITE
;
308 dma_mode
= DMA_MODE_READ
;
311 * We can not enable DMA on both channels.
313 BUG_ON(dma_channel_active(ec
->dma
));
315 hwif
->sg_nents
= ide_build_sglist(drive
, rq
);
318 * Ensure that we have the right interrupt routed.
320 icside_maskproc(drive
, 0);
323 * Route the DMA signals to the correct interface.
325 writeb(hwif
->select_data
, hwif
->config_data
);
328 * Select the correct timing for this drive.
330 set_dma_speed(ec
->dma
, drive
->drive_data
);
333 * Tell the DMA engine about the SG table and
336 set_dma_sg(ec
->dma
, hwif
->sg_table
, hwif
->sg_nents
);
337 set_dma_mode(ec
->dma
, dma_mode
);
339 drive
->waiting_for_dma
= 1;
344 static void icside_dma_exec_cmd(ide_drive_t
*drive
, u8 cmd
)
346 /* issue cmd to drive */
347 ide_execute_command(drive
, cmd
, ide_dma_intr
, 2 * WAIT_CMD
, NULL
);
350 static int icside_dma_test_irq(ide_drive_t
*drive
)
352 ide_hwif_t
*hwif
= HWIF(drive
);
353 struct icside_state
*state
= hwif
->hwif_data
;
355 return readb(state
->irq_port
+
357 ICS_ARCIN_V6_INTRSTAT_2
:
358 ICS_ARCIN_V6_INTRSTAT_1
)) & 1;
361 static void icside_dma_timeout(ide_drive_t
*drive
)
363 printk(KERN_ERR
"%s: DMA timeout occurred: ", drive
->name
);
365 if (icside_dma_test_irq(drive
))
368 ide_dump_status(drive
, "DMA timeout", ide_read_status(drive
));
370 icside_dma_end(drive
);
373 static void icside_dma_lost_irq(ide_drive_t
*drive
)
375 printk(KERN_ERR
"%s: IRQ lost\n", drive
->name
);
378 static void icside_dma_init(ide_hwif_t
*hwif
)
380 hwif
->dmatable_cpu
= NULL
;
381 hwif
->dmatable_dma
= 0;
382 hwif
->set_dma_mode
= icside_set_dma_mode
;
384 hwif
->dma_host_set
= icside_dma_host_set
;
385 hwif
->dma_setup
= icside_dma_setup
;
386 hwif
->dma_exec_cmd
= icside_dma_exec_cmd
;
387 hwif
->dma_start
= icside_dma_start
;
388 hwif
->ide_dma_end
= icside_dma_end
;
389 hwif
->ide_dma_test_irq
= icside_dma_test_irq
;
390 hwif
->dma_timeout
= icside_dma_timeout
;
391 hwif
->dma_lost_irq
= icside_dma_lost_irq
;
394 #define icside_dma_init(hwif) (0)
398 icside_setup(void __iomem
*base
, struct cardinfo
*info
, struct expansion_card
*ec
)
400 unsigned long port
= (unsigned long)base
+ info
->dataoffset
;
403 hwif
= ide_find_port(port
);
408 * Ensure we're using MMIO
410 default_hwif_mmiops(hwif
);
413 for (i
= IDE_DATA_OFFSET
; i
<= IDE_STATUS_OFFSET
; i
++) {
414 hwif
->io_ports
[i
] = port
;
415 port
+= 1 << info
->stepping
;
417 hwif
->io_ports
[IDE_CONTROL_OFFSET
] = (unsigned long)base
+ info
->ctrloffset
;
420 hwif
->chipset
= ide_acorn
;
421 hwif
->gendev
.parent
= &ec
->dev
;
422 hwif
->dev
= &ec
->dev
;
429 icside_register_v5(struct icside_state
*state
, struct expansion_card
*ec
)
433 u8 idx
[4] = { 0xff, 0xff, 0xff, 0xff };
435 base
= ecardm_iomap(ec
, ECARD_RES_MEMC
, 0, 0);
439 state
->irq_port
= base
;
441 ec
->irqaddr
= base
+ ICS_ARCIN_V5_INTRSTAT
;
444 ecard_setirq(ec
, &icside_ops_arcin_v5
, state
);
447 * Be on the safe side - disable interrupts
449 icside_irqdisable_arcin_v5(ec
, 0);
451 hwif
= icside_setup(base
, &icside_cardinfo_v5
, ec
);
455 state
->hwif
[0] = hwif
;
457 idx
[0] = hwif
->index
;
459 ide_device_add(idx
, NULL
);
464 static const struct ide_port_info icside_v6_port_info __initdata
= {
465 .host_flags
= IDE_HFLAG_SERIALIZE
|
466 IDE_HFLAG_NO_DMA
| /* no SFF-style DMA */
467 IDE_HFLAG_NO_AUTOTUNE
,
468 .mwdma_mask
= ATA_MWDMA2
,
469 .swdma_mask
= ATA_SWDMA2
,
473 icside_register_v6(struct icside_state
*state
, struct expansion_card
*ec
)
475 ide_hwif_t
*hwif
, *mate
;
476 void __iomem
*ioc_base
, *easi_base
;
477 unsigned int sel
= 0;
479 u8 idx
[4] = { 0xff, 0xff, 0xff, 0xff };
480 struct ide_port_info d
= icside_v6_port_info
;
482 ioc_base
= ecardm_iomap(ec
, ECARD_RES_IOCFAST
, 0, 0);
488 easi_base
= ioc_base
;
490 if (ecard_resource_flags(ec
, ECARD_RES_EASI
)) {
491 easi_base
= ecardm_iomap(ec
, ECARD_RES_EASI
, 0, 0);
498 * Enable access to the EASI region.
503 writeb(sel
, ioc_base
);
505 ecard_setirq(ec
, &icside_ops_arcin_v6
, state
);
507 state
->irq_port
= easi_base
;
508 state
->ioc_base
= ioc_base
;
511 * Be on the safe side - disable interrupts
513 icside_irqdisable_arcin_v6(ec
, 0);
516 * Find and register the interfaces.
518 hwif
= icside_setup(easi_base
, &icside_cardinfo_v6_1
, ec
);
519 mate
= icside_setup(easi_base
, &icside_cardinfo_v6_2
, ec
);
521 if (!hwif
|| !mate
) {
526 state
->hwif
[0] = hwif
;
527 state
->hwif
[1] = mate
;
529 hwif
->maskproc
= icside_maskproc
;
530 hwif
->hwif_data
= state
;
531 hwif
->config_data
= (unsigned long)ioc_base
;
532 hwif
->select_data
= sel
;
534 mate
->maskproc
= icside_maskproc
;
535 mate
->hwif_data
= state
;
536 mate
->config_data
= (unsigned long)ioc_base
;
537 mate
->select_data
= sel
| 1;
539 if (ec
->dma
!= NO_DMA
&& !request_dma(ec
->dma
, hwif
->name
)) {
540 icside_dma_init(hwif
);
541 icside_dma_init(mate
);
543 d
.mwdma_mask
= d
.swdma_mask
= 0;
545 idx
[0] = hwif
->index
;
546 idx
[1] = mate
->index
;
548 ide_device_add(idx
, &d
);
557 icside_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
559 struct icside_state
*state
;
563 ret
= ecard_request_resources(ec
);
567 state
= kzalloc(sizeof(struct icside_state
), GFP_KERNEL
);
573 state
->type
= ICS_TYPE_NOTYPE
;
575 idmem
= ecardm_iomap(ec
, ECARD_RES_IOCFAST
, 0, 0);
579 type
= readb(idmem
+ ICS_IDENT_OFFSET
) & 1;
580 type
|= (readb(idmem
+ ICS_IDENT_OFFSET
+ 4) & 1) << 1;
581 type
|= (readb(idmem
+ ICS_IDENT_OFFSET
+ 8) & 1) << 2;
582 type
|= (readb(idmem
+ ICS_IDENT_OFFSET
+ 12) & 1) << 3;
583 ecardm_iounmap(ec
, idmem
);
588 switch (state
->type
) {
590 dev_warn(&ec
->dev
, "A3IN unsupported\n");
594 case ICS_TYPE_A3USER
:
595 dev_warn(&ec
->dev
, "A3USER unsupported\n");
600 ret
= icside_register_v5(state
, ec
);
604 ret
= icside_register_v6(state
, ec
);
608 dev_warn(&ec
->dev
, "unknown interface type\n");
614 ecard_set_drvdata(ec
, state
);
620 ecard_release_resources(ec
);
625 static void __devexit
icside_remove(struct expansion_card
*ec
)
627 struct icside_state
*state
= ecard_get_drvdata(ec
);
629 switch (state
->type
) {
631 /* FIXME: tell IDE to stop using the interface */
633 /* Disable interrupts */
634 icside_irqdisable_arcin_v5(ec
, 0);
638 /* FIXME: tell IDE to stop using the interface */
639 if (ec
->dma
!= NO_DMA
)
642 /* Disable interrupts */
643 icside_irqdisable_arcin_v6(ec
, 0);
645 /* Reset the ROM pointer/EASI selection */
646 writeb(0, state
->ioc_base
);
650 ecard_set_drvdata(ec
, NULL
);
653 ecard_release_resources(ec
);
656 static void icside_shutdown(struct expansion_card
*ec
)
658 struct icside_state
*state
= ecard_get_drvdata(ec
);
662 * Disable interrupts from this card. We need to do
663 * this before disabling EASI since we may be accessing
664 * this register via that region.
666 local_irq_save(flags
);
667 ec
->ops
->irqdisable(ec
, 0);
668 local_irq_restore(flags
);
671 * Reset the ROM pointer so that we can read the ROM
672 * after a soft reboot. This also disables access to
673 * the IDE taskfile via the EASI region.
676 writeb(0, state
->ioc_base
);
679 static const struct ecard_id icside_ids
[] = {
680 { MANU_ICS
, PROD_ICS_IDE
},
681 { MANU_ICS2
, PROD_ICS2_IDE
},
685 static struct ecard_driver icside_driver
= {
686 .probe
= icside_probe
,
687 .remove
= __devexit_p(icside_remove
),
688 .shutdown
= icside_shutdown
,
689 .id_table
= icside_ids
,
695 static int __init
icside_init(void)
697 return ecard_register_driver(&icside_driver
);
700 MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
701 MODULE_LICENSE("GPL");
702 MODULE_DESCRIPTION("ICS IDE driver");
704 module_init(icside_init
);