Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1742838rwd; Fri, 9 Jun 2023 01:12:32 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ62fd3EwHS1OFEgInSqD1Zgulo1SJ/oHdkF017uFUEJaT4RNgX2H3DyhgFawa/XzGisLj4Y X-Received: by 2002:a05:6a00:856:b0:661:4a00:1ea5 with SMTP id q22-20020a056a00085600b006614a001ea5mr460626pfk.20.1686298352698; Fri, 09 Jun 2023 01:12:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686298352; cv=none; d=google.com; s=arc-20160816; b=FHLw8jnVufZSOK8KIpWAFaPu7Er+uHl88XO5ZY6DBFcA9pmVts8qIRMrXfOsPbyf0z 5/eGtYM9YcbhpX8A+lYIHgtC+ZTnxh8e3mulLCKz8mrmfqCdvewKU4siADLsq0sS8tja 7ULii4Fbl209Ip+dWq+HDsrlaeKmtJIMp9u851gGOI4jlmhAkKg8yjNjNsaKusH1b+ZJ /TQ0Rp8hrzeaDjrzl38sZ5Y6D9X+5oZsAu6wLnKi84IdnXTHe99JaiVqZVFm5AHFsbBN ZHcxqtWiaF5B7xmqllMLkAQO+CTU3VqFxuuXh91A6LHS0wc5u+VKhEEhOXQn4jaY0bCh MSRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LwmX1lTiaCCczI1NPGTxhaGHkbuif3HHQrM659nXr0Y=; b=o3+QsW4BvpL0X0YeFR3+IHKc9+3P7zm+pOmD1AZNmIa648doR2CxqLHa/mC9c+ClMW IMScPRtm3m7OB7f+z13U4AIsT0KXnRNki8UdUEfvNoxx8GBuIAwCImrKMlFgh12zQVe+ vVibruGwM6xztfvGiawchvHGSbHryHROUkeu8xUsTbPYkyb3MyjoEnBxD0ymjF+TzQO4 C+O220FuvPgq0wAWY3uy08i8bT5q/aNZTF/Fswv7SbWEP+1XWKiL/jYzODOjLesWejTA P6IgwqFCbTZelMlKO9wSHTphZX+3MS3JDtDG5tWW8Q0PGvIj2eTyhoSN0xTiRT2PK5EK nl/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FR2Wn4n+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bv4-20020a632e04000000b0051367d909efsi2353242pgb.106.2023.06.09.01.12.18; Fri, 09 Jun 2023 01:12:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=FR2Wn4n+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239134AbjFIHvp (ORCPT + 99 others); Fri, 9 Jun 2023 03:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239403AbjFIHvU (ORCPT ); Fri, 9 Jun 2023 03:51:20 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6F4044A0 for ; Fri, 9 Jun 2023 00:50:39 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-652a6cf1918so1241987b3a.1 for ; Fri, 09 Jun 2023 00:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686297039; x=1688889039; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=LwmX1lTiaCCczI1NPGTxhaGHkbuif3HHQrM659nXr0Y=; b=FR2Wn4n+oAcav3W8ywrHAUlNhIwMJGwIjHBjEMlglZwMUFwfGuCJh2kCw1PnjwAD2R yeLewDqbV07CjbDPe18mNTFxDm37arVJlH9KtqgPRMUp094La7B6zpZ2wF/D6Q0Eg9ky BrjnSXNQHeLJ6oNRT/fErnZgEYwHbPpL13IHc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686297039; x=1688889039; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=LwmX1lTiaCCczI1NPGTxhaGHkbuif3HHQrM659nXr0Y=; b=KM0/Vukaht48ct5S3wUBdaI55/4T+u463+nVRlO+aQ0kewsPpX2T3grsSW3VjZtq8u 4ssAPKCTMGX72yx4mwZ2HuGi4r1Wf9J6BfTWqK2oLCtF/vLWfRGcLzpgFAquSUulBD1m 4JAJ5awp8arpFiiracLi2SrXcTokyrBwRilEm87aVuhNovdmBMj4SUryOHRK5gUNmVGH odt5YbE8PBPV4yd7KG4E9vtp9QoJ+Bj7kIdBpo88UY7AWw8H2mOvR79wnNduEmRE+dvt PVBlzGk6nSPHniC/R09BMeuVj7dUEIdlyZRgh2D28kWg+8QOsQDN5cteh78ca5h2s51d FLfA== X-Gm-Message-State: AC+VfDzjaDWr61lMoHoZzQci9M7f0kcvHKaUHx7WujA4+FzYFCMa4VdU AKBQ3gioFLcswUP+4Y/LLZso2g== X-Received: by 2002:a05:6a21:6da6:b0:10c:ef18:746e with SMTP id wl38-20020a056a216da600b0010cef18746emr314444pzb.58.1686297039199; Fri, 09 Jun 2023 00:50:39 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:c2ea:d8e4:1fe8:21f0]) by smtp.gmail.com with ESMTPSA id r17-20020a170902c61100b001ac84f5559csm2622346plr.126.2023.06.09.00.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 00:50:38 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown , Liam Girdwood , Manivannan Sadhasivam , Cristian Ciocaltea , Matti Vaittinen Cc: Chen-Yu Tsai , linux-actions@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] regulator: Use bitfield values for range selectors Date: Fri, 9 Jun 2023 15:50:30 +0800 Message-ID: <20230609075032.2804554-1-wenst@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Right now the regulator helpers expect raw register values for the range selectors. This is different from the voltage selectors, which are normalized as bitfield values. This leads to a bit of confusion. Also, raw values are harder to copy from datasheets or match up with them, as datasheets will typically have bitfield values. Make the helpers expect bitfield values, and convert existing users. Include bitops.h explicitly for ffs(), and reorder the header include statements. While at it, also replace module.h with export.h, since the only use is EXPORT_SYMBOL_GPL. Signed-off-by: Chen-Yu Tsai --- Changes since v1: - Fixed up bd71847_buck4_volt_range_sel in bd718x7-regulator.c drivers/regulator/atc260x-regulator.c | 2 +- drivers/regulator/bd718x7-regulator.c | 10 +++++----- drivers/regulator/helpers.c | 9 ++++++--- drivers/regulator/tps6287x-regulator.c | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/regulator/atc260x-regulator.c b/drivers/regulator/atc260x-regulator.c index 87e237d740bc..0bba33955a1a 100644 --- a/drivers/regulator/atc260x-regulator.c +++ b/drivers/regulator/atc260x-regulator.c @@ -37,7 +37,7 @@ static const struct linear_range atc2609a_ldo_voltage_ranges1[] = { }; static const unsigned int atc260x_ldo_voltage_range_sel[] = { - 0x0, 0x20, + 0x0, 0x1, }; static int atc260x_dcdc_set_voltage_time_sel(struct regulator_dev *rdev, diff --git a/drivers/regulator/bd718x7-regulator.c b/drivers/regulator/bd718x7-regulator.c index b0b9938c20a1..211ed9861417 100644 --- a/drivers/regulator/bd718x7-regulator.c +++ b/drivers/regulator/bd718x7-regulator.c @@ -289,7 +289,7 @@ static const struct linear_range bd71837_buck5_volts[] = { * and 0x1 for last 3 ranges. */ static const unsigned int bd71837_buck5_volt_range_sel[] = { - 0x0, 0x0, 0x0, 0x80, 0x80, 0x80 + 0x0, 0x0, 0x0, 0x1, 0x1, 0x1 }; /* @@ -309,7 +309,7 @@ static const struct linear_range bd71847_buck3_volts[] = { }; static const unsigned int bd71847_buck3_volt_range_sel[] = { - 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80 + 0x0, 0x0, 0x0, 0x1, 0x2, 0x2, 0x2 }; static const struct linear_range bd71847_buck4_volts[] = { @@ -317,7 +317,7 @@ static const struct linear_range bd71847_buck4_volts[] = { REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000), }; -static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 }; +static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x1 }; /* * BUCK6 @@ -360,7 +360,7 @@ static const struct linear_range bd718xx_ldo1_volts[] = { REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000), }; -static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 }; +static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x1 }; /* * LDO2 @@ -403,7 +403,7 @@ static const struct linear_range bd71847_ldo5_volts[] = { REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000), }; -static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 }; +static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x1 }; /* * LDO6 diff --git a/drivers/regulator/helpers.c b/drivers/regulator/helpers.c index 586f42e378ee..8bdafea70d36 100644 --- a/drivers/regulator/helpers.c +++ b/drivers/regulator/helpers.c @@ -5,13 +5,14 @@ // Copyright 2007, 2008 Wolfson Microelectronics PLC. // Copyright 2008 SlimLogic Ltd. -#include -#include +#include #include +#include +#include +#include #include #include #include -#include #include "internal.h" @@ -108,6 +109,7 @@ static int regulator_range_selector_to_index(struct regulator_dev *rdev, return -EINVAL; rval &= rdev->desc->vsel_range_mask; + rval >>= ffs(rdev->desc->vsel_range_mask) - 1; for (i = 0; i < rdev->desc->n_linear_ranges; i++) { if (rdev->desc->linear_range_selectors[i] == rval) @@ -195,6 +197,7 @@ int regulator_set_voltage_sel_pickable_regmap(struct regulator_dev *rdev, sel += rdev->desc->linear_ranges[i].min_sel; range = rdev->desc->linear_range_selectors[i]; + range <<= ffs(rdev->desc->vsel_mask) - 1; if (rdev->desc->vsel_reg == rdev->desc->vsel_range_reg) { ret = regmap_update_bits(rdev->regmap, diff --git a/drivers/regulator/tps6287x-regulator.c b/drivers/regulator/tps6287x-regulator.c index 870e63ce3ff2..3139a0cbb6f7 100644 --- a/drivers/regulator/tps6287x-regulator.c +++ b/drivers/regulator/tps6287x-regulator.c @@ -41,7 +41,7 @@ static const struct linear_range tps6287x_voltage_ranges[] = { }; static const unsigned int tps6287x_voltage_range_sel[] = { - 0x0, 0x4, 0x8, 0xC + 0x0, 0x1, 0x2, 0x3 }; static const unsigned int tps6287x_ramp_table[] = { -- 2.41.0.162.gfafddb0af9-goog