firedtv-fe.c 6.2 KB
Newer Older
1
/*
2
 * FireDTV driver (formerly known as FireSAT)
3
 *
4 5
 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
 * Copyright (C) 2008 Henrik Kurelid <henrik@kurelid.se>
6 7 8 9 10 11 12
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation; either version 2 of
 *	the License, or (at your option) any later version.
 */

S
Stefan Richter 已提交
13
#include <linux/device.h>
G
Greg Kroah-Hartman 已提交
14
#include <linux/errno.h>
15
#include <linux/kernel.h>
16
#include <linux/string.h>
17 18 19
#include <linux/types.h>

#include <dvb_frontend.h>
G
Greg Kroah-Hartman 已提交
20

21
#include "firedtv.h"
G
Greg Kroah-Hartman 已提交
22

23
static int fdtv_dvb_init(struct dvb_frontend *fe)
G
Greg Kroah-Hartman 已提交
24
{
25
	struct firedtv *fdtv = fe->sec_priv;
26 27 28
	int err;

	/* FIXME - allocate free channel at IRM */
29
	fdtv->isochannel = fdtv->adapter.num;
30

31 32
	err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
					  fdtv->isochannel);
33
	if (err) {
S
Stefan Richter 已提交
34 35
		dev_err(fdtv->device,
			"could not establish point to point connection\n");
36
		return err;
37 38
	}

39
	return fdtv_start_iso(fdtv);
G
Greg Kroah-Hartman 已提交
40 41
}

42
static int fdtv_sleep(struct dvb_frontend *fe)
G
Greg Kroah-Hartman 已提交
43
{
44
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
45

46
	fdtv_stop_iso(fdtv);
47 48
	cmp_break_pp_connection(fdtv, fdtv->subunit, fdtv->isochannel);
	fdtv->isochannel = -1;
G
Greg Kroah-Hartman 已提交
49 50 51
	return 0;
}

S
Stefan Richter 已提交
52 53
#define LNBCONTROL_DONTCARE 0xff

54
static int fdtv_diseqc_send_master_cmd(struct dvb_frontend *fe,
S
Stefan Richter 已提交
55
				       struct dvb_diseqc_master_cmd *cmd)
G
Greg Kroah-Hartman 已提交
56
{
57
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
58

S
Stefan Richter 已提交
59 60
	return avc_lnb_control(fdtv, LNBCONTROL_DONTCARE, LNBCONTROL_DONTCARE,
			       LNBCONTROL_DONTCARE, 1, cmd);
G
Greg Kroah-Hartman 已提交
61 62
}

63
static int fdtv_diseqc_send_burst(struct dvb_frontend *fe,
S
Stefan Richter 已提交
64
				  fe_sec_mini_cmd_t minicmd)
G
Greg Kroah-Hartman 已提交
65 66 67 68
{
	return 0;
}

69
static int fdtv_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
G
Greg Kroah-Hartman 已提交
70
{
71
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
72

73
	fdtv->tone = tone;
G
Greg Kroah-Hartman 已提交
74 75 76
	return 0;
}

77
static int fdtv_set_voltage(struct dvb_frontend *fe,
S
Stefan Richter 已提交
78
			    fe_sec_voltage_t voltage)
G
Greg Kroah-Hartman 已提交
79
{
80
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
81

82
	fdtv->voltage = voltage;
G
Greg Kroah-Hartman 已提交
83 84 85
	return 0;
}

86
static int fdtv_read_status(struct dvb_frontend *fe, fe_status_t *status)
G
Greg Kroah-Hartman 已提交
87
{
88
	struct firedtv *fdtv = fe->sec_priv;
S
Stefan Richter 已提交
89
	struct firedtv_tuner_status stat;
G
Greg Kroah-Hartman 已提交
90

S
Stefan Richter 已提交
91
	if (avc_tuner_status(fdtv, &stat))
G
Greg Kroah-Hartman 已提交
92 93
		return -EINVAL;

S
Stefan Richter 已提交
94
	if (stat.no_rf)
G
Greg Kroah-Hartman 已提交
95
		*status = 0;
96 97 98
	else
		*status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
			  FE_HAS_CARRIER | FE_HAS_LOCK;
G
Greg Kroah-Hartman 已提交
99 100 101
	return 0;
}

