Inter-revision diff: patch 3

Comparing v9 (message) to v12 (message)

--- v9
+++ v12
@@ -5,6 +5,10 @@
 Signed-off-by: Roy Im <roy.im.opensource@diasemi.com>
 
 ---
+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
@@ -16,7 +20,6 @@
 	- Added more attributes to handle one value per file.
 	- Replaced and updated the dt-related code and functions called.
 	- Fixed error/functions.
-	- Rebased to v4.19-rc6.
 v6: No changes.
 v5: Fixed errors in Kconfig file.
 v4: Updated code as dt-bindings are changed.
@@ -26,8 +29,8 @@
 
  drivers/input/misc/Kconfig  |   13 +
  drivers/input/misc/Makefile |    1 +
- drivers/input/misc/da7280.c | 1880 +++++++++++++++++++++++++++++++++++++++++++
- 3 files changed, 1894 insertions(+)
+ drivers/input/misc/da7280.c | 1898 +++++++++++++++++++++++++++++++++++++++++++
+ 3 files changed, 1912 insertions(+)
  create mode 100644 drivers/input/misc/da7280.c
 
 diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
@@ -66,10 +69,10 @@
  obj-$(CONFIG_INPUT_DA9063_ONKEY)	+= da9063_onkey.o
 diff --git a/drivers/input/misc/da7280.c b/drivers/input/misc/da7280.c
 new file mode 100644
-index 0000000..bf2a6c9
+index 0000000..2dd76d2
 --- /dev/null
 +++ b/drivers/input/misc/da7280.c
-@@ -0,0 +1,1880 @@
+@@ -0,0 +1,1898 @@
 +// SPDX-License-Identifier: GPL-2.0+
 +/*
 + * DA7280 Haptic device driver
@@ -296,6 +299,9 @@
 +
 +#define DA7280_FF_EFFECT_COUNT_MAX	15
 +
++/* Maximum gain is 0x7fff for PWM mode */
++#define MAX_MAGNITUDE_SHIFT		15
++
 +enum da7280_haptic_dev_t {
 +	DA7280_LRA	= 0,
 +	DA7280_ERM_BAR	= 1,
@@ -340,7 +346,6 @@
 +	struct pwm_device *pwm_dev;
 +
 +	bool legacy;
-+	int pwm_id;
 +	struct delayed_work work_duration;
 +	struct work_struct work_playback;
 +	struct work_struct work_setgain;
@@ -453,11 +458,21 @@
 +
 +	pwm_get_state(haptics->pwm_dev, &state);
 +	state.enabled = enabled;
-+	period_mag_multi = enabled ? state.period * haptics->gain : 0;
-+	state.duty_cycle  = (haptics->acc_en) ?
-+		(unsigned int)(period_mag_multi >> 15) :
-+		(unsigned int)((period_mag_multi >> 15)
-+			+ state.period) / 2;
++	if (enabled) {
++		period_mag_multi = state.period * haptics->gain;
++		period_mag_multi >>= MAX_MAGNITUDE_SHIFT;
++
++		/* The interpretation of duty cycle depends on the acc_en,
++		 * it should be between 50% and 100% for acc_en = 0.
++		 * See datasheet 'PWM mode' section.
++		 */
++		if (!haptics->acc_en) {
++			period_mag_multi += state.period;
++			period_mag_multi /= 2;
++		}
++
++		state.duty_cycle = period_mag_multi;
++	}
 +
 +	error = pwm_apply_state(haptics->pwm_dev, &state);
 +	if (error)
@@ -1130,8 +1145,10 @@
 +		if (events[1] & DA7280_E_LIM_DRIVE_MASK ||
 +		    events[1] & DA7280_E_LIM_DRIVE_ACC_MASK)
 +			dev_warn(dev, "Please reduce the driver level\n");
-+		if (events[1] & DA7280_E_LIM_DRIVE_ACC_MASK)
-+			dev_warn(dev, "Please Check the mem data format\n");
++		if (events[1] & DA7280_E_MEM_TYPE_MASK)
++			dev_warn(dev, "Please check the mem data format\n");
++		if (events[1] & DA7280_E_OVERTEMP_WARN_MASK)
++			dev_warn(dev, "Over-temperature warning\n");
 +	}
 +
 +	if (events[0] & DA7280_E_SEQ_FAULT_MASK) {
@@ -1782,10 +1799,14 @@
 +	if (haptics->const_op_mode == DA7280_PWM_MODE) {
 +		haptics->pwm_dev = devm_pwm_get(dev, NULL);
 +		if (IS_ERR(haptics->pwm_dev)) {
-+			dev_err(dev, "failed to get PWM device\n");
-+			return PTR_ERR(haptics->pwm_dev);
-+		}
-+
++			error = PTR_ERR(haptics->pwm_dev);
++			if (error != -EPROBE_DEFER)
++				dev_err(dev, "unable to request PWM: %pE\n",
++					ERR_PTR(error));
++			return error;
++		}
++
++		/* Sync up PWM state and ensure it is off. */
 +		pwm_init_state(haptics->pwm_dev, &state);
 +		state.enabled = false;
 +		error = pwm_apply_state(haptics->pwm_dev, &state);
@@ -1797,7 +1818,7 @@
 +		}
 +
 +		/* Check PWM Period, it must be in 10k ~ 250kHz */
-+		period2freq = 1000000 / pwm_get_period(haptics->pwm_dev);
++		period2freq = 1000000 / state.period;
 +		if (period2freq < DA7280_MIN_PWM_FREQ_KHZ ||
 +		    period2freq > DA7280_MAX_PWM_FREQ_KHZ) {
 +			dev_err(dev, "Not supported PWM frequency(%d)\n",
@@ -1951,5 +1972,5 @@
 +MODULE_AUTHOR("Roy Im <Roy.Im.Opensource@diasemi.com>");
 +MODULE_LICENSE("GPL");
 -- 
-end-of-patch for PATCH V9
+end-of-patch for PATCH V12
 
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help