* [PATCH v2 0/2] Extend the cros_usbpd-charger to make it a passive thermal cooling device
@ 2024-11-25 8:31 Sung-Chi Li
2024-11-25 8:31 ` [PATCH v2 1/2] power: supply: cros_usbpd-charger: extend as a thermal of " Sung-Chi Li
2024-11-25 8:31 ` [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells Sung-Chi Li
0 siblings, 2 replies; 4+ messages in thread
From: Sung-Chi Li @ 2024-11-25 8:31 UTC (permalink / raw)
To: Benson Leung, Guenter Roeck, Sebastian Reichel, Lee Jones,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: chrome-platform, linux-pm, linux-kernel, devicetree, Sung-Chi Li
The cros_usbpd-charger already supports limiting input current, so we
can easily extend it as a passive thermal cooling device. By limiting
the current flow into the system, we can reduce the heat generated by
related chips, which results in reserving more thermal budget for the
system.
This series will only works on making it a OF style thermal cooling
device, so related code are guarded by #ifdef macros.
---
Changes in v2:
- Revise commit message for including the reason of change for this
series.
- Remove uses of `ifdef CONFIG_THERMAL_OF`, and use
`IS_ENABLED(CONFIG_THERMAL_OF)` when needed.
- Does not failing the driver probing if failed to register the usbpd
device as a cooling device.
---
Sung-Chi Li (2):
power: supply: cros_usbpd-charger: extend as a thermal of cooling device
dt-bindings: mfd: cros-ec: add properties for thermal cooling cells
.../devicetree/bindings/mfd/google,cros-ec.yaml | 3 +
drivers/power/supply/cros_usbpd-charger.c | 84 +++++++++++++++++++++-
2 files changed, 85 insertions(+), 2 deletions(-)
---
base-commit: ac24e26aa08fe026804f678599f805eb13374a5d
change-id: 20241122-extend_power_limit-62c2d9aabfa7
Best regards,
--
Sung-Chi Li <lschyi@chromium.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] power: supply: cros_usbpd-charger: extend as a thermal of cooling device
2024-11-25 8:31 [PATCH v2 0/2] Extend the cros_usbpd-charger to make it a passive thermal cooling device Sung-Chi Li
@ 2024-11-25 8:31 ` Sung-Chi Li
2024-11-25 8:31 ` [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells Sung-Chi Li
1 sibling, 0 replies; 4+ messages in thread
From: Sung-Chi Li @ 2024-11-25 8:31 UTC (permalink / raw)
To: Benson Leung, Guenter Roeck, Sebastian Reichel, Lee Jones,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: chrome-platform, linux-pm, linux-kernel, devicetree, Sung-Chi Li
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 <lschyi@chromium.org>
---
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 <linux/platform_device.h>
#include <linux/power_supply.h>
#include <linux/slab.h>
+#include <linux/thermal.h>
#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:
--
2.47.0.371.ga323438b13-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells
2024-11-25 8:31 [PATCH v2 0/2] Extend the cros_usbpd-charger to make it a passive thermal cooling device Sung-Chi Li
2024-11-25 8:31 ` [PATCH v2 1/2] power: supply: cros_usbpd-charger: extend as a thermal of " Sung-Chi Li
@ 2024-11-25 8:31 ` Sung-Chi Li
2024-11-25 8:45 ` Krzysztof Kozlowski
1 sibling, 1 reply; 4+ messages in thread
From: Sung-Chi Li @ 2024-11-25 8:31 UTC (permalink / raw)
To: Benson Leung, Guenter Roeck, Sebastian Reichel, Lee Jones,
Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: chrome-platform, linux-pm, linux-kernel, devicetree, Sung-Chi Li
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 <lschyi@chromium.org>
---
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:
--
2.47.0.371.ga323438b13-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells
2024-11-25 8:31 ` [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells Sung-Chi Li
@ 2024-11-25 8:45 ` Krzysztof Kozlowski
0 siblings, 0 replies; 4+ messages in thread
From: Krzysztof Kozlowski @ 2024-11-25 8:45 UTC (permalink / raw)
To: Sung-Chi Li, Benson Leung, Guenter Roeck, Sebastian Reichel,
Lee Jones, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: chrome-platform, linux-pm, linux-kernel, devicetree
On 25/11/2024 09:31, Sung-Chi Li wrote:
> 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.
EC is not part of the SoC, therefore this is not a cooling device. It is
not thermal sensor either, but this you pushed before I could object.
>
> 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.
Fix power framework then.
> - We need to use different thermal sensors to run thermal control,
> rather than using thermal sensor on the charger.
Nothing stops you from using thermal sensors or thermal control. Still,
this is not part of SoC, this is not thermal zone and this is not a SoC
cooling device.
NAK
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-11-25 8:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-25 8:31 [PATCH v2 0/2] Extend the cros_usbpd-charger to make it a passive thermal cooling device Sung-Chi Li
2024-11-25 8:31 ` [PATCH v2 1/2] power: supply: cros_usbpd-charger: extend as a thermal of " Sung-Chi Li
2024-11-25 8:31 ` [PATCH v2 2/2] dt-bindings: mfd: cros-ec: add properties for thermal cooling cells Sung-Chi Li
2024-11-25 8:45 ` Krzysztof Kozlowski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox