Blame view
drivers/hid/hid-zpff.c
3.02 KB
1a59d1b8e treewide: Replace... |
1 |
// SPDX-License-Identifier: GPL-2.0-or-later |
bb3caf7f4 Input: add force ... |
2 3 4 5 6 7 8 |
/* * Force feedback support for Zeroplus based devices * * Copyright (c) 2005, 2006 Anssi Hannula <anssi.hannula@gmail.com> */ /* |
bb3caf7f4 Input: add force ... |
9 |
*/ |
987fbc1f7 HID: move zeroplu... |
10 |
#include <linux/hid.h> |
bb3caf7f4 Input: add force ... |
11 |
#include <linux/input.h> |
5a0e3ad6a include cleanup: ... |
12 |
#include <linux/slab.h> |
8f86a2c3c hid: Add module.h... |
13 |
#include <linux/module.h> |
987fbc1f7 HID: move zeroplu... |
14 15 |
#include "hid-ids.h" |
0f6f4319a HID: fix hid-ff d... |
16 |
#ifdef CONFIG_ZEROPLUS_FF |
bb3caf7f4 Input: add force ... |
17 18 19 20 |
struct zpff_device { struct hid_report *report; }; |
987fbc1f7 HID: move zeroplu... |
21 |
static int zpff_play(struct input_dev *dev, void *data, |
bb3caf7f4 Input: add force ... |
22 23 |
struct ff_effect *effect) { |
e07129858 HID: switch to us... |
24 |
struct hid_device *hid = input_get_drvdata(dev); |
bb3caf7f4 Input: add force ... |
25 26 27 28 29 30 31 32 33 34 35 |
struct zpff_device *zpff = data; int left, right; /* * The following is specified the other way around in the Zeroplus * datasheet but the order below is correct for the XFX Executioner; * however it is possible that the XFX Executioner is an exception */ left = effect->u.rumble.strong_magnitude; right = effect->u.rumble.weak_magnitude; |
58037eb96 HID: make debuggi... |
36 37 |
dbg_hid("called with 0x%04x 0x%04x ", left, right); |
bb3caf7f4 Input: add force ... |
38 39 40 41 42 43 |
left = left * 0x7f / 0xffff; right = right * 0x7f / 0xffff; zpff->report->field[2]->value[0] = left; zpff->report->field[3]->value[0] = right; |
58037eb96 HID: make debuggi... |
44 45 |
dbg_hid("running with 0x%02x 0x%02x ", left, right); |
d88142725 HID: use hid_hw_r... |
46 |
hid_hw_request(hid, zpff->report, HID_REQ_SET_REPORT); |
bb3caf7f4 Input: add force ... |
47 48 49 |
return 0; } |
987fbc1f7 HID: move zeroplu... |
50 |
static int zpff_init(struct hid_device *hid) |
bb3caf7f4 Input: add force ... |
51 52 53 |
{ struct zpff_device *zpff; struct hid_report *report; |
d9d4b1e46 HID: Fix assumpti... |
54 55 |
struct hid_input *hidinput; struct input_dev *dev; |
78214e81a HID: zeroplus: va... |
56 |
int i, error; |
bb3caf7f4 Input: add force ... |
57 |
|
d9d4b1e46 HID: Fix assumpti... |
58 59 60 61 62 63 64 |
if (list_empty(&hid->inputs)) { hid_err(hid, "no inputs found "); return -ENODEV; } hidinput = list_entry(hid->inputs.next, struct hid_input, list); dev = hidinput->input; |
78214e81a HID: zeroplus: va... |
65 66 67 68 |
for (i = 0; i < 4; i++) { report = hid_validate_values(hid, HID_OUTPUT_REPORT, 0, i, 1); if (!report) return -ENODEV; |
bb3caf7f4 Input: add force ... |
69 70 71 72 73 74 75 |
} zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL); if (!zpff) return -ENOMEM; set_bit(FF_RUMBLE, dev->ffbit); |
987fbc1f7 HID: move zeroplu... |
76 |
error = input_ff_create_memless(dev, zpff, zpff_play); |
bb3caf7f4 Input: add force ... |
77 78 79 80 81 82 83 84 85 86 |
if (error) { kfree(zpff); return error; } zpff->report = report; zpff->report->field[0]->value[0] = 0x00; zpff->report->field[1]->value[0] = 0x02; zpff->report->field[2]->value[0] = 0x00; zpff->report->field[3]->value[0] = 0x00; |
d88142725 HID: use hid_hw_r... |
87 |
hid_hw_request(hid, zpff->report, HID_REQ_SET_REPORT); |
bb3caf7f4 Input: add force ... |
88 |
|
4291ee305 HID: Add and use ... |
89 90 |
hid_info(hid, "force feedback for Zeroplus based devices by Anssi Hannula <anssi.hannula@gmail.com> "); |
bb3caf7f4 Input: add force ... |
91 92 93 |
return 0; } |
0f6f4319a HID: fix hid-ff d... |
94 95 96 97 98 99 |
#else static inline int zpff_init(struct hid_device *hid) { return 0; } #endif |
987fbc1f7 HID: move zeroplu... |
100 101 102 103 104 105 106 |
static int zp_probe(struct hid_device *hdev, const struct hid_device_id *id) { int ret; ret = hid_parse(hdev); if (ret) { |
4291ee305 HID: Add and use ... |
107 108 |
hid_err(hdev, "parse failed "); |
987fbc1f7 HID: move zeroplu... |
109 110 111 112 113 |
goto err; } ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); if (ret) { |
4291ee305 HID: Add and use ... |
114 115 |
hid_err(hdev, "hw start failed "); |
987fbc1f7 HID: move zeroplu... |
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
goto err; } zpff_init(hdev); return 0; err: return ret; } static const struct hid_device_id zp_devices[] = { { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, { } }; MODULE_DEVICE_TABLE(hid, zp_devices); static struct hid_driver zp_driver = { .name = "zeroplus", .id_table = zp_devices, .probe = zp_probe, }; |
f425458ea HID: Use module_h... |
138 |
module_hid_driver(zp_driver); |
987fbc1f7 HID: move zeroplu... |
139 |
|
987fbc1f7 HID: move zeroplu... |
140 |
MODULE_LICENSE("GPL"); |