aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorJohan Hovold <jhovold@gmail.com>2013-04-16 12:01:28 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-04-17 13:05:35 -0400
commitcced926f0e4fb02a08d2d14e443631fe8a28db98 (patch)
tree3232a31ae7b2b2a67d4f2744901f5de7a06714fe /drivers/usb
parent35807187e4b35200b12edad319a36ee7a0167ba7 (diff)
USB: symbolserial: use port interrupt-in urb
Use the port interrupt-in urb rather managing a private one. Signed-off-by: Johan Hovold <jhovold@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/symbolserial.c102
1 files changed, 12 insertions, 90 deletions
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c
index be05e6caf9a3..32ebddf7f010 100644
--- a/drivers/usb/serial/symbolserial.c
+++ b/drivers/usb/serial/symbolserial.c
@@ -29,13 +29,6 @@ MODULE_DEVICE_TABLE(usb, id_table);
29/* This structure holds all of the individual device information */ 29/* This structure holds all of the individual device information */
30struct symbol_private { 30struct symbol_private {
31 struct usb_device *udev; 31 struct usb_device *udev;
32 struct usb_serial *serial;
33 struct usb_serial_port *port;
34 unsigned char *int_buffer;
35 struct urb *int_urb;
36 int buffer_size;
37 u8 bInterval;
38 u8 int_address;
39 spinlock_t lock; /* protects the following flags */ 32 spinlock_t lock; /* protects the following flags */
40 bool throttled; 33 bool throttled;
41 bool actually_throttled; 34 bool actually_throttled;
@@ -44,9 +37,9 @@ struct symbol_private {
44 37
45static void symbol_int_callback(struct urb *urb) 38static void symbol_int_callback(struct urb *urb)
46{ 39{
47 struct symbol_private *priv = urb->context; 40 struct usb_serial_port *port = urb->context;
41 struct symbol_private *priv = usb_get_serial_data(port->serial);
48 unsigned char *data = urb->transfer_buffer; 42 unsigned char *data = urb->transfer_buffer;
49 struct usb_serial_port *port = priv->port;
50 int status = urb->status; 43 int status = urb->status;
51 int result; 44 int result;
52 int data_length; 45 int data_length;
@@ -94,12 +87,7 @@ exit:
94 87
95 /* Continue trying to always read if we should */ 88 /* Continue trying to always read if we should */
96 if (!priv->throttled) { 89 if (!priv->throttled) {
97 usb_fill_int_urb(priv->int_urb, priv->udev, 90 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
98 usb_rcvintpipe(priv->udev,
99 priv->int_address),
100 priv->int_buffer, priv->buffer_size,
101 symbol_int_callback, priv, priv->bInterval);
102 result = usb_submit_urb(priv->int_urb, GFP_ATOMIC);
103 if (result) 91 if (result)
104 dev_err(&port->dev, 92 dev_err(&port->dev,
105 "%s - failed resubmitting read urb, error %d\n", 93 "%s - failed resubmitting read urb, error %d\n",
@@ -118,15 +106,10 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port)
118 spin_lock_irqsave(&priv->lock, flags); 106 spin_lock_irqsave(&priv->lock, flags);
119 priv->throttled = false; 107 priv->throttled = false;
120 priv->actually_throttled = false; 108 priv->actually_throttled = false;
121 priv->port = port;
122 spin_unlock_irqrestore(&priv->lock, flags); 109 spin_unlock_irqrestore(&priv->lock, flags);
123 110
124 /* Start reading from the device */ 111 /* Start reading from the device */
125 usb_fill_int_urb(priv->int_urb, priv->udev, 112 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
126 usb_rcvintpipe(priv->udev, priv->int_address),
127 priv->int_buffer, priv->buffer_size,
128 symbol_int_callback, priv, priv->bInterval);
129 result = usb_submit_urb(priv->int_urb, GFP_KERNEL);
130 if (result) 113 if (result)
131 dev_err(&port->dev, 114 dev_err(&port->dev,
132 "%s - failed resubmitting read urb, error %d\n", 115 "%s - failed resubmitting read urb, error %d\n",
@@ -136,10 +119,7 @@ static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port)
136 119
137static void symbol_close(struct usb_serial_port *port) 120static void symbol_close(struct usb_serial_port *port)
138{ 121{
139 struct symbol_private *priv = usb_get_serial_data(port->serial); 122 usb_kill_urb(port->interrupt_in_urb);
140
141 /* shutdown our urbs */
142 usb_kill_urb(priv->int_urb);
143} 123}
144 124
145static void symbol_throttle(struct tty_struct *tty) 125static void symbol_throttle(struct tty_struct *tty)
@@ -166,7 +146,7 @@ static void symbol_unthrottle(struct tty_struct *tty)
166 spin_unlock_irq(&priv->lock); 146 spin_unlock_irq(&priv->lock);
167 147
168 if (was_throttled) { 148 if (was_throttled) {
169 result = usb_submit_urb(priv->int_urb, GFP_KERNEL); 149 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
170 if (result) 150 if (result)
171 dev_err(&port->dev, 151 dev_err(&port->dev,
172 "%s - failed submitting read urb, error %d\n", 152 "%s - failed submitting read urb, error %d\n",
@@ -177,10 +157,11 @@ static void symbol_unthrottle(struct tty_struct *tty)
177static int symbol_startup(struct usb_serial *serial) 157static int symbol_startup(struct usb_serial *serial)
178{ 158{
179 struct symbol_private *priv; 159 struct symbol_private *priv;
180 struct usb_host_interface *intf; 160
181 int i; 161 if (!serial->num_interrupt_in) {
182 int retval = -ENOMEM; 162 dev_err(&serial->dev->dev, "no interrupt-in endpoint\n");
183 bool int_in_found = false; 163 return -ENODEV;
164 }
184 165
185 /* create our private serial structure */ 166 /* create our private serial structure */
186 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 167 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -189,75 +170,16 @@ static int symbol_startup(struct usb_serial *serial)
189 return -ENOMEM; 170 return -ENOMEM;
190 } 171 }
191 spin_lock_init(&priv->lock); 172 spin_lock_init(&priv->lock);
192 priv->serial = serial;
193 priv->port = serial->port[0];
194 priv->udev = serial->dev; 173 priv->udev = serial->dev;
195 174
196 /* find our interrupt endpoint */
197 intf = serial->interface->altsetting;
198 for (i = 0; i < intf->desc.bNumEndpoints; ++i) {
199 struct usb_endpoint_descriptor *endpoint;
200
201 endpoint = &intf->endpoint[i].desc;
202 if (!usb_endpoint_is_int_in(endpoint))
203 continue;
204
205 priv->int_urb = usb_alloc_urb(0, GFP_KERNEL);
206 if (!priv->int_urb) {
207 dev_err(&priv->udev->dev, "out of memory\n");
208 goto error;
209 }
210
211 priv->buffer_size = usb_endpoint_maxp(endpoint) * 2;
212 priv->int_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);
213 if (!priv->int_buffer) {
214 dev_err(&priv->udev->dev, "out of memory\n");
215 goto error;
216 }
217
218 priv->int_address = endpoint->bEndpointAddress;
219 priv->bInterval = endpoint->bInterval;
220
221 /* set up our int urb */
222 usb_fill_int_urb(priv->int_urb, priv->udev,
223 usb_rcvintpipe(priv->udev,
224 endpoint->bEndpointAddress),
225 priv->int_buffer, priv->buffer_size,
226 symbol_int_callback, priv, priv->bInterval);
227
228 int_in_found = true;
229 break;
230 }
231
232 if (!int_in_found) {
233 dev_err(&priv->udev->dev,
234 "Error - the proper endpoints were not found!\n");
235 goto error;
236 }
237
238 usb_set_serial_data(serial, priv); 175 usb_set_serial_data(serial, priv);
239 return 0; 176 return 0;
240
241error:
242 usb_free_urb(priv->int_urb);
243 kfree(priv->int_buffer);
244 kfree(priv);
245 return retval;
246}
247
248static void symbol_disconnect(struct usb_serial *serial)
249{
250 struct symbol_private *priv = usb_get_serial_data(serial);
251
252 usb_kill_urb(priv->int_urb);
253 usb_free_urb(priv->int_urb);
254} 177}
255 178
256static void symbol_release(struct usb_serial *serial) 179static void symbol_release(struct usb_serial *serial)
257{ 180{
258 struct symbol_private *priv = usb_get_serial_data(serial); 181 struct symbol_private *priv = usb_get_serial_data(serial);
259 182
260 kfree(priv->int_buffer);
261 kfree(priv); 183 kfree(priv);
262} 184}
263 185
@@ -271,10 +193,10 @@ static struct usb_serial_driver symbol_device = {
271 .attach = symbol_startup, 193 .attach = symbol_startup,
272 .open = symbol_open, 194 .open = symbol_open,
273 .close = symbol_close, 195 .close = symbol_close,
274 .disconnect = symbol_disconnect,
275 .release = symbol_release, 196 .release = symbol_release,
276 .throttle = symbol_throttle, 197 .throttle = symbol_throttle,
277 .unthrottle = symbol_unthrottle, 198 .unthrottle = symbol_unthrottle,
199 .read_int_callback = symbol_int_callback,
278}; 200};
279 201
280static struct usb_serial_driver * const serial_drivers[] = { 202static struct usb_serial_driver * const serial_drivers[] = {