2 * Atari Falcon PATA controller driver
4 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com
7 * Based on falconide.c:
9 * Created 12 Jul 1997 by Geert Uytterhoeven
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
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>
26 #include <linux/interrupt.h>
27 #include <linux/platform_device.h>
29 #include <asm/setup.h>
30 #include <asm/atarihw.h>
31 #include <asm/atariints.h>
32 #include <asm/atari_stdma.h>
35 #define DRV_NAME "pata_falcon"
36 #define DRV_VERSION "0.1.0"
38 #define ATA_HD_BASE 0xfff00000
39 #define ATA_HD_CONTROL 0x39
41 static struct scsi_host_template pata_falcon_sht
= {
42 ATA_PIO_SHT(DRV_NAME
),
45 static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd
*qc
,
47 unsigned int buflen
, int rw
)
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
;
56 if (dev
->class == ATA_DEV_ATA
&& cmd
&& cmd
->request
&&
57 !blk_rq_is_passthrough(cmd
->request
))
60 /* Transfer multiple of 2 bytes */
63 raw_insw_swapw((u16
*)data_addr
, (u16
*)buf
, words
);
65 raw_insw((u16
*)data_addr
, (u16
*)buf
, words
);
68 raw_outsw_swapw((u16
*)data_addr
, (u16
*)buf
, words
);
70 raw_outsw((u16
*)data_addr
, (u16
*)buf
, words
);
73 /* Transfer trailing byte, if any. */
74 if (unlikely(buflen
& 0x01)) {
75 unsigned char pad
[2] = { };
77 /* Point buf to the tail of buffer */
82 raw_insw_swapw((u16
*)data_addr
, (u16
*)pad
, 1);
84 raw_insw((u16
*)data_addr
, (u16
*)pad
, 1);
89 raw_outsw_swapw((u16
*)data_addr
, (u16
*)pad
, 1);
91 raw_outsw((u16
*)data_addr
, (u16
*)pad
, 1);
100 * Provide our own set_mode() as we don't want to change anything that has
101 * already been configured..
103 static int pata_falcon_set_mode(struct ata_link
*link
,
104 struct ata_device
**unused
)
106 struct ata_device
*dev
;
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");
118 static 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
,
125 static int pata_falcon_init_one(void)
127 struct ata_host
*host
;
129 struct platform_device
*pdev
;
132 if (!MACH_IS_ATARI
|| !ATARIHW_PRESENT(IDE
))
135 pr_info(DRV_NAME
": Atari Falcon PATA controller\n");
137 pdev
= platform_device_register_simple(DRV_NAME
, 0, NULL
, 0);
139 return PTR_ERR(pdev
);
141 if (!devm_request_mem_region(&pdev
->dev
, ATA_HD_BASE
, 0x40, DRV_NAME
)) {
142 pr_err(DRV_NAME
": resources busy\n");
147 host
= ata_host_alloc(&pdev
->dev
, 1);
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
;
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;
169 ap
->ioaddr
.altstatus_addr
= base
+ ATA_HD_CONTROL
;
170 ap
->ioaddr
.ctl_addr
= base
+ ATA_HD_CONTROL
;
172 ata_port_desc(ap
, "cmd 0x%lx ctl 0x%lx", (unsigned long)base
,
173 (unsigned long)base
+ ATA_HD_CONTROL
);
176 return ata_host_activate(host
, 0, NULL
, 0, &pata_falcon_sht
);
179 module_init(pata_falcon_init_one
);
181 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
182 MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
183 MODULE_LICENSE("GPL");
184 MODULE_VERSION(DRV_VERSION
);