smscoreapi.c 79 KB

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