public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Stefano Babic <sbabic@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 02/21] pmic:i2c: Add I2C byte order to PMIC framework
Date: Tue, 09 Oct 2012 13:02:53 +0200	[thread overview]
Message-ID: <5074045D.4@denx.de> (raw)
In-Reply-To: <20121009115224.38a5822c@amdc308.digital.local>

On 09/10/2012 11:52, Lukasz Majewski wrote:
> Hi Stefano,
> 
>> On 05/10/2012 10:16, 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 Lucasz,
>>
>>> Changes for v2:
>>> - Move byte_order variable to struct pmic
>>
>> Is the byte reversal you introduce here only another way for the
>> endianess ?
>>
>> It seems to me you have a PMIC whose endianess is different as the
>> SOC's endianess, and that must be changed.
>>
>> I can suppose that "normal byte" and "reverse byte" works only with
>> ARM SOC, as they are (normally, but not always) little endian, but
>> not for example on PowerPC (big endian).
> 
> This procedure was necessary since, some sensor produces output of 2B
> and those bytes are in a big endian.

Right. So we have the endianess of the SOC and the endianess of the
PMIC, and they can differ.

> For simplicity reason I decided to make the switch on received bytes.
> 
> I suppose that witch some luck :-), proper cpu_to_le16|be16 (le32|be32)
> functions can be used to avoid repetition.

I hope so.

> 
> To make the code working at both ARM and PPC we shall use the 
> __BYTE_ORDER == __LITTLE_ENDIAN check, which is CPU dependent. Hence,
> the interpretation of stored data would be consistent from CPU point of
> view.
> 
> To sum up - two options possible:
> 1. Use cpu_to_le|be functions (hack cpu_to_le32 to handle 3B input) 
> 2. Perform switch (as it was done in this patch) with explicit check of 
> __BYTE_ORDER == __LITTLE_ENDIAN.
> 
> I would opt for 1 here.

I vote for 1, too. I think generally in u-boot and kernel there is no
use of the explicit check, but I have not grepped in code.

> 
>>
>> If this is correct, then I think we need a parameter in the structure
>> to indicate the endianess, 
> 
> We need also the endiness of data coming out from sensor as it is
> defined in this patch:
> enum { PMIC_BYTE_ORDER_REVERSED, PMIC_BYTE_ORDER_NORMAL, };
> I admit, that name could be more appropriate here (like
> SENSOR_BYTE_ORDER).

Yes. The name is misleading. Which is "normal" nowadays ?


> 
> In this patch I've added a "byte_order" variable to struct pmic to
> indicate the endiantess of device (I2C connected) to which we are
> talking to. It is per sensor defined (as the struct pmic is)

I think the procedure is correct. The endianess is stored in the pmic
structure, and then calling appropriate cpu_to_le/be function we should
have the bytes in the right order.

> 
> Please feel free to comment other patches, so I could prepare v3 of
> this series :-). 

I will do..

Best 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
=====================================================================

  reply	other threads:[~2012-10-09 11:02 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05  8:16 [U-Boot] [PATCH v2 00/21] pmic: Redesign PMIC framework to support multiple instances of devices Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 01/21] pmic:i2c: Handle PMIC I2C transmission comprising of two bytes Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 02/21] pmic:i2c: Add I2C byte order to PMIC framework Lukasz Majewski
2012-10-09  8:36   ` Stefano Babic
2012-10-09  9:52     ` Lukasz Majewski
2012-10-09 11:02       ` Stefano Babic [this message]
2012-10-05  8:16 ` [U-Boot] [PATCH v2 03/21] pmic:max8997: Switch the MAX8997 PMIC to be used with multibus I2C Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 04/21] pmic: Extend PMIC framework to support multiple instances of PMIC devices Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 05/21] pmic: Introduce power_board_init() method at ./lib/board.c file Lukasz Majewski
2012-10-09  8:54   ` Stefano Babic
2012-10-09 10:25     ` Lukasz Majewski
2012-10-09 11:34       ` Stefano Babic
2012-10-09 18:05         ` Tom Rini
2012-10-10  6:24           ` Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 06/21] pmic: Enable power_board_init() support at TRATS Lukasz Majewski
2012-10-09  8:56   ` Stefano Babic
2012-10-09 10:30     ` Lukasz Majewski
2012-10-09 11:37       ` Stefano Babic
2012-10-09 12:06         ` Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 07/21] pmic:chrg: Common information about charger and battery (power_chrg.h) Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 08/21] pmic: Move pmic related code to ./drivers/power directory Lukasz Majewski
2012-10-09  8:58   ` Stefano Babic
2012-10-09 10:37     ` Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 09/21] pmic: Extend struct pmic to support battery and charger related operations Lukasz Majewski
2012-10-11  7:52   ` Stefano Babic
2012-10-12  7:54     ` Lukasz Majewski
2012-10-18 16:09     ` [U-Boot] [PATCH v2 09/21] pmic: Extend struct pmic to support battery and charger related operations [explanation] Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 10/21] pmic:battery: Support for Trats Battery at PMIC framework Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 11/21] pmic:muic: Support for MUIC built into MAX8997 device Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 12/21] pmic:fuel-gauge: Support for MAX17042 fuel-gauge Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 13/21] pmic:max8997: Function for calculating LDO internal register value Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 14/21] arm:trats:pmic: Default PMIC(MAX8997) initialization for Samsung's TRATS board Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 15/21] arm:trats:pmic: Enable MUIC (MAX8997) at " Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 16/21] arm:trats:pmic: Enable fuel-gauge (MAX17042) " Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 17/21] arm:trats:pmic: Enable battery support " Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 18/21] pmic:max8997: Support for MAX8997 internal charger control Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 19/21] arm:trats:pmic: Power consumption reduction state for Samsung's TRATS board Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 20/21] arm:trats:pmic: Support for charging battery at " Lukasz Majewski
2012-10-05  8:16 ` [U-Boot] [PATCH v2 21/21] pmic: Extend PMIC framework to support battery related commands 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=5074045D.4@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