Skip to content

Commit 9fe445f

Browse files
Redecorating1Naim
authored andcommitted
applesmc-t2: battery charge limiter
1 parent 79630ed commit 9fe445f

1 file changed

Lines changed: 41 additions & 1 deletion

File tree

drivers/hwmon/applesmc-t2.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,35 @@ static void applesmc_brightness_set(struct led_classdev *led_cdev,
14771477
dev_dbg(led_cdev->dev, "work was already on the queue.\n");
14781478
}
14791479

1480+
static ssize_t applesmc_BCLM_store(struct device *dev,
1481+
struct device_attribute *attr, char *sysfsbuf, size_t count)
1482+
{
1483+
struct applesmc_device *smc = dev_get_drvdata(dev);
1484+
u8 val;
1485+
1486+
if (kstrtou8(sysfsbuf, 10, &val) < 0)
1487+
return -EINVAL;
1488+
1489+
if (val < 0 || val > 100)
1490+
return -EINVAL;
1491+
1492+
if (applesmc_write_key(smc, "BCLM", &val, 1))
1493+
return -ENODEV;
1494+
return count;
1495+
}
1496+
1497+
static ssize_t applesmc_BCLM_show(struct device *dev,
1498+
struct device_attribute *attr, char *sysfsbuf)
1499+
{
1500+
struct applesmc_device *smc = dev_get_drvdata(dev);
1501+
u8 val;
1502+
1503+
if (applesmc_read_key(smc, "BCLM", &val, 1))
1504+
return -ENODEV;
1505+
1506+
return sysfs_emit(sysfsbuf, "%d\n", val);
1507+
}
1508+
14801509
static ssize_t applesmc_key_count_show(struct device *dev,
14811510
struct device_attribute *attr, char *sysfsbuf)
14821511
{
@@ -1611,6 +1640,11 @@ static struct applesmc_node_group temp_group[] = {
16111640
{ }
16121641
};
16131642

1643+
static struct applesmc_node_group BCLM_group[] = {
1644+
{ "battery_charge_limit", applesmc_BCLM_show, applesmc_BCLM_store },
1645+
{ }
1646+
};
1647+
16141648
/* Module stuff */
16151649

16161650
/*
@@ -1829,10 +1863,13 @@ static int applesmc_create_modules(struct applesmc_device *smc)
18291863
ret = applesmc_create_nodes(smc, info_group, 1);
18301864
if (ret)
18311865
goto out;
1866+
ret = applesmc_create_nodes(smc, BCLM_group, 1);
1867+
if (ret)
1868+
goto out_info;
18321869

18331870
ret = applesmc_create_nodes(smc, fan_group, smc->reg.fan_count);
18341871
if (ret)
1835-
goto out_info;
1872+
goto out_bclm;
18361873

18371874
ret = applesmc_create_nodes(smc, temp_group, smc->reg.index_count);
18381875
if (ret)
@@ -1868,6 +1905,8 @@ static int applesmc_create_modules(struct applesmc_device *smc)
18681905
applesmc_destroy_nodes(smc, temp_group);
18691906
out_fans:
18701907
applesmc_destroy_nodes(smc, fan_group);
1908+
out_bclm:
1909+
applesmc_destroy_nodes(smc, BCLM_group);
18711910
out_info:
18721911
applesmc_destroy_nodes(smc, info_group);
18731912
out:
@@ -1882,6 +1921,7 @@ static void applesmc_destroy_modules(struct applesmc_device *smc)
18821921
applesmc_release_accelerometer(smc);
18831922
applesmc_destroy_nodes(smc, temp_group);
18841923
applesmc_destroy_nodes(smc, fan_group);
1924+
applesmc_destroy_nodes(smc, BCLM_group);
18851925
applesmc_destroy_nodes(smc, info_group);
18861926
}
18871927

0 commit comments

Comments
 (0)