1 // SPDX-License-Identifier: GPL-2.0
4 * Amiga Gayle PATA controller driver
6 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * http://www.samsung.com
11 * Created 12 Jul 1997 by Geert Uytterhoeven
14 #include <linux/ata.h>
15 #include <linux/blkdev.h>
16 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/libata.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/zorro.h>
24 #include <scsi/scsi_cmnd.h>
25 #include <scsi/scsi_host.h>
27 #include <asm/amigahw.h>
28 #include <asm/amigaints.h>
29 #include <asm/amigayle.h>
30 #include <asm/setup.h>
32 #define DRV_NAME "pata_gayle"
33 #define DRV_VERSION "0.1.0"
35 #define GAYLE_CONTROL 0x101a
37 static const struct scsi_host_template pata_gayle_sht = {
38 ATA_PIO_SHT(DRV_NAME),
41 /* FIXME: is this needed? */
42 static unsigned int pata_gayle_data_xfer(struct ata_queued_cmd *qc,
44 unsigned int buflen, int rw)
46 struct ata_device *dev = qc->dev;
47 struct ata_port *ap = dev->link->ap;
48 void __iomem *data_addr = ap->ioaddr.data_addr;
49 unsigned int words = buflen >> 1;
51 /* Transfer multiple of 2 bytes */
53 raw_insw((u16 *)data_addr, (u16 *)buf, words);
55 raw_outsw((u16 *)data_addr, (u16 *)buf, words);
57 /* Transfer trailing byte, if any. */
58 if (unlikely(buflen & 0x01)) {
59 unsigned char pad[2] = { };
61 /* Point buf to the tail of buffer */
65 raw_insw((u16 *)data_addr, (u16 *)pad, 1);
69 raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
78 * Provide our own set_mode() as we don't want to change anything that has
79 * already been configured..
81 static int pata_gayle_set_mode(struct ata_link *link,
82 struct ata_device **unused)
84 struct ata_device *dev;
86 ata_for_each_dev(dev, link, ENABLED) {
87 /* We don't really care */
88 dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
89 dev->xfer_shift = ATA_SHIFT_PIO;
90 dev->flags |= ATA_DFLAG_PIO;
91 ata_dev_info(dev, "configured for PIO\n");
96 static bool pata_gayle_irq_check(struct ata_port *ap)
100 ch = z_readb((unsigned long)ap->private_data);
102 return !!(ch & GAYLE_IRQ_IDE);
105 static void pata_gayle_irq_clear(struct ata_port *ap)
107 (void)z_readb((unsigned long)ap->ioaddr.status_addr);
108 z_writeb(0x7c, (unsigned long)ap->private_data);
111 static struct ata_port_operations pata_gayle_a1200_ops = {
112 .inherits = &ata_sff_port_ops,
113 .sff_data_xfer = pata_gayle_data_xfer,
114 .sff_irq_check = pata_gayle_irq_check,
115 .sff_irq_clear = pata_gayle_irq_clear,
116 .cable_detect = ata_cable_unknown,
117 .set_mode = pata_gayle_set_mode,
120 static struct ata_port_operations pata_gayle_a4000_ops = {
121 .inherits = &ata_sff_port_ops,
122 .sff_data_xfer = pata_gayle_data_xfer,
123 .cable_detect = ata_cable_unknown,
124 .set_mode = pata_gayle_set_mode,
127 static int __init pata_gayle_init_one(struct platform_device *pdev)
129 struct resource *res;
130 struct gayle_ide_platform_data *pdata;
131 struct ata_host *host;
136 pdata = dev_get_platdata(&pdev->dev);
138 dev_info(&pdev->dev, "Amiga Gayle IDE controller (A%u style)\n",
139 pdata->explicit_ack ? 1200 : 4000);
141 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
145 if (!devm_request_mem_region(&pdev->dev, res->start,
146 resource_size(res), DRV_NAME)) {
147 pr_err(DRV_NAME ": resources busy\n");
152 host = ata_host_alloc(&pdev->dev, 1);
158 if (pdata->explicit_ack)
159 ap->ops = &pata_gayle_a1200_ops;
161 ap->ops = &pata_gayle_a4000_ops;
163 ap->pio_mask = ATA_PIO4;
164 ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
166 base = ZTWO_VADDR(pdata->base);
167 ap->ioaddr.data_addr = base;
168 ap->ioaddr.error_addr = base + 2 + 1 * 4;
169 ap->ioaddr.feature_addr = base + 2 + 1 * 4;
170 ap->ioaddr.nsect_addr = base + 2 + 2 * 4;
171 ap->ioaddr.lbal_addr = base + 2 + 3 * 4;
172 ap->ioaddr.lbam_addr = base + 2 + 4 * 4;
173 ap->ioaddr.lbah_addr = base + 2 + 5 * 4;
174 ap->ioaddr.device_addr = base + 2 + 6 * 4;
175 ap->ioaddr.status_addr = base + 2 + 7 * 4;
176 ap->ioaddr.command_addr = base + 2 + 7 * 4;
178 ap->ioaddr.altstatus_addr = base + GAYLE_CONTROL;
179 ap->ioaddr.ctl_addr = base + GAYLE_CONTROL;
181 ap->private_data = (void *)ZTWO_VADDR(pdata->irqport);
183 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", pdata->base,
184 pdata->base + GAYLE_CONTROL);
186 ret = ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
187 IRQF_SHARED, &pata_gayle_sht);
191 platform_set_drvdata(pdev, host);
196 static int __exit pata_gayle_remove_one(struct platform_device *pdev)
198 struct ata_host *host = platform_get_drvdata(pdev);
200 ata_host_detach(host);
205 static struct platform_driver pata_gayle_driver = {
206 .remove = __exit_p(pata_gayle_remove_one),
208 .name = "amiga-gayle-ide",
212 module_platform_driver_probe(pata_gayle_driver, pata_gayle_init_one);
214 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
215 MODULE_DESCRIPTION("low-level driver for Amiga Gayle PATA");
216 MODULE_LICENSE("GPL v2");
217 MODULE_ALIAS("platform:amiga-gayle-ide");
218 MODULE_VERSION(DRV_VERSION);