2011-10-31 23:24:49 +08:00
|
|
|
/*
|
|
|
|
* Abilis Systems Single DVB-T Receiver
|
|
|
|
* Copyright (C) 2008 Pierrick Hascoet <pierrick.hascoet@abilis.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
2011-10-31 23:24:39 +08:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include "as102_drv.h"
|
|
|
|
#include "as10x_cmd.h"
|
|
|
|
|
|
|
|
/***************************/
|
|
|
|
/* FUNCTION DEFINITION */
|
|
|
|
/***************************/
|
|
|
|
|
|
|
|
/**
|
2011-10-31 23:24:51 +08:00
|
|
|
* as10x_cmd_get_context - Send get context command to AS10x
|
2011-11-07 03:31:50 +08:00
|
|
|
* @adap: pointer to AS10x bus adapter
|
2011-10-31 23:24:51 +08:00
|
|
|
* @tag: context tag
|
|
|
|
* @pvalue: pointer where to store context value read
|
|
|
|
*
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-11-07 03:31:50 +08:00
|
|
|
int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
|
2011-10-31 23:24:39 +08:00
|
|
|
uint32_t *pvalue)
|
|
|
|
{
|
2011-10-31 23:24:46 +08:00
|
|
|
int error;
|
|
|
|
struct as10x_cmd_t *pcmd, *prsp;
|
|
|
|
|
2011-11-07 03:31:50 +08:00
|
|
|
pcmd = adap->cmd;
|
|
|
|
prsp = adap->rsp;
|
2011-10-31 23:24:46 +08:00
|
|
|
|
|
|
|
/* prepare command */
|
2011-11-07 03:31:50 +08:00
|
|
|
as10x_cmd_build(pcmd, (++adap->cmd_xid),
|
2011-10-31 23:24:46 +08:00
|
|
|
sizeof(pcmd->body.context.req));
|
|
|
|
|
|
|
|
/* fill command */
|
|
|
|
pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
|
|
|
|
pcmd->body.context.req.tag = cpu_to_le16(tag);
|
|
|
|
pcmd->body.context.req.type = cpu_to_le16(GET_CONTEXT_DATA);
|
|
|
|
|
|
|
|
/* send command */
|
2011-11-07 03:31:50 +08:00
|
|
|
if (adap->ops->xfer_cmd) {
|
|
|
|
error = adap->ops->xfer_cmd(adap,
|
|
|
|
(uint8_t *) pcmd,
|
|
|
|
sizeof(pcmd->body.context.req)
|
|
|
|
+ HEADER_SIZE,
|
|
|
|
(uint8_t *) prsp,
|
|
|
|
sizeof(prsp->body.context.rsp)
|
|
|
|
+ HEADER_SIZE);
|
2011-10-31 23:24:46 +08:00
|
|
|
} else {
|
|
|
|
error = AS10X_CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* parse response: context command do not follow the common response */
|
|
|
|
/* structure -> specific handling response parse required */
|
|
|
|
error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
|
|
|
|
|
|
|
|
if (error == 0) {
|
|
|
|
/* Response OK -> get response data */
|
2014-09-24 21:51:35 +08:00
|
|
|
*pvalue = le32_to_cpu((__force __le32)prsp->body.context.rsp.reg_val.u.value32);
|
2011-10-31 23:24:46 +08:00
|
|
|
/* value returned is always a 32-bit value */
|
|
|
|
}
|
2011-10-31 23:24:39 +08:00
|
|
|
|
|
|
|
out:
|
2011-10-31 23:24:46 +08:00
|
|
|
return error;
|
2011-10-31 23:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-31 23:24:51 +08:00
|
|
|
* as10x_cmd_set_context - send set context command to AS10x
|
2011-11-07 03:31:50 +08:00
|
|
|
* @adap: pointer to AS10x bus adapter
|
2011-10-31 23:24:51 +08:00
|
|
|
* @tag: context tag
|
|
|
|
* @value: value to set in context
|
|
|
|
*
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-11-07 03:31:50 +08:00
|
|
|
int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
|
2011-10-31 23:24:39 +08:00
|
|
|
uint32_t value)
|
|
|
|
{
|
2011-10-31 23:24:46 +08:00
|
|
|
int error;
|
|
|
|
struct as10x_cmd_t *pcmd, *prsp;
|
|
|
|
|
2011-11-07 03:31:50 +08:00
|
|
|
pcmd = adap->cmd;
|
|
|
|
prsp = adap->rsp;
|
2011-10-31 23:24:46 +08:00
|
|
|
|
|
|
|
/* prepare command */
|
2011-11-07 03:31:50 +08:00
|
|
|
as10x_cmd_build(pcmd, (++adap->cmd_xid),
|
2011-10-31 23:24:46 +08:00
|
|
|
sizeof(pcmd->body.context.req));
|
|
|
|
|
|
|
|
/* fill command */
|
|
|
|
pcmd->body.context.req.proc_id = cpu_to_le16(CONTROL_PROC_CONTEXT);
|
|
|
|
/* pcmd->body.context.req.reg_val.mode initialization is not required */
|
2014-09-24 21:51:35 +08:00
|
|
|
pcmd->body.context.req.reg_val.u.value32 = (__force u32)cpu_to_le32(value);
|
2011-10-31 23:24:46 +08:00
|
|
|
pcmd->body.context.req.tag = cpu_to_le16(tag);
|
|
|
|
pcmd->body.context.req.type = cpu_to_le16(SET_CONTEXT_DATA);
|
|
|
|
|
|
|
|
/* send command */
|
2011-11-07 03:31:50 +08:00
|
|
|
if (adap->ops->xfer_cmd) {
|
|
|
|
error = adap->ops->xfer_cmd(adap,
|
|
|
|
(uint8_t *) pcmd,
|
|
|
|
sizeof(pcmd->body.context.req)
|
|
|
|
+ HEADER_SIZE,
|
|
|
|
(uint8_t *) prsp,
|
|
|
|
sizeof(prsp->body.context.rsp)
|
|
|
|
+ HEADER_SIZE);
|
2011-10-31 23:24:46 +08:00
|
|
|
} else {
|
|
|
|
error = AS10X_CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* parse response: context command do not follow the common response */
|
|
|
|
/* structure -> specific handling response parse required */
|
|
|
|
error = as10x_context_rsp_parse(prsp, CONTROL_PROC_CONTEXT_RSP);
|
2011-10-31 23:24:39 +08:00
|
|
|
|
|
|
|
out:
|
2011-10-31 23:24:46 +08:00
|
|
|
return error;
|
2011-10-31 23:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-31 23:24:51 +08:00
|
|
|
* as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
|
2011-11-07 03:31:50 +08:00
|
|
|
* @adap: pointer to AS10x bus adapter
|
2011-10-31 23:24:51 +08:00
|
|
|
* @mode: mode selected:
|
2018-01-04 19:47:28 +08:00
|
|
|
* - ON : 0x0 => eLNA always ON
|
|
|
|
* - OFF : 0x1 => eLNA always OFF
|
|
|
|
* - AUTO : 0x2 => eLNA follow hysteresis parameters
|
2011-10-31 23:24:51 +08:00
|
|
|
* to be ON or OFF
|
|
|
|
*
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-11-07 03:31:50 +08:00
|
|
|
int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
|
2011-10-31 23:24:39 +08:00
|
|
|
{
|
2011-10-31 23:24:46 +08:00
|
|
|
int error;
|
|
|
|
struct as10x_cmd_t *pcmd, *prsp;
|
|
|
|
|
2011-11-07 03:31:50 +08:00
|
|
|
pcmd = adap->cmd;
|
|
|
|
prsp = adap->rsp;
|
2011-10-31 23:24:46 +08:00
|
|
|
|
|
|
|
/* prepare command */
|
2011-11-07 03:31:50 +08:00
|
|
|
as10x_cmd_build(pcmd, (++adap->cmd_xid),
|
2011-10-31 23:24:46 +08:00
|
|
|
sizeof(pcmd->body.cfg_change_mode.req));
|
|
|
|
|
|
|
|
/* fill command */
|
|
|
|
pcmd->body.cfg_change_mode.req.proc_id =
|
|
|
|
cpu_to_le16(CONTROL_PROC_ELNA_CHANGE_MODE);
|
|
|
|
pcmd->body.cfg_change_mode.req.mode = mode;
|
|
|
|
|
|
|
|
/* send command */
|
2011-11-07 03:31:50 +08:00
|
|
|
if (adap->ops->xfer_cmd) {
|
|
|
|
error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
|
2011-10-31 23:24:46 +08:00
|
|
|
sizeof(pcmd->body.cfg_change_mode.req)
|
|
|
|
+ HEADER_SIZE, (uint8_t *) prsp,
|
|
|
|
sizeof(prsp->body.cfg_change_mode.rsp)
|
|
|
|
+ HEADER_SIZE);
|
|
|
|
} else {
|
|
|
|
error = AS10X_CMD_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* parse response */
|
|
|
|
error = as10x_rsp_parse(prsp, CONTROL_PROC_ELNA_CHANGE_MODE_RSP);
|
2011-10-31 23:24:39 +08:00
|
|
|
|
|
|
|
out:
|
2011-10-31 23:24:46 +08:00
|
|
|
return error;
|
2011-10-31 23:24:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-31 23:24:51 +08:00
|
|
|
* as10x_context_rsp_parse - Parse context command response
|
|
|
|
* @prsp: pointer to AS10x command response buffer
|
|
|
|
* @proc_id: id of the command
|
|
|
|
*
|
2012-10-31 22:52:45 +08:00
|
|
|
* Since the contex command response does not follow the common
|
2011-10-31 23:24:51 +08:00
|
|
|
* response, a specific parse function is required.
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-10-31 23:24:46 +08:00
|
|
|
int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
|
|
|
|
{
|
|
|
|
int err;
|
2011-10-31 23:24:39 +08:00
|
|
|
|
2011-10-31 23:24:46 +08:00
|
|
|
err = prsp->body.context.rsp.error;
|
2011-10-31 23:24:39 +08:00
|
|
|
|
2011-10-31 23:24:46 +08:00
|
|
|
if ((err == 0) &&
|
|
|
|
(le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return AS10X_CMD_ERROR;
|
2011-10-31 23:24:39 +08:00
|
|
|
}
|