Re: [PATCH v16 2/2] V4L2: WL1273 FM Radio: TI WL1273 FM radio driver

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

 



Hi Matti,

On Wed, Nov 17, 2010 at 7:12 PM, Matti J. Aaltonen
<matti.j.aaltonen@xxxxxxxxx> wrote:
> This module implements V4L2 controls for the Texas Instruments
> WL1273 FM Radio and handles the communication to with the chip.
>
> Signed-off-by: Matti J. Aaltonen <matti.j.aaltonen@xxxxxxxxx>
> ---
> Âdrivers/media/radio/Kconfig    Â|  16 +
> Âdrivers/media/radio/Makefile    |  Â1 +
> Âdrivers/media/radio/radio-wl1273.c | 2347 ++++++++++++++++++++++++++++++++++++
> Â3 files changed, 2364 insertions(+), 0 deletions(-)
> Âcreate mode 100644 drivers/media/radio/radio-wl1273.c
>
> diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
> index 83567b8..c3c5488 100644
> --- a/drivers/media/radio/Kconfig
> +++ b/drivers/media/radio/Kconfig
> @@ -452,4 +452,20 @@ config RADIO_TIMBERDALE
> Â Â Â Â Âfound behind the Timberdale FPGA on the Russellville board.
> Â Â Â Â ÂEnabling this driver will automatically select the DSP and tuner.
>
> +config RADIO_WL1273
> + Â Â Â tristate "Texas Instruments WL1273 I2C FM Radio"
> + Â Â Â depends on I2C && VIDEO_V4L2
> + Â Â Â select WL1273_CORE
> + Â Â Â select FW_LOADER
> + Â Â Â ---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-wl1273.
> +
> Âendif # RADIO_ADAPTERS
> diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
> index f615583..d297074 100644
> --- a/drivers/media/radio/Makefile
> +++ b/drivers/media/radio/Makefile
> @@ -26,5 +26,6 @@ obj-$(CONFIG_RADIO_TEA5764) += radio-tea5764.o
> Âobj-$(CONFIG_RADIO_SAA7706H) += saa7706h.o
> Âobj-$(CONFIG_RADIO_TEF6862) += tef6862.o
> Âobj-$(CONFIG_RADIO_TIMBERDALE) += radio-timb.o
> +obj-$(CONFIG_RADIO_WL1273) += radio-wl1273.o
>
> ÂEXTRA_CFLAGS += -Isound
> diff --git a/drivers/media/radio/radio-wl1273.c b/drivers/media/radio/radio-wl1273.c
> new file mode 100644
> index 0000000..5ac7a4b
> --- /dev/null
> +++ b/drivers/media/radio/radio-wl1273.c
> @@ -0,0 +1,2347 @@
> +/*
> + * Driver for the Texas Instruments WL1273 FM radio.
> + *
> + * Copyright (C) Nokia Corporation
> + * Author: Matti J. Aaltonen <matti.j.aaltonen@xxxxxxxxx>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * version 2 as published by the Free Software Foundation.
> + *
> + * 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.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
> + */
> +
> +#define DEBUG
> +
> +#include <linux/delay.h>
> +#include <linux/firmware.h>
> +#include <linux/interrupt.h>
> +#include <linux/mfd/wl1273-core.h>
> +#include <linux/slab.h>
> +#include <media/v4l2-common.h>
> +#include <media/v4l2-ctrls.h>
> +#include <media/v4l2-device.h>
> +#include <media/v4l2-ioctl.h>
> +
> +#define DRIVER_DESC "Wl1273 FM Radio"
> +
> +#define WL1273_POWER_SET_OFF Â Â Â Â Â 0
> +#define WL1273_POWER_SET_FM Â Â Â Â Â Â(1 << 0)
> +#define WL1273_POWER_SET_RDS Â Â Â Â Â (1 << 1)
> +#define WL1273_POWER_SET_RETENTION Â Â (1 << 4)
> +
> +#define WL1273_PUPD_SET_OFF Â Â Â Â Â Â0x00
> +#define WL1273_PUPD_SET_ON Â Â Â Â Â Â 0x01
> +#define WL1273_PUPD_SET_RETENTION Â Â Â0x10
> +
> +#define WL1273_FREQ(x) Â Â Â Â (x * 10000 / 625)
> +#define WL1273_INV_FREQ(x) Â Â (x * 625 / 10000)
> +
> +/*
> + * static int radio_nr - The number of the radio device
> + *
> + * The default is 0.
> + */
> +static int radio_nr = -1;

You have assigned -1 to radio_nr here. But your description says "The
default is 0".
I am bit confused...

> +module_param(radio_nr, int, 0);
> +MODULE_PARM_DESC(radio_nr, "Radio Nr");

Can we add clear comments instead "Radio Nr" ?. I know other driver
has this kind of description
What you added for "rds_buf" is more clear. This is only a suggestion..

