HID: magicmouse: coding style and probe failure fixes
Use proper values to initialize bool configuration variables, tabs rather than spaces, no braces for one-line else clause, __set_bit() when the operation doesn't have to be atomic, input_set_abs_params() rather than writing the fields directly, and call hid_hw_stop() when appropriate to handle failures in the probe. Signed-off-by: Michael Poole <mdpoole@troilus.org> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
9f52314723
commit
71b38bd4c1
@ -18,22 +18,22 @@
|
|||||||
|
|
||||||
#include "hid-ids.h"
|
#include "hid-ids.h"
|
||||||
|
|
||||||
static bool emulate_3button = 1;
|
static bool emulate_3button = true;
|
||||||
module_param(emulate_3button, bool, 0644);
|
module_param(emulate_3button, bool, 0644);
|
||||||
MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
|
MODULE_PARM_DESC(emulate_3button, "Emulate a middle button");
|
||||||
|
|
||||||
static int middle_button_start = -350;
|
static int middle_button_start = -350;
|
||||||
static int middle_button_stop = +350;
|
static int middle_button_stop = +350;
|
||||||
|
|
||||||
static bool emulate_scroll_wheel = 1;
|
static bool emulate_scroll_wheel = true;
|
||||||
module_param(emulate_scroll_wheel, bool, 0644);
|
module_param(emulate_scroll_wheel, bool, 0644);
|
||||||
MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
|
MODULE_PARM_DESC(emulate_scroll_wheel, "Emulate a scroll wheel");
|
||||||
|
|
||||||
static bool report_touches = 1;
|
static bool report_touches = true;
|
||||||
module_param(report_touches, bool, 0644);
|
module_param(report_touches, bool, 0644);
|
||||||
MODULE_PARM_DESC(report_touches, "Emit touch records (otherwise, only use them for emulation)");
|
MODULE_PARM_DESC(report_touches, "Emit touch records (otherwise, only use them for emulation)");
|
||||||
|
|
||||||
static bool report_undeciphered = 0;
|
static bool report_undeciphered;
|
||||||
module_param(report_undeciphered, bool, 0644);
|
module_param(report_undeciphered, bool, 0644);
|
||||||
MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
|
MODULE_PARM_DESC(report_undeciphered, "Report undeciphered multi-touch state field using a MSC_RAW event");
|
||||||
|
|
||||||
@ -202,9 +202,8 @@ static void magicmouse_emit_touch(struct magicmouse_sc *msc, int raw_id, u8 *tda
|
|||||||
input_report_abs(input, ABS_MT_POSITION_X, x);
|
input_report_abs(input, ABS_MT_POSITION_X, x);
|
||||||
input_report_abs(input, ABS_MT_POSITION_Y, y);
|
input_report_abs(input, ABS_MT_POSITION_Y, y);
|
||||||
|
|
||||||
if (report_undeciphered) {
|
if (report_undeciphered)
|
||||||
input_event(input, EV_MSC, MSC_RAW, tdata[7]);
|
input_event(input, EV_MSC, MSC_RAW, tdata[7]);
|
||||||
}
|
|
||||||
|
|
||||||
input_mt_sync(input);
|
input_mt_sync(input);
|
||||||
}
|
}
|
||||||
@ -291,62 +290,41 @@ static void magicmouse_setup_input(struct input_dev *input, struct hid_device *h
|
|||||||
input->id.version = hdev->version;
|
input->id.version = hdev->version;
|
||||||
input->dev.parent = hdev->dev.parent;
|
input->dev.parent = hdev->dev.parent;
|
||||||
|
|
||||||
set_bit(EV_KEY, input->evbit);
|
__set_bit(EV_KEY, input->evbit);
|
||||||
set_bit(BTN_LEFT, input->keybit);
|
__set_bit(BTN_LEFT, input->keybit);
|
||||||
set_bit(BTN_RIGHT, input->keybit);
|
__set_bit(BTN_RIGHT, input->keybit);
|
||||||
if (emulate_3button)
|
if (emulate_3button)
|
||||||
set_bit(BTN_MIDDLE, input->keybit);
|
__set_bit(BTN_MIDDLE, input->keybit);
|
||||||
set_bit(BTN_TOOL_FINGER, input->keybit);
|
__set_bit(BTN_TOOL_FINGER, input->keybit);
|
||||||
|
|
||||||
set_bit(EV_REL, input->evbit);
|
__set_bit(EV_REL, input->evbit);
|
||||||
set_bit(REL_X, input->relbit);
|
__set_bit(REL_X, input->relbit);
|
||||||
set_bit(REL_Y, input->relbit);
|
__set_bit(REL_Y, input->relbit);
|
||||||
if (emulate_scroll_wheel)
|
if (emulate_scroll_wheel)
|
||||||
set_bit(REL_WHEEL, input->relbit);
|
__set_bit(REL_WHEEL, input->relbit);
|
||||||
|
|
||||||
if (report_touches) {
|
if (report_touches) {
|
||||||
set_bit(EV_ABS, input->evbit);
|
__set_bit(EV_ABS, input->evbit);
|
||||||
|
|
||||||
set_bit(ABS_MT_TRACKING_ID, input->absbit);
|
|
||||||
input->absmin[ABS_MT_TRACKING_ID] = 0;
|
|
||||||
input->absmax[ABS_MT_TRACKING_ID] = 15;
|
|
||||||
input->absfuzz[ABS_MT_TRACKING_ID] = 0;
|
|
||||||
|
|
||||||
set_bit(ABS_MT_TOUCH_MAJOR, input->absbit);
|
|
||||||
input->absmin[ABS_MT_TOUCH_MAJOR] = 0;
|
|
||||||
input->absmax[ABS_MT_TOUCH_MAJOR] = 255;
|
|
||||||
input->absfuzz[ABS_MT_TOUCH_MAJOR] = 4;
|
|
||||||
|
|
||||||
set_bit(ABS_MT_TOUCH_MINOR, input->absbit);
|
|
||||||
input->absmin[ABS_MT_TOUCH_MINOR] = 0;
|
|
||||||
input->absmax[ABS_MT_TOUCH_MINOR] = 255;
|
|
||||||
input->absfuzz[ABS_MT_TOUCH_MINOR] = 4;
|
|
||||||
|
|
||||||
set_bit(ABS_MT_ORIENTATION, input->absbit);
|
|
||||||
input->absmin[ABS_MT_ORIENTATION] = -32;
|
|
||||||
input->absmax[ABS_MT_ORIENTATION] = 31;
|
|
||||||
input->absfuzz[ABS_MT_ORIENTATION] = 1;
|
|
||||||
|
|
||||||
set_bit(ABS_MT_POSITION_X, input->absbit);
|
|
||||||
input->absmin[ABS_MT_POSITION_X] = -1100;
|
|
||||||
input->absmax[ABS_MT_POSITION_X] = 1358;
|
|
||||||
input->absfuzz[ABS_MT_POSITION_X] = 4;
|
|
||||||
|
|
||||||
|
input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, 15, 0, 0);
|
||||||
|
input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 4, 0);
|
||||||
|
input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 255, 4, 0);
|
||||||
|
input_set_abs_params(input, ABS_MT_ORIENTATION, -32, 31, 1, 0);
|
||||||
|
input_set_abs_params(input, ABS_MT_POSITION_X, -1100, 1358,
|
||||||
|
4, 0);
|
||||||
/* Note: Touch Y position from the device is inverted relative
|
/* Note: Touch Y position from the device is inverted relative
|
||||||
* to how pointer motion is reported (and relative to how USB
|
* to how pointer motion is reported (and relative to how USB
|
||||||
* HID recommends the coordinates work). This driver keeps
|
* HID recommends the coordinates work). This driver keeps
|
||||||
* the origin at the same position, and just uses the additive
|
* the origin at the same position, and just uses the additive
|
||||||
* inverse of the reported Y.
|
* inverse of the reported Y.
|
||||||
*/
|
*/
|
||||||
set_bit(ABS_MT_POSITION_Y, input->absbit);
|
input_set_abs_params(input, ABS_MT_POSITION_Y, -1589, 2047,
|
||||||
input->absmin[ABS_MT_POSITION_Y] = -1589;
|
4, 0);
|
||||||
input->absmax[ABS_MT_POSITION_Y] = 2047;
|
|
||||||
input->absfuzz[ABS_MT_POSITION_Y] = 4;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (report_undeciphered) {
|
if (report_undeciphered) {
|
||||||
set_bit(EV_MSC, input->evbit);
|
__set_bit(EV_MSC, input->evbit);
|
||||||
set_bit(MSC_RAW, input->mscbit);
|
__set_bit(MSC_RAW, input->mscbit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -385,7 +363,7 @@ static int magicmouse_probe(struct hid_device *hdev,
|
|||||||
if (!report) {
|
if (!report) {
|
||||||
dev_err(&hdev->dev, "unable to register touch report\n");
|
dev_err(&hdev->dev, "unable to register touch report\n");
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto err_free;
|
goto err_stop_hw;
|
||||||
}
|
}
|
||||||
report->size = 6;
|
report->size = 6;
|
||||||
|
|
||||||
@ -394,34 +372,36 @@ static int magicmouse_probe(struct hid_device *hdev,
|
|||||||
if (ret != sizeof(feature_1)) {
|
if (ret != sizeof(feature_1)) {
|
||||||
dev_err(&hdev->dev, "unable to request touch data (1:%d)\n",
|
dev_err(&hdev->dev, "unable to request touch data (1:%d)\n",
|
||||||
ret);
|
ret);
|
||||||
goto err_free;
|
goto err_stop_hw;
|
||||||
}
|
}
|
||||||
ret = hdev->hid_output_raw_report(hdev, feature_2,
|
ret = hdev->hid_output_raw_report(hdev, feature_2,
|
||||||
sizeof(feature_2), HID_FEATURE_REPORT);
|
sizeof(feature_2), HID_FEATURE_REPORT);
|
||||||
if (ret != sizeof(feature_2)) {
|
if (ret != sizeof(feature_2)) {
|
||||||
dev_err(&hdev->dev, "unable to request touch data (2:%d)\n",
|
dev_err(&hdev->dev, "unable to request touch data (2:%d)\n",
|
||||||
ret);
|
ret);
|
||||||
goto err_free;
|
goto err_stop_hw;
|
||||||
}
|
}
|
||||||
|
|
||||||
input = input_allocate_device();
|
input = input_allocate_device();
|
||||||
if (!input) {
|
if (!input) {
|
||||||
dev_err(&hdev->dev, "can't alloc input device\n");
|
dev_err(&hdev->dev, "can't alloc input device\n");
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto err_free;
|
goto err_stop_hw;
|
||||||
}
|
}
|
||||||
magicmouse_setup_input(input, hdev);
|
magicmouse_setup_input(input, hdev);
|
||||||
|
|
||||||
ret = input_register_device(input);
|
ret = input_register_device(input);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&hdev->dev, "input device registration failed\n");
|
dev_err(&hdev->dev, "input device registration failed\n");
|
||||||
goto err_both;
|
goto err_input;
|
||||||
}
|
}
|
||||||
msc->input = input;
|
msc->input = input;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
err_both:
|
err_input:
|
||||||
input_free_device(input);
|
input_free_device(input);
|
||||||
|
err_stop_hw:
|
||||||
|
hid_hw_stop(hdev);
|
||||||
err_free:
|
err_free:
|
||||||
kfree(msc);
|
kfree(msc);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user