Skip to contentSkip to conversation

SMC driver updates

PATCH In review Cédric Le Goater 2 participants 9 messages Oct 9, 2017 – Oct 10, 2017

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

cover SMC driver updates

Hello,

Here is a series bringing the Aspeed SMC driver to the level of what we had in openbmc kernel 4.10. There are a couple of changes :

- the DMA support is gone. It is not used, it only works for kmalloc'ed buffers and UBIFS uses vmalloc'ed buffers for instance.

- the driver was slightly adapted to take into account the new clk driver.

Tested on a palmetto and an ast2500 eval boards.

Thanks,

C.

Cédric Le Goater (6):
ARM: dts: aspeed: import OpenBMC flash layout
mtd: spi-nor: aspeed: use command mode for reads
mtd: spi-nor: aspeed: add support for SPI dual IO read mode
ARM: dts: aspeed: add a AHB clock to the G4 SMC controllers
mtd: spi-nor: aspeed: link controller with the ahb clock
mtd: spi-nor: aspeed: optimize read mode

 arch/arm/boot/dts/aspeed-ast2500-evb.dts           |   1 +
 arch/arm/boot/dts/aspeed-bmc-opp-flash-layout.dtsi |  26 ++
 arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts      |   1 +
 arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts       |   2 +
 arch/arm/boot/dts/aspeed-g4.dtsi                   |   2 +
 drivers/mtd/spi-nor/aspeed-smc.c                   | 283 ++++++++++++++++++++-
 6 files changed, 303 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/boot/dts/aspeed-bmc-opp-flash-layout.dtsi
Signature · 1 line
2.13.6
#1 lore raw

PATCH 1/6 ARM: dts: aspeed: import OpenBMC flash layout

---
 arch/arm/boot/dts/aspeed-ast2500-evb.dts           |  1 +
 arch/arm/boot/dts/aspeed-bmc-opp-flash-layout.dtsi | 26 ++++++++++++++++++++++
 arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts      |  1 +
 arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts       |  2 ++
 4 files changed, 30 insertions(+)
 create mode 100644 arch/arm/boot/dts/aspeed-bmc-opp-flash-layout.dtsi
arch/arm/boot/dts/aspeed-ast2500-evb.dts +1 -0
index dc7d73b02b76..68fd0ec54f3e 100644
@@ -26,6 +26,7 @@
 		status = "okay";
 		m25p,fast-read;
 		label = "bmc";
+#include "aspeed-bmc-opp-flash-layout.dtsi"
 	};
 };
 
arch/arm/boot/dts/aspeed-bmc-opp-flash-layout.dtsi new file +26 -0
new file mode 100644
index 000000000000..4bcfd1bf8dc5
@@ -0,0 +1,26 @@
+		label = "bmc";
+		partitions {
+				#address-cells = < 1 >;
+				#size-cells = < 1 >;
+				compatible = "fixed-partitions";
+				u-boot@0 {
+					reg = < 0 0x60000 >;
+					label = "u-boot";
+				};
+				u-boot-env@60000 {
+					reg = < 0x60000 0x20000 >;
+					label = "u-boot-env";
+				};
+				kernel@80000 {
+					reg = < 0x80000 0x440000 >;
+					label = "kernel";
+				};
+				rofs@0c0000 {
+					reg = < 0x4c0000 0x1740000 >;
+					label = "rofs";
+				};
+				rwfs@1c00000 {
+					reg = < 0x1c00000 0x400000 >;
+					label = "rwfs";
+				};
+		};
arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dts +1 -0
index e61cac42e2f5..baf9b02d66b6 100644
@@ -33,6 +33,7 @@
 		status = "okay";
 		m25p,fast-read;
 		label = "bmc";
+#include "aspeed-bmc-opp-flash-layout.dtsi"
 	};
 };
 
arch/arm/boot/dts/aspeed-bmc-opp-romulus.dts +2 -0
index 5d543d64ace9..440b010a9652 100644
@@ -37,6 +37,8 @@
 		status = "okay";
 		m25p,fast-read;
 		label = "bmc";
