Re: [U-Boot] [PATCH v2 1/6] mips: mscc_sgpio: Add the MSCC serial GPIO device (SIO)

2018-12-29 Thread Daniel Schwierzeck
Am Do., 27. Dez. 2018 um 12:51 Uhr schrieb Lars Povlsen
:
>
> This add support for the the MSCC serial GPIO driver in MSCC
> VCoreIII-based SOCs.
>
> By using a serial interface, the SIO controller significantly extends
> the number of available GPIOs with a minimum number of additional pins
> on the device. The primary purpose of the SIO controller is to connect
> control signals from SFP modules and to act as an LED controller.
>
> This adds the base driver.
>
> Signed-off-by: Lars Povlsen 
> ---
>  MAINTAINERS   |   1 +
>  drivers/gpio/Kconfig  |  11 ++
>  drivers/gpio/Makefile |   1 +
>  drivers/gpio/mscc_sgpio.c | 274 ++
>  4 files changed, 287 insertions(+)
>  create mode 100644 drivers/gpio/mscc_sgpio.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index ae825014bd..494962e9b3 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -523,6 +523,7 @@ F:  arch/mips/dts/mscc*
>  F: arch/mips/dts/ocelot*
>  F: board/mscc/
>  F: configs/mscc*
> +F: drivers/gpio/mscc_sgpio.c
>  F: include/configs/vcoreiii.h
>
>  MIPS JZ4780
> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index c8c6c60623..aa55ff43c4 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -106,6 +106,17 @@ config MSCC_BITBANG_SPI_GPIO
>   Support controlling the GPIO used for SPI bitbang by software. Can
>   be used by the VCoreIII SoCs, but it was mainly useful for Luton.
>
> +config MSCC_SGPIO
> +   bool "Microsemi Serial GPIO driver"
> +   depends on DM_GPIO && SOC_VCOREIII
> +   help
> + Support for the VCoreIII SoC serial GPIO device. By using a
> +  serial interface, the SIO controller significantly extends
> +  the number of available GPIOs with a minimum number of
> +  additional pins on the device. The primary purpose of the
> +  SIO controller is to connect control signals from SFP
> +  modules and to act as an LED controller.
> +
>  config MSM_GPIO
> bool "Qualcomm GPIO driver"
> depends on DM_GPIO
> diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
> index 61feda1537..be2b3c792f 100644
> --- a/drivers/gpio/Makefile
> +++ b/drivers/gpio/Makefile
> @@ -60,3 +60,4 @@ obj-$(CONFIG_$(SPL_)PCF8575_GPIO) += pcf8575_gpio.o
>  obj-$(CONFIG_PM8916_GPIO)  += pm8916_gpio.o
>  obj-$(CONFIG_MT7621_GPIO)  += mt7621_gpio.o
>  obj-$(CONFIG_MSCC_BITBANG_SPI_GPIO)+= gpio-mscc-bitbang-spi.o
> +obj-$(CONFIG_MSCC_SGPIO)   += mscc_sgpio.o
> diff --git a/drivers/gpio/mscc_sgpio.c b/drivers/gpio/mscc_sgpio.c
> new file mode 100644
> index 00..134d36066c
> --- /dev/null
> +++ b/drivers/gpio/mscc_sgpio.c
> @@ -0,0 +1,274 @@
> +// SPDX-License-Identifier: (GPL-2.0 OR MIT)
> +/*
> + * Microsemi SoCs serial gpio driver
> + *
> + * Author: 
> + *
> + * Copyright (c) 2018 Microsemi Corporation
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define MSCC_SGPIOS_PER_BANK   32
> +#define MSCC_SGPIO_BANK_DEPTH  4
> +
> +enum {
> +   REG_INPUT_DATA,
> +   REG_PORT_CONFIG,
> +   REG_PORT_ENABLE,
> +   REG_SIO_CONFIG,
> +   REG_SIO_CLOCK,
> +   MAXREG
> +};
> +
> +struct mscc_sgpio_bf {
> +   u8 beg;
> +   u8 end;
> +};
> +
> +struct mscc_sgpio_props {
> +   u8 regoff[MAXREG];
> +   struct mscc_sgpio_bf auto_repeat;
> +   struct mscc_sgpio_bf port_width;
> +   struct mscc_sgpio_bf clk_freq;
> +   struct mscc_sgpio_bf bit_source;
> +};
> +
> +#define __M(bf)GENMASK((bf).end, (bf).beg)
> +#define __F(bf, x) (__M(bf) & ((x) << (bf).beg))
> +#define __X(bf, x) (((x) >> (bf).beg) & GENMASK(((bf).end - (bf).beg), 
> 0))
> +
> +#define MSCC_M_CFG_SIO_AUTO_REPEAT(p)  BIT(p->props->auto_repeat.beg)
> +#define MSCC_F_CFG_SIO_PORT_WIDTH(p, x)
> __F(p->props->port_width, x)
> +#define MSCC_M_CFG_SIO_PORT_WIDTH(p)   __M(p->props->port_width)
> +#define MSCC_F_CLOCK_SIO_CLK_FREQ(p, x)
> __F(p->props->clk_freq, x)
> +#define MSCC_M_CLOCK_SIO_CLK_FREQ(p)   __M(p->props->clk_freq)
> +#define MSCC_F_PORT_CFG_BIT_SOURCE(p, x)   __F(p->props->bit_source, x)
> +#define MSCC_X_PORT_CFG_BIT_SOURCE(p, x)   __X(p->props->bit_source, x)
> +
> +const struct mscc_sgpio_props props_luton = {
> +   .regoff = { 0x00, 0x09, 0x29, 0x2a, 0x2b },
> +   .auto_repeat = { 5, 5 },
> +   .port_width  = { 2, 3 },
> +   .clk_freq= { 0, 11 },
> +   .bit_source  = { 0, 11 },
> +};
> +
> +const struct mscc_sgpio_props props_ocelot = {
> +   .regoff = { 0x00, 0x06, 0x26, 0x04, 0x05 },
> +   .auto_repeat = { 10, 10 },
> +   .port_width  = {  7, 8  },
> +   .clk_freq= {  8, 19 },
> +   .bit_source  = { 12, 23 },
> +};
> +
> +struct mscc_sgpio_priv {
> +   u32 bitcount;
> +   u32 ports;
> +   u32 clock;
> +   u32 mode[MSCC_SGPIOS_PER_BANK];
> + 

[U-Boot] [PATCH v2 1/6] mips: mscc_sgpio: Add the MSCC serial GPIO device (SIO)

2018-12-27 Thread Lars Povlsen
This add support for the the MSCC serial GPIO driver in MSCC
VCoreIII-based SOCs.

By using a serial interface, the SIO controller significantly extends
the number of available GPIOs with a minimum number of additional pins
on the device. The primary purpose of the SIO controller is to connect
control signals from SFP modules and to act as an LED controller.

This adds the base driver.

Signed-off-by: Lars Povlsen 
---
 MAINTAINERS   |   1 +
 drivers/gpio/Kconfig  |  11 ++
 drivers/gpio/Makefile |   1 +
 drivers/gpio/mscc_sgpio.c | 274 ++
 4 files changed, 287 insertions(+)
 create mode 100644 drivers/gpio/mscc_sgpio.c

diff --git a/MAINTAINERS b/MAINTAINERS
index ae825014bd..494962e9b3 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -523,6 +523,7 @@ F:  arch/mips/dts/mscc*
 F: arch/mips/dts/ocelot*
 F: board/mscc/
 F: configs/mscc*
+F: drivers/gpio/mscc_sgpio.c
 F: include/configs/vcoreiii.h
 
 MIPS JZ4780
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index c8c6c60623..aa55ff43c4 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -106,6 +106,17 @@ config MSCC_BITBANG_SPI_GPIO
  Support controlling the GPIO used for SPI bitbang by software. Can
  be used by the VCoreIII SoCs, but it was mainly useful for Luton.
 
+config MSCC_SGPIO
+   bool "Microsemi Serial GPIO driver"
+   depends on DM_GPIO && SOC_VCOREIII
+   help
+ Support for the VCoreIII SoC serial GPIO device. By using a
+  serial interface, the SIO controller significantly extends
+  the number of available GPIOs with a minimum number of
+  additional pins on the device. The primary purpose of the
+  SIO controller is to connect control signals from SFP
+  modules and to act as an LED controller.
+
 config MSM_GPIO
bool "Qualcomm GPIO driver"
depends on DM_GPIO
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 61feda1537..be2b3c792f 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -60,3 +60,4 @@ obj-$(CONFIG_$(SPL_)PCF8575_GPIO) += pcf8575_gpio.o
 obj-$(CONFIG_PM8916_GPIO)  += pm8916_gpio.o
 obj-$(CONFIG_MT7621_GPIO)  += mt7621_gpio.o
 obj-$(CONFIG_MSCC_BITBANG_SPI_GPIO)+= gpio-mscc-bitbang-spi.o
+obj-$(CONFIG_MSCC_SGPIO)   += mscc_sgpio.o
diff --git a/drivers/gpio/mscc_sgpio.c b/drivers/gpio/mscc_sgpio.c
new file mode 100644
index 00..134d36066c
--- /dev/null
+++ b/drivers/gpio/mscc_sgpio.c
@@ -0,0 +1,274 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/*
+ * Microsemi SoCs serial gpio driver
+ *
+ * Author: 
+ *
+ * Copyright (c) 2018 Microsemi Corporation
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define MSCC_SGPIOS_PER_BANK   32
+#define MSCC_SGPIO_BANK_DEPTH  4
+
+enum {
+   REG_INPUT_DATA,
+   REG_PORT_CONFIG,
+   REG_PORT_ENABLE,
+   REG_SIO_CONFIG,
+   REG_SIO_CLOCK,
+   MAXREG
+};
+
+struct mscc_sgpio_bf {
+   u8 beg;
+   u8 end;
+};
+
+struct mscc_sgpio_props {
+   u8 regoff[MAXREG];
+   struct mscc_sgpio_bf auto_repeat;
+   struct mscc_sgpio_bf port_width;
+   struct mscc_sgpio_bf clk_freq;
+   struct mscc_sgpio_bf bit_source;
+};
+
+#define __M(bf)GENMASK((bf).end, (bf).beg)
+#define __F(bf, x) (__M(bf) & ((x) << (bf).beg))
+#define __X(bf, x) (((x) >> (bf).beg) & GENMASK(((bf).end - (bf).beg), 0))
+
+#define MSCC_M_CFG_SIO_AUTO_REPEAT(p)  BIT(p->props->auto_repeat.beg)
+#define MSCC_F_CFG_SIO_PORT_WIDTH(p, x)
__F(p->props->port_width, x)
+#define MSCC_M_CFG_SIO_PORT_WIDTH(p)   __M(p->props->port_width)
+#define MSCC_F_CLOCK_SIO_CLK_FREQ(p, x)__F(p->props->clk_freq, 
x)
+#define MSCC_M_CLOCK_SIO_CLK_FREQ(p)   __M(p->props->clk_freq)
+#define MSCC_F_PORT_CFG_BIT_SOURCE(p, x)   __F(p->props->bit_source, x)
+#define MSCC_X_PORT_CFG_BIT_SOURCE(p, x)   __X(p->props->bit_source, x)
+
+const struct mscc_sgpio_props props_luton = {
+   .regoff = { 0x00, 0x09, 0x29, 0x2a, 0x2b },
+   .auto_repeat = { 5, 5 },
+   .port_width  = { 2, 3 },
+   .clk_freq= { 0, 11 },
+   .bit_source  = { 0, 11 },
+};
+
+const struct mscc_sgpio_props props_ocelot = {
+   .regoff = { 0x00, 0x06, 0x26, 0x04, 0x05 },
+   .auto_repeat = { 10, 10 },
+   .port_width  = {  7, 8  },
+   .clk_freq= {  8, 19 },
+   .bit_source  = { 12, 23 },
+};
+
+struct mscc_sgpio_priv {
+   u32 bitcount;
+   u32 ports;
+   u32 clock;
+   u32 mode[MSCC_SGPIOS_PER_BANK];
+   u32 __iomem *regs;
+   const struct mscc_sgpio_props *props;
+};
+
+static inline u32 sgpio_readl(struct mscc_sgpio_priv *priv, u32 rno, u32 off)
+{
+   u32 __iomem *reg = >regs[priv->props->regoff[rno] + off];
+
+   return readl(reg);
+}
+
+static inline void sgpio_writel(struct mscc_sgpio_priv *priv,
+