From: Constantine Shulyupin <const@MakeLinux.com>
To: Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
lm-sensors@lm-sensors.org (open list:HARDWARE MONITORING),
linux-kernel@vger.kernel.org (open list)
Cc: Constantine Shulyupin <const@MakeLinux.com>
Subject: [PATCH v2] hwmon: (nct7802) hwmon: (nct7802) Add device tree support
Date: Mon, 14 Sep 2015 00:11:30 +0300 [thread overview]
Message-ID: <1442178690-31107-1-git-send-email-const@MakeLinux.com> (raw)
Introduced properties sensorX-type with string values
"disabled", "thermal diode", "thermistor" and "voltage".
Signed-off-by: Constantine Shulyupin <const@MakeLinux.com>
---
Changed in v2:
- removed tempX_type
- introduced nuvoton,sensorX-type with string values
Changed in v1:
- Introduced tempX_type with numerical values
---
drivers/hwmon/nct7802.c | 43 ++++++++++++++++++++++++++++++++++++++++---
1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c
index 3ce33d2..edd9063 100644
--- a/drivers/hwmon/nct7802.c
+++ b/drivers/hwmon/nct7802.c
@@ -1077,9 +1077,11 @@ static const struct regmap_config nct7802_regmap_config = {
.volatile_reg = nct7802_regmap_is_volatile,
};
-static int nct7802_init_chip(struct nct7802_data *data)
+static int nct7802_init_chip(struct device_node *node,
+ struct nct7802_data *data)
{
int err;
+ int i;
/* Enable ADC */
err = regmap_update_bits(data->regmap, REG_START, 0x01, 0x01);
@@ -1092,7 +1094,34 @@ static int nct7802_init_chip(struct nct7802_data *data)
return err;
/* Enable Vcore and VCC voltage monitoring */
- return regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
+ err = regmap_update_bits(data->regmap, REG_VMON_ENABLE, 0x03, 0x03);
+ if (err)
+ return err;
+
+ for (i = 0; i < 3; i++) {
+ char propname[30];
+ const char *val;
+ int senor_type;
+
+ snprintf(propname, sizeof(propname), "nuvoton,sensor%d-type",
+ i + 1);
+ err = of_property_read_string(node, propname, &val);
+ if (err < 0)
+ break;
+ if (!strcmp(val, "disabled"))
+ senor_type = 0;
+ else if (!strcmp(val, "thermal diode"))
+ senor_type = 1;
+ else if (!strcmp(val, "thermistor"))
+ senor_type = 2;
+ else if (!strcmp(val, "voltage"))
+ senor_type = 3;
+ else
+ return -EINVAL;
+ err = regmap_update_bits(data->regmap, REG_MODE,
+ 3 << 2 * i, senor_type << 2 * i);
+ }
+ return 0;
}
static int nct7802_probe(struct i2c_client *client,
@@ -1113,7 +1142,7 @@ static int nct7802_probe(struct i2c_client *client,
mutex_init(&data->access_lock);
- ret = nct7802_init_chip(data);
+ ret = nct7802_init_chip(client->dev.of_node, data);
if (ret < 0)
return ret;
@@ -1133,10 +1162,18 @@ static const struct i2c_device_id nct7802_idtable[] = {
};
MODULE_DEVICE_TABLE(i2c, nct7802_idtable);
+#ifdef CONFIG_OF
+static const struct of_device_id nct7802_dt_match[] = {
+ { .compatible = "nuvoton,nct7802" },
+ { },
+};
+#endif
+
static struct i2c_driver nct7802_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = DRVNAME,
+ .of_match_table = of_match_ptr(nct7802_dt_match),
},
.detect = nct7802_detect,
.probe = nct7802_probe,
--
1.9.1
reply other threads:[~2015-09-13 21:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=1442178690-31107-1-git-send-email-const@MakeLinux.com \
--to=const@makelinux.com \
--cc=jdelvare@suse.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=lm-sensors@lm-sensors.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 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.