From patchwork Wed Dec 29 12:38:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Hui-R64343 X-Patchwork-Id: 76888 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 B3043B70B3 for ; Wed, 29 Dec 2010 23:44:22 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 039E82814F; Wed, 29 Dec 2010 13:44:10 +0100 (CET) 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 6cVXZn0wXJqu; Wed, 29 Dec 2010 13:44:09 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3E4E228153; Wed, 29 Dec 2010 13:43:56 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 06026280B2 for ; Wed, 29 Dec 2010 13:43:52 +0100 (CET) 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 5vf7XrTH-LD6 for ; Wed, 29 Dec 2010 13:43:50 +0100 (CET) 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 AM1EHSOBE004.bigfish.com (am1ehsobe004.messaging.microsoft.com [213.199.154.207]) by theia.denx.de (Postfix) with ESMTPS id 054922809E for ; Wed, 29 Dec 2010 13:43:47 +0100 (CET) Received: from mail45-am1-R.bigfish.com (10.3.201.253) by AM1EHSOBE004.bigfish.com (10.3.204.24) with Microsoft SMTP Server id 14.1.225.8; Wed, 29 Dec 2010 12:43:47 +0000 Received: from mail45-am1 (localhost.localdomain [127.0.0.1]) by mail45-am1-R.bigfish.com (Postfix) with ESMTP id 62AA05C02C0; Wed, 29 Dec 2010 12:43:47 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h65h) X-Spam-TCS-SCL: 4:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:de01egw02.freescale.net; RD:de01egw02.freescale.net; EFVD:NLI Received: from mail45-am1 (localhost.localdomain [127.0.0.1]) by mail45-am1 (MessageSwitch) id 1293626627177956_31982; Wed, 29 Dec 2010 12:43:47 +0000 (UTC) Received: from AM1EHSMHS006.bigfish.com (unknown [10.3.201.240]) by mail45-am1.bigfish.com (Postfix) with ESMTP id 1ED191BE804C; Wed, 29 Dec 2010 12:43:47 +0000 (UTC) Received: from de01egw02.freescale.net (192.88.165.103) by AM1EHSMHS006.bigfish.com (10.3.207.106) with Microsoft SMTP Server (TLS) id 14.1.225.8; Wed, 29 Dec 2010 12:43:46 +0000 Received: from az33smr02.freescale.net (az33smr02.freescale.net [10.64.34.200]) by de01egw02.freescale.net (8.14.3/8.14.3) with ESMTP id oBTChiKQ020049; Wed, 29 Dec 2010 05:43:44 -0700 (MST) Received: from localhost.localdomain (r64343-desktop.ap.freescale.net [10.192.242.36]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id oBTChSC4001768; Wed, 29 Dec 2010 06:43:42 -0600 (CST) From: Jason Liu To: Date: Wed, 29 Dec 2010 20:38:49 +0800 Message-ID: <1293626331-18644-9-git-send-email-r64343@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1293626331-18644-1-git-send-email-r64343@freescale.com> References: <1293626331-18644-1-git-send-email-r64343@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Subject: [U-Boot] [PATCH v3 6/8] fsl_pmic: add I2C interface support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This patch add I2C interface for fsl_pmic driver support Signed-off-by: Jason Liu --- Changes for v2: - Address the comments from Stefano, - factor out the param_check in pmic_reg for both spi/i2c --- drivers/misc/fsl_pmic.c | 52 ++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/misc/fsl_pmic.c b/drivers/misc/fsl_pmic.c index 5ee1de1..b58854d 100644 --- a/drivers/misc/fsl_pmic.c +++ b/drivers/misc/fsl_pmic.c @@ -22,11 +22,55 @@ #include #include -#include #include #include #include +static int check_param(u32 reg, u32 write) +{ + if (reg > 63 || write > 1) { + printf(" = %d is invalid. Should be less then 63\n", + reg); + return -1; + } + + return 0; +} + +#ifdef CONFIG_FSL_PMIC_I2C +#include +static int init_done; + +u32 pmic_reg(u32 reg, u32 val, u32 write) +{ + unsigned char buf[4] = { 0 }; + u32 ret_val = 0; + + if (check_param(reg, write)) + return -1; + + if (init_done == 0) { + i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); + init_done = 1; + } + + if (write) { + buf[0] = (val >> 16) & 0xff; + buf[1] = (val >> 8) & 0xff; + buf[2] = (val) & 0xff; + if (i2c_write(CONFIG_SYS_FSL_PMIC_I2C_ADDR, reg, 1, buf, 3)) + return -1; + } else { + if (i2c_read(CONFIG_SYS_FSL_PMIC_I2C_ADDR, reg, 1, buf, 3)) { + return -1; + ret_val = buf[0] << 16 | buf[1] << 8 | buf[2]; + } + } + + return ret_val; +} +#else /* SPI interface */ +#include static struct spi_slave *slave; struct spi_slave *pmic_spi_probe(void) @@ -55,11 +99,8 @@ u32 pmic_reg(u32 reg, u32 val, u32 write) return -1; } - if (reg > 63 || write > 1) { - printf(" = %d is invalid. Should be less then 63\n", - reg); + if (check_param(reg, write)) return -1; - } if (spi_claim_bus(slave)) return -1; @@ -87,6 +128,7 @@ u32 pmic_reg(u32 reg, u32 val, u32 write) spi_release_bus(slave); return cpu_to_be32(pmic_rx); } +#endif void pmic_reg_write(u32 reg, u32 value) {