Skip to contentSkip to conversation

rockchip: Add SPI driver

PATCH New Simon Glass 1 participant 2 messages Sep 2, 2015 – Sep 3, 2015

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

PATCH v6 29/41 rockchip: Add SPI driver

Add a SPI driver for the Rockchip RK3288, using driver model. It should work for other Rockchip SoCs also.

---

Changes in v6:
- Add clk_get_divisor() instead of open-coding the maths
- Add constants for the timeout and maximum clock speed
- Put rkspi_dump_regs() behind a #define option

Changes in v5:
- Drop unnecessary 'depends on DM_SPI' in Kconfig
- Tidy up rkspi_dump_regs() debug output
- Tidy up the delay in rkspi_wait_till_not_busy()

Changes in v4:
- Rename pinctrl.h to dm/pinctrl.h

Changes in v3: None
Changes in v2: None

 arch/arm/include/asm/arch-rockchip/clock.h |  20 ++
 drivers/spi/Kconfig                        |   8 +
 drivers/spi/Makefile                       |   1 +
 drivers/spi/rk_spi.c                       | 374 +++++++++++++++++++++++++++++
 drivers/spi/rk_spi.h                       | 124 ++++++++++
 5 files changed, 527 insertions(+)
 create mode 100644 drivers/spi/rk_spi.c
 create mode 100644 drivers/spi/rk_spi.h
arch/arm/include/asm/arch-rockchip/clock.h +20 -0
index 2e5ba86..8a0376c 100644
@@ -36,6 +36,26 @@ static inline int rk_pll_id(enum rk_clk_id clk_id)
 }
 
 /**
+ * clk_get_divisor() - Calculate the required clock divisior
+ *
+ * Given an input rate and a required output_rate, calculate the Rockchip
+ * divisor needed to achieve this.
+ *
+ * @input_rate:		Input clock rate in Hz
+ * @output_rate:	Output clock rate in Hz
+ * @return divisor register value to use
+ */
+static inline u32 clk_get_divisor(ulong input_rate, uint output_rate)
+{
+	uint clk_div;
+
+	clk_div = input_rate / output_rate;
+	clk_div = (clk_div + 1) & 0xfffe;
+
+	return clk_div;
+}
+
+/**
  * rockchip_get_cru() - get a pointer to the clock/reset unit registers
  *
  * @return pointer to registers, or -ve error on error
drivers/spi/Kconfig +8 -0
index c84a7b7..8e04fce 100644
@@ -58,6 +58,14 @@ config ICH_SPI
 	  access the SPI NOR flash on platforms embedding this Intel
 	  ICH IP core.
 
+config ROCKCHIP_SPI
+	bool "Rockchip SPI driver"
+	help
+	  Enable the Rockchip SPI driver, used to access SPI NOR flash and
+	  other SPI peripherals (such as the Chrome OS EC) on Rockchip SoCs.
+	  This uses driver model and requires a device tree binding to
+	  operate.
+
 config SANDBOX_SPI
 	bool "Sandbox SPI driver"
 	depends on SANDBOX && DM
drivers/spi/Makefile +1 -0
index ee88aa1..de241be 100644
@@ -39,6 +39,7 @@ obj-$(CONFIG_MPC8XXX_SPI) += mpc8xxx_spi.o
 obj-$(CONFIG_MXC_SPI) += mxc_spi.o
 obj-$(CONFIG_MXS_SPI) += mxs_spi.o
 obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
+obj-$(CONFIG_ROCKCHIP_SPI) += rk_spi.o
 obj-$(CONFIG_SANDBOX_SPI) += sandbox_spi.o
 obj-$(CONFIG_SH_SPI) += sh_spi.o
 obj-$(CONFIG_SH_QSPI) += sh_qspi.o
drivers/spi/rk_spi.c new file +374 -0

374 lines not on this page · raw message

drivers/spi/rk_spi.h new file +124 -0

124 lines not on this page · raw message

Signature · 1 line
2.5.0.457.gab17608
#1 lore raw

PATCH v6 29/41 rockchip: Add SPI driver

Applied to u-boot-rockchip.