All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [EXT] Re: [PATCH] i2c: pcf2127: fix bug that read wrong time
Date: Thu, 23 May 2019 07:54:20 +0200	[thread overview]
Message-ID: <20190523075420.2167ea2b@jawa> (raw)
In-Reply-To: <0fab1add-727f-51b8-e641-d2c4e2f9e2a0@denx.de>

Hi Heiko,

> Hello Chuanhua Han,
> 
> Am 22.05.2019 um 14:45 schrieb Chuanhua Han:
> > 
> >   
> >> -----Original Message-----
> >> From: Lukasz Majewski <lukma@denx.de>
> >> Sent: 2019年5月22日 19:32
> >> To: Chuanhua Han <chuanhua.han@nxp.com>
> >> Cc: hs at denx.de; u-boot at lists.denx.de; Biwen Li <biwen.li@nxp.com>;
> >> sjg at chromium.org; Stefano Babic <sbabic@denx.de>
> >> Subject: Re: [EXT] Re: [PATCH] i2c: pcf2127: fix bug that read
> >> wrong time
> >>
> >> On Wed, 22 May 2019 09:31:35 +0000
> >> Chuanhua Han <chuanhua.han@nxp.com> wrote:
> >>  
> >>>> -----Original Message-----
> >>>> From: Lukasz Majewski <lukma@denx.de>
> >>>> Sent: 2019年5月22日 16:41
> >>>> To: Chuanhua Han <chuanhua.han@nxp.com>
> >>>> Cc: hs at denx.de; u-boot at lists.denx.de; Biwen Li
> >>>> <biwen.li@nxp.com>; sjg at chromium.org; Stefano Babic
> >>>> <sbabic@denx.de> Subject: Re: [EXT] Re: [PATCH] i2c: pcf2127:
> >>>> fix bug that read wrong time
> >>>>
> >>>> Hi Chuanhua,
> >>>>  
> >>>>>> -----Original Message-----
> >>>>>> From: Lukasz Majewski <lukma@denx.de>
> >>>>>> Sent: 2019年5月22日 15:16
> >>>>>> To: Chuanhua Han <chuanhua.han@nxp.com>
> >>>>>> Cc: hs at denx.de; u-boot at lists.denx.de; Biwen Li
> >>>>>> <biwen.li@nxp.com>; sjg at chromium.org
> >>>>>> Subject: [EXT] Re: [PATCH] i2c: pcf2127: fix bug that read
> >>>>>> wrong time
> >>>>>>
> >>>>>> Hi Chuanhua,
> >>>>>>  
> >>>>>>> Because i2c driver does not generate a stop bit when reading
> >>>>>>> registers of pcf2127  
> >>>>>>
> >>>>>> The change (in the common i2c code) is rather large when
> >>>>>> considering the description above.
> >>>>>>
> >>>>>> Could you write a more detailed patch description? Is this only
> >>>>>> the problem with i2c in DM?  
> >>>>> OK, This is a problem with the i2c transport framework. After
> >>>>> writing the register address that you want to read, the stop
> >>>>> signal is missing before reading the register data.  
> >>>>>>
> >>>>>> Is the same code (as introduced in this commit) available in
> >>>>>> Linux kernel?  
> >>>>> The kernel does not have such a problem  
> >>>>
> >>>> Do you know maybe why such issue is not present on Linux
> >>>> kernel?  
> >>> The kernel code is encapsulated when reading the pcf2127 register,
> >>> which separates the read and write, thus generating a stop signal
> >>> before reading the register. Eg: Here is the wrapper made by the
> >>> kernel code: static int pcf2127_i2c_read(void *context, const void
> >>> *reg, size_t reg_size, void *val, size_t val_size) {
> >>>          struct device *dev = context;
> >>>          struct i2c_client *client = to_i2c_client(dev);
> >>>          int ret;
> >>>
> >>>          if (WARN_ON(reg_size != 1))
> >>>                  return -EINVAL;
> >>>
> >>>          ret = i2c_master_send(client, reg, 1);
> >>>          if (ret != 1)
> >>>                  return ret < 0 ? ret : -EIO;
> >>>
> >>>          ret = i2c_master_recv(client, val, val_size);
> >>>          if (ret != val_size)
> >>>                  return ret < 0 ? ret : -EIO;
> >>>
> >>>          return 0;
> >>> }  
> >>
> >> That was my point - the same shall be done in the pcf2127 driver.
> >> This is a slow device, so we can afford for this.  
> > There is no similar api in the uboot code to split the read data
> > into the address of the send register and receive the data. Uboot
> > encapsulates the transmit register address and the read data, so no
> > stop signal is generated.  
> 
> If this API is missing, please introduce it. But not in one big patch
> instead split it into:
> 
> - introduce I2C_M_RD_NEED_STOP_BIT
> 
> - support flag I2C_M_RD_NEED_STOP_BIT in driver drivers/i2c/mxc_i2c.c
> 
>    or may we need a more common approach to this?
> 
> - pcf2127 driver changes
> 
> Also, as Lukasz mentioned, provide commit messages with more
> information, what you do and why.

