From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 04/11] pmic: dm: Rewrite pmic_reg_{read|write|clrsetbits} to support 3 bytes transmissions
Date: Mon, 14 May 2018 11:47:14 +0200 [thread overview]
Message-ID: <20180514114714.5bcf6140@jawa> (raw)
In-Reply-To: <CAPnjgZ0q_LuSp3XjE=_OV70hZhp6f9egn7MS7Rh51OV8ThQOEA@mail.gmail.com>
Hi Simon,
> Hi Lukasz,
>
> On 7 May 2018 at 06:26, Lukasz Majewski <lukma@denx.de> wrote:
> > This commit provides support for transmissions larger than 1 byte
> > for PMIC devices used with DM (e.g. MC34708 from NXP).
> >
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> >
> > ---
> >
> > Changes in v2:
> > - pmic_reg_* fixes to use uclass private structure
> >
> > drivers/power/pmic/pmic-uclass.c | 44
> > +++++++++++++++++++++++++++++----------- 1 file changed, 32
> > insertions(+), 12 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> with comments below
>
> > diff --git a/drivers/power/pmic/pmic-uclass.c
> > b/drivers/power/pmic/pmic-uclass.c index 88669533bd..c149b84a68
> > 100644 --- a/drivers/power/pmic/pmic-uclass.c
> > +++ b/drivers/power/pmic/pmic-uclass.c
> > @@ -131,23 +131,36 @@ int pmic_write(struct udevice *dev, uint reg,
> > const uint8_t *buffer, int len)
> >
> > int pmic_reg_read(struct udevice *dev, uint reg)
> > {
> > - u8 byte;
> > + struct dm_pmic_info *pmic_info = dev_get_uclass_priv(dev);
> > + int tx_num = pmic_info->trans_len;
>
> Can you use trans_len instead of tx_num, which is confusing?
Ok.
>
> > + u32 val = 0;
> > int ret;
> >
> > - debug("%s: reg=%x", __func__, reg);
> > - ret = pmic_read(dev, reg, &byte, 1);
> > - debug(", value=%x, ret=%d\n", byte, ret);
> > + if (tx_num < 1 || tx_num > sizeof(val)) {
> > + printf("Wrong transmission size [%d]\n", tx_num);
>
> debug()
>
> > + return -EINVAL;
> > + }
> > +
> > + debug("%s: reg=%x tx_num:%d", __func__, reg, tx_num);
> > + ret = pmic_read(dev, reg, (uint8_t *)&val, tx_num);
>
> This is assuming little-endian, isn't it? I think you need to build up
> the number in a loop 8 bits at a time, or use some sort of unaligned
> function.
This is fixed in the latter patch (mc34708 PMIC support).
[PATCH v2 05/11] pmic: dm: Add support for MC34708 for PMIC DM
The part:
buf[0] = buff[2];
buf[1] = buff[1];
buf[2] = buff[0];
Is responsible for byte swap in this particular device.
This code performs similar operation when compared with old PMIC driver:
pmic_reg_write() in the drivers/power/power_i2c.c
However, the new DM model looks a bit better, as we do need to
implement only the conversion relevant to the specific PMIC IC.
>
> > + debug(", value=%x, ret=%d\n", val, ret);
> >
> > - return ret ? ret : byte;
> > + return ret ? ret : val;
> > }
> >
> > int pmic_reg_write(struct udevice *dev, uint reg, uint value)
> > {
> > - u8 byte = value;
> > + struct dm_pmic_info *pmic_info = dev_get_uclass_priv(dev);
> > + int tx_num = pmic_info->trans_len;
> > int ret;
> >
> > - debug("%s: reg=%x, value=%x", __func__, reg, value);
> > - ret = pmic_write(dev, reg, &byte, 1);
> > + if (tx_num < 1 || tx_num > sizeof(value)) {
> > + printf("Wrong transmission size [%d]\n", tx_num);
> > + return -EINVAL;
> > + }
> > +
> > + debug("%s: reg=%x, value=%x tx_num:%d", __func__, reg,
> > value, tx_num);
> > + ret = pmic_write(dev, reg, (uint8_t *)&value, tx_num);
> > debug(", ret=%d\n", ret);
> >
> > return ret;
> > @@ -155,15 +168,22 @@ int pmic_reg_write(struct udevice *dev, uint
> > reg, uint value)
> >
> > int pmic_clrsetbits(struct udevice *dev, uint reg, uint clr, uint
> > set) {
> > - u8 byte;
> > + struct dm_pmic_info *pmic_info = dev_get_uclass_priv(dev);
> > + int tx_num = pmic_info->trans_len;
> > + u32 val = 0;
> > int ret;
> >
> > - ret = pmic_reg_read(dev, reg);
> > + if (tx_num < 1 || tx_num > sizeof(val)) {
> > + printf("Wrong transmission size [%d]\n", tx_num);
> > + return -EINVAL;
> > + }
> > +
> > + ret = pmic_read(dev, reg, (uint8_t *)&val, tx_num);
> > if (ret < 0)
> > return ret;
> > - byte = (ret & ~clr) | set;
> >
> > - return pmic_reg_write(dev, reg, byte);
> > + val = (val & ~clr) | set;
> > + return pmic_write(dev, reg, (uint8_t *)&val, tx_num);
> > }
> >
> > static int pmic_pre_probe(struct udevice *dev)
> > --
> > 2.11.0
> >
>
> Regards,
> Simon
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-10 Fax: (+49)-8142-66989-80 Email: wd 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/20180514/60a86dc2/attachment.sig>
next prev parent reply other threads:[~2018-05-14 9:47 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-06 20:25 [U-Boot] [PATCH v2 00/11] pmic: sandbox: Add support for MC34709 PMIC Lukasz Majewski
2018-05-06 20:25 ` [U-Boot] [PATCH v2 01/11] pmic: fsl: Provide some more definitions for MC34708 PMIC Lukasz Majewski
2018-05-06 20:25 ` [U-Boot] [PATCH v2 02/11] pmic: fsl: Define number of bytes sent at once by " Lukasz Majewski
2018-05-13 22:01 ` Simon Glass
2018-05-06 20:26 ` [U-Boot] [PATCH v2 03/11] pmic: Add support for setting transmission length in uclass private data Lukasz Majewski
2018-05-13 22:01 ` Simon Glass
2018-05-06 20:26 ` [U-Boot] [PATCH v2 04/11] pmic: dm: Rewrite pmic_reg_{read|write|clrsetbits} to support 3 bytes transmissions Lukasz Majewski
2018-05-13 22:01 ` Simon Glass
2018-05-14 9:47 ` Lukasz Majewski [this message]
2018-05-06 20:26 ` [U-Boot] [PATCH v2 05/11] pmic: dm: Add support for MC34708 for PMIC DM Lukasz Majewski
2018-05-13 22:01 ` Simon Glass
2018-05-14 10:01 ` Lukasz Majewski
2018-05-06 20:26 ` [U-Boot] [PATCH v2 06/11] pmic: Rewrite the pmic command to not only work with single byte transmission Lukasz Majewski
2018-05-13 22:01 ` Simon Glass
2018-05-06 20:26 ` [U-Boot] [PATCH v2 07/11] sandbox: Rewrite i2c_pmic_emul.c to support PMIC with 3 bytes transmission Lukasz Majewski
2018-05-13 22:02 ` Simon Glass
2018-05-14 10:46 ` Lukasz Majewski
2018-05-06 20:26 ` [U-Boot] [PATCH v2 08/11] sandbox: Enable support for MC34708 PMIC in DTS Lukasz Majewski
2018-05-06 20:35 ` Fabio Estevam
2018-05-07 14:12 ` Lukasz Majewski
2018-05-13 22:02 ` Simon Glass
2018-05-06 20:26 ` [U-Boot] [PATCH v2 09/11] sandbox: Enable MC34708 PMIC support Lukasz Majewski
2018-05-13 22:02 ` Simon Glass
2018-05-06 20:26 ` [U-Boot] [PATCH v2 10/11] sandbox: tests: Exclude common test code (pmic_get) in test/dm/pmic.c Lukasz Majewski
2018-05-13 22:02 ` Simon Glass
2018-05-06 20:26 ` [U-Boot] [PATCH v2 11/11] sandbox: tests: Add tests for mc34708 PMIC device Lukasz Majewski
2018-05-13 22:02 ` Simon Glass
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=20180514114714.5bcf6140@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