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