Skip to contentSkip to conversation

Cortina Access Drivers Package 2

PATCH Superseded Alex Nemirovsky 3 participants 13 messages Apr 21, 2020

Subsystems (4)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover Cortina Access Drivers Package 2

This release adds the following drivers and
integrates support into the Cortina Access
Presidio Engineering Board:

CAxxxx SoC eMMC/SD controller
CAxxxx SoC I2C controller
CAxxxx Soc LED controller
CAxxxx SPI NAND and NOR controller

Changes in v6:
- Add I2C DT binding document

Changes in v5:
- Rebase code basis on v2020.04-rc5 which has
already incorporated CAxxxx eMMC initial baseline
- Rebase on codebase basis v2020.04-rc5 which already incorporated initial baseline of eMMC DT information
- NAND support removed from presidio-asic board DT.

Changes in v4:
- Rename DT compatible name
- Remove uneccessary if-statement to support 8-bit buswidth
- Remove redundant error msg
- Use symbolic constants in switch statement
- Change DT compatiblity name to match change in driver's name
- Remove unused io_ds and fifo_mode fields from DT
- Utilize standard I2C macros from <i2c.h>
- Return ETIMEDOUT in funcs that can timeout
- Return i2c_xfer_init() result to caller of i2c_read() if it fails within i2c_read() execution
- Fix misc. style guide conformance issues
- Use printf() to report i2c_xfer() runtime errors instead of debug()
- remove unused macros
- remove cortina prefix from macros
- remove use BSS variable
- further cleanup to meet code style guidelines
- add additinal struct comments
- rename DT blink rate symbol
- rename DT blink rate symbol

Changes in v3:
- Fixup syntax issues related to checkpatch.pl cleanup

Changes in v2:
- Add I2C controller
- Add LED controller
- Add SPI NAND and NOR controller

Alex Nemirovsky (3):
board: presidio-asic: update eMMC DT informatino
board: presidio-asic: Add I2C support
board: presidio-asic: Add SPI NOR support

Arthur Li (2):
mmc: ca_dw_mmc: Misc cleanup of driver
i2c: i2c-cortina: added CAxxxx I2C support

Jway Lin (2):
led: led_cortina: Add CAxxx LED support
board: presidio: add LED support

Pengpeng Chen (1):
spi: ca_sflash: Add CAxxxx SPI Flash Controller

 MAINTAINERS                                      |   8 +
 arch/arm/dts/ca-presidio-engboard.dts            |  41 +-
 board/cortina/presidio-asic/presidio.c           |  16 +-
 configs/cortina_presidio-asic-emmc_defconfig     |   5 +
 configs/cortina_presidio-asic-spi-nand_defconfig |  48 ++
 configs/cortina_presidio-asic-spi-nor_defconfig  |  59 +++
 doc/device-tree-bindings/i2c/i2c-cortina.txt     |  18 +
 drivers/i2c/Kconfig                              |   7 +
 drivers/i2c/Makefile                             |   1 +
 drivers/i2c/i2c-cortina.c                        | 346 ++++++++++++++
 drivers/i2c/i2c-cortina.h                        |  84 ++++
 drivers/led/Kconfig                              |   8 +
 drivers/led/Makefile                             |   1 +
 drivers/led/led_cortina.c                        | 268 +++++++++++
 drivers/mmc/ca_dw_mmc.c                          |  34 +-
 drivers/spi/Kconfig                              |   8 +
 drivers/spi/Makefile                             |   1 +
 drivers/spi/ca_sflash.c                          | 576 +++++++++++++++++++++++
 18 files changed, 1499 insertions(+), 30 deletions(-)
 create mode 100644 configs/cortina_presidio-asic-spi-nand_defconfig
 create mode 100644 configs/cortina_presidio-asic-spi-nor_defconfig
 create mode 100644 doc/device-tree-bindings/i2c/i2c-cortina.txt
 create mode 100644 drivers/i2c/i2c-cortina.c
 create mode 100644 drivers/i2c/i2c-cortina.h
 create mode 100644 drivers/led/led_cortina.c
 create mode 100644 drivers/spi/ca_sflash.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v6 1/8 mmc: ca_dw_mmc: Misc cleanup of driver

From: Arthur Li <[email protected]>

- Rename DT compatible name
- Remove uneccessary if-statement to support 8-bit buswidth
- Remove redundant error msg
- Use symbolic constants in switch statement

---

Changes in v6: None
Changes in v5:
- Rebase code basis on v2020.04-rc5 which has already incorporated CAxxxx eMMC initial baseline

Changes in v4:
- Rename DT compatible name
- Remove uneccessary if-statement to support 8-bit buswidth
- Remove redundant error msg
- Use symbolic constants in switch statement

Changes in v3: None
Changes in v2:
- Add I2C controller
- Add LED controller
- Add SPI NAND and NOR controller

 drivers/mmc/ca_dw_mmc.c | 34 ++++++++++++----------------------
 1 file changed, 12 insertions(+), 22 deletions(-)
drivers/mmc/ca_dw_mmc.c +12 -22
index acbc850..198c41f 100644
@@ -19,6 +19,7 @@
 
 #define SD_CLK_SEL_200MHZ (0x2)
 #define SD_CLK_SEL_100MHZ (0x1)
+#define SD_CLK_SEL_50MHZ (0x0)
 
 #define IO_DRV_SD_DS_OFFSET (16)
 #define IO_DRV_SD_DS_MASK   (0xff << IO_DRV_SD_DS_OFFSET)
@@ -44,15 +45,11 @@ static void ca_dwmci_clksel(struct dwmci_host *host)
 	struct ca_dwmmc_priv_data *priv = host->priv;
 	u32 val = readl(priv->sd_dll_reg);
 
