24 #include <linux/kernel.h>
26 #include <linux/module.h>
31 #include <linux/slab.h>
34 #include <linux/wait.h>
35 #include <asm/byteorder.h>
92 static struct list_head g_smscore_notifyees;
93 static struct list_head g_smscore_devices;
94 static struct mutex g_smscore_deviceslock;
96 static struct list_head g_smscore_registry;
97 static struct mutex g_smscore_registrylock;
99 static int default_mode = 4;
110 for (next = g_smscore_registry.next;
111 next != &g_smscore_registry;
121 entry->
mode = default_mode;
123 list_add(&entry->
entry, &g_smscore_registry);
125 sms_err(
"failed to create smscore_registry.");
134 entry = smscore_find_registry(devpath);
148 entry = smscore_find_registry(devpath);
161 entry = smscore_find_registry(devpath);
168 static void smscore_registry_settype(
char *devpath,
173 entry = smscore_find_registry(devpath);
190 spin_unlock_irqrestore(lock, flags);
213 first = &g_smscore_devices;
214 for (next = first->
next;
215 next != first && !rc;
219 rc = hotplug(coredev, coredev->
device, 1);
224 list_add(¬ifyee->
entry, &g_smscore_notifyees);
248 first = &g_smscore_notifyees;
250 for (next = first->
next; next != first;) {
255 if (notifyee->
hotplug == hotplug) {
270 while (!list_empty(&coredev->
clients)) {
285 rc = elem->
hotplug(coredev, device, arrival);
334 INIT_LIST_HEAD(&dev->
entry);
345 init_completion(&dev->version_ex_done);
346 init_completion(&dev->data_download_done);
348 init_completion(&dev->init_device_done);
349 init_completion(&dev->reload_start_done);
351 init_completion(&dev->gpio_configuration_done);
353 init_completion(&dev->gpio_get_level_done);
402 list_add(&dev->
entry, &g_smscore_devices);
418 sms_info(
"sendrequest returned error %d", rc);
445 sms_err(
"Error initialization DTV IR sub-module");
458 msg->
msgData[0] = coredev->
ir.controller;
462 (
struct SmsMsgHdr_ST2 *)msg);
463 rc = smscore_sendrequest_and_wait(coredev, msg,
470 (
"Sending IR initialization message failed");
473 sms_info(
"IR port has not been detected");
491 sms_info(
"set device mode faile , rc %d", rc);
497 rc = smscore_notify_callbacks(coredev, coredev->
device, 1);
498 smscore_init_ir(coredev);
500 sms_info(
"device %p started, rc %d", coredev, rc);
510 void *buffer,
size_t size)
522 sms_info(
"loading FW to addr 0x%x size %d",
523 mem_address, firmware->
Length);
539 rc = smscore_sendrequest_and_wait(coredev, msg,
541 &coredev->reload_start_done);
542 mem_address = *(
u32 *) &payload[20];
545 while (size && rc >= 0) {
552 sizeof(
u32) + payload_size));
554 DataMsg->
MemAddr = mem_address;
563 rc = smscore_sendrequest_and_wait(
566 &coredev->data_download_done);
585 TriggerMsg->
msgData[2] = 0x200;
595 rc = smscore_sendrequest_and_wait(
629 static int smscore_load_firmware_from_file(
struct smscore_device_t *coredev,
634 const struct firmware *
fw;
643 sms_info(
"failed to open \"%s\"", filename);
653 smscore_load_firmware_family2(coredev,
656 loadfirmware_handler(coredev->
context,
657 fw_buffer, fw->
size);
661 sms_info(
"failed to allocate firmware buffer");
690 smscore_notify_clients(coredev);
691 smscore_notify_callbacks(coredev,
NULL, 0);
697 while (!list_empty(&coredev->
buffers)) {
707 "not all buffers released.");
711 sms_info(
"waiting for %d buffer(s)",
716 sms_info(
"freed %d buffers", num_buffers);
730 sms_info(
"device %p destroyed", coredev);
748 rc = smscore_sendrequest_and_wait(coredev, msg, msg->
msgLength,
749 &coredev->version_ex_done);
751 sms_err(
"MSG_SMS_GET_VERSION_EX_REQ failed first try");
755 rc = smscore_sendrequest_and_wait(
757 &coredev->version_ex_done);
759 sms_err(
"MSG_SMS_GET_VERSION_EX_REQ failed "
760 "second try, rc %d", rc);
773 {
"none",
"dvb_nova_12mhz.inp",
"dvb_nova_12mhz_b0.inp",
"none"},
775 {
"none",
"dvb_nova_12mhz.inp",
"dvb_nova_12mhz_b0.inp",
"none"},
777 {
"none",
"tdmb_nova_12mhz.inp",
"tdmb_nova_12mhz_b0.inp",
"none"},
779 {
"none",
"none",
"none",
"none"},
781 {
"none",
"dvb_nova_12mhz.inp",
"dvb_nova_12mhz_b0.inp",
"none"},
783 {
"none",
"isdbt_nova_12mhz.inp",
"isdbt_nova_12mhz_b0.inp",
"none"},
785 {
"none",
"isdbt_nova_12mhz.inp",
"isdbt_nova_12mhz_b0.inp",
"none"},
787 {
"none",
"none",
"none",
"cmmb_vega_12mhz.inp"}
794 return (fw && fw[mode]) ? fw[
mode] : smscore_fw_lkup[
mode][
type];
813 sms_debug(
"set device mode to %d", mode);
816 sms_err(
"invalid mode specified %d", mode);
823 rc = smscore_detect_mode(coredev);
825 sms_err(
"mode detect failed %d", rc);
830 if (coredev->
mode == mode) {
831 sms_info(
"device mode %d already set", mode);
838 type = smscore_registry_gettype(coredev->
devpath);
839 fw_filename = sms_get_fw_name(coredev, mode, type);
841 rc = smscore_load_firmware_from_file(coredev,
844 sms_warn(
"error %d loading firmware: %s, "
845 "trying again with default firmware",
849 fw_filename = smscore_fw_lkup[
mode][
type];
850 rc = smscore_load_firmware_from_file(coredev,
860 sms_log(
"firmware download success: %s", fw_filename);
862 sms_info(
"mode %d supported by running "
876 rc = smscore_sendrequest_and_wait(
878 &coredev->init_device_done);
882 sms_err(
"Could not allocate buffer for "
883 "init device message.");
888 sms_err(
"invalid mode specified %d", mode);
908 sms_err(
"return error code %d.", rc);
922 return coredev->
mode;
949 firstid = &client->
idlist;
951 if ((client_id->
id ==
id) &&
959 spin_unlock_irqrestore(&coredev->
clientslock, flags);
978 static unsigned long last_sample_time;
979 static int data_total;
982 if (!last_sample_time)
983 last_sample_time = time_now;
985 if (time_now - last_sample_time > 10000) {
987 (
int)((data_total * 1000) /
988 (time_now - last_sample_time)));
990 last_sample_time = time_now;
994 data_total += cb->
size;
1017 "id %d prots 0x%x ver %d.%d",
1025 complete(&coredev->version_ex_done);
1030 complete(&coredev->init_device_done);
1034 complete(&coredev->reload_start_done);
1037 complete(&coredev->data_download_done);
1043 sms_debug(
"MSG_SMS_SWDOWNLOAD_TRIGGER_RES");
1050 sms_debug(
"MSG_SMS_GPIO_CONFIG_EX_RES");
1051 complete(&coredev->gpio_configuration_done);
1054 sms_debug(
"MSG_SMS_GPIO_SET_LEVEL_RES");
1059 u32 *msgdata = (
u32 *) phdr;
1061 sms_debug(
"MSG_SMS_GPIO_GET_LEVEL_RES gpio level %d",
1063 complete(&coredev->gpio_get_level_done);
1098 unsigned long flags;
1101 if (!list_empty(&coredev->
buffers)) {
1105 spin_unlock_irqrestore(&coredev->
bufferslock, flags);
1136 int data_type,
int id)
1145 registered_client = smscore_find_client(coredev, data_type,
id);
1146 if (registered_client == client)
1149 if (registered_client) {
1150 sms_err(
"The msg ID already registered to another client.");
1155 sms_err(
"Can't allocate memory for client id.");
1160 list_add_locked(&listentry->
entry, &client->
idlist,
1185 if (smscore_find_client(coredev, params->
data_type,
1187 sms_err(
"Client already exist.");
1193 sms_err(
"Failed to allocate memory for client.");
1197 INIT_LIST_HEAD(&newclient->
idlist);
1204 smscore_validate_client(coredev, newclient, params->
data_type,
1206 *client = newclient;
1224 unsigned long flags;
1229 while (!list_empty(&client->
idlist)) {
1241 spin_unlock_irqrestore(&coredev->
clientslock, flags);
1257 void *buffer,
size_t size)
1263 if (client ==
NULL) {
1271 if (coredev ==
NULL) {
1276 rc = smscore_validate_client(client->
coredev, client, 0,
1350 msg.data[1] = level ? 1 : 0;
1358 static int GetGpioPinParams(
u32 PinNum,
u32 *pTranslatedPinNum,
1359 u32 *pGroupNum,
u32 *pGroupCfg) {
1364 *pTranslatedPinNum = 0;
1367 }
else if (PinNum >= 2 && PinNum <= 6) {
1368 *pTranslatedPinNum = 2;
1371 }
else if (PinNum >= 7 && PinNum <= 11) {
1372 *pTranslatedPinNum = 7;
1374 }
else if (PinNum >= 12 && PinNum <= 15) {
1375 *pTranslatedPinNum = 12;
1378 }
else if (PinNum == 16) {
1379 *pTranslatedPinNum = 16;
1381 }
else if (PinNum >= 17 && PinNum <= 24) {
1382 *pTranslatedPinNum = 17;
1384 }
else if (PinNum == 25) {
1385 *pTranslatedPinNum = 25;
1387 }
else if (PinNum >= 26 && PinNum <= 28) {
1388 *pTranslatedPinNum = 26;
1390 }
else if (PinNum == 29) {
1391 *pTranslatedPinNum = 29;
1394 }
else if (PinNum == 30) {
1395 *pTranslatedPinNum = 30;
1397 }
else if (PinNum == 31) {
1398 *pTranslatedPinNum = 31;
1412 u32 TranslatedPinNum = 0;
1428 if (pGpioConfig ==
NULL)
1431 totalLen =
sizeof(
struct SmsMsgHdr_ST) + (sizeof(u32) * 6);
1441 pMsg->xMsgHeader.msgDstId =
HIF_TASK;
1442 pMsg->xMsgHeader.msgFlags = 0;
1443 pMsg->xMsgHeader.msgLength = (
u16) totalLen;
1444 pMsg->msgData[0] = PinNum;
1448 if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum,
1454 pMsg->msgData[1] = TranslatedPinNum;
1455 pMsg->msgData[2] = GroupNum;
1460 pMsg->msgData[3] = ElectricChar;
1461 pMsg->msgData[4] = pGpioConfig->
Direction;
1462 pMsg->msgData[5] = groupCfg;
1468 pMsg->msgData[4] = pGpioConfig->
Direction;
1469 pMsg->msgData[5] = 0;
1473 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1474 &coredev->gpio_configuration_done);
1478 sms_err(
"smscore_gpio_configure timeout");
1480 sms_err(
"smscore_gpio_configure error");
1514 pMsg->xMsgHeader.msgDstId =
HIF_TASK;
1515 pMsg->xMsgHeader.msgFlags = 0;
1517 pMsg->xMsgHeader.msgLength = (
u16) totalLen;
1518 pMsg->msgData[0] = PinNum;
1519 pMsg->msgData[1] = NewLevel;
1523 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1528 sms_err(
"smscore_gpio_set_level timeout");
1530 sms_err(
"smscore_gpio_set_level error");
1563 pMsg->xMsgHeader.msgDstId =
HIF_TASK;
1564 pMsg->xMsgHeader.msgFlags = 0;
1566 pMsg->xMsgHeader.msgLength = (
u16) totalLen;
1567 pMsg->msgData[0] = PinNum;
1568 pMsg->msgData[1] = 0;
1572 rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
1573 &coredev->gpio_get_level_done);
1577 sms_err(
"smscore_gpio_get_level timeout");
1579 sms_err(
"smscore_gpio_get_level error");
1591 static int __init smscore_module_init(
void)
1595 INIT_LIST_HEAD(&g_smscore_notifyees);
1596 INIT_LIST_HEAD(&g_smscore_devices);
1599 INIT_LIST_HEAD(&g_smscore_registry);
1605 static void __exit smscore_module_exit(
void)
1608 while (!list_empty(&g_smscore_notifyees)) {
1611 g_smscore_notifyees.next;
1619 while (!list_empty(&g_smscore_registry)) {
1622 g_smscore_registry.next;