smsdvb-main.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  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. /* Update ISDB-T transmission parameters */
  282. c->frequency = p->Frequency;
  283. client->fe_status = sms_to_status(p->IsDemodLocked, 0);
  284. c->bandwidth_hz = sms_to_bw(p->Bandwidth);
  285. c->transmission_mode = sms_to_mode(p->TransmissionMode);
  286. c->guard_interval = sms_to_guard_interval(p->GuardInterval);
  287. c->isdbt_partial_reception = p->PartialReception ? 1 : 0;
  288. n_layers = p->NumOfLayers;
  289. if (n_layers < 1)
  290. n_layers = 1;
  291. if (n_layers > 3)
  292. n_layers = 3;
  293. c->isdbt_layer_enabled = 0;
  294. /* update reception data */
  295. c->lna = p->IsExternalLNAOn ? 1 : 0;
  296. /* Carrier to Noise ratio, in DB */
  297. c->cnr.stat[0].svalue = p->SNR * 1000;
  298. /* Signal Strength, in DBm */
  299. c->strength.stat[0].uvalue = p->InBandPwr * 1000;
  300. /* PER/BER and per-layer stats require demod lock */
  301. if (!p->IsDemodLocked)
  302. return;
  303. client->last_per = c->block_error.stat[0].uvalue;
  304. /* Clears global counters, as the code below will sum it again */
  305. c->block_error.stat[0].uvalue = 0;
  306. c->block_count.stat[0].uvalue = 0;
  307. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  308. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  309. c->post_bit_error.stat[0].uvalue = 0;
  310. c->post_bit_count.stat[0].uvalue = 0;
  311. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  312. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  313. for (i = 0; i < n_layers; i++) {
  314. lr = &p->LayerInfo[i];
  315. /* Update per-layer transmission parameters */
  316. if (lr->NumberOfSegments > 0 && lr->NumberOfSegments < 13) {
  317. c->isdbt_layer_enabled |= 1 << i;
  318. c->layer[i].segment_count = lr->NumberOfSegments;
  319. } else {
  320. continue;
  321. }
  322. c->layer[i].modulation = sms_to_modulation(lr->Constellation);
  323. /* TS PER */
  324. c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  325. c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  326. c->block_error.stat[i + 1].uvalue += lr->ErrorTSPackets;
  327. c->block_count.stat[i + 1].uvalue += lr->TotalTSPackets;
  328. /* Update global PER counter */
  329. c->block_error.stat[0].uvalue += lr->ErrorTSPackets;
  330. c->block_count.stat[0].uvalue += lr->TotalTSPackets;
  331. /* BER */
  332. c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  333. c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  334. c->post_bit_error.stat[i + 1].uvalue += lr->BERErrorCount;
  335. c->post_bit_count.stat[i + 1].uvalue += lr->BERBitCount;
  336. /* Update global BER counter */
  337. c->post_bit_error.stat[0].uvalue += lr->BERErrorCount;
  338. c->post_bit_count.stat[0].uvalue += lr->BERBitCount;
  339. }
  340. }
  341. static void smsdvb_update_isdbt_stats_ex(struct smsdvb_client_t *client,
  342. struct SMSHOSTLIB_STATISTICS_ISDBT_EX_ST *p)
  343. {
  344. struct dvb_frontend *fe = &client->frontend;
  345. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  346. struct SMSHOSTLIB_ISDBT_LAYER_STAT_ST *lr;
  347. int i, n_layers;
  348. if (client->prt_isdb_stats_ex)
  349. client->prt_isdb_stats_ex(client->debug_data, p);
  350. /* Update ISDB-T transmission parameters */
  351. c->frequency = p->Frequency;
  352. client->fe_status = sms_to_status(p->IsDemodLocked, 0);
  353. c->bandwidth_hz = sms_to_bw(p->Bandwidth);
  354. c->transmission_mode = sms_to_mode(p->TransmissionMode);
  355. c->guard_interval = sms_to_guard_interval(p->GuardInterval);
  356. c->isdbt_partial_reception = p->PartialReception ? 1 : 0;
  357. n_layers = p->NumOfLayers;
  358. if (n_layers < 1)
  359. n_layers = 1;
  360. if (n_layers > 3)
  361. n_layers = 3;
  362. c->isdbt_layer_enabled = 0;
  363. /* update reception data */
  364. c->lna = p->IsExternalLNAOn ? 1 : 0;
  365. /* Carrier to Noise ratio, in DB */
  366. c->cnr.stat[0].svalue = p->SNR * 1000;
  367. /* Signal Strength, in DBm */
  368. c->strength.stat[0].uvalue = p->InBandPwr * 1000;
  369. /* PER/BER and per-layer stats require demod lock */
  370. if (!p->IsDemodLocked)
  371. return;
  372. client->last_per = c->block_error.stat[0].uvalue;
  373. /* Clears global counters, as the code below will sum it again */
  374. c->block_error.stat[0].uvalue = 0;
  375. c->block_count.stat[0].uvalue = 0;
  376. c->block_error.stat[0].scale = FE_SCALE_COUNTER;
  377. c->block_count.stat[0].scale = FE_SCALE_COUNTER;
  378. c->post_bit_error.stat[0].uvalue = 0;
  379. c->post_bit_count.stat[0].uvalue = 0;
  380. c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
  381. c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
  382. c->post_bit_error.len = n_layers + 1;
  383. c->post_bit_count.len = n_layers + 1;
  384. c->block_error.len = n_layers + 1;
  385. c->block_count.len = n_layers + 1;
  386. for (i = 0; i < n_layers; i++) {
  387. lr = &p->LayerInfo[i];
  388. /* Update per-layer transmission parameters */
  389. if (lr->NumberOfSegments > 0 && lr->NumberOfSegments < 13) {
  390. c->isdbt_layer_enabled |= 1 << i;
  391. c->layer[i].segment_count = lr->NumberOfSegments;
  392. } else {
  393. continue;
  394. }
  395. c->layer[i].modulation = sms_to_modulation(lr->Constellation);
  396. /* TS PER */
  397. c->block_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  398. c->block_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  399. c->block_error.stat[i + 1].uvalue += lr->ErrorTSPackets;
  400. c->block_count.stat[i + 1].uvalue += lr->TotalTSPackets;
  401. /* Update global PER counter */
  402. c->block_error.stat[0].uvalue += lr->ErrorTSPackets;
  403. c->block_count.stat[0].uvalue += lr->TotalTSPackets;
  404. /* BER */
  405. c->post_bit_error.stat[i + 1].scale = FE_SCALE_COUNTER;
  406. c->post_bit_count.stat[i + 1].scale = FE_SCALE_COUNTER;
  407. c->post_bit_error.stat[i + 1].uvalue += lr->BERErrorCount;
  408. c->post_bit_count.stat[i + 1].uvalue += lr->BERBitCount;
  409. /* Update global BER counter */
  410. c->post_bit_error.stat[0].uvalue += lr->BERErrorCount;
  411. c->post_bit_count.stat[0].uvalue += lr->BERBitCount;
  412. }
  413. }
  414. static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
  415. {
  416. struct smsdvb_client_t *client = (struct smsdvb_client_t *) context;
  417. struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) (((u8 *) cb->p)
  418. + cb->offset);
  419. void *p = phdr + 1;
  420. struct dvb_frontend *fe = &client->frontend;
  421. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  422. bool is_status_update = false;
  423. switch (phdr->msgType) {
  424. case MSG_SMS_DVBT_BDA_DATA:
  425. dvb_dmx_swfilter(&client->demux, p,
  426. cb->size - sizeof(struct SmsMsgHdr_ST));
  427. break;
  428. case MSG_SMS_RF_TUNE_RES:
  429. case MSG_SMS_ISDBT_TUNE_RES:
  430. complete(&client->tune_done);
  431. break;
  432. case MSG_SMS_SIGNAL_DETECTED_IND:
  433. client->fe_status = FE_HAS_SIGNAL | FE_HAS_CARRIER |
  434. FE_HAS_VITERBI | FE_HAS_SYNC |
  435. FE_HAS_LOCK;
  436. is_status_update = true;
  437. break;
  438. case MSG_SMS_NO_SIGNAL_IND:
  439. client->fe_status = 0;
  440. is_status_update = true;
  441. break;
  442. case MSG_SMS_TRANSMISSION_IND:
  443. smsdvb_update_tx_params(client, p);
  444. is_status_update = true;
  445. break;
  446. case MSG_SMS_HO_PER_SLICES_IND:
  447. smsdvb_update_per_slices(client, p);
  448. is_status_update = true;
  449. break;
  450. case MSG_SMS_GET_STATISTICS_RES:
  451. switch (smscore_get_device_mode(client->coredev)) {
  452. case DEVICE_MODE_ISDBT:
  453. case DEVICE_MODE_ISDBT_BDA:
  454. smsdvb_update_isdbt_stats(client, p);
  455. break;
  456. default:
  457. /* Skip SmsMsgStatisticsInfo_ST:RequestResult field */
  458. smsdvb_update_dvb_stats(client, p + sizeof(u32));
  459. }
  460. is_status_update = true;
  461. break;
  462. /* Only for ISDB-T */
  463. case MSG_SMS_GET_STATISTICS_EX_RES:
  464. /* Skip SmsMsgStatisticsInfo_ST:RequestResult field? */
  465. smsdvb_update_isdbt_stats_ex(client, p + sizeof(u32));
  466. is_status_update = true;
  467. break;
  468. default:
  469. sms_info("message not handled");
  470. }
  471. smscore_putbuffer(client->coredev, cb);
  472. if (is_status_update) {
  473. if (client->fe_status & FE_HAS_LOCK) {
  474. sms_board_dvb3_event(client, DVB3_EVENT_FE_LOCK);
  475. if (client->last_per == c->block_error.stat[0].uvalue)
  476. sms_board_dvb3_event(client, DVB3_EVENT_UNC_OK);
  477. else
  478. sms_board_dvb3_event(client, DVB3_EVENT_UNC_ERR);
  479. } else {
  480. smsdvb_stats_not_ready(fe);
  481. sms_board_dvb3_event(client, DVB3_EVENT_FE_UNLOCK);
  482. }
  483. complete(&client->stats_done);
  484. }
  485. return 0;
  486. }
  487. static void smsdvb_unregister_client(struct smsdvb_client_t *client)
  488. {
  489. /* must be called under clientslock */
  490. list_del(&client->entry);
  491. smsdvb_debugfs_release(client);
  492. smscore_unregister_client(client->smsclient);
  493. dvb_unregister_frontend(&client->frontend);
  494. dvb_dmxdev_release(&client->dmxdev);
  495. dvb_dmx_release(&client->demux);
  496. dvb_unregister_adapter(&client->adapter);
  497. kfree(client);
  498. }
  499. static void smsdvb_onremove(void *context)
  500. {
  501. kmutex_lock(&g_smsdvb_clientslock);
  502. smsdvb_unregister_client((struct smsdvb_client_t *) context);
  503. kmutex_unlock(&g_smsdvb_clientslock);
  504. }
  505. static int smsdvb_start_feed(struct dvb_demux_feed *feed)
  506. {
  507. struct smsdvb_client_t *client =
  508. container_of(feed->demux, struct smsdvb_client_t, demux);
  509. struct SmsMsgData_ST PidMsg;
  510. sms_debug("add pid %d(%x)",
  511. feed->pid, feed->pid);
  512. PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  513. PidMsg.xMsgHeader.msgDstId = HIF_TASK;
  514. PidMsg.xMsgHeader.msgFlags = 0;
  515. PidMsg.xMsgHeader.msgType = MSG_SMS_ADD_PID_FILTER_REQ;
  516. PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
  517. PidMsg.msgData[0] = feed->pid;
  518. return smsclient_sendrequest(client->smsclient,
  519. &PidMsg, sizeof(PidMsg));
  520. }
  521. static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
  522. {
  523. struct smsdvb_client_t *client =
  524. container_of(feed->demux, struct smsdvb_client_t, demux);
  525. struct SmsMsgData_ST PidMsg;
  526. sms_debug("remove pid %d(%x)",
  527. feed->pid, feed->pid);
  528. PidMsg.xMsgHeader.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  529. PidMsg.xMsgHeader.msgDstId = HIF_TASK;
  530. PidMsg.xMsgHeader.msgFlags = 0;
  531. PidMsg.xMsgHeader.msgType = MSG_SMS_REMOVE_PID_FILTER_REQ;
  532. PidMsg.xMsgHeader.msgLength = sizeof(PidMsg);
  533. PidMsg.msgData[0] = feed->pid;
  534. return smsclient_sendrequest(client->smsclient,
  535. &PidMsg, sizeof(PidMsg));
  536. }
  537. static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
  538. void *buffer, size_t size,
  539. struct completion *completion)
  540. {
  541. int rc;
  542. rc = smsclient_sendrequest(client->smsclient, buffer, size);
  543. if (rc < 0)
  544. return rc;
  545. return wait_for_completion_timeout(completion,
  546. msecs_to_jiffies(2000)) ?
  547. 0 : -ETIME;
  548. }
  549. static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
  550. {
  551. int rc;
  552. struct SmsMsgHdr_ST Msg;
  553. /* Don't request stats too fast */
  554. if (client->get_stats_jiffies &&
  555. (!time_after(jiffies, client->get_stats_jiffies)))
  556. return 0;
  557. client->get_stats_jiffies = jiffies + msecs_to_jiffies(100);
  558. Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  559. Msg.msgDstId = HIF_TASK;
  560. Msg.msgFlags = 0;
  561. Msg.msgLength = sizeof(Msg);
  562. switch (smscore_get_device_mode(client->coredev)) {
  563. case DEVICE_MODE_ISDBT:
  564. case DEVICE_MODE_ISDBT_BDA:
  565. /*
  566. * Check for firmware version, to avoid breaking for old cards
  567. */
  568. if (client->coredev->fw_version >= 0x800)
  569. Msg.msgType = MSG_SMS_GET_STATISTICS_EX_REQ;
  570. else
  571. Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;
  572. break;
  573. default:
  574. Msg.msgType = MSG_SMS_GET_STATISTICS_REQ;
  575. }
  576. rc = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  577. &client->stats_done);
  578. return rc;
  579. }
  580. static inline int led_feedback(struct smsdvb_client_t *client)
  581. {
  582. if (!(client->fe_status & FE_HAS_LOCK))
  583. return sms_board_led_feedback(client->coredev, SMS_LED_OFF);
  584. return sms_board_led_feedback(client->coredev,
  585. (client->legacy_ber == 0) ?
  586. SMS_LED_HI : SMS_LED_LO);
  587. }
  588. static int smsdvb_read_status(struct dvb_frontend *fe, fe_status_t *stat)
  589. {
  590. int rc;
  591. struct smsdvb_client_t *client;
  592. client = container_of(fe, struct smsdvb_client_t, frontend);
  593. rc = smsdvb_send_statistics_request(client);
  594. *stat = client->fe_status;
  595. led_feedback(client);
  596. return rc;
  597. }
  598. static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
  599. {
  600. int rc;
  601. struct smsdvb_client_t *client;
  602. client = container_of(fe, struct smsdvb_client_t, frontend);
  603. rc = smsdvb_send_statistics_request(client);
  604. *ber = client->legacy_ber;
  605. led_feedback(client);
  606. return rc;
  607. }
  608. static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  609. {
  610. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  611. int rc;
  612. s32 power = (s32) c->strength.stat[0].uvalue;
  613. struct smsdvb_client_t *client;
  614. client = container_of(fe, struct smsdvb_client_t, frontend);
  615. rc = smsdvb_send_statistics_request(client);
  616. if (power < -95)
  617. *strength = 0;
  618. else if (power > -29)
  619. *strength = 65535;
  620. else
  621. *strength = (power + 95) * 65535 / 66;
  622. led_feedback(client);
  623. return rc;
  624. }
  625. static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
  626. {
  627. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  628. int rc;
  629. struct smsdvb_client_t *client;
  630. client = container_of(fe, struct smsdvb_client_t, frontend);
  631. rc = smsdvb_send_statistics_request(client);
  632. /* Preferred scale for SNR with legacy API: 0.1 dB */
  633. *snr = c->cnr.stat[0].svalue / 100;
  634. led_feedback(client);
  635. return rc;
  636. }
  637. static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  638. {
  639. int rc;
  640. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  641. struct smsdvb_client_t *client;
  642. client = container_of(fe, struct smsdvb_client_t, frontend);
  643. rc = smsdvb_send_statistics_request(client);
  644. *ucblocks = c->block_error.stat[0].uvalue;
  645. led_feedback(client);
  646. return rc;
  647. }
  648. static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
  649. struct dvb_frontend_tune_settings *tune)
  650. {
  651. sms_debug("");
  652. tune->min_delay_ms = 400;
  653. tune->step_size = 250000;
  654. tune->max_drift = 0;
  655. return 0;
  656. }
  657. static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
  658. {
  659. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  660. struct smsdvb_client_t *client =
  661. container_of(fe, struct smsdvb_client_t, frontend);
  662. struct {
  663. struct SmsMsgHdr_ST Msg;
  664. u32 Data[3];
  665. } Msg;
  666. int ret;
  667. client->fe_status = 0;
  668. client->event_fe_state = -1;
  669. client->event_unc_state = -1;
  670. fe->dtv_property_cache.delivery_system = SYS_DVBT;
  671. Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  672. Msg.Msg.msgDstId = HIF_TASK;
  673. Msg.Msg.msgFlags = 0;
  674. Msg.Msg.msgType = MSG_SMS_RF_TUNE_REQ;
  675. Msg.Msg.msgLength = sizeof(Msg);
  676. Msg.Data[0] = c->frequency;
  677. Msg.Data[2] = 12000000;
  678. sms_info("%s: freq %d band %d", __func__, c->frequency,
  679. c->bandwidth_hz);
  680. switch (c->bandwidth_hz / 1000000) {
  681. case 8:
  682. Msg.Data[1] = BW_8_MHZ;
  683. break;
  684. case 7:
  685. Msg.Data[1] = BW_7_MHZ;
  686. break;
  687. case 6:
  688. Msg.Data[1] = BW_6_MHZ;
  689. break;
  690. case 0:
  691. return -EOPNOTSUPP;
  692. default:
  693. return -EINVAL;
  694. }
  695. /* Disable LNA, if any. An error is returned if no LNA is present */
  696. ret = sms_board_lna_control(client->coredev, 0);
  697. if (ret == 0) {
  698. fe_status_t status;
  699. /* tune with LNA off at first */
  700. ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  701. &client->tune_done);
  702. smsdvb_read_status(fe, &status);
  703. if (status & FE_HAS_LOCK)
  704. return ret;
  705. /* previous tune didn't lock - enable LNA and tune again */
  706. sms_board_lna_control(client->coredev, 1);
  707. }
  708. return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  709. &client->tune_done);
  710. }
  711. static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
  712. {
  713. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  714. struct smsdvb_client_t *client =
  715. container_of(fe, struct smsdvb_client_t, frontend);
  716. int board_id = smscore_get_board_id(client->coredev);
  717. struct sms_board *board = sms_get_board(board_id);
  718. enum sms_device_type_st type = board->type;
  719. int ret;
  720. struct {
  721. struct SmsMsgHdr_ST Msg;
  722. u32 Data[4];
  723. } Msg;
  724. fe->dtv_property_cache.delivery_system = SYS_ISDBT;
  725. Msg.Msg.msgSrcId = DVBT_BDA_CONTROL_MSG_ID;
  726. Msg.Msg.msgDstId = HIF_TASK;
  727. Msg.Msg.msgFlags = 0;
  728. Msg.Msg.msgType = MSG_SMS_ISDBT_TUNE_REQ;
  729. Msg.Msg.msgLength = sizeof(Msg);
  730. if (c->isdbt_sb_segment_idx == -1)
  731. c->isdbt_sb_segment_idx = 0;
  732. if (!c->isdbt_layer_enabled)
  733. c->isdbt_layer_enabled = 7;
  734. Msg.Data[0] = c->frequency;
  735. Msg.Data[1] = BW_ISDBT_1SEG;
  736. Msg.Data[2] = 12000000;
  737. Msg.Data[3] = c->isdbt_sb_segment_idx;
  738. if (c->isdbt_partial_reception) {
  739. if ((type == SMS_PELE || type == SMS_RIO) &&
  740. c->isdbt_sb_segment_count > 3)
  741. Msg.Data[1] = BW_ISDBT_13SEG;
  742. else if (c->isdbt_sb_segment_count > 1)
  743. Msg.Data[1] = BW_ISDBT_3SEG;
  744. } else if (type == SMS_PELE || type == SMS_RIO)
  745. Msg.Data[1] = BW_ISDBT_13SEG;
  746. c->bandwidth_hz = 6000000;
  747. sms_info("%s: freq %d segwidth %d segindex %d\n", __func__,
  748. c->frequency, c->isdbt_sb_segment_count,
  749. c->isdbt_sb_segment_idx);
  750. /* Disable LNA, if any. An error is returned if no LNA is present */
  751. ret = sms_board_lna_control(client->coredev, 0);
  752. if (ret == 0) {
  753. fe_status_t status;
  754. /* tune with LNA off at first */
  755. ret = smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  756. &client->tune_done);
  757. smsdvb_read_status(fe, &status);
  758. if (status & FE_HAS_LOCK)
  759. return ret;
  760. /* previous tune didn't lock - enable LNA and tune again */
  761. sms_board_lna_control(client->coredev, 1);
  762. }
  763. return smsdvb_sendrequest_and_wait(client, &Msg, sizeof(Msg),
  764. &client->tune_done);
  765. }
  766. static int smsdvb_set_frontend(struct dvb_frontend *fe)
  767. {
  768. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  769. struct smsdvb_client_t *client =
  770. container_of(fe, struct smsdvb_client_t, frontend);
  771. struct smscore_device_t *coredev = client->coredev;
  772. smsdvb_stats_not_ready(fe);
  773. c->strength.stat[0].uvalue = 0;
  774. c->cnr.stat[0].uvalue = 0;
  775. switch (smscore_get_device_mode(coredev)) {
  776. case DEVICE_MODE_DVBT:
  777. case DEVICE_MODE_DVBT_BDA:
  778. return smsdvb_dvbt_set_frontend(fe);
  779. case DEVICE_MODE_ISDBT:
  780. case DEVICE_MODE_ISDBT_BDA:
  781. return smsdvb_isdbt_set_frontend(fe);
  782. default:
  783. return -EINVAL;
  784. }
  785. }
  786. /* Nothing to do here, as stats are automatically updated */
  787. static int smsdvb_get_frontend(struct dvb_frontend *fe)
  788. {
  789. return 0;
  790. }
  791. static int smsdvb_init(struct dvb_frontend *fe)
  792. {
  793. struct smsdvb_client_t *client =
  794. container_of(fe, struct smsdvb_client_t, frontend);
  795. sms_board_power(client->coredev, 1);
  796. sms_board_dvb3_event(client, DVB3_EVENT_INIT);
  797. return 0;
  798. }
  799. static int smsdvb_sleep(struct dvb_frontend *fe)
  800. {
  801. struct smsdvb_client_t *client =
  802. container_of(fe, struct smsdvb_client_t, frontend);
  803. sms_board_led_feedback(client->coredev, SMS_LED_OFF);
  804. sms_board_power(client->coredev, 0);
  805. sms_board_dvb3_event(client, DVB3_EVENT_SLEEP);
  806. return 0;
  807. }
  808. static void smsdvb_release(struct dvb_frontend *fe)
  809. {
  810. /* do nothing */
  811. }
  812. static struct dvb_frontend_ops smsdvb_fe_ops = {
  813. .info = {
  814. .name = "Siano Mobile Digital MDTV Receiver",
  815. .frequency_min = 44250000,
  816. .frequency_max = 867250000,
  817. .frequency_stepsize = 250000,
  818. .caps = FE_CAN_INVERSION_AUTO |
  819. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  820. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  821. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
  822. FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
  823. FE_CAN_GUARD_INTERVAL_AUTO |
  824. FE_CAN_RECOVER |
  825. FE_CAN_HIERARCHY_AUTO,
  826. },
  827. .release = smsdvb_release,
  828. .set_frontend = smsdvb_set_frontend,
  829. .get_frontend = smsdvb_get_frontend,
  830. .get_tune_settings = smsdvb_get_tune_settings,
  831. .read_status = smsdvb_read_status,
  832. .read_ber = smsdvb_read_ber,
  833. .read_signal_strength = smsdvb_read_signal_strength,
  834. .read_snr = smsdvb_read_snr,
  835. .read_ucblocks = smsdvb_read_ucblocks,
  836. .init = smsdvb_init,
  837. .sleep = smsdvb_sleep,
  838. };
  839. static int smsdvb_hotplug(struct smscore_device_t *coredev,
  840. struct device *device, int arrival)
  841. {
  842. struct smsclient_params_t params;
  843. struct smsdvb_client_t *client;
  844. int rc;
  845. /* device removal handled by onremove callback */
  846. if (!arrival)
  847. return 0;
  848. client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
  849. if (!client) {
  850. sms_err("kmalloc() failed");
  851. return -ENOMEM;
  852. }
  853. /* register dvb adapter */
  854. rc = dvb_register_adapter(&client->adapter,
  855. sms_get_board(
  856. smscore_get_board_id(coredev))->name,
  857. THIS_MODULE, device, adapter_nr);
  858. if (rc < 0) {
  859. sms_err("dvb_register_adapter() failed %d", rc);
  860. goto adapter_error;
  861. }
  862. /* init dvb demux */
  863. client->demux.dmx.capabilities = DMX_TS_FILTERING;
  864. client->demux.filternum = 32; /* todo: nova ??? */
  865. client->demux.feednum = 32;
  866. client->demux.start_feed = smsdvb_start_feed;
  867. client->demux.stop_feed = smsdvb_stop_feed;
  868. rc = dvb_dmx_init(&client->demux);
  869. if (rc < 0) {
  870. sms_err("dvb_dmx_init failed %d", rc);
  871. goto dvbdmx_error;
  872. }
  873. /* init dmxdev */
  874. client->dmxdev.filternum = 32;
  875. client->dmxdev.demux = &client->demux.dmx;
  876. client->dmxdev.capabilities = 0;
  877. rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
  878. if (rc < 0) {
  879. sms_err("dvb_dmxdev_init failed %d", rc);
  880. goto dmxdev_error;
  881. }
  882. /* init and register frontend */
  883. memcpy(&client->frontend.ops, &smsdvb_fe_ops,
  884. sizeof(struct dvb_frontend_ops));
  885. switch (smscore_get_device_mode(coredev)) {
  886. case DEVICE_MODE_DVBT:
  887. case DEVICE_MODE_DVBT_BDA:
  888. client->frontend.ops.delsys[0] = SYS_DVBT;
  889. break;
  890. case DEVICE_MODE_ISDBT:
  891. case DEVICE_MODE_ISDBT_BDA:
  892. client->frontend.ops.delsys[0] = SYS_ISDBT;
  893. break;
  894. }
  895. rc = dvb_register_frontend(&client->adapter, &client->frontend);
  896. if (rc < 0) {
  897. sms_err("frontend registration failed %d", rc);
  898. goto frontend_error;
  899. }
  900. params.initial_id = 1;
  901. params.data_type = MSG_SMS_DVBT_BDA_DATA;
  902. params.onresponse_handler = smsdvb_onresponse;
  903. params.onremove_handler = smsdvb_onremove;
  904. params.context = client;
  905. rc = smscore_register_client(coredev, &params, &client->smsclient);
  906. if (rc < 0) {
  907. sms_err("smscore_register_client() failed %d", rc);
  908. goto client_error;
  909. }
  910. client->coredev = coredev;
  911. init_completion(&client->tune_done);
  912. init_completion(&client->stats_done);
  913. kmutex_lock(&g_smsdvb_clientslock);
  914. list_add(&client->entry, &g_smsdvb_clients);
  915. kmutex_unlock(&g_smsdvb_clientslock);
  916. client->event_fe_state = -1;
  917. client->event_unc_state = -1;
  918. sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG);
  919. sms_info("success");
  920. sms_board_setup(coredev);
  921. if (smsdvb_debugfs_create(client) < 0)
  922. sms_info("failed to create debugfs node");
  923. return 0;
  924. client_error:
  925. dvb_unregister_frontend(&client->frontend);
  926. frontend_error:
  927. dvb_dmxdev_release(&client->dmxdev);
  928. dmxdev_error:
  929. dvb_dmx_release(&client->demux);
  930. dvbdmx_error:
  931. dvb_unregister_adapter(&client->adapter);
  932. adapter_error:
  933. kfree(client);
  934. return rc;
  935. }
  936. static int __init smsdvb_module_init(void)
  937. {
  938. int rc;
  939. INIT_LIST_HEAD(&g_smsdvb_clients);
  940. kmutex_init(&g_smsdvb_clientslock);
  941. smsdvb_debugfs_register();
  942. rc = smscore_register_hotplug(smsdvb_hotplug);
  943. sms_debug("");
  944. return rc;
  945. }
  946. static void __exit smsdvb_module_exit(void)
  947. {
  948. smscore_unregister_hotplug(smsdvb_hotplug);
  949. kmutex_lock(&g_smsdvb_clientslock);
  950. while (!list_empty(&g_smsdvb_clients))
  951. smsdvb_unregister_client((struct smsdvb_client_t *)g_smsdvb_clients.next);
  952. smsdvb_debugfs_unregister();
  953. kmutex_unlock(&g_smsdvb_clientslock);
  954. }
  955. module_init(smsdvb_module_init);
  956. module_exit(smsdvb_module_exit);
  957. MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
  958. MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
  959. MODULE_LICENSE("GPL");