-	if (host->bus_hz >= 200000000) {
-		val &= ~SD_CLK_SEL_MASK;
+	val &= ~SD_CLK_SEL_MASK;
+	if (host->bus_hz >= 200000000)
 		val |= SD_CLK_SEL_200MHZ;
-	} else if (host->bus_hz >= 100000000) {
-		val &= ~SD_CLK_SEL_MASK;
+	else if (host->bus_hz >= 100000000)
 		val |= SD_CLK_SEL_100MHZ;
-	} else {
-		val &= ~SD_CLK_SEL_MASK;
-	}
 
 	writel(val, priv->sd_dll_reg);
 }
@@ -77,14 +74,14 @@ unsigned int ca_dwmci_get_mmc_clock(struct dwmci_host *host, uint freq)
 	u8 clk_div;
 
 	switch (sd_clk_sel) {
-	case 2:
-		clk_div = 1;
+	case SD_CLK_SEL_50MHZ:
+		clk_div = 4;
 		break;
-	case 1:
+	case SD_CLK_SEL_100MHZ:
 		clk_div = 2;
 		break;
 	default:
-		clk_div = 4;
+		clk_div = 1;
 	}
 
 	return SD_SCLK_MAX / clk_div / (host->div + 1);
@@ -100,9 +97,6 @@ static int ca_dwmmc_ofdata_to_platdata(struct udevice *dev)
 	host->dev_index = 0;
 
 	host->buswidth = dev_read_u32_default(dev, "bus-width", 1);
-	if (host->buswidth != 1 && host->buswidth != 4)
-		return -EINVAL;
-
 	host->bus_hz = dev_read_u32_default(dev, "max-frequency", 50000000);
 	priv->ds = dev_read_u32_default(dev, "io_ds", 0x33);
 	host->fifo_mode = dev_read_bool(dev, "fifo-mode");
@@ -118,10 +112,8 @@ static int ca_dwmmc_ofdata_to_platdata(struct udevice *dev)
 		return -EINVAL;
 
 	host->ioaddr = dev_read_addr_ptr(dev);
-	if (host->ioaddr == (void *)FDT_ADDR_T_NONE) {
-		printf("DWMMC: base address is invalid\n");
+	if (!host->ioaddr)
 		return -EINVAL;
-	}
 
 	host->priv = priv;
 
@@ -140,10 +132,8 @@ static int ca_dwmmc_probe(struct udevice *dev)
 	memcpy(&ca_dwmci_dm_ops, &dm_dwmci_ops, sizeof(struct dm_mmc_ops));
 
 	dwmci_setup_cfg(&plat->cfg, host, host->bus_hz, MIN_FREQ);
-	if (host->buswidth == 1) {
-		(&plat->cfg)->host_caps &= ~MMC_MODE_8BIT;
-		(&plat->cfg)->host_caps &= ~MMC_MODE_4BIT;
-	}
+	if (host->buswidth == 1)
+		(&plat->cfg)->host_caps &= ~(MMC_MODE_8BIT | MMC_MODE_4BIT);
 
 	host->mmc = &plat->mmc;
 	host->mmc->priv = &priv->host;
@@ -164,7 +154,7 @@ static int ca_dwmmc_bind(struct udevice *dev)
 }
 
 static const struct udevice_id ca_dwmmc_ids[] = {
-	{ .compatible = "snps,dw-cortina" },
+	{ .compatible = "cortina,ca-mmc" },
 	{ }
 };
 
Signature · 1 line
2.7.4
#2 lore raw

PATCH v6 2/8 board: presidio-asic: update eMMC DT informatino

In reply to Alex Nemirovsky

Change DT compatiblity name to match change in driver's name. Remove unused io_ds and fifo_mode fields from DT.

---

Changes in v6: None
Changes in v5:
- Rebase on codebase basis v2020.04-rc5 which already incorporated initial baseline of eMMC DT information

Changes in v4:
- Change DT compatiblity name to match change in driver's name
- Remove unused io_ds and fifo_mode fields from DT

Changes in v3: None
Changes in v2: None

 arch/arm/dts/ca-presidio-engboard.dts | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
arch/arm/dts/ca-presidio-engboard.dts +1 -3
index c03dacc..40c93d7 100644
@@ -10,11 +10,9 @@
    #size-cells = <1>;
 
 	mmc0: mmc at f4400000 {
-		compatible = "snps,dw-cortina";
+		compatible = "cortina,ca-mmc";
 		reg = <0x0 0xf4400000 0x1000>;
 		bus-width = <4>;
-		io_ds = <0x77>;
-		fifo-mode;
 		sd_dll_ctrl = <0xf43200e8>;
 		io_drv_ctrl = <0xf432004c>;
 	};
Signature · 1 line
2.7.4
#3 lore raw

PATCH v6 3/8 i2c: i2c-cortina: added CAxxxx I2C support

In reply to Alex Nemirovsky

From: Arthur Li <[email protected]>

Add I2C controller support for Cortina Access CAxxxx SoCs

CA_I2C: DT binding for I2C controller

DT binding document for Cortina I2C driver

---

Changes in v6:
- Add I2C DT binding document

Changes in v5: None
Changes in v4:
- Utilize standard I2C macros from <i2c.h>
- Return ETIMEDOUT in funcs that can timeout
- Return i2c_xfer_init() result to caller of i2c_read() if it fails within i2c_read() execution
- Fix misc. style guide conformance issues
- Use printf() to report i2c_xfer() runtime errors instead of debug()

