From: Andreas Kemnade <andreas@kemnade.info>
To: sre@kernel.org, andreas@kemnade.info, mazziesaccount@gmail.com,
linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] power: supply: bd71828: sysfs for auto input current limitation
Date: Mon, 4 May 2026 18:40:17 +0200 [thread overview]
Message-ID: <20260504164017.467679-1-andreas@kemnade.info> (raw)
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
next reply other threads:[~2026-05-04 16:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-04 16:40 Andreas Kemnade [this message]
2026-05-05 5:22 ` [PATCH] power: supply: bd71828: sysfs for auto input current limitation Matti Vaittinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260504164017.467679-1-andreas@kemnade.info \
--to=andreas@kemnade.info \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mazziesaccount@gmail.com \
--cc=sre@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox