| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /* Copyright Statement:
- *
- * This software/firmware and related documentation ("MediaTek Software") are
- * protected under relevant copyright laws. The information contained herein
- * is confidential and proprietary to MediaTek Inc. and/or its licensors.
- * Without the prior written permission of MediaTek inc. and/or its licensors,
- * any reproduction, modification, use or disclosure of MediaTek Software,
- * and information contained herein, in whole or in part, shall be strictly prohibited.
- */
- /* MediaTek Inc. (C) 2018. All rights reserved.
- *
- * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
- * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
- * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
- * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
- * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
- * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * The following software/firmware and/or related documentation ("MediaTek Software")
- * have been modified by MediaTek Inc. All revisions are subject to any receiver\'s
- * applicable license agreements with MediaTek Inc.
- */
- #ifndef _MSDC_UTILS_H_
- #define _MSDC_UTILS_H_
- #include "msdc_cfg.h"
- #include "mmc_types.h"
- #if defined(MMC_MSDC_DRV_CTP)
- #include <common.h>
- #endif
- #if defined(MMC_MSDC_DRV_LK)
- #include <debug.h>
- #include <string.h> //For memcpy, memset
- #include <mt_gpt.h>
- #include <malloc.h>
- #endif
- /* Print function */
- #ifndef printf
- #define printf(fmt, args...) do{}while(0)
- #endif
- #if defined(MMC_MSDC_DRV_PRELOADER)
- #include "pal_log.h"
- #ifdef pal_log_err
- #define msdc_pr_err(fmt, args...) pal_log_err(fmt, ##args)
- #else
- #define msdc_pr_err(fmt, args...) print(fmt, ##args)
- #endif
- #ifdef pal_log_info
- #define msdc_pr_info(fmt, args...) pal_log_info(fmt, ##args)
- #else
- #define msdc_pr_info(fmt, args...) print(fmt, ##args)
- #endif
- #endif
- #if defined(MMC_MSDC_DRV_LK)
- #define msdc_pr_err(fmt, args...) dprintf(CRITICAL, fmt, ##args)
- #define msdc_pr_info(fmt, args...) dprintf(INFO, fmt, ##args)
- #endif
- #if defined(MMC_MSDC_DRV_CTP)
- #define msdc_pr_err(fmt, args...) printf(fmt, ##args)
- #define msdc_pr_info(fmt, args...) MSG(INF, fmt, ##args)
- #endif
- /* Debug message event */
- #define MSG_EVT_NONE 0x00000000 /* No event */
- #define MSG_EVT_DMA 0x00000001 /* DMA related event */
- #define MSG_EVT_CMD 0x00000002 /* MSDC CMD related event */
- #define MSG_EVT_RSP 0x00000004 /* MSDC CMD RSP related event */
- #define MSG_EVT_INT 0x00000008 /* MSDC INT event */
- #define MSG_EVT_CFG 0x00000010 /* MSDC CFG event */
- #define MSG_EVT_FUC 0x00000020 /* Function event */
- #define MSG_EVT_OPS 0x00000040 /* Read/Write operation event */
- #define MSG_EVT_FIO 0x00000080 /* FIFO operation event */
- #define MSG_EVT_PWR 0x00000100 /* MSDC power related event */
- #define MSG_EVT_INF 0x01000000 /* information event */
- #define MSG_EVT_WRN 0x02000000 /* Warning event */
- #define MSG_EVT_ERR 0x04000000 /* Error event */
- #define MSG_EVT_ALL 0xffffffff
- //#define MSG_EVT_MASK (MSG_EVT_ALL & ~MSG_EVT_DMA & ~MSG_EVT_WRN & ~MSG_EVT_RSP & ~MSG_EVT_INT & ~MSG_EVT_CMD & ~MSG_EVT_OPS)
- //#define MSG_EVT_MASK (MSG_EVT_ALL & ~MSG_EVT_FIO)
- //#define MSG_EVT_MASK (MSG_EVT_FIO)
- //#define MSG_EVT_MASK (MSG_EVT_ALL)
- //#define MSG_EVT_MASK (MSG_EVT_ALL & ~MSG_EVT_DMA & ~MSG_EVT_OPS & ~MSG_EVT_INT & MSG_EVT_WRN)
- #define MSG_EVT_MASK (MSG_EVT_ALL & ~MSG_EVT_DMA & ~MSG_EVT_OPS & ~MSG_EVT_FIO)
- //#define MSG_EVT_MASK (MSG_EVT_ERR)
- #if (MSDC_SLT==1) && (MSDC_SLT_MASK_LOG == 1)
- #undef MSG_EVT_MASK
- #define MSG_EVT_MASK (MSG_EVT_ALL & ~MSG_EVT_DMA & ~MSG_EVT_OPS & ~MSG_EVT_INT & ~MSG_EVT_WRN & ~MSG_EVT_INF & ~MSG_EVT_CMD & ~MSG_EVT_RSP)
- #endif
- #undef MSG
- #ifdef MSG_DEBUG
- #define MSG(evt, fmt, args...) \
- do { \
- if ((MSG_EVT_##evt) & MSG_EVT_MASK) { \
- msdc_pr_err(fmt, ##args); \
- } \
- } while(0)
- #define MSG_FUNC(f) MSG(FUC, "<FUNC>: %s\n", __FUNCTION__)
- #else
- #define MSG(evt, fmt, args...)
- #define MSG_FUNC(f)
- #endif
- #undef BUG_ON
- #define BUG_ON(x) \
- do { \
- if (x) { \
- while(1); \
- } \
- }while(0)
- #undef WARN_ON
- #define WARN_ON(x) \
- do { \
- if (x) { \
- MSG(WRN, "[WARN] %s LINE:%d\n", #x, __LINE__); \
- } \
- }while(0)
- #define ERR_EXIT(expr, ret, expected_ret) \
- do { \
- (ret) = (expr);\
- if ((ret) != (expected_ret)) { \
- goto exit; \
- } \
- } while(0)
- #undef ARRAY_SIZE
- #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
- extern unsigned int msdc_uffs(unsigned int x);
- extern unsigned int msdc_ntohl(unsigned int n);
- extern void msdc_get_field(volatile u32 *reg, u32 field, u32 *val);
- #define uffs(x) msdc_uffs(x)
- #define ntohl(n) msdc_ntohl(n)
- #define get_field(r,f,v) msdc_get_field((volatile u32*)r,f,&v)
- #if defined(MMC_MSDC_DRV_CTP)
- #include <kal_mem.h>
- #define memcpy(dst,src,sz) KAL_memcpy(dst, src, sz)
- #define memset(p,v,s) KAL_memset(p, v, s)
- #define free(p) KAL_free(p)
- #define malloc(sz) KAL_malloc(sz, 4, KAL_USER_MSDC)
- #endif
- #ifndef min
- #define min(x, y) (x < y ? x : y)
- #endif
- #ifndef max
- #define max(x, y) (x > y ? x : y)
- #endif
- #if defined(MMC_MSDC_DRV_CTP)
- #if !defined(FPGA_PLATFORM)
- #define udelay(us) do{GPT_Delay_us(us);}while(0)
- #define mdelay(ms) do{GPT_Delay_ms(ms);}while(0)
- #else
- #define udelay(us) \
- do { \
- volatile int count = us * 10; \
- while (count--); \
- }while(0)
- #define udelay1(us) \
- do{ \
- MSDC_WRITE32(0x10008040,0x31);\
- MSDC_WRITE32(0x10008044,0x0);\
- u32 test_t1 = MSDC_READ32(0x10008048); \
- u32 test_t2; \
- do{ \
- test_t2= MSDC_READ32(0x10008048); \
- } \
- while((test_t2-test_t1) < us * 6);\
- }while(0)
- #define mdelay(ms) \
- do { \
- unsigned long i; \
- for (i = 0; i < ms; i++) \
- udelay(1000); \
- }while(0)
- #define mdelay1(ms) \
- do { \
- unsigned long i; \
- for (i = 0; i < ms; i++) \
- udelay1(1000); \
- }while(0)
- #endif
- #endif
- #define WAIT_COND(cond,tmo,left) \
- do { \
- u32 t = tmo; \
- while (1) { \
- if ((cond) || (t == 0)) break; \
- if (t > 0) {udelay(1); t--;} \
- } \
- left = t; \
- }while(0)
- #endif /* _MSDC_UTILS_H_ */
|