Skip to content

Commit

Permalink
media: si470x: allow build both USB and I2C at the same time
Browse files Browse the repository at this point in the history
Currently, either USB or I2C is built. Change it to allow
having both enabled at the same time.

The main reason is that COMPILE_TEST all[yes/mod]builds will
now contain all drivers under drivers/media.

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
  • Loading branch information
mchehab committed Apr 17, 2018
1 parent 84fc727 commit 5875798
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 47 deletions.
4 changes: 0 additions & 4 deletions drivers/media/radio/Kconfig
Expand Up @@ -15,10 +15,6 @@ if RADIO_ADAPTERS && VIDEO_V4L2
config RADIO_TEA575X
tristate

config RADIO_SI470X
bool "Silicon Labs Si470x FM Radio Receiver support"
depends on VIDEO_V4L2

source "drivers/media/radio/si470x/Kconfig"

config RADIO_SI4713
Expand Down
16 changes: 15 additions & 1 deletion drivers/media/radio/si470x/Kconfig
@@ -1,3 +1,17 @@
config RADIO_SI470X
tristate "Silicon Labs Si470x FM Radio Receiver support"
depends on VIDEO_V4L2
---help---
This is a driver for devices with the Silicon Labs SI470x
chip (either via USB or I2C buses).

Say Y here if you want to connect this type of radio to your
computer's USB port or if it is used by some other driver
via I2C bus.

To compile this driver as a module, choose M here: the
module will be called radio-si470x-common.

config USB_SI470X
tristate "Silicon Labs Si470x FM Radio Receiver support with USB"
depends on USB && RADIO_SI470X
Expand Down Expand Up @@ -25,7 +39,7 @@ config USB_SI470X

config I2C_SI470X
tristate "Silicon Labs Si470x FM Radio Receiver support with I2C"
depends on I2C && RADIO_SI470X && !USB_SI470X
depends on I2C && RADIO_SI470X
---help---
This is a driver for I2C devices with the Silicon Labs SI470x
chip.
Expand Down
8 changes: 3 additions & 5 deletions drivers/media/radio/si470x/Makefile
Expand Up @@ -2,8 +2,6 @@
# Makefile for radios with Silicon Labs Si470x FM Radio Receivers
#

radio-usb-si470x-objs := radio-si470x-usb.o radio-si470x-common.o
radio-i2c-si470x-objs := radio-si470x-i2c.o radio-si470x-common.o

obj-$(CONFIG_USB_SI470X) += radio-usb-si470x.o
obj-$(CONFIG_I2C_SI470X) += radio-i2c-si470x.o
obj-$(CONFIG_RADIO_SI470X) := radio-si470x-common.o
obj-$(CONFIG_USB_SI470X) += radio-si470x-usb.o
obj-$(CONFIG_I2C_SI470X) += radio-si470x-i2c.o
70 changes: 51 additions & 19 deletions drivers/media/radio/si470x/radio-si470x-common.c
Expand Up @@ -110,8 +110,6 @@
/* kernel includes */
#include "radio-si470x.h"



/**************************************************************************
* Module Parameters
**************************************************************************/
Expand Down Expand Up @@ -195,7 +193,7 @@ static int si470x_set_band(struct si470x_device *radio, int band)
radio->band = band;
radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_BAND;
radio->registers[SYSCONFIG2] |= radio->band << 6;
return si470x_set_register(radio, SYSCONFIG2);
return radio->set_register(radio, SYSCONFIG2);
}

/*
Expand All @@ -207,7 +205,7 @@ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)
unsigned long time_left;
bool timed_out = false;

retval = si470x_get_register(radio, POWERCFG);
retval = radio->get_register(radio, POWERCFG);
if (retval)
return retval;

Expand All @@ -219,7 +217,7 @@ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)
/* start tuning */
radio->registers[CHANNEL] &= ~CHANNEL_CHAN;
radio->registers[CHANNEL] |= CHANNEL_TUNE | chan;
retval = si470x_set_register(radio, CHANNEL);
retval = radio->set_register(radio, CHANNEL);
if (retval < 0)
goto done;

Expand All @@ -238,7 +236,7 @@ static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)

/* stop tuning */
radio->registers[CHANNEL] &= ~CHANNEL_TUNE;
retval = si470x_set_register(radio, CHANNEL);
retval = radio->set_register(radio, CHANNEL);

done:
return retval;
Expand Down Expand Up @@ -272,7 +270,7 @@ static int si470x_get_freq(struct si470x_device *radio, unsigned int *freq)
int chan, retval;

/* read channel */
retval = si470x_get_register(radio, READCHAN);
retval = radio->get_register(radio, READCHAN);
chan = radio->registers[READCHAN] & READCHAN_READCHAN;

/* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
Expand All @@ -296,6 +294,7 @@ int si470x_set_freq(struct si470x_device *radio, unsigned int freq)

return si470x_set_chan(radio, chan);
}
EXPORT_SYMBOL_GPL(si470x_set_freq);


/*
Expand Down Expand Up @@ -343,7 +342,7 @@ static int si470x_set_seek(struct si470x_device *radio,
radio->registers[POWERCFG] |= POWERCFG_SEEKUP;
else
radio->registers[POWERCFG] &= ~POWERCFG_SEEKUP;
retval = si470x_set_register(radio, POWERCFG);
retval = radio->set_register(radio, POWERCFG);
if (retval < 0)
return retval;

Expand All @@ -362,7 +361,7 @@ static int si470x_set_seek(struct si470x_device *radio,

/* stop seeking */
radio->registers[POWERCFG] &= ~POWERCFG_SEEK;
retval = si470x_set_register(radio, POWERCFG);
retval = radio->set_register(radio, POWERCFG);

/* try again, if timed out */
if (retval == 0 && timed_out)
Expand All @@ -381,7 +380,7 @@ int si470x_start(struct si470x_device *radio)
/* powercfg */
radio->registers[POWERCFG] =
POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM;
retval = si470x_set_register(radio, POWERCFG);
retval = radio->set_register(radio, POWERCFG);
if (retval < 0)
goto done;

Expand All @@ -392,7 +391,7 @@ int si470x_start(struct si470x_device *radio)
radio->registers[SYSCONFIG1] |= SYSCONFIG1_GPIO2_INT;
if (de)
radio->registers[SYSCONFIG1] |= SYSCONFIG1_DE;
retval = si470x_set_register(radio, SYSCONFIG1);
retval = radio->set_register(radio, SYSCONFIG1);
if (retval < 0)
goto done;

Expand All @@ -402,7 +401,7 @@ int si470x_start(struct si470x_device *radio)
((radio->band << 6) & SYSCONFIG2_BAND) |/* BAND */
((space << 4) & SYSCONFIG2_SPACE) | /* SPACE */
15; /* VOLUME (max) */
retval = si470x_set_register(radio, SYSCONFIG2);
retval = radio->set_register(radio, SYSCONFIG2);
if (retval < 0)
goto done;

Expand All @@ -413,6 +412,7 @@ int si470x_start(struct si470x_device *radio)
done:
return retval;
}
EXPORT_SYMBOL_GPL(si470x_start);


/*
Expand All @@ -424,19 +424,20 @@ int si470x_stop(struct si470x_device *radio)

/* sysconfig 1 */
radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
retval = si470x_set_register(radio, SYSCONFIG1);
retval = radio->set_register(radio, SYSCONFIG1);
if (retval < 0)
goto done;

/* powercfg */
radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
/* POWERCFG_ENABLE has to automatically go low */
radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE;
retval = si470x_set_register(radio, POWERCFG);
retval = radio->set_register(radio, POWERCFG);

done:
return retval;
}
EXPORT_SYMBOL_GPL(si470x_stop);


/*
Expand All @@ -448,7 +449,7 @@ static int si470x_rds_on(struct si470x_device *radio)

/* sysconfig 1 */
radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS;
retval = si470x_set_register(radio, SYSCONFIG1);
retval = radio->set_register(radio, SYSCONFIG1);
if (retval < 0)
radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;

Expand Down Expand Up @@ -542,6 +543,25 @@ static __poll_t si470x_fops_poll(struct file *file,
}


static int si470x_fops_open(struct file *file)
{
struct si470x_device *radio = video_drvdata(file);

return radio->fops_open(file);
}


/*
* si470x_fops_release - file release
*/
static int si470x_fops_release(struct file *file)
{
struct si470x_device *radio = video_drvdata(file);

return radio->fops_release(file);
}


/*
* si470x_fops - file operations interface
*/
Expand Down Expand Up @@ -570,13 +590,13 @@ static int si470x_s_ctrl(struct v4l2_ctrl *ctrl)
case V4L2_CID_AUDIO_VOLUME:
radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME;
radio->registers[SYSCONFIG2] |= ctrl->val;
return si470x_set_register(radio, SYSCONFIG2);
return radio->set_register(radio, SYSCONFIG2);
case V4L2_CID_AUDIO_MUTE:
if (ctrl->val)
radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
else
radio->registers[POWERCFG] |= POWERCFG_DMUTE;
return si470x_set_register(radio, POWERCFG);
return radio->set_register(radio, POWERCFG);
default:
return -EINVAL;
}
Expand All @@ -596,7 +616,7 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv,
return -EINVAL;

if (!radio->status_rssi_auto_update) {
retval = si470x_get_register(radio, STATUSRSSI);
retval = radio->get_register(radio, STATUSRSSI);
if (retval < 0)
return retval;
}
Expand Down Expand Up @@ -665,7 +685,7 @@ static int si470x_vidioc_s_tuner(struct file *file, void *priv,
break;
}

return si470x_set_register(radio, POWERCFG);
return radio->set_register(radio, POWERCFG);
}


