Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1 | /* |
| 2 | * stv0900_core.c |
| 3 | * |
| 4 | * Driver for ST STV0900 satellite demodulator IC. |
| 5 | * |
| 6 | * Copyright (C) ST Microelectronics. |
| 7 | * Copyright (C) 2009 NetUP Inc. |
| 8 | * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/string.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/i2c.h> |
| 31 | |
| 32 | #include "stv0900.h" |
| 33 | #include "stv0900_reg.h" |
| 34 | #include "stv0900_priv.h" |
| 35 | #include "stv0900_init.h" |
| 36 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 37 | int stvdebug = 1; |
Randy Dunlap | 5a771cb | 2009-03-08 23:01:08 -0300 | [diff] [blame] | 38 | module_param_named(debug, stvdebug, int, 0644); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 39 | |
| 40 | /* internal params node */ |
| 41 | struct stv0900_inode { |
| 42 | /* pointer for internal params, one for each pair of demods */ |
| 43 | struct stv0900_internal *internal; |
| 44 | struct stv0900_inode *next_inode; |
| 45 | }; |
| 46 | |
| 47 | /* first internal params */ |
| 48 | static struct stv0900_inode *stv0900_first_inode; |
| 49 | |
| 50 | /* find chip by i2c adapter and i2c address */ |
| 51 | static struct stv0900_inode *find_inode(struct i2c_adapter *i2c_adap, |
| 52 | u8 i2c_addr) |
| 53 | { |
| 54 | struct stv0900_inode *temp_chip = stv0900_first_inode; |
| 55 | |
| 56 | if (temp_chip != NULL) { |
| 57 | /* |
| 58 | Search of the last stv0900 chip or |
| 59 | find it by i2c adapter and i2c address */ |
| 60 | while ((temp_chip != NULL) && |
| 61 | ((temp_chip->internal->i2c_adap != i2c_adap) || |
Igor M. Liplianin | 78175bf | 2009-03-06 19:32:54 -0300 | [diff] [blame] | 62 | (temp_chip->internal->i2c_addr != i2c_addr))) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 63 | |
| 64 | temp_chip = temp_chip->next_inode; |
Igor M. Liplianin | 78175bf | 2009-03-06 19:32:54 -0300 | [diff] [blame] | 65 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | return temp_chip; |
| 69 | } |
| 70 | |
| 71 | /* deallocating chip */ |
| 72 | static void remove_inode(struct stv0900_internal *internal) |
| 73 | { |
| 74 | struct stv0900_inode *prev_node = stv0900_first_inode; |
| 75 | struct stv0900_inode *del_node = find_inode(internal->i2c_adap, |
| 76 | internal->i2c_addr); |
| 77 | |
| 78 | if (del_node != NULL) { |
| 79 | if (del_node == stv0900_first_inode) { |
| 80 | stv0900_first_inode = del_node->next_inode; |
| 81 | } else { |
| 82 | while (prev_node->next_inode != del_node) |
| 83 | prev_node = prev_node->next_inode; |
| 84 | |
| 85 | if (del_node->next_inode == NULL) |
| 86 | prev_node->next_inode = NULL; |
| 87 | else |
| 88 | prev_node->next_inode = |
| 89 | prev_node->next_inode->next_inode; |
| 90 | } |
| 91 | |
| 92 | kfree(del_node); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /* allocating new chip */ |
| 97 | static struct stv0900_inode *append_internal(struct stv0900_internal *internal) |
| 98 | { |
| 99 | struct stv0900_inode *new_node = stv0900_first_inode; |
| 100 | |
| 101 | if (new_node == NULL) { |
| 102 | new_node = kmalloc(sizeof(struct stv0900_inode), GFP_KERNEL); |
| 103 | stv0900_first_inode = new_node; |
| 104 | } else { |
| 105 | while (new_node->next_inode != NULL) |
| 106 | new_node = new_node->next_inode; |
| 107 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 108 | new_node->next_inode = kmalloc(sizeof(struct stv0900_inode), |
| 109 | GFP_KERNEL); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 110 | if (new_node->next_inode != NULL) |
| 111 | new_node = new_node->next_inode; |
| 112 | else |
| 113 | new_node = NULL; |
| 114 | } |
| 115 | |
| 116 | if (new_node != NULL) { |
| 117 | new_node->internal = internal; |
| 118 | new_node->next_inode = NULL; |
| 119 | } |
| 120 | |
| 121 | return new_node; |
| 122 | } |
| 123 | |
| 124 | s32 ge2comp(s32 a, s32 width) |
| 125 | { |
| 126 | if (width == 32) |
| 127 | return a; |
| 128 | else |
| 129 | return (a >= (1 << (width - 1))) ? (a - (1 << width)) : a; |
| 130 | } |
| 131 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 132 | void stv0900_write_reg(struct stv0900_internal *intp, u16 reg_addr, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 133 | u8 reg_data) |
| 134 | { |
| 135 | u8 data[3]; |
| 136 | int ret; |
| 137 | struct i2c_msg i2cmsg = { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 138 | .addr = intp->i2c_addr, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 139 | .flags = 0, |
| 140 | .len = 3, |
| 141 | .buf = data, |
| 142 | }; |
| 143 | |
| 144 | data[0] = MSB(reg_addr); |
| 145 | data[1] = LSB(reg_addr); |
| 146 | data[2] = reg_data; |
| 147 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 148 | ret = i2c_transfer(intp->i2c_adap, &i2cmsg, 1); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 149 | if (ret != 1) |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 150 | dprintk("%s: i2c error %d\n", __func__, ret); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 151 | } |
| 152 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 153 | u8 stv0900_read_reg(struct stv0900_internal *intp, u16 reg) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 154 | { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 155 | int ret; |
Abylay Ospan | 68191ed | 2009-06-14 14:10:05 -0300 | [diff] [blame] | 156 | u8 b0[] = { MSB(reg), LSB(reg) }; |
| 157 | u8 buf = 0; |
| 158 | struct i2c_msg msg[] = { |
| 159 | { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 160 | .addr = intp->i2c_addr, |
Abylay Ospan | 68191ed | 2009-06-14 14:10:05 -0300 | [diff] [blame] | 161 | .flags = 0, |
| 162 | .buf = b0, |
| 163 | .len = 2, |
| 164 | }, { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 165 | .addr = intp->i2c_addr, |
Abylay Ospan | 68191ed | 2009-06-14 14:10:05 -0300 | [diff] [blame] | 166 | .flags = I2C_M_RD, |
| 167 | .buf = &buf, |
| 168 | .len = 1, |
| 169 | }, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 170 | }; |
| 171 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 172 | ret = i2c_transfer(intp->i2c_adap, msg, 2); |
Abylay Ospan | 68191ed | 2009-06-14 14:10:05 -0300 | [diff] [blame] | 173 | if (ret != 2) |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 174 | dprintk("%s: i2c error %d, reg[0x%02x]\n", |
Abylay Ospan | 68191ed | 2009-06-14 14:10:05 -0300 | [diff] [blame] | 175 | __func__, ret, reg); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 176 | |
Abylay Ospan | 68191ed | 2009-06-14 14:10:05 -0300 | [diff] [blame] | 177 | return buf; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 178 | } |
| 179 | |
Márton Németh | 936c05e | 2010-01-16 13:41:43 -0300 | [diff] [blame] | 180 | static void extract_mask_pos(u32 label, u8 *mask, u8 *pos) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 181 | { |
| 182 | u8 position = 0, i = 0; |
| 183 | |
| 184 | (*mask) = label & 0xff; |
| 185 | |
| 186 | while ((position == 0) && (i < 8)) { |
| 187 | position = ((*mask) >> i) & 0x01; |
| 188 | i++; |
| 189 | } |
| 190 | |
| 191 | (*pos) = (i - 1); |
| 192 | } |
| 193 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 194 | void stv0900_write_bits(struct stv0900_internal *intp, u32 label, u8 val) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 195 | { |
| 196 | u8 reg, mask, pos; |
| 197 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 198 | reg = stv0900_read_reg(intp, (label >> 16) & 0xffff); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 199 | extract_mask_pos(label, &mask, &pos); |
| 200 | |
| 201 | val = mask & (val << pos); |
| 202 | |
| 203 | reg = (reg & (~mask)) | val; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 204 | stv0900_write_reg(intp, (label >> 16) & 0xffff, reg); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 205 | |
| 206 | } |
| 207 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 208 | u8 stv0900_get_bits(struct stv0900_internal *intp, u32 label) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 209 | { |
| 210 | u8 val = 0xff; |
| 211 | u8 mask, pos; |
| 212 | |
| 213 | extract_mask_pos(label, &mask, &pos); |
| 214 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 215 | val = stv0900_read_reg(intp, label >> 16); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 216 | val = (val & mask) >> pos; |
| 217 | |
| 218 | return val; |
| 219 | } |
| 220 | |
Márton Németh | 936c05e | 2010-01-16 13:41:43 -0300 | [diff] [blame] | 221 | static enum fe_stv0900_error stv0900_initialize(struct stv0900_internal *intp) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 222 | { |
| 223 | s32 i; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 224 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 225 | if (intp == NULL) |
| 226 | return STV0900_INVALID_HANDLE; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 227 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 228 | intp->chip_id = stv0900_read_reg(intp, R0900_MID); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 229 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 230 | if (intp->errs != STV0900_NO_ERROR) |
| 231 | return intp->errs; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 232 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 233 | /*Startup sequence*/ |
| 234 | stv0900_write_reg(intp, R0900_P1_DMDISTATE, 0x5c); |
| 235 | stv0900_write_reg(intp, R0900_P2_DMDISTATE, 0x5c); |
| 236 | msleep(3); |
| 237 | stv0900_write_reg(intp, R0900_P1_TNRCFG, 0x6c); |
| 238 | stv0900_write_reg(intp, R0900_P2_TNRCFG, 0x6f); |
| 239 | stv0900_write_reg(intp, R0900_P1_I2CRPT, 0x20); |
| 240 | stv0900_write_reg(intp, R0900_P2_I2CRPT, 0x20); |
| 241 | stv0900_write_reg(intp, R0900_NCOARSE, 0x13); |
| 242 | msleep(3); |
| 243 | stv0900_write_reg(intp, R0900_I2CCFG, 0x08); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 244 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 245 | switch (intp->clkmode) { |
| 246 | case 0: |
| 247 | case 2: |
| 248 | stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 |
| 249 | | intp->clkmode); |
| 250 | break; |
| 251 | default: |
| 252 | /* preserve SELOSCI bit */ |
| 253 | i = 0x02 & stv0900_read_reg(intp, R0900_SYNTCTRL); |
| 254 | stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 | i); |
| 255 | break; |
| 256 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 257 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 258 | msleep(3); |
| 259 | for (i = 0; i < 181; i++) |
| 260 | stv0900_write_reg(intp, STV0900_InitVal[i][0], |
| 261 | STV0900_InitVal[i][1]); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 262 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 263 | if (stv0900_read_reg(intp, R0900_MID) >= 0x20) { |
| 264 | stv0900_write_reg(intp, R0900_TSGENERAL, 0x0c); |
| 265 | for (i = 0; i < 32; i++) |
| 266 | stv0900_write_reg(intp, STV0900_Cut20_AddOnVal[i][0], |
| 267 | STV0900_Cut20_AddOnVal[i][1]); |
| 268 | } |
| 269 | |
| 270 | stv0900_write_reg(intp, R0900_P1_FSPYCFG, 0x6c); |
| 271 | stv0900_write_reg(intp, R0900_P2_FSPYCFG, 0x6c); |
| 272 | |
| 273 | stv0900_write_reg(intp, R0900_P1_PDELCTRL2, 0x01); |
| 274 | stv0900_write_reg(intp, R0900_P2_PDELCTRL2, 0x21); |
| 275 | |
| 276 | stv0900_write_reg(intp, R0900_P1_PDELCTRL3, 0x20); |
| 277 | stv0900_write_reg(intp, R0900_P2_PDELCTRL3, 0x20); |
| 278 | |
| 279 | stv0900_write_reg(intp, R0900_TSTRES0, 0x80); |
| 280 | stv0900_write_reg(intp, R0900_TSTRES0, 0x00); |
| 281 | |
| 282 | return STV0900_NO_ERROR; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 283 | } |
| 284 | |
Márton Németh | 936c05e | 2010-01-16 13:41:43 -0300 | [diff] [blame] | 285 | static u32 stv0900_get_mclk_freq(struct stv0900_internal *intp, u32 ext_clk) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 286 | { |
| 287 | u32 mclk = 90000000, div = 0, ad_div = 0; |
| 288 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 289 | div = stv0900_get_bits(intp, F0900_M_DIV); |
| 290 | ad_div = ((stv0900_get_bits(intp, F0900_SELX1RATIO) == 1) ? 4 : 6); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 291 | |
| 292 | mclk = (div + 1) * ext_clk / ad_div; |
| 293 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 294 | dprintk("%s: Calculated Mclk = %d\n", __func__, mclk); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 295 | |
| 296 | return mclk; |
| 297 | } |
| 298 | |
Márton Németh | 936c05e | 2010-01-16 13:41:43 -0300 | [diff] [blame] | 299 | static enum fe_stv0900_error stv0900_set_mclk(struct stv0900_internal *intp, u32 mclk) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 300 | { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 301 | u32 m_div, clk_sel; |
| 302 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 303 | if (intp == NULL) |
| 304 | return STV0900_INVALID_HANDLE; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 305 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 306 | if (intp->errs) |
| 307 | return STV0900_I2C_ERROR; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 308 | |
Wei Yongjun | b0f9bf3 | 2012-10-08 08:35:56 -0300 | [diff] [blame] | 309 | dprintk("%s: Mclk set to %d, Quartz = %d\n", __func__, mclk, |
| 310 | intp->quartz); |
| 311 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 312 | clk_sel = ((stv0900_get_bits(intp, F0900_SELX1RATIO) == 1) ? 4 : 6); |
| 313 | m_div = ((clk_sel * mclk) / intp->quartz) - 1; |
| 314 | stv0900_write_bits(intp, F0900_M_DIV, m_div); |
| 315 | intp->mclk = stv0900_get_mclk_freq(intp, |
| 316 | intp->quartz); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 317 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 318 | /*Set the DiseqC frequency to 22KHz */ |
| 319 | /* |
| 320 | Formula: |
| 321 | DiseqC_TX_Freq= MasterClock/(32*F22TX_Reg) |
| 322 | DiseqC_RX_Freq= MasterClock/(32*F22RX_Reg) |
| 323 | */ |
| 324 | m_div = intp->mclk / 704000; |
| 325 | stv0900_write_reg(intp, R0900_P1_F22TX, m_div); |
| 326 | stv0900_write_reg(intp, R0900_P1_F22RX, m_div); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 327 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 328 | stv0900_write_reg(intp, R0900_P2_F22TX, m_div); |
| 329 | stv0900_write_reg(intp, R0900_P2_F22RX, m_div); |
| 330 | |
| 331 | if ((intp->errs)) |
| 332 | return STV0900_I2C_ERROR; |
| 333 | |
| 334 | return STV0900_NO_ERROR; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 335 | } |
| 336 | |
Márton Németh | 936c05e | 2010-01-16 13:41:43 -0300 | [diff] [blame] | 337 | static u32 stv0900_get_err_count(struct stv0900_internal *intp, int cntr, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 338 | enum fe_stv0900_demod_num demod) |
| 339 | { |
| 340 | u32 lsb, msb, hsb, err_val; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 341 | |
| 342 | switch (cntr) { |
| 343 | case 0: |
| 344 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 345 | hsb = stv0900_get_bits(intp, ERR_CNT12); |
| 346 | msb = stv0900_get_bits(intp, ERR_CNT11); |
| 347 | lsb = stv0900_get_bits(intp, ERR_CNT10); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 348 | break; |
| 349 | case 1: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 350 | hsb = stv0900_get_bits(intp, ERR_CNT22); |
| 351 | msb = stv0900_get_bits(intp, ERR_CNT21); |
| 352 | lsb = stv0900_get_bits(intp, ERR_CNT20); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 353 | break; |
| 354 | } |
| 355 | |
| 356 | err_val = (hsb << 16) + (msb << 8) + (lsb); |
| 357 | |
| 358 | return err_val; |
| 359 | } |
| 360 | |
| 361 | static int stv0900_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 362 | { |
| 363 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 364 | struct stv0900_internal *intp = state->internal; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 365 | enum fe_stv0900_demod_num demod = state->demod; |
| 366 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 367 | stv0900_write_bits(intp, I2CT_ON, enable); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 372 | static void stv0900_set_ts_parallel_serial(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 373 | enum fe_stv0900_clock_type path1_ts, |
| 374 | enum fe_stv0900_clock_type path2_ts) |
| 375 | { |
| 376 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 377 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 378 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 379 | if (intp->chip_id >= 0x20) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 380 | switch (path1_ts) { |
| 381 | case STV0900_PARALLEL_PUNCT_CLOCK: |
| 382 | case STV0900_DVBCI_CLOCK: |
| 383 | switch (path2_ts) { |
| 384 | case STV0900_SERIAL_PUNCT_CLOCK: |
| 385 | case STV0900_SERIAL_CONT_CLOCK: |
| 386 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 387 | stv0900_write_reg(intp, R0900_TSGENERAL, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 388 | 0x00); |
| 389 | break; |
| 390 | case STV0900_PARALLEL_PUNCT_CLOCK: |
| 391 | case STV0900_DVBCI_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 392 | stv0900_write_reg(intp, R0900_TSGENERAL, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 393 | 0x06); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 394 | stv0900_write_bits(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 395 | F0900_P1_TSFIFO_MANSPEED, 3); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 396 | stv0900_write_bits(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 397 | F0900_P2_TSFIFO_MANSPEED, 0); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 398 | stv0900_write_reg(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 399 | R0900_P1_TSSPEED, 0x14); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 400 | stv0900_write_reg(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 401 | R0900_P2_TSSPEED, 0x28); |
| 402 | break; |
| 403 | } |
| 404 | break; |
| 405 | case STV0900_SERIAL_PUNCT_CLOCK: |
| 406 | case STV0900_SERIAL_CONT_CLOCK: |
| 407 | default: |
| 408 | switch (path2_ts) { |
| 409 | case STV0900_SERIAL_PUNCT_CLOCK: |
| 410 | case STV0900_SERIAL_CONT_CLOCK: |
| 411 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 412 | stv0900_write_reg(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 413 | R0900_TSGENERAL, 0x0C); |
| 414 | break; |
| 415 | case STV0900_PARALLEL_PUNCT_CLOCK: |
| 416 | case STV0900_DVBCI_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 417 | stv0900_write_reg(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 418 | R0900_TSGENERAL, 0x0A); |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 419 | dprintk("%s: 0x0a\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 420 | break; |
| 421 | } |
| 422 | break; |
| 423 | } |
| 424 | } else { |
| 425 | switch (path1_ts) { |
| 426 | case STV0900_PARALLEL_PUNCT_CLOCK: |
| 427 | case STV0900_DVBCI_CLOCK: |
| 428 | switch (path2_ts) { |
| 429 | case STV0900_SERIAL_PUNCT_CLOCK: |
| 430 | case STV0900_SERIAL_CONT_CLOCK: |
| 431 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 432 | stv0900_write_reg(intp, R0900_TSGENERAL1X, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 433 | 0x10); |
| 434 | break; |
| 435 | case STV0900_PARALLEL_PUNCT_CLOCK: |
| 436 | case STV0900_DVBCI_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 437 | stv0900_write_reg(intp, R0900_TSGENERAL1X, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 438 | 0x16); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 439 | stv0900_write_bits(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 440 | F0900_P1_TSFIFO_MANSPEED, 3); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 441 | stv0900_write_bits(intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 442 | F0900_P2_TSFIFO_MANSPEED, 0); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 443 | stv0900_write_reg(intp, R0900_P1_TSSPEED, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 444 | 0x14); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 445 | stv0900_write_reg(intp, R0900_P2_TSSPEED, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 446 | 0x28); |
| 447 | break; |
| 448 | } |
| 449 | |
| 450 | break; |
| 451 | case STV0900_SERIAL_PUNCT_CLOCK: |
| 452 | case STV0900_SERIAL_CONT_CLOCK: |
| 453 | default: |
| 454 | switch (path2_ts) { |
| 455 | case STV0900_SERIAL_PUNCT_CLOCK: |
| 456 | case STV0900_SERIAL_CONT_CLOCK: |
| 457 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 458 | stv0900_write_reg(intp, R0900_TSGENERAL1X, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 459 | 0x14); |
| 460 | break; |
| 461 | case STV0900_PARALLEL_PUNCT_CLOCK: |
| 462 | case STV0900_DVBCI_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 463 | stv0900_write_reg(intp, R0900_TSGENERAL1X, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 464 | 0x12); |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 465 | dprintk("%s: 0x12\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 466 | break; |
| 467 | } |
| 468 | |
| 469 | break; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | switch (path1_ts) { |
| 474 | case STV0900_PARALLEL_PUNCT_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 475 | stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x00); |
| 476 | stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x00); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 477 | break; |
| 478 | case STV0900_DVBCI_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 479 | stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x00); |
| 480 | stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x01); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 481 | break; |
| 482 | case STV0900_SERIAL_PUNCT_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 483 | stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x01); |
| 484 | stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x00); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 485 | break; |
| 486 | case STV0900_SERIAL_CONT_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 487 | stv0900_write_bits(intp, F0900_P1_TSFIFO_SERIAL, 0x01); |
| 488 | stv0900_write_bits(intp, F0900_P1_TSFIFO_DVBCI, 0x01); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 489 | break; |
| 490 | default: |
| 491 | break; |
| 492 | } |
| 493 | |
| 494 | switch (path2_ts) { |
| 495 | case STV0900_PARALLEL_PUNCT_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 496 | stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x00); |
| 497 | stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x00); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 498 | break; |
| 499 | case STV0900_DVBCI_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 500 | stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x00); |
| 501 | stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x01); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 502 | break; |
| 503 | case STV0900_SERIAL_PUNCT_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 504 | stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x01); |
| 505 | stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x00); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 506 | break; |
| 507 | case STV0900_SERIAL_CONT_CLOCK: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 508 | stv0900_write_bits(intp, F0900_P2_TSFIFO_SERIAL, 0x01); |
| 509 | stv0900_write_bits(intp, F0900_P2_TSFIFO_DVBCI, 0x01); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 510 | break; |
| 511 | default: |
| 512 | break; |
| 513 | } |
| 514 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 515 | stv0900_write_bits(intp, F0900_P2_RST_HWARE, 1); |
| 516 | stv0900_write_bits(intp, F0900_P2_RST_HWARE, 0); |
| 517 | stv0900_write_bits(intp, F0900_P1_RST_HWARE, 1); |
| 518 | stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency, |
| 522 | u32 bandwidth) |
| 523 | { |
| 524 | struct dvb_frontend_ops *frontend_ops = NULL; |
| 525 | struct dvb_tuner_ops *tuner_ops = NULL; |
| 526 | |
Cong Ding | 4880f56 | 2013-02-03 22:34:48 -0300 | [diff] [blame] | 527 | frontend_ops = &fe->ops; |
| 528 | tuner_ops = &frontend_ops->tuner_ops; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 529 | |
| 530 | if (tuner_ops->set_frequency) { |
| 531 | if ((tuner_ops->set_frequency(fe, frequency)) < 0) |
| 532 | dprintk("%s: Invalid parameter\n", __func__); |
| 533 | else |
| 534 | dprintk("%s: Frequency=%d\n", __func__, frequency); |
| 535 | |
| 536 | } |
| 537 | |
| 538 | if (tuner_ops->set_bandwidth) { |
| 539 | if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0) |
| 540 | dprintk("%s: Invalid parameter\n", __func__); |
| 541 | else |
| 542 | dprintk("%s: Bandwidth=%d\n", __func__, bandwidth); |
| 543 | |
| 544 | } |
| 545 | } |
| 546 | |
| 547 | void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth) |
| 548 | { |
| 549 | struct dvb_frontend_ops *frontend_ops = NULL; |
| 550 | struct dvb_tuner_ops *tuner_ops = NULL; |
| 551 | |
Cong Ding | 4880f56 | 2013-02-03 22:34:48 -0300 | [diff] [blame] | 552 | frontend_ops = &fe->ops; |
| 553 | tuner_ops = &frontend_ops->tuner_ops; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 554 | |
| 555 | if (tuner_ops->set_bandwidth) { |
| 556 | if ((tuner_ops->set_bandwidth(fe, bandwidth)) < 0) |
| 557 | dprintk("%s: Invalid parameter\n", __func__); |
| 558 | else |
| 559 | dprintk("%s: Bandwidth=%d\n", __func__, bandwidth); |
| 560 | |
| 561 | } |
| 562 | } |
| 563 | |
Igor M. Liplianin | cd79d33 | 2009-12-14 20:24:56 -0300 | [diff] [blame] | 564 | u32 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod) |
| 565 | { |
| 566 | u32 freq, round; |
| 567 | /* Formulat : |
| 568 | Tuner_Frequency(MHz) = Regs / 64 |
| 569 | Tuner_granularity(MHz) = Regs / 2048 |
| 570 | real_Tuner_Frequency = Tuner_Frequency(MHz) - Tuner_granularity(MHz) |
| 571 | */ |
| 572 | freq = (stv0900_get_bits(intp, TUN_RFFREQ2) << 10) + |
| 573 | (stv0900_get_bits(intp, TUN_RFFREQ1) << 2) + |
| 574 | stv0900_get_bits(intp, TUN_RFFREQ0); |
| 575 | |
| 576 | freq = (freq * 1000) / 64; |
| 577 | |
| 578 | round = (stv0900_get_bits(intp, TUN_RFRESTE1) >> 2) + |
| 579 | stv0900_get_bits(intp, TUN_RFRESTE0); |
| 580 | |
| 581 | round = (round * 1000) / 2048; |
| 582 | |
| 583 | return freq + round; |
| 584 | } |
| 585 | |
| 586 | void stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency, |
| 587 | u32 Bandwidth, int demod) |
| 588 | { |
| 589 | u32 tunerFrequency; |
| 590 | /* Formulat: |
| 591 | Tuner_frequency_reg= Frequency(MHz)*64 |
| 592 | */ |
| 593 | tunerFrequency = (Frequency * 64) / 1000; |
| 594 | |
| 595 | stv0900_write_bits(intp, TUN_RFFREQ2, (tunerFrequency >> 10)); |
| 596 | stv0900_write_bits(intp, TUN_RFFREQ1, (tunerFrequency >> 2) & 0xff); |
| 597 | stv0900_write_bits(intp, TUN_RFFREQ0, (tunerFrequency & 0x03)); |
| 598 | /* Low Pass Filter = BW /2 (MHz)*/ |
| 599 | stv0900_write_bits(intp, TUN_BW, Bandwidth / 2000000); |
| 600 | /* Tuner Write trig */ |
| 601 | stv0900_write_reg(intp, TNRLD, 1); |
| 602 | } |
| 603 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 604 | static s32 stv0900_get_rf_level(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 605 | const struct stv0900_table *lookup, |
| 606 | enum fe_stv0900_demod_num demod) |
| 607 | { |
| 608 | s32 agc_gain = 0, |
| 609 | imin, |
| 610 | imax, |
| 611 | i, |
| 612 | rf_lvl = 0; |
| 613 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 614 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 615 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 616 | if ((lookup == NULL) || (lookup->size <= 0)) |
| 617 | return 0; |
| 618 | |
| 619 | agc_gain = MAKEWORD(stv0900_get_bits(intp, AGCIQ_VALUE1), |
| 620 | stv0900_get_bits(intp, AGCIQ_VALUE0)); |
| 621 | |
| 622 | imin = 0; |
| 623 | imax = lookup->size - 1; |
| 624 | if (INRANGE(lookup->table[imin].regval, agc_gain, |
| 625 | lookup->table[imax].regval)) { |
| 626 | while ((imax - imin) > 1) { |
| 627 | i = (imax + imin) >> 1; |
| 628 | |
| 629 | if (INRANGE(lookup->table[imin].regval, |
| 630 | agc_gain, |
| 631 | lookup->table[i].regval)) |
| 632 | imax = i; |
| 633 | else |
| 634 | imin = i; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 635 | } |
| 636 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 637 | rf_lvl = (s32)agc_gain - lookup->table[imin].regval; |
| 638 | rf_lvl *= (lookup->table[imax].realval - |
| 639 | lookup->table[imin].realval); |
| 640 | rf_lvl /= (lookup->table[imax].regval - |
| 641 | lookup->table[imin].regval); |
| 642 | rf_lvl += lookup->table[imin].realval; |
| 643 | } else if (agc_gain > lookup->table[0].regval) |
| 644 | rf_lvl = 5; |
| 645 | else if (agc_gain < lookup->table[lookup->size-1].regval) |
| 646 | rf_lvl = -100; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 647 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 648 | dprintk("%s: RFLevel = %d\n", __func__, rf_lvl); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 649 | |
| 650 | return rf_lvl; |
| 651 | } |
| 652 | |
| 653 | static int stv0900_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 654 | { |
| 655 | struct stv0900_state *state = fe->demodulator_priv; |
| 656 | struct stv0900_internal *internal = state->internal; |
| 657 | s32 rflevel = stv0900_get_rf_level(internal, &stv0900_rf, |
| 658 | state->demod); |
| 659 | |
Igor M. Liplianin | 502cd96 | 2009-10-27 14:59:53 -0300 | [diff] [blame] | 660 | rflevel = (rflevel + 100) * (65535 / 70); |
| 661 | if (rflevel < 0) |
| 662 | rflevel = 0; |
| 663 | |
| 664 | if (rflevel > 65535) |
| 665 | rflevel = 65535; |
| 666 | |
| 667 | *strength = rflevel; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 668 | |
| 669 | return 0; |
| 670 | } |
| 671 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 672 | static s32 stv0900_carr_get_quality(struct dvb_frontend *fe, |
| 673 | const struct stv0900_table *lookup) |
| 674 | { |
| 675 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 676 | struct stv0900_internal *intp = state->internal; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 677 | enum fe_stv0900_demod_num demod = state->demod; |
| 678 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 679 | s32 c_n = -100, |
| 680 | regval, |
| 681 | imin, |
| 682 | imax, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 683 | i, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 684 | noise_field1, |
| 685 | noise_field0; |
| 686 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 687 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 688 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 689 | if (stv0900_get_standard(fe, demod) == STV0900_DVBS2_STANDARD) { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 690 | noise_field1 = NOSPLHT_NORMED1; |
| 691 | noise_field0 = NOSPLHT_NORMED0; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 692 | } else { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 693 | noise_field1 = NOSDATAT_NORMED1; |
| 694 | noise_field0 = NOSDATAT_NORMED0; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 695 | } |
| 696 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 697 | if (stv0900_get_bits(intp, LOCK_DEFINITIF)) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 698 | if ((lookup != NULL) && lookup->size) { |
| 699 | regval = 0; |
| 700 | msleep(5); |
| 701 | for (i = 0; i < 16; i++) { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 702 | regval += MAKEWORD(stv0900_get_bits(intp, |
Igor M. Liplianin | 11a8414 | 2009-03-15 07:28:45 -0300 | [diff] [blame] | 703 | noise_field1), |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 704 | stv0900_get_bits(intp, |
Igor M. Liplianin | 11a8414 | 2009-03-15 07:28:45 -0300 | [diff] [blame] | 705 | noise_field0)); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 706 | msleep(1); |
| 707 | } |
| 708 | |
| 709 | regval /= 16; |
| 710 | imin = 0; |
| 711 | imax = lookup->size - 1; |
Igor M. Liplianin | 11a8414 | 2009-03-15 07:28:45 -0300 | [diff] [blame] | 712 | if (INRANGE(lookup->table[imin].regval, |
| 713 | regval, |
| 714 | lookup->table[imax].regval)) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 715 | while ((imax - imin) > 1) { |
| 716 | i = (imax + imin) >> 1; |
Igor M. Liplianin | 11a8414 | 2009-03-15 07:28:45 -0300 | [diff] [blame] | 717 | if (INRANGE(lookup->table[imin].regval, |
| 718 | regval, |
| 719 | lookup->table[i].regval)) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 720 | imax = i; |
| 721 | else |
| 722 | imin = i; |
| 723 | } |
| 724 | |
| 725 | c_n = ((regval - lookup->table[imin].regval) |
Igor M. Liplianin | 11a8414 | 2009-03-15 07:28:45 -0300 | [diff] [blame] | 726 | * (lookup->table[imax].realval |
| 727 | - lookup->table[imin].realval) |
| 728 | / (lookup->table[imax].regval |
| 729 | - lookup->table[imin].regval)) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 730 | + lookup->table[imin].realval; |
| 731 | } else if (regval < lookup->table[imin].regval) |
| 732 | c_n = 1000; |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | return c_n; |
| 737 | } |
| 738 | |
Abylay Ospan | ee1ebcf | 2009-06-08 04:31:26 -0300 | [diff] [blame] | 739 | static int stv0900_read_ucblocks(struct dvb_frontend *fe, u32 * ucblocks) |
| 740 | { |
| 741 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 742 | struct stv0900_internal *intp = state->internal; |
Abylay Ospan | ee1ebcf | 2009-06-08 04:31:26 -0300 | [diff] [blame] | 743 | enum fe_stv0900_demod_num demod = state->demod; |
| 744 | u8 err_val1, err_val0; |
Abylay Ospan | ee1ebcf | 2009-06-08 04:31:26 -0300 | [diff] [blame] | 745 | u32 header_err_val = 0; |
| 746 | |
| 747 | *ucblocks = 0x0; |
| 748 | if (stv0900_get_standard(fe, demod) == STV0900_DVBS2_STANDARD) { |
| 749 | /* DVB-S2 delineator errors count */ |
| 750 | |
| 751 | /* retreiving number for errnous headers */ |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 752 | err_val1 = stv0900_read_reg(intp, BBFCRCKO1); |
| 753 | err_val0 = stv0900_read_reg(intp, BBFCRCKO0); |
| 754 | header_err_val = (err_val1 << 8) | err_val0; |
Abylay Ospan | ee1ebcf | 2009-06-08 04:31:26 -0300 | [diff] [blame] | 755 | |
| 756 | /* retreiving number for errnous packets */ |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 757 | err_val1 = stv0900_read_reg(intp, UPCRCKO1); |
| 758 | err_val0 = stv0900_read_reg(intp, UPCRCKO0); |
| 759 | *ucblocks = (err_val1 << 8) | err_val0; |
Abylay Ospan | ee1ebcf | 2009-06-08 04:31:26 -0300 | [diff] [blame] | 760 | *ucblocks += header_err_val; |
| 761 | } |
| 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 766 | static int stv0900_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 767 | { |
Igor M. Liplianin | 502cd96 | 2009-10-27 14:59:53 -0300 | [diff] [blame] | 768 | s32 snrlcl = stv0900_carr_get_quality(fe, |
Igor M. Liplianin | 11a8414 | 2009-03-15 07:28:45 -0300 | [diff] [blame] | 769 | (const struct stv0900_table *)&stv0900_s2_cn); |
Igor M. Liplianin | 502cd96 | 2009-10-27 14:59:53 -0300 | [diff] [blame] | 770 | snrlcl = (snrlcl + 30) * 384; |
| 771 | if (snrlcl < 0) |
| 772 | snrlcl = 0; |
| 773 | |
| 774 | if (snrlcl > 65535) |
| 775 | snrlcl = 65535; |
| 776 | |
| 777 | *snr = snrlcl; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 782 | static u32 stv0900_get_ber(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 783 | enum fe_stv0900_demod_num demod) |
| 784 | { |
| 785 | u32 ber = 10000000, i; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 786 | s32 demod_state; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 787 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 788 | demod_state = stv0900_get_bits(intp, HEADER_MODE); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 789 | |
| 790 | switch (demod_state) { |
| 791 | case STV0900_SEARCH: |
| 792 | case STV0900_PLH_DETECTED: |
| 793 | default: |
| 794 | ber = 10000000; |
| 795 | break; |
| 796 | case STV0900_DVBS_FOUND: |
| 797 | ber = 0; |
| 798 | for (i = 0; i < 5; i++) { |
| 799 | msleep(5); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 800 | ber += stv0900_get_err_count(intp, 0, demod); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | ber /= 5; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 804 | if (stv0900_get_bits(intp, PRFVIT)) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 805 | ber *= 9766; |
| 806 | ber = ber >> 13; |
| 807 | } |
| 808 | |
| 809 | break; |
| 810 | case STV0900_DVBS2_FOUND: |
| 811 | ber = 0; |
| 812 | for (i = 0; i < 5; i++) { |
| 813 | msleep(5); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 814 | ber += stv0900_get_err_count(intp, 0, demod); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | ber /= 5; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 818 | if (stv0900_get_bits(intp, PKTDELIN_LOCK)) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 819 | ber *= 9766; |
| 820 | ber = ber >> 13; |
| 821 | } |
| 822 | |
| 823 | break; |
| 824 | } |
| 825 | |
| 826 | return ber; |
| 827 | } |
| 828 | |
| 829 | static int stv0900_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 830 | { |
| 831 | struct stv0900_state *state = fe->demodulator_priv; |
| 832 | struct stv0900_internal *internal = state->internal; |
| 833 | |
| 834 | *ber = stv0900_get_ber(internal, state->demod); |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 839 | int stv0900_get_demod_lock(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 840 | enum fe_stv0900_demod_num demod, s32 time_out) |
| 841 | { |
| 842 | s32 timer = 0, |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 843 | lock = 0; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 844 | |
| 845 | enum fe_stv0900_search_state dmd_state; |
| 846 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 847 | while ((timer < time_out) && (lock == 0)) { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 848 | dmd_state = stv0900_get_bits(intp, HEADER_MODE); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 849 | dprintk("Demod State = %d\n", dmd_state); |
| 850 | switch (dmd_state) { |
| 851 | case STV0900_SEARCH: |
| 852 | case STV0900_PLH_DETECTED: |
| 853 | default: |
| 854 | lock = 0; |
| 855 | break; |
| 856 | case STV0900_DVBS2_FOUND: |
| 857 | case STV0900_DVBS_FOUND: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 858 | lock = stv0900_get_bits(intp, LOCK_DEFINITIF); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 859 | break; |
| 860 | } |
| 861 | |
| 862 | if (lock == 0) |
| 863 | msleep(10); |
| 864 | |
| 865 | timer += 10; |
| 866 | } |
| 867 | |
| 868 | if (lock) |
| 869 | dprintk("DEMOD LOCK OK\n"); |
| 870 | else |
| 871 | dprintk("DEMOD LOCK FAIL\n"); |
| 872 | |
| 873 | return lock; |
| 874 | } |
| 875 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 876 | void stv0900_stop_all_s2_modcod(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 877 | enum fe_stv0900_demod_num demod) |
| 878 | { |
| 879 | s32 regflist, |
| 880 | i; |
| 881 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 882 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 883 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 884 | regflist = MODCODLST0; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 885 | |
| 886 | for (i = 0; i < 16; i++) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 887 | stv0900_write_reg(intp, regflist + i, 0xff); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 888 | } |
| 889 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 890 | void stv0900_activate_s2_modcod(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 891 | enum fe_stv0900_demod_num demod) |
| 892 | { |
| 893 | u32 matype, |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 894 | mod_code, |
| 895 | fmod, |
| 896 | reg_index, |
| 897 | field_index; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 898 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 899 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 900 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 901 | if (intp->chip_id <= 0x11) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 902 | msleep(5); |
| 903 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 904 | mod_code = stv0900_read_reg(intp, PLHMODCOD); |
| 905 | matype = mod_code & 0x3; |
| 906 | mod_code = (mod_code & 0x7f) >> 2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 907 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 908 | reg_index = MODCODLSTF - mod_code / 2; |
| 909 | field_index = mod_code % 2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 910 | |
| 911 | switch (matype) { |
| 912 | case 0: |
| 913 | default: |
| 914 | fmod = 14; |
| 915 | break; |
| 916 | case 1: |
| 917 | fmod = 13; |
| 918 | break; |
| 919 | case 2: |
| 920 | fmod = 11; |
| 921 | break; |
| 922 | case 3: |
| 923 | fmod = 7; |
| 924 | break; |
| 925 | } |
| 926 | |
| 927 | if ((INRANGE(STV0900_QPSK_12, mod_code, STV0900_8PSK_910)) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 928 | && (matype <= 1)) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 929 | if (field_index == 0) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 930 | stv0900_write_reg(intp, reg_index, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 931 | 0xf0 | fmod); |
| 932 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 933 | stv0900_write_reg(intp, reg_index, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 934 | (fmod << 4) | 0xf); |
| 935 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 936 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 937 | } else if (intp->chip_id >= 0x12) { |
| 938 | for (reg_index = 0; reg_index < 7; reg_index++) |
| 939 | stv0900_write_reg(intp, MODCODLST0 + reg_index, 0xff); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 940 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 941 | stv0900_write_reg(intp, MODCODLSTE, 0xff); |
| 942 | stv0900_write_reg(intp, MODCODLSTF, 0xcf); |
| 943 | for (reg_index = 0; reg_index < 8; reg_index++) |
| 944 | stv0900_write_reg(intp, MODCODLST7 + reg_index, 0xcc); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 945 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 946 | |
| 947 | } |
| 948 | } |
| 949 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 950 | void stv0900_activate_s2_modcod_single(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 951 | enum fe_stv0900_demod_num demod) |
| 952 | { |
| 953 | u32 reg_index; |
| 954 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 955 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 956 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 957 | stv0900_write_reg(intp, MODCODLST0, 0xff); |
| 958 | stv0900_write_reg(intp, MODCODLST1, 0xf0); |
| 959 | stv0900_write_reg(intp, MODCODLSTF, 0x0f); |
| 960 | for (reg_index = 0; reg_index < 13; reg_index++) |
| 961 | stv0900_write_reg(intp, MODCODLST2 + reg_index, 0); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 962 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | static enum dvbfe_algo stv0900_frontend_algo(struct dvb_frontend *fe) |
| 966 | { |
| 967 | return DVBFE_ALGO_CUSTOM; |
| 968 | } |
| 969 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 970 | void stv0900_start_search(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 971 | enum fe_stv0900_demod_num demod) |
| 972 | { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 973 | u32 freq; |
| 974 | s16 freq_s16 ; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 975 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 976 | stv0900_write_bits(intp, DEMOD_MODE, 0x1f); |
| 977 | if (intp->chip_id == 0x10) |
| 978 | stv0900_write_reg(intp, CORRELEXP, 0xaa); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 979 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 980 | if (intp->chip_id < 0x20) |
| 981 | stv0900_write_reg(intp, CARHDR, 0x55); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 982 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 983 | if (intp->chip_id <= 0x20) { |
| 984 | if (intp->symbol_rate[0] <= 5000000) { |
| 985 | stv0900_write_reg(intp, CARCFG, 0x44); |
| 986 | stv0900_write_reg(intp, CFRUP1, 0x0f); |
| 987 | stv0900_write_reg(intp, CFRUP0, 0xff); |
| 988 | stv0900_write_reg(intp, CFRLOW1, 0xf0); |
| 989 | stv0900_write_reg(intp, CFRLOW0, 0x00); |
| 990 | stv0900_write_reg(intp, RTCS2, 0x68); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 991 | } else { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 992 | stv0900_write_reg(intp, CARCFG, 0xc4); |
| 993 | stv0900_write_reg(intp, RTCS2, 0x44); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 994 | } |
| 995 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 996 | } else { /*cut 3.0 above*/ |
| 997 | if (intp->symbol_rate[demod] <= 5000000) |
| 998 | stv0900_write_reg(intp, RTCS2, 0x68); |
| 999 | else |
| 1000 | stv0900_write_reg(intp, RTCS2, 0x44); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1001 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1002 | stv0900_write_reg(intp, CARCFG, 0x46); |
| 1003 | if (intp->srch_algo[demod] == STV0900_WARM_START) { |
| 1004 | freq = 1000 << 16; |
| 1005 | freq /= (intp->mclk / 1000); |
| 1006 | freq_s16 = (s16)freq; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1007 | } else { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1008 | freq = (intp->srch_range[demod] / 2000); |
| 1009 | if (intp->symbol_rate[demod] <= 5000000) |
| 1010 | freq += 80; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1011 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1012 | freq += 600; |
| 1013 | |
| 1014 | freq = freq << 16; |
| 1015 | freq /= (intp->mclk / 1000); |
| 1016 | freq_s16 = (s16)freq; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1017 | } |
| 1018 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1019 | stv0900_write_bits(intp, CFR_UP1, MSB(freq_s16)); |
| 1020 | stv0900_write_bits(intp, CFR_UP0, LSB(freq_s16)); |
| 1021 | freq_s16 *= (-1); |
| 1022 | stv0900_write_bits(intp, CFR_LOW1, MSB(freq_s16)); |
| 1023 | stv0900_write_bits(intp, CFR_LOW0, LSB(freq_s16)); |
| 1024 | } |
| 1025 | |
| 1026 | stv0900_write_reg(intp, CFRINIT1, 0); |
| 1027 | stv0900_write_reg(intp, CFRINIT0, 0); |
| 1028 | |
| 1029 | if (intp->chip_id >= 0x20) { |
| 1030 | stv0900_write_reg(intp, EQUALCFG, 0x41); |
| 1031 | stv0900_write_reg(intp, FFECFG, 0x41); |
| 1032 | |
| 1033 | if ((intp->srch_standard[demod] == STV0900_SEARCH_DVBS1) || |
| 1034 | (intp->srch_standard[demod] == STV0900_SEARCH_DSS) || |
| 1035 | (intp->srch_standard[demod] == STV0900_AUTO_SEARCH)) { |
| 1036 | stv0900_write_reg(intp, VITSCALE, |
| 1037 | 0x82); |
| 1038 | stv0900_write_reg(intp, VAVSRVIT, 0x0); |
| 1039 | } |
| 1040 | } |
| 1041 | |
| 1042 | stv0900_write_reg(intp, SFRSTEP, 0x00); |
| 1043 | stv0900_write_reg(intp, TMGTHRISE, 0xe0); |
| 1044 | stv0900_write_reg(intp, TMGTHFALL, 0xc0); |
| 1045 | stv0900_write_bits(intp, SCAN_ENABLE, 0); |
| 1046 | stv0900_write_bits(intp, CFR_AUTOSCAN, 0); |
| 1047 | stv0900_write_bits(intp, S1S2_SEQUENTIAL, 0); |
| 1048 | stv0900_write_reg(intp, RTC, 0x88); |
| 1049 | if (intp->chip_id >= 0x20) { |
| 1050 | if (intp->symbol_rate[demod] < 2000000) { |
| 1051 | if (intp->chip_id <= 0x20) |
| 1052 | stv0900_write_reg(intp, CARFREQ, 0x39); |
| 1053 | else /*cut 3.0*/ |
| 1054 | stv0900_write_reg(intp, CARFREQ, 0x89); |
| 1055 | |
| 1056 | stv0900_write_reg(intp, CARHDR, 0x40); |
| 1057 | } else if (intp->symbol_rate[demod] < 10000000) { |
| 1058 | stv0900_write_reg(intp, CARFREQ, 0x4c); |
| 1059 | stv0900_write_reg(intp, CARHDR, 0x20); |
| 1060 | } else { |
| 1061 | stv0900_write_reg(intp, CARFREQ, 0x4b); |
| 1062 | stv0900_write_reg(intp, CARHDR, 0x20); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1063 | } |
| 1064 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1065 | } else { |
| 1066 | if (intp->symbol_rate[demod] < 10000000) |
| 1067 | stv0900_write_reg(intp, CARFREQ, 0xef); |
| 1068 | else |
| 1069 | stv0900_write_reg(intp, CARFREQ, 0xed); |
| 1070 | } |
| 1071 | |
| 1072 | switch (intp->srch_algo[demod]) { |
| 1073 | case STV0900_WARM_START: |
| 1074 | stv0900_write_reg(intp, DMDISTATE, 0x1f); |
| 1075 | stv0900_write_reg(intp, DMDISTATE, 0x18); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1076 | break; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1077 | case STV0900_COLD_START: |
| 1078 | stv0900_write_reg(intp, DMDISTATE, 0x1f); |
| 1079 | stv0900_write_reg(intp, DMDISTATE, 0x15); |
| 1080 | break; |
| 1081 | default: |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1082 | break; |
| 1083 | } |
| 1084 | } |
| 1085 | |
| 1086 | u8 stv0900_get_optim_carr_loop(s32 srate, enum fe_stv0900_modcode modcode, |
| 1087 | s32 pilot, u8 chip_id) |
| 1088 | { |
| 1089 | u8 aclc_value = 0x29; |
Mauro Carvalho Chehab | d079e36 | 2016-02-22 13:12:00 -0300 | [diff] [blame] | 1090 | s32 i, cllas2_size; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1091 | const struct stv0900_car_loop_optim *cls2, *cllqs2, *cllas2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1092 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1093 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1094 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1095 | if (chip_id <= 0x12) { |
| 1096 | cls2 = FE_STV0900_S2CarLoop; |
| 1097 | cllqs2 = FE_STV0900_S2LowQPCarLoopCut30; |
| 1098 | cllas2 = FE_STV0900_S2APSKCarLoopCut30; |
Mauro Carvalho Chehab | d079e36 | 2016-02-22 13:12:00 -0300 | [diff] [blame] | 1099 | cllas2_size = ARRAY_SIZE(FE_STV0900_S2APSKCarLoopCut30); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1100 | } else if (chip_id == 0x20) { |
| 1101 | cls2 = FE_STV0900_S2CarLoopCut20; |
| 1102 | cllqs2 = FE_STV0900_S2LowQPCarLoopCut20; |
| 1103 | cllas2 = FE_STV0900_S2APSKCarLoopCut20; |
Mauro Carvalho Chehab | d079e36 | 2016-02-22 13:12:00 -0300 | [diff] [blame] | 1104 | cllas2_size = ARRAY_SIZE(FE_STV0900_S2APSKCarLoopCut20); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1105 | } else { |
| 1106 | cls2 = FE_STV0900_S2CarLoopCut30; |
| 1107 | cllqs2 = FE_STV0900_S2LowQPCarLoopCut30; |
| 1108 | cllas2 = FE_STV0900_S2APSKCarLoopCut30; |
Mauro Carvalho Chehab | d079e36 | 2016-02-22 13:12:00 -0300 | [diff] [blame] | 1109 | cllas2_size = ARRAY_SIZE(FE_STV0900_S2APSKCarLoopCut30); |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1110 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1111 | |
| 1112 | if (modcode < STV0900_QPSK_12) { |
| 1113 | i = 0; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1114 | while ((i < 3) && (modcode != cllqs2[i].modcode)) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1115 | i++; |
| 1116 | |
| 1117 | if (i >= 3) |
| 1118 | i = 2; |
| 1119 | } else { |
| 1120 | i = 0; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1121 | while ((i < 14) && (modcode != cls2[i].modcode)) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1122 | i++; |
| 1123 | |
| 1124 | if (i >= 14) { |
| 1125 | i = 0; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1126 | while ((i < 11) && (modcode != cllas2[i].modcode)) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1127 | i++; |
| 1128 | |
| 1129 | if (i >= 11) |
| 1130 | i = 10; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | if (modcode <= STV0900_QPSK_25) { |
| 1135 | if (pilot) { |
| 1136 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1137 | aclc_value = cllqs2[i].car_loop_pilots_on_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1138 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1139 | aclc_value = cllqs2[i].car_loop_pilots_on_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1140 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1141 | aclc_value = cllqs2[i].car_loop_pilots_on_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1142 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1143 | aclc_value = cllqs2[i].car_loop_pilots_on_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1144 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1145 | aclc_value = cllqs2[i].car_loop_pilots_on_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1146 | } else { |
| 1147 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1148 | aclc_value = cllqs2[i].car_loop_pilots_off_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1149 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1150 | aclc_value = cllqs2[i].car_loop_pilots_off_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1151 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1152 | aclc_value = cllqs2[i].car_loop_pilots_off_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1153 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1154 | aclc_value = cllqs2[i].car_loop_pilots_off_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1155 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1156 | aclc_value = cllqs2[i].car_loop_pilots_off_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | } else if (modcode <= STV0900_8PSK_910) { |
| 1160 | if (pilot) { |
| 1161 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1162 | aclc_value = cls2[i].car_loop_pilots_on_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1163 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1164 | aclc_value = cls2[i].car_loop_pilots_on_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1165 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1166 | aclc_value = cls2[i].car_loop_pilots_on_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1167 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1168 | aclc_value = cls2[i].car_loop_pilots_on_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1169 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1170 | aclc_value = cls2[i].car_loop_pilots_on_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1171 | } else { |
| 1172 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1173 | aclc_value = cls2[i].car_loop_pilots_off_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1174 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1175 | aclc_value = cls2[i].car_loop_pilots_off_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1176 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1177 | aclc_value = cls2[i].car_loop_pilots_off_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1178 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1179 | aclc_value = cls2[i].car_loop_pilots_off_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1180 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1181 | aclc_value = cls2[i].car_loop_pilots_off_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1182 | } |
| 1183 | |
Mauro Carvalho Chehab | d079e36 | 2016-02-22 13:12:00 -0300 | [diff] [blame] | 1184 | } else if (i < cllas2_size) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1185 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1186 | aclc_value = cllas2[i].car_loop_pilots_on_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1187 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1188 | aclc_value = cllas2[i].car_loop_pilots_on_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1189 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1190 | aclc_value = cllas2[i].car_loop_pilots_on_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1191 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1192 | aclc_value = cllas2[i].car_loop_pilots_on_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1193 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1194 | aclc_value = cllas2[i].car_loop_pilots_on_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | return aclc_value; |
| 1198 | } |
| 1199 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1200 | u8 stv0900_get_optim_short_carr_loop(s32 srate, |
| 1201 | enum fe_stv0900_modulation modulation, |
| 1202 | u8 chip_id) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1203 | { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1204 | const struct stv0900_short_frames_car_loop_optim *s2scl; |
| 1205 | const struct stv0900_short_frames_car_loop_optim_vs_mod *s2sclc30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1206 | s32 mod_index = 0; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1207 | u8 aclc_value = 0x0b; |
| 1208 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1209 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1210 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1211 | s2scl = FE_STV0900_S2ShortCarLoop; |
| 1212 | s2sclc30 = FE_STV0900_S2ShortCarLoopCut30; |
| 1213 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1214 | switch (modulation) { |
| 1215 | case STV0900_QPSK: |
| 1216 | default: |
| 1217 | mod_index = 0; |
| 1218 | break; |
| 1219 | case STV0900_8PSK: |
| 1220 | mod_index = 1; |
| 1221 | break; |
| 1222 | case STV0900_16APSK: |
| 1223 | mod_index = 2; |
| 1224 | break; |
| 1225 | case STV0900_32APSK: |
| 1226 | mod_index = 3; |
| 1227 | break; |
| 1228 | } |
| 1229 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1230 | if (chip_id >= 0x30) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1231 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1232 | aclc_value = s2sclc30[mod_index].car_loop_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1233 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1234 | aclc_value = s2sclc30[mod_index].car_loop_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1235 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1236 | aclc_value = s2sclc30[mod_index].car_loop_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1237 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1238 | aclc_value = s2sclc30[mod_index].car_loop_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1239 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1240 | aclc_value = s2sclc30[mod_index].car_loop_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1241 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1242 | } else if (chip_id >= 0x20) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1243 | if (srate <= 3000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1244 | aclc_value = s2scl[mod_index].car_loop_cut20_2; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1245 | else if (srate <= 7000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1246 | aclc_value = s2scl[mod_index].car_loop_cut20_5; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1247 | else if (srate <= 15000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1248 | aclc_value = s2scl[mod_index].car_loop_cut20_10; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1249 | else if (srate <= 25000000) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1250 | aclc_value = s2scl[mod_index].car_loop_cut20_20; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1251 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1252 | aclc_value = s2scl[mod_index].car_loop_cut20_30; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1253 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1254 | } else { |
| 1255 | if (srate <= 3000000) |
| 1256 | aclc_value = s2scl[mod_index].car_loop_cut12_2; |
| 1257 | else if (srate <= 7000000) |
| 1258 | aclc_value = s2scl[mod_index].car_loop_cut12_5; |
| 1259 | else if (srate <= 15000000) |
| 1260 | aclc_value = s2scl[mod_index].car_loop_cut12_10; |
| 1261 | else if (srate <= 25000000) |
| 1262 | aclc_value = s2scl[mod_index].car_loop_cut12_20; |
| 1263 | else |
| 1264 | aclc_value = s2scl[mod_index].car_loop_cut12_30; |
| 1265 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | return aclc_value; |
| 1269 | } |
| 1270 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1271 | static |
| 1272 | enum fe_stv0900_error stv0900_st_dvbs2_single(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1273 | enum fe_stv0900_demod_mode LDPC_Mode, |
| 1274 | enum fe_stv0900_demod_num demod) |
| 1275 | { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1276 | s32 reg_ind; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1277 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1278 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1279 | |
| 1280 | switch (LDPC_Mode) { |
| 1281 | case STV0900_DUAL: |
| 1282 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1283 | if ((intp->demod_mode != STV0900_DUAL) |
| 1284 | || (stv0900_get_bits(intp, F0900_DDEMOD) != 1)) { |
| 1285 | stv0900_write_reg(intp, R0900_GENCFG, 0x1d); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1286 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1287 | intp->demod_mode = STV0900_DUAL; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1288 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1289 | stv0900_write_bits(intp, F0900_FRESFEC, 1); |
| 1290 | stv0900_write_bits(intp, F0900_FRESFEC, 0); |
| 1291 | |
| 1292 | for (reg_ind = 0; reg_ind < 7; reg_ind++) |
| 1293 | stv0900_write_reg(intp, |
| 1294 | R0900_P1_MODCODLST0 + reg_ind, |
| 1295 | 0xff); |
| 1296 | for (reg_ind = 0; reg_ind < 8; reg_ind++) |
| 1297 | stv0900_write_reg(intp, |
| 1298 | R0900_P1_MODCODLST7 + reg_ind, |
| 1299 | 0xcc); |
| 1300 | |
| 1301 | stv0900_write_reg(intp, R0900_P1_MODCODLSTE, 0xff); |
| 1302 | stv0900_write_reg(intp, R0900_P1_MODCODLSTF, 0xcf); |
| 1303 | |
| 1304 | for (reg_ind = 0; reg_ind < 7; reg_ind++) |
| 1305 | stv0900_write_reg(intp, |
| 1306 | R0900_P2_MODCODLST0 + reg_ind, |
| 1307 | 0xff); |
| 1308 | for (reg_ind = 0; reg_ind < 8; reg_ind++) |
| 1309 | stv0900_write_reg(intp, |
| 1310 | R0900_P2_MODCODLST7 + reg_ind, |
| 1311 | 0xcc); |
| 1312 | |
| 1313 | stv0900_write_reg(intp, R0900_P2_MODCODLSTE, 0xff); |
| 1314 | stv0900_write_reg(intp, R0900_P2_MODCODLSTF, 0xcf); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | break; |
| 1318 | case STV0900_SINGLE: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1319 | if (demod == STV0900_DEMOD_2) { |
| 1320 | stv0900_stop_all_s2_modcod(intp, STV0900_DEMOD_1); |
| 1321 | stv0900_activate_s2_modcod_single(intp, |
| 1322 | STV0900_DEMOD_2); |
| 1323 | stv0900_write_reg(intp, R0900_GENCFG, 0x06); |
| 1324 | } else { |
| 1325 | stv0900_stop_all_s2_modcod(intp, STV0900_DEMOD_2); |
| 1326 | stv0900_activate_s2_modcod_single(intp, |
| 1327 | STV0900_DEMOD_1); |
| 1328 | stv0900_write_reg(intp, R0900_GENCFG, 0x04); |
| 1329 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1330 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1331 | intp->demod_mode = STV0900_SINGLE; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1332 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1333 | stv0900_write_bits(intp, F0900_FRESFEC, 1); |
| 1334 | stv0900_write_bits(intp, F0900_FRESFEC, 0); |
| 1335 | stv0900_write_bits(intp, F0900_P1_ALGOSWRST, 1); |
| 1336 | stv0900_write_bits(intp, F0900_P1_ALGOSWRST, 0); |
| 1337 | stv0900_write_bits(intp, F0900_P2_ALGOSWRST, 1); |
| 1338 | stv0900_write_bits(intp, F0900_P2_ALGOSWRST, 0); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1339 | break; |
| 1340 | } |
| 1341 | |
Mauro Carvalho Chehab | 49bc896 | 2014-09-03 15:11:54 -0300 | [diff] [blame] | 1342 | return STV0900_NO_ERROR; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static enum fe_stv0900_error stv0900_init_internal(struct dvb_frontend *fe, |
| 1346 | struct stv0900_init_params *p_init) |
| 1347 | { |
| 1348 | struct stv0900_state *state = fe->demodulator_priv; |
| 1349 | enum fe_stv0900_error error = STV0900_NO_ERROR; |
| 1350 | enum fe_stv0900_error demodError = STV0900_NO_ERROR; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1351 | struct stv0900_internal *intp = NULL; |
Igor M. Liplianin | f867c3f | 2009-06-19 05:45:23 -0300 | [diff] [blame] | 1352 | int selosci, i; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1353 | |
| 1354 | struct stv0900_inode *temp_int = find_inode(state->i2c_adap, |
| 1355 | state->config->demod_address); |
| 1356 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1357 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1358 | |
Igor M. Liplianin | 29372a8 | 2009-10-17 08:58:26 -0300 | [diff] [blame] | 1359 | if ((temp_int != NULL) && (p_init->demod_mode == STV0900_DUAL)) { |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1360 | state->internal = temp_int->internal; |
| 1361 | (state->internal->dmds_used)++; |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1362 | dprintk("%s: Find Internal Structure!\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1363 | return STV0900_NO_ERROR; |
| 1364 | } else { |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1365 | state->internal = kmalloc(sizeof(struct stv0900_internal), |
| 1366 | GFP_KERNEL); |
Roel Kluin | fb3ab10 | 2009-08-29 15:31:49 -0300 | [diff] [blame] | 1367 | if (state->internal == NULL) |
| 1368 | return STV0900_INVALID_HANDLE; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1369 | temp_int = append_internal(state->internal); |
Roel Kluin | fb3ab10 | 2009-08-29 15:31:49 -0300 | [diff] [blame] | 1370 | if (temp_int == NULL) { |
| 1371 | kfree(state->internal); |
| 1372 | state->internal = NULL; |
| 1373 | return STV0900_INVALID_HANDLE; |
| 1374 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1375 | state->internal->dmds_used = 1; |
| 1376 | state->internal->i2c_adap = state->i2c_adap; |
| 1377 | state->internal->i2c_addr = state->config->demod_address; |
| 1378 | state->internal->clkmode = state->config->clkmode; |
| 1379 | state->internal->errs = STV0900_NO_ERROR; |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1380 | dprintk("%s: Create New Internal Structure!\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1381 | } |
| 1382 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1383 | if (state->internal == NULL) { |
| 1384 | error = STV0900_INVALID_HANDLE; |
| 1385 | return error; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1386 | } |
| 1387 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1388 | demodError = stv0900_initialize(state->internal); |
| 1389 | if (demodError == STV0900_NO_ERROR) { |
| 1390 | error = STV0900_NO_ERROR; |
| 1391 | } else { |
| 1392 | if (demodError == STV0900_INVALID_HANDLE) |
| 1393 | error = STV0900_INVALID_HANDLE; |
| 1394 | else |
| 1395 | error = STV0900_I2C_ERROR; |
| 1396 | |
| 1397 | return error; |
| 1398 | } |
| 1399 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1400 | intp = state->internal; |
| 1401 | |
| 1402 | intp->demod_mode = p_init->demod_mode; |
| 1403 | stv0900_st_dvbs2_single(intp, intp->demod_mode, STV0900_DEMOD_1); |
| 1404 | intp->chip_id = stv0900_read_reg(intp, R0900_MID); |
| 1405 | intp->rolloff = p_init->rolloff; |
| 1406 | intp->quartz = p_init->dmd_ref_clk; |
| 1407 | |
| 1408 | stv0900_write_bits(intp, F0900_P1_ROLLOFF_CONTROL, p_init->rolloff); |
| 1409 | stv0900_write_bits(intp, F0900_P2_ROLLOFF_CONTROL, p_init->rolloff); |
| 1410 | |
| 1411 | intp->ts_config = p_init->ts_config; |
| 1412 | if (intp->ts_config == NULL) |
| 1413 | stv0900_set_ts_parallel_serial(intp, |
| 1414 | p_init->path1_ts_clock, |
| 1415 | p_init->path2_ts_clock); |
| 1416 | else { |
| 1417 | for (i = 0; intp->ts_config[i].addr != 0xffff; i++) |
| 1418 | stv0900_write_reg(intp, |
| 1419 | intp->ts_config[i].addr, |
| 1420 | intp->ts_config[i].val); |
| 1421 | |
| 1422 | stv0900_write_bits(intp, F0900_P2_RST_HWARE, 1); |
| 1423 | stv0900_write_bits(intp, F0900_P2_RST_HWARE, 0); |
| 1424 | stv0900_write_bits(intp, F0900_P1_RST_HWARE, 1); |
| 1425 | stv0900_write_bits(intp, F0900_P1_RST_HWARE, 0); |
| 1426 | } |
| 1427 | |
Igor M. Liplianin | cd79d33 | 2009-12-14 20:24:56 -0300 | [diff] [blame] | 1428 | intp->tuner_type[0] = p_init->tuner1_type; |
| 1429 | intp->tuner_type[1] = p_init->tuner2_type; |
| 1430 | /* tuner init */ |
| 1431 | switch (p_init->tuner1_type) { |
| 1432 | case 3: /*FE_AUTO_STB6100:*/ |
| 1433 | stv0900_write_reg(intp, R0900_P1_TNRCFG, 0x3c); |
| 1434 | stv0900_write_reg(intp, R0900_P1_TNRCFG2, 0x86); |
| 1435 | stv0900_write_reg(intp, R0900_P1_TNRCFG3, 0x18); |
| 1436 | stv0900_write_reg(intp, R0900_P1_TNRXTAL, 27); /* 27MHz */ |
| 1437 | stv0900_write_reg(intp, R0900_P1_TNRSTEPS, 0x05); |
| 1438 | stv0900_write_reg(intp, R0900_P1_TNRGAIN, 0x17); |
| 1439 | stv0900_write_reg(intp, R0900_P1_TNRADJ, 0x1f); |
| 1440 | stv0900_write_reg(intp, R0900_P1_TNRCTL2, 0x0); |
| 1441 | stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 3); |
| 1442 | break; |
| 1443 | /* case FE_SW_TUNER: */ |
| 1444 | default: |
| 1445 | stv0900_write_bits(intp, F0900_P1_TUN_TYPE, 6); |
| 1446 | break; |
| 1447 | } |
| 1448 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1449 | stv0900_write_bits(intp, F0900_P1_TUN_MADDRESS, p_init->tun1_maddress); |
| 1450 | switch (p_init->tuner1_adc) { |
| 1451 | case 1: |
| 1452 | stv0900_write_reg(intp, R0900_TSTTNR1, 0x26); |
| 1453 | break; |
| 1454 | default: |
| 1455 | break; |
| 1456 | } |
| 1457 | |
Igor M. Liplianin | cd79d33 | 2009-12-14 20:24:56 -0300 | [diff] [blame] | 1458 | stv0900_write_reg(intp, R0900_P1_TNRLD, 1); /* hw tuner */ |
| 1459 | |
| 1460 | /* tuner init */ |
| 1461 | switch (p_init->tuner2_type) { |
| 1462 | case 3: /*FE_AUTO_STB6100:*/ |
| 1463 | stv0900_write_reg(intp, R0900_P2_TNRCFG, 0x3c); |
| 1464 | stv0900_write_reg(intp, R0900_P2_TNRCFG2, 0x86); |
| 1465 | stv0900_write_reg(intp, R0900_P2_TNRCFG3, 0x18); |
| 1466 | stv0900_write_reg(intp, R0900_P2_TNRXTAL, 27); /* 27MHz */ |
| 1467 | stv0900_write_reg(intp, R0900_P2_TNRSTEPS, 0x05); |
| 1468 | stv0900_write_reg(intp, R0900_P2_TNRGAIN, 0x17); |
| 1469 | stv0900_write_reg(intp, R0900_P2_TNRADJ, 0x1f); |
| 1470 | stv0900_write_reg(intp, R0900_P2_TNRCTL2, 0x0); |
| 1471 | stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 3); |
| 1472 | break; |
| 1473 | /* case FE_SW_TUNER: */ |
| 1474 | default: |
| 1475 | stv0900_write_bits(intp, F0900_P2_TUN_TYPE, 6); |
| 1476 | break; |
| 1477 | } |
| 1478 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1479 | stv0900_write_bits(intp, F0900_P2_TUN_MADDRESS, p_init->tun2_maddress); |
| 1480 | switch (p_init->tuner2_adc) { |
| 1481 | case 1: |
| 1482 | stv0900_write_reg(intp, R0900_TSTTNR3, 0x26); |
| 1483 | break; |
| 1484 | default: |
| 1485 | break; |
| 1486 | } |
| 1487 | |
Igor M. Liplianin | cd79d33 | 2009-12-14 20:24:56 -0300 | [diff] [blame] | 1488 | stv0900_write_reg(intp, R0900_P2_TNRLD, 1); /* hw tuner */ |
| 1489 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1490 | stv0900_write_bits(intp, F0900_P1_TUN_IQSWAP, p_init->tun1_iq_inv); |
| 1491 | stv0900_write_bits(intp, F0900_P2_TUN_IQSWAP, p_init->tun2_iq_inv); |
| 1492 | stv0900_set_mclk(intp, 135000000); |
| 1493 | msleep(3); |
| 1494 | |
| 1495 | switch (intp->clkmode) { |
| 1496 | case 0: |
| 1497 | case 2: |
| 1498 | stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 | intp->clkmode); |
| 1499 | break; |
| 1500 | default: |
| 1501 | selosci = 0x02 & stv0900_read_reg(intp, R0900_SYNTCTRL); |
| 1502 | stv0900_write_reg(intp, R0900_SYNTCTRL, 0x20 | selosci); |
| 1503 | break; |
| 1504 | } |
| 1505 | msleep(3); |
| 1506 | |
| 1507 | intp->mclk = stv0900_get_mclk_freq(intp, intp->quartz); |
| 1508 | if (intp->errs) |
| 1509 | error = STV0900_I2C_ERROR; |
| 1510 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1511 | return error; |
| 1512 | } |
| 1513 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1514 | static int stv0900_status(struct stv0900_internal *intp, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1515 | enum fe_stv0900_demod_num demod) |
| 1516 | { |
| 1517 | enum fe_stv0900_search_state demod_state; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1518 | int locked = FALSE; |
Abylay Ospan | 247cb14 | 2009-12-12 13:37:44 -0300 | [diff] [blame] | 1519 | u8 tsbitrate0_val, tsbitrate1_val; |
| 1520 | s32 bitrate; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1521 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1522 | demod_state = stv0900_get_bits(intp, HEADER_MODE); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1523 | switch (demod_state) { |
| 1524 | case STV0900_SEARCH: |
| 1525 | case STV0900_PLH_DETECTED: |
| 1526 | default: |
| 1527 | locked = FALSE; |
| 1528 | break; |
| 1529 | case STV0900_DVBS2_FOUND: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1530 | locked = stv0900_get_bits(intp, LOCK_DEFINITIF) && |
| 1531 | stv0900_get_bits(intp, PKTDELIN_LOCK) && |
| 1532 | stv0900_get_bits(intp, TSFIFO_LINEOK); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1533 | break; |
| 1534 | case STV0900_DVBS_FOUND: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1535 | locked = stv0900_get_bits(intp, LOCK_DEFINITIF) && |
| 1536 | stv0900_get_bits(intp, LOCKEDVIT) && |
| 1537 | stv0900_get_bits(intp, TSFIFO_LINEOK); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1538 | break; |
| 1539 | } |
| 1540 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1541 | dprintk("%s: locked = %d\n", __func__, locked); |
| 1542 | |
Abylay Ospan | 247cb14 | 2009-12-12 13:37:44 -0300 | [diff] [blame] | 1543 | if (stvdebug) { |
| 1544 | /* Print TS bitrate */ |
| 1545 | tsbitrate0_val = stv0900_read_reg(intp, TSBITRATE0); |
| 1546 | tsbitrate1_val = stv0900_read_reg(intp, TSBITRATE1); |
| 1547 | /* Formula Bit rate = Mclk * px_tsfifo_bitrate / 16384 */ |
| 1548 | bitrate = (stv0900_get_mclk_freq(intp, intp->quartz)/1000000) |
| 1549 | * (tsbitrate1_val << 8 | tsbitrate0_val); |
| 1550 | bitrate /= 16384; |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 1551 | dprintk("TS bitrate = %d Mbit/sec\n", bitrate); |
| 1552 | } |
Abylay Ospan | 247cb14 | 2009-12-12 13:37:44 -0300 | [diff] [blame] | 1553 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1554 | return locked; |
| 1555 | } |
| 1556 | |
Evgeny Plehov | 73ec66c | 2012-11-29 15:27:38 -0300 | [diff] [blame] | 1557 | static int stv0900_set_mis(struct stv0900_internal *intp, |
| 1558 | enum fe_stv0900_demod_num demod, int mis) |
| 1559 | { |
Evgeny Plehov | 73ec66c | 2012-11-29 15:27:38 -0300 | [diff] [blame] | 1560 | dprintk("%s\n", __func__); |
| 1561 | |
| 1562 | if (mis < 0 || mis > 255) { |
| 1563 | dprintk("Disable MIS filtering\n"); |
| 1564 | stv0900_write_bits(intp, FILTER_EN, 0); |
| 1565 | } else { |
| 1566 | dprintk("Enable MIS filtering - %d\n", mis); |
| 1567 | stv0900_write_bits(intp, FILTER_EN, 1); |
| 1568 | stv0900_write_reg(intp, ISIENTRY, mis); |
| 1569 | stv0900_write_reg(intp, ISIBITENA, 0xff); |
| 1570 | } |
| 1571 | |
Mauro Carvalho Chehab | 49bc896 | 2014-09-03 15:11:54 -0300 | [diff] [blame] | 1572 | return STV0900_NO_ERROR; |
Evgeny Plehov | 73ec66c | 2012-11-29 15:27:38 -0300 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | |
Mauro Carvalho Chehab | 41da532 | 2011-12-26 18:03:12 -0300 | [diff] [blame] | 1576 | static enum dvbfe_search stv0900_search(struct dvb_frontend *fe) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1577 | { |
| 1578 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1579 | struct stv0900_internal *intp = state->internal; |
| 1580 | enum fe_stv0900_demod_num demod = state->demod; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1581 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
| 1582 | |
| 1583 | struct stv0900_search_params p_search; |
Abylay Ospan | 403c34f | 2010-03-06 15:05:26 -0300 | [diff] [blame] | 1584 | struct stv0900_signal_info p_result = intp->result[demod]; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1585 | |
| 1586 | enum fe_stv0900_error error = STV0900_NO_ERROR; |
| 1587 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1588 | dprintk("%s: ", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1589 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1590 | if (!(INRANGE(100000, c->symbol_rate, 70000000))) |
| 1591 | return DVBFE_ALGO_SEARCH_FAILED; |
| 1592 | |
Igor M. Liplianin | b699c27 | 2009-11-16 22:22:32 -0300 | [diff] [blame] | 1593 | if (state->config->set_ts_params) |
| 1594 | state->config->set_ts_params(fe, 0); |
| 1595 | |
Evgeny Plehov | 73ec66c | 2012-11-29 15:27:38 -0300 | [diff] [blame] | 1596 | stv0900_set_mis(intp, demod, c->stream_id); |
| 1597 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1598 | p_result.locked = FALSE; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1599 | p_search.path = demod; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1600 | p_search.frequency = c->frequency; |
| 1601 | p_search.symbol_rate = c->symbol_rate; |
| 1602 | p_search.search_range = 10000000; |
| 1603 | p_search.fec = STV0900_FEC_UNKNOWN; |
| 1604 | p_search.standard = STV0900_AUTO_SEARCH; |
| 1605 | p_search.iq_inversion = STV0900_IQ_AUTO; |
| 1606 | p_search.search_algo = STV0900_BLIND_SEARCH; |
Igor M. Liplianin | 38cdbce | 2011-02-28 16:52:08 -0300 | [diff] [blame] | 1607 | /* Speeds up DVB-S searching */ |
| 1608 | if (c->delivery_system == SYS_DVBS) |
| 1609 | p_search.standard = STV0900_SEARCH_DVBS1; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1610 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1611 | intp->srch_standard[demod] = p_search.standard; |
| 1612 | intp->symbol_rate[demod] = p_search.symbol_rate; |
| 1613 | intp->srch_range[demod] = p_search.search_range; |
| 1614 | intp->freq[demod] = p_search.frequency; |
| 1615 | intp->srch_algo[demod] = p_search.search_algo; |
| 1616 | intp->srch_iq_inv[demod] = p_search.iq_inversion; |
| 1617 | intp->fec[demod] = p_search.fec; |
| 1618 | if ((stv0900_algo(fe) == STV0900_RANGEOK) && |
| 1619 | (intp->errs == STV0900_NO_ERROR)) { |
| 1620 | p_result.locked = intp->result[demod].locked; |
| 1621 | p_result.standard = intp->result[demod].standard; |
| 1622 | p_result.frequency = intp->result[demod].frequency; |
| 1623 | p_result.symbol_rate = intp->result[demod].symbol_rate; |
| 1624 | p_result.fec = intp->result[demod].fec; |
| 1625 | p_result.modcode = intp->result[demod].modcode; |
| 1626 | p_result.pilot = intp->result[demod].pilot; |
| 1627 | p_result.frame_len = intp->result[demod].frame_len; |
| 1628 | p_result.spectrum = intp->result[demod].spectrum; |
| 1629 | p_result.rolloff = intp->result[demod].rolloff; |
| 1630 | p_result.modulation = intp->result[demod].modulation; |
| 1631 | } else { |
| 1632 | p_result.locked = FALSE; |
| 1633 | switch (intp->err[demod]) { |
| 1634 | case STV0900_I2C_ERROR: |
| 1635 | error = STV0900_I2C_ERROR; |
| 1636 | break; |
| 1637 | case STV0900_NO_ERROR: |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1638 | default: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1639 | error = STV0900_SEARCH_FAILED; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1640 | break; |
| 1641 | } |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1642 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1643 | |
| 1644 | if ((p_result.locked == TRUE) && (error == STV0900_NO_ERROR)) { |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1645 | dprintk("Search Success\n"); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1646 | return DVBFE_ALGO_SEARCH_SUCCESS; |
| 1647 | } else { |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1648 | dprintk("Search Fail\n"); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1649 | return DVBFE_ALGO_SEARCH_FAILED; |
| 1650 | } |
| 1651 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1652 | } |
| 1653 | |
| 1654 | static int stv0900_read_status(struct dvb_frontend *fe, enum fe_status *status) |
| 1655 | { |
| 1656 | struct stv0900_state *state = fe->demodulator_priv; |
| 1657 | |
Igor M. Liplianin | 78175bf | 2009-03-06 19:32:54 -0300 | [diff] [blame] | 1658 | dprintk("%s: ", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1659 | |
| 1660 | if ((stv0900_status(state->internal, state->demod)) == TRUE) { |
| 1661 | dprintk("DEMOD LOCK OK\n"); |
| 1662 | *status = FE_HAS_CARRIER |
| 1663 | | FE_HAS_VITERBI |
| 1664 | | FE_HAS_SYNC |
| 1665 | | FE_HAS_LOCK; |
Igor M. Liplianin | fa8bae1 | 2011-02-25 18:41:22 -0300 | [diff] [blame] | 1666 | if (state->config->set_lock_led) |
| 1667 | state->config->set_lock_led(fe, 1); |
| 1668 | } else { |
Abylay Ospan | 3b30e0a | 2011-02-14 16:03:13 -0300 | [diff] [blame] | 1669 | *status = 0; |
Igor M. Liplianin | fa8bae1 | 2011-02-25 18:41:22 -0300 | [diff] [blame] | 1670 | if (state->config->set_lock_led) |
| 1671 | state->config->set_lock_led(fe, 0); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1672 | dprintk("DEMOD LOCK FAIL\n"); |
Igor M. Liplianin | fa8bae1 | 2011-02-25 18:41:22 -0300 | [diff] [blame] | 1673 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1674 | |
| 1675 | return 0; |
| 1676 | } |
| 1677 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1678 | static int stv0900_stop_ts(struct dvb_frontend *fe, int stop_ts) |
| 1679 | { |
| 1680 | |
| 1681 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1682 | struct stv0900_internal *intp = state->internal; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1683 | enum fe_stv0900_demod_num demod = state->demod; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1684 | |
| 1685 | if (stop_ts == TRUE) |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1686 | stv0900_write_bits(intp, RST_HWARE, 1); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1687 | else |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1688 | stv0900_write_bits(intp, RST_HWARE, 0); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1689 | |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | static int stv0900_diseqc_init(struct dvb_frontend *fe) |
| 1694 | { |
| 1695 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1696 | struct stv0900_internal *intp = state->internal; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1697 | enum fe_stv0900_demod_num demod = state->demod; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1698 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1699 | stv0900_write_bits(intp, DISTX_MODE, state->config->diseqc_mode); |
| 1700 | stv0900_write_bits(intp, DISEQC_RESET, 1); |
| 1701 | stv0900_write_bits(intp, DISEQC_RESET, 0); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1702 | |
| 1703 | return 0; |
| 1704 | } |
| 1705 | |
| 1706 | static int stv0900_init(struct dvb_frontend *fe) |
| 1707 | { |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1708 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1709 | |
| 1710 | stv0900_stop_ts(fe, 1); |
| 1711 | stv0900_diseqc_init(fe); |
| 1712 | |
| 1713 | return 0; |
| 1714 | } |
| 1715 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1716 | static int stv0900_diseqc_send(struct stv0900_internal *intp , u8 *data, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1717 | u32 NbData, enum fe_stv0900_demod_num demod) |
| 1718 | { |
| 1719 | s32 i = 0; |
| 1720 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1721 | stv0900_write_bits(intp, DIS_PRECHARGE, 1); |
| 1722 | while (i < NbData) { |
| 1723 | while (stv0900_get_bits(intp, FIFO_FULL)) |
| 1724 | ;/* checkpatch complains */ |
| 1725 | stv0900_write_reg(intp, DISTXDATA, data[i]); |
| 1726 | i++; |
| 1727 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1728 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1729 | stv0900_write_bits(intp, DIS_PRECHARGE, 0); |
| 1730 | i = 0; |
| 1731 | while ((stv0900_get_bits(intp, TX_IDLE) != 1) && (i < 10)) { |
| 1732 | msleep(10); |
| 1733 | i++; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | return 0; |
| 1737 | } |
| 1738 | |
| 1739 | static int stv0900_send_master_cmd(struct dvb_frontend *fe, |
| 1740 | struct dvb_diseqc_master_cmd *cmd) |
| 1741 | { |
| 1742 | struct stv0900_state *state = fe->demodulator_priv; |
| 1743 | |
| 1744 | return stv0900_diseqc_send(state->internal, |
| 1745 | cmd->msg, |
| 1746 | cmd->msg_len, |
| 1747 | state->demod); |
| 1748 | } |
| 1749 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1750 | static int stv0900_send_burst(struct dvb_frontend *fe, |
| 1751 | enum fe_sec_mini_cmd burst) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1752 | { |
| 1753 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1754 | struct stv0900_internal *intp = state->internal; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1755 | enum fe_stv0900_demod_num demod = state->demod; |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1756 | u8 data; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1757 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1758 | |
| 1759 | switch (burst) { |
| 1760 | case SEC_MINI_A: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1761 | stv0900_write_bits(intp, DISTX_MODE, 3);/* Unmodulated */ |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1762 | data = 0x00; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1763 | stv0900_diseqc_send(intp, &data, 1, state->demod); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1764 | break; |
| 1765 | case SEC_MINI_B: |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1766 | stv0900_write_bits(intp, DISTX_MODE, 2);/* Modulated */ |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1767 | data = 0xff; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1768 | stv0900_diseqc_send(intp, &data, 1, state->demod); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1769 | break; |
| 1770 | } |
| 1771 | |
| 1772 | return 0; |
| 1773 | } |
| 1774 | |
| 1775 | static int stv0900_recv_slave_reply(struct dvb_frontend *fe, |
| 1776 | struct dvb_diseqc_slave_reply *reply) |
| 1777 | { |
| 1778 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1779 | struct stv0900_internal *intp = state->internal; |
| 1780 | enum fe_stv0900_demod_num demod = state->demod; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1781 | s32 i = 0; |
| 1782 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1783 | reply->msg_len = 0; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1784 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1785 | while ((stv0900_get_bits(intp, RX_END) != 1) && (i < 10)) { |
| 1786 | msleep(10); |
| 1787 | i++; |
| 1788 | } |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1789 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1790 | if (stv0900_get_bits(intp, RX_END)) { |
| 1791 | reply->msg_len = stv0900_get_bits(intp, FIFO_BYTENBR); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1792 | |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1793 | for (i = 0; i < reply->msg_len; i++) |
| 1794 | reply->msg[i] = stv0900_read_reg(intp, DISRXDATA); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1800 | static int stv0900_set_tone(struct dvb_frontend *fe, |
| 1801 | enum fe_sec_tone_mode toneoff) |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1802 | { |
| 1803 | struct stv0900_state *state = fe->demodulator_priv; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1804 | struct stv0900_internal *intp = state->internal; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1805 | enum fe_stv0900_demod_num demod = state->demod; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1806 | |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1807 | dprintk("%s: %s\n", __func__, ((toneoff == 0) ? "On" : "Off")); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1808 | |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1809 | switch (toneoff) { |
| 1810 | case SEC_TONE_ON: |
| 1811 | /*Set the DiseqC mode to 22Khz _continues_ tone*/ |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1812 | stv0900_write_bits(intp, DISTX_MODE, 0); |
| 1813 | stv0900_write_bits(intp, DISEQC_RESET, 1); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1814 | /*release DiseqC reset to enable the 22KHz tone*/ |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1815 | stv0900_write_bits(intp, DISEQC_RESET, 0); |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1816 | break; |
| 1817 | case SEC_TONE_OFF: |
| 1818 | /*return diseqc mode to config->diseqc_mode. |
| 1819 | Usually it's without _continues_ tone */ |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1820 | stv0900_write_bits(intp, DISTX_MODE, |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1821 | state->config->diseqc_mode); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1822 | /*maintain the DiseqC reset to disable the 22KHz tone*/ |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1823 | stv0900_write_bits(intp, DISEQC_RESET, 1); |
| 1824 | stv0900_write_bits(intp, DISEQC_RESET, 0); |
Abylay Ospan | 9329fb5 | 2009-10-17 08:38:45 -0300 | [diff] [blame] | 1825 | break; |
| 1826 | default: |
| 1827 | return -EINVAL; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | return 0; |
| 1831 | } |
| 1832 | |
| 1833 | static void stv0900_release(struct dvb_frontend *fe) |
| 1834 | { |
| 1835 | struct stv0900_state *state = fe->demodulator_priv; |
| 1836 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1837 | dprintk("%s\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1838 | |
Igor M. Liplianin | fa8bae1 | 2011-02-25 18:41:22 -0300 | [diff] [blame] | 1839 | if (state->config->set_lock_led) |
| 1840 | state->config->set_lock_led(fe, 0); |
| 1841 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1842 | if ((--(state->internal->dmds_used)) <= 0) { |
| 1843 | |
Igor M. Liplianin | 8171c20 | 2009-09-19 08:37:40 -0300 | [diff] [blame] | 1844 | dprintk("%s: Actually removing\n", __func__); |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1845 | |
| 1846 | remove_inode(state->internal); |
| 1847 | kfree(state->internal); |
| 1848 | } |
| 1849 | |
| 1850 | kfree(state); |
| 1851 | } |
| 1852 | |
Igor M. Liplianin | fa8bae1 | 2011-02-25 18:41:22 -0300 | [diff] [blame] | 1853 | static int stv0900_sleep(struct dvb_frontend *fe) |
| 1854 | { |
| 1855 | struct stv0900_state *state = fe->demodulator_priv; |
| 1856 | |
| 1857 | dprintk("%s\n", __func__); |
| 1858 | |
| 1859 | if (state->config->set_lock_led) |
| 1860 | state->config->set_lock_led(fe, 0); |
| 1861 | |
| 1862 | return 0; |
| 1863 | } |
| 1864 | |
Mauro Carvalho Chehab | 7e3e68b | 2016-02-04 12:58:30 -0200 | [diff] [blame] | 1865 | static int stv0900_get_frontend(struct dvb_frontend *fe, |
| 1866 | struct dtv_frontend_properties *p) |
Abylay Ospan | 403c34f | 2010-03-06 15:05:26 -0300 | [diff] [blame] | 1867 | { |
| 1868 | struct stv0900_state *state = fe->demodulator_priv; |
| 1869 | struct stv0900_internal *intp = state->internal; |
| 1870 | enum fe_stv0900_demod_num demod = state->demod; |
| 1871 | struct stv0900_signal_info p_result = intp->result[demod]; |
| 1872 | |
| 1873 | p->frequency = p_result.locked ? p_result.frequency : 0; |
Mauro Carvalho Chehab | 38d945e | 2011-12-26 14:34:48 -0300 | [diff] [blame] | 1874 | p->symbol_rate = p_result.locked ? p_result.symbol_rate : 0; |
Abylay Ospan | 403c34f | 2010-03-06 15:05:26 -0300 | [diff] [blame] | 1875 | return 0; |
| 1876 | } |
| 1877 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1878 | static struct dvb_frontend_ops stv0900_ops = { |
Mauro Carvalho Chehab | 38d945e | 2011-12-26 14:34:48 -0300 | [diff] [blame] | 1879 | .delsys = { SYS_DVBS, SYS_DVBS2, SYS_DSS }, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1880 | .info = { |
| 1881 | .name = "STV0900 frontend", |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1882 | .frequency_min = 950000, |
| 1883 | .frequency_max = 2150000, |
| 1884 | .frequency_stepsize = 125, |
| 1885 | .frequency_tolerance = 0, |
| 1886 | .symbol_rate_min = 1000000, |
| 1887 | .symbol_rate_max = 45000000, |
| 1888 | .symbol_rate_tolerance = 500, |
| 1889 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | |
| 1890 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | |
| 1891 | FE_CAN_FEC_7_8 | FE_CAN_QPSK | |
| 1892 | FE_CAN_2G_MODULATION | |
| 1893 | FE_CAN_FEC_AUTO |
| 1894 | }, |
| 1895 | .release = stv0900_release, |
| 1896 | .init = stv0900_init, |
Mauro Carvalho Chehab | 38d945e | 2011-12-26 14:34:48 -0300 | [diff] [blame] | 1897 | .get_frontend = stv0900_get_frontend, |
Igor M. Liplianin | fa8bae1 | 2011-02-25 18:41:22 -0300 | [diff] [blame] | 1898 | .sleep = stv0900_sleep, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1899 | .get_frontend_algo = stv0900_frontend_algo, |
| 1900 | .i2c_gate_ctrl = stv0900_i2c_gate_ctrl, |
| 1901 | .diseqc_send_master_cmd = stv0900_send_master_cmd, |
| 1902 | .diseqc_send_burst = stv0900_send_burst, |
| 1903 | .diseqc_recv_slave_reply = stv0900_recv_slave_reply, |
| 1904 | .set_tone = stv0900_set_tone, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1905 | .search = stv0900_search, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1906 | .read_status = stv0900_read_status, |
| 1907 | .read_ber = stv0900_read_ber, |
| 1908 | .read_signal_strength = stv0900_read_signal_strength, |
| 1909 | .read_snr = stv0900_read_snr, |
Abylay Ospan | ee1ebcf | 2009-06-08 04:31:26 -0300 | [diff] [blame] | 1910 | .read_ucblocks = stv0900_read_ucblocks, |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1911 | }; |
| 1912 | |
| 1913 | struct dvb_frontend *stv0900_attach(const struct stv0900_config *config, |
| 1914 | struct i2c_adapter *i2c, |
| 1915 | int demod) |
| 1916 | { |
| 1917 | struct stv0900_state *state = NULL; |
| 1918 | struct stv0900_init_params init_params; |
| 1919 | enum fe_stv0900_error err_stv0900; |
| 1920 | |
| 1921 | state = kzalloc(sizeof(struct stv0900_state), GFP_KERNEL); |
| 1922 | if (state == NULL) |
| 1923 | goto error; |
| 1924 | |
| 1925 | state->demod = demod; |
| 1926 | state->config = config; |
| 1927 | state->i2c_adap = i2c; |
| 1928 | |
| 1929 | memcpy(&state->frontend.ops, &stv0900_ops, |
| 1930 | sizeof(struct dvb_frontend_ops)); |
| 1931 | state->frontend.demodulator_priv = state; |
| 1932 | |
| 1933 | switch (demod) { |
| 1934 | case 0: |
| 1935 | case 1: |
| 1936 | init_params.dmd_ref_clk = config->xtal; |
Igor M. Liplianin | 29372a8 | 2009-10-17 08:58:26 -0300 | [diff] [blame] | 1937 | init_params.demod_mode = config->demod_mode; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1938 | init_params.rolloff = STV0900_35; |
| 1939 | init_params.path1_ts_clock = config->path1_mode; |
| 1940 | init_params.tun1_maddress = config->tun1_maddress; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1941 | init_params.tun1_iq_inv = STV0900_IQ_NORMAL; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1942 | init_params.tuner1_adc = config->tun1_adc; |
Igor M. Liplianin | cd79d33 | 2009-12-14 20:24:56 -0300 | [diff] [blame] | 1943 | init_params.tuner1_type = config->tun1_type; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1944 | init_params.path2_ts_clock = config->path2_mode; |
Igor M. Liplianin | f867c3f | 2009-06-19 05:45:23 -0300 | [diff] [blame] | 1945 | init_params.ts_config = config->ts_config_regs; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1946 | init_params.tun2_maddress = config->tun2_maddress; |
| 1947 | init_params.tuner2_adc = config->tun2_adc; |
Igor M. Liplianin | cd79d33 | 2009-12-14 20:24:56 -0300 | [diff] [blame] | 1948 | init_params.tuner2_type = config->tun2_type; |
Igor M. Liplianin | 1e0c397 | 2009-11-06 23:42:22 -0300 | [diff] [blame] | 1949 | init_params.tun2_iq_inv = STV0900_IQ_SWAPPED; |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1950 | |
| 1951 | err_stv0900 = stv0900_init_internal(&state->frontend, |
| 1952 | &init_params); |
| 1953 | |
| 1954 | if (err_stv0900) |
| 1955 | goto error; |
| 1956 | |
Evgeny Plehov | 73ec66c | 2012-11-29 15:27:38 -0300 | [diff] [blame] | 1957 | if (state->internal->chip_id >= 0x30) |
| 1958 | state->frontend.ops.info.caps |= FE_CAN_MULTISTREAM; |
| 1959 | |
Igor M. Liplianin | 99277b3 | 2009-03-03 11:45:49 -0300 | [diff] [blame] | 1960 | break; |
| 1961 | default: |
| 1962 | goto error; |
| 1963 | break; |
| 1964 | } |
| 1965 | |
| 1966 | dprintk("%s: Attaching STV0900 demodulator(%d) \n", __func__, demod); |
| 1967 | return &state->frontend; |
| 1968 | |
| 1969 | error: |
| 1970 | dprintk("%s: Failed to attach STV0900 demodulator(%d) \n", |
| 1971 | __func__, demod); |
| 1972 | kfree(state); |
| 1973 | return NULL; |
| 1974 | } |
| 1975 | EXPORT_SYMBOL(stv0900_attach); |
| 1976 | |
| 1977 | MODULE_PARM_DESC(debug, "Set debug"); |
| 1978 | |
| 1979 | MODULE_AUTHOR("Igor M. Liplianin"); |
| 1980 | MODULE_DESCRIPTION("ST STV0900 frontend"); |
| 1981 | MODULE_LICENSE("GPL"); |