From patchwork Fri Oct 5 08:16:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Majewski?= X-Patchwork-Id: 189429 X-Patchwork-Delegate: sbabic@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3A9702C032D for ; Fri, 5 Oct 2012 18:17:43 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5BCD828087; Fri, 5 Oct 2012 10:17:38 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uUWWSnbT9iyR; Fri, 5 Oct 2012 10:17:38 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 13212280B4; Fri, 5 Oct 2012 10:17:28 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 27C872808F for ; Fri, 5 Oct 2012 10:17:25 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rzub-5TomsI6 for ; Fri, 5 Oct 2012 10:17:24 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) by theia.denx.de (Postfix) with ESMTP id 1C58A28086 for ; Fri, 5 Oct 2012 10:17:15 +0200 (CEST) Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MBE00L3ZUXL89F0@mailout2.samsung.com> for u-boot@lists.denx.de; Fri, 05 Oct 2012 17:17:02 +0900 (KST) X-AuditID: cbfee61a-b7f726d000000ec7-b4-506e977cd511 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id B6.42.03783.C779E605; Fri, 05 Oct 2012 17:17:00 +0900 (KST) Received: from mcdsrvbld02.digital.local ([106.116.37.23]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01 (7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MBE0068VUZYNY10@mmp2.samsung.com> for u-boot@lists.denx.de; Fri, 05 Oct 2012 17:17:00 +0900 (KST) From: Lukasz Majewski To: u-boot@lists.denx.de Date: Fri, 05 Oct 2012 10:16:24 +0200 Message-id: <1349425003-32523-3-git-send-email-l.majewski@samsung.com> X-Mailer: git-send-email 1.7.10 In-reply-to: <1349425003-32523-1-git-send-email-l.majewski@samsung.com> References: <1349425003-32523-1-git-send-email-l.majewski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCJMWRmVeSWpSXmKPExsVy+t9jQd2a6XkBBr92C1u83dvJ7sDocfbO DsYAxigum5TUnMyy1CJ9uwSujFkX/jMVzBepmHPyKXMD4yr+LkZODgkBE4l7x+8xQthiEhfu rWfrYuTiEBKYzihx8exjJghnMZPEvkOf2ECq2AT0JD7ffcoEYosISEj86r/KCFLELLCDUaL5 5FmwImEBD4ne2dNZQGwWAVWJI1t+g8V5BdwkDvVfYIVYJy/x9H4fWJxTwF1i+/tvzCC2EFDN vAeXGCcw8i5gZFjFKJpakFxQnJSea6hXnJhbXJqXrpecn7uJEez3Z1I7GFc2WBxiFOBgVOLh TXiYGyDEmlhWXJl7iFGCg1lJhPdqUl6AEG9KYmVValF+fFFpTmrxIUZpDhYlcd5mj5QAIYH0 xJLU7NTUgtQimCwTB6dUA2PT3TPlX5dL/Y64aPXKi/G9qQ9PGbu9t2zJwUdvMw8cupRk1RLo kb43+5vu8n6mgFQnpkWlAf9nng1Z67bZ13PW0WOKVROCQ+tFAgVfXZq987P7e+534Zwd7EvP zZRZI/v7vAJb3BT3I0ocxkfVluyMF55XeaIuZLrjT4ug4r1VW77JsN5OkVJiKc5INNRiLipO BACh7SPq9wEAAA== Cc: Tom Rini , Kyungmin Park Subject: [U-Boot] [PATCH v2 02/21] pmic:i2c: Add I2C byte order to PMIC framework X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 Signed-off-by: Kyungmin Park --- Changes for v2: - Move byte_order variable to struct pmic --- drivers/misc/pmic_i2c.c | 31 ++++++++++++++++++++++++------- include/pmic.h | 2 ++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/misc/pmic_i2c.c b/drivers/misc/pmic_i2c.c index e74c372..6b1487b 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 (p->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 (p->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 (p->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 (p->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..71b7d13 100644 --- a/include/pmic.h +++ b/include/pmic.h @@ -27,6 +27,7 @@ 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; @@ -47,6 +48,7 @@ struct pmic { const char *name; unsigned char bus; unsigned char interface; + unsigned char byte_order; unsigned char number_of_regs; union hw { struct p_i2c i2c;