2 * Abilis Systems Single DVB-T Receiver
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.
16 #include <linux/kernel.h>
17 #include "as102_drv.h"
18 #include "as10x_cmd.h"
20 /***************************/
21 /* FUNCTION DEFINITION */
22 /***************************/
25 * as10x_cmd_get_context - Send get context command to AS10x
26 * @adap: pointer to AS10x bus adapter
28 * @pvalue: pointer where to store context value read
30 * Return 0 on success or negative value in case of error.
32 int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
36 struct as10x_cmd_t *pcmd, *prsp;
42 as10x_cmd_build(pcmd, (++adap->cmd_xid),
43 sizeof(pcmd->body.context.req));
46 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
47 pcmd->body.context.req.tag = cpu_to_le16(tag);
48 pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
51 if (adap->ops->xfer_cmd) {
52 error = adap->ops->xfer_cmd(adap,
54 sizeof(pcmd->body.context.req)
57 sizeof(prsp->body.context.rsp)
60 error = AS10X_CMD_ERROR;
66 /* parse response: context command do not follow the common response */
67 /* structure -> specific handling response parse required */
68 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
71 /* Response OK -> get response data */
72 *pvalue = le32_to_cpu((__force __le32)prsp->body.context.rsp.reg_val.u.value32);
73 /* value returned is always a 32-bit value */
81 * as10x_cmd_set_context - send set context command to AS10x
82 * @adap: pointer to AS10x bus adapter
84 * @value: value to set in context
86 * Return 0 on success or negative value in case of error.
88 int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
92 struct as10x_cmd_t *pcmd, *prsp;
98 as10x_cmd_build(pcmd, (++adap->cmd_xid),
99 sizeof(pcmd->body.context.req));
102 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
103 /* pcmd->body.context.req.reg_val.mode initialization is not required */
104 pcmd->body.context.req.reg_val.u.value32 = (__force u32)cpu_to_le32(value);
105 pcmd->body.context.req.tag = cpu_to_le16(tag);
106 pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
109 if (adap->ops->xfer_cmd) {
110 error = adap->ops->xfer_cmd(adap,
112 sizeof(pcmd->body.context.req)
115 sizeof(prsp->body.context.rsp)
118 error = AS10X_CMD_ERROR;
124 /* parse response: context command do not follow the common response */
125 /* structure -> specific handling response parse required */
126 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
133 * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
134 * @adap: pointer to AS10x bus adapter
135 * @mode: mode selected:
136 * - ON : 0x0 => eLNA always ON
137 * - OFF : 0x1 => eLNA always OFF
138 * - AUTO : 0x2 => eLNA follow hysteresis parameters
141 * Return 0 on success or negative value in case of error.
143 int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
146 struct as10x_cmd_t *pcmd, *prsp;
151 /* prepare command */
152 as10x_cmd_build(pcmd, (++adap->cmd_xid),
153 sizeof(pcmd->body.cfg_change_mode.req));
156 pcmd->body.cfg_change_mode.req.proc_id =
157 cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
158 pcmd->body.cfg_change_mode.req.mode = mode;
161 if (adap->ops->xfer_cmd) {
162 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
163 sizeof(pcmd->body.cfg_change_mode.req)
164 + HEADER_SIZE, (uint8_t *) prsp,
165 sizeof(prsp->body.cfg_change_mode.rsp)
168 error = AS10X_CMD_ERROR;
175 error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
182 * as10x_context_rsp_parse - Parse context command response
183 * @prsp: pointer to AS10x command response buffer
184 * @proc_id: id of the command
186 * Since the contex command response does not follow the common
187 * response, a specific parse function is required.
188 * Return 0 on success or negative value in case of error.
190 int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
194 err = prsp->body.context.rsp.error;
197 (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
200 return AS10X_CMD_ERROR;