treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / media / firewire / firedtv-fe.c
bloba73c1aefdbe611c68c76d804ec06e769d5ec432a
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
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>
7 */
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>
17 #include "firedtv.h"
19 static int fdtv_dvb_init(struct dvb_frontend *fe)
21 struct firedtv *fdtv = fe->sec_priv;
22 int err;
24 /* FIXME - allocate free channel at IRM */
25 fdtv->isochannel = fdtv->adapter.num;
27 err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
28 fdtv->isochannel);
29 if (err) {
30 dev_err(fdtv->device,
31 "could not establish point to point connection\n");
32 return err;
35 return fdtv_start_iso(fdtv);
38 static int fdtv_sleep(struct dvb_frontend *fe)
40 struct firedtv *fdtv = fe->sec_priv;
42 fdtv_stop_iso(fdtv);
43 cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
44 fdtv->isochannel = -1;
45 return 0;
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)
62 return 0;
65 static int fdtv_set_tone(struct dvb_frontend *fe, enum fe_sec_tone_mode tone)
67 struct firedtv *fdtv = fe->sec_priv;
69 fdtv->tone = tone;
70 return 0;
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;
79 return 0;
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))
88 return -EINVAL;
90 if (stat.no_rf)
91 *status = 0;
92 else
93 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
94 FE_HAS_CARRIER | FE_HAS_LOCK;
95 return 0;
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))
104 return -EINVAL;
106 *ber = stat.ber;
107 return 0;
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))
116 return -EINVAL;
118 *strength = stat.signal_strength << 8;
119 return 0;
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))
128 return -EINVAL;
130 /* C/N[dB] = -10 * log10(snr / 65535) */
131 *snr = stat.carrier_noise_ratio * 257;
132 return 0;
135 static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
137 return -EOPNOTSUPP;
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) {
170 case FIREDTV_DVB_S:
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 |
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;
187 break;
189 case FIREDTV_DVB_S2:
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 |
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;
210 case FIREDTV_DVB_C:
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 |
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;
226 break;
228 case FIREDTV_DVB_T:
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 |
236 FE_CAN_FEC_2_3 |
237 FE_CAN_TRANSMISSION_MODE_AUTO |
238 FE_CAN_GUARD_INTERVAL_AUTO |
239 FE_CAN_HIERARCHY_AUTO;
240 break;
242 default:
243 dev_err(fdtv->device, "no frontend for model type %d\n",
244 fdtv->type);
246 strscpy(fi->name, name, sizeof(fi->name));
248 fdtv->fe.dvb = &fdtv->adapter;
249 fdtv->fe.sec_priv = fdtv;