Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp7675635rwl; Thu, 23 Mar 2023 07:23:29 -0700 (PDT) X-Google-Smtp-Source: AK7set9ABloPXP/JM1Y+9dQBvDO6MnrYLx3+xKl8gJ6mThTX/tmkFE49RLSuD8w4rrp6+XbQqGQm X-Received: by 2002:a05:6a20:9307:b0:d5:f7f5:85e4 with SMTP id r7-20020a056a20930700b000d5f7f585e4mr3584036pzh.22.1679581408742; Thu, 23 Mar 2023 07:23:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679581408; cv=none; d=google.com; s=arc-20160816; b=hk6bDi7BeLTSkXXrBhdPGlwaQRyfd6GLVXimsB4SY55LjeHE/RYeaJPd/chQvXX10/ wXuiJS+ydf1aQT4TnBxcdOqTYpSapvZWkesujEdGnCYxyBYwH0NyAANanJM7yUeW6kio 3fgeDG26+hoTnvmJMuqMLmZ8QdaFOb590sb3bbGQQPqjj49C0XtAX6TF7qamV75cht2/ H/cK/3dp1FE6knvIKoYgbUVUlPhTWlrCsPQIVLQMMhh45ksxXBGaXMMWxsXFE8oWah6Q US84tefYy72+5QZq+1/mPQ/DYHdljkf+OYVsBQXKUyfqRzQgl89ywrdnG2L/vW3dF75H M63w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:reply-to:in-reply-to:references:mime-version; bh=Nr0tvPAwTMzqCSxrQ/q5aEbFBvs2djuySxiK2wGqc04=; b=LGT/4QMM89MJv3P0TNN3ei1zL/DdNQvjiy/ZJHKBEK9yd5hcJswMLDm23ahKEBa2vk G58d3u8wHuYm0wxibDjVVEYse3E0Zce9j78HsLdz3gsv/cbZdYqXqludIegYS0pxT8X4 1gWPLIFYOst0ecgUfeC8heRznYOV7jCmaTHQzH1/Q2RDBU1VEXOednzjTlmTvLbuitUU qemiuBMJ25B7H5PAl8TahGZHhmgxm/z0BG/aoY2erbr5xc/IwdczA6WBQfPdbf7iGbY8 IAYX2jcWXC/ydXnfO8yPEg1P7sMMOC+Qs7aIymQYw86mzeIHfWPtMoHlWNqSUs8z4q5f LlrQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n127-20020a632785000000b004fb3845932esi19433256pgn.576.2023.03.23.07.23.13; Thu, 23 Mar 2023 07:23:28 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229863AbjCWOWE convert rfc822-to-8bit (ORCPT + 99 others); Thu, 23 Mar 2023 10:22:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbjCWOWC (ORCPT ); Thu, 23 Mar 2023 10:22:02 -0400 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45C64128; Thu, 23 Mar 2023 07:21:59 -0700 (PDT) Received: by mail-ed1-f44.google.com with SMTP id ek18so87343022edb.6; Thu, 23 Mar 2023 07:21:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679581317; h=content-transfer-encoding:cc:to:subject:message-id:date:from :reply-to:in-reply-to:references:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KAa1d0YMwYm0v7TACxvjtijlqyjFf5/PSjuBpN/nY0Y=; b=XYPRA5qg6Z5Wb1zYbLPXj+HMQz2D7jU+qGI29K/rk4JMhKTMkyy53bX9MvIuCD88Ki Yz2UmuXaK+exUqbbMZ5sNaNdpgSomQu+tVKivqEA1e00PI7Ef3OX97Cp0/VDMKe+fbdl uCkE4FlPOlxrVE67G1h/0useoOt13eji4bQ+K5WZMt4iEhRa2PYWB2fBX66xJUpm3MnV qBJ1ncZiIAhZpMtQS2xtqvYGziYYohwrd2av2CFB3npf1/gvC3BoCjsIlX/o2kSTxwps K4m2Hn6hcGirQoTaHsZAAAoh734m4cDwKJwvJqAjcBVIwwAKRyYeDLupZ7//Lz5emXN3 CEMg== X-Gm-Message-State: AO0yUKV2AndcP/V1i55QW+lejWDHPAcYwcBFYXqRKJQGx9XUzX84LHWa rcm7hKY4p/LIHuL2GgJuPmzkE5N9PIMMYw== X-Received: by 2002:aa7:db8f:0:b0:4fd:f0a7:e0a1 with SMTP id u15-20020aa7db8f000000b004fdf0a7e0a1mr9841318edt.24.1679581317056; Thu, 23 Mar 2023 07:21:57 -0700 (PDT) Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com. [209.85.128.43]) by smtp.gmail.com with ESMTPSA id i23-20020a508717000000b004af6c5f1805sm9261165edb.52.2023.03.23.07.21.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 23 Mar 2023 07:21:56 -0700 (PDT) Received: by mail-wm1-f43.google.com with SMTP id u1so1244543wmn.5; Thu, 23 Mar 2023 07:21:56 -0700 (PDT) X-Received: by 2002:a7b:c387:0:b0:3df:d8c9:caa1 with SMTP id s7-20020a7bc387000000b003dfd8c9caa1mr783218wmj.1.1679581316251; Thu, 23 Mar 2023 07:21:56 -0700 (PDT) MIME-Version: 1.0 References: <20230120184500.1899814-1-martin.botka@somainline.org> <20230120184500.1899814-4-martin.botka@somainline.org> <20230323135919.4e21f587@donnerap.cambridge.arm.com> In-Reply-To: <20230323135919.4e21f587@donnerap.cambridge.arm.com> Reply-To: wens@csie.org From: Chen-Yu Tsai Date: Thu, 23 Mar 2023 22:21:44 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v8 3/3] regulator: axp20x: Add support for AXP313a variant To: Andre Przywara Cc: Martin Botka , martin.botka1@gmail.com, Konrad Dybcio , AngeloGioacchino Del Regno , Marijn Suijten , Jami Kettunen , Paul Bouchara , Jan Trmal , Jernej Skrabec , Samuel Holland , Lee Jones , Rob Herring , Krzysztof Kozlowski , Liam Girdwood , Mark Brown , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.8 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 On Thu, Mar 23, 2023 at 9:59 PM Andre Przywara wrote: > > On Sat, 28 Jan 2023 01:24:18 +0800 > Chen-Yu Tsai wrote: > > Hi, > > > On Sat, Jan 21, 2023 at 2:45 AM Martin Botka > > wrote: > > > > > > The AXP313a is your typical I2C controlled PMIC, although in a lighter > > > fashion compared to the other X-Powers PMICs: it has only three DCDC > > > rails, three LDOs, and no battery charging support. > > > > > > The AXP313a datasheet does not describe a register to change the DCDC > > > switching frequency, and talks of it being fixed at 3 MHz. The BSP > > > driver hints at a register being able to change that, but we haven't > > > verified that, so leave that one out. It can be added later, if needed > > > and/or required. > > > > The datasheet released by MangoPi says this isn't configurable. The > > thing that is configurable is spread-spectrum operation, and mode > > switching between fixed PWM and hybrid PFM/PWM. So just drop the > > DCDC frequency stuff and use the default code path. > > The default code path is fatal to the driver, so we can't really do this. > axp20x_set_dcdc_freq is *always* called, even when the property is missing, > in this case the frequency will just be 0. > If we don't specify the variant ID in the switch/case, we get an error and > the driver bails out with -EINVAL. > So the minimal implementation would be: > case AXP313A_ID: > return 0; > To be a bit more robust and catch cases where people try to specify some > DCDC frequency, I added this extra check for 3MHz or 0 (no property). Given that it's fixed, it really shouldn't be specified as a property. > > > The third LDO, RTCLDO, is fixed, and cannot even be turned on or off, > > > programmatically. On top of that, its voltage is customisable (either > > > 1.8V or 3.3V), which we cannot describe easily using the existing > > > regulator wrapper functions. This should be fixed properly, using > > > regulator-{min,max}-microvolt in the DT, but this requires more changes > > > to the code. As some other PMICs (AXP2xx, AXP803) seem to paper over the > > > same problem as well, we follow suit here and pretend it's a fixed 1.8V > > > regulator. A proper fix can follow later. The BSP code seems to ignore > > > this regulator altogether. > > > > > > Describe the AXP313A's voltage settings and switch registers, how the > > > voltages are encoded, and connect this to the MFD device via its > > > regulator ID. > > > > > > Signed-off-by: Martin Botka > > > Signed-off-by: Andre Przywara > > > --- > > > drivers/regulator/axp20x-regulator.c | 60 ++++++++++++++++++++++++++++ > > > 1 file changed, 60 insertions(+) > > > > > > diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c > > > index d260c442b788..3087bc98694f 100644 > > > --- a/drivers/regulator/axp20x-regulator.c > > > +++ b/drivers/regulator/axp20x-regulator.c > > > @@ -134,6 +134,11 @@ > > > #define AXP22X_PWR_OUT_DLDO4_MASK BIT_MASK(6) > > > #define AXP22X_PWR_OUT_ALDO3_MASK BIT_MASK(7) > > > > > > +#define AXP313A_DCDC1_NUM_VOLTAGES 107 > > > +#define AXP313A_DCDC23_NUM_VOLTAGES 88 > > > +#define AXP313A_DCDC_V_OUT_MASK GENMASK(6, 0) > > > +#define AXP313A_LDO_V_OUT_MASK GENMASK(4, 0) > > > + > > > #define AXP803_PWR_OUT_DCDC1_MASK BIT_MASK(0) > > > #define AXP803_PWR_OUT_DCDC2_MASK BIT_MASK(1) > > > #define AXP803_PWR_OUT_DCDC3_MASK BIT_MASK(2) > > > @@ -638,6 +643,48 @@ static const struct regulator_desc axp22x_drivevbus_regulator = { > > > .ops = &axp20x_ops_sw, > > > }; > > > > > > +static const struct linear_range axp313a_dcdc1_ranges[] = { > > > + REGULATOR_LINEAR_RANGE(500000, 0, 70, 10000), > > > + REGULATOR_LINEAR_RANGE(1220000, 71, 87, 20000), > > > + REGULATOR_LINEAR_RANGE(1600000, 88, 106, 100000), > > > +}; > > > + > > > +static const struct linear_range axp313a_dcdc2_ranges[] = { > > > + REGULATOR_LINEAR_RANGE(500000, 0, 70, 10000), > > > + REGULATOR_LINEAR_RANGE(1220000, 71, 87, 20000), > > > +}; > > > + > > > +/* > > > + * This is deviating from the datasheet. The values here are taken from the > > > + * BSP driver and have been confirmed by measurements. > > > + */ > > > +static const struct linear_range axp313a_dcdc3_ranges[] = { > > > + REGULATOR_LINEAR_RANGE(500000, 0, 70, 10000), > > > + REGULATOR_LINEAR_RANGE(1220000, 71, 102, 20000), > > > +}; > > > + > > > +static const struct regulator_desc axp313a_regulators[] = { > > > + AXP_DESC_RANGES(AXP313A, DCDC1, "dcdc1", "vin1", > > > + axp313a_dcdc1_ranges, AXP313A_DCDC1_NUM_VOLTAGES, > > > + AXP313A_DCDC1_CONRTOL, AXP313A_DCDC_V_OUT_MASK, > > > + AXP313A_OUTPUT_CONTROL, BIT(0)), > > > + AXP_DESC_RANGES(AXP313A, DCDC2, "dcdc2", "vin2", > > > + axp313a_dcdc2_ranges, AXP313A_DCDC23_NUM_VOLTAGES, > > > + AXP313A_DCDC2_CONRTOL, AXP313A_DCDC_V_OUT_MASK, > > > + AXP313A_OUTPUT_CONTROL, BIT(1)), > > > + AXP_DESC_RANGES(AXP313A, DCDC3, "dcdc3", "vin3", > > > + axp313a_dcdc3_ranges, AXP313A_DCDC23_NUM_VOLTAGES, > > > + AXP313A_DCDC3_CONRTOL, AXP313A_DCDC_V_OUT_MASK, > > > + AXP313A_OUTPUT_CONTROL, BIT(2)), > > > + AXP_DESC(AXP313A, LDO1, "ldo1", "vin1", 500, 3500, 100, > > > + AXP313A_ALDO1_CONRTOL, AXP313A_LDO_V_OUT_MASK, > > > + AXP313A_OUTPUT_CONTROL, BIT(3)), > > > > The datasheet says this one is called ALDO1 ... > > > > > + AXP_DESC(AXP313A, LDO2, "ldo2", "vin1", 500, 3500, 100, > > > + AXP313A_DLDO1_CONRTOL, AXP313A_LDO_V_OUT_MASK, > > > + AXP313A_OUTPUT_CONTROL, BIT(4)), > > > > ... and this one DLDO1. > > Fixed. > > > > > + AXP_DESC_FIXED(AXP313A, RTC_LDO, "rtc-ldo", "vin1", 1800), > > > +}; > > > + > > > /* DCDC ranges shared with AXP813 */ > > > static const struct linear_range axp803_dcdc234_ranges[] = { > > > REGULATOR_LINEAR_RANGE(500000, > > > @@ -1040,6 +1087,15 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) > > > def = 3000; > > > step = 150; > > > break; > > > + case AXP313A_ID: > > > + /* The DCDC PWM frequency seems to be fixed to 3 MHz. */ > > > + if (dcdcfreq != 3000000 && dcdcfreq != 0) { > > > + dev_err(&pdev->dev, > > > + "DCDC frequency on AXP313a is fixed to 3 MHz.\n"); > > > + return -EINVAL; > > > + } > > > + > > > + return 0; > > > > As mentioned above, please drop this. > > As mentioned above, we need at least the variant ID and a "return 0;". Do > you want me to drop the extra checks as well? Doesn't really hurt, and > provides extra info in case people try something stupid. Ah, OK. In that case let's allow the "no property" case, and error out for all any other value set. ChenYu > > Besides the bits mentioned above, this looks OK. > > Thanks! > Andre > > > > > > default: > > > dev_err(&pdev->dev, > > > "Setting DCDC frequency for unsupported AXP variant\n"); > > > @@ -1232,6 +1288,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev) > > > drivevbus = of_property_read_bool(pdev->dev.parent->of_node, > > > "x-powers,drive-vbus-en"); > > > break; > > > + case AXP313A_ID: > > > + regulators = axp313a_regulators; > > > + nregulators = AXP313A_REG_ID_MAX; > > > + break; > > > case AXP803_ID: > > > regulators = axp803_regulators; > > > nregulators = AXP803_REG_ID_MAX; > > > -- > > > 2.39.0 > > > >