4 * MediaTek <www.MediaTek.com>
5 * hongcheng <hongcheng.xia@MediaTek.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <linux/string.h>
24 #include <linux/slab.h>
26 #include "fm_typedef.h"
30 #include "fm_stdlib.h"
32 #include "fm_config.h"
33 /* #include "fm_cust_cfg.h" */
34 #include "mt6630_fm_cust_cfg.h"
35 fm_cust_cfg mt6630_fm_config
;
36 /* static fm_s32 fm_index = 0; */
38 static fm_s32
MT6630fm_cust_config_print(fm_cust_cfg
*cfg
)
40 WCN_DBG(FM_NTC
| MAIN
, "MT6630 rssi_l:\t%d\n", cfg
->rx_cfg
.long_ana_rssi_th
);
41 WCN_DBG(FM_NTC
| MAIN
, "MT6630 rssi_s:\t%d\n", cfg
->rx_cfg
.short_ana_rssi_th
);
42 WCN_DBG(FM_NTC
| MAIN
, "MT6630 pamd_th:\t%d\n", cfg
->rx_cfg
.pamd_th
);
43 WCN_DBG(FM_NTC
| MAIN
, "MT6630 mr_th:\t%d\n", cfg
->rx_cfg
.mr_th
);
44 WCN_DBG(FM_NTC
| MAIN
, "MT6630 atdc_th:\t%d\n", cfg
->rx_cfg
.atdc_th
);
45 WCN_DBG(FM_NTC
| MAIN
, "MT6630 prx_th:\t%d\n", cfg
->rx_cfg
.prx_th
);
46 WCN_DBG(FM_NTC
| MAIN
, "MT6630 atdev_th:\t%d\n", cfg
->rx_cfg
.atdev_th
);
47 WCN_DBG(FM_NTC
| MAIN
, "MT6630 smg_th:\t%d\n", cfg
->rx_cfg
.smg_th
);
48 WCN_DBG(FM_NTC
| MAIN
, "de_emphasis:\t%d\n", cfg
->rx_cfg
.deemphasis
);
49 WCN_DBG(FM_NTC
| MAIN
, "osc_freq:\t%d\n", cfg
->rx_cfg
.osc_freq
);
51 WCN_DBG(FM_NTC
| MAIN
, "aud path[%d]I2S state[%d]mode[%d]rate[%d]\n", cfg
->aud_cfg
.aud_path
,
52 cfg
->aud_cfg
.i2s_info
.status
, cfg
->aud_cfg
.i2s_info
.mode
,
53 cfg
->aud_cfg
.i2s_info
.rate
);
57 static fm_s32
MT6630cfg_item_handler(fm_s8
*grp
, fm_s8
*key
, fm_s8
*val
, fm_cust_cfg
*cfg
)
60 struct fm_rx_cust_cfg
*rx_cfg
= &cfg
->rx_cfg
;
62 if (0 <= (ret
= cfg_item_match(key
, val
, "FM_RX_RSSI_TH_LONG_MT6630", &rx_cfg
->long_ana_rssi_th
))) { /* FMR_RSSI_TH_L = 0x0301 */
66 cfg_item_match(key
, val
, "FM_RX_RSSI_TH_SHORT_MT6630",
67 &rx_cfg
->short_ana_rssi_th
))) {
71 cfg_item_match(key
, val
, "FM_RX_DESENSE_RSSI_MT6630",
72 &rx_cfg
->desene_rssi_th
))) {
74 } else if (0 <= (ret
= cfg_item_match(key
, val
, "FM_RX_PAMD_TH_MT6630", &rx_cfg
->pamd_th
))) {
76 } else if (0 <= (ret
= cfg_item_match(key
, val
, "FM_RX_MR_TH_MT6630", &rx_cfg
->mr_th
))) {
78 } else if (0 <= (ret
= cfg_item_match(key
, val
, "FM_RX_ATDC_TH_MT6630", &rx_cfg
->atdc_th
))) {
80 } else if (0 <= (ret
= cfg_item_match(key
, val
, "FM_RX_PRX_TH_MT6630", &rx_cfg
->prx_th
))) {
83 /*else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_ATDEV_TH_MT6630", &rx_cfg->atdev_th)))
87 else if (0 <= (ret
= cfg_item_match(key
, val
, "FM_RX_SMG_TH_MT6630", &rx_cfg
->smg_th
))) {
91 cfg_item_match(key
, val
, "FM_RX_DEEMPHASIS_MT6630", &rx_cfg
->deemphasis
))) {
94 (ret
= cfg_item_match(key
, val
, "FM_RX_OSC_FREQ_MT6630", &rx_cfg
->osc_freq
))) {
97 WCN_DBG(FM_WAR
| MAIN
, "MT6630 invalid key\n");
102 static fm_s32
MT6630fm_cust_config_default(fm_cust_cfg
*cfg
)
106 cfg
->rx_cfg
.long_ana_rssi_th
= FM_RX_RSSI_TH_LONG_MT6630
;
107 cfg
->rx_cfg
.short_ana_rssi_th
= FM_RX_RSSI_TH_SHORT_MT6630
;
108 cfg
->rx_cfg
.desene_rssi_th
= FM_RX_DESENSE_RSSI_MT6630
;
109 cfg
->rx_cfg
.pamd_th
= FM_RX_PAMD_TH_MT6630
;
110 cfg
->rx_cfg
.mr_th
= FM_RX_MR_TH_MT6630
;
111 cfg
->rx_cfg
.atdc_th
= FM_RX_ATDC_TH_MT6630
;
112 cfg
->rx_cfg
.prx_th
= FM_RX_PRX_TH_MT6630
;
113 cfg
->rx_cfg
.smg_th
= FM_RX_SMG_TH_MT6630
;
114 cfg
->rx_cfg
.deemphasis
= FM_RX_DEEMPHASIS_MT6630
;
115 cfg
->rx_cfg
.osc_freq
= FM_RX_OSC_FREQ_MT6630
;
117 cfg
->tx_cfg
.pamd_th
= FM_TX_PAMD_TH_MT6630
;
118 cfg
->tx_cfg
.mr_th
= FM_TX_MR_TH_MT6630
;
119 cfg
->tx_cfg
.smg_th
= FM_TX_SMG_TH_MT6630
;
121 #ifdef CONFIG_MTK_MERGE_INTERFACE_SUPPORT
122 cfg
->aud_cfg
.aud_path
= FM_AUD_MRGIF
;
123 cfg
->aud_cfg
.i2s_info
.status
= FM_I2S_OFF
;
124 cfg
->aud_cfg
.i2s_info
.mode
= FM_I2S_SLAVE
;
125 cfg
->aud_cfg
.i2s_info
.rate
= FM_I2S_44K
;
126 cfg
->aud_cfg
.i2s_pad
= FM_I2S_PAD_IO
;
127 #elif defined FM_DIGITAL_INPUT
128 cfg
->aud_cfg
.aud_path
= FM_AUD_I2S
;
129 cfg
->aud_cfg
.i2s_info
.status
= FM_I2S_OFF
;
130 cfg
->aud_cfg
.i2s_info
.mode
= FM_I2S_SLAVE
;
131 cfg
->aud_cfg
.i2s_info
.rate
= FM_I2S_44K
;
132 cfg
->aud_cfg
.i2s_pad
= FM_I2S_PAD_IO
;
133 #elif defined FM_ANALOG_INPUT
134 cfg
->aud_cfg
.aud_path
= FM_AUD_ANALOG
;
135 cfg
->aud_cfg
.i2s_info
.status
= FM_I2S_STATE_ERR
;
136 cfg
->aud_cfg
.i2s_info
.mode
= FM_I2S_MODE_ERR
;
137 cfg
->aud_cfg
.i2s_info
.rate
= FM_I2S_SR_ERR
;
138 cfg
->aud_cfg
.i2s_pad
= FM_I2S_PAD_ERR
;
140 cfg
->aud_cfg
.aud_path
= FM_AUD_ERR
;
141 cfg
->aud_cfg
.i2s_info
.status
= FM_I2S_STATE_ERR
;
142 cfg
->aud_cfg
.i2s_info
.mode
= FM_I2S_MODE_ERR
;
143 cfg
->aud_cfg
.i2s_info
.rate
= FM_I2S_SR_ERR
;
144 cfg
->aud_cfg
.i2s_pad
= FM_I2S_PAD_ERR
;
150 static fm_s32
MT6630fm_cust_config_file(const fm_s8
*filename
, fm_cust_cfg
*cfg
)
156 if (!(buf
= fm_zalloc(4096))) {
157 WCN_DBG(FM_ALT
| MAIN
, "-ENOMEM\n");
162 file_len
= fm_file_read(filename
, buf
, 4096, 0);
169 ret
= cfg_parser(buf
, MT6630cfg_item_handler
, cfg
);
180 #define MT6630_FM_CUST_CFG_PATH "etc/fmr/mt6630_fm_cust.cfg"
181 fm_s32
MT6630fm_cust_config_setup(const fm_s8
*filepath
)
185 fm_s8 file_path
[51] = { 0 };
187 MT6630fm_cust_config_default(&mt6630_fm_config
);
188 WCN_DBG(FM_NTC
| MAIN
, "MT6630 FM default config\n");
189 MT6630fm_cust_config_print(&mt6630_fm_config
);
192 filep
= MT6630_FM_CUST_CFG_PATH
;
194 memcpy(file_path
, filepath
, (strlen(filepath
) > 50) ? 50 : strlen(filepath
));
199 ret
= MT6630fm_cust_config_file(filep
, &mt6630_fm_config
);
200 WCN_DBG(FM_NTC
| MAIN
, "MT6630 FM cust config\n");
201 MT6630fm_cust_config_print(&mt6630_fm_config
);