media: i2c: Add support for DW9768 VCM
Subsystems (5)
v10 cover media: i2c: Add support for DW9768 VCM
Hello,
This series adds DT binding and V4L2 sub-device driver for Dongwoon's DW9768. DW9768 is a 10-bit DAC with 100mA output current sink capability, designed for linear control of voice coil motor(VCM).
This driver creates a V4L2 sub-device and provides control to set the desired focus via II2C serial interface.
It controls the position with 10-bit DAC data D[9:0] and seperates two 8-bit registers to control the VCM position as belows.DAC_MSB: D[9:8](ADDR: 0x03):
+---+---+---+---+---+---+---+---+
|---|---|---|---|---|---|D09|D08|
+---+---+---+---+---+---+---+---+
DAC_LSB: D[7:0](ADDR: 0x04):
+---+---+---+---+---+---+---+---+
|D07|D06|D05|D04|D03|D02|D01|D00|
+---+---+---+---+---+---+---+---+This driver supports:
- set DW9768 to standby mode once suspend and turn it back to active if resume
- set the desired focus via V4L2_CID_FOCUS_ABSOLUTE ctrl
Previous versions of this patch-set can be found here:
v9: https://lore.kernel.org/linux-media/[email protected]/
v8: https://lore.kernel.org/linux-media/[email protected]/
v7: https://lore.kernel.org/linux-media/[email protected]/
v6: https://lore.kernel.org/linux-media/[email protected]/
v5: https://lore.kernel.org/linux-media/[email protected]/
v4: https://lore.kernel.org/linux-media/[email protected]/
v3: https://lore.kernel.org/linux-media/[email protected]/
v2: https://lore.kernel.org/linux-media/[email protected]/
v1: https://lore.kernel.org/linux-media/[email protected]/
Mainly changes of v10 address comments from Sakari, Tomasz, Bingbu. Compared to v9:
- Add reviewed-by for VCM driver
- Re-send plain patch to test if there are still weird trailing whitespaces
Please review.
Thanks.
Dongchun Zhu (2):
media: dt-bindings: media: i2c: Document DW9768 bindings
media: i2c: dw9768: Add DW9768 VCM driver
.../bindings/media/i2c/dongwoon,dw9768.yaml | 100 ++++ MAINTAINERS | 8 + drivers/media/i2c/Kconfig | 12 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/dw9768.c | 554 +++++++++++++++++++++ 5 files changed, 675 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/dongwoon,dw9768.yaml create mode 100644 drivers/media/i2c/dw9768.c
Signature · 1 line
2.9.2
PATCH v10 1/2 media: dt-bindings: media: i2c: Document DW9768 bindings
Add Device Tree Binding Documentation for Dongwoon Anatech DW9768 voice coil actuator.
--- .../bindings/media/i2c/dongwoon,dw9768.yaml | 100 +++++++++++++++++++++ MAINTAINERS | 7 ++ 2 files changed, 107 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/dongwoon,dw9768.yaml
Documentation/devicetree/bindings/media/i2c/dongwoon,dw9768.yaml new file +100 -0
@@ -0,0 +1,100 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# Copyright (c) 2020 MediaTek Inc. +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/dongwoon,dw9768.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dongwoon Anatech DW9768 Voice Coil Motor (VCM) Device Tree Bindings + +maintainers: + - Dongchun Zhu <[email protected]> + +description: |- + The Dongwoon DW9768 is a single 10-bit digital-to-analog (DAC) converter + with 100 mA output current sink capability. VCM current is controlled with + a linear mode driver. The DAC is controlled via a 2-wire (I2C-compatible) + serial interface that operates at clock rates up to 1MHz. This chip + integrates Advanced Actuator Control (AAC) technology and is intended for + driving voice coil lenses in camera modules. + +properties: + compatible: + enum: + - dongwoon,dw9768 # for DW9768 VCM + - giantec,gt9769 # for GT9769 VCM + + reg: + maxItems: 1 + + vin-supply: + description: + Definition of the regulator used as Digital I/O voltage supply. + + vdd-supply: + description: + Definition of the regulator used as Digital core voltage supply. + + dongwoon,aac-mode: + description: + Indication of AAC mode select. + allOf: + - $ref: "/schemas/types.yaml#/definitions/uint32" + - enum: + - 1 # AAC2 mode(operation time# 0.48 x Tvib) + - 2 # AAC3 mode(operation time# 0.70 x Tvib) + - 3 # AAC4 mode(operation time# 0.75 x Tvib) + - 5 # AAC8 mode(operation time# 1.13 x Tvib) + default: 2 + + dongwoon,aac-timing: + description: + Number of AAC Timing count that controlled by one 6-bit period of + vibration register AACT[5:0], the unit of which is 100 us. + allOf: + - $ref: "/schemas/types.yaml#/definitions/uint32" + - default: 0x20 + minimum: 0x00 + maximum: 0x3f + + dongwoon,clock-presc: + description: + Indication of VCM internal clock dividing rate select, as one multiple + factor to calculate VCM ring periodic time Tvib. + allOf: + - $ref: "/schemas/types.yaml#/definitions/uint32" + - enum: + - 0 # Dividing Rate - 2 + - 1 # Dividing Rate - 1 + - 2 # Dividing Rate - 1/2 + - 3 # Dividing Rate - 1/4 + - 4 # Dividing Rate - 8 + - 5 # Dividing Rate - 4 + default: 1 + +required: + - compatible + - reg + - vin-supply + - vdd-supply + +additionalProperties: false + +examples: + - | + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + dw9768: camera-lens@c { + compatible = "dongwoon,dw9768"; + reg = <0x0c>; + + vin-supply = <&mt6358_vcamio_reg>; + vdd-supply = <&mt6358_vcama2_reg>; + dongwoon,aac-timing = <0x39>; + }; + }; + +...
MAINTAINERS +7 -0
@@ -5215,6 +5215,13 @@ T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/i2c/dongwoon,dw9714.txt F: drivers/media/i2c/dw9714.c +DONGWOON DW9768 LENS VOICE COIL DRIVER +M: Dongchun Zhu <[email protected]> +L: [email protected] +S: Maintained +T: git git://linuxtv.org/media_tree.git +F: Documentation/devicetree/bindings/media/i2c/dongwoon,dw9768.yaml + DONGWOON DW9807 LENS VOICE COIL DRIVER M: Sakari Ailus <[email protected]> L: [email protected]
Signature · 1 line
2.9.2
PATCH v10 2/2 media: i2c: dw9768: Add DW9768 VCM driver
In reply to Dongchun ZhuAdd a V4L2 sub-device driver for DW9768 VCM.
--- MAINTAINERS | 1 + drivers/media/i2c/Kconfig | 12 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/dw9768.c | 554 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 568 insertions(+) create mode 100644 drivers/media/i2c/dw9768.c
MAINTAINERS +1 -0
@@ -5221,6 +5221,7 @@ L: [email protected] S: Maintained T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/i2c/dongwoon,dw9768.yaml +F: drivers/media/i2c/dw9768.c DONGWOON DW9807 LENS VOICE COIL DRIVER M: Sakari Ailus <[email protected]>
drivers/media/i2c/Kconfig +12 -0
@@ -1253,6 +1253,18 @@ config VIDEO_DW9714 capability. 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_V4L2 + select MEDIA_CONTROLLER + select VIDEO_V4L2_SUBDEV_API + select V4L2_FWNODE + help + This is a driver for the DW9768 camera lens voice coil. + DW9768 is a 10 bit DAC with 100mA output current sink + capability. This is designed for linear control of + voice coil motors, controlled via I2C serial interface. + config VIDEO_DW9807_VCM tristate "DW9807 lens voice coil support" depends on I2C && VIDEO_V4L2
drivers/media/i2c/Makefile +1 -0
@@ -24,6 +24,7 @@ obj-$(CONFIG_VIDEO_SAA6752HS) += saa6752hs.o obj-$(CONFIG_VIDEO_AD5820) += ad5820.o obj-$(CONFIG_VIDEO_AK7375) += ak7375.o obj-$(CONFIG_VIDEO_DW9714) += dw9714.o +obj-$(CONFIG_VIDEO_DW9768) += dw9768.o obj-$(CONFIG_VIDEO_DW9807_VCM) += dw9807-vcm.o obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
drivers/media/i2c/dw9768.c new file +554 -0
554 lines not on this page · raw message
Signature · 1 line
2.9.2
Re: [PATCH V10 2/2] media: i2c: dw9768: Add DW9768 VCM driver
On (20/07/03 16:04), Dongchun Zhu wrote:
[..]
Quoted 14 lines
drivers/media/i2c/dw9768.c new file +14
-0+static int dw9768_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct dw9768 *dw9768; +unsigned int i; +int ret; + + dw9768 =devm_kzalloc (dev,sizeof (*dw9768),GFP_KERNEL ); +if (!dw9768) +return -ENOMEM ; + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&dw9768->sd, client, &dw9768_ops); +
[..]
Quoted 6 lines
drivers/media/i2c/dw9768.c new file +6
-0+ dw9768->sd.entity.function =MEDIA_ENT_F_LENS ; + +pm_runtime_enable (dev); +if (!pm_runtime_enabled (dev)) { + ret =dw9768_runtime_resume (dev); +if (ret <0 ) {
drivers/media/i2c/dw9768.c line 495
Quoted 10 lines
drivers/media/i2c/dw9768.c new file +10
-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 err_power_off; + }
I would expect to see a slightly different order here: first set everything up, then expose the device to PM subsystem.
[..]
drivers/media/i2c/dw9768.c line 523
Quoted 12 lines
drivers/media/i2c/dw9768.c new file +12
-0+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)) +dw9768_runtime_suspend (&client->dev); +pm_runtime_set_suspended (&client->dev);
Ditto. Shall we first disable PM (so that we won't get any unexpected PM callbacks) and then destroy the device?
-ss
Re: [PATCH V10 2/2] media: i2c: dw9768: Add DW9768 VCM driver
Quoted 29 lines · Sergey Senozhatsky
On (20/07/03 16:04), Dongchun Zhu wrote:
[..]Quoted 14 lines
drivers/media/i2c/dw9768.c new file +14
-0+static int dw9768_probe (struct i2c_client *client) +{ +struct device *dev = &client->dev; +struct dw9768 *dw9768; +unsigned int i; +int ret; + + dw9768 =devm_kzalloc (dev,sizeof (*dw9768),GFP_KERNEL ); +if (!dw9768) +return -ENOMEM ; + +/* Initialize subdev */ +v4l2_i2c_subdev_init (&dw9768->sd, client, &dw9768_ops); +[..]
Quoted 11 lines
drivers/media/i2c/dw9768.c new file +11
-0+ dw9768->sd.entity.function =MEDIA_ENT_F_LENS ; + +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; + } + } +
Quoted 9 lines
drivers/media/i2c/dw9768.c line 495
Quoted 5 lines
drivers/media/i2c/dw9768.c new file +5
-0+ ret =v4l2_async_register_subdev (&dw9768->sd); +if (ret <0 ) { +dev_err (dev,"failed to register V4L2 subdev: %d" , ret); + goto err_power_off; + }I would expect to see a slightly different order here: first set everything up, then expose the device to PM subsystem.
Thanks for chiming in. However, the code above is correct. Runtime PM callbacks don't usually rely on the availability of any userspace-facing components, while the opposite is true - when the device is registered to the userspace, it must have all the initialization aspects completed and that includes initialization of runtime PM.
Quoted 16 lines
[..]
drivers/media/i2c/dw9768.c line 523
Quoted 12 lines
drivers/media/i2c/dw9768.c new file +12
-0+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)) +dw9768_runtime_suspend (&client->dev); +pm_runtime_set_suspended (&client->dev);Ditto. Shall we first disable PM (so that we won't get any unexpected PM callbacks) and then destroy the device?
Ditto. +/- the opposite order
Best regards,
Tomasz