From patchwork Sat Apr 1 00:18:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 78048 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp943005vqo; Fri, 31 Mar 2023 18:06:15 -0700 (PDT) X-Google-Smtp-Source: AKy350YxJAdaHFZZkk8BZRE9sx3qxVx0mcRWUo7klr7QuNypxiGAX5fh+Tdk/OJSmkY/T+qqJGmJ X-Received: by 2002:a17:902:e84e:b0:1a1:8860:70e5 with SMTP id t14-20020a170902e84e00b001a1886070e5mr36021398plg.57.1680311175575; Fri, 31 Mar 2023 18:06:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680311175; cv=none; d=google.com; s=arc-20160816; b=kjIvZiT3CQglyRjJx0wbXvcnGoydNw3xUDMnfKdpmC0cBhYn30ENqJ7Oeiyj7fd1Kh +I1hnWJu6Ewi0hH01ppQK5cM3aI0PUnycGoniLMVRkt4ZVDB2f8xIToRfTN/u8kTwjla G4kz6lRjCHeoHkh6+rmL1MSdy2ASDXy9bWAlZ5asCkOxTknBlCjcjm79gSRx/h2Qzmz1 ShkMkXoK2imqJSMDNQ5W1wXTpscqgQPNe8Ya48g7zonJhF3Rl3Fm6WDpCRObo4zML0sD OOFnIXEBNAmR9FSeR8PSmg0B670vqTedmeTa3Pu1ivoamwuC4ogBkNpZj50b00sEFO1Q 30KQ== 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=qn4cF06vFz+tVlNxGfIqRoaR1uEwJsH0sMC09skinwQ=; b=iiz0bwfXM7Uu0bs7oE5ceEDJSfKga4WDg8m8Bz8mRwB6+C9+SpMoDYnmPHjrdo8fdz q/I9MXwrdyei0sHuio19oHN2u4MnkZu0oCDFj4peiBtkc7b5Cb96rxgXSL6q0S7eFs75 xcDTr3RUBKQDA2SA4KAYtUyB2Gm3fme+QeRxqQ9oI/zWDNIQjFha/DQ7JkwGQvL3+UBX wLwYi9w7lS/1ngRUY9DjV6ttJWb4BErytZvWj5qnUiAYyWLpBOp3r8fM0ChOjbuxVOMA rmn1/IKXhGPcv6eRd8B6edcj5Qiy+DVAYe/Z2uGcu81wQLFHQLwTKBDmJ0lpl/+k8Jfk CAAQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 197-20020a6301ce000000b0050bf50ed4f6si3464850pgb.628.2023.03.31.18.06.02; Fri, 31 Mar 2023 18:06:15 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233441AbjDAATE (ORCPT + 99 others); Fri, 31 Mar 2023 20:19:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233399AbjDAATD (ORCPT ); Fri, 31 Mar 2023 20:19:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B81A61D2D1; Fri, 31 Mar 2023 17:19:01 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DA98611FB; Fri, 31 Mar 2023 17:19:45 -0700 (PDT) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D88323F6C4; Fri, 31 Mar 2023 17:18:58 -0700 (PDT) From: Andre Przywara To: Lee Jones , Liam Girdwood , Chen-Yu Tsai , Mark Brown , Krzysztof Kozlowski , Rob Herring Cc: Martin Botka , martin.botka1@gmail.com, Shengyu Qu , Samuel Holland , Jernej Skrabec , linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: [PATCH v10 1/3] dt-bindings: mfd: x-powers,axp152: Document the AXP313a variant Date: Sat, 1 Apr 2023 01:18:48 +0100 Message-Id: <20230401001850.4988-2-andre.przywara@arm.com> X-Mailer: git-send-email 2.35.7 In-Reply-To: <20230401001850.4988-1-andre.przywara@arm.com> References: <20230401001850.4988-1-andre.przywara@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761933970912273498?= X-GMAIL-MSGID: =?utf-8?q?1761933970912273498?= From: Martin Botka The X-Powers AXP313a is a PMIC used on some devices with the Allwinner H616 or H313 SoC. According to the datasheet, the DC/DC converter PWM frequency is fixed (to 3 MHz), so disallow the property that lets us set this frequency for the other PMICs. Signed-off-by: Martin Botka Signed-off-by: Andre Przywara Reviewed-by: Krzysztof Kozlowski Acked-by: Chen-Yu Tsai --- .../devicetree/bindings/mfd/x-powers,axp152.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml b/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml index 2691ac08f5362..ed76b1c58cdf4 100644 --- a/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml +++ b/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml @@ -73,6 +73,16 @@ allOf: required: - interrupts + - if: + properties: + compatible: + contains: + const: x-powers,axp313a + + then: + properties: + x-powers,dcdc-freq: false + properties: compatible: oneOf: @@ -82,6 +92,7 @@ properties: - x-powers,axp209 - x-powers,axp221 - x-powers,axp223 + - x-powers,axp313a - x-powers,axp803 - x-powers,axp806 - x-powers,axp809 From patchwork Sat Apr 1 00:18:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 78047 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp932277vqo; Fri, 31 Mar 2023 17:35:48 -0700 (PDT) X-Google-Smtp-Source: AKy350Zyva5Sg5T0sN8SgEtoEXAhFn3nfJnFR9hlYElaF5e3xlad4SCLCnpxf/g42EAqZtDu3O0+ X-Received: by 2002:aa7:db94:0:b0:4bb:e80c:5667 with SMTP id u20-20020aa7db94000000b004bbe80c5667mr27915515edt.10.1680309347884; Fri, 31 Mar 2023 17:35:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680309347; cv=none; d=google.com; s=arc-20160816; b=EGk1eWZZM8oZ0NoCFKk2GB0KSCIaiBkhcLAC1i3OJFo8ZOZ595EfrpP2Rj8e2jxKA8 zLKtdi0fr6bhDLiFN2R0OOYszR/Ny61KFj+8sCD1Ny0v+soIBviopQgBcmBFz5/MMoLl +Onne0P6+PX1oJ3B5XxZnEJ4RkJEersGxq2g5md5mYtowujxyn4jK89PQDWpG+EpDf5B fLinO4dAghYZc2bWcPU6WEwW0WFKcI3km69oDfkBDglN+J3NgIv/XMH5Vsgf59tBRG3V P4mE6fzBLIA/kWDPaS8TYjw/8PDaEOnSDNoKowC5X08C063MfhKXx0movp/Ab/CRcTBo UFsw== 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=A3cz83D6g5s6qRTCl47bUE2beJc/aUdfGZvbt+LCk7E=; b=Z5Fxy+MKhQhotzT3qmAK2cYwn0YL1UT3piTyzLxW+Y0VQ2ImYkRdD4nq62iH2RVmGi 6FxaQ8aLgNVf7Gp5canniUu2NM/KUuvND98feTRPxLRZOUADKJd872L5zRRyhq5xugxE EjXsfuA8oN4t64FToPst4ytpJhthfcglsZukbMjvGO7+mjLG1b2tNjgr/NukrV1sHU7w RSE6Ossd1BG4qqVcgKdiKl8hOlixSvKmAc82NyZ2lyjhOodFCAyIi6PsWf0onQNsG9LD 3KLrWrHvZ0bShVF4hQVFOqzIkqJlKGX1atu908CBKYOV2ru3n+c3QaHbKDc6kE6DNZDn bOWg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x26-20020aa7dada000000b004af7e6911b7si2698323eds.91.2023.03.31.17.35.21; Fri, 31 Mar 2023 17:35: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233472AbjDAATK (ORCPT + 99 others); Fri, 31 Mar 2023 20:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233468AbjDAATH (ORCPT ); Fri, 31 Mar 2023 20:19:07 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 44A2E1D843 for ; Fri, 31 Mar 2023 17:19:05 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 678331713; Fri, 31 Mar 2023 17:19:49 -0700 (PDT) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3B0033F6C4; Fri, 31 Mar 2023 17:19:01 -0700 (PDT) From: Andre Przywara To: Lee Jones , Liam Girdwood , Chen-Yu Tsai , Mark Brown Cc: Martin Botka , martin.botka1@gmail.com, Shengyu Qu , Samuel Holland , Jernej Skrabec , linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v10 2/3] mfd: axp20x: Add support for AXP313a PMIC Date: Sat, 1 Apr 2023 01:18:49 +0100 Message-Id: <20230401001850.4988-3-andre.przywara@arm.com> X-Mailer: git-send-email 2.35.7 In-Reply-To: <20230401001850.4988-1-andre.przywara@arm.com> References: <20230401001850.4988-1-andre.przywara@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761932054896454829?= X-GMAIL-MSGID: =?utf-8?q?1761932054896454829?= From: Martin Botka The AXP313a is a PMIC chip produced by X-Powers, it can be connected via an I2C bus. The name AXP1530 seems to appear as well, and this is what is used in the BSP driver. From all we know it's the same chip, just a different name. However we have only seen AXP313a chips in the wild, so go with this name. Compared to the other AXP PMICs it's a rather simple affair: just three DCDC converters, three LDOs, and no battery charging support. Describe the regmap and the MFD bits, along with the registers exposed via I2C. Aside from the various regulators, also describe the power key interrupts, and adjust the shutdown handler routine to use a different register than the other PMICs. Eventually advertise the device using the new compatible string. Signed-off-by: Martin Botka Signed-off-by: Andre Przywara Acked-for-MFD-by: Lee Jones Reviewed-by: Chen-Yu Tsai --- drivers/mfd/axp20x-i2c.c | 2 + drivers/mfd/axp20x.c | 78 +++++++++++++++++++++++++++++++++++++- include/linux/mfd/axp20x.h | 32 ++++++++++++++++ 3 files changed, 111 insertions(+), 1 deletion(-) diff --git a/drivers/mfd/axp20x-i2c.c b/drivers/mfd/axp20x-i2c.c index f49fbd3079589..03fb0840a4c0e 100644 --- a/drivers/mfd/axp20x-i2c.c +++ b/drivers/mfd/axp20x-i2c.c @@ -63,6 +63,7 @@ static const struct of_device_id axp20x_i2c_of_match[] = { { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID }, { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID }, { .compatible = "x-powers,axp223", .data = (void *)AXP223_ID }, + { .compatible = "x-powers,axp313a", .data = (void *)AXP313A_ID }, { .compatible = "x-powers,axp803", .data = (void *)AXP803_ID }, { .compatible = "x-powers,axp806", .data = (void *)AXP806_ID }, { }, @@ -76,6 +77,7 @@ static const struct i2c_device_id axp20x_i2c_id[] = { { "axp209", 0 }, { "axp221", 0 }, { "axp223", 0 }, + { "axp313a", 0 }, { "axp803", 0 }, { "axp806", 0 }, { }, diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c index 01a6bbb6d266d..e6d9bf209d048 100644 --- a/drivers/mfd/axp20x.c +++ b/drivers/mfd/axp20x.c @@ -39,6 +39,7 @@ static const char * const axp20x_model_names[] = { "AXP221", "AXP223", "AXP288", + "AXP313a", "AXP803", "AXP806", "AXP809", @@ -154,6 +155,25 @@ static const struct regmap_range axp806_writeable_ranges[] = { regmap_reg_range(AXP806_REG_ADDR_EXT, AXP806_REG_ADDR_EXT), }; +static const struct regmap_range axp313a_writeable_ranges[] = { + regmap_reg_range(AXP313A_ON_INDICATE, AXP313A_IRQ_STATE), +}; + +static const struct regmap_range axp313a_volatile_ranges[] = { + regmap_reg_range(AXP313A_SHUTDOWN_CTRL, AXP313A_SHUTDOWN_CTRL), + regmap_reg_range(AXP313A_IRQ_STATE, AXP313A_IRQ_STATE), +}; + +static const struct regmap_access_table axp313a_writeable_table = { + .yes_ranges = axp313a_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(axp313a_writeable_ranges), +}; + +static const struct regmap_access_table axp313a_volatile_table = { + .yes_ranges = axp313a_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(axp313a_volatile_ranges), +}; + static const struct regmap_range axp806_volatile_ranges[] = { regmap_reg_range(AXP20X_IRQ1_STATE, AXP20X_IRQ2_STATE), }; @@ -221,6 +241,11 @@ static const struct resource axp288_fuel_gauge_resources[] = { DEFINE_RES_IRQ(AXP288_IRQ_WL1), }; +static const struct resource axp313a_pek_resources[] = { + DEFINE_RES_IRQ_NAMED(AXP313A_IRQ_PEK_RIS_EDGE, "PEK_DBR"), + DEFINE_RES_IRQ_NAMED(AXP313A_IRQ_PEK_FAL_EDGE, "PEK_DBF"), +}; + static const struct resource axp803_pek_resources[] = { DEFINE_RES_IRQ_NAMED(AXP803_IRQ_PEK_RIS_EDGE, "PEK_DBR"), DEFINE_RES_IRQ_NAMED(AXP803_IRQ_PEK_FAL_EDGE, "PEK_DBF"), @@ -272,6 +297,15 @@ static const struct regmap_config axp288_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +static const struct regmap_config axp313a_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .wr_table = &axp313a_writeable_table, + .volatile_table = &axp313a_volatile_table, + .max_register = AXP313A_IRQ_STATE, + .cache_type = REGCACHE_RBTREE, +}; + static const struct regmap_config axp806_regmap_config = { .reg_bits = 8, .val_bits = 8, @@ -415,6 +449,16 @@ static const struct regmap_irq axp288_regmap_irqs[] = { INIT_REGMAP_IRQ(AXP288, BC_USB_CHNG, 5, 1), }; +static const struct regmap_irq axp313a_regmap_irqs[] = { + INIT_REGMAP_IRQ(AXP313A, PEK_RIS_EDGE, 0, 7), + INIT_REGMAP_IRQ(AXP313A, PEK_FAL_EDGE, 0, 6), + INIT_REGMAP_IRQ(AXP313A, PEK_SHORT, 0, 5), + INIT_REGMAP_IRQ(AXP313A, PEK_LONG, 0, 4), + INIT_REGMAP_IRQ(AXP313A, DCDC3_V_LOW, 0, 3), + INIT_REGMAP_IRQ(AXP313A, DCDC2_V_LOW, 0, 2), + INIT_REGMAP_IRQ(AXP313A, DIE_TEMP_HIGH, 0, 0), +}; + static const struct regmap_irq axp803_regmap_irqs[] = { INIT_REGMAP_IRQ(AXP803, ACIN_OVER_V, 0, 7), INIT_REGMAP_IRQ(AXP803, ACIN_PLUGIN, 0, 6), @@ -548,6 +592,17 @@ static const struct regmap_irq_chip axp288_regmap_irq_chip = { }; +static const struct regmap_irq_chip axp313a_regmap_irq_chip = { + .name = "axp313a_irq_chip", + .status_base = AXP313A_IRQ_STATE, + .ack_base = AXP313A_IRQ_STATE, + .unmask_base = AXP313A_IRQ_EN, + .init_ack_masked = true, + .irqs = axp313a_regmap_irqs, + .num_irqs = ARRAY_SIZE(axp313a_regmap_irqs), + .num_regs = 1, +}; + static const struct regmap_irq_chip axp803_regmap_irq_chip = { .name = "axp803", .status_base = AXP20X_IRQ1_STATE, @@ -676,6 +731,11 @@ static const struct mfd_cell axp152_cells[] = { }, }; +static struct mfd_cell axp313a_cells[] = { + MFD_CELL_NAME("axp20x-regulator"), + MFD_CELL_RES("axp313a-pek", axp313a_pek_resources), +}; + static const struct resource axp288_adc_resources[] = { DEFINE_RES_IRQ_NAMED(AXP288_IRQ_GPADC, "GPADC"), }; @@ -828,8 +888,18 @@ static const struct mfd_cell axp813_cells[] = { static int axp20x_power_off(struct sys_off_data *data) { struct axp20x_dev *axp20x = data->cb_data; + unsigned int shutdown_reg; - regmap_write(axp20x->regmap, AXP20X_OFF_CTRL, AXP20X_OFF); + switch (axp20x->variant) { + case AXP313A_ID: + shutdown_reg = AXP313A_SHUTDOWN_CTRL; + break; + default: + shutdown_reg = AXP20X_OFF_CTRL; + break; + } + + regmap_write(axp20x->regmap, shutdown_reg, AXP20X_OFF); /* Give capacitors etc. time to drain to avoid kernel panic msg. */ mdelay(500); @@ -892,6 +962,12 @@ int axp20x_match_device(struct axp20x_dev *axp20x) axp20x->regmap_irq_chip = &axp288_regmap_irq_chip; axp20x->irq_flags = IRQF_TRIGGER_LOW; break; + case AXP313A_ID: + axp20x->nr_cells = ARRAY_SIZE(axp313a_cells); + axp20x->cells = axp313a_cells; + axp20x->regmap_cfg = &axp313a_regmap_config; + axp20x->regmap_irq_chip = &axp313a_regmap_irq_chip; + break; case AXP803_ID: axp20x->nr_cells = ARRAY_SIZE(axp803_cells); axp20x->cells = axp803_cells; diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index 2058194807bd2..edd7fdcc33f91 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -17,6 +17,7 @@ enum axp20x_variants { AXP221_ID, AXP223_ID, AXP288_ID, + AXP313A_ID, AXP803_ID, AXP806_ID, AXP809_ID, @@ -91,6 +92,17 @@ enum axp20x_variants { #define AXP22X_ALDO3_V_OUT 0x2a #define AXP22X_CHRG_CTRL3 0x35 +#define AXP313A_ON_INDICATE 0x00 +#define AXP313A_OUTPUT_CONTROL 0x10 +#define AXP313A_DCDC1_CONRTOL 0x13 +#define AXP313A_DCDC2_CONRTOL 0x14 +#define AXP313A_DCDC3_CONRTOL 0x15 +#define AXP313A_ALDO1_CONRTOL 0x16 +#define AXP313A_DLDO1_CONRTOL 0x17 +#define AXP313A_SHUTDOWN_CTRL 0x1a +#define AXP313A_IRQ_EN 0x20 +#define AXP313A_IRQ_STATE 0x21 + #define AXP806_STARTUP_SRC 0x00 #define AXP806_CHIP_ID 0x03 #define AXP806_PWR_OUT_CTRL1 0x10 @@ -322,6 +334,16 @@ enum { AXP22X_REG_ID_MAX, }; +enum { + AXP313A_DCDC1 = 0, + AXP313A_DCDC2, + AXP313A_DCDC3, + AXP313A_ALDO1, + AXP313A_DLDO1, + AXP313A_RTC_LDO, + AXP313A_REG_ID_MAX, +}; + enum { AXP806_DCDCA = 0, AXP806_DCDCB, @@ -548,6 +570,16 @@ enum axp288_irqs { AXP288_IRQ_BC_USB_CHNG, }; +enum axp313a_irqs { + AXP313A_IRQ_DIE_TEMP_HIGH, + AXP313A_IRQ_DCDC2_V_LOW = 2, + AXP313A_IRQ_DCDC3_V_LOW, + AXP313A_IRQ_PEK_LONG, + AXP313A_IRQ_PEK_SHORT, + AXP313A_IRQ_PEK_FAL_EDGE, + AXP313A_IRQ_PEK_RIS_EDGE, +}; + enum axp803_irqs { AXP803_IRQ_ACIN_OVER_V = 1, AXP803_IRQ_ACIN_PLUGIN, From patchwork Sat Apr 1 00:18:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 78046 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp926788vqo; Fri, 31 Mar 2023 17:23:03 -0700 (PDT) X-Google-Smtp-Source: AKy350Y1/Jsiq/LGRENNxiUvZCR8oO5BNT3q7W7HVaZHK8wUmZpwkPZQzgcnLVoykSycz7FKqcs+ X-Received: by 2002:a17:907:9716:b0:947:79b3:c2fa with SMTP id jg22-20020a170907971600b0094779b3c2famr7218831ejc.17.1680308583230; Fri, 31 Mar 2023 17:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680308583; cv=none; d=google.com; s=arc-20160816; b=lj+d6aE8aLu3h612DMht/Zb2aCkjAzuFTruNLyUYPx2uXTdiZW+a/0Q12+YghwJaMS 1CtlDkHM3UO1clWe27fXeJwE3WJuhgZLSac3sZNIFDUrU+OWVSKGfZVLZJ96G3TpIaXm J+wEM/gnj+/gyjru4syP4QouZ8oIBoYDnzwyuLNoPErdWPx0Bv5mV3Z9Xi0Wg0+thk75 HsloaL/wOwuOlGintTUOdzSznvk9b8WR+gNqwA8odbe8f8jDWcTs3G/0jlyaKtxwruuc byFp/1XQ7y3Xh2v1X4E4N00K7s36ioZBm1s5sOWNvmQ3K8aBKRRxzfCm0Vxcblv9GsN+ DBsw== 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=1XTvgXQYGI/KGRMwiDgWfu44isRaNT9s9Jsc8jeUJGY=; b=pMZl3IYia6f5fWMcz+B1lAi8Q39w8dqZHo8vBTLW+Gjpkz1U2aeJm+zzBJqE4rn3IN 6atCPdUvKQIlwCaOxlBWe0Ymuuj9KOBgM029kauJCgPFTklBXKyOBfa41x5wRGijNXxl kDdXdKjTkUTYiUk2rqug/pkq121FrGS07r9SjxZtX+pfUFy8GSFTPcE428z/SxwfJBS6 NWxEReSRQqUwI96ufIAfIMEbIeVfizk+E4qaYqveBiwCAwXV97/mmku06zeoKIiywcc/ Muy8FwPHtvL01s5vgDKXd4aU7cgLMdf5519Kk9EmNy8lC8ve8A4FCMJANLo7do2Qzzbm p36A== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f10-20020a170906560a00b008d4d102a7b8si2574113ejq.365.2023.03.31.17.22.38; Fri, 31 Mar 2023 17:23:03 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233478AbjDAATM (ORCPT + 99 others); Fri, 31 Mar 2023 20:19:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233465AbjDAATJ (ORCPT ); Fri, 31 Mar 2023 20:19:09 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA49C1D876 for ; Fri, 31 Mar 2023 17:19:07 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1F17F106F; Fri, 31 Mar 2023 17:19:52 -0700 (PDT) Received: from slackpad.fritz.box (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 472D03F6C4; Fri, 31 Mar 2023 17:19:05 -0700 (PDT) From: Andre Przywara To: Lee Jones , Liam Girdwood , Chen-Yu Tsai , Mark Brown Cc: Martin Botka , martin.botka1@gmail.com, Shengyu Qu , Samuel Holland , Jernej Skrabec , linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v10 3/3] regulator: axp20x: Add support for AXP313a variant Date: Sat, 1 Apr 2023 01:18:50 +0100 Message-Id: <20230401001850.4988-4-andre.przywara@arm.com> X-Mailer: git-send-email 2.35.7 In-Reply-To: <20230401001850.4988-1-andre.przywara@arm.com> References: <20230401001850.4988-1-andre.przywara@arm.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761931252691141815?= X-GMAIL-MSGID: =?utf-8?q?1761931252691141815?= From: Martin Botka 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. Check that the property allowing to change that frequency is absent from the DT, and bail out otherwise. 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 Reviewed-by: Chen-Yu Tsai Reviewed-by: Mark Brown --- 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 d260c442b788d..81f339009df9b 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, ALDO1, "aldo1", "vin1", 500, 3500, 100, + AXP313A_ALDO1_CONRTOL, AXP313A_LDO_V_OUT_MASK, + AXP313A_OUTPUT_CONTROL, BIT(3)), + AXP_DESC(AXP313A, DLDO1, "dldo1", "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 != 0) { + 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;