From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] rtc: pcf2127: Fixed bug with rtc settings and getting error time
Date: Tue, 18 Jun 2019 10:06:25 +0200 [thread overview]
Message-ID: <20190618100625.47dcd662@jawa> (raw)
In-Reply-To: <20190617131241.47124-2-chuanhua.han@nxp.com>
Hi Chuanhua,
> The previous pcf2127 RTC chip could not read and set the correct time.
> When reading the data of internal registers, the read address was the
> value of register plus 1. This is because this chip requires the host
> to send a stop signal after setting the register address and before
> reading the register data.
>
> This patch sets the DM_I2C_CHIP_ADDR_STOP flag in order to
> generate a stop signal and fixes the bug of the original read and
> write time.
Thank you for the patch. It now looks far more better than the previous
versions.
It is not using generic flag and can be reused by other ICs with
similar issues.
Let's wait for Heiko's opinion.
Reviewed-by: Lukasz Majewski <lukma@denx.de>
>
> Signed-off-by: Biwen Li <biwen.li@nxp.com>
> Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
> ---
> Changes in v4:
> - Replace DM_I2C_CHIP_RD_NO_I2C_SETUP_OFFSET with
> DM_I2C_CHIP_ADDR_STOP.
>
> Changes in v3:
> - When the rtc time is obtained, the address of the set
> register is separated from the read data.
>
> Changes in v2:
> - Split the original patch into 3 patches
> - Add detailed description information for each patch
>
> drivers/rtc/pcf2127.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/rtc/pcf2127.c b/drivers/rtc/pcf2127.c
> index dcf0340b4d..65794b98e6 100644
> --- a/drivers/rtc/pcf2127.c
> +++ b/drivers/rtc/pcf2127.c
> @@ -24,12 +24,9 @@
>
> static int pcf2127_rtc_set(struct udevice *dev, const struct
> rtc_time *tm) {
> - uchar buf[8];
> + uchar buf[7] = {0};
> int i = 0, ret;
>
> - /* start register address */
> - buf[i++] = PCF2127_REG_SC;
> -
> /* hours, minutes and seconds */
> buf[i++] = bin2bcd(tm->tm_sec);
> buf[i++] = bin2bcd(tm->tm_min);
> @@ -44,7 +41,7 @@ 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_CTRL1, buf, sizeof(buf));
> + ret = dm_i2c_write(dev, PCF2127_REG_SC, buf, i);
>
> return ret;
> }
> @@ -54,9 +51,12 @@ static int pcf2127_rtc_get(struct udevice *dev,
> struct rtc_time *tm) int ret = 0;
> uchar buf[10] = { PCF2127_REG_CTRL1 };
>
> - ret = dm_i2c_write(dev, PCF2127_REG_CTRL1, buf, 1);
> + /* Set the address of the start register to be read */
> + ret = dm_i2c_write(dev, PCF2127_REG_CTRL1, NULL, 0);
> if (ret < 0)
> return ret;
> +
> + /* Read register's data */
> ret = dm_i2c_read(dev, PCF2127_REG_CTRL1, buf, sizeof(buf));
> if (ret < 0)
> return ret;
> @@ -90,6 +90,13 @@ static int pcf2127_rtc_reset(struct udevice *dev)
> return 0;
> }
>
> +static int pcf2127_probe(struct udevice *dev)
> +{
> + i2c_set_chip_flags(dev, DM_I2C_CHIP_ADDR_STOP);
> +
> + return 0;
> +}
> +
> static const struct rtc_ops pcf2127_rtc_ops = {
> .get = pcf2127_rtc_get,
> .set = pcf2127_rtc_set,
> @@ -104,6 +111,7 @@ static const struct udevice_id pcf2127_rtc_ids[]
> = { U_BOOT_DRIVER(rtc_pcf2127) = {
> .name = "rtc-pcf2127",
> .id = UCLASS_RTC,
> + .probe = pcf2127_probe,
> .of_match = pcf2127_rtc_ids,
> .ops = &pcf2127_rtc_ops,
> };
Best regards,
Lukasz Majewski
--
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190618/fdb3ff34/attachment.sig>
next prev parent reply other threads:[~2019-06-18 8:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-17 13:12 [U-Boot] [PATCH 1/2] dm: i2c: Add a flag that need generate stop bit Chuanhua Han
2019-06-17 13:12 ` [U-Boot] [PATCH 2/2] rtc: pcf2127: Fixed bug with rtc settings and getting error time Chuanhua Han
2019-06-18 8:06 ` Lukasz Majewski [this message]
2019-06-18 8:18 ` Heiko Schocher
2019-06-24 4:48 ` [U-Boot] [EXT] " Chuanhua Han
2019-06-18 8:06 ` [U-Boot] [PATCH 1/2] dm: i2c: Add a flag that need generate stop bit Lukasz Majewski
2019-06-24 4:48 ` [U-Boot] [EXT] " Chuanhua Han
2019-07-06 17:16 ` Simon Glass
2019-07-07 14:09 ` Chuanhua Han
-- strict thread matches above, loose matches on Subject: below --
2019-05-30 10:31 [U-Boot] [PATCH 1/2] dm: i2c: Add a flag that not call i2c_setup_offset Chuanhua Han
2019-05-30 10:31 ` [U-Boot] [PATCH 2/2] rtc: pcf2127: Fixed bug with rtc settings and getting error time Chuanhua Han
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190618100625.47dcd662@jawa \
--to=lukma@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox