media: ov2640: add device tree support
Subsystems (2)
cover media: ov2640: add device tree support
This patch series add device tree support for ov2640. And also add the document for the devicetree properties.
Josh Wu (4):
media: ov2640: add async probe function
media: ov2640: add primary dt support
media: ov2640: add a master clock for sensor
media: ov2640: dt: add the device tree binding document
.../devicetree/bindings/media/i2c/ov2640.txt | 43 ++++++ drivers/media/i2c/soc_camera/ov2640.c | 151 ++++++++++++++++++--- 2 files changed, 178 insertions(+), 16 deletions(-) create mode 100644 Documentation/devicetree/bindings/media/i2c/ov2640.txt
Signature · 1 line
1.9.1
PATCH 1/4 media: ov2640: add async probe function
To support async probe for ov2640, we need remove the code to get 'mclk' in ov2640_probe() function. oterwise, if soc_camera host is not probed in the moment, then we will fail to get 'mclk' and quit the ov2640_probe() function.
So in this patch, we move such 'mclk' getting code to ov2640_s_power() function. That make ov2640 survive, as we can pass a NULL (priv-clk) to soc_camera_set_power() function.
And if soc_camera host is probed, the when ov2640_s_power() is called, then we can get the 'mclk' and that make us enable/disable soc_camera host's clock as well.
--- drivers/media/i2c/soc_camera/ov2640.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-)
drivers/media/i2c/soc_camera/ov2640.c +21 -10
@@ -739,6 +739,15 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on)struct i2c_client *client =v4l2_get_subdevdata (sd);struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client);struct ov2640_priv *priv =to_ov2640 (client); +struct v4l2_clk *clk; + +if (!priv->clk) { + clk =v4l2_clk_get (&client->dev,"mclk" ); +if (IS_ERR (clk)) +dev_warn (&client->dev,"Cannot get the mclk. maybe soc-camera host is not probed yet.\n" ); +else + priv->clk = clk; + }return soc_camera_set_power (&client->dev, ssdd, priv->clk, on); }
@@ -1078,21 +1087,21 @@ static int ov2640_probe(struct i2c_client *client,if (priv->hdl.error)return priv->hdl.error; - priv->clk =v4l2_clk_get (&client->dev,"mclk" ); -if (IS_ERR (priv->clk)) { - ret =PTR_ERR (priv->clk); - goto eclkget; - } - ret =ov2640_video_probe (client);if (ret) { -v4l2_clk_put (priv->clk); -eclkget: -v4l2_ctrl_handler_free (&priv->hdl); + goto evideoprobe; }else {dev_info (&adapter->dev,"OV2640 Probed\n" ); } + ret =v4l2_async_register_subdev (&priv->subdev); +if (ret <0 ) + goto evideoprobe; + +return 0 ; + +evideoprobe: +v4l2_ctrl_handler_free (&priv->hdl);return ret; }
@@ -1100,7 +1109,9 @@ static int ov2640_remove(struct i2c_client *client) {struct ov2640_priv *priv =to_ov2640 (client); -v4l2_clk_put (priv->clk); +v4l2_async_unregister_subdev (&priv->subdev); +if (priv->clk) +v4l2_clk_put (priv->clk);v4l2_device_unregister_subdev (&priv->subdev);v4l2_ctrl_handler_free (&priv->hdl);return 0 ;
Signature · 1 line
1.9.1
PATCH 2/4 media: ov2640: add primary dt support
In reply to Josh WuAdd device tree support for ov2640.
--- drivers/media/i2c/soc_camera/ov2640.c | 95 ++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-)
drivers/media/i2c/soc_camera/ov2640.c +89 -6
@@ -18,6 +18,8 @@#include <linux/i2c.h> #include <linux/slab.h> #include <linux/delay.h> +#include <linux/gpio.h> +#include <linux/of_gpio.h> #include <linux/v4l2-mediabus.h> #include <linux/videodev2.h>
@@ -283,6 +285,10 @@ struct ov2640_priv {u32 cfmt_code;struct v4l2_clk *clk;const struct ov2640_win_size *win; + +struct soc_camera_subdev_desc ssdd_dt; +int reset_pin; +int pwr_down_pin; };/*
@@ -1047,6 +1053,70 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = { .video = &ov2640_subdev_video_ops, }; +/* OF probe functions */ +static int ov2640_hw_power (struct device *dev,int on) +{ +struct i2c_client *client =to_i2c_client (dev); +struct ov2640_priv *priv =to_ov2640 (client); + +dev_dbg (&client->dev,"%s: %s the camera\n" , + __func__, on ?"ENABLE" :"DISABLE" ); + +/* enable or disable the camera */ +gpio_direction_output (priv->pwr_down_pin, !on); + +return 0 ; +} + +static int ov2640_hw_reset (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct ov2640_priv *priv =to_ov2640 (client); + +/* If enabled, give a reset impulse */ +gpio_direction_output (priv->reset_pin,0 ); +msleep (20 ); +gpio_direction_output (priv->reset_pin,1 ); +msleep (100 ); + +return 0 ; +} + +static int ov2640_probe_dt (struct i2c_client *client, +struct ov2640_priv *priv) +{ +struct device_node *np = client->dev.of_node; +int ret; + + priv->reset_pin =of_get_named_gpio (np,"reset-gpio" ,0 ); + priv->pwr_down_pin =of_get_named_gpio (np,"power-down-gpio" ,0 ); +if (!gpio_is_valid (priv->reset_pin) || + !gpio_is_valid (priv->pwr_down_pin)) +return -EINVAL ; + + ret =devm_gpio_request (&client->dev, priv->pwr_down_pin, +"power-down-pin" ); +if (ret <0 ) { +dev_err (&client->dev,"request gpio pin %d failed\n" , + priv->pwr_down_pin); +return ret; + } + + ret =devm_gpio_request (&client->dev, priv->reset_pin,"reset_pin" ); +if (ret <0 ) { +dev_err (&client->dev,"request gpio pin %d failed\n" , + priv->reset_pin); +return ret; + } + +/* Initialize the soc_camera_subdev_desc */ + priv->ssdd_dt.power = ov2640_hw_power; + priv->ssdd_dt.reset = ov2640_hw_reset; + client->dev.platform_data = &priv->ssdd_dt; + +return 0 ; +} +/* * i2c_driver functions */
@@ -1058,12 +1128,6 @@ static int ov2640_probe(struct i2c_client *client,struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);int ret; -if (!ssdd) { -dev_err (&adapter->dev, -"OV2640: Missing platform_data for driver\n" ); -return -EINVAL ; - } -if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) {dev_err (&adapter->dev,"OV2640: I2C-Adapter doesn't support SMBUS\n" );
@@ -1077,6 +1141,18 @@ static int ov2640_probe(struct i2c_client *client,return -ENOMEM ; } +if (!ssdd) { +if (client->dev.of_node) { + ret =ov2640_probe_dt (client, priv); +if (ret) +return ret; + }else { +dev_err (&client->dev, +"Missing platform_data for driver\n" ); +return -EINVAL ; + } + } +v4l2_i2c_subdev_init (&priv->subdev, client, &ov2640_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,2 ); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
@@ -1123,9 +1199,16 @@ static const struct i2c_device_id ov2640_id[] = { };MODULE_DEVICE_TABLE (i2c, ov2640_id); +static const struct of_device_id ov2640_of_match[] = { + {.compatible ="omnivision,ov2640" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, ov2640_of_match); +static struct i2c_driver ov2640_i2c_driver = { .driver = { .name ="ov2640" , + .of_match_table =of_match_ptr (ov2640_of_match), }, .probe = ov2640_probe, .remove = ov2640_remove,
Signature · 1 line
1.9.1
PATCH 2/4 media: ov2640: add primary dt support
Hi Josh,
Thank you for the patch.
Quoted 37 lines · On Friday 28 November 2014 18:28:25 Josh Wu wrote:
Add device tree support for ov2640.
Signed-off-by Josh Wu <[email protected]>--- drivers/media/i2c/soc_camera/ov2640.c | 95 +++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-)(quoted diff) +0
-0
b/drivers/media/i2c/soc_camera/ov2640.cindex 9ee910d..6506126 100644drivers/media/i2c/soc_camera/ov2640.c +7
-0@@ -18,6 +18,8 @@#include <linux/i2c.h> #include <linux/slab.h> #include <linux/delay.h> +#include <linux/gpio.h> +#include <linux/of_gpio.h> #include <linux/v4l2-mediabus.h> #include <linux/videodev2.h> @@ -283,6 +285,10 @@ struct ov2640_priv {u32 cfmt_code;struct v4l2_clk *clk;const struct ov2640_win_size *win; + +struct soc_camera_subdev_desc ssdd_dt; +int reset_pin; +int pwr_down_pin; };/* @@ -1047,6 +1053,70 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = { .video = &ov2640_subdev_video_ops, }; +/* OF probe functions */
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1066
Quoted 10 lines
drivers/media/i2c/soc_camera/ov2640.c +10
-0+static int ov2640_hw_power (struct device *dev,int on) +{ +struct i2c_client *client =to_i2c_client (dev); +struct ov2640_priv *priv =to_ov2640 (client); + +dev_dbg (&client->dev,"%s: %s the camera\n" , + __func__, on ?"ENABLE" :"DISABLE" ); + +/* enable or disable the camera */ +gpio_direction_output (priv->pwr_down_pin, !on);
Isn't there a delay required to wake the chip up ?
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1075
Quoted 9 lines
drivers/media/i2c/soc_camera/ov2640.c +9
-0+ +return 0 ; +} + +static int ov2640_hw_reset (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct ov2640_priv *priv =to_ov2640 (client); +
If the reset GPIO isn't specified you should return immediately without waiting 120ms.
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1078
Quoted 3 lines
drivers/media/i2c/soc_camera/ov2640.c +3
-0+/* If enabled, give a reset impulse */ +gpio_direction_output (priv->reset_pin,0 ); +msleep (20 );
Please use usleep_range().
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1080
Quoted 2 lines
drivers/media/i2c/soc_camera/ov2640.c +2
-0+gpio_direction_output (priv->reset_pin,1 ); +msleep (100 );
Is the reset delay documented somewhere ? 100ms seems pretty large to me.
Quoted 20 lines
drivers/media/i2c/soc_camera/ov2640.c +20
-0+ +return 0 ; +} + +static int ov2640_probe_dt (struct i2c_client *client, +struct ov2640_priv *priv) +{ +struct device_node *np = client->dev.of_node; +int ret; + + priv->reset_pin =of_get_named_gpio (np,"reset-gpio" ,0 ); + priv->pwr_down_pin =of_get_named_gpio (np,"power-down-gpio" ,0 ); +if (!gpio_is_valid (priv->reset_pin) || + !gpio_is_valid (priv->pwr_down_pin)) +return -EINVAL ; + + ret =devm_gpio_request (&client->dev, priv->pwr_down_pin, +"power-down-pin" ); +if (ret <0 ) { + dev_err(&client->dev, "request gpio pin %d failed\n",
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1110
Quoted 10 lines
drivers/media/i2c/soc_camera/ov2640.c +10
-0+ priv->pwr_down_pin); +return ret; + } + + ret =devm_gpio_request (&client->dev, priv->reset_pin,"reset_pin" ); +if (ret <0 ) { +dev_err (&client->dev,"request gpio pin %d failed\n" , + priv->reset_pin); +return ret; + }
Please use the gpiod API with the devm_gpiod_get_index_optional() function, it will simply your code and take care about GPIO polarity automatically. Don't forget to specify the default state using the GPIOD_* flags.
Quoted 61 lines
drivers/media/i2c/soc_camera/ov2640.c +28
-6+ +/* Initialize the soc_camera_subdev_desc */ + priv->ssdd_dt.power = ov2640_hw_power; + priv->ssdd_dt.reset = ov2640_hw_reset; + client->dev.platform_data = &priv->ssdd_dt; + +return 0 ; +} +/* * i2c_driver functions */ @@ -1058,12 +1128,6 @@ static int ov2640_probe(struct i2c_client *client,struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);int ret; -if (!ssdd) { -dev_err (&adapter->dev, -"OV2640: Missing platform_data for driver\n" ); -return -EINVAL ; - } -if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) {dev_err (&adapter->dev,"OV2640: I2C-Adapter doesn't support SMBUS\n" );@@ -1077,6 +1141,18 @@ static int ov2640_probe(struct i2c_client *client,return -ENOMEM ; } +if (!ssdd) { +if (client->dev.of_node) { + ret =ov2640_probe_dt (client, priv); +if (ret) +return ret; + }else { +dev_err (&client->dev, +"Missing platform_data for driver\n" ); +return -EINVAL ; + } + } +v4l2_i2c_subdev_init (&priv->subdev, client, &ov2640_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,2 ); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,@@ -1123,9 +1199,16 @@ static const struct i2c_device_id ov2640_id[] = { };MODULE_DEVICE_TABLE (i2c, ov2640_id); +static const struct of_device_id ov2640_of_match[] = { + {.compatible ="omnivision,ov2640" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, ov2640_of_match); +static struct i2c_driver ov2640_i2c_driver = { .driver = { .name ="ov2640" , + .of_match_table =of_match_ptr (ov2640_of_match), }, .probe = ov2640_probe, .remove = ov2640_remove,
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 2/4 media: ov2640: add primary dt support
Hi, Laurent
Quoted 41 lines · Laurent Pinchart
Hi Josh,
Thank you for the patch.
Quoted 36 lines · On Friday 28 November 2014 18:28:25 Josh Wu wrote:
Add device tree support for ov2640.
Cc devicetree at vger.kernel.orgSigned-off-by Josh Wu<[email protected]>--- drivers/media/i2c/soc_camera/ov2640.c | 95 +++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-)(quoted diff) +0
-0
b/drivers/media/i2c/soc_camera/ov2640.cindex 9ee910d..6506126 100644drivers/media/i2c/soc_camera/ov2640.c +6
-0@@ -18,6 +18,8 @@#include <linux/i2c.h> #include <linux/slab.h> #include <linux/delay.h> +#include <linux/gpio.h> +#include <linux/of_gpio.h> #include <linux/v4l2-mediabus.h> #include <linux/videodev2.h> @@ -283,6 +285,10 @@ struct ov2640_priv {u32 cfmt_code;struct v4l2_clk *clk;const struct ov2640_win_size *win; + +struct soc_camera_subdev_desc ssdd_dt; +int reset_pin; +int pwr_down_pin; };/* @@ -1047,6 +1053,70 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = { .video = &ov2640_subdev_video_ops, };
Quoted 12 lines
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1066
Quoted 11 lines
drivers/media/i2c/soc_camera/ov2640.c +11
-0+/* OF probe functions */ +static int ov2640_hw_power (struct device *dev,int on) +{ +struct i2c_client *client =to_i2c_client (dev); +struct ov2640_priv *priv =to_ov2640 (client); + +dev_dbg (&client->dev,"%s: %s the camera\n" , + __func__, on ?"ENABLE" :"DISABLE" ); + +/* enable or disable the camera */ +gpio_direction_output (priv->pwr_down_pin, !on);Isn't there a delay required to wake the chip up ?
I don't see any document mention a delay is needed when waked up.
Quoted 12 lines
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1075
Quoted 10 lines
drivers/media/i2c/soc_camera/ov2640.c +9
-0+ +return 0 ; +} + +static int ov2640_hw_reset (struct device *dev) +{ +struct i2c_client *client =to_i2c_client (dev); +struct ov2640_priv *priv =to_ov2640 (client); +If the reset GPIO isn't specified you should return immediately without waiting 120ms.
I find some document that said the reset pulse need >= 3ms. So I think use 3~5ms is enough.
Quoted 5 lines
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1078
Quoted 4 lines
drivers/media/i2c/soc_camera/ov2640.c +3
-0+/* If enabled, give a reset impulse */ +gpio_direction_output (priv->reset_pin,0 ); +msleep (20 );Please use
usleep_range().
ok.
Quoted 4 lines
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1080
Quoted 3 lines
drivers/media/i2c/soc_camera/ov2640.c +2
-0+gpio_direction_output (priv->reset_pin,1 ); +msleep (100 );Is the reset delay documented somewhere ? 100ms seems pretty large to me.
It seems no need to wait another delay after the reset pulse is generated. I will remove this line: msleep(100);
Quoted 25 lines
Quoted 25 lines
drivers/media/i2c/soc_camera/ov2640.c +25
-0+ +return 0 ; +} + +static int ov2640_probe_dt (struct i2c_client *client, +struct ov2640_priv *priv) +{ +struct device_node *np = client->dev.of_node; +int ret; + + priv->reset_pin =of_get_named_gpio (np,"reset-gpio" ,0 ); + priv->pwr_down_pin =of_get_named_gpio (np,"power-down-gpio" ,0 ); +if (!gpio_is_valid (priv->reset_pin) || + !gpio_is_valid (priv->pwr_down_pin)) +return -EINVAL ; + + ret =devm_gpio_request (&client->dev, priv->pwr_down_pin, +"power-down-pin" ); +if (ret <0 ) { +dev_err (&client->dev,"request gpio pin %d failed\n" , + priv->pwr_down_pin); +return ret; + } + + ret =devm_gpio_request (&client->dev, priv->reset_pin,"reset_pin" );
Quoted 8 lines
drivers/media/i2c/soc_camera/ov2640.c static struct v4l2_subdev_ops ov2640_subdev_ops = { · line 1110
Quoted 5 lines
drivers/media/i2c/soc_camera/ov2640.c +5
-0+if (ret <0 ) { +dev_err (&client->dev,"request gpio pin %d failed\n" , + priv->reset_pin); +return ret; + }Please use the gpiod API with the
devm_gpiod_get_index_optional()function, it will simply your code and take care about GPIO polarity automatically. Don't forget to specify the default state using the GPIOD_* flags.
Thank, I will use it.
It seems in this case, use devm_gpiod_get_optional() is enough.
Best Regards,
Josh Wu
Quoted 62 lines
Quoted 62 lines
drivers/media/i2c/soc_camera/ov2640.c +28
-6+ +/* Initialize the soc_camera_subdev_desc */ + priv->ssdd_dt.power = ov2640_hw_power; + priv->ssdd_dt.reset = ov2640_hw_reset; + client->dev.platform_data = &priv->ssdd_dt; + +return 0 ; +} +/* * i2c_driver functions */ @@ -1058,12 +1128,6 @@ static int ov2640_probe(struct i2c_client *client,struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent);int ret; -if (!ssdd) { -dev_err (&adapter->dev, -"OV2640: Missing platform_data for driver\n" ); -return -EINVAL ; - } -if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA )) {dev_err (&adapter->dev,"OV2640: I2C-Adapter doesn't support SMBUS\n" );@@ -1077,6 +1141,18 @@ static int ov2640_probe(struct i2c_client *client,return -ENOMEM ; } +if (!ssdd) { +if (client->dev.of_node) { + ret =ov2640_probe_dt (client, priv); +if (ret) +return ret; + }else { +dev_err (&client->dev, +"Missing platform_data for driver\n" ); +return -EINVAL ; + } + } +v4l2_i2c_subdev_init (&priv->subdev, client, &ov2640_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,2 ); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,@@ -1123,9 +1199,16 @@ static const struct i2c_device_id ov2640_id[] = { };MODULE_DEVICE_TABLE (i2c, ov2640_id); +static const struct of_device_id ov2640_of_match[] = { + {.compatible ="omnivision,ov2640" , }, + {}, +}; +MODULE_DEVICE_TABLE (of, ov2640_of_match); +static struct i2c_driver ov2640_i2c_driver = { .driver = { .name ="ov2640" , + .of_match_table =of_match_ptr (ov2640_of_match), }, .probe = ov2640_probe, .remove = ov2640_remove,
PATCH 3/4 media: ov2640: add a master clock for sensor
In reply to Josh WuThe master clock can be optional. It's a common clock framework clock. It can make sensor output a pixel clock to the camera interface.
If you just use a external oscillator clock as the master clock, then, just don't need set 'mck' in dt node.
--- drivers/media/i2c/soc_camera/ov2640.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
drivers/media/i2c/soc_camera/ov2640.c +25 -0
@@ -13,6 +13,7 @@* published by the Free Software Foundation. */ +#include <linux/clk.h> #include <linux/init.h> #include <linux/module.h> #include <linux/i2c.h>
@@ -31,6 +32,8 @@#define VAL_SET (x, mask, rshift, lshift) \ ((((x) >> rshift) & mask) << lshift) +#define DEFAULT_MASTER_CLK_FREQ 25000000 +/* * DSP registers * register offset for BANK_SEL == BANK_SEL_DSP
@@ -284,6 +287,7 @@ struct ov2640_priv {struct v4l2_ctrl_handler hdl;u32 cfmt_code;struct v4l2_clk *clk; +struct clk *master_clk;const struct ov2640_win_size *win;struct soc_camera_subdev_desc ssdd_dt;
@@ -746,6 +750,7 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on)struct soc_camera_subdev_desc *ssdd =soc_camera_i2c_to_desc (client);struct ov2640_priv *priv =to_ov2640 (client);struct v4l2_clk *clk; +int ret =0 ;if (!priv->clk) { clk =v4l2_clk_get (&client->dev,"mclk" );
@@ -755,6 +760,16 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on) priv->clk = clk; } +if (!IS_ERR (priv->master_clk)) { +if (on) + ret =clk_prepare_enable (priv->master_clk); +else +clk_disable_unprepare (priv->master_clk); + +if (ret) +return ret; + } +return soc_camera_set_power (&client->dev, ssdd, priv->clk, on); }
@@ -1153,6 +1168,16 @@ static int ov2640_probe(struct i2c_client *client, } } + priv->master_clk =devm_clk_get (&client->dev,"mck" ); +if (!IS_ERR (priv->master_clk)) { +/* Set ISI_MCK's frequency, it should be faster than pixel +* clock. +*/ + ret =clk_set_rate (priv->master_clk,DEFAULT_MASTER_CLK_FREQ ); +if (ret <0 ) +return ret; + } +v4l2_i2c_subdev_init (&priv->subdev, client, &ov2640_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,2 ); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
Signature · 1 line
1.9.1
PATCH 3/4 media: ov2640: add a master clock for sensor
Hi Josh,
(CC'ing the [email protected] mailing list)
Thank you for the patch.
Quoted 49 lines · On Friday 28 November 2014 18:28:26 Josh Wu wrote:
The master clock can be optional. It's a common clock framework clock. It can make sensor output a pixel clock to the camera interface.
If you just use a external oscillator clock as the master clock, then, just don't need set 'mck' in dt node.
Signed-off-by Josh Wu <[email protected]>--- drivers/media/i2c/soc_camera/ov2640.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)(quoted diff) +0
-0
b/drivers/media/i2c/soc_camera/ov2640.cindex 6506126..06c2aa9 100644drivers/media/i2c/soc_camera/ov2640.c +5
-0@@ -13,6 +13,7 @@* published by the Free Software Foundation. */ +#include <linux/clk.h> #include <linux/init.h> #include <linux/module.h> #include <linux/i2c.h> @@ -31,6 +32,8 @@#define VAL_SET (x, mask, rshift, lshift) \ ((((x) >> rshift) & mask) << lshift) +#define DEFAULT_MASTER_CLK_FREQ 25000000 +/* * DSP registers * register offset for BANK_SEL == BANK_SEL_DSP @@ -284,6 +287,7 @@ struct ov2640_priv {struct v4l2_ctrl_handler hdl;u32 cfmt_code;struct v4l2_clk *clk; +struct clk *master_clk;const struct ov2640_win_size *win;struct soc_camera_subdev_desc ssdd_dt;@@ -746,6 +750,7 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on) struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);struct ov2640_priv *priv =to_ov2640 (client);struct v4l2_clk *clk; +int ret =0 ;if (!priv->clk) { clk =v4l2_clk_get (&client->dev,"mclk" );
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_s_power(struct v4l2_subdev *sd, int · line 763
Quoted 4 lines
drivers/media/i2c/soc_camera/ov2640.c +1
-0@@ -755,6 +760,16 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on) priv->clk = clk; } +if (!IS_ERR (priv->master_clk)) {
The clock should be mandatory, you can thus drop this check.
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_s_power(struct v4l2_subdev *sd, int on) · line 770
Quoted 7 lines
drivers/media/i2c/soc_camera/ov2640.c +7
-0+if (on) + ret =clk_prepare_enable (priv->master_clk); +else +clk_disable_unprepare (priv->master_clk); + +if (ret) +return ret;
You can move the error check inside the first branch of the if and remove the ret = 0 initialization above.
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_s_power(struct v4l2_subdev *sd, int on) · line 773
Quoted 3 lines
drivers/media/i2c/soc_camera/ov2640.c +2
-0+ } +return soc_camera_set_power (&client->dev, ssdd, priv->clk, on);
If this call fails you should disable or enable the clock to undo the enable/disable above.
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_probe(struct i2c_client *client, · line 1176
Quoted 12 lines
drivers/media/i2c/soc_camera/ov2640.c +6
-0}@@ -1153,6 +1168,16 @@ static int ov2640_probe(struct i2c_client *client, } } + priv->master_clk =devm_clk_get (&client->dev,"mck" ); +if (!IS_ERR (priv->master_clk)) { +/* Set ISI_MCK's frequency, it should be faster than pixel +* clock. +*/ + ret =clk_set_rate (priv->master_clk,DEFAULT_MASTER_CLK_FREQ );
The clock frequency should be system-dependent. For the DT case an easy implementation would be to use the assigned-clock-rates to set the desired clock frequency is case of a variable clock, as adding a sensor-specific property to specify the desired clock frequency only to read that property in the driver and call clk_set_rate() seems a bit pointless to me.
Quoted 7 lines
drivers/media/i2c/soc_camera/ov2640.c +4
-0+if (ret <0 ) +return ret; + } +v4l2_i2c_subdev_init (&priv->subdev, client, &ov2640_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,2 ); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 3/4 media: ov2640: add a master clock for sensor
Hi, Laurent
Quoted 53 lines · Laurent Pinchart
Hi Josh,
(CC'ing the devicetree at vger.kernel.org mailing list)
Thank you for the patch.
Quoted 46 lines · On Friday 28 November 2014 18:28:26 Josh Wu wrote:
The master clock can be optional. It's a common clock framework clock. It can make sensor output a pixel clock to the camera interface.
If you just use a external oscillator clock as the master clock, then, just don't need set 'mck' in dt node.
Signed-off-by Josh Wu <[email protected]>--- drivers/media/i2c/soc_camera/ov2640.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)(quoted diff) +0
-0
b/drivers/media/i2c/soc_camera/ov2640.cindex 6506126..06c2aa9 100644drivers/media/i2c/soc_camera/ov2640.c +5
-0@@ -13,6 +13,7 @@* published by the Free Software Foundation. */ +#include <linux/clk.h> #include <linux/init.h> #include <linux/module.h> #include <linux/i2c.h> @@ -31,6 +32,8 @@#define VAL_SET (x, mask, rshift, lshift) \ ((((x) >> rshift) & mask) << lshift) +#define DEFAULT_MASTER_CLK_FREQ 25000000 +/* * DSP registers * register offset for BANK_SEL == BANK_SEL_DSP @@ -284,6 +287,7 @@ struct ov2640_priv {struct v4l2_ctrl_handler hdl;u32 cfmt_code;struct v4l2_clk *clk; +struct clk *master_clk;const struct ov2640_win_size *win;struct soc_camera_subdev_desc ssdd_dt;@@ -746,6 +750,7 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on) struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client);struct ov2640_priv *priv =to_ov2640 (client);struct v4l2_clk *clk; +int ret =0 ;
Quoted 8 lines
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_s_power(struct v4l2_subdev *sd, int · line 763
Quoted 7 lines
drivers/media/i2c/soc_camera/ov2640.c +1
-0if (!priv->clk) { clk =v4l2_clk_get (&client->dev,"mclk" );@@ -755,6 +760,16 @@ static int ov2640_s_power(struct v4l2_subdev *sd, int on) priv->clk = clk; } +if (!IS_ERR (priv->master_clk)) {The clock should be mandatory, you can thus drop this check.
OK. sure.
Quoted 11 lines
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_s_power(struct v4l2_subdev *sd, int on) · line 770
Quoted 8 lines
drivers/media/i2c/soc_camera/ov2640.c +7
-0+if (on) + ret =clk_prepare_enable (priv->master_clk); +else +clk_disable_unprepare (priv->master_clk); + +if (ret) +return ret;You can move the error check inside the first branch of the if and remove the ret = 0 initialization above.
Quoted 5 lines
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_s_power(struct v4l2_subdev *sd, int on) · line 773
Quoted 3 lines
drivers/media/i2c/soc_camera/ov2640.c +2
-0+ } +return soc_camera_set_power (&client->dev, ssdd, priv->clk, on);If this call fails you should disable or enable the clock to undo the enable/disable above.
ah, I totally forget this. will fix in next version. Thanks.
Quoted 7 lines
Quoted 7 lines
drivers/media/i2c/soc_camera/ov2640.c +0
-0}@@ -1153,6 +1168,16 @@ static int ov2640_probe(struct i2c_client *client, } }
Quoted 11 lines
drivers/media/i2c/soc_camera/ov2640.c static int ov2640_probe(struct i2c_client *client, · line 1176
Quoted 6 lines
drivers/media/i2c/soc_camera/ov2640.c +6
-0+ priv->master_clk =devm_clk_get (&client->dev,"mck" ); +if (!IS_ERR (priv->master_clk)) { +/* Set ISI_MCK's frequency, it should be faster than pixel +* clock. +*/ + ret =clk_set_rate (priv->master_clk,DEFAULT_MASTER_CLK_FREQ );The clock frequency should be system-dependent. For the DT case an easy implementation would be to use the assigned-clock-rates to set the desired clock frequency is case of a variable clock, as adding a sensor-specific property to specify the desired clock frequency only to read that property in the driver and call
clk_set_rate()seems a bit pointless to me.
I tried assigned-clock-rates and it works fine.
The only issue is the it cannot used by multiple nodes. But I think I can put a comments in the dt node for this.
Thanks.
Best Regards,
Josh Wu
Quoted 8 lines
Quoted 8 lines
drivers/media/i2c/soc_camera/ov2640.c +4
-0+if (ret <0 ) +return ret; + } +v4l2_i2c_subdev_init (&priv->subdev, client, &ov2640_subdev_ops);v4l2_ctrl_handler_init (&priv->hdl,2 ); v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
PATCH 4/4 media: ov2640: dt: add the device tree binding document
In reply to Josh WuAdd the document for ov2640 dt.
--- .../devicetree/bindings/media/i2c/ov2640.txt | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ov2640.txt
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +43 -0
@@ -0,0 +1,43 @@ +* Omnivision ov2640 CMOS sensor + +The Omnivision OV2640 sensor support multiple resolutions output, such as +CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB +output format. + +Required Properties : +- compatible : Must be "omnivision,ov2640" +- reset-gpio : reset pin +- power-down-gpio : power down pin + +Optional Properties: +- clocks : reference master clock, if using external fixed clock, you + no need to have such property. +- clock-names : Must be "mck", it means the master clock for ov2640. + +For further reading of port node refer Documentation/devicetree/bindings/media/ +video-interfaces.txt. + +Example: + + i2c1: i2c at f0018000 { + ov2640: camera at 0x30 { + compatible = "omnivision,ov2640"; + reg = <0x30>; + + ... ... + + reset-gpio = <&pioE 24 GPIO_ACTIVE_HIGH>; + power-down-gpio = <&pioE 29 GPIO_ACTIVE_HIGH>; + + /* use pck1 for the master clock of ov2640 */ + clocks = <&pck1>; + clock-names = "mck"; + + port { + ov2640_0: endpoint { + remote-endpoint = <&isi_0>; + bus-width = <8>; + }; + }; + }; + };
Signature · 1 line
1.9.1
PATCH 4/4 media: ov2640: dt: add the device tree binding document
Hi Josh,
Thank you for the patch.
Quoted 16 lines · On Friday 28 November 2014 18:28:27 Josh Wu wrote:
Add the document for ov2640 dt.
Signed-off-by Josh Wu <[email protected]>--- .../devicetree/bindings/media/i2c/ov2640.txt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/ov2640.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/media/i2c/ov2640.txtnew file mode 100644
index 0000000..adec147
Documentation/devicetree/bindings/media/i2c/ov2640.txt line 8
Quoted 8 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +8
-0@@ -0,0 +1,43 @@ +* Omnivision ov2640 CMOS sensor + +The Omnivision OV2640 sensor support multiple resolutions output, such as +CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB +output format. + +Required Properties : +- compatible : Must be "omnivision,ov2640"
The usual practice is to use the company's stock ticker as a prefix. In this case the compatible string would be "ovti,ov2640". You need to add the prefix to Documentation/devicetree/bindings/vendor-prefixes.txt.
Documentation/devicetree/bindings/media/i2c/ov2640.txt line 10
Quoted 2 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +2
-0+- reset-gpio : reset pin +- power-down-gpio : power down pin
That should be reset-gpios and power-down-gpios, even if there's a single GPIO. Furthermore, given that the power down pin is named PWDN you might want to name the property pwdn-gpios.
The reset and pwdn signals won't be connected on all boards, so the two properties should be optional.
Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +2
-0+Optional Properties: +- clocks : reference master clock, if using external fixed clock,you
+ no need to have such property.
The clock is required by the chip, so even when using an external fixed clock the property should be present, and reference a fixed clock node. The clocks and clock-names properties should thus be mandatory.
Quoted 1 line
+- clock-names : Must be "mck", it means the master clock for ov2640.
The clock input is named xvclk in the datasheet, you should use the same name here.
Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +2
-0+ +For further reading of port node refer
Documentation/devicetree/bindings/media/
+video-interfaces.txt.
Even if you reference that document you should still mention what port node(s) these bindings require. Something like the following text should be enough.
"The device node must contain one 'port' child node for its digital output video port, in accordance with the video interface bindings defined in Documentation/devicetree/bindings/media/video-interfaces.txt."
Documentation/devicetree/bindings/media/i2c/ov2640.txt line 27
Quoted 9 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +9
-0+ +Example: + + i2c1: i2c@f0018000 { + ov2640: camera@0x30 { + compatible = "omnivision,ov2640"; + reg = <0x30>; + + ... ...
No need for an ellipsis, what are you trying to hide ? :-)
Documentation/devicetree/bindings/media/i2c/ov2640.txt line 32
Quoted 5 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +5
-0+ + reset-gpio = <&pioE 24 GPIO_ACTIVE_HIGH>; + power-down-gpio = <&pioE 29 GPIO_ACTIVE_HIGH>; + + /* use pck1 for the master clock of ov2640 */
I think you can drop the comment.
Quoted 11 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +11
-0+ clocks = <&pck1>; + clock-names = "mck"; + + port { + ov2640_0: endpoint { + remote-endpoint = <&isi_0>; + bus-width = <8>; + }; + }; + }; + };
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 4/4 media: ov2640: dt: add the device tree binding document
Hi, Laurent
Quoted 65 lines · Laurent Pinchart
Hi Josh,
Thank you for the patch.
Quoted 16 lines · On Friday 28 November 2014 18:28:27 Josh Wu wrote:
Add the document for ov2640 dt.
Cc devicetree at vger.kernel.orgSigned-off-by Josh Wu <[email protected]>--- .../devicetree/bindings/media/i2c/ov2640.txt | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+)create mode 100644
Documentation/devicetree/bindings/media/i2c/ov2640.txt(quoted diff) +0
-0
b/Documentation/devicetree/bindings/media/i2c/ov2640.txtnew file mode 100644
index 0000000..adec147Documentation/devicetree/bindings/media/i2c/ov2640.txt line 8
Quoted 8 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +8
-0@@ -0,0 +1,43 @@ +* Omnivision ov2640 CMOS sensor + +The Omnivision OV2640 sensor support multiple resolutions output, such as +CIF, SVGA, UXGA. It also can support YUV422/420, RGB565/555 or raw RGB +output format. + +Required Properties : +- compatible : Must be "omnivision,ov2640"The usual practice is to use the company's stock ticker as a prefix. In this case the compatible string would be "ovti,ov2640". You need to add the prefix to
Documentation/devicetree/bindings/vendor-prefixes.txt.Documentation/devicetree/bindings/media/i2c/ov2640.txt line 10
Quoted 2 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +2
-0+- reset-gpio : reset pin +- power-down-gpio : power down pinThat should be reset-gpios and power-down-gpios, even if there's a single GPIO. Furthermore, given that the power down pin is named PWDN you might want to name the property pwdn-gpios.
The reset and pwdn signals won't be connected on all boards, so the two properties should be optional.
Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +2
-0+Optional Properties: +- clocks : reference master clock, if using external fixed clock,you
+ no need to have such property.The clock is required by the chip, so even when using an external fixed clock the property should be present, and reference a fixed clock node. The clocks and clock-names properties should thus be mandatory.
Quoted 1 line
+- clock-names : Must be "mck", it means the master clock for ov2640.
The clock input is named xvclk in the datasheet, you should use the same name here.
Quoted 4 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +2
-0+ +For further reading of port node refer
Documentation/devicetree/bindings/media/
+video-interfaces.txt.Even if you reference that document you should still mention what port node(s) these bindings require. Something like the following text should be enough.
"The device node must contain one 'port' child node for its digital output video port, in accordance with the video interface bindings defined in
Documentation/devicetree/bindings/media/video-interfaces.txt."
Quoted 10 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt line 27
Quoted 9 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +9
-0+ +Example: + + i2c1: i2c at f0018000 { + ov2640: camera at 0x30 { + compatible = "omnivision,ov2640"; + reg = <0x30>; + + ... ...No need for an ellipsis, what are you trying to hide ? :-)
I just emit the pinctrl property here. Will add it back.
Quoted 7 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt line 32
Quoted 6 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +5
-0+ + reset-gpio = <&pioE 24 GPIO_ACTIVE_HIGH>; + power-down-gpio = <&pioE 29 GPIO_ACTIVE_HIGH>; + + /* use pck1 for the master clock of ov2640 */I think you can drop the comment.
I will send a new version which will fix all above. Thanks for your time to review the patch. That help me a lot.
Best Regards,
Josh Wu
Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/media/i2c/ov2640.txt new file +11
-0+ clocks = <&pck1>; + clock-names = "mck"; + + port { + ov2640_0: endpoint { + remote-endpoint = <&isi_0>; + bus-width = <8>; + }; + }; + }; + };