V4L/DVB (5929): Add vp27smpx driver
authorHans Verkuil <hverkuil@xs4all.nl>
Fri, 27 Jul 2007 09:56:50 +0000 (06:56 -0300)
committerMauro Carvalho Chehab <mchehab@infradead.org>
Wed, 10 Oct 2007 01:03:25 +0000 (22:03 -0300)
This device is internal to the Panasonic VP27S tuner and is used to set
the mono/stereo/bilingual setting of the tuner.

It is used by two Japanese cx23416-based cards.

Signed-off-by: Takahiro Adachi <tadachi@tadachi-net.com>
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/ivtv/Kconfig
drivers/media/video/ivtv/ivtv-cards.c
drivers/media/video/ivtv/ivtv-cards.h
drivers/media/video/ivtv/ivtv-driver.c
drivers/media/video/ivtv/ivtv-i2c.c
drivers/media/video/vp27smpx.c [new file with mode: 0644]
include/linux/i2c-id.h
include/media/v4l2-chip-ident.h

index 675c8574403eac8ac54019045a5f5e07512204e2..0e1d2ccc4e8164189ae2b78185c60424c7f404c8 100644 (file)
@@ -148,6 +148,15 @@ config VIDEO_WM8739
          To compile this driver as a module, choose M here: the
          module will be called wm8739.
 
+config VIDEO_VP27SMPX
+       tristate "Panasonic VP27s internal MPX"
+       depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
+       ---help---
+         Support for the internal MPX of the Panasonic VP27s tuner.
+
+         To compile this driver as a module, choose M here: the
+         module will be called vp27smpx.
+
 comment "Video decoders"
 
 config VIDEO_BT819
index c5286bfba44768c763ec5b95434b39785f4b4aa0..113e525f6dabdf3fdeb5eca4928c8345b3b61b8e 100644 (file)
@@ -73,6 +73,7 @@ obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
 obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o
 obj-$(CONFIG_VIDEO_WM8775) += wm8775.o
 obj-$(CONFIG_VIDEO_WM8739) += wm8739.o
+obj-$(CONFIG_VIDEO_VP27SMPX) += vp27smpx.o
 obj-$(CONFIG_VIDEO_OVCAMCHIP) += ovcamchip/
 obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
 obj-$(CONFIG_VIDEO_MXB) += mxb.o
index 399f231abb965c31a058645e279a0a10aea7223c..5efacb3321143fa19da301b9b85928f7c32a8132 100644 (file)
@@ -14,6 +14,7 @@ config VIDEO_IVTV
        select VIDEO_CS53L32A
        select VIDEO_WM8775
        select VIDEO_WM8739
+       select VIDEO_VP27SMPX
        select VIDEO_UPD64031A
        select VIDEO_UPD64083
        ---help---
