Skip to contentSkip to conversation

m68k: pata_cswarp: Add Amiga cslab ata support

PATCH Superseded Paolo Pisati 2 participants 6 messages Mar 24, 2025 – Mar 25, 2025

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover m68k: pata_cswarp: Add Amiga cslab ata support

Here is a driver (and the subsequent defconfig change) for the pata/CF socket in the CS-Lab Warp series of Amiga boards.

Changes in v3:
- suppress a comment
- properly return ata_host_activate() error code

Change in v2:
- fix style, remove duplicate swap macro, driver version, etc
- rework the zorro attach mechanism
- remove the unnecessary zorro ids refactor

Paolo Pisati (2):
ata: pata_cswarp: Add Amiga cslab ata support
m68k: amiga_defconfig: enable PATA_CSWARP

 arch/m68k/configs/amiga_defconfig |   1 +
 drivers/ata/Kconfig               |  11 ++
 drivers/ata/Makefile              |   1 +
 drivers/ata/pata_cswarp.c         | 186 ++++++++++++++++++++++++++++++
 4 files changed, 199 insertions(+)
 create mode 100644 drivers/ata/pata_cswarp.c
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/2 ata: pata_cswarp: Add Amiga cslab ata support

Driver for the on-board IDE interface on CS-Lab Warp Expansion Card (NOTE that idemode=native has to be set in Warp Configuration)

---
 drivers/ata/Kconfig       |  11 +++
 drivers/ata/Makefile      |   1 +
 drivers/ata/pata_cswarp.c | 186 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 198 insertions(+)
 create mode 100644 drivers/ata/pata_cswarp.c
drivers/ata/Kconfig +11 -0
index e00536b49552..a278386f0fa2 100644
@@ -1025,6 +1025,17 @@ config PATA_GAYLE
 
 	  If unsure, say N.
 
+config PATA_CSWARP
+	tristate "Amiga CS Warp PATA support"
+	depends on M68K && AMIGA
+	help
+	  This option enables support for the on-board IDE interface on
+	  CS-Lab Warp Expansion Card (NOTE that idemode=native has to be
+	  set in Warp Configuration)
+
+	  If unsure, say N.
+
+
 config PATA_BUDDHA
 	tristate "Buddha/Catweasel/X-Surf PATA support"
 	depends on ZORRO
drivers/ata/Makefile +1 -0
index 20e6645ab737..7b9b87ebacea 100644
@@ -98,6 +98,7 @@ obj-$(CONFIG_PATA_WINBOND)	+= pata_sl82c105.o
 obj-$(CONFIG_PATA_CMD640_PCI)	+= pata_cmd640.o
 obj-$(CONFIG_PATA_FALCON)	+= pata_falcon.o
 obj-$(CONFIG_PATA_GAYLE)	+= pata_gayle.o
+obj-$(CONFIG_PATA_CSWARP)	+= pata_cswarp.o
 obj-$(CONFIG_PATA_BUDDHA)	+= pata_buddha.o
 obj-$(CONFIG_PATA_ISAPNP)	+= pata_isapnp.o
 obj-$(CONFIG_PATA_IXP4XX_CF)	+= pata_ixp4xx_cf.o
drivers/ata/pata_cswarp.c new file +186 -0

186 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v3 1/2] ata: pata_cswarp: Add Amiga cslab ata support

Hi Paolo,

Quoted 4 lines · Paolo Pisati

Driver for the on-board IDE interface on CS-Lab Warp Expansion Card (NOTE that idemode=native has to be set in Warp Configuration)

Thanks for your patch!

drivers/ata/Kconfig config PATA_GAYLE · line 1030

Quoted 9 lines
drivers/ata/Kconfig +3 -0
@@ -1025,6 +1025,17 @@ config PATA_GAYLE
 
          If unsure, say N.
 
+config PATA_CSWARP
+       tristate "Amiga CS Warp PATA support"
+       depends on M68K && AMIGA

&& ZORRO?

Quoted 47 lines
drivers/ata/Kconfig +8 -0
+       help
+         This option enables support for the on-board IDE interface on
+         CS-Lab Warp Expansion Card (NOTE that idemode=native has to be
+         set in Warp Configuration)
+
+         If unsure, say N.
+
+
 config PATA_BUDDHA
        tristate "Buddha/Catweasel/X-Surf PATA support"
        depends on ZORRO
