Skip to contentSkip to conversation

Add RTC driver for STM32MP1

PATCH New Benjamin Gaignard 2 participants 5 messages Jul 11, 2019 – Jul 22, 2019

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

v3 cover Add RTC driver for STM32MP1

This series add support of RTC driver for stm32mp1 SoC. First it adds the missing clocks for RTC hadrware block and after the driver itself (enabled for basic and trusted configurations).

version 3:
- release clock only on error cases.

Benjamin Gaignard (1):
rtc: Add rtc driver for stm32mp1

Patrick Delaunay (1):
clk: stm32mp1: Add RTC clock entry

 configs/stm32mp15_basic_defconfig   |   2 +
 configs/stm32mp15_trusted_defconfig |   2 +
 drivers/clk/clk_stm32mp1.c          |   9 +
 drivers/rtc/Kconfig                 |   6 +
 drivers/rtc/Makefile                |   1 +
 drivers/rtc/stm32_rtc.c             | 323 ++++++++++++++++++++++++++++++++++++
 6 files changed, 343 insertions(+)
 create mode 100644 drivers/rtc/stm32_rtc.c
Signature · 1 line
2.15.0
#1 lore raw

PATCH v3 1/2 clk: stm32mp1: Add RTC clock entry

From: Patrick Delaunay <[email protected]>

Add RTCAPB and RTC clock support.

---
 drivers/clk/clk_stm32mp1.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/clk/clk_stm32mp1.c +9 -0
index f295e4864b..97d4a34deb 100644
@@ -300,6 +300,7 @@ enum stm32mp1_parent_sel {
 	_DSI_SEL,
 	_ADC12_SEL,
 	_SPI1_SEL,
+	_RTC_SEL,
 	_PARENT_SEL_NB,
 	_UNKNOWN_SEL = 0xff,
 };
@@ -534,6 +535,7 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
 	STM32MP1_CLK_SET_CLR(RCC_MP_APB4ENSETR, 16, USBPHY_K, _USBPHY_SEL),
 
 	STM32MP1_CLK_SET_CLR(RCC_MP_APB5ENSETR, 2, I2C4_K, _I2C46_SEL),
+	STM32MP1_CLK_SET_CLR(RCC_MP_APB5ENSETR, 8, RTCAPB, _PCLK5),
 	STM32MP1_CLK_SET_CLR(RCC_MP_APB5ENSETR, 20, STGEN_K, _STGEN_SEL),
 
 	STM32MP1_CLK_SET_CLR_F(RCC_MP_AHB2ENSETR, 5, ADC12, _HCLK2),
@@ -569,6 +571,8 @@ static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
 	STM32MP1_CLK_SET_CLR(RCC_MP_AHB6ENSETR, 24, USBH, _UNKNOWN_SEL),
 
 	STM32MP1_CLK(RCC_DBGCFGR, 8, CK_DBG, _UNKNOWN_SEL),
+
+	STM32MP1_CLK(RCC_BDCR, 20, RTC, _RTC_SEL),
 };
 
 static const u8 i2c12_parents[] = {_PCLK1, _PLL4_R, _HSI_KER, _CSI_KER};
@@ -594,6 +598,7 @@ static const u8 dsi_parents[] = {_DSI_PHY, _PLL4_P};
 static const u8 adc_parents[] = {_PLL4_R, _CK_PER, _PLL3_Q};
 static const u8 spi_parents[] = {_PLL4_P, _PLL3_Q, _I2S_CKIN, _CK_PER,
 				 _PLL3_R};
