aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/platform/vsp1/vsp1_drv.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2014-04-08 12:40:13 -0400
committerMauro Carvalho Chehab <m.chehab@samsung.com>2014-04-23 09:21:58 -0400
commit0b82fb95d9edf7bdfc6486c67a42dbf9b1e97765 (patch)
tree34083bfbaa4c79c0f1c26ae587cbad5038ba0a05 /drivers/media/platform/vsp1/vsp1_drv.c
parent34d1cbdafd5b27bc06f47f557e0581b7b85d6f07 (diff)
[media] v4l: vsp1: Add DT support
Implement support for the VSP1 DT bindings in the VSP1 driver. The driver now first retrieves platform data either from the platform data pointer or by reading the device tree node, and then validates it regardless of the platform data source. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Acked-by: Sylwester Nawrocki <s.nawrocki@samsung.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/platform/vsp1/vsp1_drv.c')
-rw-r--r--drivers/media/platform/vsp1/vsp1_drv.c52
1 files changed, 44 insertions, 8 deletions
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 28e1de3270e0..c69ee0657f75 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -16,6 +16,7 @@
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/of.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
20#include <linux/videodev2.h> 21#include <linux/videodev2.h>
21 22
@@ -431,34 +432,59 @@ static const struct dev_pm_ops vsp1_pm_ops = {
431 * Platform Driver 432 * Platform Driver
432 */ 433 */
433 434
434static struct vsp1_platform_data * 435static int vsp1_validate_platform_data(struct platform_device *pdev,
435vsp1_get_platform_data(struct platform_device *pdev) 436 struct vsp1_platform_data *pdata)
436{ 437{
437 struct vsp1_platform_data *pdata = pdev->dev.platform_data;
438
439 if (pdata == NULL) { 438 if (pdata == NULL) {
440 dev_err(&pdev->dev, "missing platform data\n"); 439 dev_err(&pdev->dev, "missing platform data\n");
441 return NULL; 440 return -EINVAL;
442 } 441 }
443 442
444 if (pdata->rpf_count <= 0 || pdata->rpf_count > VPS1_MAX_RPF) { 443 if (pdata->rpf_count <= 0 || pdata->rpf_count > VPS1_MAX_RPF) {
445 dev_err(&pdev->dev, "invalid number of RPF (%u)\n", 444 dev_err(&pdev->dev, "invalid number of RPF (%u)\n",
446 pdata->rpf_count); 445 pdata->rpf_count);
447 return NULL; 446 return -EINVAL;
448 } 447 }
449 448
450 if (pdata->uds_count <= 0 || pdata->uds_count > VPS1_MAX_UDS) { 449 if (pdata->uds_count <= 0 || pdata->uds_count > VPS1_MAX_UDS) {
451 dev_err(&pdev->dev, "invalid number of UDS (%u)\n", 450 dev_err(&pdev->dev, "invalid number of UDS (%u)\n",
452 pdata->uds_count); 451 pdata->uds_count);
453 return NULL; 452 return -EINVAL;
454 } 453 }
455 454
456 if (pdata->wpf_count <= 0 || pdata->wpf_count > VPS1_MAX_WPF) { 455 if (pdata->wpf_count <= 0 || pdata->wpf_count > VPS1_MAX_WPF) {
457 dev_err(&pdev->dev, "invalid number of WPF (%u)\n", 456 dev_err(&pdev->dev, "invalid number of WPF (%u)\n",
458 pdata->wpf_count); 457 pdata->wpf_count);
459 return NULL; 458 return -EINVAL;
460 } 459 }
461 460
461 return 0;
462}
463
464static struct vsp1_platform_data *
465vsp1_get_platform_data(struct platform_device *pdev)
466{
467 struct device_node *np = pdev->dev.of_node;
468 struct vsp1_platform_data *pdata;
469
470 if (!IS_ENABLED(CONFIG_OF) || np == NULL)
471 return pdev->dev.platform_data;
472
473 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
474 if (pdata == NULL)
475 return NULL;
476
477 if (of_property_read_bool(np, "renesas,has-lif"))
478 pdata->features |= VSP1_HAS_LIF;
479 if (of_property_read_bool(np, "renesas,has-lut"))
480 pdata->features |= VSP1_HAS_LUT;
481 if (of_property_read_bool(np, "renesas,has-sru"))
482 pdata->features |= VSP1_HAS_SRU;
483
484 of_property_read_u32(np, "renesas,#rpf", &pdata->rpf_count);
485 of_property_read_u32(np, "renesas,#uds", &pdata->uds_count);
486 of_property_read_u32(np, "renesas,#wpf", &pdata->wpf_count);
487
462 return pdata; 488 return pdata;
463} 489}
464 490
@@ -481,6 +507,10 @@ static int vsp1_probe(struct platform_device *pdev)
481 if (vsp1->pdata == NULL) 507 if (vsp1->pdata == NULL)
482 return -ENODEV; 508 return -ENODEV;
483 509
510 ret = vsp1_validate_platform_data(pdev, vsp1->pdata);
511 if (ret < 0)
512 return ret;
513
484 /* I/O, IRQ and clock resources */ 514 /* I/O, IRQ and clock resources */
485 io = platform_get_resource(pdev, IORESOURCE_MEM, 0); 515 io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
486 vsp1->mmio = devm_ioremap_resource(&pdev->dev, io); 516 vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
@@ -527,6 +557,11 @@ static int vsp1_remove(struct platform_device *pdev)
527 return 0; 557 return 0;
528} 558}
529 559
560static const struct of_device_id vsp1_of_match[] = {
561 { .compatible = "renesas,vsp1" },
562 { },
563};
564
530static struct platform_driver vsp1_platform_driver = { 565static struct platform_driver vsp1_platform_driver = {
531 .probe = vsp1_probe, 566 .probe = vsp1_probe,
532 .remove = vsp1_remove, 567 .remove = vsp1_remove,
@@ -534,6 +569,7 @@ static struct platform_driver vsp1_platform_driver = {
534 .owner = THIS_MODULE, 569 .owner = THIS_MODULE,
535 .name = "vsp1", 570 .name = "vsp1",
536 .pm = &vsp1_pm_ops, 571 .pm = &vsp1_pm_ops,
572 .of_match_table = vsp1_of_match,
537 }, 573 },
538}; 574};
539 575