]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - drivers/media/firewire/firedtv-fe.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 152
[mirror_ubuntu-focal-kernel.git] / drivers / media / firewire / firedtv-fe.c
CommitLineData
2874c5fd 1// SPDX-License-Identifier: GPL-2.0-or-later
df4846c3 2/*
612262a5 3 * FireDTV driver (formerly known as FireSAT)
df4846c3 4 *
612262a5
SR
5 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
6 * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
df4846c3
HK
7 */
8
15490795 9#include <linux/device.h>
c81c8b68 10#include <linux/errno.h>
612262a5 11#include <linux/kernel.h>
8ae83cdf 12#include <linux/string.h>
612262a5
SR
13#include <linux/types.h>
14
fada1935 15#include <media/dvb_frontend.h>
c81c8b68 16
a70f81c1 17#include "firedtv.h"
c81c8b68 18
a70f81c1 19static int fdtv_dvb_init(struct dvb_frontend *fe)
c81c8b68 20{
a70f81c1 21 struct firedtv *fdtv = fe->sec_priv;
8ae83cdf
SR
22 int err;
23
24 /* FIXME - allocate free channel at IRM */
a70f81c1 25 fdtv->isochannel = fdtv->adapter.num;
8ae83cdf 26
a70f81c1
R
27 err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
28 fdtv->isochannel);
8ae83cdf 29 if (err) {
15490795
SR
30 dev_err(fdtv->device,
31 "could not establish point to point connection\n");
8ae83cdf 32 return err;
df4846c3 33 }
df4846c3 34
92374e88 35 return fdtv_start_iso(fdtv);
c81c8b68
GKH
36}
37
a70f81c1 38static int fdtv_sleep(struct dvb_frontend *fe)
c81c8b68 39{
a70f81c1 40 struct firedtv *fdtv = fe->sec_priv;
c81c8b68 41
92374e88 42 fdtv_stop_iso(fdtv);
a70f81c1
R
43 cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
44 fdtv->isochannel = -1;
c81c8b68
GKH
45 return 0;
46}
47
15490795
SR
48#define LNBCONTROL_DONTCARE 0xff
49
a70f81c1 50static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe,
15490795 51 struct dvb_diseqc_master_cmd *cmd)
c81c8b68 52{
a70f81c1 53 struct firedtv *fdtv = fe->sec_priv;
c81c8b68 54
15490795
SR
55 return avc_lnb_control(fdtv, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
56 LNBCONTROL_DONTCARE, 1, cmd);
c81c8b68
GKH
57}
58
a70f81c1 59static int fdtv_diseqc_send_burst(struct dvb_frontend *fe,
0df289a2 60 enum fe_sec_mini_cmd minicmd)
c81c8b68
GKH
61{
62 return 0;
63}
64
0df289a2 65static int fdtv_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
c81c8b68 66{
a70f81c1 67 struct firedtv *fdtv = fe->sec_priv;
c81c8b68 68
a70f81c1 69 fdtv->tone = tone;
c81c8b68
GKH
70 return 0;
71}
72
a70f81c1 73static int fdtv_set_voltage(struct dvb_frontend *fe,
0df289a2 74 enum fe_sec_voltage voltage)
c81c8b68 75{
a70f81c1 76 struct firedtv *fdtv = fe->sec_priv;
c81c8b68 77
a70f81c1 78 fdtv->voltage = voltage;
c81c8b68
GKH
79 return 0;
80}
81
0df289a2 82static int fdtv_read_status(struct dvb_frontend *fe, enum fe_status *status)
c81c8b68 83{
a70f81c1 84 struct firedtv *fdtv = fe->sec_priv;
15490795 85 struct firedtv_tuner_status stat;
c81c8b68 86
15490795 87 if (avc_tuner_status(fdtv, &stat))
c81c8b68
GKH
88 return -EINVAL;
89
15490795 90 if (stat.no_rf)
c81c8b68 91 *status = 0;
8ae83cdf
SR
92 else
93 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
94 FE_HAS_CARRIER | FE_HAS_LOCK;
c81c8b68
GKH
95 return 0;
96}
97
a70f81c1 98static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber)
c81c8b68 99{
a70f81c1 100 struct firedtv *fdtv = fe->sec_priv;
15490795 101 struct firedtv_tuner_status stat;
c81c8b68 102
15490795 103 if (avc_tuner_status(fdtv, &stat))
c81c8b68
GKH
104 return -EINVAL;
105
15490795 106 *ber = stat.ber;
c81c8b68
GKH
107 return 0;
108}
109
15490795 110static int fdtv_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
c81c8b68 111{
a70f81c1 112 struct firedtv *fdtv = fe->sec_priv;
15490795 113 struct firedtv_tuner_status stat;
c81c8b68 114
15490795 115 if (avc_tuner_status(fdtv, &stat))
c81c8b68
GKH
116 return -EINVAL;
117
15490795 118 *strength = stat.signal_strength << 8;
c81c8b68
GKH
119 return 0;
120}
121
a70f81c1 122static int fdtv_read_snr(struct dvb_frontend *fe, u16 *snr)
c81c8b68 123{
a70f81c1 124 struct firedtv *fdtv = fe->sec_priv;
15490795 125 struct firedtv_tuner_status stat;
df4846c3 126
15490795 127 if (avc_tuner_status(fdtv, &stat))
df4846c3
HK
128 return -EINVAL;
129
8ae83cdf 130 /* C/N[dB] = -10 * log10(snr / 65535) */
15490795 131 *snr = stat.carrier_noise_ratio * 257;
df4846c3 132 return 0;
c81c8b68
GKH
133}
134
a70f81c1 135static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
c81c8b68
GKH
136{
137 return -EOPNOTSUPP;
138}
139
e11eb288 140static int fdtv_set_frontend(struct dvb_frontend *fe)
c81c8b68 141{
e11eb288 142 struct dtv_frontend_properties *p = &fe->dtv_property_cache;
a70f81c1 143 struct firedtv *fdtv = fe->sec_priv;
c81c8b68 144
e11eb288 145 return avc_tuner_dsd(fdtv, p);
c81c8b68
GKH
146}
147
92374e88 148void fdtv_frontend_init(struct firedtv *fdtv, const char *name)
8ae83cdf 149{
a70f81c1 150 struct dvb_frontend_ops *ops = &fdtv->fe.ops;
f1b1eabf 151 struct dvb_frontend_internal_info *fi = &ops->info;
c81c8b68 152
a70f81c1
R
153 ops->init = fdtv_dvb_init;
154 ops->sleep = fdtv_sleep;
c81c8b68 155
e11eb288 156 ops->set_frontend = fdtv_set_frontend;
d2fd44a3 157
a70f81c1
R
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;
c81c8b68 163
6e6a8b5a 164 ops->diseqc_send_master_cmd = fdtv_diseqc_send_master_cmd;
a70f81c1
R
165 ops->diseqc_send_burst = fdtv_diseqc_send_burst;
166 ops->set_tone = fdtv_set_tone;
167 ops->set_voltage = fdtv_set_voltage;
c81c8b68 168
a70f81c1
R
169 switch (fdtv->type) {
170 case FIREDTV_DVB_S:
e11eb288 171 ops->delsys[0] = SYS_DVBS;
8ae83cdf 172
f1b1eabf
MCC
173 fi->frequency_min_hz = 950 * MHz;
174 fi->frequency_max_hz = 2150 * MHz;
175 fi->frequency_stepsize_hz = 125 * kHz;
8ae83cdf
SR
176 fi->symbol_rate_min = 1000000;
177 fi->symbol_rate_max = 40000000;
178
d2fd44a3 179 fi->caps = FE_CAN_INVERSION_AUTO |
8ae83cdf
SR
180 FE_CAN_FEC_1_2 |
181 FE_CAN_FEC_2_3 |
182 FE_CAN_FEC_3_4 |
183 FE_CAN_FEC_5_6 |
184 FE_CAN_FEC_7_8 |
185 FE_CAN_FEC_AUTO |
186 FE_CAN_QPSK;
c81c8b68 187 break;
8ae83cdf 188
d2fd44a3 189 case FIREDTV_DVB_S2:
e11eb288 190 ops->delsys[0] = SYS_DVBS;
6225f18b 191 ops->delsys[1] = SYS_DVBS2;
d2fd44a3 192
f1b1eabf
MCC
193 fi->frequency_min_hz = 950 * MHz;
194 fi->frequency_max_hz = 2150 * MHz;
195 fi->frequency_stepsize_hz = 125 * kHz;
d2fd44a3
TJ
196 fi->symbol_rate_min = 1000000;
197 fi->symbol_rate_max = 40000000;
198
199 fi->caps = FE_CAN_INVERSION_AUTO |
200 FE_CAN_FEC_1_2 |
201 FE_CAN_FEC_2_3 |
202 FE_CAN_FEC_3_4 |
203 FE_CAN_FEC_5_6 |
204 FE_CAN_FEC_7_8 |
205 FE_CAN_FEC_AUTO |
206 FE_CAN_QPSK |
207 FE_CAN_2G_MODULATION;
208 break;
209
a70f81c1 210 case FIREDTV_DVB_C:
e11eb288 211 ops->delsys[0] = SYS_DVBC_ANNEX_A;
8ae83cdf 212
f1b1eabf
MCC
213 fi->frequency_min_hz = 47 * MHz;
214 fi->frequency_max_hz = 866 * MHz;
215 fi->frequency_stepsize_hz = 62500;
8ae83cdf
SR
216 fi->symbol_rate_min = 870000;
217 fi->symbol_rate_max = 6900000;
218
6e6a8b5a 219 fi->caps = FE_CAN_INVERSION_AUTO |
8ae83cdf
SR
220 FE_CAN_QAM_16 |
221 FE_CAN_QAM_32 |
222 FE_CAN_QAM_64 |
223 FE_CAN_QAM_128 |
224 FE_CAN_QAM_256 |
225 FE_CAN_QAM_AUTO;
c81c8b68 226 break;
8ae83cdf 227
a70f81c1 228 case FIREDTV_DVB_T:
e11eb288 229 ops->delsys[0] = SYS_DVBT;
8ae83cdf 230
f1b1eabf
MCC
231 fi->frequency_min_hz = 49 * MHz;
232 fi->frequency_max_hz = 861 * MHz;
233 fi->frequency_stepsize_hz = 62500;
8ae83cdf 234
6e6a8b5a 235 fi->caps = FE_CAN_INVERSION_AUTO |
8ae83cdf
SR
236 FE_CAN_FEC_2_3 |
237 FE_CAN_TRANSMISSION_MODE_AUTO |
238 FE_CAN_GUARD_INTERVAL_AUTO |
239 FE_CAN_HIERARCHY_AUTO;
c81c8b68 240 break;
8ae83cdf 241
c81c8b68 242 default:
15490795
SR
243 dev_err(fdtv->device, "no frontend for model type %d\n",
244 fdtv->type);
c81c8b68 245 }
cc1e6315 246 strscpy(fi->name, name, sizeof(fi->name));
c81c8b68 247
a70f81c1
R
248 fdtv->fe.dvb = &fdtv->adapter;
249 fdtv->fe.sec_priv = fdtv;
c81c8b68 250}