smsdvb-main.c 32 KB

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