Commit 47f79129 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

[media] as102: prepare as102_fe to be compiled as a module

Remove the dependencies of as102_cmd from as102, in order to
allow it to be compiled as a separate module.
Signed-off-by: default avatarMauro Carvalho Chehab <m.chehab@samsung.com>
parent c098c219
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
/* header file for usb device driver*/ /* header file for usb device driver*/
#include "as102_drv.h" #include "as102_drv.h"
#include "as10x_cmd.h"
#include "as102_fe.h"
#include "as102_fw.h" #include "as102_fw.h"
#include "dvbdev.h" #include "dvbdev.h"
...@@ -176,6 +178,119 @@ static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed) ...@@ -176,6 +178,119 @@ static int as102_dvb_dmx_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
return 0; return 0;
} }
static int as102_set_tune(void *priv, struct as10x_tune_args *tune_args)
{
struct as10x_bus_adapter_t *bus_adap = priv;
int ret;
/* Set frontend arguments */
if (mutex_lock_interruptible(&bus_adap->lock))
return -EBUSY;
ret = as10x_cmd_set_tune(bus_adap, tune_args);
if (ret != 0)
dev_dbg(&bus_adap->usb_dev->dev,
"as10x_cmd_set_tune failed. (err = %d)\n", ret);
mutex_unlock(&bus_adap->lock);
return ret;
}
static int as102_get_tps(void *priv, struct as10x_tps *tps)
{
struct as10x_bus_adapter_t *bus_adap = priv;
int ret;
if (mutex_lock_interruptible(&bus_adap->lock))
return -EBUSY;
/* send abilis command: GET_TPS */
ret = as10x_cmd_get_tps(bus_adap, tps);
mutex_unlock(&bus_adap->lock);
return ret;
}
static int as102_get_status(void *priv, struct as10x_tune_status *tstate)
{
struct as10x_bus_adapter_t *bus_adap = priv;
int ret;
if (mutex_lock_interruptible(&bus_adap->lock))
return -EBUSY;
/* send abilis command: GET_TUNE_STATUS */
ret = as10x_cmd_get_tune_status(bus_adap, tstate);
if (ret < 0) {
dev_dbg(&bus_adap->usb_dev->dev,
"as10x_cmd_get_tune_status failed (err = %d)\n",
ret);
}
mutex_unlock(&bus_adap->lock);
return ret;
}
static int as102_get_stats(void *priv, struct as10x_demod_stats *demod_stats)
{
struct as10x_bus_adapter_t *bus_adap = priv;
int ret;
if (mutex_lock_interruptible(&bus_adap->lock))
return -EBUSY;
/* send abilis command: GET_TUNE_STATUS */
ret = as10x_cmd_get_demod_stats(bus_adap, demod_stats);
if (ret < 0) {
dev_dbg(&bus_adap->usb_dev->dev,
"as10x_cmd_get_demod_stats failed (probably not tuned)\n");
} else {
dev_dbg(&bus_adap->usb_dev->dev,
"demod status: fc: 0x%08x, bad fc: 0x%08x, bytes corrected: 0x%08x , MER: 0x%04x\n",
demod_stats->frame_count,
demod_stats->bad_frame_count,
demod_stats->bytes_fixed_by_rs,
demod_stats->mer);
}
mutex_unlock(&bus_adap->lock);
return ret;
}
static int as102_stream_ctrl(void *priv, int acquire, uint32_t elna_cfg)
{
struct as10x_bus_adapter_t *bus_adap = priv;
int ret;
if (mutex_lock_interruptible(&bus_adap->lock))
return -EBUSY;
if (acquire) {
if (elna_enable)
as10x_cmd_set_context(bus_adap,
CONTEXT_LNA, elna_cfg);
ret = as10x_cmd_turn_on(bus_adap);
} else {
ret = as10x_cmd_turn_off(bus_adap);
}
mutex_unlock(&bus_adap->lock);
return ret;
}
static const struct as102_fe_ops as102_fe_ops = {
.set_tune = as102_set_tune,
.get_tps = as102_get_tps,
.get_status = as102_get_status,
.get_stats = as102_get_stats,
.stream_ctrl = as102_stream_ctrl,
};
int as102_dvb_register(struct as102_dev_t *as102_dev) int as102_dvb_register(struct as102_dev_t *as102_dev)
{ {
struct device *dev = &as102_dev->bus_adap.usb_dev->dev; struct device *dev = &as102_dev->bus_adap.usb_dev->dev;
...@@ -218,6 +333,7 @@ int as102_dvb_register(struct as102_dev_t *as102_dev) ...@@ -218,6 +333,7 @@ int as102_dvb_register(struct as102_dev_t *as102_dev)
/* Attach the frontend */ /* Attach the frontend */
as102_dev->dvb_fe = dvb_attach(as102_attach, as102_dev->name, as102_dev->dvb_fe = dvb_attach(as102_attach, as102_dev->name,
&as102_fe_ops,
&as102_dev->bus_adap, &as102_dev->bus_adap,
as102_dev->elna_cfg); as102_dev->elna_cfg);
if (!as102_dev->dvb_fe) { if (!as102_dev->dvb_fe) {
......
...@@ -13,10 +13,13 @@ ...@@ -13,10 +13,13 @@
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifndef _AS102_DRV_H
#define _AS102_DRV_H
#include <linux/usb.h> #include <linux/usb.h>
#include <dvb_demux.h> #include <dvb_demux.h>
#include <dvb_frontend.h> #include <dvb_frontend.h>
#include <dmxdev.h> #include <dmxdev.h>
#include "as10x_handle.h"
#include "as10x_cmd.h" #include "as10x_cmd.h"
#include "as102_usb_drv.h" #include "as102_usb_drv.h"
...@@ -77,7 +80,4 @@ struct as102_dev_t { ...@@ -77,7 +80,4 @@ struct as102_dev_t {
int as102_dvb_register(struct as102_dev_t *dev); int as102_dvb_register(struct as102_dev_t *dev);
void as102_dvb_unregister(struct as102_dev_t *dev); void as102_dvb_unregister(struct as102_dev_t *dev);
/* FIXME: move it to a separate header */ #endif
struct dvb_frontend *as102_attach(const char *name, \ No newline at end of file
struct as10x_bus_adapter_t *bus_adap,
uint8_t elna_cfg);
...@@ -13,15 +13,17 @@ ...@@ -13,15 +13,17 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#include "as102_drv.h"
#include "as10x_types.h" #include <dvb_frontend.h>
#include "as10x_cmd.h"
#include "as102_fe.h"
struct as102_state { struct as102_state {
struct dvb_frontend frontend; struct dvb_frontend frontend;
struct as10x_demod_stats demod_stats; struct as10x_demod_stats demod_stats;
struct as10x_bus_adapter_t *bus_adap;
const struct as102_fe_ops *ops;
void *priv;
uint8_t elna_cfg; uint8_t elna_cfg;
/* signal strength */ /* signal strength */
...@@ -62,7 +64,6 @@ static int as102_fe_set_frontend(struct dvb_frontend *fe) ...@@ -62,7 +64,6 @@ static int as102_fe_set_frontend(struct dvb_frontend *fe)
{ {
struct as102_state *state = fe->demodulator_priv; struct as102_state *state = fe->demodulator_priv;
struct dtv_frontend_properties *c = &fe->dtv_property_cache; struct dtv_frontend_properties *c = &fe->dtv_property_cache;
int ret = 0;
struct as10x_tune_args tune_args = { 0 }; struct as10x_tune_args tune_args = { 0 };
/* set frequency */ /* set frequency */
...@@ -186,17 +187,7 @@ static int as102_fe_set_frontend(struct dvb_frontend *fe) ...@@ -186,17 +187,7 @@ static int as102_fe_set_frontend(struct dvb_frontend *fe)
} }
/* Set frontend arguments */ /* Set frontend arguments */
if (mutex_lock_interruptible(&state->bus_adap->lock)) return state->ops->set_tune(state->priv, &tune_args);
return -EBUSY;
ret = as10x_cmd_set_tune(state->bus_adap, &tune_args);
if (ret != 0)
dev_dbg(&state->bus_adap->usb_dev->dev,
"as10x_cmd_set_tune failed. (err = %d)\n", ret);
mutex_unlock(&state->bus_adap->lock);
return (ret < 0) ? -EINVAL : 0;
} }
static int as102_fe_get_frontend(struct dvb_frontend *fe) static int as102_fe_get_frontend(struct dvb_frontend *fe)
...@@ -206,14 +197,8 @@ static int as102_fe_get_frontend(struct dvb_frontend *fe) ...@@ -206,14 +197,8 @@ static int as102_fe_get_frontend(struct dvb_frontend *fe)
int ret = 0; int ret = 0;
struct as10x_tps tps = { 0 }; struct as10x_tps tps = { 0 };
if (mutex_lock_interruptible(&state->bus_adap->lock))
return -EBUSY;
/* send abilis command: GET_TPS */ /* send abilis command: GET_TPS */
ret = as10x_cmd_get_tps(state->bus_adap, &tps); ret = state->ops->get_tps(state->priv, &tps);
mutex_unlock(&state->bus_adap->lock);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -321,24 +306,16 @@ static int as102_fe_get_tune_settings(struct dvb_frontend *fe, ...@@ -321,24 +306,16 @@ static int as102_fe_get_tune_settings(struct dvb_frontend *fe,
return 0; return 0;
} }
static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status) static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
{ {
int ret = 0; int ret = 0;
struct as102_state *state = fe->demodulator_priv; struct as102_state *state = fe->demodulator_priv;
struct as10x_tune_status tstate = { 0 }; struct as10x_tune_status tstate = { 0 };
if (mutex_lock_interruptible(&state->bus_adap->lock))
return -EBUSY;
/* send abilis command: GET_TUNE_STATUS */ /* send abilis command: GET_TUNE_STATUS */
ret = as10x_cmd_get_tune_status(state->bus_adap, &tstate); ret = state->ops->get_status(state->priv, &tstate);
if (ret < 0) { if (ret < 0)
dev_dbg(&state->bus_adap->usb_dev->dev, return ret;
"as10x_cmd_get_tune_status failed (err = %d)\n",
ret);
goto out;
}
state->signal_strength = tstate.signal_strength; state->signal_strength = tstate.signal_strength;
state->ber = tstate.BER; state->ber = tstate.BER;
...@@ -358,31 +335,19 @@ static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status) ...@@ -358,31 +335,19 @@ static int as102_fe_read_status(struct dvb_frontend *fe, fe_status_t *status)
*status = TUNE_STATUS_NOT_TUNED; *status = TUNE_STATUS_NOT_TUNED;
} }
dev_dbg(&state->bus_adap->usb_dev->dev, pr_debug("as102: tuner status: 0x%02x, strength %d, per: %d, ber: %d\n",
"tuner status: 0x%02x, strength %d, per: %d, ber: %d\n", tstate.tune_state, tstate.signal_strength,
tstate.tune_state, tstate.signal_strength, tstate.PER, tstate.BER);
tstate.PER, tstate.BER);
if (!(*status & FE_HAS_LOCK)) {
if (*status & FE_HAS_LOCK) {
if (as10x_cmd_get_demod_stats(state->bus_adap,
(struct as10x_demod_stats *) &state->demod_stats) < 0) {
memset(&state->demod_stats, 0, sizeof(state->demod_stats));
dev_dbg(&state->bus_adap->usb_dev->dev,
"as10x_cmd_get_demod_stats failed (probably not tuned)\n");
} else {
dev_dbg(&state->bus_adap->usb_dev->dev,
"demod status: fc: 0x%08x, bad fc: 0x%08x, bytes corrected: 0x%08x , MER: 0x%04x\n",
state->demod_stats.frame_count,
state->demod_stats.bad_frame_count,
state->demod_stats.bytes_fixed_by_rs,
state->demod_stats.mer);
}
} else {
memset(&state->demod_stats, 0, sizeof(state->demod_stats)); memset(&state->demod_stats, 0, sizeof(state->demod_stats));
return 0;
} }
out: ret = state->ops->get_stats(state->priv, &state->demod_stats);
mutex_unlock(&state->bus_adap->lock); if (ret < 0)
memset(&state->demod_stats, 0, sizeof(state->demod_stats));
return ret; return ret;
} }
...@@ -436,24 +401,9 @@ static int as102_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) ...@@ -436,24 +401,9 @@ static int as102_fe_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire) static int as102_fe_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
{ {
struct as102_state *state = fe->demodulator_priv; struct as102_state *state = fe->demodulator_priv;
int ret;
if (mutex_lock_interruptible(&state->bus_adap->lock))
return -EBUSY;
if (acquire) { return state->ops->stream_ctrl(state->priv, acquire,
if (elna_enable) state->elna_cfg);
as10x_cmd_set_context(state->bus_adap,
CONTEXT_LNA, state->elna_cfg);
ret = as10x_cmd_turn_on(state->bus_adap);
} else {
ret = as10x_cmd_turn_off(state->bus_adap);
}
mutex_unlock(&state->bus_adap->lock);
return ret;
} }
static struct dvb_frontend_ops as102_fe_ops = { static struct dvb_frontend_ops as102_fe_ops = {
...@@ -488,7 +438,8 @@ static struct dvb_frontend_ops as102_fe_ops = { ...@@ -488,7 +438,8 @@ static struct dvb_frontend_ops as102_fe_ops = {
}; };
struct dvb_frontend *as102_attach(const char *name, struct dvb_frontend *as102_attach(const char *name,
struct as10x_bus_adapter_t *bus_adap, const struct as102_fe_ops *ops,
void *priv,
uint8_t elna_cfg) uint8_t elna_cfg)
{ {
struct as102_state *state; struct as102_state *state;
...@@ -496,13 +447,13 @@ struct dvb_frontend *as102_attach(const char *name, ...@@ -496,13 +447,13 @@ struct dvb_frontend *as102_attach(const char *name,
state = kzalloc(sizeof(struct as102_state), GFP_KERNEL); state = kzalloc(sizeof(struct as102_state), GFP_KERNEL);
if (state == NULL) { if (state == NULL) {
dev_err(&bus_adap->usb_dev->dev, pr_err("%s: unable to allocate memory for state\n", __func__);
"%s: unable to allocate memory for state\n", __func__);
return NULL; return NULL;
} }
fe = &state->frontend; fe = &state->frontend;
fe->demodulator_priv = state; fe->demodulator_priv = state;
state->bus_adap = bus_adap; state->ops = ops;
state->priv = priv;
state->elna_cfg = elna_cfg; state->elna_cfg = elna_cfg;
/* init frontend callback ops */ /* init frontend callback ops */
......
/*
* Abilis Systems Single DVB-T Receiver
* Copyright (C) 2014 Mauro Carvalho Chehab <m.chehab@samsung.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.
*/
#include "as10x_types.h"
struct as102_fe_ops {
int (*set_tune)(void *priv, struct as10x_tune_args *tune_args);
int (*get_tps)(void *priv, struct as10x_tps *tps);
int (*get_status)(void *priv, struct as10x_tune_status *tstate);
int (*get_stats)(void *priv, struct as10x_demod_stats *demod_stats);
int (*stream_ctrl)(void *priv, int acquire, uint32_t elna_cfg);
};
struct dvb_frontend *as102_attach(const char *name,
const struct as102_fe_ops *ops,
void *priv,
uint8_t elna_cfg);
...@@ -15,9 +15,7 @@ ...@@ -15,9 +15,7 @@
#ifndef _AS10X_CMD_H_ #ifndef _AS10X_CMD_H_
#define _AS10X_CMD_H_ #define _AS10X_CMD_H_
#ifdef __KERNEL__
#include <linux/kernel.h> #include <linux/kernel.h>
#endif
#include "as10x_types.h" #include "as10x_types.h"
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
*/ */
#ifdef __KERNEL__ #ifndef _AS10X_HANDLE_H
#define _AS10X_HANDLE_H
struct as10x_bus_adapter_t; struct as10x_bus_adapter_t;
struct as102_dev_t; struct as102_dev_t;
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#ifndef _AS10X_TYPES_H_ #ifndef _AS10X_TYPES_H_
#define _AS10X_TYPES_H_ #define _AS10X_TYPES_H_
#include "as10x_handle.h"
/*********************************/ /*********************************/
/* MACRO DEFINITIONS */ /* MACRO DEFINITIONS */
/*********************************/ /*********************************/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment