Skip to contentSkip to conversation

fsi: aspeed: Access width fixes

PATCH In review Joel Stanley 3 participants 21 messages Oct 31, 2019 – Nov 1, 2019

Subsystems (2)
lore
Share & tools
lore

Joel Stanley

author maintainer
#0 lore raw

v2 cover fsi: aspeed: Access width fixes

Here's v2 of Andrew's series, rewitten with a different approach.

There's also a collection of cleanups that I've been carrying around for a few days. Notably the driver is sparse clean now.

Tested on Tacoma and Qemu.

Andrew Jeffery (1):
fsi: aspeed: Fix endian register to enable single byte reads

Joel Stanley (7):
fsi: aspeed: Implement byte and half word writes
fsi: aspeed: Implement byte and half word reads
fsi: move defines to common header
fsi: aspeed: Fix types in debugfs
fsi: aspeed: Fix link enable
fsi: aspeed: Fix whitespace in check_errors
fsi: aspeed: Use defines for port reset

 drivers/fsi/fsi-master-aspeed.c | 247 +++++++++++++++++---------------
 drivers/fsi/fsi-master-hub.c    |  46 ------
 drivers/fsi/fsi-master.h        |  71 +++++++++
 3 files changed, 200 insertions(+), 164 deletions(-)
Signature · 1 line
2.24.0.rc1
author maintainer
#1 lore raw

PATCH v2 1/8 fsi: aspeed: Implement byte and half word writes

The driver did not previously support non-word size transfers. The fsi-i2c driver attempts accesses of this size, so we require it now.

This creates three functions for doing word, half word and byte writes. This was done to avoid having to decide which length the transfer was twice: both in aspeed_master_write to determine how much of the void * to copy, and again in opb_write to look up the opcode.

It we could have passed the opcode in aspeed_master_write, but this allows the majority of opb_writes in this driver to omit the opcode/size parameter, as most writes are full words. It also means call sites get the types checked.

---
 drivers/fsi/fsi-master-aspeed.c | 77 ++++++++++++++++++++++-----------
 1 file changed, 51 insertions(+), 26 deletions(-)
drivers/fsi/fsi-master-aspeed.c +51 -26
index 97d2cac94291..8d6deb6994fb 100644
@@ -168,23 +168,21 @@ static const u32 fsi_base = 0xa0000000;
 
 /* OPBx_XFER_SIZE */
 #define XFER_WORD	(BIT(1) | BIT(0))
-#define XFER_NIBBLE	(BIT(0))
+#define XFER_HALFWORD	(BIT(0))
 #define XFER_BYTE	(0)
 
 #define CREATE_TRACE_POINTS
 #include <trace/events/fsi_master_aspeed.h>
 
