Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/i2c Add subdriver for generic PLL-based TV tuners.



details:   https://anonhg.NetBSD.org/src/rev/e7fa56b391d6
branches:  trunk
changeset: 767194:e7fa56b391d6
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Mon Jul 11 00:01:51 2011 +0000

description:
Add subdriver for generic PLL-based TV tuners.

diffstat:

 sys/dev/i2c/files.i2c      |    7 +-
 sys/dev/i2c/tvpll.c        |  138 +++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/i2c/tvpll_tuners.c |   58 ++++++++++++++++++
 sys/dev/i2c/tvpll_tuners.h |   35 +++++++++++
 sys/dev/i2c/tvpllvar.h     |   58 ++++++++++++++++++
 5 files changed, 295 insertions(+), 1 deletions(-)

diffs (truncated from 326 to 300 lines):

diff -r bfceabe2428a -r e7fa56b391d6 sys/dev/i2c/files.i2c
--- a/sys/dev/i2c/files.i2c     Sun Jul 10 23:50:24 2011 +0000
+++ b/sys/dev/i2c/files.i2c     Mon Jul 11 00:01:51 2011 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.i2c,v 1.34 2011/04/04 17:58:40 phx Exp $
+#      $NetBSD: files.i2c,v 1.35 2011/07/11 00:01:51 jakllsch Exp $
 
 defflag        opt_i2cbus.h                            I2C_SCAN
 define i2cbus { }
@@ -21,6 +21,11 @@
 define xc5k: i2cexec
 file   dev/i2c/xc5k.c                          xc5k
 
+# Generic PLL-based tuners
+define tvpll: i2cexec
+file   dev/i2c/tvpll.c                         tvpll
+file   dev/i2c/tvpll_tuners.c                  tvpll
+
 #
 # I2C master devices
 #