+#include "aspeed-bmc-opp-flash-layout.dtsi"
+
 	};
 };
 
Signature · 1 line
2.13.6
#2 lore raw

PATCH 2/6 mtd: spi-nor: aspeed: use command mode for reads

In reply to Cédric Le Goater

When reading flash contents, try to use the "command mode" if the AHB window configured for the flash module is big enough. Else, just fall back to the "user mode" to perform the read.

---
 drivers/mtd/spi-nor/aspeed-smc.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
drivers/mtd/spi-nor/aspeed-smc.c +27 -1
index 8d3cbe27efb6..b68cd7e65b71 100644
@@ -402,6 +402,31 @@ static ssize_t aspeed_smc_write_user(struct spi_nor *nor, loff_t to,
 	return len;
 }
 
+static ssize_t aspeed_smc_read(struct spi_nor *nor, loff_t from, size_t len,
+			       u_char *read_buf)
+{
+	struct aspeed_smc_chip *chip = nor->priv;
+
+	/*
+	 * The AHB window configured for the chip is too small for the
+	 * read offset. Use the "User mode" of the controller to
+	 * perform the read.
+	 */
+	if (from >= chip->ahb_window_size) {
+		aspeed_smc_read_user(nor, from, len, read_buf);
+		goto out;
+	}
+
+	/*
+	 * Use the "Command mode" to do a direct read from the AHB
+	 * window configured for the chip. This should be the default.
+	 */
+	memcpy_fromio(read_buf, chip->ahb_base + from, len);
+
+out:
+	return len;
+}
+
 static int aspeed_smc_unregister(struct aspeed_smc_controller *controller)
 {
 	struct aspeed_smc_chip *chip;
@@ -743,6 +768,7 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)
 	}
 
 	chip->ctl_val[smc_read] |= cmd |
+		chip->nor.read_opcode << CONTROL_COMMAND_SHIFT |
 		CONTROL_IO_DUMMY_SET(chip->nor.read_dummy / 8);
 
 	dev_dbg(controller->dev, "base control register: %08x\n",
@@ -809,7 +835,7 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller,
 		nor->dev = dev;
 		nor->priv = chip;
 		spi_nor_set_flash_node(nor, child);
-		nor->read = aspeed_smc_read_user;
+		nor->read = aspeed_smc_read;
 		nor->write = aspeed_smc_write_user;
 		nor->read_reg = aspeed_smc_read_reg;
 		nor->write_reg = aspeed_smc_write_reg;
Signature · 1 line
2.13.6
#3 lore raw

PATCH 3/6 mtd: spi-nor: aspeed: add support for SPI dual IO read mode

In reply to Cédric Le Goater

Implements support for the dual IO read mode on aspeed SMC/FMC controllers which uses both MISO and MOSI lines for data during a read to double the read bandwidth.

Still to be done SNOR_PROTO_1_2_2

Based on work from Robert Lippert <[email protected]>

---
 drivers/mtd/spi-nor/aspeed-smc.c | 54 ++++++++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 11 deletions(-)
drivers/mtd/spi-nor/aspeed-smc.c +43 -11
index b68cd7e65b71..ac27a5109f6d 100644
@@ -373,18 +373,49 @@ static void aspeed_smc_send_cmd_addr(struct spi_nor *nor, u8 cmd, u32 addr)
 	}
 }
 
