Received: by 2002:ac8:1418:0:b0:3ab:920c:4c8b with SMTP id k24csp3125618qtj; Wed, 18 Jan 2023 13:27:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXur304/0l/s3tP6jhiYHRbfoiFVOhiNsS1VxifnqSLTurlbwf8w5fbQAmyxcE7aJQWbxMj2 X-Received: by 2002:a17:90a:f696:b0:229:1ebf:7dd8 with SMTP id cl22-20020a17090af69600b002291ebf7dd8mr8496710pjb.14.1674077222985; Wed, 18 Jan 2023 13:27:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674077222; cv=none; d=google.com; s=arc-20160816; b=fv4aFV3JVOs9BLCk2C9ry8+dHDNRb52FJ2Y1VYgj1uU1t/5M96bnywwuuHcFLKuAIS cB23m+zI9pvCSEHvb02MIx73KrRB9I7Y0+c5VkNw01WK/AFoyXn43YiEpVGWuxaqfz/t G0O4OxnpNHcTPp/JTXZxqdF2Eiw7dZTrOEd9+cQqmEcBMc+i1BDS+gpcm6Ua7wSYHvOW 1huHZQ6zGd1cM7Lfks+cz0tUv0VK5pBXj++WCWhsY08eXyAQX+vnEfB9b3DjzOn9cz3S e0Ykgg8naLdRJMgDey41ct5cNQ4xMATVpV5tk1iQk75SLXXja549qXF2Ww6n7kQRa+9P 9buw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4lnr9Cr+JUBURO7K4vPAQp8yVZDq1LBmRH21B9XYL6M=; b=GVzhGNsOLCls6FG9s8QJNREkqOQomcUGx1oJT0glv3aazZs59WAqETrSI3D80CQeZn /s6PAmgzxrYh07qDw9QOOprYGqNm2ro71MjB5WBVHRkFgyn+J4/hmbsm8Bs/MXdjtBVy mFpl+sAfKTyXKA75cFWJUQOXMhoxSZIsoQxz7r501Ig8/ZJwgFABHE1RwzD4gYDKEmPG PNmL1RdwHjDbAyi7Ts8BhI5zc4RI5mvm4n7+Azil3Qtx/x5NKd5COd8TnVojblofoEZg jyEoQ5uulP/RdfquaEESu7lnO/u51+BQhOJu1yh6fNldcOufQidxgDr9PJS5l/ue/h65 9v8w== 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 d8-20020a634f08000000b004b124f7a60asi33916500pgb.610.2023.01.18.13.26.57; Wed, 18 Jan 2023 13:27:02 -0800 (PST) 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 S230297AbjARVDr (ORCPT + 46 others); Wed, 18 Jan 2023 16:03:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbjARVDg (ORCPT ); Wed, 18 Jan 2023 16:03:36 -0500 Received: from m-r2.th.seeweb.it (m-r2.th.seeweb.it [5.144.164.171]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A72419686 for ; Wed, 18 Jan 2023 13:03:35 -0800 (PST) Received: from TimeMachine.lan (adsl-dyn97.91-127-229.t-com.sk [91.127.229.97]) by m-r2.th.seeweb.it (Postfix) with ESMTPA id 355373F80C; Wed, 18 Jan 2023 22:03:33 +0100 (CET) From: Martin Botka To: Martin Botka , Andre Przywara Cc: Konrad Dybcio , AngeloGioacchino Del Regno , Marijn Suijten , Jami Kettunen , Paul Bouchara , Jan Trmal , Jernej Skrabec , Samuel Holland , Martin Botka , Lee Jones , Rob Herring , Krzysztof Kozlowski , Chen-Yu Tsai , Liam Girdwood , Mark Brown , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 3/3] regulator: axp20x: Add support for AXP313a variant Date: Wed, 18 Jan 2023 22:03:18 +0100 Message-Id: <20230118210319.464371-4-martin.botka@somainline.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230118210319.464371-1-martin.botka@somainline.org> References: <20230118210319.464371-1-martin.botka@somainline.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 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 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)), + AXP_DESC(AXP313A, LDO2, "ldo2", "vin1", 500, 3500, 100, + AXP313A_DLDO1_CONRTOL, AXP313A_LDO_V_OUT_MASK, + AXP313A_OUTPUT_CONTROL, BIT(4)), + 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) { + dev_err(&pdev->dev, + "DCDC frequency on AXP313a is fixed to 3 MHz.\n"); + return -EINVAL; + } + + return 0; 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