RE: [PATCHv5 3/8] rtc: add STM32 RTC driver

2017-01-13 Thread Amelie DELAUNAY
Hi Alexandre,

> This didn't apply cleanly, please check rtc-next. I don't think I made any 
> mistake
> as the issue was only in Kconfig. You probably based your patches on 4.9
> instead of 4.10-rc1.
Sorry for this inconvenience. You're right, my patches were based on 4.9 to be 
tested on stm32f4 family.
No mistake found in your conflict resolution in Kconfig.

I'm going to send a new patch to fix warnings introduced by my driver on 
rtc-next.

Regards,
Amelie

> -Original Message-
> From: Alexandre Belloni [mailto:alexandre.bell...@free-electrons.com]
> Sent: vendredi 13 janvier 2017 01:39
> To: Amelie DELAUNAY <amelie.delau...@st.com>
> Cc: Alessandro Zummo <a.zu...@towertech.it>; Rob Herring
> <robh...@kernel.org>; Mark Rutland <mark.rutl...@arm.com>; Maxime
> Coquelin <mcoquelin.st...@gmail.com>; Alexandre TORGUE
> <alexandre.tor...@st.com>; Russell King <li...@armlinux.org.uk>; rtc-
> li...@googlegroups.com; devicet...@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; linux-kernel@vger.kernel.org; Gabriel FERNANDEZ
> <gabriel.fernan...@st.com>
> Subject: Re: [PATCHv5 3/8] rtc: add STM32 RTC driver
> 
> On 11/01/2017 at 14:46:43 +0100, Amelie Delaunay wrote :
> > This patch adds support for the STM32 RTC.
> >
> > Signed-off-by: Amelie Delaunay <amelie.delau...@st.com>
> > ---
> >  drivers/rtc/Kconfig |  11 +
> >  drivers/rtc/Makefile|   1 +
> >  drivers/rtc/rtc-stm32.c | 727
> > 
> >  3 files changed, 739 insertions(+)
> >  create mode 100644 drivers/rtc/rtc-stm32.c
> >
> 
> This didn't apply cleanly, please check rtc-next. I don't think I made any 
> mistake
> as the issue was only in Kconfig. You probably based your patches on 4.9
> instead of 4.10-rc1.
> 
> 
> --
> Alexandre Belloni, Free Electrons
> Embedded Linux and Kernel engineering
> http://free-electrons.com


RE: [PATCHv5 3/8] rtc: add STM32 RTC driver

2017-01-13 Thread Amelie DELAUNAY
Hi Alexandre,

> This didn't apply cleanly, please check rtc-next. I don't think I made any 
> mistake
> as the issue was only in Kconfig. You probably based your patches on 4.9
> instead of 4.10-rc1.
Sorry for this inconvenience. You're right, my patches were based on 4.9 to be 
tested on stm32f4 family.
No mistake found in your conflict resolution in Kconfig.

I'm going to send a new patch to fix warnings introduced by my driver on 
rtc-next.

Regards,
Amelie

> -Original Message-
> From: Alexandre Belloni [mailto:alexandre.bell...@free-electrons.com]
> Sent: vendredi 13 janvier 2017 01:39
> To: Amelie DELAUNAY 
> Cc: Alessandro Zummo ; Rob Herring
> ; Mark Rutland ; Maxime
> Coquelin ; Alexandre TORGUE
> ; Russell King ; rtc-
> li...@googlegroups.com; devicet...@vger.kernel.org; linux-arm-
> ker...@lists.infradead.org; linux-kernel@vger.kernel.org; Gabriel FERNANDEZ
> 
> Subject: Re: [PATCHv5 3/8] rtc: add STM32 RTC driver
> 
> On 11/01/2017 at 14:46:43 +0100, Amelie Delaunay wrote :
> > This patch adds support for the STM32 RTC.
> >
> > Signed-off-by: Amelie Delaunay 
> > ---
> >  drivers/rtc/Kconfig |  11 +
> >  drivers/rtc/Makefile|   1 +
> >  drivers/rtc/rtc-stm32.c | 727
> > 
> >  3 files changed, 739 insertions(+)
> >  create mode 100644 drivers/rtc/rtc-stm32.c
> >
> 
> This didn't apply cleanly, please check rtc-next. I don't think I made any 
> mistake
> as the issue was only in Kconfig. You probably based your patches on 4.9
> instead of 4.10-rc1.
> 
> 
> --
> Alexandre Belloni, Free Electrons
> Embedded Linux and Kernel engineering
> http://free-electrons.com


Re: [PATCHv5 3/8] rtc: add STM32 RTC driver

