Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
as10x_cmd_cfg.c
Go to the documentation of this file.
1 /*
2  * Abilis Systems Single DVB-T Receiver
3  * Copyright (C) 2008 Pierrick Hascoet <[email protected]>
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  */
19 
20 #include <linux/kernel.h>
21 #include "as102_drv.h"
22 #include "as10x_types.h"
23 #include "as10x_cmd.h"
24 
25 /***************************/
26 /* FUNCTION DEFINITION */
27 /***************************/
28 
38  uint32_t *pvalue)
39 {
40  int error;
41  struct as10x_cmd_t *pcmd, *prsp;
42 
43  ENTER();
44 
45  pcmd = adap->cmd;
46  prsp = adap->rsp;
47 
48  /* prepare command */
49  as10x_cmd_build(pcmd, (++adap->cmd_xid),
50  sizeof(pcmd->body.context.req));
51 
52  /* fill command */
54  pcmd->body.context.req.tag = cpu_to_le16(tag);
56 
57  /* send command */
58  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);
66  } else {
67  error = AS10X_CMD_ERROR;
68  }
69 
70  if (error < 0)
71  goto out;
72 
73  /* parse response: context command do not follow the common response */
74  /* structure -> specific handling response parse required */
76 
77  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  }
82 
83 out:
84  LEAVE();
85  return error;
86 }
87 
98 {
99  int error;
100  struct as10x_cmd_t *pcmd, *prsp;
101 
102  ENTER();
103 
104  pcmd = adap->cmd;
105  prsp = adap->rsp;
106 
107  /* prepare command */
108  as10x_cmd_build(pcmd, (++adap->cmd_xid),
109  sizeof(pcmd->body.context.req));
110 
111  /* fill command */
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);
117 
118  /* send command */
119  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);
127  } else {
128  error = AS10X_CMD_ERROR;
129  }
130 
131  if (error < 0)
132  goto out;
133 
134  /* parse response: context command do not follow the common response */
135  /* structure -> specific handling response parse required */
137 
138 out:
139  LEAVE();
140  return error;
141 }
142 
155 {
156  int error;
157  struct as10x_cmd_t *pcmd, *prsp;
158 
159  ENTER();
160 
161  pcmd = adap->cmd;
162  prsp = adap->rsp;
163 
164  /* prepare command */
165  as10x_cmd_build(pcmd, (++adap->cmd_xid),
166  sizeof(pcmd->body.cfg_change_mode.req));
167 
168  /* fill command */
169  pcmd->body.cfg_change_mode.req.proc_id =
171  pcmd->body.cfg_change_mode.req.mode = mode;
172 
173  /* send command */
174  if (adap->ops->xfer_cmd) {
175  error = adap->ops->xfer_cmd(adap, (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)
179  + HEADER_SIZE);
180  } else {
181  error = AS10X_CMD_ERROR;
182  }
183 
184  if (error < 0)
185  goto out;
186 
187  /* parse response */
189 
190 out:
191  LEAVE();
192  return error;
193 }
194 
205 {
206  int err;
207 
208  err = prsp->body.context.rsp.error;
209 
210  if ((err == 0) &&
211  (le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
212  return 0;
213  }
214  return AS10X_CMD_ERROR;
215 }