Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 323434
b: refs/heads/master
c: 74479ba
h: refs/heads/master
v: v3
  • Loading branch information
Michal Malý authored and Jiri Kosina committed Sep 25, 2012
1 parent 759618e commit 068fe8f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 84 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4fe9f8e203fdad1524c04beb390f3c6099781ed9
refs/heads/master: 74479ba861b5cd77d445c2ec8f59521ae509f7db
121 changes: 64 additions & 57 deletions trunk/drivers/hid/hid-lg4ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e
struct hid_device *hid = input_get_drvdata(dev);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
int x;

#define CLAMP(x) if (x < 0) x = 0; if (x > 0xff) x = 0xff
Expand All @@ -142,13 +143,13 @@ static int hid_lg4ff_play(struct input_dev *dev, void *data, struct ff_effect *e
case FF_CONSTANT:
x = effect->u.ramp.start_level + 0x80; /* 0x80 is no force */
CLAMP(x);
report->field[0]->value[0] = 0x11; /* Slot 1 */
report->field[0]->value[1] = 0x08;
report->field[0]->value[2] = x;
report->field[0]->value[3] = 0x80;
report->field[0]->value[4] = 0x00;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
value[0] = 0x11; /* Slot 1 */
value[1] = 0x08;
value[2] = x;
value[3] = 0x80;
value[4] = 0x00;
value[5] = 0x00;
value[6] = 0x00;

usbhid_submit_report(hid, report, USB_DIR_OUT);
break;
Expand All @@ -163,14 +164,15 @@ static void hid_lg4ff_set_autocenter_default(struct input_dev *dev, u16 magnitud
struct hid_device *hid = input_get_drvdata(dev);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;

report->field[0]->value[0] = 0xfe;
report->field[0]->value[1] = 0x0d;
report->field[0]->value[2] = magnitude >> 13;
report->field[0]->value[3] = magnitude >> 13;
report->field[0]->value[4] = magnitude >> 8;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
value[0] = 0xfe;
value[1] = 0x0d;
value[2] = magnitude >> 13;
value[3] = magnitude >> 13;
value[4] = magnitude >> 8;
value[5] = 0x00;
value[6] = 0x00;

usbhid_submit_report(hid, report, USB_DIR_OUT);
}
Expand All @@ -181,16 +183,16 @@ static void hid_lg4ff_set_autocenter_ffex(struct input_dev *dev, u16 magnitude)
struct hid_device *hid = input_get_drvdata(dev);
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;
magnitude = magnitude * 90 / 65535;


report->field[0]->value[0] = 0xfe;
report->field[0]->value[1] = 0x03;
report->field[0]->value[2] = magnitude >> 14;
report->field[0]->value[3] = magnitude >> 14;
report->field[0]->value[4] = magnitude;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
value[0] = 0xfe;
value[1] = 0x03;
value[2] = magnitude >> 14;
value[3] = magnitude >> 14;
value[4] = magnitude;
value[5] = 0x00;
value[6] = 0x00;

usbhid_submit_report(hid, report, USB_DIR_OUT);
}
Expand All @@ -200,15 +202,17 @@ static void hid_lg4ff_set_range_g25(struct hid_device *hid, u16 range)
{
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
__s32 *value = report->field[0]->value;

dbg_hid("G25/G27/DFGT: setting range to %u\n", range);

report->field[0]->value[0] = 0xf8;
report->field[0]->value[1] = 0x81;
report->field[0]->value[2] = range & 0x00ff;
report->field[0]->value[3] = (range & 0xff00) >> 8;
report->field[0]->value[4] = 0x00;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
value[0] = 0xf8;
value[1] = 0x81;
value[2] = range & 0x00ff;
value[3] = (range & 0xff00) >> 8;
value[4] = 0x00;
value[5] = 0x00;
value[6] = 0x00;

usbhid_submit_report(hid, report, USB_DIR_OUT);
}
Expand All @@ -219,16 +223,18 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
int start_left, start_right, full_range;
__s32 *value = report->field[0]->value;

dbg_hid("Driving Force Pro: setting range to %u\n", range);

/* Prepare "coarse" limit command */
report->field[0]->value[0] = 0xf8;
report->field[0]->value[1] = 0x00; /* Set later */
report->field[0]->value[2] = 0x00;
report->field[0]->value[3] = 0x00;
report->field[0]->value[4] = 0x00;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
value[0] = 0xf8;
value[1] = 0x00; /* Set later */
value[2] = 0x00;
value[3] = 0x00;
value[4] = 0x00;
value[5] = 0x00;
value[6] = 0x00;

