aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2008-06-13 23:43:26 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-07-20 06:21:09 -0400
commitf17407a85db3b86526d54e65698348873a6df617 (patch)
treeed1271461dc9faa88bcadf58a57fcc16b1adebf7
parent55ad310c2f21281f50fa040b7765a4a1151bd420 (diff)
V4L/DVB (8277): sms1xxx: update latest siano drop to 1.2.17
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.c363
-rw-r--r--drivers/media/dvb/siano/smscoreapi.h11
-rw-r--r--drivers/media/dvb/siano/smsdvb.c7
-rw-r--r--drivers/media/dvb/siano/smsusb.c48
4 files changed, 273 insertions, 156 deletions
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index 86a4b5de5e1c..76fa0f50775c 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -33,32 +33,47 @@
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)
37
38#ifdef SMSCORE_DEBUG
39
40#undef PWARNING
41# define PWARNING(fmt, args...) printk( KERN_INFO "smscore warning: line %d- %s(): " fmt,__LINE__, __func__, ## args)
42#undef PDEBUG /* undef it, just in case */
43# define PDEBUG(fmt, args...) printk( KERN_INFO "smscore - %s(): " fmt, __func__, ## args)
44
45#else /*SMSCORE_DEBUG*/
46
47#define PDEBUG(fmt, args...)
48#define PWARNING(fmt, args...)
49
50#endif
51
52
36typedef struct _smscore_device_notifyee 53typedef struct _smscore_device_notifyee
37{ 54{
38 struct list_head entry; 55 struct list_head entry;
39 hotplug_t hotplug; 56 hotplug_t hotplug;
40} smscore_device_notifyee_t; 57} smscore_device_notifyee_t;
41 58
59typedef struct _smscore_subclient
60{
61 struct list_head entry;
62 int id;
63 int data_type;
64} smscore_idlist_t;
65
42typedef struct _smscore_client 66typedef struct _smscore_client
43{ 67{
44 struct list_head entry; 68 struct list_head entry;
45 smscore_device_t *coredev; 69 smscore_device_t *coredev;
46
47 void *context; 70 void *context;
48 71 struct list_head idlist;
49 int data_type;
50
51 onresponse_t onresponse_handler; 72 onresponse_t onresponse_handler;
52 onremove_t onremove_handler; 73 onremove_t onremove_handler;
53} *psmscore_client_t; 74} *psmscore_client_t;
54 75
55typedef struct _smscore_subclient
56{
57 struct list_head entry;
58 smscore_client_t *client;
59 76
60 int id;
61} smscore_subclient_t;
62 77
63typedef struct _smscore_device 78typedef struct _smscore_device
64{ 79{
@@ -99,6 +114,7 @@ typedef struct _smscore_registry_entry
99 struct list_head entry; 114 struct list_head entry;
100 char devpath[32]; 115 char devpath[32];
101 int mode; 116 int mode;
117 sms_device_type_st type;
102} smscore_registry_entry_t; 118} smscore_registry_entry_t;
103 119
104struct list_head g_smscore_notifyees; 120struct list_head g_smscore_notifyees;
@@ -109,63 +125,102 @@ struct list_head g_smscore_registry;
109kmutex_t g_smscore_registrylock; 125kmutex_t g_smscore_registrylock;
110 126
111static int default_mode = 1; 127static int default_mode = 1;
128
112module_param(default_mode, int, 0644); 129module_param(default_mode, int, 0644);
113MODULE_PARM_DESC(default_mode, "default firmware id (device mode)"); 130MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
114 131
115int smscore_registry_getmode(char *devpath) 132static smscore_registry_entry_t *smscore_find_registry ( char *devpath )
116{ 133{
117 smscore_registry_entry_t *entry; 134 smscore_registry_entry_t *entry;
118 struct list_head *next; 135 struct list_head *next;
119 136
120 kmutex_lock(&g_smscore_registrylock); 137 kmutex_lock(&g_smscore_registrylock);
121
122 for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) 138 for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next)
123 { 139 {
124 entry = (smscore_registry_entry_t *) next; 140 entry = (smscore_registry_entry_t *) next;
125
126 if (!strcmp(entry->devpath, devpath)) 141 if (!strcmp(entry->devpath, devpath))
127 { 142 {
128 kmutex_unlock(&g_smscore_registrylock); 143 kmutex_unlock(&g_smscore_registrylock);
129 return entry->mode; 144 return entry;
130 } 145 }
131 } 146 }
132
133 entry = (smscore_registry_entry_t *) kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL); 147 entry = (smscore_registry_entry_t *) kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL);
134 if (entry) 148 if (entry)
135 { 149 {
136 entry->mode = default_mode; 150 entry->mode = default_mode;
137 strcpy(entry->devpath, devpath); 151 strcpy(entry->devpath, devpath);
138
139 list_add(&entry->entry, &g_smscore_registry); 152 list_add(&entry->entry, &g_smscore_registry);
140 } 153 }
141 154 else
155 printk ( KERN_ERR "%s failed to create smscore_registry.\n", __func__ );
142 kmutex_unlock(&g_smscore_registrylock); 156 kmutex_unlock(&g_smscore_registrylock);
157 return entry;
158}
143 159
160int smscore_registry_getmode ( char *devpath )
161{
162 smscore_registry_entry_t *entry;
163
164 entry = smscore_find_registry ( devpath );
165 if ( entry )
166 {
167 return entry->mode;
168 }
169 else
170 {
171 printk ( KERN_ERR "%s No registry found.\n", __func__ );
172 }
144 return default_mode; 173 return default_mode;
145} 174}
146 175
147void smscore_registry_setmode(char *devpath, int mode) 176sms_device_type_st smscore_registry_gettype ( char *devpath )
148{ 177{
149 smscore_registry_entry_t *entry; 178 smscore_registry_entry_t *entry;
150 struct list_head *next;
151 179
152 kmutex_lock(&g_smscore_registrylock); 180 entry = smscore_find_registry ( devpath );
181 if ( entry )
182 {
183 return entry->type;
184 }
185 else
186 {
187 printk ( KERN_ERR "%s No registry found.\n", __func__ );
188 }
189 return -1;
190}
153 191
154 for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) 192void smscore_registry_setmode ( char *devpath, int mode )
155 { 193 {
156 entry = (smscore_registry_entry_t *) next; 194 smscore_registry_entry_t *entry;
157 195
158 if (!strcmp(entry->devpath, devpath)) 196 entry = smscore_find_registry ( devpath );
197 if ( entry )
159 { 198 {
160 entry->mode = mode; 199 entry->mode = mode;
161 break; 200 }
201 else
202 {
203 printk ( KERN_ERR "%s No registry found.\n", __func__ );
162 } 204 }
163 } 205 }
164 206
165 kmutex_unlock(&g_smscore_registrylock); 207void smscore_registry_settype ( char *devpath, sms_device_type_st type )
208{
209 smscore_registry_entry_t *entry;
210
211 entry = smscore_find_registry ( devpath );
212 if ( entry )
213 {
214 entry->type = type;
215 }
216 else
217 {
218 printk ( KERN_ERR "%s No registry found.\n", __func__ );
219}
166} 220}
167 221
168 222
223
169void list_add_locked(struct list_head *new, struct list_head *head, 224void list_add_locked(struct list_head *new, struct list_head *head,
170 spinlock_t *lock) 225 spinlock_t *lock)
171{ 226{
@@ -324,7 +379,6 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
324 379
325 // init queues 380 // init queues
326 INIT_LIST_HEAD(&dev->clients); 381 INIT_LIST_HEAD(&dev->clients);
327 INIT_LIST_HEAD(&dev->subclients);
328 INIT_LIST_HEAD(&dev->buffers); 382 INIT_LIST_HEAD(&dev->buffers);
329 383
330 // init locks 384 // init locks
@@ -375,6 +429,8 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
375 dev->device_flags = params->flags; 429 dev->device_flags = params->flags;
376 strcpy(dev->devpath, params->devpath); 430 strcpy(dev->devpath, params->devpath);
377 431
432 smscore_registry_settype ( dev->devpath, params->device_type );
433
378 // add device to devices list 434 // add device to devices list
379 kmutex_lock(&g_smscore_deviceslock); 435 kmutex_lock(&g_smscore_deviceslock);
380 list_add(&dev->entry, &g_smscore_devices); 436 list_add(&dev->entry, &g_smscore_devices);
@@ -398,7 +454,10 @@ int smscore_start_device(smscore_device_t *coredev)
398{ 454{
399 int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath)); 455 int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath));
400 if (rc < 0) 456 if (rc < 0)
457 {
458 printk ( KERN_INFO "%s set device mode faile , rc %d\n", __func__, rc );
401 return rc; 459 return rc;
460 }
402 461
403 kmutex_lock(&g_smscore_deviceslock); 462 kmutex_lock(&g_smscore_deviceslock);
404 463
@@ -416,9 +475,12 @@ int smscore_sendrequest_and_wait(smscore_device_t *coredev, void *buffer,
416{ 475{
417 int rc = coredev->sendrequest_handler(coredev->context, buffer, size); 476 int rc = coredev->sendrequest_handler(coredev->context, buffer, size);
418 if (rc < 0) 477 if (rc < 0)
478 {
479 printk(KERN_INFO "%s sendrequest returned error %d\n", __func__, rc);
419 return rc; 480 return rc;
481 }
420 482
421 return wait_for_completion_timeout(completion, msecs_to_jiffies(1000)) ? 0 : -ETIME; 483 return wait_for_completion_timeout(completion, msecs_to_jiffies(10000)) ? 0 : -ETIME;
422} 484}
423 485
424int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_t size) 486int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_t size)
@@ -429,6 +491,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
429 u8 *payload = firmware->Payload; 491 u8 *payload = firmware->Payload;
430 int rc = 0; 492 int rc = 0;
431 493
494 printk(KERN_INFO "%s loading FW to addr 0x%x size %d\n", __func__, mem_address,firmware->Length);
432 if (coredev->preload_handler) 495 if (coredev->preload_handler)
433 { 496 {
434 rc = coredev->preload_handler(coredev->context); 497 rc = coredev->preload_handler(coredev->context);
@@ -443,6 +506,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
443 506
444 if (coredev->mode != DEVICE_MODE_NONE) 507 if (coredev->mode != DEVICE_MODE_NONE)
445 { 508 {
509 PDEBUG("Sending reload command\n");
446 SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, sizeof(SmsMsgHdr_ST)); 510 SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, sizeof(SmsMsgHdr_ST));
447 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->reload_start_done); 511 rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->reload_start_done);
448 mem_address = *(UINT32*) &payload[20]; 512 mem_address = *(UINT32*) &payload[20];
@@ -496,13 +560,14 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
496 560
497 rc = coredev->sendrequest_handler(coredev->context, msg, msg->msgLength); 561 rc = coredev->sendrequest_handler(coredev->context, msg, msg->msgLength);
498 } 562 }
563 msleep ( 500 );
499 } 564 }
500 565
501 printk("%s %d \n", __func__, rc); 566 printk("%s rc=%d, postload=%p \n", __func__, rc, coredev->postload_handler);
502 567
503 kfree(msg); 568 kfree(msg);
504 569
505 return (rc >= 0 && coredev->postload_handler) ? 570 return ((rc >= 0) && coredev->postload_handler) ?
506 coredev->postload_handler(coredev->context) : 571 coredev->postload_handler(coredev->context) :
507 rc; 572 rc;
508} 573}
@@ -516,8 +581,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
516 * 581 *
517 * @return 0 on success, <0 on error. 582 * @return 0 on success, <0 on error.
518 */ 583 */
519int smscore_load_firmware(smscore_device_t *coredev, char *filename, 584int smscore_load_firmware_from_file(smscore_device_t *coredev, char *filename, loadfirmware_t loadfirmware_handler)
520 loadfirmware_t loadfirmware_handler)
521{ 585{
522 int rc = -ENOENT; 586 int rc = -ENOENT;
523 587
@@ -533,7 +597,7 @@ int smscore_load_firmware(smscore_device_t *coredev, char *filename,
533 printk(KERN_INFO "%s failed to open \"%s\"\n", __func__, filename); 597 printk(KERN_INFO "%s failed to open \"%s\"\n", __func__, filename);
534 return rc; 598 return rc;
535 } 599 }
536 600 printk(KERN_INFO "%s read FW %s, size=%d\"\n", __func__, filename, fw->size);
537 fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA); 601 fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA);
538 if (fw_buffer) 602 if (fw_buffer)
539 { 603 {
@@ -556,6 +620,12 @@ int smscore_load_firmware(smscore_device_t *coredev, char *filename,
556 return rc; 620 return rc;
557} 621}
558 622
623int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8* buffer, int size, int new_mode)
624{
625 PERROR("Feature not implemented yet\n");
626 return -EFAULT;
627}
628
559/** 629/**
560 * notifies all clients registered with the device, notifies hotplugs, frees all buffers and coredev object 630 * notifies all clients registered with the device, notifies hotplugs, frees all buffers and coredev object
561 * 631 *
@@ -567,6 +637,7 @@ void smscore_unregister_device(smscore_device_t *coredev)
567{ 637{
568 smscore_buffer_t *cb; 638 smscore_buffer_t *cb;
569 int num_buffers = 0; 639 int num_buffers = 0;
640 int retry = 0;
570 641
571 kmutex_lock(&g_smscore_deviceslock); 642 kmutex_lock(&g_smscore_deviceslock);
572 643
@@ -583,9 +654,13 @@ void smscore_unregister_device(smscore_device_t *coredev)
583 kfree(cb); 654 kfree(cb);
584 num_buffers ++; 655 num_buffers ++;
585 } 656 }
586
587 if (num_buffers == coredev->num_buffers) 657 if (num_buffers == coredev->num_buffers)
588 break; 658 break;
659 if (++retry > 10)
660 {
661 printk(KERN_INFO "%s exiting although not all buffers released.\n", __func__);
662 break;
663 }
589 664
590 printk(KERN_INFO "%s waiting for %d buffer(s)\n", __func__, coredev->num_buffers - num_buffers); 665 printk(KERN_INFO "%s waiting for %d buffer(s)\n", __func__, coredev->num_buffers - num_buffers);
591 msleep(100); 666 msleep(100);
@@ -637,19 +712,20 @@ int smscore_detect_mode(smscore_device_t *coredev)
637 return rc; 712 return rc;
638} 713}
639 714
640char *smscore_fw_lkup[] = 715char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] =
641{ 716{
642 "dvb_nova_12mhz.inp", 717 /*Stellar NOVA A0 Nova B0 VEGA*/
643 "dvb_nova_12mhz.inp", 718 /*DVBT*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
644 "tdmb_nova.inp", 719 /*DVBH*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
645 "none", 720 /*TDMB*/ {"none", "tdmb_nova_12mhz.inp", "none" "none"},
646 "dvb_nova_12mhz.inp", 721 /*DABIP*/ {"none", "none", "none", "none"},
647 "isdbt_nova_12mhz.inp", 722 /*BDA*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
648 "isdbt_nova_12mhz.inp", 723 /*ISDBT*/ {"none", "isdbt_nova_12mhz.inp", "dvb_nova_12mhz.inp", "none"},
649 "cmmb_nova_12mhz.inp", 724 /*ISDBTBDA*/{"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
650 "none", 725 /*CMMB*/ {"none", "none", "none", "cmmb_vega_12mhz.inp"}
651}; 726};
652 727
728
653/** 729/**
654 * calls device handler to change mode of operation 730 * calls device handler to change mode of operation
655 * NOTE: stellar/usb may disconnect when changing mode 731 * NOTE: stellar/usb may disconnect when changing mode
@@ -663,7 +739,9 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
663{ 739{
664 void *buffer; 740 void *buffer;
665 int rc = 0; 741 int rc = 0;
742 sms_device_type_st type;
666 743
744 PDEBUG("set device mode to %d\n", mode );
667 if (coredev->device_flags & SMS_DEVICE_FAMILY2) 745 if (coredev->device_flags & SMS_DEVICE_FAMILY2)
668 { 746 {
669 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_RAW_TUNER) 747 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_RAW_TUNER)
@@ -672,12 +750,17 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
672 return -EINVAL; 750 return -EINVAL;
673 } 751 }
674 752
753 smscore_registry_setmode(coredev->devpath, mode);
754
675 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) 755 if (!(coredev->device_flags & SMS_DEVICE_NOT_READY))
676 { 756 {
677 rc = smscore_detect_mode(coredev); 757 rc = smscore_detect_mode(coredev);
678 if (rc < 0) 758 if (rc < 0)
759 {
760 printk(KERN_INFO "%s mode detect failed %d\n", __func__, rc);
679 return rc; 761 return rc;
680 } 762 }
763 }
681 764
682 if (coredev->mode == mode) 765 if (coredev->mode == mode)
683 { 766 {
@@ -687,10 +770,14 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
687 770
688 if (!(coredev->modes_supported & (1 << mode))) 771 if (!(coredev->modes_supported & (1 << mode)))
689 { 772 {
690 rc = smscore_load_firmware(coredev, smscore_fw_lkup[mode], NULL); 773 type = smscore_registry_gettype ( coredev->devpath );
774 rc = smscore_load_firmware_from_file ( coredev, smscore_fw_lkup[mode][type], NULL );
691 if (rc < 0) 775 if (rc < 0)
776 {
777 printk(KERN_INFO "%s load firmware failed %d\n", __func__, rc);
692 return rc; 778 return rc;
693 } 779 }
780 }
694 else 781 else
695 { 782 {
696 printk(KERN_INFO "%s mode %d supported by running firmware\n", __func__, mode); 783 printk(KERN_INFO "%s mode %d supported by running firmware\n", __func__, mode);
@@ -709,10 +796,21 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
709 kfree(buffer); 796 kfree(buffer);
710 } 797 }
711 else 798 else
799 {
800 printk(KERN_INFO "%s Could not allocate buffer for init device message.\n", __func__);
712 rc = -ENOMEM; 801 rc = -ENOMEM;
713 } 802 }
803 }
714 else 804 else
715 { 805 {
806 if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA)
807 {
808 printk(KERN_INFO "%s invalid mode specified %d\n", __func__, mode);
809 return -EINVAL;
810 }
811
812 smscore_registry_setmode(coredev->devpath, mode);
813
716 if (coredev->detectmode_handler) 814 if (coredev->detectmode_handler)
717 coredev->detectmode_handler(coredev->context, &coredev->mode); 815 coredev->detectmode_handler(coredev->context, &coredev->mode);
718 816
@@ -720,14 +818,14 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
720 rc = coredev->setmode_handler(coredev->context, mode); 818 rc = coredev->setmode_handler(coredev->context, mode);
721 } 819 }
722 820
723 smscore_registry_setmode(coredev->devpath, mode);
724
725 if (rc >= 0) 821 if (rc >= 0)
726 { 822 {
727 coredev->mode = mode; 823 coredev->mode = mode;
728 coredev->device_flags &= ~SMS_DEVICE_NOT_READY; 824 coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
729 } 825 }
730 826
827 if (rc != 0)
828 printk(KERN_INFO "%s return error code %d.\n", __func__, rc);
731 return rc; 829 return rc;
732} 830}
733 831
@@ -743,55 +841,40 @@ int smscore_get_device_mode(smscore_device_t *coredev)
743 return coredev->mode; 841 return coredev->mode;
744} 842}
745 843
746smscore_client_t *smscore_getclient_by_type(smscore_device_t *coredev, 844/**
747 int data_type) 845 * find client by response id & type within the clients list.
846 * return client handle or NULL.
847 *
848 * @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)
850 * @param id client id (SMS_DONT_CARE for all id )
851 *
852 */
853smscore_client_t *smscore_find_client(smscore_device_t *coredev, int data_type, int id)
748{ 854{
749 smscore_client_t *client = NULL; 855 smscore_client_t *client = NULL;
750 struct list_head *next, *first; 856 struct list_head *next, *first;
751 unsigned long flags; 857 unsigned long flags;
858 struct list_head *firstid, *nextid;
752 859
753 if (!data_type)
754 return NULL;
755 860
756 spin_lock_irqsave(&coredev->clientslock, flags); 861 spin_lock_irqsave(&coredev->clientslock, flags);
757
758 first = &coredev->clients; 862 first = &coredev->clients;
759 863 for (next = first->next; (next != first) && !client; next = next->next)
760 for (next = first->next; next != first; next = next->next) 864 {
865 firstid = &((smscore_client_t*)next )->idlist;
866 for (nextid = firstid->next ; nextid != firstid ; nextid = nextid->next)
761 { 867 {
762 if (((smscore_client_t*) next)->data_type == data_type) 868 if ((((smscore_idlist_t*)nextid)->id == id) &&
869 (((smscore_idlist_t*)nextid)->data_type == data_type ||
870 (((smscore_idlist_t*)nextid)->data_type == 0)))
763 { 871 {
764 client = (smscore_client_t*) next; 872 client = (smscore_client_t*) next;
765 break; 873 break;
766 } 874 }
767 } 875 }
768
769 spin_unlock_irqrestore(&coredev->clientslock, flags);
770
771 return client;
772}
773
774smscore_client_t *smscore_getclient_by_id(smscore_device_t *coredev, int id)
775{
776 smscore_client_t *client = NULL;
777 struct list_head *next, *first;
778 unsigned long flags;
779
780 spin_lock_irqsave(&coredev->clientslock, flags);
781
782 first = &coredev->subclients;
783
784 for (next = first->next; next != first; next = next->next)
785 {
786 if (((smscore_subclient_t*) next)->id == id)
787 {
788 client = ((smscore_subclient_t*) next)->client;
789 break;
790 }
791 } 876 }
792
793 spin_unlock_irqrestore(&coredev->clientslock, flags); 877 spin_unlock_irqrestore(&coredev->clientslock, flags);
794
795 return client; 878 return client;
796} 879}
797 880
@@ -806,8 +889,7 @@ smscore_client_t *smscore_getclient_by_id(smscore_device_t *coredev, int id)
806void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb) 889void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
807{ 890{
808 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8*) cb->p + cb->offset); 891 SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8*) cb->p + cb->offset);
809 smscore_client_t *client = smscore_getclient_by_type(coredev, 892 smscore_client_t *client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId);
810 phdr->msgType);
811 int rc = -EBUSY; 893 int rc = -EBUSY;
812 894
813 static unsigned long last_sample_time = 0; 895 static unsigned long last_sample_time = 0;
@@ -826,10 +908,9 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
826 } 908 }
827 909
828 data_total += cb->size; 910 data_total += cb->size;
829 911 /* If no client registered for type & id, check for control client where type is not registered*/
830 if (!client) 912// if (!client)
831 client = smscore_getclient_by_id(coredev, phdr->msgDstId); 913// client = smscore_find_client( coredev, 0, phdr->msgDstId);
832
833 if (client) 914 if (client)
834 rc = client->onresponse_handler(client->context, cb); 915 rc = client->onresponse_handler(client->context, cb);
835 916
@@ -877,7 +958,8 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
877 break; 958 break;
878 959
879 default: 960 default:
880 printk(KERN_INFO "%s no client (%p) or error (%d), type:%d dstid:%d\n", __func__, client, rc, phdr->msgType, phdr->msgDstId); 961 //printk(KERN_INFO "%s no client (%p) or error (%d), type:%d dstid:%d\n", __func__, client, rc, phdr->msgType, phdr->msgDstId);
962 break;
881 } 963 }
882 964
883 smscore_putbuffer(coredev, cb); 965 smscore_putbuffer(coredev, cb);
@@ -921,30 +1003,35 @@ void smscore_putbuffer(smscore_device_t *coredev, smscore_buffer_t *cb)
921 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); 1003 list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
922} 1004}
923 1005
924int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, int id) 1006int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, int data_type, int id)
925{ 1007{
926 smscore_client_t *existing_client; 1008 smscore_idlist_t *listentry;
927 smscore_subclient_t *subclient; 1009 smscore_client_t *registered_client;
928 1010
929 if (!id) 1011 if ( !client )
930 return 0; 1012 {
931 1013 PERROR("bad parameter.\n");
932 existing_client = smscore_getclient_by_id(coredev, id); 1014 return -EFAULT;
933 if (existing_client == client) 1015 }
1016 registered_client = smscore_find_client(coredev, data_type, id);
1017 if (registered_client == client)
1018 {
934 return 0; 1019 return 0;
935 1020 }
936 if (existing_client) 1021 if (registered_client)
937 return -EBUSY; 1022 {
938 1023 PERROR("The msg ID already registered to another client.\n");
939 subclient = kzalloc(sizeof(smscore_subclient_t), GFP_KERNEL); 1024 return -EEXIST;
940 if (!subclient) 1025 }
1026 listentry = kzalloc ( sizeof ( smscore_idlist_t ), GFP_KERNEL );
1027 if ( !listentry )
1028 {
1029 PERROR("Can't allocate memory for client id.\n");
941 return -ENOMEM; 1030 return -ENOMEM;
942 1031 }
943 subclient->client = client; 1032 listentry->id = id;
944 subclient->id = id; 1033 listentry->data_type = data_type;
945 1034 list_add_locked ( &listentry->entry, &client->idlist, &coredev->clientslock );
946 list_add_locked(&subclient->entry, &coredev->subclients, &coredev->clientslock);
947
948 return 0; 1035 return 0;
949} 1036}
950 1037
@@ -964,35 +1051,29 @@ int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client,
964int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client) 1051int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client)
965{ 1052{
966 smscore_client_t *newclient; 1053 smscore_client_t *newclient;
967 int rc; 1054 // check that no other channel with same parameters exists
968 1055 if (smscore_find_client(coredev, params->data_type, params->initial_id))
969 // check that no other channel with same data type exists 1056 {
970 if (params->data_type && smscore_getclient_by_type(coredev, params->data_type)) 1057 PERROR("Client already exist.\n");
971 return -EEXIST; 1058 return -EEXIST;
1059 }
972 1060
973 newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL); 1061 newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL);
974 if (!newclient) 1062 if (!newclient)
975 return -ENOMEM;
976
977 // check that no other channel with same id exists
978 rc = smscore_validate_client(coredev, newclient, params->initial_id);
979 if (rc < 0)
980 { 1063 {
981 kfree(newclient); 1064 PERROR("Failed to allocate memory for client.\n");
982 return rc; 1065 return -ENOMEM;
983 } 1066 }
984 1067
1068 INIT_LIST_HEAD ( &newclient->idlist);
985 newclient->coredev = coredev; 1069 newclient->coredev = coredev;
986 newclient->data_type = params->data_type;
987 newclient->onresponse_handler = params->onresponse_handler; 1070 newclient->onresponse_handler = params->onresponse_handler;
988 newclient->onremove_handler = params->onremove_handler; 1071 newclient->onremove_handler = params->onremove_handler;
989 newclient->context = params->context; 1072 newclient->context = params->context;
990
991 list_add_locked(&newclient->entry, &coredev->clients, &coredev->clientslock); 1073 list_add_locked(&newclient->entry, &coredev->clients, &coredev->clientslock);
992 1074 smscore_validate_client(coredev, newclient, params->data_type, params->initial_id);
993 *client = newclient; 1075 *client = newclient;
994 1076 PDEBUG ( "%p %d %d\n", params->context, params->data_type, params->initial_id );
995 printk(KERN_INFO "%s %p %d %d\n", __func__, params->context, params->data_type, params->initial_id);
996 1077
997 return 0; 1078 return 0;
998} 1079}
@@ -1006,26 +1087,19 @@ int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *param
1006void smscore_unregister_client(smscore_client_t *client) 1087void smscore_unregister_client(smscore_client_t *client)
1007{ 1088{
1008 smscore_device_t *coredev = client->coredev; 1089 smscore_device_t *coredev = client->coredev;
1009 struct list_head *next, *first;
1010 unsigned long flags; 1090 unsigned long flags;
1011 1091
1012 spin_lock_irqsave(&coredev->clientslock, flags); 1092 spin_lock_irqsave(&coredev->clientslock, flags);
1013 1093
1014 first = &coredev->subclients;
1015 1094
1016 for (next = first->next; next != first;) 1095 while (!list_empty( &client->idlist))
1017 {
1018 smscore_subclient_t *subclient = (smscore_subclient_t *) next;
1019 next = next->next;
1020
1021 if (subclient->client == client)
1022 { 1096 {
1023 list_del(&subclient->entry); 1097 smscore_idlist_t *identry = (smscore_idlist_t*)client->idlist.next;
1024 kfree(subclient); 1098 list_del ( &identry->entry );
1025 } 1099 kfree ( identry );
1026 } 1100 }
1027 1101
1028 printk(KERN_INFO "%s %p %d\n", __func__, client->context, client->data_type); 1102 printk(KERN_INFO "%s %p\n", __func__, client->context);
1029 1103
1030 list_del(&client->entry); 1104 list_del(&client->entry);
1031 kfree(client); 1105 kfree(client);
@@ -1045,11 +1119,26 @@ void smscore_unregister_client(smscore_client_t *client)
1045 */ 1119 */
1046int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size) 1120int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size)
1047{ 1121{
1048 smscore_device_t *coredev = client->coredev; 1122 smscore_device_t *coredev;
1049 SmsMsgHdr_ST* phdr = (SmsMsgHdr_ST*) buffer; 1123 SmsMsgHdr_ST* phdr = (SmsMsgHdr_ST*) buffer;
1124 int rc;
1125
1126 if ( client == NULL )
1127 {
1128 printk(KERN_ERR "%s Got NULL client\n", __func__ );
1129 return -EINVAL;
1130 }
1131
1132 coredev = client->coredev;
1050 1133
1051 // check that no other channel with same id exists 1134 // check that no other channel with same id exists
1052 int rc = smscore_validate_client(client->coredev, client, phdr->msgSrcId); 1135 if ( coredev == NULL )
1136 {
1137 printk(KERN_ERR "%s Got NULL coredev\n", __func__ );
1138 return -EINVAL;
1139 }
1140
1141 rc = smscore_validate_client(client->coredev, client, 0, phdr->msgSrcId);
1053 if (rc < 0) 1142 if (rc < 0)
1054 return rc; 1143 return rc;
1055 1144
@@ -1160,6 +1249,6 @@ module_init(smscore_module_init);
1160module_exit(smscore_module_exit); 1249module_exit(smscore_module_exit);
1161 1250
1162MODULE_DESCRIPTION("smscore"); 1251MODULE_DESCRIPTION("smscore");
1163MODULE_AUTHOR("Anatoly Greenblatt,,, (anatolyg@siano-ms.com)"); 1252MODULE_AUTHOR ( "Siano Mobile Silicon,,, (doronc@siano-ms.com)" );
1164MODULE_LICENSE("GPL"); 1253MODULE_LICENSE("GPL");
1165 1254
diff --git a/drivers/media/dvb/siano/smscoreapi.h b/drivers/media/dvb/siano/smscoreapi.h
index e44507417d28..c0a3be2fae72 100644
--- a/drivers/media/dvb/siano/smscoreapi.h
+++ b/drivers/media/dvb/siano/smscoreapi.h
@@ -56,6 +56,14 @@ typedef struct mutex kmutex_t;
56#define SMS_ROM_NO_RESPONSE 2 56#define SMS_ROM_NO_RESPONSE 2
57#define SMS_DEVICE_NOT_READY 0x8000000 57#define SMS_DEVICE_NOT_READY 0x8000000
58 58
59typedef enum {
60 SMS_STELLAR= 0,
61 SMS_NOVA_A0,
62 SMS_NOVA_B0,
63 SMS_VEGA,
64 SMS_NUM_OF_DEVICE_TYPES
65} sms_device_type_st;
66
59typedef struct _smscore_device smscore_device_t; 67typedef struct _smscore_device smscore_device_t;
60typedef struct _smscore_client smscore_client_t; 68typedef struct _smscore_client smscore_client_t;
61typedef struct _smscore_buffer smscore_buffer_t; 69typedef struct _smscore_buffer smscore_buffer_t;
@@ -102,6 +110,7 @@ typedef struct _smsdevice_params
102 postload_t postload_handler; 110 postload_t postload_handler;
103 111
104 void *context; 112 void *context;
113 sms_device_type_st device_type;
105} smsdevice_params_t; 114} smsdevice_params_t;
106 115
107typedef struct _smsclient_params 116typedef struct _smsclient_params
@@ -506,6 +515,8 @@ extern int smscore_start_device(smscore_device_t *coredev);
506extern int smscore_load_firmware(smscore_device_t *coredev, char *filename, 515extern int smscore_load_firmware(smscore_device_t *coredev, char *filename,
507 loadfirmware_t loadfirmware_handler); 516 loadfirmware_t loadfirmware_handler);
508 517
518extern int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8* buffer, int size, int new_mode);
519
509extern int smscore_set_device_mode(smscore_device_t *coredev, int mode); 520extern int smscore_set_device_mode(smscore_device_t *coredev, int mode);
510extern int smscore_get_device_mode(smscore_device_t *coredev); 521extern int smscore_get_device_mode(smscore_device_t *coredev);
511 522
diff --git a/drivers/media/dvb/siano/smsdvb.c b/drivers/media/dvb/siano/smsdvb.c
index 6975e7c61f87..e050e0da7900 100644
--- a/drivers/media/dvb/siano/smsdvb.c
+++ b/drivers/media/dvb/siano/smsdvb.c
@@ -300,9 +300,8 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
300 300
301 if (smscore_get_device_mode(coredev) != 4) 301 if (smscore_get_device_mode(coredev) != 4)
302 { 302 {
303 rc = smscore_set_device_mode(coredev, 4); 303 printk(KERN_ERR "%sSMS Device mode is not set for DVB operation.\n", __func__);
304 if (rc < 0) 304 return 0;
305 return rc;
306 } 305 }
307 306
308 client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL); 307 client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL);
@@ -356,7 +355,7 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
356 goto frontend_error; 355 goto frontend_error;
357 } 356 }
358 357
359 params.initial_id = 0; 358 params.initial_id = 1;
360 params.data_type = MSG_SMS_DVBT_BDA_DATA; 359 params.data_type = MSG_SMS_DVBT_BDA_DATA;
361 params.onresponse_handler = smsdvb_onresponse; 360 params.onresponse_handler = smsdvb_onresponse;
362 params.onremove_handler = smsdvb_onremove; 361 params.onremove_handler = smsdvb_onremove;
diff --git a/drivers/media/dvb/siano/smsusb.c b/drivers/media/dvb/siano/smsusb.c
index 1677f8591508..f719b72424d1 100644
--- a/drivers/media/dvb/siano/smsusb.c
+++ b/drivers/media/dvb/siano/smsusb.c
@@ -301,21 +301,32 @@ int smsusb_init_device(struct usb_interface *intf)
301 usb_set_intfdata(intf, dev); 301 usb_set_intfdata(intf, dev);
302 dev->udev = interface_to_usbdev(intf); 302 dev->udev = interface_to_usbdev(intf);
303 303
304 switch (dev->udev->descriptor.idProduct) 304 switch (dev->udev->descriptor.idProduct) {
305 { 305 case 0x100:
306 case 0x100: 306 dev->buffer_size = USB1_BUFFER_SIZE;
307 dev->buffer_size = USB1_BUFFER_SIZE; 307
308 308 params.setmode_handler = smsusb1_setmode;
309 params.setmode_handler = smsusb1_setmode; 309 params.detectmode_handler = smsusb1_detectmode;
310 params.detectmode_handler = smsusb1_detectmode; 310 params.device_type = SMS_STELLAR;
311 break; 311 printk(KERN_INFO "%s stellar device found\n", __func__ );
312 break;
313 default:
314 if (dev->udev->descriptor.idProduct == 0x200) {
315 params.device_type = SMS_NOVA_A0;
316 printk(KERN_INFO "%s nova A0 found\n", __FUNCTION__ );
317 } else if (dev->udev->descriptor.idProduct == 0x201) {
318 params.device_type = SMS_NOVA_B0;
319 printk(KERN_INFO "%s nova B0 found\n", __FUNCTION__);
320 } else {
321 params.device_type = SMS_VEGA;
322 printk(KERN_INFO "%s Vega found\n", __FUNCTION__);
323 }
312 324
313 default: 325 dev->buffer_size = USB2_BUFFER_SIZE;
314 dev->buffer_size = USB2_BUFFER_SIZE; 326 dev->response_alignment = dev->udev->ep_in[1]->desc.wMaxPacketSize - sizeof(SmsMsgHdr_ST);
315 dev->response_alignment = dev->udev->ep_in[1]->desc.wMaxPacketSize - sizeof(SmsMsgHdr_ST);
316 327
317 params.flags |= SMS_DEVICE_FAMILY2; 328 params.flags |= SMS_DEVICE_FAMILY2;
318 break; 329 break;
319 } 330 }
320 331
321 params.device = &dev->udev->dev; 332 params.device = &dev->udev->dev;
@@ -341,6 +352,7 @@ int smsusb_init_device(struct usb_interface *intf)
341 usb_init_urb(&dev->surbs[i].urb); 352 usb_init_urb(&dev->surbs[i].urb);
342 } 353 }
343 354
355 printk(KERN_INFO "%s smsusb_start_streaming(...).\n", __func__);
344 rc = smsusb_start_streaming(dev); 356 rc = smsusb_start_streaming(dev);
345 if (rc < 0) 357 if (rc < 0)
346 { 358 {
@@ -368,6 +380,9 @@ int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
368 char devpath[32]; 380 char devpath[32];
369 int i, rc; 381 int i, rc;
370 382
383 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
384 rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
385
371 if (intf->num_altsetting > 0) 386 if (intf->num_altsetting > 0)
372 { 387 {
373 rc = usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 0); 388 rc = usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 0);
@@ -390,11 +405,14 @@ int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
390 405
391 if (intf->cur_altsetting->desc.bInterfaceNumber == 1) 406 if (intf->cur_altsetting->desc.bInterfaceNumber == 1)
392 { 407 {
393 snprintf(devpath, 32, "%d:%s", udev->bus->busnum, udev->devpath); 408 snprintf(devpath, sizeof(devpath), "usb\\%d-%s", udev->bus->busnum, udev->devpath);
409 printk(KERN_INFO "stellar device was found.\n");
394 return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath)); 410 return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath));
395 } 411 }
396 412
397 return smsusb_init_device(intf); 413 rc = smsusb_init_device(intf);
414 printk(KERN_INFO "%s rc %d\n", __FUNCTION__, rc);
415 return rc;
398} 416}
399 417
400void smsusb_disconnect(struct usb_interface *intf) 418void smsusb_disconnect(struct usb_interface *intf)