Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 1 | /* |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 2 | * Driver for |
| 3 | * Samsung S5H1420 and |
| 4 | * PnpNetwork PN1010 QPSK Demodulator |
| 5 | * |
| 6 | * Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net> |
| 7 | * Copyright (C) 2005-8 Patrick Boettcher <pb@linuxtv.org> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/delay.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 31 | #include <linux/jiffies.h> |
| 32 | #include <asm/div64.h> |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 33 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 34 | #include <linux/i2c.h> |
| 35 | |
| 36 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 37 | #include "dvb_frontend.h" |
| 38 | #include "s5h1420.h" |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 39 | #include "s5h1420_priv.h" |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 40 | |
| 41 | #define TONE_FREQ 22000 |
| 42 | |
| 43 | struct s5h1420_state { |
| 44 | struct i2c_adapter* i2c; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 45 | const struct s5h1420_config* config; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 46 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 47 | struct dvb_frontend frontend; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 48 | struct i2c_adapter tuner_i2c_adapter; |
| 49 | |
| 50 | u8 CON_1_val; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 51 | |
| 52 | u8 postlocked:1; |
| 53 | u32 fclk; |
| 54 | u32 tunedfreq; |
| 55 | fe_code_rate_t fec_inner; |
| 56 | u32 symbol_rate; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 57 | |
| 58 | /* FIXME: ugly workaround for flexcop's incapable i2c-controller |
| 59 | * it does not support repeated-start, workaround: write addr-1 |
| 60 | * and then read |
| 61 | */ |
Patrick Boettcher | bda1cda | 2008-09-07 16:04:38 -0300 | [diff] [blame] | 62 | u8 shadow[256]; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | static u32 s5h1420_getsymbolrate(struct s5h1420_state* state); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 66 | static int s5h1420_get_tune_settings(struct dvb_frontend* fe, |
| 67 | struct dvb_frontend_tune_settings* fesettings); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 68 | |
| 69 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 70 | static int debug; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 71 | module_param(debug, int, 0644); |
| 72 | MODULE_PARM_DESC(debug, "enable debugging"); |
| 73 | |
| 74 | #define dprintk(x...) do { \ |
| 75 | if (debug) \ |
| 76 | printk(KERN_DEBUG "S5H1420: " x); \ |
| 77 | } while (0) |
| 78 | |
| 79 | static u8 s5h1420_readreg(struct s5h1420_state *state, u8 reg) |
| 80 | { |
| 81 | int ret; |
| 82 | u8 b[2]; |
| 83 | struct i2c_msg msg[] = { |
| 84 | { .addr = state->config->demod_address, .flags = 0, .buf = b, .len = 2 }, |
| 85 | { .addr = state->config->demod_address, .flags = 0, .buf = ®, .len = 1 }, |
| 86 | { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b, .len = 1 }, |
| 87 | }; |
| 88 | |
| 89 | b[0] = (reg - 1) & 0xff; |
| 90 | b[1] = state->shadow[(reg - 1) & 0xff]; |
| 91 | |
| 92 | if (state->config->repeated_start_workaround) { |
| 93 | ret = i2c_transfer(state->i2c, msg, 3); |
| 94 | if (ret != 3) |
| 95 | return ret; |
| 96 | } else { |
Patrick Boettcher | c18c5ff | 2008-09-06 13:31:58 -0300 | [diff] [blame] | 97 | ret = i2c_transfer(state->i2c, &msg[1], 1); |
| 98 | if (ret != 1) |
| 99 | return ret; |
| 100 | ret = i2c_transfer(state->i2c, &msg[2], 1); |
| 101 | if (ret != 1) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | /* dprintk("rd(%02x): %02x %02x\n", state->config->demod_address, reg, b[0]); */ |
| 106 | |
| 107 | return b[0]; |
| 108 | } |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 109 | |
| 110 | static int s5h1420_writereg (struct s5h1420_state* state, u8 reg, u8 data) |
| 111 | { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 112 | u8 buf[] = { reg, data }; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 113 | struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; |
| 114 | int err; |
| 115 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 116 | /* dprintk("wr(%02x): %02x %02x\n", state->config->demod_address, reg, data); */ |
| 117 | err = i2c_transfer(state->i2c, &msg, 1); |
| 118 | if (err != 1) { |
| 119 | dprintk("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__, err, reg, data); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 120 | return -EREMOTEIO; |
| 121 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 122 | state->shadow[reg] = data; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 127 | static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) |
| 128 | { |
| 129 | struct s5h1420_state* state = fe->demodulator_priv; |
| 130 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 131 | dprintk("enter %s\n", __func__); |
| 132 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 133 | switch(voltage) { |
| 134 | case SEC_VOLTAGE_13: |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 135 | s5h1420_writereg(state, 0x3c, |
| 136 | (s5h1420_readreg(state, 0x3c) & 0xfe) | 0x02); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 137 | break; |
| 138 | |
| 139 | case SEC_VOLTAGE_18: |
| 140 | s5h1420_writereg(state, 0x3c, s5h1420_readreg(state, 0x3c) | 0x03); |
| 141 | break; |
| 142 | |
| 143 | case SEC_VOLTAGE_OFF: |
| 144 | s5h1420_writereg(state, 0x3c, s5h1420_readreg(state, 0x3c) & 0xfd); |
| 145 | break; |
| 146 | } |
| 147 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 148 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int s5h1420_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone) |
| 153 | { |
| 154 | struct s5h1420_state* state = fe->demodulator_priv; |
| 155 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 156 | dprintk("enter %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 157 | switch(tone) { |
| 158 | case SEC_TONE_ON: |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 159 | s5h1420_writereg(state, 0x3b, |
| 160 | (s5h1420_readreg(state, 0x3b) & 0x74) | 0x08); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 161 | break; |
| 162 | |
| 163 | case SEC_TONE_OFF: |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 164 | s5h1420_writereg(state, 0x3b, |
| 165 | (s5h1420_readreg(state, 0x3b) & 0x74) | 0x01); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 166 | break; |
| 167 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 168 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 173 | static int s5h1420_send_master_cmd (struct dvb_frontend* fe, |
| 174 | struct dvb_diseqc_master_cmd* cmd) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 175 | { |
| 176 | struct s5h1420_state* state = fe->demodulator_priv; |
| 177 | u8 val; |
| 178 | int i; |
| 179 | unsigned long timeout; |
| 180 | int result = 0; |
| 181 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 182 | dprintk("enter %s\n", __func__); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 183 | if (cmd->msg_len > 8) |
| 184 | return -EINVAL; |
| 185 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 186 | /* setup for DISEQC */ |
| 187 | val = s5h1420_readreg(state, 0x3b); |
| 188 | s5h1420_writereg(state, 0x3b, 0x02); |
| 189 | msleep(15); |
| 190 | |
| 191 | /* write the DISEQC command bytes */ |
| 192 | for(i=0; i< cmd->msg_len; i++) { |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 193 | s5h1420_writereg(state, 0x3d + i, cmd->msg[i]); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* kick off transmission */ |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 197 | s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | |
| 198 | ((cmd->msg_len-1) << 4) | 0x08); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 199 | |
| 200 | /* wait for transmission to complete */ |
| 201 | timeout = jiffies + ((100*HZ) / 1000); |
| 202 | while(time_before(jiffies, timeout)) { |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 203 | if (!(s5h1420_readreg(state, 0x3b) & 0x08)) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 204 | break; |
| 205 | |
| 206 | msleep(5); |
| 207 | } |
| 208 | if (time_after(jiffies, timeout)) |
| 209 | result = -ETIMEDOUT; |
| 210 | |
| 211 | /* restore original settings */ |
| 212 | s5h1420_writereg(state, 0x3b, val); |
| 213 | msleep(15); |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 214 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 215 | return result; |
| 216 | } |
| 217 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 218 | static int s5h1420_recv_slave_reply (struct dvb_frontend* fe, |
| 219 | struct dvb_diseqc_slave_reply* reply) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 220 | { |
| 221 | struct s5h1420_state* state = fe->demodulator_priv; |
| 222 | u8 val; |
| 223 | int i; |
| 224 | int length; |
| 225 | unsigned long timeout; |
| 226 | int result = 0; |
| 227 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 228 | /* setup for DISEQC receive */ |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 229 | val = s5h1420_readreg(state, 0x3b); |
| 230 | s5h1420_writereg(state, 0x3b, 0x82); /* FIXME: guess - do we need to set DIS_RDY(0x08) in receive mode? */ |
| 231 | msleep(15); |
| 232 | |
| 233 | /* wait for reception to complete */ |
| 234 | timeout = jiffies + ((reply->timeout*HZ) / 1000); |
| 235 | while(time_before(jiffies, timeout)) { |
| 236 | if (!(s5h1420_readreg(state, 0x3b) & 0x80)) /* FIXME: do we test DIS_RDY(0x08) or RCV_EN(0x80)? */ |
| 237 | break; |
| 238 | |
| 239 | msleep(5); |
| 240 | } |
| 241 | if (time_after(jiffies, timeout)) { |
| 242 | result = -ETIMEDOUT; |
| 243 | goto exit; |
| 244 | } |
| 245 | |
| 246 | /* check error flag - FIXME: not sure what this does - docs do not describe |
| 247 | * beyond "error flag for diseqc receive data :( */ |
| 248 | if (s5h1420_readreg(state, 0x49)) { |
| 249 | result = -EIO; |
| 250 | goto exit; |
| 251 | } |
| 252 | |
| 253 | /* check length */ |
| 254 | length = (s5h1420_readreg(state, 0x3b) & 0x70) >> 4; |
| 255 | if (length > sizeof(reply->msg)) { |
| 256 | result = -EOVERFLOW; |
| 257 | goto exit; |
| 258 | } |
| 259 | reply->msg_len = length; |
| 260 | |
| 261 | /* extract data */ |
| 262 | for(i=0; i< length; i++) { |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 263 | reply->msg[i] = s5h1420_readreg(state, 0x3d + i); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | exit: |
| 267 | /* restore original settings */ |
| 268 | s5h1420_writereg(state, 0x3b, val); |
| 269 | msleep(15); |
| 270 | return result; |
| 271 | } |
| 272 | |
| 273 | static int s5h1420_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minicmd) |
| 274 | { |
| 275 | struct s5h1420_state* state = fe->demodulator_priv; |
| 276 | u8 val; |
| 277 | int result = 0; |
| 278 | unsigned long timeout; |
| 279 | |
| 280 | /* setup for tone burst */ |
| 281 | val = s5h1420_readreg(state, 0x3b); |
| 282 | s5h1420_writereg(state, 0x3b, (s5h1420_readreg(state, 0x3b) & 0x70) | 0x01); |
| 283 | |
| 284 | /* set value for B position if requested */ |
| 285 | if (minicmd == SEC_MINI_B) { |
| 286 | s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | 0x04); |
| 287 | } |
| 288 | msleep(15); |
| 289 | |
| 290 | /* start transmission */ |
| 291 | s5h1420_writereg(state, 0x3b, s5h1420_readreg(state, 0x3b) | 0x08); |
| 292 | |
| 293 | /* wait for transmission to complete */ |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 294 | timeout = jiffies + ((100*HZ) / 1000); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 295 | while(time_before(jiffies, timeout)) { |
| 296 | if (!(s5h1420_readreg(state, 0x3b) & 0x08)) |
| 297 | break; |
| 298 | |
| 299 | msleep(5); |
| 300 | } |
| 301 | if (time_after(jiffies, timeout)) |
| 302 | result = -ETIMEDOUT; |
| 303 | |
| 304 | /* restore original settings */ |
| 305 | s5h1420_writereg(state, 0x3b, val); |
| 306 | msleep(15); |
| 307 | return result; |
| 308 | } |
| 309 | |
| 310 | static fe_status_t s5h1420_get_status_bits(struct s5h1420_state* state) |
| 311 | { |
| 312 | u8 val; |
| 313 | fe_status_t status = 0; |
| 314 | |
| 315 | val = s5h1420_readreg(state, 0x14); |
| 316 | if (val & 0x02) |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 317 | status |= FE_HAS_SIGNAL; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 318 | if (val & 0x01) |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 319 | status |= FE_HAS_CARRIER; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 320 | val = s5h1420_readreg(state, 0x36); |
| 321 | if (val & 0x01) |
| 322 | status |= FE_HAS_VITERBI; |
| 323 | if (val & 0x20) |
| 324 | status |= FE_HAS_SYNC; |
| 325 | if (status == (FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI|FE_HAS_SYNC)) |
| 326 | status |= FE_HAS_LOCK; |
| 327 | |
| 328 | return status; |
| 329 | } |
| 330 | |
| 331 | static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status) |
| 332 | { |
| 333 | struct s5h1420_state* state = fe->demodulator_priv; |
| 334 | u8 val; |
| 335 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 336 | dprintk("enter %s\n", __func__); |
| 337 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 338 | if (status == NULL) |
| 339 | return -EINVAL; |
| 340 | |
| 341 | /* determine lock state */ |
| 342 | *status = s5h1420_get_status_bits(state); |
| 343 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 344 | /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert |
| 345 | the inversion, wait a bit and check again */ |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 346 | if (*status == (FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI)) { |
| 347 | val = s5h1420_readreg(state, Vit10); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 348 | if ((val & 0x07) == 0x03) { |
| 349 | if (val & 0x08) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 350 | s5h1420_writereg(state, Vit09, 0x13); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 351 | else |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 352 | s5h1420_writereg(state, Vit09, 0x1b); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 353 | |
| 354 | /* wait a bit then update lock status */ |
| 355 | mdelay(200); |
| 356 | *status = s5h1420_get_status_bits(state); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /* perform post lock setup */ |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 361 | if ((*status & FE_HAS_LOCK) && !state->postlocked) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 362 | |
| 363 | /* calculate the data rate */ |
| 364 | u32 tmp = s5h1420_getsymbolrate(state); |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 365 | switch (s5h1420_readreg(state, Vit10) & 0x07) { |
| 366 | case 0: tmp = (tmp * 2 * 1) / 2; break; |
| 367 | case 1: tmp = (tmp * 2 * 2) / 3; break; |
| 368 | case 2: tmp = (tmp * 2 * 3) / 4; break; |
| 369 | case 3: tmp = (tmp * 2 * 5) / 6; break; |
| 370 | case 4: tmp = (tmp * 2 * 6) / 7; break; |
| 371 | case 5: tmp = (tmp * 2 * 7) / 8; break; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 372 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 373 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 374 | if (tmp == 0) { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 375 | printk(KERN_ERR "s5h1420: avoided division by 0\n"); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 376 | tmp = 1; |
| 377 | } |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 378 | tmp = state->fclk / tmp; |
| 379 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 380 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 381 | /* set the MPEG_CLK_INTL for the calculated data rate */ |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 382 | if (tmp < 2) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 383 | val = 0x00; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 384 | else if (tmp < 5) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 385 | val = 0x01; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 386 | else if (tmp < 9) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 387 | val = 0x02; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 388 | else if (tmp < 13) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 389 | val = 0x03; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 390 | else if (tmp < 17) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 391 | val = 0x04; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 392 | else if (tmp < 25) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 393 | val = 0x05; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 394 | else if (tmp < 33) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 395 | val = 0x06; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 396 | else |
| 397 | val = 0x07; |
| 398 | dprintk("for MPEG_CLK_INTL %d %x\n", tmp, val); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 399 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 400 | s5h1420_writereg(state, FEC01, 0x18); |
| 401 | s5h1420_writereg(state, FEC01, 0x10); |
| 402 | s5h1420_writereg(state, FEC01, val); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 403 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 404 | /* Enable "MPEG_Out" */ |
| 405 | val = s5h1420_readreg(state, Mpeg02); |
| 406 | s5h1420_writereg(state, Mpeg02, val | (1 << 6)); |
| 407 | |
| 408 | /* kicker disable */ |
| 409 | val = s5h1420_readreg(state, QPSK01) & 0x7f; |
| 410 | s5h1420_writereg(state, QPSK01, val); |
| 411 | |
| 412 | /* DC freeze TODO it was never activated by default or it can stay activated */ |
| 413 | |
| 414 | if (s5h1420_getsymbolrate(state) >= 20000000) { |
| 415 | s5h1420_writereg(state, Loop04, 0x8a); |
| 416 | s5h1420_writereg(state, Loop05, 0x6a); |
| 417 | } else { |
| 418 | s5h1420_writereg(state, Loop04, 0x58); |
| 419 | s5h1420_writereg(state, Loop05, 0x27); |
| 420 | } |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 421 | |
| 422 | /* post-lock processing has been done! */ |
| 423 | state->postlocked = 1; |
| 424 | } |
| 425 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 426 | dprintk("leave %s\n", __func__); |
| 427 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 428 | return 0; |
| 429 | } |
| 430 | |
| 431 | static int s5h1420_read_ber(struct dvb_frontend* fe, u32* ber) |
| 432 | { |
| 433 | struct s5h1420_state* state = fe->demodulator_priv; |
| 434 | |
| 435 | s5h1420_writereg(state, 0x46, 0x1d); |
| 436 | mdelay(25); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 437 | |
| 438 | *ber = (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47); |
| 439 | |
| 440 | return 0; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static int s5h1420_read_signal_strength(struct dvb_frontend* fe, u16* strength) |
| 444 | { |
| 445 | struct s5h1420_state* state = fe->demodulator_priv; |
| 446 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 447 | u8 val = s5h1420_readreg(state, 0x15); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 448 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 449 | *strength = (u16) ((val << 8) | val); |
| 450 | |
| 451 | return 0; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static int s5h1420_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) |
| 455 | { |
| 456 | struct s5h1420_state* state = fe->demodulator_priv; |
| 457 | |
| 458 | s5h1420_writereg(state, 0x46, 0x1f); |
| 459 | mdelay(25); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 460 | |
| 461 | *ucblocks = (s5h1420_readreg(state, 0x48) << 8) | s5h1420_readreg(state, 0x47); |
| 462 | |
| 463 | return 0; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void s5h1420_reset(struct s5h1420_state* state) |
| 467 | { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 468 | dprintk("%s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 469 | s5h1420_writereg (state, 0x01, 0x08); |
| 470 | s5h1420_writereg (state, 0x01, 0x00); |
| 471 | udelay(10); |
| 472 | } |
| 473 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 474 | static void s5h1420_setsymbolrate(struct s5h1420_state* state, |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 475 | struct dtv_frontend_properties *p) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 476 | { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 477 | u8 v; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 478 | u64 val; |
| 479 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 480 | dprintk("enter %s\n", __func__); |
| 481 | |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 482 | val = ((u64) p->symbol_rate / 1000ULL) * (1ULL<<24); |
| 483 | if (p->symbol_rate < 29000000) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 484 | val *= 2; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 485 | do_div(val, (state->fclk / 1000)); |
| 486 | |
Andrew Morton | d74bee8 | 2008-04-28 08:54:56 -0300 | [diff] [blame] | 487 | dprintk("symbol rate register: %06llx\n", (unsigned long long)val); |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 488 | |
| 489 | v = s5h1420_readreg(state, Loop01); |
| 490 | s5h1420_writereg(state, Loop01, v & 0x7f); |
| 491 | s5h1420_writereg(state, Tnco01, val >> 16); |
| 492 | s5h1420_writereg(state, Tnco02, val >> 8); |
| 493 | s5h1420_writereg(state, Tnco03, val & 0xff); |
| 494 | s5h1420_writereg(state, Loop01, v | 0x80); |
| 495 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static u32 s5h1420_getsymbolrate(struct s5h1420_state* state) |
| 499 | { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 500 | return state->symbol_rate; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | static void s5h1420_setfreqoffset(struct s5h1420_state* state, int freqoffset) |
| 504 | { |
| 505 | int val; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 506 | u8 v; |
| 507 | |
| 508 | dprintk("enter %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 509 | |
| 510 | /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so |
| 511 | * divide fclk by 1000000 to get the correct value. */ |
| 512 | val = -(int) ((freqoffset * (1<<24)) / (state->fclk / 1000000)); |
| 513 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 514 | dprintk("phase rotator/freqoffset: %d %06x\n", freqoffset, val); |
| 515 | |
| 516 | v = s5h1420_readreg(state, Loop01); |
| 517 | s5h1420_writereg(state, Loop01, v & 0xbf); |
| 518 | s5h1420_writereg(state, Pnco01, val >> 16); |
| 519 | s5h1420_writereg(state, Pnco02, val >> 8); |
| 520 | s5h1420_writereg(state, Pnco03, val & 0xff); |
| 521 | s5h1420_writereg(state, Loop01, v | 0x40); |
| 522 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static int s5h1420_getfreqoffset(struct s5h1420_state* state) |
| 526 | { |
| 527 | int val; |
| 528 | |
| 529 | s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) | 0x08); |
| 530 | val = s5h1420_readreg(state, 0x0e) << 16; |
| 531 | val |= s5h1420_readreg(state, 0x0f) << 8; |
| 532 | val |= s5h1420_readreg(state, 0x10); |
| 533 | s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) & 0xf7); |
| 534 | |
| 535 | if (val & 0x800000) |
| 536 | val |= 0xff000000; |
| 537 | |
| 538 | /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so |
| 539 | * divide fclk by 1000000 to get the correct value. */ |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 540 | val = (((-val) * (state->fclk/1000000)) / (1<<24)); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 541 | |
| 542 | return val; |
| 543 | } |
| 544 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 545 | static void s5h1420_setfec_inversion(struct s5h1420_state* state, |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 546 | struct dtv_frontend_properties *p) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 547 | { |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 548 | u8 inversion = 0; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 549 | u8 vit08, vit09; |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 550 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 551 | dprintk("enter %s\n", __func__); |
| 552 | |
| 553 | if (p->inversion == INVERSION_OFF) |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 554 | inversion = state->config->invert ? 0x08 : 0; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 555 | else if (p->inversion == INVERSION_ON) |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 556 | inversion = state->config->invert ? 0 : 0x08; |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 557 | |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 558 | if ((p->fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 559 | vit08 = 0x3f; |
| 560 | vit09 = 0; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 561 | } else { |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 562 | switch (p->fec_inner) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 563 | case FEC_1_2: |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 564 | vit08 = 0x01; vit09 = 0x10; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 565 | break; |
| 566 | |
| 567 | case FEC_2_3: |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 568 | vit08 = 0x02; vit09 = 0x11; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 569 | break; |
| 570 | |
| 571 | case FEC_3_4: |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 572 | vit08 = 0x04; vit09 = 0x12; |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 573 | break; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 574 | |
| 575 | case FEC_5_6: |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 576 | vit08 = 0x08; vit09 = 0x13; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 577 | break; |
| 578 | |
| 579 | case FEC_6_7: |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 580 | vit08 = 0x10; vit09 = 0x14; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 581 | break; |
| 582 | |
| 583 | case FEC_7_8: |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 584 | vit08 = 0x20; vit09 = 0x15; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 585 | break; |
| 586 | |
| 587 | default: |
| 588 | return; |
| 589 | } |
| 590 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 591 | vit09 |= inversion; |
| 592 | dprintk("fec: %02x %02x\n", vit08, vit09); |
| 593 | s5h1420_writereg(state, Vit08, vit08); |
| 594 | s5h1420_writereg(state, Vit09, vit09); |
| 595 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state) |
| 599 | { |
| 600 | switch(s5h1420_readreg(state, 0x32) & 0x07) { |
| 601 | case 0: |
| 602 | return FEC_1_2; |
| 603 | |
| 604 | case 1: |
| 605 | return FEC_2_3; |
| 606 | |
| 607 | case 2: |
| 608 | return FEC_3_4; |
| 609 | |
| 610 | case 3: |
| 611 | return FEC_5_6; |
| 612 | |
| 613 | case 4: |
| 614 | return FEC_6_7; |
| 615 | |
| 616 | case 5: |
| 617 | return FEC_7_8; |
| 618 | } |
| 619 | |
| 620 | return FEC_NONE; |
| 621 | } |
| 622 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 623 | static fe_spectral_inversion_t s5h1420_getinversion(struct s5h1420_state* state) |
| 624 | { |
| 625 | if (s5h1420_readreg(state, 0x32) & 0x08) |
| 626 | return INVERSION_ON; |
| 627 | |
| 628 | return INVERSION_OFF; |
| 629 | } |
| 630 | |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 631 | static int s5h1420_set_frontend(struct dvb_frontend *fe) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 632 | { |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 633 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 634 | struct s5h1420_state* state = fe->demodulator_priv; |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 635 | int frequency_delta; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 636 | struct dvb_frontend_tune_settings fesettings; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 637 | |
| 638 | dprintk("enter %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 639 | |
| 640 | /* check if we should do a fast-tune */ |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 641 | s5h1420_get_tune_settings(fe, &fesettings); |
| 642 | frequency_delta = p->frequency - state->tunedfreq; |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 643 | if ((frequency_delta > -fesettings.max_drift) && |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 644 | (frequency_delta < fesettings.max_drift) && |
| 645 | (frequency_delta != 0) && |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 646 | (state->fec_inner == p->fec_inner) && |
| 647 | (state->symbol_rate == p->symbol_rate)) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 648 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 649 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 650 | fe->ops.tuner_ops.set_params(fe); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 651 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | a98af22 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 652 | } |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 653 | if (fe->ops.tuner_ops.get_frequency) { |
Andrew de Quincey | a98af22 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 654 | u32 tmp; |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 655 | fe->ops.tuner_ops.get_frequency(fe, &tmp); |
| 656 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 657 | s5h1420_setfreqoffset(state, p->frequency - tmp); |
Andrew de Quincey | a98af22 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 658 | } else { |
| 659 | s5h1420_setfreqoffset(state, 0); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 660 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 661 | dprintk("simple tune\n"); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 662 | return 0; |
| 663 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 664 | dprintk("tuning demod\n"); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 665 | |
| 666 | /* first of all, software reset */ |
| 667 | s5h1420_reset(state); |
| 668 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 669 | /* set s5h1420 fclk PLL according to desired symbol rate */ |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 670 | if (p->symbol_rate > 33000000) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 671 | state->fclk = 80000000; |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 672 | else if (p->symbol_rate > 28500000) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 673 | state->fclk = 59000000; |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 674 | else if (p->symbol_rate > 25000000) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 675 | state->fclk = 86000000; |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 676 | else if (p->symbol_rate > 1900000) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 677 | state->fclk = 88000000; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 678 | else |
| 679 | state->fclk = 44000000; |
| 680 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 681 | dprintk("pll01: %d, ToneFreq: %d\n", state->fclk/1000000 - 8, (state->fclk + (TONE_FREQ * 32) - 1) / (TONE_FREQ * 32)); |
| 682 | s5h1420_writereg(state, PLL01, state->fclk/1000000 - 8); |
| 683 | s5h1420_writereg(state, PLL02, 0x40); |
| 684 | s5h1420_writereg(state, DiS01, (state->fclk + (TONE_FREQ * 32) - 1) / (TONE_FREQ * 32)); |
| 685 | |
| 686 | /* TODO DC offset removal, config parameter ? */ |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 687 | if (p->symbol_rate > 29000000) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 688 | s5h1420_writereg(state, QPSK01, 0xae | 0x10); |
| 689 | else |
| 690 | s5h1420_writereg(state, QPSK01, 0xac | 0x10); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 691 | |
| 692 | /* set misc registers */ |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 693 | s5h1420_writereg(state, CON_1, 0x00); |
| 694 | s5h1420_writereg(state, QPSK02, 0x00); |
| 695 | s5h1420_writereg(state, Pre01, 0xb0); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 696 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 697 | s5h1420_writereg(state, Loop01, 0xF0); |
| 698 | s5h1420_writereg(state, Loop02, 0x2a); /* e7 for s5h1420 */ |
| 699 | s5h1420_writereg(state, Loop03, 0x79); /* 78 for s5h1420 */ |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 700 | if (p->symbol_rate > 20000000) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 701 | s5h1420_writereg(state, Loop04, 0x79); |
| 702 | else |
| 703 | s5h1420_writereg(state, Loop04, 0x58); |
| 704 | s5h1420_writereg(state, Loop05, 0x6b); |
| 705 | |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 706 | if (p->symbol_rate >= 8000000) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 707 | s5h1420_writereg(state, Post01, (0 << 6) | 0x10); |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 708 | else if (p->symbol_rate >= 4000000) |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 709 | s5h1420_writereg(state, Post01, (1 << 6) | 0x10); |
| 710 | else |
| 711 | s5h1420_writereg(state, Post01, (3 << 6) | 0x10); |
| 712 | |
| 713 | s5h1420_writereg(state, Monitor12, 0x00); /* unfreeze DC compensation */ |
| 714 | |
| 715 | s5h1420_writereg(state, Sync01, 0x33); |
| 716 | s5h1420_writereg(state, Mpeg01, state->config->cdclk_polarity); |
| 717 | s5h1420_writereg(state, Mpeg02, 0x3d); /* Parallel output more, disabled -> enabled later */ |
| 718 | s5h1420_writereg(state, Err01, 0x03); /* 0x1d for s5h1420 */ |
| 719 | |
| 720 | s5h1420_writereg(state, Vit06, 0x6e); /* 0x8e for s5h1420 */ |
| 721 | s5h1420_writereg(state, DiS03, 0x00); |
| 722 | s5h1420_writereg(state, Rf01, 0x61); /* Tuner i2c address - for the gate controller */ |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 723 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 724 | /* set tuner PLL */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 725 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 726 | fe->ops.tuner_ops.set_params(fe); |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 727 | if (fe->ops.i2c_gate_ctrl) |
| 728 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 729 | s5h1420_setfreqoffset(state, 0); |
| 730 | } |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 731 | |
| 732 | /* set the reset of the parameters */ |
| 733 | s5h1420_setsymbolrate(state, p); |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 734 | s5h1420_setfec_inversion(state, p); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 735 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 736 | /* start QPSK */ |
| 737 | s5h1420_writereg(state, QPSK01, s5h1420_readreg(state, QPSK01) | 1); |
| 738 | |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 739 | state->fec_inner = p->fec_inner; |
| 740 | state->symbol_rate = p->symbol_rate; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 741 | state->postlocked = 0; |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 742 | state->tunedfreq = p->frequency; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 743 | |
| 744 | dprintk("leave %s\n", __func__); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 748 | static int s5h1420_get_frontend(struct dvb_frontend* fe) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 749 | { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 750 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 751 | struct s5h1420_state* state = fe->demodulator_priv; |
| 752 | |
| 753 | p->frequency = state->tunedfreq + s5h1420_getfreqoffset(state); |
| 754 | p->inversion = s5h1420_getinversion(state); |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 755 | p->symbol_rate = s5h1420_getsymbolrate(state); |
| 756 | p->fec_inner = s5h1420_getfec(state); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 757 | |
| 758 | return 0; |
| 759 | } |
| 760 | |
Andrew de Quincey | a9d6a80 | 2005-09-09 13:02:31 -0700 | [diff] [blame] | 761 | static int s5h1420_get_tune_settings(struct dvb_frontend* fe, |
| 762 | struct dvb_frontend_tune_settings* fesettings) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 763 | { |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 764 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 765 | if (p->symbol_rate > 20000000) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 766 | fesettings->min_delay_ms = 50; |
| 767 | fesettings->step_size = 2000; |
| 768 | fesettings->max_drift = 8000; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 769 | } else if (p->symbol_rate > 12000000) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 770 | fesettings->min_delay_ms = 100; |
| 771 | fesettings->step_size = 1500; |
| 772 | fesettings->max_drift = 9000; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 773 | } else if (p->symbol_rate > 8000000) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 774 | fesettings->min_delay_ms = 100; |
| 775 | fesettings->step_size = 1000; |
| 776 | fesettings->max_drift = 8000; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 777 | } else if (p->symbol_rate > 4000000) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 778 | fesettings->min_delay_ms = 100; |
| 779 | fesettings->step_size = 500; |
| 780 | fesettings->max_drift = 7000; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 781 | } else if (p->symbol_rate > 2000000) { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 782 | fesettings->min_delay_ms = 200; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 783 | fesettings->step_size = (p->symbol_rate / 8000); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 784 | fesettings->max_drift = 14 * fesettings->step_size; |
| 785 | } else { |
| 786 | fesettings->min_delay_ms = 200; |
Mauro Carvalho Chehab | 5581e13 | 2011-12-26 16:59:09 -0300 | [diff] [blame] | 787 | fesettings->step_size = (p->symbol_rate / 8000); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 788 | fesettings->max_drift = 18 * fesettings->step_size; |
| 789 | } |
| 790 | |
| 791 | return 0; |
| 792 | } |
| 793 | |
Andrew de Quincey | a98af22 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 794 | static int s5h1420_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) |
| 795 | { |
| 796 | struct s5h1420_state* state = fe->demodulator_priv; |
| 797 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 798 | if (enable) |
| 799 | return s5h1420_writereg(state, 0x02, state->CON_1_val | 1); |
| 800 | else |
| 801 | return s5h1420_writereg(state, 0x02, state->CON_1_val & 0xfe); |
Andrew de Quincey | a98af22 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 802 | } |
| 803 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 804 | static int s5h1420_init (struct dvb_frontend* fe) |
| 805 | { |
| 806 | struct s5h1420_state* state = fe->demodulator_priv; |
| 807 | |
| 808 | /* disable power down and do reset */ |
Patrick Boettcher | c18c5ff | 2008-09-06 13:31:58 -0300 | [diff] [blame] | 809 | state->CON_1_val = state->config->serial_mpeg << 4; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 810 | s5h1420_writereg(state, 0x02, state->CON_1_val); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 811 | msleep(10); |
| 812 | s5h1420_reset(state); |
| 813 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 814 | return 0; |
| 815 | } |
| 816 | |
| 817 | static int s5h1420_sleep(struct dvb_frontend* fe) |
| 818 | { |
| 819 | struct s5h1420_state* state = fe->demodulator_priv; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 820 | state->CON_1_val = 0x12; |
| 821 | return s5h1420_writereg(state, 0x02, state->CON_1_val); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 822 | } |
| 823 | |
| 824 | static void s5h1420_release(struct dvb_frontend* fe) |
| 825 | { |
| 826 | struct s5h1420_state* state = fe->demodulator_priv; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 827 | i2c_del_adapter(&state->tuner_i2c_adapter); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 828 | kfree(state); |
| 829 | } |
| 830 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 831 | static u32 s5h1420_tuner_i2c_func(struct i2c_adapter *adapter) |
| 832 | { |
| 833 | return I2C_FUNC_I2C; |
| 834 | } |
| 835 | |
| 836 | static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num) |
| 837 | { |
| 838 | struct s5h1420_state *state = i2c_get_adapdata(i2c_adap); |
Mauro Carvalho Chehab | 9736a89 | 2013-11-02 04:29:42 -0300 | [diff] [blame] | 839 | struct i2c_msg m[3]; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 840 | u8 tx_open[2] = { CON_1, state->CON_1_val | 1 }; /* repeater stops once there was a stop condition */ |
| 841 | |
Mauro Carvalho Chehab | 9736a89 | 2013-11-02 04:29:42 -0300 | [diff] [blame] | 842 | if (1 + num > ARRAY_SIZE(m)) { |
| 843 | printk(KERN_WARNING |
| 844 | "%s: i2c xfer: num=%d is too big!\n", |
| 845 | KBUILD_MODNAME, num); |
| 846 | return -EOPNOTSUPP; |
| 847 | } |
| 848 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 849 | memset(m, 0, sizeof(struct i2c_msg) * (1 + num)); |
| 850 | |
| 851 | m[0].addr = state->config->demod_address; |
| 852 | m[0].buf = tx_open; |
| 853 | m[0].len = 2; |
| 854 | |
| 855 | memcpy(&m[1], msg, sizeof(struct i2c_msg) * num); |
| 856 | |
Mauro Carvalho Chehab | 9736a89 | 2013-11-02 04:29:42 -0300 | [diff] [blame] | 857 | return i2c_transfer(state->i2c, m, 1 + num) == 1 + num ? num : -EIO; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | static struct i2c_algorithm s5h1420_tuner_i2c_algo = { |
| 861 | .master_xfer = s5h1420_tuner_i2c_tuner_xfer, |
| 862 | .functionality = s5h1420_tuner_i2c_func, |
| 863 | }; |
| 864 | |
| 865 | struct i2c_adapter *s5h1420_get_tuner_i2c_adapter(struct dvb_frontend *fe) |
| 866 | { |
| 867 | struct s5h1420_state *state = fe->demodulator_priv; |
| 868 | return &state->tuner_i2c_adapter; |
| 869 | } |
| 870 | EXPORT_SYMBOL(s5h1420_get_tuner_i2c_adapter); |
| 871 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 872 | static struct dvb_frontend_ops s5h1420_ops; |
| 873 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 874 | struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config, |
| 875 | struct i2c_adapter *i2c) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 876 | { |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 877 | /* allocate memory for the internal state */ |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 878 | struct s5h1420_state *state = kzalloc(sizeof(struct s5h1420_state), GFP_KERNEL); |
| 879 | u8 i; |
| 880 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 881 | if (state == NULL) |
| 882 | goto error; |
| 883 | |
| 884 | /* setup the state */ |
| 885 | state->config = config; |
| 886 | state->i2c = i2c; |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 887 | state->postlocked = 0; |
| 888 | state->fclk = 88000000; |
| 889 | state->tunedfreq = 0; |
| 890 | state->fec_inner = FEC_NONE; |
| 891 | state->symbol_rate = 0; |
| 892 | |
| 893 | /* check if the demod is there + identify it */ |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 894 | i = s5h1420_readreg(state, ID01); |
| 895 | if (i != 0x03) |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 896 | goto error; |
| 897 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 898 | memset(state->shadow, 0xff, sizeof(state->shadow)); |
| 899 | |
| 900 | for (i = 0; i < 0x50; i++) |
| 901 | state->shadow[i] = s5h1420_readreg(state, i); |
| 902 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 903 | /* create dvb_frontend */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 904 | memcpy(&state->frontend.ops, &s5h1420_ops, sizeof(struct dvb_frontend_ops)); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 905 | state->frontend.demodulator_priv = state; |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 906 | |
| 907 | /* create tuner i2c adapter */ |
Jean Delvare | 1d43401 | 2008-09-03 17:12:23 -0300 | [diff] [blame] | 908 | strlcpy(state->tuner_i2c_adapter.name, "S5H1420-PN1010 tuner I2C bus", |
| 909 | sizeof(state->tuner_i2c_adapter.name)); |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 910 | state->tuner_i2c_adapter.algo = &s5h1420_tuner_i2c_algo; |
| 911 | state->tuner_i2c_adapter.algo_data = NULL; |
| 912 | i2c_set_adapdata(&state->tuner_i2c_adapter, state); |
| 913 | if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) { |
| 914 | printk(KERN_ERR "S5H1420/PN1010: tuner i2c bus could not be initialized\n"); |
| 915 | goto error; |
| 916 | } |
| 917 | |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 918 | return &state->frontend; |
| 919 | |
| 920 | error: |
| 921 | kfree(state); |
| 922 | return NULL; |
| 923 | } |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 924 | EXPORT_SYMBOL(s5h1420_attach); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 925 | |
| 926 | static struct dvb_frontend_ops s5h1420_ops = { |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 927 | .delsys = { SYS_DVBS }, |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 928 | .info = { |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 929 | .name = "Samsung S5H1420/PnpNetwork PN1010 DVB-S", |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 930 | .frequency_min = 950000, |
| 931 | .frequency_max = 2150000, |
| 932 | .frequency_stepsize = 125, /* kHz for QPSK frontends */ |
| 933 | .frequency_tolerance = 29500, |
| 934 | .symbol_rate_min = 1000000, |
| 935 | .symbol_rate_max = 45000000, |
| 936 | /* .symbol_rate_tolerance = ???,*/ |
| 937 | .caps = FE_CAN_INVERSION_AUTO | |
| 938 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 939 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
| 940 | FE_CAN_QPSK |
| 941 | }, |
| 942 | |
| 943 | .release = s5h1420_release, |
| 944 | |
| 945 | .init = s5h1420_init, |
| 946 | .sleep = s5h1420_sleep, |
Andrew de Quincey | a98af22 | 2006-04-18 17:47:10 -0300 | [diff] [blame] | 947 | .i2c_gate_ctrl = s5h1420_i2c_gate_ctrl, |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 948 | |
Mauro Carvalho Chehab | 9f69afb | 2011-12-26 14:07:00 -0300 | [diff] [blame] | 949 | .set_frontend = s5h1420_set_frontend, |
| 950 | .get_frontend = s5h1420_get_frontend, |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 951 | .get_tune_settings = s5h1420_get_tune_settings, |
| 952 | |
| 953 | .read_status = s5h1420_read_status, |
| 954 | .read_ber = s5h1420_read_ber, |
| 955 | .read_signal_strength = s5h1420_read_signal_strength, |
| 956 | .read_ucblocks = s5h1420_read_ucblocks, |
| 957 | |
| 958 | .diseqc_send_master_cmd = s5h1420_send_master_cmd, |
| 959 | .diseqc_recv_slave_reply = s5h1420_recv_slave_reply, |
| 960 | .diseqc_send_burst = s5h1420_send_burst, |
| 961 | .set_tone = s5h1420_set_tone, |
| 962 | .set_voltage = s5h1420_set_voltage, |
| 963 | }; |
| 964 | |
Patrick Boettcher | dbad108 | 2008-04-13 15:47:53 -0300 | [diff] [blame] | 965 | MODULE_DESCRIPTION("Samsung S5H1420/PnpNetwork PN1010 DVB-S Demodulator driver"); |
| 966 | MODULE_AUTHOR("Andrew de Quincey, Patrick Boettcher"); |
Andrew de Quincey | 96bf2f2 | 2005-07-07 17:57:53 -0700 | [diff] [blame] | 967 | MODULE_LICENSE("GPL"); |