cxd2880_tnrdmd_dvbt.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * cxd2880_tnrdmd_dvbt.c
  4. * Sony CXD2880 DVB-T2/T tuner + demodulator driver
  5. * control functions for DVB-T
  6. *
  7. * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
  8. */
  9. #include <media/dvb_frontend.h>
  10. #include "cxd2880_tnrdmd_dvbt.h"
  11. #include "cxd2880_tnrdmd_dvbt_mon.h"
  12. static const struct cxd2880_reg_value tune_dmd_setting_seq1[] = {
  13. {0x00, 0x00}, {0x31, 0x01},
  14. };
  15. static const struct cxd2880_reg_value tune_dmd_setting_seq2[] = {
  16. {0x00, 0x04}, {0x5c, 0xfb}, {0x00, 0x10}, {0xa4, 0x03},
  17. {0x00, 0x14}, {0xb0, 0x00}, {0x00, 0x25},
  18. };
  19. static const struct cxd2880_reg_value tune_dmd_setting_seq3[] = {
  20. {0x00, 0x12}, {0x44, 0x00},
  21. };
  22. static const struct cxd2880_reg_value tune_dmd_setting_seq4[] = {
  23. {0x00, 0x11}, {0x87, 0xd2},
  24. };
  25. static const struct cxd2880_reg_value tune_dmd_setting_seq5[] = {
  26. {0x00, 0x00}, {0xfd, 0x01},
  27. };
  28. static const struct cxd2880_reg_value sleep_dmd_setting_seq1[] = {
  29. {0x00, 0x04}, {0x5c, 0xd8}, {0x00, 0x10}, {0xa4, 0x00},
  30. };
  31. static const struct cxd2880_reg_value sleep_dmd_setting_seq2[] = {
  32. {0x00, 0x11}, {0x87, 0x04},
  33. };
  34. static int x_tune_dvbt_demod_setting(struct cxd2880_tnrdmd
  35. *tnr_dmd,
  36. enum cxd2880_dtv_bandwidth
  37. bandwidth,
  38. enum cxd2880_tnrdmd_clockmode
  39. clk_mode)
  40. {
  41. static const u8 clk_mode_ckffrq_a[2] = { 0x52, 0x49 };
  42. static const u8 clk_mode_ckffrq_b[2] = { 0x5d, 0x55 };
  43. static const u8 clk_mode_ckffrq_c[2] = { 0x60, 0x00 };
  44. static const u8 ratectl_margin[2] = { 0x01, 0xf0 };
  45. static const u8 maxclkcnt_a[3] = { 0x73, 0xca, 0x49 };
  46. static const u8 maxclkcnt_b[3] = { 0xc8, 0x13, 0xaa };
  47. static const u8 maxclkcnt_c[3] = { 0xdc, 0x6c, 0x00 };
  48. static const u8 bw8_nomi_ac[5] = { 0x15, 0x00, 0x00, 0x00, 0x00};
  49. static const u8 bw8_nomi_b[5] = { 0x14, 0x6a, 0xaa, 0xaa, 0xaa};
  50. static const u8 bw8_gtdofst_a[2] = { 0x01, 0x28 };
  51. static const u8 bw8_gtdofst_b[2] = { 0x11, 0x44 };
  52. static const u8 bw8_gtdofst_c[2] = { 0x15, 0x28 };
  53. static const u8 bw8_mrc_a[5] = { 0x30, 0x00, 0x00, 0x90, 0x00 };
  54. static const u8 bw8_mrc_b[5] = { 0x36, 0x71, 0x00, 0xa3, 0x55 };
  55. static const u8 bw8_mrc_c[5] = { 0x38, 0x00, 0x00, 0xa8, 0x00 };
  56. static const u8 bw8_notch[4] = { 0xb3, 0x00, 0x01, 0x02 };
  57. static const u8 bw7_nomi_ac[5] = { 0x18, 0x00, 0x00, 0x00, 0x00};
  58. static const u8 bw7_nomi_b[5] = { 0x17, 0x55, 0x55, 0x55, 0x55};
  59. static const u8 bw7_gtdofst_a[2] = { 0x12, 0x4c };
  60. static const u8 bw7_gtdofst_b[2] = { 0x1f, 0x15 };
  61. static const u8 bw7_gtdofst_c[2] = { 0x1f, 0xf8 };
  62. static const u8 bw7_mrc_a[5] = { 0x36, 0xdb, 0x00, 0xa4, 0x92 };
  63. static const u8 bw7_mrc_b[5] = { 0x3e, 0x38, 0x00, 0xba, 0xaa };
  64. static const u8 bw7_mrc_c[5] = { 0x40, 0x00, 0x00, 0xc0, 0x00 };
  65. static const u8 bw7_notch[4] = { 0xb8, 0x00, 0x00, 0x03 };
  66. static const u8 bw6_nomi_ac[5] = { 0x1c, 0x00, 0x00, 0x00, 0x00};
  67. static const u8 bw6_nomi_b[5] = { 0x1b, 0x38, 0xe3, 0x8e, 0x38};
  68. static const u8 bw6_gtdofst_a[2] = { 0x1f, 0xf8 };
  69. static const u8 bw6_gtdofst_b[2] = { 0x24, 0x43 };
  70. static const u8 bw6_gtdofst_c[2] = { 0x25, 0x4c };
  71. static const u8 bw6_mrc_a[5] = { 0x40, 0x00, 0x00, 0xc0, 0x00 };
  72. static const u8 bw6_mrc_b[5] = { 0x48, 0x97, 0x00, 0xd9, 0xc7 };
  73. static const u8 bw6_mrc_c[5] = { 0x4a, 0xaa, 0x00, 0xdf, 0xff };
  74. static const u8 bw6_notch[4] = { 0xbe, 0xab, 0x00, 0x03 };
  75. static const u8 bw5_nomi_ac[5] = { 0x21, 0x99, 0x99, 0x99, 0x99};
  76. static const u8 bw5_nomi_b[5] = { 0x20, 0xaa, 0xaa, 0xaa, 0xaa};
  77. static const u8 bw5_gtdofst_a[2] = { 0x26, 0x5d };
  78. static const u8 bw5_gtdofst_b[2] = { 0x2b, 0x84 };
  79. static const u8 bw5_gtdofst_c[2] = { 0x2c, 0xc2 };
  80. static const u8 bw5_mrc_a[5] = { 0x4c, 0xcc, 0x00, 0xe6, 0x66 };
  81. static const u8 bw5_mrc_b[5] = { 0x57, 0x1c, 0x01, 0x05, 0x55 };
  82. static const u8 bw5_mrc_c[5] = { 0x59, 0x99, 0x01, 0x0c, 0xcc };
  83. static const u8 bw5_notch[4] = { 0xc8, 0x01, 0x00, 0x03 };
  84. const u8 *data = NULL;
  85. u8 sst_data;
  86. int ret;
  87. if (!tnr_dmd)
  88. return -EINVAL;
  89. ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
  90. CXD2880_IO_TGT_SYS,
  91. tune_dmd_setting_seq1,
  92. ARRAY_SIZE(tune_dmd_setting_seq1));
  93. if (ret)
  94. return ret;
  95. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  96. CXD2880_IO_TGT_DMD,
  97. 0x00, 0x04);
  98. if (ret)
  99. return ret;
  100. switch (clk_mode) {
  101. case CXD2880_TNRDMD_CLOCKMODE_A:
  102. data = clk_mode_ckffrq_a;
  103. break;
  104. case CXD2880_TNRDMD_CLOCKMODE_B:
  105. data = clk_mode_ckffrq_b;
  106. break;
  107. case CXD2880_TNRDMD_CLOCKMODE_C:
  108. data = clk_mode_ckffrq_c;
  109. break;
  110. default:
  111. return -EINVAL;
  112. }
  113. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  114. CXD2880_IO_TGT_DMD,
  115. 0x65, data, 2);
  116. if (ret)
  117. return ret;
  118. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  119. CXD2880_IO_TGT_DMD,
  120. 0x5d, 0x07);
  121. if (ret)
  122. return ret;
  123. if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_SUB) {
  124. u8 data[2] = { 0x01, 0x01 };
  125. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  126. CXD2880_IO_TGT_DMD,
  127. 0x00, 0x00);
  128. if (ret)
  129. return ret;
  130. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  131. CXD2880_IO_TGT_DMD,
  132. 0xce, data, 2);
  133. if (ret)
  134. return ret;
  135. }
  136. ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
  137. CXD2880_IO_TGT_DMD,
  138. tune_dmd_setting_seq2,
  139. ARRAY_SIZE(tune_dmd_setting_seq2));
  140. if (ret)
  141. return ret;
  142. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  143. CXD2880_IO_TGT_DMD,
  144. 0xf0, ratectl_margin, 2);
  145. if (ret)
  146. return ret;
  147. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN ||
  148. tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB) {
  149. ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
  150. CXD2880_IO_TGT_DMD,
  151. tune_dmd_setting_seq3,
  152. ARRAY_SIZE(tune_dmd_setting_seq3));
  153. if (ret)
  154. return ret;
  155. }
  156. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB) {
  157. ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
  158. CXD2880_IO_TGT_DMD,
  159. tune_dmd_setting_seq4,
  160. ARRAY_SIZE(tune_dmd_setting_seq4));
  161. if (ret)
  162. return ret;
  163. }
  164. if (tnr_dmd->diver_mode != CXD2880_TNRDMD_DIVERMODE_SUB) {
  165. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  166. CXD2880_IO_TGT_DMD,
  167. 0x00, 0x04);
  168. if (ret)
  169. return ret;
  170. switch (clk_mode) {
  171. case CXD2880_TNRDMD_CLOCKMODE_A:
  172. data = maxclkcnt_a;
  173. break;
  174. case CXD2880_TNRDMD_CLOCKMODE_B:
  175. data = maxclkcnt_b;
  176. break;
  177. case CXD2880_TNRDMD_CLOCKMODE_C:
  178. data = maxclkcnt_c;
  179. break;
  180. default:
  181. return -EINVAL;
  182. }
  183. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  184. CXD2880_IO_TGT_DMD,
  185. 0x68, data, 3);
  186. if (ret)
  187. return ret;
  188. }
  189. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  190. CXD2880_IO_TGT_DMD,
  191. 0x00, 0x04);
  192. if (ret)
  193. return ret;
  194. switch (bandwidth) {
  195. case CXD2880_DTV_BW_8_MHZ:
  196. switch (clk_mode) {
  197. case CXD2880_TNRDMD_CLOCKMODE_A:
  198. case CXD2880_TNRDMD_CLOCKMODE_C:
  199. data = bw8_nomi_ac;
  200. break;
  201. case CXD2880_TNRDMD_CLOCKMODE_B:
  202. data = bw8_nomi_b;
  203. break;
  204. default:
  205. return -EINVAL;
  206. }
  207. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  208. CXD2880_IO_TGT_DMD,
  209. 0x60, data, 5);
  210. if (ret)
  211. return ret;
  212. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  213. CXD2880_IO_TGT_DMD,
  214. 0x4a, 0x00);
  215. if (ret)
  216. return ret;
  217. switch (clk_mode) {
  218. case CXD2880_TNRDMD_CLOCKMODE_A:
  219. data = bw8_gtdofst_a;
  220. break;
  221. case CXD2880_TNRDMD_CLOCKMODE_B:
  222. data = bw8_gtdofst_b;
  223. break;
  224. case CXD2880_TNRDMD_CLOCKMODE_C:
  225. data = bw8_gtdofst_c;
  226. break;
  227. default:
  228. return -EINVAL;
  229. }
  230. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  231. CXD2880_IO_TGT_DMD,
  232. 0x7d, data, 2);
  233. if (ret)
  234. return ret;
  235. switch (clk_mode) {
  236. case CXD2880_TNRDMD_CLOCKMODE_A:
  237. case CXD2880_TNRDMD_CLOCKMODE_B:
  238. sst_data = 0x35;
  239. break;
  240. case CXD2880_TNRDMD_CLOCKMODE_C:
  241. sst_data = 0x34;
  242. break;
  243. default:
  244. return -EINVAL;
  245. }
  246. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  247. CXD2880_IO_TGT_DMD,
  248. 0x71, sst_data);
  249. if (ret)
  250. return ret;
  251. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
  252. switch (clk_mode) {
  253. case CXD2880_TNRDMD_CLOCKMODE_A:
  254. data = bw8_mrc_a;
  255. break;
  256. case CXD2880_TNRDMD_CLOCKMODE_B:
  257. data = bw8_mrc_b;
  258. break;
  259. case CXD2880_TNRDMD_CLOCKMODE_C:
  260. data = bw8_mrc_c;
  261. break;
  262. default:
  263. return -EINVAL;
  264. }
  265. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  266. CXD2880_IO_TGT_DMD,
  267. 0x4b, &data[0], 2);
  268. if (ret)
  269. return ret;
  270. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  271. CXD2880_IO_TGT_DMD,
  272. 0x51, &data[2], 3);
  273. if (ret)
  274. return ret;
  275. }
  276. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  277. CXD2880_IO_TGT_DMD,
  278. 0x72, &bw8_notch[0], 2);
  279. if (ret)
  280. return ret;
  281. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  282. CXD2880_IO_TGT_DMD,
  283. 0x6b, &bw8_notch[2], 2);
  284. if (ret)
  285. return ret;
  286. break;
  287. case CXD2880_DTV_BW_7_MHZ:
  288. switch (clk_mode) {
  289. case CXD2880_TNRDMD_CLOCKMODE_A:
  290. case CXD2880_TNRDMD_CLOCKMODE_C:
  291. data = bw7_nomi_ac;
  292. break;
  293. case CXD2880_TNRDMD_CLOCKMODE_B:
  294. data = bw7_nomi_b;
  295. break;
  296. default:
  297. return -EINVAL;
  298. }
  299. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  300. CXD2880_IO_TGT_DMD,
  301. 0x60, data, 5);
  302. if (ret)
  303. return ret;
  304. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  305. CXD2880_IO_TGT_DMD,
  306. 0x4a, 0x02);
  307. if (ret)
  308. return ret;
  309. switch (clk_mode) {
  310. case CXD2880_TNRDMD_CLOCKMODE_A:
  311. data = bw7_gtdofst_a;
  312. break;
  313. case CXD2880_TNRDMD_CLOCKMODE_B:
  314. data = bw7_gtdofst_b;
  315. break;
  316. case CXD2880_TNRDMD_CLOCKMODE_C:
  317. data = bw7_gtdofst_c;
  318. break;
  319. default:
  320. return -EINVAL;
  321. }
  322. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  323. CXD2880_IO_TGT_DMD,
  324. 0x7d, data, 2);
  325. if (ret)
  326. return ret;
  327. switch (clk_mode) {
  328. case CXD2880_TNRDMD_CLOCKMODE_A:
  329. case CXD2880_TNRDMD_CLOCKMODE_B:
  330. sst_data = 0x2f;
  331. break;
  332. case CXD2880_TNRDMD_CLOCKMODE_C:
  333. sst_data = 0x2e;
  334. break;
  335. default:
  336. return -EINVAL;
  337. }
  338. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  339. CXD2880_IO_TGT_DMD,
  340. 0x71, sst_data);
  341. if (ret)
  342. return ret;
  343. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
  344. switch (clk_mode) {
  345. case CXD2880_TNRDMD_CLOCKMODE_A:
  346. data = bw7_mrc_a;
  347. break;
  348. case CXD2880_TNRDMD_CLOCKMODE_B:
  349. data = bw7_mrc_b;
  350. break;
  351. case CXD2880_TNRDMD_CLOCKMODE_C:
  352. data = bw7_mrc_c;
  353. break;
  354. default:
  355. return -EINVAL;
  356. }
  357. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  358. CXD2880_IO_TGT_DMD,
  359. 0x4b, &data[0], 2);
  360. if (ret)
  361. return ret;
  362. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  363. CXD2880_IO_TGT_DMD,
  364. 0x51, &data[2], 3);
  365. if (ret)
  366. return ret;
  367. }
  368. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  369. CXD2880_IO_TGT_DMD,
  370. 0x72, &bw7_notch[0], 2);
  371. if (ret)
  372. return ret;
  373. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  374. CXD2880_IO_TGT_DMD,
  375. 0x6b, &bw7_notch[2], 2);
  376. if (ret)
  377. return ret;
  378. break;
  379. case CXD2880_DTV_BW_6_MHZ:
  380. switch (clk_mode) {
  381. case CXD2880_TNRDMD_CLOCKMODE_A:
  382. case CXD2880_TNRDMD_CLOCKMODE_C:
  383. data = bw6_nomi_ac;
  384. break;
  385. case CXD2880_TNRDMD_CLOCKMODE_B:
  386. data = bw6_nomi_b;
  387. break;
  388. default:
  389. return -EINVAL;
  390. }
  391. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  392. CXD2880_IO_TGT_DMD,
  393. 0x60, data, 5);
  394. if (ret)
  395. return ret;
  396. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  397. CXD2880_IO_TGT_DMD,
  398. 0x4a, 0x04);
  399. if (ret)
  400. return ret;
  401. switch (clk_mode) {
  402. case CXD2880_TNRDMD_CLOCKMODE_A:
  403. data = bw6_gtdofst_a;
  404. break;
  405. case CXD2880_TNRDMD_CLOCKMODE_B:
  406. data = bw6_gtdofst_b;
  407. break;
  408. case CXD2880_TNRDMD_CLOCKMODE_C:
  409. data = bw6_gtdofst_c;
  410. break;
  411. default:
  412. return -EINVAL;
  413. }
  414. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  415. CXD2880_IO_TGT_DMD,
  416. 0x7d, data, 2);
  417. if (ret)
  418. return ret;
  419. switch (clk_mode) {
  420. case CXD2880_TNRDMD_CLOCKMODE_A:
  421. case CXD2880_TNRDMD_CLOCKMODE_C:
  422. sst_data = 0x29;
  423. break;
  424. case CXD2880_TNRDMD_CLOCKMODE_B:
  425. sst_data = 0x2a;
  426. break;
  427. default:
  428. return -EINVAL;
  429. }
  430. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  431. CXD2880_IO_TGT_DMD,
  432. 0x71, sst_data);
  433. if (ret)
  434. return ret;
  435. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
  436. switch (clk_mode) {
  437. case CXD2880_TNRDMD_CLOCKMODE_A:
  438. data = bw6_mrc_a;
  439. break;
  440. case CXD2880_TNRDMD_CLOCKMODE_B:
  441. data = bw6_mrc_b;
  442. break;
  443. case CXD2880_TNRDMD_CLOCKMODE_C:
  444. data = bw6_mrc_c;
  445. break;
  446. default:
  447. return -EINVAL;
  448. }
  449. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  450. CXD2880_IO_TGT_DMD,
  451. 0x4b, &data[0], 2);
  452. if (ret)
  453. return ret;
  454. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  455. CXD2880_IO_TGT_DMD,
  456. 0x51, &data[2], 3);
  457. if (ret)
  458. return ret;
  459. }
  460. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  461. CXD2880_IO_TGT_DMD,
  462. 0x72, &bw6_notch[0], 2);
  463. if (ret)
  464. return ret;
  465. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  466. CXD2880_IO_TGT_DMD,
  467. 0x6b, &bw6_notch[2], 2);
  468. if (ret)
  469. return ret;
  470. break;
  471. case CXD2880_DTV_BW_5_MHZ:
  472. switch (clk_mode) {
  473. case CXD2880_TNRDMD_CLOCKMODE_A:
  474. case CXD2880_TNRDMD_CLOCKMODE_C:
  475. data = bw5_nomi_ac;
  476. break;
  477. case CXD2880_TNRDMD_CLOCKMODE_B:
  478. data = bw5_nomi_b;
  479. break;
  480. default:
  481. return -EINVAL;
  482. }
  483. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  484. CXD2880_IO_TGT_DMD,
  485. 0x60, data, 5);
  486. if (ret)
  487. return ret;
  488. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  489. CXD2880_IO_TGT_DMD,
  490. 0x4a, 0x06);
  491. if (ret)
  492. return ret;
  493. switch (clk_mode) {
  494. case CXD2880_TNRDMD_CLOCKMODE_A:
  495. data = bw5_gtdofst_a;
  496. break;
  497. case CXD2880_TNRDMD_CLOCKMODE_B:
  498. data = bw5_gtdofst_b;
  499. break;
  500. case CXD2880_TNRDMD_CLOCKMODE_C:
  501. data = bw5_gtdofst_c;
  502. break;
  503. default:
  504. return -EINVAL;
  505. }
  506. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  507. CXD2880_IO_TGT_DMD,
  508. 0x7d, data, 2);
  509. if (ret)
  510. return ret;
  511. switch (clk_mode) {
  512. case CXD2880_TNRDMD_CLOCKMODE_A:
  513. case CXD2880_TNRDMD_CLOCKMODE_B:
  514. sst_data = 0x24;
  515. break;
  516. case CXD2880_TNRDMD_CLOCKMODE_C:
  517. sst_data = 0x23;
  518. break;
  519. default:
  520. return -EINVAL;
  521. }
  522. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  523. CXD2880_IO_TGT_DMD,
  524. 0x71, sst_data);
  525. if (ret)
  526. return ret;
  527. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
  528. switch (clk_mode) {
  529. case CXD2880_TNRDMD_CLOCKMODE_A:
  530. data = bw5_mrc_a;
  531. break;
  532. case CXD2880_TNRDMD_CLOCKMODE_B:
  533. data = bw5_mrc_b;
  534. break;
  535. case CXD2880_TNRDMD_CLOCKMODE_C:
  536. data = bw5_mrc_c;
  537. break;
  538. default:
  539. return -EINVAL;
  540. }
  541. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  542. CXD2880_IO_TGT_DMD,
  543. 0x4b, &data[0], 2);
  544. if (ret)
  545. return ret;
  546. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  547. CXD2880_IO_TGT_DMD,
  548. 0x51, &data[2], 3);
  549. if (ret)
  550. return ret;
  551. }
  552. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  553. CXD2880_IO_TGT_DMD,
  554. 0x72, &bw5_notch[0], 2);
  555. if (ret)
  556. return ret;
  557. ret = tnr_dmd->io->write_regs(tnr_dmd->io,
  558. CXD2880_IO_TGT_DMD,
  559. 0x6b, &bw5_notch[2], 2);
  560. if (ret)
  561. return ret;
  562. break;
  563. default:
  564. return -EINVAL;
  565. }
  566. return cxd2880_io_write_multi_regs(tnr_dmd->io,
  567. CXD2880_IO_TGT_DMD,
  568. tune_dmd_setting_seq5,
  569. ARRAY_SIZE(tune_dmd_setting_seq5));
  570. }
  571. static int x_sleep_dvbt_demod_setting(struct cxd2880_tnrdmd
  572. *tnr_dmd)
  573. {
  574. int ret;
  575. if (!tnr_dmd)
  576. return -EINVAL;
  577. ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
  578. CXD2880_IO_TGT_DMD,
  579. sleep_dmd_setting_seq1,
  580. ARRAY_SIZE(sleep_dmd_setting_seq1));
  581. if (ret)
  582. return ret;
  583. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
  584. ret = cxd2880_io_write_multi_regs(tnr_dmd->io,
  585. CXD2880_IO_TGT_DMD,
  586. sleep_dmd_setting_seq2,
  587. ARRAY_SIZE(sleep_dmd_setting_seq2));
  588. return ret;
  589. }
  590. static int dvbt_set_profile(struct cxd2880_tnrdmd *tnr_dmd,
  591. enum cxd2880_dvbt_profile profile)
  592. {
  593. int ret;
  594. if (!tnr_dmd)
  595. return -EINVAL;
  596. ret = tnr_dmd->io->write_reg(tnr_dmd->io,
  597. CXD2880_IO_TGT_DMD,
  598. 0x00, 0x10);
  599. if (ret)
  600. return ret;
  601. return tnr_dmd->io->write_reg(tnr_dmd->io,
  602. CXD2880_IO_TGT_DMD,
  603. 0x67,
  604. (profile == CXD2880_DVBT_PROFILE_HP)
  605. ? 0x00 : 0x01);
  606. }
  607. int cxd2880_tnrdmd_dvbt_tune1(struct cxd2880_tnrdmd *tnr_dmd,
  608. struct cxd2880_dvbt_tune_param
  609. *tune_param)
  610. {
  611. int ret;
  612. if (!tnr_dmd || !tune_param)
  613. return -EINVAL;
  614. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
  615. return -EINVAL;
  616. if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
  617. tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
  618. return -EINVAL;
  619. ret =
  620. cxd2880_tnrdmd_common_tune_setting1(tnr_dmd, CXD2880_DTV_SYS_DVBT,
  621. tune_param->center_freq_khz,
  622. tune_param->bandwidth, 0, 0);
  623. if (ret)
  624. return ret;
  625. ret =
  626. x_tune_dvbt_demod_setting(tnr_dmd, tune_param->bandwidth,
  627. tnr_dmd->clk_mode);
  628. if (ret)
  629. return ret;
  630. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
  631. ret =
  632. x_tune_dvbt_demod_setting(tnr_dmd->diver_sub,
  633. tune_param->bandwidth,
  634. tnr_dmd->diver_sub->clk_mode);
  635. if (ret)
  636. return ret;
  637. }
  638. return dvbt_set_profile(tnr_dmd, tune_param->profile);
  639. }
  640. int cxd2880_tnrdmd_dvbt_tune2(struct cxd2880_tnrdmd *tnr_dmd,
  641. struct cxd2880_dvbt_tune_param
  642. *tune_param)
  643. {
  644. int ret;
  645. if (!tnr_dmd || !tune_param)
  646. return -EINVAL;
  647. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
  648. return -EINVAL;
  649. if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
  650. tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
  651. return -EINVAL;
  652. ret =
  653. cxd2880_tnrdmd_common_tune_setting2(tnr_dmd, CXD2880_DTV_SYS_DVBT,
  654. 0);
  655. if (ret)
  656. return ret;
  657. tnr_dmd->state = CXD2880_TNRDMD_STATE_ACTIVE;
  658. tnr_dmd->frequency_khz = tune_param->center_freq_khz;
  659. tnr_dmd->sys = CXD2880_DTV_SYS_DVBT;
  660. tnr_dmd->bandwidth = tune_param->bandwidth;
  661. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN) {
  662. tnr_dmd->diver_sub->state = CXD2880_TNRDMD_STATE_ACTIVE;
  663. tnr_dmd->diver_sub->frequency_khz = tune_param->center_freq_khz;
  664. tnr_dmd->diver_sub->sys = CXD2880_DTV_SYS_DVBT;
  665. tnr_dmd->diver_sub->bandwidth = tune_param->bandwidth;
  666. }
  667. return 0;
  668. }
  669. int cxd2880_tnrdmd_dvbt_sleep_setting(struct cxd2880_tnrdmd *tnr_dmd)
  670. {
  671. int ret;
  672. if (!tnr_dmd)
  673. return -EINVAL;
  674. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
  675. return -EINVAL;
  676. if (tnr_dmd->state != CXD2880_TNRDMD_STATE_SLEEP &&
  677. tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
  678. return -EINVAL;
  679. ret = x_sleep_dvbt_demod_setting(tnr_dmd);
  680. if (ret)
  681. return ret;
  682. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_MAIN)
  683. ret = x_sleep_dvbt_demod_setting(tnr_dmd->diver_sub);
  684. return ret;
  685. }
  686. int cxd2880_tnrdmd_dvbt_check_demod_lock(struct cxd2880_tnrdmd
  687. *tnr_dmd,
  688. enum
  689. cxd2880_tnrdmd_lock_result
  690. *lock)
  691. {
  692. int ret;
  693. u8 sync_stat = 0;
  694. u8 ts_lock = 0;
  695. u8 unlock_detected = 0;
  696. u8 unlock_detected_sub = 0;
  697. if (!tnr_dmd || !lock)
  698. return -EINVAL;
  699. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
  700. return -EINVAL;
  701. if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
  702. return -EINVAL;
  703. ret =
  704. cxd2880_tnrdmd_dvbt_mon_sync_stat(tnr_dmd, &sync_stat, &ts_lock,
  705. &unlock_detected);
  706. if (ret)
  707. return ret;
  708. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SINGLE) {
  709. if (sync_stat == 6)
  710. *lock = CXD2880_TNRDMD_LOCK_RESULT_LOCKED;
  711. else if (unlock_detected)
  712. *lock = CXD2880_TNRDMD_LOCK_RESULT_UNLOCKED;
  713. else
  714. *lock = CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
  715. return ret;
  716. }
  717. if (sync_stat == 6) {
  718. *lock = CXD2880_TNRDMD_LOCK_RESULT_LOCKED;
  719. return ret;
  720. }
  721. ret =
  722. cxd2880_tnrdmd_dvbt_mon_sync_stat_sub(tnr_dmd, &sync_stat,
  723. &unlock_detected_sub);
  724. if (ret)
  725. return ret;
  726. if (sync_stat == 6)
  727. *lock = CXD2880_TNRDMD_LOCK_RESULT_LOCKED;
  728. else if (unlock_detected && unlock_detected_sub)
  729. *lock = CXD2880_TNRDMD_LOCK_RESULT_UNLOCKED;
  730. else
  731. *lock = CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
  732. return ret;
  733. }
  734. int cxd2880_tnrdmd_dvbt_check_ts_lock(struct cxd2880_tnrdmd
  735. *tnr_dmd,
  736. enum
  737. cxd2880_tnrdmd_lock_result
  738. *lock)
  739. {
  740. int ret;
  741. u8 sync_stat = 0;
  742. u8 ts_lock = 0;
  743. u8 unlock_detected = 0;
  744. u8 unlock_detected_sub = 0;
  745. if (!tnr_dmd || !lock)
  746. return -EINVAL;
  747. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SUB)
  748. return -EINVAL;
  749. if (tnr_dmd->state != CXD2880_TNRDMD_STATE_ACTIVE)
  750. return -EINVAL;
  751. ret =
  752. cxd2880_tnrdmd_dvbt_mon_sync_stat(tnr_dmd, &sync_stat, &ts_lock,
  753. &unlock_detected);
  754. if (ret)
  755. return ret;
  756. if (tnr_dmd->diver_mode == CXD2880_TNRDMD_DIVERMODE_SINGLE) {
  757. if (ts_lock)
  758. *lock = CXD2880_TNRDMD_LOCK_RESULT_LOCKED;
  759. else if (unlock_detected)
  760. *lock = CXD2880_TNRDMD_LOCK_RESULT_UNLOCKED;
  761. else
  762. *lock = CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
  763. return ret;
  764. }
  765. if (ts_lock) {
  766. *lock = CXD2880_TNRDMD_LOCK_RESULT_LOCKED;
  767. return ret;
  768. } else if (!unlock_detected) {
  769. *lock = CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
  770. return ret;
  771. }
  772. ret =
  773. cxd2880_tnrdmd_dvbt_mon_sync_stat_sub(tnr_dmd, &sync_stat,
  774. &unlock_detected_sub);
  775. if (ret)
  776. return ret;
  777. if (unlock_detected && unlock_detected_sub)
  778. *lock = CXD2880_TNRDMD_LOCK_RESULT_UNLOCKED;
  779. else
  780. *lock = CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT;
  781. return ret;
  782. }