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

[media] v4l: mt9v032: Add OF support

Parse DT properties into a platform data structure when a DT node is
available.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Laurent Pinchart and committed by
Mauro Carvalho Chehab
f2272e13 5888f9df

+108 -1
+39
Documentation/devicetree/bindings/media/i2c/mt9v032.txt
··· 1 + * Aptina 1/3-Inch WVGA CMOS Digital Image Sensor 2 + 3 + The Aptina MT9V032 is a 1/3-inch CMOS active pixel digital image sensor with 4 + an active array size of 752H x 480V. It is programmable through a simple 5 + two-wire serial interface. 6 + 7 + Required Properties: 8 + 9 + - compatible: value should be either one among the following 10 + (a) "aptina,mt9v022" for MT9V022 color sensor 11 + (b) "aptina,mt9v022m" for MT9V022 monochrome sensor 12 + (c) "aptina,mt9v024" for MT9V024 color sensor 13 + (d) "aptina,mt9v024m" for MT9V024 monochrome sensor 14 + (e) "aptina,mt9v032" for MT9V032 color sensor 15 + (f) "aptina,mt9v032m" for MT9V032 monochrome sensor 16 + (g) "aptina,mt9v034" for MT9V034 color sensor 17 + (h) "aptina,mt9v034m" for MT9V034 monochrome sensor 18 + 19 + Optional Properties: 20 + 21 + - link-frequencies: List of allowed link frequencies in Hz. Each frequency is 22 + expressed as a 64-bit big-endian integer. 23 + 24 + For further reading on port node refer to 25 + Documentation/devicetree/bindings/media/video-interfaces.txt. 26 + 27 + Example: 28 + 29 + mt9v032@5c { 30 + compatible = "aptina,mt9v032"; 31 + reg = <0x5c>; 32 + 33 + port { 34 + mt9v032_out: endpoint { 35 + link-frequencies = /bits/ 64 36 + <13000000 26600000 27000000>; 37 + }; 38 + }; 39 + };
+1
MAINTAINERS
··· 6535 6535 L: linux-media@vger.kernel.org 6536 6536 T: git git://linuxtv.org/media_tree.git 6537 6537 S: Maintained 6538 + F: Documentation/devicetree/bindings/media/i2c/mt9v032.txt 6538 6539 F: drivers/media/i2c/mt9v032.c 6539 6540 F: include/media/mt9v032.h 6540 6541
+68 -1
drivers/media/i2c/mt9v032.c
··· 17 17 #include <linux/i2c.h> 18 18 #include <linux/log2.h> 19 19 #include <linux/mutex.h> 20 + #include <linux/of.h> 21 + #include <linux/of_gpio.h> 20 22 #include <linux/regmap.h> 21 23 #include <linux/slab.h> 22 24 #include <linux/videodev2.h> ··· 28 26 #include <media/mt9v032.h> 29 27 #include <media/v4l2-ctrls.h> 30 28 #include <media/v4l2-device.h> 29 + #include <media/v4l2-of.h> 31 30 #include <media/v4l2-subdev.h> 32 31 33 32 /* The first four rows are black rows. The active area spans 753x481 pixels. */ ··· 879 876 * Driver initialization and probing 880 877 */ 881 878 879 + static struct mt9v032_platform_data * 880 + mt9v032_get_pdata(struct i2c_client *client) 881 + { 882 + struct mt9v032_platform_data *pdata; 883 + struct v4l2_of_endpoint endpoint; 884 + struct device_node *np; 885 + struct property *prop; 886 + 887 + if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) 888 + return client->dev.platform_data; 889 + 890 + np = of_graph_get_next_endpoint(client->dev.of_node, NULL); 891 + if (!np) 892 + return NULL; 893 + 894 + if (v4l2_of_parse_endpoint(np, &endpoint) < 0) 895 + goto done; 896 + 897 + pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL); 898 + if (!pdata) 899 + goto done; 900 + 901 + prop = of_find_property(np, "link-frequencies", NULL); 902 + if (prop) { 903 + u64 *link_freqs; 904 + size_t size = prop->length / sizeof(*link_freqs); 905 + 906 + link_freqs = devm_kcalloc(&client->dev, size, 907 + sizeof(*link_freqs), GFP_KERNEL); 908 + if (!link_freqs) 909 + goto done; 910 + 911 + if (of_property_read_u64_array(np, "link-frequencies", 912 + link_freqs, size) < 0) 913 + goto done; 914 + 915 + pdata->link_freqs = link_freqs; 916 + pdata->link_def_freq = link_freqs[0]; 917 + } 918 + 919 + pdata->clk_pol = !!(endpoint.bus.parallel.flags & 920 + V4L2_MBUS_PCLK_SAMPLE_RISING); 921 + 922 + done: 923 + of_node_put(np); 924 + return pdata; 925 + } 926 + 882 927 static int mt9v032_probe(struct i2c_client *client, 883 928 const struct i2c_device_id *did) 884 929 { 885 - struct mt9v032_platform_data *pdata = client->dev.platform_data; 930 + struct mt9v032_platform_data *pdata = mt9v032_get_pdata(client); 886 931 struct mt9v032 *mt9v032; 887 932 unsigned int i; 888 933 int ret; ··· 1088 1037 }; 1089 1038 MODULE_DEVICE_TABLE(i2c, mt9v032_id); 1090 1039 1040 + #if IS_ENABLED(CONFIG_OF) 1041 + static const struct of_device_id mt9v032_of_match[] = { 1042 + { .compatible = "aptina,mt9v022" }, 1043 + { .compatible = "aptina,mt9v022m" }, 1044 + { .compatible = "aptina,mt9v024" }, 1045 + { .compatible = "aptina,mt9v024m" }, 1046 + { .compatible = "aptina,mt9v032" }, 1047 + { .compatible = "aptina,mt9v032m" }, 1048 + { .compatible = "aptina,mt9v034" }, 1049 + { .compatible = "aptina,mt9v034m" }, 1050 + { /* Sentinel */ } 1051 + }; 1052 + MODULE_DEVICE_TABLE(of, mt9v032_of_match); 1053 + #endif 1054 + 1091 1055 static struct i2c_driver mt9v032_driver = { 1092 1056 .driver = { 1093 1057 .name = "mt9v032", 1058 + .of_match_table = of_match_ptr(mt9v032_of_match), 1094 1059 }, 1095 1060 .probe = mt9v032_probe, 1096 1061 .remove = mt9v032_remove,