Path: blob/master/drivers/media/dvb/mantis/mantis_vp2040.c
15112 views
/*1Mantis VP-2040 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_vp2040.h"3536#define MANTIS_MODEL_NAME "VP-2040"37#define MANTIS_DEV_TYPE "DVB-C"3839struct tda1002x_config vp2040_tda1002x_cu1216_config = {40.demod_address = 0x18 >> 1,41.invert = 1,42};4344struct tda10023_config vp2040_tda10023_cu1216_config = {45.demod_address = 0x18 >> 1,46.invert = 1,47};4849static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)50{51struct mantis_pci *mantis = fe->dvb->priv;52struct i2c_adapter *adapter = &mantis->adapter;5354u8 buf[6];55struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};56int i;5758#define CU1216_IF 3612500059#define TUNER_MUL 625006061u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;6263buf[0] = (div >> 8) & 0x7f;64buf[1] = div & 0xff;65buf[2] = 0xce;66buf[3] = (params->frequency < 150000000 ? 0x01 :67params->frequency < 445000000 ? 0x02 : 0x04);68buf[4] = 0xde;69buf[5] = 0x20;7071if (fe->ops.i2c_gate_ctrl)72fe->ops.i2c_gate_ctrl(fe, 1);7374if (i2c_transfer(adapter, &msg, 1) != 1)75return -EIO;7677/* wait for the pll lock */78msg.flags = I2C_M_RD;79msg.len = 1;80for (i = 0; i < 20; i++) {81if (fe->ops.i2c_gate_ctrl)82fe->ops.i2c_gate_ctrl(fe, 1);8384if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))85break;8687msleep(10);88}8990/* switch the charge pump to the lower current */91msg.flags = 0;92msg.len = 2;93msg.buf = &buf[2];94buf[2] &= ~0x40;95if (fe->ops.i2c_gate_ctrl)96fe->ops.i2c_gate_ctrl(fe, 1);9798if (i2c_transfer(adapter, &msg, 1) != 1)99return -EIO;100101return 0;102}103104static u8 read_pwm(struct mantis_pci *mantis)105{106struct i2c_adapter *adapter = &mantis->adapter;107108u8 b = 0xff;109u8 pwm;110struct i2c_msg msg[] = {111{.addr = 0x50, .flags = 0, .buf = &b, .len = 1},112{.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}113};114115if ((i2c_transfer(adapter, msg, 2) != 2)116|| (pwm == 0xff))117pwm = 0x48;118119return pwm;120}121122static int vp2040_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, &vp2040_tda1002x_cu1216_config,135adapter,136read_pwm(mantis));137138if (fe) {139dprintk(MANTIS_ERROR, 1,140"found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",141vp2040_tda1002x_cu1216_config.demod_address);142} else {143fe = dvb_attach(tda10023_attach, &vp2040_tda10023_cu1216_config,144adapter,145read_pwm(mantis));146147if (fe) {148dprintk(MANTIS_ERROR, 1,149"found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",150vp2040_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}167mantis->fe = fe;168dprintk(MANTIS_DEBUG, 1, "Done!");169170return 0;171}172173struct mantis_hwconfig vp2040_config = {174.model_name = MANTIS_MODEL_NAME,175.dev_type = MANTIS_DEV_TYPE,176.ts_size = MANTIS_TS_204,177178.baud_rate = MANTIS_BAUD_9600,179.parity = MANTIS_PARITY_NONE,180.bytes = 0,181182.frontend_init = vp2040_frontend_init,183.power = GPIF_A12,184.reset = GPIF_A13,185};186187188