-static u32 opb_write(struct fsi_master_aspeed *aspeed, uint32_t addr,
-		     uint32_t val, size_t size)
+static int __opb_write(struct fsi_master_aspeed *aspeed, u32 addr,
+		       u32 val, u32 transfer_size)
 {
 	void __iomem *base = aspeed->base;
-	u32 reg, ret, status;
-
-	/* TODO: implement other sizes, see 0x18 */
-	WARN_ON(size != 4);
+	u32 reg, status;
+	int ret;
 
 	writel(CMD_WRITE, base + OPB0_RW);
-	writel(XFER_WORD, base + OPB0_XFER_SIZE);
+	writel(transfer_size, base + OPB0_XFER_SIZE);
 	writel(addr, base + OPB0_FSI_ADDR);
 	writel(val, base + OPB0_FSI_DATA_W);
 	writel(0x1, base + OPB_IRQ_CLEAR);
@@ -196,7 +194,7 @@ static u32 opb_write(struct fsi_master_aspeed *aspeed, uint32_t addr,
 
 	status = readl(base + OPB0_STATUS);
 
-	trace_fsi_master_aspeed_opb_write(addr, val, size, status, reg);
+	trace_fsi_master_aspeed_opb_write(addr, val, transfer_size, status, reg);
 
 	/* Return error when poll timed out */
 	if (ret)
@@ -209,6 +207,21 @@ static u32 opb_write(struct fsi_master_aspeed *aspeed, uint32_t addr,
 	return 0;
 }
 
+static int opb_writeb(struct fsi_master_aspeed *aspeed, u32 addr, u8 val)
+{
+	return __opb_write(aspeed, addr, val, XFER_BYTE);
+}
+
+static int opb_writew(struct fsi_master_aspeed *aspeed, u32 addr, __be16 val)
+{
+	return __opb_write(aspeed, addr, (__force u16)val, XFER_HALFWORD);
+}
+
+static int opb_writel(struct fsi_master_aspeed *aspeed, u32 addr, __be32 val)
+{
+	return __opb_write(aspeed, addr, (__force u32)val, XFER_WORD);
+}
+
 static int opb_read(struct fsi_master_aspeed *aspeed, uint32_t addr,
 		    size_t size, u32 *out)
 {
@@ -272,8 +285,8 @@ static int check_errors(struct fsi_master_aspeed *aspeed, int err)
 		/* Check MAEB (0x70) ? */
 
 		/* Then clear errors in master */
-		ret = opb_write(aspeed, ctrl_base + 0xd0,
-				cpu_to_be32(0x20000000), 4);
+		ret = opb_writel(aspeed, ctrl_base + 0xd0,
+				cpu_to_be32(0x20000000));
 		if (ret) {
 			/* TODO: log? return different code? */
 			return ret;
@@ -314,7 +327,20 @@ static int aspeed_master_write(struct fsi_master *master, int link,
 		return -EINVAL;
 
 	addr += link * FSI_HUB_LINK_SIZE;
-	ret = opb_write(aspeed, fsi_base + addr, *(uint32_t *)val, size);
+
+	switch (size) {
+	case 1:
+		ret = opb_writeb(aspeed, fsi_base + addr, *(u8 *)val);
+		break;
+	case 2:
+		ret = opb_writew(aspeed, fsi_base + addr, *(__be16 *)val);
+		break;
+	case 4:
+		ret = opb_writel(aspeed, fsi_base + addr, *(__be32 *)val);
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	ret = check_errors(aspeed, ret);
 	if (ret)
@@ -334,8 +360,7 @@ static int aspeed_master_link_enable(struct fsi_master *master, int link)
 
 	reg = cpu_to_be32(0x80000000 >> bit);
 
-	result = opb_write(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx),
-			reg, 4);
+	result = opb_writel(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx), reg);
 
 	mdelay(FSI_LINK_ENABLE_SETUP_TIME);
 
@@ -415,46 +440,46 @@ static int aspeed_master_init(struct fsi_master_aspeed *aspeed)
 
 	reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK
 			| FSI_MRESP_RST_MCR | FSI_MRESP_RST_PYE);
-	opb_write(aspeed, ctrl_base + FSI_MRESP0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg);
 
 	/* Initialize the MFSI (hub master) engine */
 	reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK
 			| FSI_MRESP_RST_MCR | FSI_MRESP_RST_PYE);
-	opb_write(aspeed, ctrl_base + FSI_MRESP0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg);
 
 	reg = cpu_to_be32(FSI_MECTRL_EOAE | FSI_MECTRL_P8_AUTO_TERM);
-	opb_write(aspeed, ctrl_base + FSI_MECTRL, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MECTRL, reg);
 
 	reg = cpu_to_be32(FSI_MMODE_ECRC | FSI_MMODE_EPC | FSI_MMODE_RELA
 			| fsi_mmode_crs0(DEFAULT_DIVISOR)
 			| fsi_mmode_crs1(DEFAULT_DIVISOR)
 			| FSI_MMODE_P8_TO_LSB);
-	opb_write(aspeed, ctrl_base + FSI_MMODE, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MMODE, reg);
 
 	reg = cpu_to_be32(0xffff0000);
-	opb_write(aspeed, ctrl_base + FSI_MDLYR, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MDLYR, reg);
 
 	reg = cpu_to_be32(~0);
-	opb_write(aspeed, ctrl_base + FSI_MSENP0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MSENP0, reg);
 
 	/* Leave enabled long enough for master logic to set up */
 	mdelay(FSI_LINK_ENABLE_SETUP_TIME);
 
-	opb_write(aspeed, ctrl_base + FSI_MCENP0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MCENP0, reg);
 
 	opb_read(aspeed, ctrl_base + FSI_MAEB, 4, NULL);
 
 	reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK);
-	opb_write(aspeed, ctrl_base + FSI_MRESP0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg);
 
 	opb_read(aspeed, ctrl_base + FSI_MLEVP0, 4, NULL);
 
 	/* Reset the master bridge */
 	reg = cpu_to_be32(FSI_MRESB_RST_GEN);
-	opb_write(aspeed, ctrl_base + FSI_MRESB0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MRESB0, reg);
 
 	reg = cpu_to_be32(FSI_MRESB_RST_ERR);
-	opb_write(aspeed, ctrl_base + FSI_MRESB0, reg, 4);
+	opb_writel(aspeed, ctrl_base + FSI_MRESB0, reg);
 
 	return 0;
 }
@@ -478,7 +503,7 @@ static int fsi_master_aspeed_debugfs_set(void *data, u64 val)
 	u32 in = cpu_to_be32((u32)(val & 0xFFFFFFFFULL));
 	struct fsi_master_aspeed_debugfs_entry *entry = data;
 
