[ar8216] fixes breakage introduced in 776722ce36ac95877efb7fd771dde2f6ffc96433
[openwrt.git] / target / linux / ppc40x / patches / 101-pata-magicbox-cf-driver.patch
1 --- a/drivers/ata/Kconfig
2 +++ b/drivers/ata/Kconfig
3 @@ -144,6 +144,16 @@ config PDC_ADMA
4
5 If unsure, say N.
6
7 +config PATA_MAGICBOX_CF
8 + tristate "Magicbox/OpenRB Compact Flash support"
9 + depends on MAGICBOX || OPENRB
10 + help
11 + This option enables support for a Compact Flash conected on
12 + the ppc405ep expansion bus. This driver had been written for
13 + the Magicbox v2 and OpenRB boards.
14 +
15 + If unsure, say N.
16 +
17 config PATA_OCTEON_CF
18 tristate "OCTEON Boot Bus Compact Flash support"
19 depends on CPU_CAVIUM_OCTEON
20 --- a/drivers/ata/Makefile
21 +++ b/drivers/ata/Makefile
22 @@ -81,6 +81,7 @@ obj-$(CONFIG_PATA_AT91) += pata_at91.o
23 obj-$(CONFIG_PATA_CMD640_PCI) += pata_cmd640.o
24 obj-$(CONFIG_PATA_ISAPNP) += pata_isapnp.o
25 obj-$(CONFIG_PATA_IXP4XX_CF) += pata_ixp4xx_cf.o
26 +obj-$(CONFIG_PATA_MAGICBOX_CF) += pata_magicbox_cf.o
27 obj-$(CONFIG_PATA_MPIIX) += pata_mpiix.o
28 obj-$(CONFIG_PATA_NS87410) += pata_ns87410.o
29 obj-$(CONFIG_PATA_OPTI) += pata_opti.o
30 --- /dev/null
31 +++ b/drivers/ata/pata_magicbox_cf.c
32 @@ -0,0 +1,401 @@
33 +/*
34 + * PATA/CompactFlash driver for the MagicBox v2/OpenRB boards.
35 + *
36 + * Copyright (C) 2009,2012 Gabor Juhos <juhosg@openwrt.org>
37 + *
38 + * Based on the IDE driver by Wojtek Kaniewski <wojtekka@toxygen.net>
39 + *
40 + * This program is free software; you can redistribute it and/or modify it
41 + * under the terms of the GNU General Public License version 2 as published
42 + * by the Free Software Foundation.
43 + */
44 +
45 +#include <linux/kernel.h>
46 +#include <linux/module.h>
47 +#include <linux/slab.h>
48 +#include <linux/types.h>
49 +#include <linux/ioport.h>
50 +#include <linux/libata.h>
51 +#include <linux/irq.h>
52 +//#include <linux/of.h>
53 +//#include <linux/of_device.h>
54 +#include <linux/of_platform.h>
55 +#include <scsi/scsi_host.h>
56 +
57 +#define DRV_DESC "PATA/CompactFlash driver for Magicbox/OpenRB boards"
58 +#define DRV_NAME "pata_magicbox_cf"
59 +#define DRV_VERSION "0.1.0"
60 +
61 +#define MAGICBOX_CF_REG_CMD (2 * ATA_REG_CMD)
62 +#define MAGICBOX_CF_REG_DATA (2 * ATA_REG_DATA)
63 +#define MAGICBOX_CF_REG_ERR (2 * ATA_REG_ERR)
64 +#define MAGICBOX_CF_REG_FEATURE (2 * ATA_REG_FEATURE)
65 +#define MAGICBOX_CF_REG_NSECT (2 * ATA_REG_NSECT)
66 +#define MAGICBOX_CF_REG_LBAL (2 * ATA_REG_LBAL)
67 +#define MAGICBOX_CF_REG_LBAM (2 * ATA_REG_LBAM)
68 +#define MAGICBOX_CF_REG_LBAH (2 * ATA_REG_LBAH)
69 +#define MAGICBOX_CF_REG_DEVICE (2 * ATA_REG_DEVICE)
70 +#define MAGICBOX_CF_REG_STATUS (2 * ATA_REG_STATUS)
71 +#define MAGICBOX_CF_REG_ALTSTATUS (2 * 6)
72 +#define MAGICBOX_CF_REG_CTL (2 * 6)
73 +
74 +#define MAGICBOX_CF_MAXPORTS 1
75 +
76 +struct magicbox_cf_info {
77 + void __iomem *base;
78 + void __iomem *ctrl;
79 +};
80 +
81 +static inline u8 magicbox_cf_inb(void __iomem *port)
82 +{
83 + return (u8) (readw(port) >> 8) & 0xff;
84 +}
85 +
86 +static inline void magicbox_cf_outb(void __iomem *port, u8 value)
87 +{
88 + writew(value << 8, port);
89 +}
90 +
91 +static int magicbox_cf_set_mode(struct ata_link *link,
92 + struct ata_device **error)
93 +{
94 + struct ata_device *dev;
95 +
96 + ata_for_each_dev(dev, link, ENABLED) {
97 + ata_dev_printk(dev, KERN_INFO, "configured for PIO0\n");
98 + dev->pio_mode = XFER_PIO_0;
99 + dev->xfer_mode = XFER_PIO_0;
100 + dev->xfer_shift = ATA_SHIFT_PIO;
101 + dev->flags |= ATA_DFLAG_PIO;
102 + }
103 +
104 + return 0;
105 +}
106 +
107 +static void magicbox_cf_exec_command(struct ata_port *ap,
108 + const struct ata_taskfile *tf)
109 +{
110 + DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);
111 +
112 + magicbox_cf_outb(ap->ioaddr.command_addr, tf->command);
113 + ata_sff_pause(ap);
114 +}
115 +
116 +static u8 magicbox_cf_check_status(struct ata_port *ap)
117 +{
118 + u8 status;
119 +
120 + status = magicbox_cf_inb(ap->ioaddr.status_addr);
121 +
122 + DPRINTK("ata%u: status 0x%X, from %p\n", ap->print_id, status,
123 + ap->ioaddr.status_addr);
124 +
125 + return status;
126 +}
127 +
128 +static u8 magicbox_cf_check_altstatus(struct ata_port *ap)
129 +{
130 + u8 altstatus;
131 +
132 + altstatus = magicbox_cf_inb(ap->ioaddr.altstatus_addr);
133 +
134 + DPRINTK("ata%u: altstatus 0x%X, from %p\n", ap->print_id,
135 + altstatus, ap->ioaddr.altstatus_addr);
136 +
137 + return altstatus;
138 +}
139 +
140 +static void magicbox_cf_dev_select(struct ata_port *ap, unsigned int device)
141 +{
142 + /* Nothing to do. We are supporting one device only. */
143 +}
144 +
145 +static void magicbox_cf_tf_load(struct ata_port *ap,
146 + const struct ata_taskfile *tf)
147 +{
148 + struct ata_ioports *ioaddr = &ap->ioaddr;
149 + unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;
150 +
151 + if (tf->ctl != ap->last_ctl) {
152 + magicbox_cf_outb(ioaddr->ctl_addr, tf->ctl);
153 + ap->last_ctl = tf->ctl;
154 + ata_wait_idle(ap);
155 + }
156 +
157 + if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {
158 + magicbox_cf_outb(ioaddr->feature_addr, tf->hob_feature);
159 + magicbox_cf_outb(ioaddr->nsect_addr, tf->hob_nsect);
160 + magicbox_cf_outb(ioaddr->lbal_addr, tf->hob_lbal);
161 + magicbox_cf_outb(ioaddr->lbam_addr, tf->hob_lbam);
162 + magicbox_cf_outb(ioaddr->lbah_addr, tf->hob_lbah);
163 + VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",
164 + tf->hob_feature,
165 + tf->hob_nsect,
166 + tf->hob_lbal,
167 + tf->hob_lbam,
168 + tf->hob_lbah);
169 + }
170 +
171 + if (is_addr) {
172 + magicbox_cf_outb(ioaddr->feature_addr, tf->feature);
173 + magicbox_cf_outb(ioaddr->nsect_addr, tf->nsect);
174 + magicbox_cf_outb(ioaddr->lbal_addr, tf->lbal);
175 + magicbox_cf_outb(ioaddr->lbam_addr, tf->lbam);
176 + magicbox_cf_outb(ioaddr->lbah_addr, tf->lbah);
177 + VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
178 + tf->feature,
179 + tf->nsect,
180 + tf->lbal,
181 + tf->lbam,
182 + tf->lbah);
183 + }
184 +
185 + if (tf->flags & ATA_TFLAG_DEVICE) {
186 + magicbox_cf_outb(ioaddr->device_addr, tf->device);
187 + VPRINTK("device 0x%X\n", tf->device);
188 + }
189 +
190 + ata_wait_idle(ap);
191 +}
192 +
193 +static void magicbox_cf_tf_read(struct ata_port *ap, struct ata_taskfile *tf)
194 +{
195 + struct ata_ioports *ioaddr = &ap->ioaddr;
196 +
197 + tf->command = magicbox_cf_inb(ap->ioaddr.status_addr);
198 + tf->feature = magicbox_cf_inb(ioaddr->error_addr);
199 + tf->nsect = magicbox_cf_inb(ioaddr->nsect_addr);
200 + tf->lbal = magicbox_cf_inb(ioaddr->lbal_addr);
201 + tf->lbam = magicbox_cf_inb(ioaddr->lbam_addr);
202 + tf->lbah = magicbox_cf_inb(ioaddr->lbah_addr);
203 + tf->device = magicbox_cf_inb(ioaddr->device_addr);
204 + VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
205 + tf->feature,
206 + tf->nsect,
207 + tf->lbal,
208 + tf->lbam,
209 + tf->lbah);
210 +
211 + if (tf->flags & ATA_TFLAG_LBA48) {
212 + magicbox_cf_outb(ioaddr->ctl_addr, tf->ctl | ATA_HOB);
213 + tf->hob_feature = magicbox_cf_inb(ioaddr->error_addr);
214 + tf->hob_nsect = magicbox_cf_inb(ioaddr->nsect_addr);
215 + tf->hob_lbal = magicbox_cf_inb(ioaddr->lbal_addr);
216 + tf->hob_lbam = magicbox_cf_inb(ioaddr->lbam_addr);
217 + tf->hob_lbah = magicbox_cf_inb(ioaddr->lbah_addr);
218 + magicbox_cf_outb(ioaddr->ctl_addr, tf->ctl);
219 + ap->last_ctl = tf->ctl;
220 + VPRINTK("hob: feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",
221 + tf->feature,
222 + tf->nsect,
223 + tf->lbal,
224 + tf->lbam,
225 + tf->lbah);
226 + }
227 +}
228 +
229 +static unsigned int magicbox_cf_data_xfer(struct ata_device *dev,
230 + unsigned char *buf,
231 + unsigned int buflen, int rw)
232 +{
233 + struct ata_port *ap = dev->link->ap;
234 + unsigned int words = buflen >> 1;
235 + unsigned int i;
236 + u16 *buf16 = (u16 *) buf;
237 + void __iomem *mmio = ap->ioaddr.data_addr;
238 +
239 + /* Transfer multiple of 2 bytes */
240 + if (rw == READ)
241 + for (i = 0; i < words; i++)
242 + buf16[i] = readw(mmio);
243 + else
244 + for (i = 0; i < words; i++)
245 + writew(buf16[i], mmio);
246 +
247 + /* Transfer trailing 1 byte, if any. */
248 + if (unlikely(buflen & 0x01)) {
249 + u16 align_buf[1] = { 0 };
250 + unsigned char *trailing_buf = buf + buflen - 1;
251 +
252 + if (rw == READ) {
253 + align_buf[0] = readw(mmio);
254 + memcpy(trailing_buf, align_buf, 1);
255 + } else {
256 + memcpy(align_buf, trailing_buf, 1);
257 + writew(align_buf[0], mmio);
258 + }
259 + words++;
260 + }
261 +
262 + return words << 1;
263 +}
264 +
265 +static void magicbox_cf_irq_on(struct ata_port *ap)
266 +{
267 + /* Nothing to do. */
268 +}
269 +
270 +static void magicbox_cf_irq_clear(struct ata_port *ap)
271 +{
272 + /* Nothing to do. */
273 +}
274 +
275 +static struct ata_port_operations magicbox_cf_port_ops = {
276 + .inherits = &ata_sff_port_ops,
277 +
278 + .cable_detect = ata_cable_40wire,
279 + .set_mode = magicbox_cf_set_mode,
280 +
281 + .sff_exec_command = magicbox_cf_exec_command,
282 + .sff_check_status = magicbox_cf_check_status,
283 + .sff_check_altstatus = magicbox_cf_check_altstatus,
284 + .sff_dev_select = magicbox_cf_dev_select,
285 + .sff_tf_load = magicbox_cf_tf_load,
286 + .sff_tf_read = magicbox_cf_tf_read,
287 + .sff_data_xfer = magicbox_cf_data_xfer,
288 +
289 + .sff_irq_on = magicbox_cf_irq_on,
290 + .sff_irq_clear = magicbox_cf_irq_clear,
291 +
292 + .port_start = ATA_OP_NULL,
293 +};
294 +
295 +static struct scsi_host_template magicbox_cf_sht = {
296 + ATA_PIO_SHT(DRV_NAME),
297 +};
298 +
299 +static inline void magicbox_cf_setup_port(struct ata_host *host)
300 +{
301 + struct magicbox_cf_info *info = host->private_data;
302 + struct ata_port *ap;
303 +
304 + ap = host->ports[0];
305 +
306 + ap->ops = &magicbox_cf_port_ops;
307 + ap->pio_mask = ATA_PIO4;
308 + ap->flags |= ATA_FLAG_NO_ATAPI;
309 +
310 + ap->ioaddr.cmd_addr = info->base + MAGICBOX_CF_REG_CMD;
311 + ap->ioaddr.data_addr = info->base + MAGICBOX_CF_REG_DATA;
312 + ap->ioaddr.error_addr = info->base + MAGICBOX_CF_REG_ERR;
313 + ap->ioaddr.feature_addr = info->base + MAGICBOX_CF_REG_FEATURE;
314 + ap->ioaddr.nsect_addr = info->base + MAGICBOX_CF_REG_NSECT;
315 + ap->ioaddr.lbal_addr = info->base + MAGICBOX_CF_REG_LBAL;
316 + ap->ioaddr.lbam_addr = info->base + MAGICBOX_CF_REG_LBAM;
317 + ap->ioaddr.lbah_addr = info->base + MAGICBOX_CF_REG_LBAH;
318 + ap->ioaddr.device_addr = info->base + MAGICBOX_CF_REG_DEVICE;
319 + ap->ioaddr.status_addr = info->base + MAGICBOX_CF_REG_STATUS;
320 + ap->ioaddr.command_addr = info->base + MAGICBOX_CF_REG_CMD;
321 +
322 + ap->ioaddr.altstatus_addr = info->ctrl + MAGICBOX_CF_REG_ALTSTATUS;
323 + ap->ioaddr.ctl_addr = info->ctrl + MAGICBOX_CF_REG_CTL;
324 +
325 + ata_port_desc(ap, "cmd 0x%p ctl 0x%p", ap->ioaddr.cmd_addr,
326 + ap->ioaddr.ctl_addr);
327 +}
328 +
329 +static int __devinit magicbox_cf_of_probe(struct platform_device *op)
330 +{
331 + struct magicbox_cf_info *info;
332 + struct ata_host *host;
333 + int irq;
334 + int ret = 0;
335 +
336 + info = kzalloc(sizeof(struct magicbox_cf_info), GFP_KERNEL);
337 + if (info == NULL) {
338 + ret = -ENOMEM;
339 + goto err_exit;
340 + }
341 +
342 + irq = irq_of_parse_and_map(op->dev.of_node, 0);
343 + if (irq < 0) {
344 + dev_err(&op->dev, "invalid irq\n");
345 + ret = -EINVAL;
346 + goto err_free_info;
347 + }
348 +
349 + info->base = of_iomap(op->dev.of_node, 0);
350 + if (info->base == NULL) {
351 + ret = -ENOMEM;
352 + goto err_free_info;
353 + }
354 +
355 + info->ctrl = of_iomap(op->dev.of_node, 1);
356 + if (info->ctrl == NULL) {
357 + ret = -ENOMEM;
358 + goto err_unmap_base;
359 + }
360 +
361 + host = ata_host_alloc(&op->dev, MAGICBOX_CF_MAXPORTS);
362 + if (host == NULL) {
363 + ret = -ENOMEM;
364 + goto err_unmap_ctrl;
365 + }
366 +
367 + host->private_data = info;
368 + magicbox_cf_setup_port(host);
369 +
370 + ret = ata_host_activate(host, irq, ata_sff_interrupt,
371 + IRQF_TRIGGER_RISING, &magicbox_cf_sht);
372 + if (ret)
373 + goto err_unmap_ctrl;
374 +
375 + dev_set_drvdata(&op->dev, host);
376 + return 0;
377 +
378 + err_unmap_ctrl:
379 + iounmap(info->ctrl);
380 + err_unmap_base:
381 + iounmap(info->base);
382 + err_free_info:
383 + kfree(info);
384 + err_exit:
385 + return ret;
386 +}
387 +
388 +static __devexit int magicbox_cf_of_remove(struct platform_device *op)
389 +{
390 + struct ata_host *host = dev_get_drvdata(&op->dev);
391 + struct magicbox_cf_info *info = host->private_data;
392 +
393 + ata_host_detach(host);
394 + iounmap(info->ctrl);
395 + iounmap(info->base);
396 + kfree(info);
397 +
398 + return 0;
399 +}
400 +
401 +static struct of_device_id magicbox_cf_of_match[] = {
402 + { .compatible = "pata-magicbox-cf", },
403 + {},
404 +};
405 +
406 +static struct platform_driver magicbox_cf_of_platform_driver = {
407 + .probe = magicbox_cf_of_probe,
408 + .remove = __devexit_p(magicbox_cf_of_remove),
409 + .driver = {
410 + .name = DRV_NAME,
411 + .owner = THIS_MODULE,
412 + .of_match_table = magicbox_cf_of_match,
413 + },
414 +};
415 +
416 +static int __init magicbox_cf_init(void)
417 +{
418 + return platform_driver_register(&magicbox_cf_of_platform_driver);
419 +}
420 +
421 +static void __exit magicbox_cf_exit(void)
422 +{
423 + platform_driver_unregister(&magicbox_cf_of_platform_driver);
424 +}
425 +
426 +module_init(magicbox_cf_init);
427 +module_exit(magicbox_cf_exit);
428 +
429 +MODULE_DESCRIPTION(DRV_DESC);
430 +MODULE_AUTHOR("Gabor Juhos <juhosg@openwrt.org>");
431 +MODULE_LICENSE("GPL v2");
432 +MODULE_VERSION(DRV_VERSION);
433 +MODULE_DEVICE_TABLE(of, magicbox_cf_of_match);
This page took 0.05943 seconds and 5 git commands to generate.