2017-01-12 Thread Alexandre Belloni
On 11/01/2017 at 14:46:43 +0100, Amelie Delaunay wrote :
> This patch adds support for the STM32 RTC.
> 
> Signed-off-by: Amelie Delaunay 
> ---
>  drivers/rtc/Kconfig |  11 +
>  drivers/rtc/Makefile|   1 +
>  drivers/rtc/rtc-stm32.c | 727 
> 
>  3 files changed, 739 insertions(+)
>  create mode 100644 drivers/rtc/rtc-stm32.c
> 

This didn't apply cleanly, please check rtc-next. I don't think I made
any mistake as the issue was only in Kconfig. You probably based your
patches on 4.9 instead of 4.10-rc1.


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


Re: [PATCHv5 3/8] rtc: add STM32 RTC driver

2017-01-12 Thread Alexandre Belloni
On 11/01/2017 at 14:46:43 +0100, Amelie Delaunay wrote :
> This patch adds support for the STM32 RTC.
> 
> Signed-off-by: Amelie Delaunay 
> ---
>  drivers/rtc/Kconfig |  11 +
>  drivers/rtc/Makefile|   1 +
>  drivers/rtc/rtc-stm32.c | 727 
> 
>  3 files changed, 739 insertions(+)
>  create mode 100644 drivers/rtc/rtc-stm32.c
> 

This didn't apply cleanly, please check rtc-next. I don't think I made
any mistake as the issue was only in Kconfig. You probably based your
patches on 4.9 instead of 4.10-rc1.


-- 
Alexandre Belloni, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com


[PATCHv5 3/8] rtc: add STM32 RTC driver

2017-01-11 Thread Amelie Delaunay
This patch adds support for the STM32 RTC.

Signed-off-by: Amelie Delaunay 
---
 drivers/rtc/Kconfig |  11 +
 drivers/rtc/Makefile|   1 +
 drivers/rtc/rtc-stm32.c | 727 
 3 files changed, 739 insertions(+)
 create mode 100644 drivers/rtc/rtc-stm32.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e859d14..11eb28a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1706,6 +1706,17 @@ config RTC_DRV_PIC32
   This driver can also be built as a module. If so, the module
   will be called rtc-pic32
 
+config RTC_DRV_STM32
+   tristate "STM32 RTC"
+   select REGMAP_MMIO
+   depends on ARCH_STM32 || COMPILE_TEST
+   help
+  If you say yes here you get support for the STM32 On-Chip
+  Real Time Clock.
+
+  This driver can also be built as a module, if so, the module
+  will be called "rtc-stm32".
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1ac694a..87bd9cc 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -144,6 +144,7 @@ obj-$(CONFIG_RTC_DRV_SNVS)  += rtc-snvs.o
 obj-$(CONFIG_RTC_DRV_SPEAR)+= rtc-spear.o
 obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o
 obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
+obj-$(CONFIG_RTC_DRV_STM32)+= rtc-stm32.o
 obj-$(CONFIG_RTC_DRV_STMP) += rtc-stmp3xxx.o
 obj-$(CONFIG_RTC_DRV_ST_LPC)   += rtc-st-lpc.o
 obj-$(CONFIG_RTC_DRV_SUN4V)+= rtc-sun4v.o
diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
new file mode 100644
index 000..c4789b5
--- /dev/null
+++ b/drivers/rtc/rtc-stm32.c
@@ -0,0 +1,727 @@
+/*
+ * Copyright (C) Amelie Delaunay 2016
+ * Author:  Amelie Delaunay 
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME "stm32_rtc"
+
+/* STM32 RTC registers */
+#define STM32_RTC_TR   0x00
+#define STM32_RTC_DR   0x04
+#define STM32_RTC_CR   0x08
+#define STM32_RTC_ISR  0x0C
+#define STM32_RTC_PRER 0x10
+#define STM32_RTC_ALRMAR   0x1C
+#define STM32_RTC_WPR  0x24
+
+/* STM32_RTC_TR bit fields  */
+#define STM32_RTC_TR_SEC_SHIFT 0
+#define STM32_RTC_TR_SEC   GENMASK(6, 0)
+#define STM32_RTC_TR_MIN_SHIFT 8
+#define STM32_RTC_TR_MIN   GENMASK(14, 8)
+#define STM32_RTC_TR_HOUR_SHIFT16
+#define STM32_RTC_TR_HOUR  GENMASK(21, 16)
+
+/* STM32_RTC_DR bit fields */
+#define STM32_RTC_DR_DATE_SHIFT0
+#define STM32_RTC_DR_DATE  GENMASK(5, 0)
+#define STM32_RTC_DR_MONTH_SHIFT   8
+#define STM32_RTC_DR_MONTH GENMASK(12, 8)
+#define STM32_RTC_DR_WDAY_SHIFT13
+#define STM32_RTC_DR_WDAY  GENMASK(15, 13)
+#define STM32_RTC_DR_YEAR_SHIFT16
+#define STM32_RTC_DR_YEAR  GENMASK(23, 16)
+
+/* STM32_RTC_CR bit fields */
+#define STM32_RTC_CR_FMT   BIT(6)
+#define STM32_RTC_CR_ALRAE BIT(8)
+#define STM32_RTC_CR_ALRAIEBIT(12)
+
+/* STM32_RTC_ISR bit fields */
+#define STM32_RTC_ISR_ALRAWF   BIT(0)
+#define STM32_RTC_ISR_INITSBIT(4)
+#define STM32_RTC_ISR_RSF  BIT(5)
+#define STM32_RTC_ISR_INITFBIT(6)
+#define STM32_RTC_ISR_INIT BIT(7)
+#define STM32_RTC_ISR_ALRAFBIT(8)
+
+/* STM32_RTC_PRER bit fields */
+#define STM32_RTC_PRER_PRED_S_SHIFT0
+#define STM32_RTC_PRER_PRED_S  GENMASK(14, 0)
+#define STM32_RTC_PRER_PRED_A_SHIFT16
+#define STM32_RTC_PRER_PRED_A  GENMASK(22, 16)
+
+/* STM32_RTC_ALRMAR and STM32_RTC_ALRMBR bit fields */
+#define STM32_RTC_ALRMXR_SEC_SHIFT 0
+#define STM32_RTC_ALRMXR_SEC   GENMASK(6, 0)
+#define STM32_RTC_ALRMXR_SEC_MASK  BIT(7)
+#define STM32_RTC_ALRMXR_MIN_SHIFT 8
+#define STM32_RTC_ALRMXR_MIN   GENMASK(14, 8)
+#define STM32_RTC_ALRMXR_MIN_MASK  BIT(15)
+#define STM32_RTC_ALRMXR_HOUR_SHIFT16
+#define STM32_RTC_ALRMXR_HOUR  GENMASK(21, 16)
+#define STM32_RTC_ALRMXR_PMBIT(22)
+#define STM32_RTC_ALRMXR_HOUR_MASK BIT(23)
+#define STM32_RTC_ALRMXR_DATE_SHIFT24
+#define STM32_RTC_ALRMXR_DATE  GENMASK(29, 24)
+#define STM32_RTC_ALRMXR_WDSEL BIT(30)
+#define STM32_RTC_ALRMXR_WDAY_SHIFT24
+#define STM32_RTC_ALRMXR_WDAY  GENMASK(27, 24)
+#define STM32_RTC_ALRMXR_DATE_MASK BIT(31)
+
+/* STM32_RTC_WPR key constants */
+#define RTC_WPR_1ST_KEY0xCA
+#define RTC_WPR_2ND_KEY0x53
+#define RTC_WPR_WRONG_KEY  0xFF
+
+/*
+ * RTC registers are protected against parasitic write access.
+ * PWR_CR_DBP bit must be set to enable write access to RTC 

[PATCHv5 3/8] rtc: add STM32 RTC driver

2017-01-11 Thread Amelie Delaunay
This patch adds support for the STM32 RTC.

Signed-off-by: Amelie Delaunay 
---
 drivers/rtc/Kconfig |  11 +
 drivers/rtc/Makefile|   1 +
 drivers/rtc/rtc-stm32.c | 727 
 3 files changed, 739 insertions(+)
 create mode 100644 drivers/rtc/rtc-stm32.c

diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index e859d14..11eb28a 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -1706,6 +1706,17 @@ config RTC_DRV_PIC32
   This driver can also be built as a module. If so, the module
   will be called rtc-pic32
 
+config RTC_DRV_STM32
+   tristate "STM32 RTC"
+   select REGMAP_MMIO
+   depends on ARCH_STM32 || COMPILE_TEST
+   help
+  If you say yes here you get support for the STM32 On-Chip
+  Real Time Clock.
+
+  This driver can also be built as a module, if so, the module
+  will be called "rtc-stm32".
+
 comment "HID Sensor RTC drivers"
 
 config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 1ac694a..87bd9cc 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -144,6 +144,7 @@ obj-$(CONFIG_RTC_DRV_SNVS)  += rtc-snvs.o
 obj-$(CONFIG_RTC_DRV_SPEAR)+= rtc-spear.o
 obj-$(CONFIG_RTC_DRV_STARFIRE) += rtc-starfire.o
 obj-$(CONFIG_RTC_DRV_STK17TA8) += rtc-stk17ta8.o
+obj-$(CONFIG_RTC_DRV_STM32)+= rtc-stm32.o
 obj-$(CONFIG_RTC_DRV_STMP) += rtc-stmp3xxx.o
 obj-$(CONFIG_RTC_DRV_ST_LPC)   += rtc-st-lpc.o
 obj-$(CONFIG_RTC_DRV_SUN4V)+= rtc-sun4v.o
diff --git a/drivers/rtc/rtc-stm32.c b/drivers/rtc/rtc-stm32.c
new file mode 100644
index 000..c4789b5
--- /dev/null
+++ b/drivers/rtc/rtc-stm32.c
@@ -0,0 +1,727 @@
+/*
+ * Copyright (C) Amelie Delaunay 2016
+ * Author:  Amelie Delaunay 
+ * License terms:  GNU General Public License (GPL), version 2
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DRIVER_NAME "stm32_rtc"
+
+/* STM32 RTC registers */
+#define STM32_RTC_TR   0x00
+#define STM32_RTC_DR   0x04
+#define STM32_RTC_CR   0x08
+#define STM32_RTC_ISR  0x0C
+#define STM32_RTC_PRER 0x10
+#define STM32_RTC_ALRMAR   0x1C
+#define STM32_RTC_WPR  0x24
+
+/* STM32_RTC_TR bit fields  */
+#define STM32_RTC_TR_SEC_SHIFT 0
+#define STM32_RTC_TR_SEC   GENMASK(6, 0)
+#define STM32_RTC_TR_MIN_SHIFT 8
+#define STM32_RTC_TR_MIN   GENMASK(14, 8)
+#define STM32_RTC_TR_HOUR_SHIFT16
+#define STM32_RTC_TR_HOUR  GENMASK(21, 16)
+
+/* STM32_RTC_DR bit fields */
+#define STM32_RTC_DR_DATE_SHIFT0
+#define STM32_RTC_DR_DATE  GENMASK(5, 0)
+#define STM32_RTC_DR_MONTH_SHIFT   8
+#define STM32_RTC_DR_MONTH GENMASK(12, 8)
+#define STM32_RTC_DR_WDAY_SHIFT13
+#define STM32_RTC_DR_WDAY  GENMASK(15, 13)
+#define STM32_RTC_DR_YEAR_SHIFT16
+#define STM32_RTC_DR_YEAR  GENMASK(23, 16)
+
+/* STM32_RTC_CR bit fields */
+#define STM32_RTC_CR_FMT   BIT(6)
+#define STM32_RTC_CR_ALRAE BIT(8)
+#define STM32_RTC_CR_ALRAIEBIT(12)
+
+/* STM32_RTC_ISR bit fields */
+#define STM32_RTC_ISR_ALRAWF   BIT(0)
+#define STM32_RTC_ISR_INITSBIT(4)
+#define STM32_RTC_ISR_RSF  BIT(5)
+#define STM32_RTC_ISR_INITFBIT(6)
+#define STM32_RTC_ISR_INIT BIT(7)
+#define STM32_RTC_ISR_ALRAFBIT(8)
+
+/* STM32_RTC_PRER bit fields */
+#define STM32_RTC_PRER_PRED_S_SHIFT0
+#define STM32_RTC_PRER_PRED_S  GENMASK(14, 0)
+#define STM32_RTC_PRER_PRED_A_SHIFT16
+#define STM32_RTC_PRER_PRED_A  GENMASK(22, 16)
+
+/* STM32_RTC_ALRMAR and STM32_RTC_ALRMBR bit fields */
+#define STM32_RTC_ALRMXR_SEC_SHIFT 0
+#define STM32_RTC_ALRMXR_SEC   GENMASK(6, 0)
+#define STM32_RTC_ALRMXR_SEC_MASK  BIT(7)
+#define STM32_RTC_ALRMXR_MIN_SHIFT 8
+#define STM32_RTC_ALRMXR_MIN   GENMASK(14, 8)
+#define STM32_RTC_ALRMXR_MIN_MASK  BIT(15)
+#define STM32_RTC_ALRMXR_HOUR_SHIFT16
+#define STM32_RTC_ALRMXR_HOUR  GENMASK(21, 16)
+#define STM32_RTC_ALRMXR_PMBIT(22)
+#define STM32_RTC_ALRMXR_HOUR_MASK BIT(23)
+#define STM32_RTC_ALRMXR_DATE_SHIFT24
+#define STM32_RTC_ALRMXR_DATE  GENMASK(29, 24)
+#define STM32_RTC_ALRMXR_WDSEL BIT(30)
+#define STM32_RTC_ALRMXR_WDAY_SHIFT24
+#define STM32_RTC_ALRMXR_WDAY  GENMASK(27, 24)
+#define STM32_RTC_ALRMXR_DATE_MASK BIT(31)
+
+/* STM32_RTC_WPR key constants */
+#define RTC_WPR_1ST_KEY0xCA
+#define RTC_WPR_2ND_KEY0x53
+#define RTC_WPR_WRONG_KEY  0xFF
+
+/*
+ * RTC registers are protected against parasitic write access.
+ * PWR_CR_DBP bit must be set to enable write access to RTC registers.
+ */
+/* STM32_PWR_CR */
+#define