firedtv-fe.c 5.6 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.
 */

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

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

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

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

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

32 33
	err = cmp_establish_pp_connection(fdtv, fdtv->subunit,
					  fdtv->isochannel);
34
	if (err) {
35 36
		printk(KERN_ERR "Could not establish point to point "
		       "connection.\n");
37
		return err;
38 39
	}

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

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

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

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

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

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

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

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

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

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

85
static int fdtv_read_status(struct dvb_frontend *fe, fe_status_t *status)
G
Greg Kroah-Hartman 已提交
86
{
87
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
88 89
	ANTENNA_INPUT_INFO info;

90
	if (avc_tuner_status(fdtv, &info))
G
Greg Kroah-Hartman 已提交
91 92
		return -EINVAL;

93
	if (info.NoRF)
G
Greg Kroah-Hartman 已提交
94
		*status = 0;
95 96 97
	else
		*status = FE_HAS_SIGNAL | FE_HAS_VITERBI | FE_HAS_SYNC |
			  FE_HAS_CARRIER | FE_HAS_LOCK;
G
Greg Kroah-Hartman 已提交
98 99 100
	return 0;
}

101
static int fdtv_read_ber(struct dvb_frontend *fe, u32 *ber)
G
Greg Kroah-Hartman 已提交
102
{
103
	struct firedtv *fdtv = fe->sec_priv;
G
Greg Kroah-Hartman 已提交
104 105
	ANTENNA_INPUT_INFO info;

106
	if (avc_tuner_status(fdtv, &info))
G
Greg Kroah-Hartman 已提交
107 108
		return -EINVAL;

109 110
	*ber = info.BER[0] << 24 | info.BER[1] << 16 |
	       info.BER[2] << 8 | info.BER[3];
G
Greg Kroah-Hartman 已提交
111 112 113
	return 0;
}

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;
G
Greg Kroah-Hartman 已提交
117 118
	ANTENNA_INPUT_INFO info;

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

122
	*strength = info.SignalStrength << 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;
129 130
	ANTENNA_INPUT_INFO info;

131
	if (avc_tuner_status(fdtv, &info))
132 133
		return -EINVAL;

134 135
	/* C/N[dB] = -10 * log10(snr / 65535) */
	*snr = (info.CarrierNoiseRatio[0] << 8) + info.CarrierNoiseRatio[1];
136 137
	*snr *= 257;
	return 0;
G
Greg Kroah-Hartman 已提交
138 139
}

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

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

150
	/* FIXME: avc_tuner_dsd never returns ACCEPTED. Check status? */
151
	if (avc_tuner_dsd(fdtv, params) != ACCEPTED)
G
Greg Kroah-Hartman 已提交
152 153
		return -EINVAL;
	else
154
		return 0; /* not sure of this... */
G
Greg Kroah-Hartman 已提交
155 156
}

157
static int fdtv_get_frontend(struct dvb_frontend *fe,
G
Greg Kroah-Hartman 已提交
158 159 160 161 162
				struct dvb_frontend_parameters *params)
{
	return -EOPNOTSUPP;
}

163
void fdtv_frontend_init(struct firedtv *fdtv)
164
{
165
	struct dvb_frontend_ops *ops = &fdtv->fe.ops;
166
	struct dvb_frontend_info *fi = &ops->info;
G
Greg Kroah-Hartman 已提交
167

168 169
	ops->init			= fdtv_dvb_init;
	ops->sleep			= fdtv_sleep;
G
Greg Kroah-Hartman 已提交
170

171 172
	ops->set_frontend		= fdtv_set_frontend;
	ops->get_frontend		= fdtv_get_frontend;
G
Greg Kroah-Hartman 已提交
173

174 175 176 177 178
	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 已提交
179

180 181 182 183
	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 已提交
184

185 186
	switch (fdtv->type) {
	case FIREDTV_DVB_S:
187 188 189 190 191 192 193 194 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;

		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;
G
Greg Kroah-Hartman 已提交
203
		break;
204

205
	case FIREDTV_DVB_C:
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
		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 已提交
221
		break;
222

223
	case FIREDTV_DVB_T:
224 225 226 227 228 229 230 231 232 233 234
		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 已提交
235
		break;
236

G
Greg Kroah-Hartman 已提交
237
	default:
238
		printk(KERN_ERR "FireDTV: no frontend for model type %d\n",
239
		       fdtv->type);
G
Greg Kroah-Hartman 已提交
240
	}
241
	strcpy(fi->name, fdtv_model_names[fdtv->type]);
G
Greg Kroah-Hartman 已提交
242

243 244
	fdtv->fe.dvb = &fdtv->adapter;
	fdtv->fe.sec_priv = fdtv;
G
Greg Kroah-Hartman 已提交
245
}