+static int aspeed_smc_get_io_mode(struct aspeed_smc_chip *chip)
+{
+	switch (chip->nor.read_proto) {
+	case SNOR_PROTO_1_1_1:
+		return 0;
+	case SNOR_PROTO_1_1_2:
+		return CONTROL_IO_DUAL_DATA;
+	case SNOR_PROTO_1_2_2:
+		return CONTROL_IO_DUAL_ADDR_DATA;
+	default:
+		dev_err(chip->nor.dev, "unsupported SPI read mode\n");
+		return -EINVAL;
+	}
+}
+
+static void aspeed_smc_set_io_mode(struct aspeed_smc_chip *chip, u32 io_mode)
+{
+	u32 ctl;
+
+	if (io_mode > 0) {
+		ctl = readl(chip->ctl) & ~CONTROL_IO_MODE_MASK;
+		ctl |= io_mode;
+		writel(ctl, chip->ctl);
+	}
+}
+
 static ssize_t aspeed_smc_read_user(struct spi_nor *nor, loff_t from,
 				    size_t len, u_char *read_buf)
 {
 	struct aspeed_smc_chip *chip = nor->priv;
 	int i;
 	u8 dummy = 0xFF;
+	int io_mode = aspeed_smc_get_io_mode(chip);
 
 	aspeed_smc_start_user(nor);
 	aspeed_smc_send_cmd_addr(nor, nor->read_opcode, from);
 	for (i = 0; i < chip->nor.read_dummy / 8; i++)
 		aspeed_smc_write_to_ahb(chip->ahb_base, &dummy, sizeof(dummy));
 
+	/* Set IO mode only for data */
+	if (io_mode == CONTROL_IO_DUAL_DATA)
+		aspeed_smc_set_io_mode(chip, io_mode);
+
 	aspeed_smc_read_from_ahb(read_buf, chip->ahb_base, len);
 	aspeed_smc_stop_user(nor);
 	return len;
@@ -735,6 +766,7 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)
 {
 	struct aspeed_smc_controller *controller = chip->controller;
 	const struct aspeed_smc_info *info = controller->info;
+	int io_mode;
 	u32 cmd;
 
 	if (chip->nor.addr_width == 4 && info->set_4b)
@@ -757,21 +789,20 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)
 	 * TODO: Adjust clocks if fast read is supported and interpret
 	 * SPI-NOR flags to adjust controller settings.
 	 */
-	if (chip->nor.read_proto == SNOR_PROTO_1_1_1) {
-		if (chip->nor.read_dummy == 0)
-			cmd = CONTROL_COMMAND_MODE_NORMAL;
-		else
-			cmd = CONTROL_COMMAND_MODE_FREAD;
-	} else {
-		dev_err(chip->nor.dev, "unsupported SPI read mode\n");
-		return -EINVAL;
-	}
+	io_mode = aspeed_smc_get_io_mode(chip);
+	if (io_mode < 0)
+		return io_mode;
+
+	if (chip->nor.read_dummy == 0)
+		cmd = CONTROL_COMMAND_MODE_NORMAL;
+	else
+		cmd = CONTROL_COMMAND_MODE_FREAD;
 
-	chip->ctl_val[smc_read] |= cmd |
+	chip->ctl_val[smc_read] |= cmd | io_mode |
 		chip->nor.read_opcode << CONTROL_COMMAND_SHIFT |
 		CONTROL_IO_DUMMY_SET(chip->nor.read_dummy / 8);
 
-	dev_dbg(controller->dev, "base control register: %08x\n",
+	dev_info(controller->dev, "read control register: %08x\n",
 		chip->ctl_val[smc_read]);
 	return 0;
 }
@@ -782,6 +813,7 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller,
 	const struct spi_nor_hwcaps hwcaps = {
 		.mask = SNOR_HWCAPS_READ |
 			SNOR_HWCAPS_READ_FAST |
+			SNOR_HWCAPS_READ_1_1_2 |
 			SNOR_HWCAPS_PP,
 	};
 	const struct aspeed_smc_info *info = controller->info;
Signature · 1 line
2.13.6
#4 lore raw

PATCH 4/6 ARM: dts: aspeed: add a AHB clock to the G4 SMC controllers

In reply to Cédric Le Goater

We will need the AHB frequency to set the HCLK settings in the SMC controller to optimize the reads.

---
 arch/arm/boot/dts/aspeed-g4.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm/boot/dts/aspeed-g4.dtsi +2 -0
index 60ab04aa75ea..50d664058344 100644
@@ -54,6 +54,7 @@
 			#address-cells = <1>;
 			#size-cells = <0>;
 			compatible = "aspeed,ast2400-fmc";
