import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / misc / mediatek / fmradio / mt6630 / pub / mt6630_fm_config.c
1 /* mt6630_fm_config.c
2 *
3 * (C) Copyright 2011
4 * MediaTek <www.MediaTek.com>
5 * hongcheng <hongcheng.xia@MediaTek.com>
6 *
7 * FM Radio Driver
8 *
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.
13 *
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.
18 *
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
22 */
23 #include <linux/string.h>
24 #include <linux/slab.h>
25
26 #include "fm_typedef.h"
27 #include "fm_rds.h"
28 #include "fm_dbg.h"
29 #include "fm_err.h"
30 #include "fm_stdlib.h"
31 #include "fm_patch.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; */
37
38 static fm_s32 MT6630fm_cust_config_print(fm_cust_cfg *cfg)
39 {
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);
50
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);
54 return 0;
55 }
56
57 static fm_s32 MT6630cfg_item_handler(fm_s8 *grp, fm_s8 *key, fm_s8 *val, fm_cust_cfg *cfg)
58 {
59 fm_s32 ret = 0;
60 struct fm_rx_cust_cfg *rx_cfg = &cfg->rx_cfg;
61
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 */
63 return ret;
64 } else if (0 <=
65 (ret =
66 cfg_item_match(key, val, "FM_RX_RSSI_TH_SHORT_MT6630",
67 &rx_cfg->short_ana_rssi_th))) {
68 return ret;
69 } else if (0 <=
70 (ret =
71 cfg_item_match(key, val, "FM_RX_DESENSE_RSSI_MT6630",
72 &rx_cfg->desene_rssi_th))) {
73 return ret;
74 } else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_PAMD_TH_MT6630", &rx_cfg->pamd_th))) {
75 return ret;
76 } else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_MR_TH_MT6630", &rx_cfg->mr_th))) {
77 return ret;
78 } else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_ATDC_TH_MT6630", &rx_cfg->atdc_th))) {
79 return ret;
80 } else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_PRX_TH_MT6630", &rx_cfg->prx_th))) {
81 return ret;
82 }
83 /*else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_ATDEV_TH_MT6630", &rx_cfg->atdev_th)))
84 {
85 return ret;
86 } */
87 else if (0 <= (ret = cfg_item_match(key, val, "FM_RX_SMG_TH_MT6630", &rx_cfg->smg_th))) {
88 return ret;
89 } else if (0 <=
90 (ret =
91 cfg_item_match(key, val, "FM_RX_DEEMPHASIS_MT6630", &rx_cfg->deemphasis))) {
92 return ret;
93 } else if (0 <=
94 (ret = cfg_item_match(key, val, "FM_RX_OSC_FREQ_MT6630", &rx_cfg->osc_freq))) {
95 return ret;
96 } else {
97 WCN_DBG(FM_WAR | MAIN, "MT6630 invalid key\n");
98 return -1;
99 }
100 }
101
102 static fm_s32 MT6630fm_cust_config_default(fm_cust_cfg *cfg)
103 {
104 FMR_ASSERT(cfg);
105
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;
116
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;
120
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;
139 #else
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;
145 #endif
146
147 return 0;
148 }
149
150 static fm_s32 MT6630fm_cust_config_file(const fm_s8 *filename, fm_cust_cfg *cfg)
151 {
152 fm_s32 ret = 0;
153 fm_s8 *buf = NULL;
154 fm_s32 file_len = 0;
155
156 if (!(buf = fm_zalloc(4096))) {
157 WCN_DBG(FM_ALT | MAIN, "-ENOMEM\n");
158 return -ENOMEM;
159 }
160 /* fm_index = 0; */
161
162 file_len = fm_file_read(filename, buf, 4096, 0);
163
164 if (file_len <= 0) {
165 ret = -1;
166 goto out;
167 }
168
169 ret = cfg_parser(buf, MT6630cfg_item_handler, cfg);
170
171 out:
172
173 if (buf) {
174 fm_free(buf);
175 }
176
177 return ret;
178 }
179
180 #define MT6630_FM_CUST_CFG_PATH "etc/fmr/mt6630_fm_cust.cfg"
181 fm_s32 MT6630fm_cust_config_setup(const fm_s8 *filepath)
182 {
183 fm_s32 ret = 0;
184 fm_s8 *filep = NULL;
185 fm_s8 file_path[51] = { 0 };
186
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);
190
191 if (!filepath) {
192 filep = MT6630_FM_CUST_CFG_PATH;
193 } else {
194 memcpy(file_path, filepath, (strlen(filepath) > 50) ? 50 : strlen(filepath));
195 filep = file_path;
196 trim_path(&filep);
197 }
198
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);
202
203 return ret;
204 }