1 // SPDX-License-Identifier: GPL-2.0
4 * Buddha, Catweasel and X-Surf PATA controller driver
6 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
7 * http://www.samsung.com
11 * Copyright (C) 1997, 2001 by Geert Uytterhoeven and others
14 #include <linux/ata.h>
15 #include <linux/blkdev.h>
16 #include <linux/delay.h>
17 #include <linux/interrupt.h>
18 #include <linux/kernel.h>
19 #include <linux/libata.h>
21 #include <linux/module.h>
22 #include <linux/zorro.h>
23 #include <scsi/scsi_cmnd.h>
24 #include <scsi/scsi_host.h>
26 #include <asm/amigahw.h>
27 #include <asm/amigaints.h>
29 #include <asm/setup.h>
31 #define DRV_NAME "pata_buddha"
32 #define DRV_VERSION "0.1.0"
34 #define BUDDHA_BASE1 0x800
35 #define BUDDHA_BASE2 0xa00
36 #define BUDDHA_BASE3 0xc00
37 #define XSURF_BASE1 0xb000 /* 2.5" interface */
38 #define XSURF_BASE2 0xd000 /* 3.5" interface */
39 #define BUDDHA_CONTROL 0x11a
40 #define BUDDHA_IRQ 0xf00
41 #define XSURF_IRQ 0x7e
42 #define BUDDHA_IRQ_MR 0xfc0 /* master interrupt enable */
50 static unsigned int buddha_bases
[3] __initdata
= {
51 BUDDHA_BASE1
, BUDDHA_BASE2
, BUDDHA_BASE3
54 static unsigned int xsurf_bases
[2] __initdata
= {
55 XSURF_BASE1
, XSURF_BASE2
58 static struct scsi_host_template pata_buddha_sht
= {
59 ATA_PIO_SHT(DRV_NAME
),
62 /* FIXME: is this needed? */
63 static unsigned int pata_buddha_data_xfer(struct ata_queued_cmd
*qc
,
65 unsigned int buflen
, int rw
)
67 struct ata_device
*dev
= qc
->dev
;
68 struct ata_port
*ap
= dev
->link
->ap
;
69 void __iomem
*data_addr
= ap
->ioaddr
.data_addr
;
70 unsigned int words
= buflen
>> 1;
72 /* Transfer multiple of 2 bytes */
74 raw_insw((u16
*)data_addr
, (u16
*)buf
, words
);
76 raw_outsw((u16
*)data_addr
, (u16
*)buf
, words
);
78 /* Transfer trailing byte, if any. */
79 if (unlikely(buflen
& 0x01)) {
80 unsigned char pad
[2] = { };
82 /* Point buf to the tail of buffer */
86 raw_insw((u16
*)data_addr
, (u16
*)pad
, 1);
90 raw_outsw((u16
*)data_addr
, (u16
*)pad
, 1);
99 * Provide our own set_mode() as we don't want to change anything that has
100 * already been configured..
102 static int pata_buddha_set_mode(struct ata_link
*link
,
103 struct ata_device
**unused
)
105 struct ata_device
*dev
;
107 ata_for_each_dev(dev
, link
, ENABLED
) {
108 /* We don't really care */
109 dev
->pio_mode
= dev
->xfer_mode
= XFER_PIO_0
;
110 dev
->xfer_shift
= ATA_SHIFT_PIO
;
111 dev
->flags
|= ATA_DFLAG_PIO
;
112 ata_dev_info(dev
, "configured for PIO\n");
117 static bool pata_buddha_irq_check(struct ata_port
*ap
)
121 ch
= z_readb((unsigned long)ap
->private_data
);
123 return !!(ch
& 0x80);
126 static void pata_xsurf_irq_clear(struct ata_port
*ap
)
128 z_writeb(0, (unsigned long)ap
->private_data
);
131 static struct ata_port_operations pata_buddha_ops
= {
132 .inherits
= &ata_sff_port_ops
,
133 .sff_data_xfer
= pata_buddha_data_xfer
,
134 .sff_irq_check
= pata_buddha_irq_check
,
135 .cable_detect
= ata_cable_unknown
,
136 .set_mode
= pata_buddha_set_mode
,
139 static struct ata_port_operations pata_xsurf_ops
= {
140 .inherits
= &ata_sff_port_ops
,
141 .sff_data_xfer
= pata_buddha_data_xfer
,
142 .sff_irq_check
= pata_buddha_irq_check
,
143 .sff_irq_clear
= pata_xsurf_irq_clear
,
144 .cable_detect
= ata_cable_unknown
,
145 .set_mode
= pata_buddha_set_mode
,
148 static int __init
pata_buddha_init_one(void)
150 struct zorro_dev
*z
= NULL
;
152 while ((z
= zorro_find_device(ZORRO_WILDCARD
, z
))) {
153 static const char *board_name
[]
154 = { "Buddha", "Catweasel", "X-Surf" };
155 struct ata_host
*host
;
156 void __iomem
*buddha_board
;
158 unsigned int type
, nr_ports
= 2;
161 if (z
->id
== ZORRO_PROD_INDIVIDUAL_COMPUTERS_BUDDHA
) {
163 } else if (z
->id
== ZORRO_PROD_INDIVIDUAL_COMPUTERS_CATWEASEL
) {
164 type
= BOARD_CATWEASEL
;
166 } else if (z
->id
== ZORRO_PROD_INDIVIDUAL_COMPUTERS_X_SURF
) {
171 dev_info(&z
->dev
, "%s IDE controller\n", board_name
[type
]);
173 board
= z
->resource
.start
;
175 if (type
!= BOARD_XSURF
) {
176 if (!devm_request_mem_region(&z
->dev
,
177 board
+ BUDDHA_BASE1
,
181 if (!devm_request_mem_region(&z
->dev
,
185 if (!devm_request_mem_region(&z
->dev
,
192 host
= ata_host_alloc(&z
->dev
, nr_ports
);
196 buddha_board
= ZTWO_VADDR(board
);
198 /* enable the board IRQ on Buddha/Catweasel */
199 if (type
!= BOARD_XSURF
)
200 z_writeb(0, buddha_board
+ BUDDHA_IRQ_MR
);
202 for (i
= 0; i
< nr_ports
; i
++) {
203 struct ata_port
*ap
= host
->ports
[i
];
204 void __iomem
*base
, *irqport
;
205 unsigned long ctl
= 0;
207 if (type
!= BOARD_XSURF
) {
208 ap
->ops
= &pata_buddha_ops
;
209 base
= buddha_board
+ buddha_bases
[i
];
210 ctl
= BUDDHA_CONTROL
;
211 irqport
= buddha_board
+ BUDDHA_IRQ
+ i
* 0x40;
213 ap
->ops
= &pata_xsurf_ops
;
214 base
= buddha_board
+ xsurf_bases
[i
];
215 /* X-Surf has no CS1* (Control/AltStat) */
216 irqport
= buddha_board
+ XSURF_IRQ
;
219 ap
->pio_mask
= ATA_PIO4
;
220 ap
->flags
|= ATA_FLAG_SLAVE_POSS
| ATA_FLAG_NO_IORDY
;
222 ap
->ioaddr
.data_addr
= base
;
223 ap
->ioaddr
.error_addr
= base
+ 2 + 1 * 4;
224 ap
->ioaddr
.feature_addr
= base
+ 2 + 1 * 4;
225 ap
->ioaddr
.nsect_addr
= base
+ 2 + 2 * 4;
226 ap
->ioaddr
.lbal_addr
= base
+ 2 + 3 * 4;
227 ap
->ioaddr
.lbam_addr
= base
+ 2 + 4 * 4;
228 ap
->ioaddr
.lbah_addr
= base
+ 2 + 5 * 4;
229 ap
->ioaddr
.device_addr
= base
+ 2 + 6 * 4;
230 ap
->ioaddr
.status_addr
= base
+ 2 + 7 * 4;
231 ap
->ioaddr
.command_addr
= base
+ 2 + 7 * 4;
234 ap
->ioaddr
.altstatus_addr
= base
+ ctl
;
235 ap
->ioaddr
.ctl_addr
= base
+ ctl
;
238 ap
->private_data
= (void *)irqport
;
240 ata_port_desc(ap
, "cmd 0x%lx ctl 0x%lx", board
,
241 ctl
? board
+ buddha_bases
[i
] + ctl
: 0);
244 ata_host_activate(host
, IRQ_AMIGA_PORTS
, ata_sff_interrupt
,
245 IRQF_SHARED
, &pata_buddha_sht
);
252 module_init(pata_buddha_init_one
);
254 MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
255 MODULE_DESCRIPTION("low-level driver for Buddha/Catweasel/X-Surf PATA");
256 MODULE_LICENSE("GPL v2");
257 MODULE_VERSION(DRV_VERSION
);