> +
> +struct wl1273_device {
> +
> + Â Â Â char *bus_type;
> +
> + Â Â Â u8 forbidden;
> + Â Â Â unsigned int preemphasis;
> + Â Â Â unsigned int spacing;
> + Â Â Â unsigned int tx_power;
> + Â Â Â unsigned int rx_frequency;
> + Â Â Â unsigned int tx_frequency;
> + Â Â Â unsigned int rangelow;
> + Â Â Â unsigned int rangehigh;
> + Â Â Â unsigned int band;
> + Â Â Â bool stereo;
> +
> + Â Â Â /* RDS */
> + Â Â Â unsigned int rds_on;
> + Â Â Â struct delayed_work work;
> +
> + Â Â Â wait_queue_head_t read_queue;
> + Â Â Â struct mutex lock; /* for serializing fm radio operations */
> + Â Â Â struct completion busy;
> +
> + Â Â Â unsigned char *buffer;
> + Â Â Â unsigned int buf_size;
> + Â Â Â unsigned int rd_index;
> + Â Â Â unsigned int wr_index;
> +
> + Â Â Â /* Selected interrupts */
> + Â Â Â u16 irq_flags;
> + Â Â Â u16 irq_received;
> +
> + Â Â Â struct v4l2_ctrl_handler ctrl_handler;
> + Â Â Â struct v4l2_device v4l2dev;
> + Â Â Â struct video_device videodev;
> + Â Â Â struct device *dev;
> + Â Â Â struct wl1273_core *core;
> + Â Â Â struct file *owner;
> + Â Â Â char *write_buf;
> + Â Â Â unsigned int rds_users;
> +};
> +
> +#define WL1273_IRQ_MASK Â Â Â Â (WL1273_FR_EVENT Â Â Â Â Â Â Â | Â Â Â \
> + Â Â Â Â Â Â Â Â Â Â Â Â WL1273_POW_ENB_EVENT)
> +
> +/*
> + * static unsigned int rds_buf - the number of RDS buffer blocks used.
> + *
> + * The default number is 100.
> + */
> +static unsigned int rds_buf = 100;
> +module_param(rds_buf, uint, 0);
> +MODULE_PARM_DESC(rds_buf, "Number of RDS buffer entries. Default = 100");
> +
> +static int wl1273_fm_read_reg(struct wl1273_core *core, u8 reg, u16 *value)
> +{
> + Â Â Â struct i2c_client *client = core->client;
> + Â Â Â u8 b[2];
> + Â Â Â int r;
> +
> + Â Â Â r = i2c_smbus_read_i2c_block_data(client, reg, sizeof(b), b);
> + Â Â Â if (r != 2) {
> + Â Â Â Â Â Â Â dev_err(&client->dev, "%s: Read: %d fails.\n", __func__, reg);
> + Â Â Â Â Â Â Â return -EREMOTEIO;
> + Â Â Â }
> +
> + Â Â Â *value = (u16)b[0] << 8 | b[1];
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_write_cmd(struct wl1273_core *core, u8 cmd, u16 param)
> +{
> + Â Â Â struct i2c_client *client = core->client;
> +

No space here

> + Â Â Â u8 buf[] = { (param >> 8) & 0xff, param & 0xff };
> + Â Â Â int r;
> +
> + Â Â Â r = i2c_smbus_write_i2c_block_data(client, cmd, sizeof(buf), buf);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(&client->dev, "%s: Cmd: %d fails.\n", __func__, cmd);
> + Â Â Â Â Â Â Â return r;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_write_data(struct wl1273_core *core, u8 *data, u16 len)
> +{
> + Â Â Â struct i2c_client *client = core->client;
> + Â Â Â struct i2c_msg msg;
> + Â Â Â int r;
> +
> + Â Â Â msg.addr = client->addr;
> + Â Â Â msg.flags = 0;
> + Â Â Â msg.buf = data;
> + Â Â Â msg.len = len;
> +
> + Â Â Â r = i2c_transfer(client->adapter, &msg, 1);
> +

No space here

> + Â Â Â if (r != 1) {
> + Â Â Â Â Â Â Â dev_err(&client->dev, "%s: write error.\n", __func__);
> + Â Â Â Â Â Â Â return -EREMOTEIO;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_write_fw(struct wl1273_core *core,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct wl1273_fw_packet *packets, int len)
> +{
> + Â Â Â struct i2c_client *client = core->client;
> + Â Â Â struct i2c_msg msg;
> + Â Â Â int i, r = 0;
> +
> + Â Â Â msg.addr = client->addr;
> + Â Â Â msg.flags = 0;
> +
> + Â Â Â for (i = 0; i <= len; i++) {
> + Â Â Â Â Â Â Â msg.len = packets[i].len;
> + Â Â Â Â Â Â Â msg.buf = packets[i].buf;
> +
> + Â Â Â Â Â Â Â r = i2c_transfer(client->adapter, &msg, 1);
> + Â Â Â Â Â Â Â if (r < 0 && i < len + 1)
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â dev_dbg(&client->dev, "%s: i: %d\n", __func__, i);
> + Â Â Â dev_dbg(&client->dev, "%s: len + 1: %d\n", __func__, len + 1);
> +
> + Â Â Â /* Last transfer always fails. */
> + Â Â Â if (i == len || r == 1)
> + Â Â Â Â Â Â Â r = 0;
> +
> + Â Â Â return r;
> +}
> +
> +/**
> + * wl1273_fm_set_audio() - Â Â Set audio mode.
> + * @core: Â Â Â Â Â Â Â Â Â Â ÂA pointer to the device struct.
> + * @new_mode: Â Â Â Â Â Â Â Â ÂThe new audio mode.
> + *
> + * Audio modes are WL1273_AUDIO_DIGITAL and WL1273_AUDIO_ANALOG.
> + */
> +static int wl1273_fm_set_audio(struct wl1273_core *core, unsigned int new_mode)
> +{
> + Â Â Â int r = 0;
> +
> + Â Â Â if (core->mode == WL1273_MODE_OFF ||
> + Â Â Â Â Â core->mode == WL1273_MODE_SUSPENDED)
> + Â Â Â Â Â Â Â return -EPERM;
> +
> + Â Â Â if (core->mode == WL1273_MODE_RX && new_mode == WL1273_AUDIO_DIGITAL) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_PCM_MODE_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_PCM_DEF_MODE);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->i2s_mode);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_AUDIO_ENABLE_I2S);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â } else if (core->mode == WL1273_MODE_RX &&
> + Â Â Â Â Â Â Â Â Ânew_mode == WL1273_AUDIO_ANALOG) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_AUDIO_ENABLE,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_AUDIO_ENABLE_ANALOG);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â } else if (core->mode == WL1273_MODE_TX &&
> + Â Â Â Â Â Â Â Â Ânew_mode == WL1273_AUDIO_DIGITAL) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_I2S_MODE_CONFIG_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->i2s_mode);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_AUDIO_IO_SET_I2S);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â } else if (core->mode == WL1273_MODE_TX &&
> + Â Â Â Â Â Â Â Â Ânew_mode == WL1273_AUDIO_ANALOG) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_AUDIO_IO_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_AUDIO_IO_SET_ANALOG);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â core->audio_mode = new_mode;
> +out:
> + Â Â Â return r;
> +}
> +
> +/**
> + * wl1273_fm_set_volume() - Â ÂSet volume.
> + * @core: Â Â Â Â Â Â Â Â Â Â ÂA pointer to the device struct.
> + * @volume: Â Â Â Â Â Â Â Â Â ÂThe new volume value.
> + */
> +static int wl1273_fm_set_volume(struct wl1273_core *core, unsigned int volume)
> +{
> + Â Â Â u16 val;
> + Â Â Â int r;
> +
> + Â Â Â if (volume > WL1273_MAX_VOLUME)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â if (core->volume == volume)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â val = volume;

Really do we need val variable here ?

> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_VOLUME_SET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â return r;
> +
> + Â Â Â core->volume = volume;
> + Â Â Â return 0;
> +}
> +
> +#define WL1273_FIFO_HAS_DATA(status) Â (1 << 5 & status)
> +#define WL1273_RDS_CORRECTABLE_ERROR Â (1 << 3)
> +#define WL1273_RDS_UNCORRECTABLE_ERROR (1 << 4)
> +
> +static int wl1273_fm_rds(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â struct i2c_client *client = core->client;
> + Â Â Â u16 val;
> + Â Â Â u8 b0 = WL1273_RDS_DATA_GET, status;
> + Â Â Â struct v4l2_rds_data rds = { 0, 0, 0 };
> + Â Â Â struct i2c_msg msg[] = {
> + Â Â Â Â Â Â Â {
> + Â Â Â Â Â Â Â Â Â Â Â .addr = client->addr,
> + Â Â Â Â Â Â Â Â Â Â Â .flags = 0,
> + Â Â Â Â Â Â Â Â Â Â Â .buf = &b0,
> + Â Â Â Â Â Â Â Â Â Â Â .len = 1,
> + Â Â Â Â Â Â Â },
> + Â Â Â Â Â Â Â {
> + Â Â Â Â Â Â Â Â Â Â Â .addr = client->addr,
> + Â Â Â Â Â Â Â Â Â Â Â .flags = I2C_M_RD,
> + Â Â Â Â Â Â Â Â Â Â Â .buf = (u8 *) &rds,
> + Â Â Â Â Â Â Â Â Â Â Â .len = sizeof(rds),
> + Â Â Â Â Â Â Â }
> + Â Â Â };
> + Â Â Â int r;
> +
> + Â Â Â if (core->mode != WL1273_MODE_RX)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â return r;
> +
> + Â Â Â if ((val & 0x01) == 0) {
> + Â Â Â Â Â Â Â /* RDS decoder not synchronized */
> + Â Â Â Â Â Â Â return -EAGAIN;
> + Â Â Â }
> +
> + Â Â Â /* copy all four RDS blocks to internal buffer */
> + Â Â Â do {
> + Â Â Â Â Â Â Â r = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
> + Â Â Â Â Â Â Â if (r != ARRAY_SIZE(msg)) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(radio->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ": %s: read_rds error r == %i)\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__, r);
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â status = rds.block;
> +
> + Â Â Â Â Â Â Â if (!WL1273_FIFO_HAS_DATA(status))
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â /* copy bits 0-2 (the block ID) to bits 3-5 */
> + Â Â Â Â Â Â Â rds.block = V4L2_RDS_BLOCK_MSK & status;
> + Â Â Â Â Â Â Â rds.block |= rds.block << 3;
> +
> + Â Â Â Â Â Â Â /* copy the error bits to standard positions */
> + Â Â Â Â Â Â Â if (WL1273_RDS_UNCORRECTABLE_ERROR & status) {
> + Â Â Â Â Â Â Â Â Â Â Â rds.block |= V4L2_RDS_BLOCK_ERROR;
> + Â Â Â Â Â Â Â Â Â Â Â rds.block &= ~V4L2_RDS_BLOCK_CORRECTED;
> + Â Â Â Â Â Â Â } else if Â(WL1273_RDS_CORRECTABLE_ERROR & status) {
> + Â Â Â Â Â Â Â Â Â Â Â rds.block &= ~V4L2_RDS_BLOCK_ERROR;
> + Â Â Â Â Â Â Â Â Â Â Â rds.block |= V4L2_RDS_BLOCK_CORRECTED;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /* copy RDS block to internal buffer */
> + Â Â Â Â Â Â Â memcpy(&radio->buffer[radio->wr_index], &rds, RDS_BLOCK_SIZE);
> + Â Â Â Â Â Â Â radio->wr_index += 3;
> +
> + Â Â Â Â Â Â Â /* wrap write pointer */
> + Â Â Â Â Â Â Â if (radio->wr_index >= radio->buf_size)
> + Â Â Â Â Â Â Â Â Â Â Â radio->wr_index = 0;
> +
> + Â Â Â Â Â Â Â /* check for overflow & start over */
> + Â Â Â Â Â Â Â if (radio->wr_index == radio->rd_index) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(radio->dev, "RDS OVERFLOW");
> +
> + Â Â Â Â Â Â Â Â Â Â Â radio->rd_index = 0;
> + Â Â Â Â Â Â Â Â Â Â Â radio->wr_index = 0;
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â }
> + Â Â Â } while (WL1273_FIFO_HAS_DATA(status));
> +
> + Â Â Â /* wake up read queue */
> + Â Â Â if (radio->wr_index != radio->rd_index)
> + Â Â Â Â Â Â Â wake_up_interruptible(&radio->read_queue);
> +
> + Â Â Â return 0;
> +}
> +
> +static irqreturn_t wl1273_fm_irq_thread_handler(int irq, void *dev_id)
> +{
> + Â Â Â struct wl1273_device *radio = dev_id;
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â u16 flags;
> + Â Â Â int r;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_FLAG_GET, &flags);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (flags & WL1273_BL_EVENT) {
> + Â Â Â Â Â Â Â radio->irq_received = flags;
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: BL\n");
> + Â Â Â }
> +
> + Â Â Â if (flags & WL1273_RDS_EVENT) {
> + Â Â Â Â Â Â Â msleep(200);
> +
> + Â Â Â Â Â Â Â wl1273_fm_rds(radio);
> + Â Â Â }
> +
> + Â Â Â if (flags & WL1273_BBLK_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: BBLK\n");
> +
> + Â Â Â if (flags & WL1273_LSYNC_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: LSYNC\n");
> +
> + Â Â Â if (flags & WL1273_LEV_EVENT) {
> + Â Â Â Â Â Â Â u16 level;
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_RSSI_LVL_GET, &level);
> +

No space here

> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â if (level > 14)
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: LEV: 0x%x04\n", level);
> + Â Â Â }
> +
> + Â Â Â if (flags & WL1273_IFFR_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: IFFR\n");
> +
> + Â Â Â if (flags & WL1273_PI_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: PI\n");
> +
> + Â Â Â if (flags & WL1273_PD_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: PD\n");
> +
> + Â Â Â if (flags & WL1273_STIC_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: STIC\n");
> +
> + Â Â Â if (flags & WL1273_MAL_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: MAL\n");
> +
> + Â Â Â if (flags & WL1273_POW_ENB_EVENT) {
> + Â Â Â Â Â Â Â complete(&radio->busy);
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "NOT BUSY\n");
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: POW_ENB\n");
> + Â Â Â }
> +
> + Â Â Â if (flags & WL1273_SCAN_OVER_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: SCAN_OVER\n");
> +
> + Â Â Â if (flags & WL1273_ERROR_EVENT)
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: ERROR\n");
> +
> + Â Â Â if (flags & WL1273_FR_EVENT) {
> + Â Â Â Â Â Â Â u16 freq;
> +
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "IRQ: FR:\n");
> +
> + Â Â Â Â Â Â Â if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â TUNER_MODE_STOP_SEARCH);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "%s: TUNER_MODE_SET fails: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__, r);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_FREQ_SET, &freq);
> + Â Â Â Â Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â Â Â Â Â if (radio->band == WL1273_BAND_JAPAN)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â radio->rx_frequency = WL1273_BAND_JAPAN_LOW +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â freq * 50;
> + Â Â Â Â Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â radio->rx_frequency = WL1273_BAND_OTHER_LOW +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â freq * 50;
> + Â Â Â Â Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â Â Â Â Â* ÂThe driver works better with this msleep,
> + Â Â Â Â Â Â Â Â Â Â Â Â* Âthe documentation doesn't mention it.
> + Â Â Â Â Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â Â Â Â Â usleep_range(10000, 15000);
> +
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(radio->dev, "%dkHz\n", radio->rx_frequency);
> +
> + Â Â Â Â Â Â Â } else {
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_CHANL_SET, &freq);
> + Â Â Â Â Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(radio->dev, "%dkHz\n", freq);
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "%s: NOT BUSY\n", __func__);
> + Â Â Â }
> +
> +out:
> + Â Â Â wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â radio->irq_flags);
> + Â Â Â complete(&radio->busy);
> +
> + Â Â Â return IRQ_HANDLED;
> +}
> +
> +static int wl1273_fm_set_tx_freq(struct wl1273_device *radio, unsigned int freq)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â if (freq < WL1273_BAND_TX_LOW) {
> + Â Â Â Â Â Â Â dev_err(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Frequency out of range: %d < %d\n", freq,
> + Â Â Â Â Â Â Â Â Â Â Â WL1273_BAND_TX_LOW);
> + Â Â Â Â Â Â Â return -ERANGE;
> + Â Â Â }
> +
> + Â Â Â if (freq > WL1273_BAND_TX_HIGH) {
> + Â Â Â Â Â Â Â dev_err(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Frequency out of range: %d > %d\n", freq,
> + Â Â Â Â Â Â Â Â Â Â Â WL1273_BAND_TX_HIGH);
> + Â Â Â Â Â Â Â return -ERANGE;
> + Â Â Â }
> +
> + Â Â Â /*
> + Â Â Â Â* ÂThe driver works better with this sleep,
> + Â Â Â Â* Âthe documentation doesn't mention it.
> + Â Â Â Â*/
> + Â Â Â usleep_range(5000, 10000);
> +
> + Â Â Â dev_dbg(radio->dev, "%s: freq: %d kHz\n", __func__, freq);
> +
> + Â Â Â INIT_COMPLETION(radio->busy);
> + Â Â Â /* Set the current tx channel */
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_CHANL_SET, freq / 10);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â return r;
> +

