From: Matt Ranostay <mranostay@gmail.com>
To: "Andrew F . Davis" <afd@ti.com>, Sebastian Reichel <sre@kernel.org>
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
Matt Ranostay <matt@ranostay.consulting>
Subject: [PATCH 2/2] power: bq27xxx_battery: allow kernel poll_interval parameter runtime update
Date: Fri, 16 Sep 2016 20:42:55 -0700 [thread overview]
Message-ID: <1474083775-30185-3-git-send-email-matt@ranostay.consulting> (raw)
In-Reply-To: <1474083775-30185-1-git-send-email-matt@ranostay.consulting>
Fix issue with poll_interval being not updated till the previous
interval expired.
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
drivers/power/supply/bq27xxx_battery.c | 38 +++++++++++++++++++++++++++++++++-
include/linux/power/bq27xxx_battery.h | 1 +
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c
index 955424e10ae2..96fd3eec98da 100644
--- a/drivers/power/supply/bq27xxx_battery.c
+++ b/drivers/power/supply/bq27xxx_battery.c
@@ -39,6 +39,7 @@
#include <linux/device.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/param.h>
#include <linux/jiffies.h>
#include <linux/workqueue.h>
@@ -390,8 +391,35 @@ static struct {
BQ27XXX_PROP(BQ27421, bq27421_battery_props),
};
+static DEFINE_MUTEX(param_lock);
+static LIST_HEAD(bq27xxx_battery_devices);
+
+static int poll_interval_param_set(const char *val, const struct kernel_param *kp)
+{
+ struct bq27xxx_device_info *di;
+ int ret;
+
+ ret = param_set_uint(val, kp);
+ if (ret < 0)
+ return ret;
+
+ mutex_lock(¶m_lock);
+ list_for_each_entry(di, &bq27xxx_battery_devices, list) {
+ cancel_delayed_work_sync(&di->work);
+ schedule_delayed_work(&di->work, 0);
+ }
+ mutex_unlock(¶m_lock);
+
+ return ret;
+}
+
+static const struct kernel_param_ops param_ops_poll_interval = {
+ .get = param_get_ushort,
+ .set = poll_interval_param_set,
+};
+
static unsigned int poll_interval = 360;
-module_param(poll_interval, uint, 0644);
+module_param_cb(poll_interval, ¶m_ops_poll_interval, &poll_interval, 0644);
MODULE_PARM_DESC(poll_interval,
"battery poll interval in seconds - 0 disables polling");
@@ -1011,6 +1039,10 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di)
bq27xxx_battery_update(di);
+ mutex_lock(¶m_lock);
+ list_add(&di->list, &bq27xxx_battery_devices);
+ mutex_unlock(¶m_lock);
+
return 0;
err_out:
@@ -1036,6 +1068,10 @@ void bq27xxx_battery_teardown(struct bq27xxx_device_info *di)
power_supply_unregister(di->bat);
+ mutex_lock(¶m_lock);
+ list_del(&di->list);
+ mutex_unlock(¶m_lock);
+
mutex_destroy(&di->lock);
}
EXPORT_SYMBOL_GPL(bq27xxx_battery_teardown);
diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h
index b50c0492629d..e30deb046156 100644
--- a/include/linux/power/bq27xxx_battery.h
+++ b/include/linux/power/bq27xxx_battery.h
@@ -58,6 +58,7 @@ struct bq27xxx_device_info {
unsigned long last_update;
struct delayed_work work;
struct power_supply *bat;
+ struct list_head list;
struct mutex lock;
u8 *regs;
};
--
2.7.4
next prev parent reply other threads:[~2016-09-17 3:42 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-17 3:42 [PATCH 0/2] power: bq27xxx_battery: add configurable poll_interval Matt Ranostay
2016-09-17 3:42 ` [PATCH 1/2] power: bq27xxx_battery: add configurable poll_interval by sysfs Matt Ranostay
2016-09-19 19:46 ` Sebastian Reichel
2016-09-20 3:22 ` Matt Ranostay
2016-10-07 18:49 ` Pavel Machek
2016-10-24 3:08 ` Matt Ranostay
2016-10-24 8:23 ` Pavel Machek
2016-10-24 19:51 ` Pavel Machek
2016-10-24 19:55 ` Matt Ranostay
2016-09-17 3:42 ` Matt Ranostay [this message]
2016-09-19 19:49 ` [PATCH 2/2] power: bq27xxx_battery: allow kernel poll_interval parameter runtime update Sebastian Reichel
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=1474083775-30185-3-git-send-email-matt@ranostay.consulting \
--to=mranostay@gmail.com \
--cc=afd@ti.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=matt@ranostay.consulting \
--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;
as well as URLs for NNTP newsgroup(s).