Add subdriver for generic PLL-based TV tuners.

This commit is contained in:
jakllsch 2011-07-11 00:01:51 +00:00
parent 573c9331e5
commit fca353163e
5 changed files with 295 additions and 1 deletions

View File

@ -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 @@ file dev/i2c/au8522.c au8522
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
#

138
sys/dev/i2c/tvpll.c Normal file
View File

@ -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;
}

View File

@ -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
};

View File

@ -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_ */

58
sys/dev/i2c/tvpllvar.h Normal file
View File

@ -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>
#include <sys/types.h>
#include <dev/i2c/i2cvar.h>
#include <dev/dtv/dtvio.h>
struct tvpll_data {
const char * name;
uint32_t min;
uint32_t max;
uint32_t iffreq;
uint8_t *initdata;
uint8_t *sleepdata;
int count;
struct tvpll_entry{
uint32_t limit;
uint32_t stepsize;
uint8_t config;
uint8_t cb;
} *entries;
};
struct tvpll * tvpll_open(device_t, i2c_tag_t, i2c_addr_t, struct tvpll_data *);
void tvpll_close(struct tvpll *);
int tvpll_tune_dtv(struct tvpll *, const struct dvb_frontend_parameters *);
int tvpll_get_status(struct tvpll *);
#endif /* !_DEV_I2C_TVPLLVAR_H_ */