Verbose commit messages help with understanding the _real_ problem
being solved by the patch. Also are helpful in the future as a
documentation and reference.

> 
> >>  
> >>>>  
> >>>>>> How the error is reproduced? What are the symptoms of it?  
> >>>>> You can use the i2c command to read the register data of
> >>>>> pcf2127.  
> >>>>
> >>>> So the problem is with using "i2c ..." commands from U-Boot
> >>>> prompt?  
> >>> Yes,but adding debugging to the rtc driver is also the same
> >>> problem  
> >>>>  
> >>>>> You will find that you want to read the address 0 of the
> >>>>> register, but the data of the 1 address is read, and the data
> >>>>> read later will be offset.  
> >>>>
> >>>> As fair as I can tell the pcf2127 has its own DM aware driver at
> >>>> driver/rtc/pcf2127.c.
> >>>>
> >>>> Is this driver broken so you need to modify the generic i.MX I2C
> >>>> code? Have you tried to test this driver on your setup?  
> >>> Pcf2127 driver also has problems, has been modified, need i2c
> >>> general code to support  
> >>
> >> Just one remark the mxc_i2c.c is IMX specific I2C code. Not the
> >> generic one.  
> > ok  
> >>
> >> Moreover, it looks like the same approach (first send, then read)
> >> is performed in the pcf2127 driver at pcf2127_rtc_get() function.
> >>
> >> I think that the driver shall be first thoroughly checked, then
> >> fixes shall be added to it.  
> 
> I have no such device, so hard to say ... and as Lukasz alread
> mentioned the driver seems to make such an approach:
> 
>   52 static int pcf2127_rtc_get(struct udevice *dev, struct rtc_time
> *tm) 53 {
>   54         int ret = 0;
>   55         uchar buf[10] = { PCF2127_REG_CTRL1 };
>   56
>   57         ret = dm_i2c_write(dev, PCF2127_REG_CTRL1, buf, 1);
>   58         if (ret < 0)
>   59                 return ret;
>   60         ret = dm_i2c_read(dev, PCF2127_REG_CTRL1, buf,
> sizeof(buf)); 61         if (ret < 0)
>   62                 return ret;
> 

I would prefer to fix the issue in the driver itself. Only when it is
not possible we shall introduce extra flags and modify the common I2C
code.

> 
> It seems there are currently no real users of this driver:
> 
> pollux:u-boot hs [master] $ grep -lr RTC_PCF2127 .
> ./drivers/rtc/Kconfig
> ./drivers/rtc/Makefile
> pollux:u-boot hs [master] $
> 
> I added Meng Yi to cc, as he is the author of this driver. May he
> can say here more... at last I hope, the driver worked for him.
> 
> bye,
> Heiko




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/20190523/91a1ce26/attachment.sig>

  reply	other threads:[~2019-05-23  5:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-22  7:05 [U-Boot] [PATCH] i2c: pcf2127: fix bug that read wrong time Chuanhua Han
2019-05-22  7:16 ` Lukasz Majewski
2019-05-22  8:28   ` [U-Boot] [EXT] " Chuanhua Han
2019-05-22  8:40     ` Lukasz Majewski
2019-05-22  9:31       ` Chuanhua Han
2019-05-22 11:31         ` Lukasz Majewski
2019-05-22 12:45           ` Chuanhua Han
2019-05-23  3:29             ` Heiko Schocher
2019-05-23  5:54               ` Lukasz Majewski [this message]
2019-05-23  6:06                 ` Heiko Schocher
2019-05-23 10:28                 ` Chuanhua Han
2019-05-23 10:14               ` 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=20190523075420.2167ea2b@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.