diff mbox

hwmon: (adm1031) Add device tree support

Message ID 1459241443-28392-1-git-send-email-joel@jms.id.au (mailing list archive)
State Rejected
Headers show

Commit Message

Joel Stanley March 29, 2016, 8:50 a.m. UTC
This adds a of_device_id table so we can probe the driver using the
device tree.

Signed-off-by: Joel Stanley <joel@jms.id.au>
---
 Documentation/devicetree/bindings/hwmon/adm1276.txt | 21 +++++++++++++++++++++
 drivers/hwmon/pmbus/adm1275.c                       | 15 +++++++++++++++
 2 files changed, 36 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/hwmon/adm1276.txt

Comments

Guenter Roeck March 29, 2016, 9:14 a.m. UTC | #1
On 03/29/2016 01:50 AM, Joel Stanley wrote:
> This adds a of_device_id table so we can probe the driver using the
> device tree.
>
The subject line does not match the driver being modified; it suggests adm1031
while in reality the adm1275 driver is being modified.

> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
>   Documentation/devicetree/bindings/hwmon/adm1276.txt | 21 +++++++++++++++++++++

The bindings file name doesn't match the driver file name.

Besides, this should already work, through trivial bindings.
Is there a reason to believe that it does not already work ?

Guenter

>   drivers/hwmon/pmbus/adm1275.c                       | 15 +++++++++++++++
>   2 files changed, 36 insertions(+)
>   create mode 100644 Documentation/devicetree/bindings/hwmon/adm1276.txt
>
> diff --git a/Documentation/devicetree/bindings/hwmon/adm1276.txt b/Documentation/devicetree/bindings/hwmon/adm1276.txt
> new file mode 100644
> index 000000000000..45eb51867c1b
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/hwmon/adm1276.txt
> @@ -0,0 +1,21 @@
> +* Analog Devices ADM1275 and compatabile power monitors
> +
> +Required node properties:
> +
> + - compatible: manufacturer and chip name, one of
> +
> +    "adi,adm1075"
> +    "adi,adm1275"
> +    "adi,adm1276"
> +    "adi,adm1278"
> +    "adi,adm1293"
> +    "adi,adm1294"
> +
> +- reg: I2C bus address of the device
> +
> +Example adm1275 node:
> +
> +power-sensor {
> +	compatible = "adi,adm1278";
> +	reg = <0x4c>;
> +}
> diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
> index 3baa4f4a8c5e..1476a127dbdb 100644
> --- a/drivers/hwmon/pmbus/adm1275.c
> +++ b/drivers/hwmon/pmbus/adm1275.c
> @@ -22,6 +22,7 @@
>   #include <linux/slab.h>
>   #include <linux/i2c.h>
>   #include <linux/bitops.h>
> +#include <linux/of.h>
>   #include "pmbus.h"
>
>   enum chips { adm1075, adm1275, adm1276, adm1278, adm1293, adm1294 };
> @@ -344,6 +345,19 @@ static const struct i2c_device_id adm1275_id[] = {
>   };
>   MODULE_DEVICE_TABLE(i2c, adm1275_id);
>
> +#ifdef CONFIG_OF
> +static const struct of_device_id adm1275_of_match[] = {
> +	{ .compatible = "adi,adm1075" },
> +	{ .compatible = "adi,adm1275" },
> +	{ .compatible = "adi,adm1276" },
> +	{ .compatible = "adi,adm1278" },
> +	{ .compatible = "adi,adm1293" },
> +	{ .compatible = "adi,adm1294" },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(of, adm1275_of_match);
> +#endif
> +
>   static int adm1275_probe(struct i2c_client *client,
>   			 const struct i2c_device_id *id)
>   {
> @@ -598,6 +612,7 @@ static int adm1275_probe(struct i2c_client *client,
>   static struct i2c_driver adm1275_driver = {
>   	.driver = {
>   		   .name = "adm1275",
> +		   .of_match_table = of_match_ptr(adm1275_of_match),
>   		   },
>   	.probe = adm1275_probe,
>   	.remove = pmbus_do_remove,
>

--
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
Joel Stanley March 29, 2016, 9:34 a.m. UTC | #2
Hello Guenter,

On Tue, Mar 29, 2016 at 7:44 PM, Guenter Roeck <linux@roeck-us.net> wrote:
> On 03/29/2016 01:50 AM, Joel Stanley wrote:
>>
>> This adds a of_device_id table so we can probe the driver using the
>> device tree.
>>
> The subject line does not match the driver being modified; it suggests
> adm1031
> while in reality the adm1275 driver is being modified.

Apologies, that's what I get for writing a patch as I'm walking out the door.

> Besides, this should already work, through trivial bindings.
> Is there a reason to believe that it does not already work ?

I wasn't aware that we had such a mechanism, thank you. I assume you
referring to bindings/i2c/trival-devices.txt?

As background for why I added the bindings; originally this code was
patch one of two. The second added a device tree property to inform
the kernel of the external sense resistor so we could perform scaling
in the kernel.

I read the hwmon documentation on why this is not currently done.
However, as the device tree is specific to a board - things like i2c
addresses and which bus they are on - I was wondering if you would
take patches to add such a feature?

Cheers,

Joel
--
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
Guenter Roeck March 29, 2016, 2:20 p.m. UTC | #3
Hi Joel,

On 03/29/2016 02:34 AM, Joel Stanley wrote:
> Hello Guenter,
>
> On Tue, Mar 29, 2016 at 7:44 PM, Guenter Roeck <linux@roeck-us.net> wrote:
>> On 03/29/2016 01:50 AM, Joel Stanley wrote:
>>>
>>> This adds a of_device_id table so we can probe the driver using the
>>> device tree.
>>>
>> The subject line does not match the driver being modified; it suggests
>> adm1031
>> while in reality the adm1275 driver is being modified.
>
> Apologies, that's what I get for writing a patch as I'm walking out the door.
>
>> Besides, this should already work, through trivial bindings.
>> Is there a reason to believe that it does not already work ?
>
> I wasn't aware that we had such a mechanism, thank you. I assume you
> referring to bindings/i2c/trival-devices.txt?
>
Yes, and the associated mechanism.

> As background for why I added the bindings; originally this code was
> patch one of two. The second added a device tree property to inform
> the kernel of the external sense resistor so we could perform scaling
> in the kernel.
>
Add the bindings (all of them) in patch 1, and the code (all of it) in patch 2.

> I read the hwmon documentation on why this is not currently done.
> However, as the device tree is specific to a board - things like i2c
> addresses and which bus they are on - I was wondering if you would
> take patches to add such a feature?
>
Yes. Search for "shunt-resistor", which is already used for some of the
TI devices. Also see Documentation/devicetree/bindings/hwmon/ina2xx.txt.

Guenter

--
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
diff mbox

Patch

diff --git a/Documentation/devicetree/bindings/hwmon/adm1276.txt b/Documentation/devicetree/bindings/hwmon/adm1276.txt
new file mode 100644
index 000000000000..45eb51867c1b
--- /dev/null
+++ b/Documentation/devicetree/bindings/hwmon/adm1276.txt
@@ -0,0 +1,21 @@ 
+* Analog Devices ADM1275 and compatabile power monitors
+
+Required node properties:
+
+ - compatible: manufacturer and chip name, one of
+
+    "adi,adm1075"
+    "adi,adm1275"
+    "adi,adm1276"
+    "adi,adm1278"
+    "adi,adm1293"
+    "adi,adm1294"
+
+- reg: I2C bus address of the device
+
+Example adm1275 node:
+
+power-sensor {
+	compatible = "adi,adm1278";
+	reg = <0x4c>;
+}
diff --git a/drivers/hwmon/pmbus/adm1275.c b/drivers/hwmon/pmbus/adm1275.c
index 3baa4f4a8c5e..1476a127dbdb 100644
--- a/drivers/hwmon/pmbus/adm1275.c
+++ b/drivers/hwmon/pmbus/adm1275.c
@@ -22,6 +22,7 @@ 
 #include <linux/slab.h>
 #include <linux/i2c.h>
 #include <linux/bitops.h>
+#include <linux/of.h>
 #include "pmbus.h"
 
 enum chips { adm1075, adm1275, adm1276, adm1278, adm1293, adm1294 };
@@ -344,6 +345,19 @@  static const struct i2c_device_id adm1275_id[] = {
 };
 MODULE_DEVICE_TABLE(i2c, adm1275_id);
 
+#ifdef CONFIG_OF
+static const struct of_device_id adm1275_of_match[] = {
+	{ .compatible = "adi,adm1075" },
+	{ .compatible = "adi,adm1275" },
+	{ .compatible = "adi,adm1276" },
+	{ .compatible = "adi,adm1278" },
+	{ .compatible = "adi,adm1293" },
+	{ .compatible = "adi,adm1294" },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, adm1275_of_match);
+#endif
+
 static int adm1275_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
@@ -598,6 +612,7 @@  static int adm1275_probe(struct i2c_client *client,
 static struct i2c_driver adm1275_driver = {
 	.driver = {
 		   .name = "adm1275",
+		   .of_match_table = of_match_ptr(adm1275_of_match),
 		   },
 	.probe = adm1275_probe,
 	.remove = pmbus_do_remove,