102
static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber)
G
Greg Kroah-Hartman 已提交
103
{
104
	struct firedtv *fdtv = fe->sec_priv;
S
Stefan Richter 已提交
105
	struct firedtv_tuner_status stat;
G
Greg Kroah-Hartman 已提交
106

S
Stefan Richter 已提交
107
	if (avc_tuner_status(fdtv, &stat))
G
Greg Kroah-Hartman 已提交
108 109
		return -EINVAL;

S
Stefan Richter 已提交
110
	*ber = stat.ber;
G
Greg Kroah-Hartman 已提交
111 112 113
	return 0;
}

S
Stefan Richter 已提交
114
static int fdtv_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
G
Greg Kroah-Hartman 已提交
115
{
116
	struct firedtv *fdtv = fe->sec_priv;
S
Stefan Richter 已提交
117
	struct firedtv_tuner_status stat;
G
Greg Kroah-Hartman 已提交
118

S
Stefan Richter 已提交
119
	if (avc_tuner_status(fdtv, &stat))
G
Greg Kroah-Hartman 已提交
120 121
		return -EINVAL;

S
Stefan Richter 已提交
122
	*strength = stat.signal_strength << 8;
G
Greg Kroah-Hartman 已提交
123 124 125
	return 0;
}

126
static int fdtv_read_snr(struct dvb_frontend *fe, u16 *snr)
G
Greg Kroah-Hartman 已提交
127
{
128
	struct firedtv *fdtv = fe->sec_priv;
S
Stefan Richter 已提交
129
	struct firedtv_tuner_status stat;
130

S
Stefan Richter 已提交
131
	if (avc_tuner_status(fdtv, &stat))
132 133
		return -EINVAL;

134
	/* C/N[dB] = -10 * log10(snr / 65535) */
S
Stefan Richter 已提交
135
	*snr = stat.carrier_noise_ratio * 257;
136
	return 0;
G
Greg Kroah-Hartman 已提交
137 138
}

139
static int fdtv_read_uncorrected_blocks(struct dvb_frontend *fe, u32 *ucblocks)
G
Greg Kroah-Hartman 已提交
140 141 142 143
{
	return -EOPNOTSUPP;
}

144
static int fdtv_set_frontend(struct dvb_frontend *fe,
S
Stefan Richter 已提交
145
			     struct dvb_frontend_parameters *params)
G
Greg Kroah-Hartman 已提交
146
{
147
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
148

149
	return avc_tuner_dsd(fdtv, params);
G
Greg Kroah-Hartman 已提交
150 151
}

152
static int fdtv_get_frontend(struct dvb_frontend *fe,
S
Stefan Richter 已提交
153
			     struct dvb_frontend_parameters *params)
G
Greg Kroah-Hartman 已提交
154 155 156 157
{
	return -EOPNOTSUPP;
}

158 159 160 161 162 163 164 165 166 167
static int fdtv_get_property(struct dvb_frontend *fe, struct dtv_property *tvp)
{
	return 0;
}

static int fdtv_set_property(struct dvb_frontend *fe, struct dtv_property *tvp)
{
	return 0;
}

