From 97ccd7d57983475ab18f0503dd7c1df089782864 Mon Sep 17 00:00:00 2001 From: Orlando Chamberlain Date: Mon, 30 Jan 2023 18:56:27 +1100 Subject: [PATCH] battery charge limiter echo 50 | sudo tee /sys/bus/acpi/drivers/applesmc/APP0001:00/battery_charge_limit etc etc. Max is 100, min is 0 --- 3009-applesmc-battery-charge-limiter.patch | 96 ++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 3009-applesmc-battery-charge-limiter.patch diff --git a/3009-applesmc-battery-charge-limiter.patch b/3009-applesmc-battery-charge-limiter.patch new file mode 100644 index 0000000..281c50f --- /dev/null +++ b/3009-applesmc-battery-charge-limiter.patch @@ -0,0 +1,96 @@ +From 38786c7979c8ece013b5b7d5cb07dc2aa40198be Mon Sep 17 00:00:00 2001 +From: Orlando Chamberlain +Date: Mon, 30 Jan 2023 18:42:21 +1100 +Subject: [PATCH 1/1] applesmc: battery charge limiter + +--- + drivers/hwmon/applesmc.c | 42 +++++++++++++++++++++++++++++++++++++++- + 1 file changed, 41 insertions(+), 1 deletion(-) + +diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c +index 12be9269a314..bc1eec74cfef 100644 +--- a/drivers/hwmon/applesmc.c ++++ b/drivers/hwmon/applesmc.c +@@ -1478,6 +1478,35 @@ static void applesmc_brightness_set(struct led_classdev *led_cdev, + dev_dbg(led_cdev->dev, "work was already on the queue.\n"); + } + ++static ssize_t applesmc_BCLM_store(struct device *dev, ++ struct device_attribute *attr, char *sysfsbuf, size_t count) ++{ ++ struct applesmc_device *smc = dev_get_drvdata(dev); ++ u8 val; ++ ++ if (kstrtou8(sysfsbuf, 10, &val) < 0) ++ return -EINVAL; ++ ++ if (val < 0 || val > 100) ++ return -EINVAL; ++ ++ if (applesmc_write_key(smc, "BCLM", &val, 1)) ++ return -ENODEV; ++ return count; ++} ++ ++static ssize_t applesmc_BCLM_show(struct device *dev, ++ struct device_attribute *attr, char *sysfsbuf) ++{ ++ struct applesmc_device *smc = dev_get_drvdata(dev); ++ u8 val; ++ ++ if (applesmc_read_key(smc, "BCLM", &val, 1)) ++ return -ENODEV; ++ ++ return sysfs_emit(sysfsbuf, "%d\n", val); ++} ++ + static ssize_t applesmc_key_count_show(struct device *dev, + struct device_attribute *attr, char *sysfsbuf) + { +@@ -1612,6 +1641,11 @@ static struct applesmc_node_group temp_group[] = { + { } + }; + ++static struct applesmc_node_group BCLM_group[] = { ++ { "battery_charge_limit", applesmc_BCLM_show, applesmc_BCLM_store }, ++ { } ++}; ++ + /* Module stuff */ + + /* +@@ -1830,10 +1864,13 @@ static int applesmc_create_modules(struct applesmc_device *smc) + ret = applesmc_create_nodes(smc, info_group, 1); + if (ret) + goto out; ++ ret = applesmc_create_nodes(smc, BCLM_group, 1); ++ if (ret) ++ goto out_info; + + ret = applesmc_create_nodes(smc, fan_group, smc->reg.fan_count); + if (ret) +- goto out_info; ++ goto out_bclm; + + ret = applesmc_create_nodes(smc, temp_group, smc->reg.index_count); + if (ret) +@@ -1869,6 +1906,8 @@ static int applesmc_create_modules(struct applesmc_device *smc) + applesmc_destroy_nodes(smc, temp_group); + out_fans: + applesmc_destroy_nodes(smc, fan_group); ++out_bclm: ++ applesmc_destroy_nodes(smc, BCLM_group); + out_info: + applesmc_destroy_nodes(smc, info_group); + out: +@@ -1883,6 +1922,7 @@ static void applesmc_destroy_modules(struct applesmc_device *smc) + applesmc_release_accelerometer(smc); + applesmc_destroy_nodes(smc, temp_group); + applesmc_destroy_nodes(smc, fan_group); ++ applesmc_destroy_nodes(smc, BCLM_group); + applesmc_destroy_nodes(smc, info_group); + } + +-- +2.39.1 +