Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 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 | * |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 16 | */ |
| 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 Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 26 | |
| 27 | |
| 28 | #include "pvrusb2-hdw-internal.h" |
| 29 | #include "pvrusb2-debug.h" |
Mauro Carvalho Chehab | d647f0b | 2015-11-13 19:40:07 -0200 | [diff] [blame] | 30 | #include <media/drv-intf/cx25840.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 31 | #include <linux/videodev2.h> |
| 32 | #include <media/v4l2-common.h> |
| 33 | #include <linux/errno.h> |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 34 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 35 | |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 36 | struct routing_scheme_item { |
| 37 | int vid; |
| 38 | int aud; |
| 39 | }; |
| 40 | |
| 41 | struct routing_scheme { |
| 42 | const struct routing_scheme_item *def; |
| 43 | unsigned int cnt; |
| 44 | }; |
| 45 | |
| 46 | static 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 Isely | 81e804c | 2009-06-20 14:55:31 -0300 | [diff] [blame] | 65 | static const struct routing_scheme routing_def0 = { |
| 66 | .def = routing_scheme0, |
| 67 | .cnt = ARRAY_SIZE(routing_scheme0), |
| 68 | }; |
| 69 | |
Mike Isely | 9e2e3ae | 2007-11-26 02:14:23 -0300 | [diff] [blame] | 70 | /* Specific to gotview device */ |
| 71 | static const struct routing_scheme_item routing_schemegv[] = { |
| 72 | [PVR2_CVAL_INPUT_TV] = { |
| 73 | .vid = CX25840_COMPOSITE2, |
| 74 | .aud = CX25840_AUDIO5, |
| 75 | }, |
Mike Isely | 1df59f0 | 2008-04-21 03:50:39 -0300 | [diff] [blame] | 76 | [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 Isely | 9e2e3ae | 2007-11-26 02:14:23 -0300 | [diff] [blame] | 79 | .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 Isely | 81e804c | 2009-06-20 14:55:31 -0300 | [diff] [blame] | 92 | static const struct routing_scheme routing_defgv = { |
| 93 | .def = routing_schemegv, |
| 94 | .cnt = ARRAY_SIZE(routing_schemegv), |
| 95 | }; |
| 96 | |
Mike Isely | 43823c0 | 2011-03-13 20:37:11 -0300 | [diff] [blame] | 97 | /* Specific to grabster av400 device */ |
| 98 | static 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 | |
| 109 | static const struct routing_scheme routing_defav400 = { |
| 110 | .def = routing_schemeav400, |
| 111 | .cnt = ARRAY_SIZE(routing_schemeav400), |
| 112 | }; |
| 113 | |
Mike Isely | 81e804c | 2009-06-20 14:55:31 -0300 | [diff] [blame] | 114 | static const struct routing_scheme *routing_schemes[] = { |
| 115 | [PVR2_ROUTING_SCHEME_HAUPPAUGE] = &routing_def0, |
| 116 | [PVR2_ROUTING_SCHEME_GOTVIEW] = &routing_defgv, |
Mike Isely | 43823c0 | 2011-03-13 20:37:11 -0300 | [diff] [blame] | 117 | [PVR2_ROUTING_SCHEME_AV400] = &routing_defav400, |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 118 | }; |
| 119 | |
Mike Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 120 | void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd) |
| 121 | { |
Mike Isely | 5e430ca | 2009-03-07 01:51:54 -0300 | [diff] [blame] | 122 | pvr2_trace(PVR2_TRACE_CHIPS, "subdev cx2584x update..."); |
Mike Isely | 2776472 | 2009-03-07 01:57:25 -0300 | [diff] [blame] | 123 | if (hdw->input_dirty || hdw->force_dirty) { |
Mike Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 124 | 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 Isely | 90135c9 | 2009-06-20 14:57:24 -0300 | [diff] [blame] | 129 | 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 Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 134 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
Mauro Carvalho Chehab | 96292c8 | 2016-10-18 17:44:18 -0200 | [diff] [blame] | 135 | "*** WARNING *** subdev cx2584x set_input: Invalid routing scheme (%u) and/or input (%d)", |
Mike Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 136 | sid, hdw->input_val); |
| 137 | return; |
| 138 | } |
Mike Isely | 90135c9 | 2009-06-20 14:57:24 -0300 | [diff] [blame] | 139 | vid_input = sp->def[hdw->input_val].vid; |
| 140 | aud_input = sp->def[hdw->input_val].aud; |
Mike Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 141 | pvr2_trace(PVR2_TRACE_CHIPS, |
Mike Isely | 5e430ca | 2009-03-07 01:51:54 -0300 | [diff] [blame] | 142 | "subdev cx2584x set_input vid=0x%x aud=0x%x", |
Mike Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 143 | vid_input, aud_input); |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 144 | sd->ops->video->s_routing(sd, (u32)vid_input, 0, 0); |
| 145 | sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0); |
Mike Isely | 634ba26 | 2009-03-07 00:54:02 -0300 | [diff] [blame] | 146 | } |
| 147 | } |