* [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation
@ 2017-08-17 11:17 Florian Eckert
2017-08-17 11:17 ` [PATCH 2/2] hwmon: (adcxx) Add device tree support Florian Eckert
2017-08-17 17:10 ` [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation Guenter Roeck
0 siblings, 2 replies; 4+ messages in thread
From: Florian Eckert @ 2017-08-17 11:17 UTC (permalink / raw)
To: jdelvare, linux, linux-hwmon
Document the devicetree bindings for the adcxx.
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
---
Documentation/devicetree/bindings/hwmon/adcxx.txt | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
create mode 100644 Documentation/devicetree/bindings/hwmon/adcxx.txt
diff --git a/Documentation/devicetree/bindings/hwmon/adcxx.txt b/Documentation/devicetree/bindings/hwmon/adcxx.txt
new file mode 100644
index 000000000000..7b2a31b95723
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/adcxx.txt
@@ -0,0 +1,23 @@
+adcxx properties
+
+Required properties:
+- compatible: Must be one of the following:
+ - "national,adcxx1s" for adcxx1s
+ - "national,adcxx2s" for adcxx2s
+ - "national,adcxx4s" for adcxx4s
+ - "national,adcxx8s" for adcxx8s
+- reg: SPI address for chip
+
+Optional properties:
+
+- reference-voltage-millivolt
+ Reference voltage in millivolt (mV)
+
+Example:
+
+adc@6 {
+ compatible = "national,adcxx2s";
+ reg = <6 0>;
+ spi-max-frequency = <1000000>;
+ reference-voltage-millivolt = <3247>; /* 3.247 V */
+};
--
2.11.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] hwmon: (adcxx) Add device tree support
2017-08-17 11:17 [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation Florian Eckert
@ 2017-08-17 11:17 ` Florian Eckert
2017-08-17 17:17 ` Guenter Roeck
2017-08-17 17:10 ` [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation Guenter Roeck
1 sibling, 1 reply; 4+ messages in thread
From: Florian Eckert @ 2017-08-17 11:17 UTC (permalink / raw)
To: jdelvare, linux, linux-hwmon
Allow the driver to work with device tree support.
Set reference voltage of ADC with device tree property.
If not set use default 3300mV.
- reference-voltage-millivolt
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
---
drivers/hwmon/adcxx.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 51 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
index 69e0bb97e597..34e241ea86a0 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,15 @@
#include <linux/mutex.h>
#include <linux/mod_devicetable.h>
#include <linux/spi/spi.h>
+#include <linux/of_device.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 +166,58 @@ 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;
+ 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;
+ if (spi->dev.of_node)
+ of_property_read_u32(spi->dev.of_node,
+ "reference-voltage-millivolt",
+ &adc->reference);
+ if (!adc->reference)
+ adc->reference = 3300;
+ dev_info(&spi->dev, "Reference voltage set to %dmV\n", adc->reference);
+
adc->channels = channels;
mutex_init(&adc->lock);
@@ -223,10 +267,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 +278,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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation
2017-08-17 11:17 [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation Florian Eckert
2017-08-17 11:17 ` [PATCH 2/2] hwmon: (adcxx) Add device tree support Florian Eckert
@ 2017-08-17 17:10 ` Guenter Roeck
1 sibling, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-08-17 17:10 UTC (permalink / raw)
To: Florian Eckert; +Cc: jdelvare, linux-hwmon
On Thu, Aug 17, 2017 at 01:17:04PM +0200, Florian Eckert wrote:
> Document the devicetree bindings for the adcxx.
>
> Signed-off-by: Florian Eckert <fe@dev.tdt.de>
> ---
> Documentation/devicetree/bindings/hwmon/adcxx.txt | 23 +++++++++++++++++++++++
> 1 file changed, 23 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/hwmon/adcxx.txt
>
> diff --git a/Documentation/devicetree/bindings/hwmon/adcxx.txt b/Documentation/devicetree/bindings/hwmon/adcxx.txt
> new file mode 100644
> index 000000000000..7b2a31b95723
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/adcxx.txt
> @@ -0,0 +1,23 @@
> +adcxx properties
> +
> +Required properties:
> +- compatible: Must be one of the following:
> + - "national,adcxx1s" for adcxx1s
> + - "national,adcxx2s" for adcxx2s
> + - "national,adcxx4s" for adcxx4s
> + - "national,adcxx8s" for adcxx8s
> +- reg: SPI address for chip
> +
> +Optional properties:
> +
> +- reference-voltage-millivolt
> + Reference voltage in millivolt (mV)
> +
This should use a regulator binding instead. See ads7828.txt for an example.
> +Example:
> +
> +adc@6 {
> + compatible = "national,adcxx2s";
> + reg = <6 0>;
> + spi-max-frequency = <1000000>;
> + reference-voltage-millivolt = <3247>; /* 3.247 V */
> +};
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] hwmon: (adcxx) Add device tree support
2017-08-17 11:17 ` [PATCH 2/2] hwmon: (adcxx) Add device tree support Florian Eckert
@ 2017-08-17 17:17 ` Guenter Roeck
0 siblings, 0 replies; 4+ messages in thread
From: Guenter Roeck @ 2017-08-17 17:17 UTC (permalink / raw)
To: Florian Eckert; +Cc: jdelvare, linux-hwmon
On Thu, Aug 17, 2017 at 01:17:05PM +0200, Florian Eckert wrote:
> Allow the driver to work with device tree support.
> Set reference voltage of ADC with device tree property.
> If not set use default 3300mV.
>
> - reference-voltage-millivolt
>
> Signed-off-by: Florian Eckert <fe@dev.tdt.de>
> ---
> drivers/hwmon/adcxx.c | 57 +++++++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 51 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hwmon/adcxx.c b/drivers/hwmon/adcxx.c
> index 69e0bb97e597..34e241ea86a0 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,15 @@
> #include <linux/mutex.h>
> #include <linux/mod_devicetable.h>
> #include <linux/spi/spi.h>
> +#include <linux/of_device.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 +166,58 @@ 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;
> + 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;
> + if (spi->dev.of_node)
> + of_property_read_u32(spi->dev.of_node,
> + "reference-voltage-millivolt",
> + &adc->reference);
struct regulator *reg;
...
reg = devm_regulator_get_optional(dev, "vref");
if (!IS_ERR(reg)) {
vref_uv = regulator_get_voltage(reg);
adc->reference = DIV_ROUND_CLOSEST(vref_uv, 1000);
}
> + if (!adc->reference)
> + adc->reference = 3300;
> + dev_info(&spi->dev, "Reference voltage set to %dmV\n", adc->reference);
> +
I really dislike such noise. If you think you need it, please make it
dev_dbg().
> adc->channels = channels;
> mutex_init(&adc->lock);
>
> @@ -223,10 +267,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 +278,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
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-hwmon" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-08-17 17:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-17 11:17 [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation Florian Eckert
2017-08-17 11:17 ` [PATCH 2/2] hwmon: (adcxx) Add device tree support Florian Eckert
2017-08-17 17:17 ` Guenter Roeck
2017-08-17 17:10 ` [PATCH 1/2] hwmon: (adcxx) add devictree bindings documentation Guenter Roeck
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).