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 * @phandle: pointer to AS10x handle
30 * Return 0 when no error, < 0 in case of error.
32 int as10x_cmd_turn_on(as10x_handle_t
*phandle
)
35 struct as10x_cmd_t
*pcmd
, *prsp
;
43 as10x_cmd_build(pcmd
, (++phandle
->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 (phandle
->ops
->xfer_cmd
) {
51 error
= phandle
->ops
->xfer_cmd(phandle
, (uint8_t *) pcmd
,
52 sizeof(pcmd
->body
.turn_on
.req
) +
55 sizeof(prsp
->body
.turn_on
.rsp
) +
58 error
= AS10X_CMD_ERROR
;
65 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_TURNON_RSP
);
73 * as10x_cmd_turn_off - send turn off command to AS10x
74 * @phandle: pointer to AS10x handle
76 * Return 0 on success or negative value in case of error.
78 int as10x_cmd_turn_off(as10x_handle_t
*phandle
)
81 struct as10x_cmd_t
*pcmd
, *prsp
;
89 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
90 sizeof(pcmd
->body
.turn_off
.req
));
93 pcmd
->body
.turn_off
.req
.proc_id
= cpu_to_le16(CONTROL_PROC_TURNOFF
);
96 if (phandle
->ops
->xfer_cmd
) {
97 error
= phandle
->ops
->xfer_cmd(
98 phandle
, (uint8_t *) pcmd
,
99 sizeof(pcmd
->body
.turn_off
.req
) + HEADER_SIZE
,
101 sizeof(prsp
->body
.turn_off
.rsp
) + HEADER_SIZE
);
103 error
= AS10X_CMD_ERROR
;
110 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_TURNOFF_RSP
);
118 * as10x_cmd_set_tune - send set tune command to AS10x
119 * @phandle: pointer to AS10x handle
120 * @ptune: tune parameters
122 * Return 0 on success or negative value in case of error.
124 int as10x_cmd_set_tune(as10x_handle_t
*phandle
, struct as10x_tune_args
*ptune
)
127 struct as10x_cmd_t
*preq
, *prsp
;
134 /* prepare command */
135 as10x_cmd_build(preq
, (++phandle
->cmd_xid
),
136 sizeof(preq
->body
.set_tune
.req
));
139 preq
->body
.set_tune
.req
.proc_id
= cpu_to_le16(CONTROL_PROC_SETTUNE
);
140 preq
->body
.set_tune
.req
.args
.freq
= cpu_to_le32(ptune
->freq
);
141 preq
->body
.set_tune
.req
.args
.bandwidth
= ptune
->bandwidth
;
142 preq
->body
.set_tune
.req
.args
.hier_select
= ptune
->hier_select
;
143 preq
->body
.set_tune
.req
.args
.constellation
= ptune
->constellation
;
144 preq
->body
.set_tune
.req
.args
.hierarchy
= ptune
->hierarchy
;
145 preq
->body
.set_tune
.req
.args
.interleaving_mode
=
146 ptune
->interleaving_mode
;
147 preq
->body
.set_tune
.req
.args
.code_rate
= ptune
->code_rate
;
148 preq
->body
.set_tune
.req
.args
.guard_interval
= ptune
->guard_interval
;
149 preq
->body
.set_tune
.req
.args
.transmission_mode
=
150 ptune
->transmission_mode
;
153 if (phandle
->ops
->xfer_cmd
) {
154 error
= phandle
->ops
->xfer_cmd(phandle
,
156 sizeof(preq
->body
.set_tune
.req
)
159 sizeof(prsp
->body
.set_tune
.rsp
)
162 error
= AS10X_CMD_ERROR
;
169 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_SETTUNE_RSP
);
177 * as10x_cmd_get_tune_status - send get tune status command to AS10x
178 * @phandle: pointer to AS10x handle
179 * @pstatus: pointer to updated status structure of the current tune
181 * Return 0 on success or negative value in case of error.
183 int as10x_cmd_get_tune_status(as10x_handle_t
*phandle
,
184 struct as10x_tune_status
*pstatus
)
187 struct as10x_cmd_t
*preq
, *prsp
;
194 /* prepare command */
195 as10x_cmd_build(preq
, (++phandle
->cmd_xid
),
196 sizeof(preq
->body
.get_tune_status
.req
));
199 preq
->body
.get_tune_status
.req
.proc_id
=
200 cpu_to_le16(CONTROL_PROC_GETTUNESTAT
);
203 if (phandle
->ops
->xfer_cmd
) {
204 error
= phandle
->ops
->xfer_cmd(
207 sizeof(preq
->body
.get_tune_status
.req
) + HEADER_SIZE
,
209 sizeof(prsp
->body
.get_tune_status
.rsp
) + HEADER_SIZE
);
211 error
= AS10X_CMD_ERROR
;
218 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_GETTUNESTAT_RSP
);
222 /* Response OK -> get response data */
223 pstatus
->tune_state
= prsp
->body
.get_tune_status
.rsp
.sts
.tune_state
;
224 pstatus
->signal_strength
=
225 le16_to_cpu(prsp
->body
.get_tune_status
.rsp
.sts
.signal_strength
);
226 pstatus
->PER
= le16_to_cpu(prsp
->body
.get_tune_status
.rsp
.sts
.PER
);
227 pstatus
->BER
= le16_to_cpu(prsp
->body
.get_tune_status
.rsp
.sts
.BER
);
235 * send get TPS command to AS10x
236 * @phandle: pointer to AS10x handle
237 * @ptps: pointer to TPS parameters structure
239 * Return 0 on success or negative value in case of error.
241 int as10x_cmd_get_tps(as10x_handle_t
*phandle
, struct as10x_tps
*ptps
)
244 struct as10x_cmd_t
*pcmd
, *prsp
;
251 /* prepare command */
252 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
253 sizeof(pcmd
->body
.get_tps
.req
));
256 pcmd
->body
.get_tune_status
.req
.proc_id
=
257 cpu_to_le16(CONTROL_PROC_GETTPS
);
260 if (phandle
->ops
->xfer_cmd
) {
261 error
= phandle
->ops
->xfer_cmd(phandle
,
263 sizeof(pcmd
->body
.get_tps
.req
) +
266 sizeof(prsp
->body
.get_tps
.rsp
) +
269 error
= AS10X_CMD_ERROR
;
276 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_GETTPS_RSP
);
280 /* Response OK -> get response data */
281 ptps
->constellation
= prsp
->body
.get_tps
.rsp
.tps
.constellation
;
282 ptps
->hierarchy
= prsp
->body
.get_tps
.rsp
.tps
.hierarchy
;
283 ptps
->interleaving_mode
= prsp
->body
.get_tps
.rsp
.tps
.interleaving_mode
;
284 ptps
->code_rate_HP
= prsp
->body
.get_tps
.rsp
.tps
.code_rate_HP
;
285 ptps
->code_rate_LP
= prsp
->body
.get_tps
.rsp
.tps
.code_rate_LP
;
286 ptps
->guard_interval
= prsp
->body
.get_tps
.rsp
.tps
.guard_interval
;
287 ptps
->transmission_mode
= prsp
->body
.get_tps
.rsp
.tps
.transmission_mode
;
288 ptps
->DVBH_mask_HP
= prsp
->body
.get_tps
.rsp
.tps
.DVBH_mask_HP
;
289 ptps
->DVBH_mask_LP
= prsp
->body
.get_tps
.rsp
.tps
.DVBH_mask_LP
;
290 ptps
->cell_ID
= le16_to_cpu(prsp
->body
.get_tps
.rsp
.tps
.cell_ID
);
298 * as10x_cmd_get_demod_stats - send get demod stats command to AS10x
299 * @phandle: pointer to AS10x handle
300 * @pdemod_stats: pointer to demod stats parameters structure
302 * Return 0 on success or negative value in case of error.
304 int as10x_cmd_get_demod_stats(as10x_handle_t
*phandle
,
305 struct as10x_demod_stats
*pdemod_stats
)
308 struct as10x_cmd_t
*pcmd
, *prsp
;
315 /* prepare command */
316 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
317 sizeof(pcmd
->body
.get_demod_stats
.req
));
320 pcmd
->body
.get_demod_stats
.req
.proc_id
=
321 cpu_to_le16(CONTROL_PROC_GET_DEMOD_STATS
);
324 if (phandle
->ops
->xfer_cmd
) {
325 error
= phandle
->ops
->xfer_cmd(phandle
,
327 sizeof(pcmd
->body
.get_demod_stats
.req
)
330 sizeof(prsp
->body
.get_demod_stats
.rsp
)
333 error
= AS10X_CMD_ERROR
;
340 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_GET_DEMOD_STATS_RSP
);
344 /* Response OK -> get response data */
345 pdemod_stats
->frame_count
=
346 le32_to_cpu(prsp
->body
.get_demod_stats
.rsp
.stats
.frame_count
);
347 pdemod_stats
->bad_frame_count
=
348 le32_to_cpu(prsp
->body
.get_demod_stats
.rsp
.stats
.bad_frame_count
);
349 pdemod_stats
->bytes_fixed_by_rs
=
350 le32_to_cpu(prsp
->body
.get_demod_stats
.rsp
.stats
.bytes_fixed_by_rs
);
352 le16_to_cpu(prsp
->body
.get_demod_stats
.rsp
.stats
.mer
);
353 pdemod_stats
->has_started
=
354 prsp
->body
.get_demod_stats
.rsp
.stats
.has_started
;
362 * as10x_cmd_get_impulse_resp - send get impulse response command to AS10x
363 * @phandle: pointer to AS10x handle
364 * @is_ready: pointer to value indicating when impulse
365 * response data is ready
367 * Return 0 on success or negative value in case of error.
369 int as10x_cmd_get_impulse_resp(as10x_handle_t
*phandle
,
373 struct as10x_cmd_t
*pcmd
, *prsp
;
380 /* prepare command */
381 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
382 sizeof(pcmd
->body
.get_impulse_rsp
.req
));
385 pcmd
->body
.get_impulse_rsp
.req
.proc_id
=
386 cpu_to_le16(CONTROL_PROC_GET_IMPULSE_RESP
);
389 if (phandle
->ops
->xfer_cmd
) {
390 error
= phandle
->ops
->xfer_cmd(phandle
,
392 sizeof(pcmd
->body
.get_impulse_rsp
.req
)
395 sizeof(prsp
->body
.get_impulse_rsp
.rsp
)
398 error
= AS10X_CMD_ERROR
;
405 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_GET_IMPULSE_RESP_RSP
);
409 /* Response OK -> get response data */
410 *is_ready
= prsp
->body
.get_impulse_rsp
.rsp
.is_ready
;
418 * as10x_cmd_build - build AS10x command header
419 * @pcmd: pointer to AS10x command buffer
420 * @xid: sequence id of the command
421 * @cmd_len: length of the command
423 void as10x_cmd_build(struct as10x_cmd_t
*pcmd
,
424 uint16_t xid
, uint16_t cmd_len
)
426 pcmd
->header
.req_id
= cpu_to_le16(xid
);
427 pcmd
->header
.prog
= cpu_to_le16(SERVICE_PROG_ID
);
428 pcmd
->header
.version
= cpu_to_le16(SERVICE_PROG_VERSION
);
429 pcmd
->header
.data_len
= cpu_to_le16(cmd_len
);
433 * as10x_rsp_parse - Parse command response
434 * @prsp: pointer to AS10x command buffer
435 * @proc_id: id of the command
437 * Return 0 on success or negative value in case of error.
439 int as10x_rsp_parse(struct as10x_cmd_t
*prsp
, uint16_t proc_id
)
443 /* extract command error code */
444 error
= prsp
->body
.common
.rsp
.error
;
447 (le16_to_cpu(prsp
->body
.common
.rsp
.proc_id
) == proc_id
)) {
451 return AS10X_CMD_ERROR
;