1 /*
2  *  FM Driver for Connectivity chip of Texas Instruments.
3  *  FM Common module header file
4  *
5  *  Copyright (C) 2011 Texas Instruments
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License version 2 as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  */
17 
18 #ifndef _FMDRV_COMMON_H
19 #define _FMDRV_COMMON_H
20 
21 #define FM_ST_REG_TIMEOUT   msecs_to_jiffies(6000)	/* 6 sec */
22 #define FM_PKT_LOGICAL_CHAN_NUMBER  0x08   /* Logical channel 8 */
23 
24 #define REG_RD       0x1
25 #define REG_WR      0x0
26 
27 struct fm_reg_table {
28 	u8 opcode;
29 	u8 type;
30 	u8 *name;
31 };
32 
33 #define STEREO_GET               0
34 #define RSSI_LVL_GET             1
35 #define IF_COUNT_GET             2
36 #define FLAG_GET                 3
37 #define RDS_SYNC_GET             4
38 #define RDS_DATA_GET             5
39 #define FREQ_SET                 10
40 #define AF_FREQ_SET              11
41 #define MOST_MODE_SET            12
42 #define MOST_BLEND_SET           13
43 #define DEMPH_MODE_SET           14
44 #define SEARCH_LVL_SET           15
45 #define BAND_SET                 16
46 #define MUTE_STATUS_SET          17
47 #define RDS_PAUSE_LVL_SET        18
48 #define RDS_PAUSE_DUR_SET        19
49 #define RDS_MEM_SET              20
50 #define RDS_BLK_B_SET            21
51 #define RDS_MSK_B_SET            22
52 #define RDS_PI_MASK_SET          23
53 #define RDS_PI_SET               24
54 #define RDS_SYSTEM_SET           25
55 #define INT_MASK_SET             26
56 #define SEARCH_DIR_SET           27
57 #define VOLUME_SET               28
58 #define AUDIO_ENABLE_SET         29
59 #define PCM_MODE_SET             30
60 #define I2S_MODE_CONFIG_SET      31
61 #define POWER_SET                32
62 #define INTX_CONFIG_SET          33
63 #define PULL_EN_SET              34
64 #define HILO_SET                 35
65 #define SWITCH2FREF              36
66 #define FREQ_DRIFT_REPORT        37
67 
68 #define PCE_GET                  40
69 #define FIRM_VER_GET             41
70 #define ASIC_VER_GET             42
71 #define ASIC_ID_GET              43
72 #define MAN_ID_GET               44
73 #define TUNER_MODE_SET           45
74 #define STOP_SEARCH              46
75 #define RDS_CNTRL_SET            47
76 
77 #define WRITE_HARDWARE_REG       100
78 #define CODE_DOWNLOAD            101
79 #define RESET                    102
80 
81 #define FM_POWER_MODE            254
82 #define FM_INTERRUPT             255
83 
84 /* Transmitter API */
85 
86 #define CHANL_SET                55
87 #define CHANL_BW_SET		56
88 #define REF_SET                  57
89 #define POWER_ENB_SET            90
90 #define POWER_ATT_SET            58
91 #define POWER_LEV_SET            59
92 #define AUDIO_DEV_SET            60
93 #define PILOT_DEV_SET            61
94 #define RDS_DEV_SET              62
95 #define TX_BAND_SET              65
96 #define PUPD_SET                 91
97 #define AUDIO_IO_SET             63
98 #define PREMPH_SET               64
99 #define MONO_SET                 66
100 #define MUTE                     92
101 #define MPX_LMT_ENABLE           67
102 #define PI_SET                   93
103 #define ECC_SET                  69
104 #define PTY                      70
105 #define AF                       71
106 #define DISPLAY_MODE             74
107 #define RDS_REP_SET              77
108 #define RDS_CONFIG_DATA_SET      98
109 #define RDS_DATA_SET             99
110 #define RDS_DATA_ENB             94
111 #define TA_SET                   78
112 #define TP_SET                   79
113 #define DI_SET                   80
114 #define MS_SET                   81
115 #define PS_SCROLL_SPEED          82
116 #define TX_AUDIO_LEVEL_TEST      96
117 #define TX_AUDIO_LEVEL_TEST_THRESHOLD    73
118 #define TX_AUDIO_INPUT_LEVEL_RANGE_SET   54
119 #define RX_ANTENNA_SELECT        87
120 #define I2C_DEV_ADDR_SET         86
121 #define REF_ERR_CALIB_PARAM_SET          88
122 #define REF_ERR_CALIB_PERIODICITY_SET    89
123 #define SOC_INT_TRIGGER                  52
124 #define SOC_AUDIO_PATH_SET               83
125 #define SOC_PCMI_OVERRIDE                84
126 #define SOC_I2S_OVERRIDE         85
127 #define RSSI_BLOCK_SCAN_FREQ_SET 95
128 #define RSSI_BLOCK_SCAN_START    97
129 #define RSSI_BLOCK_SCAN_DATA_GET  5
130 #define READ_FMANT_TUNE_VALUE            104
131 
132 /* SKB helpers */
133 struct fm_skb_cb {
134 	__u8 fm_op;
135 	struct completion *completion;
136 };
137 
138 #define fm_cb(skb) ((struct fm_skb_cb *)(skb->cb))
139 
140 /* FM Channel-8 command message format */
141 struct fm_cmd_msg_hdr {
142 	__u8 hdr;		/* Logical Channel-8 */
143 	__u8 len;		/* Number of bytes follows */
144 	__u8 op;		/* FM Opcode */
145 	__u8 rd_wr;		/* Read/Write command */
146 	__u8 dlen;		/* Length of payload */
147 } __attribute__ ((packed));
148 
149 #define FM_CMD_MSG_HDR_SIZE    5	/* sizeof(struct fm_cmd_msg_hdr) */
150 
151 /* FM Channel-8 event messgage format */
152 struct fm_event_msg_hdr {
153 	__u8 header;		/* Logical Channel-8 */
154 	__u8 len;		/* Number of bytes follows */
155 	__u8 status;		/* Event status */
156 	__u8 num_fm_hci_cmds;	/* Number of pkts the host allowed to send */
157 	__u8 op;		/* FM Opcode */
158 	__u8 rd_wr;		/* Read/Write command */
159 	__u8 dlen;		/* Length of payload */
160 } __attribute__ ((packed));
161 
162 #define FM_EVT_MSG_HDR_SIZE     7	/* sizeof(struct fm_event_msg_hdr) */
163 
164 /* TI's magic number in firmware file */
165 #define FM_FW_FILE_HEADER_MAGIC	     0x42535442
166 
167 #define FM_ENABLE   1
168 #define FM_DISABLE  0
169 
170 /* FLAG_GET register bits */
171 #define FM_FR_EVENT		(1 << 0)
172 #define FM_BL_EVENT		(1 << 1)
173 #define FM_RDS_EVENT		(1 << 2)
174 #define FM_BBLK_EVENT		(1 << 3)
175 #define FM_LSYNC_EVENT		(1 << 4)
176 #define FM_LEV_EVENT		(1 << 5)
177 #define FM_IFFR_EVENT		(1 << 6)
178 #define FM_PI_EVENT		(1 << 7)
179 #define FM_PD_EVENT		(1 << 8)
180 #define FM_STIC_EVENT		(1 << 9)
181 #define FM_MAL_EVENT		(1 << 10)
182 #define FM_POW_ENB_EVENT	(1 << 11)
183 
184 /*
185  * Firmware files of FM. ASIC ID and ASIC version will be appened to this,
186  * later.
187  */
188 #define FM_FMC_FW_FILE_START      ("fmc_ch8")
189 #define FM_RX_FW_FILE_START       ("fm_rx_ch8")
190 #define FM_TX_FW_FILE_START       ("fm_tx_ch8")
191 
192 #define FM_UNDEFINED_FREQ		   0xFFFFFFFF
193 
194 /* Band types */
195 #define FM_BAND_EUROPE_US	0
196 #define FM_BAND_JAPAN		1
197 
198 /* Seek directions */
199 #define FM_SEARCH_DIRECTION_DOWN	0
200 #define FM_SEARCH_DIRECTION_UP		1
201 
202 /* Tunner modes */
203 #define FM_TUNER_STOP_SEARCH_MODE	0
204 #define FM_TUNER_PRESET_MODE		1
205 #define FM_TUNER_AUTONOMOUS_SEARCH_MODE	2
206 #define FM_TUNER_AF_JUMP_MODE		3
207 
208 /* Min and Max volume */
209 #define FM_RX_VOLUME_MIN	0
210 #define FM_RX_VOLUME_MAX	70
211 
212 /* Volume gain step */
213 #define FM_RX_VOLUME_GAIN_STEP	0x370
214 
215 /* Mute modes */
216 #define	FM_MUTE_ON		0
217 #define FM_MUTE_OFF		1
218 #define	FM_MUTE_ATTENUATE	2
219 
220 #define FM_RX_UNMUTE_MODE		0x00
221 #define FM_RX_RF_DEP_MODE		0x01
222 #define FM_RX_AC_MUTE_MODE		0x02
223 #define FM_RX_HARD_MUTE_LEFT_MODE	0x04
224 #define FM_RX_HARD_MUTE_RIGHT_MODE	0x08
225 #define FM_RX_SOFT_MUTE_FORCE_MODE	0x10
226 
227 /* RF dependent mute mode */
228 #define FM_RX_RF_DEPENDENT_MUTE_ON	1
229 #define FM_RX_RF_DEPENDENT_MUTE_OFF	0
230 
231 /* RSSI threshold min and max */
232 #define FM_RX_RSSI_THRESHOLD_MIN	-128
233 #define FM_RX_RSSI_THRESHOLD_MAX	127
234 
235 /* Stereo/Mono mode */
236 #define FM_STEREO_MODE		0
237 #define FM_MONO_MODE		1
238 #define FM_STEREO_SOFT_BLEND	1
239 
240 /* FM RX De-emphasis filter modes */
241 #define FM_RX_EMPHASIS_FILTER_50_USEC	0
242 #define FM_RX_EMPHASIS_FILTER_75_USEC	1
243 
244 /* FM RDS modes */
245 #define FM_RDS_DISABLE	0
246 #define FM_RDS_ENABLE	1
247 
248 #define FM_NO_PI_CODE	0
249 
250 /* FM and RX RDS block enable/disable  */
251 #define FM_RX_PWR_SET_FM_ON_RDS_OFF		0x1
252 #define FM_RX_PWR_SET_FM_AND_RDS_BLK_ON		0x3
253 #define FM_RX_PWR_SET_FM_AND_RDS_BLK_OFF	0x0
254 
255 /* RX RDS */
256 #define FM_RX_RDS_FLUSH_FIFO		0x1
257 #define FM_RX_RDS_FIFO_THRESHOLD	64	/* tuples */
258 #define FM_RDS_BLK_SIZE		3	/* 3 bytes */
259 
260 /* RDS block types */
261 #define FM_RDS_BLOCK_A		0
262 #define FM_RDS_BLOCK_B		1
263 #define FM_RDS_BLOCK_C		2
264 #define FM_RDS_BLOCK_Ctag	3
265 #define FM_RDS_BLOCK_D		4
266 #define FM_RDS_BLOCK_E		5
267 
268 #define FM_RDS_BLK_IDX_A		0
269 #define FM_RDS_BLK_IDX_B		1
270 #define FM_RDS_BLK_IDX_C		2
271 #define FM_RDS_BLK_IDX_D		3
272 #define FM_RDS_BLK_IDX_UNKNOWN	0xF0
273 
274 #define FM_RDS_STATUS_ERR_MASK	0x18
275 
276 /*
277  * Represents an RDS group type & version.
278  * There are 15 groups, each group has 2 versions: A and B.
279  */
280 #define FM_RDS_GROUP_TYPE_MASK_0A	    ((unsigned long)1<<0)
281 #define FM_RDS_GROUP_TYPE_MASK_0B	    ((unsigned long)1<<1)
282 #define FM_RDS_GROUP_TYPE_MASK_1A	    ((unsigned long)1<<2)
283 #define FM_RDS_GROUP_TYPE_MASK_1B	    ((unsigned long)1<<3)
284 #define FM_RDS_GROUP_TYPE_MASK_2A	    ((unsigned long)1<<4)
285 #define FM_RDS_GROUP_TYPE_MASK_2B	    ((unsigned long)1<<5)
286 #define FM_RDS_GROUP_TYPE_MASK_3A	    ((unsigned long)1<<6)
287 #define FM_RDS_GROUP_TYPE_MASK_3B           ((unsigned long)1<<7)
288 #define FM_RDS_GROUP_TYPE_MASK_4A	    ((unsigned long)1<<8)
289 #define FM_RDS_GROUP_TYPE_MASK_4B	    ((unsigned long)1<<9)
290 #define FM_RDS_GROUP_TYPE_MASK_5A	    ((unsigned long)1<<10)
291 #define FM_RDS_GROUP_TYPE_MASK_5B	    ((unsigned long)1<<11)
292 #define FM_RDS_GROUP_TYPE_MASK_6A	    ((unsigned long)1<<12)
293 #define FM_RDS_GROUP_TYPE_MASK_6B	    ((unsigned long)1<<13)
294 #define FM_RDS_GROUP_TYPE_MASK_7A	    ((unsigned long)1<<14)
295 #define FM_RDS_GROUP_TYPE_MASK_7B	    ((unsigned long)1<<15)
296 #define FM_RDS_GROUP_TYPE_MASK_8A           ((unsigned long)1<<16)
297 #define FM_RDS_GROUP_TYPE_MASK_8B	    ((unsigned long)1<<17)
298 #define FM_RDS_GROUP_TYPE_MASK_9A	    ((unsigned long)1<<18)
299 #define FM_RDS_GROUP_TYPE_MASK_9B	    ((unsigned long)1<<19)
300 #define FM_RDS_GROUP_TYPE_MASK_10A	    ((unsigned long)1<<20)
301 #define FM_RDS_GROUP_TYPE_MASK_10B	    ((unsigned long)1<<21)
302 #define FM_RDS_GROUP_TYPE_MASK_11A	    ((unsigned long)1<<22)
303 #define FM_RDS_GROUP_TYPE_MASK_11B	    ((unsigned long)1<<23)
304 #define FM_RDS_GROUP_TYPE_MASK_12A	    ((unsigned long)1<<24)
305 #define FM_RDS_GROUP_TYPE_MASK_12B	    ((unsigned long)1<<25)
306 #define FM_RDS_GROUP_TYPE_MASK_13A	    ((unsigned long)1<<26)
307 #define FM_RDS_GROUP_TYPE_MASK_13B	    ((unsigned long)1<<27)
308 #define FM_RDS_GROUP_TYPE_MASK_14A	    ((unsigned long)1<<28)
309 #define FM_RDS_GROUP_TYPE_MASK_14B	    ((unsigned long)1<<29)
310 #define FM_RDS_GROUP_TYPE_MASK_15A	    ((unsigned long)1<<30)
311 #define FM_RDS_GROUP_TYPE_MASK_15B	    ((unsigned long)1<<31)
312 
313 /* RX Alternate Frequency info */
314 #define FM_RDS_MIN_AF			  1
315 #define FM_RDS_MAX_AF			204
316 #define FM_RDS_MAX_AF_JAPAN		140
317 #define FM_RDS_1_AF_FOLLOWS		225
318 #define FM_RDS_25_AF_FOLLOWS		249
319 
320 /* RDS system type (RDS/RBDS) */
321 #define FM_RDS_SYSTEM_RDS		0
322 #define FM_RDS_SYSTEM_RBDS		1
323 
324 /* AF on/off */
325 #define FM_RX_RDS_AF_SWITCH_MODE_ON	1
326 #define FM_RX_RDS_AF_SWITCH_MODE_OFF	0
327 
328 /* Retry count when interrupt process goes wrong */
329 #define FM_IRQ_TIMEOUT_RETRY_MAX	5	/* 5 times */
330 
331 /* Audio IO set values */
332 #define FM_RX_AUDIO_ENABLE_I2S	0x01
333 #define FM_RX_AUDIO_ENABLE_ANALOG	0x02
334 #define FM_RX_AUDIO_ENABLE_I2S_AND_ANALOG	0x03
335 #define FM_RX_AUDIO_ENABLE_DISABLE	0x00
336 
337 /* HI/LO set values */
338 #define FM_RX_IFFREQ_TO_HI_SIDE		0x0
339 #define FM_RX_IFFREQ_TO_LO_SIDE		0x1
340 #define FM_RX_IFFREQ_HILO_AUTOMATIC	0x2
341 
342 /*
343  * Default RX mode configuration. Chip will be configured
344  * with this default values after loading RX firmware.
345  */
346 #define FM_DEFAULT_RX_VOLUME		10
347 #define FM_DEFAULT_RSSI_THRESHOLD	3
348 
349 /* Range for TX power level in units for dB/uV */
350 #define FM_PWR_LVL_LOW			91
351 #define FM_PWR_LVL_HIGH			122
352 
353 /* Chip specific default TX power level value */
354 #define FM_PWR_LVL_DEF			4
355 
356 /* FM TX Pre-emphasis filter values */
357 #define FM_TX_PREEMPH_OFF		1
358 #define FM_TX_PREEMPH_50US		0
359 #define FM_TX_PREEMPH_75US		2
360 
361 /* FM TX antenna impedance values */
362 #define FM_TX_ANT_IMP_50		0
363 #define FM_TX_ANT_IMP_200		1
364 #define FM_TX_ANT_IMP_500		2
365 
366 /* Functions exported by FM common sub-module */
367 int fmc_prepare(struct fmdev *);
368 int fmc_release(struct fmdev *);
369 
370 void fmc_update_region_info(struct fmdev *, u8);
371 int fmc_send_cmd(struct fmdev *, u8, u16,
372 				void *, unsigned int, void *, int *);
373 int fmc_is_rds_data_available(struct fmdev *, struct file *,
374 				struct poll_table_struct *);
375 int fmc_transfer_rds_from_internal_buff(struct fmdev *, struct file *,
376 					u8 __user *, size_t);
377 
378 int fmc_set_freq(struct fmdev *, u32);
379 int fmc_set_mode(struct fmdev *, u8);
380 int fmc_set_region(struct fmdev *, u8);
381 int fmc_set_mute_mode(struct fmdev *, u8);
382 int fmc_set_stereo_mono(struct fmdev *, u16);
383 int fmc_set_rds_mode(struct fmdev *, u8);
384 
385 int fmc_get_freq(struct fmdev *, u32 *);
386 int fmc_get_region(struct fmdev *, u8 *);
387 int fmc_get_mode(struct fmdev *, u8 *);
388 
389 /*
390  * channel spacing
391  */
392 #define FM_CHANNEL_SPACING_50KHZ 1
393 #define FM_CHANNEL_SPACING_100KHZ 2
394 #define FM_CHANNEL_SPACING_200KHZ 4
395 #define FM_FREQ_MUL 50
396 
397 #endif
398 
399