smsdvb-main.c 33 KB

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