Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1980809rwd; Thu, 15 Jun 2023 19:39:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4l0Nvrqi5O5q72DK21mr/Jw5Ksk/qAL5xpOLWdLWMQthVNz7kIleTAPmqnS/s36Wm0wGz9 X-Received: by 2002:a05:6a00:1391:b0:666:aa9b:3eb0 with SMTP id t17-20020a056a00139100b00666aa9b3eb0mr881619pfg.31.1686883168645; Thu, 15 Jun 2023 19:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686883168; cv=none; d=google.com; s=arc-20160816; b=IH93/jS1SsoI7DFx01Y6+cc5u6JmBNLS5sjzvXN86QrRxJ/2coVGKrOFD7OB+fOcMU qX2OqSGFenFD7tEBGiHYis2mIFdyp+uULNq7CPCEPf415WEQDfzRAeQdLCreMDy517nP 9oO92PsOvyPr9jRe4YZJtjU4N4642a2V+eyRoAMQOb6Ix1hMXUojT6Vp1gLO9IrChks2 6kzPJ5WyL7+Jg1/nPwLGZYKfMwMLB1/Q15yVDCniBz5rHgHu0FFfJoDVEACQdcaDY0Gb C+vmtT5SBfdD613fR/WQ1wYuAA7ggAxBWR85AtLq4v5h8EgI4fGbvJk2sKSbZT4xJ7rZ ZVzQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=lHBfyYUXW/saWUQVfWS3uvBbU/lpwrWaibx0CxtZmrc=; b=dR3xNbb1lcP9OEqgXc6kwIaofGAVqgA3oLN4JcRNP7B05HffHSpbwlXOlwdZWaXhCx 8J4TdyHJC66sVCPoFRhgiIyJQRlhobe7nYnva9gXpC0wB0Bj+yIqwztc9xGgvDoFj+O9 ddK+59xeTOI3ZeF8/WK8wXvtcRUbVIYb35R8xBR0KstYKcGcGXI/67ib4QYHiH4QHTDb Bk2AqGq3ZMVgIF56jT2fQHGOw8u0WyBC//tuUmgQeHMUwg0C+Lp908DUwQ0Sv/a8F4iO xus6f2LLUk/pbn3tT+EYqzmJspkk4Rpddzp7Qf0dHQ/K/BZopI1/feFiHrDOSzCvU+FZ kjWw== 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 c27-20020a056a00009b00b0063b8ab7f91csi14026849pfj.365.2023.06.15.19.39.14; Thu, 15 Jun 2023 19:39:28 -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 S239403AbjFPCWJ (ORCPT + 99 others); Thu, 15 Jun 2023 22:22:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240805AbjFPCWH (ORCPT ); Thu, 15 Jun 2023 22:22:07 -0400 Received: from mail-m11876.qiye.163.com (mail-m11876.qiye.163.com [115.236.118.76]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 853B71707; Thu, 15 Jun 2023 19:22:02 -0700 (PDT) Received: from localhost.localdomain (unknown [58.22.7.114]) by mail-m11876.qiye.163.com (Hmail) with ESMTPA id EE24A3C02EE; Fri, 16 Jun 2023 10:21:58 +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: usb: typec: tcpm: add get max power support Date: Fri, 16 Jun 2023 10:21:57 +0800 Message-Id: <20230616022157.25877-1-frank.wang@rock-chips.com> X-Mailer: git-send-email 2.17.1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFDSUNOT01LS0k3V1ktWUFJV1kPCRoVCBIfWUFZQktITVYfHkhPTEkdS00ZQkNVEwETFh oSFyQUDg9ZV1kYEgtZQVlOQ1VJSVVMVUpKT1lXWRYaDxIVHRRZQVlPS0hVSk5MSUpJVUpLS1VKQl kG X-HM-Tid: 0a88c2026e6a2eb2kusnee24a3c02ee X-HM-MType: 1 X-HM-Sender-Digest: e1kMHhlZQR0aFwgeV1kSHx4VD1lBWUc6MDo6Czo4OD1REBBLFiEcEggI GDYwCwtVSlVKTUNNQ0NJSkpCTEhMVTMWGhIXVR0JGhUQVQwaFRw7CRQYEFYYExILCFUYFBZFWVdZ EgtZQVlOQ1VJSVVMVUpKT1lXWQgBWUFJQ01PNwY+ 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 got by POWER_SUPPLY_PROP_INPUT_POWER_LIMIT property. Signed-off-by: Frank Wang --- 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