Better , radio->busy init can be moved here.. there can be a chance to
hit above return..

> + Â Â Â /* wait for the FR IRQ */
> + Â Â Â r = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000));
> + Â Â Â if (!r)
> + Â Â Â Â Â Â Â return -ETIMEDOUT;
> +
> + Â Â Â dev_dbg(radio->dev, "WL1273_CHANL_SET: %d\n", r);
> +
> + Â Â Â /* Enable the output power */
> + Â Â Â INIT_COMPLETION(radio->busy);
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_ENB_SET, 1);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â return r;
> +

here too.. applicable everywhere this file..

> + Â Â Â /* wait for the POWER_ENB IRQ */
> + Â Â Â r = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
> + Â Â Â if (!r)
> + Â Â Â Â Â Â Â return -ETIMEDOUT;
> +
> + Â Â Â radio->tx_frequency = freq;
> + Â Â Â dev_dbg(radio->dev, "WL1273_POWER_ENB_SET: %d\n", r);
> +
> + Â Â Â return Â0;
> +}
> +
> +static int wl1273_fm_set_rx_freq(struct wl1273_device *radio, unsigned int freq)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r, f;
> +
> + Â Â Â if (freq < radio->rangelow) {
> + Â Â Â Â Â Â Â dev_err(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Frequency out of range: %d < %d\n", freq,
> + Â Â Â Â Â Â Â Â Â Â Â radio->rangelow);
> + Â Â Â Â Â Â Â r = -ERANGE;
> + Â Â Â Â Â Â Â goto err;
> + Â Â Â }
> +
> + Â Â Â if (freq > radio->rangehigh) {
> + Â Â Â Â Â Â Â dev_err(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "Frequency out of range: %d > %d\n", freq,
> + Â Â Â Â Â Â Â Â Â Â Â radio->rangehigh);
> + Â Â Â Â Â Â Â r = -ERANGE;
> + Â Â Â Â Â Â Â goto err;
> + Â Â Â }
> +
> + Â Â Â dev_dbg(radio->dev, "%s: %dkHz\n", __func__, freq);
> +
> + Â Â Â wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
> +
> + Â Â Â if (radio->band == WL1273_BAND_JAPAN)
> + Â Â Â Â Â Â Â f = (freq - WL1273_BAND_JAPAN_LOW) / 50;
> + Â Â Â else
> + Â Â Â Â Â Â Â f = (freq - WL1273_BAND_OTHER_LOW) / 50;
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_FREQ_SET, f);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "FREQ_SET fails\n");
> + Â Â Â Â Â Â Â goto err;
> + Â Â Â }
> +
> + Â Â Â INIT_COMPLETION(radio->busy);
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET, TUNER_MODE_PRESET);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "TUNER_MODE_SET fails\n");

why complete here ? radio->busy is just initialized .. who is waiting
on radio->busy ?

