diff options
Diffstat (limited to 'drivers/input/ff-memless.c')
-rw-r--r-- | drivers/input/ff-memless.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c index b483b2995fa9..f967008f332e 100644 --- a/drivers/input/ff-memless.c +++ b/drivers/input/ff-memless.c | |||
@@ -221,11 +221,27 @@ static int get_compatible_type(struct ff_device *ff, int effect_type) | |||
221 | } | 221 | } |
222 | 222 | ||
223 | /* | 223 | /* |
224 | * Only left/right direction should be used (under/over 0x8000) for | ||
225 | * forward/reverse motor direction (to keep calculation fast & simple). | ||
226 | */ | ||
227 | static u16 ml_calculate_direction(u16 direction, u16 force, | ||
228 | u16 new_direction, u16 new_force) | ||
229 | { | ||
230 | if (!force) | ||
231 | return new_direction; | ||
232 | if (!new_force) | ||
233 | return direction; | ||
234 | return (((u32)(direction >> 1) * force + | ||
235 | (new_direction >> 1) * new_force) / | ||
236 | (force + new_force)) << 1; | ||
237 | } | ||
238 | |||
239 | /* | ||
224 | * Combine two effects and apply gain. | 240 | * Combine two effects and apply gain. |
225 | */ | 241 | */ |
226 | static void ml_combine_effects(struct ff_effect *effect, | 242 | static void ml_combine_effects(struct ff_effect *effect, |
227 | struct ml_effect_state *state, | 243 | struct ml_effect_state *state, |
228 | unsigned int gain) | 244 | int gain) |
229 | { | 245 | { |
230 | struct ff_effect *new = state->effect; | 246 | struct ff_effect *new = state->effect; |
231 | unsigned int strong, weak, i; | 247 | unsigned int strong, weak, i; |
@@ -252,8 +268,21 @@ static void ml_combine_effects(struct ff_effect *effect, | |||
252 | break; | 268 | break; |
253 | 269 | ||
254 | case FF_RUMBLE: | 270 | case FF_RUMBLE: |
255 | strong = new->u.rumble.strong_magnitude * gain / 0xffff; | 271 | strong = (u32)new->u.rumble.strong_magnitude * gain / 0xffff; |
256 | weak = new->u.rumble.weak_magnitude * gain / 0xffff; | 272 | weak = (u32)new->u.rumble.weak_magnitude * gain / 0xffff; |
273 | |||
274 | if (effect->u.rumble.strong_magnitude + strong) | ||
275 | effect->direction = ml_calculate_direction( | ||
276 | effect->direction, | ||
277 | effect->u.rumble.strong_magnitude, | ||
278 | new->direction, strong); | ||
279 | else if (effect->u.rumble.weak_magnitude + weak) | ||
280 | effect->direction = ml_calculate_direction( | ||
281 | effect->direction, | ||
282 | effect->u.rumble.weak_magnitude, | ||
283 | new->direction, weak); | ||
284 | else | ||
285 | effect->direction = 0; | ||
257 | effect->u.rumble.strong_magnitude = | 286 | effect->u.rumble.strong_magnitude = |
258 | min(strong + effect->u.rumble.strong_magnitude, | 287 | min(strong + effect->u.rumble.strong_magnitude, |
259 | 0xffffU); | 288 | 0xffffU); |
@@ -268,6 +297,13 @@ static void ml_combine_effects(struct ff_effect *effect, | |||
268 | /* here we also scale it 0x7fff => 0xffff */ | 297 | /* here we also scale it 0x7fff => 0xffff */ |
269 | i = i * gain / 0x7fff; | 298 | i = i * gain / 0x7fff; |
270 | 299 | ||
300 | if (effect->u.rumble.strong_magnitude + i) | ||
301 | effect->direction = ml_calculate_direction( | ||
302 | effect->direction, | ||
303 | effect->u.rumble.strong_magnitude, | ||
304 | new->direction, i); | ||
305 | else | ||
306 | effect->direction = 0; | ||
271 | effect->u.rumble.strong_magnitude = | 307 | effect->u.rumble.strong_magnitude = |
272 | min(i + effect->u.rumble.strong_magnitude, 0xffffU); | 308 | min(i + effect->u.rumble.strong_magnitude, 0xffffU); |
273 | effect->u.rumble.weak_magnitude = | 309 | effect->u.rumble.weak_magnitude = |
@@ -411,8 +447,6 @@ static int ml_ff_playback(struct input_dev *dev, int effect_id, int value) | |||
411 | msecs_to_jiffies(state->effect->replay.length); | 447 | msecs_to_jiffies(state->effect->replay.length); |
412 | state->adj_at = state->play_at; | 448 | state->adj_at = state->play_at; |
413 | 449 | ||
414 | ml_schedule_timer(ml); | ||
415 | |||
416 | } else { | 450 | } else { |
417 | debug("initiated stop"); | 451 | debug("initiated stop"); |
418 | 452 | ||
@@ -420,10 +454,10 @@ static int ml_ff_playback(struct input_dev *dev, int effect_id, int value) | |||
420 | __set_bit(FF_EFFECT_ABORTING, &state->flags); | 454 | __set_bit(FF_EFFECT_ABORTING, &state->flags); |
421 | else | 455 | else |
422 | __clear_bit(FF_EFFECT_STARTED, &state->flags); | 456 | __clear_bit(FF_EFFECT_STARTED, &state->flags); |
423 | |||
424 | ml_play_effects(ml); | ||
425 | } | 457 | } |
426 | 458 | ||
459 | ml_play_effects(ml); | ||
460 | |||
427 | return 0; | 461 | return 0; |
428 | } | 462 | } |
429 | 463 | ||