Changes in v3: None
Changes in v2: None

 MAINTAINERS                                  |   4 +
 doc/device-tree-bindings/i2c/i2c-cortina.txt |  18 ++
 drivers/i2c/Kconfig                          |   7 +
 drivers/i2c/Makefile                         |   1 +
 drivers/i2c/i2c-cortina.c                    | 346 +++++++++++++++++++++++++++
 drivers/i2c/i2c-cortina.h                    |  84 +++++++
 6 files changed, 460 insertions(+)
 create mode 100644 doc/device-tree-bindings/i2c/i2c-cortina.txt
 create mode 100644 drivers/i2c/i2c-cortina.c
 create mode 100644 drivers/i2c/i2c-cortina.h
MAINTAINERS +4 -0
index 0ee358b..307e620 100644
@@ -181,6 +181,8 @@ F:	drivers/gpio/cortina_gpio.c
 F:	drivers/watchdog/cortina_wdt.c
 F:	drivers/serial/serial_cortina.c
 F:	drivers/mmc/ca_dw_mmc.c
+F:	drivers/i2c/i2c-cortina.c
+F:	drivers/i2c/i2c-cortina.h
 
 ARM/CZ.NIC TURRIS MOX SUPPORT
 M:	Marek Behun <[email protected]>
@@ -720,6 +722,8 @@ F:	drivers/gpio/cortina_gpio.c
 F:	drivers/watchdog/cortina_wdt.c
 F:	drivers/serial/serial_cortina.c
 F:	drivers/mmc/ca_dw_mmc.c
+F:	drivers/i2c/i2c-cortina.c
+F:	drivers/i2c/i2c-cortina.h
 
 MIPS MSCC
 M:	Gregory CLEMENT <[email protected]>
doc/device-tree-bindings/i2c/i2c-cortina.txt new file +18 -0
new file mode 100644
index 0000000..59d5235
@@ -0,0 +1,18 @@
+* I2C for Cortina platforms
+
+Required properties :
+- compatible : Must be "cortina,ca-i2c"
+- reg : Offset and length of the register set for the device
+
+Recommended properties :
+- clock-frequency : desired I2C bus clock frequency in Hz. If not specified,
+		    default value is 100000. Possible values are 100000,
+		    400000 and 1000000.
+
+Examples :
+
+	i2c: i2c at f4329120 {
+		compatible = "cortina,ca-i2c";
+		reg = <0x0 0xf4329120 0x28>;
+		clock-frequency = <400000>;
+	};
drivers/i2c/Kconfig +7 -0
index 03d2fed..b98a4aa 100644
@@ -85,6 +85,13 @@ config SYS_I2C_CADENCE
 	  Say yes here to select Cadence I2C Host Controller. This controller is
 	  e.g. used by Xilinx Zynq.
 
+config SYS_I2C_CA
+	tristate "Cortina-Access I2C Controller"
+	depends on DM_I2C && CORTINA_PLATFORM
+	default n
+	help
+	  Say yes here to select Cortina-Access I2C Host Controller.
+
 config SYS_I2C_DAVINCI
 	bool "Davinci I2C Controller"
 	depends on (ARCH_KEYSTONE || ARCH_DAVINCI)
drivers/i2c/Makefile +1 -0
index f5a471f..5d18cf7 100644
@@ -12,6 +12,7 @@ obj-$(CONFIG_SYS_I2C) += i2c_core.o
 obj-$(CONFIG_SYS_I2C_ASPEED) += ast_i2c.o
 obj-$(CONFIG_SYS_I2C_AT91) += at91_i2c.o
 obj-$(CONFIG_SYS_I2C_CADENCE) += i2c-cdns.o
+obj-$(CONFIG_SYS_I2C_CA) += i2c-cortina.o
 obj-$(CONFIG_SYS_I2C_DAVINCI) += davinci_i2c.o
 obj-$(CONFIG_SYS_I2C_DW) += designware_i2c.o
 ifdef CONFIG_DM_PCI
drivers/i2c/i2c-cortina.c new file +346 -0

346 lines not on this page · raw message

drivers/i2c/i2c-cortina.h new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH v6 3/8 i2c: i2c-cortina: added CAxxxx I2C support

Hello Alex,

Am 21.04.2020 um 07:29 schrieb Alex Nemirovsky:

Quoted 8 lines

From: Arthur Li <[email protected]>

Add I2C controller support for Cortina Access CAxxxx SoCs

Quoted 8 lines

CA_I2C: DT binding for I2C controller

DT binding document for Cortina I2C driver

---

Changes in v6:
- Add I2C DT binding document

Thanks!

Quoted 21 lines

Changes in v5: None
Changes in v4:
- Utilize standard I2C macros from <i2c.h>
- Return ETIMEDOUT in funcs that can timeout
- Return i2c_xfer_init() result to caller of i2c_read() if it fails within i2c_read() execution
- Fix misc. style guide conformance issues
- Use printf() to report i2c_xfer() runtime errors instead of debug()

Changes in v3: None
Changes in v2: None

  MAINTAINERS                                  |   4 +
  doc/device-tree-bindings/i2c/i2c-cortina.txt |  18 ++
  drivers/i2c/Kconfig                          |   7 +
  drivers/i2c/Makefile                         |   1 +
  drivers/i2c/i2c-cortina.c                    | 346 +++++++++++++++++++++++++++
  drivers/i2c/i2c-cortina.h                    |  84 +++++++
  6 files changed, 460 insertions(+)
Quoted 3 lines

create mode 100644 doc/device-tree-bindings/i2c/i2c-cortina.txt create mode 100644 drivers/i2c/i2c-cortina.c
create mode 100644 drivers/i2c/i2c-cortina.h

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#5 lore raw

PATCH v6 4/8 board: presidio-asic: Add I2C support

In reply to Alex Nemirovsky

Add I2C board support for Cortina Access Presidio Engineering Board

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

 configs/cortina_presidio-asic-emmc_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/cortina_presidio-asic-emmc_defconfig +3 -0
