Skip to contentSkip to conversation

zorro: add a CS-Lab Warp 1260 MFD

RFC PATCH New Paolo Pisati 1 participant 9 messages Oct 21

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover zorro: add a CS-Lab Warp 1260 MFD

The CS-Lab Warp 1260 is an A1200 trapdoor multifunction accelerator: it contains a 68060, an FPGA, an ARM co-processor and several sub-devices hanging off them. The 68k drives the IDE interface and the RTG display controller directly, through the FPGA; the ARM owns most of the rest - USB, SD card, WiFi, audio, the Kickstart slots, the CPU clock, fan control and the board telemetry - and the 68k reaches it through a dual-port RAM mailbox.

pata_cswarp [1], queued for 7.4, binds the board's Zorro device for the IDE window alone. This series puts an mfd parent on the device instead, hands the IDE window to pata_cswarp as a cell, and uses the mailbox for a first set of board functions, exposed as sysfs attributes on the Zorro device:

  1-3  the mfd parent, pata_cswarp as its first cell, defconfig
  4    the dual-port RAM command channel and the board identity
  5-8  voltages and temperatures, fan duty cycle, Kickstart slot

selection, WiFi configuration

The layout - an mfd parent in drivers/zorro/ handing cells to the function drivers - is modelled on Geert's Zorro MFD experiments [2], which were the inspiration for this series.

It is an RFC because I would like opinions on the shape before going further:

- Geert, does this fit where you wanted to take the Zorro MFD work? Should the parent stay in drivers/zorro/, as in your experiments, or move to drivers/mfd/?
- Would you rather see the voltages, temperatures and fan in hwmon than as plain sysfs attributes?
- Writing kickslot makes the ARM reset the machine on the spot. Is a sysfs attribute acceptable for that?

Tested on a Warp 1260 (firmware 20.27) on top of 7.3. Every patch builds with W=1 for m68k multi_defconfig on next-20261021, which carries pata_cswarp [1] and its defconfig patch.

I wrote the original version of this driver myself, by hand. An LLM coding assistant came in later: it was used to review that code against CS-Lab's AmigaOS sources, to write several of the fixes folded into these patches, to split the work into this series and to draft the commit messages. I reviewed every change and tested the result on my Warp 1260.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/libata/linux.git/commit/?id=d388f9657ad68eca31d86765d48133b9258b8983
[2] https://git.kernel.org/pub/scm/linux/kernel/git/geert/linux-m68k.git/log/?h=zorro-mfd

Paolo Pisati (8):
zorro: warp mfd: add the CS-Lab Warp multifunction parent
ata: pata_cswarp: bind to the Warp mfd cell instead of the Zorro
device
m68k: defconfig: enable WARP_MFD
zorro: warp mfd: add the dual-port RAM command channel and expose the
board identity
zorro: warp mfd: expose the voltage and temperature sensors
zorro: warp mfd: expose the fan duty cycle
zorro: warp mfd: expose the Kickstart slot selection
zorro: warp mfd: expose the WiFi configuration

 arch/m68k/configs/amiga_defconfig |   1 +
 arch/m68k/configs/multi_defconfig |   1 +
 drivers/ata/Kconfig               |   2 +-
 drivers/ata/pata_cswarp.c         |  48 ++-
 drivers/zorro/Kconfig             |  31 ++
 drivers/zorro/Makefile            |   2 +
 drivers/zorro/warp-mfd.c          | 601 ++++++++++++++++++++++++++++++
 drivers/zorro/warp-mfd.h          | 170 +++++++++
 8 files changed, 828 insertions(+), 28 deletions(-)
 create mode 100644 drivers/zorro/warp-mfd.c
 create mode 100644 drivers/zorro/warp-mfd.h

base-commit: 9a482184d910775cf648863148944945b74e2815

Signature · 1 line
2.43.0
#1 lore raw

RFC PATCH 1/8 zorro: warp mfd: add the CS-Lab Warp multifunction parent

The Warp 1260 is an A1200 trapdoor accelerator whose single Zorro device fronts several functions: an ARM co-processor reached through a dual-port RAM window, and an IDE interface and an RTG display controller that the 68k drives directly.
pata_cswarp claims the whole device for the IDE window alone, which leaves no way for anything else on the board to get a driver.

Add a parent that owns the Zorro device and describes the functions as mfd cells, starting with the IDE window as a "warp-pata" cell.

Only the window layout is described here; the dual-port RAM protocol arrives with its first user.
pata_cswarp is converted in the next patch.

---
 drivers/zorro/Kconfig    | 31 ++++++++++++++
 drivers/zorro/Makefile   |  2 +
 drivers/zorro/warp-mfd.c | 87 ++++++++++++++++++++++++++++++++++++++++
 drivers/zorro/warp-mfd.h | 19 +++++++++
 4 files changed, 139 insertions(+)
 create mode 100644 drivers/zorro/warp-mfd.c
 create mode 100644 drivers/zorro/warp-mfd.h
drivers/zorro/Kconfig +31 -0
index 41475ad46e45..9060b659b13d 100644
@@ -17,3 +17,34 @@ config ZORRO_NAMES
 
 	  When in doubt, say Y.
 
