1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * FireDTV driver (formerly known as FireSAT)
5 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
6 * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
9 #include <linux/device.h>
10 #include <linux/errno.h>
11 #include <linux/kernel.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
15 #include <media/dvb_frontend.h>
19 static int fdtv_dvb_init(struct dvb_frontend
*fe
)
21 struct firedtv
*fdtv
= fe
->sec_priv
;
24 /* FIXME - allocate free channel at IRM */
25 fdtv
->isochannel
= fdtv
->adapter
.num
;
27 err
= cmp_establish_pp_connection(fdtv
, fdtv
->subunit
,
31 "could not establish point to point connection\n");
35 return fdtv_start_iso(fdtv
);
38 static int fdtv_sleep(struct dvb_frontend
*fe
)
40 struct firedtv
*fdtv
= fe
->sec_priv
;
43 cmp_break_pp_connection(fdtv
, fdtv
->subunit
, fdtv
->isochannel
);
44 fdtv
->isochannel
= -1;
48 #define LNBCONTROL_DONTCARE 0xff
50 static int fdtv_diseqc_send_master_cmd(struct dvb_frontend
*fe
,
51 struct dvb_diseqc_master_cmd
*cmd
)
53 struct firedtv
*fdtv
= fe
->sec_priv
;
55 return avc_lnb_control(fdtv
, LNBCONTROL_DONTCARE
, LNBCONTROL_DONTCARE
,
56 LNBCONTROL_DONTCARE
, 1, cmd
);
59 static int fdtv_diseqc_send_burst(struct dvb_frontend
*fe
,
60 enum fe_sec_mini_cmd minicmd
)
65 static int fdtv_set_tone(struct dvb_frontend
*fe
, enum fe_sec_tone_mode tone
)
67 struct firedtv
*fdtv
= fe
->sec_priv
;
73 static int fdtv_set_voltage(struct dvb_frontend
*fe
,
74 enum fe_sec_voltage voltage
)
76 struct firedtv
*fdtv
= fe
->sec_priv
;
78 fdtv
->voltage
= voltage
;
82 static int fdtv_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
84 struct firedtv
*fdtv
= fe
->sec_priv
;
85 struct firedtv_tuner_status stat
;
87 if (avc_tuner_status(fdtv
, &stat
))
93 *status
= FE_HAS_SIGNAL
| FE_HAS_VITERBI
| FE_HAS_SYNC
|
94 FE_HAS_CARRIER
| FE_HAS_LOCK
;
98 static int fdtv_read_ber(struct dvb_frontend
*fe
, u32
*ber
)
100 struct firedtv
*fdtv
= fe
->sec_priv
;
101 struct firedtv_tuner_status stat
;
103 if (avc_tuner_status(fdtv
, &stat
))
110 static int fdtv_read_signal_strength(struct dvb_frontend
*fe
, u16
*strength
)
112 struct firedtv
*fdtv
= fe
->sec_priv
;
113 struct firedtv_tuner_status stat
;
115 if (avc_tuner_status(fdtv
, &stat
))
118 *strength
= stat
.signal_strength
<< 8;
122 static int fdtv_read_snr(struct dvb_frontend
*fe
, u16
*snr
)
124 struct firedtv
*fdtv
= fe
->sec_priv
;
125 struct firedtv_tuner_status stat
;
127 if (avc_tuner_status(fdtv
, &stat
))
130 /* C/N[dB] = -10 * log10(snr / 65535) */
131 *snr
= stat
.carrier_noise_ratio
* 257;
135 static int fdtv_read_uncorrected_blocks(struct dvb_frontend
*fe
, u32
*ucblocks
)
140 static int fdtv_set_frontend(struct dvb_frontend
*fe
)
142 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
143 struct firedtv
*fdtv
= fe
->sec_priv
;
145 return avc_tuner_dsd(fdtv
, p
);
148 void fdtv_frontend_init(struct firedtv
*fdtv
, const char *name
)
150 struct dvb_frontend_ops
*ops
= &fdtv
->fe
.ops
;
151 struct dvb_frontend_internal_info
*fi
= &ops
->info
;
153 ops
->init
= fdtv_dvb_init
;
154 ops
->sleep
= fdtv_sleep
;
156 ops
->set_frontend
= fdtv_set_frontend
;
158 ops
->read_status
= fdtv_read_status
;
159 ops
->read_ber
= fdtv_read_ber
;
160 ops
->read_signal_strength
= fdtv_read_signal_strength
;
161 ops
->read_snr
= fdtv_read_snr
;
162 ops
->read_ucblocks
= fdtv_read_uncorrected_blocks
;
164 ops
->diseqc_send_master_cmd
= fdtv_diseqc_send_master_cmd
;
165 ops
->diseqc_send_burst
= fdtv_diseqc_send_burst
;
166 ops
->set_tone
= fdtv_set_tone
;
167 ops
->set_voltage
= fdtv_set_voltage
;
169 switch (fdtv
->type
) {
171 ops
->delsys
[0] = SYS_DVBS
;
173 fi
->frequency_min_hz
= 950 * MHz
;
174 fi
->frequency_max_hz
= 2150 * MHz
;
175 fi
->frequency_stepsize_hz
= 125 * kHz
;
176 fi
->symbol_rate_min
= 1000000;
177 fi
->symbol_rate_max
= 40000000;
179 fi
->caps
= FE_CAN_INVERSION_AUTO
|
190 ops
->delsys
[0] = SYS_DVBS
;
191 ops
->delsys
[1] = SYS_DVBS2
;
193 fi
->frequency_min_hz
= 950 * MHz
;
194 fi
->frequency_max_hz
= 2150 * MHz
;
195 fi
->frequency_stepsize_hz
= 125 * kHz
;
196 fi
->symbol_rate_min
= 1000000;
197 fi
->symbol_rate_max
= 40000000;
199 fi
->caps
= FE_CAN_INVERSION_AUTO
|
207 FE_CAN_2G_MODULATION
;
211 ops
->delsys
[0] = SYS_DVBC_ANNEX_A
;
213 fi
->frequency_min_hz
= 47 * MHz
;
214 fi
->frequency_max_hz
= 866 * MHz
;
215 fi
->frequency_stepsize_hz
= 62500;
216 fi
->symbol_rate_min
= 870000;
217 fi
->symbol_rate_max
= 6900000;
219 fi
->caps
= FE_CAN_INVERSION_AUTO
|
229 ops
->delsys
[0] = SYS_DVBT
;
231 fi
->frequency_min_hz
= 49 * MHz
;
232 fi
->frequency_max_hz
= 861 * MHz
;
233 fi
->frequency_stepsize_hz
= 62500;
235 fi
->caps
= FE_CAN_INVERSION_AUTO
|
237 FE_CAN_TRANSMISSION_MODE_AUTO
|
238 FE_CAN_GUARD_INTERVAL_AUTO
|
239 FE_CAN_HIERARCHY_AUTO
;
243 dev_err(fdtv
->device
, "no frontend for model type %d\n",
246 strscpy(fi
->name
, name
, sizeof(fi
->name
));
248 fdtv
->fe
.dvb
= &fdtv
->adapter
;
249 fdtv
->fe
.sec_priv
= fdtv
;