net: DCB: Validate DCB_ATTR_DCB_BUFFER argument
[linux/fpc-iii.git] / drivers / ata / pata_falcon.c
blob41e0d6a6cd05fa13cca3fc8c81166ce9c1c94789
1 // SPDX-License-Identifier: GPL-2.0
3 /*
4 * Atari Falcon PATA controller driver
6 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
7 * http://www.samsung.com
9 * Based on falconide.c:
11 * Created 12 Jul 1997 by Geert Uytterhoeven
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/blkdev.h>
18 #include <linux/delay.h>
19 #include <scsi/scsi_host.h>
20 #include <scsi/scsi_cmnd.h>
21 #include <linux/ata.h>
22 #include <linux/libata.h>
23 #include <linux/mm.h>
24 #include <linux/interrupt.h>
25 #include <linux/platform_device.h>
27 #include <asm/setup.h>
28 #include <asm/atarihw.h>
29 #include <asm/atariints.h>
30 #include <asm/atari_stdma.h>
31 #include <asm/ide.h>
33 #define DRV_NAME "pata_falcon"
34 #define DRV_VERSION "0.1.0"
36 #define ATA_HD_BASE 0xfff00000
37 #define ATA_HD_CONTROL 0x39
39 static struct scsi_host_template pata_falcon_sht = {
40 ATA_PIO_SHT(DRV_NAME),
43 static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
44 unsigned char *buf,
45 unsigned int buflen, int rw)
47 struct ata_device *dev = qc->dev;
48 struct ata_port *ap = dev->link->ap;
49 void __iomem *data_addr = ap->ioaddr.data_addr;
50 unsigned int words = buflen >> 1;
51 struct scsi_cmnd *cmd = qc->scsicmd;
52 bool swap = 1;
54 if (dev->class == ATA_DEV_ATA && cmd && cmd->request &&
55 !blk_rq_is_passthrough(cmd->request))
56 swap = 0;
58 /* Transfer multiple of 2 bytes */
59 if (rw == READ) {
60 if (swap)
61 raw_insw_swapw((u16 *)data_addr, (u16 *)buf, words);
62 else
63 raw_insw((u16 *)data_addr, (u16 *)buf, words);
64 } else {
65 if (swap)
66 raw_outsw_swapw((u16 *)data_addr, (u16 *)buf, words);
67 else
68 raw_outsw((u16 *)data_addr, (u16 *)buf, words);
71 /* Transfer trailing byte, if any. */
72 if (unlikely(buflen & 0x01)) {
73 unsigned char pad[2] = { };
75 /* Point buf to the tail of buffer */
76 buf += buflen - 1;
78 if (rw == READ) {
79 if (swap)
80 raw_insw_swapw((u16 *)data_addr, (u16 *)pad, 1);
81 else
82 raw_insw((u16 *)data_addr, (u16 *)pad, 1);
83 *buf = pad[0];
84 } else {
85 pad[0] = *buf;
86 if (swap)
87 raw_outsw_swapw((u16 *)data_addr, (u16 *)pad, 1);
88 else
89 raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
91 words++;
94 return words << 1;
98 * Provide our own set_mode() as we don't want to change anything that has
99 * already been configured..
101 static int pata_falcon_set_mode(struct ata_link *link,
102 struct ata_device **unused)
104 struct ata_device *dev;
106 ata_for_each_dev(dev, link, ENABLED) {
107 /* We don't really care */
108 dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
109 dev->xfer_shift = ATA_SHIFT_PIO;
110 dev->flags |= ATA_DFLAG_PIO;
111 ata_dev_info(dev, "configured for PIO\n");
113 return 0;
116 static struct ata_port_operations pata_falcon_ops = {
117 .inherits = &ata_sff_port_ops,
118 .sff_data_xfer = pata_falcon_data_xfer,
119 .cable_detect = ata_cable_unknown,
120 .set_mode = pata_falcon_set_mode,
123 static int pata_falcon_init_one(void)
125 struct ata_host *host;
126 struct ata_port *ap;
127 struct platform_device *pdev;
128 void __iomem *base;
130 if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
131 return -ENODEV;
133 pr_info(DRV_NAME ": Atari Falcon PATA controller\n");
135 pdev = platform_device_register_simple(DRV_NAME, 0, NULL, 0);
136 if (IS_ERR(pdev))
137 return PTR_ERR(pdev);
139 if (!devm_request_mem_region(&pdev->dev, ATA_HD_BASE, 0x40, DRV_NAME)) {
140 pr_err(DRV_NAME ": resources busy\n");
141 return -EBUSY;
144 /* allocate host */
145 host = ata_host_alloc(&pdev->dev, 1);
146 if (!host)
147 return -ENOMEM;
148 ap = host->ports[0];
150 ap->ops = &pata_falcon_ops;
151 ap->pio_mask = ATA_PIO4;
152 ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
153 ap->flags |= ATA_FLAG_PIO_POLLING;
155 base = (void __iomem *)ATA_HD_BASE;
156 ap->ioaddr.data_addr = base;
157 ap->ioaddr.error_addr = base + 1 + 1 * 4;
158 ap->ioaddr.feature_addr = base + 1 + 1 * 4;
159 ap->ioaddr.nsect_addr = base + 1 + 2 * 4;
160 ap->ioaddr.lbal_addr = base + 1 + 3 * 4;
161 ap->ioaddr.lbam_addr = base + 1 + 4 * 4;
162 ap->ioaddr.lbah_addr = base + 1 + 5 * 4;
163 ap->ioaddr.device_addr = base + 1 + 6 * 4;
164 ap->ioaddr.status_addr = base + 1 + 7 * 4;
165 ap->ioaddr.command_addr = base + 1 + 7 * 4;
167 ap->ioaddr.altstatus_addr = base + ATA_HD_CONTROL;
168 ap->ioaddr.ctl_addr = base + ATA_HD_CONTROL;
170 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", (unsigned long)base,
171 (unsigned long)base + ATA_HD_CONTROL);
173 /* activate */
174 return ata_host_activate(host, 0, NULL, 0, &pata_falcon_sht);
177 module_init(pata_falcon_init_one);
179 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
180 MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
181 MODULE_LICENSE("GPL v2");
182 MODULE_VERSION(DRV_VERSION);