From: Daniel Matyas <daniel.matyas@analog.com>
Cc: Daniel Matyas <daniel.matyas@analog.com>,
Jean Delvare <jdelvare@suse.com>,
Guenter Roeck <linux@roeck-us.net>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Corbet <corbet@lwn.net>, <linux-hwmon@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-doc@vger.kernel.org>
Subject: [PATCH v4 5/7] hwmon: max31827: Add support for max31828 and max31829
Date: Tue, 19 Sep 2023 12:34:53 +0300 [thread overview]
Message-ID: <20230919093456.10592-5-daniel.matyas@analog.com> (raw)
In-Reply-To: <20230919093456.10592-1-daniel.matyas@analog.com>
When adi,flt-q and/or adi,alrm-pol are not mentioned,
the default configuration is loaded.
Signed-off-by: Daniel Matyas <daniel.matyas@analog.com>
---
v3 -> v4: No change.
v3: Added patch.
drivers/hwmon/max31827.c | 68 +++++++++++++++++++++++++++++++++-------
1 file changed, 57 insertions(+), 11 deletions(-)
diff --git a/drivers/hwmon/max31827.c b/drivers/hwmon/max31827.c
index 2bddca60666d..d4127440ee32 100644
--- a/drivers/hwmon/max31827.c
+++ b/drivers/hwmon/max31827.c
@@ -46,12 +46,17 @@
#define MAX31827_12_BIT_CNV_TIME 140
#define MAX31827_ALRM_POL_LOW 0x0
+#define MAX31827_ALRM_POL_HIGH 0x1
+
#define MAX31827_FLT_Q_1 0x0
+#define MAX31827_FLT_Q_4 0x2
#define MAX31827_16_BIT_TO_M_DGR(x) (sign_extend32(x, 15) * 1000 / 16)
#define MAX31827_M_DGR_TO_16_BIT(x) (((x) << 4) / 1000)
#define MAX31827_DEVICE_ENABLE(x) ((x) ? 0xA : 0x0)
+enum chips { max31827, max31828, max31829 };
+
enum max31827_cnv {
MAX31827_CNV_1_DIV_64_HZ = 1,
MAX31827_CNV_1_DIV_32_HZ,
@@ -383,12 +388,21 @@ static int max31827_write(struct device *dev, enum hwmon_sensor_types type,
return -EOPNOTSUPP;
}
+static const struct i2c_device_id max31827_i2c_ids[] = {
+ { "max31827", max31827 },
+ { "max31828", max31828 },
+ { "max31829", max31829 },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, max31827_i2c_ids);
+
static int max31827_init_client(struct max31827_state *st,
struct fwnode_handle *fwnode)
{
bool prop;
u32 data, lsb_idx;
unsigned int res = 0;
+ enum chips type;
int ret;
st->enable = true;
@@ -402,6 +416,11 @@ static int max31827_init_client(struct max31827_state *st,
prop = fwnode_property_read_bool(fwnode, "adi,timeout-enable");
res |= FIELD_PREP(MAX31827_CONFIGURATION_TIMEOUT_MASK, !prop);
+ if (st->client->dev.of_node)
+ type = (enum chips)of_device_get_match_data(&st->client->dev);
+ else
+ type = i2c_match_id(max31827_i2c_ids, st->client)->driver_data;
+
if (fwnode_property_present(fwnode, "adi,alarm-pol")) {
ret = fwnode_property_read_u32(fwnode, "adi,alarm-pol", &data);
if (ret)
@@ -409,8 +428,19 @@ static int max31827_init_client(struct max31827_state *st,
res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK, !!data);
} else {
- res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
- MAX31827_ALRM_POL_LOW);
+ switch (type) {
+ case max31827:
+ case max31828:
+ res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
+ MAX31827_ALRM_POL_LOW);
+ break;
+ case max31829:
+ res |= FIELD_PREP(MAX31827_CONFIGURATION_ALRM_POL_MASK,
+ MAX31827_ALRM_POL_HIGH);
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
}
if (fwnode_property_present(fwnode, "adi,fault-q")) {
@@ -429,8 +459,19 @@ static int max31827_init_client(struct max31827_state *st,
res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK, lsb_idx);
} else {
- res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
- MAX31827_FLT_Q_1);
+ switch (type) {
+ case max31827:
+ res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
+ MAX31827_FLT_Q_1);
+ break;
+ case max31828:
+ case max31829:
+ res |= FIELD_PREP(MAX31827_CONFIGURATION_FLT_Q_MASK,
+ MAX31827_FLT_Q_4);
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
}
return regmap_write(st->regmap, MAX31827_CONFIGURATION_REG, res);
@@ -492,14 +533,19 @@ static int max31827_probe(struct i2c_client *client)
return PTR_ERR_OR_ZERO(hwmon_dev);
}
-static const struct i2c_device_id max31827_i2c_ids[] = {
- { "max31827", 0 },
- { }
-};
-MODULE_DEVICE_TABLE(i2c, max31827_i2c_ids);
-
static const struct of_device_id max31827_of_match[] = {
- { .compatible = "adi,max31827" },
+ {
+ .compatible = "adi,max31827",
+ .data = (void *)max31827
+ },
+ {
+ .compatible = "adi,max31828",
+ .data = (void *)max31828
+ },
+ {
+ .compatible = "adi,max31829",
+ .data = (void *)max31829
+ },
{ }
};
MODULE_DEVICE_TABLE(of, max31827_of_match);
--
2.34.1
next prev parent reply other threads:[~2023-09-19 9:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-19 9:34 [PATCH v4 1/7] hwmon: max31827: Make code cleaner Daniel Matyas
2023-09-19 9:34 ` [PATCH v4 2/7] hwmon: max31827: Modify conversion wait time Daniel Matyas
2023-10-25 21:44 ` Guenter Roeck
2023-09-19 9:34 ` [PATCH v4 3/7] dt-bindings: hwmon: Add possible new properties to max31827 bindings Daniel Matyas
2023-09-19 11:00 ` Conor Dooley
2023-10-25 21:44 ` Guenter Roeck
2023-09-19 9:34 ` [PATCH v4 4/7] hwmon: max31827: Handle new properties from the devicetree Daniel Matyas
2023-10-25 22:01 ` Guenter Roeck
2023-10-26 0:45 ` Guenter Roeck
2023-09-19 9:34 ` Daniel Matyas [this message]
2023-09-19 9:34 ` [PATCH v4 6/7] hwmon: max31827: Update bits with shutdown_write() Daniel Matyas
2023-09-19 9:34 ` [PATCH v4 7/7] hwmon: max31827: Add custom attribute for resolution Daniel Matyas
2023-10-25 21:43 ` [PATCH v4 1/7] hwmon: max31827: Make code cleaner 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=20230919093456.10592-5-daniel.matyas@analog.com \
--to=daniel.matyas@analog.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=robh+dt@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).