2 * TTUSB DEC Frontend Driver
4 * Copyright (C) 2003-2004 Alex Woods <linux-dvb@giblets.org>
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.
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.
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.
22 #include "dvb_frontend.h"
23 #include "ttusbdecfe.h"
26 #define LOF_HI 10600000
27 #define LOF_LO 9750000
29 struct ttusbdecfe_state {
31 struct dvb_frontend_ops ops;
33 /* configuration settings */
34 const struct ttusbdecfe_config* config;
36 struct dvb_frontend frontend;
43 static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
45 struct ttusbdecfe_state* state = fe->demodulator_priv;
46 u8 b[] = { 0x00, 0x00, 0x00, 0x00,
47 0x00, 0x00, 0x00, 0x00 };
53 ret=state->config->send_command(fe, 0x73, sizeof(b), b, &len, result);
58 printk(KERN_ERR "%s: unexpected reply\n", __FUNCTION__);
63 case 1: /* not tuned yet */
64 case 2: /* no signal/no lock*/
66 case 3: /* signal found and locked*/
67 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
68 FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
71 *status = FE_TIMEDOUT;
74 pr_info("%s: returned unknown value: %d\n",
75 __FUNCTION__, result[3]);
82 static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
84 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
85 u8 b[] = { 0x00, 0x00, 0x00, 0x03,
86 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x01,
88 0x00, 0x00, 0x00, 0xff,
89 0x00, 0x00, 0x00, 0xff };
91 u32 freq = htonl(p->frequency / 1000);
92 memcpy(&b[4], &freq, sizeof (u32));
93 state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
98 static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend* fe,
99 struct dvb_frontend_tune_settings* fesettings)
101 fesettings->min_delay_ms = 1500;
102 /* Drift compensation makes no sense for DVB-T */
103 fesettings->step_size = 0;
104 fesettings->max_drift = 0;
108 static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
110 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
112 u8 b[] = { 0x00, 0x00, 0x00, 0x01,
113 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x01,
115 0x00, 0x00, 0x00, 0x00,
116 0x00, 0x00, 0x00, 0x00,
117 0x00, 0x00, 0x00, 0x00,
118 0x00, 0x00, 0x00, 0x00,
119 0x00, 0x00, 0x00, 0x00,
120 0x00, 0x00, 0x00, 0x00,
121 0x00, 0x00, 0x00, 0x00 };
127 freq = htonl(p->frequency +
128 (state->hi_band ? LOF_HI : LOF_LO));
129 memcpy(&b[4], &freq, sizeof(u32));
130 sym_rate = htonl(p->u.qam.symbol_rate);
131 memcpy(&b[12], &sym_rate, sizeof(u32));
132 band = htonl(state->hi_band ? LOF_HI : LOF_LO);
133 memcpy(&b[24], &band, sizeof(u32));
134 lnb_voltage = htonl(state->voltage);
135 memcpy(&b[28], &lnb_voltage, sizeof(u32));
137 state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
142 static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
144 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
145 u8 b[] = { 0x00, 0xff, 0x00, 0x00,
146 0x00, 0x00, 0x00, 0x00,
149 memcpy(&b[4], cmd->msg, cmd->msg_len);
151 state->config->send_command(fe, 0x72,
152 sizeof(b) - (6 - cmd->msg_len), b,
159 static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
161 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
163 state->hi_band = (SEC_TONE_ON == tone);
169 static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
171 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
187 static void ttusbdecfe_release(struct dvb_frontend* fe)
189 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
193 static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
195 struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
197 struct ttusbdecfe_state* state = NULL;
199 /* allocate memory for the internal state */
200 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
204 /* setup the state */
205 state->config = config;
206 memcpy(&state->ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
208 /* create dvb_frontend */
209 state->frontend.ops = &state->ops;
210 state->frontend.demodulator_priv = state;
211 return &state->frontend;
214 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
216 struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
218 struct ttusbdecfe_state* state = NULL;
220 /* allocate memory for the internal state */
221 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
225 /* setup the state */
226 state->config = config;
229 memcpy(&state->ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
231 /* create dvb_frontend */
232 state->frontend.ops = &state->ops;
233 state->frontend.demodulator_priv = state;
234 return &state->frontend;
237 static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
240 .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
242 .frequency_min = 51000000,
243 .frequency_max = 858000000,
244 .frequency_stepsize = 62500,
245 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
246 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
247 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
248 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
249 FE_CAN_HIERARCHY_AUTO,
252 .release = ttusbdecfe_release,
254 .set_frontend = ttusbdecfe_dvbt_set_frontend,
256 .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings,
258 .read_status = ttusbdecfe_read_status,
261 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
264 .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
266 .frequency_min = 950000,
267 .frequency_max = 2150000,
268 .frequency_stepsize = 125,
269 .symbol_rate_min = 1000000, /* guessed */
270 .symbol_rate_max = 45000000, /* guessed */
271 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
272 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
276 .release = ttusbdecfe_release,
278 .set_frontend = ttusbdecfe_dvbs_set_frontend,
280 .read_status = ttusbdecfe_read_status,
282 .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
283 .set_voltage = ttusbdecfe_dvbs_set_voltage,
284 .set_tone = ttusbdecfe_dvbs_set_tone,
287 MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
288 MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
289 MODULE_LICENSE("GPL");
291 EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
292 EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);