FM Transmitter (si4713) and another changes
v10 cover FM Transmitter (si4713) and another changes
Hello guys,
Here is the version 10 of fm transmitter work.
The difference between previous version is that now it is
based only on http://www.linuxtv.org/hg/~hverkuil/v4l-dvb-strctrl,
which contains the string support for our extended control api.
Also, I've added a new extended control on the fm tx class:
rds deviation. This control was missing from previous versions. It used to be set to default value. But I believe it would be good to have it configurable.
Another minor change is about s_frequency call back. In the conversion from sysfs to extended control only interfaces, I forgot to keep the range check. That was missing on version #9. Now it is back.
I've removed the v4l2-ctl changes, as they are no longer needed due to last re-factoring which happened there. All ext controls seams to work with v4l2-ctl, including string ones.
I've also updated the documentation, including the new control and the references for character encoding of ps name and radio text.
Besides that, every thing is the same.
There is a needed change in v4l2-ctl regarding set/get frequency. Nowadays, v4l2-ctl queries only the tuner and forgets about modulators. That I will send an initial proposal in a separated patch (I believe it is not related to this series anymore).
BR,
Eduardo Valentin (8):
v4l2-subdev.h: Add g_modulator callbacks to subdev api
v4l2: video device: Add V4L2_CTRL_CLASS_FM_TX controls
v4l2: video device: Add FM_TX controls default configurations
v4l2-spec: Add documentation description for FM TX extended control
class
FMTx: si4713: Add files to add radio interface for si4713
FMTx: si4713: Add files to handle si4713 i2c device
FMTx: si4713: Add Kconfig and Makefile entries
FMTx: si4713: Add document file
linux/Documentation/video4linux/si4713.txt | 175 +++ linux/drivers/media/radio/Kconfig | 22 + linux/drivers/media/radio/Makefile | 2 + linux/drivers/media/radio/radio-si4713.c | 367 +++++ linux/drivers/media/radio/si4713-i2c.c | 2034 ++++++++++++++++++++++++++++ linux/drivers/media/radio/si4713-i2c.h | 228 ++++ linux/drivers/media/video/v4l2-common.c | 63 +- linux/include/linux/videodev2.h | 34 + linux/include/media/radio-si4713.h | 30 + linux/include/media/si4713.h | 49 + linux/include/media/v4l2-subdev.h | 2 + v4l2-spec/Makefile | 1 + v4l2-spec/controls.sgml | 210 +++ 13 files changed, 3216 insertions(+), 1 deletions(-) create mode 100644 linux/Documentation/video4linux/si4713.txt create mode 100644 linux/drivers/media/radio/radio-si4713.c create mode 100644 linux/drivers/media/radio/si4713-i2c.c create mode 100644 linux/drivers/media/radio/si4713-i2c.h create mode 100644 linux/include/media/radio-si4713.h create mode 100644 linux/include/media/si4713.h
PATCH v10 1/8 v4l2-subdev.h: Add g_modulator callbacks to subdev api
--- linux/include/media/v4l2-subdev.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
linux/include/media/v4l2-subdev.h +2 -0
@@ -137,6 +137,8 @@ struct v4l2_subdev_tuner_ops {int (*g_frequency)(struct v4l2_subdev *sd,struct v4l2_frequency *freq);int (*g_tuner)(struct v4l2_subdev *sd,struct v4l2_tuner *vt);int (*s_tuner)(struct v4l2_subdev *sd,struct v4l2_tuner *vt); +int (*g_modulator)(struct v4l2_subdev *sd,struct v4l2_modulator *vm); +int (*s_modulator)(struct v4l2_subdev *sd,struct v4l2_modulator *vm);int (*s_type_addr)(struct v4l2_subdev *sd,struct tuner_setup *type);int (*s_config)(struct v4l2_subdev *sd,const struct v4l2_priv_tun_config *config);int (*s_standby)(struct v4l2_subdev *sd);
Signature · 1 line
1.6.2.GIT
PATCH v10 2/8 v4l2: video device: Add V4L2_CTRL_CLASS_FM_TX controls
This patch adds a new class of extended controls. This class is intended to support FM Radio Modulators properties such as:
rds, audio limiters, audio compression, pilot tone generation, tuning power levels and preemphasis properties.
--- linux/include/linux/videodev2.h | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-)
linux/include/linux/videodev2.h +34 -0
@@ -817,6 +817,7 @@ struct v4l2_ext_controls {#define V4L2_CTRL_CLASS_USER 0x00980000/* Old-style 'user' controls */ #define V4L2_CTRL_CLASS_MPEG 0x00990000/* MPEG-compression controls */ #define V4L2_CTRL_CLASS_CAMERA 0x009a0000/* Camera class controls */ +#define V4L2_CTRL_CLASS_FM_TX 0x009b0000/* FM Modulator control class */ #define V4L2_CTRL_ID_MASK (0x0fffffff)#define V4L2_CTRL_ID2CLASS (id) ((id) & 0x0fff0000UL)
@@ -1156,6 +1157,39 @@ enum v4l2_exposure_auto_type {#define V4L2_CID_PRIVACY (V4L2_CID_CAMERA_CLASS_BASE+16) +/* FM Modulator class control IDs */ +#define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900) +#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1) + +#define V4L2_CID_RDS_TX_PI (V4L2_CID_FM_TX_CLASS_BASE + 1) +#define V4L2_CID_RDS_TX_PTY (V4L2_CID_FM_TX_CLASS_BASE + 2) +#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 3) +#define V4L2_CID_RDS_TX_PS_NAME (V4L2_CID_FM_TX_CLASS_BASE + 4) +#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 5) + +#define V4L2_CID_AUDIO_LIMITER_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 6) +#define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 7) +#define V4L2_CID_AUDIO_LIMITER_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 8) + +#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 9) +#define V4L2_CID_AUDIO_COMPRESSION_GAIN (V4L2_CID_FM_TX_CLASS_BASE + 10) +#define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (V4L2_CID_FM_TX_CLASS_BASE + 11) +#define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 12) +#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 13) + +#define V4L2_CID_PILOT_TONE_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 14) +#define V4L2_CID_PILOT_TONE_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 15) +#define V4L2_CID_PILOT_TONE_FREQUENCY (V4L2_CID_FM_TX_CLASS_BASE + 16) + +#define V4L2_CID_FM_TX_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 17) +enum v4l2_preemphasis { +V4L2_PREEMPHASIS_DISABLED =0 , + V4L2_PREEMPHASIS_50_uS =1 , + V4L2_PREEMPHASIS_75_uS =2 , +}; +#define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 18) +#define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 19) +/* * T U N I N G */
Signature · 1 line
1.6.2.GIT
PATCH v10 3/8 v4l2: video device: Add FM_TX controls default configurations
--- linux/drivers/media/video/v4l2-common.c | 63 ++++++++++++++++++++++++++++++- 1 files changed, 62 insertions(+), 1 deletions(-)
linux/drivers/media/video/v4l2-common.c +62 -1
@@ -343,6 +343,12 @@ const char **v4l2_ctrl_get_menu(u32 id)"Sepia" , NULL }; +static const char *fm_tx_preemphasis[] = { +"No preemphasis" , +"50 useconds" , +"75 useconds" , +NULL , + };switch (id) {case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ :
@@ -381,6 +387,8 @@ const char **v4l2_ctrl_get_menu(u32 id)return camera_exposure_auto;case V4L2_CID_COLORFX :return colorfx; +case V4L2_CID_FM_TX_PREEMPHASIS : +return fm_tx_preemphasis;default :return NULL ; }
@@ -479,6 +487,28 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_ZOOM_CONTINUOUS :return "Zoom, Continuous" ;case V4L2_CID_PRIVACY :return "Privacy" ; +/* FM Radio Modulator control */ +case V4L2_CID_FM_TX_CLASS :return "FM Radio Modulator Controls" ; +case V4L2_CID_RDS_TX_PI :return "RDS Program ID" ; +case V4L2_CID_RDS_TX_PTY :return "RDS Program Type" ; +case V4L2_CID_RDS_TX_DEVIATION :return "RDS Signal Deviation" ; +case V4L2_CID_RDS_TX_PS_NAME :return "RDS PS Name" ; +case V4L2_CID_RDS_TX_RADIO_TEXT :return "RDS Radio Text" ; +case V4L2_CID_AUDIO_LIMITER_ENABLED :return "Audio Limiter Feature Enabled" ; +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME :return "Audio Limiter Release Time" ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION :return "Audio Limiter Deviation" ; +case V4L2_CID_AUDIO_COMPRESSION_ENABLED :return "Audio Compression Feature Enabled" ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN :return "Audio Compression Gain" ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD :return "Audio Compression Threshold" ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME :return "Audio Compression Attack Time" ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME :return "Audio Compression Release Time" ; +case V4L2_CID_PILOT_TONE_ENABLED :return "Pilot Tone Feature Enabled" ; +case V4L2_CID_PILOT_TONE_DEVIATION :return "Pilot Tone Deviation" ; +case V4L2_CID_PILOT_TONE_FREQUENCY :return "Pilot Tone Frequency" ; +case V4L2_CID_FM_TX_PREEMPHASIS :return "Pre-emphasis settings" ; +case V4L2_CID_TUNE_POWER_LEVEL :return "Tune Power Level" ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR :return "Tune Antenna Capacitor" ; +default :return NULL ; }
@@ -500,7 +530,18 @@ EXPORT_SYMBOL(v4l2_ctrl_is_value64);* This information is used inside v4l2_compat_ioctl32. */ int v4l2_ctrl_is_pointer (u32 id) { -return 0 ; +int is_pointer; + +switch (id) { +case V4L2_CID_RDS_TX_PS_NAME : +case V4L2_CID_RDS_TX_RADIO_TEXT : + is_pointer =1 ; +break ; +default : + is_pointer =0 ; + } + +return is_pointer; }EXPORT_SYMBOL (v4l2_ctrl_is_pointer);
@@ -530,6 +571,9 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 stecase V4L2_CID_EXPOSURE_AUTO_PRIORITY :case V4L2_CID_FOCUS_AUTO :case V4L2_CID_PRIVACY : +case V4L2_CID_AUDIO_LIMITER_ENABLED : +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : +case V4L2_CID_PILOT_TONE_ENABLED : qctrl->type =V4L2_CTRL_TYPE_BOOLEAN ; min =0 ; max = step =1 ;
@@ -558,12 +602,18 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 stecase V4L2_CID_MPEG_STREAM_VBI_FMT :case V4L2_CID_EXPOSURE_AUTO :case V4L2_CID_COLORFX : +case V4L2_CID_FM_TX_PREEMPHASIS : qctrl->type =V4L2_CTRL_TYPE_MENU ; step =1 ;break ; +case V4L2_CID_RDS_TX_PS_NAME : +case V4L2_CID_RDS_TX_RADIO_TEXT : + qctrl->type =V4L2_CTRL_TYPE_STRING ; +break ;case V4L2_CID_USER_CLASS :case V4L2_CID_CAMERA_CLASS :case V4L2_CID_MPEG_CLASS : +case V4L2_CID_FM_TX_CLASS : qctrl->type =V4L2_CTRL_TYPE_CTRL_CLASS ; qctrl->flags |=V4L2_CTRL_FLAG_READ_ONLY ; min = max = step = def =0 ;
@@ -592,6 +642,17 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 stecase V4L2_CID_BLUE_BALANCE :case V4L2_CID_GAMMA :case V4L2_CID_SHARPNESS : +case V4L2_CID_RDS_TX_DEVIATION : +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : +case V4L2_CID_AUDIO_LIMITER_DEVIATION : +case V4L2_CID_AUDIO_COMPRESSION_GAIN : +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : +case V4L2_CID_PILOT_TONE_DEVIATION : +case V4L2_CID_PILOT_TONE_FREQUENCY : +case V4L2_CID_TUNE_POWER_LEVEL : +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : qctrl->flags |=V4L2_CTRL_FLAG_SLIDER ;break ;case V4L2_CID_PAN_RELATIVE :
Signature · 1 line
1.6.2.GIT
PATCH v10 4/8 v4l2-spec: Add documentation description for FM TX extended control class
This single patch adds documentation description for FM Modulator (FM TX) Extended Control Class and its Control IDs. The text was added under "Extended Controls" section.
--- v4l2-spec/Makefile | 1 + v4l2-spec/controls.sgml | 210 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 211 insertions(+), 0 deletions(-)
v4l2-spec/Makefile +1 -0
@@ -243,6 +243,7 @@ ENUMS = \ v4l2_power_line_frequency \ v4l2_priority \ v4l2_tuner_type \ + v4l2_preemphasis \ STRUCTS = \ v4l2_audio \
v4l2-spec/controls.sgml +210 -0
222 lines not on this page · raw message
Signature · 1 line
1.6.2.GIT
PATCH v10 5/8 FMTx: si4713: Add files to add radio interface for si4713
This patch adds files which creates the radio interface for si4713 FM transmitter (modulator) devices.
In order to do the real access to device registers, this driver uses the v4l2 subdev interface exported by si4713 i2c driver.
--- linux/drivers/media/radio/radio-si4713.c | 367 ++++++++++++++++++++++++++++++ linux/include/media/radio-si4713.h | 30 +++ 2 files changed, 397 insertions(+), 0 deletions(-) create mode 100644 linux/drivers/media/radio/radio-si4713.c create mode 100644 linux/include/media/radio-si4713.h
linux/drivers/media/radio/radio-si4713.c new file +367 -0
@@ -0,0 +1,367 @@ +/* +* 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 <[email protected]> +* +* 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/version.h> +#include <linux/platform_device.h> +#include <linux/i2c.h> +#include <linux/videodev2.h> +#include <media/v4l2-device.h> +#include <media/v4l2-common.h> +#include <media/v4l2-ioctl.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" ); +MODULE_AUTHOR ("Eduardo Valentin <[email protected]>" ); +MODULE_DESCRIPTION ("Platform driver for Si4713 FM Radio Transmitter" ); +MODULE_VERSION ("0.0.1" ); + +/* Driver state struct */ +struct radio_si4713_device { +struct v4l2_device v4l2_dev; +struct video_device *radio_dev; +}; + +/* radio_si4713_fops - file operations interface */ +static const struct v4l2_file_operations radio_si4713_fops = { + .owner =THIS_MODULE , + .ioctl = video_ioctl2, +}; + +/* Video4Linux Interface */ +static int radio_si4713_fill_audout (struct v4l2_audioout *vao) +{ +/* TODO: check presence of audio output */ +strlcpy (vao->name,"FM Modulator Audio Out" ,32 ); + +return 0 ; +} + +static int radio_si4713_enumaudout (struct file *file,void *priv, +struct v4l2_audioout *vao) +{ +return radio_si4713_fill_audout (vao); +} + +static int radio_si4713_g_audout (struct file *file,void *priv, +struct v4l2_audioout *vao) +{ +int rval =radio_si4713_fill_audout (vao); + + vao->index =0 ; + +return rval; +} + +static int radio_si4713_s_audout (struct file *file,void *priv, +struct v4l2_audioout *vao) +{ +return vao->index ? -EINVAL :0 ; +} + +/* radio_si4713_querycap - query device capabilities */ +static int radio_si4713_querycap (struct file *file,void *priv, +struct v4l2_capability *capability) +{ +struct radio_si4713_device *rsdev; + + rsdev =video_get_drvdata (video_devdata (file)); + +strlcpy (capability->driver,"radio-si4713" ,sizeof (capability->driver)); +strlcpy (capability->card,"Silicon Labs Si4713 Modulator" , +sizeof (capability->card)); + capability->capabilities =V4L2_CAP_MODULATOR |V4L2_CAP_RDS_OUTPUT ; + +return 0 ; +} + +/* radio_si4713_queryctrl - enumerate control items */ +static int radio_si4713_queryctrl (struct file *file,void *priv, +struct v4l2_queryctrl *qc) +{ +/* Must be sorted from low to high control ID! */ +static const u32 user_ctrls[] = { +V4L2_CID_USER_CLASS , +V4L2_CID_AUDIO_MUTE , +0 + }; + +/* Must be sorted from low to high control ID! */ +static const u32 fmtx_ctrls[] = { +V4L2_CID_FM_TX_CLASS , +V4L2_CID_RDS_TX_PI , +V4L2_CID_RDS_TX_PTY , +V4L2_CID_RDS_TX_DEVIATION , +V4L2_CID_RDS_TX_PS_NAME , +V4L2_CID_RDS_TX_RADIO_TEXT , +V4L2_CID_AUDIO_LIMITER_ENABLED , +V4L2_CID_AUDIO_LIMITER_RELEASE_TIME , +V4L2_CID_AUDIO_LIMITER_DEVIATION , +V4L2_CID_AUDIO_COMPRESSION_ENABLED , +V4L2_CID_AUDIO_COMPRESSION_GAIN , +V4L2_CID_AUDIO_COMPRESSION_THRESHOLD , +V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME , +V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME , +V4L2_CID_PILOT_TONE_ENABLED , +V4L2_CID_PILOT_TONE_DEVIATION , +V4L2_CID_PILOT_TONE_FREQUENCY , +V4L2_CID_FM_TX_PREEMPHASIS , +V4L2_CID_TUNE_POWER_LEVEL , +V4L2_CID_TUNE_ANTENNA_CAPACITOR , +0 + }; +static const u32 *ctrl_classes[] = { + user_ctrls, + fmtx_ctrls, +NULL + }; +struct radio_si4713_device *rsdev; + + rsdev =video_get_drvdata (video_devdata (file)); + + qc->id =v4l2_ctrl_next (ctrl_classes, qc->id); +if (qc->id ==0 ) +return -EINVAL ; + +if (qc->id ==V4L2_CID_USER_CLASS || qc->id ==V4L2_CID_FM_TX_CLASS ) +return v4l2_ctrl_query_fill (qc,0 ,0 ,0 ,0 ); + +return v4l2_device_call_until_err (&rsdev->v4l2_dev,0 , core, + queryctrl, qc); +} + +/* +* 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_ext_ctrls (struct file *file,void *p, +struct v4l2_ext_controls *vecs) +{ +return v4l2_device_call_until_err (get_v4l2_dev (file),0 , core, + g_ext_ctrls, vecs); +} + +static int radio_si4713_s_ext_ctrls (struct file *file,void *p, +struct v4l2_ext_controls *vecs) +{ +return v4l2_device_call_until_err (get_v4l2_dev (file),0 , core, + s_ext_ctrls, vecs); +} + +static int radio_si4713_g_ctrl (struct file *file,void *p, +struct v4l2_control *vc) +{ +return v4l2_device_call_until_err (get_v4l2_dev (file),0 , core, + g_ctrl, vc); +} + +static int radio_si4713_s_ctrl (struct file *file,void *p, +struct v4l2_control *vc) +{ +return v4l2_device_call_until_err (get_v4l2_dev (file),0 , core, + s_ctrl, vc); +} + +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, +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, +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,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_enumaudout = radio_si4713_enumaudout, + .vidioc_g_audout = radio_si4713_g_audout, + .vidioc_s_audout = radio_si4713_s_audout, + .vidioc_querycap = radio_si4713_querycap, + .vidioc_queryctrl = radio_si4713_queryctrl, + .vidioc_g_ext_ctrls = radio_si4713_g_ext_ctrls, + .vidioc_s_ext_ctrls = radio_si4713_s_ext_ctrls, + .vidioc_g_ctrl = radio_si4713_g_ctrl, + .vidioc_s_ctrl = radio_si4713_s_ctrl, + .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_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, + .ioctl_ops = &radio_si4713_ioctl_ops, +}; + +/* 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 =kzalloc (sizeof *rsdev,GFP_KERNEL ); +if (!rsdev) { +dev_err (&pdev->dev,"Failed to alloc video device.\n" ); + rval = -ENOMEM ; + goto exit; + } + + rval =v4l2_device_register (&pdev->dev, &rsdev->v4l2_dev); +if (rval) { +dev_err (&pdev->dev,"Failed to register v4l2 device.\n" ); + goto free_rsdev; + } + + 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,"si4713_i2c" , + pdata->subdev_board_info,NULL ); +if (!sd) { +dev_err (&pdev->dev,"Cannot get v4l2 subdevice\n" ); + rval = -ENODEV ; + goto unregister_v4l2_dev; + } + + rsdev->radio_dev =video_device_alloc (); +if (!rsdev->radio_dev) { +dev_err (&pdev->dev,"Failed to alloc video device.\n" ); + rval = -ENOMEM ; + goto unregister_v4l2_dev; + } + +memcpy (rsdev->radio_dev, &radio_si4713_vdev_template, +sizeof (radio_si4713_vdev_template)); +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 free_vdev; + } +dev_info (&pdev->dev,"New device successfully probed\n" ); + + goto exit; + +free_vdev: +video_device_release (rsdev->radio_dev); +unregister_v4l2_dev: +v4l2_device_unregister (&rsdev->v4l2_dev); +free_rsdev: +kfree (rsdev); +exit: +return rval; +} + +/* radio_si4713_pdriver_remove - remove the device */ +static int __exit radio_si4713_pdriver_remove(struct platform_device *pdev) +{ +struct v4l2_device *v4l2_dev =platform_get_drvdata (pdev); +struct radio_si4713_device *rsdev =container_of (v4l2_dev, + struct radio_si4713_device, + v4l2_dev); + +video_unregister_device (rsdev->radio_dev); +v4l2_device_unregister (&rsdev->v4l2_dev); +kfree (rsdev); + +return 0 ; +} + +static struct platform_driver radio_si4713_pdriver = { + .driver = { + .name ="radio-si4713" , + }, + .probe = radio_si4713_pdriver_probe, + .remove =__exit_p (radio_si4713_pdriver_remove), +}; + +/* Module Interface */ +static int __init radio_si4713_module_init (void ) +{ +return platform_driver_register (&radio_si4713_pdriver); +} + +static void __exit radio_si4713_module_exit(void) +{ +platform_driver_unregister (&radio_si4713_pdriver); +} + +module_init (radio_si4713_module_init); +module_exit (radio_si4713_module_exit); +
linux/include/media/radio-si4713.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* include/media/radio-si4713.h +* +* Board related data definitions for Si4713 radio transmitter chip. +* +* Copyright (c) 2009 Nokia Corporation +* Contact: Eduardo Valentin <[email protected]> +* +* 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 RADIO_SI4713_H +#define RADIO_SI4713_H + +#include <linux/i2c.h> + +#define SI4713_NAME "radio-si4713" + +/* +* Platform dependent definition +*/ +struct radio_si4713_platform_data { +int i2c_bus; +struct i2c_board_info *subdev_board_info; +}; + +#endif /* ifndef RADIO_SI4713_H*/
Signature · 1 line
1.6.2.GIT
PATCH v10 6/8 FMTx: si4713: Add files to handle si4713 i2c device
This patch adds files to control si4713 devices. Internal functions to control device properties and initialization procedures are into these files. Also, a v4l2 subdev interface is also exported. This way other drivers can use this as v4l2 i2c subdevice.
--- linux/drivers/media/radio/si4713-i2c.c | 2034 ++++++++++++++++++++++++++++++++ linux/drivers/media/radio/si4713-i2c.h | 228 ++++ linux/include/media/si4713.h | 49 + 3 files changed, 2311 insertions(+), 0 deletions(-) create mode 100644 linux/drivers/media/radio/si4713-i2c.c create mode 100644 linux/drivers/media/radio/si4713-i2c.h create mode 100644 linux/include/media/si4713.h
linux/drivers/media/radio/si4713-i2c.c new file +2034 -0
@@ -0,0 +1,2034 @@ +/* +* drivers/media/radio/si4713-i2c.c +* +* Silicon Labs Si4713 FM Radio Transmitter I2C commands. +* +* Copyright (c) 2009 Nokia Corporation +* Contact: Eduardo Valentin <[email protected]> +* +* 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/mutex.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/i2c.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 <[email protected]>" ); +MODULE_DESCRIPTION ("I2C driver for Si4713 FM Radio Transmitter" ); +MODULE_VERSION ("0.0.1" ); + +#define DEFAULT_RDS_PI 0x00 +#define DEFAULT_RDS_PTY 0x00 +#define DEFAULT_RDS_PS_NAME "Si4713 " +#define DEFAULT_RDS_RADIO_TEXT DEFAULT_RDS_PS_NAME +#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)); +#define get_mute (p) (p & 0x01) + +#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; +} + +static unsigned long dev_to_usecs (int value,unsigned long const array[], +int size) +{ +int i; +int rval = -EINVAL ; + +for (i =0 ; i < size /2 ; i++) +if (array[i *2 ] == value) { + rval = array[(i *2 ) +1 ]; +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 ; + + sdev->platform_data->set_power (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 { + sdev->platform_data->set_power (0 ); + } + +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" ); + sdev->platform_data->set_power (0 ); + 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 ]; + +mutex_lock (&sdev->mutex); + + rval =si4713_send_command (sdev,SI4713_CMD_GET_REV , +NULL ,0 , + resp,ARRAY_SIZE (resp), +DEFAULT_TIMEOUT ); + +if (rval <0 ) + goto unlock; + +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 ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* +* si4713_wait_stc - Waits STC interrupt and clears status bits. Usefull +* 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 +* @intstatus: returns current interrupt status +* @cbavail: returns the number of available circular buffer blocks. +* @cbused: returns the number of used circular buffer blocks. +* @fifoavail: returns the number of available fifo buffer blocks. +* @fifoused: returns the number of used fifo buffer blocks. +*/ +static int si4713_tx_rds_buff (struct si4713_device *sdev,u8 mode,u16 rdsb, +u16 rdsc,u16 rdsd,u8 *intstatus,u8 *cbavail, +u8 *cbused,u8 *fifoavail,u8 *fifoused) +{ +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 ]); + *intstatus = val[1 ]; + *cbavail = val[2 ]; + *cbused = val[3 ]; + *fifoavail = val[4 ]; + *fifoused = val[5 ]; +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__, *intstatus, + *cbavail, *cbused, *fifoavail, *fifoused); + } + +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) +{ +int rval; + +mutex_lock (&sdev->mutex); + +if (value) + rval =si4713_powerup (sdev); +else + rval =si4713_powerdown (sdev); + +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_set_mute (struct si4713_device *sdev,u16 mute) +{ +int rval =0 ; + + mute =set_mute (mute); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) + rval =si4713_write_property (sdev, +SI4713_TX_LINE_INPUT_MUTE , mute); + +if (rval >=0 ) + sdev->mute =get_mute (mute); + +mutex_unlock (&sdev->mutex); + +return rval; +} + +static int si4713_set_rds_ps_name (struct si4713_device *sdev,char *ps_name) +{ +int rval =0 , i; +u8 len =0 ; +u8 *tmp; + +if (!strlen (ps_name)) +return -EINVAL ; + + tmp =kzalloc (MAX_RDS_PS_NAME +1 ,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +strncpy (tmp, ps_name,MAX_RDS_PS_NAME ); + +mutex_lock (&sdev->mutex); + +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 )), + tmp + i); +if (rval <0 ) + goto unlock; + } + +/* Setup the size to be sent */ + len =strlen (tmp) -1 ; + + rval =si4713_write_property (sdev, +SI4713_TX_RDS_PS_MESSAGE_COUNT , +rds_ps_nblocks (len)); +if (rval <0 ) + goto unlock; + + rval =si4713_write_property (sdev, +SI4713_TX_RDS_PS_REPEAT_COUNT , +DEFAULT_RDS_PS_REPEAT_COUNT *2 ); +if (rval <0 ) + goto unlock; + } + +strncpy (sdev->rds_info.ps_name, tmp,MAX_RDS_PS_NAME ); + +unlock: +mutex_unlock (&sdev->mutex); +kfree (tmp); +return rval; +} + +static int si4713_set_rds_radio_text (struct si4713_device *sdev, +char *radio_text) +{ +int rval =0 , i; +u16 t_index =0 ; +u8 s, a, u, fa, fu, b_index =0 , cr_inserted =0 ; +u8 *tmp; + +if (!strlen (radio_text)) +return -EINVAL ; + + tmp =kzalloc (MAX_RDS_RADIO_TEXT +1 ,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +strncpy (tmp, radio_text,MAX_RDS_RADIO_TEXT ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_tx_rds_buff (sdev,RDS_BLOCK_CLEAR ,0 ,0 ,0 , + &s, &a, &u, &fa, &fu); +if (rval <0 ) + goto unlock; +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 (!tmp[t_index + i] || + tmp[t_index + i] == \ +RDS_CARRIAGE_RETURN ) { + tmp[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 (tmp[t_index], + tmp[t_index +1 ]), +compose_u16 (tmp[t_index +2 ], + tmp[t_index +3 ]), + &s, &a, &u, &fa, &fu); +if (rval <0 ) + goto unlock; + + t_index +=RDS_RADIOTEXT_BLK_SIZE ; + +if (cr_inserted) +break ; + }while (u < a); + } + +strncpy (sdev->rds_info.radio_text, tmp,MAX_RDS_RADIO_TEXT ); + +unlock: +mutex_unlock (&sdev->mutex); +kfree (tmp); +return rval; +} + +static int si4713_choose_econtrol_action (struct si4713_device *sdev,u32 id, +u32 **shadow,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 ; + *shadow = &sdev->rds_info.pi; +break ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : + *property =SI4713_TX_ACOMP_THRESHOLD ; + *mul =1 ; + *shadow = &sdev->acomp_info.threshold; +break ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN : + *property =SI4713_TX_ACOMP_GAIN ; + *mul =1 ; + *shadow = &sdev->acomp_info.gain; +break ; +case V4L2_CID_PILOT_TONE_FREQUENCY : + *property =SI4713_TX_PILOT_FREQUENCY ; + *mul =1 ; + *shadow = &sdev->pilot_info.frequency; +break ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : + *property =SI4713_TX_ACOMP_ATTACK_TIME ; + *mul =ATTACK_TIME_UNIT ; + *shadow = &sdev->acomp_info.attack_time; +break ; +case V4L2_CID_PILOT_TONE_DEVIATION : + *property =SI4713_TX_PILOT_DEVIATION ; + *mul =10 ; + *shadow = &sdev->pilot_info.deviation; +break ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION : + *property =SI4713_TX_AUDIO_DEVIATION ; + *mul =10 ; + *shadow = &sdev->limiter_info.deviation; +break ; +case V4L2_CID_RDS_TX_DEVIATION : + *property =SI4713_TX_RDS_DEVIATION ; + *mul =1 ; + *shadow = &sdev->rds_info.deviation; +break ; + +case V4L2_CID_RDS_TX_PTY : + *property =SI4713_TX_RDS_PS_MISC ; + *bit =5 ; + *mask =0x1F <<5 ; + *shadow = &sdev->rds_info.pty; +break ; +case V4L2_CID_AUDIO_LIMITER_ENABLED : + *property =SI4713_TX_ACOMP_ENABLE ; + *bit =1 ; + *mask =1 <<1 ; + *shadow = &sdev->limiter_info.enabled; +break ; +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : + *property =SI4713_TX_ACOMP_ENABLE ; + *bit =0 ; + *mask =1 <<0 ; + *shadow = &sdev->acomp_info.enabled; +break ; +case V4L2_CID_PILOT_TONE_ENABLED : + *property =SI4713_TX_COMPONENT_ENABLE ; + *bit =0 ; + *mask =1 <<0 ; + *shadow = &sdev->pilot_info.enabled; +break ; + +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : + *property =SI4713_TX_LIMITER_RELEASE_TIME ; + *table = limiter_times; + *size =ARRAY_SIZE (limiter_times); + *shadow = &sdev->limiter_info.release_time; +break ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : + *property =SI4713_TX_ACOMP_RELEASE_TIME ; + *table = acomp_rtimes; + *size =ARRAY_SIZE (acomp_rtimes); + *shadow = &sdev->acomp_info.release_time; +break ; +case V4L2_CID_FM_TX_PREEMPHASIS : + *property =SI4713_TX_PREEMPHASIS ; + *table = preemphasis_values; + *size =ARRAY_SIZE (preemphasis_values); + *shadow = &sdev->preemphasis; +break ; + +default : + rval = -EINVAL ; + }; + +return rval; +} + +/* write string property */ +static int si4713_write_econtrol_string (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +char ps_name[MAX_RDS_PS_NAME +1 ]; +char radio_text[MAX_RDS_RADIO_TEXT +1 ]; +int size; +s32 rval =0 ; + +switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : + size = control->length -1 ; +if (size >MAX_RDS_PS_NAME ) + size =MAX_RDS_PS_NAME ; + rval =copy_from_user (ps_name, control->string, size); +if (rval <0 ) + goto exit; + ps_name[size] ='\0' ; + rval =si4713_set_rds_ps_name (sdev, ps_name); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : + size = control->length -1 ; +if (size >MAX_RDS_RADIO_TEXT ) + size =MAX_RDS_RADIO_TEXT ; + rval =copy_from_user (radio_text, control->string, size); +if (rval <0 ) + goto exit; + radio_text[size] ='\0' ; + rval =si4713_set_rds_radio_text (sdev, radio_text); +break ; + +default : + rval = -EINVAL ; +break ; + }; + +exit: +return rval; +} + +/* properties which use tx_tune_power*/ +static int si4713_write_econtrol_tune (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; +u8 power, antcap; + +mutex_lock (&sdev->mutex); + +switch (control->id) { +case V4L2_CID_TUNE_POWER_LEVEL : + power = control->value; + antcap = sdev->antenna_capacitor; +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + power = sdev->power_level; + antcap = control->value; +break ; +default : + rval = -EINVAL ; + goto unlock; + }; + +if (sdev->power_state) + rval =si4713_tx_tune_power (sdev, power, antcap); + +if (rval ==0 ) { + sdev->power_level = power; + sdev->antenna_capacitor = antcap; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_queryctrl (struct v4l2_subdev *sd,struct v4l2_queryctrl *qc); + +static int validate_range (struct v4l2_subdev *sd, +struct v4l2_ext_control *control) +{ +struct v4l2_queryctrl vqc; +int rval; + + vqc.id = control->id; + rval =si4713_queryctrl (sd, &vqc); +if (rval <0 ) + goto exit; + +if (control->value < vqc.minimum || control->value > vqc.maximum) + rval = -EDOM ; + +exit: +return rval; +} + +static int si4713_write_econtrol_integers (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval; +u32 *shadow =NULL , val =0 ; +s32 bit =0 , mask =0 ; +u16 property =0 ; +int mul =0 ; +unsigned long *table =NULL ; +int size =0 ; + + rval =validate_range (&sdev->sd, control); +if (rval <0 ) + goto exit; + + rval =si4713_choose_econtrol_action (sdev, control->id, &shadow, &bit, + &mask, &property, &mul, &table, &size); +if (rval <0 ) + goto exit; + + val = control->value; +if (mul) { + val = control->value / mul; + }else if (table) { + rval =usecs_to_dev (control->value, table, size); +if (rval <0 ) + goto exit; + val = rval; + rval =0 ; + } + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +if (mask) { + rval =si4713_read_property (sdev, property, &val); +if (rval <0 ) + goto unlock; + val =set_bits (val, control->value, bit, mask); + } + + rval =si4713_write_property (sdev, property, val); +if (rval <0 ) + goto unlock; +if (mask) + val = control->value; + } + +if (mul) { + *shadow = val * mul; + }else if (table) { + rval =dev_to_usecs (val, table, size); +if (rval <0 ) + goto unlock; + *shadow = rval; + rval =0 ; + }else { + *shadow = val; + } + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +static int si4713_s_frequency (struct v4l2_subdev *sd,struct v4l2_frequency *f); +static int si4713_s_modulator (struct v4l2_subdev *sd,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_ext_control ctrl; +struct v4l2_frequency f; +struct v4l2_modulator vm; +struct si4713_device *tmp; +int rval =0 ; + + tmp =kmalloc (sizeof (*tmp),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +/* Get a local copy to avoid race */ +mutex_lock (&sdev->mutex); +memcpy (tmp, sdev,sizeof (*sdev)); +mutex_unlock (&sdev->mutex); + + ctrl.id =V4L2_CID_RDS_TX_PI ; + ctrl.value = tmp->rds_info.pi; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_THRESHOLD ; + ctrl.value = tmp->acomp_info.threshold; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_GAIN ; + ctrl.value = tmp->acomp_info.gain; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_FREQUENCY ; + ctrl.value = tmp->pilot_info.frequency; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME ; + ctrl.value = tmp->acomp_info.attack_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_DEVIATION ; + ctrl.value = tmp->pilot_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_DEVIATION ; + ctrl.value = tmp->limiter_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_DEVIATION ; + ctrl.value = tmp->rds_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_PTY ; + ctrl.value = tmp->rds_info.pty; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_ENABLED ; + ctrl.value = tmp->limiter_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_ENABLED ; + ctrl.value = tmp->acomp_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_ENABLED ; + ctrl.value = tmp->pilot_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_RELEASE_TIME ; + ctrl.value = tmp->limiter_info.release_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME ; + ctrl.value = tmp->acomp_info.release_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_FM_TX_PREEMPHASIS ; + ctrl.value = tmp->preemphasis; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_PS_NAME ; + rval |=si4713_set_rds_ps_name (sdev, tmp->rds_info.ps_name); + + ctrl.id =V4L2_CID_RDS_TX_RADIO_TEXT ; + rval |=si4713_set_rds_radio_text (sdev, tmp->rds_info.radio_text); + +/* Device procedure needs to set frequency first */ + f.frequency = tmp->frequency ? tmp->frequency :DEFAULT_FREQUENCY ; + f.frequency =si4713_to_v4l2 (f.frequency); + rval |=si4713_s_frequency (&sdev->sd, &f); + + ctrl.id =V4L2_CID_TUNE_POWER_LEVEL ; + ctrl.value = tmp->power_level; + rval |=si4713_write_econtrol_tune (sdev, &ctrl); + + ctrl.id =V4L2_CID_TUNE_ANTENNA_CAPACITOR ; + ctrl.value = tmp->antenna_capacitor; + rval |=si4713_write_econtrol_tune (sdev, &ctrl); + + vm.index =0 ; +if (tmp->stereo) + vm.txsubchans =V4L2_TUNER_SUB_STEREO ; +else + vm.txsubchans =V4L2_TUNER_SUB_MONO ; +if (tmp->rds_info.enabled) + vm.txsubchans |=V4L2_TUNER_SUB_RDS ; +si4713_s_modulator (&sdev->sd, &vm); + +kfree (tmp); + +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 ) + goto exit; + + rval =si4713_checkrev (sdev); +if (rval <0 ) + goto exit; + + rval =si4713_set_power_state (sdev,POWER_OFF ); +if (rval <0 ) + goto exit; + +mutex_lock (&sdev->mutex); + + sdev->rds_info.pi =DEFAULT_RDS_PI ; + sdev->rds_info.pty =DEFAULT_RDS_PTY ; + sdev->rds_info.deviation =DEFAULT_RDS_DEVIATION ; +strlcpy (sdev->rds_info.ps_name,DEFAULT_RDS_PS_NAME ,MAX_RDS_PS_NAME ); +strlcpy (sdev->rds_info.radio_text,DEFAULT_RDS_RADIO_TEXT , +MAX_RDS_RADIO_TEXT ); + sdev->rds_info.enabled =1 ; + + sdev->limiter_info.release_time =DEFAULT_LIMITER_RTIME ; + sdev->limiter_info.deviation =DEFAULT_LIMITER_DEV ; + sdev->limiter_info.enabled =1 ; + + sdev->pilot_info.deviation =DEFAULT_PILOT_DEVIATION ; + sdev->pilot_info.frequency =DEFAULT_PILOT_FREQUENCY ; + sdev->pilot_info.enabled =1 ; + + sdev->acomp_info.release_time =DEFAULT_ACOMP_RTIME ; + sdev->acomp_info.attack_time =DEFAULT_ACOMP_ATIME ; + sdev->acomp_info.threshold =DEFAULT_ACOMP_THRESHOLD ; + sdev->acomp_info.gain =DEFAULT_ACOMP_GAIN ; + sdev->acomp_info.enabled =1 ; + + sdev->frequency =DEFAULT_FREQUENCY ; + sdev->preemphasis =DEFAULT_PREEMPHASIS ; + sdev->mute =DEFAULT_MUTE ; + sdev->power_level =DEFAULT_POWER_LEVEL ; + sdev->antenna_capacitor =0 ; + sdev->stereo =1 ; + sdev->tune_rnl =DEFAULT_TUNE_RNL ; + +mutex_unlock (&sdev->mutex); + +exit: +return rval; +} + +/* read string property */ +static int si4713_read_econtrol_string (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; + +switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : +if (strlen (sdev->rds_info.ps_name) +1 > control->length) { + control->length =strlen (sdev->rds_info.ps_name) +1 ; + rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.ps_name, +strlen (sdev->rds_info.ps_name) +1 ); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : +if (strlen (sdev->rds_info.radio_text) +1 > control->length) { + control->length =strlen (sdev->rds_info.radio_text) +1 ; + rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.radio_text, +strlen (sdev->rds_info.radio_text) +1 ); +break ; + +default : + rval = -EINVAL ; +break ; + }; + +exit: +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; + + sdev->power_level = p; + sdev->antenna_capacitor = a; + sdev->tune_rnl = n; + +exit: +return rval; +} + +/* properties which use tx_tune_status */ +static int si4713_read_econtrol_tune (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_update_tune_status (sdev); +if (rval <0 ) + goto unlock; + } + +switch (control->id) { +case V4L2_CID_TUNE_POWER_LEVEL : + control->value = sdev->power_level; +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + control->value = sdev->antenna_capacitor; +break ; +default : + rval = -EINVAL ; + }; + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_read_econtrol_integers (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval; +u32 *shadow =NULL , val =0 ; +s32 bit =0 , mask =0 ; +u16 property =0 ; +int mul =0 ; +unsigned long *table =NULL ; +int size =0 ; + + rval =si4713_choose_econtrol_action (sdev, control->id, &shadow, &bit, + &mask, &property, &mul, &table, &size); +if (rval <0 ) + goto exit; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev, property, &val); +if (rval <0 ) + goto unlock; + +/* Keep negative values for threshold */ +if (control->id ==V4L2_CID_AUDIO_COMPRESSION_THRESHOLD ) + *shadow = (s16 )val; +else if (mask) + *shadow =get_status_bit (val, bit, mask); +else if (mul) + *shadow = val * mul; +else + *shadow =dev_to_usecs (val, table, size); + } + + control->value = *shadow; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +/* +* Video4Linux Subdev Interface +*/ +/* si4713_s_ext_ctrls - set extended controls value */ +static int si4713_s_ext_ctrls (struct v4l2_subdev *sd, +struct v4l2_ext_controls *ctrls) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int i; + +if (ctrls->ctrl_class !=V4L2_CTRL_CLASS_FM_TX ) +return -EINVAL ; + +for (i =0 ; i < ctrls->count; i++) { +int err; + + err =si4713_write_econtrol_integers (sdev, ctrls->controls + i); +if (err <0 ) + err =si4713_write_econtrol_string (sdev, + ctrls->controls + i); +if (err <0 ) + err =si4713_write_econtrol_tune (sdev, + ctrls->controls + i); + +if (err <0 ) { + ctrls->error_idx = i; +return err; + } + } + +return 0 ; +} + +/* si4713_g_ext_ctrls - get extended controls value */ +static int si4713_g_ext_ctrls (struct v4l2_subdev *sd, +struct v4l2_ext_controls *ctrls) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int i; + +if (ctrls->ctrl_class !=V4L2_CTRL_CLASS_FM_TX ) +return -EINVAL ; + +for (i =0 ; i < ctrls->count; i++) { +int err; + + err =si4713_read_econtrol_tune (sdev, ctrls->controls + i); +if (err <0 ) + err =si4713_read_econtrol_string (sdev, + ctrls->controls + i); +if (err <0 ) + err =si4713_read_econtrol_integers (sdev, + ctrls->controls + i); + +if (err <0 ) { + ctrls->error_idx = i; +return err; + } + } + +return 0 ; +} + +/* si4713_queryctrl - enumerate control items */ +static int si4713_queryctrl (struct v4l2_subdev *sd,struct v4l2_queryctrl *qc) +{ +int rval =0 ; + +switch (qc->id) { +/* User class controls */ +case V4L2_CID_AUDIO_MUTE : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,DEFAULT_MUTE ); +break ; +/* FM_TX class controls */ +case V4L2_CID_RDS_TX_PI : + rval =v4l2_ctrl_query_fill (qc,0 ,0xFFFF ,1 ,DEFAULT_RDS_PI ); +break ; +case V4L2_CID_RDS_TX_PTY : + rval =v4l2_ctrl_query_fill (qc,0 ,31 ,1 ,DEFAULT_RDS_PTY ); +break ; +case V4L2_CID_RDS_TX_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_DEVIATION , +10 ,DEFAULT_RDS_DEVIATION ); +break ; +case V4L2_CID_RDS_TX_PS_NAME : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_PS_NAME +1 ,0 ,0 ); +break ; +case V4L2_CID_RDS_TX_RADIO_TEXT : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_RADIO_TEXT +1 , +0 ,0 ); +break ; + +case V4L2_CID_AUDIO_LIMITER_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : + rval =v4l2_ctrl_query_fill (qc,250 ,MAX_LIMITER_RELEASE_TIME , +50 ,DEFAULT_LIMITER_RTIME ); +break ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_LIMITER_DEVIATION , +10 ,DEFAULT_LIMITER_DEV ); +break ; + +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_ACOMP_GAIN ,1 , +DEFAULT_ACOMP_GAIN ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : + rval =v4l2_ctrl_query_fill (qc,MIN_ACOMP_THRESHOLD , +MAX_ACOMP_THRESHOLD ,1 , +DEFAULT_ACOMP_THRESHOLD ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_ACOMP_ATTACK_TIME , +500 ,DEFAULT_ACOMP_ATIME ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : + rval =v4l2_ctrl_query_fill (qc,100000 ,MAX_ACOMP_RELEASE_TIME , +100000 ,DEFAULT_ACOMP_RTIME ); +break ; + +case V4L2_CID_PILOT_TONE_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_PILOT_TONE_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_PILOT_DEVIATION , +10 ,DEFAULT_PILOT_DEVIATION ); +break ; +case V4L2_CID_PILOT_TONE_FREQUENCY : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_PILOT_FREQUENCY , +1 ,DEFAULT_PILOT_FREQUENCY ); +break ; + +case V4L2_CID_FM_TX_PREEMPHASIS : + rval =v4l2_ctrl_query_fill (qc,V4L2_PREEMPHASIS_DISABLED , + V4L2_PREEMPHASIS_75_uS,1 , + V4L2_PREEMPHASIS_50_uS); +break ; +case V4L2_CID_TUNE_POWER_LEVEL : + rval =v4l2_ctrl_query_fill (qc,0 ,120 ,1 ,DEFAULT_POWER_LEVEL ); +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + rval =v4l2_ctrl_query_fill (qc,0 ,191 ,1 ,0 ); +break ; +default : + rval = -EINVAL ; +break ; + }; + +return rval; +} + +/* si4713_g_ctrl - get the value of a control */ +static int si4713_g_ctrl (struct v4l2_subdev *sd,struct v4l2_control *ctrl) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; + +if (!sdev) +return -ENODEV ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev,SI4713_TX_LINE_INPUT_MUTE , + &sdev->mute); + +if (rval <0 ) + goto unlock; + } + +switch (ctrl->id) { +case V4L2_CID_AUDIO_MUTE : + ctrl->value =get_mute (sdev->mute); +break ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* si4713_s_ctrl - set the value of a control */ +static int si4713_s_ctrl (struct v4l2_subdev *sd,struct v4l2_control *ctrl) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; + +if (!sdev) +return -ENODEV ; + +switch (ctrl->id) { +case V4L2_CID_AUDIO_MUTE : +if (ctrl->value) { + rval =si4713_set_mute (sdev, ctrl->value); +if (rval <0 ) + goto exit; + + rval =si4713_set_power_state (sdev,POWER_DOWN ); + }else { + rval =si4713_set_power_state (sdev,POWER_UP ); +if (rval <0 ) + goto exit; + + rval =si4713_setup (sdev); +if (rval <0 ) + goto exit; + + rval =si4713_set_mute (sdev, ctrl->value); + } +break ; + } + +exit: +return rval; +} + +/* si4713_ioctl - deal with private ioctls (only rnl for now) */ +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 ; + +mutex_lock (&sdev->mutex); +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 ) + goto unlock; +/* get results from tune status */ + rval =si4713_update_tune_status (sdev); +if (rval <0 ) + goto unlock; + } + rnl->rnl = sdev->tune_rnl; +break ; + +default : +/* nothing */ + rval = -ENOIOCTLCMD ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = { + .queryctrl = si4713_queryctrl, + .g_ext_ctrls = si4713_g_ext_ctrls, + .s_ext_ctrls = si4713_s_ext_ctrls, + .g_ctrl = si4713_g_ctrl, + .s_ctrl = si4713_s_ctrl, + .ioctl = si4713_ioctl, +}; + +/* 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) { + rval = -ENODEV ; + goto exit; + } + +if (vm->index >0 ) { + rval = -EINVAL ; + goto exit; + } + +strncpy (vm->name,"FM Modulator" ,32 ); + vm->capability =V4L2_TUNER_CAP_STEREO |V4L2_TUNER_CAP_LOW | +V4L2_TUNER_CAP_RDS ; + +/* Report current frequency range limits */ + vm->rangelow =si4713_to_v4l2 (FREQ_RANGE_LOW ); + vm->rangehigh =si4713_to_v4l2 (FREQ_RANGE_HIGH ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +u32 comp_en =0 ; + + rval =si4713_read_property (sdev,SI4713_TX_COMPONENT_ENABLE , + &comp_en); +if (rval <0 ) + goto unlock; + + sdev->stereo =get_status_bit (comp_en,1 ,1 <<1 ); + sdev->rds_info.enabled =get_status_bit (comp_en,2 ,1 <<2 ); + } + +/* 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_info.enabled) + vm->txsubchans |=V4L2_TUNER_SUB_RDS ; +else + vm->txsubchans &= ~V4L2_TUNER_SUB_RDS ; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +/* si4713_s_modulator - set modulator attributes */ +static int si4713_s_modulator (struct v4l2_subdev *sd,struct v4l2_modulator *vm) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; +u16 stereo, rds; +u32 p; + +if (!sdev) { + rval = -ENODEV ; + goto exit; + } + +if (vm->index >0 ) { + rval = -EINVAL ; + goto exit; + } + +/* 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 + rval = -EINVAL ; +if (rval <0 ) + goto exit; + + rds = !!(vm->txsubchans &V4L2_TUNER_SUB_RDS ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev, +SI4713_TX_COMPONENT_ENABLE , &p); +if (rval <0 ) + goto unlock; + + 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 ) + goto unlock; + } + + sdev->stereo = stereo; + sdev->rds_info.enabled = rds; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +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 ; + + f->type =V4L2_TUNER_RADIO ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +u16 freq; +u8 p, a, n; + + rval =si4713_tx_tune_status (sdev,0x00 , &freq, &p, &a, &n); +if (rval <0 ) + goto unlock; + + sdev->frequency = freq; + } + + f->frequency =si4713_to_v4l2 (sdev->frequency); + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* si4713_s_frequency - set tuner or modulator radio frequency */ +static int si4713_s_frequency (struct v4l2_subdev *sd,struct v4l2_frequency *f) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; +u16 frequency =v4l2_to_si4713 (f->frequency); + +/* Check frequency range */ +if (frequency <FREQ_RANGE_LOW || frequency >FREQ_RANGE_HIGH ) +return -EDOM ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_tx_tune_freq (sdev, frequency); +if (rval <0 ) + goto unlock; + frequency = rval; + rval =0 ; + } + sdev->frequency = frequency; + f->frequency =si4713_to_v4l2 (frequency); + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +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; +int rval; + + sdev =kzalloc (sizeof *sdev,GFP_KERNEL ); +if (!sdev) { +v4l2_err (&sdev->sd,"Failed to alloc video device.\n" ); + rval = -ENOMEM ; + goto exit; + } + + sdev->platform_data = client->dev.platform_data; +if (!sdev->platform_data) { +v4l2_err (&sdev->sd,"No platform data registered.\n" ); + rval = -ENODEV ; + goto free_sdev; + } + +v4l2_i2c_subdev_init (&sdev->sd, client, &si4713_subdev_ops); + +mutex_init (&sdev->mutex); +init_completion (&sdev->work); + +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 free_sdev; + } +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_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); + +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 Interface */ +static int __init si4713_module_init (void ) +{ +return i2c_add_driver (&si4713_i2c_driver); +} + +static void __exit si4713_module_exit(void) +{ +i2c_del_driver (&si4713_i2c_driver); +} + +module_init (si4713_module_init); +module_exit (si4713_module_exit); +
linux/drivers/media/radio/si4713-i2c.h new file +228 -0
228 lines not on this page · raw message
linux/include/media/si4713.h new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
1.6.2.GIT
PATCH v10 7/8 FMTx: si4713: Add Kconfig and Makefile entries
Simple add Makefile and Kconfig entries.
--- linux/drivers/media/radio/Kconfig | 22 ++++++++++++++++++++++ linux/drivers/media/radio/Makefile | 2 ++ 2 files changed, 24 insertions(+), 0 deletions(-)
linux/drivers/media/radio/Kconfig +22 -0
@@ -339,6 +339,28 @@ config RADIO_ZOLTRIX_PORT help Enter the I/O port of your Zoltrix radio card. +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 + ---help--- + Say Y here if you want support to Si4713 FM Radio Transmitter. + This device can transmit audio through FM. It can transmit + EDS and EBDS 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_DSBR tristate "D-Link/GemTek USB FM radio support" depends on USB && VIDEO_V4L2
linux/drivers/media/radio/Makefile +2 -0
@@ -15,6 +15,8 @@ obj-$(CONFIG_RADIO_ZOLTRIX) += radio-zoltrix.o obj-$(CONFIG_RADIO_GEMTEK) += radio-gemtek.o obj-$(CONFIG_RADIO_GEMTEK_PCI) += radio-gemtek-pci.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_MAESTRO) += radio-maestro.o obj-$(CONFIG_USB_DSBR) += dsbr100.o obj-$(CONFIG_USB_SI470X) += radio-si470x.o
Signature · 1 line
1.6.2.GIT
PATCH v10 8/8 FMTx: si4713: Add document file
This patch adds a document file for si4713 device driver. It describes the driver interfaces and organization.
--- linux/Documentation/video4linux/si4713.txt | 175 ++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) create mode 100644 linux/Documentation/video4linux/si4713.txt
linux/Documentation/video4linux/si4713.txt new file +175 -0
@@ -0,0 +1,175 @@ +Driver for I2C radios for the Silicon Labs Si4713 FM Radio Transmitters + +Copyright (c) 2009 Nokia Corporation +Contact: Eduardo Valentin <[email protected]> + + +Information about the Device +============================ +This chip is a Silicon Labs product. It is a I2C device, currently on 0×63 address. +Basically, it has transmission and signal noise level measurement features. + +The Si4713 integrates transmit functions for FM broadcast stereo transmission. +The chip also allows integrated receive power scanning to identify low signal +power FM channels. + +The chip is programmed using commands and responses. There are also several +properties which can change the behavior of this chip. + +Users must comply with local regulations on radio frequency (RF) transmission. + +Device driver description +========================= +There are two modules to handle this device. One is a I2C device driver +and the other is a platform driver. + +The I2C device driver exports a v4l2-subdev interface to the kernel. +All properties can also be accessed by v4l2 extended controls interface, by +using the v4l2-subdev calls (g_ext_ctrls, s_ext_ctrls). + +The platform device driver exports a v4l2 radio device interface to user land. +So, it uses the I2C device driver as a sub device in order to send the user +commands to the actual device. Basically it is a wrapper to the I2C device driver. + +Applications can use v4l2 radio API to specify frequency of operation, mute state, +etc. But mostly of its properties will be present in the extended controls. + +When the v4l2 mute property is set to 1 (true), the driver will turn the chip off. + +Properties description +====================== + +The properties can be accessed using v4l2 extended controls. +Here is an output from v4l2-ctl util: + +# v4l2-ctl -d /dev/radio0 --all -l +Driver Info: + Driver name : radio-si4713 + Card type : Silicon Labs Si4713 Modulator + Bus info : + Driver version: 0 + Capabilities : 0x00080800 + RDS Output + Modulator +Audio output: 0 (FM Modulator Audio Out) +Frequency: 1545600 (96.600000 MHz) +Video Standard = 0x00000000 +Modulator: + Name : FM Modulator + Capabilities : 62.5 Hz stereo rds + Frequency range : 76.0 MHz - 108.0 MHz + Available subchannels: mono rds + +User Controls + + mute (bool) : default=1 value=0 + +FM Radio Modulator Controls + + rds_program_id (int) : min=0 max=65535 step=1 default=0 value=0 + rds_program_type (int) : min=0 max=31 step=1 default=0 value=0 + rds_ps_name (str) : value='Si4713 ' len=1024 +' len=1024 rds_radio_text (str) : value='Si4713 + audio_limiter_feature_enabled (bool) : default=1 value=1 + audio_limiter_release_time (int) : min=250 max=102390 step=50 default=5010 value=5010 flags=slider + audio_limiter_deviation (int) : min=0 max=90000 step=10 default=66250 value=1020 flags=slider +audio_compression_feature_enabl (bool) : default=1 value=1 + audio_compression_gain (int) : min=0 max=20 step=1 default=15 value=15 flags=slider + audio_compression_threshold (int) : min=-40 max=0 step=1 default=-40 value=-40 flags=slider + audio_compression_attack_time (int) : min=0 max=5000 step=500 default=0 value=0 flags=slider + audio_compression_release_time (int) : min=100000 max=1000000 step=100000 default=1000000 value=1000000 flags=slider + pilot_tone_feature_enabled (bool) : default=1 value=1 + pilot_tone_deviation (int) : min=0 max=90000 step=10 default=6750 value=6750 flags=slider + pilot_tone_frequency (int) : min=0 max=19000 step=1 default=19000 value=19000 flags=slider + pre_emphasis_settings (menu) : min=0 max=2 default=1 value=1 + tune_power_level (int) : min=0 max=120 step=1 default=88 value=120 flags=slider + tune_antenna_capacitor (int) : min=0 max=191 step=1 default=0 value=112 flags=slider + +Here is a summary of them: + +* Pilot is an audible tone sent by the device. + +pilot_frequency - Configures the frequency of the stereo pilot tone. +pilot_deviation - Configures pilot tone frequency deviation level. +pilot_enabled - Enables or disables the pilot tone feature. + +* The si4713 device is capable of applying audio compression to the transmitted signal. + +acomp_enabled - Enables or disables the audio dynamic range control feature. +acomp_gain - Sets the gain for audio dynamic range control. +acomp_threshold - Sets the threshold level for audio dynamic range control. +acomp_attack_time - Sets the attack time for audio dynamic range control. +acomp_release_time - Sets the release time for audio dynamic range control. + +* Limiter setups audio deviation limiter feature. Once a over deviation occurs, +it is possible to adjust the front-end gain of the audio input and always +prevent over deviation. + +limiter_enabled - Enables or disables the limiter feature. +limiter_deviation - Configures audio frequency deviation level. +limiter_release_time - Sets the limiter release time. + +* Tuning power + +power_level - Sets the output power level for signal transmission. +antenna_capacitor - This selects the value of antenna tuning capacitor manually +or automatically if set to zero. + +* RDS related + +rds_ps_name - Sets the RDS ps name field for transmission. +rds_radio_text - Sets the RDS radio text for transmission. +rds_pi - Sets the RDS PI field for transmission. +rds_pty - Sets the RDS PTY field for transmission. + +* Region related + +preemphasis - sets the preemphasis to be applied for transmission. + +RNL +=== + +This device also has an interface to measure received noise level. To do that, you should +ioctl the device node. Here is an code of example: + +int main (int argc, char *argv[]) +{ + struct si4713_rnl rnl; + int fd = open("/dev/radio0", O_RDWR); + int rval; + + if (argc < 2) + return -EINVAL; + + if (fd < 0) + return fd; + + sscanf(argv[1], "%d", &rnl.frequency); + + rval = ioctl(fd, SI4713_IOC_MEASURE_RNL, &rnl); + if (rval < 0) + return rval; + + printf("received noise level: %d\n", rnl.rnl); + + close(fd); +} + +The struct si4713_rnl and SI4713_IOC_MEASURE_RNL are defined under +include/media/si4713.h. + +Stereo/Mono and RDS subchannels +=============================== + +The device can also be configured using the available sub channels for +transmission. To do that use S/G_MODULATOR ioctl and configure txsubchans properly. +Refer to v4l2-spec for proper use of this ioctl. + +Testing +======= +Testing is usually done with v4l2-ctl utility for managing FM tuner cards. +The tool can be found in v4l-dvb repository under v4l2-apps/util directory. + +Example for setting rds ps name: +# v4l2-ctl -d /dev/radio0 --set-ctrl=rds_ps_name="Dummy" +
Signature · 1 line
1.6.2.GIT
Re: [PATCHv10 8/8] FMTx: si4713: Add document file
Quoted 77 lines · On Friday 24 July 2009 18:37:28 Eduardo Valentin wrote:
This patch adds a document file for si4713 device driver. It describes the driver interfaces and organization.
Signed-off-by Eduardo Valentin <[email protected]>--- linux/Documentation/video4linux/si4713.txt | 175 ++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) create mode 100644 linux/Documentation/video4linux/si4713.txtlinux/Documentation/video4linux/si4713.txt new file +62
-0@@ -0,0 +1,175 @@ +Driver for I2C radios for the Silicon Labs Si4713 FM Radio Transmitters + +Copyright (c) 2009 Nokia Corporation +Contact: Eduardo Valentin <[email protected]> + + +Information about the Device +============================ +This chip is a Silicon Labs product. It is a I2C device, currently on 0Ã63 address. +Basically, it has transmission and signal noise level measurement features. + +The Si4713 integrates transmit functions for FM broadcast stereo transmission. +The chip also allows integrated receive power scanning to identify low signal +power FM channels. + +The chip is programmed using commands and responses. There are also several +properties which can change the behavior of this chip. + +Users must comply with local regulations on radio frequency (RF) transmission. + +Device driver description +========================= +There are two modules to handle this device. One is a I2C device driver +and the other is a platform driver. + +The I2C device driver exports a v4l2-subdev interface to the kernel. +All properties can also be accessed by v4l2 extended controls interface, by +using the v4l2-subdev calls (g_ext_ctrls, s_ext_ctrls). + +The platform device driver exports a v4l2 radio device interface to user land. +So, it uses the I2C device driver as a sub device in order to send the user +commands to the actual device. Basically it is a wrapper to the I2C device driver. + +Applications can use v4l2 radio API to specify frequency of operation, mute state, +etc. But mostly of its properties will be present in the extended controls. + +When the v4l2 mute property is set to 1 (true), the driver will turn the chip off. + +Properties description +====================== + +The properties can be accessed using v4l2 extended controls. +Here is an output from v4l2-ctl util: + +# v4l2-ctl -d /dev/radio0 --all -l +Driver Info: + Driver name : radio-si4713 + Card type : Silicon Labs Si4713 Modulator + Bus info : + Driver version: 0 + Capabilities : 0x00080800 + RDS Output + Modulator +Audio output: 0 (FM Modulator Audio Out) +Frequency: 1545600 (96.600000 MHz) +Video Standard = 0x00000000 +Modulator: + Name : FM Modulator + Capabilities : 62.5 Hz stereo rds + Frequency range : 76.0 MHz - 108.0 MHz + Available subchannels: mono rds +
linux/Documentation/video4linux/si4713.txt line 72
Quoted 10 lines
linux/Documentation/video4linux/si4713.txt new file +10
-0+User Controls + + mute (bool) : default=1 value=0 + +FM Radio Modulator Controls + + rds_program_id (int) : min=0 max=65535 step=1 default=0 value=0 + rds_program_type (int) : min=0 max=31 step=1 default=0 value=0 + rds_ps_name (str) : value='Si4713 ' len=1024 +' len=1024 rds_radio_text (str) : value='Si4713
This doesn't look right. I think this output is from an old v4l2-ctl version. I'd like to see this output anyway using the latest v4l2-ctl version as I haven't been able to test it myself.
Based on this output it also looks as if the rds_radio_text string has a \r at the end. If so, is it supposed to be there?
Regards,
Hans
Quoted 103 lines
linux/Documentation/video4linux/si4713.txt new file +103
-0+ audio_limiter_feature_enabled (bool) : default=1 value=1 + audio_limiter_release_time (int) : min=250 max=102390 step=50 default=5010 value=5010 flags=slider + audio_limiter_deviation (int) : min=0 max=90000 step=10 default=66250 value=1020 flags=slider +audio_compression_feature_enabl (bool) : default=1 value=1 + audio_compression_gain (int) : min=0 max=20 step=1 default=15 value=15 flags=slider + audio_compression_threshold (int) : min=-40 max=0 step=1 default=-40 value=-40 flags=slider + audio_compression_attack_time (int) : min=0 max=5000 step=500 default=0 value=0 flags=slider + audio_compression_release_time (int) : min=100000 max=1000000 step=100000 default=1000000 value=1000000 flags=slider + pilot_tone_feature_enabled (bool) : default=1 value=1 + pilot_tone_deviation (int) : min=0 max=90000 step=10 default=6750 value=6750 flags=slider + pilot_tone_frequency (int) : min=0 max=19000 step=1 default=19000 value=19000 flags=slider + pre_emphasis_settings (menu) : min=0 max=2 default=1 value=1 + tune_power_level (int) : min=0 max=120 step=1 default=88 value=120 flags=slider + tune_antenna_capacitor (int) : min=0 max=191 step=1 default=0 value=112 flags=slider + +Here is a summary of them: + +* Pilot is an audible tone sent by the device. + +pilot_frequency - Configures the frequency of the stereo pilot tone. +pilot_deviation - Configures pilot tone frequency deviation level. +pilot_enabled - Enables or disables the pilot tone feature. + +* The si4713 device is capable of applying audio compression to the transmitted signal. + +acomp_enabled - Enables or disables the audio dynamic range control feature. +acomp_gain - Sets the gain for audio dynamic range control. +acomp_threshold - Sets the threshold level for audio dynamic range control. +acomp_attack_time - Sets the attack time for audio dynamic range control. +acomp_release_time - Sets the release time for audio dynamic range control. + +* Limiter setups audio deviation limiter feature. Once a over deviation occurs, +it is possible to adjust the front-end gain of the audio input and always +prevent over deviation. + +limiter_enabled - Enables or disables the limiter feature. +limiter_deviation - Configures audio frequency deviation level. +limiter_release_time - Sets the limiter release time. + +* Tuning power + +power_level - Sets the output power level for signal transmission. +antenna_capacitor - This selects the value of antenna tuning capacitor manually +or automatically if set to zero. + +* RDS related + +rds_ps_name - Sets the RDS ps name field for transmission. +rds_radio_text - Sets the RDS radio text for transmission. +rds_pi - Sets the RDS PI field for transmission. +rds_pty - Sets the RDS PTY field for transmission. + +* Region related + +preemphasis - sets the preemphasis to be applied for transmission. + +RNL +=== + +This device also has an interface to measure received noise level. To do that, you should +ioctl the device node. Here is an code of example: + +int main (int argc, char *argv[]) +{ + struct si4713_rnl rnl; + int fd = open("/dev/radio0", O_RDWR); + int rval; + + if (argc < 2) + return -EINVAL; + + if (fd < 0) + return fd; + + sscanf(argv[1], "%d", &rnl.frequency); + + rval = ioctl(fd, SI4713_IOC_MEASURE_RNL, &rnl); + if (rval < 0) + return rval; + + printf("received noise level: %d\n", rnl.rnl); + + close(fd); +} + +The struct si4713_rnl and SI4713_IOC_MEASURE_RNL are defined under +include/media/si4713.h. + +Stereo/Mono and RDS subchannels +=============================== + +The device can also be configured using the available sub channels for +transmission. To do that use S/G_MODULATOR ioctl and configure txsubchans properly. +Refer to v4l2-spec for proper use of this ioctl. + +Testing +======= +Testing is usually done with v4l2-ctl utility for managing FM tuner cards. +The tool can be found in v4l-dvb repository under v4l2-apps/util directory. + +Example for setting rds ps name: +# v4l2-ctl -d /dev/radio0 --set-ctrl=rds_ps_name="Dummy" +
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 8/8] FMTx: si4713: Add document file
Quoted 84 lines · ext Hans Verkuil
Quoted 83 lines · On Friday 24 July 2009 18:37:28 Eduardo Valentin wrote:
This patch adds a document file for si4713 device driver. It describes the driver interfaces and organization.
Signed-off-by Eduardo Valentin <[email protected]>--- linux/Documentation/video4linux/si4713.txt | 175 ++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) create mode 100644 linux/Documentation/video4linux/si4713.txtlinux/Documentation/video4linux/si4713.txt new file +68
-0@@ -0,0 +1,175 @@ +Driver for I2C radios for the Silicon Labs Si4713 FM Radio Transmitters + +Copyright (c) 2009 Nokia Corporation +Contact: Eduardo Valentin <[email protected]> + + +Information about the Device +============================ +This chip is a Silicon Labs product. It is a I2C device, currently on 0×63 address. +Basically, it has transmission and signal noise level measurement features. + +The Si4713 integrates transmit functions for FM broadcast stereo transmission. +The chip also allows integrated receive power scanning to identify low signal +power FM channels. + +The chip is programmed using commands and responses. There are also several +properties which can change the behavior of this chip. + +Users must comply with local regulations on radio frequency (RF) transmission. + +Device driver description +========================= +There are two modules to handle this device. One is a I2C device driver +and the other is a platform driver. + +The I2C device driver exports a v4l2-subdev interface to the kernel. +All properties can also be accessed by v4l2 extended controls interface, by +using the v4l2-subdev calls (g_ext_ctrls, s_ext_ctrls). + +The platform device driver exports a v4l2 radio device interface to user land. +So, it uses the I2C device driver as a sub device in order to send the user +commands to the actual device. Basically it is a wrapper to the I2C device driver. + +Applications can use v4l2 radio API to specify frequency of operation, mute state, +etc. But mostly of its properties will be present in the extended controls. + +When the v4l2 mute property is set to 1 (true), the driver will turn the chip off. + +Properties description +====================== + +The properties can be accessed using v4l2 extended controls. +Here is an output from v4l2-ctl util: + +# v4l2-ctl -d /dev/radio0 --all -l +Driver Info: + Driver name : radio-si4713 + Card type : Silicon Labs Si4713 Modulator + Bus info : + Driver version: 0 + Capabilities : 0x00080800 + RDS Output + Modulator +Audio output: 0 (FM Modulator Audio Out) +Frequency: 1545600 (96.600000 MHz) +Video Standard = 0x00000000 +Modulator: + Name : FM Modulator + Capabilities : 62.5 Hz stereo rds + Frequency range : 76.0 MHz - 108.0 MHz + Available subchannels: mono rds + +User Controls + + mute (bool) : default=1 value=0 + +FM Radio Modulator Controls +
Quoted 8 lines
linux/Documentation/video4linux/si4713.txt line 72
Quoted 4 lines
linux/Documentation/video4linux/si4713.txt new file +4
-0+ rds_program_id (int) : min=0 max=65535 step=1 default=0 value=0 + rds_program_type (int) : min=0 max=31 step=1 default=0 value=0 + rds_ps_name (str) : value='Si4713 ' len=1024 +' len=1024 rds_radio_text (str) : value='Si4713This doesn't look right. I think this output is from an old v4l2-ctl version. I'd like to see this output anyway using the latest v4l2-ctl version as I haven't been able to test it myself.
Yeah. My bad, forgot to update here. This is the output from the older version.
Quoted 3 lines
Based on this output it also looks as if the
rds_radio_textstring has a \r at the end. If so, is it supposed to be there?
Yeah, the \r it is required for Radio Text.
Quoted 113 lines
Regards,
Hans
Quoted 103 lines
linux/Documentation/video4linux/si4713.txt new file +103
-0+ audio_limiter_feature_enabled (bool) : default=1 value=1 + audio_limiter_release_time (int) : min=250 max=102390 step=50 default=5010 value=5010 flags=slider + audio_limiter_deviation (int) : min=0 max=90000 step=10 default=66250 value=1020 flags=slider +audio_compression_feature_enabl (bool) : default=1 value=1 + audio_compression_gain (int) : min=0 max=20 step=1 default=15 value=15 flags=slider + audio_compression_threshold (int) : min=-40 max=0 step=1 default=-40 value=-40 flags=slider + audio_compression_attack_time (int) : min=0 max=5000 step=500 default=0 value=0 flags=slider + audio_compression_release_time (int) : min=100000 max=1000000 step=100000 default=1000000 value=1000000 flags=slider + pilot_tone_feature_enabled (bool) : default=1 value=1 + pilot_tone_deviation (int) : min=0 max=90000 step=10 default=6750 value=6750 flags=slider + pilot_tone_frequency (int) : min=0 max=19000 step=1 default=19000 value=19000 flags=slider + pre_emphasis_settings (menu) : min=0 max=2 default=1 value=1 + tune_power_level (int) : min=0 max=120 step=1 default=88 value=120 flags=slider + tune_antenna_capacitor (int) : min=0 max=191 step=1 default=0 value=112 flags=slider + +Here is a summary of them: + +* Pilot is an audible tone sent by the device. + +pilot_frequency - Configures the frequency of the stereo pilot tone. +pilot_deviation - Configures pilot tone frequency deviation level. +pilot_enabled - Enables or disables the pilot tone feature. + +* The si4713 device is capable of applying audio compression to the transmitted signal. + +acomp_enabled - Enables or disables the audio dynamic range control feature. +acomp_gain - Sets the gain for audio dynamic range control. +acomp_threshold - Sets the threshold level for audio dynamic range control. +acomp_attack_time - Sets the attack time for audio dynamic range control. +acomp_release_time - Sets the release time for audio dynamic range control. + +* Limiter setups audio deviation limiter feature. Once a over deviation occurs, +it is possible to adjust the front-end gain of the audio input and always +prevent over deviation. + +limiter_enabled - Enables or disables the limiter feature. +limiter_deviation - Configures audio frequency deviation level. +limiter_release_time - Sets the limiter release time. + +* Tuning power + +power_level - Sets the output power level for signal transmission. +antenna_capacitor - This selects the value of antenna tuning capacitor manually +or automatically if set to zero. + +* RDS related + +rds_ps_name - Sets the RDS ps name field for transmission. +rds_radio_text - Sets the RDS radio text for transmission. +rds_pi - Sets the RDS PI field for transmission. +rds_pty - Sets the RDS PTY field for transmission. + +* Region related + +preemphasis - sets the preemphasis to be applied for transmission. + +RNL +=== + +This device also has an interface to measure received noise level. To do that, you should +ioctl the device node. Here is an code of example: + +int main (int argc, char *argv[]) +{ + struct si4713_rnl rnl; + int fd = open("/dev/radio0", O_RDWR); + int rval; + + if (argc < 2) + return -EINVAL; + + if (fd < 0) + return fd; + + sscanf(argv[1], "%d", &rnl.frequency); + + rval = ioctl(fd, SI4713_IOC_MEASURE_RNL, &rnl); + if (rval < 0) + return rval; + + printf("received noise level: %d\n", rnl.rnl); + + close(fd); +} + +The struct si4713_rnl and SI4713_IOC_MEASURE_RNL are defined under +include/media/si4713.h. + +Stereo/Mono and RDS subchannels +=============================== + +The device can also be configured using the available sub channels for +transmission. To do that use S/G_MODULATOR ioctl and configure txsubchans properly. +Refer to v4l2-spec for proper use of this ioctl. + +Testing +======= +Testing is usually done with v4l2-ctl utility for managing FM tuner cards. +The tool can be found in v4l-dvb repository under v4l2-apps/util directory. + +Example for setting rds ps name: +# v4l2-ctl -d /dev/radio0 --set-ctrl=rds_ps_name="Dummy" +Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Signature · 1 line
Eduardo Valentin
Re: [PATCHv10 8/8] FMTx: si4713: Add document file
Quoted 94 lines · Valentin Eduardo (Nokia-D/Helsinki)
Quoted 84 lines · ext Hans Verkuil
Quoted 83 lines · On Friday 24 July 2009 18:37:28 Eduardo Valentin wrote:
This patch adds a document file for si4713 device driver. It describes the driver interfaces and organization.
Signed-off-by Eduardo Valentin <[email protected]>--- linux/Documentation/video4linux/si4713.txt | 175 ++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) create mode 100644 linux/Documentation/video4linux/si4713.txtlinux/Documentation/video4linux/si4713.txt new file +68
-0@@ -0,0 +1,175 @@ +Driver for I2C radios for the Silicon Labs Si4713 FM Radio Transmitters + +Copyright (c) 2009 Nokia Corporation +Contact: Eduardo Valentin <[email protected]> + + +Information about the Device +============================ +This chip is a Silicon Labs product. It is a I2C device, currently on 0×63 address. +Basically, it has transmission and signal noise level measurement features. + +The Si4713 integrates transmit functions for FM broadcast stereo transmission. +The chip also allows integrated receive power scanning to identify low signal +power FM channels. + +The chip is programmed using commands and responses. There are also several +properties which can change the behavior of this chip. + +Users must comply with local regulations on radio frequency (RF) transmission. + +Device driver description +========================= +There are two modules to handle this device. One is a I2C device driver +and the other is a platform driver. + +The I2C device driver exports a v4l2-subdev interface to the kernel. +All properties can also be accessed by v4l2 extended controls interface, by +using the v4l2-subdev calls (g_ext_ctrls, s_ext_ctrls). + +The platform device driver exports a v4l2 radio device interface to user land. +So, it uses the I2C device driver as a sub device in order to send the user +commands to the actual device. Basically it is a wrapper to the I2C device driver. + +Applications can use v4l2 radio API to specify frequency of operation, mute state, +etc. But mostly of its properties will be present in the extended controls. + +When the v4l2 mute property is set to 1 (true), the driver will turn the chip off. + +Properties description +====================== + +The properties can be accessed using v4l2 extended controls. +Here is an output from v4l2-ctl util: + +# v4l2-ctl -d /dev/radio0 --all -l +Driver Info: + Driver name : radio-si4713 + Card type : Silicon Labs Si4713 Modulator + Bus info : + Driver version: 0 + Capabilities : 0x00080800 + RDS Output + Modulator +Audio output: 0 (FM Modulator Audio Out) +Frequency: 1545600 (96.600000 MHz) +Video Standard = 0x00000000 +Modulator: + Name : FM Modulator + Capabilities : 62.5 Hz stereo rds + Frequency range : 76.0 MHz - 108.0 MHz + Available subchannels: mono rds + +User Controls + + mute (bool) : default=1 value=0 + +FM Radio Modulator Controls +Quoted 8 lines
linux/Documentation/video4linux/si4713.txt line 72
Quoted 4 lines
linux/Documentation/video4linux/si4713.txt new file +4
-0+ rds_program_id (int) : min=0 max=65535 step=1 default=0 value=0 + rds_program_type (int) : min=0 max=31 step=1 default=0 value=0 + rds_ps_name (str) : value='Si4713 ' len=1024 +' len=1024 rds_radio_text (str) : value='Si4713This doesn't look right. I think this output is from an old v4l2-ctl version. I'd like to see this output anyway using the latest v4l2-ctl version as I haven't been able to test it myself.
Quoted 1 line
Yeah. My bad, forgot to update here. This is the output from the older version.
I've just checked that now v4l2-ctl does not report rds subchannel for txsubchannel. Just to confirm this is something which is missing right?
In that case, I can include this minor addition also in v11.
Quoted 124 lines
Quoted 4 lines
Based on this output it also looks as if the
rds_radio_textstring has a \r at the end. If so, is it supposed to be there?Yeah, the \r it is required for Radio Text.
Quoted 113 lines
Regards,
Hans
Quoted 103 lines
linux/Documentation/video4linux/si4713.txt new file +103
-0+ audio_limiter_feature_enabled (bool) : default=1 value=1 + audio_limiter_release_time (int) : min=250 max=102390 step=50 default=5010 value=5010 flags=slider + audio_limiter_deviation (int) : min=0 max=90000 step=10 default=66250 value=1020 flags=slider +audio_compression_feature_enabl (bool) : default=1 value=1 + audio_compression_gain (int) : min=0 max=20 step=1 default=15 value=15 flags=slider + audio_compression_threshold (int) : min=-40 max=0 step=1 default=-40 value=-40 flags=slider + audio_compression_attack_time (int) : min=0 max=5000 step=500 default=0 value=0 flags=slider + audio_compression_release_time (int) : min=100000 max=1000000 step=100000 default=1000000 value=1000000 flags=slider + pilot_tone_feature_enabled (bool) : default=1 value=1 + pilot_tone_deviation (int) : min=0 max=90000 step=10 default=6750 value=6750 flags=slider + pilot_tone_frequency (int) : min=0 max=19000 step=1 default=19000 value=19000 flags=slider + pre_emphasis_settings (menu) : min=0 max=2 default=1 value=1 + tune_power_level (int) : min=0 max=120 step=1 default=88 value=120 flags=slider + tune_antenna_capacitor (int) : min=0 max=191 step=1 default=0 value=112 flags=slider + +Here is a summary of them: + +* Pilot is an audible tone sent by the device. + +pilot_frequency - Configures the frequency of the stereo pilot tone. +pilot_deviation - Configures pilot tone frequency deviation level. +pilot_enabled - Enables or disables the pilot tone feature. + +* The si4713 device is capable of applying audio compression to the transmitted signal. + +acomp_enabled - Enables or disables the audio dynamic range control feature. +acomp_gain - Sets the gain for audio dynamic range control. +acomp_threshold - Sets the threshold level for audio dynamic range control. +acomp_attack_time - Sets the attack time for audio dynamic range control. +acomp_release_time - Sets the release time for audio dynamic range control. + +* Limiter setups audio deviation limiter feature. Once a over deviation occurs, +it is possible to adjust the front-end gain of the audio input and always +prevent over deviation. + +limiter_enabled - Enables or disables the limiter feature. +limiter_deviation - Configures audio frequency deviation level. +limiter_release_time - Sets the limiter release time. + +* Tuning power + +power_level - Sets the output power level for signal transmission. +antenna_capacitor - This selects the value of antenna tuning capacitor manually +or automatically if set to zero. + +* RDS related + +rds_ps_name - Sets the RDS ps name field for transmission. +rds_radio_text - Sets the RDS radio text for transmission. +rds_pi - Sets the RDS PI field for transmission. +rds_pty - Sets the RDS PTY field for transmission. + +* Region related + +preemphasis - sets the preemphasis to be applied for transmission. + +RNL +=== + +This device also has an interface to measure received noise level. To do that, you should +ioctl the device node. Here is an code of example: + +int main (int argc, char *argv[]) +{ + struct si4713_rnl rnl; + int fd = open("/dev/radio0", O_RDWR); + int rval; + + if (argc < 2) + return -EINVAL; + + if (fd < 0) + return fd; + + sscanf(argv[1], "%d", &rnl.frequency); + + rval = ioctl(fd, SI4713_IOC_MEASURE_RNL, &rnl); + if (rval < 0) + return rval; + + printf("received noise level: %d\n", rnl.rnl); + + close(fd); +} + +The struct si4713_rnl and SI4713_IOC_MEASURE_RNL are defined under +include/media/si4713.h. + +Stereo/Mono and RDS subchannels +=============================== + +The device can also be configured using the available sub channels for +transmission. To do that use S/G_MODULATOR ioctl and configure txsubchans properly. +Refer to v4l2-spec for proper use of this ioctl. + +Testing +======= +Testing is usually done with v4l2-ctl utility for managing FM tuner cards. +The tool can be found in v4l-dvb repository under v4l2-apps/util directory. + +Example for setting rds ps name: +# v4l2-ctl -d /dev/radio0 --set-ctrl=rds_ps_name="Dummy" +Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG TelecomSignature · 1 line
Eduardo Valentin
Signature · 1 line
Eduardo Valentin
Re: [PATCHv10 8/8] FMTx: si4713: Add document file
Quoted 95 lines · On Saturday 25 July 2009 15:48:58 Eduardo Valentin wrote:
Quoted 94 lines · Valentin Eduardo (Nokia-D/Helsinki)
Quoted 92 lines · ext Hans Verkuil
Quoted 77 lines · On Friday 24 July 2009 18:37:28 Eduardo Valentin wrote:
This patch adds a document file for si4713 device driver. It describes the driver interfaces and organization.
Signed-off-by Eduardo Valentin <[email protected]>--- linux/Documentation/video4linux/si4713.txt | 175 ++++++++++++++++++++++++++++ 1 files changed, 175 insertions(+), 0 deletions(-) create mode 100644 linux/Documentation/video4linux/si4713.txtlinux/Documentation/video4linux/si4713.txt new file +62
-0@@ -0,0 +1,175 @@ +Driver for I2C radios for the Silicon Labs Si4713 FM Radio Transmitters + +Copyright (c) 2009 Nokia Corporation +Contact: Eduardo Valentin <[email protected]> + + +Information about the Device +============================ +This chip is a Silicon Labs product. It is a I2C device, currently on 0×63 address. +Basically, it has transmission and signal noise level measurement features. + +The Si4713 integrates transmit functions for FM broadcast stereo transmission. +The chip also allows integrated receive power scanning to identify low signal +power FM channels. + +The chip is programmed using commands and responses. There are also several +properties which can change the behavior of this chip. + +Users must comply with local regulations on radio frequency (RF) transmission. + +Device driver description +========================= +There are two modules to handle this device. One is a I2C device driver +and the other is a platform driver. + +The I2C device driver exports a v4l2-subdev interface to the kernel. +All properties can also be accessed by v4l2 extended controls interface, by +using the v4l2-subdev calls (g_ext_ctrls, s_ext_ctrls). + +The platform device driver exports a v4l2 radio device interface to user land. +So, it uses the I2C device driver as a sub device in order to send the user +commands to the actual device. Basically it is a wrapper to the I2C device driver. + +Applications can use v4l2 radio API to specify frequency of operation, mute state, +etc. But mostly of its properties will be present in the extended controls. + +When the v4l2 mute property is set to 1 (true), the driver will turn the chip off. + +Properties description +====================== + +The properties can be accessed using v4l2 extended controls. +Here is an output from v4l2-ctl util: + +# v4l2-ctl -d /dev/radio0 --all -l +Driver Info: + Driver name : radio-si4713 + Card type : Silicon Labs Si4713 Modulator + Bus info : + Driver version: 0 + Capabilities : 0x00080800 + RDS Output + Modulator +Audio output: 0 (FM Modulator Audio Out) +Frequency: 1545600 (96.600000 MHz) +Video Standard = 0x00000000 +Modulator: + Name : FM Modulator + Capabilities : 62.5 Hz stereo rds + Frequency range : 76.0 MHz - 108.0 MHz + Available subchannels: mono rds +linux/Documentation/video4linux/si4713.txt line 72
Quoted 10 lines
linux/Documentation/video4linux/si4713.txt new file +10
-0+User Controls + + mute (bool) : default=1 value=0 + +FM Radio Modulator Controls + + rds_program_id (int) : min=0 max=65535 step=1 default=0 value=0 + rds_program_type (int) : min=0 max=31 step=1 default=0 value=0 + rds_ps_name (str) : value='Si4713 ' len=1024 +' len=1024 rds_radio_text (str) : value='Si4713This doesn't look right. I think this output is from an old v4l2-ctl version. I'd like to see this output anyway using the latest v4l2-ctl version as I haven't been able to test it myself.
Quoted 5 lines
Quoted 1 line
Yeah. My bad, forgot to update here. This is the output from the older version.
I've just checked that now v4l2-ctl does not report rds subchannel for txsubchannel. Just to confirm this is something which is missing right?
Yes, that was missing. I've just added it to my tree. Thanks for the report.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
In reply to Eduardo ValentinQuoted 1,367 lines · On Friday 24 July 2009 18:37:26 Eduardo Valentin wrote:
This patch adds files to control si4713 devices. Internal functions to control device properties and initialization procedures are into these files. Also, a v4l2 subdev interface is also exported. This way other drivers can use this as v4l2 i2c subdevice.
Signed-off-by Eduardo Valentin <[email protected]>--- linux/drivers/media/radio/si4713-i2c.c | 2034 ++++++++++++++++++++++++++++++++ linux/drivers/media/radio/si4713-i2c.h | 228 ++++ linux/include/media/si4713.h | 49 + 3 files changed, 2311 insertions(+), 0 deletions(-) create mode 100644 linux/drivers/media/radio/si4713-i2c.c create mode 100644 linux/drivers/media/radio/si4713-i2c.h create mode 100644 linux/include/media/si4713.hlinux/drivers/media/radio/si4713-i2c.c new file +1345
-0@@ -0,0 +1,2034 @@ +/* +* drivers/media/radio/si4713-i2c.c +* +* Silicon Labs Si4713 FM Radio Transmitter I2C commands. +* +* Copyright (c) 2009 Nokia Corporation +* Contact: Eduardo Valentin <[email protected]> +* +* 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/mutex.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/i2c.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 <[email protected]>" ); +MODULE_DESCRIPTION ("I2C driver for Si4713 FM Radio Transmitter" ); +MODULE_VERSION ("0.0.1" ); + +#define DEFAULT_RDS_PI 0x00 +#define DEFAULT_RDS_PTY 0x00 +#define DEFAULT_RDS_PS_NAME "Si4713 " +#define DEFAULT_RDS_RADIO_TEXT DEFAULT_RDS_PS_NAME +#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)); +#define get_mute (p) (p & 0x01) + +#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; +} + +static unsigned long dev_to_usecs (int value,unsigned long const array[], +int size) +{ +int i; +int rval = -EINVAL ; + +for (i =0 ; i < size /2 ; i++) +if (array[i *2 ] == value) { + rval = array[(i *2 ) +1 ]; +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 ; + + sdev->platform_data->set_power (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 { + sdev->platform_data->set_power (0 ); + } + +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" ); + sdev->platform_data->set_power (0 ); + 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 ]; + +mutex_lock (&sdev->mutex); + + rval =si4713_send_command (sdev,SI4713_CMD_GET_REV , +NULL ,0 , + resp,ARRAY_SIZE (resp), +DEFAULT_TIMEOUT ); + +if (rval <0 ) + goto unlock; + +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 ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* +* si4713_wait_stc - Waits STC interrupt and clears status bits. Usefull +* 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 +* @intstatus: returns current interrupt status +* @cbavail: returns the number of available circular buffer blocks. +* @cbused: returns the number of used circular buffer blocks. +* @fifoavail: returns the number of available fifo buffer blocks. +* @fifoused: returns the number of used fifo buffer blocks. +*/ +static int si4713_tx_rds_buff (struct si4713_device *sdev,u8 mode,u16 rdsb, +u16 rdsc,u16 rdsd,u8 *intstatus,u8 *cbavail, +u8 *cbused,u8 *fifoavail,u8 *fifoused) +{ +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 ]); + *intstatus = val[1 ]; + *cbavail = val[2 ]; + *cbused = val[3 ]; + *fifoavail = val[4 ]; + *fifoused = val[5 ]; +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__, *intstatus, + *cbavail, *cbused, *fifoavail, *fifoused); + } + +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) +{ +int rval; + +mutex_lock (&sdev->mutex); + +if (value) + rval =si4713_powerup (sdev); +else + rval =si4713_powerdown (sdev); + +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_set_mute (struct si4713_device *sdev,u16 mute) +{ +int rval =0 ; + + mute =set_mute (mute); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) + rval =si4713_write_property (sdev, +SI4713_TX_LINE_INPUT_MUTE , mute); + +if (rval >=0 ) + sdev->mute =get_mute (mute); + +mutex_unlock (&sdev->mutex); + +return rval; +} + +static int si4713_set_rds_ps_name (struct si4713_device *sdev,char *ps_name) +{ +int rval =0 , i; +u8 len =0 ; +u8 *tmp; + +if (!strlen (ps_name)) +return -EINVAL ; + + tmp =kzalloc (MAX_RDS_PS_NAME +1 ,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +strncpy (tmp, ps_name,MAX_RDS_PS_NAME ); + +mutex_lock (&sdev->mutex); + +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 )), + tmp + i); +if (rval <0 ) + goto unlock; + } + +/* Setup the size to be sent */ + len =strlen (tmp) -1 ; + + rval =si4713_write_property (sdev, +SI4713_TX_RDS_PS_MESSAGE_COUNT , +rds_ps_nblocks (len)); +if (rval <0 ) + goto unlock; + + rval =si4713_write_property (sdev, +SI4713_TX_RDS_PS_REPEAT_COUNT , +DEFAULT_RDS_PS_REPEAT_COUNT *2 ); +if (rval <0 ) + goto unlock; + } + +strncpy (sdev->rds_info.ps_name, tmp,MAX_RDS_PS_NAME ); + +unlock: +mutex_unlock (&sdev->mutex); +kfree (tmp); +return rval; +} + +static int si4713_set_rds_radio_text (struct si4713_device *sdev, +char *radio_text) +{ +int rval =0 , i; +u16 t_index =0 ; +u8 s, a, u, fa, fu, b_index =0 , cr_inserted =0 ; +u8 *tmp; + +if (!strlen (radio_text)) +return -EINVAL ; + + tmp =kzalloc (MAX_RDS_RADIO_TEXT +1 ,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +strncpy (tmp, radio_text,MAX_RDS_RADIO_TEXT ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_tx_rds_buff (sdev,RDS_BLOCK_CLEAR ,0 ,0 ,0 , + &s, &a, &u, &fa, &fu); +if (rval <0 ) + goto unlock; +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 (!tmp[t_index + i] || + tmp[t_index + i] == \ +RDS_CARRIAGE_RETURN ) { + tmp[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 (tmp[t_index], + tmp[t_index +1 ]), +compose_u16 (tmp[t_index +2 ], + tmp[t_index +3 ]), + &s, &a, &u, &fa, &fu); +if (rval <0 ) + goto unlock; + + t_index +=RDS_RADIOTEXT_BLK_SIZE ; + +if (cr_inserted) +break ; + }while (u < a); + } + +strncpy (sdev->rds_info.radio_text, tmp,MAX_RDS_RADIO_TEXT ); + +unlock: +mutex_unlock (&sdev->mutex); +kfree (tmp); +return rval; +} + +static int si4713_choose_econtrol_action (struct si4713_device *sdev,u32 id, +u32 **shadow,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 ; + *shadow = &sdev->rds_info.pi; +break ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : + *property =SI4713_TX_ACOMP_THRESHOLD ; + *mul =1 ; + *shadow = &sdev->acomp_info.threshold; +break ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN : + *property =SI4713_TX_ACOMP_GAIN ; + *mul =1 ; + *shadow = &sdev->acomp_info.gain; +break ; +case V4L2_CID_PILOT_TONE_FREQUENCY : + *property =SI4713_TX_PILOT_FREQUENCY ; + *mul =1 ; + *shadow = &sdev->pilot_info.frequency; +break ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : + *property =SI4713_TX_ACOMP_ATTACK_TIME ; + *mul =ATTACK_TIME_UNIT ; + *shadow = &sdev->acomp_info.attack_time; +break ; +case V4L2_CID_PILOT_TONE_DEVIATION : + *property =SI4713_TX_PILOT_DEVIATION ; + *mul =10 ; + *shadow = &sdev->pilot_info.deviation; +break ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION : + *property =SI4713_TX_AUDIO_DEVIATION ; + *mul =10 ; + *shadow = &sdev->limiter_info.deviation; +break ; +case V4L2_CID_RDS_TX_DEVIATION : + *property =SI4713_TX_RDS_DEVIATION ; + *mul =1 ; + *shadow = &sdev->rds_info.deviation; +break ; + +case V4L2_CID_RDS_TX_PTY : + *property =SI4713_TX_RDS_PS_MISC ; + *bit =5 ; + *mask =0x1F <<5 ; + *shadow = &sdev->rds_info.pty; +break ; +case V4L2_CID_AUDIO_LIMITER_ENABLED : + *property =SI4713_TX_ACOMP_ENABLE ; + *bit =1 ; + *mask =1 <<1 ; + *shadow = &sdev->limiter_info.enabled; +break ; +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : + *property =SI4713_TX_ACOMP_ENABLE ; + *bit =0 ; + *mask =1 <<0 ; + *shadow = &sdev->acomp_info.enabled; +break ; +case V4L2_CID_PILOT_TONE_ENABLED : + *property =SI4713_TX_COMPONENT_ENABLE ; + *bit =0 ; + *mask =1 <<0 ; + *shadow = &sdev->pilot_info.enabled; +break ; + +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : + *property =SI4713_TX_LIMITER_RELEASE_TIME ; + *table = limiter_times; + *size =ARRAY_SIZE (limiter_times); + *shadow = &sdev->limiter_info.release_time; +break ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : + *property =SI4713_TX_ACOMP_RELEASE_TIME ; + *table = acomp_rtimes; + *size =ARRAY_SIZE (acomp_rtimes); + *shadow = &sdev->acomp_info.release_time; +break ; +case V4L2_CID_FM_TX_PREEMPHASIS : + *property =SI4713_TX_PREEMPHASIS ; + *table = preemphasis_values; + *size =ARRAY_SIZE (preemphasis_values); + *shadow = &sdev->preemphasis; +break ; + +default : + rval = -EINVAL ; + }; + +return rval; +} + +/* write string property */ +static int si4713_write_econtrol_string (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +char ps_name[MAX_RDS_PS_NAME +1 ]; +char radio_text[MAX_RDS_RADIO_TEXT +1 ]; +int size; +s32 rval =0 ; + +switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : + size = control->length -1 ; +if (size >MAX_RDS_PS_NAME ) + size =MAX_RDS_PS_NAME ; + rval =copy_from_user (ps_name, control->string, size); +if (rval <0 ) + goto exit; + ps_name[size] ='\0' ; + rval =si4713_set_rds_ps_name (sdev, ps_name); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : + size = control->length -1 ; +if (size >MAX_RDS_RADIO_TEXT ) + size =MAX_RDS_RADIO_TEXT ; + rval =copy_from_user (radio_text, control->string, size); +if (rval <0 ) + goto exit; + radio_text[size] ='\0' ; + rval =si4713_set_rds_radio_text (sdev, radio_text); +break ; + +default : + rval = -EINVAL ; +break ; + }; + +exit: +return rval; +} + +/* properties which use tx_tune_power*/ +static int si4713_write_econtrol_tune (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; +u8 power, antcap; + +mutex_lock (&sdev->mutex); + +switch (control->id) { +case V4L2_CID_TUNE_POWER_LEVEL : + power = control->value; + antcap = sdev->antenna_capacitor; +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + power = sdev->power_level; + antcap = control->value; +break ; +default : + rval = -EINVAL ; + goto unlock; + }; + +if (sdev->power_state) + rval =si4713_tx_tune_power (sdev, power, antcap); + +if (rval ==0 ) { + sdev->power_level = power; + sdev->antenna_capacitor = antcap; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_queryctrl (struct v4l2_subdev *sd,struct v4l2_queryctrl *qc); + +static int validate_range (struct v4l2_subdev *sd, +struct v4l2_ext_control *control) +{ +struct v4l2_queryctrl vqc; +int rval; + + vqc.id = control->id; + rval =si4713_queryctrl (sd, &vqc); +if (rval <0 ) + goto exit; + +if (control->value < vqc.minimum || control->value > vqc.maximum) + rval = -EDOM ; + +exit: +return rval; +} + +static int si4713_write_econtrol_integers (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval; +u32 *shadow =NULL , val =0 ; +s32 bit =0 , mask =0 ; +u16 property =0 ; +int mul =0 ; +unsigned long *table =NULL ; +int size =0 ; + + rval =validate_range (&sdev->sd, control); +if (rval <0 ) + goto exit; + + rval =si4713_choose_econtrol_action (sdev, control->id, &shadow, &bit, + &mask, &property, &mul, &table, &size); +if (rval <0 ) + goto exit; + + val = control->value; +if (mul) { + val = control->value / mul; + }else if (table) { + rval =usecs_to_dev (control->value, table, size); +if (rval <0 ) + goto exit; + val = rval; + rval =0 ; + } + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +if (mask) { + rval =si4713_read_property (sdev, property, &val); +if (rval <0 ) + goto unlock; + val =set_bits (val, control->value, bit, mask); + } + + rval =si4713_write_property (sdev, property, val); +if (rval <0 ) + goto unlock; +if (mask) + val = control->value; + } + +if (mul) { + *shadow = val * mul; + }else if (table) { + rval =dev_to_usecs (val, table, size); +if (rval <0 ) + goto unlock; + *shadow = rval; + rval =0 ; + }else { + *shadow = val; + } + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +static int si4713_s_frequency (struct v4l2_subdev *sd,struct v4l2_frequency *f); +static int si4713_s_modulator (struct v4l2_subdev *sd,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_ext_control ctrl; +struct v4l2_frequency f; +struct v4l2_modulator vm; +struct si4713_device *tmp; +int rval =0 ; + + tmp =kmalloc (sizeof (*tmp),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +/* Get a local copy to avoid race */ +mutex_lock (&sdev->mutex); +memcpy (tmp, sdev,sizeof (*sdev)); +mutex_unlock (&sdev->mutex); + + ctrl.id =V4L2_CID_RDS_TX_PI ; + ctrl.value = tmp->rds_info.pi; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_THRESHOLD ; + ctrl.value = tmp->acomp_info.threshold; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_GAIN ; + ctrl.value = tmp->acomp_info.gain; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_FREQUENCY ; + ctrl.value = tmp->pilot_info.frequency; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME ; + ctrl.value = tmp->acomp_info.attack_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_DEVIATION ; + ctrl.value = tmp->pilot_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_DEVIATION ; + ctrl.value = tmp->limiter_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_DEVIATION ; + ctrl.value = tmp->rds_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_PTY ; + ctrl.value = tmp->rds_info.pty; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_ENABLED ; + ctrl.value = tmp->limiter_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_ENABLED ; + ctrl.value = tmp->acomp_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_ENABLED ; + ctrl.value = tmp->pilot_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_RELEASE_TIME ; + ctrl.value = tmp->limiter_info.release_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME ; + ctrl.value = tmp->acomp_info.release_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_FM_TX_PREEMPHASIS ; + ctrl.value = tmp->preemphasis; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_PS_NAME ; + rval |=si4713_set_rds_ps_name (sdev, tmp->rds_info.ps_name); + + ctrl.id =V4L2_CID_RDS_TX_RADIO_TEXT ; + rval |=si4713_set_rds_radio_text (sdev, tmp->rds_info.radio_text); + +/* Device procedure needs to set frequency first */ + f.frequency = tmp->frequency ? tmp->frequency :DEFAULT_FREQUENCY ; + f.frequency =si4713_to_v4l2 (f.frequency); + rval |=si4713_s_frequency (&sdev->sd, &f); + + ctrl.id =V4L2_CID_TUNE_POWER_LEVEL ; + ctrl.value = tmp->power_level; + rval |=si4713_write_econtrol_tune (sdev, &ctrl); + + ctrl.id =V4L2_CID_TUNE_ANTENNA_CAPACITOR ; + ctrl.value = tmp->antenna_capacitor; + rval |=si4713_write_econtrol_tune (sdev, &ctrl); + + vm.index =0 ; +if (tmp->stereo) + vm.txsubchans =V4L2_TUNER_SUB_STEREO ; +else + vm.txsubchans =V4L2_TUNER_SUB_MONO ; +if (tmp->rds_info.enabled) + vm.txsubchans |=V4L2_TUNER_SUB_RDS ; +si4713_s_modulator (&sdev->sd, &vm); + +kfree (tmp); + +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 ) + goto exit; + + rval =si4713_checkrev (sdev); +if (rval <0 ) + goto exit; + + rval =si4713_set_power_state (sdev,POWER_OFF ); +if (rval <0 ) + goto exit; + +mutex_lock (&sdev->mutex); + + sdev->rds_info.pi =DEFAULT_RDS_PI ; + sdev->rds_info.pty =DEFAULT_RDS_PTY ; + sdev->rds_info.deviation =DEFAULT_RDS_DEVIATION ; +strlcpy (sdev->rds_info.ps_name,DEFAULT_RDS_PS_NAME ,MAX_RDS_PS_NAME ); +strlcpy (sdev->rds_info.radio_text,DEFAULT_RDS_RADIO_TEXT , +MAX_RDS_RADIO_TEXT ); + sdev->rds_info.enabled =1 ; + + sdev->limiter_info.release_time =DEFAULT_LIMITER_RTIME ; + sdev->limiter_info.deviation =DEFAULT_LIMITER_DEV ; + sdev->limiter_info.enabled =1 ; + + sdev->pilot_info.deviation =DEFAULT_PILOT_DEVIATION ; + sdev->pilot_info.frequency =DEFAULT_PILOT_FREQUENCY ; + sdev->pilot_info.enabled =1 ; + + sdev->acomp_info.release_time =DEFAULT_ACOMP_RTIME ; + sdev->acomp_info.attack_time =DEFAULT_ACOMP_ATIME ; + sdev->acomp_info.threshold =DEFAULT_ACOMP_THRESHOLD ; + sdev->acomp_info.gain =DEFAULT_ACOMP_GAIN ; + sdev->acomp_info.enabled =1 ; + + sdev->frequency =DEFAULT_FREQUENCY ; + sdev->preemphasis =DEFAULT_PREEMPHASIS ; + sdev->mute =DEFAULT_MUTE ; + sdev->power_level =DEFAULT_POWER_LEVEL ; + sdev->antenna_capacitor =0 ; + sdev->stereo =1 ; + sdev->tune_rnl =DEFAULT_TUNE_RNL ; + +mutex_unlock (&sdev->mutex); + +exit: +return rval; +} +
linux/drivers/media/radio/si4713-i2c.c line 1355
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.c new file +10
-0+/* read string property */ +static int si4713_read_econtrol_string (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; + +switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : +if (strlen (sdev->rds_info.ps_name) +1 > control->length) { + control->length =strlen (sdev->rds_info.ps_name) +1 ;
I recommend setting length to the actual maximum MAX_RDS_PS_NAME+1.
linux/drivers/media/radio/si4713-i2c.c line 1365
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.c new file +10
-0+ rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.ps_name, +strlen (sdev->rds_info.ps_name) +1 ); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : +if (strlen (sdev->rds_info.radio_text) +1 > control->length) { + control->length =strlen (sdev->rds_info.radio_text) +1 ;
Ditto.
Quoted 836 lines
linux/drivers/media/radio/si4713-i2c.c new file +669
-0+ rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.radio_text, +strlen (sdev->rds_info.radio_text) +1 ); +break ; + +default : + rval = -EINVAL ; +break ; + }; + +exit: +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; + + sdev->power_level = p; + sdev->antenna_capacitor = a; + sdev->tune_rnl = n; + +exit: +return rval; +} + +/* properties which use tx_tune_status */ +static int si4713_read_econtrol_tune (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_update_tune_status (sdev); +if (rval <0 ) + goto unlock; + } + +switch (control->id) { +case V4L2_CID_TUNE_POWER_LEVEL : + control->value = sdev->power_level; +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + control->value = sdev->antenna_capacitor; +break ; +default : + rval = -EINVAL ; + }; + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_read_econtrol_integers (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval; +u32 *shadow =NULL , val =0 ; +s32 bit =0 , mask =0 ; +u16 property =0 ; +int mul =0 ; +unsigned long *table =NULL ; +int size =0 ; + + rval =si4713_choose_econtrol_action (sdev, control->id, &shadow, &bit, + &mask, &property, &mul, &table, &size); +if (rval <0 ) + goto exit; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev, property, &val); +if (rval <0 ) + goto unlock; + +/* Keep negative values for threshold */ +if (control->id ==V4L2_CID_AUDIO_COMPRESSION_THRESHOLD ) + *shadow = (s16 )val; +else if (mask) + *shadow =get_status_bit (val, bit, mask); +else if (mul) + *shadow = val * mul; +else + *shadow =dev_to_usecs (val, table, size); + } + + control->value = *shadow; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +/* +* Video4Linux Subdev Interface +*/ +/* si4713_s_ext_ctrls - set extended controls value */ +static int si4713_s_ext_ctrls (struct v4l2_subdev *sd, +struct v4l2_ext_controls *ctrls) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int i; + +if (ctrls->ctrl_class !=V4L2_CTRL_CLASS_FM_TX ) +return -EINVAL ; + +for (i =0 ; i < ctrls->count; i++) { +int err; + + err =si4713_write_econtrol_integers (sdev, ctrls->controls + i); +if (err <0 ) + err =si4713_write_econtrol_string (sdev, + ctrls->controls + i); +if (err <0 ) + err =si4713_write_econtrol_tune (sdev, + ctrls->controls + i); + +if (err <0 ) { + ctrls->error_idx = i; +return err; + } + } + +return 0 ; +} + +/* si4713_g_ext_ctrls - get extended controls value */ +static int si4713_g_ext_ctrls (struct v4l2_subdev *sd, +struct v4l2_ext_controls *ctrls) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int i; + +if (ctrls->ctrl_class !=V4L2_CTRL_CLASS_FM_TX ) +return -EINVAL ; + +for (i =0 ; i < ctrls->count; i++) { +int err; + + err =si4713_read_econtrol_tune (sdev, ctrls->controls + i); +if (err <0 ) + err =si4713_read_econtrol_string (sdev, + ctrls->controls + i); +if (err <0 ) + err =si4713_read_econtrol_integers (sdev, + ctrls->controls + i); + +if (err <0 ) { + ctrls->error_idx = i; +return err; + } + } + +return 0 ; +} + +/* si4713_queryctrl - enumerate control items */ +static int si4713_queryctrl (struct v4l2_subdev *sd,struct v4l2_queryctrl *qc) +{ +int rval =0 ; + +switch (qc->id) { +/* User class controls */ +case V4L2_CID_AUDIO_MUTE : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,DEFAULT_MUTE ); +break ; +/* FM_TX class controls */ +case V4L2_CID_RDS_TX_PI : + rval =v4l2_ctrl_query_fill (qc,0 ,0xFFFF ,1 ,DEFAULT_RDS_PI ); +break ; +case V4L2_CID_RDS_TX_PTY : + rval =v4l2_ctrl_query_fill (qc,0 ,31 ,1 ,DEFAULT_RDS_PTY ); +break ; +case V4L2_CID_RDS_TX_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_DEVIATION , +10 ,DEFAULT_RDS_DEVIATION ); +break ; +case V4L2_CID_RDS_TX_PS_NAME : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_PS_NAME +1 ,0 ,0 ); +break ; +case V4L2_CID_RDS_TX_RADIO_TEXT : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_RADIO_TEXT +1 , +0 ,0 ); +break ; + +case V4L2_CID_AUDIO_LIMITER_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : + rval =v4l2_ctrl_query_fill (qc,250 ,MAX_LIMITER_RELEASE_TIME , +50 ,DEFAULT_LIMITER_RTIME ); +break ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_LIMITER_DEVIATION , +10 ,DEFAULT_LIMITER_DEV ); +break ; + +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_ACOMP_GAIN ,1 , +DEFAULT_ACOMP_GAIN ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : + rval =v4l2_ctrl_query_fill (qc,MIN_ACOMP_THRESHOLD , +MAX_ACOMP_THRESHOLD ,1 , +DEFAULT_ACOMP_THRESHOLD ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_ACOMP_ATTACK_TIME , +500 ,DEFAULT_ACOMP_ATIME ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : + rval =v4l2_ctrl_query_fill (qc,100000 ,MAX_ACOMP_RELEASE_TIME , +100000 ,DEFAULT_ACOMP_RTIME ); +break ; + +case V4L2_CID_PILOT_TONE_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_PILOT_TONE_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_PILOT_DEVIATION , +10 ,DEFAULT_PILOT_DEVIATION ); +break ; +case V4L2_CID_PILOT_TONE_FREQUENCY : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_PILOT_FREQUENCY , +1 ,DEFAULT_PILOT_FREQUENCY ); +break ; + +case V4L2_CID_FM_TX_PREEMPHASIS : + rval =v4l2_ctrl_query_fill (qc,V4L2_PREEMPHASIS_DISABLED , + V4L2_PREEMPHASIS_75_uS,1 , + V4L2_PREEMPHASIS_50_uS); +break ; +case V4L2_CID_TUNE_POWER_LEVEL : + rval =v4l2_ctrl_query_fill (qc,0 ,120 ,1 ,DEFAULT_POWER_LEVEL ); +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + rval =v4l2_ctrl_query_fill (qc,0 ,191 ,1 ,0 ); +break ; +default : + rval = -EINVAL ; +break ; + }; + +return rval; +} + +/* si4713_g_ctrl - get the value of a control */ +static int si4713_g_ctrl (struct v4l2_subdev *sd,struct v4l2_control *ctrl) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; + +if (!sdev) +return -ENODEV ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev,SI4713_TX_LINE_INPUT_MUTE , + &sdev->mute); + +if (rval <0 ) + goto unlock; + } + +switch (ctrl->id) { +case V4L2_CID_AUDIO_MUTE : + ctrl->value =get_mute (sdev->mute); +break ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* si4713_s_ctrl - set the value of a control */ +static int si4713_s_ctrl (struct v4l2_subdev *sd,struct v4l2_control *ctrl) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; + +if (!sdev) +return -ENODEV ; + +switch (ctrl->id) { +case V4L2_CID_AUDIO_MUTE : +if (ctrl->value) { + rval =si4713_set_mute (sdev, ctrl->value); +if (rval <0 ) + goto exit; + + rval =si4713_set_power_state (sdev,POWER_DOWN ); + }else { + rval =si4713_set_power_state (sdev,POWER_UP ); +if (rval <0 ) + goto exit; + + rval =si4713_setup (sdev); +if (rval <0 ) + goto exit; + + rval =si4713_set_mute (sdev, ctrl->value); + } +break ; + } + +exit: +return rval; +} + +/* si4713_ioctl - deal with private ioctls (only rnl for now) */ +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 ; + +mutex_lock (&sdev->mutex); +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 ) + goto unlock; +/* get results from tune status */ + rval =si4713_update_tune_status (sdev); +if (rval <0 ) + goto unlock; + } + rnl->rnl = sdev->tune_rnl; +break ; + +default : +/* nothing */ + rval = -ENOIOCTLCMD ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = { + .queryctrl = si4713_queryctrl, + .g_ext_ctrls = si4713_g_ext_ctrls, + .s_ext_ctrls = si4713_s_ext_ctrls, + .g_ctrl = si4713_g_ctrl, + .s_ctrl = si4713_s_ctrl, + .ioctl = si4713_ioctl, +}; + +/* 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) { + rval = -ENODEV ; + goto exit; + } + +if (vm->index >0 ) { + rval = -EINVAL ; + goto exit; + } + +strncpy (vm->name,"FM Modulator" ,32 ); + vm->capability =V4L2_TUNER_CAP_STEREO |V4L2_TUNER_CAP_LOW | +V4L2_TUNER_CAP_RDS ; + +/* Report current frequency range limits */ + vm->rangelow =si4713_to_v4l2 (FREQ_RANGE_LOW ); + vm->rangehigh =si4713_to_v4l2 (FREQ_RANGE_HIGH ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +u32 comp_en =0 ; + + rval =si4713_read_property (sdev,SI4713_TX_COMPONENT_ENABLE , + &comp_en); +if (rval <0 ) + goto unlock; + + sdev->stereo =get_status_bit (comp_en,1 ,1 <<1 ); + sdev->rds_info.enabled =get_status_bit (comp_en,2 ,1 <<2 ); + } + +/* 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_info.enabled) + vm->txsubchans |=V4L2_TUNER_SUB_RDS ; +else + vm->txsubchans &= ~V4L2_TUNER_SUB_RDS ; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +/* si4713_s_modulator - set modulator attributes */ +static int si4713_s_modulator (struct v4l2_subdev *sd,struct v4l2_modulator *vm) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; +u16 stereo, rds; +u32 p; + +if (!sdev) { + rval = -ENODEV ; + goto exit; + } + +if (vm->index >0 ) { + rval = -EINVAL ; + goto exit; + } + +/* 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 + rval = -EINVAL ; +if (rval <0 ) + goto exit; + + rds = !!(vm->txsubchans &V4L2_TUNER_SUB_RDS ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev, +SI4713_TX_COMPONENT_ENABLE , &p); +if (rval <0 ) + goto unlock; + + 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 ) + goto unlock; + } + + sdev->stereo = stereo; + sdev->rds_info.enabled = rds; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +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 ; + + f->type =V4L2_TUNER_RADIO ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +u16 freq; +u8 p, a, n; + + rval =si4713_tx_tune_status (sdev,0x00 , &freq, &p, &a, &n); +if (rval <0 ) + goto unlock; + + sdev->frequency = freq; + } + + f->frequency =si4713_to_v4l2 (sdev->frequency); + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* si4713_s_frequency - set tuner or modulator radio frequency */ +static int si4713_s_frequency (struct v4l2_subdev *sd,struct v4l2_frequency *f) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; +u16 frequency =v4l2_to_si4713 (f->frequency); + +/* Check frequency range */ +if (frequency <FREQ_RANGE_LOW || frequency >FREQ_RANGE_HIGH ) +return -EDOM ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_tx_tune_freq (sdev, frequency); +if (rval <0 ) + goto unlock; + frequency = rval; + rval =0 ; + } + sdev->frequency = frequency; + f->frequency =si4713_to_v4l2 (frequency); + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +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; +int rval; + + sdev =kzalloc (sizeof *sdev,GFP_KERNEL ); +if (!sdev) { +v4l2_err (&sdev->sd,"Failed to alloc video device.\n" ); + rval = -ENOMEM ; + goto exit; + } + + sdev->platform_data = client->dev.platform_data; +if (!sdev->platform_data) { +v4l2_err (&sdev->sd,"No platform data registered.\n" ); + rval = -ENODEV ; + goto free_sdev; + } + +v4l2_i2c_subdev_init (&sdev->sd, client, &si4713_subdev_ops); + +mutex_init (&sdev->mutex); +init_completion (&sdev->work); + +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 free_sdev; + } +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_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); + +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 Interface */ +static int __init si4713_module_init (void ) +{ +return i2c_add_driver (&si4713_i2c_driver); +} + +static void __exit si4713_module_exit(void) +{ +i2c_del_driver (&si4713_i2c_driver); +} + +module_init (si4713_module_init); +module_exit (si4713_module_exit); +linux/drivers/media/radio/si4713-i2c.h new file +161
-0@@ -0,0 +1,228 @@ +/* +* 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 <[email protected]> +* +* 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/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
linux/drivers/media/radio/si4713-i2c.h line 171
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.h new file +10
-0+ +struct rds_info { +u32 pi; +#define MAX_RDS_PTY 31 +u32 pty; +#define MAX_RDS_DEVIATION 90000 +u32 deviation; +#define MAX_RDS_PS_NAME 96 +u8 ps_name[MAX_RDS_PS_NAME +1 ]; +#define MAX_RDS_RADIO_TEXT 384
I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the PS_NAME is 8 and for RADIO_TEXT it is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.
Can you clarify how this is used?
Regards,
Hans
Quoted 112 lines
linux/drivers/media/radio/si4713-i2c.h new file +57
-0+u8 radio_text[MAX_RDS_RADIO_TEXT +1 ]; +u32 enabled; +}; + +struct limiter_info { +#define MAX_LIMITER_RELEASE_TIME 102390 +u32 release_time; +#define MAX_LIMITER_DEVIATION 90000 +u32 deviation; +u32 enabled; +}; + +struct pilot_info { +#define MAX_PILOT_DEVIATION 90000 +u32 deviation; +#define MAX_PILOT_FREQUENCY 19000 +u32 frequency; +u32 enabled; +}; + +struct acomp_info { +#define MAX_ACOMP_RELEASE_TIME 1000000 +u32 release_time; +#define MAX_ACOMP_ATTACK_TIME 5000 +u32 attack_time; +#define MAX_ACOMP_THRESHOLD 0 +#define MIN_ACOMP_THRESHOLD (-40) +s32 threshold; +#define MAX_ACOMP_GAIN 20 +u32 gain; +u32 enabled; +}; + +/* +* si4713_device - private data +*/ +struct si4713_device { +/* v4l2_subdev and i2c reference (v4l2_subdev priv data) */ +struct v4l2_subdev sd; +/* private data structures */ +struct mutex mutex; +struct completion work; +struct si4713_platform_data *platform_data; +struct rds_info rds_info; +struct limiter_info limiter_info; +struct pilot_info pilot_info; +struct acomp_info acomp_info; +u32 frequency; +u32 preemphasis; +u32 mute; +u32 power_level; +u32 power_state; +u32 antenna_capacitor; +u32 stereo; +u32 tune_rnl; +}; +#endif /* ifndef SI4713_I2C_H */ linux/include/media/si4713.h new file +49
-0@@ -0,0 +1,49 @@ +/* +* include/media/si4713.h +* +* Board related data definitions for Si4713 i2c device driver. +* +* Copyright (c) 2009 Nokia Corporation +* Contact: Eduardo Valentin <[email protected]> +* +* 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_H +#define SI4713_H + +/* The SI4713 I2C sensor chip has a fixed slave address of 0xc6 or 0x22. */ +#define SI4713_I2C_ADDR_BUSEN_HIGH 0x63 +#define SI4713_I2C_ADDR_BUSEN_LOW 0x11 + +/* +* Platform dependent definition +*/ +struct si4713_platform_data { +/* Set power state, zero is off, non-zero is on. */ +int (*set_power)(int power); +}; + +/* +* Structure to query for Received Noise Level (RNL). +*/ +struct si4713_rnl { +__u32 index;/* modulator index */ +__u32 frequency;/* frequency to peform rnl measurement */ +__s32 rnl;/* result of measurement in dBuV */ +__u32 reserved[4 ];/* drivers and apps must init this to 0 */ +}; + +/* +* This is the ioctl number to query for rnl. Users must pass a +* struct si4713_rnl pointer specifying desired frequency in 'frequency' field +* following driver capabilities (i.e V4L2_TUNER_CAP_LOW). +* Driver must return measured value in the same struture, filling 'rnl' field. +*/ +#define SI4713_IOC_MEASURE_RNL _IOWR('V', BASE_VIDIOC_PRIVATE + 0, \ + struct si4713_rnl) + +#endif /* ifndef SI4713_H*/
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 1,392 lines · ext Hans Verkuil
Quoted 1,367 lines · On Friday 24 July 2009 18:37:26 Eduardo Valentin wrote:
This patch adds files to control si4713 devices. Internal functions to control device properties and initialization procedures are into these files. Also, a v4l2 subdev interface is also exported. This way other drivers can use this as v4l2 i2c subdevice.
Signed-off-by Eduardo Valentin <[email protected]>--- linux/drivers/media/radio/si4713-i2c.c | 2034 ++++++++++++++++++++++++++++++++ linux/drivers/media/radio/si4713-i2c.h | 228 ++++ linux/include/media/si4713.h | 49 + 3 files changed, 2311 insertions(+), 0 deletions(-) create mode 100644 linux/drivers/media/radio/si4713-i2c.c create mode 100644 linux/drivers/media/radio/si4713-i2c.h create mode 100644 linux/include/media/si4713.hlinux/drivers/media/radio/si4713-i2c.c new file +1345
-0@@ -0,0 +1,2034 @@ +/* +* drivers/media/radio/si4713-i2c.c +* +* Silicon Labs Si4713 FM Radio Transmitter I2C commands. +* +* Copyright (c) 2009 Nokia Corporation +* Contact: Eduardo Valentin <[email protected]> +* +* 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/mutex.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/interrupt.h> +#include <linux/i2c.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 <[email protected]>" ); +MODULE_DESCRIPTION ("I2C driver for Si4713 FM Radio Transmitter" ); +MODULE_VERSION ("0.0.1" ); + +#define DEFAULT_RDS_PI 0x00 +#define DEFAULT_RDS_PTY 0x00 +#define DEFAULT_RDS_PS_NAME "Si4713 " +#define DEFAULT_RDS_RADIO_TEXT DEFAULT_RDS_PS_NAME +#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)); +#define get_mute (p) (p & 0x01) + +#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; +} + +static unsigned long dev_to_usecs (int value,unsigned long const array[], +int size) +{ +int i; +int rval = -EINVAL ; + +for (i =0 ; i < size /2 ; i++) +if (array[i *2 ] == value) { + rval = array[(i *2 ) +1 ]; +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 ; + + sdev->platform_data->set_power (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 { + sdev->platform_data->set_power (0 ); + } + +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" ); + sdev->platform_data->set_power (0 ); + 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 ]; + +mutex_lock (&sdev->mutex); + + rval =si4713_send_command (sdev,SI4713_CMD_GET_REV , +NULL ,0 , + resp,ARRAY_SIZE (resp), +DEFAULT_TIMEOUT ); + +if (rval <0 ) + goto unlock; + +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 ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* +* si4713_wait_stc - Waits STC interrupt and clears status bits. Usefull +* 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 +* @intstatus: returns current interrupt status +* @cbavail: returns the number of available circular buffer blocks. +* @cbused: returns the number of used circular buffer blocks. +* @fifoavail: returns the number of available fifo buffer blocks. +* @fifoused: returns the number of used fifo buffer blocks. +*/ +static int si4713_tx_rds_buff (struct si4713_device *sdev,u8 mode,u16 rdsb, +u16 rdsc,u16 rdsd,u8 *intstatus,u8 *cbavail, +u8 *cbused,u8 *fifoavail,u8 *fifoused) +{ +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 ]); + *intstatus = val[1 ]; + *cbavail = val[2 ]; + *cbused = val[3 ]; + *fifoavail = val[4 ]; + *fifoused = val[5 ]; +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__, *intstatus, + *cbavail, *cbused, *fifoavail, *fifoused); + } + +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) +{ +int rval; + +mutex_lock (&sdev->mutex); + +if (value) + rval =si4713_powerup (sdev); +else + rval =si4713_powerdown (sdev); + +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_set_mute (struct si4713_device *sdev,u16 mute) +{ +int rval =0 ; + + mute =set_mute (mute); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) + rval =si4713_write_property (sdev, +SI4713_TX_LINE_INPUT_MUTE , mute); + +if (rval >=0 ) + sdev->mute =get_mute (mute); + +mutex_unlock (&sdev->mutex); + +return rval; +} + +static int si4713_set_rds_ps_name (struct si4713_device *sdev,char *ps_name) +{ +int rval =0 , i; +u8 len =0 ; +u8 *tmp; + +if (!strlen (ps_name)) +return -EINVAL ; + + tmp =kzalloc (MAX_RDS_PS_NAME +1 ,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +strncpy (tmp, ps_name,MAX_RDS_PS_NAME ); + +mutex_lock (&sdev->mutex); + +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 )), + tmp + i); +if (rval <0 ) + goto unlock; + } + +/* Setup the size to be sent */ + len =strlen (tmp) -1 ; + + rval =si4713_write_property (sdev, +SI4713_TX_RDS_PS_MESSAGE_COUNT , +rds_ps_nblocks (len)); +if (rval <0 ) + goto unlock; + + rval =si4713_write_property (sdev, +SI4713_TX_RDS_PS_REPEAT_COUNT , +DEFAULT_RDS_PS_REPEAT_COUNT *2 ); +if (rval <0 ) + goto unlock; + } + +strncpy (sdev->rds_info.ps_name, tmp,MAX_RDS_PS_NAME ); + +unlock: +mutex_unlock (&sdev->mutex); +kfree (tmp); +return rval; +} + +static int si4713_set_rds_radio_text (struct si4713_device *sdev, +char *radio_text) +{ +int rval =0 , i; +u16 t_index =0 ; +u8 s, a, u, fa, fu, b_index =0 , cr_inserted =0 ; +u8 *tmp; + +if (!strlen (radio_text)) +return -EINVAL ; + + tmp =kzalloc (MAX_RDS_RADIO_TEXT +1 ,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +strncpy (tmp, radio_text,MAX_RDS_RADIO_TEXT ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_tx_rds_buff (sdev,RDS_BLOCK_CLEAR ,0 ,0 ,0 , + &s, &a, &u, &fa, &fu); +if (rval <0 ) + goto unlock; +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 (!tmp[t_index + i] || + tmp[t_index + i] == \ +RDS_CARRIAGE_RETURN ) { + tmp[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 (tmp[t_index], + tmp[t_index +1 ]), +compose_u16 (tmp[t_index +2 ], + tmp[t_index +3 ]), + &s, &a, &u, &fa, &fu); +if (rval <0 ) + goto unlock; + + t_index +=RDS_RADIOTEXT_BLK_SIZE ; + +if (cr_inserted) +break ; + }while (u < a); + } + +strncpy (sdev->rds_info.radio_text, tmp,MAX_RDS_RADIO_TEXT ); + +unlock: +mutex_unlock (&sdev->mutex); +kfree (tmp); +return rval; +} + +static int si4713_choose_econtrol_action (struct si4713_device *sdev,u32 id, +u32 **shadow,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 ; + *shadow = &sdev->rds_info.pi; +break ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : + *property =SI4713_TX_ACOMP_THRESHOLD ; + *mul =1 ; + *shadow = &sdev->acomp_info.threshold; +break ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN : + *property =SI4713_TX_ACOMP_GAIN ; + *mul =1 ; + *shadow = &sdev->acomp_info.gain; +break ; +case V4L2_CID_PILOT_TONE_FREQUENCY : + *property =SI4713_TX_PILOT_FREQUENCY ; + *mul =1 ; + *shadow = &sdev->pilot_info.frequency; +break ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : + *property =SI4713_TX_ACOMP_ATTACK_TIME ; + *mul =ATTACK_TIME_UNIT ; + *shadow = &sdev->acomp_info.attack_time; +break ; +case V4L2_CID_PILOT_TONE_DEVIATION : + *property =SI4713_TX_PILOT_DEVIATION ; + *mul =10 ; + *shadow = &sdev->pilot_info.deviation; +break ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION : + *property =SI4713_TX_AUDIO_DEVIATION ; + *mul =10 ; + *shadow = &sdev->limiter_info.deviation; +break ; +case V4L2_CID_RDS_TX_DEVIATION : + *property =SI4713_TX_RDS_DEVIATION ; + *mul =1 ; + *shadow = &sdev->rds_info.deviation; +break ; + +case V4L2_CID_RDS_TX_PTY : + *property =SI4713_TX_RDS_PS_MISC ; + *bit =5 ; + *mask =0x1F <<5 ; + *shadow = &sdev->rds_info.pty; +break ; +case V4L2_CID_AUDIO_LIMITER_ENABLED : + *property =SI4713_TX_ACOMP_ENABLE ; + *bit =1 ; + *mask =1 <<1 ; + *shadow = &sdev->limiter_info.enabled; +break ; +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : + *property =SI4713_TX_ACOMP_ENABLE ; + *bit =0 ; + *mask =1 <<0 ; + *shadow = &sdev->acomp_info.enabled; +break ; +case V4L2_CID_PILOT_TONE_ENABLED : + *property =SI4713_TX_COMPONENT_ENABLE ; + *bit =0 ; + *mask =1 <<0 ; + *shadow = &sdev->pilot_info.enabled; +break ; + +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : + *property =SI4713_TX_LIMITER_RELEASE_TIME ; + *table = limiter_times; + *size =ARRAY_SIZE (limiter_times); + *shadow = &sdev->limiter_info.release_time; +break ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : + *property =SI4713_TX_ACOMP_RELEASE_TIME ; + *table = acomp_rtimes; + *size =ARRAY_SIZE (acomp_rtimes); + *shadow = &sdev->acomp_info.release_time; +break ; +case V4L2_CID_FM_TX_PREEMPHASIS : + *property =SI4713_TX_PREEMPHASIS ; + *table = preemphasis_values; + *size =ARRAY_SIZE (preemphasis_values); + *shadow = &sdev->preemphasis; +break ; + +default : + rval = -EINVAL ; + }; + +return rval; +} + +/* write string property */ +static int si4713_write_econtrol_string (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +char ps_name[MAX_RDS_PS_NAME +1 ]; +char radio_text[MAX_RDS_RADIO_TEXT +1 ]; +int size; +s32 rval =0 ; + +switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : + size = control->length -1 ; +if (size >MAX_RDS_PS_NAME ) + size =MAX_RDS_PS_NAME ; + rval =copy_from_user (ps_name, control->string, size); +if (rval <0 ) + goto exit; + ps_name[size] ='\0' ; + rval =si4713_set_rds_ps_name (sdev, ps_name); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : + size = control->length -1 ; +if (size >MAX_RDS_RADIO_TEXT ) + size =MAX_RDS_RADIO_TEXT ; + rval =copy_from_user (radio_text, control->string, size); +if (rval <0 ) + goto exit; + radio_text[size] ='\0' ; + rval =si4713_set_rds_radio_text (sdev, radio_text); +break ; + +default : + rval = -EINVAL ; +break ; + }; + +exit: +return rval; +} + +/* properties which use tx_tune_power*/ +static int si4713_write_econtrol_tune (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; +u8 power, antcap; + +mutex_lock (&sdev->mutex); + +switch (control->id) { +case V4L2_CID_TUNE_POWER_LEVEL : + power = control->value; + antcap = sdev->antenna_capacitor; +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + power = sdev->power_level; + antcap = control->value; +break ; +default : + rval = -EINVAL ; + goto unlock; + }; + +if (sdev->power_state) + rval =si4713_tx_tune_power (sdev, power, antcap); + +if (rval ==0 ) { + sdev->power_level = power; + sdev->antenna_capacitor = antcap; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_queryctrl (struct v4l2_subdev *sd,struct v4l2_queryctrl *qc); + +static int validate_range (struct v4l2_subdev *sd, +struct v4l2_ext_control *control) +{ +struct v4l2_queryctrl vqc; +int rval; + + vqc.id = control->id; + rval =si4713_queryctrl (sd, &vqc); +if (rval <0 ) + goto exit; + +if (control->value < vqc.minimum || control->value > vqc.maximum) + rval = -EDOM ; + +exit: +return rval; +} + +static int si4713_write_econtrol_integers (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval; +u32 *shadow =NULL , val =0 ; +s32 bit =0 , mask =0 ; +u16 property =0 ; +int mul =0 ; +unsigned long *table =NULL ; +int size =0 ; + + rval =validate_range (&sdev->sd, control); +if (rval <0 ) + goto exit; + + rval =si4713_choose_econtrol_action (sdev, control->id, &shadow, &bit, + &mask, &property, &mul, &table, &size); +if (rval <0 ) + goto exit; + + val = control->value; +if (mul) { + val = control->value / mul; + }else if (table) { + rval =usecs_to_dev (control->value, table, size); +if (rval <0 ) + goto exit; + val = rval; + rval =0 ; + } + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +if (mask) { + rval =si4713_read_property (sdev, property, &val); +if (rval <0 ) + goto unlock; + val =set_bits (val, control->value, bit, mask); + } + + rval =si4713_write_property (sdev, property, val); +if (rval <0 ) + goto unlock; +if (mask) + val = control->value; + } + +if (mul) { + *shadow = val * mul; + }else if (table) { + rval =dev_to_usecs (val, table, size); +if (rval <0 ) + goto unlock; + *shadow = rval; + rval =0 ; + }else { + *shadow = val; + } + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +static int si4713_s_frequency (struct v4l2_subdev *sd,struct v4l2_frequency *f); +static int si4713_s_modulator (struct v4l2_subdev *sd,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_ext_control ctrl; +struct v4l2_frequency f; +struct v4l2_modulator vm; +struct si4713_device *tmp; +int rval =0 ; + + tmp =kmalloc (sizeof (*tmp),GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; + +/* Get a local copy to avoid race */ +mutex_lock (&sdev->mutex); +memcpy (tmp, sdev,sizeof (*sdev)); +mutex_unlock (&sdev->mutex); + + ctrl.id =V4L2_CID_RDS_TX_PI ; + ctrl.value = tmp->rds_info.pi; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_THRESHOLD ; + ctrl.value = tmp->acomp_info.threshold; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_GAIN ; + ctrl.value = tmp->acomp_info.gain; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_FREQUENCY ; + ctrl.value = tmp->pilot_info.frequency; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME ; + ctrl.value = tmp->acomp_info.attack_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_DEVIATION ; + ctrl.value = tmp->pilot_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_DEVIATION ; + ctrl.value = tmp->limiter_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_DEVIATION ; + ctrl.value = tmp->rds_info.deviation; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_PTY ; + ctrl.value = tmp->rds_info.pty; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_ENABLED ; + ctrl.value = tmp->limiter_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_ENABLED ; + ctrl.value = tmp->acomp_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_PILOT_TONE_ENABLED ; + ctrl.value = tmp->pilot_info.enabled; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_LIMITER_RELEASE_TIME ; + ctrl.value = tmp->limiter_info.release_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME ; + ctrl.value = tmp->acomp_info.release_time; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_FM_TX_PREEMPHASIS ; + ctrl.value = tmp->preemphasis; + rval |=si4713_write_econtrol_integers (sdev, &ctrl); + + ctrl.id =V4L2_CID_RDS_TX_PS_NAME ; + rval |=si4713_set_rds_ps_name (sdev, tmp->rds_info.ps_name); + + ctrl.id =V4L2_CID_RDS_TX_RADIO_TEXT ; + rval |=si4713_set_rds_radio_text (sdev, tmp->rds_info.radio_text); + +/* Device procedure needs to set frequency first */ + f.frequency = tmp->frequency ? tmp->frequency :DEFAULT_FREQUENCY ; + f.frequency =si4713_to_v4l2 (f.frequency); + rval |=si4713_s_frequency (&sdev->sd, &f); + + ctrl.id =V4L2_CID_TUNE_POWER_LEVEL ; + ctrl.value = tmp->power_level; + rval |=si4713_write_econtrol_tune (sdev, &ctrl); + + ctrl.id =V4L2_CID_TUNE_ANTENNA_CAPACITOR ; + ctrl.value = tmp->antenna_capacitor; + rval |=si4713_write_econtrol_tune (sdev, &ctrl); + + vm.index =0 ; +if (tmp->stereo) + vm.txsubchans =V4L2_TUNER_SUB_STEREO ; +else + vm.txsubchans =V4L2_TUNER_SUB_MONO ; +if (tmp->rds_info.enabled) + vm.txsubchans |=V4L2_TUNER_SUB_RDS ; +si4713_s_modulator (&sdev->sd, &vm); + +kfree (tmp); + +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 ) + goto exit; + + rval =si4713_checkrev (sdev); +if (rval <0 ) + goto exit; + + rval =si4713_set_power_state (sdev,POWER_OFF ); +if (rval <0 ) + goto exit; + +mutex_lock (&sdev->mutex); + + sdev->rds_info.pi =DEFAULT_RDS_PI ; + sdev->rds_info.pty =DEFAULT_RDS_PTY ; + sdev->rds_info.deviation =DEFAULT_RDS_DEVIATION ; +strlcpy (sdev->rds_info.ps_name,DEFAULT_RDS_PS_NAME ,MAX_RDS_PS_NAME ); +strlcpy (sdev->rds_info.radio_text,DEFAULT_RDS_RADIO_TEXT , +MAX_RDS_RADIO_TEXT ); + sdev->rds_info.enabled =1 ; + + sdev->limiter_info.release_time =DEFAULT_LIMITER_RTIME ; + sdev->limiter_info.deviation =DEFAULT_LIMITER_DEV ; + sdev->limiter_info.enabled =1 ; + + sdev->pilot_info.deviation =DEFAULT_PILOT_DEVIATION ; + sdev->pilot_info.frequency =DEFAULT_PILOT_FREQUENCY ; + sdev->pilot_info.enabled =1 ; + + sdev->acomp_info.release_time =DEFAULT_ACOMP_RTIME ; + sdev->acomp_info.attack_time =DEFAULT_ACOMP_ATIME ; + sdev->acomp_info.threshold =DEFAULT_ACOMP_THRESHOLD ; + sdev->acomp_info.gain =DEFAULT_ACOMP_GAIN ; + sdev->acomp_info.enabled =1 ; + + sdev->frequency =DEFAULT_FREQUENCY ; + sdev->preemphasis =DEFAULT_PREEMPHASIS ; + sdev->mute =DEFAULT_MUTE ; + sdev->power_level =DEFAULT_POWER_LEVEL ; + sdev->antenna_capacitor =0 ; + sdev->stereo =1 ; + sdev->tune_rnl =DEFAULT_TUNE_RNL ; + +mutex_unlock (&sdev->mutex); + +exit: +return rval; +} +linux/drivers/media/radio/si4713-i2c.c line 1355
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.c new file +10
-0+/* read string property */ +static int si4713_read_econtrol_string (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; + +switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : +if (strlen (sdev->rds_info.ps_name) +1 > control->length) { + control->length =strlen (sdev->rds_info.ps_name) +1 ;I recommend setting length to the actual maximum MAX_RDS_PS_NAME+1.
linux/drivers/media/radio/si4713-i2c.c line 1365
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.c new file +10
-0+ rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.ps_name, +strlen (sdev->rds_info.ps_name) +1 ); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : +if (strlen (sdev->rds_info.radio_text) +1 > control->length) { + control->length =strlen (sdev->rds_info.radio_text) +1 ;
Quoted 1 line
Ditto.
Right, I think doing the way you are proposing is to avoid changes that may generate failures in the following reads.
I 'll change this in the v11 as well.
Quoted 976 lines
Quoted 837 lines
linux/drivers/media/radio/si4713-i2c.c new file +669
-0+ rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.radio_text, +strlen (sdev->rds_info.radio_text) +1 ); +break ; + +default : + rval = -EINVAL ; +break ; + }; + +exit: +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; + + sdev->power_level = p; + sdev->antenna_capacitor = a; + sdev->tune_rnl = n; + +exit: +return rval; +} + +/* properties which use tx_tune_status */ +static int si4713_read_econtrol_tune (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval =0 ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_update_tune_status (sdev); +if (rval <0 ) + goto unlock; + } + +switch (control->id) { +case V4L2_CID_TUNE_POWER_LEVEL : + control->value = sdev->power_level; +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + control->value = sdev->antenna_capacitor; +break ; +default : + rval = -EINVAL ; + }; + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static int si4713_read_econtrol_integers (struct si4713_device *sdev, +struct v4l2_ext_control *control) +{ +s32 rval; +u32 *shadow =NULL , val =0 ; +s32 bit =0 , mask =0 ; +u16 property =0 ; +int mul =0 ; +unsigned long *table =NULL ; +int size =0 ; + + rval =si4713_choose_econtrol_action (sdev, control->id, &shadow, &bit, + &mask, &property, &mul, &table, &size); +if (rval <0 ) + goto exit; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev, property, &val); +if (rval <0 ) + goto unlock; + +/* Keep negative values for threshold */ +if (control->id ==V4L2_CID_AUDIO_COMPRESSION_THRESHOLD ) + *shadow = (s16 )val; +else if (mask) + *shadow =get_status_bit (val, bit, mask); +else if (mul) + *shadow = val * mul; +else + *shadow =dev_to_usecs (val, table, size); + } + + control->value = *shadow; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +/* +* Video4Linux Subdev Interface +*/ +/* si4713_s_ext_ctrls - set extended controls value */ +static int si4713_s_ext_ctrls (struct v4l2_subdev *sd, +struct v4l2_ext_controls *ctrls) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int i; + +if (ctrls->ctrl_class !=V4L2_CTRL_CLASS_FM_TX ) +return -EINVAL ; + +for (i =0 ; i < ctrls->count; i++) { +int err; + + err =si4713_write_econtrol_integers (sdev, ctrls->controls + i); +if (err <0 ) + err =si4713_write_econtrol_string (sdev, + ctrls->controls + i); +if (err <0 ) + err =si4713_write_econtrol_tune (sdev, + ctrls->controls + i); + +if (err <0 ) { + ctrls->error_idx = i; +return err; + } + } + +return 0 ; +} + +/* si4713_g_ext_ctrls - get extended controls value */ +static int si4713_g_ext_ctrls (struct v4l2_subdev *sd, +struct v4l2_ext_controls *ctrls) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int i; + +if (ctrls->ctrl_class !=V4L2_CTRL_CLASS_FM_TX ) +return -EINVAL ; + +for (i =0 ; i < ctrls->count; i++) { +int err; + + err =si4713_read_econtrol_tune (sdev, ctrls->controls + i); +if (err <0 ) + err =si4713_read_econtrol_string (sdev, + ctrls->controls + i); +if (err <0 ) + err =si4713_read_econtrol_integers (sdev, + ctrls->controls + i); + +if (err <0 ) { + ctrls->error_idx = i; +return err; + } + } + +return 0 ; +} + +/* si4713_queryctrl - enumerate control items */ +static int si4713_queryctrl (struct v4l2_subdev *sd,struct v4l2_queryctrl *qc) +{ +int rval =0 ; + +switch (qc->id) { +/* User class controls */ +case V4L2_CID_AUDIO_MUTE : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,DEFAULT_MUTE ); +break ; +/* FM_TX class controls */ +case V4L2_CID_RDS_TX_PI : + rval =v4l2_ctrl_query_fill (qc,0 ,0xFFFF ,1 ,DEFAULT_RDS_PI ); +break ; +case V4L2_CID_RDS_TX_PTY : + rval =v4l2_ctrl_query_fill (qc,0 ,31 ,1 ,DEFAULT_RDS_PTY ); +break ; +case V4L2_CID_RDS_TX_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_DEVIATION , +10 ,DEFAULT_RDS_DEVIATION ); +break ; +case V4L2_CID_RDS_TX_PS_NAME : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_PS_NAME +1 ,0 ,0 ); +break ; +case V4L2_CID_RDS_TX_RADIO_TEXT : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_RDS_RADIO_TEXT +1 , +0 ,0 ); +break ; + +case V4L2_CID_AUDIO_LIMITER_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME : + rval =v4l2_ctrl_query_fill (qc,250 ,MAX_LIMITER_RELEASE_TIME , +50 ,DEFAULT_LIMITER_RTIME ); +break ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_LIMITER_DEVIATION , +10 ,DEFAULT_LIMITER_DEV ); +break ; + +case V4L2_CID_AUDIO_COMPRESSION_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_ACOMP_GAIN ,1 , +DEFAULT_ACOMP_GAIN ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD : + rval =v4l2_ctrl_query_fill (qc,MIN_ACOMP_THRESHOLD , +MAX_ACOMP_THRESHOLD ,1 , +DEFAULT_ACOMP_THRESHOLD ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_ACOMP_ATTACK_TIME , +500 ,DEFAULT_ACOMP_ATIME ); +break ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME : + rval =v4l2_ctrl_query_fill (qc,100000 ,MAX_ACOMP_RELEASE_TIME , +100000 ,DEFAULT_ACOMP_RTIME ); +break ; + +case V4L2_CID_PILOT_TONE_ENABLED : + rval =v4l2_ctrl_query_fill (qc,0 ,1 ,1 ,1 ); +break ; +case V4L2_CID_PILOT_TONE_DEVIATION : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_PILOT_DEVIATION , +10 ,DEFAULT_PILOT_DEVIATION ); +break ; +case V4L2_CID_PILOT_TONE_FREQUENCY : + rval =v4l2_ctrl_query_fill (qc,0 ,MAX_PILOT_FREQUENCY , +1 ,DEFAULT_PILOT_FREQUENCY ); +break ; + +case V4L2_CID_FM_TX_PREEMPHASIS : + rval =v4l2_ctrl_query_fill (qc,V4L2_PREEMPHASIS_DISABLED , + V4L2_PREEMPHASIS_75_uS,1 , + V4L2_PREEMPHASIS_50_uS); +break ; +case V4L2_CID_TUNE_POWER_LEVEL : + rval =v4l2_ctrl_query_fill (qc,0 ,120 ,1 ,DEFAULT_POWER_LEVEL ); +break ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR : + rval =v4l2_ctrl_query_fill (qc,0 ,191 ,1 ,0 ); +break ; +default : + rval = -EINVAL ; +break ; + }; + +return rval; +} + +/* si4713_g_ctrl - get the value of a control */ +static int si4713_g_ctrl (struct v4l2_subdev *sd,struct v4l2_control *ctrl) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; + +if (!sdev) +return -ENODEV ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev,SI4713_TX_LINE_INPUT_MUTE , + &sdev->mute); + +if (rval <0 ) + goto unlock; + } + +switch (ctrl->id) { +case V4L2_CID_AUDIO_MUTE : + ctrl->value =get_mute (sdev->mute); +break ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* si4713_s_ctrl - set the value of a control */ +static int si4713_s_ctrl (struct v4l2_subdev *sd,struct v4l2_control *ctrl) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; + +if (!sdev) +return -ENODEV ; + +switch (ctrl->id) { +case V4L2_CID_AUDIO_MUTE : +if (ctrl->value) { + rval =si4713_set_mute (sdev, ctrl->value); +if (rval <0 ) + goto exit; + + rval =si4713_set_power_state (sdev,POWER_DOWN ); + }else { + rval =si4713_set_power_state (sdev,POWER_UP ); +if (rval <0 ) + goto exit; + + rval =si4713_setup (sdev); +if (rval <0 ) + goto exit; + + rval =si4713_set_mute (sdev, ctrl->value); + } +break ; + } + +exit: +return rval; +} + +/* si4713_ioctl - deal with private ioctls (only rnl for now) */ +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 ; + +mutex_lock (&sdev->mutex); +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 ) + goto unlock; +/* get results from tune status */ + rval =si4713_update_tune_status (sdev); +if (rval <0 ) + goto unlock; + } + rnl->rnl = sdev->tune_rnl; +break ; + +default : +/* nothing */ + rval = -ENOIOCTLCMD ; + } + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +static const struct v4l2_subdev_core_ops si4713_subdev_core_ops = { + .queryctrl = si4713_queryctrl, + .g_ext_ctrls = si4713_g_ext_ctrls, + .s_ext_ctrls = si4713_s_ext_ctrls, + .g_ctrl = si4713_g_ctrl, + .s_ctrl = si4713_s_ctrl, + .ioctl = si4713_ioctl, +}; + +/* 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) { + rval = -ENODEV ; + goto exit; + } + +if (vm->index >0 ) { + rval = -EINVAL ; + goto exit; + } + +strncpy (vm->name,"FM Modulator" ,32 ); + vm->capability =V4L2_TUNER_CAP_STEREO |V4L2_TUNER_CAP_LOW | +V4L2_TUNER_CAP_RDS ; + +/* Report current frequency range limits */ + vm->rangelow =si4713_to_v4l2 (FREQ_RANGE_LOW ); + vm->rangehigh =si4713_to_v4l2 (FREQ_RANGE_HIGH ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +u32 comp_en =0 ; + + rval =si4713_read_property (sdev,SI4713_TX_COMPONENT_ENABLE , + &comp_en); +if (rval <0 ) + goto unlock; + + sdev->stereo =get_status_bit (comp_en,1 ,1 <<1 ); + sdev->rds_info.enabled =get_status_bit (comp_en,2 ,1 <<2 ); + } + +/* 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_info.enabled) + vm->txsubchans |=V4L2_TUNER_SUB_RDS ; +else + vm->txsubchans &= ~V4L2_TUNER_SUB_RDS ; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +return rval; +} + +/* si4713_s_modulator - set modulator attributes */ +static int si4713_s_modulator (struct v4l2_subdev *sd,struct v4l2_modulator *vm) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; +u16 stereo, rds; +u32 p; + +if (!sdev) { + rval = -ENODEV ; + goto exit; + } + +if (vm->index >0 ) { + rval = -EINVAL ; + goto exit; + } + +/* 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 + rval = -EINVAL ; +if (rval <0 ) + goto exit; + + rds = !!(vm->txsubchans &V4L2_TUNER_SUB_RDS ); + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_read_property (sdev, +SI4713_TX_COMPONENT_ENABLE , &p); +if (rval <0 ) + goto unlock; + + 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 ) + goto unlock; + } + + sdev->stereo = stereo; + sdev->rds_info.enabled = rds; + +unlock: +mutex_unlock (&sdev->mutex); +exit: +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 ; + + f->type =V4L2_TUNER_RADIO ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { +u16 freq; +u8 p, a, n; + + rval =si4713_tx_tune_status (sdev,0x00 , &freq, &p, &a, &n); +if (rval <0 ) + goto unlock; + + sdev->frequency = freq; + } + + f->frequency =si4713_to_v4l2 (sdev->frequency); + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +/* si4713_s_frequency - set tuner or modulator radio frequency */ +static int si4713_s_frequency (struct v4l2_subdev *sd,struct v4l2_frequency *f) +{ +struct si4713_device *sdev =to_si4713_device (sd); +int rval =0 ; +u16 frequency =v4l2_to_si4713 (f->frequency); + +/* Check frequency range */ +if (frequency <FREQ_RANGE_LOW || frequency >FREQ_RANGE_HIGH ) +return -EDOM ; + +mutex_lock (&sdev->mutex); + +if (sdev->power_state) { + rval =si4713_tx_tune_freq (sdev, frequency); +if (rval <0 ) + goto unlock; + frequency = rval; + rval =0 ; + } + sdev->frequency = frequency; + f->frequency =si4713_to_v4l2 (frequency); + +unlock: +mutex_unlock (&sdev->mutex); +return rval; +} + +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; +int rval; + + sdev =kzalloc (sizeof *sdev,GFP_KERNEL ); +if (!sdev) { +v4l2_err (&sdev->sd,"Failed to alloc video device.\n" ); + rval = -ENOMEM ; + goto exit; + } + + sdev->platform_data = client->dev.platform_data; +if (!sdev->platform_data) { +v4l2_err (&sdev->sd,"No platform data registered.\n" ); + rval = -ENODEV ; + goto free_sdev; + } + +v4l2_i2c_subdev_init (&sdev->sd, client, &si4713_subdev_ops); + +mutex_init (&sdev->mutex); +init_completion (&sdev->work); + +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 free_sdev; + } +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_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); + +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 Interface */ +static int __init si4713_module_init (void ) +{ +return i2c_add_driver (&si4713_i2c_driver); +} + +static void __exit si4713_module_exit(void) +{ +i2c_del_driver (&si4713_i2c_driver); +} + +module_init (si4713_module_init); +module_exit (si4713_module_exit); +linux/drivers/media/radio/si4713-i2c.h new file +161
-0@@ -0,0 +1,228 @@ +/* +* 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 <[email protected]> +* +* 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/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 0x00linux/drivers/media/radio/si4713-i2c.h line 171
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.h new file +10
-0+ +struct rds_info { +u32 pi; +#define MAX_RDS_PTY 31 +u32 pty; +#define MAX_RDS_DEVIATION 90000 +u32 deviation; +#define MAX_RDS_PS_NAME 96 +u8 ps_name[MAX_RDS_PS_NAME +1 ]; +#define MAX_RDS_RADIO_TEXT 384I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.Can you clarify how this is used?
Regards,
Hans
Quoted 102 lines
linux/drivers/media/radio/si4713-i2c.h new file +57
-0+u8 radio_text[MAX_RDS_RADIO_TEXT +1 ]; +u32 enabled; +}; + +struct limiter_info { +#define MAX_LIMITER_RELEASE_TIME 102390 +u32 release_time; +#define MAX_LIMITER_DEVIATION 90000 +u32 deviation; +u32 enabled; +}; + +struct pilot_info { +#define MAX_PILOT_DEVIATION 90000 +u32 deviation; +#define MAX_PILOT_FREQUENCY 19000 +u32 frequency; +u32 enabled; +}; + +struct acomp_info { +#define MAX_ACOMP_RELEASE_TIME 1000000 +u32 release_time; +#define MAX_ACOMP_ATTACK_TIME 5000 +u32 attack_time; +#define MAX_ACOMP_THRESHOLD 0 +#define MIN_ACOMP_THRESHOLD (-40) +s32 threshold; +#define MAX_ACOMP_GAIN 20 +u32 gain; +u32 enabled; +}; + +/* +* si4713_device - private data +*/ +struct si4713_device { +/* v4l2_subdev and i2c reference (v4l2_subdev priv data) */ +struct v4l2_subdev sd; +/* private data structures */ +struct mutex mutex; +struct completion work; +struct si4713_platform_data *platform_data; +struct rds_info rds_info; +struct limiter_info limiter_info; +struct pilot_info pilot_info; +struct acomp_info acomp_info; +u32 frequency; +u32 preemphasis; +u32 mute; +u32 power_level; +u32 power_state; +u32 antenna_capacitor; +u32 stereo; +u32 tune_rnl; +}; +#endif /* ifndef SI4713_I2C_H */ linux/include/media/si4713.h new file +39
-0@@ -0,0 +1,49 @@ +/* +* include/media/si4713.h +* +* Board related data definitions for Si4713 i2c device driver. +* +* Copyright (c) 2009 Nokia Corporation +* Contact: Eduardo Valentin <[email protected]> +* +* 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_H +#define SI4713_H + +/* The SI4713 I2C sensor chip has a fixed slave address of 0xc6 or 0x22. */ +#define SI4713_I2C_ADDR_BUSEN_HIGH 0x63 +#define SI4713_I2C_ADDR_BUSEN_LOW 0x11 + +/* +* Platform dependent definition +*/ +struct si4713_platform_data { +/* Set power state, zero is off, non-zero is on. */ +int (*set_power)(int power); +}; + +/* +* Structure to query for Received Noise Level (RNL). +*/ +struct si4713_rnl { +__u32 index;/* modulator index */ +__u32 frequency;/* frequency to peform rnl measurement */ +__s32 rnl;/* result of measurement in dBuV */ +__u32 reserved[4 ];/* drivers and apps must init this to 0 */ +}; +linux/include/media/si4713.h line 49
Quoted 10 lines
linux/include/media/si4713.h new file +10
-0+/* +* This is the ioctl number to query for rnl. Users must pass a +* struct si4713_rnl pointer specifying desired frequency in 'frequency' field +* following driver capabilities (i.e V4L2_TUNER_CAP_LOW). +* Driver must return measured value in the same struture, filling 'rnl' field. +*/ +#define SI4713_IOC_MEASURE_RNL _IOWR('V', BASE_VIDIOC_PRIVATE + 0, \ + struct si4713_rnl) + +#endif /* ifndef SI4713_H*/ --
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Signature · 1 line
Eduardo Valentin
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 19 lines · On Saturday 25 July 2009 15:15:24 Eduardo Valentin wrote:
Quoted 18 lines · ext Hans Verkuil
linux/drivers/media/radio/si4713-i2c.c line 1355
Quoted 4 lines
linux/drivers/media/radio/si4713-i2c.c new file +4
-0+switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : +if (strlen (sdev->rds_info.ps_name) +1 > control->length) { + control->length =strlen (sdev->rds_info.ps_name) +1 ;I recommend setting length to the actual maximum MAX_RDS_PS_NAME+1.
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.c new file +10
-0+ rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.ps_name, +strlen (sdev->rds_info.ps_name) +1 ); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : +if (strlen (sdev->rds_info.radio_text) +1 > control->length) { + control->length =strlen (sdev->rds_info.radio_text) +1 ;
Quoted 6 lines
Quoted 1 line
Ditto.
Right, I think doing the way you are proposing is to avoid changes that may generate failures in the following reads.
I 'll change this in the v11 as well.
OK.
Quoted 15 lines
Quoted 15 lines
linux/drivers/media/radio/si4713-i2c.h line 171
Quoted 9 lines
linux/drivers/media/radio/si4713-i2c.h new file +9
-0+struct rds_info { +u32 pi; +#define MAX_RDS_PTY 31 +u32 pty; +#define MAX_RDS_DEVIATION 90000 +u32 deviation; +#define MAX_RDS_PS_NAME 96 +u8 ps_name[MAX_RDS_PS_NAME +1 ]; +#define MAX_RDS_RADIO_TEXT 384I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.
Quoted 1 line
Quoted 1 line
Can you clarify how this is used?
Did you see this comment as well? I'm quite interested in this.
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 44 lines · ext Hans Verkuil
Quoted 19 lines · On Saturday 25 July 2009 15:15:24 Eduardo Valentin wrote:
Quoted 18 lines · ext Hans Verkuil
linux/drivers/media/radio/si4713-i2c.c line 1355
Quoted 4 lines
linux/drivers/media/radio/si4713-i2c.c new file +4
-0+switch (control->id) { +case V4L2_CID_RDS_TX_PS_NAME : +if (strlen (sdev->rds_info.ps_name) +1 > control->length) { + control->length =strlen (sdev->rds_info.ps_name) +1 ;I recommend setting length to the actual maximum MAX_RDS_PS_NAME+1.
Quoted 10 lines
linux/drivers/media/radio/si4713-i2c.c new file +10
-0+ rval = -ENOSPC ; + goto exit; + } + rval =copy_to_user (control->string, sdev->rds_info.ps_name, +strlen (sdev->rds_info.ps_name) +1 ); +break ; + +case V4L2_CID_RDS_TX_RADIO_TEXT : +if (strlen (sdev->rds_info.radio_text) +1 > control->length) { + control->length =strlen (sdev->rds_info.radio_text) +1 ;Quoted 6 lines
Quoted 1 line
Ditto.
Right, I think doing the way you are proposing is to avoid changes that may generate failures in the following reads.
I 'll change this in the v11 as well.
OK.
Quoted 15 lines
Quoted 15 lines
linux/drivers/media/radio/si4713-i2c.h line 171
Quoted 9 lines
linux/drivers/media/radio/si4713-i2c.h new file +9
-0+struct rds_info { +u32 pi; +#define MAX_RDS_PTY 31 +u32 pty; +#define MAX_RDS_DEVIATION 90000 +u32 deviation; +#define MAX_RDS_PS_NAME 96 +u8 ps_name[MAX_RDS_PS_NAME +1 ]; +#define MAX_RDS_RADIO_TEXT 384I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.
Quoted 3 lines
Quoted 1 line
Quoted 1 line
Can you clarify how this is used?
Did you see this comment as well? I'm quite interested in this.
I missed this one. But is basically what Eero said. Receivers scroll it with 8xn sized PS names.
Quoted 5 lines
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Signature · 1 line
Eduardo Valentin
RE: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
In reply to Hans VerkuilQuoted 8 lines
I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.
Quoted 5 lines
Can you clarify how this is used?
Regards,
Hans
Well, PS_NAME can be 8 x n, but only 8 bytes are shown at once... so it keeps 'scrolling', or changes periodically. There's even commercial radio stations that do so.
- Eero
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 8 lines · On Saturday 25 July 2009 15:29:38 [email protected] wrote:
Quoted 8 lines
I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.Can you clarify how this is used?
Quoted 7 lines
Quoted 3 lines
Regards,
Hans
Well,
PS_NAMEcan be 8 x n, but only 8 bytes are shown at once... so it keeps 'scrolling', or changes periodically. There's even commercial radio stations that do so.
And I'm assuming that the same is true for radio text. However, this behavior contradicts the control description in the spec, so that should be clarified.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 11 lines · ext Hans Verkuil
Quoted 10 lines · On Saturday 25 July 2009 15:29:38 [email protected] wrote:
Quoted 10 lines
I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.Can you clarify how this is used?
Regards,
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Hans
Well,
PS_NAMEcan be 8 x n, but only 8 bytes are shown at once... so it keeps 'scrolling', or changes periodically. There's even commercial radio stations that do so.And I'm assuming that the same is true for radio text. However, this behavior contradicts the control description in the spec, so that should be clarified.
Yes, I'll add a comment explaining this for those defines.
Quoted 7 lines
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Signature · 1 line
Eduardo Valentin
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 14 lines · On Saturday 25 July 2009 15:25:21 Eduardo Valentin wrote:
Quoted 13 lines · ext Hans Verkuil
Quoted 12 lines · On Saturday 25 July 2009 15:29:38 [email protected] wrote:
Quoted 11 lines
I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.Can you clarify how this is used?
Regards,
Hans
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Well,
PS_NAMEcan be 8 x n, but only 8 bytes are shown at once... so it keeps 'scrolling', or changes periodically. There's even commercial radio stations that do so.And I'm assuming that the same is true for radio text. However, this behavior contradicts the control description in the spec, so that should be clarified.
Yes, I'll add a comment explaining this for those defines.
Another question: what happens if I give a string that's e.g. 10 characters long? What will happen then?
If the string must be exactly 8 x n long, then I think that it is a good idea to start using the 'step' value of v4l2_queryctrl: this can be used to tell the application that string lengths should be a multiple of the step value. I've toyed with that idea before but I couldn't think of a good use case, but this might be it.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 6/8] FMTx: si4713: Add files to handle si4713 i2c device
Quoted 19 lines · ext Hans Verkuil
Quoted 18 lines · On Saturday 25 July 2009 15:25:21 Eduardo Valentin wrote:
Quoted 17 lines · ext Hans Verkuil
Quoted 15 lines · On Saturday 25 July 2009 15:29:38 [email protected] wrote:
Quoted 11 lines
I'm surprised at these MAX string lengths. Looking at the RDS standard it seems that the max length for the
PS_NAMEis 8 and forRADIO_TEXTit is either 32 (2A group) or 64 (2B group). I don't know which group the si4713 uses.Can you clarify how this is used?
Regards,
Hans
Well,
PS_NAMEcan be 8 x n, but only 8 bytes are shown at once... so it keeps 'scrolling', or changes periodically. There's even commercial radio stations that do so.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
And I'm assuming that the same is true for radio text. However, this behavior contradicts the control description in the spec, so that should be clarified.
Yes, I'll add a comment explaining this for those defines.
Another question: what happens if I give a string that's e.g. 10 characters long? What will happen then?
I believe receiver will still scroll, but may get confused. This case, it is better to pad with spaces.
Quoted 6 lines
If the string must be exactly 8 x n long, then I think that it is a good idea to start using the 'step' value of
v4l2_queryctrl: this can be used to tell the application that string lengths should be a multiple of the step value. I've toyed with that idea before but I couldn't think of a good use case, but this might be it.
I think that would be good. It is a way to report to user land what can be done in these cases which strings can be chopped in small pieces. Of course, documenting this part it is appreciated.
Quoted 7 lines
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Signature · 1 line
Eduardo Valentin
Changes to the string control handling
Hi Eduardo,
Quoted 10 lines · On Saturday 25 July 2009 16:41:27 Eduardo Valentin wrote:
Quoted 5 lines · ext Hans Verkuil
If the string must be exactly 8 x n long, then I think that it is a good idea to start using the 'step' value of
v4l2_queryctrl: this can be used to tell the application that string lengths should be a multiple of the step value. I've toyed with that idea before but I couldn't think of a good use case, but this might be it.I think that would be good. It is a way to report to user land what can be done in these cases which strings can be chopped in small pieces. Of course, documenting this part it is appreciated.
Ok, I've implemented this. While doing this I realized that I had to change a few things:
1) the 'length' field in v4l2_ext_control has been renamed to 'size'. The name 'length' was too easy to confuse with 'string length' while in reality it referred to the memory size of the control payload. 'size' is more appropriate.
2) the 'minimum' and 'maximum' fields of v4l2_queryctrl now return the min and max string lengths, i.e. *without* terminating zero. I realized that what VIDIOC_QUERYCTRL returns has nothing to do with how much memory to reserve for the string control. It is about the properties of the string itself and it is not normal to include the terminating zero when talking about a string length.
I've incorporated everything in my v4l-dvb-strctrl tree. I apologize for the fact that you have to make yet another series of patches, but these changes are typical when you start implementing and documenting a new feature for the first time.
Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: Changes to the string control handling
Hello Hans,
Quoted 29 lines · Hans Verkuil
Hi Eduardo,
Quoted 10 lines · On Saturday 25 July 2009 16:41:27 Eduardo Valentin wrote:
Quoted 5 lines · ext Hans Verkuil
If the string must be exactly 8 x n long, then I think that it is a good idea to start using the 'step' value of
v4l2_queryctrl: this can be used to tell the application that string lengths should be a multiple of the step value. I've toyed with that idea before but I couldn't think of a good use case, but this might be it.I think that would be good. It is a way to report to user land what can be done in these cases which strings can be chopped in small pieces. Of course, documenting this part it is appreciated.
Ok, I've implemented this. While doing this I realized that I had to change a few things:
1) the 'length' field in
v4l2_ext_controlhas been renamed to 'size'. The name 'length' was too easy to confuse with 'string length' while in reality it referred to the memory size of the control payload. 'size' is more appropriate.2) the 'minimum' and 'maximum' fields of
v4l2_queryctrlnow return the min and max string lengths, i.e. *without* terminating zero. I realized that whatVIDIOC_QUERYCTRLreturns has nothing to do with how much memory to reserve for the string control. It is about the properties of the string itself and it is not normal to include the terminating zero when talking about a string length.
Quoted 4 lines
I've incorporated everything in my v4l-dvb-strctrl tree. I apologize for the fact that you have to make yet another series of patches, but these changes are typical when you start implementing and documenting a new feature for the first time.
I believe now things about string handling are becoming much clear this way. No worries about the fact that we need another (or even more) series for si4713. As it is the first driver using the new API, it is better to forge it properly, so people
can use it as example.
When I come back to office, I'll have the opportunity to test the new series. Only after that I can send it again. But I will try to send it as soon as possible.
Quoted 12 lines
Regards,
Hans
--
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom --
To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Eduardo Bezerra Valentin
Re: [PATCHv10 3/8] v4l2: video device: Add FM_TX controls default configurations
In reply to Eduardo ValentinQuoted 68 lines · On Friday 24 July 2009 18:37:23 Eduardo Valentin wrote:
Signed-off-by Eduardo Valentin <[email protected]>--- linux/drivers/media/video/v4l2-common.c | 63 ++++++++++++++++++++++++++++++- 1 files changed, 62 insertions(+), 1 deletions(-)linux/drivers/media/video/v4l2-common.c +33
-1@@ -343,6 +343,12 @@ const char **v4l2_ctrl_get_menu(u32 id)"Sepia" , NULL }; +static const char *fm_tx_preemphasis[] = { +"No preemphasis" , +"50 useconds" , +"75 useconds" , +NULL , + };switch (id) {case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ :@@ -381,6 +387,8 @@ const char **v4l2_ctrl_get_menu(u32 id)return camera_exposure_auto;case V4L2_CID_COLORFX :return colorfx; +case V4L2_CID_FM_TX_PREEMPHASIS : +return fm_tx_preemphasis;default :return NULL ; }@@ -479,6 +487,28 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_ZOOM_CONTINUOUS :return "Zoom, Continuous" ;case V4L2_CID_PRIVACY :return "Privacy" ; +/* FM Radio Modulator control */ +case V4L2_CID_FM_TX_CLASS :return "FM Radio Modulator Controls" ; +case V4L2_CID_RDS_TX_PI :return "RDS Program ID" ; +case V4L2_CID_RDS_TX_PTY :return "RDS Program Type" ; +case V4L2_CID_RDS_TX_DEVIATION :return "RDS Signal Deviation" ; +case V4L2_CID_RDS_TX_PS_NAME :return "RDS PS Name" ; +case V4L2_CID_RDS_TX_RADIO_TEXT :return "RDS Radio Text" ; +case V4L2_CID_AUDIO_LIMITER_ENABLED :return "Audio Limiter Feature Enabled" ; +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME :return "Audio Limiter Release Time" ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION :return "Audio Limiter Deviation" ; +case V4L2_CID_AUDIO_COMPRESSION_ENABLED :return "Audio Compression Feature Enabled" ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN :return "Audio Compression Gain" ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD :return "Audio Compression Threshold" ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME :return "Audio Compression Attack Time" ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME :return "Audio Compression Release Time" ; +case V4L2_CID_PILOT_TONE_ENABLED :return "Pilot Tone Feature Enabled" ; +case V4L2_CID_PILOT_TONE_DEVIATION :return "Pilot Tone Deviation" ; +case V4L2_CID_PILOT_TONE_FREQUENCY :return "Pilot Tone Frequency" ; +case V4L2_CID_FM_TX_PREEMPHASIS :return "Pre-emphasis settings" ; +case V4L2_CID_TUNE_POWER_LEVEL :return "Tune Power Level" ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR :return "Tune Antenna Capacitor" ; +default :return NULL ; }@@ -500,7 +530,18 @@ EXPORT_SYMBOL(v4l2_ctrl_is_value64);* This information is used inside v4l2_compat_ioctl32. */ int v4l2_ctrl_is_pointer (u32 id) { -return 0 ; +int is_pointer; + +switch (id) {
linux/drivers/media/video/v4l2-common.c EXPORT_SYMBOL(v4l2_ctrl_is_value64); · line 545
Quoted 10 lines
linux/drivers/media/video/v4l2-common.c +9
-0+case V4L2_CID_RDS_TX_PS_NAME : +case V4L2_CID_RDS_TX_RADIO_TEXT : + is_pointer =1 ; +break ; +default : + is_pointer =0 ; + } + +return is_pointer; }
There is no need for a temp variable. Just do this:
int v4l2_ctrl_is_pointer(u32 id)
{
switch (id) {
case V4L2_CID_RDS_TX_PS_NAME:
case V4L2_CID_RDS_TX_RADIO_TEXT:
return 1;
default:
return 0;
}
}Regards,
Hans
Signature · 1 line
Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Re: [PATCHv10 3/8] v4l2: video device: Add FM_TX controls default configurations
Quoted 93 lines · ext Hans Verkuil
Quoted 68 lines · On Friday 24 July 2009 18:37:23 Eduardo Valentin wrote:
Signed-off-by Eduardo Valentin <[email protected]>--- linux/drivers/media/video/v4l2-common.c | 63 ++++++++++++++++++++++++++++++- 1 files changed, 62 insertions(+), 1 deletions(-)linux/drivers/media/video/v4l2-common.c +33
-1@@ -343,6 +343,12 @@ const char **v4l2_ctrl_get_menu(u32 id)"Sepia" , NULL }; +static const char *fm_tx_preemphasis[] = { +"No preemphasis" , +"50 useconds" , +"75 useconds" , +NULL , + };switch (id) {case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ :@@ -381,6 +387,8 @@ const char **v4l2_ctrl_get_menu(u32 id)return camera_exposure_auto;case V4L2_CID_COLORFX :return colorfx; +case V4L2_CID_FM_TX_PREEMPHASIS : +return fm_tx_preemphasis;default :return NULL ; }@@ -479,6 +487,28 @@ const char *v4l2_ctrl_get_name(u32 id)case V4L2_CID_ZOOM_CONTINUOUS :return "Zoom, Continuous" ;case V4L2_CID_PRIVACY :return "Privacy" ; +/* FM Radio Modulator control */ +case V4L2_CID_FM_TX_CLASS :return "FM Radio Modulator Controls" ; +case V4L2_CID_RDS_TX_PI :return "RDS Program ID" ; +case V4L2_CID_RDS_TX_PTY :return "RDS Program Type" ; +case V4L2_CID_RDS_TX_DEVIATION :return "RDS Signal Deviation" ; +case V4L2_CID_RDS_TX_PS_NAME :return "RDS PS Name" ; +case V4L2_CID_RDS_TX_RADIO_TEXT :return "RDS Radio Text" ; +case V4L2_CID_AUDIO_LIMITER_ENABLED :return "Audio Limiter Feature Enabled" ; +case V4L2_CID_AUDIO_LIMITER_RELEASE_TIME :return "Audio Limiter Release Time" ; +case V4L2_CID_AUDIO_LIMITER_DEVIATION :return "Audio Limiter Deviation" ; +case V4L2_CID_AUDIO_COMPRESSION_ENABLED :return "Audio Compression Feature Enabled" ; +case V4L2_CID_AUDIO_COMPRESSION_GAIN :return "Audio Compression Gain" ; +case V4L2_CID_AUDIO_COMPRESSION_THRESHOLD :return "Audio Compression Threshold" ; +case V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME :return "Audio Compression Attack Time" ; +case V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME :return "Audio Compression Release Time" ; +case V4L2_CID_PILOT_TONE_ENABLED :return "Pilot Tone Feature Enabled" ; +case V4L2_CID_PILOT_TONE_DEVIATION :return "Pilot Tone Deviation" ; +case V4L2_CID_PILOT_TONE_FREQUENCY :return "Pilot Tone Frequency" ; +case V4L2_CID_FM_TX_PREEMPHASIS :return "Pre-emphasis settings" ; +case V4L2_CID_TUNE_POWER_LEVEL :return "Tune Power Level" ; +case V4L2_CID_TUNE_ANTENNA_CAPACITOR :return "Tune Antenna Capacitor" ; +default :return NULL ; }@@ -500,7 +530,18 @@ EXPORT_SYMBOL(v4l2_ctrl_is_value64);* This information is used inside v4l2_compat_ioctl32. */ int v4l2_ctrl_is_pointer (u32 id) { -return 0 ; +int is_pointer; + +switch (id) {linux/drivers/media/video/v4l2-common.c EXPORT_SYMBOL(v4l2_ctrl_is_value64); · line 545
Quoted 10 lines
linux/drivers/media/video/v4l2-common.c +9
-0+case V4L2_CID_RDS_TX_PS_NAME : +case V4L2_CID_RDS_TX_RADIO_TEXT : + is_pointer =1 ; +break ; +default : + is_pointer =0 ; + } + +return is_pointer; }There is no need for a temp variable. Just do this:
int
v4l2_ctrl_is_pointer(u32 id){ switch (id) { case V4L2_CID_RDS_TX_PS_NAME: case V4L2_CID_RDS_TX_RADIO_TEXT: return 1; default: return 0; } }
Quoted 3 lines
Regards,
Hans
Right, resending v11 with this minor change.
Quoted 4 lines
Signature · 2 lines
-- Hans Verkuil - video4linux developer - sponsored by TANDBERG Telecom
Signature · 1 line
Eduardo Valentin