smsdvb-debugfs.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. /***********************************************************************
  2. *
  3. * Copyright(c) 2013 Mauro Carvalho Chehab <mchehab@redhat.com>
  4. *
  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. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. ***********************************************************************/
  18. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  19. #include <linux/module.h>
  20. #include <linux/slab.h>
  21. #include <linux/init.h>
  22. #include <linux/debugfs.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/usb.h>
  25. #include "dmxdev.h"
  26. #include "dvbdev.h"
  27. #include "dvb_demux.h"
  28. #include "dvb_frontend.h"
  29. #include "smscoreapi.h"
  30. #include "smsdvb.h"
  31. static struct dentry *smsdvb_debugfs_usb_root;
  32. struct smsdvb_debugfs {
  33. struct kref refcount;
  34. spinlock_t lock;
  35. char stats_data[PAGE_SIZE];
  36. unsigned stats_count;
  37. bool stats_was_read;
  38. wait_queue_head_t stats_queue;
  39. };
  40. static void smsdvb_print_dvb_stats(struct smsdvb_debugfs *debug_data,
  41. struct sms_stats *p)
  42. {
  43. int n = 0;
  44. char *buf;
  45. spin_lock(&debug_data->lock);
  46. if (debug_data->stats_count) {
  47. spin_unlock(&debug_data->lock);
  48. return;
  49. }
  50. buf = debug_data->stats_data;
  51. n += snprintf(&buf[n], PAGE_SIZE - n,
  52. "is_rf_locked = %d\n", p->is_rf_locked);
  53. n += snprintf(&buf[n], PAGE_SIZE - n,
  54. "is_demod_locked = %d\n", p->is_demod_locked);
  55. n += snprintf(&buf[n], PAGE_SIZE - n,
  56. "is_external_lna_on = %d\n", p->is_external_lna_on);
  57. n += snprintf(&buf[n], PAGE_SIZE - n,
  58. "SNR = %d\n", p->SNR);
  59. n += snprintf(&buf[n], PAGE_SIZE - n,
  60. "ber = %d\n", p->ber);
  61. n += snprintf(&buf[n], PAGE_SIZE - n,
  62. "FIB_CRC = %d\n", p->FIB_CRC);
  63. n += snprintf(&buf[n], PAGE_SIZE - n,
  64. "ts_per = %d\n", p->ts_per);
  65. n += snprintf(&buf[n], PAGE_SIZE - n,
  66. "MFER = %d\n", p->MFER);
  67. n += snprintf(&buf[n], PAGE_SIZE - n,
  68. "RSSI = %d\n", p->RSSI);
  69. n += snprintf(&buf[n], PAGE_SIZE - n,
  70. "in_band_pwr = %d\n", p->in_band_pwr);
  71. n += snprintf(&buf[n], PAGE_SIZE - n,
  72. "carrier_offset = %d\n", p->carrier_offset);
  73. n += snprintf(&buf[n], PAGE_SIZE - n,
  74. "modem_state = %d\n", p->modem_state);
  75. n += snprintf(&buf[n], PAGE_SIZE - n,
  76. "frequency = %d\n", p->frequency);
  77. n += snprintf(&buf[n], PAGE_SIZE - n,
  78. "bandwidth = %d\n", p->bandwidth);
  79. n += snprintf(&buf[n], PAGE_SIZE - n,
  80. "transmission_mode = %d\n", p->transmission_mode);
  81. n += snprintf(&buf[n], PAGE_SIZE - n,
  82. "modem_state = %d\n", p->modem_state);
  83. n += snprintf(&buf[n], PAGE_SIZE - n,
  84. "guard_interval = %d\n", p->guard_interval);
  85. n += snprintf(&buf[n], PAGE_SIZE - n,
  86. "code_rate = %d\n", p->code_rate);
  87. n += snprintf(&buf[n], PAGE_SIZE - n,
  88. "lp_code_rate = %d\n", p->lp_code_rate);
  89. n += snprintf(&buf[n], PAGE_SIZE - n,
  90. "hierarchy = %d\n", p->hierarchy);
  91. n += snprintf(&buf[n], PAGE_SIZE - n,
  92. "constellation = %d\n", p->constellation);
  93. n += snprintf(&buf[n], PAGE_SIZE - n,
  94. "burst_size = %d\n", p->burst_size);
  95. n += snprintf(&buf[n], PAGE_SIZE - n,
  96. "burst_duration = %d\n", p->burst_duration);
  97. n += snprintf(&buf[n], PAGE_SIZE - n,
  98. "burst_cycle_time = %d\n", p->burst_cycle_time);
  99. n += snprintf(&buf[n], PAGE_SIZE - n,
  100. "calc_burst_cycle_time = %d\n",
  101. p->calc_burst_cycle_time);
  102. n += snprintf(&buf[n], PAGE_SIZE - n,
  103. "num_of_rows = %d\n", p->num_of_rows);
  104. n += snprintf(&buf[n], PAGE_SIZE - n,
  105. "num_of_padd_cols = %d\n", p->num_of_padd_cols);
  106. n += snprintf(&buf[n], PAGE_SIZE - n,
  107. "num_of_punct_cols = %d\n", p->num_of_punct_cols);
  108. n += snprintf(&buf[n], PAGE_SIZE - n,
  109. "error_ts_packets = %d\n", p->error_ts_packets);
  110. n += snprintf(&buf[n], PAGE_SIZE - n,
  111. "total_ts_packets = %d\n", p->total_ts_packets);
  112. n += snprintf(&buf[n], PAGE_SIZE - n,
  113. "num_of_valid_mpe_tlbs = %d\n", p->num_of_valid_mpe_tlbs);
  114. n += snprintf(&buf[n], PAGE_SIZE - n,
  115. "num_of_invalid_mpe_tlbs = %d\n", p->num_of_invalid_mpe_tlbs);
  116. n += snprintf(&buf[n], PAGE_SIZE - n,
  117. "num_of_corrected_mpe_tlbs = %d\n", p->num_of_corrected_mpe_tlbs);
  118. n += snprintf(&buf[n], PAGE_SIZE - n,
  119. "ber_error_count = %d\n", p->ber_error_count);
  120. n += snprintf(&buf[n], PAGE_SIZE - n,
  121. "ber_bit_count = %d\n", p->ber_bit_count);
  122. n += snprintf(&buf[n], PAGE_SIZE - n,
  123. "sms_to_host_tx_errors = %d\n", p->sms_to_host_tx_errors);
  124. n += snprintf(&buf[n], PAGE_SIZE - n,
  125. "pre_ber = %d\n", p->pre_ber);
  126. n += snprintf(&buf[n], PAGE_SIZE - n,
  127. "cell_id = %d\n", p->cell_id);
  128. n += snprintf(&buf[n], PAGE_SIZE - n,
  129. "dvbh_srv_ind_hp = %d\n", p->dvbh_srv_ind_hp);
  130. n += snprintf(&buf[n], PAGE_SIZE - n,
  131. "dvbh_srv_ind_lp = %d\n", p->dvbh_srv_ind_lp);
  132. n += snprintf(&buf[n], PAGE_SIZE - n,
  133. "num_mpe_received = %d\n", p->num_mpe_received);
  134. debug_data->stats_count = n;
  135. spin_unlock(&debug_data->lock);
  136. wake_up(&debug_data->stats_queue);
  137. }
  138. static void smsdvb_print_isdb_stats(struct smsdvb_debugfs *debug_data,
  139. struct sms_isdbt_stats *p)
  140. {
  141. int i, n = 0;
  142. char *buf;
  143. spin_lock(&debug_data->lock);
  144. if (debug_data->stats_count) {
  145. spin_unlock(&debug_data->lock);
  146. return;
  147. }
  148. buf = debug_data->stats_data;
  149. n += snprintf(&buf[n], PAGE_SIZE - n,
  150. "statistics_type = %d\t", p->statistics_type);
  151. n += snprintf(&buf[n], PAGE_SIZE - n,
  152. "full_size = %d\n", p->full_size);
  153. n += snprintf(&buf[n], PAGE_SIZE - n,
  154. "is_rf_locked = %d\t\t", p->is_rf_locked);
  155. n += snprintf(&buf[n], PAGE_SIZE - n,
  156. "is_demod_locked = %d\t", p->is_demod_locked);
  157. n += snprintf(&buf[n], PAGE_SIZE - n,
  158. "is_external_lna_on = %d\n", p->is_external_lna_on);
  159. n += snprintf(&buf[n], PAGE_SIZE - n,
  160. "SNR = %d dB\t\t", p->SNR);
  161. n += snprintf(&buf[n], PAGE_SIZE - n,
  162. "RSSI = %d dBm\t\t", p->RSSI);
  163. n += snprintf(&buf[n], PAGE_SIZE - n,
  164. "in_band_pwr = %d dBm\n", p->in_band_pwr);
  165. n += snprintf(&buf[n], PAGE_SIZE - n,
  166. "carrier_offset = %d\t", p->carrier_offset);
  167. n += snprintf(&buf[n], PAGE_SIZE - n,
  168. "bandwidth = %d\t\t", p->bandwidth);
  169. n += snprintf(&buf[n], PAGE_SIZE - n,
  170. "frequency = %d Hz\n", p->frequency);
  171. n += snprintf(&buf[n], PAGE_SIZE - n,
  172. "transmission_mode = %d\t", p->transmission_mode);
  173. n += snprintf(&buf[n], PAGE_SIZE - n,
  174. "modem_state = %d\t\t", p->modem_state);
  175. n += snprintf(&buf[n], PAGE_SIZE - n,
  176. "guard_interval = %d\n", p->guard_interval);
  177. n += snprintf(&buf[n], PAGE_SIZE - n,
  178. "system_type = %d\t\t", p->system_type);
  179. n += snprintf(&buf[n], PAGE_SIZE - n,
  180. "partial_reception = %d\t", p->partial_reception);
  181. n += snprintf(&buf[n], PAGE_SIZE - n,
  182. "num_of_layers = %d\n", p->num_of_layers);
  183. n += snprintf(&buf[n], PAGE_SIZE - n,
  184. "sms_to_host_tx_errors = %d\n", p->sms_to_host_tx_errors);
  185. for (i = 0; i < 3; i++) {
  186. if (p->layer_info[i].number_of_segments < 1 ||
  187. p->layer_info[i].number_of_segments > 13)
  188. continue;
  189. n += snprintf(&buf[n], PAGE_SIZE - n, "\nLayer %d\n", i);
  190. n += snprintf(&buf[n], PAGE_SIZE - n, "\tcode_rate = %d\t",
  191. p->layer_info[i].code_rate);
  192. n += snprintf(&buf[n], PAGE_SIZE - n, "constellation = %d\n",
  193. p->layer_info[i].constellation);
  194. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber = %-5d\t",
  195. p->layer_info[i].ber);
  196. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber_error_count = %-5d\t",
  197. p->layer_info[i].ber_error_count);
  198. n += snprintf(&buf[n], PAGE_SIZE - n, "ber_bit_count = %-5d\n",
  199. p->layer_info[i].ber_bit_count);
  200. n += snprintf(&buf[n], PAGE_SIZE - n, "\tpre_ber = %-5d\t",
  201. p->layer_info[i].pre_ber);
  202. n += snprintf(&buf[n], PAGE_SIZE - n, "\tts_per = %-5d\n",
  203. p->layer_info[i].ts_per);
  204. n += snprintf(&buf[n], PAGE_SIZE - n, "\terror_ts_packets = %-5d\t",
  205. p->layer_info[i].error_ts_packets);
  206. n += snprintf(&buf[n], PAGE_SIZE - n, "total_ts_packets = %-5d\t",
  207. p->layer_info[i].total_ts_packets);
  208. n += snprintf(&buf[n], PAGE_SIZE - n, "ti_ldepth_i = %d\n",
  209. p->layer_info[i].ti_ldepth_i);
  210. n += snprintf(&buf[n], PAGE_SIZE - n,
  211. "\tnumber_of_segments = %d\t",
  212. p->layer_info[i].number_of_segments);
  213. n += snprintf(&buf[n], PAGE_SIZE - n, "tmcc_errors = %d\n",
  214. p->layer_info[i].tmcc_errors);
  215. }
  216. debug_data->stats_count = n;
  217. spin_unlock(&debug_data->lock);
  218. wake_up(&debug_data->stats_queue);
  219. }
  220. static void smsdvb_print_isdb_stats_ex(struct smsdvb_debugfs *debug_data,
  221. struct sms_isdbt_stats_ex *p)
  222. {
  223. int i, n = 0;
  224. char *buf;
  225. spin_lock(&debug_data->lock);
  226. if (debug_data->stats_count) {
  227. spin_unlock(&debug_data->lock);
  228. return;
  229. }
  230. buf = debug_data->stats_data;
  231. n += snprintf(&buf[n], PAGE_SIZE - n,
  232. "statistics_type = %d\t", p->statistics_type);
  233. n += snprintf(&buf[n], PAGE_SIZE - n,
  234. "full_size = %d\n", p->full_size);
  235. n += snprintf(&buf[n], PAGE_SIZE - n,
  236. "is_rf_locked = %d\t\t", p->is_rf_locked);
  237. n += snprintf(&buf[n], PAGE_SIZE - n,
  238. "is_demod_locked = %d\t", p->is_demod_locked);
  239. n += snprintf(&buf[n], PAGE_SIZE - n,
  240. "is_external_lna_on = %d\n", p->is_external_lna_on);
  241. n += snprintf(&buf[n], PAGE_SIZE - n,
  242. "SNR = %d dB\t\t", p->SNR);
  243. n += snprintf(&buf[n], PAGE_SIZE - n,
  244. "RSSI = %d dBm\t\t", p->RSSI);
  245. n += snprintf(&buf[n], PAGE_SIZE - n,
  246. "in_band_pwr = %d dBm\n", p->in_band_pwr);
  247. n += snprintf(&buf[n], PAGE_SIZE - n,
  248. "carrier_offset = %d\t", p->carrier_offset);
  249. n += snprintf(&buf[n], PAGE_SIZE - n,
  250. "bandwidth = %d\t\t", p->bandwidth);
  251. n += snprintf(&buf[n], PAGE_SIZE - n,
  252. "frequency = %d Hz\n", p->frequency);
  253. n += snprintf(&buf[n], PAGE_SIZE - n,
  254. "transmission_mode = %d\t", p->transmission_mode);
  255. n += snprintf(&buf[n], PAGE_SIZE - n,
  256. "modem_state = %d\t\t", p->modem_state);
  257. n += snprintf(&buf[n], PAGE_SIZE - n,
  258. "guard_interval = %d\n", p->guard_interval);
  259. n += snprintf(&buf[n], PAGE_SIZE - n,
  260. "system_type = %d\t\t", p->system_type);
  261. n += snprintf(&buf[n], PAGE_SIZE - n,
  262. "partial_reception = %d\t", p->partial_reception);
  263. n += snprintf(&buf[n], PAGE_SIZE - n,
  264. "num_of_layers = %d\n", p->num_of_layers);
  265. n += snprintf(&buf[n], PAGE_SIZE - n, "segment_number = %d\t",
  266. p->segment_number);
  267. n += snprintf(&buf[n], PAGE_SIZE - n, "tune_bw = %d\n",
  268. p->tune_bw);
  269. for (i = 0; i < 3; i++) {
  270. if (p->layer_info[i].number_of_segments < 1 ||
  271. p->layer_info[i].number_of_segments > 13)
  272. continue;
  273. n += snprintf(&buf[n], PAGE_SIZE - n, "\nLayer %d\n", i);
  274. n += snprintf(&buf[n], PAGE_SIZE - n, "\tcode_rate = %d\t",
  275. p->layer_info[i].code_rate);
  276. n += snprintf(&buf[n], PAGE_SIZE - n, "constellation = %d\n",
  277. p->layer_info[i].constellation);
  278. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber = %-5d\t",
  279. p->layer_info[i].ber);
  280. n += snprintf(&buf[n], PAGE_SIZE - n, "\tber_error_count = %-5d\t",
  281. p->layer_info[i].ber_error_count);
  282. n += snprintf(&buf[n], PAGE_SIZE - n, "ber_bit_count = %-5d\n",
  283. p->layer_info[i].ber_bit_count);
  284. n += snprintf(&buf[n], PAGE_SIZE - n, "\tpre_ber = %-5d\t",
  285. p->layer_info[i].pre_ber);
  286. n += snprintf(&buf[n], PAGE_SIZE - n, "\tts_per = %-5d\n",
  287. p->layer_info[i].ts_per);
  288. n += snprintf(&buf[n], PAGE_SIZE - n, "\terror_ts_packets = %-5d\t",
  289. p->layer_info[i].error_ts_packets);
  290. n += snprintf(&buf[n], PAGE_SIZE - n, "total_ts_packets = %-5d\t",
  291. p->layer_info[i].total_ts_packets);
  292. n += snprintf(&buf[n], PAGE_SIZE - n, "ti_ldepth_i = %d\n",
  293. p->layer_info[i].ti_ldepth_i);
  294. n += snprintf(&buf[n], PAGE_SIZE - n,
  295. "\tnumber_of_segments = %d\t",
  296. p->layer_info[i].number_of_segments);
  297. n += snprintf(&buf[n], PAGE_SIZE - n, "tmcc_errors = %d\n",
  298. p->layer_info[i].tmcc_errors);
  299. }
  300. debug_data->stats_count = n;
  301. spin_unlock(&debug_data->lock);
  302. wake_up(&debug_data->stats_queue);
  303. }
  304. static int smsdvb_stats_open(struct inode *inode, struct file *file)
  305. {
  306. struct smsdvb_client_t *client = inode->i_private;
  307. struct smsdvb_debugfs *debug_data = client->debug_data;
  308. kref_get(&debug_data->refcount);
  309. spin_lock(&debug_data->lock);
  310. debug_data->stats_count = 0;
  311. debug_data->stats_was_read = false;
  312. spin_unlock(&debug_data->lock);
  313. file->private_data = debug_data;
  314. return 0;
  315. }
  316. static void smsdvb_debugfs_data_release(struct kref *ref)
  317. {
  318. struct smsdvb_debugfs *debug_data;
  319. debug_data = container_of(ref, struct smsdvb_debugfs, refcount);
  320. kfree(debug_data);
  321. }
  322. static int smsdvb_stats_wait_read(struct smsdvb_debugfs *debug_data)
  323. {
  324. int rc = 1;
  325. spin_lock(&debug_data->lock);
  326. if (debug_data->stats_was_read)
  327. goto exit;
  328. rc = debug_data->stats_count;
  329. exit:
  330. spin_unlock(&debug_data->lock);
  331. return rc;
  332. }
  333. static unsigned int smsdvb_stats_poll(struct file *file, poll_table *wait)
  334. {
  335. struct smsdvb_debugfs *debug_data = file->private_data;
  336. int rc;
  337. kref_get(&debug_data->refcount);
  338. poll_wait(file, &debug_data->stats_queue, wait);
  339. rc = smsdvb_stats_wait_read(debug_data);
  340. if (rc > 0)
  341. rc = POLLIN | POLLRDNORM;
  342. kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
  343. return rc;
  344. }
  345. static ssize_t smsdvb_stats_read(struct file *file, char __user *user_buf,
  346. size_t nbytes, loff_t *ppos)
  347. {
  348. int rc = 0, len;
  349. struct smsdvb_debugfs *debug_data = file->private_data;
  350. kref_get(&debug_data->refcount);
  351. if (file->f_flags & O_NONBLOCK) {
  352. rc = smsdvb_stats_wait_read(debug_data);
  353. if (!rc) {
  354. rc = -EWOULDBLOCK;
  355. goto ret;
  356. }
  357. } else {
  358. rc = wait_event_interruptible(debug_data->stats_queue,
  359. smsdvb_stats_wait_read(debug_data));
  360. if (rc < 0)
  361. goto ret;
  362. }
  363. if (debug_data->stats_was_read) {
  364. rc = 0; /* EOF */
  365. goto ret;
  366. }
  367. len = debug_data->stats_count - *ppos;
  368. if (len >= 0)
  369. rc = simple_read_from_buffer(user_buf, nbytes, ppos,
  370. debug_data->stats_data, len);
  371. else
  372. rc = 0;
  373. if (*ppos >= debug_data->stats_count) {
  374. spin_lock(&debug_data->lock);
  375. debug_data->stats_was_read = true;
  376. spin_unlock(&debug_data->lock);
  377. }
  378. ret:
  379. kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
  380. return rc;
  381. }
  382. static int smsdvb_stats_release(struct inode *inode, struct file *file)
  383. {
  384. struct smsdvb_debugfs *debug_data = file->private_data;
  385. spin_lock(&debug_data->lock);
  386. debug_data->stats_was_read = true; /* return EOF to read() */
  387. spin_unlock(&debug_data->lock);
  388. wake_up_interruptible_sync(&debug_data->stats_queue);
  389. kref_put(&debug_data->refcount, smsdvb_debugfs_data_release);
  390. file->private_data = NULL;
  391. return 0;
  392. }
  393. static const struct file_operations debugfs_stats_ops = {
  394. .open = smsdvb_stats_open,
  395. .poll = smsdvb_stats_poll,
  396. .read = smsdvb_stats_read,
  397. .release = smsdvb_stats_release,
  398. .llseek = generic_file_llseek,
  399. };
  400. /*
  401. * Functions used by smsdvb, in order to create the interfaces
  402. */
  403. int smsdvb_debugfs_create(struct smsdvb_client_t *client)
  404. {
  405. struct smscore_device_t *coredev = client->coredev;
  406. struct dentry *d;
  407. struct smsdvb_debugfs *debug_data;
  408. if (!smsdvb_debugfs_usb_root || !coredev->is_usb_device)
  409. return -ENODEV;
  410. client->debugfs = debugfs_create_dir(coredev->devpath,
  411. smsdvb_debugfs_usb_root);
  412. if (IS_ERR_OR_NULL(client->debugfs)) {
  413. pr_info("Unable to create debugfs %s directory.\n",
  414. coredev->devpath);
  415. return -ENODEV;
  416. }
  417. d = debugfs_create_file("stats", S_IRUGO | S_IWUSR, client->debugfs,
  418. client, &debugfs_stats_ops);
  419. if (!d) {
  420. debugfs_remove(client->debugfs);
  421. return -ENOMEM;
  422. }
  423. debug_data = kzalloc(sizeof(*client->debug_data), GFP_KERNEL);
  424. if (!debug_data)
  425. return -ENOMEM;
  426. client->debug_data = debug_data;
  427. client->prt_dvb_stats = smsdvb_print_dvb_stats;
  428. client->prt_isdb_stats = smsdvb_print_isdb_stats;
  429. client->prt_isdb_stats_ex = smsdvb_print_isdb_stats_ex;
  430. init_waitqueue_head(&debug_data->stats_queue);
  431. spin_lock_init(&debug_data->lock);
  432. kref_init(&debug_data->refcount);
  433. return 0;
  434. }
  435. void smsdvb_debugfs_release(struct smsdvb_client_t *client)
  436. {
  437. if (!client->debugfs)
  438. return;
  439. client->prt_dvb_stats = NULL;
  440. client->prt_isdb_stats = NULL;
  441. client->prt_isdb_stats_ex = NULL;
  442. debugfs_remove_recursive(client->debugfs);
  443. kref_put(&client->debug_data->refcount, smsdvb_debugfs_data_release);
  444. client->debug_data = NULL;
  445. client->debugfs = NULL;
  446. }
  447. int smsdvb_debugfs_register(void)
  448. {
  449. struct dentry *d;
  450. /*
  451. * FIXME: This was written to debug Siano USB devices. So, it creates
  452. * the debugfs node under <debugfs>/usb.
  453. * A similar logic would be needed for Siano sdio devices, but, in that
  454. * case, usb_debug_root is not a good choice.
  455. *
  456. * Perhaps the right fix here would be to create another sysfs root
  457. * node for sdio-based boards, but this may need some logic at sdio
  458. * subsystem.
  459. */
  460. d = debugfs_create_dir("smsdvb", usb_debug_root);
  461. if (IS_ERR_OR_NULL(d)) {
  462. sms_err("Couldn't create sysfs node for smsdvb");
  463. return PTR_ERR(d);
  464. } else {
  465. smsdvb_debugfs_usb_root = d;
  466. }
  467. return 0;
  468. }
  469. void smsdvb_debugfs_unregister(void)
  470. {
  471. debugfs_remove_recursive(smsdvb_debugfs_usb_root);
  472. smsdvb_debugfs_usb_root = NULL;
  473. }