Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 /*
0004  * Atari Falcon PATA controller driver
0005  *
0006  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
0007  *      http://www.samsung.com
0008  *
0009  * Based on falconide.c:
0010  *
0011  *     Created 12 Jul 1997 by Geert Uytterhoeven
0012  */
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/module.h>
0016 #include <linux/init.h>
0017 #include <linux/blkdev.h>
0018 #include <linux/delay.h>
0019 #include <scsi/scsi_host.h>
0020 #include <scsi/scsi_cmnd.h>
0021 #include <linux/ata.h>
0022 #include <linux/libata.h>
0023 #include <linux/mm.h>
0024 #include <linux/interrupt.h>
0025 #include <linux/platform_device.h>
0026 
0027 #include <asm/setup.h>
0028 #include <asm/atarihw.h>
0029 #include <asm/atariints.h>
0030 #include <asm/atari_stdma.h>
0031 #include <asm/ide.h>
0032 
0033 #define DRV_NAME "pata_falcon"
0034 #define DRV_VERSION "0.1.0"
0035 
0036 static struct scsi_host_template pata_falcon_sht = {
0037     ATA_PIO_SHT(DRV_NAME),
0038 };
0039 
0040 static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
0041                       unsigned char *buf,
0042                       unsigned int buflen, int rw)
0043 {
0044     struct ata_device *dev = qc->dev;
0045     struct ata_port *ap = dev->link->ap;
0046     void __iomem *data_addr = ap->ioaddr.data_addr;
0047     unsigned int words = buflen >> 1;
0048     struct scsi_cmnd *cmd = qc->scsicmd;
0049     bool swap = 1;
0050 
0051     if (dev->class == ATA_DEV_ATA && cmd &&
0052         !blk_rq_is_passthrough(scsi_cmd_to_rq(cmd)))
0053         swap = 0;
0054 
0055     /* Transfer multiple of 2 bytes */
0056     if (rw == READ) {
0057         if (swap)
0058             raw_insw_swapw(data_addr, (u16 *)buf, words);
0059         else
0060             raw_insw(data_addr, (u16 *)buf, words);
0061     } else {
0062         if (swap)
0063             raw_outsw_swapw(data_addr, (u16 *)buf, words);
0064         else
0065             raw_outsw(data_addr, (u16 *)buf, words);
0066     }
0067 
0068     /* Transfer trailing byte, if any. */
0069     if (unlikely(buflen & 0x01)) {
0070         unsigned char pad[2] = { };
0071 
0072         /* Point buf to the tail of buffer */
0073         buf += buflen - 1;
0074 
0075         if (rw == READ) {
0076             if (swap)
0077                 raw_insw_swapw(data_addr, (u16 *)pad, 1);
0078             else
0079                 raw_insw(data_addr, (u16 *)pad, 1);
0080             *buf = pad[0];
0081         } else {
0082             pad[0] = *buf;
0083             if (swap)
0084                 raw_outsw_swapw(data_addr, (u16 *)pad, 1);
0085             else
0086                 raw_outsw(data_addr, (u16 *)pad, 1);
0087         }
0088         words++;
0089     }
0090 
0091     return words << 1;
0092 }
0093 
0094 /*
0095  * Provide our own set_mode() as we don't want to change anything that has
0096  * already been configured..
0097  */
0098 static int pata_falcon_set_mode(struct ata_link *link,
0099                 struct ata_device **unused)
0100 {
0101     struct ata_device *dev;
0102 
0103     ata_for_each_dev(dev, link, ENABLED) {
0104         /* We don't really care */
0105         dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
0106         dev->xfer_shift = ATA_SHIFT_PIO;
0107         dev->flags |= ATA_DFLAG_PIO;
0108         ata_dev_info(dev, "configured for PIO\n");
0109     }
0110     return 0;
0111 }
0112 
0113 static struct ata_port_operations pata_falcon_ops = {
0114     .inherits   = &ata_sff_port_ops,
0115     .sff_data_xfer  = pata_falcon_data_xfer,
0116     .cable_detect   = ata_cable_unknown,
0117     .set_mode   = pata_falcon_set_mode,
0118 };
0119 
0120 static int __init pata_falcon_init_one(struct platform_device *pdev)
0121 {
0122     struct resource *base_mem_res, *ctl_mem_res;
0123     struct resource *base_res, *ctl_res, *irq_res;
0124     struct ata_host *host;
0125     struct ata_port *ap;
0126     void __iomem *base;
0127     int irq = 0;
0128 
0129     dev_info(&pdev->dev, "Atari Falcon and Q40/Q60 PATA controller\n");
0130 
0131     base_res = platform_get_resource(pdev, IORESOURCE_IO, 0);
0132     if (base_res && !devm_request_region(&pdev->dev, base_res->start,
0133                        resource_size(base_res), DRV_NAME)) {
0134         dev_err(&pdev->dev, "resources busy\n");
0135         return -EBUSY;
0136     }
0137 
0138     ctl_res = platform_get_resource(pdev, IORESOURCE_IO, 1);
0139     if (ctl_res && !devm_request_region(&pdev->dev, ctl_res->start,
0140                         resource_size(ctl_res), DRV_NAME)) {
0141         dev_err(&pdev->dev, "resources busy\n");
0142         return -EBUSY;
0143     }
0144 
0145     base_mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0146     if (!base_mem_res)
0147         return -ENODEV;
0148     if (!devm_request_mem_region(&pdev->dev, base_mem_res->start,
0149                      resource_size(base_mem_res), DRV_NAME)) {
0150         dev_err(&pdev->dev, "resources busy\n");
0151         return -EBUSY;
0152     }
0153 
0154     ctl_mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
0155     if (!ctl_mem_res)
0156         return -ENODEV;
0157 
0158     /* allocate host */
0159     host = ata_host_alloc(&pdev->dev, 1);
0160     if (!host)
0161         return -ENOMEM;
0162     ap = host->ports[0];
0163 
0164     ap->ops = &pata_falcon_ops;
0165     ap->pio_mask = ATA_PIO4;
0166     ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
0167 
0168     base = (void __iomem *)base_mem_res->start;
0169     /* N.B. this assumes data_addr will be used for word-sized I/O only */
0170     ap->ioaddr.data_addr        = base + 0 + 0 * 4;
0171     ap->ioaddr.error_addr       = base + 1 + 1 * 4;
0172     ap->ioaddr.feature_addr     = base + 1 + 1 * 4;
0173     ap->ioaddr.nsect_addr       = base + 1 + 2 * 4;
0174     ap->ioaddr.lbal_addr        = base + 1 + 3 * 4;
0175     ap->ioaddr.lbam_addr        = base + 1 + 4 * 4;
0176     ap->ioaddr.lbah_addr        = base + 1 + 5 * 4;
0177     ap->ioaddr.device_addr      = base + 1 + 6 * 4;
0178     ap->ioaddr.status_addr      = base + 1 + 7 * 4;
0179     ap->ioaddr.command_addr     = base + 1 + 7 * 4;
0180 
0181     base = (void __iomem *)ctl_mem_res->start;
0182     ap->ioaddr.altstatus_addr   = base + 1;
0183     ap->ioaddr.ctl_addr     = base + 1;
0184 
0185     ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx",
0186               (unsigned long)base_mem_res->start,
0187               (unsigned long)ctl_mem_res->start);
0188 
0189     irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
0190     if (irq_res && irq_res->start > 0) {
0191         irq = irq_res->start;
0192     } else {
0193         ap->flags |= ATA_FLAG_PIO_POLLING;
0194         ata_port_desc(ap, "no IRQ, using PIO polling");
0195     }
0196 
0197     /* activate */
0198     return ata_host_activate(host, irq, irq ? ata_sff_interrupt : NULL,
0199                  IRQF_SHARED, &pata_falcon_sht);
0200 }
0201 
0202 static int __exit pata_falcon_remove_one(struct platform_device *pdev)
0203 {
0204     struct ata_host *host = platform_get_drvdata(pdev);
0205 
0206     ata_host_detach(host);
0207 
0208     return 0;
0209 }
0210 
0211 static struct platform_driver pata_falcon_driver = {
0212     .remove = __exit_p(pata_falcon_remove_one),
0213     .driver   = {
0214         .name   = "atari-falcon-ide",
0215     },
0216 };
0217 
0218 module_platform_driver_probe(pata_falcon_driver, pata_falcon_init_one);
0219 
0220 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
0221 MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
0222 MODULE_LICENSE("GPL v2");
0223 MODULE_ALIAS("platform:atari-falcon-ide");
0224 MODULE_VERSION(DRV_VERSION);