> + Â Â Â Â Â Â Â complete(&radio->busy);
> + Â Â Â Â Â Â Â goto err;
> + Â Â Â }
> +
> + Â Â Â r = wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(2000));
> + Â Â Â if (!r) {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "%s: TIMEOUT\n", __func__);
> + Â Â Â Â Â Â Â return -ETIMEDOUT;
> + Â Â Â }
> +
> + Â Â Â radio->rd_index = 0;
> + Â Â Â radio->wr_index = 0;
> + Â Â Â radio->rx_frequency = freq;
> + Â Â Â return 0;
> +err:
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_get_freq(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â unsigned int freq;
> + Â Â Â u16 f;
> + Â Â Â int r;
> +
> + Â Â Â if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_FREQ_SET, &f);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â return r;
> +
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "Freq get: 0x%04x\n", f);
> + Â Â Â Â Â Â Â if (radio->band == WL1273_BAND_JAPAN)
> + Â Â Â Â Â Â Â Â Â Â Â freq = WL1273_BAND_JAPAN_LOW + 50 * f;
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â freq = WL1273_BAND_OTHER_LOW + 50 * f;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_CHANL_SET, &f);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â return r;
> +
> + Â Â Â Â Â Â Â freq = f * 10;
> + Â Â Â }
> +
> + Â Â Â return freq;
> +}
> +
> +/**
> + * wl1273_fm_upload_firmware_patch() - Upload the firmware.
> + * @radio: Â Â Â Â Â Â Â Â Â Â Â Â Â Â A pointer to the device struct.
> + *
> + * The firmware file consists of arrays of bytes where the first byte
> + * gives the array length. The first byte in the file gives the
> + * number of these arrays.
> + */
> +static int wl1273_fm_upload_firmware_patch(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â unsigned int packet_num;
> + Â Â Â const struct firmware *fw_p;
> + Â Â Â const char *fw_name = "radio-wl1273-fw.bin";
> + Â Â Â struct device *dev = radio->dev;
> + Â Â Â __u8 *ptr;
> + Â Â Â int i, n, len, r;
> + Â Â Â struct wl1273_fw_packet *packets;
> +
> + Â Â Â dev_dbg(dev, "%s:\n", __func__);
> +
> + Â Â Â if (request_firmware(&fw_p, fw_name, dev)) {
> + Â Â Â Â Â Â Â dev_info(dev, "%s - %s not found\n", __func__, fw_name);
> +
> + Â Â Â Â Â Â Â return 0;

probably, you have to return negative error . not Zero.  Isn't it
mandatory to download FM Firmware ?

> + Â Â Â }
> +
> + Â Â Â ptr = (__u8 *) fw_p->data;
> + Â Â Â packet_num = ptr[0];
> + Â Â Â dev_dbg(dev, "%s: packets: %d\n", __func__, packet_num);
> +
> + Â Â Â packets = kmalloc((packet_num + 1) * sizeof(*packets), GFP_KERNEL);
> + Â Â Â if (!packets) {
> + Â Â Â Â Â Â Â r = -ENOMEM;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }

should we need "packets " ? . Can't we deal with fw_p->data itself for
firmware download?
we can avoid eating system memory.. Give a thought on this..

> +
> + Â Â Â i = 1;
> + Â Â Â for (n = 0; n <= packet_num; n++) {
> + Â Â Â Â Â Â Â len = ptr[i];
> +
> + Â Â Â Â Â Â Â dev_dbg(dev, "%s: len[%d]: %d\n", __func__, n, len);
> +
> + Â Â Â Â Â Â Â if (i + len + 1 <= fw_p->size) {
> + Â Â Â Â Â Â Â Â Â Â Â packets[n].len = len;
> + Â Â Â Â Â Â Â Â Â Â Â packets[n].buf = ptr + i + 1;
> + Â Â Â Â Â Â Â } else {
> + Â Â Â Â Â Â Â Â Â Â Â break;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â i += len + 1;
> + Â Â Â }
> +
> + Â Â Â r = wl1273_fm_write_fw(core, packets, packet_num);
> + Â Â Â kfree(packets);
> +
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(dev, "FW upload error: %d\n", r);
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â /* ignore possible error here */
> + Â Â Â wl1273_fm_write_cmd(core, WL1273_RESET, 0);
> +
> + Â Â Â dev_dbg(dev, "n: %d, i: %d\n", n, i);
> + Â Â Â dev_dbg(dev, "%s - download OK, r: %d\n", __func__, r);
> +out:
> + Â Â Â release_firmware(fw_p);
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_stop(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> +
> + Â Â Â if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â int r = wl1273_fm_write_cmd(core, WL1273_POWER_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_POWER_SET_OFF);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(radio->dev, "%s: POWER_SET fails: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__, r);
> + Â Â Â } else if (core->mode == WL1273_MODE_TX) {
> + Â Â Â Â Â Â Â int r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET, WL1273_PUPD_SET_OFF);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "%s: PUPD_SET fails: %d\n", __func__, r);
> + Â Â Â }
> +
> + Â Â Â if (core->pdata->disable) {
> + Â Â Â Â Â Â Â core->pdata->disable();
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "Back to reset\n");
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_start(struct wl1273_device *radio, int new_mode)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â struct wl1273_fm_platform_data *pdata = core->pdata;
> + Â Â Â struct device *dev = radio->dev;
> + Â Â Â int r = -EINVAL;
> +
> + Â Â Â if (pdata->enable && core->mode == WL1273_MODE_OFF) {
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "Out of reset\n");
> +
> + Â Â Â Â Â Â Â pdata->enable();
> + Â Â Â Â Â Â Â msleep(250);
> + Â Â Â }
> +
> + Â Â Â if (new_mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â u16 val = WL1273_POWER_SET_FM;
> +
> + Â Â Â Â Â Â Â if (radio->rds_on)
> + Â Â Â Â Â Â Â Â Â Â Â val |= WL1273_POWER_SET_RDS;
> +
> + Â Â Â Â Â Â Â /* If this fails try again */
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, val);
> + Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â msleep(100);
> +
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, val);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: POWER_SET fails\n", __func__);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto fail;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /* rds buffer configuration */
> + Â Â Â Â Â Â Â radio->wr_index = 0;
> + Â Â Â Â Â Â Â radio->rd_index = 0;
> +
> + Â Â Â } else if (new_mode == WL1273_MODE_TX) {
> + Â Â Â Â Â Â Â /* If this fails try again */
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET, WL1273_PUPD_SET_ON);
> + Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â msleep(100);
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_PUPD_SET_ON);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: PUPD_SET fails\n", __func__);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto fail;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â if (radio->rds_on)
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 1);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 0);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â dev_warn(dev, "%s: Illegal mode.\n", __func__);
> + Â Â Â }
> +
> + Â Â Â if (core->mode == WL1273_MODE_OFF) {
> + Â Â Â Â Â Â Â r = wl1273_fm_upload_firmware_patch(radio);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_warn(dev, "Firmware upload failed.\n");
> +
> + Â Â Â Â Â Â Â /*
> + Â Â Â Â Â Â Â Â* Sometimes the chip is in a wrong power state at this point.
> + Â Â Â Â Â Â Â Â* So we set the power once again.
> + Â Â Â Â Â Â Â Â*/
> + Â Â Â Â Â Â Â if (new_mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â Â Â Â Â u16 val = WL1273_POWER_SET_FM;
> +
> + Â Â Â Â Â Â Â Â Â Â Â if (radio->rds_on)
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â val |= WL1273_POWER_SET_RDS;
> +
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, val);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: POWER_SET fails\n", __func__);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto fail;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â } else if (new_mode == WL1273_MODE_TX) {
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_PUPD_SET_ON);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: PUPD_SET fails\n", __func__);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto fail;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â return 0;
> +fail:
> + Â Â Â if (pdata->disable)
> + Â Â Â Â Â Â Â pdata->disable();
> +
> + Â Â Â dev_dbg(dev, "%s: return: %d\n", __func__, r);
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_suspend(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â /* Cannot go from OFF to SUSPENDED */
> + Â Â Â if (core->mode == WL1273_MODE_RX)
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_POWER_SET_RETENTION);
> + Â Â Â else if (core->mode == WL1273_MODE_TX)
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_PUPD_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_PUPD_SET_RETENTION);
> + Â Â Â else
> + Â Â Â Â Â Â Â r = -EINVAL;
> +
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "%s: POWER_SET fails: %d\n", __func__, r);
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> +out:
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_set_mode(struct wl1273_device *radio, int mode)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â struct device *dev = radio->dev;
> + Â Â Â int old_mode;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(dev, "%s\n", __func__);
> + Â Â Â dev_dbg(dev, "Forbidden modes: 0x%02x\n", radio->forbidden);
> +
> + Â Â Â old_mode = core->mode;
> + Â Â Â if (mode & radio->forbidden) {
> + Â Â Â Â Â Â Â r = -EPERM;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â switch (mode) {
> + Â Â Â case WL1273_MODE_RX:
> + Â Â Â case WL1273_MODE_TX:
> + Â Â Â Â Â Â Â r = wl1273_fm_start(radio, mode);
> + Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Cannot start.\n", __func__);
> + Â Â Â Â Â Â Â Â Â Â Â wl1273_fm_stop(radio);
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â core->mode = mode;
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
> + Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "INT_MASK_SET fails.\n");
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â /* remember previous settings */
> + Â Â Â Â Â Â Â if (mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "set freq fails: %d.\n", r);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â Â Â Â Â r = core->set_volume(core, core->volume);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "set volume fails: %d.\n", r);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â Â Â Â Â dev_dbg(dev, "%s: Set vol: %d.\n", __func__,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->volume);
> + Â Â Â Â Â Â Â } else {
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_set_tx_freq(radio, radio->tx_frequency);
> + Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "set freq fails: %d.\n", r);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "%s: Set audio mode.\n", __func__);
> +
> + Â Â Â Â Â Â Â r = core->set_audio(core, core->audio_mode);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "Cannot set audio mode.\n");
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case WL1273_MODE_OFF:
> + Â Â Â Â Â Â Â r = wl1273_fm_stop(radio);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Off fails: %d\n", __func__, r);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â core->mode = WL1273_MODE_OFF;
> +
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case WL1273_MODE_SUSPENDED:
> + Â Â Â Â Â Â Â r = wl1273_fm_suspend(radio);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Suspend fails: %d\n", __func__, r);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â core->mode = WL1273_MODE_SUSPENDED;
> +
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â default:
> + Â Â Â Â Â Â Â dev_err(dev, "%s: Unknown mode: %d\n", __func__, mode);
> + Â Â Â Â Â Â Â r = -EINVAL;
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> +out:
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â core->mode = old_mode;
> +
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_set_seek(struct wl1273_device *radio,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned int wrap_around,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned int seek_upward,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â int level)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> + Â Â Â unsigned int dir = (seek_upward == 0) ? 0 : 1;
> + Â Â Â unsigned int f;
> +
> + Â Â Â f = radio->rx_frequency;
> + Â Â Â dev_dbg(radio->dev, "rx_frequency: %d\n", f);
> +
> + Â Â Â if (dir && f + radio->spacing <= radio->rangehigh)
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rx_freq(radio, f + radio->spacing);
> + Â Â Â else if (dir && wrap_around)
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rx_freq(radio, radio->rangelow);
> + Â Â Â else if (f - radio->spacing >= radio->rangelow)
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rx_freq(radio, f - radio->spacing);
> + Â Â Â else if (wrap_around)
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rx_freq(radio, radio->rangehigh);
> +
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (level < SCHAR_MIN || level > SCHAR_MAX)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â INIT_COMPLETION(radio->busy);
> + Â Â Â dev_dbg(radio->dev, "%s: BUSY\n", __func__);
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_SEARCH_LVL_SET, level);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_SEARCH_DIR_SET, dir);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET, TUNER_MODE_AUTO_SEEK);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
> + Â Â Â if (!(radio->irq_received & WL1273_BL_EVENT))
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â radio->irq_received &= ~WL1273_BL_EVENT;
> +
> + Â Â Â if (!wrap_around)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â /* Wrap around */
> + Â Â Â dev_dbg(radio->dev, "Wrap around in HW seek.\n");
> +
> + Â Â Â if (seek_upward)
> + Â Â Â Â Â Â Â f = radio->rangelow;
> + Â Â Â else
> + Â Â Â Â Â Â Â f = radio->rangehigh;
> +
> + Â Â Â r = wl1273_fm_set_rx_freq(radio, f);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â INIT_COMPLETION(radio->busy);
> + Â Â Â dev_dbg(radio->dev, "%s: BUSY\n", __func__);
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_TUNER_MODE_SET, TUNER_MODE_AUTO_SEEK);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â wait_for_completion_timeout(&radio->busy, msecs_to_jiffies(1000));
> +out:
> + Â Â Â dev_dbg(radio->dev, "%s: Err: %d\n", __func__, r);
> + Â Â Â return r;
> +}
> +
> +/**
> + * wl1273_fm_get_tx_ctune() - ÂGet the TX tuning capacitor value.
> + * @radio: Â Â Â Â Â Â Â Â Â Â A pointer to the device struct.
> + */
> +static unsigned int wl1273_fm_get_tx_ctune(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â struct device *dev = radio->dev;
> + Â Â Â u16 val;
> + Â Â Â int r;
> +
> + Â Â Â if (core->mode == WL1273_MODE_OFF ||
> + Â Â Â Â Â core->mode == WL1273_MODE_SUSPENDED)
> + Â Â Â Â Â Â Â return -EPERM;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_READ_FMANT_TUNE_VALUE, &val);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(dev, "%s: read error: %d\n", __func__, r);
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> +out:
> + Â Â Â return val;
> +}
> +
> +/**
> + * wl1273_fm_set_preemphasis() - Set the TX pre-emphasis value.
> + * @radio: Â Â Â Â Â Â Â Â Â Â ÂA pointer to the device struct.
> + * @preemphasis: Â Â Â Â Â Â Â ÂThe new pre-amphasis value.
> + *
> + * Possible pre-emphasis values are: V4L2_PREEMPHASIS_DISABLED,
> + * V4L2_PREEMPHASIS_50_uS and V4L2_PREEMPHASIS_75_uS.
> + */
> +static int wl1273_fm_set_preemphasis(struct wl1273_device *radio,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âunsigned int preemphasis)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r;
> + Â Â Â u16 em;
> +
> + Â Â Â if (core->mode == WL1273_MODE_OFF ||
> + Â Â Â Â Â core->mode == WL1273_MODE_SUSPENDED)
> + Â Â Â Â Â Â Â return -EPERM;
> +
> + Â Â Â mutex_lock(&core->lock);
> +
> + Â Â Â switch (preemphasis) {
> + Â Â Â case V4L2_PREEMPHASIS_DISABLED:
> + Â Â Â Â Â Â Â em = 1;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case V4L2_PREEMPHASIS_50_uS:
> + Â Â Â Â Â Â Â em = 0;
> + Â Â Â Â Â Â Â break;
> + Â Â Â case V4L2_PREEMPHASIS_75_uS:
> + Â Â Â Â Â Â Â em = 2;
> + Â Â Â Â Â Â Â break;
> + Â Â Â default:
> + Â Â Â Â Â Â Â r = -EINVAL;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_PREMPH_SET, em);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â radio->preemphasis = preemphasis;
> +
> +out:
> + Â Â Â mutex_unlock(&core->lock);
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_rds_on(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> + Â Â Â if (radio->rds_on)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_SET,
> + Â Â Â Â Â Â Â Â Â Â Â WL1273_POWER_SET_FM | WL1273_POWER_SET_RDS);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_err(radio->dev, "set freq fails: %d.\n", r);
> +out:
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_rds_off(struct wl1273_device *radio)
> +{
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r;
> +
> + Â Â Â if (!radio->rds_on)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â radio->irq_flags &= ~WL1273_RDS_EVENT;
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET, radio->irq_flags);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â /* stop rds reception */
> + Â Â Â cancel_delayed_work(&radio->work);
> +
> + Â Â Â /* Service pending read */
> + Â Â Â wake_up_interruptible(&radio->read_queue);
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â r = wl1273_fm_write_cmd(core, WL1273_POWER_SET, WL1273_POWER_SET_FM);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â r = wl1273_fm_set_rx_freq(radio, radio->rx_frequency);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_err(radio->dev, "set freq fails: %d.\n", r);
> +out:
> + Â Â Â dev_dbg(radio->dev, "%s: exiting...\n", __func__);
> +
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_set_rds(struct wl1273_device *radio, unsigned int new_mode)
> +{
> + Â Â Â int r = 0;
> + Â Â Â struct wl1273_core *core = radio->core;
> +
> + Â Â Â if (core->mode == WL1273_MODE_OFF ||
> + Â Â Â Â Â core->mode == WL1273_MODE_SUSPENDED)
> + Â Â Â Â Â Â Â return -EPERM;
> +
> + Â Â Â if (new_mode == WL1273_RDS_RESET) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_RDS_CNTRL_SET, 1);
> + Â Â Â Â Â Â Â return r;
> + Â Â Â }
> +
> + Â Â Â if (core->mode == WL1273_MODE_TX && new_mode == WL1273_RDS_OFF) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 0);
> + Â Â Â } else if (core->mode == WL1273_MODE_TX && new_mode == WL1273_RDS_ON) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_RDS_DATA_ENB, 1);
> + Â Â Â } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_RDS_OFF) {
> + Â Â Â Â Â Â Â r = wl1273_fm_rds_off(radio);
> + Â Â Â } else if (core->mode == WL1273_MODE_RX && new_mode == WL1273_RDS_ON) {
> + Â Â Â Â Â Â Â r = wl1273_fm_rds_on(radio);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "%s: Unknown mode: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â __func__, new_mode);
> + Â Â Â Â Â Â Â r = -EINVAL;
> + Â Â Â }
> +
> + Â Â Â if (!r)
> + Â Â Â Â Â Â Â radio->rds_on = (new_mode == WL1273_RDS_ON) ? true : false;
> +
> + Â Â Â return r;
> +}
> +
> +static ssize_t wl1273_fm_fops_write(struct file *file, const char __user *buf,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t count, loff_t *ppos)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â u16 val;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (radio->core->mode != WL1273_MODE_TX)
> + Â Â Â Â Â Â Â return count;
> +
> + Â Â Â if (radio->rds_users == 0) {
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: RDS not on.\n", __func__);
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> +
> + Â Â Â if (mutex_lock_interruptible(&radio->core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> + Â Â Â /*
> + Â Â Â Â* Multiple processes can open the device, but only
> + Â Â Â Â* one gets to write to it.
> + Â Â Â Â*/
> + Â Â Â if (radio->owner && radio->owner != file) {
> + Â Â Â Â Â Â Â r = -EBUSY;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> + Â Â Â radio->owner = file;
> +
> + Â Â Â /* Manual Mode */
> + Â Â Â if (count > 255)
> + Â Â Â Â Â Â Â val = 255;
> + Â Â Â else
> + Â Â Â Â Â Â Â val = count;
> +
> + Â Â Â wl1273_fm_write_cmd(radio->core, WL1273_RDS_CONFIG_DATA_SET, val);
> +
> + Â Â Â if (copy_from_user(radio->write_buf + 1, buf, val)) {
> + Â Â Â Â Â Â Â r = -EFAULT;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â dev_dbg(radio->dev, "Count: %d\n", val);
> + Â Â Â dev_dbg(radio->dev, "From user: \"%s\"\n", radio->write_buf);
> +
> + Â Â Â radio->write_buf[0] = WL1273_RDS_DATA_SET;
> + Â Â Â wl1273_fm_write_data(radio->core, radio->write_buf, val + 1);
> +
> + Â Â Â r = val;
> +out:
> + Â Â Â mutex_unlock(&radio->core->lock);
> +
> + Â Â Â return r;
> +}
> +
> +static unsigned int wl1273_fm_fops_poll(struct file *file,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct poll_table_struct *pts)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> +
> + Â Â Â if (radio->owner && radio->owner != file)
> + Â Â Â Â Â Â Â return -EBUSY;
> +
> + Â Â Â radio->owner = file;
> +
> + Â Â Â if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â poll_wait(file, &radio->read_queue, pts);
> +
> + Â Â Â Â Â Â Â if (radio->rd_index != radio->wr_index)
> + Â Â Â Â Â Â Â Â Â Â Â return POLLIN | POLLRDNORM;
> +
> + Â Â Â } else if (core->mode == WL1273_MODE_TX) {
> + Â Â Â Â Â Â Â return POLLOUT | POLLWRNORM;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_fops_open(struct file *file)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (core->mode == WL1273_MODE_RX && radio->rds_on &&
> + Â Â Â Â Â !radio->rds_users) {
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "%s: Mode: %d\n", __func__, core->mode);
> +
> + Â Â Â Â Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â Â Â Â Â radio->irq_flags |= WL1273_RDS_EVENT;
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â radio->irq_flags);
> + Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â mutex_unlock(&core->lock);
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â radio->rds_users++;
> +
> + Â Â Â Â Â Â Â mutex_unlock(&core->lock);
> + Â Â Â }
> +out:
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_fops_release(struct file *file)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (radio->rds_users > 0) {
> + Â Â Â Â Â Â Â radio->rds_users--;
> + Â Â Â Â Â Â Â if (radio->rds_users == 0) {
> + Â Â Â Â Â Â Â Â Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â Â Â Â Â Â Â Â Â radio->irq_flags &= ~WL1273_RDS_EVENT;
> +
> + Â Â Â Â Â Â Â Â Â Â Â if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_INT_MASK_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â radio->irq_flags);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mutex_unlock(&core->lock);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â Â Â Â Â mutex_unlock(&core->lock);
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â if (file == radio->owner)
> + Â Â Â Â Â Â Â radio->owner = NULL;
> +out:
> + Â Â Â return r;
> +}
> +
> +static ssize_t wl1273_fm_fops_read(struct file *file, char __user *buf,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âsize_t count, loff_t *ppos)
> +{
> + Â Â Â int r = 0;
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â unsigned int block_count = 0;
> + Â Â Â u16 val;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (radio->core->mode != WL1273_MODE_RX)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â if (radio->rds_users == 0) {
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: RDS not on.\n", __func__);
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â /*
> + Â Â Â Â* Multiple processes can open the device, but only
> + Â Â Â Â* one at a time gets read access.
> + Â Â Â Â*/
> + Â Â Â if (radio->owner && radio->owner != file) {
> + Â Â Â Â Â Â Â r = -EBUSY;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> + Â Â Â radio->owner = file;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "%s: Get RDS_SYNC fails.\n", __func__);
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â } else if (val == 0) {
> + Â Â Â Â Â Â Â dev_info(radio->dev, "RDS_SYNC: Not synchronized\n");
> + Â Â Â Â Â Â Â r = -ENODATA;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> + Â Â Â /* block if no new data available */
> + Â Â Â while (radio->wr_index == radio->rd_index) {
> + Â Â Â Â Â Â Â if (file->f_flags & O_NONBLOCK) {
> + Â Â Â Â Â Â Â Â Â Â Â r = -EWOULDBLOCK;
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "%s: Wait for RDS data.\n", __func__);
> + Â Â Â Â Â Â Â if (wait_event_interruptible(radio->read_queue,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âradio->wr_index !=
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âradio->rd_index) < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â r = -EINTR;
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> + Â Â Â }
> +
> + Â Â Â /* calculate block count from byte count */
> + Â Â Â count /= RDS_BLOCK_SIZE;
> +
> + Â Â Â /* copy RDS blocks from the internal buffer and to user buffer */
> + Â Â Â while (block_count < count) {
> + Â Â Â Â Â Â Â if (radio->rd_index == radio->wr_index)
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â /* always transfer complete RDS blocks */
> + Â Â Â Â Â Â Â if (copy_to_user(buf, &radio->buffer[radio->rd_index],
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂRDS_BLOCK_SIZE))
> + Â Â Â Â Â Â Â Â Â Â Â break;
> +
> + Â Â Â Â Â Â Â /* increment and wrap the read pointer */
> + Â Â Â Â Â Â Â radio->rd_index += RDS_BLOCK_SIZE;
> + Â Â Â Â Â Â Â if (radio->rd_index >= radio->buf_size)
> + Â Â Â Â Â Â Â Â Â Â Â radio->rd_index = 0;
> +
> + Â Â Â Â Â Â Â /* increment counters */
> + Â Â Â Â Â Â Â block_count++;
> + Â Â Â Â Â Â Â buf += RDS_BLOCK_SIZE;
> + Â Â Â Â Â Â Â r += RDS_BLOCK_SIZE;
> + Â Â Â }
> +
> +out:
> + Â Â Â dev_dbg(radio->dev, "%s: exit\n", __func__);
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return r;
> +}
> +
> +static const struct v4l2_file_operations wl1273_fops = {
> +    .owner     Â= THIS_MODULE,
> +    .read      = wl1273_fm_fops_read,
> +    .write     Â= wl1273_fm_fops_write,
> +    .poll      = wl1273_fm_fops_poll,
> +    .ioctl     Â= video_ioctl2,
> +    .open      = wl1273_fm_fops_open,
> +    .release    Â= wl1273_fm_fops_release,
> +};
> +
> +static int wl1273_fm_vidioc_querycap(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct v4l2_capability *capability)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â strlcpy(capability->driver, WL1273_FM_DRIVER_NAME,
> + Â Â Â Â Â Â Â sizeof(capability->driver));
> + Â Â Â strlcpy(capability->card, "Texas Instruments Wl1273 FM Radio",
> + Â Â Â Â Â Â Â sizeof(capability->card));
> + Â Â Â strlcpy(capability->bus_info, radio->bus_type,
> + Â Â Â Â Â Â Â sizeof(capability->bus_info));
> +
> + Â Â Â capability->capabilities = V4L2_CAP_HW_FREQ_SEEK |
> + Â Â Â Â Â Â Â V4L2_CAP_TUNER | V4L2_CAP_RADIO | V4L2_CAP_AUDIO |
> + Â Â Â Â Â Â Â V4L2_CAP_RDS_CAPTURE | V4L2_CAP_MODULATOR |
> + Â Â Â Â Â Â Â V4L2_CAP_RDS_OUTPUT;
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_vidioc_g_input(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned int *i)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â *i = 0;
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_vidioc_s_input(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned int i)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (i != 0)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â return 0;
> +}
> +
> +/**
> + * wl1273_fm_set_tx_power() - ÂSet the transmission power value.
> + * @core: Â Â Â Â Â Â Â Â Â Â ÂA pointer to the device struct.
> + * @power: Â Â Â Â Â Â Â Â Â Â The new power value.
> + */
> +static int wl1273_fm_set_tx_power(struct wl1273_device *radio, u16 power)
> +{
> + Â Â Â int r;
> +
> + Â Â Â if (radio->core->mode == WL1273_MODE_OFF ||
> + Â Â Â Â Â radio->core->mode == WL1273_MODE_SUSPENDED)
> + Â Â Â Â Â Â Â return -EPERM;
> +
> + Â Â Â mutex_lock(&radio->core->lock);
> +
> + Â Â Â /* Convert the dBuV value to chip presentation */
> + Â Â Â r = wl1273_fm_write_cmd(radio->core, WL1273_POWER_LEV_SET, 122 - power);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â radio->tx_power = power;
> +
> +out:
> + Â Â Â mutex_unlock(&radio->core->lock);
> + Â Â Â return r;
> +}
> +
> +#define WL1273_SPACING_50kHz  1
> +#define WL1273_SPACING_100kHz Â2
> +#define WL1273_SPACING_200kHz Â4
> +
> +static int wl1273_fm_tx_set_spacing(struct wl1273_device *radio,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â unsigned int spacing)
> +{
> + Â Â Â int r;
> +
> + Â Â Â if (spacing == 0) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_SPACING_100kHz);
> + Â Â Â Â Â Â Â radio->spacing = 100;
> + Â Â Â } else if (spacing - 50000 < 25000) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_SPACING_50kHz);
> + Â Â Â Â Â Â Â radio->spacing = 50;
> + Â Â Â } else if (spacing - 100000 < 50000) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_SPACING_100kHz);
> + Â Â Â Â Â Â Â radio->spacing = 100;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(radio->core, WL1273_SCAN_SPACING_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_SPACING_200kHz);
> + Â Â Â Â Â Â Â radio->spacing = 200;
> + Â Â Â }
> +
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
> +{
> + Â Â Â struct wl1273_device *radio = ctrl->priv;
> + Â Â Â struct wl1273_core *core = radio->core;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â switch (ctrl->id) {
> + Â Â Â case ÂV4L2_CID_TUNE_ANTENNA_CAPACITOR:
> + Â Â Â Â Â Â Â ctrl->val = wl1273_fm_get_tx_ctune(radio);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â default:
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â__func__, ctrl->id);
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return 0;
> +}
> +
> +#define WL1273_MUTE_SOFT_ENABLE Â Â(1 << 0)
> +#define WL1273_MUTE_AC Â Â Â Â Â Â (1 << 1)
> +#define WL1273_MUTE_HARD_LEFT Â Â Â(1 << 2)
> +#define WL1273_MUTE_HARD_RIGHT Â Â (1 << 3)
> +#define WL1273_MUTE_SOFT_FORCE Â Â (1 << 4)
> +
> +static inline struct wl1273_device *to_radio(struct v4l2_ctrl *ctrl)
> +{
> + Â Â Â return container_of(ctrl->handler, struct wl1273_device, ctrl_handler);
> +}
> +
> +static int wl1273_fm_vidioc_s_ctrl(struct v4l2_ctrl *ctrl)
> +{
> + Â Â Â struct wl1273_device *radio = to_radio(ctrl);
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â switch (ctrl->id) {
> + Â Â Â case V4L2_CID_AUDIO_MUTE:
> + Â Â Â Â Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â Â Â Â Â if (core->mode == WL1273_MODE_RX && ctrl->val)
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_MUTE_STATUS_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_MUTE_HARD_LEFT |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_MUTE_HARD_RIGHT);
> + Â Â Â Â Â Â Â else if (core->mode == WL1273_MODE_RX)
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_MUTE_STATUS_SET, 0x0);
> + Â Â Â Â Â Â Â else if (core->mode == WL1273_MODE_TX && ctrl->val)
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_MUTE, 1);
> + Â Â Â Â Â Â Â else if (core->mode == WL1273_MODE_TX)
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_MUTE, 0);
> +
> + Â Â Â Â Â Â Â mutex_unlock(&core->lock);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case V4L2_CID_AUDIO_VOLUME:
> + Â Â Â Â Â Â Â if (ctrl->val == 0)
> + Â Â Â Â Â Â Â Â Â Â Â r = wl1273_fm_set_mode(radio, WL1273_MODE_OFF);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â r = Âcore->set_volume(core, core->volume);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case V4L2_CID_TUNE_PREEMPHASIS:
> + Â Â Â Â Â Â Â r = wl1273_fm_set_preemphasis(radio, ctrl->val);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â case V4L2_CID_TUNE_POWER_LEVEL:
> + Â Â Â Â Â Â Â r = wl1273_fm_set_tx_power(radio, ctrl->val);
> + Â Â Â Â Â Â Â break;
> +
> + Â Â Â default:
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: Unknown IOCTL: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â__func__, ctrl->id);
> + Â Â Â Â Â Â Â break;
> + Â Â Â }
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_vidioc_g_audio(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_audio *audio)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (audio->index > 1)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â strlcpy(audio->name, "Radio", sizeof(audio->name));
> + Â Â Â audio->capability = V4L2_AUDCAP_STEREO;
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_vidioc_s_audio(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_audio *audio)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (audio->index != 0)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â return 0;
> +}
> +
> +#define WL1273_RDS_NOT_SYNCHRONIZED 0
> +#define WL1273_RDS_SYNCHRONIZED 1
> +
> +static int wl1273_fm_vidioc_g_tuner(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_tuner *tuner)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â u16 val;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (tuner->index > 0)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â strlcpy(tuner->name, WL1273_FM_DRIVER_NAME, sizeof(tuner->name));
> + Â Â Â tuner->type = V4L2_TUNER_RADIO;
> +
> + Â Â Â tuner->rangelow = WL1273_FREQ(WL1273_BAND_JAPAN_LOW);
> + Â Â Â tuner->rangehigh = WL1273_FREQ(WL1273_BAND_OTHER_HIGH);
> +
> + Â Â Â tuner->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_RDS |
> + Â Â Â Â Â Â Â V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS_BLOCK_IO;
> +
> + Â Â Â if (radio->stereo)
> + Â Â Â Â Â Â Â tuner->audmode = V4L2_TUNER_MODE_STEREO;
> + Â Â Â else
> + Â Â Â Â Â Â Â tuner->audmode = V4L2_TUNER_MODE_MONO;
> +
> + Â Â Â if (core->mode != WL1273_MODE_RX)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_STEREO_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (val == 1)
> + Â Â Â Â Â Â Â tuner->rxsubchans = V4L2_TUNER_SUB_STEREO;
> + Â Â Â else
> + Â Â Â Â Â Â Â tuner->rxsubchans = V4L2_TUNER_SUB_MONO;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_RSSI_LVL_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â tuner->signal = (s16) val;
> + Â Â Â dev_dbg(radio->dev, "Signal: %d\n", tuner->signal);
> +
> + Â Â Â tuner->afc = 0;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (val == WL1273_RDS_SYNCHRONIZED)
> + Â Â Â Â Â Â Â tuner->rxsubchans |= V4L2_TUNER_SUB_RDS;
> +out:
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_vidioc_s_tuner(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_tuner *tuner)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> + Â Â Â dev_dbg(radio->dev, "tuner->index: %d\n", tuner->index);
> + Â Â Â dev_dbg(radio->dev, "tuner->name: %s\n", tuner->name);
> + Â Â Â dev_dbg(radio->dev, "tuner->capability: 0x%04x\n", tuner->capability);
> + Â Â Â dev_dbg(radio->dev, "tuner->rxsubchans: 0x%04x\n", tuner->rxsubchans);
> + Â Â Â dev_dbg(radio->dev, "tuner->rangelow: %d\n", tuner->rangelow);
> + Â Â Â dev_dbg(radio->dev, "tuner->rangehigh: %d\n", tuner->rangehigh);
> +
> + Â Â Â if (tuner->index > 0)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â r = wl1273_fm_set_mode(radio, WL1273_MODE_RX);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (tuner->rxsubchans & V4L2_TUNER_SUB_RDS)
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rds(radio, WL1273_RDS_ON);
> + Â Â Â else
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rds(radio, WL1273_RDS_OFF);
> +
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: RDS fails: %d\n", __func__, r);
> +
> + Â Â Â if (tuner->audmode == V4L2_TUNER_MODE_MONO) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_MOST_MODE_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_RX_MONO);
> + Â Â Â Â Â Â Â if (r < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â__func__, r);
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â radio->stereo = false;
> + Â Â Â } else if (tuner->audmode == V4L2_TUNER_MODE_STEREO) {
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_MOST_MODE_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_RX_STEREO);
> + Â Â Â Â Â Â Â if (r < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_warn(radio->dev, "%s: MOST_MODE fails: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â__func__, r);
> + Â Â Â Â Â Â Â Â Â Â Â goto out;
> + Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â radio->stereo = true;
> + Â Â Â } else {
> + Â Â Â Â Â Â Â dev_err(radio->dev, "%s: tuner->audmode: %d\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â__func__, tuner->audmode);
> + Â Â Â Â Â Â Â r = -EINVAL;
> + Â Â Â Â Â Â Â goto out;
> + Â Â Â }
> +
> +out:
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_vidioc_g_frequency(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_frequency *freq)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â freq->type = V4L2_TUNER_RADIO;
> + Â Â Â freq->frequency = WL1273_FREQ(wl1273_fm_get_freq(radio));
> +
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_vidioc_s_frequency(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_frequency *freq)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(radio->dev, "%s: %d\n", __func__, freq->frequency);
> +
> + Â Â Â if (freq->type != V4L2_TUNER_RADIO) {
> + Â Â Â Â Â Â Â dev_dbg(radio->dev,
> + Â Â Â Â Â Â Â Â Â Â Â "freq->type != V4L2_TUNER_RADIO: %d\n", freq->type);
> + Â Â Â Â Â Â Â return -EINVAL;
> + Â Â Â }
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "freq: %d\n", freq->frequency);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rx_freq(radio,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_INV_FREQ(freq->frequency));
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â": set frequency failed with %d\n", r);
> + Â Â Â } else {
> + Â Â Â Â Â Â Â r = wl1273_fm_set_tx_freq(radio,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_INV_FREQ(freq->frequency));
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â": set frequency failed with %d\n", r);
> + Â Â Â }
> +
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â dev_dbg(radio->dev, "wl1273_vidioc_s_frequency: DONE\n");
> + Â Â Â return r;
> +}
> +
> +#define WL1273_DEFAULT_SEEK_LEVEL Â Â Â7
> +
> +static int wl1273_fm_vidioc_s_hw_freq_seek(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âstruct v4l2_hw_freq_seek *seek)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (seek->tuner != 0 || seek->type != V4L2_TUNER_RADIO)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â r = wl1273_fm_set_mode(radio, WL1273_MODE_RX);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â r = wl1273_fm_tx_set_spacing(radio, seek->spacing);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "HW seek failed: %d\n", r);
> +
> + Â Â Â r = wl1273_fm_set_seek(radio, seek->wrap_around, seek->seek_upward,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂWL1273_DEFAULT_SEEK_LEVEL);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_warn(radio->dev, "HW seek failed: %d\n", r);
> +
> +out:
> + Â Â Â mutex_unlock(&core->lock);
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_vidioc_s_modulator(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_modulator *modulator)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â int r = 0;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â if (modulator->index > 0)
> + Â Â Â Â Â Â Â return -EINVAL;
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â r = wl1273_fm_set_mode(radio, WL1273_MODE_TX);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (modulator->txsubchans & V4L2_TUNER_SUB_RDS)
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rds(radio, WL1273_RDS_ON);
> + Â Â Â else
> + Â Â Â Â Â Â Â r = wl1273_fm_set_rds(radio, WL1273_RDS_OFF);
> +
> + Â Â Â if (modulator->txsubchans & V4L2_TUNER_SUB_MONO)
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_MONO_SET, WL1273_TX_MONO);
> + Â Â Â else
> + Â Â Â Â Â Â Â r = wl1273_fm_write_cmd(core, WL1273_MONO_SET,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WL1273_RX_STEREO);
> + Â Â Â if (r < 0)
> + Â Â Â Â Â Â Â dev_warn(radio->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â Â"MONO_SET fails: %d\n", r);
> +out:
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return r;
> +}
> +
> +static int wl1273_fm_vidioc_g_modulator(struct file *file, void *priv,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â struct v4l2_modulator *modulator)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â u16 val;
> + Â Â Â int r;
> +
> + Â Â Â dev_dbg(radio->dev, "%s\n", __func__);
> +
> + Â Â Â strlcpy(modulator->name, WL1273_FM_DRIVER_NAME,
> + Â Â Â Â Â Â Â sizeof(modulator->name));
> +
> + Â Â Â modulator->rangelow = WL1273_FREQ(WL1273_BAND_JAPAN_LOW);
> + Â Â Â modulator->rangehigh = WL1273_FREQ(WL1273_BAND_OTHER_HIGH);
> +
> + Â Â Â modulator->capability = ÂV4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_RDS |
> + Â Â Â Â Â Â Â V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_RDS_BLOCK_IO;
> +
> + Â Â Â if (core->mode != WL1273_MODE_TX)
> + Â Â Â Â Â Â Â return 0;
> +
> + Â Â Â if (mutex_lock_interruptible(&core->lock))
> + Â Â Â Â Â Â Â return -EINTR;
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_MONO_SET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â goto out;
> +
> + Â Â Â if (val == WL1273_TX_STEREO)
> + Â Â Â Â Â Â Â modulator->txsubchans = V4L2_TUNER_SUB_STEREO;
> + Â Â Â else
> + Â Â Â Â Â Â Â modulator->txsubchans = V4L2_TUNER_SUB_MONO;
> +
> + Â Â Â if (radio->rds_on)
> + Â Â Â Â Â Â Â modulator->txsubchans |= V4L2_TUNER_SUB_RDS;
> +out:
> + Â Â Â mutex_unlock(&core->lock);
> +
> + Â Â Â return 0;
> +}
> +
> +static int wl1273_fm_vidioc_log_status(struct file *file, void *priv)
> +{
> + Â Â Â struct wl1273_device *radio = video_get_drvdata(video_devdata(file));
> + Â Â Â struct wl1273_core *core = radio->core;
> + Â Â Â struct device *dev = radio->dev;
> + Â Â Â u16 val;
> + Â Â Â int r;
> +
> + Â Â Â dev_info(dev, DRIVER_DESC);
> +
> + Â Â Â if (core->mode == WL1273_MODE_OFF) {
> + Â Â Â Â Â Â Â dev_info(dev, "Mode: Off\n");
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> +
> + Â Â Â if (core->mode == WL1273_MODE_SUSPENDED) {
> + Â Â Â Â Â Â Â dev_info(dev, "Mode: Suspended\n");
> + Â Â Â Â Â Â Â return 0;
> + Â Â Â }
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_ASIC_ID_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_err(dev, "%s: Get ASIC_ID fails.\n", __func__);
> + Â Â Â else
> + Â Â Â Â Â Â Â dev_info(dev, "ASIC_ID: 0x%04x\n", val);
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_ASIC_VER_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_err(dev, "%s: Get ASIC_VER fails.\n", __func__);
> + Â Â Â else
> + Â Â Â Â Â Â Â dev_info(dev, "ASIC Version: 0x%04x\n", val);
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_FIRM_VER_GET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_err(dev, "%s: Get FIRM_VER fails.\n", __func__);
> + Â Â Â else
> + Â Â Â Â Â Â Â dev_info(dev, "FW version: %d(0x%04x)\n", val, val);
> +
> + Â Â Â r = wl1273_fm_read_reg(core, WL1273_BAND_SET, &val);
> + Â Â Â if (r)
> + Â Â Â Â Â Â Â dev_err(dev, "%s: Get BAND fails.\n", __func__);
> + Â Â Â else
> + Â Â Â Â Â Â Â dev_info(dev, "BAND: %d\n", val);
> +
> + Â Â Â if (core->mode == WL1273_MODE_TX) {
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_PUPD_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get PUPD fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "PUPD: 0x%04x\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_CHANL_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get CHANL fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "Tx frequency: %dkHz\n", val*10);
> + Â Â Â } else if (core->mode == WL1273_MODE_RX) {
> + Â Â Â Â Â Â Â int bf = radio->rangelow;
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_FREQ_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get FREQ fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "RX Frequency: %dkHz\n", bf + val*50);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_MOST_MODE_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get MOST_MODE fails.\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__);
> + Â Â Â Â Â Â Â else if (val == 0)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "MOST_MODE: Stereo according to blend\n");
> + Â Â Â Â Â Â Â else if (val == 1)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "MOST_MODE: Force mono output\n");
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "MOST_MODE: Unexpected value: %d\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_MOST_BLEND_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get MOST_BLEND fails.\n", __func__);
> + Â Â Â Â Â Â Â else if (val == 0)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"MOST_BLEND: Switched blend & hysteresis.\n");
> + Â Â Â Â Â Â Â else if (val == 1)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "MOST_BLEND: Soft blend.\n");
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "MOST_BLEND: Unexpected val: %d\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_STEREO_GET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get STEREO fails.\n", __func__);
> + Â Â Â Â Â Â Â else if (val == 0)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "STEREO: Not detected\n");
> + Â Â Â Â Â Â Â else if (val == 1)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "STEREO: Detected\n");
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "STEREO: Unexpected value: %d\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_RSSI_LVL_GET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get RSSI_LVL fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "RX signal strength: %d\n", (s16) val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_POWER_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get POWER fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "POWER: 0x%04x\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_INT_MASK_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get INT_MASK fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "INT_MASK: 0x%04x\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_RDS_SYNC_GET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get RDS_SYNC fails.\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__);
> + Â Â Â Â Â Â Â else if (val == 0)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "RDS_SYNC: Not synchronized\n");
> +
> + Â Â Â Â Â Â Â else if (val == 1)
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "RDS_SYNC: Synchronized\n");
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "RDS_SYNC: Unexpected value: %d\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_I2S_MODE_CONFIG_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get I2S_MODE_CONFIG fails.\n",
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "I2S_MODE_CONFIG: 0x%04x\n", val);
> +
> + Â Â Â Â Â Â Â r = wl1273_fm_read_reg(core, WL1273_VOLUME_SET, &val);
> + Â Â Â Â Â Â Â if (r)
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "%s: Get VOLUME fails.\n", __func__);
> + Â Â Â Â Â Â Â else
> + Â Â Â Â Â Â Â Â Â Â Â dev_info(dev, "VOLUME: 0x%04x\n", val);
> + Â Â Â }
> +
> + Â Â Â return 0;
> +}
> +
> +static void wl1273_vdev_release(struct video_device *dev)
> +{
> +}
> +
> +static const struct v4l2_ctrl_ops wl1273_ctrl_ops = {
> + Â Â Â .s_ctrl = wl1273_fm_vidioc_s_ctrl,
> + Â Â Â .g_volatile_ctrl = wl1273_fm_g_volatile_ctrl,
> +};
> +
> +static const struct v4l2_ioctl_ops wl1273_ioctl_ops = {
> +    .vidioc_querycap    Â= wl1273_fm_vidioc_querycap,
> +    .vidioc_g_input     = wl1273_fm_vidioc_g_input,
> +    .vidioc_s_input     = wl1273_fm_vidioc_s_input,
> +    .vidioc_g_audio     = wl1273_fm_vidioc_g_audio,
> +    .vidioc_s_audio     = wl1273_fm_vidioc_s_audio,
> +    .vidioc_g_tuner     = wl1273_fm_vidioc_g_tuner,
> +    .vidioc_s_tuner     = wl1273_fm_vidioc_s_tuner,
> +    .vidioc_g_frequency   = wl1273_fm_vidioc_g_frequency,
> +    .vidioc_s_frequency   = wl1273_fm_vidioc_s_frequency,
> + Â Â Â .vidioc_s_hw_freq_seek Â= wl1273_fm_vidioc_s_hw_freq_seek,
> +    .vidioc_g_modulator   = wl1273_fm_vidioc_g_modulator,
> +    .vidioc_s_modulator   = wl1273_fm_vidioc_s_modulator,
> +    .vidioc_log_status   Â= wl1273_fm_vidioc_log_status,
> +};
> +
> +static struct video_device wl1273_viddev_template = {
> +    .fops          = &wl1273_fops,
> +    .ioctl_ops       Â= &wl1273_ioctl_ops,
> +    .name          = WL1273_FM_DRIVER_NAME,
> +    .release        Â= wl1273_vdev_release,
> +};
> +
> +static int wl1273_fm_radio_remove(struct platform_device *pdev)
> +{
> + Â Â Â struct wl1273_device *radio = platform_get_drvdata(pdev);
> + Â Â Â struct wl1273_core *core = radio->core;
> +
> + Â Â Â dev_info(&pdev->dev, "%s.\n", __func__);
> +
> + Â Â Â free_irq(core->client->irq, radio);
> + Â Â Â core->pdata->free_resources();
> +
> + Â Â Â v4l2_ctrl_handler_free(&radio->ctrl_handler);
> + Â Â Â video_unregister_device(&radio->videodev);
> + Â Â Â v4l2_device_unregister(&radio->v4l2dev);
> + Â Â Â kfree(radio->buffer);
> + Â Â Â kfree(radio->write_buf);
> + Â Â Â kfree(radio);
> +
> + Â Â Â return 0;
> +}
> +
> +static int __devinit wl1273_fm_radio_probe(struct platform_device *pdev)
> +{
> + Â Â Â struct wl1273_core **core = pdev->dev.platform_data;
> + Â Â Â struct wl1273_device *radio;
> + Â Â Â struct v4l2_ctrl *ctrl;
> + Â Â Â int r = 0;
> +
> + Â Â Â pr_debug("%s\n", __func__);
> +
> + Â Â Â if (!core) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "No platform data.\n");
> + Â Â Â Â Â Â Â r = -EINVAL;
> + Â Â Â Â Â Â Â goto pdata_err;
> + Â Â Â }
> +
> + Â Â Â radio = kzalloc(sizeof(*radio), GFP_KERNEL);
> + Â Â Â if (!radio) {
> + Â Â Â Â Â Â Â r = -ENOMEM;
> + Â Â Â Â Â Â Â goto pdata_err;
> + Â Â Â }
> +
> + Â Â Â /* RDS buffer allocation */
> + Â Â Â radio->buf_size = rds_buf * RDS_BLOCK_SIZE;
> + Â Â Â radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
> + Â Â Â if (!radio->buffer) {
> + Â Â Â Â Â Â Â pr_err("Cannot allocate memory for RDS buffer.\n");
> + Â Â Â Â Â Â Â r = -ENOMEM;
> + Â Â Â Â Â Â Â goto err_kmalloc;
> + Â Â Â }
> +
> + Â Â Â radio->core = *core;
> + Â Â Â radio->irq_flags = WL1273_IRQ_MASK;
> + Â Â Â radio->dev = &radio->core->client->dev;
> + Â Â Â radio->rds_on = false;
> + Â Â Â radio->core->mode = WL1273_MODE_OFF;
> + Â Â Â radio->tx_power = 118;
> + Â Â Â radio->core->audio_mode = WL1273_AUDIO_ANALOG;
> + Â Â Â radio->band = WL1273_BAND_OTHER;
> + Â Â Â radio->core->i2s_mode = WL1273_I2S_DEF_MODE;
> + Â Â Â radio->core->channel_number = 2;
> + Â Â Â radio->core->volume = WL1273_DEFAULT_VOLUME;
> + Â Â Â radio->rx_frequency = WL1273_BAND_OTHER_LOW;
> + Â Â Â radio->tx_frequency = WL1273_BAND_OTHER_HIGH;
> + Â Â Â radio->rangelow = WL1273_BAND_OTHER_LOW;
> + Â Â Â radio->rangehigh = WL1273_BAND_OTHER_HIGH;
> + Â Â Â radio->stereo = true;
> + Â Â Â radio->bus_type = "I2C";
> +
> + Â Â Â radio->core->write = wl1273_fm_write_cmd;
> + Â Â Â radio->core->set_audio = wl1273_fm_set_audio;
> + Â Â Â radio->core->set_volume = wl1273_fm_set_volume;
> +
> + Â Â Â if (radio->core->pdata->request_resources) {
> + Â Â Â Â Â Â Â r = radio->core->pdata->request_resources(radio->core->client);
> + Â Â Â Â Â Â Â if (r) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(radio->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ": Cannot get platform data\n");
> + Â Â Â Â Â Â Â Â Â Â Â goto err_resources;
> + Â Â Â Â Â Â Â }
> +
> + Â Â Â Â Â Â Â dev_dbg(radio->dev, "irq: %d\n", radio->core->client->irq);
> +
> + Â Â Â Â Â Â Â r = request_threaded_irq(radio->core->client->irq, NULL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âwl1273_fm_irq_thread_handler,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂIRQF_ONESHOT | IRQF_TRIGGER_FALLING,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"wl1273-fm", radio);
> + Â Â Â Â Â Â Â if (r < 0) {
> + Â Â Â Â Â Â Â Â Â Â Â dev_err(radio->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ": Unable to register IRQ handler: %d\n", r);
> + Â Â Â Â Â Â Â Â Â Â Â goto err_request_irq;
> + Â Â Â Â Â Â Â }
> + Â Â Â } else {
> + Â Â Â Â Â Â Â dev_err(radio->dev, WL1273_FM_DRIVER_NAME ": Core WL1273 IRQ"
> + Â Â Â Â Â Â Â Â Â Â Â " not configured");
> + Â Â Â Â Â Â Â r = -EINVAL;
> + Â Â Â Â Â Â Â goto err_resources;
> + Â Â Â }
> +
> + Â Â Â init_completion(&radio->busy);
> + Â Â Â init_waitqueue_head(&radio->read_queue);
> +
> + Â Â Â radio->write_buf = kmalloc(256, GFP_KERNEL);
> + Â Â Â if (!radio->write_buf) {
> + Â Â Â Â Â Â Â r = -ENOMEM;
> + Â Â Â Â Â Â Â goto write_buf_err;
> + Â Â Â }
> +
> + Â Â Â radio->dev = &pdev->dev;
> + Â Â Â radio->v4l2dev.ctrl_handler = &radio->ctrl_handler;
> + Â Â Â radio->rds_users = 0;
> +
> + Â Â Â r = v4l2_device_register(&pdev->dev, &radio->v4l2dev);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "Cannot register v4l2_device.\n");
> + Â Â Â Â Â Â Â goto device_register_err;
> + Â Â Â }
> +
> + Â Â Â /* V4L2 configuration */
> + Â Â Â memcpy(&radio->videodev, &wl1273_viddev_template,
> + Â Â Â Â Â Â Âsizeof(wl1273_viddev_template));
> +
> + Â Â Â radio->videodev.v4l2_dev = &radio->v4l2dev;
> +
> + Â Â Â v4l2_ctrl_handler_init(&radio->ctrl_handler, 6);
> +
> + Â Â Â /* add in ascending ID order */
> + Â Â Â v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
> + Â Â Â Â Â Â Â Â Â Â Â Â V4L2_CID_AUDIO_VOLUME, 0, WL1273_MAX_VOLUME, 1,
> + Â Â Â Â Â Â Â Â Â Â Â Â WL1273_DEFAULT_VOLUME);
> +
> + Â Â Â v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
> + Â Â Â Â Â Â Â Â Â Â Â Â V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
> +
> + Â Â Â v4l2_ctrl_new_std_menu(&radio->ctrl_handler, &wl1273_ctrl_ops,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂV4L2_CID_TUNE_PREEMPHASIS,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂV4L2_PREEMPHASIS_75_uS, 0x03,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂV4L2_PREEMPHASIS_50_uS);
> +
> + Â Â Â v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
> + Â Â Â Â Â Â Â Â Â Â Â Â V4L2_CID_TUNE_POWER_LEVEL, 91, 122, 1, 118);
> +
> + Â Â Â ctrl = v4l2_ctrl_new_std(&radio->ctrl_handler, &wl1273_ctrl_ops,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ÂV4L2_CID_TUNE_ANTENNA_CAPACITOR,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â0, 255, 1, 255);
> + Â Â Â if (ctrl)
> + Â Â Â Â Â Â Â ctrl->is_volatile = 1;
> +
> + Â Â Â if (radio->ctrl_handler.error) {
> + Â Â Â Â Â Â Â r = radio->ctrl_handler.error;
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, "Ctrl handler error: %d\n", r);
> + Â Â Â Â Â Â Â goto handler_init_err;
> + Â Â Â }
> +
> + Â Â Â video_set_drvdata(&radio->videodev, radio);
> + Â Â Â platform_set_drvdata(pdev, radio);
> +
> + Â Â Â /* register video device */
> + Â Â Â r = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
> + Â Â Â if (r) {
> + Â Â Â Â Â Â Â dev_err(&pdev->dev, WL1273_FM_DRIVER_NAME
> + Â Â Â Â Â Â Â Â Â Â Â ": Could not register video device\n");
> + Â Â Â Â Â Â Â goto handler_init_err;
> + Â Â Â }
> +
> + Â Â Â return 0;
> +
> +handler_init_err:
> + Â Â Â v4l2_ctrl_handler_free(&radio->ctrl_handler);
> + Â Â Â v4l2_device_unregister(&radio->v4l2dev);
> +device_register_err:
> + Â Â Â kfree(radio->write_buf);
> +write_buf_err:
> + Â Â Â free_irq(radio->core->client->irq, radio);
> +err_request_irq:
> + Â Â Â radio->core->pdata->free_resources();
> +err_resources:
> + Â Â Â kfree(radio->buffer);
> +err_kmalloc:
> + Â Â Â kfree(radio);
> +pdata_err:
> + Â Â Â return r;
> +}
> +
> +MODULE_ALIAS("platform:wl1273_fm_radio");
> +
> +static struct platform_driver wl1273_fm_radio_driver = {
> +    .probe     Â= wl1273_fm_radio_probe,
> +    .remove     = __devexit_p(wl1273_fm_radio_remove),
> +    .driver     = {
> +        .name  = "wl1273_fm_radio",
> + Â Â Â Â Â Â Â .owner Â= THIS_MODULE,
> + Â Â Â },
> +};
> +
> +static int __init wl1273_fm_module_init(void)
> +{
> + Â Â Â pr_info("%s\n", __func__);
> + Â Â Â return platform_driver_register(&wl1273_fm_radio_driver);
> +}
> +module_init(wl1273_fm_module_init);
> +
> +static void __exit wl1273_fm_module_exit(void)
> +{
> + Â Â Â flush_scheduled_work();
> + Â Â Â platform_driver_unregister(&wl1273_fm_radio_driver);
> + Â Â Â pr_info(DRIVER_DESC ", Exiting.\n");
> +}
> +module_exit(wl1273_fm_module_exit);
> +
> +MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@xxxxxxxxx>");
> +MODULE_DESCRIPTION(DRIVER_DESC);
> +MODULE_LICENSE("GPL");
> --
> 1.6.1.3
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at Âhttp://vger.kernel.org/majordomo-info.html
>



-- 
Regards,
Raja.
ÿô.nlj·Ÿ®‰­†+%ŠË±é¥Šwÿº{.nlj·¥Š{±þg‰¯â^n‡r¡öë¨è&£ûz¹Þúzf£¢·hšˆ§~†­†Ûÿÿïÿ‘ê_èæ+v‰¨þ)ßø

[Index of Archives]     [Linux Input]     [Video for Linux]     [Gstreamer Embedded]     [Mplayer Users]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux