Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /*
0003  *  drivers/media/radio/si470x/radio-si470x.h
0004  *
0005  *  Driver for radios with Silicon Labs Si470x FM Radio Receivers
0006  *
0007  *  Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net>
0008  */
0009 
0010 
0011 /* driver definitions */
0012 #define DRIVER_NAME "radio-si470x"
0013 
0014 
0015 /* kernel includes */
0016 #include <linux/kernel.h>
0017 #include <linux/module.h>
0018 #include <linux/init.h>
0019 #include <linux/sched.h>
0020 #include <linux/slab.h>
0021 #include <linux/input.h>
0022 #include <linux/videodev2.h>
0023 #include <linux/mutex.h>
0024 #include <media/v4l2-common.h>
0025 #include <media/v4l2-ioctl.h>
0026 #include <media/v4l2-ctrls.h>
0027 #include <media/v4l2-event.h>
0028 #include <media/v4l2-device.h>
0029 #include <asm/unaligned.h>
0030 
0031 
0032 
0033 /**************************************************************************
0034  * Register Definitions
0035  **************************************************************************/
0036 #define RADIO_REGISTER_SIZE 2   /* 16 register bit width */
0037 #define RADIO_REGISTER_NUM  16  /* DEVICEID   ... RDSD */
0038 #define RDS_REGISTER_NUM    6   /* STATUSRSSI ... RDSD */
0039 
0040 #define DEVICEID        0   /* Device ID */
0041 #define DEVICEID_PN     0xf000  /* bits 15..12: Part Number */
0042 #define DEVICEID_MFGID      0x0fff  /* bits 11..00: Manufacturer ID */
0043 
0044 #define SI_CHIPID       1   /* Chip ID */
0045 #define SI_CHIPID_REV       0xfc00  /* bits 15..10: Chip Version */
0046 #define SI_CHIPID_DEV       0x0200  /* bits 09..09: Device */
0047 #define SI_CHIPID_FIRMWARE  0x01ff  /* bits 08..00: Firmware Version */
0048 
0049 #define POWERCFG        2   /* Power Configuration */
0050 #define POWERCFG_DSMUTE     0x8000  /* bits 15..15: Softmute Disable */
0051 #define POWERCFG_DMUTE      0x4000  /* bits 14..14: Mute Disable */
0052 #define POWERCFG_MONO       0x2000  /* bits 13..13: Mono Select */
0053 #define POWERCFG_RDSM       0x0800  /* bits 11..11: RDS Mode (Si4701 only) */
0054 #define POWERCFG_SKMODE     0x0400  /* bits 10..10: Seek Mode */
0055 #define POWERCFG_SEEKUP     0x0200  /* bits 09..09: Seek Direction */
0056 #define POWERCFG_SEEK       0x0100  /* bits 08..08: Seek */
0057 #define POWERCFG_DISABLE    0x0040  /* bits 06..06: Powerup Disable */
0058 #define POWERCFG_ENABLE     0x0001  /* bits 00..00: Powerup Enable */
0059 
0060 #define CHANNEL         3   /* Channel */
0061 #define CHANNEL_TUNE        0x8000  /* bits 15..15: Tune */
0062 #define CHANNEL_CHAN        0x03ff  /* bits 09..00: Channel Select */
0063 
0064 #define SYSCONFIG1      4   /* System Configuration 1 */
0065 #define SYSCONFIG1_RDSIEN   0x8000  /* bits 15..15: RDS Interrupt Enable (Si4701 only) */
0066 #define SYSCONFIG1_STCIEN   0x4000  /* bits 14..14: Seek/Tune Complete Interrupt Enable */
0067 #define SYSCONFIG1_RDS      0x1000  /* bits 12..12: RDS Enable (Si4701 only) */
0068 #define SYSCONFIG1_DE       0x0800  /* bits 11..11: De-emphasis (0=75us 1=50us) */
0069 #define SYSCONFIG1_AGCD     0x0400  /* bits 10..10: AGC Disable */
0070 #define SYSCONFIG1_BLNDADJ  0x00c0  /* bits 07..06: Stereo/Mono Blend Level Adjustment */
0071 #define SYSCONFIG1_GPIO3    0x0030  /* bits 05..04: General Purpose I/O 3 */
0072 #define SYSCONFIG1_GPIO2    0x000c  /* bits 03..02: General Purpose I/O 2 */
0073 #define SYSCONFIG1_GPIO2_DIS    0x0000  /* Disable GPIO 2 interrupt */
0074 #define SYSCONFIG1_GPIO2_INT    0x0004  /* Enable STC/RDS interrupt */
0075 #define SYSCONFIG1_GPIO1    0x0003  /* bits 01..00: General Purpose I/O 1 */
0076 
0077 #define SYSCONFIG2      5   /* System Configuration 2 */
0078 #define SYSCONFIG2_SEEKTH   0xff00  /* bits 15..08: RSSI Seek Threshold */
0079 #define SYSCONFIG2_BAND     0x00c0  /* bits 07..06: Band Select */
0080 #define SYSCONFIG2_SPACE    0x0030  /* bits 05..04: Channel Spacing */
0081 #define SYSCONFIG2_VOLUME   0x000f  /* bits 03..00: Volume */
0082 
0083 #define SYSCONFIG3      6   /* System Configuration 3 */
0084 #define SYSCONFIG3_SMUTER   0xc000  /* bits 15..14: Softmute Attack/Recover Rate */
0085 #define SYSCONFIG3_SMUTEA   0x3000  /* bits 13..12: Softmute Attenuation */
0086 #define SYSCONFIG3_SKSNR    0x00f0  /* bits 07..04: Seek SNR Threshold */
0087 #define SYSCONFIG3_SKCNT    0x000f  /* bits 03..00: Seek FM Impulse Detection Threshold */
0088 
0089 #define TEST1           7   /* Test 1 */
0090 #define TEST1_AHIZEN        0x4000  /* bits 14..14: Audio High-Z Enable */
0091 
0092 #define TEST2           8   /* Test 2 */
0093 /* TEST2 only contains reserved bits */
0094 
0095 #define BOOTCONFIG      9   /* Boot Configuration */
0096 /* BOOTCONFIG only contains reserved bits */
0097 
0098 #define STATUSRSSI      10  /* Status RSSI */
0099 #define STATUSRSSI_RDSR     0x8000  /* bits 15..15: RDS Ready (Si4701 only) */
0100 #define STATUSRSSI_STC      0x4000  /* bits 14..14: Seek/Tune Complete */
0101 #define STATUSRSSI_SF       0x2000  /* bits 13..13: Seek Fail/Band Limit */
0102 #define STATUSRSSI_AFCRL    0x1000  /* bits 12..12: AFC Rail */
0103 #define STATUSRSSI_RDSS     0x0800  /* bits 11..11: RDS Synchronized (Si4701 only) */
0104 #define STATUSRSSI_BLERA    0x0600  /* bits 10..09: RDS Block A Errors (Si4701 only) */
0105 #define STATUSRSSI_ST       0x0100  /* bits 08..08: Stereo Indicator */
0106 #define STATUSRSSI_RSSI     0x00ff  /* bits 07..00: RSSI (Received Signal Strength Indicator) */
0107 
0108 #define READCHAN        11  /* Read Channel */
0109 #define READCHAN_BLERB      0xc000  /* bits 15..14: RDS Block D Errors (Si4701 only) */
0110 #define READCHAN_BLERC      0x3000  /* bits 13..12: RDS Block C Errors (Si4701 only) */
0111 #define READCHAN_BLERD      0x0c00  /* bits 11..10: RDS Block B Errors (Si4701 only) */
0112 #define READCHAN_READCHAN   0x03ff  /* bits 09..00: Read Channel */
0113 
0114 #define RDSA            12  /* RDSA */
0115 #define RDSA_RDSA       0xffff  /* bits 15..00: RDS Block A Data (Si4701 only) */
0116 
0117 #define RDSB            13  /* RDSB */
0118 #define RDSB_RDSB       0xffff  /* bits 15..00: RDS Block B Data (Si4701 only) */
0119 
0120 #define RDSC            14  /* RDSC */
0121 #define RDSC_RDSC       0xffff  /* bits 15..00: RDS Block C Data (Si4701 only) */
0122 
0123 #define RDSD            15  /* RDSD */
0124 #define RDSD_RDSD       0xffff  /* bits 15..00: RDS Block D Data (Si4701 only) */
0125 
0126 
0127 
0128 /**************************************************************************
0129  * General Driver Definitions
0130  **************************************************************************/
0131 
0132 /*
0133  * si470x_device - private data
0134  */
0135 struct si470x_device {
0136     struct v4l2_device v4l2_dev;
0137     struct video_device videodev;
0138     struct v4l2_ctrl_handler hdl;
0139     int band;
0140 
0141     /* Silabs internal registers (0..15) */
0142     unsigned short registers[RADIO_REGISTER_NUM];
0143 
0144     /* RDS receive buffer */
0145     wait_queue_head_t read_queue;
0146     struct mutex lock;      /* buffer locking */
0147     unsigned char *buffer;      /* size is always multiple of three */
0148     unsigned int buf_size;
0149     unsigned int rd_index;
0150     unsigned int wr_index;
0151 
0152     struct completion completion;
0153     bool status_rssi_auto_update;   /* Does RSSI get updated automatic? */
0154 
0155     /* si470x ops */
0156 
0157     int (*get_register)(struct si470x_device *radio, int regnr);
0158     int (*set_register)(struct si470x_device *radio, int regnr);
0159     int (*fops_open)(struct file *file);
0160     int (*fops_release)(struct file *file);
0161     int (*vidioc_querycap)(struct file *file, void *priv,
0162                    struct v4l2_capability *capability);
0163 
0164 #if IS_ENABLED(CONFIG_USB_SI470X)
0165     /* reference to USB and video device */
0166     struct usb_device *usbdev;
0167     struct usb_interface *intf;
0168     char *usb_buf;
0169 
0170     /* Interrupt endpoint handling */
0171     char *int_in_buffer;
0172     struct usb_endpoint_descriptor *int_in_endpoint;
0173     struct urb *int_in_urb;
0174     int int_in_running;
0175 
0176     /* scratch page */
0177     unsigned char software_version;
0178     unsigned char hardware_version;
0179 #endif
0180 
0181 #if IS_ENABLED(CONFIG_I2C_SI470X)
0182     struct i2c_client *client;
0183     struct gpio_desc *gpio_reset;
0184 #endif
0185 };
0186 
0187 
0188 
0189 /**************************************************************************
0190  * Firmware Versions
0191  **************************************************************************/
0192 
0193 #define RADIO_FW_VERSION    12
0194 
0195 
0196 
0197 /**************************************************************************
0198  * Frequency Multiplicator
0199  **************************************************************************/
0200 
0201 /*
0202  * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
0203  * 62.5 kHz otherwise.
0204  * The tuner is able to have a channel spacing of 50, 100 or 200 kHz.
0205  * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW
0206  * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000
0207  */
0208 #define FREQ_MUL (1000000 / 62.5)
0209 
0210 
0211 
0212 /**************************************************************************
0213  * Common Functions
0214  **************************************************************************/
0215 extern const struct video_device si470x_viddev_template;
0216 extern const struct v4l2_ctrl_ops si470x_ctrl_ops;
0217 int si470x_disconnect_check(struct si470x_device *radio);
0218 int si470x_set_freq(struct si470x_device *radio, unsigned int freq);
0219 int si470x_start(struct si470x_device *radio);
0220 int si470x_stop(struct si470x_device *radio);