blob: 07775d1aad4efb0e8661bef9b74800551128258f [file] [log] [blame]
Mike Iselyd8554972006-06-26 20:58:46 -03001/*
2 *
Mike Iselyd8554972006-06-26 20:58:46 -03003 *
4 * Copyright (C) 2005 Mike Isely <isely@pobox.com>
5 * Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
6 *
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
10 *
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.
15 *
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
19 *
20 */
21
22#include "pvrusb2.h"
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>
30
31struct pvr2_tuner_handler {
32 struct pvr2_hdw *hdw;
33 struct pvr2_i2c_client *client;
34 struct pvr2_i2c_handler i2c_handler;
35 int type_update_fl;
36};
37
38
39static void set_type(struct pvr2_tuner_handler *ctxt)
40{
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;
45
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;
52}
53
54
55static int tuner_check(struct pvr2_tuner_handler *ctxt)
56{
57 struct pvr2_hdw *hdw = ctxt->hdw;
58 if (hdw->tuner_updated) ctxt->type_update_fl = !0;
59 return ctxt->type_update_fl != 0;
60}
61
62
63static void tuner_update(struct pvr2_tuner_handler *ctxt)
64{
65 if (ctxt->type_update_fl) set_type(ctxt);
66}
67
68
69static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
70{
Mike Iselya0fd1cb2006-06-30 11:35:28 -030071 ctxt->client->handler = NULL;
Mike Iselyd8554972006-06-26 20:58:46 -030072 kfree(ctxt);
73}
74
75
76static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
77{
78 return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
79}
80
81
Tobias Klauserc5a69d52007-02-17 20:11:19 +010082static const struct pvr2_i2c_handler_functions tuner_funcs = {
Mike Iselyd8554972006-06-26 20:58:46 -030083 .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,
87};
88
89
90int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
91{
92 struct pvr2_tuner_handler *ctxt;
93 if (cp->handler) return 0;
94
Mike Iselyca545f72007-01-20 00:37:11 -030095 ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
Mike Iselyd8554972006-06-26 20:58:46 -030096 if (!ctxt) return 0;
Mike Iselyd8554972006-06-26 20:58:46 -030097
98 ctxt->i2c_handler.func_data = ctxt;
99 ctxt->i2c_handler.func_table = &tuner_funcs;
100 ctxt->type_update_fl = !0;
101 ctxt->client = cp;
102 ctxt->hdw = hdw;
103 cp->handler = &ctxt->i2c_handler;
104 pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x tuner handler set up",
105 cp->client->addr);
106 return !0;
107}
108
109
110
111
112/*
113 Stuff for Emacs to see, in order to encourage consistent editing style:
114 *** Local Variables: ***
115 *** mode: c ***
116 *** fill-column: 70 ***
117 *** tab-width: 8 ***
118 *** c-basic-offset: 8 ***
119 *** End: ***
120 */