4 * Sony CXD2441ER digital demodulator driver
6 * Copyright 2012 Sony Corporation
7 * Copyright (C) 2014 NetUP Inc.
8 * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
9 * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/string.h>
25 #include <linux/slab.h>
26 #include <linux/bitops.h>
27 #include <linux/math64.h>
28 #include <linux/log2.h>
29 #include <linux/dynamic_debug.h>
32 #include "dvb_frontend.h"
33 #include "cxd2841er.h"
34 #include "cxd2841er_priv.h"
36 #define MAX_WRITE_REGSIZE 16
38 enum cxd2841er_state
{
46 struct cxd2841er_priv
{
47 struct dvb_frontend frontend
;
48 struct i2c_adapter
*i2c
;
51 const struct cxd2841er_config
*config
;
52 enum cxd2841er_state state
;
56 static const struct cxd2841er_cnr_data s_cn_data
[] = {
57 { 0x033e, 0 }, { 0x0339, 100 }, { 0x0333, 200 },
58 { 0x032e, 300 }, { 0x0329, 400 }, { 0x0324, 500 },
59 { 0x031e, 600 }, { 0x0319, 700 }, { 0x0314, 800 },
60 { 0x030f, 900 }, { 0x030a, 1000 }, { 0x02ff, 1100 },
61 { 0x02f4, 1200 }, { 0x02e9, 1300 }, { 0x02de, 1400 },
62 { 0x02d4, 1500 }, { 0x02c9, 1600 }, { 0x02bf, 1700 },
63 { 0x02b5, 1800 }, { 0x02ab, 1900 }, { 0x02a1, 2000 },
64 { 0x029b, 2100 }, { 0x0295, 2200 }, { 0x0290, 2300 },
65 { 0x028a, 2400 }, { 0x0284, 2500 }, { 0x027f, 2600 },
66 { 0x0279, 2700 }, { 0x0274, 2800 }, { 0x026e, 2900 },
67 { 0x0269, 3000 }, { 0x0262, 3100 }, { 0x025c, 3200 },
68 { 0x0255, 3300 }, { 0x024f, 3400 }, { 0x0249, 3500 },
69 { 0x0242, 3600 }, { 0x023c, 3700 }, { 0x0236, 3800 },
70 { 0x0230, 3900 }, { 0x022a, 4000 }, { 0x0223, 4100 },
71 { 0x021c, 4200 }, { 0x0215, 4300 }, { 0x020e, 4400 },
72 { 0x0207, 4500 }, { 0x0201, 4600 }, { 0x01fa, 4700 },
73 { 0x01f4, 4800 }, { 0x01ed, 4900 }, { 0x01e7, 5000 },
74 { 0x01e0, 5100 }, { 0x01d9, 5200 }, { 0x01d2, 5300 },
75 { 0x01cb, 5400 }, { 0x01c4, 5500 }, { 0x01be, 5600 },
76 { 0x01b7, 5700 }, { 0x01b1, 5800 }, { 0x01aa, 5900 },
77 { 0x01a4, 6000 }, { 0x019d, 6100 }, { 0x0196, 6200 },
78 { 0x018f, 6300 }, { 0x0189, 6400 }, { 0x0182, 6500 },
79 { 0x017c, 6600 }, { 0x0175, 6700 }, { 0x016f, 6800 },
80 { 0x0169, 6900 }, { 0x0163, 7000 }, { 0x015c, 7100 },
81 { 0x0156, 7200 }, { 0x0150, 7300 }, { 0x014a, 7400 },
82 { 0x0144, 7500 }, { 0x013e, 7600 }, { 0x0138, 7700 },
83 { 0x0132, 7800 }, { 0x012d, 7900 }, { 0x0127, 8000 },
84 { 0x0121, 8100 }, { 0x011c, 8200 }, { 0x0116, 8300 },
85 { 0x0111, 8400 }, { 0x010b, 8500 }, { 0x0106, 8600 },
86 { 0x0101, 8700 }, { 0x00fc, 8800 }, { 0x00f7, 8900 },
87 { 0x00f2, 9000 }, { 0x00ee, 9100 }, { 0x00ea, 9200 },
88 { 0x00e6, 9300 }, { 0x00e2, 9400 }, { 0x00de, 9500 },
89 { 0x00da, 9600 }, { 0x00d7, 9700 }, { 0x00d3, 9800 },
90 { 0x00d0, 9900 }, { 0x00cc, 10000 }, { 0x00c7, 10100 },
91 { 0x00c3, 10200 }, { 0x00bf, 10300 }, { 0x00ba, 10400 },
92 { 0x00b6, 10500 }, { 0x00b2, 10600 }, { 0x00ae, 10700 },
93 { 0x00aa, 10800 }, { 0x00a7, 10900 }, { 0x00a3, 11000 },
94 { 0x009f, 11100 }, { 0x009c, 11200 }, { 0x0098, 11300 },
95 { 0x0094, 11400 }, { 0x0091, 11500 }, { 0x008e, 11600 },
96 { 0x008a, 11700 }, { 0x0087, 11800 }, { 0x0084, 11900 },
97 { 0x0081, 12000 }, { 0x007e, 12100 }, { 0x007b, 12200 },
98 { 0x0079, 12300 }, { 0x0076, 12400 }, { 0x0073, 12500 },
99 { 0x0071, 12600 }, { 0x006e, 12700 }, { 0x006c, 12800 },
100 { 0x0069, 12900 }, { 0x0067, 13000 }, { 0x0065, 13100 },
101 { 0x0062, 13200 }, { 0x0060, 13300 }, { 0x005e, 13400 },
102 { 0x005c, 13500 }, { 0x005a, 13600 }, { 0x0058, 13700 },
103 { 0x0056, 13800 }, { 0x0054, 13900 }, { 0x0052, 14000 },
104 { 0x0050, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
105 { 0x004b, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
106 { 0x0046, 14700 }, { 0x0044, 14800 }, { 0x0043, 14900 },
107 { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
108 { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
109 { 0x0037, 15700 }, { 0x0036, 15800 }, { 0x0034, 15900 },
110 { 0x0033, 16000 }, { 0x0032, 16100 }, { 0x0031, 16200 },
111 { 0x0030, 16300 }, { 0x002f, 16400 }, { 0x002e, 16500 },
112 { 0x002d, 16600 }, { 0x002c, 16700 }, { 0x002b, 16800 },
113 { 0x002a, 16900 }, { 0x0029, 17000 }, { 0x0028, 17100 },
114 { 0x0027, 17200 }, { 0x0026, 17300 }, { 0x0025, 17400 },
115 { 0x0024, 17500 }, { 0x0023, 17600 }, { 0x0022, 17800 },
116 { 0x0021, 17900 }, { 0x0020, 18000 }, { 0x001f, 18200 },
117 { 0x001e, 18300 }, { 0x001d, 18500 }, { 0x001c, 18700 },
118 { 0x001b, 18900 }, { 0x001a, 19000 }, { 0x0019, 19200 },
119 { 0x0018, 19300 }, { 0x0017, 19500 }, { 0x0016, 19700 },
120 { 0x0015, 19900 }, { 0x0014, 20000 },
123 static const struct cxd2841er_cnr_data s2_cn_data
[] = {
124 { 0x05af, 0 }, { 0x0597, 100 }, { 0x057e, 200 },
125 { 0x0567, 300 }, { 0x0550, 400 }, { 0x0539, 500 },
126 { 0x0522, 600 }, { 0x050c, 700 }, { 0x04f6, 800 },
127 { 0x04e1, 900 }, { 0x04cc, 1000 }, { 0x04b6, 1100 },
128 { 0x04a1, 1200 }, { 0x048c, 1300 }, { 0x0477, 1400 },
129 { 0x0463, 1500 }, { 0x044f, 1600 }, { 0x043c, 1700 },
130 { 0x0428, 1800 }, { 0x0416, 1900 }, { 0x0403, 2000 },
131 { 0x03ef, 2100 }, { 0x03dc, 2200 }, { 0x03c9, 2300 },
132 { 0x03b6, 2400 }, { 0x03a4, 2500 }, { 0x0392, 2600 },
133 { 0x0381, 2700 }, { 0x036f, 2800 }, { 0x035f, 2900 },
134 { 0x034e, 3000 }, { 0x033d, 3100 }, { 0x032d, 3200 },
135 { 0x031d, 3300 }, { 0x030d, 3400 }, { 0x02fd, 3500 },
136 { 0x02ee, 3600 }, { 0x02df, 3700 }, { 0x02d0, 3800 },
137 { 0x02c2, 3900 }, { 0x02b4, 4000 }, { 0x02a6, 4100 },
138 { 0x0299, 4200 }, { 0x028c, 4300 }, { 0x027f, 4400 },
139 { 0x0272, 4500 }, { 0x0265, 4600 }, { 0x0259, 4700 },
140 { 0x024d, 4800 }, { 0x0241, 4900 }, { 0x0236, 5000 },
141 { 0x022b, 5100 }, { 0x0220, 5200 }, { 0x0215, 5300 },
142 { 0x020a, 5400 }, { 0x0200, 5500 }, { 0x01f6, 5600 },
143 { 0x01ec, 5700 }, { 0x01e2, 5800 }, { 0x01d8, 5900 },
144 { 0x01cf, 6000 }, { 0x01c6, 6100 }, { 0x01bc, 6200 },
145 { 0x01b3, 6300 }, { 0x01aa, 6400 }, { 0x01a2, 6500 },
146 { 0x0199, 6600 }, { 0x0191, 6700 }, { 0x0189, 6800 },
147 { 0x0181, 6900 }, { 0x0179, 7000 }, { 0x0171, 7100 },
148 { 0x0169, 7200 }, { 0x0161, 7300 }, { 0x015a, 7400 },
149 { 0x0153, 7500 }, { 0x014b, 7600 }, { 0x0144, 7700 },
150 { 0x013d, 7800 }, { 0x0137, 7900 }, { 0x0130, 8000 },
151 { 0x012a, 8100 }, { 0x0124, 8200 }, { 0x011e, 8300 },
152 { 0x0118, 8400 }, { 0x0112, 8500 }, { 0x010c, 8600 },
153 { 0x0107, 8700 }, { 0x0101, 8800 }, { 0x00fc, 8900 },
154 { 0x00f7, 9000 }, { 0x00f2, 9100 }, { 0x00ec, 9200 },
155 { 0x00e7, 9300 }, { 0x00e2, 9400 }, { 0x00dd, 9500 },
156 { 0x00d8, 9600 }, { 0x00d4, 9700 }, { 0x00cf, 9800 },
157 { 0x00ca, 9900 }, { 0x00c6, 10000 }, { 0x00c2, 10100 },
158 { 0x00be, 10200 }, { 0x00b9, 10300 }, { 0x00b5, 10400 },
159 { 0x00b1, 10500 }, { 0x00ae, 10600 }, { 0x00aa, 10700 },
160 { 0x00a6, 10800 }, { 0x00a3, 10900 }, { 0x009f, 11000 },
161 { 0x009b, 11100 }, { 0x0098, 11200 }, { 0x0095, 11300 },
162 { 0x0091, 11400 }, { 0x008e, 11500 }, { 0x008b, 11600 },
163 { 0x0088, 11700 }, { 0x0085, 11800 }, { 0x0082, 11900 },
164 { 0x007f, 12000 }, { 0x007c, 12100 }, { 0x007a, 12200 },
165 { 0x0077, 12300 }, { 0x0074, 12400 }, { 0x0072, 12500 },
166 { 0x006f, 12600 }, { 0x006d, 12700 }, { 0x006b, 12800 },
167 { 0x0068, 12900 }, { 0x0066, 13000 }, { 0x0064, 13100 },
168 { 0x0061, 13200 }, { 0x005f, 13300 }, { 0x005d, 13400 },
169 { 0x005b, 13500 }, { 0x0059, 13600 }, { 0x0057, 13700 },
170 { 0x0055, 13800 }, { 0x0053, 13900 }, { 0x0051, 14000 },
171 { 0x004f, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
172 { 0x004a, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
173 { 0x0045, 14700 }, { 0x0044, 14800 }, { 0x0042, 14900 },
174 { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
175 { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
176 { 0x0038, 15600 }, { 0x0037, 15700 }, { 0x0036, 15800 },
177 { 0x0034, 15900 }, { 0x0033, 16000 }, { 0x0032, 16100 },
178 { 0x0031, 16200 }, { 0x0030, 16300 }, { 0x002f, 16400 },
179 { 0x002e, 16500 }, { 0x002d, 16600 }, { 0x002c, 16700 },
180 { 0x002b, 16800 }, { 0x002a, 16900 }, { 0x0029, 17000 },
181 { 0x0028, 17100 }, { 0x0027, 17200 }, { 0x0026, 17300 },
182 { 0x0025, 17400 }, { 0x0024, 17500 }, { 0x0023, 17600 },
183 { 0x0022, 17800 }, { 0x0021, 17900 }, { 0x0020, 18000 },
184 { 0x001f, 18200 }, { 0x001e, 18300 }, { 0x001d, 18500 },
185 { 0x001c, 18700 }, { 0x001b, 18900 }, { 0x001a, 19000 },
186 { 0x0019, 19200 }, { 0x0018, 19300 }, { 0x0017, 19500 },
187 { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 },
190 #define MAKE_IFFREQ_CONFIG(iffreq) ((u32)(((iffreq)/41.0)*16777216.0 + 0.5))
192 static void cxd2841er_i2c_debug(struct cxd2841er_priv
*priv
,
193 u8 addr
, u8 reg
, u8 write
,
194 const u8
*data
, u32 len
)
196 dev_dbg(&priv
->i2c
->dev
,
197 "cxd2841er: I2C %s addr %02x reg 0x%02x size %d\n",
198 (write
== 0 ? "read" : "write"), addr
, reg
, len
);
199 print_hex_dump_bytes("cxd2841er: I2C data: ",
200 DUMP_PREFIX_OFFSET
, data
, len
);
203 static int cxd2841er_write_regs(struct cxd2841er_priv
*priv
,
204 u8 addr
, u8 reg
, const u8
*data
, u32 len
)
207 u8 buf
[MAX_WRITE_REGSIZE
+ 1];
208 u8 i2c_addr
= (addr
== I2C_SLVX
?
209 priv
->i2c_addr_slvx
: priv
->i2c_addr_slvt
);
210 struct i2c_msg msg
[1] = {
219 if (len
+ 1 >= sizeof(buf
)) {
220 dev_warn(&priv
->i2c
->dev
,"wr reg=%04x: len=%d is too big!\n",
225 cxd2841er_i2c_debug(priv
, i2c_addr
, reg
, 1, data
, len
);
227 memcpy(&buf
[1], data
, len
);
229 ret
= i2c_transfer(priv
->i2c
, msg
, 1);
230 if (ret
>= 0 && ret
!= 1)
233 dev_warn(&priv
->i2c
->dev
,
234 "%s: i2c wr failed=%d addr=%02x reg=%02x len=%d\n",
235 KBUILD_MODNAME
, ret
, i2c_addr
, reg
, len
);
241 static int cxd2841er_write_reg(struct cxd2841er_priv
*priv
,
242 u8 addr
, u8 reg
, u8 val
)
244 return cxd2841er_write_regs(priv
, addr
, reg
, &val
, 1);
247 static int cxd2841er_read_regs(struct cxd2841er_priv
*priv
,
248 u8 addr
, u8 reg
, u8
*val
, u32 len
)
251 u8 i2c_addr
= (addr
== I2C_SLVX
?
252 priv
->i2c_addr_slvx
: priv
->i2c_addr_slvt
);
253 struct i2c_msg msg
[2] = {
267 ret
= i2c_transfer(priv
->i2c
, &msg
[0], 1);
268 if (ret
>= 0 && ret
!= 1)
271 dev_warn(&priv
->i2c
->dev
,
272 "%s: i2c rw failed=%d addr=%02x reg=%02x\n",
273 KBUILD_MODNAME
, ret
, i2c_addr
, reg
);
276 ret
= i2c_transfer(priv
->i2c
, &msg
[1], 1);
277 if (ret
>= 0 && ret
!= 1)
280 dev_warn(&priv
->i2c
->dev
,
281 "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
282 KBUILD_MODNAME
, ret
, i2c_addr
, reg
);
288 static int cxd2841er_read_reg(struct cxd2841er_priv
*priv
,
289 u8 addr
, u8 reg
, u8
*val
)
291 return cxd2841er_read_regs(priv
, addr
, reg
, val
, 1);
294 static int cxd2841er_set_reg_bits(struct cxd2841er_priv
*priv
,
295 u8 addr
, u8 reg
, u8 data
, u8 mask
)
301 res
= cxd2841er_read_reg(priv
, addr
, reg
, &rdata
);
304 data
= ((data
& mask
) | (rdata
& (mask
^ 0xFF)));
306 return cxd2841er_write_reg(priv
, addr
, reg
, data
);
309 static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv
*priv
,
313 u8 data
[3] = {0, 0, 0};
315 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
317 * regValue = (symbolRateKSps * 2^14 / 1000) + 0.5
318 * = ((symbolRateKSps * 2^14) + 500) / 1000
319 * = ((symbolRateKSps * 16384) + 500) / 1000
321 reg_value
= DIV_ROUND_CLOSEST(symbol_rate
* 16384, 1000);
322 if ((reg_value
== 0) || (reg_value
> 0xFFFFF)) {
323 dev_err(&priv
->i2c
->dev
,
324 "%s(): reg_value is out of range\n", __func__
);
327 data
[0] = (u8
)((reg_value
>> 16) & 0x0F);
328 data
[1] = (u8
)((reg_value
>> 8) & 0xFF);
329 data
[2] = (u8
)(reg_value
& 0xFF);
330 /* Set SLV-T Bank : 0xAE */
331 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xae);
332 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x20, data
, 3);
336 static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv
*priv
,
339 static int cxd2841er_sleep_s_to_active_s(struct cxd2841er_priv
*priv
,
340 u8 system
, u32 symbol_rate
)
343 u8 data
[4] = { 0, 0, 0, 0 };
345 if (priv
->state
!= STATE_SLEEP_S
) {
346 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
347 __func__
, (int)priv
->state
);
350 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
351 cxd2841er_set_ts_clock_mode(priv
, SYS_DVBS
);
353 if (system
== SYS_DVBS
) {
355 } else if (system
== SYS_DVBS2
) {
358 dev_err(&priv
->i2c
->dev
, "%s(): invalid delsys %d\n",
362 /* Set SLV-X Bank : 0x00 */
363 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
364 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, data
[0]);
367 /* Set SLV-T Bank : 0x00 */
368 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
369 /* Enable S/S2 auto detection 1 */
370 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2d, data
[0]);
371 /* Set SLV-T Bank : 0xAE */
372 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xae);
373 /* Enable S/S2 auto detection 2 */
374 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, data
[0]);
375 /* Set SLV-T Bank : 0x00 */
376 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
377 /* Enable demod clock */
378 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x01);
379 /* Enable ADC clock */
380 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x31, 0x01);
382 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x63, 0x16);
384 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x65, 0x3f);
385 /* Set SLV-X Bank : 0x00 */
386 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
388 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x00);
389 /* Set SLV-T Bank : 0xA3 */
390 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa3);
391 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xac, 0x00);
396 /* Set SLV-T Bank : 0xAB */
397 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xab);
398 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x98, data
, 4);
403 cxd2841er_write_regs(priv
, I2C_SLVT
, 0xa8, data
, 4);
406 cxd2841er_write_regs(priv
, I2C_SLVT
, 0xc3, data
, 2);
407 /* Set demod parameter */
408 ret
= cxd2841er_dvbs2_set_symbol_rate(priv
, symbol_rate
);
411 /* Set SLV-T Bank : 0x00 */
412 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
413 /* disable Hi-Z setting 1 */
414 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x10);
415 /* disable Hi-Z setting 2 */
416 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0x00);
417 priv
->state
= STATE_ACTIVE_S
;
421 static int cxd2841er_sleep_tc_to_active_t_band(struct cxd2841er_priv
*priv
,
424 static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv
*priv
,
427 static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv
*priv
,
430 static int cxd2841er_retune_active(struct cxd2841er_priv
*priv
,
431 struct dtv_frontend_properties
*p
)
433 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
434 if (priv
->state
!= STATE_ACTIVE_S
&&
435 priv
->state
!= STATE_ACTIVE_TC
) {
436 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
437 __func__
, priv
->state
);
440 /* Set SLV-T Bank : 0x00 */
441 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
442 /* disable TS output */
443 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xc3, 0x01);
444 if (priv
->state
== STATE_ACTIVE_S
)
445 return cxd2841er_dvbs2_set_symbol_rate(
446 priv
, p
->symbol_rate
/ 1000);
447 else if (priv
->state
== STATE_ACTIVE_TC
) {
448 switch (priv
->system
) {
450 return cxd2841er_sleep_tc_to_active_t_band(
451 priv
, p
->bandwidth_hz
);
453 return cxd2841er_sleep_tc_to_active_t2_band(
454 priv
, p
->bandwidth_hz
);
455 case SYS_DVBC_ANNEX_A
:
456 return cxd2841er_sleep_tc_to_active_c_band(
460 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid delivery system %d\n",
461 __func__
, priv
->system
);
465 static int cxd2841er_active_s_to_sleep_s(struct cxd2841er_priv
*priv
)
467 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
468 if (priv
->state
!= STATE_ACTIVE_S
) {
469 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
470 __func__
, priv
->state
);
473 /* Set SLV-T Bank : 0x00 */
474 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
475 /* disable TS output */
476 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xc3, 0x01);
477 /* enable Hi-Z setting 1 */
478 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x1f);
479 /* enable Hi-Z setting 2 */
480 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0xff);
481 /* Set SLV-X Bank : 0x00 */
482 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
484 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x01);
485 /* Set SLV-T Bank : 0x00 */
486 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
487 /* disable ADC clock */
488 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x31, 0x00);
490 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x63, 0x16);
492 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x65, 0x27);
494 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x69, 0x06);
495 /* disable demod clock */
496 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x00);
497 /* Set SLV-T Bank : 0xAE */
498 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xae);
499 /* disable S/S2 auto detection1 */
500 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
501 /* Set SLV-T Bank : 0x00 */
502 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
503 /* disable S/S2 auto detection2 */
504 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2d, 0x00);
505 priv
->state
= STATE_SLEEP_S
;
509 static int cxd2841er_sleep_s_to_shutdown(struct cxd2841er_priv
*priv
)
511 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
512 if (priv
->state
!= STATE_SLEEP_S
) {
513 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
514 __func__
, priv
->state
);
517 /* Set SLV-T Bank : 0x00 */
518 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
520 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x3f);
522 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x9c, 0x00);
523 /* Set SLV-X Bank : 0x00 */
524 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
525 /* Disable oscillator */
526 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x15, 0x01);
528 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, 0x01);
529 priv
->state
= STATE_SHUTDOWN
;
533 static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv
*priv
)
535 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
536 if (priv
->state
!= STATE_SLEEP_TC
) {
537 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
538 __func__
, priv
->state
);
541 /* Set SLV-X Bank : 0x00 */
542 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
543 /* Disable oscillator */
544 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x15, 0x01);
546 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, 0x01);
547 priv
->state
= STATE_SHUTDOWN
;
551 static int cxd2841er_active_t_to_sleep_tc(struct cxd2841er_priv
*priv
)
553 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
554 if (priv
->state
!= STATE_ACTIVE_TC
) {
555 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
556 __func__
, priv
->state
);
559 /* Set SLV-T Bank : 0x00 */
560 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
561 /* disable TS output */
562 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xc3, 0x01);
563 /* enable Hi-Z setting 1 */
564 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x3f);
565 /* enable Hi-Z setting 2 */
566 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0xff);
567 /* Set SLV-X Bank : 0x00 */
568 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
570 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x01);
571 /* Set SLV-T Bank : 0x00 */
572 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
574 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x43, 0x0a);
576 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x0a);
577 /* Disable ADC clock */
578 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
579 /* Disable RF level monitor */
580 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2f, 0x00);
581 /* Disable demod clock */
582 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x00);
583 priv
->state
= STATE_SLEEP_TC
;
587 static int cxd2841er_active_t2_to_sleep_tc(struct cxd2841er_priv
*priv
)
589 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
590 if (priv
->state
!= STATE_ACTIVE_TC
) {
591 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
592 __func__
, priv
->state
);
595 /* Set SLV-T Bank : 0x00 */
596 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
597 /* disable TS output */
598 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xc3, 0x01);
599 /* enable Hi-Z setting 1 */
600 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x3f);
601 /* enable Hi-Z setting 2 */
602 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0xff);
603 /* Cancel DVB-T2 setting */
604 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x13);
605 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x83, 0x40);
606 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x86, 0x21);
607 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x9e, 0x09, 0x0f);
608 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x9f, 0xfb);
609 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2a);
610 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x38, 0x00, 0x0f);
611 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2b);
612 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x11, 0x00, 0x3f);
613 /* Set SLV-X Bank : 0x00 */
614 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
616 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x01);
617 /* Set SLV-T Bank : 0x00 */
618 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
620 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x43, 0x0a);
622 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x0a);
623 /* Disable ADC clock */
624 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
625 /* Disable RF level monitor */
626 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2f, 0x00);
627 /* Disable demod clock */
628 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x00);
629 priv
->state
= STATE_SLEEP_TC
;
633 static int cxd2841er_active_c_to_sleep_tc(struct cxd2841er_priv
*priv
)
635 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
636 if (priv
->state
!= STATE_ACTIVE_TC
) {
637 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
638 __func__
, priv
->state
);
641 /* Set SLV-T Bank : 0x00 */
642 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
643 /* disable TS output */
644 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xc3, 0x01);
645 /* enable Hi-Z setting 1 */
646 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x3f);
647 /* enable Hi-Z setting 2 */
648 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0xff);
649 /* Cancel DVB-C setting */
650 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x11);
651 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xa3, 0x00, 0x1f);
652 /* Set SLV-X Bank : 0x00 */
653 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
655 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x01);
656 /* Set SLV-T Bank : 0x00 */
657 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
659 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x43, 0x0a);
661 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x0a);
662 /* Disable ADC clock */
663 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
664 /* Disable RF level monitor */
665 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2f, 0x00);
666 /* Disable demod clock */
667 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x00);
668 priv
->state
= STATE_SLEEP_TC
;
672 static int cxd2841er_shutdown_to_sleep_s(struct cxd2841er_priv
*priv
)
674 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
675 if (priv
->state
!= STATE_SHUTDOWN
) {
676 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
677 __func__
, priv
->state
);
680 /* Set SLV-X Bank : 0x00 */
681 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
682 /* Clear all demodulator registers */
683 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x02, 0x00);
684 usleep_range(3000, 5000);
685 /* Set SLV-X Bank : 0x00 */
686 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
687 /* Set demod SW reset */
688 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x10, 0x01);
689 /* Set X'tal clock to 20.5Mhz */
690 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x14, 0x00);
692 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, 0x0a);
693 /* Clear demod SW reset */
694 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x10, 0x00);
695 usleep_range(1000, 2000);
696 /* Set SLV-T Bank : 0x00 */
697 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
699 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x1F);
701 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x9C, 0x40);
703 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x43, 0x0a);
704 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x0a);
706 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x63, 0x16);
707 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x65, 0x27);
708 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x69, 0x06);
709 priv
->state
= STATE_SLEEP_S
;
713 static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv
*priv
)
715 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
716 if (priv
->state
!= STATE_SHUTDOWN
) {
717 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
718 __func__
, priv
->state
);
721 /* Set SLV-X Bank : 0x00 */
722 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
723 /* Clear all demodulator registers */
724 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x02, 0x00);
725 usleep_range(3000, 5000);
726 /* Set SLV-X Bank : 0x00 */
727 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
728 /* Set demod SW reset */
729 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x10, 0x01);
730 /* Set X'tal clock to 20.5Mhz */
731 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x13, 0x00);
732 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x14, 0x00);
733 /* Clear demod SW reset */
734 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x10, 0x00);
735 usleep_range(1000, 2000);
736 /* Set SLV-T Bank : 0x00 */
737 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
739 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x43, 0x0a);
740 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x0a);
742 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x63, 0x16);
743 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x65, 0x27);
744 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x69, 0x06);
745 priv
->state
= STATE_SLEEP_TC
;
749 static int cxd2841er_tune_done(struct cxd2841er_priv
*priv
)
751 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
752 /* Set SLV-T Bank : 0x00 */
753 cxd2841er_write_reg(priv
, I2C_SLVT
, 0, 0);
755 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xfe, 0x01);
756 /* Enable TS output */
757 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xc3, 0x00);
761 /* Set TS parallel mode */
762 static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv
*priv
,
765 u8 serial_ts
, ts_rate_ctrl_off
, ts_in_off
;
767 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
768 /* Set SLV-T Bank : 0x00 */
769 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
770 cxd2841er_read_reg(priv
, I2C_SLVT
, 0xc4, &serial_ts
);
771 cxd2841er_read_reg(priv
, I2C_SLVT
, 0xd3, &ts_rate_ctrl_off
);
772 cxd2841er_read_reg(priv
, I2C_SLVT
, 0xde, &ts_in_off
);
773 dev_dbg(&priv
->i2c
->dev
, "%s(): ser_ts=0x%02x rate_ctrl_off=0x%02x in_off=0x%02x\n",
774 __func__
, serial_ts
, ts_rate_ctrl_off
, ts_in_off
);
777 * slave Bank Addr Bit default Name
778 * <SLV-T> 00h D9h [7:0] 8'h08 OTSCKPERIOD
780 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xd9, 0x08);
782 * Disable TS IF Clock
783 * slave Bank Addr Bit default Name
784 * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
786 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x32, 0x00, 0x01);
788 * slave Bank Addr Bit default Name
789 * <SLV-T> 00h 33h [1:0] 2'b01 OREG_CKSEL_TSIF
791 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x33, 0x00, 0x03);
794 * slave Bank Addr Bit default Name
795 * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
797 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x32, 0x01, 0x01);
799 if (system
== SYS_DVBT
) {
800 /* Enable parity period for DVB-T */
801 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
802 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x66, 0x01, 0x01);
803 } else if (system
== SYS_DVBC_ANNEX_A
) {
804 /* Enable parity period for DVB-C */
805 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x40);
806 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x66, 0x01, 0x01);
810 static u8
cxd2841er_chip_id(struct cxd2841er_priv
*priv
)
814 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
815 cxd2841er_write_reg(priv
, I2C_SLVT
, 0, 0);
816 cxd2841er_read_reg(priv
, I2C_SLVT
, 0xfd, &chip_id
);
820 static int cxd2841er_read_status_s(struct dvb_frontend
*fe
,
821 enum fe_status
*status
)
824 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
826 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
828 if (priv
->state
!= STATE_ACTIVE_S
) {
829 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
830 __func__
, priv
->state
);
833 /* Set SLV-T Bank : 0xA0 */
834 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa0);
836 * slave Bank Addr Bit Signal name
837 * <SLV-T> A0h 11h [2] ITSLOCK
839 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x11, ®
);
841 *status
= FE_HAS_SIGNAL
847 dev_dbg(&priv
->i2c
->dev
, "%s(): result 0x%x\n", __func__
, *status
);
851 static int cxd2841er_read_status_t_t2(struct cxd2841er_priv
*priv
,
852 u8
*sync
, u8
*tslock
, u8
*unlock
)
856 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
857 if (priv
->state
!= STATE_ACTIVE_TC
)
859 if (priv
->system
== SYS_DVBT
) {
860 /* Set SLV-T Bank : 0x10 */
861 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
863 /* Set SLV-T Bank : 0x20 */
864 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x20);
866 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x10, &data
);
867 if ((data
& 0x07) == 0x07) {
868 dev_dbg(&priv
->i2c
->dev
,
869 "%s(): invalid hardware state detected\n", __func__
);
874 *sync
= ((data
& 0x07) == 0x6 ? 1 : 0);
875 *tslock
= ((data
& 0x20) ? 1 : 0);
876 *unlock
= ((data
& 0x10) ? 1 : 0);
881 static int cxd2841er_read_status_c(struct cxd2841er_priv
*priv
, u8
*tslock
)
885 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
886 if (priv
->state
!= STATE_ACTIVE_TC
)
888 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x40);
889 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x88, &data
);
890 if ((data
& 0x01) == 0) {
893 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x10, &data
);
894 *tslock
= ((data
& 0x20) ? 1 : 0);
899 static int cxd2841er_read_status_tc(struct dvb_frontend
*fe
,
900 enum fe_status
*status
)
906 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
909 if (priv
->state
== STATE_ACTIVE_TC
) {
910 if (priv
->system
== SYS_DVBT
|| priv
->system
== SYS_DVBT2
) {
911 ret
= cxd2841er_read_status_t_t2(
912 priv
, &sync
, &tslock
, &unlock
);
918 *status
= FE_HAS_SIGNAL
|
923 *status
|= FE_HAS_LOCK
;
924 } else if (priv
->system
== SYS_DVBC_ANNEX_A
) {
925 ret
= cxd2841er_read_status_c(priv
, &tslock
);
929 *status
= FE_HAS_SIGNAL
|
937 dev_dbg(&priv
->i2c
->dev
, "%s(): status 0x%x\n", __func__
, *status
);
941 static int cxd2841er_get_carrier_offset_s_s2(struct cxd2841er_priv
*priv
,
947 s32 temp_div
, temp_q
, temp_r
;
949 if (priv
->state
!= STATE_ACTIVE_S
) {
950 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
951 __func__
, priv
->state
);
955 * Get High Sampling Rate mode
956 * slave Bank Addr Bit Signal name
957 * <SLV-T> A0h 10h [0] ITRL_LOCK
959 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa0);
960 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x10, &data
[0]);
961 if (data
[0] & 0x01) {
963 * slave Bank Addr Bit Signal name
964 * <SLV-T> A0h 50h [4] IHSMODE
966 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x50, &data
[0]);
967 is_hs_mode
= (data
[0] & 0x10 ? 1 : 0);
969 dev_dbg(&priv
->i2c
->dev
,
970 "%s(): unable to detect sampling rate mode\n",
975 * slave Bank Addr Bit Signal name
976 * <SLV-T> A0h 45h [4:0] ICFRL_CTRLVAL[20:16]
977 * <SLV-T> A0h 46h [7:0] ICFRL_CTRLVAL[15:8]
978 * <SLV-T> A0h 47h [7:0] ICFRL_CTRLVAL[7:0]
980 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x45, data
, 3);
981 cfrl_ctrlval
= sign_extend32((((u32
)data
[0] & 0x1F) << 16) |
982 (((u32
)data
[1] & 0xFF) << 8) |
983 ((u32
)data
[2] & 0xFF), 20);
984 temp_div
= (is_hs_mode
? 1048576 : 1572864);
985 if (cfrl_ctrlval
> 0) {
986 temp_q
= div_s64_rem(97375LL * cfrl_ctrlval
,
989 temp_q
= div_s64_rem(-97375LL * cfrl_ctrlval
,
992 if (temp_r
>= temp_div
/ 2)
994 if (cfrl_ctrlval
> 0)
1000 static int cxd2841er_get_carrier_offset_t2(struct cxd2841er_priv
*priv
,
1001 u32 bandwidth
, int *offset
)
1005 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1006 if (priv
->state
!= STATE_ACTIVE_TC
) {
1007 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
1008 __func__
, priv
->state
);
1011 if (priv
->system
!= SYS_DVBT2
) {
1012 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid delivery system %d\n",
1013 __func__
, priv
->system
);
1016 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x20);
1017 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x4c, data
, sizeof(data
));
1018 *offset
= -1 * sign_extend32(
1019 ((u32
)(data
[0] & 0x0F) << 24) | ((u32
)data
[1] << 16) |
1020 ((u32
)data
[2] << 8) | (u32
)data
[3], 27);
1021 switch (bandwidth
) {
1029 *offset
*= (bandwidth
/ 1000000);
1033 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid bandwidth %d\n",
1034 __func__
, bandwidth
);
1040 static int cxd2841er_get_carrier_offset_c(struct cxd2841er_priv
*priv
,
1045 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1046 if (priv
->state
!= STATE_ACTIVE_TC
) {
1047 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
1048 __func__
, priv
->state
);
1051 if (priv
->system
!= SYS_DVBC_ANNEX_A
) {
1052 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid delivery system %d\n",
1053 __func__
, priv
->system
);
1056 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x40);
1057 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x15, data
, sizeof(data
));
1058 *offset
= div_s64(41000LL * sign_extend32((((u32
)data
[0] & 0x3f) << 8)
1059 | (u32
)data
[1], 13), 16384);
1063 static int cxd2841er_read_packet_errors_t(
1064 struct cxd2841er_priv
*priv
, u32
*penum
)
1069 if (priv
->state
!= STATE_ACTIVE_TC
) {
1070 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
1071 __func__
, priv
->state
);
1074 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1075 cxd2841er_read_regs(priv
, I2C_SLVT
, 0xea, data
, sizeof(data
));
1077 *penum
= ((u32
)data
[0] << 8) | (u32
)data
[1];
1081 static int cxd2841er_read_packet_errors_t2(
1082 struct cxd2841er_priv
*priv
, u32
*penum
)
1087 if (priv
->state
!= STATE_ACTIVE_TC
) {
1088 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
1089 __func__
, priv
->state
);
1092 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x24);
1093 cxd2841er_read_regs(priv
, I2C_SLVT
, 0xfd, data
, sizeof(data
));
1095 *penum
= ((u32
)data
[1] << 8) | (u32
)data
[2];
1099 static u32
cxd2841er_mon_read_ber_s(struct cxd2841er_priv
*priv
)
1102 u32 bit_error
, bit_count
;
1105 /* Set SLV-T Bank : 0xA0 */
1106 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa0);
1108 * slave Bank Addr Bit Signal name
1109 * <SLV-T> A0h 35h [0] IFVBER_VALID
1110 * <SLV-T> A0h 36h [5:0] IFVBER_BITERR[21:16]
1111 * <SLV-T> A0h 37h [7:0] IFVBER_BITERR[15:8]
1112 * <SLV-T> A0h 38h [7:0] IFVBER_BITERR[7:0]
1113 * <SLV-T> A0h 3Dh [5:0] IFVBER_BITNUM[21:16]
1114 * <SLV-T> A0h 3Eh [7:0] IFVBER_BITNUM[15:8]
1115 * <SLV-T> A0h 3Fh [7:0] IFVBER_BITNUM[7:0]
1117 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x35, data
, 11);
1118 if (data
[0] & 0x01) {
1119 bit_error
= ((u32
)(data
[1] & 0x3F) << 16) |
1120 ((u32
)(data
[2] & 0xFF) << 8) |
1121 (u32
)(data
[3] & 0xFF);
1122 bit_count
= ((u32
)(data
[8] & 0x3F) << 16) |
1123 ((u32
)(data
[9] & 0xFF) << 8) |
1124 (u32
)(data
[10] & 0xFF);
1126 * BER = bitError / bitCount
1127 * = (bitError * 10^7) / bitCount
1128 * = ((bitError * 625 * 125 * 128) / bitCount
1130 if ((bit_count
== 0) || (bit_error
> bit_count
)) {
1131 dev_dbg(&priv
->i2c
->dev
,
1132 "%s(): invalid bit_error %d, bit_count %d\n",
1133 __func__
, bit_error
, bit_count
);
1136 temp_q
= div_u64_rem(10000000ULL * bit_error
,
1137 bit_count
, &temp_r
);
1138 if (bit_count
!= 1 && temp_r
>= bit_count
/ 2)
1142 dev_dbg(&priv
->i2c
->dev
, "%s(): no data available\n", __func__
);
1147 static u32
cxd2841er_mon_read_ber_s2(struct cxd2841er_priv
*priv
)
1150 u32 bit_error
, period
;
1154 /* Set SLV-T Bank : 0xB2 */
1155 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xb2);
1157 * slave Bank Addr Bit Signal name
1158 * <SLV-T> B2h 30h [0] IFLBER_VALID
1159 * <SLV-T> B2h 31h [3:0] IFLBER_BITERR[27:24]
1160 * <SLV-T> B2h 32h [7:0] IFLBER_BITERR[23:16]
1161 * <SLV-T> B2h 33h [7:0] IFLBER_BITERR[15:8]
1162 * <SLV-T> B2h 34h [7:0] IFLBER_BITERR[7:0]
1164 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x30, data
, 5);
1165 if (data
[0] & 0x01) {
1166 /* Bit error count */
1167 bit_error
= ((u32
)(data
[1] & 0x0F) << 24) |
1168 ((u32
)(data
[2] & 0xFF) << 16) |
1169 ((u32
)(data
[3] & 0xFF) << 8) |
1170 (u32
)(data
[4] & 0xFF);
1172 /* Set SLV-T Bank : 0xA0 */
1173 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa0);
1174 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x7a, data
);
1175 /* Measurement period */
1176 period
= (u32
)(1 << (data
[0] & 0x0F));
1178 dev_dbg(&priv
->i2c
->dev
,
1179 "%s(): period is 0\n", __func__
);
1182 if (bit_error
> (period
* 64800)) {
1183 dev_dbg(&priv
->i2c
->dev
,
1184 "%s(): invalid bit_err 0x%x period 0x%x\n",
1185 __func__
, bit_error
, period
);
1189 * BER = bitError / (period * 64800)
1190 * = (bitError * 10^7) / (period * 64800)
1191 * = (bitError * 10^5) / (period * 648)
1192 * = (bitError * 12500) / (period * 81)
1193 * = (bitError * 10) * 1250 / (period * 81)
1195 temp_q
= div_u64_rem(12500ULL * bit_error
,
1196 period
* 81, &temp_r
);
1197 if (temp_r
>= period
* 40)
1201 dev_dbg(&priv
->i2c
->dev
,
1202 "%s(): no data available\n", __func__
);
1207 static int cxd2841er_read_ber_t2(struct cxd2841er_priv
*priv
, u32
*ber
)
1211 u32 bit_err
, period_exp
, n_ldpc
;
1214 if (priv
->state
!= STATE_ACTIVE_TC
) {
1215 dev_dbg(&priv
->i2c
->dev
,
1216 "%s(): invalid state %d\n", __func__
, priv
->state
);
1219 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x20);
1220 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x39, data
, sizeof(data
));
1221 if (!(data
[0] & 0x10)) {
1222 dev_dbg(&priv
->i2c
->dev
,
1223 "%s(): no valid BER data\n", __func__
);
1226 bit_err
= ((u32
)(data
[0] & 0x0f) << 24) |
1227 ((u32
)data
[1] << 16) |
1228 ((u32
)data
[2] << 8) |
1230 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x6f, data
);
1231 period_exp
= data
[0] & 0x0f;
1232 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x22);
1233 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x5e, data
);
1234 n_ldpc
= ((data
[0] & 0x03) == 0 ? 16200 : 64800);
1235 if (bit_err
> ((1U << period_exp
) * n_ldpc
)) {
1236 dev_dbg(&priv
->i2c
->dev
,
1237 "%s(): invalid BER value\n", __func__
);
1240 if (period_exp
>= 4) {
1241 div
= (1U << (period_exp
- 4)) * (n_ldpc
/ 200);
1242 q
= div_u64_rem(3125ULL * bit_err
, div
, &r
);
1244 div
= (1U << period_exp
) * (n_ldpc
/ 200);
1245 q
= div_u64_rem(50000ULL * bit_err
, div
, &r
);
1247 *ber
= (r
>= div
/ 2) ? q
+ 1 : q
;
1251 static int cxd2841er_read_ber_t(struct cxd2841er_priv
*priv
, u32
*ber
)
1255 u32 bit_err
, period
;
1258 if (priv
->state
!= STATE_ACTIVE_TC
) {
1259 dev_dbg(&priv
->i2c
->dev
,
1260 "%s(): invalid state %d\n", __func__
, priv
->state
);
1263 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1264 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x39, data
);
1265 if (!(data
[0] & 0x01)) {
1266 dev_dbg(&priv
->i2c
->dev
,
1267 "%s(): no valid BER data\n", __func__
);
1270 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x22, data
, sizeof(data
));
1271 bit_err
= ((u32
)data
[0] << 8) | (u32
)data
[1];
1272 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x6f, data
);
1273 period
= ((data
[0] & 0x07) == 0) ? 256 : (4096 << (data
[0] & 0x07));
1275 q
= div_u64_rem(78125ULL * bit_err
, div
, &r
);
1276 *ber
= (r
>= div
/ 2) ? q
+ 1 : q
;
1280 static u32
cxd2841er_dvbs_read_snr(struct cxd2841er_priv
*priv
, u8 delsys
)
1284 int min_index
, max_index
, index
;
1285 static const struct cxd2841er_cnr_data
*cn_data
;
1287 /* Set SLV-T Bank : 0xA1 */
1288 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa1);
1290 * slave Bank Addr Bit Signal name
1291 * <SLV-T> A1h 10h [0] ICPM_QUICKRDY
1292 * <SLV-T> A1h 11h [4:0] ICPM_QUICKCNDT[12:8]
1293 * <SLV-T> A1h 12h [7:0] ICPM_QUICKCNDT[7:0]
1295 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x10, data
, 3);
1296 if (data
[0] & 0x01) {
1297 value
= ((u32
)(data
[1] & 0x1F) << 8) | (u32
)(data
[2] & 0xFF);
1299 if (delsys
== SYS_DVBS
) {
1300 cn_data
= s_cn_data
;
1301 max_index
= sizeof(s_cn_data
) /
1302 sizeof(s_cn_data
[0]) - 1;
1304 cn_data
= s2_cn_data
;
1305 max_index
= sizeof(s2_cn_data
) /
1306 sizeof(s2_cn_data
[0]) - 1;
1308 if (value
>= cn_data
[min_index
].value
) {
1309 res
= cn_data
[min_index
].cnr_x1000
;
1312 if (value
<= cn_data
[max_index
].value
) {
1313 res
= cn_data
[max_index
].cnr_x1000
;
1316 while ((max_index
- min_index
) > 1) {
1317 index
= (max_index
+ min_index
) / 2;
1318 if (value
== cn_data
[index
].value
) {
1319 res
= cn_data
[index
].cnr_x1000
;
1321 } else if (value
> cn_data
[index
].value
)
1325 if ((max_index
- min_index
) <= 1) {
1326 if (value
== cn_data
[max_index
].value
) {
1327 res
= cn_data
[max_index
].cnr_x1000
;
1330 res
= cn_data
[min_index
].cnr_x1000
;
1336 dev_dbg(&priv
->i2c
->dev
,
1337 "%s(): no data available\n", __func__
);
1343 static int cxd2841er_read_snr_t(struct cxd2841er_priv
*priv
, u32
*snr
)
1349 if (priv
->state
!= STATE_ACTIVE_TC
) {
1350 dev_dbg(&priv
->i2c
->dev
,
1351 "%s(): invalid state %d\n", __func__
, priv
->state
);
1354 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1355 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x28, data
, sizeof(data
));
1356 reg
= ((u32
)data
[0] << 8) | (u32
)data
[1];
1358 dev_dbg(&priv
->i2c
->dev
,
1359 "%s(): reg value out of range\n", __func__
);
1364 *snr
= 10000 * ((intlog10(reg
) - intlog10(5350 - reg
)) >> 24) + 28500;
1368 static int cxd2841er_read_snr_t2(struct cxd2841er_priv
*priv
, u32
*snr
)
1374 if (priv
->state
!= STATE_ACTIVE_TC
) {
1375 dev_dbg(&priv
->i2c
->dev
,
1376 "%s(): invalid state %d\n", __func__
, priv
->state
);
1379 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x20);
1380 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x28, data
, sizeof(data
));
1381 reg
= ((u32
)data
[0] << 8) | (u32
)data
[1];
1383 dev_dbg(&priv
->i2c
->dev
,
1384 "%s(): reg value out of range\n", __func__
);
1389 *snr
= 10000 * ((intlog10(reg
) -
1390 intlog10(12600 - reg
)) >> 24) + 32000;
1394 static u16
cxd2841er_read_agc_gain_t_t2(struct cxd2841er_priv
*priv
,
1399 cxd2841er_write_reg(
1400 priv
, I2C_SLVT
, 0x00, (delsys
== SYS_DVBT
? 0x10 : 0x20));
1401 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x26, data
, 2);
1402 return ((((u16
)data
[0] & 0x0F) << 8) | (u16
)(data
[1] & 0xFF)) << 4;
1405 static u16
cxd2841er_read_agc_gain_s(struct cxd2841er_priv
*priv
)
1409 /* Set SLV-T Bank : 0xA0 */
1410 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa0);
1412 * slave Bank Addr Bit Signal name
1413 * <SLV-T> A0h 1Fh [4:0] IRFAGC_GAIN[12:8]
1414 * <SLV-T> A0h 20h [7:0] IRFAGC_GAIN[7:0]
1416 cxd2841er_read_regs(priv
, I2C_SLVT
, 0x1f, data
, 2);
1417 return ((((u16
)data
[0] & 0x1F) << 8) | (u16
)(data
[1] & 0xFF)) << 3;
1420 static int cxd2841er_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
1422 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1423 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
1425 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1427 switch (p
->delivery_system
) {
1429 *ber
= cxd2841er_mon_read_ber_s(priv
);
1432 *ber
= cxd2841er_mon_read_ber_s2(priv
);
1435 return cxd2841er_read_ber_t(priv
, ber
);
1437 return cxd2841er_read_ber_t2(priv
, ber
);
1445 static int cxd2841er_read_signal_strength(struct dvb_frontend
*fe
,
1448 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1449 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
1451 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1452 switch (p
->delivery_system
) {
1455 *strength
= 65535 - cxd2841er_read_agc_gain_t_t2(
1456 priv
, p
->delivery_system
);
1460 *strength
= 65535 - cxd2841er_read_agc_gain_s(priv
);
1469 static int cxd2841er_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
1472 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1473 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
1475 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1476 switch (p
->delivery_system
) {
1478 cxd2841er_read_snr_t(priv
, &tmp
);
1481 cxd2841er_read_snr_t2(priv
, &tmp
);
1485 tmp
= cxd2841er_dvbs_read_snr(priv
, p
->delivery_system
);
1488 dev_dbg(&priv
->i2c
->dev
, "%s(): unknown delivery system %d\n",
1489 __func__
, p
->delivery_system
);
1492 *snr
= tmp
& 0xffff;
1496 static int cxd2841er_read_ucblocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
1498 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
1499 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
1501 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1502 switch (p
->delivery_system
) {
1504 cxd2841er_read_packet_errors_t(priv
, ucblocks
);
1507 cxd2841er_read_packet_errors_t2(priv
, ucblocks
);
1513 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1517 static int cxd2841er_dvbt2_set_profile(
1518 struct cxd2841er_priv
*priv
, enum cxd2841er_dvbt2_profile_t profile
)
1523 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1525 case DVBT2_PROFILE_BASE
:
1527 seq_not2d_time
= 12;
1529 case DVBT2_PROFILE_LITE
:
1531 seq_not2d_time
= 40;
1533 case DVBT2_PROFILE_ANY
:
1535 seq_not2d_time
= 40;
1540 /* Set SLV-T Bank : 0x2E */
1541 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2e);
1542 /* Set profile and tune mode */
1543 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x10, tune_mode
, 0x07);
1544 /* Set SLV-T Bank : 0x2B */
1545 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2b);
1546 /* Set early unlock detection time */
1547 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x9d, seq_not2d_time
);
1551 static int cxd2841er_dvbt2_set_plp_config(struct cxd2841er_priv
*priv
,
1552 u8 is_auto
, u8 plp_id
)
1555 dev_dbg(&priv
->i2c
->dev
,
1556 "%s() using auto PLP selection\n", __func__
);
1558 dev_dbg(&priv
->i2c
->dev
,
1559 "%s() using manual PLP selection, ID %d\n",
1562 /* Set SLV-T Bank : 0x23 */
1563 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x23);
1565 /* Manual PLP selection mode. Set the data PLP Id. */
1566 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xaf, plp_id
);
1568 /* Auto PLP select (Scanning mode = 0x00). Data PLP select = 0x01. */
1569 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xad, (is_auto
? 0x00 : 0x01));
1573 static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv
*priv
,
1582 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1583 switch (bandwidth
) {
1585 /* bank 0x20, reg 0x9f */
1591 /* bank 0x10, reg 0xa6 */
1606 iffreq
= MAKE_IFFREQ_CONFIG(4.80);
1610 /* bank 0x20, reg 0x9f */
1616 /* bank 0x10, reg 0xa6 */
1631 iffreq
= MAKE_IFFREQ_CONFIG(4.2);
1635 /* bank 0x20, reg 0x9f */
1641 /* bank 0x10, reg 0xa6 */
1656 iffreq
= MAKE_IFFREQ_CONFIG(3.6);
1660 /* bank 0x20, reg 0x9f */
1666 /* bank 0x10, reg 0xa6 */
1681 iffreq
= MAKE_IFFREQ_CONFIG(3.6);
1685 /* bank 0x20, reg 0x9f */
1691 /* bank 0x10, reg 0xa6 */
1706 iffreq
= MAKE_IFFREQ_CONFIG(3.5);
1712 /* Set SLV-T Bank : 0x20 */
1713 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x20);
1714 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x9f, b20_9f
, sizeof(b20_9f
));
1715 /* Set SLV-T Bank : 0x27 */
1716 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x27);
1717 cxd2841er_set_reg_bits(
1718 priv
, I2C_SLVT
, 0x7a,
1719 (bandwidth
== 1712000 ? 0x03 : 0x00), 0x0f);
1720 /* Set SLV-T Bank : 0x10 */
1721 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1722 /* Group delay equaliser sett. for ASCOT2E */
1723 cxd2841er_write_regs(priv
, I2C_SLVT
, 0xa6, b10_a6
, sizeof(b10_a6
));
1724 /* <IF freq setting> */
1725 b10_b6
[0] = (u8
) ((iffreq
>> 16) & 0xff);
1726 b10_b6
[1] = (u8
)((iffreq
>> 8) & 0xff);
1727 b10_b6
[2] = (u8
)(iffreq
& 0xff);
1728 cxd2841er_write_regs(priv
, I2C_SLVT
, 0xb6, b10_b6
, sizeof(b10_b6
));
1729 /* System bandwidth setting */
1730 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xd7, b10_d7
, 0x07);
1734 static int cxd2841er_sleep_tc_to_active_t_band(
1735 struct cxd2841er_priv
*priv
, u32 bandwidth
)
1737 u8 b13_9c
[2] = { 0x01, 0x14 };
1738 u8 bw8mhz_b10_9f
[] = { 0x11, 0xF0, 0x00, 0x00, 0x00 };
1739 u8 bw8mhz_b10_a6
[] = { 0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB,
1740 0x28, 0xBA, 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8 };
1741 u8 bw8mhz_b10_d9
[] = { 0x01, 0xE0 };
1742 u8 bw8mhz_b17_38
[] = { 0x01, 0x02 };
1743 u8 bw7mhz_b10_9f
[] = { 0x14, 0x80, 0x00, 0x00, 0x00 };
1744 u8 bw7mhz_b10_a6
[] = { 0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8,
1745 0x23, 0xA6, 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5 };
1746 u8 bw7mhz_b10_d9
[] = { 0x12, 0xF8 };
1747 u8 bw7mhz_b17_38
[] = { 0x00, 0x03 };
1748 u8 bw6mhz_b10_9f
[] = { 0x17, 0xEA, 0xAA, 0xAA, 0xAA };
1749 u8 bw6mhz_b10_a6
[] = { 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0,
1750 0x01, 0xE8, 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
1751 u8 bw6mhz_b10_d9
[] = { 0x1F, 0xDC };
1752 u8 bw6mhz_b17_38
[] = { 0x00, 0x03 };
1753 u8 bw5mhz_b10_9f
[] = { 0x1C, 0xB3, 0x33, 0x33, 0x33 };
1754 u8 bw5mhz_b10_a6
[] = { 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0,
1755 0x01, 0xE8, 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
1756 u8 bw5mhz_b10_d9
[] = { 0x26, 0x3C };
1757 u8 bw5mhz_b17_38
[] = { 0x00, 0x03 };
1766 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1767 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x13);
1768 /* Echo performance optimization setting */
1769 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x9c, b13_9c
, sizeof(b13_9c
));
1770 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1772 switch (bandwidth
) {
1774 b10_9f
= bw8mhz_b10_9f
;
1775 b10_a6
= bw8mhz_b10_a6
;
1776 b10_d9
= bw8mhz_b10_d9
;
1777 b17_38
= bw8mhz_b17_38
;
1779 iffreq
= MAKE_IFFREQ_CONFIG(4.80);
1782 b10_9f
= bw7mhz_b10_9f
;
1783 b10_a6
= bw7mhz_b10_a6
;
1784 b10_d9
= bw7mhz_b10_d9
;
1785 b17_38
= bw7mhz_b17_38
;
1787 iffreq
= MAKE_IFFREQ_CONFIG(4.20);
1790 b10_9f
= bw6mhz_b10_9f
;
1791 b10_a6
= bw6mhz_b10_a6
;
1792 b10_d9
= bw6mhz_b10_d9
;
1793 b17_38
= bw6mhz_b17_38
;
1795 iffreq
= MAKE_IFFREQ_CONFIG(3.60);
1798 b10_9f
= bw5mhz_b10_9f
;
1799 b10_a6
= bw5mhz_b10_a6
;
1800 b10_d9
= bw5mhz_b10_d9
;
1801 b17_38
= bw5mhz_b17_38
;
1803 iffreq
= MAKE_IFFREQ_CONFIG(3.60);
1806 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid bandwidth %d\n",
1807 __func__
, bandwidth
);
1810 /* <IF freq setting> */
1811 b10_b6
[0] = (u8
) ((iffreq
>> 16) & 0xff);
1812 b10_b6
[1] = (u8
)((iffreq
>> 8) & 0xff);
1813 b10_b6
[2] = (u8
)(iffreq
& 0xff);
1814 cxd2841er_write_regs(
1815 priv
, I2C_SLVT
, 0x9f, b10_9f
, sizeof(bw8mhz_b10_9f
));
1816 cxd2841er_write_regs(
1817 priv
, I2C_SLVT
, 0xa6, b10_a6
, sizeof(bw8mhz_b10_a6
));
1818 cxd2841er_write_regs(priv
, I2C_SLVT
, 0xb6, b10_b6
, sizeof(b10_b6
));
1819 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xd7, d7val
, 0x7);
1820 cxd2841er_write_regs(
1821 priv
, I2C_SLVT
, 0xd9, b10_d9
, sizeof(bw8mhz_b10_d9
));
1822 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x17);
1823 cxd2841er_write_regs(
1824 priv
, I2C_SLVT
, 0x38, b17_38
, sizeof(bw8mhz_b17_38
));
1828 static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv
*priv
,
1831 u8 bw7_8mhz_b10_a6
[] = {
1832 0x2D, 0xC7, 0x04, 0xF4, 0x07, 0xC5, 0x2A, 0xB8,
1833 0x27, 0x9E, 0x27, 0xA4, 0x29, 0xAB };
1834 u8 bw6mhz_b10_a6
[] = {
1835 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
1836 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
1840 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1841 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1842 switch (bandwidth
) {
1845 cxd2841er_write_regs(
1846 priv
, I2C_SLVT
, 0xa6,
1847 bw7_8mhz_b10_a6
, sizeof(bw7_8mhz_b10_a6
));
1848 iffreq
= MAKE_IFFREQ_CONFIG(4.9);
1851 cxd2841er_write_regs(
1852 priv
, I2C_SLVT
, 0xa6,
1853 bw6mhz_b10_a6
, sizeof(bw6mhz_b10_a6
));
1854 iffreq
= MAKE_IFFREQ_CONFIG(3.7);
1857 dev_dbg(&priv
->i2c
->dev
, "%s(): unsupported bandwidth %d\n",
1858 __func__
, bandwidth
);
1861 /* <IF freq setting> */
1862 b10_b6
[0] = (u8
) ((iffreq
>> 16) & 0xff);
1863 b10_b6
[1] = (u8
)((iffreq
>> 8) & 0xff);
1864 b10_b6
[2] = (u8
)(iffreq
& 0xff);
1865 cxd2841er_write_regs(priv
, I2C_SLVT
, 0xb6, b10_b6
, sizeof(b10_b6
));
1866 /* Set SLV-T Bank : 0x11 */
1867 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x11);
1868 switch (bandwidth
) {
1871 cxd2841er_set_reg_bits(
1872 priv
, I2C_SLVT
, 0xa3, 0x00, 0x1f);
1875 cxd2841er_set_reg_bits(
1876 priv
, I2C_SLVT
, 0xa3, 0x14, 0x1f);
1879 /* Set SLV-T Bank : 0x40 */
1880 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x40);
1881 switch (bandwidth
) {
1883 cxd2841er_set_reg_bits(
1884 priv
, I2C_SLVT
, 0x26, 0x0b, 0x0f);
1885 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x27, 0x3e);
1888 cxd2841er_set_reg_bits(
1889 priv
, I2C_SLVT
, 0x26, 0x09, 0x0f);
1890 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x27, 0xd6);
1893 cxd2841er_set_reg_bits(
1894 priv
, I2C_SLVT
, 0x26, 0x08, 0x0f);
1895 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x27, 0x6e);
1901 static int cxd2841er_sleep_tc_to_active_t(struct cxd2841er_priv
*priv
,
1904 u8 data
[2] = { 0x09, 0x54 };
1906 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1907 cxd2841er_set_ts_clock_mode(priv
, SYS_DVBT
);
1908 /* Set SLV-X Bank : 0x00 */
1909 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
1910 /* Set demod mode */
1911 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, 0x01);
1912 /* Set SLV-T Bank : 0x00 */
1913 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
1914 /* Enable demod clock */
1915 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x01);
1916 /* Disable RF level monitor */
1917 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2f, 0x00);
1918 /* Enable ADC clock */
1919 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
1921 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x1a);
1922 /* xtal freq 20.5MHz */
1923 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x43, data
, 2);
1925 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x00);
1926 /* Set SLV-T Bank : 0x10 */
1927 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1928 /* IFAGC gain settings */
1929 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xd2, 0x0c, 0x1f);
1930 /* Set SLV-T Bank : 0x11 */
1931 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x11);
1932 /* BBAGC TARGET level setting */
1933 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x6a, 0x50);
1934 /* Set SLV-T Bank : 0x10 */
1935 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1936 /* ASCOT setting ON */
1937 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xa5, 0x01, 0x01);
1938 /* Set SLV-T Bank : 0x18 */
1939 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x18);
1940 /* Pre-RS BER moniter setting */
1941 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x36, 0x40, 0x07);
1942 /* FEC Auto Recovery setting */
1943 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x30, 0x01, 0x01);
1944 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x31, 0x01, 0x01);
1945 /* Set SLV-T Bank : 0x00 */
1946 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
1948 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xce, 0x01, 0x01);
1949 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xcf, 0x01, 0x01);
1950 cxd2841er_sleep_tc_to_active_t_band(priv
, bandwidth
);
1951 /* Set SLV-T Bank : 0x00 */
1952 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
1953 /* Disable HiZ Setting 1 */
1954 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x28);
1955 /* Disable HiZ Setting 2 */
1956 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0x00);
1957 priv
->state
= STATE_ACTIVE_TC
;
1961 static int cxd2841er_sleep_tc_to_active_t2(struct cxd2841er_priv
*priv
,
1964 u8 data
[2] = { 0x09, 0x54 };
1966 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
1967 cxd2841er_set_ts_clock_mode(priv
, SYS_DVBT2
);
1968 /* Set SLV-X Bank : 0x00 */
1969 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
1970 /* Set demod mode */
1971 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, 0x02);
1972 /* Set SLV-T Bank : 0x00 */
1973 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
1974 /* Enable demod clock */
1975 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x01);
1976 /* Disable RF level monitor */
1977 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2f, 0x00);
1978 /* Enable ADC clock */
1979 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
1981 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x1a);
1982 /* xtal freq 20.5MHz */
1983 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x43, data
, 2);
1985 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x00);
1986 /* Set SLV-T Bank : 0x10 */
1987 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1988 /* IFAGC gain settings */
1989 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xd2, 0x0c, 0x1f);
1990 /* Set SLV-T Bank : 0x11 */
1991 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x11);
1992 /* BBAGC TARGET level setting */
1993 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x6a, 0x50);
1994 /* Set SLV-T Bank : 0x10 */
1995 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
1996 /* ASCOT setting ON */
1997 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xa5, 0x01, 0x01);
1998 /* Set SLV-T Bank : 0x20 */
1999 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x20);
2000 /* Acquisition optimization setting */
2001 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x8b, 0x3c);
2002 /* Set SLV-T Bank : 0x2b */
2003 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2b);
2004 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x76, 0x20, 0x70);
2005 /* Set SLV-T Bank : 0x00 */
2006 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
2008 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xce, 0x01, 0x01);
2009 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xcf, 0x01, 0x01);
2010 /* DVB-T2 initial setting */
2011 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x13);
2012 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x83, 0x10);
2013 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x86, 0x34);
2014 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x9e, 0x09, 0x0f);
2015 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x9f, 0xd8);
2016 /* Set SLV-T Bank : 0x2a */
2017 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2a);
2018 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x38, 0x04, 0x0f);
2019 /* Set SLV-T Bank : 0x2b */
2020 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x2b);
2021 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0x11, 0x20, 0x3f);
2023 cxd2841er_sleep_tc_to_active_t2_band(priv
, bandwidth
);
2025 /* Set SLV-T Bank : 0x00 */
2026 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
2027 /* Disable HiZ Setting 1 */
2028 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x28);
2029 /* Disable HiZ Setting 2 */
2030 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0x00);
2031 priv
->state
= STATE_ACTIVE_TC
;
2035 static int cxd2841er_sleep_tc_to_active_c(struct cxd2841er_priv
*priv
,
2038 u8 data
[2] = { 0x09, 0x54 };
2040 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2041 cxd2841er_set_ts_clock_mode(priv
, SYS_DVBC_ANNEX_A
);
2042 /* Set SLV-X Bank : 0x00 */
2043 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x00, 0x00);
2044 /* Set demod mode */
2045 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x17, 0x04);
2046 /* Set SLV-T Bank : 0x00 */
2047 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
2048 /* Enable demod clock */
2049 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2c, 0x01);
2050 /* Disable RF level monitor */
2051 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x2f, 0x00);
2052 /* Enable ADC clock */
2053 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x30, 0x00);
2055 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x41, 0x1a);
2056 /* xtal freq 20.5MHz */
2057 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x43, data
, 2);
2059 cxd2841er_write_reg(priv
, I2C_SLVX
, 0x18, 0x00);
2060 /* Set SLV-T Bank : 0x10 */
2061 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
2062 /* IFAGC gain settings */
2063 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xd2, 0x09, 0x1f);
2064 /* Set SLV-T Bank : 0x11 */
2065 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x11);
2066 /* BBAGC TARGET level setting */
2067 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x6a, 0x48);
2068 /* Set SLV-T Bank : 0x10 */
2069 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
2070 /* ASCOT setting ON */
2071 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xa5, 0x01, 0x01);
2072 /* Set SLV-T Bank : 0x40 */
2073 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x40);
2075 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xc3, 0x00, 0x04);
2076 /* Set SLV-T Bank : 0x00 */
2077 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
2079 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xce, 0x01, 0x01);
2080 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xcf, 0x01, 0x01);
2082 cxd2841er_sleep_tc_to_active_c_band(priv
, 8000000);
2083 /* Set SLV-T Bank : 0x00 */
2084 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
2085 /* Disable HiZ Setting 1 */
2086 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x80, 0x28);
2087 /* Disable HiZ Setting 2 */
2088 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x81, 0x00);
2089 priv
->state
= STATE_ACTIVE_TC
;
2093 static int cxd2841er_get_frontend(struct dvb_frontend
*fe
)
2095 enum fe_status status
= 0;
2096 u16 strength
= 0, snr
= 0;
2097 u32 errors
= 0, ber
= 0;
2098 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2099 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
2101 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2102 if (priv
->state
== STATE_ACTIVE_S
)
2103 cxd2841er_read_status_s(fe
, &status
);
2104 else if (priv
->state
== STATE_ACTIVE_TC
)
2105 cxd2841er_read_status_tc(fe
, &status
);
2107 if (status
& FE_HAS_LOCK
) {
2108 cxd2841er_read_signal_strength(fe
, &strength
);
2109 p
->strength
.len
= 1;
2110 p
->strength
.stat
[0].scale
= FE_SCALE_RELATIVE
;
2111 p
->strength
.stat
[0].uvalue
= strength
;
2112 cxd2841er_read_snr(fe
, &snr
);
2114 p
->cnr
.stat
[0].scale
= FE_SCALE_DECIBEL
;
2115 p
->cnr
.stat
[0].svalue
= snr
;
2116 cxd2841er_read_ucblocks(fe
, &errors
);
2117 p
->block_error
.len
= 1;
2118 p
->block_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
2119 p
->block_error
.stat
[0].uvalue
= errors
;
2120 cxd2841er_read_ber(fe
, &ber
);
2121 p
->post_bit_error
.len
= 1;
2122 p
->post_bit_error
.stat
[0].scale
= FE_SCALE_COUNTER
;
2123 p
->post_bit_error
.stat
[0].uvalue
= ber
;
2125 p
->strength
.len
= 1;
2126 p
->strength
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
2128 p
->cnr
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
2129 p
->block_error
.len
= 1;
2130 p
->block_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
2131 p
->post_bit_error
.len
= 1;
2132 p
->post_bit_error
.stat
[0].scale
= FE_SCALE_NOT_AVAILABLE
;
2137 static int cxd2841er_set_frontend_s(struct dvb_frontend
*fe
)
2139 int ret
= 0, i
, timeout
, carr_offset
;
2140 enum fe_status status
;
2141 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2142 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
2143 u32 symbol_rate
= p
->symbol_rate
/1000;
2145 dev_dbg(&priv
->i2c
->dev
, "%s(): %s frequency=%d symbol_rate=%d\n",
2147 (p
->delivery_system
== SYS_DVBS
? "DVB-S" : "DVB-S2"),
2148 p
->frequency
, symbol_rate
);
2149 switch (priv
->state
) {
2151 ret
= cxd2841er_sleep_s_to_active_s(
2152 priv
, p
->delivery_system
, symbol_rate
);
2154 case STATE_ACTIVE_S
:
2155 ret
= cxd2841er_retune_active(priv
, p
);
2158 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
2159 __func__
, priv
->state
);
2164 dev_dbg(&priv
->i2c
->dev
, "%s(): tune failed\n", __func__
);
2167 if (fe
->ops
.i2c_gate_ctrl
)
2168 fe
->ops
.i2c_gate_ctrl(fe
, 1);
2169 if (fe
->ops
.tuner_ops
.set_params
)
2170 fe
->ops
.tuner_ops
.set_params(fe
);
2171 if (fe
->ops
.i2c_gate_ctrl
)
2172 fe
->ops
.i2c_gate_ctrl(fe
, 0);
2173 cxd2841er_tune_done(priv
);
2174 timeout
= ((3000000 + (symbol_rate
- 1)) / symbol_rate
) + 150;
2175 for (i
= 0; i
< timeout
/ CXD2841ER_DVBS_POLLING_INVL
; i
++) {
2176 usleep_range(CXD2841ER_DVBS_POLLING_INVL
*1000,
2177 (CXD2841ER_DVBS_POLLING_INVL
+ 2) * 1000);
2178 cxd2841er_read_status_s(fe
, &status
);
2179 if (status
& FE_HAS_LOCK
)
2182 if (status
& FE_HAS_LOCK
) {
2183 if (cxd2841er_get_carrier_offset_s_s2(
2184 priv
, &carr_offset
)) {
2188 dev_dbg(&priv
->i2c
->dev
, "%s(): carrier_offset=%d\n",
2189 __func__
, carr_offset
);
2195 static int cxd2841er_set_frontend_tc(struct dvb_frontend
*fe
)
2197 int ret
= 0, timeout
;
2198 enum fe_status status
;
2199 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2200 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
2202 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2203 if (p
->delivery_system
== SYS_DVBT
) {
2204 priv
->system
= SYS_DVBT
;
2205 switch (priv
->state
) {
2206 case STATE_SLEEP_TC
:
2207 ret
= cxd2841er_sleep_tc_to_active_t(
2208 priv
, p
->bandwidth_hz
);
2210 case STATE_ACTIVE_TC
:
2211 ret
= cxd2841er_retune_active(priv
, p
);
2214 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
2215 __func__
, priv
->state
);
2218 } else if (p
->delivery_system
== SYS_DVBT2
) {
2219 priv
->system
= SYS_DVBT2
;
2220 cxd2841er_dvbt2_set_plp_config(priv
,
2221 (int)(p
->stream_id
> 255), p
->stream_id
);
2222 cxd2841er_dvbt2_set_profile(priv
, DVBT2_PROFILE_BASE
);
2223 switch (priv
->state
) {
2224 case STATE_SLEEP_TC
:
2225 ret
= cxd2841er_sleep_tc_to_active_t2(priv
,
2228 case STATE_ACTIVE_TC
:
2229 ret
= cxd2841er_retune_active(priv
, p
);
2232 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
2233 __func__
, priv
->state
);
2236 } else if (p
->delivery_system
== SYS_DVBC_ANNEX_A
||
2237 p
->delivery_system
== SYS_DVBC_ANNEX_C
) {
2238 priv
->system
= SYS_DVBC_ANNEX_A
;
2239 switch (priv
->state
) {
2240 case STATE_SLEEP_TC
:
2241 ret
= cxd2841er_sleep_tc_to_active_c(
2242 priv
, p
->bandwidth_hz
);
2244 case STATE_ACTIVE_TC
:
2245 ret
= cxd2841er_retune_active(priv
, p
);
2248 dev_dbg(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
2249 __func__
, priv
->state
);
2253 dev_dbg(&priv
->i2c
->dev
,
2254 "%s(): invalid delivery system %d\n",
2255 __func__
, p
->delivery_system
);
2260 if (fe
->ops
.i2c_gate_ctrl
)
2261 fe
->ops
.i2c_gate_ctrl(fe
, 1);
2262 if (fe
->ops
.tuner_ops
.set_params
)
2263 fe
->ops
.tuner_ops
.set_params(fe
);
2264 if (fe
->ops
.i2c_gate_ctrl
)
2265 fe
->ops
.i2c_gate_ctrl(fe
, 0);
2266 cxd2841er_tune_done(priv
);
2268 while (timeout
> 0) {
2269 ret
= cxd2841er_read_status_tc(fe
, &status
);
2272 if (status
& FE_HAS_LOCK
)
2278 dev_dbg(&priv
->i2c
->dev
,
2279 "%s(): LOCK wait timeout\n", __func__
);
2284 static int cxd2841er_tune_s(struct dvb_frontend
*fe
,
2286 unsigned int mode_flags
,
2287 unsigned int *delay
,
2288 enum fe_status
*status
)
2290 int ret
, carrier_offset
;
2291 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2292 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
2294 dev_dbg(&priv
->i2c
->dev
, "%s() re_tune=%d\n", __func__
, re_tune
);
2296 ret
= cxd2841er_set_frontend_s(fe
);
2299 cxd2841er_read_status_s(fe
, status
);
2300 if (*status
& FE_HAS_LOCK
) {
2301 if (cxd2841er_get_carrier_offset_s_s2(
2302 priv
, &carrier_offset
))
2304 p
->frequency
+= carrier_offset
;
2305 ret
= cxd2841er_set_frontend_s(fe
);
2311 return cxd2841er_read_status_s(fe
, status
);
2314 static int cxd2841er_tune_tc(struct dvb_frontend
*fe
,
2316 unsigned int mode_flags
,
2317 unsigned int *delay
,
2318 enum fe_status
*status
)
2320 int ret
, carrier_offset
;
2321 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2322 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
2324 dev_dbg(&priv
->i2c
->dev
, "%s(): re_tune %d\n", __func__
, re_tune
);
2326 ret
= cxd2841er_set_frontend_tc(fe
);
2329 cxd2841er_read_status_tc(fe
, status
);
2330 if (*status
& FE_HAS_LOCK
) {
2331 switch (priv
->system
) {
2334 ret
= cxd2841er_get_carrier_offset_t2(
2335 priv
, p
->bandwidth_hz
,
2338 case SYS_DVBC_ANNEX_A
:
2339 ret
= cxd2841er_get_carrier_offset_c(
2340 priv
, &carrier_offset
);
2343 dev_dbg(&priv
->i2c
->dev
,
2344 "%s(): invalid delivery system %d\n",
2345 __func__
, priv
->system
);
2350 dev_dbg(&priv
->i2c
->dev
, "%s(): carrier offset %d\n",
2351 __func__
, carrier_offset
);
2352 p
->frequency
+= carrier_offset
;
2353 ret
= cxd2841er_set_frontend_tc(fe
);
2359 return cxd2841er_read_status_tc(fe
, status
);
2362 static int cxd2841er_sleep_s(struct dvb_frontend
*fe
)
2364 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2366 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2367 cxd2841er_active_s_to_sleep_s(fe
->demodulator_priv
);
2368 cxd2841er_sleep_s_to_shutdown(fe
->demodulator_priv
);
2372 static int cxd2841er_sleep_tc(struct dvb_frontend
*fe
)
2374 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2376 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2377 if (priv
->state
== STATE_ACTIVE_TC
) {
2378 switch (priv
->system
) {
2380 cxd2841er_active_t_to_sleep_tc(priv
);
2383 cxd2841er_active_t2_to_sleep_tc(priv
);
2385 case SYS_DVBC_ANNEX_A
:
2386 cxd2841er_active_c_to_sleep_tc(priv
);
2389 dev_warn(&priv
->i2c
->dev
,
2390 "%s(): unknown delivery system %d\n",
2391 __func__
, priv
->system
);
2394 if (priv
->state
!= STATE_SLEEP_TC
) {
2395 dev_err(&priv
->i2c
->dev
, "%s(): invalid state %d\n",
2396 __func__
, priv
->state
);
2399 cxd2841er_sleep_tc_to_shutdown(priv
);
2403 static int cxd2841er_send_burst(struct dvb_frontend
*fe
,
2404 enum fe_sec_mini_cmd burst
)
2407 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2409 dev_dbg(&priv
->i2c
->dev
, "%s(): burst mode %s\n", __func__
,
2410 (burst
== SEC_MINI_A
? "A" : "B"));
2411 if (priv
->state
!= STATE_SLEEP_S
&&
2412 priv
->state
!= STATE_ACTIVE_S
) {
2413 dev_err(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
2414 __func__
, priv
->state
);
2417 data
= (burst
== SEC_MINI_A
? 0 : 1);
2418 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xbb);
2419 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x34, 0x01);
2420 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x35, data
);
2424 static int cxd2841er_set_tone(struct dvb_frontend
*fe
,
2425 enum fe_sec_tone_mode tone
)
2428 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2430 dev_dbg(&priv
->i2c
->dev
, "%s(): tone %s\n", __func__
,
2431 (tone
== SEC_TONE_ON
? "On" : "Off"));
2432 if (priv
->state
!= STATE_SLEEP_S
&&
2433 priv
->state
!= STATE_ACTIVE_S
) {
2434 dev_err(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
2435 __func__
, priv
->state
);
2438 data
= (tone
== SEC_TONE_ON
? 1 : 0);
2439 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xbb);
2440 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x36, data
);
2444 static int cxd2841er_send_diseqc_msg(struct dvb_frontend
*fe
,
2445 struct dvb_diseqc_master_cmd
*cmd
)
2449 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2451 if (priv
->state
!= STATE_SLEEP_S
&&
2452 priv
->state
!= STATE_ACTIVE_S
) {
2453 dev_err(&priv
->i2c
->dev
, "%s(): invalid demod state %d\n",
2454 __func__
, priv
->state
);
2457 dev_dbg(&priv
->i2c
->dev
,
2458 "%s(): cmd->len %d\n", __func__
, cmd
->msg_len
);
2459 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xbb);
2461 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x33, 0x01);
2462 /* cmd1 length & data */
2463 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x3d, cmd
->msg_len
);
2464 memset(data
, 0, sizeof(data
));
2465 for (i
= 0; i
< cmd
->msg_len
&& i
< sizeof(data
); i
++)
2466 data
[i
] = cmd
->msg
[i
];
2467 cxd2841er_write_regs(priv
, I2C_SLVT
, 0x3e, data
, sizeof(data
));
2468 /* repeat count for cmd1 */
2469 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x37, 1);
2470 /* repeat count for cmd2: always 0 */
2471 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x38, 0);
2472 /* start transmit */
2473 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x32, 0x01);
2474 /* wait for 1 sec timeout */
2475 for (i
= 0; i
< 50; i
++) {
2476 cxd2841er_read_reg(priv
, I2C_SLVT
, 0x10, data
);
2478 dev_dbg(&priv
->i2c
->dev
,
2479 "%s(): DiSEqC cmd has been sent\n", __func__
);
2484 dev_dbg(&priv
->i2c
->dev
,
2485 "%s(): DiSEqC cmd transmit timeout\n", __func__
);
2489 static void cxd2841er_release(struct dvb_frontend
*fe
)
2491 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2493 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2497 static int cxd2841er_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
2499 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2501 dev_dbg(&priv
->i2c
->dev
, "%s(): enable=%d\n", __func__
, enable
);
2502 cxd2841er_set_reg_bits(
2503 priv
, I2C_SLVX
, 0x8, (enable
? 0x01 : 0x00), 0x01);
2507 static enum dvbfe_algo
cxd2841er_get_algo(struct dvb_frontend
*fe
)
2509 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2511 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2512 return DVBFE_ALGO_HW
;
2515 static int cxd2841er_init_s(struct dvb_frontend
*fe
)
2517 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2519 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2520 cxd2841er_shutdown_to_sleep_s(priv
);
2521 /* SONY_DEMOD_CONFIG_SAT_IFAGCNEG set to 1 */
2522 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0xa0);
2523 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xb9, 0x01, 0x01);
2527 static int cxd2841er_init_tc(struct dvb_frontend
*fe
)
2529 struct cxd2841er_priv
*priv
= fe
->demodulator_priv
;
2531 dev_dbg(&priv
->i2c
->dev
, "%s()\n", __func__
);
2532 cxd2841er_shutdown_to_sleep_tc(priv
);
2533 /* SONY_DEMOD_CONFIG_IFAGCNEG = 1 */
2534 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x10);
2535 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xcb, 0x40, 0x40);
2536 /* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */
2537 cxd2841er_write_reg(priv
, I2C_SLVT
, 0xcd, 0x50);
2538 /* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */
2539 cxd2841er_write_reg(priv
, I2C_SLVT
, 0x00, 0x00);
2540 cxd2841er_set_reg_bits(priv
, I2C_SLVT
, 0xc4, 0x00, 0x80);
2544 static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops
;
2545 static struct dvb_frontend_ops cxd2841er_dvbt_t2_ops
;
2546 static struct dvb_frontend_ops cxd2841er_dvbc_ops
;
2548 static struct dvb_frontend
*cxd2841er_attach(struct cxd2841er_config
*cfg
,
2549 struct i2c_adapter
*i2c
,
2554 struct cxd2841er_priv
*priv
= NULL
;
2556 /* allocate memory for the internal state */
2557 priv
= kzalloc(sizeof(struct cxd2841er_priv
), GFP_KERNEL
);
2562 priv
->i2c_addr_slvx
= (cfg
->i2c_addr
+ 4) >> 1;
2563 priv
->i2c_addr_slvt
= (cfg
->i2c_addr
) >> 1;
2564 /* create dvb_frontend */
2567 memcpy(&priv
->frontend
.ops
,
2568 &cxd2841er_dvbs_s2_ops
,
2569 sizeof(struct dvb_frontend_ops
));
2573 memcpy(&priv
->frontend
.ops
,
2574 &cxd2841er_dvbt_t2_ops
,
2575 sizeof(struct dvb_frontend_ops
));
2578 case SYS_DVBC_ANNEX_A
:
2579 memcpy(&priv
->frontend
.ops
,
2580 &cxd2841er_dvbc_ops
,
2581 sizeof(struct dvb_frontend_ops
));
2588 priv
->frontend
.demodulator_priv
= priv
;
2589 dev_info(&priv
->i2c
->dev
,
2590 "%s(): attaching CXD2841ER DVB-%s frontend\n",
2592 dev_info(&priv
->i2c
->dev
,
2593 "%s(): I2C adapter %p SLVX addr %x SLVT addr %x\n",
2594 __func__
, priv
->i2c
,
2595 priv
->i2c_addr_slvx
, priv
->i2c_addr_slvt
);
2596 chip_id
= cxd2841er_chip_id(priv
);
2597 if (chip_id
!= CXD2841ER_CHIP_ID
) {
2598 dev_err(&priv
->i2c
->dev
, "%s(): invalid chip ID 0x%02x\n",
2600 priv
->frontend
.demodulator_priv
= NULL
;
2604 dev_info(&priv
->i2c
->dev
, "%s(): chip ID 0x%02x OK.\n",
2606 return &priv
->frontend
;
2609 struct dvb_frontend
*cxd2841er_attach_s(struct cxd2841er_config
*cfg
,
2610 struct i2c_adapter
*i2c
)
2612 return cxd2841er_attach(cfg
, i2c
, SYS_DVBS
);
2614 EXPORT_SYMBOL(cxd2841er_attach_s
);
2616 struct dvb_frontend
*cxd2841er_attach_t(struct cxd2841er_config
*cfg
,
2617 struct i2c_adapter
*i2c
)
2619 return cxd2841er_attach(cfg
, i2c
, SYS_DVBT
);
2621 EXPORT_SYMBOL(cxd2841er_attach_t
);
2623 struct dvb_frontend
*cxd2841er_attach_c(struct cxd2841er_config
*cfg
,
2624 struct i2c_adapter
*i2c
)
2626 return cxd2841er_attach(cfg
, i2c
, SYS_DVBC_ANNEX_A
);
2628 EXPORT_SYMBOL(cxd2841er_attach_c
);
2630 static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops
= {
2631 .delsys
= { SYS_DVBS
, SYS_DVBS2
},
2633 .name
= "Sony CXD2841ER DVB-S/S2 demodulator",
2634 .frequency_min
= 500000,
2635 .frequency_max
= 2500000,
2636 .frequency_stepsize
= 0,
2637 .symbol_rate_min
= 1000000,
2638 .symbol_rate_max
= 45000000,
2639 .symbol_rate_tolerance
= 500,
2640 .caps
= FE_CAN_INVERSION_AUTO
|
2644 .init
= cxd2841er_init_s
,
2645 .sleep
= cxd2841er_sleep_s
,
2646 .release
= cxd2841er_release
,
2647 .set_frontend
= cxd2841er_set_frontend_s
,
2648 .get_frontend
= cxd2841er_get_frontend
,
2649 .read_status
= cxd2841er_read_status_s
,
2650 .i2c_gate_ctrl
= cxd2841er_i2c_gate_ctrl
,
2651 .get_frontend_algo
= cxd2841er_get_algo
,
2652 .set_tone
= cxd2841er_set_tone
,
2653 .diseqc_send_burst
= cxd2841er_send_burst
,
2654 .diseqc_send_master_cmd
= cxd2841er_send_diseqc_msg
,
2655 .tune
= cxd2841er_tune_s
2658 static struct dvb_frontend_ops cxd2841er_dvbt_t2_ops
= {
2659 .delsys
= { SYS_DVBT
, SYS_DVBT2
},
2661 .name
= "Sony CXD2841ER DVB-T/T2 demodulator",
2662 .caps
= FE_CAN_FEC_1_2
|
2675 FE_CAN_TRANSMISSION_MODE_AUTO
|
2676 FE_CAN_GUARD_INTERVAL_AUTO
|
2677 FE_CAN_HIERARCHY_AUTO
|
2679 FE_CAN_2G_MODULATION
,
2680 .frequency_min
= 42000000,
2681 .frequency_max
= 1002000000
2683 .init
= cxd2841er_init_tc
,
2684 .sleep
= cxd2841er_sleep_tc
,
2685 .release
= cxd2841er_release
,
2686 .set_frontend
= cxd2841er_set_frontend_tc
,
2687 .get_frontend
= cxd2841er_get_frontend
,
2688 .read_status
= cxd2841er_read_status_tc
,
2689 .tune
= cxd2841er_tune_tc
,
2690 .i2c_gate_ctrl
= cxd2841er_i2c_gate_ctrl
,
2691 .get_frontend_algo
= cxd2841er_get_algo
2694 static struct dvb_frontend_ops cxd2841er_dvbc_ops
= {
2695 .delsys
= { SYS_DVBC_ANNEX_A
},
2697 .name
= "Sony CXD2841ER DVB-C demodulator",
2698 .caps
= FE_CAN_FEC_1_2
|
2710 FE_CAN_INVERSION_AUTO
,
2711 .frequency_min
= 42000000,
2712 .frequency_max
= 1002000000
2714 .init
= cxd2841er_init_tc
,
2715 .sleep
= cxd2841er_sleep_tc
,
2716 .release
= cxd2841er_release
,
2717 .set_frontend
= cxd2841er_set_frontend_tc
,
2718 .get_frontend
= cxd2841er_get_frontend
,
2719 .read_status
= cxd2841er_read_status_tc
,
2720 .tune
= cxd2841er_tune_tc
,
2721 .i2c_gate_ctrl
= cxd2841er_i2c_gate_ctrl
,
2722 .get_frontend_algo
= cxd2841er_get_algo
,
2725 MODULE_DESCRIPTION("Sony CXD2841ER DVB-C/C2/T/T2/S/S2 demodulator driver");
2726 MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>");
2727 MODULE_LICENSE("GPL");