diff options
author | Lad, Prabhakar <prabhakar.csengg@gmail.com> | 2013-05-26 09:08:54 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2013-06-17 10:31:37 -0400 |
commit | 8d4da37c3006f30a7cf75cd7bb33b254afc30279 (patch) | |
tree | d874b274ac0644f41a4fae77d4273108bf321d61 /drivers/media/i2c/mt9p031.c | |
parent | 3080f8c77f277eb87397d639581ebea859f9ea41 (diff) |
[media] media: i2c: mt9p031: add OF support
Add OF support for the mt9p031 sensor driver.
Alongside this patch sorts the header inclusion alphabetically.
Signed-off-by: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Reviewed-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/i2c/mt9p031.c')
-rw-r--r-- | drivers/media/i2c/mt9p031.c | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c index fe3414866a63..1abc86ed2255 100644 --- a/drivers/media/i2c/mt9p031.c +++ b/drivers/media/i2c/mt9p031.c | |||
@@ -16,9 +16,10 @@ | |||
16 | #include <linux/delay.h> | 16 | #include <linux/delay.h> |
17 | #include <linux/device.h> | 17 | #include <linux/device.h> |
18 | #include <linux/gpio.h> | 18 | #include <linux/gpio.h> |
19 | #include <linux/module.h> | ||
20 | #include <linux/i2c.h> | 19 | #include <linux/i2c.h> |
21 | #include <linux/log2.h> | 20 | #include <linux/log2.h> |
21 | #include <linux/module.h> | ||
22 | #include <linux/of_gpio.h> | ||
22 | #include <linux/pm.h> | 23 | #include <linux/pm.h> |
23 | #include <linux/regulator/consumer.h> | 24 | #include <linux/regulator/consumer.h> |
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
@@ -27,6 +28,7 @@ | |||
27 | #include <media/mt9p031.h> | 28 | #include <media/mt9p031.h> |
28 | #include <media/v4l2-ctrls.h> | 29 | #include <media/v4l2-ctrls.h> |
29 | #include <media/v4l2-device.h> | 30 | #include <media/v4l2-device.h> |
31 | #include <media/v4l2-of.h> | ||
30 | #include <media/v4l2-subdev.h> | 32 | #include <media/v4l2-subdev.h> |
31 | 33 | ||
32 | #include "aptina-pll.h" | 34 | #include "aptina-pll.h" |
@@ -927,10 +929,36 @@ static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { | |||
927 | * Driver initialization and probing | 929 | * Driver initialization and probing |
928 | */ | 930 | */ |
929 | 931 | ||
932 | static struct mt9p031_platform_data * | ||
933 | mt9p031_get_pdata(struct i2c_client *client) | ||
934 | { | ||
935 | struct mt9p031_platform_data *pdata; | ||
936 | struct device_node *np; | ||
937 | |||
938 | if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) | ||
939 | return client->dev.platform_data; | ||
940 | |||
941 | np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL); | ||
942 | if (!np) | ||
943 | return NULL; | ||
944 | |||
945 | pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); | ||
946 | if (!pdata) | ||
947 | goto done; | ||
948 | |||
949 | pdata->reset = of_get_named_gpio(client->dev.of_node, "reset-gpios", 0); | ||
950 | of_property_read_u32(np, "input-clock-frequency", &pdata->ext_freq); | ||
951 | of_property_read_u32(np, "pixel-clock-frequency", &pdata->target_freq); | ||
952 | |||
953 | done: | ||
954 | of_node_put(np); | ||
955 | return pdata; | ||
956 | } | ||
957 | |||
930 | static int mt9p031_probe(struct i2c_client *client, | 958 | static int mt9p031_probe(struct i2c_client *client, |
931 | const struct i2c_device_id *did) | 959 | const struct i2c_device_id *did) |
932 | { | 960 | { |
933 | struct mt9p031_platform_data *pdata = client->dev.platform_data; | 961 | struct mt9p031_platform_data *pdata = mt9p031_get_pdata(client); |
934 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | 962 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
935 | struct mt9p031 *mt9p031; | 963 | struct mt9p031 *mt9p031; |
936 | unsigned int i; | 964 | unsigned int i; |
@@ -1069,8 +1097,18 @@ static const struct i2c_device_id mt9p031_id[] = { | |||
1069 | }; | 1097 | }; |
1070 | MODULE_DEVICE_TABLE(i2c, mt9p031_id); | 1098 | MODULE_DEVICE_TABLE(i2c, mt9p031_id); |
1071 | 1099 | ||
1100 | #if IS_ENABLED(CONFIG_OF) | ||
1101 | static const struct of_device_id mt9p031_of_match[] = { | ||
1102 | { .compatible = "aptina,mt9p031", }, | ||
1103 | { .compatible = "aptina,mt9p031m", }, | ||
1104 | { /* sentinel */ }, | ||
1105 | }; | ||
1106 | MODULE_DEVICE_TABLE(of, mt9p031_of_match); | ||
1107 | #endif | ||
1108 | |||
1072 | static struct i2c_driver mt9p031_i2c_driver = { | 1109 | static struct i2c_driver mt9p031_i2c_driver = { |
1073 | .driver = { | 1110 | .driver = { |
1111 | .of_match_table = of_match_ptr(mt9p031_of_match), | ||
1074 | .name = "mt9p031", | 1112 | .name = "mt9p031", |
1075 | }, | 1113 | }, |
1076 | .probe = mt9p031_probe, | 1114 | .probe = mt9p031_probe, |