Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev add driver for the Auvitek AU0828 USB video controll...



details:   https://anonhg.NetBSD.org/src/rev/7e1f3246d90d
branches:  trunk
changeset: 760114:7e1f3246d90d
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Dec 27 15:42:11 2010 +0000

description:
add driver for the Auvitek AU0828 USB video controllers's analog video
capture functions:

 auvitek0 at uhub6 port 2: AU0828
 video0 at auvitek0: WinTV HVR-950Q
 uaudio0 at auvitek0 port 2 configuration 1 interface 1
 uaudio0: vendor 0x2040 product 0x7200, rev 2.00/0.05, addr 2
 uaudio0: audio rev 1.00
 audio1 at uaudio0: full duplex, playback, capture, independent

diffstat:

 sys/dev/i2c/au8522.c        |  277 +++++++++++++++
 sys/dev/i2c/au8522reg.h     |   84 ++++
 sys/dev/i2c/au8522var.h     |   62 +++
 sys/dev/i2c/xc5k.c          |  344 ++++++++++++++++++
 sys/dev/i2c/xc5kreg.h       |   66 +++
 sys/dev/i2c/xc5kvar.h       |   57 +++
 sys/dev/usb/auvitek.c       |  309 ++++++++++++++++
 sys/dev/usb/auvitek_audio.c |  144 +++++++
 sys/dev/usb/auvitek_board.c |  113 ++++++
 sys/dev/usb/auvitek_i2c.c   |  273 ++++++++++++++
 sys/dev/usb/auvitek_video.c |  803 ++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/usb/auvitekreg.h    |   76 ++++
 sys/dev/usb/auvitekvar.h    |  130 +++++++
 13 files changed, 2738 insertions(+), 0 deletions(-)

diffs (truncated from 2790 to 300 lines):