+# Zorro multifunction drivers
+
+config WARP_MFD
+	tristate "CS-Lab Warp multifunction driver"
+	depends on ZORRO
+	select MFD_CORE
+	help
+	  The CS-Lab Warp 1260 is an A1200 trapdoor accelerator. Besides the
+	  68060 it carries an FPGA and an ARM co-processor; its control
+	  registers, the dual-port RAM and the IDE interface share one Zorro
+	  device, which this driver binds to.
+
+	  The 68k drives these through the FPGA: the on-board IDE interface and
+	  an RTG display controller.
+
+	  The co-processor owns the rest, reached over the dual-port RAM: two
+	  USB host ports, an SD card slot, an ESP32 WiFi bridge,
+	  an audio mixer, the Kickstart slot selection, the CPU clock and turbo
+	  levels, thermal regulation of the fan, and the board telemetry.
+
+	  This driver hands the IDE window to pata_cswarp - which needs
+	  idemode=native set in Warp Configuration to be of any use - and
+	  exposes the configuration and telemetry reachable over the dual-port
+	  RAM in sysfs: voltages, temperatures, fan, firmware version,
+	  Kickstart slot and WiFi credentials. Nothing else on the list has a
+	  driver yet.
+
+	  If you have a CS-Lab Warp 1260 board, say Y. Otherwise, say N.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called warp-mfd.
drivers/zorro/Makefile +2 -0
index 91ba82e633e7..6fe7cc1822dc 100644
@@ -7,6 +7,8 @@ obj-$(CONFIG_ZORRO)	+= zorro.o zorro-driver.o zorro-sysfs.o
 obj-$(CONFIG_PROC_FS)	+= proc.o
 obj-$(CONFIG_ZORRO_NAMES) +=  names.o
 
+obj-$(CONFIG_WARP_MFD) += warp-mfd.o
+
 hostprogs		:= gen-devlist
 
 # Files generated that shall be removed upon make clean
drivers/zorro/warp-mfd.c new file +87 -0

87 lines not on this page · raw message

drivers/zorro/warp-mfd.h new file +19 -0
new file mode 100644
index 000000000000..3f44f2b57c76
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * CS-Lab Warp - board window layout
+ *
+ * Copyright 2026 Paolo Pisati <[email protected]>
+ */
+
+#ifndef _WARP_MFD_H
+#define _WARP_MFD_H
+
+/* Offsets from the start of the board's Zorro window. */
+#define WARP_OFFSET_DPREG_CR	0x1000	/* dual-port interrupt control reg */
+#define WARP_OFFSET_DPRAM	0x2000	/* dual-port RAM */
+#define WARP_OFFSET_ATA		0x6000	/* on-board IDE interface */
+
+#define WARP_DPRAM_SIZE		0x2000
+#define WARP_ATA_SIZE		0x1800
+
+#endif /* _WARP_MFD_H */
Signature · 1 line
2.43.0
#2 lore raw

RFC PATCH 2/8 ata: pata_cswarp: bind to the Warp mfd cell instead of the Zorro device

In reply to Paolo Pisati

Now that warp-mfd owns the device and hands the window out as the "warp-pata" cell, take it from there.

PATA_CSWARP depends on WARP_MFD from here on.

---
 drivers/ata/Kconfig       |  2 +-
 drivers/ata/pata_cswarp.c | 48 +++++++++++++++++----------------------
 2 files changed, 22 insertions(+), 28 deletions(-)
drivers/ata/Kconfig +1 -1
index 9704ed688775..407b79bf9405 100644
@@ -1035,7 +1035,7 @@ config PATA_GAYLE
 
 config PATA_CSWARP
 	tristate "Amiga CS Warp PATA support"
