1*3e0a4e85SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2d6317c68SMauro Carvalho Chehab /* 3d6317c68SMauro Carvalho Chehab * Abilis Systems Single DVB-T Receiver 4d6317c68SMauro Carvalho Chehab * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com> 5d6317c68SMauro Carvalho Chehab */ 6d6317c68SMauro Carvalho Chehab 7d6317c68SMauro Carvalho Chehab #include <linux/kernel.h> 8d6317c68SMauro Carvalho Chehab #include "as102_drv.h" 9d6317c68SMauro Carvalho Chehab #include "as10x_cmd.h" 10d6317c68SMauro Carvalho Chehab 11d6317c68SMauro Carvalho Chehab /** 12d6317c68SMauro Carvalho Chehab * as10x_cmd_add_PID_filter - send add filter command to AS10x 13d6317c68SMauro Carvalho Chehab * @adap: pointer to AS10x bus adapter 14d6317c68SMauro Carvalho Chehab * @filter: TSFilter filter for DVB-T 15d6317c68SMauro Carvalho Chehab * 16d6317c68SMauro Carvalho Chehab * Return 0 on success or negative value in case of error. 17d6317c68SMauro Carvalho Chehab */ 18d6317c68SMauro Carvalho Chehab int as10x_cmd_add_PID_filter(struct as10x_bus_adapter_t *adap, 19d6317c68SMauro Carvalho Chehab struct as10x_ts_filter *filter) 20d6317c68SMauro Carvalho Chehab { 21d6317c68SMauro Carvalho Chehab int error; 22d6317c68SMauro Carvalho Chehab struct as10x_cmd_t *pcmd, *prsp; 23d6317c68SMauro Carvalho Chehab 24d6317c68SMauro Carvalho Chehab pcmd = adap->cmd; 25d6317c68SMauro Carvalho Chehab prsp = adap->rsp; 26d6317c68SMauro Carvalho Chehab 27d6317c68SMauro Carvalho Chehab /* prepare command */ 28d6317c68SMauro Carvalho Chehab as10x_cmd_build(pcmd, (++adap->cmd_xid), 29d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.add_pid_filter.req)); 30d6317c68SMauro Carvalho Chehab 31d6317c68SMauro Carvalho Chehab /* fill command */ 32d6317c68SMauro Carvalho Chehab pcmd->body.add_pid_filter.req.proc_id = 33d6317c68SMauro Carvalho Chehab cpu_to_le16(CONTROL_PROC_SETFILTER); 34d6317c68SMauro Carvalho Chehab pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid); 35d6317c68SMauro Carvalho Chehab pcmd->body.add_pid_filter.req.stream_type = filter->type; 36d6317c68SMauro Carvalho Chehab 37d6317c68SMauro Carvalho Chehab if (filter->idx < 16) 38d6317c68SMauro Carvalho Chehab pcmd->body.add_pid_filter.req.idx = filter->idx; 39d6317c68SMauro Carvalho Chehab else 40d6317c68SMauro Carvalho Chehab pcmd->body.add_pid_filter.req.idx = 0xFF; 41d6317c68SMauro Carvalho Chehab 42d6317c68SMauro Carvalho Chehab /* send command */ 43d6317c68SMauro Carvalho Chehab if (adap->ops->xfer_cmd) { 44d6317c68SMauro Carvalho Chehab error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd, 45d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.add_pid_filter.req) 46d6317c68SMauro Carvalho Chehab + HEADER_SIZE, (uint8_t *) prsp, 47d6317c68SMauro Carvalho Chehab sizeof(prsp->body.add_pid_filter.rsp) 48d6317c68SMauro Carvalho Chehab + HEADER_SIZE); 49d6317c68SMauro Carvalho Chehab } else { 50d6317c68SMauro Carvalho Chehab error = AS10X_CMD_ERROR; 51d6317c68SMauro Carvalho Chehab } 52d6317c68SMauro Carvalho Chehab 53d6317c68SMauro Carvalho Chehab if (error < 0) 54d6317c68SMauro Carvalho Chehab goto out; 55d6317c68SMauro Carvalho Chehab 56d6317c68SMauro Carvalho Chehab /* parse response */ 57d6317c68SMauro Carvalho Chehab error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP); 58d6317c68SMauro Carvalho Chehab 59d6317c68SMauro Carvalho Chehab if (error == 0) { 60d6317c68SMauro Carvalho Chehab /* Response OK -> get response data */ 61d6317c68SMauro Carvalho Chehab filter->idx = prsp->body.add_pid_filter.rsp.filter_id; 62d6317c68SMauro Carvalho Chehab } 63d6317c68SMauro Carvalho Chehab 64d6317c68SMauro Carvalho Chehab out: 65d6317c68SMauro Carvalho Chehab return error; 66d6317c68SMauro Carvalho Chehab } 67d6317c68SMauro Carvalho Chehab 68d6317c68SMauro Carvalho Chehab /** 69d6317c68SMauro Carvalho Chehab * as10x_cmd_del_PID_filter - Send delete filter command to AS10x 70d6317c68SMauro Carvalho Chehab * @adap: pointer to AS10x bus adapte 71d6317c68SMauro Carvalho Chehab * @pid_value: PID to delete 72d6317c68SMauro Carvalho Chehab * 73d6317c68SMauro Carvalho Chehab * Return 0 on success or negative value in case of error. 74d6317c68SMauro Carvalho Chehab */ 75d6317c68SMauro Carvalho Chehab int as10x_cmd_del_PID_filter(struct as10x_bus_adapter_t *adap, 76d6317c68SMauro Carvalho Chehab uint16_t pid_value) 77d6317c68SMauro Carvalho Chehab { 78d6317c68SMauro Carvalho Chehab int error; 79d6317c68SMauro Carvalho Chehab struct as10x_cmd_t *pcmd, *prsp; 80d6317c68SMauro Carvalho Chehab 81d6317c68SMauro Carvalho Chehab pcmd = adap->cmd; 82d6317c68SMauro Carvalho Chehab prsp = adap->rsp; 83d6317c68SMauro Carvalho Chehab 84d6317c68SMauro Carvalho Chehab /* prepare command */ 85d6317c68SMauro Carvalho Chehab as10x_cmd_build(pcmd, (++adap->cmd_xid), 86d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.del_pid_filter.req)); 87d6317c68SMauro Carvalho Chehab 88d6317c68SMauro Carvalho Chehab /* fill command */ 89d6317c68SMauro Carvalho Chehab pcmd->body.del_pid_filter.req.proc_id = 90d6317c68SMauro Carvalho Chehab cpu_to_le16(CONTROL_PROC_REMOVEFILTER); 91d6317c68SMauro Carvalho Chehab pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value); 92d6317c68SMauro Carvalho Chehab 93d6317c68SMauro Carvalho Chehab /* send command */ 94d6317c68SMauro Carvalho Chehab if (adap->ops->xfer_cmd) { 95d6317c68SMauro Carvalho Chehab error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd, 96d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.del_pid_filter.req) 97d6317c68SMauro Carvalho Chehab + HEADER_SIZE, (uint8_t *) prsp, 98d6317c68SMauro Carvalho Chehab sizeof(prsp->body.del_pid_filter.rsp) 99d6317c68SMauro Carvalho Chehab + HEADER_SIZE); 100d6317c68SMauro Carvalho Chehab } else { 101d6317c68SMauro Carvalho Chehab error = AS10X_CMD_ERROR; 102d6317c68SMauro Carvalho Chehab } 103d6317c68SMauro Carvalho Chehab 104d6317c68SMauro Carvalho Chehab if (error < 0) 105d6317c68SMauro Carvalho Chehab goto out; 106d6317c68SMauro Carvalho Chehab 107d6317c68SMauro Carvalho Chehab /* parse response */ 108d6317c68SMauro Carvalho Chehab error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP); 109d6317c68SMauro Carvalho Chehab 110d6317c68SMauro Carvalho Chehab out: 111d6317c68SMauro Carvalho Chehab return error; 112d6317c68SMauro Carvalho Chehab } 113d6317c68SMauro Carvalho Chehab 114d6317c68SMauro Carvalho Chehab /** 115d6317c68SMauro Carvalho Chehab * as10x_cmd_start_streaming - Send start streaming command to AS10x 116d6317c68SMauro Carvalho Chehab * @adap: pointer to AS10x bus adapter 117d6317c68SMauro Carvalho Chehab * 118d6317c68SMauro Carvalho Chehab * Return 0 on success or negative value in case of error. 119d6317c68SMauro Carvalho Chehab */ 120d6317c68SMauro Carvalho Chehab int as10x_cmd_start_streaming(struct as10x_bus_adapter_t *adap) 121d6317c68SMauro Carvalho Chehab { 122d6317c68SMauro Carvalho Chehab int error; 123d6317c68SMauro Carvalho Chehab struct as10x_cmd_t *pcmd, *prsp; 124d6317c68SMauro Carvalho Chehab 125d6317c68SMauro Carvalho Chehab pcmd = adap->cmd; 126d6317c68SMauro Carvalho Chehab prsp = adap->rsp; 127d6317c68SMauro Carvalho Chehab 128d6317c68SMauro Carvalho Chehab /* prepare command */ 129d6317c68SMauro Carvalho Chehab as10x_cmd_build(pcmd, (++adap->cmd_xid), 130d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.start_streaming.req)); 131d6317c68SMauro Carvalho Chehab 132d6317c68SMauro Carvalho Chehab /* fill command */ 133d6317c68SMauro Carvalho Chehab pcmd->body.start_streaming.req.proc_id = 134d6317c68SMauro Carvalho Chehab cpu_to_le16(CONTROL_PROC_START_STREAMING); 135d6317c68SMauro Carvalho Chehab 136d6317c68SMauro Carvalho Chehab /* send command */ 137d6317c68SMauro Carvalho Chehab if (adap->ops->xfer_cmd) { 138d6317c68SMauro Carvalho Chehab error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd, 139d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.start_streaming.req) 140d6317c68SMauro Carvalho Chehab + HEADER_SIZE, (uint8_t *) prsp, 141d6317c68SMauro Carvalho Chehab sizeof(prsp->body.start_streaming.rsp) 142d6317c68SMauro Carvalho Chehab + HEADER_SIZE); 143d6317c68SMauro Carvalho Chehab } else { 144d6317c68SMauro Carvalho Chehab error = AS10X_CMD_ERROR; 145d6317c68SMauro Carvalho Chehab } 146d6317c68SMauro Carvalho Chehab 147d6317c68SMauro Carvalho Chehab if (error < 0) 148d6317c68SMauro Carvalho Chehab goto out; 149d6317c68SMauro Carvalho Chehab 150d6317c68SMauro Carvalho Chehab /* parse response */ 151d6317c68SMauro Carvalho Chehab error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP); 152d6317c68SMauro Carvalho Chehab 153d6317c68SMauro Carvalho Chehab out: 154d6317c68SMauro Carvalho Chehab return error; 155d6317c68SMauro Carvalho Chehab } 156d6317c68SMauro Carvalho Chehab 157d6317c68SMauro Carvalho Chehab /** 158d6317c68SMauro Carvalho Chehab * as10x_cmd_stop_streaming - Send stop streaming command to AS10x 159d6317c68SMauro Carvalho Chehab * @adap: pointer to AS10x bus adapter 160d6317c68SMauro Carvalho Chehab * 161d6317c68SMauro Carvalho Chehab * Return 0 on success or negative value in case of error. 162d6317c68SMauro Carvalho Chehab */ 163d6317c68SMauro Carvalho Chehab int as10x_cmd_stop_streaming(struct as10x_bus_adapter_t *adap) 164d6317c68SMauro Carvalho Chehab { 165d6317c68SMauro Carvalho Chehab int8_t error; 166d6317c68SMauro Carvalho Chehab struct as10x_cmd_t *pcmd, *prsp; 167d6317c68SMauro Carvalho Chehab 168d6317c68SMauro Carvalho Chehab pcmd = adap->cmd; 169d6317c68SMauro Carvalho Chehab prsp = adap->rsp; 170d6317c68SMauro Carvalho Chehab 171d6317c68SMauro Carvalho Chehab /* prepare command */ 172d6317c68SMauro Carvalho Chehab as10x_cmd_build(pcmd, (++adap->cmd_xid), 173d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.stop_streaming.req)); 174d6317c68SMauro Carvalho Chehab 175d6317c68SMauro Carvalho Chehab /* fill command */ 176d6317c68SMauro Carvalho Chehab pcmd->body.stop_streaming.req.proc_id = 177d6317c68SMauro Carvalho Chehab cpu_to_le16(CONTROL_PROC_STOP_STREAMING); 178d6317c68SMauro Carvalho Chehab 179d6317c68SMauro Carvalho Chehab /* send command */ 180d6317c68SMauro Carvalho Chehab if (adap->ops->xfer_cmd) { 181d6317c68SMauro Carvalho Chehab error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd, 182d6317c68SMauro Carvalho Chehab sizeof(pcmd->body.stop_streaming.req) 183d6317c68SMauro Carvalho Chehab + HEADER_SIZE, (uint8_t *) prsp, 184d6317c68SMauro Carvalho Chehab sizeof(prsp->body.stop_streaming.rsp) 185d6317c68SMauro Carvalho Chehab + HEADER_SIZE); 186d6317c68SMauro Carvalho Chehab } else { 187d6317c68SMauro Carvalho Chehab error = AS10X_CMD_ERROR; 188d6317c68SMauro Carvalho Chehab } 189d6317c68SMauro Carvalho Chehab 190d6317c68SMauro Carvalho Chehab if (error < 0) 191d6317c68SMauro Carvalho Chehab goto out; 192d6317c68SMauro Carvalho Chehab 193d6317c68SMauro Carvalho Chehab /* parse response */ 194d6317c68SMauro Carvalho Chehab error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP); 195d6317c68SMauro Carvalho Chehab 196d6317c68SMauro Carvalho Chehab out: 197d6317c68SMauro Carvalho Chehab return error; 198d6317c68SMauro Carvalho Chehab } 199