iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / media / video / pvrusb2 / pvrusb2-tuner.c
blob05e65ce2e3a96109684695c841b2cb06675cbc58
1 /*
3 * $Id$
5 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "pvrusb2.h"
24 #include "pvrusb2-util.h"
25 #include "pvrusb2-tuner.h"
26 #include "pvrusb2-hdw-internal.h"
27 #include "pvrusb2-debug.h"
28 #include <linux/videodev2.h>
29 #include <media/tuner.h>
30 #include <media/v4l2-common.h>
32 struct pvr2_tuner_handler {
33 struct pvr2_hdw *hdw;
34 struct pvr2_i2c_client *client;
35 struct pvr2_i2c_handler i2c_handler;
36 int type_update_fl;
40 static void set_type(struct pvr2_tuner_handler *ctxt)
42 struct pvr2_hdw *hdw = ctxt->hdw;
43 struct tuner_setup setup;
44 pvr2_trace(PVR2_TRACE_CHIPS,"i2c tuner set_type(%d)",hdw->tuner_type);
45 if (((int)(hdw->tuner_type)) < 0) return;
47 setup.addr = ADDR_UNSET;
48 setup.type = hdw->tuner_type;
49 setup.mode_mask = T_RADIO | T_ANALOG_TV;
50 /* We may really want mode_mask to be T_ANALOG_TV for now */
51 pvr2_i2c_client_cmd(ctxt->client,TUNER_SET_TYPE_ADDR,&setup);
52 ctxt->type_update_fl = 0;
56 static int tuner_check(struct pvr2_tuner_handler *ctxt)
58 struct pvr2_hdw *hdw = ctxt->hdw;
59 if (hdw->tuner_updated) ctxt->type_update_fl = !0;
60 return ctxt->type_update_fl != 0;
64 static void tuner_update(struct pvr2_tuner_handler *ctxt)
66 if (ctxt->type_update_fl) set_type(ctxt);
70 static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
72 ctxt->client->handler = NULL;
73 kfree(ctxt);
77 static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
79 return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
83 static const struct pvr2_i2c_handler_functions tuner_funcs = {
84 .detach = (void (*)(void *))pvr2_tuner_detach,
85 .check = (int (*)(void *))tuner_check,
86 .update = (void (*)(void *))tuner_update,
87 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_tuner_describe,
91 int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
93 struct pvr2_tuner_handler *ctxt;
94 if (cp->handler) return 0;
96 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
97 if (!ctxt) return 0;
99 ctxt->i2c_handler.func_data = ctxt;
100 ctxt->i2c_handler.func_table = &tuner_funcs;
101 ctxt->type_update_fl = !0;
102 ctxt->client = cp;
103 ctxt->hdw = hdw;
104 cp->handler = &ctxt->i2c_handler;
105 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up",
106 cp->client->addr);
107 return !0;
114 Stuff for Emacs to see, in order to encourage consistent editing style:
115 *** Local Variables: ***
116 *** mode: c ***
117 *** fill-column: 70 ***
118 *** tab-width: 8 ***
119 *** c-basic-offset: 8 ***
120 *** End: ***