From patchwork Mon Jul 16 10:31:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: axel lin X-Patchwork-Id: 1200461 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 28C53E0038 for ; Mon, 16 Jul 2012 10:31:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753114Ab2GPKbT (ORCPT ); Mon, 16 Jul 2012 06:31:19 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:59733 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753101Ab2GPKbQ (ORCPT ); Mon, 16 Jul 2012 06:31:16 -0400 Received: by pbbrp8 with SMTP id rp8so9852655pbb.19 for ; Mon, 16 Jul 2012 03:31:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:subject:from:to:cc:date:content-type:x-mailer :content-transfer-encoding:mime-version; bh=bxVBxh+w4FJp31fcVrQcS2UJWHtBev/SXSzzp8ERWdo=; b=LDTVWUL4wsowKIdYwNYC4j3o06jlEwtNFH8Sqhh/i6DEZT0hm5LQx5JO2tZQwDkH4s U59lEew3TumGh5OtmoBD3ChTpz1odphCPOIJ2Uo5/A+Gr5uSrbKRvFSmiva6W9PssUQy Gja+jXy/2wqquLbFcjD8FPJ40qKnlor0oMJZ4VaaGopDCej4m6jD7pET8BETE/J06vqy GdbVsP7BW5M1/ffWccOITM2tHRSt06I9L4lHLYElMlXOXkN/Z7K/Xk/8SYf9kyBAKJMB Lnubw70fdKsiGrI35Ru57XH0W8pB7eiTE/JZ3mMzcuMpTeN775nKbKnqI4jvjj1GzK3U 9FSQ== Received: by 10.68.213.234 with SMTP id nv10mr25330059pbc.56.1342434676439; Mon, 16 Jul 2012 03:31:16 -0700 (PDT) Received: from [111.255.126.108] (111-255-126-108.dynamic.hinet.net. [111.255.126.108]) by mx.google.com with ESMTPS id pp2sm11666381pbb.1.2012.07.16.03.31.13 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 03:31:15 -0700 (PDT) Message-ID: <1342434670.4717.6.camel@phoenix> Subject: [PATCH RFT] regulator: twl: Fix list_voltate for twl6030ldo_ops From: Axel Lin To: Mark Brown Cc: Rajendra Nayak , Peter Ujfalusi , Liam Girdwood , linux-kernel@vger.kernel.org, loml , Graeme Gregory Date: Mon, 16 Jul 2012 18:31:10 +0800 X-Mailer: Evolution 3.2.3-0ubuntu6 Mime-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org According to the datasheet, the voltage for twl6030ldo_ops is not linear for all cases. Linear mapping is only for the selection code from 00000001 to 00011000. Table 9. LDO Output Voltage Selection Code CODE VOUT(V) COD VOUT(V) CODE VOUT(V) CODE VOUT(V) 00000000 0 00001000 1.7 00010000 2.5 00011000 3.3 00000001 1.0 00001001 1.8 00010001 2.6 00011001 Reserved 00000010 1.1 00001010 1.9 00010010 2.7 00011010 Reserved 00000011 1.2 00001011 2.0 00010011 2.8 00011011 Reserved 00000100 1.3 00001100 2.1 00010100 2.9 00011100 Reserved 00000101 1.4 00001101 2.2 00010101 3.0 00011101 Reserved 00000110 1.5 00001110 2.3 00010110 3.1 00011110 Reserved 00000111 1.6 00001111 2.4 00010111 3.2 00011111 2.75 This patch implements the list_voltage callback based on above table. Signed-off-by: Axel Lin Tested-by: Rajendra Nayak --- drivers/regulator/twl-regulator.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index de99b78..242fe90 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c @@ -559,6 +559,27 @@ static struct regulator_ops twl6030coresmps_ops = { .get_voltage = twl6030coresmps_get_voltage, }; +static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) +{ + struct twlreg_info *info = rdev_get_drvdata(rdev); + + switch (sel) { + case 0: + return 0; + case 1 ... 24: + /* Linear mapping from 00000001 to 00011000: + * Absolute voltage value = 1.0 V + 0.1 V × (sel – 00000001) + */ + return (info->min_mV + 100 * (sel - 1)) * 1000; + case 25 ... 30: + return -EINVAL; + case 31: + return 2750000; + default: + return -EINVAL; + } +} + static int twl6030ldo_set_voltage_sel(struct regulator_dev *rdev, unsigned selector) { @@ -577,7 +598,7 @@ static int twl6030ldo_get_voltage_sel(struct regulator_dev *rdev) } static struct regulator_ops twl6030ldo_ops = { - .list_voltage = regulator_list_voltage_linear, + .list_voltage = twl6030ldo_list_voltage, .set_voltage_sel = twl6030ldo_set_voltage_sel, .get_voltage_sel = twl6030ldo_get_voltage_sel, @@ -906,12 +927,10 @@ static struct twlreg_info TWL6030_INFO_##label = { \ .desc = { \ .name = #label, \ .id = TWL6030_REG_##label, \ - .n_voltages = (max_mVolts - min_mVolts)/100 + 1, \ + .n_voltages = 32, \ .ops = &twl6030ldo_ops, \ .type = REGULATOR_VOLTAGE, \ .owner = THIS_MODULE, \ - .min_uV = min_mVolts * 1000, \ - .uV_step = 100 * 1000, \ }, \ } @@ -923,12 +942,10 @@ static struct twlreg_info TWL6025_INFO_##label = { \ .desc = { \ .name = #label, \ .id = TWL6025_REG_##label, \ - .n_voltages = ((max_mVolts - min_mVolts)/100) + 1, \ + .n_voltages = 32, \ .ops = &twl6030ldo_ops, \ .type = REGULATOR_VOLTAGE, \ .owner = THIS_MODULE, \ - .min_uV = min_mVolts * 1000, \ - .uV_step = 100 * 1000, \ }, \ }