diff mbox series

[2/2] watchdog: max63xx_wdt: Add device tree probing

Message ID 20210714153314.1004147-2-linus.walleij@linaro.org
State New
Headers show
Series [1/2] dt-bindings: watchdog: Add Maxim MAX63xx bindings | expand

Commit Message

Linus Walleij July 14, 2021, 3:33 p.m. UTC
This adds device tree probing to the MAX63xx driver so it can be
instantiated from the device tree. We use the generic fwnode-based
method to get to the match data and clean up by constifying the
functions as the match is indeed a const.

Cc: Marc Zyngier <maz@kernel.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/watchdog/max63xx_wdt.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

-- 
2.31.1

Comments

Guenter Roeck July 17, 2021, 2:08 p.m. UTC | #1
On Wed, Jul 14, 2021 at 05:33:14PM +0200, Linus Walleij wrote:
> This adds device tree probing to the MAX63xx driver so it can be

> instantiated from the device tree. We use the generic fwnode-based

> method to get to the match data and clean up by constifying the

> functions as the match is indeed a const.

> 

> Cc: Marc Zyngier <maz@kernel.org>

> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>


Reviewed-by: Guenter Roeck <linux@roeck-us.net>


> ---

>  drivers/watchdog/max63xx_wdt.c | 24 ++++++++++++++++++++----

>  1 file changed, 20 insertions(+), 4 deletions(-)

> 

> diff --git a/drivers/watchdog/max63xx_wdt.c b/drivers/watchdog/max63xx_wdt.c

> index 3a899628a834..9e1541cfae0d 100644

> --- a/drivers/watchdog/max63xx_wdt.c

> +++ b/drivers/watchdog/max63xx_wdt.c

> @@ -26,6 +26,7 @@

>  #include <linux/spinlock.h>

>  #include <linux/io.h>

>  #include <linux/slab.h>

> +#include <linux/property.h>

>  

>  #define DEFAULT_HEARTBEAT 60

>  #define MAX_HEARTBEAT     60

> @@ -99,8 +100,8 @@ static const struct max63xx_timeout max6373_table[] = {

>  	{ },

>  };

>  

> -static struct max63xx_timeout *

> -max63xx_select_timeout(struct max63xx_timeout *table, int value)

> +static const struct max63xx_timeout *

> +max63xx_select_timeout(const struct max63xx_timeout *table, int value)

>  {

>  	while (table->twd) {

>  		if (value <= table->twd) {

> @@ -202,14 +203,17 @@ static int max63xx_wdt_probe(struct platform_device *pdev)

>  {

>  	struct device *dev = &pdev->dev;

>  	struct max63xx_wdt *wdt;

> -	struct max63xx_timeout *table;

> +	const struct max63xx_timeout *table;

>  	int err;

>  

>  	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);

>  	if (!wdt)

>  		return -ENOMEM;

>  

> -	table = (struct max63xx_timeout *)pdev->id_entry->driver_data;

> +	/* Attempt to use fwnode first */

> +	table = device_get_match_data(dev);

> +	if (!table)

> +		table = (struct max63xx_timeout *)pdev->id_entry->driver_data;

>  

>  	if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)

>  		heartbeat = DEFAULT_HEARTBEAT;

> @@ -255,11 +259,23 @@ static const struct platform_device_id max63xx_id_table[] = {

>  };

>  MODULE_DEVICE_TABLE(platform, max63xx_id_table);

>  

> +static const struct of_device_id max63xx_dt_id_table[] = {

> +	{ .compatible = "maxim,max6369", .data = max6369_table, },

> +	{ .compatible = "maxim,max6370", .data = max6369_table, },

> +	{ .compatible = "maxim,max6371", .data = max6371_table, },

> +	{ .compatible = "maxim,max6372", .data = max6371_table, },

> +	{ .compatible = "maxim,max6373", .data = max6373_table, },

> +	{ .compatible = "maxim,max6374", .data = max6373_table, },

> +	{ }

> +};

> +MODULE_DEVICE_TABLE(of, max63xx_dt_id_table);

> +

>  static struct platform_driver max63xx_wdt_driver = {

>  	.probe		= max63xx_wdt_probe,

>  	.id_table	= max63xx_id_table,

>  	.driver		= {

>  		.name	= "max63xx_wdt",

> +		.of_match_table = max63xx_dt_id_table,

>  	},

>  };

>  

> -- 

> 2.31.1

>
diff mbox series

Patch

diff --git a/drivers/watchdog/max63xx_wdt.c b/drivers/watchdog/max63xx_wdt.c
index 3a899628a834..9e1541cfae0d 100644
--- a/drivers/watchdog/max63xx_wdt.c
+++ b/drivers/watchdog/max63xx_wdt.c
@@ -26,6 +26,7 @@ 
 #include <linux/spinlock.h>
 #include <linux/io.h>
 #include <linux/slab.h>
+#include <linux/property.h>
 
 #define DEFAULT_HEARTBEAT 60
 #define MAX_HEARTBEAT     60
@@ -99,8 +100,8 @@  static const struct max63xx_timeout max6373_table[] = {
 	{ },
 };
 
-static struct max63xx_timeout *
-max63xx_select_timeout(struct max63xx_timeout *table, int value)
+static const struct max63xx_timeout *
+max63xx_select_timeout(const struct max63xx_timeout *table, int value)
 {
 	while (table->twd) {
 		if (value <= table->twd) {
@@ -202,14 +203,17 @@  static int max63xx_wdt_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct max63xx_wdt *wdt;
-	struct max63xx_timeout *table;
+	const struct max63xx_timeout *table;
 	int err;
 
 	wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
 	if (!wdt)
 		return -ENOMEM;
 
-	table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
+	/* Attempt to use fwnode first */
+	table = device_get_match_data(dev);
+	if (!table)
+		table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
 
 	if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
 		heartbeat = DEFAULT_HEARTBEAT;
@@ -255,11 +259,23 @@  static const struct platform_device_id max63xx_id_table[] = {
 };
 MODULE_DEVICE_TABLE(platform, max63xx_id_table);
 
+static const struct of_device_id max63xx_dt_id_table[] = {
+	{ .compatible = "maxim,max6369", .data = max6369_table, },
+	{ .compatible = "maxim,max6370", .data = max6369_table, },
+	{ .compatible = "maxim,max6371", .data = max6371_table, },
+	{ .compatible = "maxim,max6372", .data = max6371_table, },
+	{ .compatible = "maxim,max6373", .data = max6373_table, },
+	{ .compatible = "maxim,max6374", .data = max6373_table, },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, max63xx_dt_id_table);
+
 static struct platform_driver max63xx_wdt_driver = {
 	.probe		= max63xx_wdt_probe,
 	.id_table	= max63xx_id_table,
 	.driver		= {
 		.name	= "max63xx_wdt",
+		.of_match_table = max63xx_dt_id_table,
 	},
 };