pmaports/device/testing/linux-postmarketos-stericsson/0002-pwm-ab8500-Get-HW-ID-from-reg-value.patch

59 lines
1.8 KiB
Diff
Raw Normal View History

From 6a5a212f9907a5da764878a7b0059da33371e36f Mon Sep 17 00:00:00 2001
From: Linus Walleij <linus.walleij@linaro.org>
Date: Sat, 15 Jan 2022 01:54:57 +0100
Subject: [PATCH 2/2] pwm: ab8500: Get HW ID from reg value
Instead of relying on the platform device ID which is just
assigned by the order of appearance of nodes in the device tree
if we're lucky, rely on the reg value which is stable and
predictable.
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
drivers/pwm/pwm-ab8500.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/drivers/pwm/pwm-ab8500.c b/drivers/pwm/pwm-ab8500.c
index ad37bc46f272..338e046e89ea 100644
--- a/drivers/pwm/pwm-ab8500.c
+++ b/drivers/pwm/pwm-ab8500.c
@@ -11,6 +11,7 @@
#include <linux/mfd/abx500.h>
#include <linux/mfd/abx500/ab8500.h>
#include <linux/module.h>
+#include <linux/property.h>
/*
* PWM Out generators
@@ -93,10 +94,16 @@ static const struct pwm_ops ab8500_pwm_ops = {
static int ab8500_pwm_probe(struct platform_device *pdev)
{
struct ab8500_pwm_chip *ab8500;
+ u32 hwid;
int err;
- if (pdev->id < 1 || pdev->id > 31)
- return dev_err_probe(&pdev->dev, EINVAL, "Invalid device id %d\n", pdev->id);
+ err = device_property_read_u32(&pdev->dev, "reg", &hwid);
+ if (err) {
+ dev_err_probe(&pdev->dev, err, "missing reg property\n");
+ return err;
+ }
+ if (hwid < 1 || hwid > 31)
+ return dev_err_probe(&pdev->dev, EINVAL, "Invalid device id %d\n", hwid);
/*
* Nothing to be done in probe, this is required to get the
@@ -109,7 +116,7 @@ static int ab8500_pwm_probe(struct platform_device *pdev)
ab8500->chip.dev = &pdev->dev;
ab8500->chip.ops = &ab8500_pwm_ops;
ab8500->chip.npwm = 1;
- ab8500->hwid = pdev->id - 1;
+ ab8500->hwid = hwid;
err = devm_pwmchip_add(&pdev->dev, &ab8500->chip);
if (err < 0)
--
2.38.1