-	rc = opb_write(entry->aspeed, ctrl_base + entry->addr, in, 4);
+	rc = opb_writel(entry->aspeed, ctrl_base + entry->addr, in);
 	if (rc)
 		return rc;
 
@@ -521,7 +546,7 @@ static int fsi_master_aspeed_clock_debugfs_set(void *data, u64 val)
 	reg &= ~(0x3ff << 18);
 	reg |= (val & 0x3ff) << 18;
 
-	rc = opb_write(aspeed, ctrl_base, cpu_to_be32(reg), 4);
+	rc = opb_writel(aspeed, ctrl_base, cpu_to_be32(reg));
 	if (rc)
 		return rc;
 
Signature · 1 line
2.24.0.rc1
Acked-by on v2 1/8
#2 lore raw

Re: [PATCH linux dev-5.3 v2 1/8] fsi: aspeed: Implement byte and half word writes

Hi Joel,

Quoted 7 lines

The driver did not previously support non-word size transfers. The fsi-i2c driver attempts accesses of this size, so we require it now.

This creates three functions for doing word, half word and byte writes. This was done to avoid having to decide which length the transfer was twice: both in aspeed_master_write to determine how much of the void * to copy, and again in opb_write to look up the opcode.

Looks good. I was wondering about doing only the writes in this format, but then I saw patch 2/8 (would it make sense to combine these?).

Regardless:

Cheers,

Jeremy

author maintainer
#3 lore raw

Re: [PATCH linux dev-5.3 v2 1/8] fsi: aspeed: Implement byte and half word writes

Quoted 6 lines · Jeremy Kerr

Hi Joel,

Quoted 3 lines

The driver did not previously support non-word size transfers. The fsi-i2c driver attempts accesses of this size, so we require it now.

Quoted 7 lines
Quoted 4 lines

This creates three functions for doing word, half word and byte writes. This was done to avoid having to decide which length the transfer was twice: both in aspeed_master_write to determine how much of the void * to copy, and again in opb_write to look up the opcode.

Looks good. I was wondering about doing only the writes in this format, but then I saw patch 2/8 (would it make sense to combine these?).

I was wondering at what point we merge this driver upstream, and if it's worthwhile keeping the history.

The major pending TODO is error handling.

Quoted 10 lines

Regardless:

Cheers,

Jeremy

author maintainer
#4 lore raw

PATCH v2 2/8 fsi: aspeed: Implement byte and half word reads

In reply to Joel Stanley

A similar rationale to the writes, where we create helpers for each size to ensure the callee gets type checking and allows the lookup of the size to be done once, in aspeed_master_read.

---
 drivers/fsi/fsi-master-aspeed.c | 80 ++++++++++++++++++++++++---------
 1 file changed, 59 insertions(+), 21 deletions(-)
drivers/fsi/fsi-master-aspeed.c +59 -21
index 8d6deb6994fb..b520f5df567c 100644
@@ -222,18 +222,15 @@ static int opb_writel(struct fsi_master_aspeed *aspeed, u32 addr, __be32 val)
 	return __opb_write(aspeed, addr, (__force u32)val, XFER_WORD);
 }
 
