Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2277848rwd; Fri, 16 Jun 2023 01:31:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5wLDh+ozmnqKIr0IlA/5STKIdARC9hoIfNtGh6KuzgX4HUzvw9wtmoBqniSQ3i5zdL/fJB X-Received: by 2002:a05:6830:20d5:b0:6a6:4ef2:7c98 with SMTP id z21-20020a05683020d500b006a64ef27c98mr1446184otq.31.1686904310052; Fri, 16 Jun 2023 01:31:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686904310; cv=none; d=google.com; s=arc-20160816; b=QmCdHL4VOye7jUC3Y7D3TDSEf7j1iaiJ28rMzQOZQSdxS2RV0s8KZcN+J0UeZpTbWU Xc6/QbggG24R37xl7VcZqivcipIzIpZyem4MMnqUmduFkVei0zj3Rex/zyw4JybDzCkW q4ayLrF5Vg+1hjpE8S5BJCPiI3KMZI/N8D2OFtRiZXkMkIk7czEl1rT8uKQaOkF4eFvz ZdBXrfhLaT4FNY26APVOQwaougIaWGZaSnyMZYLMKgfvIXdMMnTRlfMJrJv1yzaxwE9d A2CVBw4sMW9IOFOK1Eq45laXLoxeW0MMhu6YKCvbl1+XcM5Ki/fyXzCBpmKXQI5WZ/uu T8oA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=hbHfpXyqzOO5OEZ2rWtk/xIj+SYJUn8zmBtdxpwkBDs=; b=x5wZXM/CEbEEHicHzqeyYpDm7XcwLsTv8uDJ7cu8dFsy3XSa8QYR7stpK29cZiT5gm pLVY9qveiF6njxi7z6xvVIRkFK4SiPr0PSWAIL/fTXAR5hfEItTyQWU5cdApFXxuBEOW G8Y0OXN1et5MJ2yt4UYiDw0jVKyNZSozqDpxmZLCZW780KsC2yN6/adiPPBz+bUpSVKO g6LIM9v1L7lI23lwCUkGyxKJeeGtqquxXmn5UPlvwvSNjLzi7lqM0ziVSdFIqfNTRMnn HUNtJKY6EKReFTFeH2UKJ71B9Z5iq0rgwA9EQnKQT0o5CEURq6oa6ragQ52wg+oIe4Mq vwFA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l190-20020a6391c7000000b0055117ae386fsi2671768pge.488.2023.06.16.01.31.35; Fri, 16 Jun 2023 01:31:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=rock-chips.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240492AbjFPHw6 (ORCPT + 99 others); Fri, 16 Jun 2023 03:52:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231332AbjFPHwx (ORCPT ); Fri, 16 Jun 2023 03:52:53 -0400 Received: from mail-m11879.qiye.163.com (mail-m11879.qiye.163.com [115.236.118.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7E47272A; Fri, 16 Jun 2023 00:52:51 -0700 (PDT) Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11879.qiye.163.com (Hmail) with ESMTPA id 850126804B5; Fri, 16 Jun 2023 15:52:44 +0800 (CST) From: Frank Wang To: linux@roeck-us.net, heikki.krogerus@linux.intel.com, gregkh@linuxfoundation.org, sebastian.reichel@collabora.com, heiko@sntech.de Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, huangtao@rock-chips.com, william.wu@rock-chips.com, jianwei.zheng@rock-chips.com, yubing.zhang@rock-chips.com, wmc@rock-chips.com, Frank Wang Subject: [v4,2/2] usb: typec: tcpm: add get max power support Date: Fri, 16 Jun 2023 15:52:41 +0800 Message-Id: <20230616075241.27690-2-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230616075241.27690-1-frank.wang@rock-chips.com> References: <20230616075241.27690-1-frank.wang@rock-chips.com> X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQ0wdTlYYHUodHklKQxlDGUJVEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSkpLT0tDVUpLS1VLWQ Y+ X-HM-Tid: 0a88c33140312eb5kusn850126804b5 X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MBg6LQw6ET1DIhceSy4tCwJJ LRpPCk9VSlVKTUNNQktKQk1OTklPVTMWGhIXVR0JGhUQVQwaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFISExDNwY+ X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Traverse fixed pdos to calculate the maximum power that the charger can provide, and it can be get by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT property. Signed-off-by: Frank Wang --- Changelog: v4: - No change v3: - Use Microwatts instead of Milliwatts to follow the ABI, commented by Sebastian Reichel. v2: - No change v1: - https://patchwork.kernel.org/project/linux-usb/patch/20230313025843.17162-4-frank.wang@rock-chips.com/ drivers/usb/typec/tcpm/tcpm.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c index 9f6aaa3e70ca8..829d75ebab422 100644 --- a/drivers/usb/typec/tcpm/tcpm.c +++ b/drivers/usb/typec/tcpm/tcpm.c @@ -6340,6 +6340,27 @@ static int tcpm_psy_get_current_now(struct tcpm_port *port, return 0; } +static int tcpm_psy_get_input_power_limit(struct tcpm_port *port, + union power_supply_propval *val) +{ + unsigned int src_mv, src_ma, max_src_uw = 0; + unsigned int i, tmp; + + for (i = 0; i < port->nr_source_caps; i++) { + u32 pdo = port->source_caps[i]; + + if (pdo_type(pdo) == PDO_TYPE_FIXED) { + src_mv = pdo_fixed_voltage(pdo); + src_ma = pdo_max_current(pdo); + tmp = src_mv * src_ma; + max_src_uw = tmp > max_src_uw ? tmp : max_src_uw; + } + } + + val->intval = max_src_uw; + return 0; +} + static int tcpm_psy_get_prop(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) @@ -6369,6 +6390,9 @@ static int tcpm_psy_get_prop(struct power_supply *psy, case POWER_SUPPLY_PROP_CURRENT_NOW: ret = tcpm_psy_get_current_now(port, val); break; + case POWER_SUPPLY_PROP_INPUT_POWER_LIMIT: + tcpm_psy_get_input_power_limit(port, val); + break; default: ret = -EINVAL; break; -- 2.17.1