-	depends on M68K && AMIGA && ZORRO
+	depends on WARP_MFD
 	help
 	  This option enables support for the on-board IDE interface on
 	  CS-Lab Warp Expansion Card (NOTE that idemode=native has to be
drivers/ata/pata_cswarp.c +21 -27

110 lines not on this page · raw message

Signature · 1 line
2.43.0
#3 lore raw

RFC PATCH 3/8 m68k: defconfig: enable WARP_MFD

In reply to Paolo Pisati

Enable the CS-Lab Warp multifunction driver in the Amiga and multi defconfigs, which pata_cswarp now depends on.

---
 arch/m68k/configs/amiga_defconfig | 1 +
 arch/m68k/configs/multi_defconfig | 1 +
 2 files changed, 2 insertions(+)
arch/m68k/configs/amiga_defconfig +1 -0
index e2d474e8cb8f..75d91d502545 100644
@@ -20,6 +20,7 @@ CONFIG_AMIGA=y
 CONFIG_ZORRO=y
 CONFIG_AMIGA_PCMCIA=y
 CONFIG_ZORRO_NAMES=y
+CONFIG_WARP_MFD=y
 CONFIG_HEARTBEAT=y
 CONFIG_PROC_HARDWARE=y
 CONFIG_AMIGA_BUILTIN_SERIAL=y
arch/m68k/configs/multi_defconfig +1 -0
index 1bbd2aa653c0..120dc68d492c 100644
@@ -31,6 +31,7 @@ CONFIG_ZORRO=y
 CONFIG_AMIGA_PCMCIA=y
 CONFIG_ATARI_ROM_ISA=y
 CONFIG_ZORRO_NAMES=y
+CONFIG_WARP_MFD=y
 CONFIG_HEARTBEAT=y
 CONFIG_PROC_HARDWARE=y
 CONFIG_NATFEAT=y
Signature · 1 line
2.43.0
#4 lore raw

RFC PATCH 4/8 zorro: warp mfd: add the dual-port RAM command channel and expose the board identity

In reply to Paolo Pisati

The ARM co-processor is reached through a dual-port RAM window and an interrupt control register: the 68k writes a command frame, rings the ARM, and the ARM acknowledges and then answers in the same buffer, raising a flag for each on the shared IRQ_AMIGA_PORTS line.

The protocol header describes only what the driver uses: the control bits, GetDiag and its reply frame, laid out as the 68k sees it, with static_assert()s pinning the offsets - the firmware decides them, not the compiler.

Use it for the first attributes: boardname, hwver and fmwver, read from a fresh diagnostic frame on every access.

---
 drivers/zorro/warp-mfd.c | 258 ++++++++++++++++++++++++++++++++++++++-
 drivers/zorro/warp-mfd.h | 118 +++++++++++++++++-
 2 files changed, 373 insertions(+), 3 deletions(-)
drivers/zorro/warp-mfd.c +256 -2
index 0e80e82ab0d1..2c5b9254651a 100644
@@ -9,19 +9,44 @@
  * and the IDE interface and RTG display controller, which the 68k drives
  * directly.
  *
- * This driver claims the Zorro device and hands the IDE window to pata_cswarp
- * as an mfd cell.
+ * This driver claims the Zorro device, talks to the co-processor over the
+ * dual-port RAM to expose the board's configuration and telemetry in sysfs,
+ * and hands the IDE window to pata_cswarp as an mfd cell.
  */
 
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/bits.h>
+#include <linux/completion.h>
+#include <linux/mutex.h>
 
 #include <linux/zorro.h>
+#include <asm/amigaints.h>
 
 #include <linux/mfd/core.h>
 
 #include "warp-mfd.h"
 
+/**
+ * struct warp_mfd - per-board state
+ * @dev:    the zorro device we hang off
+ * @dpram:  mapped dual-port RAM, shared with the ARM co-processor
+ * @reg_cr: mapped dual-port interrupt control register
+ * @recv:   completed when the ARM acknowledges a message
+ * @reply:  completed when the ARM has a reply waiting in @dpram
+ * @lock:   serialises use of @dpram, which is one shared buffer
+ */
+struct warp_mfd {
+	struct device		*dev;
+	void __iomem		*dpram;
+	void __iomem		*reg_cr;
+	struct completion	recv;
+	struct completion	reply;
+	struct mutex		lock;	/* serialises @dpram */
+};
+
 static const struct mfd_cell warp_mfd_cells[] = {
 	{
 		.name		= "warp-pata",
@@ -33,14 +58,243 @@ static const struct mfd_cell warp_mfd_cells[] = {
 	}
 };
 
+static irqreturn_t warp_irq(int irq, void *data)
+{
+	struct warp_mfd *warp = data;
+	u32 cr = z_readl(warp->reg_cr);
+	irqreturn_t ret = IRQ_NONE;
+
+	/*
+	 * More than one of these can be latched by the time we run - the ARM
+	 * acknowledges and answers a GetDiag in quick succession - so test
+	 * them all. Returning after the first would leave the others set and
+	 * their waiter asleep until it times out.
+	 */
+	if (cr & DPREG_CR_MR_ARM) {
+		z_writel(DPREG_CR_CLR | DPREG_CR_MR_ARM, warp->reg_cr);
+		/* the ARM has taken the message out of the dual-port RAM */
+		complete(&warp->recv);
+		ret = IRQ_HANDLED;
+	}
+
+	if (cr & DPREG_CR_MP_68K) {
+		z_writel(DPREG_CR_CLR | DPREG_CR_MP_68K, warp->reg_cr);
+		/* the ARM has left a reply in the dual-port RAM */
+		complete(&warp->reply);
+		ret = IRQ_HANDLED;
+	}
+
+	if (cr & DPREG_CR_IF_ETHRX) {
+		z_writel(DPREG_CR_CLR | DPREG_CR_IF_ETHRX, warp->reg_cr);
+		/*
+		 * Acknowledged only. There is no network driver behind this
+		 * yet; the ARM stops re-raising it once the flag is cleared.
+		 */
+		ret = IRQ_HANDLED;
+	}
+
+	return ret;
+}
+
+/*
+ * The AmigaOS library waits on SIGBREAKF_CTRL_C alongside the ARM's signal,
+ * so a user can always break out of a stalled exchange. We have no such
+ * escape from inside a sysfs store, so bound the wait instead - and stay
+ * interruptible, which is the part of that behaviour worth keeping.
+ */
+#define WARP_MSG_TIMEOUT	msecs_to_jiffies(2000)
+
+/* send a message to the ARM coprocessor, optionally waiting for a reply */
+static int warp_send_msg(struct warp_mfd *warp, bool wait_reply)
+{
+	struct completion *done = wait_reply ? &warp->reply : &warp->recv;
+	long ret;
+
+	/* a previous exchange may have timed out and completed late */
+	reinit_completion(done);
+
+	/* enable 68k & ARM interrupts */
+	z_writel(DPREG_CR_SET | DPREG_CR_IE_68K | DPREG_CR_IE_ARM, warp->reg_cr);
+
+	/* send irq to ARM */
+	z_writel(DPREG_CR_SET | DPREG_CR_MP_ARM, warp->reg_cr);
+
+	/* wait for a reply, or just wait for a receiver ack */
+	ret = wait_for_completion_interruptible_timeout(done,
+							WARP_MSG_TIMEOUT);
+
+	/* disable ARM & 68k interrupts */
+	z_writel(DPREG_CR_CLR | DPREG_CR_IE_68K | DPREG_CR_IE_ARM, warp->reg_cr);
+
+	if (ret < 0)
+		return ret;
+	if (!ret) {
+		dev_err(warp->dev, "no answer from the ARM co-processor\n");
+		return -ETIMEDOUT;
+	}
+	return 0;
+}
+
+/*
+ * Submit one command frame and, when @rpl is given, collect the answer.
+ */
+static int warp_exec_cmd(struct warp_mfd *warp, const union warp_cmd *cmd,
+			 union warp_reply *rpl)
+{
+	int ret;
+
+	ret = mutex_lock_interruptible(&warp->lock);
+	if (ret)
+		return ret;
+
+	z_memcpy_toio(warp->dpram, cmd, sizeof(*cmd));
+	ret = warp_send_msg(warp, rpl);
+	if (!ret && rpl)
+		z_memcpy_fromio(rpl, warp->dpram, sizeof(*rpl));
+
+	mutex_unlock(&warp->lock);
+	return ret;
+}
+
+static int warp_get_status(struct warp_mfd *warp, union warp_reply *rpl)
+{
+	union warp_cmd *cmd;
+	int ret;
+
+	cmd = kzalloc_obj(*cmd);
+	if (!cmd)
+		return -ENOMEM;
+	cmd->hdr.cmd = WARP_CMD_GET_DIAG;
+	ret = warp_exec_cmd(warp, cmd, rpl);
+	kfree(cmd);
+	if (ret)
+		return ret;
+
+	/*
+	 * The dual-port RAM still holds the last frame written to it. If the
+	 * board answered something else - or did not answer and we picked up
+	 * a stale completion - the bytes look like a perfectly good reading.
+	 * The vendor library checks this on every command; so do we.
+	 */
+	if (rpl->hdr.rpl != WARP_RPL_DIAG) {
+		dev_err(warp->dev, "unexpected reply %u, wanted a diag frame\n",
+			rpl->hdr.rpl);
+		return -EIO;
+	}
+	return 0;
+}
+
+#define warp_config_uint_attr(name, field, format_string)		\
+static ssize_t name##_show(struct device *dev,				\
+			   struct device_attribute *attr, char *buf)	\
+{									\
+	int ret;							\
+	struct warp_mfd *warp = dev_get_drvdata(dev);			\
+	union warp_reply *rpl;						\
+									\
+	rpl = kmalloc_obj(*rpl);					\
+	if (!rpl)							\
+		return -ENOMEM;						\
+	ret = warp_get_status(warp, rpl);				\
+	if (ret)							\
+		goto out;						\
+	ret = sysfs_emit(buf, format_string "\n", rpl->diag.field);	\
+out:									\
+	kfree(rpl);							\
+	return ret;							\
+}									\
+static DEVICE_ATTR_RO(name)
+
+#define warp_config_string_attr(name, field)				\
+static ssize_t name##_show(struct device *dev,				\
+			   struct device_attribute *attr, char *buf)	\
+{									\
+	int ret;							\
+	struct warp_mfd *warp = dev_get_drvdata(dev);			\
+	union warp_reply *rpl;						\
+									\
+	rpl = kmalloc_obj(*rpl);					\
+	if (!rpl)							\
+		return -ENOMEM;						\
+	ret = warp_get_status(warp, rpl);				\
+	if (ret)							\
+		goto out;						\
+	ret = sysfs_emit(buf, "%.*s\n", (int)sizeof(rpl->diag.field),	\
+			 rpl->diag.field);				\
+out:									\
+	kfree(rpl);							\
+	return ret;							\
+}									\
+static DEVICE_ATTR_RO(name)
+
+warp_config_string_attr(boardname, board_name);
+warp_config_uint_attr(fmwver, fmw_ver, "%04X");
+warp_config_uint_attr(hwver, hw_ver, "%04X");
+
+static struct attribute *warp_attrs[] = {
+	/* RO attr */
+	&dev_attr_boardname.attr,
+	&dev_attr_fmwver.attr,
+	&dev_attr_hwver.attr,
+	NULL
+};
+
+static const struct attribute_group warp_attr_group = {
+	.attrs		= warp_attrs,
+};
+
 static int warp_mfd_probe(struct zorro_dev *z,
 			  const struct zorro_device_id *ent)
 {
 	unsigned long base = z->resource.start;
+	struct warp_mfd *warp;
 	int error;
 
 	dev_info(&z->dev, "Warp at 0x%08lx\n", base);
 
+	warp = devm_kzalloc(&z->dev, sizeof(*warp), GFP_KERNEL);
+	if (!warp)
+		return -ENOMEM;
+	warp->dev = &z->dev;
+	mutex_init(&warp->lock);
+	init_completion(&warp->recv);
+	init_completion(&warp->reply);
+	zorro_set_drvdata(z, warp);
+
+	if (!devm_request_mem_region(&z->dev, base + WARP_OFFSET_DPREG_CR,
+				     sizeof(u32), "warp-mfd")) {
+		dev_err(&z->dev, "cannot reserve the interrupt control register\n");
+		return -EBUSY;
+	}
+
+	if (!devm_request_mem_region(&z->dev, base + WARP_OFFSET_DPRAM,
+				     WARP_DPRAM_SIZE, "warp-mfd")) {
+		dev_err(&z->dev, "cannot reserve the dual-port RAM window\n");
+		return -EBUSY;
+	}
+
+	warp->dpram = devm_ioremap(&z->dev, base + WARP_OFFSET_DPRAM,
+				   WARP_DPRAM_SIZE);
+	warp->reg_cr = devm_ioremap(&z->dev, base + WARP_OFFSET_DPREG_CR,
+				    sizeof(u32));
+	if (!warp->dpram || !warp->reg_cr) {
+		dev_err(&z->dev, "cannot map the dual-port RAM window\n");
+		return -ENOMEM;
+	}
+
+	error = devm_request_irq(&z->dev, IRQ_AMIGA_PORTS, warp_irq,
+				 IRQF_SHARED, "warp-mfd", warp);
+	if (error) {
+		dev_err(&z->dev, "cannot request irq %u\n", IRQ_AMIGA_PORTS);
+		return error;
+	}
+
+	error = devm_device_add_group(&z->dev, &warp_attr_group);
+	if (error) {
+		dev_err(&z->dev, "cannot create sysfs attributes\n");
+		return error;
+	}
+
 	error = mfd_add_devices(&z->dev, z->dev.id, warp_mfd_cells,
 				ARRAY_SIZE(warp_mfd_cells), &z->resource,
 				0, NULL);
drivers/zorro/warp-mfd.h +117 -1

134 lines not on this page · raw message

Signature · 1 line
2.43.0
#5 lore raw

RFC PATCH 5/8 zorro: warp mfd: expose the voltage and temperature sensors

In reply to Paolo Pisati

The diagnostic frame carries the 5 V rail, the backup battery and three temperatures - the 68060, its NTC and the ARM - as IEEE-754 binary32.

Decode the bit pattern with integer arithmetic into milli-units.

---
 drivers/zorro/warp-mfd.c | 79 ++++++++++++++++++++++++++++++++++++++++
 drivers/zorro/warp-mfd.h |  4 ++
 2 files changed, 83 insertions(+)
drivers/zorro/warp-mfd.c +79 -0
index 2c5b9254651a..1bd7c701df8f 100644
@@ -19,6 +19,7 @@
 #include <linux/delay.h>
 #include <linux/interrupt.h>
 #include <linux/bits.h>
+#include <linux/limits.h>
 #include <linux/completion.h>
 #include <linux/mutex.h>
 
@@ -184,6 +185,73 @@ static int warp_get_status(struct warp_mfd *warp, union warp_reply *rpl)
 	return 0;
 }
 
+/*
+ * The board reports its sensors as IEEE-754 binary32: decode the
+ * bit pattern by hand and carry the result as milli-units.
+ */
+static int warp_f32_to_milli(u32 bits)
+{
+	int exp = (bits >> 23) & 0xff;
+	u32 frac = bits & GENMASK(22, 0);
+	int shift = exp - 127 - 23;
+	s64 v;
+
+	/*
+	 * inf, NaN, zero and subnormals all round to nothing useful here, and
+	 * so does anything of 2^23 or more: that is already past what an int
+	 * holds in milli-units, let alone what a sensor reports.
+	 */
+	if (exp == 0xff || exp == 0 || shift >= 0)
+		return 0;
+	if (shift <= -63)		/* smaller than a milli-unit */
+		return 0;
+
+	v = ((s64)(frac | BIT(23)) * 1000) >> -shift;
+	if (v > INT_MAX)		/* a shift of -1 or -2 can still overflow */
+		return 0;
+
+	return (bits & BIT(31)) ? -(int)v : (int)v;
+}
+
+/* Render milli-units with @dec decimal places, rounded, as WarpDiag shows them. */
+static int warp_print_milli(char *buf, int milli, unsigned int dec)
+{
+	unsigned int scale = (dec == 1) ? 100 : 10;
+	unsigned int units = (dec == 1) ? 10 : 100;
+	const char *sign = "";
+	unsigned int v;
+
+	if (milli < 0) {
+		sign = "-";
+		milli = -milli;
+	}
+	v = ((unsigned int)milli + scale / 2) / scale;
+
+	return sysfs_emit(buf, "%s%u.%0*u\n", sign, v / units, dec, v % units);
+}
+
+#define warp_config_sensor_attr(name, field, dec)			\
+static ssize_t name##_show(struct device *dev,				\
+			   struct device_attribute *attr, char *buf)	\
+{									\
+	int ret;							\
+	struct warp_mfd *warp = dev_get_drvdata(dev);			\
+	union warp_reply *rpl;						\
+									\
+	rpl = kmalloc_obj(*rpl);					\
+	if (!rpl)							\
+		return -ENOMEM;						\
+	ret = warp_get_status(warp, rpl);				\
+	if (ret)							\
+		goto out;						\
+	ret = warp_print_milli(buf,					\
+			       warp_f32_to_milli(rpl->diag.field), dec);\
+out:									\
+	kfree(rpl);							\
+	return ret;							\
+}									\
+static DEVICE_ATTR_RO(name)
+
 #define warp_config_uint_attr(name, field, format_string)		\
 static ssize_t name##_show(struct device *dev,				\
 			   struct device_attribute *attr, char *buf)	\
