The DW9800K's properties are too different to justify sharing the same bindings file as the dw9719, Create a separate bindings documentation for the Dongwoon Anatech DW9800K with its updated properties. More specifically: The DW9800K did not share the SAC1 and SAC6 modes that the DW9719 used. Description of vcm-prescale does not match the calculations labeled in the DW9800K datasheet for how clock diving rate is computed. New property timing-control introduced to offer more fine-tuned dividing options available to the DW9800K. Signed-off-by: Griffin Kroah-Hartman --- .../bindings/media/i2c/dongwoon,dw9719.yaml | 1 - .../bindings/media/i2c/dongwoon,dw9800k.yaml | 91 ++++++++++++++++++++++ 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9719.yaml b/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9719.yaml index 8e8d62436e0d0c4f9af9e52262b23881abd37cec..38db0764c0f70ad49295dcddc182b7e100a68b29 100644 --- a/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9719.yaml +++ b/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9719.yaml @@ -21,7 +21,6 @@ properties: - dongwoon,dw9718s - dongwoon,dw9719 - dongwoon,dw9761 - - dongwoon,dw9800k reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9800k.yaml b/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9800k.yaml new file mode 100644 index 0000000000000000000000000000000000000000..99f3b506cf12c63ddef1e3d18fd59179a5e7800c --- /dev/null +++ b/Documentation/devicetree/bindings/media/i2c/dongwoon,dw9800k.yaml @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/dongwoon,dw9800k.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Dongwoon Anatech DW9800K Bi-Direction Voice Coil Motor (Bi-VCM) Controller + +maintainers: + - Luca Weiss + - Griffin Kroah-Hartman + +description: + The Dongwoon DW9800K is a single 10-bit digital-to-analog converter with + +-130 mA output current sink capability, designed for linear control of + bi-directional voice coil motors (Bi-VCM) in camera lenses. This chip + provides a Smart Actuator Control (SAC) mode intended for minimizing + mechanical vibration. + +properties: + compatible: + enum: + - dongwoon,dw9800k + + reg: + maxItems: 1 + + vdd-supply: + description: VDD power supply, can range from 2.3V to 4.8V + + dongwoon,sac-mode: + description: > + Slew Rate Control mode to use: direct, LSC (Linear Slope Control) or + SAC2-SAC5 (Smart Actuator Control). + $ref: /schemas/types.yaml#/definitions/uint32 + enum: + - 0 # Direct mode + - 1 # LSC mode + - 2 # SAC2 mode (operation time# 0.48 x Tvib) + - 3 # SAC3 mode (operation time# 0.72 x Tvib) + - 4 # SAC4 mode (operation time# 1.20 x Tvib) + - 5 # SAC5 mode (operation time# 1.64 x Tvib) + default: 3 + + dongwoon,vcm-prescale: + description: + Indication of VCM internal clock dividing rate select, as one multiple + factor to calculate VCM ring periodic time Tvib. + $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 + + dongwoon,timing-control: + description: + In LSC mode (252 + value * 4) * divider value in microseconds + In SAC mode (6.3 + value * 0.1) * divider value in milliseconds + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0x00 + maximum: 0x3f + default: 0x20 + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + actuator@c { + compatible = "dongwoon,dw9800k"; + reg = <0x0c>; + + vdd-supply = <&pm8937_l17>; + + dongwoon,sac-mode = <4>; + dongwoon,vcm-prescale = <0>; + dongwoon,timing-control = <16>; + }; + }; -- 2.43.0 The previous DW9800K driver code was created without access to a datasheet for the part, now that we have one we can clean up some misunderstandings and add some features for further expandability. More specifically: Previously we were blindly writing registers to their downstream values, Now we know what the correct default values of SAC and SACT, and write to the correct bits as specified from the datasheet. We found that the device does indeed have an ID, and add it to the switch statement when setting up the default device properties. The largest change would be the implementation of "Ringing," this is actually an internal switch bit used to differentiate whether the SAC (smart actuator control) modes are enabled. if the "ringing" bit is zero, then actuator modes DIRECT and LSC are available(based on the value written to the Mode register). If the bit is 1, SAC2-SAC5 are available. For the devices we tested this driver on, no new values are being written, but now the option for further use of the DW9800k is available to others if they wish to do so. Fixes: 083f7f0dce16 ("media: i2c: dw9719: Add DW9800K support") Signed-off-by: Griffin Kroah-Hartman --- drivers/media/i2c/dw9719.c | 68 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/dw9719.c b/drivers/media/i2c/dw9719.c index 3b7ba88fd67c044ef9005a0aac6a5d26ab939a90..2879dc99088005cba2567b2a73627c91c270906b 100644 --- a/drivers/media/i2c/dw9719.c +++ b/drivers/media/i2c/dw9719.c @@ -68,9 +68,18 @@ #define DW9761_VCM_PRELOAD CCI_REG8(8) #define DW9761_DEFAULT_VCM_PRELOAD 0x73 -#define DW9800K_DEFAULT_SAC 1 +#define DW9800K_ID 0xEB +#define DW9800K_DEFAULT_SAC 3 #define DW9800K_MODE_SAC_SHIFT 6 -#define DW9800K_DEFAULT_VCM_FREQ 0x10 + +#define DW9800K_RESONANCE CCI_REG8(7) + +#define DW9800K_DEFAULT_DIV 0x01 +#define DW9800K_DIV_SHIFT 6 +#define DW9800K_DIV_LOW_SHIFT 2 + +#define DW9800K_DEFAULT_SACT 0x20 + #define to_dw9719_device(x) container_of(x, struct dw9719_device, sd) @@ -90,6 +99,7 @@ struct dw9719_device { u32 mode_low_bits; u32 sac_mode; u32 vcm_freq; + u32 sac_time; struct dw9719_v4l2_ctrls { struct v4l2_ctrl_handler handler; @@ -140,10 +150,6 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect) dw9719->sac_mode = DW9718S_DEFAULT_SAC; dw9719->vcm_freq = DW9718S_DEFAULT_VCM_FREQ; goto props; - case DW9800K: - dw9719->sac_mode = DW9800K_DEFAULT_SAC; - dw9719->vcm_freq = DW9800K_DEFAULT_VCM_FREQ; - goto props; default: break; } @@ -165,6 +171,11 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect) dw9719->sac_mode = DW9761_DEFAULT_SAC; dw9719->vcm_freq = DW9761_DEFAULT_VCM_FREQ; break; + case DW9800K_ID: + dw9719->sac_mode = DW9800K_DEFAULT_SAC; + dw9719->vcm_freq = DW9800K_DEFAULT_DIV; + dw9719->sac_time = DW9800K_DEFAULT_SACT; + break; default: dev_err(dw9719->dev, "Error unknown device id 0x%02llx\n", val); @@ -185,15 +196,52 @@ static int dw9719_power_up(struct dw9719_device *dw9719, bool detect) /* Optional indication of VCM prescale */ device_property_read_u32(dw9719->dev, "dongwoon,vcm-prescale", &dw9719->vcm_freq); + + /* Optional indication of SAC timing */ + device_property_read_u32(dw9719->dev, "dongwoon,timing-control", + &dw9719->sac_time); } switch (dw9719->model) { - case DW9800K: - cci_write(dw9719->regmap, DW9719_CONTROL, DW9719_ENABLE_RINGING, &ret); + case DW9800K: { + int ring, sac; + + /* + * Enable ringing for SAC3-SAC5 + * + * sac_mode reg Mode + * =========================== + * 0 0X Direct + * 1 1X LSC + * 2 00 SAC2 + * 3 01 SAC3 + * 4 10 SAC4 + * 5 11 SAC5 + */ + switch (dw9719->sac_mode) { + case 0: + ring = 0; + sac = 0; + break; + case 1: + ring = 0; + sac = 2; + break; + default: + ring = DW9719_ENABLE_RINGING; + sac = dw9719->sac_mode - 2; + break; + } + cci_write(dw9719->regmap, DW9719_CONTROL, ring, &ret); + /* DIV is 3 bits split over the bottom bit in reg 6 and the top 2 bits in reg 7 */ cci_write(dw9719->regmap, DW9719_MODE, - dw9719->sac_mode << DW9800K_MODE_SAC_SHIFT, &ret); - cci_write(dw9719->regmap, DW9719_VCM_FREQ, dw9719->vcm_freq, &ret); + (sac << DW9800K_MODE_SAC_SHIFT) | + (dw9719->vcm_freq >> DW9800K_DIV_LOW_SHIFT), &ret); + cci_write(dw9719->regmap, DW9800K_RESONANCE, + (dw9719->vcm_freq << DW9800K_DIV_SHIFT) | + dw9719->sac_time, &ret); break; + } case DW9718S: /* Datasheet says [OCP/UVLO] should be disabled below 2.5V */ dw9719->sac_mode &= DW9718S_CONTROL_SAC_MASK; -- 2.43.0 Update the node for the DW9800K for correctness. Now we correctly select SAC3 mode and enable timing-control with the newly updated device tree bindings. This is a breaking change for a part that was previously functioning, but only due to manual register writes in the driver. Now that we have the correct documentation we are able to update everything to ensure functionality with other devices using this part. Signed-off-by: Griffin Kroah-Hartman --- arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts b/arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts index f41ad446a39e2308abaea68a6b31a7e387881bf2..a657a5dcba9cdf750fab2478ca319f3a592ea295 100644 --- a/arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts +++ b/arch/arm64/boot/dts/qcom/qcm6490-fairphone-fp5.dts @@ -665,8 +665,9 @@ camera_imx858_dw9800k: actuator@e { reg = <0x0e>; vdd-supply = <&vreg_afvdd_2p8>; - dongwoon,sac-mode = <1>; - dongwoon,vcm-prescale = <16>; + dongwoon,sac-mode = <3>; + dongwoon,vcm-prescale = <0>; + dongwoon,timing-control = <16>; }; /* IMX858 @ 29 */ -- 2.43.0