Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / media / usb / as102 / as10x_cmd_cfg.c
blob5bc11a7141e741458c94cc8e9483d4eb73529606
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Abilis Systems Single DVB-T Receiver
4 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
5 */
7 #include <linux/kernel.h>
8 #include "as102_drv.h"
9 #include "as10x_cmd.h"
11 /***************************/
12 /* FUNCTION DEFINITION */
13 /***************************/
15 /**
16 * as10x_cmd_get_context - Send get context command to AS10x
17 * @adap: pointer to AS10x bus adapter
18 * @tag: context tag
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,
24 uint32_t *pvalue)
26 int error;
27 struct as10x_cmd_t *pcmd, *prsp;
29 pcmd = adap->cmd;
30 prsp = adap->rsp;
32 /* prepare command */
33 as10x_cmd_build(pcmd, (++adap->cmd_xid),
34 sizeof(pcmd->body.context.req));
36 /* fill command */
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);
41 /* send command */
42 if (adap->ops->xfer_cmd) {
43 error = adap->ops->xfer_cmd(adap,
44 (uint8_t *) pcmd,
45 sizeof(pcmd->body.context.req)
46 + HEADER_SIZE,
47 (uint8_t *) prsp,
48 sizeof(prsp->body.context.rsp)
49 + HEADER_SIZE);
50 } else {
51 error = AS10X_CMD_ERROR;
54 if (error < 0)
55 goto out;
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);
61 if (error == 0) {
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 */
67 out:
68 return error;
71 /**
72 * as10x_cmd_set_context - send set context command to AS10x
73 * @adap: pointer to AS10x bus adapter
74 * @tag: context tag
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,
80 uint32_t value)
82 int error;
83 struct as10x_cmd_t *pcmd, *prsp;
85 pcmd = adap->cmd;
86 prsp = adap->rsp;
88 /* prepare command */
89 as10x_cmd_build(pcmd, (++adap->cmd_xid),
90 sizeof(pcmd->body.context.req));
92 /* fill command */
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);
99 /* send command */
100 if (adap->ops->xfer_cmd) {
101 error = adap->ops->xfer_cmd(adap,
102 (uint8_t *) pcmd,
103 sizeof(pcmd->body.context.req)
104 + HEADER_SIZE,
105 (uint8_t *) prsp,
106 sizeof(prsp->body.context.rsp)
107 + HEADER_SIZE);
108 } else {
109 error = AS10X_CMD_ERROR;
112 if (error < 0)
113 goto out;
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);
119 out:
120 return error;
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
130 * to be ON or OFF
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)
136 int error;
137 struct as10x_cmd_t *pcmd, *prsp;
139 pcmd = adap->cmd;
140 prsp = adap->rsp;
142 /* prepare command */
143 as10x_cmd_build(pcmd, (++adap->cmd_xid),
144 sizeof(pcmd->body.cfg_change_mode.req));
146 /* fill command */
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;
151 /* send command */
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)
157 + HEADER_SIZE);
158 } else {
159 error = AS10X_CMD_ERROR;
162 if (error < 0)
163 goto out;
165 /* parse response */
166 error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
168 out:
169 return error;
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)
183 int err;
185 err = prsp->body.context.rsp.error;
187 if ((err == 0) &&
188 (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
189 return 0;
191 return AS10X_CMD_ERROR;