From: Florian Eckert <fe@dev.tdt.de>
To: jdelvare@suse.com, linux@roeck-us.net, robh+dt@kernel.org,
mark.rutland@arm.com
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, Florian Eckert <fe@dev.tdt.de>
Subject: [PATCH v3 2/2] hwmon: (adcxx) Add device tree support
Date: Thu, 15 Nov 2018 14:50:13 +0100 [thread overview]
Message-ID: <20181115135013.30723-3-fe@dev.tdt.de> (raw)
In-Reply-To: <20181115135013.30723-1-fe@dev.tdt.de>
Add device tree supoort for this driver.
Set reference voltage of ADC with the regulator device tree property.
If not set use default 3300000uV (3.3V).
- vref-supply
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
---
drivers/hwmon/adcxx.c | 62 +++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 55 insertions(+), 7 deletions(-)
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index 69e0bb97e597..6f3e7d65b5b8 100644
--- a/drivers/hwmon/adcxx.c
+++ b/drivers/hwmon/adcxx.c
@@ -4,6 +4,7 @@
* The adcxx4s is an AD converter family from National Semiconductor (NS).
*
* Copyright (c) 2008 Marc Pignat <marc.pignat@hevs.ch>
+ * Copyright (c) 2017 Florian Eckert <fe@dev.tdt.de>
*
* The adcxx4s communicates with a host processor via an SPI/Microwire Bus
* interface. This driver supports the whole family of devices with name
@@ -46,9 +47,16 @@
#include <linux/mutex.h>
#include <linux/mod_devicetable.h>
#include <linux/spi/spi.h>
+#include <linux/of_device.h>
+#include <linux/regulator/consumer.h>
#define DRVNAME "adcxx"
+#define ADCXX1S 1
+#define ADCXX2S 2
+#define ADCXX4S 4
+#define ADCXX8S 8
+
struct adcxx {
struct device *hwmon_dev;
struct mutex lock;
@@ -159,21 +167,60 @@ static struct sensor_device_attribute ad_input[] = {
SENSOR_ATTR(in7_input, S_IRUGO, adcxx_read, NULL, 7),
};
+#ifdef CONFIG_OF
+static const struct of_device_id adcxx_of_ids[] = {
+ {
+ .compatible = "national,adcxx1s",
+ .data = (void *) ADCXX1S,
+ },
+ {
+ .compatible = "national,adcxx2s",
+ .data = (void *) ADCXX2S,
+ },
+ {
+ .compatible = "national,adcxx4s",
+ .data = (void *) ADCXX4S,
+ },
+ {
+ .compatible = "national,adcxx8s",
+ . data = (void *) ADCXX8S,
+ },
+ {},
+};
+MODULE_DEVICE_TABLE(of, adcxx_of_ids);
+#endif
+
/*----------------------------------------------------------------------*/
static int adcxx_probe(struct spi_device *spi)
{
- int channels = spi_get_device_id(spi)->driver_data;
+ const struct of_device_id *match;
+ struct regulator *vref;
+ int vref_uv;
+ int channels;
struct adcxx *adc;
int status;
int i;
+ match = of_match_device(adcxx_of_ids, &spi->dev);
+ if (match)
+ channels = (int)(uintptr_t)match->data;
+ else
+ channels = spi_get_device_id(spi)->driver_data;
+
adc = devm_kzalloc(&spi->dev, sizeof(*adc), GFP_KERNEL);
if (!adc)
return -ENOMEM;
- /* set a default value for the reference */
- adc->reference = 3300;
+ vref = devm_regulator_get_optional(&spi->dev, "vref");
+ if (!IS_ERR(vref)) {
+ vref_uv = regulator_get_voltage(vref);
+ adc->reference = DIV_ROUND_CLOSEST(vref_uv, 1000);
+ }
+ if (!adc->reference)
+ adc->reference = 3300;
+ dev_dbg(&spi->dev, "Reference voltage set to %dmV\n", adc->reference);
+
adc->channels = channels;
mutex_init(&adc->lock);
@@ -223,10 +270,10 @@ static int adcxx_remove(struct spi_device *spi)
}
static const struct spi_device_id adcxx_ids[] = {
- { "adcxx1s", 1 },
- { "adcxx2s", 2 },
- { "adcxx4s", 4 },
- { "adcxx8s", 8 },
+ { "adcxx1s", ADCXX1S },
+ { "adcxx2s", ADCXX2S },
+ { "adcxx4s", ADCXX4S },
+ { "adcxx8s", ADCXX8S },
{ },
};
MODULE_DEVICE_TABLE(spi, adcxx_ids);
@@ -234,6 +281,7 @@ MODULE_DEVICE_TABLE(spi, adcxx_ids);
static struct spi_driver adcxx_driver = {
.driver = {
.name = "adcxx",
+ .of_match_table = of_match_ptr(adcxx_of_ids),
},
.id_table = adcxx_ids,
.probe = adcxx_probe,
--
2.11.0
prev parent reply other threads:[~2018-11-15 13:50 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-15 13:50 [PATCH v3 0/2] hwmon: Add device tree support for adcxx Florian Eckert
2018-11-15 13:50 ` [PATCH v3 1/2] hwmon: (adcxx) add devictree bindings documentation Florian Eckert
2018-11-17 14:40 ` Rob Herring
2018-11-19 1:25 ` Guenter Roeck
2018-11-20 7:16 ` Florian Eckert
2018-11-15 13:50 ` Florian Eckert [this message]
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=20181115135013.30723-3-fe@dev.tdt.de \
--to=fe@dev.tdt.de \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--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).