Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / usb / as102 / as10x_cmd_stream.c
blob126aea976639fde850e67f46df00398b4c6ac77e
1 /*
2 * Abilis Systems Single DVB-T Receiver
3 * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
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.
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.
16 #include <linux/kernel.h>
17 #include "as102_drv.h"
18 #include "as10x_cmd.h"
20 /**
21 * as10x_cmd_add_PID_filter - send add filter command to AS10x
22 * @adap: pointer to AS10x bus adapter
23 * @filter: TSFilter filter for DVB-T
25 * Return 0 on success or negative value in case of error.
27 int as10x_cmd_add_PID_filter(struct as10x_bus_adapter_t *adap,
28 struct as10x_ts_filter *filter)
30 int error;
31 struct as10x_cmd_t *pcmd, *prsp;
33 pcmd = adap->cmd;
34 prsp = adap->rsp;
36 /* prepare command */
37 as10x_cmd_build(pcmd, (++adap->cmd_xid),
38 sizeof(pcmd->body.add_pid_filter.req));
40 /* fill command */
41 pcmd->body.add_pid_filter.req.proc_id =
42 cpu_to_le16(CONTROL_PROC_SETFILTER);
43 pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid);
44 pcmd->body.add_pid_filter.req.stream_type = filter->type;
46 if (filter->idx < 16)
47 pcmd->body.add_pid_filter.req.idx = filter->idx;
48 else
49 pcmd->body.add_pid_filter.req.idx = 0xFF;
51 /* send command */
52 if (adap->ops->xfer_cmd) {
53 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
54 sizeof(pcmd->body.add_pid_filter.req)
55 + HEADER_SIZE, (uint8_t *) prsp,
56 sizeof(prsp->body.add_pid_filter.rsp)
57 + HEADER_SIZE);
58 } else {
59 error = AS10X_CMD_ERROR;
62 if (error < 0)
63 goto out;
65 /* parse response */
66 error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP);
68 if (error == 0) {
69 /* Response OK -> get response data */
70 filter->idx = prsp->body.add_pid_filter.rsp.filter_id;
73 out:
74 return error;
77 /**
78 * as10x_cmd_del_PID_filter - Send delete filter command to AS10x
79 * @adap: pointer to AS10x bus adapte
80 * @pid_value: PID to delete
82 * Return 0 on success or negative value in case of error.
84 int as10x_cmd_del_PID_filter(struct as10x_bus_adapter_t *adap,
85 uint16_t pid_value)
87 int error;
88 struct as10x_cmd_t *pcmd, *prsp;
90 pcmd = adap->cmd;
91 prsp = adap->rsp;
93 /* prepare command */
94 as10x_cmd_build(pcmd, (++adap->cmd_xid),
95 sizeof(pcmd->body.del_pid_filter.req));
97 /* fill command */
98 pcmd->body.del_pid_filter.req.proc_id =
99 cpu_to_le16(CONTROL_PROC_REMOVEFILTER);
100 pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value);
102 /* send command */
103 if (adap->ops->xfer_cmd) {
104 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
105 sizeof(pcmd->body.del_pid_filter.req)
106 + HEADER_SIZE, (uint8_t *) prsp,
107 sizeof(prsp->body.del_pid_filter.rsp)
108 + HEADER_SIZE);
109 } else {
110 error = AS10X_CMD_ERROR;
113 if (error < 0)
114 goto out;
116 /* parse response */
117 error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP);
119 out:
120 return error;
124 * as10x_cmd_start_streaming - Send start streaming command to AS10x
125 * @adap: pointer to AS10x bus adapter
127 * Return 0 on success or negative value in case of error.
129 int as10x_cmd_start_streaming(struct as10x_bus_adapter_t *adap)
131 int error;
132 struct as10x_cmd_t *pcmd, *prsp;
134 pcmd = adap->cmd;
135 prsp = adap->rsp;
137 /* prepare command */
138 as10x_cmd_build(pcmd, (++adap->cmd_xid),
139 sizeof(pcmd->body.start_streaming.req));
141 /* fill command */
142 pcmd->body.start_streaming.req.proc_id =
143 cpu_to_le16(CONTROL_PROC_START_STREAMING);
145 /* send command */
146 if (adap->ops->xfer_cmd) {
147 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
148 sizeof(pcmd->body.start_streaming.req)
149 + HEADER_SIZE, (uint8_t *) prsp,
150 sizeof(prsp->body.start_streaming.rsp)
151 + HEADER_SIZE);
152 } else {
153 error = AS10X_CMD_ERROR;
156 if (error < 0)
157 goto out;
159 /* parse response */
160 error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP);
162 out:
163 return error;
167 * as10x_cmd_stop_streaming - Send stop streaming command to AS10x
168 * @adap: pointer to AS10x bus adapter
170 * Return 0 on success or negative value in case of error.
172 int as10x_cmd_stop_streaming(struct as10x_bus_adapter_t *adap)
174 int8_t error;
175 struct as10x_cmd_t *pcmd, *prsp;
177 pcmd = adap->cmd;
178 prsp = adap->rsp;
180 /* prepare command */
181 as10x_cmd_build(pcmd, (++adap->cmd_xid),
182 sizeof(pcmd->body.stop_streaming.req));
184 /* fill command */
185 pcmd->body.stop_streaming.req.proc_id =
186 cpu_to_le16(CONTROL_PROC_STOP_STREAMING);
188 /* send command */
189 if (adap->ops->xfer_cmd) {
190 error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
191 sizeof(pcmd->body.stop_streaming.req)
192 + HEADER_SIZE, (uint8_t *) prsp,
193 sizeof(prsp->body.stop_streaming.rsp)
194 + HEADER_SIZE);
195 } else {
196 error = AS10X_CMD_ERROR;
199 if (error < 0)
200 goto out;
202 /* parse response */
203 error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP);
205 out:
206 return error;