Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * $Id$ |
| 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-audio.h" |
| 24 | #include "pvrusb2-hdw-internal.h" |
| 25 | #include "pvrusb2-debug.h" |
| 26 | #include <linux/videodev2.h> |
| 27 | #include <media/msp3400.h> |
| 28 | #include <media/v4l2-common.h> |
| 29 | |
| 30 | struct pvr2_msp3400_handler { |
| 31 | struct pvr2_hdw *hdw; |
| 32 | struct pvr2_i2c_client *client; |
| 33 | struct pvr2_i2c_handler i2c_handler; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 34 | unsigned long stale_mask; |
| 35 | }; |
| 36 | |
| 37 | |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 38 | |
| 39 | struct routing_scheme { |
| 40 | const int *def; |
| 41 | unsigned int cnt; |
| 42 | }; |
| 43 | |
| 44 | static const int routing_scheme0[] = { |
| 45 | [PVR2_CVAL_INPUT_TV] = MSP_INPUT_DEFAULT, |
| 46 | [PVR2_CVAL_INPUT_RADIO] = MSP_INPUT(MSP_IN_SCART2, |
| 47 | MSP_IN_TUNER1, |
| 48 | MSP_DSP_IN_SCART, |
| 49 | MSP_DSP_IN_SCART), |
| 50 | [PVR2_CVAL_INPUT_COMPOSITE] = MSP_INPUT(MSP_IN_SCART1, |
| 51 | MSP_IN_TUNER1, |
| 52 | MSP_DSP_IN_SCART, |
| 53 | MSP_DSP_IN_SCART), |
| 54 | [PVR2_CVAL_INPUT_SVIDEO] = MSP_INPUT(MSP_IN_SCART1, |
| 55 | MSP_IN_TUNER1, |
| 56 | MSP_DSP_IN_SCART, |
| 57 | MSP_DSP_IN_SCART), |
| 58 | }; |
| 59 | |
| 60 | static const struct routing_scheme routing_schemes[] = { |
| 61 | [PVR2_ROUTING_SCHEME_HAUPPAUGE] = { |
| 62 | .def = routing_scheme0, |
| 63 | .cnt = ARRAY_SIZE(routing_scheme0), |
| 64 | }, |
| 65 | }; |
| 66 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 67 | /* This function selects the correct audio input source */ |
| 68 | static void set_stereo(struct pvr2_msp3400_handler *ctxt) |
| 69 | { |
| 70 | struct pvr2_hdw *hdw = ctxt->hdw; |
| 71 | struct v4l2_routing route; |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 72 | const struct routing_scheme *sp; |
| 73 | unsigned int sid = hdw->hdw_desc->signal_routing_scheme; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 74 | |
| 75 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c msp3400 v4l2 set_stereo"); |
| 76 | |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 77 | if ((sid < ARRAY_SIZE(routing_schemes)) && |
Harvey Harrison | a6a3a17 | 2008-04-28 16:50:03 -0700 | [diff] [blame^] | 78 | ((sp = routing_schemes + sid) != NULL) && |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 79 | (hdw->input_val >= 0) && |
| 80 | (hdw->input_val < sp->cnt)) { |
| 81 | route.input = sp->def[hdw->input_val]; |
| 82 | } else { |
| 83 | pvr2_trace(PVR2_TRACE_ERROR_LEGS, |
| 84 | "*** WARNING *** i2c msp3400 v4l2 set_stereo:" |
| 85 | " Invalid routing scheme (%u) and/or input (%d)", |
| 86 | sid,hdw->input_val); |
| 87 | return; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 88 | } |
Mike Isely | f5174af | 2007-11-26 02:07:26 -0300 | [diff] [blame] | 89 | route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 90 | pvr2_i2c_client_cmd(ctxt->client,VIDIOC_INT_S_AUDIO_ROUTING,&route); |
| 91 | } |
| 92 | |
| 93 | |
| 94 | static int check_stereo(struct pvr2_msp3400_handler *ctxt) |
| 95 | { |
| 96 | struct pvr2_hdw *hdw = ctxt->hdw; |
Mike Isely | 606cf9c | 2007-01-20 01:56:04 -0300 | [diff] [blame] | 97 | return hdw->input_dirty; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
| 101 | struct pvr2_msp3400_ops { |
| 102 | void (*update)(struct pvr2_msp3400_handler *); |
| 103 | int (*check)(struct pvr2_msp3400_handler *); |
| 104 | }; |
| 105 | |
| 106 | |
| 107 | static const struct pvr2_msp3400_ops msp3400_ops[] = { |
| 108 | { .update = set_stereo, .check = check_stereo}, |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | static int msp3400_check(struct pvr2_msp3400_handler *ctxt) |
| 113 | { |
| 114 | unsigned long msk; |
| 115 | unsigned int idx; |
| 116 | |
Mike Isely | 27c7b71 | 2007-01-20 00:39:17 -0300 | [diff] [blame] | 117 | for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 118 | msk = 1 << idx; |
| 119 | if (ctxt->stale_mask & msk) continue; |
| 120 | if (msp3400_ops[idx].check(ctxt)) { |
| 121 | ctxt->stale_mask |= msk; |
| 122 | } |
| 123 | } |
| 124 | return ctxt->stale_mask != 0; |
| 125 | } |
| 126 | |
| 127 | |
| 128 | static void msp3400_update(struct pvr2_msp3400_handler *ctxt) |
| 129 | { |
| 130 | unsigned long msk; |
| 131 | unsigned int idx; |
| 132 | |
Mike Isely | 27c7b71 | 2007-01-20 00:39:17 -0300 | [diff] [blame] | 133 | for (idx = 0; idx < ARRAY_SIZE(msp3400_ops); idx++) { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 134 | msk = 1 << idx; |
| 135 | if (!(ctxt->stale_mask & msk)) continue; |
| 136 | ctxt->stale_mask &= ~msk; |
| 137 | msp3400_ops[idx].update(ctxt); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 142 | static void pvr2_msp3400_detach(struct pvr2_msp3400_handler *ctxt) |
| 143 | { |
Mike Isely | a0fd1cb | 2006-06-30 11:35:28 -0300 | [diff] [blame] | 144 | ctxt->client->handler = NULL; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 145 | kfree(ctxt); |
| 146 | } |
| 147 | |
| 148 | |
| 149 | static unsigned int pvr2_msp3400_describe(struct pvr2_msp3400_handler *ctxt, |
| 150 | char *buf,unsigned int cnt) |
| 151 | { |
| 152 | return scnprintf(buf,cnt,"handler: pvrusb2-audio v4l2"); |
| 153 | } |
| 154 | |
| 155 | |
Tobias Klauser | c5a69d5 | 2007-02-17 20:11:19 +0100 | [diff] [blame] | 156 | static const struct pvr2_i2c_handler_functions msp3400_funcs = { |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 157 | .detach = (void (*)(void *))pvr2_msp3400_detach, |
| 158 | .check = (int (*)(void *))msp3400_check, |
| 159 | .update = (void (*)(void *))msp3400_update, |
| 160 | .describe = (unsigned int (*)(void *,char *,unsigned int))pvr2_msp3400_describe, |
| 161 | }; |
| 162 | |
| 163 | |
| 164 | int pvr2_i2c_msp3400_setup(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp) |
| 165 | { |
| 166 | struct pvr2_msp3400_handler *ctxt; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 167 | if (cp->handler) return 0; |
| 168 | |
Mike Isely | ca545f7 | 2007-01-20 00:37:11 -0300 | [diff] [blame] | 169 | ctxt = kzalloc(sizeof(*ctxt),GFP_KERNEL); |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 170 | if (!ctxt) return 0; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 171 | |
| 172 | ctxt->i2c_handler.func_data = ctxt; |
| 173 | ctxt->i2c_handler.func_table = &msp3400_funcs; |
| 174 | ctxt->client = cp; |
| 175 | ctxt->hdw = hdw; |
Mike Isely | 27c7b71 | 2007-01-20 00:39:17 -0300 | [diff] [blame] | 176 | ctxt->stale_mask = (1 << ARRAY_SIZE(msp3400_ops)) - 1; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 177 | cp->handler = &ctxt->i2c_handler; |
Mike Isely | d855497 | 2006-06-26 20:58:46 -0300 | [diff] [blame] | 178 | pvr2_trace(PVR2_TRACE_CHIPS,"i2c 0x%x msp3400 V4L2 handler set up", |
| 179 | cp->client->addr); |
| 180 | return !0; |
| 181 | } |
| 182 | |
| 183 | |
| 184 | /* |
| 185 | Stuff for Emacs to see, in order to encourage consistent editing style: |
| 186 | *** Local Variables: *** |
| 187 | *** mode: c *** |
| 188 | *** fill-column: 70 *** |
| 189 | *** tab-width: 8 *** |
| 190 | *** c-basic-offset: 8 *** |
| 191 | *** End: *** |
| 192 | */ |