1 /*
2  * Montage M88DS3103 demodulator driver
3  *
4  * Copyright (C) 2013 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 
17 #ifndef M88DS3103_PRIV_H
18 #define M88DS3103_PRIV_H
19 
20 #include "dvb_frontend.h"
21 #include "m88ds3103.h"
22 #include "dvb_math.h"
23 #include <linux/firmware.h>
24 #include <linux/i2c-mux.h>
25 #include <linux/math64.h>
26 
27 #define M88DS3103_FIRMWARE "dvb-demod-m88ds3103.fw"
28 #define M88RS6000_FIRMWARE "dvb-demod-m88rs6000.fw"
29 #define M88DS3103_MCLK_KHZ 96000
30 #define M88RS6000_CHIP_ID 0x74
31 #define M88DS3103_CHIP_ID 0x70
32 
33 struct m88ds3103_priv {
34 	struct i2c_adapter *i2c;
35 	/* mutex needed due to own tuner I2C adapter */
36 	struct mutex i2c_mutex;
37 	const struct m88ds3103_config *cfg;
38 	struct dvb_frontend fe;
39 	fe_delivery_system_t delivery_system;
40 	fe_status_t fe_status;
41 	u32 ber;
42 	bool warm; /* FW running */
43 	struct i2c_adapter *i2c_adapter;
44 	/* auto detect chip id to do different config */
45 	u8 chip_id;
46 	/* main mclk is calculated for M88RS6000 dynamically */
47 	u32 mclk_khz;
48 };
49 
50 struct m88ds3103_reg_val {
51 	u8 reg;
52 	u8 val;
53 };
54 
55 static const struct m88ds3103_reg_val m88ds3103_dvbs_init_reg_vals[] = {
56 	{0x23, 0x07},
57 	{0x08, 0x03},
58 	{0x0c, 0x02},
59 	{0x21, 0x54},
60 	{0x25, 0x8a},
61 	{0x27, 0x31},
62 	{0x30, 0x08},
63 	{0x31, 0x40},
64 	{0x32, 0x32},
65 	{0x35, 0xff},
66 	{0x3a, 0x00},
67 	{0x37, 0x10},
68 	{0x38, 0x10},
69 	{0x39, 0x02},
70 	{0x42, 0x60},
71 	{0x4a, 0x80},
72 	{0x4b, 0x04},
73 	{0x4d, 0x91},
74 	{0x5d, 0xc8},
75 	{0x50, 0x36},
76 	{0x51, 0x36},
77 	{0x52, 0x36},
78 	{0x53, 0x36},
79 	{0x56, 0x01},
80 	{0x63, 0x0f},
81 	{0x64, 0x30},
82 	{0x65, 0x40},
83 	{0x68, 0x26},
84 	{0x69, 0x4c},
85 	{0x70, 0x20},
86 	{0x71, 0x70},
87 	{0x72, 0x04},
88 	{0x73, 0x00},
89 	{0x70, 0x40},
90 	{0x71, 0x70},
91 	{0x72, 0x04},
92 	{0x73, 0x00},
93 	{0x70, 0x60},
94 	{0x71, 0x70},
95 	{0x72, 0x04},
96 	{0x73, 0x00},
97 	{0x70, 0x80},
98 	{0x71, 0x70},
99 	{0x72, 0x04},
100 	{0x73, 0x00},
101 	{0x70, 0xa0},
102 	{0x71, 0x70},
103 	{0x72, 0x04},
104 	{0x73, 0x00},
105 	{0x70, 0x1f},
106 	{0x76, 0x38},
107 	{0x77, 0xa6},
108 	{0x78, 0x0c},
109 	{0x79, 0x80},
110 	{0x7f, 0x14},
111 	{0x7c, 0x00},
112 	{0xae, 0x82},
113 	{0x80, 0x64},
114 	{0x81, 0x66},
115 	{0x82, 0x44},
116 	{0x85, 0x04},
117 	{0xcd, 0xf4},
118 	{0x90, 0x33},
119 	{0xa0, 0x44},
120 	{0xc0, 0x08},
121 	{0xc3, 0x10},
122 	{0xc4, 0x08},
123 	{0xc5, 0xf0},
124 	{0xc6, 0xff},
125 	{0xc7, 0x00},
126 	{0xc8, 0x1a},
127 	{0xc9, 0x80},
128 	{0xe0, 0xf8},
129 	{0xe6, 0x8b},
130 	{0xd0, 0x40},
131 	{0xf8, 0x20},
132 	{0xfa, 0x0f},
133 	{0x00, 0x00},
134 	{0xbd, 0x01},
135 	{0xb8, 0x00},
136 };
137 
138 static const struct m88ds3103_reg_val m88ds3103_dvbs2_init_reg_vals[] = {
139 	{0x23, 0x07},
140 	{0x08, 0x07},
141 	{0x0c, 0x02},
142 	{0x21, 0x54},
143 	{0x25, 0x8a},
144 	{0x27, 0x31},
145 	{0x30, 0x08},
146 	{0x32, 0x32},
147 	{0x35, 0xff},
148 	{0x3a, 0x00},
149 	{0x37, 0x10},
150 	{0x38, 0x10},
151 	{0x39, 0x02},
152 	{0x42, 0x60},
153 	{0x4a, 0x80},
154 	{0x4b, 0x04},
155 	{0x4d, 0x91},
156 	{0x5d, 0xc8},
157 	{0x50, 0x36},
158 	{0x51, 0x36},
159 	{0x52, 0x36},
160 	{0x53, 0x36},
161 	{0x56, 0x01},
162 	{0x63, 0x0f},
163 	{0x64, 0x10},
164 	{0x65, 0x20},
165 	{0x68, 0x46},
166 	{0x69, 0xcd},
167 	{0x70, 0x20},
168 	{0x71, 0x70},
169 	{0x72, 0x04},
170 	{0x73, 0x00},
171 	{0x70, 0x40},
172 	{0x71, 0x70},
173 	{0x72, 0x04},
174 	{0x73, 0x00},
175 	{0x70, 0x60},
176 	{0x71, 0x70},
177 	{0x72, 0x04},
178 	{0x73, 0x00},
179 	{0x70, 0x80},
180 	{0x71, 0x70},
181 	{0x72, 0x04},
182 	{0x73, 0x00},
183 	{0x70, 0xa0},
184 	{0x71, 0x70},
185 	{0x72, 0x04},
186 	{0x73, 0x00},
187 	{0x70, 0x1f},
188 	{0x76, 0x38},
189 	{0x77, 0xa6},
190 	{0x78, 0x0c},
191 	{0x79, 0x80},
192 	{0x7f, 0x14},
193 	{0x85, 0x08},
194 	{0xcd, 0xf4},
195 	{0x90, 0x33},
196 	{0x86, 0x00},
197 	{0x87, 0x0f},
198 	{0x89, 0x00},
199 	{0x8b, 0x44},
200 	{0x8c, 0x66},
201 	{0x9d, 0xc1},
202 	{0x8a, 0x10},
203 	{0xad, 0x40},
204 	{0xa0, 0x44},
205 	{0xc0, 0x08},
206 	{0xc1, 0x10},
207 	{0xc2, 0x08},
208 	{0xc3, 0x10},
209 	{0xc4, 0x08},
210 	{0xc5, 0xf0},
211 	{0xc6, 0xff},
212 	{0xc7, 0x00},
213 	{0xc8, 0x1a},
214 	{0xc9, 0x80},
215 	{0xca, 0x23},
216 	{0xcb, 0x24},
217 	{0xcc, 0xf4},
218 	{0xce, 0x74},
219 	{0x00, 0x00},
220 	{0xbd, 0x01},
221 	{0xb8, 0x00},
222 };
223 
224 static const struct m88ds3103_reg_val m88rs6000_dvbs_init_reg_vals[] = {
225 	{0x23, 0x07},
226 	{0x08, 0x03},
227 	{0x0c, 0x02},
228 	{0x20, 0x00},
229 	{0x21, 0x54},
230 	{0x25, 0x82},
231 	{0x27, 0x31},
232 	{0x30, 0x08},
233 	{0x31, 0x40},
234 	{0x32, 0x32},
235 	{0x33, 0x35},
236 	{0x35, 0xff},
237 	{0x3a, 0x00},
238 	{0x37, 0x10},
239 	{0x38, 0x10},
240 	{0x39, 0x02},
241 	{0x42, 0x60},
242 	{0x4a, 0x80},
243 	{0x4b, 0x04},
244 	{0x4d, 0x91},
245 	{0x5d, 0xc8},
246 	{0x50, 0x36},
247 	{0x51, 0x36},
248 	{0x52, 0x36},
249 	{0x53, 0x36},
250 	{0x63, 0x0f},
251 	{0x64, 0x30},
252 	{0x65, 0x40},
253 	{0x68, 0x26},
254 	{0x69, 0x4c},
255 	{0x70, 0x20},
256 	{0x71, 0x70},
257 	{0x72, 0x04},
258 	{0x73, 0x00},
259 	{0x70, 0x40},
260 	{0x71, 0x70},
261 	{0x72, 0x04},
262 	{0x73, 0x00},
263 	{0x70, 0x60},
264 	{0x71, 0x70},
265 	{0x72, 0x04},
266 	{0x73, 0x00},
267 	{0x70, 0x80},
268 	{0x71, 0x70},
269 	{0x72, 0x04},
270 	{0x73, 0x00},
271 	{0x70, 0xa0},
272 	{0x71, 0x70},
273 	{0x72, 0x04},
274 	{0x73, 0x00},
275 	{0x70, 0x1f},
276 	{0x76, 0x38},
277 	{0x77, 0xa6},
278 	{0x78, 0x0c},
279 	{0x79, 0x80},
280 	{0x7f, 0x14},
281 	{0x7c, 0x00},
282 	{0xae, 0x82},
283 	{0x80, 0x64},
284 	{0x81, 0x66},
285 	{0x82, 0x44},
286 	{0x85, 0x04},
287 	{0xcd, 0xf4},
288 	{0x90, 0x33},
289 	{0xa0, 0x44},
290 	{0xbe, 0x00},
291 	{0xc0, 0x08},
292 	{0xc3, 0x10},
293 	{0xc4, 0x08},
294 	{0xc5, 0xf0},
295 	{0xc6, 0xff},
296 	{0xc7, 0x00},
297 	{0xc8, 0x1a},
298 	{0xc9, 0x80},
299 	{0xe0, 0xf8},
300 	{0xe6, 0x8b},
301 	{0xd0, 0x40},
302 	{0xf8, 0x20},
303 	{0xfa, 0x0f},
304 	{0x00, 0x00},
305 	{0xbd, 0x01},
306 	{0xb8, 0x00},
307 	{0x29, 0x11},
308 };
309 
310 static const struct m88ds3103_reg_val m88rs6000_dvbs2_init_reg_vals[] = {
311 	{0x23, 0x07},
312 	{0x08, 0x07},
313 	{0x0c, 0x02},
314 	{0x20, 0x00},
315 	{0x21, 0x54},
316 	{0x25, 0x82},
317 	{0x27, 0x31},
318 	{0x30, 0x08},
319 	{0x32, 0x32},
320 	{0x33, 0x35},
321 	{0x35, 0xff},
322 	{0x3a, 0x00},
323 	{0x37, 0x10},
324 	{0x38, 0x10},
325 	{0x39, 0x02},
326 	{0x42, 0x60},
327 	{0x4a, 0x80},
328 	{0x4b, 0x04},
329 	{0x4d, 0x91},
330 	{0x5d, 0xc8},
331 	{0x50, 0x36},
332 	{0x51, 0x36},
333 	{0x52, 0x36},
334 	{0x53, 0x36},
335 	{0x63, 0x0f},
336 	{0x64, 0x10},
337 	{0x65, 0x20},
338 	{0x68, 0x46},
339 	{0x69, 0xcd},
340 	{0x70, 0x20},
341 	{0x71, 0x70},
342 	{0x72, 0x04},
343 	{0x73, 0x00},
344 	{0x70, 0x40},
345 	{0x71, 0x70},
346 	{0x72, 0x04},
347 	{0x73, 0x00},
348 	{0x70, 0x60},
349 	{0x71, 0x70},
350 	{0x72, 0x04},
351 	{0x73, 0x00},
352 	{0x70, 0x80},
353 	{0x71, 0x70},
354 	{0x72, 0x04},
355 	{0x73, 0x00},
356 	{0x70, 0xa0},
357 	{0x71, 0x70},
358 	{0x72, 0x04},
359 	{0x73, 0x00},
360 	{0x70, 0x1f},
361 	{0x76, 0x38},
362 	{0x77, 0xa6},
363 	{0x78, 0x0c},
364 	{0x79, 0x80},
365 	{0x7f, 0x14},
366 	{0x85, 0x08},
367 	{0xcd, 0xf4},
368 	{0x90, 0x33},
369 	{0x86, 0x00},
370 	{0x87, 0x0f},
371 	{0x89, 0x00},
372 	{0x8b, 0x44},
373 	{0x8c, 0x66},
374 	{0x9d, 0xc1},
375 	{0x8a, 0x10},
376 	{0xad, 0x40},
377 	{0xa0, 0x44},
378 	{0xbe, 0x00},
379 	{0xc0, 0x08},
380 	{0xc1, 0x10},
381 	{0xc2, 0x08},
382 	{0xc3, 0x10},
383 	{0xc4, 0x08},
384 	{0xc5, 0xf0},
385 	{0xc6, 0xff},
386 	{0xc7, 0x00},
387 	{0xc8, 0x1a},
388 	{0xc9, 0x80},
389 	{0xca, 0x23},
390 	{0xcb, 0x24},
391 	{0xcc, 0xf4},
392 	{0xce, 0x74},
393 	{0x00, 0x00},
394 	{0xbd, 0x01},
395 	{0xb8, 0x00},
396 	{0x29, 0x01},
397 };
398 #endif
399