13e0a4e85SThomas Gleixner// SPDX-License-Identifier: GPL-2.0-or-later
2315cadc4SPierrick Hascoet/*
3315cadc4SPierrick Hascoet * Abilis Systems Single DVB-T Receiver
4315cadc4SPierrick Hascoet * Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
5315cadc4SPierrick Hascoet */
6f080c2efSPiotr Chmura
741b44e04SPierrick Hascoet#include <linux/kernel.h>
841b44e04SPierrick Hascoet#include "as102_drv.h"
941b44e04SPierrick Hascoet#include "as10x_cmd.h"
1041b44e04SPierrick Hascoet
1141b44e04SPierrick Hascoet/**
123b4544a3SSylwester Nawrocki * as10x_cmd_add_PID_filter - send add filter command to AS10x
1334490a0aSSylwester Nawrocki * @adap:      pointer to AS10x bus adapter
143b4544a3SSylwester Nawrocki * @filter:    TSFilter filter for DVB-T
153b4544a3SSylwester Nawrocki *
163b4544a3SSylwester Nawrocki * Return 0 on success or negative value in case of error.
173b4544a3SSylwester Nawrocki */
1834490a0aSSylwester Nawrockiint as10x_cmd_add_PID_filter(struct as10x_bus_adapter_t *adap,
1979848e9aSDevin Heitmueller			     struct as10x_ts_filter *filter)
2079848e9aSDevin Heitmueller{
2179848e9aSDevin Heitmueller	int error;
2279848e9aSDevin Heitmueller	struct as10x_cmd_t *pcmd, *prsp;
2379848e9aSDevin Heitmueller
2434490a0aSSylwester Nawrocki	pcmd = adap->cmd;
2534490a0aSSylwester Nawrocki	prsp = adap->rsp;
2679848e9aSDevin Heitmueller
2779848e9aSDevin Heitmueller	/* prepare command */
2834490a0aSSylwester Nawrocki	as10x_cmd_build(pcmd, (++adap->cmd_xid),
2979848e9aSDevin Heitmueller			sizeof(pcmd->body.add_pid_filter.req));
3079848e9aSDevin Heitmueller
3179848e9aSDevin Heitmueller	/* fill command */
3279848e9aSDevin Heitmueller	pcmd->body.add_pid_filter.req.proc_id =
3379848e9aSDevin Heitmueller		cpu_to_le16(CONTROL_PROC_SETFILTER);
3479848e9aSDevin Heitmueller	pcmd->body.add_pid_filter.req.pid = cpu_to_le16(filter->pid);
3579848e9aSDevin Heitmueller	pcmd->body.add_pid_filter.req.stream_type = filter->type;
3679848e9aSDevin Heitmueller
3779848e9aSDevin Heitmueller	if (filter->idx < 16)
3879848e9aSDevin Heitmueller		pcmd->body.add_pid_filter.req.idx = filter->idx;
3979848e9aSDevin Heitmueller	else
4079848e9aSDevin Heitmueller		pcmd->body.add_pid_filter.req.idx = 0xFF;
4179848e9aSDevin Heitmueller
4279848e9aSDevin Heitmueller	/* send command */
4334490a0aSSylwester Nawrocki	if (adap->ops->xfer_cmd) {
4434490a0aSSylwester Nawrocki		error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
4579848e9aSDevin Heitmueller				sizeof(pcmd->body.add_pid_filter.req)
4679848e9aSDevin Heitmueller				+ HEADER_SIZE, (uint8_t *) prsp,
4779848e9aSDevin Heitmueller				sizeof(prsp->body.add_pid_filter.rsp)
4879848e9aSDevin Heitmueller				+ HEADER_SIZE);
4979848e9aSDevin Heitmueller	} else {
5079848e9aSDevin Heitmueller		error = AS10X_CMD_ERROR;
5179848e9aSDevin Heitmueller	}
5279848e9aSDevin Heitmueller
5379848e9aSDevin Heitmueller	if (error < 0)
5479848e9aSDevin Heitmueller		goto out;
5579848e9aSDevin Heitmueller
5679848e9aSDevin Heitmueller	/* parse response */
5779848e9aSDevin Heitmueller	error = as10x_rsp_parse(prsp, CONTROL_PROC_SETFILTER_RSP);
5879848e9aSDevin Heitmueller
5979848e9aSDevin Heitmueller	if (error == 0) {
6079848e9aSDevin Heitmueller		/* Response OK -> get response data */
6179848e9aSDevin Heitmueller		filter->idx = prsp->body.add_pid_filter.rsp.filter_id;
6279848e9aSDevin Heitmueller	}
6341b44e04SPierrick Hascoet
6441b44e04SPierrick Hascoetout:
6579848e9aSDevin Heitmueller	return error;
6641b44e04SPierrick Hascoet}
6741b44e04SPierrick Hascoet
6841b44e04SPierrick Hascoet/**
693b4544a3SSylwester Nawrocki * as10x_cmd_del_PID_filter - Send delete filter command to AS10x
7034490a0aSSylwester Nawrocki * @adap:         pointer to AS10x bus adapte
713b4544a3SSylwester Nawrocki * @pid_value:    PID to delete
723b4544a3SSylwester Nawrocki *
733b4544a3SSylwester Nawrocki * Return 0 on success or negative value in case of error.
743b4544a3SSylwester Nawrocki */
7534490a0aSSylwester Nawrockiint as10x_cmd_del_PID_filter(struct as10x_bus_adapter_t *adap,
7641b44e04SPierrick Hascoet			     uint16_t pid_value)
7741b44e04SPierrick Hascoet{
7879848e9aSDevin Heitmueller	int error;
7979848e9aSDevin Heitmueller	struct as10x_cmd_t *pcmd, *prsp;
8041b44e04SPierrick Hascoet
8134490a0aSSylwester Nawrocki	pcmd = adap->cmd;
8234490a0aSSylwester Nawrocki	prsp = adap->rsp;
8341b44e04SPierrick Hascoet
8479848e9aSDevin Heitmueller	/* prepare command */
8534490a0aSSylwester Nawrocki	as10x_cmd_build(pcmd, (++adap->cmd_xid),
8679848e9aSDevin Heitmueller			sizeof(pcmd->body.del_pid_filter.req));
8741b44e04SPierrick Hascoet
8879848e9aSDevin Heitmueller	/* fill command */
8979848e9aSDevin Heitmueller	pcmd->body.del_pid_filter.req.proc_id =
9079848e9aSDevin Heitmueller		cpu_to_le16(CONTROL_PROC_REMOVEFILTER);
9179848e9aSDevin Heitmueller	pcmd->body.del_pid_filter.req.pid = cpu_to_le16(pid_value);
9241b44e04SPierrick Hascoet
9379848e9aSDevin Heitmueller	/* send command */
9434490a0aSSylwester Nawrocki	if (adap->ops->xfer_cmd) {
9534490a0aSSylwester Nawrocki		error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
9679848e9aSDevin Heitmueller				sizeof(pcmd->body.del_pid_filter.req)
9779848e9aSDevin Heitmueller				+ HEADER_SIZE, (uint8_t *) prsp,
9879848e9aSDevin Heitmueller				sizeof(prsp->body.del_pid_filter.rsp)
9979848e9aSDevin Heitmueller				+ HEADER_SIZE);
10079848e9aSDevin Heitmueller	} else {
10179848e9aSDevin Heitmueller		error = AS10X_CMD_ERROR;
10279848e9aSDevin Heitmueller	}
10341b44e04SPierrick Hascoet
10479848e9aSDevin Heitmueller	if (error < 0)
10579848e9aSDevin Heitmueller		goto out;
10641b44e04SPierrick Hascoet
10779848e9aSDevin Heitmueller	/* parse response */
10879848e9aSDevin Heitmueller	error = as10x_rsp_parse(prsp, CONTROL_PROC_REMOVEFILTER_RSP);
10941b44e04SPierrick Hascoet
11041b44e04SPierrick Hascoetout:
11179848e9aSDevin Heitmueller	return error;
11241b44e04SPierrick Hascoet}
11341b44e04SPierrick Hascoet
11441b44e04SPierrick Hascoet/**
1153b4544a3SSylwester Nawrocki * as10x_cmd_start_streaming - Send start streaming command to AS10x
11634490a0aSSylwester Nawrocki * @adap:   pointer to AS10x bus adapter
1173b4544a3SSylwester Nawrocki *
1183b4544a3SSylwester Nawrocki * Return 0 on success or negative value in case of error.
1193b4544a3SSylwester Nawrocki */
12034490a0aSSylwester Nawrockiint as10x_cmd_start_streaming(struct as10x_bus_adapter_t *adap)
12141b44e04SPierrick Hascoet{
12279848e9aSDevin Heitmueller	int error;
12379848e9aSDevin Heitmueller	struct as10x_cmd_t *pcmd, *prsp;
12441b44e04SPierrick Hascoet
12534490a0aSSylwester Nawrocki	pcmd = adap->cmd;
12634490a0aSSylwester Nawrocki	prsp = adap->rsp;
12741b44e04SPierrick Hascoet
12879848e9aSDevin Heitmueller	/* prepare command */
12934490a0aSSylwester Nawrocki	as10x_cmd_build(pcmd, (++adap->cmd_xid),
13079848e9aSDevin Heitmueller			sizeof(pcmd->body.start_streaming.req));
13141b44e04SPierrick Hascoet
13279848e9aSDevin Heitmueller	/* fill command */
13379848e9aSDevin Heitmueller	pcmd->body.start_streaming.req.proc_id =
13479848e9aSDevin Heitmueller		cpu_to_le16(CONTROL_PROC_START_STREAMING);
13541b44e04SPierrick Hascoet
13679848e9aSDevin Heitmueller	/* send command */
13734490a0aSSylwester Nawrocki	if (adap->ops->xfer_cmd) {
13834490a0aSSylwester Nawrocki		error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
13979848e9aSDevin Heitmueller				sizeof(pcmd->body.start_streaming.req)
14079848e9aSDevin Heitmueller				+ HEADER_SIZE, (uint8_t *) prsp,
14179848e9aSDevin Heitmueller				sizeof(prsp->body.start_streaming.rsp)
14279848e9aSDevin Heitmueller				+ HEADER_SIZE);
14379848e9aSDevin Heitmueller	} else {
14479848e9aSDevin Heitmueller		error = AS10X_CMD_ERROR;
14579848e9aSDevin Heitmueller	}
14641b44e04SPierrick Hascoet
14779848e9aSDevin Heitmueller	if (error < 0)
14879848e9aSDevin Heitmueller		goto out;
14941b44e04SPierrick Hascoet
15079848e9aSDevin Heitmueller	/* parse response */
15179848e9aSDevin Heitmueller	error = as10x_rsp_parse(prsp, CONTROL_PROC_START_STREAMING_RSP);
15241b44e04SPierrick Hascoet
15341b44e04SPierrick Hascoetout:
15479848e9aSDevin Heitmueller	return error;
15541b44e04SPierrick Hascoet}
15641b44e04SPierrick Hascoet
15741b44e04SPierrick Hascoet/**
1583b4544a3SSylwester Nawrocki * as10x_cmd_stop_streaming - Send stop streaming command to AS10x
15934490a0aSSylwester Nawrocki * @adap:   pointer to AS10x bus adapter
1603b4544a3SSylwester Nawrocki *
1613b4544a3SSylwester Nawrocki * Return 0 on success or negative value in case of error.
1623b4544a3SSylwester Nawrocki */
16334490a0aSSylwester Nawrockiint as10x_cmd_stop_streaming(struct as10x_bus_adapter_t *adap)
16441b44e04SPierrick Hascoet{
16579848e9aSDevin Heitmueller	int8_t error;
16679848e9aSDevin Heitmueller	struct as10x_cmd_t *pcmd, *prsp;
16741b44e04SPierrick Hascoet
16834490a0aSSylwester Nawrocki	pcmd = adap->cmd;
16934490a0aSSylwester Nawrocki	prsp = adap->rsp;
17041b44e04SPierrick Hascoet
17179848e9aSDevin Heitmueller	/* prepare command */
17234490a0aSSylwester Nawrocki	as10x_cmd_build(pcmd, (++adap->cmd_xid),
17379848e9aSDevin Heitmueller			sizeof(pcmd->body.stop_streaming.req));
17441b44e04SPierrick Hascoet
17579848e9aSDevin Heitmueller	/* fill command */
17679848e9aSDevin Heitmueller	pcmd->body.stop_streaming.req.proc_id =
17779848e9aSDevin Heitmueller		cpu_to_le16(CONTROL_PROC_STOP_STREAMING);
17841b44e04SPierrick Hascoet
17979848e9aSDevin Heitmueller	/* send command */
18034490a0aSSylwester Nawrocki	if (adap->ops->xfer_cmd) {
18134490a0aSSylwester Nawrocki		error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
18279848e9aSDevin Heitmueller				sizeof(pcmd->body.stop_streaming.req)
18379848e9aSDevin Heitmueller				+ HEADER_SIZE, (uint8_t *) prsp,
18479848e9aSDevin Heitmueller				sizeof(prsp->body.stop_streaming.rsp)
18579848e9aSDevin Heitmueller				+ HEADER_SIZE);
18679848e9aSDevin Heitmueller	} else {
18779848e9aSDevin Heitmueller		error = AS10X_CMD_ERROR;
18879848e9aSDevin Heitmueller	}
18941b44e04SPierrick Hascoet
19079848e9aSDevin Heitmueller	if (error < 0)
19179848e9aSDevin Heitmueller		goto out;
19241b44e04SPierrick Hascoet
19379848e9aSDevin Heitmueller	/* parse response */
19479848e9aSDevin Heitmueller	error = as10x_rsp_parse(prsp, CONTROL_PROC_STOP_STREAMING_RSP);
19541b44e04SPierrick Hascoet
19641b44e04SPierrick Hascoetout:
19779848e9aSDevin Heitmueller	return error;
19841b44e04SPierrick Hascoet}
199