From patchwork Mon Nov 25 08:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sung-Chi, Li" X-Patchwork-Id: 13884563 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 933F733987 for ; Mon, 25 Nov 2024 08:31:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732523492; cv=none; b=CiXqyGBskaCQNlFzWzUe7V5G1LQ5233hevOed7ox0zzuOpmx4GfoXN5vdTSxWRZvnjjxYHtJh4f6c9RTeCftuHWETjxz056BoUWvKTQzfgqBWxrBtG2ZP3JwBc2HMFv/2swpKOZk031D12xzjSlm4vhgW8XHwpc7xiJjgvaZqw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732523492; c=relaxed/simple; bh=Z9o0zBt1p8Fbtg42SUEpQ9tA831XqF2aBKjtqmgJJZg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=q68DOZrPkTspRzn5zygRL0D2gDPdseEkqYbWtvoykMJI23NHtRG/WIcijCRw0KmnbYAnfl1/S74/9ixIHO7/wtJi+zNc84C/7rvyhlNrz4agJRJ815B6qYxjD9AE8NUcHDrcJE8ggbs2V07nzWD7DPE6do1fGxZPyex/aX3KSGY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=Fs8vT4iO; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Fs8vT4iO" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2126408cf31so30401365ad.0 for ; Mon, 25 Nov 2024 00:31:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732523490; x=1733128290; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=gsxN4SRIKBH72Tu6V02jm4aTE1CgMy52+kme9RyF4tE=; b=Fs8vT4iOVcLGtKwwlNC/r/uLXsQVl2irboCafbwNoGiVz4GZRZ8rqFs85pLms81+XN /0ddEbTslWgdLBQehJYxGaODPO803Ph4LouKWhBN7MuHBUIWeTQju3yZ7oCyoWxSWF1p ij1a84CSAsRaDFq6Vx1GwBjgn/lwJANqjxFWE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732523490; x=1733128290; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=gsxN4SRIKBH72Tu6V02jm4aTE1CgMy52+kme9RyF4tE=; b=uyfR0kICxk6SRHjtF0UASr7zM8wdZ9Wg2rYReZAsJgIoMhjBpAglWxPcF0x2J4O3Fz P8VN8F3JNXwq0PIDuSCs3Go91QoahlXl10/ZB7uv/OB1pIcIo5AjKl430jPU8iSlQ2u3 Oi9XVkmFTQwgcDIrFEdA8xmL4KeRi9wfFngoOSmeMSUlB7no/IFxc6dMRBVfxvbV5jb7 Dvk7KJnkqUpZviCPg7mA+f8vNIFrBJiRG29Ly4H8kLPcOMBJvDbygmu2FDooqWWOexD0 nJRuc+tGvB4831QTB7wT+TNA4kROuMjIEg5ogX6Q9H1mV0q3MDgJAP2kGpQRgNpyV1Ur BFmg== X-Forwarded-Encrypted: i=1; AJvYcCU5kMJBmckf2xMDCLs0sflEY+fjbIr7ZJj/ZY+Al5GDC5gdb0xMvfuFBig2NCZdOlSrJW8KHGjZ6w==@vger.kernel.org X-Gm-Message-State: AOJu0Yyr+18WKVKeZgrgU4AlI+eQwIVX8gBN2Mgoph3ASWsiyvsm5Ihz GCPTcqFZlyzREN6AhkxhjNPCnnqq2t3pACtfFqM+ilRg9xM7WrBAY53/t+AL9A== X-Gm-Gg: ASbGncsQb3Vh8j/3bRpcmR1Fk9lZyu7psJJFQpzPYa8UNbNM/7kIm/DF7yT0s1w6b1x AWJRvm93FCKZEsTRC3A96ZArQnM0xM9Y9QP26GM9vq0+NvTIQ3kOwy+NIOlfhtaxnYOZ8C8ByRa qggWhM01Kx+eBArsmK55AJ8YU5lRS5wXgNuM2QMzwHxAH2CVNndPchLJdKdJa+98LvpUzd54hSG NwXh+j0oqETNZbjKIKITZTqyUuX86I10FgenfTujfrJSsRLoInE4m6EXsYRDVn4bQUkT6Yk X-Google-Smtp-Source: AGHT+IElfYm4ovmTHj2+mTSX4Iki8fGKuWTAto+ePAtH8SREZcFJUbZFxKAbnjYxZwRfgDH7pFKmgA== X-Received: by 2002:a17:902:d48b:b0:210:fce4:11db with SMTP id d9443c01a7336-2129f557214mr205937125ad.22.1732523489941; Mon, 25 Nov 2024 00:31:29 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:66a3:d18f:544f:227a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dbfece2sm59090025ad.157.2024.11.25.00.31.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 00:31:29 -0800 (PST) From: Sung-Chi Li Date: Mon, 25 Nov 2024 16:31:16 +0800 Subject: [PATCH v2 1/2] power: supply: cros_usbpd-charger: extend as a thermal of cooling device Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241125-extend_power_limit-v2-1-c3266a86e9b1@chromium.org> References: <20241125-extend_power_limit-v2-0-c3266a86e9b1@chromium.org> In-Reply-To: <20241125-extend_power_limit-v2-0-c3266a86e9b1@chromium.org> To: Benson Leung , Guenter Roeck , Sebastian Reichel , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: chrome-platform@lists.linux.dev, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sung-Chi Li X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732523485; l=5418; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=Z9o0zBt1p8Fbtg42SUEpQ9tA831XqF2aBKjtqmgJJZg=; b=u0ppdMgicsIpoqlOU/qoi5m7vJzwW0+wr7fdKUJ/u8eOUo4g3VrbIQDpVcfRCAqswBMrxU2QE W4e9WxlOzFJCCy9/oekvD4I0EUjz3+jrDw1b2ZfOP6/qqwX/gCaZZj/ X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= A charge chip is connected to the ChromeOS Embedded Controller (EC). When external power input into the system, current would go through the charger chip, generating heat in the system. The EC supports limiting the input current, thus reducing the generated heat. cros_usbpd-charger is the driver that takes care the system input power from the pd charger. This driver also exposes the functionality to limit input current. As a result, extend this driver to make it as a passive thermal cooling device by limiting the input current. This commit implements the required cooling methods and OF style registration. Signed-off-by: Sung-Chi Li --- drivers/power/supply/cros_usbpd-charger.c | 84 ++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/cros_usbpd-charger.c b/drivers/power/supply/cros_usbpd-charger.c index 47d3f58aa15c..a080090898c0 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -13,6 +13,7 @@ #include #include #include +#include #define CHARGER_USBPD_DIR_NAME "CROS_USBPD_CHARGER%d" #define CHARGER_DEDICATED_DIR_NAME "CROS_DEDICATED_CHARGER" @@ -22,6 +23,7 @@ sizeof(CHARGER_DEDICATED_DIR_NAME)) #define CHARGER_CACHE_UPDATE_DELAY msecs_to_jiffies(500) #define CHARGER_MANUFACTURER_MODEL_LENGTH 32 +#define CHARGER_COOLING_INTERVALS 10 #define DRV_NAME "cros-usbpd-charger" @@ -76,6 +78,8 @@ static enum power_supply_property cros_usbpd_dedicated_charger_props[] = { /* Input voltage/current limit in mV/mA. Default to none. */ static u16 input_voltage_limit = EC_POWER_LIMIT_NONE; static u16 input_current_limit = EC_POWER_LIMIT_NONE; +/* Cooling level interns of current limit */ +static u16 input_current_cooling_level; static bool cros_usbpd_charger_port_is_dedicated(struct port_data *port) { @@ -459,13 +463,19 @@ static int cros_usbpd_charger_set_prop(struct power_supply *psy, break; input_current_limit = intval; - if (input_current_limit == EC_POWER_LIMIT_NONE) + if (input_current_limit == EC_POWER_LIMIT_NONE) { dev_info(dev, "External Current Limit cleared for all ports\n"); - else + input_current_cooling_level = 0; + } else { dev_info(dev, "External Current Limit set to %dmA for all ports\n", input_current_limit); + input_current_cooling_level = + input_current_limit * + CHARGER_COOLING_INTERVALS / + port->psy_current_max; + } break; case POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT: ret = cros_usbpd_charger_set_ext_power_limit(charger, @@ -525,6 +535,64 @@ static void cros_usbpd_charger_unregister_notifier(void *data) cros_usbpd_unregister_notify(&charger->notifier); } +static int +cros_usbpd_charger_get_max_cooling_state(struct thermal_cooling_device *cdev, + unsigned long *cooling_level) +{ + *cooling_level = CHARGER_COOLING_INTERVALS; + return 0; +} + +static int +cros_usbpd_charger_get_cur_cooling_state(struct thermal_cooling_device *cdev, + unsigned long *cooling_level) +{ + *cooling_level = input_current_cooling_level; + return 0; +} + +static int +cros_usbpd_charger_set_cur_cooling_state(struct thermal_cooling_device *cdev, + unsigned long cooling_level) +{ + struct charger_data *charger = cdev->devdata; + struct port_data *port; + int current_limit; + int idx = -1; + int ret; + + for (int i = 0; i < charger->num_registered_psy; i++) { + port = charger->ports[i]; + if (port->psy_status == POWER_SUPPLY_STATUS_CHARGING) { + idx = i; + break; + } + } + + if (idx == -1) + return -EINVAL; + + current_limit = + port->psy_current_max - (cooling_level * port->psy_current_max / + CHARGER_COOLING_INTERVALS); + ret = cros_usbpd_charger_set_ext_power_limit(charger, current_limit, + input_voltage_limit); + if (ret < 0) + return ret; + + input_current_limit = (current_limit == port->psy_current_max) ? + EC_POWER_LIMIT_NONE : + current_limit; + input_current_cooling_level = cooling_level; + return 0; +} + +static const struct thermal_cooling_device_ops cros_usbpd_charger_cooling_ops = { + .get_max_state = cros_usbpd_charger_get_max_cooling_state, + .get_cur_state = cros_usbpd_charger_get_cur_cooling_state, + .set_cur_state = cros_usbpd_charger_set_cur_cooling_state, +}; + static int cros_usbpd_charger_probe(struct platform_device *pd) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent); @@ -534,6 +602,7 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) struct charger_data *charger; struct power_supply *psy; struct port_data *port; + struct thermal_cooling_device *cdev; int ret = -EINVAL; int i; @@ -674,6 +743,17 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) goto fail; } + if (IS_ENABLED(CONFIG_THERMAL_OF)) { + cdev = devm_thermal_of_cooling_device_register( + dev, ec_device->dev->of_node, DRV_NAME, charger, + &cros_usbpd_charger_cooling_ops); + if (IS_ERR(cdev)) { + dev_warn_probe( + dev, PTR_ERR(cdev), + "Failing register thermal cooling device\n"); + } + } + return 0; fail: From patchwork Mon Nov 25 08:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sung-Chi, Li" X-Patchwork-Id: 13884564 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4250F18C900 for ; Mon, 25 Nov 2024 08:31:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732523494; cv=none; b=uy1OohsVF24R6X261ikNqTAE1wZVY0N6VhBBk35lxjtxYJV4BC7kPp9iMNx37bnZuWpIlG0/xt8W8tZ8xaxJWlfa4eLFP2PmywXlTyRqGyRQbcHuOdZ1k0iHQl9gDSVzPdAJs93fXM2F1r3ewaLfUlpHM9xn1A5v2Wxwhzc1hmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732523494; c=relaxed/simple; bh=ktJPK16HT87IqUYNk6xW4DxEM+thEREPtW8kVjrlImY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iR/7YNlKYu2bdFlqj/nrpysru/82tfYNOc1eBcHMMSMLYYyQBuzez2wdhCjkDhJK2r/ECFXrmD6RKVG6l5p/ibZcwVxnzzN3cHzHNQxjxxBM12geuGqfUQm9UE+xllhDWCaouuyLnPxdRnE6stR7Q8SREJ+7cfFtSDIoGMI6l6k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=VM5qWAB7; arc=none smtp.client-ip=209.85.214.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="VM5qWAB7" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-211fd6a0a9cso29672325ad.3 for ; Mon, 25 Nov 2024 00:31:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732523492; x=1733128292; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=POCxcDAs1OPhEdapqaVu7R6Wv3Kn60gIQbQM6aiBFqA=; b=VM5qWAB78aQWuRBbdou8G1Lxim/wNWk60mcDRo60vJLSYcU2bsc3nTyJ6M8rRYc+rL P11itXOS/f3ubQpn7G3qFhp4Bwj3lBru6Hfirx0dR+e7VOOcens2t1IUh9eRpuh+bi4a 5oq3Vkg6xqAdT9G/6zVRXYAgjrAo0+RvSEiao= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732523492; x=1733128292; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=POCxcDAs1OPhEdapqaVu7R6Wv3Kn60gIQbQM6aiBFqA=; b=N4k67JFmQ0sVAG250gXFMPuQyaoAIlDLDc4uHgrSoYU5+8NJ5FcX1ienLOd8EFY6AG AHppXZGh4IwAoAOVz1AnWCt8k1IxX92ca0CCLVnwDt57Ql64hAyLKQiJQruQA1jV3Fl6 MaxWBoiF/RqWHBgZ+IMMeffRiXlFB9WT/SpMKCap6ZPRElr3PATCwfXjVfey6a+WUx/C pXVXXr63gd15g09nW8vB5Za8vVlCtdbq9tK3aZn8VEabFQy6mGLAppFauoZXPdRgGAyv 2OL0B6DKf2X3CwoT8Vk7gcP2h9oxExpctDU238FQzdXQ+RhPYRiXyxJINa9UlqZsnxzQ 5uqQ== X-Forwarded-Encrypted: i=1; AJvYcCUYgDxtzFnjE2X+oU2H6ADrmCwl7Iq+HvgFYCJMlUp8ckiMSZSlkYYWvLGitbnDPD6NRgJi4ICeqA==@vger.kernel.org X-Gm-Message-State: AOJu0YyU5TMqI3AY67/DqAehyL+5bqGhmC727hzC07VSIH2RCAhAGse6 MLGz+MU+3Nu26dKppvuYF2yHdQKMbfn2b102r0T6zzq4yVcfhTsDpu/gUsJnuw== X-Gm-Gg: ASbGncu3RiAg7rNghWx/ty8lRT++ApY3CegzaFVyWvggp7XqWFP9kh1zukBpJULO/CQ 3m0Em1BZjci5lA5goT2xZYrdJQIYFrUzdUk43i270uIZaCSUNx+hkRhzM4Mv6agEykeXbHciAsY eqpK9owxZY4TnKiW2eVetG5jWrpu+eQMlzP+KuVAE9RXL8d6+rA/hHXxaOo7mga3RMmSv8+u1EQ L7ZLUO26DOjKtrcu9xmoKYSoPXN7MY0lZYKT/YrR0JM+be4rWNHgJyBTJ6f3J1F1qhyMh3X X-Google-Smtp-Source: AGHT+IHSb4l363kSqeAiiJcrwoOGnozawSDBYK+oCcUIkkFt6/AtetpUnMMRtlfX7k/Ckh1KEU4bSg== X-Received: by 2002:a17:902:f685:b0:20c:9326:559 with SMTP id d9443c01a7336-2129f240de5mr179893455ad.29.1732523492519; Mon, 25 Nov 2024 00:31:32 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:66a3:d18f:544f:227a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2129dbfece2sm59090025ad.157.2024.11.25.00.31.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Nov 2024 00:31:32 -0800 (PST) From: Sung-Chi Li Date: Mon, 25 Nov 2024 16:31:17 +0800 Subject: [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241125-extend_power_limit-v2-2-c3266a86e9b1@chromium.org> References: <20241125-extend_power_limit-v2-0-c3266a86e9b1@chromium.org> In-Reply-To: <20241125-extend_power_limit-v2-0-c3266a86e9b1@chromium.org> To: Benson Leung , Guenter Roeck , Sebastian Reichel , Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: chrome-platform@lists.linux.dev, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Sung-Chi Li X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1732523485; l=1439; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=ktJPK16HT87IqUYNk6xW4DxEM+thEREPtW8kVjrlImY=; b=FpMKgfM5p9IzbPe7guqbp4Vjag/aqYKH4JxQjr2hWl48PN/wyJux8YdE/6fm8+fY0+2OLaW7c ohiglj075PQC4cCEHOJcL5SCqRAmB2aBhq+byXp6ug7DAA8KeGSGApQ X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= A charger chip is connect to the ChromeOS Embedded Controller (EC). When external power input into the system, current would go through the charger chip, generating heat in the system. The EC supports limiting the input current, thus reducing the generated heat. As a result, EC is a simulated passive cooling device. We cannot reuse the existing charge managing mechanism in the power framework due to: - The power framework requires the charger to expose its thermal status, which is not a supported functionality on EC. - We need to use different thermal sensors to run thermal control, rather than using thermal sensor on the charger. Add the property '#cooling-cells' bindings, such that thermal framework can recognize cros_ec as a valid thermal cooling device. Signed-off-by: Sung-Chi Li --- Documentation/devicetree/bindings/mfd/google,cros-ec.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml index aac8819bd00b..2b6f098057af 100644 --- a/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml +++ b/Documentation/devicetree/bindings/mfd/google,cros-ec.yaml @@ -96,6 +96,9 @@ properties: '#gpio-cells': const: 2 + '#cooling-cells': + const: 2 + gpio-controller: true typec: