e4000_priv.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * Elonics E4000 silicon tuner driver
  3. *
  4. * Copyright (C) 2012 Antti Palosaari <crope@iki.fi>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. */
  20. #ifndef E4000_PRIV_H
  21. #define E4000_PRIV_H
  22. #include "e4000.h"
  23. #include <linux/math64.h>
  24. #include <media/v4l2-ctrls.h>
  25. #include <media/v4l2-subdev.h>
  26. #include <linux/regmap.h>
  27. struct e4000_dev {
  28. struct i2c_client *client;
  29. struct regmap *regmap;
  30. u32 clk;
  31. struct dvb_frontend *fe;
  32. struct v4l2_subdev sd;
  33. bool active;
  34. unsigned int f_frequency;
  35. unsigned int f_bandwidth;
  36. /* Controls */
  37. struct v4l2_ctrl_handler hdl;
  38. struct v4l2_ctrl *bandwidth_auto;
  39. struct v4l2_ctrl *bandwidth;
  40. struct v4l2_ctrl *lna_gain_auto;
  41. struct v4l2_ctrl *lna_gain;
  42. struct v4l2_ctrl *mixer_gain_auto;
  43. struct v4l2_ctrl *mixer_gain;
  44. struct v4l2_ctrl *if_gain_auto;
  45. struct v4l2_ctrl *if_gain;
  46. struct v4l2_ctrl *pll_lock;
  47. };
  48. struct e4000_pll {
  49. u32 freq;
  50. u8 div_out_reg;
  51. u8 div_out;
  52. };
  53. static const struct e4000_pll e4000_pll_lut[] = {
  54. /* VCO min VCO max */
  55. { 72400000, 0x0f, 48 }, /* .......... 3475200000 */
  56. { 81200000, 0x0e, 40 }, /* 2896000000 3248000000 */
  57. { 108300000, 0x0d, 32 }, /* 2598400000 3465600000 */
  58. { 162500000, 0x0c, 24 }, /* 2599200000 3900000000 */
  59. { 216600000, 0x0b, 16 }, /* 2600000000 3465600000 */
  60. { 325000000, 0x0a, 12 }, /* 2599200000 3900000000 */
  61. { 350000000, 0x09, 8 }, /* 2600000000 2800000000 */
  62. { 432000000, 0x03, 8 }, /* 2800000000 3456000000 */
  63. { 667000000, 0x02, 6 }, /* 2592000000 4002000000 */
  64. { 1200000000, 0x01, 4 }, /* 2668000000 4800000000 */
  65. { 0xffffffff, 0x00, 2 }, /* 2400000000 .......... */
  66. };
  67. struct e4000_lna_filter {
  68. u32 freq;
  69. u8 val;
  70. };
  71. static const struct e4000_lna_filter e400_lna_filter_lut[] = {
  72. { 370000000, 0 },
  73. { 392500000, 1 },
  74. { 415000000, 2 },
  75. { 437500000, 3 },
  76. { 462500000, 4 },
  77. { 490000000, 5 },
  78. { 522500000, 6 },
  79. { 557500000, 7 },
  80. { 595000000, 8 },
  81. { 642500000, 9 },
  82. { 695000000, 10 },
  83. { 740000000, 11 },
  84. { 800000000, 12 },
  85. { 865000000, 13 },
  86. { 930000000, 14 },
  87. { 1000000000, 15 },
  88. { 1310000000, 0 },
  89. { 1340000000, 1 },
  90. { 1385000000, 2 },
  91. { 1427500000, 3 },
  92. { 1452500000, 4 },
  93. { 1475000000, 5 },
  94. { 1510000000, 6 },
  95. { 1545000000, 7 },
  96. { 1575000000, 8 },
  97. { 1615000000, 9 },
  98. { 1650000000, 10 },
  99. { 1670000000, 11 },
  100. { 1690000000, 12 },
  101. { 1710000000, 13 },
  102. { 1735000000, 14 },
  103. { 0xffffffff, 15 },
  104. };
  105. struct e4000_band {
  106. u32 freq;
  107. u8 reg07_val;
  108. u8 reg78_val;
  109. };
  110. static const struct e4000_band e4000_band_lut[] = {
  111. { 140000000, 0x01, 0x03 },
  112. { 350000000, 0x03, 0x03 },
  113. { 1000000000, 0x05, 0x03 },
  114. { 0xffffffff, 0x07, 0x00 },
  115. };
  116. struct e4000_if_filter {
  117. u32 freq;
  118. u8 reg11_val;
  119. u8 reg12_val;
  120. };
  121. static const struct e4000_if_filter e4000_if_filter_lut[] = {
  122. { 4300000, 0xfd, 0x1f },
  123. { 4400000, 0xfd, 0x1e },
  124. { 4480000, 0xfc, 0x1d },
  125. { 4560000, 0xfc, 0x1c },
  126. { 4600000, 0xfc, 0x1b },
  127. { 4800000, 0xfc, 0x1a },
  128. { 4900000, 0xfc, 0x19 },
  129. { 5000000, 0xfc, 0x18 },
  130. { 5100000, 0xfc, 0x17 },
  131. { 5200000, 0xfc, 0x16 },
  132. { 5400000, 0xfc, 0x15 },
  133. { 5500000, 0xfc, 0x14 },
  134. { 5600000, 0xfc, 0x13 },
  135. { 5800000, 0xfb, 0x12 },
  136. { 5900000, 0xfb, 0x11 },
  137. { 6000000, 0xfb, 0x10 },
  138. { 6200000, 0xfb, 0x0f },
  139. { 6400000, 0xfa, 0x0e },
  140. { 6600000, 0xfa, 0x0d },
  141. { 6800000, 0xf9, 0x0c },
  142. { 7200000, 0xf9, 0x0b },
  143. { 7400000, 0xf9, 0x0a },
  144. { 7600000, 0xf8, 0x09 },
  145. { 7800000, 0xf8, 0x08 },
  146. { 8200000, 0xf8, 0x07 },
  147. { 8600000, 0xf7, 0x06 },
  148. { 8800000, 0xf7, 0x05 },
  149. { 9200000, 0xf7, 0x04 },
  150. { 9600000, 0xf6, 0x03 },
  151. { 10000000, 0xf6, 0x02 },
  152. { 10600000, 0xf5, 0x01 },
  153. { 11000000, 0xf5, 0x00 },
  154. { 0xffffffff, 0x00, 0x20 },
  155. };
  156. struct e4000_if_gain {
  157. u8 reg16_val;
  158. u8 reg17_val;
  159. };
  160. static const struct e4000_if_gain e4000_if_gain_lut[] = {
  161. {0x00, 0x00},
  162. {0x20, 0x00},
  163. {0x40, 0x00},
  164. {0x02, 0x00},
  165. {0x22, 0x00},
  166. {0x42, 0x00},
  167. {0x04, 0x00},
  168. {0x24, 0x00},
  169. {0x44, 0x00},
  170. {0x01, 0x00},
  171. {0x21, 0x00},
  172. {0x41, 0x00},
  173. {0x03, 0x00},
  174. {0x23, 0x00},
  175. {0x43, 0x00},
  176. {0x05, 0x00},
  177. {0x25, 0x00},
  178. {0x45, 0x00},
  179. {0x07, 0x00},
  180. {0x27, 0x00},
  181. {0x47, 0x00},
  182. {0x0f, 0x00},
  183. {0x2f, 0x00},
  184. {0x4f, 0x00},
  185. {0x17, 0x00},
  186. {0x37, 0x00},
  187. {0x57, 0x00},
  188. {0x1f, 0x00},
  189. {0x3f, 0x00},
  190. {0x5f, 0x00},
  191. {0x1f, 0x01},
  192. {0x3f, 0x01},
  193. {0x5f, 0x01},
  194. {0x1f, 0x02},
  195. {0x3f, 0x02},
  196. {0x5f, 0x02},
  197. {0x1f, 0x03},
  198. {0x3f, 0x03},
  199. {0x5f, 0x03},
  200. {0x1f, 0x04},
  201. {0x3f, 0x04},
  202. {0x5f, 0x04},
  203. {0x1f, 0x0c},
  204. {0x3f, 0x0c},
  205. {0x5f, 0x0c},
  206. {0x1f, 0x14},
  207. {0x3f, 0x14},
  208. {0x5f, 0x14},
  209. {0x1f, 0x1c},
  210. {0x3f, 0x1c},
  211. {0x5f, 0x1c},
  212. {0x1f, 0x24},
  213. {0x3f, 0x24},
  214. {0x5f, 0x24},
  215. {0x7f, 0x24},
  216. };
  217. #endif