From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-hwmon@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <linux@roeck-us.net>, <jdelvare@suse.com>,
<ardeleanalex@gmail.com>, <Mark.Thoren@analog.com>,
Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH 1/3] hwmon: (ltc2945): wrap regmap into an ltc2945_state struct
Date: Fri, 6 Nov 2020 12:18:23 +0200 [thread overview]
Message-ID: <20201106101825.30960-1-alexandru.ardelean@analog.com> (raw)
The intent is to add pass the value of the sense resistor in the driver.
This change wraps a 'struct ltc2945_state', and moves the regmap reference
on that object.
Then we can add the value of the sense resistor, or other information that
would be useful for the driver.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
drivers/hwmon/ltc2945.c | 30 +++++++++++++++++++++++++-----
1 file changed, 25 insertions(+), 5 deletions(-)
diff --git a/drivers/hwmon/ltc2945.c b/drivers/hwmon/ltc2945.c
index ba9c868a8641..1cea710df668 100644
--- a/drivers/hwmon/ltc2945.c
+++ b/drivers/hwmon/ltc2945.c
@@ -58,6 +58,14 @@
#define CONTROL_MULT_SELECT (1 << 0)
#define CONTROL_TEST_MODE (1 << 4)
+/**
+ * struct ltc2945_state - driver instance specific data
+ * @regmap regmap object to access device registers
+ */
+struct ltc2945_state {
+ struct regmap *regmap;
+};
+
static inline bool is_power_reg(u8 reg)
{
return reg < LTC2945_SENSE_H;
@@ -66,7 +74,8 @@ static inline bool is_power_reg(u8 reg)
/* Return the value from the given register in uW, mV, or mA */
static long long ltc2945_reg_to_val(struct device *dev, u8 reg)
{
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct ltc2945_state *st = dev_get_drvdata(dev);
+ struct regmap *regmap = st->regmap;
unsigned int control;
u8 buf[3];
long long val;
@@ -148,7 +157,8 @@ static long long ltc2945_reg_to_val(struct device *dev, u8 reg)
static int ltc2945_val_to_reg(struct device *dev, u8 reg,
unsigned long val)
{
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct ltc2945_state *st = dev_get_drvdata(dev);
+ struct regmap *regmap = st->regmap;
unsigned int control;
int ret;
@@ -234,7 +244,8 @@ static ssize_t ltc2945_value_store(struct device *dev,
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct ltc2945_state *st = dev_get_drvdata(dev);
+ struct regmap *regmap = st->regmap;
u8 reg = attr->index;
unsigned long val;
u8 regbuf[3];
@@ -269,7 +280,8 @@ static ssize_t ltc2945_history_store(struct device *dev,
const char *buf, size_t count)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct ltc2945_state *st = dev_get_drvdata(dev);
+ struct regmap *regmap = st->regmap;
u8 reg = attr->index;
int num_regs = is_power_reg(reg) ? 3 : 2;
u8 buf_min[3] = { 0xff, 0xff, 0xff };
@@ -321,7 +333,8 @@ static ssize_t ltc2945_bool_show(struct device *dev,
struct device_attribute *da, char *buf)
{
struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
- struct regmap *regmap = dev_get_drvdata(dev);
+ struct ltc2945_state *st = dev_get_drvdata(dev);
+ struct regmap *regmap = st->regmap;
unsigned int fault;
int ret;
@@ -448,15 +461,22 @@ static const struct regmap_config ltc2945_regmap_config = {
static int ltc2945_probe(struct i2c_client *client)
{
struct device *dev = &client->dev;
+ struct ltc2945_state *st;
struct device *hwmon_dev;
struct regmap *regmap;
+ st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
+ if (!st)
+ return -ENOMEM;
+
regmap = devm_regmap_init_i2c(client, <c2945_regmap_config);
if (IS_ERR(regmap)) {
dev_err(dev, "failed to allocate register map\n");
return PTR_ERR(regmap);
}
+ st->regmap = regmap;
+
/* Clear faults */
regmap_write(regmap, LTC2945_FAULT, 0x00);
--
2.27.0
next reply other threads:[~2020-11-06 10:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-06 10:18 Alexandru Ardelean [this message]
2020-11-06 10:18 ` [PATCH 2/3] docs: hwmon: (ltc2945): change type of val to ULL in ltc2945_val_to_reg() Alexandru Ardelean
2020-11-06 13:14 ` Guenter Roeck
2020-11-09 6:38 ` Alexandru Ardelean
2020-11-06 10:18 ` [PATCH 3/3] hwmon: (ltc2945): add support for sense resistor Alexandru Ardelean
2020-11-06 13:17 ` Guenter Roeck
2020-11-09 6:41 ` Alexandru Ardelean
2020-11-09 14:42 ` Guenter Roeck
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=20201106101825.30960-1-alexandru.ardelean@analog.com \
--to=alexandru.ardelean@analog.com \
--cc=Mark.Thoren@analog.com \
--cc=ardeleanalex@gmail.com \
--cc=jdelvare@suse.com \
--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 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).