Skip to content

Commit 38b827d

Browse files
rriveramcrusnashif
authored andcommitted
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 <[email protected]>
1 parent 857b9df commit 38b827d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

drivers/haptics/drv2605.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ LOG_MODULE_REGISTER(DRV2605, CONFIG_HAPTICS_LOG_LEVEL);
124124

125125
#define DRV2605_POWER_UP_DELAY_US 250
126126

127+
#define DRV2605_VOLTAGE_SCALE_FACTOR_MV 5600
128+
129+
#define DRV2605_CALCULATE_VOLTAGE(_volt) ((_volt * 255) / DRV2605_VOLTAGE_SCALE_FACTOR_MV)
130+
127131
struct drv2605_config {
128132
struct i2c_dt_spec i2c;
129133
struct gpio_dt_spec en_gpio;
@@ -452,6 +456,11 @@ static int drv2605_hw_config(const struct device *dev)
452456
return ret;
453457
}
454458

459+
ret = i2c_reg_write_byte_dt(&config->i2c, DRV2605_REG_RATED_VOLTAGE, config->rated_voltage);
460+
if (ret < 0) {
461+
return ret;
462+
}
463+
455464
return 0;
456465
}
457466

@@ -600,6 +609,7 @@ static const struct haptics_driver_api drv2605_driver_api = {
600609
.feedback_brake_factor = DT_INST_ENUM_IDX(inst, feedback_brake_factor), \
601610
.loop_gain = DT_INST_ENUM_IDX(inst, loop_gain), \
602611
.actuator_mode = DT_INST_ENUM_IDX(inst, actuator_mode), \
612+
.rated_voltage = DRV2605_CALCULATE_VOLTAGE(DT_INST_PROP(inst, vib_rated_mv)), \
603613
}; \
604614
\
605615
static struct drv2605_data drv2605_data_##inst = { \

dts/bindings/haptics/ti,drv2605.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ properties:
4343
description: |
4444
Selects a loop gain for the feedback control. According to the datasheet,
4545
a value of 2 ("HIGH") is valid for most actuators.
46+
vib-rated-mv:
47+
type: int
48+
default: 3200
49+
description: |
50+
Sets the reference voltage for full-scale output during closed-loop
51+
operation. The default value is inherited from ti,drv260x.yaml in Linux.
4652
en-gpios:
4753
type: phandle-array
4854
description: GPIO to enable and disable the device.

0 commit comments

Comments
 (0)