Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | Driver for Zarlink VP310/MT312 Satellite Channel Decoder |
| 3 | |
| 4 | Copyright (C) 2003 Andreas Oberritter <obi@linuxtv.org> |
| 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 2 of the License, or |
| 9 | (at your option) any later version. |
| 10 | |
| 11 | This program is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | |
| 21 | References: |
| 22 | http://products.zarlink.com/product_profiles/MT312.htm |
| 23 | http://products.zarlink.com/product_profiles/SL1935.htm |
| 24 | */ |
| 25 | |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 31 | #include <linux/string.h> |
| 32 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | #include "dvb_frontend.h" |
| 35 | #include "mt312_priv.h" |
| 36 | #include "mt312.h" |
| 37 | |
| 38 | |
| 39 | struct mt312_state { |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 40 | struct i2c_adapter *i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* configuration settings */ |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 42 | const struct mt312_config *config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | struct dvb_frontend frontend; |
| 44 | |
| 45 | u8 id; |
| 46 | u8 frequency; |
| 47 | }; |
| 48 | |
| 49 | static int debug; |
| 50 | #define dprintk(args...) \ |
| 51 | do { \ |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 52 | if (debug) \ |
| 53 | printk(KERN_DEBUG "mt312: " args); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | } while (0) |
| 55 | |
| 56 | #define MT312_SYS_CLK 90000000UL /* 90 MHz */ |
| 57 | #define MT312_LPOWER_SYS_CLK 60000000UL /* 60 MHz */ |
| 58 | #define MT312_PLL_CLK 10000000UL /* 10 MHz */ |
| 59 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 60 | static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg, |
Matthias Schwarzott | 1881ee8 | 2008-04-12 15:04:46 -0300 | [diff] [blame] | 61 | u8 *buf, const size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
| 63 | int ret; |
| 64 | struct i2c_msg msg[2]; |
| 65 | u8 regbuf[1] = { reg }; |
| 66 | |
| 67 | msg[0].addr = state->config->demod_address; |
| 68 | msg[0].flags = 0; |
| 69 | msg[0].buf = regbuf; |
| 70 | msg[0].len = 1; |
| 71 | msg[1].addr = state->config->demod_address; |
| 72 | msg[1].flags = I2C_M_RD; |
| 73 | msg[1].buf = buf; |
| 74 | msg[1].len = count; |
| 75 | |
| 76 | ret = i2c_transfer(state->i2c, msg, 2); |
| 77 | |
| 78 | if (ret != 2) { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 79 | printk(KERN_ERR "%s: ret == %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | return -EREMOTEIO; |
| 81 | } |
| 82 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 83 | if (debug) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | int i; |
| 85 | dprintk("R(%d):", reg & 0x7f); |
| 86 | for (i = 0; i < count; i++) |
Matthias Schwarzott | 1881ee8 | 2008-04-12 15:04:46 -0300 | [diff] [blame] | 87 | printk(" %02x", buf[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | printk("\n"); |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 94 | static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg, |
Matthias Schwarzott | 1881ee8 | 2008-04-12 15:04:46 -0300 | [diff] [blame] | 95 | const u8 *src, const size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | { |
| 97 | int ret; |
| 98 | u8 buf[count + 1]; |
| 99 | struct i2c_msg msg; |
| 100 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 101 | if (debug) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | int i; |
| 103 | dprintk("W(%d):", reg & 0x7f); |
| 104 | for (i = 0; i < count; i++) |
Matthias Schwarzott | 1881ee8 | 2008-04-12 15:04:46 -0300 | [diff] [blame] | 105 | printk(" %02x", src[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | printk("\n"); |
| 107 | } |
| 108 | |
| 109 | buf[0] = reg; |
| 110 | memcpy(&buf[1], src, count); |
| 111 | |
| 112 | msg.addr = state->config->demod_address; |
| 113 | msg.flags = 0; |
| 114 | msg.buf = buf; |
| 115 | msg.len = count + 1; |
| 116 | |
| 117 | ret = i2c_transfer(state->i2c, &msg, 1); |
| 118 | |
| 119 | if (ret != 1) { |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 120 | dprintk("%s: ret == %d\n", __func__, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | return -EREMOTEIO; |
| 122 | } |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 127 | static inline int mt312_readreg(struct mt312_state *state, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | const enum mt312_reg_addr reg, u8 *val) |
| 129 | { |
| 130 | return mt312_read(state, reg, val, 1); |
| 131 | } |
| 132 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 133 | static inline int mt312_writereg(struct mt312_state *state, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | const enum mt312_reg_addr reg, const u8 val) |
| 135 | { |
| 136 | return mt312_write(state, reg, &val, 1); |
| 137 | } |
| 138 | |
| 139 | static inline u32 mt312_div(u32 a, u32 b) |
| 140 | { |
| 141 | return (a + (b / 2)) / b; |
| 142 | } |
| 143 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 144 | static int mt312_reset(struct mt312_state *state, const u8 full) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | { |
| 146 | return mt312_writereg(state, RESET, full ? 0x80 : 0x40); |
| 147 | } |
| 148 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 149 | static int mt312_get_inversion(struct mt312_state *state, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | fe_spectral_inversion_t *i) |
| 151 | { |
| 152 | int ret; |
| 153 | u8 vit_mode; |
| 154 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 155 | ret = mt312_readreg(state, VIT_MODE, &vit_mode); |
| 156 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return ret; |
| 158 | |
| 159 | if (vit_mode & 0x80) /* auto inversion was used */ |
| 160 | *i = (vit_mode & 0x40) ? INVERSION_ON : INVERSION_OFF; |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 165 | static int mt312_get_symbol_rate(struct mt312_state *state, u32 *sr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { |
| 167 | int ret; |
| 168 | u8 sym_rate_h; |
| 169 | u8 dec_ratio; |
| 170 | u16 sym_rat_op; |
| 171 | u16 monitor; |
| 172 | u8 buf[2]; |
| 173 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 174 | ret = mt312_readreg(state, SYM_RATE_H, &sym_rate_h); |
| 175 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | return ret; |
| 177 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 178 | if (sym_rate_h & 0x80) { |
| 179 | /* symbol rate search was used */ |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 180 | ret = mt312_writereg(state, MON_CTRL, 0x03); |
| 181 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | return ret; |
| 183 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 184 | ret = mt312_read(state, MONITOR_H, buf, sizeof(buf)); |
| 185 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | return ret; |
| 187 | |
| 188 | monitor = (buf[0] << 8) | buf[1]; |
| 189 | |
Matthias Schwarzott | 0b6a334 | 2007-12-21 08:58:09 -0300 | [diff] [blame] | 190 | dprintk("sr(auto) = %u\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | mt312_div(monitor * 15625, 4)); |
| 192 | } else { |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 193 | ret = mt312_writereg(state, MON_CTRL, 0x05); |
| 194 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | return ret; |
| 196 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 197 | ret = mt312_read(state, MONITOR_H, buf, sizeof(buf)); |
| 198 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | return ret; |
| 200 | |
| 201 | dec_ratio = ((buf[0] >> 5) & 0x07) * 32; |
| 202 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 203 | ret = mt312_read(state, SYM_RAT_OP_H, buf, sizeof(buf)); |
| 204 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | return ret; |
| 206 | |
| 207 | sym_rat_op = (buf[0] << 8) | buf[1]; |
| 208 | |
Matthias Schwarzott | 0b6a334 | 2007-12-21 08:58:09 -0300 | [diff] [blame] | 209 | dprintk("sym_rat_op=%d dec_ratio=%d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | sym_rat_op, dec_ratio); |
Matthias Schwarzott | 0b6a334 | 2007-12-21 08:58:09 -0300 | [diff] [blame] | 211 | dprintk("*sr(manual) = %lu\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | (((MT312_PLL_CLK * 8192) / (sym_rat_op + 8192)) * |
| 213 | 2) - dec_ratio); |
| 214 | } |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 219 | static int mt312_get_code_rate(struct mt312_state *state, fe_code_rate_t *cr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
| 221 | const fe_code_rate_t fec_tab[8] = |
| 222 | { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8, |
| 223 | FEC_AUTO, FEC_AUTO }; |
| 224 | |
| 225 | int ret; |
| 226 | u8 fec_status; |
| 227 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 228 | ret = mt312_readreg(state, FEC_STATUS, &fec_status); |
| 229 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | return ret; |
| 231 | |
| 232 | *cr = fec_tab[(fec_status >> 4) & 0x07]; |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 237 | static int mt312_initfe(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 239 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | int ret; |
| 241 | u8 buf[2]; |
| 242 | |
| 243 | /* wake up */ |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 244 | ret = mt312_writereg(state, CONFIG, |
| 245 | (state->frequency == 60 ? 0x88 : 0x8c)); |
| 246 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | return ret; |
| 248 | |
| 249 | /* wait at least 150 usec */ |
| 250 | udelay(150); |
| 251 | |
| 252 | /* full reset */ |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 253 | ret = mt312_reset(state, 1); |
| 254 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | return ret; |
| 256 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 257 | /* Per datasheet, write correct values. 09/28/03 ACCJr. |
| 258 | * If we don't do this, we won't get FE_HAS_VITERBI in the VP310. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 260 | u8 buf_def[8] = { 0x14, 0x12, 0x03, 0x02, |
| 261 | 0x01, 0x00, 0x00, 0x00 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 263 | ret = mt312_write(state, VIT_SETUP, buf_def, sizeof(buf_def)); |
| 264 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | return ret; |
| 266 | } |
| 267 | |
| 268 | /* SYS_CLK */ |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 269 | buf[0] = mt312_div((state->frequency == 60 ? MT312_LPOWER_SYS_CLK : |
| 270 | MT312_SYS_CLK) * 2, 1000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | |
| 272 | /* DISEQC_RATIO */ |
Matthias Schwarzott | 82cd2df | 2008-04-12 15:04:47 -0300 | [diff] [blame^] | 273 | buf[1] = mt312_div(MT312_PLL_CLK, 22000 * 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 275 | ret = mt312_write(state, SYS_CLK, buf, sizeof(buf)); |
| 276 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | return ret; |
| 278 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 279 | ret = mt312_writereg(state, SNR_THS_HIGH, 0x32); |
| 280 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | return ret; |
| 282 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 283 | ret = mt312_writereg(state, OP_CTRL, 0x53); |
| 284 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | return ret; |
| 286 | |
| 287 | /* TS_SW_LIM */ |
| 288 | buf[0] = 0x8c; |
| 289 | buf[1] = 0x98; |
| 290 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 291 | ret = mt312_write(state, TS_SW_LIM_L, buf, sizeof(buf)); |
| 292 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | return ret; |
| 294 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 295 | ret = mt312_writereg(state, CS_SW_LIM, 0x69); |
| 296 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | return ret; |
| 298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 302 | static int mt312_send_master_cmd(struct dvb_frontend *fe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | struct dvb_diseqc_master_cmd *c) |
| 304 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 305 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | int ret; |
| 307 | u8 diseqc_mode; |
| 308 | |
| 309 | if ((c->msg_len == 0) || (c->msg_len > sizeof(c->msg))) |
| 310 | return -EINVAL; |
| 311 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 312 | ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode); |
| 313 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | return ret; |
| 315 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 316 | ret = mt312_write(state, (0x80 | DISEQC_INSTR), c->msg, c->msg_len); |
| 317 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return ret; |
| 319 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 320 | ret = mt312_writereg(state, DISEQC_MODE, |
| 321 | (diseqc_mode & 0x40) | ((c->msg_len - 1) << 3) |
| 322 | | 0x04); |
| 323 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | return ret; |
| 325 | |
Matthias Schwarzott | 82cd2df | 2008-04-12 15:04:47 -0300 | [diff] [blame^] | 326 | /* is there a better way to wait for message to be transmitted */ |
| 327 | msleep(100); |
| 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | /* set DISEQC_MODE[2:0] to zero if a return message is expected */ |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 330 | if (c->msg[0] & 0x02) { |
| 331 | ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40)); |
| 332 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return ret; |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 334 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 339 | static int mt312_send_burst(struct dvb_frontend *fe, const fe_sec_mini_cmd_t c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 341 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | const u8 mini_tab[2] = { 0x02, 0x03 }; |
| 343 | |
| 344 | int ret; |
| 345 | u8 diseqc_mode; |
| 346 | |
| 347 | if (c > SEC_MINI_B) |
| 348 | return -EINVAL; |
| 349 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 350 | ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode); |
| 351 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return ret; |
| 353 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 354 | ret = mt312_writereg(state, DISEQC_MODE, |
| 355 | (diseqc_mode & 0x40) | mini_tab[c]); |
| 356 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return ret; |
| 358 | |
| 359 | return 0; |
| 360 | } |
| 361 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 362 | static int mt312_set_tone(struct dvb_frontend *fe, const fe_sec_tone_mode_t t) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 364 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | const u8 tone_tab[2] = { 0x01, 0x00 }; |
| 366 | |
| 367 | int ret; |
| 368 | u8 diseqc_mode; |
| 369 | |
| 370 | if (t > SEC_TONE_OFF) |
| 371 | return -EINVAL; |
| 372 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 373 | ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode); |
| 374 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return ret; |
| 376 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 377 | ret = mt312_writereg(state, DISEQC_MODE, |
| 378 | (diseqc_mode & 0x40) | tone_tab[t]); |
| 379 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | return ret; |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 385 | static int mt312_set_voltage(struct dvb_frontend *fe, const fe_sec_voltage_t v) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 387 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | const u8 volt_tab[3] = { 0x00, 0x40, 0x00 }; |
| 389 | |
| 390 | if (v > SEC_VOLTAGE_OFF) |
| 391 | return -EINVAL; |
| 392 | |
| 393 | return mt312_writereg(state, DISEQC_MODE, volt_tab[v]); |
| 394 | } |
| 395 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 396 | static int mt312_read_status(struct dvb_frontend *fe, fe_status_t *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 398 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | int ret; |
| 400 | u8 status[3]; |
| 401 | |
| 402 | *s = 0; |
| 403 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 404 | ret = mt312_read(state, QPSK_STAT_H, status, sizeof(status)); |
| 405 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | return ret; |
| 407 | |
Matthias Schwarzott | 0b6a334 | 2007-12-21 08:58:09 -0300 | [diff] [blame] | 408 | dprintk("QPSK_STAT_H: 0x%02x, QPSK_STAT_L: 0x%02x," |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 409 | " FEC_STATUS: 0x%02x\n", status[0], status[1], status[2]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | if (status[0] & 0xc0) |
| 412 | *s |= FE_HAS_SIGNAL; /* signal noise ratio */ |
| 413 | if (status[0] & 0x04) |
| 414 | *s |= FE_HAS_CARRIER; /* qpsk carrier lock */ |
| 415 | if (status[2] & 0x02) |
| 416 | *s |= FE_HAS_VITERBI; /* viterbi lock */ |
| 417 | if (status[2] & 0x04) |
| 418 | *s |= FE_HAS_SYNC; /* byte align lock */ |
| 419 | if (status[0] & 0x01) |
| 420 | *s |= FE_HAS_LOCK; /* qpsk lock */ |
| 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 425 | static int mt312_read_ber(struct dvb_frontend *fe, u32 *ber) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 427 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | int ret; |
| 429 | u8 buf[3]; |
| 430 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 431 | ret = mt312_read(state, RS_BERCNT_H, buf, 3); |
| 432 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | return ret; |
| 434 | |
| 435 | *ber = ((buf[0] << 16) | (buf[1] << 8) | buf[2]) * 64; |
| 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 440 | static int mt312_read_signal_strength(struct dvb_frontend *fe, |
| 441 | u16 *signal_strength) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 443 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | int ret; |
| 445 | u8 buf[3]; |
| 446 | u16 agc; |
| 447 | s16 err_db; |
| 448 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 449 | ret = mt312_read(state, AGC_H, buf, sizeof(buf)); |
| 450 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return ret; |
| 452 | |
| 453 | agc = (buf[0] << 6) | (buf[1] >> 2); |
| 454 | err_db = (s16) (((buf[1] & 0x03) << 14) | buf[2] << 6) >> 6; |
| 455 | |
| 456 | *signal_strength = agc; |
| 457 | |
Matthias Schwarzott | 0b6a334 | 2007-12-21 08:58:09 -0300 | [diff] [blame] | 458 | dprintk("agc=%08x err_db=%hd\n", agc, err_db); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 463 | static int mt312_read_snr(struct dvb_frontend *fe, u16 *snr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 465 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | int ret; |
| 467 | u8 buf[2]; |
| 468 | |
Matthias Schwarzott | 1881ee8 | 2008-04-12 15:04:46 -0300 | [diff] [blame] | 469 | ret = mt312_read(state, M_SNR_H, buf, sizeof(buf)); |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 470 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | return ret; |
| 472 | |
| 473 | *snr = 0xFFFF - ((((buf[0] & 0x7f) << 8) | buf[1]) << 1); |
| 474 | |
| 475 | return 0; |
| 476 | } |
| 477 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 478 | static int mt312_read_ucblocks(struct dvb_frontend *fe, u32 *ubc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 480 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | int ret; |
| 482 | u8 buf[2]; |
| 483 | |
Matthias Schwarzott | 1881ee8 | 2008-04-12 15:04:46 -0300 | [diff] [blame] | 484 | ret = mt312_read(state, RS_UBC_H, buf, sizeof(buf)); |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 485 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | return ret; |
| 487 | |
| 488 | *ubc = (buf[0] << 8) | buf[1]; |
| 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 493 | static int mt312_set_frontend(struct dvb_frontend *fe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | struct dvb_frontend_parameters *p) |
| 495 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 496 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | int ret; |
| 498 | u8 buf[5], config_val; |
| 499 | u16 sr; |
| 500 | |
| 501 | const u8 fec_tab[10] = |
| 502 | { 0x00, 0x01, 0x02, 0x04, 0x3f, 0x08, 0x10, 0x20, 0x3f, 0x3f }; |
| 503 | const u8 inv_tab[3] = { 0x00, 0x40, 0x80 }; |
| 504 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 505 | dprintk("%s: Freq %d\n", __func__, p->frequency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 507 | if ((p->frequency < fe->ops.info.frequency_min) |
| 508 | || (p->frequency > fe->ops.info.frequency_max)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | return -EINVAL; |
| 510 | |
| 511 | if ((p->inversion < INVERSION_OFF) |
| 512 | || (p->inversion > INVERSION_ON)) |
| 513 | return -EINVAL; |
| 514 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 515 | if ((p->u.qpsk.symbol_rate < fe->ops.info.symbol_rate_min) |
| 516 | || (p->u.qpsk.symbol_rate > fe->ops.info.symbol_rate_max)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | return -EINVAL; |
| 518 | |
| 519 | if ((p->u.qpsk.fec_inner < FEC_NONE) |
| 520 | || (p->u.qpsk.fec_inner > FEC_AUTO)) |
| 521 | return -EINVAL; |
| 522 | |
| 523 | if ((p->u.qpsk.fec_inner == FEC_4_5) |
| 524 | || (p->u.qpsk.fec_inner == FEC_8_9)) |
| 525 | return -EINVAL; |
| 526 | |
| 527 | switch (state->id) { |
| 528 | case ID_VP310: |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 529 | /* For now we will do this only for the VP310. |
| 530 | * It should be better for the mt312 as well, |
| 531 | * but tuning will be slower. ACCJr 09/29/03 |
| 532 | */ |
Alexey Dobriyan | 682e852 | 2006-01-10 00:09:16 +0300 | [diff] [blame] | 533 | ret = mt312_readreg(state, CONFIG, &config_val); |
| 534 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | return ret; |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 536 | if (p->u.qpsk.symbol_rate >= 30000000) { |
| 537 | /* Note that 30MS/s should use 90MHz */ |
| 538 | if ((config_val & 0x0c) == 0x08) { |
| 539 | /* We are running 60MHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | state->frequency = 90; |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 541 | ret = mt312_initfe(fe); |
| 542 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | return ret; |
| 544 | } |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 545 | } else { |
| 546 | if ((config_val & 0x0c) == 0x0C) { |
| 547 | /* We are running 90MHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | state->frequency = 60; |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 549 | ret = mt312_initfe(fe); |
| 550 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | return ret; |
| 552 | } |
| 553 | } |
| 554 | break; |
| 555 | |
| 556 | case ID_MT312: |
| 557 | break; |
| 558 | |
| 559 | default: |
| 560 | return -EINVAL; |
| 561 | } |
| 562 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 563 | if (fe->ops.tuner_ops.set_params) { |
| 564 | fe->ops.tuner_ops.set_params(fe, p); |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 565 | if (fe->ops.i2c_gate_ctrl) |
| 566 | fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | a81870e | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | /* sr = (u16)(sr * 256.0 / 1000000.0) */ |
| 570 | sr = mt312_div(p->u.qpsk.symbol_rate * 4, 15625); |
| 571 | |
| 572 | /* SYM_RATE */ |
| 573 | buf[0] = (sr >> 8) & 0x3f; |
| 574 | buf[1] = (sr >> 0) & 0xff; |
| 575 | |
| 576 | /* VIT_MODE */ |
| 577 | buf[2] = inv_tab[p->inversion] | fec_tab[p->u.qpsk.fec_inner]; |
| 578 | |
| 579 | /* QPSK_CTRL */ |
| 580 | buf[3] = 0x40; /* swap I and Q before QPSK demodulation */ |
| 581 | |
| 582 | if (p->u.qpsk.symbol_rate < 10000000) |
| 583 | buf[3] |= 0x04; /* use afc mode */ |
| 584 | |
| 585 | /* GO */ |
| 586 | buf[4] = 0x01; |
| 587 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 588 | ret = mt312_write(state, SYM_RATE_H, buf, sizeof(buf)); |
| 589 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | return ret; |
| 591 | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 592 | mt312_reset(state, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | return 0; |
| 595 | } |
| 596 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 597 | static int mt312_get_frontend(struct dvb_frontend *fe, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | struct dvb_frontend_parameters *p) |
| 599 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 600 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | int ret; |
| 602 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 603 | ret = mt312_get_inversion(state, &p->inversion); |
| 604 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | return ret; |
| 606 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 607 | ret = mt312_get_symbol_rate(state, &p->u.qpsk.symbol_rate); |
| 608 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | return ret; |
| 610 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 611 | ret = mt312_get_code_rate(state, &p->u.qpsk.fec_inner); |
| 612 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | return ret; |
| 614 | |
| 615 | return 0; |
| 616 | } |
| 617 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 618 | static int mt312_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
Andrew de Quincey | a81870e | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 619 | { |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 620 | struct mt312_state *state = fe->demodulator_priv; |
Andrew de Quincey | a81870e | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 621 | |
| 622 | if (enable) { |
| 623 | return mt312_writereg(state, GPP_CTRL, 0x40); |
| 624 | } else { |
| 625 | return mt312_writereg(state, GPP_CTRL, 0x00); |
| 626 | } |
| 627 | } |
| 628 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 629 | static int mt312_sleep(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 631 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | int ret; |
| 633 | u8 config; |
| 634 | |
| 635 | /* reset all registers to defaults */ |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 636 | ret = mt312_reset(state, 1); |
| 637 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | return ret; |
| 639 | |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 640 | ret = mt312_readreg(state, CONFIG, &config); |
| 641 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | return ret; |
| 643 | |
| 644 | /* enter standby */ |
Matthias Schwarzott | 994fc28b | 2007-12-24 07:12:55 -0300 | [diff] [blame] | 645 | ret = mt312_writereg(state, CONFIG, config & 0x7f); |
| 646 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | return ret; |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 652 | static int mt312_get_tune_settings(struct dvb_frontend *fe, |
| 653 | struct dvb_frontend_tune_settings *fesettings) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | { |
| 655 | fesettings->min_delay_ms = 50; |
| 656 | fesettings->step_size = 0; |
| 657 | fesettings->max_drift = 0; |
| 658 | return 0; |
| 659 | } |
| 660 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 661 | static void mt312_release(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | { |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 663 | struct mt312_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | kfree(state); |
| 665 | } |
| 666 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | static struct dvb_frontend_ops vp310_mt312_ops = { |
| 668 | |
| 669 | .info = { |
| 670 | .name = "Zarlink ???? DVB-S", |
| 671 | .type = FE_QPSK, |
| 672 | .frequency_min = 950000, |
| 673 | .frequency_max = 2150000, |
| 674 | .frequency_stepsize = (MT312_PLL_CLK / 1000) / 128, |
| 675 | .symbol_rate_min = MT312_SYS_CLK / 128, |
| 676 | .symbol_rate_max = MT312_SYS_CLK / 2, |
| 677 | .caps = |
| 678 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | |
| 679 | FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | |
| 680 | FE_CAN_FEC_AUTO | FE_CAN_QPSK | FE_CAN_MUTE_TS | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 681 | FE_CAN_RECOVER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | }, |
| 683 | |
| 684 | .release = mt312_release, |
| 685 | |
| 686 | .init = mt312_initfe, |
| 687 | .sleep = mt312_sleep, |
Andrew de Quincey | a81870e | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 688 | .i2c_gate_ctrl = mt312_i2c_gate_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | .set_frontend = mt312_set_frontend, |
| 691 | .get_frontend = mt312_get_frontend, |
| 692 | .get_tune_settings = mt312_get_tune_settings, |
| 693 | |
| 694 | .read_status = mt312_read_status, |
| 695 | .read_ber = mt312_read_ber, |
| 696 | .read_signal_strength = mt312_read_signal_strength, |
| 697 | .read_snr = mt312_read_snr, |
| 698 | .read_ucblocks = mt312_read_ucblocks, |
| 699 | |
| 700 | .diseqc_send_master_cmd = mt312_send_master_cmd, |
| 701 | .diseqc_send_burst = mt312_send_burst, |
| 702 | .set_tone = mt312_set_tone, |
| 703 | .set_voltage = mt312_set_voltage, |
| 704 | }; |
| 705 | |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 706 | struct dvb_frontend *vp310_mt312_attach(const struct mt312_config *config, |
| 707 | struct i2c_adapter *i2c) |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 708 | { |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 709 | struct mt312_state *state = NULL; |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 710 | |
| 711 | /* allocate memory for the internal state */ |
| 712 | state = kmalloc(sizeof(struct mt312_state), GFP_KERNEL); |
| 713 | if (state == NULL) |
| 714 | goto error; |
| 715 | |
| 716 | /* setup the state */ |
| 717 | state->config = config; |
| 718 | state->i2c = i2c; |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 719 | |
| 720 | /* check if the demod is there */ |
| 721 | if (mt312_readreg(state, ID, &state->id) < 0) |
| 722 | goto error; |
| 723 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 724 | /* create dvb_frontend */ |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 725 | memcpy(&state->frontend.ops, &vp310_mt312_ops, |
| 726 | sizeof(struct dvb_frontend_ops)); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 727 | state->frontend.demodulator_priv = state; |
| 728 | |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 729 | switch (state->id) { |
| 730 | case ID_VP310: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 731 | strcpy(state->frontend.ops.info.name, "Zarlink VP310 DVB-S"); |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 732 | state->frequency = 90; |
| 733 | break; |
| 734 | case ID_MT312: |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 735 | strcpy(state->frontend.ops.info.name, "Zarlink MT312 DVB-S"); |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 736 | state->frequency = 60; |
| 737 | break; |
| 738 | default: |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 739 | printk(KERN_WARNING "Only Zarlink VP310/MT312" |
| 740 | " are supported chips.\n"); |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 741 | goto error; |
| 742 | } |
| 743 | |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 744 | return &state->frontend; |
| 745 | |
| 746 | error: |
| 747 | kfree(state); |
| 748 | return NULL; |
| 749 | } |
Matthias Schwarzott | 89f6475 | 2007-12-21 08:56:44 -0300 | [diff] [blame] | 750 | EXPORT_SYMBOL(vp310_mt312_attach); |
Adrian Bunk | 805e660 | 2006-02-27 00:07:49 -0300 | [diff] [blame] | 751 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | module_param(debug, int, 0644); |
| 753 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
| 754 | |
| 755 | MODULE_DESCRIPTION("Zarlink VP310/MT312 DVB-S Demodulator driver"); |
| 756 | MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>"); |
| 757 | MODULE_LICENSE("GPL"); |
| 758 | |