From patchwork Fri Nov 22 03:47:21 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: 13882747 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (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 A4DBA15B149 for ; Fri, 22 Nov 2024 03:47:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732247259; cv=none; b=qjk4A3BBELZGO/gCx6LFUyYexCsJQNnqVx1u0RPg0x/0L3+61s4I3imkqaEqA+OD6FT8j9wl5bch5NLg2yCJI/aqpUs1NDn1b7p/c+/ShRkRbKVFND9X1gMUGMURa/8pn7TaZCxeSHYnXwmG7TVPp355N3k9Z7C96HpyKkLnksw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732247259; c=relaxed/simple; bh=0NAcyLrHHDhRn82WN0izrFPbVZrkw97X7FSs9cPtqXA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S8hqfPOdTBmIwwPOa7aHXxHFg8eFqFTF+lP4iKLUtpZE+IxOoJTTF6hwO9FVQ0q+g3uqAkWuuq2u/FwxR9VtcKLG5m3jXUKvFi9R7d/H9kt0+uRkYjyIHQlVDPd6ZPhU3h6Nepw1cZOuVhebVaeFoQctowvW/R1L4+z26lEVlZc= 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=ldm3BVuK; arc=none smtp.client-ip=209.85.167.177 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="ldm3BVuK" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3e786167712so1108889b6e.3 for ; Thu, 21 Nov 2024 19:47:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732247257; x=1732852057; 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=d5LY5RXpPtd9Rkf3ibKsfLHvQo7hHTlxcwyEUNtbdks=; b=ldm3BVuKcKz0tbeR1U7DEVCZrbFmFBHgKAmqtzW+UCdmnBol8RdEwkh/8NV4nDEEQM ZqUpOFo8IvzsH5McV57SOr6QKc/7wwNGRK1U9MwwPzEuN9eZSFj83i92mPXxyuaUJKcE kmtkvUATTjqZptD6gAuiYEKcb1YL76nTeRfcQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732247257; x=1732852057; 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=d5LY5RXpPtd9Rkf3ibKsfLHvQo7hHTlxcwyEUNtbdks=; b=OGHeeMSr4BO1zdXMR2U7qHNHfda1XJCAtsTBBi5BKTQ6MFT+GeByYuzf5HLuBfikQ3 GYz5mRW8w2EIWC/7IuR7aKv53zOhvbJom9XjXiVcM+0ew6eFHFaF2oJQTkTM2As2Zh59 fmJPoVrZtncXpwIytliOh8WRokLdWFVqoqPyAKkJNCOw8ls5O68H538nQE5FdADFJfYR JlkIdnkeBeR8JDLezOAcZhVw+WWnyVU1crSVyw3X7spv0i3Ee8mn6zPEuGNdV2XZGQ2a FNelx3hTKV2b7HHIfq3hRv4uyofjWLW1D0B0BQVtxtf+dGB55kVxgy7FWrp/GNYJEWho snLQ== X-Forwarded-Encrypted: i=1; AJvYcCVT3CwOh5AphviN8qR7kmkb76GNqK9d4YaSi8vOKdZu/Xvzc2m4x3yHHyCAqkRGZR0YMea73PcIqw==@vger.kernel.org X-Gm-Message-State: AOJu0Yz4w+PbJFbuaHa5j48Aql90wXTXz2/LxYKjM/1BkAYsYl01xbGb 5ZMaX3ODn6QpU/4+VWzBsESKizVLI0a6AyUA34oO6vGs1f/MA4mQiVZ5t5R3Kw== X-Gm-Gg: ASbGncvG+mtUAaeNRSDDmpY6e7hjndjoMgLzy+sh0u2fv/8LT4n/YO/4u1rFT6+9Jfm csN9WhNWYbgzgTPIzGgSXubBE0dY2a9+R95w3SzY4uqJr4VpHYQG4sMyPZ4iVaIAiY+AhOtbWPf z2et4gLVwtn9Vx0Dzrxhjnf2E6LBUx+xAmh49hWe58Glq0OWGfzzB8qAfU4erfyqo4GAkNn7oxH XIDzmrgYYxqX3jab1sJu42oTDkzZUGB8K2A0fWUgjqwwj6v7H9CNXR/qV9Jsbps0XyLXa0= X-Google-Smtp-Source: AGHT+IHryHek2XRVYS94YH2r4x03SqrwmBMFwfNHTimqb3KpUJr+MKVD5jT0i5y4nF7OMpy8M9x55A== X-Received: by 2002:a05:6808:2205:b0:3e7:60b1:1f49 with SMTP id 5614622812f47-3e9157a1595mr1527992b6e.4.1732247256800; Thu, 21 Nov 2024 19:47:36 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:533e:26bf:b63:973a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724de554b11sm550174b3a.133.2024.11.21.19.47.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 19:47:36 -0800 (PST) From: Sung-Chi Li Date: Fri, 22 Nov 2024 11:47:21 +0800 Subject: [PATCH 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: <20241122-extend_power_limit-v1-1-a3ecd87afa76@chromium.org> References: <20241122-extend_power_limit-v1-0-a3ecd87afa76@chromium.org> In-Reply-To: <20241122-extend_power_limit-v1-0-a3ecd87afa76@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=1732247251; l=5457; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=0NAcyLrHHDhRn82WN0izrFPbVZrkw97X7FSs9cPtqXA=; b=5RorBRojsc5DW6lyjii3KCfqlhvUkvwWPGbGmaVKEbwGjzsUje+27mQCbi8dCQMkBIUiTJa7T qCyOSvMN0GDAcumVzpM//xx+QPNcqSTpAAZ42bBWRr5S0yxWN39oTIi X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= 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. We can extend this driver to make it as a passive thermal cooling device by limiting the input current. As such, this commit implements the required cooling methods and OF style registration. Signed-off-by: Sung-Chi Li --- drivers/power/supply/cros_usbpd-charger.c | 98 +++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 5 deletions(-) diff --git a/drivers/power/supply/cros_usbpd-charger.c b/drivers/power/supply/cros_usbpd-charger.c index 47d3f58aa15c..a0451630cdd7 100644 --- a/drivers/power/supply/cros_usbpd-charger.c +++ b/drivers/power/supply/cros_usbpd-charger.c @@ -13,6 +13,9 @@ #include #include #include +#ifdef CONFIG_THERMAL_OF +#include +#endif /* CONFIG_THERMAL_OF */ #define CHARGER_USBPD_DIR_NAME "CROS_USBPD_CHARGER%d" #define CHARGER_DEDICATED_DIR_NAME "CROS_DEDICATED_CHARGER" @@ -22,6 +25,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 +80,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 +465,20 @@ 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 - dev_info(dev, - "External Current Limit set to %dmA for all ports\n", - input_current_limit); + 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 +538,66 @@ static void cros_usbpd_charger_unregister_notifier(void *data) cros_usbpd_unregister_notify(&charger->notifier); } +#ifdef CONFIG_THERMAL_OF +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 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, +}; +#endif /* CONFIG_THERMAL_OF */ + static int cros_usbpd_charger_probe(struct platform_device *pd) { struct cros_ec_dev *ec_dev = dev_get_drvdata(pd->dev.parent); @@ -534,6 +607,9 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) struct charger_data *charger; struct power_supply *psy; struct port_data *port; +#ifdef CONFIG_THERMAL_OF + struct thermal_cooling_device *cdev; +#endif /* CONFIG_THERMAL_OF */ int ret = -EINVAL; int i; @@ -674,6 +750,18 @@ static int cros_usbpd_charger_probe(struct platform_device *pd) goto fail; } +#ifdef 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_err(dev, + "Failing register thermal cooling device (err:%pe)\n", + cdev); + goto fail; + } +#endif /* CONFIG_THERMAL_OF */ + return 0; fail: From patchwork Fri Nov 22 03:47:22 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: 13882748 Received: from mail-oi1-f170.google.com (mail-oi1-f170.google.com [209.85.167.170]) (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 12E3A1632D5 for ; Fri, 22 Nov 2024 03:47:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732247261; cv=none; b=BJmp2THZfJALc6JfrGt94oPUXOsrBvlmfSrUbYhRH/jOUgmHXE1VQNjuzSCtXcrX6P7y5pcNtmFRq/uC/0OFcnr0BoDYIvHZ208LPQbRveDIARxKVUdVPi018uFyOi7BRy6UEnWLb9UjvS/cxGH3h7ADJLquo9r9rGIy0M3wxrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732247261; c=relaxed/simple; bh=ecrPWNCROGbCGBvflsd6cHirBTqgXm1cERWiLr23QUw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=juxcLa28IJZTfVqJgkHE7XSsd91nyB0M0CowG0dyp+URsW4BqALfbmJR2kVzxas7lpx9GLV0MCxJB0wef65jtZAMUKbQg2D1SZZMSVaIXdMhhYzdsQLE7Jy5pC/irkjv53LsBK8Ymhf6H3WLkoEQTWD/cttYqqmsk1nDjK1+vKg= 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=IdmHw1LD; arc=none smtp.client-ip=209.85.167.170 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="IdmHw1LD" Received: by mail-oi1-f170.google.com with SMTP id 5614622812f47-3e60f6ea262so821217b6e.1 for ; Thu, 21 Nov 2024 19:47:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1732247259; x=1732852059; 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=knk5bhF5K5WlFtwhF1HiZTyghnwunglBtYROl19Amnc=; b=IdmHw1LDH0scOAYCc1DRfAjBzUnhQlq5yZlBpW0FW+m+U2XxbcY5RTVsLwuLSMTJsp ZxbrZc0ap8+3Baj+SrZ1s+e/tuGVGW+oySEslKmUmruAG0YL0l+h4X4hlEet7DbyHqTm 7PEzg0S7k/9MGkarD6uiOVTr0IP8Gfas56EHQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732247259; x=1732852059; 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=knk5bhF5K5WlFtwhF1HiZTyghnwunglBtYROl19Amnc=; b=tIMdbO8ac7BY1Dm40Q5pRieWuQMQfQUIlecnlmZxM7DvXAmu9bJGyVe/N2CKU/2vjJ YRWbrjwytQwgC+oeB21jw0oWoOKo5MppWBFpf7Lmgv+5LUDsO2O5U182rOiMw9CryJ9o wr18N7buqSyewD+0mfs03TMscsOj2C0QynQfHj0YRJQPWmQZ9MrBzvHA+j6vU519c7q/ /Sik9ZDaUtz3LWhFtGyQthAEGKPkBaH+YnS7j5PawZ7DSp8+dvPZ5LQHBiQZJMw6CHIf VDl8ycN+hN3ujtkr5O0dHwxFKOrT8MSjeTekgvu/O1z1qlZ09ti8bCDQ/6+NRxgkrpHO hsKQ== X-Forwarded-Encrypted: i=1; AJvYcCX2Lar3Ks/SPM1K6z4szV4QirY/WOUZ+XntfxXf9l3z3CJ3l9i4pM7a4yhMQB6ojMVh/xtLtBnShQ==@vger.kernel.org X-Gm-Message-State: AOJu0YzhtzAVlZf/GjXm7IzbDVkME8cVef0On5YY3fsTmQv3wYhxo2Ri mcGJmULMq46O1bWhgn9d7yU8iORHonYyiWHSOpC8FKcXPr+BhanbFTj8iShfUCLQgKs88fy4QfE = X-Gm-Gg: ASbGnct0CyEghm9xaX3GOO3dSKTc/t6G8el0YIWwTam+29SUD+Afr8DB0d0n7OAPFoS cR6JhdmEVy4HBa3PXr0NlNcFPyEywiublSBrGvPrAHEEgpaXbwZwcqBqS85+YuGlDi7vZ56JIao j7x/OZNIXiQlwBRkpB5nneu39ZxYMrY4qMaqFMP1UI620Y8TDrcShgHvDlxgBsiirZ2SMRm8u29 UvVn1SZcsfgbBCEvmxPhCEqSM0DDueglWYhdaFA7oHzbYj22ge17aJ8vwX40qoLEcs6ODQ= X-Google-Smtp-Source: AGHT+IG9TmutnyL2idfCzGrxIgPrFSPj4hupzoYH5zYY4fJEibqFwqT2kUZnaPO1+nOzBHXjr0fcdQ== X-Received: by 2002:a05:6808:3186:b0:3e6:10d1:ecb6 with SMTP id 5614622812f47-3e915afc2f0mr2042657b6e.28.1732247259232; Thu, 21 Nov 2024 19:47:39 -0800 (PST) Received: from lschyi-p920.tpe.corp.google.com ([2401:fa00:1:10:533e:26bf:b63:973a]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-724de554b11sm550174b3a.133.2024.11.21.19.47.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 19:47:38 -0800 (PST) From: Sung-Chi Li Date: Fri, 22 Nov 2024 11:47:22 +0800 Subject: [PATCH 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: <20241122-extend_power_limit-v1-2-a3ecd87afa76@chromium.org> References: <20241122-extend_power_limit-v1-0-a3ecd87afa76@chromium.org> In-Reply-To: <20241122-extend_power_limit-v1-0-a3ecd87afa76@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=1732247251; l=873; i=lschyi@chromium.org; s=20241113; h=from:subject:message-id; bh=ecrPWNCROGbCGBvflsd6cHirBTqgXm1cERWiLr23QUw=; b=+Ar7fFL4Es6YoP98iJ8z+ts7PPhZxkPpxs/twgJcXy9F+hxWQE8UDw3qtSLkVEsv8smzvWQH5 xC5M1yQiGp1B2ApDAeFU70wlo7L2T10cnh4QYIQ6sueAac/a24ZnXMn X-Developer-Key: i=lschyi@chromium.org; a=ed25519; pk=nE3PJlqSK35GdWfB4oVLOwi4njfaUZRhM66HGos9P6o= The cros_ec supports limiting the input current to act as a passive thermal cooling device. 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: