diff options
author | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-09-15 03:01:43 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-10-28 12:52:53 -0400 |
commit | 88789672424375882166df86adde9dd77ead630e (patch) | |
tree | e8276230a2add44082522e94545ccd784b55a554 /drivers/usb/storage/onetouch.c | |
parent | b416f2e452b6c0f5075145bb7301f7f3d44d8ed5 (diff) |
[PATCH] Input: convert onetouch to dynamic input_dev allocation
Input: convert onetouch to dynamic input_dev allocation
This is required for input_dev sysfs integration
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/storage/onetouch.c')
-rw-r--r-- | drivers/usb/storage/onetouch.c | 99 |
1 files changed, 50 insertions, 49 deletions
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c index 2c9402dc702b..89401a59f952 100644 --- a/drivers/usb/storage/onetouch.c +++ b/drivers/usb/storage/onetouch.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu> | 5 | * Copyright (c) 2005 Nick Sillik <n.sillik@temple.edu> |
6 | * | 6 | * |
7 | * Initial work by: | 7 | * Initial work by: |
8 | * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se> | 8 | * Copyright (c) 2003 Erik Thyren <erth7411@student.uu.se> |
9 | * | 9 | * |
10 | * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann) | 10 | * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann) |
11 | * | 11 | * |
@@ -46,7 +46,7 @@ void onetouch_release_input(void *onetouch_); | |||
46 | struct usb_onetouch { | 46 | struct usb_onetouch { |
47 | char name[128]; | 47 | char name[128]; |
48 | char phys[64]; | 48 | char phys[64]; |
49 | struct input_dev dev; /* input device interface */ | 49 | struct input_dev *dev; /* input device interface */ |
50 | struct usb_device *udev; /* usb device */ | 50 | struct usb_device *udev; /* usb device */ |
51 | 51 | ||
52 | struct urb *irq; /* urb for interrupt in report */ | 52 | struct urb *irq; /* urb for interrupt in report */ |
@@ -58,7 +58,7 @@ static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs) | |||
58 | { | 58 | { |
59 | struct usb_onetouch *onetouch = urb->context; | 59 | struct usb_onetouch *onetouch = urb->context; |
60 | signed char *data = onetouch->data; | 60 | signed char *data = onetouch->data; |
61 | struct input_dev *dev = &onetouch->dev; | 61 | struct input_dev *dev = onetouch->dev; |
62 | int status; | 62 | int status; |
63 | 63 | ||
64 | switch (urb->status) { | 64 | switch (urb->status) { |
@@ -74,11 +74,9 @@ static void usb_onetouch_irq(struct urb *urb, struct pt_regs *regs) | |||
74 | } | 74 | } |
75 | 75 | ||
76 | input_regs(dev, regs); | 76 | input_regs(dev, regs); |
77 | 77 | input_report_key(dev, ONETOUCH_BUTTON, data[0] & 0x02); | |
78 | input_report_key(&onetouch->dev, ONETOUCH_BUTTON, | ||
79 | data[0] & 0x02); | ||
80 | |||
81 | input_sync(dev); | 78 | input_sync(dev); |
79 | |||
82 | resubmit: | 80 | resubmit: |
83 | status = usb_submit_urb (urb, SLAB_ATOMIC); | 81 | status = usb_submit_urb (urb, SLAB_ATOMIC); |
84 | if (status) | 82 | if (status) |
@@ -113,8 +111,8 @@ int onetouch_connect_input(struct us_data *ss) | |||
113 | struct usb_host_interface *interface; | 111 | struct usb_host_interface *interface; |
114 | struct usb_endpoint_descriptor *endpoint; | 112 | struct usb_endpoint_descriptor *endpoint; |
115 | struct usb_onetouch *onetouch; | 113 | struct usb_onetouch *onetouch; |
114 | struct input_dev *input_dev; | ||
116 | int pipe, maxp; | 115 | int pipe, maxp; |
117 | char path[64]; | ||
118 | 116 | ||
119 | interface = ss->pusb_intf->cur_altsetting; | 117 | interface = ss->pusb_intf->cur_altsetting; |
120 | 118 | ||
@@ -122,62 +120,62 @@ int onetouch_connect_input(struct us_data *ss) | |||
122 | return -ENODEV; | 120 | return -ENODEV; |
123 | 121 | ||
124 | endpoint = &interface->endpoint[2].desc; | 122 | endpoint = &interface->endpoint[2].desc; |
125 | if(!(endpoint->bEndpointAddress & USB_DIR_IN)) | 123 | if (!(endpoint->bEndpointAddress & USB_DIR_IN)) |
126 | return -ENODEV; | 124 | return -ENODEV; |
127 | if((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) | 125 | if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
128 | != USB_ENDPOINT_XFER_INT) | 126 | != USB_ENDPOINT_XFER_INT) |
129 | return -ENODEV; | 127 | return -ENODEV; |
130 | 128 | ||
131 | pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); | 129 | pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress); |
132 | maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); | 130 | maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe)); |
133 | 131 | ||
134 | if (!(onetouch = kcalloc(1, sizeof(struct usb_onetouch), GFP_KERNEL))) | 132 | onetouch = kzalloc(sizeof(struct usb_onetouch), GFP_KERNEL); |
135 | return -ENOMEM; | 133 | input_dev = input_allocate_device(); |
134 | if (!onetouch || !input_dev) | ||
135 | goto fail1; | ||
136 | 136 | ||
137 | onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, | 137 | onetouch->data = usb_buffer_alloc(udev, ONETOUCH_PKT_LEN, |
138 | SLAB_ATOMIC, &onetouch->data_dma); | 138 | SLAB_ATOMIC, &onetouch->data_dma); |
139 | if (!onetouch->data){ | 139 | if (!onetouch->data) |
140 | kfree(onetouch); | 140 | goto fail1; |
141 | return -ENOMEM; | ||
142 | } | ||
143 | 141 | ||
144 | onetouch->irq = usb_alloc_urb(0, GFP_KERNEL); | 142 | onetouch->irq = usb_alloc_urb(0, GFP_KERNEL); |
145 | if (!onetouch->irq){ | 143 | if (!onetouch->irq) |
146 | kfree(onetouch); | 144 | goto fail2; |
147 | usb_buffer_free(udev, ONETOUCH_PKT_LEN, | ||
148 | onetouch->data, onetouch->data_dma); | ||
149 | return -ENODEV; | ||
150 | } | ||
151 | |||
152 | 145 | ||
153 | onetouch->udev = udev; | 146 | onetouch->udev = udev; |
147 | onetouch->dev = input_dev; | ||
154 | 148 | ||
155 | set_bit(EV_KEY, onetouch->dev.evbit); | 149 | if (udev->manufacturer) |
156 | set_bit(ONETOUCH_BUTTON, onetouch->dev.keybit); | 150 | strlcpy(onetouch->name, udev->manufacturer, |
157 | clear_bit(0, onetouch->dev.keybit); | 151 | sizeof(onetouch->name)); |
152 | if (udev->product) { | ||
153 | if (udev->manufacturer) | ||
154 | strlcat(onetouch->name, " ", sizeof(onetouch->name)); | ||
155 | strlcat(onetouch->name, udev->product, sizeof(onetouch->name)); | ||
156 | } | ||
158 | 157 | ||
159 | onetouch->dev.private = onetouch; | 158 | if (!strlen(onetouch->name)) |
160 | onetouch->dev.open = usb_onetouch_open; | 159 | snprintf(onetouch->name, sizeof(onetouch->name), |
161 | onetouch->dev.close = usb_onetouch_close; | 160 | "Maxtor Onetouch %04x:%04x", |
161 | le16_to_cpu(udev->descriptor.idVendor), | ||
162 | le16_to_cpu(udev->descriptor.idProduct)); | ||
162 | 163 | ||
163 | usb_make_path(udev, path, sizeof(path)); | 164 | usb_make_path(udev, onetouch->phys, sizeof(onetouch->phys)); |
164 | sprintf(onetouch->phys, "%s/input0", path); | 165 | strlcat(onetouch->phys, "/input0", sizeof(onetouch->phys)); |
165 | 166 | ||
166 | onetouch->dev.name = onetouch->name; | 167 | input_dev->name = onetouch->name; |
167 | onetouch->dev.phys = onetouch->phys; | 168 | input_dev->phys = onetouch->phys; |
169 | usb_to_input_id(udev, &input_dev->id); | ||
170 | input_dev->cdev.dev = &udev->dev; | ||
168 | 171 | ||
169 | usb_to_input_id(udev, &onetouch->dev.id); | 172 | set_bit(EV_KEY, input_dev->evbit); |
173 | set_bit(ONETOUCH_BUTTON, input_dev->keybit); | ||
174 | clear_bit(0, input_dev->keybit); | ||
170 | 175 | ||
171 | onetouch->dev.dev = &udev->dev; | 176 | input_dev->private = onetouch; |
172 | 177 | input_dev->open = usb_onetouch_open; | |
173 | if (udev->manufacturer) | 178 | input_dev->close = usb_onetouch_close; |
174 | strcat(onetouch->name, udev->manufacturer); | ||
175 | if (udev->product) | ||
176 | sprintf(onetouch->name, "%s %s", onetouch->name, | ||
177 | udev->product); | ||
178 | if (!strlen(onetouch->name)) | ||
179 | sprintf(onetouch->name, "Maxtor Onetouch %04x:%04x", | ||
180 | onetouch->dev.id.vendor, onetouch->dev.id.product); | ||
181 | 179 | ||
182 | usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, | 180 | usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, |
183 | (maxp > 8 ? 8 : maxp), | 181 | (maxp > 8 ? 8 : maxp), |
@@ -188,10 +186,15 @@ int onetouch_connect_input(struct us_data *ss) | |||
188 | ss->extra_destructor = onetouch_release_input; | 186 | ss->extra_destructor = onetouch_release_input; |
189 | ss->extra = onetouch; | 187 | ss->extra = onetouch; |
190 | 188 | ||
191 | input_register_device(&onetouch->dev); | 189 | input_register_device(onetouch->dev); |
192 | printk(KERN_INFO "usb-input: %s on %s\n", onetouch->dev.name, path); | ||
193 | 190 | ||
194 | return 0; | 191 | return 0; |
192 | |||
193 | fail2: usb_buffer_free(udev, ONETOUCH_PKT_LEN, | ||
194 | onetouch->data, onetouch->data_dma); | ||
195 | fail1: kfree(onetouch); | ||
196 | input_free_device(input_dev); | ||
197 | return -ENOMEM; | ||
195 | } | 198 | } |
196 | 199 | ||
197 | void onetouch_release_input(void *onetouch_) | 200 | void onetouch_release_input(void *onetouch_) |
@@ -200,11 +203,9 @@ void onetouch_release_input(void *onetouch_) | |||
200 | 203 | ||
201 | if (onetouch) { | 204 | if (onetouch) { |
202 | usb_kill_urb(onetouch->irq); | 205 | usb_kill_urb(onetouch->irq); |
203 | input_unregister_device(&onetouch->dev); | 206 | input_unregister_device(onetouch->dev); |
204 | usb_free_urb(onetouch->irq); | 207 | usb_free_urb(onetouch->irq); |
205 | usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN, | 208 | usb_buffer_free(onetouch->udev, ONETOUCH_PKT_LEN, |
206 | onetouch->data, onetouch->data_dma); | 209 | onetouch->data, onetouch->data_dma); |
207 | printk(KERN_INFO "usb-input: deregistering %s\n", | ||
208 | onetouch->dev.name); | ||
209 | } | 210 | } |
210 | } | 211 | } |