Path: blob/master/drivers/media/dvb/mantis/mantis_vp2033.c
15112 views
/*1Mantis VP-2033 driver23Copyright (C) Manu Abraham ([email protected])45This program is free software; you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation; either version 2 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program; if not, write to the Free Software17Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.18*/1920#include <linux/signal.h>21#include <linux/sched.h>22#include <linux/interrupt.h>2324#include "dmxdev.h"25#include "dvbdev.h"26#include "dvb_demux.h"27#include "dvb_frontend.h"28#include "dvb_net.h"2930#include "tda1002x.h"31#include "mantis_common.h"32#include "mantis_ioc.h"33#include "mantis_dvb.h"34#include "mantis_vp2033.h"3536#define MANTIS_MODEL_NAME "VP-2033"37#define MANTIS_DEV_TYPE "DVB-C"3839struct tda1002x_config vp2033_tda1002x_cu1216_config = {40.demod_address = 0x18 >> 1,41.invert = 1,42};4344struct tda10023_config vp2033_tda10023_cu1216_config = {45.demod_address = 0x18 >> 1,46.invert = 1,47};4849static u8 read_pwm(struct mantis_pci *mantis)50{51struct i2c_adapter *adapter = &mantis->adapter;5253u8 b = 0xff;54u8 pwm;55struct i2c_msg msg[] = {56{.addr = 0x50, .flags = 0, .buf = &b, .len = 1},57{.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}58};5960if ((i2c_transfer(adapter, msg, 2) != 2)61|| (pwm == 0xff))62pwm = 0x48;6364return pwm;65}6667static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)68{69struct mantis_pci *mantis = fe->dvb->priv;70struct i2c_adapter *adapter = &mantis->adapter;7172u8 buf[6];73struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};74int i;7576#define CU1216_IF 3612500077#define TUNER_MUL 625007879u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;8081buf[0] = (div >> 8) & 0x7f;82buf[1] = div & 0xff;83buf[2] = 0xce;84buf[3] = (params->frequency < 150000000 ? 0x01 :85params->frequency < 445000000 ? 0x02 : 0x04);86buf[4] = 0xde;87buf[5] = 0x20;8889if (fe->ops.i2c_gate_ctrl)90fe->ops.i2c_gate_ctrl(fe, 1);9192if (i2c_transfer(adapter, &msg, 1) != 1)93return -EIO;9495/* wait for the pll lock */96msg.flags = I2C_M_RD;97msg.len = 1;98for (i = 0; i < 20; i++) {99if (fe->ops.i2c_gate_ctrl)100fe->ops.i2c_gate_ctrl(fe, 1);101102if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))103break;104105msleep(10);106}107108/* switch the charge pump to the lower current */109msg.flags = 0;110msg.len = 2;111msg.buf = &buf[2];112buf[2] &= ~0x40;113if (fe->ops.i2c_gate_ctrl)114fe->ops.i2c_gate_ctrl(fe, 1);115116if (i2c_transfer(adapter, &msg, 1) != 1)117return -EIO;118119return 0;120}121122static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)123{124struct i2c_adapter *adapter = &mantis->adapter;125126int err = 0;127128err = mantis_frontend_power(mantis, POWER_ON);129if (err == 0) {130mantis_frontend_soft_reset(mantis);131msleep(250);132133dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");134fe = dvb_attach(tda10021_attach, &vp2033_tda1002x_cu1216_config,135adapter,136read_pwm(mantis));137138if (fe) {139dprintk(MANTIS_ERROR, 1,140"found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",141vp2033_tda1002x_cu1216_config.demod_address);142} else {143fe = dvb_attach(tda10023_attach, &vp2033_tda10023_cu1216_config,144adapter,145read_pwm(mantis));146147if (fe) {148dprintk(MANTIS_ERROR, 1,149"found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",150vp2033_tda1002x_cu1216_config.demod_address);151}152}153154if (fe) {155fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;156dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");157} else {158return -1;159}160} else {161dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",162adapter->name,163err);164165return -EIO;166}167168mantis->fe = fe;169dprintk(MANTIS_DEBUG, 1, "Done!");170171return 0;172}173174struct mantis_hwconfig vp2033_config = {175.model_name = MANTIS_MODEL_NAME,176.dev_type = MANTIS_DEV_TYPE,177.ts_size = MANTIS_TS_204,178179.baud_rate = MANTIS_BAUD_9600,180.parity = MANTIS_PARITY_NONE,181.bytes = 0,182183.frontend_init = vp2033_frontend_init,184.power = GPIF_A12,185.reset = GPIF_A13,186};187188189