index e10008a..e45e23c 100644
@@ -10,6 +10,7 @@ CONFIG_SHOW_BOOT_PROGRESS=y
 CONFIG_BOOTDELAY=3
 CONFIG_BOARD_EARLY_INIT_R=y
 CONFIG_SYS_PROMPT="G3#"
+CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PART=y
 CONFIG_CMD_WDT=y
@@ -24,6 +25,8 @@ CONFIG_DEFAULT_DEVICE_TREE="ca-presidio-engboard"
 # CONFIG_NET is not set
 CONFIG_DM=y
 CONFIG_CORTINA_GPIO=y
+CONFIG_DM_I2C=y
+CONFIG_SYS_I2C_CA=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_DW=y
 CONFIG_MMC_DW_CORTINA=y
Signature · 1 line
2.7.4
#6 lore raw

PATCH v6 4/8 board: presidio-asic: Add I2C support

Hello Alex,

Am 21.04.2020 um 07:29 schrieb Alex Nemirovsky:

Quoted 6 lines

Add I2C board support for Cortina Access Presidio Engineering Board

---

Quoted 8 lines

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3: None
Changes in v2: None

  configs/cortina_presidio-asic-emmc_defconfig | 3 +++
  1 file changed, 3 insertions(+)

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: hs at denx.de
#7 lore raw

PATCH v6 5/8 led: led_cortina: Add CAxxx LED support

In reply to Alex Nemirovsky

From: Jway Lin <[email protected]>

Add Cortina Access LED controller support for CAxxxx SOCs

---

Changes in v6: None
Changes in v5: None
Changes in v4:
- remove unused macros
- remove cortina prefix from macros
- remove use BSS variable
- further cleanup to meet code style guidelines
- add additinal struct comments
- rename DT blink rate symbol

Changes in v3: None
Changes in v2: None

 MAINTAINERS               |   2 +
 drivers/led/Kconfig       |   8 ++
 drivers/led/Makefile      |   1 +
 drivers/led/led_cortina.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 279 insertions(+)
 create mode 100644 drivers/led/led_cortina.c
MAINTAINERS +2 -0
index 307e620..e9b6bfa 100644
@@ -183,6 +183,7 @@ F:	drivers/serial/serial_cortina.c
 F:	drivers/mmc/ca_dw_mmc.c
 F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
+F:	drivers/led/led_cortina.c
 
 ARM/CZ.NIC TURRIS MOX SUPPORT
 M:	Marek Behun <[email protected]>
@@ -724,6 +725,7 @@ F:	drivers/serial/serial_cortina.c
 F:	drivers/mmc/ca_dw_mmc.c
 F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
+F:	drivers/led/led_cortina.c
 
 MIPS MSCC
 M:	Gregory CLEMENT <[email protected]>
drivers/led/Kconfig +8 -0
index 6675934..cc87fbf 100644
@@ -35,6 +35,14 @@ config LED_BCM6858
 	  This option enables support for LEDs connected to the BCM6858
 	  HW has blinking capabilities and up to 32 LEDs can be controlled.
 
+config LED_CORTINA
+	bool "LED Support for Cortina Access CAxxxx SoCs"
+	depends on LED && (CORTINA_PLATFORM)
+	help
+	  This option enables support for LEDs connected to the Cortina
+	  Access CAxxxx SOCs.
+
+
 config LED_BLINK
 	bool "Support LED blinking"
 	depends on LED
drivers/led/Makefile +1 -0
index 3654dd3..8e3ae7f 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_LED_BCM6328) += led_bcm6328.o
 obj-$(CONFIG_LED_BCM6358) += led_bcm6358.o
 obj-$(CONFIG_LED_BCM6858) += led_bcm6858.o
 obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o
+obj-$(CONFIG_LED_CORTINA) += led_cortina.o
drivers/led/led_cortina.c new file +268 -0

268 lines not on this page · raw message

Signature · 1 line
2.7.4
#8 lore raw

PATCH v6 5/8 led: led_cortina: Add CAxxx LED support

Hi Alex,

Quoted 97 lines · Alex Nemirovsky

From: Jway Lin <[email protected]>

Add Cortina Access LED controller support for CAxxxx SOCs

---

Changes in v6: None
Changes in v5: None
Changes in v4:
- remove unused macros
- remove cortina prefix from macros
- remove use BSS variable
- further cleanup to meet code style guidelines
- add additinal struct comments
- rename DT blink rate symbol

Changes in v3: None
Changes in v2: None

 MAINTAINERS               |   2 +
 drivers/led/Kconfig       |   8 ++
 drivers/led/Makefile      |   1 +
 drivers/led/led_cortina.c | 268 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 279 insertions(+)
 create mode 100644 drivers/led/led_cortina.c
MAINTAINERS +2 -0
index 307e620..e9b6bfa 100644
@@ -183,6 +183,7 @@ F:  drivers/serial/serial_cortina.c
 F:     drivers/mmc/ca_dw_mmc.c
 F:     drivers/i2c/i2c-cortina.c
 F:     drivers/i2c/i2c-cortina.h
+F:     drivers/led/led_cortina.c
 
 ARM/CZ.NIC TURRIS MOX SUPPORT
 M:     Marek Behun <[email protected]>
@@ -724,6 +725,7 @@ F:  drivers/serial/serial_cortina.c
 F:     drivers/mmc/ca_dw_mmc.c
 F:     drivers/i2c/i2c-cortina.c
 F:     drivers/i2c/i2c-cortina.h
+F:     drivers/led/led_cortina.c
 
 MIPS MSCC
 M:     Gregory CLEMENT <[email protected]>
drivers/led/Kconfig +8 -0
index 6675934..cc87fbf 100644
@@ -35,6 +35,14 @@ config LED_BCM6858
          This option enables support for LEDs connected to the BCM6858
          HW has blinking capabilities and up to 32 LEDs can be controlled.
 
+config LED_CORTINA
+       bool "LED Support for Cortina Access CAxxxx SoCs"
+       depends on LED && (CORTINA_PLATFORM)
+       help
+         This option enables support for LEDs connected to the Cortina
+         Access CAxxxx SOCs.
+
+
 config LED_BLINK
        bool "Support LED blinking"
        depends on LED
drivers/led/Makefile +1 -0
index 3654dd3..8e3ae7f 100644
@@ -8,3 +8,4 @@ obj-$(CONFIG_LED_BCM6328) += led_bcm6328.o
 obj-$(CONFIG_LED_BCM6358) += led_bcm6358.o
 obj-$(CONFIG_LED_BCM6858) += led_bcm6858.o
 obj-$(CONFIG_$(SPL_)LED_GPIO) += led_gpio.o
+obj-$(CONFIG_LED_CORTINA) += led_cortina.o
drivers/led/led_cortina.c new file +12 -0
new file mode 100644
index 0000000..f873d30
@@ -0,0 +1,268 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+/*
+ * Copyright (C) 2020 Cortina-Access
+ * Author: Jway Lin <[email protected]>
+ *
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <errno.h>
+#include <led.h>

drivers/led/led_cortina.c line 22

Quoted 10 lines
drivers/led/led_cortina.c new file +10 -0
+#include <asm/io.h>
+#include <dm/lists.h>
+
+#define LED_MAX_HW_BLINK               127
+#define LED_MAX_COUNT                  16
+
+/* LED_CONTROL fields */
+#define LED_BLINK_RATE1_OFFSET 0
+#define LED_BLINK_RATE1_MASK   0xff
+#define LED_BLINK_RATE2_OFFSET 8

Suggestion: I would call that a SHIFT rather than an offset.

Quoted 14 lines
drivers/led/led_cortina.c new file +14 -0
+#define LED_BLINK_RATE2_MASK   0xff
+#define LED_CLK_TEST                   BIT(16)
+#define LED_CLK_POLARITY               BIT(17)
+#define LED_CLK_TEST_MODE              BIT(16)
+#define LED_CLK_TEST_RX_TEST   BIT(30)
+#define LED_CLK_TEST_TX_TEST   BIT(31)
+
+/* LED_CONFIG fields */
+#define LED_EVENT_ON_OFFSET            0
+#define LED_EVENT_ON_MASK              0x7
+#define LED_EVENT_BLINK_OFFSET 3
+#define LED_EVENT_BLINK_MASK   0x7
+#define LED_EVENT_OFF_OFFSET   6
+#define LED_EVENT_OFF_MASK             0x7

drivers/led/led_cortina.c line 46

Quoted 10 lines
drivers/led/led_cortina.c new file +10 -0
+#define LED_OFF_ON_OFFSET              9
+#define LED_OFF_ON_MASK                        0x3
+#define LED_PORT_OFFSET                        11
+#define LED_PORT_MASK                  0x7
+#define LED_OFF_VAL                            BIT(14)
+#define LED_SW_EVENT                   BIT(15)
+#define LED_BLINK_SEL                  BIT(16)
+
+/* LED_CONFIG structures */
+struct cortina_led_cfg {

struct cortina_led_priv

drivers/led/led_cortina.c line 48

Quoted 2 lines
drivers/led/led_cortina.c new file +2 -0
+       void __iomem *regs;
+       int idx;

comment?

Quoted 33 lines
drivers/led/led_cortina.c new file +33 -0
+       bool active_low;
+       int off_event;          /* set led off event */
+       int blink_event;        /* set led blink event */
+       int on_event;   /* set led on event */
+       int port;               /* corresponding ethernet port */
+       int blink;              /* blink rate sel */
+};
+
+static void cortina_led_write(void __iomem *reg, unsigned long data)
+{
+       writel(data, reg);
+}
+
+static unsigned long cortina_led_read(void __iomem *reg)
+{
+       return readl(reg);
+}
+
+static enum led_state_t cortina_led_get_state(struct udevice *dev)
+{
+       struct cortina_led_cfg *priv = dev_get_priv(dev);
+       enum led_state_t state = LEDST_OFF;
+       u32 val;
+
+       val = readl(priv->regs);
+
+       if (val & LED_SW_EVENT)
+               state = LEDST_ON;
+
+       return state;
+}
+
+static int cortina_led_set_state(struct udevice *dev, enum led_state_t state)

drivers/led/led_cortina.c line 91

