* [PATCH] power: supply: bd71828: sysfs for auto input current limitation
@ 2026-05-04 16:40 Andreas Kemnade
2026-05-05 5:22 ` Matti Vaittinen
0 siblings, 1 reply; 2+ messages in thread
From: Andreas Kemnade @ 2026-05-04 16:40 UTC (permalink / raw)
To: sre, andreas, mazziesaccount, linux-pm, linux-kernel
Add the possibility to disable the auto adjustment for input current
limitation via sysfs because it gives strange results under certain
circumstances e.g. when powering the device with solar panels
resulting in no input power usage at all.
Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
---
.../ABI/testing/sysfs-class-power-bd71828 | 12 ++++
drivers/power/supply/bd71828-power.c | 69 ++++++++++++++++++-
2 files changed, 80 insertions(+), 1 deletion(-)
create mode 100644 Documentation/ABI/testing/sysfs-class-power-bd71828
diff --git a/Documentation/ABI/testing/sysfs-class-power-bd71828 b/Documentation/ABI/testing/sysfs-class-power-bd71828
new file mode 100644
index 000000000000..2d451e1c8336
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-power-bd71828
@@ -0,0 +1,12 @@
+What: /sys/class/power_supply/bd71828_ac/auto_dcin_limit
+Description:
+ Enable/Disable automatic management of input current limit
+ (ILIM_DCIN_EN bit).
+
+ Possible values are:
+
+ ============ ===========================================
+ 1 automatic adjustment of input current limit
+ 0 no adjustment of input current limit. This
+ helps for more unusual power sources like
+ solar modules.
diff --git a/drivers/power/supply/bd71828-power.c b/drivers/power/supply/bd71828-power.c
index 5e78faa0a4aa..8c251c2a15e2 100644
--- a/drivers/power/supply/bd71828-power.c
+++ b/drivers/power/supply/bd71828-power.c
@@ -12,6 +12,7 @@
#include <linux/property.h>
#include <linux/power_supply.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
/* common defines */
#define BD7182x_MASK_VBAT_U 0x1f
@@ -25,6 +26,7 @@
#define BD71815_MASK_CONF_XSTB BIT(1)
#define BD7182x_MASK_BAT_STAT 0x3f
#define BD7182x_MASK_ILIM 0x3f
+#define BD71828_MASK_ILIM_DCIN_EN BIT(6)
#define BD7182x_MASK_DCIN_STAT 0x07
#define BD7182x_MASK_WDT_AUTO 0x40
@@ -1099,10 +1101,75 @@ static int bd7182x_get_rsens(struct bd71828_power *pwr)
return 0;
}
+static ssize_t auto_dcin_limit_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct bd71828_power *pwr = dev_get_drvdata(dev->parent);
+ int ret;
+ unsigned int v;
+
+ ret = regmap_read(pwr->regmap, pwr->regs->dcin_set, &v);
+ if (ret)
+ return ret;
+
+ return sysfs_emit(buf, "%d\n", !!(v & BD71828_MASK_ILIM_DCIN_EN));
+}
+
+static ssize_t auto_dcin_limit_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t len)
+{
+ struct bd71828_power *pwr = dev_get_drvdata(dev->parent);
+ int ret;
+ bool v;
+
+ ret = kstrtobool(buf, &v);
+ if (ret < 0)
+ return ret;
+
+ ret = regmap_update_bits(pwr->regmap, BD71828_REG_DCIN_SET,
+ BD71828_MASK_ILIM_DCIN_EN,
+ v ? BD71828_MASK_ILIM_DCIN_EN : 0);
+ if (ret < 0)
+ return ret;
+
+ return len;
+}
+
+static DEVICE_ATTR_RW(auto_dcin_limit);
+
+static struct attribute *bd71828_ac_sysfs_attrs[] = {
+ &dev_attr_auto_dcin_limit.attr,
+ NULL,
+};
+
+static bool bd71828_ac_sysfs_group_visible(struct kobject *kobj)
+{
+ struct device *dev = kobj_to_dev(kobj);
+ struct bd71828_power *pwr = dev_get_drvdata(dev->parent);
+
+ return !!pwr->regs->dcin_set;
+}
+
+DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(bd71828_ac_sysfs);
+
+static const struct attribute_group bd71828_ac_sysfs_group = {
+ .attrs = bd71828_ac_sysfs_attrs,
+ .is_visible = SYSFS_GROUP_VISIBLE(bd71828_ac_sysfs)
+};
+
+static const struct attribute_group *bd71828_ac_sysfs_groups[] = {
+ &bd71828_ac_sysfs_group,
+ NULL
+};
+
static int bd71828_power_probe(struct platform_device *pdev)
{
struct bd71828_power *pwr;
- struct power_supply_config ac_cfg = {};
+ struct power_supply_config ac_cfg = {
+ .attr_grp = bd71828_ac_sysfs_groups,
+ };
struct power_supply_config bat_cfg = {};
int ret;
--
2.47.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] power: supply: bd71828: sysfs for auto input current limitation
2026-05-04 16:40 [PATCH] power: supply: bd71828: sysfs for auto input current limitation Andreas Kemnade
@ 2026-05-05 5:22 ` Matti Vaittinen
0 siblings, 0 replies; 2+ messages in thread
From: Matti Vaittinen @ 2026-05-05 5:22 UTC (permalink / raw)
To: Andreas Kemnade, sre, linux-pm, linux-kernel
Thanks Andreas!
On 04/05/2026 19:40, Andreas Kemnade wrote:
> Add the possibility to disable the auto adjustment for input current
> limitation via sysfs because it gives strange results under certain
> circumstances e.g. when powering the device with solar panels
> resulting in no input power usage at all.
>
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
> ---
> .../ABI/testing/sysfs-class-power-bd71828 | 12 ++++
> drivers/power/supply/bd71828-power.c | 69 ++++++++++++++++++-
> 2 files changed, 80 insertions(+), 1 deletion(-)
> create mode 100644 Documentation/ABI/testing/sysfs-class-power-bd71828
// snip
> +static ssize_t auto_dcin_limit_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t len)
> +{
> + struct bd71828_power *pwr = dev_get_drvdata(dev->parent);
> + int ret;
> + bool v;
> +
> + ret = kstrtobool(buf, &v);
> + if (ret < 0)
> + return ret;
> +
> + ret = regmap_update_bits(pwr->regmap, BD71828_REG_DCIN_SET,
> + BD71828_MASK_ILIM_DCIN_EN,
> + v ? BD71828_MASK_ILIM_DCIN_EN : 0);
'nit'. I am not a big fan of the ternary. I would consider using an
if-else or the regmap_assign_bits(). Not worth re-spinning though.
> +static bool bd71828_ac_sysfs_group_visible(struct kobject *kobj)
> +{
> + struct device *dev = kobj_to_dev(kobj);
> + struct bd71828_power *pwr = dev_get_drvdata(dev->parent);
> +
> + return !!pwr->regs->dcin_set;
> +}
> +
> +DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE(bd71828_ac_sysfs);
Ah. I didn't know DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE() existed. Thanks
for teaching me a thing again :)
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-05-05 5:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04 16:40 [PATCH] power: supply: bd71828: sysfs for auto input current limitation Andreas Kemnade
2026-05-05 5:22 ` Matti Vaittinen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox