Add pcf2131 rtc support
Subsystems (3)
v3 cover Add pcf2131 rtc support
The patchset supports pcf2131 rtc.
For the details, please check the patch commit log.
Joy Zou (3):
drivers: rtc: add pcf2131 rtc driver
imx: imx93_evk: add rtc pcf2131
configs: Enable RTC pcf2131 support
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 ++ arch/arm/dts/imx93-11x11-evk.dts | 25 ++++ configs/imx93_11x11_evk_defconfig | 1 + drivers/rtc/pcf2127.c | 144 +++++++++++++++++++++-- 4 files changed, 165 insertions(+), 13 deletions(-)
Signature · 1 line
2.37.1
PATCH v3 1/3 drivers: rtc: add pcf2131 rtc driver
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.
The pcf2131 is special when write access to time registers. it requires setting the STOP and CPR bits. STOP bit needs to be cleared after time registers are updated.
---
Changes in v3:
1.merge pcf2131 into pcf2127 in order to keep same with kernel.
Changes in v2:
1. delete the unnecessary initialization.
2. retrun directly function insteand of redundancy return ret.
3. delete the unnecessary comment line.
--- drivers/rtc/pcf2127.c | 144 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 131 insertions(+), 13 deletions(-)
drivers/rtc/pcf2127.c +131 -13
@@ -23,6 +23,38 @@#define PCF2127_REG_MO 0x08#define PCF2127_REG_YR 0x09 +#define PCF2131_REG_CTRL1 0x00 +#define PCF2131_BIT_CTRL1_STOP BIT(5) +#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 + +enum { +NXP_CHIP_TYPE_PCF2127 =0 , +NXP_CHIP_TYPE_PCF2129 , +NXP_CHIP_TYPE_PCA2129 , +NXP_CHIP_TYPE_PCF2131 , +NXP_CHIP_TYPE_AMOUNT +}; + +bool is_pcf2131_type (struct udevice *dev) +{ +int type; + + type =dev_get_driver_data (dev); + +if (type ==NXP_CHIP_TYPE_PCF2131 ) +return true; +else +return false; +} +static int pcf2127_rtc_read (struct udevice *dev,uint offset,u8 *buffer,uint len) {struct dm_i2c_chip *chip =dev_get_parent_plat (dev);
@@ -43,10 +75,64 @@ static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint lreturn dm_i2c_xfer (dev, &msg,1 ); } +static int pcf2131_rtc_lock (struct udevice *dev) +{ +int ret =0 ; +uchar buf[6 ] = {PCF2131_REG_CTRL1 }; + + ret =pcf2127_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 ); +if (ret <0 ) +return ret; + + buf[PCF2131_REG_SR_RESET ] = PCF2131_SR_VAL_Clr_Pres; + +return dm_i2c_write (dev,PCF2131_REG_SR_RESET , &buf[PCF2131_REG_SR_RESET ],1 ); +} + +static int pcf2131_rtc_unlock (struct udevice *dev) +{ +int ret =0 ; +uchar buf[6 ] = {PCF2131_REG_CTRL1 }; + + ret =pcf2127_rtc_read (dev,PCF2131_REG_CTRL1 , buf,sizeof (buf)); +if (ret <0 ) +return ret; + + buf[PCF2131_REG_CTRL1 ] &= ~PCF2131_BIT_CTRL1_STOP ; +return dm_i2c_write (dev,PCF2131_REG_CTRL1 , &buf[PCF2131_REG_CTRL1 ],1 ); +} +static int pcf2127_rtc_write (struct udevice *dev,uint offset,const u8 *buffer,uint len) { -return dm_i2c_write (dev, offset, buffer, len); +int ret =0 ; +bool flag; + + flag =is_pcf2131_type (dev); +if (flag) { + ret =pcf2131_rtc_lock (dev); +if (ret <0 ) +return ret; + } + + ret =dm_i2c_write (dev, offset, buffer, len); +if (ret <0 ) { +if (flag) +pcf2131_rtc_unlock (dev); +return ret; + } + +if (flag) { + ret =pcf2131_rtc_unlock (dev); +if (ret <0 ) +return ret; + } +return ret; }static int pcf2127_rtc_set (struct udevice *dev,const struct rtc_time *tm)
@@ -68,7 +154,10 @@ static int pcf2127_rtc_set(struct udevice *dev, const struct rtc_time *tm) buf[i++] =bin2bcd (tm->tm_year %100 );/* write register's data */ - ret =dm_i2c_write (dev,PCF2127_REG_SC , buf, i); +if (is_pcf2131_type (dev)) + ret =pcf2127_rtc_write (dev,PCF2131_REG_SC , buf, i); +else + ret =pcf2127_rtc_write (dev,PCF2127_REG_SC , buf, i);return ret; }
@@ -76,7 +165,8 @@ static int pcf2127_rtc_set(struct udevice *dev, const struct rtc_time *tm)static int pcf2127_rtc_get (struct udevice *dev,struct rtc_time *tm) {int ret =0 ; -uchar buf[10 ] = {PCF2127_REG_CTRL1 }; +bool flag; +uchar buf[14 ] = {PCF2127_REG_CTRL1 }; ret =pcf2127_rtc_read (dev,PCF2127_REG_CTRL1 , buf,sizeof (buf));if (ret <0 )
@@ -85,15 +175,28 @@ static int pcf2127_rtc_get(struct udevice *dev, struct rtc_time *tm)if (buf[PCF2127_REG_CTRL3 ] &0x04 )puts ("### Warning: RTC Low Voltage - date/time not reliable\n" ); - tm->tm_sec =bcd2bin (buf[PCF2127_REG_SC ] &0x7F ); - tm->tm_min =bcd2bin (buf[PCF2127_REG_MN ] &0x7F ); - tm->tm_hour =bcd2bin (buf[PCF2127_REG_HR ] &0x3F ); - tm->tm_mday =bcd2bin (buf[PCF2127_REG_DM ] &0x3F ); - tm->tm_mon =bcd2bin (buf[PCF2127_REG_MO ] &0x1F ); - tm->tm_year =bcd2bin (buf[PCF2127_REG_YR ]) +1900 ; + flag =is_pcf2131_type (dev); +if (flag) { + 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 ; + }else { + tm->tm_sec =bcd2bin (buf[PCF2127_REG_SC ] &0x7F ); + tm->tm_min =bcd2bin (buf[PCF2127_REG_MN ] &0x7F ); + tm->tm_hour =bcd2bin (buf[PCF2127_REG_HR ] &0x3F ); + tm->tm_mday =bcd2bin (buf[PCF2127_REG_DM ] &0x3F ); + tm->tm_mon =bcd2bin (buf[PCF2127_REG_MO ] &0x1F ); + tm->tm_year =bcd2bin (buf[PCF2127_REG_YR ]) +1900 ; + }if (tm->tm_year <1970 ) tm->tm_year +=100 ;/* assume we are in 1970...2069 */ - tm->tm_wday = buf[PCF2127_REG_DW ] &0x07 ; +if (flag) + tm->tm_wday = buf[PCF2131_REG_DW ] &0x07 ; +else + tm->tm_wday = buf[PCF2127_REG_DW ] &0x07 ; tm->tm_yday =0 ; tm->tm_isdst =0 ;
@@ -111,6 +214,19 @@ static int pcf2127_rtc_reset(struct udevice *dev)return 0 ; } +static int pcf2127_probe (struct udevice *dev) +{ +struct udevice *bus, *udev; +struct dm_i2c_chip *chip =dev_get_parent_plat (dev); + +if (is_pcf2131_type (dev)) { + bus =dev_get_parent (dev); +return dm_i2c_probe (bus, chip->chip_addr,0 , &udev); + } + +return 0 ; +} +static const struct rtc_ops pcf2127_rtc_ops = { .get = pcf2127_rtc_get, .set = pcf2127_rtc_set,
@@ -120,9 +236,10 @@ static const struct rtc_ops pcf2127_rtc_ops = { };static const struct udevice_id pcf2127_rtc_ids[] = { - { .compatible ="nxp,pcf2127" }, - { .compatible ="nxp,pcf2129" }, - { .compatible ="nxp,pca2129" }, + { .compatible ="nxp,pcf2127" , .data =NXP_CHIP_TYPE_PCF2127 , }, + { .compatible ="nxp,pcf2129" , .data =NXP_CHIP_TYPE_PCF2129 , }, + { .compatible ="nxp,pca2129" , .data =NXP_CHIP_TYPE_PCA2129 , }, + { .compatible ="nxp,pcf2131" , .data =NXP_CHIP_TYPE_PCF2131 , }, { } };
@@ -131,4 +248,5 @@ U_BOOT_DRIVER(rtc_pcf2127) = { .id = UCLASS_RTC, .of_match = pcf2127_rtc_ids, .ops = &pcf2127_rtc_ops, + .probe = pcf2127_probe, };
Signature · 1 line
2.37.1
Fabio Estevam
reviewerRe: [PATCH v3 1/3] drivers: rtc: add pcf2131 rtc driver
Quoted 1 line · Joy Zou
+bool
is_pcf2131_type(struct udevice *dev)
static bool
drivers/rtc/pcf2127.c static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint l · line 80
Quoted 10 lines
static int
pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint len){ struct dm_i2c_chip *chip = dev_get_parent_plat(dev);drivers/rtc/pcf2127.c +3
-0@@ -43,10 +75,64 @@ static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint lreturn dm_i2c_xfer (dev, &msg,1 ); } +static int pcf2131_rtc_lock (struct udevice *dev) +{ +int ret =0 ;
No need to initialize ret with 0.
drivers/rtc/pcf2127.c static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint l · line 99
Quoted 3 lines
drivers/rtc/pcf2127.c +3
-0+static int pcf2131_rtc_unlock (struct udevice *dev) +{ +int ret =0 ;
Ditto.
drivers/rtc/pcf2127.c static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint l · line 113
Quoted 5 lines
drivers/rtc/pcf2127.c +1
-1static int pcf2127_rtc_write (struct udevice *dev,uint offset,const u8 *buffer,uint len) { -return dm_i2c_write (dev, offset, buffer, len); +int ret =0 ;
Ditto.
RE: [EXT] Re: [PATCH v3 1/3] drivers: rtc: add pcf2131 rtc driver
Quoted 15 lines
-----Original Message-----
From: Fabio Estevam <[email protected]>
Sent: 2024年3月27日 6:10
To: Joy Zou <[email protected]>
Cc: Peng Fan <[email protected]>; Ye Li <[email protected]>; Jacky Bai <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-uboot-imx <[email protected]>; [email protected]
Subject: [EXT] Re: [PATCH v3 1/3] drivers: rtc: add pcf2131 rtc driverCaution: 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
Quoted 5 lines
Quoted 1 line · Joy Zou
+bool
is_pcf2131_type(struct udevice *dev)static bool
Will add static key word!
Quoted 5 lines
Quoted 4 lines
static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8
*buffer, uint len) {
structdm_i2c_chip*chip =dev_get_parent_plat(dev); @@-43,10
Quoted 8 lines
Quoted 1 line
+75,64 @@ static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8
*buffer, uint l
Review
Quoted 4 lines
return dm_i2c_xfer(dev, &msg, 1); }(quoted diff) +2
-0+static int pcf2131_rtc_lock(struct udevice *dev) { + int ret = 0;No need to initialize ret with 0.
Will remove initialization 0.
Quoted 4 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+static int pcf2131_rtc_unlock(struct udevice *dev) { + int ret = 0;
Quoted 8 lines
Ditto.
drivers/rtc/pcf2127.c static int pcf2127_rtc_read(struct udevice *dev, uint offset, u8 *buffer, uint l · line 113
Quoted 4 lines
static int pcf2127_rtc_write(struct udevice *dev, uint offset,
const u8 *buffer, uint len) {drivers/rtc/pcf2127.c +1
-1-return dm_i2c_write (dev, offset, buffer, len); +int ret =0 ;Ditto.
Will remove initialization 0.
Thanks for your comments!
BR
Joy Zou
PATCH v3 2/3 imx: imx93_evk: add rtc pcf2131
In reply to Joy Zousupport rtc pcf2131 for imx93.
---
Changes in v3:
1. remove arch/arm/dts/imx93.dtsi modification because this change have existed.
Changes in v2:
1. use the flag bootph-pre-ram instead of uboot,dm-spl.
--- arch/arm/dts/imx93-11x11-evk-u-boot.dtsi | 8 ++++++++ arch/arm/dts/imx93-11x11-evk.dts | 25 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+)
arch/arm/dts/imx93-11x11-evk-u-boot.dtsi +8 -0
@@ -112,6 +112,10 @@ bootph-some-ram; }; +&lpi2c3 { + bootph-pre-ram; +}; + &{/soc@0/bus@44000000/i2c@44350000/pmic@25} { bootph-pre-ram; bootph-some-ram;
@@ -127,6 +131,10 @@ bootph-some-ram; }; +&pinctrl_lpi2c3 { + bootph-pre-ram; +}; + &fec { phy-reset-gpios = <&pcal6524 16 GPIO_ACTIVE_LOW>; phy-reset-duration = <15>;
arch/arm/dts/imx93-11x11-evk.dts +25 -0
@@ -192,6 +192,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>;
@@ -254,6 +272,13 @@ >; }; + pinctrl_lpi2c3: lpi2c3grp { + fsl,pins = < + MX93_PAD_GPIO_IO28__LPI2C3_SDA 0x40000b9e + MX93_PAD_GPIO_IO29__LPI2C3_SCL 0x40000b9e + >; + }; + pinctrl_fec: fecgrp { fsl,pins = < MX93_PAD_ENET2_MDC__ENET1_MDC 0x57e
Signature · 1 line
2.37.1
Fabio Estevam
reviewerRe: [PATCH v3 2/3] imx: imx93_evk: add rtc pcf2131
Quoted 5 lines · Joy Zou
+&lpi2c3 {
arch/arm/dts/imx93-11x11-evk.dts +4
-0+ #address-cells = <1>; + #size-cells = <0>; + clock-frequency = <400000>; + pinctrl-names = "default", "sleep";
arch/arm/dts/imx93-11x11-evk.dts line 209
Quoted 10 lines
arch/arm/dts/imx93-11x11-evk.dts +10
-0+ 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";
Please submit the RTC support to Linux first, then you can sync the devicetree with Linux in U-Boot.
In the meantime, you can add the RTC support to the -u-boot.dtsi.
Please consider using OF_UPSTREAM available in the U-Boot next branch.
RE: [EXT] Re: [PATCH v3 2/3] imx: imx93_evk: add rtc pcf2131
Quoted 34 lines
-----Original Message-----
From: Fabio Estevam <[email protected]>
Sent: 2024年3月27日 6:14
To: Joy Zou <[email protected]>
Cc: Peng Fan <[email protected]>; Ye Li <[email protected]>; Jacky Bai <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-uboot-imx <[email protected]>; [email protected]
Subject: [EXT] Re: [PATCH v3 2/3] imx:imx93_evk: add rtc pcf2131Caution: 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
Quoted 5 lines · Joy Zou
+&lpi2c3 {
arch/arm/dts/imx93-11x11-evk.dts +4
-0+ #address-cells = <1>; + #size-cells = <0>; + clock-frequency = <400000>; + pinctrl-names = "default", "sleep";arch/arm/dts/imx93-11x11-evk.dts line 209
Quoted 10 lines
arch/arm/dts/imx93-11x11-evk.dts +10
-0+ 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";
Quoted 6 lines
Please submit the RTC support to Linux first, then you can sync the devicetree with Linux in U-Boot.
In the meantime, you can add the RTC support to the
-u-boot.dtsi.Please consider using
OF_UPSTREAMavailable in the U-Boot next branch.
Will submit the RTC support patch to Linux firstly. Thanks for your comments!
BR
Joy Zou
PATCH v3 3/3 configs: Enable RTC pcf2131 support
In reply to Joy ZouEnable CONFIG_RTC_PCF2127 configs to support pcf2131.
---
Changes in v3:
1. Change CONFIG_RTC_PCF2131 into CONFIG_RTC_PCF2127 because the pcf2131 driver have been merged into the pcf2127.
--- configs/imx93_11x11_evk_defconfig | 1 + 1 file changed, 1 insertion(+)
configs/imx93_11x11_evk_defconfig +1 -0
@@ -14,6 +14,7 @@ CONFIG_DEFAULT_DEVICE_TREE="imx93-11x11-evk" CONFIG_SPL_TEXT_BASE=0x2049A000 CONFIG_TARGET_IMX93_11X11_EVK=y CONFIG_SYS_MONITOR_LEN=524288 +CONFIG_RTC_PCF2127=y CONFIG_SPL_SERIAL=y CONFIG_SPL_DRIVERS_MISC=y CONFIG_SPL_STACK=0x20519dd0
Signature · 1 line
2.37.1
Fabio Estevam
reviewerRe: [PATCH v3 3/3] configs: Enable RTC pcf2131 support
Quoted 2 lines · Joy Zou
Enable
CONFIG_RTC_PCF2127configs to support pcf2131.
Subject should be imx93_11x11_evk specific:
imx93_11x11_evk: Add PCF2131 RTC support
RE: [EXT] Re: [PATCH v3 3/3] configs: Enable RTC pcf2131 support
Quoted 16 lines
-----Original Message-----
From: Fabio Estevam <[email protected]>
Sent: 2024年3月27日 6:12
To: Joy Zou <[email protected]>
Cc: Peng Fan <[email protected]>; Ye Li <[email protected]>; Jacky Bai <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; dl-uboot-imx <[email protected]>; [email protected]
Subject: [EXT] Re: [PATCH v3 3/3] configs: Enable RTC pcf2131 supportCaution: 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
Quoted 7 lines
Quoted 2 lines · Joy Zou
Enable
CONFIG_RTC_PCF2127configs to support pcf2131.Subject should be
imx93_11x11_evkspecific:
imx93_11x11_evk: Add PCF2131 RTC support
Will modify the Subject.
Thanks for your comments!
BR
Joy Zou