Path: blob/master/drivers/media/radio/si470x/radio-si470x.h
15112 views
/*1* drivers/media/radio/si470x/radio-si470x.h2*3* Driver for radios with Silicon Labs Si470x FM Radio Receivers4*5* Copyright (c) 2009 Tobias Lorenz <[email protected]>6*7* This program is free software; you can redistribute it and/or modify8* it under the terms of the GNU General Public License as published by9* the Free Software Foundation; either version 2 of the License, or10* (at your option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA20*/212223/* driver definitions */24#define DRIVER_NAME "radio-si470x"252627/* kernel includes */28#include <linux/kernel.h>29#include <linux/module.h>30#include <linux/init.h>31#include <linux/sched.h>32#include <linux/slab.h>33#include <linux/input.h>34#include <linux/version.h>35#include <linux/videodev2.h>36#include <linux/mutex.h>37#include <media/v4l2-common.h>38#include <media/v4l2-ioctl.h>39#include <asm/unaligned.h>40414243/**************************************************************************44* Register Definitions45**************************************************************************/46#define RADIO_REGISTER_SIZE 2 /* 16 register bit width */47#define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */48#define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */4950#define DEVICEID 0 /* Device ID */51#define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */52#define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */5354#define CHIPID 1 /* Chip ID */55#define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */56#define CHIPID_DEV 0x0200 /* bits 09..09: Device */57#define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */5859#define POWERCFG 2 /* Power Configuration */60#define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */61#define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */62#define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */63#define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */64#define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */65#define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */66#define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */67#define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */68#define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */6970#define CHANNEL 3 /* Channel */71#define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */72#define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */7374#define SYSCONFIG1 4 /* System Configuration 1 */75#define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */76#define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */77#define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */78#define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */79#define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */80#define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */81#define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */82#define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */83#define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */8485#define SYSCONFIG2 5 /* System Configuration 2 */86#define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */87#define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */88#define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */89#define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */9091#define SYSCONFIG3 6 /* System Configuration 3 */92#define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */93#define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */94#define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */95#define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */9697#define TEST1 7 /* Test 1 */98#define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */99100#define TEST2 8 /* Test 2 */101/* TEST2 only contains reserved bits */102103#define BOOTCONFIG 9 /* Boot Configuration */104/* BOOTCONFIG only contains reserved bits */105106#define STATUSRSSI 10 /* Status RSSI */107#define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */108#define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */109#define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */110#define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */111#define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */112#define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */113#define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */114#define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */115116#define READCHAN 11 /* Read Channel */117#define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */118#define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */119#define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */120#define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */121122#define RDSA 12 /* RDSA */123#define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */124125#define RDSB 13 /* RDSB */126#define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */127128#define RDSC 14 /* RDSC */129#define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */130131#define RDSD 15 /* RDSD */132#define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */133134135136/**************************************************************************137* General Driver Definitions138**************************************************************************/139140/*141* si470x_device - private data142*/143struct si470x_device {144struct video_device *videodev;145146/* driver management */147unsigned int users;148149/* Silabs internal registers (0..15) */150unsigned short registers[RADIO_REGISTER_NUM];151152/* RDS receive buffer */153wait_queue_head_t read_queue;154struct mutex lock; /* buffer locking */155unsigned char *buffer; /* size is always multiple of three */156unsigned int buf_size;157unsigned int rd_index;158unsigned int wr_index;159160struct completion completion;161bool stci_enabled; /* Seek/Tune Complete Interrupt */162163#if defined(CONFIG_USB_SI470X) || defined(CONFIG_USB_SI470X_MODULE)164/* reference to USB and video device */165struct usb_device *usbdev;166struct usb_interface *intf;167168/* Interrupt endpoint handling */169char *int_in_buffer;170struct usb_endpoint_descriptor *int_in_endpoint;171struct urb *int_in_urb;172int int_in_running;173174/* scratch page */175unsigned char software_version;176unsigned char hardware_version;177178/* driver management */179unsigned char disconnected;180#endif181182#if defined(CONFIG_I2C_SI470X) || defined(CONFIG_I2C_SI470X_MODULE)183struct i2c_client *client;184#endif185};186187188189/**************************************************************************190* Firmware Versions191**************************************************************************/192193#define RADIO_FW_VERSION 15194195196197/**************************************************************************198* Frequency Multiplicator199**************************************************************************/200201/*202* The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,203* 62.5 kHz otherwise.204* The tuner is able to have a channel spacing of 50, 100 or 200 kHz.205* tuner->capability is therefore set to V4L2_TUNER_CAP_LOW206* The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000207*/208#define FREQ_MUL (1000000 / 62.5)209210211212/**************************************************************************213* Common Functions214**************************************************************************/215extern struct video_device si470x_viddev_template;216int si470x_get_register(struct si470x_device *radio, int regnr);217int si470x_set_register(struct si470x_device *radio, int regnr);218int si470x_disconnect_check(struct si470x_device *radio);219int si470x_set_freq(struct si470x_device *radio, unsigned int freq);220int si470x_start(struct si470x_device *radio);221int si470x_stop(struct si470x_device *radio);222int si470x_fops_open(struct file *file);223int si470x_fops_release(struct file *file);224int si470x_vidioc_querycap(struct file *file, void *priv,225struct v4l2_capability *capability);226227228