From f604339def269c3a8a82dd51a431c831b6945653 Mon Sep 17 00:00:00 2001 From: kimi Date: Wed, 24 Mar 2021 17:16:17 -0400 Subject: Code styling, follows Linux kernel standards --- hid-tmt300rs.c | 563 ++++++++++++++++++++++++++++++--------------------------- hid-tmt300rs.h | 185 +++++++++---------- 2 files changed, 391 insertions(+), 357 deletions(-) diff --git a/hid-tmt300rs.c b/hid-tmt300rs.c index 6abe149..639da08 100644 --- a/hid-tmt300rs.c +++ b/hid-tmt300rs.c @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: GPL-2.0 #include "hid-tmt300rs.h" static int timer_msecs = DEFAULT_TIMER_PERIOD; @@ -17,19 +18,20 @@ module_param(friction_level, int, 0); MODULE_PARM_DESC(friction_level, "Level of friction force (0-100), as per Oversteer standards"); -static struct t300rs_device_entry *t300rs_get_device(struct hid_device *hdev){ +static struct t300rs_device_entry *t300rs_get_device(struct hid_device *hdev) +{ struct t300rs_data *drv_data; struct t300rs_device_entry *t300rs; spin_lock_irqsave(&lock, lock_flags); drv_data = hid_get_drvdata(hdev); - if(!drv_data){ + if (!drv_data) { hid_err(hdev, "private data not found\n"); return NULL; } t300rs = drv_data->device_props; - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "device properties not found\n"); return NULL; } @@ -37,20 +39,20 @@ static struct t300rs_device_entry *t300rs_get_device(struct hid_device *hdev){ return t300rs; } -static int t300rs_send_int(struct input_dev *dev, u8 *send_buffer, int *trans){ +static int t300rs_send_int(struct input_dev *dev, u8 *send_buffer, int *trans) +{ struct hid_device *hdev = input_get_drvdata(dev); struct t300rs_device_entry *t300rs; int i; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return -1; } - for(i = 0; i < T300RS_BUFFER_LENGTH; ++i){ + for (i = 0; i < T300RS_BUFFER_LENGTH; ++i) t300rs->ff_field->value[i] = send_buffer[i]; - } hid_hw_request(t300rs->hdev, t300rs->report, HID_REQ_SET_REPORT); @@ -59,7 +61,9 @@ static int t300rs_send_int(struct input_dev *dev, u8 *send_buffer, int *trans){ return 0; } -static int t300rs_play_effect(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_play_effect(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; int ret, trans; @@ -69,15 +73,15 @@ static int t300rs_play_effect(struct t300rs_device_entry *t300rs, struct t300rs_ send_buffer[3] = 0x01; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed starting effect play\n"); - } - return ret; } -static int t300rs_stop_effect(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_stop_effect(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; int ret, trans; @@ -86,21 +90,21 @@ static int t300rs_stop_effect(struct t300rs_device_entry *t300rs, struct t300rs_ send_buffer[2] = 0x89; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed stopping effect play\n"); - } - return ret; } -static void t300rs_fill_envelope(u8 *send_buffer, int i, s16 level, u16 duration, struct ff_envelope *envelope){ +static void t300rs_fill_envelope(u8 *send_buffer, int i, s16 level, + u16 duration, struct ff_envelope *envelope) +{ u16 attack_length = (duration * envelope->attack_length) / 0x7fff; u16 attack_level = (level * envelope->attack_level) / 0x7fff; u16 fade_length = (duration * envelope->fade_length) / 0x7fff; u16 fade_level = (level * envelope->fade_level) / 0x7fff; - send_buffer[i ] = attack_length & 0xff; + send_buffer[i + 0] = attack_length & 0xff; send_buffer[i + 1] = attack_length >> 8; send_buffer[i + 2] = attack_level & 0xff; send_buffer[i + 3] = attack_level >> 8; @@ -118,13 +122,13 @@ static int t300rs_modify_envelope(struct t300rs_device_entry *t300rs, u8 id, struct ff_envelope envelope, struct ff_envelope envelope_old - ){ + ) +{ u16 attack_length, attack_level, fade_length, fade_level; int ret = 0, trans; - if(duration == 0){ + if (duration == 0) duration = 0xffff; - } attack_length = (duration * envelope.attack_length) / 0x7fff; attack_level = (level * envelope.attack_level) / 0x7fff; @@ -135,53 +139,53 @@ static int t300rs_modify_envelope(struct t300rs_device_entry *t300rs, send_buffer[1] = id + 1; send_buffer[2] = 0x31; - if(envelope.attack_length != envelope_old.attack_length){ + if (envelope.attack_length != envelope_old.attack_length) { send_buffer[3] = 0x81; send_buffer[4] = attack_length & 0xff; send_buffer[5] = attack_length >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying effect envelope\n"); goto error; } } - if(envelope.attack_level != envelope_old.attack_level){ + if (envelope.attack_level != envelope_old.attack_level) { send_buffer[3] = 0x82; send_buffer[4] = attack_level & 0xff; send_buffer[5] = attack_level >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying effect envelope\n"); goto error; } } - if(envelope.fade_length != envelope_old.fade_length){ + if (envelope.fade_length != envelope_old.fade_length) { send_buffer[3] = 0x84; send_buffer[4] = fade_length & 0xff; send_buffer[5] = fade_length >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying effect envelope\n"); goto error; } } - if(envelope.fade_level != envelope_old.fade_level){ + if (envelope.fade_level != envelope_old.fade_level) { send_buffer[3] = 0x88; send_buffer[4] = fade_level & 0xff; send_buffer[5] = fade_level >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying effect envelope\n"); goto error; } @@ -191,19 +195,20 @@ error: return ret; } -static int t300rs_modify_duration(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state, u8 *send_buffer){ +static int t300rs_modify_duration(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state, u8 *send_buffer) +{ struct ff_effect effect = state->effect; struct ff_effect old = state->old; u16 duration; int ret = 0, trans; - if(effect.replay.length == 0){ + if (effect.replay.length == 0) duration = 0xffff; - } else { + else duration = effect.replay.length; - } - if(effect.replay.length != old.replay.length){ + if (effect.replay.length != old.replay.length) { send_buffer[1] = effect.id + 1; send_buffer[2] = 0x49; @@ -213,7 +218,7 @@ static int t300rs_modify_duration(struct t300rs_device_entry *t300rs, struct t30 send_buffer[6] = duration >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying duration\n"); goto error; } @@ -222,7 +227,9 @@ error: return ret; } -static int t300rs_modify_constant(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state, u8 *send_buffer){ +static int t300rs_modify_constant(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state, u8 *send_buffer) +{ struct ff_effect effect = state->effect; struct ff_effect old = state->old; struct ff_constant_effect constant = effect.u.constant; @@ -232,7 +239,7 @@ static int t300rs_modify_constant(struct t300rs_device_entry *t300rs, struct t30 level = (constant.level * fixp_sin16(effect.direction * 360 / 0x10000)) / 0x7fff; - if(constant.level != constant_old.level){ + if (constant.level != constant_old.level) { send_buffer[1] = effect.id + 1; send_buffer[2] = 0x0a; @@ -241,7 +248,7 @@ static int t300rs_modify_constant(struct t300rs_device_entry *t300rs, struct t30 send_buffer[4] = level >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying constant effect\n"); goto error; } @@ -257,13 +264,13 @@ static int t300rs_modify_constant(struct t300rs_device_entry *t300rs, struct t30 constant.envelope, constant_old.envelope ); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying constant envelope\n"); goto error; } ret = t300rs_modify_duration(t300rs, state, send_buffer); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying constant duration\n"); goto error; } @@ -273,7 +280,9 @@ error: return ret; } -static int t300rs_modify_ramp(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state, u8 *send_buffer){ +static int t300rs_modify_ramp(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state, u8 *send_buffer) +{ struct ff_effect effect = state->effect; struct ff_effect old = state->old; struct ff_ramp_effect ramp = effect.u.ramp; @@ -292,7 +301,7 @@ static int t300rs_modify_ramp(struct t300rs_device_entry *t300rs, struct t300rs_ level = (top * fixp_sin16(effect.direction * 360 / 0x10000)) / 0x7fff; - if(ramp.start_level != ramp_old.start_level || ramp.end_level != ramp_old.end_level){ + if (ramp.start_level != ramp_old.start_level || ramp.end_level != ramp_old.end_level) { send_buffer[1] = effect.id + 1; send_buffer[2] = 0x0e; @@ -305,7 +314,7 @@ static int t300rs_modify_ramp(struct t300rs_device_entry *t300rs, struct t300rs_ send_buffer[7] = level >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying ramp effect\n"); goto error; } @@ -322,13 +331,13 @@ static int t300rs_modify_ramp(struct t300rs_device_entry *t300rs, struct t300rs_ ramp_old.envelope ); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying ramp envelope\n"); goto error; } ret = t300rs_modify_duration(t300rs, state, send_buffer); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying ramp duration\n"); goto error; } @@ -337,7 +346,9 @@ error: return ret; } -static int t300rs_modify_damper(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state, u8 *send_buffer){ +static int t300rs_modify_damper(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state, u8 *send_buffer) +{ struct ff_effect effect = state->effect; struct ff_effect old = state->old; struct ff_condition_effect damper = effect.u.condition[0]; @@ -345,13 +356,13 @@ static int t300rs_modify_damper(struct t300rs_device_entry *t300rs, struct t300r int ret, trans, input_level; input_level = damper_level; - if(state->effect.type == FF_FRICTION) + if (state->effect.type == FF_FRICTION) input_level = friction_level; - if(state->effect.type == FF_SPRING) + if (state->effect.type == FF_SPRING) input_level = spring_level; - if(damper.right_coeff != damper_old.right_coeff){ + if (damper.right_coeff != damper_old.right_coeff) { s16 coeff = damper.right_coeff * input_level / 100; @@ -363,14 +374,14 @@ static int t300rs_modify_damper(struct t300rs_device_entry *t300rs, struct t300r send_buffer[5] = coeff >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying damper rc\n"); goto error; } } - if(damper.left_coeff != damper_old.left_coeff){ + if (damper.left_coeff != damper_old.left_coeff) { s16 coeff = damper.left_coeff * input_level / 100; @@ -382,14 +393,15 @@ static int t300rs_modify_damper(struct t300rs_device_entry *t300rs, struct t300r send_buffer[5] = coeff >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying damper lc\n"); + goto error; } } - if((damper.deadband != damper_old.deadband) || - (damper.center != damper_old.center)){ + if ((damper.deadband != damper_old.deadband) || + (damper.center != damper_old.center)) { u16 deadband_right = 0xfffe - damper.deadband - damper.center; u16 deadband_left = 0xfffe - damper.deadband + damper.center; @@ -405,14 +417,15 @@ static int t300rs_modify_damper(struct t300rs_device_entry *t300rs, struct t300r send_buffer[7] = deadband_left >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying damper deadband\n"); + goto error; } } ret = t300rs_modify_duration(t300rs, state, send_buffer); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying damper duration\n"); goto error; } @@ -423,7 +436,9 @@ error: } -static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state, u8 *send_buffer){ +static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state, u8 *send_buffer) +{ struct ff_effect effect = state->effect; struct ff_effect old = state->old; struct ff_periodic_effect periodic = effect.u.periodic; @@ -434,7 +449,7 @@ static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t30 level = (periodic.magnitude * fixp_sin16(effect.direction * 360 / 0x10000)) / 0x7fff; - if(periodic.magnitude != periodic_old.magnitude){ + if (periodic.magnitude != periodic_old.magnitude) { send_buffer[1] = effect.id + 1; send_buffer[2] = 0x0e; @@ -444,14 +459,14 @@ static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t30 send_buffer[5] = level >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying periodic magnitude\n"); goto error; } } - if(periodic.offset != periodic_old.offset){ + if (periodic.offset != periodic_old.offset) { s16 offset = periodic.offset; @@ -463,13 +478,14 @@ static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t30 send_buffer[5] = offset >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying periodic offset\n"); + goto error; } } - if(periodic.phase != periodic_old.phase){ + if (periodic.phase != periodic_old.phase) { s16 phase = periodic.phase; @@ -481,13 +497,14 @@ static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t30 send_buffer[5] = phase >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying periodic phase\n"); + goto error; } } - if(periodic.period != periodic_old.period){ + if (periodic.period != periodic_old.period) { s16 period = periodic.period; @@ -499,8 +516,9 @@ static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t30 send_buffer[5] = period >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying periodic period\n"); + goto error; } } @@ -513,13 +531,13 @@ static int t300rs_modify_periodic(struct t300rs_device_entry *t300rs, struct t30 effect.id, periodic.envelope, periodic_old.envelope); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying periodic envelope\n"); goto error; } ret = t300rs_modify_duration(t300rs, state, send_buffer); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed modifying periodic duration\n"); goto error; } @@ -530,7 +548,9 @@ error: } -static int t300rs_upload_constant(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_upload_constant(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; struct ff_effect effect = state->effect; struct ff_constant_effect constant = state->effect.u.constant; @@ -542,20 +562,20 @@ static int t300rs_upload_constant(struct t300rs_device_entry *t300rs, struct t30 /* some games, such as DiRT Rally 2 have a weird feeling to them, sort of * like the wheel pulls just a bit to the right or left and then it just * stops. I wouldn't be surprised if it's got something to do with the - * constant envelope, but right now I don't know. */ + * constant envelope, but right now I don't know. + */ - if(test_bit(FF_EFFECT_PLAYING, &state->flags) && - test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)){ + if (test_bit(FF_EFFECT_PLAYING, &state->flags) && + test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)) { __clear_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags); return t300rs_modify_constant(t300rs, state, send_buffer); } level = (constant.level * fixp_sin16(effect.direction * 360 / 0x10000)) / 0x7fff; - if(effect.replay.length == 0){ + if (effect.replay.length == 0) duration = 0xffff; - } else { + else duration = effect.replay.length; - } offset = effect.replay.delay; @@ -581,15 +601,15 @@ static int t300rs_upload_constant(struct t300rs_device_entry *t300rs, struct t30 send_buffer[23] = 0xff; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed uploading constant effect\n"); - } - return ret; } -static int t300rs_upload_ramp(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_upload_ramp(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; struct ff_effect effect = state->effect; struct ff_ramp_effect ramp = state->effect.u.ramp; @@ -597,17 +617,18 @@ static int t300rs_upload_ramp(struct t300rs_device_entry *t300rs, struct t300rs_ u16 difference, offset, top, bottom, duration; s16 level; - if(test_bit(FF_EFFECT_PLAYING, &state->flags) && - test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)){ + if (test_bit(FF_EFFECT_PLAYING, &state->flags) && + test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)) { + __clear_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags); + return t300rs_modify_ramp(t300rs, state, send_buffer); } - if(effect.replay.length == 0){ + if (effect.replay.length == 0) duration = 0xffff; - } else { + else duration = effect.replay.length; - } top = ramp.end_level > ramp.start_level ? ramp.end_level : ramp.start_level; bottom = ramp.end_level > ramp.start_level ? ramp.start_level : ramp.end_level; @@ -624,7 +645,7 @@ static int t300rs_upload_ramp(struct t300rs_device_entry *t300rs, struct t300rs_ send_buffer[3] = difference & 0xff; send_buffer[4] = difference >> 8; - send_buffer[5] = level & 0xff; + send_buffer[5] = level & 0xff; send_buffer[6] = level >> 8; send_buffer[9] = duration & 0xff; @@ -648,15 +669,15 @@ static int t300rs_upload_ramp(struct t300rs_device_entry *t300rs, struct t300rs_ send_buffer[32] = 0xff; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed uploading ramp"); - } - return ret; } -static int t300rs_upload_spring(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_upload_spring(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; struct ff_effect effect = state->effect; /* we only care about the first axis */ @@ -664,18 +685,18 @@ static int t300rs_upload_spring(struct t300rs_device_entry *t300rs, struct t300r int ret, trans; u16 duration, right_coeff, left_coeff, deadband_right, deadband_left, offset; - if(test_bit(FF_EFFECT_PLAYING, &state->flags) && - test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)){ + if (test_bit(FF_EFFECT_PLAYING, &state->flags) && + test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)) { + __clear_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags); + return t300rs_modify_damper(t300rs, state, send_buffer); } - if(effect.replay.length == 0){ + if (effect.replay.length == 0) duration = 0xffff; - } else { + else duration = effect.replay.length; - } - send_buffer[1] = effect.id + 1; send_buffer[2] = 0x64; @@ -713,15 +734,15 @@ static int t300rs_upload_spring(struct t300rs_device_entry *t300rs, struct t300r send_buffer[37] = 0xff; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed uploading spring\n"); - } - return ret; } -static int t300rs_upload_damper(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_upload_damper(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; struct ff_effect effect = state->effect; /* we only care about the first axis */ @@ -729,20 +750,21 @@ static int t300rs_upload_damper(struct t300rs_device_entry *t300rs, struct t300r int ret, trans, input_level; u16 duration, right_coeff, left_coeff, deadband_right, deadband_left, offset; - if(test_bit(FF_EFFECT_PLAYING, &state->flags) && - test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)){ + if (test_bit(FF_EFFECT_PLAYING, &state->flags) && + test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)) { + __clear_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags); + return t300rs_modify_damper(t300rs, state, send_buffer); } - if(effect.replay.length == 0){ + if (effect.replay.length == 0) duration = 0xffff; - } else { + else duration = effect.replay.length; - } input_level = damper_level; - if(state->effect.type == FF_FRICTION) + if (state->effect.type == FF_FRICTION) input_level = friction_level; @@ -782,15 +804,15 @@ static int t300rs_upload_damper(struct t300rs_device_entry *t300rs, struct t300r send_buffer[37] = 0xff; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed uploading spring\n"); - } - return ret; } -static int t300rs_upload_periodic(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ +static int t300rs_upload_periodic(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ u8 *send_buffer = t300rs->send_buffer; struct ff_effect effect = state->effect; struct ff_periodic_effect periodic = state->effect.u.periodic; @@ -798,17 +820,18 @@ static int t300rs_upload_periodic(struct t300rs_device_entry *t300rs, struct t30 u16 duration, magnitude, phase, period, offset; s16 periodic_offset; - if(test_bit(FF_EFFECT_PLAYING, &state->flags) && - test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)){ + if (test_bit(FF_EFFECT_PLAYING, &state->flags) && + test_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags)) { + __clear_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags); + return t300rs_modify_periodic(t300rs, state, send_buffer); } - if(effect.replay.length == 0){ + if (effect.replay.length == 0) duration = 0xffff; - } else { + else duration = effect.replay.length; - } magnitude = (periodic.magnitude * fixp_sin16(effect.direction * 360 / 0x10000)) / 0x7fff; @@ -851,136 +874,137 @@ static int t300rs_upload_periodic(struct t300rs_device_entry *t300rs, struct t30 send_buffer[31] = 0xff; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(t300rs->hdev, "failed uploading periodic effect"); - } - return ret; } -static int t300rs_upload_effect(struct t300rs_device_entry *t300rs, struct t300rs_effect_state *state){ - switch(state->effect.type){ - case FF_CONSTANT: - return t300rs_upload_constant(t300rs, state); - case FF_RAMP: - return t300rs_upload_ramp(t300rs, state); - case FF_SPRING: - return t300rs_upload_spring(t300rs, state); - case FF_DAMPER: - case FF_FRICTION: - case FF_INERTIA: - return t300rs_upload_damper(t300rs, state); - case FF_PERIODIC: - return t300rs_upload_periodic(t300rs, state); - default: - hid_err(t300rs->hdev, "invalid effect type: %x", state->effect.type); - return -1; +static int t300rs_upload_effect(struct t300rs_device_entry *t300rs, + struct t300rs_effect_state *state) +{ + switch (state->effect.type) { + case FF_CONSTANT: + return t300rs_upload_constant(t300rs, state); + case FF_RAMP: + return t300rs_upload_ramp(t300rs, state); + case FF_SPRING: + return t300rs_upload_spring(t300rs, state); + case FF_DAMPER: + case FF_FRICTION: + case FF_INERTIA: + return t300rs_upload_damper(t300rs, state); + case FF_PERIODIC: + return t300rs_upload_periodic(t300rs, state); + default: + hid_err(t300rs->hdev, "invalid effect type: %x", state->effect.type); + return -1; } -} +} -static int t300rs_timer_helper(struct t300rs_device_entry *t300rs){ +static int t300rs_timer_helper(struct t300rs_device_entry *t300rs) +{ struct t300rs_effect_state *state; unsigned long jiffies_now = JIFFIES2MS(jiffies); int max_count = 0, effect_id, ret; - for(effect_id = 0; effect_id < T300RS_MAX_EFFECTS; ++effect_id){ + for (effect_id = 0; effect_id < T300RS_MAX_EFFECTS; ++effect_id) { state = &t300rs->states[effect_id]; - if(test_bit(FF_EFFECT_PLAYING, &state->flags) && state->effect.replay.length){ - if((jiffies_now - state->start_time) >= state->effect.replay.length){ + if (test_bit(FF_EFFECT_PLAYING, &state->flags) && state->effect.replay.length) { + if ((jiffies_now - state->start_time) >= state->effect.replay.length) { __clear_bit(FF_EFFECT_PLAYING, &state->flags); /* lazy bum fix? */ __clear_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags); - if(state->count){ + if (state->count) state->count--; - } - if(state->count){ + if (state->count) __set_bit(FF_EFFECT_QUEUE_START, &state->flags); - } } } - if(test_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags)){ + if (test_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags)) { __clear_bit(FF_EFFECT_QUEUE_UPLOAD, &state->flags); ret = t300rs_upload_effect(t300rs, state); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed uploading effects"); return ret; } } - if(test_bit(FF_EFFECT_QUEUE_START, &state->flags)){ + if (test_bit(FF_EFFECT_QUEUE_START, &state->flags)) { __clear_bit(FF_EFFECT_QUEUE_START, &state->flags); __set_bit(FF_EFFECT_PLAYING, &state->flags); ret = t300rs_play_effect(t300rs, state); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed starting effects\n"); return ret; } } - if(test_bit(FF_EFFECT_QUEUE_STOP, &state->flags)){ + if (test_bit(FF_EFFECT_QUEUE_STOP, &state->flags)) { __clear_bit(FF_EFFECT_QUEUE_STOP, &state->flags); __clear_bit(FF_EFFECT_PLAYING, &state->flags); ret = t300rs_stop_effect(t300rs, state); - if(ret){ + if (ret) { hid_err(t300rs->hdev, "failed stopping effect\n"); return ret; } } - if(state->count > max_count){ + if (state->count > max_count) max_count = state->count; - } } return max_count; } -static enum hrtimer_restart t300rs_timer(struct hrtimer *t){ +static enum hrtimer_restart t300rs_timer(struct hrtimer *t) +{ struct t300rs_device_entry *t300rs = container_of(t, struct t300rs_device_entry, hrtimer); int max_count; max_count = t300rs_timer_helper(t300rs); - if(max_count > 0){ + if (max_count > 0) { hrtimer_forward_now(&t300rs->hrtimer, ms_to_ktime(timer_msecs)); return HRTIMER_RESTART; } else { return HRTIMER_NORESTART; } -} +} -static int t300rs_upload(struct input_dev *dev, struct ff_effect *effect, struct ff_effect *old){ +static int t300rs_upload(struct input_dev *dev, + struct ff_effect *effect, struct ff_effect *old) +{ struct hid_device *hdev = input_get_drvdata(dev); struct t300rs_device_entry *t300rs; struct t300rs_effect_state *state; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return -1; } - if(effect->type == FF_PERIODIC && effect->u.periodic.period == 0){ + if (effect->type == FF_PERIODIC && effect->u.periodic.period == 0) return -EINVAL; - } state = &t300rs->states[effect->id]; spin_lock_irqsave(&t300rs->lock, t300rs->lock_flags); state->effect = *effect; - if(old){ + + if (old) { state->old = *old; __set_bit(FF_EFFECT_QUEUE_UPDATE, &state->flags); } else { @@ -993,56 +1017,61 @@ static int t300rs_upload(struct input_dev *dev, struct ff_effect *effect, struct return 0; } -static int t300rs_play(struct input_dev *dev, int effect_id, int value){ +static int t300rs_play(struct input_dev *dev, int effect_id, int value) +{ struct hid_device *hdev = input_get_drvdata(dev); struct t300rs_device_entry *t300rs; struct t300rs_effect_state *state; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return -1; } state = &t300rs->states[effect_id]; - if(&state->effect == 0) + if (&state->effect == 0) return 0; spin_lock_irqsave(&t300rs->lock, t300rs->lock_flags); - if(value > 0){ + if (value > 0) { state->count = value; state->start_time = JIFFIES2MS(jiffies); __set_bit(FF_EFFECT_QUEUE_START, &state->flags); - if(test_bit(FF_EFFECT_QUEUE_STOP, &state->flags)) + if (test_bit(FF_EFFECT_QUEUE_STOP, &state->flags)) __clear_bit(FF_EFFECT_QUEUE_STOP, &state->flags); } else { __set_bit(FF_EFFECT_QUEUE_STOP, &state->flags); } - if(!hrtimer_active(&t300rs->hrtimer)){ + if (!hrtimer_active(&t300rs->hrtimer)) hrtimer_start(&t300rs->hrtimer, ms_to_ktime(timer_msecs), HRTIMER_MODE_REL); - } spin_unlock_irqrestore(&t300rs->lock, t300rs->lock_flags); return 0; } -static ssize_t t300rs_spring_level_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count){ - unsigned value = simple_strtoul(buf, NULL, 10); +static ssize_t spring_level_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + unsigned int value; + + kstrtouint(buf, 10, &value); - if(value > 100) + if (value > 100) value = 100; spring_level = value; return count; } -static ssize_t t300rs_spring_level_show(struct device *dev, struct device_attribute *attr, char *buf){ +static ssize_t spring_level_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ size_t count; count = scnprintf(buf, PAGE_SIZE, "%u\n", spring_level); @@ -1050,13 +1079,16 @@ static ssize_t t300rs_spring_level_show(struct device *dev, struct device_attrib return count; } -static DEVICE_ATTR(spring_level, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, t300rs_spring_level_show, t300rs_spring_level_store); +static DEVICE_ATTR_RW(spring_level); -static ssize_t t300rs_damper_level_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count){ - unsigned value = simple_strtoul(buf, NULL, 10); +static ssize_t damper_level_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + unsigned int value; - if(value > 100) + kstrtouint(buf, 10, &value); + + if (value > 100) value = 100; damper_level = value; @@ -1064,7 +1096,9 @@ static ssize_t t300rs_damper_level_store(struct device *dev, struct device_attri return count; } -static ssize_t t300rs_damper_level_show(struct device *dev, struct device_attribute *attr, char *buf){ +static ssize_t damper_level_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ size_t count; count = scnprintf(buf, PAGE_SIZE, "%u\n", damper_level); @@ -1072,20 +1106,25 @@ static ssize_t t300rs_damper_level_show(struct device *dev, struct device_attrib return count; } -static DEVICE_ATTR(damper_level, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, t300rs_damper_level_show, t300rs_damper_level_store); +static DEVICE_ATTR_RW(damper_level); + +static ssize_t friction_level_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + unsigned int value; -static ssize_t t300rs_friction_level_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count){ - unsigned value = simple_strtoul(buf, NULL, 10); + kstrtouint(buf, 10, &value); - if(value > 100) + if (value > 100) value = 100; friction_level = value; return count; } -static ssize_t t300rs_friction_level_show(struct device *dev, struct device_attribute *attr, char *buf){ +static ssize_t friction_level_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ size_t count; count = scnprintf(buf, PAGE_SIZE, "%u\n", friction_level); @@ -1093,32 +1132,32 @@ static ssize_t t300rs_friction_level_show(struct device *dev, struct device_attr return count; } -static DEVICE_ATTR(friction_level, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, t300rs_friction_level_show, t300rs_friction_level_store); +static DEVICE_ATTR_RW(friction_level); -/* we should set a default range */ -static ssize_t t300rs_range_store(struct device *dev, struct device_attribute *attr, - const char *buf, size_t count){ +static ssize_t range_store(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ struct hid_device *hdev = to_hid_device(dev); struct t300rs_device_entry *t300rs; u8 *send_buffer; - u16 range = simple_strtoul(buf, NULL, 10); + unsigned int range; int ret, trans; + kstrtouint(buf, 10, &range); + t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return -1; } send_buffer = t300rs->send_buffer; - if(range < 40){ + if (range < 40) range = 40; - } - if(range > 1080){ + if (range > 1080) range = 1080; - } range *= 0x3c; @@ -1129,7 +1168,7 @@ static ssize_t t300rs_range_store(struct device *dev, struct device_attribute *a send_buffer[3] = range >> 8; ret = t300rs_send_int(t300rs->input_dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(hdev, "failed sending interrupts\n"); return -1; } @@ -1139,14 +1178,15 @@ static ssize_t t300rs_range_store(struct device *dev, struct device_attribute *a return count; } -static ssize_t t300rs_range_show(struct device *dev, struct device_attribute *attr, - char *buf){ +static ssize_t range_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ struct hid_device *hdev = to_hid_device(dev); struct t300rs_device_entry *t300rs; size_t count = 0; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return -1; } @@ -1155,30 +1195,31 @@ static ssize_t t300rs_range_show(struct device *dev, struct device_attribute *at return count; } -static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, t300rs_range_show, t300rs_range_store); +static DEVICE_ATTR_RW(range); -static void t300rs_set_autocenter(struct input_dev *dev, u16 value){ +static void t300rs_set_autocenter(struct input_dev *dev, u16 value) +{ struct hid_device *hdev = input_get_drvdata(dev); struct t300rs_device_entry *t300rs; u8 *send_buffer; int ret, trans; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return; } send_buffer = t300rs->send_buffer; - send_buffer[0] = 0x08; send_buffer[1] = 0x04; send_buffer[2] = 0x01; ret = t300rs_send_int(dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(hdev, "failed setting autocenter"); + return; } send_buffer[0] = 0x08; @@ -1188,21 +1229,19 @@ static void t300rs_set_autocenter(struct input_dev *dev, u16 value){ send_buffer[3] = value >> 8; ret = t300rs_send_int(dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(hdev, "failed setting autocenter"); - } - - } -static void t300rs_set_gain(struct input_dev *dev, u16 gain){ +static void t300rs_set_gain(struct input_dev *dev, u16 gain) +{ struct hid_device *hdev = input_get_drvdata(dev); struct t300rs_device_entry *t300rs; u8 *send_buffer; int ret, trans; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return; } @@ -1212,26 +1251,24 @@ static void t300rs_set_gain(struct input_dev *dev, u16 gain){ send_buffer[1] = SCALE_VALUE_U16(gain, 8); ret = t300rs_send_int(dev, send_buffer, &trans); - if(ret){ + if (ret) hid_err(hdev, "failed setting gain: %i\n", ret); - } - - } -static void t300rs_destroy(struct ff_device *ff){ - /* maybe not necessary? */ - return; +static void t300rs_destroy(struct ff_device *ff) +{ + // maybe not necessary? } -static int t300rs_open(struct input_dev *dev){ +static int t300rs_open(struct input_dev *dev) +{ struct t300rs_device_entry *t300rs; struct hid_device *hdev = input_get_drvdata(dev); u8 *send_buffer; int ret, trans; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return -1; } @@ -1241,26 +1278,25 @@ static int t300rs_open(struct input_dev *dev){ send_buffer[0] = 0x01; send_buffer[1] = 0x05; - ret = t300rs_send_int(dev, send_buffer, &trans); - if(ret){ + ret = t300rs_send_int(dev, send_buffer, &trans); + if (ret) { hid_err(hdev, "failed sending interrupts\n"); goto err; } err: - - return t300rs->open(dev); } -static void t300rs_close(struct input_dev *dev){ +static void t300rs_close(struct input_dev *dev) +{ int ret, trans; struct hid_device *hdev = input_get_drvdata(dev); struct t300rs_device_entry *t300rs; u8 *send_buffer; t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return; } @@ -1270,39 +1306,38 @@ static void t300rs_close(struct input_dev *dev){ send_buffer[0] = 0x01; ret = t300rs_send_int(dev, send_buffer, &trans); - if(ret){ + if (ret) { hid_err(hdev, "failed sending interrupts\n"); goto err; } err: - t300rs->close(dev); - return; } -static int t300rs_create_files(struct hid_device *hdev){ +static int t300rs_create_files(struct hid_device *hdev) +{ int ret; ret = device_create_file(&hdev->dev, &dev_attr_range); - if(ret){ + if (ret) { hid_warn(hdev, "unable to create sysfs interface for range\n"); goto attr_range_err; } ret = device_create_file(&hdev->dev, &dev_attr_spring_level); - if(ret){ + if (ret) { hid_warn(hdev, "unable to create sysfs interface for spring_level\n"); goto attr_spring_err; } ret = device_create_file(&hdev->dev, &dev_attr_damper_level); - if(ret){ + if (ret) { hid_warn(hdev, "unable to create sysfs interface for damper_level\n"); goto attr_damper_err; } ret = device_create_file(&hdev->dev, &dev_attr_friction_level); - if(ret){ + if (ret) { hid_warn(hdev, "unable to create sysfs interface for friction_level\n"); goto attr_friction_err; } @@ -1321,7 +1356,8 @@ attr_range_err: return ret; } -static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ +static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits) +{ struct t300rs_device_entry *t300rs; struct t300rs_data *drv_data; struct list_head *report_list; @@ -1336,15 +1372,14 @@ static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ int i, ret; drv_data = hid_get_drvdata(hdev); - if(!drv_data){ + if (!drv_data) { hid_err(hdev, "private driver data not allocated\n"); ret = -ENOMEM; goto err; } t300rs = kzalloc(sizeof(struct t300rs_device_entry), GFP_KERNEL); - if(!t300rs){ - hid_err(hdev, "device entry could not be created\n"); + if (!t300rs) { ret = -ENOMEM; goto t300rs_err; } @@ -1354,23 +1389,22 @@ static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ t300rs->usbdev = usbdev; t300rs->usbif = usbif; - t300rs->states = kzalloc(sizeof(struct t300rs_effect_state) * T300RS_MAX_EFFECTS, GFP_KERNEL); - if(!t300rs->states){ - hid_err(hdev, "effect states could not be created\n"); + t300rs->states = kzalloc( + sizeof(struct t300rs_effect_state) * T300RS_MAX_EFFECTS, GFP_KERNEL); + + if (!t300rs->states) { ret = -ENOMEM; goto states_err; } t300rs->send_buffer = kzalloc(T300RS_BUFFER_LENGTH, GFP_KERNEL); - if(!t300rs->send_buffer){ - hid_err(hdev, "send_buffer could not be created\n"); + if (!t300rs->send_buffer) { ret = -ENOMEM; goto send_err; } t300rs->firmware_response = kzalloc(sizeof(struct t300rs_firmware_response), GFP_KERNEL); - if(!t300rs->firmware_response){ - hid_err(hdev, "firmware_response could not be created\n"); + if (!t300rs->firmware_response) { ret = -ENOMEM; goto firmware_err; } @@ -1385,18 +1419,18 @@ static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ t300rs->firmware_response, t300rs_firmware_request.wLength, USB_CTRL_SET_TIMEOUT - ); + ); // Educated guess - if(t300rs->firmware_response->firmware_version < 31 && ret >= 0){ - hid_err(t300rs->hdev, - "firmware version %i is too old, please update the firmware " - "using the official Thrustmaster tools. This will have to " - "be done outside of Linux.\n", + if (t300rs->firmware_response->firmware_version < 31 && ret >= 0) { + hid_err(t300rs->hdev, + "firmware version %i is too old, please update.", t300rs->firmware_response->firmware_version ); - ret = -ENOSYS; + hid_info(t300rs->hdev, "note: this has to be done through Windows."); + + ret = -EINVAL; goto out; } @@ -1411,12 +1445,11 @@ static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ t300rs->ff_field = t300rs->report->field[0]; // set ff capabilities - for(i = 0; ff_bits[i] >= 0; ++i){ + for (i = 0; ff_bits[i] >= 0; ++i) __set_bit(ff_bits[i], input_dev->ffbit); - } ret = input_ff_create(input_dev, T300RS_MAX_EFFECTS); - if(ret){ + if (ret) { hid_err(hdev, "could not create input_ff\n"); goto out; } @@ -1435,7 +1468,7 @@ static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ input_dev->close = t300rs_close; ret = t300rs_create_files(hdev); - if(ret){ + if (ret) { // this might not be a catastrophic issue, but it could affect // programs such as oversteer, best play it safe hid_err(hdev, "could not create sysfs files\n"); @@ -1446,7 +1479,7 @@ static int t300rs_init(struct hid_device *hdev, const signed short *ff_bits){ hrtimer_init(&t300rs->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); t300rs->hrtimer.function = t300rs_timer; - t300rs_range_store(dev, &dev_attr_range, range, 10); + range_store(dev, &dev_attr_range, range, 10); t300rs_set_gain(input_dev, 0xffff); hid_info(hdev, "force feedback for T300RS\n"); @@ -1468,36 +1501,36 @@ err: } -static int t300rs_probe(struct hid_device *hdev, const struct hid_device_id *id){ +static int t300rs_probe(struct hid_device *hdev, const struct hid_device_id *id) +{ int ret; struct t300rs_data *drv_data; spin_lock_init(&lock); drv_data = kzalloc(sizeof(struct t300rs_data), GFP_KERNEL); - if(!drv_data){ - hid_err(hdev, "out of memory\n"); + if (!drv_data) { ret = -ENOMEM; goto err; } drv_data->quirks = id->driver_data; - hid_set_drvdata(hdev, (void*)drv_data); + hid_set_drvdata(hdev, (void *)drv_data); ret = hid_parse(hdev); - if(ret){ + if (ret) { hid_err(hdev, "parse failed\n"); goto err; } ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); - if(ret){ + if (ret) { hid_err(hdev, "hw start failed\n"); goto err; } - ret = t300rs_init(hdev, (void*)id->driver_data); - if(ret){ + ret = t300rs_init(hdev, (void *)id->driver_data); + if (ret) { hid_err(hdev, "t300rs_init failed\n"); goto err; } @@ -1506,13 +1539,14 @@ err: return ret; } -static void t300rs_remove(struct hid_device *hdev){ +static void t300rs_remove(struct hid_device *hdev) +{ struct t300rs_device_entry *t300rs; struct t300rs_data *drv_data; drv_data = hid_get_drvdata(hdev); t300rs = t300rs_get_device(hdev); - if(!t300rs){ + if (!t300rs) { hid_err(hdev, "could not get device\n"); return; } @@ -1530,11 +1564,10 @@ static void t300rs_remove(struct hid_device *hdev){ kfree(t300rs->firmware_response); kfree(t300rs); kfree(drv_data); - - return; } -static __u8 *t300rs_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize){ +static __u8 *t300rs_report_fixup(struct hid_device *hdev, __u8 *rdesc, unsigned int *rsize) +{ rdesc = t300rs_rdesc_fixed; *rsize = sizeof(t300rs_rdesc_fixed); return rdesc; diff --git a/hid-tmt300rs.h b/hid-tmt300rs.h index 28b44ab..c3038c5 100644 --- a/hid-tmt300rs.h +++ b/hid-tmt300rs.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GLP-2.0 */ #include #include #include @@ -15,9 +16,9 @@ /* the wheel seems to only be capable of processing a certain number of * interrupts per second, and if this value is too low the kernel urb buffer(or * some buffer at least) fills up. Optimally I would figure out some way to - * space out the interrupts so that they all leave at regular intervals, but for - * now this is good enough, go slow enough that everything works. - * */ + * space out the interrupts so that they all leave at regular intervals, but + * for now this is good enough, go slow enough that everything works. + */ #define DEFAULT_TIMER_PERIOD 8 #define FF_EFFECT_QUEUE_UPLOAD 0 @@ -37,119 +38,119 @@ spinlock_t data_lock; unsigned long data_flags; static const signed short t300rs_ff_effects[] = { - FF_CONSTANT, - FF_RAMP, - FF_SPRING, - FF_DAMPER, - FF_FRICTION, - FF_INERTIA, - FF_PERIODIC, - FF_SINE, - FF_TRIANGLE, - FF_SQUARE, - FF_SAW_UP, - FF_SAW_DOWN, - FF_AUTOCENTER, - FF_GAIN, - -1 + FF_CONSTANT, + FF_RAMP, + FF_SPRING, + FF_DAMPER, + FF_FRICTION, + FF_INERTIA, + FF_PERIODIC, + FF_SINE, + FF_TRIANGLE, + FF_SQUARE, + FF_SAW_UP, + FF_SAW_DOWN, + FF_AUTOCENTER, + FF_GAIN, + -1 }; struct t300rs_effect_state { - struct ff_effect effect; - struct ff_effect old; - bool old_set; - unsigned long flags; - unsigned long start_time; - unsigned long count; + struct ff_effect effect; + struct ff_effect old; + bool old_set; + unsigned long flags; + unsigned long start_time; + unsigned long count; }; struct __packed t300rs_firmware_response { - uint8_t unknown0; - uint8_t unknown1; - uint8_t firmware_version; - uint8_t unknown2; + uint8_t unknown0; + uint8_t unknown1; + uint8_t firmware_version; + uint8_t unknown2; }; struct usb_ctrlrequest t300rs_firmware_request = { - .bRequestType = 0xc1, - .bRequest = 86, - .wValue = 0, - .wIndex = 0, - .wLength = 8 + .bRequestType = 0xc1, + .bRequest = 86, + .wValue = 0, + .wIndex = 0, + .wLength = 8 }; struct t300rs_device_entry { - struct hid_device *hdev; - struct input_dev *input_dev; - struct hid_report *report; - struct hid_field *ff_field; - struct usb_device *usbdev; - struct usb_interface *usbif; - struct t300rs_effect_state *states; - struct t300rs_firmware_response *firmware_response; - struct hrtimer hrtimer; - - int (*open)(struct input_dev *dev); - void (*close)(struct input_dev *dev); - - spinlock_t lock; - unsigned long lock_flags; - - u8 *send_buffer; - - u16 range; - u8 effects_used; + struct hid_device *hdev; + struct input_dev *input_dev; + struct hid_report *report; + struct hid_field *ff_field; + struct usb_device *usbdev; + struct usb_interface *usbif; + struct t300rs_effect_state *states; + struct t300rs_firmware_response *firmware_response; + struct hrtimer hrtimer; + + int (*open)(struct input_dev *dev); + void (*close)(struct input_dev *dev); + + spinlock_t lock; + unsigned long lock_flags; + + u8 *send_buffer; + + u16 range; + u8 effects_used; }; -struct t300rs_data{ - unsigned long quirks; - void *device_props; +struct t300rs_data { + unsigned long quirks; + void *device_props; }; static __u8 t300rs_rdesc_fixed[] = { - 0x05, 0x01, 0x09, 0x04, 0xa1, - 0x01, 0x09, 0x01, 0xa1, 0x00, - 0x85, 0x07, 0x09, 0x30, 0x15, - 0x00, 0x27, 0xff, 0xff, 0x00, - 0x00, 0x35, 0x00, 0x47, 0xff, - 0xff, 0x00, 0x00, 0x75, 0x10, - 0x95, 0x01, 0x81, 0x02, 0x09, - 0x35, 0x26, 0xff, 0x03, 0x46, - 0xff, 0x03, 0x81, 0x02, 0x09, - 0x32, 0x81, 0x02, 0x09, 0x31, - 0x81, 0x02, 0x81, 0x03, 0x05, - 0x09, 0x19, 0x01, 0x29, 0x0d, - 0x25, 0x01, 0x45, 0x01, 0x75, - 0x01, 0x95, 0x0d, 0x81, 0x02, - 0x75, 0x0b, 0x95, 0x01, 0x81, - 0x03, 0x05, 0x01, 0x09, 0x39, - 0x25, 0x07, 0x46, 0x3b, 0x01, - 0x55, 0x00, 0x65, 0x14, 0x75, - 0x04, 0x81, 0x42, 0x65, 0x00, - 0x81, 0x03, 0x85, 0x60, // here 0x0a - 0x06, 0x00, 0xff, 0x09, 0x60, // here 0x0a - 0x75, 0x08, 0x95, 0x3f, 0x26, - 0xff, 0x7f, 0x15, 0x00, 0x46, - 0xff, 0x7f, 0x36, 0x00, 0x80, - 0x91, 0x02, 0x85, 0x02, 0x09, - 0x02, 0x81, 0x02, 0x09, 0x14, - 0x85, 0x14, 0x81, 0x02, 0xc0, - 0xc0, + 0x05, 0x01, 0x09, 0x04, 0xa1, + 0x01, 0x09, 0x01, 0xa1, 0x00, + 0x85, 0x07, 0x09, 0x30, 0x15, + 0x00, 0x27, 0xff, 0xff, 0x00, + 0x00, 0x35, 0x00, 0x47, 0xff, + 0xff, 0x00, 0x00, 0x75, 0x10, + 0x95, 0x01, 0x81, 0x02, 0x09, + 0x35, 0x26, 0xff, 0x03, 0x46, + 0xff, 0x03, 0x81, 0x02, 0x09, + 0x32, 0x81, 0x02, 0x09, 0x31, + 0x81, 0x02, 0x81, 0x03, 0x05, + 0x09, 0x19, 0x01, 0x29, 0x0d, + 0x25, 0x01, 0x45, 0x01, 0x75, + 0x01, 0x95, 0x0d, 0x81, 0x02, + 0x75, 0x0b, 0x95, 0x01, 0x81, + 0x03, 0x05, 0x01, 0x09, 0x39, + 0x25, 0x07, 0x46, 0x3b, 0x01, + 0x55, 0x00, 0x65, 0x14, 0x75, + 0x04, 0x81, 0x42, 0x65, 0x00, + 0x81, 0x03, 0x85, 0x60, // here 0x0a + 0x06, 0x00, 0xff, 0x09, 0x60, // here 0x0a + 0x75, 0x08, 0x95, 0x3f, 0x26, + 0xff, 0x7f, 0x15, 0x00, 0x46, + 0xff, 0x7f, 0x36, 0x00, 0x80, + 0x91, 0x02, 0x85, 0x02, 0x09, + 0x02, 0x81, 0x02, 0x09, 0x14, + 0x85, 0x14, 0x81, 0x02, 0xc0, + 0xc0, }; static u8 spring_values[] = { - 0xa6, 0x6a, 0xa6, 0x6a, 0xfe, - 0xff, 0xfe, 0xff, 0xfe, 0xff, - 0xfe, 0xff, 0xdf, 0x58, 0xa6, - 0x6a, 0x06 + 0xa6, 0x6a, 0xa6, 0x6a, 0xfe, + 0xff, 0xfe, 0xff, 0xfe, 0xff, + 0xfe, 0xff, 0xdf, 0x58, 0xa6, + 0x6a, 0x06 }; static u8 damper_values[] = { - 0xfc, 0x7f, 0xfc, 0x7f, 0xfe, - 0xff, 0xfe, 0xff, 0xfe, 0xff, - 0xfe, 0xff, 0xfc, 0x7f, 0xfc, - 0x7f, 0x07 + 0xfc, 0x7f, 0xfc, 0x7f, 0xfe, + 0xff, 0xfe, 0xff, 0xfe, 0xff, + 0xfe, 0xff, 0xfc, 0x7f, 0xfc, + 0x7f, 0x07 }; -- cgit v1.3