smsdvb-main.c 32 KB

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