From: Nicolin Chen <nicoleotsuka@gmail.com>
To: jdelvare@suse.com, linux@roeck-us.net
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
corbet@lwn.net, linux-doc@vger.kernel.org
Subject: [PATCH 2/2] hwmon: (ina3221) Add operating mode support
Date: Tue, 9 Oct 2018 21:33:10 -0700 [thread overview]
Message-ID: <20181010043310.30873-3-nicoleotsuka@gmail.com> (raw)
In-Reply-To: <20181010043310.30873-1-nicoleotsuka@gmail.com>
The hwmon core now has a new optional mode interface. So this patch
just implements this mode support so that user space can check and
configure via sysfs node its operating modes: power-down, one-shot,
and continuous modes.
Signed-off-by: Nicolin Chen <nicoleotsuka@gmail.com>
---
drivers/hwmon/ina3221.c | 64 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+)
diff --git a/drivers/hwmon/ina3221.c b/drivers/hwmon/ina3221.c
index d61688f04594..5218fd85506d 100644
--- a/drivers/hwmon/ina3221.c
+++ b/drivers/hwmon/ina3221.c
@@ -77,6 +77,28 @@ enum ina3221_channels {
INA3221_NUM_CHANNELS
};
+enum ina3221_modes {
+ INA3221_MODE_POWERDOWN,
+ INA3221_MODE_ONESHOT,
+ INA3221_MODE_CONTINUOUS,
+ INA3221_NUM_MODES,
+};
+
+static const char *ina3221_mode_names[INA3221_NUM_MODES] = {
+ [INA3221_MODE_POWERDOWN] = "power-down",
+ [INA3221_MODE_ONESHOT] = "one-shot",
+ [INA3221_MODE_CONTINUOUS] = "continuous",
+};
+
+static const u16 ina3221_mode_val[] = {
+ [INA3221_MODE_POWERDOWN] = INA3221_CONFIG_MODE_POWERDOWN,
+ [INA3221_MODE_ONESHOT] = INA3221_CONFIG_MODE_SHUNT |
+ INA3221_CONFIG_MODE_BUS,
+ [INA3221_MODE_CONTINUOUS] = INA3221_CONFIG_MODE_CONTINUOUS |
+ INA3221_CONFIG_MODE_SHUNT |
+ INA3221_CONFIG_MODE_BUS,
+};
+
/**
* struct ina3221_input - channel input source specific information
* @label: label of channel input source
@@ -386,9 +408,51 @@ static const struct hwmon_ops ina3221_hwmon_ops = {
.write = ina3221_write,
};
+static int ina3221_mode_get_index(struct device *dev, unsigned int *index)
+{
+ struct ina3221_data *ina = dev_get_drvdata(dev);
+ u16 mode = ina->reg_config & INA3221_CONFIG_MODE_MASK;
+
+ if (mode == INA3221_CONFIG_MODE_POWERDOWN)
+ *index = INA3221_MODE_POWERDOWN;
+ if (mode & INA3221_CONFIG_MODE_CONTINUOUS)
+ *index = INA3221_MODE_CONTINUOUS;
+ else
+ *index = INA3221_MODE_ONESHOT;
+
+ return 0;
+}
+
+static int ina3221_mode_set_index(struct device *dev, unsigned int index)
+{
+ struct ina3221_data *ina = dev_get_drvdata(dev);
+ int ret;
+
+ ret = regmap_update_bits(ina->regmap, INA3221_CONFIG,
+ INA3221_CONFIG_MODE_MASK,
+ ina3221_mode_val[index]);
+ if (ret)
+ return ret;
+
+ /* Cache the latest config register value */
+ ret = regmap_read(ina->regmap, INA3221_CONFIG, &ina->reg_config);
+ if (ret)
+ return ret;
+
+ return 0;
+}
+
+static const struct hwmon_mode ina3221_hwmon_mode = {
+ .names = ina3221_mode_names,
+ .list_size = INA3221_NUM_MODES,
+ .get_index = ina3221_mode_get_index,
+ .set_index = ina3221_mode_set_index,
+};
+
static const struct hwmon_chip_info ina3221_chip_info = {
.ops = &ina3221_hwmon_ops,
.info = ina3221_info,
+ .mode = &ina3221_hwmon_mode,
};
/* Extra attribute groups */
--
2.17.1
next prev parent reply other threads:[~2018-10-10 4:33 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-10 4:33 [PATCH 0/2] hwmon: Add operating mode support for core and ina3221 Nicolin Chen
2018-10-10 4:33 ` [PATCH 1/2] hwmon: (core) Add hwmon_mode structure and mode sysfs node Nicolin Chen
2018-10-10 13:08 ` Guenter Roeck
2018-10-10 21:13 ` Nicolin Chen
2018-10-10 21:31 ` Guenter Roeck
2018-10-10 4:33 ` Nicolin Chen [this message]
2018-10-10 13:22 ` [PATCH 2/2] hwmon: (ina3221) Add operating mode support Guenter Roeck
2018-10-10 23:09 ` Nicolin Chen
2018-10-10 23:43 ` Guenter Roeck
2018-10-11 0:24 ` Nicolin Chen
2018-10-11 19:31 ` Guenter Roeck
2018-10-11 19:36 ` Nicolin Chen
2018-10-11 19:50 ` Guenter Roeck
2018-10-11 19:53 ` Nicolin Chen
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=20181010043310.30873-3-nicoleotsuka@gmail.com \
--to=nicoleotsuka@gmail.com \
--cc=corbet@lwn.net \
--cc=jdelvare@suse.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.