smsdvb-main.c 32 KB

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