input: force feedback updates, third time
Subsystems (3)
PATCH 1/12 input: move fixp-arith.h to drivers/input
In reply to Anssi HannulaMove fixp-arith.h from drivers/usb/input to drivers/input, as the part of force feedback support that requires trigonometric functions is being moved there.
hid-lgff.c is temporarily modified to avoid breaking git-bisect.
--- drivers/input/fixp-arith.h | 90 +++++++++++++++++++++++++++++++++++++++++ drivers/usb/input/fixp-arith.h | 90 ----------------------------------------- drivers/usb/input/hid-lgff.c | 6 +- 3 files changed, 93 insertions(+), 93 deletions(-)
drivers/input/fixp-arith.h new file +90 -0
@@ -0,0 +1,90 @@ +#ifndef _FIXP_ARITH_H +#define _FIXP_ARITH_H + +/* +* $$ +* +* Simplistic fixed-point arithmetics. +* Hmm, I'm probably duplicating some code :( +* +* Copyright (c) 2002 Johann Deneux +*/ + +/* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +* +* Should you need to contact me, the author, you can do so by +* e-mail - mail your message to <[email protected]> +*/ + +#include <linux/types.h> + +// The type representing fixed-point values +typedef s16 fixp_t ; + +#define FRAC_N 8 +#define FRAC_MASK ((1<<FRAC_N)-1) + +// Not to be used directly. Use fixp_{cos,sin} +static const fixp_t cos_table[45 ] = { +0x0100 ,0x00FF ,0x00FF ,0x00FE ,0x00FD ,0x00FC ,0x00FA ,0x00F8 , +0x00F6 ,0x00F3 ,0x00F0 ,0x00ED ,0x00E9 ,0x00E6 ,0x00E2 ,0x00DD , +0x00D9 ,0x00D4 ,0x00CF ,0x00C9 ,0x00C4 ,0x00BE ,0x00B8 ,0x00B1 , +0x00AB ,0x00A4 ,0x009D ,0x0096 ,0x008F ,0x0087 ,0x0080 ,0x0078 , +0x0070 ,0x0068 ,0x005F ,0x0057 ,0x004F ,0x0046 ,0x003D ,0x0035 , +0x002C ,0x0023 ,0x001A ,0x0011 ,0x0008 +}; + + +/* a: 123 -> 123.0 */ +static inline fixp_t fixp_new (s16 a) +{ +return a<<FRAC_N ; +} + +/* a: 0xFFFF -> -1.0 +0x8000 -> 1.0 +0x0000 -> 0.0 +*/ +static inline fixp_t fixp_new16 (s16 a) +{ +return ((s32 )a)>>(16 -FRAC_N ); +} + +static inline fixp_t fixp_cos (unsigned int degrees) +{ +int quadrant = (degrees /90 ) &3 ; +unsigned int i = degrees %90 ; + +if (quadrant ==1 || quadrant ==3 ) { + i =89 - i; + } + + i >>=1 ; + +return (quadrant ==1 || quadrant ==2 )? -cos_table[i] : cos_table[i]; +} + +static inline fixp_t fixp_sin (unsigned int degrees) +{ +return -fixp_cos (degrees +90 ); +} + +static inline fixp_t fixp_mult (fixp_t a,fixp_t b) +{ +return ((s32)(a*b))>>FRAC_N ; +} + +#endif
drivers/usb/input/fixp-arith.h deleted +0 -90
90 lines not on this page · raw message
drivers/usb/input/hid-lgff.c +3 -3
@@ -37,7 +37,7 @@#include <linux/circ_buf.h> #include "hid.h" -#include "fixp-arith.h" +//#include "fixp-arith.h" /* Periodicity of the update */
@@ -445,10 +445,10 @@ static void hid_lgff_timer(unsigned longcase FF_CONSTANT : {//TODO: handle envelopes int degrees = effect->effect.direction *360 >>16 ; - x +=fixp_mult (fixp_sin (degrees), +/* x += fixp_mult(fixp_sin(degrees), fixp_new16(effect->effect.u.constant.level)); y += fixp_mult(-fixp_cos(degrees), -fixp_new16 (effect->effect.u.constant.level)); +fixp_new16(effect->effect.u.constant.level));*/ }break ;case FF_RUMBLE : right += effect->effect.u.rumble.strong_magnitude;
--
Anssi Hannula
PATCH 6/12 input: adapt iforce driver for the new force feedback interface
In reply to Anssi HannulaModify the iforce driver for the new force feedback interface.
--- drivers/input/joystick/iforce/iforce-ff.c | 61 +++------ drivers/input/joystick/iforce/iforce-main.c | 189 ++++++++-------------------- drivers/input/joystick/iforce/iforce.h | 15 -- 3 files changed, 87 insertions(+), 178 deletions(-)
drivers/input/joystick/iforce/iforce-ff.c +23 -38
@@ -198,10 +198,8 @@ static unsigned char find_button(struct* Analyse the changes in an effect, and tell if we need to send an condition * parameter packet */ -static int need_condition_modifier (struct iforce * iforce,struct ff_effect * new) +static int need_condition_modifier (struct ff_effect * old,struct ff_effect * new) { -int id = new->id; -struct ff_effect * old = &iforce->core_effects[id].effect;int ret=0 ;int i;
@@ -225,11 +223,8 @@ static int need_condition_modifier(struc* Analyse the changes in an effect, and tell if we need to send a magnitude * parameter packet */ -static int need_magnitude_modifier (struct iforce * iforce,struct ff_effect * effect) +static int need_magnitude_modifier (struct ff_effect * old,struct ff_effect * effect) { -int id = effect->id; -struct ff_effect * old = &iforce->core_effects[id].effect; -if (effect->type !=FF_CONSTANT ) {printk (KERN_WARNING "iforce.c: bad effect type in need_envelope_modifier\n" );return FALSE;
@@ -242,11 +237,8 @@ static int need_magnitude_modifier(struc* Analyse the changes in an effect, and tell if we need to send an envelope * parameter packet */ -static int need_envelope_modifier (struct iforce * iforce,struct ff_effect * effect) +static int need_envelope_modifier (struct ff_effect * old,struct ff_effect * effect) { -int id = effect->id; -struct ff_effect * old = &iforce->core_effects[id].effect; -switch (effect->type) {case FF_CONSTANT : if (old->u.constant.envelope.attack_length != effect->u.constant.envelope.attack_length
@@ -275,16 +267,12 @@ static int need_envelope_modifier(struct* Analyse the changes in an effect, and tell if we need to send a periodic * parameter effect */ -static int need_period_modifier (struct iforce * iforce,struct ff_effect * new) +static int need_period_modifier (struct ff_effect * old,struct ff_effect * new) { -int id = new->id; -struct ff_effect * old = &iforce->core_effects[id].effect; -if (new->type !=FF_PERIODIC ) { -printk (KERN_WARNING "iforce.c: bad effect type in need_periodic_modifier\n" ); +printk (KERN_WARNING "iforce.c: bad effect type in need_period_modifier\n" );return FALSE; } -return (old->u.periodic.period != new->u.periodic.period || old->u.periodic.magnitude != new->u.periodic.magnitude || old->u.periodic.offset != new->u.periodic.offset
@@ -295,11 +283,8 @@ static int need_period_modifier(struct i* Analyse the changes in an effect, and tell if we need to send an effect * packet */ -static int need_core (struct iforce * iforce,struct ff_effect * new) +static int need_core (struct ff_effect * old,struct ff_effect * new) { -int id = new->id; -struct ff_effect * old = &iforce->core_effects[id].effect; -if (old->direction != new->direction || old->trigger.button != new->trigger.button || old->trigger.interval != new->trigger.interval
@@ -360,7 +345,7 @@ static int make_core(struct iforce* ifor* Upload a periodic effect to the device * See also iforce_upload_constant. */ -int iforce_upload_periodic (struct iforce * iforce,struct ff_effect * effect,int is_update) +int iforce_upload_periodic (struct iforce * iforce,struct ff_effect * effect,struct ff_effect *old) {u8 wave_code;int core_id = effect->id;
@@ -371,18 +356,18 @@ int iforce_upload_periodic(struct iforceint param2_err =1 ;int core_err =0 ; -if (!is_update ||need_period_modifier (iforce, effect)) { +if (!old ||need_period_modifier (old, effect)) { param1_err =make_period_modifier (iforce, mod1_chunk, - is_update, + old ?1 :0 , effect->u.periodic.magnitude, effect->u.periodic.offset, effect->u.periodic.period, effect->u.periodic.phase);if (param1_err)return param1_err;set_bit (FF_MOD1_IS_USED , core_effect->flags); } -if (!is_update ||need_envelope_modifier (iforce, effect)) { +if (!old ||need_envelope_modifier (old, effect)) { param2_err = make_envelope_modifier(iforce, mod2_chunk, - is_update, + old ? 1 : 0, effect->u.periodic.envelope.attack_length, effect->u.periodic.envelope.attack_level, effect->u.periodic.envelope.fade_length,
@@ -400,7 +385,7 @@ int iforce_upload_periodic(struct iforcedefault : wave_code =0x20 ;break ; } -if (!is_update ||need_core (iforce, effect)) { +if (!old ||need_core (old, effect)) { core_err = make_core(iforce, effect->id, mod1_chunk->start, mod2_chunk->start,
@@ -429,7 +414,7 @@ int iforce_upload_periodic(struct iforce* 0 Ok, effect created or updated * 1 effect did not change since last upload, and no packet was therefore sent */ -int iforce_upload_constant (struct iforce * iforce,struct ff_effect * effect,int is_update) +int iforce_upload_constant (struct iforce * iforce,struct ff_effect * effect,struct ff_effect * old) {int core_id = effect->id;struct iforce_core_effect * core_effect = iforce->core_effects + core_id;
@@ -439,17 +424,17 @@ int iforce_upload_constant(struct iforceint param2_err =1 ;int core_err =0 ; -if (!is_update ||need_magnitude_modifier (iforce, effect)) { +if (!old ||need_magnitude_modifier (old, effect)) { param1_err =make_magnitude_modifier (iforce, mod1_chunk, - is_update, + old ?1 :0 , effect->u.constant.level);if (param1_err)return param1_err;set_bit (FF_MOD1_IS_USED , core_effect->flags); } -if (!is_update ||need_envelope_modifier (iforce, effect)) { +if (!old ||need_envelope_modifier (old, effect)) { param2_err = make_envelope_modifier(iforce, mod2_chunk, - is_update, + old ? 1 : 0, effect->u.constant.envelope.attack_length, effect->u.constant.envelope.attack_level, effect->u.constant.envelope.fade_length,
@@ -458,7 +443,7 @@ int iforce_upload_constant(struct iforceset_bit (FF_MOD2_IS_USED , core_effect->flags); } -if (!is_update ||need_core (iforce, effect)) { +if (!old ||need_core (old, effect)) { core_err = make_core(iforce, effect->id, mod1_chunk->start, mod2_chunk->start,
@@ -483,7 +468,7 @@ int iforce_upload_constant(struct iforce/* * Upload an condition effect. Those are for example friction, inertia, springs... */ -int iforce_upload_condition (struct iforce * iforce,struct ff_effect * effect,int is_update) +int iforce_upload_condition (struct iforce * iforce,struct ff_effect * effect,struct ff_effect * old) {int core_id = effect->id;struct iforce_core_effect * core_effect = iforce->core_effects + core_id;
@@ -499,9 +484,9 @@ int iforce_upload_condition(struct iforcdefault :return -1 ; } -if (!is_update ||need_condition_modifier (iforce, effect)) { +if (!old ||need_condition_modifier (old, effect)) { param_err = make_condition_modifier(iforce, mod1_chunk, - is_update, + old ? 1 : 0, effect->u.condition[0].right_saturation, effect->u.condition[0].left_saturation, effect->u.condition[0].right_coeff,
@@ -512,7 +497,7 @@ int iforce_upload_condition(struct iforcset_bit (FF_MOD1_IS_USED , core_effect->flags); param_err = make_condition_modifier(iforce, mod2_chunk, - is_update, + old ? 1 : 0, effect->u.condition[1].right_saturation, effect->u.condition[1].left_saturation, effect->u.condition[1].right_coeff,
@@ -524,7 +509,7 @@ int iforce_upload_condition(struct iforc } -if (!is_update ||need_core (iforce, effect)) { +if (!old ||need_core (old, effect)) { core_err = make_core(iforce, effect->id, mod1_chunk->start, mod2_chunk->start, type, 0xc0,
drivers/input/joystick/iforce/iforce.h +4 -11
@@ -55,7 +55,7 @@#define FALSE 0#define TRUE 1 -#define FF_EFFECTS_MAX 32 +#define IFORCE_EFFECTS_MAX 32/* Each force feedback effect is made of one core effect, which can be * associated to at most to effect modifiers
@@ -79,13 +79,6 @@ struct iforce_core_effect {struct resource mod1_chunk;struct resource mod2_chunk;unsigned long flags[NBITS (FF_MODCORE_MAX )]; -pid_t owner; -/* Used to keep track of parameters of an effect. They are needed -* to know what parts of an effect changed in an update operation. -* We try to send only parameter packets if possible, as sending -* effect parameter requires the effect to be stoped and restarted -*/ -struct ff_effect effect; };#define FF_CMD_EFFECT 0x010e
@@ -183,9 +176,9 @@ void iforce_dump_packet(char *msg, u16 cint iforce_get_id_packet (struct iforce *iforce,char *packet);/* iforce-ff.c */ -int iforce_upload_periodic (struct iforce *,struct ff_effect *,int is_update); -int iforce_upload_constant (struct iforce *,struct ff_effect *,int is_update); -int iforce_upload_condition (struct iforce *,struct ff_effect *,int is_update); +int iforce_upload_periodic (struct iforce *,struct ff_effect *,struct ff_effect * old); +int iforce_upload_constant (struct iforce *,struct ff_effect *,struct ff_effect * old); +int iforce_upload_condition (struct iforce *,struct ff_effect *,struct ff_effect * old);/* Public variables */ extern struct serio_driver iforce_serio_drv;
drivers/input/joystick/iforce/iforce-main.c +60 -129
297 lines not on this page · raw message
--
Anssi Hannula
cover input: force feedback updates, third time
Major update for the force feedback support, including a new force feedback driver interface and two new HID ff drivers.
This is the patchset I sent in 2006-05-26 with the changes of my latest patches integrated, as requested.
The changes are:
- make the ff module a bool instead of part of the input module, as we don't want to rename input.c
- use the normal event() handler in input_dev so that input.c doesn't have to make calls to ff code
Signature · 1 line
Anssi Hannula
PATCH 5/12 input: adapt uinput for the new force feedback interface
Modify the uinput driver for the new force feedback interface. The userspace interface of the force feedback part is changed and documentation in uinput.h is updated accordingly. MODULE_VERSION is also added to reflect the revision.
--- drivers/input/misc/uinput.c | 79 ++++++++++++++++++++++++++++++++++++-------- include/linux/uinput.h | 21 ++++++++--- 2 files changed, 80 insertions(+), 20 deletions(-)
drivers/input/misc/uinput.c +65 -14
@@ -20,6 +20,9 @@* Author: Aristeu Sergio Rozanski Filho <[email protected]> * * Changes/Revisions: +* 0.3 09/04/2006 (Anssi Hannula <[email protected]>) +* - updated ff support for the changes in kernel interface +* - added MODULE_VERSION * 0.2 16/10/2004 (Micah Dowty <[email protected]>) * - added force feedback support * - added UI_SET_PHYS
@@ -40,6 +43,9 @@ static int uinput_dev_event(struct input {struct uinput_device *udev; +if (type ==EV_FF ) +return input_ff_event (dev, type, code, value); + udev = dev->private; udev->buff[udev->head].type = type;
@@ -107,18 +113,31 @@ static int uinput_request_submit(structreturn request->retval; } -static int uinput_dev_upload_effect (struct input_dev *dev,struct ff_effect *effect) +static void uinput_dev_set_gain (struct input_dev *dev,u16 gain) +{ +uinput_dev_event (dev,EV_FF ,FF_GAIN , gain); +} + +static void uinput_dev_set_autocenter (struct input_dev *dev,u16 magnitude) +{ +uinput_dev_event (dev,EV_FF ,FF_AUTOCENTER , magnitude); +} + +static int uinput_dev_playback (struct input_dev *dev,int effect_id,int value) +{ +return uinput_dev_event (dev,EV_FF , effect_id, value); +} + +static int uinput_dev_upload_effect (struct input_dev *dev,struct ff_effect *effect,struct ff_effect *old) {struct uinput_request request;int retval; -if (!test_bit (EV_FF , dev->evbit)) -return -ENOSYS ; - request.id =-1 ;init_completion (&request.done); request.code =UI_FF_UPLOAD ; - request.u.effect = effect; + request.u.upload.effect = effect; + request.u.upload.old = old; retval =uinput_request_reserve_slot (dev->private, &request);if (!retval)
@@ -166,6 +185,14 @@ static void uinput_destroy_device(struct udev->state =UIST_NEW_DEVICE ; } +static struct ff_driver uinput_ff_driver = { + .upload = uinput_dev_upload_effect, + .erase = uinput_dev_erase_effect, + .playback = uinput_dev_playback, + .set_gain = uinput_dev_set_gain, + .set_autocenter = uinput_dev_set_autocenter +}; +static int uinput_create_device (struct uinput_device *udev) {int error;
@@ -181,6 +208,14 @@ static int uinput_create_device(struct ureturn error; } +if (udev->dev->ff) { + error =input_ff_register (udev->dev, &uinput_ff_driver); +if (error) { +uinput_destroy_device (udev); +return error; + } + } + udev->state =UIST_CREATED ;return 0 ;
@@ -243,8 +278,6 @@ static int uinput_allocate_device(structreturn -ENOMEM ; udev->dev->event = uinput_dev_event; - udev->dev->upload_effect = uinput_dev_upload_effect; - udev->dev->erase_effect = uinput_dev_erase_effect; udev->dev->private = udev;return 0 ;
@@ -296,7 +329,12 @@ static int uinput_setup_device(struct ui dev->id.vendor = user_dev->id.vendor; dev->id.product = user_dev->id.product; dev->id.version = user_dev->id.version; - dev->ff_effects_max = user_dev->ff_effects_max; +if (user_dev->ff_effects_max) { + retval =input_ff_allocate (dev); +if (retval) + goto exit; + dev->ff_effects_max = user_dev->ff_effects_max; + } size =sizeof (int ) * (ABS_MAX +1 );memcpy (dev->absmax, user_dev->absmax, size);
@@ -459,7 +497,12 @@ static long uinput_ioctl(struct file *fibreak ;case UI_SET_EVBIT : - retval =uinput_set_bit (arg, evbit,EV_MAX ); +if (arg ==EV_FF ) +/* EV_FF shall not be touched by the driver +it is set by force feedback subsystem */ + retval = -EINVAL ; +else + retval =uinput_set_bit (arg, evbit,EV_MAX );break ;case UI_SET_KEYBIT :
@@ -487,7 +530,10 @@ static long uinput_ioctl(struct file *fibreak ;case UI_SET_FFBIT : - retval =uinput_set_bit (arg, ffbit,FF_MAX ); +if (!udev->dev->ff) + retval = -EINVAL ; +else + retval =uinput_set_bit (arg, ff->flags,FF_MAX );break ;case UI_SET_SWBIT :
@@ -525,12 +571,17 @@ static long uinput_ioctl(struct file *fibreak ; } req =uinput_request_find (udev, ff_up.request_id); -if (!(req && req->code ==UI_FF_UPLOAD && req->u.effect)) { +if (!(req && req->code ==UI_FF_UPLOAD && req->u.upload.effect)) { retval = -EINVAL ;break ; } ff_up.retval =0 ; -memcpy (&ff_up.effect, req->u.effect,sizeof (struct ff_effect )); +memcpy (&ff_up.effect, req->u.upload.effect,sizeof (struct ff_effect )); +if (req->u.upload.old) +memcpy (&ff_up.old, req->u.upload.old,sizeof (struct ff_effect )); +else +memset (&ff_up.old,0 ,sizeof (struct ff_effect )); +if (copy_to_user (p, &ff_up,sizeof (ff_up))) { retval = -EFAULT ;break ;
@@ -561,12 +612,11 @@ static long uinput_ioctl(struct file *fibreak ; } req =uinput_request_find (udev, ff_up.request_id); -if (!(req && req->code ==UI_FF_UPLOAD && req->u.effect)) { +if (!(req && req->code ==UI_FF_UPLOAD && req->u.upload.effect)) { retval = -EINVAL ;break ; } req->retval = ff_up.retval; -memcpy (req->u.effect, &ff_up.effect,sizeof (struct ff_effect ));uinput_request_done (udev, req);break ;
@@ -622,6 +672,7 @@ static void __exit uinput_exit(void)MODULE_AUTHOR ("Aristeu Sergio Rozanski Filho" );MODULE_DESCRIPTION ("User level driver support for input subsystem" );MODULE_LICENSE ("GPL" ); +MODULE_VERSION ("0.3" );module_init (uinput_init);module_exit (uinput_exit);
include/linux/uinput.h +15 -6
@@ -22,12 +22,18 @@* Author: Aristeu Sergio Rozanski Filho <[email protected]> * * Changes/Revisions: +* 0.3 24/05/2006 (Anssi Hannula <anssi.hannulagmail.com>) +* - update ff support for the changes in kernel interface +* - add UINPUT_VERSION * 0.2 16/10/2004 (Micah Dowty <[email protected]>) * - added force feedback support * - added UI_SET_PHYS * 0.1 20/06/2002 * - first public version */ + +#define UINPUT_VERSION 3 +#ifdef __KERNEL__#define UINPUT_MINOR 223#define UINPUT_NAME "uinput"
@@ -45,7 +51,10 @@ struct uinput_request {union {int effect_id; -struct ff_effect * effect; +struct { +struct ff_effect * effect; +struct ff_effect * old; + } upload; } u; };
@@ -69,6 +78,7 @@ struct uinput_ff_upload {int request_id;int retval;struct ff_effect effect; +struct ff_effect old; };struct uinput_ff_erase {
@@ -105,7 +115,7 @@ struct uinput_ff_erase {* ioctls to retrieve additional parameters and send the return code. * The callback blocks until this return code is sent. * -* The described callback mechanism is only used if EV_FF is set. +* The described callback mechanism is only used if ff_effects_max is set. * Otherwise, default implementations of upload_effect and erase_effect * are used. *
@@ -116,9 +126,9 @@ struct uinput_ff_erase {* the 'value' from the EV_UINPUT event. * 3. Issue a UI_BEGIN_FF_UPLOAD ioctl, giving it the * uinput_ff_upload struct. It will be filled in with the -* ff_effect passed to upload_effect(). -* 4. Perform the effect upload, and place the modified ff_effect -* and a return code back into the uinput_ff_upload struct. +* ff_effects passed to upload_effect(). +* 4. Perform the effect upload, and place a return code back into +the uinput_ff_upload struct. * 5. Issue a UI_END_FF_UPLOAD ioctl, also giving it the * uinput_ff_upload_effect struct. This will complete execution * of our upload_effect() handler.
@@ -133,7 +143,6 @@ struct uinput_ff_erase {* effect ID passed to erase_effect(). * 4. Perform the effect erasure, and place a return code back * into the uinput_ff_erase struct. -* and a return code back into the uinput_ff_erase struct. * 5. Issue a UI_END_FF_ERASE ioctl, also giving it the * uinput_ff_erase_effect struct. This will complete execution * of our erase_effect() handler.
--
Anssi Hannula
PATCH 3/12 input: new force feedback interface
In reply to Anssi HannulaImplement a new force feedback interface, in which all non-driver-specific operations are separated to a common module. This includes handling effect type validations, effect timers, locking, etc.
As a result, support is added for gain and envelope for memoryless devices, periodic => rumble conversion for memoryless devices and rumble => periodic conversion for devices with periodic support instead of rumble support. Also the effect memory of devices is not emptied if the root user opens and closes the device while another user is using effects. This module also obsoletes some flawed locking and timer code in few ff drivers.
The effects are now file descriptor specific instead of the previous strange half-process half-fd specific behaviour. This is a minor change and most likely no force feedback aware programs are affected by this negatively.
Otherwise the userspace interface is left unaltered.
The code should be built as part of the input module, but unfortunately that would require renaming input.c, which we don't want to do. So instead we make INPUT_FF_EFFECTS a bool so that it cannot be built as a module.
--- drivers/input/Kconfig | 5 drivers/input/Makefile | 1 drivers/input/evdev.c | 30 - drivers/input/ff-effects.c | 894 +++++++++++++++++++++++++++++++++++++++++++++ drivers/input/input.c | 12 include/linux/input.h | 81 ++++ 6 files changed, 1006 insertions(+), 17 deletions(-)
drivers/input/Kconfig +5 -0
@@ -24,6 +24,11 @@ config INPUT if INPUT +config INPUT_FF_EFFECTS + bool "Force feedback effects" + help + Say Y here if you want to be able to play force feedback effects. + comment "Userland interfaces" config INPUT_MOUSEDEV
drivers/input/Makefile +1 -0
@@ -5,6 +5,7 @@ # Each configuration option enables a list of files. obj-$(CONFIG_INPUT) += input.o +obj-$(CONFIG_INPUT_FF_EFFECTS) += ff-effects.o obj-$(CONFIG_INPUT_MOUSEDEV) += mousedev.o obj-$(CONFIG_INPUT_JOYDEV) += joydev.o obj-$(CONFIG_INPUT_EVDEV) += evdev.o
include/linux/input.h +81 -0
93 lines not on this page · raw message
drivers/input/input.c +12 -0
@@ -733,6 +733,17 @@ static void input_dev_release(struct cla {struct input_dev *dev =to_input_dev (class_dev); +if (dev->ff) { +struct ff_device *ff = dev->ff; +clear_bit (EV_FF , dev->evbit); +mutex_lock (&dev->ff_lock); +del_timer_sync (&ff->timer); + dev->flush =NULL ; + dev->ff =NULL ; +mutex_unlock (&dev->ff_lock); +kfree (ff); + } +kfree (dev);module_put (THIS_MODULE ); }
@@ -874,6 +885,7 @@ struct input_dev *input_allocate_device(class_device_initialize (&dev->cdev);INIT_LIST_HEAD (&dev->h_list);INIT_LIST_HEAD (&dev->node); +mutex_init (&dev->ff_lock); }return dev;
drivers/input/evdev.c +13 -17
@@ -457,25 +457,21 @@ static long evdev_ioctl_handler(struct freturn 0 ; -case EVIOCSFF : -if (dev->upload_effect) { -struct ff_effect effect; -int err; - -if (copy_from_user (&effect, p,sizeof (effect))) -return -EFAULT ; - err = dev->upload_effect (dev, &effect); -if (put_user (effect.id, &(((struct ff_effect __user *)p)->id))) -return -EFAULT ; -return err; - }else -return -ENOSYS ; +case EVIOCSFF : { +struct ff_effect effect; +int err; -case EVIOCRMFF : -if (!dev->erase_effect) -return -ENOSYS ; +if (copy_from_user (&effect, p,sizeof (effect))) +return -EFAULT ; + err =input_ff_upload (dev, &effect, file); +if (put_user (effect.id, &(((struct ff_effect __user *)p)->id))) +return -EFAULT ; +return err; + } -return dev->erase_effect (dev, (int )(unsigned long ) p); +case EVIOCRMFF : +return input_ff_erase (dev, (int )(unsigned long ) p, + file);case EVIOCGEFFECTS :if (put_user (dev->ff_effects_max, ip))
drivers/input/ff-effects.c new file +894 -0
894 lines not on this page · raw message
--
Anssi Hannula
PATCH 9/12 input: update documentation of force feedback
In reply to Anssi HannulaUpdate the force feedback documentation in ff.txt and input.h.
--- Documentation/input/ff.txt | 96 ++++++++++++++++++++------------------------- include/linux/input.h | 12 +++++ 2 files changed, 54 insertions(+), 54 deletions(-)
Documentation/input/ff.txt +43 -53
@@ -1,27 +1,27 @@ Force feedback for Linux. By Johann Deneux <[email protected]> on 2001/04/22. +Updated by Anssi Hannula <[email protected]> on 2006/04/09. You may redistribute this file. Please remember to include shape.fig and interactive.fig as well. ---------------------------------------------------------------------------- -0. Introduction +1. Introduction ~~~~~~~~~~~~~~~ This document describes how to use force feedback devices under Linux. The goal is not to support these devices as if they were simple input-only devices (as it is already the case), but to really enable the rendering of force effects. -At the moment, only I-Force devices are supported, and not officially. That -means I had to find out how the protocol works on my own. Of course, the -information I managed to grasp is far from being complete, and I can not -guarranty that this driver will work for you. -This document only describes the force feedback part of the driver for I-Force -devices. Please read joystick.txt before reading further this document. +This document only describes the force feedback part of the Linux input +interface. Please read joystick.txt and input.txt before reading further this +document. 2. Instructions to the user ~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Here are instructions on how to compile and use the driver. In fact, this -driver is the normal iforce, input and evdev drivers written by Vojtech -Pavlik, plus additions to support force feedback. +To enable force feedback, you have to +1. have your kernel configured with evdev and force feedback effects enabled + with a driver that supports your device. +2. make sure evdev module is loaded and /dev/input/event* device files are + created. Before you start, let me WARN you that some devices shake violently during the initialisation phase. This happens for example with my "AVB Top Shot Pegasus".
@@ -29,39 +29,8 @@ To stop this annoying behaviour, move yo should keep a hand on your device, in order to avoid it to brake down if something goes wrong. -At the kernel's compilation: - - Enable IForce/Serial - - Enable Event interface - -Compile the modules, install them. - -You also need inputattach. - -You then need to insert the modules into the following order: -% modprobe joydev -% modprobe serport # Only for serial -% modprobe iforce -% modprobe evdev -% ./inputattach -ifor $2 & # Only for serial -If you are using USB, you don't need the inputattach step. - -Please check that you have all the /dev/input entries needed: -cd /dev -rm js* -mkdir input -mknod input/js0 c 13 0 -mknod input/js1 c 13 1 -mknod input/js2 c 13 2 -mknod input/js3 c 13 3 -ln -s input/js0 js0 -ln -s input/js1 js1 -ln -s input/js2 js2 -ln -s input/js3 js3 - -mknod input/event0 c 13 64 -mknod input/event1 c 13 65 -mknod input/event2 c 13 66 -mknod input/event3 c 13 67 +If you have a serial iforce device, you need to start inputattach. See +joystick.txt for details. 2.1 Does it work ? ~~~~~~~~~~~~~~~~~~
@@ -86,18 +55,29 @@ int ioctl(int file_descriptor, int reque Returns the features supported by the device. features is a bitfield with the following bits: -- FF_X has an X axis (usually joysticks) -- FF_Y has an Y axis (usually joysticks) -- FF_WHEEL has a wheel (usually sterring wheels) - FF_CONSTANT can render constant force effects -- FF_PERIODIC can render periodic effects (sine, triangle, square...) +- FF_PERIODIC can render periodic effects with the following waveforms: + - FF_SQUARE square waveform + - FF_TRIANGLE triangle waveform + - FF_SINE sine waveform + - FF_SAW_UP sawtooth up waveform + - FF_SAW_DOWN sawtooth down waveform + - FF_CUSTOM custom waveform - FF_RAMP can render ramp effects - FF_SPRING can simulate the presence of a spring - FF_FRICTION can simulate friction - FF_DAMPER can simulate damper effects -- FF_RUMBLE rumble effects (normally the only effect supported by rumble - pads) +- FF_RUMBLE rumble effects - FF_INERTIA can simulate inertia +- FF_GAIN gain is adjustable +- FF_AUTOCENTER autocenter is adjustable + +Note: In most cases you should use FF_PERIODIC instead of FF_RUMBLE. All + devices that support FF_RUMBLE support FF_PERIODIC (square, triangle, + sine) and the other way around. + +Note: The exact syntax FF_CUSTOM is undefined for the time being as no driver + supports it yet. int ioctl(int fd, EVIOCGEFFECTS, int *n);
@@ -120,6 +100,9 @@ to the unique id assigned by the driver. some operations (removing an effect, controlling the playback). This if field must be set to -1 by the user in order to tell the driver to allocate a new effect. + +Effects are file descriptor specific. + See <linux/input.h> for a description of the ff_effect struct. You should also find help in a few sketches, contained in files shape.fig and interactive.fig. You need xfig to visualize these files.
@@ -128,8 +111,8 @@ You need xfig to visualize these files. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ int ioctl(int fd, EVIOCRMFF, effect.id); -This makes room for new effects in the device's memory. Please note this won't -stop the effect if it was playing. +This makes room for new effects in the device's memory. Note that this also +stops the effect if it was playing. 3.4 Controlling the playback of effects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -163,8 +146,7 @@ Control of playing is done with write(). ~~~~~~~~~~~~~~~~~~~~ Not all devices have the same strength. Therefore, users should set a gain factor depending on how strong they want effects to be. This setting is -persistent across access to the driver, so you should not care about it if -you are writing games, as another utility probably already set this for you. +persistent across access to the driver. /* Set the gain of the device int gain; /* between 0 and 100 */
@@ -204,9 +186,17 @@ type of device, not all parameters can b the direction of an effect cannot be updated with iforce devices. In this case, the driver stops the effect, up-load it, and restart it. +Therefore it is recommended to dynamically change direction while the effect +is playing only when it is ok to restart the effect with a replay count of 1. 3.8 Information about the status of effects ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +NOTE: This is deprecated and should not be used. It applies only to iforce + devices and is provided for backward-compatibility only. If you have a + really good reason to use this, please contact + [email protected] or [email protected] + so that support for it can be added to all drivers. + Every time the status of an effect is changed, an event is sent. The values and meanings of the fields of the event are as follows: struct input_event {
include/linux/input.h +11 -1
@@ -672,8 +672,14 @@ struct input_absinfo {* They are sub-structures of the actually sent structure (called ff_effect) */ +/* +* All time duration values are expressed in ms. +* Time values above 32767ms (0x7fff) should not be used and have unspecified +* results depending on device. +*/ +struct ff_replay { -__u16 length;/* Duration of an effect in ms. All other times are also expressed in ms */ +__u16 length;/* Duration of an effect in ms */ __u16 delay;/* Time to wait before to start playing an effect */ };
@@ -683,6 +689,10 @@ struct ff_trigger { };struct ff_envelope { +/* The attack_level and fade_level are absolute values of the level, +i.e. if the default magnitude is negative the envelope level is +also seen as an absolute value of a below-zero value */ +/* Therefore the valid level range is from 0x0000 to 0x7fff */ __u16 attack_length;/* Duration of attack (ms) */ __u16 attack_level;/* Level at beginning of attack */ __u16 fade_length;/* Duration of fade (ms) */
--
Anssi Hannula
PATCH 4/12 input: adapt hid force feedback drivers for the new interface
In reply to Anssi HannulaModify the HID force feedback drivers for the new interface. This removes a lot of code duplication.
--- drivers/usb/input/Kconfig | 2 drivers/usb/input/hid-input.c | 4 drivers/usb/input/hid-lgff.c | 458 ++++-------------------------------------- drivers/usb/input/hid-tmff.c | 353 ++------------------------------ drivers/usb/input/hid.h | 9 5 files changed, 83 insertions(+), 743 deletions(-)
drivers/usb/input/hid.h +0 -9
@@ -442,8 +442,6 @@ struct hid_device { /* device repovoid *ff_private;/* Private data for the force-feedback driver */ void (*ff_exit)(struct hid_device *);/* Called by hid_exit_ff(hid) */ -int (*ff_event)(struct hid_device *hid,struct input_dev *input, -unsigned int type,unsigned int code,int value);#ifdef CONFIG_USB_HIDINPUT_POWERBOOK unsigned long pb_pressed_fn[NBITS (KEY_MAX )];
@@ -526,13 +524,6 @@ static inline void hid_ff_exit(struct hiif (hid->ff_exit) hid->ff_exit (hid); } -static inline int hid_ff_event (struct hid_device *hid,struct input_dev *input, -unsigned int type,unsigned int code,int value) -{ -if (hid->ff_event) -return hid->ff_event (hid, input, type, code, value); -return -ENOSYS ; -}int hid_lgff_init (struct hid_device * hid);int hid_tmff_init (struct hid_device * hid);
drivers/usb/input/hid-input.c +2 -2
@@ -737,8 +737,8 @@ static int hidinput_input_event(struct iint offset;if (type ==EV_FF ) -return hid_ff_event (hid, dev, type, code, value); - +return input_ff_event (dev, type, code, value); +if (type !=EV_LED )return -1 ;
drivers/usb/input/hid-lgff.c +50 -408
526 lines not on this page · raw message
drivers/usb/input/hid-tmff.c +30 -323
423 lines not on this page · raw message
drivers/usb/input/Kconfig +1 -1
@@ -49,7 +49,7 @@ config USB_HIDINPUT_POWERBOOK config HID_FF bool "Force feedback support (EXPERIMENTAL)" - depends on USB_HIDINPUT && EXPERIMENTAL + depends on USB_HIDINPUT && EXPERIMENTAL && INPUT_FF_EFFECTS help Say Y here is you want force feedback support for a few HID devices. See below for a list of supported devices.
--
Anssi Hannula
PATCH 10/12 input: drop the remains of the old ff interface
In reply to Anssi HannulaDrop the now unused handlers and input_report_ff().
--- include/linux/input.h | 7 ------- 1 files changed, 7 deletions(-)
include/linux/input.h +0 -7
@@ -938,8 +938,6 @@ struct input_dev {int (*accept)(struct input_dev *dev,struct file *file);int (*flush)(struct input_dev *dev,struct file *file);int (*event)(struct input_dev *dev,unsigned int type,unsigned int code,int value); -int (*upload_effect)(struct input_dev *dev,struct ff_effect *effect); -int (*erase_effect)(struct input_dev *dev,int effect_id);struct input_handle *grab;
@@ -1118,11 +1116,6 @@ static inline void input_report_abs(struinput_event (dev,EV_ABS , code, value); } -static inline void input_report_ff (struct input_dev *dev,unsigned int code,int value) -{ -input_event (dev,EV_FF , code, value); -} -static inline void input_report_ff_status (struct input_dev *dev,unsigned int code,int value) {input_event (dev,EV_FF_STATUS , code, value);
--
Anssi Hannula
PATCH 7/12 input: force feedback driver for PID devices
In reply to Anssi HannulaAdd force feedback driver for PID devices. This replaces the older PID driver which was never completed.
--- drivers/usb/input/Kconfig | 4 drivers/usb/input/Makefile | 2 drivers/usb/input/hid-ff.c | 14 drivers/usb/input/hid-input.c | 21 drivers/usb/input/hid-pidff.c | 1400 ++++++++++++++++++++++++++++++++++++++++++ drivers/usb/input/hid.h | 6 6 files changed, 1416 insertions(+), 31 deletions(-)
drivers/usb/input/hid-ff.c +7 -7
@@ -51,9 +51,6 @@ static struct hid_ff_initializer inits[] {0x46d, 0xc295, hid_lgff_init}, // Logitech MOMO force wheel {0x46d, 0xc219, hid_lgff_init}, // Logitech Cordless rumble pad 2 #endif -#ifdef CONFIG_HID_PID - {0x45e, 0x001b, hid_pid_init}, -#endif #ifdef CONFIG_THRUSTMASTER_FF {0x44f, 0xb304, hid_tmff_init}, #endif
@@ -80,9 +77,12 @@ int hid_ff_init(struct hid_device* hid) init =hid_get_ff_init (le16_to_cpu (hid->dev->descriptor.idVendor),le16_to_cpu (hid->dev->descriptor.idProduct)); -if (!init) { -dbg ("hid_ff_init could not find initializer" ); -return -ENOSYS ; - } +/* We try pidff when no other driver is found because PID is the +standards compliant way of implementing force feedback in HID. +pidff_init() will quickly abort if the device doesn't appear to +be a PID device */ +if (!init) +return pidff_init (hid); +return init->init (hid); }
drivers/usb/input/hid.h +5 -1
@@ -527,5 +527,9 @@ static inline void hid_ff_exit(struct hiint hid_lgff_init (struct hid_device * hid);int hid_tmff_init (struct hid_device * hid); -int hid_pid_init (struct hid_device * hid); +#ifdef CONFIG_HID_PID +int pidff_init (struct hid_device *hid); +#else +static inline int pidff_init (struct hid_device *hid) {return -1 ; } +#endif
drivers/usb/input/hid-input.c +1 -20
@@ -67,11 +67,9 @@ static const struct {#define map_rel (c) do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0)#define map_key (c) do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0)#define map_led (c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0) -#define map_ff (c) do { usage->code = c; usage->type = EV_FF; bit = input->ffbit; max = FF_MAX; } while (0)#define map_abs_clear (c) do { map_abs(c); clear_bit(c, bit); } while (0)#define map_key_clear (c) do { map_key(c); clear_bit(c, bit); } while (0) -#define map_ff_effect (c) do { set_bit(c, input->ffbit); } while (0)#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
@@ -527,23 +525,7 @@ static void hidinput_configure_usage(strcase HID_UP_PID : -set_bit (EV_FF , input->evbit);switch (usage->hid &HID_USAGE ) { -case 0x26 :map_ff_effect (FF_CONSTANT ); goto ignore; -case 0x27 :map_ff_effect (FF_RAMP ); goto ignore; -case 0x28 :map_ff_effect (FF_CUSTOM ); goto ignore; -case 0x30 :map_ff_effect (FF_SQUARE );map_ff_effect (FF_PERIODIC ); goto ignore; -case 0x31 :map_ff_effect (FF_SINE );map_ff_effect (FF_PERIODIC ); goto ignore; -case 0x32 :map_ff_effect (FF_TRIANGLE );map_ff_effect (FF_PERIODIC ); goto ignore; -case 0x33 :map_ff_effect (FF_SAW_UP );map_ff_effect (FF_PERIODIC ); goto ignore; -case 0x34 :map_ff_effect (FF_SAW_DOWN );map_ff_effect (FF_PERIODIC ); goto ignore; -case 0x40 :map_ff_effect (FF_SPRING ); goto ignore; -case 0x41 :map_ff_effect (FF_DAMPER ); goto ignore; -case 0x42 :map_ff_effect (FF_INERTIA ); goto ignore; -case 0x43 :map_ff_effect (FF_FRICTION ); goto ignore; -case 0x7e :map_ff (FF_GAIN );break ; -case 0x83 : input->ff_effects_max = field->value[0 ]; goto ignore; -case 0x98 :map_ff (FF_AUTOCENTER );break ;case 0xa4 :map_key_clear (BTN_DEAD );break ;default : goto ignore; }
@@ -687,8 +669,7 @@ void hidinput_hid_event(struct hid_devic }if (usage->hid == (HID_UP_PID |0x83UL )) {/* Simultaneous Effects Max */ - input->ff_effects_max = value; -dbg ("Maximum Effects - %d" ,input->ff_effects_max); +dbg ("Maximum Effects - %d" ,value);return ; }
drivers/usb/input/hid-pidff.c new file +1400 -0
1,400 lines not on this page · raw message
drivers/usb/input/Kconfig +2 -2
@@ -60,10 +60,10 @@ config HID_FF If unsure, say N. config HID_PID - bool "PID Devices (Microsoft Sidewinder Force Feedback 2)" + bool "PID device support" depends on HID_FF help - Say Y here if you have a PID-compliant joystick and wish to enable force + Say Y here if you have a PID-compliant device and wish to enable force feedback for it. The Microsoft Sidewinder Force Feedback 2 is one such device.
drivers/usb/input/Makefile +1 -1
@@ -14,7 +14,7 @@ ifeq ($(CONFIG_USB_HIDINPUT),y) usbhid-objs += hid-input.o endif ifeq ($(CONFIG_HID_PID),y) - usbhid-objs += pid.o + usbhid-objs += hid-pidff.o endif ifeq ($(CONFIG_LOGITECH_FF),y) usbhid-objs += hid-lgff.o
--
Anssi Hannula
PATCH 11/12 input: drop the old PID driver
In reply to Anssi HannulaDrop the old PID driver that is now obsoleted by a new implementation in hid-pidff.c. This older driver was never completed and is not able to upload effects.
--- drivers/usb/input/pid.c | 295 ------------------------------------------------ drivers/usb/input/pid.h | 62 ---------- 2 files changed, 357 deletions(-)
drivers/usb/input/pid.c deleted +0 -295
@@ -1,295 +0,0 @@ -/* -* PID Force feedback support for hid devices. -* -* Copyright (c) 2002 Rodrigo Damazio. -* Portions by Johann Deneux and Bjorn Augustson -*/ - -/* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -* -* Should you need to contact me, the author, you can do so by -* e-mail - mail your message to <[email protected]> -*/ - -#include <linux/config.h> -#include <linux/module.h> -#include <linux/slab.h> -#include <linux/kernel.h> -#include <linux/init.h> -#include <linux/mm.h> -#include <linux/smp_lock.h> -#include <linux/spinlock.h> -#include <linux/input.h> -#include <linux/usb.h> -#include "hid.h" -#include "pid.h" - -#define CHECK_OWNERSHIP (i, hid_pid) \ - ((i) < FF_EFFECTS_MAX && i >= 0 && \ - test_bit(FF_PID_FLAGS_USED, &hid_pid->effects[(i)].flags) && \ - (current->pid == 0 || \ - (hid_pid)->effects[(i)].owner == current->pid)) - -/* Called when a transfer is completed */ -static void hid_pid_ctrl_out (struct urb *u,struct pt_regs *regs) -{ -dev_dbg (&u->dev->dev,"hid_pid_ctrl_out - Transfer Completed\n" ); -} - -static void hid_pid_exit (struct hid_device *hid) -{ -struct hid_ff_pid *private = hid->ff_private; - -if (private->urbffout) { -usb_kill_urb (private->urbffout); -usb_free_urb (private->urbffout); - } -} - -static int pid_upload_periodic (struct hid_ff_pid *pid,struct ff_effect *effect,int is_update) -{ -dev_info (&pid->hid->dev->dev,"requested periodic force upload\n" ); -return 0 ; -} - -static int pid_upload_constant (struct hid_ff_pid *pid,struct ff_effect *effect,int is_update) -{ -dev_info (&pid->hid->dev->dev,"requested constant force upload\n" ); -return 0 ; -} - -static int pid_upload_condition (struct hid_ff_pid *pid,struct ff_effect *effect,int is_update) -{ -dev_info (&pid->hid->dev->dev,"requested Condition force upload\n" ); -return 0 ; -} - -static int pid_upload_ramp (struct hid_ff_pid *pid,struct ff_effect *effect,int is_update) -{ -dev_info (&pid->hid->dev->dev,"request ramp force upload\n" ); -return 0 ; -} - -static int hid_pid_event (struct hid_device *hid,struct input_dev *input, -unsigned int type,unsigned int code,int value) -{ -dev_dbg (&hid->dev->dev,"PID event received: type=%d,code=%d,value=%d.\n" , type, code, value); - -if (type !=EV_FF ) -return -1 ; - -return 0 ; -} - -/* Lock must be held by caller */ -static void hid_pid_ctrl_playback (struct hid_device *hid,struct hid_pid_effect *effect,int play) -{ -if (play) -set_bit (FF_PID_FLAGS_PLAYING , &effect->flags); -else -clear_bit (FF_PID_FLAGS_PLAYING , &effect->flags); -} - -static int hid_pid_erase (struct input_dev *dev,int id) -{ -struct hid_device *hid = dev->private; -struct hid_ff_pid *pid = hid->ff_private; -struct hid_field *field; -unsigned long flags; -int ret; - -if (!CHECK_OWNERSHIP (id, pid)) -return -EACCES ; - -/* Find report */ - field =hid_find_field_by_usage (hid,HID_UP_PID |FF_PID_USAGE_BLOCK_FREE , -HID_OUTPUT_REPORT ); -if (!field) { -dev_err (&hid->dev->dev,"couldn't find report\n" ); -return -EIO ; - } - - ret =hid_set_field (field,0 , pid->effects[id].device_id); -if (ret) { -dev_err (&hid->dev->dev,"couldn't set field\n" ); -return ret; - } - -hid_submit_report (hid, field->report,USB_DIR_OUT ); - -spin_lock_irqsave (&pid->lock, flags); -hid_pid_ctrl_playback (hid, pid->effects + id,0 ); - pid->effects[id].flags =0 ; -spin_unlock_irqrestore (&pid->lock, flags); - -return 0 ; -} - -/* Erase all effects this process owns */ -static int hid_pid_flush (struct input_dev *dev,struct file *file) -{ -struct hid_device *hid = dev->private; -struct hid_ff_pid *pid = hid->ff_private; -int i; - -/*NOTE: no need to lock here. The only times EFFECT_USED is -modified is when effects are uploaded or when an effect is -erased. But a process cannot close its dev/input/eventX fd -and perform ioctls on the same fd all at the same time */ -/*FIXME: multiple threads, anyone? */ -for (i =0 ; i < dev->ff_effects_max; ++i) -if (current->pid == pid->effects[i].owner - &&test_bit (FF_PID_FLAGS_USED , &pid->effects[i].flags)) -if (hid_pid_erase (dev, i)) -dev_warn (&hid->dev->dev,"erase effect %d failed" , i); - -return 0 ; -} - -static int hid_pid_upload_effect (struct input_dev *dev, -struct ff_effect *effect) -{ -struct hid_ff_pid *pid_private = (struct hid_ff_pid *)(dev->private); -int ret; -int is_update; -unsigned long flags; - -dev_dbg (&pid_private->hid->dev->dev,"upload effect called: effect_type=%x\n" , effect->type); -/* Check this effect type is supported by this device */ -if (!test_bit (effect->type, dev->ffbit)) { -dev_dbg (&pid_private->hid->dev->dev, -"invalid kind of effect requested.\n" ); -return -EINVAL ; - } - -/* -* If we want to create a new effect, get a free id -*/ -if (effect->id ==-1 ) { -int id =0 ; - -// Spinlock so we don`t get a race condition when choosing IDs -spin_lock_irqsave (&pid_private->lock, flags); - -while (id <FF_EFFECTS_MAX ) -if (!test_and_set_bit (FF_PID_FLAGS_USED , &pid_private->effects[id++].flags)) -break ; - -if (id ==FF_EFFECTS_MAX ) { -spin_unlock_irqrestore (&pid_private->lock, flags); -// TEMP - We need to get ff_effects_max correctly first: || id >= dev->ff_effects_max) { -dev_dbg (&pid_private->hid->dev->dev,"Not enough device memory\n" ); -return -ENOMEM ; - } - - effect->id = id; -dev_dbg (&pid_private->hid->dev->dev,"effect ID is %d.\n" , id); - pid_private->effects[id].owner = current->pid; - pid_private->effects[id].flags = (1 <<FF_PID_FLAGS_USED ); -spin_unlock_irqrestore (&pid_private->lock, flags); - - is_update =FF_PID_FALSE ; - }else { -/* We want to update an effect */ -if (!CHECK_OWNERSHIP (effect->id, pid_private)) -return -EACCES ; - -/* Parameter type cannot be updated */ -if (effect->type != pid_private->effects[effect->id].effect.type) -return -EINVAL ; - -/* Check the effect is not already being updated */ -if (test_bit (FF_PID_FLAGS_UPDATING , &pid_private->effects[effect->id].flags)) -return -EAGAIN ; - - is_update =FF_PID_TRUE ; - } - -/* -* Upload the effect -*/ -switch (effect->type) { -case FF_PERIODIC : - ret =pid_upload_periodic (pid_private, effect, is_update); -break ; - -case FF_CONSTANT : - ret =pid_upload_constant (pid_private, effect, is_update); -break ; - -case FF_SPRING : -case FF_FRICTION : -case FF_DAMPER : -case FF_INERTIA : - ret =pid_upload_condition (pid_private, effect, is_update); -break ; - -case FF_RAMP : - ret =pid_upload_ramp (pid_private, effect, is_update); -break ; - -default : -dev_dbg (&pid_private->hid->dev->dev, -"invalid type of effect requested - %x.\n" , - effect->type); -return -EINVAL ; - } -/* If a packet was sent, forbid new updates until we are notified -* that the packet was updated -*/ -if (ret ==0 ) -set_bit (FF_PID_FLAGS_UPDATING , &pid_private->effects[effect->id].flags); - pid_private->effects[effect->id].effect = *effect; -return ret; -} - -int hid_pid_init (struct hid_device *hid) -{ -struct hid_ff_pid *private; - struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); -struct input_dev *input_dev = hidinput->input; - - private = hid->ff_private =kzalloc (sizeof (struct hid_ff_pid ),GFP_KERNEL ); -if (!private) -return -ENOMEM ; - - private->hid = hid; - - hid->ff_exit = hid_pid_exit; - hid->ff_event = hid_pid_event; - -/* Open output URB */ -if (!(private->urbffout =usb_alloc_urb (0 ,GFP_KERNEL ))) { -kfree (private); -return -1 ; - } - -usb_fill_control_urb (private->urbffout, hid->dev,0 , - (void *)&private->ffcr, private->ctrl_buffer,8 , - hid_pid_ctrl_out, hid); - - input_dev->upload_effect = hid_pid_upload_effect; - input_dev->flush = hid_pid_flush; - input_dev->ff_effects_max =8 ;// A random default -set_bit (EV_FF , input_dev->evbit); -set_bit (EV_FF_STATUS , input_dev->evbit); - -spin_lock_init (&private->lock); - -printk (KERN_INFO "Force feedback driver for PID devices by Rodrigo Damazio <[email protected]>.\n" ); - -return 0 ; -}
drivers/usb/input/pid.h deleted +0 -62
62 lines not on this page · raw message
--
Anssi Hannula
PATCH 12/12 input: use -ENOSPC instead of -ENOMEM in iforce when device full
In reply to Anssi HannulaUse -ENOSPC instead of -ENOMEM when the iforce device doesn't have enough free memory for the new effect. All other drivers are already been using -ENOSPC, so this makes the behaviour coherent.
--- drivers/input/joystick/iforce/iforce-ff.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
drivers/input/joystick/iforce/iforce-ff.c +4 -4
@@ -47,7 +47,7 @@ static int make_magnitude_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }
@@ -80,7 +80,7 @@ static int make_period_modifier(struct i iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }
@@ -120,7 +120,7 @@ static int make_envelope_modifier(struct iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }
@@ -157,7 +157,7 @@ static int make_condition_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }
--
Anssi Hannula
PATCH 2/12 input: fix accuracy of fixp-arith.h
In reply to Anssi HannulaAdd the value of cos(90) = 0 to the table. This also moves the results so that sin(x) == sin(180-x) is true as expected.
--- drivers/input/fixp-arith.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/input/fixp-arith.h +3 -3
@@ -38,13 +38,13 @@ typedef s16 fixp_t;#define FRAC_MASK ((1<<FRAC_N)-1)// Not to be used directly. Use fixp_{cos,sin} -static const fixp_t cos_table[45 ] = { +static const fixp_t cos_table[46 ] = {0x0100 ,0x00FF ,0x00FF ,0x00FE ,0x00FD ,0x00FC ,0x00FA ,0x00F8 ,0x00F6 ,0x00F3 ,0x00F0 ,0x00ED ,0x00E9 ,0x00E6 ,0x00E2 ,0x00DD ,0x00D9 ,0x00D4 ,0x00CF ,0x00C9 ,0x00C4 ,0x00BE ,0x00B8 ,0x00B1 ,0x00AB ,0x00A4 ,0x009D ,0x0096 ,0x008F ,0x0087 ,0x0080 ,0x0078 ,0x0070 ,0x0068 ,0x005F ,0x0057 ,0x004F ,0x0046 ,0x003D ,0x0035 , -0x002C ,0x0023 ,0x001A ,0x0011 ,0x0008 +0x002C ,0x0023 ,0x001A ,0x0011 ,0x0008 ,0x0000 };
@@ -69,7 +69,7 @@ static inline fixp_t fixp_cos(unsigned iunsigned int i = degrees %90 ;if (quadrant ==1 || quadrant ==3 ) { - i =89 - i; + i =90 - i; } i >>=1 ;
--
Anssi Hannula
PATCH 8/12 input: force feedback driver for Zeroplus devices
In reply to Anssi HannulaAdd force feedback driver for some PSX-style Zeroplus devices.
--- drivers/usb/input/Kconfig | 7 ++ drivers/usb/input/Makefile | 3 + drivers/usb/input/hid-ff.c | 4 + drivers/usb/input/hid-zpff.c | 124 +++++++++++++++++++++++++++++++++++++++++++ drivers/usb/input/hid.h | 1 5 files changed, 139 insertions(+)
drivers/usb/input/hid-ff.c +4 -0
@@ -54,6 +54,10 @@ static struct hid_ff_initializer inits[] #ifdef CONFIG_THRUSTMASTER_FF {0x44f, 0xb304, hid_tmff_init}, #endif +#ifdef CONFIG_ZEROPLUS_FF + {0xc12, 0x0005, zpff_init}, + {0xc12, 0x0030, zpff_init}, +#endif {0, 0, NULL} /* Terminating entry */ };
drivers/usb/input/hid-zpff.c new file +124 -0
124 lines not on this page · raw message
drivers/usb/input/Kconfig +7 -0
@@ -87,6 +87,13 @@ config THRUSTMASTER_FF Note: if you say N here, this device will still be supported, but without force feedback. +config ZEROPLUS_FF + bool "Zeroplus based game controller support" + depends on HID_FF + help + Say Y here if you have a Zeroplus based game controller and want to + enable force feedback for it. + config USB_HIDDEV bool "/dev/hiddev raw HID device support" depends on USB_HID
drivers/usb/input/Makefile +3 -0
@@ -22,6 +22,9 @@ endif ifeq ($(CONFIG_THRUSTMASTER_FF),y) usbhid-objs += hid-tmff.o endif +ifeq ($(CONFIG_ZEROPLUS_FF),y) + usbhid-objs += hid-zpff.o +endif ifeq ($(CONFIG_HID_FF),y) usbhid-objs += hid-ff.o endif
drivers/usb/input/hid.h +1 -0
@@ -527,6 +527,7 @@ static inline void hid_ff_exit(struct hiint hid_lgff_init (struct hid_device * hid);int hid_tmff_init (struct hid_device * hid); +int zpff_init (struct hid_device * hid);#ifdef CONFIG_HID_PID int pidff_init (struct hid_device *hid);
--
Anssi Hannula
Re: [patch 12/12] input: use -ENOSPC instead of -ENOMEM in iforce when device full
In reply to Anssi HannulaQuoted 3 lines · On Tue, 30 May 2006 13:57:17 +0300 Anssi Hannula wrote:
Use
-ENOSPCinstead of-ENOMEMwhen the iforce device doesn't have enough free memory for the new effect. All other drivers are already been using-ENOSPC, so this makes the behaviour coherent.
Could all of the others be wrong?
ENOSPC: No space left on device
ENOMEM: Not enough space [!?!?!?] or Out of memory
Quoted 38 lines
Signed-off-by Anssi Hannula <[email protected]>--- drivers/input/joystick/iforce/iforce-ff.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)Index:
linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce-ff.c
===================================================================drivers/input/joystick/iforce/iforce-ff.c +3
-3@@ -47,7 +47,7 @@ static int make_magnitude_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -80,7 +80,7 @@ static int make_period_modifier(struct i iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -120,7 +120,7 @@ static int make_envelope_modifier(struct iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }
drivers/input/joystick/iforce/iforce-ff.c static int make_condition_modifier(struc
Quoted 10 lines
drivers/input/joystick/iforce/iforce-ff.c +1
-2@@ -157,7 +157,7 @@ static int make_condition_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); } --
---
~Randy
Re: [patch 03/12] input: new force feedback interface
In reply to Anssi HannulaQuoted 17 lines · On Tue, 30 May 2006 13:57:08 +0300 Anssi Hannula wrote:
drivers/input/Kconfig | 5 drivers/input/Makefile | 1 drivers/input/evdev.c | 30 - drivers/input/ff-effects.c | 894 +++++++++++++++++++++++++++++++++++++++++++++ drivers/input/input.c | 12 include/linux/input.h | 81 ++++ 6 files changed, 1006 insertions(+), 17 deletions(-)Index:
linux-2.6.17-rc4-git12/include/linux/input.h
===================================================================include/linux/input.h +4
-0@@ -1000,6 +1003,84 @@ struct input_handle { + +#ifdef CONFIG_INPUT_FF_EFFECTS +int input_ff_allocate (struct input_dev *dev); +int input_ff_register (struct input_dev *dev,struct ff_driver *driver);
include/linux/input.h struct input_handle { · line 1016
Quoted 10 lines
include/linux/input.h +10
-0+int input_ff_upload (struct input_dev *dev,struct ff_effect *effect, +struct file *file); +int input_ff_erase (struct input_dev *dev,int effect_id,struct file *file); +int input_ff_event (struct input_dev *dev,unsigned int type, +unsigned int code,int value); +#else +static inline int input_ff_allocate (struct input_dev *dev) +{ +return -EPERM ; +}
-ENOSYS seems more reasonable to me (above + below).
Quoted 29 lines
include/linux/input.h +20
-0+static inline int input_ff_register (struct input_dev *dev, +struct ff_driver *driver) +{ +return -EPERM ; +} +static inline int input_ff_upload (struct input_dev *dev, +struct ff_effect *effect,struct file *file) +{ +return -EINVAL ; +} +static inline int input_ff_erase (struct input_dev *dev,int effect_id, +struct file *file) +{ +return -EINVAL ; +} +static inline int input_ff_event (struct input_dev *dev,unsigned int type, +unsigned int code,int value) { } +#endif + +static inline void init_input_dev (struct input_dev *dev) {INIT_LIST_HEAD (&dev->h_list);Index:
linux-2.6.17-rc4-git12/drivers/input/ff-effects.c
===================================================================
drivers/input/ff-effects.c line 8
Quoted 8 lines
drivers/input/ff-effects.c new file +8
-0@@ -0,0 +1,894 @@ +/* +* Force feedback support for Linux input subsystem +* +* Copyright (c) 2006 Anssi Hannula <[email protected]> +*/ + + +/**
"/**" indicates kernel-doc format, but the rest of the function comment is not in kernel-doc format. Please use kernel-doc for all non-static/non-inline functions (basically for public/exported symbols) and at your discretion for static functions.
(applies to many functions here)
Quoted 20 lines
drivers/input/ff-effects.c new file +20
-0+* Lock the mutex and check the device has not been deleted +*/ +static inline int input_ff_safe_lock (struct input_dev *dev) +{ +mutex_lock (&dev->ff_lock); +if (dev->ff) +return 0 ; + +mutex_unlock (&dev->ff_lock); +return 1 ; +} + +/** +* Check that the effect_id is a valid effect and the user has access to it +*/ +static inline int input_ff_effect_access (struct input_dev *dev,int effect_id, +struct file *file) +{ +struct ff_device *ff = dev->ff; +
drivers/input/ff-effects.c line 81
Quoted 10 lines
drivers/input/ff-effects.c new file +10
-0+if (effect_id >= dev->ff_effects_max || effect_id <0 + || !test_bit (FF_EFFECT_USED , ff->effects[effect_id].flags)) +return -EINVAL ; + +if (ff->effects[effect_id].owner != file) +return -EACCES ; + +return 0 ; +} +
See Documentation/kernel-doc-nano-HOWTO.txt for more info:
Quoted 15 lines
drivers/input/ff-effects.c new file +15
-0+/** +* Check for the next time envelope requires an update on memoryless devices +* @event_time: Time of the next update +* +* If an event is found before @event_time, @event_time is changed and the +* functions returns 1. Otherwise it returns 0. +*/ +static int input_ff_envelope_time (struct ff_effect_status *effect, +struct ff_envelope *envelope, +unsigned long *event_time) +{ +} + +/** +* Calculate the next time effect requires an update on memoryless devices
drivers/input/ff-effects.c line 134
Quoted 10 lines
drivers/input/ff-effects.c new file +10
-0+* @ff: The device +* +* Runs through the effects and updates the timer if necessary. This function +* should be called only when the spinlock is locked. +*/ +static void input_ff_calc_timer (struct ff_device *ff) +{ +int i; +int events =0 ; +unsigned long next_time =0 ;
We generally like a blank line between data and code lines....
Quoted 62 lines
drivers/input/ff-effects.c new file +62
-0+debug ("calculating next timer" ); +for (i =0 ; i <FF_MEMLESS_EFFECTS ; ++i) { +unsigned long event_time; +struct ff_envelope *envelope =NULL ; +int event_set =0 ; + +if (!test_bit (FF_EFFECT_STARTED , ff->effects[i].flags)) { +if (test_bit (FF_EFFECT_PLAYING , ff->effects[i].flags)) { + event_time = ff->effects[i].stop_at = jiffies; + event_set =1 ; + }else +continue ; + }else { +if (!test_bit (FF_EFFECT_PLAYING , ff->effects[i].flags)) { + event_time = ff->effects[i].play_at; + event_set =1 ; + }else { +if (ff->effects[i].effect.type ==FF_PERIODIC ) + envelope = + &ff->effects[i].effect.u.periodic. + envelope; +else if (ff->effects[i].effect.type == +FF_CONSTANT ) + envelope = + &ff->effects[i].effect.u.constant. + envelope; + + event_set = +input_ff_envelope_time (&ff->effects[i], + envelope, + &event_time); +if (!event_set + && ff->effects[i].effect.replay.length) { + event_time = ff->effects[i].stop_at; + event_set =1 ; + } + } + } + +if (!event_set) +continue ; + events++; + +if (time_after (jiffies, event_time)) { + event_time = jiffies; +break ; + } +if (events ==1 ) + next_time = event_time; +else { +if (time_after (next_time, event_time)) + next_time = event_time; + } + } +if (!events) { +debug ("no actions" ); +del_timer (&ff->timer); + }else { +debug ("timer set" ); +mod_timer (&ff->timer, next_time); + } +}
drivers/input/ff-effects.c
Quoted 10 lines
drivers/input/ff-effects.c new file +10
-0+ + + +/** +* Safe sum +* @a: Integer to sum +* @b: Integer to sum +* @limit: The sum limit +* +* If @a+@b is above @limit, return @limit
unless a == 0, then return b, even if b > limit
Quoted 13 lines
drivers/input/ff-effects.c new file +13
-0+*/ +static int input_ff_safe_sum (int a,int b,int limit) +{ +int c; +if (!a) +return b; + c = a + b; +if (c > limit) +return limit; +return c; +} + +/**
drivers/input/ff-effects.c line 323
Quoted 10 lines
drivers/input/ff-effects.c new file +10
-0+* Convert an effect (for devices with memory) +*/ +static void input_ff_convert_effect (struct input_dev *dev, +struct ff_effect *effect) +{ +int strong_magnitude, weak_magnitude; + +if (effect->type ==FF_RUMBLE &&test_bit (FF_PERIODIC , dev->ff->flags)) { +/* Strong magnitude as 2/3 full and weak 1/3 full */ +/* Also divide by 2 */
why? Comments should explain why, not just what.
Quoted 17 lines
drivers/input/ff-effects.c new file +17
-0+ strong_magnitude = effect->u.rumble.strong_magnitude *2 /6 ; + weak_magnitude = effect->u.rumble.weak_magnitude /6 ; + + effect->type =FF_PERIODIC ; + + effect->u.periodic.waveform =FF_SINE ; + effect->u.periodic.period =50 ; + effect->u.periodic.magnitude = +input_ff_safe_sum (strong_magnitude, weak_magnitude,0x7fff ); + effect->u.periodic.offset =0 ; + effect->u.periodic.phase =0 ; + effect->u.periodic.envelope.attack_length =0 ; + effect->u.periodic.envelope.attack_level =0 ; + effect->u.periodic.envelope.fade_length =0 ; + effect->u.periodic.envelope.fade_level =0 ; +return ; + }
drivers/input/ff-effects.c
Quoted 10 lines
drivers/input/ff-effects.c new file +10
-0+ +printk (KERN_ERR +"ff-effects: invalid effect type in convert_effect()\n" ); +} + + + +/** +* Erase an effect +* @file: The requester
needs all parameters listed/explained
Quoted 26 lines
drivers/input/ff-effects.c new file +26
-0+* +* Erases the effect if the requester is also the effect owner. The mutex +* should already be locked before calling this function. If the device is a +* memoryless device, the spinlock will be locked. +*/ +static int _input_ff_erase (struct input_dev *dev,int effect_id, +struct file *file) +{ +unsigned long flags; +int ret =input_ff_effect_access (dev, effect_id, file); +if (ret) +return ret; +if (dev->ff->driver->playback) { + dev->ff->driver->playback (dev, effect_id,0 ); + ret = dev->ff->driver->erase (dev, effect_id); +if (!ret) +__clear_bit (FF_EFFECT_USED , + dev->ff->effects[effect_id].flags); + }else { +spin_lock_irqsave (&dev->ff->atomiclock, flags); +if (__test_and_clear_bit + (FF_EFFECT_STARTED , dev->ff->effects[effect_id].flags)) +input_ff_calc_timer (dev->ff); +spin_unlock_irqrestore (&dev->ff->atomiclock, flags); +__clear_bit (FF_EFFECT_USED , dev->ff->effects[effect_id].flags); + }
drivers/input/ff-effects.c
Quoted 10 lines
drivers/input/ff-effects.c new file +10
-0+return ret; +} + + +/** +* Set the bits and handlers +* @driver: The ff_driver struct +* +* If possible, this function should be called before the input device is +* registered. It can however be ran again if the capability bits have
s/ran/run/
drivers/input/ff-effects.c line 817
Quoted 4 lines
drivers/input/ff-effects.c new file +4
-0+* changed. +*/ +int input_ff_register (struct input_dev *dev,struct ff_driver *driver) +{
---
~Randy
Re: [patch 12/12] input: use -ENOSPC instead of -ENOMEM in iforce when device full
In reply to Randy.DunlapQuoted 10 lines · Randy.Dunlap
Quoted 3 lines · On Tue, 30 May 2006 13:57:17 +0300 Anssi Hannula wrote:
Use
-ENOSPCinstead of-ENOMEMwhen the iforce device doesn't have enough free memory for the new effect. All other drivers are already been using-ENOSPC, so this makes the behaviour coherent.Could all of the others be wrong?
They could.
Quoted 3 lines
ENOSPC: No space left on device
ENOMEM: Not enough space [!?!?!?] or Out of memory
Hmm, I thought -ENOMEM is "Out of memory" and only to be used when the system is out of memory, not some internal memory chip in external device.
Does someone have an idea which one should be used?
Quoted 54 lines
Quoted 39 lines
Signed-off-by Anssi Hannula <[email protected]>---
drivers/input/joystick/iforce/iforce-ff.c| 8 ++++----1 files changed, 4 insertions(+), 4 deletions(-)Index:
linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce-ff.c
===================================================================drivers/input/joystick/iforce/iforce-ff.c +3
-3@@ -47,7 +47,7 @@ static int make_magnitude_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -80,7 +80,7 @@ static int make_period_modifier(struct i iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -120,7 +120,7 @@ static int make_envelope_modifier(struct iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }drivers/input/joystick/iforce/iforce-ff.c static int make_condition_modifier(struc
Quoted 10 lines
drivers/input/joystick/iforce/iforce-ff.c +1
-2@@ -157,7 +157,7 @@ static int make_condition_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); } -----
~Randy
Signature · 1 line
Anssi Hannula
Re: [patch 03/12] input: new force feedback interface
In reply to Randy.DunlapQuoted 2 lines · Randy.Dunlap
On Tue, 30 May 2006 13:57:08 +0300 Anssi Hannula wrote:
Thanks for reviewing.
Quoted 22 lines
Quoted 22 lines
drivers/input/Kconfig | 5 drivers/input/Makefile | 1 drivers/input/evdev.c | 30 - drivers/input/ff-effects.c | 894 +++++++++++++++++++++++++++++++++++++++++++++ drivers/input/input.c | 12 include/linux/input.h | 81 ++++ 6 files changed, 1006 insertions(+), 17 deletions(-)Index:
linux-2.6.17-rc4-git12/include/linux/input.h
===================================================================include/linux/input.h +9
-0@@ -1000,6 +1003,84 @@ struct input_handle { + +#ifdef CONFIG_INPUT_FF_EFFECTS +int input_ff_allocate (struct input_dev *dev); +int input_ff_register (struct input_dev *dev,struct ff_driver *driver); +int input_ff_upload (struct input_dev *dev,struct ff_effect *effect, +struct file *file); +int input_ff_erase (struct input_dev *dev,int effect_id,struct file *file); +int input_ff_event (struct input_dev *dev,unsigned int type, +unsigned int code,int value);
Quoted 9 lines
include/linux/input.h struct input_handle { · line 1063
Quoted 5 lines
include/linux/input.h +5
-0+#else +static inline int input_ff_allocate (struct input_dev *dev) +{ +return -EPERM ; +}
-ENOSYSseems more reasonable to me (above + below).
Okay, I'll send a patch to change -EPERM back to -ENOSYS.
I think the -EINVAL should be left as -EINVAL because they get called only when the user performs upload or erase ioctls on device that is not marked with EV_FF.
Quoted 40 lines
Quoted 30 lines
include/linux/input.h +20
-0+static inline int input_ff_register (struct input_dev *dev, +struct ff_driver *driver) +{ +return -EPERM ; +} +static inline int input_ff_upload (struct input_dev *dev, +struct ff_effect *effect,struct file *file) +{ +return -EINVAL ; +} +static inline int input_ff_erase (struct input_dev *dev,int effect_id, +struct file *file) +{ +return -EINVAL ; +} +static inline int input_ff_event (struct input_dev *dev,unsigned int type, +unsigned int code,int value) { } +#endif + +static inline void init_input_dev (struct input_dev *dev) {INIT_LIST_HEAD (&dev->h_list);Index:
linux-2.6.17-rc4-git12/drivers/input/ff-effects.c
===================================================================drivers/input/ff-effects.c line 8
Quoted 8 lines
drivers/input/ff-effects.c new file +8
-0@@ -0,0 +1,894 @@ +/* +* Force feedback support for Linux input subsystem +* +* Copyright (c) 2006 Anssi Hannula <[email protected]> +*/ + + +/**
Quoted 6 lines
"/**" indicates kernel-doc format, but the rest of the function comment is not in kernel-doc format. Please use kernel-doc for all non-static/non-inline functions (basically for public/exported symbols) and at your discretion for static functions.
(applies to many functions here)
Okay, I didn't know about kernel-doc. I'll adapt the comments.
Quoted 26 lines
Quoted 26 lines
drivers/input/ff-effects.c new file +25
-0+* Lock the mutex and check the device has not been deleted +*/ +static inline int input_ff_safe_lock (struct input_dev *dev) +{ +mutex_lock (&dev->ff_lock); +if (dev->ff) +return 0 ; + +mutex_unlock (&dev->ff_lock); +return 1 ; +} + +/** +* Check that the effect_id is a valid effect and the user has access to it +*/ +static inline int input_ff_effect_access (struct input_dev *dev,int effect_id, +struct file *file) +{ +struct ff_device *ff = dev->ff; + +if (effect_id >= dev->ff_effects_max || effect_id <0 + || !test_bit (FF_EFFECT_USED , ff->effects[effect_id].flags)) +return -EINVAL ; + +if (ff->effects[effect_id].owner != file)
Quoted 8 lines
drivers/input/ff-effects.c line 81
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+return -EACCES ; + +return 0 ; +} +See
Documentation/kernel-doc-nano-HOWTO.txtfor more info:
Ok.
Quoted 21 lines
Quoted 21 lines
drivers/input/ff-effects.c new file +20
-0+/** +* Check for the next time envelope requires an update on memoryless devices +* @event_time: Time of the next update +* +* If an event is found before @event_time, @event_time is changed and the +* functions returns 1. Otherwise it returns 0. +*/ +static int input_ff_envelope_time (struct ff_effect_status *effect, +struct ff_envelope *envelope, +unsigned long *event_time) +{ +} + +/** +* Calculate the next time effect requires an update on memoryless devices +* @ff: The device +* +* Runs through the effects and updates the timer if necessary. This function +* should be called only when the spinlock is locked. +*/
Quoted 8 lines
drivers/input/ff-effects.c line 134
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+static void input_ff_calc_timer (struct ff_device *ff) +{ +int i; +int events =0 ; +unsigned long next_time =0 ;We generally like a blank line between data and code lines....
Ok.
Quoted 68 lines
Quoted 68 lines
drivers/input/ff-effects.c new file +67
-0+debug ("calculating next timer" ); +for (i =0 ; i <FF_MEMLESS_EFFECTS ; ++i) { +unsigned long event_time; +struct ff_envelope *envelope =NULL ; +int event_set =0 ; + +if (!test_bit (FF_EFFECT_STARTED , ff->effects[i].flags)) { +if (test_bit (FF_EFFECT_PLAYING , ff->effects[i].flags)) { + event_time = ff->effects[i].stop_at = jiffies; + event_set =1 ; + }else +continue ; + }else { +if (!test_bit (FF_EFFECT_PLAYING , ff->effects[i].flags)) { + event_time = ff->effects[i].play_at; + event_set =1 ; + }else { +if (ff->effects[i].effect.type ==FF_PERIODIC ) + envelope = + &ff->effects[i].effect.u.periodic. + envelope; +else if (ff->effects[i].effect.type == +FF_CONSTANT ) + envelope = + &ff->effects[i].effect.u.constant. + envelope; + + event_set = +input_ff_envelope_time (&ff->effects[i], + envelope, + &event_time); +if (!event_set + && ff->effects[i].effect.replay.length) { + event_time = ff->effects[i].stop_at; + event_set =1 ; + } + } + } + +if (!event_set) +continue ; + events++; + +if (time_after (jiffies, event_time)) { + event_time = jiffies; +break ; + } +if (events ==1 ) + next_time = event_time; +else { +if (time_after (next_time, event_time)) + next_time = event_time; + } + } +if (!events) { +debug ("no actions" ); +del_timer (&ff->timer); + }else { +debug ("timer set" ); +mod_timer (&ff->timer, next_time); + } +} + + + +/** +* Safe sum
Quoted 9 lines
drivers/input/ff-effects.c line 288
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+* @a: Integer to sum +* @b: Integer to sum +* @limit: The sum limit +* +* If @a+@b is above @limit, return @limit unless a == 0, then return b, even if b > limit
Right.
Quoted 18 lines
Quoted 18 lines
drivers/input/ff-effects.c new file +18
-0+*/ +static int input_ff_safe_sum (int a,int b,int limit) +{ +int c; +if (!a) +return b; + c = a + b; +if (c > limit) +return limit; +return c; +} + +/** +* Convert an effect (for devices with memory) +*/ +static void input_ff_convert_effect (struct input_dev *dev, +struct ff_effect *effect) +{
Quoted 8 lines
drivers/input/ff-effects.c line 323
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+int strong_magnitude, weak_magnitude; + +if (effect->type ==FF_RUMBLE &&test_bit (FF_PERIODIC , dev->ff->flags)) { +/* Strong magnitude as 2/3 full and weak 1/3 full */ +/* Also divide by 2 */ why? Comments should explain why, not just what.
Okay, will add.
Quoted 23 lines
Quoted 23 lines
drivers/input/ff-effects.c new file +22
-0+ strong_magnitude = effect->u.rumble.strong_magnitude *2 /6 ; + weak_magnitude = effect->u.rumble.weak_magnitude /6 ; + + effect->type =FF_PERIODIC ; + + effect->u.periodic.waveform =FF_SINE ; + effect->u.periodic.period =50 ; + effect->u.periodic.magnitude = +input_ff_safe_sum (strong_magnitude, weak_magnitude,0x7fff ); + effect->u.periodic.offset =0 ; + effect->u.periodic.phase =0 ; + effect->u.periodic.envelope.attack_length =0 ; + effect->u.periodic.envelope.attack_level =0 ; + effect->u.periodic.envelope.fade_length =0 ; + effect->u.periodic.envelope.fade_level =0 ; +return ; + } + +printk (KERN_ERR +"ff-effects: invalid effect type in convert_effect()\n" ); +} +
Quoted 8 lines
drivers/input/ff-effects.c line 545
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+ + +/** +* Erase an effect +* @file: The requester needs all parameters listed/explained
Ok.
Quoted 32 lines
Quoted 32 lines
drivers/input/ff-effects.c new file +31
-0+* +* Erases the effect if the requester is also the effect owner. The mutex +* should already be locked before calling this function. If the device is a +* memoryless device, the spinlock will be locked. +*/ +static int _input_ff_erase (struct input_dev *dev,int effect_id, +struct file *file) +{ +unsigned long flags; +int ret =input_ff_effect_access (dev, effect_id, file); +if (ret) +return ret; +if (dev->ff->driver->playback) { + dev->ff->driver->playback (dev, effect_id,0 ); + ret = dev->ff->driver->erase (dev, effect_id); +if (!ret) +__clear_bit (FF_EFFECT_USED , + dev->ff->effects[effect_id].flags); + }else { +spin_lock_irqsave (&dev->ff->atomiclock, flags); +if (__test_and_clear_bit + (FF_EFFECT_STARTED , dev->ff->effects[effect_id].flags)) +input_ff_calc_timer (dev->ff); +spin_unlock_irqrestore (&dev->ff->atomiclock, flags); +__clear_bit (FF_EFFECT_USED , dev->ff->effects[effect_id].flags); + } +return ret; +} + + +/**
Quoted 9 lines
drivers/input/ff-effects.c line 813
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+* Set the bits and handlers +* @driver: The ff_driver struct +* +* If possible, this function should be called before the input device is +* registered. It can however be ran again if the capability bits have s/ran/run/
Will change.
Quoted 5 lines
Quoted 4 lines
drivers/input/ff-effects.c new file +4
-0+* changed. +*/ +int input_ff_register (struct input_dev *dev,struct ff_driver *driver) +{
Signature · 1 line
Anssi Hannula
Re: [patch 12/12] input: use -ENOSPC instead of -ENOMEM in iforce when device full
In reply to Anssi HannulaQuoted 12 lines · On Wed, 31 May 2006 13:04:24 +0300 Anssi Hannula wrote:
Quoted 10 lines · Randy.Dunlap
Quoted 3 lines · On Tue, 30 May 2006 13:57:17 +0300 Anssi Hannula wrote:
Use
-ENOSPCinstead of-ENOMEMwhen the iforce device doesn't have enough free memory for the new effect. All other drivers are already been using-ENOSPC, so this makes the behaviour coherent.Could all of the others be wrong?
Quoted 8 lines
They could.
Quoted 3 lines
ENOSPC: No space left on device
ENOMEM: Not enough space [!?!?!?] or Out of memoryHmm, I thought
-ENOMEMis "Out of memory" and only to be used when the system is out of memory, not some internal memory chip in external device.
Oh, in the case of a device vs. system, I do agree/prefer ENOSPC. Sorry about my confusion on that.
Quoted 50 lines
Does someone have an idea which one should be used?
Quoted 48 lines
Quoted 48 lines
Signed-off-by Anssi Hannula <[email protected]>---
drivers/input/joystick/iforce/iforce-ff.c| 8 ++++----1 files changed, 4 insertions(+), 4 deletions(-)Index:
linux-2.6.17-rc4-git12/drivers/input/joystick/iforce/iforce-ff.c
===================================================================drivers/input/joystick/iforce/iforce-ff.c +4
-4@@ -47,7 +47,7 @@ static int make_magnitude_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -80,7 +80,7 @@ static int make_period_modifier(struct i iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -120,7 +120,7 @@ static int make_envelope_modifier(struct iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }@@ -157,7 +157,7 @@ static int make_condition_modifier(struc iforce->device_memory.start, iforce->device_memory.end, 2L, NULL, NULL)) {mutex_unlock (&iforce->mem_mutex); -return -ENOMEM ; +return -ENOSPC ; }mutex_unlock (&iforce->mem_mutex); }
Quoted 1 line
Quoted 1 line
Quoted 1 line
--
---
~Randy
input: return -ENOSYS for registering functions when ff is disabled
In reply to Randy.DunlapReturn -ENOSYS instead of -EPERM for input_ff_allocate() and input_ff_register() when INPUT_FF_EFFECTS is disabled.
---
--- include/linux/input.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/input.h +2 -2
@@ -1059,12 +1059,12 @@ int input_ff_event(struct input_dev *dev#else static inline int input_ff_allocate (struct input_dev *dev) { -return -EPERM ; +return -ENOSYS ; }static inline int input_ff_register (struct input_dev *dev,struct ff_driver *driver) { -return -EPERM ; +return -ENOSYS ; }static inline int input_ff_upload (struct input_dev *dev,struct ff_effect *effect,struct file *file)
input: fix comments and blank lines in new ff code
In reply to Randy.DunlapFix comments so that they conform to kernel-doc and add/remove some blank lines.
---
--- drivers/input/ff-effects.c | 103 +++++++++++++++++++++++++------------- drivers/usb/input/hid-pidff.c | 112 +++++++++++++++++++++++------------------- 2 files changed, 130 insertions(+), 85 deletions(-)
drivers/input/ff-effects.c +68 -35
@@ -49,7 +49,9 @@ EXPORT_SYMBOL_GPL(input_ff_erase);EXPORT_SYMBOL_GPL (input_ff_event);/** -* Lock the mutex and check the device has not been deleted +* input_ff_safe_lock - lock the mutex and check for the ff_device struct +* +* Returns 0 if device still present, 1 otherwise. */ static inline int input_ff_safe_lock (struct input_dev *dev) {
@@ -62,7 +64,11 @@ static inline int input_ff_safe_lock(str }/** -* Check that the effect_id is a valid effect and the user has access to it +* input_ff_effect_access - check effect id validity and access rights +* +* Returns -EINVAL if the effect @effect_id is not a real effect. +* Returns -EACCES if the effect @effect_id is owned by another fd. +* Otherwise returns 0. */ static inline int input_ff_effect_access (struct input_dev *dev,int effect_id,struct file *file)
@@ -80,9 +86,10 @@ static inline int input_ff_effect_access }/** -* Check for the next time envelope requires an update on memoryless devices +* input_ff_envelope_time - find the time when envelope will require an update * @event_time: Time of the next update * +* Checks for the next time envelope requires an update on memoryless devices. * If an event is found before @event_time, @event_time is changed and the * functions returns 1. Otherwise it returns 0. */
@@ -91,6 +98,7 @@ static int input_ff_envelope_time(struct unsigned long *event_time) {unsigned long fade_start; +if (!envelope)return 0 ;
@@ -121,17 +129,19 @@ static int input_ff_envelope_time(struct }/** -* Calculate the next time effect requires an update on memoryless devices -* @ff: The device +* input_ff_calc_timer - recalculate the timer * -* Runs through the effects and updates the timer if necessary. This function -* should be called only when the spinlock is locked. +* Calculate the next time some effect requires an update on a memoryless +* device. Functions runs through all the effects and updates the timer if +* necessary. This function should be called only while the spinlock is +* locked. */ static void input_ff_calc_timer (struct ff_device *ff) {int i;int events =0 ;unsigned long next_time =0 ; +debug ("calculating next timer" );for (i =0 ; i <FF_MEMLESS_EFFECTS ; ++i) {unsigned long event_time;
@@ -196,7 +206,7 @@ static void input_ff_calc_timer(struct f }/** -* abs() with -0x8000 => 0x7fff exception +* input_ff_unsign - abs() with -0x8000 => 0x7fff exception */ static inline u16 input_ff_unsign (s16 value) {
@@ -207,7 +217,7 @@ static inline u16 input_ff_unsign(s16 va }/** -* Apply an envelope to a value +* input_ff_envelope - apply an envelope to a value */ static int input_ff_envelope (struct ff_effect_status *effect,int value,struct ff_envelope *envelope)
@@ -263,7 +273,10 @@ static int input_ff_envelope(struct ff_e }/** -* Return the type the effect has to be converted into (memless devices) +* input_ff_emu_effect_type - get the new effect type +* +* Get the effect type into which an @effect_type type effect has to be +* converted for device @dev. */ static int input_ff_emu_effect_type (struct input_dev *dev,int effect_type) {
@@ -280,12 +293,10 @@ static int input_ff_emu_effect_type(stru }/** -* Safe sum -* @a: Integer to sum -* @b: Integer to sum -* @limit: The sum limit +* input_ff_safe_sum - safe sum * -* If @a+@b is above @limit, return @limit +* If @a == 0, returns @b. If @a+@b is above @limit, returns @limit. Otherwise +* returns @a+@b. */ static int input_ff_safe_sum (int a,int b,int limit) {
@@ -299,7 +310,7 @@ static int input_ff_safe_sum(int a, int }/** -* Signed safe sum with range -0x80-0x7f +* input_ff_s8_sum - signed safe sum with range -0x80-0x7f */ static s8 input_ff_s8_sum (int a,int b) {
@@ -311,7 +322,7 @@ static s8 input_ff_s8_sum(int a, int b) }/** -* Convert an effect (for devices with memory) +* input_ff_convert_effect - convert an effect (for devices with memory) */ static void input_ff_convert_effect (struct input_dev *dev,struct ff_effect *effect)
@@ -319,8 +330,11 @@ static void input_ff_convert_effect(struint strong_magnitude, weak_magnitude;if (effect->type ==FF_RUMBLE &&test_bit (FF_PERIODIC , dev->ff->flags)) { -/* Strong magnitude as 2/3 full and weak 1/3 full */ -/* Also divide by 2 */ +/* All the below values are only estimates */ +/* Strong magnitude is regarded as 2/3 of the +periodic.magnitude and weak magnitude as 1/3 */ +/* They are also divided by 2 as they are u16 while +periodic.magnitude is s16 */ strong_magnitude = effect->u.rumble.strong_magnitude *2 /6 ; weak_magnitude = effect->u.rumble.weak_magnitude /6 ;
@@ -344,10 +358,10 @@ static void input_ff_convert_effect(stru }/** -* Sum two effects and apply gain -* @effect: The effect that is going to be sent to the device -* @new: The effect that is added to @effect -* @gain: The gain to be applied to @new before adding +* input_ff_sum_effect - sum two effects and apply gain +* @effect: the effect that is going to be sent to the device +* @new: the effect that is added to @effect +* @gain: the gain to be applied to @new before adding * * Memoryless devices have only one effect per effect type active at one time, * so we have to convert multiple effects to a single effect.
@@ -358,6 +372,7 @@ static void input_ff_sum_effect(struct funsigned int strong, weak, i;int x, y;fixp_t level; +switch (new->effect.type) {case FF_CONSTANT :if (effect->type !=FF_CONSTANT )
@@ -411,8 +426,8 @@ static void input_ff_sum_effect(struct f }/** -* Send the effects to the memoryless device -* @timer_data: struct input_dev +* input_ff_timer - send the effects to the memoryless device +* @timer_data: &struct input_dev * * All effects are converted and sent to the device. This function is atomic * so it cannot lock the mutex. Therefore any data structures this function
@@ -541,8 +556,10 @@ static void input_ff_timer(unsigned long }/** -* Erase an effect -* @file: The requester +* _input_ff_erase - erase an effect +* @dev: the current device +* @effect_id: the effect id of the effect to be erased +* @file: the requester * * Erases the effect if the requester is also the effect owner. The mutex * should already be locked before calling this function. If the device is a
@@ -553,6 +570,7 @@ static int _input_ff_erase(struct input_ {unsigned long flags;int ret =input_ff_effect_access (dev, effect_id, file); +if (ret)return ret;if (dev->ff->driver->playback) {
@@ -573,12 +591,18 @@ static int _input_ff_erase(struct input_ }/** -* Lock the mutex and call _input_ff_erase +* input_ff_erase - lock the mutex and erase an effect +* @dev: the current device +* @effect_id: the effect id of the effect to be erased +* @file: the requester +* +* Locks the mutex and calls _input_ff_erase. */ int input_ff_erase (struct input_dev *dev,int effect_id,struct file *file) {struct ff_device *ff;int ret; +if (!test_bit (EV_FF , dev->evbit))return -EINVAL ;if (input_ff_safe_lock (dev))
@@ -592,12 +616,16 @@ int input_ff_erase(struct input_dev *dev }/** -* Lock the mutex and call _input_ff_erase for all effects +* input_ff_flush - lock the mutex and erase all owned effects +* +* Locks the mutex and calls _input_ff_erase for all effects thus erasing all +* effects that are owned by the closed fd @file. */ static int input_ff_flush (struct input_dev *dev,struct file *file) {struct ff_device *ff;int i; +debug ("flushing now" );if (input_ff_safe_lock (dev))return -ENODEV ;
@@ -609,7 +637,7 @@ static int input_ff_flush(struct input_d }/** -* Handle the EV_FF input event +* input_ff_event - handle the EV_FF input event */ int input_ff_event (struct input_dev *dev,unsigned int type,unsigned int code,int value)
@@ -617,6 +645,7 @@ int input_ff_event(struct input_dev *devstruct ff_device *ff;unsigned long flags;int i; +if (type !=EV_FF || value <0 )return -EINVAL ;
@@ -686,7 +715,7 @@ int input_ff_event(struct input_dev *dev#define VALID_WFORM_MIN FF_SQUARE#define VALID_WFORM_MAX FF_CUSTOM/** -* Check that the effect type and waveform are valid +* input_ff_validate_effect - validate the effect type and waveform */ static int input_ff_validate_effect (struct ff_effect *effect) {
@@ -700,7 +729,10 @@ static int input_ff_validate_effect(stru }/** -* Handle effect upload +* input_ff_upload - handle effect upload +* @dev: the device +* @effect: the effect +* @file: the requester */ int input_ff_upload (struct input_dev *dev,struct ff_effect *effect,struct file *file)
@@ -786,7 +818,7 @@ int input_ff_upload(struct input_dev *de }/** -* Allocate the ff_device in dev->ff +* input_ff_allocate - allocate the ff_device in dev->ff for @dev */ int input_ff_allocate (struct input_dev *dev) {
@@ -806,16 +838,17 @@ int input_ff_allocate(struct input_dev * }/** -* Set the bits and handlers +* input_ff_register - set the ff bits and handlers * @driver: The ff_driver struct * * If possible, this function should be called before the input device is -* registered. It can however be ran again if the capability bits have +* registered. It can however be run again if the capability bits have * changed. */ int input_ff_register (struct input_dev *dev,struct ff_driver *driver) {int i; +debug ("registering device" );if (!dev->ff) { printk(KERN_ERR
drivers/usb/input/hid-pidff.c +62 -50
403 lines not on this page · raw message
Re: input: fix comments and blank lines in new ff code
Quoted 4 lines · On Thu, 01 Jun 2006 22:07:16 +0300 Anssi Hannula wrote:
Fix comments so that they conform to kernel-doc and add/remove some blank lines.
Signed-off-by Anssi Hannula <[email protected]>
(attachments make review/comments more trying, so this is an abbreviated reply)
/**
- * Lock the mutex and check the device has not been deleted
+ * input_ff_safe_lock - lock the mutex and check for the ff_device struct
+ *
+ * Returns 0 if device still present, 1 otherwise.
*/
static inline int input_ff_safe_lock(struct input_dev *dev)
{
Functions that are commented with kernel-doc need all of the parameters documented also, like:
* @dev: the input_dev (or better description)
There were a few places where you had these and deleted them. :(
~~~~~~~~~~~~~~
(repeat for several functions...)
---
~Randy
Re: input: fix comments and blank lines in new ff code
Quoted 11 lines · Randy.Dunlap
Quoted 4 lines · On Thu, 01 Jun 2006 22:07:16 +0300 Anssi Hannula wrote:
Fix comments so that they conform to kernel-doc and add/remove some blank lines.
Signed-off-by Anssi Hannula <[email protected]>(attachments make review/comments more trying, so this is an abbreviated reply)
Sorry, I'll try to use some other client when I send the fixed patch.
Quoted 12 lines
/**
- * Lock the mutex and check the device has not been deleted
+ *input_ff_safe_lock- lock the mutex and check for theff_devicestruct
+ *
+ * Returns 0 if device still present, 1 otherwise.
*/
static inline intinput_ff_safe_lock(struct input_dev *dev)
{Functions that are commented with kernel-doc need all of the parameters documented also, like:
Quoted 7 lines
* @dev: the
input_dev(or better description)There were a few places where you had these and deleted them. :(
~~~~~~~~~~~~~~(repeat for several functions...)
Ah, so if the comment is kernel-doc all parameters have to be always documented...
I guess I can just remove the double ** for static functions, as I'm not sure it is necessary to document all the obvious parameters of those.
Or what do you think?
Signature · 1 line
Anssi Hannula
Re: input: fix comments and blank lines in new ff code
Quoted 29 lines · On Thu, 01 Jun 2006 23:03:09 +0300 Anssi Hannula wrote:
Quoted 11 lines · Randy.Dunlap
Quoted 4 lines · On Thu, 01 Jun 2006 22:07:16 +0300 Anssi Hannula wrote:
Fix comments so that they conform to kernel-doc and add/remove some blank lines.
Signed-off-by Anssi Hannula <[email protected]>(attachments make review/comments more trying, so this is an abbreviated reply)
Sorry, I'll try to use some other client when I send the fixed patch.
Quoted 14 lines
/**
- * Lock the mutex and check the device has not been deleted
+ *input_ff_safe_lock- lock the mutex and check for theff_devicestruct
+ *
+ * Returns 0 if device still present, 1 otherwise.
*/
static inline intinput_ff_safe_lock(struct input_dev *dev)
{Functions that are commented with kernel-doc need all of the parameters documented also, like:
* @dev: the
input_dev(or better description)
Quoted 8 lines
Quoted 5 lines
There were a few places where you had these and deleted them. :(
~~~~~~~~~~~~~~(repeat for several functions...)
Ah, so if the comment is kernel-doc all parameters have to be always documented...
Right.
Quoted 4 lines
I guess I can just remove the double ** for static functions, as I'm not sure it is necessary to document all the obvious parameters of those.
Or what do you think?
I think that kernel-doc is most important on non-static functions, so it would be OK to remove the ** for the static ones.
---
~Randy
input: fix comments and blank lines in new ff code
From: Anssi Hannula <[email protected]>
Fix comments so that they conform to kernel-doc or remove ** if they are not in kernel-doc format.
Akso add/remove some blank lines.
---
Note that the From header of my email is different as otherwise osdl.org would mark my email as spam. Please use my gmail.com address.
drivers/input/ff-effects.c | 144 +++++++++++++++++++++------------ drivers/usb/input/hid-pidff.c | 183 ++++++++++++++++++++++-------------------- 2 files changed, 191 insertions(+), 136 deletions(-)
drivers/input/ff-effects.c +93 -51
@@ -48,8 +48,10 @@ EXPORT_SYMBOL_GPL(input_ff_upload);EXPORT_SYMBOL_GPL (input_ff_erase);EXPORT_SYMBOL_GPL (input_ff_event); -/** -* Lock the mutex and check the device has not been deleted +/* +* input_ff_safe_lock - lock the mutex and check for the ff_device struct +* +* Returns 0 if device still present, 1 otherwise. */ static inline int input_ff_safe_lock (struct input_dev *dev) {
@@ -61,8 +63,12 @@ static inline int input_ff_safe_lock(strreturn 1 ; } -/** -* Check that the effect_id is a valid effect and the user has access to it +/* +* input_ff_effect_access - check effect id validity and access rights +* +* Returns -EINVAL if the effect @effect_id is not a real effect. +* Returns -EACCES if the effect @effect_id is owned by another fd. +* Otherwise returns 0. */ static inline int input_ff_effect_access (struct input_dev *dev,int effect_id,struct file *file)
@@ -79,10 +85,11 @@ static inline int input_ff_effect_accessreturn 0 ; } -/** -* Check for the next time envelope requires an update on memoryless devices +/* +* input_ff_envelope_time - find the time when envelope will require an update * @event_time: Time of the next update * +* Checks for the next time envelope requires an update on memoryless devices. * If an event is found before @event_time, @event_time is changed and the * functions returns 1. Otherwise it returns 0. */
@@ -91,6 +98,7 @@ static int input_ff_envelope_time(struct unsigned long *event_time) {unsigned long fade_start; +if (!envelope)return 0 ;
@@ -120,18 +128,20 @@ static int input_ff_envelope_time(structreturn 1 ; } -/** -* Calculate the next time effect requires an update on memoryless devices -* @ff: The device +/* +* input_ff_calc_timer - recalculate the timer * -* Runs through the effects and updates the timer if necessary. This function -* should be called only when the spinlock is locked. +* Calculate the next time some effect requires an update on a memoryless +* device. Functions runs through all the effects and updates the timer if +* necessary. This function should be called only while the spinlock is +* locked. */ static void input_ff_calc_timer (struct ff_device *ff) {int i;int events =0 ;unsigned long next_time =0 ; +debug ("calculating next timer" );for (i =0 ; i <FF_MEMLESS_EFFECTS ; ++i) {unsigned long event_time;
@@ -195,8 +205,8 @@ static void input_ff_calc_timer(struct f } } -/** -* abs() with -0x8000 => 0x7fff exception +/* +* input_ff_unsign - abs() with -0x8000 => 0x7fff exception */ static inline u16 input_ff_unsign (s16 value) {
@@ -206,8 +216,8 @@ static inline u16 input_ff_unsign(s16 vareturn (value <0 ? -value : value); } -/** -* Apply an envelope to a value +/* +* input_ff_envelope - apply an envelope to a value */ static int input_ff_envelope (struct ff_effect_status *effect,int value,struct ff_envelope *envelope)
@@ -262,8 +272,11 @@ static int input_ff_envelope(struct ff_ereturn difference + envelope_level; } -/** -* Return the type the effect has to be converted into (memless devices) +/* +* input_ff_emu_effect_type - get the new effect type +* +* Get the effect type into which an @effect_type type effect has to be +* converted for device @dev. */ static int input_ff_emu_effect_type (struct input_dev *dev,int effect_type) {
@@ -279,13 +292,11 @@ static int input_ff_emu_effect_type(strureturn 0 ; } -/** -* Safe sum -* @a: Integer to sum -* @b: Integer to sum -* @limit: The sum limit +/* +* input_ff_safe_sum - safe sum * -* If @a+@b is above @limit, return @limit +* If @a == 0, returns @b. If @a+@b is above @limit, returns @limit. Otherwise +* returns @a+@b. */ static int input_ff_safe_sum (int a,int b,int limit) {
@@ -298,8 +309,8 @@ static int input_ff_safe_sum(int a, intreturn c; } -/** -* Signed safe sum with range -0x80-0x7f +/* +* input_ff_s8_sum - signed safe sum with range -0x80-0x7f */ static s8 input_ff_s8_sum (int a,int b) {
@@ -310,8 +321,8 @@ static s8 input_ff_s8_sum(int a, int b)return c; } -/** -* Convert an effect (for devices with memory) +/* +* input_ff_convert_effect - convert an effect (for devices with memory) */ static void input_ff_convert_effect (struct input_dev *dev,struct ff_effect *effect)
@@ -319,8 +330,11 @@ static void input_ff_convert_effect(struint strong_magnitude, weak_magnitude;if (effect->type ==FF_RUMBLE &&test_bit (FF_PERIODIC , dev->ff->flags)) { -/* Strong magnitude as 2/3 full and weak 1/3 full */ -/* Also divide by 2 */ +/* All the below values are only estimates */ +/* Strong magnitude is regarded as 2/3 of the +periodic.magnitude and weak magnitude as 1/3 */ +/* They are also divided by 2 as they are u16 while +periodic.magnitude is s16 */ strong_magnitude = effect->u.rumble.strong_magnitude *2 /6 ; weak_magnitude = effect->u.rumble.weak_magnitude /6 ;
@@ -343,11 +357,11 @@ static void input_ff_convert_effect(stru "ff-effects: invalid effect type in convert_effect()\n"); } -/** -* Sum two effects and apply gain -* @effect: The effect that is going to be sent to the device -* @new: The effect that is added to @effect -* @gain: The gain to be applied to @new before adding +/* +* input_ff_sum_effect - sum two effects and apply gain +* @effect: the effect that is going to be sent to the device +* @new: the effect that is added to @effect +* @gain: the gain to be applied to @new before adding * * Memoryless devices have only one effect per effect type active at one time, * so we have to convert multiple effects to a single effect.
@@ -358,6 +372,7 @@ static void input_ff_sum_effect(struct funsigned int strong, weak, i;int x, y;fixp_t level; +switch (new->effect.type) {case FF_CONSTANT :if (effect->type !=FF_CONSTANT )
@@ -410,9 +425,9 @@ static void input_ff_sum_effect(struct fprintk (KERN_ERR "ff-effects: invalid type in input_ff_sum_effect()\n" ); } -/** -* Send the effects to the memoryless device -* @timer_data: struct input_dev +/* +* input_ff_timer - send the effects to the memoryless device +* @timer_data: &struct input_dev * * All effects are converted and sent to the device. This function is atomic * so it cannot lock the mutex. Therefore any data structures this function
@@ -540,9 +555,11 @@ static void input_ff_timer(unsigned long } -/** -* Erase an effect -* @file: The requester +/* +* _input_ff_erase - erase an effect +* @dev: the current device +* @effect_id: the effect id of the effect to be erased +* @file: the requester * * Erases the effect if the requester is also the effect owner. The mutex * should already be locked before calling this function. If the device is a
@@ -553,6 +570,7 @@ static int _input_ff_erase(struct input_ {unsigned long flags;int ret =input_ff_effect_access (dev, effect_id, file); +if (ret)return ret;if (dev->ff->driver->playback) {
@@ -573,12 +591,18 @@ static int _input_ff_erase(struct input_ }/** -* Lock the mutex and call _input_ff_erase +* input_ff_erase - lock the mutex and erase an effect +* @dev: the current device +* @effect_id: the effect id of the effect to be erased +* @file: the requester +* +* Locks the mutex and calls _input_ff_erase. */ int input_ff_erase (struct input_dev *dev,int effect_id,struct file *file) {struct ff_device *ff;int ret; +if (!test_bit (EV_FF , dev->evbit))return -EINVAL ;if (input_ff_safe_lock (dev))
@@ -591,13 +615,17 @@ int input_ff_erase(struct input_dev *devreturn ret; } -/** -* Lock the mutex and call _input_ff_erase for all effects +/* +* input_ff_flush - lock the mutex and erase all owned effects +* +* Locks the mutex and calls _input_ff_erase for all effects thus erasing all +* effects that are owned by the closed fd @file. */ static int input_ff_flush (struct input_dev *dev,struct file *file) {struct ff_device *ff;int i; +debug ("flushing now" );if (input_ff_safe_lock (dev))return -ENODEV ;
@@ -609,7 +637,14 @@ static int input_ff_flush(struct input_d }/** -* Handle the EV_FF input event +* input_ff_event - handle the EV_FF input event +* @dev: the input device +* @type: EV_FF +* @code: FF_GAIN, FF_AUTOCENTER or the effect id +* @value: gain value, autocenter gain or the effect repeat count +* +* This function can be either assigned to the event() handler of input_dev +* directly or be called from the device driver's own event() handler. */ int input_ff_event (struct input_dev *dev,unsigned int type,unsigned int code,int value)
@@ -617,6 +652,7 @@ int input_ff_event(struct input_dev *devstruct ff_device *ff;unsigned long flags;int i; +if (type !=EV_FF || value <0 )return -EINVAL ;
@@ -685,8 +721,8 @@ int input_ff_event(struct input_dev *dev#define VALID_EFFECT_MAX FF_RAMP#define VALID_WFORM_MIN FF_SQUARE#define VALID_WFORM_MAX FF_CUSTOM -/** -* Check that the effect type and waveform are valid +/* +* input_ff_validate_effect - validate the effect type and waveform */ static int input_ff_validate_effect (struct ff_effect *effect) {
@@ -700,7 +736,10 @@ static int input_ff_validate_effect(stru }/** -* Handle effect upload +* input_ff_upload - handle effect upload +* @dev: the device +* @effect: the effect +* @file: the requester */ int input_ff_upload (struct input_dev *dev,struct ff_effect *effect,struct file *file)
@@ -786,7 +825,8 @@ int input_ff_upload(struct input_dev *de }/** -* Allocate the ff_device in dev->ff +* input_ff_allocate - allocate the ff_device in dev->ff for @dev +* @dev: the input device for which the ff_device is allocated */ int input_ff_allocate (struct input_dev *dev) {
@@ -806,16 +846,18 @@ int input_ff_allocate(struct input_dev * }/** -* Set the bits and handlers -* @driver: The ff_driver struct +* input_ff_register - set the ff bits and handlers +* @dev: the input_dev struct +* @driver: the ff_driver struct * * If possible, this function should be called before the input device is -* registered. It can however be ran again if the capability bits have +* registered. It can however be run again if the capability bits have * changed. */ int input_ff_register (struct input_dev *dev,struct ff_driver *driver) {int i; +debug ("registering device" );if (!dev->ff) { printk(KERN_ERR
drivers/usb/input/hid-pidff.c +98 -85
469 lines not on this page · raw message
Re: input: fix comments and blank lines in new ff code
Quoted 11 lines · On Thu, 1 Jun 2006 23:47:16 +0300 Anssi Hannula wrote:
From: Anssi Hannula <[email protected]>
Fix comments so that they conform to kernel-doc or remove ** if they are not in kernel-doc format.
Akso add/remove some blank lines.Signed-off-by Anssi Hannula <[email protected]>---
Note that the From header of my email is different as otherwise osdl.org would mark my email as spam. Please use my gmail.com address.
What's up with that? OSDL filters are overly strong?
Quoted 8 lines
Index:
linux-2.6.17-rc4-git12/drivers/usb/input/hid-pidff.c
===================================================================drivers/usb/input/hid-pidff.c +0
-0@@ -914,16 +925,17 @@ static int pidff_reports_ok(struct inputreturn 1 ; }
drivers/usb/input/hid-pidff.c static int pidff_reports_ok(struct input · line 933
Quoted 10 lines
drivers/usb/input/hid-pidff.c +4
-4-/** -* Find a field with a specific usage within a report -* @report: The report from where to find -* @usage: The wanted usage +/* +* pidff_find_logical_field - find a field with a specific logical usage +* @report: the report from where to find +* @usage: the wanted usage * @enforce_min: logical_minimum should be 1, otherwise return NULL */
Comment does not match function name.
drivers/usb/input/hid-pidff.c static int pidff_reports_ok(struct input · line 941
Quoted 8 lines
drivers/usb/input/hid-pidff.c +1
-0static struct hid_field *pidff_find_special_field (struct hid_report *report,int usage,int enforce_min) {int i; +for (i =0 ; i < report->maxfield; i++) {if (report->field[i]->logical == (HID_UP_PID | usage) && report->field[i]->report_count >0 ) {
And I noticed one function name _input_ff_erase(). That might be a namespace violation... anyone know the namespace rules?
Otherwise all looks good to me.
---
~Randy
Re: input: fix comments and blank lines in new ff code
Quoted 9 lines · Randy.Dunlap
Quoted 6 lines · On Thu, 1 Jun 2006 23:47:16 +0300 Anssi Hannula wrote:
From: Anssi Hannula <[email protected]>
Fix comments so that they conform to kernel-doc or remove ** if they are not in kernel-doc format.
Akso add/remove some blank lines.
Quoted 9 lines
Quoted 5 lines
Signed-off-by Anssi Hannula <[email protected]>---
Note that the From header of my email is different as otherwise osdl.org would mark my email as spam. Please use my gmail.com address.
What's up with that? OSDL filters are overly strong?
If I send mail with non-google SMTP server using a gmail.com address in
Quoted 1 line
From field, the osdl.org server drops the email as spam. That's because
they've configured their server to promote gmail.com SPF record ?all to -all (meaning that gmail.com SPF record says it neither denies or allowes messages from other SMTPs to use the gmail.com as From address, but osdl.org interpretes that as denial) due to high count of forged gmail.com mails.
I've no problem with Thunderbird anymore as I configured it to use gmail.com TLS SMTP server instead for emails where From is my gmail.com address. However I can't send inline patches using Thunderbird, only MIME attachments (they are in cleartext and have "Content-Disposition:
inline", however).
The patch was sent with another client to avoid using a MIME attachment, but that client was configured for my ISP's SMTP server.
I don't really know if a MIME attachment or "wrong" From email address is a bigger nuisance.
Quoted 9 lines
Quoted 9 lines
Index:
linux-2.6.17-rc4-git12/drivers/usb/input/hid-pidff.c
===================================================================drivers/usb/input/hid-pidff.c +0
-0@@ -914,16 +925,17 @@ static int pidff_reports_ok(struct inputreturn 1 ; }
Quoted 13 lines
drivers/usb/input/hid-pidff.c static int pidff_reports_ok(struct input · line 933
Quoted 10 lines
drivers/usb/input/hid-pidff.c +4
-4-/** -* Find a field with a specific usage within a report -* @report: The report from where to find -* @usage: The wanted usage +/* +* pidff_find_logical_field - find a field with a specific logical usage +* @report: the report from where to find +* @usage: the wanted usage * @enforce_min: logical_minimum should be 1, otherwise return NULL */ Comment does not match function name.
Hmh, I wonder how did I do that... I will send a one-liner patch for this.
Quoted 12 lines
drivers/usb/input/hid-pidff.c static int pidff_reports_ok(struct input · line 941
Quoted 9 lines
drivers/usb/input/hid-pidff.c +1
-0static struct hid_field *pidff_find_special_field (struct hid_report *report,int usage,int enforce_min) {int i; +for (i =0 ; i < report->maxfield; i++) {if (report->field[i]->logical == (HID_UP_PID | usage) && report->field[i]->report_count >0 ) {
Quoted 3 lines
And I noticed one function name
_input_ff_erase(). That might be a namespace violation... anyone know the namespace rules?
Namespace violation? Never heard of that one.
Quoted 1 line
Otherwise all looks good to me.
Signature · 1 line
Anssi Hannula
Re: input: fix comments and blank lines in new ff code
Quoted 6 lines · On Fri, 02 Jun 2006 01:16:05 +0300 Anssi Hannula wrote:
I've no problem with Thunderbird anymore as I configured it to use gmail.com TLS SMTP server instead for emails where From is my gmail.com address. However I can't send inline patches using Thunderbird, only MIME attachments (they are in cleartext and have "Content-Disposition:
inline", however).
check out http://mbligh.org/linuxdocs/Email/Clients/Thunderbird
I have also written a few emails about how to use thunderbird successfully, but I don't have links to them... :(
Quoted 5 lines
The patch was sent with another client to avoid using a MIME attachment, but that client was configured for my ISP's SMTP server.
I don't really know if a MIME attachment or "wrong" From email address is a bigger nuisance.
For me, it's attachments. Especially if you make the first line of your patch be the correct:
From: your name <[email protected]>
Quoted 5 lines
Quoted 3 lines
And I noticed one function name
_input_ff_erase(). That might be a namespace violation... anyone know the namespace rules?Namespace violation? Never heard of that one.
Kernel (usually?) uses names of the form xyz_abc or __xyz_abc, not (one underscore) _xyz_abc. Has something to do with POSIX namespace, but I don't know more about it.
---
~Randy
PATCH 1/1 input: fix function name in a comment
In reply to Randy.DunlapFix function name in a comment in drivers/usb/input/hid-pidff.c.
---
This is to be applied after my previous patch "input: fix comments and blank lines in new ff code" (Thu, 1 Jun 2006 23:47:16 +0300).
drivers/usb/input/hid-pidff.c | 2 +- 1 files changed, 1 insertion(+), 1 deletion(-)
drivers/usb/input/hid-pidff.c +1 -1
@@ -926,7 +926,7 @@ static int pidff_reports_ok(struct input }/* -* pidff_find_logical_field - find a field with a specific logical usage +* pidff_find_special_field - find a field with a specific logical usage * @report: the report from where to find * @usage: the wanted usage * @enforce_min: logical_minimum should be 1, otherwise return NULL
Dmitry Torokhov
maintainerRe: [patch 03/12] input: new force feedback interface
In reply to Anssi HannulaQuoted 4 lines · Anssi Hannula
Implement a new force feedback interface, in which all non-driver-specific operations are separated to a common module. This includes handling effect type validations, effect timers, locking, etc.
Still looking at it, couple of random points for now...
Quoted 5 lines
The code should be built as part of the input module, but unfortunately that would require renaming
input.c, which we don't want to do. So instead we makeINPUT_FF_EFFECTSa bool so that it cannot be built as a module.
I am not opposed to rename input.c, I wonder what pending changes besides David's header cleanup Andrew had in mind.
include/linux/input.h struct input_dev { · line 870
Quoted 7 lines
include/linux/input.h +3
-0@@ -865,6 +865,9 @@ struct input_dev {unsigned long sndbit[NBITS (SND_MAX )];unsigned long ffbit[NBITS (FF_MAX )];unsigned long swbit[NBITS (SW_MAX )]; + +struct ff_device *ff; +struct mutex ff_lock;
I believe that ff_lock should be part of ff_device and be only used to controll access when uploading/erasing effects. The teardown process should make sure that device inactive anyway only then remove ff_device from input_dev; by that time noone should be able to upload/erase effects. Therefore ff_lock is not needed to protect dev->ff.
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 static void input_dev_release(struct cla · line 740
Quoted 12 lines
===================================================================
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +5
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla { struct input_dev *dev = to_input_dev(class_dev); + if (dev->ff) { + struct ff_device *ff = dev->ff; + clear_bit(EV_FF, dev->evbit); + mutex_lock(&dev->ff_lock); + del_timer_sync(&ff->timer);
This is too late. We need to stop timer when device gets unregistered. Clearing FF bits is pointless here as device is about to disappear; locking is also not needed because we are guaranteed to be the last user of the device structure.
I wonder if ff should be released right at unregister time...
Quoted 9 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +6
-0+ dev->flush = NULL; + dev->ff = NULL; + mutex_unlock(&dev->ff_lock); + kfree(ff); + } + kfree(dev); module_put(THIS_MODULE); }
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 static void input_dev_release(struct cla
Quoted 10 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +9
-0+static inline int input_ff_safe_lock(struct input_dev *dev) +{ + mutex_lock(&dev->ff_lock); + if (dev->ff) + return 0; + + mutex_unlock(&dev->ff_lock); + return 1; +}
This needs to go away. Users should check whether a device supports FF and if it is then it is device's responsibility to keep it there until untregister time. We don't expect FF capabilities to flip/flop on a live device.
Quoted 5 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +5
-0+static void input_ff_calc_timer(struct ff_device *ff) +{ + int i; + int events = 0; + unsigned long next_time = 0;
...
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300
Quoted 3 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +3
-0+ + if (time_after(jiffies, event_time)) { + event_time = jiffies;
Should it be next_time = jiffies? We want to schedule thetimer ASAP, right?
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300
Quoted 11 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +11
-0+ +/** + * abs() with -0x8000 => 0x7fff exception + */ +static inline u16 input_ff_unsign(s16 value) +{ + if (value == -0x8000) + return 0x7fff; + + return (value < 0 ? -value : value); +}
Why is it needed?
Quoted 9 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +9
-0+ +/** + * Safe sum + * @a: Integer to sum + * @b: Integer to sum + * @limit: The sum limit + * + * If @a+@b is above @limit, return @limit + */
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300
Quoted 10 lines
drivers/input/input.c 2006-05-27 02:38:35.000000000 +0300 renamed from drivers/input/input.c 2006-05-27 02:28:57.000000000 +0300 +10
-0+static int input_ff_safe_sum(int a, int b, int limit) +{ + int c; + if (!a) + return b; + c = a + b; + if (c > limit) + return limit; + return c; +}
As it was mentioned the result will not be limited if a == 0. Is it intended?
PLease don;t start making any changes yet, I am still looking...
Signature · 1 line
Dmitry
Re: [patch 03/12] input: new force feedback interface
Quoted 22 lines · Dmitry Torokhov
Quoted 6 lines · Anssi Hannula
Implement a new force feedback interface, in which all non-driver-specific
operations are separated to a common module. This includes handling effect
type validations, effect timers, locking, etc.Still looking at it, couple of random points for now...
Quoted 7 lines
The code should be built as part of the input module, but unfortunately that
would require renaminginput.c, which we don't want to do. So instead we makeINPUT_FF_EFFECTSa bool so that it cannot be built as a module.I am not opposed to rename
input.c, I wonder what pending changes besides David's header cleanup Andrew had in mind.
Quoted 16 lines
include/linux/input.h struct input_dev { · line 870
Quoted 7 lines
include/linux/input.h +3
-0@@ -865,6 +865,9 @@ struct input_dev {unsigned long sndbit[NBITS (SND_MAX )];unsigned long ffbit[NBITS (FF_MAX )];unsigned long swbit[NBITS (SW_MAX )]; + +struct ff_device *ff; +struct mutex ff_lock;I believe that
ff_lockshould be part offf_deviceand be only used to controll access when uploading/erasing effects. The teardown process should make sure that device inactive anyway only then removeff_devicefrominput_dev; by that time noone should be able to upload/erase effects. Thereforeff_lockis not needed to protectdev->ff.
Hmm, I remember testing this by putting a 10 second sleep into the end of input_ff_effect_upload() and dropping the ff_locking when unregistering device. Then while in that sleep I unplugged the device. The dev->ff was indeed removed while the input_ff_effect_upload() was still running.
Maybe there was/is some bug in the input device unregistering process that doesn't account for ioctls.
Anyway, I'll retest this issue soon.
Quoted 10 lines
Quoted 10 lines
===================================================================
---linux-2.6.17-rc4-git12.orig/drivers/input/input.c2006-05-27
02:28:57.000000000 +0300
+++linux-2.6.17-rc4-git12/drivers/input/input.c2006-05-27
02:38:35.000000000 +0300drivers/input/input.c +0
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla {struct input_dev *dev =to_input_dev (class_dev);
Quoted 8 lines
drivers/input/input.c static void input_dev_release(struct cla · line 740
Quoted 5 lines
drivers/input/input.c +5
-0+if (dev->ff) { +struct ff_device *ff = dev->ff; +clear_bit (EV_FF , dev->evbit); +mutex_lock (&dev->ff_lock); +del_timer_sync (&ff->timer);This is too late. We need to stop timer when device gets unregistered.
And what if driver has called input_allocate_device(), input_ff_allocate(), input_ff_register(), but then decides to abort and
calls input_dev_release()? input_unregister_device() would not get
called at all.
Quoted 3 lines
Clearing FF bits is pointless here as device is about to disappear; locking is also not needed because we are guaranteed to be the last user of the device structure.
True, if that guarantee really exists.
Quoted 13 lines
I wonder if ff should be released right at unregister time...
Quoted 9 lines
drivers/input/input.c +6
-0+ dev->flush =NULL ; + dev->ff =NULL ; +mutex_unlock (&dev->ff_lock); +kfree (ff); + } +kfree (dev);module_put (THIS_MODULE ); }
Quoted 15 lines
drivers/input/ff-effects.c line 62
Quoted 9 lines
drivers/input/ff-effects.c new file +9
-0+static inline int input_ff_safe_lock (struct input_dev *dev) +{ +mutex_lock (&dev->ff_lock); +if (dev->ff) +return 0 ; + +mutex_unlock (&dev->ff_lock); +return 1 ; +}This needs to go away. Users should check whether a device supports FF and if it is then it is device's responsibility to keep it there until untregister time. We don't expect FF capabilities to flip/flop on a live device.
This too can be removed if it is guaranteed that the device is not deleted while ioctl is executing.
Quoted 8 lines
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+static void input_ff_calc_timer (struct ff_device *ff) +{ +int i; +int events =0 ; +unsigned long next_time =0 ;...
Quoted 6 lines
drivers/input/ff-effects.c line 179
Quoted 3 lines
drivers/input/ff-effects.c new file +3
-0+ +if (time_after (jiffies, event_time)) { + event_time = jiffies;Should it be
next_time= jiffies? We want to schedule thetimer ASAP, right?
Yes, a good catch.
Quoted 6 lines
Quoted 6 lines
drivers/input/ff-effects.c new file +6
-0+ +/** +* abs() with -0x8000 => 0x7fff exception +*/ +static inline u16 input_ff_unsign (s16 value) +{
Quoted 8 lines
drivers/input/ff-effects.c line 207
Quoted 5 lines
drivers/input/ff-effects.c new file +5
-0+if (value ==-0x8000 ) +return 0x7fff ; + +return (value <0 ? -value : value); +}Why is it needed?
Oh, well... the maximum value of s16 is 0x7fff in positive side, -0x8000 in negative side. In input_ff_sum_effect() (apparently the only function that uses this) the "i = i * gain / 0x7fff" uses the maximum value of 0x7fff.
Then again, I guess it wouldn't really matter if that exception is just skipped and then detect the small overflow in input_ff_safe_sum().
Quoted 16 lines
Quoted 16 lines
drivers/input/ff-effects.c new file +15
-0+ +/** +* Safe sum +* @a: Integer to sum +* @b: Integer to sum +* @limit: The sum limit +* +* If @a+@b is above @limit, return @limit +*/ +static int input_ff_safe_sum (int a,int b,int limit) +{ +int c; +if (!a) +return b; + c = a + b;
Quoted 8 lines
drivers/input/ff-effects.c line 299
Quoted 4 lines
drivers/input/ff-effects.c new file +4
-0+if (c > limit) +return limit; +return c; +}As it was mentioned the result will not be limited if a == 0. Is it intended?
Well, b is guaranteed by the caller to be below the limit. However, if that input_ff_unsign() stuff is dropped in favor of abs(), b could be above limit and then if(!a) should be dropped.
Quoted 2 lines
PLease don;t start making any changes yet, I am still looking...
Ok.
Signature · 1 line
Anssi Hannula
Re: [patch 03/12] input: new force feedback interface
Quoted 46 lines · Anssi Hannula
Quoted 22 lines · Dmitry Torokhov
Quoted 6 lines · Anssi Hannula
Implement a new force feedback interface, in which all non-driver-specific
operations are separated to a common module. This includes handling effect
type validations, effect timers, locking, etc.Still looking at it, couple of random points for now...
Quoted 7 lines
The code should be built as part of the input module, but unfortunately that
would require renaminginput.c, which we don't want to do. So instead we makeINPUT_FF_EFFECTSa bool so that it cannot be built as a module.I am not opposed to rename
input.c, I wonder what pending changes besides David's header cleanup Andrew had in mind.Quoted 16 lines
include/linux/input.h struct input_dev { · line 870
Quoted 7 lines
include/linux/input.h +3
-0@@ -865,6 +865,9 @@ struct input_dev {unsigned long sndbit[NBITS (SND_MAX )];unsigned long ffbit[NBITS (FF_MAX )];unsigned long swbit[NBITS (SW_MAX )]; + +struct ff_device *ff; +struct mutex ff_lock;I believe that
ff_lockshould be part offf_deviceand be only used to controll access when uploading/erasing effects. The teardown process should make sure that device inactive anyway only then removeff_devicefrominput_dev; by that time noone should be able to upload/erase effects. Thereforeff_lockis not needed to protectdev->ff.Hmm, I remember testing this by putting a 10 second sleep into the end of
input_ff_effect_upload()and dropping theff_lockingwhen unregistering device. Then while in that sleep I unplugged the device. Thedev->ffwas indeed removed while theinput_ff_effect_upload()was still running.
Quoted 5 lines
Maybe there was/is some bug in the input device unregistering process that doesn't account for ioctls.
Anyway, I'll retest this issue soon.
And it will fail, locking is missing many parts of input core. Notice I said _should_, not will ;) I was trying to paint how it should work when we have proper locking and I don't want to use ff_lock to paper over some bugs in the core.
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
===================================================================
---linux-2.6.17-rc4-git12.orig/drivers/input/input.c2006-05-27
02:28:57.000000000 +0300
+++linux-2.6.17-rc4-git12/drivers/input/input.c2006-05-27
02:38:35.000000000 +0300drivers/input/input.c +0
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla {struct input_dev *dev =to_input_dev (class_dev);Quoted 8 lines
drivers/input/input.c static void input_dev_release(struct cla · line 740
Quoted 5 lines
drivers/input/input.c +5
-0+if (dev->ff) { +struct ff_device *ff = dev->ff; +clear_bit (EV_FF , dev->evbit); +mutex_lock (&dev->ff_lock); +del_timer_sync (&ff->timer);This is too late. We need to stop timer when device gets unregistered.
Quoted 5 lines
And what if driver has called
input_allocate_device(),input_ff_allocate(),input_ff_register(), but then decides to abort and
callsinput_dev_release()?input_unregister_device()would not get
called at all.
Right, but if device was never registered there is no device node so noone could start the timer and deleting it is a noop. Hmm, I think even better place would be to stop ff timer when device is closed (i.e. when last user closes file handle).
Quoted 6 lines
Quoted 3 lines
Clearing FF bits is pointless here as device is about to disappear; locking is also not needed because we are guaranteed to be the last user of the device structure.
True, if that guarantee really exists.
Yes, this is guaranteed.
Signature · 1 line
Dmitry
Re: [patch 03/12] input: new force feedback interface
Quoted 54 lines · Dmitry Torokhov
Quoted 52 lines · Anssi Hannula
Quoted 24 lines · Dmitry Torokhov
Quoted 6 lines · Anssi Hannula
Implement a new force feedback interface, in which all non-driver-specific
operations are separated to a common module. This includes handling effect
type validations, effect timers, locking, etc.Still looking at it, couple of random points for now...
Quoted 6 lines
The code should be built as part of the input module, but unfortunately that
would require renaminginput.c, which we don't want to do. So instead we makeINPUT_FF_EFFECTSa bool so that it cannot be built as a module.I am not opposed to rename
input.c, I wonder what pending changes besides David's header cleanup Andrew had in mind.Quoted 16 lines
include/linux/input.h struct input_dev { · line 870
Quoted 7 lines
include/linux/input.h +3
-0@@ -865,6 +865,9 @@ struct input_dev {unsigned long sndbit[NBITS (SND_MAX )];unsigned long ffbit[NBITS (FF_MAX )];unsigned long swbit[NBITS (SW_MAX )]; + +struct ff_device *ff; +struct mutex ff_lock;I believe that
ff_lockshould be part offf_deviceand be only used to controll access when uploading/erasing effects. The teardown process should make sure that device inactive anyway only then removeff_devicefrominput_dev; by that time noone should be able to upload/erase effects. Thereforeff_lockis not needed to protectdev->ff.Hmm, I remember testing this by putting a 10 second sleep into the end of
input_ff_effect_upload()and dropping theff_lockingwhen unregistering device. Then while in that sleep I unplugged the device. Thedev->ffwas indeed removed while theinput_ff_effect_upload()was still running.Maybe there was/is some bug in the input device unregistering process that doesn't account for ioctls.
Quoted 9 lines
Quoted 2 lines
Anyway, I'll retest this issue soon.
And it will fail, locking is missing many parts of input core. Notice I said _should_, not will ;) I was trying to paint how it should work when we have proper locking and I don't want to use
ff_lockto paper over some bugs in the core.
Ah, ok.
Quoted 25 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
===================================================================
---linux-2.6.17-rc4-git12.orig/drivers/input/input.c2006-05-27
02:28:57.000000000 +0300
+++linux-2.6.17-rc4-git12/drivers/input/input.c2006-05-27
02:38:35.000000000 +0300drivers/input/input.c +0
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla {struct input_dev *dev =to_input_dev (class_dev);Quoted 8 lines
drivers/input/input.c static void input_dev_release(struct cla · line 740
Quoted 5 lines
drivers/input/input.c +5
-0+if (dev->ff) { +struct ff_device *ff = dev->ff; +clear_bit (EV_FF , dev->evbit); +mutex_lock (&dev->ff_lock); +del_timer_sync (&ff->timer);This is too late. We need to stop timer when device gets unregistered.
Quoted 5 lines
And what if driver has called
input_allocate_device(),input_ff_allocate(),input_ff_register(), but then decides to abort and
callsinput_dev_release()?input_unregister_device()would not get
called at all.
Quoted 5 lines
Right, but if device was never registered there is no device node so noone could start the timer and deleting it is a noop. Hmm, I think even better place would be to stop ff timer when device is closed (i.e. when last user closes file handle).
Hmm... actually, they are stopped in flush(), and IIRC that is always called before deleting input_dev.
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
Clearing FF bits is pointless here as device is about to disappear; locking is also not needed because we are guaranteed to be the last user of the device structure.
True, if that guarantee really exists.
Yes, this is guaranteed.
So, now you guarantee it, but it isn't really so? ;)
When we remove locking, timer_del, clear_bit, all that is left is kfree() and I guess that has to still be run in the input_dev_release().
Signature · 1 line
Anssi Hannula
Dmitry Torokhov
maintainerRe: [patch 03/12] input: new force feedback interface
Quoted 30 lines · Anssi Hannula
Quoted 29 lines · Dmitry Torokhov
Quoted 25 lines · Anssi Hannula
Quoted 9 lines · Dmitry Torokhov
Quoted 8 lines · Anssi Hannula
---
linux-2.6.17-rc4-git12.orig/drivers/input/input.c2006-05-27
02:28:57.000000000 +0300
+++linux-2.6.17-rc4-git12/drivers/input/input.c2006-05-27
02:38:35.000000000 +0300drivers/input/input.c +0
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla {struct input_dev *dev =to_input_dev (class_dev);Quoted 8 lines
drivers/input/input.c static void input_dev_release(struct cla · line 740
Quoted 5 lines
drivers/input/input.c +5
-0+if (dev->ff) { +struct ff_device *ff = dev->ff; +clear_bit (EV_FF , dev->evbit); +mutex_lock (&dev->ff_lock); +del_timer_sync (&ff->timer);This is too late. We need to stop timer when device gets unregistered.
And what if driver has called
input_allocate_device(),input_ff_allocate(),input_ff_register(), but then decides to abort and
callsinput_dev_release()?input_unregister_device()would not get
called at all.
Quoted 9 lines
Quoted 5 lines
Right, but if device was never registered there is no device node so noone could start the timer and deleting it is a noop. Hmm, I think even better place would be to stop ff timer when device is closed (i.e. when last user closes file handle).
Hmm... actually, they are stopped in
flush(), and IIRC that is always called before deletinginput_dev.
flush is called when you close one file handle. If there are more than one process opened event device you only want to stop timer when they all closed ther handles, not when the first one did.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Clearing FF bits is pointless here as device is about to disappear; locking is also not needed because we are guaranteed to be the last user of the device structure.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
True, if that guarantee really exists.
Yes, this is guaranteed.
So, now you guarantee it, but it isn't really so? ;)
Hmm, I thought I could guarantee it, but not yet ;)
Quoted 3 lines
When we remove locking,
timer_del,clear_bit, all that is left iskfree()and I guess that has to still be run in theinput_dev_release().
Yes.
Signature · 1 line
Dmitry
Re: [patch 03/12] input: new force feedback interface
Quoted 41 lines · Dmitry Torokhov
Quoted 39 lines · Anssi Hannula
Quoted 22 lines · Dmitry Torokhov
Quoted 20 lines · Anssi Hannula
Quoted 17 lines · Dmitry Torokhov
drivers/input/input.c static void input_dev_release(struct cla · line 740
Quoted 13 lines · Anssi Hannula
---
linux-2.6.17-rc4-git12.orig/drivers/input/input.c2006-05-27
02:28:57.000000000 +0300
+++linux-2.6.17-rc4-git12/drivers/input/input.c2006-05-27
02:38:35.000000000 +0300drivers/input/input.c +5
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla {struct input_dev *dev =to_input_dev (class_dev); +if (dev->ff) { +struct ff_device *ff = dev->ff; +clear_bit (EV_FF , dev->evbit); +mutex_lock (&dev->ff_lock); +del_timer_sync (&ff->timer);This is too late. We need to stop timer when device gets unregistered.
Quoted 8 lines
Quoted 5 lines
And what if driver has called
input_allocate_device(),input_ff_allocate(),input_ff_register(), but then decides to abort and
callsinput_dev_release()?input_unregister_device()would not get
called at all.Right, but if device was never registered there is no device node so
noone
Quoted 1 line
could start the timer and deleting it is a noop. Hmm, I think even
better
Quoted 1 line
place would be to stop ff timer when device is closed (i.e. when
last user
Quoted 2 lines
closes file handle).
Quoted 8 lines
Quoted 3 lines
Hmm... actually, they are stopped in
flush(), and IIRC that is always called before deletinginput_dev.flush is called when you close one file handle. If there are more than one process opened event device you only want to stop timer when they all closed ther handles, not when the first one did.
It doesn't stop the timer explicitely. It only calls the timer recalculator function and when all file handles are closed => all effects are deleted => no events => input_ff_recalculate_timer() stops the timer.
And IIRC when device is being removed, kernel actually waits for the file handles to be flush()ed before kfree()ing the input_dev.
But hmm, when device is being removed with effects running, and input_ff_flush() erases effects and calls input_ff_recalculate_timer(), that function schedules the timer to run immediately to stop the effects. Therefore we would have a race condition: without locking dev->ff could be deleted while input_ff_timer() is still running.
That is the reason why del_timer_sync() is in input_dev_release(), to make sure the input_ff_timer() is no longer running.
Signature · 1 line
Anssi Hannula
Re: [patch 03/12] input: new force feedback interface
Quoted 72 lines · Anssi Hannula
Quoted 52 lines · Dmitry Torokhov
Quoted 49 lines · Anssi Hannula
Quoted 25 lines · Dmitry Torokhov
Quoted 22 lines · Anssi Hannula
Quoted 18 lines · Dmitry Torokhov
Review static void input_dev_release(struct cla · line 740
Quoted 13 lines · Anssi Hannula
---
linux-2.6.17-rc4-git12.orig/drivers/input/input.c2006-05-27
02:28:57.000000000 +0300
+++linux-2.6.17-rc4-git12/drivers/input/input.c2006-05-27
02:38:35.000000000 +0300(quoted diff) +5
-0@@ -733,6 +733,17 @@ static void input_dev_release(struct cla { struct input_dev *dev = to_input_dev(class_dev); + if (dev->ff) { + struct ff_device *ff = dev->ff; + clear_bit(EV_FF, dev->evbit); + mutex_lock(&dev->ff_lock); + del_timer_sync(&ff->timer);This is too late. We need to stop timer when device gets unregistered.
Quoted 8 lines
Quoted 5 lines
And what if driver has called
input_allocate_device(),input_ff_allocate(),input_ff_register(), but then decides to abort and
callsinput_dev_release()?input_unregister_device()would not get
called at all.Right, but if device was never registered there is no device node so
noone
Quoted 1 line
could start the timer and deleting it is a noop. Hmm, I think even
better
Quoted 1 line
place would be to stop ff timer when device is closed (i.e. when
last user
Quoted 2 lines
closes file handle).
Quoted 8 lines
Quoted 3 lines
Hmm... actually, they are stopped in
flush(), and IIRC that is always called before deletinginput_dev.flush is called when you close one file handle. If there are more than one process opened event device you only want to stop timer when they all closed ther handles, not when the first one did.
It doesn't stop the timer explicitely. It only calls the timer recalculator function and when all file handles are closed => all effects are deleted => no events =>
input_ff_recalculate_timer()stops the timer.And IIRC when device is being removed, kernel actually waits for the file handles to be flush()ed before kfree()ing the
input_dev.
Quoted 8 lines
But hmm, when device is being removed with effects running, and
input_ff_flush()erases effects and callsinput_ff_recalculate_timer(), that function schedules the timer to run immediately to stop the effects. Therefore we would have a race condition: without lockingdev->ffcould be deleted whileinput_ff_timer()is still running.That is the reason why
del_timer_sync()is ininput_dev_release(), to make sure theinput_ff_timer()is no longer running.
I guess we could have an atomic bit timer_is_active which would be set when the timer is either pending or timer function is running, and then in device closing or unregistering wait for it to be cleared:
1. Timer is running.
2. input_unregister_device() gets called and blocks until file handles are closed
3. The user closes the file handle.
4. input_ff_flush() removes the effects and recalculates timer. => timer is set to execute immediately, as there are effects to be stopped
5. input_close_device() or input_unregister_device() waits for the timer to finish, i.e. timer_is_active to be cleared.
Dmitry, should I make the modifications and send a patch, or do you want to have more time to look at my patches?
Signature · 1 line
Anssi Hannula