aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/siano/smsusb.c
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2008-06-15 14:14:13 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-07-20 06:21:25 -0400
commit822374165d6b11733467cfa2fa18234319198233 (patch)
treef3e29319e9d1624b8c9ed8d532ec6cab0120679a /drivers/media/dvb/siano/smsusb.c
parent73104fb3e4e692cb1f9505b548ab073b0859b256 (diff)
V4L/DVB (8280): sms1xxx: more codingstyle cleanups
Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb/siano/smsusb.c')
-rw-r--r--drivers/media/dvb/siano/smsusb.c209
1 files changed, 105 insertions, 104 deletions
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index ca9bb36544c0..d9ce3ba0910f 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -57,8 +57,8 @@ typedef struct _smsusb_device
57 57
58 smsusb_urb_t surbs[MAX_URBS]; 58 smsusb_urb_t surbs[MAX_URBS];
59 59
60 int response_alignment; 60 int response_alignment;
61 int buffer_size; 61 int buffer_size;
62} *psmsusb_device_t; 62} *psmsusb_device_t;
63 63
64int smsusb_submit_urb(smsusb_device_t *dev, smsusb_urb_t *surb); 64int smsusb_submit_urb(smsusb_device_t *dev, smsusb_urb_t *surb);
@@ -68,44 +68,50 @@ void smsusb_onresponse(struct urb *urb)
68 smsusb_urb_t *surb = (smsusb_urb_t *) urb->context; 68 smsusb_urb_t *surb = (smsusb_urb_t *) urb->context;
69 smsusb_device_t *dev = surb->dev; 69 smsusb_device_t *dev = surb->dev;
70 70
71 if (urb->status < 0) 71 if (urb->status < 0) {
72 { 72 printk(KERN_INFO "%s error, urb status %d, %d bytes\n",
73 printk(KERN_INFO "%s error, urb status %d, %d bytes\n", __func__, urb->status, urb->actual_length); 73 __func__, urb->status, urb->actual_length);
74 return; 74 return;
75 } 75 }
76 76
77 if (urb->actual_length > 0) 77 if (urb->actual_length > 0) {
78 {
79 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *) surb->cb->p; 78 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *) surb->cb->p;
80 79
81 if (urb->actual_length >= phdr->msgLength) 80 if (urb->actual_length >= phdr->msgLength) {
82 {
83 surb->cb->size = phdr->msgLength; 81 surb->cb->size = phdr->msgLength;
84 82
85 if (dev->response_alignment && (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) 83 if (dev->response_alignment &&
86 { 84 (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) {
87 surb->cb->offset = dev->response_alignment + ((phdr->msgFlags >> 8) & 3); 85
88 86 surb->cb->offset =
89 // sanity check 87 dev->response_alignment +
90 if (((int) phdr->msgLength + surb->cb->offset) > urb->actual_length) 88 ((phdr->msgFlags >> 8) & 3);
91 { 89
92 printk("%s: invalid response msglen %d offset %d size %d\n", __func__, phdr->msgLength, surb->cb->offset, urb->actual_length); 90 /* sanity check */
91 if (((int) phdr->msgLength +
92 surb->cb->offset) > urb->actual_length) {
93 printk(KERN_INFO "%s: invalid "
94 "response msglen %d offset %d "
95 "size %d\n", __func__,
96 phdr->msgLength,
97 surb->cb->offset,
98 urb->actual_length);
93 goto exit_and_resubmit; 99 goto exit_and_resubmit;
94 } 100 }
95 101
96 // move buffer pointer and copy header to its new location 102 /* move buffer pointer and
103 * copy header to its new location */
97 memcpy((char *) phdr + surb->cb->offset, 104 memcpy((char *) phdr + surb->cb->offset,
98 phdr, sizeof(SmsMsgHdr_ST)); 105 phdr, sizeof(SmsMsgHdr_ST));
99 } 106 } else
100 else
101 surb->cb->offset = 0; 107 surb->cb->offset = 0;
102 108
103 smscore_onresponse(dev->coredev, surb->cb); 109 smscore_onresponse(dev->coredev, surb->cb);
104 surb->cb = NULL; 110 surb->cb = NULL;
105 } 111 } else {
106 else 112 printk(KERN_INFO "%s invalid response "
107 { 113 "msglen %d actual %d\n", __func__,
108 printk("%s invalid response msglen %d actual %d\n", __func__, phdr->msgLength, urb->actual_length); 114 phdr->msgLength, urb->actual_length);
109 } 115 }
110 } 116 }
111 117
@@ -115,12 +121,11 @@ exit_and_resubmit:
115 121
116int smsusb_submit_urb(smsusb_device_t *dev, smsusb_urb_t *surb) 122int smsusb_submit_urb(smsusb_device_t *dev, smsusb_urb_t *surb)
117{ 123{
118 if (!surb->cb) 124 if (!surb->cb) {
119 {
120 surb->cb = smscore_getbuffer(dev->coredev); 125 surb->cb = smscore_getbuffer(dev->coredev);
121 if (!surb->cb) 126 if (!surb->cb) {
122 { 127 printk(KERN_INFO "%s smscore_getbuffer(...) "
123 printk(KERN_INFO "%s smscore_getbuffer(...) returned NULL\n", __func__); 128 "returned NULL\n", __func__);
124 return -ENOMEM; 129 return -ENOMEM;
125 } 130 }
126 } 131 }
@@ -144,12 +149,10 @@ void smsusb_stop_streaming(smsusb_device_t *dev)
144{ 149{
145 int i; 150 int i;
146 151
147 for (i = 0; i < MAX_URBS; i ++) 152 for (i = 0; i < MAX_URBS; i ++) {
148 {
149 usb_kill_urb(&dev->surbs[i].urb); 153 usb_kill_urb(&dev->surbs[i].urb);
150 154
151 if (dev->surbs[i].cb) 155 if (dev->surbs[i].cb) {
152 {
153 smscore_putbuffer(dev->coredev, dev->surbs[i].cb); 156 smscore_putbuffer(dev->coredev, dev->surbs[i].cb);
154 dev->surbs[i].cb = NULL; 157 dev->surbs[i].cb = NULL;
155 } 158 }
@@ -160,12 +163,11 @@ int smsusb_start_streaming(smsusb_device_t *dev)
160{ 163{
161 int i, rc; 164 int i, rc;
162 165
163 for (i = 0; i < MAX_URBS; i ++) 166 for (i = 0; i < MAX_URBS; i ++) {
164 {
165 rc = smsusb_submit_urb(dev, &dev->surbs[i]); 167 rc = smsusb_submit_urb(dev, &dev->surbs[i]);
166 if (rc < 0) 168 if (rc < 0) {
167 { 169 printk(KERN_INFO "%s smsusb_submit_urb(...) "
168 printk(KERN_INFO "%s smsusb_submit_urb(...) failed\n", __func__); 170 "failed\n", __func__);
169 smsusb_stop_streaming(dev); 171 smsusb_stop_streaming(dev);
170 break; 172 break;
171 } 173 }
@@ -179,11 +181,11 @@ int smsusb_sendrequest(void *context, void *buffer, size_t size)
179 smsusb_device_t *dev = (smsusb_device_t *) context; 181 smsusb_device_t *dev = (smsusb_device_t *) context;
180 int dummy; 182 int dummy;
181 183
182 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2), buffer, size, &dummy, 1000); 184 return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2),
185 buffer, size, &dummy, 1000);
183} 186}
184 187
185char *smsusb1_fw_lkup[] = 188char *smsusb1_fw_lkup[] = {
186{
187 "dvbt_stellar_usb.inp", 189 "dvbt_stellar_usb.inp",
188 "dvbh_stellar_usb.inp", 190 "dvbh_stellar_usb.inp",
189 "tdmb_stellar_usb.inp", 191 "tdmb_stellar_usb.inp",
@@ -197,32 +199,31 @@ int smsusb1_load_firmware(struct usb_device *udev, int id)
197 u8 *fw_buffer; 199 u8 *fw_buffer;
198 int rc, dummy; 200 int rc, dummy;
199 201
200 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) 202 if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) {
201 { 203 printk(KERN_INFO "%s invalid firmware id specified %d\n",
202 printk(KERN_INFO "%s invalid firmware id specified %d\n", __func__, id); 204 __func__, id);
203 return -EINVAL; 205 return -EINVAL;
204 } 206 }
205 207
206 rc = request_firmware(&fw, smsusb1_fw_lkup[id], &udev->dev); 208 rc = request_firmware(&fw, smsusb1_fw_lkup[id], &udev->dev);
207 if (rc < 0) 209 if (rc < 0) {
208 { 210 printk(KERN_INFO "%s failed to open \"%s\" mode %d\n",
209 printk(KERN_INFO "%s failed to open \"%s\" mode %d\n", __func__, smsusb1_fw_lkup[id], id); 211 __func__, smsusb1_fw_lkup[id], id);
210 return rc; 212 return rc;
211 } 213 }
212 214
213 fw_buffer = kmalloc(fw->size, GFP_KERNEL); 215 fw_buffer = kmalloc(fw->size, GFP_KERNEL);
214 if (fw_buffer) 216 if (fw_buffer) {
215 {
216 memcpy(fw_buffer, fw->data, fw->size); 217 memcpy(fw_buffer, fw->data, fw->size);
217 218
218 rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2), fw_buffer, fw->size, &dummy, 1000); 219 rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2),
220 fw_buffer, fw->size, &dummy, 1000);
219 221
220 printk(KERN_INFO "%s: sent %d(%d) bytes, rc %d\n", __func__, fw->size, dummy, rc); 222 printk(KERN_INFO "%s: sent %d(%d) bytes, rc %d\n",
223 __func__, fw->size, dummy, rc);
221 224
222 kfree(fw_buffer); 225 kfree(fw_buffer);
223 } 226 } else {
224 else
225 {
226 printk(KERN_INFO "failed to allocate firmware buffer\n"); 227 printk(KERN_INFO "failed to allocate firmware buffer\n");
227 rc = -ENOMEM; 228 rc = -ENOMEM;
228 } 229 }
@@ -238,33 +239,29 @@ void smsusb1_detectmode(void *context, int *mode)
238 239
239 *mode = DEVICE_MODE_NONE; 240 *mode = DEVICE_MODE_NONE;
240 241
241 if (!product_string) 242 if (!product_string) {
242 {
243 product_string = "none"; 243 product_string = "none";
244 printk("%s product string not found\n", __func__); 244 printk("%s product string not found\n", __func__);
245 } 245 } else if (strstr(product_string, "DVBH"))
246 else 246 *mode = 1;
247 { 247 else if (strstr(product_string, "BDA"))
248 if (strstr(product_string, "DVBH")) 248 *mode = 4;
249 *mode = 1; 249 else if (strstr(product_string, "DVBT"))
250 else if (strstr(product_string, "BDA")) 250 *mode = 0;
251 *mode = 4; 251 else if (strstr(product_string, "TDMB"))
252 else if (strstr(product_string, "DVBT")) 252 *mode = 2;
253 *mode = 0;
254 else if (strstr(product_string, "TDMB"))
255 *mode = 2;
256 }
257 253
258 printk("%s: %d \"%s\"\n", __func__, *mode, product_string); 254 printk("%s: %d \"%s\"\n", __func__, *mode, product_string);
259} 255}
260 256
261int smsusb1_setmode(void *context, int mode) 257int smsusb1_setmode(void *context, int mode)
262{ 258{
263 SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK, sizeof(SmsMsgHdr_ST), 0 }; 259 SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK,
260 sizeof(SmsMsgHdr_ST), 0 };
264 261
265 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) 262 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
266 { 263 printk(KERN_INFO "%s invalid firmware id specified %d\n",
267 printk(KERN_INFO "%s invalid firmware id specified %d\n", __func__, mode); 264 __func__, mode);
268 return -EINVAL; 265 return -EINVAL;
269 } 266 }
270 267
@@ -275,8 +272,7 @@ void smsusb_term_device(struct usb_interface *intf)
275{ 272{
276 smsusb_device_t *dev = (smsusb_device_t *) usb_get_intfdata(intf); 273 smsusb_device_t *dev = (smsusb_device_t *) usb_get_intfdata(intf);
277 274
278 if (dev) 275 if (dev) {
279 {
280 smsusb_stop_streaming(dev); 276 smsusb_stop_streaming(dev);
281 277
282 // unregister from smscore 278 // unregister from smscore
@@ -299,9 +295,9 @@ int smsusb_init_device(struct usb_interface *intf)
299 295
300 // create device object 296 // create device object
301 dev = kzalloc(sizeof(smsusb_device_t), GFP_KERNEL); 297 dev = kzalloc(sizeof(smsusb_device_t), GFP_KERNEL);
302 if (!dev) 298 if (!dev) {
303 { 299 printk(KERN_INFO "%s kzalloc(sizeof(smsusb_device_t) failed\n",
304 printk(KERN_INFO "%s kzalloc(sizeof(smsusb_device_t) failed\n", __func__); 300 __func__);
305 return -ENOMEM; 301 return -ENOMEM;
306 } 302 }
307 303
@@ -336,7 +332,9 @@ int smsusb_init_device(struct usb_interface *intf)
336 } 332 }
337 333
338 dev->buffer_size = USB2_BUFFER_SIZE; 334 dev->buffer_size = USB2_BUFFER_SIZE;
339 dev->response_alignment = dev->udev->ep_in[1]->desc.wMaxPacketSize - sizeof(SmsMsgHdr_ST); 335 dev->response_alignment =
336 dev->udev->ep_in[1]->desc.wMaxPacketSize -
337 sizeof(SmsMsgHdr_ST);
340 338
341 params.flags |= SMS_DEVICE_FAMILY2; 339 params.flags |= SMS_DEVICE_FAMILY2;
342 break; 340 break;
@@ -347,37 +345,37 @@ int smsusb_init_device(struct usb_interface *intf)
347 params.num_buffers = MAX_BUFFERS; 345 params.num_buffers = MAX_BUFFERS;
348 params.sendrequest_handler = smsusb_sendrequest; 346 params.sendrequest_handler = smsusb_sendrequest;
349 params.context = dev; 347 params.context = dev;
350 snprintf(params.devpath, sizeof(params.devpath), "usb\\%d-%s", dev->udev->bus->busnum, dev->udev->devpath); 348 snprintf(params.devpath, sizeof(params.devpath),
349 "usb\\%d-%s", dev->udev->bus->busnum, dev->udev->devpath);
351 350
352 // register in smscore 351 /* register in smscore */
353 rc = smscore_register_device(&params, &dev->coredev); 352 rc = smscore_register_device(&params, &dev->coredev);
354 if (rc < 0) 353 if (rc < 0) {
355 { 354 printk(KERN_INFO "%s smscore_register_device(...) failed, "
356 printk(KERN_INFO "%s smscore_register_device(...) failed, rc %d\n", __func__, rc); 355 "rc %d\n", __func__, rc);
357 smsusb_term_device(intf); 356 smsusb_term_device(intf);
358 return rc; 357 return rc;
359 } 358 }
360 359
361 // initialize urbs 360 // initialize urbs
362 for (i = 0; i < MAX_URBS; i ++) 361 for (i = 0; i < MAX_URBS; i++) {
363 {
364 dev->surbs[i].dev = dev; 362 dev->surbs[i].dev = dev;
365 usb_init_urb(&dev->surbs[i].urb); 363 usb_init_urb(&dev->surbs[i].urb);
366 } 364 }
367 365
368 printk(KERN_INFO "%s smsusb_start_streaming(...).\n", __func__); 366 printk(KERN_INFO "%s smsusb_start_streaming(...).\n", __func__);
369 rc = smsusb_start_streaming(dev); 367 rc = smsusb_start_streaming(dev);
370 if (rc < 0) 368 if (rc < 0) {
371 { 369 printk(KERN_INFO "%s smsusb_start_streaming(...) failed\n",
372 printk(KERN_INFO "%s smsusb_start_streaming(...) failed\n", __func__); 370 __func__);
373 smsusb_term_device(intf); 371 smsusb_term_device(intf);
374 return rc; 372 return rc;
375 } 373 }
376 374
377 rc = smscore_start_device(dev->coredev); 375 rc = smscore_start_device(dev->coredev);
378 if (rc < 0) 376 if (rc < 0) {
379 { 377 printk(KERN_INFO "%s smscore_start_device(...) failed\n",
380 printk(KERN_INFO "%s smscore_start_device(...) failed\n", __func__); 378 __func__);
381 smsusb_term_device(intf); 379 smsusb_term_device(intf);
382 return rc; 380 return rc;
383 } 381 }
@@ -396,29 +394,32 @@ int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
396 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81)); 394 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
397 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02)); 395 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
398 396
399 if (intf->num_altsetting > 0) 397 if (intf->num_altsetting > 0) {
400 {
401 rc = usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 0); 398 rc = usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 0);
402 if (rc < 0) 399 if (rc < 0) {
403 { 400 printk(KERN_INFO "%s usb_set_interface failed, "
404 printk(KERN_INFO "%s usb_set_interface failed, rc %d\n", __func__, rc); 401 "rc %d\n", __func__, rc);
405 return rc; 402 return rc;
406 } 403 }
407 } 404 }
408 405
409 printk(KERN_INFO "smsusb_probe %d\n", intf->cur_altsetting->desc.bInterfaceNumber); 406 printk(KERN_INFO "smsusb_probe %d\n",
407 intf->cur_altsetting->desc.bInterfaceNumber);
410 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i ++) 408 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i ++)
411 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i, intf->cur_altsetting->endpoint[i].desc.bEndpointAddress, intf->cur_altsetting->endpoint[i].desc.bmAttributes, intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize); 409 printk(KERN_INFO "endpoint %d %02x %02x %d\n", i,
410 intf->cur_altsetting->endpoint[i].desc.bEndpointAddress,
411 intf->cur_altsetting->endpoint[i].desc.bmAttributes,
412 intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize);
412 413
413 if (udev->actconfig->desc.bNumInterfaces == 2 && intf->cur_altsetting->desc.bInterfaceNumber == 0) 414 if ((udev->actconfig->desc.bNumInterfaces == 2) &&
414 { 415 (intf->cur_altsetting->desc.bInterfaceNumber == 0)) {
415 printk(KERN_INFO "rom interface 0 is not used\n"); 416 printk(KERN_INFO "rom interface 0 is not used\n");
416 return -ENODEV; 417 return -ENODEV;
417 } 418 }
418 419
419 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) 420 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) {
420 { 421 snprintf(devpath, sizeof(devpath), "usb\\%d-%s",
421 snprintf(devpath, sizeof(devpath), "usb\\%d-%s", udev->bus->busnum, udev->devpath); 422 udev->bus->busnum, udev->devpath);
422 printk(KERN_INFO "stellar device was found.\n"); 423 printk(KERN_INFO "stellar device was found.\n");
423 return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath)); 424 return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath));
424 } 425 }
@@ -444,7 +445,7 @@ MODULE_DEVICE_TABLE (usb, smsusb_id_table);
444static struct usb_driver smsusb_driver = { 445static struct usb_driver smsusb_driver = {
445 .name = "smsusb", 446 .name = "smsusb",
446 .probe = smsusb_probe, 447 .probe = smsusb_probe,
447 .disconnect = smsusb_disconnect, 448 .disconnect = smsusb_disconnect,
448 .id_table = smsusb_id_table, 449 .id_table = smsusb_id_table,
449}; 450};
450 451