From patchwork Tue Jul 25 11:40:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326343 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 CF462C001DF for ; Tue, 25 Jul 2023 11:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234949AbjGYLlA (ORCPT ); Tue, 25 Jul 2023 07:41:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235012AbjGYLkt (ORCPT ); Tue, 25 Jul 2023 07:40:49 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316EF1FCC for ; Tue, 25 Jul 2023 04:40:35 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99b9161b94aso345490066b.1 for ; Tue, 25 Jul 2023 04:40:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690285233; x=1690890033; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=OCWWBBRJa0PORsLtnTWiKQp9jCoJ7Z5w0rr05I0MhAM=; b=A65PLuZvDWSYYYDsjc1F+ZXpzZI+oamgjXR5RgxTp9cRoQ9Dne5I+Jh8psRSH78myb A7gqN0mwwpj20DcWesnpkiRR1y/0oDoxMW2YQF6jriAms+leXGFKjnklt/4wJaInyHnD pANYTfJu/uKiRwA8tPws/g+LXN+6so5TwwTgN30x8YjP+2P4iX0Bf5VzI49W5Rey7lcA m+dK9+9YHD//oL23pNz9tydLv7vA2IQtnvHSTwKcSe98dC3zblljuMHuDEsOVINXb535 AI/BqWNjgFBPXrudag3p1/C1VjTcqKp+5yXHOVTkDkb3pRnZ1VohwoBv+4VrR4mJoCB8 HKBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690285233; x=1690890033; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OCWWBBRJa0PORsLtnTWiKQp9jCoJ7Z5w0rr05I0MhAM=; b=JCSCvGyITdgnHGKz/mraBL70I0NPA971mvIQGxdyT/j/ftl3IVryt7NpTCRCqjfjYL yoJ9offp4iLDLP7ojZnxkWICAZAhqogeKrZHB0rGVOI/2GVXHCMwVzd/FenUsFQ68eWW NqywfPCB13WrB+yE2BvuIlQw83vJjj99Y88eNLhDZ5QcVErvmXtkPu9F5MYNY2dgkFj1 gtPKg0wWRj0GW8pBNvsHmgcxNfsfDgNtPWCwh2LD0i9Xtz2UqIIGGkTd7o94OcD675Q2 p+Y9VcF6zgkZp3eGpAIiGgqBBvUh9Y2D0k3OwasfyHKDwtFUJ9ymmVtHlJ3TA+bMvhvq 7X6w== X-Gm-Message-State: ABy/qLaRK8nYe4JqUTovxzRsBDsA+nMddAxlkqmYxrTjlgoiYetHmmFG aS0dWtd4+S8GRoYiWpFmpaqbmw== X-Google-Smtp-Source: APBJJlFS6kYrnmiucY9eWirPBclgdbF4vnVSeCw6/ChNL+5oAgMp6DRN0T580c2uPfxcC++hVTOUoQ== X-Received: by 2002:a17:906:9bdd:b0:99b:4e75:52bb with SMTP id de29-20020a1709069bdd00b0099b4e7552bbmr12428460ejc.69.1690285233475; Tue, 25 Jul 2023 04:40:33 -0700 (PDT) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id d6-20020a1709067f0600b009925cbafeaasm8088206ejr.100.2023.07.25.04.40.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 04:40:32 -0700 (PDT) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , Jean Delvare , krzysztof.kozlowski+dt@linaro.org, Rob Herring , Conor Dooley Cc: linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki , Rob Herring , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] dt-bindings: hwmon: Add Infineon TDA38640 Date: Tue, 25 Jul 2023 13:40:26 +0200 Message-ID: <20230725114030.1860571-1-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph The TDA38640 has a bug in SVID mode and to enable a workaround remove the TDA38640 from trivial-devices and add a complete schema. The schema adds the custom property 'infineon,en-pin-fixed-level' to signal a fixed level on the ENABLE pin and to enable the workaround. When the ENABLE pin is left floating it's internally pulled low. If not specified the driver will continue to use the PMBUS_OPERATION register to enable the regulator. When specified the driver will use the PMBUS_ON_OFF_CONFIG register to enable the regulator. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- .../hwmon/pmbus/infineon,tda38640.yaml | 50 +++++++++++++++++++ .../devicetree/bindings/trivial-devices.yaml | 2 - 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml base-commit: 55612007f16b5d7b1fb83a7b0f5bb686829db7c7 diff --git a/Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml b/Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml new file mode 100644 index 000000000000..520112e4e271 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/pmbus/infineon,tda38640.yaml @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- + +$id: http://devicetree.org/schemas/hwmon/pmbus/infineon,tda38640.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Infineon TDA38640 Synchronous Buck Regulator with SVID and I2C + +description: | + The Infineon TDA38640 is a 40A Single-voltage Synchronous Buck + Regulator with SVID and I2C designed for Industrial use. + + Datasheet: https://www.infineon.com/dgdl/Infineon-TDA38640-0000-DataSheet-v02_04-EN.pdf?fileId=8ac78c8c80027ecd018042f2337f00c9 + +properties: + compatible: + enum: + - infineon,tda38640 + + reg: + maxItems: 1 + + infineon,en-pin-fixed-level: + $ref: /schemas/types.yaml#/definitions/uint32 + description: | + Fixed level of the ENABLE pin. When specified the PMBUS_ON_OFF_CONFIG + register is used to enable the regulator instead of the PMBUS_OPERATION + register to workaround a bug of the tda38640 when operating in SVID-mode. + If the ENABLE pin is left floating the internal pull-down causes a low + level on the pin. + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + tda38640@40 { + compatible = "infineon,tda38640"; + reg = <0x40>; + }; + }; + diff --git a/Documentation/devicetree/bindings/trivial-devices.yaml b/Documentation/devicetree/bindings/trivial-devices.yaml index 6e24c4d25ec3..2b1fbb2a672b 100644 --- a/Documentation/devicetree/bindings/trivial-devices.yaml +++ b/Documentation/devicetree/bindings/trivial-devices.yaml @@ -151,8 +151,6 @@ properties: - infineon,slb9645tt # Infineon SLB9673 I2C TPM 2.0 - infineon,slb9673 - # Infineon TDA38640 Voltage Regulator - - infineon,tda38640 # Infineon TLV493D-A1B6 I2C 3D Magnetic Sensor - infineon,tlv493d-a1b6 # Infineon Multi-phase Digital VR Controller xdpe11280 From patchwork Tue Jul 25 11:40:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326344 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 260A9C04E69 for ; Tue, 25 Jul 2023 11:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235050AbjGYLlC (ORCPT ); Tue, 25 Jul 2023 07:41:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235017AbjGYLku (ORCPT ); Tue, 25 Jul 2023 07:40:50 -0400 Received: from mail-ej1-x629.google.com (mail-ej1-x629.google.com [IPv6:2a00:1450:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32A7A1FD2 for ; Tue, 25 Jul 2023 04:40:36 -0700 (PDT) Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-992f15c36fcso925034266b.3 for ; Tue, 25 Jul 2023 04:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690285234; x=1690890034; 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=4EsAms/GBsK+1iUec9cOrJls/H2UjnYhAk3txEAwGRk=; b=cYToPYjk35PirQBwQx8NE3OVoFdb2pztaQ5bfC/OWBAdEiyHG2ot3SaseXH3+8zh/s zeu39mYeFkkyabzPpyRttmL4hapAwNo8OEKlRmb1geJTTieV2esQtH7w2lEp9cEzvCHR ir1XdGJCd7UWDP8mlJlFMczth2qG7Ibif4ZSWQ56oMuoUVujyOp7UxTeLsgwDHorGsyN gWsTLFNDQAjeLSjqyxooiHyMRFlpdReL3dUJAVTHnZoDotCXA6Ht5mBMJINufi+R0hr/ i0qyhLOkNuYkVEDRM9yEpHS8+i7mPFzzYB9cSBaqOoeSAPEzcjAtfgjhI1x1EICLzAAf DmJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690285234; x=1690890034; 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=4EsAms/GBsK+1iUec9cOrJls/H2UjnYhAk3txEAwGRk=; b=AnKfoEWpcLYjxDYTjAUWJIyYuts+v2rHU6dCn64VCbReP9hfxNaiJ/27vQpWJ7Z67m k1EUFCsAZUB4ALyDIfofH1Kqf/PLA+g0cGTtQtWNc9DFDgt7c8WEqKQgQoG4RDatOZRP y1dMkMRvJcebJUexgNzUOb9RSS1eezTpB0zc11686dK5PwVw/jAYLLOI08SByKmitO25 vfVYLGfJfZB7foz/W+2o455Vm9MhMtSxex81qIn1lKS7JSoqXpJAQkn1ADT72BMnm8TQ 2npDWyt5N6HhM9Lg4V5vycIkHGEW6aTJ8fULbm7f+zJdMvEKQb/l+0e6QDXydIwydqwX CsPw== X-Gm-Message-State: ABy/qLavZthJaas1e4BaI/DmQzzo9wc6K1Qw30lgPHUlNV1jwTyjrGTx yg8LRncME3GHVFtbBqVg2fqztQ== X-Google-Smtp-Source: APBJJlHdTrdKDN3QHK37zBnlfxTsGeEnuQPKPszxCG5So9c4ue9V0GUISNjAv6fhrva4zHO2Y2kpgQ== X-Received: by 2002:a17:906:318d:b0:99b:b2fb:27b3 with SMTP id 13-20020a170906318d00b0099bb2fb27b3mr1323318ejy.41.1690285234773; Tue, 25 Jul 2023 04:40:34 -0700 (PDT) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id d6-20020a1709067f0600b009925cbafeaasm8088206ejr.100.2023.07.25.04.40.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 04:40:34 -0700 (PDT) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , Jean Delvare , krzysztof.kozlowski+dt@linaro.org Cc: linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] hwmon: (pmbus) Add ON_OFF_CONFIG register bits Date: Tue, 25 Jul 2023 13:40:27 +0200 Message-ID: <20230725114030.1860571-2-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725114030.1860571-1-Naresh.Solanki@9elements.com> References: <20230725114030.1860571-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph Add bits found in the ON_OFF_CONFIG register. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/pmbus.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/hwmon/pmbus/pmbus.h b/drivers/hwmon/pmbus/pmbus.h index b0832a4c690d..7a28bac7f171 100644 --- a/drivers/hwmon/pmbus/pmbus.h +++ b/drivers/hwmon/pmbus/pmbus.h @@ -243,6 +243,15 @@ enum pmbus_regs { */ #define PB_OPERATION_CONTROL_ON BIT(7) +/* + * ON_OFF_CONFIG + */ +#define PB_ON_OFF_CONFIG_POWERUP_CONTROL BIT(4) +#define PB_ON_OFF_CONFIG_OPERATION_REQ BIT(3) +#define PB_ON_OFF_CONFIG_EN_PIN_REQ BIT(2) +#define PB_ON_OFF_CONFIG_POLARITY_HIGH BIT(1) +#define PB_ON_OFF_CONFIG_TURN_OFF_FAST BIT(0) + /* * WRITE_PROTECT */ From patchwork Tue Jul 25 11:40:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naresh Solanki X-Patchwork-Id: 13326345 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 F3DE5C001E0 for ; Tue, 25 Jul 2023 11:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235058AbjGYLlD (ORCPT ); Tue, 25 Jul 2023 07:41:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234943AbjGYLkv (ORCPT ); Tue, 25 Jul 2023 07:40:51 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8F901FE1 for ; Tue, 25 Jul 2023 04:40:37 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-98377c5d53eso866270366b.0 for ; Tue, 25 Jul 2023 04:40:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=9elements.com; s=google; t=1690285236; x=1690890036; 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=AhNRFqKFycYKruMGsOn/+moIjC44ZjyIo8XOGyCOCbo=; b=W2qr9brom56oLdtsCeuu9GTb8LiKF8Rmiyb6kPM5pb4gsnB1NMl/kBvG4z0HQiFyWi wcrClJsqLQTy8wIFPOp5VbuInGicV4S5RseU2Gb94+uX+6v2Zt0555n2P9WSO8/IaElb cbqPHTwMNEkk9OmFPNJwtTfhmm7m2lLJSwfTRkE0J8MoXPAe3skVCjhmoqncJpmBl1Lr fL05Q/A3IodQggCnh72C/zDDHPJWwH4sI2EvbTC7MabLDtmdffdAkkhf3SZt6zDx8dnV hvYP2JxodPEFQawW+88ZveccEvZ2aVX6Y1Y6Klt+QWyvKfePRwlS9LiG9fS0QI6yI/ri 6PKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690285236; x=1690890036; 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=AhNRFqKFycYKruMGsOn/+moIjC44ZjyIo8XOGyCOCbo=; b=OOPcuu04IZG97U+exEnh2oLNrNhUWFL71Q83aQwgmzGPbXM/C3MvLoX8/uMCOHlghK OxZV8YqrlX2FEvDzaK45ONxnr3CCzer2vGxtUJV+OjSuzLgSoEFWU225iSHnc93aIsMG hpWMxAx7/PKXwj69mglk8CyEogyWS8lQbnsOgegineC8IBU2033ZrkajJtL3m5tTbSrB TrZ1UKTAapb0LnBHmTakvR4LgdwZiS9i3GAcMRXPJZ3oShKzF4JA4MflHjLOEeLLFbrZ 6HOkX8I1EHTSgVcO+f5PZpm+/0ZFPp+tUD8zAwbFmZov+PUVqjG4AigrfwwbKG0LrwlV bEUg== X-Gm-Message-State: ABy/qLabjjRSOqKRE6XFJJ8vIM1xd51N6Me/Ji/eJGSddD8GCkbhL4KA S5r2kxFvVjgNbRVxKBMX10bHog== X-Google-Smtp-Source: APBJJlEYKr4k9vX9l1hBB3qpQa6GwkQ6GVgVlbcGeB/RqmZwjIkCu/ps2Hsbrzuu+EaDsTLiNlnCDg== X-Received: by 2002:a17:906:209e:b0:993:d617:bdc2 with SMTP id 30-20020a170906209e00b00993d617bdc2mr12718738ejq.75.1690285236112; Tue, 25 Jul 2023 04:40:36 -0700 (PDT) Received: from stroh80.sec.9e.network (ip-078-094-000-051.um19.pools.vodafone-ip.de. [78.94.0.51]) by smtp.gmail.com with ESMTPSA id d6-20020a1709067f0600b009925cbafeaasm8088206ejr.100.2023.07.25.04.40.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jul 2023 04:40:35 -0700 (PDT) From: Naresh Solanki X-Google-Original-From: Naresh Solanki To: Guenter Roeck , Jean Delvare , krzysztof.kozlowski+dt@linaro.org Cc: linux-hwmon@vger.kernel.org, Patrick Rudolph , Naresh Solanki , linux-kernel@vger.kernel.org Subject: [PATCH 3/3] hwmon: (pmbus/tda38640) Add workaround for bug in SVID mode Date: Tue, 25 Jul 2023 13:40:28 +0200 Message-ID: <20230725114030.1860571-3-Naresh.Solanki@9elements.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725114030.1860571-1-Naresh.Solanki@9elements.com> References: <20230725114030.1860571-1-Naresh.Solanki@9elements.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org From: Patrick Rudolph The TDA38640 supports two operating modes to set the output voltage: - PMBUS - SVID Due to an undocumented bug the regulator cannot be enabled using BIT7 of OPERATION(01h) register when in SVID mode. It works when in PMBUS mode. In SVID mode the regulator only cares about the ENABLE pin. Add a workaround that needs the ENABLE pin to be left floating or tied to a fixed level. The DT must contain the newly introduced property 'infineon,en-pin-fixed-level' to enable this workaround. The workaround will map the PB_OPERATION_CONTROL_ON bit to the PB_ON_OFF_CONFIG_EN_PIN_REQ bit of the ON_OFF_CONFIG register. In combination with the fixed level on the ENABLE pin the regulator can be controlled as expected. Signed-off-by: Patrick Rudolph Signed-off-by: Naresh Solanki --- drivers/hwmon/pmbus/tda38640.c | 95 +++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 2 deletions(-) diff --git a/drivers/hwmon/pmbus/tda38640.c b/drivers/hwmon/pmbus/tda38640.c index 450b0273fb59..9d3b89d9845c 100644 --- a/drivers/hwmon/pmbus/tda38640.c +++ b/drivers/hwmon/pmbus/tda38640.c @@ -18,6 +18,72 @@ static const struct regulator_desc __maybe_unused tda38640_reg_desc[] = { PMBUS_REGULATOR("vout", 0), }; +struct tda38640_data { + struct pmbus_driver_info info; + u32 en_pin_lvl; +}; + +#define to_tda38640_data(x) container_of(x, struct tda38640_data, info) + +/* + * Map PB_ON_OFF_CONFIG_POLARITY_HIGH to PB_OPERATION_CONTROL_ON. + */ +static int tda38640_read_byte_data(struct i2c_client *client, int page, int reg) +{ + const struct pmbus_driver_info *info = pmbus_get_driver_info(client); + struct tda38640_data *data = to_tda38640_data(info); + int ret, on_off_config, enabled; + + if (reg != PMBUS_OPERATION) + return -ENODATA; + + ret = pmbus_read_byte_data(client, page, reg); + if (ret < 0) + return ret; + + on_off_config = pmbus_read_byte_data(client, page, + PMBUS_ON_OFF_CONFIG); + if (on_off_config < 0) + return on_off_config; + + enabled = !!(on_off_config & PB_ON_OFF_CONFIG_POLARITY_HIGH); + + enabled ^= data->en_pin_lvl; + if (enabled) + ret &= ~PB_OPERATION_CONTROL_ON; + else + ret |= PB_OPERATION_CONTROL_ON; + + return ret; +} + +/* + * Map PB_OPERATION_CONTROL_ON to PB_ON_OFF_CONFIG_POLARITY_HIGH. + */ +static int tda38640_write_byte_data(struct i2c_client *client, int page, + int reg, u8 byte) +{ + const struct pmbus_driver_info *info = pmbus_get_driver_info(client); + struct tda38640_data *data = to_tda38640_data(info); + int enable, ret; + + if (reg != PMBUS_OPERATION) + return -ENODATA; + + enable = !!(byte & PB_OPERATION_CONTROL_ON); + + byte &= ~PB_OPERATION_CONTROL_ON; + ret = pmbus_write_byte_data(client, page, reg, byte); + if (ret < 0) + return ret; + + enable ^= data->en_pin_lvl; + + return pmbus_update_byte_data(client, page, PMBUS_ON_OFF_CONFIG, + PB_ON_OFF_CONFIG_POLARITY_HIGH, + enable ? 0 : PB_ON_OFF_CONFIG_POLARITY_HIGH); +} + static struct pmbus_driver_info tda38640_info = { .pages = 1, .format[PSC_VOLTAGE_IN] = linear, @@ -26,7 +92,6 @@ static struct pmbus_driver_info tda38640_info = { .format[PSC_CURRENT_IN] = linear, .format[PSC_POWER] = linear, .format[PSC_TEMPERATURE] = linear, - .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_IIN @@ -41,7 +106,33 @@ static struct pmbus_driver_info tda38640_info = { static int tda38640_probe(struct i2c_client *client) { - return pmbus_do_probe(client, &tda38640_info); + struct device *dev = &client->dev; + struct device_node *np = dev_of_node(dev); + struct tda38640_data *data; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + memcpy(&data->info, &tda38640_info, sizeof(tda38640_info)); + + if (!CONFIG_SENSORS_TDA38640_REGULATOR || !np || + of_property_read_u32(np, "infineon,en-pin-fixed-level", &data->en_pin_lvl)) + return pmbus_do_probe(client, &data->info); + + /* + * Apply ON_OFF_CONFIG workaround as enabling the regulator using the + * OPERATION register doesn't work in SVID mode. + */ + data->info.read_byte_data = tda38640_read_byte_data; + data->info.write_byte_data = tda38640_write_byte_data; + /* + * One should configure PMBUS_ON_OFF_CONFIG here, but + * PB_ON_OFF_CONFIG_POWERUP_CONTROL, PB_ON_OFF_CONFIG_EN_PIN_REQ and + * PB_ON_OFF_CONFIG_EN_PIN_REQ are ignored by the device. + * Only PB_ON_OFF_CONFIG_POLARITY_HIGH has an effect. + */ + + return pmbus_do_probe(client, &data->info); } static const struct i2c_device_id tda38640_id[] = {