1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Abilis Systems Single DVB-T Receiver
4 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
7 #include <linux/kernel.h>
11 /***************************/
12 /* FUNCTION DEFINITION */
13 /***************************/
16 * as10x_cmd_get_context - Send get context command to AS10x
17 * @adap: pointer to AS10x bus adapter
19 * @pvalue: pointer where to store context value read
21 * Return 0 on success or negative value in case of error.
23 int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
27 struct as10x_cmd_t *pcmd, *prsp;
33 as10x_cmd_build(pcmd, (++adap->cmd_xid),
34 sizeof(pcmd->body.context.req));
37 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
38 pcmd->body.context.req.tag = cpu_to_le16(tag);
39 pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
42 if (adap->ops->xfer_cmd) {
43 error = adap->ops->xfer_cmd(adap,
45 sizeof(pcmd->body.context.req)
48 sizeof(prsp->body.context.rsp)
51 error = AS10X_CMD_ERROR;
57 /* parse response: context command do not follow the common response */
58 /* structure -> specific handling response parse required */
59 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
62 /* Response OK -> get response data */
63 *pvalue = le32_to_cpu((__force __le32)prsp->body.context.rsp.reg_val.u.value32);
64 /* value returned is always a 32-bit value */
72 * as10x_cmd_set_context - send set context command to AS10x
73 * @adap: pointer to AS10x bus adapter
75 * @value: value to set in context
77 * Return 0 on success or negative value in case of error.
79 int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
83 struct as10x_cmd_t *pcmd, *prsp;
89 as10x_cmd_build(pcmd, (++adap->cmd_xid),
90 sizeof(pcmd->body.context.req));
93 pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
94 /* pcmd->body.context.req.reg_val.mode initialization is not required */
95 pcmd->body.context.req.reg_val.u.value32 = (__force u32)cpu_to_le32(value);
96 pcmd->body.context.req.tag = cpu_to_le16(tag);
97 pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
100 if (adap->ops->xfer_cmd) {
101 error = adap->ops->xfer_cmd(adap,
103 sizeof(pcmd->body.context.req)
106 sizeof(prsp->body.context.rsp)
109 error = AS10X_CMD_ERROR;
115 /* parse response: context command do not follow the common response */
116 /* structure -> specific handling response parse required */
117 error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
124 * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
125 * @adap: pointer to AS10x bus adapter
126 * @mode: mode selected:
127 * - ON : 0x0 => eLNA always ON
128 * - OFF : 0x1 => eLNA always OFF
129 * - AUTO : 0x2 => eLNA follow hysteresis parameters
132 * Return 0 on success or negative value in case of error.
134 int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
137 struct as10x_cmd_t *pcmd, *prsp;
142 /* prepare command */
143 as10x_cmd_build(pcmd, (++adap->cmd_xid),
144 sizeof(pcmd->body.cfg_change_mode.req));
147 pcmd->body.cfg_change_mode.req.proc_id =
148 cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
149 pcmd->body.cfg_change_mode.req.mode = mode;
152 if (adap->ops->xfer_cmd) {
153 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
154 sizeof(pcmd->body.cfg_change_mode.req)
155 + HEADER_SIZE, (uint8_t *) prsp,
156 sizeof(prsp->body.cfg_change_mode.rsp)
159 error = AS10X_CMD_ERROR;
166 error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
173 * as10x_context_rsp_parse - Parse context command response
174 * @prsp: pointer to AS10x command response buffer
175 * @proc_id: id of the command
177 * Since the contex command response does not follow the common
178 * response, a specific parse function is required.
179 * Return 0 on success or negative value in case of error.
181 int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
185 err = prsp->body.context.rsp.error;
188 (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
191 return AS10X_CMD_ERROR;