index baab14b40e87dc974f9ae129e4fb6f057e85aabb..e51d7cc35b1c1f200c85e9851afdabcc1013efe1 100644 (file)
@@ -616,7 +616,7 @@ static const struct ivtv_card ivtv_card_gv_mvprx = {
        .hw_video = IVTV_HW_SAA7115 | IVTV_HW_UPD64031A | IVTV_HW_UPD6408X,
        .hw_audio = IVTV_HW_GPIO,
        .hw_audio_ctrl = IVTV_HW_WM8739,
-       .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_TVAUDIO |
+       .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_VP27SMPX |
                  IVTV_HW_TUNER | IVTV_HW_WM8739 |
                  IVTV_HW_UPD64031A | IVTV_HW_UPD6408X,
        .video_inputs = {
@@ -654,7 +654,7 @@ static const struct ivtv_card ivtv_card_gv_mvprx2e = {
        .hw_audio = IVTV_HW_GPIO,
        .hw_audio_ctrl = IVTV_HW_WM8739,
        .hw_all = IVTV_HW_GPIO | IVTV_HW_SAA7115 | IVTV_HW_TUNER |
-                 IVTV_HW_TVAUDIO | IVTV_HW_WM8739,
+                 IVTV_HW_VP27SMPX | IVTV_HW_WM8739,
        .video_inputs = {
                { IVTV_CARD_INPUT_VID_TUNER,  0, IVTV_SAA71XX_COMPOSITE4 },
                { IVTV_CARD_INPUT_SVIDEO1,    1, IVTV_SAA71XX_SVIDEO0    },
index 91e9e90c14a5eaebe90677f3aa165ced92d0c956..3191920f4c6b486d7387c60b171aaeafbe7a3955 100644 (file)
@@ -33,7 +33,8 @@
 #define IVTV_HW_UPD6408X  (1 << 11)
 #define IVTV_HW_SAA717X   (1 << 12)
 #define IVTV_HW_WM8739    (1 << 13)
-#define IVTV_HW_GPIO      (1 << 14)
+#define IVTV_HW_VP27SMPX  (1 << 14)
+#define IVTV_HW_GPIO      (1 << 15)
 
 #define IVTV_HW_SAA711X   (IVTV_HW_SAA7115 | IVTV_HW_SAA7114)
 
index cf52111a2dcc8b521487355e783d2445ea0051a7..f8ef267e56b2eb45dbd8a75ea9a27f2da9373a35 100644 (file)
@@ -853,6 +853,10 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
 #ifndef CONFIG_VIDEO_MSP3400
        if (hw & IVTV_HW_MSP34XX)
                ivtv_request_module(itv, "msp3400");
+#endif
+#ifndef CONFIG_VIDEO_VP27SMPX
+       if (hw & IVTV_HW_VP27SMPX)
+               ivtv_request_module(itv, "vp27smpx");
 #endif
        if (hw & IVTV_HW_TVAUDIO)
                ivtv_request_module(itv, "tvaudio");
index b3557435456db70d0cf170cb942f70c81a72f28a..5e12ebc2a9deea4de122a97d2e709a808393fd8b 100644 (file)
@@ -109,6 +109,7 @@ static const u8 hw_driverids[] = {
        I2C_DRIVERID_UPD64083,
        I2C_DRIVERID_SAA717X,
        I2C_DRIVERID_WM8739,
+       I2C_DRIVERID_VP27SMPX,
        0               /* IVTV_HW_GPIO dummy driver ID */
 };
 
@@ -128,6 +129,7 @@ static const char * const hw_drivernames[] = {
        "upd64083",
        "saa717x",
        "wm8739",
+       "vp27smpx",
        "gpio",
 };
 
diff --git a/drivers/media/video/vp27smpx.c b/drivers/media/video/vp27smpx.c
new file mode 100644 (file)
index 0000000..9aa526b
--- /dev/null
@@ -0,0 +1,211 @@
+/*
+ * vp27smpx - driver version 0.0.1
+ *
+ * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
+ *
+ * Special thanks to Kazz for the i2c data.
+ *
+ * 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.
+ */
+
+#include <linux/module.h>
+#include <linux/types.h>
+#include <linux/ioctl.h>
+#include <asm/uaccess.h>
+#include <linux/i2c.h>
+#include <linux/i2c-id.h>
+#include <linux/videodev.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
+
+MODULE_DESCRIPTION("vp27smpx driver");
+MODULE_AUTHOR("Hans Verkuil");
+MODULE_LICENSE("GPL");
+
+static unsigned short normal_i2c[] = { 0xb6 >> 1, I2C_CLIENT_END };
+
+
+I2C_CLIENT_INSMOD;
+
+/* ----------------------------------------------------------------------- */
+
+struct vp27smpx_state {
+       int radio;
+       u32 audmode;
+};
+
+static void vp27smpx_set_audmode(struct i2c_client *client, u32 audmode)
+{
+       struct vp27smpx_state *state = i2c_get_clientdata(client);
+       u8 data[3] = { 0x00, 0x00, 0x04 };
+
+       switch (audmode) {
+               case V4L2_TUNER_MODE_MONO:
+               case V4L2_TUNER_MODE_LANG1:
+                       break;
+               case V4L2_TUNER_MODE_STEREO:
+               case V4L2_TUNER_MODE_LANG1_LANG2:
+                       data[1] = 0x01;
+                       break;
+               case V4L2_TUNER_MODE_LANG2:
+                       data[1] = 0x02;
+                       break;
+       }
+
+       if (i2c_master_send(client, data, sizeof(data)) != sizeof(data)) {
+               v4l_err(client, "%s: I/O error setting audmode\n", client->name);
+       }
+       else {
+               state->audmode = audmode;
+       }
+}
+
+static int vp27smpx_command(struct i2c_client *client, unsigned int cmd,
+                         void *arg)
+{
+       struct vp27smpx_state *state = i2c_get_clientdata(client);
+       struct v4l2_tuner *vt = arg;
+
+       switch (cmd) {
+       case AUDC_SET_RADIO:
+               state->radio = 1;
+               break;
+
+       case VIDIOC_S_STD:
+               state->radio = 0;
+               break;
+
+       case VIDIOC_S_TUNER:
+               if (!state->radio)
+                       vp27smpx_set_audmode(client, vt->audmode);
+               break;
+
+       case VIDIOC_G_TUNER:
+               if (state->radio)
+                       break;
+               vt->audmode = state->audmode;
+               vt->capability = V4L2_TUNER_CAP_STEREO |
+                       V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
+               vt->rxsubchans = V4L2_TUNER_SUB_MONO;
+               break;
+
+       case VIDIOC_G_CHIP_IDENT:
+               return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_VP27SMPX, 0);
+
+       case VIDIOC_LOG_STATUS:
+               v4l_info(client, "Audio Mode: %u%s\n", state->audmode,
+                               state->radio ? " (Radio)" : "");
+               break;
+
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+
+/* i2c implementation */
+
+/*
+ * Generic i2c probe
+ * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
+ */
+
+static struct i2c_driver i2c_driver;
+
+static int vp27smpx_attach(struct i2c_adapter *adapter, int address, int kind)
+{
+       struct i2c_client *client;
+       struct vp27smpx_state *state;
+
+       /* Check if the adapter supports the needed features */
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+               return 0;
+
+       client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
+       if (client == 0)
+               return -ENOMEM;
+
+       client->addr = address;
+       client->adapter = adapter;
+       client->driver = &i2c_driver;
+       snprintf(client->name, sizeof(client->name) - 1, "vp27smpx");
+
+       v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
+
+       state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
+       if (state == NULL) {
+               kfree(client);
+               return -ENOMEM;
+       }
+       state->audmode = V4L2_TUNER_MODE_STEREO;
+       i2c_set_clientdata(client, state);
+
+       /* initialize vp27smpx */
+       vp27smpx_set_audmode(client, state->audmode);
+       i2c_attach_client(client);
+
+       return 0;
+}
+
+static int vp27smpx_probe(struct i2c_adapter *adapter)
+{
+       if (adapter->class & I2C_CLASS_TV_ANALOG)
+               return i2c_probe(adapter, &addr_data, vp27smpx_attach);
+       return 0;
+}
+
+static int vp27smpx_detach(struct i2c_client *client)
+{
+       struct vp27smpx_state *state = i2c_get_clientdata(client);
+       int err;
+
+       err = i2c_detach_client(client);
+       if (err) {
+               return err;
+       }
+       kfree(state);
+       kfree(client);
+
+       return 0;
+}
+
+/* ----------------------------------------------------------------------- */
+
+/* i2c implementation */
+static struct i2c_driver i2c_driver = {
+       .driver = {
+               .name = "vp27smpx",
+       },
+       .id             = I2C_DRIVERID_VP27SMPX,
+       .attach_adapter = vp27smpx_probe,
+       .detach_client  = vp27smpx_detach,
+       .command        = vp27smpx_command,
+};
+
+
+static int __init vp27smpx_init_module(void)
+{
+       return i2c_add_driver(&i2c_driver);
+}
+
+static void __exit vp27smpx_cleanup_module(void)
+{
+       i2c_del_driver(&i2c_driver);
+}
+
+module_init(vp27smpx_init_module);
+module_exit(vp27smpx_cleanup_module);
index b690148657140aac33bf11c2e1e288a9398e6ac6..4891e03ad23a740c1d000fa1bf49df90b15407bc 100644 (file)
 #define I2C_DRIVERID_WM8750    90      /* Wolfson WM8750 audio codec */
 #define I2C_DRIVERID_WM8753    91      /* Wolfson WM8753 audio codec */
 #define I2C_DRIVERID_LM4857    92      /* LM4857 Audio Amplifier */
+#define I2C_DRIVERID_VP27SMPX  93      /* Panasonic VP27s tuner internal MPX */
 
 #define I2C_DRIVERID_I2CDEV    900
 #define I2C_DRIVERID_ARP        902    /* SMBus ARP Client              */
index 09d16c4f00f7a55ecb6bb37bb0fdf034643209ac..8ae42c41dd08d5bb351f3958491f7a442b1659df 100644 (file)
@@ -65,6 +65,9 @@ enum {
        V4L2_IDENT_CX23415 = 415,
        V4L2_IDENT_CX23416 = 416,
 
+       /* module vp27smpx: just ident 2700 */
+       V4L2_IDENT_VP27SMPX = 2700,
+
        /* module wm8739: just ident 8739 */
        V4L2_IDENT_WM8739 = 8739,