[media] staging: as102: Initial import from Abilis
[deliverable/linux.git] / drivers / staging / media / as102 / as10x_cmd_stream.c
CommitLineData
41b44e04
PH
1/**
2
3 \file as10x_cmd_stream.c
4
5 \version $Id$
6
7 \author: S. Martinelli
8
9 ----------------------------------------------------------------------------\n
10 (c) Copyright Abilis Systems SARL 2005-2009 All rigths reserved \n
11 www.abilis.com \n
12 ----------------------------------------------------------------------------\n
13
14 \brief AS10x CMD, stream services
15
16 AS10x CMD management: build command buffer, send command through
17 selected port and wait for the response when required.
18
19*/
20
21
22#if defined(LINUX) && defined(__KERNEL__) /* linux kernel implementation */
23#include <linux/kernel.h>
24#include "as102_drv.h"
25#elif defined(WIN32)
26 #if defined(DDK) /* win32 ddk implementation */
27 #include "wdm.h"
28 #include "Device.h"
29 #include "endian_mgmt.h" /* FIXME */
30 #else /* win32 sdk implementation */
31 #include <windows.h>
32 #include "types.h"
33 #include "util.h"
34 #include "as10x_handle.h"
35 #include "endian_mgmt.h"
36 #endif
37#else /* all other cases */
38 #include <string.h>
39 #include "types.h"
40 #include "util.h"
41 #include "as10x_handle.h"
42 #include "endian_mgmt.h" /* FIXME */
43#endif /* __KERNEL__ */
44
45#include "as10x_cmd.h"
46
47
48/**
49 \brief send add filter command to AS10x
50 \param phandle: pointer to AS10x handle
51 \param filter: TSFilter filter for DVB-T
52 \param pfilter_handle: pointer where to store filter handle
53 \return 0 when no error, < 0 in case of error.
54 \callgraph
55*/
56int as10x_cmd_add_PID_filter(as10x_handle_t* phandle,
57 struct as10x_ts_filter *filter) {
58 int error;
59 struct as10x_cmd_t *pcmd, *prsp;
60
61 ENTER();
62
63 pcmd = phandle->cmd;
64 prsp = phandle->rsp;
65
66 /* prepare command */
67 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
68 sizeof(pcmd->body.add_pid_filter.req));
69
70 /* fill command */
71 pcmd->body.add_pid_filter.req.proc_id = cpu_to_le16(CONTROL_PROC_SETFILTER);
72 pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid);
73 pcmd->body.add_pid_filter.req.stream_type = filter->type;
74
75 if(filter->idx < 16)
76 pcmd->body.add_pid_filter.req.idx = filter->idx;
77 else
78 pcmd->body.add_pid_filter.req.idx = 0xFF;
79
80 /* send command */
81 if(phandle->ops->xfer_cmd) {
82 error = phandle->ops->xfer_cmd(phandle,
83 (uint8_t *) pcmd,
84 sizeof(pcmd->body.add_pid_filter.req) + HEADER_SIZE,
85 (uint8_t *) prsp,
86 sizeof(prsp->body.add_pid_filter.rsp) + HEADER_SIZE);
87 }
88 else{
89 error = AS10X_CMD_ERROR;
90 }
91
92 if(error < 0) {
93 goto out;
94 }
95
96 /* parse response */
97 error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP);
98
99 if(error == 0) {
100 /* Response OK -> get response data */
101 filter->idx = prsp->body.add_pid_filter.rsp.filter_id;
102 }
103
104out:
105 LEAVE();
106 return(error);
107}
108
109/**
110 \brief Send delete filter command to AS10x
111 \param phandle: pointer to AS10x handle
112 \param filter_handle: filter handle
113 \return 0 when no error, < 0 in case of error.
114 \callgraph
115*/
116int as10x_cmd_del_PID_filter(as10x_handle_t* phandle,
117 uint16_t pid_value)
118{
119
120 int error;
121 struct as10x_cmd_t *pcmd, *prsp;
122
123 ENTER();
124
125 pcmd = phandle->cmd;
126 prsp = phandle->rsp;
127
128 /* prepare command */
129 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
130 sizeof(pcmd->body.del_pid_filter.req));
131
132 /* fill command */
133 pcmd->body.del_pid_filter.req.proc_id = cpu_to_le16(CONTROL_PROC_REMOVEFILTER);
134 pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value);
135
136 /* send command */
137 if(phandle->ops->xfer_cmd){
138 error = phandle->ops->xfer_cmd(phandle,
139 (uint8_t *) pcmd,
140 sizeof(pcmd->body.del_pid_filter.req) + HEADER_SIZE,
141 (uint8_t *) prsp,
142 sizeof(prsp->body.del_pid_filter.rsp) + HEADER_SIZE);
143 }
144 else{
145 error = AS10X_CMD_ERROR;
146 }
147
148 if(error < 0) {
149 goto out;
150 }
151
152 /* parse response */
153 error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP);
154
155out:
156 LEAVE();
157 return(error);
158}
159
160/**
161 \brief Send start streaming command to AS10x
162 \param phandle: pointer to AS10x handle
163 \return 0 when no error, < 0 in case of error. 
164 \callgraph
165*/
166int as10x_cmd_start_streaming(as10x_handle_t* phandle)
167{
168 int error;
169 struct as10x_cmd_t *pcmd, *prsp;
170
171 ENTER();
172
173 pcmd = phandle->cmd;
174 prsp = phandle->rsp;
175
176 /* prepare command */
177 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
178 sizeof(pcmd->body.start_streaming.req));
179
180 /* fill command */
181 pcmd->body.start_streaming.req.proc_id =
182 cpu_to_le16(CONTROL_PROC_START_STREAMING);
183
184 /* send command */
185 if(phandle->ops->xfer_cmd){
186 error = phandle->ops->xfer_cmd(phandle,
187 (uint8_t *) pcmd,
188 sizeof(pcmd->body.start_streaming.req) + HEADER_SIZE,
189 (uint8_t *) prsp,
190 sizeof(prsp->body.start_streaming.rsp) + HEADER_SIZE);
191 }
192 else{
193 error = AS10X_CMD_ERROR;
194 }
195
196 if(error < 0) {
197 goto out;
198 }
199
200 /* parse response */
201 error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP);
202
203out:
204 LEAVE();
205 return(error);
206}
207
208/**
209 \brief Send stop streaming command to AS10x
210 \param phandle: pointer to AS10x handle
211 \return 0 when no error, < 0 in case of error. 
212 \callgraph
213*/
214int as10x_cmd_stop_streaming(as10x_handle_t* phandle)
215{
216 int8_t error;
217 struct as10x_cmd_t *pcmd, *prsp;
218
219 ENTER();
220
221 pcmd = phandle->cmd;
222 prsp = phandle->rsp;
223
224 /* prepare command */
225 as10x_cmd_build(pcmd, (++phandle->cmd_xid),
226 sizeof(pcmd->body.stop_streaming.req));
227
228 /* fill command */
229 pcmd->body.stop_streaming.req.proc_id =
230 cpu_to_le16(CONTROL_PROC_STOP_STREAMING);
231
232 /* send command */
233 if(phandle->ops->xfer_cmd){
234 error = phandle->ops->xfer_cmd(phandle,
235 (uint8_t *) pcmd,
236 sizeof(pcmd->body.stop_streaming.req) + HEADER_SIZE,
237 (uint8_t *) prsp,
238 sizeof(prsp->body.stop_streaming.rsp) + HEADER_SIZE);
239 }
240 else{
241 error = AS10X_CMD_ERROR;
242 }
243
244 if(error < 0) {
245 goto out;
246 }
247
248 /* parse response */
249 error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP);
250
251out:
252 LEAVE();
253 return(error);
254}
255
256
This page took 0.038532 seconds and 5 git commands to generate.