From 63d983344c7c7ed717cb5dbf1d40dcffd102cb56 Mon Sep 17 00:00:00 2001 From: Karol Lewandowski Date: Thu, 12 Apr 2012 20:45:29 +0200 Subject: s5p-tv: Add DT-support for HDMI driver Includes v4l2/dt helper function (hdmi_of_get_i2c_subdev() that probably should be implemented in v4l2 core itself. Signed-off-by: Karol Lewandowski Cc: Tomasz Stanislawski --- drivers/media/platform/s5p-tv/hdmi_drv.c | 69 +++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/s5p-tv/hdmi_drv.c b/drivers/media/platform/s5p-tv/hdmi_drv.c index 953a2ea57a0..900ad017f4a 100644 --- a/drivers/media/platform/s5p-tv/hdmi_drv.c +++ b/drivers/media/platform/s5p-tv/hdmi_drv.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include @@ -679,6 +681,57 @@ static int hdmi_enum_dv_presets(struct v4l2_subdev *sd, preset); } +#ifdef CONFIG_OF +/* Heavily based[1] on v4l2_i2c_new_subdev_board() + * + * [1] Copy-pasted, that is + */ +struct v4l2_subdev *hdmi_of_get_i2c_subdev(struct v4l2_device *v4l2_dev, + struct device_node *np, const char *propname) +{ + struct v4l2_subdev *sd = NULL; + struct i2c_client *client; + struct device_node *cnp; + + BUG_ON(!v4l2_dev); + + cnp = of_parse_phandle(np, propname, 0); + if (!cnp) { + dev_err(v4l2_dev->dev, "Can't find subdev %s\n", propname); + goto err; + } + + client = of_find_i2c_device_by_node(cnp); + if (!client) { + dev_err(v4l2_dev->dev, "subdev %s doesn't reference correct node\n", + propname); + goto err; + } + + if (client == NULL || client->driver == NULL) + goto err; + + /* Lock the module so we can safely get the v4l2_subdev pointer */ + if (!try_module_get(client->driver->driver.owner)) + goto err; + sd = i2c_get_clientdata(client); + + /* Register with the v4l2_device which increases the module's + use count as well. */ + if (v4l2_device_register_subdev(v4l2_dev, sd)) { + dev_err(v4l2_dev->dev, + "%s: failed to register subdev\n", __func__); + sd = NULL; + } + /* Decrease the module use count to match the first try_module_get. */ + module_put(client->driver->driver.owner); +err: + of_node_put(cnp); + + return sd; +} +#endif + static const struct v4l2_subdev_core_ops hdmi_sd_core_ops = { .s_power = hdmi_s_power, }; @@ -840,6 +893,12 @@ static struct v4l2_subdev *hdmi_get_subdev( struct i2c_adapter *adapter; struct device *dev = hdmi_dev->dev; +#ifdef CONFIG_OF + if (dev->of_node) + return hdmi_of_get_i2c_subdev(&hdmi_dev->v4l2_dev, + dev->of_node, propname); +#endif + if (!bdinfo) { dev_err(dev, "%s info is missing in platform data\n", propname); @@ -878,7 +937,7 @@ static int hdmi_probe(struct platform_device *pdev) dev_dbg(dev, "probe start\n"); - if (!pdata) { + if (!pdata && !dev->of_node) { dev_err(dev, "platform data is missing\n"); ret = -ENODEV; goto fail; @@ -1003,6 +1062,13 @@ static int hdmi_remove(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF +static struct of_device_id hdmi_dt_match[] = { + { .compatible = "samsung,s5pv210-hdmi" }, + { }, +}; +#endif + static struct platform_driver hdmi_driver __refdata = { .probe = hdmi_probe, .remove = hdmi_remove, @@ -1011,6 +1077,7 @@ static struct platform_driver hdmi_driver __refdata = { .name = "s5p-hdmi", .owner = THIS_MODULE, .pm = &hdmi_pm_ops, + .of_match_table = of_match_ptr(hdmi_dt_match), } }; -- cgit v1.2.3