@@ -230,12 +298,23 @@ static DEVICE_ATTR_RO(name)
 warp_config_string_attr(boardname, board_name);
 warp_config_uint_attr(fmwver, fmw_ver, "%04X");
 warp_config_uint_attr(hwver, hw_ver, "%04X");
+/* board sensors: volts to 2 decimals, temperatures to 1, as WarpDiag shows them */
+warp_config_sensor_attr(t60int, t60_internal, 1);
+warp_config_sensor_attr(t60ext, t60_ntc, 1);
+warp_config_sensor_attr(tarm, t_arm, 1);
+warp_config_sensor_attr(vbatt, vbatt, 2);
+warp_config_sensor_attr(vcc5v, vcc5v, 2);
 
 static struct attribute *warp_attrs[] = {
 	/* RO attr */
 	&dev_attr_boardname.attr,
 	&dev_attr_fmwver.attr,
 	&dev_attr_hwver.attr,
+	&dev_attr_t60int.attr,
+	&dev_attr_t60ext.attr,
+	&dev_attr_tarm.attr,
+	&dev_attr_vbatt.attr,
+	&dev_attr_vcc5v.attr,
 	NULL
 };
 
drivers/zorro/warp-mfd.h +4 -0
index 14d8f9ddd58d..8a9e7f306269 100644
@@ -82,6 +82,10 @@ struct warp_rpl_hdr {
  * Reply to WARP_CMD_GET_DIAG. Fields this driver does not expose are kept
  * so the ones after them land at the right offset.
  *
+ * The board reports its sensors as IEEE-754 binary32. They are kept as raw
+ * bit patterns because the kernel cannot use the FPU; warp_f32_to_milli()
+ * decodes them with integer arithmetic.
+ *
  * turbo_level and tz_corr_secs are reported by the firmware but no longer
  * maintained by it; treat their contents as stale.
  */
Signature · 1 line
2.43.0
#6 lore raw

RFC PATCH 6/8 zorro: warp mfd: expose the fan duty cycle

In reply to Paolo Pisati

The diagnostic frame also reports the fan drive as a percentage. Expose it as fanspeedpercent.

---
 drivers/zorro/warp-mfd.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/zorro/warp-mfd.c +2 -0
index 1bd7c701df8f..dcf13e31bee2 100644
@@ -296,6 +296,7 @@ out:									\
 static DEVICE_ATTR_RO(name)
 
 warp_config_string_attr(boardname, board_name);
+warp_config_uint_attr(fanspeedpercent, fan_percent, "%u");
 warp_config_uint_attr(fmwver, fmw_ver, "%04X");
 warp_config_uint_attr(hwver, hw_ver, "%04X");
 /* board sensors: volts to 2 decimals, temperatures to 1, as WarpDiag shows them */
@@ -308,6 +309,7 @@ warp_config_sensor_attr(vcc5v, vcc5v, 2);
 static struct attribute *warp_attrs[] = {
 	/* RO attr */
 	&dev_attr_boardname.attr,
+	&dev_attr_fanspeedpercent.attr,
 	&dev_attr_fmwver.attr,
 	&dev_attr_hwver.attr,
 	&dev_attr_t60int.attr,
Signature · 1 line
2.43.0
#7 lore raw

RFC PATCH 7/8 zorro: warp mfd: expose the Kickstart slot selection

In reply to Paolo Pisati

The board keeps several Kickstart images and the ARM boots the 68k from the selected one.

Writing kickslot makes the ARM reset the machine on the spot. That is how the board works, not a crash.

---
 drivers/zorro/warp-mfd.c | 48 ++++++++++++++++++++++++++++++++++++++++
 drivers/zorro/warp-mfd.h |  7 ++++++
 2 files changed, 55 insertions(+)
drivers/zorro/warp-mfd.c +48 -0
index dcf13e31bee2..78a3d7e59320 100644
@@ -295,6 +295,52 @@ out:									\
 }									\
 static DEVICE_ATTR_RO(name)
 
+static ssize_t kickslot_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	int ret;
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_reply *rpl;
+
+	rpl = kmalloc_obj(*rpl);
+	if (!rpl)
+		return -ENOMEM;
+	ret = warp_get_status(warp, rpl);
+	if (ret)
+		goto out;
+	ret = sysfs_emit(buf, "%u\n", rpl->diag.kickstart_nr);
+out:
+	kfree(rpl);
+	return ret;
+}
+
+/*
+ * WARNING:
+ * changing softkick slot will initiate a forced reboot - your Amiga is not
+ * crashing, it's the ARM MCU that is abruptly pulling the plug
+ */
+static ssize_t kickslot_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, unsigned int len)
+{
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_cmd *cmd;
+	int ret;
+
+	cmd = kzalloc_obj(*cmd);
+	if (!cmd)
+		return -ENOMEM;
+	cmd->hdr.cmd = WARP_CMD_SELECT_KICK;
+	ret = kstrtou8(buf, 10, &cmd->select_kick.kick_nr);
+	if (ret)
+		goto done;
+	ret = warp_exec_cmd(warp, cmd, NULL);
+done:
+	kfree(cmd);
+	return ret ? ret : len;
+}
+static DEVICE_ATTR_RW(kickslot);
+
 warp_config_string_attr(boardname, board_name);
 warp_config_uint_attr(fanspeedpercent, fan_percent, "%u");
 warp_config_uint_attr(fmwver, fmw_ver, "%04X");
