blob: f2092ce9c4be6df70d9c324265f2da264192079a [file] [log] [blame]
Manu Abraham41e840b2009-12-02 21:57:10 -03001/*
2 Mantis VP-1033 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
Manu Abrahamb3b96142009-12-04 05:41:11 -030021#include <asm/irq.h>
22#include <linux/signal.h>
23#include <linux/sched.h>
24#include <linux/interrupt.h>
25
26#include "dmxdev.h"
27#include "dvbdev.h"
28#include "dvb_demux.h"
29#include "dvb_frontend.h"
30#include "dvb_net.h"
31
32#include "stv0299.h"
Manu Abraham41e840b2009-12-02 21:57:10 -030033#include "mantis_common.h"
34#include "mantis_vp1033.h"
35
36u8 lgtdqcs001f_inittab[] = {
37 0x01, 0x15,
38 0x02, 0x00,
39 0x03, 0x00,
40 0x04, 0x2a,
41 0x05, 0x85,
42 0x06, 0x02,
43 0x07, 0x00,
44 0x08, 0x00,
45 0x0c, 0x01,
46 0x0d, 0x81,
47 0x0e, 0x44,
48 0x0f, 0x94,
49 0x10, 0x3c,
50 0x11, 0x84,
51 0x12, 0xb9,
52 0x13, 0xb5,
53 0x14, 0x4f,
54 0x15, 0xc9,
55 0x16, 0x80,
56 0x17, 0x36,
57 0x18, 0xfb,
58 0x19, 0xcf,
59 0x1a, 0xbc,
60 0x1c, 0x2b,
61 0x1d, 0x27,
62 0x1e, 0x00,
63 0x1f, 0x0b,
64 0x20, 0xa1,
65 0x21, 0x60,
66 0x22, 0x00,
67 0x23, 0x00,
68 0x28, 0x00,
69 0x29, 0x28,
70 0x2a, 0x14,
71 0x2b, 0x0f,
72 0x2c, 0x09,
73 0x2d, 0x05,
74 0x31, 0x1f,
75 0x32, 0x19,
76 0x33, 0xfc,
77 0x34, 0x13,
78 0xff, 0xff,
79};
80
Manu Abrahamdf0cca12009-12-02 22:07:24 -030081#define MANTIS_MODEL_NAME "VP-1033"
82#define MANTIS_DEV_TYPE "DVB-S/DSS"
83
Manu Abraham41e840b2009-12-02 21:57:10 -030084int lgtdqcs001f_tuner_set(struct dvb_frontend *fe,
85 struct dvb_frontend_parameters *params)
86{
Manu Abrahamb3b96142009-12-04 05:41:11 -030087 struct mantis_pci *mantis = fe->dvb->priv;
88 struct i2c_adapter *adapter = &mantis->adapter;
89
Manu Abraham41e840b2009-12-02 21:57:10 -030090 u8 buf[4];
91 u32 div;
92
Manu Abraham41e840b2009-12-02 21:57:10 -030093
Manu Abrahamb3b96142009-12-04 05:41:11 -030094 struct i2c_msg msg = {.addr = 0x61, .flags = 0, .buf = buf, .len = sizeof (buf) };
95
Manu Abraham41e840b2009-12-02 21:57:10 -030096 div = params->frequency / 250;
97
98 buf[0] = (div >> 8) & 0x7f;
99 buf[1] = div & 0xff;
100 buf[2] = 0x83;
101 buf[3] = 0xc0;
102
103 if (params->frequency < 1531000)
104 buf[3] |= 0x04;
105 else
106 buf[3] &= ~0x04;
Manu Abrahamb3b96142009-12-04 05:41:11 -0300107 if (i2c_transfer(adapter, &msg, 1) < 0) {
108 dprintk(MANTIS_ERROR, 1, "Write: I2C Transfer failed");
Manu Abraham41e840b2009-12-02 21:57:10 -0300109 return -EIO;
110 }
111 msleep_interruptible(100);
112
113 return 0;
114}
115
116int lgtdqcs001f_set_symbol_rate(struct dvb_frontend *fe,
117 u32 srate, u32 ratio)
118{
119 u8 aclk = 0;
120 u8 bclk = 0;
121
122 if (srate < 1500000) {
123 aclk = 0xb7;
124 bclk = 0x47;
125 } else if (srate < 3000000) {
126 aclk = 0xb7;
127 bclk = 0x4b;
128 } else if (srate < 7000000) {
129 aclk = 0xb7;
130 bclk = 0x4f;
131 } else if (srate < 14000000) {
132 aclk = 0xb7;
133 bclk = 0x53;
134 } else if (srate < 30000000) {
135 aclk = 0xb6;
136 bclk = 0x53;
137 } else if (srate < 45000000) {
138 aclk = 0xb4;
139 bclk = 0x51;
140 }
141 stv0299_writereg (fe, 0x13, aclk);
142 stv0299_writereg (fe, 0x14, bclk);
143
144 stv0299_writereg (fe, 0x1f, (ratio >> 16) & 0xff);
145 stv0299_writereg (fe, 0x20, (ratio >> 8) & 0xff);
146 stv0299_writereg (fe, 0x21, (ratio ) & 0xf0);
147
148 return 0;
149}
Manu Abrahamb3b96142009-12-04 05:41:11 -0300150
151struct stv0299_config lgtdqcs001f_config = {
152 .demod_address = 0x68,
153 .inittab = lgtdqcs001f_inittab,
154 .mclk = 88000000UL,
155 .invert = 0,
156 .skip_reinit = 0,
157 .volt13_op0_op1 = STV0299_VOLT13_OP0,
158 .min_delay_ms = 100,
159 .set_symbol_rate = lgtdqcs001f_set_symbol_rate,
160};
161
162static int vp1033_frontend_init(struct mantis_pci *mantis, struct dvb_frontend *fe)
163{
164 struct i2c_adapter *adapter = &mantis->adapter;
165
166 dprintk(MANTIS_ERROR, 1, "Probing for STV0299 (DVB-S)");
167 fe = stv0299_attach(&lgtdqcs001f_config, adapter);
168
169 if (fe) {
170 fe->ops.tuner_ops.set_params = lgtdqcs001f_tuner_set;
171 dprintk(MANTIS_ERROR, 1, "found STV0299 DVB-S frontend @ 0x%02x",
172 lgtdqcs001f_config.demod_address);
173
174 dprintk(MANTIS_ERROR, 1, "Mantis DVB-S STV0299 frontend attach success");
175 } else {
176 return -1;
177 }
178
179 mantis->fe = fe;
180 dprintk(MANTIS_ERROR, 1, "Done!");
181
182 return 0;
183}
184
185struct mantis_hwconfig vp1033_config = {
186 .model_name = MANTIS_MODEL_NAME,
187 .dev_type = MANTIS_DEV_TYPE,
188 .ts_size = MANTIS_TS_204,
189
190 .baud_rate = MANTIS_BAUD_9600,
191 .parity = MANTIS_PARITY_NONE,
192 .bytes = 0,
193
194 .frontend_init = vp1033_frontend_init,
195};