radio-rtc6226.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /* drivers/media/radio/rtc6226/radio-rtc6226.h
  2. *
  3. * Driver for Richwave RTC6226 FM Tuner
  4. *
  5. * Copyright (c) 2009 Tobias Lorenz <[email protected]>
  6. * Copyright (c) 2012 Hans de Goede <[email protected]>
  7. * Copyright (c) 2018 LG Electronics, Inc.
  8. * Copyright (c) 2018 Richwave Technology Co.Ltd
  9. * Copyright (c) 2021 Qualcomm Innovation Center, Inc. All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. */
  24. /* driver definitions */
  25. /* #define _RDSDEBUG */
  26. #define DRIVER_NAME "rtc6226-fmtuner"
  27. /* 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 <linux/wait.h>
  38. #include <media/v4l2-common.h>
  39. #include <media/v4l2-ioctl.h>
  40. #include <media/v4l2-ctrls.h>
  41. #include <media/v4l2-event.h>
  42. #include <media/v4l2-device.h>
  43. #include <media/v4l2-dev.h>
  44. #include <asm/unaligned.h>
  45. #include <linux/interrupt.h>
  46. #include <linux/of_gpio.h>
  47. #include <linux/of_irq.h>
  48. #include <linux/kfifo.h>
  49. #include <asm/unaligned.h>
  50. #define RW_Kernel_ENG
  51. #define DEBUG
  52. #undef FMDBG
  53. #define FMDBG(fmt, args...) pr_debug("rtc6226: " fmt, ##args)
  54. #undef FMDERR
  55. #define FMDERR(fmt, args...) pr_err("rtc6226: " fmt, ##args)
  56. /* driver definitions */
  57. #define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 1)
  58. #define DRIVER_CARD "Richwave rtc6226 FM Tuner"
  59. #define DRIVER_DESC "I2C radio driver for rtc6226 FM Tuner"
  60. #define DRIVER_VERSION "0.1.0"
  61. /**************************************************************************
  62. * Register Definitions
  63. **************************************************************************/
  64. #define RADIO_REGISTER_SIZE 2 /* 16 register bit width */
  65. #define RADIO_REGISTER_NUM 32 /* DEVICEID */
  66. #define RDS_REGISTER_NUM 6 /* STATUSRSSI */
  67. #define DEVICEID 0 /* Device ID Code */
  68. #define DEVICE_ID 0xffff /* [15:00] Device ID */
  69. #define DEVICEID_PN 0xf000 /* [15:12] Part Number */
  70. #define DEVICEID_MFGID 0x0fff /* [11:00] Manufacturer ID */
  71. #define CHIPID 1 /* Chip ID Code */
  72. #define CHIPID_REVISION_NO 0xfc00 /* [15:10] Chip Reversion */
  73. #define MPXCFG 2 /* Power Configuration */
  74. #define MPXCFG_CSR0_DIS_SMUTE 0x8000 /* [15:15] Disable Softmute */
  75. #define MPXCFG_CSR0_DIS_MUTE 0x4000 /* [14:14] Disable Mute */
  76. #define MPXCFG_CSR0_MONO 0x2000 /* [13:13] Mono or Auto Detect */
  77. #define MPXCFG_CSR0_DEEM 0x1000 /* [12:12] DE-emphasis */
  78. #define MPXCFG_CSR0_VOLUME_EXT 0x0400 /* [10:10] Volume Extend */
  79. #define MPXCFG_CSR0_BLNDADJUST 0x0300 /* [09:08] Blending Adjust */
  80. #define MPXCFG_CSR0_SMUTERATE 0x00c0 /* [07:06] Softmute Rate */
  81. #define MPXCFG_CSR0_SMUTEATT 0x0030 /* [05:04] Softmute Attenuation */
  82. #define MPXCFG_CSR0_VOLUME 0x000f /* [03:00] Volume */
  83. #define CHANNEL 3 /* Tuning Channel Setting */
  84. #define CHANNEL_CSR0_TUNE 0x8000 /* [15:15] Tune */
  85. #define CHANNEL_CSR0_CH 0x7fff /* [14:00] Tuning Channel */
  86. #define SYSCFG 4 /* System Configuration 1 */
  87. #define SYSCFG_CSR0_RDSIRQEN 0x8000 /* [15:15] RDS Interrupt Enable */
  88. #define SYSCFG_CSR0_STDIRQEN 0x4000 /* [14:14] STD Interrupt Enable */
  89. #define SYSCFG_CSR0_DIS_AGC 0x2000 /* [13:13] Disable AGC */
  90. #define SYSCFG_CSR0_RDS_EN 0x1000 /* [12:12] RDS Enable */
  91. #define SYSCFG_CSR0_RBDS_M 0x0300 /* [09:08] MMBS setting */
  92. #define SEEKCFG1 5 /* Seek Configuration 1 */
  93. #define SEEKCFG1_CSR0_SEEK 0x8000 /* [15:15] Enable Seek Function */
  94. #define SEEKCFG1_CSR0_SEEKUP 0x4000 /* [14:14] Seek Direction */
  95. #define SEEKCFG1_CSR0_SKMODE 0x2000 /* [13:13] Seek Mode */
  96. #define SEEKCFG1_CSR0_RSSI_LOW_TH 0x0f00 /* [11:08] RSSI Seek Threshold */
  97. #define SEEKCFG1_CSR0_RSSI_MONO_TH 0x000f /* [03:00] RSSI Seek Threshold */
  98. #define POWERCFG 6 /* Power Configuration */
  99. #define POWERCFG_CSR0_ENABLE 0x8000 /* [15:15] Power-up Enable */
  100. #define POWERCFG_CSR0_DISABLE 0x4000 /* [14:14] Power-up Disable */
  101. #define POWERCFG_CSR0_BLNDOFS 0x0f00 /* [11:08] Blending Offset Value */
  102. #define PADCFG 7 /* PAD Configuration */
  103. #define PADCFG_CSR0_GPIO 0x0004 /* [03:02] General purpose I/O */
  104. #define BANKCFG 8 /* Bank Serlection */
  105. #define SEEKCFG2 9 /* Seek Configuration 2 */
  106. #define STATUS 10 /* Status and Work channel */
  107. #define STATUS_RDS_RDY 0x8000 /* [15:15] RDS Ready */
  108. #define STATUS_STD 0x4000 /* [14:14] Seek/Tune Done */
  109. #define STATUS_SF 0x2000 /* [13:13] Seek Fail */
  110. #define STATUS_RDS_SYNC 0x0800 /* [11:11] RDS synchronization */
  111. #define STATUS_SI 0x0400 /* [10:10] Stereo Indicator */
  112. #define RSSI 11 /* RSSI and RDS error */
  113. #define RSSI_RDS_BA_ERRS 0xc000 /* [15:14] RDS Block A Errors */
  114. #define RSSI_RDS_BB_ERRS 0x3000 /* [15:14] RDS Block B Errors */
  115. #define RSSI_RDS_BC_ERRS 0x0c00 /* [13:12] RDS Block C Errors */
  116. #define RSSI_RDS_BD_ERRS 0x0300 /* [11:10] RDS Block D Errors */
  117. #define RSSI_RSSI 0x00ff /* [09:00] Read Channel */
  118. #define BA_DATA 12 /* Block A data */
  119. #define RDSA_RDSA 0xffff /* [15:00] RDS Block A Data */
  120. #define BB_DATA 13 /* Block B data */
  121. #define RDSB_RDSB 0xffff /* [15:00] RDS Block B Data */
  122. #define BC_DATA 14 /* Block C data */
  123. #define RDSC_RDSC 0xffff /* [15:00] RDS Block C Data */
  124. #define BD_DATA 15 /* Block D data */
  125. #define RDSD_RDSD 0xffff /* [15:00] RDS Block D Data */
  126. #define AUDIOCFG 0x12
  127. #define AUDIOCFG_CSR0_VOL_AUTOFIX 0x0800 //[11:11] LSB Volume Bit Auto Fix(1)
  128. #define RADIOCFG 0x13
  129. #define CHANNEL_CSR0_CHSPACE 0x1f00 /* [12:08] Channel Sapcing */
  130. #define RADIOSEEKCFG1 0x14
  131. /* [14:00] FM Seek Top CH, Unit 10KHz */
  132. #define CHANNEL_CSR0_FREQ_TOP 0x7fff
  133. #define RADIOSEEKCFG2 0x15
  134. /*[14:00] FM Seek Bottom CH, Unit 10KHz */
  135. #define CHANNEL_CSR0_FREQ_BOT 0x7fff
  136. #define I2SCFG 0x1c
  137. /* [13:13] I2S DSP Mode(0:Normal, 1:Special) */
  138. #define I2S_DSP_SEL 0x2000
  139. /* [12:12] BCLK Polarity(0:Falling, 1:Rising) */
  140. #define I2S_BCLK_POL 0x1000
  141. /* [11:10] Word Bits Select(0:8b, 1:16b, 2:20b, 3:24b) */
  142. #define I2S_WD_SEL 0x0c00
  143. /* [09:08] Right CH Control(0:On, 1:Off, 1x:Auto) */
  144. #define I2S_RCH_SEL 0x0300
  145. /* [07:07] I2S Enable */
  146. #define I2S_EN 0x0080 /* [07:07] I2S Enable */
  147. #define I2S_MSEL 0x0040 /* [06:06] I2S Master */
  148. /* [05:04] I2S Output Mode(0:I2S, 1:LJ, 2:DSPA, 3:DSPB) */
  149. #define I2S_MODE 0x0030
  150. /* [03:02] I2S Sample Rate(0:32K, 1:44.1K, 2:48K) */
  151. #define I2S_FS_AUD_SEL 0x000c
  152. /* [05:04] I2S BCLK Ratio(0:M32, 1:M64, 2:M128, 3:M256) */
  153. #define I2S_BCLK_AUD_SEL 0x0030
  154. #define CHANNEL1 0x1e
  155. #define STATUS_READCH 0x7fff /* [14:00] Read Channel */
  156. #define TURN_ON 1
  157. #define TURN_OFF 0
  158. #define SRCH_UP 1
  159. #define SRCH_DOWN 0
  160. #define WRAP_ENABLE 1
  161. #define WRAP_DISABLE 0
  162. #define DEFAULT_RSSI_TH 8
  163. /* Standard buffer size */
  164. #define STD_BUF_SIZE 256
  165. /* to distinguish between seek, tune during STC int. */
  166. #define NO_SEEK_TUNE_PENDING 0
  167. #define TUNE_PENDING 1
  168. #define SEEK_PENDING 2
  169. #define SCAN_PENDING 3
  170. #define START_SCAN 1
  171. #define TUNE_TIMEOUT_MSEC 3000
  172. #define SEEK_TIMEOUT_MSEC 15000
  173. #define RTC6226_MIN_SRCH_MODE 0x00
  174. #define RTC6226_MAX_SRCH_MODE 0x02
  175. #define MIN_DWELL_TIME 0x00
  176. #define MAX_DWELL_TIME 0x0F
  177. #define TUNE_STEP_SIZE 10
  178. #define NO_OF_RDS_BLKS 4
  179. #define GET_MSB(x)((x >> 8) & 0xFF)
  180. #define GET_LSB(x)((x) & 0xFF)
  181. #define OFFSET_OF_GRP_TYP 11
  182. #define RDS_INT_BIT 0x01
  183. #define FIFO_CNT_16 0x10
  184. #define UNCORRECTABLE_RDS_EN 0xFF01
  185. /* Write starts with the upper byte of register 0x02 */
  186. #define WRITE_REG_NUM 3
  187. #define WRITE_INDEX(i) ((i + 0x02)%16)
  188. /* Read starts with the upper byte of register 0x0a */
  189. #define READ_REG_NUM 2
  190. #define READ_INDEX(i) ((i + RADIO_REGISTER_NUM - 0x0a) % READ_REG_NUM)
  191. #define MSB_OF_BLK_0 4
  192. #define LSB_OF_BLK_0 5
  193. #define MSB_OF_BLK_1 6
  194. #define LSB_OF_BLK_1 7
  195. #define MSB_OF_BLK_2 8
  196. #define LSB_OF_BLK_2 9
  197. #define MSB_OF_BLK_3 10
  198. #define LSB_OF_BLK_3 11
  199. #define MAX_RT_LEN 64
  200. #define END_OF_RT 0x0d
  201. #define MAX_PS_LEN 8
  202. #define OFFSET_OF_PS 5
  203. #define PS_VALIDATE_LIMIT 2
  204. #define RT_VALIDATE_LIMIT 2
  205. #define RDS_CMD_LEN 3
  206. #define RDS_RSP_LEN 13
  207. #define PS_EVT_DATA_LEN (MAX_PS_LEN + OFFSET_OF_PS)
  208. #define NO_OF_PS 1
  209. #define OFFSET_OF_RT 5
  210. #define OFFSET_OF_PTY 5
  211. #define MAX_LEN_2B_GRP_RT 32
  212. #define CNT_FOR_2A_GRP_RT 4
  213. #define CNT_FOR_2B_GRP_RT 2
  214. #define PS_MASK 0x3
  215. #define PTY_MASK 0x1F
  216. #define NO_OF_CHARS_IN_EACH_ADD 2
  217. #define CORRECTED_NONE 0
  218. #define CORRECTED_ONE_TO_TWO 1
  219. #define CORRECTED_THREE_TO_FIVE 2
  220. #define ERRORS_CORRECTED(data, block) ((data>>block)&0x03)
  221. /*Block Errors are reported in .5% increments*/
  222. #define BLER_SCALE_MAX 200
  223. /* freqs are divided by 10. */
  224. #define SCALE_AF_CODE_TO_FREQ_KHZ(x) (87500 + (x*100))
  225. #define RDS_TYPE_0A (0 * 2 + 0)
  226. #define RDS_TYPE_0B (0 * 2 + 1)
  227. #define RDS_TYPE_2A (2 * 2 + 0)
  228. #define RDS_TYPE_2B (2 * 2 + 1)
  229. #define RDS_TYPE_3A (3 * 2 + 0)
  230. #define UNCORRECTABLE 3
  231. #define APP_GRP_typ_MASK 0x1F
  232. /*ERT*/
  233. #define ERT_AID 0x6552
  234. #define MAX_ERT_SEGMENT 31
  235. #define MAX_ERT_LEN 256
  236. #define ERT_OFFSET 3
  237. #define ERT_FORMAT_DIR_BIT 1
  238. #define ERT_CNT_PER_BLK 2
  239. /*RT PLUS*/
  240. #define DUMMY_CLASS 0
  241. #define RT_PLUS_LEN_1_TAG 3
  242. #define RT_ERT_FLAG_BIT 13
  243. #define RT_PLUS_AID 0x4bd7
  244. #define RT_ERT_FLAG_OFFSET 1
  245. #define RT_PLUS_OFFSET 2
  246. /*TAG1*/
  247. #define TAG1_MSB_OFFSET 3
  248. #define TAG1_MSB_MASK 7
  249. #define TAG1_LSB_OFFSET 13
  250. #define TAG1_POS_MSB_MASK 0x3F
  251. #define TAG1_POS_MSB_OFFSET 1
  252. #define TAG1_POS_LSB_OFFSET 7
  253. #define TAG1_LEN_OFFSET 1
  254. #define TAG1_LEN_MASK 0x3F
  255. /*TAG2*/
  256. #define TAG2_MSB_OFFSET 5
  257. #define TAG2_MSB_MASK 9
  258. #define TAG2_LSB_OFFSET 11
  259. #define TAG2_POS_MSB_MASK 0x3F
  260. #define TAG2_POS_MSB_OFFSET 3
  261. #define TAG2_POS_LSB_OFFSET 5
  262. #define TAG2_LEN_MASK 0x1F
  263. #define DEFAULT_AF_RSSI_LOW_TH 25
  264. #define NO_OF_AF_IN_GRP 2
  265. #define MAX_NO_OF_AF 25
  266. #define MAX_AF_LIST_SIZE (MAX_NO_OF_AF * 4) /* 4 bytes per freq */
  267. #define GET_AF_EVT_LEN(x) (7 + x*4)
  268. #define GET_AF_LIST_LEN(x) (x*4)
  269. #define MIN_AF_FREQ_CODE 1
  270. #define MAX_AF_FREQ_CODE 204
  271. #define MIN_RSSI 0
  272. #define MAX_RSSI 15
  273. /* 25 AFs supported for a freq. 224 means 1 AF. 225 means 2 AFs and so on */
  274. #define NO_AF_CNT_CODE 224
  275. #define MIN_AF_CNT_CODE 225
  276. #define MAX_AF_CNT_CODE 249
  277. #define AF_WAIT_SEC 10
  278. #define MAX_AF_WAIT_SEC 255
  279. #define AF_PI_WAIT_TIME 50 /* 50*100msec = 5sec */
  280. #define CH_SPACING_200 200
  281. #define CH_SPACING_100 100
  282. #define CH_SPACING_50 50
  283. #define TURNING_ON 1
  284. #define TURNING_OFF 0
  285. #define RW_PRIBASE (V4L2_CID_USER_BASE | 0xf000)
  286. /* freqs are divided by 10. */
  287. #define SCALE_AF_CODE_TO_FREQ_KHZ(x) (87500 + (x*100))
  288. #define EXTRACT_BIT(data, bit_pos) ((data >> bit_pos) & 1)
  289. #define V4L2_CID_PRIVATE_CSR0_ENABLE (RW_PRIBASE + (DEVICEID<<4) + 1)
  290. #define V4L2_CID_PRIVATE_CSR0_DISABLE (RW_PRIBASE + (DEVICEID<<4) + 2)
  291. #define V4L2_CID_PRIVATE_DEVICEID (RW_PRIBASE + (DEVICEID<<4) + 3)
  292. #define V4L2_CID_PRIVATE_CSR0_DIS_SMUTE (RW_PRIBASE + (DEVICEID<<4) + 4)
  293. #define V4L2_CID_PRIVATE_CSR0_DIS_MUTE (RW_PRIBASE + (DEVICEID<<4) + 5)
  294. #define V4L2_CID_PRIVATE_CSR0_DEEM (RW_PRIBASE + (DEVICEID<<4) + 6)
  295. #define V4L2_CID_PRIVATE_CSR0_BLNDADJUST (RW_PRIBASE + (DEVICEID<<4) + 7)
  296. #define V4L2_CID_PRIVATE_CSR0_VOLUME (RW_PRIBASE + (DEVICEID<<4) + 8)
  297. #define V4L2_CID_PRIVATE_CSR0_BAND (RW_PRIBASE + (DEVICEID<<4) + 9)
  298. #define V4L2_CID_PRIVATE_CSR0_CHSPACE (RW_PRIBASE + (DEVICEID<<4) + 10)
  299. #define V4L2_CID_PRIVATE_CSR0_DIS_AGC (RW_PRIBASE + (DEVICEID<<4) + 11)
  300. #define V4L2_CID_PRIVATE_CSR0_RDS_EN (RW_PRIBASE + (DEVICEID<<4) + 12)
  301. #define V4L2_CID_PRIVATE_SEEK_CANCEL (RW_PRIBASE + (DEVICEID<<4) + 13)
  302. #define V4L2_CID_PRIVATE_CSR0_SEEKRSSITH (RW_PRIBASE + (DEVICEID<<4) + 14)
  303. #define V4L2_CID_PRIVATE_RSSI (RW_PRIBASE + (CHIPID<<4) + 1)
  304. #define V4L2_CID_PRIVATE_RDS_RDY (RW_PRIBASE + (CHIPID<<4) + 2)
  305. #define V4L2_CID_PRIVATE_STD (RW_PRIBASE + (CHIPID<<4) + 3)
  306. #define V4L2_CID_PRIVATE_SF (RW_PRIBASE + (CHIPID<<4) + 4)
  307. #define V4L2_CID_PRIVATE_RDS_SYNC (RW_PRIBASE + (CHIPID<<4) + 5)
  308. #define V4L2_CID_PRIVATE_SI (RW_PRIBASE + (CHIPID<<4) + 6)
  309. #define NO_WAIT 2
  310. #define RDS_WAITING 5
  311. #define SEEK_CANCEL 6
  312. #define TUNE_PARAM 16
  313. /**************************************************************************
  314. * General Driver Definitions
  315. **************************************************************************/
  316. enum rtc6226_buf_t {
  317. RTC6226_FM_BUF_SRCH_LIST,
  318. RTC6226_FM_BUF_EVENTS,
  319. RTC6226_FM_BUF_RT_RDS,
  320. RTC6226_FM_BUF_PS_RDS,
  321. RTC6226_FM_BUF_RAW_RDS,
  322. RTC6226_FM_BUF_AF_LIST,
  323. RTC6226_FM_BUF_RT_PLUS = 11,
  324. RTC6226_FM_BUF_ERT,
  325. RTC6226_FM_BUF_MAX
  326. };
  327. enum rtc6226_evt_t {
  328. RTC6226_EVT_RADIO_READY,
  329. RTC6226_EVT_TUNE_SUCC,
  330. RTC6226_EVT_SEEK_COMPLETE,
  331. RTC6226_EVT_SCAN_NEXT,
  332. RTC6226_EVT_NEW_RAW_RDS,
  333. RTC6226_EVT_NEW_RT_RDS,
  334. RTC6226_EVT_NEW_PS_RDS,
  335. RTC6226_EVT_ERROR,
  336. RTC6226_EVT_BELOW_TH,
  337. RTC6226_EVT_ABOVE_TH,
  338. RTC6226_EVT_STEREO,
  339. RTC6226_EVT_MONO,
  340. RTC6226_EVT_RDS_AVAIL,
  341. RTC6226_EVT_RDS_NOT_AVAIL,
  342. RTC6226_EVT_NEW_SRCH_LIST,
  343. RTC6226_EVT_NEW_AF_LIST,
  344. RTC6226_EVT_TXRDSDAT,
  345. RTC6226_EVT_TXRDSDONE,
  346. RTC6226_EVT_RADIO_DISABLED,
  347. RTC6226_EVT_NEW_ODA,
  348. RTC6226_EVT_NEW_RT_PLUS,
  349. RTC6226_EVT_NEW_ERT
  350. };
  351. struct rtc6226_recv_conf_req {
  352. __u16 emphasis;
  353. __u16 ch_spacing;
  354. /* limits stored as actual freq / TUNE_STEP_SIZE */
  355. __u16 band_low_limit;
  356. __u16 band_high_limit;
  357. };
  358. struct rtc6226_rel_freq {
  359. __u8 rel_freq_msb;
  360. __u8 rel_freq_lsb;
  361. } __packed;
  362. struct rtc6226_srch_list_compl {
  363. __u8 num_stations_found;
  364. struct rtc6226_rel_freq rel_freq[20];
  365. } __packed;
  366. struct af_list_ev {
  367. __le32 tune_freq_khz;
  368. __le16 pi_code;
  369. __u8 af_size;
  370. __u8 af_list[MAX_AF_LIST_SIZE];
  371. } __packed;
  372. struct rtc6226_af_info {
  373. /* no. of invalid AFs. */
  374. u8 inval_freq_cnt;
  375. /* no. of AFs in the list. */
  376. u8 cnt;
  377. /* actual size of the list */
  378. u8 size;
  379. /* index of currently tuned station in the AF list. */
  380. u8 index;
  381. /* PI of the frequency */
  382. u16 pi;
  383. /* freq to which AF list belongs to. */
  384. u32 orig_freq_khz;
  385. /* AF list */
  386. u32 af_list[MAX_NO_OF_AF];
  387. };
  388. struct fm_power_vreg_data {
  389. /* voltage regulator handle */
  390. struct regulator *reg;
  391. /* regulator name */
  392. const char *name;
  393. /* voltage levels to be set */
  394. unsigned int low_vol_level;
  395. unsigned int high_vol_level;
  396. int vdd_load;
  397. /* is this regulator enabled? */
  398. bool is_enabled;
  399. };
  400. /*
  401. * rtc6226_device - private data
  402. */
  403. struct rtc6226_device {
  404. int int_gpio;
  405. int fm_sw_gpio;
  406. int ext_ldo_gpio;
  407. int reset_gpio;
  408. struct regulator *vdd_reg;
  409. struct v4l2_device v4l2_dev;
  410. struct video_device videodev;
  411. struct pinctrl *fm_pinctrl;
  412. struct pinctrl_state *gpio_state_active;
  413. struct pinctrl_state *gpio_state_suspend;
  414. struct v4l2_ctrl_handler ctrl_handler;
  415. struct fm_power_vreg_data *vddreg;
  416. struct fm_power_vreg_data *vioreg;
  417. int band;
  418. int space;
  419. atomic_t users;
  420. unsigned int mode;
  421. u8 seek_tune_status;
  422. u8 rssi_th;
  423. /* Richwave internal registers (0..15) */
  424. unsigned short registers[RADIO_REGISTER_NUM];
  425. /* RDS receive buffer */
  426. wait_queue_head_t read_queue;
  427. int irq;
  428. int tuned_freq_khz;
  429. int dwell_time_sec;
  430. struct mutex lock; /* buffer locking */
  431. unsigned char *buffer; /* size is always multiple of three */
  432. bool is_search_cancelled;
  433. u8 g_search_mode;
  434. struct rtc6226_srch_list_compl srch_list;
  435. /* buffer locks*/
  436. spinlock_t buf_lock[RTC6226_FM_BUF_MAX];
  437. struct rtc6226_recv_conf_req recv_conf;
  438. struct workqueue_struct *wqueue;
  439. struct workqueue_struct *wqueue_scan;
  440. struct workqueue_struct *wqueue_rds;
  441. struct work_struct rds_worker;
  442. struct rtc6226_af_info af_info1;
  443. struct rtc6226_af_info af_info2;
  444. struct delayed_work work;
  445. struct delayed_work work_scan;
  446. wait_queue_head_t event_queue;
  447. u8 write_buf[WRITE_REG_NUM];
  448. /* TO read events, data*/
  449. u8 read_buf[READ_REG_NUM];
  450. u16 pi; /* PI of tuned channel */
  451. u8 pty; /* programe type of the tuned channel */
  452. u16 block[NO_OF_RDS_BLKS];
  453. u8 rt_display[MAX_RT_LEN]; /* RT that will be displayed */
  454. u8 rt_tmp0[MAX_RT_LEN]; /* high probability RT */
  455. u8 rt_tmp1[MAX_RT_LEN]; /* low probability RT */
  456. u8 rt_cnt[MAX_RT_LEN]; /* high probability RT's hit count */
  457. u8 rt_flag; /* A/B flag of RT */
  458. bool valid_rt_flg; /* validity of A/B flag */
  459. u8 ps_display[MAX_PS_LEN]; /* PS that will be displayed */
  460. u8 ps_tmp0[MAX_PS_LEN]; /* high probability PS */
  461. u8 ps_tmp1[MAX_PS_LEN]; /* low probability PS */
  462. u8 ps_cnt[MAX_PS_LEN]; /* high probability PS's hit count */
  463. u8 bler[NO_OF_RDS_BLKS];
  464. u8 rt_plus_carrier;
  465. u8 ert_carrier;
  466. u8 ert_buf[MAX_ERT_LEN];
  467. u8 ert_len;
  468. u8 c_byt_pair_index;
  469. u8 utf_8_flag;
  470. u8 rt_ert_flag;
  471. u8 formatting_dir;
  472. unsigned int buf_size;
  473. unsigned int rd_index;
  474. unsigned int wr_index;
  475. struct kfifo data_buf[RTC6226_FM_BUF_MAX];
  476. struct completion completion;
  477. bool stci_enabled; /* Seek/Tune Complete Interrupt */
  478. struct i2c_client *client;
  479. unsigned int tuner_state;
  480. int lna_en;
  481. int lna_gain;
  482. };
  483. enum radio_state_t {
  484. FM_OFF,
  485. FM_RECV,
  486. FM_RESET,
  487. FM_CALIB,
  488. FM_TURNING_OFF,
  489. FM_RECV_TURNING_ON,
  490. FM_MAX_NO_STATES,
  491. };
  492. enum search_t {
  493. SEEK,
  494. SCAN,
  495. SCAN_FOR_STRONG,
  496. };
  497. /**************************************************************************
  498. * Frequency Multiplicator
  499. **************************************************************************/
  500. #define FREQ_MUL 1000
  501. #define CONFIG_RDS
  502. enum v4l2_cid_private_rtc6226_t {
  503. V4L2_CID_PRIVATE_RTC6226_SRCHMODE = (V4L2_CID_PRIVATE_BASE + 1),
  504. V4L2_CID_PRIVATE_RTC6226_SCANDWELL,
  505. V4L2_CID_PRIVATE_RTC6226_SRCHON,
  506. V4L2_CID_PRIVATE_RTC6226_STATE,
  507. V4L2_CID_PRIVATE_RTC6226_TRANSMIT_MODE,
  508. V4L2_CID_PRIVATE_RTC6226_RDSGROUP_MASK,
  509. V4L2_CID_PRIVATE_RTC6226_REGION,
  510. V4L2_CID_PRIVATE_RTC6226_SIGNAL_TH,
  511. V4L2_CID_PRIVATE_RTC6226_SRCH_PTY,
  512. V4L2_CID_PRIVATE_RTC6226_SRCH_PI,
  513. V4L2_CID_PRIVATE_RTC6226_SRCH_CNT,
  514. V4L2_CID_PRIVATE_RTC6226_EMPHASIS, /* 800000c */
  515. V4L2_CID_PRIVATE_RTC6226_RDS_STD,
  516. V4L2_CID_PRIVATE_RTC6226_SPACING,
  517. V4L2_CID_PRIVATE_RTC6226_RDSON,
  518. V4L2_CID_PRIVATE_RTC6226_RDSGROUP_PROC,
  519. V4L2_CID_PRIVATE_RTC6226_LP_MODE,
  520. V4L2_CID_PRIVATE_RTC6226_ANTENNA,
  521. V4L2_CID_PRIVATE_RTC6226_RDSD_BUF,
  522. V4L2_CID_PRIVATE_RTC6226_PSALL,
  523. /*v4l2 Tx controls*/
  524. V4L2_CID_PRIVATE_RTC6226_TX_SETPSREPEATCOUNT,
  525. V4L2_CID_PRIVATE_RTC6226_STOP_RDS_TX_PS_NAME,
  526. V4L2_CID_PRIVATE_RTC6226_STOP_RDS_TX_RT,
  527. V4L2_CID_PRIVATE_RTC6226_IOVERC,
  528. V4L2_CID_PRIVATE_RTC6226_INTDET,
  529. V4L2_CID_PRIVATE_RTC6226_MPX_DCC,
  530. V4L2_CID_PRIVATE_RTC6226_AF_JUMP,
  531. V4L2_CID_PRIVATE_RTC6226_RSSI_DELTA,
  532. V4L2_CID_PRIVATE_RTC6226_HLSI,
  533. /*
  534. * Here we have IOCTl's that are specific to IRIS
  535. * (V4L2_CID_PRIVATE_BASE + 0x1E to V4L2_CID_PRIVATE_BASE + 0x28)
  536. */
  537. V4L2_CID_PRIVATE_RTC6226_SOFT_MUTE,/* 0x800001E*/
  538. V4L2_CID_PRIVATE_RTC6226_RIVA_ACCS_ADDR,
  539. V4L2_CID_PRIVATE_RTC6226_RIVA_ACCS_LEN,
  540. V4L2_CID_PRIVATE_RTC6226_RIVA_PEEK,
  541. V4L2_CID_PRIVATE_RTC6226_RIVA_POKE,
  542. V4L2_CID_PRIVATE_RTC6226_SSBI_ACCS_ADDR,
  543. V4L2_CID_PRIVATE_RTC6226_SSBI_PEEK,
  544. V4L2_CID_PRIVATE_RTC6226_SSBI_POKE,
  545. V4L2_CID_PRIVATE_RTC6226_TX_TONE,
  546. V4L2_CID_PRIVATE_RTC6226_RDS_GRP_COUNTERS,
  547. V4L2_CID_PRIVATE_RTC6226_SET_NOTCH_FILTER, /* 0x8000028 */
  548. V4L2_CID_PRIVATE_RTC6226_SET_AUDIO_PATH, /* 0x8000029 */
  549. V4L2_CID_PRIVATE_RTC6226_DO_CALIBRATION, /* 0x800002A : IRIS */
  550. V4L2_CID_PRIVATE_RTC6226_SRCH_ALGORITHM, /* 0x800002B */
  551. V4L2_CID_PRIVATE_RTC6226_GET_SINR, /* 0x800002C : IRIS */
  552. V4L2_CID_PRIVATE_RTC6226_INTF_LOW_THRESHOLD, /* 0x800002D */
  553. V4L2_CID_PRIVATE_RTC6226_INTF_HIGH_THRESHOLD, /* 0x800002E */
  554. /* 0x800002F : IRIS, For Richwave Spike TH */
  555. V4L2_CID_PRIVATE_RTC6226_SINR_THRESHOLD,
  556. /* V4L2_CID_PRIVATE_RTC6226_QLT_THRESHOLD,
  557. */ /* 0x800002F : IRIS, For Richwave Spike TH
  558. */
  559. V4L2_CID_PRIVATE_RTC6226_SINR_SAMPLES, /* 0x8000030 : IRIS */
  560. V4L2_CID_PRIVATE_RTC6226_SPUR_FREQ,
  561. V4L2_CID_PRIVATE_RTC6226_SPUR_FREQ_RMSSI, /* For Richwave DC TH */
  562. /* V4L2_CID_PRIVATE_RTC6226_OFS_THRESHOLD, */ /* For Richwave DC TH */
  563. V4L2_CID_PRIVATE_RTC6226_SPUR_SELECTION,
  564. V4L2_CID_PRIVATE_RTC6226_UPDATE_SPUR_TABLE,
  565. V4L2_CID_PRIVATE_RTC6226_VALID_CHANNEL,
  566. V4L2_CID_PRIVATE_RTC6226_AF_RMSSI_TH,
  567. V4L2_CID_PRIVATE_RTC6226_AF_RMSSI_SAMPLES,
  568. V4L2_CID_PRIVATE_RTC6226_GOOD_CH_RMSSI_TH,
  569. V4L2_CID_PRIVATE_RTC6226_SRCHALGOTYPE,
  570. V4L2_CID_PRIVATE_RTC6226_CF0TH12,
  571. V4L2_CID_PRIVATE_RTC6226_SINRFIRSTSTAGE,
  572. V4L2_CID_PRIVATE_RTC6226_RMSSIFIRSTSTAGE,
  573. V4L2_CID_PRIVATE_RTC6226_RXREPEATCOUNT,
  574. V4L2_CID_PRIVATE_RTC6226_RSSI_TH, /* 0x800003E */
  575. V4L2_CID_PRIVATE_RTC6226_AF_JUMP_RSSI_TH /* 0x800003F */
  576. };
  577. enum FMBAND {FMBAND_87_108_MHZ, FMBAND_76_108_MHZ, FMBAND_76_91_MHZ,
  578. FMBAND_64_76_MHZ};
  579. enum FMSPACE {FMSPACE_200_KHZ, FMSPACE_100_KHZ, FMSPACE_50_KHZ};
  580. /**************************************************************************
  581. * Common Functions
  582. **************************************************************************/
  583. extern struct i2c_driver rtc6226_i2c_driver;
  584. extern struct video_device rtc6226_viddev_template;
  585. extern const struct v4l2_ioctl_ops rtc6226_ioctl_ops;
  586. extern const struct v4l2_ctrl_ops rtc6226_ctrl_ops;
  587. extern struct tasklet_struct my_tasklet;
  588. extern int rtc6226_wq_flag;
  589. extern wait_queue_head_t rtc6226_wq;
  590. extern int rtc6226_get_all_registers(struct rtc6226_device *radio);
  591. extern int rtc6226_get_register(struct rtc6226_device *radio, int regnr);
  592. extern int rtc6226_set_register(struct rtc6226_device *radio, int regnr);
  593. extern int rtc6226_set_serial_registers(struct rtc6226_device *radio,
  594. u16 *data, int bytes);
  595. int rtc6226_i2c_init(void);
  596. int rtc6226_reset_rds_data(struct rtc6226_device *radio);
  597. int rtc6226_set_freq(struct rtc6226_device *radio, unsigned int freq);
  598. int rtc6226_start(struct rtc6226_device *radio);
  599. int rtc6226_stop(struct rtc6226_device *radio);
  600. int rtc6226_fops_open(struct file *file);
  601. int rtc6226_power_up(struct rtc6226_device *radio);
  602. int rtc6226_power_down(struct rtc6226_device *radio);
  603. int rtc6226_fops_release(struct file *file);
  604. int rtc6226_vidioc_querycap(struct file *file, void *priv,
  605. struct v4l2_capability *capability);
  606. int rtc6226_enable_irq(struct rtc6226_device *radio);
  607. void rtc6226_disable_irq(struct rtc6226_device *radio);
  608. void rtc6226_scan(struct work_struct *work);
  609. void rtc6226_search(struct rtc6226_device *radio, bool on);
  610. int rtc6226_cancel_seek(struct rtc6226_device *radio);
  611. void rtc6226_rds_handler(struct work_struct *worker);
  612. void rtc6226_q_event(struct rtc6226_device *radio, enum rtc6226_evt_t event);
  613. int rtc6226_reset_rds_data(struct rtc6226_device *radio);
  614. int rtc6226_rds_on(struct rtc6226_device *radio);