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