Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1 | /* |
| 2 | * cxd2841er.c |
| 3 | * |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 4 | * Sony digital demodulator driver for |
Abylay Ospan | 9ca1736 | 2016-05-16 11:57:04 -0300 | [diff] [blame] | 5 | * CXD2841ER - DVB-S/S2/T/T2/C/C2 |
| 6 | * CXD2854ER - DVB-S/S2/T/T2/C/C2, ISDB-T/S |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 7 | * |
| 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> |
| 12 | * |
| 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. |
| 17 | * |
| 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. |
| 22 | */ |
| 23 | |
| 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> |
| 32 | |
| 33 | #include "dvb_math.h" |
| 34 | #include "dvb_frontend.h" |
| 35 | #include "cxd2841er.h" |
| 36 | #include "cxd2841er_priv.h" |
| 37 | |
Mauro Carvalho Chehab | d13a7b6 | 2015-08-11 15:22:36 -0300 | [diff] [blame] | 38 | #define MAX_WRITE_REGSIZE 16 |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 39 | #define LOG2_E_100X 144 |
| 40 | |
| 41 | /* DVB-C constellation */ |
| 42 | enum sony_dvbc_constellation_t { |
| 43 | SONY_DVBC_CONSTELLATION_16QAM, |
| 44 | SONY_DVBC_CONSTELLATION_32QAM, |
| 45 | SONY_DVBC_CONSTELLATION_64QAM, |
| 46 | SONY_DVBC_CONSTELLATION_128QAM, |
| 47 | SONY_DVBC_CONSTELLATION_256QAM |
| 48 | }; |
Mauro Carvalho Chehab | d13a7b6 | 2015-08-11 15:22:36 -0300 | [diff] [blame] | 49 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 50 | enum cxd2841er_state { |
| 51 | STATE_SHUTDOWN = 0, |
| 52 | STATE_SLEEP_S, |
| 53 | STATE_ACTIVE_S, |
| 54 | STATE_SLEEP_TC, |
| 55 | STATE_ACTIVE_TC |
| 56 | }; |
| 57 | |
| 58 | struct cxd2841er_priv { |
| 59 | struct dvb_frontend frontend; |
| 60 | struct i2c_adapter *i2c; |
| 61 | u8 i2c_addr_slvx; |
| 62 | u8 i2c_addr_slvt; |
| 63 | const struct cxd2841er_config *config; |
| 64 | enum cxd2841er_state state; |
| 65 | u8 system; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 66 | enum cxd2841er_xtal xtal; |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 67 | enum fe_caps caps; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | static const struct cxd2841er_cnr_data s_cn_data[] = { |
| 71 | { 0x033e, 0 }, { 0x0339, 100 }, { 0x0333, 200 }, |
| 72 | { 0x032e, 300 }, { 0x0329, 400 }, { 0x0324, 500 }, |
| 73 | { 0x031e, 600 }, { 0x0319, 700 }, { 0x0314, 800 }, |
| 74 | { 0x030f, 900 }, { 0x030a, 1000 }, { 0x02ff, 1100 }, |
| 75 | { 0x02f4, 1200 }, { 0x02e9, 1300 }, { 0x02de, 1400 }, |
| 76 | { 0x02d4, 1500 }, { 0x02c9, 1600 }, { 0x02bf, 1700 }, |
| 77 | { 0x02b5, 1800 }, { 0x02ab, 1900 }, { 0x02a1, 2000 }, |
| 78 | { 0x029b, 2100 }, { 0x0295, 2200 }, { 0x0290, 2300 }, |
| 79 | { 0x028a, 2400 }, { 0x0284, 2500 }, { 0x027f, 2600 }, |
| 80 | { 0x0279, 2700 }, { 0x0274, 2800 }, { 0x026e, 2900 }, |
| 81 | { 0x0269, 3000 }, { 0x0262, 3100 }, { 0x025c, 3200 }, |
| 82 | { 0x0255, 3300 }, { 0x024f, 3400 }, { 0x0249, 3500 }, |
| 83 | { 0x0242, 3600 }, { 0x023c, 3700 }, { 0x0236, 3800 }, |
| 84 | { 0x0230, 3900 }, { 0x022a, 4000 }, { 0x0223, 4100 }, |
| 85 | { 0x021c, 4200 }, { 0x0215, 4300 }, { 0x020e, 4400 }, |
| 86 | { 0x0207, 4500 }, { 0x0201, 4600 }, { 0x01fa, 4700 }, |
| 87 | { 0x01f4, 4800 }, { 0x01ed, 4900 }, { 0x01e7, 5000 }, |
| 88 | { 0x01e0, 5100 }, { 0x01d9, 5200 }, { 0x01d2, 5300 }, |
| 89 | { 0x01cb, 5400 }, { 0x01c4, 5500 }, { 0x01be, 5600 }, |
| 90 | { 0x01b7, 5700 }, { 0x01b1, 5800 }, { 0x01aa, 5900 }, |
| 91 | { 0x01a4, 6000 }, { 0x019d, 6100 }, { 0x0196, 6200 }, |
| 92 | { 0x018f, 6300 }, { 0x0189, 6400 }, { 0x0182, 6500 }, |
| 93 | { 0x017c, 6600 }, { 0x0175, 6700 }, { 0x016f, 6800 }, |
| 94 | { 0x0169, 6900 }, { 0x0163, 7000 }, { 0x015c, 7100 }, |
| 95 | { 0x0156, 7200 }, { 0x0150, 7300 }, { 0x014a, 7400 }, |
| 96 | { 0x0144, 7500 }, { 0x013e, 7600 }, { 0x0138, 7700 }, |
| 97 | { 0x0132, 7800 }, { 0x012d, 7900 }, { 0x0127, 8000 }, |
| 98 | { 0x0121, 8100 }, { 0x011c, 8200 }, { 0x0116, 8300 }, |
| 99 | { 0x0111, 8400 }, { 0x010b, 8500 }, { 0x0106, 8600 }, |
| 100 | { 0x0101, 8700 }, { 0x00fc, 8800 }, { 0x00f7, 8900 }, |
| 101 | { 0x00f2, 9000 }, { 0x00ee, 9100 }, { 0x00ea, 9200 }, |
| 102 | { 0x00e6, 9300 }, { 0x00e2, 9400 }, { 0x00de, 9500 }, |
| 103 | { 0x00da, 9600 }, { 0x00d7, 9700 }, { 0x00d3, 9800 }, |
| 104 | { 0x00d0, 9900 }, { 0x00cc, 10000 }, { 0x00c7, 10100 }, |
| 105 | { 0x00c3, 10200 }, { 0x00bf, 10300 }, { 0x00ba, 10400 }, |
| 106 | { 0x00b6, 10500 }, { 0x00b2, 10600 }, { 0x00ae, 10700 }, |
| 107 | { 0x00aa, 10800 }, { 0x00a7, 10900 }, { 0x00a3, 11000 }, |
| 108 | { 0x009f, 11100 }, { 0x009c, 11200 }, { 0x0098, 11300 }, |
| 109 | { 0x0094, 11400 }, { 0x0091, 11500 }, { 0x008e, 11600 }, |
| 110 | { 0x008a, 11700 }, { 0x0087, 11800 }, { 0x0084, 11900 }, |
| 111 | { 0x0081, 12000 }, { 0x007e, 12100 }, { 0x007b, 12200 }, |
| 112 | { 0x0079, 12300 }, { 0x0076, 12400 }, { 0x0073, 12500 }, |
| 113 | { 0x0071, 12600 }, { 0x006e, 12700 }, { 0x006c, 12800 }, |
| 114 | { 0x0069, 12900 }, { 0x0067, 13000 }, { 0x0065, 13100 }, |
| 115 | { 0x0062, 13200 }, { 0x0060, 13300 }, { 0x005e, 13400 }, |
| 116 | { 0x005c, 13500 }, { 0x005a, 13600 }, { 0x0058, 13700 }, |
| 117 | { 0x0056, 13800 }, { 0x0054, 13900 }, { 0x0052, 14000 }, |
| 118 | { 0x0050, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 }, |
| 119 | { 0x004b, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 }, |
| 120 | { 0x0046, 14700 }, { 0x0044, 14800 }, { 0x0043, 14900 }, |
| 121 | { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 }, |
| 122 | { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 }, |
| 123 | { 0x0037, 15700 }, { 0x0036, 15800 }, { 0x0034, 15900 }, |
| 124 | { 0x0033, 16000 }, { 0x0032, 16100 }, { 0x0031, 16200 }, |
| 125 | { 0x0030, 16300 }, { 0x002f, 16400 }, { 0x002e, 16500 }, |
| 126 | { 0x002d, 16600 }, { 0x002c, 16700 }, { 0x002b, 16800 }, |
| 127 | { 0x002a, 16900 }, { 0x0029, 17000 }, { 0x0028, 17100 }, |
| 128 | { 0x0027, 17200 }, { 0x0026, 17300 }, { 0x0025, 17400 }, |
| 129 | { 0x0024, 17500 }, { 0x0023, 17600 }, { 0x0022, 17800 }, |
| 130 | { 0x0021, 17900 }, { 0x0020, 18000 }, { 0x001f, 18200 }, |
| 131 | { 0x001e, 18300 }, { 0x001d, 18500 }, { 0x001c, 18700 }, |
| 132 | { 0x001b, 18900 }, { 0x001a, 19000 }, { 0x0019, 19200 }, |
| 133 | { 0x0018, 19300 }, { 0x0017, 19500 }, { 0x0016, 19700 }, |
| 134 | { 0x0015, 19900 }, { 0x0014, 20000 }, |
| 135 | }; |
| 136 | |
| 137 | static const struct cxd2841er_cnr_data s2_cn_data[] = { |
| 138 | { 0x05af, 0 }, { 0x0597, 100 }, { 0x057e, 200 }, |
| 139 | { 0x0567, 300 }, { 0x0550, 400 }, { 0x0539, 500 }, |
| 140 | { 0x0522, 600 }, { 0x050c, 700 }, { 0x04f6, 800 }, |
| 141 | { 0x04e1, 900 }, { 0x04cc, 1000 }, { 0x04b6, 1100 }, |
| 142 | { 0x04a1, 1200 }, { 0x048c, 1300 }, { 0x0477, 1400 }, |
| 143 | { 0x0463, 1500 }, { 0x044f, 1600 }, { 0x043c, 1700 }, |
| 144 | { 0x0428, 1800 }, { 0x0416, 1900 }, { 0x0403, 2000 }, |
| 145 | { 0x03ef, 2100 }, { 0x03dc, 2200 }, { 0x03c9, 2300 }, |
| 146 | { 0x03b6, 2400 }, { 0x03a4, 2500 }, { 0x0392, 2600 }, |
| 147 | { 0x0381, 2700 }, { 0x036f, 2800 }, { 0x035f, 2900 }, |
| 148 | { 0x034e, 3000 }, { 0x033d, 3100 }, { 0x032d, 3200 }, |
| 149 | { 0x031d, 3300 }, { 0x030d, 3400 }, { 0x02fd, 3500 }, |
| 150 | { 0x02ee, 3600 }, { 0x02df, 3700 }, { 0x02d0, 3800 }, |
| 151 | { 0x02c2, 3900 }, { 0x02b4, 4000 }, { 0x02a6, 4100 }, |
| 152 | { 0x0299, 4200 }, { 0x028c, 4300 }, { 0x027f, 4400 }, |
| 153 | { 0x0272, 4500 }, { 0x0265, 4600 }, { 0x0259, 4700 }, |
| 154 | { 0x024d, 4800 }, { 0x0241, 4900 }, { 0x0236, 5000 }, |
| 155 | { 0x022b, 5100 }, { 0x0220, 5200 }, { 0x0215, 5300 }, |
| 156 | { 0x020a, 5400 }, { 0x0200, 5500 }, { 0x01f6, 5600 }, |
| 157 | { 0x01ec, 5700 }, { 0x01e2, 5800 }, { 0x01d8, 5900 }, |
| 158 | { 0x01cf, 6000 }, { 0x01c6, 6100 }, { 0x01bc, 6200 }, |
| 159 | { 0x01b3, 6300 }, { 0x01aa, 6400 }, { 0x01a2, 6500 }, |
| 160 | { 0x0199, 6600 }, { 0x0191, 6700 }, { 0x0189, 6800 }, |
| 161 | { 0x0181, 6900 }, { 0x0179, 7000 }, { 0x0171, 7100 }, |
| 162 | { 0x0169, 7200 }, { 0x0161, 7300 }, { 0x015a, 7400 }, |
| 163 | { 0x0153, 7500 }, { 0x014b, 7600 }, { 0x0144, 7700 }, |
| 164 | { 0x013d, 7800 }, { 0x0137, 7900 }, { 0x0130, 8000 }, |
| 165 | { 0x012a, 8100 }, { 0x0124, 8200 }, { 0x011e, 8300 }, |
| 166 | { 0x0118, 8400 }, { 0x0112, 8500 }, { 0x010c, 8600 }, |
| 167 | { 0x0107, 8700 }, { 0x0101, 8800 }, { 0x00fc, 8900 }, |
| 168 | { 0x00f7, 9000 }, { 0x00f2, 9100 }, { 0x00ec, 9200 }, |
| 169 | { 0x00e7, 9300 }, { 0x00e2, 9400 }, { 0x00dd, 9500 }, |
| 170 | { 0x00d8, 9600 }, { 0x00d4, 9700 }, { 0x00cf, 9800 }, |
| 171 | { 0x00ca, 9900 }, { 0x00c6, 10000 }, { 0x00c2, 10100 }, |
| 172 | { 0x00be, 10200 }, { 0x00b9, 10300 }, { 0x00b5, 10400 }, |
| 173 | { 0x00b1, 10500 }, { 0x00ae, 10600 }, { 0x00aa, 10700 }, |
| 174 | { 0x00a6, 10800 }, { 0x00a3, 10900 }, { 0x009f, 11000 }, |
| 175 | { 0x009b, 11100 }, { 0x0098, 11200 }, { 0x0095, 11300 }, |
| 176 | { 0x0091, 11400 }, { 0x008e, 11500 }, { 0x008b, 11600 }, |
| 177 | { 0x0088, 11700 }, { 0x0085, 11800 }, { 0x0082, 11900 }, |
| 178 | { 0x007f, 12000 }, { 0x007c, 12100 }, { 0x007a, 12200 }, |
| 179 | { 0x0077, 12300 }, { 0x0074, 12400 }, { 0x0072, 12500 }, |
| 180 | { 0x006f, 12600 }, { 0x006d, 12700 }, { 0x006b, 12800 }, |
| 181 | { 0x0068, 12900 }, { 0x0066, 13000 }, { 0x0064, 13100 }, |
| 182 | { 0x0061, 13200 }, { 0x005f, 13300 }, { 0x005d, 13400 }, |
| 183 | { 0x005b, 13500 }, { 0x0059, 13600 }, { 0x0057, 13700 }, |
| 184 | { 0x0055, 13800 }, { 0x0053, 13900 }, { 0x0051, 14000 }, |
| 185 | { 0x004f, 14100 }, { 0x004e, 14200 }, { 0x004c, 14300 }, |
| 186 | { 0x004a, 14400 }, { 0x0049, 14500 }, { 0x0047, 14600 }, |
| 187 | { 0x0045, 14700 }, { 0x0044, 14800 }, { 0x0042, 14900 }, |
| 188 | { 0x0041, 15000 }, { 0x003f, 15100 }, { 0x003e, 15200 }, |
| 189 | { 0x003c, 15300 }, { 0x003b, 15400 }, { 0x003a, 15500 }, |
| 190 | { 0x0038, 15600 }, { 0x0037, 15700 }, { 0x0036, 15800 }, |
| 191 | { 0x0034, 15900 }, { 0x0033, 16000 }, { 0x0032, 16100 }, |
| 192 | { 0x0031, 16200 }, { 0x0030, 16300 }, { 0x002f, 16400 }, |
| 193 | { 0x002e, 16500 }, { 0x002d, 16600 }, { 0x002c, 16700 }, |
| 194 | { 0x002b, 16800 }, { 0x002a, 16900 }, { 0x0029, 17000 }, |
| 195 | { 0x0028, 17100 }, { 0x0027, 17200 }, { 0x0026, 17300 }, |
| 196 | { 0x0025, 17400 }, { 0x0024, 17500 }, { 0x0023, 17600 }, |
| 197 | { 0x0022, 17800 }, { 0x0021, 17900 }, { 0x0020, 18000 }, |
| 198 | { 0x001f, 18200 }, { 0x001e, 18300 }, { 0x001d, 18500 }, |
| 199 | { 0x001c, 18700 }, { 0x001b, 18900 }, { 0x001a, 19000 }, |
| 200 | { 0x0019, 19200 }, { 0x0018, 19300 }, { 0x0017, 19500 }, |
| 201 | { 0x0016, 19700 }, { 0x0015, 19900 }, { 0x0014, 20000 }, |
| 202 | }; |
| 203 | |
| 204 | #define MAKE_IFFREQ_CONFIG(iffreq) ((u32)(((iffreq)/41.0)*16777216.0 + 0.5)) |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 205 | #define MAKE_IFFREQ_CONFIG_XTAL(xtal, iffreq) ((xtal == SONY_XTAL_24000) ? \ |
| 206 | (u32)(((iffreq)/48.0)*16777216.0 + 0.5) : \ |
| 207 | (u32)(((iffreq)/41.0)*16777216.0 + 0.5)) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 208 | |
| 209 | static void cxd2841er_i2c_debug(struct cxd2841er_priv *priv, |
| 210 | u8 addr, u8 reg, u8 write, |
| 211 | const u8 *data, u32 len) |
| 212 | { |
| 213 | dev_dbg(&priv->i2c->dev, |
| 214 | "cxd2841er: I2C %s addr %02x reg 0x%02x size %d\n", |
| 215 | (write == 0 ? "read" : "write"), addr, reg, len); |
| 216 | print_hex_dump_bytes("cxd2841er: I2C data: ", |
| 217 | DUMP_PREFIX_OFFSET, data, len); |
| 218 | } |
| 219 | |
| 220 | static int cxd2841er_write_regs(struct cxd2841er_priv *priv, |
| 221 | u8 addr, u8 reg, const u8 *data, u32 len) |
| 222 | { |
| 223 | int ret; |
Mauro Carvalho Chehab | d13a7b6 | 2015-08-11 15:22:36 -0300 | [diff] [blame] | 224 | u8 buf[MAX_WRITE_REGSIZE + 1]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 225 | u8 i2c_addr = (addr == I2C_SLVX ? |
| 226 | priv->i2c_addr_slvx : priv->i2c_addr_slvt); |
| 227 | struct i2c_msg msg[1] = { |
| 228 | { |
| 229 | .addr = i2c_addr, |
| 230 | .flags = 0, |
Mauro Carvalho Chehab | d13a7b6 | 2015-08-11 15:22:36 -0300 | [diff] [blame] | 231 | .len = len + 1, |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 232 | .buf = buf, |
| 233 | } |
| 234 | }; |
| 235 | |
Mauro Carvalho Chehab | d13a7b6 | 2015-08-11 15:22:36 -0300 | [diff] [blame] | 236 | if (len + 1 >= sizeof(buf)) { |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 237 | dev_warn(&priv->i2c->dev, "wr reg=%04x: len=%d is too big!\n", |
Mauro Carvalho Chehab | d13a7b6 | 2015-08-11 15:22:36 -0300 | [diff] [blame] | 238 | reg, len + 1); |
| 239 | return -E2BIG; |
| 240 | } |
| 241 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 242 | cxd2841er_i2c_debug(priv, i2c_addr, reg, 1, data, len); |
| 243 | buf[0] = reg; |
| 244 | memcpy(&buf[1], data, len); |
| 245 | |
| 246 | ret = i2c_transfer(priv->i2c, msg, 1); |
| 247 | if (ret >= 0 && ret != 1) |
| 248 | ret = -EIO; |
| 249 | if (ret < 0) { |
| 250 | dev_warn(&priv->i2c->dev, |
| 251 | "%s: i2c wr failed=%d addr=%02x reg=%02x len=%d\n", |
| 252 | KBUILD_MODNAME, ret, i2c_addr, reg, len); |
| 253 | return ret; |
| 254 | } |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | static int cxd2841er_write_reg(struct cxd2841er_priv *priv, |
| 259 | u8 addr, u8 reg, u8 val) |
| 260 | { |
| 261 | return cxd2841er_write_regs(priv, addr, reg, &val, 1); |
| 262 | } |
| 263 | |
| 264 | static int cxd2841er_read_regs(struct cxd2841er_priv *priv, |
| 265 | u8 addr, u8 reg, u8 *val, u32 len) |
| 266 | { |
| 267 | int ret; |
| 268 | u8 i2c_addr = (addr == I2C_SLVX ? |
| 269 | priv->i2c_addr_slvx : priv->i2c_addr_slvt); |
| 270 | struct i2c_msg msg[2] = { |
| 271 | { |
| 272 | .addr = i2c_addr, |
| 273 | .flags = 0, |
| 274 | .len = 1, |
| 275 | .buf = ®, |
| 276 | }, { |
| 277 | .addr = i2c_addr, |
| 278 | .flags = I2C_M_RD, |
| 279 | .len = len, |
| 280 | .buf = val, |
| 281 | } |
| 282 | }; |
| 283 | |
| 284 | ret = i2c_transfer(priv->i2c, &msg[0], 1); |
| 285 | if (ret >= 0 && ret != 1) |
| 286 | ret = -EIO; |
| 287 | if (ret < 0) { |
| 288 | dev_warn(&priv->i2c->dev, |
| 289 | "%s: i2c rw failed=%d addr=%02x reg=%02x\n", |
| 290 | KBUILD_MODNAME, ret, i2c_addr, reg); |
| 291 | return ret; |
| 292 | } |
| 293 | ret = i2c_transfer(priv->i2c, &msg[1], 1); |
| 294 | if (ret >= 0 && ret != 1) |
| 295 | ret = -EIO; |
| 296 | if (ret < 0) { |
| 297 | dev_warn(&priv->i2c->dev, |
| 298 | "%s: i2c rd failed=%d addr=%02x reg=%02x\n", |
| 299 | KBUILD_MODNAME, ret, i2c_addr, reg); |
| 300 | return ret; |
| 301 | } |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 302 | cxd2841er_i2c_debug(priv, i2c_addr, reg, 0, val, len); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int cxd2841er_read_reg(struct cxd2841er_priv *priv, |
| 307 | u8 addr, u8 reg, u8 *val) |
| 308 | { |
| 309 | return cxd2841er_read_regs(priv, addr, reg, val, 1); |
| 310 | } |
| 311 | |
| 312 | static int cxd2841er_set_reg_bits(struct cxd2841er_priv *priv, |
| 313 | u8 addr, u8 reg, u8 data, u8 mask) |
| 314 | { |
| 315 | int res; |
| 316 | u8 rdata; |
| 317 | |
| 318 | if (mask != 0xff) { |
| 319 | res = cxd2841er_read_reg(priv, addr, reg, &rdata); |
| 320 | if (res) |
| 321 | return res; |
| 322 | data = ((data & mask) | (rdata & (mask ^ 0xFF))); |
| 323 | } |
| 324 | return cxd2841er_write_reg(priv, addr, reg, data); |
| 325 | } |
| 326 | |
| 327 | static int cxd2841er_dvbs2_set_symbol_rate(struct cxd2841er_priv *priv, |
| 328 | u32 symbol_rate) |
| 329 | { |
| 330 | u32 reg_value = 0; |
| 331 | u8 data[3] = {0, 0, 0}; |
| 332 | |
| 333 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 334 | /* |
| 335 | * regValue = (symbolRateKSps * 2^14 / 1000) + 0.5 |
| 336 | * = ((symbolRateKSps * 2^14) + 500) / 1000 |
| 337 | * = ((symbolRateKSps * 16384) + 500) / 1000 |
| 338 | */ |
| 339 | reg_value = DIV_ROUND_CLOSEST(symbol_rate * 16384, 1000); |
| 340 | if ((reg_value == 0) || (reg_value > 0xFFFFF)) { |
| 341 | dev_err(&priv->i2c->dev, |
| 342 | "%s(): reg_value is out of range\n", __func__); |
| 343 | return -EINVAL; |
| 344 | } |
| 345 | data[0] = (u8)((reg_value >> 16) & 0x0F); |
| 346 | data[1] = (u8)((reg_value >> 8) & 0xFF); |
| 347 | data[2] = (u8)(reg_value & 0xFF); |
| 348 | /* Set SLV-T Bank : 0xAE */ |
| 349 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae); |
| 350 | cxd2841er_write_regs(priv, I2C_SLVT, 0x20, data, 3); |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv, |
| 355 | u8 system); |
| 356 | |
| 357 | static int cxd2841er_sleep_s_to_active_s(struct cxd2841er_priv *priv, |
| 358 | u8 system, u32 symbol_rate) |
| 359 | { |
| 360 | int ret; |
| 361 | u8 data[4] = { 0, 0, 0, 0 }; |
| 362 | |
| 363 | if (priv->state != STATE_SLEEP_S) { |
| 364 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 365 | __func__, (int)priv->state); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 369 | cxd2841er_set_ts_clock_mode(priv, SYS_DVBS); |
| 370 | /* Set demod mode */ |
| 371 | if (system == SYS_DVBS) { |
| 372 | data[0] = 0x0A; |
| 373 | } else if (system == SYS_DVBS2) { |
| 374 | data[0] = 0x0B; |
| 375 | } else { |
| 376 | dev_err(&priv->i2c->dev, "%s(): invalid delsys %d\n", |
| 377 | __func__, system); |
| 378 | return -EINVAL; |
| 379 | } |
| 380 | /* Set SLV-X Bank : 0x00 */ |
| 381 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 382 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, data[0]); |
| 383 | /* DVB-S/S2 */ |
| 384 | data[0] = 0x00; |
| 385 | /* Set SLV-T Bank : 0x00 */ |
| 386 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 387 | /* Enable S/S2 auto detection 1 */ |
| 388 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, data[0]); |
| 389 | /* Set SLV-T Bank : 0xAE */ |
| 390 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae); |
| 391 | /* Enable S/S2 auto detection 2 */ |
| 392 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, data[0]); |
| 393 | /* Set SLV-T Bank : 0x00 */ |
| 394 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 395 | /* Enable demod clock */ |
| 396 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); |
| 397 | /* Enable ADC clock */ |
| 398 | cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x01); |
| 399 | /* Enable ADC 1 */ |
| 400 | cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); |
| 401 | /* Enable ADC 2 */ |
| 402 | cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x3f); |
| 403 | /* Set SLV-X Bank : 0x00 */ |
| 404 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 405 | /* Enable ADC 3 */ |
| 406 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); |
| 407 | /* Set SLV-T Bank : 0xA3 */ |
| 408 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa3); |
| 409 | cxd2841er_write_reg(priv, I2C_SLVT, 0xac, 0x00); |
| 410 | data[0] = 0x07; |
| 411 | data[1] = 0x3B; |
| 412 | data[2] = 0x08; |
| 413 | data[3] = 0xC5; |
| 414 | /* Set SLV-T Bank : 0xAB */ |
| 415 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xab); |
| 416 | cxd2841er_write_regs(priv, I2C_SLVT, 0x98, data, 4); |
| 417 | data[0] = 0x05; |
| 418 | data[1] = 0x80; |
| 419 | data[2] = 0x0A; |
| 420 | data[3] = 0x80; |
| 421 | cxd2841er_write_regs(priv, I2C_SLVT, 0xa8, data, 4); |
| 422 | data[0] = 0x0C; |
| 423 | data[1] = 0xCC; |
| 424 | cxd2841er_write_regs(priv, I2C_SLVT, 0xc3, data, 2); |
| 425 | /* Set demod parameter */ |
| 426 | ret = cxd2841er_dvbs2_set_symbol_rate(priv, symbol_rate); |
| 427 | if (ret != 0) |
| 428 | return ret; |
| 429 | /* Set SLV-T Bank : 0x00 */ |
| 430 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 431 | /* disable Hi-Z setting 1 */ |
| 432 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x10); |
| 433 | /* disable Hi-Z setting 2 */ |
| 434 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); |
| 435 | priv->state = STATE_ACTIVE_S; |
| 436 | return 0; |
| 437 | } |
| 438 | |
| 439 | static int cxd2841er_sleep_tc_to_active_t_band(struct cxd2841er_priv *priv, |
| 440 | u32 bandwidth); |
| 441 | |
| 442 | static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, |
| 443 | u32 bandwidth); |
| 444 | |
| 445 | static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv, |
| 446 | u32 bandwidth); |
| 447 | |
Mauro Carvalho Chehab | 76344a3f | 2016-05-04 18:25:38 -0300 | [diff] [blame] | 448 | static int cxd2841er_sleep_tc_to_active_i(struct cxd2841er_priv *priv, |
| 449 | u32 bandwidth); |
| 450 | |
| 451 | static int cxd2841er_active_i_to_sleep_tc(struct cxd2841er_priv *priv); |
| 452 | |
| 453 | static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv); |
| 454 | |
| 455 | static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv); |
| 456 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 457 | static int cxd2841er_retune_active(struct cxd2841er_priv *priv, |
| 458 | struct dtv_frontend_properties *p) |
| 459 | { |
| 460 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 461 | if (priv->state != STATE_ACTIVE_S && |
| 462 | priv->state != STATE_ACTIVE_TC) { |
| 463 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 464 | __func__, priv->state); |
| 465 | return -EINVAL; |
| 466 | } |
| 467 | /* Set SLV-T Bank : 0x00 */ |
| 468 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 469 | /* disable TS output */ |
| 470 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); |
| 471 | if (priv->state == STATE_ACTIVE_S) |
| 472 | return cxd2841er_dvbs2_set_symbol_rate( |
| 473 | priv, p->symbol_rate / 1000); |
| 474 | else if (priv->state == STATE_ACTIVE_TC) { |
| 475 | switch (priv->system) { |
| 476 | case SYS_DVBT: |
| 477 | return cxd2841er_sleep_tc_to_active_t_band( |
| 478 | priv, p->bandwidth_hz); |
| 479 | case SYS_DVBT2: |
| 480 | return cxd2841er_sleep_tc_to_active_t2_band( |
| 481 | priv, p->bandwidth_hz); |
| 482 | case SYS_DVBC_ANNEX_A: |
| 483 | return cxd2841er_sleep_tc_to_active_c_band( |
Mauro Carvalho Chehab | 76344a3f | 2016-05-04 18:25:38 -0300 | [diff] [blame] | 484 | priv, p->bandwidth_hz); |
| 485 | case SYS_ISDBT: |
| 486 | cxd2841er_active_i_to_sleep_tc(priv); |
| 487 | cxd2841er_sleep_tc_to_shutdown(priv); |
| 488 | cxd2841er_shutdown_to_sleep_tc(priv); |
| 489 | return cxd2841er_sleep_tc_to_active_i( |
| 490 | priv, p->bandwidth_hz); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", |
| 494 | __func__, priv->system); |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | |
| 498 | static int cxd2841er_active_s_to_sleep_s(struct cxd2841er_priv *priv) |
| 499 | { |
| 500 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 501 | if (priv->state != STATE_ACTIVE_S) { |
| 502 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 503 | __func__, priv->state); |
| 504 | return -EINVAL; |
| 505 | } |
| 506 | /* Set SLV-T Bank : 0x00 */ |
| 507 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 508 | /* disable TS output */ |
| 509 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); |
| 510 | /* enable Hi-Z setting 1 */ |
| 511 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1f); |
| 512 | /* enable Hi-Z setting 2 */ |
| 513 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); |
| 514 | /* Set SLV-X Bank : 0x00 */ |
| 515 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 516 | /* disable ADC 1 */ |
| 517 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); |
| 518 | /* Set SLV-T Bank : 0x00 */ |
| 519 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 520 | /* disable ADC clock */ |
| 521 | cxd2841er_write_reg(priv, I2C_SLVT, 0x31, 0x00); |
| 522 | /* disable ADC 2 */ |
| 523 | cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); |
| 524 | /* disable ADC 3 */ |
| 525 | cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27); |
| 526 | /* SADC Bias ON */ |
| 527 | cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06); |
| 528 | /* disable demod clock */ |
| 529 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); |
| 530 | /* Set SLV-T Bank : 0xAE */ |
| 531 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xae); |
| 532 | /* disable S/S2 auto detection1 */ |
| 533 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 534 | /* Set SLV-T Bank : 0x00 */ |
| 535 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 536 | /* disable S/S2 auto detection2 */ |
| 537 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2d, 0x00); |
| 538 | priv->state = STATE_SLEEP_S; |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static int cxd2841er_sleep_s_to_shutdown(struct cxd2841er_priv *priv) |
| 543 | { |
| 544 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 545 | if (priv->state != STATE_SLEEP_S) { |
| 546 | dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 547 | __func__, priv->state); |
| 548 | return -EINVAL; |
| 549 | } |
| 550 | /* Set SLV-T Bank : 0x00 */ |
| 551 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 552 | /* Disable DSQOUT */ |
| 553 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); |
| 554 | /* Disable DSQIN */ |
| 555 | cxd2841er_write_reg(priv, I2C_SLVT, 0x9c, 0x00); |
| 556 | /* Set SLV-X Bank : 0x00 */ |
| 557 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 558 | /* Disable oscillator */ |
| 559 | cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01); |
| 560 | /* Set demod mode */ |
| 561 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01); |
| 562 | priv->state = STATE_SHUTDOWN; |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int cxd2841er_sleep_tc_to_shutdown(struct cxd2841er_priv *priv) |
| 567 | { |
| 568 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 569 | if (priv->state != STATE_SLEEP_TC) { |
| 570 | dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 571 | __func__, priv->state); |
| 572 | return -EINVAL; |
| 573 | } |
| 574 | /* Set SLV-X Bank : 0x00 */ |
| 575 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 576 | /* Disable oscillator */ |
| 577 | cxd2841er_write_reg(priv, I2C_SLVX, 0x15, 0x01); |
| 578 | /* Set demod mode */ |
| 579 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01); |
| 580 | priv->state = STATE_SHUTDOWN; |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | static int cxd2841er_active_t_to_sleep_tc(struct cxd2841er_priv *priv) |
| 585 | { |
| 586 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 587 | if (priv->state != STATE_ACTIVE_TC) { |
| 588 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 589 | __func__, priv->state); |
| 590 | return -EINVAL; |
| 591 | } |
| 592 | /* Set SLV-T Bank : 0x00 */ |
| 593 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 594 | /* disable TS output */ |
| 595 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); |
| 596 | /* enable Hi-Z setting 1 */ |
| 597 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); |
| 598 | /* enable Hi-Z setting 2 */ |
| 599 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); |
| 600 | /* Set SLV-X Bank : 0x00 */ |
| 601 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 602 | /* disable ADC 1 */ |
| 603 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); |
| 604 | /* Set SLV-T Bank : 0x00 */ |
| 605 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 606 | /* Disable ADC 2 */ |
| 607 | cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); |
| 608 | /* Disable ADC 3 */ |
| 609 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); |
| 610 | /* Disable ADC clock */ |
| 611 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 612 | /* Disable RF level monitor */ |
| 613 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 614 | /* Disable demod clock */ |
| 615 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); |
| 616 | priv->state = STATE_SLEEP_TC; |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static int cxd2841er_active_t2_to_sleep_tc(struct cxd2841er_priv *priv) |
| 621 | { |
| 622 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 623 | if (priv->state != STATE_ACTIVE_TC) { |
| 624 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 625 | __func__, priv->state); |
| 626 | return -EINVAL; |
| 627 | } |
| 628 | /* Set SLV-T Bank : 0x00 */ |
| 629 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 630 | /* disable TS output */ |
| 631 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); |
| 632 | /* enable Hi-Z setting 1 */ |
| 633 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); |
| 634 | /* enable Hi-Z setting 2 */ |
| 635 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); |
| 636 | /* Cancel DVB-T2 setting */ |
| 637 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13); |
| 638 | cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x40); |
| 639 | cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x21); |
| 640 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f); |
| 641 | cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xfb); |
| 642 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a); |
| 643 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x00, 0x0f); |
| 644 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); |
| 645 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x00, 0x3f); |
| 646 | /* Set SLV-X Bank : 0x00 */ |
| 647 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 648 | /* disable ADC 1 */ |
| 649 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); |
| 650 | /* Set SLV-T Bank : 0x00 */ |
| 651 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 652 | /* Disable ADC 2 */ |
| 653 | cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); |
| 654 | /* Disable ADC 3 */ |
| 655 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); |
| 656 | /* Disable ADC clock */ |
| 657 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 658 | /* Disable RF level monitor */ |
| 659 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 660 | /* Disable demod clock */ |
| 661 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); |
| 662 | priv->state = STATE_SLEEP_TC; |
| 663 | return 0; |
| 664 | } |
| 665 | |
| 666 | static int cxd2841er_active_c_to_sleep_tc(struct cxd2841er_priv *priv) |
| 667 | { |
| 668 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 669 | if (priv->state != STATE_ACTIVE_TC) { |
| 670 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 671 | __func__, priv->state); |
| 672 | return -EINVAL; |
| 673 | } |
| 674 | /* Set SLV-T Bank : 0x00 */ |
| 675 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 676 | /* disable TS output */ |
| 677 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); |
| 678 | /* enable Hi-Z setting 1 */ |
| 679 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); |
| 680 | /* enable Hi-Z setting 2 */ |
| 681 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); |
| 682 | /* Cancel DVB-C setting */ |
| 683 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); |
| 684 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa3, 0x00, 0x1f); |
| 685 | /* Set SLV-X Bank : 0x00 */ |
| 686 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 687 | /* disable ADC 1 */ |
| 688 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); |
| 689 | /* Set SLV-T Bank : 0x00 */ |
| 690 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 691 | /* Disable ADC 2 */ |
| 692 | cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); |
| 693 | /* Disable ADC 3 */ |
| 694 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); |
| 695 | /* Disable ADC clock */ |
| 696 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 697 | /* Disable RF level monitor */ |
| 698 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 699 | /* Disable demod clock */ |
| 700 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); |
| 701 | priv->state = STATE_SLEEP_TC; |
| 702 | return 0; |
| 703 | } |
| 704 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 705 | static int cxd2841er_active_i_to_sleep_tc(struct cxd2841er_priv *priv) |
| 706 | { |
| 707 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 708 | if (priv->state != STATE_ACTIVE_TC) { |
| 709 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 710 | __func__, priv->state); |
| 711 | return -EINVAL; |
| 712 | } |
| 713 | /* Set SLV-T Bank : 0x00 */ |
| 714 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 715 | /* disable TS output */ |
| 716 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x01); |
| 717 | /* enable Hi-Z setting 1 */ |
| 718 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x3f); |
| 719 | /* enable Hi-Z setting 2 */ |
| 720 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0xff); |
| 721 | |
| 722 | /* TODO: Cancel demod parameter */ |
| 723 | |
| 724 | /* Set SLV-X Bank : 0x00 */ |
| 725 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 726 | /* disable ADC 1 */ |
| 727 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x01); |
| 728 | /* Set SLV-T Bank : 0x00 */ |
| 729 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 730 | /* Disable ADC 2 */ |
| 731 | cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); |
| 732 | /* Disable ADC 3 */ |
| 733 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); |
| 734 | /* Disable ADC clock */ |
| 735 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 736 | /* Disable RF level monitor */ |
| 737 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 738 | /* Disable demod clock */ |
| 739 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x00); |
| 740 | priv->state = STATE_SLEEP_TC; |
| 741 | return 0; |
| 742 | } |
| 743 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 744 | static int cxd2841er_shutdown_to_sleep_s(struct cxd2841er_priv *priv) |
| 745 | { |
| 746 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 747 | if (priv->state != STATE_SHUTDOWN) { |
| 748 | dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 749 | __func__, priv->state); |
| 750 | return -EINVAL; |
| 751 | } |
| 752 | /* Set SLV-X Bank : 0x00 */ |
| 753 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 754 | /* Clear all demodulator registers */ |
| 755 | cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00); |
| 756 | usleep_range(3000, 5000); |
| 757 | /* Set SLV-X Bank : 0x00 */ |
| 758 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 759 | /* Set demod SW reset */ |
| 760 | cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 761 | |
| 762 | switch (priv->xtal) { |
| 763 | case SONY_XTAL_20500: |
| 764 | cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x00); |
| 765 | break; |
| 766 | case SONY_XTAL_24000: |
| 767 | /* Select demod frequency */ |
| 768 | cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00); |
| 769 | cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x03); |
| 770 | break; |
| 771 | case SONY_XTAL_41000: |
| 772 | cxd2841er_write_reg(priv, I2C_SLVX, 0x14, 0x01); |
| 773 | break; |
| 774 | default: |
| 775 | dev_dbg(&priv->i2c->dev, "%s(): invalid demod xtal %d\n", |
| 776 | __func__, priv->xtal); |
| 777 | return -EINVAL; |
| 778 | } |
| 779 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 780 | /* Set demod mode */ |
| 781 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x0a); |
| 782 | /* Clear demod SW reset */ |
| 783 | cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00); |
| 784 | usleep_range(1000, 2000); |
| 785 | /* Set SLV-T Bank : 0x00 */ |
| 786 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 787 | /* enable DSQOUT */ |
| 788 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x1F); |
| 789 | /* enable DSQIN */ |
| 790 | cxd2841er_write_reg(priv, I2C_SLVT, 0x9C, 0x40); |
| 791 | /* TADC Bias On */ |
| 792 | cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); |
| 793 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); |
| 794 | /* SADC Bias On */ |
| 795 | cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); |
| 796 | cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27); |
| 797 | cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06); |
| 798 | priv->state = STATE_SLEEP_S; |
| 799 | return 0; |
| 800 | } |
| 801 | |
| 802 | static int cxd2841er_shutdown_to_sleep_tc(struct cxd2841er_priv *priv) |
| 803 | { |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 804 | u8 data = 0; |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 805 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 806 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 807 | if (priv->state != STATE_SHUTDOWN) { |
| 808 | dev_dbg(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 809 | __func__, priv->state); |
| 810 | return -EINVAL; |
| 811 | } |
| 812 | /* Set SLV-X Bank : 0x00 */ |
| 813 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 814 | /* Clear all demodulator registers */ |
| 815 | cxd2841er_write_reg(priv, I2C_SLVX, 0x02, 0x00); |
| 816 | usleep_range(3000, 5000); |
| 817 | /* Set SLV-X Bank : 0x00 */ |
| 818 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 819 | /* Set demod SW reset */ |
| 820 | cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x01); |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 821 | /* Select ADC clock mode */ |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 822 | cxd2841er_write_reg(priv, I2C_SLVX, 0x13, 0x00); |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 823 | |
| 824 | switch (priv->xtal) { |
| 825 | case SONY_XTAL_20500: |
| 826 | data = 0x0; |
| 827 | break; |
| 828 | case SONY_XTAL_24000: |
| 829 | /* Select demod frequency */ |
| 830 | cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00); |
| 831 | data = 0x3; |
| 832 | break; |
| 833 | case SONY_XTAL_41000: |
| 834 | cxd2841er_write_reg(priv, I2C_SLVX, 0x12, 0x00); |
| 835 | data = 0x1; |
| 836 | break; |
| 837 | } |
| 838 | cxd2841er_write_reg(priv, I2C_SLVX, 0x14, data); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 839 | /* Clear demod SW reset */ |
| 840 | cxd2841er_write_reg(priv, I2C_SLVX, 0x10, 0x00); |
| 841 | usleep_range(1000, 2000); |
| 842 | /* Set SLV-T Bank : 0x00 */ |
| 843 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 844 | /* TADC Bias On */ |
| 845 | cxd2841er_write_reg(priv, I2C_SLVT, 0x43, 0x0a); |
| 846 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x0a); |
| 847 | /* SADC Bias On */ |
| 848 | cxd2841er_write_reg(priv, I2C_SLVT, 0x63, 0x16); |
| 849 | cxd2841er_write_reg(priv, I2C_SLVT, 0x65, 0x27); |
| 850 | cxd2841er_write_reg(priv, I2C_SLVT, 0x69, 0x06); |
| 851 | priv->state = STATE_SLEEP_TC; |
| 852 | return 0; |
| 853 | } |
| 854 | |
| 855 | static int cxd2841er_tune_done(struct cxd2841er_priv *priv) |
| 856 | { |
| 857 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 858 | /* Set SLV-T Bank : 0x00 */ |
| 859 | cxd2841er_write_reg(priv, I2C_SLVT, 0, 0); |
| 860 | /* SW Reset */ |
| 861 | cxd2841er_write_reg(priv, I2C_SLVT, 0xfe, 0x01); |
| 862 | /* Enable TS output */ |
| 863 | cxd2841er_write_reg(priv, I2C_SLVT, 0xc3, 0x00); |
| 864 | return 0; |
| 865 | } |
| 866 | |
| 867 | /* Set TS parallel mode */ |
| 868 | static void cxd2841er_set_ts_clock_mode(struct cxd2841er_priv *priv, |
| 869 | u8 system) |
| 870 | { |
| 871 | u8 serial_ts, ts_rate_ctrl_off, ts_in_off; |
| 872 | |
| 873 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 874 | /* Set SLV-T Bank : 0x00 */ |
| 875 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 876 | cxd2841er_read_reg(priv, I2C_SLVT, 0xc4, &serial_ts); |
| 877 | cxd2841er_read_reg(priv, I2C_SLVT, 0xd3, &ts_rate_ctrl_off); |
| 878 | cxd2841er_read_reg(priv, I2C_SLVT, 0xde, &ts_in_off); |
| 879 | dev_dbg(&priv->i2c->dev, "%s(): ser_ts=0x%02x rate_ctrl_off=0x%02x in_off=0x%02x\n", |
| 880 | __func__, serial_ts, ts_rate_ctrl_off, ts_in_off); |
| 881 | |
| 882 | /* |
| 883 | * slave Bank Addr Bit default Name |
| 884 | * <SLV-T> 00h D9h [7:0] 8'h08 OTSCKPERIOD |
| 885 | */ |
| 886 | cxd2841er_write_reg(priv, I2C_SLVT, 0xd9, 0x08); |
| 887 | /* |
| 888 | * Disable TS IF Clock |
| 889 | * slave Bank Addr Bit default Name |
| 890 | * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN |
| 891 | */ |
| 892 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x00, 0x01); |
| 893 | /* |
| 894 | * slave Bank Addr Bit default Name |
| 895 | * <SLV-T> 00h 33h [1:0] 2'b01 OREG_CKSEL_TSIF |
| 896 | */ |
| 897 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x33, 0x00, 0x03); |
| 898 | /* |
| 899 | * Enable TS IF Clock |
| 900 | * slave Bank Addr Bit default Name |
| 901 | * <SLV-T> 00h 32h [0] 1'b1 OREG_CK_TSIF_EN |
| 902 | */ |
| 903 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x32, 0x01, 0x01); |
| 904 | |
| 905 | if (system == SYS_DVBT) { |
| 906 | /* Enable parity period for DVB-T */ |
| 907 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 908 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01); |
| 909 | } else if (system == SYS_DVBC_ANNEX_A) { |
| 910 | /* Enable parity period for DVB-C */ |
| 911 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 912 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x66, 0x01, 0x01); |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | static u8 cxd2841er_chip_id(struct cxd2841er_priv *priv) |
| 917 | { |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 918 | u8 chip_id = 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 919 | |
| 920 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 921 | if (cxd2841er_write_reg(priv, I2C_SLVT, 0, 0) == 0) |
| 922 | cxd2841er_read_reg(priv, I2C_SLVT, 0xfd, &chip_id); |
| 923 | else if (cxd2841er_write_reg(priv, I2C_SLVX, 0, 0) == 0) |
| 924 | cxd2841er_read_reg(priv, I2C_SLVX, 0xfd, &chip_id); |
| 925 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 926 | return chip_id; |
| 927 | } |
| 928 | |
| 929 | static int cxd2841er_read_status_s(struct dvb_frontend *fe, |
| 930 | enum fe_status *status) |
| 931 | { |
| 932 | u8 reg = 0; |
| 933 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 934 | |
| 935 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 936 | *status = 0; |
| 937 | if (priv->state != STATE_ACTIVE_S) { |
| 938 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 939 | __func__, priv->state); |
| 940 | return -EINVAL; |
| 941 | } |
| 942 | /* Set SLV-T Bank : 0xA0 */ |
| 943 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); |
| 944 | /* |
| 945 | * slave Bank Addr Bit Signal name |
| 946 | * <SLV-T> A0h 11h [2] ITSLOCK |
| 947 | */ |
| 948 | cxd2841er_read_reg(priv, I2C_SLVT, 0x11, ®); |
| 949 | if (reg & 0x04) { |
| 950 | *status = FE_HAS_SIGNAL |
| 951 | | FE_HAS_CARRIER |
| 952 | | FE_HAS_VITERBI |
| 953 | | FE_HAS_SYNC |
| 954 | | FE_HAS_LOCK; |
| 955 | } |
| 956 | dev_dbg(&priv->i2c->dev, "%s(): result 0x%x\n", __func__, *status); |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | static int cxd2841er_read_status_t_t2(struct cxd2841er_priv *priv, |
| 961 | u8 *sync, u8 *tslock, u8 *unlock) |
| 962 | { |
| 963 | u8 data = 0; |
| 964 | |
| 965 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 966 | if (priv->state != STATE_ACTIVE_TC) |
| 967 | return -EINVAL; |
| 968 | if (priv->system == SYS_DVBT) { |
| 969 | /* Set SLV-T Bank : 0x10 */ |
| 970 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 971 | } else { |
| 972 | /* Set SLV-T Bank : 0x20 */ |
| 973 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 974 | } |
| 975 | cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data); |
| 976 | if ((data & 0x07) == 0x07) { |
| 977 | dev_dbg(&priv->i2c->dev, |
| 978 | "%s(): invalid hardware state detected\n", __func__); |
| 979 | *sync = 0; |
| 980 | *tslock = 0; |
| 981 | *unlock = 0; |
| 982 | } else { |
| 983 | *sync = ((data & 0x07) == 0x6 ? 1 : 0); |
| 984 | *tslock = ((data & 0x20) ? 1 : 0); |
| 985 | *unlock = ((data & 0x10) ? 1 : 0); |
| 986 | } |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | static int cxd2841er_read_status_c(struct cxd2841er_priv *priv, u8 *tslock) |
| 991 | { |
| 992 | u8 data; |
| 993 | |
| 994 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 995 | if (priv->state != STATE_ACTIVE_TC) |
| 996 | return -EINVAL; |
| 997 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 998 | cxd2841er_read_reg(priv, I2C_SLVT, 0x88, &data); |
| 999 | if ((data & 0x01) == 0) { |
| 1000 | *tslock = 0; |
| 1001 | } else { |
| 1002 | cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data); |
| 1003 | *tslock = ((data & 0x20) ? 1 : 0); |
| 1004 | } |
| 1005 | return 0; |
| 1006 | } |
| 1007 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1008 | static int cxd2841er_read_status_i(struct cxd2841er_priv *priv, |
| 1009 | u8 *sync, u8 *tslock, u8 *unlock) |
| 1010 | { |
| 1011 | u8 data = 0; |
| 1012 | |
| 1013 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1014 | if (priv->state != STATE_ACTIVE_TC) |
| 1015 | return -EINVAL; |
| 1016 | /* Set SLV-T Bank : 0x60 */ |
| 1017 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60); |
| 1018 | cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data); |
| 1019 | dev_dbg(&priv->i2c->dev, |
| 1020 | "%s(): lock=0x%x\n", __func__, data); |
| 1021 | *sync = ((data & 0x02) ? 1 : 0); |
| 1022 | *tslock = ((data & 0x01) ? 1 : 0); |
| 1023 | *unlock = ((data & 0x10) ? 1 : 0); |
| 1024 | return 0; |
| 1025 | } |
| 1026 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1027 | static int cxd2841er_read_status_tc(struct dvb_frontend *fe, |
| 1028 | enum fe_status *status) |
| 1029 | { |
| 1030 | int ret = 0; |
| 1031 | u8 sync = 0; |
| 1032 | u8 tslock = 0; |
| 1033 | u8 unlock = 0; |
| 1034 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 1035 | |
| 1036 | *status = 0; |
| 1037 | if (priv->state == STATE_ACTIVE_TC) { |
| 1038 | if (priv->system == SYS_DVBT || priv->system == SYS_DVBT2) { |
| 1039 | ret = cxd2841er_read_status_t_t2( |
| 1040 | priv, &sync, &tslock, &unlock); |
| 1041 | if (ret) |
| 1042 | goto done; |
| 1043 | if (unlock) |
| 1044 | goto done; |
| 1045 | if (sync) |
| 1046 | *status = FE_HAS_SIGNAL | |
| 1047 | FE_HAS_CARRIER | |
| 1048 | FE_HAS_VITERBI | |
| 1049 | FE_HAS_SYNC; |
| 1050 | if (tslock) |
| 1051 | *status |= FE_HAS_LOCK; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1052 | } else if (priv->system == SYS_ISDBT) { |
| 1053 | ret = cxd2841er_read_status_i( |
| 1054 | priv, &sync, &tslock, &unlock); |
| 1055 | if (ret) |
| 1056 | goto done; |
| 1057 | if (unlock) |
| 1058 | goto done; |
| 1059 | if (sync) |
| 1060 | *status = FE_HAS_SIGNAL | |
| 1061 | FE_HAS_CARRIER | |
| 1062 | FE_HAS_VITERBI | |
| 1063 | FE_HAS_SYNC; |
| 1064 | if (tslock) |
| 1065 | *status |= FE_HAS_LOCK; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1066 | } else if (priv->system == SYS_DVBC_ANNEX_A) { |
| 1067 | ret = cxd2841er_read_status_c(priv, &tslock); |
| 1068 | if (ret) |
| 1069 | goto done; |
| 1070 | if (tslock) |
| 1071 | *status = FE_HAS_SIGNAL | |
| 1072 | FE_HAS_CARRIER | |
| 1073 | FE_HAS_VITERBI | |
| 1074 | FE_HAS_SYNC | |
| 1075 | FE_HAS_LOCK; |
| 1076 | } |
| 1077 | } |
| 1078 | done: |
| 1079 | dev_dbg(&priv->i2c->dev, "%s(): status 0x%x\n", __func__, *status); |
| 1080 | return ret; |
| 1081 | } |
| 1082 | |
| 1083 | static int cxd2841er_get_carrier_offset_s_s2(struct cxd2841er_priv *priv, |
| 1084 | int *offset) |
| 1085 | { |
| 1086 | u8 data[3]; |
| 1087 | u8 is_hs_mode; |
| 1088 | s32 cfrl_ctrlval; |
| 1089 | s32 temp_div, temp_q, temp_r; |
| 1090 | |
| 1091 | if (priv->state != STATE_ACTIVE_S) { |
| 1092 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1093 | __func__, priv->state); |
| 1094 | return -EINVAL; |
| 1095 | } |
| 1096 | /* |
| 1097 | * Get High Sampling Rate mode |
| 1098 | * slave Bank Addr Bit Signal name |
| 1099 | * <SLV-T> A0h 10h [0] ITRL_LOCK |
| 1100 | */ |
| 1101 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); |
| 1102 | cxd2841er_read_reg(priv, I2C_SLVT, 0x10, &data[0]); |
| 1103 | if (data[0] & 0x01) { |
| 1104 | /* |
| 1105 | * slave Bank Addr Bit Signal name |
| 1106 | * <SLV-T> A0h 50h [4] IHSMODE |
| 1107 | */ |
| 1108 | cxd2841er_read_reg(priv, I2C_SLVT, 0x50, &data[0]); |
| 1109 | is_hs_mode = (data[0] & 0x10 ? 1 : 0); |
| 1110 | } else { |
| 1111 | dev_dbg(&priv->i2c->dev, |
| 1112 | "%s(): unable to detect sampling rate mode\n", |
| 1113 | __func__); |
| 1114 | return -EINVAL; |
| 1115 | } |
| 1116 | /* |
| 1117 | * slave Bank Addr Bit Signal name |
| 1118 | * <SLV-T> A0h 45h [4:0] ICFRL_CTRLVAL[20:16] |
| 1119 | * <SLV-T> A0h 46h [7:0] ICFRL_CTRLVAL[15:8] |
| 1120 | * <SLV-T> A0h 47h [7:0] ICFRL_CTRLVAL[7:0] |
| 1121 | */ |
| 1122 | cxd2841er_read_regs(priv, I2C_SLVT, 0x45, data, 3); |
| 1123 | cfrl_ctrlval = sign_extend32((((u32)data[0] & 0x1F) << 16) | |
| 1124 | (((u32)data[1] & 0xFF) << 8) | |
| 1125 | ((u32)data[2] & 0xFF), 20); |
| 1126 | temp_div = (is_hs_mode ? 1048576 : 1572864); |
| 1127 | if (cfrl_ctrlval > 0) { |
| 1128 | temp_q = div_s64_rem(97375LL * cfrl_ctrlval, |
| 1129 | temp_div, &temp_r); |
| 1130 | } else { |
| 1131 | temp_q = div_s64_rem(-97375LL * cfrl_ctrlval, |
| 1132 | temp_div, &temp_r); |
| 1133 | } |
| 1134 | if (temp_r >= temp_div / 2) |
| 1135 | temp_q++; |
| 1136 | if (cfrl_ctrlval > 0) |
| 1137 | temp_q *= -1; |
| 1138 | *offset = temp_q; |
| 1139 | return 0; |
| 1140 | } |
| 1141 | |
Mauro Carvalho Chehab | 76344a3f | 2016-05-04 18:25:38 -0300 | [diff] [blame] | 1142 | static int cxd2841er_get_carrier_offset_i(struct cxd2841er_priv *priv, |
| 1143 | u32 bandwidth, int *offset) |
| 1144 | { |
| 1145 | u8 data[4]; |
| 1146 | |
| 1147 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1148 | if (priv->state != STATE_ACTIVE_TC) { |
| 1149 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1150 | __func__, priv->state); |
| 1151 | return -EINVAL; |
| 1152 | } |
| 1153 | if (priv->system != SYS_ISDBT) { |
| 1154 | dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", |
| 1155 | __func__, priv->system); |
| 1156 | return -EINVAL; |
| 1157 | } |
| 1158 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60); |
| 1159 | cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data)); |
| 1160 | *offset = -1 * sign_extend32( |
| 1161 | ((u32)(data[0] & 0x1F) << 24) | ((u32)data[1] << 16) | |
| 1162 | ((u32)data[2] << 8) | (u32)data[3], 29); |
| 1163 | |
| 1164 | switch (bandwidth) { |
| 1165 | case 6000000: |
| 1166 | *offset = -1 * ((*offset) * 8/264); |
| 1167 | break; |
| 1168 | case 7000000: |
| 1169 | *offset = -1 * ((*offset) * 8/231); |
| 1170 | break; |
| 1171 | case 8000000: |
| 1172 | *offset = -1 * ((*offset) * 8/198); |
| 1173 | break; |
| 1174 | default: |
| 1175 | dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n", |
| 1176 | __func__, bandwidth); |
| 1177 | return -EINVAL; |
| 1178 | } |
| 1179 | |
| 1180 | dev_dbg(&priv->i2c->dev, "%s(): bandwidth %d offset %d\n", |
| 1181 | __func__, bandwidth, *offset); |
| 1182 | |
| 1183 | return 0; |
| 1184 | } |
| 1185 | |
Abylay Ospan | c5ea46d | 2016-04-02 23:31:50 -0300 | [diff] [blame] | 1186 | static int cxd2841er_get_carrier_offset_t(struct cxd2841er_priv *priv, |
| 1187 | u32 bandwidth, int *offset) |
| 1188 | { |
| 1189 | u8 data[4]; |
| 1190 | |
| 1191 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1192 | if (priv->state != STATE_ACTIVE_TC) { |
| 1193 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1194 | __func__, priv->state); |
| 1195 | return -EINVAL; |
| 1196 | } |
| 1197 | if (priv->system != SYS_DVBT) { |
| 1198 | dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", |
| 1199 | __func__, priv->system); |
| 1200 | return -EINVAL; |
| 1201 | } |
| 1202 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 1203 | cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data)); |
| 1204 | *offset = -1 * sign_extend32( |
| 1205 | ((u32)(data[0] & 0x1F) << 24) | ((u32)data[1] << 16) | |
| 1206 | ((u32)data[2] << 8) | (u32)data[3], 29); |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 1207 | *offset *= (bandwidth / 1000000); |
| 1208 | *offset /= 235; |
Abylay Ospan | c5ea46d | 2016-04-02 23:31:50 -0300 | [diff] [blame] | 1209 | return 0; |
| 1210 | } |
| 1211 | |
Mauro Carvalho Chehab | c8946c8 | 2015-08-11 15:08:47 -0300 | [diff] [blame] | 1212 | static int cxd2841er_get_carrier_offset_t2(struct cxd2841er_priv *priv, |
| 1213 | u32 bandwidth, int *offset) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1214 | { |
| 1215 | u8 data[4]; |
| 1216 | |
| 1217 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1218 | if (priv->state != STATE_ACTIVE_TC) { |
| 1219 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1220 | __func__, priv->state); |
| 1221 | return -EINVAL; |
| 1222 | } |
| 1223 | if (priv->system != SYS_DVBT2) { |
| 1224 | dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", |
| 1225 | __func__, priv->system); |
| 1226 | return -EINVAL; |
| 1227 | } |
| 1228 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 1229 | cxd2841er_read_regs(priv, I2C_SLVT, 0x4c, data, sizeof(data)); |
| 1230 | *offset = -1 * sign_extend32( |
| 1231 | ((u32)(data[0] & 0x0F) << 24) | ((u32)data[1] << 16) | |
| 1232 | ((u32)data[2] << 8) | (u32)data[3], 27); |
| 1233 | switch (bandwidth) { |
| 1234 | case 1712000: |
| 1235 | *offset /= 582; |
| 1236 | break; |
| 1237 | case 5000000: |
| 1238 | case 6000000: |
| 1239 | case 7000000: |
| 1240 | case 8000000: |
| 1241 | *offset *= (bandwidth / 1000000); |
| 1242 | *offset /= 940; |
| 1243 | break; |
| 1244 | default: |
| 1245 | dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n", |
| 1246 | __func__, bandwidth); |
| 1247 | return -EINVAL; |
| 1248 | } |
| 1249 | return 0; |
| 1250 | } |
| 1251 | |
Mauro Carvalho Chehab | c8946c8 | 2015-08-11 15:08:47 -0300 | [diff] [blame] | 1252 | static int cxd2841er_get_carrier_offset_c(struct cxd2841er_priv *priv, |
| 1253 | int *offset) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1254 | { |
| 1255 | u8 data[2]; |
| 1256 | |
| 1257 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1258 | if (priv->state != STATE_ACTIVE_TC) { |
| 1259 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1260 | __func__, priv->state); |
| 1261 | return -EINVAL; |
| 1262 | } |
| 1263 | if (priv->system != SYS_DVBC_ANNEX_A) { |
| 1264 | dev_dbg(&priv->i2c->dev, "%s(): invalid delivery system %d\n", |
| 1265 | __func__, priv->system); |
| 1266 | return -EINVAL; |
| 1267 | } |
| 1268 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 1269 | cxd2841er_read_regs(priv, I2C_SLVT, 0x15, data, sizeof(data)); |
| 1270 | *offset = div_s64(41000LL * sign_extend32((((u32)data[0] & 0x3f) << 8) |
| 1271 | | (u32)data[1], 13), 16384); |
| 1272 | return 0; |
| 1273 | } |
| 1274 | |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 1275 | static int cxd2841er_read_packet_errors_c( |
| 1276 | struct cxd2841er_priv *priv, u32 *penum) |
| 1277 | { |
| 1278 | u8 data[3]; |
| 1279 | |
| 1280 | *penum = 0; |
| 1281 | if (priv->state != STATE_ACTIVE_TC) { |
| 1282 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1283 | __func__, priv->state); |
| 1284 | return -EINVAL; |
| 1285 | } |
| 1286 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 1287 | cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data)); |
| 1288 | if (data[2] & 0x01) |
| 1289 | *penum = ((u32)data[0] << 8) | (u32)data[1]; |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1293 | static int cxd2841er_read_packet_errors_t( |
| 1294 | struct cxd2841er_priv *priv, u32 *penum) |
| 1295 | { |
| 1296 | u8 data[3]; |
| 1297 | |
| 1298 | *penum = 0; |
| 1299 | if (priv->state != STATE_ACTIVE_TC) { |
| 1300 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1301 | __func__, priv->state); |
| 1302 | return -EINVAL; |
| 1303 | } |
| 1304 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 1305 | cxd2841er_read_regs(priv, I2C_SLVT, 0xea, data, sizeof(data)); |
| 1306 | if (data[2] & 0x01) |
| 1307 | *penum = ((u32)data[0] << 8) | (u32)data[1]; |
| 1308 | return 0; |
| 1309 | } |
| 1310 | |
| 1311 | static int cxd2841er_read_packet_errors_t2( |
| 1312 | struct cxd2841er_priv *priv, u32 *penum) |
| 1313 | { |
| 1314 | u8 data[3]; |
| 1315 | |
| 1316 | *penum = 0; |
| 1317 | if (priv->state != STATE_ACTIVE_TC) { |
| 1318 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1319 | __func__, priv->state); |
| 1320 | return -EINVAL; |
| 1321 | } |
| 1322 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24); |
| 1323 | cxd2841er_read_regs(priv, I2C_SLVT, 0xfd, data, sizeof(data)); |
| 1324 | if (data[0] & 0x01) |
| 1325 | *penum = ((u32)data[1] << 8) | (u32)data[2]; |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1329 | static int cxd2841er_read_packet_errors_i( |
| 1330 | struct cxd2841er_priv *priv, u32 *penum) |
| 1331 | { |
| 1332 | u8 data[2]; |
| 1333 | |
| 1334 | *penum = 0; |
| 1335 | if (priv->state != STATE_ACTIVE_TC) { |
| 1336 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1337 | __func__, priv->state); |
| 1338 | return -EINVAL; |
| 1339 | } |
| 1340 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60); |
| 1341 | cxd2841er_read_regs(priv, I2C_SLVT, 0xA1, data, 1); |
| 1342 | |
| 1343 | if (!(data[0] & 0x01)) |
| 1344 | return 0; |
| 1345 | |
| 1346 | /* Layer A */ |
| 1347 | cxd2841er_read_regs(priv, I2C_SLVT, 0xA2, data, sizeof(data)); |
| 1348 | *penum = ((u32)data[0] << 8) | (u32)data[1]; |
| 1349 | |
| 1350 | /* Layer B */ |
| 1351 | cxd2841er_read_regs(priv, I2C_SLVT, 0xA4, data, sizeof(data)); |
| 1352 | *penum += ((u32)data[0] << 8) | (u32)data[1]; |
| 1353 | |
| 1354 | /* Layer C */ |
| 1355 | cxd2841er_read_regs(priv, I2C_SLVT, 0xA6, data, sizeof(data)); |
| 1356 | *penum += ((u32)data[0] << 8) | (u32)data[1]; |
| 1357 | |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 1361 | static int cxd2841er_read_ber_c(struct cxd2841er_priv *priv, |
| 1362 | u32 *bit_error, u32 *bit_count) |
| 1363 | { |
| 1364 | u8 data[3]; |
| 1365 | u32 bit_err, period_exp; |
| 1366 | |
| 1367 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1368 | if (priv->state != STATE_ACTIVE_TC) { |
| 1369 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 1370 | __func__, priv->state); |
| 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 1374 | cxd2841er_read_regs(priv, I2C_SLVT, 0x62, data, sizeof(data)); |
| 1375 | if (!(data[0] & 0x80)) { |
| 1376 | dev_dbg(&priv->i2c->dev, |
| 1377 | "%s(): no valid BER data\n", __func__); |
| 1378 | return -EINVAL; |
| 1379 | } |
| 1380 | bit_err = ((u32)(data[0] & 0x3f) << 16) | |
| 1381 | ((u32)data[1] << 8) | |
| 1382 | (u32)data[2]; |
| 1383 | cxd2841er_read_reg(priv, I2C_SLVT, 0x60, data); |
| 1384 | period_exp = data[0] & 0x1f; |
| 1385 | |
| 1386 | if ((period_exp <= 11) && (bit_err > (1 << period_exp) * 204 * 8)) { |
| 1387 | dev_dbg(&priv->i2c->dev, |
| 1388 | "%s(): period_exp(%u) or bit_err(%u) not in range. no valid BER data\n", |
| 1389 | __func__, period_exp, bit_err); |
| 1390 | return -EINVAL; |
| 1391 | } |
| 1392 | |
| 1393 | dev_dbg(&priv->i2c->dev, |
| 1394 | "%s(): period_exp(%u) or bit_err(%u) count=%d\n", |
| 1395 | __func__, period_exp, bit_err, |
| 1396 | ((1 << period_exp) * 204 * 8)); |
| 1397 | |
| 1398 | *bit_error = bit_err; |
| 1399 | *bit_count = ((1 << period_exp) * 204 * 8); |
| 1400 | |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1404 | static int cxd2841er_mon_read_ber_s(struct cxd2841er_priv *priv, |
| 1405 | u32 *bit_error, u32 *bit_count) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1406 | { |
| 1407 | u8 data[11]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1408 | |
| 1409 | /* Set SLV-T Bank : 0xA0 */ |
| 1410 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); |
| 1411 | /* |
| 1412 | * slave Bank Addr Bit Signal name |
| 1413 | * <SLV-T> A0h 35h [0] IFVBER_VALID |
| 1414 | * <SLV-T> A0h 36h [5:0] IFVBER_BITERR[21:16] |
| 1415 | * <SLV-T> A0h 37h [7:0] IFVBER_BITERR[15:8] |
| 1416 | * <SLV-T> A0h 38h [7:0] IFVBER_BITERR[7:0] |
| 1417 | * <SLV-T> A0h 3Dh [5:0] IFVBER_BITNUM[21:16] |
| 1418 | * <SLV-T> A0h 3Eh [7:0] IFVBER_BITNUM[15:8] |
| 1419 | * <SLV-T> A0h 3Fh [7:0] IFVBER_BITNUM[7:0] |
| 1420 | */ |
| 1421 | cxd2841er_read_regs(priv, I2C_SLVT, 0x35, data, 11); |
| 1422 | if (data[0] & 0x01) { |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1423 | *bit_error = ((u32)(data[1] & 0x3F) << 16) | |
| 1424 | ((u32)(data[2] & 0xFF) << 8) | |
| 1425 | (u32)(data[3] & 0xFF); |
| 1426 | *bit_count = ((u32)(data[8] & 0x3F) << 16) | |
| 1427 | ((u32)(data[9] & 0xFF) << 8) | |
| 1428 | (u32)(data[10] & 0xFF); |
| 1429 | if ((*bit_count == 0) || (*bit_error > *bit_count)) { |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1430 | dev_dbg(&priv->i2c->dev, |
| 1431 | "%s(): invalid bit_error %d, bit_count %d\n", |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1432 | __func__, *bit_error, *bit_count); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1433 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1434 | } |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1435 | return 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1436 | } |
| 1437 | dev_dbg(&priv->i2c->dev, "%s(): no data available\n", __func__); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1438 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1442 | static int cxd2841er_mon_read_ber_s2(struct cxd2841er_priv *priv, |
| 1443 | u32 *bit_error, u32 *bit_count) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1444 | { |
| 1445 | u8 data[5]; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1446 | u32 period; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1447 | |
| 1448 | /* Set SLV-T Bank : 0xB2 */ |
| 1449 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xb2); |
| 1450 | /* |
| 1451 | * slave Bank Addr Bit Signal name |
| 1452 | * <SLV-T> B2h 30h [0] IFLBER_VALID |
| 1453 | * <SLV-T> B2h 31h [3:0] IFLBER_BITERR[27:24] |
| 1454 | * <SLV-T> B2h 32h [7:0] IFLBER_BITERR[23:16] |
| 1455 | * <SLV-T> B2h 33h [7:0] IFLBER_BITERR[15:8] |
| 1456 | * <SLV-T> B2h 34h [7:0] IFLBER_BITERR[7:0] |
| 1457 | */ |
| 1458 | cxd2841er_read_regs(priv, I2C_SLVT, 0x30, data, 5); |
| 1459 | if (data[0] & 0x01) { |
| 1460 | /* Bit error count */ |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1461 | *bit_error = ((u32)(data[1] & 0x0F) << 24) | |
| 1462 | ((u32)(data[2] & 0xFF) << 16) | |
| 1463 | ((u32)(data[3] & 0xFF) << 8) | |
| 1464 | (u32)(data[4] & 0xFF); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1465 | |
| 1466 | /* Set SLV-T Bank : 0xA0 */ |
| 1467 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); |
| 1468 | cxd2841er_read_reg(priv, I2C_SLVT, 0x7a, data); |
| 1469 | /* Measurement period */ |
| 1470 | period = (u32)(1 << (data[0] & 0x0F)); |
| 1471 | if (period == 0) { |
| 1472 | dev_dbg(&priv->i2c->dev, |
| 1473 | "%s(): period is 0\n", __func__); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1474 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1475 | } |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1476 | if (*bit_error > (period * 64800)) { |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1477 | dev_dbg(&priv->i2c->dev, |
| 1478 | "%s(): invalid bit_err 0x%x period 0x%x\n", |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1479 | __func__, *bit_error, period); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1480 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1481 | } |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1482 | *bit_count = period * 64800; |
| 1483 | |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1484 | return 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1485 | } else { |
| 1486 | dev_dbg(&priv->i2c->dev, |
| 1487 | "%s(): no data available\n", __func__); |
| 1488 | } |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1489 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1490 | } |
| 1491 | |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1492 | static int cxd2841er_read_ber_t2(struct cxd2841er_priv *priv, |
| 1493 | u32 *bit_error, u32 *bit_count) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1494 | { |
| 1495 | u8 data[4]; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1496 | u32 period_exp, n_ldpc; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1497 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1498 | if (priv->state != STATE_ACTIVE_TC) { |
| 1499 | dev_dbg(&priv->i2c->dev, |
| 1500 | "%s(): invalid state %d\n", __func__, priv->state); |
| 1501 | return -EINVAL; |
| 1502 | } |
| 1503 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 1504 | cxd2841er_read_regs(priv, I2C_SLVT, 0x39, data, sizeof(data)); |
| 1505 | if (!(data[0] & 0x10)) { |
| 1506 | dev_dbg(&priv->i2c->dev, |
| 1507 | "%s(): no valid BER data\n", __func__); |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1508 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1509 | } |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1510 | *bit_error = ((u32)(data[0] & 0x0f) << 24) | |
| 1511 | ((u32)data[1] << 16) | |
| 1512 | ((u32)data[2] << 8) | |
| 1513 | (u32)data[3]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1514 | cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data); |
| 1515 | period_exp = data[0] & 0x0f; |
| 1516 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x22); |
| 1517 | cxd2841er_read_reg(priv, I2C_SLVT, 0x5e, data); |
| 1518 | n_ldpc = ((data[0] & 0x03) == 0 ? 16200 : 64800); |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1519 | if (*bit_error > ((1U << period_exp) * n_ldpc)) { |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1520 | dev_dbg(&priv->i2c->dev, |
| 1521 | "%s(): invalid BER value\n", __func__); |
| 1522 | return -EINVAL; |
| 1523 | } |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1524 | |
| 1525 | /* |
| 1526 | * FIXME: the right thing would be to return bit_error untouched, |
| 1527 | * but, as we don't know the scale returned by the counters, let's |
| 1528 | * at least preserver BER = bit_error/bit_count. |
| 1529 | */ |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1530 | if (period_exp >= 4) { |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1531 | *bit_count = (1U << (period_exp - 4)) * (n_ldpc / 200); |
| 1532 | *bit_error *= 3125ULL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1533 | } else { |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1534 | *bit_count = (1U << period_exp) * (n_ldpc / 200); |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 1535 | *bit_error *= 50000ULL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1536 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1537 | return 0; |
| 1538 | } |
| 1539 | |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1540 | static int cxd2841er_read_ber_t(struct cxd2841er_priv *priv, |
| 1541 | u32 *bit_error, u32 *bit_count) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1542 | { |
| 1543 | u8 data[2]; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1544 | u32 period; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1545 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1546 | if (priv->state != STATE_ACTIVE_TC) { |
| 1547 | dev_dbg(&priv->i2c->dev, |
| 1548 | "%s(): invalid state %d\n", __func__, priv->state); |
| 1549 | return -EINVAL; |
| 1550 | } |
| 1551 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 1552 | cxd2841er_read_reg(priv, I2C_SLVT, 0x39, data); |
| 1553 | if (!(data[0] & 0x01)) { |
| 1554 | dev_dbg(&priv->i2c->dev, |
| 1555 | "%s(): no valid BER data\n", __func__); |
| 1556 | return 0; |
| 1557 | } |
| 1558 | cxd2841er_read_regs(priv, I2C_SLVT, 0x22, data, sizeof(data)); |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1559 | *bit_error = ((u32)data[0] << 8) | (u32)data[1]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1560 | cxd2841er_read_reg(priv, I2C_SLVT, 0x6f, data); |
| 1561 | period = ((data[0] & 0x07) == 0) ? 256 : (4096 << (data[0] & 0x07)); |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1562 | |
| 1563 | /* |
| 1564 | * FIXME: the right thing would be to return bit_error untouched, |
| 1565 | * but, as we don't know the scale returned by the counters, let's |
| 1566 | * at least preserver BER = bit_error/bit_count. |
| 1567 | */ |
| 1568 | *bit_count = period / 128; |
| 1569 | *bit_error *= 78125ULL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1570 | return 0; |
| 1571 | } |
| 1572 | |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1573 | static int cxd2841er_freeze_regs(struct cxd2841er_priv *priv) |
| 1574 | { |
| 1575 | /* |
| 1576 | * Freeze registers: ensure multiple separate register reads |
| 1577 | * are from the same snapshot |
| 1578 | */ |
| 1579 | cxd2841er_write_reg(priv, I2C_SLVT, 0x01, 0x01); |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
| 1583 | static int cxd2841er_unfreeze_regs(struct cxd2841er_priv *priv) |
| 1584 | { |
| 1585 | /* |
| 1586 | * un-freeze registers |
| 1587 | */ |
| 1588 | cxd2841er_write_reg(priv, I2C_SLVT, 0x01, 0x00); |
| 1589 | return 0; |
| 1590 | } |
| 1591 | |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1592 | static u32 cxd2841er_dvbs_read_snr(struct cxd2841er_priv *priv, |
| 1593 | u8 delsys, u32 *snr) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1594 | { |
| 1595 | u8 data[3]; |
| 1596 | u32 res = 0, value; |
| 1597 | int min_index, max_index, index; |
| 1598 | static const struct cxd2841er_cnr_data *cn_data; |
| 1599 | |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1600 | cxd2841er_freeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1601 | /* Set SLV-T Bank : 0xA1 */ |
| 1602 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa1); |
| 1603 | /* |
| 1604 | * slave Bank Addr Bit Signal name |
| 1605 | * <SLV-T> A1h 10h [0] ICPM_QUICKRDY |
| 1606 | * <SLV-T> A1h 11h [4:0] ICPM_QUICKCNDT[12:8] |
| 1607 | * <SLV-T> A1h 12h [7:0] ICPM_QUICKCNDT[7:0] |
| 1608 | */ |
| 1609 | cxd2841er_read_regs(priv, I2C_SLVT, 0x10, data, 3); |
| 1610 | if (data[0] & 0x01) { |
| 1611 | value = ((u32)(data[1] & 0x1F) << 8) | (u32)(data[2] & 0xFF); |
| 1612 | min_index = 0; |
| 1613 | if (delsys == SYS_DVBS) { |
| 1614 | cn_data = s_cn_data; |
| 1615 | max_index = sizeof(s_cn_data) / |
| 1616 | sizeof(s_cn_data[0]) - 1; |
| 1617 | } else { |
| 1618 | cn_data = s2_cn_data; |
| 1619 | max_index = sizeof(s2_cn_data) / |
| 1620 | sizeof(s2_cn_data[0]) - 1; |
| 1621 | } |
| 1622 | if (value >= cn_data[min_index].value) { |
| 1623 | res = cn_data[min_index].cnr_x1000; |
| 1624 | goto done; |
| 1625 | } |
| 1626 | if (value <= cn_data[max_index].value) { |
| 1627 | res = cn_data[max_index].cnr_x1000; |
| 1628 | goto done; |
| 1629 | } |
| 1630 | while ((max_index - min_index) > 1) { |
| 1631 | index = (max_index + min_index) / 2; |
| 1632 | if (value == cn_data[index].value) { |
| 1633 | res = cn_data[index].cnr_x1000; |
| 1634 | goto done; |
| 1635 | } else if (value > cn_data[index].value) |
| 1636 | max_index = index; |
| 1637 | else |
| 1638 | min_index = index; |
| 1639 | if ((max_index - min_index) <= 1) { |
| 1640 | if (value == cn_data[max_index].value) { |
| 1641 | res = cn_data[max_index].cnr_x1000; |
| 1642 | goto done; |
| 1643 | } else { |
| 1644 | res = cn_data[min_index].cnr_x1000; |
| 1645 | goto done; |
| 1646 | } |
| 1647 | } |
| 1648 | } |
| 1649 | } else { |
| 1650 | dev_dbg(&priv->i2c->dev, |
| 1651 | "%s(): no data available\n", __func__); |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1652 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1653 | return -EINVAL; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1654 | } |
| 1655 | done: |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1656 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1657 | *snr = res; |
| 1658 | return 0; |
| 1659 | } |
| 1660 | |
| 1661 | static uint32_t sony_log(uint32_t x) |
| 1662 | { |
| 1663 | return (((10000>>8)*(intlog2(x)>>16) + LOG2_E_100X/2)/LOG2_E_100X); |
| 1664 | } |
| 1665 | |
| 1666 | static int cxd2841er_read_snr_c(struct cxd2841er_priv *priv, u32 *snr) |
| 1667 | { |
| 1668 | u32 reg; |
| 1669 | u8 data[2]; |
| 1670 | enum sony_dvbc_constellation_t qam = SONY_DVBC_CONSTELLATION_16QAM; |
| 1671 | |
| 1672 | *snr = 0; |
| 1673 | if (priv->state != STATE_ACTIVE_TC) { |
| 1674 | dev_dbg(&priv->i2c->dev, |
| 1675 | "%s(): invalid state %d\n", |
| 1676 | __func__, priv->state); |
| 1677 | return -EINVAL; |
| 1678 | } |
| 1679 | |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1680 | cxd2841er_freeze_regs(priv); |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1681 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 1682 | cxd2841er_read_regs(priv, I2C_SLVT, 0x19, data, 1); |
| 1683 | qam = (enum sony_dvbc_constellation_t) (data[0] & 0x07); |
| 1684 | cxd2841er_read_regs(priv, I2C_SLVT, 0x4C, data, 2); |
| 1685 | |
| 1686 | reg = ((u32)(data[0]&0x1f) << 8) | (u32)data[1]; |
| 1687 | if (reg == 0) { |
| 1688 | dev_dbg(&priv->i2c->dev, |
| 1689 | "%s(): reg value out of range\n", __func__); |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1690 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1691 | return 0; |
| 1692 | } |
| 1693 | |
| 1694 | switch (qam) { |
| 1695 | case SONY_DVBC_CONSTELLATION_16QAM: |
| 1696 | case SONY_DVBC_CONSTELLATION_64QAM: |
| 1697 | case SONY_DVBC_CONSTELLATION_256QAM: |
| 1698 | /* SNR(dB) = -9.50 * ln(IREG_SNR_ESTIMATE / (24320)) */ |
| 1699 | if (reg < 126) |
| 1700 | reg = 126; |
| 1701 | *snr = -95 * (int32_t)sony_log(reg) + 95941; |
| 1702 | break; |
| 1703 | case SONY_DVBC_CONSTELLATION_32QAM: |
| 1704 | case SONY_DVBC_CONSTELLATION_128QAM: |
| 1705 | /* SNR(dB) = -8.75 * ln(IREG_SNR_ESTIMATE / (20800)) */ |
| 1706 | if (reg < 69) |
| 1707 | reg = 69; |
| 1708 | *snr = -88 * (int32_t)sony_log(reg) + 86999; |
| 1709 | break; |
| 1710 | default: |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1711 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1712 | return -EINVAL; |
| 1713 | } |
| 1714 | |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1715 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1716 | return 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1717 | } |
| 1718 | |
| 1719 | static int cxd2841er_read_snr_t(struct cxd2841er_priv *priv, u32 *snr) |
| 1720 | { |
| 1721 | u32 reg; |
| 1722 | u8 data[2]; |
| 1723 | |
| 1724 | *snr = 0; |
| 1725 | if (priv->state != STATE_ACTIVE_TC) { |
| 1726 | dev_dbg(&priv->i2c->dev, |
| 1727 | "%s(): invalid state %d\n", __func__, priv->state); |
| 1728 | return -EINVAL; |
| 1729 | } |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1730 | |
| 1731 | cxd2841er_freeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1732 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 1733 | cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data)); |
| 1734 | reg = ((u32)data[0] << 8) | (u32)data[1]; |
| 1735 | if (reg == 0) { |
| 1736 | dev_dbg(&priv->i2c->dev, |
| 1737 | "%s(): reg value out of range\n", __func__); |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1738 | cxd2841er_unfreeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1739 | return 0; |
| 1740 | } |
| 1741 | if (reg > 4996) |
| 1742 | reg = 4996; |
| 1743 | *snr = 10000 * ((intlog10(reg) - intlog10(5350 - reg)) >> 24) + 28500; |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1744 | cxd2841er_unfreeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1745 | return 0; |
| 1746 | } |
| 1747 | |
Mauro Carvalho Chehab | c8946c8 | 2015-08-11 15:08:47 -0300 | [diff] [blame] | 1748 | static int cxd2841er_read_snr_t2(struct cxd2841er_priv *priv, u32 *snr) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1749 | { |
| 1750 | u32 reg; |
| 1751 | u8 data[2]; |
| 1752 | |
| 1753 | *snr = 0; |
| 1754 | if (priv->state != STATE_ACTIVE_TC) { |
| 1755 | dev_dbg(&priv->i2c->dev, |
| 1756 | "%s(): invalid state %d\n", __func__, priv->state); |
| 1757 | return -EINVAL; |
| 1758 | } |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1759 | |
| 1760 | cxd2841er_freeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1761 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 1762 | cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data)); |
| 1763 | reg = ((u32)data[0] << 8) | (u32)data[1]; |
| 1764 | if (reg == 0) { |
| 1765 | dev_dbg(&priv->i2c->dev, |
| 1766 | "%s(): reg value out of range\n", __func__); |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1767 | cxd2841er_unfreeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1768 | return 0; |
| 1769 | } |
| 1770 | if (reg > 10876) |
| 1771 | reg = 10876; |
| 1772 | *snr = 10000 * ((intlog10(reg) - |
| 1773 | intlog10(12600 - reg)) >> 24) + 32000; |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1774 | cxd2841er_unfreeze_regs(priv); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1775 | return 0; |
| 1776 | } |
| 1777 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1778 | static int cxd2841er_read_snr_i(struct cxd2841er_priv *priv, u32 *snr) |
| 1779 | { |
| 1780 | u32 reg; |
| 1781 | u8 data[2]; |
| 1782 | |
| 1783 | *snr = 0; |
| 1784 | if (priv->state != STATE_ACTIVE_TC) { |
| 1785 | dev_dbg(&priv->i2c->dev, |
| 1786 | "%s(): invalid state %d\n", __func__, |
| 1787 | priv->state); |
| 1788 | return -EINVAL; |
| 1789 | } |
| 1790 | |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1791 | cxd2841er_freeze_regs(priv); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1792 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60); |
| 1793 | cxd2841er_read_regs(priv, I2C_SLVT, 0x28, data, sizeof(data)); |
| 1794 | reg = ((u32)data[0] << 8) | (u32)data[1]; |
| 1795 | if (reg == 0) { |
| 1796 | dev_dbg(&priv->i2c->dev, |
| 1797 | "%s(): reg value out of range\n", __func__); |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1798 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1799 | return 0; |
| 1800 | } |
| 1801 | if (reg > 4996) |
| 1802 | reg = 4996; |
| 1803 | *snr = 100 * intlog10(reg) - 9031; |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 1804 | cxd2841er_unfreeze_regs(priv); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1805 | return 0; |
| 1806 | } |
| 1807 | |
Abylay Ospan | d0998ce | 2016-06-30 23:09:48 -0300 | [diff] [blame] | 1808 | static u16 cxd2841er_read_agc_gain_c(struct cxd2841er_priv *priv, |
| 1809 | u8 delsys) |
| 1810 | { |
| 1811 | u8 data[2]; |
| 1812 | |
| 1813 | cxd2841er_write_reg( |
| 1814 | priv, I2C_SLVT, 0x00, 0x40); |
| 1815 | cxd2841er_read_regs(priv, I2C_SLVT, 0x49, data, 2); |
| 1816 | dev_dbg(&priv->i2c->dev, |
| 1817 | "%s(): AGC value=%u\n", |
| 1818 | __func__, (((u16)data[0] & 0x0F) << 8) | |
| 1819 | (u16)(data[1] & 0xFF)); |
| 1820 | return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4; |
| 1821 | } |
| 1822 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1823 | static u16 cxd2841er_read_agc_gain_t_t2(struct cxd2841er_priv *priv, |
| 1824 | u8 delsys) |
| 1825 | { |
| 1826 | u8 data[2]; |
| 1827 | |
| 1828 | cxd2841er_write_reg( |
| 1829 | priv, I2C_SLVT, 0x00, (delsys == SYS_DVBT ? 0x10 : 0x20)); |
| 1830 | cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2); |
Abylay Ospan | c5ea46d | 2016-04-02 23:31:50 -0300 | [diff] [blame] | 1831 | dev_dbg(&priv->i2c->dev, |
| 1832 | "%s(): AGC value=%u\n", |
| 1833 | __func__, (((u16)data[0] & 0x0F) << 8) | |
| 1834 | (u16)(data[1] & 0xFF)); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1835 | return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4; |
| 1836 | } |
| 1837 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1838 | static u16 cxd2841er_read_agc_gain_i(struct cxd2841er_priv *priv, |
| 1839 | u8 delsys) |
| 1840 | { |
| 1841 | u8 data[2]; |
| 1842 | |
| 1843 | cxd2841er_write_reg( |
| 1844 | priv, I2C_SLVT, 0x00, 0x60); |
| 1845 | cxd2841er_read_regs(priv, I2C_SLVT, 0x26, data, 2); |
| 1846 | |
| 1847 | dev_dbg(&priv->i2c->dev, |
| 1848 | "%s(): AGC value=%u\n", |
| 1849 | __func__, (((u16)data[0] & 0x0F) << 8) | |
| 1850 | (u16)(data[1] & 0xFF)); |
| 1851 | return ((((u16)data[0] & 0x0F) << 8) | (u16)(data[1] & 0xFF)) << 4; |
| 1852 | } |
| 1853 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1854 | static u16 cxd2841er_read_agc_gain_s(struct cxd2841er_priv *priv) |
| 1855 | { |
| 1856 | u8 data[2]; |
| 1857 | |
| 1858 | /* Set SLV-T Bank : 0xA0 */ |
| 1859 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); |
| 1860 | /* |
| 1861 | * slave Bank Addr Bit Signal name |
| 1862 | * <SLV-T> A0h 1Fh [4:0] IRFAGC_GAIN[12:8] |
| 1863 | * <SLV-T> A0h 20h [7:0] IRFAGC_GAIN[7:0] |
| 1864 | */ |
| 1865 | cxd2841er_read_regs(priv, I2C_SLVT, 0x1f, data, 2); |
| 1866 | return ((((u16)data[0] & 0x1F) << 8) | (u16)(data[1] & 0xFF)) << 3; |
| 1867 | } |
| 1868 | |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1869 | static void cxd2841er_read_ber(struct dvb_frontend *fe) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1870 | { |
| 1871 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 1872 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1873 | u32 ret, bit_error = 0, bit_count = 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1874 | |
| 1875 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1876 | switch (p->delivery_system) { |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 1877 | case SYS_DVBC_ANNEX_A: |
| 1878 | case SYS_DVBC_ANNEX_B: |
| 1879 | case SYS_DVBC_ANNEX_C: |
| 1880 | ret = cxd2841er_read_ber_c(priv, &bit_error, &bit_count); |
| 1881 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1882 | case SYS_DVBS: |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1883 | ret = cxd2841er_mon_read_ber_s(priv, &bit_error, &bit_count); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1884 | break; |
| 1885 | case SYS_DVBS2: |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1886 | ret = cxd2841er_mon_read_ber_s2(priv, &bit_error, &bit_count); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1887 | break; |
| 1888 | case SYS_DVBT: |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1889 | ret = cxd2841er_read_ber_t(priv, &bit_error, &bit_count); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1890 | break; |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1891 | case SYS_DVBT2: |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1892 | ret = cxd2841er_read_ber_t2(priv, &bit_error, &bit_count); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1893 | break; |
| 1894 | default: |
| 1895 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1896 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1897 | return; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1898 | } |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1899 | |
| 1900 | if (!ret) { |
| 1901 | p->post_bit_error.stat[0].scale = FE_SCALE_COUNTER; |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 1902 | p->post_bit_error.stat[0].uvalue += bit_error; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1903 | p->post_bit_count.stat[0].scale = FE_SCALE_COUNTER; |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 1904 | p->post_bit_count.stat[0].uvalue += bit_count; |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1905 | } else { |
| 1906 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 1907 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1908 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1909 | } |
| 1910 | |
Mauro Carvalho Chehab | 5fda1b6 | 2016-06-30 19:41:45 -0300 | [diff] [blame] | 1911 | static void cxd2841er_read_signal_strength(struct dvb_frontend *fe) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1912 | { |
| 1913 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 1914 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
Mauro Carvalho Chehab | 313a7df | 2016-07-01 15:41:38 -0300 | [diff] [blame] | 1915 | s32 strength; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1916 | |
| 1917 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1918 | switch (p->delivery_system) { |
| 1919 | case SYS_DVBT: |
| 1920 | case SYS_DVBT2: |
Mauro Carvalho Chehab | 5fda1b6 | 2016-06-30 19:41:45 -0300 | [diff] [blame] | 1921 | strength = cxd2841er_read_agc_gain_t_t2(priv, |
| 1922 | p->delivery_system); |
| 1923 | p->strength.stat[0].scale = FE_SCALE_DECIBEL; |
| 1924 | /* Formula was empirically determinated @ 410 MHz */ |
Mauro Carvalho Chehab | 313a7df | 2016-07-01 15:41:38 -0300 | [diff] [blame] | 1925 | p->strength.stat[0].uvalue = strength * 366 / 100 - 89520; |
Mauro Carvalho Chehab | 5fda1b6 | 2016-06-30 19:41:45 -0300 | [diff] [blame] | 1926 | break; /* Code moved out of the function */ |
Mauro Carvalho Chehab | 988bd28 | 2016-07-01 11:03:14 -0300 | [diff] [blame] | 1927 | case SYS_DVBC_ANNEX_A: |
Abylay Ospan | 997bdc0 | 2016-07-15 14:59:37 -0300 | [diff] [blame] | 1928 | case SYS_DVBC_ANNEX_B: |
| 1929 | case SYS_DVBC_ANNEX_C: |
| 1930 | strength = cxd2841er_read_agc_gain_c(priv, |
Mauro Carvalho Chehab | 988bd28 | 2016-07-01 11:03:14 -0300 | [diff] [blame] | 1931 | p->delivery_system); |
Mauro Carvalho Chehab | d12b791 | 2016-07-01 11:03:16 -0300 | [diff] [blame] | 1932 | p->strength.stat[0].scale = FE_SCALE_DECIBEL; |
| 1933 | /* |
| 1934 | * Formula was empirically determinated via linear regression, |
| 1935 | * using frequencies: 175 MHz, 410 MHz and 800 MHz, and a |
| 1936 | * stream modulated with QAM64 |
| 1937 | */ |
Mauro Carvalho Chehab | 313a7df | 2016-07-01 15:41:38 -0300 | [diff] [blame] | 1938 | p->strength.stat[0].uvalue = strength * 4045 / 1000 - 85224; |
Mauro Carvalho Chehab | 988bd28 | 2016-07-01 11:03:14 -0300 | [diff] [blame] | 1939 | break; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1940 | case SYS_ISDBT: |
Mauro Carvalho Chehab | 313a7df | 2016-07-01 15:41:38 -0300 | [diff] [blame] | 1941 | strength = cxd2841er_read_agc_gain_i(priv, p->delivery_system); |
| 1942 | p->strength.stat[0].scale = FE_SCALE_DECIBEL; |
| 1943 | /* |
| 1944 | * Formula was empirically determinated via linear regression, |
| 1945 | * using frequencies: 175 MHz, 410 MHz and 800 MHz. |
| 1946 | */ |
| 1947 | p->strength.stat[0].uvalue = strength * 3775 / 1000 - 90185; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1948 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1949 | case SYS_DVBS: |
| 1950 | case SYS_DVBS2: |
Mauro Carvalho Chehab | 5fda1b6 | 2016-06-30 19:41:45 -0300 | [diff] [blame] | 1951 | strength = 65535 - cxd2841er_read_agc_gain_s(priv); |
| 1952 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 1953 | p->strength.stat[0].uvalue = strength; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1954 | break; |
| 1955 | default: |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1956 | p->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1957 | break; |
| 1958 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1959 | } |
| 1960 | |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1961 | static void cxd2841er_read_snr(struct dvb_frontend *fe) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1962 | { |
| 1963 | u32 tmp = 0; |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1964 | int ret = 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1965 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 1966 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 1967 | |
| 1968 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 1969 | switch (p->delivery_system) { |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1970 | case SYS_DVBC_ANNEX_A: |
| 1971 | case SYS_DVBC_ANNEX_B: |
| 1972 | case SYS_DVBC_ANNEX_C: |
| 1973 | ret = cxd2841er_read_snr_c(priv, &tmp); |
| 1974 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1975 | case SYS_DVBT: |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1976 | ret = cxd2841er_read_snr_t(priv, &tmp); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1977 | break; |
| 1978 | case SYS_DVBT2: |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1979 | ret = cxd2841er_read_snr_t2(priv, &tmp); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1980 | break; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1981 | case SYS_ISDBT: |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1982 | ret = cxd2841er_read_snr_i(priv, &tmp); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 1983 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1984 | case SYS_DVBS: |
| 1985 | case SYS_DVBS2: |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1986 | ret = cxd2841er_dvbs_read_snr(priv, p->delivery_system, &tmp); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1987 | break; |
| 1988 | default: |
| 1989 | dev_dbg(&priv->i2c->dev, "%s(): unknown delivery system %d\n", |
| 1990 | __func__, p->delivery_system); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1991 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 1992 | return; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 1993 | } |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 1994 | |
Abylay Ospan | e05b187 | 2016-07-15 17:04:17 -0300 | [diff] [blame] | 1995 | if (!ret) { |
| 1996 | p->cnr.stat[0].scale = FE_SCALE_DECIBEL; |
| 1997 | p->cnr.stat[0].svalue = tmp; |
| 1998 | } else { |
| 1999 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 2000 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2001 | } |
| 2002 | |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 2003 | static void cxd2841er_read_ucblocks(struct dvb_frontend *fe) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2004 | { |
| 2005 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 2006 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 2007 | u32 ucblocks = 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2008 | |
| 2009 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 2010 | switch (p->delivery_system) { |
Abylay Ospan | a6f330c | 2016-07-15 15:34:22 -0300 | [diff] [blame] | 2011 | case SYS_DVBC_ANNEX_A: |
| 2012 | case SYS_DVBC_ANNEX_B: |
| 2013 | case SYS_DVBC_ANNEX_C: |
| 2014 | cxd2841er_read_packet_errors_c(priv, &ucblocks); |
| 2015 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2016 | case SYS_DVBT: |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 2017 | cxd2841er_read_packet_errors_t(priv, &ucblocks); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2018 | break; |
| 2019 | case SYS_DVBT2: |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 2020 | cxd2841er_read_packet_errors_t2(priv, &ucblocks); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2021 | break; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2022 | case SYS_ISDBT: |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 2023 | cxd2841er_read_packet_errors_i(priv, &ucblocks); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2024 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2025 | default: |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 2026 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 2027 | return; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2028 | } |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 2029 | dev_dbg(&priv->i2c->dev, "%s() ucblocks=%u\n", __func__, ucblocks); |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 2030 | |
| 2031 | p->block_error.stat[0].scale = FE_SCALE_COUNTER; |
| 2032 | p->block_error.stat[0].uvalue = ucblocks; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2033 | } |
| 2034 | |
| 2035 | static int cxd2841er_dvbt2_set_profile( |
| 2036 | struct cxd2841er_priv *priv, enum cxd2841er_dvbt2_profile_t profile) |
| 2037 | { |
| 2038 | u8 tune_mode; |
| 2039 | u8 seq_not2d_time; |
| 2040 | |
| 2041 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 2042 | switch (profile) { |
| 2043 | case DVBT2_PROFILE_BASE: |
| 2044 | tune_mode = 0x01; |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2045 | /* Set early unlock time */ |
| 2046 | seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x0E:0x0C; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2047 | break; |
| 2048 | case DVBT2_PROFILE_LITE: |
| 2049 | tune_mode = 0x05; |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2050 | /* Set early unlock time */ |
| 2051 | seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x2E:0x28; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2052 | break; |
| 2053 | case DVBT2_PROFILE_ANY: |
| 2054 | tune_mode = 0x00; |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2055 | /* Set early unlock time */ |
| 2056 | seq_not2d_time = (priv->xtal == SONY_XTAL_24000)?0x2E:0x28; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2057 | break; |
| 2058 | default: |
| 2059 | return -EINVAL; |
| 2060 | } |
| 2061 | /* Set SLV-T Bank : 0x2E */ |
| 2062 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2e); |
| 2063 | /* Set profile and tune mode */ |
| 2064 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x10, tune_mode, 0x07); |
| 2065 | /* Set SLV-T Bank : 0x2B */ |
| 2066 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); |
| 2067 | /* Set early unlock detection time */ |
| 2068 | cxd2841er_write_reg(priv, I2C_SLVT, 0x9d, seq_not2d_time); |
| 2069 | return 0; |
| 2070 | } |
| 2071 | |
| 2072 | static int cxd2841er_dvbt2_set_plp_config(struct cxd2841er_priv *priv, |
| 2073 | u8 is_auto, u8 plp_id) |
| 2074 | { |
| 2075 | if (is_auto) { |
| 2076 | dev_dbg(&priv->i2c->dev, |
| 2077 | "%s() using auto PLP selection\n", __func__); |
| 2078 | } else { |
| 2079 | dev_dbg(&priv->i2c->dev, |
| 2080 | "%s() using manual PLP selection, ID %d\n", |
| 2081 | __func__, plp_id); |
| 2082 | } |
| 2083 | /* Set SLV-T Bank : 0x23 */ |
| 2084 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23); |
| 2085 | if (!is_auto) { |
| 2086 | /* Manual PLP selection mode. Set the data PLP Id. */ |
| 2087 | cxd2841er_write_reg(priv, I2C_SLVT, 0xaf, plp_id); |
| 2088 | } |
| 2089 | /* Auto PLP select (Scanning mode = 0x00). Data PLP select = 0x01. */ |
| 2090 | cxd2841er_write_reg(priv, I2C_SLVT, 0xad, (is_auto ? 0x00 : 0x01)); |
| 2091 | return 0; |
| 2092 | } |
| 2093 | |
| 2094 | static int cxd2841er_sleep_tc_to_active_t2_band(struct cxd2841er_priv *priv, |
| 2095 | u32 bandwidth) |
| 2096 | { |
| 2097 | u32 iffreq; |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2098 | u8 data[MAX_WRITE_REGSIZE]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2099 | |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2100 | const uint8_t nominalRate8bw[3][5] = { |
| 2101 | /* TRCG Nominal Rate [37:0] */ |
| 2102 | {0x11, 0xF0, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2103 | {0x15, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2104 | {0x11, 0xF0, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2105 | }; |
| 2106 | |
| 2107 | const uint8_t nominalRate7bw[3][5] = { |
| 2108 | /* TRCG Nominal Rate [37:0] */ |
| 2109 | {0x14, 0x80, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2110 | {0x18, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2111 | {0x14, 0x80, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2112 | }; |
| 2113 | |
| 2114 | const uint8_t nominalRate6bw[3][5] = { |
| 2115 | /* TRCG Nominal Rate [37:0] */ |
| 2116 | {0x17, 0xEA, 0xAA, 0xAA, 0xAA}, /* 20.5MHz XTal */ |
| 2117 | {0x1C, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2118 | {0x17, 0xEA, 0xAA, 0xAA, 0xAA} /* 41MHz XTal */ |
| 2119 | }; |
| 2120 | |
| 2121 | const uint8_t nominalRate5bw[3][5] = { |
| 2122 | /* TRCG Nominal Rate [37:0] */ |
| 2123 | {0x1C, 0xB3, 0x33, 0x33, 0x33}, /* 20.5MHz XTal */ |
| 2124 | {0x21, 0x99, 0x99, 0x99, 0x99}, /* 24MHz XTal */ |
| 2125 | {0x1C, 0xB3, 0x33, 0x33, 0x33} /* 41MHz XTal */ |
| 2126 | }; |
| 2127 | |
| 2128 | const uint8_t nominalRate17bw[3][5] = { |
| 2129 | /* TRCG Nominal Rate [37:0] */ |
| 2130 | {0x58, 0xE2, 0xAF, 0xE0, 0xBC}, /* 20.5MHz XTal */ |
| 2131 | {0x68, 0x0F, 0xA2, 0x32, 0xD0}, /* 24MHz XTal */ |
| 2132 | {0x58, 0xE2, 0xAF, 0xE0, 0xBC} /* 41MHz XTal */ |
| 2133 | }; |
| 2134 | |
| 2135 | const uint8_t itbCoef8bw[3][14] = { |
| 2136 | {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, |
| 2137 | 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8}, /* 20.5MHz XTal */ |
| 2138 | {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, |
| 2139 | 0x29, 0xA5, 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz XTal */ |
| 2140 | {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, |
| 2141 | 0x23, 0xA9, 0x1F, 0xA8, 0x2C, 0xC8} /* 41MHz XTal */ |
| 2142 | }; |
| 2143 | |
| 2144 | const uint8_t itbCoef7bw[3][14] = { |
| 2145 | {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, |
| 2146 | 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5}, /* 20.5MHz XTal */ |
| 2147 | {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, |
| 2148 | 0x29, 0xA2, 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz XTal */ |
| 2149 | {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, |
| 2150 | 0x29, 0xB0, 0x26, 0xA9, 0x21, 0xA5} /* 41MHz XTal */ |
| 2151 | }; |
| 2152 | |
| 2153 | const uint8_t itbCoef6bw[3][14] = { |
| 2154 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, |
| 2155 | 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */ |
| 2156 | {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, |
| 2157 | 0x29, 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */ |
| 2158 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, |
| 2159 | 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */ |
| 2160 | }; |
| 2161 | |
| 2162 | const uint8_t itbCoef5bw[3][14] = { |
| 2163 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, |
| 2164 | 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */ |
| 2165 | {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, |
| 2166 | 0x29, 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */ |
| 2167 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, |
| 2168 | 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */ |
| 2169 | }; |
| 2170 | |
| 2171 | const uint8_t itbCoef17bw[3][14] = { |
| 2172 | {0x25, 0xA0, 0x36, 0x8D, 0x2E, 0x94, 0x28, 0x9B, |
| 2173 | 0x32, 0x90, 0x2C, 0x9D, 0x29, 0x99}, /* 20.5MHz XTal */ |
| 2174 | {0x33, 0x8E, 0x2B, 0x97, 0x2D, 0x95, 0x37, 0x8B, |
| 2175 | 0x30, 0x97, 0x2D, 0x9A, 0x21, 0xA4}, /* 24MHz XTal */ |
| 2176 | {0x25, 0xA0, 0x36, 0x8D, 0x2E, 0x94, 0x28, 0x9B, |
| 2177 | 0x32, 0x90, 0x2C, 0x9D, 0x29, 0x99} /* 41MHz XTal */ |
| 2178 | }; |
| 2179 | |
| 2180 | /* Set SLV-T Bank : 0x20 */ |
| 2181 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 2182 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2183 | switch (bandwidth) { |
| 2184 | case 8000000: |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2185 | /* <Timing Recovery setting> */ |
| 2186 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2187 | 0x9F, nominalRate8bw[priv->xtal], 5); |
| 2188 | |
| 2189 | /* Set SLV-T Bank : 0x27 */ |
| 2190 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); |
| 2191 | cxd2841er_set_reg_bits(priv, I2C_SLVT, |
| 2192 | 0x7a, 0x00, 0x0f); |
| 2193 | |
| 2194 | /* Set SLV-T Bank : 0x10 */ |
| 2195 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2196 | |
| 2197 | /* Group delay equaliser settings for |
| 2198 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2199 | */ |
| 2200 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2201 | 0xA6, itbCoef8bw[priv->xtal], 14); |
| 2202 | /* <IF freq setting> */ |
| 2203 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.80); |
| 2204 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2205 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2206 | data[2] = (u8)(iffreq & 0xff); |
| 2207 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2208 | /* System bandwidth setting */ |
| 2209 | cxd2841er_set_reg_bits( |
| 2210 | priv, I2C_SLVT, 0xD7, 0x00, 0x07); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2211 | break; |
| 2212 | case 7000000: |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2213 | /* <Timing Recovery setting> */ |
| 2214 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2215 | 0x9F, nominalRate7bw[priv->xtal], 5); |
| 2216 | |
| 2217 | /* Set SLV-T Bank : 0x27 */ |
| 2218 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); |
| 2219 | cxd2841er_set_reg_bits(priv, I2C_SLVT, |
| 2220 | 0x7a, 0x00, 0x0f); |
| 2221 | |
| 2222 | /* Set SLV-T Bank : 0x10 */ |
| 2223 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2224 | |
| 2225 | /* Group delay equaliser settings for |
| 2226 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2227 | */ |
| 2228 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2229 | 0xA6, itbCoef7bw[priv->xtal], 14); |
| 2230 | /* <IF freq setting> */ |
| 2231 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.20); |
| 2232 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2233 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2234 | data[2] = (u8)(iffreq & 0xff); |
| 2235 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2236 | /* System bandwidth setting */ |
| 2237 | cxd2841er_set_reg_bits( |
| 2238 | priv, I2C_SLVT, 0xD7, 0x02, 0x07); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2239 | break; |
| 2240 | case 6000000: |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2241 | /* <Timing Recovery setting> */ |
| 2242 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2243 | 0x9F, nominalRate6bw[priv->xtal], 5); |
| 2244 | |
| 2245 | /* Set SLV-T Bank : 0x27 */ |
| 2246 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); |
| 2247 | cxd2841er_set_reg_bits(priv, I2C_SLVT, |
| 2248 | 0x7a, 0x00, 0x0f); |
| 2249 | |
| 2250 | /* Set SLV-T Bank : 0x10 */ |
| 2251 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2252 | |
| 2253 | /* Group delay equaliser settings for |
| 2254 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2255 | */ |
| 2256 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2257 | 0xA6, itbCoef6bw[priv->xtal], 14); |
| 2258 | /* <IF freq setting> */ |
| 2259 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); |
| 2260 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2261 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2262 | data[2] = (u8)(iffreq & 0xff); |
| 2263 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2264 | /* System bandwidth setting */ |
| 2265 | cxd2841er_set_reg_bits( |
| 2266 | priv, I2C_SLVT, 0xD7, 0x04, 0x07); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2267 | break; |
| 2268 | case 5000000: |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2269 | /* <Timing Recovery setting> */ |
| 2270 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2271 | 0x9F, nominalRate5bw[priv->xtal], 5); |
| 2272 | |
| 2273 | /* Set SLV-T Bank : 0x27 */ |
| 2274 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); |
| 2275 | cxd2841er_set_reg_bits(priv, I2C_SLVT, |
| 2276 | 0x7a, 0x00, 0x0f); |
| 2277 | |
| 2278 | /* Set SLV-T Bank : 0x10 */ |
| 2279 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2280 | |
| 2281 | /* Group delay equaliser settings for |
| 2282 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2283 | */ |
| 2284 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2285 | 0xA6, itbCoef5bw[priv->xtal], 14); |
| 2286 | /* <IF freq setting> */ |
| 2287 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); |
| 2288 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2289 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2290 | data[2] = (u8)(iffreq & 0xff); |
| 2291 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2292 | /* System bandwidth setting */ |
| 2293 | cxd2841er_set_reg_bits( |
| 2294 | priv, I2C_SLVT, 0xD7, 0x06, 0x07); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2295 | break; |
| 2296 | case 1712000: |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2297 | /* <Timing Recovery setting> */ |
| 2298 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2299 | 0x9F, nominalRate17bw[priv->xtal], 5); |
| 2300 | |
| 2301 | /* Set SLV-T Bank : 0x27 */ |
| 2302 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); |
| 2303 | cxd2841er_set_reg_bits(priv, I2C_SLVT, |
| 2304 | 0x7a, 0x03, 0x0f); |
| 2305 | |
| 2306 | /* Set SLV-T Bank : 0x10 */ |
| 2307 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2308 | |
| 2309 | /* Group delay equaliser settings for |
| 2310 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2311 | */ |
| 2312 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2313 | 0xA6, itbCoef17bw[priv->xtal], 14); |
| 2314 | /* <IF freq setting> */ |
| 2315 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.50); |
| 2316 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2317 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2318 | data[2] = (u8)(iffreq & 0xff); |
| 2319 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2320 | /* System bandwidth setting */ |
| 2321 | cxd2841er_set_reg_bits( |
| 2322 | priv, I2C_SLVT, 0xD7, 0x03, 0x07); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2323 | break; |
| 2324 | default: |
| 2325 | return -EINVAL; |
| 2326 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2327 | return 0; |
| 2328 | } |
| 2329 | |
| 2330 | static int cxd2841er_sleep_tc_to_active_t_band( |
| 2331 | struct cxd2841er_priv *priv, u32 bandwidth) |
| 2332 | { |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2333 | u8 data[MAX_WRITE_REGSIZE]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2334 | u32 iffreq; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2335 | u8 nominalRate8bw[3][5] = { |
| 2336 | /* TRCG Nominal Rate [37:0] */ |
| 2337 | {0x11, 0xF0, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2338 | {0x15, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2339 | {0x11, 0xF0, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2340 | }; |
| 2341 | u8 nominalRate7bw[3][5] = { |
| 2342 | /* TRCG Nominal Rate [37:0] */ |
| 2343 | {0x14, 0x80, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2344 | {0x18, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2345 | {0x14, 0x80, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2346 | }; |
| 2347 | u8 nominalRate6bw[3][5] = { |
| 2348 | /* TRCG Nominal Rate [37:0] */ |
| 2349 | {0x17, 0xEA, 0xAA, 0xAA, 0xAA}, /* 20.5MHz XTal */ |
| 2350 | {0x1C, 0x00, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2351 | {0x17, 0xEA, 0xAA, 0xAA, 0xAA} /* 41MHz XTal */ |
| 2352 | }; |
| 2353 | u8 nominalRate5bw[3][5] = { |
| 2354 | /* TRCG Nominal Rate [37:0] */ |
| 2355 | {0x1C, 0xB3, 0x33, 0x33, 0x33}, /* 20.5MHz XTal */ |
| 2356 | {0x21, 0x99, 0x99, 0x99, 0x99}, /* 24MHz XTal */ |
| 2357 | {0x1C, 0xB3, 0x33, 0x33, 0x33} /* 41MHz XTal */ |
| 2358 | }; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2359 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2360 | u8 itbCoef8bw[3][14] = { |
| 2361 | {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, 0x23, 0xA9, |
| 2362 | 0x1F, 0xA8, 0x2C, 0xC8}, /* 20.5MHz XTal */ |
| 2363 | {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, 0x29, 0xA5, |
| 2364 | 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz XTal */ |
| 2365 | {0x26, 0xAF, 0x06, 0xCD, 0x13, 0xBB, 0x28, 0xBA, 0x23, 0xA9, |
| 2366 | 0x1F, 0xA8, 0x2C, 0xC8} /* 41MHz XTal */ |
| 2367 | }; |
| 2368 | u8 itbCoef7bw[3][14] = { |
| 2369 | {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, 0x29, 0xB0, |
| 2370 | 0x26, 0xA9, 0x21, 0xA5}, /* 20.5MHz XTal */ |
| 2371 | {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, 0x29, 0xA2, |
| 2372 | 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz XTal */ |
| 2373 | {0x2C, 0xBD, 0x02, 0xCF, 0x04, 0xF8, 0x23, 0xA6, 0x29, 0xB0, |
| 2374 | 0x26, 0xA9, 0x21, 0xA5} /* 41MHz XTal */ |
| 2375 | }; |
| 2376 | u8 itbCoef6bw[3][14] = { |
| 2377 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF, |
| 2378 | 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */ |
| 2379 | {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, 0xA4, |
| 2380 | 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */ |
| 2381 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF, |
| 2382 | 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */ |
| 2383 | }; |
| 2384 | u8 itbCoef5bw[3][14] = { |
| 2385 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF, |
| 2386 | 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */ |
| 2387 | {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, 0xA4, |
| 2388 | 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz XTal */ |
| 2389 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, 0xCF, |
| 2390 | 0x00, 0xE6, 0x23, 0xA4} /* 41MHz XTal */ |
| 2391 | }; |
| 2392 | |
| 2393 | /* Set SLV-T Bank : 0x13 */ |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2394 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13); |
| 2395 | /* Echo performance optimization setting */ |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2396 | data[0] = 0x01; |
| 2397 | data[1] = 0x14; |
| 2398 | cxd2841er_write_regs(priv, I2C_SLVT, 0x9C, data, 2); |
| 2399 | |
| 2400 | /* Set SLV-T Bank : 0x10 */ |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2401 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2402 | |
| 2403 | switch (bandwidth) { |
| 2404 | case 8000000: |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2405 | /* <Timing Recovery setting> */ |
| 2406 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2407 | 0x9F, nominalRate8bw[priv->xtal], 5); |
| 2408 | /* Group delay equaliser settings for |
| 2409 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2410 | */ |
| 2411 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2412 | 0xA6, itbCoef8bw[priv->xtal], 14); |
| 2413 | /* <IF freq setting> */ |
| 2414 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.80); |
| 2415 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2416 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2417 | data[2] = (u8)(iffreq & 0xff); |
| 2418 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2419 | /* System bandwidth setting */ |
| 2420 | cxd2841er_set_reg_bits( |
| 2421 | priv, I2C_SLVT, 0xD7, 0x00, 0x07); |
| 2422 | |
| 2423 | /* Demod core latency setting */ |
| 2424 | if (priv->xtal == SONY_XTAL_24000) { |
| 2425 | data[0] = 0x15; |
| 2426 | data[1] = 0x28; |
| 2427 | } else { |
| 2428 | data[0] = 0x01; |
| 2429 | data[1] = 0xE0; |
| 2430 | } |
| 2431 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2432 | |
| 2433 | /* Notch filter setting */ |
| 2434 | data[0] = 0x01; |
| 2435 | data[1] = 0x02; |
| 2436 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17); |
| 2437 | cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2438 | break; |
| 2439 | case 7000000: |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2440 | /* <Timing Recovery setting> */ |
| 2441 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2442 | 0x9F, nominalRate7bw[priv->xtal], 5); |
| 2443 | /* Group delay equaliser settings for |
| 2444 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2445 | */ |
| 2446 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2447 | 0xA6, itbCoef7bw[priv->xtal], 14); |
| 2448 | /* <IF freq setting> */ |
| 2449 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.20); |
| 2450 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2451 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2452 | data[2] = (u8)(iffreq & 0xff); |
| 2453 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2454 | /* System bandwidth setting */ |
| 2455 | cxd2841er_set_reg_bits( |
| 2456 | priv, I2C_SLVT, 0xD7, 0x02, 0x07); |
| 2457 | |
| 2458 | /* Demod core latency setting */ |
| 2459 | if (priv->xtal == SONY_XTAL_24000) { |
| 2460 | data[0] = 0x1F; |
| 2461 | data[1] = 0xF8; |
| 2462 | } else { |
| 2463 | data[0] = 0x12; |
| 2464 | data[1] = 0xF8; |
| 2465 | } |
| 2466 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2467 | |
| 2468 | /* Notch filter setting */ |
| 2469 | data[0] = 0x00; |
| 2470 | data[1] = 0x03; |
| 2471 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17); |
| 2472 | cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2473 | break; |
| 2474 | case 6000000: |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2475 | /* <Timing Recovery setting> */ |
| 2476 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2477 | 0x9F, nominalRate6bw[priv->xtal], 5); |
| 2478 | /* Group delay equaliser settings for |
| 2479 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2480 | */ |
| 2481 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2482 | 0xA6, itbCoef6bw[priv->xtal], 14); |
| 2483 | /* <IF freq setting> */ |
| 2484 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); |
| 2485 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2486 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2487 | data[2] = (u8)(iffreq & 0xff); |
| 2488 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2489 | /* System bandwidth setting */ |
| 2490 | cxd2841er_set_reg_bits( |
| 2491 | priv, I2C_SLVT, 0xD7, 0x04, 0x07); |
| 2492 | |
| 2493 | /* Demod core latency setting */ |
| 2494 | if (priv->xtal == SONY_XTAL_24000) { |
| 2495 | data[0] = 0x25; |
| 2496 | data[1] = 0x4C; |
| 2497 | } else { |
| 2498 | data[0] = 0x1F; |
| 2499 | data[1] = 0xDC; |
| 2500 | } |
| 2501 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2502 | |
| 2503 | /* Notch filter setting */ |
| 2504 | data[0] = 0x00; |
| 2505 | data[1] = 0x03; |
| 2506 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17); |
| 2507 | cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2508 | break; |
| 2509 | case 5000000: |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2510 | /* <Timing Recovery setting> */ |
| 2511 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2512 | 0x9F, nominalRate5bw[priv->xtal], 5); |
| 2513 | /* Group delay equaliser settings for |
| 2514 | * ASCOT2D, ASCOT2E and ASCOT3 tuners |
| 2515 | */ |
| 2516 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2517 | 0xA6, itbCoef5bw[priv->xtal], 14); |
| 2518 | /* <IF freq setting> */ |
| 2519 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.60); |
| 2520 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2521 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2522 | data[2] = (u8)(iffreq & 0xff); |
| 2523 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2524 | /* System bandwidth setting */ |
| 2525 | cxd2841er_set_reg_bits( |
| 2526 | priv, I2C_SLVT, 0xD7, 0x06, 0x07); |
| 2527 | |
| 2528 | /* Demod core latency setting */ |
| 2529 | if (priv->xtal == SONY_XTAL_24000) { |
| 2530 | data[0] = 0x2C; |
| 2531 | data[1] = 0xC2; |
| 2532 | } else { |
| 2533 | data[0] = 0x26; |
| 2534 | data[1] = 0x3C; |
| 2535 | } |
| 2536 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2537 | |
| 2538 | /* Notch filter setting */ |
| 2539 | data[0] = 0x00; |
| 2540 | data[1] = 0x03; |
| 2541 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x17); |
| 2542 | cxd2841er_write_regs(priv, I2C_SLVT, 0x38, data, 2); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2543 | break; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2544 | } |
| 2545 | |
| 2546 | return 0; |
| 2547 | } |
| 2548 | |
| 2549 | static int cxd2841er_sleep_tc_to_active_i_band( |
| 2550 | struct cxd2841er_priv *priv, u32 bandwidth) |
| 2551 | { |
| 2552 | u32 iffreq; |
| 2553 | u8 data[3]; |
| 2554 | |
| 2555 | /* TRCG Nominal Rate */ |
| 2556 | u8 nominalRate8bw[3][5] = { |
| 2557 | {0x00, 0x00, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2558 | {0x11, 0xB8, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2559 | {0x00, 0x00, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2560 | }; |
| 2561 | |
| 2562 | u8 nominalRate7bw[3][5] = { |
| 2563 | {0x00, 0x00, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2564 | {0x14, 0x40, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2565 | {0x00, 0x00, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2566 | }; |
| 2567 | |
| 2568 | u8 nominalRate6bw[3][5] = { |
| 2569 | {0x14, 0x2E, 0x00, 0x00, 0x00}, /* 20.5MHz XTal */ |
| 2570 | {0x17, 0xA0, 0x00, 0x00, 0x00}, /* 24MHz XTal */ |
| 2571 | {0x14, 0x2E, 0x00, 0x00, 0x00} /* 41MHz XTal */ |
| 2572 | }; |
| 2573 | |
| 2574 | u8 itbCoef8bw[3][14] = { |
| 2575 | {0x00}, /* 20.5MHz XTal */ |
| 2576 | {0x2F, 0xBA, 0x28, 0x9B, 0x28, 0x9D, 0x28, 0xA1, 0x29, |
| 2577 | 0xA5, 0x2A, 0xAC, 0x29, 0xB5}, /* 24MHz Xtal */ |
| 2578 | {0x0}, /* 41MHz XTal */ |
| 2579 | }; |
| 2580 | |
| 2581 | u8 itbCoef7bw[3][14] = { |
| 2582 | {0x00}, /* 20.5MHz XTal */ |
| 2583 | {0x30, 0xB1, 0x29, 0x9A, 0x28, 0x9C, 0x28, 0xA0, 0x29, |
| 2584 | 0xA2, 0x2B, 0xA6, 0x2B, 0xAD}, /* 24MHz Xtal */ |
| 2585 | {0x00}, /* 41MHz XTal */ |
| 2586 | }; |
| 2587 | |
| 2588 | u8 itbCoef6bw[3][14] = { |
| 2589 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, |
| 2590 | 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 20.5MHz XTal */ |
| 2591 | {0x31, 0xA8, 0x29, 0x9B, 0x27, 0x9C, 0x28, 0x9E, 0x29, |
| 2592 | 0xA4, 0x29, 0xA2, 0x29, 0xA8}, /* 24MHz Xtal */ |
| 2593 | {0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, 0x00, |
| 2594 | 0xCF, 0x00, 0xE6, 0x23, 0xA4}, /* 41MHz XTal */ |
| 2595 | }; |
| 2596 | |
| 2597 | dev_dbg(&priv->i2c->dev, "%s() bandwidth=%u\n", __func__, bandwidth); |
| 2598 | /* Set SLV-T Bank : 0x10 */ |
| 2599 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2600 | |
| 2601 | /* 20.5/41MHz Xtal support is not available |
| 2602 | * on ISDB-T 7MHzBW and 8MHzBW |
| 2603 | */ |
| 2604 | if (priv->xtal != SONY_XTAL_24000 && bandwidth > 6000000) { |
| 2605 | dev_err(&priv->i2c->dev, |
| 2606 | "%s(): bandwidth %d supported only for 24MHz xtal\n", |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2607 | __func__, bandwidth); |
| 2608 | return -EINVAL; |
| 2609 | } |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2610 | |
| 2611 | switch (bandwidth) { |
| 2612 | case 8000000: |
| 2613 | /* TRCG Nominal Rate */ |
| 2614 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2615 | 0x9F, nominalRate8bw[priv->xtal], 5); |
| 2616 | /* Group delay equaliser settings for ASCOT tuners optimized */ |
| 2617 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2618 | 0xA6, itbCoef8bw[priv->xtal], 14); |
| 2619 | |
| 2620 | /* IF freq setting */ |
| 2621 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.75); |
| 2622 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2623 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2624 | data[2] = (u8)(iffreq & 0xff); |
| 2625 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2626 | |
| 2627 | /* System bandwidth setting */ |
| 2628 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x0, 0x7); |
| 2629 | |
| 2630 | /* Demod core latency setting */ |
| 2631 | data[0] = 0x13; |
| 2632 | data[1] = 0xFC; |
| 2633 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2634 | |
| 2635 | /* Acquisition optimization setting */ |
| 2636 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12); |
| 2637 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x03, 0x07); |
| 2638 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15); |
| 2639 | cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x03); |
| 2640 | break; |
| 2641 | case 7000000: |
| 2642 | /* TRCG Nominal Rate */ |
| 2643 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2644 | 0x9F, nominalRate7bw[priv->xtal], 5); |
| 2645 | /* Group delay equaliser settings for ASCOT tuners optimized */ |
| 2646 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2647 | 0xA6, itbCoef7bw[priv->xtal], 14); |
| 2648 | |
| 2649 | /* IF freq setting */ |
| 2650 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 4.15); |
| 2651 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2652 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2653 | data[2] = (u8)(iffreq & 0xff); |
| 2654 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2655 | |
| 2656 | /* System bandwidth setting */ |
| 2657 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x02, 0x7); |
| 2658 | |
| 2659 | /* Demod core latency setting */ |
| 2660 | data[0] = 0x1A; |
| 2661 | data[1] = 0xFA; |
| 2662 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2663 | |
| 2664 | /* Acquisition optimization setting */ |
| 2665 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12); |
| 2666 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x03, 0x07); |
| 2667 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15); |
| 2668 | cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x02); |
| 2669 | break; |
| 2670 | case 6000000: |
| 2671 | /* TRCG Nominal Rate */ |
| 2672 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2673 | 0x9F, nominalRate6bw[priv->xtal], 5); |
| 2674 | /* Group delay equaliser settings for ASCOT tuners optimized */ |
| 2675 | cxd2841er_write_regs(priv, I2C_SLVT, |
| 2676 | 0xA6, itbCoef6bw[priv->xtal], 14); |
| 2677 | |
| 2678 | /* IF freq setting */ |
| 2679 | iffreq = MAKE_IFFREQ_CONFIG_XTAL(priv->xtal, 3.55); |
| 2680 | data[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2681 | data[1] = (u8)((iffreq >> 8) & 0xff); |
| 2682 | data[2] = (u8)(iffreq & 0xff); |
| 2683 | cxd2841er_write_regs(priv, I2C_SLVT, 0xB6, data, 3); |
| 2684 | |
| 2685 | /* System bandwidth setting */ |
| 2686 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd7, 0x04, 0x7); |
| 2687 | |
| 2688 | /* Demod core latency setting */ |
| 2689 | if (priv->xtal == SONY_XTAL_24000) { |
| 2690 | data[0] = 0x1F; |
| 2691 | data[1] = 0x79; |
| 2692 | } else { |
| 2693 | data[0] = 0x1A; |
| 2694 | data[1] = 0xE2; |
| 2695 | } |
| 2696 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2697 | |
| 2698 | /* Acquisition optimization setting */ |
| 2699 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x12); |
| 2700 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x71, 0x07, 0x07); |
| 2701 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15); |
| 2702 | cxd2841er_write_reg(priv, I2C_SLVT, 0xBE, 0x02); |
| 2703 | break; |
| 2704 | default: |
| 2705 | dev_dbg(&priv->i2c->dev, "%s(): invalid bandwidth %d\n", |
| 2706 | __func__, bandwidth); |
| 2707 | return -EINVAL; |
| 2708 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2709 | return 0; |
| 2710 | } |
| 2711 | |
| 2712 | static int cxd2841er_sleep_tc_to_active_c_band(struct cxd2841er_priv *priv, |
| 2713 | u32 bandwidth) |
| 2714 | { |
| 2715 | u8 bw7_8mhz_b10_a6[] = { |
| 2716 | 0x2D, 0xC7, 0x04, 0xF4, 0x07, 0xC5, 0x2A, 0xB8, |
| 2717 | 0x27, 0x9E, 0x27, 0xA4, 0x29, 0xAB }; |
| 2718 | u8 bw6mhz_b10_a6[] = { |
| 2719 | 0x27, 0xA7, 0x28, 0xB3, 0x02, 0xF0, 0x01, 0xE8, |
| 2720 | 0x00, 0xCF, 0x00, 0xE6, 0x23, 0xA4 }; |
| 2721 | u8 b10_b6[3]; |
| 2722 | u32 iffreq; |
| 2723 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 2724 | dev_dbg(&priv->i2c->dev, "%s() bw=%d\n", __func__, bandwidth); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2725 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2726 | switch (bandwidth) { |
| 2727 | case 8000000: |
| 2728 | case 7000000: |
| 2729 | cxd2841er_write_regs( |
| 2730 | priv, I2C_SLVT, 0xa6, |
| 2731 | bw7_8mhz_b10_a6, sizeof(bw7_8mhz_b10_a6)); |
| 2732 | iffreq = MAKE_IFFREQ_CONFIG(4.9); |
| 2733 | break; |
| 2734 | case 6000000: |
| 2735 | cxd2841er_write_regs( |
| 2736 | priv, I2C_SLVT, 0xa6, |
| 2737 | bw6mhz_b10_a6, sizeof(bw6mhz_b10_a6)); |
| 2738 | iffreq = MAKE_IFFREQ_CONFIG(3.7); |
| 2739 | break; |
| 2740 | default: |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 2741 | dev_err(&priv->i2c->dev, "%s(): unsupported bandwidth %d\n", |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2742 | __func__, bandwidth); |
| 2743 | return -EINVAL; |
| 2744 | } |
| 2745 | /* <IF freq setting> */ |
| 2746 | b10_b6[0] = (u8) ((iffreq >> 16) & 0xff); |
| 2747 | b10_b6[1] = (u8)((iffreq >> 8) & 0xff); |
| 2748 | b10_b6[2] = (u8)(iffreq & 0xff); |
| 2749 | cxd2841er_write_regs(priv, I2C_SLVT, 0xb6, b10_b6, sizeof(b10_b6)); |
| 2750 | /* Set SLV-T Bank : 0x11 */ |
| 2751 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); |
| 2752 | switch (bandwidth) { |
| 2753 | case 8000000: |
| 2754 | case 7000000: |
| 2755 | cxd2841er_set_reg_bits( |
| 2756 | priv, I2C_SLVT, 0xa3, 0x00, 0x1f); |
| 2757 | break; |
| 2758 | case 6000000: |
| 2759 | cxd2841er_set_reg_bits( |
| 2760 | priv, I2C_SLVT, 0xa3, 0x14, 0x1f); |
| 2761 | break; |
| 2762 | } |
| 2763 | /* Set SLV-T Bank : 0x40 */ |
| 2764 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 2765 | switch (bandwidth) { |
| 2766 | case 8000000: |
| 2767 | cxd2841er_set_reg_bits( |
| 2768 | priv, I2C_SLVT, 0x26, 0x0b, 0x0f); |
| 2769 | cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x3e); |
| 2770 | break; |
| 2771 | case 7000000: |
| 2772 | cxd2841er_set_reg_bits( |
| 2773 | priv, I2C_SLVT, 0x26, 0x09, 0x0f); |
| 2774 | cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0xd6); |
| 2775 | break; |
| 2776 | case 6000000: |
| 2777 | cxd2841er_set_reg_bits( |
| 2778 | priv, I2C_SLVT, 0x26, 0x08, 0x0f); |
| 2779 | cxd2841er_write_reg(priv, I2C_SLVT, 0x27, 0x6e); |
| 2780 | break; |
| 2781 | } |
| 2782 | return 0; |
| 2783 | } |
| 2784 | |
| 2785 | static int cxd2841er_sleep_tc_to_active_t(struct cxd2841er_priv *priv, |
| 2786 | u32 bandwidth) |
| 2787 | { |
| 2788 | u8 data[2] = { 0x09, 0x54 }; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2789 | u8 data24m[3] = {0xDC, 0x6C, 0x00}; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2790 | |
| 2791 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 2792 | cxd2841er_set_ts_clock_mode(priv, SYS_DVBT); |
| 2793 | /* Set SLV-X Bank : 0x00 */ |
| 2794 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 2795 | /* Set demod mode */ |
| 2796 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x01); |
| 2797 | /* Set SLV-T Bank : 0x00 */ |
| 2798 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 2799 | /* Enable demod clock */ |
| 2800 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); |
| 2801 | /* Disable RF level monitor */ |
| 2802 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 2803 | /* Enable ADC clock */ |
| 2804 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 2805 | /* Enable ADC 1 */ |
| 2806 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2807 | /* Enable ADC 2 & 3 */ |
| 2808 | if (priv->xtal == SONY_XTAL_41000) { |
| 2809 | data[0] = 0x0A; |
| 2810 | data[1] = 0xD4; |
| 2811 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2812 | cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); |
| 2813 | /* Enable ADC 4 */ |
| 2814 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); |
| 2815 | /* Set SLV-T Bank : 0x10 */ |
| 2816 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2817 | /* IFAGC gain settings */ |
| 2818 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f); |
| 2819 | /* Set SLV-T Bank : 0x11 */ |
| 2820 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); |
| 2821 | /* BBAGC TARGET level setting */ |
| 2822 | cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50); |
| 2823 | /* Set SLV-T Bank : 0x10 */ |
| 2824 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2825 | /* ASCOT setting ON */ |
| 2826 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); |
| 2827 | /* Set SLV-T Bank : 0x18 */ |
| 2828 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18); |
| 2829 | /* Pre-RS BER moniter setting */ |
| 2830 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x36, 0x40, 0x07); |
| 2831 | /* FEC Auto Recovery setting */ |
| 2832 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01); |
| 2833 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x01, 0x01); |
| 2834 | /* Set SLV-T Bank : 0x00 */ |
| 2835 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 2836 | /* TSIF setting */ |
| 2837 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01); |
| 2838 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01); |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 2839 | |
| 2840 | if (priv->xtal == SONY_XTAL_24000) { |
| 2841 | /* Set SLV-T Bank : 0x10 */ |
| 2842 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2843 | cxd2841er_write_reg(priv, I2C_SLVT, 0xBF, 0x60); |
| 2844 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x18); |
| 2845 | cxd2841er_write_regs(priv, I2C_SLVT, 0x24, data24m, 3); |
| 2846 | } |
| 2847 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2848 | cxd2841er_sleep_tc_to_active_t_band(priv, bandwidth); |
| 2849 | /* Set SLV-T Bank : 0x00 */ |
| 2850 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 2851 | /* Disable HiZ Setting 1 */ |
| 2852 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); |
| 2853 | /* Disable HiZ Setting 2 */ |
| 2854 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); |
| 2855 | priv->state = STATE_ACTIVE_TC; |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
| 2859 | static int cxd2841er_sleep_tc_to_active_t2(struct cxd2841er_priv *priv, |
| 2860 | u32 bandwidth) |
| 2861 | { |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2862 | u8 data[MAX_WRITE_REGSIZE]; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2863 | |
| 2864 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 2865 | cxd2841er_set_ts_clock_mode(priv, SYS_DVBT2); |
| 2866 | /* Set SLV-X Bank : 0x00 */ |
| 2867 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 2868 | /* Set demod mode */ |
| 2869 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x02); |
| 2870 | /* Set SLV-T Bank : 0x00 */ |
| 2871 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 2872 | /* Enable demod clock */ |
| 2873 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); |
| 2874 | /* Disable RF level monitor */ |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2875 | cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x00); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2876 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 2877 | /* Enable ADC clock */ |
| 2878 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 2879 | /* Enable ADC 1 */ |
| 2880 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2881 | |
| 2882 | if (priv->xtal == SONY_XTAL_41000) { |
| 2883 | data[0] = 0x0A; |
| 2884 | data[1] = 0xD4; |
| 2885 | } else { |
| 2886 | data[0] = 0x09; |
| 2887 | data[1] = 0x54; |
| 2888 | } |
| 2889 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2890 | cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); |
| 2891 | /* Enable ADC 4 */ |
| 2892 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); |
| 2893 | /* Set SLV-T Bank : 0x10 */ |
| 2894 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2895 | /* IFAGC gain settings */ |
| 2896 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x0c, 0x1f); |
| 2897 | /* Set SLV-T Bank : 0x11 */ |
| 2898 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); |
| 2899 | /* BBAGC TARGET level setting */ |
| 2900 | cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x50); |
| 2901 | /* Set SLV-T Bank : 0x10 */ |
| 2902 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 2903 | /* ASCOT setting ON */ |
| 2904 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); |
| 2905 | /* Set SLV-T Bank : 0x20 */ |
| 2906 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 2907 | /* Acquisition optimization setting */ |
| 2908 | cxd2841er_write_reg(priv, I2C_SLVT, 0x8b, 0x3c); |
| 2909 | /* Set SLV-T Bank : 0x2b */ |
| 2910 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); |
| 2911 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x76, 0x20, 0x70); |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2912 | /* Set SLV-T Bank : 0x23 */ |
| 2913 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x23); |
| 2914 | /* L1 Control setting */ |
| 2915 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xE6, 0x00, 0x03); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 2916 | /* Set SLV-T Bank : 0x00 */ |
| 2917 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 2918 | /* TSIF setting */ |
| 2919 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01); |
| 2920 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01); |
| 2921 | /* DVB-T2 initial setting */ |
| 2922 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x13); |
| 2923 | cxd2841er_write_reg(priv, I2C_SLVT, 0x83, 0x10); |
| 2924 | cxd2841er_write_reg(priv, I2C_SLVT, 0x86, 0x34); |
| 2925 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9e, 0x09, 0x0f); |
| 2926 | cxd2841er_write_reg(priv, I2C_SLVT, 0x9f, 0xd8); |
| 2927 | /* Set SLV-T Bank : 0x2a */ |
| 2928 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2a); |
| 2929 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x38, 0x04, 0x0f); |
| 2930 | /* Set SLV-T Bank : 0x2b */ |
| 2931 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2b); |
| 2932 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x11, 0x20, 0x3f); |
| 2933 | |
Abylay Ospan | 6c77161 | 2016-05-16 11:43:25 -0300 | [diff] [blame] | 2934 | /* 24MHz Xtal setting */ |
| 2935 | if (priv->xtal == SONY_XTAL_24000) { |
| 2936 | /* Set SLV-T Bank : 0x11 */ |
| 2937 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); |
| 2938 | data[0] = 0xEB; |
| 2939 | data[1] = 0x03; |
| 2940 | data[2] = 0x3B; |
| 2941 | cxd2841er_write_regs(priv, I2C_SLVT, 0x33, data, 3); |
| 2942 | |
| 2943 | /* Set SLV-T Bank : 0x20 */ |
| 2944 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x20); |
| 2945 | data[0] = 0x5E; |
| 2946 | data[1] = 0x5E; |
| 2947 | data[2] = 0x47; |
| 2948 | cxd2841er_write_regs(priv, I2C_SLVT, 0x95, data, 3); |
| 2949 | |
| 2950 | cxd2841er_write_reg(priv, I2C_SLVT, 0x99, 0x18); |
| 2951 | |
| 2952 | data[0] = 0x3F; |
| 2953 | data[1] = 0xFF; |
| 2954 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD9, data, 2); |
| 2955 | |
| 2956 | /* Set SLV-T Bank : 0x24 */ |
| 2957 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x24); |
| 2958 | data[0] = 0x0B; |
| 2959 | data[1] = 0x72; |
| 2960 | cxd2841er_write_regs(priv, I2C_SLVT, 0x34, data, 2); |
| 2961 | |
| 2962 | data[0] = 0x93; |
| 2963 | data[1] = 0xF3; |
| 2964 | data[2] = 0x00; |
| 2965 | cxd2841er_write_regs(priv, I2C_SLVT, 0xD2, data, 3); |
| 2966 | |
| 2967 | data[0] = 0x05; |
| 2968 | data[1] = 0xB8; |
| 2969 | data[2] = 0xD8; |
| 2970 | cxd2841er_write_regs(priv, I2C_SLVT, 0xDD, data, 3); |
| 2971 | |
| 2972 | cxd2841er_write_reg(priv, I2C_SLVT, 0xE0, 0x00); |
| 2973 | |
| 2974 | /* Set SLV-T Bank : 0x25 */ |
| 2975 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x25); |
| 2976 | cxd2841er_write_reg(priv, I2C_SLVT, 0xED, 0x60); |
| 2977 | |
| 2978 | /* Set SLV-T Bank : 0x27 */ |
| 2979 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x27); |
| 2980 | cxd2841er_write_reg(priv, I2C_SLVT, 0xFA, 0x34); |
| 2981 | |
| 2982 | /* Set SLV-T Bank : 0x2B */ |
| 2983 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2B); |
| 2984 | cxd2841er_write_reg(priv, I2C_SLVT, 0x4B, 0x2F); |
| 2985 | cxd2841er_write_reg(priv, I2C_SLVT, 0x9E, 0x0E); |
| 2986 | |
| 2987 | /* Set SLV-T Bank : 0x2D */ |
| 2988 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x2D); |
| 2989 | data[0] = 0x89; |
| 2990 | data[1] = 0x89; |
| 2991 | cxd2841er_write_regs(priv, I2C_SLVT, 0x24, data, 2); |
| 2992 | |
| 2993 | /* Set SLV-T Bank : 0x5E */ |
| 2994 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x5E); |
| 2995 | data[0] = 0x24; |
| 2996 | data[1] = 0x95; |
| 2997 | cxd2841er_write_regs(priv, I2C_SLVT, 0x8C, data, 2); |
| 2998 | } |
| 2999 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3000 | cxd2841er_sleep_tc_to_active_t2_band(priv, bandwidth); |
| 3001 | |
| 3002 | /* Set SLV-T Bank : 0x00 */ |
| 3003 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3004 | /* Disable HiZ Setting 1 */ |
| 3005 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); |
| 3006 | /* Disable HiZ Setting 2 */ |
| 3007 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); |
| 3008 | priv->state = STATE_ACTIVE_TC; |
| 3009 | return 0; |
| 3010 | } |
| 3011 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3012 | /* ISDB-Tb part */ |
| 3013 | static int cxd2841er_sleep_tc_to_active_i(struct cxd2841er_priv *priv, |
| 3014 | u32 bandwidth) |
| 3015 | { |
| 3016 | u8 data[2] = { 0x09, 0x54 }; |
| 3017 | u8 data24m[2] = {0x60, 0x00}; |
| 3018 | u8 data24m2[3] = {0xB7, 0x1B, 0x00}; |
| 3019 | |
| 3020 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3021 | cxd2841er_set_ts_clock_mode(priv, SYS_DVBT); |
| 3022 | /* Set SLV-X Bank : 0x00 */ |
| 3023 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 3024 | /* Set demod mode */ |
| 3025 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x06); |
| 3026 | /* Set SLV-T Bank : 0x00 */ |
| 3027 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3028 | /* Enable demod clock */ |
| 3029 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); |
| 3030 | /* Enable RF level monitor */ |
| 3031 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x01); |
| 3032 | cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x01); |
| 3033 | /* Enable ADC clock */ |
| 3034 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 3035 | /* Enable ADC 1 */ |
| 3036 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); |
| 3037 | /* xtal freq 20.5MHz or 24M */ |
| 3038 | cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); |
| 3039 | /* Enable ADC 4 */ |
| 3040 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); |
| 3041 | /* ASCOT setting ON */ |
| 3042 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); |
| 3043 | /* FEC Auto Recovery setting */ |
| 3044 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x30, 0x01, 0x01); |
| 3045 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x31, 0x00, 0x01); |
| 3046 | /* ISDB-T initial setting */ |
| 3047 | /* Set SLV-T Bank : 0x00 */ |
| 3048 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3049 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x00, 0x01); |
| 3050 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x00, 0x01); |
| 3051 | /* Set SLV-T Bank : 0x10 */ |
| 3052 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 3053 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x69, 0x04, 0x07); |
| 3054 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x6B, 0x03, 0x07); |
| 3055 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x9D, 0x50, 0xFF); |
| 3056 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xD3, 0x06, 0x1F); |
| 3057 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xED, 0x00, 0x01); |
| 3058 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xE2, 0xCE, 0x80); |
| 3059 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xF2, 0x13, 0x10); |
| 3060 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xDE, 0x2E, 0x3F); |
| 3061 | /* Set SLV-T Bank : 0x15 */ |
| 3062 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x15); |
| 3063 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xDE, 0x02, 0x03); |
| 3064 | /* Set SLV-T Bank : 0x1E */ |
| 3065 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x1E); |
| 3066 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x73, 0x68, 0xFF); |
| 3067 | /* Set SLV-T Bank : 0x63 */ |
| 3068 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x63); |
| 3069 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0x81, 0x00, 0x01); |
| 3070 | |
| 3071 | /* for xtal 24MHz */ |
| 3072 | /* Set SLV-T Bank : 0x10 */ |
| 3073 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 3074 | cxd2841er_write_regs(priv, I2C_SLVT, 0xBF, data24m, 2); |
| 3075 | /* Set SLV-T Bank : 0x60 */ |
| 3076 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x60); |
| 3077 | cxd2841er_write_regs(priv, I2C_SLVT, 0xA8, data24m2, 3); |
| 3078 | |
| 3079 | cxd2841er_sleep_tc_to_active_i_band(priv, bandwidth); |
| 3080 | /* Set SLV-T Bank : 0x00 */ |
| 3081 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3082 | /* Disable HiZ Setting 1 */ |
| 3083 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); |
| 3084 | /* Disable HiZ Setting 2 */ |
| 3085 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); |
| 3086 | priv->state = STATE_ACTIVE_TC; |
| 3087 | return 0; |
| 3088 | } |
| 3089 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3090 | static int cxd2841er_sleep_tc_to_active_c(struct cxd2841er_priv *priv, |
| 3091 | u32 bandwidth) |
| 3092 | { |
| 3093 | u8 data[2] = { 0x09, 0x54 }; |
| 3094 | |
| 3095 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3096 | cxd2841er_set_ts_clock_mode(priv, SYS_DVBC_ANNEX_A); |
| 3097 | /* Set SLV-X Bank : 0x00 */ |
| 3098 | cxd2841er_write_reg(priv, I2C_SLVX, 0x00, 0x00); |
| 3099 | /* Set demod mode */ |
| 3100 | cxd2841er_write_reg(priv, I2C_SLVX, 0x17, 0x04); |
| 3101 | /* Set SLV-T Bank : 0x00 */ |
| 3102 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3103 | /* Enable demod clock */ |
| 3104 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2c, 0x01); |
| 3105 | /* Disable RF level monitor */ |
Abylay Ospan | 4a86bc1 | 2016-07-19 00:10:20 -0300 | [diff] [blame^] | 3106 | cxd2841er_write_reg(priv, I2C_SLVT, 0x59, 0x00); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3107 | cxd2841er_write_reg(priv, I2C_SLVT, 0x2f, 0x00); |
| 3108 | /* Enable ADC clock */ |
| 3109 | cxd2841er_write_reg(priv, I2C_SLVT, 0x30, 0x00); |
| 3110 | /* Enable ADC 1 */ |
| 3111 | cxd2841er_write_reg(priv, I2C_SLVT, 0x41, 0x1a); |
| 3112 | /* xtal freq 20.5MHz */ |
| 3113 | cxd2841er_write_regs(priv, I2C_SLVT, 0x43, data, 2); |
| 3114 | /* Enable ADC 4 */ |
| 3115 | cxd2841er_write_reg(priv, I2C_SLVX, 0x18, 0x00); |
| 3116 | /* Set SLV-T Bank : 0x10 */ |
| 3117 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 3118 | /* IFAGC gain settings */ |
| 3119 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xd2, 0x09, 0x1f); |
| 3120 | /* Set SLV-T Bank : 0x11 */ |
| 3121 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x11); |
| 3122 | /* BBAGC TARGET level setting */ |
| 3123 | cxd2841er_write_reg(priv, I2C_SLVT, 0x6a, 0x48); |
| 3124 | /* Set SLV-T Bank : 0x10 */ |
| 3125 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 3126 | /* ASCOT setting ON */ |
| 3127 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xa5, 0x01, 0x01); |
| 3128 | /* Set SLV-T Bank : 0x40 */ |
| 3129 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x40); |
| 3130 | /* Demod setting */ |
| 3131 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc3, 0x00, 0x04); |
| 3132 | /* Set SLV-T Bank : 0x00 */ |
| 3133 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3134 | /* TSIF setting */ |
| 3135 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xce, 0x01, 0x01); |
| 3136 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcf, 0x01, 0x01); |
| 3137 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3138 | cxd2841er_sleep_tc_to_active_c_band(priv, bandwidth); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3139 | /* Set SLV-T Bank : 0x00 */ |
| 3140 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3141 | /* Disable HiZ Setting 1 */ |
| 3142 | cxd2841er_write_reg(priv, I2C_SLVT, 0x80, 0x28); |
| 3143 | /* Disable HiZ Setting 2 */ |
| 3144 | cxd2841er_write_reg(priv, I2C_SLVT, 0x81, 0x00); |
| 3145 | priv->state = STATE_ACTIVE_TC; |
| 3146 | return 0; |
| 3147 | } |
| 3148 | |
Mauro Carvalho Chehab | 7e3e68b | 2016-02-04 12:58:30 -0200 | [diff] [blame] | 3149 | static int cxd2841er_get_frontend(struct dvb_frontend *fe, |
| 3150 | struct dtv_frontend_properties *p) |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3151 | { |
| 3152 | enum fe_status status = 0; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3153 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3154 | |
| 3155 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3156 | if (priv->state == STATE_ACTIVE_S) |
| 3157 | cxd2841er_read_status_s(fe, &status); |
| 3158 | else if (priv->state == STATE_ACTIVE_TC) |
| 3159 | cxd2841er_read_status_tc(fe, &status); |
| 3160 | |
Mauro Carvalho Chehab | 5fda1b6 | 2016-06-30 19:41:45 -0300 | [diff] [blame] | 3161 | cxd2841er_read_signal_strength(fe); |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3162 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3163 | if (status & FE_HAS_LOCK) { |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 3164 | cxd2841er_read_snr(fe); |
| 3165 | cxd2841er_read_ucblocks(fe); |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3166 | |
Mauro Carvalho Chehab | f1b2662 | 2016-07-01 11:03:13 -0300 | [diff] [blame] | 3167 | cxd2841er_read_ber(fe); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3168 | } else { |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3169 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3170 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3171 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 3172 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3173 | } |
| 3174 | return 0; |
| 3175 | } |
| 3176 | |
| 3177 | static int cxd2841er_set_frontend_s(struct dvb_frontend *fe) |
| 3178 | { |
| 3179 | int ret = 0, i, timeout, carr_offset; |
| 3180 | enum fe_status status; |
| 3181 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3182 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 3183 | u32 symbol_rate = p->symbol_rate/1000; |
| 3184 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3185 | dev_dbg(&priv->i2c->dev, "%s(): %s frequency=%d symbol_rate=%d xtal=%d\n", |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3186 | __func__, |
| 3187 | (p->delivery_system == SYS_DVBS ? "DVB-S" : "DVB-S2"), |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3188 | p->frequency, symbol_rate, priv->xtal); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3189 | switch (priv->state) { |
| 3190 | case STATE_SLEEP_S: |
| 3191 | ret = cxd2841er_sleep_s_to_active_s( |
| 3192 | priv, p->delivery_system, symbol_rate); |
| 3193 | break; |
| 3194 | case STATE_ACTIVE_S: |
| 3195 | ret = cxd2841er_retune_active(priv, p); |
| 3196 | break; |
| 3197 | default: |
| 3198 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 3199 | __func__, priv->state); |
| 3200 | ret = -EINVAL; |
| 3201 | goto done; |
| 3202 | } |
| 3203 | if (ret) { |
| 3204 | dev_dbg(&priv->i2c->dev, "%s(): tune failed\n", __func__); |
| 3205 | goto done; |
| 3206 | } |
| 3207 | if (fe->ops.i2c_gate_ctrl) |
| 3208 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 3209 | if (fe->ops.tuner_ops.set_params) |
| 3210 | fe->ops.tuner_ops.set_params(fe); |
| 3211 | if (fe->ops.i2c_gate_ctrl) |
| 3212 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 3213 | cxd2841er_tune_done(priv); |
| 3214 | timeout = ((3000000 + (symbol_rate - 1)) / symbol_rate) + 150; |
| 3215 | for (i = 0; i < timeout / CXD2841ER_DVBS_POLLING_INVL; i++) { |
| 3216 | usleep_range(CXD2841ER_DVBS_POLLING_INVL*1000, |
| 3217 | (CXD2841ER_DVBS_POLLING_INVL + 2) * 1000); |
| 3218 | cxd2841er_read_status_s(fe, &status); |
| 3219 | if (status & FE_HAS_LOCK) |
| 3220 | break; |
| 3221 | } |
| 3222 | if (status & FE_HAS_LOCK) { |
| 3223 | if (cxd2841er_get_carrier_offset_s_s2( |
| 3224 | priv, &carr_offset)) { |
| 3225 | ret = -EINVAL; |
| 3226 | goto done; |
| 3227 | } |
| 3228 | dev_dbg(&priv->i2c->dev, "%s(): carrier_offset=%d\n", |
| 3229 | __func__, carr_offset); |
| 3230 | } |
| 3231 | done: |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3232 | /* Reset stats */ |
| 3233 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 3234 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 3235 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 3236 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 3237 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3238 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3239 | return ret; |
| 3240 | } |
| 3241 | |
| 3242 | static int cxd2841er_set_frontend_tc(struct dvb_frontend *fe) |
| 3243 | { |
| 3244 | int ret = 0, timeout; |
| 3245 | enum fe_status status; |
| 3246 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3247 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 3248 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3249 | dev_dbg(&priv->i2c->dev, "%s() delivery_system=%d bandwidth_hz=%d\n", |
| 3250 | __func__, p->delivery_system, p->bandwidth_hz); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3251 | if (p->delivery_system == SYS_DVBT) { |
| 3252 | priv->system = SYS_DVBT; |
| 3253 | switch (priv->state) { |
| 3254 | case STATE_SLEEP_TC: |
| 3255 | ret = cxd2841er_sleep_tc_to_active_t( |
| 3256 | priv, p->bandwidth_hz); |
| 3257 | break; |
| 3258 | case STATE_ACTIVE_TC: |
| 3259 | ret = cxd2841er_retune_active(priv, p); |
| 3260 | break; |
| 3261 | default: |
| 3262 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 3263 | __func__, priv->state); |
| 3264 | ret = -EINVAL; |
| 3265 | } |
| 3266 | } else if (p->delivery_system == SYS_DVBT2) { |
| 3267 | priv->system = SYS_DVBT2; |
| 3268 | cxd2841er_dvbt2_set_plp_config(priv, |
| 3269 | (int)(p->stream_id > 255), p->stream_id); |
| 3270 | cxd2841er_dvbt2_set_profile(priv, DVBT2_PROFILE_BASE); |
| 3271 | switch (priv->state) { |
| 3272 | case STATE_SLEEP_TC: |
| 3273 | ret = cxd2841er_sleep_tc_to_active_t2(priv, |
| 3274 | p->bandwidth_hz); |
| 3275 | break; |
| 3276 | case STATE_ACTIVE_TC: |
| 3277 | ret = cxd2841er_retune_active(priv, p); |
| 3278 | break; |
| 3279 | default: |
| 3280 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 3281 | __func__, priv->state); |
| 3282 | ret = -EINVAL; |
| 3283 | } |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3284 | } else if (p->delivery_system == SYS_ISDBT) { |
| 3285 | priv->system = SYS_ISDBT; |
| 3286 | switch (priv->state) { |
| 3287 | case STATE_SLEEP_TC: |
| 3288 | ret = cxd2841er_sleep_tc_to_active_i( |
| 3289 | priv, p->bandwidth_hz); |
| 3290 | break; |
| 3291 | case STATE_ACTIVE_TC: |
| 3292 | ret = cxd2841er_retune_active(priv, p); |
| 3293 | break; |
| 3294 | default: |
| 3295 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 3296 | __func__, priv->state); |
| 3297 | ret = -EINVAL; |
| 3298 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3299 | } else if (p->delivery_system == SYS_DVBC_ANNEX_A || |
| 3300 | p->delivery_system == SYS_DVBC_ANNEX_C) { |
| 3301 | priv->system = SYS_DVBC_ANNEX_A; |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3302 | /* correct bandwidth */ |
| 3303 | if (p->bandwidth_hz != 6000000 && |
| 3304 | p->bandwidth_hz != 7000000 && |
| 3305 | p->bandwidth_hz != 8000000) { |
| 3306 | p->bandwidth_hz = 8000000; |
| 3307 | dev_dbg(&priv->i2c->dev, "%s(): forcing bandwidth to %d\n", |
| 3308 | __func__, p->bandwidth_hz); |
| 3309 | } |
| 3310 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3311 | switch (priv->state) { |
| 3312 | case STATE_SLEEP_TC: |
| 3313 | ret = cxd2841er_sleep_tc_to_active_c( |
| 3314 | priv, p->bandwidth_hz); |
| 3315 | break; |
| 3316 | case STATE_ACTIVE_TC: |
| 3317 | ret = cxd2841er_retune_active(priv, p); |
| 3318 | break; |
| 3319 | default: |
| 3320 | dev_dbg(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 3321 | __func__, priv->state); |
| 3322 | ret = -EINVAL; |
| 3323 | } |
| 3324 | } else { |
| 3325 | dev_dbg(&priv->i2c->dev, |
| 3326 | "%s(): invalid delivery system %d\n", |
| 3327 | __func__, p->delivery_system); |
| 3328 | ret = -EINVAL; |
| 3329 | } |
| 3330 | if (ret) |
| 3331 | goto done; |
| 3332 | if (fe->ops.i2c_gate_ctrl) |
| 3333 | fe->ops.i2c_gate_ctrl(fe, 1); |
| 3334 | if (fe->ops.tuner_ops.set_params) |
| 3335 | fe->ops.tuner_ops.set_params(fe); |
| 3336 | if (fe->ops.i2c_gate_ctrl) |
| 3337 | fe->ops.i2c_gate_ctrl(fe, 0); |
| 3338 | cxd2841er_tune_done(priv); |
| 3339 | timeout = 2500; |
| 3340 | while (timeout > 0) { |
| 3341 | ret = cxd2841er_read_status_tc(fe, &status); |
| 3342 | if (ret) |
| 3343 | goto done; |
| 3344 | if (status & FE_HAS_LOCK) |
| 3345 | break; |
| 3346 | msleep(20); |
| 3347 | timeout -= 20; |
| 3348 | } |
| 3349 | if (timeout < 0) |
| 3350 | dev_dbg(&priv->i2c->dev, |
| 3351 | "%s(): LOCK wait timeout\n", __func__); |
| 3352 | done: |
| 3353 | return ret; |
| 3354 | } |
| 3355 | |
| 3356 | static int cxd2841er_tune_s(struct dvb_frontend *fe, |
| 3357 | bool re_tune, |
| 3358 | unsigned int mode_flags, |
| 3359 | unsigned int *delay, |
| 3360 | enum fe_status *status) |
| 3361 | { |
| 3362 | int ret, carrier_offset; |
| 3363 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3364 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 3365 | |
| 3366 | dev_dbg(&priv->i2c->dev, "%s() re_tune=%d\n", __func__, re_tune); |
| 3367 | if (re_tune) { |
| 3368 | ret = cxd2841er_set_frontend_s(fe); |
| 3369 | if (ret) |
| 3370 | return ret; |
| 3371 | cxd2841er_read_status_s(fe, status); |
| 3372 | if (*status & FE_HAS_LOCK) { |
| 3373 | if (cxd2841er_get_carrier_offset_s_s2( |
| 3374 | priv, &carrier_offset)) |
| 3375 | return -EINVAL; |
| 3376 | p->frequency += carrier_offset; |
| 3377 | ret = cxd2841er_set_frontend_s(fe); |
| 3378 | if (ret) |
| 3379 | return ret; |
| 3380 | } |
| 3381 | } |
| 3382 | *delay = HZ / 5; |
| 3383 | return cxd2841er_read_status_s(fe, status); |
| 3384 | } |
| 3385 | |
| 3386 | static int cxd2841er_tune_tc(struct dvb_frontend *fe, |
| 3387 | bool re_tune, |
| 3388 | unsigned int mode_flags, |
| 3389 | unsigned int *delay, |
| 3390 | enum fe_status *status) |
| 3391 | { |
| 3392 | int ret, carrier_offset; |
| 3393 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3394 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 3395 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3396 | dev_dbg(&priv->i2c->dev, "%s(): re_tune %d bandwidth=%d\n", __func__, |
| 3397 | re_tune, p->bandwidth_hz); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3398 | if (re_tune) { |
| 3399 | ret = cxd2841er_set_frontend_tc(fe); |
| 3400 | if (ret) |
| 3401 | return ret; |
| 3402 | cxd2841er_read_status_tc(fe, status); |
| 3403 | if (*status & FE_HAS_LOCK) { |
| 3404 | switch (priv->system) { |
Mauro Carvalho Chehab | 76344a3f | 2016-05-04 18:25:38 -0300 | [diff] [blame] | 3405 | case SYS_ISDBT: |
| 3406 | ret = cxd2841er_get_carrier_offset_i( |
| 3407 | priv, p->bandwidth_hz, |
| 3408 | &carrier_offset); |
Arnd Bergmann | bb9bd87 | 2016-08-03 13:46:21 -0700 | [diff] [blame] | 3409 | if (ret) |
| 3410 | return ret; |
Mauro Carvalho Chehab | 76344a3f | 2016-05-04 18:25:38 -0300 | [diff] [blame] | 3411 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3412 | case SYS_DVBT: |
Abylay Ospan | c5ea46d | 2016-04-02 23:31:50 -0300 | [diff] [blame] | 3413 | ret = cxd2841er_get_carrier_offset_t( |
| 3414 | priv, p->bandwidth_hz, |
| 3415 | &carrier_offset); |
Arnd Bergmann | bb9bd87 | 2016-08-03 13:46:21 -0700 | [diff] [blame] | 3416 | if (ret) |
| 3417 | return ret; |
Abylay Ospan | c5ea46d | 2016-04-02 23:31:50 -0300 | [diff] [blame] | 3418 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3419 | case SYS_DVBT2: |
| 3420 | ret = cxd2841er_get_carrier_offset_t2( |
| 3421 | priv, p->bandwidth_hz, |
| 3422 | &carrier_offset); |
Arnd Bergmann | bb9bd87 | 2016-08-03 13:46:21 -0700 | [diff] [blame] | 3423 | if (ret) |
| 3424 | return ret; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3425 | break; |
| 3426 | case SYS_DVBC_ANNEX_A: |
| 3427 | ret = cxd2841er_get_carrier_offset_c( |
| 3428 | priv, &carrier_offset); |
Arnd Bergmann | bb9bd87 | 2016-08-03 13:46:21 -0700 | [diff] [blame] | 3429 | if (ret) |
| 3430 | return ret; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3431 | break; |
| 3432 | default: |
| 3433 | dev_dbg(&priv->i2c->dev, |
| 3434 | "%s(): invalid delivery system %d\n", |
| 3435 | __func__, priv->system); |
| 3436 | return -EINVAL; |
| 3437 | } |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3438 | dev_dbg(&priv->i2c->dev, "%s(): carrier offset %d\n", |
| 3439 | __func__, carrier_offset); |
| 3440 | p->frequency += carrier_offset; |
| 3441 | ret = cxd2841er_set_frontend_tc(fe); |
| 3442 | if (ret) |
| 3443 | return ret; |
| 3444 | } |
| 3445 | } |
| 3446 | *delay = HZ / 5; |
| 3447 | return cxd2841er_read_status_tc(fe, status); |
| 3448 | } |
| 3449 | |
| 3450 | static int cxd2841er_sleep_s(struct dvb_frontend *fe) |
| 3451 | { |
| 3452 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3453 | |
| 3454 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3455 | cxd2841er_active_s_to_sleep_s(fe->demodulator_priv); |
| 3456 | cxd2841er_sleep_s_to_shutdown(fe->demodulator_priv); |
| 3457 | return 0; |
| 3458 | } |
| 3459 | |
| 3460 | static int cxd2841er_sleep_tc(struct dvb_frontend *fe) |
| 3461 | { |
| 3462 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3463 | |
| 3464 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3465 | if (priv->state == STATE_ACTIVE_TC) { |
| 3466 | switch (priv->system) { |
| 3467 | case SYS_DVBT: |
| 3468 | cxd2841er_active_t_to_sleep_tc(priv); |
| 3469 | break; |
| 3470 | case SYS_DVBT2: |
| 3471 | cxd2841er_active_t2_to_sleep_tc(priv); |
| 3472 | break; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3473 | case SYS_ISDBT: |
| 3474 | cxd2841er_active_i_to_sleep_tc(priv); |
| 3475 | break; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3476 | case SYS_DVBC_ANNEX_A: |
| 3477 | cxd2841er_active_c_to_sleep_tc(priv); |
| 3478 | break; |
| 3479 | default: |
| 3480 | dev_warn(&priv->i2c->dev, |
| 3481 | "%s(): unknown delivery system %d\n", |
| 3482 | __func__, priv->system); |
| 3483 | } |
| 3484 | } |
| 3485 | if (priv->state != STATE_SLEEP_TC) { |
| 3486 | dev_err(&priv->i2c->dev, "%s(): invalid state %d\n", |
| 3487 | __func__, priv->state); |
| 3488 | return -EINVAL; |
| 3489 | } |
| 3490 | cxd2841er_sleep_tc_to_shutdown(priv); |
| 3491 | return 0; |
| 3492 | } |
| 3493 | |
| 3494 | static int cxd2841er_send_burst(struct dvb_frontend *fe, |
| 3495 | enum fe_sec_mini_cmd burst) |
| 3496 | { |
| 3497 | u8 data; |
| 3498 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3499 | |
| 3500 | dev_dbg(&priv->i2c->dev, "%s(): burst mode %s\n", __func__, |
| 3501 | (burst == SEC_MINI_A ? "A" : "B")); |
| 3502 | if (priv->state != STATE_SLEEP_S && |
| 3503 | priv->state != STATE_ACTIVE_S) { |
| 3504 | dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 3505 | __func__, priv->state); |
| 3506 | return -EINVAL; |
| 3507 | } |
| 3508 | data = (burst == SEC_MINI_A ? 0 : 1); |
| 3509 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb); |
| 3510 | cxd2841er_write_reg(priv, I2C_SLVT, 0x34, 0x01); |
| 3511 | cxd2841er_write_reg(priv, I2C_SLVT, 0x35, data); |
| 3512 | return 0; |
| 3513 | } |
| 3514 | |
| 3515 | static int cxd2841er_set_tone(struct dvb_frontend *fe, |
| 3516 | enum fe_sec_tone_mode tone) |
| 3517 | { |
| 3518 | u8 data; |
| 3519 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3520 | |
| 3521 | dev_dbg(&priv->i2c->dev, "%s(): tone %s\n", __func__, |
| 3522 | (tone == SEC_TONE_ON ? "On" : "Off")); |
| 3523 | if (priv->state != STATE_SLEEP_S && |
| 3524 | priv->state != STATE_ACTIVE_S) { |
| 3525 | dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 3526 | __func__, priv->state); |
| 3527 | return -EINVAL; |
| 3528 | } |
| 3529 | data = (tone == SEC_TONE_ON ? 1 : 0); |
| 3530 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb); |
| 3531 | cxd2841er_write_reg(priv, I2C_SLVT, 0x36, data); |
| 3532 | return 0; |
| 3533 | } |
| 3534 | |
| 3535 | static int cxd2841er_send_diseqc_msg(struct dvb_frontend *fe, |
| 3536 | struct dvb_diseqc_master_cmd *cmd) |
| 3537 | { |
| 3538 | int i; |
| 3539 | u8 data[12]; |
| 3540 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3541 | |
| 3542 | if (priv->state != STATE_SLEEP_S && |
| 3543 | priv->state != STATE_ACTIVE_S) { |
| 3544 | dev_err(&priv->i2c->dev, "%s(): invalid demod state %d\n", |
| 3545 | __func__, priv->state); |
| 3546 | return -EINVAL; |
| 3547 | } |
| 3548 | dev_dbg(&priv->i2c->dev, |
| 3549 | "%s(): cmd->len %d\n", __func__, cmd->msg_len); |
| 3550 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xbb); |
| 3551 | /* DiDEqC enable */ |
| 3552 | cxd2841er_write_reg(priv, I2C_SLVT, 0x33, 0x01); |
| 3553 | /* cmd1 length & data */ |
| 3554 | cxd2841er_write_reg(priv, I2C_SLVT, 0x3d, cmd->msg_len); |
| 3555 | memset(data, 0, sizeof(data)); |
| 3556 | for (i = 0; i < cmd->msg_len && i < sizeof(data); i++) |
| 3557 | data[i] = cmd->msg[i]; |
| 3558 | cxd2841er_write_regs(priv, I2C_SLVT, 0x3e, data, sizeof(data)); |
| 3559 | /* repeat count for cmd1 */ |
| 3560 | cxd2841er_write_reg(priv, I2C_SLVT, 0x37, 1); |
| 3561 | /* repeat count for cmd2: always 0 */ |
| 3562 | cxd2841er_write_reg(priv, I2C_SLVT, 0x38, 0); |
| 3563 | /* start transmit */ |
| 3564 | cxd2841er_write_reg(priv, I2C_SLVT, 0x32, 0x01); |
| 3565 | /* wait for 1 sec timeout */ |
| 3566 | for (i = 0; i < 50; i++) { |
| 3567 | cxd2841er_read_reg(priv, I2C_SLVT, 0x10, data); |
| 3568 | if (!data[0]) { |
| 3569 | dev_dbg(&priv->i2c->dev, |
| 3570 | "%s(): DiSEqC cmd has been sent\n", __func__); |
| 3571 | return 0; |
| 3572 | } |
| 3573 | msleep(20); |
| 3574 | } |
| 3575 | dev_dbg(&priv->i2c->dev, |
| 3576 | "%s(): DiSEqC cmd transmit timeout\n", __func__); |
| 3577 | return -ETIMEDOUT; |
| 3578 | } |
| 3579 | |
| 3580 | static void cxd2841er_release(struct dvb_frontend *fe) |
| 3581 | { |
| 3582 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3583 | |
| 3584 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3585 | kfree(priv); |
| 3586 | } |
| 3587 | |
| 3588 | static int cxd2841er_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 3589 | { |
| 3590 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3591 | |
| 3592 | dev_dbg(&priv->i2c->dev, "%s(): enable=%d\n", __func__, enable); |
| 3593 | cxd2841er_set_reg_bits( |
| 3594 | priv, I2C_SLVX, 0x8, (enable ? 0x01 : 0x00), 0x01); |
| 3595 | return 0; |
| 3596 | } |
| 3597 | |
| 3598 | static enum dvbfe_algo cxd2841er_get_algo(struct dvb_frontend *fe) |
| 3599 | { |
| 3600 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3601 | |
| 3602 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3603 | return DVBFE_ALGO_HW; |
| 3604 | } |
| 3605 | |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3606 | static void cxd2841er_init_stats(struct dvb_frontend *fe) |
| 3607 | { |
| 3608 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 3609 | |
| 3610 | p->strength.len = 1; |
| 3611 | p->strength.stat[0].scale = FE_SCALE_RELATIVE; |
| 3612 | p->cnr.len = 1; |
| 3613 | p->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 3614 | p->block_error.len = 1; |
| 3615 | p->block_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
| 3616 | p->post_bit_error.len = 1; |
| 3617 | p->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | 4216be1 | 2016-07-01 11:03:15 -0300 | [diff] [blame] | 3618 | p->post_bit_count.len = 1; |
| 3619 | p->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE; |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3623 | static int cxd2841er_init_s(struct dvb_frontend *fe) |
| 3624 | { |
| 3625 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
| 3626 | |
Abylay Ospan | 30ae330 | 2016-04-05 15:02:37 -0300 | [diff] [blame] | 3627 | /* sanity. force demod to SHUTDOWN state */ |
| 3628 | if (priv->state == STATE_SLEEP_S) { |
| 3629 | dev_dbg(&priv->i2c->dev, "%s() forcing sleep->shutdown\n", |
| 3630 | __func__); |
| 3631 | cxd2841er_sleep_s_to_shutdown(priv); |
| 3632 | } else if (priv->state == STATE_ACTIVE_S) { |
| 3633 | dev_dbg(&priv->i2c->dev, "%s() forcing active->sleep->shutdown\n", |
| 3634 | __func__); |
| 3635 | cxd2841er_active_s_to_sleep_s(priv); |
| 3636 | cxd2841er_sleep_s_to_shutdown(priv); |
| 3637 | } |
| 3638 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3639 | dev_dbg(&priv->i2c->dev, "%s()\n", __func__); |
| 3640 | cxd2841er_shutdown_to_sleep_s(priv); |
| 3641 | /* SONY_DEMOD_CONFIG_SAT_IFAGCNEG set to 1 */ |
| 3642 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0xa0); |
| 3643 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xb9, 0x01, 0x01); |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3644 | |
| 3645 | cxd2841er_init_stats(fe); |
| 3646 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3647 | return 0; |
| 3648 | } |
| 3649 | |
| 3650 | static int cxd2841er_init_tc(struct dvb_frontend *fe) |
| 3651 | { |
| 3652 | struct cxd2841er_priv *priv = fe->demodulator_priv; |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3653 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3654 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3655 | dev_dbg(&priv->i2c->dev, "%s() bandwidth_hz=%d\n", |
| 3656 | __func__, p->bandwidth_hz); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3657 | cxd2841er_shutdown_to_sleep_tc(priv); |
| 3658 | /* SONY_DEMOD_CONFIG_IFAGCNEG = 1 */ |
| 3659 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x10); |
| 3660 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xcb, 0x40, 0x40); |
| 3661 | /* SONY_DEMOD_CONFIG_IFAGC_ADC_FS = 0 */ |
| 3662 | cxd2841er_write_reg(priv, I2C_SLVT, 0xcd, 0x50); |
| 3663 | /* SONY_DEMOD_CONFIG_PARALLEL_SEL = 1 */ |
| 3664 | cxd2841er_write_reg(priv, I2C_SLVT, 0x00, 0x00); |
| 3665 | cxd2841er_set_reg_bits(priv, I2C_SLVT, 0xc4, 0x00, 0x80); |
Mauro Carvalho Chehab | d0e20e1 | 2016-06-30 00:34:59 -0300 | [diff] [blame] | 3666 | |
| 3667 | cxd2841er_init_stats(fe); |
| 3668 | |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3669 | return 0; |
| 3670 | } |
| 3671 | |
| 3672 | static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops; |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3673 | static struct dvb_frontend_ops cxd2841er_t_c_ops; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3674 | |
| 3675 | static struct dvb_frontend *cxd2841er_attach(struct cxd2841er_config *cfg, |
| 3676 | struct i2c_adapter *i2c, |
| 3677 | u8 system) |
| 3678 | { |
| 3679 | u8 chip_id = 0; |
| 3680 | const char *type; |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3681 | const char *name; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3682 | struct cxd2841er_priv *priv = NULL; |
| 3683 | |
| 3684 | /* allocate memory for the internal state */ |
| 3685 | priv = kzalloc(sizeof(struct cxd2841er_priv), GFP_KERNEL); |
| 3686 | if (!priv) |
| 3687 | return NULL; |
| 3688 | priv->i2c = i2c; |
| 3689 | priv->config = cfg; |
| 3690 | priv->i2c_addr_slvx = (cfg->i2c_addr + 4) >> 1; |
| 3691 | priv->i2c_addr_slvt = (cfg->i2c_addr) >> 1; |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3692 | priv->xtal = cfg->xtal; |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3693 | priv->frontend.demodulator_priv = priv; |
| 3694 | dev_info(&priv->i2c->dev, |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3695 | "%s(): I2C adapter %p SLVX addr %x SLVT addr %x\n", |
| 3696 | __func__, priv->i2c, |
| 3697 | priv->i2c_addr_slvx, priv->i2c_addr_slvt); |
| 3698 | chip_id = cxd2841er_chip_id(priv); |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3699 | switch (chip_id) { |
| 3700 | case CXD2841ER_CHIP_ID: |
| 3701 | snprintf(cxd2841er_t_c_ops.info.name, 128, |
| 3702 | "Sony CXD2841ER DVB-T/T2/C demodulator"); |
| 3703 | name = "CXD2841ER"; |
| 3704 | break; |
| 3705 | case CXD2854ER_CHIP_ID: |
| 3706 | snprintf(cxd2841er_t_c_ops.info.name, 128, |
| 3707 | "Sony CXD2854ER DVB-T/T2/C and ISDB-T demodulator"); |
| 3708 | cxd2841er_t_c_ops.delsys[3] = SYS_ISDBT; |
| 3709 | name = "CXD2854ER"; |
| 3710 | break; |
| 3711 | default: |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3712 | dev_err(&priv->i2c->dev, "%s(): invalid chip ID 0x%02x\n", |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3713 | __func__, chip_id); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3714 | priv->frontend.demodulator_priv = NULL; |
| 3715 | kfree(priv); |
| 3716 | return NULL; |
| 3717 | } |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3718 | |
| 3719 | /* create dvb_frontend */ |
| 3720 | if (system == SYS_DVBS) { |
| 3721 | memcpy(&priv->frontend.ops, |
| 3722 | &cxd2841er_dvbs_s2_ops, |
| 3723 | sizeof(struct dvb_frontend_ops)); |
| 3724 | type = "S/S2"; |
| 3725 | } else { |
| 3726 | memcpy(&priv->frontend.ops, |
| 3727 | &cxd2841er_t_c_ops, |
| 3728 | sizeof(struct dvb_frontend_ops)); |
| 3729 | type = "T/T2/C/ISDB-T"; |
| 3730 | } |
| 3731 | |
| 3732 | dev_info(&priv->i2c->dev, |
| 3733 | "%s(): attaching %s DVB-%s frontend\n", |
| 3734 | __func__, name, type); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3735 | dev_info(&priv->i2c->dev, "%s(): chip ID 0x%02x OK.\n", |
| 3736 | __func__, chip_id); |
| 3737 | return &priv->frontend; |
| 3738 | } |
| 3739 | |
| 3740 | struct dvb_frontend *cxd2841er_attach_s(struct cxd2841er_config *cfg, |
| 3741 | struct i2c_adapter *i2c) |
| 3742 | { |
| 3743 | return cxd2841er_attach(cfg, i2c, SYS_DVBS); |
| 3744 | } |
| 3745 | EXPORT_SYMBOL(cxd2841er_attach_s); |
| 3746 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3747 | struct dvb_frontend *cxd2841er_attach_t_c(struct cxd2841er_config *cfg, |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3748 | struct i2c_adapter *i2c) |
| 3749 | { |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3750 | return cxd2841er_attach(cfg, i2c, 0); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3751 | } |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3752 | EXPORT_SYMBOL(cxd2841er_attach_t_c); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3753 | |
| 3754 | static struct dvb_frontend_ops cxd2841er_dvbs_s2_ops = { |
| 3755 | .delsys = { SYS_DVBS, SYS_DVBS2 }, |
| 3756 | .info = { |
| 3757 | .name = "Sony CXD2841ER DVB-S/S2 demodulator", |
| 3758 | .frequency_min = 500000, |
| 3759 | .frequency_max = 2500000, |
| 3760 | .frequency_stepsize = 0, |
| 3761 | .symbol_rate_min = 1000000, |
| 3762 | .symbol_rate_max = 45000000, |
| 3763 | .symbol_rate_tolerance = 500, |
| 3764 | .caps = FE_CAN_INVERSION_AUTO | |
| 3765 | FE_CAN_FEC_AUTO | |
| 3766 | FE_CAN_QPSK, |
| 3767 | }, |
| 3768 | .init = cxd2841er_init_s, |
| 3769 | .sleep = cxd2841er_sleep_s, |
| 3770 | .release = cxd2841er_release, |
| 3771 | .set_frontend = cxd2841er_set_frontend_s, |
| 3772 | .get_frontend = cxd2841er_get_frontend, |
| 3773 | .read_status = cxd2841er_read_status_s, |
| 3774 | .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl, |
| 3775 | .get_frontend_algo = cxd2841er_get_algo, |
| 3776 | .set_tone = cxd2841er_set_tone, |
| 3777 | .diseqc_send_burst = cxd2841er_send_burst, |
| 3778 | .diseqc_send_master_cmd = cxd2841er_send_diseqc_msg, |
| 3779 | .tune = cxd2841er_tune_s |
| 3780 | }; |
| 3781 | |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3782 | static struct dvb_frontend_ops cxd2841er_t_c_ops = { |
| 3783 | .delsys = { SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A }, |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3784 | .info = { |
Abylay Ospan | 3f3b48a | 2016-05-14 00:08:40 -0300 | [diff] [blame] | 3785 | .name = "", /* will set in attach function */ |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3786 | .caps = FE_CAN_FEC_1_2 | |
| 3787 | FE_CAN_FEC_2_3 | |
| 3788 | FE_CAN_FEC_3_4 | |
| 3789 | FE_CAN_FEC_5_6 | |
| 3790 | FE_CAN_FEC_7_8 | |
| 3791 | FE_CAN_FEC_AUTO | |
| 3792 | FE_CAN_QPSK | |
| 3793 | FE_CAN_QAM_16 | |
| 3794 | FE_CAN_QAM_32 | |
| 3795 | FE_CAN_QAM_64 | |
| 3796 | FE_CAN_QAM_128 | |
| 3797 | FE_CAN_QAM_256 | |
| 3798 | FE_CAN_QAM_AUTO | |
| 3799 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 3800 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 3801 | FE_CAN_HIERARCHY_AUTO | |
| 3802 | FE_CAN_MUTE_TS | |
| 3803 | FE_CAN_2G_MODULATION, |
| 3804 | .frequency_min = 42000000, |
| 3805 | .frequency_max = 1002000000 |
| 3806 | }, |
| 3807 | .init = cxd2841er_init_tc, |
| 3808 | .sleep = cxd2841er_sleep_tc, |
| 3809 | .release = cxd2841er_release, |
| 3810 | .set_frontend = cxd2841er_set_frontend_tc, |
| 3811 | .get_frontend = cxd2841er_get_frontend, |
| 3812 | .read_status = cxd2841er_read_status_tc, |
| 3813 | .tune = cxd2841er_tune_tc, |
| 3814 | .i2c_gate_ctrl = cxd2841er_i2c_gate_ctrl, |
| 3815 | .get_frontend_algo = cxd2841er_get_algo |
| 3816 | }; |
| 3817 | |
Abylay Ospan | 83808c2 | 2016-03-22 19:20:34 -0300 | [diff] [blame] | 3818 | MODULE_DESCRIPTION("Sony CXD2841ER/CXD2854ER DVB-C/C2/T/T2/S/S2 demodulator driver"); |
| 3819 | MODULE_AUTHOR("Sergey Kozlov <serjk@netup.ru>, Abylay Ospan <aospan@netup.ru>"); |
Kozlov Sergey | a6dc60ff | 2015-07-28 11:33:03 -0300 | [diff] [blame] | 3820 | MODULE_LICENSE("GPL"); |