Merge branch 'topic/si476x' into patchwork
* topic/si476x: Revert "[media] mfd: Add chip properties handling code for SI476X MFD" Revert "[media] mfd: Add the main bulk of core driver for SI476x code" Revert "[media] mfd: Add commands abstraction layer for SI476X MFD" [media] v4l2: Add a V4L2 driver for SI476X MFD
This commit is contained in:
commit
966a160187
8 changed files with 1840 additions and 2682 deletions
187
Documentation/video4linux/si476x.txt
Normal file
187
Documentation/video4linux/si476x.txt
Normal file
|
@ -0,0 +1,187 @@
|
|||
SI476x Driver Readme
|
||||
------------------------------------------------
|
||||
Copyright (C) 2013 Andrey Smirnov <andrew.smirnov@gmail.com>
|
||||
|
||||
TODO for the driver
|
||||
------------------------------
|
||||
|
||||
- According to the SiLabs' datasheet it is possible to update the
|
||||
firmware of the radio chip in the run-time, thus bringing it to the
|
||||
most recent version. Unfortunately I couldn't find any mentioning of
|
||||
the said firmware update for the old chips that I tested the driver
|
||||
against, so for chips like that the driver only exposes the old
|
||||
functionality.
|
||||
|
||||
|
||||
Parameters exposed over debugfs
|
||||
-------------------------------
|
||||
SI476x allow user to get multiple characteristics that can be very
|
||||
useful for EoL testing/RF performance estimation, parameters that have
|
||||
very little to do with V4L2 subsystem. Such parameters are exposed via
|
||||
debugfs and can be accessed via regular file I/O operations.
|
||||
|
||||
The drivers exposes following files:
|
||||
|
||||
* /sys/kernel/debug/<device-name>/acf
|
||||
This file contains ACF(Automatically Controlled Features) status
|
||||
information. The contents of the file is binary data of the
|
||||
following layout:
|
||||
|
||||
Offset | Name | Description
|
||||
====================================================================
|
||||
0x00 | blend_int | Flag, set when stereo separation has
|
||||
| | crossed below the blend threshold
|
||||
--------------------------------------------------------------------
|
||||
0x01 | hblend_int | Flag, set when HiBlend cutoff
|
||||
| | frequency is lower than threshold
|
||||
--------------------------------------------------------------------
|
||||
0x02 | hicut_int | Flag, set when HiCut cutoff
|
||||
| | frequency is lower than threshold
|
||||
--------------------------------------------------------------------
|
||||
0x03 | chbw_int | Flag, set when channel filter
|
||||
| | bandwidth is less than threshold
|
||||
--------------------------------------------------------------------
|
||||
0x04 | softmute_int | Flag indicating that softmute
|
||||
| | attenuation has increased above
|
||||
| | softmute threshold
|
||||
--------------------------------------------------------------------
|
||||
0x05 | smute | 0 - Audio is not soft muted
|
||||
| | 1 - Audio is soft muted
|
||||
--------------------------------------------------------------------
|
||||
0x06 | smattn | Soft mute attenuation level in dB
|
||||
--------------------------------------------------------------------
|
||||
0x07 | chbw | Channel filter bandwidth in kHz
|
||||
--------------------------------------------------------------------
|
||||
0x08 | hicut | HiCut cutoff frequency in units of
|
||||
| | 100Hz
|
||||
--------------------------------------------------------------------
|
||||
0x09 | hiblend | HiBlend cutoff frequency in units
|
||||
| | of 100 Hz
|
||||
--------------------------------------------------------------------
|
||||
0x10 | pilot | 0 - Stereo pilot is not present
|
||||
| | 1 - Stereo pilot is present
|
||||
--------------------------------------------------------------------
|
||||
0x11 | stblend | Stereo blend in %
|
||||
--------------------------------------------------------------------
|
||||
|
||||
|
||||
* /sys/kernel/debug/<device-name>/rds_blckcnt
|
||||
This file contains statistics about RDS receptions. It's binary data
|
||||
has the following layout:
|
||||
|
||||
Offset | Name | Description
|
||||
====================================================================
|
||||
0x00 | expected | Number of expected RDS blocks
|
||||
--------------------------------------------------------------------
|
||||
0x02 | received | Number of received RDS blocks
|
||||
--------------------------------------------------------------------
|
||||
0x04 | uncorrectable | Number of uncorrectable RDS blocks
|
||||
--------------------------------------------------------------------
|
||||
|
||||
* /sys/kernel/debug/<device-name>/agc
|
||||
This file contains information about parameters pertaining to
|
||||
AGC(Automatic Gain Control)
|
||||
|
||||
The layout is:
|
||||
Offset | Name | Description
|
||||
====================================================================
|
||||
0x00 | mxhi | 0 - FM Mixer PD high threshold is
|
||||
| | not tripped
|
||||
| | 1 - FM Mixer PD high threshold is
|
||||
| | tripped
|
||||
--------------------------------------------------------------------
|
||||
0x01 | mxlo | ditto for FM Mixer PD low
|
||||
--------------------------------------------------------------------
|
||||
0x02 | lnahi | ditto for FM LNA PD high
|
||||
--------------------------------------------------------------------
|
||||
0x03 | lnalo | ditto for FM LNA PD low
|
||||
--------------------------------------------------------------------
|
||||
0x04 | fmagc1 | FMAGC1 attenuator resistance
|
||||
| | (see datasheet for more detail)
|
||||
--------------------------------------------------------------------
|
||||
0x05 | fmagc2 | ditto for FMAGC2
|
||||
--------------------------------------------------------------------
|
||||
0x06 | pgagain | PGA gain in dB
|
||||
--------------------------------------------------------------------
|
||||
0x07 | fmwblang | FM/WB LNA Gain in dB
|
||||
--------------------------------------------------------------------
|
||||
|
||||
* /sys/kernel/debug/<device-name>/rsq
|
||||
This file contains information about parameters pertaining to
|
||||
RSQ(Received Signal Quality)
|
||||
|
||||
The layout is:
|
||||
Offset | Name | Description
|
||||
====================================================================
|
||||
0x00 | multhint | 0 - multipath value has not crossed
|
||||
| | the Multipath high threshold
|
||||
| | 1 - multipath value has crossed
|
||||
| | the Multipath high threshold
|
||||
--------------------------------------------------------------------
|
||||
0x01 | multlint | ditto for Multipath low threshold
|
||||
--------------------------------------------------------------------
|
||||
0x02 | snrhint | 0 - received signal's SNR has not
|
||||
| | crossed high threshold
|
||||
| | 1 - received signal's SNR has
|
||||
| | crossed high threshold
|
||||
--------------------------------------------------------------------
|
||||
0x03 | snrlint | ditto for low threshold
|
||||
--------------------------------------------------------------------
|
||||
0x04 | rssihint | ditto for RSSI high threshold
|
||||
--------------------------------------------------------------------
|
||||
0x05 | rssilint | ditto for RSSI low threshold
|
||||
--------------------------------------------------------------------
|
||||
0x06 | bltf | Flag indicating if seek command
|
||||
| | reached/wrapped seek band limit
|
||||
--------------------------------------------------------------------
|
||||
0x07 | snr_ready | Indicates that SNR metrics is ready
|
||||
--------------------------------------------------------------------
|
||||
0x08 | rssiready | ditto for RSSI metrics
|
||||
--------------------------------------------------------------------
|
||||
0x09 | injside | 0 - Low-side injection is being used
|
||||
| | 1 - High-side injection is used
|
||||
--------------------------------------------------------------------
|
||||
0x10 | afcrl | Flag indicating if AFC rails
|
||||
--------------------------------------------------------------------
|
||||
0x11 | valid | Flag indicating if channel is valid
|
||||
--------------------------------------------------------------------
|
||||
0x12 | readfreq | Current tuned frequency
|
||||
--------------------------------------------------------------------
|
||||
0x14 | freqoff | Singed frequency offset in units of
|
||||
| | 2ppm
|
||||
--------------------------------------------------------------------
|
||||
0x15 | rssi | Signed value of RSSI in dBuV
|
||||
--------------------------------------------------------------------
|
||||
0x16 | snr | Signed RF SNR in dB
|
||||
--------------------------------------------------------------------
|
||||
0x17 | issi | Signed Image Strength Signal
|
||||
| | indicator
|
||||
--------------------------------------------------------------------
|
||||
0x18 | lassi | Signed Low side adjacent Channel
|
||||
| | Strength indicator
|
||||
--------------------------------------------------------------------
|
||||
0x19 | hassi | ditto fpr High side
|
||||
--------------------------------------------------------------------
|
||||
0x20 | mult | Multipath indicator
|
||||
--------------------------------------------------------------------
|
||||
0x21 | dev | Frequency deviation
|
||||
--------------------------------------------------------------------
|
||||
0x24 | assi | Adjascent channel SSI
|
||||
--------------------------------------------------------------------
|
||||
0x25 | usn | Ultrasonic noise indicator
|
||||
--------------------------------------------------------------------
|
||||
0x26 | pilotdev | Pilot deviation in units of 100 Hz
|
||||
--------------------------------------------------------------------
|
||||
0x27 | rdsdev | ditto for RDS
|
||||
--------------------------------------------------------------------
|
||||
0x28 | assidev | ditto for ASSI
|
||||
--------------------------------------------------------------------
|
||||
0x29 | strongdev | Frequency deviation
|
||||
--------------------------------------------------------------------
|
||||
0x30 | rdspi | RDS PI code
|
||||
--------------------------------------------------------------------
|
||||
|
||||
* /sys/kernel/debug/<device-name>/rsq_primary
|
||||
This file contains information about parameters pertaining to
|
||||
RSQ(Received Signal Quality) for primary tuner only. Layout is as
|
||||
the one above.
|
|
@ -18,6 +18,22 @@ config RADIO_SI470X
|
|||
|
||||
source "drivers/media/radio/si470x/Kconfig"
|
||||
|
||||
config RADIO_SI476X
|
||||
tristate "Silicon Laboratories Si476x I2C FM Radio"
|
||||
depends on I2C && VIDEO_V4L2
|
||||
depends on MFD_SI476X_CORE
|
||||
select SND_SOC_SI476X
|
||||
---help---
|
||||
Choose Y here if you have this FM radio chip.
|
||||
|
||||
In order to control your radio card, you will need to use programs
|
||||
that are compatible with the Video For Linux 2 API. Information on
|
||||
this API and pointers to "v4l2" programs may be found at
|
||||
<file:Documentation/video4linux/API.html>.
|
||||
|
||||
To compile this driver as a module, choose M here: the
|
||||
module will be called radio-si476x.
|
||||
|
||||
config USB_MR800
|
||||
tristate "AverMedia MR 800 USB FM radio support"
|
||||
depends on USB && VIDEO_V4L2
|
||||
|
|
|
@ -19,6 +19,7 @@ obj-$(CONFIG_RADIO_GEMTEK) += radio-gemtek.o
|
|||
obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
|
||||
obj-$(CONFIG_I2C_SI4713) += si4713-i2c.o
|
||||
obj-$(CONFIG_RADIO_SI4713) += radio-si4713.o
|
||||
obj-$(CONFIG_RADIO_SI476X) += radio-si476x.o
|
||||
obj-$(CONFIG_RADIO_MIROPCM20) += radio-miropcm20.o
|
||||
obj-$(CONFIG_USB_DSBR) += dsbr100.o
|
||||
obj-$(CONFIG_RADIO_SI470X) += si470x/
|
||||
|
|
1599
drivers/media/radio/radio-si476x.c
Normal file
1599
drivers/media/radio/radio-si476x.c
Normal file
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -1,886 +0,0 @@
|
|||
/*
|
||||
* drivers/mfd/si476x-i2c.c -- Core device driver for si476x MFD
|
||||
* device
|
||||
*
|
||||
* Copyright (C) 2012 Innovative Converged Devices(ICD)
|
||||
* Copyright (C) 2013 Andrey Smirnov
|
||||
*
|
||||
* Author: Andrey Smirnov <andrew.smirnov@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; version 2 of the License.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
#include <linux/module.h>
|
||||
|
||||
#include <linux/slab.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/gpio.h>
|
||||
#include <linux/regulator/consumer.h>
|
||||
#include <linux/i2c.h>
|
||||
#include <linux/err.h>
|
||||
|
||||
#include <linux/mfd/si476x-core.h>
|
||||
|
||||
#define SI476X_MAX_IO_ERRORS 10
|
||||
#define SI476X_DRIVER_RDS_FIFO_DEPTH 128
|
||||
|
||||
/**
|
||||
* si476x_core_config_pinmux() - pin function configuration function
|
||||
*
|
||||
* @core: Core device structure
|
||||
*
|
||||
* Configure the functions of the pins of the radio chip.
|
||||
*
|
||||
* The function returns zero in case of succes or negative error code
|
||||
* otherwise.
|
||||
*/
|
||||
static int si476x_core_config_pinmux(struct si476x_core *core)
|
||||
{
|
||||
int err;
|
||||
dev_dbg(&core->client->dev, "Configuring pinmux\n");
|
||||
err = si476x_core_cmd_dig_audio_pin_cfg(core,
|
||||
core->pinmux.dclk,
|
||||
core->pinmux.dfs,
|
||||
core->pinmux.dout,
|
||||
core->pinmux.xout);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure digital audio pins(err = %d)\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = si476x_core_cmd_zif_pin_cfg(core,
|
||||
core->pinmux.iqclk,
|
||||
core->pinmux.iqfs,
|
||||
core->pinmux.iout,
|
||||
core->pinmux.qout);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure ZIF pins(err = %d)\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = si476x_core_cmd_ic_link_gpo_ctl_pin_cfg(core,
|
||||
core->pinmux.icin,
|
||||
core->pinmux.icip,
|
||||
core->pinmux.icon,
|
||||
core->pinmux.icop);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure IC-Link/GPO pins(err = %d)\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = si476x_core_cmd_ana_audio_pin_cfg(core,
|
||||
core->pinmux.lrout);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure analog audio pins(err = %d)\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
err = si476x_core_cmd_intb_pin_cfg(core,
|
||||
core->pinmux.intb,
|
||||
core->pinmux.a1);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure interrupt pins(err = %d)\n",
|
||||
err);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void si476x_core_schedule_polling_work(struct si476x_core *core)
|
||||
{
|
||||
schedule_delayed_work(&core->status_monitor,
|
||||
usecs_to_jiffies(SI476X_STATUS_POLL_US));
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_core_start() - early chip startup function
|
||||
* @core: Core device structure
|
||||
* @soft: When set, this flag forces "soft" startup, where "soft"
|
||||
* power down is the one done by sending appropriate command instead
|
||||
* of using reset pin of the tuner
|
||||
*
|
||||
* Perform required startup sequence to correctly power
|
||||
* up the chip and perform initial configuration. It does the
|
||||
* following sequence of actions:
|
||||
* 1. Claims and enables the power supplies VD and VIO1 required
|
||||
* for I2C interface of the chip operation.
|
||||
* 2. Waits for 100us, pulls the reset line up, enables irq,
|
||||
* waits for another 100us as it is specified by the
|
||||
* datasheet.
|
||||
* 3. Sends 'POWER_UP' command to the device with all provided
|
||||
* information about power-up parameters.
|
||||
* 4. Configures, pin multiplexor, disables digital audio and
|
||||
* configures interrupt sources.
|
||||
*
|
||||
* The function returns zero in case of succes or negative error code
|
||||
* otherwise.
|
||||
*/
|
||||
int si476x_core_start(struct si476x_core *core, bool soft)
|
||||
{
|
||||
struct i2c_client *client = core->client;
|
||||
int err;
|
||||
|
||||
if (!soft) {
|
||||
if (gpio_is_valid(core->gpio_reset))
|
||||
gpio_set_value_cansleep(core->gpio_reset, 1);
|
||||
|
||||
if (client->irq)
|
||||
enable_irq(client->irq);
|
||||
|
||||
udelay(100);
|
||||
|
||||
if (!client->irq) {
|
||||
atomic_set(&core->is_alive, 1);
|
||||
si476x_core_schedule_polling_work(core);
|
||||
}
|
||||
} else {
|
||||
if (client->irq)
|
||||
enable_irq(client->irq);
|
||||
else {
|
||||
atomic_set(&core->is_alive, 1);
|
||||
si476x_core_schedule_polling_work(core);
|
||||
}
|
||||
}
|
||||
|
||||
err = si476x_core_cmd_power_up(core,
|
||||
&core->power_up_parameters);
|
||||
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Power up failure(err = %d)\n",
|
||||
err);
|
||||
goto disable_irq;
|
||||
}
|
||||
|
||||
if (client->irq)
|
||||
atomic_set(&core->is_alive, 1);
|
||||
|
||||
err = si476x_core_config_pinmux(core);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure pinmux(err = %d)\n",
|
||||
err);
|
||||
goto disable_irq;
|
||||
}
|
||||
|
||||
if (client->irq) {
|
||||
err = regmap_write(core->regmap,
|
||||
SI476X_PROP_INT_CTL_ENABLE,
|
||||
SI476X_RDSIEN |
|
||||
SI476X_STCIEN |
|
||||
SI476X_CTSIEN);
|
||||
if (err < 0) {
|
||||
dev_err(&core->client->dev,
|
||||
"Failed to configure interrupt sources"
|
||||
"(err = %d)\n", err);
|
||||
goto disable_irq;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
disable_irq:
|
||||
if (err == -ENODEV)
|
||||
atomic_set(&core->is_alive, 0);
|
||||
|
||||
if (client->irq)
|
||||
disable_irq(client->irq);
|
||||
else
|
||||
cancel_delayed_work_sync(&core->status_monitor);
|
||||
|
||||
if (gpio_is_valid(core->gpio_reset))
|
||||
gpio_set_value_cansleep(core->gpio_reset, 0);
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_start);
|
||||
|
||||
/**
|
||||
* si476x_core_stop() - chip power-down function
|
||||
* @core: Core device structure
|
||||
* @soft: When set, function sends a POWER_DOWN command instead of
|
||||
* bringing reset line low
|
||||
*
|
||||
* Power down the chip by performing following actions:
|
||||
* 1. Disable IRQ or stop the polling worker
|
||||
* 2. Send the POWER_DOWN command if the power down is soft or bring
|
||||
* reset line low if not.
|
||||
*
|
||||
* The function returns zero in case of succes or negative error code
|
||||
* otherwise.
|
||||
*/
|
||||
int si476x_core_stop(struct si476x_core *core, bool soft)
|
||||
{
|
||||
int err = 0;
|
||||
atomic_set(&core->is_alive, 0);
|
||||
|
||||
if (soft) {
|
||||
/* TODO: This probably shoud be a configurable option,
|
||||
* so it is possible to have the chips keep their
|
||||
* oscillators running
|
||||
*/
|
||||
struct si476x_power_down_args args = {
|
||||
.xosc = false,
|
||||
};
|
||||
err = si476x_core_cmd_power_down(core, &args);
|
||||
}
|
||||
|
||||
/* We couldn't disable those before
|
||||
* 'si476x_core_cmd_power_down' since we expect to get CTS
|
||||
* interrupt */
|
||||
if (core->client->irq)
|
||||
disable_irq(core->client->irq);
|
||||
else
|
||||
cancel_delayed_work_sync(&core->status_monitor);
|
||||
|
||||
if (!soft) {
|
||||
if (gpio_is_valid(core->gpio_reset))
|
||||
gpio_set_value_cansleep(core->gpio_reset, 0);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_stop);
|
||||
|
||||
/**
|
||||
* si476x_core_set_power_state() - set the level at which the power is
|
||||
* supplied for the chip.
|
||||
* @core: Core device structure
|
||||
* @next_state: enum si476x_power_state describing power state to
|
||||
* switch to.
|
||||
*
|
||||
* Switch on all the required power supplies
|
||||
*
|
||||
* This function returns 0 in case of suvccess and negative error code
|
||||
* otherwise.
|
||||
*/
|
||||
int si476x_core_set_power_state(struct si476x_core *core,
|
||||
enum si476x_power_state next_state)
|
||||
{
|
||||
/*
|
||||
It is not clear form the datasheet if it is possible to
|
||||
work with device if not all power domains are operational.
|
||||
So for now the power-up policy is "power-up all the things!"
|
||||
*/
|
||||
int err = 0;
|
||||
|
||||
if (core->power_state == SI476X_POWER_INCONSISTENT) {
|
||||
dev_err(&core->client->dev,
|
||||
"The device in inconsistent power state\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (next_state != core->power_state) {
|
||||
switch (next_state) {
|
||||
case SI476X_POWER_UP_FULL:
|
||||
err = regulator_bulk_enable(ARRAY_SIZE(core->supplies),
|
||||
core->supplies);
|
||||
if (err < 0) {
|
||||
core->power_state = SI476X_POWER_INCONSISTENT;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Startup timing diagram recommends to have a
|
||||
* 100 us delay between enabling of the power
|
||||
* supplies and turning the tuner on.
|
||||
*/
|
||||
udelay(100);
|
||||
|
||||
err = si476x_core_start(core, false);
|
||||
if (err < 0)
|
||||
goto disable_regulators;
|
||||
|
||||
core->power_state = next_state;
|
||||
break;
|
||||
|
||||
case SI476X_POWER_DOWN:
|
||||
core->power_state = next_state;
|
||||
err = si476x_core_stop(core, false);
|
||||
if (err < 0)
|
||||
core->power_state = SI476X_POWER_INCONSISTENT;
|
||||
disable_regulators:
|
||||
err = regulator_bulk_disable(ARRAY_SIZE(core->supplies),
|
||||
core->supplies);
|
||||
if (err < 0)
|
||||
core->power_state = SI476X_POWER_INCONSISTENT;
|
||||
break;
|
||||
default:
|
||||
BUG();
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_set_power_state);
|
||||
|
||||
/**
|
||||
* si476x_core_report_drainer_stop() - mark the completion of the RDS
|
||||
* buffer drain porcess by the worker.
|
||||
*
|
||||
* @core: Core device structure
|
||||
*/
|
||||
static inline void si476x_core_report_drainer_stop(struct si476x_core *core)
|
||||
{
|
||||
mutex_lock(&core->rds_drainer_status_lock);
|
||||
core->rds_drainer_is_working = false;
|
||||
mutex_unlock(&core->rds_drainer_status_lock);
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_core_start_rds_drainer_once() - start RDS drainer worker if
|
||||
* ther is none working, do nothing otherwise
|
||||
*
|
||||
* @core: Datastructure corresponding to the chip.
|
||||
*/
|
||||
static inline void si476x_core_start_rds_drainer_once(struct si476x_core *core)
|
||||
{
|
||||
mutex_lock(&core->rds_drainer_status_lock);
|
||||
if (!core->rds_drainer_is_working) {
|
||||
core->rds_drainer_is_working = true;
|
||||
schedule_work(&core->rds_fifo_drainer);
|
||||
}
|
||||
mutex_unlock(&core->rds_drainer_status_lock);
|
||||
}
|
||||
/**
|
||||
* si476x_drain_rds_fifo() - RDS buffer drainer.
|
||||
* @work: struct work_struct being ppassed to the function by the
|
||||
* kernel.
|
||||
*
|
||||
* Drain the contents of the RDS FIFO of
|
||||
*/
|
||||
static void si476x_core_drain_rds_fifo(struct work_struct *work)
|
||||
{
|
||||
int err;
|
||||
|
||||
struct si476x_core *core = container_of(work, struct si476x_core,
|
||||
rds_fifo_drainer);
|
||||
|
||||
struct si476x_rds_status_report report;
|
||||
|
||||
si476x_core_lock(core);
|
||||
err = si476x_core_cmd_fm_rds_status(core, true, false, false, &report);
|
||||
if (!err) {
|
||||
int i = report.rdsfifoused;
|
||||
dev_dbg(&core->client->dev,
|
||||
"%d elements in RDS FIFO. Draining.\n", i);
|
||||
for (; i > 0; --i) {
|
||||
err = si476x_core_cmd_fm_rds_status(core, false, false,
|
||||
(i == 1), &report);
|
||||
if (err < 0)
|
||||
goto unlock;
|
||||
|
||||
kfifo_in(&core->rds_fifo, report.rds,
|
||||
sizeof(report.rds));
|
||||
dev_dbg(&core->client->dev, "RDS data:\n %*ph\n",
|
||||
(int)sizeof(report.rds), report.rds);
|
||||
}
|
||||
dev_dbg(&core->client->dev, "Drrrrained!\n");
|
||||
wake_up_interruptible(&core->rds_read_queue);
|
||||
}
|
||||
|
||||
unlock:
|
||||
si476x_core_unlock(core);
|
||||
si476x_core_report_drainer_stop(core);
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_core_pronounce_dead()
|
||||
*
|
||||
* @core: Core device structure
|
||||
*
|
||||
* Mark the device as being dead and wake up all potentially waiting
|
||||
* threads of execution.
|
||||
*
|
||||
*/
|
||||
static void si476x_core_pronounce_dead(struct si476x_core *core)
|
||||
{
|
||||
dev_info(&core->client->dev, "Core device is dead.\n");
|
||||
|
||||
atomic_set(&core->is_alive, 0);
|
||||
|
||||
/* Wake up al possible waiting processes */
|
||||
wake_up_interruptible(&core->rds_read_queue);
|
||||
|
||||
atomic_set(&core->cts, 1);
|
||||
wake_up(&core->command);
|
||||
|
||||
atomic_set(&core->stc, 1);
|
||||
wake_up(&core->tuning);
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_core_i2c_xfer()
|
||||
*
|
||||
* @core: Core device structure
|
||||
* @type: Transfer type
|
||||
* @buf: Transfer buffer for/with data
|
||||
* @count: Transfer buffer size
|
||||
*
|
||||
* Perfrom and I2C transfer(either read or write) and keep a counter
|
||||
* of I/O errors. If the error counter rises above the threshold
|
||||
* pronounce device dead.
|
||||
*
|
||||
* The function returns zero on succes or negative error code on
|
||||
* failure.
|
||||
*/
|
||||
int si476x_core_i2c_xfer(struct si476x_core *core,
|
||||
enum si476x_i2c_type type,
|
||||
char *buf, int count)
|
||||
{
|
||||
static int io_errors_count;
|
||||
int err;
|
||||
if (type == SI476X_I2C_SEND)
|
||||
err = i2c_master_send(core->client, buf, count);
|
||||
else
|
||||
err = i2c_master_recv(core->client, buf, count);
|
||||
|
||||
if (err < 0) {
|
||||
if (io_errors_count++ > SI476X_MAX_IO_ERRORS)
|
||||
si476x_core_pronounce_dead(core);
|
||||
} else {
|
||||
io_errors_count = 0;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_i2c_xfer);
|
||||
|
||||
/**
|
||||
* si476x_get_status()
|
||||
* @core: Core device structure
|
||||
*
|
||||
* Get the status byte of the core device by berforming one byte I2C
|
||||
* read.
|
||||
*
|
||||
* The function returns a status value or a negative error code on
|
||||
* error.
|
||||
*/
|
||||
static int si476x_core_get_status(struct si476x_core *core)
|
||||
{
|
||||
u8 response;
|
||||
int err = si476x_core_i2c_xfer(core, SI476X_I2C_RECV,
|
||||
&response, sizeof(response));
|
||||
|
||||
return (err < 0) ? err : response;
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_get_and_signal_status() - IRQ dispatcher
|
||||
* @core: Core device structure
|
||||
*
|
||||
* Dispatch the arrived interrupt request based on the value of the
|
||||
* status byte reported by the tuner.
|
||||
*
|
||||
*/
|
||||
static void si476x_core_get_and_signal_status(struct si476x_core *core)
|
||||
{
|
||||
int status = si476x_core_get_status(core);
|
||||
if (status < 0) {
|
||||
dev_err(&core->client->dev, "Failed to get status\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (status & SI476X_CTS) {
|
||||
/* Unfortunately completions could not be used for
|
||||
* signalling CTS since this flag cannot be cleared
|
||||
* in status byte, and therefore once it becomes true
|
||||
* multiple calls to 'complete' would cause the
|
||||
* commands following the current one to be completed
|
||||
* before they actually are */
|
||||
dev_dbg(&core->client->dev, "[interrupt] CTSINT\n");
|
||||
atomic_set(&core->cts, 1);
|
||||
wake_up(&core->command);
|
||||
}
|
||||
|
||||
if (status & SI476X_FM_RDS_INT) {
|
||||
dev_dbg(&core->client->dev, "[interrupt] RDSINT\n");
|
||||
si476x_core_start_rds_drainer_once(core);
|
||||
}
|
||||
|
||||
if (status & SI476X_STC_INT) {
|
||||
dev_dbg(&core->client->dev, "[interrupt] STCINT\n");
|
||||
atomic_set(&core->stc, 1);
|
||||
wake_up(&core->tuning);
|
||||
}
|
||||
}
|
||||
|
||||
static void si476x_core_poll_loop(struct work_struct *work)
|
||||
{
|
||||
struct si476x_core *core = SI476X_WORK_TO_CORE(work);
|
||||
|
||||
si476x_core_get_and_signal_status(core);
|
||||
|
||||
if (atomic_read(&core->is_alive))
|
||||
si476x_core_schedule_polling_work(core);
|
||||
}
|
||||
|
||||
static irqreturn_t si476x_core_interrupt(int irq, void *dev)
|
||||
{
|
||||
struct si476x_core *core = dev;
|
||||
|
||||
si476x_core_get_and_signal_status(core);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_firmware_version_to_revision()
|
||||
* @core: Core device structure
|
||||
* @major: Firmware major number
|
||||
* @minor1: Firmware first minor number
|
||||
* @minor2: Firmware second minor number
|
||||
*
|
||||
* Convert a chip's firmware version number into an offset that later
|
||||
* will be used to as offset in "vtable" of tuner functions
|
||||
*
|
||||
* This function returns a positive offset in case of success and a -1
|
||||
* in case of failure.
|
||||
*/
|
||||
static int si476x_core_fwver_to_revision(struct si476x_core *core,
|
||||
int func, int major,
|
||||
int minor1, int minor2)
|
||||
{
|
||||
switch (func) {
|
||||
case SI476X_FUNC_FM_RECEIVER:
|
||||
switch (major) {
|
||||
case 5:
|
||||
return SI476X_REVISION_A10;
|
||||
case 8:
|
||||
return SI476X_REVISION_A20;
|
||||
case 10:
|
||||
return SI476X_REVISION_A30;
|
||||
default:
|
||||
goto unknown_revision;
|
||||
}
|
||||
case SI476X_FUNC_AM_RECEIVER:
|
||||
switch (major) {
|
||||
case 5:
|
||||
return SI476X_REVISION_A10;
|
||||
case 7:
|
||||
return SI476X_REVISION_A20;
|
||||
case 9:
|
||||
return SI476X_REVISION_A30;
|
||||
default:
|
||||
goto unknown_revision;
|
||||
}
|
||||
case SI476X_FUNC_WB_RECEIVER:
|
||||
switch (major) {
|
||||
case 3:
|
||||
return SI476X_REVISION_A10;
|
||||
case 5:
|
||||
return SI476X_REVISION_A20;
|
||||
case 7:
|
||||
return SI476X_REVISION_A30;
|
||||
default:
|
||||
goto unknown_revision;
|
||||
}
|
||||
case SI476X_FUNC_BOOTLOADER:
|
||||
default: /* FALLTHROUG */
|
||||
BUG();
|
||||
return -1;
|
||||
}
|
||||
|
||||
unknown_revision:
|
||||
dev_err(&core->client->dev,
|
||||
"Unsupported version of the firmware: %d.%d.%d, "
|
||||
"reverting to A10 comptible functions\n",
|
||||
major, minor1, minor2);
|
||||
|
||||
return SI476X_REVISION_A10;
|
||||
}
|
||||
|
||||
/**
|
||||
* si476x_get_revision_info()
|
||||
* @core: Core device structure
|
||||
*
|
||||
* Get the firmware version number of the device. It is done in
|
||||
* following three steps:
|
||||
* 1. Power-up the device
|
||||
* 2. Send the 'FUNC_INFO' command
|
||||
* 3. Powering the device down.
|
||||
*
|
||||
* The function return zero on success and a negative error code on
|
||||
* failure.
|
||||
*/
|
||||
static int si476x_core_get_revision_info(struct si476x_core *core)
|
||||
{
|
||||
int rval;
|
||||
struct si476x_func_info info;
|
||||
|
||||
si476x_core_lock(core);
|
||||
rval = si476x_core_set_power_state(core, SI476X_POWER_UP_FULL);
|
||||
if (rval < 0)
|
||||
goto exit;
|
||||
|
||||
rval = si476x_core_cmd_func_info(core, &info);
|
||||
if (rval < 0)
|
||||
goto power_down;
|
||||
|
||||
core->revision = si476x_core_fwver_to_revision(core, info.func,
|
||||
info.firmware.major,
|
||||
info.firmware.minor[0],
|
||||
info.firmware.minor[1]);
|
||||
power_down:
|
||||
si476x_core_set_power_state(core, SI476X_POWER_DOWN);
|
||||
exit:
|
||||
si476x_core_unlock(core);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
bool si476x_core_has_am(struct si476x_core *core)
|
||||
{
|
||||
return core->chip_id == SI476X_CHIP_SI4761 ||
|
||||
core->chip_id == SI476X_CHIP_SI4764;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_has_am);
|
||||
|
||||
bool si476x_core_has_diversity(struct si476x_core *core)
|
||||
{
|
||||
return core->chip_id == SI476X_CHIP_SI4764;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_has_diversity);
|
||||
|
||||
bool si476x_core_is_a_secondary_tuner(struct si476x_core *core)
|
||||
{
|
||||
return si476x_core_has_diversity(core) &&
|
||||
(core->diversity_mode == SI476X_PHDIV_SECONDARY_ANTENNA ||
|
||||
core->diversity_mode == SI476X_PHDIV_SECONDARY_COMBINING);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_is_a_secondary_tuner);
|
||||
|
||||
bool si476x_core_is_a_primary_tuner(struct si476x_core *core)
|
||||
{
|
||||
return si476x_core_has_diversity(core) &&
|
||||
(core->diversity_mode == SI476X_PHDIV_PRIMARY_ANTENNA ||
|
||||
core->diversity_mode == SI476X_PHDIV_PRIMARY_COMBINING);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_is_a_primary_tuner);
|
||||
|
||||
bool si476x_core_is_in_am_receiver_mode(struct si476x_core *core)
|
||||
{
|
||||
return si476x_core_has_am(core) &&
|
||||
(core->power_up_parameters.func == SI476X_FUNC_AM_RECEIVER);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_is_in_am_receiver_mode);
|
||||
|
||||
bool si476x_core_is_powered_up(struct si476x_core *core)
|
||||
{
|
||||
return core->power_state == SI476X_POWER_UP_FULL;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(si476x_core_is_powered_up);
|
||||
|
||||
static int si476x_core_probe(struct i2c_client *client,
|
||||
const struct i2c_device_id *id)
|
||||
{
|
||||
int rval;
|
||||
struct si476x_core *core;
|
||||
struct si476x_platform_data *pdata;
|
||||
struct mfd_cell *cell;
|
||||
int cell_num;
|
||||
|
||||
core = devm_kzalloc(&client->dev, sizeof(*core), GFP_KERNEL);
|
||||
if (!core) {
|
||||
dev_err(&client->dev,
|
||||
"failed to allocate 'struct si476x_core'\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
core->client = client;
|
||||
|
||||
core->regmap = devm_regmap_init_si476x(core);
|
||||
if (IS_ERR(core->regmap)) {
|
||||
rval = PTR_ERR(core->regmap);
|
||||
dev_err(&client->dev,
|
||||
"Failed to allocate register map: %d\n",
|
||||
rval);
|
||||
return rval;
|
||||
}
|
||||
|
||||
i2c_set_clientdata(client, core);
|
||||
|
||||
atomic_set(&core->is_alive, 0);
|
||||
core->power_state = SI476X_POWER_DOWN;
|
||||
|
||||
pdata = client->dev.platform_data;
|
||||
if (pdata) {
|
||||
memcpy(&core->power_up_parameters,
|
||||
&pdata->power_up_parameters,
|
||||
sizeof(core->power_up_parameters));
|
||||
|
||||
core->gpio_reset = -1;
|
||||
if (gpio_is_valid(pdata->gpio_reset)) {
|
||||
rval = gpio_request(pdata->gpio_reset, "si476x reset");
|
||||
if (rval) {
|
||||
dev_err(&client->dev,
|
||||
"Failed to request gpio: %d\n", rval);
|
||||
return rval;
|
||||
}
|
||||
core->gpio_reset = pdata->gpio_reset;
|
||||
gpio_direction_output(core->gpio_reset, 0);
|
||||
}
|
||||
|
||||
core->diversity_mode = pdata->diversity_mode;
|
||||
memcpy(&core->pinmux, &pdata->pinmux,
|
||||
sizeof(struct si476x_pinmux));
|
||||
} else {
|
||||
dev_err(&client->dev, "No platform data provided\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
core->supplies[0].supply = "vd";
|
||||
core->supplies[1].supply = "va";
|
||||
core->supplies[2].supply = "vio1";
|
||||
core->supplies[3].supply = "vio2";
|
||||
|
||||
rval = devm_regulator_bulk_get(&client->dev,
|
||||
ARRAY_SIZE(core->supplies),
|
||||
core->supplies);
|
||||
if (rval) {
|
||||
dev_err(&client->dev, "Failet to gett all of the regulators\n");
|
||||
goto free_gpio;
|
||||
}
|
||||
|
||||
mutex_init(&core->cmd_lock);
|
||||
init_waitqueue_head(&core->command);
|
||||
init_waitqueue_head(&core->tuning);
|
||||
|
||||
rval = kfifo_alloc(&core->rds_fifo,
|
||||
SI476X_DRIVER_RDS_FIFO_DEPTH *
|
||||
sizeof(struct v4l2_rds_data),
|
||||
GFP_KERNEL);
|
||||
if (rval) {
|
||||
dev_err(&client->dev, "Could not alloate the FIFO\n");
|
||||
goto free_gpio;
|
||||
}
|
||||
mutex_init(&core->rds_drainer_status_lock);
|
||||
init_waitqueue_head(&core->rds_read_queue);
|
||||
INIT_WORK(&core->rds_fifo_drainer, si476x_core_drain_rds_fifo);
|
||||
|
||||
if (client->irq) {
|
||||
rval = devm_request_threaded_irq(&client->dev,
|
||||
client->irq, NULL,
|
||||
si476x_core_interrupt,
|
||||
IRQF_TRIGGER_FALLING,
|
||||
client->name, core);
|
||||
if (rval < 0) {
|
||||
dev_err(&client->dev, "Could not request IRQ %d\n",
|
||||
client->irq);
|
||||
goto free_kfifo;
|
||||
}
|
||||
disable_irq(client->irq);
|
||||
dev_dbg(&client->dev, "IRQ requested.\n");
|
||||
|
||||
core->rds_fifo_depth = 20;
|
||||
} else {
|
||||
INIT_DELAYED_WORK(&core->status_monitor,
|
||||
si476x_core_poll_loop);
|
||||
dev_info(&client->dev,
|
||||
"No IRQ number specified, will use polling\n");
|
||||
|
||||
core->rds_fifo_depth = 5;
|
||||
}
|
||||
|
||||
core->chip_id = id->driver_data;
|
||||
|
||||
rval = si476x_core_get_revision_info(core);
|
||||
if (rval < 0) {
|
||||
rval = -ENODEV;
|
||||
goto free_kfifo;
|
||||
}
|
||||
|
||||
cell_num = 0;
|
||||
|
||||
cell = &core->cells[SI476X_RADIO_CELL];
|
||||
cell->name = "si476x-radio";
|
||||
cell_num++;
|
||||
|
||||
#ifdef CONFIG_SND_SOC_SI476X
|
||||
if ((core->chip_id == SI476X_CHIP_SI4761 ||
|
||||
core->chip_id == SI476X_CHIP_SI4764) &&
|
||||
core->pinmux.dclk == SI476X_DCLK_DAUDIO &&
|
||||
core->pinmux.dfs == SI476X_DFS_DAUDIO &&
|
||||
core->pinmux.dout == SI476X_DOUT_I2S_OUTPUT &&
|
||||
core->pinmux.xout == SI476X_XOUT_TRISTATE) {
|
||||
cell = &core->cells[SI476X_CODEC_CELL];
|
||||
cell->name = "si476x-codec";
|
||||
cell_num++;
|
||||
}
|
||||
#endif
|
||||
rval = mfd_add_devices(&client->dev,
|
||||
(client->adapter->nr << 8) + client->addr,
|
||||
core->cells, cell_num,
|
||||
NULL, 0, NULL);
|
||||
if (!rval)
|
||||
return 0;
|
||||
|
||||
free_kfifo:
|
||||
kfifo_free(&core->rds_fifo);
|
||||
|
||||
free_gpio:
|
||||
if (gpio_is_valid(core->gpio_reset))
|
||||
gpio_free(core->gpio_reset);
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
static int si476x_core_remove(struct i2c_client *client)
|
||||
{
|
||||
struct si476x_core *core = i2c_get_clientdata(client);
|
||||
|
||||
si476x_core_pronounce_dead(core);
|
||||
mfd_remove_devices(&client->dev);
|
||||
|
||||
if (client->irq)
|
||||
disable_irq(client->irq);
|
||||
else
|
||||
cancel_delayed_work_sync(&core->status_monitor);
|
||||
|
||||
kfifo_free(&core->rds_fifo);
|
||||
|
||||
if (gpio_is_valid(core->gpio_reset))
|
||||
gpio_free(core->gpio_reset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const struct i2c_device_id si476x_id[] = {
|
||||
{ "si4761", SI476X_CHIP_SI4761 },
|
||||
{ "si4764", SI476X_CHIP_SI4764 },
|
||||
{ "si4768", SI476X_CHIP_SI4768 },
|
||||
{ },
|
||||
};
|
||||
MODULE_DEVICE_TABLE(i2c, si476x_id);
|
||||
|
||||
static struct i2c_driver si476x_core_driver = {
|
||||
.driver = {
|
||||
.name = "si476x-core",
|
||||
.owner = THIS_MODULE,
|
||||
},
|
||||
.probe = si476x_core_probe,
|
||||
.remove = si476x_core_remove,
|
||||
.id_table = si476x_id,
|
||||
};
|
||||
module_i2c_driver(si476x_core_driver);
|
||||
|
||||
|
||||
MODULE_AUTHOR("Andrey Smirnov <andrew.smirnov@gmail.com>");
|
||||
MODULE_DESCRIPTION("Si4761/64/68 AM/FM MFD core device driver");
|
||||
MODULE_LICENSE("GPL");
|
|
@ -1,242 +0,0 @@
|
|||
/*
|
||||
* drivers/mfd/si476x-prop.c -- Subroutines to access
|
||||
* properties of si476x chips
|
||||
*
|
||||
* Copyright (C) 2012 Innovative Converged Devices(ICD)
|
||||
* Copyright (C) 2013 Andrey Smirnov
|
||||
*
|
||||
* Author: Andrey Smirnov <andrew.smirnov@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; version 2 of the License.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include <linux/module.h>
|
||||
|
||||
#include <media/si476x.h>
|
||||
#include <linux/mfd/si476x-core.h>
|
||||
|
||||
struct si476x_property_range {
|
||||
u16 low, high;
|
||||
};
|
||||
|
||||
static bool si476x_core_element_is_in_array(u16 element,
|
||||
const u16 array[],
|
||||
size_t size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
if (element == array[i])
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool si476x_core_element_is_in_range(u16 element,
|
||||
const struct si476x_property_range range[],
|
||||
size_t size)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
if (element <= range[i].high && element >= range[i].low)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool si476x_core_is_valid_property_a10(struct si476x_core *core,
|
||||
u16 property)
|
||||
{
|
||||
static const u16 valid_properties[] = {
|
||||
0x0000,
|
||||
0x0500, 0x0501,
|
||||
0x0600,
|
||||
0x0709, 0x070C, 0x070D, 0x70E, 0x710,
|
||||
0x0718,
|
||||
0x1207, 0x1208,
|
||||
0x2007,
|
||||
0x2300,
|
||||
};
|
||||
|
||||
static const struct si476x_property_range valid_ranges[] = {
|
||||
{ 0x0200, 0x0203 },
|
||||
{ 0x0300, 0x0303 },
|
||||
{ 0x0400, 0x0404 },
|
||||
{ 0x0700, 0x0707 },
|
||||
{ 0x1100, 0x1102 },
|
||||
{ 0x1200, 0x1204 },
|
||||
{ 0x1300, 0x1306 },
|
||||
{ 0x2000, 0x2005 },
|
||||
{ 0x2100, 0x2104 },
|
||||
{ 0x2106, 0x2106 },
|
||||
{ 0x2200, 0x220E },
|
||||
{ 0x3100, 0x3104 },
|
||||
{ 0x3207, 0x320F },
|
||||
{ 0x3300, 0x3304 },
|
||||
{ 0x3500, 0x3517 },
|
||||
{ 0x3600, 0x3617 },
|
||||
{ 0x3700, 0x3717 },
|
||||
{ 0x4000, 0x4003 },
|
||||
};
|
||||
|
||||
return si476x_core_element_is_in_range(property, valid_ranges,
|
||||
ARRAY_SIZE(valid_ranges)) ||
|
||||
si476x_core_element_is_in_array(property, valid_properties,
|
||||
ARRAY_SIZE(valid_properties));
|
||||
}
|
||||
|
||||
static bool si476x_core_is_valid_property_a20(struct si476x_core *core,
|
||||
u16 property)
|
||||
{
|
||||
static const u16 valid_properties[] = {
|
||||
0x071B,
|
||||
0x1006,
|
||||
0x2210,
|
||||
0x3401,
|
||||
};
|
||||
|
||||
static const struct si476x_property_range valid_ranges[] = {
|
||||
{ 0x2215, 0x2219 },
|
||||
};
|
||||
|
||||
return si476x_core_is_valid_property_a10(core, property) ||
|
||||
si476x_core_element_is_in_range(property, valid_ranges,
|
||||
ARRAY_SIZE(valid_ranges)) ||
|
||||
si476x_core_element_is_in_array(property, valid_properties,
|
||||
ARRAY_SIZE(valid_properties));
|
||||
}
|
||||
|
||||
static bool si476x_core_is_valid_property_a30(struct si476x_core *core,
|
||||
u16 property)
|
||||
{
|
||||
static const u16 valid_properties[] = {
|
||||
0x071C, 0x071D,
|
||||
0x1007, 0x1008,
|
||||
0x220F, 0x2214,
|
||||
0x2301,
|
||||
0x3105, 0x3106,
|
||||
0x3402,
|
||||
};
|
||||
|
||||
static const struct si476x_property_range valid_ranges[] = {
|
||||
{ 0x0405, 0x0411 },
|
||||
{ 0x2008, 0x200B },
|
||||
{ 0x2220, 0x2223 },
|
||||
{ 0x3100, 0x3106 },
|
||||
};
|
||||
|
||||
return si476x_core_is_valid_property_a20(core, property) ||
|
||||
si476x_core_element_is_in_range(property, valid_ranges,
|
||||
ARRAY_SIZE(valid_ranges)) ||
|
||||
si476x_core_element_is_in_array(property, valid_properties,
|
||||
ARRAY_SIZE(valid_properties));
|
||||
}
|
||||
|
||||
typedef bool (*valid_property_pred_t) (struct si476x_core *, u16);
|
||||
|
||||
static bool si476x_core_is_valid_property(struct si476x_core *core,
|
||||
u16 property)
|
||||
{
|
||||
static const valid_property_pred_t is_valid_property[] = {
|
||||
[SI476X_REVISION_A10] = si476x_core_is_valid_property_a10,
|
||||
[SI476X_REVISION_A20] = si476x_core_is_valid_property_a20,
|
||||
[SI476X_REVISION_A30] = si476x_core_is_valid_property_a30,
|
||||
};
|
||||
|
||||
BUG_ON(core->revision > SI476X_REVISION_A30 ||
|
||||
core->revision == -1);
|
||||
return is_valid_property[core->revision](core, property);
|
||||
}
|
||||
|
||||
|
||||
static bool si476x_core_is_readonly_property(struct si476x_core *core,
|
||||
u16 property)
|
||||
{
|
||||
BUG_ON(core->revision > SI476X_REVISION_A30 ||
|
||||
core->revision == -1);
|
||||
|
||||
switch (core->revision) {
|
||||
case SI476X_REVISION_A10:
|
||||
return (property == 0x3200);
|
||||
case SI476X_REVISION_A20:
|
||||
return (property == 0x1006 ||
|
||||
property == 0x2210 ||
|
||||
property == 0x3200);
|
||||
case SI476X_REVISION_A30:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool si476x_core_regmap_readable_register(struct device *dev,
|
||||
unsigned int reg)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct si476x_core *core = i2c_get_clientdata(client);
|
||||
|
||||
return si476x_core_is_valid_property(core, (u16) reg);
|
||||
|
||||
}
|
||||
|
||||
static bool si476x_core_regmap_writable_register(struct device *dev,
|
||||
unsigned int reg)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct si476x_core *core = i2c_get_clientdata(client);
|
||||
|
||||
return si476x_core_is_valid_property(core, (u16) reg) &&
|
||||
!si476x_core_is_readonly_property(core, (u16) reg);
|
||||
}
|
||||
|
||||
|
||||
static int si476x_core_regmap_write(void *context, unsigned int reg,
|
||||
unsigned int val)
|
||||
{
|
||||
return si476x_core_cmd_set_property(context, reg, val);
|
||||
}
|
||||
|
||||
static int si476x_core_regmap_read(void *context, unsigned int reg,
|
||||
unsigned *val)
|
||||
{
|
||||
struct si476x_core *core = context;
|
||||
int err;
|
||||
|
||||
err = si476x_core_cmd_get_property(core, reg);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
*val = err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static const struct regmap_config si476x_regmap_config = {
|
||||
.reg_bits = 16,
|
||||
.val_bits = 16,
|
||||
|
||||
.max_register = 0x4003,
|
||||
|
||||
.writeable_reg = si476x_core_regmap_writable_register,
|
||||
.readable_reg = si476x_core_regmap_readable_register,
|
||||
|
||||
.reg_read = si476x_core_regmap_read,
|
||||
.reg_write = si476x_core_regmap_write,
|
||||
|
||||
.cache_type = REGCACHE_RBTREE,
|
||||
};
|
||||
|
||||
struct regmap *devm_regmap_init_si476x(struct si476x_core *core)
|
||||
{
|
||||
return devm_regmap_init(&core->client->dev, NULL,
|
||||
core, &si476x_regmap_config);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(devm_regmap_init_si476x);
|
37
include/media/si476x.h
Normal file
37
include/media/si476x.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* include/media/si476x.h -- Common definitions for si476x driver
|
||||
*
|
||||
* Copyright (C) 2012 Innovative Converged Devices(ICD)
|
||||
* Copyright (C) 2013 Andrey Smirnov
|
||||
*
|
||||
* Author: Andrey Smirnov <andrew.smirnov@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; version 2 of the License.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SI476X_H
|
||||
#define SI476X_H
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/videodev2.h>
|
||||
|
||||
#include <linux/mfd/si476x-reports.h>
|
||||
|
||||
enum si476x_ctrl_id {
|
||||
V4L2_CID_SI476X_RSSI_THRESHOLD = (V4L2_CID_USER_SI476X_BASE + 1),
|
||||
V4L2_CID_SI476X_SNR_THRESHOLD = (V4L2_CID_USER_SI476X_BASE + 2),
|
||||
V4L2_CID_SI476X_MAX_TUNE_ERROR = (V4L2_CID_USER_SI476X_BASE + 3),
|
||||
V4L2_CID_SI476X_HARMONICS_COUNT = (V4L2_CID_USER_SI476X_BASE + 4),
|
||||
V4L2_CID_SI476X_DIVERSITY_MODE = (V4L2_CID_USER_SI476X_BASE + 5),
|
||||
V4L2_CID_SI476X_INTERCHIP_LINK = (V4L2_CID_USER_SI476X_BASE + 6),
|
||||
};
|
||||
|
||||
#endif /* SI476X_H*/
|
Loading…
Reference in a new issue