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/init.h>
14 #include <linux/slab.h>
15 #include <linux/wait.h>
16 #include <linux/module.h>
17 #include <linux/delay.h>
18 #include <linux/time.h>
19 #include <linux/errno.h>
20 #include <linux/interrupt.h>
21 #include <ieee1394_hotplug.h>
23 #include <highlevel.h>
31 #include "firesat-rc.h"
32 #include "firesat-ci.h"
34 static int firesat_dvb_init(struct dvb_frontend *fe)
37 struct firesat *firesat = fe->sec_priv;
38 // printk("fdi: 1\n");
39 firesat->isochannel = firesat->adapter->num; //<< 1 | (firesat->subunit & 0x1); // ### ask IRM
40 // printk("fdi: 2\n");
41 result = try_CMPEstablishPPconnection(firesat, firesat->subunit, firesat->isochannel);
43 printk(KERN_ERR "Could not establish point to point "
47 // printk("fdi: 3\n");
49 result = setup_iso_channel(firesat);
50 // printk("fdi: 4. Result was %d\n", result);
54 static int firesat_sleep(struct dvb_frontend *fe)
56 struct firesat *firesat = fe->sec_priv;
58 tear_down_iso_channel(firesat);
59 try_CMPBreakPPconnection(firesat, firesat->subunit, firesat->isochannel);
60 firesat->isochannel = -1;
64 static int firesat_diseqc_send_master_cmd(struct dvb_frontend *fe,
65 struct dvb_diseqc_master_cmd *cmd)
67 struct firesat *firesat = fe->sec_priv;
69 return AVCLNBControl(firesat, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
70 LNBCONTROL_DONTCARE, 1, cmd);
73 static int firesat_diseqc_send_burst(struct dvb_frontend *fe,
74 fe_sec_mini_cmd_t minicmd)
79 static int firesat_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
81 struct firesat *firesat = fe->sec_priv;
87 static int firesat_set_voltage(struct dvb_frontend *fe,
88 fe_sec_voltage_t voltage)
90 struct firesat *firesat = fe->sec_priv;
92 firesat->voltage = voltage;
96 static int firesat_read_status (struct dvb_frontend *fe, fe_status_t *status)
98 struct firesat *firesat = fe->sec_priv;
99 ANTENNA_INPUT_INFO info;
101 if (AVCTunerStatus(firesat, &info))
107 *status = FE_HAS_SIGNAL |
117 static int firesat_read_ber(struct dvb_frontend *fe, u32 *ber)
119 struct firesat *firesat = fe->sec_priv;
120 ANTENNA_INPUT_INFO info;
122 if (AVCTunerStatus(firesat, &info))
125 *ber = (info.BER[0] << 24) |
126 (info.BER[1] << 16) |
133 static int firesat_read_signal_strength (struct dvb_frontend *fe, u16 *strength)
135 struct firesat *firesat = fe->sec_priv;
136 ANTENNA_INPUT_INFO info;
138 if (AVCTunerStatus(firesat, &info))
141 *strength = info.SignalStrength << 8;
146 static int firesat_read_snr(struct dvb_frontend *fe, u16 *snr)
148 struct firesat *firesat = fe->sec_priv;
149 ANTENNA_INPUT_INFO info;
151 if (AVCTunerStatus(firesat, &info))
154 *snr = (info.CarrierNoiseRatio[0] << 8) +
155 info.CarrierNoiseRatio[1];
157 // C/N[dB] = -10 * log10(snr / 65535)
162 static int firesat_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
167 static int firesat_set_frontend(struct dvb_frontend *fe,
168 struct dvb_frontend_parameters *params)
170 struct firesat *firesat = fe->sec_priv;
172 if (AVCTuner_DSD(firesat, params, NULL) != ACCEPTED)
175 return 0; //not sure of this...
178 static int firesat_get_frontend(struct dvb_frontend *fe,
179 struct dvb_frontend_parameters *params)
184 static struct dvb_frontend_info firesat_S_frontend_info;
185 static struct dvb_frontend_info firesat_C_frontend_info;
186 static struct dvb_frontend_info firesat_T_frontend_info;
188 static struct dvb_frontend_ops firesat_ops = {
190 .init = firesat_dvb_init,
191 .sleep = firesat_sleep,
193 .set_frontend = firesat_set_frontend,
194 .get_frontend = firesat_get_frontend,
196 .read_status = firesat_read_status,
197 .read_ber = firesat_read_ber,
198 .read_signal_strength = firesat_read_signal_strength,
199 .read_snr = firesat_read_snr,
200 .read_ucblocks = firesat_read_uncorrected_blocks,
202 .diseqc_send_master_cmd = firesat_diseqc_send_master_cmd,
203 .diseqc_send_burst = firesat_diseqc_send_burst,
204 .set_tone = firesat_set_tone,
205 .set_voltage = firesat_set_voltage,
208 int firesat_frontend_attach(struct firesat *firesat, struct dvb_frontend *fe)
210 switch (firesat->type) {
212 firesat->model_name = "FireSAT DVB-S";
213 firesat->frontend_info = &firesat_S_frontend_info;
216 firesat->model_name = "FireSAT DVB-C";
217 firesat->frontend_info = &firesat_C_frontend_info;
220 firesat->model_name = "FireSAT DVB-T";
221 firesat->frontend_info = &firesat_T_frontend_info;
224 printk("%s: unknown model type 0x%x !\n",
225 __func__, firesat->type);
226 firesat->model_name = "Unknown";
227 firesat->frontend_info = NULL;
229 fe->ops = firesat_ops;
230 fe->ops.info = *(firesat->frontend_info);
231 fe->dvb = firesat->adapter;
236 static struct dvb_frontend_info firesat_S_frontend_info = {
238 .name = "FireSAT DVB-S Frontend",
241 .frequency_min = 950000,
242 .frequency_max = 2150000,
243 .frequency_stepsize = 125,
244 .symbol_rate_min = 1000000,
245 .symbol_rate_max = 40000000,
247 .caps = FE_CAN_INVERSION_AUTO |
257 static struct dvb_frontend_info firesat_C_frontend_info = {
259 .name = "FireSAT DVB-C Frontend",
262 .frequency_min = 47000000,
263 .frequency_max = 866000000,
264 .frequency_stepsize = 62500,
265 .symbol_rate_min = 870000,
266 .symbol_rate_max = 6900000,
268 .caps = FE_CAN_INVERSION_AUTO |
277 static struct dvb_frontend_info firesat_T_frontend_info = {
279 .name = "FireSAT DVB-T Frontend",
282 .frequency_min = 49000000,
283 .frequency_max = 861000000,
284 .frequency_stepsize = 62500,
286 .caps = FE_CAN_INVERSION_AUTO |
288 FE_CAN_TRANSMISSION_MODE_AUTO |
289 FE_CAN_GUARD_INTERVAL_AUTO |
290 FE_CAN_HIERARCHY_AUTO,