Skip to content

Commit 585ba60

Browse files
linuswWim Van Sebroeck
authored andcommitted
watchdog: max63xx_wdt: Add device tree probing
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 <[email protected]> Signed-off-by: Linus Walleij <[email protected]> Reviewed-by: Guenter Roeck <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Wim Van Sebroeck <[email protected]>
1 parent 11648fa commit 585ba60

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

drivers/watchdog/max63xx_wdt.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/spinlock.h>
2727
#include <linux/io.h>
2828
#include <linux/slab.h>
29+
#include <linux/property.h>
2930

3031
#define DEFAULT_HEARTBEAT 60
3132
#define MAX_HEARTBEAT 60
@@ -99,8 +100,8 @@ static const struct max63xx_timeout max6373_table[] = {
99100
{ },
100101
};
101102

102-
static struct max63xx_timeout *
103-
max63xx_select_timeout(struct max63xx_timeout *table, int value)
103+
static const struct max63xx_timeout *
104+
max63xx_select_timeout(const struct max63xx_timeout *table, int value)
104105
{
105106
while (table->twd) {
106107
if (value <= table->twd) {
@@ -202,14 +203,17 @@ static int max63xx_wdt_probe(struct platform_device *pdev)
202203
{
203204
struct device *dev = &pdev->dev;
204205
struct max63xx_wdt *wdt;
205-
struct max63xx_timeout *table;
206+
const struct max63xx_timeout *table;
206207
int err;
207208

208209
wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
209210
if (!wdt)
210211
return -ENOMEM;
211212

212-
table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
213+
/* Attempt to use fwnode first */
214+
table = device_get_match_data(dev);
215+
if (!table)
216+
table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
213217

214218
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
215219
heartbeat = DEFAULT_HEARTBEAT;
@@ -255,11 +259,23 @@ static const struct platform_device_id max63xx_id_table[] = {
255259
};
256260
MODULE_DEVICE_TABLE(platform, max63xx_id_table);
257261

262+
static const struct of_device_id max63xx_dt_id_table[] = {
263+
{ .compatible = "maxim,max6369", .data = max6369_table, },
264+
{ .compatible = "maxim,max6370", .data = max6369_table, },
265+
{ .compatible = "maxim,max6371", .data = max6371_table, },
266+
{ .compatible = "maxim,max6372", .data = max6371_table, },
267+
{ .compatible = "maxim,max6373", .data = max6373_table, },
268+
{ .compatible = "maxim,max6374", .data = max6373_table, },
269+
{ }
270+
};
271+
MODULE_DEVICE_TABLE(of, max63xx_dt_id_table);
272+
258273
static struct platform_driver max63xx_wdt_driver = {
259274
.probe = max63xx_wdt_probe,
260275
.id_table = max63xx_id_table,
261276
.driver = {
262277
.name = "max63xx_wdt",
278+
.of_match_table = max63xx_dt_id_table,
263279
},
264280
};
265281

0 commit comments

Comments
 (0)