blob: 725af3af5b27105f5c2e8555e68de691272e41fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * TTUSB DEC Frontend Driver
3 *
4 * Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
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
22#include "dvb_frontend.h"
23#include "ttusbdecfe.h"
24
25
26#define LOF_HI 10600000
27#define LOF_LO 9750000
28
29struct ttusbdecfe_state {
30
31 struct dvb_frontend_ops ops;
32
33 /* configuration settings */
34 const struct ttusbdecfe_config* config;
35
36 struct dvb_frontend frontend;
37
38 u8 hi_band;
39 u8 voltage;
40};
41
42
43static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
44{
45 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
46 FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
47
48 return 0;
49}
50
51static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
52{
53 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
54 u8 b[] = { 0x00, 0x00, 0x00, 0x03,
55 0x00, 0x00, 0x00, 0x00,
56 0x00, 0x00, 0x00, 0x01,
57 0x00, 0x00, 0x00, 0xff,
58 0x00, 0x00, 0x00, 0xff };
59
60 u32 freq = htonl(p->frequency / 1000);
61 memcpy(&b[4], &freq, sizeof (u32));
62 state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
63
64 return 0;
65}
66
67static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
68{
69 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
70
71 u8 b[] = { 0x00, 0x00, 0x00, 0x01,
72 0x00, 0x00, 0x00, 0x00,
73 0x00, 0x00, 0x00, 0x01,
74 0x00, 0x00, 0x00, 0x00,
75 0x00, 0x00, 0x00, 0x00,
76 0x00, 0x00, 0x00, 0x00,
77 0x00, 0x00, 0x00, 0x00,
78 0x00, 0x00, 0x00, 0x00,
79 0x00, 0x00, 0x00, 0x00,
80 0x00, 0x00, 0x00, 0x00 };
81 u32 freq;
82 u32 sym_rate;
83 u32 band;
84 u32 lnb_voltage;
85
86 freq = htonl(p->frequency +
87 (state->hi_band ? LOF_HI : LOF_LO));
88 memcpy(&b[4], &freq, sizeof(u32));
89 sym_rate = htonl(p->u.qam.symbol_rate);
90 memcpy(&b[12], &sym_rate, sizeof(u32));
91 band = htonl(state->hi_band ? LOF_HI : LOF_LO);
92 memcpy(&b[24], &band, sizeof(u32));
93 lnb_voltage = htonl(state->voltage);
94 memcpy(&b[28], &lnb_voltage, sizeof(u32));
95
96 state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
97
98 return 0;
99}
100
101static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
102{
103 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
104 u8 b[] = { 0x00, 0xff, 0x00, 0x00,
105 0x00, 0x00, 0x00, 0x00,
106 0x00, 0x00 };
107
108 memcpy(&b[4], cmd->msg, cmd->msg_len);
109
110 state->config->send_command(fe, 0x72,
111 sizeof(b) - (6 - cmd->msg_len), b,
112 NULL, NULL);
113
114 return 0;
115}
116
117
118static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
119{
120 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
121
122 state->hi_band = (SEC_TONE_ON == tone);
123
124 return 0;
125}
126
127
128static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
129{
130 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
131
132 switch (voltage) {
133 case SEC_VOLTAGE_13:
134 state->voltage = 13;
135 break;
136 case SEC_VOLTAGE_18:
137 state->voltage = 18;
138 break;
139 default:
140 return -EINVAL;
141 }
142
143 return 0;
144}
145
146static void ttusbdecfe_release(struct dvb_frontend* fe)
147{
148 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
149 kfree(state);
150}
151
152static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
153
154struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
155{
156 struct ttusbdecfe_state* state = NULL;
157
158 /* allocate memory for the internal state */
159 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
Adrian Bunk771e7152005-07-07 17:57:52 -0700160 if (state == NULL)
161 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* setup the state */
164 state->config = config;
165 memcpy(&state->ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
166
167 /* create dvb_frontend */
168 state->frontend.ops = &state->ops;
169 state->frontend.demodulator_priv = state;
170 return &state->frontend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
173static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
174
175struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
176{
177 struct ttusbdecfe_state* state = NULL;
178
179 /* allocate memory for the internal state */
180 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
Adrian Bunk771e7152005-07-07 17:57:52 -0700181 if (state == NULL)
182 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183
184 /* setup the state */
185 state->config = config;
186 state->voltage = 0;
187 state->hi_band = 0;
188 memcpy(&state->ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
189
190 /* create dvb_frontend */
191 state->frontend.ops = &state->ops;
192 state->frontend.demodulator_priv = state;
193 return &state->frontend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
196static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
197
198 .info = {
199 .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
200 .type = FE_OFDM,
201 .frequency_min = 51000000,
202 .frequency_max = 858000000,
203 .frequency_stepsize = 62500,
204 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
205 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
206 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
207 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
208 FE_CAN_HIERARCHY_AUTO,
209 },
210
211 .release = ttusbdecfe_release,
212
213 .set_frontend = ttusbdecfe_dvbt_set_frontend,
214
215 .read_status = ttusbdecfe_read_status,
216};
217
218static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
219
220 .info = {
221 .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
222 .type = FE_QPSK,
223 .frequency_min = 950000,
224 .frequency_max = 2150000,
225 .frequency_stepsize = 125,
226 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
227 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
228 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
229 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
230 FE_CAN_HIERARCHY_AUTO,
231 },
232
233 .release = ttusbdecfe_release,
234
235 .set_frontend = ttusbdecfe_dvbs_set_frontend,
236
237 .read_status = ttusbdecfe_read_status,
238
239 .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
240 .set_voltage = ttusbdecfe_dvbs_set_voltage,
241 .set_tone = ttusbdecfe_dvbs_set_tone,
242};
243
244MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
245MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
246MODULE_LICENSE("GPL");
247
248EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
249EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);