drivers/ata/pata_cswarp.c new file +32 -0
@@ -0,0 +1,186 @@
+// SPDX-License-Identifier: GPL-2.0
+
+/*
+ * Amiga CS Warp PATA controller driver
+ *
+ * Copyright (c) 2024 CS-Lab s.c.
+ *             http://www.cs-lab.eu
+ *
+ * Based on pata_gayle.c, pata_buddha.c and warpATA.device:
+ *
+ *     Created 2 Jun 2024 by Andrzej Rogozynski
+ */
+
+#include <linux/ata.h>
+#include <linux/blkdev.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/libata.h>
+#include <linux/mm.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/zorro.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_host.h>
+
+#include <asm/amigahw.h>
+#include <asm/amigaints.h>
+#include <asm/amigayle.h>
+#include <asm/setup.h>
+
+#define DRV_NAME "pata_cswarp"

drivers/ata/pata_cswarp.c line 42

Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10 -0
+
+#define WARP_OFFSET_ATA         0x6000
+
+static const struct scsi_host_template pata_cswarp_sht = {
+       ATA_PIO_SHT(DRV_NAME),
+};
+
+static unsigned int pata_cswarp_data_xfer(struct ata_queued_cmd *qc,
+                                        unsigned char *buf,
+                                        unsigned int buflen, int rw)

It is a pity ata_port_operations.sff_data_xfer() doesn't take a void *buf, else the casts below can be dropped.

Until that has changed, I think it is worthwhile to do the cast only once, by introducing a temporary variable:

    u16 *buf16 = (u16 *)buf;

drivers/ata/pata_cswarp.c line 46

Quoted 4 lines
drivers/ata/pata_cswarp.c new file +4 -0
+{
+       struct ata_device *dev = qc->dev;
+       struct ata_port *ap = dev->link->ap;
+       void __iomem *data_addr = ap->ioaddr.data_addr;

"volatile void __iomem *data_addr ...", so you can drop the casts below.

Quoted 4 lines
drivers/ata/pata_cswarp.c new file +4 -0
+       unsigned int words = buflen >> 1;
+
+       /* Transfer multiple of 2 bytes */
+       if (rw == READ)

drivers/ata/pata_cswarp.c line 60

Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10 -0
+               raw_insw((u16 *)data_addr, (u16 *)buf, words);
+       else
+               raw_outsw((u16 *)data_addr, (u16 *)buf, words);
+
+       /* Transfer trailing byte, if any. */
+       if (unlikely(buflen & 0x01)) {
+               unsigned char pad[2] = { };
+
+               /* Point buf to the tail of buffer */
+               buf += buflen - 1;

buf16 += words;

drivers/ata/pata_cswarp.c line 63

Quoted 3 lines
drivers/ata/pata_cswarp.c new file +3 -0
+
+               if (rw == READ) {
+                       raw_insw((u16 *)data_addr, (u16 *)pad, 1);

No need to loop, just use raw_inw() for a single word.

drivers/ata/pata_cswarp.c line 67

Quoted 4 lines
drivers/ata/pata_cswarp.c new file +4 -0
+                       *buf = pad[0];
+               } else {
+                       pad[0] = *buf;
+                       raw_outsw((u16 *)data_addr, (u16 *)pad, 1);

likewise, raw_outw().

drivers/ata/pata_cswarp.c line 72

Quoted 5 lines
drivers/ata/pata_cswarp.c new file +5 -0
+               }
+               words++;
+       }
+
+       return words << 1;

This can be one more than buflen, when the latter is odd. Why not just return buflen instead?

Quoted 13 lines
drivers/ata/pata_cswarp.c new file +12 -0
+}
 
