media: i2c: mt9p031: add OF support
Subsystems (4)
RFC PATCH v2 1/1 media: i2c: mt9p031: add OF support
From: Lad, Prabhakar <[email protected]>
add OF support for the mt9p031 sensor driver. Alongside this patch sorts the header inclusion alphabetically.
---
Changes for v2:
1: Used '-' instead of '_' for device properties.
2: Specified gpio reset pin as phandle in device node.
3: Handle platform data properly even if kernel is compiled with
devicetree support.
4: Used dev_* for messages in drivers instead of pr_*.
5: Changed compatible property to "aptina,mt9p031" and "aptina,mt9p031m". 6: Sorted the header inclusion alphabetically and fixed some minor code nits.
.../devicetree/bindings/media/i2c/mt9p031.txt | 37 ++++++++++++ drivers/media/i2c/mt9p031.c | 62 +++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/media/i2c/mt9p031.txt
Documentation/devicetree/bindings/media/i2c/mt9p031.txt new file +37 -0
@@ -0,0 +1,37 @@ +* Aptina 1/2.5-Inch 5Mp CMOS Digital Image Sensor + +The Aptina MT9P031 is a 1/2.5-inch CMOS active pixel digital image sensor with +an active array size of 2592H x 1944V. It is programmable through a simple +two-wire serial interface. + +Required Properties : +- compatible : value should be either one among the following + (a) "aptina,mt9p031" for mt9p031 sensor + (b) "aptina,mt9p031m" for mt9p031m sensor + +- input-clock-frequency : Input clock frequency. + +- pixel-clock-frequency : Pixel clock frequency. + +Optional Properties : +-gpio-reset: Chip reset GPIO + +Example: + +i2c0@1c22000 { + ... + ... + mt9p031@5d { + compatible = "aptina,mt9p031"; + reg = <0x5d>; + gpio-reset = <&gpio3 30 0>; + + port { + mt9p031_1: endpoint { + input-clock-frequency = <6000000>; + pixel-clock-frequency = <96000000>; + }; + }; + }; + ... +};
drivers/media/i2c/mt9p031.c +60 -2
93 lines not on this page · raw message
Signature · 1 line
1.7.4.1
Quoted 104 lines · Prabhakar Lad
From: Lad, Prabhakar <[email protected]>
add OF support for the mt9p031 sensor driver. Alongside this patch sorts the header inclusion alphabetically.
Signed-off-by Lad, Prabhakar <[email protected]>Cc Hans Verkuil <[email protected]>Cc Laurent Pinchart <[email protected]>Cc Mauro Carvalho Chehab <[email protected]>Cc Guennadi Liakhovetski <[email protected]>Cc Sylwester Nawrocki <[email protected]>Cc Sakari Ailus <[email protected]>Cc Grant Likely <[email protected]>Cc Sascha Hauer <[email protected]>Cc Rob Herring <[email protected]>Cc Rob Landley <[email protected]>---
Changes for v2:
1: Used '-' instead of '_' for device properties.
2: Specified gpio reset pin as phandle in device node.
3: Handle platform data properly even if kernel is compiled with
devicetree support.
4: Used dev_* for messages in drivers instead of pr_*.
5: Changed compatible property to "aptina,mt9p031" and "aptina,mt9p031m". 6: Sorted the header inclusion alphabetically and fixed some minor code nits..../devicetree/bindings/media/i2c/mt9p031.txt | 37 ++++++++++++ drivers/media/i2c/mt9p031.c | 62 +++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/media/i2c/mt9p031.txtDocumentation/devicetree/bindings/media/i2c/mt9p031.txt new file +37
-0@@ -0,0 +1,37 @@ +* Aptina 1/2.5-Inch 5Mp CMOS Digital Image Sensor + +The Aptina MT9P031 is a 1/2.5-inch CMOS active pixel digital image sensor with +an active array size of 2592H x 1944V. It is programmable through a simple +two-wire serial interface. + +Required Properties : +- compatible : value should be either one among the following + (a) "aptina,mt9p031" for mt9p031 sensor + (b) "aptina,mt9p031m" for mt9p031m sensor + +- input-clock-frequency : Input clock frequency. + +- pixel-clock-frequency : Pixel clock frequency. + +Optional Properties : +-gpio-reset: Chip reset GPIO + +Example: + +i2c0@1c22000 { + ... + ... + mt9p031@5d { + compatible = "aptina,mt9p031"; + reg = <0x5d>; + gpio-reset = <&gpio3 30 0>; + + port { + mt9p031_1: endpoint { + input-clock-frequency = <6000000>; + pixel-clock-frequency = <96000000>; + }; + }; + }; + ... +};drivers/media/i2c/mt9p031.c +4
-1@@ -16,9 +16,11 @@#include <linux/delay.h> #include <linux/device.h> #include <linux/gpio.h> -#include <linux/module.h> #include <linux/i2c.h> #include <linux/log2.h> +#include <linux/module.h> +#include <linux/of_device.h> +#include <linux/of_gpio.h> #include <linux/pm.h> #include <linux/regulator/consumer.h> #include <linux/slab.h> @@ -28,6 +30,7 @@#include <media/v4l2-chip-ident.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> +#include <media/v4l2-of.h> #include <media/v4l2-subdev.h> #include "aptina-pll.h"
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 939
Quoted 9 lines
drivers/media/i2c/mt9p031.c +6
-0@@ -928,10 +931,57 @@ static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = {* Driver initialization and probing */ +#if defined(CONFIG_OF ) +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) + +{ +if (client->dev.of_node) {
By inverting the logic here and returning immediately you can safe an indention level for the bulk of this function.
Quoted 4 lines
drivers/media/i2c/mt9p031.c +4
-0+struct device_node *np; +struct mt9p031_platform_data *pdata; + + np =v4l2_of_get_next_endpoint (client->dev.of_node,NULL );
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 953
Quoted 10 lines
drivers/media/i2c/mt9p031.c +10
-0+if (!np) +return NULL ; + + pdata =devm_kzalloc (&client->dev, +sizeof (struct mt9p031_platform_data ), +GFP_KERNEL ); +if (!pdata) { +dev_err (&client->dev, +"mt9p031 failed allocate memeory\n" ); +return NULL ;
s/memeory/memory/
Better drop this message completely. If you are really out of memory you'll notice it quite fast anyway.
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 966
Quoted 13 lines
drivers/media/i2c/mt9p031.c +13
-0+ } + pdata->reset =of_get_named_gpio (client->dev.of_node, +"gpio-reset" ,0 ); +if (!gpio_is_valid (pdata->reset)) + pdata->reset =-1 ; + +if (of_property_read_u32 (np,"input-clock-frequency" , + &pdata->ext_freq)) +return NULL ; + +if (of_property_read_u32 (np,"pixel-clock-frequency" , + &pdata->target_freq)) +return NULL ;
returning NULL here means that when these properties are missing the driver bails out with the message "No platform data\n" which is not very helpful for users. How about just ignoring this here and return pdata? The driver will probably print a more useful message later when it notices that the clock params are invalid.
Quoted 23 lines
drivers/media/i2c/mt9p031.c +15
-1+ + return pdata; + } + +return client->dev.platform_data; +} +#else +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) +{ +return client->dev.platform_data; +} +#endif +static int mt9p031_probe (struct i2c_client *client,const struct i2c_device_id *did) { -struct mt9p031_platform_data *pdata = client->dev.platform_data; +struct mt9p031_platform_data *pdata =mt9p031_get_pdata (client);struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct mt9p031 *mt9p031;unsigned int i;
drivers/media/i2c/mt9p031.c static const struct i2c_device_id mt9p031_id[] = { · line 1127
Quoted 8 lines
drivers/media/i2c/mt9p031.c +5
-0@@ -1070,8 +1120,16 @@ static const struct i2c_device_id mt9p031_id[] = { };MODULE_DEVICE_TABLE (i2c, mt9p031_id); +static const struct of_device_id mt9p031_of_match[] = { + { .compatible ="aptina,mt9p031" , }, + { .compatible ="aptina,mt9p031m" , }, + {}, +};
I would have expected something like:
static const struct of_device_id mt9p031_of_match[] = {
{
.compatible = "aptina,mt9p031-sensor",
.data = (void *)MT9P031_MODEL_COLOR,
}, {
.compatible = "aptina,mt9p031m-sensor",
.data = (void *)MT9P031_MODEL_MONOCHROME,
}, {
/* sentinel */
},
};of_id = of_match_device(mt9p031_of_match, &client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;
To handle monochrome sensors.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Sascha,
Thanks for the quick review.
Quoted 5 lines · Sascha Hauer
Quoted 4 lines · Prabhakar Lad
From: Lad, Prabhakar <[email protected]>
add OF support for the mt9p031 sensor driver. Alongside this patch sorts the header inclusion alphabetically.
[Snip]
Quoted 10 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 939
Quoted 6 lines
drivers/media/i2c/mt9p031.c +6
-0+#if defined(CONFIG_OF ) +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) + +{ +if (client->dev.of_node) {By inverting the logic here and returning immediately you can safe an indention level for the bulk of this function.
OK
Quoted 17 lines
Quoted 4 lines
drivers/media/i2c/mt9p031.c +4
-0+struct device_node *np; +struct mt9p031_platform_data *pdata; + + np =v4l2_of_get_next_endpoint (client->dev.of_node,NULL );drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 953
Quoted 10 lines
drivers/media/i2c/mt9p031.c +10
-0+if (!np) +return NULL ; + + pdata =devm_kzalloc (&client->dev, +sizeof (struct mt9p031_platform_data ), +GFP_KERNEL ); +if (!pdata) { +dev_err (&client->dev, +"mt9p031 failed allocate memeory\n" ); +return NULL ;s/memeory/memory/
Quoted 3 lines
Better drop this message completely. If you are really out of memory you'll notice it quite fast anyway.
alright I'll drop the message.
Quoted 11 lines
Quoted 11 lines
drivers/media/i2c/mt9p031.c +11
-0+ } + pdata->reset =of_get_named_gpio (client->dev.of_node, +"gpio-reset" ,0 ); +if (!gpio_is_valid (pdata->reset)) + pdata->reset =-1 ; + +if (of_property_read_u32 (np,"input-clock-frequency" , + &pdata->ext_freq)) +return NULL ; + + if (of_property_read_u32(np, "pixel-clock-frequency",
Quoted 9 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 966
Quoted 2 lines
drivers/media/i2c/mt9p031.c +2
-0+ &pdata->target_freq)) +return NULL ;returning NULL here means that when these properties are missing the driver bails out with the message "No platform data\n" which is not very helpful for users. How about just ignoring this here and return pdata? The driver will probably print a more useful message later when it notices that the clock params are invalid.
Yes would be good idea of not returning NULL.
Quoted 46 lines
Quoted 23 lines
drivers/media/i2c/mt9p031.c +15
-1+ + return pdata; + } + +return client->dev.platform_data; +} +#else +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) +{ +return client->dev.platform_data; +} +#endif +static int mt9p031_probe (struct i2c_client *client,const struct i2c_device_id *did) { -struct mt9p031_platform_data *pdata = client->dev.platform_data; +struct mt9p031_platform_data *pdata =mt9p031_get_pdata (client);struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct mt9p031 *mt9p031;unsigned int i;drivers/media/i2c/mt9p031.c static const struct i2c_device_id mt9p031_id[] = { · line 1127
Quoted 8 lines
drivers/media/i2c/mt9p031.c +5
-0@@ -1070,8 +1120,16 @@ static const struct i2c_device_id mt9p031_id[] = { };MODULE_DEVICE_TABLE (i2c, mt9p031_id); +static const struct of_device_id mt9p031_of_match[] = { + { .compatible ="aptina,mt9p031" , }, + { .compatible ="aptina,mt9p031m" , }, + {}, +};I would have expected something like:
static const struct of_device_id mt9p031_of_match[] = { { .compatible = "aptina,mt9p031-sensor", .data = (void *)MT9P031_MODEL_COLOR, }, { .compatible = "aptina,mt9p031m-sensor", .data = (void *)MT9P031_MODEL_MONOCHROME, }, { /* sentinel */ }, };
Quoted 6 lines
of_id = of_match_device(mt9p031_of_match, &client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;To handle monochrome sensors.
OK will do the same.
Regards,
--Prabhakar Lad
Laurent Pinchart
maintainerHi Prabhakar,
Thank you for the patch.
Quoted 4 lines · On Thursday 02 May 2013 12:34:25 Prabhakar Lad wrote:
Quoted 3 lines · Sascha Hauer
Quoted 2 lines · Prabhakar Lad
From: Lad, Prabhakar <[email protected]>
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
add OF support for the mt9p031 sensor driver. Alongside this patch sorts the header inclusion alphabetically.
[Snip]
Quoted 3 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 936
Quoted 3 lines
drivers/media/i2c/mt9p031.c +3
-0+#if defined(CONFIG_OF ) +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client)
Please align this line on the left.
Quoted 25 lines
Quoted 5 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 939
Quoted 2 lines
drivers/media/i2c/mt9p031.c +2
-0+{ +if (client->dev.of_node) {By inverting the logic here and returning immediately you can safe an indention level for the bulk of this function.
OK
Quoted 17 lines
Quoted 4 lines
drivers/media/i2c/mt9p031.c +4
-0+struct device_node *np; +struct mt9p031_platform_data *pdata; + + np =v4l2_of_get_next_endpoint (client->dev.of_node,NULL );drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 953
Quoted 10 lines
drivers/media/i2c/mt9p031.c +10
-0+if (!np) +return NULL ; + + pdata =devm_kzalloc (&client->dev, +sizeof (struct mt9p031_platform_data ), +GFP_KERNEL ); +if (!pdata) { +dev_err (&client->dev, +"mt9p031 failed allocate memeory\n" ); +return NULL ;s/memeory/memory/
Quoted 10 lines
Quoted 2 lines
Better drop this message completely. If you are really out of memory you'll notice it quite fast anyway.
alright I'll drop the message.
Quoted 5 lines
Quoted 5 lines
drivers/media/i2c/mt9p031.c +5
-0+ } + pdata->reset =of_get_named_gpio (client->dev.of_node, +"gpio-reset" ,0 ); +if (!gpio_is_valid (pdata->reset)) + pdata->reset =-1 ;
I've just sent a patch that converts the manual -1 checks in the driver to gpio_is_valid(). You can thus drop these two lines.
Quoted 65 lines
Quoted 8 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 966
Quoted 7 lines
drivers/media/i2c/mt9p031.c +7
-0+if (of_property_read_u32 (np,"input-clock-frequency" , + &pdata->ext_freq)) +return NULL ; + +if (of_property_read_u32 (np,"pixel-clock-frequency" , + &pdata->target_freq)) +return NULL ;Quoted 5 lines
returning NULL here means that when these properties are missing the driver bails out with the message "No platform data\n" which is not very helpful for users. How about just ignoring this here and return pdata? The driver will probably print a more useful message later when it notices that the clock params are invalid.
Yes would be good idea of not returning NULL.
Quoted 49 lines
Quoted 25 lines
drivers/media/i2c/mt9p031.c +15
-1+ + return pdata; + } + +return client->dev.platform_data; +} +#else +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) +{ +return client->dev.platform_data; +} +#endif +static int mt9p031_probe (struct i2c_client *client,const struct i2c_device_id *did) { -struct mt9p031_platform_data *pdata = client->dev.platform_data; +struct mt9p031_platform_data *pdata =mt9p031_get_pdata (client);struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct mt9p031 *mt9p031;unsigned int i;drivers/media/i2c/mt9p031.c static const struct i2c_device_id mt9p031_id[] = { · line 1128
Quoted 9 lines
drivers/media/i2c/mt9p031.c +5
-0@@ -1070,8 +1120,16 @@ static const struct i2c_device_id mt9p031_id[] = { };MODULE_DEVICE_TABLE (i2c, mt9p031_id); +static const struct of_device_id mt9p031_of_match[] = { + { .compatible ="aptina,mt9p031" , }, + { .compatible ="aptina,mt9p031m" , }, + {}, +};I would have expected something like:
static const struct of_device_id mt9p031_of_match[] = { { .compatible = "aptina,mt9p031-sensor", .data = (void *)MT9P031_MODEL_COLOR, }, { .compatible = "aptina,mt9p031m-sensor", .data = (void *)MT9P031_MODEL_MONOCHROME, }, { /* sentinel */ }, };
Quoted 7 lines
Quoted 5 lines
of_id = of_match_device(mt9p031_of_match, &client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;To handle monochrome sensors.
OK will do the same.
And please guard the table with #ifdef CONFIG_OF.
Signature · 3 lines
Regards, Laurent Pinchart
Hi Laurent,
Thanks for the review.
Quoted 12 lines · Laurent Pinchart
Hi Prabhakar,
Thank you for the patch.
Quoted 7 lines · On Thursday 02 May 2013 12:34:25 Prabhakar Lad wrote:
Quoted 5 lines · Sascha Hauer
Quoted 4 lines · Prabhakar Lad
From: Lad, Prabhakar <[email protected]>
add OF support for the mt9p031 sensor driver. Alongside this patch sorts the header inclusion alphabetically.
Quoted 8 lines
Quoted 5 lines
[Snip]
Quoted 3 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 936
Quoted 3 lines
drivers/media/i2c/mt9p031.c +3
-0+#if defined(CONFIG_OF ) +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client)Please align this line on the left.
OK
Quoted 30 lines
Quoted 30 lines
Quoted 5 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 939
Quoted 2 lines
drivers/media/i2c/mt9p031.c +2
-0+{ +if (client->dev.of_node) {By inverting the logic here and returning immediately you can safe an indention level for the bulk of this function.
OK
Quoted 17 lines
Quoted 4 lines
drivers/media/i2c/mt9p031.c +4
-0+struct device_node *np; +struct mt9p031_platform_data *pdata; + + np =v4l2_of_get_next_endpoint (client->dev.of_node,NULL );drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 953
Quoted 10 lines
drivers/media/i2c/mt9p031.c +10
-0+if (!np) +return NULL ; + + pdata =devm_kzalloc (&client->dev, +sizeof (struct mt9p031_platform_data ), +GFP_KERNEL ); +if (!pdata) { +dev_err (&client->dev, +"mt9p031 failed allocate memeory\n" ); +return NULL ;s/memeory/memory/
Quoted 2 lines
Better drop this message completely. If you are really out of memory you'll notice it quite fast anyway.
alright I'll drop the message.
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 958
Quoted 5 lines
drivers/media/i2c/mt9p031.c +5
-0+ } + pdata->reset =of_get_named_gpio (client->dev.of_node, +"gpio-reset" ,0 ); +if (!gpio_is_valid (pdata->reset)) + pdata->reset =-1 ;I've just sent a patch that converts the manual -1 checks in the driver to
gpio_is_valid(). You can thus drop these two lines.
OK I'll drop this check.
Quoted 69 lines
Quoted 69 lines
Quoted 8 lines
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 966
Quoted 7 lines
drivers/media/i2c/mt9p031.c +7
-0+if (of_property_read_u32 (np,"input-clock-frequency" , + &pdata->ext_freq)) +return NULL ; + +if (of_property_read_u32 (np,"pixel-clock-frequency" , + &pdata->target_freq)) +return NULL ;Quoted 5 lines
returning NULL here means that when these properties are missing the driver bails out with the message "No platform data\n" which is not very helpful for users. How about just ignoring this here and return pdata? The driver will probably print a more useful message later when it notices that the clock params are invalid.
Yes would be good idea of not returning NULL.
Quoted 53 lines
Quoted 25 lines
drivers/media/i2c/mt9p031.c +15
-1+ + return pdata; + } + +return client->dev.platform_data; +} +#else +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) +{ +return client->dev.platform_data; +} +#endif +static int mt9p031_probe (struct i2c_client *client,const struct i2c_device_id *did) { -struct mt9p031_platform_data *pdata = client->dev.platform_data; +struct mt9p031_platform_data *pdata =mt9p031_get_pdata (client);struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);struct mt9p031 *mt9p031;unsigned int i;drivers/media/i2c/mt9p031.c static const struct i2c_device_id mt9p031_id[] = { · line 1128
Quoted 9 lines
drivers/media/i2c/mt9p031.c +5
-0@@ -1070,8 +1120,16 @@ static const struct i2c_device_id mt9p031_id[] = { };MODULE_DEVICE_TABLE (i2c, mt9p031_id); +static const struct of_device_id mt9p031_of_match[] = { + { .compatible ="aptina,mt9p031" , }, + { .compatible ="aptina,mt9p031m" , }, + {}, +};I would have expected something like:
static const struct of_device_id mt9p031_of_match[] = { { .compatible = "aptina,mt9p031-sensor", .data = (void *)MT9P031_MODEL_COLOR, }, { .compatible = "aptina,mt9p031m-sensor", .data = (void *)MT9P031_MODEL_MONOCHROME, }, { /* sentinel */ }, };of_id = of_match_device(mt9p031_of_match, &client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
To handle monochrome sensors.
OK will do the same.
And please guard the table with #ifdef
CONFIG_OF.
But guarding the table #ifdef CONFIG_OF would cause compilation failure for below code when CONFIG_OF is undefined in probe
of_id = of_match_device(of_match_ptr(mt9p031_of_match),
&client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;
and also in mt9p031_i2c_driver structure,of_match_table = of_match_ptr(mt9p031_of_match),
which force me to define mt9p031_of_match to NULL when CONFIG_OF is undefined
Regards,
--Prabhakar Lad
Laurent Pinchart
maintainerHi Prabhakar,
Quoted 8 lines · On Thursday 02 May 2013 18:48:37 Prabhakar Lad wrote:
Quoted 7 lines · Laurent Pinchart
Quoted 6 lines · On Thursday 02 May 2013 12:34:25 Prabhakar Lad wrote:
Quoted 5 lines · Sascha Hauer
Quoted 4 lines · Prabhakar Lad
From: Lad, Prabhakar <[email protected]>
add OF support for the mt9p031 sensor driver. Alongside this patch sorts the header inclusion alphabetically.
[snip]
Quoted 35 lines
Quoted 29 lines
Quoted 29 lines
Quoted 29 lines
drivers/media/i2c/mt9p031.c static const struct i2c_device_id mt9p031_id[] · line 1128
Quoted 10 lines
drivers/media/i2c/mt9p031.c +5
-0@@ -1070,8 +1120,16 @@ static const struct i2c_device_id mt9p031_id[] = { };MODULE_DEVICE_TABLE (i2c, mt9p031_id); +static const struct of_device_id mt9p031_of_match[] = { + { .compatible ="aptina,mt9p031" , }, + { .compatible ="aptina,mt9p031m" , }, + {}, +};I would have expected something like:
static const struct of_device_id mt9p031_of_match[] = { { .compatible = "aptina,mt9p031-sensor", .data = (void *)MT9P031_MODEL_COLOR, }, { .compatible = "aptina,mt9p031m-sensor", .data = (void *)MT9P031_MODEL_MONOCHROME, }, { /* sentinel */ }, };of_id = of_match_device(mt9p031_of_match, &client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;Quoted 5 lines
Quoted 3 lines
Quoted 1 line
To handle monochrome sensors.
OK will do the same.
And please guard the table with #ifdef
CONFIG_OF.
Quoted 7 lines
But guarding the table #ifdef
CONFIG_OFwould cause compilation failure for below code whenCONFIG_OFis undefined in probe
of_id= of_match_device(of_match_ptr(mt9p031_of_match),&client->dev); if (of_id) mt9p031->model = (enum mt9p031_model)of_id->data;
You could guard the above code with an #ifdef CONFIG_OF as well.
Quoted 5 lines
and also in
mt9p031_i2c_driverstructure,of_match_table=of_match_ptr(mt9p031_of_match),which force me to define
mt9p031_of_matchto NULL whenCONFIG_OFis undefined
of_match_ptr is defined as NULL when CONFIG_OF is disabled.
Signature · 3 lines
Regards, Laurent Pinchart
Quoted 9 lines · On Thursday 02 May 2013 08:55:18 Sascha Hauer wrote:
drivers/media/i2c/mt9p031.c static const struct v4l2_subdev_internal_ops mt9p031_subdev_internal_ops = { · line 939
Quoted 6 lines
drivers/media/i2c/mt9p031.c +6
-0+#if defined(CONFIG_OF ) +static struct mt9p031_platform_data * +mt9p031_get_pdata (struct i2c_client *client) + +{ +if (client->dev.of_node) {By inverting the logic here and returning immediately you can safe an indention level for the bulk of this function.
Right, also make this
if (!IS_ENABLED(CONFIG_OF) || !client->dev.of_node) return client->dev.platform_data;
Then the rest of the function gets discarded by the compiler when CONFIG_OF is not set, and you can kill the #ifdef around the function.
Arnd