smscoreapi.c 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  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. * send init device request and wait for response
  1117. *
  1118. * @param coredev pointer to a coredev object returned by
  1119. * smscore_register_device
  1120. * @param mode requested mode of operation
  1121. *
  1122. * @return 0 on success, <0 on error.
  1123. */
  1124. int smscore_init_device(struct smscore_device_t *coredev, int mode)
  1125. {
  1126. void *buffer;
  1127. struct SmsMsgData_ST *msg;
  1128. int rc = 0;
  1129. buffer = kmalloc(sizeof(struct SmsMsgData_ST) +
  1130. SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
  1131. if (!buffer) {
  1132. sms_err("Could not allocate buffer for init device message.");
  1133. return -ENOMEM;
  1134. }
  1135. msg = (struct SmsMsgData_ST *)SMS_ALIGN_ADDRESS(buffer);
  1136. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ,
  1137. sizeof(struct SmsMsgData_ST));
  1138. msg->msgData[0] = mode;
  1139. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)msg);
  1140. rc = smscore_sendrequest_and_wait(coredev, msg,
  1141. msg->xMsgHeader. msgLength,
  1142. &coredev->init_device_done);
  1143. kfree(buffer);
  1144. return rc;
  1145. }
  1146. /**
  1147. * calls device handler to change mode of operation
  1148. * NOTE: stellar/usb may disconnect when changing mode
  1149. *
  1150. * @param coredev pointer to a coredev object returned by
  1151. * smscore_register_device
  1152. * @param mode requested mode of operation
  1153. *
  1154. * @return 0 on success, <0 on error.
  1155. */
  1156. int smscore_set_device_mode(struct smscore_device_t *coredev, int mode)
  1157. {
  1158. int rc = 0;
  1159. sms_debug("set device mode to %d", mode);
  1160. if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
  1161. if (mode < DEVICE_MODE_DVBT || mode >= DEVICE_MODE_RAW_TUNER) {
  1162. sms_err("invalid mode specified %d", mode);
  1163. return -EINVAL;
  1164. }
  1165. smscore_registry_setmode(coredev->devpath, mode);
  1166. if (!(coredev->device_flags & SMS_DEVICE_NOT_READY)) {
  1167. rc = smscore_detect_mode(coredev);
  1168. if (rc < 0) {
  1169. sms_err("mode detect failed %d", rc);
  1170. return rc;
  1171. }
  1172. }
  1173. if (coredev->mode == mode) {
  1174. sms_info("device mode %d already set", mode);
  1175. return 0;
  1176. }
  1177. if (!(coredev->modes_supported & (1 << mode))) {
  1178. rc = smscore_load_firmware_from_file(coredev,
  1179. mode, 0, NULL);
  1180. /*
  1181. * try again with the default firmware -
  1182. * get the fw filename from look-up table
  1183. */
  1184. if (rc < 0) {
  1185. sms_debug("error %d loading firmware, trying again with default firmware",
  1186. rc);
  1187. rc = smscore_load_firmware_from_file(coredev,
  1188. mode, 1,
  1189. NULL);
  1190. if (rc < 0) {
  1191. sms_debug("error %d loading firmware",
  1192. rc);
  1193. return rc;
  1194. }
  1195. }
  1196. if (rc >= 0)
  1197. sms_info("firmware download success");
  1198. } else {
  1199. sms_info("mode %d is already supported by running firmware",
  1200. mode);
  1201. }
  1202. if (coredev->fw_version >= 0x800) {
  1203. rc = smscore_init_device(coredev, mode);
  1204. if (rc < 0)
  1205. sms_err("device init failed, rc %d.", rc);
  1206. }
  1207. } else {
  1208. if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_MAX) {
  1209. sms_err("invalid mode specified %d", mode);
  1210. return -EINVAL;
  1211. }
  1212. smscore_registry_setmode(coredev->devpath, mode);
  1213. if (coredev->detectmode_handler)
  1214. coredev->detectmode_handler(coredev->context,
  1215. &coredev->mode);
  1216. if (coredev->mode != mode && coredev->setmode_handler)
  1217. rc = coredev->setmode_handler(coredev->context, mode);
  1218. }
  1219. if (rc >= 0) {
  1220. char *buffer;
  1221. coredev->mode = mode;
  1222. coredev->device_flags &= ~SMS_DEVICE_NOT_READY;
  1223. buffer = kmalloc(sizeof(struct SmsMsgData_ST) +
  1224. SMS_DMA_ALIGNMENT, GFP_KERNEL | GFP_DMA);
  1225. if (buffer) {
  1226. struct SmsMsgData_ST *msg = (struct SmsMsgData_ST *) SMS_ALIGN_ADDRESS(buffer);
  1227. SMS_INIT_MSG(&msg->xMsgHeader, MSG_SMS_INIT_DEVICE_REQ,
  1228. sizeof(struct SmsMsgData_ST));
  1229. msg->msgData[0] = mode;
  1230. rc = smscore_sendrequest_and_wait(
  1231. coredev, msg, msg->xMsgHeader.msgLength,
  1232. &coredev->init_device_done);
  1233. kfree(buffer);
  1234. }
  1235. }
  1236. if (rc < 0)
  1237. sms_err("return error code %d.", rc);
  1238. else
  1239. sms_debug("Success setting device mode.");
  1240. return rc;
  1241. }
  1242. /**
  1243. * calls device handler to get current mode of operation
  1244. *
  1245. * @param coredev pointer to a coredev object returned by
  1246. * smscore_register_device
  1247. *
  1248. * @return current mode
  1249. */
  1250. int smscore_get_device_mode(struct smscore_device_t *coredev)
  1251. {
  1252. return coredev->mode;
  1253. }
  1254. EXPORT_SYMBOL_GPL(smscore_get_device_mode);
  1255. /**
  1256. * find client by response id & type within the clients list.
  1257. * return client handle or NULL.
  1258. *
  1259. * @param coredev pointer to a coredev object returned by
  1260. * smscore_register_device
  1261. * @param data_type client data type (SMS_DONT_CARE for all types)
  1262. * @param id client id (SMS_DONT_CARE for all id)
  1263. *
  1264. */
  1265. static struct
  1266. smscore_client_t *smscore_find_client(struct smscore_device_t *coredev,
  1267. int data_type, int id)
  1268. {
  1269. struct list_head *first;
  1270. struct smscore_client_t *client;
  1271. unsigned long flags;
  1272. struct list_head *firstid;
  1273. struct smscore_idlist_t *client_id;
  1274. spin_lock_irqsave(&coredev->clientslock, flags);
  1275. first = &coredev->clients;
  1276. list_for_each_entry(client, first, entry) {
  1277. firstid = &client->idlist;
  1278. list_for_each_entry(client_id, firstid, entry) {
  1279. if ((client_id->id == id) &&
  1280. (client_id->data_type == data_type ||
  1281. (client_id->data_type == 0)))
  1282. goto found;
  1283. }
  1284. }
  1285. client = NULL;
  1286. found:
  1287. spin_unlock_irqrestore(&coredev->clientslock, flags);
  1288. return client;
  1289. }
  1290. /**
  1291. * find client by response id/type, call clients onresponse handler
  1292. * return buffer to pool on error
  1293. *
  1294. * @param coredev pointer to a coredev object returned by
  1295. * smscore_register_device
  1296. * @param cb pointer to response buffer descriptor
  1297. *
  1298. */
  1299. void smscore_onresponse(struct smscore_device_t *coredev,
  1300. struct smscore_buffer_t *cb) {
  1301. struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) ((u8 *) cb->p
  1302. + cb->offset);
  1303. struct smscore_client_t *client;
  1304. int rc = -EBUSY;
  1305. static unsigned long last_sample_time; /* = 0; */
  1306. static int data_total; /* = 0; */
  1307. unsigned long time_now = jiffies_to_msecs(jiffies);
  1308. if (!last_sample_time)
  1309. last_sample_time = time_now;
  1310. if (time_now - last_sample_time > 10000) {
  1311. sms_debug("\ndata rate %d bytes/secs",
  1312. (int)((data_total * 1000) /
  1313. (time_now - last_sample_time)));
  1314. last_sample_time = time_now;
  1315. data_total = 0;
  1316. }
  1317. data_total += cb->size;
  1318. /* Do we need to re-route? */
  1319. if ((phdr->msgType == MSG_SMS_HO_PER_SLICES_IND) ||
  1320. (phdr->msgType == MSG_SMS_TRANSMISSION_IND)) {
  1321. if (coredev->mode == DEVICE_MODE_DVBT_BDA)
  1322. phdr->msgDstId = DVBT_BDA_CONTROL_MSG_ID;
  1323. }
  1324. client = smscore_find_client(coredev, phdr->msgType, phdr->msgDstId);
  1325. /* If no client registered for type & id,
  1326. * check for control client where type is not registered */
  1327. if (client)
  1328. rc = client->onresponse_handler(client->context, cb);
  1329. if (rc < 0) {
  1330. smsendian_handle_rx_message((struct SmsMsgData_ST *)phdr);
  1331. switch (phdr->msgType) {
  1332. case MSG_SMS_ISDBT_TUNE_RES:
  1333. break;
  1334. case MSG_SMS_RF_TUNE_RES:
  1335. break;
  1336. case MSG_SMS_SIGNAL_DETECTED_IND:
  1337. break;
  1338. case MSG_SMS_NO_SIGNAL_IND:
  1339. break;
  1340. case MSG_SMS_SPI_INT_LINE_SET_RES:
  1341. break;
  1342. case MSG_SMS_INTERFACE_LOCK_IND:
  1343. break;
  1344. case MSG_SMS_INTERFACE_UNLOCK_IND:
  1345. break;
  1346. case MSG_SMS_GET_VERSION_EX_RES:
  1347. {
  1348. struct SmsVersionRes_ST *ver =
  1349. (struct SmsVersionRes_ST *) phdr;
  1350. sms_debug("Firmware id %d prots 0x%x ver %d.%d",
  1351. ver->FirmwareId, ver->SupportedProtocols,
  1352. ver->RomVersionMajor, ver->RomVersionMinor);
  1353. coredev->mode = ver->FirmwareId == 255 ?
  1354. DEVICE_MODE_NONE : ver->FirmwareId;
  1355. coredev->modes_supported = ver->SupportedProtocols;
  1356. coredev->fw_version = ver->RomVersionMajor << 8 |
  1357. ver->RomVersionMinor;
  1358. complete(&coredev->version_ex_done);
  1359. break;
  1360. }
  1361. case MSG_SMS_INIT_DEVICE_RES:
  1362. complete(&coredev->init_device_done);
  1363. break;
  1364. case MSG_SW_RELOAD_START_RES:
  1365. complete(&coredev->reload_start_done);
  1366. break;
  1367. case MSG_SMS_DATA_VALIDITY_RES:
  1368. {
  1369. struct SmsMsgData_ST *validity = (struct SmsMsgData_ST *) phdr;
  1370. sms_err("MSG_SMS_DATA_VALIDITY_RES, checksum = 0x%x",
  1371. validity->msgData[0]);
  1372. complete(&coredev->data_validity_done);
  1373. break;
  1374. }
  1375. case MSG_SMS_DATA_DOWNLOAD_RES:
  1376. complete(&coredev->data_download_done);
  1377. break;
  1378. case MSG_SW_RELOAD_EXEC_RES:
  1379. break;
  1380. case MSG_SMS_SWDOWNLOAD_TRIGGER_RES:
  1381. complete(&coredev->trigger_done);
  1382. break;
  1383. case MSG_SMS_SLEEP_RESUME_COMP_IND:
  1384. complete(&coredev->resume_done);
  1385. break;
  1386. case MSG_SMS_GPIO_CONFIG_EX_RES:
  1387. complete(&coredev->gpio_configuration_done);
  1388. break;
  1389. case MSG_SMS_GPIO_SET_LEVEL_RES:
  1390. complete(&coredev->gpio_set_level_done);
  1391. break;
  1392. case MSG_SMS_GPIO_GET_LEVEL_RES:
  1393. {
  1394. u32 *msgdata = (u32 *) phdr;
  1395. coredev->gpio_get_res = msgdata[1];
  1396. sms_debug("gpio level %d",
  1397. coredev->gpio_get_res);
  1398. complete(&coredev->gpio_get_level_done);
  1399. break;
  1400. }
  1401. case MSG_SMS_START_IR_RES:
  1402. complete(&coredev->ir_init_done);
  1403. break;
  1404. case MSG_SMS_IR_SAMPLES_IND:
  1405. sms_ir_event(coredev,
  1406. (const char *)
  1407. ((char *)phdr
  1408. + sizeof(struct SmsMsgHdr_ST)),
  1409. (int)phdr->msgLength
  1410. - sizeof(struct SmsMsgHdr_ST));
  1411. break;
  1412. default:
  1413. sms_debug("message not handled.\n");
  1414. break;
  1415. }
  1416. smscore_putbuffer(coredev, cb);
  1417. }
  1418. }
  1419. EXPORT_SYMBOL_GPL(smscore_onresponse);
  1420. /**
  1421. * return pointer to next free buffer descriptor from core pool
  1422. *
  1423. * @param coredev pointer to a coredev object returned by
  1424. * smscore_register_device
  1425. *
  1426. * @return pointer to descriptor on success, NULL on error.
  1427. */
  1428. static struct smscore_buffer_t *get_entry(struct smscore_device_t *coredev)
  1429. {
  1430. struct smscore_buffer_t *cb = NULL;
  1431. unsigned long flags;
  1432. spin_lock_irqsave(&coredev->bufferslock, flags);
  1433. if (!list_empty(&coredev->buffers)) {
  1434. cb = (struct smscore_buffer_t *) coredev->buffers.next;
  1435. list_del(&cb->entry);
  1436. }
  1437. spin_unlock_irqrestore(&coredev->bufferslock, flags);
  1438. return cb;
  1439. }
  1440. struct smscore_buffer_t *smscore_getbuffer(struct smscore_device_t *coredev)
  1441. {
  1442. struct smscore_buffer_t *cb = NULL;
  1443. wait_event(coredev->buffer_mng_waitq, (cb = get_entry(coredev)));
  1444. return cb;
  1445. }
  1446. EXPORT_SYMBOL_GPL(smscore_getbuffer);
  1447. /**
  1448. * return buffer descriptor to a pool
  1449. *
  1450. * @param coredev pointer to a coredev object returned by
  1451. * smscore_register_device
  1452. * @param cb pointer buffer descriptor
  1453. *
  1454. */
  1455. void smscore_putbuffer(struct smscore_device_t *coredev,
  1456. struct smscore_buffer_t *cb) {
  1457. wake_up_interruptible(&coredev->buffer_mng_waitq);
  1458. list_add_locked(&cb->entry, &coredev->buffers, &coredev->bufferslock);
  1459. }
  1460. EXPORT_SYMBOL_GPL(smscore_putbuffer);
  1461. static int smscore_validate_client(struct smscore_device_t *coredev,
  1462. struct smscore_client_t *client,
  1463. int data_type, int id)
  1464. {
  1465. struct smscore_idlist_t *listentry;
  1466. struct smscore_client_t *registered_client;
  1467. if (!client) {
  1468. sms_err("bad parameter.");
  1469. return -EINVAL;
  1470. }
  1471. registered_client = smscore_find_client(coredev, data_type, id);
  1472. if (registered_client == client)
  1473. return 0;
  1474. if (registered_client) {
  1475. sms_err("The msg ID already registered to another client.");
  1476. return -EEXIST;
  1477. }
  1478. listentry = kzalloc(sizeof(struct smscore_idlist_t), GFP_KERNEL);
  1479. if (!listentry) {
  1480. sms_err("Can't allocate memory for client id.");
  1481. return -ENOMEM;
  1482. }
  1483. listentry->id = id;
  1484. listentry->data_type = data_type;
  1485. list_add_locked(&listentry->entry, &client->idlist,
  1486. &coredev->clientslock);
  1487. return 0;
  1488. }
  1489. /**
  1490. * creates smsclient object, check that id is taken by another client
  1491. *
  1492. * @param coredev pointer to a coredev object from clients hotplug
  1493. * @param initial_id all messages with this id would be sent to this client
  1494. * @param data_type all messages of this type would be sent to this client
  1495. * @param onresponse_handler client handler that is called to
  1496. * process incoming messages
  1497. * @param onremove_handler client handler that is called when device is removed
  1498. * @param context client-specific context
  1499. * @param client pointer to a value that receives created smsclient object
  1500. *
  1501. * @return 0 on success, <0 on error.
  1502. */
  1503. int smscore_register_client(struct smscore_device_t *coredev,
  1504. struct smsclient_params_t *params,
  1505. struct smscore_client_t **client)
  1506. {
  1507. struct smscore_client_t *newclient;
  1508. /* check that no other channel with same parameters exists */
  1509. if (smscore_find_client(coredev, params->data_type,
  1510. params->initial_id)) {
  1511. sms_err("Client already exist.");
  1512. return -EEXIST;
  1513. }
  1514. newclient = kzalloc(sizeof(struct smscore_client_t), GFP_KERNEL);
  1515. if (!newclient) {
  1516. sms_err("Failed to allocate memory for client.");
  1517. return -ENOMEM;
  1518. }
  1519. INIT_LIST_HEAD(&newclient->idlist);
  1520. newclient->coredev = coredev;
  1521. newclient->onresponse_handler = params->onresponse_handler;
  1522. newclient->onremove_handler = params->onremove_handler;
  1523. newclient->context = params->context;
  1524. list_add_locked(&newclient->entry, &coredev->clients,
  1525. &coredev->clientslock);
  1526. smscore_validate_client(coredev, newclient, params->data_type,
  1527. params->initial_id);
  1528. *client = newclient;
  1529. sms_debug("%p %d %d", params->context, params->data_type,
  1530. params->initial_id);
  1531. return 0;
  1532. }
  1533. EXPORT_SYMBOL_GPL(smscore_register_client);
  1534. /**
  1535. * frees smsclient object and all subclients associated with it
  1536. *
  1537. * @param client pointer to smsclient object returned by
  1538. * smscore_register_client
  1539. *
  1540. */
  1541. void smscore_unregister_client(struct smscore_client_t *client)
  1542. {
  1543. struct smscore_device_t *coredev = client->coredev;
  1544. unsigned long flags;
  1545. spin_lock_irqsave(&coredev->clientslock, flags);
  1546. while (!list_empty(&client->idlist)) {
  1547. struct smscore_idlist_t *identry =
  1548. (struct smscore_idlist_t *) client->idlist.next;
  1549. list_del(&identry->entry);
  1550. kfree(identry);
  1551. }
  1552. sms_info("%p", client->context);
  1553. list_del(&client->entry);
  1554. kfree(client);
  1555. spin_unlock_irqrestore(&coredev->clientslock, flags);
  1556. }
  1557. EXPORT_SYMBOL_GPL(smscore_unregister_client);
  1558. /**
  1559. * verifies that source id is not taken by another client,
  1560. * calls device handler to send requests to the device
  1561. *
  1562. * @param client pointer to smsclient object returned by
  1563. * smscore_register_client
  1564. * @param buffer pointer to a request buffer
  1565. * @param size size (in bytes) of request buffer
  1566. *
  1567. * @return 0 on success, <0 on error.
  1568. */
  1569. int smsclient_sendrequest(struct smscore_client_t *client,
  1570. void *buffer, size_t size)
  1571. {
  1572. struct smscore_device_t *coredev;
  1573. struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer;
  1574. int rc;
  1575. if (client == NULL) {
  1576. sms_err("Got NULL client");
  1577. return -EINVAL;
  1578. }
  1579. coredev = client->coredev;
  1580. /* check that no other channel with same id exists */
  1581. if (coredev == NULL) {
  1582. sms_err("Got NULL coredev");
  1583. return -EINVAL;
  1584. }
  1585. rc = smscore_validate_client(client->coredev, client, 0,
  1586. phdr->msgSrcId);
  1587. if (rc < 0)
  1588. return rc;
  1589. return coredev->sendrequest_handler(coredev->context, buffer, size);
  1590. }
  1591. EXPORT_SYMBOL_GPL(smsclient_sendrequest);
  1592. /* old GPIO managements implementation */
  1593. int smscore_configure_gpio(struct smscore_device_t *coredev, u32 pin,
  1594. struct smscore_config_gpio *pinconfig)
  1595. {
  1596. struct {
  1597. struct SmsMsgHdr_ST hdr;
  1598. u32 data[6];
  1599. } msg;
  1600. if (coredev->device_flags & SMS_DEVICE_FAMILY2) {
  1601. msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1602. msg.hdr.msgDstId = HIF_TASK;
  1603. msg.hdr.msgFlags = 0;
  1604. msg.hdr.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ;
  1605. msg.hdr.msgLength = sizeof(msg);
  1606. msg.data[0] = pin;
  1607. msg.data[1] = pinconfig->pullupdown;
  1608. /* Convert slew rate for Nova: Fast(0) = 3 / Slow(1) = 0; */
  1609. msg.data[2] = pinconfig->outputslewrate == 0 ? 3 : 0;
  1610. switch (pinconfig->outputdriving) {
  1611. case SMS_GPIO_OUTPUTDRIVING_S_16mA:
  1612. msg.data[3] = 7; /* Nova - 16mA */
  1613. break;
  1614. case SMS_GPIO_OUTPUTDRIVING_S_12mA:
  1615. msg.data[3] = 5; /* Nova - 11mA */
  1616. break;
  1617. case SMS_GPIO_OUTPUTDRIVING_S_8mA:
  1618. msg.data[3] = 3; /* Nova - 7mA */
  1619. break;
  1620. case SMS_GPIO_OUTPUTDRIVING_S_4mA:
  1621. default:
  1622. msg.data[3] = 2; /* Nova - 4mA */
  1623. break;
  1624. }
  1625. msg.data[4] = pinconfig->direction;
  1626. msg.data[5] = 0;
  1627. } else /* TODO: SMS_DEVICE_FAMILY1 */
  1628. return -EINVAL;
  1629. return coredev->sendrequest_handler(coredev->context,
  1630. &msg, sizeof(msg));
  1631. }
  1632. int smscore_set_gpio(struct smscore_device_t *coredev, u32 pin, int level)
  1633. {
  1634. struct {
  1635. struct SmsMsgHdr_ST hdr;
  1636. u32 data[3];
  1637. } msg;
  1638. if (pin > MAX_GPIO_PIN_NUMBER)
  1639. return -EINVAL;
  1640. msg.hdr.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1641. msg.hdr.msgDstId = HIF_TASK;
  1642. msg.hdr.msgFlags = 0;
  1643. msg.hdr.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ;
  1644. msg.hdr.msgLength = sizeof(msg);
  1645. msg.data[0] = pin;
  1646. msg.data[1] = level ? 1 : 0;
  1647. msg.data[2] = 0;
  1648. return coredev->sendrequest_handler(coredev->context,
  1649. &msg, sizeof(msg));
  1650. }
  1651. /* new GPIO management implementation */
  1652. static int GetGpioPinParams(u32 PinNum, u32 *pTranslatedPinNum,
  1653. u32 *pGroupNum, u32 *pGroupCfg) {
  1654. *pGroupCfg = 1;
  1655. if (PinNum <= 1) {
  1656. *pTranslatedPinNum = 0;
  1657. *pGroupNum = 9;
  1658. *pGroupCfg = 2;
  1659. } else if (PinNum >= 2 && PinNum <= 6) {
  1660. *pTranslatedPinNum = 2;
  1661. *pGroupNum = 0;
  1662. *pGroupCfg = 2;
  1663. } else if (PinNum >= 7 && PinNum <= 11) {
  1664. *pTranslatedPinNum = 7;
  1665. *pGroupNum = 1;
  1666. } else if (PinNum >= 12 && PinNum <= 15) {
  1667. *pTranslatedPinNum = 12;
  1668. *pGroupNum = 2;
  1669. *pGroupCfg = 3;
  1670. } else if (PinNum == 16) {
  1671. *pTranslatedPinNum = 16;
  1672. *pGroupNum = 23;
  1673. } else if (PinNum >= 17 && PinNum <= 24) {
  1674. *pTranslatedPinNum = 17;
  1675. *pGroupNum = 3;
  1676. } else if (PinNum == 25) {
  1677. *pTranslatedPinNum = 25;
  1678. *pGroupNum = 6;
  1679. } else if (PinNum >= 26 && PinNum <= 28) {
  1680. *pTranslatedPinNum = 26;
  1681. *pGroupNum = 4;
  1682. } else if (PinNum == 29) {
  1683. *pTranslatedPinNum = 29;
  1684. *pGroupNum = 5;
  1685. *pGroupCfg = 2;
  1686. } else if (PinNum == 30) {
  1687. *pTranslatedPinNum = 30;
  1688. *pGroupNum = 8;
  1689. } else if (PinNum == 31) {
  1690. *pTranslatedPinNum = 31;
  1691. *pGroupNum = 17;
  1692. } else
  1693. return -1;
  1694. *pGroupCfg <<= 24;
  1695. return 0;
  1696. }
  1697. int smscore_gpio_configure(struct smscore_device_t *coredev, u8 PinNum,
  1698. struct smscore_config_gpio *pGpioConfig) {
  1699. u32 totalLen;
  1700. u32 TranslatedPinNum = 0;
  1701. u32 GroupNum = 0;
  1702. u32 ElectricChar;
  1703. u32 groupCfg;
  1704. void *buffer;
  1705. int rc;
  1706. struct SetGpioMsg {
  1707. struct SmsMsgHdr_ST xMsgHeader;
  1708. u32 msgData[6];
  1709. } *pMsg;
  1710. if (PinNum > MAX_GPIO_PIN_NUMBER)
  1711. return -EINVAL;
  1712. if (pGpioConfig == NULL)
  1713. return -EINVAL;
  1714. totalLen = sizeof(struct SmsMsgHdr_ST) + (sizeof(u32) * 6);
  1715. buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
  1716. GFP_KERNEL | GFP_DMA);
  1717. if (!buffer)
  1718. return -ENOMEM;
  1719. pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
  1720. pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1721. pMsg->xMsgHeader.msgDstId = HIF_TASK;
  1722. pMsg->xMsgHeader.msgFlags = 0;
  1723. pMsg->xMsgHeader.msgLength = (u16) totalLen;
  1724. pMsg->msgData[0] = PinNum;
  1725. if (!(coredev->device_flags & SMS_DEVICE_FAMILY2)) {
  1726. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_REQ;
  1727. if (GetGpioPinParams(PinNum, &TranslatedPinNum, &GroupNum,
  1728. &groupCfg) != 0) {
  1729. rc = -EINVAL;
  1730. goto free;
  1731. }
  1732. pMsg->msgData[1] = TranslatedPinNum;
  1733. pMsg->msgData[2] = GroupNum;
  1734. ElectricChar = (pGpioConfig->pullupdown)
  1735. | (pGpioConfig->inputcharacteristics << 2)
  1736. | (pGpioConfig->outputslewrate << 3)
  1737. | (pGpioConfig->outputdriving << 4);
  1738. pMsg->msgData[3] = ElectricChar;
  1739. pMsg->msgData[4] = pGpioConfig->direction;
  1740. pMsg->msgData[5] = groupCfg;
  1741. } else {
  1742. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_CONFIG_EX_REQ;
  1743. pMsg->msgData[1] = pGpioConfig->pullupdown;
  1744. pMsg->msgData[2] = pGpioConfig->outputslewrate;
  1745. pMsg->msgData[3] = pGpioConfig->outputdriving;
  1746. pMsg->msgData[4] = pGpioConfig->direction;
  1747. pMsg->msgData[5] = 0;
  1748. }
  1749. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
  1750. rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
  1751. &coredev->gpio_configuration_done);
  1752. if (rc != 0) {
  1753. if (rc == -ETIME)
  1754. sms_err("smscore_gpio_configure timeout");
  1755. else
  1756. sms_err("smscore_gpio_configure error");
  1757. }
  1758. free:
  1759. kfree(buffer);
  1760. return rc;
  1761. }
  1762. int smscore_gpio_set_level(struct smscore_device_t *coredev, u8 PinNum,
  1763. u8 NewLevel) {
  1764. u32 totalLen;
  1765. int rc;
  1766. void *buffer;
  1767. struct SetGpioMsg {
  1768. struct SmsMsgHdr_ST xMsgHeader;
  1769. u32 msgData[3]; /* keep it 3 ! */
  1770. } *pMsg;
  1771. if ((NewLevel > 1) || (PinNum > MAX_GPIO_PIN_NUMBER))
  1772. return -EINVAL;
  1773. totalLen = sizeof(struct SmsMsgHdr_ST) +
  1774. (3 * sizeof(u32)); /* keep it 3 ! */
  1775. buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
  1776. GFP_KERNEL | GFP_DMA);
  1777. if (!buffer)
  1778. return -ENOMEM;
  1779. pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
  1780. pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1781. pMsg->xMsgHeader.msgDstId = HIF_TASK;
  1782. pMsg->xMsgHeader.msgFlags = 0;
  1783. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_SET_LEVEL_REQ;
  1784. pMsg->xMsgHeader.msgLength = (u16) totalLen;
  1785. pMsg->msgData[0] = PinNum;
  1786. pMsg->msgData[1] = NewLevel;
  1787. /* Send message to SMS */
  1788. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
  1789. rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
  1790. &coredev->gpio_set_level_done);
  1791. if (rc != 0) {
  1792. if (rc == -ETIME)
  1793. sms_err("smscore_gpio_set_level timeout");
  1794. else
  1795. sms_err("smscore_gpio_set_level error");
  1796. }
  1797. kfree(buffer);
  1798. return rc;
  1799. }
  1800. int smscore_gpio_get_level(struct smscore_device_t *coredev, u8 PinNum,
  1801. u8 *level) {
  1802. u32 totalLen;
  1803. int rc;
  1804. void *buffer;
  1805. struct SetGpioMsg {
  1806. struct SmsMsgHdr_ST xMsgHeader;
  1807. u32 msgData[2];
  1808. } *pMsg;
  1809. if (PinNum > MAX_GPIO_PIN_NUMBER)
  1810. return -EINVAL;
  1811. totalLen = sizeof(struct SmsMsgHdr_ST) + (2 * sizeof(u32));
  1812. buffer = kmalloc(totalLen + SMS_DMA_ALIGNMENT,
  1813. GFP_KERNEL | GFP_DMA);
  1814. if (!buffer)
  1815. return -ENOMEM;
  1816. pMsg = (struct SetGpioMsg *) SMS_ALIGN_ADDRESS(buffer);
  1817. pMsg->xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  1818. pMsg->xMsgHeader.msgDstId = HIF_TASK;
  1819. pMsg->xMsgHeader.msgFlags = 0;
  1820. pMsg->xMsgHeader.msgType = MSG_SMS_GPIO_GET_LEVEL_REQ;
  1821. pMsg->xMsgHeader.msgLength = (u16) totalLen;
  1822. pMsg->msgData[0] = PinNum;
  1823. pMsg->msgData[1] = 0;
  1824. /* Send message to SMS */
  1825. smsendian_handle_tx_message((struct SmsMsgHdr_ST *)pMsg);
  1826. rc = smscore_sendrequest_and_wait(coredev, pMsg, totalLen,
  1827. &coredev->gpio_get_level_done);
  1828. if (rc != 0) {
  1829. if (rc == -ETIME)
  1830. sms_err("smscore_gpio_get_level timeout");
  1831. else
  1832. sms_err("smscore_gpio_get_level error");
  1833. }
  1834. kfree(buffer);
  1835. /* Its a race between other gpio_get_level() and the copy of the single
  1836. * global 'coredev->gpio_get_res' to the function's variable 'level'
  1837. */
  1838. *level = coredev->gpio_get_res;
  1839. return rc;
  1840. }
  1841. static int __init smscore_module_init(void)
  1842. {
  1843. int rc = 0;
  1844. INIT_LIST_HEAD(&g_smscore_notifyees);
  1845. INIT_LIST_HEAD(&g_smscore_devices);
  1846. kmutex_init(&g_smscore_deviceslock);
  1847. INIT_LIST_HEAD(&g_smscore_registry);
  1848. kmutex_init(&g_smscore_registrylock);
  1849. return rc;
  1850. }
  1851. static void __exit smscore_module_exit(void)
  1852. {
  1853. kmutex_lock(&g_smscore_deviceslock);
  1854. while (!list_empty(&g_smscore_notifyees)) {
  1855. struct smscore_device_notifyee_t *notifyee =
  1856. (struct smscore_device_notifyee_t *)
  1857. g_smscore_notifyees.next;
  1858. list_del(&notifyee->entry);
  1859. kfree(notifyee);
  1860. }
  1861. kmutex_unlock(&g_smscore_deviceslock);
  1862. kmutex_lock(&g_smscore_registrylock);
  1863. while (!list_empty(&g_smscore_registry)) {
  1864. struct smscore_registry_entry_t *entry =
  1865. (struct smscore_registry_entry_t *)
  1866. g_smscore_registry.next;
  1867. list_del(&entry->entry);
  1868. kfree(entry);
  1869. }
  1870. kmutex_unlock(&g_smscore_registrylock);
  1871. sms_debug("");
  1872. }
  1873. module_init(smscore_module_init);
  1874. module_exit(smscore_module_exit);
  1875. MODULE_DESCRIPTION("Siano MDTV Core module");
  1876. MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
  1877. MODULE_LICENSE("GPL");