Quoted 10 lines
drivers/led/led_cortina.c new file +10 -0
+{
+       u32 val;
+       struct cortina_led_cfg *priv = dev_get_priv(dev);
+
+       val = readl(priv->regs);
+
+       switch (state) {
+       case LEDST_OFF:
+               val &= ~LED_SW_EVENT;
+               val &= ~(LED_OFF_ON_MASK << LED_OFF_ON_OFFSET);

Those two lines look like they could move above the switch()

drivers/led/led_cortina.c line 92

Quoted 1 line
drivers/led/led_cortina.c new file +1 -0
+               val |= 0x3 << LED_OFF_ON_OFFSET;

Perhaps 3 (and the 1 below) should be in an enum since you are using ones for everything else?

drivers/led/led_cortina.c line 99

Quoted 7 lines
drivers/led/led_cortina.c new file +7 -0
+               cortina_led_write(priv->regs, val);
+               break;
+       case LEDST_ON:
+               val |= LED_SW_EVENT;
+               val &= ~(LED_OFF_ON_MASK << LED_OFF_ON_OFFSET);
+               val |= 0x1 << LED_OFF_ON_OFFSET;
+               cortina_led_write(priv->regs, val);

that line looks like it could be below the switch.

Quoted 13 lines
drivers/led/led_cortina.c new file +13 -0
+               break;
+       case LEDST_TOGGLE:
+               if (cortina_led_get_state(dev) == LEDST_OFF)
+                       return cortina_led_set_state(dev, LEDST_ON);
+               else
+                       return cortina_led_set_state(dev, LEDST_OFF);
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return 0;

drivers/led/led_cortina.c line 122

Quoted 10 lines
drivers/led/led_cortina.c new file +10 -0
+}
+
+static const struct led_ops cortina_led_ops = {
+       .get_state = cortina_led_get_state,
+       .set_state = cortina_led_set_state,
+};
+
+static int cortina_led_probe(struct udevice *dev)
+{
+       struct led_uc_plat *uc_plat = dev_get_uclass_platdata(dev);

Reading the DT should really happen in the ofdata_to_platdata method.

Quoted 7 lines
drivers/led/led_cortina.c new file +7 -0
+
+       /* Top-level LED node */
+       if (!uc_plat->label) {
+               void __iomem *regs;
+               u32 reg_value, val;
+               u16 rate1, rate2;
+

drivers/led/led_cortina.c line 139

Quoted 10 lines
drivers/led/led_cortina.c new file +10 -0
+               regs = dev_remap_addr(dev);
+               if (!regs)
+                       return -EINVAL;
+
+               reg_value = 0;
+               reg_value |= LED_CLK_POLARITY;
+
+               rate1 = dev_read_u32_default(dev, "cortina,blink-rate1", 256);
+               rate2 = dev_read_u32_default(dev, "cortina,blink-rate2", 512);
+

If you put these into your platdata then you can have a probe() method which just talks to the hardware, not also reading DT.

drivers/led/led_cortina.c line 152

Quoted 13 lines
drivers/led/led_cortina.c new file +13 -0
+               val = rate1 / 16 - 1;
+               rate1 = val > LED_MAX_HW_BLINK ?
+                                       LED_MAX_HW_BLINK : val;
+               reg_value |= (rate1 & LED_BLINK_RATE1_MASK) <<
+                                       LED_BLINK_RATE1_OFFSET;
+
+               val = rate2 / 16 - 1;
+               rate2 = val > LED_MAX_HW_BLINK ?
+                                       LED_MAX_HW_BLINK : val;
+               reg_value |= (rate2 & LED_BLINK_RATE2_MASK) <<
+                                       LED_BLINK_RATE2_OFFSET;
+
+               cortina_led_write(regs, reg_value);

That call belongs in probe() though.

Quoted 83 lines
drivers/led/led_cortina.c new file +83 -0
+
+       } else {
+               struct cortina_led_cfg *priv = dev_get_priv(dev);
+               void __iomem *regs;
+               u32 pin, val, blink, port, off_event, blink_event, on_event;
+
+               regs = dev_remap_addr(dev_get_parent(dev));
+               if (!regs)
+                       return -EINVAL;
+
+               pin = dev_read_u32_default(dev, "pin", LED_MAX_COUNT);
+
+               if (pin >= LED_MAX_COUNT)
+                       return -EINVAL;
+
+               priv->regs = regs + 4 + pin * 4;
+
+               val = cortina_led_read(priv->regs);
+
+               if (dev_read_bool(dev, "active-low")) {
+                       priv->active_low = true;
+                       val |= LED_OFF_VAL;
+               } else {
+                       priv->active_low = false;
+                       val &= ~LED_OFF_VAL;
+               }
+
+               blink = dev_read_u32_default(dev, "blink-sel", 0);
+
+               if (blink == 0) {
+                       priv->blink = 0;
+                       val &= ~LED_BLINK_SEL;
+               } else if (blink == 1) {
+                       priv->blink = 1;
+                       val |= LED_BLINK_SEL;
+               }
+
+               off_event = dev_read_u32_default(dev, "off-event", 3);
+               val &= ~(LED_EVENT_OFF_MASK << LED_EVENT_OFF_OFFSET);
+               if (off_event != 3) {
+                       priv->off_event = off_event;
+                       val |= BIT(off_event) << LED_EVENT_OFF_OFFSET;
+               }
+
+               blink_event = dev_read_u32_default(dev, "blink-event", 3);
+               val &= ~(LED_EVENT_BLINK_MASK << LED_EVENT_BLINK_OFFSET);
+               if (blink_event != 3) {
+                       priv->blink_event = blink_event;
+                       val |= BIT(blink_event) << LED_EVENT_BLINK_OFFSET;
+               }
+
+               on_event = dev_read_u32_default(dev, "on-event", 3);
+               val &= ~(LED_EVENT_ON_MASK << LED_EVENT_ON_OFFSET);
+               if (on_event != 3) {
+                       priv->on_event = on_event;
+                       val |= BIT(on_event) << LED_EVENT_ON_OFFSET;
+               }
+
+               port = dev_read_u32_default(dev, "port", 0);
+               priv->port = port;
+               val &= ~(LED_PORT_MASK << LED_PORT_OFFSET);
+               val |= port << LED_PORT_OFFSET;
+
+               /* force off */
+               val &= ~(LED_OFF_ON_MASK << LED_OFF_ON_OFFSET);
+               val |= 0x3 << LED_OFF_ON_OFFSET;
+
+               cortina_led_write(priv->regs, val);
+       }
+
+       return 0;
+}
+
+static int cortina_led_bind(struct udevice *parent)
+{
+       ofnode node;
+
+       dev_for_each_subnode(node, parent) {
+               struct led_uc_plat *uc_plat;
+               struct udevice *dev;
+               const char *label;
+               int ret;
+

drivers/led/led_cortina.c line 245

Quoted 10 lines
drivers/led/led_cortina.c new file +10 -0
+               label = ofnode_read_string(node, "label");
+               if (!label) {
+                       debug("%s: node %s has no label\n", __func__,
+                             ofnode_get_name(node));
+                       return -EINVAL;
+               }
+
+               ret = device_bind_driver_to_node(parent, "ca-leds",
+                                                ofnode_get_name(node),
+                                                node, &dev);

If you have your own binding, could you add a compatible string for the child nodes so that DM can bind drivers automatically?

Quoted 24 lines
drivers/led/led_cortina.c new file +23 -1
+               if (ret)
+                       return ret;
+               uc_plat = dev_get_uclass_platdata(dev);
+               uc_plat->label = label;
+       }
+
+       return 0;
+}
+
+static const struct udevice_id ca_led_ids[] = {
+       { .compatible = "cortina,ca-leds" },
+       { /* sentinel */ }
+};
+
+U_BOOT_DRIVER(cortina_led) = {
+       .name = "ca-leds",
+       .id = UCLASS_LED,
+       .of_match = ca_led_ids,
+       .bind = cortina_led_bind,
+       .probe = cortina_led_probe,
+       .priv_auto_alloc_size = sizeof(struct cortina_led_cfg),
+       .ops = &cortina_led_ops,
+};
--
Quoted 2 lines

2.7.4

Regards,
Simon

#9 lore raw

PATCH v6 6/8 board: presidio: add LED support

In reply to Alex Nemirovsky

From: Jway Lin <[email protected]>

Add LED support for Cortina Access Presidio Engineering Board

CC Simon Glass <[email protected]>

---

Changes in v6: None
Changes in v5: None
Changes in v4:
- rename DT blink rate symbol

Changes in v3: None
Changes in v2: None

 arch/arm/dts/ca-presidio-engboard.dts        | 31 ++++++++++++++++++++++++++++
 configs/cortina_presidio-asic-emmc_defconfig |  2 ++
 2 files changed, 33 insertions(+)
arch/arm/dts/ca-presidio-engboard.dts +31 -0
index 40c93d7..eef433e 100644
@@ -64,4 +64,35 @@
 			spi-max-frequency = <108000000>;
 		};
 	};
