From patchwork Wed Mar 23 19:22:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivaylo Dimitrov X-Patchwork-Id: 8653281 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 081F6C0553 for ; Wed, 23 Mar 2016 19:24:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 26FB520411 for ; Wed, 23 Mar 2016 19:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0640C203ED for ; Wed, 23 Mar 2016 19:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752230AbcCWTYR (ORCPT ); Wed, 23 Mar 2016 15:24:17 -0400 Received: from mail-wm0-f49.google.com ([74.125.82.49]:33686 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751644AbcCWTYR (ORCPT ); Wed, 23 Mar 2016 15:24:17 -0400 Received: by mail-wm0-f49.google.com with SMTP id l68so246857103wml.0; Wed, 23 Mar 2016 12:24:16 -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=GmhCLeU2DUfGXUUJmFo8UFBfyKF61igI0jVAppPm+ds=; b=DhF6G7TbaSsLvYuUJ0UjBmNsuBumu3Njxqeqxs7b8LbOLKKZtVnZj9KAI1N6L//FFw TKX/WjiMDjH2FjhuorzOB7DcznfHnZQACXFkKNHAuvAvc37Eg4VCxAYQfv9CUKDHun/g /ude+8f4lDaBC6WnVnYTeYysTjTRNYFEhjtTl3CucxUq22CxA1KC4kJicCNiNERc00Hb syx0y+2jo58LQiNtzzZZJhDBGRBs5QVxP48FDmc8vGiKHQat/RGWNtAN2Iomlq/p0z4x E4il3AMrYazPBNCLYxTr/VgBttun+5ywP9J6C0T64WEXhoCaEE+OZPwAMcW/aKE/kD8c jYWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=GmhCLeU2DUfGXUUJmFo8UFBfyKF61igI0jVAppPm+ds=; b=jBe8hMrd4QkkN1avbzc2GYY9WI6QuKNstqHBtllEcwtlIQOQaCD86CUbD2Zp3iig9f MuiE3AiDQaAKZ9IBLM84p9lT6/WojBhi1tTuoNZ3pfHdmArPLlMPpLhLRxSof+LWb2nF fdPPw7WkL3l15Sg8DhAC2ybN0wnNIyVvQuXJwl/cTGuksyWKqma//nVBKwJ0FWxDYXil b6xW/AxS5k4AisTHpj+DNrfWrPTQHxBUQkoJtXPjDiZttyytYC1Gq93kuZ65h2qFiaqe h+oN04K7mFKhnDm2ke/SVKu84PCOfZFUKGgcf5Yrwn4s+0JwgUumEeVLIhZf/52wZJ2L KKQA== X-Gm-Message-State: AD7BkJKr7va+gY6vUBB1Xdoi4pTl8Guye5yVm9/e6beTOaiS0WmKT/UyEegwDwRMj6HSKA== X-Received: by 10.194.61.169 with SMTP id q9mr5201493wjr.77.1458761055304; Wed, 23 Mar 2016 12:24:15 -0700 (PDT) Received: from localhost.localdomain ([46.249.74.23]) by smtp.gmail.com with ESMTPSA id j18sm23762056wmd.2.2016.03.23.12.24.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 23 Mar 2016 12:24:14 -0700 (PDT) From: Ivaylo Dimitrov To: tony@atomide.com, lgirdwood@gmail.com, broonie@kernel.org Cc: linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, Ivaylo Dimitrov Subject: [PATCH] regulator: twl: Enable regulators over the powerbus as well Date: Wed, 23 Mar 2016 21:22:36 +0200 Message-Id: <1458760956-29892-1-git-send-email-ivo.g.dimitrov.75@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Assigning a device group to a regulator does not change its state. To change the state of a regulator a message over the powerbus is required. Also, the check for the current state of a regulator should not count on a device group being assigned, but on the current resource state. Signed-off-by: Ivaylo Dimitrov --- drivers/regulator/twl-regulator.c | 85 ++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 955a6fb..125d5b1 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -21,7 +21,7 @@ #include #include #include - +#include /* * The TWL4030/TW5030/TPS659x0/TWL6030 family chips include power management, a @@ -165,7 +165,7 @@ static int twl4030reg_is_enabled(struct regulator_dev *rdev) if (state < 0) return state; - return state & P1_GRP_4030; + return (state & 0x0f) != 0; } static int twl6030reg_is_enabled(struct regulator_dev *rdev) @@ -188,11 +188,78 @@ static int twl6030reg_is_enabled(struct regulator_dev *rdev) return grp && (val == TWL6030_CFG_STATE_ON); } +#define PB_I2C_BUSY BIT(0) +#define PB_I2C_BWEN BIT(1) + +static int twl4030_wait_pb_ready(void) +{ + + int ret; + int timeout = 10; + u8 val; + + do { + ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, + TWL4030_PM_MASTER_PB_CFG); + if (ret < 0) + return ret; + + if (!(val & PB_I2C_BUSY)) + return 0; + + mdelay(1); + timeout--; + } while (timeout); + + return -ETIMEDOUT; +} + +static int twl4030_send_pb_msg(unsigned msg) +{ + u8 val; + int ret; + + /* save powerbus configuration */ + ret = twl_i2c_read_u8(TWL_MODULE_PM_MASTER, &val, + TWL4030_PM_MASTER_PB_CFG); + if (ret < 0) + return ret; + + /* Enable I2C access to powerbus */ + ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val | PB_I2C_BWEN, + TWL4030_PM_MASTER_PB_CFG); + if (ret < 0) + return ret; + + ret = twl4030_wait_pb_ready(); + if (ret < 0) + return ret; + + ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg >> 8, + TWL4030_PM_MASTER_PB_WORD_MSB); + if (ret < 0) + return ret; + + ret = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, msg & 0xff, + TWL4030_PM_MASTER_PB_WORD_LSB); + if (ret < 0) + return ret; + + ret = twl4030_wait_pb_ready(); + if (ret < 0) + return ret; + + /* Restore powerbus configuration */ + return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, val, + TWL_MODULE_PM_MASTER); +} + static int twl4030reg_enable(struct regulator_dev *rdev) { struct twlreg_info *info = rdev_get_drvdata(rdev); int grp; int ret; + unsigned message; grp = twlreg_grp(rdev); if (grp < 0) @@ -201,8 +268,12 @@ static int twl4030reg_enable(struct regulator_dev *rdev) grp |= P1_GRP_4030; ret = twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_GRP, grp); + if (ret < 0) + return ret; - return ret; + message = MSG_SINGULAR(DEV_GRP_P1, info->id, RES_STATE_ACTIVE); + + return twl4030_send_pb_msg(message); } static int twl6030reg_enable(struct regulator_dev *rdev) @@ -324,13 +395,7 @@ static int twl4030reg_set_mode(struct regulator_dev *rdev, unsigned mode) if (!(status & (P3_GRP_4030 | P2_GRP_4030 | P1_GRP_4030))) return -EACCES; - status = twl_i2c_write_u8(TWL_MODULE_PM_MASTER, - message >> 8, TWL4030_PM_MASTER_PB_WORD_MSB); - if (status < 0) - return status; - - return twl_i2c_write_u8(TWL_MODULE_PM_MASTER, - message & 0xff, TWL4030_PM_MASTER_PB_WORD_LSB); + return twl4030_send_pb_msg(message); } static int twl6030reg_set_mode(struct regulator_dev *rdev, unsigned mode)