Mailing List archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[linux-dvb] Re: refactoring
On Sunday 10 Oct 2004 15:45, Gerd Knorr wrote:
> > Before anyone gets too excited, this was an experimental structure. I
> > think a better solution would be something like:
> >
> > struct dvb_fe {
> > struct fe_api *api;
> > struct dvb_adapter *dvb;
> > void *priv;
> > };
> >
> > struct fe_api {
> > struct dvb_frontend_info info;
> >
> > void (*attach)(....)
> > void (*set_tps)(struct dvb_fe*, struct dvb_frontend_parameters*);
> > void (*get_tps)(struct dvb_fe*, struct dvb_frontend_parameters*);
> > void (*get_status)(struct dvb_fe*, struct fe_status*);
> > /* whatever else is needed, for diseqc, ... */
> > void (*destroy)(struct dvb_fe*);
> > };
>
> Looks ok. What attach() should do?
Actually, I found a way to do this that means we don't need the _attach()
functions exported:
You use dvb_register_frontend()/dvb_unregister_frontend() directly to
create/destroy frontend devices:
extern int dvb_register_frontend(struct dvb_adapter* dvb,
struct dvb_frontend_ops* ops,
void* adapter_data,
void* demodulator_config,
struct module* module,
struct dvb_frontend** fe);
extern int dvb_unregister_frontend(struct dvb_frontend* fe);
Each frontend exposes an XXX_attach()/XXX_detach() function pointer, which are
called during from the generic frontend code.
e.g. for cx22702:
static void cx22702_detach(struct dvb_frontend* fe)
{
struct cx22702_state* state = (struct cx22702_state*)
fe->demodulator_priv;
kfree(state);
}
static int cx22702_attach(void* demodulator_config,
void** demodulator_data)
{
struct cx22702_config* config = (struct cx22702_config*)
demodulator_config;
struct cx22702_state* state = NULL;
int ret = -ENODEV;
/* allocate memory for the internal state */
state = (struct cx22702_state*) kmalloc(sizeof(struct cx22702_state),
GFP_KERNEL);
if (state == NULL) {
ret = -ENOMEM;
goto error;
}
/* setup the state */
state->config = config;
state->prevUCBlocks = 0;
/* check if the demod is there */
if (cx22702_readreg(state, 0x1f) != 0x3) goto error;
/* ok! */
*demodulator_data = state;
return 0;
error:
if (state) kfree(state);
return ret;
}
Not all frontends need to allocate state, so they can do away with providing a
XXX_detach() function.
Home |
Main Index |
Thread Index