📄 mt312.c
字号:
/* Driver for Zarlink VP310/MT312 Satellite Channel Decoder Copyright (C) 2003 Andreas Oberritter <obi@linuxtv.org> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. References: http://products.zarlink.com/product_profiles/MT312.htm http://products.zarlink.com/product_profiles/SL1935.htm*/#include <linux/delay.h>#include <linux/errno.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/string.h>#include <linux/slab.h>#include "dvb_frontend.h"#include "mt312_priv.h"#include "mt312.h"struct mt312_state { struct i2c_adapter* i2c; struct dvb_frontend_ops ops; /* configuration settings */ const struct mt312_config* config; struct dvb_frontend frontend; u8 id; u8 frequency;};static int debug;#define dprintk(args...) \ do { \ if (debug) printk(KERN_DEBUG "mt312: " args); \ } while (0)#define MT312_SYS_CLK 90000000UL /* 90 MHz */#define MT312_LPOWER_SYS_CLK 60000000UL /* 60 MHz */#define MT312_PLL_CLK 10000000UL /* 10 MHz */static int mt312_read(struct mt312_state* state, const enum mt312_reg_addr reg, void *buf, const size_t count){ int ret; struct i2c_msg msg[2]; u8 regbuf[1] = { reg }; msg[0].addr = state->config->demod_address; msg[0].flags = 0; msg[0].buf = regbuf; msg[0].len = 1; msg[1].addr = state->config->demod_address; msg[1].flags = I2C_M_RD; msg[1].buf = buf; msg[1].len = count; ret = i2c_transfer(state->i2c, msg, 2); if (ret != 2) { printk(KERN_ERR "%s: ret == %d\n", __FUNCTION__, ret); return -EREMOTEIO; } if(debug) { int i; dprintk("R(%d):", reg & 0x7f); for (i = 0; i < count; i++) printk(" %02x", ((const u8 *) buf)[i]); printk("\n"); } return 0;}static int mt312_write(struct mt312_state* state, const enum mt312_reg_addr reg, const void *src, const size_t count){ int ret; u8 buf[count + 1]; struct i2c_msg msg; if(debug) { int i; dprintk("W(%d):", reg & 0x7f); for (i = 0; i < count; i++) printk(" %02x", ((const u8 *) src)[i]); printk("\n"); } buf[0] = reg; memcpy(&buf[1], src, count); msg.addr = state->config->demod_address; msg.flags = 0; msg.buf = buf; msg.len = count + 1; ret = i2c_transfer(state->i2c, &msg, 1); if (ret != 1) { dprintk("%s: ret == %d\n", __FUNCTION__, ret); return -EREMOTEIO; } return 0;}static inline int mt312_readreg(struct mt312_state* state, const enum mt312_reg_addr reg, u8 *val){ return mt312_read(state, reg, val, 1);}static inline int mt312_writereg(struct mt312_state* state, const enum mt312_reg_addr reg, const u8 val){ return mt312_write(state, reg, &val, 1);}static inline u32 mt312_div(u32 a, u32 b){ return (a + (b / 2)) / b;}static int mt312_reset(struct mt312_state* state, const u8 full){ return mt312_writereg(state, RESET, full ? 0x80 : 0x40);}static int mt312_get_inversion(struct mt312_state* state, fe_spectral_inversion_t *i){ int ret; u8 vit_mode; if ((ret = mt312_readreg(state, VIT_MODE, &vit_mode)) < 0) return ret; if (vit_mode & 0x80) /* auto inversion was used */ *i = (vit_mode & 0x40) ? INVERSION_ON : INVERSION_OFF; return 0;}static int mt312_get_symbol_rate(struct mt312_state* state, u32 *sr){ int ret; u8 sym_rate_h; u8 dec_ratio; u16 sym_rat_op; u16 monitor; u8 buf[2]; if ((ret = mt312_readreg(state, SYM_RATE_H, &sym_rate_h)) < 0) return ret; if (sym_rate_h & 0x80) { /* symbol rate search was used */ if ((ret = mt312_writereg(state, MON_CTRL, 0x03)) < 0) return ret; if ((ret = mt312_read(state, MONITOR_H, buf, sizeof(buf))) < 0) return ret; monitor = (buf[0] << 8) | buf[1]; dprintk(KERN_DEBUG "sr(auto) = %u\n", mt312_div(monitor * 15625, 4)); } else { if ((ret = mt312_writereg(state, MON_CTRL, 0x05)) < 0) return ret; if ((ret = mt312_read(state, MONITOR_H, buf, sizeof(buf))) < 0) return ret; dec_ratio = ((buf[0] >> 5) & 0x07) * 32; if ((ret = mt312_read(state, SYM_RAT_OP_H, buf, sizeof(buf))) < 0) return ret; sym_rat_op = (buf[0] << 8) | buf[1]; dprintk(KERN_DEBUG "sym_rat_op=%d dec_ratio=%d\n", sym_rat_op, dec_ratio); dprintk(KERN_DEBUG "*sr(manual) = %lu\n", (((MT312_PLL_CLK * 8192) / (sym_rat_op + 8192)) * 2) - dec_ratio); } return 0;}static int mt312_get_code_rate(struct mt312_state* state, fe_code_rate_t *cr){ const fe_code_rate_t fec_tab[8] = { FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_6_7, FEC_7_8, FEC_AUTO, FEC_AUTO }; int ret; u8 fec_status; if ((ret = mt312_readreg(state, FEC_STATUS, &fec_status)) < 0) return ret; *cr = fec_tab[(fec_status >> 4) & 0x07]; return 0;}static int mt312_initfe(struct dvb_frontend* fe){ struct mt312_state *state = fe->demodulator_priv; int ret; u8 buf[2]; /* wake up */ if ((ret = mt312_writereg(state, CONFIG, (state->frequency == 60 ? 0x88 : 0x8c))) < 0) return ret; /* wait at least 150 usec */ udelay(150); /* full reset */ if ((ret = mt312_reset(state, 1)) < 0) return ret;// Per datasheet, write correct values. 09/28/03 ACCJr.// If we don't do this, we won't get FE_HAS_VITERBI in the VP310. { u8 buf_def[8]={0x14, 0x12, 0x03, 0x02, 0x01, 0x00, 0x00, 0x00}; if ((ret = mt312_write(state, VIT_SETUP, buf_def, sizeof(buf_def))) < 0) return ret; } /* SYS_CLK */ buf[0] = mt312_div((state->frequency == 60 ? MT312_LPOWER_SYS_CLK : MT312_SYS_CLK) * 2, 1000000); /* DISEQC_RATIO */ buf[1] = mt312_div(MT312_PLL_CLK, 15000 * 4); if ((ret = mt312_write(state, SYS_CLK, buf, sizeof(buf))) < 0) return ret; if ((ret = mt312_writereg(state, SNR_THS_HIGH, 0x32)) < 0) return ret; if ((ret = mt312_writereg(state, OP_CTRL, 0x53)) < 0) return ret; /* TS_SW_LIM */ buf[0] = 0x8c; buf[1] = 0x98; if ((ret = mt312_write(state, TS_SW_LIM_L, buf, sizeof(buf))) < 0) return ret; if ((ret = mt312_writereg(state, CS_SW_LIM, 0x69)) < 0) return ret; if (state->config->pll_init) { mt312_writereg(state, GPP_CTRL, 0x40); state->config->pll_init(fe); mt312_writereg(state, GPP_CTRL, 0x00); } return 0;}static int mt312_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *c){ struct mt312_state *state = fe->demodulator_priv; int ret; u8 diseqc_mode; if ((c->msg_len == 0) || (c->msg_len > sizeof(c->msg))) return -EINVAL; if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0) return ret; if ((ret = mt312_write(state, (0x80 | DISEQC_INSTR), c->msg, c->msg_len)) < 0) return ret; if ((ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40) | ((c->msg_len - 1) << 3) | 0x04)) < 0) return ret; /* set DISEQC_MODE[2:0] to zero if a return message is expected */ if (c->msg[0] & 0x02) if ((ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40))) < 0) return ret; return 0;}static int mt312_send_burst(struct dvb_frontend* fe, const fe_sec_mini_cmd_t c){ struct mt312_state *state = fe->demodulator_priv; const u8 mini_tab[2] = { 0x02, 0x03 }; int ret; u8 diseqc_mode; if (c > SEC_MINI_B) return -EINVAL; if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0) return ret; if ((ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40) | mini_tab[c])) < 0) return ret; return 0;}static int mt312_set_tone(struct dvb_frontend* fe, const fe_sec_tone_mode_t t){ struct mt312_state *state = fe->demodulator_priv; const u8 tone_tab[2] = { 0x01, 0x00 }; int ret; u8 diseqc_mode; if (t > SEC_TONE_OFF) return -EINVAL; if ((ret = mt312_readreg(state, DISEQC_MODE, &diseqc_mode)) < 0) return ret; if ((ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40) | tone_tab[t])) < 0) return ret; return 0;}static int mt312_set_voltage(struct dvb_frontend* fe, const fe_sec_voltage_t v){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -