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> 32788f6febSRandy Dunlap #include <linux/sched.h> 33b09cd163SJoonyoung Shim #include <linux/slab.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 <asm/unaligned.h> 41b09cd163SJoonyoung Shim 42b09cd163SJoonyoung Shim 439dcb79c2STobias Lorenz 44b09cd163SJoonyoung Shim /************************************************************************** 45b09cd163SJoonyoung Shim * Register Definitions 46b09cd163SJoonyoung Shim **************************************************************************/ 47b09cd163SJoonyoung Shim #define RADIO_REGISTER_SIZE 2 /* 16 register bit width */ 48b09cd163SJoonyoung Shim #define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */ 49b09cd163SJoonyoung Shim #define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */ 50b09cd163SJoonyoung Shim 51b09cd163SJoonyoung Shim #define DEVICEID 0 /* Device ID */ 52b09cd163SJoonyoung Shim #define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */ 53b09cd163SJoonyoung Shim #define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */ 54b09cd163SJoonyoung Shim 55b09cd163SJoonyoung Shim #define CHIPID 1 /* Chip ID */ 56b09cd163SJoonyoung Shim #define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */ 57b09cd163SJoonyoung Shim #define CHIPID_DEV 0x0200 /* bits 09..09: Device */ 58b09cd163SJoonyoung Shim #define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */ 59b09cd163SJoonyoung Shim 60b09cd163SJoonyoung Shim #define POWERCFG 2 /* Power Configuration */ 61b09cd163SJoonyoung Shim #define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */ 62b09cd163SJoonyoung Shim #define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */ 63b09cd163SJoonyoung Shim #define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */ 64b09cd163SJoonyoung Shim #define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */ 65b09cd163SJoonyoung Shim #define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */ 66b09cd163SJoonyoung Shim #define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */ 67b09cd163SJoonyoung Shim #define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */ 68b09cd163SJoonyoung Shim #define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */ 69b09cd163SJoonyoung Shim #define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */ 70b09cd163SJoonyoung Shim 71b09cd163SJoonyoung Shim #define CHANNEL 3 /* Channel */ 72b09cd163SJoonyoung Shim #define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */ 73b09cd163SJoonyoung Shim #define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */ 74b09cd163SJoonyoung Shim 75b09cd163SJoonyoung Shim #define SYSCONFIG1 4 /* System Configuration 1 */ 76b09cd163SJoonyoung Shim #define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */ 77b09cd163SJoonyoung Shim #define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */ 78b09cd163SJoonyoung Shim #define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */ 79b09cd163SJoonyoung Shim #define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */ 80b09cd163SJoonyoung Shim #define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */ 81b09cd163SJoonyoung Shim #define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */ 82b09cd163SJoonyoung Shim #define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */ 83b09cd163SJoonyoung Shim #define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */ 84b09cd163SJoonyoung Shim #define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */ 85b09cd163SJoonyoung Shim 86b09cd163SJoonyoung Shim #define SYSCONFIG2 5 /* System Configuration 2 */ 87b09cd163SJoonyoung Shim #define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */ 88b09cd163SJoonyoung Shim #define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */ 89b09cd163SJoonyoung Shim #define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */ 90b09cd163SJoonyoung Shim #define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */ 91b09cd163SJoonyoung Shim 92b09cd163SJoonyoung Shim #define SYSCONFIG3 6 /* System Configuration 3 */ 93b09cd163SJoonyoung Shim #define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */ 94b09cd163SJoonyoung Shim #define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */ 95b09cd163SJoonyoung Shim #define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */ 96b09cd163SJoonyoung Shim #define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */ 97b09cd163SJoonyoung Shim 98b09cd163SJoonyoung Shim #define TEST1 7 /* Test 1 */ 99b09cd163SJoonyoung Shim #define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */ 100b09cd163SJoonyoung Shim 101b09cd163SJoonyoung Shim #define TEST2 8 /* Test 2 */ 102b09cd163SJoonyoung Shim /* TEST2 only contains reserved bits */ 103b09cd163SJoonyoung Shim 104b09cd163SJoonyoung Shim #define BOOTCONFIG 9 /* Boot Configuration */ 105b09cd163SJoonyoung Shim /* BOOTCONFIG only contains reserved bits */ 106b09cd163SJoonyoung Shim 107b09cd163SJoonyoung Shim #define STATUSRSSI 10 /* Status RSSI */ 108b09cd163SJoonyoung Shim #define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */ 109b09cd163SJoonyoung Shim #define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */ 110b09cd163SJoonyoung Shim #define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */ 111b09cd163SJoonyoung Shim #define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */ 112b09cd163SJoonyoung Shim #define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */ 113b09cd163SJoonyoung Shim #define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */ 114b09cd163SJoonyoung Shim #define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */ 115b09cd163SJoonyoung Shim #define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */ 116b09cd163SJoonyoung Shim 117b09cd163SJoonyoung Shim #define READCHAN 11 /* Read Channel */ 118b09cd163SJoonyoung Shim #define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */ 119b09cd163SJoonyoung Shim #define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */ 120b09cd163SJoonyoung Shim #define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */ 121b09cd163SJoonyoung Shim #define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */ 122b09cd163SJoonyoung Shim 123b09cd163SJoonyoung Shim #define RDSA 12 /* RDSA */ 124b09cd163SJoonyoung Shim #define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */ 125b09cd163SJoonyoung Shim 126b09cd163SJoonyoung Shim #define RDSB 13 /* RDSB */ 127b09cd163SJoonyoung Shim #define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */ 128b09cd163SJoonyoung Shim 129b09cd163SJoonyoung Shim #define RDSC 14 /* RDSC */ 130b09cd163SJoonyoung Shim #define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */ 131b09cd163SJoonyoung Shim 132b09cd163SJoonyoung Shim #define RDSD 15 /* RDSD */ 133b09cd163SJoonyoung Shim #define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */ 134b09cd163SJoonyoung Shim 135b09cd163SJoonyoung Shim 1369dcb79c2STobias Lorenz 137b09cd163SJoonyoung Shim /************************************************************************** 138b09cd163SJoonyoung Shim * General Driver Definitions 139b09cd163SJoonyoung Shim **************************************************************************/ 140b09cd163SJoonyoung Shim 141b09cd163SJoonyoung Shim /* 142b09cd163SJoonyoung Shim * si470x_device - private data 143b09cd163SJoonyoung Shim */ 144b09cd163SJoonyoung Shim struct si470x_device { 145b09cd163SJoonyoung Shim struct video_device *videodev; 146b09cd163SJoonyoung Shim 1479dcb79c2STobias Lorenz /* driver management */ 1489dcb79c2STobias Lorenz unsigned int users; 1499dcb79c2STobias Lorenz 1509dcb79c2STobias Lorenz /* Silabs internal registers (0..15) */ 1519dcb79c2STobias Lorenz unsigned short registers[RADIO_REGISTER_NUM]; 1529dcb79c2STobias Lorenz 1539dcb79c2STobias Lorenz /* RDS receive buffer */ 1549dcb79c2STobias Lorenz wait_queue_head_t read_queue; 1559dcb79c2STobias Lorenz struct mutex lock; /* buffer locking */ 1569dcb79c2STobias Lorenz unsigned char *buffer; /* size is always multiple of three */ 1579dcb79c2STobias Lorenz unsigned int buf_size; 1589dcb79c2STobias Lorenz unsigned int rd_index; 1599dcb79c2STobias Lorenz unsigned int wr_index; 160cc35bbddSJoonyoung Shim 1610830be3fSJoonyoung Shim struct completion completion; 1620830be3fSJoonyoung Shim bool stci_enabled; /* Seek/Tune Complete Interrupt */ 1630830be3fSJoonyoung Shim 164cc35bbddSJoonyoung Shim #if defined(CONFIG_USB_SI470X) || defined(CONFIG_USB_SI470X_MODULE) 165b09cd163SJoonyoung Shim /* reference to USB and video device */ 166b09cd163SJoonyoung Shim struct usb_device *usbdev; 167b09cd163SJoonyoung Shim struct usb_interface *intf; 168b09cd163SJoonyoung Shim 169b09cd163SJoonyoung Shim /* Interrupt endpoint handling */ 170b09cd163SJoonyoung Shim char *int_in_buffer; 171b09cd163SJoonyoung Shim struct usb_endpoint_descriptor *int_in_endpoint; 172b09cd163SJoonyoung Shim struct urb *int_in_urb; 173b09cd163SJoonyoung Shim int int_in_running; 174b09cd163SJoonyoung Shim 175b09cd163SJoonyoung Shim /* scratch page */ 176b09cd163SJoonyoung Shim unsigned char software_version; 177b09cd163SJoonyoung Shim unsigned char hardware_version; 178b09cd163SJoonyoung Shim 179b09cd163SJoonyoung Shim /* driver management */ 180b09cd163SJoonyoung Shim unsigned char disconnected; 181cc35bbddSJoonyoung Shim #endif 182b09cd163SJoonyoung Shim 1839dcb79c2STobias Lorenz #if defined(CONFIG_I2C_SI470X) || defined(CONFIG_I2C_SI470X_MODULE) 1849dcb79c2STobias Lorenz struct i2c_client *client; 185fe2137ddSJoonyoung Shim struct work_struct radio_work; 1869dcb79c2STobias Lorenz #endif 187b09cd163SJoonyoung Shim }; 188b09cd163SJoonyoung Shim 189b09cd163SJoonyoung Shim 1909dcb79c2STobias Lorenz 1919dcb79c2STobias Lorenz /************************************************************************** 1929dcb79c2STobias Lorenz * Firmware Versions 1939dcb79c2STobias Lorenz **************************************************************************/ 1949dcb79c2STobias Lorenz 1959dcb79c2STobias Lorenz #define RADIO_FW_VERSION 15 1969dcb79c2STobias Lorenz 1979dcb79c2STobias Lorenz 1989dcb79c2STobias Lorenz 1999dcb79c2STobias Lorenz /************************************************************************** 2009dcb79c2STobias Lorenz * Frequency Multiplicator 2019dcb79c2STobias Lorenz **************************************************************************/ 2029dcb79c2STobias Lorenz 203b09cd163SJoonyoung Shim /* 204b09cd163SJoonyoung Shim * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW, 205b09cd163SJoonyoung Shim * 62.5 kHz otherwise. 206b09cd163SJoonyoung Shim * The tuner is able to have a channel spacing of 50, 100 or 200 kHz. 207b09cd163SJoonyoung Shim * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW 208b09cd163SJoonyoung Shim * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000 209b09cd163SJoonyoung Shim */ 210b09cd163SJoonyoung Shim #define FREQ_MUL (1000000 / 62.5) 211b09cd163SJoonyoung Shim 212b09cd163SJoonyoung Shim 213b09cd163SJoonyoung Shim 214b09cd163SJoonyoung Shim /************************************************************************** 215b09cd163SJoonyoung Shim * Common Functions 216b09cd163SJoonyoung Shim **************************************************************************/ 217b09cd163SJoonyoung Shim extern struct video_device si470x_viddev_template; 218b09cd163SJoonyoung Shim int si470x_get_register(struct si470x_device *radio, int regnr); 219b09cd163SJoonyoung Shim int si470x_set_register(struct si470x_device *radio, int regnr); 2203c7cc8d5SJoonyoung Shim int si470x_disconnect_check(struct si470x_device *radio); 221b09cd163SJoonyoung Shim int si470x_set_freq(struct si470x_device *radio, unsigned int freq); 222b09cd163SJoonyoung Shim int si470x_start(struct si470x_device *radio); 223b09cd163SJoonyoung Shim int si470x_stop(struct si470x_device *radio); 2241aa925c9SJoonyoung Shim int si470x_fops_open(struct file *file); 2251aa925c9SJoonyoung Shim int si470x_fops_release(struct file *file); 226b09cd163SJoonyoung Shim int si470x_vidioc_querycap(struct file *file, void *priv, 227b09cd163SJoonyoung Shim struct v4l2_capability *capability); 228