Linux 2.6.34-rc3
[pohmelfs.git] / drivers / media / dvb / firewire / firedtv-fe.c
blobe49cdc88b0c7fe751c1ab27cb3010deb97005f5d
1 /*
2 * FireDTV driver (formerly known as FireSAT)
4 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
5 * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
13 #include <linux/device.h>
14 #include <linux/errno.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/types.h>
19 #include <dvb_frontend.h>
21 #include "firedtv.h"
23 static int fdtv_dvb_init(struct dvb_frontend *fe)
25 struct firedtv *fdtv = fe->sec_priv;
26 int err;
28 /* FIXME - allocate free channel at IRM */
29 fdtv->isochannel = fdtv->adapter.num;
31 err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
32 fdtv->isochannel);
33 if (err) {
34 dev_err(fdtv->device,
35 "could not establish point to point connection\n");
36 return err;
39 return fdtv->backend->start_iso(fdtv);
42 static int fdtv_sleep(struct dvb_frontend *fe)
44 struct firedtv *fdtv = fe->sec_priv;
46 fdtv->backend->stop_iso(fdtv);
47 cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
48 fdtv->isochannel = -1;
49 return 0;
52 #define LNBCONTROL_DONTCARE 0xff
54 static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe,
55 struct dvb_diseqc_master_cmd *cmd)
57 struct firedtv *fdtv = fe->sec_priv;
59 return avc_lnb_control(fdtv, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
60 LNBCONTROL_DONTCARE, 1, cmd);
63 static int fdtv_diseqc_send_burst(struct dvb_frontend *fe,
64 fe_sec_mini_cmd_t minicmd)
66 return 0;
69 static int fdtv_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
71 struct firedtv *fdtv = fe->sec_priv;
73 fdtv->tone = tone;
74 return 0;
77 static int fdtv_set_voltage(struct dvb_frontend *fe,
78 fe_sec_voltage_t voltage)
80 struct firedtv *fdtv = fe->sec_priv;
82 fdtv->voltage = voltage;
83 return 0;
86 static int fdtv_read_status(struct dvb_frontend *fe, fe_status_t *status)
88 struct firedtv *fdtv = fe->sec_priv;
89 struct firedtv_tuner_status stat;
91 if (avc_tuner_status(fdtv, &stat))
92 return -EINVAL;
94 if (stat.no_rf)
95 *status = 0;
96 else
97 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
98 FE_HAS_CARRIER | FE_HAS_LOCK;
99 return 0;
102 static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber)
104 struct firedtv *fdtv = fe->sec_priv;
105 struct firedtv_tuner_status stat;
107 if (avc_tuner_status(fdtv, &stat))
108 return -EINVAL;
110 *ber = stat.ber;
111 return 0;
114 static int fdtv_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
116 struct firedtv *fdtv = fe->sec_priv;
117 struct firedtv_tuner_status stat;
119 if (avc_tuner_status(fdtv, &stat))
120 return -EINVAL;
122 *strength = stat.signal_strength << 8;
123 return 0;
126 static int fdtv_read_snr(struct dvb_frontend *fe, u16 *snr)
128 struct firedtv *fdtv = fe->sec_priv;
129 struct firedtv_tuner_status stat;
131 if (avc_tuner_status(fdtv, &stat))
132 return -EINVAL;
134 /* C/N[dB] = -10 * log10(snr / 65535) */
135 *snr = stat.carrier_noise_ratio * 257;
136 return 0;
139 static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
141 return -EOPNOTSUPP;
144 static int fdtv_set_frontend(struct dvb_frontend *fe,
145 struct dvb_frontend_parameters *params)
147 struct firedtv *fdtv = fe->sec_priv;
149 return avc_tuner_dsd(fdtv, params);
152 static int fdtv_get_frontend(struct dvb_frontend *fe,
153 struct dvb_frontend_parameters *params)
155 return -EOPNOTSUPP;
158 void fdtv_frontend_init(struct firedtv *fdtv)
160 struct dvb_frontend_ops *ops = &fdtv->fe.ops;
161 struct dvb_frontend_info *fi = &ops->info;
163 ops->init = fdtv_dvb_init;
164 ops->sleep = fdtv_sleep;
166 ops->set_frontend = fdtv_set_frontend;
167 ops->get_frontend = fdtv_get_frontend;
169 ops->read_status = fdtv_read_status;
170 ops->read_ber = fdtv_read_ber;
171 ops->read_signal_strength = fdtv_read_signal_strength;
172 ops->read_snr = fdtv_read_snr;
173 ops->read_ucblocks = fdtv_read_uncorrected_blocks;
175 ops->diseqc_send_master_cmd = fdtv_diseqc_send_master_cmd;
176 ops->diseqc_send_burst = fdtv_diseqc_send_burst;
177 ops->set_tone = fdtv_set_tone;
178 ops->set_voltage = fdtv_set_voltage;
180 switch (fdtv->type) {
181 case FIREDTV_DVB_S:
182 case FIREDTV_DVB_S2:
183 fi->type = FE_QPSK;
185 fi->frequency_min = 950000;
186 fi->frequency_max = 2150000;
187 fi->frequency_stepsize = 125;
188 fi->symbol_rate_min = 1000000;
189 fi->symbol_rate_max = 40000000;
191 fi->caps = FE_CAN_INVERSION_AUTO |
192 FE_CAN_FEC_1_2 |
193 FE_CAN_FEC_2_3 |
194 FE_CAN_FEC_3_4 |
195 FE_CAN_FEC_5_6 |
196 FE_CAN_FEC_7_8 |
197 FE_CAN_FEC_AUTO |
198 FE_CAN_QPSK;
199 break;
201 case FIREDTV_DVB_C:
202 fi->type = FE_QAM;
204 fi->frequency_min = 47000000;
205 fi->frequency_max = 866000000;
206 fi->frequency_stepsize = 62500;
207 fi->symbol_rate_min = 870000;
208 fi->symbol_rate_max = 6900000;
210 fi->caps = FE_CAN_INVERSION_AUTO |
211 FE_CAN_QAM_16 |
212 FE_CAN_QAM_32 |
213 FE_CAN_QAM_64 |
214 FE_CAN_QAM_128 |
215 FE_CAN_QAM_256 |
216 FE_CAN_QAM_AUTO;
217 break;
219 case FIREDTV_DVB_T:
220 fi->type = FE_OFDM;
222 fi->frequency_min = 49000000;
223 fi->frequency_max = 861000000;
224 fi->frequency_stepsize = 62500;
226 fi->caps = FE_CAN_INVERSION_AUTO |
227 FE_CAN_FEC_2_3 |
228 FE_CAN_TRANSMISSION_MODE_AUTO |
229 FE_CAN_GUARD_INTERVAL_AUTO |
230 FE_CAN_HIERARCHY_AUTO;
231 break;
233 default:
234 dev_err(fdtv->device, "no frontend for model type %d\n",
235 fdtv->type);
237 strcpy(fi->name, fdtv_model_names[fdtv->type]);
239 fdtv->fe.dvb = &fdtv->adapter;
240 fdtv->fe.sec_priv = fdtv;