2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/kernel.h>
21 #include "as102_drv.h"
22 #include "as10x_types.h"
23 #include "as10x_cmd.h"
25 /***************************/
26 /* FUNCTION DEFINITION */
27 /***************************/
30 * as10x_cmd_get_context - Send get context command to AS10x
31 * @phandle: pointer to AS10x handle
33 * @pvalue: pointer where to store context value read
35 * Return 0 on success or negative value in case of error.
37 int as10x_cmd_get_context(as10x_handle_t
*phandle
, uint16_t tag
,
41 struct as10x_cmd_t
*pcmd
, *prsp
;
49 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
50 sizeof(pcmd
->body
.context
.req
));
53 pcmd
->body
.context
.req
.proc_id
= cpu_to_le16(CONTROL_PROC_CONTEXT
);
54 pcmd
->body
.context
.req
.tag
= cpu_to_le16(tag
);
55 pcmd
->body
.context
.req
.type
= cpu_to_le16(GET_CONTEXT_DATA
);
58 if (phandle
->ops
->xfer_cmd
) {
59 error
= phandle
->ops
->xfer_cmd(phandle
,
61 sizeof(pcmd
->body
.context
.req
)
64 sizeof(prsp
->body
.context
.rsp
)
67 error
= AS10X_CMD_ERROR
;
73 /* parse response: context command do not follow the common response */
74 /* structure -> specific handling response parse required */
75 error
= as10x_context_rsp_parse(prsp
, CONTROL_PROC_CONTEXT_RSP
);
78 /* Response OK -> get response data */
79 *pvalue
= le32_to_cpu(prsp
->body
.context
.rsp
.reg_val
.u
.value32
);
80 /* value returned is always a 32-bit value */
89 * as10x_cmd_set_context - send set context command to AS10x
90 * @phandle: pointer to AS10x handle
92 * @value: value to set in context
94 * Return 0 on success or negative value in case of error.
96 int as10x_cmd_set_context(as10x_handle_t
*phandle
, uint16_t tag
,
100 struct as10x_cmd_t
*pcmd
, *prsp
;
107 /* prepare command */
108 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
109 sizeof(pcmd
->body
.context
.req
));
112 pcmd
->body
.context
.req
.proc_id
= cpu_to_le16(CONTROL_PROC_CONTEXT
);
113 /* pcmd->body.context.req.reg_val.mode initialization is not required */
114 pcmd
->body
.context
.req
.reg_val
.u
.value32
= cpu_to_le32(value
);
115 pcmd
->body
.context
.req
.tag
= cpu_to_le16(tag
);
116 pcmd
->body
.context
.req
.type
= cpu_to_le16(SET_CONTEXT_DATA
);
119 if (phandle
->ops
->xfer_cmd
) {
120 error
= phandle
->ops
->xfer_cmd(phandle
,
122 sizeof(pcmd
->body
.context
.req
)
125 sizeof(prsp
->body
.context
.rsp
)
128 error
= AS10X_CMD_ERROR
;
134 /* parse response: context command do not follow the common response */
135 /* structure -> specific handling response parse required */
136 error
= as10x_context_rsp_parse(prsp
, CONTROL_PROC_CONTEXT_RSP
);
144 * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
145 * @phandle: pointer to AS10x handle
146 * @mode: mode selected:
147 * - ON : 0x0 => eLNA always ON
148 * - OFF : 0x1 => eLNA always OFF
149 * - AUTO : 0x2 => eLNA follow hysteresis parameters
152 * Return 0 on success or negative value in case of error.
154 int as10x_cmd_eLNA_change_mode(as10x_handle_t
*phandle
, uint8_t mode
)
157 struct as10x_cmd_t
*pcmd
, *prsp
;
164 /* prepare command */
165 as10x_cmd_build(pcmd
, (++phandle
->cmd_xid
),
166 sizeof(pcmd
->body
.cfg_change_mode
.req
));
169 pcmd
->body
.cfg_change_mode
.req
.proc_id
=
170 cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE
);
171 pcmd
->body
.cfg_change_mode
.req
.mode
= mode
;
174 if (phandle
->ops
->xfer_cmd
) {
175 error
= phandle
->ops
->xfer_cmd(phandle
, (uint8_t *) pcmd
,
176 sizeof(pcmd
->body
.cfg_change_mode
.req
)
177 + HEADER_SIZE
, (uint8_t *) prsp
,
178 sizeof(prsp
->body
.cfg_change_mode
.rsp
)
181 error
= AS10X_CMD_ERROR
;
188 error
= as10x_rsp_parse(prsp
, CONTROL_PROC_ELNA_CHANGE_MODE_RSP
);
196 * as10x_context_rsp_parse - Parse context command response
197 * @prsp: pointer to AS10x command response buffer
198 * @proc_id: id of the command
200 * Since the contex command reponse does not follow the common
201 * response, a specific parse function is required.
202 * Return 0 on success or negative value in case of error.
204 int as10x_context_rsp_parse(struct as10x_cmd_t
*prsp
, uint16_t proc_id
)
208 err
= prsp
->body
.context
.rsp
.error
;
211 (le16_to_cpu(prsp
->body
.context
.rsp
.proc_id
) == proc_id
)) {
214 return AS10X_CMD_ERROR
;