Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5144812img; Wed, 27 Mar 2019 03:03:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbmq+uL5OPtEhx3Wosynwo7SCnmLw2iHYDRRIdd3+4ogtXxnQiiT0ShutaNrkUrGQ6RQmV X-Received: by 2002:a63:7154:: with SMTP id b20mr26649996pgn.359.1553681006891; Wed, 27 Mar 2019 03:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553681006; cv=none; d=google.com; s=arc-20160816; b=KI3gL6Majat3kPbYpjAZsN0fpOamUBKjdJqCSA00hY0Tg657ZzxlxsEwMHW/qGxs4E BdZC4jagoBf1J7jXyCJnwM3C9A1+0XBF3KBwG3OmQhNWPY4pA7kRjQRQDPb8YKJZ1V+9 5T8GjaYgcCnwFr6+l+5z9FS9j6eMWzkrF3JZfkb1aAvlQU/PcPBqqWy+EKg0cmL9Teug zhvTqAB5VPTQ1+Pok4uTrvoT7urieNmP7XQveFKqib2fiT8NclCHcNs1SBG9ynHQi4zc iiAnFiNQwDAsMlJlRi4P+T0kQ9ABABFFpo+8+Mc+E1PcwVCNF7aNWf1pkelbX1Jaq8L6 V+mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+VLzeyLMdtCQvXkU4RKTaJDTW9VOoDXGyE7olCvYU8I=; b=f44hb5lPqO3124yuJugYX1W7qsMT4CYSYPPucwDjC7qEEdSMFkMUk33LRGKmXIBu8p 4BqLoPFrisjeLq5hoae54QS+JxiX1+rFl1HWRwu+9KnPhmgTAfgEV1i5aX+2xn6Gq+eL XHTQUZwGnFTMvFzJZXuGxdOMZwuY7MC9itwuhIfzkJSj15wDe048iTf/Iiv+gOdb7GrP WbSbMQIWs0TkZRJbNaUMLscEOWp8bv60fshOHI/ut2v1b+tTw3O0/dSUUiPko96ym4fW 6fAeMnYg9+11WvIYoRq57pTgtctpSTr63Q9Q14xss+izw5QkAUw3fRb3w7qz/Q6rL4Ly LBhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=KYIJ8Z9D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 59si19742634plb.405.2019.03.27.03.03.10; Wed, 27 Mar 2019 03:03:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=KYIJ8Z9D; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732800AbfC0KCL (ORCPT + 99 others); Wed, 27 Mar 2019 06:02:11 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:55106 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727557AbfC0KCL (ORCPT ); Wed, 27 Mar 2019 06:02:11 -0400 Received: by mail-it1-f194.google.com with SMTP id w18so24437295itj.4 for ; Wed, 27 Mar 2019 03:02:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=+VLzeyLMdtCQvXkU4RKTaJDTW9VOoDXGyE7olCvYU8I=; b=KYIJ8Z9DbIgRPpqbVU4DFqFAPHfS6tROxYOdIGHOmbq/Lg2UmTNWEJRGp06Vke3pyb uK4FwbpU38Hg7WIt+9uSgmmBISHWnXDwIZZ0ZcaWsBJkGCvt979WU7Tq3Omu4pi/Zjfj 0TWEDgGa3QYvgSPRSzzZbJsoBSSf4zc7pZNtdgrg/Sq65hQN+KOmcWgzyjTEf2mNKsMc uJ6NWnKA3RCk5WbAV7QFzcSDW6YCj/T0QqdwrAEAL3qylEOw1Cb8c0KM7CzR3I+Ta0hk AoVpsWrhqNN56PQYWghBP/ZO71PiJTCBuqulXBuVzyYxjg+2fMLdsJmZoDl3mx611bYl doQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=+VLzeyLMdtCQvXkU4RKTaJDTW9VOoDXGyE7olCvYU8I=; b=NI/295xeukywAhT7hckaGpZ3V4U11pLCEoWsF+qamX5dybQbCJp50g/uAFvpASQIXU DlkQZ4AEiHXFuTq5yx22Xr1fNGyj31mcrJ7gcLu8o1gSHcGGe/ewRxB6JXdufwvqYLog ryDzKY2LjGkvI/oizWoBGXpP0WVxFp7erewKTZrbftsq0IipVWJM83rHcWsg+yCyE0Xh MCnMwFPe6FuU0BaynN0ldMiLiu/I9C66J0vU4TePgRReOzu4i77eB3G+dnTSESpMfXMc app8sJ4B3yunC8Fei4k0L49eHL/lOPS/iI0xPDcaBgPXP4mwmPTcTb3JWqmatWGzxxZI TCWA== X-Gm-Message-State: APjAAAVR5JdxmbIKQ9eREeyMzE9Qgur2ex8rVHebkyhMhOIjuDCyQh64 BDGMr1DxxvMTJ+ylflCG628wA6gVxyipaY75DQEAKw== X-Received: by 2002:a24:3ac8:: with SMTP id m191mr2711977itm.74.1553680929569; Wed, 27 Mar 2019 03:02:09 -0700 (PDT) MIME-Version: 1.0 References: <20190325135557.3423-1-axel.lin@ingics.com> In-Reply-To: <20190325135557.3423-1-axel.lin@ingics.com> From: Bartosz Golaszewski Date: Wed, 27 Mar 2019 11:01:58 +0100 Message-ID: Subject: Re: [PATCH] regulator: max77650: Convert MAX77651 SBB1 to pickable linear range To: Axel Lin Cc: Mark Brown , Bartosz Golaszewski , Liam Girdwood , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org pon., 25 mar 2019 o 14:56 Axel Lin napisa=C5=82(a): > > The pickable linear range is suitable for The MAX77651 SBB1. > According to MAX77651 TV_SBB1 Code Table: > Use BIT[1:0] as range selectors. > Use BIT[5:2] as selectors for each linear range. > > The MAX77651 SBB1 supports up to selector 57, selector 58 ~ 63 are RSVD, > thus set n_voltage to 58. > > Signed-off-by: Axel Lin > --- > Hi Bartosz, > I don't have this h/w, please help to review and test this patch. > Thanks, > Axel > > drivers/regulator/max77650-regulator.c | 134 +++++++++---------------- > 1 file changed, 45 insertions(+), 89 deletions(-) > > diff --git a/drivers/regulator/max77650-regulator.c b/drivers/regulator/m= ax77650-regulator.c > index 5c4f86c98510..24b4a0a3c3bb 100644 > --- a/drivers/regulator/max77650-regulator.c > +++ b/drivers/regulator/max77650-regulator.c > @@ -20,6 +20,8 @@ > > #define MAX77650_REGULATOR_V_LDO_MASK GENMASK(6, 0) > #define MAX77650_REGULATOR_V_SBB_MASK GENMASK(5, 0) > +#define MAX77651_REGULATOR_V_SBB1_MASK GENMASK(5, 2) > +#define MAX77651_REGULATOR_V_SBB1_RANGE_MASK GENMASK(1, 0) > > #define MAX77650_REGULATOR_AD_MASK BIT(3) > #define MAX77650_REGULATOR_AD_DISABLED 0x00 > @@ -27,6 +29,8 @@ > > #define MAX77650_REGULATOR_CURR_LIM_MASK GENMASK(7, 6) > > +static struct max77650_regulator_desc max77651_SBB1_desc; > + > enum { > MAX77650_REGULATOR_ID_LDO =3D 0, > MAX77650_REGULATOR_ID_SBB0, > @@ -41,43 +45,20 @@ struct max77650_regulator_desc { > unsigned int regB; > }; > > -static const unsigned int max77651_sbb1_regulator_volt_table[] =3D { > - 2400000, 3200000, 4000000, 4800000, > - 2450000, 3250000, 4050000, 4850000, > - 2500000, 3300000, 4100000, 4900000, > - 2550000, 3350000, 4150000, 4950000, > - 2600000, 3400000, 4200000, 5000000, > - 2650000, 3450000, 4250000, 5050000, > - 2700000, 3500000, 4300000, 5100000, > - 2750000, 3550000, 4350000, 5150000, > - 2800000, 3600000, 4400000, 5200000, > - 2850000, 3650000, 4450000, 5250000, > - 2900000, 3700000, 4500000, 0, > - 2950000, 3750000, 4550000, 0, > - 3000000, 3800000, 4600000, 0, > - 3050000, 3850000, 4650000, 0, > - 3100000, 3900000, 4700000, 0, > - 3150000, 3950000, 4750000, 0, > +static const unsigned int max77651_sbb1_volt_range_sel[] =3D { > + 0x0, 0x1, 0x2, 0x3 > }; > > -#define MAX77651_REGULATOR_SBB1_SEL_DEC(_val) \ > - (((_val & 0x3c) >> 2) | ((_val & 0x03) << 4)) > -#define MAX77651_REGULATOR_SBB1_SEL_ENC(_val) \ > - (((_val & 0x30) >> 4) | ((_val & 0x0f) << 2)) > - > -#define MAX77650_REGULATOR_SBB1_SEL_DECR(_val) \ > - do { \ > - _val =3D MAX77651_REGULATOR_SBB1_SEL_DEC(_val); = \ > - _val--; \ > - _val =3D MAX77651_REGULATOR_SBB1_SEL_ENC(_val); = \ > - } while (0) > - > -#define MAX77650_REGULATOR_SBB1_SEL_INCR(_val) \ > - do { \ > - _val =3D MAX77651_REGULATOR_SBB1_SEL_DEC(_val); = \ > - _val++; \ > - _val =3D MAX77651_REGULATOR_SBB1_SEL_ENC(_val); = \ > - } while (0) > +static const struct regulator_linear_range max77651_sbb1_volt_ranges[] = =3D { > + /* range index 0 */ > + REGULATOR_LINEAR_RANGE(2400000, 0x00, 0x0f, 50000), > + /* range index 1 */ > + REGULATOR_LINEAR_RANGE(3200000, 0x00, 0x0f, 50000), > + /* range index 2 */ > + REGULATOR_LINEAR_RANGE(4000000, 0x00, 0x0f, 50000), > + /* range index 3 */ > + REGULATOR_LINEAR_RANGE(4800000, 0x00, 0x09, 50000), > +}; > > static const unsigned int max77650_current_limit_table[] =3D { > 1000000, 866000, 707000, 500000, > @@ -130,6 +111,7 @@ static int max77650_regulator_disable(struct regulato= r_dev *rdev) > static int max77650_regulator_set_voltage_sel(struct regulator_dev *rdev= , > unsigned int sel) > { > + struct max77650_regulator_desc *rdesc =3D rdev_get_drvdata(rdev); > int rv =3D 0, curr, diff; > bool ascending; > > @@ -137,15 +119,24 @@ static int max77650_regulator_set_voltage_sel(struc= t regulator_dev *rdev, > * If the regulator is disabled, we can program the desired > * voltage right away. > */ > - if (!max77650_regulator_is_enabled(rdev)) > - return regulator_set_voltage_sel_regmap(rdev, sel); > + if (!max77650_regulator_is_enabled(rdev)) { > + if (rdesc =3D=3D &max77651_SBB1_desc) > + return regulator_set_voltage_sel_pickable_regmap(= rdev, > + = sel); > + else > + return regulator_set_voltage_sel_regmap(rdev, sel= ); > + } > > /* > * Otherwise we need to manually ramp the output voltage up/down > * one step at a time. > */ > > - curr =3D regulator_get_voltage_sel_regmap(rdev); > + if (rdesc =3D=3D &max77651_SBB1_desc) > + curr =3D regulator_get_voltage_sel_pickable_regmap(rdev); > + else > + curr =3D regulator_get_voltage_sel_regmap(rdev); > + > if (curr < 0) > return curr; > > @@ -162,57 +153,18 @@ static int max77650_regulator_set_voltage_sel(struc= t regulator_dev *rdev, > * the selector equals 0. > */ > for (ascending ? curr++ : curr--;; ascending ? curr++ : curr--) { > - rv =3D regulator_set_voltage_sel_regmap(rdev, curr); > - if (rv) > - return rv; > - > - if (curr =3D=3D sel) > - break; > - } > - > - return 0; > -} > - > -/* > - * Special case: non-linear voltage table for max77651 SBB1 - software > - * must ensure the voltage is ramped in 50mV increments. > - */ > -static int max77651_regulator_sbb1_set_voltage_sel(struct regulator_dev = *rdev, > - unsigned int sel) > -{ > - int rv =3D 0, curr, vcurr, vdest, vdiff; > - > - /* > - * If the regulator is disabled, we can program the desired > - * voltage right away. > - */ > - if (!max77650_regulator_is_enabled(rdev)) > - return regulator_set_voltage_sel_regmap(rdev, sel); > - > - curr =3D regulator_get_voltage_sel_regmap(rdev); > - if (curr < 0) > - return curr; > - > - if (curr =3D=3D sel) > - return 0; /* Already there. */ > - > - vcurr =3D max77651_sbb1_regulator_volt_table[curr]; > - vdest =3D max77651_sbb1_regulator_volt_table[sel]; > - vdiff =3D vcurr - vdest; > - > - for (;;) { > - if (vdiff > 0) > - MAX77650_REGULATOR_SBB1_SEL_DECR(curr); > + if (rdesc =3D=3D &max77651_SBB1_desc) > + rv =3D regulator_set_voltage_sel_pickable_regmap(= rdev, > + cu= rr); > else > - MAX77650_REGULATOR_SBB1_SEL_INCR(curr); > + rv =3D regulator_set_voltage_sel_regmap(rdev, cur= r); > > - rv =3D regulator_set_voltage_sel_regmap(rdev, curr); > if (rv) > return rv; > > if (curr =3D=3D sel) > break; > - }; > + } > > return 0; > } > @@ -241,14 +193,14 @@ static const struct regulator_ops max77650_regulato= r_SBB_ops =3D { > .set_active_discharge =3D regulator_set_active_discharge_regmap= , > }; > > -/* Special case for max77651 SBB1 - non-linear voltage mapping. */ > +/* Special case for max77651 SBB1 - pickable linear-range voltage mappin= g. */ > static const struct regulator_ops max77651_SBB1_regulator_ops =3D { > .is_enabled =3D max77650_regulator_is_enabled, > .enable =3D max77650_regulator_enable, > .disable =3D max77650_regulator_disable, > - .list_voltage =3D regulator_list_voltage_table, > - .get_voltage_sel =3D regulator_get_voltage_sel_regmap, > - .set_voltage_sel =3D max77651_regulator_sbb1_set_voltage_s= el, > + .list_voltage =3D regulator_list_voltage_pickable_linea= r_range, > + .get_voltage_sel =3D regulator_get_voltage_sel_pickable_re= gmap, > + .set_voltage_sel =3D max77650_regulator_set_voltage_sel, > .get_current_limit =3D regulator_get_current_limit_regmap, > .set_current_limit =3D regulator_set_current_limit_regmap, > .set_active_discharge =3D regulator_set_active_discharge_regmap= , > @@ -345,9 +297,13 @@ static struct max77650_regulator_desc max77651_SBB1_= desc =3D { > .supply_name =3D "in-sbb1", > .id =3D MAX77650_REGULATOR_ID_SBB1, > .ops =3D &max77651_SBB1_regulator_ops, > - .volt_table =3D max77651_sbb1_regulator_volt_= table, > - .n_voltages =3D ARRAY_SIZE(max77651_sbb1_regulator_volt_t= able), > - .vsel_mask =3D MAX77650_REGULATOR_V_SBB_MASK= , > + .linear_range_selectors =3D max77651_sbb1_volt_range_sel, > + .linear_ranges =3D max77651_sbb1_volt_ranges, > + .n_linear_ranges =3D ARRAY_SIZE(max77651_sbb1_volt= _ranges), > + .n_voltages =3D 58, > + .vsel_range_mask =3D MAX77651_REGULATOR_V_SBB1_RAN= GE_MASK, > + .vsel_range_reg =3D MAX77650_REG_CNFG_SBB1_A, > + .vsel_mask =3D MAX77651_REGULATOR_V_SBB1_MAS= K, > .vsel_reg =3D MAX77650_REG_CNFG_SBB1_A, > .active_discharge_off =3D MAX77650_REGULATOR_AD_DISABLE= D, > .active_discharge_on =3D MAX77650_REGULATOR_AD_ENABLED= , > -- > 2.17.1 > Hi, what tree is this patch based on, because it doesn't apply on top of v5.1-r= c2. Bart