+
+	leds: led-controller at f43200f0 {
+		compatible = "cortina,ca-leds";
+		reg = <0x0 0xf43200f0 0x40>;
+
+		cortina,blink-rate1 = <256>;
+		cortina,blink-rate2 = <512>;
+
+		led at 0 {
+			pin = <0>;
+			active-low;
+			blink-sel =<0>;
+			port = <0>;
+			off-event = <0>;
+			label = "led0";
+		};
+
+		led at 1 {
+			pin = <1>;
+			active-low;
+			blink-sel =<1>;
+			label = "led1";
+		};
+
+		led at 2 {
+			pin = <2>;
+			active-low;
+			label = "led2";
+		};
+
+	};
 };
configs/cortina_presidio-asic-emmc_defconfig +2 -0
index e45e23c..3c6bd6b 100644
@@ -27,6 +27,8 @@ CONFIG_DM=y
 CONFIG_CORTINA_GPIO=y
 CONFIG_DM_I2C=y
 CONFIG_SYS_I2C_CA=y
+CONFIG_LED=y
+CONFIG_LED_CORTINA=y
 CONFIG_DM_MMC=y
 CONFIG_MMC_DW=y
 CONFIG_MMC_DW_CORTINA=y
Signature · 1 line
2.7.4
#10 lore raw

PATCH v6 6/8 board: presidio: add LED support

Hi Alex,

Quoted 18 lines · Alex Nemirovsky

From: Jway Lin <[email protected]>

Add LED support for Cortina Access Presidio Engineering Board

CC Simon Glass <[email protected]>

---

Changes in v6: None
Changes in v5: None
Changes in v4:
- rename DT blink rate symbol

Quoted 7 lines

Changes in v3: None
Changes in v2: None

 arch/arm/dts/ca-presidio-engboard.dts        | 31 ++++++++++++++++++++++++++++
 configs/cortina_presidio-asic-emmc_defconfig |  2 ++
 2 files changed, 33 insertions(+)

Do you have a new binding file for this from Linux? It seems to use properties which I don't see in the existing binding in U-Boot.

Quoted 30 lines
arch/arm/dts/ca-presidio-engboard.dts +22 -0
index 40c93d7..eef433e 100644
@@ -64,4 +64,35 @@
                        spi-max-frequency = <108000000>;
                };
        };
+
+       leds: led-controller at f43200f0 {
+               compatible = "cortina,ca-leds";
+               reg = <0x0 0xf43200f0 0x40>;
+
+               cortina,blink-rate1 = <256>;
+               cortina,blink-rate2 = <512>;
+
+               led at 0 {
+                       pin = <0>;
+                       active-low;
+                       blink-sel =<0>;
+                       port = <0>;
+                       off-event = <0>;
+                       label = "led0";
+               };
+
+               led at 1 {
+                       pin = <1>;
+                       active-low;
+                       blink-sel =<1>;
+                       label = "led1";

arch/arm/dts/ca-presidio-engboard.dts line 98

Quoted 10 lines
arch/arm/dts/ca-presidio-engboard.dts +9 -0
+               };
+
+               led at 2 {
+                       pin = <2>;
+                       active-low;
+                       label = "led2";
+               };
+
+       };
 };

Regards,
Simon

#11 lore raw

PATCH v6 7/8 spi: ca_sflash: Add CAxxxx SPI Flash Controller

In reply to Alex Nemirovsky

From: Pengpeng Chen <[email protected]>

