radio-si470x.h 8.5 KB

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