From nobody Thu Nov 14 06:09:15 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2898E81817 for ; Tue, 26 Sep 2023 04:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233640AbjIZEkW (ORCPT ); Tue, 26 Sep 2023 00:40:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233599AbjIZEkT (ORCPT ); Tue, 26 Sep 2023 00:40:19 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C09997 for ; Mon, 25 Sep 2023 21:40:13 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3adcec86a8cso4665308b6e.3 for ; Mon, 25 Sep 2023 21:40:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695703212; x=1696308012; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KeCQHNN67pQ7pJgPPlVJkQB5FjS2X6XolXrY+Dloy10=; b=E9YBVuxJbWHllTVwcaeoClQ6tBw0GPK6czAdtOvYjq9i/nekACITS2iFdN0/GEd2TC qfsANRa0RaH/yCQqmO8RPDwcDCYsGwz4PTfJ6SNX4FkZsMIehVD0qjIP10vjmt5844Qw DUhmW/cV0JYwBr/sGl0r/wUMdJ6VeaRAW8w3I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695703212; x=1696308012; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KeCQHNN67pQ7pJgPPlVJkQB5FjS2X6XolXrY+Dloy10=; b=hR5MSta4WThF3bsu0rHAAbG2S4TNTo0S7dSYGjkpS4W7LZmFxex2ngOKfnlG41Jy3Z uC7cfSQ/68gdpD7aFUlfvk77IL7GrJcGq9ahWXgLqHP9yo8bECZpxys/mwkYSeKHzXY9 uYGmGyd0HwXXz1Gb+bCCiB4sRk77vcFnIEqCNnqaIXI1SQwekYoWKiUFbtuFiaO0kEZy 3oA0FGHzp69eUacUBrhxRztF7txkA8lFSD8MqV6uElqCsB5S+jHSAY0TpcD9EEjzTOAH QC9/QSOsbDcda583jgNf9C4s0qH5KCLQI2WVhm+oRW00JVLx4l6B6+4bSrKVp9LNE67a DKqg== X-Gm-Message-State: AOJu0YynT8up7aksNIgzXzZwmDBLcgAR6A3OtmXkl3C0sriDAIs7iq/K u0MgT6wDxQSFQ+J+bTsnYewM1Q== X-Google-Smtp-Source: AGHT+IHehDzy+dlk1eUDD0RZV2ctyJps9+It45O13YJejel9PHZX4R6qjb0iIyY7nNel3o2UK3jpPg== X-Received: by 2002:a05:6870:340d:b0:1dc:797a:daf4 with SMTP id g13-20020a056870340d00b001dc797adaf4mr9384807oah.7.1695703212418; Mon, 25 Sep 2023 21:40:12 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:ba86:87c4:df1a:be60]) by smtp.gmail.com with ESMTPSA id p11-20020a63ab0b000000b00563590be25esm8667210pgf.29.2023.09.25.21.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 21:40:11 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown Cc: Chen-Yu Tsai , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Zhiyong Tao , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH RESEND v3 1/3] regulator: mt6358: Fail probe on unknown chip ID Date: Tue, 26 Sep 2023 12:34:46 +0800 Message-ID: <20230926043450.2353320-2-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog In-Reply-To: <20230926043450.2353320-1-wenst@chromium.org> References: <20230926043450.2353320-1-wenst@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The MT6358 and MT6366 PMICs, and likely many others from MediaTek, have a chip ID register, making the chip semi-discoverable. The driver currently supports two PMICs and expects to be probed on one or the other. It does not account for incorrect mfd driver entries or device trees. While these should not happen, if they do, it could be catastrophic for the device. The driver should be sure the hardware is what it expects. Make the driver fail to probe if the chip ID presented is not a known one. Suggested-by: AngeloGioacchino Del Regno Fixes: f0e3c6261af1 ("regulator: mt6366: Add support for MT6366 regulator") Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno --- drivers/regulator/mt6358-regulator.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt635= 8-regulator.c index 65fbd95f1dbb..4ca8fbf4b3e2 100644 --- a/drivers/regulator/mt6358-regulator.c +++ b/drivers/regulator/mt6358-regulator.c @@ -688,12 +688,18 @@ static int mt6358_regulator_probe(struct platform_dev= ice *pdev) const struct mt6358_regulator_info *mt6358_info; int i, max_regulator, ret; =20 - if (mt6397->chip_id =3D=3D MT6366_CHIP_ID) { - max_regulator =3D MT6366_MAX_REGULATOR; - mt6358_info =3D mt6366_regulators; - } else { + switch (mt6397->chip_id) { + case MT6358_CHIP_ID: max_regulator =3D MT6358_MAX_REGULATOR; mt6358_info =3D mt6358_regulators; + break; + case MT6366_CHIP_ID: + max_regulator =3D MT6366_MAX_REGULATOR; + mt6358_info =3D mt6366_regulators; + break; + default: + dev_err(&pdev->dev, "unsupported chip ID: %d\n", mt6397->chip_id); + return -EINVAL; } =20 ret =3D mt6358_sync_vcn33_setting(&pdev->dev); --=20 2.42.0.515.g380fc7ccd1-goog From nobody Thu Nov 14 06:09:15 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCF35E81817 for ; Tue, 26 Sep 2023 04:40:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233644AbjIZEk2 (ORCPT ); Tue, 26 Sep 2023 00:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233637AbjIZEkV (ORCPT ); Tue, 26 Sep 2023 00:40:21 -0400 Received: from mail-oo1-xc35.google.com (mail-oo1-xc35.google.com [IPv6:2607:f8b0:4864:20::c35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60240B3 for ; Mon, 25 Sep 2023 21:40:15 -0700 (PDT) Received: by mail-oo1-xc35.google.com with SMTP id 006d021491bc7-57bab4e9e1aso2561376eaf.3 for ; Mon, 25 Sep 2023 21:40:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695703214; x=1696308014; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EQhU1RkcH7MjgUWyE/kqZPIAnN+PPGh4wt2Rdh5pkv0=; b=K8QfU4KhRgNakiAdKwmfrWjPvYqSw3nu9DfoFwAgEA7GIuLeRzvPMLSr6wE1p+j1et PwIFle+QFXDL0Be9StgCe/zgKJr93LAXoibhbtNX5Oihk/Ub8udAxmED7jP2Asd2vajK CP97vvcTrcPCllrxl1FvhP2piMtM7mlZVAq+k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695703214; x=1696308014; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EQhU1RkcH7MjgUWyE/kqZPIAnN+PPGh4wt2Rdh5pkv0=; b=fEhhVyNRf5DCQR8X4z2hsO9DB72/2Kk4RsDxUyB5KNy9BIlP5OGilufJyDSvuTPD33 oyQa6w04S8XVW/mBe4bjWe52KtXGil8zPABQ4qL44LoTf+v666h6isuAEmSIsQYJpelX 3mz5qEsZAwNO7qNuHwu72K+pl/Odol5BwkL188Ss1ClD9F+dLL6VJypqf1bjq4ik0g3E Qse6007dxr5mBen96qV04QOwB5/aX5fgpeQnFuCi65fgl0/T6fkEBu5GHS/jXeq37/m4 2IXD9CTOd9UPjdukBa8+MLaP1vcLWjNGJOZ9alnf4hSTYNJzAvyQzcszLlUMxu8tvoUy axjw== X-Gm-Message-State: AOJu0YxwdykTW44fpAFTkyTz0CfjH6qqCEDjsB/bd2FoFtNkYmCMpaaG GeZDm8CSbPJBNW9Vf41n8vZ5Dg== X-Google-Smtp-Source: AGHT+IEWSTLXw8RQzEFqN1UX9tizE2LvrNAvvFmqQcPF3kAdf+Kqd7mBd/0Vf+yCuYgkkHfxWZqQ9g== X-Received: by 2002:a05:6870:17a7:b0:1bb:4606:5be with SMTP id r39-20020a05687017a700b001bb460605bemr11235714oae.9.1695703214656; Mon, 25 Sep 2023 21:40:14 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:ba86:87c4:df1a:be60]) by smtp.gmail.com with ESMTPSA id p11-20020a63ab0b000000b00563590be25esm8667210pgf.29.2023.09.25.21.40.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 21:40:14 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown Cc: Chen-Yu Tsai , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Zhiyong Tao , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH RESEND v3 2/3] regulator: mt6358: Add output voltage fine tuning to fixed regulators Date: Tue, 26 Sep 2023 12:34:47 +0800 Message-ID: <20230926043450.2353320-3-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog In-Reply-To: <20230926043450.2353320-1-wenst@chromium.org> References: <20230926043450.2353320-1-wenst@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The "fixed" LDO regulators found on the MT6358 and MT6366 PMICs have either no voltage selection register, or only one valid setting. However these do have a fine voltage calibration setting that can slightly boost the output voltage from 0 mV to 100 mV, in 10 mV increments. Add support for this by changing these into linear range regulators. Some register definitions that are missing are also added. Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno Acked-by: Lee Jones --- drivers/regulator/mt6358-regulator.c | 15 +++++++++++++-- include/linux/mfd/mt6358/registers.h | 6 ++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt635= 8-regulator.c index 4ca8fbf4b3e2..f2eb0c14d1ed 100644 --- a/drivers/regulator/mt6358-regulator.c +++ b/drivers/regulator/mt6358-regulator.c @@ -123,10 +123,13 @@ struct mt6358_regulator_info { .type =3D REGULATOR_VOLTAGE, \ .id =3D MT6358_ID_##vreg, \ .owner =3D THIS_MODULE, \ - .n_voltages =3D 1, \ + .n_voltages =3D 11, \ + .vsel_reg =3D MT6358_##vreg##_ANA_CON0, \ + .vsel_mask =3D GENMASK(3, 0), \ .enable_reg =3D enreg, \ .enable_mask =3D BIT(enbit), \ .min_uV =3D volt, \ + .uV_step =3D 10000, \ }, \ .status_reg =3D MT6358_LDO_##vreg##_CON1, \ .qi =3D BIT(15), \ @@ -219,10 +222,13 @@ struct mt6358_regulator_info { .type =3D REGULATOR_VOLTAGE, \ .id =3D MT6366_ID_##vreg, \ .owner =3D THIS_MODULE, \ - .n_voltages =3D 1, \ + .n_voltages =3D 11, \ + .vsel_reg =3D MT6358_##vreg##_ANA_CON0, \ + .vsel_mask =3D GENMASK(3, 0), \ .enable_reg =3D enreg, \ .enable_mask =3D BIT(enbit), \ .min_uV =3D volt, \ + .uV_step =3D 10000, \ }, \ .status_reg =3D MT6358_LDO_##vreg##_CON1, \ .qi =3D BIT(15), \ @@ -488,8 +494,13 @@ static const struct regulator_ops mt6358_volt_table_op= s =3D { .get_status =3D mt6358_get_status, }; =20 +/* "Fixed" LDOs with output voltage calibration +0 ~ +10 mV */ static const struct regulator_ops mt6358_volt_fixed_ops =3D { .list_voltage =3D regulator_list_voltage_linear, + .map_voltage =3D regulator_map_voltage_linear, + .set_voltage_sel =3D regulator_set_voltage_sel_regmap, + .get_voltage_sel =3D mt6358_get_buck_voltage_sel, + .set_voltage_time_sel =3D regulator_set_voltage_time_sel, .enable =3D regulator_enable_regmap, .disable =3D regulator_disable_regmap, .is_enabled =3D regulator_is_enabled_regmap, diff --git a/include/linux/mfd/mt6358/registers.h b/include/linux/mfd/mt635= 8/registers.h index 3d33517f178c..5ea2590be710 100644 --- a/include/linux/mfd/mt6358/registers.h +++ b/include/linux/mfd/mt6358/registers.h @@ -262,6 +262,12 @@ #define MT6358_LDO_VBIF28_CON3 0x1db0 #define MT6358_VCAMA1_ANA_CON0 0x1e08 #define MT6358_VCAMA2_ANA_CON0 0x1e0c +#define MT6358_VFE28_ANA_CON0 0x1e10 +#define MT6358_VCN28_ANA_CON0 0x1e14 +#define MT6358_VBIF28_ANA_CON0 0x1e18 +#define MT6358_VAUD28_ANA_CON0 0x1e1c +#define MT6358_VAUX18_ANA_CON0 0x1e20 +#define MT6358_VXO22_ANA_CON0 0x1e24 #define MT6358_VCN33_ANA_CON0 0x1e28 #define MT6358_VSIM1_ANA_CON0 0x1e2c #define MT6358_VSIM2_ANA_CON0 0x1e30 --=20 2.42.0.515.g380fc7ccd1-goog From nobody Thu Nov 14 06:09:15 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A586E81817 for ; Tue, 26 Sep 2023 04:40:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233320AbjIZEkb (ORCPT ); Tue, 26 Sep 2023 00:40:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232910AbjIZEkZ (ORCPT ); Tue, 26 Sep 2023 00:40:25 -0400 Received: from mail-oa1-x34.google.com (mail-oa1-x34.google.com [IPv6:2001:4860:4864:20::34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD152E9 for ; Mon, 25 Sep 2023 21:40:17 -0700 (PDT) Received: by mail-oa1-x34.google.com with SMTP id 586e51a60fabf-1dc863efb61so4327790fac.0 for ; Mon, 25 Sep 2023 21:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695703217; x=1696308017; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=KsTEiGLEIoP2dw7+MHGjmKSR5eD5gS3NgglU4Z920oU=; b=hJh5odHSTYM75ZLxrFqVlIjD3UVv9BdKWmRk/gGy2EupwemjTA309VD5ZtjszxHqRo HkVjXK0Yf43uUGouP+xOc1+S28LQFK/rnTj6SQzFSQyZxB1JPNiiIDrGvHsq/ylNtuoR XwqUOBRQ4B2r8AjDQPqwoAlkbODMNfzJqIcic= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695703217; x=1696308017; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KsTEiGLEIoP2dw7+MHGjmKSR5eD5gS3NgglU4Z920oU=; b=qynmKmufPHv+mmu5euAVaJ4PHPIiqfJQLtSUMnrXnAY9H1GE/CYd3vQqfg6r0b/9CA c1aymE5VPTHAyqKIQSacsuAV35MRPoClDxyGyTX+srjzQZgSwL92W80S4Ow8pIYcon6u qxpAXWRjY4RV6gTwKd4BO+rBuxVt2c8oVShpU7QPu3gwqAtCvMGO4RArsbcrd7+7BS6K scaVXj4hRxR7gsfqll3o7FdzT/THG3tnkzqKzcXex/RiZeBNr9EYm6J5zv6f19t6cTZL NzCTRji9/f+6UBx5SXvhJM+q9tkDYoK/9Cb51rBnb9U8NnNpCYvwBO5qUy3Pmmch+K8T Pu3w== X-Gm-Message-State: AOJu0YzYJvAU2xiEZlgVePFZAYUGBqShZbaGZ8D9Bc6OYNEyCskradCj uJ51l88lHM2cavAer4jur4rdNQ== X-Google-Smtp-Source: AGHT+IFz+38AnulHRK8KSajuFBpuds9/FzZn/SgTmE237zYOufSKmzP1S0S4i0NkHmQhv68y0tAsBA== X-Received: by 2002:a05:6870:470c:b0:1d5:8da3:f057 with SMTP id b12-20020a056870470c00b001d58da3f057mr10366065oaq.59.1695703216823; Mon, 25 Sep 2023 21:40:16 -0700 (PDT) Received: from wenstp920.tpe.corp.google.com ([2401:fa00:1:10:ba86:87c4:df1a:be60]) by smtp.gmail.com with ESMTPSA id p11-20020a63ab0b000000b00563590be25esm8667210pgf.29.2023.09.25.21.40.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 21:40:16 -0700 (PDT) From: Chen-Yu Tsai To: Mark Brown Cc: Chen-Yu Tsai , Lee Jones , Matthias Brugger , AngeloGioacchino Del Regno , Zhiyong Tao , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Subject: [PATCH RESEND v3 3/3] regulator: mt6358: Add output voltage fine tuning to variable LDOs Date: Tue, 26 Sep 2023 12:34:48 +0800 Message-ID: <20230926043450.2353320-4-wenst@chromium.org> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog In-Reply-To: <20230926043450.2353320-1-wenst@chromium.org> References: <20230926043450.2353320-1-wenst@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Some of the LDO regulators in the MT6358/MT6366 have sparsely populated voltage tables, supported by custom get/set operators. While it works, it requires more code and an extra field to store the lookup table. These LDOs also have fine voltage calibration settings that can slightly boost the output voltage from 0 mV to 100 mV, in 10 mV increments. These combined could be modeled as a pickable set of linear ranges. The coarse voltage setting is modeled as the range selector, while each range has 11 selectors, starting from the range's base voltage, up to +100 mV, in 10mV increments. Signed-off-by: Chen-Yu Tsai Reviewed-by: AngeloGioacchino Del Regno --- drivers/regulator/mt6358-regulator.c | 275 +++++++++++---------------- 1 file changed, 115 insertions(+), 160 deletions(-) diff --git a/drivers/regulator/mt6358-regulator.c b/drivers/regulator/mt635= 8-regulator.c index f2eb0c14d1ed..c4ecac5f3fc8 100644 --- a/drivers/regulator/mt6358-regulator.c +++ b/drivers/regulator/mt6358-regulator.c @@ -26,8 +26,6 @@ struct mt6358_regulator_info { struct regulator_desc desc; u32 status_reg; u32 qi; - const u32 *index_table; - unsigned int n_table; u32 da_vsel_reg; u32 da_vsel_mask; u32 modeset_reg; @@ -64,9 +62,7 @@ struct mt6358_regulator_info { .modeset_mask =3D BIT(_modeset_shift), \ } =20 -#define MT6358_LDO(match, vreg, ldo_volt_table, \ - ldo_index_table, enreg, enbit, vosel, \ - vosel_mask) \ +#define MT6358_LDO(match, vreg, volt_ranges, enreg, enbit, vosel, vosel_ma= sk) \ [MT6358_ID_##vreg] =3D { \ .desc =3D { \ .name =3D #vreg, \ @@ -75,17 +71,19 @@ struct mt6358_regulator_info { .type =3D REGULATOR_VOLTAGE, \ .id =3D MT6358_ID_##vreg, \ .owner =3D THIS_MODULE, \ - .n_voltages =3D ARRAY_SIZE(ldo_volt_table), \ - .volt_table =3D ldo_volt_table, \ - .vsel_reg =3D vosel, \ - .vsel_mask =3D vosel_mask, \ + .n_voltages =3D ARRAY_SIZE(volt_ranges##_ranges) * 11, \ + .linear_ranges =3D volt_ranges##_ranges, \ + .linear_range_selectors_bitfield =3D volt_ranges##_selectors, \ + .n_linear_ranges =3D ARRAY_SIZE(volt_ranges##_ranges), \ + .vsel_range_reg =3D vosel, \ + .vsel_range_mask =3D vosel_mask, \ + .vsel_reg =3D MT6358_##vreg##_ANA_CON0, \ + .vsel_mask =3D GENMASK(3, 0), \ .enable_reg =3D enreg, \ .enable_mask =3D BIT(enbit), \ }, \ .status_reg =3D MT6358_LDO_##vreg##_CON1, \ .qi =3D BIT(15), \ - .index_table =3D ldo_index_table, \ - .n_table =3D ARRAY_SIZE(ldo_index_table), \ } =20 #define MT6358_LDO1(match, vreg, min, max, step, \ @@ -163,9 +161,7 @@ struct mt6358_regulator_info { .modeset_mask =3D BIT(_modeset_shift), \ } =20 -#define MT6366_LDO(match, vreg, ldo_volt_table, \ - ldo_index_table, enreg, enbit, vosel, \ - vosel_mask) \ +#define MT6366_LDO(match, vreg, volt_ranges, enreg, enbit, vosel, vosel_ma= sk) \ [MT6366_ID_##vreg] =3D { \ .desc =3D { \ .name =3D #vreg, \ @@ -174,17 +170,19 @@ struct mt6358_regulator_info { .type =3D REGULATOR_VOLTAGE, \ .id =3D MT6366_ID_##vreg, \ .owner =3D THIS_MODULE, \ - .n_voltages =3D ARRAY_SIZE(ldo_volt_table), \ - .volt_table =3D ldo_volt_table, \ - .vsel_reg =3D vosel, \ - .vsel_mask =3D vosel_mask, \ + .n_voltages =3D ARRAY_SIZE(volt_ranges##_ranges) * 11, \ + .linear_ranges =3D volt_ranges##_ranges, \ + .linear_range_selectors_bitfield =3D volt_ranges##_selectors, \ + .n_linear_ranges =3D ARRAY_SIZE(volt_ranges##_ranges), \ + .vsel_range_reg =3D vosel, \ + .vsel_range_mask =3D vosel_mask, \ + .vsel_reg =3D MT6358_##vreg##_ANA_CON0, \ + .vsel_mask =3D GENMASK(3, 0), \ .enable_reg =3D enreg, \ .enable_mask =3D BIT(enbit), \ }, \ .status_reg =3D MT6358_LDO_##vreg##_CON1, \ .qi =3D BIT(15), \ - .index_table =3D ldo_index_table, \ - .n_table =3D ARRAY_SIZE(ldo_index_table), \ } =20 #define MT6366_LDO1(match, vreg, min, max, step, \ @@ -235,95 +233,95 @@ struct mt6358_regulator_info { } =20 =20 -static const unsigned int vdram2_voltages[] =3D { - 600000, 1800000, -}; - -static const unsigned int vsim_voltages[] =3D { - 1700000, 1800000, 2700000, 3000000, 3100000, -}; - -static const unsigned int vibr_voltages[] =3D { - 1200000, 1300000, 1500000, 1800000, - 2000000, 2800000, 3000000, 3300000, +/* VDRAM2 voltage selector not shown in datasheet */ +static const unsigned int vdram2_selectors[] =3D { 0, 12 }; +static const struct linear_range vdram2_ranges[] =3D { + REGULATOR_LINEAR_RANGE(600000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), }; =20 -static const unsigned int vusb_voltages[] =3D { - 3000000, 3100000, +static const unsigned int vsim_selectors[] =3D { 3, 4, 8, 11, 12 }; +static const struct linear_range vsim_ranges[] =3D { + REGULATOR_LINEAR_RANGE(1700000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2700000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3100000, 0, 10, 10000), }; =20 -static const unsigned int vcamd_voltages[] =3D { - 900000, 1000000, 1100000, 1200000, - 1300000, 1500000, 1800000, +static const unsigned int vibr_selectors[] =3D { 0, 1, 2, 4, 5, 9, 11, 13 = }; +static const struct linear_range vibr_ranges[] =3D { + REGULATOR_LINEAR_RANGE(1200000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1300000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1500000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3300000, 0, 10, 10000), }; =20 -static const unsigned int vefuse_voltages[] =3D { - 1700000, 1800000, 1900000, +/* VUSB voltage selector not shown in datasheet */ +static const unsigned int vusb_selectors[] =3D { 3, 4 }; +static const struct linear_range vusb_ranges[] =3D { + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3100000, 0, 10, 10000), }; =20 -static const unsigned int vmch_vemc_voltages[] =3D { - 2900000, 3000000, 3300000, +static const unsigned int vcamd_selectors[] =3D { 3, 4, 5, 6, 7, 9, 12 }; +static const struct linear_range vcamd_ranges[] =3D { + REGULATOR_LINEAR_RANGE(900000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1100000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1200000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1300000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1500000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), }; =20 -static const unsigned int vcama_voltages[] =3D { - 1800000, 2500000, 2700000, - 2800000, 2900000, 3000000, +static const unsigned int vefuse_selectors[] =3D { 11, 12, 13 }; +static const struct linear_range vefuse_ranges[] =3D { + REGULATOR_LINEAR_RANGE(1700000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(1900000, 0, 10, 10000), }; =20 -static const unsigned int vcn33_voltages[] =3D { - 3300000, 3400000, 3500000, +static const unsigned int vmch_vemc_selectors[] =3D { 2, 3, 5 }; +static const struct linear_range vmch_vemc_ranges[] =3D { + REGULATOR_LINEAR_RANGE(2900000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3300000, 0, 10, 10000), }; =20 -static const unsigned int vmc_voltages[] =3D { - 1800000, 2900000, 3000000, 3300000, +static const unsigned int vcama_selectors[] =3D { 0, 7, 9, 10, 11, 12 }; +static const struct linear_range vcama_ranges[] =3D { + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2500000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2700000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2900000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), }; =20 -static const unsigned int vldo28_voltages[] =3D { - 2800000, 3000000, +static const unsigned int vcn33_selectors[] =3D { 1, 2, 3 }; +static const struct linear_range vcn33_ranges[] =3D { + REGULATOR_LINEAR_RANGE(3300000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3400000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3500000, 0, 10, 10000), }; =20 -static const u32 vdram2_idx[] =3D { - 0, 12, +static const unsigned int vmc_selectors[] =3D { 4, 10, 11, 13 }; +static const struct linear_range vmc_ranges[] =3D { + REGULATOR_LINEAR_RANGE(1800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(2900000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3300000, 0, 10, 10000), }; =20 -static const u32 vsim_idx[] =3D { - 3, 4, 8, 11, 12, -}; - -static const u32 vibr_idx[] =3D { - 0, 1, 2, 4, 5, 9, 11, 13, -}; - -static const u32 vusb_idx[] =3D { - 3, 4, -}; - -static const u32 vcamd_idx[] =3D { - 3, 4, 5, 6, 7, 9, 12, -}; - -static const u32 vefuse_idx[] =3D { - 11, 12, 13, -}; - -static const u32 vmch_vemc_idx[] =3D { - 2, 3, 5, -}; - -static const u32 vcama_idx[] =3D { - 0, 7, 9, 10, 11, 12, -}; - -static const u32 vcn33_idx[] =3D { - 1, 2, 3, -}; - -static const u32 vmc_idx[] =3D { - 4, 10, 11, 13, -}; - -static const u32 vldo28_idx[] =3D { - 1, 3, +static const unsigned int vldo28_selectors[] =3D { 1, 3 }; +static const struct linear_range vldo28_ranges[] =3D { + REGULATOR_LINEAR_RANGE(2800000, 0, 10, 10000), + REGULATOR_LINEAR_RANGE(3000000, 0, 10, 10000), }; =20 static unsigned int mt6358_map_mode(unsigned int mode) @@ -332,49 +330,6 @@ static unsigned int mt6358_map_mode(unsigned int mode) REGULATOR_MODE_NORMAL : REGULATOR_MODE_FAST; } =20 -static int mt6358_set_voltage_sel(struct regulator_dev *rdev, - unsigned int selector) -{ - const struct mt6358_regulator_info *info =3D to_regulator_info(rdev->desc= ); - int idx, ret; - const u32 *pvol; - - pvol =3D info->index_table; - - idx =3D pvol[selector]; - idx <<=3D ffs(info->desc.vsel_mask) - 1; - ret =3D regmap_update_bits(rdev->regmap, info->desc.vsel_reg, - info->desc.vsel_mask, idx); - - return ret; -} - -static int mt6358_get_voltage_sel(struct regulator_dev *rdev) -{ - const struct mt6358_regulator_info *info =3D to_regulator_info(rdev->desc= ); - int idx, ret; - u32 selector; - const u32 *pvol; - - ret =3D regmap_read(rdev->regmap, info->desc.vsel_reg, &selector); - if (ret !=3D 0) { - dev_info(&rdev->dev, - "Failed to get mt6358 %s vsel reg: %d\n", - info->desc.name, ret); - return ret; - } - - selector =3D (selector & info->desc.vsel_mask) >> - (ffs(info->desc.vsel_mask) - 1); - pvol =3D info->index_table; - for (idx =3D 0; idx < info->desc.n_voltages; idx++) { - if (pvol[idx] =3D=3D selector) - return idx; - } - - return -EINVAL; -} - static int mt6358_get_buck_voltage_sel(struct regulator_dev *rdev) { const struct mt6358_regulator_info *info =3D to_regulator_info(rdev->desc= ); @@ -483,10 +438,10 @@ static const struct regulator_ops mt6358_volt_range_o= ps =3D { }; =20 static const struct regulator_ops mt6358_volt_table_ops =3D { - .list_voltage =3D regulator_list_voltage_table, - .map_voltage =3D regulator_map_voltage_iterate, - .set_voltage_sel =3D mt6358_set_voltage_sel, - .get_voltage_sel =3D mt6358_get_voltage_sel, + .list_voltage =3D regulator_list_voltage_pickable_linear_range, + .map_voltage =3D regulator_map_voltage_pickable_linear_range, + .set_voltage_sel =3D regulator_set_voltage_sel_pickable_regmap, + .get_voltage_sel =3D regulator_get_voltage_sel_pickable_regmap, .set_voltage_time_sel =3D regulator_set_voltage_time_sel, .enable =3D regulator_enable_regmap, .disable =3D regulator_disable_regmap, @@ -546,34 +501,34 @@ static const struct mt6358_regulator_info mt6358_regu= lators[] =3D { MT6358_REG_FIXED("ldo_vrf18", VRF18, MT6358_LDO_VRF18_CON0, 0, 1800000), MT6358_REG_FIXED("ldo_vaud28", VAUD28, MT6358_LDO_VAUD28_CON0, 0, 2800000), - MT6358_LDO("ldo_vdram2", VDRAM2, vdram2_voltages, vdram2_idx, + MT6358_LDO("ldo_vdram2", VDRAM2, vdram2, MT6358_LDO_VDRAM2_CON0, 0, MT6358_LDO_VDRAM2_ELR0, 0xf), - MT6358_LDO("ldo_vsim1", VSIM1, vsim_voltages, vsim_idx, + MT6358_LDO("ldo_vsim1", VSIM1, vsim, MT6358_LDO_VSIM1_CON0, 0, MT6358_VSIM1_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vibr", VIBR, vibr_voltages, vibr_idx, + MT6358_LDO("ldo_vibr", VIBR, vibr, MT6358_LDO_VIBR_CON0, 0, MT6358_VIBR_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vusb", VUSB, vusb_voltages, vusb_idx, + MT6358_LDO("ldo_vusb", VUSB, vusb, MT6358_LDO_VUSB_CON0_0, 0, MT6358_VUSB_ANA_CON0, 0x700), - MT6358_LDO("ldo_vcamd", VCAMD, vcamd_voltages, vcamd_idx, + MT6358_LDO("ldo_vcamd", VCAMD, vcamd, MT6358_LDO_VCAMD_CON0, 0, MT6358_VCAMD_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vefuse", VEFUSE, vefuse_voltages, vefuse_idx, + MT6358_LDO("ldo_vefuse", VEFUSE, vefuse, MT6358_LDO_VEFUSE_CON0, 0, MT6358_VEFUSE_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vmch", VMCH, vmch_vemc_voltages, vmch_vemc_idx, + MT6358_LDO("ldo_vmch", VMCH, vmch_vemc, MT6358_LDO_VMCH_CON0, 0, MT6358_VMCH_ANA_CON0, 0x700), - MT6358_LDO("ldo_vcama1", VCAMA1, vcama_voltages, vcama_idx, + MT6358_LDO("ldo_vcama1", VCAMA1, vcama, MT6358_LDO_VCAMA1_CON0, 0, MT6358_VCAMA1_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vemc", VEMC, vmch_vemc_voltages, vmch_vemc_idx, + MT6358_LDO("ldo_vemc", VEMC, vmch_vemc, MT6358_LDO_VEMC_CON0, 0, MT6358_VEMC_ANA_CON0, 0x700), - MT6358_LDO("ldo_vcn33", VCN33, vcn33_voltages, vcn33_idx, + MT6358_LDO("ldo_vcn33", VCN33, vcn33, MT6358_LDO_VCN33_CON0_0, 0, MT6358_VCN33_ANA_CON0, 0x300), - MT6358_LDO("ldo_vcama2", VCAMA2, vcama_voltages, vcama_idx, + MT6358_LDO("ldo_vcama2", VCAMA2, vcama, MT6358_LDO_VCAMA2_CON0, 0, MT6358_VCAMA2_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vmc", VMC, vmc_voltages, vmc_idx, + MT6358_LDO("ldo_vmc", VMC, vmc, MT6358_LDO_VMC_CON0, 0, MT6358_VMC_ANA_CON0, 0xf00), - MT6358_LDO("ldo_vldo28", VLDO28, vldo28_voltages, vldo28_idx, + MT6358_LDO("ldo_vldo28", VLDO28, vldo28, MT6358_LDO_VLDO28_CON0_0, 0, MT6358_VLDO28_ANA_CON0, 0x300), - MT6358_LDO("ldo_vsim2", VSIM2, vsim_voltages, vsim_idx, + MT6358_LDO("ldo_vsim2", VSIM2, vsim, MT6358_LDO_VSIM2_CON0, 0, MT6358_VSIM2_ANA_CON0, 0xf00), MT6358_LDO1("ldo_vsram_proc11", VSRAM_PROC11, 500000, 1293750, 6250, MT6358_LDO_VSRAM_PROC11_DBG0, 0x7f00, MT6358_LDO_VSRAM_CON0, 0x7f), @@ -622,25 +577,25 @@ static const struct mt6358_regulator_info mt6366_regu= lators[] =3D { MT6366_REG_FIXED("ldo_vrf18", VRF18, MT6358_LDO_VRF18_CON0, 0, 1800000), MT6366_REG_FIXED("ldo_vaud28", VAUD28, MT6358_LDO_VAUD28_CON0, 0, 2800000), - MT6366_LDO("ldo_vdram2", VDRAM2, vdram2_voltages, vdram2_idx, + MT6366_LDO("ldo_vdram2", VDRAM2, vdram2, MT6358_LDO_VDRAM2_CON0, 0, MT6358_LDO_VDRAM2_ELR0, 0x10), - MT6366_LDO("ldo_vsim1", VSIM1, vsim_voltages, vsim_idx, + MT6366_LDO("ldo_vsim1", VSIM1, vsim, MT6358_LDO_VSIM1_CON0, 0, MT6358_VSIM1_ANA_CON0, 0xf00), - MT6366_LDO("ldo_vibr", VIBR, vibr_voltages, vibr_idx, + MT6366_LDO("ldo_vibr", VIBR, vibr, MT6358_LDO_VIBR_CON0, 0, MT6358_VIBR_ANA_CON0, 0xf00), - MT6366_LDO("ldo_vusb", VUSB, vusb_voltages, vusb_idx, + MT6366_LDO("ldo_vusb", VUSB, vusb, MT6358_LDO_VUSB_CON0_0, 0, MT6358_VUSB_ANA_CON0, 0x700), - MT6366_LDO("ldo_vefuse", VEFUSE, vefuse_voltages, vefuse_idx, + MT6366_LDO("ldo_vefuse", VEFUSE, vefuse, MT6358_LDO_VEFUSE_CON0, 0, MT6358_VEFUSE_ANA_CON0, 0xf00), - MT6366_LDO("ldo_vmch", VMCH, vmch_vemc_voltages, vmch_vemc_idx, + MT6366_LDO("ldo_vmch", VMCH, vmch_vemc, MT6358_LDO_VMCH_CON0, 0, MT6358_VMCH_ANA_CON0, 0x700), - MT6366_LDO("ldo_vemc", VEMC, vmch_vemc_voltages, vmch_vemc_idx, + MT6366_LDO("ldo_vemc", VEMC, vmch_vemc, MT6358_LDO_VEMC_CON0, 0, MT6358_VEMC_ANA_CON0, 0x700), - MT6366_LDO("ldo_vcn33", VCN33, vcn33_voltages, vcn33_idx, + MT6366_LDO("ldo_vcn33", VCN33, vcn33, MT6358_LDO_VCN33_CON0_0, 0, MT6358_VCN33_ANA_CON0, 0x300), - MT6366_LDO("ldo_vmc", VMC, vmc_voltages, vmc_idx, + MT6366_LDO("ldo_vmc", VMC, vmc, MT6358_LDO_VMC_CON0, 0, MT6358_VMC_ANA_CON0, 0xf00), - MT6366_LDO("ldo_vsim2", VSIM2, vsim_voltages, vsim_idx, + MT6366_LDO("ldo_vsim2", VSIM2, vsim, MT6358_LDO_VSIM2_CON0, 0, MT6358_VSIM2_ANA_CON0, 0xf00), MT6366_LDO1("ldo_vsram_proc11", VSRAM_PROC11, 500000, 1293750, 6250, MT6358_LDO_VSRAM_PROC11_DBG0, 0x7f00, MT6358_LDO_VSRAM_CON0, 0x7f), --=20 2.42.0.515.g380fc7ccd1-goog