[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / drivers / media / dvb / ttusb-dec / ttusbdecfe.c
blob1699cc9f6bb0ddd563d4f49d8ce5b0609e95455a
1 /*
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;
38 u8 hi_band;
39 u8 voltage;
43 static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
45 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
46 FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
48 return 0;
51 static int ttusbdecfe_dvbt_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
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 };
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);
64 return 0;
67 static int ttusbdecfe_dvbs_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
69 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
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;
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));
96 state->config->send_command(fe, 0x71, sizeof(b), b, NULL, NULL);
98 return 0;
101 static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *cmd)
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 };
108 memcpy(&b[4], cmd->msg, cmd->msg_len);
110 state->config->send_command(fe, 0x72,
111 sizeof(b) - (6 - cmd->msg_len), b,
112 NULL, NULL);
114 return 0;
118 static int ttusbdecfe_dvbs_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
120 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
122 state->hi_band = (SEC_TONE_ON == tone);
124 return 0;
128 static int ttusbdecfe_dvbs_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
130 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
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;
143 return 0;
146 static void ttusbdecfe_release(struct dvb_frontend* fe)
148 struct ttusbdecfe_state* state = (struct ttusbdecfe_state*) fe->demodulator_priv;
149 kfree(state);
152 static struct dvb_frontend_ops ttusbdecfe_dvbt_ops;
154 struct dvb_frontend* ttusbdecfe_dvbt_attach(const struct ttusbdecfe_config* config)
156 struct ttusbdecfe_state* state = NULL;
158 /* allocate memory for the internal state */
159 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
160 if (state == NULL) goto error;
162 /* setup the state */
163 state->config = config;
164 memcpy(&state->ops, &ttusbdecfe_dvbt_ops, sizeof(struct dvb_frontend_ops));
166 /* create dvb_frontend */
167 state->frontend.ops = &state->ops;
168 state->frontend.demodulator_priv = state;
169 return &state->frontend;
171 error:
172 kfree(state);
173 return NULL;
176 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops;
178 struct dvb_frontend* ttusbdecfe_dvbs_attach(const struct ttusbdecfe_config* config)
180 struct ttusbdecfe_state* state = NULL;
182 /* allocate memory for the internal state */
183 state = (struct ttusbdecfe_state*) kmalloc(sizeof(struct ttusbdecfe_state), GFP_KERNEL);
184 if (state == NULL) goto error;
186 /* setup the state */
187 state->config = config;
188 state->voltage = 0;
189 state->hi_band = 0;
190 memcpy(&state->ops, &ttusbdecfe_dvbs_ops, sizeof(struct dvb_frontend_ops));
192 /* create dvb_frontend */
193 state->frontend.ops = &state->ops;
194 state->frontend.demodulator_priv = state;
195 return &state->frontend;
197 error:
198 kfree(state);
199 return NULL;
202 static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
204 .info = {
205 .name = "TechnoTrend/Hauppauge DEC2000-t Frontend",
206 .type = FE_OFDM,
207 .frequency_min = 51000000,
208 .frequency_max = 858000000,
209 .frequency_stepsize = 62500,
210 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
211 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
212 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
213 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
214 FE_CAN_HIERARCHY_AUTO,
217 .release = ttusbdecfe_release,
219 .set_frontend = ttusbdecfe_dvbt_set_frontend,
221 .read_status = ttusbdecfe_read_status,
224 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
226 .info = {
227 .name = "TechnoTrend/Hauppauge DEC3000-s Frontend",
228 .type = FE_QPSK,
229 .frequency_min = 950000,
230 .frequency_max = 2150000,
231 .frequency_stepsize = 125,
232 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
233 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
234 FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
235 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
236 FE_CAN_HIERARCHY_AUTO,
239 .release = ttusbdecfe_release,
241 .set_frontend = ttusbdecfe_dvbs_set_frontend,
243 .read_status = ttusbdecfe_read_status,
245 .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
246 .set_voltage = ttusbdecfe_dvbs_set_voltage,
247 .set_tone = ttusbdecfe_dvbs_set_tone,
250 MODULE_DESCRIPTION("TTUSB DEC DVB-T/S Demodulator driver");
251 MODULE_AUTHOR("Alex Woods/Andrew de Quincey");
252 MODULE_LICENSE("GPL");
254 EXPORT_SYMBOL(ttusbdecfe_dvbt_attach);
255 EXPORT_SYMBOL(ttusbdecfe_dvbs_attach);