From patchwork Thu Mar 12 09:57:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bo Shen X-Patchwork-Id: 449361 X-Patchwork-Delegate: p.marczak@samsung.com 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 DDDAC14010F for ; Thu, 12 Mar 2015 20:57:27 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6389C4A039; Thu, 12 Mar 2015 10:57:25 +0100 (CET) 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 lSXEeh8tr7jj; Thu, 12 Mar 2015 10:57:25 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id CD25BA741D; Thu, 12 Mar 2015 10:57:24 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DC494A741D for ; Thu, 12 Mar 2015 10:57:20 +0100 (CET) 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 qZgEHruYeU20 for ; Thu, 12 Mar 2015 10:57:20 +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 DVREDG01.corp.atmel.com (nasmtp01.atmel.com [192.199.1.245]) by theia.denx.de (Postfix) with ESMTPS id 130044A033 for ; Thu, 12 Mar 2015 10:57:17 +0100 (CET) Received: from sjogate2.atmel.com (10.42.103.223) by DVREDG01.corp.atmel.com (10.42.103.30) with Microsoft SMTP Server id 14.2.347.0; Thu, 12 Mar 2015 03:57:08 -0600 Received: from localhost.localdomain ([10.217.12.46]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id t2C9sQGK003278; Thu, 12 Mar 2015 02:54:26 -0700 (PDT) From: Bo Shen To: Date: Thu, 12 Mar 2015 17:57:07 +0800 Message-ID: <1426154227-27517-1-git-send-email-voice.shen@atmel.com> X-Mailer: git-send-email 2.3.0 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [RFC PATCH] PMIC: add act8865 series support X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Add Active-Semi act8865 series PMU support. Signed-off-by: Bo Shen --- drivers/power/Makefile | 1 + drivers/power/act8865.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++ include/act8865.h | 54 +++++++++++++++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 drivers/power/act8865.c create mode 100644 include/act8865.h diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 2145652..0c2a8cf 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -5,6 +5,7 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-$(CONFIG_ACT8865_POWER) += act8865.o obj-$(CONFIG_AS3722_POWER) += as3722.o obj-$(CONFIG_AXP152_POWER) += axp152.o obj-$(CONFIG_AXP209_POWER) += axp209.o diff --git a/drivers/power/act8865.c b/drivers/power/act8865.c new file mode 100644 index 0000000..c36f7bd --- /dev/null +++ b/drivers/power/act8865.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2015 Atmel Corporation + * Bo Shen + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include + +static int act8865_read(u32 reg, uchar *val) +{ + return i2c_read(ACT8865_I2C_ADDR, reg, 1, val, 1); +} + +static int act8865_write(u32 reg, uchar val) +{ + return i2c_write(ACT8865_I2C_ADDR, reg, 1, &val, 1); +} + +int act8865_disable_i2c_interface(void) +{ + uchar val; + + /* Check the I2C interface is disabled or not */ + if (act8865_read(ACT8865_SYS_CONTROL0, &val)) { + debug("ACT8865: i2c interface has been disabled\n"); + return 0; + } + + /* + * As the ACT8865 don't have ID register, so we try one by one + * to disable the exist chips (303, 304, 305) in this series. + */ + + /* Try to disable ACT8865QI303 */ + act8865_write(0x0B, 0xE9); + act8865_write(0x02, 0x07); + if (act8865_write(0x03, 0x01)) { + debug("ACT8865: subtype 303 has been disabled\n"); + return 0; + } + + /* Try to disable ACT8865QI304 */ + act8865_write(0x0B, 0xEE); + act8865_write(0x02, 0x07); + if (act8865_write(0x03, 0x01)) { + debug("ACT8865: subtype 304 has been disabled\n"); + return 0; + } + + /* Try to disable ACT8865QI305 */ + act8865_write(0x0B, 0xEE); + act8865_write(0x02, 0x07); + if (act8865_write(0x03, 0x01)) { + debug("ACT8865: subtype 305 has been disabled\n"); + return 0; + } + + debug("ACT8865: the chip can not be disabled\n"); + + return 0; +} + +int act8865_enable_ldo_output(enum act8865_ldo ldo, enum act8865_volt volt) +{ + u32 conf_reg, ctrl_reg; + uchar val; + + switch (ldo) { + case ACT8865_LDO_REG4: + conf_reg = ACT8865_REG4_CONFIG0; + ctrl_reg = ACT8865_REG4_CONTROL; + break; + + case ACT8865_LDO_REG5: + conf_reg = ACT8865_REG5_CONFIG0; + ctrl_reg = ACT8865_REG5_CONTROL; + break; + + case ACT8865_LDO_REG6: + conf_reg = ACT8865_REG6_CONFIG0; + ctrl_reg = ACT8865_REG6_CONTROL; + break; + + case ACT8865_LDO_REG7: + conf_reg = ACT8865_REG7_CONFIG0; + ctrl_reg = ACT8865_REG7_CONTROL; + break; + default: + error("ACT8865: unsupported LDO\n"); + return -1; + } + + /* Set the LDO output voltage */ + act8865_write(conf_reg, 0x18); + /* Enable the LDO */ + act8865_read(ctrl_reg, &val); + val |= ACT8865_OUTPUT_ENABLE; + act8865_write(ctrl_reg, val); + + return 0; +} diff --git a/include/act8865.h b/include/act8865.h new file mode 100644 index 0000000..f6053ac --- /dev/null +++ b/include/act8865.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2015 Atmel Corporation + * Bo Shen + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#define ACT8865_SYS_CONTROL0 0x00 +#define ACT8865_SYS_CONTROL1 0x01 + +#define ACT8865_REG1_CONFIG0 0x20 +#define ACT8865_REG1_CONFIG1 0x21 +#define ACT8865_REG1_CONTROL 0x22 + +#define ACT8865_REG2_CONFIG0 0x30 +#define ACT8865_REG2_CONFIG1 0x31 +#define ACT8865_REG2_CONTROL 0x32 + +#define ACT8865_REG3_CONFIG0 0x40 +#define ACT8865_REG3_CONFIG1 0x41 +#define ACT8865_REG3_CONTROL 0x42 + +#define ACT8865_REG4_CONFIG0 0x50 +#define ACT8865_REG4_CONTROL 0x51 + +#define ACT8865_REG5_CONFIG0 0x54 +#define ACT8865_REG5_CONTROL 0x55 + +#define ACT8865_REG6_CONFIG0 0x60 +#define ACT8865_REG6_CONTROL 0x61 + +#define ACT8865_REG7_CONFIG0 0x64 +#define ACT8865_REG7_CONTROL 0x65 + +#define ACT8865_OUTPUT_ENABLE (0x01 << 7) + +#define ACT8865_I2C_ADDR 0x5B + +enum act8865_ldo { + ACT8865_LDO_REG4 = 4, + ACT8865_LDO_REG5, + ACT8865_LDO_REG6, + ACT8865_LDO_REG7, +}; + +enum act8865_volt { + ACT8865_1V2_VOLT, + ACT8865_1V8_VOLT, + ACT8865_2V5_VOLT, + ACT8865_3V3_VOLT, +}; + +int act8865_enable_ldo_output(enum act8865_ldo ldo, enum act8865_volt volt); +int act8865_disable_i2c_interface(void);