blob: 4a2bbd76665541990d69009b133686ae7b947fd6 [file] [log] [blame]
Pierrick Hascoet315cadc2011-10-31 12:24:49 -03001/*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
4 *
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)
8 * any later version.
9 *
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.
14 *
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.
18 */
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030019
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030020#include <linux/kernel.h>
21#include "as102_drv.h"
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030022#include "as10x_types.h"
23#include "as10x_cmd.h"
24
25/***************************/
26/* FUNCTION DEFINITION */
27/***************************/
28
29/**
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -030030 * as10x_cmd_get_context - Send get context command to AS10x
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030031 * @adap: pointer to AS10x bus adapter
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -030032 * @tag: context tag
33 * @pvalue: pointer where to store context value read
34 *
35 * Return 0 on success or negative value in case of error.
36 */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030037int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030038 uint32_t *pvalue)
39{
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030040 int error;
41 struct as10x_cmd_t *pcmd, *prsp;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030042
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030043 ENTER();
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030044
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030045 pcmd = adap->cmd;
46 prsp = adap->rsp;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030047
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030048 /* prepare command */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030049 as10x_cmd_build(pcmd, (++adap->cmd_xid),
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030050 sizeof(pcmd->body.context.req));
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030051
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030052 /* fill command */
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);
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030056
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030057 /* send command */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030058 if (adap->ops->xfer_cmd) {
59 error = adap->ops->xfer_cmd(adap,
60 (uint8_t *) pcmd,
61 sizeof(pcmd->body.context.req)
62 + HEADER_SIZE,
63 (uint8_t *) prsp,
64 sizeof(prsp->body.context.rsp)
65 + HEADER_SIZE);
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030066 } else {
67 error = AS10X_CMD_ERROR;
68 }
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030069
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030070 if (error < 0)
71 goto out;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030072
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030073 /* 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);
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030076
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030077 if (error == 0) {
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 */
81 }
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030082
83out:
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030084 LEAVE();
85 return error;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030086}
87
88/**
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -030089 * as10x_cmd_set_context - send set context command to AS10x
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030090 * @adap: pointer to AS10x bus adapter
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -030091 * @tag: context tag
92 * @value: value to set in context
93 *
94 * Return 0 on success or negative value in case of error.
95 */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -030096int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
Pierrick Hascoet41b44e02011-10-31 12:24:39 -030097 uint32_t value)
98{
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -030099 int error;
100 struct as10x_cmd_t *pcmd, *prsp;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300101
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300102 ENTER();
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300103
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300104 pcmd = adap->cmd;
105 prsp = adap->rsp;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300106
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300107 /* prepare command */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300108 as10x_cmd_build(pcmd, (++adap->cmd_xid),
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300109 sizeof(pcmd->body.context.req));
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300110
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300111 /* fill command */
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);
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300117
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300118 /* send command */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300119 if (adap->ops->xfer_cmd) {
120 error = adap->ops->xfer_cmd(adap,
121 (uint8_t *) pcmd,
122 sizeof(pcmd->body.context.req)
123 + HEADER_SIZE,
124 (uint8_t *) prsp,
125 sizeof(prsp->body.context.rsp)
126 + HEADER_SIZE);
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300127 } else {
128 error = AS10X_CMD_ERROR;
129 }
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300130
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300131 if (error < 0)
132 goto out;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300133
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300134 /* 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);
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300137
138out:
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300139 LEAVE();
140 return error;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300141}
142
143/**
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -0300144 * as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300145 * @adap: pointer to AS10x bus adapter
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -0300146 * @mode: mode selected:
147 * - ON : 0x0 => eLNA always ON
148 * - OFF : 0x1 => eLNA always OFF
149 * - AUTO : 0x2 => eLNA follow hysteresis parameters
150 * to be ON or OFF
151 *
152 * Return 0 on success or negative value in case of error.
153 */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300154int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300155{
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300156 int error;
157 struct as10x_cmd_t *pcmd, *prsp;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300158
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300159 ENTER();
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300160
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300161 pcmd = adap->cmd;
162 prsp = adap->rsp;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300163
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300164 /* prepare command */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300165 as10x_cmd_build(pcmd, (++adap->cmd_xid),
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300166 sizeof(pcmd->body.cfg_change_mode.req));
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300167
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300168 /* fill command */
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;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300172
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300173 /* send command */
Sylwester Nawrocki34490a02011-11-06 16:31:50 -0300174 if (adap->ops->xfer_cmd) {
175 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300176 sizeof(pcmd->body.cfg_change_mode.req)
177 + HEADER_SIZE, (uint8_t *) prsp,
178 sizeof(prsp->body.cfg_change_mode.rsp)
179 + HEADER_SIZE);
180 } else {
181 error = AS10X_CMD_ERROR;
182 }
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300183
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300184 if (error < 0)
185 goto out;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300186
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300187 /* parse response */
188 error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300189
190out:
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300191 LEAVE();
192 return error;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300193}
194
195/**
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -0300196 * as10x_context_rsp_parse - Parse context command response
197 * @prsp: pointer to AS10x command response buffer
198 * @proc_id: id of the command
199 *
Masanari Iida6dc8f382012-10-31 11:52:45 -0300200 * Since the contex command response does not follow the common
Sylwester Nawrocki3b4544a2011-10-31 12:24:51 -0300201 * response, a specific parse function is required.
202 * Return 0 on success or negative value in case of error.
203 */
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300204int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
205{
206 int err;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300207
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300208 err = prsp->body.context.rsp.error;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300209
Devin Heitmuellere2e02ca2011-10-31 12:24:46 -0300210 if ((err == 0) &&
211 (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
212 return 0;
213 }
214 return AS10X_CMD_ERROR;
Pierrick Hascoet41b44e02011-10-31 12:24:39 -0300215}