smsdvb-main.c 32 KB

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