media: ov2740: Debug log chip ID
PATCH v2 1/4 media: ov2740: Debug log chip ID
Calling the identify function may get delayed till the first stream-on, add a dev_dbg() to it so that we know when it has run. This is useful to debug bring-up problems related to regulators / clks / GPIOs.
---
Changes in v2:
- Prefix chip-id with "0x" when logging it as it is logged in hex
--- drivers/media/i2c/ov2740.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/media/i2c/ov2740.c +2 -0
@@ -644,6 +644,8 @@ static int ov2740_identify_module(struct ov2740 *ov2740)return -ENXIO ; } +dev_dbg (&client->dev,"chip id: 0x%x\n" , val); + ov2740->identified = true;return 0 ;
Signature · 1 line
2.47.1
PATCH v2 2/4 media: ov2740: Add camera orientation and sensor rotation controls
Add camera orientation and sensor rotation controls using the v4l2_fwnode_device_parse() and v4l2_ctrl_new_fwnode_properties() helpers.
---
Changes in v2:
- Call v4l2_ctrl_handler_free() on v4l2_fwnode_device_parse() errors
--- drivers/media/i2c/ov2740.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/media/i2c/ov2740.c +12 -1
@@ -755,15 +755,17 @@ static const struct v4l2_ctrl_ops ov2740_ctrl_ops = {static int ov2740_init_controls (struct ov2740 *ov2740) { +struct i2c_client *client =v4l2_get_subdevdata (&ov2740->sd);struct v4l2_ctrl_handler *ctrl_hdlr;const struct ov2740_mode *cur_mode;s64 exposure_max, h_blank, pixel_rate;u32 vblank_min, vblank_max, vblank_default; +struct v4l2_fwnode_device_properties props;int size;int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret =v4l2_ctrl_handler_init (ctrl_hdlr,8 ); + ret =v4l2_ctrl_handler_init (ctrl_hdlr,10 );if (ret)return ret;
@@ -813,6 +815,15 @@ static int ov2740_init_controls(struct ov2740 *ov2740)V4L2_CID_TEST_PATTERN ,ARRAY_SIZE (ov2740_test_pattern_menu) -1 , 0, 0, ov2740_test_pattern_menu); + + ret =v4l2_fwnode_device_parse (&client->dev, &props); +if (ret) { +v4l2_ctrl_handler_free (ctrl_hdlr); +return ret; + } + +v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &ov2740_ctrl_ops, &props); +if (ctrl_hdlr->error) {v4l2_ctrl_handler_free (ctrl_hdlr);return ctrl_hdlr->error;
Signature · 1 line
2.47.1
Re: [PATCH v2 2/4] media: ov2740: Add camera orientation and sensor rotation controls
Quoted 6 lines · Hans de Goede
Add camera orientation and sensor rotation controls using the
v4l2_fwnode_device_parse()andv4l2_ctrl_new_fwnode_properties()helpers.Tested-by Stanislaw Gruszka <[email protected]>
Quoted 50 lines
Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Callv4l2_ctrl_handler_free()onv4l2_fwnode_device_parse()errors--- drivers/media/i2c/ov2740.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)drivers/media/i2c/ov2740.c +12
-2@@ -755,15 +755,17 @@ static const struct v4l2_ctrl_ops ov2740_ctrl_ops = {static int ov2740_init_controls (struct ov2740 *ov2740) { +struct i2c_client *client =v4l2_get_subdevdata (&ov2740->sd);struct v4l2_ctrl_handler *ctrl_hdlr;const struct ov2740_mode *cur_mode;s64 exposure_max, h_blank, pixel_rate;u32 vblank_min, vblank_max, vblank_default; +struct v4l2_fwnode_device_properties props;int size;int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret =v4l2_ctrl_handler_init (ctrl_hdlr,8 ); + ret =v4l2_ctrl_handler_init (ctrl_hdlr,10 );if (ret)return ret;@@ -813,6 +815,15 @@ static int ov2740_init_controls(struct ov2740 *ov2740)V4L2_CID_TEST_PATTERN ,ARRAY_SIZE (ov2740_test_pattern_menu) -1 , 0, 0, ov2740_test_pattern_menu); + + ret =v4l2_fwnode_device_parse (&client->dev, &props); +if (ret) { +v4l2_ctrl_handler_free (ctrl_hdlr); +return ret; + } + +v4l2_ctrl_new_fwnode_properties (ctrl_hdlr, &ov2740_ctrl_ops, &props); +if (ctrl_hdlr->error) {v4l2_ctrl_handler_free (ctrl_hdlr);return ctrl_hdlr->error; --2.47.1
Signature · 1 line
Ricardo Ribalda
PATCH v2 3/4 media: ov2740: Add powerdown GPIO support
In reply to Hans de GoedeThe ov2740 sensor has both reset and power_down inputs according to the datasheet one or the other should always be tied to DOVDD but on some designs both are attached to GPIOs.
Add support for controlling both a reset and a powerdown GPIO.
--- drivers/media/i2c/ov2740.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/media/i2c/ov2740.c +13 -2
@@ -525,6 +525,7 @@ struct ov2740 {/* GPIOs, clocks */ struct gpio_desc *reset_gpio; +struct gpio_desc *powerdown_gpio;struct clk *clk;/* Current mode */
@@ -1308,6 +1309,7 @@ static int ov2740_suspend(struct device *dev)struct ov2740 *ov2740 =to_ov2740 (sd);gpiod_set_value_cansleep (ov2740->reset_gpio,1 ); +gpiod_set_value_cansleep (ov2740->powerdown_gpio,1 );clk_disable_unprepare (ov2740->clk);return 0 ; }
@@ -1322,6 +1324,7 @@ static int ov2740_resume(struct device *dev)if (ret)return ret; +gpiod_set_value_cansleep (ov2740->powerdown_gpio,0 );gpiod_set_value_cansleep (ov2740->reset_gpio,0 );msleep (20 );
@@ -1350,9 +1353,17 @@ static int ov2740_probe(struct i2c_client *client)if (IS_ERR (ov2740->reset_gpio)) {return dev_err_probe (dev,PTR_ERR (ov2740->reset_gpio),"failed to get reset GPIO\n" ); - }else if (ov2740->reset_gpio) { + } + + ov2740->powerdown_gpio =devm_gpiod_get_optional (dev,"powerdown" ,GPIOD_OUT_HIGH ); +if (IS_ERR (ov2740->powerdown_gpio)) { +return dev_err_probe (dev,PTR_ERR (ov2740->powerdown_gpio), +"failed to get powerdown GPIO\n" ); + } + +if (ov2740->reset_gpio || ov2740->powerdown_gpio) {/* -* Ensure reset is asserted for at least 20 ms before +* Ensure reset/powerdown is asserted for at least 20 ms before * ov2740_resume() deasserts it. */ msleep (20 );
Signature · 1 line
2.47.1
PATCH v2 4/4 media: ov2740: Add regulator support
In reply to Hans de GoedeOn some designs the regulators for the AVDD / DOVDD / DVDD power rails are controlled by Linux.
Add support to the driver for getting regulators for these 3 rails and for enabling these regulators when necessary.
The datasheet specifies a delay of 0ns between enabling the regulators, IOW they can all 3 be enabled at the same time. This allows using the bulk regulator API.
The regulator core will provide dummy regulators for the 3 power-rails when necessary.
---
Changes in v2:
- Directly use ARRAY_SIZE(ov2740_supply_name), drop OV2740_NUM_SUPPLIES define
- Make i in probe() unsigned
--- drivers/media/i2c/ov2740.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/media/i2c/ov2740.c +29 -2
@@ -11,6 +11,7 @@#include <linux/pm_runtime.h> #include <linux/nvmem-provider.h> #include <linux/regmap.h> +#include <linux/regulator/consumer.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <media/v4l2-fwnode.h>
@@ -76,6 +77,12 @@/* OTP registers from sensor */ #define OV2740_REG_OTP_CUSTOMER 0x7010 +static const char *const ov2740_supply_name[] = { +"AVDD" , +"DOVDD" , +"DVDD" , +}; +struct nvm_data {struct nvmem_device *nvmem;struct regmap *regmap;
@@ -523,10 +530,11 @@ struct ov2740 {struct v4l2_ctrl *hblank;struct v4l2_ctrl *exposure; -/* GPIOs, clocks */ +/* GPIOs, clocks, regulators */ struct gpio_desc *reset_gpio;struct gpio_desc *powerdown_gpio;struct clk *clk; +struct regulator_bulk_data supplies[ARRAY_SIZE (ov2740_supply_name)];/* Current mode */ const struct ov2740_mode *cur_mode;
@@ -1311,6 +1319,8 @@ static int ov2740_suspend(struct device *dev)gpiod_set_value_cansleep (ov2740->reset_gpio,1 );gpiod_set_value_cansleep (ov2740->powerdown_gpio,1 );clk_disable_unprepare (ov2740->clk); +regulator_bulk_disable (ARRAY_SIZE (ov2740_supply_name), + ov2740->supplies);return 0 ; }
@@ -1320,10 +1330,18 @@ static int ov2740_resume(struct device *dev)struct ov2740 *ov2740 =to_ov2740 (sd);int ret; - ret =clk_prepare_enable (ov2740->clk); + ret =regulator_bulk_enable (ARRAY_SIZE (ov2740_supply_name), + ov2740->supplies);if (ret)return ret; + ret =clk_prepare_enable (ov2740->clk); +if (ret) { +regulator_bulk_disable (ARRAY_SIZE (ov2740_supply_name), + ov2740->supplies); +return ret; + } +gpiod_set_value_cansleep (ov2740->powerdown_gpio,0 );gpiod_set_value_cansleep (ov2740->reset_gpio,0 );msleep (20 );
@@ -1336,6 +1354,7 @@ static int ov2740_probe(struct i2c_client *client)struct device *dev = &client->dev;struct ov2740 *ov2740;bool full_power; +unsigned int i;int ret; ov2740 =devm_kzalloc (&client->dev,sizeof (*ov2740),GFP_KERNEL );
@@ -1374,6 +1393,14 @@ static int ov2740_probe(struct i2c_client *client)return dev_err_probe (dev,PTR_ERR (ov2740->clk),"failed to get clock\n" ); +for (i =0 ; i <ARRAY_SIZE (ov2740_supply_name); i++) + ov2740->supplies[i].supply = ov2740_supply_name[i]; + + ret =devm_regulator_bulk_get (dev,ARRAY_SIZE (ov2740_supply_name), + ov2740->supplies); +if (ret) +return dev_err_probe (dev, ret,"failed to get regulators\n" ); + full_power =acpi_dev_state_d0 (&client->dev);if (full_power) {/* ACPI does not always clear the reset GPIO / enable the clock */
Signature · 1 line
2.47.1
Sakari Ailus
maintainerHi Hans,
Quoted 10 lines · Hans de Goede
Calling the identify function may get delayed till the first stream-on, add a
dev_dbg()to it so that we know when it has run. This is useful to debug bring-up problems related to regulators / clks / GPIOs.Reviewed-by Ricardo Ribalda <[email protected]>Tested-by Stanislaw Gruszka <[email protected]>Signed-off-by Hans de Goede <[email protected]>---
Changes in v2:
- Prefix chip-id with "0x" when logging it as it is logged in hex
It seems I accidentally took v1 and that is now merged. I'll post a few patches to bring in the fixes you wrote for v2.
Signature · 3 lines
Regards, Sakari Ailus