2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2006-07-19 05:40:30 +00:00
|
|
|
/*
|
|
|
|
* Force feedback support for memoryless devices
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Anssi Hannula <anssi.hannula@gmail.com>
|
|
|
|
* Copyright (c) 2006 Dmitry Torokhov <dtor@mail.ru>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* #define DEBUG */
|
|
|
|
|
2010-11-30 07:33:07 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
2006-07-19 05:40:30 +00:00
|
|
|
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2006-07-19 05:40:30 +00:00
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/spinlock.h>
|
[PATCH] remove many unneeded #includes of sched.h
After Al Viro (finally) succeeded in removing the sched.h #include in module.h
recently, it makes sense again to remove other superfluous sched.h includes.
There are quite a lot of files which include it but don't actually need
anything defined in there. Presumably these includes were once needed for
macros that used to live in sched.h, but moved to other header files in the
course of cleaning it up.
To ease the pain, this time I did not fiddle with any header files and only
removed #includes from .c-files, which tend to cause less trouble.
Compile tested against 2.6.20-rc2 and 2.6.20-rc2-mm2 (with offsets) on alpha,
arm, i386, ia64, mips, powerpc, and x86_64 with allnoconfig, defconfig,
allmodconfig, and allyesconfig as well as a few randconfigs on x86_64 and all
configs in arch/arm/configs on arm. I also checked that no new warnings were
introduced by the patch (actually, some warnings are removed that were emitted
by unnecessarily included header files).
Signed-off-by: Tim Schmielau <tim@physik3.uni-rostock.de>
Acked-by: Russell King <rmk+kernel@arm.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-02-14 08:33:14 +00:00
|
|
|
#include <linux/jiffies.h>
|
2012-05-14 11:07:44 +00:00
|
|
|
#include <linux/fixp-arith.h>
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Anssi Hannula <anssi.hannula@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("Force feedback support for memoryless devices");
|
|
|
|
|
|
|
|
/* Number of effects handled with memoryless devices */
|
|
|
|
#define FF_MEMLESS_EFFECTS 16
|
|
|
|
|
|
|
|
/* Envelope update interval in ms */
|
|
|
|
#define FF_ENVELOPE_INTERVAL 50
|
|
|
|
|
|
|
|
#define FF_EFFECT_STARTED 0
|
|
|
|
#define FF_EFFECT_PLAYING 1
|
|
|
|
#define FF_EFFECT_ABORTING 2
|
|
|
|
|
|
|
|
struct ml_effect_state {
|
|
|
|
struct ff_effect *effect;
|
|
|
|
unsigned long flags; /* effect state (STARTED, PLAYING, etc) */
|
|
|
|
int count; /* loop count of the effect */
|
|
|
|
unsigned long play_at; /* start time */
|
|
|
|
unsigned long stop_at; /* stop time */
|
|
|
|
unsigned long adj_at; /* last time the effect was sent */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ml_device {
|
|
|
|
void *private;
|
|
|
|
struct ml_effect_state states[FF_MEMLESS_EFFECTS];
|
|
|
|
int gain;
|
|
|
|
struct timer_list timer;
|
|
|
|
struct input_dev *dev;
|
|
|
|
|
|
|
|
int (*play_effect)(struct input_dev *dev, void *data,
|
|
|
|
struct ff_effect *effect);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct ff_envelope *get_envelope(const struct ff_effect *effect)
|
|
|
|
{
|
|
|
|
static const struct ff_envelope empty_envelope;
|
|
|
|
|
|
|
|
switch (effect->type) {
|
2012-07-30 05:33:03 +00:00
|
|
|
case FF_PERIODIC:
|
|
|
|
return &effect->u.periodic.envelope;
|
|
|
|
|
|
|
|
case FF_CONSTANT:
|
|
|
|
return &effect->u.constant.envelope;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return &empty_envelope;
|
2006-07-19 05:40:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for the next time envelope requires an update on memoryless devices
|
|
|
|
*/
|
|
|
|
static unsigned long calculate_next_time(struct ml_effect_state *state)
|
|
|
|
{
|
|
|
|
const struct ff_envelope *envelope = get_envelope(state->effect);
|
|
|
|
unsigned long attack_stop, fade_start, next_fade;
|
|
|
|
|
|
|
|
if (envelope->attack_length) {
|
|
|
|
attack_stop = state->play_at +
|
|
|
|
msecs_to_jiffies(envelope->attack_length);
|
|
|
|
if (time_before(state->adj_at, attack_stop))
|
|
|
|
return state->adj_at +
|
|
|
|
msecs_to_jiffies(FF_ENVELOPE_INTERVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state->effect->replay.length) {
|
|
|
|
if (envelope->fade_length) {
|
|
|
|
/* check when fading should start */
|
|
|
|
fade_start = state->stop_at -
|
|
|
|
msecs_to_jiffies(envelope->fade_length);
|
|
|
|
|
|
|
|
if (time_before(state->adj_at, fade_start))
|
|
|
|
return fade_start;
|
|
|
|
|
|
|
|
/* already fading, advance to next checkpoint */
|
|
|
|
next_fade = state->adj_at +
|
|
|
|
msecs_to_jiffies(FF_ENVELOPE_INTERVAL);
|
|
|
|
if (time_before(next_fade, state->stop_at))
|
|
|
|
return next_fade;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state->stop_at;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state->play_at;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ml_schedule_timer(struct ml_device *ml)
|
|
|
|
{
|
|
|
|
struct ml_effect_state *state;
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
unsigned long earliest = 0;
|
|
|
|
unsigned long next_at;
|
|
|
|
int events = 0;
|
|
|
|
int i;
|
|
|
|
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("calculating next timer\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
for (i = 0; i < FF_MEMLESS_EFFECTS; i++) {
|
|
|
|
|
|
|
|
state = &ml->states[i];
|
|
|
|
|
|
|
|
if (!test_bit(FF_EFFECT_STARTED, &state->flags))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (test_bit(FF_EFFECT_PLAYING, &state->flags))
|
|
|
|
next_at = calculate_next_time(state);
|
|
|
|
else
|
|
|
|
next_at = state->play_at;
|
|
|
|
|
|
|
|
if (time_before_eq(now, next_at) &&
|
|
|
|
(++events == 1 || time_before(next_at, earliest)))
|
|
|
|
earliest = next_at;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!events) {
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("no actions\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
del_timer(&ml->timer);
|
|
|
|
} else {
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("timer set\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
mod_timer(&ml->timer, earliest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Apply an envelope to a value
|
|
|
|
*/
|
|
|
|
static int apply_envelope(struct ml_effect_state *state, int value,
|
|
|
|
struct ff_envelope *envelope)
|
|
|
|
{
|
|
|
|
struct ff_effect *effect = state->effect;
|
|
|
|
unsigned long now = jiffies;
|
|
|
|
int time_from_level;
|
|
|
|
int time_of_envelope;
|
|
|
|
int envelope_level;
|
|
|
|
int difference;
|
|
|
|
|
|
|
|
if (envelope->attack_length &&
|
|
|
|
time_before(now,
|
|
|
|
state->play_at + msecs_to_jiffies(envelope->attack_length))) {
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("value = 0x%x, attack_level = 0x%x\n",
|
|
|
|
value, envelope->attack_level);
|
2006-07-19 05:40:30 +00:00
|
|
|
time_from_level = jiffies_to_msecs(now - state->play_at);
|
|
|
|
time_of_envelope = envelope->attack_length;
|
2012-07-08 01:17:54 +00:00
|
|
|
envelope_level = min_t(u16, envelope->attack_level, 0x7fff);
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
} else if (envelope->fade_length && effect->replay.length &&
|
|
|
|
time_after(now,
|
|
|
|
state->stop_at - msecs_to_jiffies(envelope->fade_length)) &&
|
|
|
|
time_before(now, state->stop_at)) {
|
|
|
|
time_from_level = jiffies_to_msecs(state->stop_at - now);
|
|
|
|
time_of_envelope = envelope->fade_length;
|
2012-07-08 01:17:54 +00:00
|
|
|
envelope_level = min_t(u16, envelope->fade_level, 0x7fff);
|
2006-07-19 05:40:30 +00:00
|
|
|
} else
|
|
|
|
return value;
|
|
|
|
|
|
|
|
difference = abs(value) - envelope_level;
|
|
|
|
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("difference = %d\n", difference);
|
|
|
|
pr_debug("time_from_level = 0x%x\n", time_from_level);
|
|
|
|
pr_debug("time_of_envelope = 0x%x\n", time_of_envelope);
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
difference = difference * time_from_level / time_of_envelope;
|
|
|
|
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("difference = %d\n", difference);
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
return value < 0 ?
|
|
|
|
-(difference + envelope_level) : (difference + envelope_level);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return the type the effect has to be converted into (memless devices)
|
|
|
|
*/
|
|
|
|
static int get_compatible_type(struct ff_device *ff, int effect_type)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (test_bit(effect_type, ff->ffbit))
|
|
|
|
return effect_type;
|
|
|
|
|
|
|
|
if (effect_type == FF_PERIODIC && test_bit(FF_RUMBLE, ff->ffbit))
|
|
|
|
return FF_RUMBLE;
|
|
|
|
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_err("invalid type in get_compatible_type()\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-12-25 05:52:20 +00:00
|
|
|
/*
|
|
|
|
* Only left/right direction should be used (under/over 0x8000) for
|
|
|
|
* forward/reverse motor direction (to keep calculation fast & simple).
|
|
|
|
*/
|
|
|
|
static u16 ml_calculate_direction(u16 direction, u16 force,
|
|
|
|
u16 new_direction, u16 new_force)
|
|
|
|
{
|
|
|
|
if (!force)
|
|
|
|
return new_direction;
|
|
|
|
if (!new_force)
|
|
|
|
return direction;
|
|
|
|
return (((u32)(direction >> 1) * force +
|
|
|
|
(new_direction >> 1) * new_force) /
|
|
|
|
(force + new_force)) << 1;
|
|
|
|
}
|
|
|
|
|
2015-02-04 09:07:30 +00:00
|
|
|
#define FRAC_N 8
|
|
|
|
static inline s16 fixp_new16(s16 a)
|
|
|
|
{
|
|
|
|
return ((s32)a) >> (16 - FRAC_N);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline s16 fixp_mult(s16 a, s16 b)
|
|
|
|
{
|
|
|
|
a = ((s32)a * 0x100) / 0x7fff;
|
|
|
|
return ((s32)(a * b)) >> FRAC_N;
|
|
|
|
}
|
|
|
|
|
2006-07-19 05:40:30 +00:00
|
|
|
/*
|
|
|
|
* Combine two effects and apply gain.
|
|
|
|
*/
|
|
|
|
static void ml_combine_effects(struct ff_effect *effect,
|
|
|
|
struct ml_effect_state *state,
|
2009-12-25 05:44:19 +00:00
|
|
|
int gain)
|
2006-07-19 05:40:30 +00:00
|
|
|
{
|
|
|
|
struct ff_effect *new = state->effect;
|
|
|
|
unsigned int strong, weak, i;
|
|
|
|
int x, y;
|
2015-02-04 09:07:30 +00:00
|
|
|
s16 level;
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
switch (new->type) {
|
|
|
|
case FF_CONSTANT:
|
|
|
|
i = new->direction * 360 / 0xffff;
|
|
|
|
level = fixp_new16(apply_envelope(state,
|
|
|
|
new->u.constant.level,
|
|
|
|
&new->u.constant.envelope));
|
2015-02-04 09:07:30 +00:00
|
|
|
x = fixp_mult(fixp_sin16(i), level) * gain / 0xffff;
|
|
|
|
y = fixp_mult(-fixp_cos16(i), level) * gain / 0xffff;
|
2006-07-19 05:40:30 +00:00
|
|
|
/*
|
|
|
|
* here we abuse ff_ramp to hold x and y of constant force
|
|
|
|
* If in future any driver wants something else than x and y
|
|
|
|
* in s8, this should be changed to something more generic
|
|
|
|
*/
|
|
|
|
effect->u.ramp.start_level =
|
2008-05-05 15:50:59 +00:00
|
|
|
clamp_val(effect->u.ramp.start_level + x, -0x80, 0x7f);
|
2006-07-19 05:40:30 +00:00
|
|
|
effect->u.ramp.end_level =
|
2008-05-05 15:50:59 +00:00
|
|
|
clamp_val(effect->u.ramp.end_level + y, -0x80, 0x7f);
|
2006-07-19 05:40:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FF_RUMBLE:
|
2009-12-25 05:44:19 +00:00
|
|
|
strong = (u32)new->u.rumble.strong_magnitude * gain / 0xffff;
|
|
|
|
weak = (u32)new->u.rumble.weak_magnitude * gain / 0xffff;
|
2009-12-25 05:52:20 +00:00
|
|
|
|
|
|
|
if (effect->u.rumble.strong_magnitude + strong)
|
|
|
|
effect->direction = ml_calculate_direction(
|
|
|
|
effect->direction,
|
|
|
|
effect->u.rumble.strong_magnitude,
|
|
|
|
new->direction, strong);
|
|
|
|
else if (effect->u.rumble.weak_magnitude + weak)
|
|
|
|
effect->direction = ml_calculate_direction(
|
|
|
|
effect->direction,
|
|
|
|
effect->u.rumble.weak_magnitude,
|
|
|
|
new->direction, weak);
|
|
|
|
else
|
|
|
|
effect->direction = 0;
|
2006-07-19 05:40:30 +00:00
|
|
|
effect->u.rumble.strong_magnitude =
|
|
|
|
min(strong + effect->u.rumble.strong_magnitude,
|
|
|
|
0xffffU);
|
|
|
|
effect->u.rumble.weak_magnitude =
|
|
|
|
min(weak + effect->u.rumble.weak_magnitude, 0xffffU);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FF_PERIODIC:
|
|
|
|
i = apply_envelope(state, abs(new->u.periodic.magnitude),
|
|
|
|
&new->u.periodic.envelope);
|
|
|
|
|
|
|
|
/* here we also scale it 0x7fff => 0xffff */
|
|
|
|
i = i * gain / 0x7fff;
|
|
|
|
|
2009-12-25 05:52:20 +00:00
|
|
|
if (effect->u.rumble.strong_magnitude + i)
|
|
|
|
effect->direction = ml_calculate_direction(
|
|
|
|
effect->direction,
|
|
|
|
effect->u.rumble.strong_magnitude,
|
|
|
|
new->direction, i);
|
|
|
|
else
|
|
|
|
effect->direction = 0;
|
2006-07-19 05:40:30 +00:00
|
|
|
effect->u.rumble.strong_magnitude =
|
|
|
|
min(i + effect->u.rumble.strong_magnitude, 0xffffU);
|
|
|
|
effect->u.rumble.weak_magnitude =
|
|
|
|
min(i + effect->u.rumble.weak_magnitude, 0xffffU);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_err("invalid type in ml_combine_effects()\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Because memoryless devices have only one effect per effect type active
|
|
|
|
* at one time we have to combine multiple effects into one
|
|
|
|
*/
|
|
|
|
static int ml_get_combo_effect(struct ml_device *ml,
|
|
|
|
unsigned long *effect_handled,
|
|
|
|
struct ff_effect *combo_effect)
|
|
|
|
{
|
|
|
|
struct ff_effect *effect;
|
|
|
|
struct ml_effect_state *state;
|
|
|
|
int effect_type;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(combo_effect, 0, sizeof(struct ff_effect));
|
|
|
|
|
|
|
|
for (i = 0; i < FF_MEMLESS_EFFECTS; i++) {
|
|
|
|
if (__test_and_set_bit(i, effect_handled))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
state = &ml->states[i];
|
|
|
|
effect = state->effect;
|
|
|
|
|
|
|
|
if (!test_bit(FF_EFFECT_STARTED, &state->flags))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (time_before(jiffies, state->play_at))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* here we have started effects that are either
|
|
|
|
* currently playing (and may need be aborted)
|
|
|
|
* or need to start playing.
|
|
|
|
*/
|
|
|
|
effect_type = get_compatible_type(ml->dev->ff, effect->type);
|
|
|
|
if (combo_effect->type != effect_type) {
|
|
|
|
if (combo_effect->type != 0) {
|
|
|
|
__clear_bit(i, effect_handled);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
combo_effect->type = effect_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (__test_and_clear_bit(FF_EFFECT_ABORTING, &state->flags)) {
|
|
|
|
__clear_bit(FF_EFFECT_PLAYING, &state->flags);
|
|
|
|
__clear_bit(FF_EFFECT_STARTED, &state->flags);
|
|
|
|
} else if (effect->replay.length &&
|
|
|
|
time_after_eq(jiffies, state->stop_at)) {
|
|
|
|
|
|
|
|
__clear_bit(FF_EFFECT_PLAYING, &state->flags);
|
|
|
|
|
|
|
|
if (--state->count <= 0) {
|
|
|
|
__clear_bit(FF_EFFECT_STARTED, &state->flags);
|
|
|
|
} else {
|
|
|
|
state->play_at = jiffies +
|
|
|
|
msecs_to_jiffies(effect->replay.delay);
|
|
|
|
state->stop_at = state->play_at +
|
|
|
|
msecs_to_jiffies(effect->replay.length);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
__set_bit(FF_EFFECT_PLAYING, &state->flags);
|
|
|
|
state->adj_at = jiffies;
|
|
|
|
ml_combine_effects(combo_effect, state, ml->gain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return combo_effect->type != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ml_play_effects(struct ml_device *ml)
|
|
|
|
{
|
|
|
|
struct ff_effect effect;
|
|
|
|
DECLARE_BITMAP(handled_bm, FF_MEMLESS_EFFECTS);
|
|
|
|
|
|
|
|
memset(handled_bm, 0, sizeof(handled_bm));
|
|
|
|
|
|
|
|
while (ml_get_combo_effect(ml, handled_bm, &effect))
|
|
|
|
ml->play_effect(ml->dev, ml->private, &effect);
|
|
|
|
|
|
|
|
ml_schedule_timer(ml);
|
|
|
|
}
|
|
|
|
|
2017-10-20 00:22:46 +00:00
|
|
|
static void ml_effect_timer(struct timer_list *t)
|
2006-07-19 05:40:30 +00:00
|
|
|
{
|
2017-10-20 00:22:46 +00:00
|
|
|
struct ml_device *ml = from_timer(ml, t, timer);
|
|
|
|
struct input_dev *dev = ml->dev;
|
2009-11-07 05:39:07 +00:00
|
|
|
unsigned long flags;
|
2006-07-19 05:40:30 +00:00
|
|
|
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("timer: updating effects\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
|
2009-11-07 05:39:07 +00:00
|
|
|
spin_lock_irqsave(&dev->event_lock, flags);
|
2006-07-19 05:40:30 +00:00
|
|
|
ml_play_effects(ml);
|
2009-11-07 05:39:07 +00:00
|
|
|
spin_unlock_irqrestore(&dev->event_lock, flags);
|
2006-07-19 05:40:30 +00:00
|
|
|
}
|
|
|
|
|
2009-11-07 05:39:07 +00:00
|
|
|
/*
|
|
|
|
* Sets requested gain for FF effects. Called with dev->event_lock held.
|
|
|
|
*/
|
2006-07-19 05:40:30 +00:00
|
|
|
static void ml_ff_set_gain(struct input_dev *dev, u16 gain)
|
|
|
|
{
|
|
|
|
struct ml_device *ml = dev->ff->private;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ml->gain = gain;
|
|
|
|
|
|
|
|
for (i = 0; i < FF_MEMLESS_EFFECTS; i++)
|
|
|
|
__clear_bit(FF_EFFECT_PLAYING, &ml->states[i].flags);
|
|
|
|
|
|
|
|
ml_play_effects(ml);
|
|
|
|
}
|
|
|
|
|
2009-11-07 05:39:07 +00:00
|
|
|
/*
|
|
|
|
* Start/stop specified FF effect. Called with dev->event_lock held.
|
|
|
|
*/
|
2006-07-19 05:40:30 +00:00
|
|
|
static int ml_ff_playback(struct input_dev *dev, int effect_id, int value)
|
|
|
|
{
|
|
|
|
struct ml_device *ml = dev->ff->private;
|
|
|
|
struct ml_effect_state *state = &ml->states[effect_id];
|
|
|
|
|
|
|
|
if (value > 0) {
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("initiated play\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
__set_bit(FF_EFFECT_STARTED, &state->flags);
|
|
|
|
state->count = value;
|
|
|
|
state->play_at = jiffies +
|
|
|
|
msecs_to_jiffies(state->effect->replay.delay);
|
|
|
|
state->stop_at = state->play_at +
|
|
|
|
msecs_to_jiffies(state->effect->replay.length);
|
|
|
|
state->adj_at = state->play_at;
|
|
|
|
|
|
|
|
} else {
|
2010-11-30 07:33:07 +00:00
|
|
|
pr_debug("initiated stop\n");
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
if (test_bit(FF_EFFECT_PLAYING, &state->flags))
|
|
|
|
__set_bit(FF_EFFECT_ABORTING, &state->flags);
|
|
|
|
else
|
|
|
|
__clear_bit(FF_EFFECT_STARTED, &state->flags);
|
|
|
|
}
|
|
|
|
|
2009-12-25 05:52:19 +00:00
|
|
|
ml_play_effects(ml);
|
|
|
|
|
2006-07-19 05:40:30 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ml_ff_upload(struct input_dev *dev,
|
|
|
|
struct ff_effect *effect, struct ff_effect *old)
|
|
|
|
{
|
|
|
|
struct ml_device *ml = dev->ff->private;
|
|
|
|
struct ml_effect_state *state = &ml->states[effect->id];
|
|
|
|
|
2009-11-07 05:39:07 +00:00
|
|
|
spin_lock_irq(&dev->event_lock);
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
if (test_bit(FF_EFFECT_STARTED, &state->flags)) {
|
|
|
|
__clear_bit(FF_EFFECT_PLAYING, &state->flags);
|
|
|
|
state->play_at = jiffies +
|
|
|
|
msecs_to_jiffies(state->effect->replay.delay);
|
|
|
|
state->stop_at = state->play_at +
|
|
|
|
msecs_to_jiffies(state->effect->replay.length);
|
|
|
|
state->adj_at = state->play_at;
|
|
|
|
ml_schedule_timer(ml);
|
|
|
|
}
|
|
|
|
|
2009-11-07 05:39:07 +00:00
|
|
|
spin_unlock_irq(&dev->event_lock);
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ml_ff_destroy(struct ff_device *ff)
|
|
|
|
{
|
|
|
|
struct ml_device *ml = ff->private;
|
|
|
|
|
2019-11-15 19:35:05 +00:00
|
|
|
/*
|
|
|
|
* Even though we stop all playing effects when tearing down
|
|
|
|
* an input device (via input_device_flush() that calls into
|
|
|
|
* input_ff_flush() that stops and erases all effects), we
|
|
|
|
* do not actually stop the timer, and therefore we should
|
|
|
|
* do it here.
|
|
|
|
*/
|
|
|
|
del_timer_sync(&ml->timer);
|
|
|
|
|
2006-07-19 05:40:30 +00:00
|
|
|
kfree(ml->private);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2006-11-24 05:43:09 +00:00
|
|
|
* input_ff_create_memless() - create memoryless force-feedback device
|
2006-07-19 05:40:30 +00:00
|
|
|
* @dev: input device supporting force-feedback
|
|
|
|
* @data: driver-specific data to be passed into @play_effect
|
|
|
|
* @play_effect: driver-specific method for playing FF effect
|
|
|
|
*/
|
|
|
|
int input_ff_create_memless(struct input_dev *dev, void *data,
|
|
|
|
int (*play_effect)(struct input_dev *, void *, struct ff_effect *))
|
|
|
|
{
|
|
|
|
struct ml_device *ml;
|
|
|
|
struct ff_device *ff;
|
|
|
|
int error;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
ml = kzalloc(sizeof(struct ml_device), GFP_KERNEL);
|
|
|
|
if (!ml)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
ml->dev = dev;
|
|
|
|
ml->private = data;
|
|
|
|
ml->play_effect = play_effect;
|
|
|
|
ml->gain = 0xffff;
|
2017-10-20 00:22:46 +00:00
|
|
|
timer_setup(&ml->timer, ml_effect_timer, 0);
|
2006-07-19 05:40:30 +00:00
|
|
|
|
|
|
|
set_bit(FF_GAIN, dev->ffbit);
|
|
|
|
|
|
|
|
error = input_ff_create(dev, FF_MEMLESS_EFFECTS);
|
|
|
|
if (error) {
|
|
|
|
kfree(ml);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
ff = dev->ff;
|
|
|
|
ff->private = ml;
|
|
|
|
ff->upload = ml_ff_upload;
|
|
|
|
ff->playback = ml_ff_playback;
|
|
|
|
ff->set_gain = ml_ff_set_gain;
|
|
|
|
ff->destroy = ml_ff_destroy;
|
|
|
|
|
|
|
|
/* we can emulate periodic effects with RUMBLE */
|
|
|
|
if (test_bit(FF_RUMBLE, ff->ffbit)) {
|
|
|
|
set_bit(FF_PERIODIC, dev->ffbit);
|
|
|
|
set_bit(FF_SINE, dev->ffbit);
|
|
|
|
set_bit(FF_TRIANGLE, dev->ffbit);
|
|
|
|
set_bit(FF_SQUARE, dev->ffbit);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < FF_MEMLESS_EFFECTS; i++)
|
|
|
|
ml->states[i].effect = &ff->effects[i];
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(input_ff_create_memless);
|