Add Amlogic Meson SPI Flash Controller driver
Subsystems (2)
v3 cover Add Amlogic Meson SPI Flash Controller driver
The Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC.
This patchset add the driver ported from linux, but also import the regmap regmap_read_poll_timeout() to implify the register polling in the driver.
Neil Armstrong (3):
regmap: add regmap_read_poll_timeout() helper
test: regmap: add regmap_read_poll_timeout test
spi: Add Amlogic Meson SPI Flash Controller driver
drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/meson_spifc.c | 330 ++++++++++++++++++++++++++++++++++++++ include/regmap.h | 38 +++++ test/dm/regmap.c | 26 +++ 5 files changed, 403 insertions(+) create mode 100644 drivers/spi/meson_spifc.c
Signature · 1 line
2.19.1
PATCH v3 1/3 regmap: add regmap_read_poll_timeout() helper
Add the regmap_read_poll_timeout() macro based on the Linux implementation to simplify register polling with configurable timeout and sleep.
--- include/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
include/regmap.h +38 -0
@@ -42,6 +42,44 @@ int regmap_read(struct regmap *map, uint offset, uint *valp);#define regmap_read32 (map, ptr, member, valp) \ regmap_read(map, (uint32_t *)(ptr)->member - (uint32_t *)(ptr), valp) +/** +* regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs +* +* @map: Regmap to read from +* @addr: Offset to poll +* @val: Unsigned integer variable to read the value into +* @cond: Break condition (usually involving @val) +* @sleep_us: Maximum time to sleep between reads in us (0 tight-loops). +* @timeout_ms: Timeout in ms, 0 means never timeout +* +* Returns 0 on success and -ETIMEDOUT upon a timeout or the regmap_read +* error return value in case of a error read. In the two former cases, +* the last read value at @addr is stored in @val. Must not be called +* from atomic context if sleep_us or timeout_us are used. +* +* This is modelled after the regmap_read_poll_timeout macros in linux but +* with millisecond timeout. +*/ +#define regmap_read_poll_timeout (map, addr, val, cond, sleep_us, timeout_ms) \ +({ \ + unsigned long __start = get_timer(0); \ + int __ret; \ + for (;;) { \ + __ret = regmap_read((map), (addr), &(val)); \ + if (__ret) \ + break; \ + if (cond) \ + break; \ + if ((timeout_ms) && get_timer(__start) > (timeout_ms)) { \ + __ret = regmap_read((map), (addr), &(val)); \ + break; \ + } \ + if ((sleep_us)) \ + udelay((sleep_us)); \ + } \ + __ret ?: ((cond) ? 0 : -ETIMEDOUT); \ +}) +/** * regmap_update_bits() - Perform a read/modify/write using a mask *
Signature · 1 line
2.19.1
PATCH v3 1/3 regmap: add regmap_read_poll_timeout() helper
Quoted 6 lines · Neil Armstrong
Add the
regmap_read_poll_timeout()macro based on the Linux implementation to simplify register polling with configurable timeout and sleep.Signed-off-by Neil Armstrong <[email protected]>---
PATCH v3 2/3 test: regmap: add regmap_read_poll_timeout test
In reply to Neil ArmstrongAdd test to regmap_read_poll_timeout() helper to check the timeout works properly but cannot test proper condition matching since read/write calls are not executed in sandbox.
--- test/dm/regmap.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
test/dm/regmap.c +26 -0
@@ -116,3 +116,29 @@ static int dm_test_regmap_rw(struct unit_test_state *uts) }DM_TEST (dm_test_regmap_rw,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Read polling test */ +static int dm_test_regmap_poll (struct unit_test_state *uts) +{ +struct udevice *dev; +struct regmap *map; +uint reg; +unsigned long start; + +ut_assertok (uclass_get_device (UCLASS_SYSCON ,0 , &dev)); + map =syscon_get_regmap (dev); +ut_assertok_ptr (map); + + start =get_timer (0 ); + +ut_asserteq (-ETIMEDOUT , +regmap_read_poll_timeout (map,0 , reg, + (reg ==0xcacafafa ), +1 ,5 *CONFIG_SYS_HZ )); + +ut_assert (get_timer (start) > (5 *CONFIG_SYS_HZ )); + +return 0 ; +} + +DM_TEST (dm_test_regmap_poll,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.19.1
PATCH v3 2/3 test: regmap: add regmap_read_poll_timeout test
Quoted 7 lines · Neil Armstrong
Add test to
regmap_read_poll_timeout()helper to check the timeout works properly but cannot test proper condition matching since read/write calls are not executed in sandbox.Signed-off-by Neil Armstrong <[email protected]>---
PATCH v3 3/3 spi: Add Amlogic Meson SPI Flash Controller driver
In reply to Neil ArmstrongThe Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC. This driver, ported from the Linux meson-spi-spifc driver, add support for this controller on the Amlogic Meson GX SoCs in U-Boot.
--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/meson_spifc.c | 330 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 339 insertions(+) create mode 100644 drivers/spi/meson_spifc.c
drivers/spi/Kconfig +8 -0
@@ -116,6 +116,14 @@ config ICH_SPI access the SPI NOR flash on platforms embedding this Intel ICH IP core. +config MESON_SPIFC + bool "Amlogic Meson SPI Flash Controller driver" + depends on ARCH_MESON + help + Enable the Amlogic Meson SPI Flash Controller SPIFC) driver. + This driver can be used to access the SPI NOR flash chips on + Amlogic Meson SoCs. + config MT7621_SPI bool "MediaTek MT7621 SPI driver" depends on ARCH_MT7620
drivers/spi/Makefile +1 -0
@@ -31,6 +31,7 @@ obj-$(CONFIG_FSL_QSPI) += fsl_qspi.o obj-$(CONFIG_ICH_SPI) += ich.o obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o +obj-$(CONFIG_MESON_SPIFC) += meson_spifc.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.o
drivers/spi/meson_spifc.c new file +330 -0
330 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH v3 3/3 spi: Add Amlogic Meson SPI Flash Controller driver
Quoted 126 lines · Neil Armstrong
The Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC. This driver, ported from the Linux meson-spi-spifc driver, add support for this controller on the Amlogic Meson GX SoCs in U-Boot.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/meson_spifc.c | 330 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 339 insertions(+) create mode 100644 drivers/spi/meson_spifc.cdrivers/spi/Kconfig +8
-0@@ -116,6 +116,14 @@ config ICH_SPI access the SPI NOR flash on platforms embedding this Intel ICH IP core. +config MESON_SPIFC + bool "Amlogic Meson SPI Flash Controller driver" + depends on ARCH_MESON + help + Enable the Amlogic Meson SPI Flash Controller SPIFC) driver. + This driver can be used to access the SPI NOR flash chips on + Amlogic Meson SoCs. + config MT7621_SPI bool "MediaTek MT7621 SPI driver" depends on ARCH_MT7620drivers/spi/Makefile +1
-0@@ -31,6 +31,7 @@ obj-$(CONFIG_FSL_QSPI) += fsl_qspi.o obj-$(CONFIG_ICH_SPI) += ich.o obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o +obj-$(CONFIG_MESON_SPIFC) += meson_spifc.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.odrivers/spi/meson_spifc.c new file +76
-0@@ -0,0 +1,330 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2014 Beniamino Galvani <[email protected]> +* Copyright (C) 2018 BayLibre, SAS +* Author: Neil Armstrong <[email protected]> +* +* Amlogic Meson SPI Flash Controller driver +*/ + +#include <common.h> +#include <spi.h> +#include <clk.h> +#include <dm.h> +#include <regmap.h> +#include <errno.h> +#include <asm/io.h> +#include <linux/bitfield.h> + +/* register map */ +#define REG_CMD 0x00 +#define REG_ADDR 0x04 +#define REG_CTRL 0x08 +#define REG_CTRL1 0x0c +#define REG_STATUS 0x10 +#define REG_CTRL2 0x14 +#define REG_CLOCK 0x18 +#define REG_USER 0x1c +#define REG_USER1 0x20 +#define REG_USER2 0x24 +#define REG_USER3 0x28 +#define REG_USER4 0x2c +#define REG_SLAVE 0x30 +#define REG_SLAVE1 0x34 +#define REG_SLAVE2 0x38 +#define REG_SLAVE3 0x3c +#define REG_C0 0x40 +#define REG_B8 0x60 +#define REG_MAX 0x7c + +/* register fields */ +#define CMD_USER BIT(18) +#define CTRL_ENABLE_AHB BIT(17) +#define CLOCK_SOURCE BIT(31) +#define CLOCK_DIV_SHIFT 12 +#define CLOCK_DIV_MASK (0x3f << CLOCK_DIV_SHIFT) +#define CLOCK_CNT_HIGH_SHIFT 6 +#define CLOCK_CNT_HIGH_MASK (0x3f << CLOCK_CNT_HIGH_SHIFT) +#define CLOCK_CNT_LOW_SHIFT 0 +#define CLOCK_CNT_LOW_MASK (0x3f << CLOCK_CNT_LOW_SHIFT) +#define USER_DIN_EN_MS BIT(0) +#define USER_CMP_MODE BIT(2) +#define USER_CLK_NOT_INV BIT(7) +#define USER_UC_DOUT_SEL BIT(27) +#define USER_UC_DIN_SEL BIT(28) +#define USER_UC_MASK ((BIT(5) - 1) << 27) +#define USER1_BN_UC_DOUT_SHIFT 17 +#define USER1_BN_UC_DOUT_MASK (0xff << 16) +#define USER1_BN_UC_DIN_SHIFT 8 +#define USER1_BN_UC_DIN_MASK (0xff << 8) +#define USER4_CS_POL_HIGH BIT(23) +#define USER4_IDLE_CLK_HIGH BIT(29) +#define USER4_CS_ACT BIT(30) +#define SLAVE_TRST_DONE BIT(4) +#define SLAVE_OP_MODE BIT(30) +#define SLAVE_SW_RST BIT(31) + +#define SPIFC_BUFFER_SIZE 64 + +struct meson_spifc_priv { +struct regmap *regmap; +struct clk clk; +}; + +/** +* meson_spifc_wait_ready() - wait for the current operation to terminate +* @spifc: the Meson SPI device
drivers/spi/meson_spifc.c line 86
Quoted 10 lines
drivers/spi/meson_spifc.c new file +10
-0+* Return: 0 on success, a negative value on error +*/ +static int meson_spifc_wait_ready (struct meson_spifc_priv *spifc) +{ +u32 data; + +return regmap_read_poll_timeout (spifc->regmap,REG_SLAVE , data, + (data &SLAVE_TRST_DONE ), +0 ,5 *CONFIG_SYS_HZ ); +}
We can call poll_timeout directly w/o separate function, since we have only one call. I can do that while applying if you are OK?
PATCH v3 3/3 spi: Add Amlogic Meson SPI Flash Controller driver
Quoted 141 lines · Jagan Teki
Quoted 126 lines · Neil Armstrong
The Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC. This driver, ported from the Linux meson-spi-spifc driver, add support for this controller on the Amlogic Meson GX SoCs in U-Boot.
Signed-off-by Neil Armstrong <[email protected]>--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/meson_spifc.c | 330 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 339 insertions(+) create mode 100644 drivers/spi/meson_spifc.cdrivers/spi/Kconfig +8
-0@@ -116,6 +116,14 @@ config ICH_SPI access the SPI NOR flash on platforms embedding this Intel ICH IP core. +config MESON_SPIFC + bool "Amlogic Meson SPI Flash Controller driver" + depends on ARCH_MESON + help + Enable the Amlogic Meson SPI Flash Controller SPIFC) driver. + This driver can be used to access the SPI NOR flash chips on + Amlogic Meson SoCs. + config MT7621_SPI bool "MediaTek MT7621 SPI driver" depends on ARCH_MT7620drivers/spi/Makefile +1
-0@@ -31,6 +31,7 @@ obj-$(CONFIG_FSL_QSPI) += fsl_qspi.o obj-$(CONFIG_ICH_SPI) += ich.o obj-$(CONFIG_KIRKWOOD_SPI) += kirkwood_spi.o obj-$(CONFIG_LPC32XX_SSP) += lpc32xx_ssp.o +obj-$(CONFIG_MESON_SPIFC) += meson_spifc.o obj-$(CONFIG_MPC8XX_SPI) += mpc8xx_spi.o obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o obj-$(CONFIG_MT7621_SPI) += mt7621_spi.odrivers/spi/meson_spifc.c new file +76
-0@@ -0,0 +1,330 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright (C) 2014 Beniamino Galvani <[email protected]> +* Copyright (C) 2018 BayLibre, SAS +* Author: Neil Armstrong <[email protected]> +* +* Amlogic Meson SPI Flash Controller driver +*/ + +#include <common.h> +#include <spi.h> +#include <clk.h> +#include <dm.h> +#include <regmap.h> +#include <errno.h> +#include <asm/io.h> +#include <linux/bitfield.h> + +/* register map */ +#define REG_CMD 0x00 +#define REG_ADDR 0x04 +#define REG_CTRL 0x08 +#define REG_CTRL1 0x0c +#define REG_STATUS 0x10 +#define REG_CTRL2 0x14 +#define REG_CLOCK 0x18 +#define REG_USER 0x1c +#define REG_USER1 0x20 +#define REG_USER2 0x24 +#define REG_USER3 0x28 +#define REG_USER4 0x2c +#define REG_SLAVE 0x30 +#define REG_SLAVE1 0x34 +#define REG_SLAVE2 0x38 +#define REG_SLAVE3 0x3c +#define REG_C0 0x40 +#define REG_B8 0x60 +#define REG_MAX 0x7c + +/* register fields */ +#define CMD_USER BIT(18) +#define CTRL_ENABLE_AHB BIT(17) +#define CLOCK_SOURCE BIT(31) +#define CLOCK_DIV_SHIFT 12 +#define CLOCK_DIV_MASK (0x3f << CLOCK_DIV_SHIFT) +#define CLOCK_CNT_HIGH_SHIFT 6 +#define CLOCK_CNT_HIGH_MASK (0x3f << CLOCK_CNT_HIGH_SHIFT) +#define CLOCK_CNT_LOW_SHIFT 0 +#define CLOCK_CNT_LOW_MASK (0x3f << CLOCK_CNT_LOW_SHIFT) +#define USER_DIN_EN_MS BIT(0) +#define USER_CMP_MODE BIT(2) +#define USER_CLK_NOT_INV BIT(7) +#define USER_UC_DOUT_SEL BIT(27) +#define USER_UC_DIN_SEL BIT(28) +#define USER_UC_MASK ((BIT(5) - 1) << 27) +#define USER1_BN_UC_DOUT_SHIFT 17 +#define USER1_BN_UC_DOUT_MASK (0xff << 16) +#define USER1_BN_UC_DIN_SHIFT 8 +#define USER1_BN_UC_DIN_MASK (0xff << 8) +#define USER4_CS_POL_HIGH BIT(23) +#define USER4_IDLE_CLK_HIGH BIT(29) +#define USER4_CS_ACT BIT(30) +#define SLAVE_TRST_DONE BIT(4) +#define SLAVE_OP_MODE BIT(30) +#define SLAVE_SW_RST BIT(31) + +#define SPIFC_BUFFER_SIZE 64 + +struct meson_spifc_priv { +struct regmap *regmap; +struct clk clk; +}; + +/** +* meson_spifc_wait_ready() - wait for the current operation to terminate +* @spifc: the Meson SPI device drivers/spi/meson_spifc.c line 86
Quoted 10 lines
drivers/spi/meson_spifc.c new file +10
-0+* Return: 0 on success, a negative value on error +*/ +static int meson_spifc_wait_ready (struct meson_spifc_priv *spifc) +{ +u32 data; + +return regmap_read_poll_timeout (spifc->regmap,REG_SLAVE , data, + (data &SLAVE_TRST_DONE ), +0 ,5 *CONFIG_SYS_HZ ); +}We can call
poll_timeoutdirectly w/o separate function, since we have only one call. I can do that while applying if you are OK?
Quoted 2 lines
Reviewed-by Jagan Teki <[email protected]>
Sure, no problem.
Tell me when applied so I can test it before you send the PR to tom.
Neil
Jerome Brunet
reviewerv3 cover Add Amlogic Meson SPI Flash Controller driver
In reply to Neil ArmstrongQuoted 10 lines · Neil Armstrong
The Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC.
This patchset add the driver ported from linux, but also import the regmap
regmap_read_poll_timeout()to implify the register polling in the driver.Neil Armstrong (3):
regmap: addregmap_read_poll_timeout()helper
test: regmap: addregmap_read_poll_timeouttest
spi: Add Amlogic Meson SPI Flash Controller driver
Quoted 8 lines
drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/meson_spifc.c | 330 ++++++++++++++++++++++++++++++++++++++ include/regmap.h | 38 +++++ test/dm/regmap.c | 26 +++ 5 files changed, 403 insertions(+) create mode 100644 drivers/spi/meson_spifc.c
... on the libretech aml-s805x-ac which should be submitted soon.
v3 cover Add Amlogic Meson SPI Flash Controller driver
In reply to Neil ArmstrongQuoted 10 lines · Neil Armstrong
The Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC.
This patchset add the driver ported from linux, but also import the regmap
regmap_read_poll_timeout()to implify the register polling in the driver.Neil Armstrong (3):
regmap: addregmap_read_poll_timeout()helper
test: regmap: addregmap_read_poll_timeouttest
spi: Add Amlogic Meson SPI Flash Controller driver
There are few regmap patches upstreamed recently, can you rebase and the send the series again. take care of direct poll_timeout w/o any function on driver.
v3 cover Add Amlogic Meson SPI Flash Controller driver
Quoted 7 lines · Jagan Teki
Quoted 6 lines · Neil Armstrong
The Amlogic Meson SoCs embeds a Flash oriented SPI Controller name SPIFC.
This patchset add the driver ported from linux, but also import the regmap
regmap_read_poll_timeout()to implify the register polling in the driver.
Quoted 9 lines
Quoted 4 lines
Neil Armstrong (3):
regmap: addregmap_read_poll_timeout()helper
test: regmap: addregmap_read_poll_timeouttest
spi: Add Amlogic Meson SPI Flash Controller driverThere are few regmap patches upstreamed recently, can you rebase and the send the series again. take care of direct
poll_timeoutw/o any function on driver.
Sure,
Neil