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>
154 #include <asm/memory.h>
158 #include "mt6620_reg.h"
159 #elif defined(MT5931)
160 #include "mt5931_reg.h"
161 #elif defined(MT6628)
162 #include "mt6628_reg.h"
165 #if CFG_DBG_GPIO_PINS/* FIXME: move to platform or custom header */
166 #include <mach/mt6516_gpio.h>
169 /*******************************************************************************
171 ********************************************************************************
174 #define HIF_SDIO_ERR_TITLE_STR "["CHIP_NAME"] SDIO Access Error!"
175 #define HIF_SDIO_ERR_DESC_STR "**SDIO Access Error**\n"
181 * function prototypes
186 mtk_sdio_probe(MTK_WCN_HIF_SDIO_CLTCTX, const MTK_WCN_HIF_SDIO_FUNCINFO *);
189 mtk_sdio_remove(MTK_WCN_HIF_SDIO_CLTCTX);
190 static INT32 mtk_sdio_interrupt(MTK_WCN_HIF_SDIO_CLTCTX);
193 * sdio function info table
196 static MTK_WCN_HIF_SDIO_FUNCINFO funcInfo[] = {
198 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x020a, 0x1, 512) },
199 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x020c, 0x2, 512) },
200 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x018a, 0x1, 512) },
201 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x018c, 0x2, 512) },
202 #elif defined(MT5931)
203 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x5931, 0x1, 512) },
204 #elif defined(MT6628)
205 { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x6628, 0x1, 512) },
210 static MTK_WCN_HIF_SDIO_CLTINFO cltInfo = {
211 .func_tbl = funcInfo,
212 .func_tbl_size = sizeof(funcInfo)/sizeof(MTK_WCN_HIF_SDIO_FUNCINFO),
213 .hif_clt_probe = mtk_sdio_probe,
214 .hif_clt_remove = mtk_sdio_remove,
215 .hif_clt_irq = mtk_sdio_interrupt,
220 static const struct sdio_device_id mtk_sdio_ids[] = {
222 { SDIO_DEVICE(0x037a, 0x020a) }, /* Not an SDIO standard class device */
223 { SDIO_DEVICE(0x037a, 0x020b) }, /* Not an SDIO standard class device */
224 { SDIO_DEVICE(0x037a, 0x020c) }, /* Not an SDIO standard class device */
225 #elif defined(MT5931)
226 { SDIO_DEVICE(0x037a, 0x5931) }, /* Not an SDIO standard class device */
227 #elif defined(MT6628)
228 { SDIO_DEVICE(0x037a, 0x6628) }, /* Not an SDIO standard class device */
230 { /* end: all zeroes */ },
233 MODULE_DEVICE_TABLE(sdio, mtk_sdio_ids);
237 /*******************************************************************************
239 ********************************************************************************
243 /*******************************************************************************
244 * P U B L I C D A T A
245 ********************************************************************************
248 /*******************************************************************************
249 * P R I V A T E D A T A
250 ********************************************************************************
252 static probe_card pfWlanProbe = NULL;
253 static remove_card pfWlanRemove = NULL;
256 #if (MTK_WCN_HIF_SDIO == 0)
257 static struct sdio_driver mtk_sdio_driver = {
258 .name = "wlan", /* "MTK SDIO WLAN Driver" */
259 .id_table = mtk_sdio_ids,
266 #if CFG_DBG_GPIO_PINS
269 UINT_32 dbgPinSTP[] = {
270 GPIO_PLATFORM(33)/* CMFLASH, IDX_ERR J613 */
271 , GPIO_PLATFORM(62)/* EINT3, IDX_TX_THREAD */
272 , GPIO_PLATFORM(80)/* SPI_CS_N, IDX_TX_REQ J613 */
273 , GPIO_PLATFORM(81)/* SPI_SCK, IDX_TX_PORT_WRITE J613 */
274 , GPIO_PLATFORM(17) /* CMRST, IDX_STP_MTX_BT J618 */
275 , GPIO_PLATFORM(18) /* CMPDN, IDX_STP_MTX_FM J613 */
276 , GPIO_PLATFORM(19) /* CMVREF,IDX_STP_MTX_GPS J613 */
277 , GPIO_INVALID /* REMOVED, IDX_STP_MTX_WIFI */
278 , GPIO_INVALID /* REMOVED, IDX_STP_MTX_WMT */
279 , GPIO_PLATFORM(135) /* SCL2, IDX_LOOP_CNT J616 */
280 , GPIO_PLATFORM(136) /* SDA2, IDX_NO_BUF J616 */
281 , GPIO_PLATFORM(30) /* CAM_MECHSH0, IDX_BT_TX, J613 low-active */
282 , GPIO_PLATFORM(31) /* CAM_MECHSH1, IDX_BT_RX, J613 low-active */
283 , GPIO_PLATFORM(124) /* GPS_PWR_EN, ThreadDSPIn [GPS] */
284 , GPIO_PLATFORM(125) /* GPS_SYNC, mtk_sys_msg_recv [GPS] */
285 , GPIO_PLATFORM(21) /* GPS_EINT8, dump_nmea_data [GPS] */
286 , GPIO_PLATFORM(29) /* CAM_STROBE, IDX_GPS_TX, J613 low-active */
287 , GPIO_PLATFORM(20) /*CMHREF, J613 UNUSED */
288 // , GPIO_6516(64) /* EINT5, REMOVED!!! for MT6620-Wi-Fi Int */
289 // , GPIO_6516(122) /* BT_PWR_EN, REMOVED!!! for MT6620-PMU_EN */
290 // , GPIO_6516(123) /* BT_RESET, REMOVED!!! for MT6620-RST */
293 /*******************************************************************************
295 ********************************************************************************
298 /*******************************************************************************
299 * F U N C T I O N D E C L A R A T I O N S
300 ********************************************************************************
303 /*******************************************************************************
305 ********************************************************************************
307 #if CFG_DBG_GPIO_PINS
308 void debug_gpio_init(void)
312 for (i = 0; i < sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]); ++i) {
313 if (GPIO_INVALID == dbgPinSTP[i]) {
316 //printk(KERN_INFO "[%s] %ld \n", __FUNCTION__, dbgPinSTP[i]);
317 mt_set_gpio_pull_enable(dbgPinSTP[i], 0); /* disable pull */
318 mt_set_gpio_dir(dbgPinSTP[i], GPIO_DIR_OUT); /* set output */
319 mt_set_gpio_mode(dbgPinSTP[i], GPIO_MODE_00); /* set gpio mode */
321 /* toggle twice to check if ok: */
322 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ZERO); /* tie low */
323 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ONE); /* tie high*/
324 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ZERO); /* tie low */
325 mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ONE); /* tie high*/
327 //printk(KERN_INFO "[%s] initialization ok \n", __FUNCTION__);
330 void debug_gpio_deinit(void)
333 for (i = 0; i < sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]); ++i) {
334 if (GPIO_INVALID == dbgPinSTP[i]) {
337 //printk(KERN_INFO "[%s] %ld \n", __FUNCTION__, dbgPinSTP[i]);
338 mt_set_gpio_dir(dbgPinSTP[i], GPIO_DIR_IN);
341 //printk(KERN_INFO "[%s] k\n", __FUNCTION__);
344 void mtk_wcn_stp_debug_gpio_assert(UINT_32 dwIndex, UINT_32 dwMethod)
348 if (dwIndex >= (sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]))) {
349 //printk(KERN_INFO "[%s] invalid dwIndex(%ld) \n", __FUNCTION__, dwIndex);
353 if (dwIndex > IDX_STP_MAX) {
354 //printk(KERN_INFO "[%s] dwIndex(%ld) > IDX_STP_MAX(%d) \n", __FUNCTION__, dwIndex, IDX_STP_MAX);
357 if (GPIO_INVALID == dbgPinSTP[dwIndex]) {
361 if (dwMethod & DBG_TIE_DIR) {
362 if (dwMethod & DBG_HIGH) {
363 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ONE);
366 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ZERO);
371 if (dwMethod & DBG_TOGGLE(0)) {
372 for (i = 0; i < DBG_TOGGLE_NUM(dwMethod); ++i) {
373 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ZERO);
374 mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ONE);
383 /*----------------------------------------------------------------------------*/
385 * \brief This function is a SDIO interrupt callback function
387 * \param[in] func pointer to SDIO handle
391 /*----------------------------------------------------------------------------*/
395 static INT32 mtk_sdio_interrupt(MTK_WCN_HIF_SDIO_CLTCTX cltCtx)
397 P_GLUE_INFO_T prGlueInfo = NULL;
400 prGlueInfo = mtk_wcn_hif_sdio_get_drvdata(cltCtx);
405 //printk(KERN_INFO DRV_NAME"No glue info in mtk_sdio_interrupt()\n");
406 return (-HIF_SDIO_ERR_FAIL);
409 if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
410 //printk(KERN_INFO DRV_NAME"GLUE_FLAG_HALT skip INT\n");
411 ret = mtk_wcn_hif_sdio_writel(cltCtx, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
415 ret = mtk_wcn_hif_sdio_writel(cltCtx, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
417 set_bit (GLUE_FLAG_INT_BIT, &prGlueInfo->u4Flag);
419 /* when we got sdio interrupt, we wake up the tx servie thread*/
420 wake_up_interruptible(&prGlueInfo->waitq);
427 static unsigned int in_interrupt = 0;
429 static void mtk_sdio_interrupt(struct sdio_func *func)
431 P_GLUE_INFO_T prGlueInfo = NULL;
435 prGlueInfo = sdio_get_drvdata(func);
439 //printk(KERN_INFO DRV_NAME"No glue info in mtk_sdio_interrupt()\n");
443 if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
444 sdio_writel(prGlueInfo->rHifInfo.func, WHLPCR_INT_EN_CLR, MCR_WHLPCR, &ret);
445 //printk(KERN_INFO DRV_NAME"GLUE_FLAG_HALT skip INT\n");
449 sdio_writel(prGlueInfo->rHifInfo.func, WHLPCR_INT_EN_CLR, MCR_WHLPCR, &ret);
452 wlanISR(prGlueInfo->prAdapter, TRUE);
454 if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
455 /* Should stop now... skip pending interrupt */
456 //printk(KERN_INFO DRV_NAME"ignore pending interrupt\n");
459 wlanIST(prGlueInfo->prAdapter);
463 set_bit (GLUE_FLAG_INT_BIT, &prGlueInfo->u4Flag);
465 /* when we got sdio interrupt, we wake up the tx servie thread*/
466 wake_up_interruptible(&prGlueInfo->waitq);
470 /*----------------------------------------------------------------------------*/
472 * \brief This function is a SDIO probe function
474 * \param[in] func pointer to SDIO handle
475 * \param[in] id pointer to SDIO device id table
479 /*----------------------------------------------------------------------------*/
483 // FIXME: global variable
484 static const MTK_WCN_HIF_SDIO_FUNCINFO *prFunc;
488 mtk_sdio_probe(MTK_WCN_HIF_SDIO_CLTCTX cltCtx, const MTK_WCN_HIF_SDIO_FUNCINFO *prFuncInfo)
490 INT32 ret = HIF_SDIO_ERR_SUCCESS;
494 if (pfWlanProbe((PVOID) &cltCtx) != WLAN_STATUS_SUCCESS) {
495 //printk(KERN_WARNING DRV_NAME"pfWlanProbe fail!call pfWlanRemove()\n");
497 ret = -(HIF_SDIO_ERR_FAIL);
499 //printk(KERN_INFO DRV_NAME"mtk_wifi_sdio_probe() done(%d)\n", ret);
504 static int mtk_sdio_probe (
505 struct sdio_func *func,
506 const struct sdio_device_id *id
512 //printk(KERN_INFO DRV_NAME "mtk_sdio_probe()\n");
517 //printk(KERN_INFO DRV_NAME "Basic struct size checking...\n");
518 //printk(KERN_INFO DRV_NAME "sizeof(struct device) = %d\n", sizeof(struct device));
519 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_host) = %d\n", sizeof(struct mmc_host));
520 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_card) = %d\n", sizeof(struct mmc_card));
521 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_driver) = %d\n", sizeof(struct mmc_driver));
522 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_data) = %d\n", sizeof(struct mmc_data));
523 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_command) = %d\n", sizeof(struct mmc_command));
524 //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_request) = %d\n", sizeof(struct mmc_request));
525 //printk(KERN_INFO DRV_NAME "sizeof(struct sdio_func) = %d\n", sizeof(struct sdio_func));
527 //printk(KERN_INFO DRV_NAME "Card information checking...\n");
528 //printk(KERN_INFO DRV_NAME "func = 0x%p\n", func);
529 //printk(KERN_INFO DRV_NAME "Number of info = %d:\n", func->card->num_info);
531 for (i = 0; i < func->card->num_info; i++) {
532 //printk(KERN_INFO DRV_NAME "info[%d]: %s\n", i, func->card->info[i]);
535 sdio_claim_host(func);
536 ret = sdio_enable_func(func);
537 sdio_release_host(func);
540 //printk(KERN_INFO DRV_NAME"sdio_enable_func failed!\n");
543 //printk(KERN_INFO DRV_NAME"sdio_enable_func done!\n");
545 if (pfWlanProbe((PVOID)func) != WLAN_STATUS_SUCCESS) {
546 //printk(KERN_WARNING DRV_NAME"pfWlanProbe fail!call pfWlanRemove()\n");
551 #if CFG_DBG_GPIO_PINS
552 //printk(KERN_INFO "[%s] init debug gpio, 20100815 \n", __FUNCTION__);
553 /* Debug pins initialization */
559 //printk(KERN_INFO DRV_NAME"mtk_sdio_probe() done(%d)\n", ret);
567 mtk_sdio_remove(MTK_WCN_HIF_SDIO_CLTCTX cltCtx)
569 INT32 ret = HIF_SDIO_ERR_SUCCESS;
570 //printk(KERN_INFO DRV_NAME"pfWlanRemove done\n");
578 struct sdio_func *func
581 //printk(KERN_INFO DRV_NAME"mtk_sdio_remove()\n");
583 #if CFG_DBG_GPIO_PINS
584 //printk(KERN_INFO "[%s] deinit debug gpio \n", __FUNCTION__);
589 //printk(KERN_INFO DRV_NAME"pfWlanRemove done\n");
592 sdio_claim_host(func);
593 sdio_disable_func(func);
594 //printk(KERN_INFO DRV_NAME"sdio_disable_func() done\n");
595 sdio_release_host(func);
597 //printk(KERN_INFO DRV_NAME"mtk_sdio_remove() done\n");
601 #if (MTK_WCN_HIF_SDIO == 0)
604 struct device * pDev,
608 //printk(KERN_INFO "mtk_sdio: mtk_sdio_suspend dev(0x%p)\n", pDev);
609 //printk(KERN_INFO "mtk_sdio: MediaTek SDIO WLAN driver\n");
614 int mtk_sdio_resume (
618 //printk(KERN_INFO "mtk_sdio: mtk_sdio_resume dev(0x%p)\n", pDev);
625 /*----------------------------------------------------------------------------*/
627 * \brief This function will register sdio bus to the os
629 * \param[in] pfProbe Function pointer to detect card
630 * \param[in] pfRemove Function pointer to remove card
632 * \return The result of registering sdio bus
634 /*----------------------------------------------------------------------------*/
646 //printk(KERN_INFO "mtk_sdio: MediaTek SDIO WLAN driver\n");
647 //printk(KERN_INFO "mtk_sdio: Copyright MediaTek Inc.\n");
649 pfWlanProbe = pfProbe;
650 pfWlanRemove = pfRemove;
653 /* register MTK sdio client */
654 ret = ((mtk_wcn_hif_sdio_client_reg(&cltInfo) == HIF_SDIO_ERR_SUCCESS) ? WLAN_STATUS_SUCCESS : WLAN_STATUS_FAILURE);
656 mtk_sdio_driver.probe = mtk_sdio_probe;
657 mtk_sdio_driver.remove = mtk_sdio_remove;
659 mtk_sdio_driver.drv.suspend = mtk_sdio_suspend;
660 mtk_sdio_driver.drv.resume = mtk_sdio_resume;
662 ret = (sdio_register_driver(&mtk_sdio_driver) == 0) ? WLAN_STATUS_SUCCESS : WLAN_STATUS_FAILURE;
666 } /* end of glRegisterBus() */
669 /*----------------------------------------------------------------------------*/
671 * \brief This function will unregister sdio bus to the os
673 * \param[in] pfRemove Function pointer to remove card
677 /*----------------------------------------------------------------------------*/
687 /* unregister MTK sdio client */
688 mtk_wcn_hif_sdio_client_unreg(&cltInfo);
690 sdio_unregister_driver(&mtk_sdio_driver);
694 } /* end of glUnregisterBus() */
697 /*----------------------------------------------------------------------------*/
699 * \brief This function stores hif related info, which is initialized before.
701 * \param[in] prGlueInfo Pointer to glue info structure
702 * \param[in] u4Cookie Pointer to UINT_32 memory base variable for _HIF_HPI
706 /*----------------------------------------------------------------------------*/
709 P_GLUE_INFO_T prGlueInfo,
713 P_GL_HIF_INFO_T prHif = NULL;
715 prHif = &prGlueInfo->rHifInfo;
718 //prHif->prFuncInfo = ((MTK_WCN_HIF_SDIO_FUNCINFO *) u4Cookie);
719 prHif->prFuncInfo = prFunc;
720 prHif->cltCtx = *((MTK_WCN_HIF_SDIO_CLTCTX *) u4Cookie);
721 mtk_wcn_hif_sdio_set_drvdata(prHif->cltCtx, prGlueInfo);
724 prHif->func = (struct sdio_func *) u4Cookie;
726 //printk(KERN_INFO DRV_NAME"prHif->func->dev = 0x%p\n", &prHif->func->dev);
727 //printk(KERN_INFO DRV_NAME"prHif->func->vendor = 0x%04X\n", prHif->func->vendor);
728 //printk(KERN_INFO DRV_NAME"prHif->func->device = 0x%04X\n", prHif->func->device);
729 //printk(KERN_INFO DRV_NAME"prHif->func->func = 0x%04X\n", prHif->func->num);
731 sdio_set_drvdata(prHif->func, prGlueInfo);
733 SET_NETDEV_DEV(prGlueInfo->prDevHandler, &prHif->func->dev);
737 } /* end of glSetHifInfo() */
739 /*----------------------------------------------------------------------------*/
741 * \brief This function clears hif related info.
743 * \param[in] prGlueInfo Pointer to glue info structure
747 /*----------------------------------------------------------------------------*/
750 P_GLUE_INFO_T prGlueInfo
753 //P_GL_HIF_INFO_T prHif = NULL;
754 //ASSERT(prGlueInfo);
755 //prHif = &prGlueInfo->rHifInfo;
758 } /* end of glClearHifInfo() */
761 /*----------------------------------------------------------------------------*/
763 * \brief Initialize bus operation and hif related information, request resources.
765 * \param[out] pvData A pointer to HIF-specific data type buffer.
766 * For eHPI, pvData is a pointer to UINT_32 type and stores a
767 * mapped base address.
771 /*----------------------------------------------------------------------------*/
777 #if (MTK_WCN_HIF_SDIO == 0)
779 struct sdio_func *func = NULL;
783 func = (struct sdio_func *) pvData;
785 sdio_claim_host(func);
786 ret = sdio_set_block_size(func, 512);
787 sdio_release_host(func);
790 //printk(KERN_INFO DRV_NAME"sdio_set_block_size 512 failed!\n");
793 //printk(KERN_INFO DRV_NAME"sdio_set_block_size 512 done!\n");
796 //printk(KERN_INFO DRV_NAME"param: func->cur_blksize(%d)\n", func->cur_blksize);
797 //printk(KERN_INFO DRV_NAME"param: func->max_blksize(%d)\n", func->max_blksize);
798 //printk(KERN_INFO DRV_NAME"param: func->card->host->max_blk_size(%d)\n", func->card->host->max_blk_size);
799 //printk(KERN_INFO DRV_NAME"param: func->card->host->max_blk_count(%d)\n", func->card->host->max_blk_count);
802 } /* end of glBusInit() */
805 /*----------------------------------------------------------------------------*/
807 * \brief Stop bus operation and release resources.
809 * \param[in] pvData A pointer to struct net_device.
813 /*----------------------------------------------------------------------------*/
821 } /* end of glBusRelease() */
824 /*----------------------------------------------------------------------------*/
826 * \brief Setup bus interrupt operation and interrupt handler for os.
828 * \param[in] pvData A pointer to struct net_device.
829 * \param[in] pfnIsr A pointer to interrupt handler function.
830 * \param[in] pvCookie Private data for pfnIsr function.
832 * \retval WLAN_STATUS_SUCCESS if success
833 * NEGATIVE_VALUE if fail
835 /*----------------------------------------------------------------------------*/
845 #if (MTK_WCN_HIF_SDIO == 0)
846 struct net_device *prNetDevice = NULL;
847 P_GLUE_INFO_T prGlueInfo = NULL;
848 P_GL_HIF_INFO_T prHifInfo = NULL;
854 prNetDevice = (struct net_device *) pvData;
855 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
861 prHifInfo = &prGlueInfo->rHifInfo;
863 sdio_claim_host(prHifInfo->func);
864 ret = sdio_claim_irq(prHifInfo->func, mtk_sdio_interrupt);
865 sdio_release_host(prHifInfo->func);
868 struct net_device *prNetDevice = NULL;
869 P_GLUE_INFO_T prGlueInfo = NULL;
875 prNetDevice = (struct net_device *) pvData;
877 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
883 mtk_wcn_hif_sdio_enable_irq(prGlueInfo->rHifInfo.cltCtx, MTK_WCN_BOOL_TRUE);
887 } /* end of glBusSetIrq() */
890 /*----------------------------------------------------------------------------*/
892 * \brief Stop bus interrupt operation and disable interrupt handling for os.
894 * \param[in] pvData A pointer to struct net_device.
895 * \param[in] pvCookie Private data for pfnIsr function.
899 /*----------------------------------------------------------------------------*/
906 #if (MTK_WCN_HIF_SDIO == 0)
907 struct net_device *prNetDevice = NULL;
908 P_GLUE_INFO_T prGlueInfo = NULL;
909 P_GL_HIF_INFO_T prHifInfo = NULL;
914 //printk(KERN_INFO DRV_NAME"%s null pvData\n", __FUNCTION__);
917 prNetDevice = (struct net_device *) pvData;
918 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
921 //printk(KERN_INFO DRV_NAME"%s no glue info\n", __FUNCTION__);
925 prHifInfo = &prGlueInfo->rHifInfo;
927 sdio_claim_host(prHifInfo->func);
928 ret = sdio_release_irq(prHifInfo->func);
929 sdio_release_host(prHifInfo->func);
932 struct net_device *prNetDevice = NULL;
933 P_GLUE_INFO_T prGlueInfo = NULL;
937 //printk(KERN_INFO DRV_NAME"%s null pvData\n", __FUNCTION__);
940 prNetDevice = (struct net_device *) pvData;
942 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
945 //printk(KERN_INFO DRV_NAME"%s no glue info\n", __FUNCTION__);
949 mtk_wcn_hif_sdio_enable_irq(prGlueInfo->rHifInfo.cltCtx, MTK_WCN_BOOL_FALSE);
954 } /* end of glBusreeIrq() */
957 /*----------------------------------------------------------------------------*/
959 * \brief Read a 32-bit device register
961 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
962 * \param[in] u4Register Register offset
963 * \param[in] pu4Value Pointer to variable used to store read value
965 * \retval TRUE operation success
966 * \retval FALSE operation fail
968 /*----------------------------------------------------------------------------*/
971 IN P_GLUE_INFO_T prGlueInfo,
972 IN UINT_32 u4Register,
973 OUT PUINT_32 pu4Value
982 ret = mtk_wcn_hif_sdio_readl(prGlueInfo->rHifInfo.cltCtx, u4Register, (PUINT32) pu4Value);
985 sdio_claim_host(prGlueInfo->rHifInfo.func);
988 *pu4Value = sdio_readl(prGlueInfo->rHifInfo.func, u4Register, &ret);
991 sdio_release_host(prGlueInfo->rHifInfo.func);
996 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_readl() reports error: %x", ret);
997 DBGLOG(HAL, ERROR, ("sdio_readl() reports error: %x", ret));
1000 return (ret) ? FALSE : TRUE;
1001 } /* end of kalDevRegRead() */
1004 /*----------------------------------------------------------------------------*/
1006 * \brief Write a 32-bit device register
1008 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1009 * \param[in] u4Register Register offset
1010 * \param[in] u4Value Value to be written
1012 * \retval TRUE operation success
1013 * \retval FALSE operation fail
1015 /*----------------------------------------------------------------------------*/
1018 IN P_GLUE_INFO_T prGlueInfo,
1019 IN UINT_32 u4Register,
1027 #if MTK_WCN_HIF_SDIO
1028 ret = mtk_wcn_hif_sdio_writel(prGlueInfo->rHifInfo.cltCtx, u4Register, u4Value);
1030 if (!in_interrupt) {
1031 sdio_claim_host(prGlueInfo->rHifInfo.func);
1034 sdio_writel(prGlueInfo->rHifInfo.func, u4Value, u4Register, &ret);
1036 if (!in_interrupt) {
1037 sdio_release_host(prGlueInfo->rHifInfo.func);
1042 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writel() reports error: %x", ret);
1043 DBGLOG(HAL, ERROR, ("sdio_writel() reports error: %x", ret));
1046 return (ret) ? FALSE : TRUE;
1047 } /* end of kalDevRegWrite() */
1050 /*----------------------------------------------------------------------------*/
1052 * \brief Read device I/O port
1054 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1055 * \param[in] u2Port I/O port offset
1056 * \param[in] u2Len Length to be read
1057 * \param[out] pucBuf Pointer to read buffer
1058 * \param[in] u2ValidOutBufSize Length of the buffer valid to be accessed
1060 * \retval TRUE operation success
1061 * \retval FALSE operation fail
1063 /*----------------------------------------------------------------------------*/
1066 IN P_GLUE_INFO_T prGlueInfo,
1070 IN UINT_16 u2ValidOutBufSize
1073 P_GL_HIF_INFO_T prHifInfo = NULL;
1074 PUINT_8 pucDst = NULL;
1079 #if (MTK_WCN_HIF_SDIO == 0)
1080 struct sdio_func *prSdioFunc = NULL;
1084 //printk(KERN_INFO DRV_NAME"++kalDevPortRead++ buf:0x%p, port:0x%x, length:%d\n", pucBuf, u2Port, u2Len);
1088 prHifInfo = &prGlueInfo->rHifInfo;
1093 ASSERT(u2Len <= u2ValidOutBufSize);
1095 #if (MTK_WCN_HIF_SDIO == 0)
1096 prSdioFunc = prHifInfo->func;
1098 ASSERT(prSdioFunc->cur_blksize > 0);
1100 if (!in_interrupt) {
1101 sdio_claim_host(prSdioFunc);
1104 /* Split buffer into multiple single block to workaround hifsys */
1105 while (count >= prSdioFunc->cur_blksize) {
1106 count -= prSdioFunc->cur_blksize;
1109 if (count > 0 && bNum > 0) {
1114 ret = sdio_readsb(prSdioFunc, pucDst, u2Port, prSdioFunc->cur_blksize * bNum);
1117 /* ENE workaround */
1120 sdio_writel(prSdioFunc, 0x0, SDIO_X86_WORKAROUND_WRITE_MCR, &tmp);
1126 ret = sdio_readsb(prSdioFunc, pucDst, u2Port, count);
1129 if (!in_interrupt) {
1130 sdio_release_host(prSdioFunc);
1134 /* Split buffer into multiple single block to workaround hifsys */
1135 while (count >= (prGlueInfo->rHifInfo).prFuncInfo->blk_sz) {
1136 count -= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz);
1139 if (count > 0 && bNum > 0) {
1144 ret = mtk_wcn_hif_sdio_read_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucDst,
1145 ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz) * bNum);
1148 ret = mtk_wcn_hif_sdio_read_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucDst, (count+3)&~0x3U);
1153 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_readsb() reports error: %x", ret);
1154 DBGLOG(HAL, ERROR, ("sdio_readsb() reports error: %x", ret));
1157 return (ret) ? FALSE : TRUE;
1158 } /* end of kalDevPortRead() */
1161 /*----------------------------------------------------------------------------*/
1163 * \brief Write device I/O port
1165 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1166 * \param[in] u2Port I/O port offset
1167 * \param[in] u2Len Length to be write
1168 * \param[in] pucBuf Pointer to write buffer
1169 * \param[in] u2ValidInBufSize Length of the buffer valid to be accessed
1171 * \retval TRUE operation success
1172 * \retval FALSE operation fail
1174 /*----------------------------------------------------------------------------*/
1177 IN P_GLUE_INFO_T prGlueInfo,
1181 IN UINT_16 u2ValidInBufSize
1184 P_GL_HIF_INFO_T prHifInfo = NULL;
1185 PUINT_8 pucSrc = NULL;
1190 #if (MTK_WCN_HIF_SDIO == 0)
1191 struct sdio_func *prSdioFunc = NULL;
1195 //printk(KERN_INFO DRV_NAME"++kalDevPortWrite++ buf:0x%p, port:0x%x, length:%d\n", pucBuf, u2Port, u2Len);
1199 prHifInfo = &prGlueInfo->rHifInfo;
1204 ASSERT(u2Len <= u2ValidInBufSize);
1206 #if (MTK_WCN_HIF_SDIO == 0)
1207 prSdioFunc = prHifInfo->func;
1208 ASSERT(prSdioFunc->cur_blksize > 0);
1210 if (!in_interrupt) {
1211 sdio_claim_host(prSdioFunc);
1214 /* Split buffer into multiple single block to workaround hifsys */
1215 while (count >= prSdioFunc->cur_blksize) {
1216 count -= prSdioFunc->cur_blksize;
1219 if (count > 0 && bNum > 0) {
1223 if (bNum > 0) { // block mode
1224 ret = sdio_writesb(prSdioFunc, u2Port, pucSrc, prSdioFunc->cur_blksize * bNum);
1227 /* ENE workaround */
1230 sdio_writel(prSdioFunc, 0x0, SDIO_X86_WORKAROUND_WRITE_MCR, &tmp);
1237 ret = sdio_writesb(prSdioFunc, u2Port, pucSrc, count);
1240 if (!in_interrupt) {
1241 sdio_release_host(prSdioFunc);
1244 /* Split buffer into multiple single block to workaround hifsys */
1245 while (count >= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz)) {
1246 count -= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz);
1249 if (count > 0 && bNum > 0) {
1253 if (bNum > 0) { // block mode
1254 ret = mtk_wcn_hif_sdio_write_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucSrc,
1255 ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz) * bNum);
1258 ret = mtk_wcn_hif_sdio_write_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucSrc, (count+3)&~0x3U);
1263 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writesb() reports error: %x", ret);
1264 DBGLOG(HAL, ERROR, ("sdio_writesb() reports error: %x", ret));
1267 return (ret) ? FALSE : TRUE;
1268 } /* end of kalDevPortWrite() */
1271 /*----------------------------------------------------------------------------*/
1273 * \brief Write device I/O port in byte with CMD52
1275 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1276 * \param[in] u4Addr I/O port offset
1277 * \param[in] ucData Single byte of data to be written
1279 * \retval TRUE operation success
1280 * \retval FALSE operation fail
1282 /*----------------------------------------------------------------------------*/
1284 kalDevWriteWithSdioCmd52 (
1285 IN P_GLUE_INFO_T prGlueInfo,
1292 #if (MTK_WCN_HIF_SDIO == 0)
1293 if (!in_interrupt) {
1294 sdio_claim_host(prGlueInfo->rHifInfo.func);
1297 sdio_writeb(prGlueInfo->rHifInfo.func, ucData, u4Addr, &ret);
1299 if (!in_interrupt) {
1300 sdio_release_host(prGlueInfo->rHifInfo.func);
1303 ret = mtk_wcn_hif_sdio_writeb(prGlueInfo->rHifInfo.cltCtx, u4Addr, ucData);
1307 kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writeb() reports error: %x", ret);
1308 DBGLOG(HAL, ERROR, ("sdio_writeb() reports error: %x", ret));
1311 return (ret) ? FALSE : TRUE;
1313 } /* end of kalDevWriteWithSdioCmd52() */
1318 IN P_GLUE_INFO_T prGlueInfo,
1319 IN UINT_32 ePowerMode