Path: blob/master/drivers/media/dvb/frontends/cx24116.c
15112 views
/*1Conexant cx24116/cx24118 - DVBS/S2 Satellite demod/tuner driver23Copyright (C) 2006-2008 Steven Toth <[email protected]>4Copyright (C) 2006-2007 Georg Acher5Copyright (C) 2007-2008 Darron Broad6March 20077Fixed some bugs.8Added diseqc support.9Added corrected signal strength support.10August 200711Sync with legacy version.12Some clean ups.13Copyright (C) 2008 Igor Liplianin14September, 9th 200815Fixed locking on high symbol rates (>30000).16Implement MPEG initialization parameter.17January, 17th 200918Fill set_voltage with actually control voltage code.19Correct set tone to not affect voltage.2021This program is free software; you can redistribute it and/or modify22it under the terms of the GNU General Public License as published by23the Free Software Foundation; either version 2 of the License, or24(at your option) any later version.2526This program is distributed in the hope that it will be useful,27but WITHOUT ANY WARRANTY; without even the implied warranty of28MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the29GNU General Public License for more details.3031You should have received a copy of the GNU General Public License32along with this program; if not, write to the Free Software33Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.34*/3536#include <linux/slab.h>37#include <linux/kernel.h>38#include <linux/module.h>39#include <linux/moduleparam.h>40#include <linux/init.h>41#include <linux/firmware.h>4243#include "dvb_frontend.h"44#include "cx24116.h"4546static int debug;47module_param(debug, int, 0644);48MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");4950#define dprintk(args...) \51do { \52if (debug) \53printk(KERN_INFO "cx24116: " args); \54} while (0)5556#define CX24116_DEFAULT_FIRMWARE "dvb-fe-cx24116.fw"57#define CX24116_SEARCH_RANGE_KHZ 50005859/* known registers */60#define CX24116_REG_COMMAND (0x00) /* command args 0x00..0x1e */61#define CX24116_REG_EXECUTE (0x1f) /* execute command */62#define CX24116_REG_MAILBOX (0x96) /* FW or multipurpose mailbox? */63#define CX24116_REG_RESET (0x20) /* reset status > 0 */64#define CX24116_REG_SIGNAL (0x9e) /* signal low */65#define CX24116_REG_SSTATUS (0x9d) /* signal high / status */66#define CX24116_REG_QUALITY8 (0xa3)67#define CX24116_REG_QSTATUS (0xbc)68#define CX24116_REG_QUALITY0 (0xd5)69#define CX24116_REG_BER0 (0xc9)70#define CX24116_REG_BER8 (0xc8)71#define CX24116_REG_BER16 (0xc7)72#define CX24116_REG_BER24 (0xc6)73#define CX24116_REG_UCB0 (0xcb)74#define CX24116_REG_UCB8 (0xca)75#define CX24116_REG_CLKDIV (0xf3)76#define CX24116_REG_RATEDIV (0xf9)7778/* configured fec (not tuned) or actual FEC (tuned) 1=1/2 2=2/3 etc */79#define CX24116_REG_FECSTATUS (0x9c)8081/* FECSTATUS bits */82/* mask to determine configured fec (not tuned) or actual fec (tuned) */83#define CX24116_FEC_FECMASK (0x1f)8485/* Select DVB-S demodulator, else DVB-S2 */86#define CX24116_FEC_DVBS (0x20)87#define CX24116_FEC_UNKNOWN (0x40) /* Unknown/unused */8889/* Pilot mode requested when tuning else always reset when tuned */90#define CX24116_FEC_PILOT (0x80)9192/* arg buffer size */93#define CX24116_ARGLEN (0x1e)9495/* rolloff */96#define CX24116_ROLLOFF_020 (0x00)97#define CX24116_ROLLOFF_025 (0x01)98#define CX24116_ROLLOFF_035 (0x02)99100/* pilot bit */101#define CX24116_PILOT_OFF (0x00)102#define CX24116_PILOT_ON (0x40)103104/* signal status */105#define CX24116_HAS_SIGNAL (0x01)106#define CX24116_HAS_CARRIER (0x02)107#define CX24116_HAS_VITERBI (0x04)108#define CX24116_HAS_SYNCLOCK (0x08)109#define CX24116_HAS_UNKNOWN1 (0x10)110#define CX24116_HAS_UNKNOWN2 (0x20)111#define CX24116_STATUS_MASK (0x0f)112#define CX24116_SIGNAL_MASK (0xc0)113114#define CX24116_DISEQC_TONEOFF (0) /* toneburst never sent */115#define CX24116_DISEQC_TONECACHE (1) /* toneburst cached */116#define CX24116_DISEQC_MESGCACHE (2) /* message cached */117118/* arg offset for DiSEqC */119#define CX24116_DISEQC_BURST (1)120#define CX24116_DISEQC_ARG2_2 (2) /* unknown value=2 */121#define CX24116_DISEQC_ARG3_0 (3) /* unknown value=0 */122#define CX24116_DISEQC_ARG4_0 (4) /* unknown value=0 */123#define CX24116_DISEQC_MSGLEN (5)124#define CX24116_DISEQC_MSGOFS (6)125126/* DiSEqC burst */127#define CX24116_DISEQC_MINI_A (0)128#define CX24116_DISEQC_MINI_B (1)129130/* DiSEqC tone burst */131static int toneburst = 1;132module_param(toneburst, int, 0644);133MODULE_PARM_DESC(toneburst, "DiSEqC toneburst 0=OFF, 1=TONE CACHE, "\134"2=MESSAGE CACHE (default:1)");135136/* SNR measurements */137static int esno_snr;138module_param(esno_snr, int, 0644);139MODULE_PARM_DESC(esno_snr, "SNR return units, 0=PERCENTAGE 0-100, "\140"1=ESNO(db * 10) (default:0)");141142enum cmds {143CMD_SET_VCO = 0x10,144CMD_TUNEREQUEST = 0x11,145CMD_MPEGCONFIG = 0x13,146CMD_TUNERINIT = 0x14,147CMD_BANDWIDTH = 0x15,148CMD_GETAGC = 0x19,149CMD_LNBCONFIG = 0x20,150CMD_LNBSEND = 0x21, /* Formerly CMD_SEND_DISEQC */151CMD_LNBDCLEVEL = 0x22,152CMD_SET_TONE = 0x23,153CMD_UPDFWVERS = 0x35,154CMD_TUNERSLEEP = 0x36,155CMD_AGCCONTROL = 0x3b, /* Unknown */156};157158/* The Demod/Tuner can't easily provide these, we cache them */159struct cx24116_tuning {160u32 frequency;161u32 symbol_rate;162fe_spectral_inversion_t inversion;163fe_code_rate_t fec;164165fe_delivery_system_t delsys;166fe_modulation_t modulation;167fe_pilot_t pilot;168fe_rolloff_t rolloff;169170/* Demod values */171u8 fec_val;172u8 fec_mask;173u8 inversion_val;174u8 pilot_val;175u8 rolloff_val;176};177178/* Basic commands that are sent to the firmware */179struct cx24116_cmd {180u8 len;181u8 args[CX24116_ARGLEN];182};183184struct cx24116_state {185struct i2c_adapter *i2c;186const struct cx24116_config *config;187188struct dvb_frontend frontend;189190struct cx24116_tuning dcur;191struct cx24116_tuning dnxt;192193u8 skip_fw_load;194u8 burst;195struct cx24116_cmd dsec_cmd;196};197198static int cx24116_writereg(struct cx24116_state *state, int reg, int data)199{200u8 buf[] = { reg, data };201struct i2c_msg msg = { .addr = state->config->demod_address,202.flags = 0, .buf = buf, .len = 2 };203int err;204205if (debug > 1)206printk("cx24116: %s: write reg 0x%02x, value 0x%02x\n",207__func__, reg, data);208209err = i2c_transfer(state->i2c, &msg, 1);210if (err != 1) {211printk(KERN_ERR "%s: writereg error(err == %i, reg == 0x%02x,"212" value == 0x%02x)\n", __func__, err, reg, data);213return -EREMOTEIO;214}215216return 0;217}218219/* Bulk byte writes to a single I2C address, for 32k firmware load */220static int cx24116_writeregN(struct cx24116_state *state, int reg,221const u8 *data, u16 len)222{223int ret = -EREMOTEIO;224struct i2c_msg msg;225u8 *buf;226227buf = kmalloc(len + 1, GFP_KERNEL);228if (buf == NULL) {229printk("Unable to kmalloc\n");230ret = -ENOMEM;231goto error;232}233234*(buf) = reg;235memcpy(buf + 1, data, len);236237msg.addr = state->config->demod_address;238msg.flags = 0;239msg.buf = buf;240msg.len = len + 1;241242if (debug > 1)243printk(KERN_INFO "cx24116: %s: write regN 0x%02x, len = %d\n",244__func__, reg, len);245246ret = i2c_transfer(state->i2c, &msg, 1);247if (ret != 1) {248printk(KERN_ERR "%s: writereg error(err == %i, reg == 0x%02x\n",249__func__, ret, reg);250ret = -EREMOTEIO;251}252253error:254kfree(buf);255256return ret;257}258259static int cx24116_readreg(struct cx24116_state *state, u8 reg)260{261int ret;262u8 b0[] = { reg };263u8 b1[] = { 0 };264struct i2c_msg msg[] = {265{ .addr = state->config->demod_address, .flags = 0,266.buf = b0, .len = 1 },267{ .addr = state->config->demod_address, .flags = I2C_M_RD,268.buf = b1, .len = 1 }269};270271ret = i2c_transfer(state->i2c, msg, 2);272273if (ret != 2) {274printk(KERN_ERR "%s: reg=0x%x (error=%d)\n",275__func__, reg, ret);276return ret;277}278279if (debug > 1)280printk(KERN_INFO "cx24116: read reg 0x%02x, value 0x%02x\n",281reg, b1[0]);282283return b1[0];284}285286static int cx24116_set_inversion(struct cx24116_state *state,287fe_spectral_inversion_t inversion)288{289dprintk("%s(%d)\n", __func__, inversion);290291switch (inversion) {292case INVERSION_OFF:293state->dnxt.inversion_val = 0x00;294break;295case INVERSION_ON:296state->dnxt.inversion_val = 0x04;297break;298case INVERSION_AUTO:299state->dnxt.inversion_val = 0x0C;300break;301default:302return -EINVAL;303}304305state->dnxt.inversion = inversion;306307return 0;308}309310/*311* modfec (modulation and FEC)312* ===========================313*314* MOD FEC mask/val standard315* ---- -------- ----------- --------316* QPSK FEC_1_2 0x02 0x02+X DVB-S317* QPSK FEC_2_3 0x04 0x02+X DVB-S318* QPSK FEC_3_4 0x08 0x02+X DVB-S319* QPSK FEC_4_5 0x10 0x02+X DVB-S (?)320* QPSK FEC_5_6 0x20 0x02+X DVB-S321* QPSK FEC_6_7 0x40 0x02+X DVB-S322* QPSK FEC_7_8 0x80 0x02+X DVB-S323* QPSK FEC_8_9 0x01 0x02+X DVB-S (?) (NOT SUPPORTED?)324* QPSK AUTO 0xff 0x02+X DVB-S325*326* For DVB-S high byte probably represents FEC327* and low byte selects the modulator. The high328* byte is search range mask. Bit 5 may turn329* on DVB-S and remaining bits represent some330* kind of calibration (how/what i do not know).331*332* Eg.(2/3) szap "Zone Horror"333*334* mask/val = 0x04, 0x20335* status 1f | signal c3c0 | snr a333 | ber 00000098 | unc 0 | FE_HAS_LOCK336*337* mask/val = 0x04, 0x30338* status 1f | signal c3c0 | snr a333 | ber 00000000 | unc 0 | FE_HAS_LOCK339*340* After tuning FECSTATUS contains actual FEC341* in use numbered 1 through to 8 for 1/2 .. 2/3 etc342*343* NBC=NOT/NON BACKWARD COMPATIBLE WITH DVB-S (DVB-S2 only)344*345* NBC-QPSK FEC_1_2 0x00, 0x04 DVB-S2346* NBC-QPSK FEC_3_5 0x00, 0x05 DVB-S2347* NBC-QPSK FEC_2_3 0x00, 0x06 DVB-S2348* NBC-QPSK FEC_3_4 0x00, 0x07 DVB-S2349* NBC-QPSK FEC_4_5 0x00, 0x08 DVB-S2350* NBC-QPSK FEC_5_6 0x00, 0x09 DVB-S2351* NBC-QPSK FEC_8_9 0x00, 0x0a DVB-S2352* NBC-QPSK FEC_9_10 0x00, 0x0b DVB-S2353*354* NBC-8PSK FEC_3_5 0x00, 0x0c DVB-S2355* NBC-8PSK FEC_2_3 0x00, 0x0d DVB-S2356* NBC-8PSK FEC_3_4 0x00, 0x0e DVB-S2357* NBC-8PSK FEC_5_6 0x00, 0x0f DVB-S2358* NBC-8PSK FEC_8_9 0x00, 0x10 DVB-S2359* NBC-8PSK FEC_9_10 0x00, 0x11 DVB-S2360*361* For DVB-S2 low bytes selects both modulator362* and FEC. High byte is meaningless here. To363* set pilot, bit 6 (0x40) is set. When inspecting364* FECSTATUS bit 7 (0x80) represents the pilot365* selection whilst not tuned. When tuned, actual FEC366* in use is found in FECSTATUS as per above. Pilot367* value is reset.368*/369370/* A table of modulation, fec and configuration bytes for the demod.371* Not all S2 mmodulation schemes are support and not all rates with372* a scheme are support. Especially, no auto detect when in S2 mode.373*/374static struct cx24116_modfec {375fe_delivery_system_t delivery_system;376fe_modulation_t modulation;377fe_code_rate_t fec;378u8 mask; /* In DVBS mode this is used to autodetect */379u8 val; /* Passed to the firmware to indicate mode selection */380} CX24116_MODFEC_MODES[] = {381/* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */382383/*mod fec mask val */384{ SYS_DVBS, QPSK, FEC_NONE, 0xfe, 0x30 },385{ SYS_DVBS, QPSK, FEC_1_2, 0x02, 0x2e }, /* 00000010 00101110 */386{ SYS_DVBS, QPSK, FEC_2_3, 0x04, 0x2f }, /* 00000100 00101111 */387{ SYS_DVBS, QPSK, FEC_3_4, 0x08, 0x30 }, /* 00001000 00110000 */388{ SYS_DVBS, QPSK, FEC_4_5, 0xfe, 0x30 }, /* 000?0000 ? */389{ SYS_DVBS, QPSK, FEC_5_6, 0x20, 0x31 }, /* 00100000 00110001 */390{ SYS_DVBS, QPSK, FEC_6_7, 0xfe, 0x30 }, /* 0?000000 ? */391{ SYS_DVBS, QPSK, FEC_7_8, 0x80, 0x32 }, /* 10000000 00110010 */392{ SYS_DVBS, QPSK, FEC_8_9, 0xfe, 0x30 }, /* 0000000? ? */393{ SYS_DVBS, QPSK, FEC_AUTO, 0xfe, 0x30 },394/* NBC-QPSK */395{ SYS_DVBS2, QPSK, FEC_1_2, 0x00, 0x04 },396{ SYS_DVBS2, QPSK, FEC_3_5, 0x00, 0x05 },397{ SYS_DVBS2, QPSK, FEC_2_3, 0x00, 0x06 },398{ SYS_DVBS2, QPSK, FEC_3_4, 0x00, 0x07 },399{ SYS_DVBS2, QPSK, FEC_4_5, 0x00, 0x08 },400{ SYS_DVBS2, QPSK, FEC_5_6, 0x00, 0x09 },401{ SYS_DVBS2, QPSK, FEC_8_9, 0x00, 0x0a },402{ SYS_DVBS2, QPSK, FEC_9_10, 0x00, 0x0b },403/* 8PSK */404{ SYS_DVBS2, PSK_8, FEC_3_5, 0x00, 0x0c },405{ SYS_DVBS2, PSK_8, FEC_2_3, 0x00, 0x0d },406{ SYS_DVBS2, PSK_8, FEC_3_4, 0x00, 0x0e },407{ SYS_DVBS2, PSK_8, FEC_5_6, 0x00, 0x0f },408{ SYS_DVBS2, PSK_8, FEC_8_9, 0x00, 0x10 },409{ SYS_DVBS2, PSK_8, FEC_9_10, 0x00, 0x11 },410/*411* `val' can be found in the FECSTATUS register when tuning.412* FECSTATUS will give the actual FEC in use if tuning was successful.413*/414};415416static int cx24116_lookup_fecmod(struct cx24116_state *state,417fe_delivery_system_t d, fe_modulation_t m, fe_code_rate_t f)418{419int i, ret = -EOPNOTSUPP;420421dprintk("%s(0x%02x,0x%02x)\n", __func__, m, f);422423for (i = 0; i < ARRAY_SIZE(CX24116_MODFEC_MODES); i++) {424if ((d == CX24116_MODFEC_MODES[i].delivery_system) &&425(m == CX24116_MODFEC_MODES[i].modulation) &&426(f == CX24116_MODFEC_MODES[i].fec)) {427ret = i;428break;429}430}431432return ret;433}434435static int cx24116_set_fec(struct cx24116_state *state,436fe_delivery_system_t delsys, fe_modulation_t mod, fe_code_rate_t fec)437{438int ret = 0;439440dprintk("%s(0x%02x,0x%02x)\n", __func__, mod, fec);441442ret = cx24116_lookup_fecmod(state, delsys, mod, fec);443444if (ret < 0)445return ret;446447state->dnxt.fec = fec;448state->dnxt.fec_val = CX24116_MODFEC_MODES[ret].val;449state->dnxt.fec_mask = CX24116_MODFEC_MODES[ret].mask;450dprintk("%s() mask/val = 0x%02x/0x%02x\n", __func__,451state->dnxt.fec_mask, state->dnxt.fec_val);452453return 0;454}455456static int cx24116_set_symbolrate(struct cx24116_state *state, u32 rate)457{458dprintk("%s(%d)\n", __func__, rate);459460/* check if symbol rate is within limits */461if ((rate > state->frontend.ops.info.symbol_rate_max) ||462(rate < state->frontend.ops.info.symbol_rate_min)) {463dprintk("%s() unsupported symbol_rate = %d\n", __func__, rate);464return -EOPNOTSUPP;465}466467state->dnxt.symbol_rate = rate;468dprintk("%s() symbol_rate = %d\n", __func__, rate);469470return 0;471}472473static int cx24116_load_firmware(struct dvb_frontend *fe,474const struct firmware *fw);475476static int cx24116_firmware_ondemand(struct dvb_frontend *fe)477{478struct cx24116_state *state = fe->demodulator_priv;479const struct firmware *fw;480int ret = 0;481482dprintk("%s()\n", __func__);483484if (cx24116_readreg(state, 0x20) > 0) {485486if (state->skip_fw_load)487return 0;488489/* Load firmware */490/* request the firmware, this will block until loaded */491printk(KERN_INFO "%s: Waiting for firmware upload (%s)...\n",492__func__, CX24116_DEFAULT_FIRMWARE);493ret = request_firmware(&fw, CX24116_DEFAULT_FIRMWARE,494state->i2c->dev.parent);495printk(KERN_INFO "%s: Waiting for firmware upload(2)...\n",496__func__);497if (ret) {498printk(KERN_ERR "%s: No firmware uploaded "499"(timeout or file not found?)\n", __func__);500return ret;501}502503/* Make sure we don't recurse back through here504* during loading */505state->skip_fw_load = 1;506507ret = cx24116_load_firmware(fe, fw);508if (ret)509printk(KERN_ERR "%s: Writing firmware to device failed\n",510__func__);511512release_firmware(fw);513514printk(KERN_INFO "%s: Firmware upload %s\n", __func__,515ret == 0 ? "complete" : "failed");516517/* Ensure firmware is always loaded if required */518state->skip_fw_load = 0;519}520521return ret;522}523524/* Take a basic firmware command structure, format it525* and forward it for processing526*/527static int cx24116_cmd_execute(struct dvb_frontend *fe, struct cx24116_cmd *cmd)528{529struct cx24116_state *state = fe->demodulator_priv;530int i, ret;531532dprintk("%s()\n", __func__);533534/* Load the firmware if required */535ret = cx24116_firmware_ondemand(fe);536if (ret != 0) {537printk(KERN_ERR "%s(): Unable initialise the firmware\n",538__func__);539return ret;540}541542/* Write the command */543for (i = 0; i < cmd->len ; i++) {544dprintk("%s: 0x%02x == 0x%02x\n", __func__, i, cmd->args[i]);545cx24116_writereg(state, i, cmd->args[i]);546}547548/* Start execution and wait for cmd to terminate */549cx24116_writereg(state, CX24116_REG_EXECUTE, 0x01);550while (cx24116_readreg(state, CX24116_REG_EXECUTE)) {551msleep(10);552if (i++ > 64) {553/* Avoid looping forever if the firmware does554not respond */555printk(KERN_WARNING "%s() Firmware not responding\n",556__func__);557return -EREMOTEIO;558}559}560return 0;561}562563static int cx24116_load_firmware(struct dvb_frontend *fe,564const struct firmware *fw)565{566struct cx24116_state *state = fe->demodulator_priv;567struct cx24116_cmd cmd;568int i, ret, len, max, remaining;569unsigned char vers[4];570571dprintk("%s\n", __func__);572dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n",573fw->size,574fw->data[0],575fw->data[1],576fw->data[fw->size-2],577fw->data[fw->size-1]);578579/* Toggle 88x SRST pin to reset demod */580if (state->config->reset_device)581state->config->reset_device(fe);582583/* Begin the firmware load process */584/* Prepare the demod, load the firmware, cleanup after load */585586/* Init PLL */587cx24116_writereg(state, 0xE5, 0x00);588cx24116_writereg(state, 0xF1, 0x08);589cx24116_writereg(state, 0xF2, 0x13);590591/* Start PLL */592cx24116_writereg(state, 0xe0, 0x03);593cx24116_writereg(state, 0xe0, 0x00);594595/* Unknown */596cx24116_writereg(state, CX24116_REG_CLKDIV, 0x46);597cx24116_writereg(state, CX24116_REG_RATEDIV, 0x00);598599/* Unknown */600cx24116_writereg(state, 0xF0, 0x03);601cx24116_writereg(state, 0xF4, 0x81);602cx24116_writereg(state, 0xF5, 0x00);603cx24116_writereg(state, 0xF6, 0x00);604605/* Split firmware to the max I2C write len and write.606* Writes whole firmware as one write when i2c_wr_max is set to 0. */607if (state->config->i2c_wr_max)608max = state->config->i2c_wr_max;609else610max = INT_MAX; /* enough for 32k firmware */611612for (remaining = fw->size; remaining > 0; remaining -= max - 1) {613len = remaining;614if (len > max - 1)615len = max - 1;616617cx24116_writeregN(state, 0xF7, &fw->data[fw->size - remaining],618len);619}620621cx24116_writereg(state, 0xF4, 0x10);622cx24116_writereg(state, 0xF0, 0x00);623cx24116_writereg(state, 0xF8, 0x06);624625/* Firmware CMD 10: VCO config */626cmd.args[0x00] = CMD_SET_VCO;627cmd.args[0x01] = 0x05;628cmd.args[0x02] = 0xdc;629cmd.args[0x03] = 0xda;630cmd.args[0x04] = 0xae;631cmd.args[0x05] = 0xaa;632cmd.args[0x06] = 0x04;633cmd.args[0x07] = 0x9d;634cmd.args[0x08] = 0xfc;635cmd.args[0x09] = 0x06;636cmd.len = 0x0a;637ret = cx24116_cmd_execute(fe, &cmd);638if (ret != 0)639return ret;640641cx24116_writereg(state, CX24116_REG_SSTATUS, 0x00);642643/* Firmware CMD 14: Tuner config */644cmd.args[0x00] = CMD_TUNERINIT;645cmd.args[0x01] = 0x00;646cmd.args[0x02] = 0x00;647cmd.len = 0x03;648ret = cx24116_cmd_execute(fe, &cmd);649if (ret != 0)650return ret;651652cx24116_writereg(state, 0xe5, 0x00);653654/* Firmware CMD 13: MPEG config */655cmd.args[0x00] = CMD_MPEGCONFIG;656cmd.args[0x01] = 0x01;657cmd.args[0x02] = 0x75;658cmd.args[0x03] = 0x00;659if (state->config->mpg_clk_pos_pol)660cmd.args[0x04] = state->config->mpg_clk_pos_pol;661else662cmd.args[0x04] = 0x02;663cmd.args[0x05] = 0x00;664cmd.len = 0x06;665ret = cx24116_cmd_execute(fe, &cmd);666if (ret != 0)667return ret;668669/* Firmware CMD 35: Get firmware version */670cmd.args[0x00] = CMD_UPDFWVERS;671cmd.len = 0x02;672for (i = 0; i < 4; i++) {673cmd.args[0x01] = i;674ret = cx24116_cmd_execute(fe, &cmd);675if (ret != 0)676return ret;677vers[i] = cx24116_readreg(state, CX24116_REG_MAILBOX);678}679printk(KERN_INFO "%s: FW version %i.%i.%i.%i\n", __func__,680vers[0], vers[1], vers[2], vers[3]);681682return 0;683}684685static int cx24116_read_status(struct dvb_frontend *fe, fe_status_t *status)686{687struct cx24116_state *state = fe->demodulator_priv;688689int lock = cx24116_readreg(state, CX24116_REG_SSTATUS) &690CX24116_STATUS_MASK;691692dprintk("%s: status = 0x%02x\n", __func__, lock);693694*status = 0;695696if (lock & CX24116_HAS_SIGNAL)697*status |= FE_HAS_SIGNAL;698if (lock & CX24116_HAS_CARRIER)699*status |= FE_HAS_CARRIER;700if (lock & CX24116_HAS_VITERBI)701*status |= FE_HAS_VITERBI;702if (lock & CX24116_HAS_SYNCLOCK)703*status |= FE_HAS_SYNC | FE_HAS_LOCK;704705return 0;706}707708static int cx24116_read_ber(struct dvb_frontend *fe, u32 *ber)709{710struct cx24116_state *state = fe->demodulator_priv;711712dprintk("%s()\n", __func__);713714*ber = (cx24116_readreg(state, CX24116_REG_BER24) << 24) |715(cx24116_readreg(state, CX24116_REG_BER16) << 16) |716(cx24116_readreg(state, CX24116_REG_BER8) << 8) |717cx24116_readreg(state, CX24116_REG_BER0);718719return 0;720}721722/* TODO Determine function and scale appropriately */723static int cx24116_read_signal_strength(struct dvb_frontend *fe,724u16 *signal_strength)725{726struct cx24116_state *state = fe->demodulator_priv;727struct cx24116_cmd cmd;728int ret;729u16 sig_reading;730731dprintk("%s()\n", __func__);732733/* Firmware CMD 19: Get AGC */734cmd.args[0x00] = CMD_GETAGC;735cmd.len = 0x01;736ret = cx24116_cmd_execute(fe, &cmd);737if (ret != 0)738return ret;739740sig_reading =741(cx24116_readreg(state,742CX24116_REG_SSTATUS) & CX24116_SIGNAL_MASK) |743(cx24116_readreg(state, CX24116_REG_SIGNAL) << 6);744*signal_strength = 0 - sig_reading;745746dprintk("%s: raw / cooked = 0x%04x / 0x%04x\n",747__func__, sig_reading, *signal_strength);748749return 0;750}751752/* SNR (0..100)% = (sig & 0xf0) * 10 + (sig & 0x0f) * 10 / 16 */753static int cx24116_read_snr_pct(struct dvb_frontend *fe, u16 *snr)754{755struct cx24116_state *state = fe->demodulator_priv;756u8 snr_reading;757static const u32 snr_tab[] = { /* 10 x Table (rounded up) */7580x00000, 0x0199A, 0x03333, 0x04ccD, 0x06667,7590x08000, 0x0999A, 0x0b333, 0x0cccD, 0x0e667,7600x10000, 0x1199A, 0x13333, 0x14ccD, 0x16667,7610x18000 };762763dprintk("%s()\n", __func__);764765snr_reading = cx24116_readreg(state, CX24116_REG_QUALITY0);766767if (snr_reading >= 0xa0 /* 100% */)768*snr = 0xffff;769else770*snr = snr_tab[(snr_reading & 0xf0) >> 4] +771(snr_tab[(snr_reading & 0x0f)] >> 4);772773dprintk("%s: raw / cooked = 0x%02x / 0x%04x\n", __func__,774snr_reading, *snr);775776return 0;777}778779/* The reelbox patches show the value in the registers represents780* ESNO, from 0->30db (values 0->300). We provide this value by781* default.782*/783static int cx24116_read_snr_esno(struct dvb_frontend *fe, u16 *snr)784{785struct cx24116_state *state = fe->demodulator_priv;786787dprintk("%s()\n", __func__);788789*snr = cx24116_readreg(state, CX24116_REG_QUALITY8) << 8 |790cx24116_readreg(state, CX24116_REG_QUALITY0);791792dprintk("%s: raw 0x%04x\n", __func__, *snr);793794return 0;795}796797static int cx24116_read_snr(struct dvb_frontend *fe, u16 *snr)798{799if (esno_snr == 1)800return cx24116_read_snr_esno(fe, snr);801else802return cx24116_read_snr_pct(fe, snr);803}804805static int cx24116_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)806{807struct cx24116_state *state = fe->demodulator_priv;808809dprintk("%s()\n", __func__);810811*ucblocks = (cx24116_readreg(state, CX24116_REG_UCB8) << 8) |812cx24116_readreg(state, CX24116_REG_UCB0);813814return 0;815}816817/* Overwrite the current tuning params, we are about to tune */818static void cx24116_clone_params(struct dvb_frontend *fe)819{820struct cx24116_state *state = fe->demodulator_priv;821memcpy(&state->dcur, &state->dnxt, sizeof(state->dcur));822}823824/* Wait for LNB */825static int cx24116_wait_for_lnb(struct dvb_frontend *fe)826{827struct cx24116_state *state = fe->demodulator_priv;828int i;829830dprintk("%s() qstatus = 0x%02x\n", __func__,831cx24116_readreg(state, CX24116_REG_QSTATUS));832833/* Wait for up to 300 ms */834for (i = 0; i < 30 ; i++) {835if (cx24116_readreg(state, CX24116_REG_QSTATUS) & 0x20)836return 0;837msleep(10);838}839840dprintk("%s(): LNB not ready\n", __func__);841842return -ETIMEDOUT; /* -EBUSY ? */843}844845static int cx24116_set_voltage(struct dvb_frontend *fe,846fe_sec_voltage_t voltage)847{848struct cx24116_cmd cmd;849int ret;850851dprintk("%s: %s\n", __func__,852voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :853voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");854855/* Wait for LNB ready */856ret = cx24116_wait_for_lnb(fe);857if (ret != 0)858return ret;859860/* Wait for voltage/min repeat delay */861msleep(100);862863cmd.args[0x00] = CMD_LNBDCLEVEL;864cmd.args[0x01] = (voltage == SEC_VOLTAGE_18 ? 0x01 : 0x00);865cmd.len = 0x02;866867/* Min delay time before DiSEqC send */868msleep(15);869870return cx24116_cmd_execute(fe, &cmd);871}872873static int cx24116_set_tone(struct dvb_frontend *fe,874fe_sec_tone_mode_t tone)875{876struct cx24116_cmd cmd;877int ret;878879dprintk("%s(%d)\n", __func__, tone);880if ((tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF)) {881printk(KERN_ERR "%s: Invalid, tone=%d\n", __func__, tone);882return -EINVAL;883}884885/* Wait for LNB ready */886ret = cx24116_wait_for_lnb(fe);887if (ret != 0)888return ret;889890/* Min delay time after DiSEqC send */891msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */892893/* Now we set the tone */894cmd.args[0x00] = CMD_SET_TONE;895cmd.args[0x01] = 0x00;896cmd.args[0x02] = 0x00;897898switch (tone) {899case SEC_TONE_ON:900dprintk("%s: setting tone on\n", __func__);901cmd.args[0x03] = 0x01;902break;903case SEC_TONE_OFF:904dprintk("%s: setting tone off\n", __func__);905cmd.args[0x03] = 0x00;906break;907}908cmd.len = 0x04;909910/* Min delay time before DiSEqC send */911msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */912913return cx24116_cmd_execute(fe, &cmd);914}915916/* Initialise DiSEqC */917static int cx24116_diseqc_init(struct dvb_frontend *fe)918{919struct cx24116_state *state = fe->demodulator_priv;920struct cx24116_cmd cmd;921int ret;922923/* Firmware CMD 20: LNB/DiSEqC config */924cmd.args[0x00] = CMD_LNBCONFIG;925cmd.args[0x01] = 0x00;926cmd.args[0x02] = 0x10;927cmd.args[0x03] = 0x00;928cmd.args[0x04] = 0x8f;929cmd.args[0x05] = 0x28;930cmd.args[0x06] = (toneburst == CX24116_DISEQC_TONEOFF) ? 0x00 : 0x01;931cmd.args[0x07] = 0x01;932cmd.len = 0x08;933ret = cx24116_cmd_execute(fe, &cmd);934if (ret != 0)935return ret;936937/* Prepare a DiSEqC command */938state->dsec_cmd.args[0x00] = CMD_LNBSEND;939940/* DiSEqC burst */941state->dsec_cmd.args[CX24116_DISEQC_BURST] = CX24116_DISEQC_MINI_A;942943/* Unknown */944state->dsec_cmd.args[CX24116_DISEQC_ARG2_2] = 0x02;945state->dsec_cmd.args[CX24116_DISEQC_ARG3_0] = 0x00;946/* Continuation flag? */947state->dsec_cmd.args[CX24116_DISEQC_ARG4_0] = 0x00;948949/* DiSEqC message length */950state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] = 0x00;951952/* Command length */953state->dsec_cmd.len = CX24116_DISEQC_MSGOFS;954955return 0;956}957958/* Send DiSEqC message with derived burst (hack) || previous burst */959static int cx24116_send_diseqc_msg(struct dvb_frontend *fe,960struct dvb_diseqc_master_cmd *d)961{962struct cx24116_state *state = fe->demodulator_priv;963int i, ret;964965/* Dump DiSEqC message */966if (debug) {967printk(KERN_INFO "cx24116: %s(", __func__);968for (i = 0 ; i < d->msg_len ;) {969printk(KERN_INFO "0x%02x", d->msg[i]);970if (++i < d->msg_len)971printk(KERN_INFO ", ");972}973printk(") toneburst=%d\n", toneburst);974}975976/* Validate length */977if (d->msg_len > (CX24116_ARGLEN - CX24116_DISEQC_MSGOFS))978return -EINVAL;979980/* DiSEqC message */981for (i = 0; i < d->msg_len; i++)982state->dsec_cmd.args[CX24116_DISEQC_MSGOFS + i] = d->msg[i];983984/* DiSEqC message length */985state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] = d->msg_len;986987/* Command length */988state->dsec_cmd.len = CX24116_DISEQC_MSGOFS +989state->dsec_cmd.args[CX24116_DISEQC_MSGLEN];990991/* DiSEqC toneburst */992if (toneburst == CX24116_DISEQC_MESGCACHE)993/* Message is cached */994return 0;995996else if (toneburst == CX24116_DISEQC_TONEOFF)997/* Message is sent without burst */998state->dsec_cmd.args[CX24116_DISEQC_BURST] = 0;9991000else if (toneburst == CX24116_DISEQC_TONECACHE) {1001/*1002* Message is sent with derived else cached burst1003*1004* WRITE PORT GROUP COMMAND 381005*1006* 0/A/A: E0 10 38 F0..F31007* 1/B/B: E0 10 38 F4..F71008* 2/C/A: E0 10 38 F8..FB1009* 3/D/B: E0 10 38 FC..FF1010*1011* databyte[3]= 8421:84211012* ABCD:WXYZ1013* CLR :SET1014*1015* WX= PORT SELECT 0..3 (X=TONEBURST)1016* Y = VOLTAGE (0=13V, 1=18V)1017* Z = BAND (0=LOW, 1=HIGH(22K))1018*/1019if (d->msg_len >= 4 && d->msg[2] == 0x38)1020state->dsec_cmd.args[CX24116_DISEQC_BURST] =1021((d->msg[3] & 4) >> 2);1022if (debug)1023dprintk("%s burst=%d\n", __func__,1024state->dsec_cmd.args[CX24116_DISEQC_BURST]);1025}10261027/* Wait for LNB ready */1028ret = cx24116_wait_for_lnb(fe);1029if (ret != 0)1030return ret;10311032/* Wait for voltage/min repeat delay */1033msleep(100);10341035/* Command */1036ret = cx24116_cmd_execute(fe, &state->dsec_cmd);1037if (ret != 0)1038return ret;1039/*1040* Wait for send1041*1042* Eutelsat spec:1043* >15ms delay + (XXX determine if FW does this, see set_tone)1044* 13.5ms per byte +1045* >15ms delay +1046* 12.5ms burst +1047* >15ms delay (XXX determine if FW does this, see set_tone)1048*/1049msleep((state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] << 4) +1050((toneburst == CX24116_DISEQC_TONEOFF) ? 30 : 60));10511052return 0;1053}10541055/* Send DiSEqC burst */1056static int cx24116_diseqc_send_burst(struct dvb_frontend *fe,1057fe_sec_mini_cmd_t burst)1058{1059struct cx24116_state *state = fe->demodulator_priv;1060int ret;10611062dprintk("%s(%d) toneburst=%d\n", __func__, burst, toneburst);10631064/* DiSEqC burst */1065if (burst == SEC_MINI_A)1066state->dsec_cmd.args[CX24116_DISEQC_BURST] =1067CX24116_DISEQC_MINI_A;1068else if (burst == SEC_MINI_B)1069state->dsec_cmd.args[CX24116_DISEQC_BURST] =1070CX24116_DISEQC_MINI_B;1071else1072return -EINVAL;10731074/* DiSEqC toneburst */1075if (toneburst != CX24116_DISEQC_MESGCACHE)1076/* Burst is cached */1077return 0;10781079/* Burst is to be sent with cached message */10801081/* Wait for LNB ready */1082ret = cx24116_wait_for_lnb(fe);1083if (ret != 0)1084return ret;10851086/* Wait for voltage/min repeat delay */1087msleep(100);10881089/* Command */1090ret = cx24116_cmd_execute(fe, &state->dsec_cmd);1091if (ret != 0)1092return ret;10931094/*1095* Wait for send1096*1097* Eutelsat spec:1098* >15ms delay + (XXX determine if FW does this, see set_tone)1099* 13.5ms per byte +1100* >15ms delay +1101* 12.5ms burst +1102* >15ms delay (XXX determine if FW does this, see set_tone)1103*/1104msleep((state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] << 4) + 60);11051106return 0;1107}11081109static void cx24116_release(struct dvb_frontend *fe)1110{1111struct cx24116_state *state = fe->demodulator_priv;1112dprintk("%s\n", __func__);1113kfree(state);1114}11151116static struct dvb_frontend_ops cx24116_ops;11171118struct dvb_frontend *cx24116_attach(const struct cx24116_config *config,1119struct i2c_adapter *i2c)1120{1121struct cx24116_state *state = NULL;1122int ret;11231124dprintk("%s\n", __func__);11251126/* allocate memory for the internal state */1127state = kzalloc(sizeof(struct cx24116_state), GFP_KERNEL);1128if (state == NULL)1129goto error1;11301131state->config = config;1132state->i2c = i2c;11331134/* check if the demod is present */1135ret = (cx24116_readreg(state, 0xFF) << 8) |1136cx24116_readreg(state, 0xFE);1137if (ret != 0x0501) {1138printk(KERN_INFO "Invalid probe, probably not a CX24116 device\n");1139goto error2;1140}11411142/* create dvb_frontend */1143memcpy(&state->frontend.ops, &cx24116_ops,1144sizeof(struct dvb_frontend_ops));1145state->frontend.demodulator_priv = state;1146return &state->frontend;11471148error2: kfree(state);1149error1: return NULL;1150}1151EXPORT_SYMBOL(cx24116_attach);11521153/*1154* Initialise or wake up device1155*1156* Power config will reset and load initial firmware if required1157*/1158static int cx24116_initfe(struct dvb_frontend *fe)1159{1160struct cx24116_state *state = fe->demodulator_priv;1161struct cx24116_cmd cmd;1162int ret;11631164dprintk("%s()\n", __func__);11651166/* Power on */1167cx24116_writereg(state, 0xe0, 0);1168cx24116_writereg(state, 0xe1, 0);1169cx24116_writereg(state, 0xea, 0);11701171/* Firmware CMD 36: Power config */1172cmd.args[0x00] = CMD_TUNERSLEEP;1173cmd.args[0x01] = 0;1174cmd.len = 0x02;1175ret = cx24116_cmd_execute(fe, &cmd);1176if (ret != 0)1177return ret;11781179ret = cx24116_diseqc_init(fe);1180if (ret != 0)1181return ret;11821183/* HVR-4000 needs this */1184return cx24116_set_voltage(fe, SEC_VOLTAGE_13);1185}11861187/*1188* Put device to sleep1189*/1190static int cx24116_sleep(struct dvb_frontend *fe)1191{1192struct cx24116_state *state = fe->demodulator_priv;1193struct cx24116_cmd cmd;1194int ret;11951196dprintk("%s()\n", __func__);11971198/* Firmware CMD 36: Power config */1199cmd.args[0x00] = CMD_TUNERSLEEP;1200cmd.args[0x01] = 1;1201cmd.len = 0x02;1202ret = cx24116_cmd_execute(fe, &cmd);1203if (ret != 0)1204return ret;12051206/* Power off (Shutdown clocks) */1207cx24116_writereg(state, 0xea, 0xff);1208cx24116_writereg(state, 0xe1, 1);1209cx24116_writereg(state, 0xe0, 1);12101211return 0;1212}12131214static int cx24116_set_property(struct dvb_frontend *fe,1215struct dtv_property *tvp)1216{1217dprintk("%s(..)\n", __func__);1218return 0;1219}12201221static int cx24116_get_property(struct dvb_frontend *fe,1222struct dtv_property *tvp)1223{1224dprintk("%s(..)\n", __func__);1225return 0;1226}12271228/* dvb-core told us to tune, the tv property cache will be complete,1229* it's safe for is to pull values and use them for tuning purposes.1230*/1231static int cx24116_set_frontend(struct dvb_frontend *fe,1232struct dvb_frontend_parameters *p)1233{1234struct cx24116_state *state = fe->demodulator_priv;1235struct dtv_frontend_properties *c = &fe->dtv_property_cache;1236struct cx24116_cmd cmd;1237fe_status_t tunerstat;1238int i, status, ret, retune = 1;12391240dprintk("%s()\n", __func__);12411242switch (c->delivery_system) {1243case SYS_DVBS:1244dprintk("%s: DVB-S delivery system selected\n", __func__);12451246/* Only QPSK is supported for DVB-S */1247if (c->modulation != QPSK) {1248dprintk("%s: unsupported modulation selected (%d)\n",1249__func__, c->modulation);1250return -EOPNOTSUPP;1251}12521253/* Pilot doesn't exist in DVB-S, turn bit off */1254state->dnxt.pilot_val = CX24116_PILOT_OFF;12551256/* DVB-S only supports 0.35 */1257if (c->rolloff != ROLLOFF_35) {1258dprintk("%s: unsupported rolloff selected (%d)\n",1259__func__, c->rolloff);1260return -EOPNOTSUPP;1261}1262state->dnxt.rolloff_val = CX24116_ROLLOFF_035;1263break;12641265case SYS_DVBS2:1266dprintk("%s: DVB-S2 delivery system selected\n", __func__);12671268/*1269* NBC 8PSK/QPSK with DVB-S is supported for DVB-S2,1270* but not hardware auto detection1271*/1272if (c->modulation != PSK_8 && c->modulation != QPSK) {1273dprintk("%s: unsupported modulation selected (%d)\n",1274__func__, c->modulation);1275return -EOPNOTSUPP;1276}12771278switch (c->pilot) {1279case PILOT_AUTO: /* Not supported but emulated */1280state->dnxt.pilot_val = (c->modulation == QPSK)1281? CX24116_PILOT_OFF : CX24116_PILOT_ON;1282retune++;1283break;1284case PILOT_OFF:1285state->dnxt.pilot_val = CX24116_PILOT_OFF;1286break;1287case PILOT_ON:1288state->dnxt.pilot_val = CX24116_PILOT_ON;1289break;1290default:1291dprintk("%s: unsupported pilot mode selected (%d)\n",1292__func__, c->pilot);1293return -EOPNOTSUPP;1294}12951296switch (c->rolloff) {1297case ROLLOFF_20:1298state->dnxt.rolloff_val = CX24116_ROLLOFF_020;1299break;1300case ROLLOFF_25:1301state->dnxt.rolloff_val = CX24116_ROLLOFF_025;1302break;1303case ROLLOFF_35:1304state->dnxt.rolloff_val = CX24116_ROLLOFF_035;1305break;1306case ROLLOFF_AUTO: /* Rolloff must be explicit */1307default:1308dprintk("%s: unsupported rolloff selected (%d)\n",1309__func__, c->rolloff);1310return -EOPNOTSUPP;1311}1312break;13131314default:1315dprintk("%s: unsupported delivery system selected (%d)\n",1316__func__, c->delivery_system);1317return -EOPNOTSUPP;1318}1319state->dnxt.delsys = c->delivery_system;1320state->dnxt.modulation = c->modulation;1321state->dnxt.frequency = c->frequency;1322state->dnxt.pilot = c->pilot;1323state->dnxt.rolloff = c->rolloff;13241325ret = cx24116_set_inversion(state, c->inversion);1326if (ret != 0)1327return ret;13281329/* FEC_NONE/AUTO for DVB-S2 is not supported and detected here */1330ret = cx24116_set_fec(state, c->delivery_system, c->modulation, c->fec_inner);1331if (ret != 0)1332return ret;13331334ret = cx24116_set_symbolrate(state, c->symbol_rate);1335if (ret != 0)1336return ret;13371338/* discard the 'current' tuning parameters and prepare to tune */1339cx24116_clone_params(fe);13401341dprintk("%s: delsys = %d\n", __func__, state->dcur.delsys);1342dprintk("%s: modulation = %d\n", __func__, state->dcur.modulation);1343dprintk("%s: frequency = %d\n", __func__, state->dcur.frequency);1344dprintk("%s: pilot = %d (val = 0x%02x)\n", __func__,1345state->dcur.pilot, state->dcur.pilot_val);1346dprintk("%s: retune = %d\n", __func__, retune);1347dprintk("%s: rolloff = %d (val = 0x%02x)\n", __func__,1348state->dcur.rolloff, state->dcur.rolloff_val);1349dprintk("%s: symbol_rate = %d\n", __func__, state->dcur.symbol_rate);1350dprintk("%s: FEC = %d (mask/val = 0x%02x/0x%02x)\n", __func__,1351state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);1352dprintk("%s: Inversion = %d (val = 0x%02x)\n", __func__,1353state->dcur.inversion, state->dcur.inversion_val);13541355/* This is also done in advise/acquire on HVR4000 but not on LITE */1356if (state->config->set_ts_params)1357state->config->set_ts_params(fe, 0);13581359/* Set/Reset B/W */1360cmd.args[0x00] = CMD_BANDWIDTH;1361cmd.args[0x01] = 0x01;1362cmd.len = 0x02;1363ret = cx24116_cmd_execute(fe, &cmd);1364if (ret != 0)1365return ret;13661367/* Prepare a tune request */1368cmd.args[0x00] = CMD_TUNEREQUEST;13691370/* Frequency */1371cmd.args[0x01] = (state->dcur.frequency & 0xff0000) >> 16;1372cmd.args[0x02] = (state->dcur.frequency & 0x00ff00) >> 8;1373cmd.args[0x03] = (state->dcur.frequency & 0x0000ff);13741375/* Symbol Rate */1376cmd.args[0x04] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;1377cmd.args[0x05] = ((state->dcur.symbol_rate / 1000) & 0x00ff);13781379/* Automatic Inversion */1380cmd.args[0x06] = state->dcur.inversion_val;13811382/* Modulation / FEC / Pilot */1383cmd.args[0x07] = state->dcur.fec_val | state->dcur.pilot_val;13841385cmd.args[0x08] = CX24116_SEARCH_RANGE_KHZ >> 8;1386cmd.args[0x09] = CX24116_SEARCH_RANGE_KHZ & 0xff;1387cmd.args[0x0a] = 0x00;1388cmd.args[0x0b] = 0x00;1389cmd.args[0x0c] = state->dcur.rolloff_val;1390cmd.args[0x0d] = state->dcur.fec_mask;13911392if (state->dcur.symbol_rate > 30000000) {1393cmd.args[0x0e] = 0x04;1394cmd.args[0x0f] = 0x00;1395cmd.args[0x10] = 0x01;1396cmd.args[0x11] = 0x77;1397cmd.args[0x12] = 0x36;1398cx24116_writereg(state, CX24116_REG_CLKDIV, 0x44);1399cx24116_writereg(state, CX24116_REG_RATEDIV, 0x01);1400} else {1401cmd.args[0x0e] = 0x06;1402cmd.args[0x0f] = 0x00;1403cmd.args[0x10] = 0x00;1404cmd.args[0x11] = 0xFA;1405cmd.args[0x12] = 0x24;1406cx24116_writereg(state, CX24116_REG_CLKDIV, 0x46);1407cx24116_writereg(state, CX24116_REG_RATEDIV, 0x00);1408}14091410cmd.len = 0x13;14111412/* We need to support pilot and non-pilot tuning in the1413* driver automatically. This is a workaround for because1414* the demod does not support autodetect.1415*/1416do {1417/* Reset status register */1418status = cx24116_readreg(state, CX24116_REG_SSTATUS)1419& CX24116_SIGNAL_MASK;1420cx24116_writereg(state, CX24116_REG_SSTATUS, status);14211422/* Tune */1423ret = cx24116_cmd_execute(fe, &cmd);1424if (ret != 0)1425break;14261427/*1428* Wait for up to 500 ms before retrying1429*1430* If we are able to tune then generally it occurs within 100ms.1431* If it takes longer, try a different toneburst setting.1432*/1433for (i = 0; i < 50 ; i++) {1434cx24116_read_status(fe, &tunerstat);1435status = tunerstat & (FE_HAS_SIGNAL | FE_HAS_SYNC);1436if (status == (FE_HAS_SIGNAL | FE_HAS_SYNC)) {1437dprintk("%s: Tuned\n", __func__);1438goto tuned;1439}1440msleep(10);1441}14421443dprintk("%s: Not tuned\n", __func__);14441445/* Toggle pilot bit when in auto-pilot */1446if (state->dcur.pilot == PILOT_AUTO)1447cmd.args[0x07] ^= CX24116_PILOT_ON;1448} while (--retune);14491450tuned: /* Set/Reset B/W */1451cmd.args[0x00] = CMD_BANDWIDTH;1452cmd.args[0x01] = 0x00;1453cmd.len = 0x02;1454ret = cx24116_cmd_execute(fe, &cmd);1455if (ret != 0)1456return ret;14571458return ret;1459}14601461static int cx24116_tune(struct dvb_frontend *fe, struct dvb_frontend_parameters *params,1462unsigned int mode_flags, unsigned int *delay, fe_status_t *status)1463{1464*delay = HZ / 5;1465if (params) {1466int ret = cx24116_set_frontend(fe, params);1467if (ret)1468return ret;1469}1470return cx24116_read_status(fe, status);1471}14721473static int cx24116_get_algo(struct dvb_frontend *fe)1474{1475return DVBFE_ALGO_HW;1476}14771478static struct dvb_frontend_ops cx24116_ops = {14791480.info = {1481.name = "Conexant CX24116/CX24118",1482.type = FE_QPSK,1483.frequency_min = 950000,1484.frequency_max = 2150000,1485.frequency_stepsize = 1011, /* kHz for QPSK frontends */1486.frequency_tolerance = 5000,1487.symbol_rate_min = 1000000,1488.symbol_rate_max = 45000000,1489.caps = FE_CAN_INVERSION_AUTO |1490FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |1491FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |1492FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |1493FE_CAN_2G_MODULATION |1494FE_CAN_QPSK | FE_CAN_RECOVER1495},14961497.release = cx24116_release,14981499.init = cx24116_initfe,1500.sleep = cx24116_sleep,1501.read_status = cx24116_read_status,1502.read_ber = cx24116_read_ber,1503.read_signal_strength = cx24116_read_signal_strength,1504.read_snr = cx24116_read_snr,1505.read_ucblocks = cx24116_read_ucblocks,1506.set_tone = cx24116_set_tone,1507.set_voltage = cx24116_set_voltage,1508.diseqc_send_master_cmd = cx24116_send_diseqc_msg,1509.diseqc_send_burst = cx24116_diseqc_send_burst,1510.get_frontend_algo = cx24116_get_algo,1511.tune = cx24116_tune,15121513.set_property = cx24116_set_property,1514.get_property = cx24116_get_property,1515.set_frontend = cx24116_set_frontend,1516};15171518MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24116/cx24118 hardware");1519MODULE_AUTHOR("Steven Toth");1520MODULE_LICENSE("GPL");1521152215231524