2017-12-05 19:59:23 +01:00
|
|
|
/*
|
|
|
|
* ddbridge-mci.c: Digital Devices microcode interface
|
|
|
|
*
|
2018-03-22 19:36:08 +01:00
|
|
|
* Copyright (C) 2017-2018 Digital Devices GmbH
|
|
|
|
* Ralph Metzler <rjkm@metzlerbros.de>
|
|
|
|
* Marcus Metzler <mocm@metzlerbros.de>
|
2017-12-05 19:59:23 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 only, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, point your browser to
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ddbridge.h"
|
|
|
|
#include "ddbridge-io.h"
|
|
|
|
#include "ddbridge-mci.h"
|
|
|
|
|
|
|
|
static LIST_HEAD(mci_list);
|
|
|
|
|
|
|
|
static int mci_reset(struct mci *state)
|
|
|
|
{
|
|
|
|
struct ddb_link *link = state->base->link;
|
|
|
|
u32 status = 0;
|
|
|
|
u32 timeout = 40;
|
|
|
|
|
|
|
|
ddblwritel(link, MCI_CONTROL_RESET, MCI_CONTROL);
|
|
|
|
ddblwritel(link, 0, MCI_CONTROL + 4); /* 1= no internal init */
|
|
|
|
msleep(300);
|
|
|
|
ddblwritel(link, 0, MCI_CONTROL);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
status = ddblreadl(link, MCI_CONTROL);
|
|
|
|
if ((status & MCI_CONTROL_READY) == MCI_CONTROL_READY)
|
|
|
|
break;
|
|
|
|
if (--timeout == 0)
|
|
|
|
break;
|
|
|
|
msleep(50);
|
|
|
|
}
|
|
|
|
if ((status & MCI_CONTROL_READY) == 0 )
|
|
|
|
return -1;
|
|
|
|
if (link->ids.device == 0x0009)
|
|
|
|
ddblwritel(link, SX8_TSCONFIG_MODE_NORMAL, SX8_TSCONFIG);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
int ddb_mci_config(struct mci *state, u32 config)
|
2018-01-01 21:01:49 +01:00
|
|
|
{
|
|
|
|
struct ddb_link *link = state->base->link;
|
|
|
|
|
|
|
|
if (link->ids.device != 0x0009)
|
|
|
|
return -EINVAL;
|
|
|
|
ddblwritel(link, config, SX8_TSCONFIG);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
static int ddb_mci_cmd_raw_unlocked(struct mci *state,
|
|
|
|
u32 *cmd, u32 cmd_len,
|
|
|
|
u32 *res, u32 res_len)
|
2017-12-05 19:59:23 +01:00
|
|
|
{
|
|
|
|
struct ddb_link *link = state->base->link;
|
|
|
|
u32 i, val;
|
|
|
|
unsigned long stat;
|
|
|
|
|
|
|
|
val = ddblreadl(link, MCI_CONTROL);
|
|
|
|
if (val & (MCI_CONTROL_RESET | MCI_CONTROL_START_COMMAND))
|
|
|
|
return -EIO;
|
|
|
|
if (cmd && cmd_len)
|
|
|
|
for (i = 0; i < cmd_len; i++)
|
|
|
|
ddblwritel(link, cmd[i], MCI_COMMAND + i * 4);
|
|
|
|
val |= (MCI_CONTROL_START_COMMAND | MCI_CONTROL_ENABLE_DONE_INTERRUPT);
|
|
|
|
ddblwritel(link, val, MCI_CONTROL);
|
|
|
|
|
|
|
|
stat = wait_for_completion_timeout(&state->base->completion, HZ);
|
|
|
|
if (stat == 0) {
|
|
|
|
printk("MCI timeout\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
if (res && res_len)
|
|
|
|
for (i = 0; i < res_len; i++)
|
|
|
|
res[i] = ddblreadl(link, MCI_RESULT + i * 4);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
int ddb_mci_cmd_unlocked(struct mci *state,
|
|
|
|
struct mci_command *command,
|
|
|
|
struct mci_result *result)
|
2017-12-05 19:59:23 +01:00
|
|
|
{
|
|
|
|
u32 *cmd = (u32 *) command;
|
|
|
|
u32 *res = (u32 *) result;
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
return ddb_mci_cmd_raw_unlocked(state, cmd, sizeof(*command)/sizeof(u32),
|
|
|
|
res, sizeof(*result)/sizeof(u32));
|
2017-12-05 19:59:23 +01:00
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
int ddb_mci_cmd(struct mci *state,
|
|
|
|
struct mci_command *command,
|
|
|
|
struct mci_result *result)
|
2017-12-05 19:59:23 +01:00
|
|
|
{
|
|
|
|
int stat;
|
2018-05-15 23:01:39 +02:00
|
|
|
|
2017-12-05 19:59:23 +01:00
|
|
|
mutex_lock(&state->base->mci_lock);
|
2018-05-15 23:01:39 +02:00
|
|
|
stat = ddb_mci_cmd_raw_unlocked(state,
|
2017-12-05 19:59:23 +01:00
|
|
|
(u32 *)command, sizeof(*command)/sizeof(u32),
|
|
|
|
(u32 *)result, sizeof(*result)/sizeof(u32));
|
|
|
|
mutex_unlock(&state->base->mci_lock);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
int ddb_mci_cmd_raw(struct mci *state,
|
2017-12-05 19:59:23 +01:00
|
|
|
struct mci_command *command, u32 command_len,
|
|
|
|
struct mci_result *result, u32 result_len)
|
|
|
|
{
|
|
|
|
int stat;
|
2018-05-15 23:01:39 +02:00
|
|
|
|
2017-12-05 19:59:23 +01:00
|
|
|
mutex_lock(&state->base->mci_lock);
|
2018-05-15 23:01:39 +02:00
|
|
|
stat = ddb_mci_cmd_raw_unlocked(state,
|
|
|
|
(u32 *)command, command_len,
|
|
|
|
(u32 *)result, result_len);
|
2017-12-05 19:59:23 +01:00
|
|
|
mutex_unlock(&state->base->mci_lock);
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
static int ddb_mci_get_iq(struct mci *mci, u32 demod, s16 *i, s16 *q)
|
2017-12-05 19:59:23 +01:00
|
|
|
{
|
|
|
|
int stat;
|
|
|
|
struct mci_command cmd;
|
2018-05-15 23:01:39 +02:00
|
|
|
struct mci_result res;
|
2017-12-05 19:59:23 +01:00
|
|
|
|
2018-01-16 23:43:02 +01:00
|
|
|
memset(&cmd, 0, sizeof(cmd));
|
2018-05-15 23:01:39 +02:00
|
|
|
memset(&res, 0, sizeof(res));
|
|
|
|
cmd.command = MCI_CMD_GET_IQSYMBOL;
|
|
|
|
cmd.demod = demod;
|
|
|
|
stat = ddb_mci_cmd(mci, &cmd, &res);
|
2017-12-05 19:59:23 +01:00
|
|
|
if (!stat) {
|
2018-05-15 23:01:39 +02:00
|
|
|
*i = res.iq_symbol.i;
|
|
|
|
*q = res.iq_symbol.q;
|
2017-12-05 19:59:23 +01:00
|
|
|
}
|
|
|
|
return stat;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
static void mci_handler(void *priv)
|
2017-12-05 19:59:23 +01:00
|
|
|
{
|
2018-05-15 23:01:39 +02:00
|
|
|
struct mci_base *base = (struct mci_base *)priv;
|
2017-12-05 19:59:23 +01:00
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
complete(&base->completion);
|
2017-12-05 19:59:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct mci_base *match_base(void *key)
|
|
|
|
{
|
|
|
|
struct mci_base *p;
|
|
|
|
|
|
|
|
list_for_each_entry(p, &mci_list, mci_list)
|
|
|
|
if (p->key == key)
|
|
|
|
return p;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int probe(struct mci *state)
|
|
|
|
{
|
|
|
|
mci_reset(state);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
struct dvb_frontend *ddb_mci_attach(struct ddb_input *input, struct mci_cfg *cfg, int nr)
|
2017-12-05 19:59:23 +01:00
|
|
|
{
|
|
|
|
struct ddb_port *port = input->port;
|
|
|
|
struct ddb *dev = port->dev;
|
|
|
|
struct ddb_link *link = &dev->link[port->lnr];
|
|
|
|
struct mci_base *base;
|
|
|
|
struct mci *state;
|
2018-05-15 23:01:39 +02:00
|
|
|
void *key = cfg->type ? (void *) port : (void *) link;
|
2017-12-05 19:59:23 +01:00
|
|
|
|
2018-05-15 23:01:39 +02:00
|
|
|
state = kzalloc(cfg->state_size, GFP_KERNEL);
|
2017-12-05 19:59:23 +01:00
|
|
|
if (!state)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
base = match_base(key);
|
|
|
|
if (base) {
|
|
|
|
base->count++;
|
|
|
|
state->base = base;
|
|
|
|
} else {
|
2018-05-15 23:01:39 +02:00
|
|
|
base = kzalloc(cfg->base_size, GFP_KERNEL);
|
2017-12-05 19:59:23 +01:00
|
|
|
if (!base)
|
|
|
|
goto fail;
|
|
|
|
base->key = key;
|
|
|
|
base->count = 1;
|
|
|
|
base->link = link;
|
|
|
|
mutex_init(&base->mci_lock);
|
|
|
|
mutex_init(&base->tuner_lock);
|
|
|
|
ddb_irq_set(dev, link->nr, 0, mci_handler, base);
|
|
|
|
init_completion(&base->completion);
|
|
|
|
state->base = base;
|
|
|
|
if (probe(state) < 0) {
|
|
|
|
kfree(base);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
list_add(&base->mci_list, &mci_list);
|
2018-05-15 23:01:39 +02:00
|
|
|
if (cfg->base_init)
|
|
|
|
cfg->base_init(base);
|
2017-12-05 19:59:23 +01:00
|
|
|
}
|
2018-05-15 23:01:39 +02:00
|
|
|
memcpy(&state->fe.ops, cfg->fe_ops, sizeof(struct dvb_frontend_ops));
|
2017-12-05 19:59:23 +01:00
|
|
|
state->fe.demodulator_priv = state;
|
|
|
|
state->nr = nr;
|
|
|
|
state->tuner = nr;
|
|
|
|
state->demod = nr;
|
2018-05-15 23:01:39 +02:00
|
|
|
if (cfg->init)
|
|
|
|
cfg->init(state);
|
2017-12-05 19:59:23 +01:00
|
|
|
return &state->fe;
|
|
|
|
fail:
|
|
|
|
kfree(state);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|