Expand Down Expand Up @@ -742,6 +762,15 @@ static int si470x_vidioc_enum_freq_bands(struct file *file, void *priv,
const struct v4l2_ctrl_ops si470x_ctrl_ops = {
.s_ctrl = si470x_s_ctrl,
};
EXPORT_SYMBOL_GPL(si470x_ctrl_ops);

static int si470x_vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *capability)
{
struct si470x_device *radio = video_drvdata(file);

return radio->vidioc_querycap(file, priv, capability);
};

/*
* si470x_ioctl_ops - video device ioctl operations
Expand All @@ -768,3 +797,6 @@ const struct video_device si470x_viddev_template = {
.release = video_device_release_empty,
.ioctl_ops = &si470x_ioctl_ops,
};
EXPORT_SYMBOL_GPL(si470x_viddev_template);

MODULE_LICENSE("GPL");
18 changes: 12 additions & 6 deletions drivers/media/radio/si470x/radio-si470x-i2c.c
Expand Up @@ -89,7 +89,7 @@ MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
/*
* si470x_get_register - read register
*/
int si470x_get_register(struct si470x_device *radio, int regnr)
static int si470x_get_register(struct si470x_device *radio, int regnr)
{
u16 buf[READ_REG_NUM];
struct i2c_msg msgs[1] = {
Expand All @@ -113,7 +113,7 @@ int si470x_get_register(struct si470x_device *radio, int regnr)
/*
* si470x_set_register - write register
*/
int si470x_set_register(struct si470x_device *radio, int regnr)
static int si470x_set_register(struct si470x_device *radio, int regnr)
{
int i;
u16 buf[WRITE_REG_NUM];
Expand Down Expand Up @@ -174,7 +174,7 @@ static int si470x_get_all_registers(struct si470x_device *radio)
/*
* si470x_fops_open - file open
*/
int si470x_fops_open(struct file *file)
static int si470x_fops_open(struct file *file)
{
struct si470x_device *radio = video_drvdata(file);
int retval = v4l2_fh_open(file);
Expand Down Expand Up @@ -206,7 +206,7 @@ int si470x_fops_open(struct file *file)
/*
* si470x_fops_release - file release
*/
int si470x_fops_release(struct file *file)
static int si470x_fops_release(struct file *file)
{
struct si470x_device *radio = video_drvdata(file);

Expand All @@ -226,8 +226,8 @@ int si470x_fops_release(struct file *file)
/*
* si470x_vidioc_querycap - query device capabilities
*/
int si470x_vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *capability)
static int si470x_vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *capability)
{
strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
Expand Down Expand Up @@ -361,6 +361,12 @@ static int si470x_i2c_probe(struct i2c_client *client,
mutex_init(&radio->lock);
init_completion(&radio->completion);

radio->get_register = si470x_get_register;
radio->set_register = si470x_set_register;
radio->fops_open = si470x_fops_open;
radio->fops_release = si470x_fops_release;
radio->vidioc_querycap = si470x_vidioc_querycap;

retval = v4l2_device_register(&client->dev, &radio->v4l2_dev);
if (retval < 0) {
dev_err(&client->dev, "couldn't register v4l2_device\n");
Expand Down
18 changes: 12 additions & 6 deletions drivers/media/radio/si470x/radio-si470x-usb.c
Expand Up @@ -250,7 +250,7 @@ static int si470x_set_report(struct si470x_device *radio, void *buf, int size)
/*
* si470x_get_register - read register
*/
int si470x_get_register(struct si470x_device *radio, int regnr)
static int si470x_get_register(struct si470x_device *radio, int regnr)
{
int retval;

Expand All @@ -268,7 +268,7 @@ int si470x_get_register(struct si470x_device *radio, int regnr)
/*
* si470x_set_register - write register
*/
int si470x_set_register(struct si470x_device *radio, int regnr)
static int si470x_set_register(struct si470x_device *radio, int regnr)
{
int retval;

Expand Down Expand Up @@ -482,12 +482,12 @@ static void si470x_int_in_callback(struct urb *urb)
}


int si470x_fops_open(struct file *file)
static int si470x_fops_open(struct file *file)
{
return v4l2_fh_open(file);
}

int si470x_fops_release(struct file *file)
static int si470x_fops_release(struct file *file)
{
return v4l2_fh_release(file);
}
Expand All @@ -514,8 +514,8 @@ static void si470x_usb_release(struct v4l2_device *v4l2_dev)
/*
* si470x_vidioc_querycap - query device capabilities
*/
int si470x_vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *capability)
static int si470x_vidioc_querycap(struct file *file, void *priv,
struct v4l2_capability *capability)
{
struct si470x_device *radio = video_drvdata(file);

Expand Down Expand Up @@ -598,6 +598,12 @@ static int si470x_usb_driver_probe(struct usb_interface *intf,
mutex_init(&radio->lock);
init_completion(&radio->completion);

radio->get_register = si470x_get_register;
radio->set_register = si470x_set_register;
radio->fops_open = si470x_fops_open;
radio->fops_release = si470x_fops_release;
radio->vidioc_querycap = si470x_vidioc_querycap;

iface_desc = intf->cur_altsetting;

/* Set up interrupt endpoint information. */
Expand Down

0 comments on commit 5875798

Please sign in to comment.