Commit f17407a8 authored by Michael Krufky's avatar Michael Krufky Committed by Mauro Carvalho Chehab

V4L/DVB (8277): sms1xxx: update latest siano drop to 1.2.17

Signed-off-by: default avatarMichael Krufky <mkrufky@linuxtv.org>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 55ad310c
...@@ -33,32 +33,47 @@ ...@@ -33,32 +33,47 @@
#include "smscoreapi.h" #include "smscoreapi.h"
#define PERROR(fmt, args...) printk( KERN_ERR "smscore error: line %d- %s(): " fmt,__LINE__, __func__, ## args)
#ifdef SMSCORE_DEBUG
#undef PWARNING
# define PWARNING(fmt, args...) printk( KERN_INFO "smscore warning: line %d- %s(): " fmt,__LINE__, __func__, ## args)
#undef PDEBUG /* undef it, just in case */
# define PDEBUG(fmt, args...) printk( KERN_INFO "smscore - %s(): " fmt, __func__, ## args)
#else /*SMSCORE_DEBUG*/
#define PDEBUG(fmt, args...)
#define PWARNING(fmt, args...)
#endif
typedef struct _smscore_device_notifyee typedef struct _smscore_device_notifyee
{ {
struct list_head entry; struct list_head entry;
hotplug_t hotplug; hotplug_t hotplug;
} smscore_device_notifyee_t; } smscore_device_notifyee_t;
typedef struct _smscore_subclient
{
struct list_head entry;
int id;
int data_type;
} smscore_idlist_t;
typedef struct _smscore_client typedef struct _smscore_client
{ {
struct list_head entry; struct list_head entry;
smscore_device_t *coredev; smscore_device_t *coredev;
void *context; void *context;
struct list_head idlist;
int data_type;
onresponse_t onresponse_handler; onresponse_t onresponse_handler;
onremove_t onremove_handler; onremove_t onremove_handler;
} *psmscore_client_t; } *psmscore_client_t;
typedef struct _smscore_subclient
{
struct list_head entry;
smscore_client_t *client;
int id;
} smscore_subclient_t;
typedef struct _smscore_device typedef struct _smscore_device
{ {
...@@ -99,6 +114,7 @@ typedef struct _smscore_registry_entry ...@@ -99,6 +114,7 @@ typedef struct _smscore_registry_entry
struct list_head entry; struct list_head entry;
char devpath[32]; char devpath[32];
int mode; int mode;
sms_device_type_st type;
} smscore_registry_entry_t; } smscore_registry_entry_t;
struct list_head g_smscore_notifyees; struct list_head g_smscore_notifyees;
...@@ -109,63 +125,102 @@ struct list_head g_smscore_registry; ...@@ -109,63 +125,102 @@ struct list_head g_smscore_registry;
kmutex_t g_smscore_registrylock; kmutex_t g_smscore_registrylock;
static int default_mode = 1; static int default_mode = 1;
module_param(default_mode, int, 0644); module_param(default_mode, int, 0644);
MODULE_PARM_DESC(default_mode, "default firmware id (device mode)"); MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
int smscore_registry_getmode(char *devpath) static smscore_registry_entry_t *smscore_find_registry ( char *devpath )
{ {
smscore_registry_entry_t *entry; smscore_registry_entry_t *entry;
struct list_head *next; struct list_head *next;
kmutex_lock(&g_smscore_registrylock); kmutex_lock(&g_smscore_registrylock);
for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next)
{ {
entry = (smscore_registry_entry_t *) next; entry = (smscore_registry_entry_t *) next;
if (!strcmp(entry->devpath, devpath)) if (!strcmp(entry->devpath, devpath))
{ {
kmutex_unlock(&g_smscore_registrylock); kmutex_unlock(&g_smscore_registrylock);
return entry->mode; return entry;
} }
} }
entry = (smscore_registry_entry_t *) kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL); entry = (smscore_registry_entry_t *) kmalloc(sizeof(smscore_registry_entry_t), GFP_KERNEL);
if (entry) if (entry)
{ {
entry->mode = default_mode; entry->mode = default_mode;
strcpy(entry->devpath, devpath); strcpy(entry->devpath, devpath);
list_add(&entry->entry, &g_smscore_registry); list_add(&entry->entry, &g_smscore_registry);
} }
else
printk ( KERN_ERR "%s failed to create smscore_registry.\n", __func__ );
kmutex_unlock(&g_smscore_registrylock); kmutex_unlock(&g_smscore_registrylock);
return entry;
}
int smscore_registry_getmode ( char *devpath )
{
smscore_registry_entry_t *entry;
entry = smscore_find_registry ( devpath );
if ( entry )
{
return entry->mode;
}
else
{
printk ( KERN_ERR "%s No registry found.\n", __func__ );
}
return default_mode; return default_mode;
} }
void smscore_registry_setmode(char *devpath, int mode) sms_device_type_st smscore_registry_gettype ( char *devpath )
{ {
smscore_registry_entry_t *entry; smscore_registry_entry_t *entry;
struct list_head *next;
kmutex_lock(&g_smscore_registrylock); entry = smscore_find_registry ( devpath );
if ( entry )
{
return entry->type;
}
else
{
printk ( KERN_ERR "%s No registry found.\n", __func__ );
}
return -1;
}
for (next = g_smscore_registry.next; next != &g_smscore_registry; next = next->next) void smscore_registry_setmode ( char *devpath, int mode )
{ {
entry = (smscore_registry_entry_t *) next; smscore_registry_entry_t *entry;
if (!strcmp(entry->devpath, devpath)) entry = smscore_find_registry ( devpath );
if ( entry )
{ {
entry->mode = mode; entry->mode = mode;
break; }
else
{
printk ( KERN_ERR "%s No registry found.\n", __func__ );
} }
} }
kmutex_unlock(&g_smscore_registrylock); void smscore_registry_settype ( char *devpath, sms_device_type_st type )
{
smscore_registry_entry_t *entry;
entry = smscore_find_registry ( devpath );
if ( entry )
{
entry->type = type;
}
else
{
printk ( KERN_ERR "%s No registry found.\n", __func__ );
}
} }
void list_add_locked(struct list_head *new, struct list_head *head, void list_add_locked(struct list_head *new, struct list_head *head,
spinlock_t *lock) spinlock_t *lock)
{ {
...@@ -324,7 +379,6 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored ...@@ -324,7 +379,6 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
// init queues // init queues
INIT_LIST_HEAD(&dev->clients); INIT_LIST_HEAD(&dev->clients);
INIT_LIST_HEAD(&dev->subclients);
INIT_LIST_HEAD(&dev->buffers); INIT_LIST_HEAD(&dev->buffers);
// init locks // init locks
...@@ -375,6 +429,8 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored ...@@ -375,6 +429,8 @@ int smscore_register_device(smsdevice_params_t *params, smscore_device_t **cored
dev->device_flags = params->flags; dev->device_flags = params->flags;
strcpy(dev->devpath, params->devpath); strcpy(dev->devpath, params->devpath);
smscore_registry_settype ( dev->devpath, params->device_type );
// add device to devices list // add device to devices list
kmutex_lock(&g_smscore_deviceslock); kmutex_lock(&g_smscore_deviceslock);
list_add(&dev->entry, &g_smscore_devices); list_add(&dev->entry, &g_smscore_devices);
...@@ -398,7 +454,10 @@ int smscore_start_device(smscore_device_t *coredev) ...@@ -398,7 +454,10 @@ int smscore_start_device(smscore_device_t *coredev)
{ {
int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath)); int rc = smscore_set_device_mode(coredev, smscore_registry_getmode(coredev->devpath));
if (rc < 0) if (rc < 0)
{
printk ( KERN_INFO "%s set device mode faile , rc %d\n", __func__, rc );
return rc; return rc;
}
kmutex_lock(&g_smscore_deviceslock); kmutex_lock(&g_smscore_deviceslock);
...@@ -416,9 +475,12 @@ int smscore_sendrequest_and_wait(smscore_device_t *coredev, void *buffer, ...@@ -416,9 +475,12 @@ int smscore_sendrequest_and_wait(smscore_device_t *coredev, void *buffer,
{ {
int rc = coredev->sendrequest_handler(coredev->context, buffer, size); int rc = coredev->sendrequest_handler(coredev->context, buffer, size);
if (rc < 0) if (rc < 0)
{
printk(KERN_INFO "%s sendrequest returned error %d\n", __func__, rc);
return rc; return rc;
}
return wait_for_completion_timeout(completion, msecs_to_jiffies(1000)) ? 0 : -ETIME; return wait_for_completion_timeout(completion, msecs_to_jiffies(10000)) ? 0 : -ETIME;
} }
int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_t size) int 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,6 +491,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
u8 *payload = firmware->Payload; u8 *payload = firmware->Payload;
int rc = 0; int rc = 0;
printk(KERN_INFO "%s loading FW to addr 0x%x size %d\n", __func__, mem_address,firmware->Length);
if (coredev->preload_handler) if (coredev->preload_handler)
{ {
rc = coredev->preload_handler(coredev->context); rc = coredev->preload_handler(coredev->context);
...@@ -443,6 +506,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_ ...@@ -443,6 +506,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
if (coredev->mode != DEVICE_MODE_NONE) if (coredev->mode != DEVICE_MODE_NONE)
{ {
PDEBUG("Sending reload command\n");
SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, sizeof(SmsMsgHdr_ST)); SMS_INIT_MSG(msg, MSG_SW_RELOAD_START_REQ, sizeof(SmsMsgHdr_ST));
rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->reload_start_done); rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength, &coredev->reload_start_done);
mem_address = *(UINT32*) &payload[20]; mem_address = *(UINT32*) &payload[20];
...@@ -496,13 +560,14 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_ ...@@ -496,13 +560,14 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
rc = coredev->sendrequest_handler(coredev->context, msg, msg->msgLength); rc = coredev->sendrequest_handler(coredev->context, msg, msg->msgLength);
} }
msleep ( 500 );
} }
printk("%s %d \n", __func__, rc); printk("%s rc=%d, postload=%p \n", __func__, rc, coredev->postload_handler);
kfree(msg); kfree(msg);
return (rc >= 0 && coredev->postload_handler) ? return ((rc >= 0) && coredev->postload_handler) ?
coredev->postload_handler(coredev->context) : coredev->postload_handler(coredev->context) :
rc; rc;
} }
...@@ -516,8 +581,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_ ...@@ -516,8 +581,7 @@ int smscore_load_firmware_family2(smscore_device_t *coredev, void *buffer, size_
* *
* @return 0 on success, <0 on error. * @return 0 on success, <0 on error.
*/ */
int smscore_load_firmware(smscore_device_t *coredev, char *filename, int smscore_load_firmware_from_file(smscore_device_t *coredev, char *filename, loadfirmware_t loadfirmware_handler)
loadfirmware_t loadfirmware_handler)
{ {
int rc = -ENOENT; int rc = -ENOENT;
...@@ -533,7 +597,7 @@ int smscore_load_firmware(smscore_device_t *coredev, char *filename, ...@@ -533,7 +597,7 @@ int smscore_load_firmware(smscore_device_t *coredev, char *filename,
printk(KERN_INFO "%s failed to open \"%s\"\n", __func__, filename); printk(KERN_INFO "%s failed to open \"%s\"\n", __func__, filename);
return rc; return rc;
} }
printk(KERN_INFO "%s read FW %s, size=%d\"\n", __func__, filename, fw->size);
fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA); fw_buffer = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT), GFP_KERNEL | GFP_DMA);
if (fw_buffer) if (fw_buffer)
{ {
...@@ -556,6 +620,12 @@ int smscore_load_firmware(smscore_device_t *coredev, char *filename, ...@@ -556,6 +620,12 @@ int smscore_load_firmware(smscore_device_t *coredev, char *filename,
return rc; return rc;
} }
int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8* buffer, int size, int new_mode)
{
PERROR("Feature not implemented yet\n");
return -EFAULT;
}
/** /**
* notifies all clients registered with the device, notifies hotplugs, frees all buffers and coredev object * notifies all clients registered with the device, notifies hotplugs, frees all buffers and coredev object
* *
...@@ -567,6 +637,7 @@ void smscore_unregister_device(smscore_device_t *coredev) ...@@ -567,6 +637,7 @@ void smscore_unregister_device(smscore_device_t *coredev)
{ {
smscore_buffer_t *cb; smscore_buffer_t *cb;
int num_buffers = 0; int num_buffers = 0;
int retry = 0;
kmutex_lock(&g_smscore_deviceslock); kmutex_lock(&g_smscore_deviceslock);
...@@ -583,9 +654,13 @@ void smscore_unregister_device(smscore_device_t *coredev) ...@@ -583,9 +654,13 @@ void smscore_unregister_device(smscore_device_t *coredev)
kfree(cb); kfree(cb);
num_buffers ++; num_buffers ++;
} }
if (num_buffers == coredev->num_buffers) if (num_buffers == coredev->num_buffers)
break; break;
if (++retry > 10)
{
printk(KERN_INFO "%s exiting although not all buffers released.\n", __func__);
break;
}
printk(KERN_INFO "%s waiting for %d buffer(s)\n", __func__, coredev->num_buffers - num_buffers); printk(KERN_INFO "%s waiting for %d buffer(s)\n", __func__, coredev->num_buffers - num_buffers);
msleep(100); msleep(100);
...@@ -637,19 +712,20 @@ int smscore_detect_mode(smscore_device_t *coredev) ...@@ -637,19 +712,20 @@ int smscore_detect_mode(smscore_device_t *coredev)
return rc; return rc;
} }
char *smscore_fw_lkup[] = char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] =
{ {
"dvb_nova_12mhz.inp", /*Stellar NOVA A0 Nova B0 VEGA*/
"dvb_nova_12mhz.inp", /*DVBT*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
"tdmb_nova.inp", /*DVBH*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
"none", /*TDMB*/ {"none", "tdmb_nova_12mhz.inp", "none" "none"},
"dvb_nova_12mhz.inp", /*DABIP*/ {"none", "none", "none", "none"},
"isdbt_nova_12mhz.inp", /*BDA*/ {"none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none"},
"isdbt_nova_12mhz.inp", /*ISDBT*/ {"none", "isdbt_nova_12mhz.inp", "dvb_nova_12mhz.inp", "none"},
"cmmb_nova_12mhz.inp", /*ISDBTBDA*/{"none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none"},
"none", /*CMMB*/ {"none", "none", "none", "cmmb_vega_12mhz.inp"}
}; };
/** /**
* calls device handler to change mode of operation * calls device handler to change mode of operation
* NOTE: stellar/usb may disconnect when changing mode * NOTE: stellar/usb may disconnect when changing mode
...@@ -663,7 +739,9 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode) ...@@ -663,7 +739,9 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
{ {
void *buffer; void *buffer;
int rc = 0; int rc = 0;
sms_device_type_st type;
PDEBUG("set device mode to %d\n", mode );
if (coredev->device_flags & SMS_DEVICE_FAMILY2) if (coredev->device_flags & SMS_DEVICE_FAMILY2)
{ {
if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_RAW_TUNER) 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,12 +750,17 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
return -EINVAL; return -EINVAL;
} }
smscore_registry_setmode(coredev->devpath, mode);
if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) if (!(coredev->device_flags & SMS_DEVICE_NOT_READY))
{ {
rc = smscore_detect_mode(coredev); rc = smscore_detect_mode(coredev);
if (rc < 0) if (rc < 0)
{
printk(KERN_INFO "%s mode detect failed %d\n", __func__, rc);
return rc; return rc;
} }
}
if (coredev->mode == mode) if (coredev->mode == mode)
{ {
...@@ -687,10 +770,14 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode) ...@@ -687,10 +770,14 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
if (!(coredev->modes_supported & (1 << mode))) if (!(coredev->modes_supported & (1 << mode)))
{ {
rc = smscore_load_firmware(coredev, smscore_fw_lkup[mode], NULL); type = smscore_registry_gettype ( coredev->devpath );
rc = smscore_load_firmware_from_file ( coredev, smscore_fw_lkup[mode][type], NULL );
if (rc < 0) if (rc < 0)
{
printk(KERN_INFO "%s load firmware failed %d\n", __func__, rc);
return rc; return rc;
} }
}
else else
{ {
printk(KERN_INFO "%s mode %d supported by running firmware\n", __func__, mode); 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,10 +796,21 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
kfree(buffer); kfree(buffer);
} }
else else
{
printk(KERN_INFO "%s Could not allocate buffer for init device message.\n", __func__);
rc = -ENOMEM; rc = -ENOMEM;
} }
}
else else
{ {
if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA)
{
printk(KERN_INFO "%s invalid mode specified %d\n", __func__, mode);
return -EINVAL;
}
smscore_registry_setmode(coredev->devpath, mode);
if (coredev->detectmode_handler) if (coredev->detectmode_handler)
coredev->detectmode_handler(coredev->context, &coredev->mode); coredev->detectmode_handler(coredev->context, &coredev->mode);
...@@ -720,14 +818,14 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode) ...@@ -720,14 +818,14 @@ int smscore_set_device_mode(smscore_device_t *coredev, int mode)
rc = coredev->setmode_handler(coredev->context, mode); rc = coredev->setmode_handler(coredev->context, mode);
} }
smscore_registry_setmode(coredev->devpath, mode);
if (rc >= 0) if (rc >= 0)
{ {
coredev->mode = mode; coredev->mode = mode;
coredev->device_flags &= ~SMS_DEVICE_NOT_READY; coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
} }
if (rc != 0)
printk(KERN_INFO "%s return error code %d.\n", __func__, rc);
return rc; return rc;
} }
...@@ -743,55 +841,40 @@ int smscore_get_device_mode(smscore_device_t *coredev) ...@@ -743,55 +841,40 @@ int smscore_get_device_mode(smscore_device_t *coredev)
return coredev->mode; return coredev->mode;
} }
smscore_client_t *smscore_getclient_by_type(smscore_device_t *coredev, /**
int data_type) * find client by response id & type within the clients list.
* return client handle or NULL.
*
* @param coredev pointer to a coredev object returned by smscore_register_device
* @param data_type client data type (SMS_DONT_CARE for all types)
* @param id client id (SMS_DONT_CARE for all id )
*
*/
smscore_client_t *smscore_find_client(smscore_device_t *coredev, int data_type, int id)
{ {
smscore_client_t *client = NULL; smscore_client_t *client = NULL;
struct list_head *next, *first; struct list_head *next, *first;
unsigned long flags; unsigned long flags;
struct list_head *firstid, *nextid;
if (!data_type)
return NULL;
spin_lock_irqsave(&coredev->clientslock, flags); spin_lock_irqsave(&coredev->clientslock, flags);
first = &coredev->clients; first = &coredev->clients;
for (next = first->next; (next != first) && !client; next = next->next)
for (next = first->next; next != first; next = next->next) {
firstid = &((smscore_client_t*)next )->idlist;
for (nextid = firstid->next ; nextid != firstid ; nextid = nextid->next)
{ {
if (((smscore_client_t*) next)->data_type == data_type) if ((((smscore_idlist_t*)nextid)->id == id) &&
(((smscore_idlist_t*)nextid)->data_type == data_type ||
(((smscore_idlist_t*)nextid)->data_type == 0)))
{ {
client = (smscore_client_t*) next; client = (smscore_client_t*) next;
break; break;
} }
} }
spin_unlock_irqrestore(&coredev->clientslock, flags);
return client;
}
smscore_client_t *smscore_getclient_by_id(smscore_device_t *coredev, int id)
{
smscore_client_t *client = NULL;
struct list_head *next, *first;
unsigned long flags;
spin_lock_irqsave(&coredev->clientslock, flags);
first = &coredev->subclients;
for (next = first->next; next != first; next = next->next)
{
if (((smscore_subclient_t*) next)->id == id)
{
client = ((smscore_subclient_t*) next)->client;
break;
}
} }
spin_unlock_irqrestore(&coredev->clientslock, flags); spin_unlock_irqrestore(&coredev->clientslock, flags);
return client; return client;
} }
...@@ -806,8 +889,7 @@ smscore_client_t *smscore_getclient_by_id(smscore_device_t *coredev, int id) ...@@ -806,8 +889,7 @@ smscore_client_t *smscore_getclient_by_id(smscore_device_t *coredev, int id)
void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb) void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
{ {
SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8*) cb->p + cb->offset); SmsMsgHdr_ST *phdr = (SmsMsgHdr_ST *)((u8*) cb->p + cb->offset);
smscore_client_t *client = smscore_getclient_by_type(coredev, smscore_client_t *client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId);
phdr->msgType);
int rc = -EBUSY; int rc = -EBUSY;
static unsigned long last_sample_time = 0; static unsigned long last_sample_time = 0;
...@@ -826,10 +908,9 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb) ...@@ -826,10 +908,9 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
} }
data_total += cb->size; data_total += cb->size;
/* If no client registered for type & id, check for control client where type is not registered*/
if (!client) // if (!client)
client = smscore_getclient_by_id(coredev, phdr->msgDstId); // client = smscore_find_client( coredev, 0, phdr->msgDstId);
if (client) if (client)
rc = client->onresponse_handler(client->context, cb); rc = client->onresponse_handler(client->context, cb);
...@@ -877,7 +958,8 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb) ...@@ -877,7 +958,8 @@ void smscore_onresponse(smscore_device_t *coredev, smscore_buffer_t *cb)
break; break;
default: default:
printk(KERN_INFO "%s no client (%p) or error (%d), type:%d dstid:%d\n", __func__, client, rc, phdr->msgType, phdr->msgDstId); //printk(KERN_INFO "%s no client (%p) or error (%d), type:%d dstid:%d\n", __func__, client, rc, phdr->msgType, phdr->msgDstId);
break;
} }
smscore_putbuffer(coredev, cb); smscore_putbuffer(coredev, cb);
...@@ -921,30 +1003,35 @@ void smscore_putbuffer(smscore_device_t *coredev, smscore_buffer_t *cb) ...@@ -921,30 +1003,35 @@ void smscore_putbuffer(smscore_device_t *coredev, smscore_buffer_t *cb)
list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock); list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
} }
int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, int id) int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, int data_type, int id)
{ {
smscore_client_t *existing_client; smscore_idlist_t *listentry;
smscore_subclient_t *subclient; smscore_client_t *registered_client;
if (!id) if ( !client )
return 0; {
PERROR("bad parameter.\n");
existing_client = smscore_getclient_by_id(coredev, id); return -EFAULT;
if (existing_client == client) }
registered_client = smscore_find_client(coredev, data_type, id);
if (registered_client == client)
{
return 0; return 0;
}
if (existing_client) if (registered_client)
return -EBUSY; {
PERROR("The msg ID already registered to another client.\n");
subclient = kzalloc(sizeof(smscore_subclient_t), GFP_KERNEL); return -EEXIST;
if (!subclient) }
listentry = kzalloc ( sizeof ( smscore_idlist_t ), GFP_KERNEL );
if ( !listentry )
{
PERROR("Can't allocate memory for client id.\n");
return -ENOMEM; return -ENOMEM;
}
subclient->client = client; listentry->id = id;
subclient->id = id; listentry->data_type = data_type;
list_add_locked ( &listentry->entry, &client->idlist, &coredev->clientslock );
list_add_locked(&subclient->entry, &coredev->subclients, &coredev->clientslock);
return 0; return 0;
} }
...@@ -964,35 +1051,29 @@ int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client, ...@@ -964,35 +1051,29 @@ int smscore_validate_client(smscore_device_t *coredev, smscore_client_t *client,
int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client) int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *params, smscore_client_t **client)
{ {
smscore_client_t *newclient; smscore_client_t *newclient;
int rc; // check that no other channel with same parameters exists
if (smscore_find_client(coredev, params->data_type, params->initial_id))
// check that no other channel with same data type exists {
if (params->data_type && smscore_getclient_by_type(coredev, params->data_type)) PERROR("Client already exist.\n");
return -EEXIST; return -EEXIST;
}
newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL); newclient = kzalloc(sizeof(smscore_client_t), GFP_KERNEL);
if (!newclient) if (!newclient)
return -ENOMEM;
// check that no other channel with same id exists
rc = smscore_validate_client(coredev, newclient, params->initial_id);
if (rc < 0)
{ {
kfree(newclient); PERROR("Failed to allocate memory for client.\n");
return rc; return -ENOMEM;
} }
INIT_LIST_HEAD ( &newclient->idlist);
newclient->coredev = coredev; newclient->coredev = coredev;
newclient->data_type = params->data_type;
newclient->onresponse_handler = params->onresponse_handler; newclient->onresponse_handler = params->onresponse_handler;
newclient->onremove_handler = params->onremove_handler; newclient->onremove_handler = params->onremove_handler;
newclient->context = params->context; newclient->context = params->context;
list_add_locked(&newclient->entry, &coredev->clients, &coredev->clientslock); list_add_locked(&newclient->entry, &coredev->clients, &coredev->clientslock);
smscore_validate_client(coredev, newclient, params->data_type, params->initial_id);
*client = newclient; *client = newclient;
PDEBUG ( "%p %d %d\n", params->context, params->data_type, params->initial_id );
printk(KERN_INFO "%s %p %d %d\n", __func__, params->context, params->data_type, params->initial_id);
return 0; return 0;
} }
...@@ -1006,26 +1087,19 @@ int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *param ...@@ -1006,26 +1087,19 @@ int smscore_register_client(smscore_device_t *coredev, smsclient_params_t *param
void smscore_unregister_client(smscore_client_t *client) void smscore_unregister_client(smscore_client_t *client)
{ {
smscore_device_t *coredev = client->coredev; smscore_device_t *coredev = client->coredev;
struct list_head *next, *first;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&coredev->clientslock, flags); spin_lock_irqsave(&coredev->clientslock, flags);
first = &coredev->subclients;
for (next = first->next; next != first;) while (!list_empty( &client->idlist))
{
smscore_subclient_t *subclient = (smscore_subclient_t *) next;
next = next->next;
if (subclient->client == client)
{ {
list_del(&subclient->entry); smscore_idlist_t *identry = (smscore_idlist_t*)client->idlist.next;
kfree(subclient); list_del ( &identry->entry );
} kfree ( identry );
} }
printk(KERN_INFO "%s %p %d\n", __func__, client->context, client->data_type); printk(KERN_INFO "%s %p\n", __func__, client->context);
list_del(&client->entry); list_del(&client->entry);
kfree(client); kfree(client);
...@@ -1045,11 +1119,26 @@ void smscore_unregister_client(smscore_client_t *client) ...@@ -1045,11 +1119,26 @@ void smscore_unregister_client(smscore_client_t *client)
*/ */
int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size) int smsclient_sendrequest(smscore_client_t *client, void *buffer, size_t size)
{ {
smscore_device_t *coredev = client->coredev; smscore_device_t *coredev;
SmsMsgHdr_ST* phdr = (SmsMsgHdr_ST*) buffer; SmsMsgHdr_ST* phdr = (SmsMsgHdr_ST*) buffer;
int rc;
if ( client == NULL )
{
printk(KERN_ERR "%s Got NULL client\n", __func__ );
return -EINVAL;
}
coredev = client->coredev;
// check that no other channel with same id exists // check that no other channel with same id exists
int rc = smscore_validate_client(client->coredev, client, phdr->msgSrcId); if ( coredev == NULL )
{
printk(KERN_ERR "%s Got NULL coredev\n", __func__ );
return -EINVAL;
}
rc = smscore_validate_client(client->coredev, client, 0, phdr->msgSrcId);
if (rc < 0) if (rc < 0)
return rc; return rc;
...@@ -1160,6 +1249,6 @@ module_init(smscore_module_init); ...@@ -1160,6 +1249,6 @@ module_init(smscore_module_init);
module_exit(smscore_module_exit); module_exit(smscore_module_exit);
MODULE_DESCRIPTION("smscore"); MODULE_DESCRIPTION("smscore");
MODULE_AUTHOR("Anatoly Greenblatt,,, (anatolyg@siano-ms.com)"); MODULE_AUTHOR ( "Siano Mobile Silicon,,, (doronc@siano-ms.com)" );
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
...@@ -56,6 +56,14 @@ typedef struct mutex kmutex_t; ...@@ -56,6 +56,14 @@ typedef struct mutex kmutex_t;
#define SMS_ROM_NO_RESPONSE 2 #define SMS_ROM_NO_RESPONSE 2
#define SMS_DEVICE_NOT_READY 0x8000000 #define SMS_DEVICE_NOT_READY 0x8000000
typedef enum {
SMS_STELLAR= 0,
SMS_NOVA_A0,
SMS_NOVA_B0,
SMS_VEGA,
SMS_NUM_OF_DEVICE_TYPES
} sms_device_type_st;
typedef struct _smscore_device smscore_device_t; typedef struct _smscore_device smscore_device_t;
typedef struct _smscore_client smscore_client_t; typedef struct _smscore_client smscore_client_t;
typedef struct _smscore_buffer smscore_buffer_t; typedef struct _smscore_buffer smscore_buffer_t;
...@@ -102,6 +110,7 @@ typedef struct _smsdevice_params ...@@ -102,6 +110,7 @@ typedef struct _smsdevice_params
postload_t postload_handler; postload_t postload_handler;
void *context; void *context;
sms_device_type_st device_type;
} smsdevice_params_t; } smsdevice_params_t;
typedef struct _smsclient_params typedef struct _smsclient_params
...@@ -506,6 +515,8 @@ extern int smscore_start_device(smscore_device_t *coredev); ...@@ -506,6 +515,8 @@ extern int smscore_start_device(smscore_device_t *coredev);
extern int smscore_load_firmware(smscore_device_t *coredev, char *filename, extern int smscore_load_firmware(smscore_device_t *coredev, char *filename,
loadfirmware_t loadfirmware_handler); loadfirmware_t loadfirmware_handler);
extern int smscore_load_firmware_from_buffer(smscore_device_t *coredev, u8* buffer, int size, int new_mode);
extern int smscore_set_device_mode(smscore_device_t *coredev, int mode); extern int smscore_set_device_mode(smscore_device_t *coredev, int mode);
extern int smscore_get_device_mode(smscore_device_t *coredev); extern int smscore_get_device_mode(smscore_device_t *coredev);
......
...@@ -300,9 +300,8 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device, ...@@ -300,9 +300,8 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
if (smscore_get_device_mode(coredev) != 4) if (smscore_get_device_mode(coredev) != 4)
{ {
rc = smscore_set_device_mode(coredev, 4); printk(KERN_ERR "%sSMS Device mode is not set for DVB operation.\n", __func__);
if (rc < 0) return 0;
return rc;
} }
client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL); client = kzalloc(sizeof(smsdvb_client_t), GFP_KERNEL);
...@@ -356,7 +355,7 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device, ...@@ -356,7 +355,7 @@ int smsdvb_hotplug(smscore_device_t *coredev, struct device *device,
goto frontend_error; goto frontend_error;
} }
params.initial_id = 0; params.initial_id = 1;
params.data_type = MSG_SMS_DVBT_BDA_DATA; params.data_type = MSG_SMS_DVBT_BDA_DATA;
params.onresponse_handler = smsdvb_onresponse; params.onresponse_handler = smsdvb_onresponse;
params.onremove_handler = smsdvb_onremove; params.onremove_handler = smsdvb_onremove;
......
...@@ -301,21 +301,32 @@ int smsusb_init_device(struct usb_interface *intf) ...@@ -301,21 +301,32 @@ int smsusb_init_device(struct usb_interface *intf)
usb_set_intfdata(intf, dev); usb_set_intfdata(intf, dev);
dev->udev = interface_to_usbdev(intf); dev->udev = interface_to_usbdev(intf);
switch (dev->udev->descriptor.idProduct) switch (dev->udev->descriptor.idProduct) {
{ case 0x100:
case 0x100: dev->buffer_size = USB1_BUFFER_SIZE;
dev->buffer_size = USB1_BUFFER_SIZE;
params.setmode_handler = smsusb1_setmode;
params.setmode_handler = smsusb1_setmode; params.detectmode_handler = smsusb1_detectmode;
params.detectmode_handler = smsusb1_detectmode; params.device_type = SMS_STELLAR;
break; printk(KERN_INFO "%s stellar device found\n", __func__ );
break;
default:
if (dev->udev->descriptor.idProduct == 0x200) {
params.device_type = SMS_NOVA_A0;
printk(KERN_INFO "%s nova A0 found\n", __FUNCTION__ );
} else if (dev->udev->descriptor.idProduct == 0x201) {
params.device_type = SMS_NOVA_B0;
printk(KERN_INFO "%s nova B0 found\n", __FUNCTION__);
} else {
params.device_type = SMS_VEGA;
printk(KERN_INFO "%s Vega found\n", __FUNCTION__);
}
default: dev->buffer_size = USB2_BUFFER_SIZE;
dev->buffer_size = USB2_BUFFER_SIZE; dev->response_alignment = dev->udev->ep_in[1]->desc.wMaxPacketSize - sizeof(SmsMsgHdr_ST);
dev->response_alignment = dev->udev->ep_in[1]->desc.wMaxPacketSize - sizeof(SmsMsgHdr_ST);
params.flags |= SMS_DEVICE_FAMILY2; params.flags |= SMS_DEVICE_FAMILY2;
break; break;
} }
params.device = &dev->udev->dev; params.device = &dev->udev->dev;
...@@ -341,6 +352,7 @@ int smsusb_init_device(struct usb_interface *intf) ...@@ -341,6 +352,7 @@ int smsusb_init_device(struct usb_interface *intf)
usb_init_urb(&dev->surbs[i].urb); usb_init_urb(&dev->surbs[i].urb);
} }
printk(KERN_INFO "%s smsusb_start_streaming(...).\n", __func__);
rc = smsusb_start_streaming(dev); rc = smsusb_start_streaming(dev);
if (rc < 0) if (rc < 0)
{ {
...@@ -368,6 +380,9 @@ int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id) ...@@ -368,6 +380,9 @@ int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
char devpath[32]; char devpath[32];
int i, rc; int i, rc;
rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x81));
rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, 0x02));
if (intf->num_altsetting > 0) if (intf->num_altsetting > 0)
{ {
rc = usb_set_interface(udev, intf->cur_altsetting->desc.bInterfaceNumber, 0); 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,11 +405,14 @@ int smsusb_probe(struct usb_interface *intf, const struct usb_device_id *id)
if (intf->cur_altsetting->desc.bInterfaceNumber == 1) if (intf->cur_altsetting->desc.bInterfaceNumber == 1)
{ {
snprintf(devpath, 32, "%d:%s", udev->bus->busnum, udev->devpath); snprintf(devpath, sizeof(devpath), "usb\\%d-%s", udev->bus->busnum, udev->devpath);
printk(KERN_INFO "stellar device was found.\n");
return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath)); return smsusb1_load_firmware(udev, smscore_registry_getmode(devpath));
} }
return smsusb_init_device(intf); rc = smsusb_init_device(intf);
printk(KERN_INFO "%s rc %d\n", __FUNCTION__, rc);
return rc;
} }
void smsusb_disconnect(struct usb_interface *intf) void smsusb_disconnect(struct usb_interface *intf)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment