From patchwork Fri Jun 9 07:50:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chen-Yu Tsai X-Patchwork-Id: 105345 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp781552vqr; Fri, 9 Jun 2023 00:59:47 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4mSMZOnZ6YbuQoTq4j78nAGkEk7TVX8O4CE+/rKyi6b5eQZWy87AaCSCalmIqQK6bog5JT X-Received: by 2002:a17:903:32ca:b0:1ae:50cc:455 with SMTP id i10-20020a17090332ca00b001ae50cc0455mr456063plr.39.1686297587463; Fri, 09 Jun 2023 00:59:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686297587; cv=none; d=google.com; s=arc-20160816; b=IrPY4TnnFphduddtxxgWTkvucrevZbbfp/F6muR8cQrGLgRWtNxG4o/NDD7exT50TB hGs/vOsjHZ3cBIPHZjdjts0fnF2ihNz3CsYAjUmo2896gRfCRuRsB63kBZpy0qWj6iL4 vnZQ55P012KgC2eFKeL4mOCMu8+ZEw2jYamp4Rf1saZw98RcODPtkq08CvyZNatNIcwP Bmuq2GGLHp8C6yteKcCxRCX9uzfI3YiMN60yesxswGignqScihf+otpx8UOrdUihnKwN L1pfB3hrSZqI7UVpnVOjGhtacAAP1xMd6G06+3XqmoSAkJSWG6xrT9vrefLqoZ61yUA8 SzCw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u3-20020a170902e5c300b001ab29399c72si2287089plf.502.2023.06.09.00.59.34; Fri, 09 Jun 2023 00:59:47 -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 S239190AbjFIHvq (ORCPT + 99 others); Fri, 9 Jun 2023 03:51:46 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768211179128753462?= X-GMAIL-MSGID: =?utf-8?q?1768211179128753462?= 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 Reviewed-by: Matti Vaittinen --- 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[] = {