Re: [V7, 2/2] media: i2c: dw9768: Add DW9768 VCM driver

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Tomasz,

Thanks for the review.

On Fri, 2020-06-05 at 13:44 +0000, Tomasz Figa wrote:
> Hi Dongchun,
> 
> On Fri, Jun 05, 2020 at 06:54:12PM +0800, Dongchun Zhu wrote:
> > Add a V4L2 sub-device driver for DW9768 voice coil motor, providing
> > control to set the desired focus via IIC serial interface.
> > 
> > Signed-off-by: Dongchun Zhu <dongchun.zhu@xxxxxxxxxxxx>
> > ---
> >  MAINTAINERS                |   1 +
> >  drivers/media/i2c/Kconfig  |  13 ++
> >  drivers/media/i2c/Makefile |   1 +
> >  drivers/media/i2c/dw9768.c | 566 +++++++++++++++++++++++++++++++++++++++++++++
> >  4 files changed, 581 insertions(+)
> >  create mode 100644 drivers/media/i2c/dw9768.c
> > 
> 
> Thank you for the patch. Please see my comments inline.
> 
> [snip]
> > +/*
> > + * DW9768 requires waiting time (delay time) of t_OPR after power-up,
> > + * or in the case of PD reset taking place.
> > + */
> > +#define DW9768_T_OPR_US				1000
> > +#define DW9768_Tvib_MS_BASE10			(64 - 1)
> 
> Kernel macro names are uppercase only.
> 

Aha... This is caused by my carelessness.
Fixed in next release.

> [snip]
> > +	/* Set AAC Timing */
> > +	if (dw9768->aac_timing != DW9768_AAC_TIME_DEFAULT) {
> > +		ret = i2c_smbus_write_byte_data(client, DW9768_AAC_TIME_REG,
> > +						dw9768->aac_timing);
> > +		if (ret < 0)
> > +			return ret;
> > +	}
> > +
> > +	move_delay_us = dw9768_cal_move_delay(dw9768->aac_mode,
> > +					      dw9768->clock_presc,
> > +					      dw9768->aac_timing) / 100;
> 
> We could calculate this once in probe() and store the ready us value in
> the dw9768 struct.
> 

Great idea :-)
>From the perspective of 'move_delay_us' itself, it defines VCM Operation
Time, which is indeed an intrinsic parameter that belongs to DW9768
private structure.

> > +
> > +	for (val = dw9768->focus->val % DW9768_MOVE_STEPS;
> > +	     val <= dw9768->focus->val;
> > +	     val += DW9768_MOVE_STEPS) {
> > +		ret = dw9768_set_dac(dw9768, val);
> > +		if (ret) {
> > +			dev_err(&client->dev, "%s I2C failure: %d",
> > +				__func__, ret);
> > +			return ret;
> > +		}
> > +		usleep_range(move_delay_us, move_delay_us + 1000);
> > +	}
> > +
> > +	return 0;
> > +}
> [snip]
> > +	pm_runtime_enable(dev);
> > +	if (!pm_runtime_enabled(dev)) {
> > +		ret = dw9768_runtime_resume(dev);
> > +		if (ret < 0) {
> > +			dev_err(dev, "failed to power on: %d\n", ret);
> > +			goto err_clean_entity;
> > +		}
> > +	}
> > +
> > +	ret = v4l2_async_register_subdev(&dw9768->sd);
> > +	if (ret < 0) {
> > +		dev_err(dev, "failed to register V4L2 subdev: %d", ret);
> > +		goto error_async_register;
> > +	}
> > +
> > +	return 0;
> > +
> > +error_async_register:
> 
> The recommendation is to name the labels after the clean-up task that needs
> to be done. Should this one be called error_power_off?
> 

Understood.
'error_async_register' would be replaced of 'err_power_off' in next
release.

> > +	if (!pm_runtime_enabled(dev))
> > +		dw9768_runtime_suspend(dev);
> 
> Shouldn't we also call pm_runtime_disable() here?
> 

Thanks for the reminder.
We would add pm_runtime_disable() in next release.
Just like:
err_power_off:
	pm_runtime_disable(dev);
	if (!pm_runtime_enabled(dev))
		dw9768_runtime_suspend(dev);

> > +err_clean_entity:
> > +	media_entity_cleanup(&dw9768->sd.entity);
> > +err_free_handler:
> > +	v4l2_ctrl_handler_free(&dw9768->ctrls);
> > +
> > +	return ret;
> > +}
> > +
> > +static int dw9768_remove(struct i2c_client *client)
> > +{
> > +	struct v4l2_subdev *sd = i2c_get_clientdata(client);
> > +	struct dw9768 *dw9768 = sd_to_dw9768(sd);
> > +
> > +	v4l2_async_unregister_subdev(&dw9768->sd);
> > +	v4l2_ctrl_handler_free(&dw9768->ctrls);
> > +	media_entity_cleanup(&dw9768->sd.entity);
> > +	pm_runtime_disable(&client->dev);
> > +	if (!pm_runtime_status_suspended(&client->dev))
> 
> pm_runtime_status_suspended() doesn't consider the runtime PM disable
> state. There is also pm_runtime_suspended() and that should be correct
> here.
> 

Fixed in next release.

> Best regards,
> Tomasz





[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux