smsdvb-main.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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 "dmxdev.h"
  22. #include "dvbdev.h"
  23. #include "dvb_demux.h"
  24. #include "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 * 65535;
  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. kfree(coredev->media_dev);
  514. coredev->media_dev = NULL;
  515. #endif
  516. }
  517. static void smsdvb_unregister_client(struct smsdvb_client_t *client)
  518. {
  519. /* must be called under clientslock */
  520. list_del(&client->entry);
  521. smsdvb_debugfs_release(client);
  522. smscore_unregister_client(client->smsclient);
  523. dvb_unregister_frontend(&client->frontend);
  524. dvb_dmxdev_release(&client->dmxdev);
  525. dvb_dmx_release(&client->demux);
  526. smsdvb_media_device_unregister(client);
  527. dvb_unregister_adapter(&client->adapter);
  528. kfree(client);
  529. }
  530. static void smsdvb_onremove(void *context)
  531. {
  532. kmutex_lock(&g_smsdvb_clientslock);
  533. smsdvb_unregister_client((struct smsdvb_client_t *) context);
  534. kmutex_unlock(&g_smsdvb_clientslock);
  535. }
  536. static int smsdvb_start_feed(struct dvb_demux_feed *feed)
  537. {
  538. struct smsdvb_client_t *client =
  539. container_of(feed->demux, struct smsdvb_client_t, demux);
  540. struct sms_msg_data pid_msg;
  541. pr_debug("add pid %d(%x)\n",
  542. feed->pid, feed->pid);
  543. client->feed_users++;
  544. pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
  545. pid_msg.x_msg_header.msg_dst_id = HIF_TASK;
  546. pid_msg.x_msg_header.msg_flags = 0;
  547. pid_msg.x_msg_header.msg_type = MSG_SMS_ADD_PID_FILTER_REQ;
  548. pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
  549. pid_msg.msg_data[0] = feed->pid;
  550. return smsclient_sendrequest(client->smsclient,
  551. &pid_msg, sizeof(pid_msg));
  552. }
  553. static int smsdvb_stop_feed(struct dvb_demux_feed *feed)
  554. {
  555. struct smsdvb_client_t *client =
  556. container_of(feed->demux, struct smsdvb_client_t, demux);
  557. struct sms_msg_data pid_msg;
  558. pr_debug("remove pid %d(%x)\n",
  559. feed->pid, feed->pid);
  560. client->feed_users--;
  561. pid_msg.x_msg_header.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
  562. pid_msg.x_msg_header.msg_dst_id = HIF_TASK;
  563. pid_msg.x_msg_header.msg_flags = 0;
  564. pid_msg.x_msg_header.msg_type = MSG_SMS_REMOVE_PID_FILTER_REQ;
  565. pid_msg.x_msg_header.msg_length = sizeof(pid_msg);
  566. pid_msg.msg_data[0] = feed->pid;
  567. return smsclient_sendrequest(client->smsclient,
  568. &pid_msg, sizeof(pid_msg));
  569. }
  570. static int smsdvb_sendrequest_and_wait(struct smsdvb_client_t *client,
  571. void *buffer, size_t size,
  572. struct completion *completion)
  573. {
  574. int rc;
  575. rc = smsclient_sendrequest(client->smsclient, buffer, size);
  576. if (rc < 0)
  577. return rc;
  578. return wait_for_completion_timeout(completion,
  579. msecs_to_jiffies(2000)) ?
  580. 0 : -ETIME;
  581. }
  582. static int smsdvb_send_statistics_request(struct smsdvb_client_t *client)
  583. {
  584. int rc;
  585. struct sms_msg_hdr msg;
  586. /* Don't request stats too fast */
  587. if (client->get_stats_jiffies &&
  588. (!time_after(jiffies, client->get_stats_jiffies)))
  589. return 0;
  590. client->get_stats_jiffies = jiffies + msecs_to_jiffies(100);
  591. msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
  592. msg.msg_dst_id = HIF_TASK;
  593. msg.msg_flags = 0;
  594. msg.msg_length = sizeof(msg);
  595. switch (smscore_get_device_mode(client->coredev)) {
  596. case DEVICE_MODE_ISDBT:
  597. case DEVICE_MODE_ISDBT_BDA:
  598. /*
  599. * Check for firmware version, to avoid breaking for old cards
  600. */
  601. if (client->coredev->fw_version >= 0x800)
  602. msg.msg_type = MSG_SMS_GET_STATISTICS_EX_REQ;
  603. else
  604. msg.msg_type = MSG_SMS_GET_STATISTICS_REQ;
  605. break;
  606. default:
  607. msg.msg_type = MSG_SMS_GET_STATISTICS_REQ;
  608. }
  609. rc = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
  610. &client->stats_done);
  611. return rc;
  612. }
  613. static inline int led_feedback(struct smsdvb_client_t *client)
  614. {
  615. if (!(client->fe_status & FE_HAS_LOCK))
  616. return sms_board_led_feedback(client->coredev, SMS_LED_OFF);
  617. return sms_board_led_feedback(client->coredev,
  618. (client->legacy_ber == 0) ?
  619. SMS_LED_HI : SMS_LED_LO);
  620. }
  621. static int smsdvb_read_status(struct dvb_frontend *fe, enum fe_status *stat)
  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. *stat = client->fe_status;
  628. led_feedback(client);
  629. return rc;
  630. }
  631. static int smsdvb_read_ber(struct dvb_frontend *fe, u32 *ber)
  632. {
  633. int rc;
  634. struct smsdvb_client_t *client;
  635. client = container_of(fe, struct smsdvb_client_t, frontend);
  636. rc = smsdvb_send_statistics_request(client);
  637. *ber = client->legacy_ber;
  638. led_feedback(client);
  639. return rc;
  640. }
  641. static int smsdvb_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
  642. {
  643. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  644. int rc;
  645. s32 power = (s32) c->strength.stat[0].uvalue;
  646. struct smsdvb_client_t *client;
  647. client = container_of(fe, struct smsdvb_client_t, frontend);
  648. rc = smsdvb_send_statistics_request(client);
  649. if (power < -95)
  650. *strength = 0;
  651. else if (power > -29)
  652. *strength = 65535;
  653. else
  654. *strength = (power + 95) * 65535 / 66;
  655. led_feedback(client);
  656. return rc;
  657. }
  658. static int smsdvb_read_snr(struct dvb_frontend *fe, u16 *snr)
  659. {
  660. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  661. int rc;
  662. struct smsdvb_client_t *client;
  663. client = container_of(fe, struct smsdvb_client_t, frontend);
  664. rc = smsdvb_send_statistics_request(client);
  665. /* Preferred scale for SNR with legacy API: 0.1 dB */
  666. *snr = ((u32)c->cnr.stat[0].svalue) / 100;
  667. led_feedback(client);
  668. return rc;
  669. }
  670. static int smsdvb_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
  671. {
  672. int rc;
  673. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  674. struct smsdvb_client_t *client;
  675. client = container_of(fe, struct smsdvb_client_t, frontend);
  676. rc = smsdvb_send_statistics_request(client);
  677. *ucblocks = c->block_error.stat[0].uvalue;
  678. led_feedback(client);
  679. return rc;
  680. }
  681. static int smsdvb_get_tune_settings(struct dvb_frontend *fe,
  682. struct dvb_frontend_tune_settings *tune)
  683. {
  684. pr_debug("\n");
  685. tune->min_delay_ms = 400;
  686. tune->step_size = 250000;
  687. tune->max_drift = 0;
  688. return 0;
  689. }
  690. static int smsdvb_dvbt_set_frontend(struct dvb_frontend *fe)
  691. {
  692. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  693. struct smsdvb_client_t *client =
  694. container_of(fe, struct smsdvb_client_t, frontend);
  695. struct {
  696. struct sms_msg_hdr msg;
  697. u32 Data[3];
  698. } msg;
  699. int ret;
  700. client->fe_status = 0;
  701. client->event_fe_state = -1;
  702. client->event_unc_state = -1;
  703. fe->dtv_property_cache.delivery_system = SYS_DVBT;
  704. msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
  705. msg.msg.msg_dst_id = HIF_TASK;
  706. msg.msg.msg_flags = 0;
  707. msg.msg.msg_type = MSG_SMS_RF_TUNE_REQ;
  708. msg.msg.msg_length = sizeof(msg);
  709. msg.Data[0] = c->frequency;
  710. msg.Data[2] = 12000000;
  711. pr_debug("%s: freq %d band %d\n", __func__, c->frequency,
  712. c->bandwidth_hz);
  713. switch (c->bandwidth_hz / 1000000) {
  714. case 8:
  715. msg.Data[1] = BW_8_MHZ;
  716. break;
  717. case 7:
  718. msg.Data[1] = BW_7_MHZ;
  719. break;
  720. case 6:
  721. msg.Data[1] = BW_6_MHZ;
  722. break;
  723. case 0:
  724. return -EOPNOTSUPP;
  725. default:
  726. return -EINVAL;
  727. }
  728. /* Disable LNA, if any. An error is returned if no LNA is present */
  729. ret = sms_board_lna_control(client->coredev, 0);
  730. if (ret == 0) {
  731. enum fe_status status;
  732. /* tune with LNA off at first */
  733. ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
  734. &client->tune_done);
  735. smsdvb_read_status(fe, &status);
  736. if (status & FE_HAS_LOCK)
  737. return ret;
  738. /* previous tune didn't lock - enable LNA and tune again */
  739. sms_board_lna_control(client->coredev, 1);
  740. }
  741. return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
  742. &client->tune_done);
  743. }
  744. static int smsdvb_isdbt_set_frontend(struct dvb_frontend *fe)
  745. {
  746. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  747. struct smsdvb_client_t *client =
  748. container_of(fe, struct smsdvb_client_t, frontend);
  749. int board_id = smscore_get_board_id(client->coredev);
  750. struct sms_board *board = sms_get_board(board_id);
  751. enum sms_device_type_st type = board->type;
  752. int ret;
  753. struct {
  754. struct sms_msg_hdr msg;
  755. u32 Data[4];
  756. } msg;
  757. fe->dtv_property_cache.delivery_system = SYS_ISDBT;
  758. msg.msg.msg_src_id = DVBT_BDA_CONTROL_MSG_ID;
  759. msg.msg.msg_dst_id = HIF_TASK;
  760. msg.msg.msg_flags = 0;
  761. msg.msg.msg_type = MSG_SMS_ISDBT_TUNE_REQ;
  762. msg.msg.msg_length = sizeof(msg);
  763. if (c->isdbt_sb_segment_idx == -1)
  764. c->isdbt_sb_segment_idx = 0;
  765. if (!c->isdbt_layer_enabled)
  766. c->isdbt_layer_enabled = 7;
  767. msg.Data[0] = c->frequency;
  768. msg.Data[1] = BW_ISDBT_1SEG;
  769. msg.Data[2] = 12000000;
  770. msg.Data[3] = c->isdbt_sb_segment_idx;
  771. if (c->isdbt_partial_reception) {
  772. if ((type == SMS_PELE || type == SMS_RIO) &&
  773. c->isdbt_sb_segment_count > 3)
  774. msg.Data[1] = BW_ISDBT_13SEG;
  775. else if (c->isdbt_sb_segment_count > 1)
  776. msg.Data[1] = BW_ISDBT_3SEG;
  777. } else if (type == SMS_PELE || type == SMS_RIO)
  778. msg.Data[1] = BW_ISDBT_13SEG;
  779. c->bandwidth_hz = 6000000;
  780. pr_debug("freq %d segwidth %d segindex %d\n",
  781. c->frequency, c->isdbt_sb_segment_count,
  782. c->isdbt_sb_segment_idx);
  783. /* Disable LNA, if any. An error is returned if no LNA is present */
  784. ret = sms_board_lna_control(client->coredev, 0);
  785. if (ret == 0) {
  786. enum fe_status status;
  787. /* tune with LNA off at first */
  788. ret = smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
  789. &client->tune_done);
  790. smsdvb_read_status(fe, &status);
  791. if (status & FE_HAS_LOCK)
  792. return ret;
  793. /* previous tune didn't lock - enable LNA and tune again */
  794. sms_board_lna_control(client->coredev, 1);
  795. }
  796. return smsdvb_sendrequest_and_wait(client, &msg, sizeof(msg),
  797. &client->tune_done);
  798. }
  799. static int smsdvb_set_frontend(struct dvb_frontend *fe)
  800. {
  801. struct dtv_frontend_properties *c = &fe->dtv_property_cache;
  802. struct smsdvb_client_t *client =
  803. container_of(fe, struct smsdvb_client_t, frontend);
  804. struct smscore_device_t *coredev = client->coredev;
  805. smsdvb_stats_not_ready(fe);
  806. c->strength.stat[0].uvalue = 0;
  807. c->cnr.stat[0].uvalue = 0;
  808. client->has_tuned = false;
  809. switch (smscore_get_device_mode(coredev)) {
  810. case DEVICE_MODE_DVBT:
  811. case DEVICE_MODE_DVBT_BDA:
  812. return smsdvb_dvbt_set_frontend(fe);
  813. case DEVICE_MODE_ISDBT:
  814. case DEVICE_MODE_ISDBT_BDA:
  815. return smsdvb_isdbt_set_frontend(fe);
  816. default:
  817. return -EINVAL;
  818. }
  819. }
  820. /* Nothing to do here, as stats are automatically updated */
  821. static int smsdvb_get_frontend(struct dvb_frontend *fe)
  822. {
  823. return 0;
  824. }
  825. static int smsdvb_init(struct dvb_frontend *fe)
  826. {
  827. struct smsdvb_client_t *client =
  828. container_of(fe, struct smsdvb_client_t, frontend);
  829. sms_board_power(client->coredev, 1);
  830. sms_board_dvb3_event(client, DVB3_EVENT_INIT);
  831. return 0;
  832. }
  833. static int smsdvb_sleep(struct dvb_frontend *fe)
  834. {
  835. struct smsdvb_client_t *client =
  836. container_of(fe, struct smsdvb_client_t, frontend);
  837. sms_board_led_feedback(client->coredev, SMS_LED_OFF);
  838. sms_board_power(client->coredev, 0);
  839. sms_board_dvb3_event(client, DVB3_EVENT_SLEEP);
  840. return 0;
  841. }
  842. static void smsdvb_release(struct dvb_frontend *fe)
  843. {
  844. /* do nothing */
  845. }
  846. static struct dvb_frontend_ops smsdvb_fe_ops = {
  847. .info = {
  848. .name = "Siano Mobile Digital MDTV Receiver",
  849. .frequency_min = 44250000,
  850. .frequency_max = 867250000,
  851. .frequency_stepsize = 250000,
  852. .caps = FE_CAN_INVERSION_AUTO |
  853. FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
  854. FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
  855. FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
  856. FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
  857. FE_CAN_GUARD_INTERVAL_AUTO |
  858. FE_CAN_RECOVER |
  859. FE_CAN_HIERARCHY_AUTO,
  860. },
  861. .release = smsdvb_release,
  862. .set_frontend = smsdvb_set_frontend,
  863. .get_frontend = smsdvb_get_frontend,
  864. .get_tune_settings = smsdvb_get_tune_settings,
  865. .read_status = smsdvb_read_status,
  866. .read_ber = smsdvb_read_ber,
  867. .read_signal_strength = smsdvb_read_signal_strength,
  868. .read_snr = smsdvb_read_snr,
  869. .read_ucblocks = smsdvb_read_ucblocks,
  870. .init = smsdvb_init,
  871. .sleep = smsdvb_sleep,
  872. };
  873. static int smsdvb_hotplug(struct smscore_device_t *coredev,
  874. struct device *device, int arrival)
  875. {
  876. struct smsclient_params_t params;
  877. struct smsdvb_client_t *client;
  878. int rc;
  879. /* device removal handled by onremove callback */
  880. if (!arrival)
  881. return 0;
  882. client = kzalloc(sizeof(struct smsdvb_client_t), GFP_KERNEL);
  883. if (!client)
  884. return -ENOMEM;
  885. /* register dvb adapter */
  886. rc = dvb_register_adapter(&client->adapter,
  887. sms_get_board(
  888. smscore_get_board_id(coredev))->name,
  889. THIS_MODULE, device, adapter_nr);
  890. if (rc < 0) {
  891. pr_err("dvb_register_adapter() failed %d\n", rc);
  892. goto adapter_error;
  893. }
  894. dvb_register_media_controller(&client->adapter, coredev->media_dev);
  895. /* init dvb demux */
  896. client->demux.dmx.capabilities = DMX_TS_FILTERING;
  897. client->demux.filternum = 32; /* todo: nova ??? */
  898. client->demux.feednum = 32;
  899. client->demux.start_feed = smsdvb_start_feed;
  900. client->demux.stop_feed = smsdvb_stop_feed;
  901. rc = dvb_dmx_init(&client->demux);
  902. if (rc < 0) {
  903. pr_err("dvb_dmx_init failed %d\n", rc);
  904. goto dvbdmx_error;
  905. }
  906. /* init dmxdev */
  907. client->dmxdev.filternum = 32;
  908. client->dmxdev.demux = &client->demux.dmx;
  909. client->dmxdev.capabilities = 0;
  910. rc = dvb_dmxdev_init(&client->dmxdev, &client->adapter);
  911. if (rc < 0) {
  912. pr_err("dvb_dmxdev_init failed %d\n", rc);
  913. goto dmxdev_error;
  914. }
  915. /* init and register frontend */
  916. memcpy(&client->frontend.ops, &smsdvb_fe_ops,
  917. sizeof(struct dvb_frontend_ops));
  918. switch (smscore_get_device_mode(coredev)) {
  919. case DEVICE_MODE_DVBT:
  920. case DEVICE_MODE_DVBT_BDA:
  921. client->frontend.ops.delsys[0] = SYS_DVBT;
  922. break;
  923. case DEVICE_MODE_ISDBT:
  924. case DEVICE_MODE_ISDBT_BDA:
  925. client->frontend.ops.delsys[0] = SYS_ISDBT;
  926. break;
  927. }
  928. rc = dvb_register_frontend(&client->adapter, &client->frontend);
  929. if (rc < 0) {
  930. pr_err("frontend registration failed %d\n", rc);
  931. goto frontend_error;
  932. }
  933. params.initial_id = 1;
  934. params.data_type = MSG_SMS_DVBT_BDA_DATA;
  935. params.onresponse_handler = smsdvb_onresponse;
  936. params.onremove_handler = smsdvb_onremove;
  937. params.context = client;
  938. rc = smscore_register_client(coredev, &params, &client->smsclient);
  939. if (rc < 0) {
  940. pr_err("smscore_register_client() failed %d\n", rc);
  941. goto client_error;
  942. }
  943. client->coredev = coredev;
  944. init_completion(&client->tune_done);
  945. init_completion(&client->stats_done);
  946. kmutex_lock(&g_smsdvb_clientslock);
  947. list_add(&client->entry, &g_smsdvb_clients);
  948. kmutex_unlock(&g_smsdvb_clientslock);
  949. client->event_fe_state = -1;
  950. client->event_unc_state = -1;
  951. sms_board_dvb3_event(client, DVB3_EVENT_HOTPLUG);
  952. sms_board_setup(coredev);
  953. if (smsdvb_debugfs_create(client) < 0)
  954. pr_info("failed to create debugfs node\n");
  955. dvb_create_media_graph(&client->adapter);
  956. pr_info("DVB interface registered.\n");
  957. return 0;
  958. client_error:
  959. dvb_unregister_frontend(&client->frontend);
  960. frontend_error:
  961. dvb_dmxdev_release(&client->dmxdev);
  962. dmxdev_error:
  963. dvb_dmx_release(&client->demux);
  964. dvbdmx_error:
  965. smsdvb_media_device_unregister(client);
  966. dvb_unregister_adapter(&client->adapter);
  967. adapter_error:
  968. kfree(client);
  969. return rc;
  970. }
  971. static int __init smsdvb_module_init(void)
  972. {
  973. int rc;
  974. INIT_LIST_HEAD(&g_smsdvb_clients);
  975. kmutex_init(&g_smsdvb_clientslock);
  976. smsdvb_debugfs_register();
  977. rc = smscore_register_hotplug(smsdvb_hotplug);
  978. pr_debug("\n");
  979. return rc;
  980. }
  981. static void __exit smsdvb_module_exit(void)
  982. {
  983. smscore_unregister_hotplug(smsdvb_hotplug);
  984. kmutex_lock(&g_smsdvb_clientslock);
  985. while (!list_empty(&g_smsdvb_clients))
  986. smsdvb_unregister_client((struct smsdvb_client_t *)g_smsdvb_clients.next);
  987. smsdvb_debugfs_unregister();
  988. kmutex_unlock(&g_smsdvb_clientslock);
  989. }
  990. module_init(smsdvb_module_init);
  991. module_exit(smsdvb_module_exit);
  992. MODULE_DESCRIPTION("SMS DVB subsystem adaptation module");
  993. MODULE_AUTHOR("Siano Mobile Silicon, Inc. (uris@siano-ms.com)");
  994. MODULE_LICENSE("GPL");