From: johann d. <jd...@us...> - 2002-03-10 12:26:43
|
Update of /cvsroot/linuxconsole/ruby/linux/drivers/usb In directory usw-pr-cvs1:/tmp/cvs-serv5822 Modified Files: hid-core.c hid-ff.c hid-input.c hid.h Log Message: Cosmetics. Moved hid_ff_exit calls to hid_free_device. Index: hid-core.c =================================================================== RCS file: /cvsroot/linuxconsole/ruby/linux/drivers/usb/hid-core.c,v retrieving revision 1.47 retrieving revision 1.48 diff -u -d -r1.47 -r1.48 --- hid-core.c 6 Mar 2002 23:02:58 -0000 1.47 +++ hid-core.c 10 Mar 2002 12:26:40 -0000 1.48 @@ -519,6 +519,10 @@ { unsigned i,j; +#ifdef CONFIG_HID_FF + hid_ff_exit(device); +#endif + for (i = 0; i < HID_REPORT_TYPES; i++) { struct hid_report_enum *report_enum = device->report_enum + i; @@ -1374,10 +1378,6 @@ return hid; fail: -#ifdef CONFIG_HID_FF - if (hid->exit_ff) - hid->exit_ff(hid); -#endif hid_free_device(hid); if (hid->urbin) usb_free_urb(hid->urbin); if (hid->urbout) usb_free_urb(hid->urbout); @@ -1403,7 +1403,7 @@ hid_dump_device(hid); #ifdef CONFIG_HID_FF - if (hid_init_ff(hid)) { + if (hid_ff_init(hid)) { hid_free_device(hid); return NULL; } @@ -1465,10 +1465,6 @@ if (hid->urbout) usb_free_urb(hid->urbout); -#ifdef CONFIG_HID_FF - if (hid->exit_ff) - hid->exit_ff(hid); -#endif hid_free_device(hid); } Index: hid-ff.c =================================================================== RCS file: /cvsroot/linuxconsole/ruby/linux/drivers/usb/hid-ff.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- hid-ff.c 6 Mar 2002 23:02:58 -0000 1.1 +++ hid-ff.c 10 Mar 2002 12:26:40 -0000 1.2 @@ -81,18 +81,19 @@ #define LGFF_BUFFER_SIZE 8 struct hid_ff_logitech { - struct urb* urbffout; /* Output URB used to send ff commands */ - struct usb_ctrlrequest ffcr; /* ff commands are sent using control URBs */ - char ffoutbuf[LGFF_BUFFER_SIZE]; - signed char rumble_left; /* Magnitude of left motor */ - signed char rumble_right; /* Magnitude of right motor */ - int rumble_play; /* Enable rumbling */ + struct urb* urbffout; /* Output URB used to send ff commands */ + struct usb_ctrlrequest ffcr; /* ff commands are sent using control URBs */ + char buf[LGFF_BUFFER_SIZE]; + unsigned char left; /* Magnitude of left motor */ + unsigned char right; /* Magnitude of right motor */ + int play; /* Enable rumbling */ }; static void hid_lgff_ctrl_out(struct urb *urb); static int hid_lgff_upload_effect(struct input_dev* input, struct ff_effect* effect); static void hid_lgff_exit(struct hid_device* hid); -static int hid_lgff_event(struct input_dev* input, unsigned int type, unsigned int code, int value); +static int hid_lgff_event(struct hid_device *hid, struct input_dev* input, + unsigned int type, unsigned int code, int value); static void hid_lgff_make_rumble(struct hid_device* hid); static int hid_lgff_init(struct hid_device* hid) @@ -101,10 +102,12 @@ /* Private data */ private = hid->ff_private = kmalloc(sizeof(struct hid_ff_logitech), GFP_KERNEL); + memset(private, 0, sizeof(struct hid_ff_logitech)); + if (!hid->ff_private) return -1; /* Event and exit callbacks */ - hid->exit_ff = hid_lgff_exit; + hid->ff_exit = hid_lgff_exit; hid->ff_event = hid_lgff_event; /* USB init */ @@ -113,7 +116,7 @@ return -1; } - FILL_CONTROL_URB(private->urbffout, hid->dev, 0, (void*) &private->ffcr, private->ffoutbuf, 8, hid_lgff_ctrl_out, hid); + usb_fill_control_urb(private->urbffout, hid->dev, 0, (void*) &private->ffcr, private->buf, 8, hid_lgff_ctrl_out, hid); dbg("Created ff output control urb"); /* Input init */ @@ -122,6 +125,7 @@ set_bit(EV_FF, hid->input.evbit); hid->input.ff_effects_max = 1; + return 0; } @@ -135,15 +139,15 @@ } } -static int hid_lgff_event(struct input_dev* input, unsigned int type, unsigned int code, int value) +static int hid_lgff_event(struct hid_device *hid, struct input_dev* input, + unsigned int type, unsigned int code, int value) { - struct hid_device *hid = input->private; struct hid_ff_logitech *lgff = hid->ff_private; if (type == EV_FF) { - int old = lgff->rumble_play; - lgff->rumble_play = (value!=0); - if (old != lgff->rumble_play) hid_lgff_make_rumble(hid); + int old = lgff->play; + lgff->play = (value!=0); + if (old != lgff->play) hid_lgff_make_rumble(hid); return 0; } @@ -157,20 +161,20 @@ int err; dbg("in hid_make_rumble"); - memcpy(lgff->ffoutbuf, packet, 8); - if (lgff->rumble_play) { - lgff->ffoutbuf[3] = lgff->rumble_left; - lgff->ffoutbuf[4] = lgff->rumble_right; + memcpy(lgff->buf, packet, 8); + if (lgff->play) { + lgff->buf[3] = lgff->left; + lgff->buf[4] = lgff->right; } else { - lgff->ffoutbuf[3] = 0; - lgff->ffoutbuf[4] = 0; + lgff->buf[3] = 0; + lgff->buf[4] = 0; } lgff->urbffout->pipe = usb_sndctrlpipe(hid->dev, 0); lgff->ffcr.bRequestType = USB_TYPE_CLASS | USB_DIR_OUT | USB_RECIP_INTERFACE; lgff->urbffout->transfer_buffer_length = lgff->ffcr.wLength = 8; lgff->ffcr.bRequest = 9; - lgff->ffcr.wValue = 0x0203; + lgff->ffcr.wValue = 0x0203; /*NOTE: Potential problem with little/big endian */ lgff->ffcr.wIndex = 0; lgff->urbffout->dev = hid->dev; @@ -190,7 +194,7 @@ static int hid_lgff_upload_effect(struct input_dev* input, struct ff_effect* effect) { - struct hid_device* hid = input->private; + struct hid_device *hid = input->private; struct hid_ff_logitech *lgff = hid->ff_private; dbg("ioctl rumble"); @@ -199,8 +203,8 @@ switch (effect->type) { case FF_RUMBLE: - lgff->rumble_left = 0x80; - lgff->rumble_right = 0x00; + lgff->left = effect->u.rumble.strong_magnitude >> 9; + lgff->right = effect->u.rumble.weak_magnitude >> 9; break; Index: hid-input.c =================================================================== RCS file: /cvsroot/linuxconsole/ruby/linux/drivers/usb/hid-input.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- hid-input.c 6 Mar 2002 23:02:58 -0000 1.21 +++ hid-input.c 10 Mar 2002 12:26:40 -0000 1.22 @@ -382,7 +382,7 @@ #ifdef CONFIG_HID_FF if (type == EV_FF) { - return hid->ff_event? hid->ff_event(dev, type, code, value) : -1; + return hid_ff_event(hid, dev, type, code, value); } #else if (0) {} Index: hid.h =================================================================== RCS file: /cvsroot/linuxconsole/ruby/linux/drivers/usb/hid.h,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- hid.h 6 Mar 2002 23:02:58 -0000 1.28 +++ hid.h 10 Mar 2002 12:26:40 -0000 1.29 @@ -358,8 +358,9 @@ char uniq[64]; /* Device unique identifier (serial #) */ void *ff_private; /* Private data for the force-feedback driver */ - void (*exit_ff)(struct hid_device*); /* Called by hid_exit_ff(hid) */ - int (*ff_event)(struct input_dev*, unsigned int type, unsigned int code, int value); + void (*ff_exit)(struct hid_device*); /* Called by hid_exit_ff(hid) */ + int (*ff_event)(struct hid_device *hid, struct input_dev *input, + unsigned int type, unsigned int code, int value); }; #define HID_GLOBAL_STACK_SIZE 4 @@ -415,6 +416,19 @@ void hid_submit_report(struct hid_device *, struct hid_report *, unsigned char dir); void hid_init_reports(struct hid_device *hid); + #ifdef CONFIG_HID_FF -int hid_init_ff(struct hid_device *hid); + +int hid_ff_init(struct hid_device *hid); +static inline void hid_ff_exit(struct hid_device *hid) +{ + if (hid->ff_exit) hid->ff_exit(hid); +} + +static inline int hid_ff_event(struct hid_device *hid, struct input_dev *input, + unsigned int type, unsigned int code, int value) +{ + if (hid->ff_event) return hid->ff_event(hid, input, type, code, value); + return -ENOSYS; +} #endif |