diff mbox

pwm: imx: use of_alias_get_id() to get pwm base from DT alias

Message ID 1447248241-18352-1-git-send-email-mkl@pengutronix.de
State Rejected
Headers show

Commit Message

Marc Kleine-Budde Nov. 11, 2015, 1:24 p.m. UTC
The DT probe uses a dynamically allocated base by pwm core. The actual pwm
device number depends on the probe order of the devices in the DT. This not
intuitive and sometimes hard for users to map the Linux pwm number to the
actual hardware pin. (Especially on the mx25, where pwm4 is probed first.)

Use alias to identify the id of pwm port and pass it as base to the pwm core.
If an alias is not defined in device tree, a base number dynamically allocated
by pwm core will be used.

Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/pwm/pwm-imx.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Thierry Reding Nov. 12, 2015, 12:43 p.m. UTC | #1
On Wed, Nov 11, 2015 at 02:24:01PM +0100, Marc Kleine-Budde wrote:
> The DT probe uses a dynamically allocated base by pwm core. The actual pwm
> device number depends on the probe order of the devices in the DT. This not
> intuitive and sometimes hard for users to map the Linux pwm number to the
> actual hardware pin. (Especially on the mx25, where pwm4 is probed first.)
> 
> Use alias to identify the id of pwm port and pass it as base to the pwm core.
> If an alias is not defined in device tree, a base number dynamically allocated
> by pwm core will be used.
> 
> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
> ---
>  drivers/pwm/pwm-imx.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)

What is your use-case? The base is merely used as a way to set a fixed
global base number for the PWM chip. However that global namespace is a
relic from old times and no drivers (except for the very oldest) should
be using this. OF-enabled drivers certainly don't fall into that
category since there is no need to refer to the PWM devices by their
global number.

Also note that most users of the legacy API are now gone, so the global
namespace will be removed eventually, so you should not rely on it.

Thierry
diff mbox

Patch

diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index 66d6f0c5c421..9a2a46337d82 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -276,11 +276,15 @@  static int imx_pwm_probe(struct platform_device *pdev)
 	const struct imx_pwm_data *data;
 	struct imx_chip *imx;
 	struct resource *r;
-	int ret = 0;
+	int base, ret = 0;
 
 	if (!of_id)
 		return -ENODEV;
 
+	base = of_alias_get_id(pdev->dev.of_node, "pwm");
+	if (base < 0)
+		base = -1;
+
 	imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL);
 	if (imx == NULL)
 		return -ENOMEM;
@@ -301,7 +305,7 @@  static int imx_pwm_probe(struct platform_device *pdev)
 
 	imx->chip.ops = &imx_pwm_ops;
 	imx->chip.dev = &pdev->dev;
-	imx->chip.base = -1;
+	imx->chip.base = base;
 	imx->chip.npwm = 1;
 	imx->chip.can_sleep = true;