aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pwm
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2013-07-25 18:27:41 -0400
committerThierry Reding <thierry.reding@gmail.com>2013-09-03 07:09:15 -0400
commit382457e562bbb1ea7d94923e58fcbac9e981ff18 (patch)
tree47280d1a49086517f0ac7b0b3d81087310297194 /drivers/pwm
parenteb9bdef111b82389f9b7943bc29fb72c3a0fa5b0 (diff)
pwm: renesas-tpu: Add DT support
Specify DT bindings for the TPU PWM controller and add OF support to the driver. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Acked-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'drivers/pwm')
-rw-r--r--drivers/pwm/pwm-renesas-tpu.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/drivers/pwm/pwm-renesas-tpu.c b/drivers/pwm/pwm-renesas-tpu.c
index 2600892782c1..3eeffff69280 100644
--- a/drivers/pwm/pwm-renesas-tpu.c
+++ b/drivers/pwm/pwm-renesas-tpu.c
@@ -20,6 +20,7 @@
20#include <linux/ioport.h> 20#include <linux/ioport.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/of.h>
23#include <linux/platform_data/pwm-renesas-tpu.h> 24#include <linux/platform_data/pwm-renesas-tpu.h>
24#include <linux/platform_device.h> 25#include <linux/platform_device.h>
25#include <linux/pm_runtime.h> 26#include <linux/pm_runtime.h>
@@ -86,7 +87,7 @@ struct tpu_pwm_device {
86 87
87struct tpu_device { 88struct tpu_device {
88 struct platform_device *pdev; 89 struct platform_device *pdev;
89 struct tpu_pwm_platform_data *pdata; 90 enum pwm_polarity polarities[TPU_CHANNEL_MAX];
90 struct pwm_chip chip; 91 struct pwm_chip chip;
91 spinlock_t lock; 92 spinlock_t lock;
92 93
@@ -228,8 +229,7 @@ static int tpu_pwm_request(struct pwm_chip *chip, struct pwm_device *_pwm)
228 229
229 pwm->tpu = tpu; 230 pwm->tpu = tpu;
230 pwm->channel = _pwm->hwpwm; 231 pwm->channel = _pwm->hwpwm;
231 pwm->polarity = tpu->pdata ? tpu->pdata->channels[pwm->channel].polarity 232 pwm->polarity = tpu->polarities[pwm->channel];
232 : PWM_POLARITY_NORMAL;
233 pwm->prescaler = 0; 233 pwm->prescaler = 0;
234 pwm->period = 0; 234 pwm->period = 0;
235 pwm->duty = 0; 235 pwm->duty = 0;
@@ -388,6 +388,16 @@ static const struct pwm_ops tpu_pwm_ops = {
388 * Probe and remove 388 * Probe and remove
389 */ 389 */
390 390
391static void tpu_parse_pdata(struct tpu_device *tpu)
392{
393 struct tpu_pwm_platform_data *pdata = tpu->pdev->dev.platform_data;
394 unsigned int i;
395
396 for (i = 0; i < ARRAY_SIZE(tpu->polarities); ++i)
397 tpu->polarities[i] = pdata ? pdata->channels[i].polarity
398 : PWM_POLARITY_NORMAL;
399}
400
391static int tpu_probe(struct platform_device *pdev) 401static int tpu_probe(struct platform_device *pdev)
392{ 402{
393 struct tpu_device *tpu; 403 struct tpu_device *tpu;
@@ -400,7 +410,11 @@ static int tpu_probe(struct platform_device *pdev)
400 return -ENOMEM; 410 return -ENOMEM;
401 } 411 }
402 412
403 tpu->pdata = pdev->dev.platform_data; 413 spin_lock_init(&tpu->lock);
414 tpu->pdev = pdev;
415
416 /* Initialize device configuration from platform data. */
417 tpu_parse_pdata(tpu);
404 418
405 /* Map memory, get clock and pin control. */ 419 /* Map memory, get clock and pin control. */
406 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 420 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -422,11 +436,10 @@ static int tpu_probe(struct platform_device *pdev)
422 /* Initialize and register the device. */ 436 /* Initialize and register the device. */
423 platform_set_drvdata(pdev, tpu); 437 platform_set_drvdata(pdev, tpu);
424 438
425 spin_lock_init(&tpu->lock);
426 tpu->pdev = pdev;
427
428 tpu->chip.dev = &pdev->dev; 439 tpu->chip.dev = &pdev->dev;
429 tpu->chip.ops = &tpu_pwm_ops; 440 tpu->chip.ops = &tpu_pwm_ops;
441 tpu->chip.of_xlate = of_pwm_xlate_with_flags;
442 tpu->chip.of_pwm_n_cells = 3;
430 tpu->chip.base = -1; 443 tpu->chip.base = -1;
431 tpu->chip.npwm = TPU_CHANNEL_MAX; 444 tpu->chip.npwm = TPU_CHANNEL_MAX;
432 445
@@ -457,12 +470,26 @@ static int tpu_remove(struct platform_device *pdev)
457 return 0; 470 return 0;
458} 471}
459 472
473#ifdef CONFIG_OF
474static const struct of_device_id tpu_of_table[] = {
475 { .compatible = "renesas,tpu-r8a73a4", },
476 { .compatible = "renesas,tpu-r8a7740", },
477 { .compatible = "renesas,tpu-r8a7790", },
478 { .compatible = "renesas,tpu-sh7372", },
479 { .compatible = "renesas,tpu", },
480 { },
481};
482
483MODULE_DEVICE_TABLE(of, tpu_of_table);
484#endif
485
460static struct platform_driver tpu_driver = { 486static struct platform_driver tpu_driver = {
461 .probe = tpu_probe, 487 .probe = tpu_probe,
462 .remove = tpu_remove, 488 .remove = tpu_remove,
463 .driver = { 489 .driver = {
464 .name = "renesas-tpu-pwm", 490 .name = "renesas-tpu-pwm",
465 .owner = THIS_MODULE, 491 .owner = THIS_MODULE,
492 .of_match_table = of_match_ptr(tpu_of_table),
466 } 493 }
467}; 494};
468 495