diff options
author | Lad, Prabhakar <prabhakar.csengg@gmail.com> | 2013-08-11 01:25:21 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2013-08-24 03:16:05 -0400 |
commit | c0d9644fa01892653bc9e31ef4296e78f8d8c1ca (patch) | |
tree | ff90ce6a5a09948a278d1930faf876f30caef2fd /drivers/media/i2c | |
parent | d1d70aa69db3d09240e9faf6bf68a044b9107480 (diff) |
[media] media: i2c: tvp7002: add OF support
add OF support for the tvp7002 driver.
Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'drivers/media/i2c')
-rw-r--r-- | drivers/media/i2c/tvp7002.c | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/drivers/media/i2c/tvp7002.c b/drivers/media/i2c/tvp7002.c index f6b1f3fe2608..24a08fa7e328 100644 --- a/drivers/media/i2c/tvp7002.c +++ b/drivers/media/i2c/tvp7002.c | |||
@@ -35,6 +35,8 @@ | |||
35 | #include <media/v4l2-device.h> | 35 | #include <media/v4l2-device.h> |
36 | #include <media/v4l2-common.h> | 36 | #include <media/v4l2-common.h> |
37 | #include <media/v4l2-ctrls.h> | 37 | #include <media/v4l2-ctrls.h> |
38 | #include <media/v4l2-of.h> | ||
39 | |||
38 | #include "tvp7002_reg.h" | 40 | #include "tvp7002_reg.h" |
39 | 41 | ||
40 | MODULE_DESCRIPTION("TI TVP7002 Video and Graphics Digitizer driver"); | 42 | MODULE_DESCRIPTION("TI TVP7002 Video and Graphics Digitizer driver"); |
@@ -943,6 +945,48 @@ static const struct v4l2_subdev_ops tvp7002_ops = { | |||
943 | .pad = &tvp7002_pad_ops, | 945 | .pad = &tvp7002_pad_ops, |
944 | }; | 946 | }; |
945 | 947 | ||
948 | static struct tvp7002_config * | ||
949 | tvp7002_get_pdata(struct i2c_client *client) | ||
950 | { | ||
951 | struct v4l2_of_endpoint bus_cfg; | ||
952 | struct tvp7002_config *pdata; | ||
953 | struct device_node *endpoint; | ||
954 | unsigned int flags; | ||
955 | |||
956 | if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) | ||
957 | return client->dev.platform_data; | ||
958 | |||
959 | endpoint = v4l2_of_get_next_endpoint(client->dev.of_node, NULL); | ||
960 | if (!endpoint) | ||
961 | return NULL; | ||
962 | |||
963 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); | ||
964 | if (!pdata) | ||
965 | goto done; | ||
966 | |||
967 | v4l2_of_parse_endpoint(endpoint, &bus_cfg); | ||
968 | flags = bus_cfg.bus.parallel.flags; | ||
969 | |||
970 | if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH) | ||
971 | pdata->hs_polarity = 1; | ||
972 | |||
973 | if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH) | ||
974 | pdata->vs_polarity = 1; | ||
975 | |||
976 | if (flags & V4L2_MBUS_PCLK_SAMPLE_RISING) | ||
977 | pdata->clk_polarity = 1; | ||
978 | |||
979 | if (flags & V4L2_MBUS_FIELD_EVEN_HIGH) | ||
980 | pdata->fid_polarity = 1; | ||
981 | |||
982 | if (flags & V4L2_MBUS_VIDEO_SOG_ACTIVE_HIGH) | ||
983 | pdata->sog_polarity = 1; | ||
984 | |||
985 | done: | ||
986 | of_node_put(endpoint); | ||
987 | return pdata; | ||
988 | } | ||
989 | |||
946 | /* | 990 | /* |
947 | * tvp7002_probe - Probe a TVP7002 device | 991 | * tvp7002_probe - Probe a TVP7002 device |
948 | * @c: ptr to i2c_client struct | 992 | * @c: ptr to i2c_client struct |
@@ -954,32 +998,32 @@ static const struct v4l2_subdev_ops tvp7002_ops = { | |||
954 | */ | 998 | */ |
955 | static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id) | 999 | static int tvp7002_probe(struct i2c_client *c, const struct i2c_device_id *id) |
956 | { | 1000 | { |
1001 | struct tvp7002_config *pdata = tvp7002_get_pdata(c); | ||
957 | struct v4l2_subdev *sd; | 1002 | struct v4l2_subdev *sd; |
958 | struct tvp7002 *device; | 1003 | struct tvp7002 *device; |
959 | struct v4l2_dv_timings timings; | 1004 | struct v4l2_dv_timings timings; |
960 | int polarity_a; | 1005 | int polarity_a; |
961 | int polarity_b; | 1006 | int polarity_b; |
962 | u8 revision; | 1007 | u8 revision; |
963 | |||
964 | int error; | 1008 | int error; |
965 | 1009 | ||
1010 | if (pdata == NULL) { | ||
1011 | dev_err(&c->dev, "No platform data\n"); | ||
1012 | return -EINVAL; | ||
1013 | } | ||
1014 | |||
966 | /* Check if the adapter supports the needed features */ | 1015 | /* Check if the adapter supports the needed features */ |
967 | if (!i2c_check_functionality(c->adapter, | 1016 | if (!i2c_check_functionality(c->adapter, |
968 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) | 1017 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
969 | return -EIO; | 1018 | return -EIO; |
970 | 1019 | ||
971 | if (!c->dev.platform_data) { | ||
972 | v4l_err(c, "No platform data!!\n"); | ||
973 | return -ENODEV; | ||
974 | } | ||
975 | |||
976 | device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL); | 1020 | device = devm_kzalloc(&c->dev, sizeof(struct tvp7002), GFP_KERNEL); |
977 | 1021 | ||
978 | if (!device) | 1022 | if (!device) |
979 | return -ENOMEM; | 1023 | return -ENOMEM; |
980 | 1024 | ||
981 | sd = &device->sd; | 1025 | sd = &device->sd; |
982 | device->pdata = c->dev.platform_data; | 1026 | device->pdata = pdata; |
983 | device->current_timings = tvp7002_timings; | 1027 | device->current_timings = tvp7002_timings; |
984 | 1028 | ||
985 | /* Tell v4l2 the device is ready */ | 1029 | /* Tell v4l2 the device is ready */ |
@@ -1084,9 +1128,18 @@ static const struct i2c_device_id tvp7002_id[] = { | |||
1084 | }; | 1128 | }; |
1085 | MODULE_DEVICE_TABLE(i2c, tvp7002_id); | 1129 | MODULE_DEVICE_TABLE(i2c, tvp7002_id); |
1086 | 1130 | ||
1131 | #if IS_ENABLED(CONFIG_OF) | ||
1132 | static const struct of_device_id tvp7002_of_match[] = { | ||
1133 | { .compatible = "ti,tvp7002", }, | ||
1134 | { /* sentinel */ }, | ||
1135 | }; | ||
1136 | MODULE_DEVICE_TABLE(of, tvp7002_of_match); | ||
1137 | #endif | ||
1138 | |||
1087 | /* I2C driver data */ | 1139 | /* I2C driver data */ |
1088 | static struct i2c_driver tvp7002_driver = { | 1140 | static struct i2c_driver tvp7002_driver = { |
1089 | .driver = { | 1141 | .driver = { |
1142 | .of_match_table = of_match_ptr(tvp7002_of_match), | ||
1090 | .owner = THIS_MODULE, | 1143 | .owner = THIS_MODULE, |
1091 | .name = TVP7002_MODULE_NAME, | 1144 | .name = TVP7002_MODULE_NAME, |
1092 | }, | 1145 | }, |