Skip to content

Commit 1b5239f

Browse files
nunojsagroeck
authored andcommitted
hwmon: (axi-fan-control) Use device firmware agnostic API
Don't directly use OF and use device property APIs. In addition, this makes the probe() code neater and also allow us to move the of_device_id table to it's natural place. While at it, make sure to explicitly include mod_devicetable.h for the of_device_id table. Signed-off-by: Nuno Sa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Guenter Roeck <[email protected]>
1 parent 692cf83 commit 1b5239f

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

drivers/hwmon/axi-fan-control.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
#include <linux/io.h>
1414
#include <linux/kernel.h>
1515
#include <linux/module.h>
16-
#include <linux/of.h>
16+
#include <linux/mod_devicetable.h>
1717
#include <linux/platform_device.h>
18+
#include <linux/property.h>
1819

1920
/* register map */
2021
#define ADI_REG_RSTN 0x0080
@@ -368,12 +369,12 @@ static irqreturn_t axi_fan_control_irq_handler(int irq, void *data)
368369
}
369370

370371
static int axi_fan_control_init(struct axi_fan_control_data *ctl,
371-
const struct device_node *np)
372+
const struct device *dev)
372373
{
373374
int ret;
374375

375376
/* get fan pulses per revolution */
376-
ret = of_property_read_u32(np, "pulses-per-revolution", &ctl->ppr);
377+
ret = device_property_read_u32(dev, "pulses-per-revolution", &ctl->ppr);
377378
if (ret)
378379
return ret;
379380

@@ -443,25 +444,16 @@ static struct attribute *axi_fan_control_attrs[] = {
443444
};
444445
ATTRIBUTE_GROUPS(axi_fan_control);
445446

446-
static const u32 version_1_0_0 = ADI_AXI_PCORE_VER(1, 0, 'a');
447-
448-
static const struct of_device_id axi_fan_control_of_match[] = {
449-
{ .compatible = "adi,axi-fan-control-1.00.a",
450-
.data = (void *)&version_1_0_0},
451-
{},
452-
};
453-
MODULE_DEVICE_TABLE(of, axi_fan_control_of_match);
454-
455447
static int axi_fan_control_probe(struct platform_device *pdev)
456448
{
457449
struct axi_fan_control_data *ctl;
458450
struct clk *clk;
459-
const struct of_device_id *id;
451+
const unsigned int *id;
460452
const char *name = "axi_fan_control";
461453
u32 version;
462454
int ret;
463455

464-
id = of_match_node(axi_fan_control_of_match, pdev->dev.of_node);
456+
id = device_get_match_data(&pdev->dev);
465457
if (!id)
466458
return -EINVAL;
467459

@@ -485,18 +477,18 @@ static int axi_fan_control_probe(struct platform_device *pdev)
485477

486478
version = axi_ioread(ADI_AXI_REG_VERSION, ctl);
487479
if (ADI_AXI_PCORE_VER_MAJOR(version) !=
488-
ADI_AXI_PCORE_VER_MAJOR((*(u32 *)id->data))) {
480+
ADI_AXI_PCORE_VER_MAJOR((*id))) {
489481
dev_err(&pdev->dev, "Major version mismatch. Expected %d.%.2d.%c, Reported %d.%.2d.%c\n",
490-
ADI_AXI_PCORE_VER_MAJOR((*(u32 *)id->data)),
491-
ADI_AXI_PCORE_VER_MINOR((*(u32 *)id->data)),
492-
ADI_AXI_PCORE_VER_PATCH((*(u32 *)id->data)),
482+
ADI_AXI_PCORE_VER_MAJOR(*id),
483+
ADI_AXI_PCORE_VER_MINOR(*id),
484+
ADI_AXI_PCORE_VER_PATCH(*id),
493485
ADI_AXI_PCORE_VER_MAJOR(version),
494486
ADI_AXI_PCORE_VER_MINOR(version),
495487
ADI_AXI_PCORE_VER_PATCH(version));
496488
return -ENODEV;
497489
}
498490

499-
ret = axi_fan_control_init(ctl, pdev->dev.of_node);
491+
ret = axi_fan_control_init(ctl, &pdev->dev);
500492
if (ret) {
501493
dev_err(&pdev->dev, "Failed to initialize device\n");
502494
return ret;
@@ -527,6 +519,15 @@ static int axi_fan_control_probe(struct platform_device *pdev)
527519
return 0;
528520
}
529521

522+
static const u32 version_1_0_0 = ADI_AXI_PCORE_VER(1, 0, 'a');
523+
524+
static const struct of_device_id axi_fan_control_of_match[] = {
525+
{ .compatible = "adi,axi-fan-control-1.00.a",
526+
.data = (void *)&version_1_0_0},
527+
{},
528+
};
529+
MODULE_DEVICE_TABLE(of, axi_fan_control_of_match);
530+
530531
static struct platform_driver axi_fan_control_driver = {
531532
.driver = {
532533
.name = "axi_fan_control_driver",

0 commit comments

Comments
 (0)