smscoreapi.c 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  1. /*
  2. * Siano core API module
  3. *
  4. * This file contains implementation for the interface to sms core component
  5. *
  6. * author: Uri Shkolnik
  7. *
  8. * Copyright (c), 2005-2008 Siano Mobile Silicon, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation;
  13. *
  14. * Software distributed under the License is distributed on an "AS IS"
  15. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
  16. *
  17. * See the GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <linux/kernel.h>
  24. #include <linux/init.h>
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/dma-mapping.h>
  28. #include <linux/delay.h>
  29. #include <linux/io.h>
  30. #include <linux/slab.h>
  31. #include <linux/firmware.h>
  32. #include <linux/wait.h>
  33. #include <asm/byteorder.h>
  34. #include "smscoreapi.h"
  35. #include "sms-cards.h"
  36. #include "smsir.h"
  37. #include "smsendian.h"
  38. static int sms_dbg;
  39. module_param_named(debug, sms_dbg, int, 0644);
  40. MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
  41. struct smscore_device_notifyee_t {
  42. struct list_head entry;
  43. hotplug_t hotplug;
  44. };
  45. struct smscore_idlist_t {
  46. struct list_head entry;
  47. int id;
  48. int data_type;
  49. };
  50. struct smscore_client_t {
  51. struct list_head entry;
  52. struct smscore_device_t *coredev;
  53. void *context;
  54. struct list_head idlist;
  55. onresponse_t onresponse_handler;
  56. onremove_t onremove_handler;
  57. };
  58. static char *siano_msgs[] = {
  59. [MSG_TYPE_BASE_VAL - MSG_TYPE_BASE_VAL] = "MSG_TYPE_BASE_VAL",
  60. [MSG_SMS_GET_VERSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_REQ",
  61. [MSG_SMS_GET_VERSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_RES",
  62. [MSG_SMS_MULTI_BRIDGE_CFG - MSG_TYPE_BASE_VAL] = "MSG_SMS_MULTI_BRIDGE_CFG",
  63. [MSG_SMS_GPIO_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_REQ",
  64. [MSG_SMS_GPIO_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_RES",
  65. [MSG_SMS_GPIO_SET_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_SET_LEVEL_REQ",
  66. [MSG_SMS_GPIO_SET_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_SET_LEVEL_RES",
  67. [MSG_SMS_GPIO_GET_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_GET_LEVEL_REQ",
  68. [MSG_SMS_GPIO_GET_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_GET_LEVEL_RES",
  69. [MSG_SMS_EEPROM_BURN_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_BURN_IND",
  70. [MSG_SMS_LOG_ENABLE_CHANGE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ENABLE_CHANGE_REQ",
  71. [MSG_SMS_LOG_ENABLE_CHANGE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ENABLE_CHANGE_RES",
  72. [MSG_SMS_SET_MAX_TX_MSG_LEN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_MAX_TX_MSG_LEN_REQ",
  73. [MSG_SMS_SET_MAX_TX_MSG_LEN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_MAX_TX_MSG_LEN_RES",
  74. [MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_HALFDUPLEX_TOKEN_HOST_TO_DEVICE",
  75. [MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_HALFDUPLEX_TOKEN_DEVICE_TO_HOST",
  76. [MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_REQ",
  77. [MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_FLAG_CHANGE_RES",
  78. [MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_SIGNAL_DETECTED_IND",
  79. [MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_BACKGROUND_SCAN_NO_SIGNAL_IND",
  80. [MSG_SMS_CONFIGURE_RF_SWITCH_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIGURE_RF_SWITCH_REQ",
  81. [MSG_SMS_CONFIGURE_RF_SWITCH_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIGURE_RF_SWITCH_RES",
  82. [MSG_SMS_MRC_PATH_DISCONNECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_PATH_DISCONNECT_REQ",
  83. [MSG_SMS_MRC_PATH_DISCONNECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_PATH_DISCONNECT_RES",
  84. [MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_REQ",
  85. [MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_1SEG_THROUGH_FULLSEG_RES",
  86. [MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_REQ",
  87. [MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RECEIVE_VHF_VIA_VHF_INPUT_RES",
  88. [MSG_WR_REG_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_WR_REG_RFT_REQ",
  89. [MSG_WR_REG_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_WR_REG_RFT_RES",
  90. [MSG_RD_REG_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_RFT_REQ",
  91. [MSG_RD_REG_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_RFT_RES",
  92. [MSG_RD_REG_ALL_RFT_REQ - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_ALL_RFT_REQ",
  93. [MSG_RD_REG_ALL_RFT_RES - MSG_TYPE_BASE_VAL] = "MSG_RD_REG_ALL_RFT_RES",
  94. [MSG_HELP_INT - MSG_TYPE_BASE_VAL] = "MSG_HELP_INT",
  95. [MSG_RUN_SCRIPT_INT - MSG_TYPE_BASE_VAL] = "MSG_RUN_SCRIPT_INT",
  96. [MSG_SMS_EWS_INBAND_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EWS_INBAND_REQ",
  97. [MSG_SMS_EWS_INBAND_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EWS_INBAND_RES",
  98. [MSG_SMS_RFS_SELECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RFS_SELECT_REQ",
  99. [MSG_SMS_RFS_SELECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RFS_SELECT_RES",
  100. [MSG_SMS_MB_GET_VER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_GET_VER_REQ",
  101. [MSG_SMS_MB_GET_VER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_GET_VER_RES",
  102. [MSG_SMS_MB_WRITE_CFGFILE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_WRITE_CFGFILE_REQ",
  103. [MSG_SMS_MB_WRITE_CFGFILE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_WRITE_CFGFILE_RES",
  104. [MSG_SMS_MB_READ_CFGFILE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_READ_CFGFILE_REQ",
  105. [MSG_SMS_MB_READ_CFGFILE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_READ_CFGFILE_RES",
  106. [MSG_SMS_RD_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RD_MEM_REQ",
  107. [MSG_SMS_RD_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RD_MEM_RES",
  108. [MSG_SMS_WR_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_WR_MEM_REQ",
  109. [MSG_SMS_WR_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_WR_MEM_RES",
  110. [MSG_SMS_UPDATE_MEM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_UPDATE_MEM_REQ",
  111. [MSG_SMS_UPDATE_MEM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_UPDATE_MEM_RES",
  112. [MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_REQ",
  113. [MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_FULL_PARAMS_SET_RES",
  114. [MSG_SMS_RF_TUNE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RF_TUNE_REQ",
  115. [MSG_SMS_RF_TUNE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RF_TUNE_RES",
  116. [MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_REQ",
  117. [MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_ENABLE_HIGH_MOBILITY_RES",
  118. [MSG_SMS_ISDBT_SB_RECEPTION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_SB_RECEPTION_REQ",
  119. [MSG_SMS_ISDBT_SB_RECEPTION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_SB_RECEPTION_RES",
  120. [MSG_SMS_GENERIC_EPROM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_WRITE_REQ",
  121. [MSG_SMS_GENERIC_EPROM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_WRITE_RES",
  122. [MSG_SMS_GENERIC_EPROM_READ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_READ_REQ",
  123. [MSG_SMS_GENERIC_EPROM_READ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_EPROM_READ_RES",
  124. [MSG_SMS_EEPROM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_WRITE_REQ",
  125. [MSG_SMS_EEPROM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EEPROM_WRITE_RES",
  126. [MSG_SMS_CUSTOM_READ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_READ_REQ",
  127. [MSG_SMS_CUSTOM_READ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_READ_RES",
  128. [MSG_SMS_CUSTOM_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_WRITE_REQ",
  129. [MSG_SMS_CUSTOM_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CUSTOM_WRITE_RES",
  130. [MSG_SMS_INIT_DEVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_INIT_DEVICE_REQ",
  131. [MSG_SMS_INIT_DEVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_INIT_DEVICE_RES",
  132. [MSG_SMS_ATSC_SET_ALL_IP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SET_ALL_IP_REQ",
  133. [MSG_SMS_ATSC_SET_ALL_IP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SET_ALL_IP_RES",
  134. [MSG_SMS_ATSC_START_ENSEMBLE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_START_ENSEMBLE_REQ",
  135. [MSG_SMS_ATSC_START_ENSEMBLE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_START_ENSEMBLE_RES",
  136. [MSG_SMS_SET_OUTPUT_MODE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_OUTPUT_MODE_REQ",
  137. [MSG_SMS_SET_OUTPUT_MODE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_OUTPUT_MODE_RES",
  138. [MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_GET_LIST_REQ",
  139. [MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_GET_LIST_RES",
  140. [MSG_SMS_SUB_CHANNEL_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_START_REQ",
  141. [MSG_SMS_SUB_CHANNEL_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_START_RES",
  142. [MSG_SMS_SUB_CHANNEL_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_STOP_REQ",
  143. [MSG_SMS_SUB_CHANNEL_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SUB_CHANNEL_STOP_RES",
  144. [MSG_SMS_ATSC_IP_FILTER_ADD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_ADD_REQ",
  145. [MSG_SMS_ATSC_IP_FILTER_ADD_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_ADD_RES",
  146. [MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_REQ",
  147. [MSG_SMS_ATSC_IP_FILTER_REMOVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_RES",
  148. [MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_REQ",
  149. [MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_IP_FILTER_REMOVE_ALL_RES",
  150. [MSG_SMS_WAIT_CMD - MSG_TYPE_BASE_VAL] = "MSG_SMS_WAIT_CMD",
  151. [MSG_SMS_ADD_PID_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ADD_PID_FILTER_REQ",
  152. [MSG_SMS_ADD_PID_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ADD_PID_FILTER_RES",
  153. [MSG_SMS_REMOVE_PID_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_REMOVE_PID_FILTER_REQ",
  154. [MSG_SMS_REMOVE_PID_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_REMOVE_PID_FILTER_RES",
  155. [MSG_SMS_FAST_INFORMATION_CHANNEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_FAST_INFORMATION_CHANNEL_REQ",
  156. [MSG_SMS_FAST_INFORMATION_CHANNEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_FAST_INFORMATION_CHANNEL_RES",
  157. [MSG_SMS_DAB_CHANNEL - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_CHANNEL",
  158. [MSG_SMS_GET_PID_FILTER_LIST_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_PID_FILTER_LIST_REQ",
  159. [MSG_SMS_GET_PID_FILTER_LIST_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_PID_FILTER_LIST_RES",
  160. [MSG_SMS_POWER_DOWN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_REQ",
  161. [MSG_SMS_POWER_DOWN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_RES",
  162. [MSG_SMS_ATSC_SLT_EXIST_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_SLT_EXIST_IND",
  163. [MSG_SMS_ATSC_NO_SLT_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_ATSC_NO_SLT_IND",
  164. [MSG_SMS_GET_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_REQ",
  165. [MSG_SMS_GET_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_RES",
  166. [MSG_SMS_SEND_DUMP - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_DUMP",
  167. [MSG_SMS_SCAN_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_START_REQ",
  168. [MSG_SMS_SCAN_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_START_RES",
  169. [MSG_SMS_SCAN_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_STOP_REQ",
  170. [MSG_SMS_SCAN_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_STOP_RES",
  171. [MSG_SMS_SCAN_PROGRESS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_PROGRESS_IND",
  172. [MSG_SMS_SCAN_COMPLETE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SCAN_COMPLETE_IND",
  173. [MSG_SMS_LOG_ITEM - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_ITEM",
  174. [MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_SUBCHANNEL_RECONFIG_REQ",
  175. [MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DAB_SUBCHANNEL_RECONFIG_RES",
  176. [MSG_SMS_HO_PER_SLICES_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PER_SLICES_IND",
  177. [MSG_SMS_HO_INBAND_POWER_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_INBAND_POWER_IND",
  178. [MSG_SMS_MANUAL_DEMOD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MANUAL_DEMOD_REQ",
  179. [MSG_SMS_HO_TUNE_ON_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_ON_REQ",
  180. [MSG_SMS_HO_TUNE_ON_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_ON_RES",
  181. [MSG_SMS_HO_TUNE_OFF_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_OFF_REQ",
  182. [MSG_SMS_HO_TUNE_OFF_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_TUNE_OFF_RES",
  183. [MSG_SMS_HO_PEEK_FREQ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_REQ",
  184. [MSG_SMS_HO_PEEK_FREQ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_RES",
  185. [MSG_SMS_HO_PEEK_FREQ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HO_PEEK_FREQ_IND",
  186. [MSG_SMS_MB_ATTEN_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_ATTEN_SET_REQ",
  187. [MSG_SMS_MB_ATTEN_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MB_ATTEN_SET_RES",
  188. [MSG_SMS_ENABLE_STAT_IN_I2C_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENABLE_STAT_IN_I2C_REQ",
  189. [MSG_SMS_ENABLE_STAT_IN_I2C_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENABLE_STAT_IN_I2C_RES",
  190. [MSG_SMS_SET_ANTENNA_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_ANTENNA_CONFIG_REQ",
  191. [MSG_SMS_SET_ANTENNA_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_ANTENNA_CONFIG_RES",
  192. [MSG_SMS_GET_STATISTICS_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_EX_REQ",
  193. [MSG_SMS_GET_STATISTICS_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_STATISTICS_EX_RES",
  194. [MSG_SMS_SLEEP_RESUME_COMP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SLEEP_RESUME_COMP_IND",
  195. [MSG_SMS_SWITCH_HOST_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWITCH_HOST_INTERFACE_REQ",
  196. [MSG_SMS_SWITCH_HOST_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWITCH_HOST_INTERFACE_RES",
  197. [MSG_SMS_DATA_DOWNLOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_DOWNLOAD_REQ",
  198. [MSG_SMS_DATA_DOWNLOAD_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_DOWNLOAD_RES",
  199. [MSG_SMS_DATA_VALIDITY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_VALIDITY_REQ",
  200. [MSG_SMS_DATA_VALIDITY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_VALIDITY_RES",
  201. [MSG_SMS_SWDOWNLOAD_TRIGGER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_TRIGGER_REQ",
  202. [MSG_SMS_SWDOWNLOAD_TRIGGER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_TRIGGER_RES",
  203. [MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_BACKDOOR_REQ",
  204. [MSG_SMS_SWDOWNLOAD_BACKDOOR_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SWDOWNLOAD_BACKDOOR_RES",
  205. [MSG_SMS_GET_VERSION_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_EX_REQ",
  206. [MSG_SMS_GET_VERSION_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_VERSION_EX_RES",
  207. [MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CLOCK_OUTPUT_CONFIG_REQ",
  208. [MSG_SMS_CLOCK_OUTPUT_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CLOCK_OUTPUT_CONFIG_RES",
  209. [MSG_SMS_I2C_SET_FREQ_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SET_FREQ_REQ",
  210. [MSG_SMS_I2C_SET_FREQ_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SET_FREQ_RES",
  211. [MSG_SMS_GENERIC_I2C_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_I2C_REQ",
  212. [MSG_SMS_GENERIC_I2C_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GENERIC_I2C_RES",
  213. [MSG_SMS_DVBT_BDA_DATA - MSG_TYPE_BASE_VAL] = "MSG_SMS_DVBT_BDA_DATA",
  214. [MSG_SW_RELOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_REQ",
  215. [MSG_SMS_DATA_MSG - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_MSG",
  216. [MSG_TABLE_UPLOAD_REQ - MSG_TYPE_BASE_VAL] = "MSG_TABLE_UPLOAD_REQ",
  217. [MSG_TABLE_UPLOAD_RES - MSG_TYPE_BASE_VAL] = "MSG_TABLE_UPLOAD_RES",
  218. [MSG_SW_RELOAD_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_START_REQ",
  219. [MSG_SW_RELOAD_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_START_RES",
  220. [MSG_SW_RELOAD_EXEC_REQ - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_EXEC_REQ",
  221. [MSG_SW_RELOAD_EXEC_RES - MSG_TYPE_BASE_VAL] = "MSG_SW_RELOAD_EXEC_RES",
  222. [MSG_SMS_SPI_INT_LINE_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_INT_LINE_SET_REQ",
  223. [MSG_SMS_SPI_INT_LINE_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_INT_LINE_SET_RES",
  224. [MSG_SMS_GPIO_CONFIG_EX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_EX_REQ",
  225. [MSG_SMS_GPIO_CONFIG_EX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GPIO_CONFIG_EX_RES",
  226. [MSG_SMS_WATCHDOG_ACT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_WATCHDOG_ACT_REQ",
  227. [MSG_SMS_WATCHDOG_ACT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_WATCHDOG_ACT_RES",
  228. [MSG_SMS_LOOPBACK_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOOPBACK_REQ",
  229. [MSG_SMS_LOOPBACK_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOOPBACK_RES",
  230. [MSG_SMS_RAW_CAPTURE_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_START_REQ",
  231. [MSG_SMS_RAW_CAPTURE_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_START_RES",
  232. [MSG_SMS_RAW_CAPTURE_ABORT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_ABORT_REQ",
  233. [MSG_SMS_RAW_CAPTURE_ABORT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_ABORT_RES",
  234. [MSG_SMS_RAW_CAPTURE_COMPLETE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_RAW_CAPTURE_COMPLETE_IND",
  235. [MSG_SMS_DATA_PUMP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_IND",
  236. [MSG_SMS_DATA_PUMP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_REQ",
  237. [MSG_SMS_DATA_PUMP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DATA_PUMP_RES",
  238. [MSG_SMS_FLASH_DL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_FLASH_DL_REQ",
  239. [MSG_SMS_EXEC_TEST_1_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXEC_TEST_1_REQ",
  240. [MSG_SMS_EXEC_TEST_1_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXEC_TEST_1_RES",
  241. [MSG_SMS_ENBALE_TS_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENBALE_TS_INTERFACE_REQ",
  242. [MSG_SMS_ENBALE_TS_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ENBALE_TS_INTERFACE_RES",
  243. [MSG_SMS_SPI_SET_BUS_WIDTH_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_SET_BUS_WIDTH_REQ",
  244. [MSG_SMS_SPI_SET_BUS_WIDTH_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SPI_SET_BUS_WIDTH_RES",
  245. [MSG_SMS_SEND_EMM_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_EMM_REQ",
  246. [MSG_SMS_SEND_EMM_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_EMM_RES",
  247. [MSG_SMS_DISABLE_TS_INTERFACE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DISABLE_TS_INTERFACE_REQ",
  248. [MSG_SMS_DISABLE_TS_INTERFACE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DISABLE_TS_INTERFACE_RES",
  249. [MSG_SMS_IS_BUF_FREE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IS_BUF_FREE_REQ",
  250. [MSG_SMS_IS_BUF_FREE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IS_BUF_FREE_RES",
  251. [MSG_SMS_EXT_ANTENNA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXT_ANTENNA_REQ",
  252. [MSG_SMS_EXT_ANTENNA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXT_ANTENNA_RES",
  253. [MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NET_OF_FREQ_REQ_OBSOLETE",
  254. [MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NET_OF_FREQ_RES_OBSOLETE",
  255. [MSG_SMS_BATTERY_LEVEL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_BATTERY_LEVEL_REQ",
  256. [MSG_SMS_BATTERY_LEVEL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_BATTERY_LEVEL_RES",
  257. [MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_INJECT_TABLE_REQ_OBSOLETE",
  258. [MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_INJECT_TABLE_RES_OBSOLETE",
  259. [MSG_SMS_FM_RADIO_BLOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_FM_RADIO_BLOCK_IND",
  260. [MSG_SMS_HOST_NOTIFICATION_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_HOST_NOTIFICATION_IND",
  261. [MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_CONTROL_TABLE_REQ_OBSOLETE",
  262. [MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_CONTROL_TABLE_RES_OBSOLETE",
  263. [MSG_SMS_CMMB_GET_NETWORKS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NETWORKS_REQ",
  264. [MSG_SMS_CMMB_GET_NETWORKS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_NETWORKS_RES",
  265. [MSG_SMS_CMMB_START_SERVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_SERVICE_REQ",
  266. [MSG_SMS_CMMB_START_SERVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_SERVICE_RES",
  267. [MSG_SMS_CMMB_STOP_SERVICE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_SERVICE_REQ",
  268. [MSG_SMS_CMMB_STOP_SERVICE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_SERVICE_RES",
  269. [MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_ADD_CHANNEL_FILTER_REQ",
  270. [MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_ADD_CHANNEL_FILTER_RES",
  271. [MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_REQ",
  272. [MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_REMOVE_CHANNEL_FILTER_RES",
  273. [MSG_SMS_CMMB_START_CONTROL_INFO_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_CONTROL_INFO_REQ",
  274. [MSG_SMS_CMMB_START_CONTROL_INFO_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_START_CONTROL_INFO_RES",
  275. [MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_CONTROL_INFO_REQ",
  276. [MSG_SMS_CMMB_STOP_CONTROL_INFO_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_STOP_CONTROL_INFO_RES",
  277. [MSG_SMS_ISDBT_TUNE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_TUNE_REQ",
  278. [MSG_SMS_ISDBT_TUNE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_ISDBT_TUNE_RES",
  279. [MSG_SMS_TRANSMISSION_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_TRANSMISSION_IND",
  280. [MSG_SMS_PID_STATISTICS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_PID_STATISTICS_IND",
  281. [MSG_SMS_POWER_DOWN_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_IND",
  282. [MSG_SMS_POWER_DOWN_CONF - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_DOWN_CONF",
  283. [MSG_SMS_POWER_UP_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_UP_IND",
  284. [MSG_SMS_POWER_UP_CONF - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_UP_CONF",
  285. [MSG_SMS_POWER_MODE_SET_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_MODE_SET_REQ",
  286. [MSG_SMS_POWER_MODE_SET_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_POWER_MODE_SET_RES",
  287. [MSG_SMS_DEBUG_HOST_EVENT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEBUG_HOST_EVENT_REQ",
  288. [MSG_SMS_DEBUG_HOST_EVENT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEBUG_HOST_EVENT_RES",
  289. [MSG_SMS_NEW_CRYSTAL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NEW_CRYSTAL_REQ",
  290. [MSG_SMS_NEW_CRYSTAL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NEW_CRYSTAL_RES",
  291. [MSG_SMS_CONFIG_SPI_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIG_SPI_REQ",
  292. [MSG_SMS_CONFIG_SPI_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CONFIG_SPI_RES",
  293. [MSG_SMS_I2C_SHORT_STAT_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_I2C_SHORT_STAT_IND",
  294. [MSG_SMS_START_IR_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_START_IR_REQ",
  295. [MSG_SMS_START_IR_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_START_IR_RES",
  296. [MSG_SMS_IR_SAMPLES_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_IR_SAMPLES_IND",
  297. [MSG_SMS_CMMB_CA_SERVICE_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_CA_SERVICE_IND",
  298. [MSG_SMS_SLAVE_DEVICE_DETECTED - MSG_TYPE_BASE_VAL] = "MSG_SMS_SLAVE_DEVICE_DETECTED",
  299. [MSG_SMS_INTERFACE_LOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_INTERFACE_LOCK_IND",
  300. [MSG_SMS_INTERFACE_UNLOCK_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_INTERFACE_UNLOCK_IND",
  301. [MSG_SMS_SEND_ROSUM_BUFF_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_ROSUM_BUFF_REQ",
  302. [MSG_SMS_SEND_ROSUM_BUFF_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_ROSUM_BUFF_RES",
  303. [MSG_SMS_ROSUM_BUFF - MSG_TYPE_BASE_VAL] = "MSG_SMS_ROSUM_BUFF",
  304. [MSG_SMS_SET_AES128_KEY_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_AES128_KEY_REQ",
  305. [MSG_SMS_SET_AES128_KEY_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_AES128_KEY_RES",
  306. [MSG_SMS_MBBMS_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_WRITE_REQ",
  307. [MSG_SMS_MBBMS_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_WRITE_RES",
  308. [MSG_SMS_MBBMS_READ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_MBBMS_READ_IND",
  309. [MSG_SMS_IQ_STREAM_START_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_START_REQ",
  310. [MSG_SMS_IQ_STREAM_START_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_START_RES",
  311. [MSG_SMS_IQ_STREAM_STOP_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_STOP_REQ",
  312. [MSG_SMS_IQ_STREAM_STOP_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_STOP_RES",
  313. [MSG_SMS_IQ_STREAM_DATA_BLOCK - MSG_TYPE_BASE_VAL] = "MSG_SMS_IQ_STREAM_DATA_BLOCK",
  314. [MSG_SMS_GET_EEPROM_VERSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_EEPROM_VERSION_REQ",
  315. [MSG_SMS_GET_EEPROM_VERSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_GET_EEPROM_VERSION_RES",
  316. [MSG_SMS_SIGNAL_DETECTED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SIGNAL_DETECTED_IND",
  317. [MSG_SMS_NO_SIGNAL_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_NO_SIGNAL_IND",
  318. [MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_SHUTDOWN_SLAVE_REQ",
  319. [MSG_SMS_MRC_SHUTDOWN_SLAVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_SHUTDOWN_SLAVE_RES",
  320. [MSG_SMS_MRC_BRINGUP_SLAVE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_BRINGUP_SLAVE_REQ",
  321. [MSG_SMS_MRC_BRINGUP_SLAVE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_BRINGUP_SLAVE_RES",
  322. [MSG_SMS_EXTERNAL_LNA_CTRL_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXTERNAL_LNA_CTRL_REQ",
  323. [MSG_SMS_EXTERNAL_LNA_CTRL_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_EXTERNAL_LNA_CTRL_RES",
  324. [MSG_SMS_SET_PERIODIC_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_PERIODIC_STATISTICS_REQ",
  325. [MSG_SMS_SET_PERIODIC_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SET_PERIODIC_STATISTICS_RES",
  326. [MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_REQ",
  327. [MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_AUTO_OUTPUT_TS0_RES",
  328. [LOCAL_TUNE - MSG_TYPE_BASE_VAL] = "LOCAL_TUNE",
  329. [LOCAL_IFFT_H_ICI - MSG_TYPE_BASE_VAL] = "LOCAL_IFFT_H_ICI",
  330. [MSG_RESYNC_REQ - MSG_TYPE_BASE_VAL] = "MSG_RESYNC_REQ",
  331. [MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_MRC_STATISTICS_REQ",
  332. [MSG_SMS_CMMB_GET_MRC_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_MRC_STATISTICS_RES",
  333. [MSG_SMS_LOG_EX_ITEM - MSG_TYPE_BASE_VAL] = "MSG_SMS_LOG_EX_ITEM",
  334. [MSG_SMS_DEVICE_DATA_LOSS_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_DEVICE_DATA_LOSS_IND",
  335. [MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_MRC_WATCHDOG_TRIGGERED_IND",
  336. [MSG_SMS_USER_MSG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_USER_MSG_REQ",
  337. [MSG_SMS_USER_MSG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_USER_MSG_RES",
  338. [MSG_SMS_SMART_CARD_INIT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_INIT_REQ",
  339. [MSG_SMS_SMART_CARD_INIT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_INIT_RES",
  340. [MSG_SMS_SMART_CARD_WRITE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_WRITE_REQ",
  341. [MSG_SMS_SMART_CARD_WRITE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_WRITE_RES",
  342. [MSG_SMS_SMART_CARD_READ_IND - MSG_TYPE_BASE_VAL] = "MSG_SMS_SMART_CARD_READ_IND",
  343. [MSG_SMS_TSE_ENABLE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_TSE_ENABLE_REQ",
  344. [MSG_SMS_TSE_ENABLE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_TSE_ENABLE_RES",
  345. [MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_SHORT_STATISTICS_REQ",
  346. [MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_GET_SHORT_STATISTICS_RES",
  347. [MSG_SMS_LED_CONFIG_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_LED_CONFIG_REQ",
  348. [MSG_SMS_LED_CONFIG_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_LED_CONFIG_RES",
  349. [MSG_PWM_ANTENNA_REQ - MSG_TYPE_BASE_VAL] = "MSG_PWM_ANTENNA_REQ",
  350. [MSG_PWM_ANTENNA_RES - MSG_TYPE_BASE_VAL] = "MSG_PWM_ANTENNA_RES",
  351. [MSG_SMS_CMMB_SMD_SN_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SMD_SN_REQ",
  352. [MSG_SMS_CMMB_SMD_SN_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SMD_SN_RES",
  353. [MSG_SMS_CMMB_SET_CA_CW_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_CW_REQ",
  354. [MSG_SMS_CMMB_SET_CA_CW_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_CW_RES",
  355. [MSG_SMS_CMMB_SET_CA_SALT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_SALT_REQ",
  356. [MSG_SMS_CMMB_SET_CA_SALT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_CMMB_SET_CA_SALT_RES",
  357. [MSG_SMS_NSCD_INIT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_INIT_REQ",
  358. [MSG_SMS_NSCD_INIT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_INIT_RES",
  359. [MSG_SMS_NSCD_PROCESS_SECTION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_PROCESS_SECTION_REQ",
  360. [MSG_SMS_NSCD_PROCESS_SECTION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_PROCESS_SECTION_RES",
  361. [MSG_SMS_DBD_CREATE_OBJECT_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CREATE_OBJECT_REQ",
  362. [MSG_SMS_DBD_CREATE_OBJECT_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CREATE_OBJECT_RES",
  363. [MSG_SMS_DBD_CONFIGURE_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CONFIGURE_REQ",
  364. [MSG_SMS_DBD_CONFIGURE_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_CONFIGURE_RES",
  365. [MSG_SMS_DBD_SET_KEYS_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_SET_KEYS_REQ",
  366. [MSG_SMS_DBD_SET_KEYS_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_SET_KEYS_RES",
  367. [MSG_SMS_DBD_PROCESS_HEADER_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_HEADER_REQ",
  368. [MSG_SMS_DBD_PROCESS_HEADER_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_HEADER_RES",
  369. [MSG_SMS_DBD_PROCESS_DATA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_DATA_REQ",
  370. [MSG_SMS_DBD_PROCESS_DATA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_DATA_RES",
  371. [MSG_SMS_DBD_PROCESS_GET_DATA_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_GET_DATA_REQ",
  372. [MSG_SMS_DBD_PROCESS_GET_DATA_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_DBD_PROCESS_GET_DATA_RES",
  373. [MSG_SMS_NSCD_OPEN_SESSION_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_OPEN_SESSION_REQ",
  374. [MSG_SMS_NSCD_OPEN_SESSION_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_NSCD_OPEN_SESSION_RES",
  375. [MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_HOST_DATA_TO_DEMUX_REQ",
  376. [MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES - MSG_TYPE_BASE_VAL] = "MSG_SMS_SEND_HOST_DATA_TO_DEMUX_RES",
  377. [MSG_LAST_MSG_TYPE - MSG_TYPE_BASE_VAL] = "MSG_LAST_MSG_TYPE",
  378. };
  379. char *smscore_translate_msg(enum msg_types msgtype)
  380. {
  381. int i = msgtype - MSG_TYPE_BASE_VAL;
  382. char *msg;
  383. if (i < 0 || i > ARRAY_SIZE(siano_msgs))
  384. return "Unknown msg type";
  385. msg = siano_msgs[i];
  386. if (!*msg)
  387. return "Unknown msg type";
  388. return msg;
  389. }
  390. EXPORT_SYMBOL_GPL(smscore_translate_msg);
  391. void smscore_set_board_id(struct smscore_device_t *core, int id)
  392. {
  393. core->board_id = id;
  394. }
  395. int smscore_led_state(struct smscore_device_t *core, int led)
  396. {
  397. if (led >= 0)
  398. core->led_state = led;
  399. return core->led_state;
  400. }
  401. EXPORT_SYMBOL_GPL(smscore_set_board_id);
  402. int smscore_get_board_id(struct smscore_device_t *core)
  403. {
  404. return core->board_id;
  405. }
  406. EXPORT_SYMBOL_GPL(smscore_get_board_id);
  407. struct smscore_registry_entry_t {
  408. struct list_head entry;
  409. char devpath[32];
  410. int mode;
  411. enum sms_device_type_st type;
  412. };
  413. static struct list_head g_smscore_notifyees;
  414. static struct list_head g_smscore_devices;
  415. static struct mutex g_smscore_deviceslock;
  416. static struct list_head g_smscore_registry;
  417. static struct mutex g_smscore_registrylock;
  418. static int default_mode = 4;
  419. module_param(default_mode, int, 0644);
  420. MODULE_PARM_DESC(default_mode, "default firmware id (device mode)");
  421. static struct smscore_registry_entry_t *smscore_find_registry(char *devpath)
  422. {
  423. struct smscore_registry_entry_t *entry;
  424. struct list_head *next;
  425. kmutex_lock(&g_smscore_registrylock);
  426. for (next = g_smscore_registry.next;
  427. next != &g_smscore_registry;
  428. next = next->next) {
  429. entry = (struct smscore_registry_entry_t *) next;
  430. if (!strcmp(entry->devpath, devpath)) {
  431. kmutex_unlock(&g_smscore_registrylock);
  432. return entry;
  433. }
  434. }
  435. entry = kmalloc(sizeof(struct smscore_registry_entry_t), GFP_KERNEL);
  436. if (entry) {
  437. entry->mode = default_mode;
  438. strcpy(entry->devpath, devpath);
  439. list_add(&entry->entry, &g_smscore_registry);
  440. } else
  441. sms_err("failed to create smscore_registry.");
  442. kmutex_unlock(&g_smscore_registrylock);
  443. return entry;
  444. }
  445. int smscore_registry_getmode(char *devpath)
  446. {
  447. struct smscore_registry_entry_t *entry;
  448. entry = smscore_find_registry(devpath);
  449. if (entry)
  450. return entry->mode;
  451. else
  452. sms_err("No registry found.");
  453. return default_mode;
  454. }
  455. EXPORT_SYMBOL_GPL(smscore_registry_getmode);
  456. static enum sms_device_type_st smscore_registry_gettype(char *devpath)
  457. {
  458. struct smscore_registry_entry_t *entry;
  459. entry = smscore_find_registry(devpath);
  460. if (entry)
  461. return entry->type;
  462. else
  463. sms_err("No registry found.");
  464. return -EINVAL;
  465. }
  466. static void smscore_registry_setmode(char *devpath, int mode)
  467. {
  468. struct smscore_registry_entry_t *entry;
  469. entry = smscore_find_registry(devpath);
  470. if (entry)
  471. entry->mode = mode;
  472. else
  473. sms_err("No registry found.");
  474. }
  475. static void smscore_registry_settype(char *devpath,
  476. enum sms_device_type_st type)
  477. {
  478. struct smscore_registry_entry_t *entry;
  479. entry = smscore_find_registry(devpath);
  480. if (entry)
  481. entry->type = type;
  482. else
  483. sms_err("No registry found.");
  484. }
  485. static void list_add_locked(struct list_head *new, struct list_head *head,
  486. spinlock_t *lock)
  487. {
  488. unsigned long flags;
  489. spin_lock_irqsave(lock, flags);
  490. list_add(new, head);
  491. spin_unlock_irqrestore(lock, flags);
  492. }
  493. /**
  494. * register a client callback that called when device plugged in/unplugged
  495. * NOTE: if devices exist callback is called immediately for each device
  496. *
  497. * @param hotplug callback
  498. *
  499. * @return 0 on success, <0 on error.
  500. */
  501. int smscore_register_hotplug(hotplug_t hotplug)
  502. {
  503. struct smscore_device_notifyee_t *notifyee;
  504. struct list_head *next, *first;
  505. int rc = 0;
  506. kmutex_lock(&g_smscore_deviceslock);
  507. notifyee = kmalloc(sizeof(struct smscore_device_notifyee_t),
  508. GFP_KERNEL);
  509. if (notifyee) {
  510. /* now notify callback about existing devices */
  511. first = &g_smscore_devices;
  512. for (next = first->next;
  513. next != first && !rc;
  514. next = next->next) {
  515. struct smscore_device_t *coredev =
  516. (struct smscore_device_t *) next;
  517. rc = hotplug(coredev, coredev->device, 1);
  518. }
  519. if (rc >= 0) {
  520. notifyee->hotplug = hotplug;
  521. list_add(&notifyee->entry, &g_smscore_notifyees);
  522. } else
  523. kfree(notifyee);
  524. } else
  525. rc = -ENOMEM;
  526. kmutex_unlock(&g_smscore_deviceslock);
  527. return rc;
  528. }
  529. EXPORT_SYMBOL_GPL(smscore_register_hotplug);
  530. /**
  531. * unregister a client callback that called when device plugged in/unplugged
  532. *
  533. * @param hotplug callback
  534. *
  535. */
  536. void smscore_unregister_hotplug(hotplug_t hotplug)
  537. {
  538. struct list_head *next, *first;
  539. kmutex_lock(&g_smscore_deviceslock);
  540. first = &g_smscore_notifyees;
  541. for (next = first->next; next != first;) {
  542. struct smscore_device_notifyee_t *notifyee =
  543. (struct smscore_device_notifyee_t *) next;
  544. next = next->next;
  545. if (notifyee->hotplug == hotplug) {
  546. list_del(&notifyee->entry);
  547. kfree(notifyee);
  548. }
  549. }
  550. kmutex_unlock(&g_smscore_deviceslock);
  551. }
  552. EXPORT_SYMBOL_GPL(smscore_unregister_hotplug);
  553. static void smscore_notify_clients(struct smscore_device_t *coredev)
  554. {
  555. struct smscore_client_t *client;
  556. /* the client must call smscore_unregister_client from remove handler */
  557. while (!list_empty(&coredev->clients)) {
  558. client = (struct smscore_client_t *) coredev->clients.next;
  559. client->onremove_handler(client->context);
  560. }
  561. }
  562. static int smscore_notify_callbacks(struct smscore_device_t *coredev,
  563. struct device *device, int arrival)
  564. {
  565. struct smscore_device_notifyee_t *elem;
  566. int rc = 0;
  567. /* note: must be called under g_deviceslock */
  568. list_for_each_entry(elem, &g_smscore_notifyees, entry) {
  569. rc = elem->hotplug(coredev, device, arrival);
  570. if (rc < 0)
  571. break;
  572. }
  573. return rc;
  574. }
  575. static struct
  576. smscore_buffer_t *smscore_createbuffer(u8 *buffer, void *common_buffer,
  577. dma_addr_t common_buffer_phys)
  578. {
  579. struct smscore_buffer_t *cb;
  580. cb = kzalloc(sizeof(struct smscore_buffer_t), GFP_KERNEL);
  581. if (!cb) {
  582. sms_info("kzalloc(...) failed");
  583. return NULL;
  584. }
  585. cb->p = buffer;
  586. cb->offset_in_common = buffer - (u8 *) common_buffer;
  587. cb->phys = common_buffer_phys + cb->offset_in_common;
  588. return cb;
  589. }
  590. /**
  591. * creates coredev object for a device, prepares buffers,
  592. * creates buffer mappings, notifies registered hotplugs about new device.
  593. *
  594. * @param params device pointer to struct with device specific parameters
  595. * and handlers
  596. * @param coredev pointer to a value that receives created coredev object
  597. *
  598. * @return 0 on success, <0 on error.
  599. */
  600. int smscore_register_device(struct smsdevice_params_t *params,
  601. struct smscore_device_t **coredev)
  602. {
  603. struct smscore_device_t *dev;
  604. u8 *buffer;
  605. dev = kzalloc(sizeof(struct smscore_device_t), GFP_KERNEL);
  606. if (!dev) {
  607. sms_info("kzalloc(...) failed");
  608. return -ENOMEM;
  609. }
  610. /* init list entry so it could be safe in smscore_unregister_device */
  611. INIT_LIST_HEAD(&dev->entry);
  612. /* init queues */
  613. INIT_LIST_HEAD(&dev->clients);
  614. INIT_LIST_HEAD(&dev->buffers);
  615. /* init locks */
  616. spin_lock_init(&dev->clientslock);
  617. spin_lock_init(&dev->bufferslock);
  618. /* init completion events */
  619. init_completion(&dev->version_ex_done);
  620. init_completion(&dev->data_download_done);
  621. init_completion(&dev->data_validity_done);
  622. init_completion(&dev->trigger_done);
  623. init_completion(&dev->init_device_done);
  624. init_completion(&dev->reload_start_done);
  625. init_completion(&dev->resume_done);
  626. init_completion(&dev->gpio_configuration_done);
  627. init_completion(&dev->gpio_set_level_done);
  628. init_completion(&dev->gpio_get_level_done);
  629. init_completion(&dev->ir_init_done);
  630. /* Buffer management */
  631. init_waitqueue_head(&dev->buffer_mng_waitq);
  632. /* alloc common buffer */
  633. dev->common_buffer_size = params->buffer_size * params->num_buffers;
  634. dev->common_buffer = dma_alloc_coherent(NULL, dev->common_buffer_size,
  635. &dev->common_buffer_phys,
  636. GFP_KERNEL | GFP_DMA);
  637. if (!dev->common_buffer) {
  638. smscore_unregister_device(dev);
  639. return -ENOMEM;
  640. }
  641. /* prepare dma buffers */
  642. for (buffer = dev->common_buffer;
  643. dev->num_buffers < params->num_buffers;
  644. dev->num_buffers++, buffer += params->buffer_size) {
  645. struct smscore_buffer_t *cb;
  646. cb = smscore_createbuffer(buffer, dev->common_buffer,
  647. dev->common_buffer_phys);
  648. if (!cb) {
  649. smscore_unregister_device(dev);
  650. return -ENOMEM;
  651. }
  652. smscore_putbuffer(dev, cb);
  653. }
  654. sms_info("allocated %d buffers", dev->num_buffers);
  655. dev->mode = DEVICE_MODE_NONE;
  656. dev->board_id = SMS_BOARD_UNKNOWN;
  657. dev->context = params->context;
  658. dev->device = params->device;
  659. dev->setmode_handler = params->setmode_handler;
  660. dev->detectmode_handler = params->detectmode_handler;
  661. dev->sendrequest_handler = params->sendrequest_handler;
  662. dev->preload_handler = params->preload_handler;
  663. dev->postload_handler = params->postload_handler;
  664. dev->device_flags = params->flags;
  665. strcpy(dev->devpath, params->devpath);
  666. smscore_registry_settype(dev->devpath, params->device_type);
  667. /* add device to devices list */
  668. kmutex_lock(&g_smscore_deviceslock);
  669. list_add(&dev->entry, &g_smscore_devices);
  670. kmutex_unlock(&g_smscore_deviceslock);
  671. *coredev = dev;
  672. sms_info("device %p created", dev);
  673. return 0;
  674. }
  675. EXPORT_SYMBOL_GPL(smscore_register_device);
  676. static int smscore_sendrequest_and_wait(struct smscore_device_t *coredev,
  677. void *buffer, size_t size, struct completion *completion) {
  678. int rc;
  679. if (completion == NULL)
  680. return -EINVAL;
  681. init_completion(completion);
  682. rc = coredev->sendrequest_handler(coredev->context, buffer, size);
  683. if (rc < 0) {
  684. sms_info("sendrequest returned error %d", rc);
  685. return rc;
  686. }
  687. return wait_for_completion_timeout(completion,
  688. msecs_to_jiffies(SMS_PROTOCOL_MAX_RAOUNDTRIP_MS)) ?
  689. 0 : -ETIME;
  690. }
  691. /**
  692. * Starts & enables IR operations
  693. *
  694. * @return 0 on success, < 0 on error.
  695. */
  696. static int smscore_init_ir(struct smscore_device_t *coredev)
  697. {
  698. int ir_io;
  699. int rc;
  700. void *buffer;
  701. coredev->ir.dev = NULL;
  702. ir_io = sms_get_board(smscore_get_board_id(coredev))->board_cfg.ir;
  703. if (ir_io) {/* only if IR port exist we use IR sub-module */
  704. sms_info("IR loading");
  705. rc = sms_ir_init(coredev);
  706. if (rc != 0)
  707. sms_err("Error initialization DTV IR sub-module");
  708. else {
  709. buffer = kmalloc(sizeof(struct SmsMsgData_ST2) +
  710. SMS_DMA_ALIGNMENT,
  711. GFP_KERNEL | GFP_DMA);
  712. if (buffer) {
  713. struct SmsMsgData_ST2 *msg =
  714. (struct SmsMsgData_ST2 *)
  715. SMS_ALIGN_ADDRESS(buffer);
  716. SMS_INIT_MSG(&msg->xMsgHeader,
  717. MSG_SMS_START_IR_REQ,
  718. sizeof(struct SmsMsgData_ST2));
  719. msg->msgData[0] = coredev->ir.controller;
  720. msg->msgData[1] = coredev->ir.timeout;
  721. smsendian_handle_tx_message(
  722. (struct SmsMsgHdr_ST2 *)msg);
  723. rc = smscore_sendrequest_and_wait(coredev, msg,
  724. msg->xMsgHeader. msgLength,
  725. &coredev->ir_init_done);
  726. kfree(buffer);
  727. } else
  728. sms_err
  729. ("Sending IR initialization message failed");
  730. }
  731. } else
  732. sms_info("IR port has not been detected");
  733. return 0;
  734. }
  735. /**
  736. * configures device features according to board configuration structure.
  737. *
  738. * @param coredev pointer to a coredev object returned by
  739. * smscore_register_device
  740. *
  741. * @return 0 on success, <0 on error.
  742. */
  743. int smscore_configure_board(struct smscore_device_t *coredev)
  744. {
  745. struct sms_board *board;
  746. board = sms_get_board(coredev->board_id);
  747. if (!board) {
  748. sms_err("no board configuration exist.");
  749. return -EINVAL;
  750. }
  751. if (board->mtu) {
  752. struct SmsMsgData_ST MtuMsg;
  753. sms_debug("set max transmit unit %d", board->mtu);
  754. MtuMsg.xMsgHeader.msgSrcId = 0;
  755. MtuMsg.xMsgHeader.msgDstId = HIF_TASK;
  756. MtuMsg.xMsgHeader.msgFlags = 0;
  757. MtuMsg.xMsgHeader.msgType = MSG_SMS_SET_MAX_TX_MSG_LEN_REQ;
  758. MtuMsg.xMsgHeader.msgLength = sizeof(MtuMsg);
  759. MtuMsg.msgData[0] = board->mtu;
  760. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)&MtuMsg);
  761. coredev->sendrequest_handler(coredev->context, &MtuMsg,
  762. sizeof(MtuMsg));
  763. }
  764. if (board->crystal) {
  765. struct SmsMsgData_ST CrysMsg;
  766. sms_debug("set crystal value %d", board->crystal);
  767. SMS_INIT_MSG(&CrysMsg.xMsgHeader,
  768. MSG_SMS_NEW_CRYSTAL_REQ,
  769. sizeof(CrysMsg));
  770. CrysMsg.msgData[0] = board->crystal;
  771. smsendian_handle_tx_message((struct SmsMsgHdr_S *)&CrysMsg);
  772. coredev->sendrequest_handler(coredev->context, &CrysMsg,
  773. sizeof(CrysMsg));
  774. }
  775. return 0;
  776. }
  777. /**
  778. * sets initial device mode and notifies client hotplugs that device is ready
  779. *
  780. * @param coredev pointer to a coredev object returned by
  781. * smscore_register_device
  782. *
  783. * @return 0 on success, <0 on error.
  784. */
  785. int smscore_start_device(struct smscore_device_t *coredev)
  786. {
  787. int rc = smscore_set_device_mode(
  788. coredev, smscore_registry_getmode(coredev->devpath));
  789. if (rc < 0) {
  790. sms_info("set device mode faile , rc %d", rc);
  791. return rc;
  792. }
  793. rc = smscore_configure_board(coredev);
  794. if (rc < 0) {
  795. sms_info("configure board failed , rc %d", rc);
  796. return rc;
  797. }
  798. kmutex_lock(&g_smscore_deviceslock);
  799. rc = smscore_notify_callbacks(coredev, coredev->device, 1);
  800. smscore_init_ir(coredev);
  801. sms_info("device %p started, rc %d", coredev, rc);
  802. kmutex_unlock(&g_smscore_deviceslock);
  803. return rc;
  804. }
  805. EXPORT_SYMBOL_GPL(smscore_start_device);
  806. static int smscore_load_firmware_family2(struct smscore_device_t *coredev,
  807. void *buffer, size_t size)
  808. {
  809. struct SmsFirmware_ST *firmware = (struct SmsFirmware_ST *) buffer;
  810. struct SmsMsgData_ST4 *msg;
  811. u32 mem_address, calc_checksum = 0;
  812. u32 i, *ptr;
  813. u8 *payload = firmware->Payload;
  814. int rc = 0;
  815. firmware->StartAddress = le32_to_cpu(firmware->StartAddress);
  816. firmware->Length = le32_to_cpu(firmware->Length);
  817. mem_address = firmware->StartAddress;
  818. sms_info("loading FW to addr 0x%x size %d",
  819. mem_address, firmware->Length);
  820. if (coredev->preload_handler) {
  821. rc = coredev->preload_handler(coredev->context);
  822. if (rc < 0)
  823. return rc;
  824. }
  825. /* PAGE_SIZE buffer shall be enough and dma aligned */
  826. msg = kmalloc(PAGE_SIZE, GFP_KERNEL | GFP_DMA);
  827. if (!msg)
  828. return -ENOMEM;
  829. if (coredev->mode != DEVICE_MODE_NONE) {
  830. sms_debug("sending reload command.");
  831. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_START_REQ,
  832. sizeof(struct SmsMsgHdr_ST));
  833. rc = smscore_sendrequest_and_wait(coredev, msg,
  834. msg->xMsgHeader.msgLength,
  835. &coredev->reload_start_done);
  836. if (rc < 0) {
  837. sms_err("device reload failed, rc %d", rc);
  838. goto exit_fw_download;
  839. }
  840. mem_address = *(u32 *) &payload[20];
  841. }
  842. for (i = 0, ptr = (u32 *)firmware->Payload; i < firmware->Length/4 ;
  843. i++, ptr++)
  844. calc_checksum += *ptr;
  845. while (size && rc >= 0) {
  846. struct SmsDataDownload_ST *DataMsg =
  847. (struct SmsDataDownload_ST *) msg;
  848. int payload_size = min((int) size, SMS_MAX_PAYLOAD_SIZE);
  849. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_DATA_DOWNLOAD_REQ,
  850. (u16)(sizeof(struct SmsMsgHdr_ST) +
  851. sizeof(u32) + payload_size));
  852. DataMsg->MemAddr = mem_address;
  853. memcpy(DataMsg->Payload, payload, payload_size);
  854. rc = smscore_sendrequest_and_wait(coredev, DataMsg,
  855. DataMsg->xMsgHeader.msgLength,
  856. &coredev->data_download_done);
  857. payload += payload_size;
  858. size -= payload_size;
  859. mem_address += payload_size;
  860. }
  861. if (rc < 0)
  862. goto exit_fw_download;
  863. sms_err("sending MSG_SMS_DATA_VALIDITY_REQ expecting 0x%x",
  864. calc_checksum);
  865. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_DATA_VALIDITY_REQ,
  866. sizeof(msg->xMsgHeader) +
  867. sizeof(u32) * 3);
  868. msg->msgData[0] = firmware->StartAddress;
  869. /* Entry point */
  870. msg->msgData[1] = firmware->Length;
  871. msg->msgData[2] = 0; /* Regular checksum*/
  872. smsendian_handle_tx_message(msg);
  873. rc = smscore_sendrequest_and_wait(coredev, msg,
  874. msg->xMsgHeader.msgLength,
  875. &coredev->data_validity_done);
  876. if (rc < 0)
  877. goto exit_fw_download;
  878. if (coredev->mode == DEVICE_MODE_NONE) {
  879. struct SmsMsgData_ST *TriggerMsg =
  880. (struct SmsMsgData_ST *) msg;
  881. sms_debug("sending MSG_SMS_SWDOWNLOAD_TRIGGER_REQ");
  882. SMS_INIT_MSG(&msg->xMsgHeader,
  883. MSG_SMS_SWDOWNLOAD_TRIGGER_REQ,
  884. sizeof(struct SmsMsgHdr_ST) +
  885. sizeof(u32) * 5);
  886. TriggerMsg->msgData[0] = firmware->StartAddress;
  887. /* Entry point */
  888. TriggerMsg->msgData[1] = 6; /* Priority */
  889. TriggerMsg->msgData[2] = 0x200; /* Stack size */
  890. TriggerMsg->msgData[3] = 0; /* Parameter */
  891. TriggerMsg->msgData[4] = 4; /* Task ID */
  892. smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
  893. rc = smscore_sendrequest_and_wait(coredev, TriggerMsg,
  894. TriggerMsg->xMsgHeader.msgLength,
  895. &coredev->trigger_done);
  896. } else {
  897. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SW_RELOAD_EXEC_REQ,
  898. sizeof(struct SmsMsgHdr_ST));
  899. smsendian_handle_tx_message((struct SmsMsgHdr_S *)msg);
  900. rc = coredev->sendrequest_handler(coredev->context, msg,
  901. msg->xMsgHeader.msgLength);
  902. }
  903. if (rc < 0)
  904. goto exit_fw_download;
  905. /*
  906. * backward compatibility - wait to device_ready_done for
  907. * not more than 400 ms
  908. */
  909. msleep(400);
  910. exit_fw_download:
  911. kfree(msg);
  912. if (coredev->postload_handler) {
  913. sms_debug("rc=%d, postload=0x%p", rc, coredev->postload_handler);
  914. if (rc >= 0)
  915. return coredev->postload_handler(coredev->context);
  916. }
  917. sms_debug("rc=%d", rc);
  918. return rc;
  919. }
  920. static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
  921. int mode, int lookup);
  922. /**
  923. * loads specified firmware into a buffer and calls device loadfirmware_handler
  924. *
  925. * @param coredev pointer to a coredev object returned by
  926. * smscore_register_device
  927. * @param filename null-terminated string specifies firmware file name
  928. * @param loadfirmware_handler device handler that loads firmware
  929. *
  930. * @return 0 on success, <0 on error.
  931. */
  932. static int smscore_load_firmware_from_file(struct smscore_device_t *coredev,
  933. int mode, int lookup,
  934. loadfirmware_t loadfirmware_handler)
  935. {
  936. int rc = -ENOENT;
  937. u8 *fw_buf;
  938. u32 fw_buf_size;
  939. const struct firmware *fw;
  940. char *fw_filename = smscore_get_fw_filename(coredev, mode, lookup);
  941. sms_debug("Firmware name: %s\n", fw_filename);
  942. if (!strcmp(fw_filename, "none"))
  943. return -ENOENT;
  944. if (loadfirmware_handler == NULL && !(coredev->device_flags
  945. & SMS_DEVICE_FAMILY2))
  946. return -EINVAL;
  947. rc = request_firmware(&fw, fw_filename, coredev->device);
  948. if (rc < 0) {
  949. sms_info("failed to open \"%s\"", fw_filename);
  950. return rc;
  951. }
  952. sms_info("read fw %s, buffer size=0x%zx", fw_filename, fw->size);
  953. fw_buf = kmalloc(ALIGN(fw->size, SMS_ALLOC_ALIGNMENT),
  954. GFP_KERNEL | GFP_DMA);
  955. if (!fw_buf) {
  956. sms_info("failed to allocate firmware buffer");
  957. return -ENOMEM;
  958. }
  959. memcpy(fw_buf, fw->data, fw->size);
  960. fw_buf_size = fw->size;
  961. rc = (coredev->device_flags & SMS_DEVICE_FAMILY2) ?
  962. smscore_load_firmware_family2(coredev, fw_buf, fw_buf_size)
  963. : loadfirmware_handler(coredev->context, fw_buf,
  964. fw_buf_size);
  965. kfree(fw_buf);
  966. release_firmware(fw);
  967. return rc;
  968. }
  969. /**
  970. * notifies all clients registered with the device, notifies hotplugs,
  971. * frees all buffers and coredev object
  972. *
  973. * @param coredev pointer to a coredev object returned by
  974. * smscore_register_device
  975. *
  976. * @return 0 on success, <0 on error.
  977. */
  978. void smscore_unregister_device(struct smscore_device_t *coredev)
  979. {
  980. struct smscore_buffer_t *cb;
  981. int num_buffers = 0;
  982. int retry = 0;
  983. kmutex_lock(&g_smscore_deviceslock);
  984. /* Release input device (IR) resources */
  985. sms_ir_exit(coredev);
  986. smscore_notify_clients(coredev);
  987. smscore_notify_callbacks(coredev, NULL, 0);
  988. /* at this point all buffers should be back
  989. * onresponse must no longer be called */
  990. while (1) {
  991. while (!list_empty(&coredev->buffers)) {
  992. cb = (struct smscore_buffer_t *) coredev->buffers.next;
  993. list_del(&cb->entry);
  994. kfree(cb);
  995. num_buffers++;
  996. }
  997. if (num_buffers == coredev->num_buffers)
  998. break;
  999. if (++retry > 10) {
  1000. sms_info("exiting although "
  1001. "not all buffers released.");
  1002. break;
  1003. }
  1004. sms_info("waiting for %d buffer(s)",
  1005. coredev->num_buffers - num_buffers);
  1006. kmutex_unlock(&g_smscore_deviceslock);
  1007. msleep(100);
  1008. kmutex_lock(&g_smscore_deviceslock);
  1009. }
  1010. sms_info("freed %d buffers", num_buffers);
  1011. if (coredev->common_buffer)
  1012. dma_free_coherent(NULL, coredev->common_buffer_size,
  1013. coredev->common_buffer, coredev->common_buffer_phys);
  1014. kfree(coredev->fw_buf);
  1015. list_del(&coredev->entry);
  1016. kfree(coredev);
  1017. kmutex_unlock(&g_smscore_deviceslock);
  1018. sms_info("device %p destroyed", coredev);
  1019. }
  1020. EXPORT_SYMBOL_GPL(smscore_unregister_device);
  1021. static int smscore_detect_mode(struct smscore_device_t *coredev)
  1022. {
  1023. void *buffer = kmalloc(sizeof(struct SmsMsgHdr_ST) + SMS_DMA_ALIGNMENT,
  1024. GFP_KERNEL | GFP_DMA);
  1025. struct SmsMsgHdr_ST *msg =
  1026. (struct SmsMsgHdr_ST *) SMS_ALIGN_ADDRESS(buffer);
  1027. int rc;
  1028. if (!buffer)
  1029. return -ENOMEM;
  1030. SMS_INIT_MSG(msg, MSG_SMS_GET_VERSION_EX_REQ,
  1031. sizeof(struct SmsMsgHdr_ST));
  1032. rc = smscore_sendrequest_and_wait(coredev, msg, msg->msgLength,
  1033. &coredev->version_ex_done);
  1034. if (rc == -ETIME) {
  1035. sms_err("MSG_SMS_GET_VERSION_EX_REQ failed first try");
  1036. if (wait_for_completion_timeout(&coredev->resume_done,
  1037. msecs_to_jiffies(5000))) {
  1038. rc = smscore_sendrequest_and_wait(
  1039. coredev, msg, msg->msgLength,
  1040. &coredev->version_ex_done);
  1041. if (rc < 0)
  1042. sms_err("MSG_SMS_GET_VERSION_EX_REQ failed "
  1043. "second try, rc %d", rc);
  1044. } else
  1045. rc = -ETIME;
  1046. }
  1047. kfree(buffer);
  1048. return rc;
  1049. }
  1050. static char *smscore_fw_lkup[][SMS_NUM_OF_DEVICE_TYPES] = {
  1051. /*Stellar, NOVA A0, Nova B0, VEGA, VENICE, MING, PELE, RIO, DENVER_1530, DENVER_2160 */
  1052. /*DVBT*/
  1053. { "none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none", "none", "none", "none", "dvb_rio.inp", "none", "none" },
  1054. /*DVBH*/
  1055. { "none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none", "none", "none", "none", "dvbh_rio.inp", "none", "none" },
  1056. /*TDMB*/
  1057. { "none", "tdmb_nova_12mhz.inp", "tdmb_nova_12mhz_b0.inp", "none", "none", "none", "none", "none", "none", "tdmb_denver.inp" },
  1058. /*DABIP*/
  1059. { "none", "none", "none", "none", "none", "none", "none", "none", "none", "none" },
  1060. /*DVBT_BDA*/
  1061. { "none", "dvb_nova_12mhz.inp", "dvb_nova_12mhz_b0.inp", "none", "none", "none", "none", "dvb_rio.inp", "none", "none" },
  1062. /*ISDBT*/
  1063. { "none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none", "none", "none", "isdbt_pele.inp", "isdbt_rio.inp", "none", "none" },
  1064. /*ISDBT_BDA*/
  1065. { "none", "isdbt_nova_12mhz.inp", "isdbt_nova_12mhz_b0.inp", "none", "none", "none", "isdbt_pele.inp", "isdbt_rio.inp", "none", "none" },
  1066. /*CMMB*/
  1067. { "none", "none", "none", "cmmb_vega_12mhz.inp", "cmmb_venice_12mhz.inp", "cmmb_ming_app.inp", "none", "none", "none", "none" },
  1068. /*RAW - not supported*/
  1069. { "none", "none", "none", "none", "none", "none", "none", "none", "none", "none" },
  1070. /*FM*/
  1071. { "none", "none", "fm_radio.inp", "none", "none", "none", "none", "fm_radio_rio.inp", "none", "none" },
  1072. /*FM_BDA*/
  1073. { "none", "none", "fm_radio.inp", "none", "none", "none", "none", "fm_radio_rio.inp", "none", "none" },
  1074. /*ATSC*/
  1075. { "none", "none", "none", "none", "none", "none", "none", "none", "atsc_denver.inp", "none" }
  1076. };
  1077. /**
  1078. * get firmware file name from one of the two mechanisms : sms_boards or
  1079. * smscore_fw_lkup.
  1080. * @param coredev pointer to a coredev object returned by
  1081. * smscore_register_device
  1082. * @param mode requested mode of operation
  1083. * @param lookup if 1, always get the fw filename from smscore_fw_lkup
  1084. * table. if 0, try first to get from sms_boards
  1085. *
  1086. * @return 0 on success, <0 on error.
  1087. */
  1088. static char *smscore_get_fw_filename(struct smscore_device_t *coredev,
  1089. int mode, int lookup)
  1090. {
  1091. char **fw;
  1092. int board_id = smscore_get_board_id(coredev);
  1093. enum sms_device_type_st type;
  1094. type = smscore_registry_gettype(coredev->devpath);
  1095. if ((board_id == SMS_BOARD_UNKNOWN) || (lookup == 1)) {
  1096. sms_debug("trying to get fw name from lookup table mode %d type %d",
  1097. mode, type);
  1098. return smscore_fw_lkup[mode][type];
  1099. }
  1100. sms_debug("trying to get fw name from sms_boards board_id %d mode %d",
  1101. board_id, mode);
  1102. fw = sms_get_board(board_id)->fw;
  1103. if (fw == NULL) {
  1104. sms_debug("cannot find fw name in sms_boards, getting from lookup table mode %d type %d",
  1105. mode, type);
  1106. return smscore_fw_lkup[mode][type];
  1107. }
  1108. if (fw[mode] == NULL) {
  1109. sms_debug("cannot find fw name in sms_boards, getting from lookup table mode %d type %d",
  1110. mode, type);
  1111. return smscore_fw_lkup[mode][type];
  1112. }
  1113. return fw[mode];
  1114. }
  1115. /**
  1116. * calls device handler to change mode of operation
  1117. * NOTE: stellar/usb may disconnect when changing mode
  1118. *
  1119. * @param coredev pointer to a coredev object returned by
  1120. * smscore_register_device
  1121. * @param mode requested mode of operation
  1122. *
  1123. * @return 0 on success, <0 on error.
  1124. */
  1125. int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
  1126. {
  1127. int rc = 0;
  1128. sms_debug("set device mode to %d", mode);
  1129. if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
  1130. if (mode < DEVICE_MODE_DVBT || mode >= DEVICE_MODE_RAW_TUNER) {
  1131. sms_err("invalid mode specified %d", mode);
  1132. return -EINVAL;
  1133. }
  1134. smscore_registry_setmode(coredev->devpath, mode);
  1135. if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) {
  1136. rc = smscore_detect_mode(coredev);
  1137. if (rc < 0) {
  1138. sms_err("mode detect failed %d", rc);
  1139. return rc;
  1140. }
  1141. }
  1142. if (coredev->mode == mode) {
  1143. sms_info("device mode %d already set", mode);
  1144. return 0;
  1145. }
  1146. if (!(coredev->modes_supported & (1 << mode))) {
  1147. rc = smscore_load_firmware_from_file(coredev,
  1148. mode, 0, NULL);
  1149. /*
  1150. * try again with the default firmware -
  1151. * get the fw filename from look-up table
  1152. */
  1153. if (rc < 0) {
  1154. sms_debug("error %d loading firmware, trying again with default firmware",
  1155. rc);
  1156. rc = smscore_load_firmware_from_file(coredev,
  1157. mode, 1,
  1158. NULL);
  1159. if (rc < 0) {
  1160. sms_debug("error %d loading firmware",
  1161. rc);
  1162. return rc;
  1163. }
  1164. }
  1165. if (rc >= 0)
  1166. sms_info("firmware download success");
  1167. } else {
  1168. sms_info("mode %d is already supported by running firmware",
  1169. mode);
  1170. }
  1171. } else {
  1172. if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) {
  1173. sms_err("invalid mode specified %d", mode);
  1174. return -EINVAL;
  1175. }
  1176. smscore_registry_setmode(coredev->devpath, mode);
  1177. if (coredev->detectmode_handler)
  1178. coredev->detectmode_handler(coredev->context,
  1179. &coredev->mode);
  1180. if (coredev->mode != mode && coredev->setmode_handler)
  1181. rc = coredev->setmode_handler(coredev->context, mode);
  1182. }
  1183. if (rc >= 0) {
  1184. char *buffer;
  1185. coredev->mode = mode;
  1186. coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
  1187. buffer = kmalloc(sizeof(struct SmsMsgData_ST) +
  1188. SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
  1189. if (buffer) {
  1190. struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *) SMS_ALIGN_ADDRESS(buffer);
  1191. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ,
  1192. sizeof(struct SmsMsgData_ST));
  1193. msg->msgData[0] = mode;
  1194. rc = smscore_sendrequest_and_wait(
  1195. coredev, msg, msg->xMsgHeader.msgLength,
  1196. &coredev->init_device_done);
  1197. kfree(buffer);
  1198. }
  1199. }
  1200. if (rc < 0)
  1201. sms_err("return error code %d.", rc);
  1202. else
  1203. sms_debug("Success setting device mode.");
  1204. return rc;
  1205. }
  1206. /**
  1207. * calls device handler to get current mode of operation
  1208. *
  1209. * @param coredev pointer to a coredev object returned by
  1210. * smscore_register_device
  1211. *
  1212. * @return current mode
  1213. */
  1214. int smscore_get_device_mode(struct smscore_device_t *coredev)
  1215. {
  1216. return coredev->mode;
  1217. }
  1218. EXPORT_SYMBOL_GPL(smscore_get_device_mode);
  1219. /**
  1220. * find client by response id & type within the clients list.
  1221. * return client handle or NULL.
  1222. *
  1223. * @param coredev pointer to a coredev object returned by
  1224. * smscore_register_device
  1225. * @param data_type client data type (SMS_DONT_CARE for all types)
  1226. * @param id client id (SMS_DONT_CARE for all id)
  1227. *
  1228. */
  1229. static struct
  1230. smscore_client_t *smscore_find_client(struct smscore_device_t *coredev,
  1231. int data_type, int id)
  1232. {
  1233. struct list_head *first;
  1234. struct smscore_client_t *client;
  1235. unsigned long flags;
  1236. struct list_head *firstid;
  1237. struct smscore_idlist_t *client_id;
  1238. spin_lock_irqsave(&coredev->clientslock, flags);
  1239. first = &coredev->clients;
  1240. list_for_each_entry(client, first, entry) {
  1241. firstid = &client->idlist;
  1242. list_for_each_entry(client_id, firstid, entry) {
  1243. if ((client_id->id == id) &&
  1244. (client_id->data_type == data_type ||
  1245. (client_id->data_type == 0)))
  1246. goto found;
  1247. }
  1248. }
  1249. client = NULL;
  1250. found:
  1251. spin_unlock_irqrestore(&coredev->clientslock, flags);
  1252. return client;
  1253. }
  1254. /**
  1255. * find client by response id/type, call clients onresponse handler
  1256. * return buffer to pool on error
  1257. *
  1258. * @param coredev pointer to a coredev object returned by
  1259. * smscore_register_device
  1260. * @param cb pointer to response buffer descriptor
  1261. *
  1262. */
  1263. void smscore_onresponse(struct smscore_device_t *coredev,
  1264. struct smscore_buffer_t *cb) {
  1265. struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) ((u8 *) cb->p
  1266. + cb->offset);
  1267. struct smscore_client_t *client;
  1268. int rc = -EBUSY;
  1269. static unsigned long last_sample_time; /* = 0; */
  1270. static int data_total; /* = 0; */
  1271. unsigned long time_now = jiffies_to_msecs(jiffies);
  1272. if (!last_sample_time)
  1273. last_sample_time = time_now;
  1274. if (time_now - last_sample_time > 10000) {
  1275. sms_debug("\ndata rate %d bytes/secs",
  1276. (int)((data_total * 1000) /
  1277. (time_now - last_sample_time)));
  1278. last_sample_time = time_now;
  1279. data_total = 0;
  1280. }
  1281. data_total += cb->size;
  1282. /* Do we need to re-route? */
  1283. if ((phdr->msgType == MSG_SMS_HO_PER_SLICES_IND) ||
  1284. (phdr->msgType == MSG_SMS_TRANSMISSION_IND)) {
  1285. if (coredev->mode == DEVICE_MODE_DVBT_BDA)
  1286. phdr->msgDstId = DVBT_BDA_CONTROL_MSG_ID;
  1287. }
  1288. client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId);
  1289. /* If no client registered for type & id,
  1290. * check for control client where type is not registered */
  1291. if (client)
  1292. rc = client->onresponse_handler(client->context, cb);
  1293. if (rc < 0) {
  1294. smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
  1295. switch (phdr->msgType) {
  1296. case MSG_SMS_ISDBT_TUNE_RES:
  1297. break;
  1298. case MSG_SMS_RF_TUNE_RES:
  1299. break;
  1300. case MSG_SMS_SIGNAL_DETECTED_IND:
  1301. break;
  1302. case MSG_SMS_NO_SIGNAL_IND:
  1303. break;
  1304. case MSG_SMS_SPI_INT_LINE_SET_RES:
  1305. break;
  1306. case MSG_SMS_INTERFACE_LOCK_IND:
  1307. break;
  1308. case MSG_SMS_INTERFACE_UNLOCK_IND:
  1309. break;
  1310. case MSG_SMS_GET_VERSION_EX_RES:
  1311. {
  1312. struct SmsVersionRes_ST *ver =
  1313. (struct SmsVersionRes_ST *) phdr;
  1314. sms_debug("Firmware id %d prots 0x%x ver %d.%d",
  1315. ver->FirmwareId, ver->SupportedProtocols,
  1316. ver->RomVersionMajor, ver->RomVersionMinor);
  1317. coredev->mode = ver->FirmwareId == 255 ?
  1318. DEVICE_MODE_NONE : ver->FirmwareId;
  1319. coredev->modes_supported = ver->SupportedProtocols;
  1320. coredev->fw_version = ver->RomVersionMajor << 8 |
  1321. ver->RomVersionMinor;
  1322. complete(&coredev->version_ex_done);
  1323. break;
  1324. }
  1325. case MSG_SMS_INIT_DEVICE_RES:
  1326. complete(&coredev->init_device_done);
  1327. break;
  1328. case MSG_SW_RELOAD_START_RES:
  1329. complete(&coredev->reload_start_done);
  1330. break;
  1331. case MSG_SMS_DATA_VALIDITY_RES:
  1332. {
  1333. struct SmsMsgData_ST *validity = (struct SmsMsgData_ST *) phdr;
  1334. sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
  1335. validity->msgData[0]);
  1336. complete(&coredev->data_validity_done);
  1337. break;
  1338. }
  1339. case MSG_SMS_DATA_DOWNLOAD_RES:
  1340. complete(&coredev->data_download_done);
  1341. break;
  1342. case MSG_SW_RELOAD_EXEC_RES:
  1343. break;
  1344. case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
  1345. complete(&coredev->trigger_done);
  1346. break;
  1347. case MSG_SMS_SLEEP_RESUME_COMP_IND:
  1348. complete(&coredev->resume_done);
  1349. break;
  1350. case MSG_SMS_GPIO_CONFIG_EX_RES:
  1351. complete(&coredev->gpio_configuration_done);
  1352. break;
  1353. case MSG_SMS_GPIO_SET_LEVEL_RES:
  1354. complete(&coredev->gpio_set_level_done);
  1355. break;
  1356. case MSG_SMS_GPIO_GET_LEVEL_RES:
  1357. {
  1358. u32 *msgdata = (u32 *) phdr;
  1359. coredev->gpio_get_res = msgdata[1];
  1360. sms_debug("gpio level %d",
  1361. coredev->gpio_get_res);
  1362. complete(&coredev->gpio_get_level_done);
  1363. break;
  1364. }
  1365. case MSG_SMS_START_IR_RES:
  1366. complete(&coredev->ir_init_done);
  1367. break;
  1368. case MSG_SMS_IR_SAMPLES_IND:
  1369. sms_ir_event(coredev,
  1370. (const char *)
  1371. ((char *)phdr
  1372. + sizeof(struct SmsMsgHdr_ST)),
  1373. (int)phdr->msgLength
  1374. - sizeof(struct SmsMsgHdr_ST));
  1375. break;
  1376. default:
  1377. sms_debug("message not handled.\n");
  1378. break;
  1379. }
  1380. smscore_putbuffer(coredev, cb);
  1381. }
  1382. }
  1383. EXPORT_SYMBOL_GPL(smscore_onresponse);
  1384. /**
  1385. * return pointer to next free buffer descriptor from core pool
  1386. *
  1387. * @param coredev pointer to a coredev object returned by
  1388. * smscore_register_device
  1389. *
  1390. * @return pointer to descriptor on success, NULL on error.
  1391. */
  1392. static struct smscore_buffer_t *get_entry(struct smscore_device_t *coredev)
  1393. {
  1394. struct smscore_buffer_t *cb = NULL;
  1395. unsigned long flags;
  1396. spin_lock_irqsave(&coredev->bufferslock, flags);
  1397. if (!list_empty(&coredev->buffers)) {
  1398. cb = (struct smscore_buffer_t *) coredev->buffers.next;
  1399. list_del(&cb->entry);
  1400. }
  1401. spin_unlock_irqrestore(&coredev->bufferslock, flags);
  1402. return cb;
  1403. }
  1404. struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
  1405. {
  1406. struct smscore_buffer_t *cb = NULL;
  1407. wait_event(coredev->buffer_mng_waitq, (cb = get_entry(coredev)));
  1408. return cb;
  1409. }
  1410. EXPORT_SYMBOL_GPL(smscore_getbuffer);
  1411. /**
  1412. * return buffer descriptor to a pool
  1413. *
  1414. * @param coredev pointer to a coredev object returned by
  1415. * smscore_register_device
  1416. * @param cb pointer buffer descriptor
  1417. *
  1418. */
  1419. void smscore_putbuffer(struct smscore_device_t *coredev,
  1420. struct smscore_buffer_t *cb) {
  1421. wake_up_interruptible(&coredev->buffer_mng_waitq);
  1422. list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
  1423. }
  1424. EXPORT_SYMBOL_GPL(smscore_putbuffer);
  1425. static int smscore_validate_client(struct smscore_device_t *coredev,
  1426. struct smscore_client_t *client,
  1427. int data_type, int id)
  1428. {
  1429. struct smscore_idlist_t *listentry;
  1430. struct smscore_client_t *registered_client;
  1431. if (!client) {
  1432. sms_err("bad parameter.");
  1433. return -EINVAL;
  1434. }
  1435. registered_client = smscore_find_client(coredev, data_type, id);
  1436. if (registered_client == client)
  1437. return 0;
  1438. if (registered_client) {
  1439. sms_err("The msg ID already registered to another client.");
  1440. return -EEXIST;
  1441. }
  1442. listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL);
  1443. if (!listentry) {
  1444. sms_err("Can't allocate memory for client id.");
  1445. return -ENOMEM;
  1446. }
  1447. listentry->id = id;
  1448. listentry->data_type = data_type;
  1449. list_add_locked(&listentry->entry, &client->idlist,
  1450. &coredev->clientslock);
  1451. return 0;
  1452. }
  1453. /**
  1454. * creates smsclient object, check that id is taken by another client
  1455. *
  1456. * @param coredev pointer to a coredev object from clients hotplug
  1457. * @param initial_id all messages with this id would be sent to this client
  1458. * @param data_type all messages of this type would be sent to this client
  1459. * @param onresponse_handler client handler that is called to
  1460. * process incoming messages
  1461. * @param onremove_handler client handler that is called when device is removed
  1462. * @param context client-specific context
  1463. * @param client pointer to a value that receives created smsclient object
  1464. *
  1465. * @return 0 on success, <0 on error.
  1466. */
  1467. int smscore_register_client(struct smscore_device_t *coredev,
  1468. struct smsclient_params_t *params,
  1469. struct smscore_client_t **client)
  1470. {
  1471. struct smscore_client_t *newclient;
  1472. /* check that no other channel with same parameters exists */
  1473. if (smscore_find_client(coredev, params->data_type,
  1474. params->initial_id)) {
  1475. sms_err("Client already exist.");
  1476. return -EEXIST;
  1477. }
  1478. newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL);
  1479. if (!newclient) {
  1480. sms_err("Failed to allocate memory for client.");
  1481. return -ENOMEM;
  1482. }
  1483. INIT_LIST_HEAD(&newclient->idlist);
  1484. newclient->coredev = coredev;
  1485. newclient->onresponse_handler = params->onresponse_handler;
  1486. newclient->onremove_handler = params->onremove_handler;
  1487. newclient->context = params->context;
  1488. list_add_locked(&newclient->entry, &coredev->clients,
  1489. &coredev->clientslock);
  1490. smscore_validate_client(coredev, newclient, params->data_type,
  1491. params->initial_id);
  1492. *client = newclient;
  1493. sms_debug("%p %d %d", params->context, params->data_type,
  1494. params->initial_id);
  1495. return 0;
  1496. }
  1497. EXPORT_SYMBOL_GPL(smscore_register_client);
  1498. /**
  1499. * frees smsclient object and all subclients associated with it
  1500. *
  1501. * @param client pointer to smsclient object returned by
  1502. * smscore_register_client
  1503. *
  1504. */
  1505. void smscore_unregister_client(struct smscore_client_t *client)
  1506. {
  1507. struct smscore_device_t *coredev = client->coredev;
  1508. unsigned long flags;
  1509. spin_lock_irqsave(&coredev->clientslock, flags);
  1510. while (!list_empty(&client->idlist)) {
  1511. struct smscore_idlist_t *identry =
  1512. (struct smscore_idlist_t *) client->idlist.next;
  1513. list_del(&identry->entry);
  1514. kfree(identry);
  1515. }
  1516. sms_info("%p", client->context);
  1517. list_del(&client->entry);
  1518. kfree(client);
  1519. spin_unlock_irqrestore(&coredev->clientslock, flags);
  1520. }
  1521. EXPORT_SYMBOL_GPL(smscore_unregister_client);
  1522. /**
  1523. * verifies that source id is not taken by another client,
  1524. * calls device handler to send requests to the device
  1525. *
  1526. * @param client pointer to smsclient object returned by
  1527. * smscore_register_client
  1528. * @param buffer pointer to a request buffer
  1529. * @param size size (in bytes) of request buffer
  1530. *
  1531. * @return 0 on success, <0 on error.
  1532. */
  1533. int smsclient_sendrequest(struct smscore_client_t *client,
  1534. void *buffer, size_t size)
  1535. {
  1536. struct smscore_device_t *coredev;
  1537. struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
  1538. int rc;
  1539. if (client == NULL) {
  1540. sms_err("Got NULL client");
  1541. return -EINVAL;
  1542. }
  1543. coredev = client->coredev;
  1544. /* check that no other channel with same id exists */
  1545. if (coredev == NULL) {
  1546. sms_err("Got NULL coredev");
  1547. return -EINVAL;
  1548. }
  1549. rc = smscore_validate_client(client->coredev, client, 0,
  1550. phdr->msgSrcId);
  1551. if (rc < 0)
  1552. return rc;
  1553. return coredev->sendrequest_handler(coredev->context, buffer, size);
  1554. }
  1555. EXPORT_SYMBOL_GPL(smsclient_sendrequest);
  1556. /* old GPIO managements implementation */
  1557. int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
  1558. struct smscore_config_gpio *pinconfig)
  1559. {
  1560. struct {
  1561. struct SmsMsgHdr_ST hdr;
  1562. u32 data[6];
  1563. } msg;
  1564. if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
  1565. msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1566. msg.hdr.msgDstId = HIF_TASK;
  1567. msg.hdr.msgFlags = 0;
  1568. msg.hdr.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ;
  1569. msg.hdr.msgLength = sizeof(msg);
  1570. msg.data[0] = pin;
  1571. msg.data[1] = pinconfig->pullupdown;
  1572. /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
  1573. msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0;
  1574. switch (pinconfig->outputdriving) {
  1575. case SMS_GPIO_OUTPUTDRIVING_S_16mA:
  1576. msg.data[3] = 7; /* Nova - 16mA */
  1577. break;
  1578. case SMS_GPIO_OUTPUTDRIVING_S_12mA:
  1579. msg.data[3] = 5; /* Nova - 11mA */
  1580. break;
  1581. case SMS_GPIO_OUTPUTDRIVING_S_8mA:
  1582. msg.data[3] = 3; /* Nova - 7mA */
  1583. break;
  1584. case SMS_GPIO_OUTPUTDRIVING_S_4mA:
  1585. default:
  1586. msg.data[3] = 2; /* Nova - 4mA */
  1587. break;
  1588. }
  1589. msg.data[4] = pinconfig->direction;
  1590. msg.data[5] = 0;
  1591. } else /* TODO: SMS_DEVICE_FAMILY1 */
  1592. return -EINVAL;
  1593. return coredev->sendrequest_handler(coredev->context,
  1594. &msg, sizeof(msg));
  1595. }
  1596. int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
  1597. {
  1598. struct {
  1599. struct SmsMsgHdr_ST hdr;
  1600. u32 data[3];
  1601. } msg;
  1602. if (pin > MAX_GPIO_PIN_NUMBER)
  1603. return -EINVAL;
  1604. msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1605. msg.hdr.msgDstId = HIF_TASK;
  1606. msg.hdr.msgFlags = 0;
  1607. msg.hdr.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ;
  1608. msg.hdr.msgLength = sizeof(msg);
  1609. msg.data[0] = pin;
  1610. msg.data[1] = level ? 1 : 0;
  1611. msg.data[2] = 0;
  1612. return coredev->sendrequest_handler(coredev->context,
  1613. &msg, sizeof(msg));
  1614. }
  1615. /* new GPIO management implementation */
  1616. static int GetGpioPinParams(u32 PinNum, u32 *pTranslatedPinNum,
  1617. u32 *pGroupNum, u32 *pGroupCfg) {
  1618. *pGroupCfg = 1;
  1619. if (PinNum <= 1) {
  1620. *pTranslatedPinNum = 0;
  1621. *pGroupNum = 9;
  1622. *pGroupCfg = 2;
  1623. } else if (PinNum >= 2 && PinNum <= 6) {
  1624. *pTranslatedPinNum = 2;
  1625. *pGroupNum = 0;
  1626. *pGroupCfg = 2;
  1627. } else if (PinNum >= 7 && PinNum <= 11) {
  1628. *pTranslatedPinNum = 7;
  1629. *pGroupNum = 1;
  1630. } else if (PinNum >= 12 && PinNum <= 15) {
  1631. *pTranslatedPinNum = 12;
  1632. *pGroupNum = 2;
  1633. *pGroupCfg = 3;
  1634. } else if (PinNum == 16) {
  1635. *pTranslatedPinNum = 16;
  1636. *pGroupNum = 23;
  1637. } else if (PinNum >= 17 && PinNum <= 24) {
  1638. *pTranslatedPinNum = 17;
  1639. *pGroupNum = 3;
  1640. } else if (PinNum == 25) {
  1641. *pTranslatedPinNum = 25;
  1642. *pGroupNum = 6;
  1643. } else if (PinNum >= 26 && PinNum <= 28) {
  1644. *pTranslatedPinNum = 26;
  1645. *pGroupNum = 4;
  1646. } else if (PinNum == 29) {
  1647. *pTranslatedPinNum = 29;
  1648. *pGroupNum = 5;
  1649. *pGroupCfg = 2;
  1650. } else if (PinNum == 30) {
  1651. *pTranslatedPinNum = 30;
  1652. *pGroupNum = 8;
  1653. } else if (PinNum == 31) {
  1654. *pTranslatedPinNum = 31;
  1655. *pGroupNum = 17;
  1656. } else
  1657. return -1;
  1658. *pGroupCfg <<= 24;
  1659. return 0;
  1660. }
  1661. int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
  1662. struct smscore_config_gpio *pGpioConfig) {
  1663. u32 totalLen;
  1664. u32 TranslatedPinNum = 0;
  1665. u32 GroupNum = 0;
  1666. u32 ElectricChar;
  1667. u32 groupCfg;
  1668. void *buffer;
  1669. int rc;
  1670. struct SetGpioMsg {
  1671. struct SmsMsgHdr_ST xMsgHeader;
  1672. u32 msgData[6];
  1673. } *pMsg;
  1674. if (PinNum > MAX_GPIO_PIN_NUMBER)
  1675. return -EINVAL;
  1676. if (pGpioConfig == NULL)
  1677. return -EINVAL;
  1678. totalLen = sizeof(struct SmsMsgHdr_ST) + (sizeof(u32) * 6);
  1679. buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
  1680. GFP_KERNEL | GFP_DMA);
  1681. if (!buffer)
  1682. return -ENOMEM;
  1683. pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
  1684. pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1685. pMsg->xMsgHeader.msgDstId = HIF_TASK;
  1686. pMsg->xMsgHeader.msgFlags = 0;
  1687. pMsg->xMsgHeader.msgLength = (u16) totalLen;
  1688. pMsg->msgData[0] = PinNum;
  1689. if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
  1690. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ;
  1691. if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum,
  1692. &groupCfg) != 0) {
  1693. rc = -EINVAL;
  1694. goto free;
  1695. }
  1696. pMsg->msgData[1] = TranslatedPinNum;
  1697. pMsg->msgData[2] = GroupNum;
  1698. ElectricChar = (pGpioConfig->pullupdown)
  1699. | (pGpioConfig->inputcharacteristics << 2)
  1700. | (pGpioConfig->outputslewrate << 3)
  1701. | (pGpioConfig->outputdriving << 4);
  1702. pMsg->msgData[3] = ElectricChar;
  1703. pMsg->msgData[4] = pGpioConfig->direction;
  1704. pMsg->msgData[5] = groupCfg;
  1705. } else {
  1706. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ;
  1707. pMsg->msgData[1] = pGpioConfig->pullupdown;
  1708. pMsg->msgData[2] = pGpioConfig->outputslewrate;
  1709. pMsg->msgData[3] = pGpioConfig->outputdriving;
  1710. pMsg->msgData[4] = pGpioConfig->direction;
  1711. pMsg->msgData[5] = 0;
  1712. }
  1713. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
  1714. rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
  1715. &coredev->gpio_configuration_done);
  1716. if (rc != 0) {
  1717. if (rc == -ETIME)
  1718. sms_err("smscore_gpio_configure timeout");
  1719. else
  1720. sms_err("smscore_gpio_configure error");
  1721. }
  1722. free:
  1723. kfree(buffer);
  1724. return rc;
  1725. }
  1726. int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
  1727. u8 NewLevel) {
  1728. u32 totalLen;
  1729. int rc;
  1730. void *buffer;
  1731. struct SetGpioMsg {
  1732. struct SmsMsgHdr_ST xMsgHeader;
  1733. u32 msgData[3]; /* keep it 3 ! */
  1734. } *pMsg;
  1735. if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER))
  1736. return -EINVAL;
  1737. totalLen = sizeof(struct SmsMsgHdr_ST) +
  1738. (3 * sizeof(u32)); /* keep it 3 ! */
  1739. buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
  1740. GFP_KERNEL | GFP_DMA);
  1741. if (!buffer)
  1742. return -ENOMEM;
  1743. pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
  1744. pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1745. pMsg->xMsgHeader.msgDstId = HIF_TASK;
  1746. pMsg->xMsgHeader.msgFlags = 0;
  1747. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ;
  1748. pMsg->xMsgHeader.msgLength = (u16) totalLen;
  1749. pMsg->msgData[0] = PinNum;
  1750. pMsg->msgData[1] = NewLevel;
  1751. /* Send message to SMS */
  1752. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
  1753. rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
  1754. &coredev->gpio_set_level_done);
  1755. if (rc != 0) {
  1756. if (rc == -ETIME)
  1757. sms_err("smscore_gpio_set_level timeout");
  1758. else
  1759. sms_err("smscore_gpio_set_level error");
  1760. }
  1761. kfree(buffer);
  1762. return rc;
  1763. }
  1764. int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
  1765. u8 *level) {
  1766. u32 totalLen;
  1767. int rc;
  1768. void *buffer;
  1769. struct SetGpioMsg {
  1770. struct SmsMsgHdr_ST xMsgHeader;
  1771. u32 msgData[2];
  1772. } *pMsg;
  1773. if (PinNum > MAX_GPIO_PIN_NUMBER)
  1774. return -EINVAL;
  1775. totalLen = sizeof(struct SmsMsgHdr_ST) + (2 * sizeof(u32));
  1776. buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
  1777. GFP_KERNEL | GFP_DMA);
  1778. if (!buffer)
  1779. return -ENOMEM;
  1780. pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
  1781. pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1782. pMsg->xMsgHeader.msgDstId = HIF_TASK;
  1783. pMsg->xMsgHeader.msgFlags = 0;
  1784. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_GET_LEVEL_REQ;
  1785. pMsg->xMsgHeader.msgLength = (u16) totalLen;
  1786. pMsg->msgData[0] = PinNum;
  1787. pMsg->msgData[1] = 0;
  1788. /* Send message to SMS */
  1789. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
  1790. rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
  1791. &coredev->gpio_get_level_done);
  1792. if (rc != 0) {
  1793. if (rc == -ETIME)
  1794. sms_err("smscore_gpio_get_level timeout");
  1795. else
  1796. sms_err("smscore_gpio_get_level error");
  1797. }
  1798. kfree(buffer);
  1799. /* Its a race between other gpio_get_level() and the copy of the single
  1800. * global 'coredev->gpio_get_res' to the function's variable 'level'
  1801. */
  1802. *level = coredev->gpio_get_res;
  1803. return rc;
  1804. }
  1805. static int __init smscore_module_init(void)
  1806. {
  1807. int rc = 0;
  1808. INIT_LIST_HEAD(&g_smscore_notifyees);
  1809. INIT_LIST_HEAD(&g_smscore_devices);
  1810. kmutex_init(&g_smscore_deviceslock);
  1811. INIT_LIST_HEAD(&g_smscore_registry);
  1812. kmutex_init(&g_smscore_registrylock);
  1813. return rc;
  1814. }
  1815. static void __exit smscore_module_exit(void)
  1816. {
  1817. kmutex_lock(&g_smscore_deviceslock);
  1818. while (!list_empty(&g_smscore_notifyees)) {
  1819. struct smscore_device_notifyee_t *notifyee =
  1820. (struct smscore_device_notifyee_t *)
  1821. g_smscore_notifyees.next;
  1822. list_del(&notifyee->entry);
  1823. kfree(notifyee);
  1824. }
  1825. kmutex_unlock(&g_smscore_deviceslock);
  1826. kmutex_lock(&g_smscore_registrylock);
  1827. while (!list_empty(&g_smscore_registry)) {
  1828. struct smscore_registry_entry_t *entry =
  1829. (struct smscore_registry_entry_t *)
  1830. g_smscore_registry.next;
  1831. list_del(&entry->entry);
  1832. kfree(entry);
  1833. }
  1834. kmutex_unlock(&g_smscore_registrylock);
  1835. sms_debug("");
  1836. }
  1837. module_init(smscore_module_init);
  1838. module_exit(smscore_module_exit);
  1839. MODULE_DESCRIPTION("Siano MDTV Core module");
  1840. MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
  1841. MODULE_LICENSE("GPL");