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.
38 \brief Declaration of library functions
40 Any definitions in this file will be shared among GLUE Layer and internal Driver Stack.
43 /*******************************************************************************
44 * Copyright (c) 2009 MediaTek Inc.
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
50 ********************************************************************************
53 /*******************************************************************************
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.
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.
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
82 ********************************************************************************
85 /*******************************************************************************
86 * C O M P I L E R F L A G S
87 ********************************************************************************
90 /*******************************************************************************
92 ********************************************************************************
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)
99 /*******************************************************************************
100 * E X T E R N A L R E F E R E N C E S
101 ********************************************************************************
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>
112 #include <mach/mtk_wcn_cmb_stub.h>
114 /*******************************************************************************
116 ********************************************************************************
121 /*******************************************************************************
123 ********************************************************************************
129 /*******************************************************************************
130 * P U B L I C D A T A
131 ********************************************************************************
134 /*******************************************************************************
135 * P R I V A T E D A T A
136 ********************************************************************************
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;
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]
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,
155 /*******************************************************************************
156 * F U N C T I O N D E C L A R A T I O N S
157 ********************************************************************************
160 /*******************************************************************************
162 ********************************************************************************
166 * \brief A registration function for WMT-PLAT to register itself to CMB-STUB.
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.
171 * \param p_stub_cb a pointer carrying CMB_STUB_CB information
173 * \retval 0 operation success
174 * \retval -1 invalid parameters
177 mtk_wcn_cmb_stub_reg (P_CMB_STUB_CB 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);
186 CMB_STUB_LOG_DBG( "[cmb_stub] registered, p_stub_cb:0x%p size(%d)\n",
187 p_stub_cb, p_stub_cb->size);
189 cmb_stub_aif_ctrl_cb = p_stub_cb->aif_ctrl_cb;
190 cmb_stub_func_ctrl_cb = p_stub_cb->func_ctrl_cb;
194 EXPORT_SYMBOL(mtk_wcn_cmb_stub_reg);
197 * \brief A unregistration function for WMT-PLAT to unregister from CMB-STUB.
199 * An MTK-WCN-CMB-STUB unregistration function provided to WMT-PLAT to
200 * unregister itself and clear callback function references.
202 * \retval 0 operation success
205 mtk_wcn_cmb_stub_unreg (void)
207 cmb_stub_aif_ctrl_cb = NULL;
208 cmb_stub_func_ctrl_cb = NULL;
210 CMB_STUB_LOG_INFO("[cmb_stub] unregistered \n"); /* KERN_DEBUG */
214 EXPORT_SYMBOL(mtk_wcn_cmb_stub_unreg);
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)
221 if ( (CMB_STUB_AIF_MAX <= state)
222 || (CMB_STUB_AIF_CTRL_MAX <= ctrl) ) {
224 CMB_STUB_LOG_WARN("[cmb_stub] aif_ctrl invalid (%d, %d)\n", state, ctrl);
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 */
234 cmb_stub_aif_stat = state;
238 CMB_STUB_LOG_WARN("[cmb_stub] aif_ctrl_cb null \n");
242 EXPORT_SYMBOL(mtk_wcn_cmb_stub_aif_ctrl);
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]
250 mt_combo_audio_ctrl_ex (COMBO_AUDIO_STATE state, u32 clt_ctrl)
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);
258 return mtk_wcn_cmb_stub_aif_ctrl(audio2aif[state],
259 (clt_ctrl) ? CMB_STUB_AIF_CTRL_EN : CMB_STUB_AIF_CTRL_DIS );
261 EXPORT_SYMBOL(mt_combo_audio_ctrl_ex);
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);
268 CMB_STUB_LOG_WARN("[cmb_stub] func_ctrl_cb null \n");
271 EXPORT_SYMBOL(mtk_wcn_cmb_stub_func_ctrl);
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);
278 _mt_combo_plt_do_deep_idle(COMBO_IF src, int enter) {
281 const char *combo_if_name[] =
286 if(src != COMBO_IF_UART && src!= COMBO_IF_MSDC){
287 CMB_STUB_LOG_WARN("src = %d is error\n", src);
291 if(src >= 0 && src < COMBO_IF_MAX){
292 CMB_STUB_LOG_INFO("src = %s, to enter deep idle? %d \n",
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*/
303 //clr_device_working_ability(MT65XX_PDN_PERI_UART3, DEEP_IDLE_STATE);
304 //disable_dpidle_by_bit(MT65XX_PDN_PERI_UART2);
306 //set_device_working_ability(MT65XX_PDN_PERI_UART3, DEEP_IDLE_STATE);
307 //enable_dpidle_by_bit(MT65XX_PDN_PERI_UART2);
314 //clr_device_working_ability(MT65XX_PDN_PERI_MSDC2, DEEP_IDLE_STATE);
316 //set_device_working_ability(MT65XX_PDN_PERI_MSDC2, DEEP_IDLE_STATE);
330 mt_combo_plt_enter_deep_idle (
334 // TODO: [FixMe][GeorgeKuo] handling this depends on common UART or common SDIO
335 return _mt_combo_plt_do_deep_idle(src, 1);
337 EXPORT_SYMBOL(mt_combo_plt_enter_deep_idle);
340 mt_combo_plt_exit_deep_idle (
344 // TODO: [FixMe][GeorgeKuo] handling this depends on common UART or common SDIO
345 return _mt_combo_plt_do_deep_idle(src, 0);
347 EXPORT_SYMBOL(mt_combo_plt_exit_deep_idle);