blob: d5bec0f69becf1f75241a340ed982a88fd81b073 [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 *
Mike Iselyd8554972006-06-26 20:58:46 -030016 */
17
18/*
19
20 This source file is specifically designed to interface with the
21 cx2584x, in kernels 2.6.16 or newer.
22
23*/
24
25#include "pvrusb2-cx2584x-v4l.h"
Mike Iselyd8554972006-06-26 20:58:46 -030026
27
28#include "pvrusb2-hdw-internal.h"
29#include "pvrusb2-debug.h"
Mauro Carvalho Chehabd647f0b2015-11-13 19:40:07 -020030#include <media/drv-intf/cx25840.h>
Mike Iselyd8554972006-06-26 20:58:46 -030031#include <linux/videodev2.h>
32#include <media/v4l2-common.h>
33#include <linux/errno.h>
Mike Iselyd8554972006-06-26 20:58:46 -030034
Mike Iselyd8554972006-06-26 20:58:46 -030035
Mike Iselyf5174af2007-11-26 02:07:26 -030036struct routing_scheme_item {
37 int vid;
38 int aud;
39};
40
41struct routing_scheme {
42 const struct routing_scheme_item *def;
43 unsigned int cnt;
44};
45
46static const struct routing_scheme_item routing_scheme0[] = {
47 [PVR2_CVAL_INPUT_TV] = {
48 .vid = CX25840_COMPOSITE7,
49 .aud = CX25840_AUDIO8,
50 },
51 [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */
52 .vid = CX25840_COMPOSITE3,
53 .aud = CX25840_AUDIO_SERIAL,
54 },
55 [PVR2_CVAL_INPUT_COMPOSITE] = {
56 .vid = CX25840_COMPOSITE3,
57 .aud = CX25840_AUDIO_SERIAL,
58 },
59 [PVR2_CVAL_INPUT_SVIDEO] = {
60 .vid = CX25840_SVIDEO1,
61 .aud = CX25840_AUDIO_SERIAL,
62 },
63};
64
Mike Isely81e804c2009-06-20 14:55:31 -030065static const struct routing_scheme routing_def0 = {
66 .def = routing_scheme0,
67 .cnt = ARRAY_SIZE(routing_scheme0),
68};
69
Mike Isely9e2e3ae2007-11-26 02:14:23 -030070/* Specific to gotview device */
71static const struct routing_scheme_item routing_schemegv[] = {
72 [PVR2_CVAL_INPUT_TV] = {
73 .vid = CX25840_COMPOSITE2,
74 .aud = CX25840_AUDIO5,
75 },
Mike Isely1df59f02008-04-21 03:50:39 -030076 [PVR2_CVAL_INPUT_RADIO] = {
77 /* line-in is used for radio and composite. A GPIO is
78 used to switch between the two choices. */
Mike Isely9e2e3ae2007-11-26 02:14:23 -030079 .vid = CX25840_COMPOSITE1,
80 .aud = CX25840_AUDIO_SERIAL,
81 },
82 [PVR2_CVAL_INPUT_COMPOSITE] = {
83 .vid = CX25840_COMPOSITE1,
84 .aud = CX25840_AUDIO_SERIAL,
85 },
86 [PVR2_CVAL_INPUT_SVIDEO] = {
87 .vid = (CX25840_SVIDEO_LUMA3|CX25840_SVIDEO_CHROMA4),
88 .aud = CX25840_AUDIO_SERIAL,
89 },
90};
91
Mike Isely81e804c2009-06-20 14:55:31 -030092static const struct routing_scheme routing_defgv = {
93 .def = routing_schemegv,
94 .cnt = ARRAY_SIZE(routing_schemegv),
95};
96
Mike Isely43823c02011-03-13 20:37:11 -030097/* Specific to grabster av400 device */
98static const struct routing_scheme_item routing_schemeav400[] = {
99 [PVR2_CVAL_INPUT_COMPOSITE] = {
100 .vid = CX25840_COMPOSITE1,
101 .aud = CX25840_AUDIO_SERIAL,
102 },
103 [PVR2_CVAL_INPUT_SVIDEO] = {
104 .vid = (CX25840_SVIDEO_LUMA2|CX25840_SVIDEO_CHROMA4),
105 .aud = CX25840_AUDIO_SERIAL,
106 },
107};
108
109static const struct routing_scheme routing_defav400 = {
110 .def = routing_schemeav400,
111 .cnt = ARRAY_SIZE(routing_schemeav400),
112};
113
Mike Isely81e804c2009-06-20 14:55:31 -0300114static const struct routing_scheme *routing_schemes[] = {
115 [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0,
116 [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv,
Mike Isely43823c02011-03-13 20:37:11 -0300117 [PVR2_ROUTING_SCHEME_AV400] = &routing_defav400,
Mike Iselyf5174af2007-11-26 02:07:26 -0300118};
119
Mike Isely634ba262009-03-07 00:54:02 -0300120void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
121{
Mike Isely5e430ca2009-03-07 01:51:54 -0300122 pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update...");
Mike Isely27764722009-03-07 01:57:25 -0300123 if (hdw->input_dirty || hdw->force_dirty) {
Mike Isely634ba262009-03-07 00:54:02 -0300124 enum cx25840_video_input vid_input;
125 enum cx25840_audio_input aud_input;
126 const struct routing_scheme *sp;
127 unsigned int sid = hdw->hdw_desc->signal_routing_scheme;
128
Mike Isely90135c92009-06-20 14:57:24 -0300129 sp = (sid < ARRAY_SIZE(routing_schemes)) ?
130 routing_schemes[sid] : NULL;
131 if ((sp == NULL) ||
132 (hdw->input_val < 0) ||
133 (hdw->input_val >= sp->cnt)) {
Mike Isely634ba262009-03-07 00:54:02 -0300134 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
Mauro Carvalho Chehab96292c82016-10-18 17:44:18 -0200135 "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)",
Mike Isely634ba262009-03-07 00:54:02 -0300136 sid, hdw->input_val);
137 return;
138 }
Mike Isely90135c92009-06-20 14:57:24 -0300139 vid_input = sp->def[hdw->input_val].vid;
140 aud_input = sp->def[hdw->input_val].aud;
Mike Isely634ba262009-03-07 00:54:02 -0300141 pvr2_trace(PVR2_TRACE_CHIPS,
Mike Isely5e430ca2009-03-07 01:51:54 -0300142 "subdev cx2584x set_input vid=0x%x aud=0x%x",
Mike Isely634ba262009-03-07 00:54:02 -0300143 vid_input, aud_input);
Hans Verkuil5325b422009-04-02 11:26:22 -0300144 sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0);
145 sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
Mike Isely634ba262009-03-07 00:54:02 -0300146 }
147}