add MTK-combo-module,continue with commit 17f39ed917874e77e80411f33faba1b7ee8138c8
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / common / platform / rockchip / mtk_wcn_cmb_stub_rockchip.c
1 /* Copyright Statement:
2  *
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.
9  *
10  * MediaTek Inc. (C) 2010. All rights reserved.
11  *
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.
30  *
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.
34  */
35
36
37 /*! \file
38     \brief  Declaration of library functions
39
40     Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
41 */
42
43 /*******************************************************************************
44 * Copyright (c) 2009 MediaTek Inc.
45 *
46 * All rights reserved. Copying, compilation, modification, distribution
47 * or any other use whatsoever of this material is strictly prohibited
48 * except in accordance with a Software License Agreement with
49 * MediaTek Inc.
50 ********************************************************************************
51 */
52
53 /*******************************************************************************
54 * LEGAL DISCLAIMER
55 *
56 * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND
57 * AGREES THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK
58 * SOFTWARE") RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE
59 * PROVIDED TO BUYER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY
60 * DISCLAIMS ANY AND ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT
61 * LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
62 * PARTICULAR PURPOSE OR NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE
63 * ANY WARRANTY WHATSOEVER WITH RESPECT TO THE SOFTWARE OF ANY THIRD PARTY
64 * WHICH MAY BE USED BY, INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK
65 * SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY
66 * WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE
67 * FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S SPECIFICATION OR TO
68 * CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
69 *
70 * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
71 * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL
72 * BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT
73 * ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY
74 * BUYER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
75 *
76 * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
77 * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT
78 * OF LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING
79 * THEREOF AND RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN
80 * FRANCISCO, CA, UNDER THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE
81 * (ICC).
82 ********************************************************************************
83 */
84
85 /*******************************************************************************
86 *                         C O M P I L E R   F L A G S
87 ********************************************************************************
88 */
89
90 /*******************************************************************************
91 *                                 M A C R O S
92 ********************************************************************************
93 */
94 #define CMB_STUB_LOG_INFO(fmt, arg...) printk(KERN_INFO fmt, ##arg)
95 #define CMB_STUB_LOG_WARN(fmt, arg...) printk(KERN_WARNING fmt, ##arg)
96 #define CMB_STUB_LOG_DBG(fmt, arg...) printk(KERN_DEBUG fmt, ##arg)
97
98
99 /*******************************************************************************
100 *                    E X T E R N A L   R E F E R E N C E S
101 ********************************************************************************
102 */
103 #include <linux/kernel.h>
104 #include <linux/module.h>
105 //#include <cust_gpio_usage.h>
106 //#include <mach/mt6573_pll.h> /* clr_device_working_ability, MT65XX_PDN_PERI_UART3, DEEP_IDLE_STATE, MT65XX_PDN_PERI_MSDC2 */
107 //#include <mach/mt6575_dcm.h>
108 // TODO: [FixMe][GeorgeKuo] keep prototype unchanged temporarily. Replace it
109 // when integrate MT6628 & ALPS & other built-in modules, such as AUDIO.
110 //#include <mach/mt_combo.h>
111
112 #include <mach/mtk_wcn_cmb_stub.h>
113
114 /*******************************************************************************
115 *                              C O N S T A N T S
116 ********************************************************************************
117 */
118
119
120
121 /*******************************************************************************
122 *                             D A T A   T Y P E S
123 ********************************************************************************
124 */
125
126
127
128
129 /*******************************************************************************
130 *                            P U B L I C   D A T A
131 ********************************************************************************
132 */
133
134 /*******************************************************************************
135 *                           P R I V A T E   D A T A
136 ********************************************************************************
137 */
138
139 static wmt_aif_ctrl_cb cmb_stub_aif_ctrl_cb = NULL;
140 static wmt_func_ctrl_cb cmb_stub_func_ctrl_cb = NULL;
141 static CMB_STUB_AIF_X cmb_stub_aif_stat = CMB_STUB_AIF_0;
142
143 /* A temp translation table between COMBO_AUDIO_STATE_X and CMB_STUB_AIF_X.
144  * This is used for ALPS backward compatible ONLY!!! Remove this table, related
145  * functions, and type definition after modifying other kernel built-in modules,
146  * such as AUDIO. [FixMe][GeorgeKuo]
147  */
148 static CMB_STUB_AIF_X audio2aif[] = {
149     [COMBO_AUDIO_STATE_0] = CMB_STUB_AIF_0,
150     [COMBO_AUDIO_STATE_1] = CMB_STUB_AIF_1,
151     [COMBO_AUDIO_STATE_2] = CMB_STUB_AIF_2,
152     [COMBO_AUDIO_STATE_3] = CMB_STUB_AIF_3,
153 };
154
155 /*******************************************************************************
156 *                  F U N C T I O N   D E C L A R A T I O N S
157 ********************************************************************************
158 */
159
160 /*******************************************************************************
161 *                              F U N C T I O N S
162 ********************************************************************************
163 */
164
165 /*!
166  * \brief A registration function for WMT-PLAT to register itself to CMB-STUB.
167  *
168  * An MTK-WCN-CMB-STUB registration function provided to WMT-PLAT to register
169  * itself and related callback functions when driver being loaded into kernel.
170  *
171  * \param p_stub_cb a pointer carrying CMB_STUB_CB information
172  *
173  * \retval 0 operation success
174  * \retval -1 invalid parameters
175  */
176 int
177 mtk_wcn_cmb_stub_reg (P_CMB_STUB_CB p_stub_cb)
178 {
179     if ( (!p_stub_cb )
180         || (p_stub_cb->size != sizeof(CMB_STUB_CB)) ) {
181         CMB_STUB_LOG_WARN( "[cmb_stub] invalid p_stub_cb:0x%p size(%d)\n",
182             p_stub_cb, (p_stub_cb) ? p_stub_cb->size: 0);
183         return -1;
184     }
185
186     CMB_STUB_LOG_DBG( "[cmb_stub] registered, p_stub_cb:0x%p size(%d)\n",
187         p_stub_cb, p_stub_cb->size);
188
189     cmb_stub_aif_ctrl_cb = p_stub_cb->aif_ctrl_cb;
190     cmb_stub_func_ctrl_cb = p_stub_cb->func_ctrl_cb;
191
192     return 0;
193 }
194 EXPORT_SYMBOL(mtk_wcn_cmb_stub_reg);
195
196 /*!
197  * \brief A unregistration function for WMT-PLAT to unregister from CMB-STUB.
198  *
199  * An MTK-WCN-CMB-STUB unregistration function provided to WMT-PLAT to
200  * unregister itself and clear callback function references.
201  *
202  * \retval 0 operation success
203  */
204 int
205 mtk_wcn_cmb_stub_unreg (void)
206 {
207     cmb_stub_aif_ctrl_cb = NULL;
208     cmb_stub_func_ctrl_cb = NULL;
209
210     CMB_STUB_LOG_INFO("[cmb_stub] unregistered \n"); /* KERN_DEBUG */
211
212     return 0;
213 }
214 EXPORT_SYMBOL(mtk_wcn_cmb_stub_unreg);
215
216 /* stub functions for kernel to control audio path pin mux */
217 int mtk_wcn_cmb_stub_aif_ctrl (CMB_STUB_AIF_X state, CMB_STUB_AIF_CTRL ctrl)
218 {
219     int ret;
220
221     if ( (CMB_STUB_AIF_MAX <= state)
222         || (CMB_STUB_AIF_CTRL_MAX <= ctrl) ) {
223
224         CMB_STUB_LOG_WARN("[cmb_stub] aif_ctrl invalid (%d, %d)\n", state, ctrl);
225         return -1;
226     }
227
228     /* avoid the early interrupt before we register the eirq_handler */
229     if (cmb_stub_aif_ctrl_cb){
230         ret = (*cmb_stub_aif_ctrl_cb)(state, ctrl);
231         CMB_STUB_LOG_INFO( "[cmb_stub] aif_ctrl_cb state(%d->%d) ctrl(%d) ret(%d)\n",
232             cmb_stub_aif_stat , state, ctrl, ret); /* KERN_DEBUG */
233
234         cmb_stub_aif_stat = state;
235         return ret;
236     }
237     else {
238         CMB_STUB_LOG_WARN("[cmb_stub] aif_ctrl_cb null \n");
239         return -2;
240     }
241 }
242 EXPORT_SYMBOL(mtk_wcn_cmb_stub_aif_ctrl);
243
244 /* Use a temp translation table between COMBO_AUDIO_STATE_X and CMB_STUB_AIF_X
245  * for ALPS backward compatible ONLY!!! Remove this table, related functions,
246  * and type definition after modifying other kernel built-in modules, such as
247  * AUDIO. [FixMe][GeorgeKuo]
248  */
249 int
250 mt_combo_audio_ctrl_ex (COMBO_AUDIO_STATE state, u32 clt_ctrl)
251 {
252     /* input sanity check */
253     if (COMBO_AUDIO_STATE_MAX < state) {
254         CMB_STUB_LOG_WARN("[cmb_stub] invalid COMBO_AUDIO_STATE(%d)\n", state);
255         return -1;
256     }
257
258     return mtk_wcn_cmb_stub_aif_ctrl(audio2aif[state],
259         (clt_ctrl) ? CMB_STUB_AIF_CTRL_EN : CMB_STUB_AIF_CTRL_DIS );
260 }
261 EXPORT_SYMBOL(mt_combo_audio_ctrl_ex);
262
263 void mtk_wcn_cmb_stub_func_ctrl (unsigned int type, unsigned int on) {
264     if (cmb_stub_func_ctrl_cb) {
265         (*cmb_stub_func_ctrl_cb)(type, on);
266     }
267     else {
268         CMB_STUB_LOG_WARN("[cmb_stub] func_ctrl_cb null \n");
269     }
270 }
271 EXPORT_SYMBOL(mtk_wcn_cmb_stub_func_ctrl);
272
273 /*platform-related APIs*/
274 //void clr_device_working_ability(UINT32 clockId, MT6573_STATE state);
275 //void set_device_working_ability(UINT32 clockId, MT6573_STATE state);
276
277 static int
278 _mt_combo_plt_do_deep_idle(COMBO_IF src, int enter) {
279     int ret = -1;
280
281     const char *combo_if_name[] =
282     {   "COMBO_IF_UART",
283         "COMBO_IF_MSDC"
284     };
285
286     if(src != COMBO_IF_UART && src!= COMBO_IF_MSDC){
287         CMB_STUB_LOG_WARN("src = %d is error\n", src);
288         return ret;
289     }
290
291     if(src >= 0 && src < COMBO_IF_MAX){
292         CMB_STUB_LOG_INFO("src = %s, to enter deep idle? %d \n",
293             combo_if_name[src],
294             enter);
295     }
296
297     /*TODO: For Common SDIO configuration, we need to do some judgement between STP and WIFI
298             to decide if the msdc will enter deep idle safely*/
299
300     switch(src){
301         case COMBO_IF_UART:
302             if(enter == 0){
303                 //clr_device_working_ability(MT65XX_PDN_PERI_UART3, DEEP_IDLE_STATE);
304                 //disable_dpidle_by_bit(MT65XX_PDN_PERI_UART2);
305             } else {
306                 //set_device_working_ability(MT65XX_PDN_PERI_UART3, DEEP_IDLE_STATE);
307                 //enable_dpidle_by_bit(MT65XX_PDN_PERI_UART2);
308             }
309             ret = 0;
310             break;
311
312         case COMBO_IF_MSDC:
313             if(enter == 0){
314                 //clr_device_working_ability(MT65XX_PDN_PERI_MSDC2, DEEP_IDLE_STATE);
315             } else {
316                 //set_device_working_ability(MT65XX_PDN_PERI_MSDC2, DEEP_IDLE_STATE);
317             }
318             ret = 0;
319             break;
320
321         default:
322             ret = -1;
323             break;
324     }
325
326     return ret;
327 }
328
329 int
330 mt_combo_plt_enter_deep_idle (
331     COMBO_IF src
332     ) {
333     //return 0;
334     // TODO: [FixMe][GeorgeKuo] handling this depends on common UART or common SDIO
335     return _mt_combo_plt_do_deep_idle(src, 1);
336 }
337 EXPORT_SYMBOL(mt_combo_plt_enter_deep_idle);
338
339 int
340 mt_combo_plt_exit_deep_idle (
341     COMBO_IF src
342     ) {
343     //return 0;
344     // TODO: [FixMe][GeorgeKuo] handling this depends on common UART or common SDIO
345     return _mt_combo_plt_do_deep_idle(src, 0);
346 }
347 EXPORT_SYMBOL(mt_combo_plt_exit_deep_idle);
348