blob: 6fe9793b98b3cfe19dfc22f664c3696ad78d71f3 [file] [log] [blame]
Rambaldia70f81c2009-01-17 14:47:34 +01001/*
2 * FireDTV driver (formerly known as FireSAT)
3 *
4 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
5 * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
6 *
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.
11 */
12
Stefan Richter15490792009-02-23 14:21:10 +010013#include <linux/device.h>
Rambaldia70f81c2009-01-17 14:47:34 +010014#include <linux/errno.h>
15#include <linux/kernel.h>
16#include <linux/string.h>
17#include <linux/types.h>
18
19#include <dvb_frontend.h>
20
Rambaldia70f81c2009-01-17 14:47:34 +010021#include "firedtv.h"
22
23static int fdtv_dvb_init(struct dvb_frontend *fe)
24{
25 struct firedtv *fdtv = fe->sec_priv;
26 int err;
27
28 /* FIXME - allocate free channel at IRM */
29 fdtv->isochannel = fdtv->adapter.num;
30
31 err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
32 fdtv->isochannel);
33 if (err) {
Stefan Richter15490792009-02-23 14:21:10 +010034 dev_err(fdtv->device,
35 "could not establish point to point connection\n");
Rambaldia70f81c2009-01-17 14:47:34 +010036 return err;
37 }
38
Stefan Richter92374e82011-02-06 11:41:44 -030039 return fdtv_start_iso(fdtv);
Rambaldia70f81c2009-01-17 14:47:34 +010040}
41
42static int fdtv_sleep(struct dvb_frontend *fe)
43{
44 struct firedtv *fdtv = fe->sec_priv;
45
Stefan Richter92374e82011-02-06 11:41:44 -030046 fdtv_stop_iso(fdtv);
Rambaldia70f81c2009-01-17 14:47:34 +010047 cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
48 fdtv->isochannel = -1;
49 return 0;
50}
51
Stefan Richter15490792009-02-23 14:21:10 +010052#define LNBCONTROL_DONTCARE 0xff
53
Rambaldia70f81c2009-01-17 14:47:34 +010054static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe,
Stefan Richter15490792009-02-23 14:21:10 +010055 struct dvb_diseqc_master_cmd *cmd)
Rambaldia70f81c2009-01-17 14:47:34 +010056{
57 struct firedtv *fdtv = fe->sec_priv;
58
Stefan Richter15490792009-02-23 14:21:10 +010059 return avc_lnb_control(fdtv, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
60 LNBCONTROL_DONTCARE, 1, cmd);
Rambaldia70f81c2009-01-17 14:47:34 +010061}
62
63static int fdtv_diseqc_send_burst(struct dvb_frontend *fe,
Stefan Richter15490792009-02-23 14:21:10 +010064 fe_sec_mini_cmd_t minicmd)
Rambaldia70f81c2009-01-17 14:47:34 +010065{
66 return 0;
67}
68
69static int fdtv_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
70{
71 struct firedtv *fdtv = fe->sec_priv;
72
73 fdtv->tone = tone;
74 return 0;
75}
76
77static int fdtv_set_voltage(struct dvb_frontend *fe,
Stefan Richter15490792009-02-23 14:21:10 +010078 fe_sec_voltage_t voltage)
Rambaldia70f81c2009-01-17 14:47:34 +010079{
80 struct firedtv *fdtv = fe->sec_priv;
81
82 fdtv->voltage = voltage;
83 return 0;
84}
85
86static int fdtv_read_status(struct dvb_frontend *fe, fe_status_t *status)
87{
88 struct firedtv *fdtv = fe->sec_priv;
Stefan Richter15490792009-02-23 14:21:10 +010089 struct firedtv_tuner_status stat;
Rambaldia70f81c2009-01-17 14:47:34 +010090
Stefan Richter15490792009-02-23 14:21:10 +010091 if (avc_tuner_status(fdtv, &stat))
Rambaldia70f81c2009-01-17 14:47:34 +010092 return -EINVAL;
93
Stefan Richter15490792009-02-23 14:21:10 +010094 if (stat.no_rf)
Rambaldia70f81c2009-01-17 14:47:34 +010095 *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;
100}
101
102static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber)
103{
104 struct firedtv *fdtv = fe->sec_priv;
Stefan Richter15490792009-02-23 14:21:10 +0100105 struct firedtv_tuner_status stat;
Rambaldia70f81c2009-01-17 14:47:34 +0100106
Stefan Richter15490792009-02-23 14:21:10 +0100107 if (avc_tuner_status(fdtv, &stat))
Rambaldia70f81c2009-01-17 14:47:34 +0100108 return -EINVAL;
109
Stefan Richter15490792009-02-23 14:21:10 +0100110 *ber = stat.ber;
Rambaldia70f81c2009-01-17 14:47:34 +0100111 return 0;
112}
113
Stefan Richter15490792009-02-23 14:21:10 +0100114static int fdtv_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
Rambaldia70f81c2009-01-17 14:47:34 +0100115{
116 struct firedtv *fdtv = fe->sec_priv;
Stefan Richter15490792009-02-23 14:21:10 +0100117 struct firedtv_tuner_status stat;
Rambaldia70f81c2009-01-17 14:47:34 +0100118
Stefan Richter15490792009-02-23 14:21:10 +0100119 if (avc_tuner_status(fdtv, &stat))
Rambaldia70f81c2009-01-17 14:47:34 +0100120 return -EINVAL;
121
Stefan Richter15490792009-02-23 14:21:10 +0100122 *strength = stat.signal_strength << 8;
Rambaldia70f81c2009-01-17 14:47:34 +0100123 return 0;
124}
125
126static int fdtv_read_snr(struct dvb_frontend *fe, u16 *snr)
127{
128 struct firedtv *fdtv = fe->sec_priv;
Stefan Richter15490792009-02-23 14:21:10 +0100129 struct firedtv_tuner_status stat;
Rambaldia70f81c2009-01-17 14:47:34 +0100130
Stefan Richter15490792009-02-23 14:21:10 +0100131 if (avc_tuner_status(fdtv, &stat))
Rambaldia70f81c2009-01-17 14:47:34 +0100132 return -EINVAL;
133
134 /* C/N[dB] = -10 * log10(snr / 65535) */
Stefan Richter15490792009-02-23 14:21:10 +0100135 *snr = stat.carrier_noise_ratio * 257;
Rambaldia70f81c2009-01-17 14:47:34 +0100136 return 0;
137}
138
139static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
140{
141 return -EOPNOTSUPP;
142}
143
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300144static int fdtv_set_frontend(struct dvb_frontend *fe)
Rambaldia70f81c2009-01-17 14:47:34 +0100145{
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300146 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
Rambaldia70f81c2009-01-17 14:47:34 +0100147 struct firedtv *fdtv = fe->sec_priv;
148
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300149 return avc_tuner_dsd(fdtv, p);
Rambaldia70f81c2009-01-17 14:47:34 +0100150}
151
Stefan Richter92374e82011-02-06 11:41:44 -0300152void fdtv_frontend_init(struct firedtv *fdtv, const char *name)
Rambaldia70f81c2009-01-17 14:47:34 +0100153{
154 struct dvb_frontend_ops *ops = &fdtv->fe.ops;
155 struct dvb_frontend_info *fi = &ops->info;
156
157 ops->init = fdtv_dvb_init;
158 ops->sleep = fdtv_sleep;
159
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300160 ops->set_frontend = fdtv_set_frontend;
Tommy Jonssond2fd44a2010-09-12 16:03:45 -0300161
Rambaldia70f81c2009-01-17 14:47:34 +0100162 ops->read_status = fdtv_read_status;
163 ops->read_ber = fdtv_read_ber;
164 ops->read_signal_strength = fdtv_read_signal_strength;
165 ops->read_snr = fdtv_read_snr;
166 ops->read_ucblocks = fdtv_read_uncorrected_blocks;
167
168 ops->diseqc_send_master_cmd = fdtv_diseqc_send_master_cmd;
169 ops->diseqc_send_burst = fdtv_diseqc_send_burst;
170 ops->set_tone = fdtv_set_tone;
171 ops->set_voltage = fdtv_set_voltage;
172
173 switch (fdtv->type) {
174 case FIREDTV_DVB_S:
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300175 ops->delsys[0] = SYS_DVBS;
Tommy Jonssond2fd44a2010-09-12 16:03:45 -0300176
177 fi->frequency_min = 950000;
178 fi->frequency_max = 2150000;
179 fi->frequency_stepsize = 125;
180 fi->symbol_rate_min = 1000000;
181 fi->symbol_rate_max = 40000000;
182
183 fi->caps = FE_CAN_INVERSION_AUTO |
184 FE_CAN_FEC_1_2 |
185 FE_CAN_FEC_2_3 |
186 FE_CAN_FEC_3_4 |
187 FE_CAN_FEC_5_6 |
188 FE_CAN_FEC_7_8 |
189 FE_CAN_FEC_AUTO |
190 FE_CAN_QPSK;
191 break;
192
Beat Michel Liechtie73bf9f2009-02-24 15:52:49 +0100193 case FIREDTV_DVB_S2:
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300194 ops->delsys[0] = SYS_DVBS;
Mauro Carvalho Chehab6225f182012-01-04 23:10:19 -0200195 ops->delsys[1] = SYS_DVBS2;
Rambaldia70f81c2009-01-17 14:47:34 +0100196
197 fi->frequency_min = 950000;
198 fi->frequency_max = 2150000;
199 fi->frequency_stepsize = 125;
200 fi->symbol_rate_min = 1000000;
201 fi->symbol_rate_max = 40000000;
202
Tommy Jonssond2fd44a2010-09-12 16:03:45 -0300203 fi->caps = FE_CAN_INVERSION_AUTO |
204 FE_CAN_FEC_1_2 |
205 FE_CAN_FEC_2_3 |
206 FE_CAN_FEC_3_4 |
207 FE_CAN_FEC_5_6 |
208 FE_CAN_FEC_7_8 |
209 FE_CAN_FEC_AUTO |
210 FE_CAN_QPSK |
211 FE_CAN_2G_MODULATION;
Rambaldia70f81c2009-01-17 14:47:34 +0100212 break;
213
214 case FIREDTV_DVB_C:
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300215 ops->delsys[0] = SYS_DVBC_ANNEX_A;
Rambaldia70f81c2009-01-17 14:47:34 +0100216
217 fi->frequency_min = 47000000;
218 fi->frequency_max = 866000000;
219 fi->frequency_stepsize = 62500;
220 fi->symbol_rate_min = 870000;
221 fi->symbol_rate_max = 6900000;
222
223 fi->caps = FE_CAN_INVERSION_AUTO |
224 FE_CAN_QAM_16 |
225 FE_CAN_QAM_32 |
226 FE_CAN_QAM_64 |
227 FE_CAN_QAM_128 |
228 FE_CAN_QAM_256 |
229 FE_CAN_QAM_AUTO;
230 break;
231
232 case FIREDTV_DVB_T:
Mauro Carvalho Chehabe11eb282011-12-26 16:12:40 -0300233 ops->delsys[0] = SYS_DVBT;
Rambaldia70f81c2009-01-17 14:47:34 +0100234
235 fi->frequency_min = 49000000;
236 fi->frequency_max = 861000000;
237 fi->frequency_stepsize = 62500;
238
239 fi->caps = FE_CAN_INVERSION_AUTO |
240 FE_CAN_FEC_2_3 |
241 FE_CAN_TRANSMISSION_MODE_AUTO |
242 FE_CAN_GUARD_INTERVAL_AUTO |
243 FE_CAN_HIERARCHY_AUTO;
244 break;
245
246 default:
Stefan Richter15490792009-02-23 14:21:10 +0100247 dev_err(fdtv->device, "no frontend for model type %d\n",
248 fdtv->type);
Rambaldia70f81c2009-01-17 14:47:34 +0100249 }
Stefan Richter92374e82011-02-06 11:41:44 -0300250 strcpy(fi->name, name);
Rambaldia70f81c2009-01-17 14:47:34 +0100251
252 fdtv->fe.dvb = &fdtv->adapter;
253 fdtv->fe.sec_priv = fdtv;
254}