/*
    
File name   : tc90507xbg.h

Description : Driver for tdc90507xbg OFDM Demodulator

COPYRIGHT (C) NXP Semiconductors

Date          Modification                              Name
15 Dec 2008   Created                                   Daniel Patrick - Anastacio Cavalcante
05 Jan 2009	  Adapted I2C communication					Daniel Patrick - Anastacio Cavalcante
07 Jan 2009   Added set_pll_registers function	        Daniel Patrick
09 Jan 2009   Implemented fine tuner					Daniel Patrick - Anastacio Cavalcante
12 Jan 2009   Changed functions name to DTF85500		Daniel Patrick
13 Jan 2009   Added BER measurement after viterbi		Daniel Patrick

*/


#ifndef MB86A20S_H
#define MB86A20S_H

#include <linux/dvb/frontend.h>
#include <linux/firmware.h>

#define MB86A20S_I2C_ADDR0          0x10
#define MB86A20S_I2C_ADDR1          0x18

struct mb86a20s_config
{
    /* the demodulator's i2c address */
    u8 demod_address;

    /* Xtal frequency, 4 or 16MHz */
    u32 xtal_freq;

    /* IF frequency */
    u32 if_freq;

    /* PLL factors */
    u32 PLL_M_Factor;
    u32 PLL_N_Factor;
    u32 PLL_P_Factor;

    /* AGC Tuner use */
    bool AGC_TunUsed; 

    /* AGC Polarity */
    bool AGC_PolaTun;
    bool AGC_PolaIf;

    u8 AGC_TunMin;
    u8 AGC_TunMax;
    u8 AGC_IfMin;
    u8 AGC_IfMax;
    
    /* Output configuration */
    u32 OUT_ParaSer;
    u32 OUT_ModeAB;
    u32 OUT_ParaDiv;    /* 7: default value */
    u32 OUT_MsbLsb;
    u32 OUT_Poclk;

    /* does the "inversion" need inverted? */
    u8 spectral_inv;

    /* PLL maintenance */
    int (*pll_init)(struct dvb_frontend* fe);
    void (*pll_sleep)(struct dvb_frontend* fe);
    int (*pll_set)(struct dvb_frontend* fe, struct dvb_frontend_parameters* params);

    /* the linked attenuator demodulator's i2c address */
    u8 attenuator_demod_address;

    /* enable tuning algorithm 0 = disable / 1 = enable*/
    u8 tuning_algo;
};

struct mb86a20s_state
{
    struct i2c_adapter*                     i2c;
    struct dvb_frontend_ops                 ops;
    const struct mb86a20s_config            config;
    struct dvb_frontend                     frontend;

    /* private demod data */
    u8 initialised:1;
};


#if defined(CONFIG_DVB_MB86A20S) || (defined(CONFIG_ISDB_MB86A20S_MODULE) && defined(MODULE))
extern struct dvb_frontend* mb86a20s_attach(const struct mb86a20s_config* config,
                                                 struct i2c_adapter* i2c);

#else
static inline struct dvb_frontend* mb86a20s_attach(const struct mb86a20s_config* config,
                                                        struct i2c_adapter* i2c)
{
    printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
    return NULL;
}
#endif // CONFIG_DVB_MB86A20S

#endif // MB86A20S_H
