• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *
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 
31 struct 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 
set_type(struct pvr2_tuner_handler * ctxt)39 static 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 
tuner_check(struct pvr2_tuner_handler * ctxt)55 static 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 
tuner_update(struct pvr2_tuner_handler * ctxt)63 static void tuner_update(struct pvr2_tuner_handler *ctxt)
64 {
65 	if (ctxt->type_update_fl) set_type(ctxt);
66 }
67 
68 
pvr2_tuner_detach(struct pvr2_tuner_handler * ctxt)69 static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
70 {
71 	ctxt->client->handler = NULL;
72 	kfree(ctxt);
73 }
74 
75 
pvr2_tuner_describe(struct pvr2_tuner_handler * ctxt,char * buf,unsigned int cnt)76 static 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 
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,
87 };
88 
89 
pvr2_i2c_tuner_setup(struct pvr2_hdw * hdw,struct pvr2_i2c_client * cp)90 int 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 
95 	ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
96 	if (!ctxt) return 0;
97 
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   */
121