it - LITMUS^RT with extended reservations for Forbidden Zones paper @ RTAS'20
aboutsummaryrefslogblamecommitdiffstats
path: root/drivers/media/dvb-frontends/tua6100.c
blob: 1d41abd47f043432c01c6e937347f67699fc39cc (plain) (tree)
1
  






















                                                                               

   
                       












                                





                                                    









                                                                                              
                                                    






                                             
                                                      
 
                                                                    














                                                                                               
                                   
                               
            
                               

                           
                                   
                               
            
                               
 

                                
                                    




                                   
                                   
                                
                                        
                                
            
                                
 




                                                                    








































                                                                         
                                                       





                                           
                                   






































                                                                                               
/*
 * Driver for Infineon tua6100 pll.
 *
 * (c) 2006 Andrew de Quincey
 *
 * Based on code found in budget-av.c, which has the following:
 * Compiled from various sources by Michael Hunold <michael@mihu.de>
 *
 * CI interface support (c) 2004 Olivier Gournet <ogournet@anevia.com> &
 *                               Andrew de Quincey <adq_dvb@lidskialf.net>
 *
 * Copyright (C) 2002 Ralph Metzler <rjkm@metzlerbros.de>
 *
 * Copyright (C) 1999-2002 Ralph  Metzler
 *                       & Marcus Metzler for convergence integrated media GmbH
 * 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.
 */

#include <linux/slab.h>
#include <linux/module.h>
#include <linux/dvb/frontend.h>
#include <asm/types.h>

#include "tua6100.h"

struct tua6100_priv {
	/* i2c details */
	int i2c_address;
	struct i2c_adapter *i2c;
	u32 frequency;
};

static void tua6100_release(struct dvb_frontend *fe)
{
	kfree(fe->tuner_priv);
	fe->tuner_priv = NULL;
}

static int tua6100_sleep(struct dvb_frontend *fe)
{
	struct tua6100_priv *priv = fe->tuner_priv;
	int ret;
	u8 reg0[] = { 0x00, 0x00 };
	struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 };

	if (fe->ops.i2c_gate_ctrl)
		fe->ops.i2c_gate_ctrl(fe, 1);
	if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
		printk("%s: i2c error\n", __func__);
	}
	if (fe->ops.i2c_gate_ctrl)
		fe->ops.i2c_gate_ctrl(fe, 0);

	return (ret == 1) ? 0 : ret;
}

static int tua6100_set_params(struct dvb_frontend *fe)
{
	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
	struct tua6100_priv *priv = fe->tuner_priv;
	u32 div;
	u32 prediv;
	u8 reg0[] = { 0x00, 0x00 };
	u8 reg1[] = { 0x01, 0x00, 0x00, 0x00 };
	u8 reg2[] = { 0x02, 0x00, 0x00 };
	struct i2c_msg msg0 = { .addr = priv->i2c_address, .flags = 0, .buf = reg0, .len = 2 };
	struct i2c_msg msg1 = { .addr = priv->i2c_address, .flags = 0, .buf = reg1, .len = 4 };
	struct i2c_msg msg2 = { .addr = priv->i2c_address, .flags = 0, .buf = reg2, .len = 3 };

#define _R 4
#define _P 32
#define _ri 4000000

	// setup register 0
	if (c->frequency < 2000000)
		reg0[1] = 0x03;
	else
		reg0[1] = 0x07;

	// setup register 1
	if (c->frequency < 1630000)
		reg1[1] = 0x2c;
	else
		reg1[1] = 0x0c;

	if (_P == 64)
		reg1[1] |= 0x40;
	if (c->frequency >= 1525000)
		reg1[1] |= 0x80;

	// register 2
	reg2[1] = (_R >> 8) & 0x03;
	reg2[2] = _R;
	if (c->frequency < 1455000)
		reg2[1] |= 0x1c;
	else if (c->frequency < 1630000)
		reg2[1] |= 0x0c;
	else
		reg2[1] |= 0x1c;

	/*
	 * The N divisor ratio (note: c->frequency is in kHz, but we