+static const u8 rtc_parents[] = {_UNKNOWN_ID, _LSE, _LSI, _HSE};
 
 static const struct stm32mp1_clk_sel stm32mp1_clk_sel[_PARENT_SEL_NB] = {
 	STM32MP1_CLK_PARENT(_I2C12_SEL, RCC_I2C12CKSELR, 0, 0x7, i2c12_parents),
@@ -619,6 +624,9 @@ static const struct stm32mp1_clk_sel stm32mp1_clk_sel[_PARENT_SEL_NB] = {
 	STM32MP1_CLK_PARENT(_DSI_SEL, RCC_DSICKSELR, 0, 0x1, dsi_parents),
 	STM32MP1_CLK_PARENT(_ADC12_SEL, RCC_ADCCKSELR, 0, 0x1, adc_parents),
 	STM32MP1_CLK_PARENT(_SPI1_SEL, RCC_SPI2S1CKSELR, 0, 0x7, spi_parents),
+	STM32MP1_CLK_PARENT(_RTC_SEL, RCC_BDCR, RCC_BDCR_RTCSRC_SHIFT,
+			    (RCC_BDCR_RTCSRC_MASK >> RCC_BDCR_RTCSRC_SHIFT),
+			    rtc_parents),
 };
 
 #ifdef STM32MP1_CLOCK_TREE_INIT
@@ -734,6 +742,7 @@ char * const stm32mp1_clk_parent_sel_name[_PARENT_SEL_NB] = {
 	[_DSI_SEL] = "DSI",
 	[_ADC12_SEL] = "ADC12",
 	[_SPI1_SEL] = "SPI1",
+	[_RTC_SEL] = "RTC",
 };
 
 static const struct stm32mp1_clk_data stm32mp1_data = {
Signature · 1 line
2.15.0
#2 lore raw

PATCH v3 1/2 clk: stm32mp1: Add RTC clock entry

Hi,

Quoted 5 lines

From: Benjamin GAIGNARD <[email protected]>
Sent: jeudi 11 juillet 2019 12:04

From: Patrick Delaunay <[email protected]>

Quoted 8 lines

Add RTCAPB and RTC clock support.

---
 drivers/clk/clk_stm32mp1.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Applied to u-boot-stm32/master, thanks!

Patrick

#3 lore raw

PATCH v3 2/2 rtc: Add rtc driver for stm32mp1

In reply to Benjamin Gaignard

Add support of STM32MP1 rtc driver.
Enable it for basic and trusted configurations.

---
version 3:
- release clock only on error cases.

 configs/stm32mp15_basic_defconfig   |   2 +
 configs/stm32mp15_trusted_defconfig |   2 +
 drivers/rtc/Kconfig                 |   6 +
 drivers/rtc/Makefile                |   1 +
 drivers/rtc/stm32_rtc.c             | 323 ++++++++++++++++++++++++++++++++++++
 5 files changed, 334 insertions(+)
 create mode 100644 drivers/rtc/stm32_rtc.c
configs/stm32mp15_basic_defconfig +2 -0
index 79687d3dfd..5c75457cd5 100644
@@ -95,6 +95,8 @@ CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
 CONFIG_DM_REGULATOR_STPMIC1=y
+CONFIG_DM_RTC=y
+CONFIG_RTC_STM32=y
 CONFIG_SERIAL_RX_BUFFER=y
 CONFIG_STM32_SERIAL=y
 CONFIG_SPI=y
configs/stm32mp15_trusted_defconfig +2 -0
index e1ab2ab0d5..a71afa4d81 100644
@@ -85,6 +85,8 @@ CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_REGULATOR_STM32_VREFBUF=y
 CONFIG_DM_REGULATOR_STPMIC1=y
+CONFIG_DM_RTC=y
+CONFIG_RTC_STM32=y
 CONFIG_SERIAL_RX_BUFFER=y
 CONFIG_STM32_SERIAL=y
 CONFIG_SPI=y
drivers/rtc/Kconfig +6 -0
index fd0009b2e2..a383e632ad 100644
@@ -110,4 +110,10 @@ config RTC_M41T62
 	  Enable driver for ST's M41T62 compatible RTC devices (like RV-4162).
 	  It is a serial (I2C) real-time clock (RTC) with alarm.
 
+config RTC_STM32
+	bool "Enable STM32 RTC driver"
+	depends on DM_RTC
+	help
+	  Enable STM32 RTC driver. This driver supports the rtc that is present
+	  on some STM32 SoCs.
 endmenu
drivers/rtc/Makefile +1 -0
index 1724602f1c..90e79fb30d 100644
@@ -50,5 +50,6 @@ obj-$(CONFIG_RTC_RX8025) += rx8025.o
 obj-$(CONFIG_RTC_RX8010SJ) += rx8010sj.o
 obj-$(CONFIG_RTC_S3C24X0) += s3c24x0_rtc.o
 obj-$(CONFIG_RTC_S35392A) += s35392a.o
+obj-$(CONFIG_RTC_STM32) += stm32_rtc.o
 obj-$(CONFIG_SANDBOX) += sandbox_rtc.o
 obj-$(CONFIG_RTC_X1205) += x1205.o
drivers/rtc/stm32_rtc.c new file +323 -0

323 lines not on this page · raw message

Signature · 1 line
2.15.0
#4 lore raw

PATCH v3 2/2 rtc: Add rtc driver for stm32mp1

Hi,

Quoted 11 lines

From: Benjamin GAIGNARD <[email protected]>
Sent: jeudi 11 juillet 2019 12:04

Add support of STM32MP1 rtc driver.
Enable it for basic and trusted configurations.

---
version 3:
- release clock only on error cases.

Quoted 9 lines
 configs/stm32mp15_basic_defconfig   |   2 +
 configs/stm32mp15_trusted_defconfig |   2 +
 drivers/rtc/Kconfig                 |   6 +
 drivers/rtc/Makefile                |   1 +
 drivers/rtc/stm32_rtc.c             | 323
++++++++++++++++++++++++++++++++++++
 5 files changed, 334 insertions(+)
 create mode 100644 drivers/rtc/stm32_rtc.c

Applied to u-boot-stm32/master, thanks!

But still errors because RTC year as only 2 digits in register (00-99 only =>> %100 is missing) and U-Boot expect year with 4 digits (0000-9999)
=> I will push a correction today.

Patrick