From patchwork Tue Sep 16 17:22:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 4918721 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9A730BEEA5 for ; Tue, 16 Sep 2014 17:23:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B4AE3201F5 for ; Tue, 16 Sep 2014 17:23:35 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D30F72010F for ; Tue, 16 Sep 2014 17:23:34 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XTwTW-0004sr-Jp; Tue, 16 Sep 2014 17:23:34 +0000 Received: from mail-pd0-x230.google.com ([2607:f8b0:400e:c02::230]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XTwTP-0004oM-33 for linux-rockchip@lists.infradead.org; Tue, 16 Sep 2014 17:23:27 +0000 Received: by mail-pd0-f176.google.com with SMTP id y13so215888pdi.7 for ; Tue, 16 Sep 2014 10:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=rCQlYl55hBW8e66WnDPLs0E1JB0fus01TiqlERdn1+c=; b=fFU+ZgbnrMD8pvXlRpwqFbkFBOks8YSYwvIrDUqVNbNTEuItbORJVIjXG8ay6r8zBW lIcsXEeEG176jriHtgSCO5qlVe10QifR2+x8L0UNHozKhz9isfBeY63X4Bz4W3k6/97j IGd+weHaJI8NLmscf7JfHBAKWGLm1kqdfgtsg= 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=rCQlYl55hBW8e66WnDPLs0E1JB0fus01TiqlERdn1+c=; b=UB9FtMQLX4TSKUqu/ztyGTJwCsRB0xpfJRh/OaTsN0JGgu+N56lpn5uSF2bWqCyClW DR9nxBApxizVC3neJUI2N9IHVRiMn5l/LxKUVTtM21RrcSRpKEs+E7y4/vB6WLxZ3l0O OOEwBQbXl67UyERCd6RNvASdXSi8ZAlWSCu0VgvV4K6S4lcePqXRDjoEabBO7FJLgim4 jmvMzEWeYVYB2abyYhHReTOMA93TwD5Fif4ifIrp1VJ7B30tAWGHzB8eIYeeDOGddBUA yh7sWoIqFBE3TV99QDwj9eO/3D0f5ijFZGqy2JRDDE54zmhglP41HgVEkDyrqnpeXLz8 UccA== X-Gm-Message-State: ALoCoQnR8e8oxc4m8Y9E0hgMoU6Rd9ZLRz7pt7NsEQUtIL1ZhLe6QcAijn/YmYFJkt0YvqBEx15a X-Received: by 10.67.23.164 with SMTP id ib4mr52464510pad.31.1410888184966; Tue, 16 Sep 2014 10:23:04 -0700 (PDT) Received: from tictac.mtv.corp.google.com (tictac.mtv.corp.google.com [172.22.162.15]) by mx.google.com with ESMTPSA id p3sm14699359pde.35.2014.09.16.10.23.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 16 Sep 2014 10:23:04 -0700 (PDT) From: Doug Anderson To: Mark Brown , Chris Zhong , Heiko Stuebner Subject: [PATCH] regulator: rk808: Add function for ramp delay for buck1/buck2 Date: Tue, 16 Sep 2014 10:22:54 -0700 Message-Id: <1410888174-8279-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140916_102327_150779_041D993E X-CRM114-Status: GOOD ( 10.42 ) X-Spam-Score: -0.8 (/) Cc: axel.lin@ingics.com, linux-kernel@vger.kernel.org, lgirdwood@gmail.com, Doug Anderson , linux-rockchip@lists.infradead.org, Sonny Rao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD,T_DKIM_INVALID,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 On rk808 buck1 and buck2 have programmable ramp delays. Let's add a function to allow a client of rk808 to set them. Signed-off-by: Doug Anderson --- drivers/regulator/rk808-regulator.c | 57 +++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/rk808-regulator.c b/drivers/regulator/rk808-regulator.c index 07b0eb4..e305416 100644 --- a/drivers/regulator/rk808-regulator.c +++ b/drivers/regulator/rk808-regulator.c @@ -28,6 +28,21 @@ #define RK808_BUCK4_VSEL_MASK 0xf #define RK808_LDO_VSEL_MASK 0x1f +/* Ramp rate definitions for buck1 / buck2 only */ +#define RK808_RAMP_RATE_OFFSET 3 +#define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET) +#define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET) +#define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET) +#define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) +#define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) + +static const int rk808_buck_config_regs[] = { + RK808_BUCK1_CONFIG_REG, + RK808_BUCK2_CONFIG_REG, + RK808_BUCK3_CONFIG_REG, + RK808_BUCK4_CONFIG_REG, +}; + static const struct regulator_linear_range rk808_buck_voltage_ranges[] = { REGULATOR_LINEAR_RANGE(700000, 0, 63, 12500), }; @@ -49,6 +64,44 @@ static const struct regulator_linear_range rk808_ldo6_voltage_ranges[] = { REGULATOR_LINEAR_RANGE(800000, 0, 17, 100000), }; +static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) +{ + unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US; + unsigned int reg = rk808_buck_config_regs[rdev->desc->id - + RK808_ID_DCDC1]; + + switch (ramp_delay) { + case 1 ... 2000: + ramp_value = RK808_RAMP_RATE_2MV_PER_US; + break; + case 2001 ... 4000: + ramp_value = RK808_RAMP_RATE_4MV_PER_US; + break; + case 4001 ... 6000: + ramp_value = RK808_RAMP_RATE_6MV_PER_US; + break; + case 6001 ... 10000: + break; + default: + pr_warn("%s ramp_delay: %d not supported, setting 10000\n", + rdev->desc->name, ramp_delay); + } + + return regmap_update_bits(rdev->regmap, reg, + RK808_RAMP_RATE_MASK, ramp_value); +} + +static struct regulator_ops rk808_buck1_2_ops = { + .list_voltage = regulator_list_voltage_linear_range, + .map_voltage = regulator_map_voltage_linear_range, + .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_ramp_delay = rk808_set_ramp_delay, +}; + static struct regulator_ops rk808_reg_ops = { .list_voltage = regulator_list_voltage_linear_range, .map_voltage = regulator_map_voltage_linear_range, @@ -70,7 +123,7 @@ static const struct regulator_desc rk808_reg[] = { .name = "DCDC_REG1", .supply_name = "vcc1", .id = RK808_ID_DCDC1, - .ops = &rk808_reg_ops, + .ops = &rk808_buck1_2_ops, .type = REGULATOR_VOLTAGE, .n_voltages = 64, .linear_ranges = rk808_buck_voltage_ranges, @@ -84,7 +137,7 @@ static const struct regulator_desc rk808_reg[] = { .name = "DCDC_REG2", .supply_name = "vcc2", .id = RK808_ID_DCDC2, - .ops = &rk808_reg_ops, + .ops = &rk808_buck1_2_ops, .type = REGULATOR_VOLTAGE, .n_voltages = 64, .linear_ranges = rk808_buck_voltage_ranges,