Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Lad, Prabhakar and committed by
Mauro Carvalho Chehab
8d4da37c 3080f8c7

+80 -2
+40
Documentation/devicetree/bindings/media/i2c/mt9p031.txt
··· 1 + * Aptina 1/2.5-Inch 5Mp CMOS Digital Image Sensor 2 + 3 + The Aptina MT9P031 is a 1/2.5-inch CMOS active pixel digital image sensor with 4 + an active array size of 2592H x 1944V. It is programmable through a simple 5 + two-wire serial interface. 6 + 7 + Required 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 + 16 + Optional Properties: 17 + - reset-gpios: Chip reset GPIO 18 + 19 + For further reading on port node refer to 20 + Documentation/devicetree/bindings/media/video-interfaces.txt. 21 + 22 + Example: 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 + };
+40 -2
drivers/media/i2c/mt9p031.c
··· 16 16 #include <linux/delay.h> 17 17 #include <linux/device.h> 18 18 #include <linux/gpio.h> 19 - #include <linux/module.h> 20 19 #include <linux/i2c.h> 21 20 #include <linux/log2.h> 21 + #include <linux/module.h> 22 + #include <linux/of_gpio.h> 22 23 #include <linux/pm.h> 23 24 #include <linux/regulator/consumer.h> 24 25 #include <linux/slab.h> ··· 28 27 #include <media/mt9p031.h> 29 28 #include <media/v4l2-ctrls.h> 30 29 #include <media/v4l2-device.h> 30 + #include <media/v4l2-of.h> 31 31 #include <media/v4l2-subdev.h> 32 32 33 33 #include "aptina-pll.h" ··· 929 927 * Driver initialization and probing 930 928 */ 931 929 930 + static struct mt9p031_platform_data * 931 + mt9p031_get_pdata(struct i2c_client *client) 932 + { 933 + struct mt9p031_platform_data *pdata; 934 + struct device_node *np; 935 + 936 + if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) 937 + return client->dev.platform_data; 938 + 939 + np = v4l2_of_get_next_endpoint(client->dev.of_node, NULL); 940 + if (!np) 941 + return NULL; 942 + 943 + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); 944 + if (!pdata) 945 + goto done; 946 + 947 + pdata->reset = of_get_named_gpio(client->dev.of_node, "reset-gpios", 0); 948 + of_property_read_u32(np, "input-clock-frequency", &pdata->ext_freq); 949 + of_property_read_u32(np, "pixel-clock-frequency", &pdata->target_freq); 950 + 951 + done: 952 + of_node_put(np); 953 + return pdata; 954 + } 955 + 932 956 static int mt9p031_probe(struct i2c_client *client, 933 957 const struct i2c_device_id *did) 934 958 { 935 - struct mt9p031_platform_data *pdata = client->dev.platform_data; 959 + struct mt9p031_platform_data *pdata = mt9p031_get_pdata(client); 936 960 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 937 961 struct mt9p031 *mt9p031; 938 962 unsigned int i; ··· 1097 1069 }; 1098 1070 MODULE_DEVICE_TABLE(i2c, mt9p031_id); 1099 1071 1072 + #if IS_ENABLED(CONFIG_OF) 1073 + static const struct of_device_id mt9p031_of_match[] = { 1074 + { .compatible = "aptina,mt9p031", }, 1075 + { .compatible = "aptina,mt9p031m", }, 1076 + { /* sentinel */ }, 1077 + }; 1078 + MODULE_DEVICE_TABLE(of, mt9p031_of_match); 1079 + #endif 1080 + 1100 1081 static struct i2c_driver mt9p031_i2c_driver = { 1101 1082 .driver = { 1083 + .of_match_table = of_match_ptr(mt9p031_of_match), 1102 1084 .name = "mt9p031", 1103 1085 }, 1104 1086 .probe = mt9p031_probe,