• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/src/linux/linux-2.6/drivers/media/video/pvrusb2/
1/*
2 *
3 *  $Id: pvrusb2-tuner.c,v 1.1.1.1 2007/08/03 18:52:41 Exp $
4 *
5 *  Copyright (C) 2005 Mike Isely <isely@pobox.com>
6 *  Copyright (C) 2004 Aurelien Alleaume <slts@free.fr>
7 *
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
11 *
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.
16 *
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
20 *
21 */
22
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>
31
32struct 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;
37};
38
39
40static void set_type(struct pvr2_tuner_handler *ctxt)
41{
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;
46
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;
53}
54
55
56static int tuner_check(struct pvr2_tuner_handler *ctxt)
57{
58	struct pvr2_hdw *hdw = ctxt->hdw;
59	if (hdw->tuner_updated) ctxt->type_update_fl = !0;
60	return ctxt->type_update_fl != 0;
61}
62
63
64static void tuner_update(struct pvr2_tuner_handler *ctxt)
65{
66	if (ctxt->type_update_fl) set_type(ctxt);
67}
68
69
70static void pvr2_tuner_detach(struct pvr2_tuner_handler *ctxt)
71{
72	ctxt->client->handler = NULL;
73	kfree(ctxt);
74}
75
76
77static unsigned int pvr2_tuner_describe(struct pvr2_tuner_handler *ctxt,char *buf,unsigned int cnt)
78{
79	return scnprintf(buf,cnt,"handler: pvrusb2-tuner");
80}
81
82
83static 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,
88};
89
90
91int pvr2_i2c_tuner_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
92{
93	struct pvr2_tuner_handler *ctxt;
94	if (cp->handler) return 0;
95
96	ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL);
97	if (!ctxt) return 0;
98
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;
108}
109
110
111
112
113/*
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: ***
121  */
122