1 /******************************************************************************
4 *[Revision Date] 2010-03-01
7 * The program provides SDIO HIF driver
9 * Copyright (C) 2010 MediaTek Incorporation. All Rights Reserved.
10 ******************************************************************************/
19 * Add AEE message support
20 * 1) Show AEE warning(red screen) if SDIO access error occurs
24 * [WCXRP00000851] [MT6628 Wi-Fi][Driver] Add HIFSYS related definition to driver source tree
25 * include correct header file upon setting.
28 * [WCXRP00001098] [MT6620 Wi-Fi][Driver] Replace printk by DBG LOG macros in linux porting layer
29 * 1. eliminaite direct calls to printk in porting layer.
30 * 2. replaced by DBGLOG, which would be XLOG on ALPS platforms.
33 * [WCXRP00000994] [MT6620 Wi-Fi][Driver] dump message for bus error and reset bus error flag while re-initialized
34 * 1. always show error message for SDIO bus errors.
35 * 2. reset bus error flag when re-initialization
38 * [WCXRP00000851] [MT6628 Wi-Fi][Driver] Add HIFSYS related definition to driver source tree
39 * add MT6628 related definitions for Linux/Android driver.
42 * [WCXRP00000702] [MT5931][Driver] Modify initialization sequence for E1 ASIC
43 * add device ID for MT5931.
46 * [WCXRP00000623] [MT6620 Wi-Fi][Driver] use ARCH define to distinguish PC Linux driver
47 * Use CONFIG_X86 instead of PC_LINUX_DRIVER_USE option to have proper compile settting for PC Linux driver
50 * [WCXRP00000592] [MT6620 Wi-Fi][Driver] Support PC Linux Environment Driver Build
51 * Add a compiler option "PC_LINUX_DRIVER_USE" for building driver in PC Linux environment.
54 * [WCXRP00000559] [MT6620 Wi-Fi][Driver] Combine TX/RX DMA buffers into a single one to reduce physically continuous memory consumption
55 * deprecate CFG_HANDLE_IST_IN_SDIO_CALLBACK.
58 * [WCXRP00000559] [MT6620 Wi-Fi][Driver] Combine TX/RX DMA buffers into a single one to reduce physically continuous memory consumption
59 * 1. deprecate CFG_HANDLE_IST_IN_SDIO_CALLBACK
60 * 2. Use common coalescing buffer for both TX/RX directions
64 * [WCXRP00000521] [MT6620 Wi-Fi][Driver] Remove non-standard debug message
65 * Toggle non-standard debug messages to comments.
67 * 11 15 2010 jeffrey.chang
68 * [WCXRP00000181] [MT6620 Wi-Fi][Driver] fix the driver message "GLUE_FLAG_HALT skip INT" during unloading
69 * Fix GLUE_FALG_HALT message which cause driver to hang
72 * [WCXRP00000166] [MT6620 Wi-Fi][Driver] use SDIO CMD52 for enabling/disabling interrupt to reduce transaction period
76 * [WCXRP00000166] [MT6620 Wi-Fi][Driver] use SDIO CMD52 for enabling/disabling interrupt to reduce transaction period
77 * change to use CMD52 for enabling/disabling interrupt to reduce SDIO transaction time
79 * 11 01 2010 yarco.yang
80 * [WCXRP00000149] [MT6620 WI-Fi][Driver]Fine tune performance on MT6516 platform
81 * Add code to run WlanIST in SDIO callback.
84 * [WCXRP00000122] [MT6620 Wi-Fi][Driver] Preparation for YuSu source tree integration
85 * remove HIF_SDIO_ONE flags because the settings could be merged for runtime detection instead of compile-time.
87 * 10 19 2010 jeffrey.chang
88 * [WCXRP00000120] [MT6620 Wi-Fi][Driver] Refine linux kernel module to the license of MTK propietary and enable MTK HIF by default
89 * Refine linux kernel module to the license of MTK and enable MTK HIF
91 * 08 21 2010 jeffrey.chang
93 * 1) add sdio two setting
94 * 2) bug fix of sdio glue
96 * 08 18 2010 jeffrey.chang
98 * support multi-function sdio
102 * #if defined(__X86__) is not working, change to use #ifdef CONFIG_X86.
106 * add ENE SDIO host workaround for x86 linux platform.
110 * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
112 * 06 06 2010 kevin.huang
113 * [WPD00003832][MT6620 5931] Create driver base
114 * [MT6620 5931] Create driver base
116 * 05 07 2010 jeffrey.chang
117 * [WPD00003826]Initial import for Linux port
120 * 03 28 2010 jeffrey.chang
121 * [WPD00003826]Initial import for Linux port
122 * clear sdio interrupt
124 * 03 24 2010 jeffrey.chang
125 * [WPD00003826]Initial import for Linux port
126 * initial import for Linux port
130 /*******************************************************************************
131 * C O M P I L E R F L A G S
132 ********************************************************************************
135 /*******************************************************************************
136 * E X T E R N A L R E F E R E N C E S
137 ********************************************************************************
143 #include "hif_sdio.h"
145 #include <linux/mmc/card.h>
146 #include <linux/mmc/host.h>
147 #include <linux/mmc/sdio.h>
148 #include <linux/mmc/sdio_func.h> /* sdio_readl(), etc */
149 #include <linux/mmc/sdio_ids.h>
152 #include <linux/mm.h>
153 //#ifndef CONFIG_X86 modify by Nicolas Luo
155 #include <asm/memory.h>
160 #include "mt6620_reg.h"
161 #elif defined(MT5931)
162 #include "mt5931_reg.h"
163 #elif defined(MT6628)
164 #include "mt6628_reg.h"
167 #if CFG_DBG_GPIO_PINS/* FIXME: move to platform or custom header */
168 #include <mach/mt6516_gpio.h>
171 /*******************************************************************************
173 ********************************************************************************
176 #define HIF_SDIO_ERR_TITLE_STR "["CHIP_NAME"] SDIO Access Error!"
177 #define HIF_SDIO_ERR_DESC_STR "**SDIO Access Error**\n"
183 * function prototypes
188 mtk_sdio_probe(MTK_WCN_HIF_SDIO_CLTCTX, const MTK_WCN_HIF_SDIO_FUNCINFO *);
191 mtk_sdio_remove(MTK_WCN_HIF_SDIO_CLTCTX);
192 static INT32 mtk_sdio_interrupt(MTK_WCN_HIF_SDIO_CLTCTX);
195 * sdio function info table
198 static MTK_WCN_HIF_SDIO_FUNCINFO funcInfo[] = {
200 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x020a, 0x1, 512) },
201 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x020c, 0x2, 512) },
202 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x018a, 0x1, 512) },
203 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x018c, 0x2, 512) },
204 #elif defined(MT5931)
205 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x5931, 0x1, 512) },
206 #elif defined(MT6628)
207 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x6628, 0x1, 512) },
212 static MTK_WCN_HIF_SDIO_CLTINFO cltInfo = {
213 .func_tbl = funcInfo,
214 .func_tbl_size = sizeof(funcInfo)/sizeof(MTK_WCN_HIF_SDIO_FUNCINFO),
215 .hif_clt_probe = mtk_sdio_probe,
216 .hif_clt_remove = mtk_sdio_remove,
217 .hif_clt_irq = mtk_sdio_interrupt,
222 static const struct sdio_device_id mtk_sdio_ids[] = {
224 { SDIO_DEVICE(0x037a, 0x020a) }, /* Not an SDIO standard class device */
225 { SDIO_DEVICE(0x037a, 0x020b) }, /* Not an SDIO standard class device */
226 { SDIO_DEVICE(0x037a, 0x020c) }, /* Not an SDIO standard class device */
227 #elif defined(MT5931)
228 { SDIO_DEVICE(0x037a, 0x5931) }, /* Not an SDIO standard class device */
229 #elif defined(MT6628)
230 { SDIO_DEVICE(0x037a, 0x6628) }, /* Not an SDIO standard class device */
232 { /* end: all zeroes */ },
235 MODULE_DEVICE_TABLE(sdio, mtk_sdio_ids);
239 /*******************************************************************************
241 ********************************************************************************
245 /*******************************************************************************
246 * P U B L I C D A T A
247 ********************************************************************************
249 extern KAL_WAKE_LOCK_T isr_wakelock;
251 /*******************************************************************************
252 * P R I V A T E D A T A
253 ********************************************************************************
255 static probe_card pfWlanProbe = NULL;
256 static remove_card pfWlanRemove = NULL;
259 #if (MTK_WCN_HIF_SDIO == 0)
260 static struct sdio_driver mtk_sdio_driver = {
261 .name = "wlan", /* "MTK SDIO WLAN Driver" */
262 .id_table = mtk_sdio_ids,
269 #if CFG_DBG_GPIO_PINS
272 UINT_32 dbgPinSTP[] = {
273 GPIO_PLATFORM(33)/* CMFLASH, IDX_ERR J613 */
274 , GPIO_PLATFORM(62)/* EINT3, IDX_TX_THREAD */
275 , GPIO_PLATFORM(80)/* SPI_CS_N, IDX_TX_REQ J613 */
276 , GPIO_PLATFORM(81)/* SPI_SCK, IDX_TX_PORT_WRITE J613 */
277 , GPIO_PLATFORM(17) /* CMRST, IDX_STP_MTX_BT J618 */
278 , GPIO_PLATFORM(18) /* CMPDN, IDX_STP_MTX_FM J613 */
279 , GPIO_PLATFORM(19) /* CMVREF,IDX_STP_MTX_GPS J613 */
280 , GPIO_INVALID /* REMOVED, IDX_STP_MTX_WIFI */
281 , GPIO_INVALID /* REMOVED, IDX_STP_MTX_WMT */
282 , GPIO_PLATFORM(135) /* SCL2, IDX_LOOP_CNT J616 */
283 , GPIO_PLATFORM(136) /* SDA2, IDX_NO_BUF J616 */
284 , GPIO_PLATFORM(30) /* CAM_MECHSH0, IDX_BT_TX, J613 low-active */
285 , GPIO_PLATFORM(31) /* CAM_MECHSH1, IDX_BT_RX, J613 low-active */
286 , GPIO_PLATFORM(124) /* GPS_PWR_EN, ThreadDSPIn [GPS] */
287 , GPIO_PLATFORM(125) /* GPS_SYNC, mtk_sys_msg_recv [GPS] */
288 , GPIO_PLATFORM(21) /* GPS_EINT8, dump_nmea_data [GPS] */
289 , GPIO_PLATFORM(29) /* CAM_STROBE, IDX_GPS_TX, J613 low-active */
290 , GPIO_PLATFORM(20) /*CMHREF, J613 UNUSED */
291 // , GPIO_6516(64) /* EINT5, REMOVED!!! for MT6620-Wi-Fi Int */
292 // , GPIO_6516(122) /* BT_PWR_EN, REMOVED!!! for MT6620-PMU_EN */
293 // , GPIO_6516(123) /* BT_RESET, REMOVED!!! for MT6620-RST */
296 /*******************************************************************************
298 ********************************************************************************
301 /*******************************************************************************
302 * F U N C T I O N D E C L A R A T I O N S
303 ********************************************************************************
306 /*******************************************************************************
308 ********************************************************************************
310 #if CFG_DBG_GPIO_PINS
311 void debug_gpio_init(void)
315 for (i = 0; i < sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]); ++i) {
316 if (GPIO_INVALID == dbgPinSTP[i]) {
319 //printk(KERN_INFO "[%s] %ld \n", __FUNCTION__, dbgPinSTP[i]);
320 mt_set_gpio_pull_enable(dbgPinSTP[i], 0); /* disable pull */
321 mt_set_gpio_dir(dbgPinSTP[i], GPIO_DIR_OUT); /* set output */
322 mt_set_gpio_mode(dbgPinSTP[i], GPIO_MODE_00); /* set gpio mode */
324 /* toggle twice to check if ok: */
325 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ZERO); /* tie low */
326 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ONE); /* tie high*/
327 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ZERO); /* tie low */
328 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ONE); /* tie high*/
330 //printk(KERN_INFO "[%s] initialization ok \n", __FUNCTION__);
333 void debug_gpio_deinit(void)
336 for (i = 0; i < sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]); ++i) {
337 if (GPIO_INVALID == dbgPinSTP[i]) {
340 //printk(KERN_INFO "[%s] %ld \n", __FUNCTION__, dbgPinSTP[i]);
341 mt_set_gpio_dir(dbgPinSTP[i], GPIO_DIR_IN);
344 //printk(KERN_INFO "[%s] k\n", __FUNCTION__);
347 void mtk_wcn_stp_debug_gpio_assert(UINT_32 dwIndex, UINT_32 dwMethod)
351 if (dwIndex >= (sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]))) {
352 //printk(KERN_INFO "[%s] invalid dwIndex(%ld) \n", __FUNCTION__, dwIndex);
356 if (dwIndex > IDX_STP_MAX) {
357 //printk(KERN_INFO "[%s] dwIndex(%ld) > IDX_STP_MAX(%d) \n", __FUNCTION__, dwIndex, IDX_STP_MAX);
360 if (GPIO_INVALID == dbgPinSTP[dwIndex]) {
364 if (dwMethod & DBG_TIE_DIR) {
365 if (dwMethod & DBG_HIGH) {
366 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ONE);
369 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ZERO);
374 if (dwMethod & DBG_TOGGLE(0)) {
375 for (i = 0; i < DBG_TOGGLE_NUM(dwMethod); ++i) {
376 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ZERO);
377 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ONE);
386 /*----------------------------------------------------------------------------*/
388 * \brief This function is a SDIO interrupt callback function
390 * \param[in] func pointer to SDIO handle
394 /*----------------------------------------------------------------------------*/
398 static INT32 mtk_sdio_interrupt(MTK_WCN_HIF_SDIO_CLTCTX cltCtx)
400 P_GLUE_INFO_T prGlueInfo = NULL;
403 prGlueInfo = mtk_wcn_hif_sdio_get_drvdata(cltCtx);
408 //printk(KERN_INFO DRV_NAME"No glue info in mtk_sdio_interrupt()\n");
409 return (-HIF_SDIO_ERR_FAIL);
412 if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
413 //printk(KERN_INFO DRV_NAME"GLUE_FLAG_HALT skip INT\n");
414 ret = mtk_wcn_hif_sdio_writel(cltCtx, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
418 KAL_WAKE_UNLOCK(NULL, &isr_wakelock);
419 KAL_WAKE_LOCK_TIMEOUT(NULL, &isr_wakelock, KAL_HZ/10);
420 ret = mtk_wcn_hif_sdio_writel(cltCtx, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
422 set_bit (GLUE_FLAG_INT_BIT, &prGlueInfo->u4Flag);
424 /* when we got sdio interrupt, we wake up the tx servie thread*/
425 wake_up_interruptible(&prGlueInfo->waitq);
432 static unsigned int in_interrupt = 0;
434 static void mtk_sdio_interrupt(struct sdio_func *func)
436 P_GLUE_INFO_T prGlueInfo = NULL;
440 prGlueInfo = sdio_get_drvdata(func);
444 //printk(KERN_INFO DRV_NAME"No glue info in mtk_sdio_interrupt()\n");
448 if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
449 sdio_writel(prGlueInfo->rHifInfo.func, WHLPCR_INT_EN_CLR, MCR_WHLPCR, &ret);
450 //printk(KERN_INFO DRV_NAME"GLUE_FLAG_HALT skip INT\n");
454 sdio_writel(prGlueInfo->rHifInfo.func, WHLPCR_INT_EN_CLR, MCR_WHLPCR, &ret);
457 wlanISR(prGlueInfo->prAdapter, TRUE);
459 if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
460 /* Should stop now... skip pending interrupt */
461 //printk(KERN_INFO DRV_NAME"ignore pending interrupt\n");
464 wlanIST(prGlueInfo->prAdapter);
468 set_bit (GLUE_FLAG_INT_BIT, &prGlueInfo->u4Flag);
470 /* when we got sdio interrupt, we wake up the tx servie thread*/
471 wake_up_interruptible(&prGlueInfo->waitq);
475 /*----------------------------------------------------------------------------*/
477 * \brief This function is a SDIO probe function
479 * \param[in] func pointer to SDIO handle
480 * \param[in] id pointer to SDIO device id table
484 /*----------------------------------------------------------------------------*/
488 // FIXME: global variable
489 static const MTK_WCN_HIF_SDIO_FUNCINFO *prFunc;
493 mtk_sdio_probe(MTK_WCN_HIF_SDIO_CLTCTX cltCtx, const MTK_WCN_HIF_SDIO_FUNCINFO *prFuncInfo)
495 INT32 ret = HIF_SDIO_ERR_SUCCESS;
499 if (pfWlanProbe((PVOID) &cltCtx) != WLAN_STATUS_SUCCESS) {
500 //printk(KERN_WARNING DRV_NAME"pfWlanProbe fail!call pfWlanRemove()\n");
502 ret = -(HIF_SDIO_ERR_FAIL);
504 //printk(KERN_INFO DRV_NAME"mtk_wifi_sdio_probe() done(%d)\n", ret);
509 static int mtk_sdio_probe (
510 struct sdio_func *func,
511 const struct sdio_device_id *id
517 //printk(KERN_INFO DRV_NAME "mtk_sdio_probe()\n");
522 //printk(KERN_INFO DRV_NAME "Basic struct size checking...\n");
523 //printk(KERN_INFO DRV_NAME "sizeof(struct device) = %d\n", sizeof(struct device));
524 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_host) = %d\n", sizeof(struct mmc_host));
525 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_card) = %d\n", sizeof(struct mmc_card));
526 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_driver) = %d\n", sizeof(struct mmc_driver));
527 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_data) = %d\n", sizeof(struct mmc_data));
528 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_command) = %d\n", sizeof(struct mmc_command));
529 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_request) = %d\n", sizeof(struct mmc_request));
530 //printk(KERN_INFO DRV_NAME "sizeof(struct sdio_func) = %d\n", sizeof(struct sdio_func));
532 //printk(KERN_INFO DRV_NAME "Card information checking...\n");
533 //printk(KERN_INFO DRV_NAME "func = 0x%p\n", func);
534 //printk(KERN_INFO DRV_NAME "Number of info = %d:\n", func->card->num_info);
536 for (i = 0; i < func->card->num_info; i++) {
537 //printk(KERN_INFO DRV_NAME "info[%d]: %s\n", i, func->card->info[i]);
540 sdio_claim_host(func);
541 ret = sdio_enable_func(func);
542 sdio_release_host(func);
545 //printk(KERN_INFO DRV_NAME"sdio_enable_func failed!\n");
548 //printk(KERN_INFO DRV_NAME"sdio_enable_func done!\n");
550 if (pfWlanProbe((PVOID)func) != WLAN_STATUS_SUCCESS) {
551 //printk(KERN_WARNING DRV_NAME"pfWlanProbe fail!call pfWlanRemove()\n");
556 #if CFG_DBG_GPIO_PINS
557 //printk(KERN_INFO "[%s] init debug gpio, 20100815 \n", __FUNCTION__);
558 /* Debug pins initialization */
564 //printk(KERN_INFO DRV_NAME"mtk_sdio_probe() done(%d)\n", ret);
572 mtk_sdio_remove(MTK_WCN_HIF_SDIO_CLTCTX cltCtx)
574 INT32 ret = HIF_SDIO_ERR_SUCCESS;
575 //printk(KERN_INFO DRV_NAME"pfWlanRemove done\n");
583 struct sdio_func *func
586 //printk(KERN_INFO DRV_NAME"mtk_sdio_remove()\n");
588 #if CFG_DBG_GPIO_PINS
589 //printk(KERN_INFO "[%s] deinit debug gpio \n", __FUNCTION__);
594 //printk(KERN_INFO DRV_NAME"pfWlanRemove done\n");
597 sdio_claim_host(func);
598 sdio_disable_func(func);
599 //printk(KERN_INFO DRV_NAME"sdio_disable_func() done\n");
600 sdio_release_host(func);
602 //printk(KERN_INFO DRV_NAME"mtk_sdio_remove() done\n");
606 #if (MTK_WCN_HIF_SDIO == 0)
609 struct device * pDev,
613 //printk(KERN_INFO "mtk_sdio: mtk_sdio_suspend dev(0x%p)\n", pDev);
614 //printk(KERN_INFO "mtk_sdio: MediaTek SDIO WLAN driver\n");
619 int mtk_sdio_resume (
623 //printk(KERN_INFO "mtk_sdio: mtk_sdio_resume dev(0x%p)\n", pDev);
630 /*----------------------------------------------------------------------------*/
632 * \brief This function will register sdio bus to the os
634 * \param[in] pfProbe Function pointer to detect card
635 * \param[in] pfRemove Function pointer to remove card
637 * \return The result of registering sdio bus
639 /*----------------------------------------------------------------------------*/
651 //printk(KERN_INFO "mtk_sdio: MediaTek SDIO WLAN driver\n");
652 //printk(KERN_INFO "mtk_sdio: Copyright MediaTek Inc.\n");
654 pfWlanProbe = pfProbe;
655 pfWlanRemove = pfRemove;
658 /* register MTK sdio client */
659 ret = ((mtk_wcn_hif_sdio_client_reg(&cltInfo) == HIF_SDIO_ERR_SUCCESS) ? WLAN_STATUS_SUCCESS : WLAN_STATUS_FAILURE);
661 mtk_sdio_driver.probe = mtk_sdio_probe;
662 mtk_sdio_driver.remove = mtk_sdio_remove;
664 mtk_sdio_driver.drv.suspend = mtk_sdio_suspend;
665 mtk_sdio_driver.drv.resume = mtk_sdio_resume;
667 ret = (sdio_register_driver(&mtk_sdio_driver) == 0) ? WLAN_STATUS_SUCCESS : WLAN_STATUS_FAILURE;
671 } /* end of glRegisterBus() */
674 /*----------------------------------------------------------------------------*/
676 * \brief This function will unregister sdio bus to the os
678 * \param[in] pfRemove Function pointer to remove card
682 /*----------------------------------------------------------------------------*/
692 /* unregister MTK sdio client */
693 mtk_wcn_hif_sdio_client_unreg(&cltInfo);
695 sdio_unregister_driver(&mtk_sdio_driver);
699 } /* end of glUnregisterBus() */
702 /*----------------------------------------------------------------------------*/
704 * \brief This function stores hif related info, which is initialized before.
706 * \param[in] prGlueInfo Pointer to glue info structure
707 * \param[in] u4Cookie Pointer to UINT_32 memory base variable for _HIF_HPI
711 /*----------------------------------------------------------------------------*/
714 P_GLUE_INFO_T prGlueInfo,
718 P_GL_HIF_INFO_T prHif = NULL;
720 prHif = &prGlueInfo->rHifInfo;
723 //prHif->prFuncInfo = ((MTK_WCN_HIF_SDIO_FUNCINFO *) u4Cookie);
724 prHif->prFuncInfo = prFunc;
725 prHif->cltCtx = *((MTK_WCN_HIF_SDIO_CLTCTX *) u4Cookie);
726 mtk_wcn_hif_sdio_set_drvdata(prHif->cltCtx, prGlueInfo);
729 prHif->func = (struct sdio_func *) u4Cookie;
731 //printk(KERN_INFO DRV_NAME"prHif->func->dev = 0x%p\n", &prHif->func->dev);
732 //printk(KERN_INFO DRV_NAME"prHif->func->vendor = 0x%04X\n", prHif->func->vendor);
733 //printk(KERN_INFO DRV_NAME"prHif->func->device = 0x%04X\n", prHif->func->device);
734 //printk(KERN_INFO DRV_NAME"prHif->func->func = 0x%04X\n", prHif->func->num);
736 sdio_set_drvdata(prHif->func, prGlueInfo);
738 SET_NETDEV_DEV(prGlueInfo->prDevHandler, &prHif->func->dev);
742 } /* end of glSetHifInfo() */
744 /*----------------------------------------------------------------------------*/
746 * \brief This function clears hif related info.
748 * \param[in] prGlueInfo Pointer to glue info structure
752 /*----------------------------------------------------------------------------*/
755 P_GLUE_INFO_T prGlueInfo
758 //P_GL_HIF_INFO_T prHif = NULL;
759 //ASSERT(prGlueInfo);
760 //prHif = &prGlueInfo->rHifInfo;
763 } /* end of glClearHifInfo() */
766 /*----------------------------------------------------------------------------*/
768 * \brief Initialize bus operation and hif related information, request resources.
770 * \param[out] pvData A pointer to HIF-specific data type buffer.
771 * For eHPI, pvData is a pointer to UINT_32 type and stores a
772 * mapped base address.
776 /*----------------------------------------------------------------------------*/
782 #if (MTK_WCN_HIF_SDIO == 0)
784 struct sdio_func *func = NULL;
788 func = (struct sdio_func *) pvData;
790 sdio_claim_host(func);
791 ret = sdio_set_block_size(func, 512);
792 sdio_release_host(func);
795 //printk(KERN_INFO DRV_NAME"sdio_set_block_size 512 failed!\n");
798 //printk(KERN_INFO DRV_NAME"sdio_set_block_size 512 done!\n");
801 //printk(KERN_INFO DRV_NAME"param: func->cur_blksize(%d)\n", func->cur_blksize);
802 //printk(KERN_INFO DRV_NAME"param: func->max_blksize(%d)\n", func->max_blksize);
803 //printk(KERN_INFO DRV_NAME"param: func->card->host->max_blk_size(%d)\n", func->card->host->max_blk_size);
804 //printk(KERN_INFO DRV_NAME"param: func->card->host->max_blk_count(%d)\n", func->card->host->max_blk_count);
807 } /* end of glBusInit() */
810 /*----------------------------------------------------------------------------*/
812 * \brief Stop bus operation and release resources.
814 * \param[in] pvData A pointer to struct net_device.
818 /*----------------------------------------------------------------------------*/
826 } /* end of glBusRelease() */
829 /*----------------------------------------------------------------------------*/
831 * \brief Setup bus interrupt operation and interrupt handler for os.
833 * \param[in] pvData A pointer to struct net_device.
834 * \param[in] pfnIsr A pointer to interrupt handler function.
835 * \param[in] pvCookie Private data for pfnIsr function.
837 * \retval WLAN_STATUS_SUCCESS if success
838 * NEGATIVE_VALUE if fail
840 /*----------------------------------------------------------------------------*/
850 #if (MTK_WCN_HIF_SDIO == 0)
851 struct net_device *prNetDevice = NULL;
852 P_GLUE_INFO_T prGlueInfo = NULL;
853 P_GL_HIF_INFO_T prHifInfo = NULL;
859 prNetDevice = (struct net_device *) pvData;
860 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
866 prHifInfo = &prGlueInfo->rHifInfo;
868 sdio_claim_host(prHifInfo->func);
869 ret = sdio_claim_irq(prHifInfo->func, mtk_sdio_interrupt);
870 sdio_release_host(prHifInfo->func);
873 struct net_device *prNetDevice = NULL;
874 P_GLUE_INFO_T prGlueInfo = NULL;
880 prNetDevice = (struct net_device *) pvData;
882 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
888 mtk_wcn_hif_sdio_enable_irq(prGlueInfo->rHifInfo.cltCtx, MTK_WCN_BOOL_TRUE);
892 } /* end of glBusSetIrq() */
895 /*----------------------------------------------------------------------------*/
897 * \brief Stop bus interrupt operation and disable interrupt handling for os.
899 * \param[in] pvData A pointer to struct net_device.
900 * \param[in] pvCookie Private data for pfnIsr function.
904 /*----------------------------------------------------------------------------*/
911 #if (MTK_WCN_HIF_SDIO == 0)
912 struct net_device *prNetDevice = NULL;
913 P_GLUE_INFO_T prGlueInfo = NULL;
914 P_GL_HIF_INFO_T prHifInfo = NULL;
919 //printk(KERN_INFO DRV_NAME"%s null pvData\n", __FUNCTION__);
922 prNetDevice = (struct net_device *) pvData;
923 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
926 //printk(KERN_INFO DRV_NAME"%s no glue info\n", __FUNCTION__);
930 prHifInfo = &prGlueInfo->rHifInfo;
932 sdio_claim_host(prHifInfo->func);
933 ret = sdio_release_irq(prHifInfo->func);
934 sdio_release_host(prHifInfo->func);
937 struct net_device *prNetDevice = NULL;
938 P_GLUE_INFO_T prGlueInfo = NULL;
942 //printk(KERN_INFO DRV_NAME"%s null pvData\n", __FUNCTION__);
945 prNetDevice = (struct net_device *) pvData;
947 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
950 //printk(KERN_INFO DRV_NAME"%s no glue info\n", __FUNCTION__);
954 mtk_wcn_hif_sdio_enable_irq(prGlueInfo->rHifInfo.cltCtx, MTK_WCN_BOOL_FALSE);
959 } /* end of glBusreeIrq() */
962 /*----------------------------------------------------------------------------*/
964 * \brief Read a 32-bit device register
966 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
967 * \param[in] u4Register Register offset
968 * \param[in] pu4Value Pointer to variable used to store read value
970 * \retval TRUE operation success
971 * \retval FALSE operation fail
973 /*----------------------------------------------------------------------------*/
976 IN P_GLUE_INFO_T prGlueInfo,
977 IN UINT_32 u4Register,
978 OUT PUINT_32 pu4Value
987 ret = mtk_wcn_hif_sdio_readl(prGlueInfo->rHifInfo.cltCtx, u4Register, (PUINT32) pu4Value);
990 sdio_claim_host(prGlueInfo->rHifInfo.func);
993 *pu4Value = sdio_readl(prGlueInfo->rHifInfo.func, u4Register, &ret);
996 sdio_release_host(prGlueInfo->rHifInfo.func);
1001 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_readl() reports error: %x", ret);
1002 DBGLOG(HAL, ERROR, ("sdio_readl() reports error: %x", ret));
1005 return (ret) ? FALSE : TRUE;
1006 } /* end of kalDevRegRead() */
1009 /*----------------------------------------------------------------------------*/
1011 * \brief Write a 32-bit device register
1013 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1014 * \param[in] u4Register Register offset
1015 * \param[in] u4Value Value to be written
1017 * \retval TRUE operation success
1018 * \retval FALSE operation fail
1020 /*----------------------------------------------------------------------------*/
1023 IN P_GLUE_INFO_T prGlueInfo,
1024 IN UINT_32 u4Register,
1032 #if MTK_WCN_HIF_SDIO
1033 ret = mtk_wcn_hif_sdio_writel(prGlueInfo->rHifInfo.cltCtx, u4Register, u4Value);
1035 if (!in_interrupt) {
1036 sdio_claim_host(prGlueInfo->rHifInfo.func);
1039 sdio_writel(prGlueInfo->rHifInfo.func, u4Value, u4Register, &ret);
1041 if (!in_interrupt) {
1042 sdio_release_host(prGlueInfo->rHifInfo.func);
1047 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writel() reports error: %x", ret);
1048 DBGLOG(HAL, ERROR, ("sdio_writel() reports error: %x", ret));
1051 return (ret) ? FALSE : TRUE;
1052 } /* end of kalDevRegWrite() */
1055 /*----------------------------------------------------------------------------*/
1057 * \brief Read device I/O port
1059 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1060 * \param[in] u2Port I/O port offset
1061 * \param[in] u2Len Length to be read
1062 * \param[out] pucBuf Pointer to read buffer
1063 * \param[in] u2ValidOutBufSize Length of the buffer valid to be accessed
1065 * \retval TRUE operation success
1066 * \retval FALSE operation fail
1068 /*----------------------------------------------------------------------------*/
1071 IN P_GLUE_INFO_T prGlueInfo,
1075 IN UINT_16 u2ValidOutBufSize
1078 P_GL_HIF_INFO_T prHifInfo = NULL;
1079 PUINT_8 pucDst = NULL;
1084 #if (MTK_WCN_HIF_SDIO == 0)
1085 struct sdio_func *prSdioFunc = NULL;
1089 //printk(KERN_INFO DRV_NAME"++kalDevPortRead++ buf:0x%p, port:0x%x, length:%d\n", pucBuf, u2Port, u2Len);
1093 prHifInfo = &prGlueInfo->rHifInfo;
1098 ASSERT(u2Len <= u2ValidOutBufSize);
1100 #if (MTK_WCN_HIF_SDIO == 0)
1101 prSdioFunc = prHifInfo->func;
1103 ASSERT(prSdioFunc->cur_blksize > 0);
1105 if (!in_interrupt) {
1106 sdio_claim_host(prSdioFunc);
1109 /* Split buffer into multiple single block to workaround hifsys */
1110 while (count >= prSdioFunc->cur_blksize) {
1111 count -= prSdioFunc->cur_blksize;
1114 if (count > 0 && bNum > 0) {
1119 ret = sdio_readsb(prSdioFunc, pucDst, u2Port, prSdioFunc->cur_blksize * bNum);
1122 /* ENE workaround */
1125 sdio_writel(prSdioFunc, 0x0, SDIO_X86_WORKAROUND_WRITE_MCR, &tmp);
1131 ret = sdio_readsb(prSdioFunc, pucDst, u2Port, count);
1134 if (!in_interrupt) {
1135 sdio_release_host(prSdioFunc);
1139 /* Split buffer into multiple single block to workaround hifsys */
1140 while (count >= (prGlueInfo->rHifInfo).prFuncInfo->blk_sz) {
1141 count -= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz);
1144 if (count > 0 && bNum > 0) {
1149 ret = mtk_wcn_hif_sdio_read_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucDst,
1150 ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz) * bNum);
1153 ret = mtk_wcn_hif_sdio_read_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucDst, count);
1158 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_readsb() reports error: %x", ret);
1159 DBGLOG(HAL, ERROR, ("sdio_readsb() reports error: %x", ret));
1162 return (ret) ? FALSE : TRUE;
1163 } /* end of kalDevPortRead() */
1166 /*----------------------------------------------------------------------------*/
1168 * \brief Write device I/O port
1170 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1171 * \param[in] u2Port I/O port offset
1172 * \param[in] u2Len Length to be write
1173 * \param[in] pucBuf Pointer to write buffer
1174 * \param[in] u2ValidInBufSize Length of the buffer valid to be accessed
1176 * \retval TRUE operation success
1177 * \retval FALSE operation fail
1179 /*----------------------------------------------------------------------------*/
1182 IN P_GLUE_INFO_T prGlueInfo,
1186 IN UINT_16 u2ValidInBufSize
1189 P_GL_HIF_INFO_T prHifInfo = NULL;
1190 PUINT_8 pucSrc = NULL;
1195 #if (MTK_WCN_HIF_SDIO == 0)
1196 struct sdio_func *prSdioFunc = NULL;
1200 //printk(KERN_INFO DRV_NAME"++kalDevPortWrite++ buf:0x%p, port:0x%x, length:%d\n", pucBuf, u2Port, u2Len);
1204 prHifInfo = &prGlueInfo->rHifInfo;
1209 ASSERT(u2Len <= u2ValidInBufSize);
1211 #if (MTK_WCN_HIF_SDIO == 0)
1212 prSdioFunc = prHifInfo->func;
1213 ASSERT(prSdioFunc->cur_blksize > 0);
1215 if (!in_interrupt) {
1216 sdio_claim_host(prSdioFunc);
1219 /* Split buffer into multiple single block to workaround hifsys */
1220 while (count >= prSdioFunc->cur_blksize) {
1221 count -= prSdioFunc->cur_blksize;
1224 if (count > 0 && bNum > 0) {
1228 if (bNum > 0) { // block mode
1229 ret = sdio_writesb(prSdioFunc, u2Port, pucSrc, prSdioFunc->cur_blksize * bNum);
1232 /* ENE workaround */
1235 sdio_writel(prSdioFunc, 0x0, SDIO_X86_WORKAROUND_WRITE_MCR, &tmp);
1242 ret = sdio_writesb(prSdioFunc, u2Port, pucSrc, count);
1245 if (!in_interrupt) {
1246 sdio_release_host(prSdioFunc);
1249 /* Split buffer into multiple single block to workaround hifsys */
1250 while (count >= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz)) {
1251 count -= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz);
1254 if (count > 0 && bNum > 0) {
1258 if (bNum > 0) { // block mode
1259 ret = mtk_wcn_hif_sdio_write_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucSrc,
1260 ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz) * bNum);
1263 ret = mtk_wcn_hif_sdio_write_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucSrc, count);
1268 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writesb() reports error: %x", ret);
1269 DBGLOG(HAL, ERROR, ("sdio_writesb() reports error: %x", ret));
1272 return (ret) ? FALSE : TRUE;
1273 } /* end of kalDevPortWrite() */
1276 /*----------------------------------------------------------------------------*/
1278 * \brief Write device I/O port in byte with CMD52
1280 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1281 * \param[in] u4Addr I/O port offset
1282 * \param[in] ucData Single byte of data to be written
1284 * \retval TRUE operation success
1285 * \retval FALSE operation fail
1287 /*----------------------------------------------------------------------------*/
1289 kalDevWriteWithSdioCmd52 (
1290 IN P_GLUE_INFO_T prGlueInfo,
1297 #if (MTK_WCN_HIF_SDIO == 0)
1298 if (!in_interrupt) {
1299 sdio_claim_host(prGlueInfo->rHifInfo.func);
1302 sdio_writeb(prGlueInfo->rHifInfo.func, ucData, u4Addr, &ret);
1304 if (!in_interrupt) {
1305 sdio_release_host(prGlueInfo->rHifInfo.func);
1308 ret = mtk_wcn_hif_sdio_writeb(prGlueInfo->rHifInfo.cltCtx, u4Addr, ucData);
1312 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writeb() reports error: %x", ret);
1313 DBGLOG(HAL, ERROR, ("sdio_writeb() reports error: %x", ret));
1316 return (ret) ? FALSE : TRUE;
1318 } /* end of kalDevWriteWithSdioCmd52() */
1323 IN P_GLUE_INFO_T prGlueInfo,
1324 IN UINT_32 ePowerMode