if (range > 200) {
report->field[0]->value[1] = 0x03;
Expand All @@ -240,13 +246,13 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
usbhid_submit_report(hid, report, USB_DIR_OUT);

/* Prepare "fine" limit command */
report->field[0]->value[0] = 0x81;
report->field[0]->value[1] = 0x0b;
report->field[0]->value[2] = 0x00;
report->field[0]->value[3] = 0x00;
report->field[0]->value[4] = 0x00;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
value[0] = 0x81;
value[1] = 0x0b;
value[2] = 0x00;
value[3] = 0x00;
value[4] = 0x00;
value[5] = 0x00;
value[6] = 0x00;

if (range == 200 || range == 900) { /* Do not apply any fine limit */
usbhid_submit_report(hid, report, USB_DIR_OUT);
Expand All @@ -257,11 +263,11 @@ static void hid_lg4ff_set_range_dfp(struct hid_device *hid, __u16 range)
start_left = (((full_range - range + 1) * 2047) / full_range);
start_right = 0xfff - start_left;

report->field[0]->value[2] = start_left >> 4;
report->field[0]->value[3] = start_right >> 4;
report->field[0]->value[4] = 0xff;
report->field[0]->value[5] = (start_right & 0xe) << 4 | (start_left & 0xe);
report->field[0]->value[6] = 0xff;
value[2] = start_left >> 4;
value[3] = start_right >> 4;
value[4] = 0xff;
value[5] = (start_right & 0xe) << 4 | (start_left & 0xe);
value[6] = 0xff;

usbhid_submit_report(hid, report, USB_DIR_OUT);
}
Expand Down Expand Up @@ -344,14 +350,15 @@ static void lg4ff_set_leds(struct hid_device *hid, __u8 leds)
{
struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
struct hid_report *report = list_entry(report_list->next, struct hid_report, list);

report->field[0]->value[0] = 0xf8;
report->field[0]->value[1] = 0x12;
report->field[0]->value[2] = leds;
report->field[0]->value[3] = 0x00;
report->field[0]->value[4] = 0x00;
report->field[0]->value[5] = 0x00;
report->field[0]->value[6] = 0x00;
__s32 *value = report->field[0]->value;

value[0] = 0xf8;
value[1] = 0x12;
value[2] = leds;
value[3] = 0x00;
value[4] = 0x00;
value[5] = 0x00;
value[6] = 0x00;
usbhid_submit_report(hid, report, USB_DIR_OUT);
}

Expand Down Expand Up @@ -501,7 +508,7 @@ int lg4ff_init(struct hid_device *hid)
/* Check if autocentering is available and
* set the centering force to zero by default */
if (test_bit(FF_AUTOCENTER, dev->ffbit)) {
if(rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */
if (rev_maj == FFEX_REV_MAJ && rev_min == FFEX_REV_MIN) /* Formula Force EX expects different autocentering command */
dev->ff->set_autocenter = hid_lg4ff_set_autocenter_ffex;
else
dev->ff->set_autocenter = hid_lg4ff_set_autocenter_default;
Expand Down
69 changes: 43 additions & 26 deletions trunk/drivers/hid/hidraw.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ static struct cdev hidraw_cdev;
static struct class *hidraw_class;
static struct hidraw *hidraw_table[HIDRAW_MAX_DEVICES];
static DEFINE_MUTEX(minors_lock);
static void drop_ref(struct hidraw *hid, int exists_bit);

static ssize_t hidraw_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
{
Expand Down Expand Up @@ -114,7 +113,7 @@ static ssize_t hidraw_send_report(struct file *file, const char __user *buffer,
__u8 *buf;
int ret = 0;

if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
if (!hidraw_table[minor]) {
ret = -ENODEV;
goto out;
}
Expand Down Expand Up @@ -262,7 +261,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
}

mutex_lock(&minors_lock);
if (!hidraw_table[minor] || !hidraw_table[minor]->exist) {
if (!hidraw_table[minor]) {
err = -ENODEV;
goto out_unlock;
}
Expand Down Expand Up @@ -299,12 +298,36 @@ static int hidraw_open(struct inode *inode, struct file *file)
static int hidraw_release(struct inode * inode, struct file * file)
{
unsigned int minor = iminor(inode);
struct hidraw *dev;
struct hidraw_list *list = file->private_data;
int ret;
int i;

mutex_lock(&minors_lock);
if (!hidraw_table[minor]) {
ret = -ENODEV;
goto unlock;
}

drop_ref(hidraw_table[minor], 0);
list_del(&list->node);
dev = hidraw_table[minor];
if (!--dev->open) {
if (list->hidraw->exist) {
hid_hw_power(dev->hid, PM_HINT_NORMAL);
hid_hw_close(dev->hid);
} else {
kfree(list->hidraw);
}
}

for (i = 0; i < HIDRAW_BUFFER_SIZE; ++i)
kfree(list->buffer[i].value);
kfree(list);
return 0;
ret = 0;
unlock:
mutex_unlock(&minors_lock);

return ret;
}

static long hidraw_ioctl(struct file *file, unsigned int cmd,
Expand Down Expand Up @@ -506,7 +529,21 @@ EXPORT_SYMBOL_GPL(hidraw_connect);
void hidraw_disconnect(struct hid_device *hid)
{
struct hidraw *hidraw = hid->hidraw;
drop_ref(hidraw, 1);

mutex_lock(&minors_lock);
hidraw->exist = 0;

device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));

hidraw_table[hidraw->minor] = NULL;

if (hidraw->open) {
hid_hw_close(hid);
wake_up_interruptible(&hidraw->wait);
} else {
kfree(hidraw);
}
mutex_unlock(&minors_lock);
}
EXPORT_SYMBOL_GPL(hidraw_disconnect);

Expand Down Expand Up @@ -548,23 +585,3 @@ void hidraw_exit(void)
unregister_chrdev_region(dev_id, HIDRAW_MAX_DEVICES);

}

static void drop_ref(struct hidraw *hidraw, int exists_bit)
{
mutex_lock(&minors_lock);
if (exists_bit) {
hid_hw_close(hidraw->hid);
hidraw->exist = 0;
if (hidraw->open)
wake_up_interruptible(&hidraw->wait);
} else {
--hidraw->open;
}

if (!hidraw->open && !hidraw->exist) {
device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
hidraw_table[hidraw->minor] = NULL;
kfree(hidraw);
}
mutex_unlock(&minors_lock);
}

0 comments on commit 068fe8f

Please sign in to comment.