linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Review Patch 0/9] si4713 usb device driver
@ 2013-10-15 15:24 Dinesh Ram
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                   ` (2 more replies)
  0 siblings, 3 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086

Hello Eduardo,

In this patch series, I have addressed the comments by you
concerning my last patch series.
In the resulting patches, I have corrected most of the
style issues and adding of comments. However, some warnings
given out by checkpatch.pl (mostly complaing about lines longer
than 80 characters) are still there because I saw that code readibility
suffers by breaking up those lines.

Also Hans has contributed patches 8 and 9 in this patch series
which address the issues of the handling of unknown regulators,
which have apparently changed since 3.10. Hans has tested it and the
driver loads again.

Let me know when you are able to test it again.

Kind regards,
Dinesh Ram
dinesh.ram@cern.ch
dinesh.ram086@gmail.com


^ permalink raw reply	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory
  2013-10-15 15:24 [Review Patch 0/9] si4713 usb device driver Dinesh Ram
@ 2013-10-15 15:24 ` Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used Dinesh Ram
                     ` (8 more replies)
  2013-10-15 17:37 ` [Review Patch 0/9] si4713 usb device driver edubezval
  2013-11-18 14:31 ` edubezval
  2 siblings, 9 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram

Added a new si4713 directory which will contain all si4713 related files.
Also updated Makefile and Kconfig

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 drivers/media/radio/Kconfig                        |   29 +-
 drivers/media/radio/Makefile                       |    3 +-
 drivers/media/radio/radio-si4713.c                 |  246 ----
 drivers/media/radio/si4713-i2c.c                   | 1532 --------------------
 drivers/media/radio/si4713-i2c.h                   |  238 ---
 drivers/media/radio/si4713/Kconfig                 |   25 +
 drivers/media/radio/si4713/Makefile                |    7 +
 drivers/media/radio/si4713/radio-platform-si4713.c |  246 ++++
 drivers/media/radio/si4713/si4713.c                | 1532 ++++++++++++++++++++
 drivers/media/radio/si4713/si4713.h                |  238 +++
 10 files changed, 2055 insertions(+), 2041 deletions(-)
 delete mode 100644 drivers/media/radio/radio-si4713.c
 delete mode 100644 drivers/media/radio/si4713-i2c.c
 delete mode 100644 drivers/media/radio/si4713-i2c.h
 create mode 100644 drivers/media/radio/si4713/Kconfig
 create mode 100644 drivers/media/radio/si4713/Makefile
 create mode 100644 drivers/media/radio/si4713/radio-platform-si4713.c
 create mode 100644 drivers/media/radio/si4713/si4713.c
 create mode 100644 drivers/media/radio/si4713/si4713.h

diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 6ecdc39..57ea9c3 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -15,6 +15,12 @@ if RADIO_ADAPTERS && VIDEO_V4L2
 config RADIO_TEA575X
 	tristate
 
+config RADIO_SI4713
+	tristate "Silicon Labs Si4713 FM Radio with RDS Transmitter support"
+	depends on VIDEO_V4L2
+
+source "drivers/media/radio/si4713/Kconfig"
+
 config RADIO_SI470X
 	bool "Silicon Labs Si470x FM Radio Receiver support"
 	depends on VIDEO_V4L2
@@ -113,29 +119,6 @@ config RADIO_SHARK2
 	  To compile this driver as a module, choose M here: the
 	  module will be called radio-shark2.
 
-config I2C_SI4713
-	tristate "I2C driver for Silicon Labs Si4713 device"
-	depends on I2C && VIDEO_V4L2
-	---help---
-	  Say Y here if you want support to Si4713 I2C device.
-	  This device driver supports only i2c bus.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called si4713.
-
-config RADIO_SI4713
-	tristate "Silicon Labs Si4713 FM Radio Transmitter support"
-	depends on I2C && VIDEO_V4L2
-	select I2C_SI4713
-	---help---
-	  Say Y here if you want support to Si4713 FM Radio Transmitter.
-	  This device can transmit audio through FM. It can transmit
-	  RDS and RBDS signals as well. This module is the v4l2 radio
-	  interface for the i2c driver of this device.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called radio-si4713.
-
 config USB_KEENE
 	tristate "Keene FM Transmitter USB support"
 	depends on USB && VIDEO_V4L2
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index 3b64560..eb1a3a0 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -17,12 +17,11 @@ obj-$(CONFIG_RADIO_RTRACK) += radio-aimslab.o
 obj-$(CONFIG_RADIO_ZOLTRIX) += radio-zoltrix.o
 obj-$(CONFIG_RADIO_GEMTEK) += radio-gemtek.o
 obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
-obj-$(CONFIG_I2C_SI4713) += si4713-i2c.o
-obj-$(CONFIG_RADIO_SI4713) += radio-si4713.o
 obj-$(CONFIG_RADIO_SI476X) += radio-si476x.o
 obj-$(CONFIG_RADIO_MIROPCM20) += radio-miropcm20.o
 obj-$(CONFIG_USB_DSBR) += dsbr100.o
 obj-$(CONFIG_RADIO_SI470X) += si470x/
+obj-$(CONFIG_RADIO_SI4713) += si4713/
 obj-$(CONFIG_USB_MR800) += radio-mr800.o
 obj-$(CONFIG_USB_KEENE) += radio-keene.o
 obj-$(CONFIG_USB_MA901) += radio-ma901.o
diff --git a/drivers/media/radio/radio-si4713.c b/drivers/media/radio/radio-si4713.c
deleted file mode 100644
index ba4cfc9..0000000
--- a/drivers/media/radio/radio-si4713.c
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * drivers/media/radio/radio-si4713.c
- *
- * Platform Driver for Silicon Labs Si4713 FM Radio Transmitter:
- *
- * Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
- * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * 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
- */
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <linux/i2c.h>
-#include <linux/videodev2.h>
-#include <linux/slab.h>
-#include <media/v4l2-device.h>
-#include <media/v4l2-common.h>
-#include <media/v4l2-ioctl.h>
-#include <media/v4l2-fh.h>
-#include <media/v4l2-ctrls.h>
-#include <media/v4l2-event.h>
-#include <media/radio-si4713.h>
-
-/* module parameters */
-static int radio_nr = -1;	/* radio device minor (-1 ==> auto assign) */
-module_param(radio_nr, int, 0);
-MODULE_PARM_DESC(radio_nr,
-		 "Minor number for radio device (-1 ==> auto assign)");
-
-MODULE_LICENSE("GPL v2");
-MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
-MODULE_DESCRIPTION("Platform driver for Si4713 FM Radio Transmitter");
-MODULE_VERSION("0.0.1");
-MODULE_ALIAS("platform:radio-si4713");
-
-/* Driver state struct */
-struct radio_si4713_device {
-	struct v4l2_device		v4l2_dev;
-	struct video_device		radio_dev;
-	struct mutex lock;
-};
-
-/* radio_si4713_fops - file operations interface */
-static const struct v4l2_file_operations radio_si4713_fops = {
-	.owner		= THIS_MODULE,
-	.open = v4l2_fh_open,
-	.release = v4l2_fh_release,
-	.poll = v4l2_ctrl_poll,
-	/* Note: locking is done at the subdev level in the i2c driver. */
-	.unlocked_ioctl	= video_ioctl2,
-};
-
-/* Video4Linux Interface */
-
-/* radio_si4713_querycap - query device capabilities */
-static int radio_si4713_querycap(struct file *file, void *priv,
-					struct v4l2_capability *capability)
-{
-	strlcpy(capability->driver, "radio-si4713", sizeof(capability->driver));
-	strlcpy(capability->card, "Silicon Labs Si4713 Modulator",
-		sizeof(capability->card));
-	strlcpy(capability->bus_info, "platform:radio-si4713",
-		sizeof(capability->bus_info));
-	capability->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
-	capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
-
-	return 0;
-}
-
-/*
- * v4l2 ioctl call backs.
- * we are just a wrapper for v4l2_sub_devs.
- */
-static inline struct v4l2_device *get_v4l2_dev(struct file *file)
-{
-	return &((struct radio_si4713_device *)video_drvdata(file))->v4l2_dev;
-}
-
-static int radio_si4713_g_modulator(struct file *file, void *p,
-				    struct v4l2_modulator *vm)
-{
-	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
-					  g_modulator, vm);
-}
-
-static int radio_si4713_s_modulator(struct file *file, void *p,
-				    const struct v4l2_modulator *vm)
-{
-	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
-					  s_modulator, vm);
-}
-
-static int radio_si4713_g_frequency(struct file *file, void *p,
-				    struct v4l2_frequency *vf)
-{
-	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
-					  g_frequency, vf);
-}
-
-static int radio_si4713_s_frequency(struct file *file, void *p,
-				    const struct v4l2_frequency *vf)
-{
-	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
-					  s_frequency, vf);
-}
-
-static long radio_si4713_default(struct file *file, void *p,
-				 bool valid_prio, unsigned int cmd, void *arg)
-{
-	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
-					  ioctl, cmd, arg);
-}
-
-static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
-	.vidioc_querycap	= radio_si4713_querycap,
-	.vidioc_g_modulator	= radio_si4713_g_modulator,
-	.vidioc_s_modulator	= radio_si4713_s_modulator,
-	.vidioc_g_frequency	= radio_si4713_g_frequency,
-	.vidioc_s_frequency	= radio_si4713_s_frequency,
-	.vidioc_log_status      = v4l2_ctrl_log_status,
-	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
-	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
-	.vidioc_default		= radio_si4713_default,
-};
-
-/* radio_si4713_vdev_template - video device interface */
-static struct video_device radio_si4713_vdev_template = {
-	.fops			= &radio_si4713_fops,
-	.name			= "radio-si4713",
-	.release		= video_device_release_empty,
-	.ioctl_ops		= &radio_si4713_ioctl_ops,
-	.vfl_dir		= VFL_DIR_TX,
-};
-
-/* Platform driver interface */
-/* radio_si4713_pdriver_probe - probe for the device */
-static int radio_si4713_pdriver_probe(struct platform_device *pdev)
-{
-	struct radio_si4713_platform_data *pdata = pdev->dev.platform_data;
-	struct radio_si4713_device *rsdev;
-	struct i2c_adapter *adapter;
-	struct v4l2_subdev *sd;
-	int rval = 0;
-
-	if (!pdata) {
-		dev_err(&pdev->dev, "Cannot proceed without platform data.\n");
-		rval = -EINVAL;
-		goto exit;
-	}
-
-	rsdev = devm_kzalloc(&pdev->dev, sizeof(*rsdev), GFP_KERNEL);
-	if (!rsdev) {
-		dev_err(&pdev->dev, "Failed to alloc video device.\n");
-		rval = -ENOMEM;
-		goto exit;
-	}
-	mutex_init(&rsdev->lock);
-
-	rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev);
-	if (rval) {
-		dev_err(&pdev->dev, "Failed to register v4l2 device.\n");
-		goto exit;
-	}
-
-	adapter = i2c_get_adapter(pdata->i2c_bus);
-	if (!adapter) {
-		dev_err(&pdev->dev, "Cannot get i2c adapter %d\n",
-			pdata->i2c_bus);
-		rval = -ENODEV;
-		goto unregister_v4l2_dev;
-	}
-
-	sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter,
-				       pdata->subdev_board_info, NULL);
-	if (!sd) {
-		dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n");
-		rval = -ENODEV;
-		goto put_adapter;
-	}
-
-	rsdev->radio_dev = radio_si4713_vdev_template;
-	rsdev->radio_dev.v4l2_dev = &rsdev->v4l2_dev;
-	rsdev->radio_dev.ctrl_handler = sd->ctrl_handler;
-	set_bit(V4L2_FL_USE_FH_PRIO, &rsdev->radio_dev.flags);
-	/* Serialize all access to the si4713 */
-	rsdev->radio_dev.lock = &rsdev->lock;
-	video_set_drvdata(&rsdev->radio_dev, rsdev);
-	if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
-		dev_err(&pdev->dev, "Could not register video device.\n");
-		rval = -EIO;
-		goto put_adapter;
-	}
-	dev_info(&pdev->dev, "New device successfully probed\n");
-
-	goto exit;
-
-put_adapter:
-	i2c_put_adapter(adapter);
-unregister_v4l2_dev:
-	v4l2_device_unregister(&rsdev->v4l2_dev);
-exit:
-	return rval;
-}
-
-/* radio_si4713_pdriver_remove - remove the device */
-static int radio_si4713_pdriver_remove(struct platform_device *pdev)
-{
-	struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
-	struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next,
-					    struct v4l2_subdev, list);
-	struct i2c_client *client = v4l2_get_subdevdata(sd);
-	struct radio_si4713_device *rsdev;
-
-	rsdev = container_of(v4l2_dev, struct radio_si4713_device, v4l2_dev);
-	video_unregister_device(&rsdev->radio_dev);
-	i2c_put_adapter(client->adapter);
-	v4l2_device_unregister(&rsdev->v4l2_dev);
-
-	return 0;
-}
-
-static struct platform_driver radio_si4713_pdriver = {
-	.driver		= {
-		.name	= "radio-si4713",
-		.owner	= THIS_MODULE,
-	},
-	.probe		= radio_si4713_pdriver_probe,
-	.remove         = radio_si4713_pdriver_remove,
-};
-
-module_platform_driver(radio_si4713_pdriver);
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713-i2c.c
deleted file mode 100644
index fe16088..0000000
--- a/drivers/media/radio/si4713-i2c.c
+++ /dev/null
@@ -1,1532 +0,0 @@
-/*
- * drivers/media/radio/si4713-i2c.c
- *
- * Silicon Labs Si4713 FM Radio Transmitter I2C commands.
- *
- * Copyright (c) 2009 Nokia Corporation
- * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * 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
- */
-
-#include <linux/completion.h>
-#include <linux/delay.h>
-#include <linux/interrupt.h>
-#include <linux/i2c.h>
-#include <linux/slab.h>
-#include <linux/gpio.h>
-#include <linux/regulator/consumer.h>
-#include <linux/module.h>
-#include <media/v4l2-device.h>
-#include <media/v4l2-ioctl.h>
-#include <media/v4l2-common.h>
-
-#include "si4713-i2c.h"
-
-/* module parameters */
-static int debug;
-module_param(debug, int, S_IRUGO | S_IWUSR);
-MODULE_PARM_DESC(debug, "Debug level (0 - 2)");
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
-MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
-MODULE_VERSION("0.0.1");
-
-static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
-	"vio",
-	"vdd",
-};
-
-#define DEFAULT_RDS_PI			0x00
-#define DEFAULT_RDS_PTY			0x00
-#define DEFAULT_RDS_DEVIATION		0x00C8
-#define DEFAULT_RDS_PS_REPEAT_COUNT	0x0003
-#define DEFAULT_LIMITER_RTIME		0x1392
-#define DEFAULT_LIMITER_DEV		0x102CA
-#define DEFAULT_PILOT_FREQUENCY 	0x4A38
-#define DEFAULT_PILOT_DEVIATION		0x1A5E
-#define DEFAULT_ACOMP_ATIME		0x0000
-#define DEFAULT_ACOMP_RTIME		0xF4240L
-#define DEFAULT_ACOMP_GAIN		0x0F
-#define DEFAULT_ACOMP_THRESHOLD 	(-0x28)
-#define DEFAULT_MUTE			0x01
-#define DEFAULT_POWER_LEVEL		88
-#define DEFAULT_FREQUENCY		8800
-#define DEFAULT_PREEMPHASIS		FMPE_EU
-#define DEFAULT_TUNE_RNL		0xFF
-
-#define to_si4713_device(sd)	container_of(sd, struct si4713_device, sd)
-
-/* frequency domain transformation (using times 10 to avoid floats) */
-#define FREQDEV_UNIT	100000
-#define FREQV4L2_MULTI	625
-#define si4713_to_v4l2(f)	((f * FREQDEV_UNIT) / FREQV4L2_MULTI)
-#define v4l2_to_si4713(f)	((f * FREQV4L2_MULTI) / FREQDEV_UNIT)
-#define FREQ_RANGE_LOW			7600
-#define FREQ_RANGE_HIGH			10800
-
-#define MAX_ARGS 7
-
-#define RDS_BLOCK			8
-#define RDS_BLOCK_CLEAR			0x03
-#define RDS_BLOCK_LOAD			0x04
-#define RDS_RADIOTEXT_2A		0x20
-#define RDS_RADIOTEXT_BLK_SIZE		4
-#define RDS_RADIOTEXT_INDEX_MAX		0x0F
-#define RDS_CARRIAGE_RETURN		0x0D
-
-#define rds_ps_nblocks(len)	((len / RDS_BLOCK) + (len % RDS_BLOCK ? 1 : 0))
-
-#define get_status_bit(p, b, m)	(((p) & (m)) >> (b))
-#define set_bits(p, v, b, m)	(((p) & ~(m)) | ((v) << (b)))
-
-#define ATTACK_TIME_UNIT	500
-
-#define POWER_OFF			0x00
-#define POWER_ON			0x01
-
-#define msb(x)                  ((u8)((u16) x >> 8))
-#define lsb(x)                  ((u8)((u16) x &  0x00FF))
-#define compose_u16(msb, lsb)	(((u16)msb << 8) | lsb)
-#define check_command_failed(status)	(!(status & SI4713_CTS) || \
-					(status & SI4713_ERR))
-/* mute definition */
-#define set_mute(p)	((p & 1) | ((p & 1) << 1));
-
-#ifdef DEBUG
-#define DBG_BUFFER(device, message, buffer, size)			\
-	{								\
-		int i;							\
-		char str[(size)*5];					\
-		for (i = 0; i < size; i++)				\
-			sprintf(str + i * 5, " 0x%02x", buffer[i]);	\
-		v4l2_dbg(2, debug, device, "%s:%s\n", message, str);	\
-	}
-#else
-#define DBG_BUFFER(device, message, buffer, size)
-#endif
-
-/*
- * Values for limiter release time (sorted by second column)
- *	device	release
- *	value	time (us)
- */
-static long limiter_times[] = {
-	2000,	250,
-	1000,	500,
-	510,	1000,
-	255,	2000,
-	170,	3000,
-	127,	4020,
-	102,	5010,
-	85,	6020,
-	73,	7010,
-	64,	7990,
-	57,	8970,
-	51,	10030,
-	25,	20470,
-	17,	30110,
-	13,	39380,
-	10,	51190,
-	8,	63690,
-	7,	73140,
-	6,	85330,
-	5,	102390,
-};
-
-/*
- * Values for audio compression release time (sorted by second column)
- *	device	release
- *	value	time (us)
- */
-static unsigned long acomp_rtimes[] = {
-	0,	100000,
-	1,	200000,
-	2,	350000,
-	3,	525000,
-	4,	1000000,
-};
-
-/*
- * Values for preemphasis (sorted by second column)
- *	device	preemphasis
- *	value	value (v4l2)
- */
-static unsigned long preemphasis_values[] = {
-	FMPE_DISABLED,	V4L2_PREEMPHASIS_DISABLED,
-	FMPE_EU,	V4L2_PREEMPHASIS_50_uS,
-	FMPE_USA,	V4L2_PREEMPHASIS_75_uS,
-};
-
-static int usecs_to_dev(unsigned long usecs, unsigned long const array[],
-			int size)
-{
-	int i;
-	int rval = -EINVAL;
-
-	for (i = 0; i < size / 2; i++)
-		if (array[(i * 2) + 1] >= usecs) {
-			rval = array[i * 2];
-			break;
-		}
-
-	return rval;
-}
-
-/* si4713_handler: IRQ handler, just complete work */
-static irqreturn_t si4713_handler(int irq, void *dev)
-{
-	struct si4713_device *sdev = dev;
-
-	v4l2_dbg(2, debug, &sdev->sd,
-			"%s: sending signal to completion work.\n", __func__);
-	complete(&sdev->work);
-
-	return IRQ_HANDLED;
-}
-
-/*
- * si4713_send_command - sends a command to si4713 and waits its response
- * @sdev: si4713_device structure for the device we are communicating
- * @command: command id
- * @args: command arguments we are sending (up to 7)
- * @argn: actual size of @args
- * @response: buffer to place the expected response from the device (up to 15)
- * @respn: actual size of @response
- * @usecs: amount of time to wait before reading the response (in usecs)
- */
-static int si4713_send_command(struct si4713_device *sdev, const u8 command,
-				const u8 args[], const int argn,
-				u8 response[], const int respn, const int usecs)
-{
-	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
-	u8 data1[MAX_ARGS + 1];
-	int err;
-
-	if (!client->adapter)
-		return -ENODEV;
-
-	/* First send the command and its arguments */
-	data1[0] = command;
-	memcpy(data1 + 1, args, argn);
-	DBG_BUFFER(&sdev->sd, "Parameters", data1, argn + 1);
-
-	err = i2c_master_send(client, data1, argn + 1);
-	if (err != argn + 1) {
-		v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
-			command);
-		return (err > 0) ? -EIO : err;
-	}
-
-	/* Wait response from interrupt */
-	if (!wait_for_completion_timeout(&sdev->work,
-				usecs_to_jiffies(usecs) + 1))
-		v4l2_warn(&sdev->sd,
-				"(%s) Device took too much time to answer.\n",
-				__func__);
-
-	/* Then get the response */
-	err = i2c_master_recv(client, response, respn);
-	if (err != respn) {
-		v4l2_err(&sdev->sd,
-			"Error while reading response for command 0x%02x\n",
-			command);
-		return (err > 0) ? -EIO : err;
-	}
-
-	DBG_BUFFER(&sdev->sd, "Response", response, respn);
-	if (check_command_failed(response[0]))
-		return -EBUSY;
-
-	return 0;
-}
-
-/*
- * si4713_read_property - reads a si4713 property
- * @sdev: si4713_device structure for the device we are communicating
- * @prop: property identification number
- * @pv: property value to be returned on success
- */
-static int si4713_read_property(struct si4713_device *sdev, u16 prop, u32 *pv)
-{
-	int err;
-	u8 val[SI4713_GET_PROP_NRESP];
-	/*
-	 * 	.First byte = 0
-	 * 	.Second byte = property's MSB
-	 * 	.Third byte = property's LSB
-	 */
-	const u8 args[SI4713_GET_PROP_NARGS] = {
-		0x00,
-		msb(prop),
-		lsb(prop),
-	};
-
-	err = si4713_send_command(sdev, SI4713_CMD_GET_PROPERTY,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		return err;
-
-	*pv = compose_u16(val[2], val[3]);
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: property=0x%02x value=0x%02x status=0x%02x\n",
-			__func__, prop, *pv, val[0]);
-
-	return err;
-}
-
-/*
- * si4713_write_property - modifies a si4713 property
- * @sdev: si4713_device structure for the device we are communicating
- * @prop: property identification number
- * @val: new value for that property
- */
-static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
-{
-	int rval;
-	u8 resp[SI4713_SET_PROP_NRESP];
-	/*
-	 * 	.First byte = 0
-	 * 	.Second byte = property's MSB
-	 * 	.Third byte = property's LSB
-	 * 	.Fourth byte = value's MSB
-	 * 	.Fifth byte = value's LSB
-	 */
-	const u8 args[SI4713_SET_PROP_NARGS] = {
-		0x00,
-		msb(prop),
-		lsb(prop),
-		msb(val),
-		lsb(val),
-	};
-
-	rval = si4713_send_command(sdev, SI4713_CMD_SET_PROPERTY,
-					args, ARRAY_SIZE(args),
-					resp, ARRAY_SIZE(resp),
-					DEFAULT_TIMEOUT);
-
-	if (rval < 0)
-		return rval;
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: property=0x%02x value=0x%02x status=0x%02x\n",
-			__func__, prop, val, resp[0]);
-
-	/*
-	 * As there is no command response for SET_PROPERTY,
-	 * wait Tcomp time to finish before proceed, in order
-	 * to have property properly set.
-	 */
-	msleep(TIMEOUT_SET_PROPERTY);
-
-	return rval;
-}
-
-/*
- * si4713_powerup - Powers the device up
- * @sdev: si4713_device structure for the device we are communicating
- */
-static int si4713_powerup(struct si4713_device *sdev)
-{
-	int err;
-	u8 resp[SI4713_PWUP_NRESP];
-	/*
-	 * 	.First byte = Enabled interrupts and boot function
-	 * 	.Second byte = Input operation mode
-	 */
-	const u8 args[SI4713_PWUP_NARGS] = {
-		SI4713_PWUP_CTSIEN | SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
-		SI4713_PWUP_OPMOD_ANALOG,
-	};
-
-	if (sdev->power_state)
-		return 0;
-
-	err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
-				    sdev->supplies);
-	if (err) {
-		v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
-		return err;
-	}
-	if (gpio_is_valid(sdev->gpio_reset)) {
-		udelay(50);
-		gpio_set_value(sdev->gpio_reset, 1);
-	}
-
-	err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
-					args, ARRAY_SIZE(args),
-					resp, ARRAY_SIZE(resp),
-					TIMEOUT_POWER_UP);
-
-	if (!err) {
-		v4l2_dbg(1, debug, &sdev->sd, "Powerup response: 0x%02x\n",
-				resp[0]);
-		v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
-		sdev->power_state = POWER_ON;
-
-		err = si4713_write_property(sdev, SI4713_GPO_IEN,
-						SI4713_STC_INT | SI4713_CTS);
-	} else {
-		if (gpio_is_valid(sdev->gpio_reset))
-			gpio_set_value(sdev->gpio_reset, 0);
-		err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
-					     sdev->supplies);
-		if (err)
-			v4l2_err(&sdev->sd,
-				 "Failed to disable supplies: %d\n", err);
-	}
-
-	return err;
-}
-
-/*
- * si4713_powerdown - Powers the device down
- * @sdev: si4713_device structure for the device we are communicating
- */
-static int si4713_powerdown(struct si4713_device *sdev)
-{
-	int err;
-	u8 resp[SI4713_PWDN_NRESP];
-
-	if (!sdev->power_state)
-		return 0;
-
-	err = si4713_send_command(sdev, SI4713_CMD_POWER_DOWN,
-					NULL, 0,
-					resp, ARRAY_SIZE(resp),
-					DEFAULT_TIMEOUT);
-
-	if (!err) {
-		v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n",
-				resp[0]);
-		v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
-		if (gpio_is_valid(sdev->gpio_reset))
-			gpio_set_value(sdev->gpio_reset, 0);
-		err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
-					     sdev->supplies);
-		if (err)
-			v4l2_err(&sdev->sd,
-				 "Failed to disable supplies: %d\n", err);
-		sdev->power_state = POWER_OFF;
-	}
-
-	return err;
-}
-
-/*
- * si4713_checkrev - Checks if we are treating a device with the correct rev.
- * @sdev: si4713_device structure for the device we are communicating
- */
-static int si4713_checkrev(struct si4713_device *sdev)
-{
-	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
-	int rval;
-	u8 resp[SI4713_GETREV_NRESP];
-
-	rval = si4713_send_command(sdev, SI4713_CMD_GET_REV,
-					NULL, 0,
-					resp, ARRAY_SIZE(resp),
-					DEFAULT_TIMEOUT);
-
-	if (rval < 0)
-		return rval;
-
-	if (resp[1] == SI4713_PRODUCT_NUMBER) {
-		v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
-				client->addr << 1, client->adapter->name);
-	} else {
-		v4l2_err(&sdev->sd, "Invalid product number\n");
-		rval = -EINVAL;
-	}
-	return rval;
-}
-
-/*
- * si4713_wait_stc - Waits STC interrupt and clears status bits. Useful
- *		     for TX_TUNE_POWER, TX_TUNE_FREQ and TX_TUNE_MEAS
- * @sdev: si4713_device structure for the device we are communicating
- * @usecs: timeout to wait for STC interrupt signal
- */
-static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
-{
-	int err;
-	u8 resp[SI4713_GET_STATUS_NRESP];
-
-	/* Wait response from STC interrupt */
-	if (!wait_for_completion_timeout(&sdev->work,
-			usecs_to_jiffies(usecs) + 1))
-		v4l2_warn(&sdev->sd,
-			"%s: device took too much time to answer (%d usec).\n",
-				__func__, usecs);
-
-	/* Clear status bits */
-	err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
-					NULL, 0,
-					resp, ARRAY_SIZE(resp),
-					DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		goto exit;
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: status bits: 0x%02x\n", __func__, resp[0]);
-
-	if (!(resp[0] & SI4713_STC_INT))
-		err = -EIO;
-
-exit:
-	return err;
-}
-
-/*
- * si4713_tx_tune_freq - Sets the state of the RF carrier and sets the tuning
- * 			frequency between 76 and 108 MHz in 10 kHz units and
- * 			steps of 50 kHz.
- * @sdev: si4713_device structure for the device we are communicating
- * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
- */
-static int si4713_tx_tune_freq(struct si4713_device *sdev, u16 frequency)
-{
-	int err;
-	u8 val[SI4713_TXFREQ_NRESP];
-	/*
-	 * 	.First byte = 0
-	 * 	.Second byte = frequency's MSB
-	 * 	.Third byte = frequency's LSB
-	 */
-	const u8 args[SI4713_TXFREQ_NARGS] = {
-		0x00,
-		msb(frequency),
-		lsb(frequency),
-	};
-
-	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_FREQ,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		return err;
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: frequency=0x%02x status=0x%02x\n", __func__,
-			frequency, val[0]);
-
-	err = si4713_wait_stc(sdev, TIMEOUT_TX_TUNE);
-	if (err < 0)
-		return err;
-
-	return compose_u16(args[1], args[2]);
-}
-
-/*
- * si4713_tx_tune_power - Sets the RF voltage level between 88 and 115 dBuV in
- * 			1 dB units. A value of 0x00 indicates off. The command
- * 			also sets the antenna tuning capacitance. A value of 0
- * 			indicates autotuning, and a value of 1 - 191 indicates
- * 			a manual override, which results in a tuning
- * 			capacitance of 0.25 pF x @antcap.
- * @sdev: si4713_device structure for the device we are communicating
- * @power: tuning power (88 - 115 dBuV, unit/step 1 dB)
- * @antcap: value of antenna tuning capacitor (0 - 191)
- */
-static int si4713_tx_tune_power(struct si4713_device *sdev, u8 power,
-				u8 antcap)
-{
-	int err;
-	u8 val[SI4713_TXPWR_NRESP];
-	/*
-	 * 	.First byte = 0
-	 * 	.Second byte = 0
-	 * 	.Third byte = power
-	 * 	.Fourth byte = antcap
-	 */
-	const u8 args[SI4713_TXPWR_NARGS] = {
-		0x00,
-		0x00,
-		power,
-		antcap,
-	};
-
-	if (((power > 0) && (power < SI4713_MIN_POWER)) ||
-		power > SI4713_MAX_POWER || antcap > SI4713_MAX_ANTCAP)
-		return -EDOM;
-
-	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_POWER,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		return err;
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: power=0x%02x antcap=0x%02x status=0x%02x\n",
-			__func__, power, antcap, val[0]);
-
-	return si4713_wait_stc(sdev, TIMEOUT_TX_TUNE_POWER);
-}
-
-/*
- * si4713_tx_tune_measure - Enters receive mode and measures the received noise
- * 			level in units of dBuV on the selected frequency.
- * 			The Frequency must be between 76 and 108 MHz in 10 kHz
- * 			units and steps of 50 kHz. The command also sets the
- * 			antenna	tuning capacitance. A value of 0 means
- * 			autotuning, and a value of 1 to 191 indicates manual
- * 			override.
- * @sdev: si4713_device structure for the device we are communicating
- * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
- * @antcap: value of antenna tuning capacitor (0 - 191)
- */
-static int si4713_tx_tune_measure(struct si4713_device *sdev, u16 frequency,
-					u8 antcap)
-{
-	int err;
-	u8 val[SI4713_TXMEA_NRESP];
-	/*
-	 * 	.First byte = 0
-	 * 	.Second byte = frequency's MSB
-	 * 	.Third byte = frequency's LSB
-	 * 	.Fourth byte = antcap
-	 */
-	const u8 args[SI4713_TXMEA_NARGS] = {
-		0x00,
-		msb(frequency),
-		lsb(frequency),
-		antcap,
-	};
-
-	sdev->tune_rnl = DEFAULT_TUNE_RNL;
-
-	if (antcap > SI4713_MAX_ANTCAP)
-		return -EDOM;
-
-	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_MEASURE,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		return err;
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: frequency=0x%02x antcap=0x%02x status=0x%02x\n",
-			__func__, frequency, antcap, val[0]);
-
-	return si4713_wait_stc(sdev, TIMEOUT_TX_TUNE);
-}
-
-/*
- * si4713_tx_tune_status- Returns the status of the tx_tune_freq, tx_tune_mea or
- * 			tx_tune_power commands. This command return the current
- * 			frequency, output voltage in dBuV, the antenna tunning
- * 			capacitance value and the received noise level. The
- * 			command also clears the stcint interrupt bit when the
- * 			first bit of its arguments is high.
- * @sdev: si4713_device structure for the device we are communicating
- * @intack: 0x01 to clear the seek/tune complete interrupt status indicator.
- * @frequency: returned frequency
- * @power: returned power
- * @antcap: returned antenna capacitance
- * @noise: returned noise level
- */
-static int si4713_tx_tune_status(struct si4713_device *sdev, u8 intack,
-					u16 *frequency,	u8 *power,
-					u8 *antcap, u8 *noise)
-{
-	int err;
-	u8 val[SI4713_TXSTATUS_NRESP];
-	/*
-	 * 	.First byte = intack bit
-	 */
-	const u8 args[SI4713_TXSTATUS_NARGS] = {
-		intack & SI4713_INTACK_MASK,
-	};
-
-	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_STATUS,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (!err) {
-		v4l2_dbg(1, debug, &sdev->sd,
-			"%s: status=0x%02x\n", __func__, val[0]);
-		*frequency = compose_u16(val[2], val[3]);
-		sdev->frequency = *frequency;
-		*power = val[5];
-		*antcap = val[6];
-		*noise = val[7];
-		v4l2_dbg(1, debug, &sdev->sd, "%s: response: %d x 10 kHz "
-				"(power %d, antcap %d, rnl %d)\n", __func__,
-				*frequency, *power, *antcap, *noise);
-	}
-
-	return err;
-}
-
-/*
- * si4713_tx_rds_buff - Loads the RDS group buffer FIFO or circular buffer.
- * @sdev: si4713_device structure for the device we are communicating
- * @mode: the buffer operation mode.
- * @rdsb: RDS Block B
- * @rdsc: RDS Block C
- * @rdsd: RDS Block D
- * @cbleft: returns the number of available circular buffer blocks minus the
- *          number of used circular buffer blocks.
- */
-static int si4713_tx_rds_buff(struct si4713_device *sdev, u8 mode, u16 rdsb,
-				u16 rdsc, u16 rdsd, s8 *cbleft)
-{
-	int err;
-	u8 val[SI4713_RDSBUFF_NRESP];
-
-	const u8 args[SI4713_RDSBUFF_NARGS] = {
-		mode & SI4713_RDSBUFF_MODE_MASK,
-		msb(rdsb),
-		lsb(rdsb),
-		msb(rdsc),
-		lsb(rdsc),
-		msb(rdsd),
-		lsb(rdsd),
-	};
-
-	err = si4713_send_command(sdev, SI4713_CMD_TX_RDS_BUFF,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (!err) {
-		v4l2_dbg(1, debug, &sdev->sd,
-			"%s: status=0x%02x\n", __func__, val[0]);
-		*cbleft = (s8)val[2] - val[3];
-		v4l2_dbg(1, debug, &sdev->sd, "%s: response: interrupts"
-				" 0x%02x cb avail: %d cb used %d fifo avail"
-				" %d fifo used %d\n", __func__, val[1],
-				val[2], val[3], val[4], val[5]);
-	}
-
-	return err;
-}
-
-/*
- * si4713_tx_rds_ps - Loads the program service buffer.
- * @sdev: si4713_device structure for the device we are communicating
- * @psid: program service id to be loaded.
- * @pschar: assumed 4 size char array to be loaded into the program service
- */
-static int si4713_tx_rds_ps(struct si4713_device *sdev, u8 psid,
-				unsigned char *pschar)
-{
-	int err;
-	u8 val[SI4713_RDSPS_NRESP];
-
-	const u8 args[SI4713_RDSPS_NARGS] = {
-		psid & SI4713_RDSPS_PSID_MASK,
-		pschar[0],
-		pschar[1],
-		pschar[2],
-		pschar[3],
-	};
-
-	err = si4713_send_command(sdev, SI4713_CMD_TX_RDS_PS,
-				  args, ARRAY_SIZE(args), val,
-				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		return err;
-
-	v4l2_dbg(1, debug, &sdev->sd, "%s: status=0x%02x\n", __func__, val[0]);
-
-	return err;
-}
-
-static int si4713_set_power_state(struct si4713_device *sdev, u8 value)
-{
-	if (value)
-		return si4713_powerup(sdev);
-	return si4713_powerdown(sdev);
-}
-
-static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
-{
-	int rval = 0;
-
-	mute = set_mute(mute);
-
-	if (sdev->power_state)
-		rval = si4713_write_property(sdev,
-				SI4713_TX_LINE_INPUT_MUTE, mute);
-
-	return rval;
-}
-
-static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
-{
-	int rval = 0, i;
-	u8 len = 0;
-
-	/* We want to clear the whole thing */
-	if (!strlen(ps_name))
-		memset(ps_name, 0, MAX_RDS_PS_NAME + 1);
-
-	if (sdev->power_state) {
-		/* Write the new ps name and clear the padding */
-		for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) {
-			rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)),
-						ps_name + i);
-			if (rval < 0)
-				return rval;
-		}
-
-		/* Setup the size to be sent */
-		if (strlen(ps_name))
-			len = strlen(ps_name) - 1;
-		else
-			len = 1;
-
-		rval = si4713_write_property(sdev,
-				SI4713_TX_RDS_PS_MESSAGE_COUNT,
-				rds_ps_nblocks(len));
-		if (rval < 0)
-			return rval;
-
-		rval = si4713_write_property(sdev,
-				SI4713_TX_RDS_PS_REPEAT_COUNT,
-				DEFAULT_RDS_PS_REPEAT_COUNT * 2);
-		if (rval < 0)
-			return rval;
-	}
-
-	return rval;
-}
-
-static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
-{
-	int rval = 0, i;
-	u16 t_index = 0;
-	u8 b_index = 0, cr_inserted = 0;
-	s8 left;
-
-	if (!sdev->power_state)
-		return rval;
-
-	rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left);
-	if (rval < 0)
-		return rval;
-
-	if (!strlen(rt))
-		return rval;
-
-	do {
-		/* RDS spec says that if the last block isn't used,
-		 * then apply a carriage return
-		 */
-		if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {
-			for (i = 0; i < RDS_RADIOTEXT_BLK_SIZE; i++) {
-				if (!rt[t_index + i] ||
-				    rt[t_index + i] == RDS_CARRIAGE_RETURN) {
-					rt[t_index + i] = RDS_CARRIAGE_RETURN;
-					cr_inserted = 1;
-					break;
-				}
-			}
-		}
-
-		rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_LOAD,
-				compose_u16(RDS_RADIOTEXT_2A, b_index++),
-				compose_u16(rt[t_index], rt[t_index + 1]),
-				compose_u16(rt[t_index + 2], rt[t_index + 3]),
-				&left);
-		if (rval < 0)
-			return rval;
-
-		t_index += RDS_RADIOTEXT_BLK_SIZE;
-
-		if (cr_inserted)
-			break;
-	} while (left > 0);
-
-	return rval;
-}
-
-/*
- * si4713_update_tune_status - update properties from tx_tune_status
- * command. Must be called with sdev->mutex held.
- * @sdev: si4713_device structure for the device we are communicating
- */
-static int si4713_update_tune_status(struct si4713_device *sdev)
-{
-	int rval;
-	u16 f = 0;
-	u8 p = 0, a = 0, n = 0;
-
-	rval = si4713_tx_tune_status(sdev, 0x00, &f, &p, &a, &n);
-
-	if (rval < 0)
-		goto exit;
-
-/*	TODO: check that power_level and antenna_capacitor really are not
-	changed by the hardware. If they are, then these controls should become
-	volatiles.
-	sdev->power_level = p;
-	sdev->antenna_capacitor = a;*/
-	sdev->tune_rnl = n;
-
-exit:
-	return rval;
-}
-
-static int si4713_choose_econtrol_action(struct si4713_device *sdev, u32 id,
-		s32 *bit, s32 *mask, u16 *property, int *mul,
-		unsigned long **table, int *size)
-{
-	s32 rval = 0;
-
-	switch (id) {
-	/* FM_TX class controls */
-	case V4L2_CID_RDS_TX_PI:
-		*property = SI4713_TX_RDS_PI;
-		*mul = 1;
-		break;
-	case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
-		*property = SI4713_TX_ACOMP_THRESHOLD;
-		*mul = 1;
-		break;
-	case V4L2_CID_AUDIO_COMPRESSION_GAIN:
-		*property = SI4713_TX_ACOMP_GAIN;
-		*mul = 1;
-		break;
-	case V4L2_CID_PILOT_TONE_FREQUENCY:
-		*property = SI4713_TX_PILOT_FREQUENCY;
-		*mul = 1;
-		break;
-	case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
-		*property = SI4713_TX_ACOMP_ATTACK_TIME;
-		*mul = ATTACK_TIME_UNIT;
-		break;
-	case V4L2_CID_PILOT_TONE_DEVIATION:
-		*property = SI4713_TX_PILOT_DEVIATION;
-		*mul = 10;
-		break;
-	case V4L2_CID_AUDIO_LIMITER_DEVIATION:
-		*property = SI4713_TX_AUDIO_DEVIATION;
-		*mul = 10;
-		break;
-	case V4L2_CID_RDS_TX_DEVIATION:
-		*property = SI4713_TX_RDS_DEVIATION;
-		*mul = 1;
-		break;
-
-	case V4L2_CID_RDS_TX_PTY:
-		*property = SI4713_TX_RDS_PS_MISC;
-		*bit = 5;
-		*mask = 0x1F << 5;
-		break;
-	case V4L2_CID_AUDIO_LIMITER_ENABLED:
-		*property = SI4713_TX_ACOMP_ENABLE;
-		*bit = 1;
-		*mask = 1 << 1;
-		break;
-	case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
-		*property = SI4713_TX_ACOMP_ENABLE;
-		*bit = 0;
-		*mask = 1 << 0;
-		break;
-	case V4L2_CID_PILOT_TONE_ENABLED:
-		*property = SI4713_TX_COMPONENT_ENABLE;
-		*bit = 0;
-		*mask = 1 << 0;
-		break;
-
-	case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
-		*property = SI4713_TX_LIMITER_RELEASE_TIME;
-		*table = limiter_times;
-		*size = ARRAY_SIZE(limiter_times);
-		break;
-	case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
-		*property = SI4713_TX_ACOMP_RELEASE_TIME;
-		*table = acomp_rtimes;
-		*size = ARRAY_SIZE(acomp_rtimes);
-		break;
-	case V4L2_CID_TUNE_PREEMPHASIS:
-		*property = SI4713_TX_PREEMPHASIS;
-		*table = preemphasis_values;
-		*size = ARRAY_SIZE(preemphasis_values);
-		break;
-
-	default:
-		rval = -EINVAL;
-		break;
-	}
-
-	return rval;
-}
-
-static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);
-static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);
-/*
- * si4713_setup - Sets the device up with current configuration.
- * @sdev: si4713_device structure for the device we are communicating
- */
-static int si4713_setup(struct si4713_device *sdev)
-{
-	struct v4l2_frequency f;
-	struct v4l2_modulator vm;
-	int rval;
-
-	/* Device procedure needs to set frequency first */
-	f.tuner = 0;
-	f.frequency = sdev->frequency ? sdev->frequency : DEFAULT_FREQUENCY;
-	f.frequency = si4713_to_v4l2(f.frequency);
-	rval = si4713_s_frequency(&sdev->sd, &f);
-
-	vm.index = 0;
-	if (sdev->stereo)
-		vm.txsubchans = V4L2_TUNER_SUB_STEREO;
-	else
-		vm.txsubchans = V4L2_TUNER_SUB_MONO;
-	if (sdev->rds_enabled)
-		vm.txsubchans |= V4L2_TUNER_SUB_RDS;
-	si4713_s_modulator(&sdev->sd, &vm);
-
-	return rval;
-}
-
-/*
- * si4713_initialize - Sets the device up with default configuration.
- * @sdev: si4713_device structure for the device we are communicating
- */
-static int si4713_initialize(struct si4713_device *sdev)
-{
-	int rval;
-
-	rval = si4713_set_power_state(sdev, POWER_ON);
-	if (rval < 0)
-		return rval;
-
-	rval = si4713_checkrev(sdev);
-	if (rval < 0)
-		return rval;
-
-	rval = si4713_set_power_state(sdev, POWER_OFF);
-	if (rval < 0)
-		return rval;
-
-
-	sdev->frequency = DEFAULT_FREQUENCY;
-	sdev->stereo = 1;
-	sdev->tune_rnl = DEFAULT_TUNE_RNL;
-	return 0;
-}
-
-/* si4713_s_ctrl - set the value of a control */
-static int si4713_s_ctrl(struct v4l2_ctrl *ctrl)
-{
-	struct si4713_device *sdev =
-		container_of(ctrl->handler, struct si4713_device, ctrl_handler);
-	u32 val = 0;
-	s32 bit = 0, mask = 0;
-	u16 property = 0;
-	int mul = 0;
-	unsigned long *table = NULL;
-	int size = 0;
-	bool force = false;
-	int c;
-	int ret = 0;
-
-	if (ctrl->id != V4L2_CID_AUDIO_MUTE)
-		return -EINVAL;
-	if (ctrl->is_new) {
-		if (ctrl->val) {
-			ret = si4713_set_mute(sdev, ctrl->val);
-			if (!ret)
-				ret = si4713_set_power_state(sdev, POWER_DOWN);
-			return ret;
-		}
-		ret = si4713_set_power_state(sdev, POWER_UP);
-		if (!ret)
-			ret = si4713_set_mute(sdev, ctrl->val);
-		if (!ret)
-			ret = si4713_setup(sdev);
-		if (ret)
-			return ret;
-		force = true;
-	}
-
-	if (!sdev->power_state)
-		return 0;
-
-	for (c = 1; !ret && c < ctrl->ncontrols; c++) {
-		ctrl = ctrl->cluster[c];
-
-		if (!force && !ctrl->is_new)
-			continue;
-
-		switch (ctrl->id) {
-		case V4L2_CID_RDS_TX_PS_NAME:
-			ret = si4713_set_rds_ps_name(sdev, ctrl->string);
-			break;
-
-		case V4L2_CID_RDS_TX_RADIO_TEXT:
-			ret = si4713_set_rds_radio_text(sdev, ctrl->string);
-			break;
-
-		case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
-			/* don't handle this control if we force setting all
-			 * controls since in that case it will be handled by
-			 * V4L2_CID_TUNE_POWER_LEVEL. */
-			if (force)
-				break;
-			/* fall through */
-		case V4L2_CID_TUNE_POWER_LEVEL:
-			ret = si4713_tx_tune_power(sdev,
-				sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);
-			if (!ret) {
-				/* Make sure we don't set this twice */
-				sdev->tune_ant_cap->is_new = false;
-				sdev->tune_pwr_level->is_new = false;
-			}
-			break;
-
-		default:
-			ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,
-					&mask, &property, &mul, &table, &size);
-			if (ret < 0)
-				break;
-
-			val = ctrl->val;
-			if (mul) {
-				val = val / mul;
-			} else if (table) {
-				ret = usecs_to_dev(val, table, size);
-				if (ret < 0)
-					break;
-				val = ret;
-				ret = 0;
-			}
-
-			if (mask) {
-				ret = si4713_read_property(sdev, property, &val);
-				if (ret < 0)
-					break;
-				val = set_bits(val, ctrl->val, bit, mask);
-			}
-
-			ret = si4713_write_property(sdev, property, val);
-			if (ret < 0)
-				break;
-			if (mask)
-				val = ctrl->val;
-			break;
-		}
-	}
-
-	return ret;
-}
-
-/* si4713_ioctl - deal with private ioctls (only rnl for now) */
-static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
-{
-	struct si4713_device *sdev = to_si4713_device(sd);
-	struct si4713_rnl *rnl = arg;
-	u16 frequency;
-	int rval = 0;
-
-	if (!arg)
-		return -EINVAL;
-
-	switch (cmd) {
-	case SI4713_IOC_MEASURE_RNL:
-		frequency = v4l2_to_si4713(rnl->frequency);
-
-		if (sdev->power_state) {
-			/* Set desired measurement frequency */
-			rval = si4713_tx_tune_measure(sdev, frequency, 0);
-			if (rval < 0)
-				return rval;
-			/* get results from tune status */
-			rval = si4713_update_tune_status(sdev);
-			if (rval < 0)
-				return rval;
-		}
-		rnl->rnl = sdev->tune_rnl;
-		break;
-
-	default:
-		/* nothing */
-		rval = -ENOIOCTLCMD;
-	}
-
-	return rval;
-}
-
-/* si4713_g_modulator - get modulator attributes */
-static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
-{
-	struct si4713_device *sdev = to_si4713_device(sd);
-	int rval = 0;
-
-	if (!sdev)
-		return -ENODEV;
-
-	if (vm->index > 0)
-		return -EINVAL;
-
-	strncpy(vm->name, "FM Modulator", 32);
-	vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW |
-		V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_CONTROLS;
-
-	/* Report current frequency range limits */
-	vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW);
-	vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH);
-
-	if (sdev->power_state) {
-		u32 comp_en = 0;
-
-		rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE,
-						&comp_en);
-		if (rval < 0)
-			return rval;
-
-		sdev->stereo = get_status_bit(comp_en, 1, 1 << 1);
-	}
-
-	/* Report current audio mode: mono or stereo */
-	if (sdev->stereo)
-		vm->txsubchans = V4L2_TUNER_SUB_STEREO;
-	else
-		vm->txsubchans = V4L2_TUNER_SUB_MONO;
-
-	/* Report rds feature status */
-	if (sdev->rds_enabled)
-		vm->txsubchans |= V4L2_TUNER_SUB_RDS;
-	else
-		vm->txsubchans &= ~V4L2_TUNER_SUB_RDS;
-
-	return rval;
-}
-
-/* si4713_s_modulator - set modulator attributes */
-static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)
-{
-	struct si4713_device *sdev = to_si4713_device(sd);
-	int rval = 0;
-	u16 stereo, rds;
-	u32 p;
-
-	if (!sdev)
-		return -ENODEV;
-
-	if (vm->index > 0)
-		return -EINVAL;
-
-	/* Set audio mode: mono or stereo */
-	if (vm->txsubchans & V4L2_TUNER_SUB_STEREO)
-		stereo = 1;
-	else if (vm->txsubchans & V4L2_TUNER_SUB_MONO)
-		stereo = 0;
-	else
-		return -EINVAL;
-
-	rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS);
-
-	if (sdev->power_state) {
-		rval = si4713_read_property(sdev,
-						SI4713_TX_COMPONENT_ENABLE, &p);
-		if (rval < 0)
-			return rval;
-
-		p = set_bits(p, stereo, 1, 1 << 1);
-		p = set_bits(p, rds, 2, 1 << 2);
-
-		rval = si4713_write_property(sdev,
-						SI4713_TX_COMPONENT_ENABLE, p);
-		if (rval < 0)
-			return rval;
-	}
-
-	sdev->stereo = stereo;
-	sdev->rds_enabled = rds;
-
-	return rval;
-}
-
-/* si4713_g_frequency - get tuner or modulator radio frequency */
-static int si4713_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
-{
-	struct si4713_device *sdev = to_si4713_device(sd);
-	int rval = 0;
-
-	if (f->tuner)
-		return -EINVAL;
-
-	if (sdev->power_state) {
-		u16 freq;
-		u8 p, a, n;
-
-		rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n);
-		if (rval < 0)
-			return rval;
-
-		sdev->frequency = freq;
-	}
-
-	f->frequency = si4713_to_v4l2(sdev->frequency);
-
-	return rval;
-}
-
-/* si4713_s_frequency - set tuner or modulator radio frequency */
-static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
-{
-	struct si4713_device *sdev = to_si4713_device(sd);
-	int rval = 0;
-	u16 frequency = v4l2_to_si4713(f->frequency);
-
-	if (f->tuner)
-		return -EINVAL;
-
-	/* Check frequency range */
-	frequency = clamp_t(u16, frequency, FREQ_RANGE_LOW, FREQ_RANGE_HIGH);
-
-	if (sdev->power_state) {
-		rval = si4713_tx_tune_freq(sdev, frequency);
-		if (rval < 0)
-			return rval;
-		frequency = rval;
-		rval = 0;
-	}
-	sdev->frequency = frequency;
-
-	return rval;
-}
-
-static const struct v4l2_ctrl_ops si4713_ctrl_ops = {
-	.s_ctrl = si4713_s_ctrl,
-};
-
-static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = {
-	.ioctl		= si4713_ioctl,
-};
-
-static const struct v4l2_subdev_tuner_ops si4713_subdev_tuner_ops = {
-	.g_frequency	= si4713_g_frequency,
-	.s_frequency	= si4713_s_frequency,
-	.g_modulator	= si4713_g_modulator,
-	.s_modulator	= si4713_s_modulator,
-};
-
-static const struct v4l2_subdev_ops si4713_subdev_ops = {
-	.core		= &si4713_subdev_core_ops,
-	.tuner		= &si4713_subdev_tuner_ops,
-};
-
-/*
- * I2C driver interface
- */
-/* si4713_probe - probe for the device */
-static int si4713_probe(struct i2c_client *client,
-					const struct i2c_device_id *id)
-{
-	struct si4713_device *sdev;
-	struct si4713_platform_data *pdata = client->dev.platform_data;
-	struct v4l2_ctrl_handler *hdl;
-	int rval, i;
-
-	sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
-	if (!sdev) {
-		dev_err(&client->dev, "Failed to alloc video device.\n");
-		rval = -ENOMEM;
-		goto exit;
-	}
-
-	sdev->gpio_reset = -1;
-	if (pdata && gpio_is_valid(pdata->gpio_reset)) {
-		rval = gpio_request(pdata->gpio_reset, "si4713 reset");
-		if (rval) {
-			dev_err(&client->dev,
-				"Failed to request gpio: %d\n", rval);
-			goto free_sdev;
-		}
-		sdev->gpio_reset = pdata->gpio_reset;
-		gpio_direction_output(sdev->gpio_reset, 0);
-	}
-
-	for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
-		sdev->supplies[i].supply = si4713_supply_names[i];
-
-	rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
-				  sdev->supplies);
-	if (rval) {
-		dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
-		goto free_gpio;
-	}
-
-	v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops);
-
-	init_completion(&sdev->work);
-
-	hdl = &sdev->ctrl_handler;
-	v4l2_ctrl_handler_init(hdl, 20);
-	sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_MUTE, 0, 1, 1, DEFAULT_MUTE);
-
-	sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, DEFAULT_RDS_PI);
-	sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_RDS_TX_PTY, 0, 31, 1, DEFAULT_RDS_PTY);
-	sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_RDS_TX_DEVIATION, 0, MAX_RDS_DEVIATION,
-			10, DEFAULT_RDS_DEVIATION);
-	/*
-	 * Report step as 8. From RDS spec, psname
-	 * should be 8. But there are receivers which scroll strings
-	 * sized as 8xN.
-	 */
-	sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_RDS_TX_PS_NAME, 0, MAX_RDS_PS_NAME, 8, 0);
-	/*
-	 * Report step as 32 (2A block). From RDS spec,
-	 * radio text should be 32 for 2A block. But there are receivers
-	 * which scroll strings sized as 32xN. Setting default to 32.
-	 */
-	sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);
-
-	sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_LIMITER_ENABLED, 0, 1, 1, 1);
-	sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_LIMITER_RELEASE_TIME, 250,
-			MAX_LIMITER_RELEASE_TIME, 10, DEFAULT_LIMITER_RTIME);
-	sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_LIMITER_DEVIATION, 0,
-			MAX_LIMITER_DEVIATION, 10, DEFAULT_LIMITER_DEV);
-
-	sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_COMPRESSION_ENABLED, 0, 1, 1, 1);
-	sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_COMPRESSION_GAIN, 0, MAX_ACOMP_GAIN, 1,
-			DEFAULT_ACOMP_GAIN);
-	sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,
-			MAX_ACOMP_THRESHOLD, 1,
-			DEFAULT_ACOMP_THRESHOLD);
-	sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME, 0,
-			MAX_ACOMP_ATTACK_TIME, 500, DEFAULT_ACOMP_ATIME);
-	sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME, 100000,
-			MAX_ACOMP_RELEASE_TIME, 100000, DEFAULT_ACOMP_RTIME);
-
-	sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_PILOT_TONE_ENABLED, 0, 1, 1, 1);
-	sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_PILOT_TONE_DEVIATION, 0, MAX_PILOT_DEVIATION,
-			10, DEFAULT_PILOT_DEVIATION);
-	sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_PILOT_TONE_FREQUENCY, 0, MAX_PILOT_FREQUENCY,
-			1, DEFAULT_PILOT_FREQUENCY);
-
-	sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops,
-			V4L2_CID_TUNE_PREEMPHASIS,
-			V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
-	sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);
-	sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, 191, 1, 0);
-
-	if (hdl->error) {
-		rval = hdl->error;
-		goto free_ctrls;
-	}
-	v4l2_ctrl_cluster(20, &sdev->mute);
-	sdev->sd.ctrl_handler = hdl;
-
-	if (client->irq) {
-		rval = request_irq(client->irq,
-			si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED,
-			client->name, sdev);
-		if (rval < 0) {
-			v4l2_err(&sdev->sd, "Could not request IRQ\n");
-			goto put_reg;
-		}
-		v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n");
-	} else {
-		v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n");
-	}
-
-	rval = si4713_initialize(sdev);
-	if (rval < 0) {
-		v4l2_err(&sdev->sd, "Failed to probe device information.\n");
-		goto free_irq;
-	}
-
-	return 0;
-
-free_irq:
-	if (client->irq)
-		free_irq(client->irq, sdev);
-free_ctrls:
-	v4l2_ctrl_handler_free(hdl);
-put_reg:
-	regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
-free_gpio:
-	if (gpio_is_valid(sdev->gpio_reset))
-		gpio_free(sdev->gpio_reset);
-free_sdev:
-	kfree(sdev);
-exit:
-	return rval;
-}
-
-/* si4713_remove - remove the device */
-static int si4713_remove(struct i2c_client *client)
-{
-	struct v4l2_subdev *sd = i2c_get_clientdata(client);
-	struct si4713_device *sdev = to_si4713_device(sd);
-
-	if (sdev->power_state)
-		si4713_set_power_state(sdev, POWER_DOWN);
-
-	if (client->irq > 0)
-		free_irq(client->irq, sdev);
-
-	v4l2_device_unregister_subdev(sd);
-	v4l2_ctrl_handler_free(sd->ctrl_handler);
-	regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
-	if (gpio_is_valid(sdev->gpio_reset))
-		gpio_free(sdev->gpio_reset);
-	kfree(sdev);
-
-	return 0;
-}
-
-/* si4713_i2c_driver - i2c driver interface */
-static const struct i2c_device_id si4713_id[] = {
-	{ "si4713" , 0 },
-	{ },
-};
-MODULE_DEVICE_TABLE(i2c, si4713_id);
-
-static struct i2c_driver si4713_i2c_driver = {
-	.driver		= {
-		.name	= "si4713",
-	},
-	.probe		= si4713_probe,
-	.remove         = si4713_remove,
-	.id_table       = si4713_id,
-};
-
-module_i2c_driver(si4713_i2c_driver);
diff --git a/drivers/media/radio/si4713-i2c.h b/drivers/media/radio/si4713-i2c.h
deleted file mode 100644
index 25cdea2..0000000
--- a/drivers/media/radio/si4713-i2c.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * drivers/media/radio/si4713-i2c.h
- *
- * Property and commands definitions for Si4713 radio transmitter chip.
- *
- * Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
- * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
- *
- * This file is licensed under the terms of the GNU General Public License
- * version 2. This program is licensed "as is" without any warranty of any
- * kind, whether express or implied.
- *
- */
-
-#ifndef SI4713_I2C_H
-#define SI4713_I2C_H
-
-#include <media/v4l2-subdev.h>
-#include <media/v4l2-ctrls.h>
-#include <media/si4713.h>
-
-#define SI4713_PRODUCT_NUMBER		0x0D
-
-/* Command Timeouts */
-#define DEFAULT_TIMEOUT			500
-#define TIMEOUT_SET_PROPERTY		20
-#define TIMEOUT_TX_TUNE_POWER		30000
-#define TIMEOUT_TX_TUNE			110000
-#define TIMEOUT_POWER_UP		200000
-
-/*
- * Command and its arguments definitions
- */
-#define SI4713_PWUP_CTSIEN		(1<<7)
-#define SI4713_PWUP_GPO2OEN		(1<<6)
-#define SI4713_PWUP_PATCH		(1<<5)
-#define SI4713_PWUP_XOSCEN		(1<<4)
-#define SI4713_PWUP_FUNC_TX		0x02
-#define SI4713_PWUP_FUNC_PATCH		0x0F
-#define SI4713_PWUP_OPMOD_ANALOG	0x50
-#define SI4713_PWUP_OPMOD_DIGITAL	0x0F
-#define SI4713_PWUP_NARGS		2
-#define SI4713_PWUP_NRESP		1
-#define SI4713_CMD_POWER_UP		0x01
-
-#define SI4713_GETREV_NRESP		9
-#define SI4713_CMD_GET_REV		0x10
-
-#define SI4713_PWDN_NRESP		1
-#define SI4713_CMD_POWER_DOWN		0x11
-
-#define SI4713_SET_PROP_NARGS		5
-#define SI4713_SET_PROP_NRESP		1
-#define SI4713_CMD_SET_PROPERTY		0x12
-
-#define SI4713_GET_PROP_NARGS		3
-#define SI4713_GET_PROP_NRESP		4
-#define SI4713_CMD_GET_PROPERTY		0x13
-
-#define SI4713_GET_STATUS_NRESP		1
-#define SI4713_CMD_GET_INT_STATUS	0x14
-
-#define SI4713_CMD_PATCH_ARGS		0x15
-#define SI4713_CMD_PATCH_DATA		0x16
-
-#define SI4713_MAX_FREQ			10800
-#define SI4713_MIN_FREQ			7600
-#define SI4713_TXFREQ_NARGS		3
-#define SI4713_TXFREQ_NRESP		1
-#define SI4713_CMD_TX_TUNE_FREQ		0x30
-
-#define SI4713_MAX_POWER		120
-#define SI4713_MIN_POWER		88
-#define SI4713_MAX_ANTCAP		191
-#define SI4713_MIN_ANTCAP		0
-#define SI4713_TXPWR_NARGS		4
-#define SI4713_TXPWR_NRESP		1
-#define SI4713_CMD_TX_TUNE_POWER	0x31
-
-#define SI4713_TXMEA_NARGS		4
-#define SI4713_TXMEA_NRESP		1
-#define SI4713_CMD_TX_TUNE_MEASURE	0x32
-
-#define SI4713_INTACK_MASK		0x01
-#define SI4713_TXSTATUS_NARGS		1
-#define SI4713_TXSTATUS_NRESP		8
-#define SI4713_CMD_TX_TUNE_STATUS	0x33
-
-#define SI4713_OVERMOD_BIT		(1 << 2)
-#define SI4713_IALH_BIT			(1 << 1)
-#define SI4713_IALL_BIT			(1 << 0)
-#define SI4713_ASQSTATUS_NARGS		1
-#define SI4713_ASQSTATUS_NRESP		5
-#define SI4713_CMD_TX_ASQ_STATUS	0x34
-
-#define SI4713_RDSBUFF_MODE_MASK	0x87
-#define SI4713_RDSBUFF_NARGS		7
-#define SI4713_RDSBUFF_NRESP		6
-#define SI4713_CMD_TX_RDS_BUFF		0x35
-
-#define SI4713_RDSPS_PSID_MASK		0x1F
-#define SI4713_RDSPS_NARGS		5
-#define SI4713_RDSPS_NRESP		1
-#define SI4713_CMD_TX_RDS_PS		0x36
-
-#define SI4713_CMD_GPO_CTL		0x80
-#define SI4713_CMD_GPO_SET		0x81
-
-/*
- * Bits from status response
- */
-#define SI4713_CTS			(1<<7)
-#define SI4713_ERR			(1<<6)
-#define SI4713_RDS_INT			(1<<2)
-#define SI4713_ASQ_INT			(1<<1)
-#define SI4713_STC_INT			(1<<0)
-
-/*
- * Property definitions
- */
-#define SI4713_GPO_IEN			0x0001
-#define SI4713_DIG_INPUT_FORMAT		0x0101
-#define SI4713_DIG_INPUT_SAMPLE_RATE	0x0103
-#define SI4713_REFCLK_FREQ		0x0201
-#define SI4713_REFCLK_PRESCALE		0x0202
-#define SI4713_TX_COMPONENT_ENABLE	0x2100
-#define SI4713_TX_AUDIO_DEVIATION	0x2101
-#define SI4713_TX_PILOT_DEVIATION	0x2102
-#define SI4713_TX_RDS_DEVIATION		0x2103
-#define SI4713_TX_LINE_INPUT_LEVEL	0x2104
-#define SI4713_TX_LINE_INPUT_MUTE	0x2105
-#define SI4713_TX_PREEMPHASIS		0x2106
-#define SI4713_TX_PILOT_FREQUENCY	0x2107
-#define SI4713_TX_ACOMP_ENABLE		0x2200
-#define SI4713_TX_ACOMP_THRESHOLD	0x2201
-#define SI4713_TX_ACOMP_ATTACK_TIME	0x2202
-#define SI4713_TX_ACOMP_RELEASE_TIME	0x2203
-#define SI4713_TX_ACOMP_GAIN		0x2204
-#define SI4713_TX_LIMITER_RELEASE_TIME	0x2205
-#define SI4713_TX_ASQ_INTERRUPT_SOURCE	0x2300
-#define SI4713_TX_ASQ_LEVEL_LOW		0x2301
-#define SI4713_TX_ASQ_DURATION_LOW	0x2302
-#define SI4713_TX_ASQ_LEVEL_HIGH	0x2303
-#define SI4713_TX_ASQ_DURATION_HIGH	0x2304
-#define SI4713_TX_RDS_INTERRUPT_SOURCE	0x2C00
-#define SI4713_TX_RDS_PI		0x2C01
-#define SI4713_TX_RDS_PS_MIX		0x2C02
-#define SI4713_TX_RDS_PS_MISC		0x2C03
-#define SI4713_TX_RDS_PS_REPEAT_COUNT	0x2C04
-#define SI4713_TX_RDS_PS_MESSAGE_COUNT	0x2C05
-#define SI4713_TX_RDS_PS_AF		0x2C06
-#define SI4713_TX_RDS_FIFO_SIZE		0x2C07
-
-#define PREEMPHASIS_USA			75
-#define PREEMPHASIS_EU			50
-#define PREEMPHASIS_DISABLED		0
-#define FMPE_USA			0x00
-#define FMPE_EU				0x01
-#define FMPE_DISABLED			0x02
-
-#define POWER_UP			0x01
-#define POWER_DOWN			0x00
-
-#define MAX_RDS_PTY			31
-#define MAX_RDS_DEVIATION		90000
-
-/*
- * PSNAME is known to be defined as 8 character sized (RDS Spec).
- * However, there is receivers which scroll PSNAME 8xN sized.
- */
-#define MAX_RDS_PS_NAME			96
-
-/*
- * MAX_RDS_RADIO_TEXT is known to be defined as 32 (2A group) or 64 (2B group)
- * character sized (RDS Spec).
- * However, there is receivers which scroll them as well.
- */
-#define MAX_RDS_RADIO_TEXT		384
-
-#define MAX_LIMITER_RELEASE_TIME	102390
-#define MAX_LIMITER_DEVIATION		90000
-
-#define MAX_PILOT_DEVIATION		90000
-#define MAX_PILOT_FREQUENCY		19000
-
-#define MAX_ACOMP_RELEASE_TIME		1000000
-#define MAX_ACOMP_ATTACK_TIME		5000
-#define MAX_ACOMP_THRESHOLD		0
-#define MIN_ACOMP_THRESHOLD		(-40)
-#define MAX_ACOMP_GAIN			20
-
-#define SI4713_NUM_SUPPLIES		2
-
-/*
- * si4713_device - private data
- */
-struct si4713_device {
-	/* v4l2_subdev and i2c reference (v4l2_subdev priv data) */
-	struct v4l2_subdev sd;
-	struct v4l2_ctrl_handler ctrl_handler;
-	/* private data structures */
-	struct { /* si4713 control cluster */
-		/* This is one big cluster since the mute control
-		 * powers off the device and after unmuting again all
-		 * controls need to be set at once. The only way of doing
-		 * that is by making it one big cluster. */
-		struct v4l2_ctrl *mute;
-		struct v4l2_ctrl *rds_ps_name;
-		struct v4l2_ctrl *rds_radio_text;
-		struct v4l2_ctrl *rds_pi;
-		struct v4l2_ctrl *rds_deviation;
-		struct v4l2_ctrl *rds_pty;
-		struct v4l2_ctrl *compression_enabled;
-		struct v4l2_ctrl *compression_threshold;
-		struct v4l2_ctrl *compression_gain;
-		struct v4l2_ctrl *compression_attack_time;
-		struct v4l2_ctrl *compression_release_time;
-		struct v4l2_ctrl *pilot_tone_enabled;
-		struct v4l2_ctrl *pilot_tone_freq;
-		struct v4l2_ctrl *pilot_tone_deviation;
-		struct v4l2_ctrl *limiter_enabled;
-		struct v4l2_ctrl *limiter_deviation;
-		struct v4l2_ctrl *limiter_release_time;
-		struct v4l2_ctrl *tune_preemphasis;
-		struct v4l2_ctrl *tune_pwr_level;
-		struct v4l2_ctrl *tune_ant_cap;
-	};
-	struct completion work;
-	struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
-	int gpio_reset;
-	u32 power_state;
-	u32 rds_enabled;
-	u32 frequency;
-	u32 preemphasis;
-	u32 stereo;
-	u32 tune_rnl;
-};
-#endif /* ifndef SI4713_I2C_H */
diff --git a/drivers/media/radio/si4713/Kconfig b/drivers/media/radio/si4713/Kconfig
new file mode 100644
index 0000000..ec640b8
--- /dev/null
+++ b/drivers/media/radio/si4713/Kconfig
@@ -0,0 +1,25 @@
+config PLATFORM_SI4713
+	tristate "Silicon Labs Si4713 FM Radio Transmitter support with I2C"
+	depends on I2C && RADIO_SI4713
+	select SI4713
+	---help---
+	  This is a driver for I2C devices with the Silicon Labs SI4713
+	  chip.
+
+	  Say Y here if you want to connect this type of radio to your
+	  computer's I2C port.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called radio-platform-si4713.
+
+config I2C_SI4713
+	tristate "Silicon Labs Si4713 FM Radio Transmitter support"
+	depends on I2C && RADIO_SI4713
+	---help---
+	  Say Y here if you want support to Si4713 FM Radio Transmitter.
+	  This device can transmit audio through FM. It can transmit
+	  RDS and RBDS signals as well. This module is the v4l2 radio
+	  interface for the i2c driver of this device.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called si4713.
diff --git a/drivers/media/radio/si4713/Makefile b/drivers/media/radio/si4713/Makefile
new file mode 100644
index 0000000..9d0bd0e
--- /dev/null
+++ b/drivers/media/radio/si4713/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for radios with Silicon Labs Si4713 FM Radio Transmitters
+#
+
+obj-$(CONFIG_I2C_SI4713) += si4713.o
+obj-$(CONFIG_PLATFORM_SI4713) += radio-platform-si4713.o
+
diff --git a/drivers/media/radio/si4713/radio-platform-si4713.c b/drivers/media/radio/si4713/radio-platform-si4713.c
new file mode 100644
index 0000000..cf0aad4
--- /dev/null
+++ b/drivers/media/radio/si4713/radio-platform-si4713.c
@@ -0,0 +1,246 @@
+/*
+ * drivers/media/radio/radio-platform-si4713.c
+ *
+ * Platform Driver for Silicon Labs Si4713 FM Radio Transmitter:
+ *
+ * Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
+ * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/videodev2.h>
+#include <linux/slab.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-fh.h>
+#include <media/v4l2-ctrls.h>
+#include <media/v4l2-event.h>
+#include <media/radio-si4713.h>
+
+/* module parameters */
+static int radio_nr = -1;	/* radio device minor (-1 ==> auto assign) */
+module_param(radio_nr, int, 0);
+MODULE_PARM_DESC(radio_nr,
+		 "Minor number for radio device (-1 ==> auto assign)");
+
+MODULE_LICENSE("GPL v2");
+MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
+MODULE_DESCRIPTION("Platform driver for Si4713 FM Radio Transmitter");
+MODULE_VERSION("0.0.1");
+MODULE_ALIAS("platform:radio-si4713");
+
+/* Driver state struct */
+struct radio_si4713_device {
+	struct v4l2_device		v4l2_dev;
+	struct video_device		radio_dev;
+	struct mutex lock;
+};
+
+/* radio_si4713_fops - file operations interface */
+static const struct v4l2_file_operations radio_si4713_fops = {
+	.owner		= THIS_MODULE,
+	.open = v4l2_fh_open,
+	.release = v4l2_fh_release,
+	.poll = v4l2_ctrl_poll,
+	/* Note: locking is done at the subdev level in the i2c driver. */
+	.unlocked_ioctl	= video_ioctl2,
+};
+
+/* Video4Linux Interface */
+
+/* radio_si4713_querycap - query device capabilities */
+static int radio_si4713_querycap(struct file *file, void *priv,
+					struct v4l2_capability *capability)
+{
+	strlcpy(capability->driver, "radio-si4713", sizeof(capability->driver));
+	strlcpy(capability->card, "Silicon Labs Si4713 Modulator",
+		sizeof(capability->card));
+	strlcpy(capability->bus_info, "platform:radio-si4713",
+		sizeof(capability->bus_info));
+	capability->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
+	capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
+
+	return 0;
+}
+
+/*
+ * v4l2 ioctl call backs.
+ * we are just a wrapper for v4l2_sub_devs.
+ */
+static inline struct v4l2_device *get_v4l2_dev(struct file *file)
+{
+	return &((struct radio_si4713_device *)video_drvdata(file))->v4l2_dev;
+}
+
+static int radio_si4713_g_modulator(struct file *file, void *p,
+				    struct v4l2_modulator *vm)
+{
+	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
+					  g_modulator, vm);
+}
+
+static int radio_si4713_s_modulator(struct file *file, void *p,
+				    const struct v4l2_modulator *vm)
+{
+	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
+					  s_modulator, vm);
+}
+
+static int radio_si4713_g_frequency(struct file *file, void *p,
+				    struct v4l2_frequency *vf)
+{
+	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
+					  g_frequency, vf);
+}
+
+static int radio_si4713_s_frequency(struct file *file, void *p,
+				    const struct v4l2_frequency *vf)
+{
+	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, tuner,
+					  s_frequency, vf);
+}
+
+static long radio_si4713_default(struct file *file, void *p,
+				 bool valid_prio, unsigned int cmd, void *arg)
+{
+	return v4l2_device_call_until_err(get_v4l2_dev(file), 0, core,
+					  ioctl, cmd, arg);
+}
+
+static struct v4l2_ioctl_ops radio_si4713_ioctl_ops = {
+	.vidioc_querycap	= radio_si4713_querycap,
+	.vidioc_g_modulator	= radio_si4713_g_modulator,
+	.vidioc_s_modulator	= radio_si4713_s_modulator,
+	.vidioc_g_frequency	= radio_si4713_g_frequency,
+	.vidioc_s_frequency	= radio_si4713_s_frequency,
+	.vidioc_log_status      = v4l2_ctrl_log_status,
+	.vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
+	.vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+	.vidioc_default		= radio_si4713_default,
+};
+
+/* radio_si4713_vdev_template - video device interface */
+static struct video_device radio_si4713_vdev_template = {
+	.fops			= &radio_si4713_fops,
+	.name			= "radio-si4713",
+	.release		= video_device_release_empty,
+	.ioctl_ops		= &radio_si4713_ioctl_ops,
+	.vfl_dir		= VFL_DIR_TX,
+};
+
+/* Platform driver interface */
+/* radio_si4713_pdriver_probe - probe for the device */
+static int radio_si4713_pdriver_probe(struct platform_device *pdev)
+{
+	struct radio_si4713_platform_data *pdata = pdev->dev.platform_data;
+	struct radio_si4713_device *rsdev;
+	struct i2c_adapter *adapter;
+	struct v4l2_subdev *sd;
+	int rval = 0;
+
+	if (!pdata) {
+		dev_err(&pdev->dev, "Cannot proceed without platform data.\n");
+		rval = -EINVAL;
+		goto exit;
+	}
+
+	rsdev = devm_kzalloc(&pdev->dev, sizeof(*rsdev), GFP_KERNEL);
+	if (!rsdev) {
+		dev_err(&pdev->dev, "Failed to alloc video device.\n");
+		rval = -ENOMEM;
+		goto exit;
+	}
+	mutex_init(&rsdev->lock);
+
+	rval = v4l2_device_register(&pdev->dev, &rsdev->v4l2_dev);
+	if (rval) {
+		dev_err(&pdev->dev, "Failed to register v4l2 device.\n");
+		goto exit;
+	}
+
+	adapter = i2c_get_adapter(pdata->i2c_bus);
+	if (!adapter) {
+		dev_err(&pdev->dev, "Cannot get i2c adapter %d\n",
+			pdata->i2c_bus);
+		rval = -ENODEV;
+		goto unregister_v4l2_dev;
+	}
+
+	sd = v4l2_i2c_new_subdev_board(&rsdev->v4l2_dev, adapter,
+				       pdata->subdev_board_info, NULL);
+	if (!sd) {
+		dev_err(&pdev->dev, "Cannot get v4l2 subdevice\n");
+		rval = -ENODEV;
+		goto put_adapter;
+	}
+
+	rsdev->radio_dev = radio_si4713_vdev_template;
+	rsdev->radio_dev.v4l2_dev = &rsdev->v4l2_dev;
+	rsdev->radio_dev.ctrl_handler = sd->ctrl_handler;
+	set_bit(V4L2_FL_USE_FH_PRIO, &rsdev->radio_dev.flags);
+	/* Serialize all access to the si4713 */
+	rsdev->radio_dev.lock = &rsdev->lock;
+	video_set_drvdata(&rsdev->radio_dev, rsdev);
+	if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
+		dev_err(&pdev->dev, "Could not register video device.\n");
+		rval = -EIO;
+		goto put_adapter;
+	}
+	dev_info(&pdev->dev, "New device successfully probed\n");
+
+	goto exit;
+
+put_adapter:
+	i2c_put_adapter(adapter);
+unregister_v4l2_dev:
+	v4l2_device_unregister(&rsdev->v4l2_dev);
+exit:
+	return rval;
+}
+
+/* radio_si4713_pdriver_remove - remove the device */
+static int radio_si4713_pdriver_remove(struct platform_device *pdev)
+{
+	struct v4l2_device *v4l2_dev = platform_get_drvdata(pdev);
+	struct v4l2_subdev *sd = list_entry(v4l2_dev->subdevs.next,
+					    struct v4l2_subdev, list);
+	struct i2c_client *client = v4l2_get_subdevdata(sd);
+	struct radio_si4713_device *rsdev;
+
+	rsdev = container_of(v4l2_dev, struct radio_si4713_device, v4l2_dev);
+	video_unregister_device(&rsdev->radio_dev);
+	i2c_put_adapter(client->adapter);
+	v4l2_device_unregister(&rsdev->v4l2_dev);
+
+	return 0;
+}
+
+static struct platform_driver radio_si4713_pdriver = {
+	.driver		= {
+		.name	= "radio-si4713",
+		.owner	= THIS_MODULE,
+	},
+	.probe		= radio_si4713_pdriver_probe,
+	.remove         = radio_si4713_pdriver_remove,
+};
+
+module_platform_driver(radio_si4713_pdriver);
diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
new file mode 100644
index 0000000..ac727e3
--- /dev/null
+++ b/drivers/media/radio/si4713/si4713.c
@@ -0,0 +1,1532 @@
+/*
+ * drivers/media/radio/si4713.c
+ *
+ * Silicon Labs Si4713 FM Radio Transmitter I2C commands.
+ *
+ * Copyright (c) 2009 Nokia Corporation
+ * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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
+ */
+
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/regulator/consumer.h>
+#include <linux/module.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-common.h>
+
+#include "si4713.h"
+
+/* module parameters */
+static int debug;
+module_param(debug, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug, "Debug level (0 - 2)");
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
+MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
+MODULE_VERSION("0.0.1");
+
+static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
+	"vio",
+	"vdd",
+};
+
+#define DEFAULT_RDS_PI			0x00
+#define DEFAULT_RDS_PTY			0x00
+#define DEFAULT_RDS_DEVIATION		0x00C8
+#define DEFAULT_RDS_PS_REPEAT_COUNT	0x0003
+#define DEFAULT_LIMITER_RTIME		0x1392
+#define DEFAULT_LIMITER_DEV		0x102CA
+#define DEFAULT_PILOT_FREQUENCY 	0x4A38
+#define DEFAULT_PILOT_DEVIATION		0x1A5E
+#define DEFAULT_ACOMP_ATIME		0x0000
+#define DEFAULT_ACOMP_RTIME		0xF4240L
+#define DEFAULT_ACOMP_GAIN		0x0F
+#define DEFAULT_ACOMP_THRESHOLD 	(-0x28)
+#define DEFAULT_MUTE			0x01
+#define DEFAULT_POWER_LEVEL		88
+#define DEFAULT_FREQUENCY		8800
+#define DEFAULT_PREEMPHASIS		FMPE_EU
+#define DEFAULT_TUNE_RNL		0xFF
+
+#define to_si4713_device(sd)	container_of(sd, struct si4713_device, sd)
+
+/* frequency domain transformation (using times 10 to avoid floats) */
+#define FREQDEV_UNIT	100000
+#define FREQV4L2_MULTI	625
+#define si4713_to_v4l2(f)	((f * FREQDEV_UNIT) / FREQV4L2_MULTI)
+#define v4l2_to_si4713(f)	((f * FREQV4L2_MULTI) / FREQDEV_UNIT)
+#define FREQ_RANGE_LOW			7600
+#define FREQ_RANGE_HIGH			10800
+
+#define MAX_ARGS 7
+
+#define RDS_BLOCK			8
+#define RDS_BLOCK_CLEAR			0x03
+#define RDS_BLOCK_LOAD			0x04
+#define RDS_RADIOTEXT_2A		0x20
+#define RDS_RADIOTEXT_BLK_SIZE		4
+#define RDS_RADIOTEXT_INDEX_MAX		0x0F
+#define RDS_CARRIAGE_RETURN		0x0D
+
+#define rds_ps_nblocks(len)	((len / RDS_BLOCK) + (len % RDS_BLOCK ? 1 : 0))
+
+#define get_status_bit(p, b, m)	(((p) & (m)) >> (b))
+#define set_bits(p, v, b, m)	(((p) & ~(m)) | ((v) << (b)))
+
+#define ATTACK_TIME_UNIT	500
+
+#define POWER_OFF			0x00
+#define POWER_ON			0x01
+
+#define msb(x)                  ((u8)((u16) x >> 8))
+#define lsb(x)                  ((u8)((u16) x &  0x00FF))
+#define compose_u16(msb, lsb)	(((u16)msb << 8) | lsb)
+#define check_command_failed(status)	(!(status & SI4713_CTS) || \
+					(status & SI4713_ERR))
+/* mute definition */
+#define set_mute(p)	((p & 1) | ((p & 1) << 1));
+
+#ifdef DEBUG
+#define DBG_BUFFER(device, message, buffer, size)			\
+	{								\
+		int i;							\
+		char str[(size)*5];					\
+		for (i = 0; i < size; i++)				\
+			sprintf(str + i * 5, " 0x%02x", buffer[i]);	\
+		v4l2_dbg(2, debug, device, "%s:%s\n", message, str);	\
+	}
+#else
+#define DBG_BUFFER(device, message, buffer, size)
+#endif
+
+/*
+ * Values for limiter release time (sorted by second column)
+ *	device	release
+ *	value	time (us)
+ */
+static long limiter_times[] = {
+	2000,	250,
+	1000,	500,
+	510,	1000,
+	255,	2000,
+	170,	3000,
+	127,	4020,
+	102,	5010,
+	85,	6020,
+	73,	7010,
+	64,	7990,
+	57,	8970,
+	51,	10030,
+	25,	20470,
+	17,	30110,
+	13,	39380,
+	10,	51190,
+	8,	63690,
+	7,	73140,
+	6,	85330,
+	5,	102390,
+};
+
+/*
+ * Values for audio compression release time (sorted by second column)
+ *	device	release
+ *	value	time (us)
+ */
+static unsigned long acomp_rtimes[] = {
+	0,	100000,
+	1,	200000,
+	2,	350000,
+	3,	525000,
+	4,	1000000,
+};
+
+/*
+ * Values for preemphasis (sorted by second column)
+ *	device	preemphasis
+ *	value	value (v4l2)
+ */
+static unsigned long preemphasis_values[] = {
+	FMPE_DISABLED,	V4L2_PREEMPHASIS_DISABLED,
+	FMPE_EU,	V4L2_PREEMPHASIS_50_uS,
+	FMPE_USA,	V4L2_PREEMPHASIS_75_uS,
+};
+
+static int usecs_to_dev(unsigned long usecs, unsigned long const array[],
+			int size)
+{
+	int i;
+	int rval = -EINVAL;
+
+	for (i = 0; i < size / 2; i++)
+		if (array[(i * 2) + 1] >= usecs) {
+			rval = array[i * 2];
+			break;
+		}
+
+	return rval;
+}
+
+/* si4713_handler: IRQ handler, just complete work */
+static irqreturn_t si4713_handler(int irq, void *dev)
+{
+	struct si4713_device *sdev = dev;
+
+	v4l2_dbg(2, debug, &sdev->sd,
+			"%s: sending signal to completion work.\n", __func__);
+	complete(&sdev->work);
+
+	return IRQ_HANDLED;
+}
+
+/*
+ * si4713_send_command - sends a command to si4713 and waits its response
+ * @sdev: si4713_device structure for the device we are communicating
+ * @command: command id
+ * @args: command arguments we are sending (up to 7)
+ * @argn: actual size of @args
+ * @response: buffer to place the expected response from the device (up to 15)
+ * @respn: actual size of @response
+ * @usecs: amount of time to wait before reading the response (in usecs)
+ */
+static int si4713_send_command(struct si4713_device *sdev, const u8 command,
+				const u8 args[], const int argn,
+				u8 response[], const int respn, const int usecs)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
+	u8 data1[MAX_ARGS + 1];
+	int err;
+
+	if (!client->adapter)
+		return -ENODEV;
+
+	/* First send the command and its arguments */
+	data1[0] = command;
+	memcpy(data1 + 1, args, argn);
+	DBG_BUFFER(&sdev->sd, "Parameters", data1, argn + 1);
+
+	err = i2c_master_send(client, data1, argn + 1);
+	if (err != argn + 1) {
+		v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
+			command);
+		return (err > 0) ? -EIO : err;
+	}
+
+	/* Wait response from interrupt */
+	if (!wait_for_completion_timeout(&sdev->work,
+				usecs_to_jiffies(usecs) + 1))
+		v4l2_warn(&sdev->sd,
+				"(%s) Device took too much time to answer.\n",
+				__func__);
+
+	/* Then get the response */
+	err = i2c_master_recv(client, response, respn);
+	if (err != respn) {
+		v4l2_err(&sdev->sd,
+			"Error while reading response for command 0x%02x\n",
+			command);
+		return (err > 0) ? -EIO : err;
+	}
+
+	DBG_BUFFER(&sdev->sd, "Response", response, respn);
+	if (check_command_failed(response[0]))
+		return -EBUSY;
+
+	return 0;
+}
+
+/*
+ * si4713_read_property - reads a si4713 property
+ * @sdev: si4713_device structure for the device we are communicating
+ * @prop: property identification number
+ * @pv: property value to be returned on success
+ */
+static int si4713_read_property(struct si4713_device *sdev, u16 prop, u32 *pv)
+{
+	int err;
+	u8 val[SI4713_GET_PROP_NRESP];
+	/*
+	 * 	.First byte = 0
+	 * 	.Second byte = property's MSB
+	 * 	.Third byte = property's LSB
+	 */
+	const u8 args[SI4713_GET_PROP_NARGS] = {
+		0x00,
+		msb(prop),
+		lsb(prop),
+	};
+
+	err = si4713_send_command(sdev, SI4713_CMD_GET_PROPERTY,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (err < 0)
+		return err;
+
+	*pv = compose_u16(val[2], val[3]);
+
+	v4l2_dbg(1, debug, &sdev->sd,
+			"%s: property=0x%02x value=0x%02x status=0x%02x\n",
+			__func__, prop, *pv, val[0]);
+
+	return err;
+}
+
+/*
+ * si4713_write_property - modifies a si4713 property
+ * @sdev: si4713_device structure for the device we are communicating
+ * @prop: property identification number
+ * @val: new value for that property
+ */
+static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
+{
+	int rval;
+	u8 resp[SI4713_SET_PROP_NRESP];
+	/*
+	 * 	.First byte = 0
+	 * 	.Second byte = property's MSB
+	 * 	.Third byte = property's LSB
+	 * 	.Fourth byte = value's MSB
+	 * 	.Fifth byte = value's LSB
+	 */
+	const u8 args[SI4713_SET_PROP_NARGS] = {
+		0x00,
+		msb(prop),
+		lsb(prop),
+		msb(val),
+		lsb(val),
+	};
+
+	rval = si4713_send_command(sdev, SI4713_CMD_SET_PROPERTY,
+					args, ARRAY_SIZE(args),
+					resp, ARRAY_SIZE(resp),
+					DEFAULT_TIMEOUT);
+
+	if (rval < 0)
+		return rval;
+
+	v4l2_dbg(1, debug, &sdev->sd,
+			"%s: property=0x%02x value=0x%02x status=0x%02x\n",
+			__func__, prop, val, resp[0]);
+
+	/*
+	 * As there is no command response for SET_PROPERTY,
+	 * wait Tcomp time to finish before proceed, in order
+	 * to have property properly set.
+	 */
+	msleep(TIMEOUT_SET_PROPERTY);
+
+	return rval;
+}
+
+/*
+ * si4713_powerup - Powers the device up
+ * @sdev: si4713_device structure for the device we are communicating
+ */
+static int si4713_powerup(struct si4713_device *sdev)
+{
+	int err;
+	u8 resp[SI4713_PWUP_NRESP];
+	/*
+	 * 	.First byte = Enabled interrupts and boot function
+	 * 	.Second byte = Input operation mode
+	 */
+	const u8 args[SI4713_PWUP_NARGS] = {
+		SI4713_PWUP_CTSIEN | SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
+		SI4713_PWUP_OPMOD_ANALOG,
+	};
+
+	if (sdev->power_state)
+		return 0;
+
+	err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
+				    sdev->supplies);
+	if (err) {
+		v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
+		return err;
+	}
+	if (gpio_is_valid(sdev->gpio_reset)) {
+		udelay(50);
+		gpio_set_value(sdev->gpio_reset, 1);
+	}
+
+	err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
+					args, ARRAY_SIZE(args),
+					resp, ARRAY_SIZE(resp),
+					TIMEOUT_POWER_UP);
+
+	if (!err) {
+		v4l2_dbg(1, debug, &sdev->sd, "Powerup response: 0x%02x\n",
+				resp[0]);
+		v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
+		sdev->power_state = POWER_ON;
+
+		err = si4713_write_property(sdev, SI4713_GPO_IEN,
+						SI4713_STC_INT | SI4713_CTS);
+	} else {
+		if (gpio_is_valid(sdev->gpio_reset))
+			gpio_set_value(sdev->gpio_reset, 0);
+		err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
+					     sdev->supplies);
+		if (err)
+			v4l2_err(&sdev->sd,
+				 "Failed to disable supplies: %d\n", err);
+	}
+
+	return err;
+}
+
+/*
+ * si4713_powerdown - Powers the device down
+ * @sdev: si4713_device structure for the device we are communicating
+ */
+static int si4713_powerdown(struct si4713_device *sdev)
+{
+	int err;
+	u8 resp[SI4713_PWDN_NRESP];
+
+	if (!sdev->power_state)
+		return 0;
+
+	err = si4713_send_command(sdev, SI4713_CMD_POWER_DOWN,
+					NULL, 0,
+					resp, ARRAY_SIZE(resp),
+					DEFAULT_TIMEOUT);
+
+	if (!err) {
+		v4l2_dbg(1, debug, &sdev->sd, "Power down response: 0x%02x\n",
+				resp[0]);
+		v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
+		if (gpio_is_valid(sdev->gpio_reset))
+			gpio_set_value(sdev->gpio_reset, 0);
+		err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
+					     sdev->supplies);
+		if (err)
+			v4l2_err(&sdev->sd,
+				 "Failed to disable supplies: %d\n", err);
+		sdev->power_state = POWER_OFF;
+	}
+
+	return err;
+}
+
+/*
+ * si4713_checkrev - Checks if we are treating a device with the correct rev.
+ * @sdev: si4713_device structure for the device we are communicating
+ */
+static int si4713_checkrev(struct si4713_device *sdev)
+{
+	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
+	int rval;
+	u8 resp[SI4713_GETREV_NRESP];
+
+	rval = si4713_send_command(sdev, SI4713_CMD_GET_REV,
+					NULL, 0,
+					resp, ARRAY_SIZE(resp),
+					DEFAULT_TIMEOUT);
+
+	if (rval < 0)
+		return rval;
+
+	if (resp[1] == SI4713_PRODUCT_NUMBER) {
+		v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
+				client->addr << 1, client->adapter->name);
+	} else {
+		v4l2_err(&sdev->sd, "Invalid product number\n");
+		rval = -EINVAL;
+	}
+	return rval;
+}
+
+/*
+ * si4713_wait_stc - Waits STC interrupt and clears status bits. Useful
+ *		     for TX_TUNE_POWER, TX_TUNE_FREQ and TX_TUNE_MEAS
+ * @sdev: si4713_device structure for the device we are communicating
+ * @usecs: timeout to wait for STC interrupt signal
+ */
+static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
+{
+	int err;
+	u8 resp[SI4713_GET_STATUS_NRESP];
+
+	/* Wait response from STC interrupt */
+	if (!wait_for_completion_timeout(&sdev->work,
+			usecs_to_jiffies(usecs) + 1))
+		v4l2_warn(&sdev->sd,
+			"%s: device took too much time to answer (%d usec).\n",
+				__func__, usecs);
+
+	/* Clear status bits */
+	err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
+					NULL, 0,
+					resp, ARRAY_SIZE(resp),
+					DEFAULT_TIMEOUT);
+
+	if (err < 0)
+		goto exit;
+
+	v4l2_dbg(1, debug, &sdev->sd,
+			"%s: status bits: 0x%02x\n", __func__, resp[0]);
+
+	if (!(resp[0] & SI4713_STC_INT))
+		err = -EIO;
+
+exit:
+	return err;
+}
+
+/*
+ * si4713_tx_tune_freq - Sets the state of the RF carrier and sets the tuning
+ * 			frequency between 76 and 108 MHz in 10 kHz units and
+ * 			steps of 50 kHz.
+ * @sdev: si4713_device structure for the device we are communicating
+ * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
+ */
+static int si4713_tx_tune_freq(struct si4713_device *sdev, u16 frequency)
+{
+	int err;
+	u8 val[SI4713_TXFREQ_NRESP];
+	/*
+	 * 	.First byte = 0
+	 * 	.Second byte = frequency's MSB
+	 * 	.Third byte = frequency's LSB
+	 */
+	const u8 args[SI4713_TXFREQ_NARGS] = {
+		0x00,
+		msb(frequency),
+		lsb(frequency),
+	};
+
+	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_FREQ,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (err < 0)
+		return err;
+
+	v4l2_dbg(1, debug, &sdev->sd,
+			"%s: frequency=0x%02x status=0x%02x\n", __func__,
+			frequency, val[0]);
+
+	err = si4713_wait_stc(sdev, TIMEOUT_TX_TUNE);
+	if (err < 0)
+		return err;
+
+	return compose_u16(args[1], args[2]);
+}
+
+/*
+ * si4713_tx_tune_power - Sets the RF voltage level between 88 and 115 dBuV in
+ * 			1 dB units. A value of 0x00 indicates off. The command
+ * 			also sets the antenna tuning capacitance. A value of 0
+ * 			indicates autotuning, and a value of 1 - 191 indicates
+ * 			a manual override, which results in a tuning
+ * 			capacitance of 0.25 pF x @antcap.
+ * @sdev: si4713_device structure for the device we are communicating
+ * @power: tuning power (88 - 115 dBuV, unit/step 1 dB)
+ * @antcap: value of antenna tuning capacitor (0 - 191)
+ */
+static int si4713_tx_tune_power(struct si4713_device *sdev, u8 power,
+				u8 antcap)
+{
+	int err;
+	u8 val[SI4713_TXPWR_NRESP];
+	/*
+	 * 	.First byte = 0
+	 * 	.Second byte = 0
+	 * 	.Third byte = power
+	 * 	.Fourth byte = antcap
+	 */
+	const u8 args[SI4713_TXPWR_NARGS] = {
+		0x00,
+		0x00,
+		power,
+		antcap,
+	};
+
+	if (((power > 0) && (power < SI4713_MIN_POWER)) ||
+		power > SI4713_MAX_POWER || antcap > SI4713_MAX_ANTCAP)
+		return -EDOM;
+
+	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_POWER,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (err < 0)
+		return err;
+
+	v4l2_dbg(1, debug, &sdev->sd,
+			"%s: power=0x%02x antcap=0x%02x status=0x%02x\n",
+			__func__, power, antcap, val[0]);
+
+	return si4713_wait_stc(sdev, TIMEOUT_TX_TUNE_POWER);
+}
+
+/*
+ * si4713_tx_tune_measure - Enters receive mode and measures the received noise
+ * 			level in units of dBuV on the selected frequency.
+ * 			The Frequency must be between 76 and 108 MHz in 10 kHz
+ * 			units and steps of 50 kHz. The command also sets the
+ * 			antenna	tuning capacitance. A value of 0 means
+ * 			autotuning, and a value of 1 to 191 indicates manual
+ * 			override.
+ * @sdev: si4713_device structure for the device we are communicating
+ * @frequency: desired frequency (76 - 108 MHz, unit 10 KHz, step 50 kHz)
+ * @antcap: value of antenna tuning capacitor (0 - 191)
+ */
+static int si4713_tx_tune_measure(struct si4713_device *sdev, u16 frequency,
+					u8 antcap)
+{
+	int err;
+	u8 val[SI4713_TXMEA_NRESP];
+	/*
+	 * 	.First byte = 0
+	 * 	.Second byte = frequency's MSB
+	 * 	.Third byte = frequency's LSB
+	 * 	.Fourth byte = antcap
+	 */
+	const u8 args[SI4713_TXMEA_NARGS] = {
+		0x00,
+		msb(frequency),
+		lsb(frequency),
+		antcap,
+	};
+
+	sdev->tune_rnl = DEFAULT_TUNE_RNL;
+
+	if (antcap > SI4713_MAX_ANTCAP)
+		return -EDOM;
+
+	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_MEASURE,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (err < 0)
+		return err;
+
+	v4l2_dbg(1, debug, &sdev->sd,
+			"%s: frequency=0x%02x antcap=0x%02x status=0x%02x\n",
+			__func__, frequency, antcap, val[0]);
+
+	return si4713_wait_stc(sdev, TIMEOUT_TX_TUNE);
+}
+
+/*
+ * si4713_tx_tune_status- Returns the status of the tx_tune_freq, tx_tune_mea or
+ * 			tx_tune_power commands. This command return the current
+ * 			frequency, output voltage in dBuV, the antenna tunning
+ * 			capacitance value and the received noise level. The
+ * 			command also clears the stcint interrupt bit when the
+ * 			first bit of its arguments is high.
+ * @sdev: si4713_device structure for the device we are communicating
+ * @intack: 0x01 to clear the seek/tune complete interrupt status indicator.
+ * @frequency: returned frequency
+ * @power: returned power
+ * @antcap: returned antenna capacitance
+ * @noise: returned noise level
+ */
+static int si4713_tx_tune_status(struct si4713_device *sdev, u8 intack,
+					u16 *frequency,	u8 *power,
+					u8 *antcap, u8 *noise)
+{
+	int err;
+	u8 val[SI4713_TXSTATUS_NRESP];
+	/*
+	 * 	.First byte = intack bit
+	 */
+	const u8 args[SI4713_TXSTATUS_NARGS] = {
+		intack & SI4713_INTACK_MASK,
+	};
+
+	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_STATUS,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (!err) {
+		v4l2_dbg(1, debug, &sdev->sd,
+			"%s: status=0x%02x\n", __func__, val[0]);
+		*frequency = compose_u16(val[2], val[3]);
+		sdev->frequency = *frequency;
+		*power = val[5];
+		*antcap = val[6];
+		*noise = val[7];
+		v4l2_dbg(1, debug, &sdev->sd, "%s: response: %d x 10 kHz "
+				"(power %d, antcap %d, rnl %d)\n", __func__,
+				*frequency, *power, *antcap, *noise);
+	}
+
+	return err;
+}
+
+/*
+ * si4713_tx_rds_buff - Loads the RDS group buffer FIFO or circular buffer.
+ * @sdev: si4713_device structure for the device we are communicating
+ * @mode: the buffer operation mode.
+ * @rdsb: RDS Block B
+ * @rdsc: RDS Block C
+ * @rdsd: RDS Block D
+ * @cbleft: returns the number of available circular buffer blocks minus the
+ *          number of used circular buffer blocks.
+ */
+static int si4713_tx_rds_buff(struct si4713_device *sdev, u8 mode, u16 rdsb,
+				u16 rdsc, u16 rdsd, s8 *cbleft)
+{
+	int err;
+	u8 val[SI4713_RDSBUFF_NRESP];
+
+	const u8 args[SI4713_RDSBUFF_NARGS] = {
+		mode & SI4713_RDSBUFF_MODE_MASK,
+		msb(rdsb),
+		lsb(rdsb),
+		msb(rdsc),
+		lsb(rdsc),
+		msb(rdsd),
+		lsb(rdsd),
+	};
+
+	err = si4713_send_command(sdev, SI4713_CMD_TX_RDS_BUFF,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (!err) {
+		v4l2_dbg(1, debug, &sdev->sd,
+			"%s: status=0x%02x\n", __func__, val[0]);
+		*cbleft = (s8)val[2] - val[3];
+		v4l2_dbg(1, debug, &sdev->sd, "%s: response: interrupts"
+				" 0x%02x cb avail: %d cb used %d fifo avail"
+				" %d fifo used %d\n", __func__, val[1],
+				val[2], val[3], val[4], val[5]);
+	}
+
+	return err;
+}
+
+/*
+ * si4713_tx_rds_ps - Loads the program service buffer.
+ * @sdev: si4713_device structure for the device we are communicating
+ * @psid: program service id to be loaded.
+ * @pschar: assumed 4 size char array to be loaded into the program service
+ */
+static int si4713_tx_rds_ps(struct si4713_device *sdev, u8 psid,
+				unsigned char *pschar)
+{
+	int err;
+	u8 val[SI4713_RDSPS_NRESP];
+
+	const u8 args[SI4713_RDSPS_NARGS] = {
+		psid & SI4713_RDSPS_PSID_MASK,
+		pschar[0],
+		pschar[1],
+		pschar[2],
+		pschar[3],
+	};
+
+	err = si4713_send_command(sdev, SI4713_CMD_TX_RDS_PS,
+				  args, ARRAY_SIZE(args), val,
+				  ARRAY_SIZE(val), DEFAULT_TIMEOUT);
+
+	if (err < 0)
+		return err;
+
+	v4l2_dbg(1, debug, &sdev->sd, "%s: status=0x%02x\n", __func__, val[0]);
+
+	return err;
+}
+
+static int si4713_set_power_state(struct si4713_device *sdev, u8 value)
+{
+	if (value)
+		return si4713_powerup(sdev);
+	return si4713_powerdown(sdev);
+}
+
+static int si4713_set_mute(struct si4713_device *sdev, u16 mute)
+{
+	int rval = 0;
+
+	mute = set_mute(mute);
+
+	if (sdev->power_state)
+		rval = si4713_write_property(sdev,
+				SI4713_TX_LINE_INPUT_MUTE, mute);
+
+	return rval;
+}
+
+static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
+{
+	int rval = 0, i;
+	u8 len = 0;
+
+	/* We want to clear the whole thing */
+	if (!strlen(ps_name))
+		memset(ps_name, 0, MAX_RDS_PS_NAME + 1);
+
+	if (sdev->power_state) {
+		/* Write the new ps name and clear the padding */
+		for (i = 0; i < MAX_RDS_PS_NAME; i += (RDS_BLOCK / 2)) {
+			rval = si4713_tx_rds_ps(sdev, (i / (RDS_BLOCK / 2)),
+						ps_name + i);
+			if (rval < 0)
+				return rval;
+		}
+
+		/* Setup the size to be sent */
+		if (strlen(ps_name))
+			len = strlen(ps_name) - 1;
+		else
+			len = 1;
+
+		rval = si4713_write_property(sdev,
+				SI4713_TX_RDS_PS_MESSAGE_COUNT,
+				rds_ps_nblocks(len));
+		if (rval < 0)
+			return rval;
+
+		rval = si4713_write_property(sdev,
+				SI4713_TX_RDS_PS_REPEAT_COUNT,
+				DEFAULT_RDS_PS_REPEAT_COUNT * 2);
+		if (rval < 0)
+			return rval;
+	}
+
+	return rval;
+}
+
+static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
+{
+	int rval = 0, i;
+	u16 t_index = 0;
+	u8 b_index = 0, cr_inserted = 0;
+	s8 left;
+
+	if (!sdev->power_state)
+		return rval;
+
+	rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_CLEAR, 0, 0, 0, &left);
+	if (rval < 0)
+		return rval;
+
+	if (!strlen(rt))
+		return rval;
+
+	do {
+		/* RDS spec says that if the last block isn't used,
+		 * then apply a carriage return
+		 */
+		if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {
+			for (i = 0; i < RDS_RADIOTEXT_BLK_SIZE; i++) {
+				if (!rt[t_index + i] ||
+				    rt[t_index + i] == RDS_CARRIAGE_RETURN) {
+					rt[t_index + i] = RDS_CARRIAGE_RETURN;
+					cr_inserted = 1;
+					break;
+				}
+			}
+		}
+
+		rval = si4713_tx_rds_buff(sdev, RDS_BLOCK_LOAD,
+				compose_u16(RDS_RADIOTEXT_2A, b_index++),
+				compose_u16(rt[t_index], rt[t_index + 1]),
+				compose_u16(rt[t_index + 2], rt[t_index + 3]),
+				&left);
+		if (rval < 0)
+			return rval;
+
+		t_index += RDS_RADIOTEXT_BLK_SIZE;
+
+		if (cr_inserted)
+			break;
+	} while (left > 0);
+
+	return rval;
+}
+
+/*
+ * si4713_update_tune_status - update properties from tx_tune_status
+ * command. Must be called with sdev->mutex held.
+ * @sdev: si4713_device structure for the device we are communicating
+ */
+static int si4713_update_tune_status(struct si4713_device *sdev)
+{
+	int rval;
+	u16 f = 0;
+	u8 p = 0, a = 0, n = 0;
+
+	rval = si4713_tx_tune_status(sdev, 0x00, &f, &p, &a, &n);
+
+	if (rval < 0)
+		goto exit;
+
+/*	TODO: check that power_level and antenna_capacitor really are not
+	changed by the hardware. If they are, then these controls should become
+	volatiles.
+	sdev->power_level = p;
+	sdev->antenna_capacitor = a;*/
+	sdev->tune_rnl = n;
+
+exit:
+	return rval;
+}
+
+static int si4713_choose_econtrol_action(struct si4713_device *sdev, u32 id,
+		s32 *bit, s32 *mask, u16 *property, int *mul,
+		unsigned long **table, int *size)
+{
+	s32 rval = 0;
+
+	switch (id) {
+	/* FM_TX class controls */
+	case V4L2_CID_RDS_TX_PI:
+		*property = SI4713_TX_RDS_PI;
+		*mul = 1;
+		break;
+	case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD:
+		*property = SI4713_TX_ACOMP_THRESHOLD;
+		*mul = 1;
+		break;
+	case V4L2_CID_AUDIO_COMPRESSION_GAIN:
+		*property = SI4713_TX_ACOMP_GAIN;
+		*mul = 1;
+		break;
+	case V4L2_CID_PILOT_TONE_FREQUENCY:
+		*property = SI4713_TX_PILOT_FREQUENCY;
+		*mul = 1;
+		break;
+	case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME:
+		*property = SI4713_TX_ACOMP_ATTACK_TIME;
+		*mul = ATTACK_TIME_UNIT;
+		break;
+	case V4L2_CID_PILOT_TONE_DEVIATION:
+		*property = SI4713_TX_PILOT_DEVIATION;
+		*mul = 10;
+		break;
+	case V4L2_CID_AUDIO_LIMITER_DEVIATION:
+		*property = SI4713_TX_AUDIO_DEVIATION;
+		*mul = 10;
+		break;
+	case V4L2_CID_RDS_TX_DEVIATION:
+		*property = SI4713_TX_RDS_DEVIATION;
+		*mul = 1;
+		break;
+
+	case V4L2_CID_RDS_TX_PTY:
+		*property = SI4713_TX_RDS_PS_MISC;
+		*bit = 5;
+		*mask = 0x1F << 5;
+		break;
+	case V4L2_CID_AUDIO_LIMITER_ENABLED:
+		*property = SI4713_TX_ACOMP_ENABLE;
+		*bit = 1;
+		*mask = 1 << 1;
+		break;
+	case V4L2_CID_AUDIO_COMPRESSION_ENABLED:
+		*property = SI4713_TX_ACOMP_ENABLE;
+		*bit = 0;
+		*mask = 1 << 0;
+		break;
+	case V4L2_CID_PILOT_TONE_ENABLED:
+		*property = SI4713_TX_COMPONENT_ENABLE;
+		*bit = 0;
+		*mask = 1 << 0;
+		break;
+
+	case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME:
+		*property = SI4713_TX_LIMITER_RELEASE_TIME;
+		*table = limiter_times;
+		*size = ARRAY_SIZE(limiter_times);
+		break;
+	case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME:
+		*property = SI4713_TX_ACOMP_RELEASE_TIME;
+		*table = acomp_rtimes;
+		*size = ARRAY_SIZE(acomp_rtimes);
+		break;
+	case V4L2_CID_TUNE_PREEMPHASIS:
+		*property = SI4713_TX_PREEMPHASIS;
+		*table = preemphasis_values;
+		*size = ARRAY_SIZE(preemphasis_values);
+		break;
+
+	default:
+		rval = -EINVAL;
+		break;
+	}
+
+	return rval;
+}
+
+static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);
+static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);
+/*
+ * si4713_setup - Sets the device up with current configuration.
+ * @sdev: si4713_device structure for the device we are communicating
+ */
+static int si4713_setup(struct si4713_device *sdev)
+{
+	struct v4l2_frequency f;
+	struct v4l2_modulator vm;
+	int rval;
+
+	/* Device procedure needs to set frequency first */
+	f.tuner = 0;
+	f.frequency = sdev->frequency ? sdev->frequency : DEFAULT_FREQUENCY;
+	f.frequency = si4713_to_v4l2(f.frequency);
+	rval = si4713_s_frequency(&sdev->sd, &f);
+
+	vm.index = 0;
+	if (sdev->stereo)
+		vm.txsubchans = V4L2_TUNER_SUB_STEREO;
+	else
+		vm.txsubchans = V4L2_TUNER_SUB_MONO;
+	if (sdev->rds_enabled)
+		vm.txsubchans |= V4L2_TUNER_SUB_RDS;
+	si4713_s_modulator(&sdev->sd, &vm);
+
+	return rval;
+}
+
+/*
+ * si4713_initialize - Sets the device up with default configuration.
+ * @sdev: si4713_device structure for the device we are communicating
+ */
+static int si4713_initialize(struct si4713_device *sdev)
+{
+	int rval;
+
+	rval = si4713_set_power_state(sdev, POWER_ON);
+	if (rval < 0)
+		return rval;
+
+	rval = si4713_checkrev(sdev);
+	if (rval < 0)
+		return rval;
+
+	rval = si4713_set_power_state(sdev, POWER_OFF);
+	if (rval < 0)
+		return rval;
+
+
+	sdev->frequency = DEFAULT_FREQUENCY;
+	sdev->stereo = 1;
+	sdev->tune_rnl = DEFAULT_TUNE_RNL;
+	return 0;
+}
+
+/* si4713_s_ctrl - set the value of a control */
+static int si4713_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+	struct si4713_device *sdev =
+		container_of(ctrl->handler, struct si4713_device, ctrl_handler);
+	u32 val = 0;
+	s32 bit = 0, mask = 0;
+	u16 property = 0;
+	int mul = 0;
+	unsigned long *table = NULL;
+	int size = 0;
+	bool force = false;
+	int c;
+	int ret = 0;
+
+	if (ctrl->id != V4L2_CID_AUDIO_MUTE)
+		return -EINVAL;
+	if (ctrl->is_new) {
+		if (ctrl->val) {
+			ret = si4713_set_mute(sdev, ctrl->val);
+			if (!ret)
+				ret = si4713_set_power_state(sdev, POWER_DOWN);
+			return ret;
+		}
+		ret = si4713_set_power_state(sdev, POWER_UP);
+		if (!ret)
+			ret = si4713_set_mute(sdev, ctrl->val);
+		if (!ret)
+			ret = si4713_setup(sdev);
+		if (ret)
+			return ret;
+		force = true;
+	}
+
+	if (!sdev->power_state)
+		return 0;
+
+	for (c = 1; !ret && c < ctrl->ncontrols; c++) {
+		ctrl = ctrl->cluster[c];
+
+		if (!force && !ctrl->is_new)
+			continue;
+
+		switch (ctrl->id) {
+		case V4L2_CID_RDS_TX_PS_NAME:
+			ret = si4713_set_rds_ps_name(sdev, ctrl->string);
+			break;
+
+		case V4L2_CID_RDS_TX_RADIO_TEXT:
+			ret = si4713_set_rds_radio_text(sdev, ctrl->string);
+			break;
+
+		case V4L2_CID_TUNE_ANTENNA_CAPACITOR:
+			/* don't handle this control if we force setting all
+			 * controls since in that case it will be handled by
+			 * V4L2_CID_TUNE_POWER_LEVEL. */
+			if (force)
+				break;
+			/* fall through */
+		case V4L2_CID_TUNE_POWER_LEVEL:
+			ret = si4713_tx_tune_power(sdev,
+				sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);
+			if (!ret) {
+				/* Make sure we don't set this twice */
+				sdev->tune_ant_cap->is_new = false;
+				sdev->tune_pwr_level->is_new = false;
+			}
+			break;
+
+		default:
+			ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,
+					&mask, &property, &mul, &table, &size);
+			if (ret < 0)
+				break;
+
+			val = ctrl->val;
+			if (mul) {
+				val = val / mul;
+			} else if (table) {
+				ret = usecs_to_dev(val, table, size);
+				if (ret < 0)
+					break;
+				val = ret;
+				ret = 0;
+			}
+
+			if (mask) {
+				ret = si4713_read_property(sdev, property, &val);
+				if (ret < 0)
+					break;
+				val = set_bits(val, ctrl->val, bit, mask);
+			}
+
+			ret = si4713_write_property(sdev, property, val);
+			if (ret < 0)
+				break;
+			if (mask)
+				val = ctrl->val;
+			break;
+		}
+	}
+
+	return ret;
+}
+
+/* si4713_ioctl - deal with private ioctls (only rnl for now) */
+static long si4713_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
+{
+	struct si4713_device *sdev = to_si4713_device(sd);
+	struct si4713_rnl *rnl = arg;
+	u16 frequency;
+	int rval = 0;
+
+	if (!arg)
+		return -EINVAL;
+
+	switch (cmd) {
+	case SI4713_IOC_MEASURE_RNL:
+		frequency = v4l2_to_si4713(rnl->frequency);
+
+		if (sdev->power_state) {
+			/* Set desired measurement frequency */
+			rval = si4713_tx_tune_measure(sdev, frequency, 0);
+			if (rval < 0)
+				return rval;
+			/* get results from tune status */
+			rval = si4713_update_tune_status(sdev);
+			if (rval < 0)
+				return rval;
+		}
+		rnl->rnl = sdev->tune_rnl;
+		break;
+
+	default:
+		/* nothing */
+		rval = -ENOIOCTLCMD;
+	}
+
+	return rval;
+}
+
+/* si4713_g_modulator - get modulator attributes */
+static int si4713_g_modulator(struct v4l2_subdev *sd, struct v4l2_modulator *vm)
+{
+	struct si4713_device *sdev = to_si4713_device(sd);
+	int rval = 0;
+
+	if (!sdev)
+		return -ENODEV;
+
+	if (vm->index > 0)
+		return -EINVAL;
+
+	strncpy(vm->name, "FM Modulator", 32);
+	vm->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW |
+		V4L2_TUNER_CAP_RDS | V4L2_TUNER_CAP_RDS_CONTROLS;
+
+	/* Report current frequency range limits */
+	vm->rangelow = si4713_to_v4l2(FREQ_RANGE_LOW);
+	vm->rangehigh = si4713_to_v4l2(FREQ_RANGE_HIGH);
+
+	if (sdev->power_state) {
+		u32 comp_en = 0;
+
+		rval = si4713_read_property(sdev, SI4713_TX_COMPONENT_ENABLE,
+						&comp_en);
+		if (rval < 0)
+			return rval;
+
+		sdev->stereo = get_status_bit(comp_en, 1, 1 << 1);
+	}
+
+	/* Report current audio mode: mono or stereo */
+	if (sdev->stereo)
+		vm->txsubchans = V4L2_TUNER_SUB_STEREO;
+	else
+		vm->txsubchans = V4L2_TUNER_SUB_MONO;
+
+	/* Report rds feature status */
+	if (sdev->rds_enabled)
+		vm->txsubchans |= V4L2_TUNER_SUB_RDS;
+	else
+		vm->txsubchans &= ~V4L2_TUNER_SUB_RDS;
+
+	return rval;
+}
+
+/* si4713_s_modulator - set modulator attributes */
+static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)
+{
+	struct si4713_device *sdev = to_si4713_device(sd);
+	int rval = 0;
+	u16 stereo, rds;
+	u32 p;
+
+	if (!sdev)
+		return -ENODEV;
+
+	if (vm->index > 0)
+		return -EINVAL;
+
+	/* Set audio mode: mono or stereo */
+	if (vm->txsubchans & V4L2_TUNER_SUB_STEREO)
+		stereo = 1;
+	else if (vm->txsubchans & V4L2_TUNER_SUB_MONO)
+		stereo = 0;
+	else
+		return -EINVAL;
+
+	rds = !!(vm->txsubchans & V4L2_TUNER_SUB_RDS);
+
+	if (sdev->power_state) {
+		rval = si4713_read_property(sdev,
+						SI4713_TX_COMPONENT_ENABLE, &p);
+		if (rval < 0)
+			return rval;
+
+		p = set_bits(p, stereo, 1, 1 << 1);
+		p = set_bits(p, rds, 2, 1 << 2);
+
+		rval = si4713_write_property(sdev,
+						SI4713_TX_COMPONENT_ENABLE, p);
+		if (rval < 0)
+			return rval;
+	}
+
+	sdev->stereo = stereo;
+	sdev->rds_enabled = rds;
+
+	return rval;
+}
+
+/* si4713_g_frequency - get tuner or modulator radio frequency */
+static int si4713_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f)
+{
+	struct si4713_device *sdev = to_si4713_device(sd);
+	int rval = 0;
+
+	if (f->tuner)
+		return -EINVAL;
+
+	if (sdev->power_state) {
+		u16 freq;
+		u8 p, a, n;
+
+		rval = si4713_tx_tune_status(sdev, 0x00, &freq, &p, &a, &n);
+		if (rval < 0)
+			return rval;
+
+		sdev->frequency = freq;
+	}
+
+	f->frequency = si4713_to_v4l2(sdev->frequency);
+
+	return rval;
+}
+
+/* si4713_s_frequency - set tuner or modulator radio frequency */
+static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
+{
+	struct si4713_device *sdev = to_si4713_device(sd);
+	int rval = 0;
+	u16 frequency = v4l2_to_si4713(f->frequency);
+
+	if (f->tuner)
+		return -EINVAL;
+
+	/* Check frequency range */
+	frequency = clamp_t(u16, frequency, FREQ_RANGE_LOW, FREQ_RANGE_HIGH);
+
+	if (sdev->power_state) {
+		rval = si4713_tx_tune_freq(sdev, frequency);
+		if (rval < 0)
+			return rval;
+		frequency = rval;
+		rval = 0;
+	}
+	sdev->frequency = frequency;
+
+	return rval;
+}
+
+static const struct v4l2_ctrl_ops si4713_ctrl_ops = {
+	.s_ctrl = si4713_s_ctrl,
+};
+
+static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = {
+	.ioctl		= si4713_ioctl,
+};
+
+static const struct v4l2_subdev_tuner_ops si4713_subdev_tuner_ops = {
+	.g_frequency	= si4713_g_frequency,
+	.s_frequency	= si4713_s_frequency,
+	.g_modulator	= si4713_g_modulator,
+	.s_modulator	= si4713_s_modulator,
+};
+
+static const struct v4l2_subdev_ops si4713_subdev_ops = {
+	.core		= &si4713_subdev_core_ops,
+	.tuner		= &si4713_subdev_tuner_ops,
+};
+
+/*
+ * I2C driver interface
+ */
+/* si4713_probe - probe for the device */
+static int si4713_probe(struct i2c_client *client,
+					const struct i2c_device_id *id)
+{
+	struct si4713_device *sdev;
+	struct si4713_platform_data *pdata = client->dev.platform_data;
+	struct v4l2_ctrl_handler *hdl;
+	int rval, i;
+
+	sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
+	if (!sdev) {
+		dev_err(&client->dev, "Failed to alloc video device.\n");
+		rval = -ENOMEM;
+		goto exit;
+	}
+
+	sdev->gpio_reset = -1;
+	if (pdata && gpio_is_valid(pdata->gpio_reset)) {
+		rval = gpio_request(pdata->gpio_reset, "si4713 reset");
+		if (rval) {
+			dev_err(&client->dev,
+				"Failed to request gpio: %d\n", rval);
+			goto free_sdev;
+		}
+		sdev->gpio_reset = pdata->gpio_reset;
+		gpio_direction_output(sdev->gpio_reset, 0);
+	}
+
+	for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
+		sdev->supplies[i].supply = si4713_supply_names[i];
+
+	rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
+				  sdev->supplies);
+	if (rval) {
+		dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
+		goto free_gpio;
+	}
+
+	v4l2_i2c_subdev_init(&sdev->sd, client, &si4713_subdev_ops);
+
+	init_completion(&sdev->work);
+
+	hdl = &sdev->ctrl_handler;
+	v4l2_ctrl_handler_init(hdl, 20);
+	sdev->mute = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_MUTE, 0, 1, 1, DEFAULT_MUTE);
+
+	sdev->rds_pi = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_RDS_TX_PI, 0, 0xffff, 1, DEFAULT_RDS_PI);
+	sdev->rds_pty = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_RDS_TX_PTY, 0, 31, 1, DEFAULT_RDS_PTY);
+	sdev->rds_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_RDS_TX_DEVIATION, 0, MAX_RDS_DEVIATION,
+			10, DEFAULT_RDS_DEVIATION);
+	/*
+	 * Report step as 8. From RDS spec, psname
+	 * should be 8. But there are receivers which scroll strings
+	 * sized as 8xN.
+	 */
+	sdev->rds_ps_name = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_RDS_TX_PS_NAME, 0, MAX_RDS_PS_NAME, 8, 0);
+	/*
+	 * Report step as 32 (2A block). From RDS spec,
+	 * radio text should be 32 for 2A block. But there are receivers
+	 * which scroll strings sized as 32xN. Setting default to 32.
+	 */
+	sdev->rds_radio_text = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);
+
+	sdev->limiter_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_LIMITER_ENABLED, 0, 1, 1, 1);
+	sdev->limiter_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_LIMITER_RELEASE_TIME, 250,
+			MAX_LIMITER_RELEASE_TIME, 10, DEFAULT_LIMITER_RTIME);
+	sdev->limiter_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_LIMITER_DEVIATION, 0,
+			MAX_LIMITER_DEVIATION, 10, DEFAULT_LIMITER_DEV);
+
+	sdev->compression_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_COMPRESSION_ENABLED, 0, 1, 1, 1);
+	sdev->compression_gain = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_COMPRESSION_GAIN, 0, MAX_ACOMP_GAIN, 1,
+			DEFAULT_ACOMP_GAIN);
+	sdev->compression_threshold = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,
+			MAX_ACOMP_THRESHOLD, 1,
+			DEFAULT_ACOMP_THRESHOLD);
+	sdev->compression_attack_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME, 0,
+			MAX_ACOMP_ATTACK_TIME, 500, DEFAULT_ACOMP_ATIME);
+	sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME, 100000,
+			MAX_ACOMP_RELEASE_TIME, 100000, DEFAULT_ACOMP_RTIME);
+
+	sdev->pilot_tone_enabled = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_PILOT_TONE_ENABLED, 0, 1, 1, 1);
+	sdev->pilot_tone_deviation = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_PILOT_TONE_DEVIATION, 0, MAX_PILOT_DEVIATION,
+			10, DEFAULT_PILOT_DEVIATION);
+	sdev->pilot_tone_freq = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_PILOT_TONE_FREQUENCY, 0, MAX_PILOT_FREQUENCY,
+			1, DEFAULT_PILOT_FREQUENCY);
+
+	sdev->tune_preemphasis = v4l2_ctrl_new_std_menu(hdl, &si4713_ctrl_ops,
+			V4L2_CID_TUNE_PREEMPHASIS,
+			V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
+	sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);
+	sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
+			V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, 191, 1, 0);
+
+	if (hdl->error) {
+		rval = hdl->error;
+		goto free_ctrls;
+	}
+	v4l2_ctrl_cluster(20, &sdev->mute);
+	sdev->sd.ctrl_handler = hdl;
+
+	if (client->irq) {
+		rval = request_irq(client->irq,
+			si4713_handler, IRQF_TRIGGER_FALLING | IRQF_DISABLED,
+			client->name, sdev);
+		if (rval < 0) {
+			v4l2_err(&sdev->sd, "Could not request IRQ\n");
+			goto put_reg;
+		}
+		v4l2_dbg(1, debug, &sdev->sd, "IRQ requested.\n");
+	} else {
+		v4l2_warn(&sdev->sd, "IRQ not configured. Using timeouts.\n");
+	}
+
+	rval = si4713_initialize(sdev);
+	if (rval < 0) {
+		v4l2_err(&sdev->sd, "Failed to probe device information.\n");
+		goto free_irq;
+	}
+
+	return 0;
+
+free_irq:
+	if (client->irq)
+		free_irq(client->irq, sdev);
+free_ctrls:
+	v4l2_ctrl_handler_free(hdl);
+put_reg:
+	regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
+free_gpio:
+	if (gpio_is_valid(sdev->gpio_reset))
+		gpio_free(sdev->gpio_reset);
+free_sdev:
+	kfree(sdev);
+exit:
+	return rval;
+}
+
+/* si4713_remove - remove the device */
+static int si4713_remove(struct i2c_client *client)
+{
+	struct v4l2_subdev *sd = i2c_get_clientdata(client);
+	struct si4713_device *sdev = to_si4713_device(sd);
+
+	if (sdev->power_state)
+		si4713_set_power_state(sdev, POWER_DOWN);
+
+	if (client->irq > 0)
+		free_irq(client->irq, sdev);
+
+	v4l2_device_unregister_subdev(sd);
+	v4l2_ctrl_handler_free(sd->ctrl_handler);
+	regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
+	if (gpio_is_valid(sdev->gpio_reset))
+		gpio_free(sdev->gpio_reset);
+	kfree(sdev);
+
+	return 0;
+}
+
+/* si4713_i2c_driver - i2c driver interface */
+static const struct i2c_device_id si4713_id[] = {
+	{ "si4713" , 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(i2c, si4713_id);
+
+static struct i2c_driver si4713_i2c_driver = {
+	.driver		= {
+		.name	= "si4713",
+	},
+	.probe		= si4713_probe,
+	.remove         = si4713_remove,
+	.id_table       = si4713_id,
+};
+
+module_i2c_driver(si4713_i2c_driver);
diff --git a/drivers/media/radio/si4713/si4713.h b/drivers/media/radio/si4713/si4713.h
new file mode 100644
index 0000000..c274e1f
--- /dev/null
+++ b/drivers/media/radio/si4713/si4713.h
@@ -0,0 +1,238 @@
+/*
+ * drivers/media/radio/si4713.h
+ *
+ * Property and commands definitions for Si4713 radio transmitter chip.
+ *
+ * Copyright (c) 2008 Instituto Nokia de Tecnologia - INdT
+ * Contact: Eduardo Valentin <eduardo.valentin@nokia.com>
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ *
+ */
+
+#ifndef SI4713_I2C_H
+#define SI4713_I2C_H
+
+#include <media/v4l2-subdev.h>
+#include <media/v4l2-ctrls.h>
+#include <media/si4713.h>
+
+#define SI4713_PRODUCT_NUMBER		0x0D
+
+/* Command Timeouts */
+#define DEFAULT_TIMEOUT			500
+#define TIMEOUT_SET_PROPERTY		20
+#define TIMEOUT_TX_TUNE_POWER		30000
+#define TIMEOUT_TX_TUNE			110000
+#define TIMEOUT_POWER_UP		200000
+
+/*
+ * Command and its arguments definitions
+ */
+#define SI4713_PWUP_CTSIEN		(1<<7)
+#define SI4713_PWUP_GPO2OEN		(1<<6)
+#define SI4713_PWUP_PATCH		(1<<5)
+#define SI4713_PWUP_XOSCEN		(1<<4)
+#define SI4713_PWUP_FUNC_TX		0x02
+#define SI4713_PWUP_FUNC_PATCH		0x0F
+#define SI4713_PWUP_OPMOD_ANALOG	0x50
+#define SI4713_PWUP_OPMOD_DIGITAL	0x0F
+#define SI4713_PWUP_NARGS		2
+#define SI4713_PWUP_NRESP		1
+#define SI4713_CMD_POWER_UP		0x01
+
+#define SI4713_GETREV_NRESP		9
+#define SI4713_CMD_GET_REV		0x10
+
+#define SI4713_PWDN_NRESP		1
+#define SI4713_CMD_POWER_DOWN		0x11
+
+#define SI4713_SET_PROP_NARGS		5
+#define SI4713_SET_PROP_NRESP		1
+#define SI4713_CMD_SET_PROPERTY		0x12
+
+#define SI4713_GET_PROP_NARGS		3
+#define SI4713_GET_PROP_NRESP		4
+#define SI4713_CMD_GET_PROPERTY		0x13
+
+#define SI4713_GET_STATUS_NRESP		1
+#define SI4713_CMD_GET_INT_STATUS	0x14
+
+#define SI4713_CMD_PATCH_ARGS		0x15
+#define SI4713_CMD_PATCH_DATA		0x16
+
+#define SI4713_MAX_FREQ			10800
+#define SI4713_MIN_FREQ			7600
+#define SI4713_TXFREQ_NARGS		3
+#define SI4713_TXFREQ_NRESP		1
+#define SI4713_CMD_TX_TUNE_FREQ		0x30
+
+#define SI4713_MAX_POWER		120
+#define SI4713_MIN_POWER		88
+#define SI4713_MAX_ANTCAP		191
+#define SI4713_MIN_ANTCAP		0
+#define SI4713_TXPWR_NARGS		4
+#define SI4713_TXPWR_NRESP		1
+#define SI4713_CMD_TX_TUNE_POWER	0x31
+
+#define SI4713_TXMEA_NARGS		4
+#define SI4713_TXMEA_NRESP		1
+#define SI4713_CMD_TX_TUNE_MEASURE	0x32
+
+#define SI4713_INTACK_MASK		0x01
+#define SI4713_TXSTATUS_NARGS		1
+#define SI4713_TXSTATUS_NRESP		8
+#define SI4713_CMD_TX_TUNE_STATUS	0x33
+
+#define SI4713_OVERMOD_BIT		(1 << 2)
+#define SI4713_IALH_BIT			(1 << 1)
+#define SI4713_IALL_BIT			(1 << 0)
+#define SI4713_ASQSTATUS_NARGS		1
+#define SI4713_ASQSTATUS_NRESP		5
+#define SI4713_CMD_TX_ASQ_STATUS	0x34
+
+#define SI4713_RDSBUFF_MODE_MASK	0x87
+#define SI4713_RDSBUFF_NARGS		7
+#define SI4713_RDSBUFF_NRESP		6
+#define SI4713_CMD_TX_RDS_BUFF		0x35
+
+#define SI4713_RDSPS_PSID_MASK		0x1F
+#define SI4713_RDSPS_NARGS		5
+#define SI4713_RDSPS_NRESP		1
+#define SI4713_CMD_TX_RDS_PS		0x36
+
+#define SI4713_CMD_GPO_CTL		0x80
+#define SI4713_CMD_GPO_SET		0x81
+
+/*
+ * Bits from status response
+ */
+#define SI4713_CTS			(1<<7)
+#define SI4713_ERR			(1<<6)
+#define SI4713_RDS_INT			(1<<2)
+#define SI4713_ASQ_INT			(1<<1)
+#define SI4713_STC_INT			(1<<0)
+
+/*
+ * Property definitions
+ */
+#define SI4713_GPO_IEN			0x0001
+#define SI4713_DIG_INPUT_FORMAT		0x0101
+#define SI4713_DIG_INPUT_SAMPLE_RATE	0x0103
+#define SI4713_REFCLK_FREQ		0x0201
+#define SI4713_REFCLK_PRESCALE		0x0202
+#define SI4713_TX_COMPONENT_ENABLE	0x2100
+#define SI4713_TX_AUDIO_DEVIATION	0x2101
+#define SI4713_TX_PILOT_DEVIATION	0x2102
+#define SI4713_TX_RDS_DEVIATION		0x2103
+#define SI4713_TX_LINE_INPUT_LEVEL	0x2104
+#define SI4713_TX_LINE_INPUT_MUTE	0x2105
+#define SI4713_TX_PREEMPHASIS		0x2106
+#define SI4713_TX_PILOT_FREQUENCY	0x2107
+#define SI4713_TX_ACOMP_ENABLE		0x2200
+#define SI4713_TX_ACOMP_THRESHOLD	0x2201
+#define SI4713_TX_ACOMP_ATTACK_TIME	0x2202
+#define SI4713_TX_ACOMP_RELEASE_TIME	0x2203
+#define SI4713_TX_ACOMP_GAIN		0x2204
+#define SI4713_TX_LIMITER_RELEASE_TIME	0x2205
+#define SI4713_TX_ASQ_INTERRUPT_SOURCE	0x2300
+#define SI4713_TX_ASQ_LEVEL_LOW		0x2301
+#define SI4713_TX_ASQ_DURATION_LOW	0x2302
+#define SI4713_TX_ASQ_LEVEL_HIGH	0x2303
+#define SI4713_TX_ASQ_DURATION_HIGH	0x2304
+#define SI4713_TX_RDS_INTERRUPT_SOURCE	0x2C00
+#define SI4713_TX_RDS_PI		0x2C01
+#define SI4713_TX_RDS_PS_MIX		0x2C02
+#define SI4713_TX_RDS_PS_MISC		0x2C03
+#define SI4713_TX_RDS_PS_REPEAT_COUNT	0x2C04
+#define SI4713_TX_RDS_PS_MESSAGE_COUNT	0x2C05
+#define SI4713_TX_RDS_PS_AF		0x2C06
+#define SI4713_TX_RDS_FIFO_SIZE		0x2C07
+
+#define PREEMPHASIS_USA			75
+#define PREEMPHASIS_EU			50
+#define PREEMPHASIS_DISABLED		0
+#define FMPE_USA			0x00
+#define FMPE_EU				0x01
+#define FMPE_DISABLED			0x02
+
+#define POWER_UP			0x01
+#define POWER_DOWN			0x00
+
+#define MAX_RDS_PTY			31
+#define MAX_RDS_DEVIATION		90000
+
+/*
+ * PSNAME is known to be defined as 8 character sized (RDS Spec).
+ * However, there is receivers which scroll PSNAME 8xN sized.
+ */
+#define MAX_RDS_PS_NAME			96
+
+/*
+ * MAX_RDS_RADIO_TEXT is known to be defined as 32 (2A group) or 64 (2B group)
+ * character sized (RDS Spec).
+ * However, there is receivers which scroll them as well.
+ */
+#define MAX_RDS_RADIO_TEXT		384
+
+#define MAX_LIMITER_RELEASE_TIME	102390
+#define MAX_LIMITER_DEVIATION		90000
+
+#define MAX_PILOT_DEVIATION		90000
+#define MAX_PILOT_FREQUENCY		19000
+
+#define MAX_ACOMP_RELEASE_TIME		1000000
+#define MAX_ACOMP_ATTACK_TIME		5000
+#define MAX_ACOMP_THRESHOLD		0
+#define MIN_ACOMP_THRESHOLD		(-40)
+#define MAX_ACOMP_GAIN			20
+
+#define SI4713_NUM_SUPPLIES		2
+
+/*
+ * si4713_device - private data
+ */
+struct si4713_device {
+	/* v4l2_subdev and i2c reference (v4l2_subdev priv data) */
+	struct v4l2_subdev sd;
+	struct v4l2_ctrl_handler ctrl_handler;
+	/* private data structures */
+	struct { /* si4713 control cluster */
+		/* This is one big cluster since the mute control
+		 * powers off the device and after unmuting again all
+		 * controls need to be set at once. The only way of doing
+		 * that is by making it one big cluster. */
+		struct v4l2_ctrl *mute;
+		struct v4l2_ctrl *rds_ps_name;
+		struct v4l2_ctrl *rds_radio_text;
+		struct v4l2_ctrl *rds_pi;
+		struct v4l2_ctrl *rds_deviation;
+		struct v4l2_ctrl *rds_pty;
+		struct v4l2_ctrl *compression_enabled;
+		struct v4l2_ctrl *compression_threshold;
+		struct v4l2_ctrl *compression_gain;
+		struct v4l2_ctrl *compression_attack_time;
+		struct v4l2_ctrl *compression_release_time;
+		struct v4l2_ctrl *pilot_tone_enabled;
+		struct v4l2_ctrl *pilot_tone_freq;
+		struct v4l2_ctrl *pilot_tone_deviation;
+		struct v4l2_ctrl *limiter_enabled;
+		struct v4l2_ctrl *limiter_deviation;
+		struct v4l2_ctrl *limiter_release_time;
+		struct v4l2_ctrl *tune_preemphasis;
+		struct v4l2_ctrl *tune_pwr_level;
+		struct v4l2_ctrl *tune_ant_cap;
+	};
+	struct completion work;
+	struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
+	int gpio_reset;
+	u32 power_state;
+	u32 rds_enabled;
+	u32 frequency;
+	u32 preemphasis;
+	u32 stereo;
+	u32 tune_rnl;
+};
+#endif /* ifndef SI4713_I2C_H */
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-12-03 15:35     ` Mauro Carvalho Chehab
  2013-10-15 15:24   ` [REVIEW PATCH 3/9] si4713 : Reorganized includes in si4713.c/h Dinesh Ram
                     ` (7 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram

Checks have been introduced at several places in the code to test if an interrupt is set or not.
For devices which do not use the interrupt, to get a valid response, within a specified timeout,
the device is polled instead.

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 drivers/media/radio/si4713/si4713.c |  108 +++++++++++++++++++++--------------
 1 file changed, 64 insertions(+), 44 deletions(-)

diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
index ac727e3..24ae41d 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -27,11 +27,11 @@
 #include <linux/i2c.h>
 #include <linux/slab.h>
 #include <linux/gpio.h>
-#include <linux/regulator/consumer.h>
 #include <linux/module.h>
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-common.h>
+#include <linux/regulator/consumer.h>
 
 #include "si4713.h"
 
@@ -213,6 +213,7 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
 				u8 response[], const int respn, const int usecs)
 {
 	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
+	unsigned long until_jiffies;
 	u8 data1[MAX_ARGS + 1];
 	int err;
 
@@ -228,30 +229,39 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
 	if (err != argn + 1) {
 		v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
 			command);
-		return (err > 0) ? -EIO : err;
+		return err < 0 ? err : -EIO;
 	}
 
+	until_jiffies = jiffies + usecs_to_jiffies(usecs) + 1;
+
 	/* Wait response from interrupt */
-	if (!wait_for_completion_timeout(&sdev->work,
+	if (client->irq) {
+		if (!wait_for_completion_timeout(&sdev->work,
 				usecs_to_jiffies(usecs) + 1))
-		v4l2_warn(&sdev->sd,
+			v4l2_warn(&sdev->sd,
 				"(%s) Device took too much time to answer.\n",
 				__func__);
-
-	/* Then get the response */
-	err = i2c_master_recv(client, response, respn);
-	if (err != respn) {
-		v4l2_err(&sdev->sd,
-			"Error while reading response for command 0x%02x\n",
-			command);
-		return (err > 0) ? -EIO : err;
 	}
 
-	DBG_BUFFER(&sdev->sd, "Response", response, respn);
-	if (check_command_failed(response[0]))
-		return -EBUSY;
+	do {
+		err = i2c_master_recv(client, response, respn);
+		if (err != respn) {
+			v4l2_err(&sdev->sd,
+				"Error %d while reading response for command 0x%02x\n",
+				err, command);
+			return err < 0 ? err : -EIO;
+		}
+
+		DBG_BUFFER(&sdev->sd, "Response", response, respn);
+		if (!check_command_failed(response[0]))
+			return 0;
 
-	return 0;
+		if (client->irq)
+			return -EBUSY;
+		msleep(1);
+	} while (jiffies <= until_jiffies);
+
+	return -EBUSY;
 }
 
 /*
@@ -344,14 +354,15 @@ static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
  */
 static int si4713_powerup(struct si4713_device *sdev)
 {
+	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
 	int err;
 	u8 resp[SI4713_PWUP_NRESP];
 	/*
 	 * 	.First byte = Enabled interrupts and boot function
 	 * 	.Second byte = Input operation mode
 	 */
-	const u8 args[SI4713_PWUP_NARGS] = {
-		SI4713_PWUP_CTSIEN | SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
+	u8 args[SI4713_PWUP_NARGS] = {
+		SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
 		SI4713_PWUP_OPMOD_ANALOG,
 	};
 
@@ -369,6 +380,9 @@ static int si4713_powerup(struct si4713_device *sdev)
 		gpio_set_value(sdev->gpio_reset, 1);
 	}
 
+	if (client->irq)
+		args[0] |= SI4713_PWUP_CTSIEN;
+
 	err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
 					args, ARRAY_SIZE(args),
 					resp, ARRAY_SIZE(resp),
@@ -380,7 +394,8 @@ static int si4713_powerup(struct si4713_device *sdev)
 		v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
 		sdev->power_state = POWER_ON;
 
-		err = si4713_write_property(sdev, SI4713_GPO_IEN,
+		if (client->irq)
+			err = si4713_write_property(sdev, SI4713_GPO_IEN,
 						SI4713_STC_INT | SI4713_CTS);
 	} else {
 		if (gpio_is_valid(sdev->gpio_reset))
@@ -465,33 +480,39 @@ static int si4713_checkrev(struct si4713_device *sdev)
  */
 static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
 {
-	int err;
+	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
 	u8 resp[SI4713_GET_STATUS_NRESP];
+	unsigned long start_jiffies = jiffies;
+	int err;
 
-	/* Wait response from STC interrupt */
-	if (!wait_for_completion_timeout(&sdev->work,
-			usecs_to_jiffies(usecs) + 1))
+	if (client->irq &&
+	    !wait_for_completion_timeout(&sdev->work, usecs_to_jiffies(usecs) + 1))
 		v4l2_warn(&sdev->sd,
-			"%s: device took too much time to answer (%d usec).\n",
-				__func__, usecs);
-
-	/* Clear status bits */
-	err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
-					NULL, 0,
-					resp, ARRAY_SIZE(resp),
-					DEFAULT_TIMEOUT);
-
-	if (err < 0)
-		goto exit;
-
-	v4l2_dbg(1, debug, &sdev->sd,
-			"%s: status bits: 0x%02x\n", __func__, resp[0]);
-
-	if (!(resp[0] & SI4713_STC_INT))
-		err = -EIO;
-
-exit:
-	return err;
+			"(%s) Device took too much time to answer.\n", __func__);
+
+	for (;;) {
+		/* Clear status bits */
+		err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
+				NULL, 0,
+				resp, ARRAY_SIZE(resp),
+				DEFAULT_TIMEOUT);
+		/* The USB device returns errors when it waits for the
+		 * STC bit to be set. Hence polling */
+		if (err >= 0) {
+			v4l2_dbg(1, debug, &sdev->sd,
+				"%s: status bits: 0x%02x\n", __func__, resp[0]);
+
+			if (resp[0] & SI4713_STC_INT)
+				return 0;
+		}
+		if (jiffies_to_usecs(jiffies - start_jiffies) > usecs)
+			return err < 0 ? err : -EIO;
+		/* We sleep here for 3 ms in order to avoid flooding the device
+		 * with USB requests. The si4713 USB driver was developed
+		 * by reverse engineering the Windows USB driver. The windows
+		 * driver also has a ~2.5 ms delay between responses. */
+		msleep(3);
+	}
 }
 
 /*
@@ -1024,7 +1045,6 @@ static int si4713_initialize(struct si4713_device *sdev)
 	if (rval < 0)
 		return rval;
 
-
 	sdev->frequency = DEFAULT_FREQUENCY;
 	sdev->stereo = 1;
 	sdev->tune_rnl = DEFAULT_TUNE_RNL;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 3/9] si4713 : Reorganized includes in si4713.c/h
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 4/9] si4713 : Bug fix for si4713_tx_tune_power() method in the i2c driver Dinesh Ram
                     ` (6 subsequent siblings)
  8 siblings, 0 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram

Moved the header <linux/regulator/consumer.h> from si4713.c to si4713.h

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 drivers/media/radio/si4713/si4713.c |    1 -
 drivers/media/radio/si4713/si4713.h |    1 +
 2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
index 24ae41d..1da9364 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -31,7 +31,6 @@
 #include <media/v4l2-device.h>
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-common.h>
-#include <linux/regulator/consumer.h>
 
 #include "si4713.h"
 
diff --git a/drivers/media/radio/si4713/si4713.h b/drivers/media/radio/si4713/si4713.h
index c274e1f..dc0ce66 100644
--- a/drivers/media/radio/si4713/si4713.h
+++ b/drivers/media/radio/si4713/si4713.h
@@ -15,6 +15,7 @@
 #ifndef SI4713_I2C_H
 #define SI4713_I2C_H
 
+#include <linux/regulator/consumer.h>
 #include <media/v4l2-subdev.h>
 #include <media/v4l2-ctrls.h>
 #include <media/si4713.h>
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 4/9] si4713 : Bug fix for si4713_tx_tune_power() method in the i2c driver
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 3/9] si4713 : Reorganized includes in si4713.c/h Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 5/9] si4713 : HID blacklist Si4713 USB development board Dinesh Ram
                     ` (5 subsequent siblings)
  8 siblings, 0 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram

In the si4713_tx_tune_power() method, the args array element 'power'
can take values between SI4713_MIN_POWER and SI4713_MAX_POWER. power = 0
is also valid. All the values (0 > power < SI4713_MIN_POWER) are illegal
and hence are all mapped to SI4713_MIN_POWER.

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 drivers/media/radio/si4713/si4713.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
index 1da9364..d297a5b 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -555,14 +555,14 @@ static int si4713_tx_tune_freq(struct si4713_device *sdev, u16 frequency)
 }
 
 /*
- * si4713_tx_tune_power - Sets the RF voltage level between 88 and 115 dBuV in
+ * si4713_tx_tune_power - Sets the RF voltage level between 88 and 120 dBuV in
  * 			1 dB units. A value of 0x00 indicates off. The command
  * 			also sets the antenna tuning capacitance. A value of 0
  * 			indicates autotuning, and a value of 1 - 191 indicates
  * 			a manual override, which results in a tuning
  * 			capacitance of 0.25 pF x @antcap.
  * @sdev: si4713_device structure for the device we are communicating
- * @power: tuning power (88 - 115 dBuV, unit/step 1 dB)
+ * @power: tuning power (88 - 120 dBuV, unit/step 1 dB)
  * @antcap: value of antenna tuning capacitor (0 - 191)
  */
 static int si4713_tx_tune_power(struct si4713_device *sdev, u8 power,
@@ -576,16 +576,16 @@ static int si4713_tx_tune_power(struct si4713_device *sdev, u8 power,
 	 * 	.Third byte = power
 	 * 	.Fourth byte = antcap
 	 */
-	const u8 args[SI4713_TXPWR_NARGS] = {
+	u8 args[SI4713_TXPWR_NARGS] = {
 		0x00,
 		0x00,
 		power,
 		antcap,
 	};
 
-	if (((power > 0) && (power < SI4713_MIN_POWER)) ||
-		power > SI4713_MAX_POWER || antcap > SI4713_MAX_ANTCAP)
-		return -EDOM;
+	/* Map power values 1-87 to MIN_POWER (88) */
+	if (power > 0 && power < SI4713_MIN_POWER)
+		args[2] = power = SI4713_MIN_POWER;
 
 	err = si4713_send_command(sdev, SI4713_CMD_TX_TUNE_POWER,
 				  args, ARRAY_SIZE(args), val,
@@ -1462,9 +1462,9 @@ static int si4713_probe(struct i2c_client *client,
 			V4L2_CID_TUNE_PREEMPHASIS,
 			V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
 	sdev->tune_pwr_level = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);
+			V4L2_CID_TUNE_POWER_LEVEL, 0, SI4713_MAX_POWER, 1, DEFAULT_POWER_LEVEL);
 	sdev->tune_ant_cap = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
-			V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, 191, 1, 0);
+			V4L2_CID_TUNE_ANTENNA_CAPACITOR, 0, SI4713_MAX_ANTCAP, 1, 0);
 
 	if (hdl->error) {
 		rval = hdl->error;
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 5/9] si4713 : HID blacklist Si4713 USB development board
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                     ` (2 preceding siblings ...)
  2013-10-15 15:24   ` [REVIEW PATCH 4/9] si4713 : Bug fix for si4713_tx_tune_power() method in the i2c driver Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713 Dinesh Ram
                     ` (4 subsequent siblings)
  8 siblings, 0 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media
  Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram, Jiri Kosina

The Si4713 development board contains a Si4713 FM transmitter chip
and is handled by the radio-usb-si4713 driver.
The board reports itself as (10c4:8244) Cygnal Integrated Products, Inc.
and misidentifies itself as a HID device in its USB interface descriptor.
This patch ignores this device as an HID device and hence loads the custom driver.

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Acked-by: Jiri Kosina <jkosina@suse.cz>
---
 drivers/hid/hid-core.c |    1 +
 drivers/hid/hid-ids.h  |    2 ++
 2 files changed, 3 insertions(+)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 5a8c011..e7f11b3 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -2107,6 +2107,7 @@ static const struct hid_device_id hid_ignore_list[] = {
 	{ HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI4713) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 9cbc7ab..d43e827 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -241,6 +241,8 @@
 #define USB_VENDOR_ID_CYGNAL		0x10c4
 #define USB_DEVICE_ID_CYGNAL_RADIO_SI470X	0x818a
 
+#define USB_DEVICE_ID_CYGNAL_RADIO_SI4713       0x8244
+
 #define USB_VENDOR_ID_CYPRESS		0x04b4
 #define USB_DEVICE_ID_CYPRESS_MOUSE	0x0001
 #define USB_DEVICE_ID_CYPRESS_HIDCOM	0x5500
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                     ` (3 preceding siblings ...)
  2013-10-15 15:24   ` [REVIEW PATCH 5/9] si4713 : HID blacklist Si4713 USB development board Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-11-05 14:18     ` edubezval
  2013-10-15 15:24   ` [REVIEW PATCH 7/9] si4713 : Added MAINTAINERS entry for radio-usb-si4713 driver Dinesh Ram
                     ` (3 subsequent siblings)
  8 siblings, 1 reply; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram

This is the USB driver for the Silicon Labs development board.
It contains the Si4713 FM transmitter chip.

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 drivers/media/radio/si4713/Kconfig            |   15 +
 drivers/media/radio/si4713/Makefile           |    1 +
 drivers/media/radio/si4713/radio-usb-si4713.c |  540 +++++++++++++++++++++++++
 3 files changed, 556 insertions(+)
 create mode 100644 drivers/media/radio/si4713/radio-usb-si4713.c

diff --git a/drivers/media/radio/si4713/Kconfig b/drivers/media/radio/si4713/Kconfig
index ec640b8..a7c3ba8 100644
--- a/drivers/media/radio/si4713/Kconfig
+++ b/drivers/media/radio/si4713/Kconfig
@@ -1,3 +1,18 @@
+config USB_SI4713
+	tristate "Silicon Labs Si4713 FM Radio Transmitter support with USB"
+	depends on USB && RADIO_SI4713
+	select SI4713
+	---help---
+	  This is a driver for USB devices with the Silicon Labs SI4713
+	  chip. Currently these devices are known to work.
+	  - 10c4:8244: Silicon Labs FM Transmitter USB device.
+
+	  Say Y here if you want to connect this type of radio to your
+	  computer's USB port.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called radio-usb-si4713.
+
 config PLATFORM_SI4713
 	tristate "Silicon Labs Si4713 FM Radio Transmitter support with I2C"
 	depends on I2C && RADIO_SI4713
diff --git a/drivers/media/radio/si4713/Makefile b/drivers/media/radio/si4713/Makefile
index 9d0bd0e..6524674 100644
--- a/drivers/media/radio/si4713/Makefile
+++ b/drivers/media/radio/si4713/Makefile
@@ -3,5 +3,6 @@
 #
 
 obj-$(CONFIG_I2C_SI4713) += si4713.o
+obj-$(CONFIG_USB_SI4713) += radio-usb-si4713.o
 obj-$(CONFIG_PLATFORM_SI4713) += radio-platform-si4713.o
 
diff --git a/drivers/media/radio/si4713/radio-usb-si4713.c b/drivers/media/radio/si4713/radio-usb-si4713.c
new file mode 100644
index 0000000..a75e2c8
--- /dev/null
+++ b/drivers/media/radio/si4713/radio-usb-si4713.c
@@ -0,0 +1,540 @@
+/*
+ * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
+ * All rights reserved.
+ *
+ * This program is free software; you may redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+/* kernel includes */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/usb.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/mutex.h>
+#include <linux/i2c.h>
+/* V4l includes */
+#include <linux/videodev2.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-device.h>
+#include <media/v4l2-ioctl.h>
+#include <media/v4l2-event.h>
+#include <media/si4713.h>
+
+#include "si4713.h"
+
+/* driver and module definitions */
+MODULE_AUTHOR("Dinesh Ram <dinesh.ram@cern.ch>");
+MODULE_DESCRIPTION("Si4713 FM Transmitter USB driver");
+MODULE_LICENSE("GPL v2");
+
+/* The Device announces itself as Cygnal Integrated Products, Inc. */
+#define USB_SI4713_VENDOR		0x10c4
+#define USB_SI4713_PRODUCT		0x8244
+
+#define BUFFER_LENGTH			64
+#define USB_TIMEOUT			1000
+#define USB_RESP_TIMEOUT		50000
+
+/* USB Device ID List */
+static struct usb_device_id usb_si4713_usb_device_table[] = {
+	{USB_DEVICE_AND_INTERFACE_INFO(USB_SI4713_VENDOR, USB_SI4713_PRODUCT,
+							USB_CLASS_HID, 0, 0) },
+	{ }						/* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE(usb, usb_si4713_usb_device_table);
+
+struct si4713_usb_device {
+	struct usb_device	*usbdev;
+	struct usb_interface	*intf;
+	struct video_device	vdev;
+	struct v4l2_device	v4l2_dev;
+	struct v4l2_subdev	*v4l2_subdev;
+	struct mutex		lock;
+	struct i2c_adapter	i2c_adapter;
+
+	u8			*buffer;
+};
+
+static inline struct si4713_usb_device *to_si4713_dev(struct v4l2_device *v4l2_dev)
+{
+	return container_of(v4l2_dev, struct si4713_usb_device, v4l2_dev);
+}
+
+static int vidioc_querycap(struct file *file, void *priv,
+					struct v4l2_capability *v)
+{
+	struct si4713_usb_device *radio = video_drvdata(file);
+
+	strlcpy(v->driver, "radio-usb-si4713", sizeof(v->driver));
+	strlcpy(v->card, "Si4713 FM Transmitter", sizeof(v->card));
+	usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
+	v->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
+	v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
+
+	return 0;
+}
+
+static int vidioc_g_modulator(struct file *file, void *priv,
+				struct v4l2_modulator *vm)
+{
+	struct si4713_usb_device *radio = video_drvdata(file);
+
+	return v4l2_subdev_call(radio->v4l2_subdev, tuner, g_modulator, vm);
+}
+
+static int vidioc_s_modulator(struct file *file, void *priv,
+				const struct v4l2_modulator *vm)
+{
+	struct si4713_usb_device *radio = video_drvdata(file);
+
+	return v4l2_subdev_call(radio->v4l2_subdev, tuner, s_modulator, vm);
+}
+
+static int vidioc_s_frequency(struct file *file, void *priv,
+				const struct v4l2_frequency *vf)
+{
+	struct si4713_usb_device *radio = video_drvdata(file);
+
+	return v4l2_subdev_call(radio->v4l2_subdev, tuner, s_frequency, vf);
+}
+
+static int vidioc_g_frequency(struct file *file, void *priv,
+				struct v4l2_frequency *vf)
+{
+	struct si4713_usb_device *radio = video_drvdata(file);
+
+	return v4l2_subdev_call(radio->v4l2_subdev, tuner, g_frequency, vf);
+}
+
+static const struct v4l2_ioctl_ops usb_si4713_ioctl_ops = {
+	.vidioc_querycap	  = vidioc_querycap,
+	.vidioc_g_modulator	  = vidioc_g_modulator,
+	.vidioc_s_modulator	  = vidioc_s_modulator,
+	.vidioc_g_frequency	  = vidioc_g_frequency,
+	.vidioc_s_frequency	  = vidioc_s_frequency,
+	.vidioc_log_status	  = v4l2_ctrl_log_status,
+       .vidioc_subscribe_event   = v4l2_ctrl_subscribe_event,
+       .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
+};
+
+/* File system interface */
+static const struct v4l2_file_operations usb_si4713_fops = {
+	.owner		= THIS_MODULE,
+	.open           = v4l2_fh_open,
+	.release        = v4l2_fh_release,
+	.poll           = v4l2_ctrl_poll,
+	.unlocked_ioctl	= video_ioctl2,
+};
+
+static void usb_si4713_video_device_release(struct v4l2_device *v4l2_dev)
+{
+	struct si4713_usb_device *radio = to_si4713_dev(v4l2_dev);
+	struct i2c_adapter *adapter = &radio->i2c_adapter;
+
+	i2c_del_adapter(adapter);
+	v4l2_device_unregister(&radio->v4l2_dev);
+	kfree(radio->buffer);
+	kfree(radio);
+}
+
+/*
+ * This command sequence emulates the behaviour of the Windows driver.
+ * The structure of these commands was determined by sniffing the
+ * usb traffic of the device during startup.
+ * Most likely, these commands make some queries to the device.
+ * Commands are sent to enquire parameters like the bus mode,
+ * component revision, boot mode, the device serial number etc.
+ *
+ * These commands are necessary to be sent in this order during startup.
+ * The device fails to powerup if these commands are not sent.
+ *
+ * The complete list of startup commands is given in the start_seq table below.
+ */
+static int si4713_send_startup_command(struct si4713_usb_device *radio)
+{
+	unsigned long until_jiffies = jiffies + usecs_to_jiffies(USB_RESP_TIMEOUT) + 1;
+	u8 *buffer = radio->buffer;
+	int retval;
+
+	/* send the command */
+	retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
+					0x09, 0x21, 0x033f, 0, radio->buffer,
+					BUFFER_LENGTH, USB_TIMEOUT);
+	if (retval < 0)
+		return retval;
+
+	for (;;) {
+		/* receive the response */
+		retval = usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
+				0x01, 0xa1, 0x033f, 0, radio->buffer,
+				BUFFER_LENGTH, USB_TIMEOUT);
+		if (retval < 0)
+			return retval;
+		if (!radio->buffer[1]) {
+			/* USB traffic sniffing showed that some commands require
+			 * additional checks. */
+			switch (buffer[1]) {
+			case 0x32:
+				if (radio->buffer[2] == 0)
+					return 0;
+				break;
+			case 0x14:
+			case 0x12:
+				if (radio->buffer[2] & SI4713_CTS)
+					return 0;
+				break;
+			case 0x06:
+				if ((radio->buffer[2] & SI4713_CTS) && radio->buffer[9] == 0x08)
+					return 0;
+				break;
+			default:
+				return 0;
+			}
+		}
+		if (jiffies > until_jiffies)
+			return -EIO;
+		msleep(3);
+	}
+
+	return retval;
+}
+
+struct si4713_start_seq_table {
+	int len;
+	u8 payload[8];
+};
+
+/*
+ * Some of the startup commands that could be recognized are :
+ * (0x03): Get serial number of the board (Response : CB000-00-00)
+ * (0x06, 0x03, 0x03, 0x08, 0x01, 0x0f) : Get Component revision
+ */
+struct si4713_start_seq_table start_seq[] = {
+
+	{ 1, { 0x03 } },
+	{ 2, { 0x32, 0x7f } },
+	{ 6, { 0x06, 0x03, 0x03, 0x08, 0x01, 0x0f } },
+	{ 2, { 0x14, 0x02 } },
+	{ 2, { 0x09, 0x90 } },
+	{ 3, { 0x08, 0x90, 0xfa } },
+	{ 2, { 0x36, 0x01 } },
+	{ 2, { 0x05, 0x03 } },
+	{ 7, { 0x06, 0x00, 0x06, 0x0e, 0x01, 0x0f, 0x05 } },
+	{ 1, { 0x12 } },
+	/* Commands that are sent after pressing the 'Initialize'
+		button in the windows application */
+	{ 1, { 0x03 } },
+	{ 1, { 0x01 } },
+	{ 2, { 0x09, 0x90 } },
+	{ 3, { 0x08, 0x90, 0xfa } },
+	{ 1, { 0x34 } },
+	{ 2, { 0x35, 0x01 } },
+	{ 2, { 0x36, 0x01 } },
+	{ 2, { 0x30, 0x09 } },
+	{ 4, { 0x30, 0x06, 0x00, 0xe2 } },
+	{ 3, { 0x31, 0x01, 0x30 } },
+	{ 3, { 0x31, 0x04, 0x09 } },
+	{ 2, { 0x05, 0x02 } },
+	{ 6, { 0x06, 0x03, 0x03, 0x08, 0x01, 0x0f } },
+};
+
+static int si4713_start_seq(struct si4713_usb_device *radio)
+{
+	int retval = 0;
+	int i;
+
+	radio->buffer[0] = 0x3f;
+
+	for (i = 0; i < ARRAY_SIZE(start_seq); i++) {
+		int len = start_seq[i].len;
+		u8 *payload = start_seq[i].payload;
+
+		memcpy(radio->buffer + 1, payload, len);
+		memset(radio->buffer + len + 1, 0, BUFFER_LENGTH - 1 - len);
+		retval = si4713_send_startup_command(radio);
+	}
+
+	return retval;
+}
+
+static struct i2c_board_info si4713_board_info = {
+	I2C_BOARD_INFO("si4713", SI4713_I2C_ADDR_BUSEN_HIGH),
+};
+
+struct si4713_command_table {
+	int command_id;
+	u8 payload[8];
+};
+
+/*
+ * Structure of a command :
+ *	Byte 1 : 0x3f (always)
+ *	Byte 2 : 0x06 (send a command)
+ *	Byte 3 : Unknown
+ *	Byte 4 : Number of arguments + 1 (for the command byte)
+ *	Byte 5 : Number of response bytes
+ */
+struct si4713_command_table command_table[] = {
+
+	{ SI4713_CMD_POWER_UP,		{ 0x00, SI4713_PWUP_NARGS + 1, SI4713_PWUP_NRESP} },
+	{ SI4713_CMD_GET_REV,		{ 0x03, 0x01, SI4713_GETREV_NRESP } },
+	{ SI4713_CMD_POWER_DOWN,	{ 0x00, 0x01, SI4713_PWDN_NRESP} },
+	{ SI4713_CMD_SET_PROPERTY,	{ 0x00, SI4713_SET_PROP_NARGS + 1, SI4713_SET_PROP_NRESP } },
+	{ SI4713_CMD_GET_PROPERTY,	{ 0x00, SI4713_GET_PROP_NARGS + 1, SI4713_GET_PROP_NRESP } },
+	{ SI4713_CMD_TX_TUNE_FREQ,	{ 0x03, SI4713_TXFREQ_NARGS + 1, SI4713_TXFREQ_NRESP } },
+	{ SI4713_CMD_TX_TUNE_POWER,	{ 0x03, SI4713_TXPWR_NARGS + 1, SI4713_TXPWR_NRESP } },
+	{ SI4713_CMD_TX_TUNE_MEASURE,	{ 0x03, SI4713_TXMEA_NARGS + 1, SI4713_TXMEA_NRESP } },
+	{ SI4713_CMD_TX_TUNE_STATUS,	{ 0x00, SI4713_TXSTATUS_NARGS + 1, SI4713_TXSTATUS_NRESP } },
+	{ SI4713_CMD_TX_ASQ_STATUS,	{ 0x03, SI4713_ASQSTATUS_NARGS + 1, SI4713_ASQSTATUS_NRESP } },
+	{ SI4713_CMD_GET_INT_STATUS,	{ 0x03, 0x01, SI4713_GET_STATUS_NRESP } },
+	{ SI4713_CMD_TX_RDS_BUFF,	{ 0x03, SI4713_RDSBUFF_NARGS + 1, SI4713_RDSBUFF_NRESP } },
+	{ SI4713_CMD_TX_RDS_PS,		{ 0x00, SI4713_RDSPS_NARGS + 1, SI4713_RDSPS_NRESP } },
+};
+
+static int send_command(struct si4713_usb_device *radio, u8 *payload, char *data, int len)
+{
+	int retval;
+
+	radio->buffer[0] = 0x3f;
+	radio->buffer[1] = 0x06;
+
+	memcpy(radio->buffer + 2, payload, 3);
+	memcpy(radio->buffer + 5, data, len);
+	memset(radio->buffer + 5 + len, 0, BUFFER_LENGTH - 5 - len);
+
+	/* send the command */
+	retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
+					0x09, 0x21, 0x033f, 0, radio->buffer,
+					BUFFER_LENGTH, USB_TIMEOUT);
+
+	return retval < 0 ? retval : 0;
+}
+
+static int si4713_i2c_read(struct si4713_usb_device *radio, char *data, int len)
+{
+	unsigned long until_jiffies = jiffies + usecs_to_jiffies(USB_RESP_TIMEOUT) + 1;
+	int retval;
+
+	/* receive the response */
+	for (;;) {
+		retval = usb_control_msg(radio->usbdev,
+					usb_rcvctrlpipe(radio->usbdev, 0),
+					0x01, 0xa1, 0x033f, 0, radio->buffer,
+					BUFFER_LENGTH, USB_TIMEOUT);
+		if (retval < 0)
+			return retval;
+
+		/*
+		 * Check that we get a valid reply back (buffer[1] == 0) and
+		 * that CTS is set before returning, otherwise we wait and try
+		 * again. The i2c driver also does the CTS check, but the timeouts
+		 * used there are much too small for this USB driver, so we wait
+		 * for it here.
+		 */
+		if (radio->buffer[1] == 0 && (radio->buffer[2] & SI4713_CTS)) {
+			memcpy(data, radio->buffer + 2, len);
+			return 0;
+		}
+		if (jiffies > until_jiffies) {
+			/* Zero the status value, ensuring CTS isn't set */
+			data[0] = 0;
+			return 0;
+		}
+		msleep(3);
+	}
+}
+
+static int si4713_i2c_write(struct si4713_usb_device *radio, char *data, int len)
+{
+	int retval = -EINVAL;
+	int i;
+
+	if (len > BUFFER_LENGTH - 5)
+		return -EINVAL;
+
+	for (i = 0; i < ARRAY_SIZE(command_table); i++) {
+		if (data[0] == command_table[i].command_id)
+			retval = send_command(radio, command_table[i].payload,
+						data, len);
+	}
+
+	return retval < 0 ? retval : 0;
+}
+
+static int si4713_transfer(struct i2c_adapter *i2c_adapter,
+				struct i2c_msg *msgs, int num)
+{
+	struct si4713_usb_device *radio = i2c_get_adapdata(i2c_adapter);
+	int retval = -EINVAL;
+	int i;
+
+	if (num <= 0)
+		return 0;
+
+	for (i = 0; i < num; i++) {
+		if (msgs[i].flags & I2C_M_RD)
+			retval = si4713_i2c_read(radio, msgs[i].buf, msgs[i].len);
+		else
+			retval = si4713_i2c_write(radio, msgs[i].buf, msgs[i].len);
+		if (retval)
+			break;
+	}
+
+	return retval ? retval : num;
+}
+
+static u32 si4713_functionality(struct i2c_adapter *adapter)
+{
+	return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
+}
+
+static struct i2c_algorithm si4713_algo = {
+	.master_xfer   = si4713_transfer,
+	.functionality = si4713_functionality,
+};
+
+/* This name value shows up in the sysfs filename associated
+		with this I2C adapter */
+static struct i2c_adapter si4713_i2c_adapter_template = {
+	.name   = "si4713-i2c",
+	.owner  = THIS_MODULE,
+	.algo   = &si4713_algo,
+};
+
+int si4713_register_i2c_adapter(struct si4713_usb_device *radio)
+{
+	radio->i2c_adapter = si4713_i2c_adapter_template;
+	/* set up sysfs linkage to our parent device */
+	radio->i2c_adapter.dev.parent = &radio->usbdev->dev;
+	i2c_set_adapdata(&radio->i2c_adapter, radio);
+
+	return i2c_add_adapter(&radio->i2c_adapter);
+}
+
+/* check if the device is present and register with v4l and usb if it is */
+static int usb_si4713_probe(struct usb_interface *intf,
+				const struct usb_device_id *id)
+{
+	struct si4713_usb_device *radio;
+	struct i2c_adapter *adapter;
+	struct v4l2_subdev *sd;
+	int retval = -ENOMEM;
+
+	dev_info(&intf->dev, "Si4713 development board discovered: (%04X:%04X)\n",
+			id->idVendor, id->idProduct);
+
+	/* Initialize local device structure */
+	radio = kzalloc(sizeof(struct si4713_usb_device), GFP_KERNEL);
+	if (radio)
+		radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
+
+	if (!radio || !radio->buffer) {
+		dev_err(&intf->dev, "kmalloc for si4713_usb_device failed\n");
+		kfree(radio);
+		return -ENOMEM;
+	}
+
+	mutex_init(&radio->lock);
+
+	radio->usbdev = interface_to_usbdev(intf);
+	radio->intf = intf;
+	usb_set_intfdata(intf, &radio->v4l2_dev);
+
+	retval = si4713_start_seq(radio);
+	if (retval < 0)
+		goto err_v4l2;
+
+	retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
+	if (retval < 0) {
+		dev_err(&intf->dev, "couldn't register v4l2_device\n");
+		goto err_v4l2;
+	}
+
+	retval = si4713_register_i2c_adapter(radio);
+	if (retval < 0) {
+		dev_err(&intf->dev, "could not register i2c device\n");
+		goto err_i2cdev;
+	}
+
+	adapter = &radio->i2c_adapter;
+	sd = v4l2_i2c_new_subdev_board(&radio->v4l2_dev, adapter,
+					  &si4713_board_info, NULL);
+	radio->v4l2_subdev = sd;
+	if (!sd) {
+		dev_err(&intf->dev, "cannot get v4l2 subdevice\n");
+		retval = -ENODEV;
+		goto del_adapter;
+	}
+
+	radio->vdev.ctrl_handler = sd->ctrl_handler;
+	radio->v4l2_dev.release = usb_si4713_video_device_release;
+	strlcpy(radio->vdev.name, radio->v4l2_dev.name,
+		sizeof(radio->vdev.name));
+	radio->vdev.v4l2_dev = &radio->v4l2_dev;
+	radio->vdev.fops = &usb_si4713_fops;
+	radio->vdev.ioctl_ops = &usb_si4713_ioctl_ops;
+	radio->vdev.lock = &radio->lock;
+	radio->vdev.release = video_device_release_empty;
+	radio->vdev.vfl_dir = VFL_DIR_TX;
+
+	video_set_drvdata(&radio->vdev, radio);
+	set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags);
+
+	retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
+	if (retval < 0) {
+		dev_err(&intf->dev, "could not register video device\n");
+		goto del_adapter;
+	}
+
+	dev_info(&intf->dev, "V4L2 device registered as %s\n",
+			video_device_node_name(&radio->vdev));
+
+	return 0;
+
+del_adapter:
+	i2c_del_adapter(adapter);
+err_i2cdev:
+	v4l2_device_unregister(&radio->v4l2_dev);
+err_v4l2:
+	kfree(radio->buffer);
+	kfree(radio);
+	return retval;
+}
+
+static void usb_si4713_disconnect(struct usb_interface *intf)
+{
+	struct si4713_usb_device *radio = to_si4713_dev(usb_get_intfdata(intf));
+
+	dev_info(&intf->dev, "Si4713 development board now disconnected\n");
+
+	mutex_lock(&radio->lock);
+	usb_set_intfdata(intf, NULL);
+	video_unregister_device(&radio->vdev);
+	v4l2_device_disconnect(&radio->v4l2_dev);
+	mutex_unlock(&radio->lock);
+	v4l2_device_put(&radio->v4l2_dev);
+}
+
+/* USB subsystem interface */
+static struct usb_driver usb_si4713_driver = {
+	.name			= "radio-usb-si4713",
+	.probe			= usb_si4713_probe,
+	.disconnect		= usb_si4713_disconnect,
+	.id_table		= usb_si4713_usb_device_table,
+};
+
+module_usb_driver(usb_si4713_driver);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 7/9] si4713 : Added MAINTAINERS entry for radio-usb-si4713 driver
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                     ` (4 preceding siblings ...)
  2013-10-15 15:24   ` [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713 Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-10-15 15:24   ` [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data Dinesh Ram
                     ` (2 subsequent siblings)
  8 siblings, 0 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Dinesh Ram

Hans Verkuil <hverkuil@xs4all.nl> will maintain the USB driver for si4713

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 MAINTAINERS |   12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index 72b1e5c..1ed7363 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -7520,7 +7520,7 @@ L:	linux-media@vger.kernel.org
 T:	git git://linuxtv.org/media_tree.git
 W:	http://linuxtv.org
 S:	Odd Fixes
-F:	drivers/media/radio/si4713-i2c.?
+F:	drivers/media/radio/si4713/si4713.?
 
 SI4713 FM RADIO TRANSMITTER PLATFORM DRIVER
 M:	Eduardo Valentin <edubezval@gmail.com>
@@ -7528,7 +7528,15 @@ L:	linux-media@vger.kernel.org
 T:	git git://linuxtv.org/media_tree.git
 W:	http://linuxtv.org
 S:	Odd Fixes
-F:	drivers/media/radio/radio-si4713.c
+F:	drivers/media/radio/si4713/radio-platform-si4713.c
+
+SI4713 FM RADIO TRANSMITTER USB DRIVER
+M:	Hans Verkuil <hverkuil@xs4all.nl>
+L:	linux-media@vger.kernel.org
+T:	git git://linuxtv.org/media_tree.git
+W:	http://linuxtv.org
+S:	Maintained
+F:	drivers/media/radio/si4713/radio-usb-si4713.c
 
 SIANO DVB DRIVER
 M:	Mauro Carvalho Chehab <m.chehab@samsung.com>
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                     ` (5 preceding siblings ...)
  2013-10-15 15:24   ` [REVIEW PATCH 7/9] si4713 : Added MAINTAINERS entry for radio-usb-si4713 driver Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-11-04 14:07     ` edubezval
  2013-10-15 15:24   ` [REVIEW PATCH 9/9] si4713: si4713_set_rds_radio_text overwrites terminating \0 Dinesh Ram
  2013-12-03 15:39   ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Mauro Carvalho Chehab
  8 siblings, 1 reply; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Hans Verkuil

The supply list is needed by the platform driver, but not by the usb driver.
So this information belongs to the platform data and should not be hardcoded
in the subdevice driver.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 arch/arm/mach-omap2/board-rx51-peripherals.c |    7 ++++
 drivers/media/radio/si4713/si4713.c          |   52 +++++++++++++-------------
 drivers/media/radio/si4713/si4713.h          |    3 +-
 include/media/si4713.h                       |    2 +
 4 files changed, 37 insertions(+), 27 deletions(-)

diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
index f6fe388..eae73f7 100644
--- a/arch/arm/mach-omap2/board-rx51-peripherals.c
+++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
@@ -776,7 +776,14 @@ static struct regulator_init_data rx51_vintdig = {
 	},
 };
 
+static const char * const si4713_supply_names[SI4713_NUM_SUPPLIES] = {
+	"vio",
+	"vdd",
+};
+
 static struct si4713_platform_data rx51_si4713_i2c_data __initdata_or_module = {
+	.supplies	= ARRAY_SIZE(si4713_supply_names),
+	.supply_names	= si4713_supply_names,
 	.gpio_reset	= RX51_FMTX_RESET_GPIO,
 };
 
diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
index d297a5b..920dfa5 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -44,11 +44,6 @@ MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
 MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
 MODULE_VERSION("0.0.1");
 
-static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
-	"vio",
-	"vdd",
-};
-
 #define DEFAULT_RDS_PI			0x00
 #define DEFAULT_RDS_PTY			0x00
 #define DEFAULT_RDS_DEVIATION		0x00C8
@@ -368,11 +363,12 @@ static int si4713_powerup(struct si4713_device *sdev)
 	if (sdev->power_state)
 		return 0;
 
-	err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
-				    sdev->supplies);
-	if (err) {
-		v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
-		return err;
+	if (sdev->supplies) {
+		err = regulator_bulk_enable(sdev->supplies, sdev->supply_data);
+		if (err) {
+			v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
+			return err;
+		}
 	}
 	if (gpio_is_valid(sdev->gpio_reset)) {
 		udelay(50);
@@ -396,11 +392,12 @@ static int si4713_powerup(struct si4713_device *sdev)
 		if (client->irq)
 			err = si4713_write_property(sdev, SI4713_GPO_IEN,
 						SI4713_STC_INT | SI4713_CTS);
-	} else {
-		if (gpio_is_valid(sdev->gpio_reset))
-			gpio_set_value(sdev->gpio_reset, 0);
-		err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
-					     sdev->supplies);
+		return err;
+	}
+	if (gpio_is_valid(sdev->gpio_reset))
+		gpio_set_value(sdev->gpio_reset, 0);
+	if (sdev->supplies) {
+		err = regulator_bulk_disable(sdev->supplies, sdev->supply_data);
 		if (err)
 			v4l2_err(&sdev->sd,
 				 "Failed to disable supplies: %d\n", err);
@@ -432,11 +429,13 @@ static int si4713_powerdown(struct si4713_device *sdev)
 		v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
 		if (gpio_is_valid(sdev->gpio_reset))
 			gpio_set_value(sdev->gpio_reset, 0);
-		err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
-					     sdev->supplies);
-		if (err)
-			v4l2_err(&sdev->sd,
-				 "Failed to disable supplies: %d\n", err);
+		if (sdev->supplies) {
+			err = regulator_bulk_disable(sdev->supplies,
+						     sdev->supply_data);
+			if (err)
+				v4l2_err(&sdev->sd,
+					 "Failed to disable supplies: %d\n", err);
+		}
 		sdev->power_state = POWER_OFF;
 	}
 
@@ -1381,13 +1380,14 @@ static int si4713_probe(struct i2c_client *client,
 		}
 		sdev->gpio_reset = pdata->gpio_reset;
 		gpio_direction_output(sdev->gpio_reset, 0);
+		sdev->supplies = pdata->supplies;
 	}
 
-	for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
-		sdev->supplies[i].supply = si4713_supply_names[i];
+	for (i = 0; i < sdev->supplies; i++)
+		sdev->supply_data[i].supply = pdata->supply_names[i];
 
-	rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
-				  sdev->supplies);
+	rval = regulator_bulk_get(&client->dev, sdev->supplies,
+				  sdev->supply_data);
 	if (rval) {
 		dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
 		goto free_gpio;
@@ -1500,7 +1500,7 @@ free_irq:
 free_ctrls:
 	v4l2_ctrl_handler_free(hdl);
 put_reg:
-	regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
+	regulator_bulk_free(sdev->supplies, sdev->supply_data);
 free_gpio:
 	if (gpio_is_valid(sdev->gpio_reset))
 		gpio_free(sdev->gpio_reset);
@@ -1524,7 +1524,7 @@ static int si4713_remove(struct i2c_client *client)
 
 	v4l2_device_unregister_subdev(sd);
 	v4l2_ctrl_handler_free(sd->ctrl_handler);
-	regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
+	regulator_bulk_free(sdev->supplies, sdev->supply_data);
 	if (gpio_is_valid(sdev->gpio_reset))
 		gpio_free(sdev->gpio_reset);
 	kfree(sdev);
diff --git a/drivers/media/radio/si4713/si4713.h b/drivers/media/radio/si4713/si4713.h
index dc0ce66..986e27b 100644
--- a/drivers/media/radio/si4713/si4713.h
+++ b/drivers/media/radio/si4713/si4713.h
@@ -227,7 +227,8 @@ struct si4713_device {
 		struct v4l2_ctrl *tune_ant_cap;
 	};
 	struct completion work;
-	struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
+	unsigned supplies;
+	struct regulator_bulk_data supply_data[SI4713_NUM_SUPPLIES];
 	int gpio_reset;
 	u32 power_state;
 	u32 rds_enabled;
diff --git a/include/media/si4713.h b/include/media/si4713.h
index ed7353e..f98a0a7 100644
--- a/include/media/si4713.h
+++ b/include/media/si4713.h
@@ -23,6 +23,8 @@
  * Platform dependent definition
  */
 struct si4713_platform_data {
+	const char * const *supply_names;
+	unsigned supplies;
 	int gpio_reset; /* < 0 if not used */
 };
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [REVIEW PATCH 9/9] si4713: si4713_set_rds_radio_text overwrites terminating \0
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                     ` (6 preceding siblings ...)
  2013-10-15 15:24   ` [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data Dinesh Ram
@ 2013-10-15 15:24   ` Dinesh Ram
  2013-12-03 15:39   ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Mauro Carvalho Chehab
  8 siblings, 0 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-10-15 15:24 UTC (permalink / raw)
  To: linux-media; +Cc: Hans Verkuil, edubezval, dinesh.ram086, Hans Verkuil

si4713_set_rds_radio_text will overwrite the terminating zero at the
end of the rds radio text string in order to send out a carriage return
as per the RDS spec.

Use a separate char buffer for the CR instead of corrupting the control
string.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/radio/si4713/si4713.c |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
index 920dfa5..aadecb5 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -831,8 +831,9 @@ static int si4713_set_rds_ps_name(struct si4713_device *sdev, char *ps_name)
 	return rval;
 }
 
-static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
+static int si4713_set_rds_radio_text(struct si4713_device *sdev, const char *rt)
 {
+	static const char cr[RDS_RADIOTEXT_BLK_SIZE] = { RDS_CARRIAGE_RETURN, 0 };
 	int rval = 0, i;
 	u16 t_index = 0;
 	u8 b_index = 0, cr_inserted = 0;
@@ -856,7 +857,7 @@ static int si4713_set_rds_radio_text(struct si4713_device *sdev, char *rt)
 			for (i = 0; i < RDS_RADIOTEXT_BLK_SIZE; i++) {
 				if (!rt[t_index + i] ||
 				    rt[t_index + i] == RDS_CARRIAGE_RETURN) {
-					rt[t_index + i] = RDS_CARRIAGE_RETURN;
+					rt = cr;
 					cr_inserted = 1;
 					break;
 				}
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [Review Patch 0/9] si4713 usb device driver
  2013-10-15 15:24 [Review Patch 0/9] si4713 usb device driver Dinesh Ram
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
@ 2013-10-15 17:37 ` edubezval
  2013-11-04  9:33   ` Hans Verkuil
  2013-11-18 14:31 ` edubezval
  2 siblings, 1 reply; 31+ messages in thread
From: edubezval @ 2013-10-15 17:37 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: Linux-Media, Hans Verkuil, dinesh.ram086

Hello Dinesh,

On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
> Hello Eduardo,
>
> In this patch series, I have addressed the comments by you
> concerning my last patch series.
> In the resulting patches, I have corrected most of the
> style issues and adding of comments. However, some warnings
> given out by checkpatch.pl (mostly complaing about lines longer
> than 80 characters) are still there because I saw that code readibility
> suffers by breaking up those lines.
>
> Also Hans has contributed patches 8 and 9 in this patch series
> which address the issues of the handling of unknown regulators,
> which have apparently changed since 3.10. Hans has tested it and the
> driver loads again.
>
> Let me know when you are able to test it again.
>

Hopefully I will be able to give it a shot on n900 and on silabs
devboard until the end of the week. Thanks for not giving up.

> Kind regards,
> Dinesh Ram
> dinesh.ram@cern.ch
> dinesh.ram086@gmail.com
>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [Review Patch 0/9] si4713 usb device driver
  2013-10-15 17:37 ` [Review Patch 0/9] si4713 usb device driver edubezval
@ 2013-11-04  9:33   ` Hans Verkuil
  2013-11-04 14:09     ` edubezval
  0 siblings, 1 reply; 31+ messages in thread
From: Hans Verkuil @ 2013-11-04  9:33 UTC (permalink / raw)
  To: edubezval; +Cc: Dinesh Ram, Linux-Media, dinesh.ram086

On 10/15/2013 07:37 PM, edubezval@gmail.com wrote:
> Hello Dinesh,
> 
> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>> Hello Eduardo,
>>
>> In this patch series, I have addressed the comments by you
>> concerning my last patch series.
>> In the resulting patches, I have corrected most of the
>> style issues and adding of comments. However, some warnings
>> given out by checkpatch.pl (mostly complaing about lines longer
>> than 80 characters) are still there because I saw that code readibility
>> suffers by breaking up those lines.
>>
>> Also Hans has contributed patches 8 and 9 in this patch series
>> which address the issues of the handling of unknown regulators,
>> which have apparently changed since 3.10. Hans has tested it and the
>> driver loads again.
>>
>> Let me know when you are able to test it again.
>>
> 
> Hopefully I will be able to give it a shot on n900 and on silabs
> devboard until the end of the week. Thanks for not giving up.

Did you find time to do this? I'm waiting for feedback from you.

Regards,

	Hans

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data
  2013-10-15 15:24   ` [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data Dinesh Ram
@ 2013-11-04 14:07     ` edubezval
  2013-11-05  8:38       ` Hans Verkuil
  0 siblings, 1 reply; 31+ messages in thread
From: edubezval @ 2013-11-04 14:07 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: Linux-Media, Hans Verkuil, d ram, Hans Verkuil

Hi,

On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
> The supply list is needed by the platform driver, but not by the usb driver.
> So this information belongs to the platform data and should not be hardcoded
> in the subdevice driver.
>
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

Dinesh, could you please sign this patch too?

> ---
>  arch/arm/mach-omap2/board-rx51-peripherals.c |    7 ++++
>  drivers/media/radio/si4713/si4713.c          |   52 +++++++++++++-------------
>  drivers/media/radio/si4713/si4713.h          |    3 +-
>  include/media/si4713.h                       |    2 +
>  4 files changed, 37 insertions(+), 27 deletions(-)
>
> diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
> index f6fe388..eae73f7 100644
> --- a/arch/arm/mach-omap2/board-rx51-peripherals.c
> +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
> @@ -776,7 +776,14 @@ static struct regulator_init_data rx51_vintdig = {
>         },
>  };
>
> +static const char * const si4713_supply_names[SI4713_NUM_SUPPLIES] = {

This patch produces the following compilation error:
arch/arm/mach-omap2/board-rx51-peripherals.c:779:47: error:
'SI4713_NUM_SUPPLIES' undeclared here (not in a function)
arch/arm/mach-omap2/board-rx51-peripherals.c:785:14: error: bit-field
'<anonymous>' width not an integer constant
arch/arm/mach-omap2/board-rx51-peripherals.c:779:27: warning:
'si4713_supply_names' defined but not used [-Wunused-variable]
make[1]: *** [arch/arm/mach-omap2/board-rx51-peripherals.o] Error 1
make: *** [arch/arm/mach-omap2] Error 2
make: *** Waiting for unfinished jobs....


> +       "vio",
> +       "vdd",
> +};
> +
>  static struct si4713_platform_data rx51_si4713_i2c_data __initdata_or_module = {
> +       .supplies       = ARRAY_SIZE(si4713_supply_names),
> +       .supply_names   = si4713_supply_names,
>         .gpio_reset     = RX51_FMTX_RESET_GPIO,
>  };
>
> diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
> index d297a5b..920dfa5 100644
> --- a/drivers/media/radio/si4713/si4713.c
> +++ b/drivers/media/radio/si4713/si4713.c
> @@ -44,11 +44,6 @@ MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
>  MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
>  MODULE_VERSION("0.0.1");
>
> -static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
> -       "vio",
> -       "vdd",
> -};
> -
>  #define DEFAULT_RDS_PI                 0x00
>  #define DEFAULT_RDS_PTY                        0x00
>  #define DEFAULT_RDS_DEVIATION          0x00C8
> @@ -368,11 +363,12 @@ static int si4713_powerup(struct si4713_device *sdev)
>         if (sdev->power_state)
>                 return 0;
>
> -       err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
> -                                   sdev->supplies);
> -       if (err) {
> -               v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
> -               return err;
> +       if (sdev->supplies) {
> +               err = regulator_bulk_enable(sdev->supplies, sdev->supply_data);
> +               if (err) {
> +                       v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
> +                       return err;
> +               }
>         }
>         if (gpio_is_valid(sdev->gpio_reset)) {
>                 udelay(50);
> @@ -396,11 +392,12 @@ static int si4713_powerup(struct si4713_device *sdev)
>                 if (client->irq)
>                         err = si4713_write_property(sdev, SI4713_GPO_IEN,
>                                                 SI4713_STC_INT | SI4713_CTS);
> -       } else {
> -               if (gpio_is_valid(sdev->gpio_reset))
> -                       gpio_set_value(sdev->gpio_reset, 0);
> -               err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
> -                                            sdev->supplies);
> +               return err;
> +       }
> +       if (gpio_is_valid(sdev->gpio_reset))
> +               gpio_set_value(sdev->gpio_reset, 0);
> +       if (sdev->supplies) {
> +               err = regulator_bulk_disable(sdev->supplies, sdev->supply_data);
>                 if (err)
>                         v4l2_err(&sdev->sd,
>                                  "Failed to disable supplies: %d\n", err);
> @@ -432,11 +429,13 @@ static int si4713_powerdown(struct si4713_device *sdev)
>                 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
>                 if (gpio_is_valid(sdev->gpio_reset))
>                         gpio_set_value(sdev->gpio_reset, 0);
> -               err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
> -                                            sdev->supplies);
> -               if (err)
> -                       v4l2_err(&sdev->sd,
> -                                "Failed to disable supplies: %d\n", err);
> +               if (sdev->supplies) {
> +                       err = regulator_bulk_disable(sdev->supplies,
> +                                                    sdev->supply_data);
> +                       if (err)
> +                               v4l2_err(&sdev->sd,
> +                                        "Failed to disable supplies: %d\n", err);
> +               }
>                 sdev->power_state = POWER_OFF;
>         }
>
> @@ -1381,13 +1380,14 @@ static int si4713_probe(struct i2c_client *client,
>                 }
>                 sdev->gpio_reset = pdata->gpio_reset;
>                 gpio_direction_output(sdev->gpio_reset, 0);
> +               sdev->supplies = pdata->supplies;
>         }
>
> -       for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
> -               sdev->supplies[i].supply = si4713_supply_names[i];
> +       for (i = 0; i < sdev->supplies; i++)
> +               sdev->supply_data[i].supply = pdata->supply_names[i];
>
> -       rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
> -                                 sdev->supplies);
> +       rval = regulator_bulk_get(&client->dev, sdev->supplies,
> +                                 sdev->supply_data);
>         if (rval) {
>                 dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
>                 goto free_gpio;
> @@ -1500,7 +1500,7 @@ free_irq:
>  free_ctrls:
>         v4l2_ctrl_handler_free(hdl);
>  put_reg:
> -       regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
> +       regulator_bulk_free(sdev->supplies, sdev->supply_data);
>  free_gpio:
>         if (gpio_is_valid(sdev->gpio_reset))
>                 gpio_free(sdev->gpio_reset);
> @@ -1524,7 +1524,7 @@ static int si4713_remove(struct i2c_client *client)
>
>         v4l2_device_unregister_subdev(sd);
>         v4l2_ctrl_handler_free(sd->ctrl_handler);
> -       regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
> +       regulator_bulk_free(sdev->supplies, sdev->supply_data);
>         if (gpio_is_valid(sdev->gpio_reset))
>                 gpio_free(sdev->gpio_reset);
>         kfree(sdev);
> diff --git a/drivers/media/radio/si4713/si4713.h b/drivers/media/radio/si4713/si4713.h
> index dc0ce66..986e27b 100644
> --- a/drivers/media/radio/si4713/si4713.h
> +++ b/drivers/media/radio/si4713/si4713.h
> @@ -227,7 +227,8 @@ struct si4713_device {
>                 struct v4l2_ctrl *tune_ant_cap;
>         };
>         struct completion work;
> -       struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
> +       unsigned supplies;
> +       struct regulator_bulk_data supply_data[SI4713_NUM_SUPPLIES];
>         int gpio_reset;
>         u32 power_state;
>         u32 rds_enabled;
> diff --git a/include/media/si4713.h b/include/media/si4713.h
> index ed7353e..f98a0a7 100644
> --- a/include/media/si4713.h
> +++ b/include/media/si4713.h
> @@ -23,6 +23,8 @@
>   * Platform dependent definition
>   */
>  struct si4713_platform_data {
> +       const char * const *supply_names;
> +       unsigned supplies;
>         int gpio_reset; /* < 0 if not used */
>  };
>
> --
> 1.7.9.5
>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [Review Patch 0/9] si4713 usb device driver
  2013-11-04  9:33   ` Hans Verkuil
@ 2013-11-04 14:09     ` edubezval
  2013-11-04 14:13       ` Hans Verkuil
  0 siblings, 1 reply; 31+ messages in thread
From: edubezval @ 2013-11-04 14:09 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Dinesh Ram, Linux-Media, d ram

Hans,

On Mon, Nov 4, 2013 at 5:33 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> On 10/15/2013 07:37 PM, edubezval@gmail.com wrote:
>> Hello Dinesh,
>>
>> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>>> Hello Eduardo,
>>>
>>> In this patch series, I have addressed the comments by you
>>> concerning my last patch series.
>>> In the resulting patches, I have corrected most of the
>>> style issues and adding of comments. However, some warnings
>>> given out by checkpatch.pl (mostly complaing about lines longer
>>> than 80 characters) are still there because I saw that code readibility
>>> suffers by breaking up those lines.
>>>
>>> Also Hans has contributed patches 8 and 9 in this patch series
>>> which address the issues of the handling of unknown regulators,
>>> which have apparently changed since 3.10. Hans has tested it and the
>>> driver loads again.
>>>
>>> Let me know when you are able to test it again.
>>>
>>
>> Hopefully I will be able to give it a shot on n900 and on silabs
>> devboard until the end of the week. Thanks for not giving up.
>
> Did you find time to do this? I'm waiting for feedback from you.

sorry for the late answer, I was offline for two weeks taking care of
my newborn  son :-).

I am giving the series a second shot.

>
> Regards,
>
>         Hans



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [Review Patch 0/9] si4713 usb device driver
  2013-11-04 14:09     ` edubezval
@ 2013-11-04 14:13       ` Hans Verkuil
       [not found]         ` <CAP_RhzfWKc8y27uU4VXFu6cAt87NvO=BnLNq9WeGG_kpxihTKQ@mail.gmail.com>
  0 siblings, 1 reply; 31+ messages in thread
From: Hans Verkuil @ 2013-11-04 14:13 UTC (permalink / raw)
  To: edubezval; +Cc: Dinesh Ram, Linux-Media, d ram

On 11/04/2013 03:09 PM, edubezval@gmail.com wrote:
> Hans,
> 
> On Mon, Nov 4, 2013 at 5:33 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>> On 10/15/2013 07:37 PM, edubezval@gmail.com wrote:
>>> Hello Dinesh,
>>>
>>> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>>>> Hello Eduardo,
>>>>
>>>> In this patch series, I have addressed the comments by you
>>>> concerning my last patch series.
>>>> In the resulting patches, I have corrected most of the
>>>> style issues and adding of comments. However, some warnings
>>>> given out by checkpatch.pl (mostly complaing about lines longer
>>>> than 80 characters) are still there because I saw that code readibility
>>>> suffers by breaking up those lines.
>>>>
>>>> Also Hans has contributed patches 8 and 9 in this patch series
>>>> which address the issues of the handling of unknown regulators,
>>>> which have apparently changed since 3.10. Hans has tested it and the
>>>> driver loads again.
>>>>
>>>> Let me know when you are able to test it again.
>>>>
>>>
>>> Hopefully I will be able to give it a shot on n900 and on silabs
>>> devboard until the end of the week. Thanks for not giving up.
>>
>> Did you find time to do this? I'm waiting for feedback from you.
> 
> sorry for the late answer, I was offline for two weeks taking care of
> my newborn  son :-).

An excellent reason! Congratulations!

	Hans

> 
> I am giving the series a second shot.
> 
>>
>> Regards,
>>
>>         Hans
> 
> 
> 


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [Review Patch 0/9] si4713 usb device driver
       [not found]         ` <CAP_RhzfWKc8y27uU4VXFu6cAt87NvO=BnLNq9WeGG_kpxihTKQ@mail.gmail.com>
@ 2013-11-04 14:39           ` edubezval
  0 siblings, 0 replies; 31+ messages in thread
From: edubezval @ 2013-11-04 14:39 UTC (permalink / raw)
  To: d ram; +Cc: Hans Verkuil, Dinesh Ram, Linux-Media

On Mon, Nov 4, 2013 at 10:21 AM, d ram <dinesh.ram086@gmail.com> wrote:
> Hearty congratulations Eduardo !

Thanks,

> Btw...I didnt get any compilation error for the patch sent by Hans.
> Are you using the trunk version of the kernel?

I've just reset to v3.12 tag. The issue is actually produced by the
patch itself as it moves the macro definition, but still uses it in
the board file.

>
>
> On Mon, Nov 4, 2013 at 3:13 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>>
>> On 11/04/2013 03:09 PM, edubezval@gmail.com wrote:
>> > Hans,
>> >
>> > On Mon, Nov 4, 2013 at 5:33 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
>> >> On 10/15/2013 07:37 PM, edubezval@gmail.com wrote:
>> >>> Hello Dinesh,
>> >>>
>> >>> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch>
>> >>> wrote:
>> >>>> Hello Eduardo,
>> >>>>
>> >>>> In this patch series, I have addressed the comments by you
>> >>>> concerning my last patch series.
>> >>>> In the resulting patches, I have corrected most of the
>> >>>> style issues and adding of comments. However, some warnings
>> >>>> given out by checkpatch.pl (mostly complaing about lines longer
>> >>>> than 80 characters) are still there because I saw that code
>> >>>> readibility
>> >>>> suffers by breaking up those lines.
>> >>>>
>> >>>> Also Hans has contributed patches 8 and 9 in this patch series
>> >>>> which address the issues of the handling of unknown regulators,
>> >>>> which have apparently changed since 3.10. Hans has tested it and the
>> >>>> driver loads again.
>> >>>>
>> >>>> Let me know when you are able to test it again.
>> >>>>
>> >>>
>> >>> Hopefully I will be able to give it a shot on n900 and on silabs
>> >>> devboard until the end of the week. Thanks for not giving up.
>> >>
>> >> Did you find time to do this? I'm waiting for feedback from you.
>> >
>> > sorry for the late answer, I was offline for two weeks taking care of
>> > my newborn  son :-).
>>
>> An excellent reason! Congratulations!
>>
>>         Hans
>>
>> >
>> > I am giving the series a second shot.
>> >
>> >>
>> >> Regards,
>> >>
>> >>         Hans
>> >
>> >
>> >
>>
>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data
  2013-11-04 14:07     ` edubezval
@ 2013-11-05  8:38       ` Hans Verkuil
  2013-11-05 14:14         ` edubezval
  0 siblings, 1 reply; 31+ messages in thread
From: Hans Verkuil @ 2013-11-05  8:38 UTC (permalink / raw)
  To: edubezval; +Cc: Dinesh Ram, Linux-Media, Hans Verkuil, d ram, Hans Verkuil

Hi,

On 11/04/13 15:07, edubezval@gmail.com wrote:
> Hi,
> 
> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>> The supply list is needed by the platform driver, but not by the usb driver.
>> So this information belongs to the platform data and should not be hardcoded
>> in the subdevice driver.
>>
>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
> 
> Dinesh, could you please sign this patch too?
> 
>> ---
>>  arch/arm/mach-omap2/board-rx51-peripherals.c |    7 ++++
>>  drivers/media/radio/si4713/si4713.c          |   52 +++++++++++++-------------
>>  drivers/media/radio/si4713/si4713.h          |    3 +-
>>  include/media/si4713.h                       |    2 +
>>  4 files changed, 37 insertions(+), 27 deletions(-)
>>
>> diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
>> index f6fe388..eae73f7 100644
>> --- a/arch/arm/mach-omap2/board-rx51-peripherals.c
>> +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
>> @@ -776,7 +776,14 @@ static struct regulator_init_data rx51_vintdig = {
>>         },
>>  };
>>
>> +static const char * const si4713_supply_names[SI4713_NUM_SUPPLIES] = {
> 
> This patch produces the following compilation error:
> arch/arm/mach-omap2/board-rx51-peripherals.c:779:47: error:
> 'SI4713_NUM_SUPPLIES' undeclared here (not in a function)

Hmm, I thought I had compile-tested this, apparently not. Does it compile if
you just remove SI4713_NUM_SUPPLIES? It's not necessary here.

Regards,

	Hans

> arch/arm/mach-omap2/board-rx51-peripherals.c:785:14: error: bit-field
> '<anonymous>' width not an integer constant
> arch/arm/mach-omap2/board-rx51-peripherals.c:779:27: warning:
> 'si4713_supply_names' defined but not used [-Wunused-variable]
> make[1]: *** [arch/arm/mach-omap2/board-rx51-peripherals.o] Error 1
> make: *** [arch/arm/mach-omap2] Error 2
> make: *** Waiting for unfinished jobs....
> 
> 
>> +       "vio",
>> +       "vdd",
>> +};
>> +
>>  static struct si4713_platform_data rx51_si4713_i2c_data __initdata_or_module = {
>> +       .supplies       = ARRAY_SIZE(si4713_supply_names),
>> +       .supply_names   = si4713_supply_names,
>>         .gpio_reset     = RX51_FMTX_RESET_GPIO,
>>  };
>>
>> diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
>> index d297a5b..920dfa5 100644
>> --- a/drivers/media/radio/si4713/si4713.c
>> +++ b/drivers/media/radio/si4713/si4713.c
>> @@ -44,11 +44,6 @@ MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
>>  MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
>>  MODULE_VERSION("0.0.1");
>>
>> -static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
>> -       "vio",
>> -       "vdd",
>> -};
>> -
>>  #define DEFAULT_RDS_PI                 0x00
>>  #define DEFAULT_RDS_PTY                        0x00
>>  #define DEFAULT_RDS_DEVIATION          0x00C8
>> @@ -368,11 +363,12 @@ static int si4713_powerup(struct si4713_device *sdev)
>>         if (sdev->power_state)
>>                 return 0;
>>
>> -       err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
>> -                                   sdev->supplies);
>> -       if (err) {
>> -               v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
>> -               return err;
>> +       if (sdev->supplies) {
>> +               err = regulator_bulk_enable(sdev->supplies, sdev->supply_data);
>> +               if (err) {
>> +                       v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
>> +                       return err;
>> +               }
>>         }
>>         if (gpio_is_valid(sdev->gpio_reset)) {
>>                 udelay(50);
>> @@ -396,11 +392,12 @@ static int si4713_powerup(struct si4713_device *sdev)
>>                 if (client->irq)
>>                         err = si4713_write_property(sdev, SI4713_GPO_IEN,
>>                                                 SI4713_STC_INT | SI4713_CTS);
>> -       } else {
>> -               if (gpio_is_valid(sdev->gpio_reset))
>> -                       gpio_set_value(sdev->gpio_reset, 0);
>> -               err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
>> -                                            sdev->supplies);
>> +               return err;
>> +       }
>> +       if (gpio_is_valid(sdev->gpio_reset))
>> +               gpio_set_value(sdev->gpio_reset, 0);
>> +       if (sdev->supplies) {
>> +               err = regulator_bulk_disable(sdev->supplies, sdev->supply_data);
>>                 if (err)
>>                         v4l2_err(&sdev->sd,
>>                                  "Failed to disable supplies: %d\n", err);
>> @@ -432,11 +429,13 @@ static int si4713_powerdown(struct si4713_device *sdev)
>>                 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
>>                 if (gpio_is_valid(sdev->gpio_reset))
>>                         gpio_set_value(sdev->gpio_reset, 0);
>> -               err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
>> -                                            sdev->supplies);
>> -               if (err)
>> -                       v4l2_err(&sdev->sd,
>> -                                "Failed to disable supplies: %d\n", err);
>> +               if (sdev->supplies) {
>> +                       err = regulator_bulk_disable(sdev->supplies,
>> +                                                    sdev->supply_data);
>> +                       if (err)
>> +                               v4l2_err(&sdev->sd,
>> +                                        "Failed to disable supplies: %d\n", err);
>> +               }
>>                 sdev->power_state = POWER_OFF;
>>         }
>>
>> @@ -1381,13 +1380,14 @@ static int si4713_probe(struct i2c_client *client,
>>                 }
>>                 sdev->gpio_reset = pdata->gpio_reset;
>>                 gpio_direction_output(sdev->gpio_reset, 0);
>> +               sdev->supplies = pdata->supplies;
>>         }
>>
>> -       for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
>> -               sdev->supplies[i].supply = si4713_supply_names[i];
>> +       for (i = 0; i < sdev->supplies; i++)
>> +               sdev->supply_data[i].supply = pdata->supply_names[i];
>>
>> -       rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
>> -                                 sdev->supplies);
>> +       rval = regulator_bulk_get(&client->dev, sdev->supplies,
>> +                                 sdev->supply_data);
>>         if (rval) {
>>                 dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
>>                 goto free_gpio;
>> @@ -1500,7 +1500,7 @@ free_irq:
>>  free_ctrls:
>>         v4l2_ctrl_handler_free(hdl);
>>  put_reg:
>> -       regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
>> +       regulator_bulk_free(sdev->supplies, sdev->supply_data);
>>  free_gpio:
>>         if (gpio_is_valid(sdev->gpio_reset))
>>                 gpio_free(sdev->gpio_reset);
>> @@ -1524,7 +1524,7 @@ static int si4713_remove(struct i2c_client *client)
>>
>>         v4l2_device_unregister_subdev(sd);
>>         v4l2_ctrl_handler_free(sd->ctrl_handler);
>> -       regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
>> +       regulator_bulk_free(sdev->supplies, sdev->supply_data);
>>         if (gpio_is_valid(sdev->gpio_reset))
>>                 gpio_free(sdev->gpio_reset);
>>         kfree(sdev);
>> diff --git a/drivers/media/radio/si4713/si4713.h b/drivers/media/radio/si4713/si4713.h
>> index dc0ce66..986e27b 100644
>> --- a/drivers/media/radio/si4713/si4713.h
>> +++ b/drivers/media/radio/si4713/si4713.h
>> @@ -227,7 +227,8 @@ struct si4713_device {
>>                 struct v4l2_ctrl *tune_ant_cap;
>>         };
>>         struct completion work;
>> -       struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
>> +       unsigned supplies;
>> +       struct regulator_bulk_data supply_data[SI4713_NUM_SUPPLIES];
>>         int gpio_reset;
>>         u32 power_state;
>>         u32 rds_enabled;
>> diff --git a/include/media/si4713.h b/include/media/si4713.h
>> index ed7353e..f98a0a7 100644
>> --- a/include/media/si4713.h
>> +++ b/include/media/si4713.h
>> @@ -23,6 +23,8 @@
>>   * Platform dependent definition
>>   */
>>  struct si4713_platform_data {
>> +       const char * const *supply_names;
>> +       unsigned supplies;
>>         int gpio_reset; /* < 0 if not used */
>>  };
>>
>> --
>> 1.7.9.5
>>
> 
> 
> 

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data
  2013-11-05  8:38       ` Hans Verkuil
@ 2013-11-05 14:14         ` edubezval
  0 siblings, 0 replies; 31+ messages in thread
From: edubezval @ 2013-11-05 14:14 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Dinesh Ram, Linux-Media, Hans Verkuil, d ram, Hans Verkuil

On Tue, Nov 5, 2013 at 4:38 AM, Hans Verkuil <hansverk@cisco.com> wrote:
> Hi,
>
> On 11/04/13 15:07, edubezval@gmail.com wrote:
>> Hi,
>>
>> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>>> The supply list is needed by the platform driver, but not by the usb driver.
>>> So this information belongs to the platform data and should not be hardcoded
>>> in the subdevice driver.
>>>
>>> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
>>
>> Dinesh, could you please sign this patch too?
>>
>>> ---
>>>  arch/arm/mach-omap2/board-rx51-peripherals.c |    7 ++++
>>>  drivers/media/radio/si4713/si4713.c          |   52 +++++++++++++-------------
>>>  drivers/media/radio/si4713/si4713.h          |    3 +-
>>>  include/media/si4713.h                       |    2 +
>>>  4 files changed, 37 insertions(+), 27 deletions(-)
>>>
>>> diff --git a/arch/arm/mach-omap2/board-rx51-peripherals.c b/arch/arm/mach-omap2/board-rx51-peripherals.c
>>> index f6fe388..eae73f7 100644
>>> --- a/arch/arm/mach-omap2/board-rx51-peripherals.c
>>> +++ b/arch/arm/mach-omap2/board-rx51-peripherals.c
>>> @@ -776,7 +776,14 @@ static struct regulator_init_data rx51_vintdig = {
>>>         },
>>>  };
>>>
>>> +static const char * const si4713_supply_names[SI4713_NUM_SUPPLIES] = {
>>
>> This patch produces the following compilation error:
>> arch/arm/mach-omap2/board-rx51-peripherals.c:779:47: error:
>> 'SI4713_NUM_SUPPLIES' undeclared here (not in a function)
>
> Hmm, I thought I had compile-tested this, apparently not. Does it compile if
> you just remove SI4713_NUM_SUPPLIES? It's not necessary here.

Yes, it does compile. I just tried compiling testing with
omap2plus_defconfig, that is what I use to boot n900 too.

>
> Regards,
>
>         Hans
>
>> arch/arm/mach-omap2/board-rx51-peripherals.c:785:14: error: bit-field
>> '<anonymous>' width not an integer constant
>> arch/arm/mach-omap2/board-rx51-peripherals.c:779:27: warning:
>> 'si4713_supply_names' defined but not used [-Wunused-variable]
>> make[1]: *** [arch/arm/mach-omap2/board-rx51-peripherals.o] Error 1
>> make: *** [arch/arm/mach-omap2] Error 2
>> make: *** Waiting for unfinished jobs....
>>
>>
>>> +       "vio",
>>> +       "vdd",
>>> +};
>>> +
>>>  static struct si4713_platform_data rx51_si4713_i2c_data __initdata_or_module = {
>>> +       .supplies       = ARRAY_SIZE(si4713_supply_names),
>>> +       .supply_names   = si4713_supply_names,
>>>         .gpio_reset     = RX51_FMTX_RESET_GPIO,
>>>  };
>>>
>>> diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
>>> index d297a5b..920dfa5 100644
>>> --- a/drivers/media/radio/si4713/si4713.c
>>> +++ b/drivers/media/radio/si4713/si4713.c
>>> @@ -44,11 +44,6 @@ MODULE_AUTHOR("Eduardo Valentin <eduardo.valentin@nokia.com>");
>>>  MODULE_DESCRIPTION("I2C driver for Si4713 FM Radio Transmitter");
>>>  MODULE_VERSION("0.0.1");
>>>
>>> -static const char *si4713_supply_names[SI4713_NUM_SUPPLIES] = {
>>> -       "vio",
>>> -       "vdd",
>>> -};
>>> -
>>>  #define DEFAULT_RDS_PI                 0x00
>>>  #define DEFAULT_RDS_PTY                        0x00
>>>  #define DEFAULT_RDS_DEVIATION          0x00C8
>>> @@ -368,11 +363,12 @@ static int si4713_powerup(struct si4713_device *sdev)
>>>         if (sdev->power_state)
>>>                 return 0;
>>>
>>> -       err = regulator_bulk_enable(ARRAY_SIZE(sdev->supplies),
>>> -                                   sdev->supplies);
>>> -       if (err) {
>>> -               v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
>>> -               return err;
>>> +       if (sdev->supplies) {
>>> +               err = regulator_bulk_enable(sdev->supplies, sdev->supply_data);
>>> +               if (err) {
>>> +                       v4l2_err(&sdev->sd, "Failed to enable supplies: %d\n", err);
>>> +                       return err;
>>> +               }
>>>         }
>>>         if (gpio_is_valid(sdev->gpio_reset)) {
>>>                 udelay(50);
>>> @@ -396,11 +392,12 @@ static int si4713_powerup(struct si4713_device *sdev)
>>>                 if (client->irq)
>>>                         err = si4713_write_property(sdev, SI4713_GPO_IEN,
>>>                                                 SI4713_STC_INT | SI4713_CTS);
>>> -       } else {
>>> -               if (gpio_is_valid(sdev->gpio_reset))
>>> -                       gpio_set_value(sdev->gpio_reset, 0);
>>> -               err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
>>> -                                            sdev->supplies);
>>> +               return err;
>>> +       }
>>> +       if (gpio_is_valid(sdev->gpio_reset))
>>> +               gpio_set_value(sdev->gpio_reset, 0);
>>> +       if (sdev->supplies) {
>>> +               err = regulator_bulk_disable(sdev->supplies, sdev->supply_data);
>>>                 if (err)
>>>                         v4l2_err(&sdev->sd,
>>>                                  "Failed to disable supplies: %d\n", err);
>>> @@ -432,11 +429,13 @@ static int si4713_powerdown(struct si4713_device *sdev)
>>>                 v4l2_dbg(1, debug, &sdev->sd, "Device in reset mode\n");
>>>                 if (gpio_is_valid(sdev->gpio_reset))
>>>                         gpio_set_value(sdev->gpio_reset, 0);
>>> -               err = regulator_bulk_disable(ARRAY_SIZE(sdev->supplies),
>>> -                                            sdev->supplies);
>>> -               if (err)
>>> -                       v4l2_err(&sdev->sd,
>>> -                                "Failed to disable supplies: %d\n", err);
>>> +               if (sdev->supplies) {
>>> +                       err = regulator_bulk_disable(sdev->supplies,
>>> +                                                    sdev->supply_data);
>>> +                       if (err)
>>> +                               v4l2_err(&sdev->sd,
>>> +                                        "Failed to disable supplies: %d\n", err);
>>> +               }
>>>                 sdev->power_state = POWER_OFF;
>>>         }
>>>
>>> @@ -1381,13 +1380,14 @@ static int si4713_probe(struct i2c_client *client,
>>>                 }
>>>                 sdev->gpio_reset = pdata->gpio_reset;
>>>                 gpio_direction_output(sdev->gpio_reset, 0);
>>> +               sdev->supplies = pdata->supplies;
>>>         }
>>>
>>> -       for (i = 0; i < ARRAY_SIZE(sdev->supplies); i++)
>>> -               sdev->supplies[i].supply = si4713_supply_names[i];
>>> +       for (i = 0; i < sdev->supplies; i++)
>>> +               sdev->supply_data[i].supply = pdata->supply_names[i];
>>>
>>> -       rval = regulator_bulk_get(&client->dev, ARRAY_SIZE(sdev->supplies),
>>> -                                 sdev->supplies);
>>> +       rval = regulator_bulk_get(&client->dev, sdev->supplies,
>>> +                                 sdev->supply_data);
>>>         if (rval) {
>>>                 dev_err(&client->dev, "Cannot get regulators: %d\n", rval);
>>>                 goto free_gpio;
>>> @@ -1500,7 +1500,7 @@ free_irq:
>>>  free_ctrls:
>>>         v4l2_ctrl_handler_free(hdl);
>>>  put_reg:
>>> -       regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
>>> +       regulator_bulk_free(sdev->supplies, sdev->supply_data);
>>>  free_gpio:
>>>         if (gpio_is_valid(sdev->gpio_reset))
>>>                 gpio_free(sdev->gpio_reset);
>>> @@ -1524,7 +1524,7 @@ static int si4713_remove(struct i2c_client *client)
>>>
>>>         v4l2_device_unregister_subdev(sd);
>>>         v4l2_ctrl_handler_free(sd->ctrl_handler);
>>> -       regulator_bulk_free(ARRAY_SIZE(sdev->supplies), sdev->supplies);
>>> +       regulator_bulk_free(sdev->supplies, sdev->supply_data);
>>>         if (gpio_is_valid(sdev->gpio_reset))
>>>                 gpio_free(sdev->gpio_reset);
>>>         kfree(sdev);
>>> diff --git a/drivers/media/radio/si4713/si4713.h b/drivers/media/radio/si4713/si4713.h
>>> index dc0ce66..986e27b 100644
>>> --- a/drivers/media/radio/si4713/si4713.h
>>> +++ b/drivers/media/radio/si4713/si4713.h
>>> @@ -227,7 +227,8 @@ struct si4713_device {
>>>                 struct v4l2_ctrl *tune_ant_cap;
>>>         };
>>>         struct completion work;
>>> -       struct regulator_bulk_data supplies[SI4713_NUM_SUPPLIES];
>>> +       unsigned supplies;
>>> +       struct regulator_bulk_data supply_data[SI4713_NUM_SUPPLIES];
>>>         int gpio_reset;
>>>         u32 power_state;
>>>         u32 rds_enabled;
>>> diff --git a/include/media/si4713.h b/include/media/si4713.h
>>> index ed7353e..f98a0a7 100644
>>> --- a/include/media/si4713.h
>>> +++ b/include/media/si4713.h
>>> @@ -23,6 +23,8 @@
>>>   * Platform dependent definition
>>>   */
>>>  struct si4713_platform_data {
>>> +       const char * const *supply_names;
>>> +       unsigned supplies;
>>>         int gpio_reset; /* < 0 if not used */
>>>  };
>>>
>>> --
>>> 1.7.9.5
>>>
>>
>>
>>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713
  2013-10-15 15:24   ` [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713 Dinesh Ram
@ 2013-11-05 14:18     ` edubezval
  2013-11-07  7:40       ` Hans Verkuil
  2013-11-18 14:47       ` edubezval
  0 siblings, 2 replies; 31+ messages in thread
From: edubezval @ 2013-11-05 14:18 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: Linux-Media, Hans Verkuil, d ram

Dinesh

On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
> This is the USB driver for the Silicon Labs development board.
> It contains the Si4713 FM transmitter chip.
>

I tried this driver again. The system attempts to probe the device but
it fails because the product revision read out of the USB device is
wrong.
[  220.855158] usb 2-1.3.3: new full-speed USB device number 10 using ehci-pci
[  220.949677] usb 2-1.3.3: New USB device found, idVendor=10c4, idProduct=8244
[  220.949683] usb 2-1.3.3: New USB device strings: Mfr=1, Product=2,
SerialNumber=3
[  220.949688] usb 2-1.3.3: Product: Si47xx Baseboard
[  220.949691] usb 2-1.3.3: Manufacturer: SILICON LABORATORIES INC.
[  220.949695] usb 2-1.3.3: SerialNumber: CBDA8-00-0
[  220.950157] usbhid 2-1.3.3:1.0: couldn't find an input interrupt endpoint
[ 1014.981012] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
discovered: (10C4:8244)
[ 1015.870984] si4713 12-0063: IRQ not configured. Using timeouts.
[ 1015.943551] si4713 12-0063: Invalid product number   <<< Here is
the code without modification
[ 1015.943556] si4713 12-0063: Failed to probe device information.
[ 1015.943568] si4713: probe of 12-0063 failed with error -22
[ 1015.943613] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
[ 1015.943672] usbcore: registered new interface driver radio-usb-si4713
[ 1274.419987] perf samples too long (2504 > 2500), lowering
kernel.perf_event_max_sample_rate to 50000
[ 1308.851059] usbcore: deregistering interface driver radio-usb-si4713
[ 1500.478308] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
discovered: (10C4:8244)
[ 1500.612240] si4713 12-0063: IRQ not configured. Using timeouts.
[ 1500.683489] si4713 12-0063: Invalid product number 0x15 <<< Here it
prints the PN read
[ 1500.683495] si4713 12-0063: Failed to probe device information.
[ 1500.683509] si4713: probe of 12-0063 failed with error -22
[ 1500.683558] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
[ 1500.683624] usbcore: registered new interface driver radio-usb-si4713

Here is simple diff of what I used to print the PN value:
diff --git a/drivers/media/radio/si4713/si4713.c
b/drivers/media/radio/si4713/si4713.c
index aadecb5..ee53584 100644
--- a/drivers/media/radio/si4713/si4713.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -464,7 +464,7 @@ static int si4713_checkrev(struct si4713_device *sdev)
                v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
                                client->addr << 1, client->adapter->name);
        } else {
-               v4l2_err(&sdev->sd, "Invalid product number\n");
+               v4l2_err(&sdev->sd, "Invalid product number 0x%X\n", resp[1]);
                rval = -EINVAL;
        }
        return rval;

It is expected to be 0x0D  instead of 0x15, if I am not mistaken.

> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
> ---
>  drivers/media/radio/si4713/Kconfig            |   15 +
>  drivers/media/radio/si4713/Makefile           |    1 +
>  drivers/media/radio/si4713/radio-usb-si4713.c |  540 +++++++++++++++++++++++++
>  3 files changed, 556 insertions(+)
>  create mode 100644 drivers/media/radio/si4713/radio-usb-si4713.c
>
> diff --git a/drivers/media/radio/si4713/Kconfig b/drivers/media/radio/si4713/Kconfig
> index ec640b8..a7c3ba8 100644
> --- a/drivers/media/radio/si4713/Kconfig
> +++ b/drivers/media/radio/si4713/Kconfig
> @@ -1,3 +1,18 @@
> +config USB_SI4713
> +       tristate "Silicon Labs Si4713 FM Radio Transmitter support with USB"
> +       depends on USB && RADIO_SI4713
> +       select SI4713
> +       ---help---
> +         This is a driver for USB devices with the Silicon Labs SI4713
> +         chip. Currently these devices are known to work.
> +         - 10c4:8244: Silicon Labs FM Transmitter USB device.
> +
> +         Say Y here if you want to connect this type of radio to your
> +         computer's USB port.
> +
> +         To compile this driver as a module, choose M here: the
> +         module will be called radio-usb-si4713.
> +
>  config PLATFORM_SI4713
>         tristate "Silicon Labs Si4713 FM Radio Transmitter support with I2C"
>         depends on I2C && RADIO_SI4713
> diff --git a/drivers/media/radio/si4713/Makefile b/drivers/media/radio/si4713/Makefile
> index 9d0bd0e..6524674 100644
> --- a/drivers/media/radio/si4713/Makefile
> +++ b/drivers/media/radio/si4713/Makefile
> @@ -3,5 +3,6 @@
>  #
>
>  obj-$(CONFIG_I2C_SI4713) += si4713.o
> +obj-$(CONFIG_USB_SI4713) += radio-usb-si4713.o
>  obj-$(CONFIG_PLATFORM_SI4713) += radio-platform-si4713.o
>
> diff --git a/drivers/media/radio/si4713/radio-usb-si4713.c b/drivers/media/radio/si4713/radio-usb-si4713.c
> new file mode 100644
> index 0000000..a75e2c8
> --- /dev/null
> +++ b/drivers/media/radio/si4713/radio-usb-si4713.c
> @@ -0,0 +1,540 @@
> +/*
> + * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
> + * All rights reserved.
> + *
> + * This program is free software; you may redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; version 2 of the License.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +/* kernel includes */
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/usb.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/input.h>
> +#include <linux/mutex.h>
> +#include <linux/i2c.h>
> +/* V4l includes */
> +#include <linux/videodev2.h>
> +#include <media/v4l2-common.h>
> +#include <media/v4l2-device.h>
> +#include <media/v4l2-ioctl.h>
> +#include <media/v4l2-event.h>
> +#include <media/si4713.h>
> +
> +#include "si4713.h"
> +
> +/* driver and module definitions */
> +MODULE_AUTHOR("Dinesh Ram <dinesh.ram@cern.ch>");
> +MODULE_DESCRIPTION("Si4713 FM Transmitter USB driver");
> +MODULE_LICENSE("GPL v2");
> +
> +/* The Device announces itself as Cygnal Integrated Products, Inc. */
> +#define USB_SI4713_VENDOR              0x10c4
> +#define USB_SI4713_PRODUCT             0x8244
> +
> +#define BUFFER_LENGTH                  64
> +#define USB_TIMEOUT                    1000
> +#define USB_RESP_TIMEOUT               50000
> +
> +/* USB Device ID List */
> +static struct usb_device_id usb_si4713_usb_device_table[] = {
> +       {USB_DEVICE_AND_INTERFACE_INFO(USB_SI4713_VENDOR, USB_SI4713_PRODUCT,
> +                                                       USB_CLASS_HID, 0, 0) },
> +       { }                                             /* Terminating entry */
> +};
> +
> +MODULE_DEVICE_TABLE(usb, usb_si4713_usb_device_table);
> +
> +struct si4713_usb_device {
> +       struct usb_device       *usbdev;
> +       struct usb_interface    *intf;
> +       struct video_device     vdev;
> +       struct v4l2_device      v4l2_dev;
> +       struct v4l2_subdev      *v4l2_subdev;
> +       struct mutex            lock;
> +       struct i2c_adapter      i2c_adapter;
> +
> +       u8                      *buffer;
> +};
> +
> +static inline struct si4713_usb_device *to_si4713_dev(struct v4l2_device *v4l2_dev)
> +{
> +       return container_of(v4l2_dev, struct si4713_usb_device, v4l2_dev);
> +}
> +
> +static int vidioc_querycap(struct file *file, void *priv,
> +                                       struct v4l2_capability *v)
> +{
> +       struct si4713_usb_device *radio = video_drvdata(file);
> +
> +       strlcpy(v->driver, "radio-usb-si4713", sizeof(v->driver));
> +       strlcpy(v->card, "Si4713 FM Transmitter", sizeof(v->card));
> +       usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
> +       v->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
> +       v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
> +
> +       return 0;
> +}
> +
> +static int vidioc_g_modulator(struct file *file, void *priv,
> +                               struct v4l2_modulator *vm)
> +{
> +       struct si4713_usb_device *radio = video_drvdata(file);
> +
> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, g_modulator, vm);
> +}
> +
> +static int vidioc_s_modulator(struct file *file, void *priv,
> +                               const struct v4l2_modulator *vm)
> +{
> +       struct si4713_usb_device *radio = video_drvdata(file);
> +
> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, s_modulator, vm);
> +}
> +
> +static int vidioc_s_frequency(struct file *file, void *priv,
> +                               const struct v4l2_frequency *vf)
> +{
> +       struct si4713_usb_device *radio = video_drvdata(file);
> +
> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, s_frequency, vf);
> +}
> +
> +static int vidioc_g_frequency(struct file *file, void *priv,
> +                               struct v4l2_frequency *vf)
> +{
> +       struct si4713_usb_device *radio = video_drvdata(file);
> +
> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, g_frequency, vf);
> +}
> +
> +static const struct v4l2_ioctl_ops usb_si4713_ioctl_ops = {
> +       .vidioc_querycap          = vidioc_querycap,
> +       .vidioc_g_modulator       = vidioc_g_modulator,
> +       .vidioc_s_modulator       = vidioc_s_modulator,
> +       .vidioc_g_frequency       = vidioc_g_frequency,
> +       .vidioc_s_frequency       = vidioc_s_frequency,
> +       .vidioc_log_status        = v4l2_ctrl_log_status,
> +       .vidioc_subscribe_event   = v4l2_ctrl_subscribe_event,
> +       .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
> +};
> +
> +/* File system interface */
> +static const struct v4l2_file_operations usb_si4713_fops = {
> +       .owner          = THIS_MODULE,
> +       .open           = v4l2_fh_open,
> +       .release        = v4l2_fh_release,
> +       .poll           = v4l2_ctrl_poll,
> +       .unlocked_ioctl = video_ioctl2,
> +};
> +
> +static void usb_si4713_video_device_release(struct v4l2_device *v4l2_dev)
> +{
> +       struct si4713_usb_device *radio = to_si4713_dev(v4l2_dev);
> +       struct i2c_adapter *adapter = &radio->i2c_adapter;
> +
> +       i2c_del_adapter(adapter);
> +       v4l2_device_unregister(&radio->v4l2_dev);
> +       kfree(radio->buffer);
> +       kfree(radio);
> +}
> +
> +/*
> + * This command sequence emulates the behaviour of the Windows driver.
> + * The structure of these commands was determined by sniffing the
> + * usb traffic of the device during startup.
> + * Most likely, these commands make some queries to the device.
> + * Commands are sent to enquire parameters like the bus mode,
> + * component revision, boot mode, the device serial number etc.
> + *
> + * These commands are necessary to be sent in this order during startup.
> + * The device fails to powerup if these commands are not sent.
> + *
> + * The complete list of startup commands is given in the start_seq table below.
> + */
> +static int si4713_send_startup_command(struct si4713_usb_device *radio)
> +{
> +       unsigned long until_jiffies = jiffies + usecs_to_jiffies(USB_RESP_TIMEOUT) + 1;
> +       u8 *buffer = radio->buffer;
> +       int retval;
> +
> +       /* send the command */
> +       retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
> +                                       0x09, 0x21, 0x033f, 0, radio->buffer,
> +                                       BUFFER_LENGTH, USB_TIMEOUT);
> +       if (retval < 0)
> +               return retval;
> +
> +       for (;;) {
> +               /* receive the response */
> +               retval = usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
> +                               0x01, 0xa1, 0x033f, 0, radio->buffer,
> +                               BUFFER_LENGTH, USB_TIMEOUT);
> +               if (retval < 0)
> +                       return retval;
> +               if (!radio->buffer[1]) {
> +                       /* USB traffic sniffing showed that some commands require
> +                        * additional checks. */
> +                       switch (buffer[1]) {
> +                       case 0x32:
> +                               if (radio->buffer[2] == 0)
> +                                       return 0;
> +                               break;
> +                       case 0x14:
> +                       case 0x12:
> +                               if (radio->buffer[2] & SI4713_CTS)
> +                                       return 0;
> +                               break;
> +                       case 0x06:
> +                               if ((radio->buffer[2] & SI4713_CTS) && radio->buffer[9] == 0x08)
> +                                       return 0;
> +                               break;
> +                       default:
> +                               return 0;
> +                       }
> +               }
> +               if (jiffies > until_jiffies)
> +                       return -EIO;
> +               msleep(3);
> +       }
> +
> +       return retval;
> +}
> +
> +struct si4713_start_seq_table {
> +       int len;
> +       u8 payload[8];
> +};
> +
> +/*
> + * Some of the startup commands that could be recognized are :
> + * (0x03): Get serial number of the board (Response : CB000-00-00)
> + * (0x06, 0x03, 0x03, 0x08, 0x01, 0x0f) : Get Component revision
> + */
> +struct si4713_start_seq_table start_seq[] = {
> +
> +       { 1, { 0x03 } },
> +       { 2, { 0x32, 0x7f } },
> +       { 6, { 0x06, 0x03, 0x03, 0x08, 0x01, 0x0f } },
> +       { 2, { 0x14, 0x02 } },
> +       { 2, { 0x09, 0x90 } },
> +       { 3, { 0x08, 0x90, 0xfa } },
> +       { 2, { 0x36, 0x01 } },
> +       { 2, { 0x05, 0x03 } },
> +       { 7, { 0x06, 0x00, 0x06, 0x0e, 0x01, 0x0f, 0x05 } },
> +       { 1, { 0x12 } },
> +       /* Commands that are sent after pressing the 'Initialize'
> +               button in the windows application */
> +       { 1, { 0x03 } },
> +       { 1, { 0x01 } },
> +       { 2, { 0x09, 0x90 } },
> +       { 3, { 0x08, 0x90, 0xfa } },
> +       { 1, { 0x34 } },
> +       { 2, { 0x35, 0x01 } },
> +       { 2, { 0x36, 0x01 } },
> +       { 2, { 0x30, 0x09 } },
> +       { 4, { 0x30, 0x06, 0x00, 0xe2 } },
> +       { 3, { 0x31, 0x01, 0x30 } },
> +       { 3, { 0x31, 0x04, 0x09 } },
> +       { 2, { 0x05, 0x02 } },
> +       { 6, { 0x06, 0x03, 0x03, 0x08, 0x01, 0x0f } },
> +};
> +
> +static int si4713_start_seq(struct si4713_usb_device *radio)
> +{
> +       int retval = 0;
> +       int i;
> +
> +       radio->buffer[0] = 0x3f;
> +
> +       for (i = 0; i < ARRAY_SIZE(start_seq); i++) {
> +               int len = start_seq[i].len;
> +               u8 *payload = start_seq[i].payload;
> +
> +               memcpy(radio->buffer + 1, payload, len);
> +               memset(radio->buffer + len + 1, 0, BUFFER_LENGTH - 1 - len);
> +               retval = si4713_send_startup_command(radio);
> +       }
> +
> +       return retval;
> +}
> +
> +static struct i2c_board_info si4713_board_info = {
> +       I2C_BOARD_INFO("si4713", SI4713_I2C_ADDR_BUSEN_HIGH),
> +};
> +
> +struct si4713_command_table {
> +       int command_id;
> +       u8 payload[8];
> +};
> +
> +/*
> + * Structure of a command :
> + *     Byte 1 : 0x3f (always)
> + *     Byte 2 : 0x06 (send a command)
> + *     Byte 3 : Unknown
> + *     Byte 4 : Number of arguments + 1 (for the command byte)
> + *     Byte 5 : Number of response bytes
> + */
> +struct si4713_command_table command_table[] = {
> +
> +       { SI4713_CMD_POWER_UP,          { 0x00, SI4713_PWUP_NARGS + 1, SI4713_PWUP_NRESP} },
> +       { SI4713_CMD_GET_REV,           { 0x03, 0x01, SI4713_GETREV_NRESP } },
> +       { SI4713_CMD_POWER_DOWN,        { 0x00, 0x01, SI4713_PWDN_NRESP} },
> +       { SI4713_CMD_SET_PROPERTY,      { 0x00, SI4713_SET_PROP_NARGS + 1, SI4713_SET_PROP_NRESP } },
> +       { SI4713_CMD_GET_PROPERTY,      { 0x00, SI4713_GET_PROP_NARGS + 1, SI4713_GET_PROP_NRESP } },
> +       { SI4713_CMD_TX_TUNE_FREQ,      { 0x03, SI4713_TXFREQ_NARGS + 1, SI4713_TXFREQ_NRESP } },
> +       { SI4713_CMD_TX_TUNE_POWER,     { 0x03, SI4713_TXPWR_NARGS + 1, SI4713_TXPWR_NRESP } },
> +       { SI4713_CMD_TX_TUNE_MEASURE,   { 0x03, SI4713_TXMEA_NARGS + 1, SI4713_TXMEA_NRESP } },
> +       { SI4713_CMD_TX_TUNE_STATUS,    { 0x00, SI4713_TXSTATUS_NARGS + 1, SI4713_TXSTATUS_NRESP } },
> +       { SI4713_CMD_TX_ASQ_STATUS,     { 0x03, SI4713_ASQSTATUS_NARGS + 1, SI4713_ASQSTATUS_NRESP } },
> +       { SI4713_CMD_GET_INT_STATUS,    { 0x03, 0x01, SI4713_GET_STATUS_NRESP } },
> +       { SI4713_CMD_TX_RDS_BUFF,       { 0x03, SI4713_RDSBUFF_NARGS + 1, SI4713_RDSBUFF_NRESP } },
> +       { SI4713_CMD_TX_RDS_PS,         { 0x00, SI4713_RDSPS_NARGS + 1, SI4713_RDSPS_NRESP } },
> +};
> +
> +static int send_command(struct si4713_usb_device *radio, u8 *payload, char *data, int len)
> +{
> +       int retval;
> +
> +       radio->buffer[0] = 0x3f;
> +       radio->buffer[1] = 0x06;
> +
> +       memcpy(radio->buffer + 2, payload, 3);
> +       memcpy(radio->buffer + 5, data, len);
> +       memset(radio->buffer + 5 + len, 0, BUFFER_LENGTH - 5 - len);
> +
> +       /* send the command */
> +       retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
> +                                       0x09, 0x21, 0x033f, 0, radio->buffer,
> +                                       BUFFER_LENGTH, USB_TIMEOUT);
> +
> +       return retval < 0 ? retval : 0;
> +}
> +
> +static int si4713_i2c_read(struct si4713_usb_device *radio, char *data, int len)
> +{
> +       unsigned long until_jiffies = jiffies + usecs_to_jiffies(USB_RESP_TIMEOUT) + 1;
> +       int retval;
> +
> +       /* receive the response */
> +       for (;;) {
> +               retval = usb_control_msg(radio->usbdev,
> +                                       usb_rcvctrlpipe(radio->usbdev, 0),
> +                                       0x01, 0xa1, 0x033f, 0, radio->buffer,
> +                                       BUFFER_LENGTH, USB_TIMEOUT);
> +               if (retval < 0)
> +                       return retval;
> +
> +               /*
> +                * Check that we get a valid reply back (buffer[1] == 0) and
> +                * that CTS is set before returning, otherwise we wait and try
> +                * again. The i2c driver also does the CTS check, but the timeouts
> +                * used there are much too small for this USB driver, so we wait
> +                * for it here.
> +                */
> +               if (radio->buffer[1] == 0 && (radio->buffer[2] & SI4713_CTS)) {
> +                       memcpy(data, radio->buffer + 2, len);
> +                       return 0;
> +               }
> +               if (jiffies > until_jiffies) {
> +                       /* Zero the status value, ensuring CTS isn't set */
> +                       data[0] = 0;
> +                       return 0;
> +               }
> +               msleep(3);
> +       }
> +}
> +
> +static int si4713_i2c_write(struct si4713_usb_device *radio, char *data, int len)
> +{
> +       int retval = -EINVAL;
> +       int i;
> +
> +       if (len > BUFFER_LENGTH - 5)
> +               return -EINVAL;
> +
> +       for (i = 0; i < ARRAY_SIZE(command_table); i++) {
> +               if (data[0] == command_table[i].command_id)
> +                       retval = send_command(radio, command_table[i].payload,
> +                                               data, len);
> +       }
> +
> +       return retval < 0 ? retval : 0;
> +}
> +
> +static int si4713_transfer(struct i2c_adapter *i2c_adapter,
> +                               struct i2c_msg *msgs, int num)
> +{
> +       struct si4713_usb_device *radio = i2c_get_adapdata(i2c_adapter);
> +       int retval = -EINVAL;
> +       int i;
> +
> +       if (num <= 0)
> +               return 0;
> +
> +       for (i = 0; i < num; i++) {
> +               if (msgs[i].flags & I2C_M_RD)
> +                       retval = si4713_i2c_read(radio, msgs[i].buf, msgs[i].len);
> +               else
> +                       retval = si4713_i2c_write(radio, msgs[i].buf, msgs[i].len);
> +               if (retval)
> +                       break;
> +       }
> +
> +       return retval ? retval : num;
> +}
> +
> +static u32 si4713_functionality(struct i2c_adapter *adapter)
> +{
> +       return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
> +}
> +
> +static struct i2c_algorithm si4713_algo = {
> +       .master_xfer   = si4713_transfer,
> +       .functionality = si4713_functionality,
> +};
> +
> +/* This name value shows up in the sysfs filename associated
> +               with this I2C adapter */
> +static struct i2c_adapter si4713_i2c_adapter_template = {
> +       .name   = "si4713-i2c",
> +       .owner  = THIS_MODULE,
> +       .algo   = &si4713_algo,
> +};
> +
> +int si4713_register_i2c_adapter(struct si4713_usb_device *radio)
> +{
> +       radio->i2c_adapter = si4713_i2c_adapter_template;
> +       /* set up sysfs linkage to our parent device */
> +       radio->i2c_adapter.dev.parent = &radio->usbdev->dev;
> +       i2c_set_adapdata(&radio->i2c_adapter, radio);
> +
> +       return i2c_add_adapter(&radio->i2c_adapter);
> +}
> +
> +/* check if the device is present and register with v4l and usb if it is */
> +static int usb_si4713_probe(struct usb_interface *intf,
> +                               const struct usb_device_id *id)
> +{
> +       struct si4713_usb_device *radio;
> +       struct i2c_adapter *adapter;
> +       struct v4l2_subdev *sd;
> +       int retval = -ENOMEM;
> +
> +       dev_info(&intf->dev, "Si4713 development board discovered: (%04X:%04X)\n",
> +                       id->idVendor, id->idProduct);
> +
> +       /* Initialize local device structure */
> +       radio = kzalloc(sizeof(struct si4713_usb_device), GFP_KERNEL);
> +       if (radio)
> +               radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
> +
> +       if (!radio || !radio->buffer) {
> +               dev_err(&intf->dev, "kmalloc for si4713_usb_device failed\n");
> +               kfree(radio);
> +               return -ENOMEM;
> +       }
> +
> +       mutex_init(&radio->lock);
> +
> +       radio->usbdev = interface_to_usbdev(intf);
> +       radio->intf = intf;
> +       usb_set_intfdata(intf, &radio->v4l2_dev);
> +
> +       retval = si4713_start_seq(radio);
> +       if (retval < 0)
> +               goto err_v4l2;
> +
> +       retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
> +       if (retval < 0) {
> +               dev_err(&intf->dev, "couldn't register v4l2_device\n");
> +               goto err_v4l2;
> +       }
> +
> +       retval = si4713_register_i2c_adapter(radio);
> +       if (retval < 0) {
> +               dev_err(&intf->dev, "could not register i2c device\n");
> +               goto err_i2cdev;
> +       }
> +
> +       adapter = &radio->i2c_adapter;
> +       sd = v4l2_i2c_new_subdev_board(&radio->v4l2_dev, adapter,
> +                                         &si4713_board_info, NULL);
> +       radio->v4l2_subdev = sd;
> +       if (!sd) {
> +               dev_err(&intf->dev, "cannot get v4l2 subdevice\n");
> +               retval = -ENODEV;
> +               goto del_adapter;
> +       }
> +
> +       radio->vdev.ctrl_handler = sd->ctrl_handler;
> +       radio->v4l2_dev.release = usb_si4713_video_device_release;
> +       strlcpy(radio->vdev.name, radio->v4l2_dev.name,
> +               sizeof(radio->vdev.name));
> +       radio->vdev.v4l2_dev = &radio->v4l2_dev;
> +       radio->vdev.fops = &usb_si4713_fops;
> +       radio->vdev.ioctl_ops = &usb_si4713_ioctl_ops;
> +       radio->vdev.lock = &radio->lock;
> +       radio->vdev.release = video_device_release_empty;
> +       radio->vdev.vfl_dir = VFL_DIR_TX;
> +
> +       video_set_drvdata(&radio->vdev, radio);
> +       set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags);
> +
> +       retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
> +       if (retval < 0) {
> +               dev_err(&intf->dev, "could not register video device\n");
> +               goto del_adapter;
> +       }
> +
> +       dev_info(&intf->dev, "V4L2 device registered as %s\n",
> +                       video_device_node_name(&radio->vdev));
> +
> +       return 0;
> +
> +del_adapter:
> +       i2c_del_adapter(adapter);
> +err_i2cdev:
> +       v4l2_device_unregister(&radio->v4l2_dev);
> +err_v4l2:
> +       kfree(radio->buffer);
> +       kfree(radio);
> +       return retval;
> +}
> +
> +static void usb_si4713_disconnect(struct usb_interface *intf)
> +{
> +       struct si4713_usb_device *radio = to_si4713_dev(usb_get_intfdata(intf));
> +
> +       dev_info(&intf->dev, "Si4713 development board now disconnected\n");
> +
> +       mutex_lock(&radio->lock);
> +       usb_set_intfdata(intf, NULL);
> +       video_unregister_device(&radio->vdev);
> +       v4l2_device_disconnect(&radio->v4l2_dev);
> +       mutex_unlock(&radio->lock);
> +       v4l2_device_put(&radio->v4l2_dev);
> +}
> +
> +/* USB subsystem interface */
> +static struct usb_driver usb_si4713_driver = {
> +       .name                   = "radio-usb-si4713",
> +       .probe                  = usb_si4713_probe,
> +       .disconnect             = usb_si4713_disconnect,
> +       .id_table               = usb_si4713_usb_device_table,
> +};
> +
> +module_usb_driver(usb_si4713_driver);
> --
> 1.7.9.5
>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713
  2013-11-05 14:18     ` edubezval
@ 2013-11-07  7:40       ` Hans Verkuil
  2013-11-11 12:34         ` edubezval
  2013-11-18 14:47       ` edubezval
  1 sibling, 1 reply; 31+ messages in thread
From: Hans Verkuil @ 2013-11-07  7:40 UTC (permalink / raw)
  To: edubezval; +Cc: Dinesh Ram, Linux-Media, d ram

On 11/05/2013 03:18 PM, edubezval@gmail.com wrote:
> Dinesh
> 
> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>> This is the USB driver for the Silicon Labs development board.
>> It contains the Si4713 FM transmitter chip.
>>
> 
> I tried this driver again. The system attempts to probe the device but
> it fails because the product revision read out of the USB device is
> wrong.
> [  220.855158] usb 2-1.3.3: new full-speed USB device number 10 using ehci-pci
> [  220.949677] usb 2-1.3.3: New USB device found, idVendor=10c4, idProduct=8244
> [  220.949683] usb 2-1.3.3: New USB device strings: Mfr=1, Product=2,
> SerialNumber=3
> [  220.949688] usb 2-1.3.3: Product: Si47xx Baseboard
> [  220.949691] usb 2-1.3.3: Manufacturer: SILICON LABORATORIES INC.
> [  220.949695] usb 2-1.3.3: SerialNumber: CBDA8-00-0
> [  220.950157] usbhid 2-1.3.3:1.0: couldn't find an input interrupt endpoint
> [ 1014.981012] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
> discovered: (10C4:8244)
> [ 1015.870984] si4713 12-0063: IRQ not configured. Using timeouts.
> [ 1015.943551] si4713 12-0063: Invalid product number   <<< Here is
> the code without modification
> [ 1015.943556] si4713 12-0063: Failed to probe device information.
> [ 1015.943568] si4713: probe of 12-0063 failed with error -22
> [ 1015.943613] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
> [ 1015.943672] usbcore: registered new interface driver radio-usb-si4713
> [ 1274.419987] perf samples too long (2504 > 2500), lowering
> kernel.perf_event_max_sample_rate to 50000
> [ 1308.851059] usbcore: deregistering interface driver radio-usb-si4713
> [ 1500.478308] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
> discovered: (10C4:8244)
> [ 1500.612240] si4713 12-0063: IRQ not configured. Using timeouts.
> [ 1500.683489] si4713 12-0063: Invalid product number 0x15 <<< Here it
> prints the PN read
> [ 1500.683495] si4713 12-0063: Failed to probe device information.
> [ 1500.683509] si4713: probe of 12-0063 failed with error -22
> [ 1500.683558] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
> [ 1500.683624] usbcore: registered new interface driver radio-usb-si4713
> 
> Here is simple diff of what I used to print the PN value:
> diff --git a/drivers/media/radio/si4713/si4713.c
> b/drivers/media/radio/si4713/si4713.c
> index aadecb5..ee53584 100644
> --- a/drivers/media/radio/si4713/si4713.c
> +++ b/drivers/media/radio/si4713/si4713.c
> @@ -464,7 +464,7 @@ static int si4713_checkrev(struct si4713_device *sdev)
>                 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
>                                 client->addr << 1, client->adapter->name);
>         } else {
> -               v4l2_err(&sdev->sd, "Invalid product number\n");
> +               v4l2_err(&sdev->sd, "Invalid product number 0x%X\n", resp[1]);
>                 rval = -EINVAL;
>         }
>         return rval;
> 
> It is expected to be 0x0D  instead of 0x15, if I am not mistaken.

What are the markings on the si471x chip on your USB board? Perhaps you have
a slightly different version of the chip?

A value of 0x15 suggests a si4721 transceiver instead of a si4713 transmitter.
Which might actually still work with this driver (although with the TX
functionality only, of course), so you might try accepting the 0x15 value.

Regards,

	Hans

> 
>> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
>> ---
>>  drivers/media/radio/si4713/Kconfig            |   15 +
>>  drivers/media/radio/si4713/Makefile           |    1 +
>>  drivers/media/radio/si4713/radio-usb-si4713.c |  540 +++++++++++++++++++++++++
>>  3 files changed, 556 insertions(+)
>>  create mode 100644 drivers/media/radio/si4713/radio-usb-si4713.c


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713
  2013-11-07  7:40       ` Hans Verkuil
@ 2013-11-11 12:34         ` edubezval
  0 siblings, 0 replies; 31+ messages in thread
From: edubezval @ 2013-11-11 12:34 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Dinesh Ram, Linux-Media, d ram

On Thu, Nov 7, 2013 at 3:40 AM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> On 11/05/2013 03:18 PM, edubezval@gmail.com wrote:
>> Dinesh
>>
>> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>>> This is the USB driver for the Silicon Labs development board.
>>> It contains the Si4713 FM transmitter chip.
>>>
>>
>> I tried this driver again. The system attempts to probe the device but
>> it fails because the product revision read out of the USB device is
>> wrong.
>> [  220.855158] usb 2-1.3.3: new full-speed USB device number 10 using ehci-pci
>> [  220.949677] usb 2-1.3.3: New USB device found, idVendor=10c4, idProduct=8244
>> [  220.949683] usb 2-1.3.3: New USB device strings: Mfr=1, Product=2,
>> SerialNumber=3
>> [  220.949688] usb 2-1.3.3: Product: Si47xx Baseboard
>> [  220.949691] usb 2-1.3.3: Manufacturer: SILICON LABORATORIES INC.
>> [  220.949695] usb 2-1.3.3: SerialNumber: CBDA8-00-0
>> [  220.950157] usbhid 2-1.3.3:1.0: couldn't find an input interrupt endpoint
>> [ 1014.981012] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
>> discovered: (10C4:8244)
>> [ 1015.870984] si4713 12-0063: IRQ not configured. Using timeouts.
>> [ 1015.943551] si4713 12-0063: Invalid product number   <<< Here is
>> the code without modification
>> [ 1015.943556] si4713 12-0063: Failed to probe device information.
>> [ 1015.943568] si4713: probe of 12-0063 failed with error -22
>> [ 1015.943613] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
>> [ 1015.943672] usbcore: registered new interface driver radio-usb-si4713
>> [ 1274.419987] perf samples too long (2504 > 2500), lowering
>> kernel.perf_event_max_sample_rate to 50000
>> [ 1308.851059] usbcore: deregistering interface driver radio-usb-si4713
>> [ 1500.478308] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
>> discovered: (10C4:8244)
>> [ 1500.612240] si4713 12-0063: IRQ not configured. Using timeouts.
>> [ 1500.683489] si4713 12-0063: Invalid product number 0x15 <<< Here it
>> prints the PN read
>> [ 1500.683495] si4713 12-0063: Failed to probe device information.
>> [ 1500.683509] si4713: probe of 12-0063 failed with error -22
>> [ 1500.683558] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
>> [ 1500.683624] usbcore: registered new interface driver radio-usb-si4713
>>
>> Here is simple diff of what I used to print the PN value:
>> diff --git a/drivers/media/radio/si4713/si4713.c
>> b/drivers/media/radio/si4713/si4713.c
>> index aadecb5..ee53584 100644
>> --- a/drivers/media/radio/si4713/si4713.c
>> +++ b/drivers/media/radio/si4713/si4713.c
>> @@ -464,7 +464,7 @@ static int si4713_checkrev(struct si4713_device *sdev)
>>                 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
>>                                 client->addr << 1, client->adapter->name);
>>         } else {
>> -               v4l2_err(&sdev->sd, "Invalid product number\n");
>> +               v4l2_err(&sdev->sd, "Invalid product number 0x%X\n", resp[1]);
>>                 rval = -EINVAL;
>>         }
>>         return rval;
>>
>> It is expected to be 0x0D  instead of 0x15, if I am not mistaken.
>
> What are the markings on the si471x chip on your USB board? Perhaps you have
> a slightly different version of the chip?
>
> A value of 0x15 suggests a si4721 transceiver instead of a si4713 transmitter.
> Which might actually still work with this driver (although with the TX
> functionality only, of course), so you might try accepting the 0x15 value.
>

In fact I have a si4721 board :-(. Sorry for the noise. I am gonna
give it a shot any way by hacking the kernel and allowing it to be
recognized.

> Regards,
>
>         Hans
>
>>
>>> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
>>> ---
>>>  drivers/media/radio/si4713/Kconfig            |   15 +
>>>  drivers/media/radio/si4713/Makefile           |    1 +
>>>  drivers/media/radio/si4713/radio-usb-si4713.c |  540 +++++++++++++++++++++++++
>>>  3 files changed, 556 insertions(+)
>>>  create mode 100644 drivers/media/radio/si4713/radio-usb-si4713.c
>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [Review Patch 0/9] si4713 usb device driver
  2013-10-15 15:24 [Review Patch 0/9] si4713 usb device driver Dinesh Ram
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
  2013-10-15 17:37 ` [Review Patch 0/9] si4713 usb device driver edubezval
@ 2013-11-18 14:31 ` edubezval
  2 siblings, 0 replies; 31+ messages in thread
From: edubezval @ 2013-11-18 14:31 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: Linux-Media, Hans Verkuil, d ram

Hans, Dinesh,

On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
> Hello Eduardo,
>
> In this patch series, I have addressed the comments by you
> concerning my last patch series.
> In the resulting patches, I have corrected most of the
> style issues and adding of comments. However, some warnings
> given out by checkpatch.pl (mostly complaing about lines longer
> than 80 characters) are still there because I saw that code readibility
> suffers by breaking up those lines.
>
> Also Hans has contributed patches 8 and 9 in this patch series
> which address the issues of the handling of unknown regulators,
> which have apparently changed since 3.10. Hans has tested it and the
> driver loads again.
>
> Let me know when you are able to test it again.


After fixing the compilation issue, you can add my:


Tested-by: Eduardo Valentin <edubezval@gmail.com>
Acked-by: Eduardo Valentin <edubezval@gmail.com>

Tests were done using n900. The si4721 case needs to be taken in a
separated work I believe. So although I believe it is a minor diff, I
won't add my tested by for now on that case.

>
> Kind regards,
> Dinesh Ram
> dinesh.ram@cern.ch
> dinesh.ram086@gmail.com
>



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713
  2013-11-05 14:18     ` edubezval
  2013-11-07  7:40       ` Hans Verkuil
@ 2013-11-18 14:47       ` edubezval
  1 sibling, 0 replies; 31+ messages in thread
From: edubezval @ 2013-11-18 14:47 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: Linux-Media, Hans Verkuil, d ram

Hello,

On Tue, Nov 5, 2013 at 10:18 AM, edubezval@gmail.com
<edubezval@gmail.com> wrote:
> Dinesh
>
> On Tue, Oct 15, 2013 at 11:24 AM, Dinesh Ram <dinesh.ram@cern.ch> wrote:
>> This is the USB driver for the Silicon Labs development board.
>> It contains the Si4713 FM transmitter chip.
>>
>
> I tried this driver again. The system attempts to probe the device but
> it fails because the product revision read out of the USB device is
> wrong.
> [  220.855158] usb 2-1.3.3: new full-speed USB device number 10 using ehci-pci
> [  220.949677] usb 2-1.3.3: New USB device found, idVendor=10c4, idProduct=8244
> [  220.949683] usb 2-1.3.3: New USB device strings: Mfr=1, Product=2,
> SerialNumber=3
> [  220.949688] usb 2-1.3.3: Product: Si47xx Baseboard
> [  220.949691] usb 2-1.3.3: Manufacturer: SILICON LABORATORIES INC.
> [  220.949695] usb 2-1.3.3: SerialNumber: CBDA8-00-0
> [  220.950157] usbhid 2-1.3.3:1.0: couldn't find an input interrupt endpoint
> [ 1014.981012] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
> discovered: (10C4:8244)
> [ 1015.870984] si4713 12-0063: IRQ not configured. Using timeouts.
> [ 1015.943551] si4713 12-0063: Invalid product number   <<< Here is
> the code without modification
> [ 1015.943556] si4713 12-0063: Failed to probe device information.
> [ 1015.943568] si4713: probe of 12-0063 failed with error -22
> [ 1015.943613] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
> [ 1015.943672] usbcore: registered new interface driver radio-usb-si4713
> [ 1274.419987] perf samples too long (2504 > 2500), lowering
> kernel.perf_event_max_sample_rate to 50000
> [ 1308.851059] usbcore: deregistering interface driver radio-usb-si4713
> [ 1500.478308] radio-usb-si4713 2-1.3.3:1.0: Si4713 development board
> discovered: (10C4:8244)
> [ 1500.612240] si4713 12-0063: IRQ not configured. Using timeouts.
> [ 1500.683489] si4713 12-0063: Invalid product number 0x15 <<< Here it
> prints the PN read
> [ 1500.683495] si4713 12-0063: Failed to probe device information.
> [ 1500.683509] si4713: probe of 12-0063 failed with error -22
> [ 1500.683558] radio-usb-si4713 2-1.3.3:1.0: cannot get v4l2 subdevice
> [ 1500.683624] usbcore: registered new interface driver radio-usb-si4713
>
> Here is simple diff of what I used to print the PN value:
> diff --git a/drivers/media/radio/si4713/si4713.c
> b/drivers/media/radio/si4713/si4713.c
> index aadecb5..ee53584 100644
> --- a/drivers/media/radio/si4713/si4713.c
> +++ b/drivers/media/radio/si4713/si4713.c
> @@ -464,7 +464,7 @@ static int si4713_checkrev(struct si4713_device *sdev)
>                 v4l2_info(&sdev->sd, "chip found @ 0x%02x (%s)\n",
>                                 client->addr << 1, client->adapter->name);
>         } else {
> -               v4l2_err(&sdev->sd, "Invalid product number\n");
> +               v4l2_err(&sdev->sd, "Invalid product number 0x%X\n", resp[1]);
>                 rval = -EINVAL;
>         }
>         return rval;
>

Feel free to use the code above as you wish, no warranties are
provided though :-).

For the little diff above, you may include in the driver code base with my
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>

> It is expected to be 0x0D  instead of 0x15, if I am not mistaken.
>
>> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
>> ---
>>  drivers/media/radio/si4713/Kconfig            |   15 +
>>  drivers/media/radio/si4713/Makefile           |    1 +
>>  drivers/media/radio/si4713/radio-usb-si4713.c |  540 +++++++++++++++++++++++++
>>  3 files changed, 556 insertions(+)
>>  create mode 100644 drivers/media/radio/si4713/radio-usb-si4713.c
>>
>> diff --git a/drivers/media/radio/si4713/Kconfig b/drivers/media/radio/si4713/Kconfig
>> index ec640b8..a7c3ba8 100644
>> --- a/drivers/media/radio/si4713/Kconfig
>> +++ b/drivers/media/radio/si4713/Kconfig
>> @@ -1,3 +1,18 @@
>> +config USB_SI4713
>> +       tristate "Silicon Labs Si4713 FM Radio Transmitter support with USB"
>> +       depends on USB && RADIO_SI4713
>> +       select SI4713
>> +       ---help---
>> +         This is a driver for USB devices with the Silicon Labs SI4713
>> +         chip. Currently these devices are known to work.
>> +         - 10c4:8244: Silicon Labs FM Transmitter USB device.
>> +
>> +         Say Y here if you want to connect this type of radio to your
>> +         computer's USB port.
>> +
>> +         To compile this driver as a module, choose M here: the
>> +         module will be called radio-usb-si4713.
>> +
>>  config PLATFORM_SI4713
>>         tristate "Silicon Labs Si4713 FM Radio Transmitter support with I2C"
>>         depends on I2C && RADIO_SI4713
>> diff --git a/drivers/media/radio/si4713/Makefile b/drivers/media/radio/si4713/Makefile
>> index 9d0bd0e..6524674 100644
>> --- a/drivers/media/radio/si4713/Makefile
>> +++ b/drivers/media/radio/si4713/Makefile
>> @@ -3,5 +3,6 @@
>>  #
>>
>>  obj-$(CONFIG_I2C_SI4713) += si4713.o
>> +obj-$(CONFIG_USB_SI4713) += radio-usb-si4713.o
>>  obj-$(CONFIG_PLATFORM_SI4713) += radio-platform-si4713.o
>>
>> diff --git a/drivers/media/radio/si4713/radio-usb-si4713.c b/drivers/media/radio/si4713/radio-usb-si4713.c
>> new file mode 100644
>> index 0000000..a75e2c8
>> --- /dev/null
>> +++ b/drivers/media/radio/si4713/radio-usb-si4713.c
>> @@ -0,0 +1,540 @@
>> +/*
>> + * Copyright 2013 Cisco Systems, Inc. and/or its affiliates.
>> + * All rights reserved.
>> + *
>> + * This program is free software; you may redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; version 2 of the License.
>> + *
>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
>> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
>> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
>> + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
>> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
>> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
>> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
>> + * SOFTWARE.
>> + */
>> +
>> +/* kernel includes */
>> +#include <linux/kernel.h>
>> +#include <linux/module.h>
>> +#include <linux/usb.h>
>> +#include <linux/init.h>
>> +#include <linux/slab.h>
>> +#include <linux/input.h>
>> +#include <linux/mutex.h>
>> +#include <linux/i2c.h>
>> +/* V4l includes */
>> +#include <linux/videodev2.h>
>> +#include <media/v4l2-common.h>
>> +#include <media/v4l2-device.h>
>> +#include <media/v4l2-ioctl.h>
>> +#include <media/v4l2-event.h>
>> +#include <media/si4713.h>
>> +
>> +#include "si4713.h"
>> +
>> +/* driver and module definitions */
>> +MODULE_AUTHOR("Dinesh Ram <dinesh.ram@cern.ch>");
>> +MODULE_DESCRIPTION("Si4713 FM Transmitter USB driver");
>> +MODULE_LICENSE("GPL v2");
>> +
>> +/* The Device announces itself as Cygnal Integrated Products, Inc. */
>> +#define USB_SI4713_VENDOR              0x10c4
>> +#define USB_SI4713_PRODUCT             0x8244
>> +
>> +#define BUFFER_LENGTH                  64
>> +#define USB_TIMEOUT                    1000
>> +#define USB_RESP_TIMEOUT               50000
>> +
>> +/* USB Device ID List */
>> +static struct usb_device_id usb_si4713_usb_device_table[] = {
>> +       {USB_DEVICE_AND_INTERFACE_INFO(USB_SI4713_VENDOR, USB_SI4713_PRODUCT,
>> +                                                       USB_CLASS_HID, 0, 0) },
>> +       { }                                             /* Terminating entry */
>> +};
>> +
>> +MODULE_DEVICE_TABLE(usb, usb_si4713_usb_device_table);
>> +
>> +struct si4713_usb_device {
>> +       struct usb_device       *usbdev;
>> +       struct usb_interface    *intf;
>> +       struct video_device     vdev;
>> +       struct v4l2_device      v4l2_dev;
>> +       struct v4l2_subdev      *v4l2_subdev;
>> +       struct mutex            lock;
>> +       struct i2c_adapter      i2c_adapter;
>> +
>> +       u8                      *buffer;
>> +};
>> +
>> +static inline struct si4713_usb_device *to_si4713_dev(struct v4l2_device *v4l2_dev)
>> +{
>> +       return container_of(v4l2_dev, struct si4713_usb_device, v4l2_dev);
>> +}
>> +
>> +static int vidioc_querycap(struct file *file, void *priv,
>> +                                       struct v4l2_capability *v)
>> +{
>> +       struct si4713_usb_device *radio = video_drvdata(file);
>> +
>> +       strlcpy(v->driver, "radio-usb-si4713", sizeof(v->driver));
>> +       strlcpy(v->card, "Si4713 FM Transmitter", sizeof(v->card));
>> +       usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
>> +       v->device_caps = V4L2_CAP_MODULATOR | V4L2_CAP_RDS_OUTPUT;
>> +       v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
>> +
>> +       return 0;
>> +}
>> +
>> +static int vidioc_g_modulator(struct file *file, void *priv,
>> +                               struct v4l2_modulator *vm)
>> +{
>> +       struct si4713_usb_device *radio = video_drvdata(file);
>> +
>> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, g_modulator, vm);
>> +}
>> +
>> +static int vidioc_s_modulator(struct file *file, void *priv,
>> +                               const struct v4l2_modulator *vm)
>> +{
>> +       struct si4713_usb_device *radio = video_drvdata(file);
>> +
>> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, s_modulator, vm);
>> +}
>> +
>> +static int vidioc_s_frequency(struct file *file, void *priv,
>> +                               const struct v4l2_frequency *vf)
>> +{
>> +       struct si4713_usb_device *radio = video_drvdata(file);
>> +
>> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, s_frequency, vf);
>> +}
>> +
>> +static int vidioc_g_frequency(struct file *file, void *priv,
>> +                               struct v4l2_frequency *vf)
>> +{
>> +       struct si4713_usb_device *radio = video_drvdata(file);
>> +
>> +       return v4l2_subdev_call(radio->v4l2_subdev, tuner, g_frequency, vf);
>> +}
>> +
>> +static const struct v4l2_ioctl_ops usb_si4713_ioctl_ops = {
>> +       .vidioc_querycap          = vidioc_querycap,
>> +       .vidioc_g_modulator       = vidioc_g_modulator,
>> +       .vidioc_s_modulator       = vidioc_s_modulator,
>> +       .vidioc_g_frequency       = vidioc_g_frequency,
>> +       .vidioc_s_frequency       = vidioc_s_frequency,
>> +       .vidioc_log_status        = v4l2_ctrl_log_status,
>> +       .vidioc_subscribe_event   = v4l2_ctrl_subscribe_event,
>> +       .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
>> +};
>> +
>> +/* File system interface */
>> +static const struct v4l2_file_operations usb_si4713_fops = {
>> +       .owner          = THIS_MODULE,
>> +       .open           = v4l2_fh_open,
>> +       .release        = v4l2_fh_release,
>> +       .poll           = v4l2_ctrl_poll,
>> +       .unlocked_ioctl = video_ioctl2,
>> +};
>> +
>> +static void usb_si4713_video_device_release(struct v4l2_device *v4l2_dev)
>> +{
>> +       struct si4713_usb_device *radio = to_si4713_dev(v4l2_dev);
>> +       struct i2c_adapter *adapter = &radio->i2c_adapter;
>> +
>> +       i2c_del_adapter(adapter);
>> +       v4l2_device_unregister(&radio->v4l2_dev);
>> +       kfree(radio->buffer);
>> +       kfree(radio);
>> +}
>> +
>> +/*
>> + * This command sequence emulates the behaviour of the Windows driver.
>> + * The structure of these commands was determined by sniffing the
>> + * usb traffic of the device during startup.
>> + * Most likely, these commands make some queries to the device.
>> + * Commands are sent to enquire parameters like the bus mode,
>> + * component revision, boot mode, the device serial number etc.
>> + *
>> + * These commands are necessary to be sent in this order during startup.
>> + * The device fails to powerup if these commands are not sent.
>> + *
>> + * The complete list of startup commands is given in the start_seq table below.
>> + */
>> +static int si4713_send_startup_command(struct si4713_usb_device *radio)
>> +{
>> +       unsigned long until_jiffies = jiffies + usecs_to_jiffies(USB_RESP_TIMEOUT) + 1;
>> +       u8 *buffer = radio->buffer;
>> +       int retval;
>> +
>> +       /* send the command */
>> +       retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
>> +                                       0x09, 0x21, 0x033f, 0, radio->buffer,
>> +                                       BUFFER_LENGTH, USB_TIMEOUT);
>> +       if (retval < 0)
>> +               return retval;
>> +
>> +       for (;;) {
>> +               /* receive the response */
>> +               retval = usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
>> +                               0x01, 0xa1, 0x033f, 0, radio->buffer,
>> +                               BUFFER_LENGTH, USB_TIMEOUT);
>> +               if (retval < 0)
>> +                       return retval;
>> +               if (!radio->buffer[1]) {
>> +                       /* USB traffic sniffing showed that some commands require
>> +                        * additional checks. */
>> +                       switch (buffer[1]) {
>> +                       case 0x32:
>> +                               if (radio->buffer[2] == 0)
>> +                                       return 0;
>> +                               break;
>> +                       case 0x14:
>> +                       case 0x12:
>> +                               if (radio->buffer[2] & SI4713_CTS)
>> +                                       return 0;
>> +                               break;
>> +                       case 0x06:
>> +                               if ((radio->buffer[2] & SI4713_CTS) && radio->buffer[9] == 0x08)
>> +                                       return 0;
>> +                               break;
>> +                       default:
>> +                               return 0;
>> +                       }
>> +               }
>> +               if (jiffies > until_jiffies)
>> +                       return -EIO;
>> +               msleep(3);
>> +       }
>> +
>> +       return retval;
>> +}
>> +
>> +struct si4713_start_seq_table {
>> +       int len;
>> +       u8 payload[8];
>> +};
>> +
>> +/*
>> + * Some of the startup commands that could be recognized are :
>> + * (0x03): Get serial number of the board (Response : CB000-00-00)
>> + * (0x06, 0x03, 0x03, 0x08, 0x01, 0x0f) : Get Component revision
>> + */
>> +struct si4713_start_seq_table start_seq[] = {
>> +
>> +       { 1, { 0x03 } },
>> +       { 2, { 0x32, 0x7f } },
>> +       { 6, { 0x06, 0x03, 0x03, 0x08, 0x01, 0x0f } },
>> +       { 2, { 0x14, 0x02 } },
>> +       { 2, { 0x09, 0x90 } },
>> +       { 3, { 0x08, 0x90, 0xfa } },
>> +       { 2, { 0x36, 0x01 } },
>> +       { 2, { 0x05, 0x03 } },
>> +       { 7, { 0x06, 0x00, 0x06, 0x0e, 0x01, 0x0f, 0x05 } },
>> +       { 1, { 0x12 } },
>> +       /* Commands that are sent after pressing the 'Initialize'
>> +               button in the windows application */
>> +       { 1, { 0x03 } },
>> +       { 1, { 0x01 } },
>> +       { 2, { 0x09, 0x90 } },
>> +       { 3, { 0x08, 0x90, 0xfa } },
>> +       { 1, { 0x34 } },
>> +       { 2, { 0x35, 0x01 } },
>> +       { 2, { 0x36, 0x01 } },
>> +       { 2, { 0x30, 0x09 } },
>> +       { 4, { 0x30, 0x06, 0x00, 0xe2 } },
>> +       { 3, { 0x31, 0x01, 0x30 } },
>> +       { 3, { 0x31, 0x04, 0x09 } },
>> +       { 2, { 0x05, 0x02 } },
>> +       { 6, { 0x06, 0x03, 0x03, 0x08, 0x01, 0x0f } },
>> +};
>> +
>> +static int si4713_start_seq(struct si4713_usb_device *radio)
>> +{
>> +       int retval = 0;
>> +       int i;
>> +
>> +       radio->buffer[0] = 0x3f;
>> +
>> +       for (i = 0; i < ARRAY_SIZE(start_seq); i++) {
>> +               int len = start_seq[i].len;
>> +               u8 *payload = start_seq[i].payload;
>> +
>> +               memcpy(radio->buffer + 1, payload, len);
>> +               memset(radio->buffer + len + 1, 0, BUFFER_LENGTH - 1 - len);
>> +               retval = si4713_send_startup_command(radio);
>> +       }
>> +
>> +       return retval;
>> +}
>> +
>> +static struct i2c_board_info si4713_board_info = {
>> +       I2C_BOARD_INFO("si4713", SI4713_I2C_ADDR_BUSEN_HIGH),
>> +};
>> +
>> +struct si4713_command_table {
>> +       int command_id;
>> +       u8 payload[8];
>> +};
>> +
>> +/*
>> + * Structure of a command :
>> + *     Byte 1 : 0x3f (always)
>> + *     Byte 2 : 0x06 (send a command)
>> + *     Byte 3 : Unknown
>> + *     Byte 4 : Number of arguments + 1 (for the command byte)
>> + *     Byte 5 : Number of response bytes
>> + */
>> +struct si4713_command_table command_table[] = {
>> +
>> +       { SI4713_CMD_POWER_UP,          { 0x00, SI4713_PWUP_NARGS + 1, SI4713_PWUP_NRESP} },
>> +       { SI4713_CMD_GET_REV,           { 0x03, 0x01, SI4713_GETREV_NRESP } },
>> +       { SI4713_CMD_POWER_DOWN,        { 0x00, 0x01, SI4713_PWDN_NRESP} },
>> +       { SI4713_CMD_SET_PROPERTY,      { 0x00, SI4713_SET_PROP_NARGS + 1, SI4713_SET_PROP_NRESP } },
>> +       { SI4713_CMD_GET_PROPERTY,      { 0x00, SI4713_GET_PROP_NARGS + 1, SI4713_GET_PROP_NRESP } },
>> +       { SI4713_CMD_TX_TUNE_FREQ,      { 0x03, SI4713_TXFREQ_NARGS + 1, SI4713_TXFREQ_NRESP } },
>> +       { SI4713_CMD_TX_TUNE_POWER,     { 0x03, SI4713_TXPWR_NARGS + 1, SI4713_TXPWR_NRESP } },
>> +       { SI4713_CMD_TX_TUNE_MEASURE,   { 0x03, SI4713_TXMEA_NARGS + 1, SI4713_TXMEA_NRESP } },
>> +       { SI4713_CMD_TX_TUNE_STATUS,    { 0x00, SI4713_TXSTATUS_NARGS + 1, SI4713_TXSTATUS_NRESP } },
>> +       { SI4713_CMD_TX_ASQ_STATUS,     { 0x03, SI4713_ASQSTATUS_NARGS + 1, SI4713_ASQSTATUS_NRESP } },
>> +       { SI4713_CMD_GET_INT_STATUS,    { 0x03, 0x01, SI4713_GET_STATUS_NRESP } },
>> +       { SI4713_CMD_TX_RDS_BUFF,       { 0x03, SI4713_RDSBUFF_NARGS + 1, SI4713_RDSBUFF_NRESP } },
>> +       { SI4713_CMD_TX_RDS_PS,         { 0x00, SI4713_RDSPS_NARGS + 1, SI4713_RDSPS_NRESP } },
>> +};
>> +
>> +static int send_command(struct si4713_usb_device *radio, u8 *payload, char *data, int len)
>> +{
>> +       int retval;
>> +
>> +       radio->buffer[0] = 0x3f;
>> +       radio->buffer[1] = 0x06;
>> +
>> +       memcpy(radio->buffer + 2, payload, 3);
>> +       memcpy(radio->buffer + 5, data, len);
>> +       memset(radio->buffer + 5 + len, 0, BUFFER_LENGTH - 5 - len);
>> +
>> +       /* send the command */
>> +       retval = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
>> +                                       0x09, 0x21, 0x033f, 0, radio->buffer,
>> +                                       BUFFER_LENGTH, USB_TIMEOUT);
>> +
>> +       return retval < 0 ? retval : 0;
>> +}
>> +
>> +static int si4713_i2c_read(struct si4713_usb_device *radio, char *data, int len)
>> +{
>> +       unsigned long until_jiffies = jiffies + usecs_to_jiffies(USB_RESP_TIMEOUT) + 1;
>> +       int retval;
>> +
>> +       /* receive the response */
>> +       for (;;) {
>> +               retval = usb_control_msg(radio->usbdev,
>> +                                       usb_rcvctrlpipe(radio->usbdev, 0),
>> +                                       0x01, 0xa1, 0x033f, 0, radio->buffer,
>> +                                       BUFFER_LENGTH, USB_TIMEOUT);
>> +               if (retval < 0)
>> +                       return retval;
>> +
>> +               /*
>> +                * Check that we get a valid reply back (buffer[1] == 0) and
>> +                * that CTS is set before returning, otherwise we wait and try
>> +                * again. The i2c driver also does the CTS check, but the timeouts
>> +                * used there are much too small for this USB driver, so we wait
>> +                * for it here.
>> +                */
>> +               if (radio->buffer[1] == 0 && (radio->buffer[2] & SI4713_CTS)) {
>> +                       memcpy(data, radio->buffer + 2, len);
>> +                       return 0;
>> +               }
>> +               if (jiffies > until_jiffies) {
>> +                       /* Zero the status value, ensuring CTS isn't set */
>> +                       data[0] = 0;
>> +                       return 0;
>> +               }
>> +               msleep(3);
>> +       }
>> +}
>> +
>> +static int si4713_i2c_write(struct si4713_usb_device *radio, char *data, int len)
>> +{
>> +       int retval = -EINVAL;
>> +       int i;
>> +
>> +       if (len > BUFFER_LENGTH - 5)
>> +               return -EINVAL;
>> +
>> +       for (i = 0; i < ARRAY_SIZE(command_table); i++) {
>> +               if (data[0] == command_table[i].command_id)
>> +                       retval = send_command(radio, command_table[i].payload,
>> +                                               data, len);
>> +       }
>> +
>> +       return retval < 0 ? retval : 0;
>> +}
>> +
>> +static int si4713_transfer(struct i2c_adapter *i2c_adapter,
>> +                               struct i2c_msg *msgs, int num)
>> +{
>> +       struct si4713_usb_device *radio = i2c_get_adapdata(i2c_adapter);
>> +       int retval = -EINVAL;
>> +       int i;
>> +
>> +       if (num <= 0)
>> +               return 0;
>> +
>> +       for (i = 0; i < num; i++) {
>> +               if (msgs[i].flags & I2C_M_RD)
>> +                       retval = si4713_i2c_read(radio, msgs[i].buf, msgs[i].len);
>> +               else
>> +                       retval = si4713_i2c_write(radio, msgs[i].buf, msgs[i].len);
>> +               if (retval)
>> +                       break;
>> +       }
>> +
>> +       return retval ? retval : num;
>> +}
>> +
>> +static u32 si4713_functionality(struct i2c_adapter *adapter)
>> +{
>> +       return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
>> +}
>> +
>> +static struct i2c_algorithm si4713_algo = {
>> +       .master_xfer   = si4713_transfer,
>> +       .functionality = si4713_functionality,
>> +};
>> +
>> +/* This name value shows up in the sysfs filename associated
>> +               with this I2C adapter */
>> +static struct i2c_adapter si4713_i2c_adapter_template = {
>> +       .name   = "si4713-i2c",
>> +       .owner  = THIS_MODULE,
>> +       .algo   = &si4713_algo,
>> +};
>> +
>> +int si4713_register_i2c_adapter(struct si4713_usb_device *radio)
>> +{
>> +       radio->i2c_adapter = si4713_i2c_adapter_template;
>> +       /* set up sysfs linkage to our parent device */
>> +       radio->i2c_adapter.dev.parent = &radio->usbdev->dev;
>> +       i2c_set_adapdata(&radio->i2c_adapter, radio);
>> +
>> +       return i2c_add_adapter(&radio->i2c_adapter);
>> +}
>> +
>> +/* check if the device is present and register with v4l and usb if it is */
>> +static int usb_si4713_probe(struct usb_interface *intf,
>> +                               const struct usb_device_id *id)
>> +{
>> +       struct si4713_usb_device *radio;
>> +       struct i2c_adapter *adapter;
>> +       struct v4l2_subdev *sd;
>> +       int retval = -ENOMEM;
>> +
>> +       dev_info(&intf->dev, "Si4713 development board discovered: (%04X:%04X)\n",
>> +                       id->idVendor, id->idProduct);
>> +
>> +       /* Initialize local device structure */
>> +       radio = kzalloc(sizeof(struct si4713_usb_device), GFP_KERNEL);
>> +       if (radio)
>> +               radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
>> +
>> +       if (!radio || !radio->buffer) {
>> +               dev_err(&intf->dev, "kmalloc for si4713_usb_device failed\n");
>> +               kfree(radio);
>> +               return -ENOMEM;
>> +       }
>> +
>> +       mutex_init(&radio->lock);
>> +
>> +       radio->usbdev = interface_to_usbdev(intf);
>> +       radio->intf = intf;
>> +       usb_set_intfdata(intf, &radio->v4l2_dev);
>> +
>> +       retval = si4713_start_seq(radio);
>> +       if (retval < 0)
>> +               goto err_v4l2;
>> +
>> +       retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
>> +       if (retval < 0) {
>> +               dev_err(&intf->dev, "couldn't register v4l2_device\n");
>> +               goto err_v4l2;
>> +       }
>> +
>> +       retval = si4713_register_i2c_adapter(radio);
>> +       if (retval < 0) {
>> +               dev_err(&intf->dev, "could not register i2c device\n");
>> +               goto err_i2cdev;
>> +       }
>> +
>> +       adapter = &radio->i2c_adapter;
>> +       sd = v4l2_i2c_new_subdev_board(&radio->v4l2_dev, adapter,
>> +                                         &si4713_board_info, NULL);
>> +       radio->v4l2_subdev = sd;
>> +       if (!sd) {
>> +               dev_err(&intf->dev, "cannot get v4l2 subdevice\n");
>> +               retval = -ENODEV;
>> +               goto del_adapter;
>> +       }
>> +
>> +       radio->vdev.ctrl_handler = sd->ctrl_handler;
>> +       radio->v4l2_dev.release = usb_si4713_video_device_release;
>> +       strlcpy(radio->vdev.name, radio->v4l2_dev.name,
>> +               sizeof(radio->vdev.name));
>> +       radio->vdev.v4l2_dev = &radio->v4l2_dev;
>> +       radio->vdev.fops = &usb_si4713_fops;
>> +       radio->vdev.ioctl_ops = &usb_si4713_ioctl_ops;
>> +       radio->vdev.lock = &radio->lock;
>> +       radio->vdev.release = video_device_release_empty;
>> +       radio->vdev.vfl_dir = VFL_DIR_TX;
>> +
>> +       video_set_drvdata(&radio->vdev, radio);
>> +       set_bit(V4L2_FL_USE_FH_PRIO, &radio->vdev.flags);
>> +
>> +       retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
>> +       if (retval < 0) {
>> +               dev_err(&intf->dev, "could not register video device\n");
>> +               goto del_adapter;
>> +       }
>> +
>> +       dev_info(&intf->dev, "V4L2 device registered as %s\n",
>> +                       video_device_node_name(&radio->vdev));
>> +
>> +       return 0;
>> +
>> +del_adapter:
>> +       i2c_del_adapter(adapter);
>> +err_i2cdev:
>> +       v4l2_device_unregister(&radio->v4l2_dev);
>> +err_v4l2:
>> +       kfree(radio->buffer);
>> +       kfree(radio);
>> +       return retval;
>> +}
>> +
>> +static void usb_si4713_disconnect(struct usb_interface *intf)
>> +{
>> +       struct si4713_usb_device *radio = to_si4713_dev(usb_get_intfdata(intf));
>> +
>> +       dev_info(&intf->dev, "Si4713 development board now disconnected\n");
>> +
>> +       mutex_lock(&radio->lock);
>> +       usb_set_intfdata(intf, NULL);
>> +       video_unregister_device(&radio->vdev);
>> +       v4l2_device_disconnect(&radio->v4l2_dev);
>> +       mutex_unlock(&radio->lock);
>> +       v4l2_device_put(&radio->v4l2_dev);
>> +}
>> +
>> +/* USB subsystem interface */
>> +static struct usb_driver usb_si4713_driver = {
>> +       .name                   = "radio-usb-si4713",
>> +       .probe                  = usb_si4713_probe,
>> +       .disconnect             = usb_si4713_disconnect,
>> +       .id_table               = usb_si4713_usb_device_table,
>> +};
>> +
>> +module_usb_driver(usb_si4713_driver);
>> --
>> 1.7.9.5
>>
>
>
>
> --
> Eduardo Bezerra Valentin



-- 
Eduardo Bezerra Valentin

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used
  2013-10-15 15:24   ` [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used Dinesh Ram
@ 2013-12-03 15:35     ` Mauro Carvalho Chehab
  2013-12-03 17:06       ` Hans Verkuil
  0 siblings, 1 reply; 31+ messages in thread
From: Mauro Carvalho Chehab @ 2013-12-03 15:35 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: linux-media, Hans Verkuil, edubezval, dinesh.ram086

Em Tue, 15 Oct 2013 17:24:38 +0200
Dinesh Ram <dinesh.ram@cern.ch> escreveu:

> Checks have been introduced at several places in the code to test if an interrupt is set or not.
> For devices which do not use the interrupt, to get a valid response, within a specified timeout,
> the device is polled instead.
> 
> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
> ---
>  drivers/media/radio/si4713/si4713.c |  108 +++++++++++++++++++++--------------
>  1 file changed, 64 insertions(+), 44 deletions(-)
> 
> diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
> index ac727e3..24ae41d 100644
> --- a/drivers/media/radio/si4713/si4713.c
> +++ b/drivers/media/radio/si4713/si4713.c
> @@ -27,11 +27,11 @@
>  #include <linux/i2c.h>
>  #include <linux/slab.h>
>  #include <linux/gpio.h>
> -#include <linux/regulator/consumer.h>
>  #include <linux/module.h>
>  #include <media/v4l2-device.h>
>  #include <media/v4l2-ioctl.h>
>  #include <media/v4l2-common.h>
> +#include <linux/regulator/consumer.h>
>  
>  #include "si4713.h"
>  
> @@ -213,6 +213,7 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
>  				u8 response[], const int respn, const int usecs)
>  {
>  	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
> +	unsigned long until_jiffies;
>  	u8 data1[MAX_ARGS + 1];
>  	int err;
>  
> @@ -228,30 +229,39 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
>  	if (err != argn + 1) {
>  		v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
>  			command);
> -		return (err > 0) ? -EIO : err;
> +		return err < 0 ? err : -EIO;
>  	}
>  
> +	until_jiffies = jiffies + usecs_to_jiffies(usecs) + 1;
> +
>  	/* Wait response from interrupt */
> -	if (!wait_for_completion_timeout(&sdev->work,
> +	if (client->irq) {
> +		if (!wait_for_completion_timeout(&sdev->work,
>  				usecs_to_jiffies(usecs) + 1))
> -		v4l2_warn(&sdev->sd,
> +			v4l2_warn(&sdev->sd,
>  				"(%s) Device took too much time to answer.\n",
>  				__func__);
> -
> -	/* Then get the response */
> -	err = i2c_master_recv(client, response, respn);
> -	if (err != respn) {
> -		v4l2_err(&sdev->sd,
> -			"Error while reading response for command 0x%02x\n",
> -			command);
> -		return (err > 0) ? -EIO : err;
>  	}
>  
> -	DBG_BUFFER(&sdev->sd, "Response", response, respn);
> -	if (check_command_failed(response[0]))
> -		return -EBUSY;
> +	do {
> +		err = i2c_master_recv(client, response, respn);
> +		if (err != respn) {
> +			v4l2_err(&sdev->sd,
> +				"Error %d while reading response for command 0x%02x\n",
> +				err, command);
> +			return err < 0 ? err : -EIO;
> +		}
> +
> +		DBG_BUFFER(&sdev->sd, "Response", response, respn);
> +		if (!check_command_failed(response[0]))
> +			return 0;
>  
> -	return 0;
> +		if (client->irq)
> +			return -EBUSY;
> +		msleep(1);
> +	} while (jiffies <= until_jiffies);

This could result on an endless loop due to the limited space for jiffies.
You should, instead, use the proper macros (time_after, time_before, ...).

> +
> +	return -EBUSY;
>  }
>  
>  /*
> @@ -344,14 +354,15 @@ static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
>   */
>  static int si4713_powerup(struct si4713_device *sdev)
>  {
> +	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
>  	int err;
>  	u8 resp[SI4713_PWUP_NRESP];
>  	/*
>  	 * 	.First byte = Enabled interrupts and boot function
>  	 * 	.Second byte = Input operation mode
>  	 */
> -	const u8 args[SI4713_PWUP_NARGS] = {
> -		SI4713_PWUP_CTSIEN | SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
> +	u8 args[SI4713_PWUP_NARGS] = {
> +		SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
>  		SI4713_PWUP_OPMOD_ANALOG,
>  	};
>  
> @@ -369,6 +380,9 @@ static int si4713_powerup(struct si4713_device *sdev)
>  		gpio_set_value(sdev->gpio_reset, 1);
>  	}
>  
> +	if (client->irq)
> +		args[0] |= SI4713_PWUP_CTSIEN;
> +
>  	err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
>  					args, ARRAY_SIZE(args),
>  					resp, ARRAY_SIZE(resp),
> @@ -380,7 +394,8 @@ static int si4713_powerup(struct si4713_device *sdev)
>  		v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
>  		sdev->power_state = POWER_ON;
>  
> -		err = si4713_write_property(sdev, SI4713_GPO_IEN,
> +		if (client->irq)
> +			err = si4713_write_property(sdev, SI4713_GPO_IEN,
>  						SI4713_STC_INT | SI4713_CTS);
>  	} else {
>  		if (gpio_is_valid(sdev->gpio_reset))
> @@ -465,33 +480,39 @@ static int si4713_checkrev(struct si4713_device *sdev)
>   */
>  static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
>  {
> -	int err;
> +	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
>  	u8 resp[SI4713_GET_STATUS_NRESP];
> +	unsigned long start_jiffies = jiffies;
> +	int err;
>  
> -	/* Wait response from STC interrupt */
> -	if (!wait_for_completion_timeout(&sdev->work,
> -			usecs_to_jiffies(usecs) + 1))
> +	if (client->irq &&
> +	    !wait_for_completion_timeout(&sdev->work, usecs_to_jiffies(usecs) + 1))
>  		v4l2_warn(&sdev->sd,
> -			"%s: device took too much time to answer (%d usec).\n",
> -				__func__, usecs);
> -
> -	/* Clear status bits */
> -	err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
> -					NULL, 0,
> -					resp, ARRAY_SIZE(resp),
> -					DEFAULT_TIMEOUT);
> -
> -	if (err < 0)
> -		goto exit;
> -
> -	v4l2_dbg(1, debug, &sdev->sd,
> -			"%s: status bits: 0x%02x\n", __func__, resp[0]);
> -
> -	if (!(resp[0] & SI4713_STC_INT))
> -		err = -EIO;
> -
> -exit:
> -	return err;
> +			"(%s) Device took too much time to answer.\n", __func__);
> +
> +	for (;;) {
> +		/* Clear status bits */
> +		err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
> +				NULL, 0,
> +				resp, ARRAY_SIZE(resp),
> +				DEFAULT_TIMEOUT);
> +		/* The USB device returns errors when it waits for the
> +		 * STC bit to be set. Hence polling */
> +		if (err >= 0) {
> +			v4l2_dbg(1, debug, &sdev->sd,
> +				"%s: status bits: 0x%02x\n", __func__, resp[0]);
> +
> +			if (resp[0] & SI4713_STC_INT)
> +				return 0;
> +		}
> +		if (jiffies_to_usecs(jiffies - start_jiffies) > usecs)

Same here: use the proper macro to check time after/before.

> +			return err < 0 ? err : -EIO;
> +		/* We sleep here for 3 ms in order to avoid flooding the device
> +		 * with USB requests. The si4713 USB driver was developed
> +		 * by reverse engineering the Windows USB driver. The windows
> +		 * driver also has a ~2.5 ms delay between responses. */
> +		msleep(3);
> +	}
>  }
>  
>  /*
> @@ -1024,7 +1045,6 @@ static int si4713_initialize(struct si4713_device *sdev)
>  	if (rval < 0)
>  		return rval;
>  
> -
>  	sdev->frequency = DEFAULT_FREQUENCY;
>  	sdev->stereo = 1;
>  	sdev->tune_rnl = DEFAULT_TUNE_RNL;


-- 

Cheers,
Mauro

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory
  2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
                     ` (7 preceding siblings ...)
  2013-10-15 15:24   ` [REVIEW PATCH 9/9] si4713: si4713_set_rds_radio_text overwrites terminating \0 Dinesh Ram
@ 2013-12-03 15:39   ` Mauro Carvalho Chehab
       [not found]     ` <CAP_RhzeRgLir1FGL6UN2-yXXaS-1knsS2BP20MjfMJRAEyDqeg@mail.gmail.com>
  2013-12-03 16:58     ` Hans Verkuil
  8 siblings, 2 replies; 31+ messages in thread
From: Mauro Carvalho Chehab @ 2013-12-03 15:39 UTC (permalink / raw)
  To: Dinesh Ram; +Cc: linux-media, Hans Verkuil, edubezval, dinesh.ram086

Em Tue, 15 Oct 2013 17:24:37 +0200
Dinesh Ram <dinesh.ram@cern.ch> escreveu:

> Added a new si4713 directory which will contain all si4713 related files.
> Also updated Makefile and Kconfig
> 
> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
> ---
>  drivers/media/radio/Kconfig                        |   29 +-
>  drivers/media/radio/Makefile                       |    3 +-
>  drivers/media/radio/radio-si4713.c                 |  246 ----
>  drivers/media/radio/si4713-i2c.c                   | 1532 --------------------
>  drivers/media/radio/si4713-i2c.h                   |  238 ---
>  drivers/media/radio/si4713/Kconfig                 |   25 +
>  drivers/media/radio/si4713/Makefile                |    7 +
>  drivers/media/radio/si4713/radio-platform-si4713.c |  246 ++++
>  drivers/media/radio/si4713/si4713.c                | 1532 ++++++++++++++++++++
>  drivers/media/radio/si4713/si4713.h                |  238 +++
>  10 files changed, 2055 insertions(+), 2041 deletions(-)
>  delete mode 100644 drivers/media/radio/radio-si4713.c
>  delete mode 100644 drivers/media/radio/si4713-i2c.c
>  delete mode 100644 drivers/media/radio/si4713-i2c.h
>  create mode 100644 drivers/media/radio/si4713/Kconfig
>  create mode 100644 drivers/media/radio/si4713/Makefile
>  create mode 100644 drivers/media/radio/si4713/radio-platform-si4713.c
>  create mode 100644 drivers/media/radio/si4713/si4713.c
>  create mode 100644 drivers/media/radio/si4713/si4713.h
> 

Please submit rename patches like that using "git show -M", in order to show only
what changed. 

Btw, while here, I would expect a latter patch on this series fixing the
checkpatch.pl warnings/errors:

WARNING: please write a paragraph that describes the config symbol fully
#23: FILE: drivers/media/radio/Kconfig:24:
+config RADIO_SI4713

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2181: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:19:
+ * You should have received a copy of the GNU General Public License$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2182: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:20:
+ * along with this program; if not, write to the Free Software$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2183: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:21:
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$

WARNING: line over 80 characters
#2242: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:80:
+	capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;

WARNING: line over 80 characters
#2365: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:203:
+	if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2433: FILE: drivers/media/radio/si4713/si4713.c:19:
+ * You should have received a copy of the GNU General Public License$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2434: FILE: drivers/media/radio/si4713/si4713.c:20:
+ * along with this program; if not, write to the Free Software$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2435: FILE: drivers/media/radio/si4713/si4713.c:21:
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$

WARNING: please, no space before tabs
#2473: FILE: drivers/media/radio/si4713/si4713.c:59:
+#define DEFAULT_PILOT_FREQUENCY ^I0x4A38$

WARNING: please, no space before tabs
#2478: FILE: drivers/media/radio/si4713/si4713.c:64:
+#define DEFAULT_ACOMP_THRESHOLD ^I(-0x28)$

WARNING: please, no space before tabs
#2682: FILE: drivers/media/radio/si4713/si4713.c:268:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2683: FILE: drivers/media/radio/si4713/si4713.c:269:
+^I * ^I.Second byte = property's MSB$

WARNING: please, no space before tabs
#2684: FILE: drivers/media/radio/si4713/si4713.c:270:
+^I * ^I.Third byte = property's LSB$

WARNING: please, no space before tabs
#2719: FILE: drivers/media/radio/si4713/si4713.c:305:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2720: FILE: drivers/media/radio/si4713/si4713.c:306:
+^I * ^I.Second byte = property's MSB$

WARNING: please, no space before tabs
#2721: FILE: drivers/media/radio/si4713/si4713.c:307:
+^I * ^I.Third byte = property's LSB$

WARNING: please, no space before tabs
#2722: FILE: drivers/media/radio/si4713/si4713.c:308:
+^I * ^I.Fourth byte = value's MSB$

WARNING: please, no space before tabs
#2723: FILE: drivers/media/radio/si4713/si4713.c:309:
+^I * ^I.Fifth byte = value's LSB$

WARNING: please, no space before tabs
#2764: FILE: drivers/media/radio/si4713/si4713.c:350:
+^I * ^I.First byte = Enabled interrupts and boot function$

WARNING: please, no space before tabs
#2765: FILE: drivers/media/radio/si4713/si4713.c:351:
+^I * ^I.Second byte = Input operation mode$

WARNING: please, no space before tabs
#2913: FILE: drivers/media/radio/si4713/si4713.c:499:
+ * ^I^I^Ifrequency between 76 and 108 MHz in 10 kHz units and$

WARNING: please, no space before tabs
#2914: FILE: drivers/media/radio/si4713/si4713.c:500:
+ * ^I^I^Isteps of 50 kHz.$

WARNING: please, no space before tabs
#2923: FILE: drivers/media/radio/si4713/si4713.c:509:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2924: FILE: drivers/media/radio/si4713/si4713.c:510:
+^I * ^I.Second byte = frequency's MSB$

WARNING: please, no space before tabs
#2925: FILE: drivers/media/radio/si4713/si4713.c:511:
+^I * ^I.Third byte = frequency's LSB$

WARNING: please, no space before tabs
#2953: FILE: drivers/media/radio/si4713/si4713.c:539:
+ * ^I^I^I1 dB units. A value of 0x00 indicates off. The command$

WARNING: please, no space before tabs
#2954: FILE: drivers/media/radio/si4713/si4713.c:540:
+ * ^I^I^Ialso sets the antenna tuning capacitance. A value of 0$

WARNING: please, no space before tabs
#2955: FILE: drivers/media/radio/si4713/si4713.c:541:
+ * ^I^I^Iindicates autotuning, and a value of 1 - 191 indicates$

WARNING: please, no space before tabs
#2956: FILE: drivers/media/radio/si4713/si4713.c:542:
+ * ^I^I^Ia manual override, which results in a tuning$

WARNING: please, no space before tabs
#2957: FILE: drivers/media/radio/si4713/si4713.c:543:
+ * ^I^I^Icapacitance of 0.25 pF x @antcap.$

WARNING: please, no space before tabs
#2968: FILE: drivers/media/radio/si4713/si4713.c:554:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2969: FILE: drivers/media/radio/si4713/si4713.c:555:
+^I * ^I.Second byte = 0$

WARNING: please, no space before tabs
#2970: FILE: drivers/media/radio/si4713/si4713.c:556:
+^I * ^I.Third byte = power$

WARNING: please, no space before tabs
#2971: FILE: drivers/media/radio/si4713/si4713.c:557:
+^I * ^I.Fourth byte = antcap$

WARNING: please, no space before tabs
#3000: FILE: drivers/media/radio/si4713/si4713.c:586:
+ * ^I^I^Ilevel in units of dBuV on the selected frequency.$

WARNING: please, no space before tabs
#3001: FILE: drivers/media/radio/si4713/si4713.c:587:
+ * ^I^I^IThe Frequency must be between 76 and 108 MHz in 10 kHz$

WARNING: please, no space before tabs
#3002: FILE: drivers/media/radio/si4713/si4713.c:588:
+ * ^I^I^Iunits and steps of 50 kHz. The command also sets the$

WARNING: please, no space before tabs
#3003: FILE: drivers/media/radio/si4713/si4713.c:589:
+ * ^I^I^Iantenna^Ituning capacitance. A value of 0 means$

WARNING: please, no space before tabs
#3004: FILE: drivers/media/radio/si4713/si4713.c:590:
+ * ^I^I^Iautotuning, and a value of 1 to 191 indicates manual$

WARNING: please, no space before tabs
#3005: FILE: drivers/media/radio/si4713/si4713.c:591:
+ * ^I^I^Ioverride.$

WARNING: please, no space before tabs
#3016: FILE: drivers/media/radio/si4713/si4713.c:602:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#3017: FILE: drivers/media/radio/si4713/si4713.c:603:
+^I * ^I.Second byte = frequency's MSB$

WARNING: please, no space before tabs
#3018: FILE: drivers/media/radio/si4713/si4713.c:604:
+^I * ^I.Third byte = frequency's LSB$

WARNING: please, no space before tabs
#3019: FILE: drivers/media/radio/si4713/si4713.c:605:
+^I * ^I.Fourth byte = antcap$

WARNING: please, no space before tabs
#3049: FILE: drivers/media/radio/si4713/si4713.c:635:
+ * ^I^I^Itx_tune_power commands. This command return the current$

WARNING: please, no space before tabs
#3050: FILE: drivers/media/radio/si4713/si4713.c:636:
+ * ^I^I^Ifrequency, output voltage in dBuV, the antenna tunning$

WARNING: please, no space before tabs
#3051: FILE: drivers/media/radio/si4713/si4713.c:637:
+ * ^I^I^Icapacitance value and the received noise level. The$

WARNING: please, no space before tabs
#3052: FILE: drivers/media/radio/si4713/si4713.c:638:
+ * ^I^I^Icommand also clears the stcint interrupt bit when the$

WARNING: please, no space before tabs
#3053: FILE: drivers/media/radio/si4713/si4713.c:639:
+ * ^I^I^Ifirst bit of its arguments is high.$

WARNING: please, no space before tabs
#3068: FILE: drivers/media/radio/si4713/si4713.c:654:
+^I * ^I.First byte = intack bit$

WARNING: quoted string split across lines
#3087: FILE: drivers/media/radio/si4713/si4713.c:673:
+		v4l2_dbg(1, debug, &sdev->sd, "%s: response: %d x 10 kHz "
+				"(power %d, antcap %d, rnl %d)\n", __func__,

WARNING: quoted string split across lines
#3129: FILE: drivers/media/radio/si4713/si4713.c:715:
+		v4l2_dbg(1, debug, &sdev->sd, "%s: response: interrupts"
+				" 0x%02x cb avail: %d cb used %d fifo avail"

WARNING: line over 80 characters
#3250: FILE: drivers/media/radio/si4713/si4713.c:836:
+		if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {

WARNING: line over 80 characters
#3391: FILE: drivers/media/radio/si4713/si4713.c:977:
+static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);

WARNING: line over 80 characters
#3392: FILE: drivers/media/radio/si4713/si4713.c:978:
+static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);

WARNING: line over 80 characters
#3509: FILE: drivers/media/radio/si4713/si4713.c:1095:
+				sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);

WARNING: line over 80 characters
#3518: FILE: drivers/media/radio/si4713/si4713.c:1104:
+			ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,

WARNING: line over 80 characters
#3535: FILE: drivers/media/radio/si4713/si4713.c:1121:
+				ret = si4713_read_property(sdev, property, &val);

WARNING: line over 80 characters
#3636: FILE: drivers/media/radio/si4713/si4713.c:1222:
+static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)

WARNING: line over 80 characters
#3706: FILE: drivers/media/radio/si4713/si4713.c:1292:
+static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)

WARNING: sizeof *sdev should be sizeof(*sdev)
#3762: FILE: drivers/media/radio/si4713/si4713.c:1348:
+	sdev = kzalloc(sizeof *sdev, GFP_KERNEL);

WARNING: line over 80 characters
#3820: FILE: drivers/media/radio/si4713/si4713.c:1406:
+			V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);

WARNING: line over 80 characters
#3837: FILE: drivers/media/radio/si4713/si4713.c:1423:
+			V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,

WARNING: line over 80 characters
#3843: FILE: drivers/media/radio/si4713/si4713.c:1429:
+	sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,

WARNING: line over 80 characters
#3860: FILE: drivers/media/radio/si4713/si4713.c:1446:
+			V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);

total: 6 errors, 60 warnings, 2101 lines checked

Your patch has style problems, please review.

If any of these errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.



-- 

Cheers,
Mauro

^ permalink raw reply	[flat|nested] 31+ messages in thread

* FW: [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory
       [not found]     ` <CAP_RhzeRgLir1FGL6UN2-yXXaS-1knsS2BP20MjfMJRAEyDqeg@mail.gmail.com>
@ 2013-12-03 16:06       ` Dinesh Ram
  0 siblings, 0 replies; 31+ messages in thread
From: Dinesh Ram @ 2013-12-03 16:06 UTC (permalink / raw)
  To: Linux-Media

[-- Attachment #1: Type: text/plain, Size: 14784 bytes --]

Mail to the mailing list from my gmail id bounce back.
Trying with this ID.

From: d ram [dinesh.ram086@gmail.com]
Sent: 03 December 2013 16:57
To: Mauro Carvalho Chehab
Cc: Dinesh Ram; Linux-Media; Hans Verkuil; Eduardo Valentin
Subject: Re: [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory

Hello Mauro,

I am not sure what happened here. Maybe the patch got mixed up.
I had corrected all of the errors / warnings. But maybe I mailed the incorrect one (beats me how !)
Please find the correct one attached with this email.

checkpatch.pl<http://checkpatch.pl> on this one gives :

scripts/checkpatch.pl<http://checkpatch.pl> 0001-si4713-Reorganized-drivers-media-radio-directory.patch
WARNING: please write a paragraph that describes the config symbol fully
#34: FILE: drivers/media/radio/Kconfig:18:
+config RADIO_SI4713

total: 0 errors, 1 warnings, 112 lines checked

0001-si4713-Reorganized-drivers-media-radio-directory.patch has style problems, please review.

If any of these errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.


Regards,
Dinesh Ram


On Tue, Dec 3, 2013 at 4:39 PM, Mauro Carvalho Chehab <m.chehab@samsung.com<mailto:m.chehab@samsung.com>> wrote:
Em Tue, 15 Oct 2013 17:24:37 +0200
Dinesh Ram <dinesh.ram@cern.ch<mailto:dinesh.ram@cern.ch>> escreveu:

> Added a new si4713 directory which will contain all si4713 related files.
> Also updated Makefile and Kconfig
>
> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch<mailto:dinesh.ram@cern.ch>>
> ---
>  drivers/media/radio/Kconfig                        |   29 +-
>  drivers/media/radio/Makefile                       |    3 +-
>  drivers/media/radio/radio-si4713.c                 |  246 ----
>  drivers/media/radio/si4713-i2c.c                   | 1532 --------------------
>  drivers/media/radio/si4713-i2c.h                   |  238 ---
>  drivers/media/radio/si4713/Kconfig                 |   25 +
>  drivers/media/radio/si4713/Makefile                |    7 +
>  drivers/media/radio/si4713/radio-platform-si4713.c |  246 ++++
>  drivers/media/radio/si4713/si4713.c                | 1532 ++++++++++++++++++++
>  drivers/media/radio/si4713/si4713.h                |  238 +++
>  10 files changed, 2055 insertions(+), 2041 deletions(-)
>  delete mode 100644 drivers/media/radio/radio-si4713.c
>  delete mode 100644 drivers/media/radio/si4713-i2c.c
>  delete mode 100644 drivers/media/radio/si4713-i2c.h
>  create mode 100644 drivers/media/radio/si4713/Kconfig
>  create mode 100644 drivers/media/radio/si4713/Makefile
>  create mode 100644 drivers/media/radio/si4713/radio-platform-si4713.c
>  create mode 100644 drivers/media/radio/si4713/si4713.c
>  create mode 100644 drivers/media/radio/si4713/si4713.h
>

Please submit rename patches like that using "git show -M", in order to show only
what changed.

Btw, while here, I would expect a latter patch on this series fixing the
checkpatch.pl<http://checkpatch.pl> warnings/errors:

WARNING: please write a paragraph that describes the config symbol fully
#23: FILE: drivers/media/radio/Kconfig:24:
+config RADIO_SI4713

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2181: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:19:
+ * You should have received a copy of the GNU General Public License$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2182: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:20:
+ * along with this program; if not, write to the Free Software$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2183: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:21:
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$

WARNING: line over 80 characters
#2242: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:80:
+       capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;

WARNING: line over 80 characters
#2365: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:203:
+       if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2433: FILE: drivers/media/radio/si4713/si4713.c:19:
+ * You should have received a copy of the GNU General Public License$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2434: FILE: drivers/media/radio/si4713/si4713.c:20:
+ * along with this program; if not, write to the Free Software$

ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
#2435: FILE: drivers/media/radio/si4713/si4713.c:21:
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$

WARNING: please, no space before tabs
#2473: FILE: drivers/media/radio/si4713/si4713.c:59:
+#define DEFAULT_PILOT_FREQUENCY ^I0x4A38$

WARNING: please, no space before tabs
#2478: FILE: drivers/media/radio/si4713/si4713.c:64:
+#define DEFAULT_ACOMP_THRESHOLD ^I(-0x28)$

WARNING: please, no space before tabs
#2682: FILE: drivers/media/radio/si4713/si4713.c:268:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2683: FILE: drivers/media/radio/si4713/si4713.c:269:
+^I * ^I.Second byte = property's MSB$

WARNING: please, no space before tabs
#2684: FILE: drivers/media/radio/si4713/si4713.c:270:
+^I * ^I.Third byte = property's LSB$

WARNING: please, no space before tabs
#2719: FILE: drivers/media/radio/si4713/si4713.c:305:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2720: FILE: drivers/media/radio/si4713/si4713.c:306:
+^I * ^I.Second byte = property's MSB$

WARNING: please, no space before tabs
#2721: FILE: drivers/media/radio/si4713/si4713.c:307:
+^I * ^I.Third byte = property's LSB$

WARNING: please, no space before tabs
#2722: FILE: drivers/media/radio/si4713/si4713.c:308:
+^I * ^I.Fourth byte = value's MSB$

WARNING: please, no space before tabs
#2723: FILE: drivers/media/radio/si4713/si4713.c:309:
+^I * ^I.Fifth byte = value's LSB$

WARNING: please, no space before tabs
#2764: FILE: drivers/media/radio/si4713/si4713.c:350:
+^I * ^I.First byte = Enabled interrupts and boot function$

WARNING: please, no space before tabs
#2765: FILE: drivers/media/radio/si4713/si4713.c:351:
+^I * ^I.Second byte = Input operation mode$

WARNING: please, no space before tabs
#2913: FILE: drivers/media/radio/si4713/si4713.c:499:
+ * ^I^I^Ifrequency between 76 and 108 MHz in 10 kHz units and$

WARNING: please, no space before tabs
#2914: FILE: drivers/media/radio/si4713/si4713.c:500:
+ * ^I^I^Isteps of 50 kHz.$

WARNING: please, no space before tabs
#2923: FILE: drivers/media/radio/si4713/si4713.c:509:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2924: FILE: drivers/media/radio/si4713/si4713.c:510:
+^I * ^I.Second byte = frequency's MSB$

WARNING: please, no space before tabs
#2925: FILE: drivers/media/radio/si4713/si4713.c:511:
+^I * ^I.Third byte = frequency's LSB$

WARNING: please, no space before tabs
#2953: FILE: drivers/media/radio/si4713/si4713.c:539:
+ * ^I^I^I1 dB units. A value of 0x00 indicates off. The command$

WARNING: please, no space before tabs
#2954: FILE: drivers/media/radio/si4713/si4713.c:540:
+ * ^I^I^Ialso sets the antenna tuning capacitance. A value of 0$

WARNING: please, no space before tabs
#2955: FILE: drivers/media/radio/si4713/si4713.c:541:
+ * ^I^I^Iindicates autotuning, and a value of 1 - 191 indicates$

WARNING: please, no space before tabs
#2956: FILE: drivers/media/radio/si4713/si4713.c:542:
+ * ^I^I^Ia manual override, which results in a tuning$

WARNING: please, no space before tabs
#2957: FILE: drivers/media/radio/si4713/si4713.c:543:
+ * ^I^I^Icapacitance of 0.25 pF x @antcap.$

WARNING: please, no space before tabs
#2968: FILE: drivers/media/radio/si4713/si4713.c:554:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#2969: FILE: drivers/media/radio/si4713/si4713.c:555:
+^I * ^I.Second byte = 0$

WARNING: please, no space before tabs
#2970: FILE: drivers/media/radio/si4713/si4713.c:556:
+^I * ^I.Third byte = power$

WARNING: please, no space before tabs
#2971: FILE: drivers/media/radio/si4713/si4713.c:557:
+^I * ^I.Fourth byte = antcap$

WARNING: please, no space before tabs
#3000: FILE: drivers/media/radio/si4713/si4713.c:586:
+ * ^I^I^Ilevel in units of dBuV on the selected frequency.$

WARNING: please, no space before tabs
#3001: FILE: drivers/media/radio/si4713/si4713.c:587:
+ * ^I^I^IThe Frequency must be between 76 and 108 MHz in 10 kHz$

WARNING: please, no space before tabs
#3002: FILE: drivers/media/radio/si4713/si4713.c:588:
+ * ^I^I^Iunits and steps of 50 kHz. The command also sets the$

WARNING: please, no space before tabs
#3003: FILE: drivers/media/radio/si4713/si4713.c:589:
+ * ^I^I^Iantenna^Ituning capacitance. A value of 0 means$

WARNING: please, no space before tabs
#3004: FILE: drivers/media/radio/si4713/si4713.c:590:
+ * ^I^I^Iautotuning, and a value of 1 to 191 indicates manual$

WARNING: please, no space before tabs
#3005: FILE: drivers/media/radio/si4713/si4713.c:591:
+ * ^I^I^Ioverride.$

WARNING: please, no space before tabs
#3016: FILE: drivers/media/radio/si4713/si4713.c:602:
+^I * ^I.First byte = 0$

WARNING: please, no space before tabs
#3017: FILE: drivers/media/radio/si4713/si4713.c:603:
+^I * ^I.Second byte = frequency's MSB$

WARNING: please, no space before tabs
#3018: FILE: drivers/media/radio/si4713/si4713.c:604:
+^I * ^I.Third byte = frequency's LSB$

WARNING: please, no space before tabs
#3019: FILE: drivers/media/radio/si4713/si4713.c:605:
+^I * ^I.Fourth byte = antcap$

WARNING: please, no space before tabs
#3049: FILE: drivers/media/radio/si4713/si4713.c:635:
+ * ^I^I^Itx_tune_power commands. This command return the current$

WARNING: please, no space before tabs
#3050: FILE: drivers/media/radio/si4713/si4713.c:636:
+ * ^I^I^Ifrequency, output voltage in dBuV, the antenna tunning$

WARNING: please, no space before tabs
#3051: FILE: drivers/media/radio/si4713/si4713.c:637:
+ * ^I^I^Icapacitance value and the received noise level. The$

WARNING: please, no space before tabs
#3052: FILE: drivers/media/radio/si4713/si4713.c:638:
+ * ^I^I^Icommand also clears the stcint interrupt bit when the$

WARNING: please, no space before tabs
#3053: FILE: drivers/media/radio/si4713/si4713.c:639:
+ * ^I^I^Ifirst bit of its arguments is high.$

WARNING: please, no space before tabs
#3068: FILE: drivers/media/radio/si4713/si4713.c:654:
+^I * ^I.First byte = intack bit$

WARNING: quoted string split across lines
#3087: FILE: drivers/media/radio/si4713/si4713.c:673:
+               v4l2_dbg(1, debug, &sdev->sd, "%s: response: %d x 10 kHz "
+                               "(power %d, antcap %d, rnl %d)\n", __func__,

WARNING: quoted string split across lines
#3129: FILE: drivers/media/radio/si4713/si4713.c:715:
+               v4l2_dbg(1, debug, &sdev->sd, "%s: response: interrupts"
+                               " 0x%02x cb avail: %d cb used %d fifo avail"

WARNING: line over 80 characters
#3250: FILE: drivers/media/radio/si4713/si4713.c:836:
+               if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {

WARNING: line over 80 characters
#3391: FILE: drivers/media/radio/si4713/si4713.c:977:
+static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);

WARNING: line over 80 characters
#3392: FILE: drivers/media/radio/si4713/si4713.c:978:
+static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);

WARNING: line over 80 characters
#3509: FILE: drivers/media/radio/si4713/si4713.c:1095:
+                               sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);

WARNING: line over 80 characters
#3518: FILE: drivers/media/radio/si4713/si4713.c:1104:
+                       ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,

WARNING: line over 80 characters
#3535: FILE: drivers/media/radio/si4713/si4713.c:1121:
+                               ret = si4713_read_property(sdev, property, &val);

WARNING: line over 80 characters
#3636: FILE: drivers/media/radio/si4713/si4713.c:1222:
+static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)

WARNING: line over 80 characters
#3706: FILE: drivers/media/radio/si4713/si4713.c:1292:
+static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)

WARNING: sizeof *sdev should be sizeof(*sdev)
#3762: FILE: drivers/media/radio/si4713/si4713.c:1348:
+       sdev = kzalloc(sizeof *sdev, GFP_KERNEL);

WARNING: line over 80 characters
#3820: FILE: drivers/media/radio/si4713/si4713.c:1406:
+                       V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);

WARNING: line over 80 characters
#3837: FILE: drivers/media/radio/si4713/si4713.c:1423:
+                       V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,

WARNING: line over 80 characters
#3843: FILE: drivers/media/radio/si4713/si4713.c:1429:
+       sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,

WARNING: line over 80 characters
#3860: FILE: drivers/media/radio/si4713/si4713.c:1446:
+                       V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);

total: 6 errors, 60 warnings, 2101 lines checked

Your patch has style problems, please review.

If any of these errors are false positives, please report
them to the maintainer, see CHECKPATCH in MAINTAINERS.



--

Cheers,
Mauro


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-si4713-Reorganized-drivers-media-radio-directory.patch --]
[-- Type: text/x-patch; name="0001-si4713-Reorganized-drivers-media-radio-directory.patch", Size: 6847 bytes --]

From e0c42c229e08425a074810964ef1f6b90504715e Mon Sep 17 00:00:00 2001
Message-Id: <e0c42c229e08425a074810964ef1f6b90504715e.1381848762.git.dinesh.ram@cern.ch>
From: Dinesh Ram <dinesh.ram@cern.ch>
Date: Sat, 5 Oct 2013 19:24:01 +0200
Subject: [PATCH 1/9] si4713 : Reorganized drivers/media/radio directory

Added a new si4713 directory which will contain all si4713 related files.
Also updated Makefile and Kconfig

Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
---
 drivers/media/radio/Kconfig                        |   29 ++++----------------
 drivers/media/radio/Makefile                       |    3 +-
 drivers/media/radio/si4713/Kconfig                 |   25 +++++++++++++++++
 drivers/media/radio/si4713/Makefile                |    7 +++++
 .../radio-platform-si4713.c}                       |    2 +-
 .../media/radio/{si4713-i2c.c => si4713/si4713.c}  |    4 +--
 .../media/radio/{si4713-i2c.h => si4713/si4713.h}  |    2 +-
 7 files changed, 43 insertions(+), 29 deletions(-)
 create mode 100644 drivers/media/radio/si4713/Kconfig
 create mode 100644 drivers/media/radio/si4713/Makefile
 rename drivers/media/radio/{radio-si4713.c => si4713/radio-platform-si4713.c} (99%)
 rename drivers/media/radio/{si4713-i2c.c => si4713/si4713.c} (99%)
 rename drivers/media/radio/{si4713-i2c.h => si4713/si4713.h} (99%)

diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 6ecdc39..57ea9c3 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -15,6 +15,12 @@ if RADIO_ADAPTERS && VIDEO_V4L2
 config RADIO_TEA575X
 	tristate
 
+config RADIO_SI4713
+	tristate "Silicon Labs Si4713 FM Radio with RDS Transmitter support"
+	depends on VIDEO_V4L2
+
+source "drivers/media/radio/si4713/Kconfig"
+
 config RADIO_SI470X
 	bool "Silicon Labs Si470x FM Radio Receiver support"
 	depends on VIDEO_V4L2
@@ -113,29 +119,6 @@ config RADIO_SHARK2
 	  To compile this driver as a module, choose M here: the
 	  module will be called radio-shark2.
 
-config I2C_SI4713
-	tristate "I2C driver for Silicon Labs Si4713 device"
-	depends on I2C && VIDEO_V4L2
-	---help---
-	  Say Y here if you want support to Si4713 I2C device.
-	  This device driver supports only i2c bus.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called si4713.
-
-config RADIO_SI4713
-	tristate "Silicon Labs Si4713 FM Radio Transmitter support"
-	depends on I2C && VIDEO_V4L2
-	select I2C_SI4713
-	---help---
-	  Say Y here if you want support to Si4713 FM Radio Transmitter.
-	  This device can transmit audio through FM. It can transmit
-	  RDS and RBDS signals as well. This module is the v4l2 radio
-	  interface for the i2c driver of this device.
-
-	  To compile this driver as a module, choose M here: the
-	  module will be called radio-si4713.
-
 config USB_KEENE
 	tristate "Keene FM Transmitter USB support"
 	depends on USB && VIDEO_V4L2
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index 3b64560..eb1a3a0 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -17,12 +17,11 @@ obj-$(CONFIG_RADIO_RTRACK) += radio-aimslab.o
 obj-$(CONFIG_RADIO_ZOLTRIX) += radio-zoltrix.o
 obj-$(CONFIG_RADIO_GEMTEK) += radio-gemtek.o
 obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
-obj-$(CONFIG_I2C_SI4713) += si4713-i2c.o
-obj-$(CONFIG_RADIO_SI4713) += radio-si4713.o
 obj-$(CONFIG_RADIO_SI476X) += radio-si476x.o
 obj-$(CONFIG_RADIO_MIROPCM20) += radio-miropcm20.o
 obj-$(CONFIG_USB_DSBR) += dsbr100.o
 obj-$(CONFIG_RADIO_SI470X) += si470x/
+obj-$(CONFIG_RADIO_SI4713) += si4713/
 obj-$(CONFIG_USB_MR800) += radio-mr800.o
 obj-$(CONFIG_USB_KEENE) += radio-keene.o
 obj-$(CONFIG_USB_MA901) += radio-ma901.o
diff --git a/drivers/media/radio/si4713/Kconfig b/drivers/media/radio/si4713/Kconfig
new file mode 100644
index 0000000..ec640b8
--- /dev/null
+++ b/drivers/media/radio/si4713/Kconfig
@@ -0,0 +1,25 @@
+config PLATFORM_SI4713
+	tristate "Silicon Labs Si4713 FM Radio Transmitter support with I2C"
+	depends on I2C && RADIO_SI4713
+	select SI4713
+	---help---
+	  This is a driver for I2C devices with the Silicon Labs SI4713
+	  chip.
+
+	  Say Y here if you want to connect this type of radio to your
+	  computer's I2C port.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called radio-platform-si4713.
+
+config I2C_SI4713
+	tristate "Silicon Labs Si4713 FM Radio Transmitter support"
+	depends on I2C && RADIO_SI4713
+	---help---
+	  Say Y here if you want support to Si4713 FM Radio Transmitter.
+	  This device can transmit audio through FM. It can transmit
+	  RDS and RBDS signals as well. This module is the v4l2 radio
+	  interface for the i2c driver of this device.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called si4713.
diff --git a/drivers/media/radio/si4713/Makefile b/drivers/media/radio/si4713/Makefile
new file mode 100644
index 0000000..9d0bd0e
--- /dev/null
+++ b/drivers/media/radio/si4713/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for radios with Silicon Labs Si4713 FM Radio Transmitters
+#
+
+obj-$(CONFIG_I2C_SI4713) += si4713.o
+obj-$(CONFIG_PLATFORM_SI4713) += radio-platform-si4713.o
+
diff --git a/drivers/media/radio/radio-si4713.c b/drivers/media/radio/si4713/radio-platform-si4713.c
similarity index 99%
rename from drivers/media/radio/radio-si4713.c
rename to drivers/media/radio/si4713/radio-platform-si4713.c
index ba4cfc9..cf0aad4 100644
--- a/drivers/media/radio/radio-si4713.c
+++ b/drivers/media/radio/si4713/radio-platform-si4713.c
@@ -1,5 +1,5 @@
 /*
- * drivers/media/radio/radio-si4713.c
+ * drivers/media/radio/radio-platform-si4713.c
  *
  * Platform Driver for Silicon Labs Si4713 FM Radio Transmitter:
  *
diff --git a/drivers/media/radio/si4713-i2c.c b/drivers/media/radio/si4713/si4713.c
similarity index 99%
rename from drivers/media/radio/si4713-i2c.c
rename to drivers/media/radio/si4713/si4713.c
index fe16088..ac727e3 100644
--- a/drivers/media/radio/si4713-i2c.c
+++ b/drivers/media/radio/si4713/si4713.c
@@ -1,5 +1,5 @@
 /*
- * drivers/media/radio/si4713-i2c.c
+ * drivers/media/radio/si4713.c
  *
  * Silicon Labs Si4713 FM Radio Transmitter I2C commands.
  *
@@ -33,7 +33,7 @@
 #include <media/v4l2-ioctl.h>
 #include <media/v4l2-common.h>
 
-#include "si4713-i2c.h"
+#include "si4713.h"
 
 /* module parameters */
 static int debug;
diff --git a/drivers/media/radio/si4713-i2c.h b/drivers/media/radio/si4713/si4713.h
similarity index 99%
rename from drivers/media/radio/si4713-i2c.h
rename to drivers/media/radio/si4713/si4713.h
index 25cdea2..c274e1f 100644
--- a/drivers/media/radio/si4713-i2c.h
+++ b/drivers/media/radio/si4713/si4713.h
@@ -1,5 +1,5 @@
 /*
- * drivers/media/radio/si4713-i2c.h
+ * drivers/media/radio/si4713.h
  *
  * Property and commands definitions for Si4713 radio transmitter chip.
  *
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory
  2013-12-03 15:39   ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Mauro Carvalho Chehab
       [not found]     ` <CAP_RhzeRgLir1FGL6UN2-yXXaS-1knsS2BP20MjfMJRAEyDqeg@mail.gmail.com>
@ 2013-12-03 16:58     ` Hans Verkuil
  2013-12-04 17:41       ` Mauro Carvalho Chehab
  1 sibling, 1 reply; 31+ messages in thread
From: Hans Verkuil @ 2013-12-03 16:58 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Dinesh Ram, linux-media, edubezval, dinesh.ram086

On 12/03/2013 04:39 PM, Mauro Carvalho Chehab wrote:
> Em Tue, 15 Oct 2013 17:24:37 +0200
> Dinesh Ram <dinesh.ram@cern.ch> escreveu:
> 
>> Added a new si4713 directory which will contain all si4713 related files.
>> Also updated Makefile and Kconfig
>>
>> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
>> ---
>>  drivers/media/radio/Kconfig                        |   29 +-
>>  drivers/media/radio/Makefile                       |    3 +-
>>  drivers/media/radio/radio-si4713.c                 |  246 ----
>>  drivers/media/radio/si4713-i2c.c                   | 1532 --------------------
>>  drivers/media/radio/si4713-i2c.h                   |  238 ---
>>  drivers/media/radio/si4713/Kconfig                 |   25 +
>>  drivers/media/radio/si4713/Makefile                |    7 +
>>  drivers/media/radio/si4713/radio-platform-si4713.c |  246 ++++
>>  drivers/media/radio/si4713/si4713.c                | 1532 ++++++++++++++++++++
>>  drivers/media/radio/si4713/si4713.h                |  238 +++
>>  10 files changed, 2055 insertions(+), 2041 deletions(-)
>>  delete mode 100644 drivers/media/radio/radio-si4713.c
>>  delete mode 100644 drivers/media/radio/si4713-i2c.c
>>  delete mode 100644 drivers/media/radio/si4713-i2c.h
>>  create mode 100644 drivers/media/radio/si4713/Kconfig
>>  create mode 100644 drivers/media/radio/si4713/Makefile
>>  create mode 100644 drivers/media/radio/si4713/radio-platform-si4713.c
>>  create mode 100644 drivers/media/radio/si4713/si4713.c
>>  create mode 100644 drivers/media/radio/si4713/si4713.h
>>
> 
> Please submit rename patches like that using "git show -M", in order to show only
> what changed. 

My pull request for this patch series does this correctly.

> 
> Btw, while here, I would expect a latter patch on this series fixing the
> checkpatch.pl warnings/errors:

Why? Moving a source from one directory to another doesn't mean you have to clean up
all the checkpatch warnings/errors. There is nothing special here that warrants the
extra work.

> 
> WARNING: please write a paragraph that describes the config symbol fully
> #23: FILE: drivers/media/radio/Kconfig:24:
> +config RADIO_SI4713
> 
> ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> #2181: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:19:
> + * You should have received a copy of the GNU General Public License$
> 
> ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> #2182: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:20:
> + * along with this program; if not, write to the Free Software$
> 
> ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> #2183: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:21:
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$

This check only appeared in 3.13, and this patch series is older than that.

Regards,

	Hans

> 
> WARNING: line over 80 characters
> #2242: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:80:
> +	capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
> 
> WARNING: line over 80 characters
> #2365: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:203:
> +	if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
> 
> ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> #2433: FILE: drivers/media/radio/si4713/si4713.c:19:
> + * You should have received a copy of the GNU General Public License$
> 
> ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> #2434: FILE: drivers/media/radio/si4713/si4713.c:20:
> + * along with this program; if not, write to the Free Software$
> 
> ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> #2435: FILE: drivers/media/radio/si4713/si4713.c:21:
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$
> 
> WARNING: please, no space before tabs
> #2473: FILE: drivers/media/radio/si4713/si4713.c:59:
> +#define DEFAULT_PILOT_FREQUENCY ^I0x4A38$
> 
> WARNING: please, no space before tabs
> #2478: FILE: drivers/media/radio/si4713/si4713.c:64:
> +#define DEFAULT_ACOMP_THRESHOLD ^I(-0x28)$
> 
> WARNING: please, no space before tabs
> #2682: FILE: drivers/media/radio/si4713/si4713.c:268:
> +^I * ^I.First byte = 0$
> 
> WARNING: please, no space before tabs
> #2683: FILE: drivers/media/radio/si4713/si4713.c:269:
> +^I * ^I.Second byte = property's MSB$
> 
> WARNING: please, no space before tabs
> #2684: FILE: drivers/media/radio/si4713/si4713.c:270:
> +^I * ^I.Third byte = property's LSB$
> 
> WARNING: please, no space before tabs
> #2719: FILE: drivers/media/radio/si4713/si4713.c:305:
> +^I * ^I.First byte = 0$
> 
> WARNING: please, no space before tabs
> #2720: FILE: drivers/media/radio/si4713/si4713.c:306:
> +^I * ^I.Second byte = property's MSB$
> 
> WARNING: please, no space before tabs
> #2721: FILE: drivers/media/radio/si4713/si4713.c:307:
> +^I * ^I.Third byte = property's LSB$
> 
> WARNING: please, no space before tabs
> #2722: FILE: drivers/media/radio/si4713/si4713.c:308:
> +^I * ^I.Fourth byte = value's MSB$
> 
> WARNING: please, no space before tabs
> #2723: FILE: drivers/media/radio/si4713/si4713.c:309:
> +^I * ^I.Fifth byte = value's LSB$
> 
> WARNING: please, no space before tabs
> #2764: FILE: drivers/media/radio/si4713/si4713.c:350:
> +^I * ^I.First byte = Enabled interrupts and boot function$
> 
> WARNING: please, no space before tabs
> #2765: FILE: drivers/media/radio/si4713/si4713.c:351:
> +^I * ^I.Second byte = Input operation mode$
> 
> WARNING: please, no space before tabs
> #2913: FILE: drivers/media/radio/si4713/si4713.c:499:
> + * ^I^I^Ifrequency between 76 and 108 MHz in 10 kHz units and$
> 
> WARNING: please, no space before tabs
> #2914: FILE: drivers/media/radio/si4713/si4713.c:500:
> + * ^I^I^Isteps of 50 kHz.$
> 
> WARNING: please, no space before tabs
> #2923: FILE: drivers/media/radio/si4713/si4713.c:509:
> +^I * ^I.First byte = 0$
> 
> WARNING: please, no space before tabs
> #2924: FILE: drivers/media/radio/si4713/si4713.c:510:
> +^I * ^I.Second byte = frequency's MSB$
> 
> WARNING: please, no space before tabs
> #2925: FILE: drivers/media/radio/si4713/si4713.c:511:
> +^I * ^I.Third byte = frequency's LSB$
> 
> WARNING: please, no space before tabs
> #2953: FILE: drivers/media/radio/si4713/si4713.c:539:
> + * ^I^I^I1 dB units. A value of 0x00 indicates off. The command$
> 
> WARNING: please, no space before tabs
> #2954: FILE: drivers/media/radio/si4713/si4713.c:540:
> + * ^I^I^Ialso sets the antenna tuning capacitance. A value of 0$
> 
> WARNING: please, no space before tabs
> #2955: FILE: drivers/media/radio/si4713/si4713.c:541:
> + * ^I^I^Iindicates autotuning, and a value of 1 - 191 indicates$
> 
> WARNING: please, no space before tabs
> #2956: FILE: drivers/media/radio/si4713/si4713.c:542:
> + * ^I^I^Ia manual override, which results in a tuning$
> 
> WARNING: please, no space before tabs
> #2957: FILE: drivers/media/radio/si4713/si4713.c:543:
> + * ^I^I^Icapacitance of 0.25 pF x @antcap.$
> 
> WARNING: please, no space before tabs
> #2968: FILE: drivers/media/radio/si4713/si4713.c:554:
> +^I * ^I.First byte = 0$
> 
> WARNING: please, no space before tabs
> #2969: FILE: drivers/media/radio/si4713/si4713.c:555:
> +^I * ^I.Second byte = 0$
> 
> WARNING: please, no space before tabs
> #2970: FILE: drivers/media/radio/si4713/si4713.c:556:
> +^I * ^I.Third byte = power$
> 
> WARNING: please, no space before tabs
> #2971: FILE: drivers/media/radio/si4713/si4713.c:557:
> +^I * ^I.Fourth byte = antcap$
> 
> WARNING: please, no space before tabs
> #3000: FILE: drivers/media/radio/si4713/si4713.c:586:
> + * ^I^I^Ilevel in units of dBuV on the selected frequency.$
> 
> WARNING: please, no space before tabs
> #3001: FILE: drivers/media/radio/si4713/si4713.c:587:
> + * ^I^I^IThe Frequency must be between 76 and 108 MHz in 10 kHz$
> 
> WARNING: please, no space before tabs
> #3002: FILE: drivers/media/radio/si4713/si4713.c:588:
> + * ^I^I^Iunits and steps of 50 kHz. The command also sets the$
> 
> WARNING: please, no space before tabs
> #3003: FILE: drivers/media/radio/si4713/si4713.c:589:
> + * ^I^I^Iantenna^Ituning capacitance. A value of 0 means$
> 
> WARNING: please, no space before tabs
> #3004: FILE: drivers/media/radio/si4713/si4713.c:590:
> + * ^I^I^Iautotuning, and a value of 1 to 191 indicates manual$
> 
> WARNING: please, no space before tabs
> #3005: FILE: drivers/media/radio/si4713/si4713.c:591:
> + * ^I^I^Ioverride.$
> 
> WARNING: please, no space before tabs
> #3016: FILE: drivers/media/radio/si4713/si4713.c:602:
> +^I * ^I.First byte = 0$
> 
> WARNING: please, no space before tabs
> #3017: FILE: drivers/media/radio/si4713/si4713.c:603:
> +^I * ^I.Second byte = frequency's MSB$
> 
> WARNING: please, no space before tabs
> #3018: FILE: drivers/media/radio/si4713/si4713.c:604:
> +^I * ^I.Third byte = frequency's LSB$
> 
> WARNING: please, no space before tabs
> #3019: FILE: drivers/media/radio/si4713/si4713.c:605:
> +^I * ^I.Fourth byte = antcap$
> 
> WARNING: please, no space before tabs
> #3049: FILE: drivers/media/radio/si4713/si4713.c:635:
> + * ^I^I^Itx_tune_power commands. This command return the current$
> 
> WARNING: please, no space before tabs
> #3050: FILE: drivers/media/radio/si4713/si4713.c:636:
> + * ^I^I^Ifrequency, output voltage in dBuV, the antenna tunning$
> 
> WARNING: please, no space before tabs
> #3051: FILE: drivers/media/radio/si4713/si4713.c:637:
> + * ^I^I^Icapacitance value and the received noise level. The$
> 
> WARNING: please, no space before tabs
> #3052: FILE: drivers/media/radio/si4713/si4713.c:638:
> + * ^I^I^Icommand also clears the stcint interrupt bit when the$
> 
> WARNING: please, no space before tabs
> #3053: FILE: drivers/media/radio/si4713/si4713.c:639:
> + * ^I^I^Ifirst bit of its arguments is high.$
> 
> WARNING: please, no space before tabs
> #3068: FILE: drivers/media/radio/si4713/si4713.c:654:
> +^I * ^I.First byte = intack bit$
> 
> WARNING: quoted string split across lines
> #3087: FILE: drivers/media/radio/si4713/si4713.c:673:
> +		v4l2_dbg(1, debug, &sdev->sd, "%s: response: %d x 10 kHz "
> +				"(power %d, antcap %d, rnl %d)\n", __func__,
> 
> WARNING: quoted string split across lines
> #3129: FILE: drivers/media/radio/si4713/si4713.c:715:
> +		v4l2_dbg(1, debug, &sdev->sd, "%s: response: interrupts"
> +				" 0x%02x cb avail: %d cb used %d fifo avail"
> 
> WARNING: line over 80 characters
> #3250: FILE: drivers/media/radio/si4713/si4713.c:836:
> +		if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {
> 
> WARNING: line over 80 characters
> #3391: FILE: drivers/media/radio/si4713/si4713.c:977:
> +static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);
> 
> WARNING: line over 80 characters
> #3392: FILE: drivers/media/radio/si4713/si4713.c:978:
> +static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);
> 
> WARNING: line over 80 characters
> #3509: FILE: drivers/media/radio/si4713/si4713.c:1095:
> +				sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);
> 
> WARNING: line over 80 characters
> #3518: FILE: drivers/media/radio/si4713/si4713.c:1104:
> +			ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,
> 
> WARNING: line over 80 characters
> #3535: FILE: drivers/media/radio/si4713/si4713.c:1121:
> +				ret = si4713_read_property(sdev, property, &val);
> 
> WARNING: line over 80 characters
> #3636: FILE: drivers/media/radio/si4713/si4713.c:1222:
> +static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)
> 
> WARNING: line over 80 characters
> #3706: FILE: drivers/media/radio/si4713/si4713.c:1292:
> +static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
> 
> WARNING: sizeof *sdev should be sizeof(*sdev)
> #3762: FILE: drivers/media/radio/si4713/si4713.c:1348:
> +	sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
> 
> WARNING: line over 80 characters
> #3820: FILE: drivers/media/radio/si4713/si4713.c:1406:
> +			V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);
> 
> WARNING: line over 80 characters
> #3837: FILE: drivers/media/radio/si4713/si4713.c:1423:
> +			V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,
> 
> WARNING: line over 80 characters
> #3843: FILE: drivers/media/radio/si4713/si4713.c:1429:
> +	sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
> 
> WARNING: line over 80 characters
> #3860: FILE: drivers/media/radio/si4713/si4713.c:1446:
> +			V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);
> 
> total: 6 errors, 60 warnings, 2101 lines checked
> 
> Your patch has style problems, please review.
> 
> If any of these errors are false positives, please report
> them to the maintainer, see CHECKPATCH in MAINTAINERS.
> 
> 
> 


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used
  2013-12-03 15:35     ` Mauro Carvalho Chehab
@ 2013-12-03 17:06       ` Hans Verkuil
       [not found]         ` <1386129496.79520.YahooMailNeo@web190906.mail.sg3.yahoo.com>
  0 siblings, 1 reply; 31+ messages in thread
From: Hans Verkuil @ 2013-12-03 17:06 UTC (permalink / raw)
  To: Mauro Carvalho Chehab; +Cc: Dinesh Ram, linux-media, edubezval, dinesh.ram086

On 12/03/2013 04:35 PM, Mauro Carvalho Chehab wrote:
> Em Tue, 15 Oct 2013 17:24:38 +0200
> Dinesh Ram <dinesh.ram@cern.ch> escreveu:
> 
>> Checks have been introduced at several places in the code to test if an interrupt is set or not.
>> For devices which do not use the interrupt, to get a valid response, within a specified timeout,
>> the device is polled instead.
>>
>> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
>> ---
>>  drivers/media/radio/si4713/si4713.c |  108 +++++++++++++++++++++--------------
>>  1 file changed, 64 insertions(+), 44 deletions(-)
>>
>> diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
>> index ac727e3..24ae41d 100644
>> --- a/drivers/media/radio/si4713/si4713.c
>> +++ b/drivers/media/radio/si4713/si4713.c
>> @@ -27,11 +27,11 @@
>>  #include <linux/i2c.h>
>>  #include <linux/slab.h>
>>  #include <linux/gpio.h>
>> -#include <linux/regulator/consumer.h>
>>  #include <linux/module.h>
>>  #include <media/v4l2-device.h>
>>  #include <media/v4l2-ioctl.h>
>>  #include <media/v4l2-common.h>
>> +#include <linux/regulator/consumer.h>
>>  
>>  #include "si4713.h"
>>  
>> @@ -213,6 +213,7 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
>>  				u8 response[], const int respn, const int usecs)
>>  {
>>  	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
>> +	unsigned long until_jiffies;
>>  	u8 data1[MAX_ARGS + 1];
>>  	int err;
>>  
>> @@ -228,30 +229,39 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
>>  	if (err != argn + 1) {
>>  		v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
>>  			command);
>> -		return (err > 0) ? -EIO : err;
>> +		return err < 0 ? err : -EIO;
>>  	}
>>  
>> +	until_jiffies = jiffies + usecs_to_jiffies(usecs) + 1;
>> +
>>  	/* Wait response from interrupt */
>> -	if (!wait_for_completion_timeout(&sdev->work,
>> +	if (client->irq) {
>> +		if (!wait_for_completion_timeout(&sdev->work,
>>  				usecs_to_jiffies(usecs) + 1))
>> -		v4l2_warn(&sdev->sd,
>> +			v4l2_warn(&sdev->sd,
>>  				"(%s) Device took too much time to answer.\n",
>>  				__func__);
>> -
>> -	/* Then get the response */
>> -	err = i2c_master_recv(client, response, respn);
>> -	if (err != respn) {
>> -		v4l2_err(&sdev->sd,
>> -			"Error while reading response for command 0x%02x\n",
>> -			command);
>> -		return (err > 0) ? -EIO : err;
>>  	}
>>  
>> -	DBG_BUFFER(&sdev->sd, "Response", response, respn);
>> -	if (check_command_failed(response[0]))
>> -		return -EBUSY;
>> +	do {
>> +		err = i2c_master_recv(client, response, respn);
>> +		if (err != respn) {
>> +			v4l2_err(&sdev->sd,
>> +				"Error %d while reading response for command 0x%02x\n",
>> +				err, command);
>> +			return err < 0 ? err : -EIO;
>> +		}
>> +
>> +		DBG_BUFFER(&sdev->sd, "Response", response, respn);
>> +		if (!check_command_failed(response[0]))
>> +			return 0;
>>  
>> -	return 0;
>> +		if (client->irq)
>> +			return -EBUSY;
>> +		msleep(1);
>> +	} while (jiffies <= until_jiffies);
> 
> This could result on an endless loop due to the limited space for jiffies.
> You should, instead, use the proper macros (time_after, time_before, ...).

True. Can this be done as a separate follow-up patch? I'd really like to get this
driver merged, it's been sitting here for ages.

Dinesh, can you have a go at this?

Regards,

	Hans

> 
>> +
>> +	return -EBUSY;
>>  }
>>  
>>  /*
>> @@ -344,14 +354,15 @@ static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
>>   */
>>  static int si4713_powerup(struct si4713_device *sdev)
>>  {
>> +	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
>>  	int err;
>>  	u8 resp[SI4713_PWUP_NRESP];
>>  	/*
>>  	 * 	.First byte = Enabled interrupts and boot function
>>  	 * 	.Second byte = Input operation mode
>>  	 */
>> -	const u8 args[SI4713_PWUP_NARGS] = {
>> -		SI4713_PWUP_CTSIEN | SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
>> +	u8 args[SI4713_PWUP_NARGS] = {
>> +		SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
>>  		SI4713_PWUP_OPMOD_ANALOG,
>>  	};
>>  
>> @@ -369,6 +380,9 @@ static int si4713_powerup(struct si4713_device *sdev)
>>  		gpio_set_value(sdev->gpio_reset, 1);
>>  	}
>>  
>> +	if (client->irq)
>> +		args[0] |= SI4713_PWUP_CTSIEN;
>> +
>>  	err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
>>  					args, ARRAY_SIZE(args),
>>  					resp, ARRAY_SIZE(resp),
>> @@ -380,7 +394,8 @@ static int si4713_powerup(struct si4713_device *sdev)
>>  		v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
>>  		sdev->power_state = POWER_ON;
>>  
>> -		err = si4713_write_property(sdev, SI4713_GPO_IEN,
>> +		if (client->irq)
>> +			err = si4713_write_property(sdev, SI4713_GPO_IEN,
>>  						SI4713_STC_INT | SI4713_CTS);
>>  	} else {
>>  		if (gpio_is_valid(sdev->gpio_reset))
>> @@ -465,33 +480,39 @@ static int si4713_checkrev(struct si4713_device *sdev)
>>   */
>>  static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
>>  {
>> -	int err;
>> +	struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
>>  	u8 resp[SI4713_GET_STATUS_NRESP];
>> +	unsigned long start_jiffies = jiffies;
>> +	int err;
>>  
>> -	/* Wait response from STC interrupt */
>> -	if (!wait_for_completion_timeout(&sdev->work,
>> -			usecs_to_jiffies(usecs) + 1))
>> +	if (client->irq &&
>> +	    !wait_for_completion_timeout(&sdev->work, usecs_to_jiffies(usecs) + 1))
>>  		v4l2_warn(&sdev->sd,
>> -			"%s: device took too much time to answer (%d usec).\n",
>> -				__func__, usecs);
>> -
>> -	/* Clear status bits */
>> -	err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
>> -					NULL, 0,
>> -					resp, ARRAY_SIZE(resp),
>> -					DEFAULT_TIMEOUT);
>> -
>> -	if (err < 0)
>> -		goto exit;
>> -
>> -	v4l2_dbg(1, debug, &sdev->sd,
>> -			"%s: status bits: 0x%02x\n", __func__, resp[0]);
>> -
>> -	if (!(resp[0] & SI4713_STC_INT))
>> -		err = -EIO;
>> -
>> -exit:
>> -	return err;
>> +			"(%s) Device took too much time to answer.\n", __func__);
>> +
>> +	for (;;) {
>> +		/* Clear status bits */
>> +		err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
>> +				NULL, 0,
>> +				resp, ARRAY_SIZE(resp),
>> +				DEFAULT_TIMEOUT);
>> +		/* The USB device returns errors when it waits for the
>> +		 * STC bit to be set. Hence polling */
>> +		if (err >= 0) {
>> +			v4l2_dbg(1, debug, &sdev->sd,
>> +				"%s: status bits: 0x%02x\n", __func__, resp[0]);
>> +
>> +			if (resp[0] & SI4713_STC_INT)
>> +				return 0;
>> +		}
>> +		if (jiffies_to_usecs(jiffies - start_jiffies) > usecs)
> 
> Same here: use the proper macro to check time after/before.
> 
>> +			return err < 0 ? err : -EIO;
>> +		/* We sleep here for 3 ms in order to avoid flooding the device
>> +		 * with USB requests. The si4713 USB driver was developed
>> +		 * by reverse engineering the Windows USB driver. The windows
>> +		 * driver also has a ~2.5 ms delay between responses. */
>> +		msleep(3);
>> +	}
>>  }
>>  
>>  /*
>> @@ -1024,7 +1045,6 @@ static int si4713_initialize(struct si4713_device *sdev)
>>  	if (rval < 0)
>>  		return rval;
>>  
>> -
>>  	sdev->frequency = DEFAULT_FREQUENCY;
>>  	sdev->stereo = 1;
>>  	sdev->tune_rnl = DEFAULT_TUNE_RNL;
> 
> 


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory
  2013-12-03 16:58     ` Hans Verkuil
@ 2013-12-04 17:41       ` Mauro Carvalho Chehab
  0 siblings, 0 replies; 31+ messages in thread
From: Mauro Carvalho Chehab @ 2013-12-04 17:41 UTC (permalink / raw)
  To: Hans Verkuil; +Cc: Dinesh Ram, linux-media, edubezval, dinesh.ram086

Em Tue, 03 Dec 2013 17:58:00 +0100
Hans Verkuil <hverkuil@xs4all.nl> escreveu:

> On 12/03/2013 04:39 PM, Mauro Carvalho Chehab wrote:
> > Em Tue, 15 Oct 2013 17:24:37 +0200
> > Dinesh Ram <dinesh.ram@cern.ch> escreveu:
> > 
> >> Added a new si4713 directory which will contain all si4713 related files.
> >> Also updated Makefile and Kconfig
> >>
> >> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
> >> ---
> >>  drivers/media/radio/Kconfig                        |   29 +-
> >>  drivers/media/radio/Makefile                       |    3 +-
> >>  drivers/media/radio/radio-si4713.c                 |  246 ----
> >>  drivers/media/radio/si4713-i2c.c                   | 1532 --------------------
> >>  drivers/media/radio/si4713-i2c.h                   |  238 ---
> >>  drivers/media/radio/si4713/Kconfig                 |   25 +
> >>  drivers/media/radio/si4713/Makefile                |    7 +
> >>  drivers/media/radio/si4713/radio-platform-si4713.c |  246 ++++
> >>  drivers/media/radio/si4713/si4713.c                | 1532 ++++++++++++++++++++
> >>  drivers/media/radio/si4713/si4713.h                |  238 +++
> >>  10 files changed, 2055 insertions(+), 2041 deletions(-)
> >>  delete mode 100644 drivers/media/radio/radio-si4713.c
> >>  delete mode 100644 drivers/media/radio/si4713-i2c.c
> >>  delete mode 100644 drivers/media/radio/si4713-i2c.h
> >>  create mode 100644 drivers/media/radio/si4713/Kconfig
> >>  create mode 100644 drivers/media/radio/si4713/Makefile
> >>  create mode 100644 drivers/media/radio/si4713/radio-platform-si4713.c
> >>  create mode 100644 drivers/media/radio/si4713/si4713.c
> >>  create mode 100644 drivers/media/radio/si4713/si4713.h
> >>
> > 
> > Please submit rename patches like that using "git show -M", in order to show only
> > what changed. 
> 
> My pull request for this patch series does this correctly.

Git pull does it automatically.

The thing is that patch review happens based on the email with the
patch sent to the ML. Reviewing a renaming patch on email, without the
-M requires someone to import the patch, and then see what happened.
So, this makes the review process slower.

> 
> > 
> > Btw, while here, I would expect a latter patch on this series fixing the
> > checkpatch.pl warnings/errors:
> 
> Why? Moving a source from one directory to another doesn't mean you have to clean up
> all the checkpatch warnings/errors. There is nothing special here that warrants the
> extra work.

This is not a requirement for the merge, but, since the code will be changed
a lot, and will be moved to some other place, this is the better moment to
cleanup those warnings/errors.

> 
> > 
> > WARNING: please write a paragraph that describes the config symbol fully
> > #23: FILE: drivers/media/radio/Kconfig:24:
> > +config RADIO_SI4713
> > 
> > ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> > #2181: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:19:
> > + * You should have received a copy of the GNU General Public License$
> > 
> > ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> > #2182: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:20:
> > + * along with this program; if not, write to the Free Software$
> > 
> > ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> > #2183: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:21:
> > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$
> 
> This check only appeared in 3.13, and this patch series is older than that.
> 
> Regards,
> 
> 	Hans
> 
> > 
> > WARNING: line over 80 characters
> > #2242: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:80:
> > +	capability->capabilities = capability->device_caps | V4L2_CAP_DEVICE_CAPS;
> > 
> > WARNING: line over 80 characters
> > #2365: FILE: drivers/media/radio/si4713/radio-platform-si4713.c:203:
> > +	if (video_register_device(&rsdev->radio_dev, VFL_TYPE_RADIO, radio_nr)) {
> > 
> > ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> > #2433: FILE: drivers/media/radio/si4713/si4713.c:19:
> > + * You should have received a copy of the GNU General Public License$
> > 
> > ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> > #2434: FILE: drivers/media/radio/si4713/si4713.c:20:
> > + * along with this program; if not, write to the Free Software$
> > 
> > ERROR: Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.
> > #2435: FILE: drivers/media/radio/si4713/si4713.c:21:
> > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA$
> > 
> > WARNING: please, no space before tabs
> > #2473: FILE: drivers/media/radio/si4713/si4713.c:59:
> > +#define DEFAULT_PILOT_FREQUENCY ^I0x4A38$
> > 
> > WARNING: please, no space before tabs
> > #2478: FILE: drivers/media/radio/si4713/si4713.c:64:
> > +#define DEFAULT_ACOMP_THRESHOLD ^I(-0x28)$
> > 
> > WARNING: please, no space before tabs
> > #2682: FILE: drivers/media/radio/si4713/si4713.c:268:
> > +^I * ^I.First byte = 0$
> > 
> > WARNING: please, no space before tabs
> > #2683: FILE: drivers/media/radio/si4713/si4713.c:269:
> > +^I * ^I.Second byte = property's MSB$
> > 
> > WARNING: please, no space before tabs
> > #2684: FILE: drivers/media/radio/si4713/si4713.c:270:
> > +^I * ^I.Third byte = property's LSB$
> > 
> > WARNING: please, no space before tabs
> > #2719: FILE: drivers/media/radio/si4713/si4713.c:305:
> > +^I * ^I.First byte = 0$
> > 
> > WARNING: please, no space before tabs
> > #2720: FILE: drivers/media/radio/si4713/si4713.c:306:
> > +^I * ^I.Second byte = property's MSB$
> > 
> > WARNING: please, no space before tabs
> > #2721: FILE: drivers/media/radio/si4713/si4713.c:307:
> > +^I * ^I.Third byte = property's LSB$
> > 
> > WARNING: please, no space before tabs
> > #2722: FILE: drivers/media/radio/si4713/si4713.c:308:
> > +^I * ^I.Fourth byte = value's MSB$
> > 
> > WARNING: please, no space before tabs
> > #2723: FILE: drivers/media/radio/si4713/si4713.c:309:
> > +^I * ^I.Fifth byte = value's LSB$
> > 
> > WARNING: please, no space before tabs
> > #2764: FILE: drivers/media/radio/si4713/si4713.c:350:
> > +^I * ^I.First byte = Enabled interrupts and boot function$
> > 
> > WARNING: please, no space before tabs
> > #2765: FILE: drivers/media/radio/si4713/si4713.c:351:
> > +^I * ^I.Second byte = Input operation mode$
> > 
> > WARNING: please, no space before tabs
> > #2913: FILE: drivers/media/radio/si4713/si4713.c:499:
> > + * ^I^I^Ifrequency between 76 and 108 MHz in 10 kHz units and$
> > 
> > WARNING: please, no space before tabs
> > #2914: FILE: drivers/media/radio/si4713/si4713.c:500:
> > + * ^I^I^Isteps of 50 kHz.$
> > 
> > WARNING: please, no space before tabs
> > #2923: FILE: drivers/media/radio/si4713/si4713.c:509:
> > +^I * ^I.First byte = 0$
> > 
> > WARNING: please, no space before tabs
> > #2924: FILE: drivers/media/radio/si4713/si4713.c:510:
> > +^I * ^I.Second byte = frequency's MSB$
> > 
> > WARNING: please, no space before tabs
> > #2925: FILE: drivers/media/radio/si4713/si4713.c:511:
> > +^I * ^I.Third byte = frequency's LSB$
> > 
> > WARNING: please, no space before tabs
> > #2953: FILE: drivers/media/radio/si4713/si4713.c:539:
> > + * ^I^I^I1 dB units. A value of 0x00 indicates off. The command$
> > 
> > WARNING: please, no space before tabs
> > #2954: FILE: drivers/media/radio/si4713/si4713.c:540:
> > + * ^I^I^Ialso sets the antenna tuning capacitance. A value of 0$
> > 
> > WARNING: please, no space before tabs
> > #2955: FILE: drivers/media/radio/si4713/si4713.c:541:
> > + * ^I^I^Iindicates autotuning, and a value of 1 - 191 indicates$
> > 
> > WARNING: please, no space before tabs
> > #2956: FILE: drivers/media/radio/si4713/si4713.c:542:
> > + * ^I^I^Ia manual override, which results in a tuning$
> > 
> > WARNING: please, no space before tabs
> > #2957: FILE: drivers/media/radio/si4713/si4713.c:543:
> > + * ^I^I^Icapacitance of 0.25 pF x @antcap.$
> > 
> > WARNING: please, no space before tabs
> > #2968: FILE: drivers/media/radio/si4713/si4713.c:554:
> > +^I * ^I.First byte = 0$
> > 
> > WARNING: please, no space before tabs
> > #2969: FILE: drivers/media/radio/si4713/si4713.c:555:
> > +^I * ^I.Second byte = 0$
> > 
> > WARNING: please, no space before tabs
> > #2970: FILE: drivers/media/radio/si4713/si4713.c:556:
> > +^I * ^I.Third byte = power$
> > 
> > WARNING: please, no space before tabs
> > #2971: FILE: drivers/media/radio/si4713/si4713.c:557:
> > +^I * ^I.Fourth byte = antcap$
> > 
> > WARNING: please, no space before tabs
> > #3000: FILE: drivers/media/radio/si4713/si4713.c:586:
> > + * ^I^I^Ilevel in units of dBuV on the selected frequency.$
> > 
> > WARNING: please, no space before tabs
> > #3001: FILE: drivers/media/radio/si4713/si4713.c:587:
> > + * ^I^I^IThe Frequency must be between 76 and 108 MHz in 10 kHz$
> > 
> > WARNING: please, no space before tabs
> > #3002: FILE: drivers/media/radio/si4713/si4713.c:588:
> > + * ^I^I^Iunits and steps of 50 kHz. The command also sets the$
> > 
> > WARNING: please, no space before tabs
> > #3003: FILE: drivers/media/radio/si4713/si4713.c:589:
> > + * ^I^I^Iantenna^Ituning capacitance. A value of 0 means$
> > 
> > WARNING: please, no space before tabs
> > #3004: FILE: drivers/media/radio/si4713/si4713.c:590:
> > + * ^I^I^Iautotuning, and a value of 1 to 191 indicates manual$
> > 
> > WARNING: please, no space before tabs
> > #3005: FILE: drivers/media/radio/si4713/si4713.c:591:
> > + * ^I^I^Ioverride.$
> > 
> > WARNING: please, no space before tabs
> > #3016: FILE: drivers/media/radio/si4713/si4713.c:602:
> > +^I * ^I.First byte = 0$
> > 
> > WARNING: please, no space before tabs
> > #3017: FILE: drivers/media/radio/si4713/si4713.c:603:
> > +^I * ^I.Second byte = frequency's MSB$
> > 
> > WARNING: please, no space before tabs
> > #3018: FILE: drivers/media/radio/si4713/si4713.c:604:
> > +^I * ^I.Third byte = frequency's LSB$
> > 
> > WARNING: please, no space before tabs
> > #3019: FILE: drivers/media/radio/si4713/si4713.c:605:
> > +^I * ^I.Fourth byte = antcap$
> > 
> > WARNING: please, no space before tabs
> > #3049: FILE: drivers/media/radio/si4713/si4713.c:635:
> > + * ^I^I^Itx_tune_power commands. This command return the current$
> > 
> > WARNING: please, no space before tabs
> > #3050: FILE: drivers/media/radio/si4713/si4713.c:636:
> > + * ^I^I^Ifrequency, output voltage in dBuV, the antenna tunning$
> > 
> > WARNING: please, no space before tabs
> > #3051: FILE: drivers/media/radio/si4713/si4713.c:637:
> > + * ^I^I^Icapacitance value and the received noise level. The$
> > 
> > WARNING: please, no space before tabs
> > #3052: FILE: drivers/media/radio/si4713/si4713.c:638:
> > + * ^I^I^Icommand also clears the stcint interrupt bit when the$
> > 
> > WARNING: please, no space before tabs
> > #3053: FILE: drivers/media/radio/si4713/si4713.c:639:
> > + * ^I^I^Ifirst bit of its arguments is high.$
> > 
> > WARNING: please, no space before tabs
> > #3068: FILE: drivers/media/radio/si4713/si4713.c:654:
> > +^I * ^I.First byte = intack bit$
> > 
> > WARNING: quoted string split across lines
> > #3087: FILE: drivers/media/radio/si4713/si4713.c:673:
> > +		v4l2_dbg(1, debug, &sdev->sd, "%s: response: %d x 10 kHz "
> > +				"(power %d, antcap %d, rnl %d)\n", __func__,
> > 
> > WARNING: quoted string split across lines
> > #3129: FILE: drivers/media/radio/si4713/si4713.c:715:
> > +		v4l2_dbg(1, debug, &sdev->sd, "%s: response: interrupts"
> > +				" 0x%02x cb avail: %d cb used %d fifo avail"
> > 
> > WARNING: line over 80 characters
> > #3250: FILE: drivers/media/radio/si4713/si4713.c:836:
> > +		if (t_index < (RDS_RADIOTEXT_INDEX_MAX * RDS_RADIOTEXT_BLK_SIZE)) {
> > 
> > WARNING: line over 80 characters
> > #3391: FILE: drivers/media/radio/si4713/si4713.c:977:
> > +static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f);
> > 
> > WARNING: line over 80 characters
> > #3392: FILE: drivers/media/radio/si4713/si4713.c:978:
> > +static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *);
> > 
> > WARNING: line over 80 characters
> > #3509: FILE: drivers/media/radio/si4713/si4713.c:1095:
> > +				sdev->tune_pwr_level->val, sdev->tune_ant_cap->val);
> > 
> > WARNING: line over 80 characters
> > #3518: FILE: drivers/media/radio/si4713/si4713.c:1104:
> > +			ret = si4713_choose_econtrol_action(sdev, ctrl->id, &bit,
> > 
> > WARNING: line over 80 characters
> > #3535: FILE: drivers/media/radio/si4713/si4713.c:1121:
> > +				ret = si4713_read_property(sdev, property, &val);
> > 
> > WARNING: line over 80 characters
> > #3636: FILE: drivers/media/radio/si4713/si4713.c:1222:
> > +static int si4713_s_modulator(struct v4l2_subdev *sd, const struct v4l2_modulator *vm)
> > 
> > WARNING: line over 80 characters
> > #3706: FILE: drivers/media/radio/si4713/si4713.c:1292:
> > +static int si4713_s_frequency(struct v4l2_subdev *sd, const struct v4l2_frequency *f)
> > 
> > WARNING: sizeof *sdev should be sizeof(*sdev)
> > #3762: FILE: drivers/media/radio/si4713/si4713.c:1348:
> > +	sdev = kzalloc(sizeof *sdev, GFP_KERNEL);
> > 
> > WARNING: line over 80 characters
> > #3820: FILE: drivers/media/radio/si4713/si4713.c:1406:
> > +			V4L2_CID_RDS_TX_RADIO_TEXT, 0, MAX_RDS_RADIO_TEXT, 32, 0);
> > 
> > WARNING: line over 80 characters
> > #3837: FILE: drivers/media/radio/si4713/si4713.c:1423:
> > +			V4L2_CID_AUDIO_COMPRESSION_THRESHOLD, MIN_ACOMP_THRESHOLD,
> > 
> > WARNING: line over 80 characters
> > #3843: FILE: drivers/media/radio/si4713/si4713.c:1429:
> > +	sdev->compression_release_time = v4l2_ctrl_new_std(hdl, &si4713_ctrl_ops,
> > 
> > WARNING: line over 80 characters
> > #3860: FILE: drivers/media/radio/si4713/si4713.c:1446:
> > +			V4L2_CID_TUNE_POWER_LEVEL, 0, 120, 1, DEFAULT_POWER_LEVEL);
> > 
> > total: 6 errors, 60 warnings, 2101 lines checked
> > 
> > Your patch has style problems, please review.
> > 
> > If any of these errors are false positives, please report
> > them to the maintainer, see CHECKPATCH in MAINTAINERS.
> > 
> > 
> > 
> 


-- 

Cheers,
Mauro

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used
       [not found]         ` <1386129496.79520.YahooMailNeo@web190906.mail.sg3.yahoo.com>
@ 2013-12-04 17:42           ` Mauro Carvalho Chehab
  2013-12-05  7:39           ` Hans Verkuil
  1 sibling, 0 replies; 31+ messages in thread
From: Mauro Carvalho Chehab @ 2013-12-04 17:42 UTC (permalink / raw)
  To: dinesh ram
  Cc: Hans Verkuil, Dinesh Ram, linux-media, edubezval, dinesh.ram086

Em Wed, 04 Dec 2013 11:58:16 +0800 (SGT)
dinesh ram <dino_mc4@yahoo.co.in> escreveu:

> Hello Mauro and Hans,
> 
> I agree with Hans that this driver has been sitting here for some time now.
> As stated, If this can be a separate follow-up patch, it would be great.
> 
> @Hans : Yes I can have a go at it and send you the changes to test against the hardware.
> But I wont be able to do it before next week.

It can be added on a separate patch, provided that it is on the same series.

Regards,
Mauro

> 
> Kind regards,
> Dinesh
> 
> On Tuesday, 3 December 2013 6:06 PM, Hans Verkuil <hverkuil@xs4all.nl> wrote:
> 
> On 12/03/2013 04:35 PM, Mauro Carvalho Chehab wrote:
> > Em Tue, 15 Oct 2013 17:24:38 +0200
> > Dinesh Ram <dinesh.ram@cern.ch> escreveu:
> > 
> >> Checks have been introduced at several places in the code to test if an interrupt is set or not.
> >> For devices which do not use the interrupt, to get a valid response, within a specified timeout,
> >> the device is polled instead.
> >>
> >> Signed-off-by: Dinesh Ram <dinesh.ram@cern.ch>
> >> ---
> >>  drivers/media/radio/si4713/si4713.c |  108 +++++++++++++++++++++--------------
> >>  1 file changed, 64 insertions(+), 44 deletions(-)
> >>
> >> diff --git a/drivers/media/radio/si4713/si4713.c b/drivers/media/radio/si4713/si4713.c
> >> index ac727e3..24ae41d 100644
> >> --- a/drivers/media/radio/si4713/si4713.c
> >> +++ b/drivers/media/radio/si4713/si4713.c
> >> @@ -27,11 +27,11 @@
> >>  #include <linux/i2c.h>
> >>  #include <linux/slab.h>
> >>  #include <linux/gpio.h>
> >> -#include <linux/regulator/consumer.h>
> >>  #include <linux/module.h>
> >>  #include <media/v4l2-device.h>
> >>  #include <media/v4l2-ioctl.h>
> >>  #include <media/v4l2-common.h>
> >> +#include <linux/regulator/consumer.h>
> >>  
> >>  #include "si4713.h"
> >>  
> >> @@ -213,6 +213,7 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
> >>                  u8 response[], const int respn, const int usecs)
> >>  {
> >>      struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
> >> +    unsigned long until_jiffies;
> >>      u8 data1[MAX_ARGS + 1];
> >>      int err;
> >>  
> >> @@ -228,30 +229,39 @@ static int si4713_send_command(struct si4713_device *sdev, const u8 command,
> >>      if (err != argn + 1) {
> >>          v4l2_err(&sdev->sd, "Error while sending command 0x%02x\n",
> >>              command);
> >> -        return (err > 0) ? -EIO : err;
> >> +        return err < 0 ? err : -EIO;
> >>      }
> >>  
> >> +    until_jiffies = jiffies + usecs_to_jiffies(usecs) + 1;
> >> +
> >>      /* Wait response from interrupt */
> >> -    if (!wait_for_completion_timeout(&sdev->work,
> >> +    if (client->irq) {
> >> +        if (!wait_for_completion_timeout(&sdev->work,
> >>                  usecs_to_jiffies(usecs) + 1))
> >> -        v4l2_warn(&sdev->sd,
> >> +            v4l2_warn(&sdev->sd,
> >>                  "(%s) Device took too much time to answer.\n",
> >>                  __func__);
> >> -
> >> -    /* Then get the response */
> >> -    err = i2c_master_recv(client, response, respn);
> >> -    if (err != respn) {
> >> -        v4l2_err(&sdev->sd,
> >> -            "Error while reading response for command 0x%02x\n",
> >> -            command);
> >> -        return (err > 0) ? -EIO : err;
> >>      }
> >>  
> >> -    DBG_BUFFER(&sdev->sd, "Response", response, respn);
> >> -    if (check_command_failed(response[0]))
> >> -        return -EBUSY;
> >> +    do {
> >> +        err = i2c_master_recv(client, response, respn);
> >> +        if (err != respn) {
> >> +            v4l2_err(&sdev->sd,
> >> +                "Error %d while reading response for command 0x%02x\n",
> >> +                err, command);
> >> +            return err < 0 ? err : -EIO;
> >> +        }
> >> +
> >> +        DBG_BUFFER(&sdev->sd, "Response", response, respn);
> >> +        if (!check_command_failed(response[0]))
> >> +            return 0;
> >>  
> >> -    return 0;
> >> +        if (client->irq)
> >> +            return -EBUSY;
> >> +        msleep(1);
> >> +    } while (jiffies <= until_jiffies);
> > 
> > This could result on an endless loop due to the limited space for jiffies.
> > You should, instead, use the proper macros (time_after, time_before, ...).
> 
> True. Can this be done as a separate follow-up patch? I'd really like to get this
> driver merged, it's been sitting here for ages.
> 
> Dinesh, can you have a go at this?
> 
> Regards,
> 
>     Hans
> 
> 
> > 
> >> +
> >> +    return -EBUSY;
> >>  }
> >>  
> >>  /*
> >> @@ -344,14 +354,15 @@ static int si4713_write_property(struct si4713_device *sdev, u16 prop, u16 val)
> >>   */
> >>  static int si4713_powerup(struct si4713_device *sdev)
> >>  {
> >> +    struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
> >>      int err;
> >>      u8 resp[SI4713_PWUP_NRESP];
> >>      /*
> >>       *     .First byte = Enabled interrupts and boot function
> >>       *     .Second byte = Input operation mode
> >>       */
> >> -    const u8 args[SI4713_PWUP_NARGS] = {
> >> -        SI4713_PWUP_CTSIEN | SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
> >> +    u8 args[SI4713_PWUP_NARGS] = {
> >> +        SI4713_PWUP_GPO2OEN | SI4713_PWUP_FUNC_TX,
> >>          SI4713_PWUP_OPMOD_ANALOG,
> >>      };
> >>  
> >> @@ -369,6 +380,9 @@ static int si4713_powerup(struct si4713_device *sdev)
> >>          gpio_set_value(sdev->gpio_reset, 1);
> >>      }
> >>  
> >> +    if (client->irq)
> >> +        args[0] |= SI4713_PWUP_CTSIEN;
> >> +
> >>      err = si4713_send_command(sdev, SI4713_CMD_POWER_UP,
> >>                      args, ARRAY_SIZE(args),
> >>                      resp, ARRAY_SIZE(resp),
> >> @@ -380,7 +394,8 @@ static int si4713_powerup(struct si4713_device *sdev)
> >>          v4l2_dbg(1, debug, &sdev->sd, "Device in power up mode\n");
> >>          sdev->power_state = POWER_ON;
> >>  
> >> -        err = si4713_write_property(sdev, SI4713_GPO_IEN,
> >> +        if (client->irq)
> >> +            err = si4713_write_property(sdev, SI4713_GPO_IEN,
> >>                          SI4713_STC_INT | SI4713_CTS);
> >>      } else {
> >>          if (gpio_is_valid(sdev->gpio_reset))
> >> @@ -465,33 +480,39 @@ static int si4713_checkrev(struct si4713_device *sdev)
> >>   */
> >>  static int si4713_wait_stc(struct si4713_device *sdev, const int usecs)
> >>  {
> >> -    int err;
> >> +    struct i2c_client *client = v4l2_get_subdevdata(&sdev->sd);
> >>      u8 resp[SI4713_GET_STATUS_NRESP];
> >> +    unsigned long start_jiffies = jiffies;
> >> +    int err;
> >>  
> >> -    /* Wait response from STC interrupt */
> >> -    if (!wait_for_completion_timeout(&sdev->work,
> >> -            usecs_to_jiffies(usecs) + 1))
> >> +    if (client->irq &&
> >> +        !wait_for_completion_timeout(&sdev->work, usecs_to_jiffies(usecs) + 1))
> >>          v4l2_warn(&sdev->sd,
> >> -            "%s: device took too much time to answer (%d usec).\n",
> >> -                __func__, usecs);
> >> -
> >> -    /* Clear status bits */
> >> -    err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
> >> -                    NULL, 0,
> >> -                    resp, ARRAY_SIZE(resp),
> >> -                    DEFAULT_TIMEOUT);
> >> -
> >> -    if (err < 0)
> >> -        goto exit;
> >> -
> >> -    v4l2_dbg(1, debug, &sdev->sd,
> >> -            "%s: status bits: 0x%02x\n", __func__, resp[0]);
> >> -
> >> -    if (!(resp[0] & SI4713_STC_INT))
> >> -        err = -EIO;
> >> -
> >> -exit:
> >> -    return err;
> >> +            "(%s) Device took too much time to answer.\n", __func__);
> >> +
> >> +    for (;;) {
> >> +        /* Clear status bits */
> >> +        err = si4713_send_command(sdev, SI4713_CMD_GET_INT_STATUS,
> >> +                NULL, 0,
> >> +                resp, ARRAY_SIZE(resp),
> >> +                DEFAULT_TIMEOUT);
> >> +        /* The USB device returns errors when it waits for the
> >> +         * STC bit to be set. Hence polling */
> >> +        if (err >= 0) {
> >> +            v4l2_dbg(1, debug, &sdev->sd,
> >> +                "%s: status bits: 0x%02x\n", __func__, resp[0]);
> >> +
> >> +            if (resp[0] & SI4713_STC_INT)
> >> +                return 0;
> >> +        }
> >> +        if (jiffies_to_usecs(jiffies - start_jiffies) > usecs)
> > 
> > Same here: use the proper macro to check time after/before.
> > 
> >> +            return err < 0 ? err : -EIO;
> >> +        /* We sleep here for 3 ms in order to avoid flooding the device
> >> +         * with USB requests. The si4713 USB driver was developed
> >> +         * by reverse engineering the Windows USB driver. The windows
> >> +         * driver also has a ~2.5 ms delay between responses. */
> >> +        msleep(3);
> >> +    }
> >>  }
> >>  
> >>  /*
> >> @@ -1024,7 +1045,6 @@ static int si4713_initialize(struct si4713_device *sdev)
> >>      if (rval < 0)
> >>          return rval;
> >>  
> >> -
> >>      sdev->frequency = DEFAULT_FREQUENCY;
> >>      sdev->stereo = 1;
> >>      sdev->tune_rnl = DEFAULT_TUNE_RNL;
> > 
> > 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-media" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


-- 

Cheers,
Mauro

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used
       [not found]         ` <1386129496.79520.YahooMailNeo@web190906.mail.sg3.yahoo.com>
  2013-12-04 17:42           ` Mauro Carvalho Chehab
@ 2013-12-05  7:39           ` Hans Verkuil
  1 sibling, 0 replies; 31+ messages in thread
From: Hans Verkuil @ 2013-12-05  7:39 UTC (permalink / raw)
  To: dinesh ram
  Cc: Mauro Carvalho Chehab, Dinesh Ram, linux-media, edubezval, dinesh.ram086

Hi Dinesh,

On 12/04/2013 04:58 AM, dinesh ram wrote:
> Hello Mauro and Hans,
> 
> I agree with Hans that this driver has been sitting here for some time now.
> As stated, If this can be a separate follow-up patch, it would be great.
> 
> @Hans : Yes I can have a go at it and send you the changes to test against the hardware.
> But I wont be able to do it before next week.

I'll have time tomorrow, so I'll make the follow-up patch. This is taking way too
long, so I want to push this forward as quickly as I can. Normally this never takes
so much time...

Regards,

	Hans


^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2013-12-05  7:40 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-15 15:24 [Review Patch 0/9] si4713 usb device driver Dinesh Ram
2013-10-15 15:24 ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Dinesh Ram
2013-10-15 15:24   ` [REVIEW PATCH 2/9] si4713 : Modified i2c driver to handle cases where interrupts are not used Dinesh Ram
2013-12-03 15:35     ` Mauro Carvalho Chehab
2013-12-03 17:06       ` Hans Verkuil
     [not found]         ` <1386129496.79520.YahooMailNeo@web190906.mail.sg3.yahoo.com>
2013-12-04 17:42           ` Mauro Carvalho Chehab
2013-12-05  7:39           ` Hans Verkuil
2013-10-15 15:24   ` [REVIEW PATCH 3/9] si4713 : Reorganized includes in si4713.c/h Dinesh Ram
2013-10-15 15:24   ` [REVIEW PATCH 4/9] si4713 : Bug fix for si4713_tx_tune_power() method in the i2c driver Dinesh Ram
2013-10-15 15:24   ` [REVIEW PATCH 5/9] si4713 : HID blacklist Si4713 USB development board Dinesh Ram
2013-10-15 15:24   ` [REVIEW PATCH 6/9] si4713 : Added the USB driver for Si4713 Dinesh Ram
2013-11-05 14:18     ` edubezval
2013-11-07  7:40       ` Hans Verkuil
2013-11-11 12:34         ` edubezval
2013-11-18 14:47       ` edubezval
2013-10-15 15:24   ` [REVIEW PATCH 7/9] si4713 : Added MAINTAINERS entry for radio-usb-si4713 driver Dinesh Ram
2013-10-15 15:24   ` [REVIEW PATCH 8/9] si4713: move supply list to si4713_platform_data Dinesh Ram
2013-11-04 14:07     ` edubezval
2013-11-05  8:38       ` Hans Verkuil
2013-11-05 14:14         ` edubezval
2013-10-15 15:24   ` [REVIEW PATCH 9/9] si4713: si4713_set_rds_radio_text overwrites terminating \0 Dinesh Ram
2013-12-03 15:39   ` [REVIEW PATCH 1/9] si4713 : Reorganized drivers/media/radio directory Mauro Carvalho Chehab
     [not found]     ` <CAP_RhzeRgLir1FGL6UN2-yXXaS-1knsS2BP20MjfMJRAEyDqeg@mail.gmail.com>
2013-12-03 16:06       ` FW: " Dinesh Ram
2013-12-03 16:58     ` Hans Verkuil
2013-12-04 17:41       ` Mauro Carvalho Chehab
2013-10-15 17:37 ` [Review Patch 0/9] si4713 usb device driver edubezval
2013-11-04  9:33   ` Hans Verkuil
2013-11-04 14:09     ` edubezval
2013-11-04 14:13       ` Hans Verkuil
     [not found]         ` <CAP_RhzfWKc8y27uU4VXFu6cAt87NvO=BnLNq9WeGG_kpxihTKQ@mail.gmail.com>
2013-11-04 14:39           ` edubezval
2013-11-18 14:31 ` edubezval

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).