Add pcf2131 rtc support
Subsystems (3)
cover Add pcf2131 rtc support
The patchset supports pcf2131 rtc.
For the details, please check the patch commit log.
Joy Zou (3):
configs: Enable RTC pcf2131 support
imx: imx93_evk: add rtc pcf2131
drivers: rtc: add pcf2131 rtc driver
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 + arch/arm/dts/imx93-11x11-evk.dts | 25 +++ arch/arm/dts/imx93.dtsi | 2 +- configs/imx93_11x11_evk_defconfig | 2 +- drivers/rtc/Kconfig | 10 ++ drivers/rtc/Makefile | 1 + drivers/rtc/pcf2131.c | 189 +++++++++++++++++++++++ 7 files changed, 235 insertions(+), 2 deletions(-) create mode 100644 drivers/rtc/pcf2131.c
Signature · 1 line
2.37.1
PATCH 1/3 configs: Enable RTC pcf2131 support
Enable CONFIG_RTC_PCF2131 configs to support pcf2131.
Disable CONFIG_RTC_EMULATION configs. The default rtc0 change into pcf2131.
--- configs/imx93_11x11_evk_defconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configs/imx93_11x11_evk_defconfig +1 -1
@@ -13,6 +13,7 @@ CONFIG_DEFAULT_DEVICE_TREE="imx93-11x11-evk" CONFIG_SPL_TEXT_BASE=0x2049A000 CONFIG_TARGET_IMX93_11X11_EVK=y CONFIG_SYS_PROMPT="u-boot=> " +CONFIG_RTC_PCF2131=y CONFIG_SPL_SERIAL=y CONFIG_SPL_DRIVERS_MISC=y CONFIG_SPL_STACK=0x2051ddd0
@@ -107,7 +108,6 @@ CONFIG_DM_REGULATOR=y CONFIG_DM_REGULATOR_FIXED=y CONFIG_DM_REGULATOR_GPIO=y CONFIG_DM_RTC=y -CONFIG_RTC_EMULATION=y CONFIG_DM_SERIAL=y CONFIG_FSL_LPUART=y CONFIG_ULP_WATCHDOG=y
Signature · 1 line
2.37.1
PATCH 2/3 imx: imx93_evk: add rtc pcf2131
In reply to Joy Zousupport rtc pcf2131 for imx93.
--- arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 ++++++++ arch/arm/dts/imx93-11x11-evk.dts | 25 ++++++++++++++++++++++++ arch/arm/dts/imx93.dtsi | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-)
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +8 -0
@@ -113,6 +113,10 @@ bootph-pre-ram; }; +&lpi2c3 { + u-boot,dm-spl; +}; + &{/soc@0/bus@44000000/i2c@44350000/pmic@25} { bootph-pre-ram; };
@@ -125,6 +129,10 @@ bootph-pre-ram; }; +&pinctrl_lpi2c3 { + u-boot,dm-spl; +}; + &fec { phy-reset-gpios = <&pcal6524 16 GPIO_ACTIVE_LOW>; phy-reset-duration = <15>;
arch/arm/dts/imx93-11x11-evk.dts +25 -0
@@ -244,6 +244,24 @@ }; }; +&lpi2c3 { + #address-cells = <1>; + #size-cells = <0>; + clock-frequency = <400000>; + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&pinctrl_lpi2c3>; + pinctrl-1 = <&pinctrl_lpi2c3>; + status = "okay"; + + pcf2131: rtc@53 { + compatible = "nxp,pcf2131"; + reg = <0x53>; + interrupt-parent = <&pcal6524>; + interrupts = <1 IRQ_TYPE_LEVEL_LOW>; + status = "okay"; + }; +}; + &lpuart1 { /* console */ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart1>;
@@ -461,6 +479,13 @@ >; }; + pinctrl_lpi2c3: lpi2c3grp { + fsl,pins = < + MX93_PAD_GPIO_IO28__LPI2C3_SDA 0x40000b9e + MX93_PAD_GPIO_IO29__LPI2C3_SCL 0x40000b9e + >; + }; + pinctrl_pcal6524: pcal6524grp { fsl,pins = < MX93_PAD_CCM_CLKO2__GPIO3_IO27 0x31e
arch/arm/dts/imx93.dtsi +1 -1
@@ -319,7 +319,7 @@ reg = <0x42530000 0x10000>; interrupts = <GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>; clocks = <&clk IMX93_CLK_LPI2C3_GATE>, - <&clk IMX93_CLK_LPI2C3_GATE>; + <&clk IMX93_CLK_BUS_WAKEUP>; clock-names = "per", "ipg"; status = "disabled"; };
Signature · 1 line
2.37.1
Re: [PATCH v1 2/3] imx: imx93_evk: add rtc pcf2131
Quoted 17 lines · Joy Zou
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
support rtc pcf2131 for imx93.
Signed-off-by Joy Zou <[email protected]>--- arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 ++++++++ arch/arm/dts/imx93-11x11-evk.dts | 25 ++++++++++++++++++++++++ arch/arm/dts/imx93.dtsi | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-)arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +0
-0
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi line 118
Quoted 6 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +3
-0@@ -113,6 +113,10 @@ bootph-pre-ram; }; +&lpi2c3 { + u-boot,dm-spl; +};
Do you need rtc in SPL stage or only in U-Boot proper?
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi line 134
Quoted 11 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +4
-0+ &{/soc@0/bus@44000000/i2c@44350000/pmic@25} { bootph-pre-ram; };@@ -125,6 +129,10 @@ bootph-pre-ram; }; +&pinctrl_lpi2c3 { + u-boot,dm-spl; +};
Ditto.
Quoted 52 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +1
-0+ &fec { phy-reset-gpios = <&pcal6524 16 GPIO_ACTIVE_LOW>; phy-reset-duration = <15>;arch/arm/dts/imx93-11x11-evk.dts +25
-0@@ -244,6 +244,24 @@ }; }; +&lpi2c3 { + #address-cells = <1>; + #size-cells = <0>; + clock-frequency = <400000>; + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&pinctrl_lpi2c3>; + pinctrl-1 = <&pinctrl_lpi2c3>; + status = "okay"; + + pcf2131: rtc@53 { + compatible = "nxp,pcf2131"; + reg = <0x53>; + interrupt-parent = <&pcal6524>; + interrupts = <1 IRQ_TYPE_LEVEL_LOW>; + status = "okay"; + }; +}; + &lpuart1 { /* console */ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart1>;@@ -461,6 +479,13 @@ >; }; + pinctrl_lpi2c3: lpi2c3grp { + fsl,pins = < + MX93_PAD_GPIO_IO28__LPI2C3_SDA 0x40000b9e + MX93_PAD_GPIO_IO29__LPI2C3_SCL 0x40000b9e + >; + }; + pinctrl_pcal6524: pcal6524grp { fsl,pins = < MX93_PAD_CCM_CLKO2__GPIO3_IO27 0x31earch/arm/dts/imx93.dtsi +0
-0
arch/arm/dts/imx93.dtsi line 322
Quoted 5 lines
arch/arm/dts/imx93.dtsi +1
-1@@ -319,7 +319,7 @@ reg = <0x42530000 0x10000>; interrupts = <GIC_SPI 62 IRQ_TYPE_LEVEL_HIGH>; clocks = <&clk IMX93_CLK_LPI2C3_GATE>, - <&clk IMX93_CLK_LPI2C3_GATE>; + <&clk IMX93_CLK_BUS_WAKEUP>;
What is this change for?
Regards,
Peng.
Quoted 6 lines
arch/arm/dts/imx93.dtsi +0
-1clock-names = "per", "ipg"; status = "disabled"; }; --2.37.1
RE: [PATCH v1 2/3] imx: imx93_evk: add rtc pcf2131
Quoted 37 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2023年5月31日 9:37
To: Joy Zou <[email protected]>; Peng Fan <[email protected]>; Ye Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: dl-uboot-imx <[email protected]>; [email protected]
Subject: Re: [PATCH v1 2/3] imx:imx93_evk: add rtc pcf2131Quoted 11 lines · Joy Zou
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
support rtc pcf2131 for imx93.
Signed-off-by Joy Zou <[email protected]>--- arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 ++++++++ arch/arm/dts/imx93-11x11-evk.dts | 25++++++++++++++++++++++++
Quoted 12 lines
arch/arm/dts/imx93.dtsi | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-)arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +0
-0@@ -113,6 +113,10 @@ bootph-pre-ram; };
Quoted 5 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi line 118
Quoted 3 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +3
-0+&lpi2c3 { + u-boot,dm-spl; +};Do you need rtc in SPL stage or only in U-Boot proper?
only in U-Boot proper.
Quoted 9 lines
Quoted 9 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +1
-0+ &{/soc@0/bus@44000000/i2c@44350000/pmic@25} { bootph-pre-ram; };@@ -125,6 +129,10 @@ bootph-pre-ram; };
Quoted 5 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi line 134
Quoted 3 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +3
-0+&pinctrl_lpi2c3 { + u-boot,dm-spl; +};Ditto.
only in U-Boot proper.
Quoted 59 lines
Quoted 38 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +1
-0+ &fec { phy-reset-gpios = <&pcal6524 16 GPIO_ACTIVE_LOW>; phy-reset-duration = <15>;arch/arm/dts/imx93-11x11-evk.dts +18
-0@@ -244,6 +244,24 @@ }; }; +&lpi2c3 { + #address-cells = <1>; + #size-cells = <0>; + clock-frequency = <400000>; + pinctrl-names = "default", "sleep"; + pinctrl-0 = <&pinctrl_lpi2c3>; + pinctrl-1 = <&pinctrl_lpi2c3>; + status = "okay"; + + pcf2131: rtc@53 { + compatible = "nxp,pcf2131"; + reg = <0x53>; + interrupt-parent = <&pcal6524>; + interrupts = <1 IRQ_TYPE_LEVEL_LOW>; + status = "okay"; + }; +}; + &lpuart1 { /* console */ pinctrl-names = "default"; pinctrl-0 = <&pinctrl_uart1>; @@ -461,6 +479,13 @@>; };arch/arm/dts/imx93-11x11-evk.dts
Quoted 3 lines
arch/arm/dts/imx93-11x11-evk.dts +3
-0+ pinctrl_lpi2c3: lpi2c3grp { + fsl,pins = < + MX93_PAD_GPIO_IO28__LPI2C3_SDA
0x40000b9eQuoted 1 line
+
MX93_PAD_GPIO_IO29__LPI2C3_SCL
0x40000b9earch/arm/dts/imx93-11x11-evk.dts
Quoted 6 lines
arch/arm/dts/imx93-11x11-evk.dts +3
-0+ >; + }; + pinctrl_pcal6524: pcal6524grp { fsl,pins = < MX93_PAD_CCM_CLKO2__GPIO3_IO27
0x31earch/arm/dts/imx93.dtsi line 320
Quoted 7 lines
arch/arm/dts/imx93.dtsi index renamed from arch/arm/dts/imx93.dtsi +0
-0
28026ccecc..ac4b81c02f100644arch/arm/dts/imx93.dtsi +0
-0@@ -319,7 +319,7 @@ reg = <0x42530000 0x10000>; interrupts = <GIC_SPI 62
IRQ_TYPE_LEVEL_HIGH>;
Quoted 8 lines
arch/arm/dts/imx93.dtsi line 321
Quoted 1 line
arch/arm/dts/imx93.dtsi +0
-0clocks = <&clk
IMX93_CLK_LPI2C3_GATE>,arch/arm/dts/imx93.dtsi line 322
Quoted 1 line
arch/arm/dts/imx93.dtsi +0
-1- <&clk
IMX93_CLK_LPI2C3_GATE>;arch/arm/dts/imx93.dtsi line 322
Quoted 1 line
arch/arm/dts/imx93.dtsi +1
-0+ <&clk
IMX93_CLK_BUS_WAKEUP>;What is this change for?
Because the lpi2c3 ipg clk only need bus_wakeup_clk_root according to the imx93 RM. Thanks peng!
BR
Joy Zou
Quoted 9 lines
Regards,
Peng.Quoted 6 lines
arch/arm/dts/imx93.dtsi +0
-1clock-names = "per", "ipg"; status = "disabled"; }; --2.37.1
PATCH 3/3 drivers: rtc: add pcf2131 rtc driver
In reply to Joy ZouAdding support for pcf2131 RTC chip.
The pcf2131 is similar to the pcf2127. The driver support rtc register read/write by using rtc cmd and rtc date set/get by using date cmd.
--- drivers/rtc/Kconfig | 10 +++ drivers/rtc/Makefile | 1 + drivers/rtc/pcf2131.c | 189 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+) create mode 100644 drivers/rtc/pcf2131.c
drivers/rtc/Kconfig +10 -0
@@ -64,6 +64,16 @@ config RTC_PCF2127 has a selectable I2C-bus or SPI-bus, a backup battery switch-over circuit, a programmable watchdog function, a timestamp function, and many other features. +config RTC_PCF2131 + bool "Enable PCF2131 driver" + depends on DM_RTC + help + The PCF2131 is a CMOS Real Time Clock (RTC) and calendar with an integrated + Temperature Compensated Crystal (Xtal) Oscillator (TCXO) and a 32.768 kHz quartz + crystal optimized for very high accuracy and very low power consumption. The PCF2127 + has a selectable I2C-bus or SPI-bus, a backup battery switch-over circuit, a + programmable watchdog function, a timestamp function, and many other features. + config RTC_DS1307 bool "Enable DS1307 driver" depends on DM_RTC
drivers/rtc/Makefile +1 -0
@@ -27,6 +27,7 @@ obj-$(CONFIG_RTC_MV) += mvrtc.o obj-$(CONFIG_RTC_MXS) += mxsrtc.o obj-$(CONFIG_RTC_PCF8563) += pcf8563.o obj-$(CONFIG_RTC_PCF2127) += pcf2127.o +obj-$(CONFIG_RTC_PCF2131) += pcf2131.o obj-$(CONFIG_RTC_PL031) += pl031.o obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o obj-$(CONFIG_RTC_RV3028) += rv3028.o
drivers/rtc/pcf2131.c new file +189 -0
189 lines not on this page · raw message
Signature · 1 line
2.37.1
Re: [PATCH v1 3/3] drivers: rtc: add pcf2131 rtc driver
Quoted 55 lines · Joy Zou
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
Adding support for pcf2131 RTC chip.
The pcf2131 is similar to the pcf2127. The driver support rtc register read/write by using rtc cmd and rtc date set/get by using date cmd.
Signed-off-by Joy Zou <[email protected]>--- drivers/rtc/Kconfig | 10 +++ drivers/rtc/Makefile | 1 + drivers/rtc/pcf2131.c | 189 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 200 insertions(+)create mode 100644
drivers/rtc/pcf2131.cdrivers/rtc/Kconfig +10
-0@@ -64,6 +64,16 @@ config RTC_PCF2127 has a selectable I2C-bus or SPI-bus, a backup battery switch-over circuit, a programmable watchdog function, a timestamp function, and many other features. +config RTC_PCF2131 + bool "Enable PCF2131 driver" + depends on DM_RTC + help + The PCF2131 is a CMOS Real Time Clock (RTC) and calendar with an integrated + Temperature Compensated Crystal (Xtal) Oscillator (TCXO) and a 32.768 kHz quartz + crystal optimized for very high accuracy and very low power consumption. The PCF2127 + has a selectable I2C-bus or SPI-bus, a backup battery switch-over circuit, a + programmable watchdog function, a timestamp function, and many other features. + config RTC_DS1307 bool "Enable DS1307 driver" depends on DM_RTCdrivers/rtc/Makefile +1
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_RTC_MV) += mvrtc.o obj-$(CONFIG_RTC_MXS) += mxsrtc.o obj-$(CONFIG_RTC_PCF8563) += pcf8563.o obj-$(CONFIG_RTC_PCF2127) += pcf2127.o +obj-$(CONFIG_RTC_PCF2131) += pcf2131.o obj-$(CONFIG_RTC_PL031) += pl031.o obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o obj-$(CONFIG_RTC_RV3028) += rv3028.odrivers/rtc/pcf2131.c new file +0
-0
drivers/rtc/pcf2131.c line 8
Quoted 8 lines
drivers/rtc/pcf2131.c new file +8
-0@@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* The NXP PCF2131 RTC uboot driver. +* Copyright 2023 NXP +* Date & Time support for PCF2131 RTC +*/ + +/* #define DEBUG */
Drop this line.
Quoted 50 lines
drivers/rtc/pcf2131.c new file +50
-0+ +#include <common.h> +#include <command.h> +#include <dm.h> +#include <i2c.h> +#include <log.h> +#include <rtc.h> + +#define PCF2131_REG_CTRL1 0x00 +#define PCF2131_BIT_CTRL1_STOP BIT(5) +#define PCF2131_BIT_CTRL1_100TH_S_DIS BIT(4) +#define PCF2131_REG_CTRL2 0x01 +#define PCF2131_REG_CTRL3 0x02 +#define PCF2131_REG_SR_RESET 0x05 +#define PCF2131_SR_VAL_Clr_Pres 0xa4 +#define PCF2131_REG_SC 0x07 +#define PCF2131_REG_MN 0x08 +#define PCF2131_REG_HR 0x09 +#define PCF2131_REG_DM 0x0a +#define PCF2131_REG_DW 0x0b +#define PCF2131_REG_MO 0x0c +#define PCF2131_REG_YR 0x0d + +static int pcf2131_rtc_read (struct udevice *dev,uint offset,u8 *buffer,uint len) +{ +struct dm_i2c_chip *chip =dev_get_parent_plat (dev); +struct i2c_msg msg; +int ret; + +/* Set the address of the start register to be read */ + ret =dm_i2c_write (dev, offset,NULL ,0 ); +if (ret <0 ) +return ret; + +/* Read register's data */ + msg.addr = chip->chip_addr; + msg.flags |=I2C_M_RD ; + msg.len = len; + msg.buf = buffer; + +return dm_i2c_xfer (dev, &msg,1 ); +} + +static int pcf2131_rtc_lock (struct udevice *dev) +{ +int ret =0 ; +uchar buf[6 ] = {PCF2131_REG_CTRL1 }; + + ret =pcf2131_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 )
drivers/rtc/pcf2131.c line 68
Quoted 10 lines
drivers/rtc/pcf2131.c new file +10
-0+return ret; + + buf[PCF2131_REG_CTRL1 ] |=PCF2131_BIT_CTRL1_STOP ; + ret =dm_i2c_write (dev,PCF2131_REG_CTRL1 , &buf[PCF2131_REG_CTRL1 ],1 ); +if (ret <0 ) +return ret; + + buf[PCF2131_REG_SR_RESET ] = PCF2131_SR_VAL_Clr_Pres; + ret =dm_i2c_write (dev,PCF2131_REG_SR_RESET , &buf[PCF2131_REG_SR_RESET ],1 ); +return ret;
Just "return dm_i2c_write..." is ok.
Quoted 4 lines
drivers/rtc/pcf2131.c new file +4
-0+} + +static int pcf2131_rtc_unlock (struct udevice *dev) +{
drivers/rtc/pcf2131.c line 82
Quoted 10 lines
drivers/rtc/pcf2131.c new file +10
-0+int ret =0 ; +uchar buf[6 ] = {PCF2131_REG_CTRL1 }; + + ret =pcf2131_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 ) +return ret; + + buf[PCF2131_REG_CTRL1 ] &= ~PCF2131_BIT_CTRL1_STOP ; + ret =dm_i2c_write (dev,PCF2131_REG_CTRL1 , &buf[PCF2131_REG_CTRL1 ],1 ); +return ret;
Ditto.
Quoted 7 lines
drivers/rtc/pcf2131.c new file +7
-0+} + +static int pcf2131_rtc_write (struct udevice *dev,uint offset, +const u8 *buffer,uint len) +{ +int ret =0 ; +
drivers/rtc/pcf2131.c line 99
Quoted 10 lines
drivers/rtc/pcf2131.c new file +10
-0+ ret =pcf2131_rtc_lock (dev); +if (ret <0 ) +return ret; + + ret =dm_i2c_write (dev, offset, buffer, len); +if (ret <0 ) +return ret; + + ret =pcf2131_rtc_unlock (dev); +return ret;
Ditto.
drivers/rtc/pcf2131.c
Quoted 4 lines
drivers/rtc/pcf2131.c new file +4
-0+} + +static int pcf2131_rtc_set (struct udevice *dev,const struct rtc_time *tm) +{ > + uchar buf[7] = {0};
No need init is to 0?
Quoted 16 lines
drivers/rtc/pcf2131.c new file +16
-0+int i =0 , ret; + +/* hours, minutes and seconds */ + buf[i++] =bin2bcd (tm->tm_sec); + buf[i++] =bin2bcd (tm->tm_min); + buf[i++] =bin2bcd (tm->tm_hour); + buf[i++] =bin2bcd (tm->tm_mday); + buf[i++] = tm->tm_wday &0x07 ; + +/* month, 1 - 12 */ + buf[i++] =bin2bcd (tm->tm_mon); + +/* year */ + buf[i++] =bin2bcd (tm->tm_year %100 ); + + ret =pcf2131_rtc_lock (dev);
drivers/rtc/pcf2131.c line 130
Quoted 10 lines
drivers/rtc/pcf2131.c new file +10
-0+if (ret <0 ) +return ret; + +/* write register's data */ + ret =dm_i2c_write (dev,PCF2131_REG_SC , buf, i); +if (ret <0 ) +return ret; + + ret =pcf2131_rtc_unlock (dev); +return ret;
Just "return pfc2131_rtc_unlock..." is ok.
drivers/rtc/pcf2131.c line 136
Quoted 6 lines
drivers/rtc/pcf2131.c new file +6
-0+} + +static int pcf2131_rtc_get (struct udevice *dev,struct rtc_time *tm) +{ +int ret =0 ; +uchar buf[16 ] = {PCF2131_REG_CTRL1 };
No need initialize buf?
Quoted 54 lines
drivers/rtc/pcf2131.c new file +53
-1+ + ret =pcf2131_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 ) +return ret; + +if (buf[PCF2131_REG_CTRL3 ] &0x04 ) +puts ("### Warning: RTC Low Voltage - date/time not reliable\n" ); + + tm->tm_sec =bcd2bin (buf[PCF2131_REG_SC ] &0x7F ); + tm->tm_min =bcd2bin (buf[PCF2131_REG_MN ] &0x7F ); + tm->tm_hour =bcd2bin (buf[PCF2131_REG_HR ] &0x3F ); + tm->tm_mday =bcd2bin (buf[PCF2131_REG_DM ] &0x3F ); + tm->tm_mon =bcd2bin (buf[PCF2131_REG_MO ] &0x1F ); + tm->tm_year =bcd2bin (buf[PCF2131_REG_YR ]) +1900 ; +if (tm->tm_year <1970 ) + tm->tm_year +=100 ;/* assume we are in 1970...2069 */ + tm->tm_wday = buf[PCF2131_REG_DW ] &0x07 ; + tm->tm_yday =0 ; + tm->tm_isdst =0 ; + +debug ("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n" , + tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + +return ret; +} + +static int pcf2131_rtc_reset (struct udevice *dev) +{ +/*Doing nothing here*/ + +return 0 ; +} + +static const struct rtc_ops pcf2131_rtc_ops = { + .get = pcf2131_rtc_get, + .set = pcf2131_rtc_set, + .reset = pcf2131_rtc_reset, + .read = pcf2131_rtc_read, + .write = pcf2131_rtc_write, +}; + +static const struct udevice_id pcf2131_rtc_ids[] = { + { .compatible ="nxp,pcf2131" }, + { } +}; + +U_BOOT_DRIVER (rtc_pcf2131) = { + .name ="rtc-pcf2131" , + .id =UCLASS_RTC , + .of_match = pcf2131_rtc_ids, + .ops = &pcf2131_rtc_ops, +}; --
Quoted 2 lines
2.37.1
Regards,
Peng.
RE: [PATCH v1 3/3] drivers: rtc: add pcf2131 rtc driver
Quoted 78 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2023年5月31日 9:35
To: Joy Zou <[email protected]>; Peng Fan <[email protected]>; Ye Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: dl-uboot-imx <[email protected]>; [email protected]
Subject: Re: [PATCH v1 3/3] drivers: rtc: add pcf2131 rtc driverQuoted 7 lines · Joy Zou
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
Adding support for pcf2131 RTC chip.
Quoted 8 lines
The pcf2131 is similar to the pcf2127. The driver support rtc register read/write by using rtc cmd and rtc date set/get by using date cmd.
Signed-off-by Joy Zou <[email protected]>--- drivers/rtc/Kconfig | 10 +++ drivers/rtc/Makefile | 1 + drivers/rtc/pcf2131.c | 189++++++++++++++++++++++++++++++++++++++++++
drivers/rtc/Kconfig config RTC_PCF2127 · line 64
Quoted 9 lines
3 files changed, 200 insertions(+)create mode 100644
drivers/rtc/pcf2131.cdrivers/rtc/Kconfig index renamed from drivers/rtc/Kconfig +0
-0
23173139e0..507dc6cbcb100644drivers/rtc/Kconfig +0
-0@@ -64,6 +64,16 @@ config RTC_PCF2127 has a selectable I2C-bus or SPI-bus, a backup batteryswitch-over circuit, a
drivers/rtc/Kconfig config RTC_PCF2127 · line 65
Quoted 1 line
drivers/rtc/Kconfig +0
-0programmable watchdog function, a timestamp function, andmany other features.
drivers/rtc/Kconfig config RTC_PCF2127
Quoted 6 lines
drivers/rtc/Kconfig +5
-0+config RTC_PCF2131 + bool "Enable PCF2131 driver" + depends on DM_RTC + help + The PCF2131 is a CMOS Real Time Clock (RTC) and calendar withan integrated
drivers/rtc/Kconfig config RTC_PCF2127 · line 71
Quoted 1 line
drivers/rtc/Kconfig +1
-0+ Temperature Compensated Crystal (Xtal) Oscillator (TCXO) and a32.768 kHz quartz
drivers/rtc/Kconfig config RTC_PCF2127 · line 72
Quoted 1 line
drivers/rtc/Kconfig +1
-0+ crystal optimized for very high accuracy and very low powerconsumption. The PCF2127
drivers/rtc/Kconfig config RTC_PCF2127 · line 73
Quoted 1 line
drivers/rtc/Kconfig +1
-0+ has a selectable I2C-bus or SPI-bus, a backup battery switch-overcircuit, a
drivers/rtc/Kconfig config RTC_PCF2127 · line 74
Quoted 1 line
drivers/rtc/Kconfig +1
-0+ programmable watchdog function, a timestamp function, andmany other features.
Quoted 22 lines
drivers/rtc/Kconfig +1
-0+ config RTC_DS1307 bool "Enable DS1307 driver" depends on DM_RTCdrivers/rtc/Makefile index renamed from drivers/rtc/Makefile +0
-0
308fab8da9..722f2be98f100644drivers/rtc/Makefile +1
-0@@ -27,6 +27,7 @@ obj-$(CONFIG_RTC_MV) += mvrtc.o obj-$(CONFIG_RTC_MXS) += mxsrtc.o obj-$(CONFIG_RTC_PCF8563) += pcf8563.o obj-$(CONFIG_RTC_PCF2127) += pcf2127.o +obj-$(CONFIG_RTC_PCF2131) += pcf2131.o obj-$(CONFIG_RTC_PL031) += pl031.o obj-$(CONFIG_RTC_PT7C4338) += pt7c4338.o obj-$(CONFIG_RTC_RV3028) += rv3028.o diff --git
a/drivers/rtc/pcf2131.cb/drivers/rtc/pcf2131.cnew file mode 100644 index 0000000000..8b9c17a2c8drivers/rtc/pcf2131.c new file +1
-0@@ -0,0 +1,189 @@ +// SPDX-License-Identifier: GPL-2.0+
Quoted 8 lines
drivers/rtc/pcf2131.c line 8
Quoted 6 lines
drivers/rtc/pcf2131.c new file +6
-0+/* +* The NXP PCF2131 RTC uboot driver. +* Copyright 2023 NXP +* Date & Time support for PCF2131 RTC */ + +/* #define DEBUG */ Drop this line.
Okay. Have dropped in patch v2.
Quoted 59 lines
Quoted 43 lines
drivers/rtc/pcf2131.c new file +42
-0+ +#include <common.h> +#include <command.h> +#include <dm.h> +#include <i2c.h> +#include <log.h> +#include <rtc.h> + +#define PCF2131_REG_CTRL1 0x00 +#define PCF2131_BIT_CTRL1_STOP BIT(5) +#define PCF2131_BIT_CTRL1_100TH_S_DIS BIT(4) +#define PCF2131_REG_CTRL2 0x01 +#define PCF2131_REG_CTRL3 0x02 +#define PCF2131_REG_SR_RESET 0x05 +#define PCF2131_SR_VAL_Clr_Pres 0xa4 +#define PCF2131_REG_SC 0x07 +#define PCF2131_REG_MN 0x08 +#define PCF2131_REG_HR 0x09 +#define PCF2131_REG_DM 0x0a +#define PCF2131_REG_DW 0x0b +#define PCF2131_REG_MO 0x0c +#define PCF2131_REG_YR 0x0d + +static int pcf2131_rtc_read (struct udevice *dev,uint offset,u8 +*buffer,uint len) { +struct dm_i2c_chip *chip =dev_get_parent_plat (dev); +struct i2c_msg msg; +int ret; + +/* Set the address of the start register to be read */ + ret =dm_i2c_write (dev, offset,NULL ,0 ); +if (ret <0 ) +return ret; + +/* Read register's data */ + msg.addr = chip->chip_addr; + msg.flags |=I2C_M_RD ; + msg.len = len; + msg.buf = buffer; + +return dm_i2c_xfer (dev, &msg,1 ); } +drivers/rtc/pcf2131.c
Quoted 10 lines
drivers/rtc/pcf2131.c new file +10
-0+static int pcf2131_rtc_lock (struct udevice *dev) { +int ret =0 ; +uchar buf[6 ] = {PCF2131_REG_CTRL1 }; + + ret =pcf2131_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 ) +return ret; + + buf[PCF2131_REG_CTRL1 ] |=PCF2131_BIT_CTRL1_STOP ; + ret = dm_i2c_write(dev, PCF2131_REG_CTRL1,&buf[PCF2131_REG_CTRL1], 1);
drivers/rtc/pcf2131.c
Quoted 5 lines
drivers/rtc/pcf2131.c new file +5
-0+if (ret <0 ) +return ret; + + buf[PCF2131_REG_SR_RESET ] = PCF2131_SR_VAL_Clr_Pres; + ret = dm_i2c_write(dev, PCF2131_REG_SR_RESET,
Quoted 4 lines
&buf[PCF2131_REG_SR_RESET], 1);
drivers/rtc/pcf2131.c line 65
Quoted 1 line
drivers/rtc/pcf2131.c new file +1
-0+return ret;Just "return
dm_i2c_write..." is ok.
Okay. Have changed in patch v2.
Quoted 14 lines
drivers/rtc/pcf2131.c
Quoted 13 lines
drivers/rtc/pcf2131.c new file +12
-0+} + +static int pcf2131_rtc_unlock (struct udevice *dev) { +int ret =0 ; +uchar buf[6 ] = {PCF2131_REG_CTRL1 }; + + ret =pcf2131_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 ) +return ret; + + buf[PCF2131_REG_CTRL1 ] &= ~PCF2131_BIT_CTRL1_STOP ; + ret = dm_i2c_write(dev, PCF2131_REG_CTRL1,&buf[PCF2131_REG_CTRL1], 1);
Quoted 3 lines
drivers/rtc/pcf2131.c line 78
Quoted 1 line
drivers/rtc/pcf2131.c new file +1
-0+return ret;Ditto.
Have changed in patch v2.
Quoted 12 lines
Quoted 12 lines
drivers/rtc/pcf2131.c new file +11
-0+} + +static int pcf2131_rtc_write (struct udevice *dev,uint offset, +const u8 *buffer,uint len) { +int ret =0 ; + + ret =pcf2131_rtc_lock (dev); +if (ret <0 ) +return ret; + + ret =dm_i2c_write (dev, offset, buffer, len);
Quoted 8 lines
drivers/rtc/pcf2131.c line 99
Quoted 5 lines
drivers/rtc/pcf2131.c new file +5
-0+if (ret <0 ) +return ret; + + ret =pcf2131_rtc_unlock (dev); +return ret;Ditto.
Have changed in patch v2.
Quoted 7 lines
drivers/rtc/pcf2131.c
Quoted 5 lines
drivers/rtc/pcf2131.c new file +4
-0+} + +static int pcf2131_rtc_set (struct udevice *dev,const struct rtc_time *tm) +{ > + uchar buf[7] = {0};No need init is to 0?
Have deleted the unnecessary initialization in patch v2
Quoted 21 lines
Quoted 21 lines
drivers/rtc/pcf2131.c new file +20
-0+int i =0 , ret; + +/* hours, minutes and seconds */ + buf[i++] =bin2bcd (tm->tm_sec); + buf[i++] =bin2bcd (tm->tm_min); + buf[i++] =bin2bcd (tm->tm_hour); + buf[i++] =bin2bcd (tm->tm_mday); + buf[i++] = tm->tm_wday &0x07 ; + +/* month, 1 - 12 */ + buf[i++] =bin2bcd (tm->tm_mon); + +/* year */ + buf[i++] =bin2bcd (tm->tm_year %100 ); + + ret =pcf2131_rtc_lock (dev); +if (ret <0 ) +return ret; + +/* write register's data */
Quoted 8 lines
drivers/rtc/pcf2131.c line 130
Quoted 6 lines
drivers/rtc/pcf2131.c new file +6
-0+ ret =dm_i2c_write (dev,PCF2131_REG_SC , buf, i); +if (ret <0 ) +return ret; + + ret =pcf2131_rtc_unlock (dev); +return ret;Just "return
pfc2131_rtc_unlock..." is ok.
Have changed in patch v2.
Quoted 9 lines
drivers/rtc/pcf2131.c line 136
Quoted 7 lines
drivers/rtc/pcf2131.c new file +6
-0+} + +static int pcf2131_rtc_get (struct udevice *dev,struct rtc_time *tm) +{ +int ret =0 ; +uchar buf[16 ] = {PCF2131_REG_CTRL1 };No need initialize buf?
Have deleted the unnecessary initialization in patch v2. Thanks peng!
BR
Joy Zou
Quoted 62 lines
Quoted 8 lines
drivers/rtc/pcf2131.c new file +7
-0+ + ret =pcf2131_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 ) +return ret; + +if (buf[PCF2131_REG_CTRL3 ] &0x04 ) + puts("### Warning: RTC Low Voltage - date/time notdrivers/rtc/pcf2131.c
Quoted 10 lines
drivers/rtc/pcf2131.c new file +10
-0+ reliable\n"); + + tm->tm_sec =bcd2bin (buf[PCF2131_REG_SC ] &0x7F ); + tm->tm_min =bcd2bin (buf[PCF2131_REG_MN ] &0x7F ); + tm->tm_hour =bcd2bin (buf[PCF2131_REG_HR ] &0x3F ); + tm->tm_mday =bcd2bin (buf[PCF2131_REG_DM ] &0x3F ); + tm->tm_mon =bcd2bin (buf[PCF2131_REG_MO ] &0x1F ); + tm->tm_year =bcd2bin (buf[PCF2131_REG_YR ]) +1900 ; +if (tm->tm_year <1970 ) + tm->tm_year +=100 ;/* assume we are in 1970...2069 */
drivers/rtc/pcf2131.c
Quoted 5 lines
drivers/rtc/pcf2131.c new file +5
-0+ tm->tm_wday = buf[PCF2131_REG_DW ] &0x07 ; + tm->tm_yday =0 ; + tm->tm_isdst =0 ; + + debug("Get DATE: %4d-%02d-%02d (wday=%d)TIME: %2d:%02d:%02d\n",
Quoted 32 lines
drivers/rtc/pcf2131.c new file +31
-1+ tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday, + tm->tm_hour, tm->tm_min, tm->tm_sec); + +return ret; +} + +static int pcf2131_rtc_reset (struct udevice *dev) { +/*Doing nothing here*/ + +return 0 ; +} + +static const struct rtc_ops pcf2131_rtc_ops = { + .get = pcf2131_rtc_get, + .set = pcf2131_rtc_set, + .reset = pcf2131_rtc_reset, + .read = pcf2131_rtc_read, + .write = pcf2131_rtc_write, +}; + +static const struct udevice_id pcf2131_rtc_ids[] = { + { .compatible ="nxp,pcf2131" }, + { } +}; + +U_BOOT_DRIVER (rtc_pcf2131) = { + .name ="rtc-pcf2131" , + .id =UCLASS_RTC , + .of_match = pcf2131_rtc_ids, + .ops = &pcf2131_rtc_ops, +}; --Quoted 2 lines
2.37.1
Regards,
Peng.
Quoted 10 lines · Joy Zou
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
The patchset supports pcf2131 rtc.
For the details, please check the patch commit log.Joy Zou (3):
configs: Enable RTC pcf2131 support
imx:imx93_evk: add rtc pcf2131
drivers: rtc: add pcf2131 rtc driver
Please reorder your patches, with drivers as 1st, imx as 2nd, configs as 3rd to avoid bisect issue.
Thanks,
Peng.
Quoted 14 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 + arch/arm/dts/imx93-11x11-evk.dts | 25 +++ arch/arm/dts/imx93.dtsi | 2 +- configs/imx93_11x11_evk_defconfig | 2 +- drivers/rtc/Kconfig | 10 ++ drivers/rtc/Makefile | 1 + drivers/rtc/pcf2131.c | 189 +++++++++++++++++++++++ 7 files changed, 235 insertions(+), 2 deletions(-)create mode 100644
drivers/rtc/pcf2131.c--
2.37.1
Quoted 21 lines
-----Original Message-----
From: Peng Fan (OSS) <[email protected]>
Sent: 2023年5月31日 9:38
To: Joy Zou <[email protected]>; Peng Fan <[email protected]>; Ye Li <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: dl-uboot-imx <[email protected]>; [email protected]
Subject: Re: [PATCH v1 0/3] Add pcf2131 rtc supportQuoted 8 lines · Joy Zou
Caution: This is an external email. Please take care when clicking links or opening attachments. When in doubt, report the message using the 'Report this email' button
The patchset supports pcf2131 rtc.
For the details, please check the patch commit log.
Quoted 7 lines
Quoted 4 lines
Joy Zou (3):
configs: Enable RTC pcf2131 support
imx:imx93_evk: add rtc pcf2131
drivers: rtc: add pcf2131 rtc driverPlease reorder your patches, with drivers as 1st, imx as 2nd, configs as 3rd to avoid bisect issue.
Have reordered the patchset.
Thanks peng!
BR
Joy Zou
Quoted 19 lines
Thanks,
Peng.Quoted 8 lines
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 + arch/arm/dts/imx93-11x11-evk.dts | 25 +++ arch/arm/dts/imx93.dtsi | 2 +- configs/imx93_11x11_evk_defconfig | 2 +- drivers/rtc/Kconfig | 10 ++ drivers/rtc/Makefile | 1 + drivers/rtc/pcf2131.c | 189+++++++++++++++++++++++
Quoted 6 lines
7 files changed, 235 insertions(+), 2 deletions(-)create mode 100644
drivers/rtc/pcf2131.c--
2.37.1