diff options
Diffstat (limited to 'drivers/usb/serial/kobil_sct.c')
-rw-r--r-- | drivers/usb/serial/kobil_sct.c | 103 |
1 files changed, 10 insertions, 93 deletions
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c index 903d938e174b..78b48c31abf5 100644 --- a/drivers/usb/serial/kobil_sct.c +++ b/drivers/usb/serial/kobil_sct.c | |||
@@ -65,7 +65,7 @@ static int kobil_tiocmget(struct tty_struct *tty); | |||
65 | static int kobil_tiocmset(struct tty_struct *tty, | 65 | static int kobil_tiocmset(struct tty_struct *tty, |
66 | unsigned int set, unsigned int clear); | 66 | unsigned int set, unsigned int clear); |
67 | static void kobil_read_int_callback(struct urb *urb); | 67 | static void kobil_read_int_callback(struct urb *urb); |
68 | static void kobil_write_callback(struct urb *purb); | 68 | static void kobil_write_int_callback(struct urb *urb); |
69 | static void kobil_set_termios(struct tty_struct *tty, | 69 | static void kobil_set_termios(struct tty_struct *tty, |
70 | struct usb_serial_port *port, struct ktermios *old); | 70 | struct usb_serial_port *port, struct ktermios *old); |
71 | static void kobil_init_termios(struct tty_struct *tty); | 71 | static void kobil_init_termios(struct tty_struct *tty); |
@@ -99,6 +99,7 @@ static struct usb_serial_driver kobil_device = { | |||
99 | .write = kobil_write, | 99 | .write = kobil_write, |
100 | .write_room = kobil_write_room, | 100 | .write_room = kobil_write_room, |
101 | .read_int_callback = kobil_read_int_callback, | 101 | .read_int_callback = kobil_read_int_callback, |
102 | .write_int_callback = kobil_write_int_callback, | ||
102 | }; | 103 | }; |
103 | 104 | ||
104 | static struct usb_serial_driver * const serial_drivers[] = { | 105 | static struct usb_serial_driver * const serial_drivers[] = { |
@@ -106,8 +107,6 @@ static struct usb_serial_driver * const serial_drivers[] = { | |||
106 | }; | 107 | }; |
107 | 108 | ||
108 | struct kobil_private { | 109 | struct kobil_private { |
109 | int write_int_endpoint_address; | ||
110 | int read_int_endpoint_address; | ||
111 | unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */ | 110 | unsigned char buf[KOBIL_BUF_LENGTH]; /* buffer for the APDU to send */ |
112 | int filled; /* index of the last char in buf */ | 111 | int filled; /* index of the last char in buf */ |
113 | int cur_pos; /* index of the next char to send in buf */ | 112 | int cur_pos; /* index of the next char to send in buf */ |
@@ -117,14 +116,8 @@ struct kobil_private { | |||
117 | 116 | ||
118 | static int kobil_port_probe(struct usb_serial_port *port) | 117 | static int kobil_port_probe(struct usb_serial_port *port) |
119 | { | 118 | { |
120 | int i; | ||
121 | struct usb_serial *serial = port->serial; | 119 | struct usb_serial *serial = port->serial; |
122 | struct kobil_private *priv; | 120 | struct kobil_private *priv; |
123 | struct usb_device *pdev; | ||
124 | struct usb_host_config *actconfig; | ||
125 | struct usb_interface *interface; | ||
126 | struct usb_host_interface *altsetting; | ||
127 | struct usb_host_endpoint *endpoint; | ||
128 | 121 | ||
129 | priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL); | 122 | priv = kmalloc(sizeof(struct kobil_private), GFP_KERNEL); |
130 | if (!priv) | 123 | if (!priv) |
@@ -150,30 +143,6 @@ static int kobil_port_probe(struct usb_serial_port *port) | |||
150 | } | 143 | } |
151 | usb_set_serial_port_data(port, priv); | 144 | usb_set_serial_port_data(port, priv); |
152 | 145 | ||
153 | /* search for the necessary endpoints */ | ||
154 | pdev = serial->dev; | ||
155 | actconfig = pdev->actconfig; | ||
156 | interface = actconfig->interface[0]; | ||
157 | altsetting = interface->cur_altsetting; | ||
158 | endpoint = altsetting->endpoint; | ||
159 | |||
160 | for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { | ||
161 | endpoint = &altsetting->endpoint[i]; | ||
162 | if (usb_endpoint_is_int_out(&endpoint->desc)) { | ||
163 | dev_dbg(&serial->dev->dev, | ||
164 | "%s Found interrupt out endpoint. Address: %d\n", | ||
165 | __func__, endpoint->desc.bEndpointAddress); | ||
166 | priv->write_int_endpoint_address = | ||
167 | endpoint->desc.bEndpointAddress; | ||
168 | } | ||
169 | if (usb_endpoint_is_int_in(&endpoint->desc)) { | ||
170 | dev_dbg(&serial->dev->dev, | ||
171 | "%s Found interrupt in endpoint. Address: %d\n", | ||
172 | __func__, endpoint->desc.bEndpointAddress); | ||
173 | priv->read_int_endpoint_address = | ||
174 | endpoint->desc.bEndpointAddress; | ||
175 | } | ||
176 | } | ||
177 | return 0; | 146 | return 0; |
178 | } | 147 | } |
179 | 148 | ||
@@ -205,7 +174,6 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
205 | struct kobil_private *priv; | 174 | struct kobil_private *priv; |
206 | unsigned char *transfer_buffer; | 175 | unsigned char *transfer_buffer; |
207 | int transfer_buffer_length = 8; | 176 | int transfer_buffer_length = 8; |
208 | int write_urb_transfer_buffer_length = 8; | ||
209 | 177 | ||
210 | priv = usb_get_serial_port_data(port); | 178 | priv = usb_get_serial_port_data(port); |
211 | 179 | ||
@@ -214,27 +182,6 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
214 | if (!transfer_buffer) | 182 | if (!transfer_buffer) |
215 | return -ENOMEM; | 183 | return -ENOMEM; |
216 | 184 | ||
217 | /* allocate write_urb */ | ||
218 | if (!port->write_urb) { | ||
219 | dev_dbg(dev, "%s - Allocating port->write_urb\n", __func__); | ||
220 | port->write_urb = usb_alloc_urb(0, GFP_KERNEL); | ||
221 | if (!port->write_urb) { | ||
222 | dev_dbg(dev, "%s - usb_alloc_urb failed\n", __func__); | ||
223 | kfree(transfer_buffer); | ||
224 | return -ENOMEM; | ||
225 | } | ||
226 | } | ||
227 | |||
228 | /* allocate memory for write_urb transfer buffer */ | ||
229 | port->write_urb->transfer_buffer = | ||
230 | kmalloc(write_urb_transfer_buffer_length, GFP_KERNEL); | ||
231 | if (!port->write_urb->transfer_buffer) { | ||
232 | kfree(transfer_buffer); | ||
233 | usb_free_urb(port->write_urb); | ||
234 | port->write_urb = NULL; | ||
235 | return -ENOMEM; | ||
236 | } | ||
237 | |||
238 | /* get hardware version */ | 185 | /* get hardware version */ |
239 | result = usb_control_msg(port->serial->dev, | 186 | result = usb_control_msg(port->serial->dev, |
240 | usb_rcvctrlpipe(port->serial->dev, 0), | 187 | usb_rcvctrlpipe(port->serial->dev, 0), |
@@ -310,12 +257,7 @@ static int kobil_open(struct tty_struct *tty, struct usb_serial_port *port) | |||
310 | static void kobil_close(struct usb_serial_port *port) | 257 | static void kobil_close(struct usb_serial_port *port) |
311 | { | 258 | { |
312 | /* FIXME: Add rts/dtr methods */ | 259 | /* FIXME: Add rts/dtr methods */ |
313 | if (port->write_urb) { | 260 | usb_kill_urb(port->interrupt_out_urb); |
314 | usb_poison_urb(port->write_urb); | ||
315 | kfree(port->write_urb->transfer_buffer); | ||
316 | usb_free_urb(port->write_urb); | ||
317 | port->write_urb = NULL; | ||
318 | } | ||
319 | usb_kill_urb(port->interrupt_in_urb); | 261 | usb_kill_urb(port->interrupt_in_urb); |
320 | } | 262 | } |
321 | 263 | ||
@@ -333,24 +275,8 @@ static void kobil_read_int_callback(struct urb *urb) | |||
333 | } | 275 | } |
334 | 276 | ||
335 | if (urb->actual_length) { | 277 | if (urb->actual_length) { |
336 | 278 | usb_serial_debug_data(&port->dev, __func__, urb->actual_length, | |
337 | /* BEGIN DEBUG */ | 279 | data); |
338 | /* | ||
339 | char *dbg_data; | ||
340 | |||
341 | dbg_data = kzalloc((3 * purb->actual_length + 10) | ||
342 | * sizeof(char), GFP_KERNEL); | ||
343 | if (! dbg_data) { | ||
344 | return; | ||
345 | } | ||
346 | for (i = 0; i < purb->actual_length; i++) { | ||
347 | sprintf(dbg_data +3*i, "%02X ", data[i]); | ||
348 | } | ||
349 | dev_dbg(&port->dev, " <-- %s\n", dbg_data); | ||
350 | kfree(dbg_data); | ||
351 | */ | ||
352 | /* END DEBUG */ | ||
353 | |||
354 | tty_insert_flip_string(&port->port, data, urb->actual_length); | 280 | tty_insert_flip_string(&port->port, data, urb->actual_length); |
355 | tty_flip_buffer_push(&port->port); | 281 | tty_flip_buffer_push(&port->port); |
356 | } | 282 | } |
@@ -360,7 +286,7 @@ static void kobil_read_int_callback(struct urb *urb) | |||
360 | } | 286 | } |
361 | 287 | ||
362 | 288 | ||
363 | static void kobil_write_callback(struct urb *purb) | 289 | static void kobil_write_int_callback(struct urb *urb) |
364 | { | 290 | { |
365 | } | 291 | } |
366 | 292 | ||
@@ -403,23 +329,14 @@ static int kobil_write(struct tty_struct *tty, struct usb_serial_port *port, | |||
403 | 329 | ||
404 | while (todo > 0) { | 330 | while (todo > 0) { |
405 | /* max 8 byte in one urb (endpoint size) */ | 331 | /* max 8 byte in one urb (endpoint size) */ |
406 | length = (todo < 8) ? todo : 8; | 332 | length = min(todo, port->interrupt_out_size); |
407 | /* copy data to transfer buffer */ | 333 | /* copy data to transfer buffer */ |
408 | memcpy(port->write_urb->transfer_buffer, | 334 | memcpy(port->interrupt_out_buffer, |
409 | priv->buf + priv->cur_pos, length); | 335 | priv->buf + priv->cur_pos, length); |
410 | usb_fill_int_urb(port->write_urb, | 336 | port->interrupt_out_urb->transfer_buffer_length = length; |
411 | port->serial->dev, | ||
412 | usb_sndintpipe(port->serial->dev, | ||
413 | priv->write_int_endpoint_address), | ||
414 | port->write_urb->transfer_buffer, | ||
415 | length, | ||
416 | kobil_write_callback, | ||
417 | port, | ||
418 | 8 | ||
419 | ); | ||
420 | 337 | ||
421 | priv->cur_pos = priv->cur_pos + length; | 338 | priv->cur_pos = priv->cur_pos + length; |
422 | result = usb_submit_urb(port->write_urb, GFP_NOIO); | 339 | result = usb_submit_urb(port->interrupt_out_urb, GFP_NOIO); |
423 | dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result); | 340 | dev_dbg(&port->dev, "%s - Send write URB returns: %i\n", __func__, result); |
424 | todo = priv->filled - priv->cur_pos; | 341 | todo = priv->filled - priv->cur_pos; |
425 | 342 | ||