linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pwm: imx: use of_alias_get_id() to get pwm base from DT alias
@ 2015-11-11 13:24 Marc Kleine-Budde
  2015-11-12 12:43 ` Thierry Reding
  0 siblings, 1 reply; 2+ messages in thread
From: Marc Kleine-Budde @ 2015-11-11 13:24 UTC (permalink / raw)
  To: linux-pwm; +Cc: Thierry Reding, kernel, Marc Kleine-Budde

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(-)

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;
 
-- 
2.6.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-11-12 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-11 13:24 [PATCH] pwm: imx: use of_alias_get_id() to get pwm base from DT alias Marc Kleine-Budde
2015-11-12 12:43 ` Thierry Reding

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).