2011-10-31 15:24:49 +00: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 15:24:39 +00:00
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include "as102_drv.h"
|
|
|
|
#include "as10x_cmd.h"
|
|
|
|
|
|
|
|
/***************************/
|
|
|
|
/* FUNCTION DEFINITION */
|
|
|
|
/***************************/
|
|
|
|
|
|
|
|
/**
|
2011-10-31 15:24:51 +00:00
|
|
|
* as10x_cmd_get_context - Send get context command to AS10x
|
2011-11-06 19:31:50 +00:00
|
|
|
* @adap: pointer to AS10x bus adapter
|
2011-10-31 15:24:51 +00: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-06 19:31:50 +00:00
|
|
|
int as10x_cmd_get_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
|
2011-10-31 15:24:39 +00:00
|
|
|
uint32_t *pvalue)
|
|
|
|
{
|
2011-10-31 15:24:46 +00:00
|
|
|
int error;
|
|
|
|
struct as10x_cmd_t *pcmd, *prsp;
|
|
|
|
|
2011-11-06 19:31:50 +00:00
|
|
|
pcmd = adap->cmd;
|
|
|
|
prsp = adap->rsp;
|
2011-10-31 15:24:46 +00:00
|
|
|
|
|
|
|
/* prepare command */
|
2011-11-06 19:31:50 +00:00
|
|
|
as10x_cmd_build(pcmd, (++adap->cmd_xid),
|
2011-10-31 15:24:46 +00: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-06 19:31:50 +00: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 15:24:46 +00: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 13:51:35 +00:00
|
|
|
*pvalue = le32_to_cpu((__force __le32)prsp->body.context.rsp.reg_val.u.value32);
|
2011-10-31 15:24:46 +00:00
|
|
|
/* value returned is always a 32-bit value */
|
|
|
|
}
|
2011-10-31 15:24:39 +00:00
|
|
|
|
|
|
|
out:
|
2011-10-31 15:24:46 +00:00
|
|
|
return error;
|
2011-10-31 15:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-31 15:24:51 +00:00
|
|
|
* as10x_cmd_set_context - send set context command to AS10x
|
2011-11-06 19:31:50 +00:00
|
|
|
* @adap: pointer to AS10x bus adapter
|
2011-10-31 15:24:51 +00:00
|
|
|
* @tag: context tag
|
|
|
|
* @value: value to set in context
|
|
|
|
*
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-11-06 19:31:50 +00:00
|
|
|
int as10x_cmd_set_context(struct as10x_bus_adapter_t *adap, uint16_t tag,
|
2011-10-31 15:24:39 +00:00
|
|
|
uint32_t value)
|
|
|
|
{
|
2011-10-31 15:24:46 +00:00
|
|
|
int error;
|
|
|
|
struct as10x_cmd_t *pcmd, *prsp;
|
|
|
|
|
2011-11-06 19:31:50 +00:00
|
|
|
pcmd = adap->cmd;
|
|
|
|
prsp = adap->rsp;
|
2011-10-31 15:24:46 +00:00
|
|
|
|
|
|
|
/* prepare command */
|
2011-11-06 19:31:50 +00:00
|
|
|
as10x_cmd_build(pcmd, (++adap->cmd_xid),
|
2011-10-31 15:24:46 +00: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 13:51:35 +00:00
|
|
|
pcmd->body.context.req.reg_val.u.value32 = (__force u32)cpu_to_le32(value);
|
2011-10-31 15:24:46 +00: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-06 19:31:50 +00: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 15:24:46 +00: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 15:24:39 +00:00
|
|
|
|
|
|
|
out:
|
2011-10-31 15:24:46 +00:00
|
|
|
return error;
|
2011-10-31 15:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-31 15:24:51 +00:00
|
|
|
* as10x_cmd_eLNA_change_mode - send eLNA change mode command to AS10x
|
2011-11-06 19:31:50 +00:00
|
|
|
* @adap: pointer to AS10x bus adapter
|
2011-10-31 15:24:51 +00:00
|
|
|
* @mode: mode selected:
|
|
|
|
* - ON : 0x0 => eLNA always ON
|
|
|
|
* - OFF : 0x1 => eLNA always OFF
|
|
|
|
* - AUTO : 0x2 => eLNA follow hysteresis parameters
|
|
|
|
* to be ON or OFF
|
|
|
|
*
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-11-06 19:31:50 +00:00
|
|
|
int as10x_cmd_eLNA_change_mode(struct as10x_bus_adapter_t *adap, uint8_t mode)
|
2011-10-31 15:24:39 +00:00
|
|
|
{
|
2011-10-31 15:24:46 +00:00
|
|
|
int error;
|
|
|
|
struct as10x_cmd_t *pcmd, *prsp;
|
|
|
|
|
2011-11-06 19:31:50 +00:00
|
|
|
pcmd = adap->cmd;
|
|
|
|
prsp = adap->rsp;
|
2011-10-31 15:24:46 +00:00
|
|
|
|
|
|
|
/* prepare command */
|
2011-11-06 19:31:50 +00:00
|
|
|
as10x_cmd_build(pcmd, (++adap->cmd_xid),
|
2011-10-31 15:24:46 +00: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-06 19:31:50 +00:00
|
|
|
if (adap->ops->xfer_cmd) {
|
|
|
|
error = adap->ops->xfer_cmd(adap, (uint8_t *) pcmd,
|
2011-10-31 15:24:46 +00: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 15:24:39 +00:00
|
|
|
|
|
|
|
out:
|
2011-10-31 15:24:46 +00:00
|
|
|
return error;
|
2011-10-31 15:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-31 15:24:51 +00: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 14:52:45 +00:00
|
|
|
* Since the contex command response does not follow the common
|
2011-10-31 15:24:51 +00:00
|
|
|
* response, a specific parse function is required.
|
|
|
|
* Return 0 on success or negative value in case of error.
|
|
|
|
*/
|
2011-10-31 15:24:46 +00:00
|
|
|
int as10x_context_rsp_parse(struct as10x_cmd_t *prsp, uint16_t proc_id)
|
|
|
|
{
|
|
|
|
int err;
|
2011-10-31 15:24:39 +00:00
|
|
|
|
2011-10-31 15:24:46 +00:00
|
|
|
err = prsp->body.context.rsp.error;
|
2011-10-31 15:24:39 +00:00
|
|
|
|
2011-10-31 15:24:46 +00:00
|
|
|
if ((err == 0) &&
|
|
|
|
(le16_to_cpu(prsp->body.context.rsp.proc_id) == proc_id)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return AS10X_CMD_ERROR;
|
2011-10-31 15:24:39 +00:00
|
|
|
}
|