@@ -317,6 +363,8 @@ static struct attribute *warp_attrs[] = {
 	&dev_attr_tarm.attr,
 	&dev_attr_vbatt.attr,
 	&dev_attr_vcc5v.attr,
+	/* RW attr */
+	&dev_attr_kickslot.attr,
 	NULL
 };
 
drivers/zorro/warp-mfd.h +7 -0
index 8a9e7f306269..0633accc980d 100644
@@ -57,6 +57,7 @@
 
 /* Command opcodes. Only the ones this driver issues are listed. */
 enum warp_cmd_id {
+	WARP_CMD_SELECT_KICK	= 5,
 	WARP_CMD_GET_DIAG	= 6,
 };
 
@@ -70,8 +71,14 @@ struct warp_cmd_hdr {
 	u32	cmd;			/* enum warp_cmd_id */
 };
 
+struct warp_cmd_select_kick {
+	struct warp_cmd_hdr	hdr;
+	u8			kick_nr;
+};
+
 union warp_cmd {
 	struct warp_cmd_hdr		hdr;
+	struct warp_cmd_select_kick	select_kick;
 };
 
 struct warp_rpl_hdr {
Signature · 1 line
2.43.0
#8 lore raw

RFC PATCH 8/8 zorro: warp mfd: expose the WiFi configuration

In reply to Paolo Pisati

The ARM owns the WiFi radio. Report its state and let the SSID and passphrase be set through SetWiFiSSID and SetWiFiPass.

---
 drivers/zorro/warp-mfd.c | 131 +++++++++++++++++++++++++++++++++++++++
 drivers/zorro/warp-mfd.h |  26 +++++++-
 2 files changed, 156 insertions(+), 1 deletion(-)
drivers/zorro/warp-mfd.c +131 -0
index 78a3d7e59320..abe1cd686123 100644
@@ -295,6 +295,19 @@ out:									\
 }									\
 static DEVICE_ATTR_RO(name)
 
