Path: blob/master/drivers/media/dvb/mantis/mantis_vp1033.c
15112 views
/*1Mantis VP-1033 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 "stv0299.h"31#include "mantis_common.h"32#include "mantis_ioc.h"33#include "mantis_dvb.h"34#include "mantis_vp1033.h"35#include "mantis_reg.h"3637u8 lgtdqcs001f_inittab[] = {380x01, 0x15,390x02, 0x30,400x03, 0x00,410x04, 0x2a,420x05, 0x85,430x06, 0x02,440x07, 0x00,450x08, 0x00,460x0c, 0x01,470x0d, 0x81,480x0e, 0x44,490x0f, 0x94,500x10, 0x3c,510x11, 0x84,520x12, 0xb9,530x13, 0xb5,540x14, 0x4f,550x15, 0xc9,560x16, 0x80,570x17, 0x36,580x18, 0xfb,590x19, 0xcf,600x1a, 0xbc,610x1c, 0x2b,620x1d, 0x27,630x1e, 0x00,640x1f, 0x0b,650x20, 0xa1,660x21, 0x60,670x22, 0x00,680x23, 0x00,690x28, 0x00,700x29, 0x28,710x2a, 0x14,720x2b, 0x0f,730x2c, 0x09,740x2d, 0x05,750x31, 0x1f,760x32, 0x19,770x33, 0xfc,780x34, 0x13,790xff, 0xff,80};8182#define MANTIS_MODEL_NAME "VP-1033"83#define MANTIS_DEV_TYPE "DVB-S/DSS"8485int lgtdqcs001f_tuner_set(struct dvb_frontend *fe,86struct dvb_frontend_parameters *params)87{88struct mantis_pci *mantis = fe->dvb->priv;89struct i2c_adapter *adapter = &mantis->adapter;9091u8 buf[4];92u32 div;939495struct i2c_msg msg = {.addr = 0x61, .flags = 0, .buf = buf, .len = sizeof(buf)};9697div = params->frequency / 250;9899buf[0] = (div >> 8) & 0x7f;100buf[1] = div & 0xff;101buf[2] = 0x83;102buf[3] = 0xc0;103104if (params->frequency < 1531000)105buf[3] |= 0x04;106else107buf[3] &= ~0x04;108if (i2c_transfer(adapter, &msg, 1) < 0) {109dprintk(MANTIS_ERROR, 1, "Write: I2C Transfer failed");110return -EIO;111}112msleep_interruptible(100);113114return 0;115}116117int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe,118u32 srate, u32 ratio)119{120u8 aclk = 0;121u8 bclk = 0;122123if (srate < 1500000) {124aclk = 0xb7;125bclk = 0x47;126} else if (srate < 3000000) {127aclk = 0xb7;128bclk = 0x4b;129} else if (srate < 7000000) {130aclk = 0xb7;131bclk = 0x4f;132} else if (srate < 14000000) {133aclk = 0xb7;134bclk = 0x53;135} else if (srate < 30000000) {136aclk = 0xb6;137bclk = 0x53;138} else if (srate < 45000000) {139aclk = 0xb4;140bclk = 0x51;141}142stv0299_writereg(fe, 0x13, aclk);143stv0299_writereg(fe, 0x14, bclk);144145stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);146stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);147stv0299_writereg(fe, 0x21, ratio & 0xf0);148149return 0;150}151152struct stv0299_config lgtdqcs001f_config = {153.demod_address = 0x68,154.inittab = lgtdqcs001f_inittab,155.mclk = 88000000UL,156.invert = 0,157.skip_reinit = 0,158.volt13_op0_op1 = STV0299_VOLT13_OP0,159.min_delay_ms = 100,160.set_symbol_rate = lgtdqcs001f_set_symbol_rate,161};162163static int vp1033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)164{165struct i2c_adapter *adapter = &mantis->adapter;166167int err = 0;168169err = mantis_frontend_power(mantis, POWER_ON);170if (err == 0) {171mantis_frontend_soft_reset(mantis);172msleep(250);173174dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");175fe = dvb_attach(stv0299_attach, &lgtdqcs001f_config, adapter);176177if (fe) {178fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;179dprintk(MANTIS_ERROR, 1, "found STV0299 DVB-S frontend @ 0x%02x",180lgtdqcs001f_config.demod_address);181182dprintk(MANTIS_ERROR, 1, "Mantis DVB-S STV0299 frontend attach success");183} else {184return -1;185}186} else {187dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",188adapter->name,189err);190191return -EIO;192}193mantis->fe = fe;194dprintk(MANTIS_ERROR, 1, "Done!");195196return 0;197}198199struct mantis_hwconfig vp1033_config = {200.model_name = MANTIS_MODEL_NAME,201.dev_type = MANTIS_DEV_TYPE,202.ts_size = MANTIS_TS_204,203204.baud_rate = MANTIS_BAUD_9600,205.parity = MANTIS_PARITY_NONE,206.bytes = 0,207208.frontend_init = vp1033_frontend_init,209.power = GPIF_A12,210.reset = GPIF_A13,211};212213214