4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "pvrusb2-util.h"
24 #include "pvrusb2-tuner.h"
25 #include "pvrusb2-hdw-internal.h"
26 #include "pvrusb2-debug.h"
27 #include <linux/videodev2.h>
28 #include <media/tuner.h>
29 #include <media/v4l2-common.h>
31 struct pvr2_tuner_handler {
33 struct pvr2_i2c_client *client;
34 struct pvr2_i2c_handler i2c_handler;
39 static void set_type(struct pvr2_tuner_handler *ctxt)
41 struct pvr2_hdw *hdw = ctxt->hdw;
42 struct tuner_setup setup;
43 pvr2_trace(PVR2_TRACE_CHIPS,"i2c tuner set_type(%d)",hdw->tuner_type);
44 if (((int)(hdw->tuner_type)) < 0) return;
46 setup.addr = ADDR_UNSET;
47 setup.type = hdw->tuner_type;
48 setup.mode_mask = T_RADIO | T_ANALOG_TV;
49 /* We may really want mode_mask to be T_ANALOG_TV for now */
50 pvr2_i2c_client_cmd(ctxt->client,TUNER_SET_TYPE_ADDR,&setup);
51 ctxt->type_update_fl = 0;
55 static int tuner_check(struct pvr2_tuner_handler *ctxt)
57 struct pvr2_hdw *hdw = ctxt->hdw;
58 if (hdw->tuner_updated) ctxt->type_update_fl = !0;
59 return ctxt->type_update_fl != 0;
63 static void tuner_update(struct pvr2_tuner_handler *ctxt)
65 if (ctxt->type_update_fl) set_type(ctxt);
69 static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
71 ctxt->client->handler = NULL;
76 static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
78 return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
82 static const struct pvr2_i2c_handler_functions tuner_funcs = {
83 .detach = (void (*)(void *))pvr2_tuner_detach,
84 .check = (int (*)(void *))tuner_check,
85 .update = (void (*)(void *))tuner_update,
86 .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_tuner_describe,
90 int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
92 struct pvr2_tuner_handler *ctxt;
93 if (cp->handler) return 0;
95 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
98 ctxt->i2c_handler.func_data = ctxt;
99 ctxt->i2c_handler.func_table = &tuner_funcs;
100 ctxt->type_update_fl = !0;
103 cp->handler = &ctxt->i2c_handler;
104 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up",
113 Stuff for Emacs to see, in order to encourage consistent editing style:
114 *** Local Variables: ***
116 *** fill-column: 70 ***
118 *** c-basic-offset: 8 ***