aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/devicetree/bindings/media/i2c/mt9p031.txt40
-rw-r--r--drivers/media/i2c/mt9p031.c42
2 files changed, 80 insertions, 2 deletions
diff --git a/Documentation/devicetree/bindings/media/i2c/mt9p031.txt b/Documentation/devicetree/bindings/media/i2c/mt9p031.txt
new file mode 100644
index 000000000000..cb60443ff78f
--- /dev/null
+++ b/Documentation/devicetree/bindings/media/i2c/mt9p031.txt
@@ -0,0 +1,40 @@
1* Aptina 1/2.5-Inch 5Mp CMOS Digital Image Sensor
2
3The Aptina MT9P031 is a 1/2.5-inch CMOS active pixel digital image sensor with
4an active array size of 2592H x 1944V. It is programmable through a simple
5two-wire serial interface.
6
7Required Properties:
8- compatible: value should be either one among the following
9 (a) "aptina,mt9p031" for mt9p031 sensor
10 (b) "aptina,mt9p031m" for mt9p031m sensor
11
12- input-clock-frequency: Input clock frequency.
13
14- pixel-clock-frequency: Pixel clock frequency.
15
16Optional Properties:
17- reset-gpios: Chip reset GPIO
18
19For further reading on port node refer to
20Documentation/devicetree/bindings/media/video-interfaces.txt.
21
22Example:
23
24 i2c0@1c22000 {
25 ...
26 ...
27 mt9p031@5d {
28 compatible = "aptina,mt9p031";
29 reg = <0x5d>;
30 reset-gpios = <&gpio3 30 0>;
31
32 port {
33 mt9p031_1: endpoint {
34 input-clock-frequency = <6000000>;
35 pixel-clock-frequency = <96000000>;
36 };
37 };
38 };
39 ...
40 };
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
932static struct mt9p031_platform_data *
933mt9p031_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
953done:
954 of_node_put(np);
955 return pdata;
956}
957
930static int mt9p031_probe(struct i2c_client *client, 958static 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};
1070MODULE_DEVICE_TABLE(i2c, mt9p031_id); 1098MODULE_DEVICE_TABLE(i2c, mt9p031_id);
1071 1099
1100#if IS_ENABLED(CONFIG_OF)
1101static const struct of_device_id mt9p031_of_match[] = {
1102 { .compatible = "aptina,mt9p031", },
1103 { .compatible = "aptina,mt9p031m", },
1104 { /* sentinel */ },
1105};
1106MODULE_DEVICE_TABLE(of, mt9p031_of_match);
1107#endif
1108
1072static struct i2c_driver mt9p031_i2c_driver = { 1109static 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,