cxd2880_tnrdmd_mon.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * cxd2880_tnrdmd_mon.c
  4. * Sony CXD2880 DVB-T2/T tuner + demodulator driver
  5. * common monitor functions
  6. *
  7. * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
  8. */
  9. #include "cxd2880_common.h"
  10. #include "cxd2880_tnrdmd_mon.h"
  11. static const u8 rf_lvl_seq[2] = {
  12. 0x80, 0x00,
  13. };
  14. int cxd2880_tnrdmd_mon_rf_lvl(struct cxd2880_tnrdmd *tnr_dmd,
  15. int *rf_lvl_db)
  16. {
  17. u8 rdata[2];
  18. int ret;
  19. if (!tnr_dmd || !rf_lvl_db)
  20. return -EINVAL;
  21. if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
  22. return -EINVAL;
  23. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  24. CXD2880_IO_TGT_DMD,
  25. 0x00, 0x00);
  26. if (ret)
  27. return ret;
  28. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  29. CXD2880_IO_TGT_DMD,
  30. 0x10, 0x01);
  31. if (ret)
  32. return ret;
  33. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  34. CXD2880_IO_TGT_SYS,
  35. 0x00, 0x10);
  36. if (ret)
  37. return ret;
  38. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  39. CXD2880_IO_TGT_SYS,
  40. 0x5b, rf_lvl_seq, 2);
  41. if (ret)
  42. return ret;
  43. usleep_range(2000, 3000);
  44. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  45. CXD2880_IO_TGT_SYS,
  46. 0x00, 0x1a);
  47. if (ret)
  48. return ret;
  49. ret = tnr_dmd->io->read_regs(tnr_dmd->io,
  50. CXD2880_IO_TGT_SYS,
  51. 0x15, rdata, 2);
  52. if (ret)
  53. return ret;
  54. if (rdata[0] || rdata[1])
  55. return -EINVAL;
  56. ret = tnr_dmd->io->read_regs(tnr_dmd->io,
  57. CXD2880_IO_TGT_SYS,
  58. 0x11, rdata, 2);
  59. if (ret)
  60. return ret;
  61. *rf_lvl_db =
  62. cxd2880_convert2s_complement((rdata[0] << 3) |
  63. ((rdata[1] & 0xe0) >> 5), 11);
  64. *rf_lvl_db *= 125;
  65. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  66. CXD2880_IO_TGT_DMD,
  67. 0x00, 0x00);
  68. if (ret)
  69. return ret;
  70. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  71. CXD2880_IO_TGT_DMD,
  72. 0x10, 0x00);
  73. if (ret)
  74. return ret;
  75. if (tnr_dmd->rf_lvl_cmpstn)
  76. ret = tnr_dmd->rf_lvl_cmpstn(tnr_dmd, rf_lvl_db);
  77. return ret;
  78. }
  79. int cxd2880_tnrdmd_mon_rf_lvl_sub(struct cxd2880_tnrdmd *tnr_dmd,
  80. int *rf_lvl_db)
  81. {
  82. if (!tnr_dmd || !rf_lvl_db)
  83. return -EINVAL;
  84. if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
  85. return -EINVAL;
  86. return cxd2880_tnrdmd_mon_rf_lvl(tnr_dmd->diver_sub, rf_lvl_db);
  87. }
  88. int cxd2880_tnrdmd_mon_internal_cpu_status(struct cxd2880_tnrdmd
  89. *tnr_dmd, u16 *status)
  90. {
  91. u8 data[2] = { 0 };
  92. int ret;
  93. if (!tnr_dmd || !status)
  94. return -EINVAL;
  95. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  96. CXD2880_IO_TGT_SYS,
  97. 0x00, 0x1a);
  98. if (ret)
  99. return ret;
  100. ret = tnr_dmd->io->read_regs(tnr_dmd->io,
  101. CXD2880_IO_TGT_SYS,
  102. 0x15, data, 2);
  103. if (ret)
  104. return ret;
  105. *status = (data[0] << 8) | data[1];
  106. return 0;
  107. }
  108. int cxd2880_tnrdmd_mon_internal_cpu_status_sub(struct
  109. cxd2880_tnrdmd
  110. *tnr_dmd,
  111. u16 *status)
  112. {
  113. if (!tnr_dmd || !status)
  114. return -EINVAL;
  115. if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_MAIN)
  116. return -EINVAL;
  117. return cxd2880_tnrdmd_mon_internal_cpu_status(tnr_dmd->diver_sub,
  118. status);
  119. }