blob: 05e52358ae495a121c94c6722e8f536b5d418eb4 [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/*
23
24 This source file is specifically designed to interface with the
25 cx2584x, in kernels 2.6.16 or newer.
26
27*/
28
29#include "pvrusb2-cx2584x-v4l.h"
30#include "pvrusb2-video-v4l.h"
Mike Iselyd8554972006-06-26 20:58:46 -030031
32
33#include "pvrusb2-hdw-internal.h"
34#include "pvrusb2-debug.h"
35#include <media/cx25840.h>
36#include <linux/videodev2.h>
37#include <media/v4l2-common.h>
38#include <linux/errno.h>
39#include <linux/slab.h>
40
Mike Iselyd8554972006-06-26 20:58:46 -030041
Mike Iselyf5174af2007-11-26 02:07:26 -030042struct routing_scheme_item {
43 int vid;
44 int aud;
45};
46
47struct routing_scheme {
48 const struct routing_scheme_item *def;
49 unsigned int cnt;
50};
51
52static const struct routing_scheme_item routing_scheme0[] = {
53 [PVR2_CVAL_INPUT_TV] = {
54 .vid = CX25840_COMPOSITE7,
55 .aud = CX25840_AUDIO8,
56 },
57 [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
58 .vid = CX25840_COMPOSITE3,
59 .aud = CX25840_AUDIO_SERIAL,
60 },
61 [PVR2_CVAL_INPUT_COMPOSITE] = {
62 .vid = CX25840_COMPOSITE3,
63 .aud = CX25840_AUDIO_SERIAL,
64 },
65 [PVR2_CVAL_INPUT_SVIDEO] = {
66 .vid = CX25840_SVIDEO1,
67 .aud = CX25840_AUDIO_SERIAL,
68 },
69};
70
Mike Isely9e2e3ae2007-11-26 02:14:23 -030071/* Specific to gotview device */
72static const struct routing_scheme_item routing_schemegv[] = {
73 [PVR2_CVAL_INPUT_TV] = {
74 .vid = CX25840_COMPOSITE2,
75 .aud = CX25840_AUDIO5,
76 },
Mike Isely1df59f02008-04-21 03:50:39 -030077 [PVR2_CVAL_INPUT_RADIO] = {
78 /* line-in is used for radio and composite. A GPIO is
79 used to switch between the two choices. */
Mike Isely9e2e3ae2007-11-26 02:14:23 -030080 .vid = CX25840_COMPOSITE1,
81 .aud = CX25840_AUDIO_SERIAL,
82 },
83 [PVR2_CVAL_INPUT_COMPOSITE] = {
84 .vid = CX25840_COMPOSITE1,
85 .aud = CX25840_AUDIO_SERIAL,
86 },
87 [PVR2_CVAL_INPUT_SVIDEO] = {
88 .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
89 .aud = CX25840_AUDIO_SERIAL,
90 },
91};
92
Mike Iselyf5174af2007-11-26 02:07:26 -030093static const struct routing_scheme routing_schemes[] = {
94 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = {
95 .def = routing_scheme0,
96 .cnt = ARRAY_SIZE(routing_scheme0),
97 },
Mike Isely9e2e3ae2007-11-26 02:14:23 -030098 [PVR2_ROUTING_SCHEME_GOTVIEW] = {
99 .def = routing_schemegv,
100 .cnt = ARRAY_SIZE(routing_schemegv),
101 },
Mike Iselyf5174af2007-11-26 02:07:26 -0300102};
103
Mike Isely634ba262009-03-07 00:54:02 -0300104void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
105{
Mike Isely5e430ca2009-03-07 01:51:54 -0300106 pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
Mike Isely27764722009-03-07 01:57:25 -0300107 if (hdw->input_dirty || hdw->force_dirty) {
Mike Isely634ba262009-03-07 00:54:02 -0300108 enum cx25840_video_input vid_input;
109 enum cx25840_audio_input aud_input;
110 const struct routing_scheme *sp;
111 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
112
Mike Isely634ba262009-03-07 00:54:02 -0300113 if ((sid < ARRAY_SIZE(routing_schemes)) &&
114 ((sp = routing_schemes + sid) != NULL) &&
115 (hdw->input_val >= 0) &&
116 (hdw->input_val < sp->cnt)) {
117 vid_input = sp->def[hdw->input_val].vid;
118 aud_input = sp->def[hdw->input_val].aud;
119 } else {
120 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
121 "*** WARNING *** subdev cx2584x set_input:"
122 " Invalid routing scheme (%u)"
123 " and/or input (%d)",
124 sid, hdw->input_val);
125 return;
126 }
127
128 pvr2_trace(PVR2_TRACE_CHIPS,
Mike Isely5e430ca2009-03-07 01:51:54 -0300129 "subdev cx2584x set_input vid=0x%x aud=0x%x",
Mike Isely634ba262009-03-07 00:54:02 -0300130 vid_input, aud_input);
Hans Verkuil5325b422009-04-02 11:26:22 -0300131 sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
132 sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
Mike Isely634ba262009-03-07 00:54:02 -0300133 }
134}
Mike Iselyd8554972006-06-26 20:58:46 -0300135
136
Mike Iselyacd92d42009-03-06 23:32:02 -0300137
Mike Iselyd8554972006-06-26 20:58:46 -0300138/*
139 Stuff for Emacs to see, in order to encourage consistent editing style:
140 *** Local Variables: ***
141 *** mode: c ***
142 *** fill-column: 70 ***
143 *** tab-width: 8 ***
144 *** c-basic-offset: 8 ***
145 *** End: ***
146 */