[U-Boot] [PATCH v3 1/2] arm: sunxi: Allwinner A10 SPI driver

Add spi driver for sun4i, sun5i and sun7i SoCs. The driver is adapted from mailine kernel.
Signed-off-by: Stefan Mavrodiev stefan@olimex.com --- Changes for v3: - Add required changes in dts and defeconfig file for testing
Changes for v2: - Updated copyright including original owners - Remove write/read register function. They are replaced with direct opts - Some coding style changes
drivers/spi/Kconfig | 5 + drivers/spi/Makefile | 1 + drivers/spi/sun4i_spi.c | 456 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 462 insertions(+) create mode 100644 drivers/spi/sun4i_spi.c
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 494639f..9001182 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -132,6 +132,11 @@ config STM32_QSPI used to access the SPI NOR flash chips on platforms embedding this ST IP core.
+config SUN4I_SPI + bool "Allwinner A10 SoCs SPI controller" + help + SPI driver for Allwinner sun4i, sun5i and sun7i SoCs + config TEGRA114_SPI bool "nVidia Tegra114 SPI driver" help diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index e3184db..aa7645a 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -42,6 +42,7 @@ obj-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o obj-$(CONFIG_SH_SPI) += sh_spi.o obj-$(CONFIG_SH_QSPI) += sh_qspi.o obj-$(CONFIG_STM32_QSPI) += stm32_qspi.o +obj-$(CONFIG_SUN4I_SPI) += sun4i_spi.o obj-$(CONFIG_TEGRA114_SPI) += tegra114_spi.o obj-$(CONFIG_TEGRA20_SFLASH) += tegra20_sflash.o obj-$(CONFIG_TEGRA20_SLINK) += tegra20_slink.o diff --git a/drivers/spi/sun4i_spi.c b/drivers/spi/sun4i_spi.c new file mode 100644 index 0000000..4f4cca6 --- /dev/null +++ b/drivers/spi/sun4i_spi.c @@ -0,0 +1,456 @@ +/* + * (C) Copyright 2017 Whitebox Systems / Northend Systems B.V. + * S.J.R. van Schaik stephan@whiteboxsystems.nl + * M.B.W. Wajer merlijn@whiteboxsystems.nl + * + * (C) Copyright 2017 Olimex Ltd.. + * Stefan Mavrodiev stefan@olimex.com + * + * + * Based on linux spi driver. Original copyright follows: + * linux/drivers/spi/spi-sun4i.c + * + * Copyright (C) 2012 - 2014 Allwinner Tech + * Pan Nan pannan@allwinnertech.com + * + * Copyright (C) 2014 Maxime Ripard + * Maxime Ripard maxime.ripard@free-electrons.com + * + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <dm.h> +#include <spi.h> +#include <errno.h> +#include <fdt_support.h> +#include <wait_bit.h> + +#include <asm/bitops.h> +#include <asm/gpio.h> +#include <asm/io.h> + +#include <asm/arch/clock.h> + +#define SUN4I_FIFO_DEPTH 64 + +#define SUN4I_RXDATA_REG 0x00 + +#define SUN4I_TXDATA_REG 0x04 + +#define SUN4I_CTL_REG 0x08 +#define SUN4I_CTL_ENABLE BIT(0) +#define SUN4I_CTL_MASTER BIT(1) +#define SUN4I_CTL_CPHA BIT(2) +#define SUN4I_CTL_CPOL BIT(3) +#define SUN4I_CTL_CS_ACTIVE_LOW BIT(4) +#define SUN4I_CTL_LMTF BIT(6) +#define SUN4I_CTL_TF_RST BIT(8) +#define SUN4I_CTL_RF_RST BIT(9) +#define SUN4I_CTL_XCH_MASK 0x0400 +#define SUN4I_CTL_XCH BIT(10) +#define SUN4I_CTL_CS_MASK 0x3000 +#define SUN4I_CTL_CS(cs) (((cs) << 12) & SUN4I_CTL_CS_MASK) +#define SUN4I_CTL_DHB BIT(15) +#define SUN4I_CTL_CS_MANUAL BIT(16) +#define SUN4I_CTL_CS_LEVEL BIT(17) +#define SUN4I_CTL_TP BIT(18) + +#define SUN4I_INT_CTL_REG 0x0c +#define SUN4I_INT_CTL_RF_F34 BIT(4) +#define SUN4I_INT_CTL_TF_E34 BIT(12) +#define SUN4I_INT_CTL_TC BIT(16) + +#define SUN4I_INT_STA_REG 0x10 + +#define SUN4I_DMA_CTL_REG 0x14 + +#define SUN4I_WAIT_REG 0x18 + +#define SUN4I_CLK_CTL_REG 0x1c +#define SUN4I_CLK_CTL_CDR2_MASK 0xff +#define SUN4I_CLK_CTL_CDR2(div) ((div) & SUN4I_CLK_CTL_CDR2_MASK) +#define SUN4I_CLK_CTL_CDR1_MASK 0xf +#define SUN4I_CLK_CTL_CDR1(div) (((div) & SUN4I_CLK_CTL_CDR1_MASK) << 8) +#define SUN4I_CLK_CTL_DRS BIT(12) + +#define SUN4I_MAX_XFER_SIZE 0xffffff + +#define SUN4I_BURST_CNT_REG 0x20 +#define SUN4I_BURST_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE) + +#define SUN4I_XMIT_CNT_REG 0x24 +#define SUN4I_XMIT_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE) + +#define SUN4I_FIFO_STA_REG 0x28 +#define SUN4I_FIFO_STA_RF_CNT_MASK 0x7f +#define SUN4I_FIFO_STA_RF_CNT_BITS 0 +#define SUN4I_FIFO_STA_TF_CNT_MASK 0x7f +#define SUN4I_FIFO_STA_TF_CNT_BITS 16 + +#define SUN4I_SPI_MAX_RATE 24000000 +#define SUN4I_SPI_MIN_RATE 3000 +#define SUN4I_SPI_DEFAULT_RATE 1000000 +#define SUN4I_SPI_TIMEOUT_US 1000000 + +/* sun4i spi register set */ +struct sun4i_spi_regs { + u32 rxdata; + u32 txdata; + u32 ctl; + u32 intctl; + u32 st; + u32 dmactl; + u32 wait; + u32 cctl; + u32 bc; + u32 tc; + u32 fifo_sta; +}; + +struct sun4i_spi_platdata { + u32 base_addr; + u32 max_hz; +}; + +struct sun4i_spi_priv { + struct sun4i_spi_regs *regs; + u32 freq; + u32 mode; + + const u8 *tx_buf; + u8 *rx_buf; +}; + +DECLARE_GLOBAL_DATA_PTR; + +static inline void sun4i_spi_drain_fifo(struct sun4i_spi_priv *priv, int len) +{ + u8 byte; + + while (len--) { + byte = readb(&priv->regs->rxdata); + *priv->rx_buf++ = byte; + } +} + +static inline void sun4i_spi_fill_fifo(struct sun4i_spi_priv *priv, int len) +{ + u8 byte; + + while (len--) { + byte = priv->tx_buf ? *priv->tx_buf++ : 0; + writeb(byte, &priv->regs->txdata); + } +} + +static void sun4i_spi_set_cs(struct udevice *bus, u8 cs, bool enable) +{ + struct sun4i_spi_priv *priv = dev_get_priv(bus); + u32 reg; + + reg = readl(&priv->regs->ctl); + + reg &= ~SUN4I_CTL_CS_MASK; + reg |= SUN4I_CTL_CS(cs); + + if (enable) + reg &= ~SUN4I_CTL_CS_LEVEL; + else + reg |= SUN4I_CTL_CS_LEVEL; + + writel(reg, &priv->regs->ctl); +} + +static int sun4i_spi_parse_pins(struct udevice *dev) +{ + const void *fdt = gd->fdt_blob; + const char *pin_name; + const fdt32_t *list; + u32 phandle; + int drive, pull = 0, pin, i; + int offset; + int size; + + list = fdt_getprop(fdt, dev_of_offset(dev), "pinctrl-0", &size); + if (!list) { + printf("WARNING: sun4i_spi: cannot find pinctrl-0 node\n"); + return -EINVAL; + } + + while (size) { + phandle = fdt32_to_cpu(*list++); + size -= sizeof(*list); + + offset = fdt_node_offset_by_phandle(fdt, phandle); + if (offset < 0) + return offset; + + drive = fdt_getprop_u32_default_node(fdt, offset, 0, + "drive-strength", 0); + if (drive) { + if (drive <= 10) + drive = 0; + else if (drive <= 20) + drive = 1; + else if (drive <= 30) + drive = 2; + else + drive = 3; + } else { + drive = fdt_getprop_u32_default_node(fdt, offset, 0, + "allwinner,drive", + 0); + drive = min(drive, 3); + } + + if (fdt_get_property(fdt, offset, "bias-disable", NULL)) + pull = 0; + else if (fdt_get_property(fdt, offset, "bias-pull-up", NULL)) + pull = 1; + else if (fdt_get_property(fdt, offset, "bias-pull-down", NULL)) + pull = 2; + else + pull = fdt_getprop_u32_default_node(fdt, offset, 0, + "allwinner,pull", + 0); + pull = min(pull, 2); + + for (i = 0; ; i++) { + pin_name = fdt_stringlist_get(fdt, offset, + "pins", i, NULL); + if (!pin_name) { + pin_name = fdt_stringlist_get(fdt, offset, + "allwinner,pins", + i, NULL); + if (!pin_name) + break; + } + + pin = name_to_gpio(pin_name); + if (pin < 0) + break; + + sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SPI0); + sunxi_gpio_set_drv(pin, drive); + sunxi_gpio_set_pull(pin, pull); + } + } + return 0; +} + +static inline void sun4i_spi_enable_clock(void) +{ + struct sunxi_ccm_reg *const ccm = + (struct sunxi_ccm_reg *const)SUNXI_CCM_BASE; + + setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_SPI0)); + writel((1 << 31), &ccm->spi0_clk_cfg); +} + +static int sun4i_spi_ofdata_to_platdata(struct udevice *bus) +{ + struct sun4i_spi_platdata *plat = dev_get_platdata(bus); + int node = dev_of_offset(bus); + + plat->base_addr = devfdt_get_addr(bus); + plat->max_hz = fdtdec_get_int(gd->fdt_blob, node, + "spi-max-frequency", + SUN4I_SPI_DEFAULT_RATE); + + if (plat->max_hz > SUN4I_SPI_MAX_RATE) + plat->max_hz = SUN4I_SPI_MAX_RATE; + + return 0; +} + +static int sun4i_spi_probe(struct udevice *bus) +{ + struct sun4i_spi_platdata *plat = dev_get_platdata(bus); + struct sun4i_spi_priv *priv = dev_get_priv(bus); + + sun4i_spi_enable_clock(); + sun4i_spi_parse_pins(bus); + + priv->regs = (struct sun4i_spi_regs *)(uintptr_t)plat->base_addr; + priv->freq = plat->max_hz; + + return 0; +} + +static int sun4i_spi_claim_bus(struct udevice *dev) +{ + struct sun4i_spi_priv *priv = dev_get_priv(dev->parent); + + writel(SUN4I_CTL_ENABLE | SUN4I_CTL_MASTER | SUN4I_CTL_TP | + SUN4I_CTL_CS_MANUAL | SUN4I_CTL_CS_ACTIVE_LOW, + &priv->regs->ctl); + return 0; +} + +static int sun4i_spi_release_bus(struct udevice *dev) +{ + struct sun4i_spi_priv *priv = dev_get_priv(dev->parent); + u32 reg; + + reg = readl(&priv->regs->ctl); + reg &= ~SUN4I_CTL_ENABLE; + writel(reg, &priv->regs->ctl); + + return 0; +} + +static int sun4i_spi_xfer(struct udevice *dev, unsigned int bitlen, + const void *dout, void *din, unsigned long flags) +{ + struct udevice *bus = dev->parent; + struct sun4i_spi_priv *priv = dev_get_priv(bus); + struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev); + + u32 len = bitlen / 8; + u32 reg; + u8 nbytes; + int ret; + + priv->tx_buf = dout; + priv->rx_buf = din; + + if (bitlen % 8) { + debug("%s: non byte-aligned SPI transfer.\n", __func__); + return -ENAVAIL; + } + + if (flags & SPI_XFER_BEGIN) + sun4i_spi_set_cs(bus, slave_plat->cs, true); + + reg = readl(&priv->regs->ctl); + + /* Reset FIFOs */ + writel(reg | SUN4I_CTL_RF_RST | SUN4I_CTL_TF_RST, &priv->regs->ctl); + + while (len) { + /* Setup the transfer now... */ + nbytes = min(len, (u32)(SUN4I_FIFO_DEPTH - 1)); + + /* Setup the counters */ + writel(SUN4I_BURST_CNT(nbytes), &priv->regs->bc); + writel(SUN4I_XMIT_CNT(nbytes), &priv->regs->tc); + + /* Fill the TX FIFO */ + sun4i_spi_fill_fifo(priv, nbytes); + + /* Start the transfer */ + reg = readl(&priv->regs->ctl); + writel(reg | SUN4I_CTL_XCH, &priv->regs->ctl); + + /* Wait transfer to complete */ + ret = wait_for_bit(__func__, &priv->regs->ctl, + SUN4I_CTL_XCH_MASK, false, + SUN4I_SPI_TIMEOUT_US, false); + if (ret) { + printf("ERROR: sun4i_spi: Timeout transferring data\n"); + sun4i_spi_set_cs(bus, slave_plat->cs, false); + return ret; + } + + /* Drain the RX FIFO */ + sun4i_spi_drain_fifo(priv, nbytes); + + len -= nbytes; + } + + if (flags & SPI_XFER_END) + sun4i_spi_set_cs(bus, slave_plat->cs, false); + + return 0; +} + +static int sun4i_spi_set_speed(struct udevice *dev, uint speed) +{ + struct sun4i_spi_platdata *plat = dev_get_platdata(dev); + struct sun4i_spi_priv *priv = dev_get_priv(dev); + unsigned int div; + u32 reg; + + if (speed > plat->max_hz) + speed = plat->max_hz; + + if (speed < SUN4I_SPI_MIN_RATE) + speed = SUN4I_SPI_MIN_RATE; + /* + * Setup clock divider. + * + * We have two choices there. Either we can use the clock + * divide rate 1, which is calculated thanks to this formula: + * SPI_CLK = MOD_CLK / (2 ^ (cdr + 1)) + * Or we can use CDR2, which is calculated with the formula: + * SPI_CLK = MOD_CLK / (2 * (cdr + 1)) + * Whether we use the former or the latter is set through the + * DRS bit. + * + * First try CDR2, and if we can't reach the expected + * frequency, fall back to CDR1. + */ + + div = SUN4I_SPI_MAX_RATE / (2 * speed); + + if (div <= (SUN4I_CLK_CTL_CDR2_MASK + 1)) { + if (div > 0) + div--; + + reg = SUN4I_CLK_CTL_CDR2(div) | SUN4I_CLK_CTL_DRS; + } else { + div = __ilog2(SUN4I_SPI_MAX_RATE) - __ilog2(speed); + reg = SUN4I_CLK_CTL_CDR1(div); + } + + priv->freq = speed; + writel(reg, &priv->regs->cctl); + + return 0; +} + +static int sun4i_spi_set_mode(struct udevice *dev, uint mode) +{ + struct sun4i_spi_priv *priv = dev_get_priv(dev); + u32 reg; + + reg = readl(&priv->regs->ctl); + reg &= ~(SUN4I_CTL_CPOL | SUN4I_CTL_CPHA); + + if (mode & SPI_CPOL) + reg |= SUN4I_CTL_CPOL; + + if (mode & SPI_CPHA) + reg |= SUN4I_CTL_CPHA; + + priv->mode = mode; + writel(reg, &priv->regs->ctl); + + return 0; +} + +static const struct dm_spi_ops sun4i_spi_ops = { + .claim_bus = sun4i_spi_claim_bus, + .release_bus = sun4i_spi_release_bus, + .xfer = sun4i_spi_xfer, + .set_speed = sun4i_spi_set_speed, + .set_mode = sun4i_spi_set_mode, +}; + +static const struct udevice_id sun4i_spi_ids[] = { + { .compatible = "allwinner,sun4i-a10-spi" }, + { } +}; + +U_BOOT_DRIVER(sun4i_spi) = { + .name = "sun4i_spi", + .id = UCLASS_SPI, + .of_match = sun4i_spi_ids, + .ops = &sun4i_spi_ops, + .ofdata_to_platdata = sun4i_spi_ofdata_to_platdata, + .platdata_auto_alloc_size = sizeof(struct sun4i_spi_platdata), + .priv_auto_alloc_size = sizeof(struct sun4i_spi_priv), + .probe = sun4i_spi_probe, +};

Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are: - Exposing spi0 alternative pins in the dts file - Add alias node, enabling driver probing - Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2 I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB => sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com --- arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0; + spi0 = &spi0; };
chosen { @@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
+ spi0_pins_b: spi0@1 { + allwinner,pins = "PC0", "PC1", "PC2"; + allwinner,function = "spi0"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + }; + + spi0_cs0_pins_b: spi0_cs0@1 { + allwinner,pins = "PC23"; + allwinner,function = "spi0"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + }; + usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in"; @@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 { + pinctrl-names = "default"; + pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>; + status = "okay"; +}; + &uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>; diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y +CONFIG_CMD_SPI=y +CONFIG_SPI_FLASH=y +CONFIG_SPI_FLASH_WINBOND=y +CONFIG_SPL_SPI_SUNXI=y +CONFIG_DM_SPI=y +CONFIG_SUN4I_SPI=y

On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are:
- Exposing spi0 alternative pins in the dts file
- Add alias node, enabling driver probing
- Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
try to use erase/write and read commands to verify
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0;
spi0 = &spi0; }; chosen {
@@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
spi0_pins_b: spi0@1 {
allwinner,pins = "PC0", "PC1", "PC2";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
spi0_cs0_pins_b: spi0_cs0@1 {
allwinner,pins = "PC23";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in";
@@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>;
status = "okay";
+};
&uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>; diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
this command is not needed, since the current usage on your board as spi-nor flash

On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are:
- Exposing spi0 alternative pins in the dts file
- Add alias node, enabling driver probing
- Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0;
spi0 = &spi0; }; chosen {
@@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
spi0_pins_b: spi0@1 {
allwinner,pins = "PC0", "PC1", "PC2";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
spi0_cs0_pins_b: spi0_cs0@1 {
allwinner,pins = "PC23";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in";
@@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>;
status = "okay";
+};
- &uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
this command is not needed, since the current usage on your board as spi-nor flash
Regards, Stefan Mavrodiev

On 01/02/2018 01:01 PM, Stefan Mavrodiev wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are: - Exposing spi0 alternative pins in the dts file - Add alias node, enabling driver probing - Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0; + spi0 = &spi0; };
chosen { @@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
+ spi0_pins_b: spi0@1 { + allwinner,pins = "PC0", "PC1", "PC2"; + allwinner,function = "spi0"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + };
+ spi0_cs0_pins_b: spi0_cs0@1 { + allwinner,pins = "PC23"; + allwinner,function = "spi0"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + };
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in"; @@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 { + pinctrl-names = "default"; + pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>; + status = "okay"; +};
&uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>; diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
this command is not needed, since the current usage on your board as spi-nor flash
Regards, Stefan Mavrodiev
Hello,
What's the current status of the driver? Do I have to make more changes, etc ?
Regards, Stefan Mavrodiev

On Thu, Jan 11, 2018 at 11:38 AM, Stefan Mavrodiev stefan@olimex.com wrote:
On 01/02/2018 01:01 PM, Stefan Mavrodiev wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are:
- Exposing spi0 alternative pins in the dts file
- Add alias node, enabling driver probing
- Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0;
spi0 = &spi0; }; chosen {
@@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
spi0_pins_b: spi0@1 {
allwinner,pins = "PC0", "PC1", "PC2";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
spi0_cs0_pins_b: spi0_cs0@1 {
allwinner,pins = "PC23";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in";
@@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>;
status = "okay";
+};
- &uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
this command is not needed, since the current usage on your board as spi-nor flash
Regards, Stefan Mavrodiev
Hello,
What's the current status of the driver? Do I have to make more changes, etc ?
Basically you need to wait sometime for comments we are reviewing with defined order, you can see patchwork 'Under Review' state with 'jagan' as delegate for finding what patches are currently reviewing and patches waited long have priority.

On Tue, Jan 2, 2018 at 4:31 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are:
- Exposing spi0 alternative pins in the dts file
- Add alias node, enabling driver probing
- Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I've Rev.6 does it have spi-nor?
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
this can be an issue if we boot the system from spi-nor, where we can get saved env.
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0;
spi0 = &spi0; }; chosen {
@@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
spi0_pins_b: spi0@1 {
allwinner,pins = "PC0", "PC1", "PC2";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
spi0_cs0_pins_b: spi0_cs0@1 {
allwinner,pins = "PC23";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in";
@@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>;
status = "okay";
+};
- &uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
drop this.

On 01/22/2018 10:36 AM, Jagan Teki wrote:
On Tue, Jan 2, 2018 at 4:31 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are: - Exposing spi0 alternative pins in the dts file - Add alias node, enabling driver probing - Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200)
Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I've Rev.6 does it have spi-nor?
I assume Rev.6 is actually Rev.F. The first prototype with SPI flash is Rev.I (Rev.9).
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
this can be an issue if we boot the system from spi-nor, where we can get saved env.
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi => sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB,
total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0;
spi0 = &spi0; }; chosen {
@@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
spi0_pins_b: spi0@1 {
allwinner,pins = "PC0", "PC1", "PC2";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
spi0_cs0_pins_b: spi0_cs0@1 {
allwinner,pins = "PC23";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in";
@@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>;
status = "okay";
+};
- &uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
drop this.

On 01/30/2018 09:15 AM, Stefan Mavrodiev wrote:
On 01/22/2018 10:36 AM, Jagan Teki wrote:
On Tue, Jan 2, 2018 at 4:31 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are: - Exposing spi0 alternative pins in the dts file - Add alias node, enabling driver probing - Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 +0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I've Rev.6 does it have spi-nor?
I assume Rev.6 is actually Rev.F. The first prototype with SPI flash is Rev.I (Rev.9).
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
this can be an issue if we boot the system from spi-nor, where we can get saved env.
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0; + spi0 = &spi0; };
chosen { @@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
+ spi0_pins_b: spi0@1 { + allwinner,pins = "PC0", "PC1", "PC2"; + allwinner,function = "spi0"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + };
+ spi0_cs0_pins_b: spi0_cs0@1 { + allwinner,pins = "PC23"; + allwinner,function = "spi0"; + allwinner,drive = <SUN4I_PINCTRL_10_MA>; + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; + };
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in"; @@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 { + pinctrl-names = "default"; + pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>; + status = "okay"; +};
&uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>; diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
drop this.
Hi,
I have problem with the driver. I'm not sure where the problem is. Without calling sspi first, sf probe doesn't work. I guess driver doesn't bind.
The output is:
=> sf probe Invalid chip select 0:0 (err=-19) Failed to initialize SPI flash at 0:0
Maybe I'm missing something?
Regards, Stefan Mavrodiev

On Thu, Feb 1, 2018 at 8:08 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 01/30/2018 09:15 AM, Stefan Mavrodiev wrote:
On 01/22/2018 10:36 AM, Jagan Teki wrote:
On Tue, Jan 2, 2018 at 4:31 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Driver testing is done with A20-OLinuXino-Lime2. Testing requirements are: - Exposing spi0 alternative pins in the dts file - Add alias node, enabling driver probing - Enable spi flash related options in the defconfig file
The testing log is: U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48) DRAM: 1024 MiB CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 Trying to boot from sunxi SPI
U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48
+0200) Allwinner Technology
CPU: Allwinner A20 (SUN7I) Model: Olimex A20-OLinuXino-LIME2
Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I've Rev.6 does it have spi-nor?
I assume Rev.6 is actually Rev.F. The first prototype with SPI flash is Rev.I (Rev.9).
I2C: ready DRAM: 1 GiB MMC: SUNXI SD/MMC: 0 MMC: no card present mmc_init: -123, time 1 *** Warning - MMC init failed, using default environment
you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
this can be an issue if we boot the system from spi-nor, where we can get saved env.
In: serial Out: serial Err: serial Allwinner mUSB OTG (Peripheral) SCSI: SATA link 0 timeout. AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode flags: ncq stag pm led clo only pmp pio slum part ccc apst Net: No ethernet found. starting USB... USB0: USB EHCI 1.00 USB1: USB OHCI 1.0 USB2: USB EHCI 1.00 USB3: USB OHCI 1.0 scanning bus 0 for devices... 1 USB Device(s) found scanning bus 2 for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s)
found Hit any key to stop autoboot: 0 => sspi
=> sf probe SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB,
total 16 MiB
try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
=> sf test 0 100000 SPI flash test: 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps Test passed 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps =>
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 +++++++++++++++++++++ configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ 2 files changed, 29 insertions(+)
diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts index d5c796c..3c708da 100644 --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts @@ -54,6 +54,7 @@
aliases { serial0 = &uart0;
spi0 = &spi0; }; chosen {
@@ -215,6 +216,20 @@ allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; };
spi0_pins_b: spi0@1 {
allwinner,pins = "PC0", "PC1", "PC2";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
spi0_cs0_pins_b: spi0_cs0@1 {
allwinner,pins = "PC23";
allwinner,function = "spi0";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
usb0_id_detect_pin: usb0_id_detect_pin@0 { allwinner,pins = "PH4"; allwinner,function = "gpio_in";
@@ -257,6 +272,12 @@ status = "okay"; };
+&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>;
status = "okay";
+};
- &uart0 { pinctrl-names = "default"; pinctrl-0 = <&uart0_pins_a>;
diff --git a/configs/A20-OLinuXino-Lime2_defconfig b/configs/A20-OLinuXino-Lime2_defconfig index 1edc844..c499e3d 100644 --- a/configs/A20-OLinuXino-Lime2_defconfig +++ b/configs/A20-OLinuXino-Lime2_defconfig @@ -30,3 +30,11 @@ CONFIG_SCSI=y CONFIG_USB_EHCI_HCD=y CONFIG_USB_MUSB_GADGET=y CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y +CONFIG_CMD_SF=y +CONFIG_CMD_SF_TEST=y
Ok, but not useful to include in config's
+CONFIG_CMD_SPI=y
drop this.
Hi,
I have problem with the driver. I'm not sure where the problem is. Without calling sspi first, sf probe doesn't work. I guess driver doesn't bind.
The output is:
=> sf probe Invalid chip select 0:0 (err=-19) Failed to initialize SPI flash at 0:0
Haa..observed similar with sun6i_spi [1], what I've seen is controller writes are not done with direct 'sf probe'
So with sspi are you able to do ops with sf?
[1] http://git.denx.de/?p=u-boot-spi.git;a=commitdiff;h=0a45dde186f766626b806de3...

On 02/01/2018 04:45 PM, Jagan Teki wrote:
On Thu, Feb 1, 2018 at 8:08 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 01/30/2018 09:15 AM, Stefan Mavrodiev wrote:
On 01/22/2018 10:36 AM, Jagan Teki wrote:
On Tue, Jan 2, 2018 at 4:31 PM, Stefan Mavrodiev stefan.mavrodiev@gmail.com wrote:
On 12/26/2017 11:47 AM, Jagan Teki wrote:
On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote: > Driver testing is done with A20-OLinuXino-Lime2. Testing > requirements are: > - Exposing spi0 alternative pins in the dts file > - Add alias node, enabling driver probing > - Enable spi flash related options in the defconfig file > > The testing log is: > U-Boot SPL 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - > 11:39:48) > DRAM: 1024 MiB > CPU: 912000000Hz, AXI/AHB/APB: 3/2/2 > Trying to boot from sunxi SPI > > > U-Boot 2018.01-rc2-00023-gfa13cb3-dirty (Dec 22 2017 - 11:39:48 > +0200) > Allwinner Technology > > CPU: Allwinner A20 (SUN7I) > Model: Olimex A20-OLinuXino-LIME2 Lime2 doen't have in-built spi-nor is it?
We have some prototypes with this option.
I've Rev.6 does it have spi-nor?
I assume Rev.6 is actually Rev.F. The first prototype with SPI flash is Rev.I (Rev.9).
> I2C: ready > DRAM: 1 GiB > MMC: SUNXI SD/MMC: 0 > MMC: no card present > mmc_init: -123, time 1 > *** Warning - MMC init failed, using default environment you lost the env? since it's spi-nor better to use flash env.
What's the point since this is only test case?
this can be an issue if we boot the system from spi-nor, where we can get saved env.
> In: serial > Out: serial > Err: serial > Allwinner mUSB OTG (Peripheral) > SCSI: SATA link 0 timeout. > AHCI 0001.0100 32 slots 1 ports 3 Gbps 0x1 impl SATA mode > flags: ncq stag pm led clo only pmp pio slum part ccc apst > Net: No ethernet found. > starting USB... > USB0: USB EHCI 1.00 > USB1: USB OHCI 1.0 > USB2: USB EHCI 1.00 > USB3: USB OHCI 1.0 > scanning bus 0 for devices... 1 USB Device(s) found > scanning bus 2 for devices... 1 USB Device(s) found > scanning usb for storage devices... 0 Storage Device(s) > found > Hit any key to stop autoboot: 0 > => sspi > > => sf probe > SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, > total 16 MiB try to use erase/write and read commands to verify
# Erase one sector => sf erase 0x1000 0x100 SF: 256 bytes @ 0x1000 Erased: ERROR => sf erase 0x1000 0x1000 SF: 4096 bytes @ 0x1000 Erased: OK
# Get some random data => md.b 0x50000000 0x100 50000000: d6 4d d0 7e 93 d8 0f 48 1b ef 7f 7e be 4e a8 5d .M.~...H...~.N.] 50000010: fd 9f e5 7f 2f 7b 5b 19 ed de d8 58 99 7a 24 da ..../{[....X.z$. 50000020: ef dd 9c 45 d7 97 ab 4f e7 fb ee 61 bc de 6a 1a ...E...O...a..j. 50000030: 9a 9f f4 3a be 4b 2f f3 ce 77 87 7e 07 23 af ff ...:.K/..w.~.#.. 50000040: e5 e5 c0 fa 65 e2 78 9b 16 38 42 52 e5 6c 52 0d ....e.x..8BR.lR. 50000050: f5 ff da 94 7f 98 96 d7 f0 9d 66 ae 9b b9 a2 cd ..........f..... 50000060: 0b dd f1 c9 1d 3b fe 5b cf ef d6 ce 8b c5 fd 56 .....;.[.......V 50000070: e2 52 eb 78 d4 f1 bf 57 56 6a 57 58 52 f1 0e 9d .R.x...WVjWXR... 50000080: df be f8 19 bf cf d7 ac 4b 3e 86 21 3f c3 fe 3e ........K>.!?..> 50000090: ea 27 52 ca 1f 79 bd 7b ef bf 96 c9 9d f6 81 d3 .'R..y.{........ 500000a0: cc 2e 8b c8 34 7f c5 2f 29 19 a8 dc 54 7a 07 1d ....4../)...Tz.. 500000b0: f4 e6 db ed 38 03 59 bb 31 ee b3 dd 5c e6 be 58 ....8.Y.1.....X 500000c0: a6 7c 87 61 84 47 e0 b1 a1 fc 6e d3 d5 93 bf 8a .|.a.G....n..... 500000d0: 5d a3 be 4b cf 07 1d 92 ff 36 f9 46 fb 5a cb 8f ]..K.....6.F.Z.. 500000e0: f9 27 7a b8 7b 07 2e 22 a1 ee 56 bc a7 de 57 6a .'z.{.."..V...Wj 500000f0: da d4 7d 7f ee db 7a e2 bc 5c 44 64 b7 fc ea 3e ..}...z..\Dd...
# Write one page to spi-nor => sf write 0x50000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Written: OK
# Readback data => sf read 0x51000000 0x1000 0x100 device 0 offset 0x1000, size 0x100 SF: 256 bytes @ 0x1000 Read: OK
# Compare data => cmp.b 0x50000000 0x51000000 0x100 Total of 256 byte(s) were the same
> => sf test 0 100000 > SPI flash test: > 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps > 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps > 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps > 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps > Test passed > 0 erase: 11407 ticks, 89 KiB/s 0.712 Mbps > 1 check: 8881 ticks, 115 KiB/s 0.920 Mbps > 2 write: 10824 ticks, 94 KiB/s 0.752 Mbps > 3 read: 8872 ticks, 115 KiB/s 0.920 Mbps > => > > Signed-off-by: Stefan Mavrodiev stefan@olimex.com > --- > arch/arm/dts/sun7i-a20-olinuxino-lime2.dts | 21 > +++++++++++++++++++++ > configs/A20-OLinuXino-Lime2_defconfig | 8 ++++++++ > 2 files changed, 29 insertions(+) > > diff --git a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts > b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts > index d5c796c..3c708da 100644 > --- a/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts > +++ b/arch/arm/dts/sun7i-a20-olinuxino-lime2.dts > @@ -54,6 +54,7 @@ > > aliases { > serial0 = &uart0; > + spi0 = &spi0; > }; > > chosen { > @@ -215,6 +216,20 @@ > allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; > }; > > + spi0_pins_b: spi0@1 { > + allwinner,pins = "PC0", "PC1", "PC2"; > + allwinner,function = "spi0"; > + allwinner,drive = <SUN4I_PINCTRL_10_MA>; > + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; > + }; > + > + spi0_cs0_pins_b: spi0_cs0@1 { > + allwinner,pins = "PC23"; > + allwinner,function = "spi0"; > + allwinner,drive = <SUN4I_PINCTRL_10_MA>; > + allwinner,pull = <SUN4I_PINCTRL_NO_PULL>; > + }; > + > usb0_id_detect_pin: usb0_id_detect_pin@0 { > allwinner,pins = "PH4"; > allwinner,function = "gpio_in"; > @@ -257,6 +272,12 @@ > status = "okay"; > }; > > +&spi0 { > + pinctrl-names = "default"; > + pinctrl-0 = <&spi0_pins_b>, <&spi0_cs0_pins_b>; > + status = "okay"; > +}; > + > &uart0 { > pinctrl-names = "default"; > pinctrl-0 = <&uart0_pins_a>; > diff --git a/configs/A20-OLinuXino-Lime2_defconfig > b/configs/A20-OLinuXino-Lime2_defconfig > index 1edc844..c499e3d 100644 > --- a/configs/A20-OLinuXino-Lime2_defconfig > +++ b/configs/A20-OLinuXino-Lime2_defconfig > @@ -30,3 +30,11 @@ CONFIG_SCSI=y > CONFIG_USB_EHCI_HCD=y > CONFIG_USB_MUSB_GADGET=y > CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y > +CONFIG_CMD_SF=y > +CONFIG_CMD_SF_TEST=y Ok, but not useful to include in config's
> +CONFIG_CMD_SPI=y
drop this.
Hi,
I have problem with the driver. I'm not sure where the problem is. Without calling sspi first, sf probe doesn't work. I guess driver doesn't bind.
The output is:
=> sf probe Invalid chip select 0:0 (err=-19) Failed to initialize SPI flash at 0:0
Haa..observed similar with sun6i_spi [1], what I've seen is controller writes are not done with direct 'sf probe'
So with sspi are you able to do ops with sf?
[1] http://git.denx.de/?p=u-boot-spi.git;a=commitdiff;h=0a45dde186f766626b806de3...
Hi,
I've made some fast debugging with/without sspi command.
=> sf probe spi_find_chip_select() -> device_find_first_child(spi@01c05000) device_find_first_child() -> parent: spi@01c05000 device_find_first_child() -> child_heads is empty! Invalid chip select 0:0 (err=-19) Failed to initialize SPI flash at 0:0
=> sspi spi_find_chip_select() -> device_find_first_child(spi@01c05000) device_find_first_child() -> parent: spi@01c05000 device_find_first_child() -> child_heads is empty! spi_get_bus_and_cs: Binding new device 'generic_0:0', busnum=0, cs=0, driver=spi_generic_drv device_bind_common() - name: generic_0:0; parent name: spi@01c05000 spi_get_bus_and_cs: bus=7af3c138, slave=7af4bd7
=> sf probe spi_find_chip_select() -> device_find_first_child(spi@01c05000) device_find_first_child() -> parent: spi@01c05000 spi_find_chip_select: plat=7af4bd68, cs=0 spi_get_bus_and_cs: bus=7af3c138, slave=7af4bd78 SF: Detected w25q128bv with page size 256 Bytes, erase size 4 KiB, total 16 MiB
What I can see is that the flash device never get binded with spi driver. The sspi command creates generic spi device, which later is used by sf opts.
I think flash device doesn't get read from the DT when CONFIG_DM_SPI_FLASH is enabled. If legacy controls are enabled maybe there should be way to bind driver to device?
Regards, Stefan Mavrodiev

On Fri, Dec 22, 2017 at 3:30 PM, Stefan Mavrodiev stefan@olimex.com wrote:
Add spi driver for sun4i, sun5i and sun7i SoCs. The driver is adapted from mailine kernel.
Signed-off-by: Stefan Mavrodiev stefan@olimex.com
Changes for v3: - Add required changes in dts and defeconfig file for testing
Changes for v2: - Updated copyright including original owners - Remove write/read register function. They are replaced with direct opts - Some coding style changes
drivers/spi/Kconfig | 5 + drivers/spi/Makefile | 1 + drivers/spi/sun4i_spi.c | 456 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 462 insertions(+) create mode 100644 drivers/spi/sun4i_spi.c
diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig index 494639f..9001182 100644 --- a/drivers/spi/Kconfig +++ b/drivers/spi/Kconfig @@ -132,6 +132,11 @@ config STM32_QSPI used to access the SPI NOR flash chips on platforms embedding this ST IP core.
+config SUN4I_SPI
bool "Allwinner A10 SoCs SPI controller"
help
SPI driver for Allwinner sun4i, sun5i and sun7i SoCs
config TEGRA114_SPI bool "nVidia Tegra114 SPI driver" help diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index e3184db..aa7645a 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -42,6 +42,7 @@ obj-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o obj-$(CONFIG_SH_SPI) += sh_spi.o obj-$(CONFIG_SH_QSPI) += sh_qspi.o obj-$(CONFIG_STM32_QSPI) += stm32_qspi.o +obj-$(CONFIG_SUN4I_SPI) += sun4i_spi.o obj-$(CONFIG_TEGRA114_SPI) += tegra114_spi.o obj-$(CONFIG_TEGRA20_SFLASH) += tegra20_sflash.o obj-$(CONFIG_TEGRA20_SLINK) += tegra20_slink.o diff --git a/drivers/spi/sun4i_spi.c b/drivers/spi/sun4i_spi.c new file mode 100644 index 0000000..4f4cca6 --- /dev/null +++ b/drivers/spi/sun4i_spi.c @@ -0,0 +1,456 @@ +/*
- (C) Copyright 2017 Whitebox Systems / Northend Systems B.V.
- S.J.R. van Schaik stephan@whiteboxsystems.nl
- M.B.W. Wajer merlijn@whiteboxsystems.nl
- (C) Copyright 2017 Olimex Ltd..
- Stefan Mavrodiev stefan@olimex.com
remove exctra line
- Based on linux spi driver. Original copyright follows:
- linux/drivers/spi/spi-sun4i.c
- Copyright (C) 2012 - 2014 Allwinner Tech
- Pan Nan pannan@allwinnertech.com
- Copyright (C) 2014 Maxime Ripard
- Maxime Ripard maxime.ripard@free-electrons.com
ditto
- SPDX-License-Identifier: GPL-2.0+
- */
+#include <common.h> +#include <dm.h> +#include <spi.h> +#include <errno.h> +#include <fdt_support.h> +#include <wait_bit.h>
+#include <asm/bitops.h> +#include <asm/gpio.h> +#include <asm/io.h>
+#include <asm/arch/clock.h>
+#define SUN4I_FIFO_DEPTH 64
+#define SUN4I_RXDATA_REG 0x00
+#define SUN4I_TXDATA_REG 0x04
+#define SUN4I_CTL_REG 0x08 +#define SUN4I_CTL_ENABLE BIT(0) +#define SUN4I_CTL_MASTER BIT(1) +#define SUN4I_CTL_CPHA BIT(2) +#define SUN4I_CTL_CPOL BIT(3) +#define SUN4I_CTL_CS_ACTIVE_LOW BIT(4) +#define SUN4I_CTL_LMTF BIT(6) +#define SUN4I_CTL_TF_RST BIT(8) +#define SUN4I_CTL_RF_RST BIT(9) +#define SUN4I_CTL_XCH_MASK 0x0400 +#define SUN4I_CTL_XCH BIT(10) +#define SUN4I_CTL_CS_MASK 0x3000 +#define SUN4I_CTL_CS(cs) (((cs) << 12) & SUN4I_CTL_CS_MASK) +#define SUN4I_CTL_DHB BIT(15) +#define SUN4I_CTL_CS_MANUAL BIT(16) +#define SUN4I_CTL_CS_LEVEL BIT(17) +#define SUN4I_CTL_TP BIT(18)
+#define SUN4I_INT_CTL_REG 0x0c +#define SUN4I_INT_CTL_RF_F34 BIT(4) +#define SUN4I_INT_CTL_TF_E34 BIT(12) +#define SUN4I_INT_CTL_TC BIT(16)
+#define SUN4I_INT_STA_REG 0x10
+#define SUN4I_DMA_CTL_REG 0x14
+#define SUN4I_WAIT_REG 0x18
+#define SUN4I_CLK_CTL_REG 0x1c +#define SUN4I_CLK_CTL_CDR2_MASK 0xff +#define SUN4I_CLK_CTL_CDR2(div) ((div) & SUN4I_CLK_CTL_CDR2_MASK) +#define SUN4I_CLK_CTL_CDR1_MASK 0xf +#define SUN4I_CLK_CTL_CDR1(div) (((div) & SUN4I_CLK_CTL_CDR1_MASK) << 8) +#define SUN4I_CLK_CTL_DRS BIT(12)
+#define SUN4I_MAX_XFER_SIZE 0xffffff
+#define SUN4I_BURST_CNT_REG 0x20 +#define SUN4I_BURST_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
+#define SUN4I_XMIT_CNT_REG 0x24 +#define SUN4I_XMIT_CNT(cnt) ((cnt) & SUN4I_MAX_XFER_SIZE)
+#define SUN4I_FIFO_STA_REG 0x28 +#define SUN4I_FIFO_STA_RF_CNT_MASK 0x7f +#define SUN4I_FIFO_STA_RF_CNT_BITS 0 +#define SUN4I_FIFO_STA_TF_CNT_MASK 0x7f +#define SUN4I_FIFO_STA_TF_CNT_BITS 16
+#define SUN4I_SPI_MAX_RATE 24000000 +#define SUN4I_SPI_MIN_RATE 3000 +#define SUN4I_SPI_DEFAULT_RATE 1000000 +#define SUN4I_SPI_TIMEOUT_US 1000000
+/* sun4i spi register set */ +struct sun4i_spi_regs {
u32 rxdata;
u32 txdata;
u32 ctl;
u32 intctl;
u32 st;
u32 dmactl;
u32 wait;
u32 cctl;
u32 bc;
u32 tc;
u32 fifo_sta;
+};
+struct sun4i_spi_platdata {
u32 base_addr;
u32 max_hz;
+};
+struct sun4i_spi_priv {
struct sun4i_spi_regs *regs;
u32 freq;
u32 mode;
const u8 *tx_buf;
u8 *rx_buf;
+};
+DECLARE_GLOBAL_DATA_PTR;
+static inline void sun4i_spi_drain_fifo(struct sun4i_spi_priv *priv, int len) +{
u8 byte;
while (len--) {
byte = readb(&priv->regs->rxdata);
*priv->rx_buf++ = byte;
}
+}
+static inline void sun4i_spi_fill_fifo(struct sun4i_spi_priv *priv, int len) +{
u8 byte;
while (len--) {
byte = priv->tx_buf ? *priv->tx_buf++ : 0;
writeb(byte, &priv->regs->txdata);
}
+}
+static void sun4i_spi_set_cs(struct udevice *bus, u8 cs, bool enable) +{
struct sun4i_spi_priv *priv = dev_get_priv(bus);
u32 reg;
reg = readl(&priv->regs->ctl);
reg &= ~SUN4I_CTL_CS_MASK;
reg |= SUN4I_CTL_CS(cs);
if (enable)
reg &= ~SUN4I_CTL_CS_LEVEL;
else
reg |= SUN4I_CTL_CS_LEVEL;
writel(reg, &priv->regs->ctl);
+}
+static int sun4i_spi_parse_pins(struct udevice *dev) +{
const void *fdt = gd->fdt_blob;
const char *pin_name;
const fdt32_t *list;
u32 phandle;
int drive, pull = 0, pin, i;
int offset;
int size;
list = fdt_getprop(fdt, dev_of_offset(dev), "pinctrl-0", &size);
if (!list) {
printf("WARNING: sun4i_spi: cannot find pinctrl-0 node\n");
return -EINVAL;
}
while (size) {
phandle = fdt32_to_cpu(*list++);
size -= sizeof(*list);
offset = fdt_node_offset_by_phandle(fdt, phandle);
if (offset < 0)
return offset;
drive = fdt_getprop_u32_default_node(fdt, offset, 0,
"drive-strength", 0);
if (drive) {
if (drive <= 10)
drive = 0;
else if (drive <= 20)
drive = 1;
else if (drive <= 30)
drive = 2;
else
drive = 3;
} else {
drive = fdt_getprop_u32_default_node(fdt, offset, 0,
"allwinner,drive",
0);
drive = min(drive, 3);
}
if (fdt_get_property(fdt, offset, "bias-disable", NULL))
pull = 0;
else if (fdt_get_property(fdt, offset, "bias-pull-up", NULL))
pull = 1;
else if (fdt_get_property(fdt, offset, "bias-pull-down", NULL))
pull = 2;
else
pull = fdt_getprop_u32_default_node(fdt, offset, 0,
"allwinner,pull",
0);
pull = min(pull, 2);
for (i = 0; ; i++) {
pin_name = fdt_stringlist_get(fdt, offset,
"pins", i, NULL);
if (!pin_name) {
pin_name = fdt_stringlist_get(fdt, offset,
"allwinner,pins",
i, NULL);
if (!pin_name)
break;
}
pin = name_to_gpio(pin_name);
if (pin < 0)
break;
sunxi_gpio_set_cfgpin(pin, SUNXI_GPC_SPI0);
sunxi_gpio_set_drv(pin, drive);
sunxi_gpio_set_pull(pin, pull);
}
}
return 0;
+}
+static inline void sun4i_spi_enable_clock(void) +{
struct sunxi_ccm_reg *const ccm =
(struct sunxi_ccm_reg *const)SUNXI_CCM_BASE;
setbits_le32(&ccm->ahb_gate0, (1 << AHB_GATE_OFFSET_SPI0));
writel((1 << 31), &ccm->spi0_clk_cfg);
+}
+static int sun4i_spi_ofdata_to_platdata(struct udevice *bus) +{
struct sun4i_spi_platdata *plat = dev_get_platdata(bus);
int node = dev_of_offset(bus);
plat->base_addr = devfdt_get_addr(bus);
plat->max_hz = fdtdec_get_int(gd->fdt_blob, node,
"spi-max-frequency",
SUN4I_SPI_DEFAULT_RATE);
if (plat->max_hz > SUN4I_SPI_MAX_RATE)
plat->max_hz = SUN4I_SPI_MAX_RATE;
return 0;
+}
+static int sun4i_spi_probe(struct udevice *bus) +{
struct sun4i_spi_platdata *plat = dev_get_platdata(bus);
struct sun4i_spi_priv *priv = dev_get_priv(bus);
sun4i_spi_enable_clock();
sun4i_spi_parse_pins(bus);
priv->regs = (struct sun4i_spi_regs *)(uintptr_t)plat->base_addr;
priv->freq = plat->max_hz;
return 0;
+}
+static int sun4i_spi_claim_bus(struct udevice *dev) +{
struct sun4i_spi_priv *priv = dev_get_priv(dev->parent);
writel(SUN4I_CTL_ENABLE | SUN4I_CTL_MASTER | SUN4I_CTL_TP |
SUN4I_CTL_CS_MANUAL | SUN4I_CTL_CS_ACTIVE_LOW,
&priv->regs->ctl);
return 0;
+}
+static int sun4i_spi_release_bus(struct udevice *dev) +{
struct sun4i_spi_priv *priv = dev_get_priv(dev->parent);
u32 reg;
reg = readl(&priv->regs->ctl);
reg &= ~SUN4I_CTL_ENABLE;
writel(reg, &priv->regs->ctl);
return 0;
+}
+static int sun4i_spi_xfer(struct udevice *dev, unsigned int bitlen,
const void *dout, void *din, unsigned long flags)
+{
struct udevice *bus = dev->parent;
struct sun4i_spi_priv *priv = dev_get_priv(bus);
struct dm_spi_slave_platdata *slave_plat = dev_get_parent_platdata(dev);
u32 len = bitlen / 8;
u32 reg;
u8 nbytes;
int ret;
priv->tx_buf = dout;
priv->rx_buf = din;
if (bitlen % 8) {
debug("%s: non byte-aligned SPI transfer.\n", __func__);
return -ENAVAIL;
}
if (flags & SPI_XFER_BEGIN)
sun4i_spi_set_cs(bus, slave_plat->cs, true);
reg = readl(&priv->regs->ctl);
/* Reset FIFOs */
writel(reg | SUN4I_CTL_RF_RST | SUN4I_CTL_TF_RST, &priv->regs->ctl);
while (len) {
/* Setup the transfer now... */
nbytes = min(len, (u32)(SUN4I_FIFO_DEPTH - 1));
/* Setup the counters */
writel(SUN4I_BURST_CNT(nbytes), &priv->regs->bc);
writel(SUN4I_XMIT_CNT(nbytes), &priv->regs->tc);
/* Fill the TX FIFO */
sun4i_spi_fill_fifo(priv, nbytes);
/* Start the transfer */
reg = readl(&priv->regs->ctl);
writel(reg | SUN4I_CTL_XCH, &priv->regs->ctl);
/* Wait transfer to complete */
ret = wait_for_bit(__func__, &priv->regs->ctl,
SUN4I_CTL_XCH_MASK, false,
SUN4I_SPI_TIMEOUT_US, false);
if (ret) {
printf("ERROR: sun4i_spi: Timeout transferring data\n");
sun4i_spi_set_cs(bus, slave_plat->cs, false);
return ret;
}
/* Drain the RX FIFO */
sun4i_spi_drain_fifo(priv, nbytes);
len -= nbytes;
}
if (flags & SPI_XFER_END)
sun4i_spi_set_cs(bus, slave_plat->cs, false);
return 0;
+}
+static int sun4i_spi_set_speed(struct udevice *dev, uint speed) +{
struct sun4i_spi_platdata *plat = dev_get_platdata(dev);
struct sun4i_spi_priv *priv = dev_get_priv(dev);
unsigned int div;
u32 reg;
if (speed > plat->max_hz)
speed = plat->max_hz;
if (speed < SUN4I_SPI_MIN_RATE)
speed = SUN4I_SPI_MIN_RATE;
/*
* Setup clock divider.
*
* We have two choices there. Either we can use the clock
* divide rate 1, which is calculated thanks to this formula:
* SPI_CLK = MOD_CLK / (2 ^ (cdr + 1))
* Or we can use CDR2, which is calculated with the formula:
* SPI_CLK = MOD_CLK / (2 * (cdr + 1))
* Whether we use the former or the latter is set through the
* DRS bit.
*
* First try CDR2, and if we can't reach the expected
* frequency, fall back to CDR1.
*/
read cctl on reg before writiing.
Except above changes,
Reviewed-by: Jagan Teki jagan@openedev.com
participants (3)
-
Jagan Teki
-
Stefan Mavrodiev
-
Stefan Mavrodiev