Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | Driver for ST STV0299 demodulator |
| 3 | |
| 4 | Copyright (C) 2001-2002 Convergence Integrated Media GmbH |
| 5 | <ralph@convergence.de>, |
| 6 | <holger@convergence.de>, |
| 7 | <js@convergence.de> |
| 8 | |
| 9 | |
| 10 | Philips SU1278/SH |
| 11 | |
| 12 | Copyright (C) 2002 by Peter Schildmann <peter.schildmann@web.de> |
| 13 | |
| 14 | |
| 15 | LG TDQF-S001F |
| 16 | |
| 17 | Copyright (C) 2002 Felix Domke <tmbinc@elitedvb.net> |
| 18 | & Andreas Oberritter <obi@linuxtv.org> |
| 19 | |
| 20 | |
| 21 | Support for Samsung TBMU24112IMB used on Technisat SkyStar2 rev. 2.6B |
| 22 | |
| 23 | Copyright (C) 2003 Vadim Catana <skystar@moldova.cc>: |
| 24 | |
| 25 | Support for Philips SU1278 on Technotrend hardware |
| 26 | |
| 27 | Copyright (C) 2004 Andrew de Quincey <adq_dvb@lidskialf.net> |
| 28 | |
| 29 | This program is free software; you can redistribute it and/or modify |
| 30 | it under the terms of the GNU General Public License as published by |
| 31 | the Free Software Foundation; either version 2 of the License, or |
| 32 | (at your option) any later version. |
| 33 | |
| 34 | This program is distributed in the hope that it will be useful, |
| 35 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 36 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 37 | GNU General Public License for more details. |
| 38 | |
| 39 | You should have received a copy of the GNU General Public License |
| 40 | along with this program; if not, write to the Free Software |
| 41 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 42 | |
| 43 | */ |
| 44 | |
| 45 | #include <linux/init.h> |
| 46 | #include <linux/kernel.h> |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 47 | #include <linux/ktime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/string.h> |
| 50 | #include <linux/slab.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 51 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/div64.h> |
| 53 | |
| 54 | #include "dvb_frontend.h" |
| 55 | #include "stv0299.h" |
| 56 | |
| 57 | struct stv0299_state { |
| 58 | struct i2c_adapter* i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | const struct stv0299_config* config; |
| 60 | struct dvb_frontend frontend; |
| 61 | |
| 62 | u8 initialised:1; |
| 63 | u32 tuner_frequency; |
| 64 | u32 symbol_rate; |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 65 | enum fe_code_rate fec_inner; |
Andrew de Quincey | 3765022 | 2005-11-08 21:35:11 -0800 | [diff] [blame] | 66 | int errmode; |
Oliver Endriss | 7876ad7 | 2008-06-19 23:25:04 -0300 | [diff] [blame] | 67 | u32 ucblocks; |
Malcolm Priestley | 24fb060 | 2011-03-26 21:57:33 -0300 | [diff] [blame] | 68 | u8 mcr_reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | }; |
| 70 | |
Andrew de Quincey | 3765022 | 2005-11-08 21:35:11 -0800 | [diff] [blame] | 71 | #define STATUS_BER 0 |
| 72 | #define STATUS_UCBLOCKS 1 |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static int debug; |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 75 | static int debug_legacy_dish_switch; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #define dprintk(args...) \ |
| 77 | do { \ |
| 78 | if (debug) printk(KERN_DEBUG "stv0299: " args); \ |
| 79 | } while (0) |
| 80 | |
| 81 | |
| 82 | static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data) |
| 83 | { |
| 84 | int ret; |
| 85 | u8 buf [] = { reg, data }; |
| 86 | struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; |
| 87 | |
| 88 | ret = i2c_transfer (state->i2c, &msg, 1); |
| 89 | |
| 90 | if (ret != 1) |
Mauro Carvalho Chehab | 4bd69e7 | 2016-10-18 17:44:22 -0200 | [diff] [blame] | 91 | dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n", |
| 92 | __func__, reg, data, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | return (ret != 1) ? -EREMOTEIO : 0; |
| 95 | } |
| 96 | |
lawrence rust | 2e4e98e | 2010-08-25 09:50:20 -0300 | [diff] [blame] | 97 | static int stv0299_write(struct dvb_frontend* fe, const u8 buf[], int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 99 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Andrew de Quincey | c10d14d | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 101 | if (len != 2) |
| 102 | return -EINVAL; |
| 103 | |
| 104 | return stv0299_writeregI(state, buf[0], buf[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static u8 stv0299_readreg (struct stv0299_state* state, u8 reg) |
| 108 | { |
| 109 | int ret; |
| 110 | u8 b0 [] = { reg }; |
| 111 | u8 b1 [] = { 0 }; |
| 112 | struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 }, |
| 113 | { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } }; |
| 114 | |
| 115 | ret = i2c_transfer (state->i2c, msg, 2); |
| 116 | |
| 117 | if (ret != 2) |
| 118 | dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 119 | __func__, reg, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
| 121 | return b1[0]; |
| 122 | } |
| 123 | |
| 124 | static int stv0299_readregs (struct stv0299_state* state, u8 reg1, u8 *b, u8 len) |
| 125 | { |
| 126 | int ret; |
| 127 | struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = ®1, .len = 1 }, |
| 128 | { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b, .len = len } }; |
| 129 | |
| 130 | ret = i2c_transfer (state->i2c, msg, 2); |
| 131 | |
| 132 | if (ret != 2) |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 133 | dprintk("%s: readreg error (ret == %i)\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | return ret == 2 ? 0 : ret; |
| 136 | } |
| 137 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 138 | static int stv0299_set_FEC(struct stv0299_state *state, enum fe_code_rate fec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 140 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | switch (fec) { |
| 143 | case FEC_AUTO: |
| 144 | { |
| 145 | return stv0299_writeregI (state, 0x31, 0x1f); |
| 146 | } |
| 147 | case FEC_1_2: |
| 148 | { |
| 149 | return stv0299_writeregI (state, 0x31, 0x01); |
| 150 | } |
| 151 | case FEC_2_3: |
| 152 | { |
| 153 | return stv0299_writeregI (state, 0x31, 0x02); |
| 154 | } |
| 155 | case FEC_3_4: |
| 156 | { |
| 157 | return stv0299_writeregI (state, 0x31, 0x04); |
| 158 | } |
| 159 | case FEC_5_6: |
| 160 | { |
| 161 | return stv0299_writeregI (state, 0x31, 0x08); |
| 162 | } |
| 163 | case FEC_7_8: |
| 164 | { |
| 165 | return stv0299_writeregI (state, 0x31, 0x10); |
| 166 | } |
| 167 | default: |
| 168 | { |
| 169 | return -EINVAL; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 174 | static enum fe_code_rate stv0299_get_fec(struct stv0299_state *state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 176 | static enum fe_code_rate fec_tab[] = { FEC_2_3, FEC_3_4, FEC_5_6, |
| 177 | FEC_7_8, FEC_1_2 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | u8 index; |
| 179 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 180 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
| 182 | index = stv0299_readreg (state, 0x1b); |
| 183 | index &= 0x7; |
| 184 | |
| 185 | if (index > 4) |
| 186 | return FEC_AUTO; |
| 187 | |
| 188 | return fec_tab [index]; |
| 189 | } |
| 190 | |
| 191 | static int stv0299_wait_diseqc_fifo (struct stv0299_state* state, int timeout) |
| 192 | { |
| 193 | unsigned long start = jiffies; |
| 194 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 195 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | while (stv0299_readreg(state, 0x0a) & 1) { |
| 198 | if (jiffies - start > timeout) { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 199 | dprintk ("%s: timeout!!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return -ETIMEDOUT; |
| 201 | } |
| 202 | msleep(10); |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 203 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | static int stv0299_wait_diseqc_idle (struct stv0299_state* state, int timeout) |
| 209 | { |
| 210 | unsigned long start = jiffies; |
| 211 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 212 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | while ((stv0299_readreg(state, 0x0a) & 3) != 2 ) { |
| 215 | if (jiffies - start > timeout) { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 216 | dprintk ("%s: timeout!!\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return -ETIMEDOUT; |
| 218 | } |
| 219 | msleep(10); |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int stv0299_set_symbolrate (struct dvb_frontend* fe, u32 srate) |
| 226 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 227 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | u64 big = srate; |
| 229 | u32 ratio; |
| 230 | |
| 231 | // check rate is within limits |
| 232 | if ((srate < 1000000) || (srate > 45000000)) return -EINVAL; |
| 233 | |
| 234 | // calculate value to program |
| 235 | big = big << 20; |
| 236 | big += (state->config->mclk-1); // round correctly |
| 237 | do_div(big, state->config->mclk); |
| 238 | ratio = big << 4; |
| 239 | |
| 240 | return state->config->set_symbol_rate(fe, srate, ratio); |
| 241 | } |
| 242 | |
| 243 | static int stv0299_get_symbolrate (struct stv0299_state* state) |
| 244 | { |
| 245 | u32 Mclk = state->config->mclk / 4096L; |
| 246 | u32 srate; |
| 247 | s32 offset; |
| 248 | u8 sfr[3]; |
| 249 | s8 rtf; |
| 250 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 251 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | stv0299_readregs (state, 0x1f, sfr, 3); |
Oliver Endriss | 0402a6c | 2007-07-12 23:22:59 -0300 | [diff] [blame] | 254 | stv0299_readregs (state, 0x1a, (u8 *)&rtf, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
| 256 | srate = (sfr[0] << 8) | sfr[1]; |
| 257 | srate *= Mclk; |
| 258 | srate /= 16; |
| 259 | srate += (sfr[2] >> 4) * Mclk / 256; |
| 260 | offset = (s32) rtf * (srate / 4096L); |
| 261 | offset /= 128; |
| 262 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 263 | dprintk ("%s : srate = %i\n", __func__, srate); |
| 264 | dprintk ("%s : ofset = %i\n", __func__, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | srate += offset; |
| 267 | |
| 268 | srate += 1000; |
| 269 | srate /= 2000; |
| 270 | srate *= 2000; |
| 271 | |
| 272 | return srate; |
| 273 | } |
| 274 | |
| 275 | static int stv0299_send_diseqc_msg (struct dvb_frontend* fe, |
| 276 | struct dvb_diseqc_master_cmd *m) |
| 277 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 278 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | u8 val; |
| 280 | int i; |
| 281 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 282 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | if (stv0299_wait_diseqc_idle (state, 100) < 0) |
| 285 | return -ETIMEDOUT; |
| 286 | |
| 287 | val = stv0299_readreg (state, 0x08); |
| 288 | |
| 289 | if (stv0299_writeregI (state, 0x08, (val & ~0x7) | 0x6)) /* DiSEqC mode */ |
| 290 | return -EREMOTEIO; |
| 291 | |
| 292 | for (i=0; i<m->msg_len; i++) { |
| 293 | if (stv0299_wait_diseqc_fifo (state, 100) < 0) |
| 294 | return -ETIMEDOUT; |
| 295 | |
| 296 | if (stv0299_writeregI (state, 0x09, m->msg[i])) |
| 297 | return -EREMOTEIO; |
| 298 | } |
| 299 | |
| 300 | if (stv0299_wait_diseqc_idle (state, 100) < 0) |
| 301 | return -ETIMEDOUT; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 306 | static int stv0299_send_diseqc_burst(struct dvb_frontend *fe, |
| 307 | enum fe_sec_mini_cmd burst) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 309 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | u8 val; |
| 311 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 312 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | if (stv0299_wait_diseqc_idle (state, 100) < 0) |
| 315 | return -ETIMEDOUT; |
| 316 | |
| 317 | val = stv0299_readreg (state, 0x08); |
| 318 | |
| 319 | if (stv0299_writeregI (state, 0x08, (val & ~0x7) | 0x2)) /* burst mode */ |
| 320 | return -EREMOTEIO; |
| 321 | |
| 322 | if (stv0299_writeregI (state, 0x09, burst == SEC_MINI_A ? 0x00 : 0xff)) |
| 323 | return -EREMOTEIO; |
| 324 | |
| 325 | if (stv0299_wait_diseqc_idle (state, 100) < 0) |
| 326 | return -ETIMEDOUT; |
| 327 | |
| 328 | if (stv0299_writeregI (state, 0x08, val)) |
| 329 | return -EREMOTEIO; |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 334 | static int stv0299_set_tone(struct dvb_frontend *fe, |
| 335 | enum fe_sec_tone_mode tone) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 337 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | u8 val; |
| 339 | |
| 340 | if (stv0299_wait_diseqc_idle (state, 100) < 0) |
| 341 | return -ETIMEDOUT; |
| 342 | |
| 343 | val = stv0299_readreg (state, 0x08); |
| 344 | |
| 345 | switch (tone) { |
| 346 | case SEC_TONE_ON: |
| 347 | return stv0299_writeregI (state, 0x08, val | 0x3); |
| 348 | |
| 349 | case SEC_TONE_OFF: |
| 350 | return stv0299_writeregI (state, 0x08, (val & ~0x3) | 0x02); |
| 351 | |
| 352 | default: |
| 353 | return -EINVAL; |
| 354 | } |
| 355 | } |
| 356 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 357 | static int stv0299_set_voltage(struct dvb_frontend *fe, |
| 358 | enum fe_sec_voltage voltage) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 360 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | u8 reg0x08; |
| 362 | u8 reg0x0c; |
| 363 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 364 | dprintk("%s: %s\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" : |
| 366 | voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??"); |
| 367 | |
| 368 | reg0x08 = stv0299_readreg (state, 0x08); |
| 369 | reg0x0c = stv0299_readreg (state, 0x0c); |
| 370 | |
| 371 | /** |
| 372 | * H/V switching over OP0, OP1 and OP2 are LNB power enable bits |
| 373 | */ |
| 374 | reg0x0c &= 0x0f; |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 375 | reg0x08 = (reg0x08 & 0x3f) | (state->config->lock_output << 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | switch (voltage) { |
| 378 | case SEC_VOLTAGE_13: |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 379 | if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) |
| 380 | reg0x0c |= 0x10; /* OP1 off, OP0 on */ |
| 381 | else |
| 382 | reg0x0c |= 0x40; /* OP1 on, OP0 off */ |
| 383 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | case SEC_VOLTAGE_18: |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 385 | reg0x0c |= 0x50; /* OP1 on, OP0 on */ |
| 386 | break; |
| 387 | case SEC_VOLTAGE_OFF: |
| 388 | /* LNB power off! */ |
| 389 | reg0x08 = 0x00; |
| 390 | reg0x0c = 0x00; |
| 391 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | default: |
| 393 | return -EINVAL; |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 394 | } |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 395 | |
| 396 | if (state->config->op0_off) |
| 397 | reg0x0c &= ~0x10; |
| 398 | |
| 399 | stv0299_writeregI(state, 0x08, reg0x08); |
| 400 | return stv0299_writeregI(state, 0x0c, reg0x0c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Peter Beutner | 400b708 | 2006-01-09 15:32:43 -0200 | [diff] [blame] | 403 | static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long cmd) |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 404 | { |
| 405 | struct stv0299_state* state = fe->demodulator_priv; |
| 406 | u8 reg0x08; |
| 407 | u8 reg0x0c; |
| 408 | u8 lv_mask = 0x40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | u8 last = 1; |
| 410 | int i; |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 411 | ktime_t nexttime; |
| 412 | ktime_t tv[10]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 414 | reg0x08 = stv0299_readreg (state, 0x08); |
| 415 | reg0x0c = stv0299_readreg (state, 0x0c); |
| 416 | reg0x0c &= 0x0f; |
| 417 | stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6)); |
| 418 | if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) |
| 419 | lv_mask = 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
| 421 | cmd = cmd << 1; |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 422 | if (debug_legacy_dish_switch) |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 423 | printk ("%s switch command: 0x%04lx\n",__func__, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Abhilash Jindal | 6b3f999 | 2016-01-31 03:47:31 -0200 | [diff] [blame] | 425 | nexttime = ktime_get_boottime(); |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 426 | if (debug_legacy_dish_switch) |
Ezequiel Garcia | ee45ddc | 2012-10-23 15:57:24 -0300 | [diff] [blame] | 427 | tv[0] = nexttime; |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 428 | stv0299_writeregI (state, 0x0c, reg0x0c | 0x50); /* set LNB to 18V */ |
| 429 | |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 430 | dvb_frontend_sleep_until(&nexttime, 32000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | for (i=0; i<9; i++) { |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 433 | if (debug_legacy_dish_switch) |
Abhilash Jindal | 6b3f999 | 2016-01-31 03:47:31 -0200 | [diff] [blame] | 434 | tv[i+1] = ktime_get_boottime(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if((cmd & 0x01) != last) { |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 436 | /* set voltage to (last ? 13V : 18V) */ |
| 437 | stv0299_writeregI (state, 0x0c, reg0x0c | (last ? lv_mask : 0x50)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | last = (last) ? 0 : 1; |
| 439 | } |
| 440 | |
| 441 | cmd = cmd >> 1; |
| 442 | |
| 443 | if (i != 8) |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 444 | dvb_frontend_sleep_until(&nexttime, 8000); |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 445 | } |
| 446 | if (debug_legacy_dish_switch) { |
| 447 | printk ("%s(%d): switch delay (should be 32k followed by all 8k\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 448 | __func__, fe->dvb->num); |
NooneImportant | 83b75b0 | 2005-11-08 21:35:27 -0800 | [diff] [blame] | 449 | for (i = 1; i < 10; i++) |
Tina Ruchandani | 9056a23 | 2015-05-31 04:17:06 -0300 | [diff] [blame] | 450 | printk("%d: %d\n", i, |
| 451 | (int) ktime_us_delta(tv[i], tv[i-1])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
| 457 | static int stv0299_init (struct dvb_frontend* fe) |
| 458 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 459 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | int i; |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 461 | u8 reg; |
| 462 | u8 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | dprintk("stv0299: init chip\n"); |
| 465 | |
Malcolm Priestley | 24fb060 | 2011-03-26 21:57:33 -0300 | [diff] [blame] | 466 | stv0299_writeregI(state, 0x02, 0x30 | state->mcr_reg); |
| 467 | msleep(50); |
| 468 | |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 469 | for (i = 0; ; i += 2) { |
| 470 | reg = state->config->inittab[i]; |
| 471 | val = state->config->inittab[i+1]; |
| 472 | if (reg == 0xff && val == 0xff) |
| 473 | break; |
| 474 | if (reg == 0x0c && state->config->op0_off) |
| 475 | val &= ~0x10; |
Malcolm Priestley | 24fb060 | 2011-03-26 21:57:33 -0300 | [diff] [blame] | 476 | if (reg == 0x2) |
| 477 | state->mcr_reg = val & 0xf; |
Oliver Endriss | e84b133 | 2008-04-20 21:57:34 -0300 | [diff] [blame] | 478 | stv0299_writeregI(state, reg, val); |
| 479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | return 0; |
| 482 | } |
| 483 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 484 | static int stv0299_read_status(struct dvb_frontend *fe, |
| 485 | enum fe_status *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 487 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | u8 signal = 0xff - stv0299_readreg (state, 0x18); |
| 490 | u8 sync = stv0299_readreg (state, 0x1b); |
| 491 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 492 | dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | *status = 0; |
| 494 | |
| 495 | if (signal > 10) |
| 496 | *status |= FE_HAS_SIGNAL; |
| 497 | |
| 498 | if (sync & 0x80) |
| 499 | *status |= FE_HAS_CARRIER; |
| 500 | |
| 501 | if (sync & 0x10) |
| 502 | *status |= FE_HAS_VITERBI; |
| 503 | |
| 504 | if (sync & 0x08) |
| 505 | *status |= FE_HAS_SYNC; |
| 506 | |
| 507 | if ((sync & 0x98) == 0x98) |
| 508 | *status |= FE_HAS_LOCK; |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
| 513 | static int stv0299_read_ber(struct dvb_frontend* fe, u32* ber) |
| 514 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 515 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Oliver Endriss | 7876ad7 | 2008-06-19 23:25:04 -0300 | [diff] [blame] | 517 | if (state->errmode != STATUS_BER) |
| 518 | return -ENOSYS; |
| 519 | |
| 520 | *ber = stv0299_readreg(state, 0x1e) | (stv0299_readreg(state, 0x1d) << 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength) |
| 526 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 527 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | |
| 529 | s32 signal = 0xffff - ((stv0299_readreg (state, 0x18) << 8) |
| 530 | | stv0299_readreg (state, 0x19)); |
| 531 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 532 | dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __func__, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | stv0299_readreg (state, 0x18), |
| 534 | stv0299_readreg (state, 0x19), (int) signal); |
| 535 | |
| 536 | signal = signal * 5 / 4; |
| 537 | *strength = (signal > 0xffff) ? 0xffff : (signal < 0) ? 0 : signal; |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | static int stv0299_read_snr(struct dvb_frontend* fe, u16* snr) |
| 543 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 544 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | |
| 546 | s32 xsnr = 0xffff - ((stv0299_readreg (state, 0x24) << 8) |
| 547 | | stv0299_readreg (state, 0x25)); |
| 548 | xsnr = 3 * (xsnr - 0xa100); |
| 549 | *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr; |
| 550 | |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | static int stv0299_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) |
| 555 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 556 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Oliver Endriss | 7876ad7 | 2008-06-19 23:25:04 -0300 | [diff] [blame] | 558 | if (state->errmode != STATUS_UCBLOCKS) |
| 559 | return -ENOSYS; |
| 560 | |
| 561 | state->ucblocks += stv0299_readreg(state, 0x1e); |
| 562 | state->ucblocks += (stv0299_readreg(state, 0x1d) << 8); |
| 563 | *ucblocks = state->ucblocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 568 | static int stv0299_set_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | { |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 570 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 571 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | int invval = 0; |
| 573 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 574 | dprintk ("%s : FE_SET_FRONTEND\n", __func__); |
Igor M. Liplianin | e4aab64 | 2008-09-23 15:43:57 -0300 | [diff] [blame] | 575 | if (state->config->set_ts_params) |
| 576 | state->config->set_ts_params(fe, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
| 578 | // set the inversion |
| 579 | if (p->inversion == INVERSION_OFF) invval = 0; |
| 580 | else if (p->inversion == INVERSION_ON) invval = 1; |
| 581 | else { |
| 582 | printk("stv0299 does not support auto-inversion\n"); |
| 583 | return -EINVAL; |
| 584 | } |
| 585 | if (state->config->invert) invval = (~invval) & 1; |
| 586 | stv0299_writeregI(state, 0x0c, (stv0299_readreg(state, 0x0c) & 0xfe) | invval); |
| 587 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 588 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 589 | fe->ops.tuner_ops.set_params(fe); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 590 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 53a8ee3 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 593 | stv0299_set_FEC(state, p->fec_inner); |
| 594 | stv0299_set_symbolrate(fe, p->symbol_rate); |
Andrew de Quincy | 3528cc4e | 2005-11-08 21:35:28 -0800 | [diff] [blame] | 595 | stv0299_writeregI(state, 0x22, 0x00); |
| 596 | stv0299_writeregI(state, 0x23, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | state->tuner_frequency = p->frequency; |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 599 | state->fec_inner = p->fec_inner; |
| 600 | state->symbol_rate = p->symbol_rate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
Mauro Carvalho Chehab | 7e3e68b | 2016-02-04 12:58:30 -0200 | [diff] [blame] | 605 | static int stv0299_get_frontend(struct dvb_frontend *fe, |
| 606 | struct dtv_frontend_properties *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 608 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | s32 derot_freq; |
| 610 | int invval; |
| 611 | |
| 612 | derot_freq = (s32)(s16) ((stv0299_readreg (state, 0x22) << 8) |
| 613 | | stv0299_readreg (state, 0x23)); |
| 614 | |
| 615 | derot_freq *= (state->config->mclk >> 16); |
| 616 | derot_freq += 500; |
| 617 | derot_freq /= 1000; |
| 618 | |
| 619 | p->frequency += derot_freq; |
| 620 | |
| 621 | invval = stv0299_readreg (state, 0x0c) & 1; |
| 622 | if (state->config->invert) invval = (~invval) & 1; |
| 623 | p->inversion = invval ? INVERSION_ON : INVERSION_OFF; |
| 624 | |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 625 | p->fec_inner = stv0299_get_fec(state); |
| 626 | p->symbol_rate = stv0299_get_symbolrate(state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | static int stv0299_sleep(struct dvb_frontend* fe) |
| 632 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 633 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | |
Malcolm Priestley | 24fb060 | 2011-03-26 21:57:33 -0300 | [diff] [blame] | 635 | stv0299_writeregI(state, 0x02, 0xb0 | state->mcr_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | state->initialised = 0; |
| 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
Andrew de Quincey | 53a8ee3 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 641 | static int stv0299_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) |
| 642 | { |
| 643 | struct stv0299_state* state = fe->demodulator_priv; |
| 644 | |
| 645 | if (enable) { |
Andrew de Quincey | a9686e0 | 2006-05-22 10:31:40 -0300 | [diff] [blame] | 646 | stv0299_writeregI(state, 0x05, 0xb5); |
Andrew de Quincey | 53a8ee3 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 647 | } else { |
Andrew de Quincey | a9686e0 | 2006-05-22 10:31:40 -0300 | [diff] [blame] | 648 | stv0299_writeregI(state, 0x05, 0x35); |
Andrew de Quincey | 53a8ee3 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 649 | } |
Andrew de Quincey | a9686e0 | 2006-05-22 10:31:40 -0300 | [diff] [blame] | 650 | udelay(1); |
| 651 | return 0; |
Andrew de Quincey | 53a8ee3 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 652 | } |
| 653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | static int stv0299_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) |
| 655 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 656 | struct stv0299_state* state = fe->demodulator_priv; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 657 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | |
| 659 | fesettings->min_delay_ms = state->config->min_delay_ms; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 660 | if (p->symbol_rate < 10000000) { |
| 661 | fesettings->step_size = p->symbol_rate / 32000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | fesettings->max_drift = 5000; |
| 663 | } else { |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 664 | fesettings->step_size = p->symbol_rate / 16000; |
| 665 | fesettings->max_drift = p->symbol_rate / 2000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | } |
| 667 | return 0; |
| 668 | } |
| 669 | |
| 670 | static void stv0299_release(struct dvb_frontend* fe) |
| 671 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 672 | struct stv0299_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | kfree(state); |
| 674 | } |
| 675 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame] | 676 | static const struct dvb_frontend_ops stv0299_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
| 678 | struct dvb_frontend* stv0299_attach(const struct stv0299_config* config, |
| 679 | struct i2c_adapter* i2c) |
| 680 | { |
| 681 | struct stv0299_state* state = NULL; |
| 682 | int id; |
| 683 | |
| 684 | /* allocate memory for the internal state */ |
Matthias Schwarzott | 084e24a | 2009-08-10 22:51:01 -0300 | [diff] [blame] | 685 | state = kzalloc(sizeof(struct stv0299_state), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | if (state == NULL) goto error; |
| 687 | |
| 688 | /* setup the state */ |
| 689 | state->config = config; |
| 690 | state->i2c = i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | state->initialised = 0; |
| 692 | state->tuner_frequency = 0; |
| 693 | state->symbol_rate = 0; |
| 694 | state->fec_inner = 0; |
Andrew de Quincey | 3765022 | 2005-11-08 21:35:11 -0800 | [diff] [blame] | 695 | state->errmode = STATUS_BER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | |
| 697 | /* check if the demod is there */ |
Malcolm Priestley | 24fb060 | 2011-03-26 21:57:33 -0300 | [diff] [blame] | 698 | stv0299_writeregI(state, 0x02, 0x30); /* standby off */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | msleep(200); |
| 700 | id = stv0299_readreg(state, 0x00); |
| 701 | |
| 702 | /* register 0x00 contains 0xa1 for STV0299 and STV0299B */ |
| 703 | /* register 0x00 might contain 0x80 when returning from standby */ |
| 704 | if (id != 0xa1 && id != 0x80) goto error; |
| 705 | |
| 706 | /* create dvb_frontend */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 707 | memcpy(&state->frontend.ops, &stv0299_ops, sizeof(struct dvb_frontend_ops)); |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 708 | state->frontend.demodulator_priv = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | return &state->frontend; |
| 710 | |
| 711 | error: |
| 712 | kfree(state); |
| 713 | return NULL; |
| 714 | } |
| 715 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame] | 716 | static const struct dvb_frontend_ops stv0299_ops = { |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 717 | .delsys = { SYS_DVBS }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | .info = { |
| 719 | .name = "ST STV0299 DVB-S", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | .frequency_min = 950000, |
| 721 | .frequency_max = 2150000, |
| 722 | .frequency_stepsize = 125, /* kHz for QPSK frontends */ |
| 723 | .frequency_tolerance = 0, |
| 724 | .symbol_rate_min = 1000000, |
| 725 | .symbol_rate_max = 45000000, |
| 726 | .symbol_rate_tolerance = 500, /* ppm */ |
| 727 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 728 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | |
| 729 | FE_CAN_QPSK | |
| 730 | FE_CAN_FEC_AUTO |
| 731 | }, |
| 732 | |
| 733 | .release = stv0299_release, |
| 734 | |
| 735 | .init = stv0299_init, |
| 736 | .sleep = stv0299_sleep, |
Andrew de Quincey | c10d14d | 2006-08-08 09:10:08 -0300 | [diff] [blame] | 737 | .write = stv0299_write, |
Andrew de Quincey | 53a8ee3 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 738 | .i2c_gate_ctrl = stv0299_i2c_gate_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | |
Mauro Carvalho Chehab | 45f4a8e | 2011-12-26 14:29:52 -0300 | [diff] [blame] | 740 | .set_frontend = stv0299_set_frontend, |
| 741 | .get_frontend = stv0299_get_frontend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | .get_tune_settings = stv0299_get_tune_settings, |
| 743 | |
| 744 | .read_status = stv0299_read_status, |
| 745 | .read_ber = stv0299_read_ber, |
| 746 | .read_signal_strength = stv0299_read_signal_strength, |
| 747 | .read_snr = stv0299_read_snr, |
| 748 | .read_ucblocks = stv0299_read_ucblocks, |
| 749 | |
| 750 | .diseqc_send_master_cmd = stv0299_send_diseqc_msg, |
| 751 | .diseqc_send_burst = stv0299_send_diseqc_burst, |
| 752 | .set_tone = stv0299_set_tone, |
| 753 | .set_voltage = stv0299_set_voltage, |
| 754 | .dishnetwork_send_legacy_command = stv0299_send_legacy_dish_cmd, |
| 755 | }; |
| 756 | |
Johannes Stezenbach | 591ad98 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 757 | module_param(debug_legacy_dish_switch, int, 0444); |
| 758 | MODULE_PARM_DESC(debug_legacy_dish_switch, "Enable timing analysis for Dish Network legacy switches"); |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | module_param(debug, int, 0644); |
| 761 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
| 762 | |
| 763 | MODULE_DESCRIPTION("ST STV0299 DVB Demodulator driver"); |
Mauro Carvalho Chehab | 4bd69e7 | 2016-10-18 17:44:22 -0200 | [diff] [blame] | 764 | MODULE_AUTHOR("Ralph Metzler, Holger Waechtler, Peter Schildmann, Felix Domke, Andreas Oberritter, Andrew de Quincey, Kenneth Aafly"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | MODULE_LICENSE("GPL"); |
| 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | EXPORT_SYMBOL(stv0299_attach); |