From patchwork Sun Oct 16 23:43:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616368 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 C7EAFC43219 for ; Sun, 16 Oct 2022 23:42:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229894AbiJPXmT (ORCPT ); Sun, 16 Oct 2022 19:42:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbiJPXmS (ORCPT ); Sun, 16 Oct 2022 19:42:18 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88AAC13D68; Sun, 16 Oct 2022 16:42:17 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id i131-20020a1c3b89000000b003c6c154d528so4451762wma.4; Sun, 16 Oct 2022 16:42:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=p8WgOnqzsVIcwM2hwBH1ea3tXcJUTMam+tnMayl18pQ=; b=loCBswe7W5OffBB4isgFvCHt5qA62IhRzDSaInfeKsrWfq3Q8wPL9j5TlLOSl4fcP8 HT+b3Fc9UMFDm+6HP6uC0aeitQx5VnCdBbJnstvpuHYxLdx8j0c4FMAf4ec+mrAnYusl RcRfVd8yyb9Qcw0f+ODXTFfMKFsWpsqfVWJTh4ulhU4cnqp41wtVFTSbbrlIcmTPLCcd VuvanJewga4E0gs3MDwt+++OOEBWR8981SJ7RBKacwVLCni9ZVyITghKUu1KGvvWEYMJ E+n+YLcPTv9Eu3ZP8IjQ9y4VrDDXqdt5ZhMpxL11CNXUcZT2H4mLUKJE/I+348XRhhkN 3g1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=p8WgOnqzsVIcwM2hwBH1ea3tXcJUTMam+tnMayl18pQ=; b=IfHJKx57l+k4VyGq3n6y/2ME6cD9zohNx1nAfAjxhw4p91nYXX+0h+XnqnYNxZyJ6c cv53j3cC+tlXCUQS/mpv7rG1xsyw8oJp5BKg0+/HFLC7uCP7RKmDkIfXM3Fr1LJ05lHK UusyYm94rVuVIkQU4puMz5kCIljI9wK090cOlFZBst9rrkLct/Re5g8wIlHC4+h8d4fJ ntGd/9Gfyo6Y42VadiaIpvBci3ipt5yigYusbWeOPXoVXhJ5E1GDdvQ+OoF9SItnwChU 8IMwMvjEh7DKcSJHtsB4zJOUQrHlCkbKmy6ttRtMKVKOCrdATcPa8nuQmdyPMOm/lVc8 5u0g== X-Gm-Message-State: ACrzQf37DXQjGtaYbvCDRL5/p3jG/bFJVHTSweMl2PwqVU5BJGzrdc39 DDFvhuGoHvrq6i8ktvDz7vo= X-Google-Smtp-Source: AMsMyM5eik2T/bnArxDDhgOKiZOZwBmt6hxrOloBDQjAaYF5dkvzOM9fC17hAXAVG/PcuQhpJC8Kxw== X-Received: by 2002:a05:600c:4e51:b0:3c0:55e0:7719 with SMTP id e17-20020a05600c4e5100b003c055e07719mr5569381wmq.3.1665963736070; Sun, 16 Oct 2022 16:42:16 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id bv20-20020a0560001f1400b00231a5fa1ae2sm6950749wrb.20.2022.10.16.16.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:15 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring Subject: [PATCH v6 01/13] dt-bindings: mfd: add bindings for AXP192 MFD device Date: Mon, 17 Oct 2022 00:43:23 +0100 Message-Id: <20221016234335.904212-2-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192 is another X-Powers PMIC similar to the existing ones. Acked-by: Rob Herring Acked-by: Chen-Yu Tsai Signed-off-by: Aidan MacDonald --- Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml b/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml index b7a8747d5fa0..db9845add060 100644 --- a/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml +++ b/Documentation/devicetree/bindings/mfd/x-powers,axp152.yaml @@ -84,6 +84,7 @@ properties: oneOf: - enum: - x-powers,axp152 + - x-powers,axp192 - x-powers,axp202 - x-powers,axp209 - x-powers,axp221 From patchwork Sun Oct 16 23:43:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 615640 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 81371C4332F for ; Sun, 16 Oct 2022 23:42:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229633AbiJPXmV (ORCPT ); Sun, 16 Oct 2022 19:42:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229803AbiJPXmU (ORCPT ); Sun, 16 Oct 2022 19:42:20 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F3BB13D68; Sun, 16 Oct 2022 16:42:19 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id bg9-20020a05600c3c8900b003bf249616b0so8787292wmb.3; Sun, 16 Oct 2022 16:42:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=713k9A6cCfEIb7eNKGVtq1FKwXEY5zby7RrWVPQyY24=; b=eyEdwym3MlKxaLg0tiz1H3ve/wbTs4RV4XzkFJNZJVv1fllfY8wrWlh0jYb0y3vu/l M+RLxXsdbJLQFmM//ovIlh0CdXukS2tK8NFtebCP4tuYKRWPkDZVXOOK51B+Dn4qPNQQ fYkVqUjYULqN6P9z9U8hs2wXmH5OFESfYiswlXEltv579j2KyRl20Om7SBLKf86ucJFa 5TCmOh72mIB3lqHqez1cNw2xPdPdFD8Cn0ivAQCIYruAqjpQj7axnqBBCD6+kOiOpUs3 ElBee8n0672BldpXi7tEESuaqXue0LbUdH8mp0kJWe1IbZoPt/2XU68p8WVoEx1+XpmB KDvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=713k9A6cCfEIb7eNKGVtq1FKwXEY5zby7RrWVPQyY24=; b=wb8m9xZ8SxVvr310WdrrSCE2aZYpWl0Pj4ki/mG7FiyYMunXDrxvNxtqwlZjNJrA/W jYcwkDYOlfVtXVBmrM3AGlgt9lbuo9qiwcX4JmevJ1WDnq/9MnI3fxHuuFZ9x0ZBa3pw 52CAkDQLeF/YnXnoPCrjrLu1jXsVoGN9XiXSI1nU+BJtiQW9Q/tVJyktetPg3l3gFSeY punEfB2wE7Eyk1tYixVGtqWRXrbfOcDC+qvlev9Gfs4FbAsOniaNiDkZH3v545HhtdB+ 9DEA2PjeKUIOE9fCt4p4C84XmvamqTDYpfkB9W02YjQ6G/IVkeS05yQd/+K+yNu933OH vYuQ== X-Gm-Message-State: ACrzQf1OEbkzuaG7raqoMM6/XmX1o//TQCXUhfrgY608Wg0hDGtJApCJ /LlaO/J2uTT3dSM/t/x9uio= X-Google-Smtp-Source: AMsMyM6O6jGsOLeRVyzvYrXzNe4Ie/G9bJPjaPPjTIwbs/TuN4dCR/yLgqmoEVgj93JNs2EZP/HndQ== X-Received: by 2002:a05:600c:2f9a:b0:3b4:9bd5:1472 with SMTP id t26-20020a05600c2f9a00b003b49bd51472mr16858598wmn.171.1665963737658; Sun, 16 Oct 2022 16:42:17 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id n14-20020a05600c4f8e00b003b47b80cec3sm13781642wmq.42.2022.10.16.16.42.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:17 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring Subject: [PATCH v6 02/13] dt-bindings: iio: adc: axp209: Add AXP192 compatible Date: Mon, 17 Oct 2022 00:43:24 +0100 Message-Id: <20221016234335.904212-3-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192 is identical to the AXP20x, except for two additional GPIO ADC channels. Acked-by: Rob Herring Reviewed-by: Chen-Yu Tsai Signed-off-by: Aidan MacDonald --- .../bindings/iio/adc/x-powers,axp209-adc.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml index d6d3d8590171..1a68e650ac7d 100644 --- a/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml +++ b/Documentation/devicetree/bindings/iio/adc/x-powers,axp209-adc.yaml @@ -14,6 +14,23 @@ description: | Device is a child of an axp209 multifunction device ADC channels and their indexes per variant: + AXP192 + ------ + 0 | acin_v + 1 | acin_i + 2 | vbus_v + 3 | vbus_i + 4 | pmic_temp + 5 | gpio0_v + 6 | gpio1_v + 7 | gpio2_v + 8 | gpio3_v + 9 | ipsout_v + 10 | batt_v + 11 | batt_chrg_i + 12 | batt_dischrg_i + 13 | ts_v + AXP209 ------ 0 | acin_v @@ -50,6 +67,7 @@ description: | properties: compatible: oneOf: + - const: x-powers,axp192-adc - const: x-powers,axp209-adc - const: x-powers,axp221-adc - const: x-powers,axp813-adc From patchwork Sun Oct 16 23:43:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616367 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 CF66BC433FE for ; Sun, 16 Oct 2022 23:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229927AbiJPXmY (ORCPT ); Sun, 16 Oct 2022 19:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229898AbiJPXmV (ORCPT ); Sun, 16 Oct 2022 19:42:21 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 946DA240AF; Sun, 16 Oct 2022 16:42:20 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id az22-20020a05600c601600b003c6b72797fdso8778586wmb.5; Sun, 16 Oct 2022 16:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=HBGk5yA9hr5t3AA+tWd2/rq303jcXV9PFlMj181BSFI=; b=FhzdIdle7Byp6UdzdLvBMHNqAXydDtYl8lsjaf+sXGSFAyqWiKijaWH6Gwvy2XXdRc 5SuBEo+syYBxHH+A6SALXgimxXRouIkhHCVh+MmkCrrvK9iZCfFFZSDaE7q9yD8lG7Z+ 0r9fXF+ZUB87e7rot1GrdNYtXfXBZ+qlmAZr1EtVZwf4ZW33ei6IWgck3v7oXNmiQpcm D1/0reRUyJDqOOUsjLTQMqjt46oD8wn6PkKsLLcO0K88r8l6hAHkj5pHHLlppGF/sSSw Asp5bFIn9D2HU/LRD0cfH2G/NwacMnNuHJqZbir2cA6sBu89Lsn9+aLxJ32N1T025h65 PlUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=HBGk5yA9hr5t3AA+tWd2/rq303jcXV9PFlMj181BSFI=; b=lxGiQ4GVaLf1ecUn7aSdUxqbfVPC9Y6SGe4LnH+FpvP6RU+5IixagR9dtN0hxHDnz3 Eg40FGD03RAARNlrop8tfYsB5O04MduAK1oZrh6vT37lS5x1iv0s5OdXkVgZ/UuSTLY4 rGfi0hvkOf+SJ/rCTS60l5nHTPQwMCXTSthh5p+yrXPeW4JQxhNun8E3zC5vEwc9x3uA lm/D2gRMnqcd5Vhavm5pY4oiYGT+IiQvyQWwmz+qdNfYiaHDRC4f0oztZ+Xg1oIJaxnN Mk9z/p4yT4wYhEm6DfwUfEIr24fHoObhuqBgDbvty9WYKx8HVbrmBTpfhAboJCUnKm1I Caiw== X-Gm-Message-State: ACrzQf0nk1kkK6Obn+a1SU7ZoEbw5q1kgi0/fAesoHsKx8fY4IBUo+FG z7mHddRiSSYXfVsp/0kPyJ4= X-Google-Smtp-Source: AMsMyM6a1b3h3S0EzopzsnKdRQez9JmYa4UY6asFstktCNSMPY1coWwLPN5UeQ/iX+acJIMRkSrByg== X-Received: by 2002:a05:600c:1c08:b0:3c6:e398:64e0 with SMTP id j8-20020a05600c1c0800b003c6e39864e0mr5455065wms.2.1665963739130; Sun, 16 Oct 2022 16:42:19 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id o14-20020a05600c4fce00b003c6b67426b0sm14315527wmq.12.2022.10.16.16.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:18 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring Subject: [PATCH v6 03/13] dt-bindings: power: supply: axp20x: Add AXP192 compatible Date: Mon, 17 Oct 2022 00:43:25 +0100 Message-Id: <20221016234335.904212-4-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192's USB power supply is similar to the AXP202 but it has different USB current limits and a different offset for the VBUS status register. Acked-by: Rob Herring Signed-off-by: Aidan MacDonald --- .../bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml index 3ce648dd91bd..34b7959d6772 100644 --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-usb-power-supply.yaml @@ -22,6 +22,7 @@ properties: compatible: oneOf: - enum: + - x-powers,axp192-usb-power-supply - x-powers,axp202-usb-power-supply - x-powers,axp221-usb-power-supply - x-powers,axp223-usb-power-supply From patchwork Sun Oct 16 23:43:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 615639 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 EECB5C43219 for ; Sun, 16 Oct 2022 23:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbiJPXmY (ORCPT ); Sun, 16 Oct 2022 19:42:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229916AbiJPXmX (ORCPT ); Sun, 16 Oct 2022 19:42:23 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 065D727150; Sun, 16 Oct 2022 16:42:22 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id n12so15964564wrp.10; Sun, 16 Oct 2022 16:42:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=mkCe7sPSDik6TqNHygx3u2xLVqvEa5+V8b5EsZsfws4=; b=Y3Ze7ElpIWs8oa2OXQ0U5hHbqTe7iv2NUU/HJhcolCUIT5ldNECiF1hWl1IEdSSGR2 ExWGWD35hyRaRQQC8PQoGjhKeACFSWyhG7zDq8z00kZ0JjiD0boYWhGrHFfu8OBUnRcx smFi/7UynZxl2TrXo/sguRN8a+tG67Nvrvdy0KT4ryKU1/o5Z6xyZZlnZK4Ve3FUgI0Y v40VtUp92jDE5KpXIWm/CLNRWmyNHexlzWO6jCgz+Y7xnNC40F1lZaR7hdq6St0P+LaH 8RouuZEpgSAwJ5AFNfWTq/5VztI+oHFfn5tA4wy/hx4HpWUD1gOH037BjV8E6TkOoBxu keVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=mkCe7sPSDik6TqNHygx3u2xLVqvEa5+V8b5EsZsfws4=; b=Bqj3hJkEEPtFVB+kzn8eEoOuOSk+O+Xm6MWg0AZuSyj2i5FCov7R1EwLsqLcaimJNy G3xSoxcSP/K4fE0TAGlQs83eveseO5DlxNs2qnKCT9+cVBYiJuKXnhtA1yB1mlgyCTI/ mVw8KVDUoRCXMp3B34IYBRYNE5HW+o+ckFcDdKD6W9Jw5Nbky517x/FJDNhS1YZ3aW3a qlhGCyzAdr5uEsO87gI5/iBxBfHyBpnDpay/CWTCVHZa/IGSn5tEonObmSjPceD7bpVE VYvWEvHevsTB28d9M/PtOcGL3Ll7cil0m4S4rO8Yuw+6F85kpmewNPq6LiBb8OLtKZW2 CcOA== X-Gm-Message-State: ACrzQf0sKcXRHkjjLWtuLcezC/2T3fgH3wRBCDYTe8W+ovjHOfSjC9cH VJpUE0J7h5nvhhnu1lG+PhQ= X-Google-Smtp-Source: AMsMyM6DaG/YKxnIVQ4FPnil+EcHG751UhYdbn/xbmkSKLY/z7D/J9yEfHX73Hea608b2deDhyEOaA== X-Received: by 2002:a05:6000:2c5:b0:22f:5242:131d with SMTP id o5-20020a05600002c500b0022f5242131dmr4374157wry.228.1665963740536; Sun, 16 Oct 2022 16:42:20 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id h10-20020a5d504a000000b0022a403954c3sm7138795wrt.42.2022.10.16.16.42.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:20 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring Subject: [PATCH v6 04/13] dt-bindings: power: axp20x-battery: Add AXP192 compatible Date: Mon, 17 Oct 2022 00:43:26 +0100 Message-Id: <20221016234335.904212-5-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192's battery charger is similar to the others supported by the axp20x_battery driver. Acked-by: Rob Herring Signed-off-by: Aidan MacDonald --- .../power/supply/x-powers,axp20x-battery-power-supply.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml index e0b95ecbbebd..11f56b07e788 100644 --- a/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml +++ b/Documentation/devicetree/bindings/power/supply/x-powers,axp20x-battery-power-supply.yaml @@ -20,6 +20,7 @@ allOf: properties: compatible: oneOf: + - const: x-powers,axp192-battery-power-supply - const: x-powers,axp202-battery-power-supply - const: x-powers,axp209-battery-power-supply - const: x-powers,axp221-battery-power-supply From patchwork Sun Oct 16 23:43:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616366 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 D3E24C43217 for ; Sun, 16 Oct 2022 23:42:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiJPXma (ORCPT ); Sun, 16 Oct 2022 19:42:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229944AbiJPXm0 (ORCPT ); Sun, 16 Oct 2022 19:42:26 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D6B6240AF; Sun, 16 Oct 2022 16:42:23 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j16so16016668wrh.5; Sun, 16 Oct 2022 16:42:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=RC00DptrKqRetsk1LRqkKtKNlqlCvRvibCIGe0/vrcU=; b=cPyapGYf9cJcRULhQ5FbA7DkfzHxTzHbdtf9318vyYIYad6LqawSug1hM37DJQP3hr 3kFusZ++GViiO+cbkAekh6f+wQEKyPEZ4/f4cNTqFkx1ZdBLndcpzF653yS9MIRYKDb0 RhQefcDb0wImiHvISsUsSvtxvOLtc27bicsjwZqtDalHTmAnZKDDHt02c/DHaL777ufX LsgOYhwxlJqzT+vzfyng0hMQH3gpqo0a1IUFfTQ0zxMioeW8auqXFOfKTI7Hmtk3a724 xZhsPirIwxoYpf7aZ9k6C7yCwth+ge6IqNatLdGzn6m9enB8Oglm2SmtUkiZkxfYSpxT 6c/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=RC00DptrKqRetsk1LRqkKtKNlqlCvRvibCIGe0/vrcU=; b=Im5eLHffWNJC/TQlwJ1WJgLcoRvwsf74uUJ4c8O6szuT2CbhXIe64Wpx9k/C4JIdbH jCXhXoqOC4OBrMhFv/eOME7Fj6IxFukT07UzCzklkf58zhLoW8apYCYGDcvXjijEV4VU MTYPi19AF2H+NjSxfTiSMtMs7CtuhYC0/18+J+be0Meq6Cfcj7mgSnQgrRZ8T+Sn34ND TgyOWlQCrx+50hnIkQmd1W5MaLRg6o9XKZrPYlwm2I+TBMdHxYt2qQJJUiA1LZBKFRio IUKQtXWRF2RMo2DfsVI1BlgADaQ3CfwLC6W0wRLUrE7TkgcgLtTCvUD/edmb9BcqzJRK vODw== X-Gm-Message-State: ACrzQf1ldz5yjBFt3U3589xwvtuIQxYhX71/ECEEXASYhmeIS+uy5uCS 4QbVmgWLnLBbybECcCXbBFI= X-Google-Smtp-Source: AMsMyM5mJpW/aP5MmHFa8Z/gDMObDpoea0p6Sw0QIwijFDeIbttGFkpMJPIw6owjsUsm77FF5yBVlQ== X-Received: by 2002:a5d:4a4d:0:b0:22d:c8cb:8687 with SMTP id v13-20020a5d4a4d000000b0022dc8cb8687mr4499828wrs.554.1665963741858; Sun, 16 Oct 2022 16:42:21 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id c7-20020a05600c0ac700b003c6bd12ac27sm8706305wmr.37.2022.10.16.16.42.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:21 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 05/13] mfd: axp20x: Add support for AXP192 Date: Mon, 17 Oct 2022 00:43:27 +0100 Message-Id: <20221016234335.904212-6-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192 PMIC is similar to the AXP202/AXP209, but with different regulators, additional GPIOs, and a different IRQ register layout. Acked-for-MFD-by: Lee Jones Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/mfd/axp20x-i2c.c | 2 + drivers/mfd/axp20x.c | 141 +++++++++++++++++++++++++++++++++++++ include/linux/mfd/axp20x.h | 84 ++++++++++++++++++++++ 3 files changed, 227 insertions(+) diff --git a/drivers/mfd/axp20x-i2c.c b/drivers/mfd/axp20x-i2c.c index 8fd6727dc30a..88d816adc69b 100644 --- a/drivers/mfd/axp20x-i2c.c +++ b/drivers/mfd/axp20x-i2c.c @@ -60,6 +60,7 @@ static void axp20x_i2c_remove(struct i2c_client *i2c) #ifdef CONFIG_OF static const struct of_device_id axp20x_i2c_of_match[] = { { .compatible = "x-powers,axp152", .data = (void *)AXP152_ID }, + { .compatible = "x-powers,axp192", .data = (void *)AXP192_ID }, { .compatible = "x-powers,axp202", .data = (void *)AXP202_ID }, { .compatible = "x-powers,axp209", .data = (void *)AXP209_ID }, { .compatible = "x-powers,axp221", .data = (void *)AXP221_ID }, @@ -73,6 +74,7 @@ MODULE_DEVICE_TABLE(of, axp20x_i2c_of_match); static const struct i2c_device_id axp20x_i2c_id[] = { { "axp152", 0 }, + { "axp192", 0 }, { "axp202", 0 }, { "axp209", 0 }, { "axp221", 0 }, diff --git a/drivers/mfd/axp20x.c b/drivers/mfd/axp20x.c index 88a212a8168c..7d2949209d77 100644 --- a/drivers/mfd/axp20x.c +++ b/drivers/mfd/axp20x.c @@ -34,6 +34,7 @@ static const char * const axp20x_model_names[] = { "AXP152", + "AXP192", "AXP202", "AXP209", "AXP221", @@ -92,6 +93,35 @@ static const struct regmap_access_table axp20x_volatile_table = { .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges), }; +static const struct regmap_range axp192_writeable_ranges[] = { + regmap_reg_range(AXP192_DATACACHE(0), AXP192_DATACACHE(5)), + regmap_reg_range(AXP192_PWR_OUT_CTRL, AXP192_IRQ5_STATE), + regmap_reg_range(AXP20X_DCDC_MODE, AXP192_N_RSTO_CTRL), + regmap_reg_range(AXP20X_CC_CTRL, AXP20X_CC_CTRL), +}; + +static const struct regmap_range axp192_volatile_ranges[] = { + regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP192_USB_OTG_STATUS), + regmap_reg_range(AXP192_IRQ1_STATE, AXP192_IRQ4_STATE), + regmap_reg_range(AXP192_IRQ5_STATE, AXP192_IRQ5_STATE), + regmap_reg_range(AXP20X_ACIN_V_ADC_H, AXP20X_IPSOUT_V_HIGH_L), + regmap_reg_range(AXP20X_TIMER_CTRL, AXP20X_TIMER_CTRL), + regmap_reg_range(AXP192_GPIO2_0_STATE, AXP192_GPIO2_0_STATE), + regmap_reg_range(AXP192_GPIO4_3_STATE, AXP192_GPIO4_3_STATE), + regmap_reg_range(AXP192_N_RSTO_CTRL, AXP192_N_RSTO_CTRL), + regmap_reg_range(AXP20X_CHRG_CC_31_24, AXP20X_CC_CTRL), +}; + +static const struct regmap_access_table axp192_writeable_table = { + .yes_ranges = axp192_writeable_ranges, + .n_yes_ranges = ARRAY_SIZE(axp192_writeable_ranges), +}; + +static const struct regmap_access_table axp192_volatile_table = { + .yes_ranges = axp192_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(axp192_volatile_ranges), +}; + /* AXP22x ranges are shared with the AXP809, as they cover the same range */ static const struct regmap_range axp22x_writeable_ranges[] = { regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE), @@ -173,6 +203,19 @@ static const struct resource axp152_pek_resources[] = { DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_FAL_EDGE, "PEK_DBF"), }; +static const struct resource axp192_ac_power_supply_resources[] = { + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"), + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"), + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_ACIN_OVER_V, "ACIN_OVER_V"), +}; + +static const struct resource axp192_usb_power_supply_resources[] = { + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"), + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"), + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_VALID, "VBUS_VALID"), + DEFINE_RES_IRQ_NAMED(AXP192_IRQ_VBUS_NOT_VALID, "VBUS_NOT_VALID"), +}; + static const struct resource axp20x_ac_power_supply_resources[] = { DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"), DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"), @@ -245,6 +288,15 @@ static const struct regmap_config axp152_regmap_config = { .cache_type = REGCACHE_RBTREE, }; +static const struct regmap_config axp192_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .wr_table = &axp192_writeable_table, + .volatile_table = &axp192_volatile_table, + .max_register = AXP20X_CC_CTRL, + .cache_type = REGCACHE_RBTREE, +}; + static const struct regmap_config axp20x_regmap_config = { .reg_bits = 8, .val_bits = 8, @@ -304,6 +356,42 @@ static const struct regmap_irq axp152_regmap_irqs[] = { INIT_REGMAP_IRQ(AXP152, GPIO0_INPUT, 2, 0), }; +static const struct regmap_irq axp192_regmap_irqs[] = { + INIT_REGMAP_IRQ(AXP192, ACIN_OVER_V, 0, 7), + INIT_REGMAP_IRQ(AXP192, ACIN_PLUGIN, 0, 6), + INIT_REGMAP_IRQ(AXP192, ACIN_REMOVAL, 0, 5), + INIT_REGMAP_IRQ(AXP192, VBUS_OVER_V, 0, 4), + INIT_REGMAP_IRQ(AXP192, VBUS_PLUGIN, 0, 3), + INIT_REGMAP_IRQ(AXP192, VBUS_REMOVAL, 0, 2), + INIT_REGMAP_IRQ(AXP192, VBUS_V_LOW, 0, 1), + INIT_REGMAP_IRQ(AXP192, BATT_PLUGIN, 1, 7), + INIT_REGMAP_IRQ(AXP192, BATT_REMOVAL, 1, 6), + INIT_REGMAP_IRQ(AXP192, BATT_ENT_ACT_MODE, 1, 5), + INIT_REGMAP_IRQ(AXP192, BATT_EXIT_ACT_MODE, 1, 4), + INIT_REGMAP_IRQ(AXP192, CHARG, 1, 3), + INIT_REGMAP_IRQ(AXP192, CHARG_DONE, 1, 2), + INIT_REGMAP_IRQ(AXP192, BATT_TEMP_HIGH, 1, 1), + INIT_REGMAP_IRQ(AXP192, BATT_TEMP_LOW, 1, 0), + INIT_REGMAP_IRQ(AXP192, DIE_TEMP_HIGH, 2, 7), + INIT_REGMAP_IRQ(AXP192, CHARG_I_LOW, 2, 6), + INIT_REGMAP_IRQ(AXP192, DCDC1_V_LONG, 2, 5), + INIT_REGMAP_IRQ(AXP192, DCDC2_V_LONG, 2, 4), + INIT_REGMAP_IRQ(AXP192, DCDC3_V_LONG, 2, 3), + INIT_REGMAP_IRQ(AXP192, PEK_SHORT, 2, 1), + INIT_REGMAP_IRQ(AXP192, PEK_LONG, 2, 0), + INIT_REGMAP_IRQ(AXP192, N_OE_PWR_ON, 3, 7), + INIT_REGMAP_IRQ(AXP192, N_OE_PWR_OFF, 3, 6), + INIT_REGMAP_IRQ(AXP192, VBUS_VALID, 3, 5), + INIT_REGMAP_IRQ(AXP192, VBUS_NOT_VALID, 3, 4), + INIT_REGMAP_IRQ(AXP192, VBUS_SESS_VALID, 3, 3), + INIT_REGMAP_IRQ(AXP192, VBUS_SESS_END, 3, 2), + INIT_REGMAP_IRQ(AXP192, LOW_PWR_LVL, 3, 0), + INIT_REGMAP_IRQ(AXP192, TIMER, 4, 7), + INIT_REGMAP_IRQ(AXP192, GPIO2_INPUT, 4, 2), + INIT_REGMAP_IRQ(AXP192, GPIO1_INPUT, 4, 1), + INIT_REGMAP_IRQ(AXP192, GPIO0_INPUT, 4, 0), +}; + static const struct regmap_irq axp20x_regmap_irqs[] = { INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7), INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6), @@ -514,6 +602,32 @@ static const struct regmap_irq_chip axp152_regmap_irq_chip = { .num_regs = 3, }; +static unsigned int axp192_get_irq_reg(struct regmap_irq_chip_data *data, + unsigned int base, int index) +{ + /* linear mapping for IRQ1 to IRQ4 */ + if (index < 4) + return base + index; + + /* handle IRQ5 separately */ + if (base == AXP192_IRQ1_EN) + return AXP192_IRQ5_EN; + + return AXP192_IRQ5_STATE; +} + +static const struct regmap_irq_chip axp192_regmap_irq_chip = { + .name = "axp192_irq_chip", + .status_base = AXP192_IRQ1_STATE, + .ack_base = AXP192_IRQ1_STATE, + .unmask_base = AXP192_IRQ1_EN, + .init_ack_masked = true, + .irqs = axp192_regmap_irqs, + .num_irqs = ARRAY_SIZE(axp192_regmap_irqs), + .num_regs = 5, + .get_irq_reg = axp192_get_irq_reg, +}; + static const struct regmap_irq_chip axp20x_regmap_irq_chip = { .name = "axp20x_irq_chip", .status_base = AXP20X_IRQ1_STATE, @@ -588,6 +702,27 @@ static const struct regmap_irq_chip axp809_regmap_irq_chip = { .num_regs = 5, }; +static const struct mfd_cell axp192_cells[] = { + { + .name = "axp192-adc", + .of_compatible = "x-powers,axp192-adc", + }, { + .name = "axp20x-battery-power-supply", + .of_compatible = "x-powers,axp192-battery-power-supply", + }, { + .name = "axp20x-ac-power-supply", + .of_compatible = "x-powers,axp202-ac-power-supply", + .num_resources = ARRAY_SIZE(axp192_ac_power_supply_resources), + .resources = axp192_ac_power_supply_resources, + }, { + .name = "axp20x-usb-power-supply", + .of_compatible = "x-powers,axp192-usb-power-supply", + .num_resources = ARRAY_SIZE(axp192_usb_power_supply_resources), + .resources = axp192_usb_power_supply_resources, + }, + { .name = "axp20x-regulator" }, +}; + static const struct mfd_cell axp20x_cells[] = { { .name = "axp20x-gpio", @@ -874,6 +1009,12 @@ int axp20x_match_device(struct axp20x_dev *axp20x) axp20x->regmap_cfg = &axp152_regmap_config; axp20x->regmap_irq_chip = &axp152_regmap_irq_chip; break; + case AXP192_ID: + axp20x->nr_cells = ARRAY_SIZE(axp192_cells); + axp20x->cells = axp192_cells; + axp20x->regmap_cfg = &axp192_regmap_config; + axp20x->regmap_irq_chip = &axp192_regmap_irq_chip; + break; case AXP202_ID: case AXP209_ID: axp20x->nr_cells = ARRAY_SIZE(axp20x_cells); diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index 9ab0e2fca7ea..c9a9ee8ec246 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -12,6 +12,7 @@ enum axp20x_variants { AXP152_ID = 0, + AXP192_ID, AXP202_ID, AXP209_ID, AXP221_ID, @@ -24,6 +25,7 @@ enum axp20x_variants { NR_AXP20X_VARIANTS, }; +#define AXP192_DATACACHE(m) (0x06 + (m)) #define AXP20X_DATACACHE(m) (0x04 + (m)) /* Power supply */ @@ -45,6 +47,13 @@ enum axp20x_variants { #define AXP152_DCDC_FREQ 0x37 #define AXP152_DCDC_MODE 0x80 +#define AXP192_USB_OTG_STATUS 0x04 +#define AXP192_PWR_OUT_CTRL 0x12 +#define AXP192_DCDC2_V_OUT 0x23 +#define AXP192_DCDC1_V_OUT 0x26 +#define AXP192_DCDC3_V_OUT 0x27 +#define AXP192_LDO2_3_V_OUT 0x28 + #define AXP20X_PWR_INPUT_STATUS 0x00 #define AXP20X_PWR_OP_MODE 0x01 #define AXP20X_USB_OTG_STATUS 0x02 @@ -139,6 +148,17 @@ enum axp20x_variants { #define AXP152_IRQ2_STATE 0x49 #define AXP152_IRQ3_STATE 0x4a +#define AXP192_IRQ1_EN 0x40 +#define AXP192_IRQ2_EN 0x41 +#define AXP192_IRQ3_EN 0x42 +#define AXP192_IRQ4_EN 0x43 +#define AXP192_IRQ1_STATE 0x44 +#define AXP192_IRQ2_STATE 0x45 +#define AXP192_IRQ3_STATE 0x46 +#define AXP192_IRQ4_STATE 0x47 +#define AXP192_IRQ5_EN 0x4a +#define AXP192_IRQ5_STATE 0x4d + #define AXP20X_IRQ1_EN 0x40 #define AXP20X_IRQ2_EN 0x41 #define AXP20X_IRQ3_EN 0x42 @@ -153,6 +173,11 @@ enum axp20x_variants { #define AXP20X_IRQ6_STATE 0x4d /* ADC */ +#define AXP192_GPIO2_V_ADC_H 0x68 +#define AXP192_GPIO2_V_ADC_L 0x69 +#define AXP192_GPIO3_V_ADC_H 0x6a +#define AXP192_GPIO3_V_ADC_L 0x6b + #define AXP20X_ACIN_V_ADC_H 0x56 #define AXP20X_ACIN_V_ADC_L 0x57 #define AXP20X_ACIN_I_ADC_H 0x58 @@ -182,6 +207,8 @@ enum axp20x_variants { #define AXP20X_IPSOUT_V_HIGH_L 0x7f /* Power supply */ +#define AXP192_GPIO30_IN_RANGE 0x85 + #define AXP20X_DCDC_MODE 0x80 #define AXP20X_ADC_EN1 0x82 #define AXP20X_ADC_EN2 0x83 @@ -210,6 +237,16 @@ enum axp20x_variants { #define AXP152_PWM1_FREQ_Y 0x9c #define AXP152_PWM1_DUTY_CYCLE 0x9d +#define AXP192_GPIO0_CTRL 0x90 +#define AXP192_LDO_IO0_V_OUT 0x91 +#define AXP192_GPIO1_CTRL 0x92 +#define AXP192_GPIO2_CTRL 0x93 +#define AXP192_GPIO2_0_STATE 0x94 +#define AXP192_GPIO4_3_CTRL 0x95 +#define AXP192_GPIO4_3_STATE 0x96 +#define AXP192_GPIO2_0_PULL 0x97 +#define AXP192_N_RSTO_CTRL 0x9e + #define AXP20X_GPIO0_CTRL 0x90 #define AXP20X_LDO5_V_OUT 0x91 #define AXP20X_GPIO1_CTRL 0x92 @@ -287,6 +324,17 @@ enum axp20x_variants { #define AXP288_FG_TUNE5 0xed /* Regulators IDs */ +enum { + AXP192_DCDC1 = 0, + AXP192_DCDC2, + AXP192_DCDC3, + AXP192_LDO1, + AXP192_LDO2, + AXP192_LDO3, + AXP192_LDO_IO0, + AXP192_REG_ID_MAX +}; + enum { AXP20X_LDO1 = 0, AXP20X_LDO2, @@ -440,6 +488,42 @@ enum { AXP152_IRQ_GPIO0_INPUT, }; +enum axp192_irqs { + AXP192_IRQ_ACIN_OVER_V = 1, + AXP192_IRQ_ACIN_PLUGIN, + AXP192_IRQ_ACIN_REMOVAL, + AXP192_IRQ_VBUS_OVER_V, + AXP192_IRQ_VBUS_PLUGIN, + AXP192_IRQ_VBUS_REMOVAL, + AXP192_IRQ_VBUS_V_LOW, + AXP192_IRQ_BATT_PLUGIN, + AXP192_IRQ_BATT_REMOVAL, + AXP192_IRQ_BATT_ENT_ACT_MODE, + AXP192_IRQ_BATT_EXIT_ACT_MODE, + AXP192_IRQ_CHARG, + AXP192_IRQ_CHARG_DONE, + AXP192_IRQ_BATT_TEMP_HIGH, + AXP192_IRQ_BATT_TEMP_LOW, + AXP192_IRQ_DIE_TEMP_HIGH, + AXP192_IRQ_CHARG_I_LOW, + AXP192_IRQ_DCDC1_V_LONG, + AXP192_IRQ_DCDC2_V_LONG, + AXP192_IRQ_DCDC3_V_LONG, + AXP192_IRQ_PEK_SHORT = 22, + AXP192_IRQ_PEK_LONG, + AXP192_IRQ_N_OE_PWR_ON, + AXP192_IRQ_N_OE_PWR_OFF, + AXP192_IRQ_VBUS_VALID, + AXP192_IRQ_VBUS_NOT_VALID, + AXP192_IRQ_VBUS_SESS_VALID, + AXP192_IRQ_VBUS_SESS_END, + AXP192_IRQ_LOW_PWR_LVL = 31, + AXP192_IRQ_TIMER, + AXP192_IRQ_GPIO2_INPUT = 37, + AXP192_IRQ_GPIO1_INPUT, + AXP192_IRQ_GPIO0_INPUT, +}; + enum { AXP20X_IRQ_ACIN_OVER_V = 1, AXP20X_IRQ_ACIN_PLUGIN, From patchwork Sun Oct 16 23:43:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 615638 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 B46F2C4167E for ; Sun, 16 Oct 2022 23:42:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229968AbiJPXmb (ORCPT ); Sun, 16 Oct 2022 19:42:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229912AbiJPXm0 (ORCPT ); Sun, 16 Oct 2022 19:42:26 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3990B27170; Sun, 16 Oct 2022 16:42:25 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id u10so16023042wrq.2; Sun, 16 Oct 2022 16:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=cVesUdRnr++muKO+nw0A5YMx26afNvf+61fP6zkLiKQ=; b=IAugVCKWS8iu1mYNPo7x624yhvrgIbtP4XXrcNoyhYsWL3fAto3oNqli2TXyB82xk/ cs/poUkH7S4M18Cnc4r1cbLGzuED9ahz8gXJyOyxSGXTYc6aBMhTpvLUcZyLKEgcGSbJ WQ9db97LwXTqDoli21SimAFakj5iYX0AGbydVjJoSHrdk7MfTazxj4wmsrkmR0c0x1p2 oYQEh33SVn/qiTaaFXssYuPo4l6htg/fd0dXcNIn+liiPqb2rYFTjyj21Z+Tn6+dnvev YKznxwc0Sy9i7i0vCVykDNCD6cNi+DcMUBOFlBSJVyBzJkB0ZGUyk0koMUu9pN/aqCM2 KwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=cVesUdRnr++muKO+nw0A5YMx26afNvf+61fP6zkLiKQ=; b=CceJCXhfrmw3X6S2owhK+XWh6hEYQhT9wgLBPX5nyf8nC6C6pZzZwrvVrXcHix7dK2 t/+CdXOFygG4HCKkQ/1hguQUODPwsSyPs6E8vdnpT0jOV11ELQkIhxb10kqN2wMBXD9O ii3tKzp8Ioq5RRLr82Fmm1GDMnFzaYO7wH+1miOdkO8v5N2WIrxXtlvcGz+68ltOEK+2 qgngVWET/ubxJPysecdiby5OyFGPNLDinVBGF+cENYEp9gyWBK8UHUwmSvcHcwrpPQ+c fFbSzeIThZPk85bEX9wqlUm+oaw5l/I/NHGDyqo2AZ98dpFwNBVaxnfZd7UbLK1Ko7Tv sLxg== X-Gm-Message-State: ACrzQf2k1EBoOi/Ms7Bik9p4s7qHylWwcFxlGS2wx8eK8X0okI8JG9Ef KQGG6pq0ir0KvgiJC5EvVc4= X-Google-Smtp-Source: AMsMyM4XDjA6tZsosCtyFk8qFfnYu7/f7jyhaepXkKvxEqSvxPuZk/FXL4D6qrucXdegd75bfisbiw== X-Received: by 2002:a5d:660d:0:b0:22e:57b6:ebd with SMTP id n13-20020a5d660d000000b0022e57b60ebdmr4657441wru.674.1665963743632; Sun, 16 Oct 2022 16:42:23 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id g16-20020a05600c311000b003c6237e867esm8788653wmo.0.2022.10.16.16.42.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:23 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 06/13] regulator: axp20x: Add support for AXP192 Date: Mon, 17 Oct 2022 00:43:28 +0100 Message-Id: <20221016234335.904212-7-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add support for the AXP192 PMIC. Acked-by: Mark Brown Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/regulator/axp20x-regulator.c | 100 ++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 9 deletions(-) diff --git a/drivers/regulator/axp20x-regulator.c b/drivers/regulator/axp20x-regulator.c index d260c442b788..ee79a9ed0249 100644 --- a/drivers/regulator/axp20x-regulator.c +++ b/drivers/regulator/axp20x-regulator.c @@ -27,6 +27,29 @@ #include #include +#define AXP192_GPIO0_FUNC_MASK GENMASK(2, 0) + +#define AXP192_IO_ENABLED 0x02 +#define AXP192_IO_DISABLED 0x06 + +#define AXP192_WORKMODE_DCDC1_MASK BIT_MASK(3) +#define AXP192_WORKMODE_DCDC2_MASK BIT_MASK(2) +#define AXP192_WORKMODE_DCDC3_MASK BIT_MASK(1) + +#define AXP192_DCDC1_V_OUT_MASK GENMASK(6, 0) +#define AXP192_DCDC2_V_OUT_MASK GENMASK(5, 0) +#define AXP192_DCDC3_V_OUT_MASK GENMASK(6, 0) +#define AXP192_LDO2_V_OUT_MASK GENMASK(7, 4) +#define AXP192_LDO3_V_OUT_MASK GENMASK(3, 0) +#define AXP192_LDO_IO0_V_OUT_MASK GENMASK(7, 4) + +#define AXP192_PWR_OUT_EXTEN_MASK BIT_MASK(6) +#define AXP192_PWR_OUT_DCDC2_MASK BIT_MASK(4) +#define AXP192_PWR_OUT_LDO3_MASK BIT_MASK(3) +#define AXP192_PWR_OUT_LDO2_MASK BIT_MASK(2) +#define AXP192_PWR_OUT_DCDC3_MASK BIT_MASK(1) +#define AXP192_PWR_OUT_DCDC1_MASK BIT_MASK(0) + #define AXP20X_GPIO0_FUNC_MASK GENMASK(3, 0) #define AXP20X_GPIO1_FUNC_MASK GENMASK(3, 0) @@ -375,25 +398,32 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) switch (axp20x->variant) { case AXP209_ID: - if (id == AXP20X_DCDC2) { + if (id == AXP20X_LDO3) { slew_rates = axp209_dcdc2_ldo3_slew_rates; rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates); reg = AXP20X_DCDC2_LDO3_V_RAMP; - mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK | - AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK; + mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK | + AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK; enable = (ramp > 0) ? - AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN : 0; + AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN : 0; break; } - if (id == AXP20X_LDO3) { + fallthrough; + + case AXP192_ID: + /* + * AXP192 and AXP209 share the same DCDC2 ramp configuration + */ + if ((axp20x->variant == AXP209_ID && id == AXP20X_DCDC2) || + (axp20x->variant == AXP192_ID && id == AXP192_DCDC2)) { slew_rates = axp209_dcdc2_ldo3_slew_rates; rate_count = ARRAY_SIZE(axp209_dcdc2_ldo3_slew_rates); reg = AXP20X_DCDC2_LDO3_V_RAMP; - mask = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE_MASK | - AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN_MASK; + mask = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE_MASK | + AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN_MASK; enable = (ramp > 0) ? - AXP20X_DCDC2_LDO3_V_RAMP_LDO3_EN : 0; + AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_EN : 0; break; } @@ -415,7 +445,8 @@ static int axp20x_set_ramp_delay(struct regulator_dev *rdev, int ramp) if (ramp > slew_rates[i]) break; - if (id == AXP20X_DCDC2) + if ((axp20x->variant == AXP209_ID && id == AXP20X_DCDC2) || + (axp20x->variant == AXP192_ID && id == AXP192_DCDC2)) cfg = AXP20X_DCDC2_LDO3_V_RAMP_DCDC2_RATE(i); else cfg = AXP20X_DCDC2_LDO3_V_RAMP_LDO3_RATE(i); @@ -511,6 +542,29 @@ static const struct regulator_ops axp20x_ops_sw = { .is_enabled = regulator_is_enabled_regmap, }; +static const struct regulator_desc axp192_regulators[] = { + AXP_DESC(AXP192, DCDC1, "dcdc1", "vin1", 700, 3500, 25, + AXP192_DCDC1_V_OUT, AXP192_DCDC1_V_OUT_MASK, + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC1_MASK), + AXP_DESC(AXP192, DCDC2, "dcdc2", "vin2", 700, 2275, 25, + AXP192_DCDC2_V_OUT, AXP192_DCDC2_V_OUT_MASK, + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC2_MASK), + AXP_DESC(AXP192, DCDC3, "dcdc3", "vin3", 700, 3500, 25, + AXP192_DCDC3_V_OUT, AXP192_DCDC3_V_OUT_MASK, + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_DCDC3_MASK), + AXP_DESC_FIXED(AXP192, LDO1, "ldo1", "acin", 1250), + AXP_DESC(AXP192, LDO2, "ldo2", "ldoin", 1800, 3300, 100, + AXP192_LDO2_3_V_OUT, AXP192_LDO2_V_OUT_MASK, + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_LDO2_MASK), + AXP_DESC(AXP192, LDO3, "ldo3", "ldoin", 1800, 3300, 100, + AXP192_LDO2_3_V_OUT, AXP192_LDO3_V_OUT_MASK, + AXP192_PWR_OUT_CTRL, AXP192_PWR_OUT_LDO3_MASK), + AXP_DESC_IO(AXP192, LDO_IO0, "ldo_io0", "ips", 700, 3300, 100, + AXP192_LDO_IO0_V_OUT, AXP192_LDO_IO0_V_OUT_MASK, + AXP192_GPIO0_CTRL, AXP192_GPIO0_FUNC_MASK, + AXP192_IO_ENABLED, AXP192_IO_DISABLED), +}; + static const struct linear_range axp20x_ldo4_ranges[] = { REGULATOR_LINEAR_RANGE(1250000, AXP20X_LDO4_V_OUT_1250mV_START, @@ -1008,6 +1062,12 @@ static int axp20x_set_dcdc_freq(struct platform_device *pdev, u32 dcdcfreq) u32 min, max, def, step; switch (axp20x->variant) { + case AXP192_ID: + min = 900; + max = 2025; + def = 1500; + step = 75; + break; case AXP202_ID: case AXP209_ID: min = 750; @@ -1100,6 +1160,24 @@ static int axp20x_set_dcdc_workmode(struct regulator_dev *rdev, int id, u32 work unsigned int mask; switch (axp20x->variant) { + case AXP192_ID: + switch (id) { + case AXP192_DCDC1: + mask = AXP192_WORKMODE_DCDC1_MASK; + break; + case AXP192_DCDC2: + mask = AXP192_WORKMODE_DCDC2_MASK; + break; + case AXP192_DCDC3: + mask = AXP192_WORKMODE_DCDC3_MASK; + break; + default: + return -EINVAL; + } + + workmode <<= ffs(mask) - 1; + break; + case AXP202_ID: case AXP209_ID: if ((id != AXP20X_DCDC2) && (id != AXP20X_DCDC3)) @@ -1220,6 +1298,10 @@ static int axp20x_regulator_probe(struct platform_device *pdev) bool drivevbus = false; switch (axp20x->variant) { + case AXP192_ID: + regulators = axp192_regulators; + nregulators = AXP192_REG_ID_MAX; + break; case AXP202_ID: case AXP209_ID: regulators = axp20x_regulators; From patchwork Sun Oct 16 23:43:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 615637 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 621B8C4167D for ; Sun, 16 Oct 2022 23:42:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbiJPXmr (ORCPT ); Sun, 16 Oct 2022 19:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbiJPXma (ORCPT ); Sun, 16 Oct 2022 19:42:30 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E87F127150; Sun, 16 Oct 2022 16:42:26 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id w18so15994112wro.7; Sun, 16 Oct 2022 16:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=iLzGYWDmP7UYu1QNx5f+Qbth2SePhNiLrOaMsgn1dzA=; b=MZmeAAI6Ahc5u0nPigQy5ddDWdsm7rcBJ8PnwV2YGDnAkxU9KkxHnHWqD5166cOiVu 4eWTXWqQ/bx4S332HPEpUC7Lk4klRm5C9C4vUw8pa+l0OMd/C61x08nAq0C18Ndpc7Cd pF/lqXTWnCJmAZWS/PqvTJ81jHqvv/Jm7PkFM04QPaonNfZtGopr+sJHZdqWg6j1hItt KDsOJBVkIPa7BgV+ao9eWp4XKa+IKWBj+Y8Iou+MVEcrisgf8aDOSnEpXNIU/bu4LB+l 47D0OxMirl4uzr7iPDJQC3E6LIRyi2Bkq/b7Ky/tJasiR0z+zQgyH0KLbSs0MDedPbi9 j0bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iLzGYWDmP7UYu1QNx5f+Qbth2SePhNiLrOaMsgn1dzA=; b=HVvuKuCQn9y/LkvV3LCjdFQJbcY1gJtzHq7fNKNAlni9ONwqwMwUltLnawtKZ0sekL AD36aoIXrW5vBvWlce23/JH6NTkn6G4OXPEBp8zZ+D3IO4+spQ1m8VqZpLUSJzkTtaev H+/KcR7PP3/cIawUnGJZunIt6izjKHlVNiZYHgzfR+skqvYx70sHvCDiL3yiDa38rnwO U7oKa1xVxft5GEAYQTSBJ5uybeMWQA4xlV5jF74L6nfu/EpRN8X97pNMUxX6iK2svQur y85Ef1MRHQ+a5Hh61WzLhPQBR+3AoTGV6RZsXUdJm32yGCbNSNzEa5dDDmpRzxvmfYn5 2kuw== X-Gm-Message-State: ACrzQf1GgcbZiIkiNw7WqLKURttPXFWAUxYORaD2lemqd+MHT21cFxWZ Q+4O0/9JAo3MbyFyGiw7Ego= X-Google-Smtp-Source: AMsMyM7LeDLj/ALhsbjhvbO2NC2tmDEnb4Lln27sAAM8L3wQ4vzUSa03N/jgEKEke+FvA1TtE8wPig== X-Received: by 2002:a5d:530b:0:b0:22e:3e8c:45aa with SMTP id e11-20020a5d530b000000b0022e3e8c45aamr4886492wrv.321.1665963745079; Sun, 16 Oct 2022 16:42:25 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id l15-20020a05600c4f0f00b003c6cc57566fsm13008690wmq.14.2022.10.16.16.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:24 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Subject: [PATCH v6 07/13] iio: adc: axp20x_adc: Minor code cleanups Date: Mon, 17 Oct 2022 00:43:29 +0100 Message-Id: <20221016234335.904212-8-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The code may be clearer if parameters are not re-purposed to hold temporary results like register values, so introduce local variables as necessary to avoid that. Regroup macros based on chip type, and use the FIELD_PREP() macro instead of a hand-rolled version. Suggested-by: Jonathan Cameron Reviewed-by: Chen-Yu Tsai Reviewed-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/iio/adc/axp20x_adc.c | 61 +++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 53bf7d4899d2..ab25e6e1ff65 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -5,6 +5,7 @@ * Quentin Schulz */ +#include #include #include #include @@ -22,20 +23,20 @@ #include #define AXP20X_ADC_EN1_MASK GENMASK(7, 0) - #define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7)) + #define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0)) #define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0) #define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1) -#define AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(x) ((x) & BIT(0)) -#define AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(x) (((x) & BIT(0)) << 1) #define AXP20X_ADC_RATE_MASK GENMASK(7, 6) -#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) -#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK) #define AXP20X_ADC_RATE_HZ(x) ((ilog2((x) / 25) << 6) & AXP20X_ADC_RATE_MASK) + #define AXP22X_ADC_RATE_HZ(x) ((ilog2((x) / 100) << 6) & AXP20X_ADC_RATE_MASK) + +#define AXP813_V_I_ADC_RATE_MASK GENMASK(5, 4) +#define AXP813_ADC_RATE_MASK (AXP20X_ADC_RATE_MASK | AXP813_V_I_ADC_RATE_MASK) #define AXP813_TS_GPIO0_ADC_RATE_HZ(x) AXP20X_ADC_RATE_HZ(x) #define AXP813_V_I_ADC_RATE_HZ(x) ((ilog2((x) / 100) << 4) & AXP813_V_I_ADC_RATE_MASK) #define AXP813_ADC_RATE_HZ(x) (AXP20X_ADC_RATE_HZ(x) | AXP813_V_I_ADC_RATE_HZ(x)) @@ -234,7 +235,7 @@ static int axp20x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); - int size = 12; + int ret, size; /* * N.B.: Unlike the Chinese datasheets tell, the charging current is @@ -246,10 +247,11 @@ static int axp20x_adc_raw(struct iio_dev *indio_dev, else size = 12; - *val = axp20x_read_variable_width(info->regmap, chan->address, size); - if (*val < 0) - return *val; + ret = axp20x_read_variable_width(info->regmap, chan->address, size); + if (ret < 0) + return ret; + *val = ret; return IIO_VAL_INT; } @@ -257,11 +259,13 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); + int ret; - *val = axp20x_read_variable_width(info->regmap, chan->address, 12); - if (*val < 0) - return *val; + ret = axp20x_read_variable_width(info->regmap, chan->address, 12); + if (ret < 0) + return ret; + *val = ret; return IIO_VAL_INT; } @@ -269,11 +273,13 @@ static int axp813_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); + int ret; - *val = axp20x_read_variable_width(info->regmap, chan->address, 12); - if (*val < 0) - return *val; + ret = axp20x_read_variable_width(info->regmap, chan->address, 12); + if (ret < 0) + return ret; + *val = ret; return IIO_VAL_INT; } @@ -443,27 +449,27 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, int *val) { struct axp20x_adc_iio *info = iio_priv(indio_dev); + unsigned int regval; int ret; - ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, val); + ret = regmap_read(info->regmap, AXP20X_GPIO10_IN_RANGE, ®val); if (ret < 0) return ret; switch (channel) { case AXP20X_GPIO0_V: - *val &= AXP20X_GPIO10_IN_RANGE_GPIO0; + regval = FIELD_GET(AXP20X_GPIO10_IN_RANGE_GPIO0, regval); break; case AXP20X_GPIO1_V: - *val &= AXP20X_GPIO10_IN_RANGE_GPIO1; + regval = FIELD_GET(AXP20X_GPIO10_IN_RANGE_GPIO1, regval); break; default: return -EINVAL; } - *val = *val ? 700000 : 0; - + *val = regval ? 700000 : 0; return IIO_VAL_INT; } @@ -548,7 +554,7 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, long mask) { struct axp20x_adc_iio *info = iio_priv(indio_dev); - unsigned int reg, regval; + unsigned int regmask, regval; /* * The AXP20X PMIC allows the user to choose between 0V and 0.7V offsets @@ -560,25 +566,22 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, if (val != 0 && val != 700000) return -EINVAL; - val = val ? 1 : 0; - switch (chan->channel) { case AXP20X_GPIO0_V: - reg = AXP20X_GPIO10_IN_RANGE_GPIO0; - regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(val); + regmask = AXP20X_GPIO10_IN_RANGE_GPIO0; + regval = FIELD_PREP(AXP20X_GPIO10_IN_RANGE_GPIO0, !!val); break; case AXP20X_GPIO1_V: - reg = AXP20X_GPIO10_IN_RANGE_GPIO1; - regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(val); + regmask = AXP20X_GPIO10_IN_RANGE_GPIO1; + regval = FIELD_PREP(AXP20X_GPIO10_IN_RANGE_GPIO1, !!val); break; default: return -EINVAL; } - return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, reg, - regval); + return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, regmask, regval); } static const struct iio_info axp20x_adc_iio_info = { From patchwork Sun Oct 16 23:43:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616365 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 9B574C4332F for ; Sun, 16 Oct 2022 23:42:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229988AbiJPXmr (ORCPT ); Sun, 16 Oct 2022 19:42:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229955AbiJPXma (ORCPT ); Sun, 16 Oct 2022 19:42:30 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8BBE27CFD; Sun, 16 Oct 2022 16:42:26 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j16so16017098wrh.5; Sun, 16 Oct 2022 16:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=9iQ42DvT7kTgetW5TS8dmSiYkpUS6xNSvrMGj0peFw8=; b=o2Qhxs69zm3BrTRBcSq0mgrrFPeS3SQwliVPzpHd97HNYWLvDMxJpdDSpOvb1Fy4ye nA/qOVrkWItaVL3PUdKgaRv9Ag3hQnZuusaA/+tO22hW2AlctKoZhJTi7XPkx0qbuW8T AGj640QhXYm0ZkV+17VFia8V6rHjM33bpOjGq0z/wRdf05n4ziC6SbX8EgeZkaBUNRXW vP5BVPrqGF407P5Fgochq0+HyIp/nZ9QqeNbCapziCpXJC551p+BP8D7tjg8X1xzTlhn hvKL6hqTyb4p/X73JclOclG/WhPthJcvnb5viPAniFUuaVnyzVyHF87zC3GYdOjKpnUg CoLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9iQ42DvT7kTgetW5TS8dmSiYkpUS6xNSvrMGj0peFw8=; b=iIeWHo++uYtWytgvRPVFv4oNW1Q5T9+jzp3ErSwYtHxR48AWsVqPCt7l7064VrfEY6 ey+lgzO6NrXZ+buWMf2LLi4iCgWfE/C7l70MF51shbeImOXhcgMy35Y0uZNztnlD2jBD EKor56wgXbJrxqgTBwqG7tESCl/XCtJjTHJPhyBiNv0bp7rEoYWuALjzcq1jCs/BBWBF I4u1nhsaqvjuMLnix+UTHqT/JYEKXG9VhoZgVw1ZhmC+eBTFIYYPztc3MJJdoPmewEj2 9e6W8aU6mKZzQH+SwUiGW6bZ0xkxaf/spL+WkrXq2CzFEMGkp7JBd0nBSdhMy+PZAZiH iUtg== X-Gm-Message-State: ACrzQf2GRTlX7446y9vDfFhpmOlp2jLM6aSaP0d+ZY4JUonZkTOd4Rby ujhG4o3V0YkJHes14MtIeLI= X-Google-Smtp-Source: AMsMyM61lMMzVHbrWF/FTBy/pbOCUMsGU2H4CyKaCzslxskg3aLjsjEZPWk4Q8+fxjdVwygtNOxeqA== X-Received: by 2002:a5d:4d07:0:b0:22e:3c45:9f00 with SMTP id z7-20020a5d4d07000000b0022e3c459f00mr4573014wrt.646.1665963746468; Sun, 16 Oct 2022 16:42:26 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id f7-20020a1cc907000000b003b31c560a0csm8397203wmb.12.2022.10.16.16.42.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:26 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Subject: [PATCH v6 08/13] iio: adc: axp20x_adc: Replace adc_en2 flag with adc_en2_mask field Date: Mon, 17 Oct 2022 00:43:30 +0100 Message-Id: <20221016234335.904212-9-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The adc_en2 flag is essentially specific to axp20x-compatible devices because it hardcodes register values. Replace it with a mask field so the register value can be specified in device match data. Reviewed-by: Andy Shevchenko Reviewed-by: Jonathan Cameron Signed-off-by: Aidan MacDonald --- drivers/iio/adc/axp20x_adc.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index ab25e6e1ff65..75bda94dbce1 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -623,9 +623,9 @@ struct axp_data { int num_channels; struct iio_chan_spec const *channels; unsigned long adc_en1_mask; + unsigned long adc_en2_mask; int (*adc_rate)(struct axp20x_adc_iio *info, int rate); - bool adc_en2; struct iio_map *maps; }; @@ -634,8 +634,8 @@ static const struct axp_data axp20x_data = { .num_channels = ARRAY_SIZE(axp20x_adc_channels), .channels = axp20x_adc_channels, .adc_en1_mask = AXP20X_ADC_EN1_MASK, + .adc_en2_mask = AXP20X_ADC_EN2_MASK, .adc_rate = axp20x_adc_rate, - .adc_en2 = true, .maps = axp20x_maps, }; @@ -645,7 +645,6 @@ static const struct axp_data axp22x_data = { .channels = axp22x_adc_channels, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp22x_adc_rate, - .adc_en2 = false, .maps = axp22x_maps, }; @@ -655,7 +654,6 @@ static const struct axp_data axp813_data = { .channels = axp813_adc_channels, .adc_en1_mask = AXP22X_ADC_EN1_MASK, .adc_rate = axp813_adc_rate, - .adc_en2 = false, .maps = axp22x_maps, }; @@ -713,10 +711,10 @@ static int axp20x_probe(struct platform_device *pdev) /* Enable the ADCs on IP */ regmap_write(info->regmap, AXP20X_ADC_EN1, info->data->adc_en1_mask); - if (info->data->adc_en2) - /* Enable GPIO0/1 and internal temperature ADCs */ + if (info->data->adc_en2_mask) regmap_update_bits(info->regmap, AXP20X_ADC_EN2, - AXP20X_ADC_EN2_MASK, AXP20X_ADC_EN2_MASK); + info->data->adc_en2_mask, + info->data->adc_en2_mask); /* Configure ADCs rate */ info->data->adc_rate(info, 100); @@ -741,7 +739,7 @@ static int axp20x_probe(struct platform_device *pdev) fail_map: regmap_write(info->regmap, AXP20X_ADC_EN1, 0); - if (info->data->adc_en2) + if (info->data->adc_en2_mask) regmap_write(info->regmap, AXP20X_ADC_EN2, 0); return ret; @@ -757,7 +755,7 @@ static int axp20x_remove(struct platform_device *pdev) regmap_write(info->regmap, AXP20X_ADC_EN1, 0); - if (info->data->adc_en2) + if (info->data->adc_en2_mask) regmap_write(info->regmap, AXP20X_ADC_EN2, 0); return 0; From patchwork Sun Oct 16 23:43:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616364 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 B50D2C4332F for ; Sun, 16 Oct 2022 23:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbiJPXm5 (ORCPT ); Sun, 16 Oct 2022 19:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230012AbiJPXms (ORCPT ); Sun, 16 Oct 2022 19:42:48 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 407CB27926; Sun, 16 Oct 2022 16:42:29 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id r3-20020a05600c35c300b003b4b5f6c6bdso8796039wmq.2; Sun, 16 Oct 2022 16:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=ZVDsQVUoXvmNA77LPJOpJward80S9xfbJHcpTm+nB6k=; b=LdxhTUGv6G/jlHfDy9pL7GUcaGdHPUeipIafb3dmrWm7Y2wyMQRFqvBwtKK8Ji6cpY nl045tPCGMpLFcHbwnuokGlpuAejRaoqnZR2dGu9dIrS4t8jeNUygscvUE7DifymeyZe hMnqIT1rM60SORrNdgs/vu/XYFFQpGzrG+cHVviow0qbo/M2G3fEYMB+lSDZrhsMmz4H Uc6S3RFfqz1s0Gj/P4otHikC7+SCcqdESEq7Da+JprHXigiMLPwsCI8OxsoF1rcAswuY Tr78r4C5/wag+SZSy2MCcAZ0cqDKRSHx+YQbA0IQt1PTnIBb0Ee/csk0+dqAoIbGFqRi X6EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=ZVDsQVUoXvmNA77LPJOpJward80S9xfbJHcpTm+nB6k=; b=FoEcxfzYIakofNr6lxferrHQ2eoMl6edYTaZVm0rDlS1heiOk0jpYWPQkrg6nhljlf efvg2lPh0QwTusTTC1Cfi2jHH8K/+/EeEGVM7GCT7RdImEgiNsgY6sEZ2Vut0wKSqOCS H6CW/ZEGtri/mABGBHkq+FfKY/SWvgsm0SCAHRTgZ03l55rF7UkFCdILmGxmobeATvwh vg76o05sOr1UnAUm4DZ5hlg/Rxh2rYPluCS/unihLF0W1SgLowFdEb+LbVavxumrem0a aZYhrQzHWY9syG/jUBrCQOIJhQAawz6fFI72T+OlK7HlCAIdk8QcDjJdc7vwSco3tf5J FpXg== X-Gm-Message-State: ACrzQf0rHbUhLtMbTUi2S0AetKDFQYn8AU7nNs8qsdsrc4uJWG269L56 1/BGSvgFVgU8Bp69HV1xpWY= X-Google-Smtp-Source: AMsMyM5nWP/Bnp/5xlA33MAoj44akUajQaDLEcURpTH8g/8ghQI4o1ULBLs45uyXTcT9+jfuFyRQZg== X-Received: by 2002:a1c:f60d:0:b0:3be:708b:c96c with SMTP id w13-20020a1cf60d000000b003be708bc96cmr17752477wmc.168.1665963747975; Sun, 16 Oct 2022 16:42:27 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id p14-20020a05600c468e00b003c6f3e5ba42sm3442346wmo.46.2022.10.16.16.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:27 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron Subject: [PATCH v6 09/13] iio: adc: axp20x_adc: Add support for AXP192 Date: Mon, 17 Oct 2022 00:43:31 +0100 Message-Id: <20221016234335.904212-10-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192 is identical to the AXP20x, except for the addition of two more GPIO ADC channels. Reviewed-by: Jonathan Cameron Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/iio/adc/axp20x_adc.c | 279 +++++++++++++++++++++++++++++++++++ 1 file changed, 279 insertions(+) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 75bda94dbce1..8d748b814f20 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -22,11 +22,19 @@ #include #include +#define AXP192_ADC_EN1_MASK GENMASK(7, 0) +#define AXP192_ADC_EN2_MASK (GENMASK(3, 0) | BIT(7)) + #define AXP20X_ADC_EN1_MASK GENMASK(7, 0) #define AXP20X_ADC_EN2_MASK (GENMASK(3, 2) | BIT(7)) #define AXP22X_ADC_EN1_MASK (GENMASK(7, 5) | BIT(0)) +#define AXP192_GPIO30_IN_RANGE_GPIO0 BIT(0) +#define AXP192_GPIO30_IN_RANGE_GPIO1 BIT(1) +#define AXP192_GPIO30_IN_RANGE_GPIO2 BIT(2) +#define AXP192_GPIO30_IN_RANGE_GPIO3 BIT(3) + #define AXP20X_GPIO10_IN_RANGE_GPIO0 BIT(0) #define AXP20X_GPIO10_IN_RANGE_GPIO1 BIT(1) @@ -71,6 +79,25 @@ struct axp20x_adc_iio { const struct axp_data *data; }; +enum axp192_adc_channel_v { + AXP192_ACIN_V = 0, + AXP192_VBUS_V, + AXP192_TS_IN, + AXP192_GPIO0_V, + AXP192_GPIO1_V, + AXP192_GPIO2_V, + AXP192_GPIO3_V, + AXP192_IPSOUT_V, + AXP192_BATT_V, +}; + +enum axp192_adc_channel_i { + AXP192_ACIN_I = 0, + AXP192_VBUS_I, + AXP192_BATT_CHRG_I, + AXP192_BATT_DISCHRG_I, +}; + enum axp20x_adc_channel_v { AXP20X_ACIN_V = 0, AXP20X_VBUS_V, @@ -158,6 +185,43 @@ static struct iio_map axp22x_maps[] = { * The only exception is for the battery. batt_v will be in_voltage6_raw and * charge current in_current6_raw and discharge current will be in_current7_raw. */ +static const struct iio_chan_spec axp192_adc_channels[] = { + AXP20X_ADC_CHANNEL(AXP192_ACIN_V, "acin_v", IIO_VOLTAGE, + AXP20X_ACIN_V_ADC_H), + AXP20X_ADC_CHANNEL(AXP192_ACIN_I, "acin_i", IIO_CURRENT, + AXP20X_ACIN_I_ADC_H), + AXP20X_ADC_CHANNEL(AXP192_VBUS_V, "vbus_v", IIO_VOLTAGE, + AXP20X_VBUS_V_ADC_H), + AXP20X_ADC_CHANNEL(AXP192_VBUS_I, "vbus_i", IIO_CURRENT, + AXP20X_VBUS_I_ADC_H), + { + .type = IIO_TEMP, + .address = AXP20X_TEMP_ADC_H, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_OFFSET), + .datasheet_name = "pmic_temp", + }, + AXP20X_ADC_CHANNEL_OFFSET(AXP192_GPIO0_V, "gpio0_v", IIO_VOLTAGE, + AXP20X_GPIO0_V_ADC_H), + AXP20X_ADC_CHANNEL_OFFSET(AXP192_GPIO1_V, "gpio1_v", IIO_VOLTAGE, + AXP20X_GPIO1_V_ADC_H), + AXP20X_ADC_CHANNEL_OFFSET(AXP192_GPIO2_V, "gpio2_v", IIO_VOLTAGE, + AXP192_GPIO2_V_ADC_H), + AXP20X_ADC_CHANNEL_OFFSET(AXP192_GPIO3_V, "gpio3_v", IIO_VOLTAGE, + AXP192_GPIO3_V_ADC_H), + AXP20X_ADC_CHANNEL(AXP192_IPSOUT_V, "ipsout_v", IIO_VOLTAGE, + AXP20X_IPSOUT_V_HIGH_H), + AXP20X_ADC_CHANNEL(AXP192_BATT_V, "batt_v", IIO_VOLTAGE, + AXP20X_BATT_V_H), + AXP20X_ADC_CHANNEL(AXP192_BATT_CHRG_I, "batt_chrg_i", IIO_CURRENT, + AXP20X_BATT_CHRG_I_H), + AXP20X_ADC_CHANNEL(AXP192_BATT_DISCHRG_I, "batt_dischrg_i", IIO_CURRENT, + AXP20X_BATT_DISCHRG_I_H), + AXP20X_ADC_CHANNEL(AXP192_TS_IN, "ts_v", IIO_VOLTAGE, + AXP20X_TS_IN_H), +}; + static const struct iio_chan_spec axp20x_adc_channels[] = { AXP20X_ADC_CHANNEL(AXP20X_ACIN_V, "acin_v", IIO_VOLTAGE, AXP20X_ACIN_V_ADC_H), @@ -231,6 +295,27 @@ static const struct iio_chan_spec axp813_adc_channels[] = { AXP288_TS_ADC_H), }; +static int axp192_adc_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val) +{ + struct axp20x_adc_iio *info = iio_priv(indio_dev); + int ret, size; + + if (chan->type == IIO_CURRENT && + (chan->channel == AXP192_BATT_CHRG_I || + chan->channel == AXP192_BATT_DISCHRG_I)) + size = 13; + else + size = 12; + + ret = axp20x_read_variable_width(info->regmap, chan->address, size); + if (ret < 0) + return ret; + + *val = ret; + return IIO_VAL_INT; +} + static int axp20x_adc_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { @@ -283,6 +368,44 @@ static int axp813_adc_raw(struct iio_dev *indio_dev, return IIO_VAL_INT; } +static int axp192_adc_scale_voltage(int channel, int *val, int *val2) +{ + switch (channel) { + case AXP192_ACIN_V: + case AXP192_VBUS_V: + *val = 1; + *val2 = 700000; + return IIO_VAL_INT_PLUS_MICRO; + + case AXP192_GPIO0_V: + case AXP192_GPIO1_V: + case AXP192_GPIO2_V: + case AXP192_GPIO3_V: + *val = 0; + *val2 = 500000; + return IIO_VAL_INT_PLUS_MICRO; + + case AXP192_BATT_V: + *val = 1; + *val2 = 100000; + return IIO_VAL_INT_PLUS_MICRO; + + case AXP192_IPSOUT_V: + *val = 1; + *val2 = 400000; + return IIO_VAL_INT_PLUS_MICRO; + + case AXP192_TS_IN: + /* 0.8 mV per LSB */ + *val = 0; + *val2 = 800000; + return IIO_VAL_INT_PLUS_MICRO; + + default: + return -EINVAL; + } +} + static int axp20x_adc_scale_voltage(int channel, int *val, int *val2) { switch (channel) { @@ -386,6 +509,29 @@ static int axp20x_adc_scale_current(int channel, int *val, int *val2) } } +static int axp192_adc_scale(struct iio_chan_spec const *chan, int *val, + int *val2) +{ + switch (chan->type) { + case IIO_VOLTAGE: + return axp192_adc_scale_voltage(chan->channel, val, val2); + + case IIO_CURRENT: + /* + * AXP192 current channels are identical to the AXP20x, + * therefore we can re-use the scaling function. + */ + return axp20x_adc_scale_current(chan->channel, val, val2); + + case IIO_TEMP: + *val = 100; + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + static int axp20x_adc_scale(struct iio_chan_spec const *chan, int *val, int *val2) { @@ -445,6 +591,42 @@ static int axp813_adc_scale(struct iio_chan_spec const *chan, int *val, } } +static int axp192_adc_offset_voltage(struct iio_dev *indio_dev, int channel, + int *val) +{ + struct axp20x_adc_iio *info = iio_priv(indio_dev); + unsigned int regval; + int ret; + + ret = regmap_read(info->regmap, AXP192_GPIO30_IN_RANGE, ®val); + if (ret < 0) + return ret; + + switch (channel) { + case AXP192_GPIO0_V: + regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO0, regval); + break; + + case AXP192_GPIO1_V: + regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO1, regval); + break; + + case AXP192_GPIO2_V: + regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO2, regval); + break; + + case AXP192_GPIO3_V: + regval = FIELD_GET(AXP192_GPIO30_IN_RANGE_GPIO3, regval); + break; + + default: + return -EINVAL; + } + + *val = regval ? 700000 : 0; + return IIO_VAL_INT; +} + static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, int *val) { @@ -473,6 +655,22 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, return IIO_VAL_INT; } +static int axp192_adc_offset(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val) +{ + switch (chan->type) { + case IIO_VOLTAGE: + return axp192_adc_offset_voltage(indio_dev, chan->channel, val); + + case IIO_TEMP: + *val = -1447; + return IIO_VAL_INT; + + default: + return -EINVAL; + } +} + static int axp20x_adc_offset(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val) { @@ -489,6 +687,25 @@ static int axp20x_adc_offset(struct iio_dev *indio_dev, } } +static int axp192_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int *val, + int *val2, long mask) +{ + switch (mask) { + case IIO_CHAN_INFO_OFFSET: + return axp192_adc_offset(indio_dev, chan, val); + + case IIO_CHAN_INFO_SCALE: + return axp192_adc_scale(chan, val, val2); + + case IIO_CHAN_INFO_RAW: + return axp192_adc_raw(indio_dev, chan, val); + + default: + return -EINVAL; + } +} + static int axp20x_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) @@ -549,6 +766,51 @@ static int axp813_read_raw(struct iio_dev *indio_dev, } } +static int axp192_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, int val, int val2, + long mask) +{ + struct axp20x_adc_iio *info = iio_priv(indio_dev); + unsigned int regmask, regval; + + /* + * The AXP192 PMIC allows the user to choose between 0V and 0.7V offsets + * for (independently) GPIO0-3 when in ADC mode. + */ + if (mask != IIO_CHAN_INFO_OFFSET) + return -EINVAL; + + if (val != 0 && val != 700000) + return -EINVAL; + + switch (chan->channel) { + case AXP192_GPIO0_V: + regmask = AXP192_GPIO30_IN_RANGE_GPIO0; + regval = FIELD_PREP(AXP192_GPIO30_IN_RANGE_GPIO0, !!val); + break; + + case AXP192_GPIO1_V: + regmask = AXP192_GPIO30_IN_RANGE_GPIO1; + regval = FIELD_PREP(AXP192_GPIO30_IN_RANGE_GPIO1, !!val); + break; + + case AXP192_GPIO2_V: + regmask = AXP192_GPIO30_IN_RANGE_GPIO2; + regval = FIELD_PREP(AXP192_GPIO30_IN_RANGE_GPIO2, !!val); + break; + + case AXP192_GPIO3_V: + regmask = AXP192_GPIO30_IN_RANGE_GPIO3; + regval = FIELD_PREP(AXP192_GPIO30_IN_RANGE_GPIO3, !!val); + break; + + default: + return -EINVAL; + } + + return regmap_update_bits(info->regmap, AXP192_GPIO30_IN_RANGE, regmask, regval); +} + static int axp20x_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) @@ -584,6 +846,11 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, return regmap_update_bits(info->regmap, AXP20X_GPIO10_IN_RANGE, regmask, regval); } +static const struct iio_info axp192_adc_iio_info = { + .read_raw = axp192_read_raw, + .write_raw = axp192_write_raw, +}; + static const struct iio_info axp20x_adc_iio_info = { .read_raw = axp20x_read_raw, .write_raw = axp20x_write_raw, @@ -629,6 +896,16 @@ struct axp_data { struct iio_map *maps; }; +static const struct axp_data axp192_data = { + .iio_info = &axp192_adc_iio_info, + .num_channels = ARRAY_SIZE(axp192_adc_channels), + .channels = axp192_adc_channels, + .adc_en1_mask = AXP192_ADC_EN1_MASK, + .adc_en2_mask = AXP192_ADC_EN2_MASK, + .adc_rate = axp20x_adc_rate, + .maps = axp20x_maps, +}; + static const struct axp_data axp20x_data = { .iio_info = &axp20x_adc_iio_info, .num_channels = ARRAY_SIZE(axp20x_adc_channels), @@ -658,6 +935,7 @@ static const struct axp_data axp813_data = { }; static const struct of_device_id axp20x_adc_of_match[] = { + { .compatible = "x-powers,axp192-adc", .data = (void *)&axp192_data, }, { .compatible = "x-powers,axp209-adc", .data = (void *)&axp20x_data, }, { .compatible = "x-powers,axp221-adc", .data = (void *)&axp22x_data, }, { .compatible = "x-powers,axp813-adc", .data = (void *)&axp813_data, }, @@ -666,6 +944,7 @@ static const struct of_device_id axp20x_adc_of_match[] = { MODULE_DEVICE_TABLE(of, axp20x_adc_of_match); static const struct platform_device_id axp20x_adc_id_match[] = { + { .name = "axp192-adc", .driver_data = (kernel_ulong_t)&axp192_data, }, { .name = "axp20x-adc", .driver_data = (kernel_ulong_t)&axp20x_data, }, { .name = "axp22x-adc", .driver_data = (kernel_ulong_t)&axp22x_data, }, { .name = "axp813-adc", .driver_data = (kernel_ulong_t)&axp813_data, }, From patchwork Sun Oct 16 23:43:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 615636 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 78801C433FE for ; Sun, 16 Oct 2022 23:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbiJPXnD (ORCPT ); Sun, 16 Oct 2022 19:43:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbiJPXmt (ORCPT ); Sun, 16 Oct 2022 19:42:49 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3578437408; Sun, 16 Oct 2022 16:42:31 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id bv10so16003709wrb.4; Sun, 16 Oct 2022 16:42:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=xVoR5fEFXEn1wnD9ecqINhC8kaMx1xCBXArxnuhKVxg=; b=UNtTf7WnJQh34O+QV5PpTFm3pED1tEo6mzd6miSNBXIOHTX33IV/OLXxM9xkrd8iAz RUudZmC6YntaJTSlzrrIAGik5/Fjvh4OVtDlL6uOFPPwM/8gns7u9TptmmjjHHP31jR+ VrOthy3lcVP1rWfvI5WSeykNAytE26qOPipZ53ccpCsO/zz9WIZXNdbKLZGq+XTyAWAo xRed8fZm7vKMTIKUGs7CuPztLfS1jU6QZhH5czgs3JVrNIvGrYgA/6OLReoT3+6Z9Ysn kDmmPJO8AEhHM+x+eZgkHdVtGY6bJ4pW5KGI8GtY5pYtOazHDDGl7ZjcaDtngQKQvE1p qv0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=xVoR5fEFXEn1wnD9ecqINhC8kaMx1xCBXArxnuhKVxg=; b=g4n+s20HF0oGTBXqUYwYKkcm9H6EFpdDRmyC+vK33TupmD25iBbMxmZVQnhYkW/Rys n/Z7tJunLO7AMe9YY1CsjMMRaeSyByYM2/xCmXm13wXKMShxXFDAuE3CgLLxHqrsDt7u huYFxhPRqjbYNSNh1ig+CZNPAS6mmWVaMLC3Pratj647vRV/+zV2tZdvhNwN1uc40hUd s0MCzWFgs2kgfqIdL3QsphSP/yUVVUp68Y96YxnhYFWT+EZmPvBBE0A0SzZ6wNZFg/t+ g0/mHAnmAUSl8202m+srcTF7FLAQGB+z7tNQ6q+2ijJh4fdD3kwk3MCI3uFEeio216Kn grog== X-Gm-Message-State: ACrzQf0uFsObi+9Yh2WamAIVq7kKgZGXoduMhzteCdWVlckULIyFOvki 18vynNIao2K2br5eS9yKFts= X-Google-Smtp-Source: AMsMyM499yzAKHSUJyKxSvlsexJxJg4em6fAXtN1S3z4sdl2Yd4fL98krA1llKGGRjFY2k3mx2l4Rw== X-Received: by 2002:adf:e491:0:b0:22e:4483:a8b5 with SMTP id i17-20020adfe491000000b0022e4483a8b5mr4775629wrm.497.1665963749559; Sun, 16 Oct 2022 16:42:29 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id z6-20020a1cf406000000b003c6deb5c1edsm8496773wma.45.2022.10.16.16.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:29 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel Subject: [PATCH v6 10/13] power: supply: axp20x_usb_power: Add support for AXP192 Date: Mon, 17 Oct 2022 00:43:32 +0100 Message-Id: <20221016234335.904212-11-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192's USB power supply is similar to the AXP202 but it has different USB current limits and a different offset for the VBUS status register. Acked-by: Sebastian Reichel Reviewed-by: Chen-Yu Tsai Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_usb_power.c | 84 +++++++++++++++++++++---- 1 file changed, 73 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index a1e6d1d44808..f83e2ed6d507 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -48,6 +48,9 @@ #define AXP813_VBUS_CLIMIT_2000mA 2 #define AXP813_VBUS_CLIMIT_2500mA 3 +#define AXP192_VBUS_CLIMIT_EN BIT(1) +#define AXP192_VBUS_CLIMIT_100mA BIT(0) + #define AXP20X_ADC_EN1_VBUS_CURR BIT(2) #define AXP20X_ADC_EN1_VBUS_VOLT BIT(3) @@ -121,6 +124,25 @@ static void axp20x_usb_power_poll_vbus(struct work_struct *work) mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNCE_TIME); } +static int axp192_get_current_max(struct axp20x_usb_power *power, int *val) +{ + unsigned int v; + int ret; + + ret = regmap_read(power->regmap, AXP20X_VBUS_IPSOUT_MGMT, &v); + if (ret) + return ret; + + if (!(v & AXP192_VBUS_CLIMIT_EN)) + *val = -1; + else if (v & AXP192_VBUS_CLIMIT_100mA) + *val = 100000; + else + *val = 500000; + + return 0; +} + static int axp20x_get_current_max(struct axp20x_usb_power *power, int *val) { unsigned int v; @@ -179,7 +201,7 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { struct axp20x_usb_power *power = power_supply_get_drvdata(psy); - unsigned int input, v; + unsigned int input, v, reg; int ret; switch (psp) { @@ -215,6 +237,8 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CURRENT_MAX: if (power->axp20x_id == AXP813_ID) return axp813_get_current_max(power, &val->intval); + else if (power->axp20x_id == AXP192_ID) + return axp192_get_current_max(power, &val->intval); return axp20x_get_current_max(power, &val->intval); case POWER_SUPPLY_PROP_CURRENT_NOW: if (IS_ENABLED(CONFIG_AXP20X_ADC)) { @@ -256,16 +280,19 @@ static int axp20x_usb_power_get_property(struct power_supply *psy, val->intval = POWER_SUPPLY_HEALTH_GOOD; - if (power->axp20x_id == AXP202_ID) { - ret = regmap_read(power->regmap, - AXP20X_USB_OTG_STATUS, &v); - if (ret) - return ret; + if (power->axp20x_id == AXP192_ID) + reg = AXP192_USB_OTG_STATUS; + else if (power->axp20x_id == AXP202_ID) + reg = AXP20X_USB_OTG_STATUS; + else + break; /* Other chips lack the OTG status register */ - if (!(v & AXP20X_USB_STATUS_VBUS_VALID)) - val->intval = - POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; - } + ret = regmap_read(power->regmap, reg, &v); + if (ret) + return ret; + + if (!(v & AXP20X_USB_STATUS_VBUS_VALID)) + val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE; break; case POWER_SUPPLY_PROP_PRESENT: val->intval = !!(input & AXP20X_PWR_STATUS_VBUS_PRESENT); @@ -316,6 +343,28 @@ static int axp20x_usb_power_set_voltage_min(struct axp20x_usb_power *power, return -EINVAL; } +static int axp192_usb_power_set_current_max(struct axp20x_usb_power *power, + int intval) +{ + const unsigned int mask = AXP192_VBUS_CLIMIT_EN | + AXP192_VBUS_CLIMIT_100mA; + unsigned int val; + + switch (intval) { + case 100000: + val = AXP192_VBUS_CLIMIT_EN | AXP192_VBUS_CLIMIT_100mA; + break; + case 500000: + val = AXP192_VBUS_CLIMIT_EN; + break; + default: + return -EINVAL; + } + + return regmap_update_bits(power->regmap, + AXP20X_VBUS_IPSOUT_MGMT, mask, val); +} + static int axp813_usb_power_set_current_max(struct axp20x_usb_power *power, int intval) { @@ -383,6 +432,9 @@ static int axp20x_usb_power_set_property(struct power_supply *psy, if (power->axp20x_id == AXP813_ID) return axp813_usb_power_set_current_max(power, val->intval); + else if (power->axp20x_id == AXP192_ID) + return axp192_usb_power_set_current_max(power, + val->intval); return axp20x_usb_power_set_current_max(power, val->intval); default: @@ -468,6 +520,13 @@ struct axp_data { enum axp20x_variants axp20x_id; }; +static const struct axp_data axp192_data = { + .power_desc = &axp20x_usb_power_desc, + .irq_names = axp20x_irq_names, + .num_irq_names = ARRAY_SIZE(axp20x_irq_names), + .axp20x_id = AXP192_ID, +}; + static const struct axp_data axp202_data = { .power_desc = &axp20x_usb_power_desc, .irq_names = axp20x_irq_names, @@ -600,7 +659,7 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) if (ret) return ret; - if (power->axp20x_id == AXP202_ID) { + if (power->axp20x_id == AXP192_ID || power->axp20x_id == AXP202_ID) { /* Enable vbus valid checking */ ret = regmap_update_bits(power->regmap, AXP20X_VBUS_MON, AXP20X_VBUS_MON_VBUS_VALID, @@ -659,6 +718,9 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) static const struct of_device_id axp20x_usb_power_match[] = { { + .compatible = "x-powers,axp192-usb-power-supply", + .data = &axp192_data, + }, { .compatible = "x-powers,axp202-usb-power-supply", .data = &axp202_data, }, { From patchwork Sun Oct 16 23:43:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616363 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 B8030C43217 for ; Sun, 16 Oct 2022 23:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbiJPXnS (ORCPT ); Sun, 16 Oct 2022 19:43:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230033AbiJPXmx (ORCPT ); Sun, 16 Oct 2022 19:42:53 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C433038449; Sun, 16 Oct 2022 16:42:33 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id a3so16087493wrt.0; Sun, 16 Oct 2022 16:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=6706nU4p7iq9wHYgQ+Dtrw1GcYB0dWgaEHmzw7yDg1c=; b=BIf82YTB4Ss8IOrnHMsPmUp39Hbw1ZkvXkZZqkYigh/f8Z86X/tFzm3d36uZAF73dJ mzP5U81Wsd8+exjUfqOOIOlnfrQ6NmXCyIquJxrek088/Ew1BjqTvArGxJDojFn000wc B6ENJBF3txgbnvW6kRDf64IEWklPP0nNN6PWBuKSfnvHEyCtTXi3eX7VS2AAcmBluoHD qXAIa4EBMfQEdjzeVHKi3I4Y25nrDQn/gktdFoEpJaLnJ37+NkHZDvuJX9e6zo9UaMON GaJNC2xFNJpGUie7SJqB/TaXoa1oUjfh2R7/DB3bO6zRTcWy8Ie66CEQtug7PMU8BXCc 1z7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=6706nU4p7iq9wHYgQ+Dtrw1GcYB0dWgaEHmzw7yDg1c=; b=vndZJbExV49fuAz52WjcHYXZNRSzdhYlp4FQ9t9sxaEHMZEaq+tRLo/fAdYNnsDoYc 8979z6TR4XYQ5lzSr19r1uJD+zbRkZ/EHHtXSnUAkCGjxKbcVi59oomtXAMl+aQ6usIM HdmbYf+zDctnxB4v0CnFmG9U11OM6FXGuhy1L/KW0tCl50cIDTlw56DQyhrhFJKhB/J+ mc4hefbVfujACIXHPTVgL7V/Gli/o0x2QEp+WD+3vcWxNCUKlKqEbaOkQILvOL3m78JK ejvbV80n7TCzQqm+MjGzEo1kU1ButyDDyU5vZzI1UV+fKqCVgLzPATLaJ9pw4He8WBYj kR8A== X-Gm-Message-State: ACrzQf1FvLJTmieX6cWjLm/WYPhmtv7ZTHzwVBafuEsQD8eXRydjVmkO 5EBFahX58RWq6eKuE+Zf9/yjqACsR81f8g== X-Google-Smtp-Source: AMsMyM7pSfzTlPlJAN6WJH+4EJnWcQEWpkM78YOXMTtPT/y3Wnwljc/8t5bWUF7R4cn/QFQpOueXug== X-Received: by 2002:a5d:5612:0:b0:22e:35b7:5654 with SMTP id l18-20020a5d5612000000b0022e35b75654mr4718820wrv.651.1665963751137; Sun, 16 Oct 2022 16:42:31 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id q13-20020a05600c46cd00b003c6f426467fsm3332702wmo.40.2022.10.16.16.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:30 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel Subject: [PATCH v6 11/13] power: axp20x_battery: Add constant charge current table Date: Mon, 17 Oct 2022 00:43:33 +0100 Message-Id: <20221016234335.904212-12-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add a table-based lookup method for constant charge current, which is necessary when the setting cannot be represented as a linear range. This also replaces the hard-coded 300 mA default ccc setting if the DT-specified value is unsupported; the minimum value for the device is now set exactly instead of relying on the value being rounded down to a supported value. Reviewed-by: Andy Shevchenko Acked-by: Sebastian Reichel Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_battery.c | 59 +++++++++++++++++++++------ 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index 9106077c0dbb..401779d84d2b 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -61,6 +61,14 @@ struct axp20x_batt_ps; struct axp_data { int ccc_scale; int ccc_offset; + /* + * Lookup table for constant charge current, if provided this is used + * instead of ccc_scale/ccc_offset. + * + * The table is indexed by the field AXP20X_CHRG_CTRL1_TGT_CURR so it + * must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements. + */ + const int *ccc_table; bool has_fg_valid; int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val); int (*set_max_voltage)(struct axp20x_batt_ps *batt, int val); @@ -176,7 +184,10 @@ static int axp20x_get_constant_charge_current(struct axp20x_batt_ps *axp, *val &= AXP20X_CHRG_CTRL1_TGT_CURR; - *val = *val * axp->data->ccc_scale + axp->data->ccc_offset; + if (axp->data->ccc_table) + *val = axp->data->ccc_table[*val]; + else + *val = *val * axp->data->ccc_scale + axp->data->ccc_offset; return 0; } @@ -389,16 +400,35 @@ static int axp20x_battery_set_max_voltage(struct axp20x_batt_ps *axp20x_batt, AXP20X_CHRG_CTRL1_TGT_VOLT, val); } +static int axp20x_get_constant_charge_current_sel(struct axp20x_batt_ps *axp_batt, + int charge_current) +{ + int i; + + if (axp_batt->data->ccc_table) { + for (i = AXP20X_CHRG_CTRL1_TGT_CURR; i >= 0; i--) { + if (axp_batt->data->ccc_table[i] <= charge_current) + return i; + } + + return -EINVAL; + } + + i = (charge_current - axp_batt->data->ccc_offset) / axp_batt->data->ccc_scale; + if (i > AXP20X_CHRG_CTRL1_TGT_CURR || i < 0) + return -EINVAL; + + return i; +} + static int axp20x_set_constant_charge_current(struct axp20x_batt_ps *axp_batt, int charge_current) { if (charge_current > axp_batt->max_ccc) return -EINVAL; - charge_current = (charge_current - axp_batt->data->ccc_offset) / - axp_batt->data->ccc_scale; - - if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0) + charge_current = axp20x_get_constant_charge_current_sel(axp_batt, charge_current); + if (charge_current < 0) return -EINVAL; return regmap_update_bits(axp_batt->regmap, AXP20X_CHRG_CTRL1, @@ -410,14 +440,14 @@ static int axp20x_set_max_constant_charge_current(struct axp20x_batt_ps *axp, { bool lower_max = false; - charge_current = (charge_current - axp->data->ccc_offset) / - axp->data->ccc_scale; - - if (charge_current > AXP20X_CHRG_CTRL1_TGT_CURR || charge_current < 0) + charge_current = axp20x_get_constant_charge_current_sel(axp, charge_current); + if (charge_current < 0) return -EINVAL; - charge_current = charge_current * axp->data->ccc_scale + - axp->data->ccc_offset; + if (axp->data->ccc_table) + charge_current = axp->data->ccc_table[charge_current]; + else + charge_current = charge_current * axp->data->ccc_scale + axp->data->ccc_offset; if (charge_current > axp->max_ccc) dev_warn(axp->dev, @@ -629,7 +659,12 @@ static int axp20x_power_probe(struct platform_device *pdev) ccc)) { dev_err(&pdev->dev, "couldn't set constant charge current from DT: fallback to minimum value\n"); - ccc = 300000; + + if (axp20x_batt->data->ccc_table) + ccc = axp20x_batt->data->ccc_table[0]; + else + ccc = axp20x_batt->data->ccc_offset; + axp20x_batt->max_ccc = ccc; axp20x_set_constant_charge_current(axp20x_batt, ccc); } From patchwork Sun Oct 16 23:43:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 615635 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 DC8D8C433FE for ; Sun, 16 Oct 2022 23:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbiJPXnY (ORCPT ); Sun, 16 Oct 2022 19:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229961AbiJPXm4 (ORCPT ); Sun, 16 Oct 2022 19:42:56 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C44DF3844D; Sun, 16 Oct 2022 16:42:33 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id w18so15994876wro.7; Sun, 16 Oct 2022 16:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=yLNaaOsLr96TmggGShacOs0+QBHQK9LKPCnPOfIZ4M0=; b=XHEmXq0xose8BCxHQ7cp7eQEBOoG+00uP5Fqf1CATZbpmqd3XJkipc9ZiVNgCEO9ly /dgsR55qnGgGcI8V+aS4DzyWKCXlcr0pmEvGHmASNswkilZ8fS4LGHuySpzQcwyc2XNf GI+JlpHoVqiRYe2qdp52ZckEn9yaqF8lF8QR+CoXeb3q4tAX7tfEhe5mbFfLF9MfRO7r sHl4mJLhkRpsb/Px9i6RYM1HyZjERAdVy0IC45Z8xYbNIygY1QZpjbPgcqpVUrDwL8+t mPwx/xGLFSCNzb5mxDqC5PulNoz5x6CwublCKBzruLKwcy30ynyvC1J/Biqxv8WlriW2 ZLdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=yLNaaOsLr96TmggGShacOs0+QBHQK9LKPCnPOfIZ4M0=; b=6t21k77LkQyxCDpNkWEo5ELhzgZnxnhU/OfE2rcv5NSJFVdoP8e5vAlOPJ9B1r1n7U P7sDN7Fi/jAF6zFjarcVVP6LolIy82tqMYzVsbmbOxD5JGO1W2He8e9vHU7pYPt/eXT0 4oVMbfx2MAnnQgsSgOnjZ5ltxbwjGIZDODu27SlmY58y9mD8tMJvhYroR+jOTA5fbt3p ByXKl9o1wJ/6r+iYE143rDTCTJP3ZypygerGkKRM/KA0ezKuvkAi+NvgFhZRJKCRPlgK iX9/gmRTyWEDZ8V6MMCldN55VcyZAMn9BvekAN2IAu4mWKJw14Z9DCIalchu43WWK3uH YqqQ== X-Gm-Message-State: ACrzQf2XEte5KynSzcJCBwvGeBSw4czWo5yplfDExetHvheo3F240Ka9 R5os3OAfQ4Vl16N7em560Ks= X-Google-Smtp-Source: AMsMyM52GUJp+BCZmmlQDioN889uuJnt4eIbHt5nmnNOJVid/qznriWjERrYLQHlc4X7WlugEoHoig== X-Received: by 2002:a5d:4535:0:b0:232:3648:7771 with SMTP id j21-20020a5d4535000000b0023236487771mr4602684wra.342.1665963752790; Sun, 16 Oct 2022 16:42:32 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id u7-20020adfed47000000b002286670bafasm7152829wro.48.2022.10.16.16.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:32 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel Subject: [PATCH v6 12/13] power: axp20x_battery: Support battery status without fuel gauge Date: Mon, 17 Oct 2022 00:43:34 +0100 Message-Id: <20221016234335.904212-13-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Add a "has_fg" flag to indicate that the chip has a fuel gauge. Report battery full status on chips with no fuel gauge using the battery voltage. Acked-by: Sebastian Reichel Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_battery.c | 34 ++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index 401779d84d2b..574c1d001556 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -69,6 +69,7 @@ struct axp_data { * must have AXP20X_CHRG_CTRL1_TGT_CURR+1 elements. */ const int *ccc_table; + bool has_fg; bool has_fg_valid; int (*get_max_voltage)(struct axp20x_batt_ps *batt, int *val); int (*set_max_voltage)(struct axp20x_batt_ps *batt, int val); @@ -197,7 +198,7 @@ static int axp20x_battery_get_prop(struct power_supply *psy, union power_supply_propval *val) { struct axp20x_batt_ps *axp20x_batt = power_supply_get_drvdata(psy); - int ret = 0, reg, val1; + int ret = 0, reg, val1, val2; switch (psp) { case POWER_SUPPLY_PROP_PRESENT: @@ -231,6 +232,34 @@ static int axp20x_battery_get_prop(struct power_supply *psy, return 0; } + /* + * If the chip does not have a fuel gauge, we check battery full status + * using voltage instead. + */ + if (!axp20x_batt->data->has_fg) { + ret = axp20x_batt->data->get_max_voltage(axp20x_batt, &val1); + if (ret) + return ret; + + ret = iio_read_channel_processed(axp20x_batt->batt_v, &val2); + if (ret) + return ret; + + /* IIO subsystem reports voltage in mV but we need uV */ + val2 *= 1000; + + /* + * According to the AXP192 datasheet, charging will restart if + * the battery voltage drops below V_rch = V_tgt - 0.1 V, so we + * report the battery is full if its voltage is at least V_rch. + */ + if (val2 >= val1 - 100000) + val->intval = POWER_SUPPLY_STATUS_FULL; + else + val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; + break; + } + ret = regmap_read(axp20x_batt->regmap, AXP20X_FG_RES, &val1); if (ret) return ret; @@ -552,6 +581,7 @@ static const struct power_supply_desc axp20x_batt_ps_desc = { static const struct axp_data axp209_data = { .ccc_scale = 100000, .ccc_offset = 300000, + .has_fg = true, .get_max_voltage = axp20x_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, }; @@ -559,6 +589,7 @@ static const struct axp_data axp209_data = { static const struct axp_data axp221_data = { .ccc_scale = 150000, .ccc_offset = 300000, + .has_fg = true, .has_fg_valid = true, .get_max_voltage = axp22x_battery_get_max_voltage, .set_max_voltage = axp22x_battery_set_max_voltage, @@ -567,6 +598,7 @@ static const struct axp_data axp221_data = { static const struct axp_data axp813_data = { .ccc_scale = 200000, .ccc_offset = 200000, + .has_fg = true, .has_fg_valid = true, .get_max_voltage = axp813_battery_get_max_voltage, .set_max_voltage = axp20x_battery_set_max_voltage, From patchwork Sun Oct 16 23:43:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aidan MacDonald X-Patchwork-Id: 616362 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 0FFFBC43217 for ; Sun, 16 Oct 2022 23:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbiJPXno (ORCPT ); Sun, 16 Oct 2022 19:43:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230111AbiJPXnT (ORCPT ); Sun, 16 Oct 2022 19:43:19 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E340F399CD; Sun, 16 Oct 2022 16:42:36 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id y10so7616867wma.0; Sun, 16 Oct 2022 16:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=7GeqA6RimLfLm9Mc18q8mMiWhfUsPblKqcrMhkZEToU=; b=LPqoEX9APVxjLOUyQH+1IzLg92/TOVSLvZn+fPPTowM2hxzd75s6hE6i6eX+5aP+Qw AR/6W8TnL0y9Tg4cqkAy9lbEW1v1NaQkEJhm+ICwGdpKY4ETyVJtuJLxJPC92IBCUCr4 /C67vziOG8rBUo1xPTFP2Yc4HlEy9RIVQqp9HrGOs/uZK++ecmdLPtM+7X9BFyQTDjD9 SnkJ4O+FP5Lb5c07XdWTgAsdREFkqwoBdcssT0MvTURTxpaqO3rVNLWDdAWutyumQWgn EucpPcfgIxbgVvU4eiLYP/sxXNiV/caucPXfNUkS3qby/T02htXiwKhYEkAFMoM+A/9V cb6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=7GeqA6RimLfLm9Mc18q8mMiWhfUsPblKqcrMhkZEToU=; b=MA66+ysGyAuC4s399kYI5JYRof4EnLJZtoayRahUvvY/SKLWQTy16nrz5cWsMa2ddX 8E2N5wQXrxuv/bYqz6d+2CJw0lr8ere2fVLNbURZlA6jRbOZdgDkOgdCwcMuTUJNcjT3 WaDFdFl++bmdJqHRIhb5Er+jIk3qO7zM8HFRaB8fuTeDuyPhW8rXLVKvCgUkCEqgtHmw KrwtPF82tDpR0ft0XY9ZQBz1H/GsPlljTL5xGXltkTtuCJ7OyZwXF3A4jOpy7VxrbIuS Uat3IKTzpGry79DPIJhxJvU2jG7MZ1WFm/bxZwUqdydYBixB53D1i+nLs5/2/20t4ajF 6blQ== X-Gm-Message-State: ACrzQf2DN5nw0dkEI4MA+N4MrTnz06YpZcbj7F3GBSkol459LSvgJqwR 9c6XDukzvohAPKm/9EdwGxI= X-Google-Smtp-Source: AMsMyM7OzezZkfSVx0BmqVE2Xlsd36XVkmtVLM4u3fU8/A29efl49HSOCeA7D9eONFNlaUQPaUPRVg== X-Received: by 2002:a05:600c:4e01:b0:3c6:eba6:75a3 with SMTP id b1-20020a05600c4e0100b003c6eba675a3mr8367606wmq.4.1665963754081; Sun, 16 Oct 2022 16:42:34 -0700 (PDT) Received: from localhost (188.31.4.189.threembb.co.uk. [188.31.4.189]) by smtp.gmail.com with ESMTPSA id f8-20020a05600c4e8800b003b4cba4ef71sm15400056wmq.41.2022.10.16.16.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 16 Oct 2022 16:42:33 -0700 (PDT) From: Aidan MacDonald To: jic23@kernel.org, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, wens@csie.org, lee.jones@linaro.org, sre@kernel.org, lgirdwood@gmail.com, broonie@kernel.org Cc: lars@metafoo.de, andy.shevchenko@gmail.com, linus.walleij@linaro.org, brgl@bgdev.pl, michael@walle.cc, samuel@sholland.org, linux-iio@vger.kernel.org, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Sebastian Reichel Subject: [PATCH v6 13/13] power: axp20x_battery: Add support for AXP192 Date: Mon, 17 Oct 2022 00:43:35 +0100 Message-Id: <20221016234335.904212-14-aidanmacdonald.0x0@gmail.com> In-Reply-To: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> References: <20221016234335.904212-1-aidanmacdonald.0x0@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AXP192 has a battery charger similar to other X-Powers PMICs, but unlike the other supported devices, it does not have a fuel gauge and can't report battery capacity directly. Acked-by: Sebastian Reichel Reviewed-by: Andy Shevchenko Signed-off-by: Aidan MacDonald --- drivers/power/supply/axp20x_battery.c | 49 +++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/axp20x_battery.c b/drivers/power/supply/axp20x_battery.c index 574c1d001556..1e84d26ce8e3 100644 --- a/drivers/power/supply/axp20x_battery.c +++ b/drivers/power/supply/axp20x_battery.c @@ -544,6 +544,19 @@ static int axp20x_battery_set_prop(struct power_supply *psy, } } +static enum power_supply_property axp192_battery_props[] = { + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT, + POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX, + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN, + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, +}; + static enum power_supply_property axp20x_battery_props[] = { POWER_SUPPLY_PROP_PRESENT, POWER_SUPPLY_PROP_ONLINE, @@ -568,6 +581,16 @@ static int axp20x_battery_prop_writeable(struct power_supply *psy, psp == POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX; } +static const struct power_supply_desc axp192_batt_ps_desc = { + .name = "axp192-battery", + .type = POWER_SUPPLY_TYPE_BATTERY, + .properties = axp192_battery_props, + .num_properties = ARRAY_SIZE(axp192_battery_props), + .property_is_writeable = axp20x_battery_prop_writeable, + .get_property = axp20x_battery_get_prop, + .set_property = axp20x_battery_set_prop, +}; + static const struct power_supply_desc axp20x_batt_ps_desc = { .name = "axp20x-battery", .type = POWER_SUPPLY_TYPE_BATTERY, @@ -578,6 +601,19 @@ static const struct power_supply_desc axp20x_batt_ps_desc = { .set_property = axp20x_battery_set_prop, }; +static const int axp192_ccc_table[AXP20X_CHRG_CTRL1_TGT_CURR+1] = { + 100000, 190000, 280000, 360000, + 450000, 550000, 630000, 700000, + 780000, 880000, 960000, 1000000, + 1080000, 1160000, 1240000, 1320000, +}; + +static const struct axp_data axp192_data = { + .ccc_table = axp192_ccc_table, + .get_max_voltage = axp20x_battery_get_max_voltage, + .set_max_voltage = axp20x_battery_set_max_voltage, +}; + static const struct axp_data axp209_data = { .ccc_scale = 100000, .ccc_offset = 300000, @@ -606,6 +642,9 @@ static const struct axp_data axp813_data = { static const struct of_device_id axp20x_battery_ps_id[] = { { + .compatible = "x-powers,axp192-battery-power-supply", + .data = (void *)&axp192_data, + }, { .compatible = "x-powers,axp209-battery-power-supply", .data = (void *)&axp209_data, }, { @@ -623,6 +662,7 @@ static int axp20x_power_probe(struct platform_device *pdev) struct axp20x_batt_ps *axp20x_batt; struct power_supply_config psy_cfg = {}; struct power_supply_battery_info *info; + const struct power_supply_desc *ps_desc; struct device *dev = &pdev->dev; if (!of_device_is_available(pdev->dev.of_node)) @@ -666,9 +706,12 @@ static int axp20x_power_probe(struct platform_device *pdev) axp20x_batt->data = (struct axp_data *)of_device_get_match_data(dev); - axp20x_batt->batt = devm_power_supply_register(&pdev->dev, - &axp20x_batt_ps_desc, - &psy_cfg); + if (!axp20x_batt->data->has_fg) + ps_desc = &axp192_batt_ps_desc; + else + ps_desc = &axp20x_batt_ps_desc; + + axp20x_batt->batt = devm_power_supply_register(&pdev->dev, ps_desc, &psy_cfg); if (IS_ERR(axp20x_batt->batt)) { dev_err(&pdev->dev, "failed to register power supply: %ld\n", PTR_ERR(axp20x_batt->batt));