From patchwork Sun Nov 25 11:39:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Henrik_Nordstr=C3=B6m?= X-Patchwork-Id: 201521 X-Patchwork-Delegate: hs@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 8219D2C007C for ; Sun, 25 Nov 2012 22:39:56 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 411724A025; Sun, 25 Nov 2012 12:39:53 +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 IQFXg71ECzF4; Sun, 25 Nov 2012 12:39:53 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4876C4A029; Sun, 25 Nov 2012 12:39:50 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 926584A037 for ; Sun, 25 Nov 2012 12:39:47 +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 ECbaHAdNb30z for ; Sun, 25 Nov 2012 12:39:46 +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 vps1.hno.se (vps1.hno.se [31.192.227.87]) by theia.denx.de (Postfix) with ESMTPS id 31EFF4A025 for ; Sun, 25 Nov 2012 12:39:44 +0100 (CET) Received: from home.hno.se (home.hno.se [IPv6:2001:470:df90::1]) (authenticated bits=128) by vps1.hno.se (8.14.4/8.14.4) with ESMTP id qAPBdeAA014201 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Sun, 25 Nov 2012 12:39:42 +0100 Received: from [127.0.0.1] (localhost.localdomain [127.0.0.1]) by home.hno.se (8.14.5/8.14.5) with ESMTP id qAPBddjj015241 for ; Sun, 25 Nov 2012 12:39:39 +0100 Message-ID: <1353843579.17518.16.camel@home.hno.se> From: Henrik =?ISO-8859-1?Q?Nordstr=F6m?= To: U-Boot Mailing List Date: Sun, 25 Nov 2012 12:39:39 +0100 In-Reply-To: References: X-Mailer: Evolution 3.2.3 (3.2.3-3.fc16) Mime-Version: 1.0 Subject: [U-Boot] [PATCH 05/22] power: Add AXP209 Power Management controller (I2C) 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This adds support for AXP209 Power Management controller, used by most sunxi (Allwinner A10/A13) based boards. From: Henrik Nordstrom Signed-off-by: Henrik Nordstrom Signed-off-by: Stefan Roese --- drivers/power/Makefile | 1 + drivers/power/axp209.c | 183 ++++++++++++++++++++++++++++++++++++++++++++++++ include/axp209.h | 29 ++++++++ 3 files changed, 213 insertions(+), 0 deletions(-) create mode 100644 drivers/power/axp209.c create mode 100644 include/axp209.h diff --git a/drivers/power/Makefile b/drivers/power/Makefile index 8c71901..ad768ff 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile @@ -25,6 +25,7 @@ include $(TOPDIR)/config.mk LIB := $(obj)libpower.o +COBJS-$(CONFIG_AXP209_POWER) += axp209.o COBJS-$(CONFIG_FTPMU010_POWER) += ftpmu010.o COBJS-$(CONFIG_TPS6586X_POWER) += tps6586x.o COBJS-$(CONFIG_TWL4030_POWER) += twl4030.o diff --git a/drivers/power/axp209.c b/drivers/power/axp209.c new file mode 100644 index 0000000..be98d80 --- /dev/null +++ b/drivers/power/axp209.c @@ -0,0 +1,183 @@ +/* + * (C) Copyright 2012 + * Henrik Nordstrom + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#include +#include +#include + +enum axp209_reg { + AXP209_CHIP_VERSION = 0x3, + AXP209_DCDC2_VOLTAGE = 0x23, + AXP209_DCDC3_VOLTAGE = 0x27, + AXP209_LDO24_VOLTAGE = 0x28, + AXP209_LDO3_VOLTAGE = 0x29, + AXP209_SHUTDOWN = 0x32, +}; + +int axp209_write(enum axp209_reg reg, u8 val) +{ + return i2c_write(0x34, reg, 1, &val, 1); +} + +int axp209_read(enum axp209_reg reg, u8 *val) +{ + return i2c_read(0x34, reg, 1, val, 1); +} + +int axp209_set_dcdc2(int mvolt) +{ + int cfg = (mvolt - 700) / 25; + int rc; + u8 current; + + if (cfg < 0) + cfg = 0; + if (cfg > (1 << 6) - 1) + cfg = (1 << 6) - 1; + + /* Do we really need to be this gentle? It has built-in voltage slope */ + while ((rc = axp209_read(AXP209_DCDC2_VOLTAGE, ¤t)) == 0 + && current != cfg) { + if (current < cfg) + current++; + else + current--; + + rc = axp209_write(AXP209_DCDC2_VOLTAGE, current); + if (rc) + break; + } + + return rc; +} + +int axp209_set_dcdc3(int mvolt) +{ + int cfg = (mvolt - 700) / 25; + u8 reg; + int rc; + + if (cfg < 0) + cfg = 0; + if (cfg > (1 << 7) - 1) + cfg = (1 << 7) - 1; + + rc = axp209_write(AXP209_DCDC3_VOLTAGE, cfg); + rc |= axp209_read(AXP209_DCDC3_VOLTAGE, ®); + + return rc; +} + +int axp209_set_ldo2(int mvolt) +{ + int cfg = (mvolt - 1800) / 100; + int rc; + u8 reg; + + if (cfg < 0) + cfg = 0; + if (cfg > 15) + cfg = 15; + + rc = axp209_read(AXP209_LDO24_VOLTAGE, ®); + if (rc) + return rc; + + reg = (reg & 0x0f) | (cfg << 4); + rc = axp209_write(AXP209_LDO24_VOLTAGE, reg); + if (rc) + return rc; + + return 0; +} + +int axp209_set_ldo3(int mvolt) +{ + int cfg = (mvolt - 700) / 25; + + if (cfg < 0) + cfg = 0; + if (cfg > 127) + cfg = 127; + if (mvolt == -1) + cfg = 0x80; /* detemined by LDO3IN pin */ + + return axp209_write(AXP209_LDO3_VOLTAGE, cfg); +} + +int axp209_set_ldo4(int mvolt) +{ + int cfg = (mvolt - 1800) / 100; + int rc; + static const int vindex[] = { + 1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2500, + 2700, 2800, 3000, 3100, 3200, 3300 + }; + u8 reg; + + /* Translate mvolt to register cfg value, requested <= selected */ + for (cfg = 0; mvolt < vindex[cfg] && cfg < 15; cfg++) + ; + + rc = axp209_read(AXP209_LDO24_VOLTAGE, ®); + if (rc) + return rc; + + /* LDO4 configuration is in lower 4 bits */ + reg = (reg & 0xf0) | (cfg << 0); + rc = axp209_write(AXP209_LDO24_VOLTAGE, reg); + if (rc) + return rc; + + return 0; +} + +void axp209_poweroff(void) +{ + u8 val; + + if (axp209_read(AXP209_SHUTDOWN, &val) != 0) + return; + + val |= 1 << 7; + + if (axp209_write(AXP209_SHUTDOWN, val) != 0) + return; + + udelay(10000); /* wait for power to drain */ +} + +int axp209_init(void) +{ + u8 ver; + int rc; + + rc = axp209_read(AXP209_CHIP_VERSION, &ver); + if (rc) + return rc; + + if (ver != 0x21) + return -1; + + return 0; +} diff --git a/include/axp209.h b/include/axp209.h new file mode 100644 index 0000000..61338ac --- /dev/null +++ b/include/axp209.h @@ -0,0 +1,29 @@ +/* + * (C) Copyright 2012 Henrik Nordstrom + * + * See file CREDITS for list of people who contributed to this + * project. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +extern int axp209_set_dcdc2(int mvolt); +extern int axp209_set_dcdc3(int mvolt); +extern int axp209_set_ldo2(int mvolt); +extern int axp209_set_ldo3(int mvolt); +extern int axp209_set_ldo4(int mvolt); +extern void axp209_poweroff(void); +extern int axp209_init(void);