]> Pileus Git - ~andy/linux/blob - drivers/staging/media/as102/as10x_cmd_stream.c
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux
[~andy/linux] / drivers / staging / media / as102 / as10x_cmd_stream.c
1 /*
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  */
19
20 #include <linux/kernel.h>
21 #include "as102_drv.h"
22 #include "as10x_cmd.h"
23
24 /**
25  * as10x_cmd_add_PID_filter - send add filter command to AS10x
26  * @adap:      pointer to AS10x bus adapter
27  * @filter:    TSFilter filter for DVB-T
28  *
29  * Return 0 on success or negative value in case of error.
30  */
31 int as10x_cmd_add_PID_filter(struct as10x_bus_adapter_t *adap,
32                              struct as10x_ts_filter *filter)
33 {
34         int error;
35         struct as10x_cmd_t *pcmd, *prsp;
36
37         pcmd = adap->cmd;
38         prsp = adap->rsp;
39
40         /* prepare command */
41         as10x_cmd_build(pcmd, (++adap->cmd_xid),
42                         sizeof(pcmd->body.add_pid_filter.req));
43
44         /* fill command */
45         pcmd->body.add_pid_filter.req.proc_id =
46                 cpu_to_le16(CONTROL_PROC_SETFILTER);
47         pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid);
48         pcmd->body.add_pid_filter.req.stream_type = filter->type;
49
50         if (filter->idx < 16)
51                 pcmd->body.add_pid_filter.req.idx = filter->idx;
52         else
53                 pcmd->body.add_pid_filter.req.idx = 0xFF;
54
55         /* send command */
56         if (adap->ops->xfer_cmd) {
57                 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
58                                 sizeof(pcmd->body.add_pid_filter.req)
59                                 + HEADER_SIZE, (uint8_t *) prsp,
60                                 sizeof(prsp->body.add_pid_filter.rsp)
61                                 + HEADER_SIZE);
62         } else {
63                 error = AS10X_CMD_ERROR;
64         }
65
66         if (error < 0)
67                 goto out;
68
69         /* parse response */
70         error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP);
71
72         if (error == 0) {
73                 /* Response OK -> get response data */
74                 filter->idx = prsp->body.add_pid_filter.rsp.filter_id;
75         }
76
77 out:
78         return error;
79 }
80
81 /**
82  * as10x_cmd_del_PID_filter - Send delete filter command to AS10x
83  * @adap:         pointer to AS10x bus adapte
84  * @pid_value:    PID to delete
85  *
86  * Return 0 on success or negative value in case of error.
87  */
88 int as10x_cmd_del_PID_filter(struct as10x_bus_adapter_t *adap,
89                              uint16_t pid_value)
90 {
91         int error;
92         struct as10x_cmd_t *pcmd, *prsp;
93
94         pcmd = adap->cmd;
95         prsp = adap->rsp;
96
97         /* prepare command */
98         as10x_cmd_build(pcmd, (++adap->cmd_xid),
99                         sizeof(pcmd->body.del_pid_filter.req));
100
101         /* fill command */
102         pcmd->body.del_pid_filter.req.proc_id =
103                 cpu_to_le16(CONTROL_PROC_REMOVEFILTER);
104         pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value);
105
106         /* send command */
107         if (adap->ops->xfer_cmd) {
108                 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
109                                 sizeof(pcmd->body.del_pid_filter.req)
110                                 + HEADER_SIZE, (uint8_t *) prsp,
111                                 sizeof(prsp->body.del_pid_filter.rsp)
112                                 + HEADER_SIZE);
113         } else {
114                 error = AS10X_CMD_ERROR;
115         }
116
117         if (error < 0)
118                 goto out;
119
120         /* parse response */
121         error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP);
122
123 out:
124         return error;
125 }
126
127 /**
128  * as10x_cmd_start_streaming - Send start streaming command to AS10x
129  * @adap:   pointer to AS10x bus adapter
130  *
131  * Return 0 on success or negative value in case of error.
132  */
133 int as10x_cmd_start_streaming(struct as10x_bus_adapter_t *adap)
134 {
135         int error;
136         struct as10x_cmd_t *pcmd, *prsp;
137
138         pcmd = adap->cmd;
139         prsp = adap->rsp;
140
141         /* prepare command */
142         as10x_cmd_build(pcmd, (++adap->cmd_xid),
143                         sizeof(pcmd->body.start_streaming.req));
144
145         /* fill command */
146         pcmd->body.start_streaming.req.proc_id =
147                 cpu_to_le16(CONTROL_PROC_START_STREAMING);
148
149         /* send command */
150         if (adap->ops->xfer_cmd) {
151                 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
152                                 sizeof(pcmd->body.start_streaming.req)
153                                 + HEADER_SIZE, (uint8_t *) prsp,
154                                 sizeof(prsp->body.start_streaming.rsp)
155                                 + HEADER_SIZE);
156         } else {
157                 error = AS10X_CMD_ERROR;
158         }
159
160         if (error < 0)
161                 goto out;
162
163         /* parse response */
164         error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP);
165
166 out:
167         return error;
168 }
169
170 /**
171  * as10x_cmd_stop_streaming - Send stop streaming command to AS10x
172  * @adap:   pointer to AS10x bus adapter
173  *
174  * Return 0 on success or negative value in case of error.
175  */
176 int as10x_cmd_stop_streaming(struct as10x_bus_adapter_t *adap)
177 {
178         int8_t error;
179         struct as10x_cmd_t *pcmd, *prsp;
180
181         pcmd = adap->cmd;
182         prsp = adap->rsp;
183
184         /* prepare command */
185         as10x_cmd_build(pcmd, (++adap->cmd_xid),
186                         sizeof(pcmd->body.stop_streaming.req));
187
188         /* fill command */
189         pcmd->body.stop_streaming.req.proc_id =
190                 cpu_to_le16(CONTROL_PROC_STOP_STREAMING);
191
192         /* send command */
193         if (adap->ops->xfer_cmd) {
194                 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
195                                 sizeof(pcmd->body.stop_streaming.req)
196                                 + HEADER_SIZE, (uint8_t *) prsp,
197                                 sizeof(prsp->body.stop_streaming.rsp)
198                                 + HEADER_SIZE);
199         } else {
200                 error = AS10X_CMD_ERROR;
201         }
202
203         if (error < 0)
204                 goto out;
205
206         /* parse response */
207         error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP);
208
209 out:
210         return error;
211 }