+			clocks = <&syscon ASPEED_CLK_AHB>;
 			status = "disabled";
 			interrupts = <19>;
 			flash@0 {
@@ -69,6 +70,7 @@
 			#address-cells = <1>;
 			#size-cells = <0>;
 			compatible = "aspeed,ast2400-spi";
+			clocks = <&syscon ASPEED_CLK_AHB>;
 			status = "disabled";
 			flash@0 {
 				reg = < 0 >;
Signature · 1 line
2.13.6
#5 lore raw

PATCH 5/6 mtd: spi-nor: aspeed: link controller with the ahb clock

In reply to Cédric Le Goater

We will need the AHB frequency to set the HCLK settings in the SMC controller to optimize the reads.

---
 drivers/mtd/spi-nor/aspeed-smc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/mtd/spi-nor/aspeed-smc.c +10 -0
index ac27a5109f6d..ae429154992d 100644
@@ -10,6 +10,7 @@
  */
 
 #include <linux/bug.h>
+#include <linux/clk.h>
 #include <linux/device.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -113,6 +114,8 @@ struct aspeed_smc_controller {
 	void __iomem *ahb_base;			/* per-chip windows resource */
 	u32 ahb_window_size;			/* full mapping window size */
 
+	unsigned long	clk_frequency;
+
 	struct aspeed_smc_chip *chips[0];	/* pointers to attached chips */
 };
 
@@ -911,6 +914,7 @@ static int aspeed_smc_probe(struct platform_device *pdev)
 	struct aspeed_smc_controller *controller;
 	const struct of_device_id *match;
 	const struct aspeed_smc_info *info;
+	struct clk *clk;
 	struct resource *res;
 	int ret;
 
@@ -941,6 +945,12 @@ static int aspeed_smc_probe(struct platform_device *pdev)
 
 	controller->ahb_window_size = resource_size(res);
 
+	clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(clk))
+		return PTR_ERR(clk);
+	controller->clk_frequency = clk_get_rate(clk);
+	devm_clk_put(&pdev->dev, clk);
+
 	ret = aspeed_smc_setup_flash(controller, np, res);
 	if (ret)
 		dev_err(dev, "Aspeed SMC probe failed %d\n", ret);
Signature · 1 line
2.13.6
#6 lore raw

PATCH 6/6 mtd: spi-nor: aspeed: optimize read mode

In reply to Cédric Le Goater

This is only for SPI controllers as U-Boot should have done it already for the FMC controller using DMAs.

The algo is based on the one found in the OpenPOWER pflash tool. It first reads a golden buffer at low speed and then performs reads with different clocks and delay cycles settings to find the fastest configuration for the chip.

It can be deactivated at boot time with the kernel parameter :

aspeed_smc.optimize_read=0

---
 drivers/mtd/spi-nor/aspeed-smc.c | 191 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 191 insertions(+)
drivers/mtd/spi-nor/aspeed-smc.c +191 -0
index ae429154992d..a301895d1f06 100644
@@ -21,6 +21,7 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/sizes.h>
+#include <linux/slab.h>
 #include <linux/sysfs.h>
 
 #define DEVICE_NAME	"aspeed-smc"
@@ -42,12 +43,16 @@ struct aspeed_smc_info {
 	bool hastype;		/* flash type field exists in config reg */
 	u8 we0;			/* shift for write enable bit for CE0 */
 	u8 ctl0;		/* offset in regs of ctl for CE0 */
+	u8 timing;		/* offset in regs of timing */
 
 	void (*set_4b)(struct aspeed_smc_chip *chip);
+	int (*optimize_read)(struct aspeed_smc_chip *chip, u32 max_freq);
 };
 
 static void aspeed_smc_chip_set_4b_spi_2400(struct aspeed_smc_chip *chip);
 static void aspeed_smc_chip_set_4b(struct aspeed_smc_chip *chip);
