da7280: haptic driver submission
Subsystems (5)
PATCH v16 3/3 Input: new da7280 haptic driver
In reply to Roy ImAdds support for the Dialog DA7280 LRA/ERM Haptic Driver with multiple mode and integrated waveform memory and wideband support. It communicates via an I2C bus to the device.
---
v16:
- Corrected some code and updated description in Kconfig.
v15:
- Removed some defines and updated some comments.
v14:
- Updated pwm related code, alignments and comments.
v13:
- Updated some conditions in pwm function and alignments.
v12: No changes.
v11:
- Updated the pwm related code, comments and typo.
v10:
- Updated the pwm related function and added some comments.
v9:
- Removed the header file and put the definitions into the c file.
- Updated the pwm code and error logs with %pE
v8:
- Added changes to support FF_PERIODIC/FF_CUSTOM and FF_CONSTANT.
- Updated the dt-related code.
- Removed memless related functions.
v7:
- Added more attributes to handle one value per file.
- Replaced and updated the dt-related code and functions called.
- Fixed error/functions.
v6: No changes.
v5: Fixed errors in Kconfig file.
v4: Updated code as dt-bindings are changed.
v3: No changes.
v2: Fixed kbuild error/warning
drivers/input/misc/Kconfig | 13 + drivers/input/misc/Makefile | 1 + drivers/input/misc/da7280.c | 1840 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1854 insertions(+) create mode 100644 drivers/input/misc/da7280.c
drivers/input/misc/Kconfig +13 -0
@@ -869,4 +869,17 @@ config INPUT_STPMIC1_ONKEY To compile this driver as a module, choose M here: the module will be called stpmic1_onkey. +config INPUT_DA7280_HAPTICS + tristate "Dialog Semiconductor DA7280 haptics support" + depends on INPUT && I2C + select INPUT_FF_MEMLESS + select REGMAP_I2C + help + Say Y to enable support for the Dialog DA7280 haptics driver. + The haptics can be controlled by I2C communication, + or by PWM input, or by GPI. + + To compile this driver as a module, choose M here: the + module will be called da7280. + endif
drivers/input/misc/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o obj-$(CONFIG_INPUT_CPCAP_PWRBUTTON) += cpcap-pwrbutton.o +obj-$(CONFIG_INPUT_DA7280_HAPTICS) += da7280.o obj-$(CONFIG_INPUT_DA9052_ONKEY) += da9052_onkey.o obj-$(CONFIG_INPUT_DA9055_ONKEY) += da9055_onkey.o obj-$(CONFIG_INPUT_DA9063_ONKEY) += da9063_onkey.o
drivers/input/misc/da7280.c new file +1840 -0
1,840 lines not on this page · raw message
Signature · 1 line
end-of-patch for PATCH v16
v16 cover da7280: haptic driver submission
This patch adds support for the Dialog DA7280 Haptic driver IC.
In this patch set the following is provided:
[PATCH v16 1/3] MAINTAINERS file update for DA7280 [PATCH v16 2/3] DA7280 DT Binding
[PATCH v16 3/3] DA7280 Driver
This patch applies against linux-next and v5.8-rc4
Thank you,
Roy Im, Dialog Semiconductor Ltd.
Roy Im (3):
MAINTAINERS: da7280 updates to the Dialog Semiconductor search terms
dt-bindings: input: Add document bindings for DA7280
Input: new da7280 haptic driver
.../devicetree/bindings/input/dlg,da7280.txt | 109 ++ MAINTAINERS | 2 + drivers/input/misc/Kconfig | 13 + drivers/input/misc/Makefile | 1 + drivers/input/misc/da7280.c | 1840 ++++++++++++++++++++ 5 files changed, 1965 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/dlg,da7280.txt create mode 100644 drivers/input/misc/da7280.c
Signature · 1 line
end-of-patch for PATCH v16
PATCH v16 1/3 MAINTAINERS: da7280 updates to the Dialog Semiconductor search terms
This patch adds the da7280 bindings doc and driver to the Dialog Semiconductor support list.
---
v16: No changes.
v15: No changes.
v14: No changes.
v13: No changes.
v12: Corrected file list order.
v11: No changes.
v10: No changes.
v9: No changes.
v8: No changes.
v7: No changes.
v6: No changes.
v5: No changes.
v4: No changes.
v3: No changes.
v2: No changes.
MAINTAINERS | 2 ++ 1 file changed, 2 insertions(+)
MAINTAINERS +2 -0
@@ -5002,6 +5002,7 @@ M: Support Opensource <[email protected]> S: Supported W: http://www.dialog-semiconductor.com/products F: Documentation/devicetree/bindings/input/da90??-onkey.txt +F: Documentation/devicetree/bindings/input/dlg,da72??.txt F: Documentation/devicetree/bindings/mfd/da90*.txt F: Documentation/devicetree/bindings/regulator/da92*.txt F: Documentation/devicetree/bindings/regulator/slg51000.txt
@@ -5012,6 +5013,7 @@ F: Documentation/hwmon/da90??.rst F: drivers/gpio/gpio-da90??.c F: drivers/hwmon/da90??-hwmon.c F: drivers/iio/adc/da91??-*.c +F: drivers/input/misc/da72??.[ch] F: drivers/input/misc/da90??_onkey.c F: drivers/input/touchscreen/da9052_tsi.c F: drivers/leds/leds-da90??.c
Signature · 1 line
end-of-patch for PATCH v16
PATCH v16 2/3 dt-bindings: input: Add document bindings for DA7280
In reply to Roy ImAdd device tree binding information for DA7280 haptic driver. Example bindings for DA7280 are added.
---
v16: No changes.
v15: No changes.
v14: No changes.
v13: No changes.
v12: No changes.
v11: No changes.
v10: No changes.
v9: No changes.
v8: Updated descriptions for new properties.
v7: No changes.
v6: No changes.
v5: Updated descriptions and fixed errors.
v4: Fixed commit message, properties.
v3: Fixed subject format.
v2: No changes
.../devicetree/bindings/input/dlg,da7280.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/dlg,da7280.txt
Documentation/devicetree/bindings/input/dlg,da7280.txt new file +109 -0
@@ -0,0 +1,109 @@ +Dialog Semiconductor DA7280 Haptics bindings + +Required properties: +- compatible: Should be "dlg,da7280". +- reg: Specifies the I2C slave address. + +- interrupt-parent : Specifies the phandle of the interrupt controller to + which the IRQs from DA7280 are delivered to. + +- dlg,actuator-type: Set Actuator type. it should be one of: + "LRA" - Linear Resonance Actuator type. + "ERM-bar" - Bar type Eccentric Rotating Mass. + "ERM-coin" - Coin type Eccentric Rotating Mass. + +- dlg,const-op-mode: Haptic operation mode for FF_CONSTANT. + Possible values: + 1 - Direct register override(DRO) mode triggered by i2c(default), + 2 - PWM data source mode controlled by PWM duty, +- dlg,periodic-op-mode: Haptic operation mode for FF_PERIODIC. + Possible values: + 1 - Register triggered waveform memory(RTWM) mode, the pattern + assigned to the PS_SEQ_ID played as much times as PS_SEQ_LOOP, + 2 - Edge triggered waveform memory(ETWM) mode, external GPI(N) + control are required to enable/disable and it needs to keep + device enabled by sending magnitude (X > 0), + the pattern is assigned to the GPI(N)_SEQUENCE_ID below. + The default value is 1 for both of the operation modes. + For more details, please see the datasheet. + +- dlg,nom-microvolt: Nominal actuator voltage rating. + Valid values: 0 - 6000000. +- dlg,abs-max-microvolt: Absolute actuator maximum voltage rating. + Valid values: 0 - 6000000. +- dlg,imax-microamp: Actuator max current rating. + Valid values: 0 - 252000. + Default: 130000. +- dlg,impd-micro-ohms: the impedance of the actuator in micro ohms. + Valid values: 0 - 1500000000. + +Optional properties: +- pwms : phandle to the physical PWM(Pulse Width Modulation) device. + PWM properties should be named "pwms". And number of cell is different + for each pwm device. + (See Documentation/devicetree/bindings/pwm/pwm.txt + for further information relating to pwm properties) + +- dlg,ps-seq-id: the PS_SEQ_ID(pattern ID in waveform memory inside chip) + to play back when RTWM-MODE is enabled. + Valid range: 0 - 15. +- dlg,ps-seq-loop: the PS_SEQ_LOOP, Number of times the pre-stored sequence + pointed to by PS_SEQ_ID or GPI(N)_SEQUENCE_ID is repeated. + Valid range: 0 - 15. +- dlg,gpiN-seq-id: the GPI(N)_SEQUENCE_ID, pattern to play + when gpi0 is triggered, 'N' must be 0 - 2. + Valid range: 0 - 15. +- dlg,gpiN-mode: the pattern mode which can select either + "Single-pattern" or "Multi-pattern", 'N' must be 0 - 2. +- dlg,gpiN-polarity: gpiN polarity which can be chosen among + "Rising-edge", "Falling-edge" and "Both-edge", + 'N' must be 0 - 2 + Haptic will work by this edge option in case of ETWM mode. + +- dlg,resonant-freq-hz: use in case of LRA. + the frequency range: 50 - 300. + Default: 205. + +- dlg,bemf-sens-enable: Enable for internal loop computations. +- dlg,freq-track-enable: Enable for resonant frequency tracking. +- dlg,acc-enable: Enable for active acceleration. +- dlg,rapid-stop-enable: Enable for rapid stop. +- dlg,amp-pid-enable: Enable for the amplitude PID. +- dlg,mem-array: Customized waveform memory(patterns) data downloaded to + the device during initialization. This is an array of 100 values(u8). + +For further information, see device datasheet. + +====== + +Example: + + haptics: da7280-haptics@4a { + compatible = "dlg,da7280"; + reg = <0x4a>; + interrupt-parent = <&gpio6>; + interrupts = <11 IRQ_TYPE_LEVEL_LOW>; + dlg,actuator-type = "LRA"; + dlg,dlg,const-op-mode = <1>; + dlg,dlg,periodic-op-mode = <1>; + dlg,nom-microvolt = <2000000>; + dlg,abs-max-microvolt = <2000000>; + dlg,imax-microamp = <170000>; + dlg,resonant-freq-hz = <180>; + dlg,impd-micro-ohms = <10500000>; + dlg,freq-track-enable; + dlg,rapid-stop-enable; + dlg,mem-array = < + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + >; + + };
Signature · 1 line
end-of-patch for PATCH v16
Re: [PATCH v16 3/3] Input: new da7280 haptic driver
In reply to Roy ImQuoted 37 lines · Roy Im
Adds support for the Dialog DA7280 LRA/ERM Haptic Driver with multiple mode and integrated waveform memory and wideband support. It communicates via an I2C bus to the device.
Signed-off-by Roy Im <[email protected]>---
v16:
- Corrected some code and updated description inKconfig.
v15:
- Removed some defines and updated some comments.
v14:
- Updated pwm related code, alignments and comments.
v13:
- Updated some conditions in pwm function and alignments.
v12: No changes.
v11:
- Updated the pwm related code, comments and typo.
v10:
- Updated the pwm related function and added some comments.
v9:
- Removed the header file and put the definitions into the c file.
- Updated the pwm code and error logs with %pE
v8:
- Added changes to support FF_PERIODIC/FF_CUSTOM andFF_CONSTANT.
- Updated the dt-related code.
- Removed memless related functions.
v7:
- Added more attributes to handle one value per file.
- Replaced and updated the dt-related code and functions called.
- Fixed error/functions.
v6: No changes.
v5: Fixed errors inKconfigfile.
v4: Updated code as dt-bindings are changed.
v3: No changes.
v2: Fixed kbuild error/warning
Quoted 5 lines
drivers/input/misc/Kconfig | 13 + drivers/input/misc/Makefile | 1 + drivers/input/misc/da7280.c | 1840 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1854 insertions(+) create mode 100644 drivers/input/misc/da7280.c
Hi Roy,
Overall the driver looks pretty good now. I did find one issue, see below. If you fix that I am happy to add a Reviewed-by line.
Quoted 5 lines
drivers/input/misc/da7280.c new file +0
-0
[snip]
Quoted 6 lines
drivers/input/misc/da7280.c new file +6
-0+static int da7280_haptic_set_pwm (struct da7280_haptic *haptics,bool enabled) +{ +struct pwm_state state; +u64 period_mag_multi; +int error; +
drivers/input/misc/da7280.c line 338
Quoted 10 lines
drivers/input/misc/da7280.c new file +10
-0+if (!haptics->gain && enabled) { +dev_err (haptics->dev, +"Please set the gain first for the pwm mode\n" ); +return -EINVAL ; + } + +pwm_get_state (haptics->pwm_dev, &state); + state.enabled = enabled; +if (enabled) { + period_mag_multi = state.period * haptics->gain;
You are multiplying an unsigned int to a u16 and storing it in a u64. However, C doesn't promote the types, so you'll end up with an unexpected result here. You can fix it by promoting state.period to u64, ie:
period_mage_multi = (u64)state.period * haptics->gain;
See the following example code which demonstrates the problem.
#include <stdio.h>
#include <stdint.h>
uint64_t foo(unsigned int a, uint16_t b)
{
uint64_t tmp = a * b;
return tmp;
}uint64_t bar(unsigned int a, uint16_t b)
{
uint64_t tmp = (uint64_t)a * b;
return tmp;
}int main()
{
uint64_t val;
unsigned int a = 0xff00ff00;
uint16_t b = 0x200;
val = foo(a, b);
printf("result(%0x, %0x) = %0llx\n", a, b, val);
val = bar(a, b);
printf("result(%0x, %0x) = %0llx\n", a, b, val);
}Cheers,
Jes
RE: [PATCH v16 3/3] Input: new da7280 haptic driver
Quoted 45 lines · Jes Sorensen
Quoted 37 lines · Roy Im
Adds support for the Dialog DA7280 LRA/ERM Haptic Driver with multiple mode and integrated waveform memory and wideband support. It communicates via an I2C bus to the device.
Signed-off-by Roy Im <[email protected]>---
v16:
- Corrected some code and updated description inKconfig.
v15:
- Removed some defines and updated some comments.
v14:
- Updated pwm related code, alignments and comments.
v13:
- Updated some conditions in pwm function and alignments.
v12: No changes.
v11:
- Updated the pwm related code, comments and typo.
v10:
- Updated the pwm related function and added some comments.
v9:
- Removed the header file and put the definitions into the c file.
- Updated the pwm code and error logs with %pE
v8:
- Added changes to support FF_PERIODIC/FF_CUSTOM andFF_CONSTANT.
- Updated the dt-related code.
- Removed memless related functions.
v7:
- Added more attributes to handle one value per file.
- Replaced and updated the dt-related code and functions called.
- Fixed error/functions.
v6: No changes.
v5: Fixed errors inKconfigfile.
v4: Updated code as dt-bindings are changed.
v3: No changes.
v2: Fixed kbuild error/warningQuoted 6 lines
drivers/input/misc/Kconfig | 13 + drivers/input/misc/Makefile | 1 + drivers/input/misc/da7280.c | 1840 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1854 insertions(+) create mode 100644 drivers/input/misc/da7280.c
Quoted 5 lines
Hi Roy,
Overall the driver looks pretty good now. I did find one issue, see below. If you fix that I am happy to add a Reviewed-by line.
Reviewed-by Jes Sorensen <[email protected]>
Thanks a lot and I will fix as you advised below, then I will add a Reviewed-line in the next patch.
Quoted 61 lines
Quoted 5 lines
drivers/input/misc/da7280.c new file +0
-0[snip]
Quoted 6 lines
drivers/input/misc/da7280.c new file +6
-0+static int da7280_haptic_set_pwm (struct da7280_haptic *haptics,bool enabled) +{ +struct pwm_state state; +u64 period_mag_multi; +int error; +drivers/input/misc/da7280.c line 338
Quoted 10 lines
drivers/input/misc/da7280.c new file +10
-0+if (!haptics->gain && enabled) { +dev_err (haptics->dev, +"Please set the gain first for the pwm mode\n" ); +return -EINVAL ; + } + +pwm_get_state (haptics->pwm_dev, &state); + state.enabled = enabled; +if (enabled) { + period_mag_multi = state.period * haptics->gain;You are multiplying an unsigned int to a u16 and storing it in a u64. However, C doesn't promote the types, so you'll end up with an unexpected result here. You can fix it by promoting state.period to u64, ie:
period_mage_multi = (u64)state.period * haptics->gain;See the following example code which demonstrates the problem.
#include <
stdio.h>
#include <stdint.h>
uint64_tfoo(unsigned int a, uint16_t b){ uint64_t tmp = a * b; return tmp; }
uint64_tbar(unsigned int a, uint16_t b){ uint64_t tmp = (uint64_t)a * b; return tmp; }int
main(){ uint64_t val; unsigned int a = 0xff00ff00; uint16_t b = 0x200; val = foo(a, b); printf("result(%0x, %0x) = %0llx\n", a, b, val); val = bar(a, b); printf("result(%0x, %0x) = %0llx\n", a, b, val); }
Quoted 2 lines
Cheers,
Jes
Yes, you are right, I see the different result, I will fix this.
Kind regards,
Roy