168
void fdtv_frontend_init(struct firedtv *fdtv, const char *name)
169
{
170
	struct dvb_frontend_ops *ops = &fdtv->fe.ops;
171
	struct dvb_frontend_info *fi = &ops->info;
G
Greg Kroah-Hartman 已提交
172

173 174
	ops->init			= fdtv_dvb_init;
	ops->sleep			= fdtv_sleep;
G
Greg Kroah-Hartman 已提交
175

176 177
	ops->set_frontend		= fdtv_set_frontend;
	ops->get_frontend		= fdtv_get_frontend;
G
Greg Kroah-Hartman 已提交
178

179 180 181
	ops->get_property		= fdtv_get_property;
	ops->set_property		= fdtv_set_property;

182 183 184 185 186
	ops->read_status		= fdtv_read_status;
	ops->read_ber			= fdtv_read_ber;
	ops->read_signal_strength	= fdtv_read_signal_strength;
	ops->read_snr			= fdtv_read_snr;
	ops->read_ucblocks		= fdtv_read_uncorrected_blocks;
G
Greg Kroah-Hartman 已提交
187

188 189 190 191
	ops->diseqc_send_master_cmd 	= fdtv_diseqc_send_master_cmd;
	ops->diseqc_send_burst		= fdtv_diseqc_send_burst;
	ops->set_tone			= fdtv_set_tone;
	ops->set_voltage		= fdtv_set_voltage;
G
Greg Kroah-Hartman 已提交
192

193 194
	switch (fdtv->type) {
	case FIREDTV_DVB_S:
195 196 197 198 199 200 201 202
		fi->type		= FE_QPSK;

		fi->frequency_min	= 950000;
		fi->frequency_max	= 2150000;
		fi->frequency_stepsize	= 125;
		fi->symbol_rate_min	= 1000000;
		fi->symbol_rate_max	= 40000000;

203
		fi->caps		= FE_CAN_INVERSION_AUTO |
204 205 206 207 208 209 210
					  FE_CAN_FEC_1_2	|
					  FE_CAN_FEC_2_3	|
					  FE_CAN_FEC_3_4	|
					  FE_CAN_FEC_5_6	|
					  FE_CAN_FEC_7_8	|
					  FE_CAN_FEC_AUTO	|
					  FE_CAN_QPSK;
G
Greg Kroah-Hartman 已提交
211
		break;
212

213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
	case FIREDTV_DVB_S2:
		fi->type		= FE_QPSK;

		fi->frequency_min	= 950000;
		fi->frequency_max	= 2150000;
		fi->frequency_stepsize	= 125;
		fi->symbol_rate_min	= 1000000;
		fi->symbol_rate_max	= 40000000;

		fi->caps		= FE_CAN_INVERSION_AUTO |
					  FE_CAN_FEC_1_2        |
					  FE_CAN_FEC_2_3        |
					  FE_CAN_FEC_3_4        |
					  FE_CAN_FEC_5_6        |
					  FE_CAN_FEC_7_8        |
					  FE_CAN_FEC_AUTO       |
					  FE_CAN_QPSK           |
					  FE_CAN_2G_MODULATION;
		break;

233
	case FIREDTV_DVB_C:
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
		fi->type		= FE_QAM;

		fi->frequency_min	= 47000000;
		fi->frequency_max	= 866000000;
		fi->frequency_stepsize	= 62500;
		fi->symbol_rate_min	= 870000;
		fi->symbol_rate_max	= 6900000;

		fi->caps 		= FE_CAN_INVERSION_AUTO |
					  FE_CAN_QAM_16		|
					  FE_CAN_QAM_32		|
					  FE_CAN_QAM_64		|
					  FE_CAN_QAM_128	|
					  FE_CAN_QAM_256	|
					  FE_CAN_QAM_AUTO;
G
Greg Kroah-Hartman 已提交
249
		break;
250

251
	case FIREDTV_DVB_T:
252 253 254 255 256 257 258 259 260 261 262
		fi->type		= FE_OFDM;

		fi->frequency_min	= 49000000;
		fi->frequency_max	= 861000000;
		fi->frequency_stepsize	= 62500;

		fi->caps 		= FE_CAN_INVERSION_AUTO		|
					  FE_CAN_FEC_2_3		|
					  FE_CAN_TRANSMISSION_MODE_AUTO |
					  FE_CAN_GUARD_INTERVAL_AUTO	|
					  FE_CAN_HIERARCHY_AUTO;
G
Greg Kroah-Hartman 已提交
263
		break;
264

G
Greg Kroah-Hartman 已提交
265
	default:
S
Stefan Richter 已提交
266 267
		dev_err(fdtv->device, "no frontend for model type %d\n",
			fdtv->type);
G
Greg Kroah-Hartman 已提交
268
	}
269
	strcpy(fi->name, name);
G
Greg Kroah-Hartman 已提交
270

271 272
	fdtv->fe.dvb = &fdtv->adapter;
	fdtv->fe.sec_priv = fdtv;
G
Greg Kroah-Hartman 已提交
273
}