Add SPI Flash controller driver for Cortina Access CAxxxx SoCs

---

Changes in v6: None
Changes in v5: None
Changes in v4: None
Changes in v3:
- Fixup syntax issues related to checkpatch.pl cleanup

Changes in v2: None

 MAINTAINERS             |   2 +
 drivers/spi/Kconfig     |   8 +
 drivers/spi/Makefile    |   1 +
 drivers/spi/ca_sflash.c | 576 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 587 insertions(+)
 create mode 100644 drivers/spi/ca_sflash.c
MAINTAINERS +2 -0
index e9b6bfa..5047748 100644
@@ -184,6 +184,7 @@ F:	drivers/mmc/ca_dw_mmc.c
 F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
 F:	drivers/led/led_cortina.c
+F:	drivers/spi/ca_sflash.c
 
 ARM/CZ.NIC TURRIS MOX SUPPORT
 M:	Marek Behun <[email protected]>
@@ -726,6 +727,7 @@ F:	drivers/mmc/ca_dw_mmc.c
 F:	drivers/i2c/i2c-cortina.c
 F:	drivers/i2c/i2c-cortina.h
 F:	drivers/led/led_cortina.c
+F:	drivers/spi/ca_sflash.c
 
 MIPS MSCC
 M:	Gregory CLEMENT <[email protected]>
drivers/spi/Kconfig +8 -0
index 4166c61..8a244f1 100644
@@ -106,6 +106,14 @@ config BCMSTB_SPI
 	  be used to access the SPI flash on platforms embedding this
 	  Broadcom SPI core.
 
+config CORTINA_SFLASH
+	bool "Cortina-Access Serial Flash controller driver"
+	depends on DM_SPI && SPI_MEM
+	help
+	  Enable the Cortina-Access Serial Flash controller driver. This driver
+	  can be used to access the SPI NOR/NAND flash on platforms embedding this
+	  Cortina-Access IP core.
+
 config CADENCE_QSPI
 	bool "Cadence QSPI driver"
 	help
drivers/spi/Makefile +1 -0
index 52462e1..32b98b4 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_BCM63XX_SPI) += bcm63xx_spi.o
 obj-$(CONFIG_BCMSTB_SPI) += bcmstb_spi.o
 obj-$(CONFIG_CADENCE_QSPI) += cadence_qspi.o cadence_qspi_apb.o
 obj-$(CONFIG_CF_SPI) += cf_spi.o
+obj-$(CONFIG_CORTINA_SFLASH) += ca_sflash.o
 obj-$(CONFIG_DAVINCI_SPI) += davinci_spi.o
 obj-$(CONFIG_DESIGNWARE_SPI) += designware_spi.o
 obj-$(CONFIG_EXYNOS_SPI) += exynos_spi.o
drivers/spi/ca_sflash.c new file +576 -0

576 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

PATCH v6 8/8 board: presidio-asic: Add SPI NOR support

In reply to Alex Nemirovsky

Add SPI NOR support for Cortina Access
Presidio Engineering Board

---

Changes in v6: None
Changes in v5:
- NAND support removed from presidio-asic board DT.

Changes in v4: None
Changes in v3: None
Changes in v2: None

 arch/arm/dts/ca-presidio-engboard.dts            |  6 +--
 board/cortina/presidio-asic/presidio.c           | 16 ++++++-
 configs/cortina_presidio-asic-spi-nand_defconfig | 48 +++++++++++++++++++
 configs/cortina_presidio-asic-spi-nor_defconfig  | 59 ++++++++++++++++++++++++
 4 files changed, 124 insertions(+), 5 deletions(-)
 create mode 100644 configs/cortina_presidio-asic-spi-nand_defconfig
 create mode 100644 configs/cortina_presidio-asic-spi-nor_defconfig
arch/arm/dts/ca-presidio-engboard.dts +2 -4
index eef433e..cc7c888 100644
@@ -53,15 +53,13 @@
 	};
 
 	sflash: sflash-controller at f4324000 {
-		#address-cells = <2>;
-		#size-cells = <1>;
 		compatible = "cortina,ca-sflash";
 		reg = <0x0 0xf4324000 0x50>;
 		reg-names = "sflash-regs";
 		flash at 0 {
 			compatible = "jedec,spi-nor";
-			spi-rx-bus-width = <1>;
-			spi-max-frequency = <108000000>;
+			spi-rx-bus-width = <4>;
+			spi-tx-bus-width = <4>;
 		};
 	};
 
board/cortina/presidio-asic/presidio.c +15 -1
index b4fa01f..d547b60 100644
@@ -14,7 +14,7 @@
 #include <asm/psci.h>
 #include <cpu_func.h>
 #include <asm/armv8/mmu.h>
-
+#include <dm/uclass.h>
 DECLARE_GLOBAL_DATA_PTR;
 
 #define CA_PERIPH_BASE                  0xE0000000UL
@@ -70,9 +70,23 @@ static noinline int invoke_psci_fn_smc(u64 function_id, u64 arg0, u64 arg1,
 	return function_id;
 }
 
+#ifdef CONFIG_CORTINA_SFLASH
+static int init_sflash(void)
+{
+	struct udevice *dev;
+
+	uclass_first_device(UCLASS_SPI, &dev);
+
+	return 0;
+}
+#endif
+
 int board_early_init_r(void)
 {
 	dcache_disable();
+#ifdef CONFIG_CORTINA_SFLASH
+	init_sflash();
+#endif
 	return 0;
 }
 
configs/cortina_presidio-asic-spi-nand_defconfig new file +48 -0

48 lines not on this page · raw message

configs/cortina_presidio-asic-spi-nor_defconfig new file +59 -0

59 lines not on this page · raw message

Signature · 1 line
2.7.4