4 * Sony digital demodulator driver for
5 * CXD2841ER - DVB-S/S2/T/T2/C/C2
6 * CXD2854ER - DVB-S/S2/T/T2/C/C2, ISDB-T/S
8 * Copyright 2012 Sony Corporation
9 * Copyright (C) 2014 NetUP Inc.
10 * Copyright (C) 2014 Sergey Kozlov <serjk@netup.ru>
11 * Copyright (C) 2014 Abylay Ospan <aospan@netup.ru>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/string.h>
27 #include <linux/slab.h>
28 #include <linux/bitops.h>
29 #include <linux/math64.h>
30 #include <linux/log2.h>
31 #include <linux/dynamic_debug.h>
34 #include "dvb_frontend.h"
35 #include "cxd2841er.h"
36 #include "cxd2841er_priv.h"
38 #define MAX_WRITE_REGSIZE 16
39 #define LOG2_E_100X 144
41 #define INTLOG10X100(x) ((u32) (((u64) intlog10(x) * 100) >> 24))
43 /* DVB-C constellation */
44 enum sony_dvbc_constellation_t {
45 SONY_DVBC_CONSTELLATION_16QAM,
46 SONY_DVBC_CONSTELLATION_32QAM,
47 SONY_DVBC_CONSTELLATION_64QAM,
48 SONY_DVBC_CONSTELLATION_128QAM,
49 SONY_DVBC_CONSTELLATION_256QAM
52 enum cxd2841er_state {
60 struct cxd2841er_priv {
61 struct dvb_frontend frontend;
62 struct i2c_adapter *i2c;
65 const struct cxd2841er_config *config;
66 enum cxd2841er_state state;
68 enum cxd2841er_xtal xtal;
73 static const struct cxd2841er_cnr_data s_cn_data[] = {
74 { 0x033e, 0 }, { 0x0339, 100 }, { 0x0333, 200 },
75 { 0x032e, 300 }, { 0x0329, 400 }, { 0x0324, 500 },
76 { 0x031e, 600 }, { 0x0319, 700 }, { 0x0314, 800 },
77 { 0x030f, 900 }, { 0x030a, 1000 }, { 0x02ff, 1100 },
78 { 0x02f4, 1200 }, { 0x02e9, 1300 }, { 0x02de, 1400 },
79 { 0x02d4, 1500 }, { 0x02c9, 1600 }, { 0x02bf, 1700 },
80 { 0x02b5, 1800 }, { 0x02ab, 1900 }, { 0x02a1, 2000 },
81 { 0x029b, 2100 }, { 0x0295, 2200 }, { 0x0290, 2300 },
82 { 0x028a, 2400 }, { 0x0284, 2500 }, { 0x027f, 2600 },
83 { 0x0279, 2700 }, { 0x0274, 2800 }, { 0x026e, 2900 },
84 { 0x0269, 3000 }, { 0x0262, 3100 }, { 0x025c, 3200 },
85 { 0x0255, 3300 }, { 0x024f, 3400 }, { 0x0249, 3500 },
86 { 0x0242, 3600 }, { 0x023c, 3700 }, { 0x0236, 3800 },
87 { 0x0230, 3900 }, { 0x022a, 4000 }, { 0x0223, 4100 },
88 { 0x021c, 4200 }, { 0x0215, 4300 }, { 0x020e, 4400 },
89 { 0x0207, 4500 }, { 0x0201, 4600 }, { 0x01fa, 4700 },
90 { 0x01f4, 4800 }, { 0x01ed, 4900 }, { 0x01e7, 5000 },
91 { 0x01e0, 5100 }, { 0x01d9, 5200 }, { 0x01d2, 5300 },
92 { 0x01cb, 5400 }, { 0x01c4, 5500 }, { 0x01be, 5600 },
93 { 0x01b7, 5700 }, { 0x01b1, 5800 }, { 0x01aa, 5900 },
94 { 0x01a4, 6000 }, { 0x019d, 6100 }, { 0x0196, 6200 },
95 { 0x018f, 6300 }, { 0x0189, 6400 }, { 0x0182, 6500 },
96 { 0x017c, 6600 }, { 0x0175, 6700 }, { 0x016f, 6800 },
97 { 0x0169, 6900 }, { 0x0163, 7000 }, { 0x015c, 7100 },
98 { 0x0156, 7200 }, { 0x0150, 7300 }, { 0x014a, 7400 },
99 { 0x0144, 7500 }, { 0x013e, 7600 }, { 0x0138, 7700 },
100 { 0x0132, 7800 }, { 0x012d, 7900 }, { 0x0127, 8000 },
101 { 0x0121, 8100 }, { 0x011c, 8200 }, { 0x0116, 8300 },
102 { 0x0111, 8400 }, { 0x010b, 8500 }, { 0x0106, 8600 },
103 { 0x0101, 8700 }, { 0x00fc, 8800 }, { 0x00f7, 8900 },
104 { 0x00f2, 9000 }, { 0x00ee, 9100 }, { 0x00ea, 9200 },
105 { 0x00e6, 9300 }, { 0x00e2, 9400 }, { 0x00de, 9500 },
106 { 0x00da, 9600 }, { 0x00d7, 9700 }, { 0x00d3, 9800 },
107 { 0x00d0, 9900 }, { 0x00cc, 10000 }, { 0x00c7, 10100 },
108 { 0x00c3, 10200 }, { 0x00bf, 10300 }, { 0x00ba, 10400 },
109 { 0x00b6, 10500 }, { 0x00b2, 10600 }, { 0x00ae, 10700 },
110 { 0x00aa, 10800 }, { 0x00a7, 10900 }, { 0x00a3, 11000 },
111 { 0x009f, 11100 }, { 0x009c, 11200 }, { 0x0098, 11300 },
112 { 0x0094, 11400 }, { 0x0091, 11500 }, { 0x008e, 11600 },
113 { 0x008a, 11700 }, { 0x0087, 11800 }, { 0x0084, 11900 },
114 { 0x0081, 12000 }, { 0x007e, 12100 }, { 0x007b, 12200 },
115 { 0x0079, 12300 }, { 0x0076, 12400 }, { 0x0073, 12500 },
116 { 0x0071, 12600 }, { 0x006e, 12700 }, { 0x006c, 12800 },
117 { 0x0069, 12900 }, { 0x0067, 13000 }, { 0x0065, 13100 },
118 { 0x0062, 13200 }, { 0x0060, 13300 }, { 0x005e, 13400 },
119 { 0x005c, 13500 }, { 0x005a, 13600 }, { 0x0058, 13700 },
120 { 0x0056, 13800 }, { 0x0054, 13900 }, { 0x0052, 14000 },
121 { 0x0050, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
122 { 0x004b, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
123 { 0x0046, 14700 }, { 0x0044, 14800 }, { 0x0043, 14900 },
124 { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
125 { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
126 { 0x0037, 15700 }, { 0x0036, 15800 }, { 0x0034, 15900 },
127 { 0x0033, 16000 }, { 0x0032, 16100 }, { 0x0031, 16200 },
128 { 0x0030, 16300 }, { 0x002f, 16400 }, { 0x002e, 16500 },
129 { 0x002d, 16600 }, { 0x002c, 16700 }, { 0x002b, 16800 },
130 { 0x002a, 16900 }, { 0x0029, 17000 }, { 0x0028, 17100 },
131 { 0x0027, 17200 }, { 0x0026, 17300 }, { 0x0025, 17400 },
132 { 0x0024, 17500 }, { 0x0023, 17600 }, { 0x0022, 17800 },
133 { 0x0021, 17900 }, { 0x0020, 18000 }, { 0x001f, 18200 },
134 { 0x001e, 18300 }, { 0x001d, 18500 }, { 0x001c, 18700 },
135 { 0x001b, 18900 }, { 0x001a, 19000 }, { 0x0019, 19200 },
136 { 0x0018, 19300 }, { 0x0017, 19500 }, { 0x0016, 19700 },
137 { 0x0015, 19900 }, { 0x0014, 20000 },
140 static const struct cxd2841er_cnr_data s2_cn_data[] = {
141 { 0x05af, 0 }, { 0x0597, 100 }, { 0x057e, 200 },
142 { 0x0567, 300 }, { 0x0550, 400 }, { 0x0539, 500 },
143 { 0x0522, 600 }, { 0x050c, 700 }, { 0x04f6, 800 },
144 { 0x04e1, 900 }, { 0x04cc, 1000 }, { 0x04b6, 1100 },
145 { 0x04a1, 1200 }, { 0x048c, 1300 }, { 0x0477, 1400 },
146 { 0x0463, 1500 }, { 0x044f, 1600 }, { 0x043c, 1700 },
147 { 0x0428, 1800 }, { 0x0416, 1900 }, { 0x0403, 2000 },
148 { 0x03ef, 2100 }, { 0x03dc, 2200 }, { 0x03c9, 2300 },
149 { 0x03b6, 2400 }, { 0x03a4, 2500 }, { 0x0392, 2600 },
150 { 0x0381, 2700 }, { 0x036f, 2800 }, { 0x035f, 2900 },
151 { 0x034e, 3000 }, { 0x033d, 3100 }, { 0x032d, 3200 },
152 { 0x031d, 3300 }, { 0x030d, 3400 }, { 0x02fd, 3500 },
153 { 0x02ee, 3600 }, { 0x02df, 3700 }, { 0x02d0, 3800 },
154 { 0x02c2, 3900 }, { 0x02b4, 4000 }, { 0x02a6, 4100 },
155 { 0x0299, 4200 }, { 0x028c, 4300 }, { 0x027f, 4400 },
156 { 0x0272, 4500 }, { 0x0265, 4600 }, { 0x0259, 4700 },
157 { 0x024d, 4800 }, { 0x0241, 4900 }, { 0x0236, 5000 },
158 { 0x022b, 5100 }, { 0x0220, 5200 }, { 0x0215, 5300 },
159 { 0x020a, 5400 }, { 0x0200, 5500 }, { 0x01f6, 5600 },
160 { 0x01ec, 5700 }, { 0x01e2, 5800 }, { 0x01d8, 5900 },
161 { 0x01cf, 6000 }, { 0x01c6, 6100 }, { 0x01bc, 6200 },
162 { 0x01b3, 6300 }, { 0x01aa, 6400 }, { 0x01a2, 6500 },
163 { 0x0199, 6600 }, { 0x0191, 6700 }, { 0x0189, 6800 },
164 { 0x0181, 6900 }, { 0x0179, 7000 }, { 0x0171, 7100 },
165 { 0x0169, 7200 }, { 0x0161, 7300 }, { 0x015a, 7400 },
166 { 0x0153, 7500 }, { 0x014b, 7600 }, { 0x0144, 7700 },
167 { 0x013d, 7800 }, { 0x0137, 7900 }, { 0x0130, 8000 },
168 { 0x012a, 8100 }, { 0x0124, 8200 }, { 0x011e, 8300 },
169 { 0x0118, 8400 }, { 0x0112, 8500 }, { 0x010c, 8600 },
170 { 0x0107, 8700 }, { 0x0101, 8800 }, { 0x00fc, 8900 },
171 { 0x00f7, 9000 }, { 0x00f2, 9100 }, { 0x00ec, 9200 },
172 { 0x00e7, 9300 }, { 0x00e2, 9400 }, { 0x00dd, 9500 },
173 { 0x00d8, 9600 }, { 0x00d4, 9700 }, { 0x00cf, 9800 },
174 { 0x00ca, 9900 }, { 0x00c6, 10000 }, { 0x00c2, 10100 },
175 { 0x00be, 10200 }, { 0x00b9, 10300 }, { 0x00b5, 10400 },
176 { 0x00b1, 10500 }, { 0x00ae, 10600 }, { 0x00aa, 10700 },
177 { 0x00a6, 10800 }, { 0x00a3, 10900 }, { 0x009f, 11000 },
178 { 0x009b, 11100 }, { 0x0098, 11200 }, { 0x0095, 11300 },
179 { 0x0091, 11400 }, { 0x008e, 11500 }, { 0x008b, 11600 },
180 { 0x0088, 11700 }, { 0x0085, 11800 }, { 0x0082, 11900 },
181 { 0x007f, 12000 }, { 0x007c, 12100 }, { 0x007a, 12200 },
182 { 0x0077, 12300 }, { 0x0074, 12400 }, { 0x0072, 12500 },
183 { 0x006f, 12600 }, { 0x006d, 12700 }, { 0x006b, 12800 },
184 { 0x0068, 12900 }, { 0x0066, 13000 }, { 0x0064, 13100 },
185 { 0x0061, 13200 }, { 0x005f, 13300 }, { 0x005d, 13400 },
186 { 0x005b, 13500 }, { 0x0059, 13600 }, { 0x0057, 13700 },
187 { 0x0055, 13800 }, { 0x0053, 13900 }, { 0x0051, 14000 },
188 { 0x004f, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 },
189 { 0x004a, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 },
190 { 0x0045, 14700 }, { 0x0044, 14800 }, { 0x0042, 14900 },
191 { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 },
192 { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 },
193 { 0x0038, 15600 }, { 0x0037, 15700 }, { 0x0036, 15800 },
194 { 0x0034, 15900 }, { 0x0033, 16000 }, { 0x0032, 16100 },
195 { 0x0031, 16200 }, { 0x0030, 16300 }, { 0x002f, 16400 },
196 { 0x002e, 16500 }, { 0x002d, 16600 }, { 0x002c, 16700 },
197 { 0x002b, 16800 }, { 0x002a, 16900 }, { 0x0029, 17000 },
198 { 0x0028, 17100 }, { 0x0027, 17200 }, { 0x0026, 17300 },
199 { 0x0025, 17400 }, { 0x0024, 17500 }, { 0x0023, 17600 },
200 { 0x0022, 17800 }, { 0x0021, 17900 }, { 0x0020, 18000 },
201 { 0x001f, 18200 }, { 0x001e, 18300 }, { 0x001d, 18500 },
202 { 0x001c, 18700 }, { 0x001b, 18900 }, { 0x001a, 19000 },
203 { 0x0019, 19200 }, { 0x0018, 19300 }, { 0x0017, 19500 },
204 { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 },
207 static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv);
208 static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv);
210 static void cxd2841er_i2c_debug(struct cxd2841er_priv *priv,
211 u8 addr, u8 reg, u8 write,
212 const u8 *data, u32 len)
214 dev_dbg(&priv->i2c->dev,
215 "cxd2841er: I2C %s addr %02x reg 0x%02x size %d data %*ph\n",
216 (write == 0 ? "read" : "write"), addr, reg, len, len, data);
219 static int cxd2841er_write_regs(struct cxd2841er_priv *priv,
220 u8 addr, u8 reg, const u8 *data, u32 len)
223 u8 buf[MAX_WRITE_REGSIZE + 1];
224 u8 i2c_addr = (addr == I2C_SLVX ?
225 priv->i2c_addr_slvx : priv->i2c_addr_slvt);
226 struct i2c_msg msg[1] = {
235 if (len + 1 >= sizeof(buf)) {
236 dev_warn(&priv->i2c->dev, "wr reg=%04x: len=%d is too big!\n",
241 cxd2841er_i2c_debug(priv, i2c_addr, reg, 1, data, len);
243 memcpy(&buf[1], data, len);
245 ret = i2c_transfer(priv->i2c, msg, 1);
246 if (ret >= 0 && ret != 1)
249 dev_warn(&priv->i2c->dev,
250 "%s: i2c wr failed=%d addr=%02x reg=%02x len=%d\n",
251 KBUILD_MODNAME, ret, i2c_addr, reg, len);
257 static int cxd2841er_write_reg(struct cxd2841er_priv *priv,
258 u8 addr, u8 reg, u8 val)
260 return cxd2841er_write_regs(priv, addr, reg, &val, 1);
263 static int cxd2841er_read_regs(struct cxd2841er_priv *priv,
264 u8 addr, u8 reg, u8 *val, u32 len)
267 u8 i2c_addr = (addr == I2C_SLVX ?
268 priv->i2c_addr_slvx : priv->i2c_addr_slvt);
269 struct i2c_msg msg[2] = {
283 ret = i2c_transfer(priv->i2c, msg, 2);
284 if (ret >= 0 && ret != 2)
287 dev_warn(&priv->i2c->dev,
288 "%s: i2c rd failed=%d addr=%02x reg=%02x\n",
289 KBUILD_MODNAME, ret, i2c_addr, reg);
292 cxd2841er_i2c_debug(priv, i2c_addr, reg, 0, val, len);
296 static int cxd2841er_read_reg(struct cxd2841er_priv *priv,
297 u8 addr, u8 reg, u8 *val)
299 return cxd2841er_read_regs(priv, addr, reg, val, 1);
302 static int cxd2841er_set_reg_bits(struct cxd2841er_priv *priv,
303 u8 addr, u8 reg, u8 data, u8 mask)
309 res = cxd2841er_read_reg(priv, addr, reg, &rdata);
312 data = ((data & mask) | (rdata & (mask ^ 0xFF)));
314 return cxd2841er_write_reg(priv, addr, reg, data);
317 static u32 cxd2841er_calc_iffreq_xtal(enum cxd2841er_xtal xtal, u32 ifhz)
321 tmp = (u64) ifhz * 16777216;
322 do_div(tmp, ((xtal == SONY_XTAL_24000) ? 48000000 : 41000000));
327 static u32 cxd2841er_calc_iffreq(u32 ifhz)
329 return cxd2841er_calc_iffreq_xtal(SONY_XTAL_20500, ifhz);
332 static int cxd2841er_get_if_hz(struct cxd2841er_priv *priv, u32 def_hz)
336 if (priv->frontend.ops.tuner_ops.get_if_frequency
337 && (priv->flags & CXD2841ER_AUTO_IFHZ))
338 priv->frontend.ops.tuner_ops.get_if_frequency(
339 &priv->frontend, &hz);
346 static int cxd2841er_tuner_set(struct dvb_frontend *fe)
348 struct cxd2841er_priv *priv = fe->demodulator_priv;
350 if ((priv->flags & CXD2841ER_USE_GATECTRL) && fe->ops.i2c_gate_ctrl)
351 fe->ops.i2c_gate_ctrl(fe, 1);
352 if (fe->ops.tuner_ops.set_params)
353 fe->ops.tuner_ops.set_params(fe);
354 if ((priv->flags & CXD2841ER_USE_GATECTRL) && fe->ops.i2c_gate_ctrl)
355 fe->ops.i2c_gate_ctrl(fe, 0);
360 static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv *priv,
364 u8 data[3] = {0, 0, 0};
366 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
368 * regValue = (symbolRateKSps * 2^14 / 1000) + 0.5
369 * = ((symbolRateKSps * 2^14) + 500) / 1000
370 * = ((symbolRateKSps * 16384) + 500) / 1000
372 reg_value = DIV_ROUND_CLOSEST(symbol_rate * 16384, 1000);
373 if ((reg_value == 0) || (reg_value > 0xFFFFF)) {
374 dev_err(&priv->i2c->dev,
375 "%s(): reg_value is out of range\n", __func__);
378 data[0] = (u8)((reg_value >> 16) & 0x0F);
379 data[1] = (u8)((reg_value >> 8) & 0xFF);
380 data[2] = (u8)(reg_value & 0xFF);
381 /* Set SLV-T Bank : 0xAE */
382 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
383 cxd2841er_write_regs(priv, I2C_SLVT, 0x20, data, 3);
387 static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv,
390 static int cxd2841er_sleep_s_to_active_s(struct cxd2841er_priv *priv,
391 u8 system, u32 symbol_rate)
394 u8 data[4] = { 0, 0, 0, 0 };
396 if (priv->state != STATE_SLEEP_S) {
397 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
398 __func__, (int)priv->state);
401 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
402 cxd2841er_set_ts_clock_mode(priv, SYS_DVBS);
404 if (system == SYS_DVBS) {
406 } else if (system == SYS_DVBS2) {
409 dev_err(&priv->i2c->dev, "%s(): invalid delsys %d\n",
413 /* Set SLV-X Bank : 0x00 */
414 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
415 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, data[0]);
418 /* Set SLV-T Bank : 0x00 */
419 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
420 /* Enable S/S2 auto detection 1 */
421 cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, data[0]);
422 /* Set SLV-T Bank : 0xAE */
423 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
424 /* Enable S/S2 auto detection 2 */
425 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, data[0]);
426 /* Set SLV-T Bank : 0x00 */
427 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
428 /* Enable demod clock */
429 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
430 /* Enable ADC clock */
431 cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x01);
433 cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
435 cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x3f);
436 /* Set SLV-X Bank : 0x00 */
437 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
439 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
440 /* Set SLV-T Bank : 0xA3 */
441 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa3);
442 cxd2841er_write_reg(priv, I2C_SLVT, 0xac, 0x00);
447 /* Set SLV-T Bank : 0xAB */
448 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xab);
449 cxd2841er_write_regs(priv, I2C_SLVT, 0x98, data, 4);
454 cxd2841er_write_regs(priv, I2C_SLVT, 0xa8, data, 4);
457 cxd2841er_write_regs(priv, I2C_SLVT, 0xc3, data, 2);
458 /* Set demod parameter */
459 ret = cxd2841er_dvbs2_set_symbol_rate(priv, symbol_rate);
462 /* Set SLV-T Bank : 0x00 */
463 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
464 /* disable Hi-Z setting 1 */
465 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x10);
466 /* disable Hi-Z setting 2 */
467 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
468 priv->state = STATE_ACTIVE_S;
472 static int cxd2841er_sleep_tc_to_active_t_band(struct cxd2841er_priv *priv,
475 static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv,
478 static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv,
481 static int cxd2841er_sleep_tc_to_active_i(struct cxd2841er_priv *priv,
484 static int cxd2841er_active_i_to_sleep_tc(struct cxd2841er_priv *priv);
486 static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv);
488 static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv);
490 static int cxd2841er_sleep_tc(struct dvb_frontend *fe);
492 static int cxd2841er_retune_active(struct cxd2841er_priv *priv,
493 struct dtv_frontend_properties *p)
495 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
496 if (priv->state != STATE_ACTIVE_S &&
497 priv->state != STATE_ACTIVE_TC) {
498 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
499 __func__, priv->state);
502 /* Set SLV-T Bank : 0x00 */
503 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
504 /* disable TS output */
505 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
506 if (priv->state == STATE_ACTIVE_S)
507 return cxd2841er_dvbs2_set_symbol_rate(
508 priv, p->symbol_rate / 1000);
509 else if (priv->state == STATE_ACTIVE_TC) {
510 switch (priv->system) {
512 return cxd2841er_sleep_tc_to_active_t_band(
513 priv, p->bandwidth_hz);
515 return cxd2841er_sleep_tc_to_active_t2_band(
516 priv, p->bandwidth_hz);
517 case SYS_DVBC_ANNEX_A:
518 return cxd2841er_sleep_tc_to_active_c_band(
519 priv, p->bandwidth_hz);
521 cxd2841er_active_i_to_sleep_tc(priv);
522 cxd2841er_sleep_tc_to_shutdown(priv);
523 cxd2841er_shutdown_to_sleep_tc(priv);
524 return cxd2841er_sleep_tc_to_active_i(
525 priv, p->bandwidth_hz);
528 dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
529 __func__, priv->system);
533 static int cxd2841er_active_s_to_sleep_s(struct cxd2841er_priv *priv)
535 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
536 if (priv->state != STATE_ACTIVE_S) {
537 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
538 __func__, priv->state);
541 /* Set SLV-T Bank : 0x00 */
542 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
543 /* disable TS output */
544 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
545 /* enable Hi-Z setting 1 */
546 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1f);
547 /* enable Hi-Z setting 2 */
548 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
549 /* Set SLV-X Bank : 0x00 */
550 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
552 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
553 /* Set SLV-T Bank : 0x00 */
554 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
555 /* disable ADC clock */
556 cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x00);
558 cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
560 cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
562 cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
563 /* disable demod clock */
564 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
565 /* Set SLV-T Bank : 0xAE */
566 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae);
567 /* disable S/S2 auto detection1 */
568 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
569 /* Set SLV-T Bank : 0x00 */
570 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
571 /* disable S/S2 auto detection2 */
572 cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, 0x00);
573 priv->state = STATE_SLEEP_S;
577 static int cxd2841er_sleep_s_to_shutdown(struct cxd2841er_priv *priv)
579 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
580 if (priv->state != STATE_SLEEP_S) {
581 dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
582 __func__, priv->state);
585 /* Set SLV-T Bank : 0x00 */
586 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
588 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
590 cxd2841er_write_reg(priv, I2C_SLVT, 0x9c, 0x00);
591 /* Set SLV-X Bank : 0x00 */
592 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
593 /* Disable oscillator */
594 cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01);
596 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
597 priv->state = STATE_SHUTDOWN;
601 static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv)
603 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
604 if (priv->state != STATE_SLEEP_TC) {
605 dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
606 __func__, priv->state);
609 /* Set SLV-X Bank : 0x00 */
610 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
611 /* Disable oscillator */
612 cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01);
614 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
615 priv->state = STATE_SHUTDOWN;
619 static int cxd2841er_active_t_to_sleep_tc(struct cxd2841er_priv *priv)
621 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
622 if (priv->state != STATE_ACTIVE_TC) {
623 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
624 __func__, priv->state);
627 /* Set SLV-T Bank : 0x00 */
628 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
629 /* disable TS output */
630 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
631 /* enable Hi-Z setting 1 */
632 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
633 /* enable Hi-Z setting 2 */
634 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
635 /* Set SLV-X Bank : 0x00 */
636 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
638 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
639 /* Set SLV-T Bank : 0x00 */
640 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
642 cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
644 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
645 /* Disable ADC clock */
646 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
647 /* Disable RF level monitor */
648 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
649 /* Disable demod clock */
650 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
651 priv->state = STATE_SLEEP_TC;
655 static int cxd2841er_active_t2_to_sleep_tc(struct cxd2841er_priv *priv)
657 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
658 if (priv->state != STATE_ACTIVE_TC) {
659 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
660 __func__, priv->state);
663 /* Set SLV-T Bank : 0x00 */
664 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
665 /* disable TS output */
666 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
667 /* enable Hi-Z setting 1 */
668 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
669 /* enable Hi-Z setting 2 */
670 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
671 /* Cancel DVB-T2 setting */
672 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
673 cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x40);
674 cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x21);
675 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f);
676 cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xfb);
677 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a);
678 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x00, 0x0f);
679 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
680 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x00, 0x3f);
681 /* Set SLV-X Bank : 0x00 */
682 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
684 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
685 /* Set SLV-T Bank : 0x00 */
686 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
688 cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
690 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
691 /* Disable ADC clock */
692 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
693 /* Disable RF level monitor */
694 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
695 /* Disable demod clock */
696 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
697 priv->state = STATE_SLEEP_TC;
701 static int cxd2841er_active_c_to_sleep_tc(struct cxd2841er_priv *priv)
703 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
704 if (priv->state != STATE_ACTIVE_TC) {
705 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
706 __func__, priv->state);
709 /* Set SLV-T Bank : 0x00 */
710 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
711 /* disable TS output */
712 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
713 /* enable Hi-Z setting 1 */
714 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
715 /* enable Hi-Z setting 2 */
716 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
717 /* Cancel DVB-C setting */
718 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
719 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa3, 0x00, 0x1f);
720 /* Set SLV-X Bank : 0x00 */
721 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
723 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
724 /* Set SLV-T Bank : 0x00 */
725 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
727 cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
729 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
730 /* Disable ADC clock */
731 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
732 /* Disable RF level monitor */
733 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
734 /* Disable demod clock */
735 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
736 priv->state = STATE_SLEEP_TC;
740 static int cxd2841er_active_i_to_sleep_tc(struct cxd2841er_priv *priv)
742 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
743 if (priv->state != STATE_ACTIVE_TC) {
744 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
745 __func__, priv->state);
748 /* Set SLV-T Bank : 0x00 */
749 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
750 /* disable TS output */
751 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01);
752 /* enable Hi-Z setting 1 */
753 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f);
754 /* enable Hi-Z setting 2 */
755 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff);
757 /* TODO: Cancel demod parameter */
759 /* Set SLV-X Bank : 0x00 */
760 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
762 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01);
763 /* Set SLV-T Bank : 0x00 */
764 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
766 cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
768 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
769 /* Disable ADC clock */
770 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
771 /* Disable RF level monitor */
772 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
773 /* Disable demod clock */
774 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00);
775 priv->state = STATE_SLEEP_TC;
779 static int cxd2841er_shutdown_to_sleep_s(struct cxd2841er_priv *priv)
781 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
782 if (priv->state != STATE_SHUTDOWN) {
783 dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
784 __func__, priv->state);
787 /* Set SLV-X Bank : 0x00 */
788 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
789 /* Clear all demodulator registers */
790 cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00);
791 usleep_range(3000, 5000);
792 /* Set SLV-X Bank : 0x00 */
793 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
794 /* Set demod SW reset */
795 cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01);
797 switch (priv->xtal) {
798 case SONY_XTAL_20500:
799 cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00);
801 case SONY_XTAL_24000:
802 /* Select demod frequency */
803 cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00);
804 cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x03);
806 case SONY_XTAL_41000:
807 cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x01);
810 dev_dbg(&priv->i2c->dev, "%s(): invalid demod xtal %d\n",
811 __func__, priv->xtal);
816 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x0a);
817 /* Clear demod SW reset */
818 cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00);
819 usleep_range(1000, 2000);
820 /* Set SLV-T Bank : 0x00 */
821 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
823 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1F);
825 cxd2841er_write_reg(priv, I2C_SLVT, 0x9C, 0x40);
827 cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
828 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
830 cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
831 cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
832 cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
833 priv->state = STATE_SLEEP_S;
837 static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv)
841 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
842 if (priv->state != STATE_SHUTDOWN) {
843 dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n",
844 __func__, priv->state);
847 /* Set SLV-X Bank : 0x00 */
848 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
849 /* Clear all demodulator registers */
850 cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00);
851 usleep_range(3000, 5000);
852 /* Set SLV-X Bank : 0x00 */
853 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
854 /* Set demod SW reset */
855 cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01);
856 /* Select ADC clock mode */
857 cxd2841er_write_reg(priv, I2C_SLVX, 0x13, 0x00);
859 switch (priv->xtal) {
860 case SONY_XTAL_20500:
863 case SONY_XTAL_24000:
864 /* Select demod frequency */
865 cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00);
868 case SONY_XTAL_41000:
869 cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00);
873 cxd2841er_write_reg(priv, I2C_SLVX, 0x14, data);
874 /* Clear demod SW reset */
875 cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00);
876 usleep_range(1000, 2000);
877 /* Set SLV-T Bank : 0x00 */
878 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
880 cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a);
881 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a);
883 cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16);
884 cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27);
885 cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06);
886 priv->state = STATE_SLEEP_TC;
890 static int cxd2841er_tune_done(struct cxd2841er_priv *priv)
892 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
893 /* Set SLV-T Bank : 0x00 */
894 cxd2841er_write_reg(priv, I2C_SLVT, 0, 0);
896 cxd2841er_write_reg(priv, I2C_SLVT, 0xfe, 0x01);
897 /* Enable TS output */
898 cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x00);
902 /* Set TS parallel mode */
903 static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv,
906 u8 serial_ts, ts_rate_ctrl_off, ts_in_off;
908 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
909 /* Set SLV-T Bank : 0x00 */
910 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
911 cxd2841er_read_reg(priv, I2C_SLVT, 0xc4, &serial_ts);
912 cxd2841er_read_reg(priv, I2C_SLVT, 0xd3, &ts_rate_ctrl_off);
913 cxd2841er_read_reg(priv, I2C_SLVT, 0xde, &ts_in_off);
914 dev_dbg(&priv->i2c->dev, "%s(): ser_ts=0x%02x rate_ctrl_off=0x%02x in_off=0x%02x\n",
915 __func__, serial_ts, ts_rate_ctrl_off, ts_in_off);
918 * slave Bank Addr Bit default Name
919 * <SLV-T> 00h C4h [1:0] 2'b?? OSERCKMODE
921 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4,
922 ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x01 : 0x00), 0x03);
924 * slave Bank Addr Bit default Name
925 * <SLV-T> 00h D1h [1:0] 2'b?? OSERDUTYMODE
927 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd1,
928 ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x01 : 0x00), 0x03);
930 * slave Bank Addr Bit default Name
931 * <SLV-T> 00h D9h [7:0] 8'h08 OTSCKPERIOD
933 cxd2841er_write_reg(priv, I2C_SLVT, 0xd9, 0x08);
935 * Disable TS IF Clock
936 * slave Bank Addr Bit default Name
937 * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
939 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x00, 0x01);
941 * slave Bank Addr Bit default Name
942 * <SLV-T> 00h 33h [1:0] 2'b01 OREG_CKSEL_TSIF
944 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x33,
945 ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x01 : 0x00), 0x03);
948 * slave Bank Addr Bit default Name
949 * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN
951 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x01, 0x01);
953 if (system == SYS_DVBT) {
954 /* Enable parity period for DVB-T */
955 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
956 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01);
957 } else if (system == SYS_DVBC_ANNEX_A) {
958 /* Enable parity period for DVB-C */
959 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
960 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01);
964 static u8 cxd2841er_chip_id(struct cxd2841er_priv *priv)
968 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
969 if (cxd2841er_write_reg(priv, I2C_SLVT, 0, 0) == 0)
970 cxd2841er_read_reg(priv, I2C_SLVT, 0xfd, &chip_id);
971 else if (cxd2841er_write_reg(priv, I2C_SLVX, 0, 0) == 0)
972 cxd2841er_read_reg(priv, I2C_SLVX, 0xfd, &chip_id);
977 static int cxd2841er_read_status_s(struct dvb_frontend *fe,
978 enum fe_status *status)
981 struct cxd2841er_priv *priv = fe->demodulator_priv;
983 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
985 if (priv->state != STATE_ACTIVE_S) {
986 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
987 __func__, priv->state);
990 /* Set SLV-T Bank : 0xA0 */
991 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
993 * slave Bank Addr Bit Signal name
994 * <SLV-T> A0h 11h [2] ITSLOCK
996 cxd2841er_read_reg(priv, I2C_SLVT, 0x11, ®);
998 *status = FE_HAS_SIGNAL
1004 dev_dbg(&priv->i2c->dev, "%s(): result 0x%x\n", __func__, *status);
1008 static int cxd2841er_read_status_t_t2(struct cxd2841er_priv *priv,
1009 u8 *sync, u8 *tslock, u8 *unlock)
1013 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1014 if (priv->state != STATE_ACTIVE_TC)
1016 if (priv->system == SYS_DVBT) {
1017 /* Set SLV-T Bank : 0x10 */
1018 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
1020 /* Set SLV-T Bank : 0x20 */
1021 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
1023 cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
1024 if ((data & 0x07) == 0x07) {
1025 dev_dbg(&priv->i2c->dev,
1026 "%s(): invalid hardware state detected\n", __func__);
1031 *sync = ((data & 0x07) == 0x6 ? 1 : 0);
1032 *tslock = ((data & 0x20) ? 1 : 0);
1033 *unlock = ((data & 0x10) ? 1 : 0);
1038 static int cxd2841er_read_status_c(struct cxd2841er_priv *priv, u8 *tslock)
1042 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1043 if (priv->state != STATE_ACTIVE_TC)
1045 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
1046 cxd2841er_read_reg(priv, I2C_SLVT, 0x88, &data);
1047 if ((data & 0x01) == 0) {
1050 cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
1051 *tslock = ((data & 0x20) ? 1 : 0);
1056 static int cxd2841er_read_status_i(struct cxd2841er_priv *priv,
1057 u8 *sync, u8 *tslock, u8 *unlock)
1061 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1062 if (priv->state != STATE_ACTIVE_TC)
1064 /* Set SLV-T Bank : 0x60 */
1065 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
1066 cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data);
1067 dev_dbg(&priv->i2c->dev,
1068 "%s(): lock=0x%x\n", __func__, data);
1069 *sync = ((data & 0x02) ? 1 : 0);
1070 *tslock = ((data & 0x01) ? 1 : 0);
1071 *unlock = ((data & 0x10) ? 1 : 0);
1075 static int cxd2841er_read_status_tc(struct dvb_frontend *fe,
1076 enum fe_status *status)
1082 struct cxd2841er_priv *priv = fe->demodulator_priv;
1085 if (priv->state == STATE_ACTIVE_TC) {
1086 if (priv->system == SYS_DVBT || priv->system == SYS_DVBT2) {
1087 ret = cxd2841er_read_status_t_t2(
1088 priv, &sync, &tslock, &unlock);
1094 *status = FE_HAS_SIGNAL |
1099 *status |= FE_HAS_LOCK;
1100 } else if (priv->system == SYS_ISDBT) {
1101 ret = cxd2841er_read_status_i(
1102 priv, &sync, &tslock, &unlock);
1108 *status = FE_HAS_SIGNAL |
1113 *status |= FE_HAS_LOCK;
1114 } else if (priv->system == SYS_DVBC_ANNEX_A) {
1115 ret = cxd2841er_read_status_c(priv, &tslock);
1119 *status = FE_HAS_SIGNAL |
1127 dev_dbg(&priv->i2c->dev, "%s(): status 0x%x\n", __func__, *status);
1131 static int cxd2841er_get_carrier_offset_s_s2(struct cxd2841er_priv *priv,
1137 s32 temp_div, temp_q, temp_r;
1139 if (priv->state != STATE_ACTIVE_S) {
1140 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1141 __func__, priv->state);
1145 * Get High Sampling Rate mode
1146 * slave Bank Addr Bit Signal name
1147 * <SLV-T> A0h 10h [0] ITRL_LOCK
1149 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
1150 cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data[0]);
1151 if (data[0] & 0x01) {
1153 * slave Bank Addr Bit Signal name
1154 * <SLV-T> A0h 50h [4] IHSMODE
1156 cxd2841er_read_reg(priv, I2C_SLVT, 0x50, &data[0]);
1157 is_hs_mode = (data[0] & 0x10 ? 1 : 0);
1159 dev_dbg(&priv->i2c->dev,
1160 "%s(): unable to detect sampling rate mode\n",
1165 * slave Bank Addr Bit Signal name
1166 * <SLV-T> A0h 45h [4:0] ICFRL_CTRLVAL[20:16]
1167 * <SLV-T> A0h 46h [7:0] ICFRL_CTRLVAL[15:8]
1168 * <SLV-T> A0h 47h [7:0] ICFRL_CTRLVAL[7:0]
1170 cxd2841er_read_regs(priv, I2C_SLVT, 0x45, data, 3);
1171 cfrl_ctrlval = sign_extend32((((u32)data[0] & 0x1F) << 16) |
1172 (((u32)data[1] & 0xFF) << 8) |
1173 ((u32)data[2] & 0xFF), 20);
1174 temp_div = (is_hs_mode ? 1048576 : 1572864);
1175 if (cfrl_ctrlval > 0) {
1176 temp_q = div_s64_rem(97375LL * cfrl_ctrlval,
1179 temp_q = div_s64_rem(-97375LL * cfrl_ctrlval,
1182 if (temp_r >= temp_div / 2)
1184 if (cfrl_ctrlval > 0)
1190 static int cxd2841er_get_carrier_offset_i(struct cxd2841er_priv *priv,
1191 u32 bandwidth, int *offset)
1195 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1196 if (priv->state != STATE_ACTIVE_TC) {
1197 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1198 __func__, priv->state);
1201 if (priv->system != SYS_ISDBT) {
1202 dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
1203 __func__, priv->system);
1206 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
1207 cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
1208 *offset = -1 * sign_extend32(
1209 ((u32)(data[0] & 0x1F) << 24) | ((u32)data[1] << 16) |
1210 ((u32)data[2] << 8) | (u32)data[3], 29);
1212 switch (bandwidth) {
1214 *offset = -1 * ((*offset) * 8/264);
1217 *offset = -1 * ((*offset) * 8/231);
1220 *offset = -1 * ((*offset) * 8/198);
1223 dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
1224 __func__, bandwidth);
1228 dev_dbg(&priv->i2c->dev, "%s(): bandwidth %d offset %d\n",
1229 __func__, bandwidth, *offset);
1234 static int cxd2841er_get_carrier_offset_t(struct cxd2841er_priv *priv,
1235 u32 bandwidth, int *offset)
1239 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1240 if (priv->state != STATE_ACTIVE_TC) {
1241 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1242 __func__, priv->state);
1245 if (priv->system != SYS_DVBT) {
1246 dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
1247 __func__, priv->system);
1250 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
1251 cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
1252 *offset = -1 * sign_extend32(
1253 ((u32)(data[0] & 0x1F) << 24) | ((u32)data[1] << 16) |
1254 ((u32)data[2] << 8) | (u32)data[3], 29);
1255 *offset *= (bandwidth / 1000000);
1260 static int cxd2841er_get_carrier_offset_t2(struct cxd2841er_priv *priv,
1261 u32 bandwidth, int *offset)
1265 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1266 if (priv->state != STATE_ACTIVE_TC) {
1267 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1268 __func__, priv->state);
1271 if (priv->system != SYS_DVBT2) {
1272 dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
1273 __func__, priv->system);
1276 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
1277 cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data));
1278 *offset = -1 * sign_extend32(
1279 ((u32)(data[0] & 0x0F) << 24) | ((u32)data[1] << 16) |
1280 ((u32)data[2] << 8) | (u32)data[3], 27);
1281 switch (bandwidth) {
1289 *offset *= (bandwidth / 1000000);
1293 dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
1294 __func__, bandwidth);
1300 static int cxd2841er_get_carrier_offset_c(struct cxd2841er_priv *priv,
1305 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1306 if (priv->state != STATE_ACTIVE_TC) {
1307 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1308 __func__, priv->state);
1311 if (priv->system != SYS_DVBC_ANNEX_A) {
1312 dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n",
1313 __func__, priv->system);
1316 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
1317 cxd2841er_read_regs(priv, I2C_SLVT, 0x15, data, sizeof(data));
1318 *offset = div_s64(41000LL * sign_extend32((((u32)data[0] & 0x3f) << 8)
1319 | (u32)data[1], 13), 16384);
1323 static int cxd2841er_read_packet_errors_c(
1324 struct cxd2841er_priv *priv, u32 *penum)
1329 if (priv->state != STATE_ACTIVE_TC) {
1330 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1331 __func__, priv->state);
1334 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
1335 cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data));
1337 *penum = ((u32)data[0] << 8) | (u32)data[1];
1341 static int cxd2841er_read_packet_errors_t(
1342 struct cxd2841er_priv *priv, u32 *penum)
1347 if (priv->state != STATE_ACTIVE_TC) {
1348 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1349 __func__, priv->state);
1352 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
1353 cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data));
1355 *penum = ((u32)data[0] << 8) | (u32)data[1];
1359 static int cxd2841er_read_packet_errors_t2(
1360 struct cxd2841er_priv *priv, u32 *penum)
1365 if (priv->state != STATE_ACTIVE_TC) {
1366 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1367 __func__, priv->state);
1370 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24);
1371 cxd2841er_read_regs(priv, I2C_SLVT, 0xfd, data, sizeof(data));
1373 *penum = ((u32)data[1] << 8) | (u32)data[2];
1377 static int cxd2841er_read_packet_errors_i(
1378 struct cxd2841er_priv *priv, u32 *penum)
1383 if (priv->state != STATE_ACTIVE_TC) {
1384 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1385 __func__, priv->state);
1388 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
1389 cxd2841er_read_regs(priv, I2C_SLVT, 0xA1, data, 1);
1391 if (!(data[0] & 0x01))
1395 cxd2841er_read_regs(priv, I2C_SLVT, 0xA2, data, sizeof(data));
1396 *penum = ((u32)data[0] << 8) | (u32)data[1];
1399 cxd2841er_read_regs(priv, I2C_SLVT, 0xA4, data, sizeof(data));
1400 *penum += ((u32)data[0] << 8) | (u32)data[1];
1403 cxd2841er_read_regs(priv, I2C_SLVT, 0xA6, data, sizeof(data));
1404 *penum += ((u32)data[0] << 8) | (u32)data[1];
1409 static int cxd2841er_read_ber_c(struct cxd2841er_priv *priv,
1410 u32 *bit_error, u32 *bit_count)
1413 u32 bit_err, period_exp;
1415 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1416 if (priv->state != STATE_ACTIVE_TC) {
1417 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1418 __func__, priv->state);
1421 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
1422 cxd2841er_read_regs(priv, I2C_SLVT, 0x62, data, sizeof(data));
1423 if (!(data[0] & 0x80)) {
1424 dev_dbg(&priv->i2c->dev,
1425 "%s(): no valid BER data\n", __func__);
1428 bit_err = ((u32)(data[0] & 0x3f) << 16) |
1429 ((u32)data[1] << 8) |
1431 cxd2841er_read_reg(priv, I2C_SLVT, 0x60, data);
1432 period_exp = data[0] & 0x1f;
1434 if ((period_exp <= 11) && (bit_err > (1 << period_exp) * 204 * 8)) {
1435 dev_dbg(&priv->i2c->dev,
1436 "%s(): period_exp(%u) or bit_err(%u) not in range. no valid BER data\n",
1437 __func__, period_exp, bit_err);
1441 dev_dbg(&priv->i2c->dev,
1442 "%s(): period_exp(%u) or bit_err(%u) count=%d\n",
1443 __func__, period_exp, bit_err,
1444 ((1 << period_exp) * 204 * 8));
1446 *bit_error = bit_err;
1447 *bit_count = ((1 << period_exp) * 204 * 8);
1452 static int cxd2841er_read_ber_i(struct cxd2841er_priv *priv,
1453 u32 *bit_error, u32 *bit_count)
1458 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1459 if (priv->state != STATE_ACTIVE_TC) {
1460 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
1461 __func__, priv->state);
1465 cxd2841er_freeze_regs(priv);
1466 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
1467 cxd2841er_read_regs(priv, I2C_SLVT, 0x5B, pktnum, sizeof(pktnum));
1468 cxd2841er_read_regs(priv, I2C_SLVT, 0x16, data, sizeof(data));
1469 cxd2841er_unfreeze_regs(priv);
1471 if (!pktnum[0] && !pktnum[1]) {
1472 dev_dbg(&priv->i2c->dev,
1473 "%s(): no valid BER data\n", __func__);
1477 *bit_error = ((u32)(data[0] & 0x7F) << 16) |
1478 ((u32)data[1] << 8) | data[2];
1479 *bit_count = ((((u32)pktnum[0] << 8) | pktnum[1]) * 204 * 8);
1480 dev_dbg(&priv->i2c->dev, "%s(): bit_error=%u bit_count=%u\n",
1481 __func__, *bit_error, *bit_count);
1486 static int cxd2841er_mon_read_ber_s(struct cxd2841er_priv *priv,
1487 u32 *bit_error, u32 *bit_count)
1491 /* Set SLV-T Bank : 0xA0 */
1492 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
1494 * slave Bank Addr Bit Signal name
1495 * <SLV-T> A0h 35h [0] IFVBER_VALID
1496 * <SLV-T> A0h 36h [5:0] IFVBER_BITERR[21:16]
1497 * <SLV-T> A0h 37h [7:0] IFVBER_BITERR[15:8]
1498 * <SLV-T> A0h 38h [7:0] IFVBER_BITERR[7:0]
1499 * <SLV-T> A0h 3Dh [5:0] IFVBER_BITNUM[21:16]
1500 * <SLV-T> A0h 3Eh [7:0] IFVBER_BITNUM[15:8]
1501 * <SLV-T> A0h 3Fh [7:0] IFVBER_BITNUM[7:0]
1503 cxd2841er_read_regs(priv, I2C_SLVT, 0x35, data, 11);
1504 if (data[0] & 0x01) {
1505 *bit_error = ((u32)(data[1] & 0x3F) << 16) |
1506 ((u32)(data[2] & 0xFF) << 8) |
1507 (u32)(data[3] & 0xFF);
1508 *bit_count = ((u32)(data[8] & 0x3F) << 16) |
1509 ((u32)(data[9] & 0xFF) << 8) |
1510 (u32)(data[10] & 0xFF);
1511 if ((*bit_count == 0) || (*bit_error > *bit_count)) {
1512 dev_dbg(&priv->i2c->dev,
1513 "%s(): invalid bit_error %d, bit_count %d\n",
1514 __func__, *bit_error, *bit_count);
1519 dev_dbg(&priv->i2c->dev, "%s(): no data available\n", __func__);
1524 static int cxd2841er_mon_read_ber_s2(struct cxd2841er_priv *priv,
1525 u32 *bit_error, u32 *bit_count)
1530 /* Set SLV-T Bank : 0xB2 */
1531 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xb2);
1533 * slave Bank Addr Bit Signal name
1534 * <SLV-T> B2h 30h [0] IFLBER_VALID
1535 * <SLV-T> B2h 31h [3:0] IFLBER_BITERR[27:24]
1536 * <SLV-T> B2h 32h [7:0] IFLBER_BITERR[23:16]
1537 * <SLV-T> B2h 33h [7:0] IFLBER_BITERR[15:8]
1538 * <SLV-T> B2h 34h [7:0] IFLBER_BITERR[7:0]
1540 cxd2841er_read_regs(priv, I2C_SLVT, 0x30, data, 5);
1541 if (data[0] & 0x01) {
1542 /* Bit error count */
1543 *bit_error = ((u32)(data[1] & 0x0F) << 24) |
1544 ((u32)(data[2] & 0xFF) << 16) |
1545 ((u32)(data[3] & 0xFF) << 8) |
1546 (u32)(data[4] & 0xFF);
1548 /* Set SLV-T Bank : 0xA0 */
1549 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
1550 cxd2841er_read_reg(priv, I2C_SLVT, 0x7a, data);
1551 /* Measurement period */
1552 period = (u32)(1 << (data[0] & 0x0F));
1554 dev_dbg(&priv->i2c->dev,
1555 "%s(): period is 0\n", __func__);
1558 if (*bit_error > (period * 64800)) {
1559 dev_dbg(&priv->i2c->dev,
1560 "%s(): invalid bit_err 0x%x period 0x%x\n",
1561 __func__, *bit_error, period);
1564 *bit_count = period * 64800;
1568 dev_dbg(&priv->i2c->dev,
1569 "%s(): no data available\n", __func__);
1574 static int cxd2841er_read_ber_t2(struct cxd2841er_priv *priv,
1575 u32 *bit_error, u32 *bit_count)
1578 u32 period_exp, n_ldpc;
1580 if (priv->state != STATE_ACTIVE_TC) {
1581 dev_dbg(&priv->i2c->dev,
1582 "%s(): invalid state %d\n", __func__, priv->state);
1585 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
1586 cxd2841er_read_regs(priv, I2C_SLVT, 0x39, data, sizeof(data));
1587 if (!(data[0] & 0x10)) {
1588 dev_dbg(&priv->i2c->dev,
1589 "%s(): no valid BER data\n", __func__);
1592 *bit_error = ((u32)(data[0] & 0x0f) << 24) |
1593 ((u32)data[1] << 16) |
1594 ((u32)data[2] << 8) |
1596 cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data);
1597 period_exp = data[0] & 0x0f;
1598 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x22);
1599 cxd2841er_read_reg(priv, I2C_SLVT, 0x5e, data);
1600 n_ldpc = ((data[0] & 0x03) == 0 ? 16200 : 64800);
1601 if (*bit_error > ((1U << period_exp) * n_ldpc)) {
1602 dev_dbg(&priv->i2c->dev,
1603 "%s(): invalid BER value\n", __func__);
1608 * FIXME: the right thing would be to return bit_error untouched,
1609 * but, as we don't know the scale returned by the counters, let's
1610 * at least preserver BER = bit_error/bit_count.
1612 if (period_exp >= 4) {
1613 *bit_count = (1U << (period_exp - 4)) * (n_ldpc / 200);
1614 *bit_error *= 3125ULL;
1616 *bit_count = (1U << period_exp) * (n_ldpc / 200);
1617 *bit_error *= 50000ULL;
1622 static int cxd2841er_read_ber_t(struct cxd2841er_priv *priv,
1623 u32 *bit_error, u32 *bit_count)
1628 if (priv->state != STATE_ACTIVE_TC) {
1629 dev_dbg(&priv->i2c->dev,
1630 "%s(): invalid state %d\n", __func__, priv->state);
1633 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
1634 cxd2841er_read_reg(priv, I2C_SLVT, 0x39, data);
1635 if (!(data[0] & 0x01)) {
1636 dev_dbg(&priv->i2c->dev,
1637 "%s(): no valid BER data\n", __func__);
1640 cxd2841er_read_regs(priv, I2C_SLVT, 0x22, data, sizeof(data));
1641 *bit_error = ((u32)data[0] << 8) | (u32)data[1];
1642 cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data);
1643 period = ((data[0] & 0x07) == 0) ? 256 : (4096 << (data[0] & 0x07));
1646 * FIXME: the right thing would be to return bit_error untouched,
1647 * but, as we don't know the scale returned by the counters, let's
1648 * at least preserver BER = bit_error/bit_count.
1650 *bit_count = period / 128;
1651 *bit_error *= 78125ULL;
1655 static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv)
1658 * Freeze registers: ensure multiple separate register reads
1659 * are from the same snapshot
1661 cxd2841er_write_reg(priv, I2C_SLVT, 0x01, 0x01);
1665 static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv)
1668 * un-freeze registers
1670 cxd2841er_write_reg(priv, I2C_SLVT, 0x01, 0x00);
1674 static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv,
1675 u8 delsys, u32 *snr)
1679 int min_index, max_index, index;
1680 static const struct cxd2841er_cnr_data *cn_data;
1682 cxd2841er_freeze_regs(priv);
1683 /* Set SLV-T Bank : 0xA1 */
1684 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa1);
1686 * slave Bank Addr Bit Signal name
1687 * <SLV-T> A1h 10h [0] ICPM_QUICKRDY
1688 * <SLV-T> A1h 11h [4:0] ICPM_QUICKCNDT[12:8]
1689 * <SLV-T> A1h 12h [7:0] ICPM_QUICKCNDT[7:0]
1691 cxd2841er_read_regs(priv, I2C_SLVT, 0x10, data, 3);
1692 cxd2841er_unfreeze_regs(priv);
1694 if (data[0] & 0x01) {
1695 value = ((u32)(data[1] & 0x1F) << 8) | (u32)(data[2] & 0xFF);
1697 if (delsys == SYS_DVBS) {
1698 cn_data = s_cn_data;
1699 max_index = sizeof(s_cn_data) /
1700 sizeof(s_cn_data[0]) - 1;
1702 cn_data = s2_cn_data;
1703 max_index = sizeof(s2_cn_data) /
1704 sizeof(s2_cn_data[0]) - 1;
1706 if (value >= cn_data[min_index].value) {
1707 res = cn_data[min_index].cnr_x1000;
1710 if (value <= cn_data[max_index].value) {
1711 res = cn_data[max_index].cnr_x1000;
1714 while ((max_index - min_index) > 1) {
1715 index = (max_index + min_index) / 2;
1716 if (value == cn_data[index].value) {
1717 res = cn_data[index].cnr_x1000;
1719 } else if (value > cn_data[index].value)
1723 if ((max_index - min_index) <= 1) {
1724 if (value == cn_data[max_index].value) {
1725 res = cn_data[max_index].cnr_x1000;
1728 res = cn_data[min_index].cnr_x1000;
1734 dev_dbg(&priv->i2c->dev,
1735 "%s(): no data available\n", __func__);
1743 static uint32_t sony_log(uint32_t x)
1745 return (((10000>>8)*(intlog2(x)>>16) + LOG2_E_100X/2)/LOG2_E_100X);
1748 static int cxd2841er_read_snr_c(struct cxd2841er_priv *priv, u32 *snr)
1752 enum sony_dvbc_constellation_t qam = SONY_DVBC_CONSTELLATION_16QAM;
1755 if (priv->state != STATE_ACTIVE_TC) {
1756 dev_dbg(&priv->i2c->dev,
1757 "%s(): invalid state %d\n",
1758 __func__, priv->state);
1762 cxd2841er_freeze_regs(priv);
1763 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
1764 cxd2841er_read_regs(priv, I2C_SLVT, 0x19, data, 1);
1765 qam = (enum sony_dvbc_constellation_t) (data[0] & 0x07);
1766 cxd2841er_read_regs(priv, I2C_SLVT, 0x4C, data, 2);
1767 cxd2841er_unfreeze_regs(priv);
1769 reg = ((u32)(data[0]&0x1f) << 8) | (u32)data[1];
1771 dev_dbg(&priv->i2c->dev,
1772 "%s(): reg value out of range\n", __func__);
1777 case SONY_DVBC_CONSTELLATION_16QAM:
1778 case SONY_DVBC_CONSTELLATION_64QAM:
1779 case SONY_DVBC_CONSTELLATION_256QAM:
1780 /* SNR(dB) = -9.50 * ln(IREG_SNR_ESTIMATE / (24320)) */
1783 *snr = -95 * (int32_t)sony_log(reg) + 95941;
1785 case SONY_DVBC_CONSTELLATION_32QAM:
1786 case SONY_DVBC_CONSTELLATION_128QAM:
1787 /* SNR(dB) = -8.75 * ln(IREG_SNR_ESTIMATE / (20800)) */
1790 *snr = -88 * (int32_t)sony_log(reg) + 86999;
1799 static int cxd2841er_read_snr_t(struct cxd2841er_priv *priv, u32 *snr)
1805 if (priv->state != STATE_ACTIVE_TC) {
1806 dev_dbg(&priv->i2c->dev,
1807 "%s(): invalid state %d\n", __func__, priv->state);
1811 cxd2841er_freeze_regs(priv);
1812 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
1813 cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
1814 cxd2841er_unfreeze_regs(priv);
1816 reg = ((u32)data[0] << 8) | (u32)data[1];
1818 dev_dbg(&priv->i2c->dev,
1819 "%s(): reg value out of range\n", __func__);
1824 *snr = 100 * ((INTLOG10X100(reg) - INTLOG10X100(5350 - reg)) + 285);
1828 static int cxd2841er_read_snr_t2(struct cxd2841er_priv *priv, u32 *snr)
1834 if (priv->state != STATE_ACTIVE_TC) {
1835 dev_dbg(&priv->i2c->dev,
1836 "%s(): invalid state %d\n", __func__, priv->state);
1840 cxd2841er_freeze_regs(priv);
1841 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
1842 cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
1843 cxd2841er_unfreeze_regs(priv);
1845 reg = ((u32)data[0] << 8) | (u32)data[1];
1847 dev_dbg(&priv->i2c->dev,
1848 "%s(): reg value out of range\n", __func__);
1853 *snr = 100 * ((INTLOG10X100(reg) - INTLOG10X100(12600 - reg)) + 320);
1857 static int cxd2841er_read_snr_i(struct cxd2841er_priv *priv, u32 *snr)
1863 if (priv->state != STATE_ACTIVE_TC) {
1864 dev_dbg(&priv->i2c->dev,
1865 "%s(): invalid state %d\n", __func__,
1870 cxd2841er_freeze_regs(priv);
1871 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
1872 cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data));
1873 cxd2841er_unfreeze_regs(priv);
1875 reg = ((u32)data[0] << 8) | (u32)data[1];
1877 dev_dbg(&priv->i2c->dev,
1878 "%s(): reg value out of range\n", __func__);
1881 *snr = 10000 * (intlog10(reg) >> 24) - 9031;
1885 static u16 cxd2841er_read_agc_gain_c(struct cxd2841er_priv *priv,
1890 cxd2841er_write_reg(
1891 priv, I2C_SLVT, 0x00, 0x40);
1892 cxd2841er_read_regs(priv, I2C_SLVT, 0x49, data, 2);
1893 dev_dbg(&priv->i2c->dev,
1894 "%s(): AGC value=%u\n",
1895 __func__, (((u16)data[0] & 0x0F) << 8) |
1896 (u16)(data[1] & 0xFF));
1897 return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
1900 static u16 cxd2841er_read_agc_gain_t_t2(struct cxd2841er_priv *priv,
1905 cxd2841er_write_reg(
1906 priv, I2C_SLVT, 0x00, (delsys == SYS_DVBT ? 0x10 : 0x20));
1907 cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2);
1908 dev_dbg(&priv->i2c->dev,
1909 "%s(): AGC value=%u\n",
1910 __func__, (((u16)data[0] & 0x0F) << 8) |
1911 (u16)(data[1] & 0xFF));
1912 return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
1915 static u16 cxd2841er_read_agc_gain_i(struct cxd2841er_priv *priv,
1920 cxd2841er_write_reg(
1921 priv, I2C_SLVT, 0x00, 0x60);
1922 cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2);
1924 dev_dbg(&priv->i2c->dev,
1925 "%s(): AGC value=%u\n",
1926 __func__, (((u16)data[0] & 0x0F) << 8) |
1927 (u16)(data[1] & 0xFF));
1928 return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4;
1931 static u16 cxd2841er_read_agc_gain_s(struct cxd2841er_priv *priv)
1935 /* Set SLV-T Bank : 0xA0 */
1936 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
1938 * slave Bank Addr Bit Signal name
1939 * <SLV-T> A0h 1Fh [4:0] IRFAGC_GAIN[12:8]
1940 * <SLV-T> A0h 20h [7:0] IRFAGC_GAIN[7:0]
1942 cxd2841er_read_regs(priv, I2C_SLVT, 0x1f, data, 2);
1943 return ((((u16)data[0] & 0x1F) << 8) | (u16)(data[1] & 0xFF)) << 3;
1946 static void cxd2841er_read_ber(struct dvb_frontend *fe)
1948 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1949 struct cxd2841er_priv *priv = fe->demodulator_priv;
1950 u32 ret, bit_error = 0, bit_count = 0;
1952 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1953 switch (p->delivery_system) {
1954 case SYS_DVBC_ANNEX_A:
1955 case SYS_DVBC_ANNEX_B:
1956 case SYS_DVBC_ANNEX_C:
1957 ret = cxd2841er_read_ber_c(priv, &bit_error, &bit_count);
1960 ret = cxd2841er_read_ber_i(priv, &bit_error, &bit_count);
1963 ret = cxd2841er_mon_read_ber_s(priv, &bit_error, &bit_count);
1966 ret = cxd2841er_mon_read_ber_s2(priv, &bit_error, &bit_count);
1969 ret = cxd2841er_read_ber_t(priv, &bit_error, &bit_count);
1972 ret = cxd2841er_read_ber_t2(priv, &bit_error, &bit_count);
1975 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1976 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1981 p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
1982 p->post_bit_error.stat[0].uvalue += bit_error;
1983 p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
1984 p->post_bit_count.stat[0].uvalue += bit_count;
1986 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1987 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
1991 static void cxd2841er_read_signal_strength(struct dvb_frontend *fe)
1993 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1994 struct cxd2841er_priv *priv = fe->demodulator_priv;
1997 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
1998 switch (p->delivery_system) {
2001 strength = cxd2841er_read_agc_gain_t_t2(priv,
2002 p->delivery_system);
2003 p->strength.stat[0].scale = FE_SCALE_DECIBEL;
2004 /* Formula was empirically determinated @ 410 MHz */
2005 p->strength.stat[0].uvalue = strength * 366 / 100 - 89520;
2006 break; /* Code moved out of the function */
2007 case SYS_DVBC_ANNEX_A:
2008 case SYS_DVBC_ANNEX_B:
2009 case SYS_DVBC_ANNEX_C:
2010 strength = cxd2841er_read_agc_gain_c(priv,
2011 p->delivery_system);
2012 p->strength.stat[0].scale = FE_SCALE_DECIBEL;
2014 * Formula was empirically determinated via linear regression,
2015 * using frequencies: 175 MHz, 410 MHz and 800 MHz, and a
2016 * stream modulated with QAM64
2018 p->strength.stat[0].uvalue = strength * 4045 / 1000 - 85224;
2021 strength = cxd2841er_read_agc_gain_i(priv, p->delivery_system);
2022 p->strength.stat[0].scale = FE_SCALE_DECIBEL;
2024 * Formula was empirically determinated via linear regression,
2025 * using frequencies: 175 MHz, 410 MHz and 800 MHz.
2027 p->strength.stat[0].uvalue = strength * 3775 / 1000 - 90185;
2031 strength = 65535 - cxd2841er_read_agc_gain_s(priv);
2032 p->strength.stat[0].scale = FE_SCALE_RELATIVE;
2033 p->strength.stat[0].uvalue = strength;
2036 p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
2041 static void cxd2841er_read_snr(struct dvb_frontend *fe)
2045 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
2046 struct cxd2841er_priv *priv = fe->demodulator_priv;
2048 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
2049 switch (p->delivery_system) {
2050 case SYS_DVBC_ANNEX_A:
2051 case SYS_DVBC_ANNEX_B:
2052 case SYS_DVBC_ANNEX_C:
2053 ret = cxd2841er_read_snr_c(priv, &tmp);
2056 ret = cxd2841er_read_snr_t(priv, &tmp);
2059 ret = cxd2841er_read_snr_t2(priv, &tmp);
2062 ret = cxd2841er_read_snr_i(priv, &tmp);
2066 ret = cxd2841er_dvbs_read_snr(priv, p->delivery_system, &tmp);
2069 dev_dbg(&priv->i2c->dev, "%s(): unknown delivery system %d\n",
2070 __func__, p->delivery_system);
2071 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
2075 dev_dbg(&priv->i2c->dev, "%s(): snr=%d\n",
2076 __func__, (int32_t)tmp);
2079 p->cnr.stat[0].scale = FE_SCALE_DECIBEL;
2080 p->cnr.stat[0].svalue = tmp;
2082 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
2086 static void cxd2841er_read_ucblocks(struct dvb_frontend *fe)
2088 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
2089 struct cxd2841er_priv *priv = fe->demodulator_priv;
2092 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
2093 switch (p->delivery_system) {
2094 case SYS_DVBC_ANNEX_A:
2095 case SYS_DVBC_ANNEX_B:
2096 case SYS_DVBC_ANNEX_C:
2097 cxd2841er_read_packet_errors_c(priv, &ucblocks);
2100 cxd2841er_read_packet_errors_t(priv, &ucblocks);
2103 cxd2841er_read_packet_errors_t2(priv, &ucblocks);
2106 cxd2841er_read_packet_errors_i(priv, &ucblocks);
2109 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
2112 dev_dbg(&priv->i2c->dev, "%s() ucblocks=%u\n", __func__, ucblocks);
2114 p->block_error.stat[0].scale = FE_SCALE_COUNTER;
2115 p->block_error.stat[0].uvalue = ucblocks;
2118 static int cxd2841er_dvbt2_set_profile(
2119 struct cxd2841er_priv *priv, enum cxd2841er_dvbt2_profile_t profile)
2124 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
2126 case DVBT2_PROFILE_BASE:
2128 /* Set early unlock time */
2129 seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x0E:0x0C;
2131 case DVBT2_PROFILE_LITE:
2133 /* Set early unlock time */
2134 seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x2E:0x28;
2136 case DVBT2_PROFILE_ANY:
2138 /* Set early unlock time */
2139 seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x2E:0x28;
2144 /* Set SLV-T Bank : 0x2E */
2145 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2e);
2146 /* Set profile and tune mode */
2147 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x10, tune_mode, 0x07);
2148 /* Set SLV-T Bank : 0x2B */
2149 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
2150 /* Set early unlock detection time */
2151 cxd2841er_write_reg(priv, I2C_SLVT, 0x9d, seq_not2d_time);
2155 static int cxd2841er_dvbt2_set_plp_config(struct cxd2841er_priv *priv,
2156 u8 is_auto, u8 plp_id)
2159 dev_dbg(&priv->i2c->dev,
2160 "%s() using auto PLP selection\n", __func__);
2162 dev_dbg(&priv->i2c->dev,
2163 "%s() using manual PLP selection, ID %d\n",
2166 /* Set SLV-T Bank : 0x23 */
2167 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23);
2169 /* Manual PLP selection mode. Set the data PLP Id. */
2170 cxd2841er_write_reg(priv, I2C_SLVT, 0xaf, plp_id);
2172 /* Auto PLP select (Scanning mode = 0x00). Data PLP select = 0x01. */
2173 cxd2841er_write_reg(priv, I2C_SLVT, 0xad, (is_auto ? 0x00 : 0x01));
2177 static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv,
2181 u8 data[MAX_WRITE_REGSIZE];
2183 static const uint8_t nominalRate8bw[3][5] = {
2184 /* TRCG Nominal Rate [37:0] */
2185 {0x11, 0xF0, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2186 {0x15, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2187 {0x11, 0xF0, 0x00, 0x00, 0x00} /* 41MHz XTal */
2190 static const uint8_t nominalRate7bw[3][5] = {
2191 /* TRCG Nominal Rate [37:0] */
2192 {0x14, 0x80, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2193 {0x18, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2194 {0x14, 0x80, 0x00, 0x00, 0x00} /* 41MHz XTal */
2197 static const uint8_t nominalRate6bw[3][5] = {
2198 /* TRCG Nominal Rate [37:0] */
2199 {0x17, 0xEA, 0xAA, 0xAA, 0xAA}, /* 20.5MHz XTal */
2200 {0x1C, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2201 {0x17, 0xEA, 0xAA, 0xAA, 0xAA} /* 41MHz XTal */
2204 static const uint8_t nominalRate5bw[3][5] = {
2205 /* TRCG Nominal Rate [37:0] */
2206 {0x1C, 0xB3, 0x33, 0x33, 0x33}, /* 20.5MHz XTal */
2207 {0x21, 0x99, 0x99, 0x99, 0x99}, /* 24MHz XTal */
2208 {0x1C, 0xB3, 0x33, 0x33, 0x33} /* 41MHz XTal */
2211 static const uint8_t nominalRate17bw[3][5] = {
2212 /* TRCG Nominal Rate [37:0] */
2213 {0x58, 0xE2, 0xAF, 0xE0, 0xBC}, /* 20.5MHz XTal */
2214 {0x68, 0x0F, 0xA2, 0x32, 0xD0}, /* 24MHz XTal */
2215 {0x58, 0xE2, 0xAF, 0xE0, 0xBC} /* 41MHz XTal */
2218 static const uint8_t itbCoef8bw[3][14] = {
2219 {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA,
2220 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8}, /* 20.5MHz XTal */
2221 {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1,
2222 0x29, 0xA5, 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz XTal */
2223 {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA,
2224 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8} /* 41MHz XTal */
2227 static const uint8_t itbCoef7bw[3][14] = {
2228 {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6,
2229 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5}, /* 20.5MHz XTal */
2230 {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0,
2231 0x29, 0xA2, 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz XTal */
2232 {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6,
2233 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5} /* 41MHz XTal */
2236 static const uint8_t itbCoef6bw[3][14] = {
2237 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
2238 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
2239 {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E,
2240 0x29, 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
2241 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
2242 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
2245 static const uint8_t itbCoef5bw[3][14] = {
2246 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
2247 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
2248 {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E,
2249 0x29, 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
2250 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
2251 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
2254 static const uint8_t itbCoef17bw[3][14] = {
2255 {0x25, 0xA0, 0x36, 0x8D, 0x2E, 0x94, 0x28, 0x9B,
2256 0x32, 0x90, 0x2C, 0x9D, 0x29, 0x99}, /* 20.5MHz XTal */
2257 {0x33, 0x8E, 0x2B, 0x97, 0x2D, 0x95, 0x37, 0x8B,
2258 0x30, 0x97, 0x2D, 0x9A, 0x21, 0xA4}, /* 24MHz XTal */
2259 {0x25, 0xA0, 0x36, 0x8D, 0x2E, 0x94, 0x28, 0x9B,
2260 0x32, 0x90, 0x2C, 0x9D, 0x29, 0x99} /* 41MHz XTal */
2263 /* Set SLV-T Bank : 0x20 */
2264 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
2266 switch (bandwidth) {
2268 /* <Timing Recovery setting> */
2269 cxd2841er_write_regs(priv, I2C_SLVT,
2270 0x9F, nominalRate8bw[priv->xtal], 5);
2272 /* Set SLV-T Bank : 0x27 */
2273 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
2274 cxd2841er_set_reg_bits(priv, I2C_SLVT,
2277 /* Set SLV-T Bank : 0x10 */
2278 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2280 /* Group delay equaliser settings for
2281 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2283 if (priv->flags & CXD2841ER_ASCOT)
2284 cxd2841er_write_regs(priv, I2C_SLVT,
2285 0xA6, itbCoef8bw[priv->xtal], 14);
2286 /* <IF freq setting> */
2287 ifhz = cxd2841er_get_if_hz(priv, 4800000);
2288 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2289 data[0] = (u8) ((iffreq >> 16) & 0xff);
2290 data[1] = (u8)((iffreq >> 8) & 0xff);
2291 data[2] = (u8)(iffreq & 0xff);
2292 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2293 /* System bandwidth setting */
2294 cxd2841er_set_reg_bits(
2295 priv, I2C_SLVT, 0xD7, 0x00, 0x07);
2298 /* <Timing Recovery setting> */
2299 cxd2841er_write_regs(priv, I2C_SLVT,
2300 0x9F, nominalRate7bw[priv->xtal], 5);
2302 /* Set SLV-T Bank : 0x27 */
2303 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
2304 cxd2841er_set_reg_bits(priv, I2C_SLVT,
2307 /* Set SLV-T Bank : 0x10 */
2308 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2310 /* Group delay equaliser settings for
2311 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2313 if (priv->flags & CXD2841ER_ASCOT)
2314 cxd2841er_write_regs(priv, I2C_SLVT,
2315 0xA6, itbCoef7bw[priv->xtal], 14);
2316 /* <IF freq setting> */
2317 ifhz = cxd2841er_get_if_hz(priv, 4200000);
2318 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2319 data[0] = (u8) ((iffreq >> 16) & 0xff);
2320 data[1] = (u8)((iffreq >> 8) & 0xff);
2321 data[2] = (u8)(iffreq & 0xff);
2322 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2323 /* System bandwidth setting */
2324 cxd2841er_set_reg_bits(
2325 priv, I2C_SLVT, 0xD7, 0x02, 0x07);
2328 /* <Timing Recovery setting> */
2329 cxd2841er_write_regs(priv, I2C_SLVT,
2330 0x9F, nominalRate6bw[priv->xtal], 5);
2332 /* Set SLV-T Bank : 0x27 */
2333 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
2334 cxd2841er_set_reg_bits(priv, I2C_SLVT,
2337 /* Set SLV-T Bank : 0x10 */
2338 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2340 /* Group delay equaliser settings for
2341 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2343 if (priv->flags & CXD2841ER_ASCOT)
2344 cxd2841er_write_regs(priv, I2C_SLVT,
2345 0xA6, itbCoef6bw[priv->xtal], 14);
2346 /* <IF freq setting> */
2347 ifhz = cxd2841er_get_if_hz(priv, 3600000);
2348 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2349 data[0] = (u8) ((iffreq >> 16) & 0xff);
2350 data[1] = (u8)((iffreq >> 8) & 0xff);
2351 data[2] = (u8)(iffreq & 0xff);
2352 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2353 /* System bandwidth setting */
2354 cxd2841er_set_reg_bits(
2355 priv, I2C_SLVT, 0xD7, 0x04, 0x07);
2358 /* <Timing Recovery setting> */
2359 cxd2841er_write_regs(priv, I2C_SLVT,
2360 0x9F, nominalRate5bw[priv->xtal], 5);
2362 /* Set SLV-T Bank : 0x27 */
2363 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
2364 cxd2841er_set_reg_bits(priv, I2C_SLVT,
2367 /* Set SLV-T Bank : 0x10 */
2368 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2370 /* Group delay equaliser settings for
2371 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2373 if (priv->flags & CXD2841ER_ASCOT)
2374 cxd2841er_write_regs(priv, I2C_SLVT,
2375 0xA6, itbCoef5bw[priv->xtal], 14);
2376 /* <IF freq setting> */
2377 ifhz = cxd2841er_get_if_hz(priv, 3600000);
2378 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2379 data[0] = (u8) ((iffreq >> 16) & 0xff);
2380 data[1] = (u8)((iffreq >> 8) & 0xff);
2381 data[2] = (u8)(iffreq & 0xff);
2382 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2383 /* System bandwidth setting */
2384 cxd2841er_set_reg_bits(
2385 priv, I2C_SLVT, 0xD7, 0x06, 0x07);
2388 /* <Timing Recovery setting> */
2389 cxd2841er_write_regs(priv, I2C_SLVT,
2390 0x9F, nominalRate17bw[priv->xtal], 5);
2392 /* Set SLV-T Bank : 0x27 */
2393 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
2394 cxd2841er_set_reg_bits(priv, I2C_SLVT,
2397 /* Set SLV-T Bank : 0x10 */
2398 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2400 /* Group delay equaliser settings for
2401 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2403 if (priv->flags & CXD2841ER_ASCOT)
2404 cxd2841er_write_regs(priv, I2C_SLVT,
2405 0xA6, itbCoef17bw[priv->xtal], 14);
2406 /* <IF freq setting> */
2407 ifhz = cxd2841er_get_if_hz(priv, 3500000);
2408 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2409 data[0] = (u8) ((iffreq >> 16) & 0xff);
2410 data[1] = (u8)((iffreq >> 8) & 0xff);
2411 data[2] = (u8)(iffreq & 0xff);
2412 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2413 /* System bandwidth setting */
2414 cxd2841er_set_reg_bits(
2415 priv, I2C_SLVT, 0xD7, 0x03, 0x07);
2423 static int cxd2841er_sleep_tc_to_active_t_band(
2424 struct cxd2841er_priv *priv, u32 bandwidth)
2426 u8 data[MAX_WRITE_REGSIZE];
2428 static const u8 nominalRate8bw[3][5] = {
2429 /* TRCG Nominal Rate [37:0] */
2430 {0x11, 0xF0, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2431 {0x15, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2432 {0x11, 0xF0, 0x00, 0x00, 0x00} /* 41MHz XTal */
2434 static const u8 nominalRate7bw[3][5] = {
2435 /* TRCG Nominal Rate [37:0] */
2436 {0x14, 0x80, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2437 {0x18, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2438 {0x14, 0x80, 0x00, 0x00, 0x00} /* 41MHz XTal */
2440 static const u8 nominalRate6bw[3][5] = {
2441 /* TRCG Nominal Rate [37:0] */
2442 {0x17, 0xEA, 0xAA, 0xAA, 0xAA}, /* 20.5MHz XTal */
2443 {0x1C, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2444 {0x17, 0xEA, 0xAA, 0xAA, 0xAA} /* 41MHz XTal */
2446 static const u8 nominalRate5bw[3][5] = {
2447 /* TRCG Nominal Rate [37:0] */
2448 {0x1C, 0xB3, 0x33, 0x33, 0x33}, /* 20.5MHz XTal */
2449 {0x21, 0x99, 0x99, 0x99, 0x99}, /* 24MHz XTal */
2450 {0x1C, 0xB3, 0x33, 0x33, 0x33} /* 41MHz XTal */
2453 static const u8 itbCoef8bw[3][14] = {
2454 {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, 0x23, 0xA9,
2455 0x1F, 0xA8, 0x2C, 0xC8}, /* 20.5MHz XTal */
2456 {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, 0x29, 0xA5,
2457 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz XTal */
2458 {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, 0x23, 0xA9,
2459 0x1F, 0xA8, 0x2C, 0xC8} /* 41MHz XTal */
2461 static const u8 itbCoef7bw[3][14] = {
2462 {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, 0x29, 0xB0,
2463 0x26, 0xA9, 0x21, 0xA5}, /* 20.5MHz XTal */
2464 {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, 0x29, 0xA2,
2465 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz XTal */
2466 {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, 0x29, 0xB0,
2467 0x26, 0xA9, 0x21, 0xA5} /* 41MHz XTal */
2469 static const u8 itbCoef6bw[3][14] = {
2470 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
2471 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
2472 {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, 0xA4,
2473 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
2474 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
2475 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
2477 static const u8 itbCoef5bw[3][14] = {
2478 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
2479 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
2480 {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, 0xA4,
2481 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */
2482 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF,
2483 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */
2486 /* Set SLV-T Bank : 0x13 */
2487 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
2488 /* Echo performance optimization setting */
2491 cxd2841er_write_regs(priv, I2C_SLVT, 0x9C, data, 2);
2493 /* Set SLV-T Bank : 0x10 */
2494 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2496 switch (bandwidth) {
2498 /* <Timing Recovery setting> */
2499 cxd2841er_write_regs(priv, I2C_SLVT,
2500 0x9F, nominalRate8bw[priv->xtal], 5);
2501 /* Group delay equaliser settings for
2502 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2504 if (priv->flags & CXD2841ER_ASCOT)
2505 cxd2841er_write_regs(priv, I2C_SLVT,
2506 0xA6, itbCoef8bw[priv->xtal], 14);
2507 /* <IF freq setting> */
2508 ifhz = cxd2841er_get_if_hz(priv, 4800000);
2509 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2510 data[0] = (u8) ((iffreq >> 16) & 0xff);
2511 data[1] = (u8)((iffreq >> 8) & 0xff);
2512 data[2] = (u8)(iffreq & 0xff);
2513 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2514 /* System bandwidth setting */
2515 cxd2841er_set_reg_bits(
2516 priv, I2C_SLVT, 0xD7, 0x00, 0x07);
2518 /* Demod core latency setting */
2519 if (priv->xtal == SONY_XTAL_24000) {
2526 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2528 /* Notch filter setting */
2531 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
2532 cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
2535 /* <Timing Recovery setting> */
2536 cxd2841er_write_regs(priv, I2C_SLVT,
2537 0x9F, nominalRate7bw[priv->xtal], 5);
2538 /* Group delay equaliser settings for
2539 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2541 if (priv->flags & CXD2841ER_ASCOT)
2542 cxd2841er_write_regs(priv, I2C_SLVT,
2543 0xA6, itbCoef7bw[priv->xtal], 14);
2544 /* <IF freq setting> */
2545 ifhz = cxd2841er_get_if_hz(priv, 4200000);
2546 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2547 data[0] = (u8) ((iffreq >> 16) & 0xff);
2548 data[1] = (u8)((iffreq >> 8) & 0xff);
2549 data[2] = (u8)(iffreq & 0xff);
2550 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2551 /* System bandwidth setting */
2552 cxd2841er_set_reg_bits(
2553 priv, I2C_SLVT, 0xD7, 0x02, 0x07);
2555 /* Demod core latency setting */
2556 if (priv->xtal == SONY_XTAL_24000) {
2563 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2565 /* Notch filter setting */
2568 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
2569 cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
2572 /* <Timing Recovery setting> */
2573 cxd2841er_write_regs(priv, I2C_SLVT,
2574 0x9F, nominalRate6bw[priv->xtal], 5);
2575 /* Group delay equaliser settings for
2576 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2578 if (priv->flags & CXD2841ER_ASCOT)
2579 cxd2841er_write_regs(priv, I2C_SLVT,
2580 0xA6, itbCoef6bw[priv->xtal], 14);
2581 /* <IF freq setting> */
2582 ifhz = cxd2841er_get_if_hz(priv, 3600000);
2583 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2584 data[0] = (u8) ((iffreq >> 16) & 0xff);
2585 data[1] = (u8)((iffreq >> 8) & 0xff);
2586 data[2] = (u8)(iffreq & 0xff);
2587 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2588 /* System bandwidth setting */
2589 cxd2841er_set_reg_bits(
2590 priv, I2C_SLVT, 0xD7, 0x04, 0x07);
2592 /* Demod core latency setting */
2593 if (priv->xtal == SONY_XTAL_24000) {
2600 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2602 /* Notch filter setting */
2605 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
2606 cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
2609 /* <Timing Recovery setting> */
2610 cxd2841er_write_regs(priv, I2C_SLVT,
2611 0x9F, nominalRate5bw[priv->xtal], 5);
2612 /* Group delay equaliser settings for
2613 * ASCOT2D, ASCOT2E and ASCOT3 tuners
2615 if (priv->flags & CXD2841ER_ASCOT)
2616 cxd2841er_write_regs(priv, I2C_SLVT,
2617 0xA6, itbCoef5bw[priv->xtal], 14);
2618 /* <IF freq setting> */
2619 ifhz = cxd2841er_get_if_hz(priv, 3600000);
2620 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2621 data[0] = (u8) ((iffreq >> 16) & 0xff);
2622 data[1] = (u8)((iffreq >> 8) & 0xff);
2623 data[2] = (u8)(iffreq & 0xff);
2624 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2625 /* System bandwidth setting */
2626 cxd2841er_set_reg_bits(
2627 priv, I2C_SLVT, 0xD7, 0x06, 0x07);
2629 /* Demod core latency setting */
2630 if (priv->xtal == SONY_XTAL_24000) {
2637 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2639 /* Notch filter setting */
2642 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17);
2643 cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2);
2650 static int cxd2841er_sleep_tc_to_active_i_band(
2651 struct cxd2841er_priv *priv, u32 bandwidth)
2656 /* TRCG Nominal Rate */
2657 static const u8 nominalRate8bw[3][5] = {
2658 {0x00, 0x00, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2659 {0x11, 0xB8, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2660 {0x00, 0x00, 0x00, 0x00, 0x00} /* 41MHz XTal */
2663 static const u8 nominalRate7bw[3][5] = {
2664 {0x00, 0x00, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2665 {0x14, 0x40, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2666 {0x00, 0x00, 0x00, 0x00, 0x00} /* 41MHz XTal */
2669 static const u8 nominalRate6bw[3][5] = {
2670 {0x14, 0x2E, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */
2671 {0x17, 0xA0, 0x00, 0x00, 0x00}, /* 24MHz XTal */
2672 {0x14, 0x2E, 0x00, 0x00, 0x00} /* 41MHz XTal */
2675 static const u8 itbCoef8bw[3][14] = {
2676 {0x00}, /* 20.5MHz XTal */
2677 {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, 0x29,
2678 0xA5, 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz Xtal */
2679 {0x0}, /* 41MHz XTal */
2682 static const u8 itbCoef7bw[3][14] = {
2683 {0x00}, /* 20.5MHz XTal */
2684 {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, 0x29,
2685 0xA2, 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz Xtal */
2686 {0x00}, /* 41MHz XTal */
2689 static const u8 itbCoef6bw[3][14] = {
2690 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00,
2691 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */
2692 {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29,
2693 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz Xtal */
2694 {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00,
2695 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 41MHz XTal */
2698 dev_dbg(&priv->i2c->dev, "%s() bandwidth=%u\n", __func__, bandwidth);
2699 /* Set SLV-T Bank : 0x10 */
2700 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2702 /* 20.5/41MHz Xtal support is not available
2703 * on ISDB-T 7MHzBW and 8MHzBW
2705 if (priv->xtal != SONY_XTAL_24000 && bandwidth > 6000000) {
2706 dev_err(&priv->i2c->dev,
2707 "%s(): bandwidth %d supported only for 24MHz xtal\n",
2708 __func__, bandwidth);
2712 switch (bandwidth) {
2714 /* TRCG Nominal Rate */
2715 cxd2841er_write_regs(priv, I2C_SLVT,
2716 0x9F, nominalRate8bw[priv->xtal], 5);
2717 /* Group delay equaliser settings for ASCOT tuners optimized */
2718 if (priv->flags & CXD2841ER_ASCOT)
2719 cxd2841er_write_regs(priv, I2C_SLVT,
2720 0xA6, itbCoef8bw[priv->xtal], 14);
2722 /* IF freq setting */
2723 ifhz = cxd2841er_get_if_hz(priv, 4750000);
2724 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2725 data[0] = (u8) ((iffreq >> 16) & 0xff);
2726 data[1] = (u8)((iffreq >> 8) & 0xff);
2727 data[2] = (u8)(iffreq & 0xff);
2728 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2730 /* System bandwidth setting */
2731 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x0, 0x7);
2733 /* Demod core latency setting */
2736 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2738 /* Acquisition optimization setting */
2739 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12);
2740 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x03, 0x07);
2741 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
2742 cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x03);
2745 /* TRCG Nominal Rate */
2746 cxd2841er_write_regs(priv, I2C_SLVT,
2747 0x9F, nominalRate7bw[priv->xtal], 5);
2748 /* Group delay equaliser settings for ASCOT tuners optimized */
2749 if (priv->flags & CXD2841ER_ASCOT)
2750 cxd2841er_write_regs(priv, I2C_SLVT,
2751 0xA6, itbCoef7bw[priv->xtal], 14);
2753 /* IF freq setting */
2754 ifhz = cxd2841er_get_if_hz(priv, 4150000);
2755 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2756 data[0] = (u8) ((iffreq >> 16) & 0xff);
2757 data[1] = (u8)((iffreq >> 8) & 0xff);
2758 data[2] = (u8)(iffreq & 0xff);
2759 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2761 /* System bandwidth setting */
2762 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x02, 0x7);
2764 /* Demod core latency setting */
2767 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2769 /* Acquisition optimization setting */
2770 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12);
2771 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x03, 0x07);
2772 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
2773 cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x02);
2776 /* TRCG Nominal Rate */
2777 cxd2841er_write_regs(priv, I2C_SLVT,
2778 0x9F, nominalRate6bw[priv->xtal], 5);
2779 /* Group delay equaliser settings for ASCOT tuners optimized */
2780 if (priv->flags & CXD2841ER_ASCOT)
2781 cxd2841er_write_regs(priv, I2C_SLVT,
2782 0xA6, itbCoef6bw[priv->xtal], 14);
2784 /* IF freq setting */
2785 ifhz = cxd2841er_get_if_hz(priv, 3550000);
2786 iffreq = cxd2841er_calc_iffreq_xtal(priv->xtal, ifhz);
2787 data[0] = (u8) ((iffreq >> 16) & 0xff);
2788 data[1] = (u8)((iffreq >> 8) & 0xff);
2789 data[2] = (u8)(iffreq & 0xff);
2790 cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3);
2792 /* System bandwidth setting */
2793 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x04, 0x7);
2795 /* Demod core latency setting */
2796 if (priv->xtal == SONY_XTAL_24000) {
2803 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
2805 /* Acquisition optimization setting */
2806 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12);
2807 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x07, 0x07);
2808 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
2809 cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x02);
2812 dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n",
2813 __func__, bandwidth);
2819 static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv,
2822 u8 bw7_8mhz_b10_a6[] = {
2823 0x2D, 0xC7, 0x04, 0xF4, 0x07, 0xC5, 0x2A, 0xB8,
2824 0x27, 0x9E, 0x27, 0xA4, 0x29, 0xAB };
2825 u8 bw6mhz_b10_a6[] = {
2826 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8,
2827 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 };
2831 if (bandwidth != 6000000 &&
2832 bandwidth != 7000000 &&
2833 bandwidth != 8000000) {
2834 dev_info(&priv->i2c->dev, "%s(): unsupported bandwidth %d. Forcing 8Mhz!\n",
2835 __func__, bandwidth);
2836 bandwidth = 8000000;
2839 dev_dbg(&priv->i2c->dev, "%s() bw=%d\n", __func__, bandwidth);
2840 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2841 switch (bandwidth) {
2844 if (priv->flags & CXD2841ER_ASCOT)
2845 cxd2841er_write_regs(
2846 priv, I2C_SLVT, 0xa6,
2847 bw7_8mhz_b10_a6, sizeof(bw7_8mhz_b10_a6));
2848 ifhz = cxd2841er_get_if_hz(priv, 4900000);
2849 iffreq = cxd2841er_calc_iffreq(ifhz);
2852 if (priv->flags & CXD2841ER_ASCOT)
2853 cxd2841er_write_regs(
2854 priv, I2C_SLVT, 0xa6,
2855 bw6mhz_b10_a6, sizeof(bw6mhz_b10_a6));
2856 ifhz = cxd2841er_get_if_hz(priv, 3700000);
2857 iffreq = cxd2841er_calc_iffreq(ifhz);
2860 dev_err(&priv->i2c->dev, "%s(): unsupported bandwidth %d\n",
2861 __func__, bandwidth);
2864 /* <IF freq setting> */
2865 b10_b6[0] = (u8) ((iffreq >> 16) & 0xff);
2866 b10_b6[1] = (u8)((iffreq >> 8) & 0xff);
2867 b10_b6[2] = (u8)(iffreq & 0xff);
2868 cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6));
2869 /* Set SLV-T Bank : 0x11 */
2870 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
2871 switch (bandwidth) {
2874 cxd2841er_set_reg_bits(
2875 priv, I2C_SLVT, 0xa3, 0x00, 0x1f);
2878 cxd2841er_set_reg_bits(
2879 priv, I2C_SLVT, 0xa3, 0x14, 0x1f);
2882 /* Set SLV-T Bank : 0x40 */
2883 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
2884 switch (bandwidth) {
2886 cxd2841er_set_reg_bits(
2887 priv, I2C_SLVT, 0x26, 0x0b, 0x0f);
2888 cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x3e);
2891 cxd2841er_set_reg_bits(
2892 priv, I2C_SLVT, 0x26, 0x09, 0x0f);
2893 cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0xd6);
2896 cxd2841er_set_reg_bits(
2897 priv, I2C_SLVT, 0x26, 0x08, 0x0f);
2898 cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x6e);
2904 static int cxd2841er_sleep_tc_to_active_t(struct cxd2841er_priv *priv,
2907 u8 data[2] = { 0x09, 0x54 };
2908 u8 data24m[3] = {0xDC, 0x6C, 0x00};
2910 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
2911 cxd2841er_set_ts_clock_mode(priv, SYS_DVBT);
2912 /* Set SLV-X Bank : 0x00 */
2913 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
2914 /* Set demod mode */
2915 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01);
2916 /* Set SLV-T Bank : 0x00 */
2917 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
2918 /* Enable demod clock */
2919 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
2920 /* Disable RF level monitor */
2921 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
2922 /* Enable ADC clock */
2923 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
2925 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
2926 /* Enable ADC 2 & 3 */
2927 if (priv->xtal == SONY_XTAL_41000) {
2931 cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
2933 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
2934 /* Set SLV-T Bank : 0x10 */
2935 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2936 /* IFAGC gain settings */
2937 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f);
2938 /* Set SLV-T Bank : 0x11 */
2939 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
2940 /* BBAGC TARGET level setting */
2941 cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50);
2942 /* Set SLV-T Bank : 0x10 */
2943 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2945 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
2946 ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
2947 /* Set SLV-T Bank : 0x18 */
2948 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18);
2949 /* Pre-RS BER moniter setting */
2950 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x36, 0x40, 0x07);
2951 /* FEC Auto Recovery setting */
2952 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01);
2953 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x01, 0x01);
2954 /* Set SLV-T Bank : 0x00 */
2955 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
2957 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
2958 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
2960 if (priv->xtal == SONY_XTAL_24000) {
2961 /* Set SLV-T Bank : 0x10 */
2962 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
2963 cxd2841er_write_reg(priv, I2C_SLVT, 0xBF, 0x60);
2964 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18);
2965 cxd2841er_write_regs(priv, I2C_SLVT, 0x24, data24m, 3);
2968 cxd2841er_sleep_tc_to_active_t_band(priv, bandwidth);
2969 /* Set SLV-T Bank : 0x00 */
2970 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
2971 /* Disable HiZ Setting 1 */
2972 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
2973 /* Disable HiZ Setting 2 */
2974 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
2975 priv->state = STATE_ACTIVE_TC;
2979 static int cxd2841er_sleep_tc_to_active_t2(struct cxd2841er_priv *priv,
2982 u8 data[MAX_WRITE_REGSIZE];
2984 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
2985 cxd2841er_set_ts_clock_mode(priv, SYS_DVBT2);
2986 /* Set SLV-X Bank : 0x00 */
2987 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
2988 /* Set demod mode */
2989 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x02);
2990 /* Set SLV-T Bank : 0x00 */
2991 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
2992 /* Enable demod clock */
2993 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
2994 /* Disable RF level monitor */
2995 cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x00);
2996 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
2997 /* Enable ADC clock */
2998 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
3000 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
3002 if (priv->xtal == SONY_XTAL_41000) {
3010 cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
3012 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
3013 /* Set SLV-T Bank : 0x10 */
3014 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3015 /* IFAGC gain settings */
3016 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f);
3017 /* Set SLV-T Bank : 0x11 */
3018 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
3019 /* BBAGC TARGET level setting */
3020 cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50);
3021 /* Set SLV-T Bank : 0x10 */
3022 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3024 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
3025 ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
3026 /* Set SLV-T Bank : 0x20 */
3027 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
3028 /* Acquisition optimization setting */
3029 cxd2841er_write_reg(priv, I2C_SLVT, 0x8b, 0x3c);
3030 /* Set SLV-T Bank : 0x2b */
3031 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
3032 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x76, 0x20, 0x70);
3033 /* Set SLV-T Bank : 0x23 */
3034 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23);
3035 /* L1 Control setting */
3036 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xE6, 0x00, 0x03);
3037 /* Set SLV-T Bank : 0x00 */
3038 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3040 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
3041 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
3042 /* DVB-T2 initial setting */
3043 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13);
3044 cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x10);
3045 cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x34);
3046 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f);
3047 cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xd8);
3048 /* Set SLV-T Bank : 0x2a */
3049 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a);
3050 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x04, 0x0f);
3051 /* Set SLV-T Bank : 0x2b */
3052 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b);
3053 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x20, 0x3f);
3055 /* 24MHz Xtal setting */
3056 if (priv->xtal == SONY_XTAL_24000) {
3057 /* Set SLV-T Bank : 0x11 */
3058 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
3062 cxd2841er_write_regs(priv, I2C_SLVT, 0x33, data, 3);
3064 /* Set SLV-T Bank : 0x20 */
3065 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20);
3069 cxd2841er_write_regs(priv, I2C_SLVT, 0x95, data, 3);
3071 cxd2841er_write_reg(priv, I2C_SLVT, 0x99, 0x18);
3075 cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2);
3077 /* Set SLV-T Bank : 0x24 */
3078 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24);
3081 cxd2841er_write_regs(priv, I2C_SLVT, 0x34, data, 2);
3086 cxd2841er_write_regs(priv, I2C_SLVT, 0xD2, data, 3);
3091 cxd2841er_write_regs(priv, I2C_SLVT, 0xDD, data, 3);
3093 cxd2841er_write_reg(priv, I2C_SLVT, 0xE0, 0x00);
3095 /* Set SLV-T Bank : 0x25 */
3096 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x25);
3097 cxd2841er_write_reg(priv, I2C_SLVT, 0xED, 0x60);
3099 /* Set SLV-T Bank : 0x27 */
3100 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27);
3101 cxd2841er_write_reg(priv, I2C_SLVT, 0xFA, 0x34);
3103 /* Set SLV-T Bank : 0x2B */
3104 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2B);
3105 cxd2841er_write_reg(priv, I2C_SLVT, 0x4B, 0x2F);
3106 cxd2841er_write_reg(priv, I2C_SLVT, 0x9E, 0x0E);
3108 /* Set SLV-T Bank : 0x2D */
3109 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2D);
3112 cxd2841er_write_regs(priv, I2C_SLVT, 0x24, data, 2);
3114 /* Set SLV-T Bank : 0x5E */
3115 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x5E);
3118 cxd2841er_write_regs(priv, I2C_SLVT, 0x8C, data, 2);
3121 cxd2841er_sleep_tc_to_active_t2_band(priv, bandwidth);
3123 /* Set SLV-T Bank : 0x00 */
3124 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3125 /* Disable HiZ Setting 1 */
3126 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
3127 /* Disable HiZ Setting 2 */
3128 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
3129 priv->state = STATE_ACTIVE_TC;
3134 static int cxd2841er_sleep_tc_to_active_i(struct cxd2841er_priv *priv,
3137 u8 data[2] = { 0x09, 0x54 };
3138 u8 data24m[2] = {0x60, 0x00};
3139 u8 data24m2[3] = {0xB7, 0x1B, 0x00};
3141 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3142 cxd2841er_set_ts_clock_mode(priv, SYS_DVBT);
3143 /* Set SLV-X Bank : 0x00 */
3144 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
3145 /* Set demod mode */
3146 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x06);
3147 /* Set SLV-T Bank : 0x00 */
3148 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3149 /* Enable demod clock */
3150 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
3151 /* Enable RF level monitor */
3152 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x01);
3153 cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x01);
3154 /* Enable ADC clock */
3155 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
3157 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
3158 /* xtal freq 20.5MHz or 24M */
3159 cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
3161 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
3163 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
3164 ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
3165 /* FEC Auto Recovery setting */
3166 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01);
3167 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x00, 0x01);
3168 /* ISDB-T initial setting */
3169 /* Set SLV-T Bank : 0x00 */
3170 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3171 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x00, 0x01);
3172 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x00, 0x01);
3173 /* Set SLV-T Bank : 0x10 */
3174 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3175 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x69, 0x04, 0x07);
3176 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x6B, 0x03, 0x07);
3177 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9D, 0x50, 0xFF);
3178 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xD3, 0x06, 0x1F);
3179 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xED, 0x00, 0x01);
3180 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xE2, 0xCE, 0x80);
3181 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xF2, 0x13, 0x10);
3182 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xDE, 0x2E, 0x3F);
3183 /* Set SLV-T Bank : 0x15 */
3184 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15);
3185 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xDE, 0x02, 0x03);
3186 /* Set SLV-T Bank : 0x1E */
3187 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x1E);
3188 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x73, 0x68, 0xFF);
3189 /* Set SLV-T Bank : 0x63 */
3190 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x63);
3191 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x81, 0x00, 0x01);
3193 /* for xtal 24MHz */
3194 /* Set SLV-T Bank : 0x10 */
3195 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3196 cxd2841er_write_regs(priv, I2C_SLVT, 0xBF, data24m, 2);
3197 /* Set SLV-T Bank : 0x60 */
3198 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60);
3199 cxd2841er_write_regs(priv, I2C_SLVT, 0xA8, data24m2, 3);
3201 cxd2841er_sleep_tc_to_active_i_band(priv, bandwidth);
3202 /* Set SLV-T Bank : 0x00 */
3203 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3204 /* Disable HiZ Setting 1 */
3205 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
3206 /* Disable HiZ Setting 2 */
3207 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
3208 priv->state = STATE_ACTIVE_TC;
3212 static int cxd2841er_sleep_tc_to_active_c(struct cxd2841er_priv *priv,
3215 u8 data[2] = { 0x09, 0x54 };
3217 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3218 cxd2841er_set_ts_clock_mode(priv, SYS_DVBC_ANNEX_A);
3219 /* Set SLV-X Bank : 0x00 */
3220 cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00);
3221 /* Set demod mode */
3222 cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x04);
3223 /* Set SLV-T Bank : 0x00 */
3224 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3225 /* Enable demod clock */
3226 cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01);
3227 /* Disable RF level monitor */
3228 cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x00);
3229 cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00);
3230 /* Enable ADC clock */
3231 cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00);
3233 cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a);
3234 /* xtal freq 20.5MHz */
3235 cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2);
3237 cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00);
3238 /* Set SLV-T Bank : 0x10 */
3239 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3240 /* IFAGC gain settings */
3241 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x09, 0x1f);
3242 /* Set SLV-T Bank : 0x11 */
3243 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11);
3244 /* BBAGC TARGET level setting */
3245 cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x48);
3246 /* Set SLV-T Bank : 0x10 */
3247 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3249 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5,
3250 ((priv->flags & CXD2841ER_ASCOT) ? 0x01 : 0x00), 0x01);
3251 /* Set SLV-T Bank : 0x40 */
3252 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40);
3254 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc3, 0x00, 0x04);
3255 /* Set SLV-T Bank : 0x00 */
3256 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3258 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01);
3259 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01);
3261 cxd2841er_sleep_tc_to_active_c_band(priv, bandwidth);
3262 /* Set SLV-T Bank : 0x00 */
3263 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3264 /* Disable HiZ Setting 1 */
3265 cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28);
3266 /* Disable HiZ Setting 2 */
3267 cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00);
3268 priv->state = STATE_ACTIVE_TC;
3272 static int cxd2841er_get_frontend(struct dvb_frontend *fe,
3273 struct dtv_frontend_properties *p)
3275 enum fe_status status = 0;
3276 struct cxd2841er_priv *priv = fe->demodulator_priv;
3278 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3279 if (priv->state == STATE_ACTIVE_S)
3280 cxd2841er_read_status_s(fe, &status);
3281 else if (priv->state == STATE_ACTIVE_TC)
3282 cxd2841er_read_status_tc(fe, &status);
3284 if (priv->state == STATE_ACTIVE_TC || priv->state == STATE_ACTIVE_S)
3285 cxd2841er_read_signal_strength(fe);
3287 p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3289 if (status & FE_HAS_LOCK) {
3290 cxd2841er_read_snr(fe);
3291 cxd2841er_read_ucblocks(fe);
3293 cxd2841er_read_ber(fe);
3295 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3296 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3297 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3298 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3303 static int cxd2841er_set_frontend_s(struct dvb_frontend *fe)
3305 int ret = 0, i, timeout, carr_offset;
3306 enum fe_status status;
3307 struct cxd2841er_priv *priv = fe->demodulator_priv;
3308 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
3309 u32 symbol_rate = p->symbol_rate/1000;
3311 dev_dbg(&priv->i2c->dev, "%s(): %s frequency=%d symbol_rate=%d xtal=%d\n",
3313 (p->delivery_system == SYS_DVBS ? "DVB-S" : "DVB-S2"),
3314 p->frequency, symbol_rate, priv->xtal);
3316 if (priv->flags & CXD2841ER_EARLY_TUNE)
3317 cxd2841er_tuner_set(fe);
3319 switch (priv->state) {
3321 ret = cxd2841er_sleep_s_to_active_s(
3322 priv, p->delivery_system, symbol_rate);
3324 case STATE_ACTIVE_S:
3325 ret = cxd2841er_retune_active(priv, p);
3328 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
3329 __func__, priv->state);
3334 dev_dbg(&priv->i2c->dev, "%s(): tune failed\n", __func__);
3338 if (!(priv->flags & CXD2841ER_EARLY_TUNE))
3339 cxd2841er_tuner_set(fe);
3341 cxd2841er_tune_done(priv);
3342 timeout = ((3000000 + (symbol_rate - 1)) / symbol_rate) + 150;
3343 for (i = 0; i < timeout / CXD2841ER_DVBS_POLLING_INVL; i++) {
3344 usleep_range(CXD2841ER_DVBS_POLLING_INVL*1000,
3345 (CXD2841ER_DVBS_POLLING_INVL + 2) * 1000);
3346 cxd2841er_read_status_s(fe, &status);
3347 if (status & FE_HAS_LOCK)
3350 if (status & FE_HAS_LOCK) {
3351 if (cxd2841er_get_carrier_offset_s_s2(
3352 priv, &carr_offset)) {
3356 dev_dbg(&priv->i2c->dev, "%s(): carrier_offset=%d\n",
3357 __func__, carr_offset);
3361 p->strength.stat[0].scale = FE_SCALE_RELATIVE;
3362 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3363 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3364 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3365 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3370 static int cxd2841er_set_frontend_tc(struct dvb_frontend *fe)
3372 int ret = 0, timeout;
3373 enum fe_status status;
3374 struct cxd2841er_priv *priv = fe->demodulator_priv;
3375 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
3377 dev_dbg(&priv->i2c->dev, "%s() delivery_system=%d bandwidth_hz=%d\n",
3378 __func__, p->delivery_system, p->bandwidth_hz);
3380 if (priv->flags & CXD2841ER_EARLY_TUNE)
3381 cxd2841er_tuner_set(fe);
3383 /* deconfigure/put demod to sleep on delsys switch if active */
3384 if (priv->state == STATE_ACTIVE_TC &&
3385 priv->system != p->delivery_system) {
3386 dev_dbg(&priv->i2c->dev, "%s(): old_delsys=%d, new_delsys=%d -> sleep\n",
3387 __func__, priv->system, p->delivery_system);
3388 cxd2841er_sleep_tc(fe);
3391 if (p->delivery_system == SYS_DVBT) {
3392 priv->system = SYS_DVBT;
3393 switch (priv->state) {
3394 case STATE_SLEEP_TC:
3395 ret = cxd2841er_sleep_tc_to_active_t(
3396 priv, p->bandwidth_hz);
3398 case STATE_ACTIVE_TC:
3399 ret = cxd2841er_retune_active(priv, p);
3402 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
3403 __func__, priv->state);
3406 } else if (p->delivery_system == SYS_DVBT2) {
3407 priv->system = SYS_DVBT2;
3408 cxd2841er_dvbt2_set_plp_config(priv,
3409 (int)(p->stream_id > 255), p->stream_id);
3410 cxd2841er_dvbt2_set_profile(priv, DVBT2_PROFILE_BASE);
3411 switch (priv->state) {
3412 case STATE_SLEEP_TC:
3413 ret = cxd2841er_sleep_tc_to_active_t2(priv,
3416 case STATE_ACTIVE_TC:
3417 ret = cxd2841er_retune_active(priv, p);
3420 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
3421 __func__, priv->state);
3424 } else if (p->delivery_system == SYS_ISDBT) {
3425 priv->system = SYS_ISDBT;
3426 switch (priv->state) {
3427 case STATE_SLEEP_TC:
3428 ret = cxd2841er_sleep_tc_to_active_i(
3429 priv, p->bandwidth_hz);
3431 case STATE_ACTIVE_TC:
3432 ret = cxd2841er_retune_active(priv, p);
3435 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
3436 __func__, priv->state);
3439 } else if (p->delivery_system == SYS_DVBC_ANNEX_A ||
3440 p->delivery_system == SYS_DVBC_ANNEX_C) {
3441 priv->system = SYS_DVBC_ANNEX_A;
3442 /* correct bandwidth */
3443 if (p->bandwidth_hz != 6000000 &&
3444 p->bandwidth_hz != 7000000 &&
3445 p->bandwidth_hz != 8000000) {
3446 p->bandwidth_hz = 8000000;
3447 dev_dbg(&priv->i2c->dev, "%s(): forcing bandwidth to %d\n",
3448 __func__, p->bandwidth_hz);
3451 switch (priv->state) {
3452 case STATE_SLEEP_TC:
3453 ret = cxd2841er_sleep_tc_to_active_c(
3454 priv, p->bandwidth_hz);
3456 case STATE_ACTIVE_TC:
3457 ret = cxd2841er_retune_active(priv, p);
3460 dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n",
3461 __func__, priv->state);
3465 dev_dbg(&priv->i2c->dev,
3466 "%s(): invalid delivery system %d\n",
3467 __func__, p->delivery_system);
3473 if (!(priv->flags & CXD2841ER_EARLY_TUNE))
3474 cxd2841er_tuner_set(fe);
3476 cxd2841er_tune_done(priv);
3478 if (priv->flags & CXD2841ER_NO_WAIT_LOCK)
3482 while (timeout > 0) {
3483 ret = cxd2841er_read_status_tc(fe, &status);
3486 if (status & FE_HAS_LOCK)
3492 dev_dbg(&priv->i2c->dev,
3493 "%s(): LOCK wait timeout\n", __func__);
3498 static int cxd2841er_tune_s(struct dvb_frontend *fe,
3500 unsigned int mode_flags,
3501 unsigned int *delay,
3502 enum fe_status *status)
3504 int ret, carrier_offset;
3505 struct cxd2841er_priv *priv = fe->demodulator_priv;
3506 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
3508 dev_dbg(&priv->i2c->dev, "%s() re_tune=%d\n", __func__, re_tune);
3510 ret = cxd2841er_set_frontend_s(fe);
3513 cxd2841er_read_status_s(fe, status);
3514 if (*status & FE_HAS_LOCK) {
3515 if (cxd2841er_get_carrier_offset_s_s2(
3516 priv, &carrier_offset))
3518 p->frequency += carrier_offset;
3519 ret = cxd2841er_set_frontend_s(fe);
3525 return cxd2841er_read_status_s(fe, status);
3528 static int cxd2841er_tune_tc(struct dvb_frontend *fe,
3530 unsigned int mode_flags,
3531 unsigned int *delay,
3532 enum fe_status *status)
3534 int ret, carrier_offset;
3535 struct cxd2841er_priv *priv = fe->demodulator_priv;
3536 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
3538 dev_dbg(&priv->i2c->dev, "%s(): re_tune %d bandwidth=%d\n", __func__,
3539 re_tune, p->bandwidth_hz);
3541 ret = cxd2841er_set_frontend_tc(fe);
3544 cxd2841er_read_status_tc(fe, status);
3545 if (*status & FE_HAS_LOCK) {
3546 switch (priv->system) {
3548 ret = cxd2841er_get_carrier_offset_i(
3549 priv, p->bandwidth_hz,
3555 ret = cxd2841er_get_carrier_offset_t(
3556 priv, p->bandwidth_hz,
3562 ret = cxd2841er_get_carrier_offset_t2(
3563 priv, p->bandwidth_hz,
3568 case SYS_DVBC_ANNEX_A:
3569 ret = cxd2841er_get_carrier_offset_c(
3570 priv, &carrier_offset);
3575 dev_dbg(&priv->i2c->dev,
3576 "%s(): invalid delivery system %d\n",
3577 __func__, priv->system);
3580 dev_dbg(&priv->i2c->dev, "%s(): carrier offset %d\n",
3581 __func__, carrier_offset);
3582 p->frequency += carrier_offset;
3583 ret = cxd2841er_set_frontend_tc(fe);
3589 return cxd2841er_read_status_tc(fe, status);
3592 static int cxd2841er_sleep_s(struct dvb_frontend *fe)
3594 struct cxd2841er_priv *priv = fe->demodulator_priv;
3596 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3597 cxd2841er_active_s_to_sleep_s(fe->demodulator_priv);
3598 cxd2841er_sleep_s_to_shutdown(fe->demodulator_priv);
3602 static int cxd2841er_sleep_tc(struct dvb_frontend *fe)
3604 struct cxd2841er_priv *priv = fe->demodulator_priv;
3606 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3608 if (priv->state == STATE_ACTIVE_TC) {
3609 switch (priv->system) {
3611 cxd2841er_active_t_to_sleep_tc(priv);
3614 cxd2841er_active_t2_to_sleep_tc(priv);
3617 cxd2841er_active_i_to_sleep_tc(priv);
3619 case SYS_DVBC_ANNEX_A:
3620 cxd2841er_active_c_to_sleep_tc(priv);
3623 dev_warn(&priv->i2c->dev,
3624 "%s(): unknown delivery system %d\n",
3625 __func__, priv->system);
3628 if (priv->state != STATE_SLEEP_TC) {
3629 dev_err(&priv->i2c->dev, "%s(): invalid state %d\n",
3630 __func__, priv->state);
3636 static int cxd2841er_shutdown_tc(struct dvb_frontend *fe)
3638 struct cxd2841er_priv *priv = fe->demodulator_priv;
3640 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3642 if (!cxd2841er_sleep_tc(fe))
3643 cxd2841er_sleep_tc_to_shutdown(priv);
3647 static int cxd2841er_send_burst(struct dvb_frontend *fe,
3648 enum fe_sec_mini_cmd burst)
3651 struct cxd2841er_priv *priv = fe->demodulator_priv;
3653 dev_dbg(&priv->i2c->dev, "%s(): burst mode %s\n", __func__,
3654 (burst == SEC_MINI_A ? "A" : "B"));
3655 if (priv->state != STATE_SLEEP_S &&
3656 priv->state != STATE_ACTIVE_S) {
3657 dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
3658 __func__, priv->state);
3661 data = (burst == SEC_MINI_A ? 0 : 1);
3662 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
3663 cxd2841er_write_reg(priv, I2C_SLVT, 0x34, 0x01);
3664 cxd2841er_write_reg(priv, I2C_SLVT, 0x35, data);
3668 static int cxd2841er_set_tone(struct dvb_frontend *fe,
3669 enum fe_sec_tone_mode tone)
3672 struct cxd2841er_priv *priv = fe->demodulator_priv;
3674 dev_dbg(&priv->i2c->dev, "%s(): tone %s\n", __func__,
3675 (tone == SEC_TONE_ON ? "On" : "Off"));
3676 if (priv->state != STATE_SLEEP_S &&
3677 priv->state != STATE_ACTIVE_S) {
3678 dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
3679 __func__, priv->state);
3682 data = (tone == SEC_TONE_ON ? 1 : 0);
3683 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
3684 cxd2841er_write_reg(priv, I2C_SLVT, 0x36, data);
3688 static int cxd2841er_send_diseqc_msg(struct dvb_frontend *fe,
3689 struct dvb_diseqc_master_cmd *cmd)
3693 struct cxd2841er_priv *priv = fe->demodulator_priv;
3695 if (priv->state != STATE_SLEEP_S &&
3696 priv->state != STATE_ACTIVE_S) {
3697 dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n",
3698 __func__, priv->state);
3701 dev_dbg(&priv->i2c->dev,
3702 "%s(): cmd->len %d\n", __func__, cmd->msg_len);
3703 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb);
3705 cxd2841er_write_reg(priv, I2C_SLVT, 0x33, 0x01);
3706 /* cmd1 length & data */
3707 cxd2841er_write_reg(priv, I2C_SLVT, 0x3d, cmd->msg_len);
3708 memset(data, 0, sizeof(data));
3709 for (i = 0; i < cmd->msg_len && i < sizeof(data); i++)
3710 data[i] = cmd->msg[i];
3711 cxd2841er_write_regs(priv, I2C_SLVT, 0x3e, data, sizeof(data));
3712 /* repeat count for cmd1 */
3713 cxd2841er_write_reg(priv, I2C_SLVT, 0x37, 1);
3714 /* repeat count for cmd2: always 0 */
3715 cxd2841er_write_reg(priv, I2C_SLVT, 0x38, 0);
3716 /* start transmit */
3717 cxd2841er_write_reg(priv, I2C_SLVT, 0x32, 0x01);
3718 /* wait for 1 sec timeout */
3719 for (i = 0; i < 50; i++) {
3720 cxd2841er_read_reg(priv, I2C_SLVT, 0x10, data);
3722 dev_dbg(&priv->i2c->dev,
3723 "%s(): DiSEqC cmd has been sent\n", __func__);
3728 dev_dbg(&priv->i2c->dev,
3729 "%s(): DiSEqC cmd transmit timeout\n", __func__);
3733 static void cxd2841er_release(struct dvb_frontend *fe)
3735 struct cxd2841er_priv *priv = fe->demodulator_priv;
3737 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3741 static int cxd2841er_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
3743 struct cxd2841er_priv *priv = fe->demodulator_priv;
3745 dev_dbg(&priv->i2c->dev, "%s(): enable=%d\n", __func__, enable);
3746 cxd2841er_set_reg_bits(
3747 priv, I2C_SLVX, 0x8, (enable ? 0x01 : 0x00), 0x01);
3751 static enum dvbfe_algo cxd2841er_get_algo(struct dvb_frontend *fe)
3753 struct cxd2841er_priv *priv = fe->demodulator_priv;
3755 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3756 return DVBFE_ALGO_HW;
3759 static void cxd2841er_init_stats(struct dvb_frontend *fe)
3761 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
3763 p->strength.len = 1;
3764 p->strength.stat[0].scale = FE_SCALE_RELATIVE;
3766 p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3767 p->block_error.len = 1;
3768 p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3769 p->post_bit_error.len = 1;
3770 p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3771 p->post_bit_count.len = 1;
3772 p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
3776 static int cxd2841er_init_s(struct dvb_frontend *fe)
3778 struct cxd2841er_priv *priv = fe->demodulator_priv;
3780 /* sanity. force demod to SHUTDOWN state */
3781 if (priv->state == STATE_SLEEP_S) {
3782 dev_dbg(&priv->i2c->dev, "%s() forcing sleep->shutdown\n",
3784 cxd2841er_sleep_s_to_shutdown(priv);
3785 } else if (priv->state == STATE_ACTIVE_S) {
3786 dev_dbg(&priv->i2c->dev, "%s() forcing active->sleep->shutdown\n",
3788 cxd2841er_active_s_to_sleep_s(priv);
3789 cxd2841er_sleep_s_to_shutdown(priv);
3792 dev_dbg(&priv->i2c->dev, "%s()\n", __func__);
3793 cxd2841er_shutdown_to_sleep_s(priv);
3794 /* SONY_DEMOD_CONFIG_SAT_IFAGCNEG set to 1 */
3795 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0);
3796 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xb9, 0x01, 0x01);
3798 cxd2841er_init_stats(fe);
3803 static int cxd2841er_init_tc(struct dvb_frontend *fe)
3805 struct cxd2841er_priv *priv = fe->demodulator_priv;
3806 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
3808 dev_dbg(&priv->i2c->dev, "%s() bandwidth_hz=%d\n",
3809 __func__, p->bandwidth_hz);
3810 cxd2841er_shutdown_to_sleep_tc(priv);
3811 /* SONY_DEMOD_CONFIG_IFAGCNEG = 1 (0 for NO_AGCNEG */
3812 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10);
3813 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcb,
3814 ((priv->flags & CXD2841ER_NO_AGCNEG) ? 0x00 : 0x40), 0x40);
3815 /* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */
3816 cxd2841er_write_reg(priv, I2C_SLVT, 0xcd, 0x50);
3817 /* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */
3818 cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00);
3819 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4,
3820 ((priv->flags & CXD2841ER_TS_SERIAL) ? 0x80 : 0x00), 0x80);
3822 /* clear TSCFG bits 3+4 */
3823 if (priv->flags & CXD2841ER_TSBITS)
3824 cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4, 0x00, 0x18);
3826 cxd2841er_init_stats(fe);
3831 static const struct dvb_frontend_ops cxd2841er_dvbs_s2_ops;
3832 static struct dvb_frontend_ops cxd2841er_t_c_ops;
3834 static struct dvb_frontend *cxd2841er_attach(struct cxd2841er_config *cfg,
3835 struct i2c_adapter *i2c,
3841 struct cxd2841er_priv *priv = NULL;
3843 /* allocate memory for the internal state */
3844 priv = kzalloc(sizeof(struct cxd2841er_priv), GFP_KERNEL);
3849 priv->i2c_addr_slvx = (cfg->i2c_addr + 4) >> 1;
3850 priv->i2c_addr_slvt = (cfg->i2c_addr) >> 1;
3851 priv->xtal = cfg->xtal;
3852 priv->flags = cfg->flags;
3853 priv->frontend.demodulator_priv = priv;
3854 dev_info(&priv->i2c->dev,
3855 "%s(): I2C adapter %p SLVX addr %x SLVT addr %x\n",
3856 __func__, priv->i2c,
3857 priv->i2c_addr_slvx, priv->i2c_addr_slvt);
3858 chip_id = cxd2841er_chip_id(priv);
3860 case CXD2837ER_CHIP_ID:
3861 snprintf(cxd2841er_t_c_ops.info.name, 128,
3862 "Sony CXD2837ER DVB-T/T2/C demodulator");
3866 case CXD2838ER_CHIP_ID:
3867 snprintf(cxd2841er_t_c_ops.info.name, 128,
3868 "Sony CXD2838ER ISDB-T demodulator");
3869 cxd2841er_t_c_ops.delsys[0] = SYS_ISDBT;
3870 cxd2841er_t_c_ops.delsys[1] = SYS_UNDEFINED;
3871 cxd2841er_t_c_ops.delsys[2] = SYS_UNDEFINED;
3875 case CXD2841ER_CHIP_ID:
3876 snprintf(cxd2841er_t_c_ops.info.name, 128,
3877 "Sony CXD2841ER DVB-T/T2/C demodulator");
3879 type = "T/T2/C/ISDB-T";
3881 case CXD2843ER_CHIP_ID:
3882 snprintf(cxd2841er_t_c_ops.info.name, 128,
3883 "Sony CXD2843ER DVB-T/T2/C/C2 demodulator");
3887 case CXD2854ER_CHIP_ID:
3888 snprintf(cxd2841er_t_c_ops.info.name, 128,
3889 "Sony CXD2854ER DVB-T/T2/C and ISDB-T demodulator");
3890 cxd2841er_t_c_ops.delsys[3] = SYS_ISDBT;
3892 type = "C/C2/T/T2/ISDB-T";
3895 dev_err(&priv->i2c->dev, "%s(): invalid chip ID 0x%02x\n",
3897 priv->frontend.demodulator_priv = NULL;
3902 /* create dvb_frontend */
3903 if (system == SYS_DVBS) {
3904 memcpy(&priv->frontend.ops,
3905 &cxd2841er_dvbs_s2_ops,
3906 sizeof(struct dvb_frontend_ops));
3909 memcpy(&priv->frontend.ops,
3911 sizeof(struct dvb_frontend_ops));
3914 dev_info(&priv->i2c->dev,
3915 "%s(): attaching %s DVB-%s frontend\n",
3916 __func__, name, type);
3917 dev_info(&priv->i2c->dev, "%s(): chip ID 0x%02x OK.\n",
3919 return &priv->frontend;
3922 struct dvb_frontend *cxd2841er_attach_s(struct cxd2841er_config *cfg,
3923 struct i2c_adapter *i2c)
3925 return cxd2841er_attach(cfg, i2c, SYS_DVBS);
3927 EXPORT_SYMBOL(cxd2841er_attach_s);
3929 struct dvb_frontend *cxd2841er_attach_t_c(struct cxd2841er_config *cfg,
3930 struct i2c_adapter *i2c)
3932 return cxd2841er_attach(cfg, i2c, 0);
3934 EXPORT_SYMBOL(cxd2841er_attach_t_c);
3936 static const struct dvb_frontend_ops cxd2841er_dvbs_s2_ops = {
3937 .delsys = { SYS_DVBS, SYS_DVBS2 },
3939 .name = "Sony CXD2841ER DVB-S/S2 demodulator",
3940 .frequency_min = 500000,
3941 .frequency_max = 2500000,
3942 .frequency_stepsize = 0,
3943 .symbol_rate_min = 1000000,
3944 .symbol_rate_max = 45000000,
3945 .symbol_rate_tolerance = 500,
3946 .caps = FE_CAN_INVERSION_AUTO |
3950 .init = cxd2841er_init_s,
3951 .sleep = cxd2841er_sleep_s,
3952 .release = cxd2841er_release,
3953 .set_frontend = cxd2841er_set_frontend_s,
3954 .get_frontend = cxd2841er_get_frontend,
3955 .read_status = cxd2841er_read_status_s,
3956 .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
3957 .get_frontend_algo = cxd2841er_get_algo,
3958 .set_tone = cxd2841er_set_tone,
3959 .diseqc_send_burst = cxd2841er_send_burst,
3960 .diseqc_send_master_cmd = cxd2841er_send_diseqc_msg,
3961 .tune = cxd2841er_tune_s
3964 static struct dvb_frontend_ops cxd2841er_t_c_ops = {
3965 .delsys = { SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A },
3967 .name = "", /* will set in attach function */
3968 .caps = FE_CAN_FEC_1_2 |
3981 FE_CAN_TRANSMISSION_MODE_AUTO |
3982 FE_CAN_GUARD_INTERVAL_AUTO |
3983 FE_CAN_HIERARCHY_AUTO |
3985 FE_CAN_2G_MODULATION,
3986 .frequency_min = 42000000,
3987 .frequency_max = 1002000000,
3988 .symbol_rate_min = 870000,
3989 .symbol_rate_max = 11700000
3991 .init = cxd2841er_init_tc,
3992 .sleep = cxd2841er_shutdown_tc,
3993 .release = cxd2841er_release,
3994 .set_frontend = cxd2841er_set_frontend_tc,
3995 .get_frontend = cxd2841er_get_frontend,
3996 .read_status = cxd2841er_read_status_tc,
3997 .tune = cxd2841er_tune_tc,
3998 .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl,
3999 .get_frontend_algo = cxd2841er_get_algo
4002 MODULE_DESCRIPTION("Sony CXD2837/38/41/43/54ER DVB-C/C2/T/T2/S/S2 demodulator driver");
4003 MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>, Abylay Ospan <aospan@netup.ru>");
4004 MODULE_LICENSE("GPL");