+static int warp_copy_str_arg(char *dst, size_t dst_size, const char *src,
+			     size_t len)
+{
+	while (len && (src[len - 1] == '\n' || src[len - 1] == '\r'))
+		len--;
+	if (len >= dst_size)
+		return -EINVAL;
+
+	memcpy(dst, src, len);
+	memset(dst + len, 0, dst_size - len);
+	return 0;
+}
+
 static ssize_t kickslot_show(struct device *dev,
 			     struct device_attribute *attr, char *buf)
 {
@@ -341,6 +354,121 @@ static ssize_t kickslot_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(kickslot);
 
+static ssize_t wifipass_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	int ret;
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_reply *rpl;
+
+	rpl = kmalloc_obj(*rpl);
+	if (!rpl)
+		return -ENOMEM;
+	ret = warp_get_status(warp, rpl);
+	if (ret)
+		goto out;
+	ret = sysfs_emit(buf, "%.*s\n", (int)sizeof(rpl->diag.wifi_pass),
+			 rpl->diag.wifi_pass);
+out:
+	kfree(rpl);
+	return ret;
+}
+
+static ssize_t wifipass_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, unsigned int len)
+{
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_cmd *cmd;
+	int ret;
+
+	cmd = kzalloc_obj(*cmd);
+	if (!cmd)
+		return -ENOMEM;
+	cmd->hdr.cmd = WARP_CMD_SET_WIFI_PASS;
+	ret = warp_copy_str_arg(cmd->wifi_pass.pass,
+				sizeof(cmd->wifi_pass.pass), buf, len);
+	if (!ret)
+		ret = warp_exec_cmd(warp, cmd, NULL);
+	kfree(cmd);
+	return ret ? ret : len;
+}
+static DEVICE_ATTR_RW(wifipass);
+
+static ssize_t wifissid_show(struct device *dev,
+			     struct device_attribute *attr, char *buf)
+{
+	int ret;
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_reply *rpl;
+
+	rpl = kmalloc_obj(*rpl);
+	if (!rpl)
+		return -ENOMEM;
+	ret = warp_get_status(warp, rpl);
+	if (ret)
+		goto out;
+	ret = sysfs_emit(buf, "%.*s\n", (int)sizeof(rpl->diag.wifi_ssid),
+			 rpl->diag.wifi_ssid);
+out:
+	kfree(rpl);
+	return ret;
+}
+
+static ssize_t wifissid_store(struct device *dev,
+			      struct device_attribute *attr,
+			      const char *buf, unsigned int len)
+{
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_cmd *cmd;
+	int ret;
+
+	cmd = kzalloc_obj(*cmd);
+	if (!cmd)
+		return -ENOMEM;
+	cmd->hdr.cmd = WARP_CMD_SET_WIFI_SSID;
+	ret = warp_copy_str_arg(cmd->wifi_ssid.ssid,
+				sizeof(cmd->wifi_ssid.ssid), buf, len);
+	if (!ret)
+		ret = warp_exec_cmd(warp, cmd, NULL);
+	kfree(cmd);
+	return ret ? ret : len;
+}
+static DEVICE_ATTR_RW(wifissid);
+
+static const char * const wifistate[] = {
+	[WARP_WIFI_UNKNOWN]		= "Unknown",
+	[WARP_WIFI_STARTED]		= "Started",
+	[WARP_WIFI_STOPPED]		= "Stopped",
+	[WARP_WIFI_CONNECTED]		= "Connected",
+	[WARP_WIFI_DISCONNECTED]	= "Disconnected",
+};
+
+static_assert(ARRAY_SIZE(wifistate) == WARP_WIFI_STATE_COUNT);
+
+static ssize_t wifistate_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	int ret;
+	struct warp_mfd *warp = dev_get_drvdata(dev);
+	union warp_reply *rpl;
+	u32 state;
+
+	rpl = kmalloc_obj(*rpl);
+	if (!rpl)
+		return -ENOMEM;
+	ret = warp_get_status(warp, rpl);
+	if (ret)
+		goto out;
+	state = rpl->diag.wifi_state;
+	ret = sysfs_emit(buf, "%s\n", state < ARRAY_SIZE(wifistate) ?
+				    wifistate[state] : "Invalid");
+out:
+	kfree(rpl);
+	return ret;
+}
+static DEVICE_ATTR_RO(wifistate);
+
 warp_config_string_attr(boardname, board_name);
 warp_config_uint_attr(fanspeedpercent, fan_percent, "%u");
 warp_config_uint_attr(fmwver, fmw_ver, "%04X");
