#include <linux/usb.h>
 #include <media/tuner.h>
 #include <media/msp3400.h>
+#include <media/saa7115.h>
+#include <media/tvp5150.h>
 #include <media/tveeprom.h>
 #include <media/audiochip.h>
 #include <media/v4l2-common.h>
                .decoder      = EM28XX_SAA7113,
                .input           = {{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input           = {{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input           = {{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 2,
+                       .vmux     = SAA7115_COMPOSITE2,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 2,
+                       .vmux     = SAA7115_COMPOSITE2,
                        .amux     = 0,
                },{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                /*FIXME: S-Video not tested */
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 0,
+                       .vmux     = TVP5150_COMPOSITE0,
                        .amux     = MSP_INPUT_DEFAULT,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 2,
+                       .vmux     = TVP5150_SVIDEO,
                        .amux     = MSP_INPUT(MSP_IN_SCART1, MSP_IN_TUNER1,
                                        MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
                }},
                .decoder        = EM28XX_SAA7114,
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 4,
+                       .vmux     = SAA7115_COMPOSITE4,
                        .amux     = 0,
                },{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 2,
+                       .vmux     = SAA7115_COMPOSITE2,
                        .amux     = 0,
                },{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 2,
+                       .vmux     = SAA7115_COMPOSITE2,
                        .amux     = 0,
                },{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input          = {{
                        .type     = EM28XX_VMUX_TELEVISION,
-                       .vmux     = 2,
+                       .vmux     = SAA7115_COMPOSITE2,
                        .amux     = 0,
                },{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
                .decoder      = EM28XX_SAA7113,
                .input          = {{
                        .type     = EM28XX_VMUX_COMPOSITE1,
-                       .vmux     = 0,
+                       .vmux     = SAA7115_COMPOSITE0,
                        .amux     = 1,
                },{
                        .type     = EM28XX_VMUX_SVIDEO,
-                       .vmux     = 9,
+                       .vmux     = SAA7115_SVIDEO3,
                        .amux     = 1,
                }},
        },
 
 static void em28xx_config_i2c(struct em28xx *dev)
 {
        struct v4l2_frequency f;
+       struct v4l2_routing route;
+
+       route.input = INPUT(dev->ctl_input)->vmux;
+       route.output = 0;
        em28xx_i2c_call_clients(dev, VIDIOC_INT_RESET, NULL);
-       em28xx_i2c_call_clients(dev, VIDIOC_S_INPUT, &dev->ctl_input);
+       em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
        em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL);
 
        /* configure tuner */
 
 static void video_mux(struct em28xx *dev, int index)
 {
-       int input, ainput;
+       int ainput;
+       struct v4l2_routing route;
 
-       input = INPUT(index)->vmux;
+       route.input = INPUT(index)->vmux;
+       route.output = 0;
        dev->ctl_input = index;
        dev->ctl_ainput = INPUT(index)->amux;
 
-       em28xx_i2c_call_clients(dev, VIDIOC_S_INPUT, &input);
+       em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
 
-       em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,input,dev->ctl_ainput);
+       em28xx_videodbg("Setting input index=%d, vmux=%d, amux=%d\n",index,route.input,dev->ctl_ainput);
 
        if (dev->has_msp34xx) {
-               struct v4l2_routing route;
-
                if (dev->i2s_speed)
                        em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed);
                route.input = dev->ctl_ainput;
 
                break;
        }
 
-       case VIDIOC_G_INPUT:
-               *(int *)arg = state->input;
-               break;
-
-       case VIDIOC_S_INPUT:
-               v4l_dbg(1, debug, client, "decoder set input %d\n", *iarg);
-               /* inputs from 0-9 are available */
-               if (*iarg < 0 || *iarg > 9) {
-                       return -EINVAL;
-               }
-
-               if (state->input == *iarg)
-                       break;
-               v4l_dbg(1, debug, client, "now setting %s input\n",
-                       *iarg >= 6 ? "S-Video" : "Composite");
-               state->input = *iarg;
-
-               /* select mode */
-               saa7115_write(client, 0x02,
-                             (saa7115_read(client, 0x02) & 0xf0) |
-                              state->input);
-
-               /* bypass chrominance trap for modes 6..9 */
-               saa7115_write(client, 0x09,
-                             (saa7115_read(client, 0x09) & 0x7f) |
-                              (state->input < 6 ? 0x0 : 0x80));
-               break;
-
        case VIDIOC_STREAMON:
        case VIDIOC_STREAMOFF:
                v4l_dbg(1, debug, client, "%s output\n",
 
 #include <linux/delay.h>
 #include <linux/video_decoder.h>
 #include <media/v4l2-common.h>
+#include <media/tvp5150.h>
 
 #include "tvp5150_reg.h"
 
        struct i2c_client *client;
 
        v4l2_std_id norm;       /* Current set standard */
-       int input;
+       struct v4l2_routing route;
        int enable;
        int bright;
        int contrast;
 /****************************************************************************
                        Basic functions
  ****************************************************************************/
-enum tvp5150_input {
-       TVP5150_ANALOG_CH0 = 0,
-       TVP5150_SVIDEO = 1,
-       TVP5150_ANALOG_CH1 = 2,
-       TVP5150_BLACK_SCREEN = 8
-};
 
-static inline void tvp5150_selmux(struct i2c_client *c,
-                                 enum tvp5150_input input)
+static inline void tvp5150_selmux(struct i2c_client *c)
 {
        int opmode=0;
-
        struct tvp5150 *decoder = i2c_get_clientdata(c);
+       int input = 0;
 
-       if (!decoder->enable)
-               input |= TVP5150_BLACK_SCREEN;
+       if ((decoder->route.output & TVP5150_BLACK_SCREEN) || !decoder->enable)
+               input = 8;
 
        switch (input) {
-       case TVP5150_ANALOG_CH0:
-       case TVP5150_ANALOG_CH1:
+       case TVP5150_COMPOSITE1:
+               input |= 2;
+               /* fall through */
+       case TVP5150_COMPOSITE0:
                opmode=0x30;            /* TV Mode */
                break;
+       case TVP5150_SVIDEO:
        default:
+               input |= 1;
                opmode=0;               /* Auto Mode */
                break;
        }
        tvp5150_vdp_init(c, vbi_ram_default);
 
        /* Selects decoder input */
-       tvp5150_selmux(c, decoder->input);
+       tvp5150_selmux(c);
 
        /* Initializes TVP5150 to stream enabled values */
        tvp5150_write_inittab(c, tvp5150_init_enable);
        case VIDIOC_INT_RESET:
                tvp5150_reset(c);
                break;
+       case VIDIOC_INT_G_VIDEO_ROUTING:
+       {
+               struct v4l2_routing *route = arg;
+
+               *route = decoder->route;
+               break;
+       }
+       case VIDIOC_INT_S_VIDEO_ROUTING:
+       {
+               struct v4l2_routing *route = arg;
+
+               decoder->route = *route;
+               tvp5150_selmux(c);
+               break;
+       }
        case VIDIOC_S_STD:
                if (decoder->norm == *(v4l2_std_id *)arg)
                        break;
        rv = i2c_attach_client(c);
 
        core->norm = V4L2_STD_ALL;      /* Default is autodetect */
-       core->input = 2;
+       core->route.input = TVP5150_COMPOSITE1;
        core->enable = 1;
        core->bright = 32768;
        core->contrast = 32768;
 
--- /dev/null
+/*
+    tvp5150.h - definition for tvp5150 inputs
+
+    Copyright (C) 2006 Hans Verkuil (hverkuil@xs4all.nl)
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef _TVP5150_H_
+#define _TVP5150_H_
+
+/* TVP5150 HW inputs */
+#define TVP5150_COMPOSITE0 0
+#define TVP5150_COMPOSITE1 1
+#define TVP5150_SVIDEO     2
+
+/* TVP5150 HW outputs */
+#define TVP5150_NORMAL       0
+#define TVP5150_BLACK_SCREEN 1
+
+#endif
+