1 /*
2  *  Driver for Dummy Frontend
3  *
4  *  Written by Emard <emard@softhome.net>
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; if not, write to the Free Software
19  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20  */
21 
22 #include <linux/module.h>
23 #include <linux/init.h>
24 #include <linux/string.h>
25 #include <linux/slab.h>
26 
27 #include "dvb_frontend.h"
28 #include "dvb_dummy_fe.h"
29 
30 
31 struct dvb_dummy_fe_state {
32 	struct dvb_frontend frontend;
33 };
34 
35 
36 static int dvb_dummy_fe_read_status(struct dvb_frontend *fe,
37 				    enum fe_status *status)
38 {
39 	*status = FE_HAS_SIGNAL
40 		| FE_HAS_CARRIER
41 		| FE_HAS_VITERBI
42 		| FE_HAS_SYNC
43 		| FE_HAS_LOCK;
44 
45 	return 0;
46 }
47 
48 static int dvb_dummy_fe_read_ber(struct dvb_frontend* fe, u32* ber)
49 {
50 	*ber = 0;
51 	return 0;
52 }
53 
54 static int dvb_dummy_fe_read_signal_strength(struct dvb_frontend* fe, u16* strength)
55 {
56 	*strength = 0;
57 	return 0;
58 }
59 
60 static int dvb_dummy_fe_read_snr(struct dvb_frontend* fe, u16* snr)
61 {
62 	*snr = 0;
63 	return 0;
64 }
65 
66 static int dvb_dummy_fe_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
67 {
68 	*ucblocks = 0;
69 	return 0;
70 }
71 
72 /*
73  * Only needed if it actually reads something from the hardware
74  */
75 static int dvb_dummy_fe_get_frontend(struct dvb_frontend *fe)
76 {
77 	return 0;
78 }
79 
80 static int dvb_dummy_fe_set_frontend(struct dvb_frontend *fe)
81 {
82 	if (fe->ops.tuner_ops.set_params) {
83 		fe->ops.tuner_ops.set_params(fe);
84 		if (fe->ops.i2c_gate_ctrl)
85 			fe->ops.i2c_gate_ctrl(fe, 0);
86 	}
87 
88 	return 0;
89 }
90 
91 static int dvb_dummy_fe_sleep(struct dvb_frontend* fe)
92 {
93 	return 0;
94 }
95 
96 static int dvb_dummy_fe_init(struct dvb_frontend* fe)
97 {
98 	return 0;
99 }
100 
101 static int dvb_dummy_fe_set_tone(struct dvb_frontend *fe,
102 				 enum fe_sec_tone_mode tone)
103 {
104 	return 0;
105 }
106 
107 static int dvb_dummy_fe_set_voltage(struct dvb_frontend *fe,
108 				    enum fe_sec_voltage voltage)
109 {
110 	return 0;
111 }
112 
113 static void dvb_dummy_fe_release(struct dvb_frontend* fe)
114 {
115 	struct dvb_dummy_fe_state* state = fe->demodulator_priv;
116 	kfree(state);
117 }
118 
119 static struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops;
120 
121 struct dvb_frontend* dvb_dummy_fe_ofdm_attach(void)
122 {
123 	struct dvb_dummy_fe_state* state = NULL;
124 
125 	/* allocate memory for the internal state */
126 	state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
127 	if (!state)
128 		return NULL;
129 
130 	/* create dvb_frontend */
131 	memcpy(&state->frontend.ops, &dvb_dummy_fe_ofdm_ops, sizeof(struct dvb_frontend_ops));
132 	state->frontend.demodulator_priv = state;
133 	return &state->frontend;
134 }
135 
136 static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;
137 
138 struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
139 {
140 	struct dvb_dummy_fe_state* state = NULL;
141 
142 	/* allocate memory for the internal state */
143 	state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
144 	if (!state)
145 		return NULL;
146 
147 	/* create dvb_frontend */
148 	memcpy(&state->frontend.ops, &dvb_dummy_fe_qpsk_ops, sizeof(struct dvb_frontend_ops));
149 	state->frontend.demodulator_priv = state;
150 	return &state->frontend;
151 }
152 
153 static struct dvb_frontend_ops dvb_dummy_fe_qam_ops;
154 
155 struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
156 {
157 	struct dvb_dummy_fe_state* state = NULL;
158 
159 	/* allocate memory for the internal state */
160 	state = kzalloc(sizeof(struct dvb_dummy_fe_state), GFP_KERNEL);
161 	if (!state)
162 		return NULL;
163 
164 	/* create dvb_frontend */
165 	memcpy(&state->frontend.ops, &dvb_dummy_fe_qam_ops, sizeof(struct dvb_frontend_ops));
166 	state->frontend.demodulator_priv = state;
167 	return &state->frontend;
168 }
169 
170 static struct dvb_frontend_ops dvb_dummy_fe_ofdm_ops = {
171 	.delsys = { SYS_DVBT },
172 	.info = {
173 		.name			= "Dummy DVB-T",
174 		.frequency_min		= 0,
175 		.frequency_max		= 863250000,
176 		.frequency_stepsize	= 62500,
177 		.caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
178 				FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
179 				FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO |
180 				FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
181 				FE_CAN_TRANSMISSION_MODE_AUTO |
182 				FE_CAN_GUARD_INTERVAL_AUTO |
183 				FE_CAN_HIERARCHY_AUTO,
184 	},
185 
186 	.release = dvb_dummy_fe_release,
187 
188 	.init = dvb_dummy_fe_init,
189 	.sleep = dvb_dummy_fe_sleep,
190 
191 	.set_frontend = dvb_dummy_fe_set_frontend,
192 	.get_frontend = dvb_dummy_fe_get_frontend,
193 
194 	.read_status = dvb_dummy_fe_read_status,
195 	.read_ber = dvb_dummy_fe_read_ber,
196 	.read_signal_strength = dvb_dummy_fe_read_signal_strength,
197 	.read_snr = dvb_dummy_fe_read_snr,
198 	.read_ucblocks = dvb_dummy_fe_read_ucblocks,
199 };
200 
201 static struct dvb_frontend_ops dvb_dummy_fe_qam_ops = {
202 	.delsys = { SYS_DVBC_ANNEX_A },
203 	.info = {
204 		.name			= "Dummy DVB-C",
205 		.frequency_stepsize	= 62500,
206 		.frequency_min		= 51000000,
207 		.frequency_max		= 858000000,
208 		.symbol_rate_min	= (57840000/2)/64,     /* SACLK/64 == (XIN/2)/64 */
209 		.symbol_rate_max	= (57840000/2)/4,      /* SACLK/4 */
210 		.caps = FE_CAN_QAM_16 | FE_CAN_QAM_32 | FE_CAN_QAM_64 |
211 			FE_CAN_QAM_128 | FE_CAN_QAM_256 |
212 			FE_CAN_FEC_AUTO | FE_CAN_INVERSION_AUTO
213 	},
214 
215 	.release = dvb_dummy_fe_release,
216 
217 	.init = dvb_dummy_fe_init,
218 	.sleep = dvb_dummy_fe_sleep,
219 
220 	.set_frontend = dvb_dummy_fe_set_frontend,
221 	.get_frontend = dvb_dummy_fe_get_frontend,
222 
223 	.read_status = dvb_dummy_fe_read_status,
224 	.read_ber = dvb_dummy_fe_read_ber,
225 	.read_signal_strength = dvb_dummy_fe_read_signal_strength,
226 	.read_snr = dvb_dummy_fe_read_snr,
227 	.read_ucblocks = dvb_dummy_fe_read_ucblocks,
228 };
229 
230 static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops = {
231 	.delsys = { SYS_DVBS },
232 	.info = {
233 		.name			= "Dummy DVB-S",
234 		.frequency_min		= 950000,
235 		.frequency_max		= 2150000,
236 		.frequency_stepsize	= 250,           /* kHz for QPSK frontends */
237 		.frequency_tolerance	= 29500,
238 		.symbol_rate_min	= 1000000,
239 		.symbol_rate_max	= 45000000,
240 		.caps = FE_CAN_INVERSION_AUTO |
241 			FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
242 			FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
243 			FE_CAN_QPSK
244 	},
245 
246 	.release = dvb_dummy_fe_release,
247 
248 	.init = dvb_dummy_fe_init,
249 	.sleep = dvb_dummy_fe_sleep,
250 
251 	.set_frontend = dvb_dummy_fe_set_frontend,
252 	.get_frontend = dvb_dummy_fe_get_frontend,
253 
254 	.read_status = dvb_dummy_fe_read_status,
255 	.read_ber = dvb_dummy_fe_read_ber,
256 	.read_signal_strength = dvb_dummy_fe_read_signal_strength,
257 	.read_snr = dvb_dummy_fe_read_snr,
258 	.read_ucblocks = dvb_dummy_fe_read_ucblocks,
259 
260 	.set_voltage = dvb_dummy_fe_set_voltage,
261 	.set_tone = dvb_dummy_fe_set_tone,
262 };
263 
264 MODULE_DESCRIPTION("DVB DUMMY Frontend");
265 MODULE_AUTHOR("Emard");
266 MODULE_LICENSE("GPL");
267 
268 EXPORT_SYMBOL(dvb_dummy_fe_ofdm_attach);
269 EXPORT_SYMBOL(dvb_dummy_fe_qam_attach);
270 EXPORT_SYMBOL(dvb_dummy_fe_qpsk_attach);
271