diff -r 6f06b556401c -r 7e1f3246d90d sys/dev/i2c/au8522.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/au8522.c      Mon Dec 27 15:42:11 2010 +0000
@@ -0,0 +1,277 @@
+/* $NetBSD: au8522.c,v 1.1 2010/12/27 15:42:11 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Auvitek AU8522
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: au8522.c,v 1.1 2010/12/27 15:42:11 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+#include <sys/module.h>
+
+#include <dev/i2c/i2cvar.h>
+
+#include <dev/i2c/au8522reg.h>
+#include <dev/i2c/au8522var.h>
+
+static int     au8522_reset(struct au8522 *);
+static int     au8522_read_1(struct au8522 *, uint16_t, uint8_t *);
+static int     au8522_write_1(struct au8522 *, uint16_t, uint8_t);
+static int     au8522_set_vinput(struct au8522 *, au8522_vinput_t);
+static int     au8522_set_ainput(struct au8522 *, au8522_ainput_t);
+static void    au8522_set_common(struct au8522 *, au8522_vinput_t);
+
+static int
+au8522_reset(struct au8522 *au)
+{
+       return au8522_write_1(au, 0xa4, 1 << 5);
+}
+
+static int
+au8522_read_1(struct au8522 *au, uint16_t reg, uint8_t *val)
+{
+       uint8_t cmd[2];
+       int error;
+
+       cmd[0] = (reg >> 8) | 0x40;
+       cmd[1] = reg & 0xff;
+       error = iic_exec(au->i2c, I2C_OP_WRITE, au->i2c_addr,
+           cmd, sizeof(cmd), NULL, 0, 0);
+       if (error)
+               return error;
+       return iic_exec(au->i2c, I2C_OP_READ, au->i2c_addr,
+                   NULL, 0, val, sizeof(*val), 0);
+}
+
+static int
+au8522_write_1(struct au8522 *au, uint16_t reg, uint8_t val)
+{
+       uint8_t data[3];
+
+       data[0] = (reg >> 8) | 0x80;
+       data[1] = reg & 0xff;
+       data[2] = val;
+       return iic_exec(au->i2c, I2C_OP_WRITE, au->i2c_addr,
+           data, sizeof(data), NULL, 0, 0);
+}
+
+static int
+au8522_set_vinput(struct au8522 *au, au8522_vinput_t vi)
+{
+       switch (vi) {
+       case AU8522_VINPUT_CVBS:
+               au8522_write_1(au, AU8522_REG_MODCLKCTL, AU8522_MODCLKCTL_CVBS);
+               au8522_write_1(au, AU8522_REG_PGACTL, 0x00);
+               au8522_write_1(au, AU8522_REG_CLAMPCTL, 0x0e);
+               au8522_write_1(au, AU8522_REG_PGACTL, 0x10);
+               au8522_write_1(au, AU8522_REG_INPUTCTL,
+                   AU8522_INPUTCTL_CVBS_CH1);
+
+               au8522_set_common(au, vi);
+
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_CVBS);
+               break;
+       case AU8522_VINPUT_SVIDEO:
+               au8522_write_1(au, AU8522_REG_MODCLKCTL,
+                   AU8522_MODCLKCTL_SVIDEO);
+               au8522_write_1(au, AU8522_REG_INPUTCTL,
+                   AU8522_INPUTCTL_SVIDEO_CH13);
+               au8522_write_1(au, AU8522_REG_CLAMPCTL, 0x00);
+
+               au8522_set_common(au, vi);
+
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_CVBS);
+
+               break;
+       case AU8522_VINPUT_CVBS_TUNER:
+               au8522_write_1(au, AU8522_REG_MODCLKCTL, AU8522_MODCLKCTL_CVBS);
+               au8522_write_1(au, AU8522_REG_PGACTL, 0x00);
+               au8522_write_1(au, AU8522_REG_CLAMPCTL, 0x0e);
+               au8522_write_1(au, AU8522_REG_PGACTL, 0x10);
+               au8522_write_1(au, AU8522_REG_INPUTCTL,
+                   AU8522_INPUTCTL_CVBS_CH4_SIF);
+
+               au8522_set_common(au, vi);
+
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_CVBS);
+
+               break;
+       default:
+               return EINVAL;
+       }
+
+       return 0;
+}
+
+static void
+au8522_set_common(struct au8522 *au, au8522_vinput_t vi)
+{
+       au8522_write_1(au, AU8522_REG_INTMASK, 0x00);
+       au8522_write_1(au, AU8522_REG_VIDEOMODE, vi == AU8522_VINPUT_SVIDEO ?
+           AU8522_VIDEOMODE_SVIDEO : AU8522_VIDEOMODE_CVBS);
+       au8522_write_1(au, AU8522_REG_TV_PGA, AU8522_TV_PGA_CVBS);
+}
+
+static int
+au8522_set_ainput(struct au8522 *au, au8522_ainput_t ai)
+{
+       /* mute during mode change */
+       au8522_write_1(au, AU8522_REG_AUDIO_VOL_L, 0x00);
+       au8522_write_1(au, AU8522_REG_AUDIO_VOL_R, 0x00);
+       au8522_write_1(au, AU8522_REG_AUDIO_VOL, 0x00);
+
+       switch (ai) {
+       case AU8522_AINPUT_SIF:
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_CVBS);
+               au8522_write_1(au, AU8522_REG_AUDIO_MODE, 0x82);
+               au8522_write_1(au, AU8522_REG_SYSMODCTL1,
+                   AU8522_SYSMODCTL1_I2S);
+               au8522_write_1(au, AU8522_REG_AUDIO_FREQ, 0x03);
+               au8522_write_1(au, AU8522_REG_I2S_CTL2, 0xc2);
+               /* unmute */
+               au8522_write_1(au, AU8522_REG_AUDIO_VOL_L, 0x7f);
+               au8522_write_1(au, AU8522_REG_AUDIO_VOL_R, 0x7f);
+               au8522_write_1(au, AU8522_REG_AUDIO_VOL, 0xff);
+               break;
+       case AU8522_AINPUT_NONE:
+               au8522_write_1(au, AU8522_REG_USBEN, 0x00);
+               au8522_write_1(au, AU8522_REG_AUDIO_VOL_L, 0x7f);
+               au8522_write_1(au, AU8522_REG_AUDIO_VOL_R, 0x7f);
+               au8522_write_1(au, AU8522_REG_AUDIO_MODE, 0x40);
+               au8522_write_1(au, AU8522_REG_SYSMODCTL1,
+                   AU8522_SYSMODCTL1_SVIDEO);
+               au8522_write_1(au, AU8522_REG_AUDIO_FREQ, 0x03);
+               au8522_write_1(au, AU8522_REG_I2S_CTL2, 0x02);
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_CVBS);
+               break;
+       default:
+               return EINVAL;
+       }
+       return 0;
+}
+
+struct au8522 *
+au8522_open(device_t parent, i2c_tag_t i2c, i2c_addr_t addr)
+{
+       struct au8522 *au;
+
+       au = kmem_alloc(sizeof(*au), KM_SLEEP);
+       if (au == NULL)
+               return NULL;
+       au->parent = parent;
+       au->i2c = i2c;
+       au->i2c_addr = addr;
+
+       if (au8522_reset(au))
+               goto failed;
+       if (au8522_write_1(au, AU8522_REG_TUNERCTL, AU8522_TUNERCTL_EN))
+               goto failed;
+
+       return au;
+
+failed:
+       kmem_free(au, sizeof(*au));
+       return NULL;
+}
+
+void
+au8522_close(struct au8522 *au)
+{
+       kmem_free(au, sizeof(*au));
+}
+
+void
+au8522_enable(struct au8522 *au, bool enable)
+{
+       if (enable) {
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_RESET);
+               delay(1000);
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_CVBS);
+       } else {
+               au8522_write_1(au, AU8522_REG_SYSMODCTL0,
+                   AU8522_SYSMODCTL0_DISABLE);
+       }
+}
+
+void
+au8522_set_input(struct au8522 *au, au8522_vinput_t vi, au8522_ainput_t ai)
+{
+       au8522_reset(au);
+
+       if (vi != AU8522_VINPUT_UNCONF)
+               au8522_set_vinput(au, vi);
+       if (ai != AU8522_AINPUT_UNCONF)
+               au8522_set_ainput(au, ai);
+}
+
+int
+au8522_get_signal(struct au8522 *au)
+{
+       uint8_t status;
+
+       if (au8522_read_1(au, AU8522_REG_STATUS, &status))
+               return 0;
+
+#ifdef AU8522_DEBUG
+       printf("au8522: status=0x%02x\n", status);
+#endif
+       return (status & AU8522_STATUS_LOCK) == AU8522_STATUS_LOCK ? 1 : 0;
+}
+
+#ifdef _MODULE
+
+MODULE(MODULE_CLASS_DRIVER, au8522, NULL);
+
+static int
+au8522_modcmd(modcmd_t cmd, void *opaque)
+{
+       switch (cmd) {
+       case MODULE_CMD_INIT:
+               return 0;
+       case MODULE_CMD_FINI:
+               return 0;
+       default:
+               return ENOTTY;
+       }
+}
+
+#endif /* !_MODULE */
diff -r 6f06b556401c -r 7e1f3246d90d sys/dev/i2c/au8522reg.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/au8522reg.h   Mon Dec 27 15:42:11 2010 +0000
@@ -0,0 +1,84 @@
+/* $NetBSD: au8522reg.h,v 1.1 2010/12/27 15:42:11 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2010 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *



Home | Main Index | Thread Index | Old Index