-static int opb_read(struct fsi_master_aspeed *aspeed, uint32_t addr,
-		    size_t size, u32 *out)
+static int __opb_read(struct fsi_master_aspeed *aspeed, uint32_t addr,
+		      u32 transfer_size, void *out)
 {
 	void __iomem *base = aspeed->base;
 	u32 result, reg;
 	int status, ret;
 
-	/* TODO: implement other sizes, see 0x18 */
-	WARN_ON(size != 4);
-
 	writel(CMD_READ, base + OPB0_RW);
-	writel(XFER_WORD, base + OPB0_XFER_SIZE);
+	writel(transfer_size, base + OPB0_XFER_SIZE);
 	writel(addr, base + OPB0_FSI_ADDR);
 	writel(0x1, base + OPB_IRQ_CLEAR);
 	writel(0x1, base + OPB_TRIGGER);
@@ -246,7 +243,7 @@ static int opb_read(struct fsi_master_aspeed *aspeed, uint32_t addr,
 
 	result = readl(base + OPB0_FSI_DATA_R);
 
-	trace_fsi_master_aspeed_opb_read(addr, size, result,
+	trace_fsi_master_aspeed_opb_read(addr, transfer_size, result,
 			readl(base + OPB0_STATUS),
 			reg);
 
@@ -258,12 +255,41 @@ static int opb_read(struct fsi_master_aspeed *aspeed, uint32_t addr,
 	if (status & STATUS_ERR_ACK)
 		return -EIO;
 
-	if (out)
-		*out = result;
+	if (out) {
+		switch (transfer_size) {
+		case XFER_BYTE:
+			*(u8 *)out = result;
+			break;
+		case XFER_HALFWORD:
+			*(u16 *)out = result;
+			break;
+		case XFER_WORD:
+			*(u32 *)out = result;
+			break;
+		default:
+			return -EINVAL;
+		}
+
+	}
 
 	return 0;
 }
 
+static int opb_readl(struct fsi_master_aspeed *aspeed, uint32_t addr, __be32 *out)
+{
+	return __opb_read(aspeed, addr, XFER_WORD, out);
+}
+
+static int opb_readw(struct fsi_master_aspeed *aspeed, uint32_t addr, __be16 *out)
+{
+	return __opb_read(aspeed, addr, XFER_HALFWORD, (void *)out);
+}
+
+static int opb_readb(struct fsi_master_aspeed *aspeed, uint32_t addr, u8 *out)
+{
+	return __opb_read(aspeed, addr, XFER_BYTE, (void *)out);
+}
+
 static int check_errors(struct fsi_master_aspeed *aspeed, int err)
 {
 	int ret;
@@ -271,9 +297,9 @@ static int check_errors(struct fsi_master_aspeed *aspeed, int err)
 	 if (trace_fsi_master_aspeed_opb_error_enabled()) {
 		 __be32 mresp0, mstap0, mesrb0;
 
-		 opb_read(aspeed, ctrl_base + FSI_MRESP0, 4, &mresp0);
-		 opb_read(aspeed, ctrl_base + FSI_MSTAP0, 4, &mstap0);
-		 opb_read(aspeed, ctrl_base + FSI_MESRB0, 4, &mesrb0);
+		 opb_readl(aspeed, ctrl_base + FSI_MRESP0, &mresp0);
+		 opb_readl(aspeed, ctrl_base + FSI_MSTAP0, &mstap0);
+		 opb_readl(aspeed, ctrl_base + FSI_MESRB0, &mesrb0);
 
 		 trace_fsi_master_aspeed_opb_error(
 				 be32_to_cpu(mresp0),
@@ -308,7 +334,20 @@ static int aspeed_master_read(struct fsi_master *master, int link,
 		return -EINVAL;
 
 	addr += link * FSI_HUB_LINK_SIZE;
-	ret = opb_read(aspeed, fsi_base + addr, size, val);
+
+	switch (size) {
+	case 1:
+		ret = opb_readb(aspeed, fsi_base + addr, val);
+		break;
+	case 2:
+		ret = opb_readw(aspeed, fsi_base + addr, val);
+		break;
+	case 4:
+		ret = opb_readl(aspeed, fsi_base + addr, val);
+		break;
+	default:
+		return -EINVAL;
+	}
 
 	ret = check_errors(aspeed, ret);
 	if (ret)
@@ -364,8 +403,7 @@ static int aspeed_master_link_enable(struct fsi_master *master, int link)
 
 	mdelay(FSI_LINK_ENABLE_SETUP_TIME);
 
-	ret = opb_read(aspeed, ctrl_base + FSI_MENP0 + (4 * idx),
-			4, &result);
+	ret = opb_readl(aspeed, ctrl_base + FSI_MENP0 + (4 * idx), &result);
 	if (ret)
 		return ret;
 
@@ -467,12 +505,12 @@ static int aspeed_master_init(struct fsi_master_aspeed *aspeed)
 
 	opb_writel(aspeed, ctrl_base + FSI_MCENP0, reg);
 
-	opb_read(aspeed, ctrl_base + FSI_MAEB, 4, NULL);
+	opb_readl(aspeed, ctrl_base + FSI_MAEB, NULL);
 
 	reg = cpu_to_be32(FSI_MRESP_RST_ALL_MASTER | FSI_MRESP_RST_ALL_LINK);
 	opb_writel(aspeed, ctrl_base + FSI_MRESP0, reg);
 
-	opb_read(aspeed, ctrl_base + FSI_MLEVP0, 4, NULL);
+	opb_readl(aspeed, ctrl_base + FSI_MLEVP0, NULL);
 
 	/* Reset the master bridge */
 	reg = cpu_to_be32(FSI_MRESB_RST_GEN);
@@ -490,7 +528,7 @@ static int fsi_master_aspeed_debugfs_get(void *data, u64 *val)
 	u32 out;
 	struct fsi_master_aspeed_debugfs_entry *entry = data;
 
-	rc = opb_read(entry->aspeed, ctrl_base + entry->addr, 4, &out);
+	rc = opb_readl(entry->aspeed, ctrl_base + entry->addr, &out);
 	if (rc)
 		return rc;
 
@@ -519,7 +557,7 @@ static int fsi_master_aspeed_clock_debugfs_get(void *data, u64 *val)
 	u32 out;
 	int rc;
 
-	rc = opb_read(aspeed, ctrl_base, 4, &out);
+	rc = opb_readl(aspeed, ctrl_base, &out);
 	if (rc)
 		return rc;
 
@@ -537,7 +575,7 @@ static int fsi_master_aspeed_clock_debugfs_set(void *data, u64 val)
 	if (val > 0x3ff)
 		return -EINVAL;
 
-	rc = opb_read(aspeed, ctrl_base, 4, &raw);
+	rc = opb_readl(aspeed, ctrl_base, &raw);
 	if (rc)
 		return rc;
 
@@ -610,7 +648,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	 */
 	writel(0x1, aspeed->base + OPB0_SELECT);
 
-	rc = opb_read(aspeed, ctrl_base + FSI_MVER, 4, &raw);
+	rc = opb_readl(aspeed, ctrl_base + FSI_MVER, &raw);
 	if (rc) {
 		dev_err(&pdev->dev, "failed to read hub version\n");
 		return rc;
Signature · 1 line
2.24.0.rc1
Reviewed-by on v2 2/8
#5 lore raw

Re: [PATCH linux dev-5.3 v2 2/8] fsi: aspeed: Implement byte and half word reads

Quoted 5 lines · Joel Stanley

A similar rationale to the writes, where we create helpers for each size to ensure the callee gets type checking and allows the lookup of the size to be done once, in aspeed_master_read.

author maintainer
#6 lore raw

PATCH v2 3/8 fsi: aspeed: Fix endian register to enable single byte reads

In reply to Joel Stanley

From: Andrew Jeffery <[email protected]>

The endian register controls where the incoming bytes end up in the data register. Currently reading single bytes is broken, and reading half words is causes the data to appear in both the upper and lower part of the register.

The current value of the OPB0 read order selection register caused a data read register value of 0xffffffff to be read for single byte accesses over FSI. A value of 0x03 for the read order byte-access slot correctly "swaps" the BE MSB value to the LE LSB for extraction by the APB2OPB bridge:

    # devmem 0x1e79b05c
    0x00030B1B
    # dd if=raw bs=1 count=1 | hexdump -C
        fsi_master_read: fsi0:00:00 00000000[1]
         opb read: addr a0000000 size 1: result ffffffc0 status: 00000000 irq_status: 00010000
         opb read: addr 800000d0 size 4: result 00000000 status: 00000002 irq_status: 00010000
         opb read: addr 800000d0 size 4: result 00000000 status: 00000002 irq_status: 00010000
         opb read: addr 800001d0 size 4: result 00000000 status: 00000002 irq_status: 00010000
         mresp0 00000000 mstap0 00000000 mesrb0 00000000
        fsi_master_rw_result: fsi0:00:00 00000000[1] => {c0} ret 0
    1+0 records in
    1+0 records out
    00000000  c0                                                |.|
    00000001

This fixes half-word access read order selection in the same manner.

---
 drivers/fsi/fsi-master-aspeed.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/fsi/fsi-master-aspeed.c +1 -1
index b520f5df567c..5b947c70c0f9 100644
@@ -635,7 +635,7 @@ static int fsi_master_aspeed_probe(struct platform_device *pdev)
 	writel(fsi_base, aspeed->base + OPB_FSI_BASE);
 
 	/* Set read data order */
-	writel(0x0011bb1b, aspeed->base + OPB0_R_ENDIAN);
+	writel(0x00030b1b, aspeed->base + OPB0_R_ENDIAN);
 
 	/* Set write data order */
 	writel(0x0011bb1b, aspeed->base + OPB0_W_ENDIAN);
Signature · 1 line
2.24.0.rc1
author maintainer
#7 lore raw

PATCH v2 4/8 fsi: move defines to common header

In reply to Joel Stanley

The FSI master registers are common to the hub and AST2600 master (and the FSP2, if someone was to upstream a driver for that).

Add defines to the fsi-master.h header, and introduce headings to delineate the existing low level details.

---
 drivers/fsi/fsi-master-aspeed.c | 55 -------------------------
 drivers/fsi/fsi-master-hub.c    | 46 ---------------------
 drivers/fsi/fsi-master.h        | 71 +++++++++++++++++++++++++++++++++
 3 files changed, 71 insertions(+), 101 deletions(-)
drivers/fsi/fsi-master-aspeed.c +0 -55
index 5b947c70c0f9..e38e1c2c4f15 100644
@@ -17,61 +17,6 @@
 
 #include "fsi-master.h"
 
-/* TODO: these are copied from the hub master. Put them in a common header */
-
-/* Control Registers */
-#define FSI_MMODE		0x0		/* R/W: mode */
-#define FSI_MDLYR		0x4		/* R/W: delay */
-#define FSI_MCRSP		0x8		/* R/W: clock rate */
-#define FSI_MENP0		0x10		/* R/W: enable */
-#define FSI_MLEVP0		0x18		/* R: plug detect */
-#define FSI_MSENP0		0x18		/* S: Set enable */
-#define FSI_MCENP0		0x20		/* C: Clear enable */
-#define FSI_MAEB		0x70		/* R: Error address */
-#define FSI_MVER		0x74		/* R: master version/type */
-#define FSI_MSTAP0		0xd0		/* R: Port status */
-#define FSI_MRESP0		0xd0		/* W: Port reset */
-#define FSI_MESRB0		0x1d0		/* R: Master error status */
-#define FSI_MRESB0		0x1d0		/* W: Reset bridge */
-#define FSI_MSCSB0	 	0x1d4		/* R: Master sub command stack */
-#define FSI_MATRB0	 	0x1d8		/* R: Master address trace */
-#define FSI_MDTRB0	 	0x1dc		/* R: Master data trace */
-#define FSI_MECTRL		0x2e0		/* W: Error control */
-
-/* MMODE: Mode control */
-#define FSI_MMODE_EIP		0x80000000	/* Enable interrupt polling */
-#define FSI_MMODE_ECRC		0x40000000	/* Enable error recovery */
-#define FSI_MMODE_RELA		0x20000000	/* Enable relative address commands */
-#define FSI_MMODE_EPC		0x10000000	/* Enable parity checking */
-#define FSI_MMODE_P8_TO_LSB	0x00000010	/* Timeout value LSB */
-						/*   MSB=1, LSB=0 is 0.8 ms */
-						/*   MSB=0, LSB=1 is 0.9 ms */
-#define FSI_MMODE_CRS0SHFT	18		/* Clk rate selection 0 shift */
-#define FSI_MMODE_CRS0MASK	0x3ff		/* Clk rate selection 0 mask */
-#define FSI_MMODE_CRS1SHFT	8		/* Clk rate selection 1 shift */
-#define FSI_MMODE_CRS1MASK	0x3ff		/* Clk rate selection 1 mask */
-
-/* MRESB: Reset brindge */
-#define FSI_MRESB_RST_GEN	0x80000000	/* General reset */
-#define FSI_MRESB_RST_ERR	0x40000000	/* Error Reset */
-
-/* MRESB: Reset port */
-#define FSI_MRESP_RST_ALL_MASTER 0x20000000	/* Reset all FSI masters */
-#define FSI_MRESP_RST_ALL_LINK	0x10000000	/* Reset all FSI port contr. */
-#define FSI_MRESP_RST_MCR	0x08000000	/* Reset FSI master reg. */
-#define FSI_MRESP_RST_PYE	0x04000000	/* Reset FSI parity error */
-#define FSI_MRESP_RST_ALL	0xfc000000	/* Reset any error */
-
-/* MECTRL: Error control */
-#define FSI_MECTRL_EOAE		0x8000		/* Enable machine check when */
-						/* master 0 in error */
-#define FSI_MECTRL_P8_AUTO_TERM	0x4000		/* Auto terminate */
-
-#define FSI_ENGID_HUB_MASTER		0x1c
-#define FSI_HUB_LINK_OFFSET		0x80000
-#define FSI_HUB_LINK_SIZE		0x80000
-#define FSI_HUB_MASTER_MAX_LINKS	8
-
 #define FSI_LINK_ENABLE_SETUP_TIME	10	/* in mS */
 
 #define FSI_NUM_DEBUGFS_ENTRIES		17
drivers/fsi/fsi-master-hub.c +0 -46

53 lines not on this page · raw message

drivers/fsi/fsi-master.h +71 -0

83 lines not on this page · raw message

Signature · 1 line
2.24.0.rc1
Acked-by on v2 4/8
#8 lore raw

Re: [PATCH linux dev-5.3 v2 4/8] fsi: move defines to common header

Quoted 7 lines · Joel Stanley

The FSI master registers are common to the hub and AST2600 master (and the FSP2, if someone was to upstream a driver for that).

Add defines to the fsi-master.h header, and introduce headings to delineate the existing low level details.

Acked-by on v2 4/8
#9 lore raw

Re: [PATCH linux dev-5.3 v2 4/8] fsi: move defines to common header

In reply to Joel Stanley

Hi Joel,

Quoted 5 lines

The FSI master registers are common to the hub and AST2600 master (and the FSP2, if someone was to upstream a driver for that).

Add defines to the fsi-master.h header, and introduce headings to delineate the existing low level details.

I'm in two minds about this - it's a specific hardware master implementation, while fsi-master.h is for the generic core API.

That said, it's probably neater than introducing a new header here, so:

Maybe a potential future change: a unified driver that handles this common hardware, just with different register interface implementations?

Cheers,

Jeremy

author maintainer
#10 lore raw

Re: [PATCH linux dev-5.3 v2 4/8] fsi: move defines to common header

Quoted 11 lines · Jeremy Kerr

Hi Joel,

Quoted 5 lines

The FSI master registers are common to the hub and AST2600 master (and the FSP2, if someone was to upstream a driver for that).

Add defines to the fsi-master.h header, and introduce headings to delineate the existing low level details.

I'm in two minds about this - it's a specific hardware master implementation, while fsi-master.h is for the generic core API.

It's a bit messy already, as a bunch of the defines in there are for the soft FSI drivers. I could create two new headers, one for the soft masters, and one for the hardware ones.

Quoted 6 lines

That said, it's probably neater than introducing a new header here, so:

Maybe a potential future change: a unified driver that handles this common hardware, just with different register interface implementations?

That would be cool. It would also make it less work to do a FSP driver.

Thanks for the review.

author maintainer
#11 lore raw

PATCH v2 5/8 fsi: aspeed: Fix types in debugfs

In reply to Joel Stanley
---
 drivers/fsi/fsi-master-aspeed.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/fsi/fsi-master-aspeed.c +10 -9
index e38e1c2c4f15..8f757eaa6a55 100644
@@ -469,9 +469,9 @@ static int aspeed_master_init(struct fsi_master_aspeed *aspeed)
 
 static int fsi_master_aspeed_debugfs_get(void *data, u64 *val)
 {
-	int rc;
-	u32 out;
 	struct fsi_master_aspeed_debugfs_entry *entry = data;
+	__be32 out;
+	int rc;
 
 	rc = opb_readl(entry->aspeed, ctrl_base + entry->addr, &out);
 	if (rc)
@@ -482,11 +482,11 @@ static int fsi_master_aspeed_debugfs_get(void *data, u64 *val)
 }
 static int fsi_master_aspeed_debugfs_set(void *data, u64 val)
 {
-	u32 rc;
-	u32 in = cpu_to_be32((u32)(val & 0xFFFFFFFFULL));
 	struct fsi_master_aspeed_debugfs_entry *entry = data;
+	int rc;
 
-	rc = opb_writel(entry->aspeed, ctrl_base + entry->addr, in);
+	rc = opb_writel(entry->aspeed, ctrl_base + entry->addr,
+			cpu_to_be32(val));
 	if (rc)
 		return rc;
 
@@ -499,14 +499,14 @@ DEFINE_DEBUGFS_ATTRIBUTE(fsi_master_aspeed_debugfs_ops,
 static int fsi_master_aspeed_clock_debugfs_get(void *data, u64 *val)
 {
 	struct fsi_master_aspeed *aspeed = data;
-	u32 out;
+	__be32 out;
 	int rc;
 
 	rc = opb_readl(aspeed, ctrl_base, &out);
 	if (rc)
 		return rc;
 
-	*val = (u64)((be32_to_cpu(out) >> 18) & 0x3ff);
+	*val = (be32_to_cpu(out) >> FSI_MMODE_CRS0SHFT) & FSI_MMODE_CRS0MASK;
 
 	return 0;
 }
@@ -526,8 +526,9 @@ static int fsi_master_aspeed_clock_debugfs_set(void *data, u64 val)
 
 	reg = be32_to_cpu(raw);
 
-	reg &= ~(0x3ff << 18);
-	reg |= (val & 0x3ff) << 18;
+
+	reg &= ~(FSI_MMODE_CRS0MASK << FSI_MMODE_CRS0SHFT);
+	reg |= fsi_mmode_crs0(val);
 
 	rc = opb_writel(aspeed, ctrl_base, cpu_to_be32(reg));
 	if (rc)
Signature · 1 line
2.24.0.rc1
author maintainer
#14 lore raw

PATCH v2 6/8 fsi: aspeed: Fix link enable

In reply to Joel Stanley

Link enable was saving the value of the write to result, which was not checked. It should either have been ignoring the result of the write, or erroring out if it failed. This chose to error out.

---
 drivers/fsi/fsi-master-aspeed.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/fsi/fsi-master-aspeed.c +3 -1
index 8f757eaa6a55..ee760e84c576 100644
@@ -344,7 +344,9 @@ static int aspeed_master_link_enable(struct fsi_master *master, int link)
 
 	reg = cpu_to_be32(0x80000000 >> bit);
 
-	result = opb_writel(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx), reg);
+	ret = opb_writel(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx), reg);
+	if (ret)
+		return ret;
 
 	mdelay(FSI_LINK_ENABLE_SETUP_TIME);
 
Signature · 1 line
2.24.0.rc1
Reviewed-by on v2 6/8
#15 lore raw

Re: [PATCH linux dev-5.3 v2 6/8] fsi: aspeed: Fix link enable

Quoted 5 lines · Joel Stanley

Link enable was saving the value of the write to result, which was not checked. It should either have been ignoring the result of the write, or erroring out if it failed. This chose to error out.

Lolled-by^W

Quoted 18 lines
---
 drivers/fsi/fsi-master-aspeed.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/fsi/fsi-master-aspeed.c +3 -1
index 8f757eaa6a55..ee760e84c576 100644
@@ -344,7 +344,9 @@ static int aspeed_master_link_enable(struct 
 fsi_master *master, int link)
 
 	reg = cpu_to_be32(0x80000000 >> bit);
 
-	result = opb_writel(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx), reg);
+	ret = opb_writel(aspeed, ctrl_base + FSI_MSENP0 + (4 * idx), reg);
+	if (ret)
+		return ret;
#16 lore raw

Re: [PATCH linux dev-5.3 v2 6/8] fsi: aspeed: Fix link enable

In reply to Joel Stanley

Hi Joel,

Quoted 3 lines

Link enable was saving the value of the write to result, which was not checked. It should either have been ignoring the result of the write, or erroring out if it failed. This chose to error out.

The fix looks good, but should we do this before the introduction of the readl/writel changes?

Also, it looks like the previous code using both 'reg' and 'ret' as variable names might be a path to future confusion, maybe we should avoid that.

Cheers,

Jeremy

author maintainer
#17 lore raw

PATCH v2 7/8 fsi: aspeed: Fix whitespace in check_errors

In reply to Joel Stanley
---
 drivers/fsi/fsi-master-aspeed.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
drivers/fsi/fsi-master-aspeed.c +12 -12
index ee760e84c576..686380414fba 100644
@@ -239,18 +239,18 @@ static int check_errors(struct fsi_master_aspeed *aspeed, int err)
 {
 	int ret;
 
-	 if (trace_fsi_master_aspeed_opb_error_enabled()) {
-		 __be32 mresp0, mstap0, mesrb0;
-
-		 opb_readl(aspeed, ctrl_base + FSI_MRESP0, &mresp0);
-		 opb_readl(aspeed, ctrl_base + FSI_MSTAP0, &mstap0);
-		 opb_readl(aspeed, ctrl_base + FSI_MESRB0, &mesrb0);
-
-		 trace_fsi_master_aspeed_opb_error(
-				 be32_to_cpu(mresp0),
-				 be32_to_cpu(mstap0),
-				 be32_to_cpu(mesrb0));
-	 };
+	if (trace_fsi_master_aspeed_opb_error_enabled()) {
+		__be32 mresp0, mstap0, mesrb0;
+
+		opb_readl(aspeed, ctrl_base + FSI_MRESP0, &mresp0);
+		opb_readl(aspeed, ctrl_base + FSI_MSTAP0, &mstap0);
+		opb_readl(aspeed, ctrl_base + FSI_MESRB0, &mesrb0);
+
+		trace_fsi_master_aspeed_opb_error(
+				be32_to_cpu(mresp0),
+				be32_to_cpu(mstap0),
+				be32_to_cpu(mesrb0));
+	};
 
 	if (err == -EIO) {
 		/* Check MAEB (0x70) ? */
Signature · 1 line
2.24.0.rc1
author maintainer
#19 lore raw

PATCH v2 8/8 fsi: aspeed: Use defines for port reset

In reply to Joel Stanley
---
 drivers/fsi/fsi-master-aspeed.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fsi/fsi-master-aspeed.c +2 -2
index 686380414fba..595350800406 100644
@@ -256,8 +256,8 @@ static int check_errors(struct fsi_master_aspeed *aspeed, int err)
 		/* Check MAEB (0x70) ? */
 
 		/* Then clear errors in master */
-		ret = opb_writel(aspeed, ctrl_base + 0xd0,
-				cpu_to_be32(0x20000000));
+		ret = opb_writel(aspeed, ctrl_base + FSI_MRESP0,
+				cpu_to_be32(FSI_MRESP_RST_ALL_MASTER));
 		if (ret) {
 			/* TODO: log? return different code? */
 			return ret;
Signature · 1 line
2.24.0.rc1