From 79f0520436fc116fc377862069b83bda06c8c9ff Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Mon, 12 Aug 2024 14:53:59 +0000 Subject: [PATCH 1/8] dts: haptics: drv2605: Documents GPIOs Documents the enable GPI and the input/trigger GPI in the dt bindings. Signed-off-by: Ricardo Rivera-Matos --- dts/bindings/haptics/ti,drv2605.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dts/bindings/haptics/ti,drv2605.yaml b/dts/bindings/haptics/ti,drv2605.yaml index 0b71cc007a63e..b2e9d8bf50b2a 100644 --- a/dts/bindings/haptics/ti,drv2605.yaml +++ b/dts/bindings/haptics/ti,drv2605.yaml @@ -33,3 +33,9 @@ properties: - "MEDIUM" - "HIGH" - "VERY_HIGH" + en-gpios: + type: phandle-array + description: GPIO to enable and disable the device. + in-trig-gpios: + type: phandle-array + description: GPIO to trigger ROM waveforms or drive an input signal. From a67d6685e4020bea7e176028b28e755ff60dcb3a Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Mon, 12 Aug 2024 15:06:42 +0000 Subject: [PATCH 2/8] drivers: haptics: drv2605: Drops ti prefix from DT props Removes the "ti_" prefix form the the device tree properties. Signed-off-by: Ricardo Rivera-Matos --- drivers/haptics/drv2605.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/haptics/drv2605.c b/drivers/haptics/drv2605.c index 3427894bec919..022611bdd9b07 100644 --- a/drivers/haptics/drv2605.c +++ b/drivers/haptics/drv2605.c @@ -601,11 +601,11 @@ static const struct haptics_driver_api drv2605_driver_api = { \ static const struct drv2605_config drv2605_config_##inst = { \ .i2c = I2C_DT_SPEC_INST_GET(inst), \ - .en_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, ti_en_gpios, {}), \ - .in_trig_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, ti_in_trig_gpios, {}), \ - .feedback_brake_factor = DT_INST_ENUM_IDX_OR(inst, ti_feedback_brake_factor, 3), \ - .loop_gain = DT_INST_ENUM_IDX_OR(inst, ti_loop_gain, 2), \ - .actuator_mode = DT_INST_ENUM_IDX_OR(inst, ti_actuator_mode, 0), \ + .en_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, en_gpios, {}), \ + .in_trig_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, in_trig_gpios, {}), \ + .feedback_brake_factor = DT_INST_ENUM_IDX_OR(inst, feedback_brake_factor, 3), \ + .loop_gain = DT_INST_ENUM_IDX_OR(inst, loop_gain, 2), \ + .actuator_mode = DT_INST_ENUM_IDX_OR(inst, actuator_mode, 0), \ }; \ \ static struct drv2605_data drv2605_data_##inst = { \ From ab9b46908bb069963d46a8e33738a8a45ad1f2d7 Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Mon, 12 Aug 2024 18:31:39 +0000 Subject: [PATCH 3/8] drivers: haptics: drv2605: Drops unused drv2605_pm_state Removes an unused enum defining the DRV2605 power states. This enum is dead code so it is being removed. Signed-off-by: Ricardo Rivera-Matos --- drivers/haptics/drv2605.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/drivers/haptics/drv2605.c b/drivers/haptics/drv2605.c index 022611bdd9b07..75a639e4c6902 100644 --- a/drivers/haptics/drv2605.c +++ b/drivers/haptics/drv2605.c @@ -124,12 +124,6 @@ LOG_MODULE_REGISTER(DRV2605, CONFIG_HAPTICS_LOG_LEVEL); #define DRV2605_POWER_UP_DELAY_US 250 -enum drv2605_pm_state { - DRV2605_PM_STATE_SHUTDOWN, - DRV2605_PM_STATE_STANDBY, - DRV2605_PM_STATE_ACTIVE, -}; - struct drv2605_config { struct i2c_dt_spec i2c; struct gpio_dt_spec en_gpio; From 9b1da2d85027fcb66e18122ad21e7217a3e6e741 Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Thu, 15 Aug 2024 18:42:51 +0000 Subject: [PATCH 4/8] dts: bindings: drv2605: Requires actuator-mode prop Requires the actuator-mode property to be set as there is no safe default value. Signed-off-by: Ricardo Rivera-Matos --- dts/bindings/haptics/ti,drv2605.yaml | 1 + tests/drivers/build_all/haptics/i2c.dtsi | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dts/bindings/haptics/ti,drv2605.yaml b/dts/bindings/haptics/ti,drv2605.yaml index b2e9d8bf50b2a..1664a0f93795f 100644 --- a/dts/bindings/haptics/ti,drv2605.yaml +++ b/dts/bindings/haptics/ti,drv2605.yaml @@ -11,6 +11,7 @@ include: i2c-device.yaml properties: actuator-mode: + required: true type: string enum: - "ERM" diff --git a/tests/drivers/build_all/haptics/i2c.dtsi b/tests/drivers/build_all/haptics/i2c.dtsi index 2038347e11ada..a4fc6bb6c2b69 100644 --- a/tests/drivers/build_all/haptics/i2c.dtsi +++ b/tests/drivers/build_all/haptics/i2c.dtsi @@ -11,4 +11,6 @@ drv2605@0 { compatible = "ti,drv2605"; reg = <0x0>; status = "okay"; + + actuator-mode = "LRA"; }; From 4ac9a9b942c147c8b467da4e2cfdcf66f2c450df Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Tue, 13 Aug 2024 16:53:08 +0000 Subject: [PATCH 5/8] drivers: haptics: drv2605: Pick up property defaults from DT Adds the default value for the existing properties to the device tree and fall back on those values at initialization if necessary. Signed-off-by: Ricardo Rivera-Matos --- drivers/haptics/drv2605.c | 6 +++--- dts/bindings/haptics/ti,drv2605.yaml | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/haptics/drv2605.c b/drivers/haptics/drv2605.c index 75a639e4c6902..87eb4b7e44218 100644 --- a/drivers/haptics/drv2605.c +++ b/drivers/haptics/drv2605.c @@ -597,9 +597,9 @@ static const struct haptics_driver_api drv2605_driver_api = { .i2c = I2C_DT_SPEC_INST_GET(inst), \ .en_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, en_gpios, {}), \ .in_trig_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, in_trig_gpios, {}), \ - .feedback_brake_factor = DT_INST_ENUM_IDX_OR(inst, feedback_brake_factor, 3), \ - .loop_gain = DT_INST_ENUM_IDX_OR(inst, loop_gain, 2), \ - .actuator_mode = DT_INST_ENUM_IDX_OR(inst, actuator_mode, 0), \ + .feedback_brake_factor = DT_INST_ENUM_IDX(inst, feedback_brake_factor), \ + .loop_gain = DT_INST_ENUM_IDX(inst, loop_gain), \ + .actuator_mode = DT_INST_ENUM_IDX(inst, actuator_mode), \ }; \ \ static struct drv2605_data drv2605_data_##inst = { \ diff --git a/dts/bindings/haptics/ti,drv2605.yaml b/dts/bindings/haptics/ti,drv2605.yaml index 1664a0f93795f..6b3932feb6180 100644 --- a/dts/bindings/haptics/ti,drv2605.yaml +++ b/dts/bindings/haptics/ti,drv2605.yaml @@ -27,6 +27,11 @@ properties: - "8X" - "16X" - "DISABLED" + default: "3X" + description: | + Selects the feedback gain ratio between braking gain and driving gain. + According to the datasheet, a value of 2 ("3X") is valid for most + actuators. loop-gain: type: string enum: @@ -34,6 +39,10 @@ properties: - "MEDIUM" - "HIGH" - "VERY_HIGH" + default: "HIGH" + description: | + Selects a loop gain for the feedback control. According to the datasheet, + a value of 2 ("HIGH") is valid for most actuators. en-gpios: type: phandle-array description: GPIO to enable and disable the device. From edf9eebf2a8a7d7a8f539fe20ca50de5ba805f54 Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Tue, 13 Aug 2024 16:12:08 +0000 Subject: [PATCH 6/8] drivers: haptics: drv2605: Introduces rated voltage prop Adds support for boot time configuration of the rated voltage at initialization via "vib-rated-mv" devicetree property. Signed-off-by: Ricardo Rivera-Matos --- drivers/haptics/drv2605.c | 10 ++++++++++ dts/bindings/haptics/ti,drv2605.yaml | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/drivers/haptics/drv2605.c b/drivers/haptics/drv2605.c index 87eb4b7e44218..30306a08e5657 100644 --- a/drivers/haptics/drv2605.c +++ b/drivers/haptics/drv2605.c @@ -124,6 +124,10 @@ LOG_MODULE_REGISTER(DRV2605, CONFIG_HAPTICS_LOG_LEVEL); #define DRV2605_POWER_UP_DELAY_US 250 +#define DRV2605_VOLTAGE_SCALE_FACTOR_MV 5600 + +#define DRV2605_CALCULATE_VOLTAGE(_volt) ((_volt * 255) / DRV2605_VOLTAGE_SCALE_FACTOR_MV) + struct drv2605_config { struct i2c_dt_spec i2c; struct gpio_dt_spec en_gpio; @@ -452,6 +456,11 @@ static int drv2605_hw_config(const struct device *dev) return ret; } + ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_RATED_VOLTAGE, config->rated_voltage); + if (ret < 0) { + return ret; + } + return 0; } @@ -600,6 +609,7 @@ static const struct haptics_driver_api drv2605_driver_api = { .feedback_brake_factor = DT_INST_ENUM_IDX(inst, feedback_brake_factor), \ .loop_gain = DT_INST_ENUM_IDX(inst, loop_gain), \ .actuator_mode = DT_INST_ENUM_IDX(inst, actuator_mode), \ + .rated_voltage = DRV2605_CALCULATE_VOLTAGE(DT_INST_PROP(inst, vib_rated_mv)), \ }; \ \ static struct drv2605_data drv2605_data_##inst = { \ diff --git a/dts/bindings/haptics/ti,drv2605.yaml b/dts/bindings/haptics/ti,drv2605.yaml index 6b3932feb6180..f27a241a07663 100644 --- a/dts/bindings/haptics/ti,drv2605.yaml +++ b/dts/bindings/haptics/ti,drv2605.yaml @@ -43,6 +43,12 @@ properties: description: | Selects a loop gain for the feedback control. According to the datasheet, a value of 2 ("HIGH") is valid for most actuators. + vib-rated-mv: + type: int + default: 3200 + description: | + Sets the reference voltage for full-scale output during closed-loop + operation. The default value is inherited from ti,drv260x.yaml in Linux. en-gpios: type: phandle-array description: GPIO to enable and disable the device. From 68ba03203fe9a898911715b735c9cf978f23a6d0 Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Tue, 13 Aug 2024 16:27:08 +0000 Subject: [PATCH 7/8] drivers: haptics: drv2605: Introduces overdrive clamp prop Adds "vib-overdrive-mv" device tree property to configure the overdrive clamp at initialization. Signed-off-by: Ricardo Rivera-Matos --- drivers/haptics/drv2605.c | 8 ++++++++ dts/bindings/haptics/ti,drv2605.yaml | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/drivers/haptics/drv2605.c b/drivers/haptics/drv2605.c index 30306a08e5657..bc8c2f3a8c004 100644 --- a/drivers/haptics/drv2605.c +++ b/drivers/haptics/drv2605.c @@ -461,6 +461,12 @@ static int drv2605_hw_config(const struct device *dev) return ret; } + ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_OVERDRIVE_CLAMP_VOLTAGE, + config->overdrive_clamp_voltage); + if (ret < 0) { + return ret; + } + return 0; } @@ -610,6 +616,8 @@ static const struct haptics_driver_api drv2605_driver_api = { .loop_gain = DT_INST_ENUM_IDX(inst, loop_gain), \ .actuator_mode = DT_INST_ENUM_IDX(inst, actuator_mode), \ .rated_voltage = DRV2605_CALCULATE_VOLTAGE(DT_INST_PROP(inst, vib_rated_mv)), \ + .overdrive_clamp_voltage = \ + DRV2605_CALCULATE_VOLTAGE(DT_INST_PROP(inst, vib_overdrive_mv)), \ }; \ \ static struct drv2605_data drv2605_data_##inst = { \ diff --git a/dts/bindings/haptics/ti,drv2605.yaml b/dts/bindings/haptics/ti,drv2605.yaml index f27a241a07663..484267c4abe9b 100644 --- a/dts/bindings/haptics/ti,drv2605.yaml +++ b/dts/bindings/haptics/ti,drv2605.yaml @@ -49,6 +49,12 @@ properties: description: | Sets the reference voltage for full-scale output during closed-loop operation. The default value is inherited from ti,drv260x.yaml in Linux. + vib-overdrive-mv: + type: int + default: 3200 + description: | + Sets a clamp so that the automatic overdrive is bounded. The default + value is inherited from ti,drv260x.yaml in Linux. en-gpios: type: phandle-array description: GPIO to enable and disable the device. From 341aeeb8c206f165343d66b5f2a97076fe2d8fb3 Mon Sep 17 00:00:00 2001 From: Ricardo Rivera-Matos Date: Thu, 15 Aug 2024 19:09:32 +0000 Subject: [PATCH 8/8] drivers: haptics: drv2605: Hard codes open loop mode for LRA mode Enables open loop operation when initializing into LRA mode. Open loop operation is enabled by default for ERM mode. This is hard coded for LRA mode because calibration is currently unsupported. Signed-off-by: Ricardo Rivera-Matos --- drivers/haptics/drv2605.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/haptics/drv2605.c b/drivers/haptics/drv2605.c index bc8c2f3a8c004..a1de61512f2b3 100644 --- a/drivers/haptics/drv2605.c +++ b/drivers/haptics/drv2605.c @@ -90,6 +90,9 @@ LOG_MODULE_REGISTER(DRV2605, CONFIG_HAPTICS_LOG_LEVEL); #define DRV2605_LOOP_GAIN GENMASK(3, 2) #define DRV2605_BEMF_GAIN GENMASK(1, 0) +#define DRV2605_ACTUATOR_MODE_ERM 0 +#define DRV2605_ACTUATOR_MODE_LRA 1 + #define DRV2605_REG_CONTROL1 0x1b #define DRV2605_STARTUP_BOOST BIT(7) #define DRV2605_AC_COUPLE BIT(5) @@ -467,6 +470,14 @@ static int drv2605_hw_config(const struct device *dev) return ret; } + if (config->actuator_mode == DRV2605_ACTUATOR_MODE_LRA) { + ret = i2c_reg_update_byte_dt(&config->i2c, DRV2605_REG_CONTROL3, + DRV2605_LRA_OPEN_LOOP, DRV2605_LRA_OPEN_LOOP); + if (ret < 0) { + return ret; + } + } + return 0; }