2008-12-31 05:27:09 +07:00
|
|
|
/*
|
|
|
|
* driver/media/radio/radio-tea5764.c
|
|
|
|
*
|
|
|
|
* Driver for TEA5764 radio chip for linux 2.6.
|
|
|
|
* This driver is for TEA5764 chip from NXP, used in EZX phones from Motorola.
|
|
|
|
* The I2C protocol is used for communicate with chip.
|
|
|
|
*
|
|
|
|
* Based in radio-tea5761.c Copyright (C) 2005 Nokia Corporation
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Fabio Belavenuto <belavenuto@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
* 2008-12-06 Fabio Belavenuto <belavenuto@gmail.com>
|
|
|
|
* initial code
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* add platform_data support for IRQs platform dependencies
|
|
|
|
* add RDS support
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2008-12-31 05:27:09 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h> /* Initdata */
|
|
|
|
#include <linux/videodev2.h> /* kernel radio structs */
|
|
|
|
#include <linux/i2c.h> /* I2C */
|
|
|
|
#include <media/v4l2-common.h>
|
|
|
|
#include <media/v4l2-ioctl.h>
|
2013-02-03 18:25:32 +07:00
|
|
|
#include <media/v4l2-device.h>
|
2013-02-03 18:34:18 +07:00
|
|
|
#include <media/v4l2-ctrls.h>
|
2013-02-03 18:39:09 +07:00
|
|
|
#include <media/v4l2-event.h>
|
2008-12-31 05:27:09 +07:00
|
|
|
|
2011-06-25 20:15:42 +07:00
|
|
|
#define DRIVER_VERSION "0.0.2"
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
#define DRIVER_AUTHOR "Fabio Belavenuto <belavenuto@gmail.com>"
|
|
|
|
#define DRIVER_DESC "A driver for the TEA5764 radio chip for EZX Phones."
|
|
|
|
|
|
|
|
#define PINFO(format, ...)\
|
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": "\
|
|
|
|
DRIVER_VERSION ": " format "\n", ## __VA_ARGS__)
|
|
|
|
#define PWARN(format, ...)\
|
|
|
|
printk(KERN_WARNING KBUILD_MODNAME ": "\
|
|
|
|
DRIVER_VERSION ": " format "\n", ## __VA_ARGS__)
|
|
|
|
# define PDEBUG(format, ...)\
|
|
|
|
printk(KERN_DEBUG KBUILD_MODNAME ": "\
|
|
|
|
DRIVER_VERSION ": " format "\n", ## __VA_ARGS__)
|
|
|
|
|
|
|
|
/* Frequency limits in MHz -- these are European values. For Japanese
|
|
|
|
devices, that would be 76000 and 91000. */
|
2013-05-31 16:19:04 +07:00
|
|
|
#define FREQ_MIN 87500U
|
|
|
|
#define FREQ_MAX 108000U
|
2008-12-31 05:27:09 +07:00
|
|
|
#define FREQ_MUL 16
|
|
|
|
|
|
|
|
/* TEA5764 registers */
|
|
|
|
#define TEA5764_MANID 0x002b
|
|
|
|
#define TEA5764_CHIPID 0x5764
|
|
|
|
|
|
|
|
#define TEA5764_INTREG_BLMSK 0x0001
|
|
|
|
#define TEA5764_INTREG_FRRMSK 0x0002
|
|
|
|
#define TEA5764_INTREG_LEVMSK 0x0008
|
|
|
|
#define TEA5764_INTREG_IFMSK 0x0010
|
|
|
|
#define TEA5764_INTREG_BLMFLAG 0x0100
|
|
|
|
#define TEA5764_INTREG_FRRFLAG 0x0200
|
|
|
|
#define TEA5764_INTREG_LEVFLAG 0x0800
|
|
|
|
#define TEA5764_INTREG_IFFLAG 0x1000
|
|
|
|
|
|
|
|
#define TEA5764_FRQSET_SUD 0x8000
|
|
|
|
#define TEA5764_FRQSET_SM 0x4000
|
|
|
|
|
|
|
|
#define TEA5764_TNCTRL_PUPD1 0x8000
|
|
|
|
#define TEA5764_TNCTRL_PUPD0 0x4000
|
|
|
|
#define TEA5764_TNCTRL_BLIM 0x2000
|
|
|
|
#define TEA5764_TNCTRL_SWPM 0x1000
|
|
|
|
#define TEA5764_TNCTRL_IFCTC 0x0800
|
|
|
|
#define TEA5764_TNCTRL_AFM 0x0400
|
|
|
|
#define TEA5764_TNCTRL_SMUTE 0x0200
|
|
|
|
#define TEA5764_TNCTRL_SNC 0x0100
|
|
|
|
#define TEA5764_TNCTRL_MU 0x0080
|
|
|
|
#define TEA5764_TNCTRL_SSL1 0x0040
|
|
|
|
#define TEA5764_TNCTRL_SSL0 0x0020
|
|
|
|
#define TEA5764_TNCTRL_HLSI 0x0010
|
|
|
|
#define TEA5764_TNCTRL_MST 0x0008
|
|
|
|
#define TEA5764_TNCTRL_SWP 0x0004
|
|
|
|
#define TEA5764_TNCTRL_DTC 0x0002
|
|
|
|
#define TEA5764_TNCTRL_AHLSI 0x0001
|
|
|
|
|
|
|
|
#define TEA5764_TUNCHK_LEVEL(x) (((x) & 0x00F0) >> 4)
|
|
|
|
#define TEA5764_TUNCHK_IFCNT(x) (((x) & 0xFE00) >> 9)
|
|
|
|
#define TEA5764_TUNCHK_TUNTO 0x0100
|
|
|
|
#define TEA5764_TUNCHK_LD 0x0008
|
|
|
|
#define TEA5764_TUNCHK_STEREO 0x0004
|
|
|
|
|
|
|
|
#define TEA5764_TESTREG_TRIGFR 0x0800
|
|
|
|
|
|
|
|
struct tea5764_regs {
|
|
|
|
u16 intreg; /* INTFLAG & INTMSK */
|
|
|
|
u16 frqset; /* FRQSETMSB & FRQSETLSB */
|
|
|
|
u16 tnctrl; /* TNCTRL1 & TNCTRL2 */
|
|
|
|
u16 frqchk; /* FRQCHKMSB & FRQCHKLSB */
|
|
|
|
u16 tunchk; /* IFCHK & LEVCHK */
|
|
|
|
u16 testreg; /* TESTBITS & TESTMODE */
|
|
|
|
u16 rdsstat; /* RDSSTAT1 & RDSSTAT2 */
|
|
|
|
u16 rdslb; /* RDSLBMSB & RDSLBLSB */
|
|
|
|
u16 rdspb; /* RDSPBMSB & RDSPBLSB */
|
|
|
|
u16 rdsbc; /* RDSBBC & RDSGBC */
|
|
|
|
u16 rdsctrl; /* RDSCTRL1 & RDSCTRL2 */
|
|
|
|
u16 rdsbbl; /* PAUSEDET & RDSBBL */
|
|
|
|
u16 manid; /* MANID1 & MANID2 */
|
|
|
|
u16 chipid; /* CHIPID1 & CHIPID2 */
|
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
|
|
|
struct tea5764_write_regs {
|
|
|
|
u8 intreg; /* INTMSK */
|
2014-08-21 02:40:00 +07:00
|
|
|
__be16 frqset; /* FRQSETMSB & FRQSETLSB */
|
|
|
|
__be16 tnctrl; /* TNCTRL1 & TNCTRL2 */
|
|
|
|
__be16 testreg; /* TESTBITS & TESTMODE */
|
|
|
|
__be16 rdsctrl; /* RDSCTRL1 & RDSCTRL2 */
|
|
|
|
__be16 rdsbbl; /* PAUSEDET & RDSBBL */
|
2008-12-31 05:27:09 +07:00
|
|
|
} __attribute__ ((packed));
|
|
|
|
|
2011-10-13 03:51:22 +07:00
|
|
|
#ifdef CONFIG_RADIO_TEA5764_XTAL
|
2008-12-31 05:27:09 +07:00
|
|
|
#define RADIO_TEA5764_XTAL 1
|
2011-10-13 03:51:22 +07:00
|
|
|
#else
|
|
|
|
#define RADIO_TEA5764_XTAL 0
|
2008-12-31 05:27:09 +07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
static int radio_nr = -1;
|
|
|
|
static int use_xtal = RADIO_TEA5764_XTAL;
|
|
|
|
|
|
|
|
struct tea5764_device {
|
2013-02-03 18:34:18 +07:00
|
|
|
struct v4l2_device v4l2_dev;
|
|
|
|
struct v4l2_ctrl_handler ctrl_handler;
|
2008-12-31 05:27:09 +07:00
|
|
|
struct i2c_client *i2c_client;
|
2013-02-03 18:27:57 +07:00
|
|
|
struct video_device vdev;
|
2008-12-31 05:27:09 +07:00
|
|
|
struct tea5764_regs regs;
|
|
|
|
struct mutex mutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* I2C code related */
|
2012-10-28 03:35:46 +07:00
|
|
|
static int tea5764_i2c_read(struct tea5764_device *radio)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
u16 *p = (u16 *) &radio->regs;
|
|
|
|
|
|
|
|
struct i2c_msg msgs[1] = {
|
2012-09-18 18:22:33 +07:00
|
|
|
{ .addr = radio->i2c_client->addr,
|
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.len = sizeof(radio->regs),
|
|
|
|
.buf = (void *)&radio->regs
|
|
|
|
},
|
2008-12-31 05:27:09 +07:00
|
|
|
};
|
|
|
|
if (i2c_transfer(radio->i2c_client->adapter, msgs, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
for (i = 0; i < sizeof(struct tea5764_regs) / sizeof(u16); i++)
|
2014-08-21 02:40:00 +07:00
|
|
|
p[i] = __be16_to_cpu((__force __be16)p[i]);
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-28 03:35:46 +07:00
|
|
|
static int tea5764_i2c_write(struct tea5764_device *radio)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
|
|
|
struct tea5764_write_regs wr;
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
struct i2c_msg msgs[1] = {
|
2012-09-18 18:22:33 +07:00
|
|
|
{
|
|
|
|
.addr = radio->i2c_client->addr,
|
|
|
|
.len = sizeof(wr),
|
|
|
|
.buf = (void *)&wr
|
|
|
|
},
|
2008-12-31 05:27:09 +07:00
|
|
|
};
|
|
|
|
wr.intreg = r->intreg & 0xff;
|
|
|
|
wr.frqset = __cpu_to_be16(r->frqset);
|
|
|
|
wr.tnctrl = __cpu_to_be16(r->tnctrl);
|
|
|
|
wr.testreg = __cpu_to_be16(r->testreg);
|
|
|
|
wr.rdsctrl = __cpu_to_be16(r->rdsctrl);
|
|
|
|
wr.rdsbbl = __cpu_to_be16(r->rdsbbl);
|
|
|
|
if (i2c_transfer(radio->i2c_client->adapter, msgs, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tea5764_power_up(struct tea5764_device *radio)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
|
|
|
if (!(r->tnctrl & TEA5764_TNCTRL_PUPD0)) {
|
|
|
|
r->tnctrl &= ~(TEA5764_TNCTRL_AFM | TEA5764_TNCTRL_MU |
|
|
|
|
TEA5764_TNCTRL_HLSI);
|
|
|
|
if (!use_xtal)
|
|
|
|
r->testreg |= TEA5764_TESTREG_TRIGFR;
|
|
|
|
else
|
|
|
|
r->testreg &= ~TEA5764_TESTREG_TRIGFR;
|
|
|
|
|
|
|
|
r->tnctrl |= TEA5764_TNCTRL_PUPD0;
|
|
|
|
tea5764_i2c_write(radio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tea5764_power_down(struct tea5764_device *radio)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
|
|
|
if (r->tnctrl & TEA5764_TNCTRL_PUPD0) {
|
|
|
|
r->tnctrl &= ~TEA5764_TNCTRL_PUPD0;
|
|
|
|
tea5764_i2c_write(radio);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tea5764_set_freq(struct tea5764_device *radio, int freq)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
|
|
|
/* formula: (freq [+ or -] 225000) / 8192 */
|
|
|
|
if (r->tnctrl & TEA5764_TNCTRL_HLSI)
|
|
|
|
r->frqset = (freq + 225000) / 8192;
|
|
|
|
else
|
|
|
|
r->frqset = (freq - 225000) / 8192;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tea5764_get_freq(struct tea5764_device *radio)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
|
|
|
if (r->tnctrl & TEA5764_TNCTRL_HLSI)
|
|
|
|
return (r->frqchk * 8192) - 225000;
|
|
|
|
else
|
|
|
|
return (r->frqchk * 8192) + 225000;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* tune an frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
|
|
|
|
static void tea5764_tune(struct tea5764_device *radio, int freq)
|
|
|
|
{
|
|
|
|
tea5764_set_freq(radio, freq);
|
|
|
|
if (tea5764_i2c_write(radio))
|
|
|
|
PWARN("Could not set frequency!");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tea5764_set_audout_mode(struct tea5764_device *radio, int audmode)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
int tnctrl = r->tnctrl;
|
|
|
|
|
|
|
|
if (audmode == V4L2_TUNER_MODE_MONO)
|
|
|
|
r->tnctrl |= TEA5764_TNCTRL_MST;
|
|
|
|
else
|
|
|
|
r->tnctrl &= ~TEA5764_TNCTRL_MST;
|
|
|
|
if (tnctrl != r->tnctrl)
|
|
|
|
tea5764_i2c_write(radio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tea5764_get_audout_mode(struct tea5764_device *radio)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
|
|
|
if (r->tnctrl & TEA5764_TNCTRL_MST)
|
|
|
|
return V4L2_TUNER_MODE_MONO;
|
|
|
|
else
|
|
|
|
return V4L2_TUNER_MODE_STEREO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tea5764_mute(struct tea5764_device *radio, int on)
|
|
|
|
{
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
int tnctrl = r->tnctrl;
|
|
|
|
|
|
|
|
if (on)
|
|
|
|
r->tnctrl |= TEA5764_TNCTRL_MU;
|
|
|
|
else
|
|
|
|
r->tnctrl &= ~TEA5764_TNCTRL_MU;
|
|
|
|
if (tnctrl != r->tnctrl)
|
|
|
|
tea5764_i2c_write(radio);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* V4L2 vidioc */
|
|
|
|
static int vidioc_querycap(struct file *file, void *priv,
|
|
|
|
struct v4l2_capability *v)
|
|
|
|
{
|
|
|
|
struct tea5764_device *radio = video_drvdata(file);
|
2013-02-03 18:27:57 +07:00
|
|
|
struct video_device *dev = &radio->vdev;
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
strlcpy(v->driver, dev->dev.driver->name, sizeof(v->driver));
|
|
|
|
strlcpy(v->card, dev->name, sizeof(v->card));
|
2009-03-25 06:38:22 +07:00
|
|
|
snprintf(v->bus_info, sizeof(v->bus_info),
|
|
|
|
"I2C:%s", dev_name(&dev->dev));
|
2013-02-03 18:36:42 +07:00
|
|
|
v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
|
|
|
|
v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
|
2008-12-31 05:27:09 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_g_tuner(struct file *file, void *priv,
|
|
|
|
struct v4l2_tuner *v)
|
|
|
|
{
|
|
|
|
struct tea5764_device *radio = video_drvdata(file);
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
|
|
|
if (v->index > 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2013-05-31 16:19:04 +07:00
|
|
|
strlcpy(v->name, "FM", sizeof(v->name));
|
2008-12-31 05:27:09 +07:00
|
|
|
v->type = V4L2_TUNER_RADIO;
|
|
|
|
tea5764_i2c_read(radio);
|
|
|
|
v->rangelow = FREQ_MIN * FREQ_MUL;
|
|
|
|
v->rangehigh = FREQ_MAX * FREQ_MUL;
|
|
|
|
v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
|
|
|
|
if (r->tunchk & TEA5764_TUNCHK_STEREO)
|
2009-06-20 16:29:12 +07:00
|
|
|
v->rxsubchans = V4L2_TUNER_SUB_STEREO;
|
|
|
|
else
|
|
|
|
v->rxsubchans = V4L2_TUNER_SUB_MONO;
|
2008-12-31 05:27:09 +07:00
|
|
|
v->audmode = tea5764_get_audout_mode(radio);
|
|
|
|
v->signal = TEA5764_TUNCHK_LEVEL(r->tunchk) * 0xffff / 0xf;
|
|
|
|
v->afc = TEA5764_TUNCHK_IFCNT(r->tunchk);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_s_tuner(struct file *file, void *priv,
|
2013-03-15 16:10:06 +07:00
|
|
|
const struct v4l2_tuner *v)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
|
|
|
struct tea5764_device *radio = video_drvdata(file);
|
|
|
|
|
|
|
|
if (v->index > 0)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
tea5764_set_audout_mode(radio, v->audmode);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_s_frequency(struct file *file, void *priv,
|
2013-03-19 14:09:26 +07:00
|
|
|
const struct v4l2_frequency *f)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
|
|
|
struct tea5764_device *radio = video_drvdata(file);
|
2013-05-31 16:19:04 +07:00
|
|
|
unsigned freq = f->frequency;
|
2008-12-31 05:27:09 +07:00
|
|
|
|
2009-11-27 14:33:25 +07:00
|
|
|
if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
|
2008-12-31 05:27:09 +07:00
|
|
|
return -EINVAL;
|
2013-05-31 16:19:04 +07:00
|
|
|
if (freq == 0) {
|
2008-12-31 05:27:09 +07:00
|
|
|
/* We special case this as a power down control. */
|
|
|
|
tea5764_power_down(radio);
|
2013-05-31 16:19:04 +07:00
|
|
|
/* Yes, that's what is returned in this case. This
|
|
|
|
whole special case is non-compliant and should really
|
|
|
|
be replaced with something better, but changing this
|
|
|
|
might well break code that depends on this behavior.
|
|
|
|
So we keep it as-is. */
|
2008-12-31 05:27:09 +07:00
|
|
|
return -EINVAL;
|
2013-05-31 16:19:04 +07:00
|
|
|
}
|
2013-11-04 16:28:57 +07:00
|
|
|
freq = clamp(freq, FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL);
|
2008-12-31 05:27:09 +07:00
|
|
|
tea5764_power_up(radio);
|
2013-05-31 16:19:04 +07:00
|
|
|
tea5764_tune(radio, (freq * 125) / 2);
|
2008-12-31 05:27:09 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vidioc_g_frequency(struct file *file, void *priv,
|
|
|
|
struct v4l2_frequency *f)
|
|
|
|
{
|
|
|
|
struct tea5764_device *radio = video_drvdata(file);
|
|
|
|
struct tea5764_regs *r = &radio->regs;
|
|
|
|
|
2009-11-27 14:33:25 +07:00
|
|
|
if (f->tuner != 0)
|
|
|
|
return -EINVAL;
|
2008-12-31 05:27:09 +07:00
|
|
|
tea5764_i2c_read(radio);
|
|
|
|
f->type = V4L2_TUNER_RADIO;
|
|
|
|
if (r->tnctrl & TEA5764_TNCTRL_PUPD0)
|
|
|
|
f->frequency = (tea5764_get_freq(radio) * 2) / 125;
|
|
|
|
else
|
|
|
|
f->frequency = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-02-03 18:34:18 +07:00
|
|
|
static int tea5764_s_ctrl(struct v4l2_ctrl *ctrl)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
2013-02-03 18:34:18 +07:00
|
|
|
struct tea5764_device *radio =
|
|
|
|
container_of(ctrl->handler, struct tea5764_device, ctrl_handler);
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
switch (ctrl->id) {
|
|
|
|
case V4L2_CID_AUDIO_MUTE:
|
2013-02-03 18:34:18 +07:00
|
|
|
tea5764_mute(radio, ctrl->val);
|
2008-12-31 05:27:09 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-02-03 18:34:18 +07:00
|
|
|
static const struct v4l2_ctrl_ops tea5764_ctrl_ops = {
|
|
|
|
.s_ctrl = tea5764_s_ctrl,
|
|
|
|
};
|
|
|
|
|
2008-12-31 05:27:09 +07:00
|
|
|
/* File system interface */
|
|
|
|
static const struct v4l2_file_operations tea5764_fops = {
|
|
|
|
.owner = THIS_MODULE,
|
2013-02-03 18:39:09 +07:00
|
|
|
.open = v4l2_fh_open,
|
|
|
|
.release = v4l2_fh_release,
|
|
|
|
.poll = v4l2_ctrl_poll,
|
2010-11-14 19:46:23 +07:00
|
|
|
.unlocked_ioctl = video_ioctl2,
|
2008-12-31 05:27:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct v4l2_ioctl_ops tea5764_ioctl_ops = {
|
|
|
|
.vidioc_querycap = vidioc_querycap,
|
|
|
|
.vidioc_g_tuner = vidioc_g_tuner,
|
|
|
|
.vidioc_s_tuner = vidioc_s_tuner,
|
|
|
|
.vidioc_g_frequency = vidioc_g_frequency,
|
|
|
|
.vidioc_s_frequency = vidioc_s_frequency,
|
2013-02-03 18:39:09 +07:00
|
|
|
.vidioc_log_status = v4l2_ctrl_log_status,
|
|
|
|
.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
|
|
|
|
.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
|
2008-12-31 05:27:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* V4L2 interface */
|
2017-08-26 15:43:43 +07:00
|
|
|
static const struct video_device tea5764_radio_template = {
|
2008-12-31 05:27:09 +07:00
|
|
|
.name = "TEA5764 FM-Radio",
|
|
|
|
.fops = &tea5764_fops,
|
|
|
|
.ioctl_ops = &tea5764_ioctl_ops,
|
2013-02-03 18:27:57 +07:00
|
|
|
.release = video_device_release_empty,
|
2008-12-31 05:27:09 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* I2C probe: check if the device exists and register with v4l if it is */
|
2012-12-22 04:17:53 +07:00
|
|
|
static int tea5764_i2c_probe(struct i2c_client *client,
|
|
|
|
const struct i2c_device_id *id)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
|
|
|
struct tea5764_device *radio;
|
2013-02-03 18:25:32 +07:00
|
|
|
struct v4l2_device *v4l2_dev;
|
2013-02-03 18:34:18 +07:00
|
|
|
struct v4l2_ctrl_handler *hdl;
|
2008-12-31 05:27:09 +07:00
|
|
|
struct tea5764_regs *r;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
PDEBUG("probe");
|
2010-11-14 19:46:23 +07:00
|
|
|
radio = kzalloc(sizeof(struct tea5764_device), GFP_KERNEL);
|
2008-12-31 05:27:09 +07:00
|
|
|
if (!radio)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-02-03 18:25:32 +07:00
|
|
|
v4l2_dev = &radio->v4l2_dev;
|
|
|
|
ret = v4l2_device_register(&client->dev, v4l2_dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
v4l2_err(v4l2_dev, "could not register v4l2_device\n");
|
|
|
|
goto errfr;
|
|
|
|
}
|
2013-02-03 18:34:18 +07:00
|
|
|
|
|
|
|
hdl = &radio->ctrl_handler;
|
|
|
|
v4l2_ctrl_handler_init(hdl, 1);
|
|
|
|
v4l2_ctrl_new_std(hdl, &tea5764_ctrl_ops,
|
|
|
|
V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
|
|
|
|
v4l2_dev->ctrl_handler = hdl;
|
|
|
|
if (hdl->error) {
|
|
|
|
ret = hdl->error;
|
|
|
|
v4l2_err(v4l2_dev, "Could not register controls\n");
|
|
|
|
goto errunreg;
|
|
|
|
}
|
|
|
|
|
2008-12-31 05:27:09 +07:00
|
|
|
mutex_init(&radio->mutex);
|
|
|
|
radio->i2c_client = client;
|
|
|
|
ret = tea5764_i2c_read(radio);
|
|
|
|
if (ret)
|
2013-02-03 18:25:32 +07:00
|
|
|
goto errunreg;
|
2008-12-31 05:27:09 +07:00
|
|
|
r = &radio->regs;
|
|
|
|
PDEBUG("chipid = %04X, manid = %04X", r->chipid, r->manid);
|
|
|
|
if (r->chipid != TEA5764_CHIPID ||
|
|
|
|
(r->manid & 0x0fff) != TEA5764_MANID) {
|
|
|
|
PWARN("This chip is not a TEA5764!");
|
|
|
|
ret = -EINVAL;
|
2013-02-03 18:25:32 +07:00
|
|
|
goto errunreg;
|
2008-12-31 05:27:09 +07:00
|
|
|
}
|
|
|
|
|
2013-02-03 18:27:57 +07:00
|
|
|
radio->vdev = tea5764_radio_template;
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
i2c_set_clientdata(client, radio);
|
2013-02-03 18:27:57 +07:00
|
|
|
video_set_drvdata(&radio->vdev, radio);
|
|
|
|
radio->vdev.lock = &radio->mutex;
|
|
|
|
radio->vdev.v4l2_dev = v4l2_dev;
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
/* initialize and power off the chip */
|
|
|
|
tea5764_i2c_read(radio);
|
|
|
|
tea5764_set_audout_mode(radio, V4L2_TUNER_MODE_STEREO);
|
|
|
|
tea5764_mute(radio, 1);
|
|
|
|
tea5764_power_down(radio);
|
|
|
|
|
2013-02-03 18:27:57 +07:00
|
|
|
ret = video_register_device(&radio->vdev, VFL_TYPE_RADIO, radio_nr);
|
2010-11-14 19:46:23 +07:00
|
|
|
if (ret < 0) {
|
|
|
|
PWARN("Could not register video device!");
|
2013-02-03 18:27:57 +07:00
|
|
|
goto errunreg;
|
2010-11-14 19:46:23 +07:00
|
|
|
}
|
|
|
|
|
2008-12-31 05:27:09 +07:00
|
|
|
PINFO("registered.");
|
|
|
|
return 0;
|
2013-02-03 18:25:32 +07:00
|
|
|
errunreg:
|
2013-02-03 18:34:18 +07:00
|
|
|
v4l2_ctrl_handler_free(hdl);
|
2013-02-03 18:25:32 +07:00
|
|
|
v4l2_device_unregister(v4l2_dev);
|
2008-12-31 05:27:09 +07:00
|
|
|
errfr:
|
|
|
|
kfree(radio);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-22 04:17:53 +07:00
|
|
|
static int tea5764_i2c_remove(struct i2c_client *client)
|
2008-12-31 05:27:09 +07:00
|
|
|
{
|
|
|
|
struct tea5764_device *radio = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
PDEBUG("remove");
|
|
|
|
if (radio) {
|
|
|
|
tea5764_power_down(radio);
|
2013-02-03 18:27:57 +07:00
|
|
|
video_unregister_device(&radio->vdev);
|
2013-02-03 18:34:18 +07:00
|
|
|
v4l2_ctrl_handler_free(&radio->ctrl_handler);
|
2013-02-03 18:25:32 +07:00
|
|
|
v4l2_device_unregister(&radio->v4l2_dev);
|
2008-12-31 05:27:09 +07:00
|
|
|
kfree(radio);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* I2C subsystem interface */
|
|
|
|
static const struct i2c_device_id tea5764_id[] = {
|
|
|
|
{ "radio-tea5764", 0 },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, tea5764_id);
|
|
|
|
|
|
|
|
static struct i2c_driver tea5764_i2c_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "radio-tea5764",
|
|
|
|
},
|
|
|
|
.probe = tea5764_i2c_probe,
|
2012-12-22 04:17:53 +07:00
|
|
|
.remove = tea5764_i2c_remove,
|
2008-12-31 05:27:09 +07:00
|
|
|
.id_table = tea5764_id,
|
|
|
|
};
|
|
|
|
|
2012-02-12 16:56:32 +07:00
|
|
|
module_i2c_driver(tea5764_i2c_driver);
|
2008-12-31 05:27:09 +07:00
|
|
|
|
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_LICENSE("GPL");
|
2011-06-25 20:15:42 +07:00
|
|
|
MODULE_VERSION(DRIVER_VERSION);
|
2008-12-31 05:27:09 +07:00
|
|
|
|
2011-07-08 16:00:37 +07:00
|
|
|
module_param(use_xtal, int, 0);
|
2008-12-31 05:27:09 +07:00
|
|
|
MODULE_PARM_DESC(use_xtal, "Chip have a xtal connected in board");
|
|
|
|
module_param(radio_nr, int, 0);
|
|
|
|
MODULE_PARM_DESC(radio_nr, "video4linux device number to use");
|