diff options
Diffstat (limited to 'drivers/usb/input/usbmouse.c')
-rw-r--r-- | drivers/usb/input/usbmouse.c | 93 |
1 files changed, 50 insertions, 43 deletions
diff --git a/drivers/usb/input/usbmouse.c b/drivers/usb/input/usbmouse.c index 4104dec847fb..230f6b1b314a 100644 --- a/drivers/usb/input/usbmouse.c +++ b/drivers/usb/input/usbmouse.c | |||
@@ -50,7 +50,7 @@ struct usb_mouse { | |||
50 | char name[128]; | 50 | char name[128]; |
51 | char phys[64]; | 51 | char phys[64]; |
52 | struct usb_device *usbdev; | 52 | struct usb_device *usbdev; |
53 | struct input_dev dev; | 53 | struct input_dev *dev; |
54 | struct urb *irq; | 54 | struct urb *irq; |
55 | 55 | ||
56 | signed char *data; | 56 | signed char *data; |
@@ -61,7 +61,7 @@ static void usb_mouse_irq(struct urb *urb, struct pt_regs *regs) | |||
61 | { | 61 | { |
62 | struct usb_mouse *mouse = urb->context; | 62 | struct usb_mouse *mouse = urb->context; |
63 | signed char *data = mouse->data; | 63 | signed char *data = mouse->data; |
64 | struct input_dev *dev = &mouse->dev; | 64 | struct input_dev *dev = mouse->dev; |
65 | int status; | 65 | int status; |
66 | 66 | ||
67 | switch (urb->status) { | 67 | switch (urb->status) { |
@@ -115,14 +115,14 @@ static void usb_mouse_close(struct input_dev *dev) | |||
115 | usb_kill_urb(mouse->irq); | 115 | usb_kill_urb(mouse->irq); |
116 | } | 116 | } |
117 | 117 | ||
118 | static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_id * id) | 118 | static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id) |
119 | { | 119 | { |
120 | struct usb_device * dev = interface_to_usbdev(intf); | 120 | struct usb_device *dev = interface_to_usbdev(intf); |
121 | struct usb_host_interface *interface; | 121 | struct usb_host_interface *interface; |
122 | struct usb_endpoint_descriptor *endpoint; | 122 | struct usb_endpoint_descriptor *endpoint; |
123 | struct usb_mouse *mouse; | 123 | struct usb_mouse *mouse; |
124 | struct input_dev *input_dev; | ||
124 | int pipe, maxp; | 125 | int pipe, maxp; |
125 | char path[64]; | ||
126 | 126 | ||
127 | interface = intf->cur_altsetting; | 127 | interface = intf->cur_altsetting; |
128 | 128 | ||
@@ -130,59 +130,62 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_ | |||
130 | return -ENODEV; | 130 | return -ENODEV; |
131 | 131 | ||
132 | endpoint = &interface->endpoint[0].desc; | 132 | endpoint = &interface->endpoint[0].desc; |
133 | if (!(endpoint->bEndpointAddress & 0x80)) | 133 | if (!(endpoint->bEndpointAddress & USB_DIR_IN)) |
134 | return -ENODEV; | 134 | return -ENODEV; |
135 | if ((endpoint->bmAttributes & 3) != 3) | 135 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != USB_ENDPOINT_XFER_INT) |
136 | return -ENODEV; | 136 | return -ENODEV; |
137 | 137 | ||
138 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); | 138 | pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress); |
139 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); | 139 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); |
140 | 140 | ||
141 | if (!(mouse = kmalloc(sizeof(struct usb_mouse), GFP_KERNEL))) | 141 | mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL); |
142 | return -ENOMEM; | 142 | input_dev = input_allocate_device(); |
143 | memset(mouse, 0, sizeof(struct usb_mouse)); | 143 | if (!mouse || !input_dev) |
144 | goto fail1; | ||
144 | 145 | ||
145 | mouse->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &mouse->data_dma); | 146 | mouse->data = usb_buffer_alloc(dev, 8, SLAB_ATOMIC, &mouse->data_dma); |
146 | if (!mouse->data) { | 147 | if (!mouse->data) |
147 | kfree(mouse); | 148 | goto fail1; |
148 | return -ENOMEM; | ||
149 | } | ||
150 | 149 | ||
151 | mouse->irq = usb_alloc_urb(0, GFP_KERNEL); | 150 | mouse->irq = usb_alloc_urb(0, GFP_KERNEL); |
152 | if (!mouse->irq) { | 151 | if (!mouse->irq) |
153 | usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); | 152 | goto fail2; |
154 | kfree(mouse); | ||
155 | return -ENODEV; | ||
156 | } | ||
157 | 153 | ||
158 | mouse->usbdev = dev; | 154 | mouse->usbdev = dev; |
155 | mouse->dev = input_dev; | ||
156 | |||
157 | if (dev->manufacturer) | ||
158 | strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name)); | ||
159 | 159 | ||
160 | mouse->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_REL); | 160 | if (dev->product) { |
161 | mouse->dev.keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); | 161 | if (dev->manufacturer) |
162 | mouse->dev.relbit[0] = BIT(REL_X) | BIT(REL_Y); | 162 | strlcat(mouse->name, " ", sizeof(mouse->name)); |
163 | mouse->dev.keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); | 163 | strlcat(mouse->name, dev->product, sizeof(mouse->name)); |
164 | mouse->dev.relbit[0] |= BIT(REL_WHEEL); | 164 | } |
165 | 165 | ||
166 | mouse->dev.private = mouse; | 166 | if (!strlen(mouse->name)) |
167 | mouse->dev.open = usb_mouse_open; | 167 | snprintf(mouse->name, sizeof(mouse->name), |
168 | mouse->dev.close = usb_mouse_close; | 168 | "USB HIDBP Mouse %04x:%04x", |
169 | le16_to_cpu(dev->descriptor.idVendor), | ||
170 | le16_to_cpu(dev->descriptor.idProduct)); | ||
169 | 171 | ||
170 | usb_make_path(dev, path, 64); | 172 | usb_make_path(dev, mouse->phys, sizeof(mouse->phys)); |
171 | sprintf(mouse->phys, "%s/input0", path); | 173 | strlcat(mouse->phys, "/input0", sizeof(mouse->phys)); |
172 | 174 | ||
173 | mouse->dev.name = mouse->name; | 175 | input_dev->name = mouse->name; |
174 | mouse->dev.phys = mouse->phys; | 176 | input_dev->phys = mouse->phys; |
175 | usb_to_input_id(dev, &mouse->dev.id); | 177 | usb_to_input_id(dev, &input_dev->id); |
176 | mouse->dev.dev = &intf->dev; | 178 | input_dev->cdev.dev = &intf->dev; |
177 | 179 | ||
178 | if (dev->manufacturer) | 180 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REL); |
179 | strcat(mouse->name, dev->manufacturer); | 181 | input_dev->keybit[LONG(BTN_MOUSE)] = BIT(BTN_LEFT) | BIT(BTN_RIGHT) | BIT(BTN_MIDDLE); |
180 | if (dev->product) | 182 | input_dev->relbit[0] = BIT(REL_X) | BIT(REL_Y); |
181 | sprintf(mouse->name, "%s %s", mouse->name, dev->product); | 183 | input_dev->keybit[LONG(BTN_MOUSE)] |= BIT(BTN_SIDE) | BIT(BTN_EXTRA); |
184 | input_dev->relbit[0] |= BIT(REL_WHEEL); | ||
182 | 185 | ||
183 | if (!strlen(mouse->name)) | 186 | input_dev->private = mouse; |
184 | sprintf(mouse->name, "USB HIDBP Mouse %04x:%04x", | 187 | input_dev->open = usb_mouse_open; |
185 | mouse->dev.id.vendor, mouse->dev.id.product); | 188 | input_dev->close = usb_mouse_close; |
186 | 189 | ||
187 | usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data, | 190 | usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data, |
188 | (maxp > 8 ? 8 : maxp), | 191 | (maxp > 8 ? 8 : maxp), |
@@ -190,11 +193,15 @@ static int usb_mouse_probe(struct usb_interface * intf, const struct usb_device_ | |||
190 | mouse->irq->transfer_dma = mouse->data_dma; | 193 | mouse->irq->transfer_dma = mouse->data_dma; |
191 | mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; | 194 | mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
192 | 195 | ||
193 | input_register_device(&mouse->dev); | 196 | input_register_device(mouse->dev); |
194 | printk(KERN_INFO "input: %s on %s\n", mouse->name, path); | ||
195 | 197 | ||
196 | usb_set_intfdata(intf, mouse); | 198 | usb_set_intfdata(intf, mouse); |
197 | return 0; | 199 | return 0; |
200 | |||
201 | fail2: usb_buffer_free(dev, 8, mouse->data, mouse->data_dma); | ||
202 | fail1: input_free_device(input_dev); | ||
203 | kfree(mouse); | ||
204 | return -ENOMEM; | ||
198 | } | 205 | } |
199 | 206 | ||
200 | static void usb_mouse_disconnect(struct usb_interface *intf) | 207 | static void usb_mouse_disconnect(struct usb_interface *intf) |
@@ -204,7 +211,7 @@ static void usb_mouse_disconnect(struct usb_interface *intf) | |||
204 | usb_set_intfdata(intf, NULL); | 211 | usb_set_intfdata(intf, NULL); |
205 | if (mouse) { | 212 | if (mouse) { |
206 | usb_kill_urb(mouse->irq); | 213 | usb_kill_urb(mouse->irq); |
207 | input_unregister_device(&mouse->dev); | 214 | input_unregister_device(mouse->dev); |
208 | usb_free_urb(mouse->irq); | 215 | usb_free_urb(mouse->irq); |
209 | usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma); | 216 | usb_buffer_free(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma); |
210 | kfree(mouse); | 217 | kfree(mouse); |