-
Notifications
You must be signed in to change notification settings - Fork 12
/
3009-applesmc-battery-charge-limiter.patch
96 lines (87 loc) · 2.69 KB
/
3009-applesmc-battery-charge-limiter.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
From add0db8b96c3f90b844586a3b9ea32041bae4b2c Mon Sep 17 00:00:00 2001
From: Orlando Chamberlain <[email protected]>
Date: Mon, 30 Jan 2023 18:42:21 +1100
Subject: [PATCH 9/9] 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 5f67d7362..698f44794 100644
--- a/drivers/hwmon/applesmc.c
+++ b/drivers/hwmon/applesmc.c
@@ -1477,6 +1477,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)
{
@@ -1611,6 +1640,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 */
/*
@@ -1829,10 +1863,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)
@@ -1868,6 +1905,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:
@@ -1882,6 +1921,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.45.2