From patchwork Wed Oct 29 16:22:41 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suriyan Ramasami X-Patchwork-Id: 404694 X-Patchwork-Delegate: promsoft@gmail.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 10794140081 for ; Thu, 30 Oct 2014 03:23:04 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 695B04B98D; Wed, 29 Oct 2014 17:23:02 +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 BANmsZkB0S+g; Wed, 29 Oct 2014 17:23:02 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BE9C14B984; Wed, 29 Oct 2014 17:23:01 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ADB034B984 for ; Wed, 29 Oct 2014 17:22:58 +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 6SzOVjNSFfFv for ; Wed, 29 Oct 2014 17:22:58 +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 mail-oi0-f52.google.com (mail-oi0-f52.google.com [209.85.218.52]) by theia.denx.de (Postfix) with ESMTPS id 534EF4B983 for ; Wed, 29 Oct 2014 17:22:55 +0100 (CET) Received: by mail-oi0-f52.google.com with SMTP id u20so2541355oif.39 for ; Wed, 29 Oct 2014 09:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=zdBpbEmtz0nfD5Xvc1dkq4FvOThryo+J4cuveNzOvxs=; b=yW9a5nhWRZhwIumpmGFFwq1eEJYH+8iYHm7zE5XwBXyWww/+OJTJnip8BpUndBssyi 4TebkSvc4H/HV+6W3BDyW4GgIFLAKBlYA0HrDDycPWM2lTn4wwPSTbd5ru9ixLTonJhA BXHAl/dj7gIfKx3+uWaMqqx9+XtopLkZNAo3dyIsd/KPADlXZDuZUZH95c90U3xkZU1v dnZYgO6ElJgErzOmXAGbToGtSGgq6BNA7QUhquybvdZaPTyOl3qX4Cy4Qalb9JgPJWG1 zecGUjqv6fM2M9/UHlgcN/x+ATUq2Zcj3Z6T7ZqW2bGfIlZ06Penw/2cY+nNd+J3AABr YnYg== X-Received: by 10.202.181.197 with SMTP id e188mr1520731oif.96.1414599773836; Wed, 29 Oct 2014 09:22:53 -0700 (PDT) Received: from suriyanT430.us.oracle.com ([148.87.13.5]) by mx.google.com with ESMTPSA id n2sm1934280oel.17.2014.10.29.09.22.52 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 29 Oct 2014 09:22:53 -0700 (PDT) From: Suriyan Ramasami To: u-boot@lists.denx.de Date: Wed, 29 Oct 2014 09:22:41 -0700 Message-Id: <1414599763-15861-1-git-send-email-suriyan.r@gmail.com> X-Mailer: git-send-email 1.9.1 Cc: Jeroen Hofstee , Suriyan Ramasami , Przemyslaw Marczak , Jaehoon Chung , Przemyslaw Marczak Subject: [U-Boot] [PATCH v3 1/3] arm: odroid: pmic77686: allow buck voltage settings X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 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 Allow to set the buck voltage for the max77686. This will be used to reset the SMC LAN9730 ethernet on the odroids. Signed-off-by: Suriyan Ramasami --- Changes in v3: * Correct ldo and buck validation logic * Jaehoon/Przemyslaw - Use negative errno values for error condistions * Albert - its buck not bucket Changes in v2: * Jaehoon - separate out this patch Changes in v1: - First try drivers/power/pmic/pmic_max77686.c | 52 +++++++++++++++++++++++++++++++++++--- include/power/max77686_pmic.h | 3 +++ 2 files changed, 52 insertions(+), 3 deletions(-) diff --git a/drivers/power/pmic/pmic_max77686.c b/drivers/power/pmic/pmic_max77686.c index df1fd91..95b1a57 100644 --- a/drivers/power/pmic/pmic_max77686.c +++ b/drivers/power/pmic/pmic_max77686.c @@ -42,11 +42,30 @@ static unsigned int max77686_ldo_volt2hex(int ldo, ulong uV) return 0; } +static int max77686_buck_volt2hex(int buck, ulong uV) +{ + int hex = 0; + + if (buck < 5 || buck > 9) { + debug("%s: buck %d is not supported\n", __func__, buck); + return -EINVAL; + } + + hex = (uV - 750000) / 50000; + + if (hex >= 0 && hex <= MAX77686_BUCK_VOLT_MAX_HEX) + return hex; + + debug("%s: %ld is wrong voltage value for BUCK%d\n", + __func__, uV, buck); + return -EINVAL; +} + int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV) { unsigned int val, ret, hex, adr; - if (ldo < 1 && ldo > 26) { + if (ldo < 1 || ldo > 26) { printf("%s: %d is wrong ldo number\n", __func__, ldo); return -1; } @@ -68,11 +87,38 @@ int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV) return ret; } +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV) +{ + unsigned int val, adr; + int hex, ret; + + if (buck < 5 || buck > 9) { + printf("%s: %d is an unsupported bucket number\n", + __func__, buck); + return -EINVAL; + } + + adr = max77686_buck_addr[buck] + 1; + hex = max77686_buck_volt2hex(buck, uV); + + if (hex < 0) + return hex; + + ret = pmic_reg_read(p, adr, &val); + if (ret) + return ret; + + val &= ~MAX77686_BUCK_VOLT_MASK; + ret |= pmic_reg_write(p, adr, val | hex); + + return ret; +} + int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode) { unsigned int val, ret, adr, mode; - if (ldo < 1 && 26 < ldo) { + if (ldo < 1 || 26 < ldo) { printf("%s: %d is wrong ldo number\n", __func__, ldo); return -1; } @@ -157,7 +203,7 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode) /* mode */ switch (opmode) { case OPMODE_OFF: - mode = MAX77686_BUCK_MODE_OFF; + mode = MAX77686_BUCK_MODE_OFF << mode_shift; break; case OPMODE_STANDBY: switch (buck) { diff --git a/include/power/max77686_pmic.h b/include/power/max77686_pmic.h index c2a772a..b0e4255 100644 --- a/include/power/max77686_pmic.h +++ b/include/power/max77686_pmic.h @@ -150,6 +150,7 @@ enum { int max77686_set_ldo_voltage(struct pmic *p, int ldo, ulong uV); int max77686_set_ldo_mode(struct pmic *p, int ldo, char opmode); +int max77686_set_buck_voltage(struct pmic *p, int buck, ulong uV); int max77686_set_buck_mode(struct pmic *p, int buck, char opmode); #define MAX77686_LDO_VOLT_MAX_HEX 0x3f @@ -159,6 +160,8 @@ int max77686_set_buck_mode(struct pmic *p, int buck, char opmode); #define MAX77686_LDO_MODE_STANDBY (0x01 << 0x06) #define MAX77686_LDO_MODE_LPM (0x02 << 0x06) #define MAX77686_LDO_MODE_ON (0x03 << 0x06) +#define MAX77686_BUCK_VOLT_MAX_HEX 0x3f +#define MAX77686_BUCK_VOLT_MASK 0x3f #define MAX77686_BUCK_MODE_MASK 0x03 #define MAX77686_BUCK_MODE_SHIFT_1 0x00 #define MAX77686_BUCK_MODE_SHIFT_2 0x04