2019-05-27 06:55:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-08-09 17:23:35 +00:00
|
|
|
/*
|
|
|
|
* drivers/media/radio/si470x/radio-si470x-i2c.c
|
|
|
|
*
|
|
|
|
* I2C driver for radios with Silicon Labs Si470x FM Radio Receivers
|
|
|
|
*
|
2009-08-10 21:44:14 +00:00
|
|
|
* Copyright (c) 2009 Samsung Electronics Co.Ltd
|
2009-08-09 17:23:35 +00:00
|
|
|
* Author: Joonyoung Shim <jy0922.shim@samsung.com>
|
2009-08-10 21:44:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* driver definitions */
|
|
|
|
#define DRIVER_AUTHOR "Joonyoung Shim <jy0922.shim@samsung.com>";
|
2021-08-03 19:46:09 +00:00
|
|
|
#define DRIVER_CARD "Silicon Labs Si470x FM Radio"
|
2009-08-10 21:44:14 +00:00
|
|
|
#define DRIVER_DESC "I2C radio driver for Si470x FM Radio Receivers"
|
2011-06-25 13:15:42 +00:00
|
|
|
#define DRIVER_VERSION "1.0.2"
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
/* kernel includes */
|
2009-08-09 17:23:35 +00:00
|
|
|
#include <linux/i2c.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 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-08-09 17:23:35 +00:00
|
|
|
#include <linux/delay.h>
|
2018-12-07 13:58:11 +00:00
|
|
|
#include <linux/gpio/consumer.h>
|
2009-12-10 19:50:34 +00:00
|
|
|
#include <linux/interrupt.h>
|
2009-08-09 17:23:35 +00:00
|
|
|
|
|
|
|
#include "radio-si470x.h"
|
|
|
|
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/* I2C Device ID List */
|
|
|
|
static const struct i2c_device_id si470x_i2c_id[] = {
|
|
|
|
/* Generic Entry */
|
|
|
|
{ "si470x", 0 },
|
|
|
|
/* Terminating entry */
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, si470x_i2c_id);
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Module Parameters
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Radio Nr */
|
|
|
|
static int radio_nr = -1;
|
|
|
|
module_param(radio_nr, int, 0444);
|
|
|
|
MODULE_PARM_DESC(radio_nr, "Radio Nr");
|
|
|
|
|
2009-12-10 19:50:34 +00:00
|
|
|
/* RDS buffer blocks */
|
|
|
|
static unsigned int rds_buf = 100;
|
|
|
|
module_param(rds_buf, uint, 0444);
|
|
|
|
MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
|
|
|
|
|
|
|
|
/* RDS maximum block errors */
|
|
|
|
static unsigned short max_rds_errors = 1;
|
|
|
|
/* 0 means 0 errors requiring correction */
|
|
|
|
/* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
|
|
|
|
/* 2 means 3-5 errors requiring correction */
|
|
|
|
/* 3 means 6+ errors or errors in checkword, correction not possible */
|
|
|
|
module_param(max_rds_errors, ushort, 0644);
|
|
|
|
MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* I2C Definitions
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/* Write starts with the upper byte of register 0x02 */
|
|
|
|
#define WRITE_REG_NUM 8
|
|
|
|
#define WRITE_INDEX(i) (i + 0x02)
|
|
|
|
|
|
|
|
/* Read starts with the upper byte of register 0x0a */
|
2009-08-09 17:23:35 +00:00
|
|
|
#define READ_REG_NUM RADIO_REGISTER_NUM
|
|
|
|
#define READ_INDEX(i) ((i + RADIO_REGISTER_NUM - 0x0a) % READ_REG_NUM)
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/**************************************************************************
|
|
|
|
* General Driver Functions - REGISTERs
|
|
|
|
**************************************************************************/
|
2009-08-09 17:23:35 +00:00
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/*
|
|
|
|
* si470x_get_register - read register
|
|
|
|
*/
|
2018-04-05 19:08:12 +00:00
|
|
|
static int si470x_get_register(struct si470x_device *radio, int regnr)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
2018-04-06 11:54:51 +00:00
|
|
|
__be16 buf[READ_REG_NUM];
|
2009-08-09 17:23:35 +00:00
|
|
|
struct i2c_msg msgs[1] = {
|
2012-09-18 11:22:36 +00:00
|
|
|
{
|
|
|
|
.addr = radio->client->addr,
|
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.len = sizeof(u16) * READ_REG_NUM,
|
|
|
|
.buf = (void *)buf
|
|
|
|
},
|
2009-08-09 17:23:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
radio->registers[regnr] = __be16_to_cpu(buf[READ_INDEX(regnr)]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/*
|
|
|
|
* si470x_set_register - write register
|
|
|
|
*/
|
2018-04-05 19:08:12 +00:00
|
|
|
static int si470x_set_register(struct si470x_device *radio, int regnr)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
|
|
|
int i;
|
2018-04-06 11:54:51 +00:00
|
|
|
__be16 buf[WRITE_REG_NUM];
|
2009-08-09 17:23:35 +00:00
|
|
|
struct i2c_msg msgs[1] = {
|
2012-09-18 11:22:36 +00:00
|
|
|
{
|
|
|
|
.addr = radio->client->addr,
|
|
|
|
.len = sizeof(u16) * WRITE_REG_NUM,
|
|
|
|
.buf = (void *)buf
|
|
|
|
},
|
2009-08-09 17:23:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < WRITE_REG_NUM; i++)
|
|
|
|
buf[i] = __cpu_to_be16(radio->registers[WRITE_INDEX(i)]);
|
|
|
|
|
|
|
|
if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* General Driver Functions - ENTIRE REGISTERS
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* si470x_get_all_registers - read entire registers
|
|
|
|
*/
|
|
|
|
static int si470x_get_all_registers(struct si470x_device *radio)
|
|
|
|
{
|
|
|
|
int i;
|
2018-04-06 11:54:51 +00:00
|
|
|
__be16 buf[READ_REG_NUM];
|
2009-08-10 21:44:14 +00:00
|
|
|
struct i2c_msg msgs[1] = {
|
2012-09-18 11:22:36 +00:00
|
|
|
{
|
|
|
|
.addr = radio->client->addr,
|
|
|
|
.flags = I2C_M_RD,
|
|
|
|
.len = sizeof(u16) * READ_REG_NUM,
|
|
|
|
.buf = (void *)buf
|
|
|
|
},
|
2009-08-10 21:44:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (i2c_transfer(radio->client->adapter, msgs, 1) != 1)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
for (i = 0; i < READ_REG_NUM; i++)
|
|
|
|
radio->registers[i] = __be16_to_cpu(buf[READ_INDEX(i)]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* File Operations Interface
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* si470x_fops_open - file open
|
|
|
|
*/
|
2018-04-05 19:08:12 +00:00
|
|
|
static int si470x_fops_open(struct file *file)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
|
|
|
struct si470x_device *radio = video_drvdata(file);
|
2012-05-04 12:16:57 +00:00
|
|
|
int retval = v4l2_fh_open(file);
|
2009-08-09 17:23:35 +00:00
|
|
|
|
2012-05-04 12:16:57 +00:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
2009-08-09 17:23:35 +00:00
|
|
|
|
2012-05-04 12:16:57 +00:00
|
|
|
if (v4l2_fh_is_singular_file(file)) {
|
2009-08-09 17:23:35 +00:00
|
|
|
/* start radio */
|
|
|
|
retval = si470x_start(radio);
|
2009-12-10 19:50:34 +00:00
|
|
|
if (retval < 0)
|
|
|
|
goto done;
|
|
|
|
|
2011-03-11 06:54:46 +00:00
|
|
|
/* enable RDS / STC interrupt */
|
2009-12-10 19:50:34 +00:00
|
|
|
radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDSIEN;
|
2011-03-11 06:54:46 +00:00
|
|
|
radio->registers[SYSCONFIG1] |= SYSCONFIG1_STCIEN;
|
2009-12-10 19:50:34 +00:00
|
|
|
radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_GPIO2;
|
|
|
|
radio->registers[SYSCONFIG1] |= 0x1 << 2;
|
|
|
|
retval = si470x_set_register(radio, SYSCONFIG1);
|
|
|
|
}
|
2009-08-10 21:44:14 +00:00
|
|
|
|
2009-12-10 19:50:34 +00:00
|
|
|
done:
|
2012-05-04 12:16:57 +00:00
|
|
|
if (retval)
|
|
|
|
v4l2_fh_release(file);
|
2009-08-09 17:23:35 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* si470x_fops_release - file release
|
|
|
|
*/
|
2018-04-05 19:08:12 +00:00
|
|
|
static int si470x_fops_release(struct file *file)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
|
|
|
struct si470x_device *radio = video_drvdata(file);
|
|
|
|
|
2012-05-04 12:16:57 +00:00
|
|
|
if (v4l2_fh_is_singular_file(file))
|
2009-08-09 17:23:35 +00:00
|
|
|
/* stop radio */
|
2012-05-04 12:16:57 +00:00
|
|
|
si470x_stop(radio);
|
2009-08-10 21:44:14 +00:00
|
|
|
|
2012-05-04 12:16:57 +00:00
|
|
|
return v4l2_fh_release(file);
|
2009-08-09 17:23:35 +00:00
|
|
|
}
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* Video4Linux Interface
|
|
|
|
**************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* si470x_vidioc_querycap - query device capabilities
|
|
|
|
*/
|
2018-04-05 19:08:12 +00:00
|
|
|
static int si470x_vidioc_querycap(struct file *file, void *priv,
|
|
|
|
struct v4l2_capability *capability)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
2018-09-10 12:19:14 +00:00
|
|
|
strscpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
|
|
|
|
strscpy(capability->card, DRIVER_CARD, sizeof(capability->card));
|
2009-08-09 17:23:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* I2C Interface
|
|
|
|
**************************************************************************/
|
|
|
|
|
2009-12-10 19:50:34 +00:00
|
|
|
/*
|
2011-03-11 06:54:48 +00:00
|
|
|
* si470x_i2c_interrupt - interrupt handler
|
2009-12-10 19:50:34 +00:00
|
|
|
*/
|
2011-03-11 06:54:48 +00:00
|
|
|
static irqreturn_t si470x_i2c_interrupt(int irq, void *dev_id)
|
2009-12-10 19:50:34 +00:00
|
|
|
{
|
2011-03-11 06:54:48 +00:00
|
|
|
struct si470x_device *radio = dev_id;
|
2009-12-10 19:50:34 +00:00
|
|
|
unsigned char regnr;
|
|
|
|
unsigned char blocknum;
|
|
|
|
unsigned short bler; /* rds block errors */
|
|
|
|
unsigned short rds;
|
|
|
|
unsigned char tmpbuf[3];
|
|
|
|
int retval = 0;
|
|
|
|
|
2011-03-11 06:54:46 +00:00
|
|
|
/* check Seek/Tune Complete */
|
|
|
|
retval = si470x_get_register(radio, STATUSRSSI);
|
|
|
|
if (retval < 0)
|
2011-03-11 06:54:48 +00:00
|
|
|
goto end;
|
2011-03-11 06:54:46 +00:00
|
|
|
|
|
|
|
if (radio->registers[STATUSRSSI] & STATUSRSSI_STC)
|
|
|
|
complete(&radio->completion);
|
|
|
|
|
2009-12-10 19:50:34 +00:00
|
|
|
/* safety checks */
|
|
|
|
if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
|
2011-03-11 06:54:48 +00:00
|
|
|
goto end;
|
2009-12-10 19:50:34 +00:00
|
|
|
|
|
|
|
/* Update RDS registers */
|
2011-03-11 06:54:46 +00:00
|
|
|
for (regnr = 1; regnr < RDS_REGISTER_NUM; regnr++) {
|
2009-12-10 19:50:34 +00:00
|
|
|
retval = si470x_get_register(radio, STATUSRSSI + regnr);
|
|
|
|
if (retval < 0)
|
2011-03-11 06:54:48 +00:00
|
|
|
goto end;
|
2009-12-10 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* get rds blocks */
|
|
|
|
if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0)
|
|
|
|
/* No RDS group ready, better luck next time */
|
2011-03-11 06:54:48 +00:00
|
|
|
goto end;
|
2009-12-10 19:50:34 +00:00
|
|
|
|
|
|
|
for (blocknum = 0; blocknum < 4; blocknum++) {
|
|
|
|
switch (blocknum) {
|
|
|
|
default:
|
|
|
|
bler = (radio->registers[STATUSRSSI] &
|
|
|
|
STATUSRSSI_BLERA) >> 9;
|
|
|
|
rds = radio->registers[RDSA];
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
bler = (radio->registers[READCHAN] &
|
|
|
|
READCHAN_BLERB) >> 14;
|
|
|
|
rds = radio->registers[RDSB];
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
bler = (radio->registers[READCHAN] &
|
|
|
|
READCHAN_BLERC) >> 12;
|
|
|
|
rds = radio->registers[RDSC];
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
bler = (radio->registers[READCHAN] &
|
|
|
|
READCHAN_BLERD) >> 10;
|
|
|
|
rds = radio->registers[RDSD];
|
|
|
|
break;
|
2012-09-28 08:37:22 +00:00
|
|
|
}
|
2009-12-10 19:50:34 +00:00
|
|
|
|
|
|
|
/* Fill the V4L2 RDS buffer */
|
|
|
|
put_unaligned_le16(rds, &tmpbuf);
|
|
|
|
tmpbuf[2] = blocknum; /* offset name */
|
|
|
|
tmpbuf[2] |= blocknum << 3; /* received offset */
|
|
|
|
if (bler > max_rds_errors)
|
|
|
|
tmpbuf[2] |= 0x80; /* uncorrectable errors */
|
|
|
|
else if (bler > 0)
|
|
|
|
tmpbuf[2] |= 0x40; /* corrected error(s) */
|
|
|
|
|
|
|
|
/* copy RDS block to internal buffer */
|
|
|
|
memcpy(&radio->buffer[radio->wr_index], &tmpbuf, 3);
|
|
|
|
radio->wr_index += 3;
|
|
|
|
|
|
|
|
/* wrap write pointer */
|
|
|
|
if (radio->wr_index >= radio->buf_size)
|
|
|
|
radio->wr_index = 0;
|
|
|
|
|
|
|
|
/* check for overflow */
|
|
|
|
if (radio->wr_index == radio->rd_index) {
|
|
|
|
/* increment and wrap read pointer */
|
|
|
|
radio->rd_index += 3;
|
|
|
|
if (radio->rd_index >= radio->buf_size)
|
|
|
|
radio->rd_index = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radio->wr_index != radio->rd_index)
|
|
|
|
wake_up_interruptible(&radio->read_queue);
|
|
|
|
|
2011-03-11 06:54:48 +00:00
|
|
|
end:
|
2009-12-10 19:50:34 +00:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/*
|
|
|
|
* si470x_i2c_probe - probe for the device
|
|
|
|
*/
|
2019-07-10 21:51:45 +00:00
|
|
|
static int si470x_i2c_probe(struct i2c_client *client)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
|
|
|
struct si470x_device *radio;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
/* private data allocation and initialization */
|
2018-12-07 13:58:10 +00:00
|
|
|
radio = devm_kzalloc(&client->dev, sizeof(*radio), GFP_KERNEL);
|
2009-08-09 17:23:35 +00:00
|
|
|
if (!radio) {
|
|
|
|
retval = -ENOMEM;
|
|
|
|
goto err_initial;
|
|
|
|
}
|
2009-12-10 19:50:34 +00:00
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
radio->client = client;
|
2012-07-12 19:55:48 +00:00
|
|
|
radio->band = 1; /* Default to 76 - 108 MHz */
|
2009-08-09 17:23:35 +00:00
|
|
|
mutex_init(&radio->lock);
|
2012-06-14 12:43:12 +00:00
|
|
|
init_completion(&radio->completion);
|
2009-08-09 17:23:35 +00:00
|
|
|
|
2018-04-05 19:08:12 +00:00
|
|
|
radio->get_register = si470x_get_register;
|
|
|
|
radio->set_register = si470x_set_register;
|
|
|
|
radio->fops_open = si470x_fops_open;
|
|
|
|
radio->fops_release = si470x_fops_release;
|
|
|
|
radio->vidioc_querycap = si470x_vidioc_querycap;
|
|
|
|
|
2018-02-26 23:22:02 +00:00
|
|
|
retval = v4l2_device_register(&client->dev, &radio->v4l2_dev);
|
|
|
|
if (retval < 0) {
|
|
|
|
dev_err(&client->dev, "couldn't register v4l2_device\n");
|
2018-12-07 13:58:10 +00:00
|
|
|
goto err_initial;
|
2018-02-26 23:22:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v4l2_ctrl_handler_init(&radio->hdl, 2);
|
|
|
|
v4l2_ctrl_new_std(&radio->hdl, &si470x_ctrl_ops,
|
|
|
|
V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
|
|
|
|
v4l2_ctrl_new_std(&radio->hdl, &si470x_ctrl_ops,
|
|
|
|
V4L2_CID_AUDIO_VOLUME, 0, 15, 1, 15);
|
|
|
|
if (radio->hdl.error) {
|
|
|
|
retval = radio->hdl.error;
|
|
|
|
dev_err(&client->dev, "couldn't register control\n");
|
2021-10-15 09:58:55 +00:00
|
|
|
goto err_all;
|
2018-02-26 23:22:02 +00:00
|
|
|
}
|
|
|
|
|
2012-05-04 12:16:57 +00:00
|
|
|
/* video device initialization */
|
|
|
|
radio->videodev = si470x_viddev_template;
|
2018-02-26 23:22:02 +00:00
|
|
|
radio->videodev.ctrl_handler = &radio->hdl;
|
|
|
|
radio->videodev.lock = &radio->lock;
|
|
|
|
radio->videodev.v4l2_dev = &radio->v4l2_dev;
|
|
|
|
radio->videodev.release = video_device_release_empty;
|
2019-06-04 11:19:52 +00:00
|
|
|
radio->videodev.device_caps =
|
|
|
|
V4L2_CAP_HW_FREQ_SEEK | V4L2_CAP_READWRITE | V4L2_CAP_TUNER |
|
|
|
|
V4L2_CAP_RADIO | V4L2_CAP_RDS_CAPTURE;
|
2012-05-04 12:16:57 +00:00
|
|
|
video_set_drvdata(&radio->videodev, radio);
|
2009-08-09 17:23:35 +00:00
|
|
|
|
2018-12-07 13:58:11 +00:00
|
|
|
radio->gpio_reset = devm_gpiod_get_optional(&client->dev, "reset",
|
|
|
|
GPIOD_OUT_LOW);
|
|
|
|
if (IS_ERR(radio->gpio_reset)) {
|
|
|
|
retval = PTR_ERR(radio->gpio_reset);
|
|
|
|
dev_err(&client->dev, "Failed to request gpio: %d\n", retval);
|
|
|
|
goto err_all;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radio->gpio_reset)
|
|
|
|
gpiod_set_value(radio->gpio_reset, 1);
|
|
|
|
|
2009-08-09 17:23:35 +00:00
|
|
|
/* power up : need 110ms */
|
|
|
|
radio->registers[POWERCFG] = POWERCFG_ENABLE;
|
|
|
|
if (si470x_set_register(radio, POWERCFG) < 0) {
|
|
|
|
retval = -EIO;
|
2018-12-07 13:58:10 +00:00
|
|
|
goto err_all;
|
2009-08-09 17:23:35 +00:00
|
|
|
}
|
|
|
|
msleep(110);
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/* get device and chip versions */
|
2009-08-09 17:23:35 +00:00
|
|
|
if (si470x_get_all_registers(radio) < 0) {
|
|
|
|
retval = -EIO;
|
2018-12-07 13:58:10 +00:00
|
|
|
goto err_all;
|
2009-08-09 17:23:35 +00:00
|
|
|
}
|
|
|
|
dev_info(&client->dev, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
|
2015-06-22 18:25:31 +00:00
|
|
|
radio->registers[DEVICEID], radio->registers[SI_CHIPID]);
|
|
|
|
if ((radio->registers[SI_CHIPID] & SI_CHIPID_FIRMWARE) < RADIO_FW_VERSION) {
|
2009-08-10 21:44:14 +00:00
|
|
|
dev_warn(&client->dev,
|
2021-11-29 11:38:06 +00:00
|
|
|
"This driver is known to work with firmware version %u, but the device has firmware version %u.\n"
|
|
|
|
"If you have some trouble using this driver, please report to V4L ML at linux-media@vger.kernel.org\n",
|
|
|
|
RADIO_FW_VERSION,
|
2015-06-22 18:25:31 +00:00
|
|
|
radio->registers[SI_CHIPID] & SI_CHIPID_FIRMWARE);
|
2009-08-10 21:44:14 +00:00
|
|
|
}
|
2009-08-09 17:23:35 +00:00
|
|
|
|
|
|
|
/* set initial frequency */
|
|
|
|
si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
|
|
|
|
|
2009-12-10 19:50:34 +00:00
|
|
|
/* rds buffer allocation */
|
|
|
|
radio->buf_size = rds_buf * 3;
|
2018-12-07 13:58:10 +00:00
|
|
|
radio->buffer = devm_kmalloc(&client->dev, radio->buf_size, GFP_KERNEL);
|
2009-12-10 19:50:34 +00:00
|
|
|
if (!radio->buffer) {
|
|
|
|
retval = -EIO;
|
2018-12-07 13:58:10 +00:00
|
|
|
goto err_all;
|
2009-12-10 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* rds buffer configuration */
|
|
|
|
radio->wr_index = 0;
|
|
|
|
radio->rd_index = 0;
|
|
|
|
init_waitqueue_head(&radio->read_queue);
|
|
|
|
|
2018-12-07 13:58:10 +00:00
|
|
|
retval = devm_request_threaded_irq(&client->dev, client->irq, NULL,
|
|
|
|
si470x_i2c_interrupt,
|
|
|
|
IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
|
|
|
|
DRIVER_NAME, radio);
|
2009-12-10 19:50:34 +00:00
|
|
|
if (retval) {
|
|
|
|
dev_err(&client->dev, "Failed to register interrupt\n");
|
2018-12-07 13:58:10 +00:00
|
|
|
goto err_all;
|
2009-12-10 19:50:34 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 17:23:35 +00:00
|
|
|
/* register video device */
|
2012-05-04 12:16:57 +00:00
|
|
|
retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO,
|
2009-08-10 21:44:14 +00:00
|
|
|
radio_nr);
|
2009-08-09 17:23:35 +00:00
|
|
|
if (retval) {
|
|
|
|
dev_warn(&client->dev, "Could not register video device\n");
|
|
|
|
goto err_all;
|
|
|
|
}
|
|
|
|
i2c_set_clientdata(client, radio);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err_all:
|
2018-02-26 23:22:02 +00:00
|
|
|
v4l2_ctrl_handler_free(&radio->hdl);
|
|
|
|
v4l2_device_unregister(&radio->v4l2_dev);
|
2009-08-09 17:23:35 +00:00
|
|
|
err_initial:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* si470x_i2c_remove - remove the device
|
|
|
|
*/
|
2022-08-15 08:02:30 +00:00
|
|
|
static void si470x_i2c_remove(struct i2c_client *client)
|
2009-08-09 17:23:35 +00:00
|
|
|
{
|
|
|
|
struct si470x_device *radio = i2c_get_clientdata(client);
|
|
|
|
|
2012-05-04 12:16:57 +00:00
|
|
|
video_unregister_device(&radio->videodev);
|
2009-08-09 17:23:35 +00:00
|
|
|
|
2018-12-07 13:58:11 +00:00
|
|
|
if (radio->gpio_reset)
|
|
|
|
gpiod_set_value(radio->gpio_reset, 0);
|
|
|
|
|
2019-11-10 06:28:15 +00:00
|
|
|
v4l2_ctrl_handler_free(&radio->hdl);
|
|
|
|
v4l2_device_unregister(&radio->v4l2_dev);
|
2009-08-09 17:23:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-01 17:24:21 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2009-12-10 19:52:50 +00:00
|
|
|
/*
|
|
|
|
* si470x_i2c_suspend - suspend the device
|
|
|
|
*/
|
2011-03-11 06:54:47 +00:00
|
|
|
static int si470x_i2c_suspend(struct device *dev)
|
2009-12-10 19:52:50 +00:00
|
|
|
{
|
2011-03-11 06:54:47 +00:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
2009-12-10 19:52:50 +00:00
|
|
|
struct si470x_device *radio = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
/* power down */
|
|
|
|
radio->registers[POWERCFG] |= POWERCFG_DISABLE;
|
|
|
|
if (si470x_set_register(radio, POWERCFG) < 0)
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* si470x_i2c_resume - resume the device
|
|
|
|
*/
|
2011-03-11 06:54:47 +00:00
|
|
|
static int si470x_i2c_resume(struct device *dev)
|
2009-12-10 19:52:50 +00:00
|
|
|
{
|
2011-03-11 06:54:47 +00:00
|
|
|
struct i2c_client *client = to_i2c_client(dev);
|
2009-12-10 19:52:50 +00:00
|
|
|
struct si470x_device *radio = i2c_get_clientdata(client);
|
|
|
|
|
|
|
|
/* power up : need 110ms */
|
|
|
|
radio->registers[POWERCFG] |= POWERCFG_ENABLE;
|
|
|
|
if (si470x_set_register(radio, POWERCFG) < 0)
|
|
|
|
return -EIO;
|
|
|
|
msleep(110);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-11 06:54:47 +00:00
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(si470x_i2c_pm, si470x_i2c_suspend, si470x_i2c_resume);
|
2009-12-10 19:52:50 +00:00
|
|
|
#endif
|
|
|
|
|
2018-12-07 13:58:09 +00:00
|
|
|
#if IS_ENABLED(CONFIG_OF)
|
|
|
|
static const struct of_device_id si470x_of_match[] = {
|
|
|
|
{ .compatible = "silabs,si470x" },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, si470x_of_match);
|
|
|
|
#endif
|
2009-12-10 19:52:50 +00:00
|
|
|
|
2009-08-10 21:44:14 +00:00
|
|
|
/*
|
|
|
|
* si470x_i2c_driver - i2c driver interface
|
|
|
|
*/
|
2009-08-09 17:23:35 +00:00
|
|
|
static struct i2c_driver si470x_i2c_driver = {
|
|
|
|
.driver = {
|
2009-08-10 21:44:14 +00:00
|
|
|
.name = "si470x",
|
2018-12-07 13:58:09 +00:00
|
|
|
.of_match_table = of_match_ptr(si470x_of_match),
|
2013-11-01 17:24:21 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2011-03-11 06:54:47 +00:00
|
|
|
.pm = &si470x_i2c_pm,
|
|
|
|
#endif
|
2009-08-09 17:23:35 +00:00
|
|
|
},
|
2019-07-10 21:51:45 +00:00
|
|
|
.probe_new = si470x_i2c_probe,
|
2012-12-21 21:17:53 +00:00
|
|
|
.remove = si470x_i2c_remove,
|
2009-08-10 21:44:14 +00:00
|
|
|
.id_table = si470x_i2c_id,
|
2009-08-09 17:23:35 +00:00
|
|
|
};
|
|
|
|
|
2012-02-12 09:56:32 +00:00
|
|
|
module_i2c_driver(si470x_i2c_driver);
|
2009-08-09 17:23:35 +00:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
2009-08-10 21:44:14 +00:00
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
|
|
|
MODULE_VERSION(DRIVER_VERSION);
|