1 --- a/drivers/ide/Kconfig
2 +++ b/drivers/ide/Kconfig
3 @@ -717,6 +717,11 @@ config BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
4 depends on SOC_AU1200 && BLK_DEV_IDE_AU1XXX
7 +config BLK_DEV_IDE_MAGICBOX
8 + tristate "Magicbox CF card support"
9 + depends on MAGICBOXV2 || OPENRB_LIGHT
10 + select IDE_XFER_MODE
12 config BLK_DEV_IDE_TX4938
13 tristate "TX4938 internal IDE support"
15 --- a/drivers/ide/Makefile
16 +++ b/drivers/ide/Makefile
17 @@ -113,6 +113,7 @@ obj-$(CONFIG_BLK_DEV_IDE_RAPIDE) += rapi
18 obj-$(CONFIG_BLK_DEV_PALMCHIP_BK3710) += palm_bk3710.o
20 obj-$(CONFIG_BLK_DEV_IDE_AU1XXX) += au1xxx-ide.o
21 +obj-$(CONFIG_BLK_DEV_IDE_MAGICBOX) += magicbox_ide.o
23 obj-$(CONFIG_BLK_DEV_IDE_TX4938) += tx4938ide.o
24 obj-$(CONFIG_BLK_DEV_IDE_TX4939) += tx4939ide.o
26 +++ b/drivers/ide/magicbox_ide.c
29 + * IDE driver for the MagicBox 2.0 onboard CompactFlash slot.
31 + * Copyright (C) 2009 Gabor Juhos <juhosg@openwrt.org>
33 + * Based on the original driver by Wojtek Kaniewski <wojtekka@toxygen.net>
35 + * This program is free software; you can redistribute it and/or modify it
36 + * under the terms of the GNU General Public License version 2 as published
37 + * by the Free Software Foundation.
40 +#include <linux/types.h>
41 +#include <linux/ioport.h>
42 +#include <linux/of.h>
43 +#include <linux/of_device.h>
44 +#include <linux/of_platform.h>
45 +#include <linux/ide.h>
47 +#include <asm/dcr-native.h>
49 +#define DRV_DESC "IDE driver for Magicbox 2.0 onboard CF slot"
50 +#define DRV_NAME "magicbox_cf"
52 +static inline u8 magicbox_ide_inb(unsigned long port)
54 + return (u8) (readw((void __iomem *) port) >> 8) & 0xff;
57 +static inline void magicbox_ide_outb(u8 value, unsigned long port)
59 + writew(value << 8, (void __iomem *) port);
62 +static inline void magicbox_ide_insw(unsigned long port, void *addr, u32 count)
66 + for (ptr = addr; count--; ptr++)
67 + *ptr = readw((void __iomem *) port);
70 +static inline void magicbox_ide_insl(unsigned long port, void *addr, u32 count)
74 + for (ptr = addr; count--; ptr++)
75 + *ptr = readl((void __iomem *) port);
78 +static inline void magicbox_ide_outsw(unsigned long port, void *addr,
83 + for (ptr = addr; count--; ptr++)
84 + writew(*ptr, (void __iomem *) port);
87 +static inline void magicbox_ide_outsl(unsigned long port, void *addr,
92 + for (ptr = addr; count--; ptr++)
93 + writel(*ptr, (void __iomem *) port);
96 +static void magicbox_ide_exec_command(ide_hwif_t *hwif, u8 cmd)
98 + magicbox_ide_outb(cmd, hwif->io_ports.command_addr);
101 +static u8 magicbox_ide_read_status(ide_hwif_t *hwif)
103 + return magicbox_ide_inb(hwif->io_ports.status_addr);
106 +static u8 magicbox_ide_read_altstatus(ide_hwif_t *hwif)
108 + return magicbox_ide_inb(hwif->io_ports.ctl_addr);
111 +static void magicbox_ide_write_devctl(ide_hwif_t *hwif, u8 ctl)
113 + magicbox_ide_outb(ctl, hwif->io_ports.ctl_addr);
116 +static void magicbox_ide_tf_load(ide_drive_t *drive, struct ide_taskfile *tf,
119 + struct ide_io_ports *io_ports = &drive->hwif->io_ports;
121 + if (valid & IDE_VALID_FEATURE)
122 + magicbox_ide_outb(tf->feature, io_ports->feature_addr);
123 + if (valid & IDE_VALID_NSECT)
124 + magicbox_ide_outb(tf->nsect, io_ports->nsect_addr);
125 + if (valid & IDE_VALID_LBAL)
126 + magicbox_ide_outb(tf->lbal, io_ports->lbal_addr);
127 + if (valid & IDE_VALID_LBAM)
128 + magicbox_ide_outb(tf->lbam, io_ports->lbam_addr);
129 + if (valid & IDE_VALID_LBAH)
130 + magicbox_ide_outb(tf->lbah, io_ports->lbah_addr);
132 + if (valid & IDE_VALID_DEVICE)
133 + magicbox_ide_outb(tf->device, io_ports->device_addr);
136 +static void magicbox_ide_tf_read(ide_drive_t *drive, struct ide_taskfile *tf,
139 + struct ide_io_ports *io_ports = &drive->hwif->io_ports;
141 + if (valid & IDE_VALID_NSECT)
142 + tf->nsect = magicbox_ide_inb(io_ports->nsect_addr);
143 + if (valid & IDE_VALID_LBAL)
144 + tf->lbal = magicbox_ide_inb(io_ports->lbal_addr);
145 + if (valid & IDE_VALID_LBAM)
146 + tf->lbam = magicbox_ide_inb(io_ports->lbam_addr);
147 + if (valid & IDE_VALID_LBAH)
148 + tf->lbah = magicbox_ide_inb(io_ports->lbah_addr);
149 + if (valid & IDE_VALID_DEVICE)
150 + tf->device = magicbox_ide_inb(io_ports->device_addr);
153 +static void magicbox_ide_input_data(ide_drive_t *drive, struct ide_cmd *cmd,
154 + void *buf, unsigned int len)
156 + unsigned long port = drive->hwif->io_ports.data_addr;
160 + if (drive->io_32bit) {
161 + magicbox_ide_insl(port, buf, len / 4);
163 + if ((len & 3) >= 2)
164 + magicbox_ide_insw(port, (u8 *)buf + (len & ~3), 1);
166 + magicbox_ide_insw(port, buf, len / 2);
170 +static void magicbox_ide_output_data(ide_drive_t *drive, struct ide_cmd *cmd,
171 + void *buf, unsigned int len)
173 + unsigned long port = drive->hwif->io_ports.data_addr;
177 + if (drive->io_32bit) {
178 + magicbox_ide_outsl(port, buf, len / 4);
180 + if ((len & 3) >= 2)
181 + magicbox_ide_outsw(port, (u8 *)buf + (len & ~3), 1);
183 + magicbox_ide_outsw(port, buf, len / 2);
187 +static void magicbox_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
191 +static u8 magicbox_ide_cable_detect(ide_hwif_t *hwif)
193 + return ATA_CBL_PATA40;
196 +static const struct ide_tp_ops magicbox_ide_tp_ops = {
197 + .exec_command = magicbox_ide_exec_command,
198 + .read_status = magicbox_ide_read_status,
199 + .read_altstatus = magicbox_ide_read_altstatus,
200 + .write_devctl = magicbox_ide_write_devctl,
202 + .dev_select = ide_dev_select,
203 + .tf_load = magicbox_ide_tf_load,
204 + .tf_read = magicbox_ide_tf_read,
206 + .input_data = magicbox_ide_input_data,
207 + .output_data = magicbox_ide_output_data,
210 +static const struct ide_port_ops magicbox_ide_port_ops = {
211 + .set_pio_mode = magicbox_ide_set_pio_mode,
212 + .cable_detect = magicbox_ide_cable_detect,
215 +static const struct ide_port_info magicbox_ide_port_info = {
217 + .chipset = ide_generic,
218 + .tp_ops = &magicbox_ide_tp_ops,
219 + .port_ops = &magicbox_ide_port_ops,
220 + .host_flags = IDE_HFLAG_SINGLE |
223 + IDE_HFLAG_UNMASK_IRQS,
224 + .pio_mask = ATA_PIO4,
227 +static inline void magicbox_ide_setup_hw(hw_regs_t *hw, u16 __iomem *base,
228 + u16 __iomem *ctrl, int irq)
230 + unsigned long port = (unsigned long) base;
233 + memset(hw, 0, sizeof(*hw));
234 + for (i = 0; i <= 7; i++)
235 + hw->io_ports_array[i] = port + i * 2;
238 + * the IDE control register is at ATA address 6,
239 + * with CS1 active instead of CS0
241 + hw->io_ports.ctl_addr = (unsigned long)ctrl + (6 * 2);
244 +static int __devinit magicbox_ide_of_probe(struct of_device *op,
245 + const struct of_device_id *match)
248 + hw_regs_t *hws[] = { &hw, NULL, NULL, NULL };
249 + struct ide_host *host;
255 + irq = irq_of_parse_and_map(op->node, 0);
257 + dev_err(&op->dev, "invalid irq\n");
262 + base = of_iomap(op->node, 0);
263 + if (base == NULL) {
268 + ctrl = of_iomap(op->node, 1);
269 + if (ctrl == NULL) {
271 + goto err_unmap_base;
274 + magicbox_ide_setup_hw(&hw, base, ctrl, irq);
278 + hw.chipset = ide_generic;
279 + hw.ack_intr = NULL;
281 + ret = ide_host_add(&magicbox_ide_port_info, hws, &host);
283 + goto err_unmap_ctrl;
285 + dev_set_drvdata(&op->dev, host);
297 +static struct of_device_id magicbox_ide_of_match[] = {
298 + { .compatible = "magicbox-cf", },
302 +static struct of_platform_driver magicbox_ide_of_platform_driver = {
303 + .owner = THIS_MODULE,
305 + .match_table = magicbox_ide_of_match,
306 + .probe = magicbox_ide_of_probe,
309 + .owner = THIS_MODULE,
313 +static int __init magicbox_ide_init(void)
315 + return of_register_platform_driver(&magicbox_ide_of_platform_driver);
318 +module_init(magicbox_ide_init);
320 +MODULE_DESCRIPTION(DRV_DESC);
321 +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
322 +MODULE_LICENSE("GPL v2");
323 +MODULE_DEVICE_TABLE(of, magicbox_ide_of_match);