smsdvb-main.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  1. /****************************************************************
  2. Siano Mobile Silicon, Inc.
  3. MDTV receiver kernel modules.
  4. Copyright (C) 2006-2008, Uri Shkolnik
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ****************************************************************/
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/init.h>
  19. #include "dmxdev.h"
  20. #include "dvbdev.h"
  21. #include "dvb_demux.h"
  22. #include "dvb_frontend.h"
  23. #include "smscoreapi.h"
  24. #include "sms-cards.h"
  25. #include "smsdvb.h"
  26. DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
  27. static struct list_head g_smsdvb_clients;
  28. static struct mutex g_smsdvb_clientslock;
  29. static int sms_dbg;
  30. module_param_named(debug, sms_dbg, int, 0644);
  31. MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))");
  32. u32 sms_to_guard_interval_table[] = {
  33. [0] = GUARD_INTERVAL_1_32,
  34. [1] = GUARD_INTERVAL_1_16,
  35. [2] = GUARD_INTERVAL_1_8,
  36. [3] = GUARD_INTERVAL_1_4,
  37. };
  38. u32 sms_to_code_rate_table[] = {
  39. [0] = FEC_1_2,
  40. [1] = FEC_2_3,
  41. [2] = FEC_3_4,
  42. [3] = FEC_5_6,
  43. [4] = FEC_7_8,
  44. };
  45. u32 sms_to_hierarchy_table[] = {
  46. [0] = HIERARCHY_NONE,
  47. [1] = HIERARCHY_1,
  48. [2] = HIERARCHY_2,
  49. [3] = HIERARCHY_4,
  50. };
  51. u32 sms_to_modulation_table[] = {
  52. [0] = QPSK,
  53. [1] = QAM_16,
  54. [2] = QAM_64,
  55. [3] = DQPSK,
  56. };
  57. /* Events that may come from DVB v3 adapter */
  58. static void sms_board_dvb3_event(struct smsdvb_client_t *client,
  59. enum SMS_DVB3_EVENTS event) {
  60. struct smscore_device_t *coredev = client->coredev;
  61. switch (event) {
  62. case DVB3_EVENT_INIT:
  63. sms_debug("DVB3_EVENT_INIT");
  64. sms_board_event(coredev, BOARD_EVENT_BIND);
  65. break;
  66. case DVB3_EVENT_SLEEP:
  67. sms_debug("DVB3_EVENT_SLEEP");
  68. sms_board_event(coredev, BOARD_EVENT_POWER_SUSPEND);
  69. break;
  70. case DVB3_EVENT_HOTPLUG:
  71. sms_debug("DVB3_EVENT_HOTPLUG");
  72. sms_board_event(coredev, BOARD_EVENT_POWER_INIT);
  73. break;
  74. case DVB3_EVENT_FE_LOCK:
  75. if (client->event_fe_state != DVB3_EVENT_FE_LOCK) {
  76. client->event_fe_state = DVB3_EVENT_FE_LOCK;
  77. sms_debug("DVB3_EVENT_FE_LOCK");
  78. sms_board_event(coredev, BOARD_EVENT_FE_LOCK);
  79. }
  80. break;
  81. case DVB3_EVENT_FE_UNLOCK:
  82. if (client->event_fe_state != DVB3_EVENT_FE_UNLOCK) {
  83. client->event_fe_state = DVB3_EVENT_FE_UNLOCK;
  84. sms_debug("DVB3_EVENT_FE_UNLOCK");
  85. sms_board_event(coredev, BOARD_EVENT_FE_UNLOCK);
  86. }
  87. break;
  88. case DVB3_EVENT_UNC_OK:
  89. if (client->event_unc_state != DVB3_EVENT_UNC_OK) {
  90. client->event_unc_state = DVB3_EVENT_UNC_OK;
  91. sms_debug("DVB3_EVENT_UNC_OK");
  92. sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_OK);
  93. }
  94. break;
  95. case DVB3_EVENT_UNC_ERR:
  96. if (client->event_unc_state != DVB3_EVENT_UNC_ERR) {
  97. client->event_unc_state = DVB3_EVENT_UNC_ERR;
  98. sms_debug("DVB3_EVENT_UNC_ERR");
  99. sms_board_event(coredev, BOARD_EVENT_MULTIPLEX_ERRORS);
  100. }
  101. break;
  102. default:
  103. sms_err("Unknown dvb3 api event");
  104. break;
  105. }
  106. }
  107. static void smsdvb_stats_not_ready(struct dvb_frontend *fe)
  108. {
  109. struct smsdvb_client_t *client =
  110. container_of(fe, struct smsdvb_client_t, frontend);
  111. struct smscore_device_t *coredev = client->coredev;
  112. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  113. int i, n_layers;
  114. switch (smscore_get_device_mode(coredev)) {
  115. case DEVICE_MODE_ISDBT:
  116. case DEVICE_MODE_ISDBT_BDA:
  117. n_layers = 4;
  118. default:
  119. n_layers = 1;
  120. }
  121. /* Global stats */
  122. c->strength.len = 1;
  123. c->cnr.len = 1;
  124. c->strength.stat[0].scale = FE_SCALE_DECIBEL;
  125. c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
  126. /* Per-layer stats */
  127. c->post_bit_error.len = n_layers;
  128. c->post_bit_count.len = n_layers;
  129. c->block_error.len = n_layers;
  130. c->block_count.len = n_layers;
  131. /*
  132. * Put all of them at FE_SCALE_NOT_AVAILABLE. They're dynamically
  133. * changed when the stats become available.
  134. */
  135. for (i = 0; i < n_layers; i++) {
  136. c->post_bit_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
  137. c->post_bit_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
  138. c->block_error.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
  139. c->block_count.stat[i].scale = FE_SCALE_NOT_AVAILABLE;
  140. }
  141. }
  142. static inline int sms_to_mode(u32 mode)
  143. {
  144. switch (mode) {
  145. case 2:
  146. return TRANSMISSION_MODE_2K;
  147. case 4:
  148. return TRANSMISSION_MODE_4K;
  149. case 8:
  150. return TRANSMISSION_MODE_8K;
  151. }
  152. return TRANSMISSION_MODE_AUTO;
  153. }
  154. static inline int sms_to_status(u32 is_demod_locked, u32 is_rf_locked)
  155. {
  156. if (is_demod_locked)
  157. return FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI |
  158. FE_HAS_SYNC | FE_HAS_LOCK;
  159. if (is_rf_locked)
  160. return FE_HAS_SIGNAL | FE_HAS_CARRIER;
  161. return 0;
  162. }
  163. static inline u32 sms_to_bw(u32 value)
  164. {
  165. return value * 1000000;
  166. }
  167. #define convert_from_table(value, table, defval) ({ \
  168. u32 __ret; \
  169. if (value < ARRAY_SIZE(table)) \
  170. __ret = table[value]; \
  171. else \
  172. __ret = defval; \
  173. __ret; \
  174. })
  175. #define sms_to_guard_interval(value) \
  176. convert_from_table(value, sms_to_guard_interval_table, \
  177. GUARD_INTERVAL_AUTO);
  178. #define sms_to_code_rate(value) \
  179. convert_from_table(value, sms_to_code_rate_table, \
  180. FEC_NONE);
  181. #define sms_to_hierarchy(value) \
  182. convert_from_table(value, sms_to_hierarchy_table, \
  183. FEC_NONE);
  184. #define sms_to_modulation(value) \
  185. convert_from_table(value, sms_to_modulation_table, \
  186. FEC_NONE);
  187. static void smsdvb_update_tx_params(struct smsdvb_client_t *client,
  188. struct TRANSMISSION_STATISTICS_S *p)
  189. {
  190. struct dvb_frontend *fe = &client->frontend;
  191. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  192. c->frequency = p->Frequency;
  193. client->fe_status = sms_to_status(p->IsDemodLocked, 0);
  194. c->bandwidth_hz = sms_to_bw(p->Bandwidth);
  195. c->transmission_mode = sms_to_mode(p->TransmissionMode);
  196. c->guard_interval = sms_to_guard_interval(p->GuardInterval);
  197. c->code_rate_HP = sms_to_code_rate(p->CodeRate);
  198. c->code_rate_LP = sms_to_code_rate(p->LPCodeRate);
  199. c->hierarchy = sms_to_hierarchy(p->Hierarchy);
  200. c->modulation = sms_to_modulation(p->Constellation);
  201. }
  202. static void smsdvb_update_per_slices(struct smsdvb_client_t *client,
  203. struct RECEPTION_STATISTICS_PER_SLICES_S *p)
  204. {
  205. struct dvb_frontend *fe = &client->frontend;
  206. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  207. client->fe_status = sms_to_status(p->IsDemodLocked, p->IsRfLocked);
  208. c->modulation = sms_to_modulation(p->constellation);
  209. /* Signal Strength, in DBm */
  210. c->strength.stat[0].uvalue = p->inBandPower * 1000;
  211. /* Carrier to Noise ratio, in DB */
  212. c->cnr.stat[0].svalue = p->snr * 1000;
  213. /* PER/BER requires demod lock */
  214. if (!p->IsDemodLocked)
  215. return;
  216. /* TS PER */
  217. client->last_per = c->block_error.stat[0].uvalue;
  218. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  219. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  220. c->block_error.stat[0].uvalue += p->etsPackets;
  221. c->block_count.stat[0].uvalue += p->etsPackets + p->tsPackets;
  222. /* BER */
  223. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  224. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  225. c->post_bit_error.stat[0].uvalue += p->BERErrorCount;
  226. c->post_bit_count.stat[0].uvalue += p->BERBitCount;
  227. /* Legacy PER/BER */
  228. client->legacy_per = (p->etsPackets * 65535) /
  229. (p->tsPackets + p->etsPackets);
  230. }
  231. static void smsdvb_update_dvb_stats(struct smsdvb_client_t *client,
  232. struct SMSHOSTLIB_STATISTICS_ST *p)
  233. {
  234. struct dvb_frontend *fe = &client->frontend;
  235. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  236. if (client->prt_dvb_stats)
  237. client->prt_dvb_stats(client->debug_data, p);
  238. client->fe_status = sms_to_status(p->IsDemodLocked, p->IsRfLocked);
  239. /* Update DVB modulation parameters */
  240. c->frequency = p->Frequency;
  241. client->fe_status = sms_to_status(p->IsDemodLocked, 0);
  242. c->bandwidth_hz = sms_to_bw(p->Bandwidth);
  243. c->transmission_mode = sms_to_mode(p->TransmissionMode);
  244. c->guard_interval = sms_to_guard_interval(p->GuardInterval);
  245. c->code_rate_HP = sms_to_code_rate(p->CodeRate);
  246. c->code_rate_LP = sms_to_code_rate(p->LPCodeRate);
  247. c->hierarchy = sms_to_hierarchy(p->Hierarchy);
  248. c->modulation = sms_to_modulation(p->Constellation);
  249. /* update reception data */
  250. c->lna = p->IsExternalLNAOn ? 1 : 0;
  251. /* Carrier to Noise ratio, in DB */
  252. c->cnr.stat[0].svalue = p->SNR * 1000;
  253. /* Signal Strength, in DBm */
  254. c->strength.stat[0].uvalue = p->InBandPwr * 1000;
  255. /* PER/BER requires demod lock */
  256. if (!p->IsDemodLocked)
  257. return;
  258. /* TS PER */
  259. client->last_per = c->block_error.stat[0].uvalue;
  260. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  261. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  262. c->block_error.stat[0].uvalue += p->ErrorTSPackets;
  263. c->block_count.stat[0].uvalue += p->TotalTSPackets;
  264. /* BER */
  265. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  266. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  267. c->post_bit_error.stat[0].uvalue += p->BERErrorCount;
  268. c->post_bit_count.stat[0].uvalue += p->BERBitCount;
  269. /* Legacy PER/BER */
  270. client->legacy_ber = p->BER;
  271. };
  272. static void smsdvb_update_isdbt_stats(struct smsdvb_client_t *client,
  273. struct SMSHOSTLIB_STATISTICS_ISDBT_ST *p)
  274. {
  275. struct dvb_frontend *fe = &client->frontend;
  276. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  277. struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST *lr;
  278. int i, n_layers;
  279. if (client->prt_isdb_stats)
  280. client->prt_isdb_stats(client->debug_data, p);
  281. client->fe_status = sms_to_status(p->IsDemodLocked, p->IsRfLocked);
  282. /*
  283. * Firmware 2.1 seems to report only lock status and
  284. * Signal strength. The signal strength indicator is at the
  285. * wrong field.
  286. */
  287. if (p->StatisticsType == 0) {
  288. c->strength.stat[0].uvalue = ((s32)p->TransmissionMode) * 1000;
  289. c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
  290. return;
  291. }
  292. /* Update ISDB-T transmission parameters */
  293. c->frequency = p->Frequency;
  294. c->bandwidth_hz = sms_to_bw(p->Bandwidth);
  295. c->transmission_mode = sms_to_mode(p->TransmissionMode);
  296. c->guard_interval = sms_to_guard_interval(p->GuardInterval);
  297. c->isdbt_partial_reception = p->PartialReception ? 1 : 0;
  298. n_layers = p->NumOfLayers;
  299. if (n_layers < 1)
  300. n_layers = 1;
  301. if (n_layers > 3)
  302. n_layers = 3;
  303. c->isdbt_layer_enabled = 0;
  304. /* update reception data */
  305. c->lna = p->IsExternalLNAOn ? 1 : 0;
  306. /* Carrier to Noise ratio, in DB */
  307. c->cnr.stat[0].svalue = p->SNR * 1000;
  308. /* Signal Strength, in DBm */
  309. c->strength.stat[0].uvalue = p->InBandPwr * 1000;
  310. /* PER/BER and per-layer stats require demod lock */
  311. if (!p->IsDemodLocked)
  312. return;
  313. client->last_per = c->block_error.stat[0].uvalue;
  314. /* Clears global counters, as the code below will sum it again */
  315. c->block_error.stat[0].uvalue = 0;
  316. c->block_count.stat[0].uvalue = 0;
  317. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  318. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  319. c->post_bit_error.stat[0].uvalue = 0;
  320. c->post_bit_count.stat[0].uvalue = 0;
  321. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  322. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  323. for (i = 0; i < n_layers; i++) {
  324. lr = &p->LayerInfo[i];
  325. /* Update per-layer transmission parameters */
  326. if (lr->NumberOfSegments > 0 && lr->NumberOfSegments < 13) {
  327. c->isdbt_layer_enabled |= 1 << i;
  328. c->layer[i].segment_count = lr->NumberOfSegments;
  329. } else {
  330. continue;
  331. }
  332. c->layer[i].modulation = sms_to_modulation(lr->Constellation);
  333. /* TS PER */
  334. c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  335. c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  336. c->block_error.stat[i + 1].uvalue += lr->ErrorTSPackets;
  337. c->block_count.stat[i + 1].uvalue += lr->TotalTSPackets;
  338. /* Update global PER counter */
  339. c->block_error.stat[0].uvalue += lr->ErrorTSPackets;
  340. c->block_count.stat[0].uvalue += lr->TotalTSPackets;
  341. /* BER */
  342. c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  343. c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  344. c->post_bit_error.stat[i + 1].uvalue += lr->BERErrorCount;
  345. c->post_bit_count.stat[i + 1].uvalue += lr->BERBitCount;
  346. /* Update global BER counter */
  347. c->post_bit_error.stat[0].uvalue += lr->BERErrorCount;
  348. c->post_bit_count.stat[0].uvalue += lr->BERBitCount;
  349. }
  350. }
  351. static void smsdvb_update_isdbt_stats_ex(struct smsdvb_client_t *client,
  352. struct SMSHOSTLIB_STATISTICS_ISDBT_EX_ST *p)
  353. {
  354. struct dvb_frontend *fe = &client->frontend;
  355. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  356. struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST *lr;
  357. int i, n_layers;
  358. if (client->prt_isdb_stats_ex)
  359. client->prt_isdb_stats_ex(client->debug_data, p);
  360. /* Update ISDB-T transmission parameters */
  361. c->frequency = p->Frequency;
  362. client->fe_status = sms_to_status(p->IsDemodLocked, 0);
  363. c->bandwidth_hz = sms_to_bw(p->Bandwidth);
  364. c->transmission_mode = sms_to_mode(p->TransmissionMode);
  365. c->guard_interval = sms_to_guard_interval(p->GuardInterval);
  366. c->isdbt_partial_reception = p->PartialReception ? 1 : 0;
  367. n_layers = p->NumOfLayers;
  368. if (n_layers < 1)
  369. n_layers = 1;
  370. if (n_layers > 3)
  371. n_layers = 3;
  372. c->isdbt_layer_enabled = 0;
  373. /* update reception data */
  374. c->lna = p->IsExternalLNAOn ? 1 : 0;
  375. /* Carrier to Noise ratio, in DB */
  376. c->cnr.stat[0].svalue = p->SNR * 1000;
  377. /* Signal Strength, in DBm */
  378. c->strength.stat[0].uvalue = p->InBandPwr * 1000;
  379. /* PER/BER and per-layer stats require demod lock */
  380. if (!p->IsDemodLocked)
  381. return;
  382. client->last_per = c->block_error.stat[0].uvalue;
  383. /* Clears global counters, as the code below will sum it again */
  384. c->block_error.stat[0].uvalue = 0;
  385. c->block_count.stat[0].uvalue = 0;
  386. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  387. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  388. c->post_bit_error.stat[0].uvalue = 0;
  389. c->post_bit_count.stat[0].uvalue = 0;
  390. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  391. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  392. c->post_bit_error.len = n_layers + 1;
  393. c->post_bit_count.len = n_layers + 1;
  394. c->block_error.len = n_layers + 1;
  395. c->block_count.len = n_layers + 1;
  396. for (i = 0; i < n_layers; i++) {
  397. lr = &p->LayerInfo[i];
  398. /* Update per-layer transmission parameters */
  399. if (lr->NumberOfSegments > 0 && lr->NumberOfSegments < 13) {
  400. c->isdbt_layer_enabled |= 1 << i;
  401. c->layer[i].segment_count = lr->NumberOfSegments;
  402. } else {
  403. continue;
  404. }
  405. c->layer[i].modulation = sms_to_modulation(lr->Constellation);
  406. /* TS PER */
  407. c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  408. c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  409. c->block_error.stat[i + 1].uvalue += lr->ErrorTSPackets;
  410. c->block_count.stat[i + 1].uvalue += lr->TotalTSPackets;
  411. /* Update global PER counter */
  412. c->block_error.stat[0].uvalue += lr->ErrorTSPackets;
  413. c->block_count.stat[0].uvalue += lr->TotalTSPackets;
  414. /* BER */
  415. c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  416. c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  417. c->post_bit_error.stat[i + 1].uvalue += lr->BERErrorCount;
  418. c->post_bit_count.stat[i + 1].uvalue += lr->BERBitCount;
  419. /* Update global BER counter */
  420. c->post_bit_error.stat[0].uvalue += lr->BERErrorCount;
  421. c->post_bit_count.stat[0].uvalue += lr->BERBitCount;
  422. }
  423. }
  424. static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
  425. {
  426. struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
  427. struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) (((u8 *) cb->p)
  428. + cb->offset);
  429. void *p = phdr + 1;
  430. struct dvb_frontend *fe = &client->frontend;
  431. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  432. bool is_status_update = false;
  433. switch (phdr->msgType) {
  434. case MSG_SMS_DVBT_BDA_DATA:
  435. /*
  436. * Only feed data to dvb demux if are there any feed listening
  437. * to it and if the device has tuned
  438. */
  439. if (client->feed_users && client->has_tuned)
  440. dvb_dmx_swfilter(&client->demux, p,
  441. cb->size - sizeof(struct SmsMsgHdr_ST));
  442. break;
  443. case MSG_SMS_RF_TUNE_RES:
  444. case MSG_SMS_ISDBT_TUNE_RES:
  445. complete(&client->tune_done);
  446. break;
  447. case MSG_SMS_SIGNAL_DETECTED_IND:
  448. client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
  449. FE_HAS_VITERBI | FE_HAS_SYNC |
  450. FE_HAS_LOCK;
  451. is_status_update = true;
  452. break;
  453. case MSG_SMS_NO_SIGNAL_IND:
  454. client->fe_status = 0;
  455. is_status_update = true;
  456. break;
  457. case MSG_SMS_TRANSMISSION_IND:
  458. smsdvb_update_tx_params(client, p);
  459. is_status_update = true;
  460. break;
  461. case MSG_SMS_HO_PER_SLICES_IND:
  462. smsdvb_update_per_slices(client, p);
  463. is_status_update = true;
  464. break;
  465. case MSG_SMS_GET_STATISTICS_RES:
  466. switch (smscore_get_device_mode(client->coredev)) {
  467. case DEVICE_MODE_ISDBT:
  468. case DEVICE_MODE_ISDBT_BDA:
  469. smsdvb_update_isdbt_stats(client, p);
  470. break;
  471. default:
  472. /* Skip SmsMsgStatisticsInfo_ST:RequestResult field */
  473. smsdvb_update_dvb_stats(client, p + sizeof(u32));
  474. }
  475. is_status_update = true;
  476. break;
  477. /* Only for ISDB-T */
  478. case MSG_SMS_GET_STATISTICS_EX_RES:
  479. /* Skip SmsMsgStatisticsInfo_ST:RequestResult field? */
  480. smsdvb_update_isdbt_stats_ex(client, p + sizeof(u32));
  481. is_status_update = true;
  482. break;
  483. default:
  484. sms_info("message not handled");
  485. }
  486. smscore_putbuffer(client->coredev, cb);
  487. if (is_status_update) {
  488. if (client->fe_status & FE_HAS_LOCK) {
  489. sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK);
  490. if (client->last_per == c->block_error.stat[0].uvalue)
  491. sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK);
  492. else
  493. sms_board_dvb3_event(client, DVB3_EVENT_UNC_ERR);
  494. client->has_tuned = true;
  495. } else {
  496. smsdvb_stats_not_ready(fe);
  497. client->has_tuned = false;
  498. sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK);
  499. }
  500. complete(&client->stats_done);
  501. }
  502. return 0;
  503. }
  504. static void smsdvb_unregister_client(struct smsdvb_client_t *client)
  505. {
  506. /* must be called under clientslock */
  507. list_del(&client->entry);
  508. smsdvb_debugfs_release(client);
  509. smscore_unregister_client(client->smsclient);
  510. dvb_unregister_frontend(&client->frontend);
  511. dvb_dmxdev_release(&client->dmxdev);
  512. dvb_dmx_release(&client->demux);
  513. dvb_unregister_adapter(&client->adapter);
  514. kfree(client);
  515. }
  516. static void smsdvb_onremove(void *context)
  517. {
  518. kmutex_lock(&g_smsdvb_clientslock);
  519. smsdvb_unregister_client((struct smsdvb_client_t *) context);
  520. kmutex_unlock(&g_smsdvb_clientslock);
  521. }
  522. static int smsdvb_start_feed(struct dvb_demux_feed *feed)
  523. {
  524. struct smsdvb_client_t *client =
  525. container_of(feed->demux, struct smsdvb_client_t, demux);
  526. struct SmsMsgData_ST PidMsg;
  527. sms_debug("add pid %d(%x)",
  528. feed->pid, feed->pid);
  529. client->feed_users++;
  530. PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  531. PidMsg.xMsgHeader.msgDstId = HIF_TASK;
  532. PidMsg.xMsgHeader.msgFlags = 0;
  533. PidMsg.xMsgHeader.msgType = MSG_SMS_ADD_PID_FILTER_REQ;
  534. PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
  535. PidMsg.msgData[0] = feed->pid;
  536. return smsclient_sendrequest(client->smsclient,
  537. &PidMsg, sizeof(PidMsg));
  538. }
  539. static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
  540. {
  541. struct smsdvb_client_t *client =
  542. container_of(feed->demux, struct smsdvb_client_t, demux);
  543. struct SmsMsgData_ST PidMsg;
  544. sms_debug("remove pid %d(%x)",
  545. feed->pid, feed->pid);
  546. client->feed_users--;
  547. PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  548. PidMsg.xMsgHeader.msgDstId = HIF_TASK;
  549. PidMsg.xMsgHeader.msgFlags = 0;
  550. PidMsg.xMsgHeader.msgType = MSG_SMS_REMOVE_PID_FILTER_REQ;
  551. PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
  552. PidMsg.msgData[0] = feed->pid;
  553. return smsclient_sendrequest(client->smsclient,
  554. &PidMsg, sizeof(PidMsg));
  555. }
  556. static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
  557. void *buffer, size_t size,
  558. struct completion *completion)
  559. {
  560. int rc;
  561. rc = smsclient_sendrequest(client->smsclient, buffer, size);
  562. if (rc < 0)
  563. return rc;
  564. return wait_for_completion_timeout(completion,
  565. msecs_to_jiffies(2000)) ?
  566. 0 : -ETIME;
  567. }
  568. static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
  569. {
  570. int rc;
  571. struct SmsMsgHdr_ST Msg;
  572. /* Don't request stats too fast */
  573. if (client->get_stats_jiffies &&
  574. (!time_after(jiffies, client->get_stats_jiffies)))
  575. return 0;
  576. client->get_stats_jiffies = jiffies + msecs_to_jiffies(100);
  577. Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  578. Msg.msgDstId = HIF_TASK;
  579. Msg.msgFlags = 0;
  580. Msg.msgLength = sizeof(Msg);
  581. switch (smscore_get_device_mode(client->coredev)) {
  582. case DEVICE_MODE_ISDBT:
  583. case DEVICE_MODE_ISDBT_BDA:
  584. /*
  585. * Check for firmware version, to avoid breaking for old cards
  586. */
  587. if (client->coredev->fw_version >= 0x800)
  588. Msg.msgType = MSG_SMS_GET_STATISTICS_EX_REQ;
  589. else
  590. Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;
  591. break;
  592. default:
  593. Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;
  594. }
  595. rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  596. &client->stats_done);
  597. return rc;
  598. }
  599. static inline int led_feedback(struct smsdvb_client_t *client)
  600. {
  601. if (!(client->fe_status & FE_HAS_LOCK))
  602. return sms_board_led_feedback(client->coredev, SMS_LED_OFF);
  603. return sms_board_led_feedback(client->coredev,
  604. (client->legacy_ber == 0) ?
  605. SMS_LED_HI : SMS_LED_LO);
  606. }
  607. static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat)
  608. {
  609. int rc;
  610. struct smsdvb_client_t *client;
  611. client = container_of(fe, struct smsdvb_client_t, frontend);
  612. rc = smsdvb_send_statistics_request(client);
  613. *stat = client->fe_status;
  614. led_feedback(client);
  615. return rc;
  616. }
  617. static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
  618. {
  619. int rc;
  620. struct smsdvb_client_t *client;
  621. client = container_of(fe, struct smsdvb_client_t, frontend);
  622. rc = smsdvb_send_statistics_request(client);
  623. *ber = client->legacy_ber;
  624. led_feedback(client);
  625. return rc;
  626. }
  627. static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  628. {
  629. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  630. int rc;
  631. s32 power = (s32) c->strength.stat[0].uvalue;
  632. struct smsdvb_client_t *client;
  633. client = container_of(fe, struct smsdvb_client_t, frontend);
  634. rc = smsdvb_send_statistics_request(client);
  635. if (power < -95)
  636. *strength = 0;
  637. else if (power > -29)
  638. *strength = 65535;
  639. else
  640. *strength = (power + 95) * 65535 / 66;
  641. led_feedback(client);
  642. return rc;
  643. }
  644. static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
  645. {
  646. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  647. int rc;
  648. struct smsdvb_client_t *client;
  649. client = container_of(fe, struct smsdvb_client_t, frontend);
  650. rc = smsdvb_send_statistics_request(client);
  651. /* Preferred scale for SNR with legacy API: 0.1 dB */
  652. *snr = c->cnr.stat[0].svalue / 100;
  653. led_feedback(client);
  654. return rc;
  655. }
  656. static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  657. {
  658. int rc;
  659. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  660. struct smsdvb_client_t *client;
  661. client = container_of(fe, struct smsdvb_client_t, frontend);
  662. rc = smsdvb_send_statistics_request(client);
  663. *ucblocks = c->block_error.stat[0].uvalue;
  664. led_feedback(client);
  665. return rc;
  666. }
  667. static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
  668. struct dvb_frontend_tune_settings *tune)
  669. {
  670. sms_debug("");
  671. tune->min_delay_ms = 400;
  672. tune->step_size = 250000;
  673. tune->max_drift = 0;
  674. return 0;
  675. }
  676. static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
  677. {
  678. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  679. struct smsdvb_client_t *client =
  680. container_of(fe, struct smsdvb_client_t, frontend);
  681. struct {
  682. struct SmsMsgHdr_ST Msg;
  683. u32 Data[3];
  684. } Msg;
  685. int ret;
  686. client->fe_status = 0;
  687. client->event_fe_state = -1;
  688. client->event_unc_state = -1;
  689. fe->dtv_property_cache.delivery_system = SYS_DVBT;
  690. Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  691. Msg.Msg.msgDstId = HIF_TASK;
  692. Msg.Msg.msgFlags = 0;
  693. Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ;
  694. Msg.Msg.msgLength = sizeof(Msg);
  695. Msg.Data[0] = c->frequency;
  696. Msg.Data[2] = 12000000;
  697. sms_info("%s: freq %d band %d", __func__, c->frequency,
  698. c->bandwidth_hz);
  699. switch (c->bandwidth_hz / 1000000) {
  700. case 8:
  701. Msg.Data[1] = BW_8_MHZ;
  702. break;
  703. case 7:
  704. Msg.Data[1] = BW_7_MHZ;
  705. break;
  706. case 6:
  707. Msg.Data[1] = BW_6_MHZ;
  708. break;
  709. case 0:
  710. return -EOPNOTSUPP;
  711. default:
  712. return -EINVAL;
  713. }
  714. /* Disable LNA, if any. An error is returned if no LNA is present */
  715. ret = sms_board_lna_control(client->coredev, 0);
  716. if (ret == 0) {
  717. fe_status_t status;
  718. /* tune with LNA off at first */
  719. ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  720. &client->tune_done);
  721. smsdvb_read_status(fe, &status);
  722. if (status & FE_HAS_LOCK)
  723. return ret;
  724. /* previous tune didn't lock - enable LNA and tune again */
  725. sms_board_lna_control(client->coredev, 1);
  726. }
  727. return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  728. &client->tune_done);
  729. }
  730. static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
  731. {
  732. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  733. struct smsdvb_client_t *client =
  734. container_of(fe, struct smsdvb_client_t, frontend);
  735. int board_id = smscore_get_board_id(client->coredev);
  736. struct sms_board *board = sms_get_board(board_id);
  737. enum sms_device_type_st type = board->type;
  738. int ret;
  739. struct {
  740. struct SmsMsgHdr_ST Msg;
  741. u32 Data[4];
  742. } Msg;
  743. fe->dtv_property_cache.delivery_system = SYS_ISDBT;
  744. Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  745. Msg.Msg.msgDstId = HIF_TASK;
  746. Msg.Msg.msgFlags = 0;
  747. Msg.Msg.msgType = MSG_SMS_ISDBT_TUNE_REQ;
  748. Msg.Msg.msgLength = sizeof(Msg);
  749. if (c->isdbt_sb_segment_idx == -1)
  750. c->isdbt_sb_segment_idx = 0;
  751. if (!c->isdbt_layer_enabled)
  752. c->isdbt_layer_enabled = 7;
  753. Msg.Data[0] = c->frequency;
  754. Msg.Data[1] = BW_ISDBT_1SEG;
  755. Msg.Data[2] = 12000000;
  756. Msg.Data[3] = c->isdbt_sb_segment_idx;
  757. if (c->isdbt_partial_reception) {
  758. if ((type == SMS_PELE || type == SMS_RIO) &&
  759. c->isdbt_sb_segment_count > 3)
  760. Msg.Data[1] = BW_ISDBT_13SEG;
  761. else if (c->isdbt_sb_segment_count > 1)
  762. Msg.Data[1] = BW_ISDBT_3SEG;
  763. } else if (type == SMS_PELE || type == SMS_RIO)
  764. Msg.Data[1] = BW_ISDBT_13SEG;
  765. c->bandwidth_hz = 6000000;
  766. sms_info("%s: freq %d segwidth %d segindex %d\n", __func__,
  767. c->frequency, c->isdbt_sb_segment_count,
  768. c->isdbt_sb_segment_idx);
  769. /* Disable LNA, if any. An error is returned if no LNA is present */
  770. ret = sms_board_lna_control(client->coredev, 0);
  771. if (ret == 0) {
  772. fe_status_t status;
  773. /* tune with LNA off at first */
  774. ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  775. &client->tune_done);
  776. smsdvb_read_status(fe, &status);
  777. if (status & FE_HAS_LOCK)
  778. return ret;
  779. /* previous tune didn't lock - enable LNA and tune again */
  780. sms_board_lna_control(client->coredev, 1);
  781. }
  782. return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  783. &client->tune_done);
  784. }
  785. static int smsdvb_set_frontend(struct dvb_frontend *fe)
  786. {
  787. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  788. struct smsdvb_client_t *client =
  789. container_of(fe, struct smsdvb_client_t, frontend);
  790. struct smscore_device_t *coredev = client->coredev;
  791. smsdvb_stats_not_ready(fe);
  792. c->strength.stat[0].uvalue = 0;
  793. c->cnr.stat[0].uvalue = 0;
  794. client->has_tuned = false;
  795. switch (smscore_get_device_mode(coredev)) {
  796. case DEVICE_MODE_DVBT:
  797. case DEVICE_MODE_DVBT_BDA:
  798. return smsdvb_dvbt_set_frontend(fe);
  799. case DEVICE_MODE_ISDBT:
  800. case DEVICE_MODE_ISDBT_BDA:
  801. return smsdvb_isdbt_set_frontend(fe);
  802. default:
  803. return -EINVAL;
  804. }
  805. }
  806. /* Nothing to do here, as stats are automatically updated */
  807. static int smsdvb_get_frontend(struct dvb_frontend *fe)
  808. {
  809. return 0;
  810. }
  811. static int smsdvb_init(struct dvb_frontend *fe)
  812. {
  813. struct smsdvb_client_t *client =
  814. container_of(fe, struct smsdvb_client_t, frontend);
  815. sms_board_power(client->coredev, 1);
  816. sms_board_dvb3_event(client, DVB3_EVENT_INIT);
  817. return 0;
  818. }
  819. static int smsdvb_sleep(struct dvb_frontend *fe)
  820. {
  821. struct smsdvb_client_t *client =
  822. container_of(fe, struct smsdvb_client_t, frontend);
  823. sms_board_led_feedback(client->coredev, SMS_LED_OFF);
  824. sms_board_power(client->coredev, 0);
  825. sms_board_dvb3_event(client, DVB3_EVENT_SLEEP);
  826. return 0;
  827. }
  828. static void smsdvb_release(struct dvb_frontend *fe)
  829. {
  830. /* do nothing */
  831. }
  832. static struct dvb_frontend_ops smsdvb_fe_ops = {
  833. .info = {
  834. .name = "Siano Mobile Digital MDTV Receiver",
  835. .frequency_min = 44250000,
  836. .frequency_max = 867250000,
  837. .frequency_stepsize = 250000,
  838. .caps = FE_CAN_INVERSION_AUTO |
  839. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  840. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  841. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
  842. FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
  843. FE_CAN_GUARD_INTERVAL_AUTO |
  844. FE_CAN_RECOVER |
  845. FE_CAN_HIERARCHY_AUTO,
  846. },
  847. .release = smsdvb_release,
  848. .set_frontend = smsdvb_set_frontend,
  849. .get_frontend = smsdvb_get_frontend,
  850. .get_tune_settings = smsdvb_get_tune_settings,
  851. .read_status = smsdvb_read_status,
  852. .read_ber = smsdvb_read_ber,
  853. .read_signal_strength = smsdvb_read_signal_strength,
  854. .read_snr = smsdvb_read_snr,
  855. .read_ucblocks = smsdvb_read_ucblocks,
  856. .init = smsdvb_init,
  857. .sleep = smsdvb_sleep,
  858. };
  859. static int smsdvb_hotplug(struct smscore_device_t *coredev,
  860. struct device *device, int arrival)
  861. {
  862. struct smsclient_params_t params;
  863. struct smsdvb_client_t *client;
  864. int rc;
  865. /* device removal handled by onremove callback */
  866. if (!arrival)
  867. return 0;
  868. client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
  869. if (!client) {
  870. sms_err("kmalloc() failed");
  871. return -ENOMEM;
  872. }
  873. /* register dvb adapter */
  874. rc = dvb_register_adapter(&client->adapter,
  875. sms_get_board(
  876. smscore_get_board_id(coredev))->name,
  877. THIS_MODULE, device, adapter_nr);
  878. if (rc < 0) {
  879. sms_err("dvb_register_adapter() failed %d", rc);
  880. goto adapter_error;
  881. }
  882. /* init dvb demux */
  883. client->demux.dmx.capabilities = DMX_TS_FILTERING;
  884. client->demux.filternum = 32; /* todo: nova ??? */
  885. client->demux.feednum = 32;
  886. client->demux.start_feed = smsdvb_start_feed;
  887. client->demux.stop_feed = smsdvb_stop_feed;
  888. rc = dvb_dmx_init(&client->demux);
  889. if (rc < 0) {
  890. sms_err("dvb_dmx_init failed %d", rc);
  891. goto dvbdmx_error;
  892. }
  893. /* init dmxdev */
  894. client->dmxdev.filternum = 32;
  895. client->dmxdev.demux = &client->demux.dmx;
  896. client->dmxdev.capabilities = 0;
  897. rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
  898. if (rc < 0) {
  899. sms_err("dvb_dmxdev_init failed %d", rc);
  900. goto dmxdev_error;
  901. }
  902. /* init and register frontend */
  903. memcpy(&client->frontend.ops, &smsdvb_fe_ops,
  904. sizeof(struct dvb_frontend_ops));
  905. switch (smscore_get_device_mode(coredev)) {
  906. case DEVICE_MODE_DVBT:
  907. case DEVICE_MODE_DVBT_BDA:
  908. client->frontend.ops.delsys[0] = SYS_DVBT;
  909. break;
  910. case DEVICE_MODE_ISDBT:
  911. case DEVICE_MODE_ISDBT_BDA:
  912. client->frontend.ops.delsys[0] = SYS_ISDBT;
  913. break;
  914. }
  915. rc = dvb_register_frontend(&client->adapter, &client->frontend);
  916. if (rc < 0) {
  917. sms_err("frontend registration failed %d", rc);
  918. goto frontend_error;
  919. }
  920. params.initial_id = 1;
  921. params.data_type = MSG_SMS_DVBT_BDA_DATA;
  922. params.onresponse_handler = smsdvb_onresponse;
  923. params.onremove_handler = smsdvb_onremove;
  924. params.context = client;
  925. rc = smscore_register_client(coredev, &params, &client->smsclient);
  926. if (rc < 0) {
  927. sms_err("smscore_register_client() failed %d", rc);
  928. goto client_error;
  929. }
  930. client->coredev = coredev;
  931. init_completion(&client->tune_done);
  932. init_completion(&client->stats_done);
  933. kmutex_lock(&g_smsdvb_clientslock);
  934. list_add(&client->entry, &g_smsdvb_clients);
  935. kmutex_unlock(&g_smsdvb_clientslock);
  936. client->event_fe_state = -1;
  937. client->event_unc_state = -1;
  938. sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG);
  939. sms_info("success");
  940. sms_board_setup(coredev);
  941. if (smsdvb_debugfs_create(client) < 0)
  942. sms_info("failed to create debugfs node");
  943. return 0;
  944. client_error:
  945. dvb_unregister_frontend(&client->frontend);
  946. frontend_error:
  947. dvb_dmxdev_release(&client->dmxdev);
  948. dmxdev_error:
  949. dvb_dmx_release(&client->demux);
  950. dvbdmx_error:
  951. dvb_unregister_adapter(&client->adapter);
  952. adapter_error:
  953. kfree(client);
  954. return rc;
  955. }
  956. static int __init smsdvb_module_init(void)
  957. {
  958. int rc;
  959. INIT_LIST_HEAD(&g_smsdvb_clients);
  960. kmutex_init(&g_smsdvb_clientslock);
  961. smsdvb_debugfs_register();
  962. rc = smscore_register_hotplug(smsdvb_hotplug);
  963. sms_debug("");
  964. return rc;
  965. }
  966. static void __exit smsdvb_module_exit(void)
  967. {
  968. smscore_unregister_hotplug(smsdvb_hotplug);
  969. kmutex_lock(&g_smsdvb_clientslock);
  970. while (!list_empty(&g_smsdvb_clients))
  971. smsdvb_unregister_client((struct smsdvb_client_t *)g_smsdvb_clients.next);
  972. smsdvb_debugfs_unregister();
  973. kmutex_unlock(&g_smsdvb_clientslock);
  974. }
  975. module_init(smsdvb_module_init);
  976. module_exit(smsdvb_module_exit);
  977. MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
  978. MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
  979. MODULE_LICENSE("GPL");