From patchwork Thu Jan 31 12:46:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Otavio Salvador X-Patchwork-Id: 10790451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5358B922 for ; Thu, 31 Jan 2019 12:46:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46B3D30C54 for ; Thu, 31 Jan 2019 12:46:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3A4D330C60; Thu, 31 Jan 2019 12:46:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2F0F430C54 for ; Thu, 31 Jan 2019 12:46:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=HZjGCp3q+D5meOVd72V7Vd5dfAbhY/HO3lKS3RjF9zE=; b=nntoVQTeO+dnGi CQj+2ueBzpL9OpWEHwc6O/VU17MXig0ug2Zs0LQzd8VLHf6FClIv6Rh8OAC9wXflIDEer5HCkSSFP jTEATTs/BtvYZ+3eeM5eKibieJyS/vMr/iBmNbIYPuqYD6Pz7SK16crYvDf4lZpVxIHlGTy9V5xvg 6KT5AeC6hpAgGgxUnUPLLrm8zofeS5W301Mt+Ino2v0VrQGOSbjElZ15WJSXw3n36nnCzJLDkHz8c 4JLPK1Npm9mltew/pXGgRMQqRAPTKQQmPL6k4P30VUl6llPZtUkvgb37cC8V+oGKI1xIeUaTxZhTo GGaAhNfx8cRCsmN/Bwag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gpBje-0004xl-AU; Thu, 31 Jan 2019 12:46:26 +0000 Received: from mail-qt1-f194.google.com ([209.85.160.194]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gpBja-0004vx-Q2 for linux-arm-kernel@lists.infradead.org; Thu, 31 Jan 2019 12:46:24 +0000 Received: by mail-qt1-f194.google.com with SMTP id l12so3231188qtf.8 for ; Thu, 31 Jan 2019 04:46:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :organization:content-transfer-encoding; bh=L8eYQ5hhgefqEk+G7G/K6cViDNiGVYa5I3lqc3l2fKo=; b=g3tIFnCLtXWvUkUjgGwRfQTP0VyjxvAgt2PRUG3YXrAskwjPYBJU3oUyYaWKaLqA7r gkggXSmLu/ePF8azA0HYXVrJ6egKm3VqOFOyxHJc+VVOlo3JJzvSvE6a77vV61i6k3jH j5LkhSmVUB/9Wt7nG+x5n1Pukz+olaOoYhu4Jnx/eMByVX6dyeUmZs2yBgxVHSjSTD67 XVM3Cs8Ekt76ZVUX24Y2iFD5WiDOTar9B4T1ZrGopG9+M7/bYKUaryHjvF/JZHiN9OaC RTS3TQeoDJA7mGjkowuLlL4g839PzQNZA8Ytd7689jvKxia522No6y1vaJaB8riWJByo YFWw== X-Gm-Message-State: AJcUukeLDZLa9gNGOw7/Grq5uB76kN88pD8rMUeSTVjcyCULyVJYXsYT UJgmJ6AAFCDXxXFiYKhqNxZBnRyn X-Google-Smtp-Source: ALg8bN64WFSjsq/qY2vOIzrG4Stxph0C1vhkZYuvk4OnOyBhpDKh35j0iww5bxmf7GXtvWhXo39vGw== X-Received: by 2002:aed:2217:: with SMTP id n23mr32811022qtc.288.1548938780741; Thu, 31 Jan 2019 04:46:20 -0800 (PST) Received: from localhost.localdomain ([181.220.86.121]) by smtp.gmail.com with ESMTPSA id m68sm4045377qte.49.2019.01.31.04.46.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 31 Jan 2019 04:46:19 -0800 (PST) Received: by localhost.localdomain (sSMTP sendmail emulation); Thu, 31 Jan 2019 10:46:13 -0200 From: Otavio Salvador To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] regulator: rk808: Fix BUCK1/2 voltages on rk805 Date: Thu, 31 Jan 2019 10:46:01 -0200 Message-Id: <20190131124601.29763-1-otavio@ossystems.com.br> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Organization: O.S. Systems Software LTDA. X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190131_044622_855262_320E2E32 X-CRM114-Status: GOOD ( 15.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jason Zhu , Otavio Salvador , Mark Brown , Liam Girdwood , linux-kernel@vger.kernel.org, Tony Xie , Vicent Chi , Andy Yan , Philipp Tomsic Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP RK805 has the following voltage range for the BUCK1 and BUCK2 regulators: From 0.7125V to 1.45V in 12.5mV steps, 1.8V, 2V, 2.2V and 2.3V , which corresponds to the following values as per the RK805 datasheet: 000 000: 0.7125V 000 001: 0.725V …… 111 011: 1.45V 111 100: 1.8V 111 101: 2.0V 111 110: 2.2V 111 111: 2.3V This means that the voltage range is not linear and so RK805 can not reuse the same regulator_ops structure from RK808. Fix it by creating a list with the correct supported voltage values for RK805 BUCK1 and BUCK2 regulators. Tested on a rv1108-elgin-r1 board that now correctly reports a BUCK2 voltage of 2.2V instead of the unsupported value of 1.4875V. Fixes: c4e0d344c1f0 ("regulator: rk808: Add regulator driver for RK805") Signed-off-by: Otavio Salvador --- Changes in v2: - add fixes tag - rebase on top of linux-next drivers/regulator/rk808-regulator.c | 53 ++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c index 08578f6d737d..79e79cdd503b 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c @@ -289,6 +289,21 @@ static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) RK808_RAMP_RATE_MASK, ramp_value); } +static int rk805_set_suspend_voltage(struct regulator_dev *rdev, int uv) +{ + unsigned int reg; + int sel = regulator_map_voltage_ascend(rdev, uv, uv); + + if (sel < 0) + return -EINVAL; + + reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; + + return regmap_update_bits(rdev->regmap, reg, + rdev->desc->vsel_mask, + sel); +} + static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv) { unsigned int reg; @@ -384,6 +399,19 @@ static const struct regulator_ops rk805_switch_ops = { .set_suspend_disable = rk805_set_suspend_disable, }; +static struct regulator_ops rk805_buck1_2_ops = { + .list_voltage = regulator_list_voltage_table, + .map_voltage = regulator_map_voltage_ascend, + .get_voltage_sel = regulator_get_voltage_sel_regmap, + .set_voltage_sel = regulator_set_voltage_sel_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, + .is_enabled = regulator_is_enabled_regmap, + .set_suspend_voltage = rk805_set_suspend_voltage, + .set_suspend_enable = rk805_set_suspend_enable, + .set_suspend_disable = rk805_set_suspend_disable, +}; + static const struct regulator_ops rk808_buck1_2_ops = { .list_voltage = regulator_list_voltage_linear, .map_voltage = regulator_map_voltage_linear, @@ -433,6 +461,17 @@ static const struct regulator_ops rk808_switch_ops = { .set_suspend_disable = rk808_set_suspend_disable, }; +static const int rk805_buck_1_2_voltages[] = { + 712500, 725000, 737500, 750000, 762500, 775000, 787500, 800000, + 812500, 825000, 837500, 850000, 862500, 875000, 887500, 900000, + 912500, 925000, 937500, 950000, 962500, 975000, 987500, 1000000, + 1012500, 1025000, 1037500, 1050000, 1062500, 1075000, 1087500, 1100000, + 1112500, 1125000, 1137500, 1150000, 1162500, 1175000, 1187500, 1200000, + 1212500, 1225000, 1237500, 1250000, 1262500, 1275000, 1287500, 1300000, + 1312500, 1325000, 1337500, 1350000, 1362500, 1375000, 1387500, 1400000, + 1412500, 1425000, 1437500, 1450000, 1800000, 2000000, 2200000, 2300000, +}; + static const struct regulator_desc rk805_reg[] = { { .name = "DCDC_REG1", @@ -440,11 +479,10 @@ static const struct regulator_desc rk805_reg[] = { .of_match = of_match_ptr("DCDC_REG1"), .regulators_node = of_match_ptr("regulators"), .id = RK805_ID_DCDC1, - .ops = &rk805_reg_ops, + .ops = &rk805_buck1_2_ops, .type = REGULATOR_VOLTAGE, - .min_uV = 712500, - .uV_step = 12500, - .n_voltages = 64, + .n_voltages = ARRAY_SIZE(rk805_buck_1_2_voltages), + .volt_table = rk805_buck_1_2_voltages, .vsel_reg = RK805_BUCK1_ON_VSEL_REG, .vsel_mask = RK818_BUCK_VSEL_MASK, .enable_reg = RK805_DCDC_EN_REG, @@ -456,11 +494,10 @@ static const struct regulator_desc rk805_reg[] = { .of_match = of_match_ptr("DCDC_REG2"), .regulators_node = of_match_ptr("regulators"), .id = RK805_ID_DCDC2, - .ops = &rk805_reg_ops, + .ops = &rk805_buck1_2_ops, .type = REGULATOR_VOLTAGE, - .min_uV = 712500, - .uV_step = 12500, - .n_voltages = 64, + .n_voltages = ARRAY_SIZE(rk805_buck_1_2_voltages), + .volt_table = rk805_buck_1_2_voltages, .vsel_reg = RK805_BUCK2_ON_VSEL_REG, .vsel_mask = RK818_BUCK_VSEL_MASK, .enable_reg = RK805_DCDC_EN_REG,