smsdvb-main.c 33 KB

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