From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 02/16] pmic:i2c: Add I2C byte order to PMIC framework
Date: Mon, 17 Sep 2012 11:33:20 +0200 [thread overview]
Message-ID: <5056EE60.2020604@denx.de> (raw)
In-Reply-To: <1347637215-4830-3-git-send-email-l.majewski@samsung.com>
On 14/09/2012 17:40, Lukasz Majewski wrote:
> Since the pmic_reg_read is the u32 value, the order in which bytes
> are placed to form u32 value is important.
>
> This commit adds the reverse (which is default) and normal byte order.
>
> Signed-off-by: Lukasz Majewski <l.majewski@samsung.com>
> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com>
> ---
Hi,
> drivers/misc/pmic_i2c.c | 31 ++++++++++++++++++++++++-------
> include/pmic.h | 3 +++
> 2 files changed, 27 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/misc/pmic_i2c.c b/drivers/misc/pmic_i2c.c
> index e74c372..1aa5b7b 100644
> --- a/drivers/misc/pmic_i2c.c
> +++ b/drivers/misc/pmic_i2c.c
> @@ -40,13 +40,24 @@ int pmic_reg_write(struct pmic *p, u32 reg, u32 val)
>
> switch (pmic_i2c_tx_num) {
> case 3:
> - buf[0] = (val >> 16) & 0xff;
> - buf[1] = (val >> 8) & 0xff;
> - buf[2] = val & 0xff;
> + if (pmic_i2c_byte_order == PMIC_BYTE_ORDER_NORMAL) {
> + buf[2] = (val >> 16) & 0xff;
> + buf[1] = (val >> 8) & 0xff;
> + buf[0] = val & 0xff;
> + } else {
> + buf[0] = (val >> 16) & 0xff;
> + buf[1] = (val >> 8) & 0xff;
> + buf[2] = val & 0xff;
> + }
> break;
> case 2:
> - buf[0] = (val >> 8) & 0xff;
> - buf[1] = val & 0xff;
> + if (pmic_i2c_byte_order == PMIC_BYTE_ORDER_NORMAL) {
> + buf[1] = (val >> 8) & 0xff;
> + buf[0] = val & 0xff;
> + } else {
> + buf[0] = (val >> 8) & 0xff;
> + buf[1] = val & 0xff;
> + }
> break;
> case 1:
> buf[0] = val & 0xff;
> @@ -75,10 +86,16 @@ int pmic_reg_read(struct pmic *p, u32 reg, u32 *val)
>
> switch (pmic_i2c_tx_num) {
> case 3:
> - ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];
> + if (pmic_i2c_byte_order == PMIC_BYTE_ORDER_NORMAL)
> + ret_val = buf[2] << 16 | buf[1] << 8 | buf[0];
> + else
> + ret_val = buf[0] << 16 | buf[1] << 8 | buf[2];
> break;
> case 2:
> - ret_val = buf[0] << 8 | buf[1];
> + if (pmic_i2c_byte_order == PMIC_BYTE_ORDER_NORMAL)
> + ret_val = buf[1] << 8 | buf[0];
> + else
> + ret_val = buf[0] << 8 | buf[1];
> break;
> case 1:
> ret_val = buf[0];
> diff --git a/include/pmic.h b/include/pmic.h
> index 6a05b40..2166f73 100644
> --- a/include/pmic.h
> +++ b/include/pmic.h
> @@ -27,11 +27,13 @@
> enum { PMIC_I2C, PMIC_SPI, };
> enum { I2C_PMIC, I2C_NUM, };
> enum { PMIC_READ, PMIC_WRITE, };
> +enum { PMIC_BYTE_ORDER_REVERSED, PMIC_BYTE_ORDER_NORMAL, };
>
> struct p_i2c {
> unsigned char addr;
> unsigned char *buf;
> unsigned char tx_num;
> + unsigned char byte_order;
I can imagine we could have the same issue with SPI and not only with
I2C. The byte order is not strictly related to the interface type, and I
think this should add to the "struct pmic" instead of the "struct p_i2c".
Regards,
Stefano Babic
--
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
next prev parent reply other threads:[~2012-09-17 9:33 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-14 15:39 [U-Boot] [PATCH 00/16] pmic: Redesign PMIC framework to support multiple instances of devices Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 01/16] pmic:i2c: Handle PMIC I2C transmission comprising of two bytes Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 02/16] pmic:i2c: Add I2C byte order to PMIC framework Lukasz Majewski
2012-09-17 9:33 ` Stefano Babic [this message]
2012-09-17 20:41 ` Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 03/16] pmic:max8997: Switch the MAX8997 PMIC to be used with multibus I2C Lukasz Majewski
2012-09-17 9:36 ` Stefano Babic
2012-09-17 20:46 ` Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 04/16] pmic: Extend PMIC framework to support multiple instances of PMIC devices Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 05/16] pmic: Introduce power_board_init() method at ./lib/board.c file Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 06/16] pmic: Enable power_board_init() support at TRATS Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 07/16] pmic:chrg: Common information about charger and battery (power_chrg.h) Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 08/16] pmic:muic: Support for MUIC built into MAX8997 device Lukasz Majewski
2012-09-17 9:51 ` Stefano Babic
2012-09-17 21:05 ` Lukasz Majewski
2012-10-02 12:49 ` Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 09/16] pmic:fuel-gauge: Support for MAX17042 fuel-gauge Lukasz Majewski
2012-09-14 17:23 ` Tom Rini
2012-09-17 20:59 ` Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 10/16] pmic:max8997: Function for calculating LDO internal register value Lukasz Majewski
2012-09-14 17:24 ` Tom Rini
2012-09-17 20:57 ` Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 11/16] arm:trats:pmic: Default PMIC(MAX8997) initialization for Samsung's TRATS board Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 12/16] arm:trats:pmic: Enable MUIC (MAX8997) at " Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 13/16] arm:trats:pmic: Enable fuel-gauge (MAX17042) " Lukasz Majewski
2012-09-14 17:26 ` Tom Rini
2012-09-17 20:56 ` Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 14/16] pmic:max8997: Support for MAX8997 internal charger control Lukasz Majewski
2012-09-14 15:40 ` [U-Boot] [PATCH 15/16] arm:trats:pmic: Support for charging battery at Samsung's TRATS board Lukasz Majewski
2012-09-14 17:32 ` Tom Rini
2012-09-17 20:55 ` Lukasz Majewski
2012-09-17 21:27 ` Tom Rini
2012-09-14 15:40 ` [U-Boot] [PATCH 16/16] arm:trats:pmic: Power consumption reduction state for " Lukasz Majewski
2012-09-14 17:35 ` [U-Boot] [PATCH 00/16] pmic: Redesign PMIC framework to support multiple instances of devices Tom Rini
2012-09-17 20:49 ` Lukasz Majewski
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=5056EE60.2020604@denx.de \
--to=sbabic@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