1b09cd163SJoonyoung Shim /* 2b09cd163SJoonyoung Shim * drivers/media/radio/si470x/radio-si470x.h 3b09cd163SJoonyoung Shim * 4b09cd163SJoonyoung Shim * Driver for radios with Silicon Labs Si470x FM Radio Receivers 5b09cd163SJoonyoung Shim * 6b09cd163SJoonyoung Shim * Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net> 7b09cd163SJoonyoung Shim * 8b09cd163SJoonyoung Shim * This program is free software; you can redistribute it and/or modify 9b09cd163SJoonyoung Shim * it under the terms of the GNU General Public License as published by 10b09cd163SJoonyoung Shim * the Free Software Foundation; either version 2 of the License, or 11b09cd163SJoonyoung Shim * (at your option) any later version. 12b09cd163SJoonyoung Shim * 13b09cd163SJoonyoung Shim * This program is distributed in the hope that it will be useful, 14b09cd163SJoonyoung Shim * but WITHOUT ANY WARRANTY; without even the implied warranty of 15b09cd163SJoonyoung Shim * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16b09cd163SJoonyoung Shim * GNU General Public License for more details. 17b09cd163SJoonyoung Shim * 18b09cd163SJoonyoung Shim * You should have received a copy of the GNU General Public License 19b09cd163SJoonyoung Shim * along with this program; if not, write to the Free Software 20b09cd163SJoonyoung Shim * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21b09cd163SJoonyoung Shim */ 22b09cd163SJoonyoung Shim 23b09cd163SJoonyoung Shim 24b09cd163SJoonyoung Shim /* driver definitions */ 25b09cd163SJoonyoung Shim #define DRIVER_NAME "radio-si470x" 26b09cd163SJoonyoung Shim 27b09cd163SJoonyoung Shim 28b09cd163SJoonyoung Shim /* kernel includes */ 29b09cd163SJoonyoung Shim #include <linux/kernel.h> 30b09cd163SJoonyoung Shim #include <linux/module.h> 31b09cd163SJoonyoung Shim #include <linux/init.h> 32b09cd163SJoonyoung Shim #include <linux/slab.h> 33b09cd163SJoonyoung Shim #include <linux/smp_lock.h> 34b09cd163SJoonyoung Shim #include <linux/input.h> 35b09cd163SJoonyoung Shim #include <linux/version.h> 36b09cd163SJoonyoung Shim #include <linux/videodev2.h> 37b09cd163SJoonyoung Shim #include <linux/mutex.h> 38b09cd163SJoonyoung Shim #include <media/v4l2-common.h> 39b09cd163SJoonyoung Shim #include <media/v4l2-ioctl.h> 40b09cd163SJoonyoung Shim #include <media/rds.h> 41b09cd163SJoonyoung Shim #include <asm/unaligned.h> 42b09cd163SJoonyoung Shim 43b09cd163SJoonyoung Shim 449dcb79c2STobias Lorenz 45b09cd163SJoonyoung Shim /************************************************************************** 46b09cd163SJoonyoung Shim * Register Definitions 47b09cd163SJoonyoung Shim **************************************************************************/ 48b09cd163SJoonyoung Shim #define RADIO_REGISTER_SIZE 2 /* 16 register bit width */ 49b09cd163SJoonyoung Shim #define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */ 50b09cd163SJoonyoung Shim #define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */ 51b09cd163SJoonyoung Shim 52b09cd163SJoonyoung Shim #define DEVICEID 0 /* Device ID */ 53b09cd163SJoonyoung Shim #define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */ 54b09cd163SJoonyoung Shim #define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */ 55b09cd163SJoonyoung Shim 56b09cd163SJoonyoung Shim #define CHIPID 1 /* Chip ID */ 57b09cd163SJoonyoung Shim #define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */ 58b09cd163SJoonyoung Shim #define CHIPID_DEV 0x0200 /* bits 09..09: Device */ 59b09cd163SJoonyoung Shim #define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */ 60b09cd163SJoonyoung Shim 61b09cd163SJoonyoung Shim #define POWERCFG 2 /* Power Configuration */ 62b09cd163SJoonyoung Shim #define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */ 63b09cd163SJoonyoung Shim #define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */ 64b09cd163SJoonyoung Shim #define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */ 65b09cd163SJoonyoung Shim #define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */ 66b09cd163SJoonyoung Shim #define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */ 67b09cd163SJoonyoung Shim #define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */ 68b09cd163SJoonyoung Shim #define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */ 69b09cd163SJoonyoung Shim #define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */ 70b09cd163SJoonyoung Shim #define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */ 71b09cd163SJoonyoung Shim 72b09cd163SJoonyoung Shim #define CHANNEL 3 /* Channel */ 73b09cd163SJoonyoung Shim #define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */ 74b09cd163SJoonyoung Shim #define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */ 75b09cd163SJoonyoung Shim 76b09cd163SJoonyoung Shim #define SYSCONFIG1 4 /* System Configuration 1 */ 77b09cd163SJoonyoung Shim #define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */ 78b09cd163SJoonyoung Shim #define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */ 79b09cd163SJoonyoung Shim #define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */ 80b09cd163SJoonyoung Shim #define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */ 81b09cd163SJoonyoung Shim #define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */ 82b09cd163SJoonyoung Shim #define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */ 83b09cd163SJoonyoung Shim #define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */ 84b09cd163SJoonyoung Shim #define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */ 85b09cd163SJoonyoung Shim #define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */ 86b09cd163SJoonyoung Shim 87b09cd163SJoonyoung Shim #define SYSCONFIG2 5 /* System Configuration 2 */ 88b09cd163SJoonyoung Shim #define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */ 89b09cd163SJoonyoung Shim #define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */ 90b09cd163SJoonyoung Shim #define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */ 91b09cd163SJoonyoung Shim #define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */ 92b09cd163SJoonyoung Shim 93b09cd163SJoonyoung Shim #define SYSCONFIG3 6 /* System Configuration 3 */ 94b09cd163SJoonyoung Shim #define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */ 95b09cd163SJoonyoung Shim #define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */ 96b09cd163SJoonyoung Shim #define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */ 97b09cd163SJoonyoung Shim #define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */ 98b09cd163SJoonyoung Shim 99b09cd163SJoonyoung Shim #define TEST1 7 /* Test 1 */ 100b09cd163SJoonyoung Shim #define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */ 101b09cd163SJoonyoung Shim 102b09cd163SJoonyoung Shim #define TEST2 8 /* Test 2 */ 103b09cd163SJoonyoung Shim /* TEST2 only contains reserved bits */ 104b09cd163SJoonyoung Shim 105b09cd163SJoonyoung Shim #define BOOTCONFIG 9 /* Boot Configuration */ 106b09cd163SJoonyoung Shim /* BOOTCONFIG only contains reserved bits */ 107b09cd163SJoonyoung Shim 108b09cd163SJoonyoung Shim #define STATUSRSSI 10 /* Status RSSI */ 109b09cd163SJoonyoung Shim #define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */ 110b09cd163SJoonyoung Shim #define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */ 111b09cd163SJoonyoung Shim #define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */ 112b09cd163SJoonyoung Shim #define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */ 113b09cd163SJoonyoung Shim #define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */ 114b09cd163SJoonyoung Shim #define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */ 115b09cd163SJoonyoung Shim #define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */ 116b09cd163SJoonyoung Shim #define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */ 117b09cd163SJoonyoung Shim 118b09cd163SJoonyoung Shim #define READCHAN 11 /* Read Channel */ 119b09cd163SJoonyoung Shim #define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */ 120b09cd163SJoonyoung Shim #define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */ 121b09cd163SJoonyoung Shim #define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */ 122b09cd163SJoonyoung Shim #define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */ 123b09cd163SJoonyoung Shim 124b09cd163SJoonyoung Shim #define RDSA 12 /* RDSA */ 125b09cd163SJoonyoung Shim #define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */ 126b09cd163SJoonyoung Shim 127b09cd163SJoonyoung Shim #define RDSB 13 /* RDSB */ 128b09cd163SJoonyoung Shim #define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */ 129b09cd163SJoonyoung Shim 130b09cd163SJoonyoung Shim #define RDSC 14 /* RDSC */ 131b09cd163SJoonyoung Shim #define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */ 132b09cd163SJoonyoung Shim 133b09cd163SJoonyoung Shim #define RDSD 15 /* RDSD */ 134b09cd163SJoonyoung Shim #define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */ 135b09cd163SJoonyoung Shim 136b09cd163SJoonyoung Shim 1379dcb79c2STobias Lorenz 138b09cd163SJoonyoung Shim /************************************************************************** 139b09cd163SJoonyoung Shim * General Driver Definitions 140b09cd163SJoonyoung Shim **************************************************************************/ 141b09cd163SJoonyoung Shim 142b09cd163SJoonyoung Shim /* 143b09cd163SJoonyoung Shim * si470x_device - private data 144b09cd163SJoonyoung Shim */ 145b09cd163SJoonyoung Shim struct si470x_device { 146b09cd163SJoonyoung Shim struct video_device *videodev; 147b09cd163SJoonyoung Shim 1489dcb79c2STobias Lorenz /* driver management */ 1499dcb79c2STobias Lorenz unsigned int users; 1509dcb79c2STobias Lorenz 1519dcb79c2STobias Lorenz /* Silabs internal registers (0..15) */ 1529dcb79c2STobias Lorenz unsigned short registers[RADIO_REGISTER_NUM]; 1539dcb79c2STobias Lorenz 1549dcb79c2STobias Lorenz /* RDS receive buffer */ 1559dcb79c2STobias Lorenz wait_queue_head_t read_queue; 1569dcb79c2STobias Lorenz struct mutex lock; /* buffer locking */ 1579dcb79c2STobias Lorenz unsigned char *buffer; /* size is always multiple of three */ 1589dcb79c2STobias Lorenz unsigned int buf_size; 1599dcb79c2STobias Lorenz unsigned int rd_index; 1609dcb79c2STobias Lorenz unsigned int wr_index; 161cc35bbddSJoonyoung Shim 162cc35bbddSJoonyoung Shim #if defined(CONFIG_USB_SI470X) || defined(CONFIG_USB_SI470X_MODULE) 163b09cd163SJoonyoung Shim /* reference to USB and video device */ 164b09cd163SJoonyoung Shim struct usb_device *usbdev; 165b09cd163SJoonyoung Shim struct usb_interface *intf; 166b09cd163SJoonyoung Shim 167b09cd163SJoonyoung Shim /* Interrupt endpoint handling */ 168b09cd163SJoonyoung Shim char *int_in_buffer; 169b09cd163SJoonyoung Shim struct usb_endpoint_descriptor *int_in_endpoint; 170b09cd163SJoonyoung Shim struct urb *int_in_urb; 171b09cd163SJoonyoung Shim int int_in_running; 172b09cd163SJoonyoung Shim 173b09cd163SJoonyoung Shim /* scratch page */ 174b09cd163SJoonyoung Shim unsigned char software_version; 175b09cd163SJoonyoung Shim unsigned char hardware_version; 176b09cd163SJoonyoung Shim 177b09cd163SJoonyoung Shim /* driver management */ 178b09cd163SJoonyoung Shim unsigned char disconnected; 179b09cd163SJoonyoung Shim struct mutex disconnect_lock; 180cc35bbddSJoonyoung Shim #endif 181b09cd163SJoonyoung Shim 1829dcb79c2STobias Lorenz #if defined(CONFIG_I2C_SI470X) || defined(CONFIG_I2C_SI470X_MODULE) 1839dcb79c2STobias Lorenz struct i2c_client *client; 1849dcb79c2STobias Lorenz #endif 185b09cd163SJoonyoung Shim }; 186b09cd163SJoonyoung Shim 187b09cd163SJoonyoung Shim 1889dcb79c2STobias Lorenz 1899dcb79c2STobias Lorenz /************************************************************************** 1909dcb79c2STobias Lorenz * Firmware Versions 1919dcb79c2STobias Lorenz **************************************************************************/ 1929dcb79c2STobias Lorenz 1939dcb79c2STobias Lorenz #define RADIO_FW_VERSION 15 1949dcb79c2STobias Lorenz 1959dcb79c2STobias Lorenz 1969dcb79c2STobias Lorenz 1979dcb79c2STobias Lorenz /************************************************************************** 1989dcb79c2STobias Lorenz * Frequency Multiplicator 1999dcb79c2STobias Lorenz **************************************************************************/ 2009dcb79c2STobias Lorenz 201b09cd163SJoonyoung Shim /* 202b09cd163SJoonyoung Shim * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW, 203b09cd163SJoonyoung Shim * 62.5 kHz otherwise. 204b09cd163SJoonyoung Shim * The tuner is able to have a channel spacing of 50, 100 or 200 kHz. 205b09cd163SJoonyoung Shim * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW 206b09cd163SJoonyoung Shim * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000 207b09cd163SJoonyoung Shim */ 208b09cd163SJoonyoung Shim #define FREQ_MUL (1000000 / 62.5) 209b09cd163SJoonyoung Shim 210b09cd163SJoonyoung Shim 211b09cd163SJoonyoung Shim 212b09cd163SJoonyoung Shim /************************************************************************** 213b09cd163SJoonyoung Shim * Common Functions 214b09cd163SJoonyoung Shim **************************************************************************/ 215b09cd163SJoonyoung Shim extern struct video_device si470x_viddev_template; 216b09cd163SJoonyoung Shim int si470x_get_register(struct si470x_device *radio, int regnr); 217b09cd163SJoonyoung Shim int si470x_set_register(struct si470x_device *radio, int regnr); 2183c7cc8d5SJoonyoung Shim int si470x_disconnect_check(struct si470x_device *radio); 219b09cd163SJoonyoung Shim int si470x_set_freq(struct si470x_device *radio, unsigned int freq); 220b09cd163SJoonyoung Shim int si470x_start(struct si470x_device *radio); 221b09cd163SJoonyoung Shim int si470x_stop(struct si470x_device *radio); 222b09cd163SJoonyoung Shim int si470x_rds_on(struct si470x_device *radio); 2231aa925c9SJoonyoung Shim int si470x_fops_open(struct file *file); 2241aa925c9SJoonyoung Shim int si470x_fops_release(struct file *file); 225b09cd163SJoonyoung Shim int si470x_vidioc_querycap(struct file *file, void *priv, 226b09cd163SJoonyoung Shim struct v4l2_capability *capability); 227