blob: 8d48b5abe04a5eb42d3eb0586b85e6884751ca9f [file] [log] [blame]
Manu Abraham41e840b2009-12-02 21:57:10 -03001/*
2 Mantis VP-2033 driver
3
Manu Abraham8825a092009-12-15 09:13:49 -03004 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
Manu Abraham41e840b2009-12-02 21:57:10 -03005
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
Manu Abrahamb3b96142009-12-04 05:41:11 -030021#include <linux/signal.h>
22#include <linux/sched.h>
23#include <linux/interrupt.h>
24
25#include "dmxdev.h"
26#include "dvbdev.h"
27#include "dvb_demux.h"
28#include "dvb_frontend.h"
29#include "dvb_net.h"
30
31#include "tda1002x.h"
Manu Abraham41e840b2009-12-02 21:57:10 -030032#include "mantis_common.h"
Manu Abrahambc832fa2009-12-04 05:57:28 -030033#include "mantis_ioc.h"
34#include "mantis_dvb.h"
Manu Abraham41e840b2009-12-02 21:57:10 -030035#include "mantis_vp2033.h"
36
Manu Abrahamdf0cca12009-12-02 22:07:24 -030037#define MANTIS_MODEL_NAME "VP-2033"
38#define MANTIS_DEV_TYPE "DVB-C"
39
Hans Verkuil967a3782014-08-20 18:26:40 -030040static struct tda1002x_config vp2033_tda1002x_cu1216_config = {
Manu Abraham2687d832009-12-04 04:39:14 -030041 .demod_address = 0x18 >> 1,
42 .invert = 1,
Manu Abraham41e840b2009-12-02 21:57:10 -030043};
44
Hans Verkuil967a3782014-08-20 18:26:40 -030045static struct tda10023_config vp2033_tda10023_cu1216_config = {
Manu Abrahamb3b96142009-12-04 05:41:11 -030046 .demod_address = 0x18 >> 1,
47 .invert = 1,
48};
49
50static u8 read_pwm(struct mantis_pci *mantis)
Manu Abraham2687d832009-12-04 04:39:14 -030051{
Manu Abrahamb3b96142009-12-04 05:41:11 -030052 struct i2c_adapter *adapter = &mantis->adapter;
53
Manu Abraham2687d832009-12-04 04:39:14 -030054 u8 b = 0xff;
55 u8 pwm;
56 struct i2c_msg msg[] = {
Manu Abrahamb3b96142009-12-04 05:41:11 -030057 {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
58 {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
Manu Abraham2687d832009-12-04 04:39:14 -030059 };
60
Manu Abrahamb3b96142009-12-04 05:41:11 -030061 if ((i2c_transfer(adapter, msg, 2) != 2)
Manu Abraham2687d832009-12-04 04:39:14 -030062 || (pwm == 0xff))
63 pwm = 0x48;
64
65 return pwm;
66}
67
Mauro Carvalho Chehab14d24d12011-12-24 12:24:33 -030068static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe)
Manu Abraham41e840b2009-12-02 21:57:10 -030069{
Mauro Carvalho Chehabf0b6c2a2011-12-23 07:10:02 -030070 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
Manu Abraham41e840b2009-12-02 21:57:10 -030071 struct mantis_pci *mantis = fe->dvb->priv;
Manu Abrahamb3b96142009-12-04 05:41:11 -030072 struct i2c_adapter *adapter = &mantis->adapter;
Manu Abraham41e840b2009-12-02 21:57:10 -030073
Manu Abraham2687d832009-12-04 04:39:14 -030074 u8 buf[6];
Manu Abrahamf5ae4f62009-12-15 08:47:21 -030075 struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
Manu Abraham2687d832009-12-04 04:39:14 -030076 int i;
Manu Abraham41e840b2009-12-02 21:57:10 -030077
Manu Abraham2687d832009-12-04 04:39:14 -030078#define CU1216_IF 36125000
Manu Abraham41e840b2009-12-02 21:57:10 -030079#define TUNER_MUL 62500
80
Mauro Carvalho Chehabf0b6c2a2011-12-23 07:10:02 -030081 u32 div = (p->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
Manu Abraham41e840b2009-12-02 21:57:10 -030082
83 buf[0] = (div >> 8) & 0x7f;
84 buf[1] = div & 0xff;
Manu Abraham2687d832009-12-04 04:39:14 -030085 buf[2] = 0xce;
Mauro Carvalho Chehabf0b6c2a2011-12-23 07:10:02 -030086 buf[3] = (p->frequency < 150000000 ? 0x01 :
87 p->frequency < 445000000 ? 0x02 : 0x04);
Manu Abraham2687d832009-12-04 04:39:14 -030088 buf[4] = 0xde;
89 buf[5] = 0x20;
Manu Abraham41e840b2009-12-02 21:57:10 -030090
Manu Abraham2687d832009-12-04 04:39:14 -030091 if (fe->ops.i2c_gate_ctrl)
92 fe->ops.i2c_gate_ctrl(fe, 1);
93
Manu Abrahamb3b96142009-12-04 05:41:11 -030094 if (i2c_transfer(adapter, &msg, 1) != 1)
Manu Abraham41e840b2009-12-02 21:57:10 -030095 return -EIO;
Manu Abraham2687d832009-12-04 04:39:14 -030096
97 /* wait for the pll lock */
98 msg.flags = I2C_M_RD;
99 msg.len = 1;
100 for (i = 0; i < 20; i++) {
101 if (fe->ops.i2c_gate_ctrl)
102 fe->ops.i2c_gate_ctrl(fe, 1);
103
Manu Abrahamb3b96142009-12-04 05:41:11 -0300104 if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
Manu Abraham2687d832009-12-04 04:39:14 -0300105 break;
106
107 msleep(10);
Manu Abraham41e840b2009-12-02 21:57:10 -0300108 }
Manu Abraham2687d832009-12-04 04:39:14 -0300109
110 /* switch the charge pump to the lower current */
111 msg.flags = 0;
112 msg.len = 2;
113 msg.buf = &buf[2];
114 buf[2] &= ~0x40;
115 if (fe->ops.i2c_gate_ctrl)
116 fe->ops.i2c_gate_ctrl(fe, 1);
117
Manu Abrahamb3b96142009-12-04 05:41:11 -0300118 if (i2c_transfer(adapter, &msg, 1) != 1)
Manu Abraham2687d832009-12-04 04:39:14 -0300119 return -EIO;
Manu Abrahamda7365f2009-12-02 22:11:00 -0300120
Manu Abraham41e840b2009-12-02 21:57:10 -0300121 return 0;
122}
Manu Abrahamb3b96142009-12-04 05:41:11 -0300123
124static int vp2033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
125{
126 struct i2c_adapter *adapter = &mantis->adapter;
127
Manu Abrahambc832fa2009-12-04 05:57:28 -0300128 int err = 0;
Manu Abrahamb3b96142009-12-04 05:41:11 -0300129
Manu Abrahambc832fa2009-12-04 05:57:28 -0300130 err = mantis_frontend_power(mantis, POWER_ON);
131 if (err == 0) {
132 mantis_frontend_soft_reset(mantis);
133 msleep(250);
134
135 dprintk(MANTIS_ERROR, 1, "Probing for CU1216 (DVB-C)");
Bjørn Morka22407f2010-11-14 14:24:36 -0300136 fe = dvb_attach(tda10021_attach, &vp2033_tda1002x_cu1216_config,
Manu Abrahamb3b96142009-12-04 05:41:11 -0300137 adapter,
138 read_pwm(mantis));
139
140 if (fe) {
141 dprintk(MANTIS_ERROR, 1,
Manu Abrahambc832fa2009-12-04 05:57:28 -0300142 "found Philips CU1216 DVB-C frontend (TDA10021) @ 0x%02x",
Manu Abrahamb3b96142009-12-04 05:41:11 -0300143 vp2033_tda1002x_cu1216_config.demod_address);
Manu Abrahambc832fa2009-12-04 05:57:28 -0300144 } else {
Bjørn Morka22407f2010-11-14 14:24:36 -0300145 fe = dvb_attach(tda10023_attach, &vp2033_tda10023_cu1216_config,
Manu Abrahambc832fa2009-12-04 05:57:28 -0300146 adapter,
147 read_pwm(mantis));
Manu Abrahamb3b96142009-12-04 05:41:11 -0300148
Manu Abrahambc832fa2009-12-04 05:57:28 -0300149 if (fe) {
150 dprintk(MANTIS_ERROR, 1,
151 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
152 vp2033_tda1002x_cu1216_config.demod_address);
153 }
154 }
155
156 if (fe) {
157 fe->ops.tuner_ops.set_params = tda1002x_cu1216_tuner_set;
158 dprintk(MANTIS_ERROR, 1, "Mantis DVB-C Philips CU1216 frontend attach success");
159 } else {
160 return -1;
161 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300162 } else {
Manu Abrahambc832fa2009-12-04 05:57:28 -0300163 dprintk(MANTIS_ERROR, 1, "Frontend on <%s> POWER ON failed! <%d>",
164 adapter->name,
165 err);
166
167 return -EIO;
Manu Abrahamb3b96142009-12-04 05:41:11 -0300168 }
169
170 mantis->fe = fe;
171 dprintk(MANTIS_DEBUG, 1, "Done!");
172
173 return 0;
174}
175
176struct mantis_hwconfig vp2033_config = {
177 .model_name = MANTIS_MODEL_NAME,
178 .dev_type = MANTIS_DEV_TYPE,
179 .ts_size = MANTIS_TS_204,
180
181 .baud_rate = MANTIS_BAUD_9600,
182 .parity = MANTIS_PARITY_NONE,
183 .bytes = 0,
184
185 .frontend_init = vp2033_frontend_init,
Manu Abrahambc832fa2009-12-04 05:57:28 -0300186 .power = GPIF_A12,
187 .reset = GPIF_A13,
Manu Abrahamb3b96142009-12-04 05:41:11 -0300188};