@@ -363,8 +491,11 @@ static struct attribute *warp_attrs[] = {
 	&dev_attr_tarm.attr,
 	&dev_attr_vbatt.attr,
 	&dev_attr_vcc5v.attr,
+	&dev_attr_wifistate.attr,
 	/* RW attr */
 	&dev_attr_kickslot.attr,
+	&dev_attr_wifipass.attr,
+	&dev_attr_wifissid.attr,
 	NULL
 };
 
drivers/zorro/warp-mfd.h +25 -1
index 0633accc980d..1a7a50b6a278 100644
@@ -59,6 +59,8 @@
 enum warp_cmd_id {
 	WARP_CMD_SELECT_KICK	= 5,
 	WARP_CMD_GET_DIAG	= 6,
+	WARP_CMD_SET_WIFI_SSID	= 10,
+	WARP_CMD_SET_WIFI_PASS	= 11,
 };
 
 /* Reply opcodes, as reported in struct warp_rpl_hdr::rpl. */
@@ -67,6 +69,16 @@ enum warp_rpl_id {
 	WARP_RPL_DIAG		= 1,
 };
 
+/* Values reported in struct warp_diag::wifi_state. */
+enum warp_wifi_state {
+	WARP_WIFI_UNKNOWN	= 0,
+	WARP_WIFI_STARTED	= 1,
+	WARP_WIFI_STOPPED	= 2,
+	WARP_WIFI_CONNECTED	= 3,
+	WARP_WIFI_DISCONNECTED	= 4,
+	WARP_WIFI_STATE_COUNT
+};
+
 struct warp_cmd_hdr {
 	u32	cmd;			/* enum warp_cmd_id */
 };
@@ -76,9 +88,21 @@ struct warp_cmd_select_kick {
 	u8			kick_nr;
 };
 
+struct warp_cmd_wifi_ssid {
+	struct warp_cmd_hdr	hdr;
+	char			ssid[WARP_WIFI_SSID_LEN];
+};
+
+struct warp_cmd_wifi_pass {
+	struct warp_cmd_hdr	hdr;
+	char			pass[WARP_WIFI_PASS_LEN];
+};
+
 union warp_cmd {
 	struct warp_cmd_hdr		hdr;
 	struct warp_cmd_select_kick	select_kick;
+	struct warp_cmd_wifi_ssid	wifi_ssid;
+	struct warp_cmd_wifi_pass	wifi_pass;
 };
 
 struct warp_rpl_hdr {
@@ -122,7 +146,7 @@ struct warp_diag {
 	u8			ide_ack_as;
 	s32			tz_corr_secs;		/* obsolete */
 	u8			board_type;
-	u32			wifi_state;
+	u32			wifi_state;		/* enum warp_wifi_state */
 	u32			cpu_freq_mhz;		/* binary32 */
 	u32			cpu_clk_phase_shift_deg; /* binary32 */
 };
Signature · 1 line
2.43.0