From: Lukasz Majewski <lukma@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 07/11] sandbox: Rewrite i2c_pmic_emul.c to support PMIC with 3 bytes transmission
Date: Mon, 14 May 2018 12:46:44 +0200 [thread overview]
Message-ID: <20180514124644.74e60363@jawa> (raw)
In-Reply-To: <CAPnjgZ2wa5owKXQZS4EOOVJaT_j-TVWhxb3rUo-9yDw7duABdQ@mail.gmail.com>
Hi Simon,
> Hi Lukasz,
>
> On 7 May 2018 at 06:26, Lukasz Majewski <lukma@denx.de> wrote:
> > This change enables support for MC34708 PMIC in sandbox. Now we can
> > emulate the I2C transfers larger than 1 byte.
> >
> > Notable changes for this driver:
> >
> > - From now on the register number is not equal to index in the
> > buffer, which emulates the PMIC registers
> >
> > - The PMIC register's pool is now dynamically allocated up till
> > 64 regs * 3 bytes each = 192 B
> >
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> >
> > ---
> >
> > Changes in v2:
> > - New patch
> >
> > drivers/power/pmic/i2c_pmic_emul.c | 45
> > ++++++++++++++++++++++++++------------ 1 file changed, 31
> > insertions(+), 14 deletions(-)
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Comments below
>
> >
> > diff --git a/drivers/power/pmic/i2c_pmic_emul.c
> > b/drivers/power/pmic/i2c_pmic_emul.c index c58ebb8825..6f227a92f3
> > 100644 --- a/drivers/power/pmic/i2c_pmic_emul.c
> > +++ b/drivers/power/pmic/i2c_pmic_emul.c
> > @@ -19,8 +19,11 @@
> > * @reg: PMICs registers array
> > */
> > struct sandbox_i2c_pmic_plat_data {
> > - u8 rw_reg;
> > - u8 reg[SANDBOX_PMIC_REG_COUNT];
> > + u8 rw_reg, rw_idx;
> > + u8 reg_count;
> > + u8 trans_len;
> > + u8 buf_size;
> > + u8 *reg;
> > };
> >
> > static int sandbox_i2c_pmic_read_data(struct udevice *emul, uchar
> > chip, @@ -28,16 +31,16 @@ static int
> > sandbox_i2c_pmic_read_data(struct udevice *emul, uchar chip, {
> > struct sandbox_i2c_pmic_plat_data *plat =
> > dev_get_platdata(emul);
> >
> > - if (plat->rw_reg + len > SANDBOX_PMIC_REG_COUNT) {
> > + if (plat->rw_idx + len > plat->buf_size) {
> > pr_err("Request exceeds PMIC register range! Max
> > register: %#x",
> > - SANDBOX_PMIC_REG_COUNT);
> > + plat->reg_count);
> > return -EFAULT;
> > }
> >
> > - debug("Read PMIC: %#x at register: %#x count: %d\n",
> > - (unsigned)chip & 0xff, plat->rw_reg, len);
> > + debug("Read PMIC: %#x at register: %#x idx: %#x count:
> > %d\n",
> > + (unsigned int)chip & 0xff, plat->rw_reg,
> > plat->rw_idx, len);
> >
> > - memcpy(buffer, &plat->reg[plat->rw_reg], len);
> > + memcpy(buffer, plat->reg + plat->rw_idx, len);
>
> Why change this?
For the sandbox_pmic(), which emulates single byte transmission, the
number of registers (rw_reg) is also the index in the pool emulating
the device.
With support for devices having 3 bytes sent at once, the register
number (rw_req) cannot be used as index anymore.
>
> >
> > return 0;
> > }
> > @@ -54,9 +57,10 @@ static int sandbox_i2c_pmic_write_data(struct
> > udevice *emul, uchar chip,
> >
> > /* Set PMIC register for I/O */
> > plat->rw_reg = *buffer;
> > + plat->rw_idx = plat->rw_reg * plat->trans_len;
> >
> > - debug("Write PMIC: %#x at register: %#x count: %d\n",
> > - (unsigned)chip & 0xff, plat->rw_reg, len);
> > + debug("Write PMIC: %#x at register: %#x idx: %#x count:
> > %d\n",
> > + (unsigned int)chip & 0xff, plat->rw_reg,
> > plat->rw_idx, len);
> >
> > /* For read operation, set (write) only chip reg */
> > if (next_is_read)
> > @@ -65,12 +69,12 @@ static int sandbox_i2c_pmic_write_data(struct
> > udevice *emul, uchar chip, buffer++;
> > len--;
> >
> > - if (plat->rw_reg + len > SANDBOX_PMIC_REG_COUNT) {
> > + if (plat->rw_idx + len > plat->buf_size) {
> > pr_err("Request exceeds PMIC register range! Max
> > register: %#x",
> > - SANDBOX_PMIC_REG_COUNT);
> > + plat->reg_count);
> > }
> >
> > - memcpy(&plat->reg[plat->rw_reg], buffer, len);
> > + memcpy(plat->reg + plat->rw_idx, buffer, len);
>
> and this?
>
> >
> > return 0;
> > }
> > @@ -101,20 +105,33 @@ static int sandbox_i2c_pmic_xfer(struct
> > udevice *emul, struct i2c_msg *msg, static int
> > sandbox_i2c_pmic_ofdata_to_platdata(struct udevice *emul) {
> > struct sandbox_i2c_pmic_plat_data *plat =
> > dev_get_platdata(emul);
> > + struct udevice *pmic_dev = dev_get_parent(emul);
> > + struct dm_pmic_info *pmic_info =
> > dev_get_uclass_priv(pmic_dev); const u8 *reg_defaults;
> >
> > debug("%s:%d Setting PMIC default registers\n", __func__,
> > __LINE__);
> > + plat->reg_count = pmic_reg_count(pmic_dev);
> > + plat->trans_len = pmic_info->trans_len;
> > + plat->buf_size = plat->reg_count * plat->trans_len;
> > +
> > + plat->reg = calloc(1, plat->buf_size);
> > + if (!plat->reg) {
> > + pr_err("Canot allocate memory (%d B) for PMIC I2C
> > emulation!\n",
> > + plat->buf_size);
>
> debug()
Ok
>
> > + return -ENOMEM;
> > + }
> >
> > reg_defaults = dev_read_u8_array_ptr(emul, "reg-defaults",
> > -
> > SANDBOX_PMIC_REG_COUNT);
> > + plat->buf_size);
> >
> > if (!reg_defaults) {
> > pr_err("Property \"reg-defaults\" not found for
> > device: %s!", emul->name);
> > + free(plat->reg);
> > return -EINVAL;
> > }
> >
> > - memcpy(&plat->reg, reg_defaults, SANDBOX_PMIC_REG_COUNT);
> > + memcpy(plat->reg, reg_defaults, plat->buf_size);
> >
> > return 0;
> > }
> > --
> > 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/503a5db6/attachment.sig>
next prev parent reply other threads:[~2018-05-14 10:46 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
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 [this message]
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=20180514124644.74e60363@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