Re: [PATCH v3 14/18] media: i2c: Add driver for DW9719 VCM

Hans de Goede
2023-07-06T12:54:04Z

Hi Dave,

On 7/6/23 13:18, Dave Stevenson wrote:
> Hi Hans
>
> On Wed, 5 Jul 2023 at 22:33, Hans de Goede <hdegoede@redhat.com> wrote:
>>
>> From: Daniel Scally <djrscally@gmail.com>
>>
>> Add a driver for the DW9719 VCM. The driver creates a v4l2 subdevice
>> and registers a control to set the desired focus.
>>
>> Signed-off-by: Daniel Scally <djrscally@gmail.com>
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> Changes in v3 (Hans de Goede)
>> - New patch in v3 of this series based on Dan Scally's initial
>> DW9719 upstream submission:
>> https://lore.kernel.org/all/20211128232115.38833-1-djrscally@gmail.com/
>> - Drop hack to enable "vsio" regulator, this is no longer necessary
>> now that there is a device-link making the VCM a runtime-pm consumer
>> of the sensor
>> - Add checking of device-properties for sac-mode and vcm-freq,
>> as requested by Sakari, this is done similar to the dw9768:
>> Documentation/devicetree/bindings/media/i2c/dongwoon,dw9768.yaml
>> Note no devicetree binding doc is added since currently only
>> i2c_device_id enumeration (instantiated by IPU bridge) is
>> supported
>> ---
>> MAINTAINERS | 7 +
>> drivers/media/i2c/Kconfig | 11 +
>> drivers/media/i2c/Makefile | 1 +
>> drivers/media/i2c/dw9719.c | 427 +++++++++++++++++++++++++++++++++++++
>> 4 files changed, 446 insertions(+)
>> create mode 100644 drivers/media/i2c/dw9719.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 494682dd437f..cf8e799f6ea2 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -6266,6 +6266,13 @@ T: git git://linuxtv.org/media_tree.git
>> F: Documentation/devicetree/bindings/media/i2c/dongwoon,dw9714.yaml
>> F: drivers/media/i2c/dw9714.c
>>
>> +DONGWOON DW9719 LENS VOICE COIL DRIVER
>> +M: Daniel Scally <djrscally@gmail.com>
>> +L: linux-media@vger.kernel.org
>> +S: Maintained
>> +T: git git://linuxtv.org/media_tree.git
>> +F: drivers/media/i2c/dw9719.c
>> +
>> DONGWOON DW9768 LENS VOICE COIL DRIVER
>> L: linux-media@vger.kernel.org
>> S: Orphan
>> diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
>> index 26dc365365d8..4864f1df3c7a 100644
>> --- a/drivers/media/i2c/Kconfig
>> +++ b/drivers/media/i2c/Kconfig
>> @@ -875,6 +875,17 @@ config VIDEO_DW9714
>> capability. This is designed for linear control of
>> voice coil motors, controlled via I2C serial interface.
>>
>> +config VIDEO_DW9719
>> + tristate "DW9719 lens voice coil support"
>> + depends on I2C && VIDEO_DEV
>> + select MEDIA_CONTROLLER
>> + select VIDEO_V4L2_SUBDEV_API
>> + select V4L2_ASYNC
>> + help
>> + This is a driver for the DW9719 camera lens voice coil.
>> + This is designed for linear control of voice coil motors,
>> + controlled via I2C serial interface.
>> +
>> config VIDEO_DW9768
>> tristate "DW9768 lens voice coil support"
>> depends on I2C && VIDEO_DEV
>> diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile
>> index d175a2e2fb19..745f8d07e649 100644
>> --- a/drivers/media/i2c/Makefile
>> +++ b/drivers/media/i2c/Makefile
>> @@ -32,6 +32,7 @@ obj-$(CONFIG_VIDEO_DS90UB913) += ds90ub913.o
>> obj-$(CONFIG_VIDEO_DS90UB953) += ds90ub953.o
>> obj-$(CONFIG_VIDEO_DS90UB960) += ds90ub960.o
>> obj-$(CONFIG_VIDEO_DW9714) += dw9714.o
>> +obj-$(CONFIG_VIDEO_DW9719) += dw9719.o
>> obj-$(CONFIG_VIDEO_DW9768) += dw9768.o
>> obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o
>> obj-$(CONFIG_VIDEO_ET8EK8) += et8ek8/
>> diff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c
>> new file mode 100644
>> index 000000000000..7b83ae102131
>> --- /dev/null
>> +++ b/drivers/media/i2c/dw9719.c
>> @@ -0,0 +1,427 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +// Copyright (c) 2012 Intel Corporation
>> +
>> +/*
>> + * Based on linux/modules/camera/drivers/media/i2c/imx/dw9719.c in this repo:
>> + * https://github.com/ZenfoneArea/android_kernel_asus_zenfone5
>> + */
>> +
>> +#include <asm/unaligned.h>
>> +
>> +#include <linux/delay.h>
>> +#include <linux/i2c.h>
>> +#include <linux/pm_runtime.h>
>> +#include <linux/regulator/consumer.h>
>> +#include <linux/types.h>
>> +
>> +#include <media/v4l2-common.h>
>> +#include <media/v4l2-ctrls.h>
>> +#include <media/v4l2-subdev.h>
>> +
>> +#define DW9719_MAX_FOCUS_POS 1023
>> +#define DW9719_CTRL_STEPS 16
>> +#define DW9719_CTRL_DELAY_US 1000
>> +#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
>> +
>> +#define DW9719_INFO 0
>> +#define DW9719_ID 0xF1
>> +#define DW9719_CONTROL 2
>> +#define DW9719_VCM_CURRENT 3
>> +
>> +#define DW9719_MODE 6
>> +#define DW9719_VCM_FREQ 7
>> +
>> +#define DW9719_MODE_SAC_SHIFT 4
>> +#define DW9719_MODE_SAC3 4
>> +
>> +#define DW9719_DEFAULT_VCM_FREQ 0x60
>> +
>> +#define DW9719_ENABLE_RINGING 0x02
>
> This register setup and the ramping up/down code is nearly identical
> to the existing dw9807-vcm driver[1]. Admittedly that doesn't expose
> SAC (Smart Actuator Control) for damping the movement, but dw9807 does
> support it.
>
> The only really quirky bit here is the "Jiggle SCL pin to wake up
> device", but I can't find a datasheet to know anything more about
> that. The other apparent distinction would be whether DW9719 has the
> VBUSY bit in the status register that dw9807 is abiding by, whilst
> this driver doesn't.
>
> Should this be a new driver, or a variant of dw9807-vcm?

So I did a quick check and there are some interesting differences,
like the dw9719 code writing 1 to the CTRL register on resume /
powerup while as the dw9807 code writes 0 on resume / powerup.

And I have been unable to find a datasheet for either model.

This means that both drivers have some black-box aspects,
like the powerup differences, to them (both come from Android source
dumps I think).

This + the small size of these drivers, makes me think that it
would be best to just keep this as a separate driver.

So for the next standalone (not as part of this series)
submission I plan to stick with having a separate driver
and I'll try to address all the other review remarks.

Regards,

Hans