2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 * Copyright (C) 2010 Devin Heitmueller <dheitmueller@kernellabs.com>
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, or (at your option)
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 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <linux/kernel.h>
22 #include "as102_drv.h"
23 #include "as10x_types.h"
24 #include "as10x_cmd.h"
27 * as10x_cmd_turn_on - send turn on command to AS10x
28 * @adap: pointer to AS10x bus adapter
30 * Return 0 when no error, < 0 in case of error.
32 int as10x_cmd_turn_on(struct as10x_bus_adapter_t *adap)
34 int error = AS10X_CMD_ERROR;
35 struct as10x_cmd_t *pcmd, *prsp;
43 as10x_cmd_build(pcmd, (++adap->cmd_xid),
44 sizeof(pcmd->body.turn_on.req));
47 pcmd->body.turn_on.req.proc_id = cpu_to_le16(CONTROL_PROC_TURNON);
50 if (adap->ops->xfer_cmd) {
51 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
52 sizeof(pcmd->body.turn_on.req) +
55 sizeof(prsp->body.turn_on.rsp) +
63 error = as10x_rsp_parse(prsp, CONTROL_PROC_TURNON_RSP);
71 * as10x_cmd_turn_off - send turn off command to AS10x
72 * @adap: pointer to AS10x bus adapter
74 * Return 0 on success or negative value in case of error.
76 int as10x_cmd_turn_off(struct as10x_bus_adapter_t *adap)
78 int error = AS10X_CMD_ERROR;
79 struct as10x_cmd_t *pcmd, *prsp;
87 as10x_cmd_build(pcmd, (++adap->cmd_xid),
88 sizeof(pcmd->body.turn_off.req));
91 pcmd->body.turn_off.req.proc_id = cpu_to_le16(CONTROL_PROC_TURNOFF);
94 if (adap->ops->xfer_cmd) {
95 error = adap->ops->xfer_cmd(
96 adap, (uint8_t *) pcmd,
97 sizeof(pcmd->body.turn_off.req) + HEADER_SIZE,
99 sizeof(prsp->body.turn_off.rsp) + HEADER_SIZE);
106 error = as10x_rsp_parse(prsp, CONTROL_PROC_TURNOFF_RSP);
114 * as10x_cmd_set_tune - send set tune command to AS10x
115 * @adap: pointer to AS10x bus adapter
116 * @ptune: tune parameters
118 * Return 0 on success or negative value in case of error.
120 int as10x_cmd_set_tune(struct as10x_bus_adapter_t *adap,
121 struct as10x_tune_args *ptune)
123 int error = AS10X_CMD_ERROR;
124 struct as10x_cmd_t *preq, *prsp;
131 /* prepare command */
132 as10x_cmd_build(preq, (++adap->cmd_xid),
133 sizeof(preq->body.set_tune.req));
136 preq->body.set_tune.req.proc_id = cpu_to_le16(CONTROL_PROC_SETTUNE);
137 preq->body.set_tune.req.args.freq = cpu_to_le32(ptune->freq);
138 preq->body.set_tune.req.args.bandwidth = ptune->bandwidth;
139 preq->body.set_tune.req.args.hier_select = ptune->hier_select;
140 preq->body.set_tune.req.args.modulation = ptune->modulation;
141 preq->body.set_tune.req.args.hierarchy = ptune->hierarchy;
142 preq->body.set_tune.req.args.interleaving_mode =
143 ptune->interleaving_mode;
144 preq->body.set_tune.req.args.code_rate = ptune->code_rate;
145 preq->body.set_tune.req.args.guard_interval = ptune->guard_interval;
146 preq->body.set_tune.req.args.transmission_mode =
147 ptune->transmission_mode;
150 if (adap->ops->xfer_cmd) {
151 error = adap->ops->xfer_cmd(adap,
153 sizeof(preq->body.set_tune.req)
156 sizeof(prsp->body.set_tune.rsp)
164 error = as10x_rsp_parse(prsp, CONTROL_PROC_SETTUNE_RSP);
172 * as10x_cmd_get_tune_status - send get tune status command to AS10x
173 * @adap: pointer to AS10x bus adapter
174 * @pstatus: pointer to updated status structure of the current tune
176 * Return 0 on success or negative value in case of error.
178 int as10x_cmd_get_tune_status(struct as10x_bus_adapter_t *adap,
179 struct as10x_tune_status *pstatus)
181 int error = AS10X_CMD_ERROR;
182 struct as10x_cmd_t *preq, *prsp;
189 /* prepare command */
190 as10x_cmd_build(preq, (++adap->cmd_xid),
191 sizeof(preq->body.get_tune_status.req));
194 preq->body.get_tune_status.req.proc_id =
195 cpu_to_le16(CONTROL_PROC_GETTUNESTAT);
198 if (adap->ops->xfer_cmd) {
199 error = adap->ops->xfer_cmd(
202 sizeof(preq->body.get_tune_status.req) + HEADER_SIZE,
204 sizeof(prsp->body.get_tune_status.rsp) + HEADER_SIZE);
211 error = as10x_rsp_parse(prsp, CONTROL_PROC_GETTUNESTAT_RSP);
215 /* Response OK -> get response data */
216 pstatus->tune_state = prsp->body.get_tune_status.rsp.sts.tune_state;
217 pstatus->signal_strength =
218 le16_to_cpu(prsp->body.get_tune_status.rsp.sts.signal_strength);
219 pstatus->PER = le16_to_cpu(prsp->body.get_tune_status.rsp.sts.PER);
220 pstatus->BER = le16_to_cpu(prsp->body.get_tune_status.rsp.sts.BER);
228 * as10x_cmd_get_tps - send get TPS command to AS10x
229 * @adap: pointer to AS10x handle
230 * @ptps: pointer to TPS parameters structure
232 * Return 0 on success or negative value in case of error.
234 int as10x_cmd_get_tps(struct as10x_bus_adapter_t *adap, struct as10x_tps *ptps)
236 int error = AS10X_CMD_ERROR;
237 struct as10x_cmd_t *pcmd, *prsp;
244 /* prepare command */
245 as10x_cmd_build(pcmd, (++adap->cmd_xid),
246 sizeof(pcmd->body.get_tps.req));
249 pcmd->body.get_tune_status.req.proc_id =
250 cpu_to_le16(CONTROL_PROC_GETTPS);
253 if (adap->ops->xfer_cmd) {
254 error = adap->ops->xfer_cmd(adap,
256 sizeof(pcmd->body.get_tps.req) +
259 sizeof(prsp->body.get_tps.rsp) +
267 error = as10x_rsp_parse(prsp, CONTROL_PROC_GETTPS_RSP);
271 /* Response OK -> get response data */
272 ptps->modulation = prsp->body.get_tps.rsp.tps.modulation;
273 ptps->hierarchy = prsp->body.get_tps.rsp.tps.hierarchy;
274 ptps->interleaving_mode = prsp->body.get_tps.rsp.tps.interleaving_mode;
275 ptps->code_rate_HP = prsp->body.get_tps.rsp.tps.code_rate_HP;
276 ptps->code_rate_LP = prsp->body.get_tps.rsp.tps.code_rate_LP;
277 ptps->guard_interval = prsp->body.get_tps.rsp.tps.guard_interval;
278 ptps->transmission_mode = prsp->body.get_tps.rsp.tps.transmission_mode;
279 ptps->DVBH_mask_HP = prsp->body.get_tps.rsp.tps.DVBH_mask_HP;
280 ptps->DVBH_mask_LP = prsp->body.get_tps.rsp.tps.DVBH_mask_LP;
281 ptps->cell_ID = le16_to_cpu(prsp->body.get_tps.rsp.tps.cell_ID);
289 * as10x_cmd_get_demod_stats - send get demod stats command to AS10x
290 * @adap: pointer to AS10x bus adapter
291 * @pdemod_stats: pointer to demod stats parameters structure
293 * Return 0 on success or negative value in case of error.
295 int as10x_cmd_get_demod_stats(struct as10x_bus_adapter_t *adap,
296 struct as10x_demod_stats *pdemod_stats)
298 int error = AS10X_CMD_ERROR;
299 struct as10x_cmd_t *pcmd, *prsp;
306 /* prepare command */
307 as10x_cmd_build(pcmd, (++adap->cmd_xid),
308 sizeof(pcmd->body.get_demod_stats.req));
311 pcmd->body.get_demod_stats.req.proc_id =
312 cpu_to_le16(CONTROL_PROC_GET_DEMOD_STATS);
315 if (adap->ops->xfer_cmd) {
316 error = adap->ops->xfer_cmd(adap,
318 sizeof(pcmd->body.get_demod_stats.req)
321 sizeof(prsp->body.get_demod_stats.rsp)
329 error = as10x_rsp_parse(prsp, CONTROL_PROC_GET_DEMOD_STATS_RSP);
333 /* Response OK -> get response data */
334 pdemod_stats->frame_count =
335 le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.frame_count);
336 pdemod_stats->bad_frame_count =
337 le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.bad_frame_count);
338 pdemod_stats->bytes_fixed_by_rs =
339 le32_to_cpu(prsp->body.get_demod_stats.rsp.stats.bytes_fixed_by_rs);
341 le16_to_cpu(prsp->body.get_demod_stats.rsp.stats.mer);
342 pdemod_stats->has_started =
343 prsp->body.get_demod_stats.rsp.stats.has_started;
351 * as10x_cmd_get_impulse_resp - send get impulse response command to AS10x
352 * @adap: pointer to AS10x bus adapter
353 * @is_ready: pointer to value indicating when impulse
354 * response data is ready
356 * Return 0 on success or negative value in case of error.
358 int as10x_cmd_get_impulse_resp(struct as10x_bus_adapter_t *adap,
361 int error = AS10X_CMD_ERROR;
362 struct as10x_cmd_t *pcmd, *prsp;
369 /* prepare command */
370 as10x_cmd_build(pcmd, (++adap->cmd_xid),
371 sizeof(pcmd->body.get_impulse_rsp.req));
374 pcmd->body.get_impulse_rsp.req.proc_id =
375 cpu_to_le16(CONTROL_PROC_GET_IMPULSE_RESP);
378 if (adap->ops->xfer_cmd) {
379 error = adap->ops->xfer_cmd(adap,
381 sizeof(pcmd->body.get_impulse_rsp.req)
384 sizeof(prsp->body.get_impulse_rsp.rsp)
392 error = as10x_rsp_parse(prsp, CONTROL_PROC_GET_IMPULSE_RESP_RSP);
396 /* Response OK -> get response data */
397 *is_ready = prsp->body.get_impulse_rsp.rsp.is_ready;
405 * as10x_cmd_build - build AS10x command header
406 * @pcmd: pointer to AS10x command buffer
407 * @xid: sequence id of the command
408 * @cmd_len: length of the command
410 void as10x_cmd_build(struct as10x_cmd_t *pcmd,
411 uint16_t xid, uint16_t cmd_len)
413 pcmd->header.req_id = cpu_to_le16(xid);
414 pcmd->header.prog = cpu_to_le16(SERVICE_PROG_ID);
415 pcmd->header.version = cpu_to_le16(SERVICE_PROG_VERSION);
416 pcmd->header.data_len = cpu_to_le16(cmd_len);
420 * as10x_rsp_parse - Parse command response
421 * @prsp: pointer to AS10x command buffer
422 * @proc_id: id of the command
424 * Return 0 on success or negative value in case of error.
426 int as10x_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
430 /* extract command error code */
431 error = prsp->body.common.rsp.error;
434 (le16_to_cpu(prsp->body.common.rsp.proc_id) == proc_id)) {
438 return AS10X_CMD_ERROR;