^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Atari Falcon PATA controller driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2016 Samsung Electronics Co., Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * http://www.samsung.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Based on falconide.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Created 12 Jul 1997 by Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <scsi/scsi_cmnd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/ata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/libata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <asm/atarihw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <asm/atariints.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/atari_stdma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <asm/ide.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define DRV_NAME "pata_falcon"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define DRV_VERSION "0.1.0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define ATA_HD_CONTROL 0x39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) static struct scsi_host_template pata_falcon_sht = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) ATA_PIO_SHT(DRV_NAME),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int buflen, int rw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct ata_device *dev = qc->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct ata_port *ap = dev->link->ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) void __iomem *data_addr = ap->ioaddr.data_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int words = buflen >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct scsi_cmnd *cmd = qc->scsicmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) bool swap = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (dev->class == ATA_DEV_ATA && cmd && cmd->request &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) !blk_rq_is_passthrough(cmd->request))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) swap = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Transfer multiple of 2 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (rw == READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (swap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) raw_insw_swapw((u16 *)data_addr, (u16 *)buf, words);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) raw_insw((u16 *)data_addr, (u16 *)buf, words);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (swap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) raw_outsw_swapw((u16 *)data_addr, (u16 *)buf, words);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) raw_outsw((u16 *)data_addr, (u16 *)buf, words);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* Transfer trailing byte, if any. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (unlikely(buflen & 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned char pad[2] = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Point buf to the tail of buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) buf += buflen - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (rw == READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (swap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) raw_insw_swapw((u16 *)data_addr, (u16 *)pad, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) raw_insw((u16 *)data_addr, (u16 *)pad, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) *buf = pad[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) pad[0] = *buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (swap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) raw_outsw_swapw((u16 *)data_addr, (u16 *)pad, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) words++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return words << 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * Provide our own set_mode() as we don't want to change anything that has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * already been configured..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int pata_falcon_set_mode(struct ata_link *link,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct ata_device **unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) struct ata_device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) ata_for_each_dev(dev, link, ENABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /* We don't really care */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) dev->xfer_shift = ATA_SHIFT_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dev->flags |= ATA_DFLAG_PIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) ata_dev_info(dev, "configured for PIO\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static struct ata_port_operations pata_falcon_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .inherits = &ata_sff_port_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .sff_data_xfer = pata_falcon_data_xfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .cable_detect = ata_cable_unknown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .set_mode = pata_falcon_set_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int __init pata_falcon_init_one(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct ata_host *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct ata_port *ap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) dev_info(&pdev->dev, "Atari Falcon PATA controller\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (!res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) if (!devm_request_mem_region(&pdev->dev, res->start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) resource_size(res), DRV_NAME)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) dev_err(&pdev->dev, "resources busy\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /* allocate host */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) host = ata_host_alloc(&pdev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) ap = host->ports[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) ap->ops = &pata_falcon_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) ap->pio_mask = ATA_PIO4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ap->flags |= ATA_FLAG_PIO_POLLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) base = (void __iomem *)res->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ap->ioaddr.data_addr = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ap->ioaddr.error_addr = base + 1 + 1 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) ap->ioaddr.feature_addr = base + 1 + 1 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) ap->ioaddr.nsect_addr = base + 1 + 2 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) ap->ioaddr.lbal_addr = base + 1 + 3 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ap->ioaddr.lbam_addr = base + 1 + 4 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) ap->ioaddr.lbah_addr = base + 1 + 5 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) ap->ioaddr.device_addr = base + 1 + 6 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) ap->ioaddr.status_addr = base + 1 + 7 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) ap->ioaddr.command_addr = base + 1 + 7 * 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) ap->ioaddr.altstatus_addr = base + ATA_HD_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ap->ioaddr.ctl_addr = base + ATA_HD_CONTROL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", (unsigned long)base,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) (unsigned long)base + ATA_HD_CONTROL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* activate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) return ata_host_activate(host, 0, NULL, 0, &pata_falcon_sht);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) static int __exit pata_falcon_remove_one(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct ata_host *host = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) ata_host_detach(host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static struct platform_driver pata_falcon_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .remove = __exit_p(pata_falcon_remove_one),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) .name = "atari-falcon-ide",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) module_platform_driver_probe(pata_falcon_driver, pata_falcon_init_one);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) MODULE_ALIAS("platform:atari-falcon-ide");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) MODULE_VERSION(DRV_VERSION);