diff -r bfceabe2428a -r e7fa56b391d6 sys/dev/i2c/tvpll.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/tvpll.c       Mon Jul 11 00:01:51 2011 +0000
@@ -0,0 +1,138 @@
+/* $NetBSD: tvpll.c,v 1.1 2011/07/11 00:01:52 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2008, 2011 Jonathan A. Kollasch
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tvpll.c,v 1.1 2011/07/11 00:01:52 jakllsch Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/kmem.h>
+#include <sys/syslog.h>
+
+#include <dev/dtv/dtvio.h>
+#include <dev/i2c/i2cvar.h>
+#include <dev/i2c/tvpllvar.h>
+
+struct tvpll {
+       device_t                parent;
+       i2c_tag_t               tag;
+       i2c_addr_t              addr;
+       const struct tvpll_data *       pll;
+       uint32_t                frequency;
+};
+
+static uint32_t tvpll_algo(struct tvpll *, uint8_t *,
+               const struct dvb_frontend_parameters *, uint32_t *);
+
+struct tvpll *
+tvpll_open(device_t parent, i2c_tag_t t, i2c_addr_t a, struct tvpll_data *p)
+{
+       struct tvpll *tvpll;
+
+       tvpll = kmem_alloc(sizeof(struct tvpll), KM_NOSLEEP);
+        if (tvpll == NULL)
+                return NULL;
+
+       tvpll->tag = t;
+       tvpll->addr = a;
+
+       tvpll->pll = p;
+
+       return tvpll;
+}
+
+void
+tvpll_close(struct tvpll *tvpll)
+{
+       kmem_free(tvpll, sizeof(*tvpll));
+}
+
+static uint32_t
+tvpll_algo(struct tvpll *tvpll, uint8_t *b,
+    const struct dvb_frontend_parameters *p, uint32_t *fr)
+{
+       const struct tvpll_data *pll;
+       uint32_t d;
+       int i;
+       
+       pll = tvpll->pll;
+
+       if(p->frequency != 0 &&
+           (p->frequency < pll->min || p->frequency > pll->max))
+               return 0;
+
+       for(i = 0; i < pll->count; i++) {
+               if (p->frequency > pll->entries[i].limit)
+                       continue;
+               else
+                       break;
+       }
+
+       if ( i >= pll->count)
+               return EINVAL;
+
+       d = (p->frequency + pll->iffreq) / pll->entries[i].stepsize;
+
+       b[0] = (d >> 8) & 0xff;
+       b[1] = (d >> 0) & 0xff;
+       b[2] = pll->entries[i].config;
+       b[3] = pll->entries[i].cb;
+
+       *fr = (d * pll->entries[i].stepsize) - pll->iffreq;
+
+       log(LOG_DEBUG, "pllw %d %02x %02x %02x %02x\n", *fr, b[0], b[1], b[2], b[3]);
+       return 0;
+}
+
+int
+tvpll_tune_dtv(struct tvpll *tvpll,
+    const struct dvb_frontend_parameters *params)
+{
+       int rv;
+       uint32_t fr;
+       uint8_t b[4];
+
+       fr = 0;
+
+       if((rv = tvpll_algo(tvpll, b, params, &fr)) != 0)
+               return rv;
+
+       /* gate ctrl? */
+
+       iic_acquire_bus(tvpll->tag, I2C_F_POLL);
+       rv = iic_exec(tvpll->tag, I2C_OP_WRITE_WITH_STOP, tvpll->addr, b, 4, NULL, 0, I2C_F_POLL);
+       iic_release_bus(tvpll->tag, I2C_F_POLL);
+
+       if (rv != 0)
+               printf("%s\n", __func__);
+
+       tvpll->frequency = fr;
+
+       return rv;
+}
diff -r bfceabe2428a -r e7fa56b391d6 sys/dev/i2c/tvpll_tuners.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/tvpll_tuners.c        Mon Jul 11 00:01:51 2011 +0000
@@ -0,0 +1,58 @@
+/* $NetBSD: tvpll_tuners.c,v 1.1 2011/07/11 00:01:52 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2008, 2011 Jonathan A. Kollasch
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tvpll_tuners.c,v 1.1 2011/07/11 00:01:52 jakllsch Exp $");
+
+#include <sys/param.h>
+#include <dev/i2c/tvpllvar.h>
+#include <dev/i2c/tvpll_tuners.h>
+
+static struct tvpll_entry tuv1236d_pll_entries[] = {  
+       { 157250000, 62500, 0xc6, 0x41 },
+       { 454000000, 62500, 0xc6, 0x42 },
+       { 999999999, 62500, 0xc6, 0x44 },
+};
+struct tvpll_data tvpll_tuv1236d_pll = {
+       "Philips TUV1236D",
+       54000000, 864000000, 44000000,
+       NULL, NULL,
+       __arraycount(tuv1236d_pll_entries), tuv1236d_pll_entries
+};
+
+static struct tvpll_entry tdvs_h06xf_pll_entries[] = {
+       { 160000000, 62500, 0xce, 0x01 },
+        { 450000000, 62500, 0xce, 0x02 },
+       { 999999999, 62500, 0xce, 0x04 },
+};
+struct tvpll_data tvpll_tdvs_h06xf_pll = {
+       "LG TDVS-H06xF",
+       54000000, 863000000, 44000000,
+       NULL, NULL,
+       __arraycount(tdvs_h06xf_pll_entries), tdvs_h06xf_pll_entries
+};
diff -r bfceabe2428a -r e7fa56b391d6 sys/dev/i2c/tvpll_tuners.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/tvpll_tuners.h        Mon Jul 11 00:01:51 2011 +0000
@@ -0,0 +1,35 @@
+/* $NetBSD: tvpll_tuners.h,v 1.1 2011/07/11 00:01:52 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2008 Jonathan A. Kollasch
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#ifndef _DEV_I2C_TVPLL_TUNERS_H_
+#define _DEV_I2C_TVPLL_TUNERS_H_
+
+struct tvpll_data tvpll_tuv1236d_pll;
+struct tvpll_data tvpll_tdvs_h06xf_pll;
+
+#endif /* !_DEV_I2C_TVPLL_TUNERS_H_ */
diff -r bfceabe2428a -r e7fa56b391d6 sys/dev/i2c/tvpllvar.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/i2c/tvpllvar.h    Mon Jul 11 00:01:51 2011 +0000
@@ -0,0 +1,58 @@
+/* $NetBSD: tvpllvar.h,v 1.1 2011/07/11 00:01:52 jakllsch Exp $ */
+
+/*
+ * Copyright (c) 2008 Jonathan A. Kollasch
+ * 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 COPYRIGHT HOLDERS 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 COPYRIGHT HOLDER 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.
+ */
+
+#ifndef _DEV_I2C_TVPLLVAR_H_
+#define _DEV_I2C_TVPLLVAR_H_
+
+#include <sys/param.h>



Home | Main Index | Thread Index | Old Index