aboutsummaryrefslogtreecommitdiffstats
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
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>
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c651
-rw-r--r--drivers/media/dvb/siano/smscoreapi.h394
-rw-r--r--drivers/media/dvb/siano/smsdvb.c175
-rw-r--r--drivers/media/dvb/siano/smsusb.c209
4 files changed, 714 insertions, 715 deletions
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index 41c63e5622d8..ba72daf5ced0 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -33,23 +33,23 @@
33 33
34#include "smscoreapi.h" 34#include "smscoreapi.h"
35 35
36#define PERROR(fmt, args...) printk( KERN_ERR "smscore error: line %d- %s(): " fmt,__LINE__, __func__, ## args) 36#define PERROR(fmt, args...)\
37 printk(KERN_ERR "smscore error: line %d- %s(): " fmt, \
38 __LINE__, __func__, ## args)
37 39
38#ifdef SMSCORE_DEBUG 40#ifdef SMSCORE_DEBUG
39
40#undef PWARNING 41#undef PWARNING
41# define PWARNING(fmt, args...) printk( KERN_INFO "smscore warning: line %d- %s(): " fmt,__LINE__, __func__, ## args) 42# define PWARNING(fmt, args...) printk(KERN_INFO "smscore warning: " \
43 "line %d- %s(): " fmt, \
44 __LINE__, __func__, ## args)
42#undef PDEBUG /* undef it, just in case */ 45#undef PDEBUG /* undef it, just in case */
43# define PDEBUG(fmt, args...) printk( KERN_INFO "smscore - %s(): " fmt, __func__, ## args) 46# define PDEBUG(fmt, args...) printk(KERN_INFO "smscore - %s(): " fmt, \
44 47 __func__, ## args)
45#else /*SMSCORE_DEBUG*/ 48#else /*SMSCORE_DEBUG*/
46
47#define PDEBUG(fmt, args...) 49#define PDEBUG(fmt, args...)
48#define PWARNING(fmt, args...) 50#define PWARNING(fmt, args...)
49
50#endif 51#endif
51 52
52
53typedef struct _smscore_device_notifyee 53typedef struct _smscore_device_notifyee
54{ 54{
55 struct list_head entry; 55 struct list_head entry;
@@ -129,100 +129,86 @@ static int default_mode = 1;
129module_param(default_mode, int, 0644); 129module_param(default_mode, int, 0644);
130MODULE_PARM_DESC(default_mode, "default firmware id (device mode)"); 130MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
131 131
132static smscore_registry_entry_t *smscore_find_registry ( char *devpath ) 132static smscore_registry_entry_t *smscore_find_registry(char *devpath)
133{ 133{
134 smscore_registry_entry_t *entry; 134 smscore_registry_entry_t *entry;
135 struct list_head *next; 135 struct list_head *next;
136 136
137 kmutex_lock(&g_smscore_registrylock); 137 kmutex_lock(&g_smscore_registrylock);
138 for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) 138 for (next = g_smscore_registry.next;
139 { 139 next != &g_smscore_registry;
140 next = next->next) {
140 entry = (smscore_registry_entry_t *) next; 141 entry = (smscore_registry_entry_t *) next;
141 if (!strcmp(entry->devpath, devpath)) 142 if (!strcmp(entry->devpath, devpath)) {
142 {
143 kmutex_unlock(&g_smscore_registrylock); 143 kmutex_unlock(&g_smscore_registrylock);
144 return entry; 144 return entry;
145 } 145 }
146 } 146 }
147 entry = (smscore_registry_entry_t *) kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL); 147 entry = (smscore_registry_entry_t *)
148 if (entry) 148 kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL);
149 { 149 if (entry) {
150 entry->mode = default_mode; 150 entry->mode = default_mode;
151 strcpy(entry->devpath, devpath); 151 strcpy(entry->devpath, devpath);
152 list_add(&entry->entry, &g_smscore_registry); 152 list_add(&entry->entry, &g_smscore_registry);
153 } 153 } else
154 else 154 printk(KERN_ERR "%s failed to create smscore_registry.\n",
155 printk ( KERN_ERR "%s failed to create smscore_registry.\n", __func__ ); 155 __func__);
156 kmutex_unlock(&g_smscore_registrylock); 156 kmutex_unlock(&g_smscore_registrylock);
157 return entry; 157 return entry;
158} 158}
159 159
160int smscore_registry_getmode ( char *devpath ) 160int smscore_registry_getmode(char *devpath)
161{ 161{
162 smscore_registry_entry_t *entry; 162 smscore_registry_entry_t *entry;
163 163
164 entry = smscore_find_registry ( devpath ); 164 entry = smscore_find_registry(devpath);
165 if ( entry ) 165 if (entry)
166 {
167 return entry->mode; 166 return entry->mode;
168 }
169 else 167 else
170 { 168 printk(KERN_ERR "%s No registry found.\n", __func__);
171 printk ( KERN_ERR "%s No registry found.\n", __func__ ); 169
172 }
173 return default_mode; 170 return default_mode;
174} 171}
175 172
176sms_device_type_st smscore_registry_gettype ( char *devpath ) 173sms_device_type_st smscore_registry_gettype(char *devpath)
177{ 174{
178 smscore_registry_entry_t *entry; 175 smscore_registry_entry_t *entry;
179 176
180 entry = smscore_find_registry ( devpath ); 177 entry = smscore_find_registry(devpath);
181 if ( entry ) 178 if (entry)
182 {
183 return entry->type; 179 return entry->type;
184 }
185 else 180 else
186 { 181 printk(KERN_ERR "%s No registry found.\n", __func__);
187 printk ( KERN_ERR "%s No registry found.\n", __func__ ); 182
188 }
189 return -1; 183 return -1;
190} 184}
191 185
192void smscore_registry_setmode ( char *devpath, int mode ) 186void smscore_registry_setmode(char *devpath, int mode)
193 { 187{
194 smscore_registry_entry_t *entry; 188 smscore_registry_entry_t *entry;
195 189
196 entry = smscore_find_registry ( devpath ); 190 entry = smscore_find_registry(devpath);
197 if ( entry ) 191 if (entry)
198 { 192 entry->mode = mode;
199 entry->mode = mode;
200 }
201 else 193 else
202 { 194 printk(KERN_ERR "%s No registry found.\n", __func__);
203 printk ( KERN_ERR "%s No registry found.\n", __func__ ); 195}
204 }
205 }
206 196
207void smscore_registry_settype ( char *devpath, sms_device_type_st type ) 197void smscore_registry_settype(char *devpath, sms_device_type_st type)
208{ 198{
209 smscore_registry_entry_t *entry; 199 smscore_registry_entry_t *entry;
210 200
211 entry = smscore_find_registry ( devpath ); 201 entry = smscore_find_registry(devpath);
212 if ( entry ) 202 if (entry)
213 {
214 entry->type = type; 203 entry->type = type;
215 }
216 else 204 else
217 { 205 printk(KERN_ERR "%s No registry found.\n", __func__);
218 printk ( KERN_ERR "%s No registry found.\n", __func__ );
219}
220} 206}
221 207
222 208
223 209
224void list_add_locked(struct list_head *new, struct list_head *head, 210void list_add_locked(struct list_head *new, struct list_head *head,
225 spinlock_t *lock) 211 spinlock_t *lock)
226{ 212{
227 unsigned long flags; 213 unsigned long flags;
228 214
@@ -250,25 +236,22 @@ int smscore_register_hotplug(hotplug_t hotplug)
250 kmutex_lock(&g_smscore_deviceslock); 236 kmutex_lock(&g_smscore_deviceslock);
251 237
252 notifyee = kmalloc(sizeof(smscore_device_notifyee_t), GFP_KERNEL); 238 notifyee = kmalloc(sizeof(smscore_device_notifyee_t), GFP_KERNEL);
253 if (notifyee) 239 if (notifyee) {
254 { 240 /* now notify callback about existing devices */
255 // now notify callback about existing devices
256 first = &g_smscore_devices; 241 first = &g_smscore_devices;
257 for (next = first->next; next != first && !rc; next = next->next) 242 for (next = first->next;
258 { 243 next != first && !rc;
244 next = next->next) {
259 smscore_device_t *coredev = (smscore_device_t *) next; 245 smscore_device_t *coredev = (smscore_device_t *) next;
260 rc = hotplug(coredev, coredev->device, 1); 246 rc = hotplug(coredev, coredev->device, 1);
261 } 247 }
262 248
263 if (rc >= 0) 249 if (rc >= 0) {
264 {
265 notifyee->hotplug = hotplug; 250 notifyee->hotplug = hotplug;
266 list_add(&notifyee->entry, &g_smscore_notifyees); 251 list_add(&notifyee->entry, &g_smscore_notifyees);
267 } 252 } else
268 else
269 kfree(notifyee); 253 kfree(notifyee);
270 } 254 } else
271 else
272 rc = -ENOMEM; 255 rc = -ENOMEM;
273 256
274 kmutex_unlock(&g_smscore_deviceslock); 257 kmutex_unlock(&g_smscore_deviceslock);
@@ -290,13 +273,12 @@ void smscore_unregister_hotplug(hotplug_t hotplug)
290 273
291 first = &g_smscore_notifyees; 274 first = &g_smscore_notifyees;
292 275
293 for (next = first->next; next != first;) 276 for (next = first->next; next != first;) {
294 { 277 smscore_device_notifyee_t *notifyee =
295 smscore_device_notifyee_t *notifyee = (smscore_device_notifyee_t *) next; 278 (smscore_device_notifyee_t *) next;
296 next = next->next; 279 next = next->next;
297 280
298 if (notifyee->hotplug == hotplug) 281 if (notifyee->hotplug == hotplug) {
299 {
300 list_del(&notifyee->entry); 282 list_del(&notifyee->entry);
301 kfree(notifyee); 283 kfree(notifyee);
302 } 284 }
@@ -309,25 +291,24 @@ void smscore_notify_clients(smscore_device_t *coredev)
309{ 291{
310 smscore_client_t *client; 292 smscore_client_t *client;
311 293
312 // the client must call smscore_unregister_client from remove handler 294 /* the client must call smscore_unregister_client from remove handler */
313 while (!list_empty(&coredev->clients)) 295 while (!list_empty(&coredev->clients)) {
314 {
315 client = (smscore_client_t *) coredev->clients.next; 296 client = (smscore_client_t *) coredev->clients.next;
316 client->onremove_handler(client->context); 297 client->onremove_handler(client->context);
317 } 298 }
318} 299}
319 300
320int smscore_notify_callbacks(smscore_device_t *coredev, struct device *device, int arrival) 301int smscore_notify_callbacks(smscore_device_t *coredev, struct device *device,
302 int arrival)
321{ 303{
322 struct list_head *next, *first; 304 struct list_head *next, *first;
323 int rc = 0; 305 int rc = 0;
324 306
325 // note: must be called under g_deviceslock 307 /* note: must be called under g_deviceslock */
326 308
327 first = &g_smscore_notifyees; 309 first = &g_smscore_notifyees;
328 310
329 for (next = first->next; next != first; next = next->next) 311 for (next = first->next; next != first; next = next->next) {
330 {
331 rc = ((smscore_device_notifyee_t *) next)->hotplug(coredev, device, arrival); 312 rc = ((smscore_device_notifyee_t *) next)->hotplug(coredev, device, arrival);
332 if (rc < 0) 313 if (rc < 0)
333 break; 314 break;
@@ -340,8 +321,7 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
340 dma_addr_t common_buffer_phys) 321 dma_addr_t common_buffer_phys)
341{ 322{
342 smscore_buffer_t *cb = kmalloc(sizeof(smscore_buffer_t), GFP_KERNEL); 323 smscore_buffer_t *cb = kmalloc(sizeof(smscore_buffer_t), GFP_KERNEL);
343 if (!cb) 324 if (!cb) {
344 {
345 printk(KERN_INFO "%s kmalloc(...) failed\n", __func__); 325 printk(KERN_INFO "%s kmalloc(...) failed\n", __func__);
346 return NULL; 326 return NULL;
347 } 327 }
@@ -354,38 +334,38 @@ smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
354} 334}
355 335
356/** 336/**
357 * creates coredev object for a device, prepares buffers, creates buffer mappings, notifies 337 * creates coredev object for a device, prepares buffers,
358 * registered hotplugs about new device. 338 * creates buffer mappings, notifies registered hotplugs about new device.
359 * 339 *
360 * @param params device pointer to struct with device specific parameters and handlers 340 * @param params device pointer to struct with device specific parameters and handlers
361 * @param coredev pointer to a value that receives created coredev object 341 * @param coredev pointer to a value that receives created coredev object
362 * 342 *
363 * @return 0 on success, <0 on error. 343 * @return 0 on success, <0 on error.
364 */ 344 */
365int smscore_register_device(smsdevice_params_t *params, smscore_device_t **coredev) 345int smscore_register_device(smsdevice_params_t *params,
346 smscore_device_t **coredev)
366{ 347{
367 smscore_device_t *dev; 348 smscore_device_t *dev;
368 u8 *buffer; 349 u8 *buffer;
369 350
370 dev = kzalloc(sizeof(smscore_device_t), GFP_KERNEL); 351 dev = kzalloc(sizeof(smscore_device_t), GFP_KERNEL);
371 if (!dev) 352 if (!dev) {
372 {
373 printk(KERN_INFO "%s kzalloc(...) failed\n", __func__); 353 printk(KERN_INFO "%s kzalloc(...) failed\n", __func__);
374 return -ENOMEM; 354 return -ENOMEM;
375 } 355 }
376 356
377 // init list entry so it could be safe in smscore_unregister_device 357 /* init list entry so it could be safe in smscore_unregister_device */
378 INIT_LIST_HEAD(&dev->entry); 358 INIT_LIST_HEAD(&dev->entry);
379 359
380 // init queues 360 /* init queues */
381 INIT_LIST_HEAD(&dev->clients); 361 INIT_LIST_HEAD(&dev->clients);
382 INIT_LIST_HEAD(&dev->buffers); 362 INIT_LIST_HEAD(&dev->buffers);
383 363
384 // init locks 364 /* init locks */
385 spin_lock_init(&dev->clientslock); 365 spin_lock_init(&dev->clientslock);
386 spin_lock_init(&dev->bufferslock); 366 spin_lock_init(&dev->bufferslock);
387 367
388 // init completion events 368 /* init completion events */
389 init_completion(&dev->version_ex_done); 369 init_completion(&dev->version_ex_done);
390 init_completion(&dev->data_download_done); 370 init_completion(&dev->data_download_done);
391 init_completion(&dev->trigger_done); 371 init_completion(&dev->trigger_done);
@@ -393,21 +373,22 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
393 init_completion(&dev->reload_start_done); 373 init_completion(&dev->reload_start_done);
394 init_completion(&dev->resume_done); 374 init_completion(&dev->resume_done);
395 375
396 // alloc common buffer 376 /* alloc common buffer */
397 dev->common_buffer_size = params->buffer_size * params->num_buffers; 377 dev->common_buffer_size = params->buffer_size * params->num_buffers;
398 dev->common_buffer = dma_alloc_coherent(NULL, dev->common_buffer_size, &dev->common_buffer_phys, GFP_KERNEL | GFP_DMA); 378 dev->common_buffer = dma_alloc_coherent(NULL, dev->common_buffer_size,
399 if (!dev->common_buffer) 379 &dev->common_buffer_phys,
400 { 380 GFP_KERNEL | GFP_DMA);
381 if (!dev->common_buffer) {
401 smscore_unregister_device(dev); 382 smscore_unregister_device(dev);
402 return -ENOMEM; 383 return -ENOMEM;
403 } 384 }
404 385
405 // prepare dma buffers 386 /* prepare dma buffers */
406 for (buffer = dev->common_buffer; dev->num_buffers < params->num_buffers; dev->num_buffers ++, buffer += params->buffer_size) 387 for (buffer = dev->common_buffer;
407 { 388 dev->num_buffers < params->num_buffers;
389 dev->num_buffers ++, buffer += params->buffer_size) {
408 smscore_buffer_t *cb = smscore_createbuffer(buffer, dev->common_buffer, dev->common_buffer_phys); 390 smscore_buffer_t *cb = smscore_createbuffer(buffer, dev->common_buffer, dev->common_buffer_phys);
409 if (!cb) 391 if (!cb) {
410 {
411 smscore_unregister_device(dev); 392 smscore_unregister_device(dev);
412 return -ENOMEM; 393 return -ENOMEM;
413 } 394 }
@@ -415,7 +396,8 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
415 smscore_putbuffer(dev, cb); 396 smscore_putbuffer(dev, cb);
416 } 397 }
417 398
418 printk(KERN_INFO "%s allocated %d buffers\n", __func__, dev->num_buffers); 399 printk(KERN_INFO "%s allocated %d buffers\n",
400 __func__, dev->num_buffers);
419 401
420 dev->mode = DEVICE_MODE_NONE; 402 dev->mode = DEVICE_MODE_NONE;
421 dev->context = params->context; 403 dev->context = params->context;
@@ -429,9 +411,9 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
429 dev->device_flags = params->flags; 411 dev->device_flags = params->flags;
430 strcpy(dev->devpath, params->devpath); 412 strcpy(dev->devpath, params->devpath);
431 413
432 smscore_registry_settype ( dev->devpath, params->device_type ); 414 smscore_registry_settype(dev->devpath, params->device_type);
433 415
434 // add device to devices list 416 /* add device to devices list */
435 kmutex_lock(&g_smscore_deviceslock); 417 kmutex_lock(&g_smscore_deviceslock);
436 list_add(&dev->entry, &g_smscore_devices); 418 list_add(&dev->entry, &g_smscore_devices);
437 kmutex_unlock(&g_smscore_deviceslock); 419 kmutex_unlock(&g_smscore_deviceslock);
@@ -453,9 +435,8 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
453int smscore_start_device(smscore_device_t *coredev) 435int smscore_start_device(smscore_device_t *coredev)
454{ 436{
455 int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath)); 437 int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath));
456 if (rc < 0) 438 if (rc < 0) {
457 { 439 printk(KERN_INFO "%s set device mode faile , rc %d\n", __func__, rc);
458 printk ( KERN_INFO "%s set device mode faile , rc %d\n", __func__, rc );
459 return rc; 440 return rc;
460 } 441 }
461 442
@@ -463,7 +444,8 @@ int smscore_start_device(smscore_device_t *coredev)
463 444
464 rc = smscore_notify_callbacks(coredev, coredev->device, 1); 445 rc = smscore_notify_callbacks(coredev, coredev->device, 1);
465 446
466 printk(KERN_INFO "%s device %p started, rc %d\n", __func__, coredev, rc); 447 printk(KERN_INFO "%s device %p started, rc %d\n",
448 __func__, coredev, rc);
467 449
468 kmutex_unlock(&g_smscore_deviceslock); 450 kmutex_unlock(&g_smscore_deviceslock);
469 451
@@ -471,44 +453,49 @@ int smscore_start_device(smscore_device_t *coredev)
471} 453}
472 454
473int smscore_sendrequest_and_wait(smscore_device_t *coredev, void *buffer, 455int smscore_sendrequest_and_wait(smscore_device_t *coredev, void *buffer,
474 size_t size, struct completion *completion) 456 size_t size, struct completion *completion)
475{ 457{
476 int rc = coredev->sendrequest_handler(coredev->context, buffer, size); 458 int rc = coredev->sendrequest_handler(coredev->context, buffer, size);
477 if (rc < 0) 459 if (rc < 0) {
478 { 460 printk(KERN_INFO "%s sendrequest returned error %d\n",
479 printk(KERN_INFO "%s sendrequest returned error %d\n", __func__, rc); 461 __func__, rc);
480 return rc; 462 return rc;
481 } 463 }
482 464
483 return wait_for_completion_timeout(completion, msecs_to_jiffies(10000)) ? 0 : -ETIME; 465 return wait_for_completion_timeout(completion,
466 msecs_to_jiffies(10000)) ?
467 0 : -ETIME;
484} 468}
485 469
486int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_t size) 470int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer,
471 size_t size)
487{ 472{
488 SmsFirmware_ST* firmware = (SmsFirmware_ST*) buffer; 473 SmsFirmware_ST *firmware = (SmsFirmware_ST *) buffer;
489 SmsMsgHdr_ST *msg; 474 SmsMsgHdr_ST *msg;
490 UINT32 mem_address = firmware->StartAddress; 475 UINT32 mem_address = firmware->StartAddress;
491 u8 *payload = firmware->Payload; 476 u8 *payload = firmware->Payload;
492 int rc = 0; 477 int rc = 0;
493 478
494 printk(KERN_INFO "%s loading FW to addr 0x%x size %d\n", __func__, mem_address,firmware->Length); 479 printk(KERN_INFO "%s loading FW to addr 0x%x size %d\n",
495 if (coredev->preload_handler) 480 __func__, mem_address, firmware->Length);
496 { 481 if (coredev->preload_handler) {
497 rc = coredev->preload_handler(coredev->context); 482 rc = coredev->preload_handler(coredev->context);
498 if (rc < 0) 483 if (rc < 0)
499 return rc; 484 return rc;
500 } 485 }
501 486
502 // PAGE_SIZE buffer shall be enough and dma aligned 487 /* PAGE_SIZE buffer shall be enough and dma aligned */
503 msg = (SmsMsgHdr_ST *) kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA); 488 msg = (SmsMsgHdr_ST *) kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
504 if (!msg) 489 if (!msg)
505 return -ENOMEM; 490 return -ENOMEM;
506 491
507 if (coredev->mode != DEVICE_MODE_NONE) 492 if (coredev->mode != DEVICE_MODE_NONE) {
508 {
509 PDEBUG("Sending reload command\n"); 493 PDEBUG("Sending reload command\n");
510 SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, sizeof(SmsMsgHdr_ST)); 494 SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ,
511 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->reload_start_done); 495 sizeof(SmsMsgHdr_ST));
496 rc = smscore_sendrequest_and_wait(coredev, msg,
497 msg->msgLength,
498 &coredev->reload_start_done);
512 mem_address = *(UINT32*) &payload[20]; 499 mem_address = *(UINT32*) &payload[20];
513 } 500 }
514 501
@@ -517,12 +504,15 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
517 SmsDataDownload_ST *DataMsg = (SmsDataDownload_ST *) msg; 504 SmsDataDownload_ST *DataMsg = (SmsDataDownload_ST *) msg;
518 int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE); 505 int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE);
519 506
520 SMS_INIT_MSG(msg, MSG_SMS_DATA_DOWNLOAD_REQ, (UINT16)(sizeof(SmsMsgHdr_ST) + sizeof(UINT32) + payload_size)); 507 SMS_INIT_MSG(msg, MSG_SMS_DATA_DOWNLOAD_REQ,
508 (UINT16)(sizeof(SmsMsgHdr_ST) +
509 sizeof(UINT32) + payload_size));
521 510
522 DataMsg->MemAddr = mem_address; 511 DataMsg->MemAddr = mem_address;
523 memcpy(DataMsg->Payload, payload, payload_size); 512 memcpy(DataMsg->Payload, payload, payload_size);
524 513
525 if (coredev->device_flags & SMS_ROM_NO_RESPONSE && coredev->mode == DEVICE_MODE_NONE) 514 if ((coredev->device_flags & SMS_ROM_NO_RESPONSE) &&
515 (coredev->mode == DEVICE_MODE_NONE))
526 rc = coredev->sendrequest_handler(coredev->context, DataMsg, DataMsg->xMsgHeader.msgLength); 516 rc = coredev->sendrequest_handler(coredev->context, DataMsg, DataMsg->xMsgHeader.msgLength);
527 else 517 else
528 rc = smscore_sendrequest_and_wait(coredev, DataMsg, DataMsg->xMsgHeader.msgLength, &coredev->data_download_done); 518 rc = smscore_sendrequest_and_wait(coredev, DataMsg, DataMsg->xMsgHeader.msgLength, &coredev->data_download_done);
@@ -532,13 +522,13 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
532 mem_address += payload_size; 522 mem_address += payload_size;
533 } 523 }
534 524
535 if (rc >= 0) 525 if (rc >= 0) {
536 { 526 if (coredev->mode == DEVICE_MODE_NONE) {
537 if (coredev->mode == DEVICE_MODE_NONE) 527 SmsMsgData_ST *TriggerMsg = (SmsMsgData_ST *) msg;
538 {
539 SmsMsgData_ST* TriggerMsg = (SmsMsgData_ST*) msg;
540 528
541 SMS_INIT_MSG(msg, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ, sizeof(SmsMsgHdr_ST) + sizeof(UINT32) * 5); 529 SMS_INIT_MSG(msg, MSG_SMS_SWDOWNLOAD_TRIGGER_REQ,
530 sizeof(SmsMsgHdr_ST) +
531 sizeof(UINT32) * 5);
542 532
543 TriggerMsg->msgData[0] = firmware->StartAddress; // Entry point 533 TriggerMsg->msgData[0] = firmware->StartAddress; // Entry point
544 TriggerMsg->msgData[1] = 5; // Priority 534 TriggerMsg->msgData[1] = 5; // Priority
@@ -546,24 +536,23 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
546 TriggerMsg->msgData[3] = 0; // Parameter 536 TriggerMsg->msgData[3] = 0; // Parameter
547 TriggerMsg->msgData[4] = 4; // Task ID 537 TriggerMsg->msgData[4] = 4; // Task ID
548 538
549 if (coredev->device_flags & SMS_ROM_NO_RESPONSE) 539 if (coredev->device_flags & SMS_ROM_NO_RESPONSE) {
550 {
551 rc = coredev->sendrequest_handler(coredev->context, TriggerMsg, TriggerMsg->xMsgHeader.msgLength); 540 rc = coredev->sendrequest_handler(coredev->context, TriggerMsg, TriggerMsg->xMsgHeader.msgLength);
552 msleep(100); 541 msleep(100);
553 } 542 } else
554 else
555 rc = smscore_sendrequest_and_wait(coredev, TriggerMsg, TriggerMsg->xMsgHeader.msgLength, &coredev->trigger_done); 543 rc = smscore_sendrequest_and_wait(coredev, TriggerMsg, TriggerMsg->xMsgHeader.msgLength, &coredev->trigger_done);
556 } 544 } else {
557 else 545 SMS_INIT_MSG(msg, MSG_SW_RELOAD_EXEC_REQ,
558 { 546 sizeof(SmsMsgHdr_ST));
559 SMS_INIT_MSG(msg, MSG_SW_RELOAD_EXEC_REQ, sizeof(SmsMsgHdr_ST));
560 547
561 rc = coredev->sendrequest_handler(coredev->context, msg, msg->msgLength); 548 rc = coredev->sendrequest_handler(coredev->context,
549 msg, msg->msgLength);
562 } 550 }
563 msleep ( 500 ); 551 msleep(500);
564 } 552 }
565 553
566 printk("%s rc=%d, postload=%p \n", __func__, rc, coredev->postload_handler); 554 printk("%s rc=%d, postload=%p \n", __func__, rc,
555 coredev->postload_handler);
567 556
568 kfree(msg); 557 kfree(msg);
569 558
@@ -581,37 +570,39 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
581 * 570 *
582 * @return 0 on success, <0 on error. 571 * @return 0 on success, <0 on error.
583 */ 572 */
584int smscore_load_firmware_from_file(smscore_device_t *coredev, char *filename, loadfirmware_t loadfirmware_handler) 573int smscore_load_firmware_from_file(smscore_device_t *coredev, char *filename,
574 loadfirmware_t loadfirmware_handler)
585{ 575{
586 int rc = -ENOENT; 576 int rc = -ENOENT;
587 577
588 const struct firmware *fw; 578 const struct firmware *fw;
589 u8 *fw_buffer; 579 u8 *fw_buffer;
590 580
591 if (loadfirmware_handler == NULL && !(coredev->device_flags & SMS_DEVICE_FAMILY2)) 581 if (loadfirmware_handler == NULL && !(coredev->device_flags &
582 SMS_DEVICE_FAMILY2))
592 return -EINVAL; 583 return -EINVAL;
593 584
594 rc = request_firmware(&fw, filename, coredev->device); 585 rc = request_firmware(&fw, filename, coredev->device);
595 if (rc < 0) 586 if (rc < 0) {
596 { 587 printk(KERN_INFO "%s failed to open \"%s\"\n",
597 printk(KERN_INFO "%s failed to open \"%s\"\n", __func__, filename); 588 __func__, filename);
598 return rc; 589 return rc;
599 } 590 }
600 printk(KERN_INFO "%s read FW %s, size=%d\"\n", __func__, filename, fw->size); 591 printk(KERN_INFO "%s read FW %s, size=%d\"\n", __func__,
601 fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA); 592 filename, fw->size);
602 if (fw_buffer) 593 fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT),
603 { 594 GFP_KERNEL | GFP_DMA);
595 if (fw_buffer) {
604 memcpy(fw_buffer, fw->data, fw->size); 596 memcpy(fw_buffer, fw->data, fw->size);
605 597
606 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ? 598 rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
607 smscore_load_firmware_family2(coredev, fw_buffer, fw->size) : 599 smscore_load_firmware_family2(coredev, fw_buffer, fw->size) :
608 loadfirmware_handler(coredev->context, fw_buffer, fw->size); 600 loadfirmware_handler(coredev->context, fw_buffer, fw->size);
609 601
610 kfree(fw_buffer); 602 kfree(fw_buffer);
611 } 603 } else {
612 else 604 printk(KERN_INFO "%s failed to allocate firmware buffer\n",
613 { 605 __func__);
614 printk(KERN_INFO "%s failed to allocate firmware buffer\n", __func__);
615 rc = -ENOMEM; 606 rc = -ENOMEM;
616 } 607 }
617 608
@@ -620,7 +611,8 @@ int smscore_load_firmware_from_file(smscore_device_t *coredev, char *filename, l
620 return rc; 611 return rc;
621} 612}
622 613
623int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8 *buffer, int size, int new_mode) 614int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8 *buffer,
615 int size, int new_mode)
624{ 616{
625 PERROR("Feature not implemented yet\n"); 617 PERROR("Feature not implemented yet\n");
626 return -EFAULT; 618 return -EFAULT;
@@ -644,32 +636,33 @@ void smscore_unregister_device(smscore_device_t *coredev)
644 smscore_notify_clients(coredev); 636 smscore_notify_clients(coredev);
645 smscore_notify_callbacks(coredev, NULL, 0); 637 smscore_notify_callbacks(coredev, NULL, 0);
646 638
647 // at this point all buffers should be back 639 /* at this point all buffers should be back
648 // onresponse must no longer be called 640 * onresponse must no longer be called */
649 641
650 while (1) 642 while (1) {
651 { 643 while ((cb = smscore_getbuffer(coredev))) {
652 while ((cb = smscore_getbuffer(coredev)))
653 {
654 kfree(cb); 644 kfree(cb);
655 num_buffers ++; 645 num_buffers ++;
656 } 646 }
657 if (num_buffers == coredev->num_buffers) 647 if (num_buffers == coredev->num_buffers)
658 break; 648 break;
659 if (++retry > 10) 649 if (++retry > 10) {
660 { 650 printk(KERN_INFO "%s exiting although "
661 printk(KERN_INFO "%s exiting although not all buffers released.\n", __func__); 651 "not all buffers released.\n", __func__);
662 break; 652 break;
663 } 653 }
664 654
665 printk(KERN_INFO "%s waiting for %d buffer(s)\n", __func__, coredev->num_buffers - num_buffers); 655 printk(KERN_INFO "%s waiting for %d buffer(s)\n", __func__,
656 coredev->num_buffers - num_buffers);
666 msleep(100); 657 msleep(100);
667 } 658 }
668 659
669 printk(KERN_INFO "%s freed %d buffers\n", __func__, num_buffers); 660 printk(KERN_INFO "%s freed %d buffers\n", __func__, num_buffers);
670 661
671 if (coredev->common_buffer) 662 if (coredev->common_buffer)
672 dma_free_coherent(NULL, coredev->common_buffer_size, coredev->common_buffer, coredev->common_buffer_phys); 663 dma_free_coherent(NULL, coredev->common_buffer_size,
664 coredev->common_buffer,
665 coredev->common_buffer_phys);
673 666
674 list_del(&coredev->entry); 667 list_del(&coredev->entry);
675 kfree(coredev); 668 kfree(coredev);
@@ -681,7 +674,8 @@ void smscore_unregister_device(smscore_device_t *coredev)
681 674
682int smscore_detect_mode(smscore_device_t *coredev) 675int smscore_detect_mode(smscore_device_t *coredev)
683{ 676{
684 void *buffer = kmalloc(sizeof(SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA); 677 void *buffer = kmalloc(sizeof(SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT,
678 GFP_KERNEL | GFP_DMA);
685 SmsMsgHdr_ST *msg = (SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer); 679 SmsMsgHdr_ST *msg = (SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer);
686 int rc; 680 int rc;
687 681
@@ -690,20 +684,17 @@ int smscore_detect_mode(smscore_device_t *coredev)
690 684
691 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ, sizeof(SmsMsgHdr_ST)); 685 SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ, sizeof(SmsMsgHdr_ST));
692 686
693 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->version_ex_done); 687 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength,
694 if (rc == -ETIME) 688 &coredev->version_ex_done);
695 { 689 if (rc == -ETIME) {
696 printk("%s: MSG_SMS_GET_VERSION_EX_REQ failed first try\n", __func__); 690 printk("%s: MSG_SMS_GET_VERSION_EX_REQ failed first try\n", __func__);
697 691
698 if (wait_for_completion_timeout(&coredev->resume_done, msecs_to_jiffies(5000))) 692 if (wait_for_completion_timeout(&coredev->resume_done,
699 { 693 msecs_to_jiffies(5000))) {
700 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->version_ex_done); 694 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->version_ex_done);
701 if (rc < 0) 695 if (rc < 0)
702 {
703 printk("%s: MSG_SMS_GET_VERSION_EX_REQ failed second try, rc %d\n", __func__, rc); 696 printk("%s: MSG_SMS_GET_VERSION_EX_REQ failed second try, rc %d\n", __func__, rc);
704 } 697 } else
705 }
706 else
707 rc = -ETIME; 698 rc = -ETIME;
708 } 699 }
709 700
@@ -712,17 +703,16 @@ int smscore_detect_mode(smscore_device_t *coredev)
712 return rc; 703 return rc;
713} 704}
714 705
715char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = 706char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = {
716{
717 /*Stellar NOVA A0 Nova B0 VEGA*/ 707 /*Stellar NOVA A0 Nova B0 VEGA*/
718 /*DVBT*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, 708 /*DVBT*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
719 /*DVBH*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, 709 /*DVBH*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
720 /*TDMB*/ {"none", "tdmb_nova_12mhz.inp", "none" "none"}, 710 /*TDMB*/ {"none", "tdmb_nova_12mhz.inp", "none", "none"},
721 /*DABIP*/ {"none", "none", "none", "none"}, 711 /*DABIP*/ {"none", "none", "none", "none"},
722 /*BDA*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"}, 712 /*BDA*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
723 /*ISDBT*/ {"none", "isdbt_nova_12mhz.inp", "dvb_nova_12mhz.inp", "none"}, 713 /*ISDBT*/ {"none", "isdbt_nova_12mhz.inp", "dvb_nova_12mhz.inp", "none"},
724 /*ISDBTBDA*/{"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"}, 714 /*ISDBTBDA*/{"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
725 /*CMMB*/ {"none", "none", "none", "cmmb_vega_12mhz.inp"} 715 /*CMMB*/ {"none", "none", "none", "cmmb_vega_12mhz.inp"}
726}; 716};
727 717
728 718
@@ -741,51 +731,44 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
741 int rc = 0; 731 int rc = 0;
742 sms_device_type_st type; 732 sms_device_type_st type;
743 733
744 PDEBUG("set device mode to %d\n", mode ); 734 PDEBUG("set device mode to %d\n", mode);
745 if (coredev->device_flags & SMS_DEVICE_FAMILY2) 735 if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
746 { 736 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_RAW_TUNER) {
747 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_RAW_TUNER) 737 printk(KERN_INFO "%s invalid mode specified %d\n",
748 { 738 __func__, mode);
749 printk(KERN_INFO "%s invalid mode specified %d\n", __func__, mode);
750 return -EINVAL; 739 return -EINVAL;
751 } 740 }
752 741
753 smscore_registry_setmode(coredev->devpath, mode); 742 smscore_registry_setmode(coredev->devpath, mode);
754 743
755 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) 744 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) {
756 {
757 rc = smscore_detect_mode(coredev); 745 rc = smscore_detect_mode(coredev);
758 if (rc < 0) 746 if (rc < 0) {
759 { 747 printk(KERN_INFO "%s mode detect failed %d\n",
760 printk(KERN_INFO "%s mode detect failed %d\n", __func__, rc); 748 __func__, rc);
761 return rc; 749 return rc;
762 } 750 }
763 } 751 }
764 752
765 if (coredev->mode == mode) 753 if (coredev->mode == mode) {
766 { 754 printk(KERN_INFO "%s device mode %d already set\n",
767 printk(KERN_INFO "%s device mode %d already set\n", __func__, mode); 755 __func__, mode);
768 return 0; 756 return 0;
769 } 757 }
770 758
771 if (!(coredev->modes_supported & (1 << mode))) 759 if (!(coredev->modes_supported & (1 << mode))) {
772 { 760 type = smscore_registry_gettype(coredev->devpath);
773 type = smscore_registry_gettype ( coredev->devpath ); 761 rc = smscore_load_firmware_from_file(coredev, smscore_fw_lkup[mode][type], NULL);
774 rc = smscore_load_firmware_from_file ( coredev, smscore_fw_lkup[mode][type], NULL ); 762 if (rc < 0) {
775 if (rc < 0)
776 {
777 printk(KERN_INFO "%s load firmware failed %d\n", __func__, rc); 763 printk(KERN_INFO "%s load firmware failed %d\n", __func__, rc);
778 return rc; 764 return rc;
779 } 765 }
780 } 766 } else
781 else
782 {
783 printk(KERN_INFO "%s mode %d supported by running firmware\n", __func__, mode); 767 printk(KERN_INFO "%s mode %d supported by running firmware\n", __func__, mode);
784 }
785 768
786 buffer = kmalloc(sizeof(SmsMsgData_ST) + SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA); 769 buffer = kmalloc(sizeof(SmsMsgData_ST) + SMS_DMA_ALIGNMENT,
787 if (buffer) 770 GFP_KERNEL | GFP_DMA);
788 { 771 if (buffer) {
789 SmsMsgData_ST *msg = (SmsMsgData_ST *) SMS_ALIGN_ADDRESS(buffer); 772 SmsMsgData_ST *msg = (SmsMsgData_ST *) SMS_ALIGN_ADDRESS(buffer);
790 773
791 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ, sizeof(SmsMsgData_ST)); 774 SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ, sizeof(SmsMsgData_ST));
@@ -794,32 +777,28 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
794 rc = smscore_sendrequest_and_wait(coredev, msg, msg->xMsgHeader.msgLength, &coredev->init_device_done); 777 rc = smscore_sendrequest_and_wait(coredev, msg, msg->xMsgHeader.msgLength, &coredev->init_device_done);
795 778
796 kfree(buffer); 779 kfree(buffer);
797 } 780 } else {
798 else
799 {
800 printk(KERN_INFO "%s Could not allocate buffer for init device message.\n", __func__); 781 printk(KERN_INFO "%s Could not allocate buffer for init device message.\n", __func__);
801 rc = -ENOMEM; 782 rc = -ENOMEM;
802 } 783 }
803 } 784 } else {
804 else 785 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
805 { 786 printk(KERN_INFO "%s invalid mode specified %d\n",
806 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) 787 __func__, mode);
807 {
808 printk(KERN_INFO "%s invalid mode specified %d\n", __func__, mode);
809 return -EINVAL; 788 return -EINVAL;
810 } 789 }
811 790
812 smscore_registry_setmode(coredev->devpath, mode); 791 smscore_registry_setmode(coredev->devpath, mode);
813 792
814 if (coredev->detectmode_handler) 793 if (coredev->detectmode_handler)
815 coredev->detectmode_handler(coredev->context, &coredev->mode); 794 coredev->detectmode_handler(coredev->context,
795 &coredev->mode);
816 796
817 if (coredev->mode != mode && coredev->setmode_handler) 797 if (coredev->mode != mode && coredev->setmode_handler)
818 rc = coredev->setmode_handler(coredev->context, mode); 798 rc = coredev->setmode_handler(coredev->context, mode);
819 } 799 }
820 800
821 if (rc >= 0) 801 if (rc >= 0) {
822 {
823 coredev->mode = mode; 802 coredev->mode = mode;
824 coredev->device_flags &= ~SMS_DEVICE_NOT_READY; 803 coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
825 } 804 }
@@ -847,7 +826,7 @@ int smscore_get_device_mode(smscore_device_t *coredev)
847 * 826 *
848 * @param coredev pointer to a coredev object returned by smscore_register_device 827 * @param coredev pointer to a coredev object returned by smscore_register_device
849 * @param data_type client data type (SMS_DONT_CARE for all types) 828 * @param data_type client data type (SMS_DONT_CARE for all types)
850 * @param id client id (SMS_DONT_CARE for all id ) 829 * @param id client id (SMS_DONT_CARE for all id)
851 * 830 *
852 */ 831 */
853smscore_client_t *smscore_find_client(smscore_device_t *coredev, int data_type, int id) 832smscore_client_t *smscore_find_client(smscore_device_t *coredev, int data_type, int id)
@@ -860,20 +839,21 @@ smscore_client_t *smscore_find_client(smscore_device_t *coredev, int data_type,
860 839
861 spin_lock_irqsave(&coredev->clientslock, flags); 840 spin_lock_irqsave(&coredev->clientslock, flags);
862 first = &coredev->clients; 841 first = &coredev->clients;
863 for (next = first->next; (next != first) && !client; next = next->next) 842 for (next = first->next;
864 { 843 (next != first) && !client;
865 firstid = &((smscore_client_t*)next )->idlist; 844 next = next->next) {
866 for (nextid = firstid->next ; nextid != firstid ; nextid = nextid->next) 845 firstid = &((smscore_client_t*)next)->idlist;
867 { 846 for (nextid = firstid->next;
847 nextid != firstid;
848 nextid = nextid->next) {
868 if ((((smscore_idlist_t*)nextid)->id == id) && 849 if ((((smscore_idlist_t*)nextid)->id == id) &&
869 (((smscore_idlist_t*)nextid)->data_type == data_type || 850 (((smscore_idlist_t*)nextid)->data_type == data_type ||
870 (((smscore_idlist_t*)nextid)->data_type == 0))) 851 (((smscore_idlist_t*)nextid)->data_type == 0))) {
871 { 852 client = (smscore_client_t*) next;
872 client = (smscore_client_t*) next; 853 break;
873 break; 854 }
874 } 855 }
875 } 856 }
876 }
877 spin_unlock_irqrestore(&coredev->clientslock, flags); 857 spin_unlock_irqrestore(&coredev->clientslock, flags);
878 return client; 858 return client;
879} 859}
@@ -889,7 +869,8 @@ smscore_client_t *smscore_find_client(smscore_device_t *coredev, int data_type,
889void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb) 869void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
890{ 870{
891 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8 *) cb->p + cb->offset); 871 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8 *) cb->p + cb->offset);
892 smscore_client_t *client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId); 872 smscore_client_t *client = smscore_find_client(coredev, phdr->msgType,
873 phdr->msgDstId);
893 int rc = -EBUSY; 874 int rc = -EBUSY;
894 875
895 static unsigned long last_sample_time = 0; 876 static unsigned long last_sample_time = 0;
@@ -901,67 +882,62 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
901 882
902 if (time_now - last_sample_time > 10000) 883 if (time_now - last_sample_time > 10000)
903 { 884 {
904 printk("\n%s data rate %d bytes/secs\n", __func__, (int)((data_total * 1000) / (time_now - last_sample_time))); 885 printk("\n%s data rate %d bytes/secs\n", __func__,
886 (int)((data_total * 1000) /
887 (time_now - last_sample_time)));
905 888
906 last_sample_time = time_now; 889 last_sample_time = time_now;
907 data_total = 0; 890 data_total = 0;
908 } 891 }
909 892
910 data_total += cb->size; 893 data_total += cb->size;
911 /* If no client registered for type & id, check for control client where type is not registered*/ 894 /* If no client registered for type & id,
912// if (!client) 895 * check for control client where type is not registered */
913// client = smscore_find_client( coredev, 0, phdr->msgDstId);
914 if (client) 896 if (client)
915 rc = client->onresponse_handler(client->context, cb); 897 rc = client->onresponse_handler(client->context, cb);
916 898
917 if (rc < 0) 899 if (rc < 0) {
918 { 900 switch (phdr->msgType) {
919 switch (phdr->msgType) 901 case MSG_SMS_GET_VERSION_EX_RES:
920 { 902 {
921 case MSG_SMS_GET_VERSION_EX_RES: 903 SmsVersionRes_ST *ver = (SmsVersionRes_ST *) phdr;
922 { 904 printk("%s: MSG_SMS_GET_VERSION_EX_RES id %d "
923 SmsVersionRes_ST *ver = (SmsVersionRes_ST*) phdr; 905 "prots 0x%x ver %d.%d\n", __func__,
924 printk("%s: MSG_SMS_GET_VERSION_EX_RES id %d prots 0x%x ver %d.%d\n", __func__, ver->FirmwareId, ver->SupportedProtocols, ver->RomVersionMajor, ver->RomVersionMinor); 906 ver->FirmwareId, ver->SupportedProtocols,
925 907 ver->RomVersionMajor, ver->RomVersionMinor);
926 coredev->mode = ver->FirmwareId == 255 ? DEVICE_MODE_NONE : ver->FirmwareId;
927 coredev->modes_supported = ver->SupportedProtocols;
928
929 complete(&coredev->version_ex_done);
930 break;
931 }
932
933 case MSG_SMS_INIT_DEVICE_RES:
934 printk("%s: MSG_SMS_INIT_DEVICE_RES\n", __func__);
935 complete(&coredev->init_device_done);
936 break;
937
938 case MSG_SW_RELOAD_START_RES:
939 printk("%s: MSG_SW_RELOAD_START_RES\n", __func__);
940 complete(&coredev->reload_start_done);
941 break;
942
943 case MSG_SMS_DATA_DOWNLOAD_RES:
944 complete(&coredev->data_download_done);
945 break;
946
947 case MSG_SW_RELOAD_EXEC_RES:
948 printk("%s: MSG_SW_RELOAD_EXEC_RES\n", __func__);
949 break;
950 908
951 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES: 909 coredev->mode = ver->FirmwareId == 255 ?
952 printk("%s: MSG_SMS_SWDOWNLOAD_TRIGGER_RES\n", __func__); 910 DEVICE_MODE_NONE : ver->FirmwareId;
953 complete(&coredev->trigger_done); 911 coredev->modes_supported = ver->SupportedProtocols;
954 break;
955
956 case MSG_SMS_SLEEP_RESUME_COMP_IND:
957 complete(&coredev->resume_done);
958 break;
959 912
960 default: 913 complete(&coredev->version_ex_done);
961 //printk(KERN_INFO "%s no client (%p) or error (%d), type:%d dstid:%d\n", __func__, client, rc, phdr->msgType, phdr->msgDstId); 914 break;
962 break; 915 }
916 case MSG_SMS_INIT_DEVICE_RES:
917 printk("%s: MSG_SMS_INIT_DEVICE_RES\n", __func__);
918 complete(&coredev->init_device_done);
919 break;
920 case MSG_SW_RELOAD_START_RES:
921 printk("%s: MSG_SW_RELOAD_START_RES\n", __func__);
922 complete(&coredev->reload_start_done);
923 break;
924 case MSG_SMS_DATA_DOWNLOAD_RES:
925 complete(&coredev->data_download_done);
926 break;
927 case MSG_SW_RELOAD_EXEC_RES:
928 printk("%s: MSG_SW_RELOAD_EXEC_RES\n", __func__);
929 break;
930 case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
931 printk("%s: MSG_SMS_SWDOWNLOAD_TRIGGER_RES\n",
932 __func__);
933 complete(&coredev->trigger_done);
934 break;
935 case MSG_SMS_SLEEP_RESUME_COMP_IND:
936 complete(&coredev->resume_done);
937 break;
938 default:
939 break;
963 } 940 }
964
965 smscore_putbuffer(coredev, cb); 941 smscore_putbuffer(coredev, cb);
966 } 942 }
967} 943}
@@ -980,8 +956,7 @@ smscore_buffer_t *smscore_getbuffer(smscore_device_t *coredev)
980 956
981 spin_lock_irqsave(&coredev->bufferslock, flags); 957 spin_lock_irqsave(&coredev->bufferslock, flags);
982 958
983 if (!list_empty(&coredev->buffers)) 959 if (!list_empty(&coredev->buffers)) {
984 {
985 cb = (smscore_buffer_t *) coredev->buffers.next; 960 cb = (smscore_buffer_t *) coredev->buffers.next;
986 list_del(&cb->entry); 961 list_del(&cb->entry);
987 } 962 }
@@ -1003,35 +978,33 @@ void smscore_putbuffer(smscore_device_t *coredev, smscore_buffer_t *cb)
1003 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); 978 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
1004} 979}
1005 980
1006int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, int data_type, int id) 981int smscore_validate_client(smscore_device_t *coredev,
982 smscore_client_t *client, int data_type, int id)
1007{ 983{
1008 smscore_idlist_t *listentry; 984 smscore_idlist_t *listentry;
1009 smscore_client_t *registered_client; 985 smscore_client_t *registered_client;
1010 986
1011 if ( !client ) 987 if (!client) {
1012 {
1013 PERROR("bad parameter.\n"); 988 PERROR("bad parameter.\n");
1014 return -EFAULT; 989 return -EFAULT;
1015 } 990 }
1016 registered_client = smscore_find_client(coredev, data_type, id); 991 registered_client = smscore_find_client(coredev, data_type, id);
1017 if (registered_client == client) 992 if (registered_client == client) {
1018 {
1019 return 0; 993 return 0;
1020 } 994 }
1021 if (registered_client) 995 if (registered_client) {
1022 {
1023 PERROR("The msg ID already registered to another client.\n"); 996 PERROR("The msg ID already registered to another client.\n");
1024 return -EEXIST; 997 return -EEXIST;
1025 } 998 }
1026 listentry = kzalloc ( sizeof ( smscore_idlist_t ), GFP_KERNEL ); 999 listentry = kzalloc(sizeof(smscore_idlist_t), GFP_KERNEL);
1027 if ( !listentry ) 1000 if (!listentry) {
1028 {
1029 PERROR("Can't allocate memory for client id.\n"); 1001 PERROR("Can't allocate memory for client id.\n");
1030 return -ENOMEM; 1002 return -ENOMEM;
1031 } 1003 }
1032 listentry->id = id; 1004 listentry->id = id;
1033 listentry->data_type = data_type; 1005 listentry->data_type = data_type;
1034 list_add_locked ( &listentry->entry, &client->idlist, &coredev->clientslock ); 1006 list_add_locked(&listentry->entry, &client->idlist,
1007 &coredev->clientslock);
1035 return 0; 1008 return 0;
1036} 1009}
1037 1010
@@ -1051,29 +1024,31 @@ int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client,
1051int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client) 1024int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client)
1052{ 1025{
1053 smscore_client_t *newclient; 1026 smscore_client_t *newclient;
1054 // check that no other channel with same parameters exists 1027 /* check that no other channel with same parameters exists */
1055 if (smscore_find_client(coredev, params->data_type, params->initial_id)) 1028 if (smscore_find_client(coredev, params->data_type,
1056 { 1029 params->initial_id)) {
1057 PERROR("Client already exist.\n"); 1030 PERROR("Client already exist.\n");
1058 return -EEXIST; 1031 return -EEXIST;
1059 } 1032 }
1060 1033
1061 newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL); 1034 newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL);
1062 if (!newclient) 1035 if (!newclient) {
1063 {
1064 PERROR("Failed to allocate memory for client.\n"); 1036 PERROR("Failed to allocate memory for client.\n");
1065 return -ENOMEM; 1037 return -ENOMEM;
1066 } 1038 }
1067 1039
1068 INIT_LIST_HEAD ( &newclient->idlist); 1040 INIT_LIST_HEAD(&newclient->idlist);
1069 newclient->coredev = coredev; 1041 newclient->coredev = coredev;
1070 newclient->onresponse_handler = params->onresponse_handler; 1042 newclient->onresponse_handler = params->onresponse_handler;
1071 newclient->onremove_handler = params->onremove_handler; 1043 newclient->onremove_handler = params->onremove_handler;
1072 newclient->context = params->context; 1044 newclient->context = params->context;
1073 list_add_locked(&newclient->entry, &coredev->clients, &coredev->clientslock); 1045 list_add_locked(&newclient->entry, &coredev->clients,
1074 smscore_validate_client(coredev, newclient, params->data_type, params->initial_id); 1046 &coredev->clientslock);
1047 smscore_validate_client(coredev, newclient, params->data_type,
1048 params->initial_id);
1075 *client = newclient; 1049 *client = newclient;
1076 PDEBUG ( "%p %d %d\n", params->context, params->data_type, params->initial_id ); 1050 PDEBUG("%p %d %d\n", params->context, params->data_type,
1051 params->initial_id);
1077 1052
1078 return 0; 1053 return 0;
1079} 1054}
@@ -1092,11 +1067,11 @@ void smscore_unregister_client(smscore_client_t *client)
1092 spin_lock_irqsave(&coredev->clientslock, flags); 1067 spin_lock_irqsave(&coredev->clientslock, flags);
1093 1068
1094 1069
1095 while (!list_empty( &client->idlist)) 1070 while (!list_empty(&client->idlist)) {
1096 { 1071 smscore_idlist_t *identry =
1097 smscore_idlist_t *identry = (smscore_idlist_t*)client->idlist.next; 1072 (smscore_idlist_t*) client->idlist.next;
1098 list_del ( &identry->entry ); 1073 list_del(&identry->entry);
1099 kfree ( identry ); 1074 kfree(identry);
1100 } 1075 }
1101 1076
1102 printk(KERN_INFO "%s %p\n", __func__, client->context); 1077 printk(KERN_INFO "%s %p\n", __func__, client->context);
@@ -1123,22 +1098,21 @@ int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size)
1123 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *) buffer; 1098 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *) buffer;
1124 int rc; 1099 int rc;
1125 1100
1126 if ( client == NULL ) 1101 if (client == NULL) {
1127 { 1102 printk(KERN_ERR "%s Got NULL client\n", __func__);
1128 printk(KERN_ERR "%s Got NULL client\n", __func__ );
1129 return -EINVAL; 1103 return -EINVAL;
1130 } 1104 }
1131 1105
1132 coredev = client->coredev; 1106 coredev = client->coredev;
1133 1107
1134 // check that no other channel with same id exists 1108 /* check that no other channel with same id exists */
1135 if ( coredev == NULL ) 1109 if (coredev == NULL) {
1136 { 1110 printk(KERN_ERR "%s Got NULL coredev\n", __func__);
1137 printk(KERN_ERR "%s Got NULL coredev\n", __func__ );
1138 return -EINVAL; 1111 return -EINVAL;
1139 } 1112 }
1140 1113
1141 rc = smscore_validate_client(client->coredev, client, 0, phdr->msgSrcId); 1114 rc = smscore_validate_client(client->coredev, client, 0,
1115 phdr->msgSrcId);
1142 if (rc < 0) 1116 if (rc < 0)
1143 return rc; 1117 return rc;
1144 1118
@@ -1168,21 +1142,25 @@ int smscore_get_common_buffer_size(smscore_device_t *coredev)
1168int smscore_map_common_buffer(smscore_device_t *coredev, 1142int smscore_map_common_buffer(smscore_device_t *coredev,
1169 struct vm_area_struct *vma) 1143 struct vm_area_struct *vma)
1170{ 1144{
1171 unsigned long end = vma->vm_end, start = vma->vm_start, size = PAGE_ALIGN(coredev->common_buffer_size); 1145 unsigned long end = vma->vm_end,
1146 start = vma->vm_start,
1147 size = PAGE_ALIGN(coredev->common_buffer_size);
1172 1148
1173 if (!(vma->vm_flags & (VM_READ | VM_SHARED)) || (vma->vm_flags & VM_WRITE)) 1149 if (!(vma->vm_flags & (VM_READ | VM_SHARED)) ||
1174 { 1150 (vma->vm_flags & VM_WRITE)) {
1175 printk(KERN_INFO "%s invalid vm flags\n", __func__); 1151 printk(KERN_INFO "%s invalid vm flags\n", __func__);
1176 return -EINVAL; 1152 return -EINVAL;
1177 } 1153 }
1178 1154
1179 if ((end - start) != size) 1155 if ((end - start) != size) {
1180 { 1156 printk(KERN_INFO "%s invalid size %d expected %d\n",
1181 printk(KERN_INFO "%s invalid size %d expected %d\n", __func__, (int)(end - start), (int) size); 1157 __func__, (int)(end - start), (int) size);
1182 return -EINVAL; 1158 return -EINVAL;
1183 } 1159 }
1184 1160
1185 if (remap_pfn_range(vma, start, coredev->common_buffer_phys >> PAGE_SHIFT, size, pgprot_noncached(vma->vm_page_prot))) 1161 if (remap_pfn_range(vma, start,
1162 coredev->common_buffer_phys >> PAGE_SHIFT,
1163 size, pgprot_noncached(vma->vm_page_prot)))
1186 { 1164 {
1187 printk(KERN_INFO "%s remap_page_range failed\n", __func__); 1165 printk(KERN_INFO "%s remap_page_range failed\n", __func__);
1188 return -EAGAIN; 1166 return -EAGAIN;
@@ -1217,9 +1195,9 @@ void smscore_module_exit(void)
1217{ 1195{
1218 1196
1219 kmutex_lock(&g_smscore_deviceslock); 1197 kmutex_lock(&g_smscore_deviceslock);
1220 while (!list_empty(&g_smscore_notifyees)) 1198 while (!list_empty(&g_smscore_notifyees)) {
1221 { 1199 smscore_device_notifyee_t *notifyee =
1222 smscore_device_notifyee_t *notifyee = (smscore_device_notifyee_t *) g_smscore_notifyees.next; 1200 (smscore_device_notifyee_t *) g_smscore_notifyees.next;
1223 1201
1224 list_del(&notifyee->entry); 1202 list_del(&notifyee->entry);
1225 kfree(notifyee); 1203 kfree(notifyee);
@@ -1227,9 +1205,9 @@ void smscore_module_exit(void)
1227 kmutex_unlock(&g_smscore_deviceslock); 1205 kmutex_unlock(&g_smscore_deviceslock);
1228 1206
1229 kmutex_lock(&g_smscore_registrylock); 1207 kmutex_lock(&g_smscore_registrylock);
1230 while (!list_empty(&g_smscore_registry)) 1208 while (!list_empty(&g_smscore_registry)) {
1231 { 1209 smscore_registry_entry_t *entry =
1232 smscore_registry_entry_t *entry = (smscore_registry_entry_t *) g_smscore_registry.next; 1210 (smscore_registry_entry_t *) g_smscore_registry.next;
1233 1211
1234 list_del(&entry->entry); 1212 list_del(&entry->entry);
1235 kfree(entry); 1213 kfree(entry);
@@ -1249,6 +1227,5 @@ module_init(smscore_module_init);
1249module_exit(smscore_module_exit); 1227module_exit(smscore_module_exit);
1250 1228
1251MODULE_DESCRIPTION("smscore"); 1229MODULE_DESCRIPTION("smscore");
1252MODULE_AUTHOR ( "Siano Mobile Silicon,,, (doronc@siano-ms.com)" ); 1230MODULE_AUTHOR("Siano Mobile Silicon,,, (doronc@siano-ms.com)");
1253MODULE_LICENSE("GPL"); 1231MODULE_LICENSE("GPL");
1254
diff --git a/drivers/media/dvb/siano/smscoreapi.h b/drivers/media/dvb/siano/smscoreapi.h
index 601bdb8304db..79fa71a5f284 100644
--- a/drivers/media/dvb/siano/smscoreapi.h
+++ b/drivers/media/dvb/siano/smscoreapi.h
@@ -82,12 +82,12 @@ typedef void (*onremove_t)(void *context);
82 82
83typedef struct _smscore_buffer 83typedef struct _smscore_buffer
84{ 84{
85 // public members, once passed to clients can be changed freely 85 /* public members, once passed to clients can be changed freely */
86 struct list_head entry; 86 struct list_head entry;
87 int size; 87 int size;
88 int offset; 88 int offset;
89 89
90 // private members, read-only for clients 90 /* private members, read-only for clients */
91 void *p; 91 void *p;
92 dma_addr_t phys; 92 dma_addr_t phys;
93 unsigned long offset_in_common; 93 unsigned long offset_in_common;
@@ -123,7 +123,7 @@ typedef struct _smsclient_params
123 void *context; 123 void *context;
124} smsclient_params_t; 124} smsclient_params_t;
125 125
126// GPIO definitions for antenna frequency domain control (SMS8021) 126/* GPIO definitions for antenna frequency domain control (SMS8021) */
127#define SMS_ANTENNA_GPIO_0 1 127#define SMS_ANTENNA_GPIO_0 1
128#define SMS_ANTENNA_GPIO_1 0 128#define SMS_ANTENNA_GPIO_1 0
129 129
@@ -223,7 +223,7 @@ typedef struct SmsMsgHdr_S
223 UINT16 msgType; 223 UINT16 msgType;
224 UINT8 msgSrcId; 224 UINT8 msgSrcId;
225 UINT8 msgDstId; 225 UINT8 msgDstId;
226 UINT16 msgLength; // Length is of the entire message, including header 226 UINT16 msgLength; /* Length of entire message, including header */
227 UINT16 msgFlags; 227 UINT16 msgFlags;
228} SmsMsgHdr_ST; 228} SmsMsgHdr_ST;
229 229
@@ -244,24 +244,24 @@ typedef struct SmsVersionRes_S
244{ 244{
245 SmsMsgHdr_ST xMsgHeader; 245 SmsMsgHdr_ST xMsgHeader;
246 246
247 UINT16 ChipModel; // e.g. 0x1102 for SMS-1102 "Nova" 247 UINT16 ChipModel; /* e.g. 0x1102 for SMS-1102 "Nova" */
248 UINT8 Step; // 0 - Step A 248 UINT8 Step; /* 0 - Step A */
249 UINT8 MetalFix; // 0 - Metal 0 249 UINT8 MetalFix; /* 0 - Metal 0 */
250 250
251 UINT8 FirmwareId; // 0xFF � ROM, otherwise the value indicated by SMSHOSTLIB_DEVICE_MODES_E 251 UINT8 FirmwareId; /* 0xFF � ROM, otherwise the value indicated by SMSHOSTLIB_DEVICE_MODES_E */
252 UINT8 SupportedProtocols; // Bitwise OR combination of supported protocols 252 UINT8 SupportedProtocols; /* Bitwise OR combination of supported protocols */
253 253
254 UINT8 VersionMajor; 254 UINT8 VersionMajor;
255 UINT8 VersionMinor; 255 UINT8 VersionMinor;
256 UINT8 VersionPatch; 256 UINT8 VersionPatch;
257 UINT8 VersionFieldPatch; 257 UINT8 VersionFieldPatch;
258 258
259 UINT8 RomVersionMajor; 259 UINT8 RomVersionMajor;
260 UINT8 RomVersionMinor; 260 UINT8 RomVersionMinor;
261 UINT8 RomVersionPatch; 261 UINT8 RomVersionPatch;
262 UINT8 RomVersionFieldPatch; 262 UINT8 RomVersionFieldPatch;
263 263
264 UINT8 TextLabel[34]; 264 UINT8 TextLabel[34];
265} SmsVersionRes_ST; 265} SmsVersionRes_ST;
266 266
267typedef struct SmsFirmware_S 267typedef struct SmsFirmware_S
@@ -274,59 +274,60 @@ typedef struct SmsFirmware_S
274 274
275typedef struct SMSHOSTLIB_STATISTICS_S 275typedef struct SMSHOSTLIB_STATISTICS_S
276{ 276{
277 UINT32 Reserved; //!< Reserved 277 UINT32 Reserved; /* Reserved */
278 278
279 /// Common parameters 279 /* Common parameters */
280 UINT32 IsRfLocked; //!< 0 - not locked, 1 - locked 280 UINT32 IsRfLocked; /* 0 - not locked, 1 - locked */
281 UINT32 IsDemodLocked; //!< 0 - not locked, 1 - locked 281 UINT32 IsDemodLocked; /* 0 - not locked, 1 - locked */
282 UINT32 IsExternalLNAOn; //!< 0 - external LNA off, 1 - external LNA on 282 UINT32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
283 283
284 /// Reception quality 284 /* Reception quality */
285 INT32 SNR; //!< dB 285 INT32 SNR; /* dB */
286 UINT32 BER; //!< Post Viterbi BER [1E-5] 286 UINT32 BER; /* Post Viterbi BER [1E-5] */
287 UINT32 FIB_CRC; //!< CRC errors percentage, valid only for DAB 287 UINT32 FIB_CRC; /* CRC errors percentage, valid only for DAB */
288 UINT32 TS_PER; //!< Transport stream PER, 0xFFFFFFFF indicate N/A, valid only for DVB-T/H 288 UINT32 TS_PER; /* Transport stream PER, 0xFFFFFFFF indicate N/A, valid only for DVB-T/H */
289 UINT32 MFER; //!< DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H 289 UINT32 MFER; /* DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H */
290 INT32 RSSI; //!< dBm 290 INT32 RSSI; /* dBm */
291 INT32 InBandPwr; //!< In band power in dBM 291 INT32 InBandPwr; /* In band power in dBM */
292 INT32 CarrierOffset; //!< Carrier Offset in bin/1024 292 INT32 CarrierOffset; /* Carrier Offset in bin/1024 */
293 293
294 /// Transmission parameters 294 /* Transmission parameters */
295 UINT32 Frequency; //!< Frequency in Hz 295 UINT32 Frequency; /* Frequency in Hz */
296 UINT32 Bandwidth; //!< Bandwidth in MHz, valid only for DVB-T/H 296 UINT32 Bandwidth; /* Bandwidth in MHz, valid only for DVB-T/H */
297 UINT32 TransmissionMode; //!< Transmission Mode, for DAB modes 1-4, for DVB-T/H FFT mode carriers in Kilos 297 UINT32 TransmissionMode; /* Transmission Mode, for DAB modes 1-4, for DVB-T/H FFT mode carriers in Kilos */
298 UINT32 ModemState; //!< from SMS_DvbModemState_ET , valid only for DVB-T/H 298 UINT32 ModemState; /* from SMS_DvbModemState_ET , valid only for DVB-T/H */
299 UINT32 GuardInterval; //!< Guard Interval, 1 divided by value , valid only for DVB-T/H 299 UINT32 GuardInterval; /* Guard Interval, 1 divided by value , valid only for DVB-T/H */
300 UINT32 CodeRate; //!< Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H 300 UINT32 CodeRate; /* Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H */
301 UINT32 LPCodeRate; //!< Low Priority Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H 301 UINT32 LPCodeRate; /* Low Priority Code Rate from SMS_DvbModemState_ET, valid only for DVB-T/H */
302 UINT32 Hierarchy; //!< Hierarchy from SMS_Hierarchy_ET, valid only for DVB-T/H 302 UINT32 Hierarchy; /* Hierarchy from SMS_Hierarchy_ET, valid only for DVB-T/H */
303 UINT32 Constellation; //!< Constellation from SMS_Constellation_ET, valid only for DVB-T/H 303 UINT32 Constellation; /* Constellation from SMS_Constellation_ET, valid only for DVB-T/H */
304 304
305 /// Burst parameters, valid only for DVB-H 305 /* Burst parameters, valid only for DVB-H */
306 UINT32 BurstSize; //!< Current burst size in bytes, valid only for DVB-H 306 UINT32 BurstSize; /* Current burst size in bytes, valid only for DVB-H */
307 UINT32 BurstDuration; //!< Current burst duration in mSec, valid only for DVB-H 307 UINT32 BurstDuration; /* Current burst duration in mSec, valid only for DVB-H */
308 UINT32 BurstCycleTime; //!< Current burst cycle time in mSec, valid only for DVB-H 308 UINT32 BurstCycleTime; /* Current burst cycle time in mSec, valid only for DVB-H */
309 UINT32 CalculatedBurstCycleTime;//!< Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H 309 UINT32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H */
310 UINT32 NumOfRows; //!< Number of rows in MPE table, valid only for DVB-H 310 UINT32 NumOfRows; /* Number of rows in MPE table, valid only for DVB-H */
311 UINT32 NumOfPaddCols; //!< Number of padding columns in MPE table, valid only for DVB-H 311 UINT32 NumOfPaddCols; /* Number of padding columns in MPE table, valid only for DVB-H */
312 UINT32 NumOfPunctCols; //!< Number of puncturing columns in MPE table, valid only for DVB-H 312 UINT32 NumOfPunctCols; /* Number of puncturing columns in MPE table, valid only for DVB-H */
313 UINT32 ErrorTSPackets; //!< Number of erroneous transport-stream packets 313 UINT32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
314 UINT32 TotalTSPackets; //!< Total number of transport-stream packets 314 UINT32 TotalTSPackets; /* Total number of transport-stream packets */
315 UINT32 NumOfValidMpeTlbs; //!< Number of MPE tables which do not include errors after MPE RS decoding 315 UINT32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include errors after MPE RS decoding */
316 UINT32 NumOfInvalidMpeTlbs; //!< Number of MPE tables which include errors after MPE RS decoding 316 UINT32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors after MPE RS decoding */
317 UINT32 NumOfCorrectedMpeTlbs; //!< Number of MPE tables which were corrected by MPE RS decoding 317 UINT32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected by MPE RS decoding */
318 /// Common params 318
319 UINT32 BERErrorCount; //!< Number of errornous SYNC bits. 319 /* Common params */
320 UINT32 BERBitCount; //!< Total number of SYNC bits. 320 UINT32 BERErrorCount; /* Number of errornous SYNC bits. */
321 321 UINT32 BERBitCount; /* Total number of SYNC bits. */
322 /// Interface information 322
323 UINT32 SmsToHostTxErrors; //!< Total number of transmission errors. 323 /* Interface information */
324 324 UINT32 SmsToHostTxErrors; /* Total number of transmission errors. */
325 /// DAB/T-DMB 325
326 UINT32 PreBER; //!< DAB/T-DMB only: Pre Viterbi BER [1E-5] 326 /* DAB/T-DMB */
327 327 UINT32 PreBER; /* DAB/T-DMB only: Pre Viterbi BER [1E-5] */
328 /// DVB-H TPS parameters 328
329 UINT32 CellId; //!< TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered 329 /* DVB-H TPS parameters */
330 UINT32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered */
330 331
331} SMSHOSTLIB_STATISTICS_ST; 332} SMSHOSTLIB_STATISTICS_ST;
332 333
@@ -336,147 +337,151 @@ typedef struct
336 337
337 SMSHOSTLIB_STATISTICS_ST Stat; 338 SMSHOSTLIB_STATISTICS_ST Stat;
338 339
339 // Split the calc of the SNR in DAB 340 /* Split the calc of the SNR in DAB */
340 UINT32 Signal; //!< dB 341 UINT32 Signal; /* dB */
341 UINT32 Noise; //!< dB 342 UINT32 Noise; /* dB */
342 343
343} SmsMsgStatisticsInfo_ST; 344} SmsMsgStatisticsInfo_ST;
344 345
345typedef struct SMSHOSTLIB_ISDBT_LAYER_STAT_S 346typedef struct SMSHOSTLIB_ISDBT_LAYER_STAT_S
346{ 347{
347 // Per-layer information 348 /* Per-layer information */
348 UINT32 CodeRate; //!< Code Rate from SMSHOSTLIB_CODE_RATE_ET, 255 means layer does not exist 349 UINT32 CodeRate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET, 255 means layer does not exist */
349 UINT32 Constellation; //!< Constellation from SMSHOSTLIB_CONSTELLATION_ET, 255 means layer does not exist 350 UINT32 Constellation; /* Constellation from SMSHOSTLIB_CONSTELLATION_ET, 255 means layer does not exist */
350 UINT32 BER; //!< Post Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A 351 UINT32 BER; /* Post Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */
351 UINT32 BERErrorCount; //!< Post Viterbi Error Bits Count 352 UINT32 BERErrorCount; /* Post Viterbi Error Bits Count */
352 UINT32 BERBitCount; //!< Post Viterbi Total Bits Count 353 UINT32 BERBitCount; /* Post Viterbi Total Bits Count */
353 UINT32 PreBER; //!< Pre Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A 354 UINT32 PreBER; /* Pre Viterbi BER [1E-5], 0xFFFFFFFF indicate N/A */
354 UINT32 TS_PER; //!< Transport stream PER [%], 0xFFFFFFFF indicate N/A 355 UINT32 TS_PER; /* Transport stream PER [%], 0xFFFFFFFF indicate N/A */
355 UINT32 ErrorTSPackets; //!< Number of erroneous transport-stream packets 356 UINT32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
356 UINT32 TotalTSPackets; //!< Total number of transport-stream packets 357 UINT32 TotalTSPackets; /* Total number of transport-stream packets */
357 UINT32 TILdepthI; //!< Time interleaver depth I parameter, 255 means layer does not exist 358 UINT32 TILdepthI; /* Time interleaver depth I parameter, 255 means layer does not exist */
358 UINT32 NumberOfSegments; //!< Number of segments in layer A, 255 means layer does not exist 359 UINT32 NumberOfSegments; /* Number of segments in layer A, 255 means layer does not exist */
359 UINT32 TMCCErrors; //!< TMCC errors 360 UINT32 TMCCErrors; /* TMCC errors */
360} SMSHOSTLIB_ISDBT_LAYER_STAT_ST; 361} SMSHOSTLIB_ISDBT_LAYER_STAT_ST;
361 362
362typedef struct SMSHOSTLIB_STATISTICS_ISDBT_S 363typedef struct SMSHOSTLIB_STATISTICS_ISDBT_S
363{ 364{
364 UINT32 StatisticsType; //!< Enumerator identifying the type of the structure. Values are the same as SMSHOSTLIB_DEVICE_MODES_E 365 UINT32 StatisticsType; /* Enumerator identifying the type of the
365 //!< This fiels MUST always first in any statistics structure 366 * structure. Values are the same as
366 367 * SMSHOSTLIB_DEVICE_MODES_E
367 UINT32 FullSize; //!< Total size of the structure returned by the modem. If the size requested by 368 *
368 //!< the host is smaller than FullSize, the struct will be truncated 369 * This field MUST always be first in any
369 370 * statistics structure */
370 // Common parameters 371
371 UINT32 IsRfLocked; //!< 0 - not locked, 1 - locked 372 UINT32 FullSize; /* Total size of the structure returned by the modem. If the size requested by
372 UINT32 IsDemodLocked; //!< 0 - not locked, 1 - locked 373 * the host is smaller than FullSize, the struct will be truncated */
373 UINT32 IsExternalLNAOn; //!< 0 - external LNA off, 1 - external LNA on 374
374 375 /* Common parameters */
375 // Reception quality 376 UINT32 IsRfLocked; /* 0 - not locked, 1 - locked */
376 INT32 SNR; //!< dB 377 UINT32 IsDemodLocked; /* 0 - not locked, 1 - locked */
377 INT32 RSSI; //!< dBm 378 UINT32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
378 INT32 InBandPwr; //!< In band power in dBM 379
379 INT32 CarrierOffset; //!< Carrier Offset in Hz 380 /* Reception quality */
380 381 INT32 SNR; /* dB */
381 // Transmission parameters 382 INT32 RSSI; /* dBm */
382 UINT32 Frequency; //!< Frequency in Hz 383 INT32 InBandPwr; /* In band power in dBM */
383 UINT32 Bandwidth; //!< Bandwidth in MHz 384 INT32 CarrierOffset; /* Carrier Offset in Hz */
384 UINT32 TransmissionMode; //!< ISDB-T transmission mode 385
385 UINT32 ModemState; //!< 0 - Acquisition, 1 - Locked 386 /* Transmission parameters */
386 UINT32 GuardInterval; //!< Guard Interval, 1 divided by value 387 UINT32 Frequency; /* Frequency in Hz */
387 UINT32 SystemType; //!< ISDB-T system type (ISDB-T / ISDB-Tsb) 388 UINT32 Bandwidth; /* Bandwidth in MHz */
388 UINT32 PartialReception; //!< TRUE - partial reception, FALSE otherwise 389 UINT32 TransmissionMode; /* ISDB-T transmission mode */
389 UINT32 NumOfLayers; //!< Number of ISDB-T layers in the network 390 UINT32 ModemState; /* 0 - Acquisition, 1 - Locked */
390 391 UINT32 GuardInterval; /* Guard Interval, 1 divided by value */
391 // Per-layer information 392 UINT32 SystemType; /* ISDB-T system type (ISDB-T / ISDB-Tsb) */
392 // Layers A, B and C 393 UINT32 PartialReception; /* TRUE - partial reception, FALSE otherwise */
393 SMSHOSTLIB_ISDBT_LAYER_STAT_ST LayerInfo[3]; //!< Per-layer statistics, see SMSHOSTLIB_ISDBT_LAYER_STAT_ST 394 UINT32 NumOfLayers; /* Number of ISDB-T layers in the network */
394 395
395 // Interface information 396 /* Per-layer information */
396 UINT32 SmsToHostTxErrors; //!< Total number of transmission errors. 397 /* Layers A, B and C */
398 SMSHOSTLIB_ISDBT_LAYER_STAT_ST LayerInfo[3]; /* Per-layer statistics, see SMSHOSTLIB_ISDBT_LAYER_STAT_ST */
399
400 /* Interface information */
401 UINT32 SmsToHostTxErrors; /* Total number of transmission errors. */
397 402
398} SMSHOSTLIB_STATISTICS_ISDBT_ST; 403} SMSHOSTLIB_STATISTICS_ISDBT_ST;
399 404
400typedef struct SMSHOSTLIB_STATISTICS_DVB_S 405typedef struct SMSHOSTLIB_STATISTICS_DVB_S
401{ 406{
402 UINT32 StatisticsType; //!< Enumerator identifying the type of the structure. Values are the same as SMSHOSTLIB_DEVICE_MODES_E 407 UINT32 StatisticsType; /* Enumerator identifying the type of the structure. Values are the same as SMSHOSTLIB_DEVICE_MODES_E
403 //!< This fiels MUST always first in any statistics structure 408 * This fiels MUST always first in any statistics structure */
404 409
405 UINT32 FullSize; //!< Total size of the structure returned by the modem. If the size requested by 410 UINT32 FullSize; /* Total size of the structure returned by the modem. If the size requested by
406 //!< the host is smaller than FullSize, the struct will be truncated 411 * the host is smaller than FullSize, the struct will be truncated */
407 // Common parameters 412 /* Common parameters */
408 UINT32 IsRfLocked; //!< 0 - not locked, 1 - locked 413 UINT32 IsRfLocked; /* 0 - not locked, 1 - locked */
409 UINT32 IsDemodLocked; //!< 0 - not locked, 1 - locked 414 UINT32 IsDemodLocked; /* 0 - not locked, 1 - locked */
410 UINT32 IsExternalLNAOn; //!< 0 - external LNA off, 1 - external LNA on 415 UINT32 IsExternalLNAOn; /* 0 - external LNA off, 1 - external LNA on */
411 416
412 // Reception quality 417 /* Reception quality */
413 INT32 SNR; //!< dB 418 INT32 SNR; /* dB */
414 UINT32 BER; //!< Post Viterbi BER [1E-5] 419 UINT32 BER; /* Post Viterbi BER [1E-5] */
415 UINT32 BERErrorCount; //!< Number of errornous SYNC bits. 420 UINT32 BERErrorCount; /* Number of errornous SYNC bits. */
416 UINT32 BERBitCount; //!< Total number of SYNC bits. 421 UINT32 BERBitCount; /* Total number of SYNC bits. */
417 UINT32 TS_PER; //!< Transport stream PER, 0xFFFFFFFF indicate N/A 422 UINT32 TS_PER; /* Transport stream PER, 0xFFFFFFFF indicate N/A */
418 UINT32 MFER; //!< DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H 423 UINT32 MFER; /* DVB-H frame error rate in percentage, 0xFFFFFFFF indicate N/A, valid only for DVB-H */
419 INT32 RSSI; //!< dBm 424 INT32 RSSI; /* dBm */
420 INT32 InBandPwr; //!< In band power in dBM 425 INT32 InBandPwr; /* In band power in dBM */
421 INT32 CarrierOffset; //!< Carrier Offset in bin/1024 426 INT32 CarrierOffset; /* Carrier Offset in bin/1024 */
422 427
423 // Transmission parameters 428 /* Transmission parameters */
424 UINT32 Frequency; //!< Frequency in Hz 429 UINT32 Frequency; /* Frequency in Hz */
425 UINT32 Bandwidth; //!< Bandwidth in MHz 430 UINT32 Bandwidth; /* Bandwidth in MHz */
426 UINT32 ModemState; //!< from SMSHOSTLIB_DVB_MODEM_STATE_ET 431 UINT32 ModemState; /* from SMSHOSTLIB_DVB_MODEM_STATE_ET */
427 UINT32 TransmissionMode; //!< FFT mode carriers in Kilos 432 UINT32 TransmissionMode; /* FFT mode carriers in Kilos */
428 UINT32 GuardInterval; //!< Guard Interval, 1 divided by value 433 UINT32 GuardInterval; /* Guard Interval, 1 divided by value */
429 UINT32 CodeRate; //!< Code Rate from SMSHOSTLIB_CODE_RATE_ET 434 UINT32 CodeRate; /* Code Rate from SMSHOSTLIB_CODE_RATE_ET */
430 UINT32 LPCodeRate; //!< Low Priority Code Rate from SMSHOSTLIB_CODE_RATE_ET 435 UINT32 LPCodeRate; /* Low Priority Code Rate from SMSHOSTLIB_CODE_RATE_ET */
431 UINT32 Hierarchy; //!< Hierarchy from SMSHOSTLIB_HIERARCHY_ET 436 UINT32 Hierarchy; /* Hierarchy from SMSHOSTLIB_HIERARCHY_ET */
432 UINT32 Constellation; //!< Constellation from SMSHOSTLIB_CONSTELLATION_ET 437 UINT32 Constellation; /* Constellation from SMSHOSTLIB_CONSTELLATION_ET */
433 438
434 // Burst parameters, valid only for DVB-H 439 /* Burst parameters, valid only for DVB-H */
435 UINT32 BurstSize; //!< Current burst size in bytes, valid only for DVB-H 440 UINT32 BurstSize; /* Current burst size in bytes, valid only for DVB-H */
436 UINT32 BurstDuration; //!< Current burst duration in mSec, valid only for DVB-H 441 UINT32 BurstDuration; /* Current burst duration in mSec, valid only for DVB-H */
437 UINT32 BurstCycleTime; //!< Current burst cycle time in mSec, valid only for DVB-H 442 UINT32 BurstCycleTime; /* Current burst cycle time in mSec, valid only for DVB-H */
438 UINT32 CalculatedBurstCycleTime;//!< Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H 443 UINT32 CalculatedBurstCycleTime; /* Current burst cycle time in mSec, as calculated by demodulator, valid only for DVB-H */
439 UINT32 NumOfRows; //!< Number of rows in MPE table, valid only for DVB-H 444 UINT32 NumOfRows; /* Number of rows in MPE table, valid only for DVB-H */
440 UINT32 NumOfPaddCols; //!< Number of padding columns in MPE table, valid only for DVB-H 445 UINT32 NumOfPaddCols; /* Number of padding columns in MPE table, valid only for DVB-H */
441 UINT32 NumOfPunctCols; //!< Number of puncturing columns in MPE table, valid only for DVB-H 446 UINT32 NumOfPunctCols; /* Number of puncturing columns in MPE table, valid only for DVB-H */
442 UINT32 ErrorTSPackets; //!< Number of erroneous transport-stream packets 447 UINT32 ErrorTSPackets; /* Number of erroneous transport-stream packets */
443 UINT32 TotalTSPackets; //!< Total number of transport-stream packets 448 UINT32 TotalTSPackets; /* Total number of transport-stream packets */
444 UINT32 NumOfValidMpeTlbs; //!< Number of MPE tables which do not include errors after MPE RS decoding, valid only for DVB-H 449 UINT32 NumOfValidMpeTlbs; /* Number of MPE tables which do not include errors after MPE RS decoding, valid only for DVB-H */
445 UINT32 NumOfInvalidMpeTlbs; //!< Number of MPE tables which include errors after MPE RS decoding, valid only for DVB-H 450 UINT32 NumOfInvalidMpeTlbs; /* Number of MPE tables which include errors after MPE RS decoding, valid only for DVB-H */
446 UINT32 NumOfCorrectedMpeTlbs; //!< Number of MPE tables which were corrected by MPE RS decoding, valid only for DVB-H 451 UINT32 NumOfCorrectedMpeTlbs; /* Number of MPE tables which were corrected by MPE RS decoding, valid only for DVB-H */
447 UINT32 NumMPEReceived; //!< DVB-H, Num MPE section received 452 UINT32 NumMPEReceived; /* DVB-H, Num MPE section received */
448 453
449 // DVB-H TPS parameters 454 /* DVB-H TPS parameters */
450 UINT32 CellId; //!< TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered 455 UINT32 CellId; /* TPS Cell ID in bits 15..0, bits 31..16 zero; if set to 0xFFFFFFFF cell_id not yet recovered */
451 UINT32 DvbhSrvIndHP; //!< DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator 456 UINT32 DvbhSrvIndHP; /* DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator */
452 UINT32 DvbhSrvIndLP; //!< DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator 457 UINT32 DvbhSrvIndLP; /* DVB-H service indication info, bit 1 - Time Slicing indicator, bit 0 - MPE-FEC indicator */
453 458
454 // Interface information 459 /* Interface information */
455 UINT32 SmsToHostTxErrors; //!< Total number of transmission errors. 460 UINT32 SmsToHostTxErrors; /* Total number of transmission errors. */
456 461
457} SMSHOSTLIB_STATISTICS_DVB_ST; 462} SMSHOSTLIB_STATISTICS_DVB_ST;
458 463
459typedef struct SMSHOSTLIB_GPIO_CONFIG_S 464typedef struct SMSHOSTLIB_GPIO_CONFIG_S
460{ 465{
461 UINT8 Direction; //!< GPIO direction: Input - 0, Output - 1 466 UINT8 Direction; /* GPIO direction: Input - 0, Output - 1 */
462 UINT8 PullUpDown; //!< PullUp/PullDown: None - 0, PullDown - 1, PullUp - 2, Keeper - 3 467 UINT8 PullUpDown; /* PullUp/PullDown: None - 0, PullDown - 1, PullUp - 2, Keeper - 3 */
463 UINT8 InputCharacteristics; //!< Input Characteristics: Normal - 0, Schmitt trigger - 1 468 UINT8 InputCharacteristics; /* Input Characteristics: Normal - 0, Schmitt trigger - 1 */
464 UINT8 OutputSlewRate; //!< Output Slew Rate: Fast slew rate - 0, Slow slew rate - 1 469 UINT8 OutputSlewRate; /* Output Slew Rate: Fast slew rate - 0, Slow slew rate - 1 */
465 UINT8 OutputDriving; //!< Output driving capability: 4mA - 0, 8mA - 1, 12mA - 2, 16mA - 3 470 UINT8 OutputDriving; /* Output driving capability: 4mA - 0, 8mA - 1, 12mA - 2, 16mA - 3 */
466} SMSHOSTLIB_GPIO_CONFIG_ST; 471} SMSHOSTLIB_GPIO_CONFIG_ST;
467 472
468typedef struct SMSHOSTLIB_I2C_REQ_S 473typedef struct SMSHOSTLIB_I2C_REQ_S
469{ 474{
470 UINT32 DeviceAddress; // I2c device address 475 UINT32 DeviceAddress; /* I2c device address */
471 UINT32 WriteCount; // number of bytes to write 476 UINT32 WriteCount; /* number of bytes to write */
472 UINT32 ReadCount; // number of bytes to read 477 UINT32 ReadCount; /* number of bytes to read */
473 UINT8 Data[1]; 478 UINT8 Data[1];
474} SMSHOSTLIB_I2C_REQ_ST; 479} SMSHOSTLIB_I2C_REQ_ST;
475 480
476typedef struct SMSHOSTLIB_I2C_RES_S 481typedef struct SMSHOSTLIB_I2C_RES_S
477{ 482{
478 UINT32 Status; // non-zero value in case of failure 483 UINT32 Status; /* non-zero value in case of failure */
479 UINT32 ReadCount; // number of bytes read 484 UINT32 ReadCount; /* number of bytes read */
480 UINT8 Data[1]; 485 UINT8 Data[1];
481} SMSHOSTLIB_I2C_RES_ST; 486} SMSHOSTLIB_I2C_RES_ST;
482 487
@@ -492,12 +497,12 @@ typedef struct _smsdvb_client
492 struct dmxdev dmxdev; 497 struct dmxdev dmxdev;
493 struct dvb_frontend frontend; 498 struct dvb_frontend frontend;
494 499
495 fe_status_t fe_status; 500 fe_status_t fe_status;
496 int fe_ber, fe_snr, fe_signal_strength; 501 int fe_ber, fe_snr, fe_signal_strength;
497 502
498 struct completion tune_done, stat_done; 503 struct completion tune_done, stat_done;
499 504
500 // todo: save freq/band instead whole struct 505 /* todo: save freq/band instead whole struct */
501 struct dvb_frontend_parameters fe_params; 506 struct dvb_frontend_parameters fe_params;
502 507
503} smsdvb_client_t; 508} smsdvb_client_t;
@@ -508,14 +513,17 @@ extern int smscore_registry_getmode(char *devpath);
508extern int smscore_register_hotplug(hotplug_t hotplug); 513extern int smscore_register_hotplug(hotplug_t hotplug);
509extern void smscore_unregister_hotplug(hotplug_t hotplug); 514extern void smscore_unregister_hotplug(hotplug_t hotplug);
510 515
511extern int smscore_register_device(smsdevice_params_t *params, smscore_device_t **coredev); 516extern int smscore_register_device(smsdevice_params_t *params,
517 smscore_device_t **coredev);
512extern void smscore_unregister_device(smscore_device_t *coredev); 518extern void smscore_unregister_device(smscore_device_t *coredev);
513 519
514extern int smscore_start_device(smscore_device_t *coredev); 520extern int smscore_start_device(smscore_device_t *coredev);
515extern int smscore_load_firmware(smscore_device_t *coredev, char *filename, 521extern int smscore_load_firmware(smscore_device_t *coredev, char *filename,
516 loadfirmware_t loadfirmware_handler); 522 loadfirmware_t loadfirmware_handler);
517 523
518extern int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8 *buffer, int size, int new_mode); 524extern int smscore_load_firmware_from_buffer(smscore_device_t *coredev,
525 u8 *buffer, int size,
526 int new_mode);
519 527
520extern int smscore_set_device_mode(smscore_device_t *coredev, int mode); 528extern int smscore_set_device_mode(smscore_device_t *coredev, int mode);
521extern int smscore_get_device_mode(smscore_device_t *coredev); 529extern int smscore_get_device_mode(smscore_device_t *coredev);
@@ -525,8 +533,10 @@ extern int smscore_register_client(smscore_device_t *coredev,
525 smscore_client_t **client); 533 smscore_client_t **client);
526extern void smscore_unregister_client(smscore_client_t *client); 534extern void smscore_unregister_client(smscore_client_t *client);
527 535
528extern int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size); 536extern int smsclient_sendrequest(smscore_client_t *client,
529extern void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb); 537 void *buffer, size_t size);
538extern void smscore_onresponse(smscore_device_t *coredev,
539 smscore_buffer_t *cb);
530 540
531extern int smscore_get_common_buffer_size(smscore_device_t *coredev); 541extern int smscore_get_common_buffer_size(smscore_device_t *coredev);
532extern int smscore_map_common_buffer(smscore_device_t *coredev, 542extern int smscore_map_common_buffer(smscore_device_t *coredev,
@@ -543,4 +553,4 @@ void smsdvb_unregister(void);
543int smsusb_register(void); 553int smsusb_register(void);
544void smsusb_unregister(void); 554void smsusb_unregister(void);
545 555
546#endif // __smscoreapi_h__ 556#endif /* __smscoreapi_h__ */
diff --git a/drivers/media/dvb/siano/smsdvb.c b/drivers/media/dvb/siano/smsdvb.c
index e050e0da7900..13980fb649c4 100644
--- a/drivers/media/dvb/siano/smsdvb.c
+++ b/drivers/media/dvb/siano/smsdvb.c
@@ -34,47 +34,49 @@ int smsdvb_onresponse(void *context, smscore_buffer_t *cb)
34 smsdvb_client_t *client = (smsdvb_client_t *) context; 34 smsdvb_client_t *client = (smsdvb_client_t *) context;
35 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)(((u8 *) cb->p) + cb->offset); 35 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)(((u8 *) cb->p) + cb->offset);
36 36
37 switch(phdr->msgType) 37 switch(phdr->msgType) {
38 { 38 case MSG_SMS_DVBT_BDA_DATA:
39 case MSG_SMS_DVBT_BDA_DATA: 39 dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1),
40 dvb_dmx_swfilter(&client->demux, (u8 *)(phdr + 1), 40 cb->size - sizeof(SmsMsgHdr_ST));
41 cb->size - sizeof(SmsMsgHdr_ST)); 41 break;
42 break; 42
43 case MSG_SMS_RF_TUNE_RES:
44 complete(&client->tune_done);
45 break;
43 46
44 case MSG_SMS_RF_TUNE_RES: 47 case MSG_SMS_GET_STATISTICS_RES:
45 complete(&client->tune_done); 48 {
46 break; 49 SmsMsgStatisticsInfo_ST *p =
50 (SmsMsgStatisticsInfo_ST *)(phdr + 1);
47 51
48 case MSG_SMS_GET_STATISTICS_RES: 52 if (p->Stat.IsDemodLocked)
49 { 53 {
50 SmsMsgStatisticsInfo_ST *p = 54 client->fe_status = FE_HAS_SIGNAL |
51 (SmsMsgStatisticsInfo_ST *)(phdr + 1); 55 FE_HAS_CARRIER |
52 56 FE_HAS_VITERBI |
53 if (p->Stat.IsDemodLocked) 57 FE_HAS_SYNC |
54 { 58 FE_HAS_LOCK;
55 client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 59
56 client->fe_snr = p->Stat.SNR; 60 client->fe_snr = p->Stat.SNR;
57 client->fe_ber = p->Stat.BER; 61 client->fe_ber = p->Stat.BER;
58
59 if (p->Stat.InBandPwr < -95)
60 client->fe_signal_strength = 0;
61 else if (p->Stat.InBandPwr > -29)
62 client->fe_signal_strength = 100;
63 else
64 client->fe_signal_strength = (p->Stat.InBandPwr + 95) * 3 / 2;
65 }
66 else
67 {
68 client->fe_status = 0;
69 client->fe_snr =
70 client->fe_ber =
71 client->fe_signal_strength = 0;
72 }
73 62
74 complete(&client->stat_done); 63 if (p->Stat.InBandPwr < -95)
75 break; 64 client->fe_signal_strength = 0;
65 else if (p->Stat.InBandPwr > -29)
66 client->fe_signal_strength = 100;
67 else
68 client->fe_signal_strength =
69 (p->Stat.InBandPwr + 95) * 3 / 2;
70 } else {
71 client->fe_status = 0;
72 client->fe_snr =
73 client->fe_ber =
74 client->fe_signal_strength = 0;
76 } 75 }
77 } 76
77 complete(&client->stat_done);
78 break;
79 } }
78 80
79 smscore_putbuffer(client->coredev, cb); 81 smscore_putbuffer(client->coredev, cb);
80 82
@@ -106,7 +108,8 @@ void smsdvb_onremove(void *context)
106 108
107static int smsdvb_start_feed(struct dvb_demux_feed *feed) 109static int smsdvb_start_feed(struct dvb_demux_feed *feed)
108{ 110{
109 smsdvb_client_t *client = container_of(feed->demux, smsdvb_client_t, demux); 111 smsdvb_client_t *client =
112 container_of(feed->demux, smsdvb_client_t, demux);
110 SmsMsgData_ST PidMsg; 113 SmsMsgData_ST PidMsg;
111 114
112 printk("%s add pid %d(%x)\n", __func__, feed->pid, feed->pid); 115 printk("%s add pid %d(%x)\n", __func__, feed->pid, feed->pid);
@@ -118,12 +121,14 @@ static int smsdvb_start_feed(struct dvb_demux_feed *feed)
118 PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); 121 PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
119 PidMsg.msgData[0] = feed->pid; 122 PidMsg.msgData[0] = feed->pid;
120 123
121 return smsclient_sendrequest(client->smsclient, &PidMsg, sizeof(PidMsg)); 124 return smsclient_sendrequest(client->smsclient,
125 &PidMsg, sizeof(PidMsg));
122} 126}
123 127
124static int smsdvb_stop_feed(struct dvb_demux_feed *feed) 128static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
125{ 129{
126 smsdvb_client_t *client = container_of(feed->demux, smsdvb_client_t, demux); 130 smsdvb_client_t *client =
131 container_of(feed->demux, smsdvb_client_t, demux);
127 SmsMsgData_ST PidMsg; 132 SmsMsgData_ST PidMsg;
128 133
129 printk("%s remove pid %d(%x)\n", __func__, feed->pid, feed->pid); 134 printk("%s remove pid %d(%x)\n", __func__, feed->pid, feed->pid);
@@ -135,7 +140,8 @@ static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
135 PidMsg.xMsgHeader.msgLength = sizeof(PidMsg); 140 PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
136 PidMsg.msgData[0] = feed->pid; 141 PidMsg.msgData[0] = feed->pid;
137 142
138 return smsclient_sendrequest(client->smsclient, &PidMsg, sizeof(PidMsg)); 143 return smsclient_sendrequest(client->smsclient,
144 &PidMsg, sizeof(PidMsg));
139} 145}
140 146
141static int smsdvb_sendrequest_and_wait(smsdvb_client_t *client, 147static int smsdvb_sendrequest_and_wait(smsdvb_client_t *client,
@@ -146,13 +152,18 @@ static int smsdvb_sendrequest_and_wait(smsdvb_client_t *client,
146 if (rc < 0) 152 if (rc < 0)
147 return rc; 153 return rc;
148 154
149 return wait_for_completion_timeout(completion, msecs_to_jiffies(2000)) ? 0 : -ETIME; 155 return wait_for_completion_timeout(completion,
156 msecs_to_jiffies(2000)) ?
157 0 : -ETIME;
150} 158}
151 159
152static int smsdvb_send_statistics_request(smsdvb_client_t *client) 160static int smsdvb_send_statistics_request(smsdvb_client_t *client)
153{ 161{
154 SmsMsgHdr_ST Msg = { MSG_SMS_GET_STATISTICS_REQ, DVBT_BDA_CONTROL_MSG_ID, HIF_TASK, sizeof(SmsMsgHdr_ST), 0 }; 162 SmsMsgHdr_ST Msg = { MSG_SMS_GET_STATISTICS_REQ,
155 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), &client->stat_done); 163 DVBT_BDA_CONTROL_MSG_ID,
164 HIF_TASK, sizeof(SmsMsgHdr_ST), 0 };
165 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
166 &client->stat_done);
156} 167}
157 168
158static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat) 169static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat)
@@ -199,7 +210,8 @@ static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
199 return rc; 210 return rc;
200} 211}
201 212
202static int smsdvb_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend_tune_settings *tune) 213static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
214 struct dvb_frontend_tune_settings *tune)
203{ 215{
204 printk("%s\n", __func__); 216 printk("%s\n", __func__);
205 217
@@ -209,14 +221,15 @@ static int smsdvb_get_tune_settings(struct dvb_frontend *fe, struct dvb_frontend
209 return 0; 221 return 0;
210} 222}
211 223
212static int smsdvb_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep) 224static int smsdvb_set_frontend(struct dvb_frontend *fe,
225 struct dvb_frontend_parameters *fep)
213{ 226{
214 smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); 227 smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend);
215 228
216 struct 229 struct
217 { 230 {
218 SmsMsgHdr_ST Msg; 231 SmsMsgHdr_ST Msg;
219 u32 Data[3]; 232 u32 Data[3];
220 } Msg; 233 } Msg;
221 234
222 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID; 235 Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
@@ -227,29 +240,32 @@ static int smsdvb_set_frontend(struct dvb_frontend *fe, struct dvb_frontend_para
227 Msg.Data[0] = fep->frequency; 240 Msg.Data[0] = fep->frequency;
228 Msg.Data[2] = 12000000; 241 Msg.Data[2] = 12000000;
229 242
230 printk("%s freq %d band %d\n", __func__, fep->frequency, fep->u.ofdm.bandwidth); 243 printk("%s freq %d band %d\n", __func__,
244 fep->frequency, fep->u.ofdm.bandwidth);
231 245
232 switch(fep->u.ofdm.bandwidth) 246 switch(fep->u.ofdm.bandwidth)
233 { 247 {
234 case BANDWIDTH_8_MHZ: Msg.Data[1] = BW_8_MHZ; break; 248 case BANDWIDTH_8_MHZ: Msg.Data[1] = BW_8_MHZ; break;
235 case BANDWIDTH_7_MHZ: Msg.Data[1] = BW_7_MHZ; break; 249 case BANDWIDTH_7_MHZ: Msg.Data[1] = BW_7_MHZ; break;
236 case BANDWIDTH_6_MHZ: Msg.Data[1] = BW_6_MHZ; break; 250 case BANDWIDTH_6_MHZ: Msg.Data[1] = BW_6_MHZ; break;
237// case BANDWIDTH_5_MHZ: Msg.Data[1] = BW_5_MHZ; break;
238 case BANDWIDTH_AUTO: return -EOPNOTSUPP; 251 case BANDWIDTH_AUTO: return -EOPNOTSUPP;
239 default: return -EINVAL; 252 default: return -EINVAL;
240 } 253 }
241 254
242 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg), &client->tune_done); 255 return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
256 &client->tune_done);
243} 257}
244 258
245static int smsdvb_get_frontend(struct dvb_frontend *fe, struct dvb_frontend_parameters *fep) 259static int smsdvb_get_frontend(struct dvb_frontend *fe,
260 struct dvb_frontend_parameters *fep)
246{ 261{
247 smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend); 262 smsdvb_client_t *client = container_of(fe, smsdvb_client_t, frontend);
248 263
249 printk("%s\n", __func__); 264 printk("%s\n", __func__);
250 265
251 // todo: 266 // todo:
252 memcpy(fep, &client->fe_params, sizeof(struct dvb_frontend_parameters)); 267 memcpy(fep, &client->fe_params,
268 sizeof(struct dvb_frontend_parameters));
253 return 0; 269 return 0;
254} 270}
255 271
@@ -260,19 +276,19 @@ static void smsdvb_release(struct dvb_frontend *fe)
260 276
261static struct dvb_frontend_ops smsdvb_fe_ops = { 277static struct dvb_frontend_ops smsdvb_fe_ops = {
262 .info = { 278 .info = {
263 .name = "Siano Mobile Digital SMS10xx", 279 .name = "Siano Mobile Digital SMS10xx",
264 .type = FE_OFDM, 280 .type = FE_OFDM,
265 .frequency_min = 44250000, 281 .frequency_min = 44250000,
266 .frequency_max = 867250000, 282 .frequency_max = 867250000,
267 .frequency_stepsize = 250000, 283 .frequency_stepsize = 250000,
268 .caps = FE_CAN_INVERSION_AUTO | 284 .caps = FE_CAN_INVERSION_AUTO |
269 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | 285 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
270 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | 286 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
271 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | 287 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
272 FE_CAN_TRANSMISSION_MODE_AUTO | 288 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
273 FE_CAN_GUARD_INTERVAL_AUTO | 289 FE_CAN_GUARD_INTERVAL_AUTO |
274 FE_CAN_RECOVER | 290 FE_CAN_RECOVER |
275 FE_CAN_HIERARCHY_AUTO, 291 FE_CAN_HIERARCHY_AUTO,
276 }, 292 },
277 293
278 .release = smsdvb_release, 294 .release = smsdvb_release,
@@ -287,8 +303,8 @@ static struct dvb_frontend_ops smsdvb_fe_ops = {
287 .read_snr = smsdvb_read_snr, 303 .read_snr = smsdvb_read_snr,
288}; 304};
289 305
290int smsdvb_hotplug(smscore_device_t *coredev, struct device *device, 306int smsdvb_hotplug(smscore_device_t *coredev,
291 int arrival) 307 struct device *device, int arrival)
292{ 308{
293 smsclient_params_t params; 309 smsclient_params_t params;
294 smsdvb_client_t *client; 310 smsdvb_client_t *client;
@@ -298,23 +314,21 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
298 if (!arrival) 314 if (!arrival)
299 return 0; 315 return 0;
300 316
301 if (smscore_get_device_mode(coredev) != 4) 317 if (smscore_get_device_mode(coredev) != 4) {
302 {
303 printk(KERN_ERR "%sSMS Device mode is not set for DVB operation.\n", __func__); 318 printk(KERN_ERR "%sSMS Device mode is not set for DVB operation.\n", __func__);
304 return 0; 319 return 0;
305 } 320 }
306 321
307 client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL); 322 client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL);
308 if (!client) 323 if (!client) {
309 {
310 printk(KERN_INFO "%s kmalloc() failed\n", __func__); 324 printk(KERN_INFO "%s kmalloc() failed\n", __func__);
311 return -ENOMEM; 325 return -ENOMEM;
312 } 326 }
313 327
314 // register dvb adapter 328 // register dvb adapter
315 rc = dvb_register_adapter(&client->adapter, "Siano Digital Receiver", THIS_MODULE, device, adapter_nr); 329 rc = dvb_register_adapter(&client->adapter, "Siano Digital Receiver",
316 if (rc < 0) 330 THIS_MODULE, device, adapter_nr);
317 { 331 if (rc < 0) {
318 printk("%s dvb_register_adapter() failed %d\n", __func__, rc); 332 printk("%s dvb_register_adapter() failed %d\n", __func__, rc);
319 goto adapter_error; 333 goto adapter_error;
320 } 334 }
@@ -327,8 +341,7 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
327 client->demux.stop_feed = smsdvb_stop_feed; 341 client->demux.stop_feed = smsdvb_stop_feed;
328 342
329 rc = dvb_dmx_init(&client->demux); 343 rc = dvb_dmx_init(&client->demux);
330 if (rc < 0) 344 if (rc < 0) {
331 {
332 printk("%s dvb_dmx_init failed %d\n\n", __func__, rc); 345 printk("%s dvb_dmx_init failed %d\n\n", __func__, rc);
333 goto dvbdmx_error; 346 goto dvbdmx_error;
334 } 347 }
@@ -339,18 +352,17 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
339 client->dmxdev.capabilities = 0; 352 client->dmxdev.capabilities = 0;
340 353
341 rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter); 354 rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
342 if (rc < 0) 355 if (rc < 0) {
343 {
344 printk("%s dvb_dmxdev_init failed %d\n", __func__, rc); 356 printk("%s dvb_dmxdev_init failed %d\n", __func__, rc);
345 goto dmxdev_error; 357 goto dmxdev_error;
346 } 358 }
347 359
348 // init and register frontend 360 // init and register frontend
349 memcpy(&client->frontend.ops, &smsdvb_fe_ops, sizeof(struct dvb_frontend_ops)); 361 memcpy(&client->frontend.ops, &smsdvb_fe_ops,
362 sizeof(struct dvb_frontend_ops));
350 363
351 rc = dvb_register_frontend(&client->adapter, &client->frontend); 364 rc = dvb_register_frontend(&client->adapter, &client->frontend);
352 if (rc < 0) 365 if (rc < 0) {
353 {
354 printk("%s frontend registration failed %d\n", __func__, rc); 366 printk("%s frontend registration failed %d\n", __func__, rc);
355 goto frontend_error; 367 goto frontend_error;
356 } 368 }
@@ -362,9 +374,9 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
362 params.context = client; 374 params.context = client;
363 375
364 rc = smscore_register_client(coredev, &params, &client->smsclient); 376 rc = smscore_register_client(coredev, &params, &client->smsclient);
365 if (rc < 0) 377 if (rc < 0) {
366 { 378 printk(KERN_INFO "%s smscore_register_client() failed %d\n",
367 printk(KERN_INFO "%s smscore_register_client() failed %d\n", __func__, rc); 379 __func__, rc);
368 goto client_error; 380 goto client_error;
369 } 381 }
370 382
@@ -421,9 +433,8 @@ void smsdvb_unregister(void)
421 kmutex_lock(&g_smsdvb_clientslock); 433 kmutex_lock(&g_smsdvb_clientslock);
422 434
423 while (!list_empty(&g_smsdvb_clients)) 435 while (!list_empty(&g_smsdvb_clients))
424 smsdvb_unregister_client((smsdvb_client_t *) g_smsdvb_clients.next); 436 smsdvb_unregister_client(
437 (smsdvb_client_t *) g_smsdvb_clients.next);
425 438
426 kmutex_unlock(&g_smsdvb_clientslock); 439 kmutex_unlock(&g_smsdvb_clientslock);
427
428} 440}
429
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