blob: d480741afd786dc3e13420077d43f4567f38e666 [file] [log] [blame]
Manu Abrahamb2eb1312009-12-04 04:42:22 -03001/*
2 Mantis VP-2040 driver
3
4 Copyright (C) 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
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 Abrahamb2eb1312009-12-04 04:42:22 -030032#include "mantis_common.h"
Manu Abrahambc832fa2009-12-04 05:57:28 -030033#include "mantis_ioc.h"
34#include "mantis_dvb.h"
Manu Abrahamb2eb1312009-12-04 04:42:22 -030035#include "mantis_vp2040.h"
36
37#define MANTIS_MODEL_NAME "VP-2040"
38#define MANTIS_DEV_TYPE "DVB-C"
39
Manu Abrahamb3b96142009-12-04 05:41:11 -030040struct tda1002x_config vp2040_tda1002x_cu1216_config = {
41 .demod_address = 0x18 >> 1,
42 .invert = 1,
43};
44
45struct tda10023_config vp2040_tda10023_cu1216_config = {
46 .demod_address = 0x18 >> 1,
47 .invert = 1,
48};
49
Mauro Carvalho Chehab14d24d12011-12-24 12:24:33 -030050static int tda1002x_cu1216_tuner_set(struct dvb_frontend *fe)
Manu Abrahamb3b96142009-12-04 05:41:11 -030051{
Mauro Carvalho Chehab31cbc532011-12-23 07:18:04 -030052 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
Manu Abrahamb3b96142009-12-04 05:41:11 -030053 struct mantis_pci *mantis = fe->dvb->priv;
54 struct i2c_adapter *adapter = &mantis->adapter;
55
56 u8 buf[6];
Manu Abrahamf5ae4f62009-12-15 08:47:21 -030057 struct i2c_msg msg = {.addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf)};
Manu Abrahamb3b96142009-12-04 05:41:11 -030058 int i;
59
60#define CU1216_IF 36125000
61#define TUNER_MUL 62500
62
Mauro Carvalho Chehab31cbc532011-12-23 07:18:04 -030063 u32 div = (p->frequency + CU1216_IF + TUNER_MUL / 2) / TUNER_MUL;
Manu Abrahamb3b96142009-12-04 05:41:11 -030064
65 buf[0] = (div >> 8) & 0x7f;
66 buf[1] = div & 0xff;
67 buf[2] = 0xce;
Mauro Carvalho Chehab31cbc532011-12-23 07:18:04 -030068 buf[3] = (p->frequency < 150000000 ? 0x01 :
69 p->frequency < 445000000 ? 0x02 : 0x04);
Manu Abrahamb3b96142009-12-04 05:41:11 -030070 buf[4] = 0xde;
71 buf[5] = 0x20;
72
73 if (fe->ops.i2c_gate_ctrl)
74 fe->ops.i2c_gate_ctrl(fe, 1);
75
76 if (i2c_transfer(adapter, &msg, 1) != 1)
77 return -EIO;
78
79 /* wait for the pll lock */
80 msg.flags = I2C_M_RD;
81 msg.len = 1;
82 for (i = 0; i < 20; i++) {
83 if (fe->ops.i2c_gate_ctrl)
84 fe->ops.i2c_gate_ctrl(fe, 1);
85
86 if (i2c_transfer(adapter, &msg, 1) == 1 && (buf[0] & 0x40))
87 break;
88
89 msleep(10);
90 }
91
92 /* switch the charge pump to the lower current */
93 msg.flags = 0;
94 msg.len = 2;
95 msg.buf = &buf[2];
96 buf[2] &= ~0x40;
97 if (fe->ops.i2c_gate_ctrl)
98 fe->ops.i2c_gate_ctrl(fe, 1);
99
100 if (i2c_transfer(adapter, &msg, 1) != 1)
101 return -EIO;
102
103 return 0;
104}
105
106static u8 read_pwm(struct mantis_pci *mantis)
107{
108 struct i2c_adapter *adapter = &mantis->adapter;
109
110 u8 b = 0xff;
111 u8 pwm;
112 struct i2c_msg msg[] = {
113 {.addr = 0x50, .flags = 0, .buf = &b, .len = 1},
114 {.addr = 0x50, .flags = I2C_M_RD, .buf = &pwm, .len = 1}
115 };
116
117 if ((i2c_transfer(adapter, msg, 2) != 2)
118 || (pwm == 0xff))
119 pwm = 0x48;
120
121 return pwm;
122}
123
124static int vp2040_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, &vp2040_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 vp2040_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, &vp2040_tda10023_cu1216_config,
Manu Abrahambc832fa2009-12-04 05:57:28 -0300146 adapter,
147 read_pwm(mantis));
148
149 if (fe) {
150 dprintk(MANTIS_ERROR, 1,
151 "found Philips CU1216 DVB-C frontend (TDA10023) @ 0x%02x",
152 vp2040_tda1002x_cu1216_config.demod_address);
153 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300154 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300155
Manu Abrahambc832fa2009-12-04 05:57:28 -0300156 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);
Manu Abrahamb3b96142009-12-04 05:41:11 -0300166
Manu Abrahambc832fa2009-12-04 05:57:28 -0300167 return -EIO;
168 }
Manu Abrahamb3b96142009-12-04 05:41:11 -0300169 mantis->fe = fe;
170 dprintk(MANTIS_DEBUG, 1, "Done!");
171
172 return 0;
173}
174
175struct mantis_hwconfig vp2040_config = {
Manu Abrahamb2eb1312009-12-04 04:42:22 -0300176 .model_name = MANTIS_MODEL_NAME,
177 .dev_type = MANTIS_DEV_TYPE,
178 .ts_size = MANTIS_TS_204,
Manu Abrahamb3b96142009-12-04 05:41:11 -0300179
Manu Abrahamadd20632009-12-04 05:39:57 -0300180 .baud_rate = MANTIS_BAUD_9600,
181 .parity = MANTIS_PARITY_NONE,
182 .bytes = 0,
Manu Abrahamb2eb1312009-12-04 04:42:22 -0300183
Manu Abrahamb3b96142009-12-04 05:41:11 -0300184 .frontend_init = vp2040_frontend_init,
Manu Abrahambc832fa2009-12-04 05:57:28 -0300185 .power = GPIF_A12,
186 .reset = GPIF_A13,
Manu Abrahamb2eb1312009-12-04 04:42:22 -0300187};