1
0
Fork 0

media: ov5640 mipi v2: fix kernel warning when no camera is plugged in

in 5451781dad commit, it added the check that
the regulator need to be disabled before calling regulator_put().
If not do so, the kernel will print warning message as below.
To fix this, need to disable regulator before probe function return if the
camera's not found. regulator_put() will be called when probe fails in this case
as devm_regulator_get() already called in probe function.

[    2.834247] ov5640_mipi 1-003c: Camera is not found
[    2.839198] ------------[ cut here ]------------
[    2.844386] WARNING: CPU: 0 PID: 33 at drivers/regulator/core.c:2039 _regulator_put+0x34/0xd8
[    2.852954] Modules linked in:
[    2.856091] CPU: 0 PID: 33 Comm: kworker/0:1 Not tainted 5.3.0-rc3-next-20190809-5.3-warrior-next+g1dc2946 #1
[    2.866044] Hardware name: NXP i.MX8MQ EVK (DT)
[    2.870692] Workqueue: events deferred_probe_work_func
[    2.875879] pstate: 60000005 (nZCv daif -PAN -UAO)
[    2.880712] pc : _regulator_put+0x34/0xd8
[    2.884756] lr : _regulator_put+0x34/0xd8
[    2.888802] sp : ffff00001210b5f0
[    2.892153] x29: ffff00001210b5f0 x28: ffff0000111ca238
[    2.897478] x27: ffff000011db1850 x26: ffff000011db1790
[    2.902800] x25: ffff000011db1790 x24: 0000000000000009
[    2.908151] x23: ffff00001210b698 x22: ffff8000baec9e00
[    2.913501] x21: ffff000011c498c8 x20: ffff8000baecc100
[    2.918852] x19: ffff8000baecc100 x18: 0000000000000010
[    2.924202] x17: 0000000000000000 x16: 0000000000000000
[    2.929553] x15: ffffffffffffffff x14: ffff000011c498c8
[    2.934904] x13: ffff00009210b387 x12: ffff00001210b38f
[    2.940254] x11: ffff000011c62000 x10: ffff00001210b310
[    2.945605] x9 : 00000000ffffffd0 x8 : ffff0000106e31a0
[    2.950955] x7 : 0000000000000124 x6 : ffff000011e63b43
[    2.956305] x5 : 0000000000000000 x4 : 0000000000000000
[    2.961655] x3 : 00000000ffffffff x2 : e14ea0006ddd6c00
[    2.967006] x1 : 0000000000000000 x0 : 0000000000000024
[    2.972390] Call trace:
[    2.974884]  _regulator_put+0x34/0xd8
[    2.978588]  regulator_put+0x2c/0x40
[    2.982227]  devm_regulator_release+0x10/0x18
[    2.986640]  release_nodes+0x1b0/0x220
[    2.990429]  devres_release_all+0x34/0x58
[    2.994480]  really_probe+0x1b8/0x2e8
[    2.998184]  driver_probe_device+0x74/0x118
[    3.002406]  __device_attach_driver+0x80/0xb8
[    3.006805]  bus_for_each_drv+0x78/0xc8
[    3.010653]  __device_attach+0xd4/0x130
[    3.014528]  device_initial_probe+0x10/0x18
[    3.018746]  bus_probe_device+0x90/0x98
[    3.022624]  device_add+0x48c/0x720
[    3.026150]  device_register+0x1c/0x28
[    3.029975]  i2c_new_client_device+0x130/0x2a0
[    3.034431]  i2c_new_device+0xc/0x20
[    3.038061]  of_i2c_register_device+0x70/0x98
[    3.042457]  of_i2c_register_devices+0x98/0x120
[    3.047026]  i2c_register_adapter+0x160/0x410
[    3.051395]  __i2c_add_numbered_adapter+0x58/0x90
[    3.056137]  i2c_add_adapter+0x9c/0xc8
[    3.059925]  i2c_add_numbered_adapter+0x24/0x30
[    3.064507]  i2c_imx_probe+0x3d0/0x880
[    3.068296]  platform_drv_probe+0x50/0xa0
[    3.072318]  really_probe+0xdc/0x2e8
[    3.075933]  driver_probe_device+0x74/0x118
[    3.080127]  __device_attach_driver+0x80/0xb8
[    3.084522]  bus_for_each_drv+0x78/0xc8
[    3.088397]  __device_attach+0xd4/0x130
[    3.092268]  device_initial_probe+0x10/0x18
[    3.096461]  bus_probe_device+0x90/0x98
[    3.100332]  deferred_probe_work_func+0x64/0x98
[    3.104956]  process_one_work+0x1e0/0x320
[    3.109007]  worker_thread+0x228/0x428
[    3.112812]  kthread+0x120/0x128
[    3.116104]  ret_from_fork+0x10/0x18
[    3.119722] ---[ end trace 69a95d03ced5eb6c ]---

Signed-off-by: Robby Cai <robby.cai@nxp.com>
(cherry picked from commit ddfe50087eb3addb4d0574b8ee1a153b7da71284)
5.4-rM2-2.2.x-imx-squashed
Robby Cai 2019-10-14 15:41:49 +08:00 committed by Dong Aisheng
parent 1b8ca61ed2
commit cc90e18113
1 changed files with 19 additions and 19 deletions

View File

@ -626,6 +626,21 @@ static int ov5640_regulator_enable(struct device *dev)
return ret;
}
static void ov5640_regualtor_disable(void)
{
if (analog_regulator)
regulator_disable(analog_regulator);
if (core_regulator)
regulator_disable(core_regulator);
if (io_regulator)
regulator_disable(io_regulator);
if (gpo_regulator)
regulator_disable(gpo_regulator);
}
static s32 ov5640_write_reg(struct ov5640 *sensor, u16 reg, u8 val)
{
struct device *dev = &sensor->i2c_client->dev;
@ -1259,14 +1274,7 @@ static int ov5640_s_power(struct v4l2_subdev *sd, int on)
if (regulator_enable(analog_regulator) != 0)
return -EIO;
} else if (!on && sensor->on) {
if (analog_regulator)
regulator_disable(analog_regulator);
if (core_regulator)
regulator_disable(core_regulator);
if (io_regulator)
regulator_disable(io_regulator);
if (gpo_regulator)
regulator_disable(gpo_regulator);
ov5640_regualtor_disable();
}
sensor->on = on;
@ -1758,12 +1766,14 @@ static int ov5640_probe(struct i2c_client *client,
&chip_id_high);
if (retval < 0 || chip_id_high != 0x56) {
dev_warn(dev, "Camera is not found\n");
ov5640_regualtor_disable();
clk_disable_unprepare(sensor->sensor_clk);
return -ENODEV;
}
retval = ov5640_read_reg(sensor, OV5640_CHIP_ID_LOW_BYTE, &chip_id_low);
if (retval < 0 || chip_id_low != 0x40) {
dev_warn(dev, "Camera is not found\n");
ov5640_regualtor_disable();
clk_disable_unprepare(sensor->sensor_clk);
return -ENODEV;
}
@ -1807,17 +1817,7 @@ static int ov5640_remove(struct i2c_client *client)
ov5640_power_down(sensor, 1);
if (gpo_regulator)
regulator_disable(gpo_regulator);
if (analog_regulator)
regulator_disable(analog_regulator);
if (core_regulator)
regulator_disable(core_regulator);
if (io_regulator)
regulator_disable(io_regulator);
ov5640_regualtor_disable();
return 0;
}