1 /* Copyright Statement:
3 * This software/firmware and related documentation ("MediaTek Software") are
4 * protected under relevant copyright laws. The information contained herein
5 * is confidential and proprietary to MediaTek Inc. and/or its licensors.
6 * Without the prior written permission of MediaTek inc. and/or its licensors,
7 * any reproduction, modification, use or disclosure of MediaTek Software,
8 * and information contained herein, in whole or in part, shall be strictly prohibited.
10 /* MediaTek Inc. (C) 2010. All rights reserved.
12 * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
13 * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
14 * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
15 * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
18 * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
19 * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
20 * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
21 * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
22 * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
23 * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
24 * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
25 * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
26 * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
27 * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
28 * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
29 * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
31 * The following software/firmware and/or related documentation ("MediaTek Software")
32 * have been modified by MediaTek Inc. All revisions are subject to any receiver's
33 * applicable license agreements with MediaTek Inc.
36 /* alps/ALPS_SW/TRUNK/MAIN/alps/kernel/arch/arm/mach-mt6516/include/mach/fm.h
39 * MediaTek <www.MediaTek.com>
40 * William Chung <William.Chung@MediaTek.com>
42 * MT6516 AR10x0 FM Radio Driver
44 * This program is free software; you can redistribute it and/or modify
45 * it under the terms of the GNU General Public License as published by
46 * the Free Software Foundation; either version 2 of the License, or
47 * (at your option) any later version.
49 * This program is distributed in the hope that it will be useful,
50 * but WITHOUT ANY WARRANTY; without even the implied warranty of
51 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
52 * GNU General Public License for more details.
54 * You should have received a copy of the GNU General Public License
55 * along with this program; if not, write to the Free Software
56 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
64 #include <linux/ioctl.h>
65 #include <linux/time.h>
75 //*****************************************************************************************
76 //***********************************FM config for customer ***********************************
77 //*****************************************************************************************
79 #define FMR_RSSI_TH_LONG 0x0301 //FM radio long antenna RSSI threshold(11.375dBuV)
80 #define FMR_RSSI_TH_SHORT 0x02E0 //FM radio short antenna RSSI threshold(-1dBuV)
81 #define FMR_CQI_TH 0x00E9 //FM radio Channel quality indicator threshold(0x0000~0x00FF)
82 #define FMR_SEEK_SPACE 1 //FM radio seek space,1:100KHZ; 2:200KHZ
83 #define FMR_SCAN_CH_SIZE 40 //FM radio scan max channel size
84 #define FMR_BAND 1 //FM radio band, 1:87.5MHz~108.0MHz; 2:76.0MHz~90.0MHz; 3:76.0MHz~108.0MHz; 4:special
85 #define FMR_BAND_FREQ_L 875 //FM radio special band low freq(Default 87.5MHz)
86 #define FMR_BAND_FREQ_H 1080 //FM radio special band high freq(Default 108.0MHz)
87 #define FM_SCAN_SORT_SELECT FM_SCAN_SORT_DOWN
90 #define FMTX_PWR_LEVEL_MAX 120 //FM transmitter power level, rang: 85db~120db, default 120db
92 //*****************************************************************************************
93 //***********************************FM config for engineer ***********************************
94 //*****************************************************************************************
96 #define FMR_MR_TH 0x01BD //FM radio MR threshold
97 #define ADDR_SCAN_TH 0xE0 //scan thrshold register
98 #define ADDR_CQI_TH 0xE1 //scan CQI register
101 #define FMTX_SCAN_HOLE_LOW 923 //92.3MHz~95.4MHz should not show to user
102 #define FMTX_SCAN_HOLE_HIGH 954 //92.3MHz~95.4MHz should not show to user
103 //*****************************************************************************************
106 #define FM_DEVICE_NAME "/dev/fm"
112 #define FM_BADSTATUS 3
113 #define FM_TUNE_FAILED 4
114 #define FM_SEEK_FAILED 5
116 #define FM_SCAN_FAILED 7
120 #define FM_BAND_UNKNOWN 0
121 #define FM_BAND_UE 1 // US/Europe band 87.5MHz ~ 108MHz (DEFAULT)
122 #define FM_BAND_JAPAN 2 // Japan band 76MHz ~ 90MHz
123 #define FM_BAND_JAPANW 3 // Japan wideband 76MHZ ~ 108MHz
124 #define FM_BAND_SPECIAL 4 // special band between 76MHZ and 108MHz
125 #define FM_BAND_DEFAULT FM_BAND_UE
126 #define FM_FREQ_MIN FMR_BAND_FREQ_L
127 #define FM_FREQ_MAX FMR_BAND_FREQ_H
128 #define FM_RAIDO_BAND FM_BAND_UE
130 #define FM_SPACE_UNKNOWN 0
131 #define FM_SPACE_100K 1
132 #define FM_SPACE_200K 2
133 #define FM_SPACE_DEFAULT FMR_SEEK_SPACE
134 #define FM_SEEK_SPACE FMR_SEEK_SPACE
137 #define FM_MAX_CHL_SIZE FMR_SCAN_CH_SIZE
139 #define FM_AUTO_HILO_OFF 0
140 #define FM_AUTO_HILO_ON 1
144 #define FM_SEEK_DOWN 1
146 #define FM_CHIP_AR1000 0x1000
147 #define FM_CHIP_MT5192 0x91
148 #define FM_CHIP_MT5193 0x92
149 #define FM_CHIP_MT6616 0x6616
150 #define FM_CHIP_MT6620 0x6620
151 #define FM_CHIP_MT6626 0x6626
152 #define FM_CHIP_MT6628 0x6628
153 #define FM_CHIP_UNSUPPORTED 0xffff
156 #define FM_SEEKTH_LEVEL_DEFAULT 4
158 #define FM_IOC_MAGIC 0xf5 // FIXME: any conflict?
160 struct fm_tune_parm {
165 uint16_t freq; // IN/OUT parameter
168 struct fm_seek_parm {
175 uint16_t freq; // IN/OUT parameter
178 struct fm_scan_parm {
183 uint16_t freq; // OUT parameter
184 uint16_t ScanTBL[16]; //need no less than the chip
185 uint16_t ScanTBLSize; //IN/OUT parameter
196 struct fm_ch_rssi cr[16*16];
200 int chip_id; //chip ID, eg. 6620
201 int eco_ver; //chip ECO version, eg. E3
202 int rom_ver; //FM DSP rom code version, eg. V2
203 int patch_ver; //FM DSP patch version, eg. 1.11
214 uint8_t Artificial_Head;
218 uint32_t flag_status;
228 uint8_t Local_Time_offset_signbit;
229 uint8_t Local_Time_offset_half_hour;
235 int16_t AF[2][25]; //100KHz
249 uint8_t TextData[4][64];
260 int dirty; //indicate if the data changed or not
261 int len; //the data len form chip
268 unsigned long groupA[16]; //RDS groupA counter
269 unsigned long groupB[16]; //RDS groupB counter
272 enum rds_group_cnt_opcode
274 RDS_GROUP_CNT_READ = 0,
280 struct rds_group_cnt_req
283 enum rds_group_cnt_opcode op;
284 struct rds_group_cnt gc;
290 RDSFlag_Struct RDSFlag;
296 uint8_t Radio_Page_Code;
297 uint16_t Program_Item_Number_Code;
298 uint8_t Extend_Country_Code;
299 uint16_t Language_Code;
303 //uint16_t Block_Backup[32][4];
304 //uint16_t Group_Cnt[32];
307 uint16_t event_status; //will use RDSFlag_Struct RDSFlag->flag_status to check which event, is that ok?
311 //Need care the following definition.
312 //valid Rds Flag for notify
314 RDS_FLAG_IS_TP = 0x0001, // Program is a traffic program
315 RDS_FLAG_IS_TA = 0x0002, // Program currently broadcasts a traffic ann.
316 RDS_FLAG_IS_MUSIC = 0x0004, // Program currently broadcasts music
317 RDS_FLAG_IS_STEREO = 0x0008, // Program is transmitted in stereo
318 RDS_FLAG_IS_ARTIFICIAL_HEAD = 0x0010, // Program is an artificial head recording
319 RDS_FLAG_IS_COMPRESSED = 0x0020, // Program content is compressed
320 RDS_FLAG_IS_DYNAMIC_PTY = 0x0040, // Program type can change
321 RDS_FLAG_TEXT_AB = 0x0080 // If this flag changes state, a new radio text string begins
325 RDS_EVENT_FLAGS = 0x0001, // One of the RDS flags has changed state
326 RDS_EVENT_PI_CODE = 0x0002, // The program identification code has changed
327 RDS_EVENT_PTY_CODE = 0x0004, // The program type code has changed
328 RDS_EVENT_PROGRAMNAME = 0x0008, // The program name has changed
329 RDS_EVENT_UTCDATETIME = 0x0010, // A new UTC date/time is available
330 RDS_EVENT_LOCDATETIME = 0x0020, // A new local date/time is available
331 RDS_EVENT_LAST_RADIOTEXT = 0x0040, // A radio text string was completed
332 RDS_EVENT_AF = 0x0080, // Current Channel RF signal strength too weak, need do AF switch
333 RDS_EVENT_AF_LIST = 0x0100, // An alternative frequency list is ready
334 RDS_EVENT_AFON_LIST = 0x0200, // An alternative frequency list is ready
335 RDS_EVENT_TAON = 0x0400, // Other Network traffic announcement start
336 RDS_EVENT_TAON_OFF = 0x0800, // Other Network traffic announcement finished.
337 RDS_EVENT_RDS = 0x2000, // RDS Interrupt had arrived durint timer period
338 RDS_EVENT_NO_RDS = 0x4000, // RDS Interrupt not arrived durint timer period
339 RDS_EVENT_RDS_TIMER = 0x8000 // Timer for RDS Bler Check. ---- BLER block error rate
342 struct fm_rds_tx_parm {
345 uint16_t ps[12]; // 4 ps
346 uint16_t other_rds[87]; // 0~29 other groups
347 uint8_t other_rds_cnt; // # of other group
350 typedef struct fm_rds_tx_req{
351 unsigned char pty; // 0~31 integer
352 unsigned char rds_rbds; // 0:RDS, 1:RBDS
353 unsigned char dyn_pty; // 0:static, 1:dynamic
354 unsigned short pi_code; // 2-byte hex
355 unsigned char ps_buf[8]; // hex buf of PS
356 unsigned char ps_len; // length of PS, must be 0 / 8"
357 unsigned char af; // 0~204, 0:not used, 1~204:(87.5+0.1*af)MHz
358 unsigned char ah; // Artificial head, 0:no, 1:yes
359 unsigned char stereo; // 0:mono, 1:stereo
360 unsigned char compress; // Audio compress, 0:no, 1:yes
361 unsigned char tp; // traffic program, 0:no, 1:yes
362 unsigned char ta; // traffic announcement, 0:no, 1:yes
363 unsigned char speech; // 0:music, 1:speech
366 #define TX_SCAN_MAX 10
367 #define TX_SCAN_MIN 1
368 struct fm_tx_scan_parm {
370 uint8_t band; //87.6~108MHz
373 uint16_t freq; // start freq, if less than band min freq, then will use band min freq
375 uint16_t ScanTBL[TX_SCAN_MAX]; //need no less than the chip
376 uint16_t ScanTBLSize; //IN: desired size, OUT: scan result size
379 struct fm_gps_rtc_info{
380 int err; //error number, 0: success, other: err code
381 int retryCnt; //GPS mnl can decide retry times
382 int ageThd; //GPS 3D fix time diff threshold
383 int driftThd; //GPS RTC drift threshold
384 struct timeval tvThd; //time value diff threshold
385 int age; //GPS 3D fix time diff
386 int drift; //GPS RTC drift
388 unsigned long stamp; //time stamp in jiffies
389 struct timeval tv; //time stamp value in RTC
413 struct fm_i2s_setting{
424 #define FM_IOCTL_POWERUP _IOWR(FM_IOC_MAGIC, 0, struct fm_tune_parm*)
425 #define FM_IOCTL_POWERDOWN _IOWR(FM_IOC_MAGIC, 1, int32_t*)
426 #define FM_IOCTL_TUNE _IOWR(FM_IOC_MAGIC, 2, struct fm_tune_parm*)
427 #define FM_IOCTL_SEEK _IOWR(FM_IOC_MAGIC, 3, struct fm_seek_parm*)
428 #define FM_IOCTL_SETVOL _IOWR(FM_IOC_MAGIC, 4, uint32_t*)
429 #define FM_IOCTL_GETVOL _IOWR(FM_IOC_MAGIC, 5, uint32_t*)
430 #define FM_IOCTL_MUTE _IOWR(FM_IOC_MAGIC, 6, uint32_t*)
431 #define FM_IOCTL_GETRSSI _IOWR(FM_IOC_MAGIC, 7, uint32_t*)
432 #define FM_IOCTL_SCAN _IOWR(FM_IOC_MAGIC, 8, struct fm_scan_parm*)
433 #define FM_IOCTL_STOP_SCAN _IO(FM_IOC_MAGIC, 9)
434 #define FM_IOCTL_POWERUP_TX _IOWR(FM_IOC_MAGIC, 20, struct fm_tune_parm*)
435 #define FM_IOCTL_TUNE_TX _IOWR(FM_IOC_MAGIC, 21, struct fm_tune_parm*)
436 #define FM_IOCTL_RDS_TX _IOWR(FM_IOC_MAGIC, 22, struct fm_rds_tx_parm*)
438 //IOCTL and struct for test
439 #define FM_IOCTL_GETCHIPID _IOWR(FM_IOC_MAGIC, 10, uint16_t*)
440 #define FM_IOCTL_EM_TEST _IOWR(FM_IOC_MAGIC, 11, struct fm_em_parm*)
441 #define FM_IOCTL_RW_REG _IOWR(FM_IOC_MAGIC, 12, struct fm_ctl_parm*)
442 #define FM_IOCTL_GETMONOSTERO _IOWR(FM_IOC_MAGIC, 13, uint16_t*)
443 #define FM_IOCTL_GETCURPAMD _IOWR(FM_IOC_MAGIC, 14, uint16_t*)
444 #define FM_IOCTL_GETGOODBCNT _IOWR(FM_IOC_MAGIC, 15, uint16_t*)
445 #define FM_IOCTL_GETBADBNT _IOWR(FM_IOC_MAGIC, 16, uint16_t*)
446 #define FM_IOCTL_GETBLERRATIO _IOWR(FM_IOC_MAGIC, 17, uint16_t*)
450 #define FM_IOCTL_RDS_ONOFF _IOWR(FM_IOC_MAGIC, 18, uint16_t*)
451 #define FM_IOCTL_RDS_SUPPORT _IOWR(FM_IOC_MAGIC, 19, int32_t*)
453 #define FM_IOCTL_RDS_SIM_DATA _IOWR(FM_IOC_MAGIC, 23, uint32_t*)
454 #define FM_IOCTL_IS_FM_POWERED_UP _IOWR(FM_IOC_MAGIC, 24, uint32_t*)
457 #define FM_IOCTL_TX_SUPPORT _IOWR(FM_IOC_MAGIC, 25, int32_t*)
458 #define FM_IOCTL_RDSTX_SUPPORT _IOWR(FM_IOC_MAGIC, 26, int32_t*)
459 #define FM_IOCTL_RDSTX_ENABLE _IOWR(FM_IOC_MAGIC, 27, int32_t*)
460 #define FM_IOCTL_TX_SCAN _IOWR(FM_IOC_MAGIC, 28, struct fm_tx_scan_parm*)
462 //IOCTL for FM over BT
463 #define FM_IOCTL_OVER_BT_ENABLE _IOWR(FM_IOC_MAGIC, 29, int32_t*)
465 //IOCTL for FM ANTENNA SWITCH
466 #define FM_IOCTL_ANA_SWITCH _IOWR(FM_IOC_MAGIC, 30, int32_t*)
467 #define FM_IOCTL_GETCAPARRAY _IOWR(FM_IOC_MAGIC, 31, int32_t*)
469 //IOCTL for FM compensation by GPS RTC
470 #define FM_IOCTL_GPS_RTC_DRIFT _IOWR(FM_IOC_MAGIC, 32, struct fm_gps_rtc_info*)
472 //IOCTL for FM I2S Setting
473 #define FM_IOCTL_I2S_SETTING _IOWR(FM_IOC_MAGIC, 33, struct fm_i2s_setting*)
475 #define FM_IOCTL_RDS_GROUPCNT _IOWR(FM_IOC_MAGIC, 34, struct rds_group_cnt_req*)
476 #define FM_IOCTL_RDS_GET_LOG _IOWR(FM_IOC_MAGIC, 35, struct rds_raw_data*)
478 #define FM_IOCTL_SCAN_GETRSSI _IOWR(FM_IOC_MAGIC, 36, struct fm_rssi_req*)
479 #define FM_IOCTL_SETMONOSTERO _IOWR(FM_IOC_MAGIC, 37, int32_t)
480 #define FM_IOCTL_GET_HW_INFO _IOWR(FM_IOC_MAGIC, 38, struct fm_hw_info*)
482 #define FM_IOCTL_DUMP_REG _IO(FM_IOC_MAGIC, 0xFF)
512 uint16_t rw_flag;//0:write, 1:read