You've already forked linux-t2-patches
mirror of
https://github.com/t2linux/linux-t2-patches.git
synced 2026-04-30 13:52:11 -07:00
97ccd7d579
echo 50 | sudo tee /sys/bus/acpi/drivers/applesmc/APP0001:00/battery_charge_limit etc etc. Max is 100, min is 0
97 lines
2.7 KiB
Diff
97 lines
2.7 KiB
Diff
From 38786c7979c8ece013b5b7d5cb07dc2aa40198be Mon Sep 17 00:00:00 2001
|
|
From: Orlando Chamberlain <orlandoch.dev@gmail.com>
|
|
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
|
|
|