From patchwork Wed Dec 22 13:23:50 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: 76406 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 E0244B7082 for ; Thu, 23 Dec 2010 00:30:01 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0F48528146; Wed, 22 Dec 2010 14:29:38 +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 wjzaum7JcXwF; Wed, 22 Dec 2010 14:29:37 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F074028133; Wed, 22 Dec 2010 14:29:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0D4D928136 for ; Wed, 22 Dec 2010 14:29:35 +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 ooFkNFlkCj5h for ; Wed, 22 Dec 2010 14:29:33 +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 TX2EHSOBE006.bigfish.com (tx2ehsobe003.messaging.microsoft.com [65.55.88.13]) by theia.denx.de (Postfix) with ESMTPS id 057ED2810A for ; Wed, 22 Dec 2010 14:29:17 +0100 (CET) Received: from mail139-tx2-R.bigfish.com (10.9.14.254) by TX2EHSOBE006.bigfish.com (10.9.40.26) with Microsoft SMTP Server id 14.1.225.8; Wed, 22 Dec 2010 13:29:16 +0000 Received: from mail139-tx2 (localhost.localdomain [127.0.0.1]) by mail139-tx2-R.bigfish.com (Postfix) with ESMTP id 4390011A816D; Wed, 22 Dec 2010 13:28:58 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h63h) X-Spam-TCS-SCL: 2:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:az33egw02.freescale.net; RD:az33egw02.freescale.net; EFVD:NLI Received: from mail139-tx2 (localhost.localdomain [127.0.0.1]) by mail139-tx2 (MessageSwitch) id 1293024538131383_30633; Wed, 22 Dec 2010 13:28:58 +0000 (UTC) Received: from TX2EHSMHS012.bigfish.com (unknown [10.9.14.247]) by mail139-tx2.bigfish.com (Postfix) with ESMTP id 1C3111318052; Wed, 22 Dec 2010 13:28:58 +0000 (UTC) Received: from az33egw02.freescale.net (192.88.158.103) by TX2EHSMHS012.bigfish.com (10.9.99.112) with Microsoft SMTP Server (TLS) id 14.1.225.8; Wed, 22 Dec 2010 13:28:56 +0000 Received: from az33smr01.freescale.net (az33smr01.freescale.net [10.64.34.199]) by az33egw02.freescale.net (8.14.3/8.14.3) with ESMTP id oBMDSsCQ017486; Wed, 22 Dec 2010 06:28:55 -0700 (MST) Received: from localhost.localdomain (r64343-desktop.ap.freescale.net [10.192.242.36]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id oBMDSoXR007125; Wed, 22 Dec 2010 07:28:53 -0600 (CST) From: Jason Liu To: Date: Wed, 22 Dec 2010 21:23:50 +0800 Message-ID: <1293024231-4897-2-git-send-email-r64343@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1293024231-4897-1-git-send-email-r64343@freescale.com> References: <1293024231-4897-1-git-send-email-r64343@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Subject: [U-Boot] [PATCH 2/3] 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 --- drivers/misc/fsl_pmic.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 files changed, 38 insertions(+), 1 deletions(-) diff --git a/drivers/misc/fsl_pmic.c b/drivers/misc/fsl_pmic.c index 5ee1de1..a54f220 100644 --- a/drivers/misc/fsl_pmic.c +++ b/drivers/misc/fsl_pmic.c @@ -22,11 +22,47 @@ #include #include -#include #include #include #include +#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 (reg > 63 || write > 1) { + printf(" = %d is invalid. Should be less then 63\n", + reg); + 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) @@ -87,6 +123,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) {