blob: 4664d295921863f15a26ae2eccad3f9e49d7869e [file] [log] [blame]
Manu Abraham41e840b2009-12-02 21:57:10 -03001/*
2 Mantis VP-2033 driver
3
4 Copyright (C) 2005, 2006 Manu Abraham (abraham.manu@gmail.com)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include "mantis_common.h"
22#include "mantis_vp2033.h"
23
Manu Abrahamdf0cca12009-12-02 22:07:24 -030024#define MANTIS_MODEL_NAME "VP-2033"
25#define MANTIS_DEV_TYPE "DVB-C"
26
27struct mantis_hwconfig vp2033_mantis_config = {
28 .model_name = MANTIS_MODEL_NAME,
29 .dev_type = MANTIS_DEV_TYPE,
Manu Abraham2687d832009-12-04 04:39:14 -030030 .ts_size = MANTIS_TS_204,
Manu Abrahamdf0cca12009-12-02 22:07:24 -030031};
32
Manu Abraham2687d832009-12-04 04:39:14 -030033struct tda1002x_config philips_cu1216_config = {
34 .demod_address = 0x18 >> 1,
35 .invert = 1,
Manu Abraham41e840b2009-12-02 21:57:10 -030036};
37
Manu Abraham2687d832009-12-04 04:39:14 -030038u8 read_pwm(struct mantis_pci *mantis)
39{
40 u8 b = 0xff;
41 u8 pwm;
42 struct i2c_msg msg[] = {
43 {.addr = 0x50,.flags = 0,.buf = &b,.len = 1},
44 {.addr = 0x50,.flags = I2C_M_RD,.buf = &pwm,.len = 1}
45 };
46
47 if ((i2c_transfer(&mantis->adapter, msg, 2) != 2)
48 || (pwm == 0xff))
49 pwm = 0x48;
50
51 return pwm;
52}
53
54int philips_cu1216_tuner_set(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
Manu Abraham41e840b2009-12-02 21:57:10 -030055{
Manu Abraham41e840b2009-12-02 21:57:10 -030056 struct mantis_pci *mantis = fe->dvb->priv;
57
Manu Abraham2687d832009-12-04 04:39:14 -030058 u8 buf[6];
59 struct i2c_msg msg = {.addr = 0x60,.flags = 0,.buf = buf,.len = sizeof(buf) };
60 int i;
Manu Abraham41e840b2009-12-02 21:57:10 -030061
Manu Abraham2687d832009-12-04 04:39:14 -030062#define CU1216_IF 36125000
Manu Abraham41e840b2009-12-02 21:57:10 -030063#define TUNER_MUL 62500
64
Manu Abraham2687d832009-12-04 04:39:14 -030065 u32 div = (params->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
Manu Abraham41e840b2009-12-02 21:57:10 -030066
67 buf[0] = (div >> 8) & 0x7f;
68 buf[1] = div & 0xff;
Manu Abraham2687d832009-12-04 04:39:14 -030069 buf[2] = 0xce;
70 buf[3] = (params->frequency < 150000000 ? 0x01 :
71 params->frequency < 445000000 ? 0x02 : 0x04);
72 buf[4] = 0xde;
73 buf[5] = 0x20;
Manu Abraham41e840b2009-12-02 21:57:10 -030074
Manu Abraham2687d832009-12-04 04:39:14 -030075 if (fe->ops.i2c_gate_ctrl)
76 fe->ops.i2c_gate_ctrl(fe, 1);
77
78 if (i2c_transfer(&mantis->adapter, &msg, 1) != 1)
Manu Abraham41e840b2009-12-02 21:57:10 -030079 return -EIO;
Manu Abraham2687d832009-12-04 04:39:14 -030080
81 /* wait for the pll lock */
82 msg.flags = I2C_M_RD;
83 msg.len = 1;
84 for (i = 0; i < 20; i++) {
85 if (fe->ops.i2c_gate_ctrl)
86 fe->ops.i2c_gate_ctrl(fe, 1);
87
88 if (i2c_transfer(&mantis->adapter, &msg, 1) == 1 && (buf[0] & 0x40))
89 break;
90
91 msleep(10);
Manu Abraham41e840b2009-12-02 21:57:10 -030092 }
Manu Abraham2687d832009-12-04 04:39:14 -030093
94 /* switch the charge pump to the lower current */
95 msg.flags = 0;
96 msg.len = 2;
97 msg.buf = &buf[2];
98 buf[2] &= ~0x40;
99 if (fe->ops.i2c_gate_ctrl)
100 fe->ops.i2c_gate_ctrl(fe, 1);
101
102 if (i2c_transfer(&mantis->adapter, &msg, 1) != 1)
103 return -EIO;
Manu Abrahamda7365f2009-12-02 22:11:00 -0300104
Manu Abraham41e840b2009-12-02 21:57:10 -0300105 return 0;
106}