Skip to content

Commit

Permalink
[media] v4l: vsp1: Add DT support
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Laurent Pinchart authored and Mauro Carvalho Chehab committed Apr 23, 2014
1 parent 34d1cbd commit 0b82fb9
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions drivers/media/platform/vsp1/vsp1_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <linux/device.h>
#include <linux/interrupt.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/videodev2.h>

Expand Down Expand Up @@ -431,34 +432,59 @@ static const struct dev_pm_ops vsp1_pm_ops = {
* Platform Driver
*/

static struct vsp1_platform_data *
vsp1_get_platform_data(struct platform_device *pdev)
static int vsp1_validate_platform_data(struct platform_device *pdev,
struct vsp1_platform_data *pdata)
{
struct vsp1_platform_data *pdata = pdev->dev.platform_data;

if (pdata == NULL) {
dev_err(&pdev->dev, "missing platform data\n");
return NULL;
return -EINVAL;
}

if (pdata->rpf_count <= 0 || pdata->rpf_count > VPS1_MAX_RPF) {
dev_err(&pdev->dev, "invalid number of RPF (%u)\n",
pdata->rpf_count);
return NULL;
return -EINVAL;
}

if (pdata->uds_count <= 0 || pdata->uds_count > VPS1_MAX_UDS) {
dev_err(&pdev->dev, "invalid number of UDS (%u)\n",
pdata->uds_count);
return NULL;
return -EINVAL;
}

if (pdata->wpf_count <= 0 || pdata->wpf_count > VPS1_MAX_WPF) {
dev_err(&pdev->dev, "invalid number of WPF (%u)\n",
pdata->wpf_count);
return NULL;
return -EINVAL;
}

return 0;
}

static struct vsp1_platform_data *
vsp1_get_platform_data(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
struct vsp1_platform_data *pdata;

if (!IS_ENABLED(CONFIG_OF) || np == NULL)
return pdev->dev.platform_data;

pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (pdata == NULL)
return NULL;

if (of_property_read_bool(np, "renesas,has-lif"))
pdata->features |= VSP1_HAS_LIF;
if (of_property_read_bool(np, "renesas,has-lut"))
pdata->features |= VSP1_HAS_LUT;
if (of_property_read_bool(np, "renesas,has-sru"))
pdata->features |= VSP1_HAS_SRU;

of_property_read_u32(np, "renesas,#rpf", &pdata->rpf_count);
of_property_read_u32(np, "renesas,#uds", &pdata->uds_count);
of_property_read_u32(np, "renesas,#wpf", &pdata->wpf_count);

return pdata;
}

Expand All @@ -481,6 +507,10 @@ static int vsp1_probe(struct platform_device *pdev)
if (vsp1->pdata == NULL)
return -ENODEV;

ret = vsp1_validate_platform_data(pdev, vsp1->pdata);
if (ret < 0)
return ret;

/* I/O, IRQ and clock resources */
io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
vsp1->mmio = devm_ioremap_resource(&pdev->dev, io);
Expand Down Expand Up @@ -527,13 +557,19 @@ static int vsp1_remove(struct platform_device *pdev)
return 0;
}

static const struct of_device_id vsp1_of_match[] = {
{ .compatible = "renesas,vsp1" },
{ },
};

static struct platform_driver vsp1_platform_driver = {
.probe = vsp1_probe,
.remove = vsp1_remove,
.driver = {
.owner = THIS_MODULE,
.name = "vsp1",
.pm = &vsp1_pm_ops,
.of_match_table = vsp1_of_match,
},
};

Expand Down

0 comments on commit 0b82fb9

Please sign in to comment.