xref: /linux/drivers/media/tuners/e4000_priv.h (revision 3932b9ca55b0be314a36d3e84faff3e823c081f5)
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 
21 #ifndef E4000_PRIV_H
22 #define E4000_PRIV_H
23 
24 #include "e4000.h"
25 #include <media/v4l2-ctrls.h>
26 #include <media/v4l2-subdev.h>
27 #include <linux/regmap.h>
28 
29 struct e4000 {
30 	struct i2c_client *client;
31 	struct regmap *regmap;
32 	u32 clock;
33 	struct dvb_frontend *fe;
34 	struct v4l2_subdev sd;
35 	bool active;
36 
37 	/* Controls */
38 	struct v4l2_ctrl_handler hdl;
39 	struct v4l2_ctrl *bandwidth_auto;
40 	struct v4l2_ctrl *bandwidth;
41 	struct v4l2_ctrl *lna_gain_auto;
42 	struct v4l2_ctrl *lna_gain;
43 	struct v4l2_ctrl *mixer_gain_auto;
44 	struct v4l2_ctrl *mixer_gain;
45 	struct v4l2_ctrl *if_gain_auto;
46 	struct v4l2_ctrl *if_gain;
47 	struct v4l2_ctrl *pll_lock;
48 };
49 
50 struct e4000_pll {
51 	u32 freq;
52 	u8 div;
53 	u8 mul;
54 };
55 
56 static const struct e4000_pll e4000_pll_lut[] = {
57 /*                                      VCO min    VCO max */
58 	{   72400000, 0x0f, 48 }, /* .......... 3475200000 */
59 	{   81200000, 0x0e, 40 }, /* 2896000000 3248000000 */
60 	{  108300000, 0x0d, 32 }, /* 2598400000 3465600000 */
61 	{  162500000, 0x0c, 24 }, /* 2599200000 3900000000 */
62 	{  216600000, 0x0b, 16 }, /* 2600000000 3465600000 */
63 	{  325000000, 0x0a, 12 }, /* 2599200000 3900000000 */
64 	{  350000000, 0x09,  8 }, /* 2600000000 2800000000 */
65 	{  432000000, 0x03,  8 }, /* 2800000000 3456000000 */
66 	{  667000000, 0x02,  6 }, /* 2592000000 4002000000 */
67 	{ 1200000000, 0x01,  4 }, /* 2668000000 4800000000 */
68 	{ 0xffffffff, 0x00,  2 }, /* 2400000000 .......... */
69 };
70 
71 struct e4000_lna_filter {
72 	u32 freq;
73 	u8 val;
74 };
75 
76 static const struct e4000_lna_filter e400_lna_filter_lut[] = {
77 	{  370000000,  0 },
78 	{  392500000,  1 },
79 	{  415000000,  2 },
80 	{  437500000,  3 },
81 	{  462500000,  4 },
82 	{  490000000,  5 },
83 	{  522500000,  6 },
84 	{  557500000,  7 },
85 	{  595000000,  8 },
86 	{  642500000,  9 },
87 	{  695000000, 10 },
88 	{  740000000, 11 },
89 	{  800000000, 12 },
90 	{  865000000, 13 },
91 	{  930000000, 14 },
92 	{ 1000000000, 15 },
93 	{ 1310000000,  0 },
94 	{ 1340000000,  1 },
95 	{ 1385000000,  2 },
96 	{ 1427500000,  3 },
97 	{ 1452500000,  4 },
98 	{ 1475000000,  5 },
99 	{ 1510000000,  6 },
100 	{ 1545000000,  7 },
101 	{ 1575000000,  8 },
102 	{ 1615000000,  9 },
103 	{ 1650000000, 10 },
104 	{ 1670000000, 11 },
105 	{ 1690000000, 12 },
106 	{ 1710000000, 13 },
107 	{ 1735000000, 14 },
108 	{ 0xffffffff, 15 },
109 };
110 
111 struct e4000_band {
112 	u32 freq;
113 	u8 reg07_val;
114 	u8 reg78_val;
115 };
116 
117 static const struct e4000_band e4000_band_lut[] = {
118 	{  140000000, 0x01, 0x03 },
119 	{  350000000, 0x03, 0x03 },
120 	{ 1000000000, 0x05, 0x03 },
121 	{ 0xffffffff, 0x07, 0x00 },
122 };
123 
124 struct e4000_if_filter {
125 	u32 freq;
126 	u8 reg11_val;
127 	u8 reg12_val;
128 };
129 
130 static const struct e4000_if_filter e4000_if_filter_lut[] = {
131 	{    4300000, 0xfd, 0x1f },
132 	{    4400000, 0xfd, 0x1e },
133 	{    4480000, 0xfc, 0x1d },
134 	{    4560000, 0xfc, 0x1c },
135 	{    4600000, 0xfc, 0x1b },
136 	{    4800000, 0xfc, 0x1a },
137 	{    4900000, 0xfc, 0x19 },
138 	{    5000000, 0xfc, 0x18 },
139 	{    5100000, 0xfc, 0x17 },
140 	{    5200000, 0xfc, 0x16 },
141 	{    5400000, 0xfc, 0x15 },
142 	{    5500000, 0xfc, 0x14 },
143 	{    5600000, 0xfc, 0x13 },
144 	{    5800000, 0xfb, 0x12 },
145 	{    5900000, 0xfb, 0x11 },
146 	{    6000000, 0xfb, 0x10 },
147 	{    6200000, 0xfb, 0x0f },
148 	{    6400000, 0xfa, 0x0e },
149 	{    6600000, 0xfa, 0x0d },
150 	{    6800000, 0xf9, 0x0c },
151 	{    7200000, 0xf9, 0x0b },
152 	{    7400000, 0xf9, 0x0a },
153 	{    7600000, 0xf8, 0x09 },
154 	{    7800000, 0xf8, 0x08 },
155 	{    8200000, 0xf8, 0x07 },
156 	{    8600000, 0xf7, 0x06 },
157 	{    8800000, 0xf7, 0x05 },
158 	{    9200000, 0xf7, 0x04 },
159 	{    9600000, 0xf6, 0x03 },
160 	{   10000000, 0xf6, 0x02 },
161 	{   10600000, 0xf5, 0x01 },
162 	{   11000000, 0xf5, 0x00 },
163 	{ 0xffffffff, 0x00, 0x20 },
164 };
165 
166 struct e4000_if_gain {
167 	u8 reg16_val;
168 	u8 reg17_val;
169 };
170 
171 static const struct e4000_if_gain e4000_if_gain_lut[] = {
172 	{0x00, 0x00},
173 	{0x20, 0x00},
174 	{0x40, 0x00},
175 	{0x02, 0x00},
176 	{0x22, 0x00},
177 	{0x42, 0x00},
178 	{0x04, 0x00},
179 	{0x24, 0x00},
180 	{0x44, 0x00},
181 	{0x01, 0x00},
182 	{0x21, 0x00},
183 	{0x41, 0x00},
184 	{0x03, 0x00},
185 	{0x23, 0x00},
186 	{0x43, 0x00},
187 	{0x05, 0x00},
188 	{0x25, 0x00},
189 	{0x45, 0x00},
190 	{0x07, 0x00},
191 	{0x27, 0x00},
192 	{0x47, 0x00},
193 	{0x0f, 0x00},
194 	{0x2f, 0x00},
195 	{0x4f, 0x00},
196 	{0x17, 0x00},
197 	{0x37, 0x00},
198 	{0x57, 0x00},
199 	{0x1f, 0x00},
200 	{0x3f, 0x00},
201 	{0x5f, 0x00},
202 	{0x1f, 0x01},
203 	{0x3f, 0x01},
204 	{0x5f, 0x01},
205 	{0x1f, 0x02},
206 	{0x3f, 0x02},
207 	{0x5f, 0x02},
208 	{0x1f, 0x03},
209 	{0x3f, 0x03},
210 	{0x5f, 0x03},
211 	{0x1f, 0x04},
212 	{0x3f, 0x04},
213 	{0x5f, 0x04},
214 	{0x1f, 0x0c},
215 	{0x3f, 0x0c},
216 	{0x5f, 0x0c},
217 	{0x1f, 0x14},
218 	{0x3f, 0x14},
219 	{0x5f, 0x14},
220 	{0x1f, 0x1c},
221 	{0x3f, 0x1c},
222 	{0x5f, 0x1c},
223 	{0x1f, 0x24},
224 	{0x3f, 0x24},
225 	{0x5f, 0x24},
226 	{0x7f, 0x24},
227 };
228 
229 #endif
230