+static int aspeed_smc_optimize_read(struct aspeed_smc_chip *chip,
+				     u32 max_freq);
 
 static const struct aspeed_smc_info fmc_2400_info = {
 	.maxsize = 64 * 1024 * 1024,
@@ -55,6 +60,7 @@ static const struct aspeed_smc_info fmc_2400_info = {
 	.hastype = true,
 	.we0 = 16,
 	.ctl0 = 0x10,
+	.timing = 0x94,
 	.set_4b = aspeed_smc_chip_set_4b,
 };
 
@@ -64,7 +70,9 @@ static const struct aspeed_smc_info spi_2400_info = {
 	.hastype = false,
 	.we0 = 0,
 	.ctl0 = 0x04,
+	.timing = 0x94,
 	.set_4b = aspeed_smc_chip_set_4b_spi_2400,
+	.optimize_read = aspeed_smc_optimize_read,
 };
 
 static const struct aspeed_smc_info fmc_2500_info = {
@@ -73,6 +81,7 @@ static const struct aspeed_smc_info fmc_2500_info = {
 	.hastype = true,
 	.we0 = 16,
 	.ctl0 = 0x10,
+	.timing = 0x94,
 	.set_4b = aspeed_smc_chip_set_4b,
 };
 
@@ -82,7 +91,9 @@ static const struct aspeed_smc_info spi_2500_info = {
 	.hastype = false,
 	.we0 = 16,
 	.ctl0 = 0x10,
+	.timing = 0x94,
 	.set_4b = aspeed_smc_chip_set_4b,
+	.optimize_read = aspeed_smc_optimize_read,
 };
 
 enum aspeed_smc_ctl_reg_value {
@@ -205,6 +216,12 @@ struct aspeed_smc_controller {
 	((controller)->regs + SEGMENT_ADDR_REG0 + (cs) * 4)
 
 /*
+ * Switch to turn off read optimisation if needed
+ */
+static bool optimize_read = true;
+module_param(optimize_read, bool, 0644);
+
+/*
  * In user mode all data bytes read or written to the chip decode address
  * range are transferred to or from the SPI bus. The range is treated as a
  * fifo of arbitratry 1, 2, or 4 byte width but each write has to be aligned
@@ -765,6 +782,174 @@ static int aspeed_smc_chip_setup_init(struct aspeed_smc_chip *chip,
 	return 0;
 }
 
+
+#define CALIBRATE_BUF_SIZE 16384
+
+static bool aspeed_smc_check_reads(struct aspeed_smc_chip *chip,
+				  const u8 *golden_buf, u8 *test_buf)
+{
+	int i;
+
+	for (i = 0; i < 10; i++) {
+		aspeed_smc_read_from_ahb(test_buf, chip->ahb_base,
+					 CALIBRATE_BUF_SIZE);
+		if (memcmp(test_buf, golden_buf, CALIBRATE_BUF_SIZE) != 0)
+			return false;
+	}
+	return true;
+}
+
+static int aspeed_smc_calibrate_reads(struct aspeed_smc_chip *chip, u32 hdiv,
+				      const u8 *golden_buf, u8 *test_buf)
+{
+	struct aspeed_smc_controller *controller = chip->controller;
+	const struct aspeed_smc_info *info = controller->info;
+	int i;
+	int good_pass = -1, pass_count = 0;
+	u32 shift = (hdiv - 1) << 2;
+	u32 mask = ~(0xfu << shift);
+	u32 fread_timing_val = 0;
+
+#define FREAD_TPASS(i)	(((i) / 2) | (((i) & 1) ? 0 : 8))
+
+	/* Try HCLK delay 0..5, each one with/without delay and look for a
+	 * good pair.
+	 */
+	for (i = 0; i < 12; i++) {
+		bool pass;
+
+		fread_timing_val &= mask;
+		fread_timing_val |= FREAD_TPASS(i) << shift;
+
+		writel(fread_timing_val, controller->regs + info->timing);
+		pass = aspeed_smc_check_reads(chip, golden_buf, test_buf);
+		dev_dbg(chip->nor.dev,
+			"  * [%08x] %d HCLK delay, %dns DI delay : %s",
+			fread_timing_val, i/2, (i & 1) ? 0 : 4,
+			pass ? "PASS" : "FAIL");
+		if (pass) {
+			pass_count++;
+			if (pass_count == 3) {
+				good_pass = i - 1;
+				break;
+			}
+		} else
+			pass_count = 0;
+	}
+
+	/* No good setting for this frequency */
+	if (good_pass < 0)
+		return -1;
+
+	/* We have at least one pass of margin, let's use first pass */
+	fread_timing_val &= mask;
+	fread_timing_val |= FREAD_TPASS(good_pass) << shift;
+	writel(fread_timing_val, controller->regs + info->timing);
+	dev_dbg(chip->nor.dev, " * -> good is pass %d [0x%08x]",
+		good_pass, fread_timing_val);
+	return 0;
+}
+
+static bool aspeed_smc_check_calib_data(const u8 *test_buf, u32 size)
+{
+	const u32 *tb32 = (const u32 *) test_buf;
+	u32 i, cnt = 0;
+
+	/* We check if we have enough words that are neither all 0
+	 * nor all 1's so the calibration can be considered valid.
+	 *
+	 * I use an arbitrary threshold for now of 64
+	 */
+	size >>= 2;
+	for (i = 0; i < size; i++) {
+		if (tb32[i] != 0 && tb32[i] != 0xffffffff)
+			cnt++;
+	}
+	return cnt >= 64;
+}
+
+static const uint32_t aspeed_smc_hclk_divs[] = {
+	0xf, /* HCLK */
+	0x7, /* HCLK/2 */
+	0xe, /* HCLK/3 */
+	0x6, /* HCLK/4 */
+	0xd, /* HCLK/5 */
+};
+#define ASPEED_SMC_HCLK_DIV(i) (aspeed_smc_hclk_divs[(i) - 1] << 8)
+
+static int aspeed_smc_optimize_read(struct aspeed_smc_chip *chip,
+				     u32 max_freq)
+{
+	u8 *golden_buf, *test_buf;
+	int i, rc, best_div = -1;
+	u32 save_read_val = chip->ctl_val[smc_read];
+	u32 ahb_freq = chip->controller->clk_frequency;
+
+	dev_dbg(chip->nor.dev, "AHB frequency: %d MHz", ahb_freq / 1000000);
+
+	test_buf = kmalloc(CALIBRATE_BUF_SIZE * 2, GFP_KERNEL);
+	golden_buf = test_buf + CALIBRATE_BUF_SIZE;
+
+	/* We start with the dumbest setting (keep 4Byte bit) and read
+	 * some data
+	 */
+	chip->ctl_val[smc_read] = (chip->ctl_val[smc_read] & 0x2000) |
+		(0x00 << 28) | /* Single bit */
+		(0x00 << 24) | /* CE# max */
+		(0x03 << 16) | /* use normal reads */
+		(0x00 <<  8) | /* HCLK/16 */
+		(0x00 <<  6) | /* no dummy cycle */
+		(0x00);        /* normal read */
+
+	writel(chip->ctl_val[smc_read], chip->ctl);
+
+	aspeed_smc_read_from_ahb(golden_buf, chip->ahb_base,
+				 CALIBRATE_BUF_SIZE);
+
+	/* Establish our read mode with freq field set to 0 (HCLK/16) */
+	chip->ctl_val[smc_read] = save_read_val & 0xfffff0ff;
+
+	/* Check if calibration data is suitable */
+	if (!aspeed_smc_check_calib_data(golden_buf, CALIBRATE_BUF_SIZE)) {
+		dev_info(chip->nor.dev,
+			 "Calibration area too uniform, using low speed");
+		writel(chip->ctl_val[smc_read], chip->ctl);
+		kfree(test_buf);
+		return 0;
+	}
+
+	/* Now we iterate the HCLK dividers until we find our breaking point */
+	for (i = ARRAY_SIZE(aspeed_smc_hclk_divs); i > 0; i--) {
+		u32 tv, freq;
+
+		/* Compare timing to max */
+		freq = ahb_freq / i;
+		if (freq >= max_freq)
+			continue;
+
+		/* Set the timing */
+		tv = chip->ctl_val[smc_read] | ASPEED_SMC_HCLK_DIV(i);
+		writel(tv, chip->ctl);
+		dev_dbg(chip->nor.dev, "Trying HCLK/%d...", i);
+		rc = aspeed_smc_calibrate_reads(chip, i, golden_buf, test_buf);
+		if (rc == 0)
+			best_div = i;
+	}
+	kfree(test_buf);
+
+	/* Nothing found ? */
+	if (best_div < 0)
+		dev_warn(chip->nor.dev, "No good frequency, using dumb slow");
+	else {
+		dev_dbg(chip->nor.dev, "Found good read timings at HCLK/%d",
+			best_div);
+		chip->ctl_val[smc_read] |= ASPEED_SMC_HCLK_DIV(best_div);
+	}
+
+	writel(chip->ctl_val[smc_read], chip->ctl);
+	return 0;
+}
+
 static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)
 {
 	struct aspeed_smc_controller *controller = chip->controller;
@@ -807,6 +992,12 @@ static int aspeed_smc_chip_setup_finish(struct aspeed_smc_chip *chip)
 
 	dev_info(controller->dev, "read control register: %08x\n",
 		chip->ctl_val[smc_read]);
+
+	/*
+	 * TODO: get max freq from chip
+	 */
+	if (optimize_read && info->optimize_read)
+		info->optimize_read(chip, 104000000);
 	return 0;
 }
 
Signature · 1 line
2.13.6
maintainer
#7 lore raw
In reply to Cédric Le Goater

Hello Cedric,

Quoted 5 lines · Cédric Le Goater

Hello,

Here is a series bringing the Aspeed SMC driver to the level of what we had in openbmc kernel 4.10. There are a couple of changes :

Quoted 7 lines

- the DMA support is gone. It is not used, it only works for kmalloc'ed buffers and UBIFS uses vmalloc'ed buffers for instance.

- the driver was slightly adapted to take into account the new clk driver.

Tested on a palmetto and an ast2500 eval boards.

Thanks! I applied these to dev-4.13. They did not cleanly apply. Can you double check that head of the remote you're using is c0df354f409687d3565073e17fab75913755ed07?

I did them applied, but they appear to fail to probe on my evb:

[    1.901227] aspeed-smc 1e620000.flash-controller: mx25l25635e (32768 Kbytes)
[    1.908304] aspeed-smc 1e620000.flash-controller: CE0 window [
0x20000000 - 0x22000000 ] 32MB
[    1.916831] aspeed-smc 1e620000.flash-controller: CE1 window [
0x22000000 - 0x2a000000 ] 128MB
[    1.925540] aspeed-smc 1e620000.flash-controller: unsupported SPI read mode
[    1.932516] aspeed-smc 1e620000.flash-controller: Aspeed SMC probe failed -22
[    1.946376] aspeed-smc: probe of 1e620000.flash-controller failed
with error -22
[    1.955217] aspeed-smc 1e630000.flash-controller: w25q256 (32768 Kbytes)
[    1.961943] aspeed-smc 1e630000.flash-controller: CE0 window [
0x30000000 - 0x32000000 ] 32MB
[    1.970467] aspeed-smc 1e630000.flash-controller: CE1 window [
0x32000000 - 0x38000000 ] 96MB
[    1.978982] aspeed-smc 1e630000.flash-controller: unsupported SPI read mode
[    1.985941] aspeed-smc 1e630000.flash-controller: Aspeed SMC probe failed -22
[    1.995375] aspeed-smc: probe of 1e630000.flash-controller failed
with error -22
[    2.004072] aspeed-smc 1e631000.flash-controller: Aspeed SMC probe failed -19

Cheers,

Joel

#8 lore raw
Quoted 11 lines · Joel Stanley

Hello Cedric,

Quoted 8 lines · Cédric Le Goater

Hello,

Here is a series bringing the Aspeed SMC driver to the level of what we had in openbmc kernel 4.10. There are a couple of changes :

- the DMA support is gone. It is not used, it only works for kmalloc'ed buffers and UBIFS uses vmalloc'ed buffers for instance.

Quoted 8 lines
Quoted 4 lines

- the driver was slightly adapted to take into account the new clk driver.

Tested on a palmetto and an ast2500 eval boards.

Thanks! I applied these to dev-4.13. They did not cleanly apply. Can you double check that head of the remote you're using is c0df354f409687d3565073e17fab75913755ed07?

yes it is. See my branch from yesterday :

https://github.com/legoater/linux/commits/openbmc-4.13

curious.

Quoted 13 lines

I did them applied, but they appear to fail to probe on my evb:

[    1.901227] aspeed-smc 1e620000.flash-controller: mx25l25635e (32768 Kbytes)
[    1.908304] aspeed-smc 1e620000.flash-controller: CE0 window [
0x20000000 - 0x22000000 ] 32MB
[    1.916831] aspeed-smc 1e620000.flash-controller: CE1 window [
0x22000000 - 0x2a000000 ] 128MB
[    1.925540] aspeed-smc 1e620000.flash-controller: unsupported SPI read mode
[    1.932516] aspeed-smc 1e620000.flash-controller: Aspeed SMC probe failed -22
[    1.946376] aspeed-smc: probe of 1e620000.flash-controller failed
with error -22
[    1.955217] aspeed-smc 1e630000.flash-controller: w25q256 (32768 Kbytes)
[    1.961943] aspeed-smc 1e630000.flash-controller: CE0 window [
Quoted 8 lines

0x30000000 - 0x32000000 ] 32MB

[    1.970467] aspeed-smc 1e630000.flash-controller: CE1 window [
0x32000000 - 0x38000000 ] 96MB
[    1.978982] aspeed-smc 1e630000.flash-controller: unsupported SPI read mode
[    1.985941] aspeed-smc 1e630000.flash-controller: Aspeed SMC probe failed -22
[    1.995375] aspeed-smc: probe of 1e630000.flash-controller failed
with error -22
[    2.004072] aspeed-smc 1e631000.flash-controller: Aspeed SMC probe failed -19

Looks ok on my side :

[    0.000000] Linux version 4.13.5-00039-gc0df354f4096-dirty ([email protected]) (gcc version 7.1.0 (Fedora 7.1.0-2.fc26)) #4 Mon Oct 9 12:58:44 CEST 2017
...
[    3.905220] aspeed-smc 1e620000.flash-controller: w25q256 (32768 Kbytes)
[    3.911980] aspeed-smc 1e620000.flash-controller: CE0 window [ 0x20000000 - 0x22000000 ] 32MB
[    3.920656] aspeed-smc 1e620000.flash-controller: CE1 window [ 0x22000000 - 0x2a000000 ] 128MB
[    3.929451] aspeed-smc 1e620000.flash-controller: read control register: 203b0641
[    3.962938] 5 ofpart partitions found on MTD device bmc
[    3.987941] Creating 5 MTD partitions on "bmc":
[    3.992642] 0x000000000000-0x000000060000 : "u-boot"
[    4.018345] 0x000000060000-0x000000080000 : "u-boot-env"
[    4.044080] 0x000000080000-0x0000004c0000 : "kernel"
[    4.069659] 0x0000004c0000-0x000001c00000 : "rofs"
[    4.095786] 0x000001c00000-0x000002000000 : "rwfs"
[    4.123717] aspeed-smc 1e630000.flash-controller: w25q256 (32768 Kbytes)
[    4.130625] aspeed-smc 1e630000.flash-controller: CE0 window [ 0x30000000 - 0x32000000 ] 32MB
[    4.139317] aspeed-smc 1e630000.flash-controller: CE1 window [ 0x32000000 - 0x38000000 ] 96MB
[    4.148031] aspeed-smc 1e630000.flash-controller: read control register: 203b0741
[    4.982664] aspeed-smc 1e631000.flash-controller: Aspeed SMC probe failed -19
[    5.019361] libphy: Fixed MDIO Bus: probed

are you sure we are using the same kernel ?

Cheers,

C.