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 /* configuration settings */
32 const struct ttusbdecfe_config
* config
;
34 struct dvb_frontend frontend
;
41 static int ttusbdecfe_read_status(struct dvb_frontend
* fe
, fe_status_t
* status
)
43 struct ttusbdecfe_state
* state
= fe
->demodulator_priv
;
44 u8 b
[] = { 0x00, 0x00, 0x00, 0x00,
45 0x00, 0x00, 0x00, 0x00 };
51 ret
=state
->config
->send_command(fe
, 0x73, sizeof(b
), b
, &len
, result
);
56 printk(KERN_ERR
"%s: unexpected reply\n", __FUNCTION__
);
61 case 1: /* not tuned yet */
62 case 2: /* no signal/no lock*/
64 case 3: /* signal found and locked*/
65 *status
= FE_HAS_SIGNAL
| FE_HAS_VITERBI
|
66 FE_HAS_SYNC
| FE_HAS_CARRIER
| FE_HAS_LOCK
;
69 *status
= FE_TIMEDOUT
;
72 pr_info("%s: returned unknown value: %d\n",
73 __FUNCTION__
, result
[3]);
80 static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
82 struct ttusbdecfe_state
* state
= (struct ttusbdecfe_state
*) fe
->demodulator_priv
;
83 u8 b
[] = { 0x00, 0x00, 0x00, 0x03,
84 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x01,
86 0x00, 0x00, 0x00, 0xff,
87 0x00, 0x00, 0x00, 0xff };
89 u32 freq
= htonl(p
->frequency
/ 1000);
90 memcpy(&b
[4], &freq
, sizeof (u32
));
91 state
->config
->send_command(fe
, 0x71, sizeof(b
), b
, NULL
, NULL
);
96 static int ttusbdecfe_dvbt_get_tune_settings(struct dvb_frontend
* fe
,
97 struct dvb_frontend_tune_settings
* fesettings
)
99 fesettings
->min_delay_ms
= 1500;
100 /* Drift compensation makes no sense for DVB-T */
101 fesettings
->step_size
= 0;
102 fesettings
->max_drift
= 0;
106 static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*p
)
108 struct ttusbdecfe_state
* state
= (struct ttusbdecfe_state
*) fe
->demodulator_priv
;
110 u8 b
[] = { 0x00, 0x00, 0x00, 0x01,
111 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x01,
113 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00,
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 };
125 freq
= htonl(p
->frequency
+
126 (state
->hi_band
? LOF_HI
: LOF_LO
));
127 memcpy(&b
[4], &freq
, sizeof(u32
));
128 sym_rate
= htonl(p
->u
.qam
.symbol_rate
);
129 memcpy(&b
[12], &sym_rate
, sizeof(u32
));
130 band
= htonl(state
->hi_band
? LOF_HI
: LOF_LO
);
131 memcpy(&b
[24], &band
, sizeof(u32
));
132 lnb_voltage
= htonl(state
->voltage
);
133 memcpy(&b
[28], &lnb_voltage
, sizeof(u32
));
135 state
->config
->send_command(fe
, 0x71, sizeof(b
), b
, NULL
, NULL
);
140 static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend
* fe
, struct dvb_diseqc_master_cmd
*cmd
)
142 struct ttusbdecfe_state
* state
= (struct ttusbdecfe_state
*) fe
->demodulator_priv
;
143 u8 b
[] = { 0x00, 0xff, 0x00, 0x00,
144 0x00, 0x00, 0x00, 0x00,
147 memcpy(&b
[4], cmd
->msg
, cmd
->msg_len
);
149 state
->config
->send_command(fe
, 0x72,
150 sizeof(b
) - (6 - cmd
->msg_len
), b
,
157 static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend
* fe
, fe_sec_tone_mode_t tone
)
159 struct ttusbdecfe_state
* state
= (struct ttusbdecfe_state
*) fe
->demodulator_priv
;
161 state
->hi_band
= (SEC_TONE_ON
== tone
);
167 static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend
* fe
, fe_sec_voltage_t voltage
)
169 struct ttusbdecfe_state
* state
= (struct ttusbdecfe_state
*) fe
->demodulator_priv
;
185 static void ttusbdecfe_release(struct dvb_frontend
* fe
)
187 struct ttusbdecfe_state
* state
= (struct ttusbdecfe_state
*) fe
->demodulator_priv
;
191 static struct dvb_frontend_ops ttusbdecfe_dvbt_ops
;
193 struct dvb_frontend
* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config
* config
)
195 struct ttusbdecfe_state
* state
= NULL
;
197 /* allocate memory for the internal state */
198 state
= kmalloc(sizeof(struct ttusbdecfe_state
), GFP_KERNEL
);
202 /* setup the state */
203 state
->config
= config
;
205 /* create dvb_frontend */
206 memcpy(&state
->frontend
.ops
, &ttusbdecfe_dvbt_ops
, sizeof(struct dvb_frontend_ops
));
207 state
->frontend
.demodulator_priv
= state
;
208 return &state
->frontend
;
211 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops
;
213 struct dvb_frontend
* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config
* config
)
215 struct ttusbdecfe_state
* state
= NULL
;
217 /* allocate memory for the internal state */
218 state
= kmalloc(sizeof(struct ttusbdecfe_state
), GFP_KERNEL
);
222 /* setup the state */
223 state
->config
= config
;
227 /* create dvb_frontend */
228 memcpy(&state
->frontend
.ops
, &ttusbdecfe_dvbs_ops
, sizeof(struct dvb_frontend_ops
));
229 state
->frontend
.demodulator_priv
= state
;
230 return &state
->frontend
;
233 static struct dvb_frontend_ops ttusbdecfe_dvbt_ops
= {
236 .name
= "TechnoTrend/Hauppauge DEC2000-t Frontend",
238 .frequency_min
= 51000000,
239 .frequency_max
= 858000000,
240 .frequency_stepsize
= 62500,
241 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
242 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
243 FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
244 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
|
245 FE_CAN_HIERARCHY_AUTO
,
248 .release
= ttusbdecfe_release
,
250 .set_frontend
= ttusbdecfe_dvbt_set_frontend
,
252 .get_tune_settings
= ttusbdecfe_dvbt_get_tune_settings
,
254 .read_status
= ttusbdecfe_read_status
,
257 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops
= {
260 .name
= "TechnoTrend/Hauppauge DEC3000-s Frontend",
262 .frequency_min
= 950000,
263 .frequency_max
= 2150000,
264 .frequency_stepsize
= 125,
265 .symbol_rate_min
= 1000000, /* guessed */
266 .symbol_rate_max
= 45000000, /* guessed */
267 .caps
= FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
268 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
272 .release
= ttusbdecfe_release
,
274 .set_frontend
= ttusbdecfe_dvbs_set_frontend
,
276 .read_status
= ttusbdecfe_read_status
,
278 .diseqc_send_master_cmd
= ttusbdecfe_dvbs_diseqc_send_master_cmd
,
279 .set_voltage
= ttusbdecfe_dvbs_set_voltage
,
280 .set_tone
= ttusbdecfe_dvbs_set_tone
,
283 MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
284 MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
285 MODULE_LICENSE("GPL");
287 EXPORT_SYMBOL(ttusbdecfe_dvbt_attach
);
288 EXPORT_SYMBOL(ttusbdecfe_dvbs_attach
);