+static int pata_cswarp_probe(struct zorro_dev *z,
+                            const struct zorro_device_id *ent)
+{
+       static const char board_name[] = "csWarp";
+       struct ata_host *host;
+       struct ata_port *ap;
+       void __iomem *cswarp_ctrl_board, *base;
+       unsigned long board = z->resource.start;
+
+       dev_info(&z->dev, "%s IDE controller (board: 0x%lx)\n", board_name,
+                board);

drivers/ata/pata_cswarp.c line 121

Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10 -0
+
+       if (!devm_request_mem_region(&z->dev, board + WARP_OFFSET_ATA, 0x1800,
+                                    DRV_NAME))
+               return -ENXIO;
+
+       host = ata_host_alloc(&z->dev, 1);
+       if (!host)
+               return -ENXIO;
+
+       cswarp_ctrl_board = (void *)board;

ioremap(board + WARP_OFFSET_ATA, ...)?

Quoted 16 lines
drivers/ata/pata_cswarp.c new file +16 -0
+
+       ap = host->ports[0];
+       base = cswarp_ctrl_board + WARP_OFFSET_ATA;
+
+       ap->ops = &pata_cswarp_ops;
+
+       ap->pio_mask = ATA_PIO4;
+       ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY |
+               ATA_FLAG_PIO_POLLING;
+
+       ap->ioaddr.data_addr            = base;
+       ap->ioaddr.error_addr           = base + 1 * 4;
+       ap->ioaddr.feature_addr         = base + 1 * 4;
+       ap->ioaddr.nsect_addr           = base + 2 * 4;
+       ap->ioaddr.lbal_addr            = base + 3 * 4;
+       ap->ioaddr.lbam_addr            = base + 4 * 4;

drivers/ata/pata_cswarp.c line 147

Quoted 10 lines
drivers/ata/pata_cswarp.c new file +10 -0
+       ap->ioaddr.lbah_addr            = base + 5 * 4;
+       ap->ioaddr.device_addr          = base + 6 * 4;
+       ap->ioaddr.status_addr          = base + 7 * 4;
+       ap->ioaddr.command_addr         = base + 7 * 4;
+
+       ap->ioaddr.altstatus_addr       = base + (0x1000 | (6UL << 2));
+       ap->ioaddr.ctl_addr             = base + (0x1000 | (6UL << 2));
+
+       ata_port_desc(ap, "  cmd 0x%lx ctl 0x%lx", (unsigned long)base,
+                     (unsigned long)ap->ioaddr.ctl_addr);

These two printed addresses are virtual addresses.
However, due to the use of a cast instead of ioremap(), they are identical. Still, I think it is better to print board + WARP_OFFSET_ATA and board + WARP_OFFSET_ATA + 0x1000 | (6UL << 2) instead.

drivers/ata/pata_cswarp.c line 151

Quoted 4 lines
drivers/ata/pata_cswarp.c new file +4 -0
+
+       return ata_host_activate(host, 0, NULL,
+                         IRQF_SHARED, &pata_cswarp_sht);
+}

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw

Re: [PATCH v3 1/2] ata: pata_cswarp: Add Amiga cslab ata support

Quoted 9 lines · Geert Uytterhoeven

drivers/ata/pata_cswarp.c line 72

Quoted 6 lines
drivers/ata/pata_cswarp.c new file +5 -0
+               }
+               words++;
+       }
+
+       return words << 1;

This can be one more than buflen, when the latter is odd. Why not just return buflen instead?

I think "every" m68k pata driver is buggy in this regard, e.g. pata_buddha, pata_gayle, pata_falcon, etc
And words++ can go too.

Quoted 8 lines

drivers/ata/pata_cswarp.c line 147

Quoted 3 lines
drivers/ata/pata_cswarp.c new file +3 -0
+
+       ata_port_desc(ap, "  cmd 0x%lx ctl 0x%lx", (unsigned long)base,
+                     (unsigned long)ap->ioaddr.ctl_addr);

These two printed addresses are virtual addresses.
However, due to the use of a cast instead of ioremap(), they are identical. Still, I think it is better to print board + WARP_OFFSET_ATA and board + WARP_OFFSET_ATA + 0x1000 | (6UL << 2) instead.

Honestly i don't follow you here, but i'll ioremap() and send a v4.

Signature · 2 lines
bye,
p.
#4 lore raw

Re: [PATCH v3 1/2] ata: pata_cswarp: Add Amiga cslab ata support

Hi Paolo,

Quoted 7 lines · Paolo Pisati
Quoted 6 lines · Geert Uytterhoeven

drivers/ata/pata_cswarp.c line 147

Quoted 3 lines
drivers/ata/pata_cswarp.c new file +3 -0
+
+       ata_port_desc(ap, "  cmd 0x%lx ctl 0x%lx", (unsigned long)base,
+                     (unsigned long)ap->ioaddr.ctl_addr);

These two printed addresses are virtual addresses.
However, due to the use of a cast instead of ioremap(), they are identical.

... identical to the physical addresses.

Quoted 4 lines
Quoted 2 lines

Still, I think it is better to print board + WARP_OFFSET_ATA and board + WARP_OFFSET_ATA + 0x1000 | (6UL << 2) instead.

Honestly i don't follow you here, but i'll ioremap() and send a v4.

Thanks!

Gr{oetje,eeting}s,

Geert

Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
#5 lore raw

PATCH v3 2/2 m68k: amiga_defconfig: enable PATA_CSWARP

In reply to Paolo Pisati
---
 arch/m68k/configs/amiga_defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/m68k/configs/amiga_defconfig +1 -0
index c705247e7b5b..feed92c95394 100644
@@ -334,6 +334,7 @@ CONFIG_ATA=y
 # CONFIG_ATA_VERBOSE_ERROR is not set
 # CONFIG_ATA_BMDMA is not set
 CONFIG_PATA_GAYLE=y
+CONFIG_PATA_CSWARP=y
 CONFIG_PATA_BUDDHA=y
 CONFIG_MD=y
 CONFIG_BLK_DEV_DM=m
Signature · 1 line
2.34.1