Skip to contentSkip to conversation

rockchip: rk3328: Add SPI support

PATCH New Johannes Krottmayer 2 participants 8 messages Jul 8, 2020 – Jul 18, 2020

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

cover rockchip: rk3328: Add SPI support

This patch series adds support for the RK3328 SPI
controller.

Johannes Krottmayer (3):
drivers: clk: rockchip: clk_rk3328: Add SPI support
drivers: spi: rk_spi: Add support for RK3328
ARM: dts: rk3328: Add SPI support

 arch/arm/dts/rk3328-u-boot.dtsi   |  5 +++++
 drivers/clk/rockchip/clk_rk3328.c | 31 +++++++++++++++++++++++++++++++
 drivers/spi/rk_spi.c              |  2 ++
 3 files changed, 38 insertions(+)
Signature · 1 line
2.26.2
#1 lore raw

PATCH 1/3 drivers: clk: rockchip: clk_rk3328: Add SPI support

Add SPI support for the RK3328 clock driver

---
 drivers/clk/rockchip/clk_rk3328.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/clk/rockchip/clk_rk3328.c +31 -0
index 02d3b08efa..bf4f1069ea 100644
@@ -555,6 +555,31 @@ static ulong rk3328_saradc_set_clk(struct rk3328_cru *cru, uint hz)
 	return rk3328_saradc_get_clk(cru);
 }
 
+static ulong rk3328_spi_get_clk(struct rk3328_cru *cru)
+{
+	u32 div, val;
+
+	val = readl(&cru->clksel_con[24]);
+	div = (val & CLK_SPI_DIV_CON_MASK) >> CLK_SPI_DIV_CON_SHIFT;
+
+	return DIV_TO_RATE(OSC_HZ, div);
+}
+
+static ulong rk3328_spi_set_clk(struct rk3328_cru *cru, uint hz)
+{
+	u32 src_clk_div;
+
+	src_clk_div = GPLL_HZ / hz;
+	assert(src_clk_div < 128);
+
+	rk_clrsetreg(&cru->clksel_con[24],
+		     CLK_PWM_PLL_SEL_MASK | CLK_PWM_DIV_CON_MASK,
+		     CLK_PWM_PLL_SEL_GPLL << CLK_PWM_PLL_SEL_SHIFT |
+		     (src_clk_div - 1) << CLK_PWM_DIV_CON_SHIFT);
+
+	return rk3328_spi_get_clk(cru);
+}
+
 static ulong rk3328_clk_get_rate(struct clk *clk)
 {
 	struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
@@ -581,6 +606,9 @@ static ulong rk3328_clk_get_rate(struct clk *clk)
 	case SCLK_SARADC:
 		rate = rk3328_saradc_get_clk(priv->cru);
 		break;
+	case SCLK_SPI:
+		rate = rk3328_spi_get_clk(priv->cru);
+		break;
 	default:
 		return -ENOENT;
 	}
@@ -617,6 +645,9 @@ static ulong rk3328_clk_set_rate(struct clk *clk, ulong rate)
 	case SCLK_SARADC:
 		ret = rk3328_saradc_set_clk(priv->cru, rate);
 		break;
+	case SCLK_SPI:
+		ret = rk3328_spi_set_clk(priv->cru, rate);
+		break;
 	case DCLK_LCDC:
 	case SCLK_PDM:
 	case SCLK_RTC32K:
Signature · 1 line
2.26.2
#3 lore raw

PATCH 2/3 drivers: spi: rk_spi: Add support for RK3328

In reply to Johannes Krottmayer

Add support for the RK3328 SPI controller

---
I don't know if "rk3399_spi_params" is also required for the RK3328 SPI controller.

Probing, Reading, Writing and Erasing of a flash device works with the SF command. Tested it with the PINE64 Rock64 board.

 drivers/spi/rk_spi.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/spi/rk_spi.c +2 -0
index 833cb04922..0495e04945 100644
@@ -545,7 +545,9 @@ const  struct rockchip_spi_params rk3399_spi_params = {
 };
 
 static const struct udevice_id rockchip_spi_ids[] = {
+	{ .compatible = "rockchip,rk3066-spi" },
 	{ .compatible = "rockchip,rk3288-spi" },
+	{ .compatible = "rockchip,rk3328-spi" },
 	{ .compatible = "rockchip,rk3368-spi",
 	  .data = (ulong)&rk3399_spi_params },
 	{ .compatible = "rockchip,rk3399-spi",
Signature · 1 line
2.26.2
#5 lore raw

PATCH 3/3 ARM: dts: rk3328: Add SPI support

In reply to Johannes Krottmayer

Add U-Boot SPI support for the RK3328

---
 arch/arm/dts/rk3328-u-boot.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm/dts/rk3328-u-boot.dtsi +5 -0
index c69e13e11e..c980daae99 100644
@@ -7,6 +7,7 @@
 	aliases {
 		mmc0 = &emmc;
 		mmc1 = &sdmmc;
+ 		spi0 = &spi0;
 	};
 
 	chosen {
@@ -66,3 +67,7 @@
 &usb20_otg {
 	hnp-srp-disable;
 };
+
+&spi0 {
+	u-boot,dm-pre-reloc;
+};
Signature · 1 line
2.26.2
#2 lore raw

PATCH 1/3 drivers: clk: rockchip: clk_rk3328: Add SPI support

In reply to Johannes Krottmayer
Quoted 5 lines · Johannes Krottmayer

Add SPI support for the RK3328 clock driver

Thanks,
- Kever

Quoted 60 lines
---
  drivers/clk/rockchip/clk_rk3328.c | 31 +++++++++++++++++++++++++++++++
  1 file changed, 31 insertions(+)
drivers/clk/rockchip/clk_rk3328.c +31 -0
index 02d3b08efa..bf4f1069ea 100644
@@ -555,6 +555,31 @@ static ulong rk3328_saradc_set_clk(struct rk3328_cru *cru, uint hz)
  	return rk3328_saradc_get_clk(cru);
  }
 
+static ulong rk3328_spi_get_clk(struct rk3328_cru *cru)
+{
+	u32 div, val;
+
+	val = readl(&cru->clksel_con[24]);
+	div = (val & CLK_SPI_DIV_CON_MASK) >> CLK_SPI_DIV_CON_SHIFT;
+
+	return DIV_TO_RATE(OSC_HZ, div);
+}
+
+static ulong rk3328_spi_set_clk(struct rk3328_cru *cru, uint hz)
+{
+	u32 src_clk_div;
+
+	src_clk_div = GPLL_HZ / hz;
+	assert(src_clk_div < 128);
+
+	rk_clrsetreg(&cru->clksel_con[24],
+		     CLK_PWM_PLL_SEL_MASK | CLK_PWM_DIV_CON_MASK,
+		     CLK_PWM_PLL_SEL_GPLL << CLK_PWM_PLL_SEL_SHIFT |
+		     (src_clk_div - 1) << CLK_PWM_DIV_CON_SHIFT);
+
+	return rk3328_spi_get_clk(cru);
+}
+
  static ulong rk3328_clk_get_rate(struct clk *clk)
  {
  	struct rk3328_clk_priv *priv = dev_get_priv(clk->dev);
@@ -581,6 +606,9 @@ static ulong rk3328_clk_get_rate(struct clk *clk)
  	case SCLK_SARADC:
  		rate = rk3328_saradc_get_clk(priv->cru);
  		break;
+	case SCLK_SPI:
+		rate = rk3328_spi_get_clk(priv->cru);
+		break;
  	default:
  		return -ENOENT;
  	}
@@ -617,6 +645,9 @@ static ulong rk3328_clk_set_rate(struct clk *clk, ulong rate)
  	case SCLK_SARADC:
  		ret = rk3328_saradc_set_clk(priv->cru, rate);
  		break;
+	case SCLK_SPI:
+		ret = rk3328_spi_set_clk(priv->cru, rate);
+		break;
  	case DCLK_LCDC:
  	case SCLK_PDM:
  	case SCLK_RTC32K:
#4 lore raw

PATCH 2/3 drivers: spi: rk_spi: Add support for RK3328

In reply to Johannes Krottmayer
Quoted 5 lines · Johannes Krottmayer

Add support for the RK3328 SPI controller

Thanks,
- Kever

Quoted 24 lines

---
I don't know if "rk3399_spi_params" is also required for the RK3328 SPI controller.

Probing, Reading, Writing and Erasing of a flash device works with the SF command. Tested it with the PINE64 Rock64 board.

  drivers/spi/rk_spi.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/spi/rk_spi.c +2 -0
index 833cb04922..0495e04945 100644
@@ -545,7 +545,9 @@ const  struct rockchip_spi_params rk3399_spi_params = {
  };
 
  static const struct udevice_id rockchip_spi_ids[] = {
+	{ .compatible = "rockchip,rk3066-spi" },
  	{ .compatible = "rockchip,rk3288-spi" },
+	{ .compatible = "rockchip,rk3328-spi" },
  	{ .compatible = "rockchip,rk3368-spi",
  	  .data = (ulong)&rk3399_spi_params },
  	{ .compatible = "rockchip,rk3399-spi",
#6 lore raw

PATCH 3/3 ARM: dts: rk3328: Add SPI support

In reply to Johannes Krottmayer
Quoted 5 lines · Johannes Krottmayer

Add U-Boot SPI support for the RK3328

Thanks,
- Kever

Quoted 24 lines
---
  arch/arm/dts/rk3328-u-boot.dtsi | 5 +++++
  1 file changed, 5 insertions(+)
arch/arm/dts/rk3328-u-boot.dtsi +5 -0
index c69e13e11e..c980daae99 100644
@@ -7,6 +7,7 @@
  	aliases {
  		mmc0 = &emmc;
  		mmc1 = &sdmmc;
+ 		spi0 = &spi0;
  	};
 
  	chosen {
@@ -66,3 +67,7 @@
  &usb20_otg {
  	hnp-srp-disable;
  };
+
+&spi0 {
+	u-boot,dm-pre-reloc;
+};
#7 lore raw

cover rockchip: rk3328: Add SPI support

In reply to Johannes Krottmayer
Quoted 8 lines · Johannes Krottmayer

This patch series adds support for the RK3328 SPI
controller.

Johannes Krottmayer (3):
drivers: clk: rockchip: clk_rk3328: Add SPI support
drivers: spi: rk_spi: Add support for RK3328
ARM: dts: rk3328: Add SPI support

Quoted 5 lines
  arch/arm/dts/rk3328-u-boot.dtsi   |  5 +++++
  drivers/clk/rockchip/clk_rk3328.c | 31 +++++++++++++++++++++++++++++++
  drivers/spi/rk_spi.c              |  2 ++
  3 files changed, 38 insertions(+)

Applied to u-boot-rockchip master for this patch set, thanks.