Initial commit: Linux kernel 4.19 for Unplugged OS

This commit is contained in:
ziv committed 2025-10-06 13:52:42 +00:00
commit d30235b04c
80519 files changed
+35800681

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
config MTK_BTIF
tristate "MediaTek BTIF Driver"
help
MTK connectivity BTIF driver for A/D die
and not supported in combo project
It is used to config whether BTIF driver
is supported or not.
+38
View File
@@ -0,0 +1,38 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# BTIF driver for AD DIE
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
#subdir-ccflags-y can be used in 2.6.34 in the future
MTK_PLATFORM := $(subst ",,$(CONFIG_MTK_PLATFORM))
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat/$(MTK_PLATFORM)/include
subdir-ccflags-y += -I$(srctree)/arch/arm/mach-$(MTK_PLATFORM)/include/mach
subdir-ccflags-y += -I$(srctree)/drivers/misc/mediatek/include/mt-plat
obj-$(CONFIG_MTK_BTIF) += common/
ifeq ($(CONFIG_MTK_ENG_BUILD), y)
subdir-ccflags-y += -D BTIF_DBG_SUPPORT=1
else
subdir-ccflags-y += -D BTIF_DBG_SUPPORT=0
endif
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
@@ -0,0 +1,31 @@
#
# Copyright (C) 2015 MediaTek Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# BTIF driver for AD DIE
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
ifneq ($(KERNELRELEASE),)
ccflags-y += -I$(src)/inc
ccflags-y += -I$(src)/plat_inc
obj-$(CONFIG_MTK_BTIF) += btif_drv.o
btif_drv-objs := mtk_btif.o mtk_btif_exp.o btif_dma_plat.o btif_plat.o
# Otherwise we were called directly from the command
# line; invoke the kernel build system.
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
endif
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,329 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __MTK_BTIF_H_
#define __MTK_BTIF_H_
#include <linux/version.h>
#include <linux/module.h>
#include <linux/types.h>
#include <linux/mutex.h>
#include <linux/spinlock.h>
#include <linux/atomic.h>
#include <linux/list.h>
#include <linux/dma-mapping.h>
#include <linux/vmalloc.h>
#include <linux/sched.h>
#include <linux/sched/rt.h>
#include <linux/kthread.h>
#include <linux/workqueue.h>
#include <linux/interrupt.h>
#include <linux/fs.h>
#include <linux/uaccess.h>
#include <linux/string.h>
#include <linux/time.h> /* gettimeofday */
#include <asm-generic/bug.h>
#include "btif_pub.h"
#include "btif_dma_pub.h"
#include "mtk_btif_exp.h"
#define BTIF_PORT_NR 1
#define BTIF_USER_NAME_MAX_LEN 32
/*-------------Register Defination Start ---------------*/
#if (defined(CONFIG_MTK_GMO_RAM_OPTIMIZE) && !defined(CONFIG_MTK_ENG_BUILD))
#define BTIF_RX_BUFFER_SIZE (1024 * 32)
#else
#define BTIF_RX_BUFFER_SIZE (1024 * 64)
#endif
#define BTIF_TX_BUFFER_FIFO_SIZE (1024 * 4)
/*------------Register Defination End ----------------*/
/*------------BTIF Module Clock and Power Control Defination---------------*/
enum _ENUM_BTIF_RX_TYPE_ {
BTIF_IRQ_CTX = 0,
BTIF_TASKLET_CTX = BTIF_IRQ_CTX + 1,
BTIF_THREAD_CTX = BTIF_TASKLET_CTX + 1,
BTIF_WQ_CTX = BTIF_THREAD_CTX + 1,
BTIF_RX_TYPE_MAX,
};
enum _ENUM_BTIF_TX_TYPE_ {
BTIF_TX_USER_CTX = 0,
BTIF_TX_SINGLE_CTX = BTIF_TX_USER_CTX + 1,
BTIF_TX_TYPE_MAX,
};
enum _ENUM_BTIF_STATE_ {
B_S_OFF = 0,
B_S_SUSPEND = B_S_OFF + 1,
B_S_DPIDLE = B_S_SUSPEND + 1,
B_S_ON = B_S_DPIDLE + 1,
B_S_MAX,
};
#if BTIF_DBG_SUPPORT
enum _ENUM_BTIF_TEST_CASE_ {
BTIF_TEST_RX_THREAD_BLOCK = 0,
BTIF_TEST_RX_IRQ_BLOCK = 1,
};
#endif
#define ENABLE_BTIF_RX_DMA 1
#define ENABLE_BTIF_TX_DMA 1
#ifdef ENABLE_BTIF_TX_DMA
#define BTIF_TX_MODE BTIF_MODE_DMA
#else
#define BTIF_TX_MODE BTIF_MODE_PIO
#endif
#ifdef ENABLE_BTIF_RX_DMA
#define BTIF_RX_MODE BTIF_MODE_DMA
#else
#define BTIF_RX_MODE BTIF_MODE_PIO
#endif
#define BTIF_RX_BTM_CTX BTIF_THREAD_CTX/*BTIF_WQ_CTX*//* BTIF_TASKLET_CTX */
/*
* -- cannot be used because ,
* mtk_wcn_stp_parser data will call *(stp_if_tx) to send ack,
* in which context sleepable lock or usleep operation may be used,
* these operation is not allowed in tasklet, may cause schedule_bug
*/
#define BTIF_TX_CTX BTIF_TX_USER_CTX /* BTIF_TX_SINGLE_CTX */
#define ENABLE_BTIF_RX_THREAD_RT_SCHED 1
#define MAX_BTIF_RXD_TIME_REC 3
/*Structure Defination*/
/*-----------------BTIF setting--------------*/
struct _mtk_btif_setting_ {
enum _ENUM_BTIF_MODE_ tx_mode; /*BTIF Tx Mode Setting */
enum _ENUM_BTIF_MODE_ rx_mode; /*BTIF Tx Mode Setting */
enum _ENUM_BTIF_RX_TYPE_ rx_type; /*rx handle type */
enum _ENUM_BTIF_TX_TYPE_ tx_type; /*tx type */
};
/*---------------------------------------------------------------------------*/
struct _btif_buf_str_ {
unsigned int size;
unsigned char *p_buf;
/*
* For Tx: next Tx data pointer to FIFO;
* For Rx: next read data pointer from BTIF user
*/
unsigned int rd_idx;
/*
* For Tx: next Tx data pointer from BTIF user;
* For Rx: next write data(from FIFO) pointer
*/
unsigned int wr_idx;
};
/*---------------------------------------------------------------------------*/
struct _mtk_btif_dma_ {
/*struct _mtk_btif_ **/ void *p_btif;
/*BTIF pointer to which DMA belongs */
enum _ENUM_BTIF_DIR_ dir; /*DMA's direction: */
bool enable; /*DMA enable or disable flag */
struct _MTK_DMA_INFO_STR_ *p_dma_info; /*DMA's IRQ information */
spinlock_t iolock; /*io lock for DMA channel */
atomic_t entry; /* entry count */
};
#if (defined(CONFIG_MTK_GMO_RAM_OPTIMIZE) && !defined(CONFIG_MTK_ENG_BUILD))
#define BTIF_LOG_ENTRY_NUM 10
#else
#define BTIF_LOG_ENTRY_NUM 30
#endif
#define BTIF_LOG_SZ 16
typedef void (*MTK_BTIF_RX_NOTIFY) (void);
struct _btif_log_buf_t_ {
unsigned int len;
struct timespec64 timer;
struct timespec64 ts;
unsigned char buffer[BTIF_LOG_SZ];
};
struct _btif_log_queue_t_ {
enum _ENUM_BTIF_DIR_ dir;
bool enable;
bool output_flag;
unsigned int in;
unsigned int out;
unsigned int size;
spinlock_t lock;
struct _btif_log_buf_t_ *p_queue;
struct _btif_log_buf_t_ *p_dump_queue;
struct work_struct dump_work;
unsigned int dump_size;
};
/*---------------------------------------------------------------------------*/
struct _mtk_btif_ {
unsigned int open_counter; /*open counter */
bool enable; /*BTIF module enable flag */
bool lpbk_flag; /*BTIF module enable flag */
enum _ENUM_BTIF_STATE_ state; /*BTIF state mechanism */
struct mutex state_mtx; /*lock to BTIF state mechanism's state change */
struct mutex ops_mtx; /*lock to BTIF's open and close */
enum _ENUM_BTIF_MODE_ tx_mode; /* BTIF Tx channel mode */
enum _ENUM_BTIF_MODE_ rx_mode; /* BTIF Rx channel mode */
struct mutex tx_mtx; /*lock to BTIF's tx process */
/*rx handling */
enum _ENUM_BTIF_RX_TYPE_ btm_type; /*BTIF Rx bottom half context */
/*tx handling*/
enum _ENUM_BTIF_TX_TYPE_ tx_ctx; /*BTIF tx context */
/* unsigned char rx_buf[BTIF_RX_BUFFER_SIZE]; */
struct _btif_buf_str_ btif_buf;
spinlock_t rx_irq_spinlock; /*lock for rx irq handling */
/*rx workqueue information*/
/*lock to BTIF's rx bottom half when kernel thread is used */
struct mutex rx_mtx;
struct workqueue_struct *p_rx_wq;
struct work_struct rx_work;
struct workqueue_struct *p_tx_wq;
struct work_struct tx_work;
struct kfifo *p_tx_fifo;
/*rx tasklet information*/
struct tasklet_struct rx_tasklet;
/*lock to BTIF's rx bottom half when tasklet is used */
spinlock_t rx_tasklet_spinlock;
/*rx thread information*/
struct mutex rx_thread_mtx;
struct task_struct *p_task;
struct completion rx_comp;
struct _mtk_btif_setting_ *setting; /*BTIF setting */
struct _mtk_btif_dma_ *p_tx_dma; /*BTIF Tx channel DMA */
struct _mtk_btif_dma_ *p_rx_dma; /*BTIF Rx channel DMA */
MTK_WCN_BTIF_RX_CB rx_cb; /*Rx callback function */
MTK_BTIF_RX_NOTIFY rx_notify;
struct _MTK_BTIF_INFO_STR_ *p_btif_info; /*BTIF's information */
/*Log Tx data to buffer*/
struct _btif_log_queue_t_ tx_log;
/*Log Rx data to buffer*/
struct _btif_log_queue_t_ rx_log;
/* struct list_head *p_user_list; */
struct list_head user_list;
/* get btif dev pointer*/
void *private_data;
#if BTIF_DBG_SUPPORT
/* Test btif thread */
struct delayed_work btif_rx_test_work;
enum _ENUM_BTIF_TEST_CASE_ test_case;
int delay_sched_time;
#endif
};
/*---------------------------------------------------------------------------*/
struct _mtk_btif_user_ {
bool enable; /*register its state */
struct list_head entry; /*btif_user's bi-direction list table */
/*BTIF's user, static allocation */
char u_name[BTIF_USER_NAME_MAX_LEN];
unsigned long u_id;
struct _mtk_btif_ *p_btif;
};
/*---------------------------------------------------------------------------*/
#define BBS_PTR(ptr, idx) ((ptr->p_buf) + idx)
#define BBS_SIZE(ptr) ((ptr)->size)
#define BBS_MASK(ptr) (BBS_SIZE(ptr) - 1)
#define BBS_COUNT(ptr) ((ptr)->wr_idx >= (ptr)->rd_idx ? (ptr)->wr_idx - \
(ptr)->rd_idx : BBS_SIZE(ptr) - \
((ptr)->rd_idx - (ptr)->wr_idx))
#define BBS_COUNT_CUR(ptr, wr_idx) (wr_idx >= (ptr)->rd_idx ? wr_idx - \
(ptr)->rd_idx : BBS_SIZE(ptr) - \
((ptr)->rd_idx - wr_idx))
#define BBS_LEFT(ptr) (BBS_SIZE(ptr) - BBS_COUNT(ptr))
#define BBS_AVL_SIZE(ptr) (BBS_SIZE(ptr) - BBS_COUNT(ptr))
#define BBS_FULL(ptr) (BBS_COUNT(ptr) - BBS_SIZE(ptr))
#define BBS_EMPTY(ptr) ((ptr)->wr_idx == (ptr)->rd_idx)
#define BBS_WRITE_MOVE_NEXT(ptr) ((ptr)->wr_idx = \
((ptr)->wr_idx + 1) & BBS_MASK(ptr))
#define BBS_READ_MOVE_NEXT(ptr) ((ptr)->rd_idx = \
((ptr)->rd_idx + 1) & BBS_MASK(ptr))
#define BBS_INIT(ptr) \
{ \
(ptr)->rd_idx = (ptr)->wr_idx = 0; \
(ptr)->size = BTIF_RX_BUFFER_SIZE; \
}
#define BTIF_MUTEX_UNLOCK(x) mutex_unlock(x)
extern struct _mtk_btif_ g_btif[];
int btif_open(struct _mtk_btif_ *p_btif);
int btif_close(struct _mtk_btif_ *p_btif);
int btif_send_data(struct _mtk_btif_ *p_btif,
const unsigned char *p_buf, unsigned int buf_len);
int btif_enter_dpidle(struct _mtk_btif_ *p_btif);
int btif_exit_dpidle(struct _mtk_btif_ *p_btif);
int btif_rx_cb_reg(struct _mtk_btif_ *p_btif, MTK_WCN_BTIF_RX_CB rx_cb);
/*for test purpose*/
int _btif_suspend(struct _mtk_btif_ *p_btif);
int _btif_resume(struct _mtk_btif_ *p_btif);
int _btif_restore_noirq(struct _mtk_btif_ *p_btif);
int btif_lpbk_ctrl(struct _mtk_btif_ *p_btif, bool flag);
int btif_log_buf_dmp_in(struct _btif_log_queue_t_ *p_log_que, const char *p_buf,
int len);
int btif_dump_data(const char *p_buf, int len);
int btif_log_buf_dmp_out(struct _btif_log_queue_t_ *p_log_que);
int btif_log_buf_enable(struct _btif_log_queue_t_ *p_log_que);
int btif_log_buf_disable(struct _btif_log_queue_t_ *p_log_que);
int btif_log_output_enable(struct _btif_log_queue_t_ *p_log_que);
int btif_log_output_disable(struct _btif_log_queue_t_ *p_log_que);
int btif_log_buf_reset(struct _btif_log_queue_t_ *p_log_que);
int btif_log_buf_init(struct _mtk_btif_ *p_btif);
int btif_dump_reg(struct _mtk_btif_ *p_btif, enum _ENUM_BTIF_REG_ID_ flag);
int btif_rx_notify_reg(struct _mtk_btif_ *p_btif, MTK_BTIF_RX_NOTIFY rx_notify);
int btif_raise_wak_signal(struct _mtk_btif_ *p_btif);
int btif_clock_ctrl(struct _mtk_btif_ *p_btif, int en);
bool btif_parser_wmt_evt(struct _mtk_btif_ *p_btif,
const char *sub_str,
unsigned int sub_len);
void mtk_btif_read_cpu_sw_rst_debug(void);
int btif_rx_data_path_lock(struct _mtk_btif_ *p_btif);
int btif_rx_data_path_unlock(struct _mtk_btif_ *p_btif);
int btif_rx_buf_has_pending_data(struct _mtk_btif_ *p_btif);
int btif_rx_dma_has_pending_data(struct _mtk_btif_ *p_btif);
int btif_tx_dma_has_pending_data(struct _mtk_btif_ *p_btif);
void btif_dump_dma_vfifo(struct _mtk_btif_ *p_btif);
bool btif_is_tx_complete(struct _mtk_btif_ *p_btif);
struct task_struct *btif_rx_thread_get(struct _mtk_btif_ *p_btif);
void btif_do_gettimeofday(struct timespec64 *tv);
int btif_dump_array(const char *string, const char *p_buf, int len);
#endif /*__MTK_BTIF_H_*/
@@ -0,0 +1,328 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef _MTK_BTIF_EXP_H_
#define _MTK_BTIF_EXP_H_
/*--------------marco defination---------------*/
#define BTIF_MAX_LEN_PER_PKT 2048
#define BTIF_RXD_BE_BLOCKED_DETECT 1
/*--------------Enum Defination---------------*/
enum _ENUM_BTIF_DPIDLE_ {
BTIF_DPIDLE_DISABLE = 0,
BTIF_DPIDLE_ENABLE = BTIF_DPIDLE_DISABLE + 1,
BTIF_DPIDLE_MAX,
};
enum _ENUM_BTIF_LPBK_MODE_ {
BTIF_LPBK_DISABLE = 0,
BTIF_LPBK_ENABLE = BTIF_LPBK_DISABLE + 1,
BTIF_LPBK_MAX,
};
enum _ENUM_BTIF_DBG_ID_ {
BTIF_DISABLE_LOGGER = 0,
BTIF_ENABLE_LOGGER = BTIF_DISABLE_LOGGER + 1,
BTIF_DUMP_LOG = BTIF_ENABLE_LOGGER + 1,
BTIF_CLR_LOG = BTIF_DUMP_LOG + 1,
BTIF_DUMP_BTIF_REG = BTIF_CLR_LOG + 1,
BTIF_ENABLE_RT_LOG = BTIF_DUMP_BTIF_REG + 1,
BTIF_DISABLE_RT_LOG = BTIF_ENABLE_RT_LOG + 1,
BTIF_DUMP_BTIF_IRQ = BTIF_DISABLE_RT_LOG + 1,
BTIF_DUMP_DMA_VFIFO = BTIF_DUMP_BTIF_IRQ + 1,
BTIF_DBG_MAX,
};
enum _ENUM_BTIF_OP_ERROR_CODE_ {
E_BTIF_AGAIN = 0,
E_BTIF_FAIL = -1,
E_BTIF_BAD_POINTER = -2,
E_BTIF_NO_SPACE = -3,
E_BTIF_INTR = -4,
E_BTIF_INVAL_PARAM = -5,
E_BTIF_ALREADY_OPEN = -6,
E_BTIF_NOT_OPEN = -7,
E_BTIF_INVAL_STATE = -8,
};
/*--------------End of Enum Defination---------------*/
/*--------------Type Definition---------------*/
typedef int (*MTK_WCN_BTIF_RX_CB) (unsigned char *p_buf,
unsigned int len);
/*--------------End of Type Definition---------------*/
/*--------------Normal Mode API declearation---------------*/
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_open
* DESCRIPTION
* open BTIF interface, will do BTIF module HW and SW initialization
* PARAMETERS
* p_owner [IN] pointer to owner who call this API,
* currently there are 2 owner ("stp" or "btif_tester")
* may use this module
* user's id string must be less than 32 bytes
* for "stp", BTIF will call rx callback function to route rx data to STP
* for "stp_tester", BTIF will save rx data
* and wait for native process to access
* p_id [IN] BTIF's user id will be put to this address
* RETURNS
* int 0 = succeed; others = fail, for detailed information,
* please see ENUM_BTIF_OP_ERROR_CODE
* if open success, value p_id will be the only identifier for
* user to access BTIF's other operations
* including read/write/dpidle_ctrl/rx_cb_retister
* this user id is only an identifier used for owner identification
*****************************************************************************/
int mtk_wcn_btif_open(char *p_owner, unsigned long *p_id);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_close
* DESCRIPTION
* close BTIF interface, will do BTIF module HW and SW de-initialization
* once this API is called, p_btif should never be used by BTIF's user again
* PARAMETERS
* u_id [IN] BTIF's user id
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_close(unsigned long u_id);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_write
* DESCRIPTION
* send data throuth BTIF module
* there's no internal buffer to cache STP data in BTIF driver,
* if in DMA mode
* btif driver will check if there's enough space
* in vFIFO for data to send in DMA mode
* if yes, put data to vFIFO and return corresponding data length to caller
* if no, corresponding error code will be returned to called
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* p_buf [IN] pointer to target data to send
* len [IN] data length (less than 2014 bytes per STP package)
*
* if in non-DMA mode, BTIF driver will try to write to THR of BTIF controller
* if btif driver detected that no space is available in Tx FIFO,
* will return E_BTIF_NO_SPACE,
* mostly something is wrong with BTIF or consys when this
* return value is returned
* RETURNS
* int positive: data length send through BTIF;
* negative: please see ENUM_BTIF_OP_ERROR_CODE
* E_BTIF_AGAIN (0) will be returned to caller if btif does not have
* enough vFIFO to send data, when caller get 0,
* he should wait for a moment (5~10ms maybe) and
* try a few times (maybe 10~20)
* if still get E_BTIF_AGAIN, should call BTIF's debug API and
* dump BTIF driver and BTIF/DMA register information to kernel log
* for debug
* E_BTIF_BAD_POINTER will be returned to caller if btif is not
* opened successfully before call this API
* E_BTIF_INVAL_PARAM will be returned if parameter is not valid
*****************************************************************************/
int mtk_wcn_btif_write(unsigned long u_id,
const unsigned char *p_buf, unsigned int len);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_read
* DESCRIPTION
* read data from BTIF module
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* p_buf [IN/OUT] pointer to buffer where rx data will be put
* max_len [IN] max buffer length
* RETURNS
* int positive: data length read from BTIF;
* negative: please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_read(unsigned long u_id,
unsigned char *p_buf, unsigned int max_len);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_dpidle_ctrl
* DESCRIPTION
* control if BTIF module allow system enter deepidle state or not
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* en_flag [IN] one of enum _ENUM_BTIF_DPIDLE_
* RETURNS
* int always return 0
*****************************************************************************/
int mtk_wcn_btif_dpidle_ctrl(unsigned long u_id,
enum _ENUM_BTIF_DPIDLE_ en_flag);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_rx_cb_register
* DESCRIPTION
* register rx callback function to BTIF module by btif user
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* rx_cb [IN] pointer to stp rx handler callback function,
* should be comply with MTK_WCN_BTIF_RX_CB
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_rx_cb_register(unsigned long u_id, MTK_WCN_BTIF_RX_CB rx_cb);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_wakeup_consys
* DESCRIPTION
* once sleep command is sent to con sys,
* should call this API before send wakeup command to
* make con sys aware host want to send data to consys
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_wakeup_consys(unsigned long u_id);
/*--------------End of Normal Mode API declearation----------------*/
/*--------------Debug Purpose API declearation----------------*/
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_loopback_ctrl
* DESCRIPTION
* enable/disable BTIF internal loopback function,
* when this function is enabled,
* data send to btif will be received by btif itself
* only for debug purpose, should never use this function in normal mode
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* enable [IN] loopback mode control flag, enable or disable,
* shou be one of enum _ENUM_BTIF_LPBK_MODE_
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_loopback_ctrl(unsigned long u_id,
enum _ENUM_BTIF_LPBK_MODE_ enable);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_logger_ctrl
* DESCRIPTION
* control BTIF logger function's behavior
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* flag [IN] should be one of enum _ENUM_BTIF_DBG_ID_
* BTIF_DISABLE_LOGGER - disable btif logger
* BTIF_ENABLE_LOGGER - enable btif logger
* BTIF_DUMP_LOG - dump log logged by btif
* BTIF_CLR_LOG - clear btif log buffer
* BTIF_DUMP_BTIF_REG - dump btif controller's register
* BTIF_DUMP_DMA_REG - dump DMA controller's register
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information,
* please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_dbg_ctrl(unsigned long u_id, enum _ENUM_BTIF_DBG_ID_ flag);
/*-----------End of Debug Purpose API declearation------------*/
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_parser_wmt_evt
* DESCRIPTION
* parser wmt sleep/wakeup evt in btif bbs buffer for debug
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* sub_str [IN] the str to be parsered
* str_len [IN] the length of sub_str
* RETURNS
* bool true = succeed;
* false = fail;
*****************************************************************************/
bool mtk_wcn_btif_parser_wmt_evt(unsigned long u_id,
const char *sub_str, unsigned int str_len);
/*****************************************************************************
* FUNCTION
* mtk_btif_exp_rx_has_pending_data
* DESCRIPTION
* Check if rx buffer and rx vff have pending data
* PARAMETERS
* u_id [IN] btif index
* RETURNS
* positive means has pending data
* zeor means no pending data
* negative means fail
*****************************************************************************/
int mtk_btif_exp_rx_has_pending_data(unsigned long u_id);
/*****************************************************************************
* FUNCTION
* mtk_btif_exp_tx_has_pending_data
* DESCRIPTION
* Check if tx vff has pending data
* PARAMETERS
* u_id [IN] btif index
* RETURNS
* positive means has pending data
* zeor means no pending data
* negative means fail
*****************************************************************************/
int mtk_btif_exp_tx_has_pending_data(unsigned long u_id);
/*****************************************************************************
* FUNCTION
* mtk_btif_is_tx_complete
* DESCRIPTION
* Check if tx is complete
* PARAMETERS
* u_id [IN] btif index
* RETURNS
* positive means tx is complete
* zeor means tx is ongoing
* negative means fail
*****************************************************************************/
int mtk_btif_is_tx_complete(unsigned long u_id);
/*****************************************************************************
* FUNCTION
* mtk_btif_exp_rx_thread_get
* DESCRIPTION
* get btif_rxd thread
* PARAMETERS
* u_id [IN] btif index
* RETURNS
* btif_rxd thread task pointer, NULL means fail
*****************************************************************************/
struct task_struct *mtk_btif_exp_rx_thread_get(unsigned long u_id);
int mtk_btif_exp_open_test(void);
int mtk_btif_exp_close_test(void);
int mtk_btif_exp_write_test(void);
int mtk_btif_exp_suspend_test(void);
int mtk_btif_exp_resume_test(void);
int mtk_btif_exp_enter_dpidle_test(void);
int mtk_btif_exp_exit_dpidle_test(void);
int mtk_btif_exp_write_stress_test(unsigned int length, unsigned int loop);
int mtk_btif_exp_log_debug_test(int flag);
int mtk_btif_exp_restore_noirq_test(void);
int btif_wakeup_consys_no_id(void);
int mtk_btif_exp_clock_ctrl(int en);
#if BTIF_RXD_BE_BLOCKED_DETECT
int mtk_btif_rxd_be_blocked_flag_get(void);
#endif
void mtk_btif_read_cpu_sw_rst_debug_exp(void);
#endif /*_MTK_BTIF_EXP_H_*/
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,870 @@
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifdef DFT_TAG
#undef DFT_TAG
#endif
#define DFT_TAG "MTK-BTIF-EXP"
/*#include "mtk_btif_exp.h"*/
#include "mtk_btif.h"
/*---------------------------------Function----------------------------------*/
struct _mtk_btif_ *btif_exp_srh_id(unsigned long u_id)
{
int index = 0;
struct _mtk_btif_ *p_btif = NULL;
struct list_head *p_list = NULL;
struct list_head *tmp = NULL;
struct _mtk_btif_user_ *p_user = NULL;
for (index = 0; (index < BTIF_PORT_NR) && (p_btif == NULL); index++) {
p_list = &(g_btif[index].user_list);
list_for_each(tmp, p_list) {
p_user = container_of(tmp,
struct _mtk_btif_user_,
entry);
if (u_id == p_user->u_id) {
p_btif = p_user->p_btif;
BTIF_DBG_FUNC
("BTIF's user id(%lu), p_btif(0x%p)\n",
p_user->u_id, p_btif);
break;
}
}
}
if (p_btif == NULL) {
BTIF_INFO_FUNC
("no btif structure found for BTIF's user id(0x%lx)\n",
u_id);
}
return p_btif;
}
/*-----Normal Mode API declearation-------*/
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_open
* DESCRIPTION
* open BTIF interface, will do BTIF module HW and SW initialization
* PARAMETERS
* p_owner [IN] pointer to owner who call this API,
* currently there are 2 owner ("stp" or "btif_tester")
* may use this module
* for "stp", BTIF will call rx callback function to route rx data to STP
* for "stp_tester", BTIF will save rx data and wait for native process
* to access
* p_id [IN] BTIF's user id will be put to this address
* RETURNS
* int 0 = BTIF module initialization fail;
* negative = BTIF module initialization success
* if open success, value p_id will be the only identifier
* for user to access BTIF's other operations
* including read/write/dpidle_ctrl/rx_cb_retister
* this user id is only an identifier used for owner identification
*****************************************************************************/
int mtk_wcn_btif_open(char *p_owner, unsigned long *p_id)
{
int i_ret = -1;
unsigned int index = 0;
struct _mtk_btif_user_ *p_new_user = NULL;
struct _mtk_btif_ *p_btif = &g_btif[index];
struct list_head *p_user_list = &(p_btif->user_list);
BTIF_DBG_FUNC("++");
BTIF_DBG_FUNC("p_btif(0x%p)\n", p_btif);
if (mutex_lock_killable(&(p_btif->ops_mtx))) {
BTIF_ERR_FUNC("mutex_lock_killable return failed\n");
return E_BTIF_INTR;
}
if ((p_owner == NULL) || (p_id == NULL)) {
if (p_id)
*p_id = 0;
BTIF_ERR_FUNC("parameter invalid, p_owner(0x%p), p_id(0x%p)\n",
p_owner, p_id);
BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
return E_BTIF_INVAL_PARAM;
}
/*check if btif is already opened or not, if yes, just return fail*/
if (!list_empty(p_user_list)) {
struct list_head *pos = NULL;
struct _mtk_btif_user_ *p_user = NULL;
BTIF_ERR_FUNC("BTIF's user list is not empty\n");
list_for_each(pos, p_user_list) {
p_user = container_of(pos,
struct _mtk_btif_user_,
entry);
BTIF_INFO_FUNC("BTIF's user id(0x%lx), name(%s)\n",
p_user->u_id, p_user->u_name);
}
/*leave p_id alone*/
BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
return E_BTIF_ALREADY_OPEN;
}
p_new_user = vmalloc(sizeof(struct _mtk_btif_user_));
if (p_new_user != NULL) {
INIT_LIST_HEAD(&(p_new_user->entry));
p_new_user->enable = false;
p_new_user->p_btif = p_btif;
p_new_user->u_id = (unsigned long)p_new_user;
strncpy(p_new_user->u_name, p_owner,
sizeof(p_new_user->u_name) - 1);
p_new_user->u_name[sizeof(p_new_user->u_name) - 1] = '\0';
BTIF_DBG_FUNC("owner name:%s, recorded name:%s\n",
p_owner, p_new_user->u_name);
i_ret = btif_open(p_btif);
if (i_ret) {
BTIF_ERR_FUNC("btif_open failed, i_ret(%d)\n", i_ret);
*p_id = 0;
/*free btif new user's structure*/
vfree(p_new_user);
p_new_user = NULL;
} else {
BTIF_INFO_FUNC("btif_open succeed\n");
*p_id = p_new_user->u_id;
/*mark enable flag to true*/
p_new_user->enable = true;
/*add to uer lsit*/
list_add_tail(&(p_new_user->entry), p_user_list);
}
} else {
*p_id = 0;
i_ret = -ENOMEM;
BTIF_ERR_FUNC("alloc memory struct _mtk_btif_user_ failed\n");
}
BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
BTIF_DBG_FUNC("--");
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_open);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_close
* DESCRIPTION
* close BTIF interface, will do BTIF module HW and SW de-initialization
* once this API is called, p_btif should never be used by BTIF's user again
* PARAMETERS
* u_id [IN] BTIF's user id
* RETURNS
* int 0 = succeed;
* others = fail,
* for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_close(unsigned long u_id)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
struct list_head *pos = NULL;
struct list_head *p_user_list = NULL;
BTIF_DBG_FUNC("++");
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
if (mutex_lock_killable(&(p_btif->ops_mtx))) {
BTIF_ERR_FUNC("mutex_lock_killable return failed\n");
return E_BTIF_INTR;
}
p_user_list = &(p_btif->user_list);
list_for_each(pos, p_user_list) {
struct _mtk_btif_user_ *p_user =
container_of(pos, struct _mtk_btif_user_, entry);
if (p_user->u_id == u_id) {
BTIF_INFO_FUNC
("user who's id is 0x%lx deleted from user list\n",
u_id);
list_del(pos);
vfree(p_user);
i_ret = btif_close(p_btif);
if (i_ret)
BTIF_WARN_FUNC("BTIF close failed");
break;
}
}
BTIF_MUTEX_UNLOCK(&(p_btif->ops_mtx));
BTIF_DBG_FUNC("--");
return 0;
}
EXPORT_SYMBOL(mtk_wcn_btif_close);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_write
* DESCRIPTION
* send data throuth BTIF module
* there's no internal buffer to cache STP data in BTIF driver,
* if in DMA mode
* btif driver will check if there's enough space in vFIFO for data to send
* in DMA mode
* if yes, put data to vFIFO and return corresponding data length to caller
* if no, corresponding error code will be returned to called
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* p_buf [IN] pointer to target data to send
* len [IN] data length (less than 2014 bytes per STP package)
*
* if in non-DMA mode, BTIF driver will try to write to THR of BTIF controller
* if btif driver detected that no space is available in Tx FIFO,
* will return E_BTIF_NO_SPACE, mostly something is wrong with BTIF or
* consys when this return value is returned
* RETURNS
* int positive: data length send through BTIF;
* negative: please see ENUM_BTIF_OP_ERROR_CODE
* E_BTIF_AGAIN (0) will be returned to caller
* if btif does not have enough vFIFO to send data,
* when caller get 0, he should wait for a moment
* (5~10ms maybe) and try a few times (maybe 10~20)
* if still get E_BTIF_AGAIN,
* should call BTIF's debug API and dump BTIF driver
* and BTIF/DMA register information to kernel log for debug
* E_BTIF_BAD_POINTER will be returned to caller
* if btif is not opened successfully before call this API
* E_BTIF_INVAL_PARAM will be returned if parameter is not valid
*****************************************************************************/
int mtk_wcn_btif_write(unsigned long u_id,
const unsigned char *p_buf, unsigned int len)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
BTIF_DBG_FUNC("++");
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
if (p_buf == NULL) {
BTIF_ERR_FUNC("invalid p_buf (0x%p)\n", p_buf);
return E_BTIF_INVAL_PARAM;
}
if ((len == 0) || (len > BTIF_MAX_LEN_PER_PKT)) {
BTIF_ERR_FUNC("invalid buffer length(%d)\n", len);
return E_BTIF_INVAL_PARAM;
}
i_ret = btif_send_data(p_btif, p_buf, len);
BTIF_DBG_FUNC("--, i_ret:%d\n", i_ret);
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_write);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_read
* DESCRIPTION
* read data from BTIF module
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* p_buf [IN/OUT] pointer to buffer where rx data will be put
* max_len [IN] max buffer length
* RETURNS
* int positive: data length read from BTIF;
* negative: please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_read(unsigned long u_id,
unsigned char *p_buf, unsigned int max_len)
{
return 0;
}
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_dpidle_ctrl
* DESCRIPTION
* control if BTIF module allow system enter deepidle state or not
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* en_flag [IN] one of enum _ENUM_BTIF_DPIDLE_
* RETURNS
* int always return 0
*****************************************************************************/
int mtk_wcn_btif_dpidle_ctrl(unsigned long u_id,
enum _ENUM_BTIF_DPIDLE_ en_flag)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
if (en_flag == BTIF_DPIDLE_DISABLE)
i_ret = btif_exit_dpidle(p_btif);
else {
i_ret = btif_enter_dpidle(p_btif);
BTIF_INFO_FUNC("enter deep idle\n");
}
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_dpidle_ctrl);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_rx_cb_register
* DESCRIPTION
* register rx callback function to BTIF module by btif user
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* rx_cb [IN] pointer to stp rx handler callback function,
* should be comply with MTK_WCN_BTIF_RX_CB
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information,
* please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_rx_cb_register(unsigned long u_id, MTK_WCN_BTIF_RX_CB rx_cb)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
i_ret = btif_rx_cb_reg(p_btif, rx_cb);
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_rx_cb_register);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_wakeup_consys
* DESCRIPTION
* once sleep command is sent to con sys,
* should call this API before send wakeup command
* to make con sys aware host want to send data to consys
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* RETURNS
* int 0 = succeed; others = fail, for detailed information,
* please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_wakeup_consys(unsigned long u_id)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
/*i_ret = hal_btif_raise_wak_sig(p_btif->p_btif_info);*/
i_ret = btif_raise_wak_signal(p_btif);
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_wakeup_consys);
/***************End of Normal Mode API declearation**********/
/***************Debug Purpose API declearation**********/
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_loopback_ctrl
* DESCRIPTION
* enable/disable BTIF internal loopback function,
* when this function is enabled data send to btif
* will be received by btif itself
* only for debug purpose, should never use this function in normal mode
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* enable [IN] loopback mode control flag, enable or disable,
* shou be one of enum _ENUM_BTIF_LPBK_MODE_
* RETURNS
* int 0 = succeed;
* others = fail, for detailed information, please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_loopback_ctrl(unsigned long u_id,
enum _ENUM_BTIF_LPBK_MODE_ enable)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
i_ret =
btif_lpbk_ctrl(p_btif, enable == BTIF_LPBK_ENABLE ? true : false);
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_loopback_ctrl);
/*****************************************************************************
* FUNCTION
* mtk_wcn_btif_logger_ctrl
* DESCRIPTION
* control BTIF logger function's behavior
* PARAMETERS
* p_btif [IN] pointer returned by mtk_wcn_btif_open
* flag [IN] should be one of enum _ENUM_BTIF_DBG_ID_
* BTIF_DISABLE_LOGGER - disable btif logger
* BTIF_ENABLE_LOGGER - enable btif logger
* BTIF_DUMP_LOG - dump log logged by btif
* BTIF_CLR_LOG - clear btif log buffer
* BTIF_DUMP_BTIF_REG - dump btif controller's register
* BTIF_DUMP_DMA_REG - dump DMA controller's register
* RETURNS
* int 0 = succeed; others = fail, for detailed information,
* please see ENUM_BTIF_OP_ERROR_CODE
*****************************************************************************/
int mtk_wcn_btif_dbg_ctrl(unsigned long u_id, enum _ENUM_BTIF_DBG_ID_ flag)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
i_ret = 0;
switch (flag) {
case BTIF_DISABLE_LOGGER:{
BTIF_INFO_FUNC
("disable btif log function for both Tx and Rx\n");
btif_log_buf_disable(&p_btif->tx_log);
btif_log_buf_disable(&p_btif->rx_log);
}
break;
case BTIF_ENABLE_LOGGER:{
BTIF_INFO_FUNC
("enable btif log function for both Tx and Rx\n");
btif_log_buf_enable(&p_btif->tx_log);
btif_log_buf_enable(&p_btif->rx_log);
}
break;
case BTIF_DUMP_LOG:{
BTIF_INFO_FUNC("dump btif log for both Tx and Rx\n");
btif_log_buf_dmp_out(&p_btif->tx_log);
btif_log_buf_dmp_out(&p_btif->rx_log);
}
break;
case BTIF_CLR_LOG:{
BTIF_INFO_FUNC("clear btif log for both Tx and Rx\n");
btif_log_buf_reset(&p_btif->tx_log);
btif_log_buf_reset(&p_btif->rx_log);
}
break;
case BTIF_DUMP_BTIF_REG:
btif_dump_reg(p_btif, REG_ALL);
break;
case BTIF_DUMP_BTIF_IRQ:
btif_dump_reg(p_btif, REG_IRQ);
break;
case BTIF_ENABLE_RT_LOG:
BTIF_INFO_FUNC
("enable btif real time log for both Tx and Rx\n");
btif_log_output_enable(&p_btif->tx_log);
btif_log_output_enable(&p_btif->rx_log);
break;
case BTIF_DISABLE_RT_LOG:
BTIF_INFO_FUNC
("disable btif real time log for both Tx and Rx\n");
btif_log_output_disable(&p_btif->tx_log);
btif_log_output_disable(&p_btif->rx_log);
break;
case BTIF_DUMP_DMA_VFIFO:
btif_dump_dma_vfifo(p_btif);
break;
default:
BTIF_INFO_FUNC("not supported flag:%d\n", flag);
i_ret = -2;
break;
}
return i_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_dbg_ctrl);
bool mtk_wcn_btif_parser_wmt_evt(unsigned long u_id,
const char *sub_str, unsigned int str_len)
{
bool b_ret = false;
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL)
return E_BTIF_INVAL_PARAM;
b_ret = btif_parser_wmt_evt(p_btif, sub_str, str_len);
BTIF_INFO_FUNC("parser wmt evt %s\n", b_ret ? "ok" : "fail");
return b_ret;
}
EXPORT_SYMBOL(mtk_wcn_btif_parser_wmt_evt);
/**********End of Debug Purpose API declearation**********/
int btif_open_no_id(void)
{
int i_ret = 0;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = btif_open(p_btif);
if (i_ret)
BTIF_ERR_FUNC("btif_open failed, i_ret(%d)\n", i_ret);
else
BTIF_INFO_FUNC("btif_open succeed\n");
return i_ret;
}
int btif_close_no_id(void)
{
int i_ret = 0;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = btif_close(p_btif);
if (i_ret)
BTIF_ERR_FUNC("btif_close failed, i_ret(%d)\n", i_ret);
else
BTIF_INFO_FUNC("btif_close succeed\n");
return i_ret;
}
int btif_write_no_id(const unsigned char *p_buf, unsigned int len)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = &g_btif[0];
BTIF_DBG_FUNC("++");
if (p_buf == NULL) {
BTIF_ERR_FUNC("invalid p_buf (0x%p)\n", p_buf);
return E_BTIF_INVAL_PARAM;
}
if ((len == 0) || (len > BTIF_MAX_LEN_PER_PKT)) {
BTIF_ERR_FUNC("invalid buffer length(%d)\n", len);
return E_BTIF_INVAL_PARAM;
}
i_ret = btif_send_data(p_btif, p_buf, len);
BTIF_DBG_FUNC("--, i_ret:%d\n", i_ret);
return i_ret;
}
int btif_dpidle_ctrl_no_id(enum _ENUM_BTIF_DPIDLE_ en_flag)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = &g_btif[0];
if (en_flag == BTIF_DPIDLE_DISABLE)
i_ret = btif_exit_dpidle(p_btif);
else
i_ret = btif_enter_dpidle(p_btif);
return i_ret;
}
int btif_wakeup_consys_no_id(void)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = &g_btif[0];
/*i_ret = hal_btif_raise_wak_sig(p_btif->p_btif_info);*/
i_ret = btif_raise_wak_signal(p_btif);
return i_ret;
}
int btif_loopback_ctrl_no_id(enum _ENUM_BTIF_LPBK_MODE_ enable)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret =
btif_lpbk_ctrl(p_btif, enable == BTIF_LPBK_ENABLE ? true : false);
return i_ret;
}
int btif_dbg_ctrl_no_id(enum _ENUM_BTIF_DBG_ID_ flag)
{
int i_ret = -1;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = 0;
switch (flag) {
case BTIF_DISABLE_LOGGER:{
BTIF_INFO_FUNC
("disable btif log function for both Tx and Rx\n");
btif_log_buf_disable(&p_btif->tx_log);
btif_log_buf_disable(&p_btif->rx_log);
}
break;
case BTIF_ENABLE_LOGGER:{
BTIF_INFO_FUNC
("enable btif log function for both Tx and Rx\n");
btif_log_buf_enable(&p_btif->tx_log);
btif_log_buf_enable(&p_btif->rx_log);
}
break;
case BTIF_DUMP_LOG:{
BTIF_INFO_FUNC("dump btif log for both Tx and Rx\n");
btif_log_buf_dmp_out(&p_btif->tx_log);
btif_log_buf_dmp_out(&p_btif->rx_log);
}
break;
case BTIF_CLR_LOG:{
BTIF_INFO_FUNC("clear btif log for both Tx and Rx\n");
btif_log_buf_reset(&p_btif->tx_log);
btif_log_buf_reset(&p_btif->rx_log);
}
break;
case BTIF_DUMP_BTIF_REG:
btif_dump_reg(p_btif, REG_ALL);
break;
case BTIF_DUMP_BTIF_IRQ:
btif_dump_reg(p_btif, REG_IRQ);
break;
case BTIF_ENABLE_RT_LOG:
BTIF_INFO_FUNC
("enable btif real time log for both Tx and Rx\n");
btif_log_output_enable(&p_btif->tx_log);
btif_log_output_enable(&p_btif->rx_log);
break;
case BTIF_DISABLE_RT_LOG:
BTIF_INFO_FUNC
("disable btif real time log for both Tx and Rx\n");
btif_log_output_disable(&p_btif->tx_log);
btif_log_output_disable(&p_btif->rx_log);
break;
default:
BTIF_INFO_FUNC("not supported flag:%d\n", flag);
i_ret = -2;
break;
}
return i_ret;
}
int mtk_btif_exp_open_test(void)
{
int i_ret = 0;
i_ret = btif_open_no_id();
if (i_ret < 0) {
BTIF_INFO_FUNC("mtk_wcn_btif_open failed\n");
return -1;
}
BTIF_INFO_FUNC("mtk_wcn_btif_open succeed\n");
return i_ret;
}
int mtk_btif_exp_close_test(void)
{
int i_ret = 0;
i_ret = btif_close_no_id();
if (i_ret < 0) {
BTIF_INFO_FUNC("mtk_wcn_btif_close failed\n");
return -1;
}
BTIF_INFO_FUNC("mtk_wcn_btif_close succeed\n");
return i_ret;
}
int mtk_btif_exp_write_test(void)
{
return mtk_btif_exp_write_stress_test(100, 10);
}
int mtk_btif_exp_write_stress_test(unsigned int length, unsigned int max_loop)
{
#define BUF_LEN 1024
int i_ret = 0;
int idx = 0;
int buf_len = length > BUF_LEN ? BUF_LEN : length;
int loop = max_loop > 1000000 ? 1000000 : max_loop;
unsigned char *buffer;
buffer = kmalloc(BUF_LEN, GFP_KERNEL);
if (!buffer) {
BTIF_ERR_FUNC("btif tester kmalloc failed\n");
return -1;
}
for (idx = 0; idx < buf_len; idx++)
/* btif_stress_test_buf[idx] = BUF_LEN -idx; */
*(buffer + idx) = idx % 255;
i_ret = btif_loopback_ctrl_no_id(BTIF_LPBK_ENABLE);
BTIF_INFO_FUNC("mtk_wcn_btif_loopback_ctrl returned %d\n", i_ret);
while (loop--) {
i_ret = btif_write_no_id(buffer, buf_len);
BTIF_INFO_FUNC("mtk_wcn_btif_write left loop:%d, i_ret:%d\n",
loop, i_ret);
if (i_ret != buf_len) {
BTIF_INFO_FUNC("target len %d, sent len: %d\n",
buf_len, i_ret);
break;
}
buf_len--;
if (buf_len <= 0)
buf_len = length > BUF_LEN ? BUF_LEN : length;
}
kfree(buffer);
return i_ret;
}
int mtk_btif_exp_suspend_test(void)
{
int i_ret = 0;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = _btif_suspend(p_btif);
return i_ret;
}
int mtk_btif_exp_restore_noirq_test(void)
{
int i_ret = 0;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = _btif_restore_noirq(p_btif);
return i_ret;
}
int mtk_btif_exp_clock_ctrl(int en)
{
int i_ret = 0;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = btif_clock_ctrl(p_btif, en);
return i_ret;
}
int mtk_btif_exp_resume_test(void)
{
int i_ret = 0;
struct _mtk_btif_ *p_btif = &g_btif[0];
i_ret = _btif_resume(p_btif);
return i_ret;
}
int mtk_btif_exp_enter_dpidle_test(void)
{
return btif_dpidle_ctrl_no_id(BTIF_DPIDLE_ENABLE);
}
int mtk_btif_exp_exit_dpidle_test(void)
{
return btif_dpidle_ctrl_no_id(BTIF_DPIDLE_DISABLE);
}
int mtk_btif_exp_log_debug_test(int flag)
{
int i_ret = 0;
i_ret = btif_dbg_ctrl_no_id(flag);
return i_ret;
}
void mtk_btif_read_cpu_sw_rst_debug_exp(void)
{
mtk_btif_read_cpu_sw_rst_debug();
}
int mtk_btif_exp_rx_has_pending_data(unsigned long u_id)
{
struct _mtk_btif_ *p_btif = NULL;
int has_pending_data = 0;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL) {
BTIF_ERR_FUNC("parameter invalid\n");
return E_BTIF_INVAL_PARAM;
}
/* Lock the data path to ensure that the current data path is
* not processing data. If fail to get lock, it means rx data
* path is busy and we assume there has pending data to avoid
* thread is blocked here.
*/
if (btif_rx_data_path_lock(p_btif))
return 1;
has_pending_data = btif_rx_buf_has_pending_data(p_btif);
if (has_pending_data == 0)
has_pending_data = btif_rx_dma_has_pending_data(p_btif);
btif_rx_data_path_unlock(p_btif);
return has_pending_data;
}
EXPORT_SYMBOL(mtk_btif_exp_rx_has_pending_data);
int mtk_btif_exp_tx_has_pending_data(unsigned long u_id)
{
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL) {
BTIF_ERR_FUNC("E_BTIF_INVAL_PARAM\n");
return E_BTIF_INVAL_PARAM;
}
return btif_tx_dma_has_pending_data(p_btif);
}
EXPORT_SYMBOL(mtk_btif_exp_tx_has_pending_data);
int mtk_btif_is_tx_complete(unsigned long u_id)
{
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL) {
BTIF_ERR_FUNC("E_BTIF_INVAL_PARAM\n");
return E_BTIF_INVAL_PARAM;
}
return btif_is_tx_complete(p_btif);
}
EXPORT_SYMBOL(mtk_btif_is_tx_complete);
struct task_struct *mtk_btif_exp_rx_thread_get(unsigned long u_id)
{
struct _mtk_btif_ *p_btif = NULL;
p_btif = btif_exp_srh_id(u_id);
if (p_btif == NULL) {
BTIF_ERR_FUNC("E_BTIF_INVAL_PARAM\n");
return NULL;
}
return btif_rx_thread_get(p_btif);
}
EXPORT_SYMBOL(mtk_btif_exp_rx_thread_get);
/************End of Function**********/
@@ -0,0 +1,194 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __HAL_BTIF_DMA_H_
#define __HAL_BTIF_DMA_H_
#include <linux/io.h>
#include "btif_dma_pub.h"
#if defined(CONFIG_MTK_CLKMGR)
#if defined(CONFIG_ARCH_MT6580)
#define MTK_BTIF_APDMA_CLK_CG MT_CG_APDMA_SW_CG
#elif defined(CONFIG_ARCH_MT6735)
#define MTK_BTIF_APDMA_CLK_CG MT_CG_PERI_APDMA
#elif defined(CONFIG_ARCH_MT6735M)
#define MTK_BTIF_APDMA_CLK_CG MT_CG_PERI_APDMA
#elif defined(CONFIG_ARCH_MT6753)
#define MTK_BTIF_APDMA_CLK_CG MT_CG_PERI_APDMA
#endif
#else
extern struct clk *clk_btif_apdma; /*btif apdma clock*/
#endif /* !defined(CONFIG_MTK_CLKMGR) */
#define TX_DMA_VFF_SIZE (1024 * 8) /*Tx vFIFO Len must be 8 Byte allignment */
#define RX_DMA_VFF_SIZE (1024 * 8) /*Rx vFIFO Len must be 8 Byte allignment */
#define DMA_TX_THRE(n) (n - 7) /*Tx Trigger Level */
#define DMA_RX_THRE(n) (1) /*Rx Trigger Level */
/***************************Hardware related defination************************/
#ifndef CONFIG_OF
/*DMA channel's offset refer to AP_DMA's base address*/
#define BTIF_TX_DMA_OFFSET 0x880
#define BTIF_RX_DMA_OFFSET 0x900
#endif
/*Register Address Mapping*/
#define DMA_INT_FLAG_OFFSET 0x00
#define DMA_INT_EN_OFFSET 0x04
#define DMA_EN_OFFSET 0x08
#define DMA_RST_OFFSET 0x0C
#define DMA_STOP_OFFSET 0x10
#define DMA_FLUSH_OFFSET 0x14
#define DMA_BASE_OFFSET 0x1C
#define DMA_LEN_OFFSET 0x24
#define DMA_THRE_OFFSET 0x28
#define DMA_WPT_OFFSET 0x2C
#define DMA_RPT_OFFSET 0x30
#define DMA_VALID_OFFSET 0x3C
#define DMA_LEFT_OFFSET 0x40
#define DMA_VFF_BIT29_OFFSET 0x01
#define TX_DMA_INT_FLAG(base) (unsigned long)(base + 0x0)
/*BTIF Tx Virtual FIFO Interrupt Flag Register */
#define TX_DMA_INT_EN(base) (unsigned long)(base + 0x4)
/*BTIF Tx Virtual FIFO Interrupt Enable Register */
#define TX_DMA_EN(base) (unsigned long)(base + DMA_EN_OFFSET)
/*BTIF Tx Virtual FIFO Enable Register */
#define TX_DMA_RST(base) (unsigned long)(base + DMA_RST_OFFSET)
/*BTIF Tx Virtual FIFO Reset Register */
#define TX_DMA_STOP(base) (unsigned long)(base + DMA_STOP_OFFSET)
/*BTIF Tx Virtual FIFO STOP Register */
#define TX_DMA_FLUSH(base) (unsigned long)(base + DMA_FLUSH_OFFSET)
/*BTIF Tx Virtual FIFO Flush Register */
#define TX_DMA_VFF_ADDR(base) (unsigned long)(base + 0x1C)
/*BTIF Tx Virtual FIFO Base Address Register */
#define TX_DMA_VFF_LEN(base) (unsigned long)(base + 0x24)
/*BTIF Tx Virtual FIFO Length Register */
#define TX_DMA_VFF_THRE(base) (unsigned long)(base + 0x28)
/*BTIF Tx Virtual FIFO Threshold Register */
#define TX_DMA_VFF_WPT(base) (unsigned long)(base + 0x2C)
/*BTIF Tx Virtual FIFO Write Pointer Register */
#define TX_DMA_VFF_RPT(base) (unsigned long)(base + 0x30)
/*BTIF Tx Virtual FIFO Read Pointer Register */
#define TX_DMA_W_INT_BUF_SIZE(base) (unsigned long)(base + 0x34)
/*BTIF Tx Virtual FIFO Internal Tx Write Buffer Size Register */
#define TX_DMA_INT_BUF_SIZE(base) (unsigned long)(base + 0x38)
/*BTIF Tx Virtual FIFO Internal Tx Buffer Size Register */
#define TX_DMA_VFF_VALID_SIZE(base) (unsigned long)(base + 0x3C)
/*BTIF Tx Virtual FIFO Valid Size Register */
#define TX_DMA_VFF_LEFT_SIZE(base) (unsigned long)(base + 0x40)
/*BTIF Tx Virtual FIFO Left Size Register */
#define TX_DMA_DEBUG_STATUS(base) (unsigned long)(base + 0x50)
/*BTIF Tx Virtual FIFO Debug Status Register */
#define TX_DMA_VFF_ADDR_H(base) (unsigned long)(base + 0x54)
/*BTIF Tx Virtual FIFO Base High Address Register */
/*Rx Register Address Mapping*/
#define RX_DMA_INT_FLAG(base) (unsigned long)(base + 0x0)
/*BTIF Rx Virtual FIFO Interrupt Flag Register */
#define RX_DMA_INT_EN(base) (unsigned long)(base + 0x4)
/*BTIF Rx Virtual FIFO Interrupt Enable Register */
#define RX_DMA_EN(base) (unsigned long)(base + DMA_EN_OFFSET)
/*BTIF Rx Virtual FIFO Enable Register */
#define RX_DMA_RST(base) (unsigned long)(base + DMA_RST_OFFSET)
/*BTIF Rx Virtual FIFO Reset Register */
#define RX_DMA_STOP(base) (unsigned long)(base + DMA_STOP_OFFSET)
/*BTIF Rx Virtual FIFO Stop Register */
#define RX_DMA_FLUSH(base) (unsigned long)(base + DMA_FLUSH_OFFSET)
/*BTIF Rx Virtual FIFO Flush Register */
#define RX_DMA_VFF_ADDR(base) (unsigned long)(base + 0x1C)
/*BTIF Rx Virtual FIFO Base Address Register */
#define RX_DMA_VFF_LEN(base) (unsigned long)(base + 0x24)
/*BTIF Rx Virtual FIFO Length Register */
#define RX_DMA_VFF_THRE(base) (unsigned long)(base + 0x28)
/*BTIF Rx Virtual FIFO Threshold Register */
#define RX_DMA_VFF_WPT(base) (unsigned long)(base + 0x2C)
/*BTIF Rx Virtual FIFO Write Pointer Register */
#define RX_DMA_VFF_RPT(base) (unsigned long)(base + 0x30)
/*BTIF Rx Virtual FIFO Read Pointer Register */
#define RX_DMA_FLOW_CTRL_THRE(base) (unsigned long)(base + 0x34)
/*BTIF Rx Virtual FIFO Flow Control Register */
#define RX_DMA_INT_BUF_SIZE(base) (unsigned long)(base + 0x38)
/*BTIF Rx Virtual FIFO Internal Buffer Register */
#define RX_DMA_VFF_VALID_SIZE(base) (unsigned long)(base + 0x3C)
/*BTIF Rx Virtual FIFO Valid Size Register */
#define RX_DMA_VFF_LEFT_SIZE(base) (unsigned long)(base + 0x40)
/*BTIF Rx Virtual FIFO Left Size Register */
#define RX_DMA_DEBUG_STATUS(base) (unsigned long)(base + 0x50)
/*BTIF Rx Virtual FIFO Debug Status Register */
#define RX_DMA_VFF_ADDR_H(base) (unsigned long)(base + 0x54)
/*BTIF Rx Virtual FIFO Base High Address Register */
#define DMA_EN_BIT (0x1)
#define DMA_STOP_BIT (0x1)
#define DMA_RST_BIT (0x1)
#define DMA_FLUSH_BIT (0x1)
#define DMA_WARM_RST (0x1 << 0)
#define DMA_HARD_RST (0x1 << 1)
#define DMA_WPT_MASK (0x0000FFFF)
#define DMA_WPT_WRAP (0x00010000)
#define DMA_RPT_MASK (0x0000FFFF)
#define DMA_RPT_WRAP (0x00010000)
/*APDMA BTIF Tx Reg Ctrl Bit*/
#define TX_DMA_INT_FLAG_MASK (0x1)
#define TX_DMA_INTEN_BIT (0x1)
#define TX_DMA_ADDR_MASK (0xFFFFFFF8)
#define TX_DMA_LEN_MASK (0x0000FFF8)
#define TX_DMA_THRE_MASK (0x0000FFFF)
#define TX_DMA_W_INT_BUF_MASK (0x000000FF)
#define TX_DMA_VFF_VALID_MASK (0x0000FFFF)
#define TX_DMA_VFF_LEFT_MASK (0x0000FFFF)
/*APDMA BTIF Rx Reg Ctrl Bit*/
#define RX_DMA_INT_THRE (0x1 << 0)
#define RX_DMA_INT_DONE (0x1 << 1)
#define RX_DMA_INT_THRE_EN (0x1 << 0)
#define RX_DMA_INT_DONE_EN (0x1 << 1)
#define RX_DMA_ADDR_MASK (0xFFFFFFF8)
#define RX_DMA_LEN_MASK (0x0000FFF8)
#define RX_DMA_THRE_MASK (0x0000FFFF)
#define RX_DMA_FLOW_CTRL_THRE_MASK (0x000000FF)
#define RX_DMA_INT_BUF_SIZE_MASK (0x0000001F)
#define RX_DMA_VFF_VALID_MASK (0x0000001F)
#define RX_DMA_VFF_LEFT_MASK (0x0000FFFF)
struct _MTK_BTIF_DMA_VFIFO_ {
struct _DMA_VFIFO_ vfifo;
unsigned int wpt; /*DMA's write pointer, */
/* which is maintained by SW for Tx DMA and HW for Rx DMA */
unsigned int last_wpt_wrap; /*last wrap bit for wpt */
unsigned int rpt; /*DMA's read pointer, */
/* which is maintained by HW for Tx DMA and SW for Rx DMA */
unsigned int last_rpt_wrap; /*last wrap bit for rpt */
};
/*for DMA debug purpose*/
struct _MTK_BTIF_DMA_REG_DMP_DBG_ {
unsigned long reg_addr;
unsigned int reg_val;
};
#endif /*__HAL_BTIF_DMA_H_*/
@@ -0,0 +1,198 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __HAL_BTIFD_DMA_PUB_H_
#define __HAL_BTIFD_DMA_PUB_H_
#include <linux/dma-mapping.h>
#include "plat_common.h"
enum _ENUM_DMA_CTRL_ {
DMA_CTRL_DISABLE = 0,
DMA_CTRL_ENABLE = DMA_CTRL_DISABLE + 1,
DMA_CTRL_BOTH,
};
/*****************************************************************************
* FUNCTION
* hal_tx_dma_info_get
* DESCRIPTION
* get btif tx dma channel's information
* PARAMETERS
* dma_dir [IN] DMA's direction
* RETURNS
* pointer to btif dma's information structure
*****************************************************************************/
struct _MTK_DMA_INFO_STR_ *hal_btif_dma_info_get(enum _ENUM_DMA_DIR_ dma_dir);
/*****************************************************************************
* FUNCTION
* hal_btif_dma_hw_init
* DESCRIPTION
* control clock output enable/disable of DMA module
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_dma_hw_init(struct _MTK_DMA_INFO_STR_ *p_dma_info);
/*****************************************************************************
* FUNCTION
* hal_btif_clk_ctrl
* DESCRIPTION
* control clock output enable/disable of DMA module
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_dma_clk_ctrl(struct _MTK_DMA_INFO_STR_ *p_dma_info,
enum _ENUM_CLOCK_CTRL_ flag);
/*****************************************************************************
* FUNCTION
* hal_tx_dma_ctrl
* DESCRIPTION
* enable/disable Tx DMA channel
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* ctrl_id [IN] enable/disable ID
* dma_dir [IN] DMA's direction
* RETURNS
* 0 means success; negative means fail
*****************************************************************************/
int hal_btif_dma_ctrl(struct _MTK_DMA_INFO_STR_ *p_dma_info,
enum _ENUM_DMA_CTRL_ ctrl_id);
/*****************************************************************************
* FUNCTION
* hal_btif_dma_rx_cb_reg
* DESCRIPTION
* register rx callback function to dma module
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* rx_cb [IN] function pointer to btif
* RETURNS
* 0 means success; negative means fail
*****************************************************************************/
int hal_btif_dma_rx_cb_reg(struct _MTK_DMA_INFO_STR_ *p_dma_info,
dma_rx_buf_write rx_cb);
/*****************************************************************************
* FUNCTION
* hal_tx_vfifo_reset
* DESCRIPTION
* reset tx virtual fifo information, except memory information
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* dma_dir [IN] DMA's direction
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_vfifo_reset(struct _MTK_DMA_INFO_STR_ *p_dma_info);
/*****************************************************************************
* FUNCTION
* hal_tx_dma_irq_handler
* DESCRIPTION
* lower level tx interrupt handler
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_tx_dma_irq_handler(struct _MTK_DMA_INFO_STR_ *p_dma_info);
/*****************************************************************************
* FUNCTION
* hal_dma_send_data
* DESCRIPTION
* send data through btif in DMA mode
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* p_buf [IN] pointer to rx data buffer
* max_len [IN] tx buffer length
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_dma_send_data(struct _MTK_DMA_INFO_STR_ *p_dma_info,
const unsigned char *p_buf, const unsigned int buf_len);
/*****************************************************************************
* FUNCTION
* hal_dma_is_tx_complete
* DESCRIPTION
* get tx complete flag
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* RETURNS
* true means tx complete, false means tx in process
*****************************************************************************/
bool hal_dma_is_tx_complete(struct _MTK_DMA_INFO_STR_ *p_dma_info);
/*****************************************************************************
* FUNCTION
* hal_dma_get_ava_room
* DESCRIPTION
* get tx available room
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* RETURNS
* available room size
*****************************************************************************/
int hal_dma_get_ava_room(struct _MTK_DMA_INFO_STR_ *p_dma_info);
/*****************************************************************************
* FUNCTION
* hal_dma_is_tx_allow
* DESCRIPTION
* is tx operation allowed by DMA
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* RETURNS
* true if tx operation is allowed; false if tx is not allowed
*****************************************************************************/
bool hal_dma_is_tx_allow(struct _MTK_DMA_INFO_STR_ *p_dma_info);
/*****************************************************************************
* FUNCTION
* hal_rx_dma_irq_handler
* DESCRIPTION
* lower level rx interrupt handler
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* p_buf [IN/OUT] pointer to rx data buffer
* max_len [IN] max length of rx buffer
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_rx_dma_irq_handler(struct _MTK_DMA_INFO_STR_ *p_dma_info,
unsigned char *p_buf, const unsigned int max_len);
/*****************************************************************************
* FUNCTION
* hal_dma_dump_reg
* DESCRIPTION
* dump BTIF module's information when needed
* PARAMETERS
* p_dma_info [IN] pointer to BTIF dma channel's information
* flag [IN] register id flag
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_dma_dump_reg(struct _MTK_DMA_INFO_STR_ *p_dma_info,
enum _ENUM_BTIF_REG_ID_ flag);
void hal_dma_dump_vfifo(struct _MTK_DMA_INFO_STR_ *p_dma_info);
int hal_dma_pm_ops(struct _MTK_DMA_INFO_STR_ *p_dma_info,
enum _MTK_BTIF_PM_OPID_ opid);
int hal_dma_tx_has_pending(struct _MTK_DMA_INFO_STR_ *p_dma_info);
int hal_dma_rx_has_pending(struct _MTK_DMA_INFO_STR_ *p_dma_info);
int hal_rx_dma_lock(bool enable);
#endif /*__HAL_BTIFD_DMA_PUB_H_*/
@@ -0,0 +1,115 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __HAL_BTIF_H_
#define __HAL_BTIF_H_
#ifndef CONFIG_OF
#define MTK_BTIF_REG_BASE BTIF_BASE
#endif
#if defined(CONFIG_MTK_CLKMGR)
#if defined(CONFIG_ARCH_MT6580)
#define MTK_BTIF_CG_BIT MT_CG_BTIF_SW_CG
#elif defined(CONFIG_ARCH_MT6735)
#define MTK_BTIF_CG_BIT MT_CG_PERI_BTIF
#elif defined(CONFIG_ARCH_MT6735M)
#define MTK_BTIF_CG_BIT MT_CG_PERI_BTIF
#elif defined(CONFIG_ARCH_MT6753)
#define MTK_BTIF_CG_BIT MT_CG_PERI_BTIF
#endif
#else
struct clk *clk_btif_apdma; /*btif apdma clock*/
struct clk *clk_btif; /*btif clock*/
#endif /* !defined(CONFIG_MTK_CLKMGR) */
#define BTIF_RBR(base) (unsigned long)(base + 0x0)
/*RX Buffer Register: read only */
#define BTIF_THR(base) (unsigned long)(base + 0x0)
/*Rx Holding Register: write only */
#define BTIF_IER(base) (unsigned long)(base + 0x4)
/*Interrupt Enable Register: read/write */
#define BTIF_IIR(base) (unsigned long)(base + 0x8)
/*Interrupt Identification Register: read only */
#define BTIF_FIFOCTRL(base) (unsigned long)(base + 0x8)
/*FIFO Control Register: write only */
#define BTIF_FAKELCR(base) (unsigned long)(base + 0xC)
/*FAKE LCR Register: read/write */
#define BTIF_LSR(base) (unsigned long)(base + 0x14)
/*Line Status Register: read only */
#define BTIF_SLEEP_EN(base) (unsigned long)(base + 0x48)
/*Sleep Enable Register: read/write */
#define BTIF_DMA_EN(base) (unsigned long)(base + 0x4C)
/*DMA Enable Register: read/write */
#define BTIF_RTOCNT(base) (unsigned long)(base + 0x54)
/*Rx Timeout Count Register: read/write */
#define BTIF_TRI_LVL(base) (unsigned long)(base + 0x60)
/*Tx/Rx Trigger Level Control Register: read/write */
#define BTIF_WAK(base) (unsigned long)(base + 0x64)
/*BTIF module wakeup Register: write only */
#define BTIF_WAT_TIME(base) (unsigned long)(base + 0x68)
/*BTIF ASYNC Wait Time Control Register: read/write */
#define BTIF_HANDSHAKE(base) (unsigned long)(base + 0x6C)
/*BTIF New Handshake Control Register: read/write */
/*BTIF_IER bits*/
#define BTIF_IER_TXEEN (0x1 << 1) /*1: Tx holding register is empty */
#define BTIF_IER_RXFEN (0x1 << 0) /*1: Rx buffer contains data */
/*BTIF_IIR bits*/
#define BTIF_IIR_NINT (0x1 << 0) /*No INT Pending */
#define BTIF_IIR_TX_EMPTY (0x1 << 1) /*Tx Holding Register empty */
#define BTIF_IIR_RX (0x1 << 2) /*Rx data received */
#define BTIF_IIR_RX_TIMEOUT (0x11 << 2) /*Rx data received */
/*BTIF_LSR bits*/
#define BTIF_LSR_DR_BIT (0x1 << 0)
#define BTIF_LSR_THRE_BIT (0x1 << 5)
#define BTIF_LSR_TEMT_BIT (0x1 << 6)
/*BTIF_FIFOCTRL bits*/
#define BTIF_FIFOCTRL_CLR_TX (0x1 << 2) /*Clear Tx FIRO */
#define BTIF_FIFOCTRL_CLR_RX (0x1 << 1) /*Clear Rx FIRO */
/*BTIF_FAKELCR bits*/
#define BTIF_FAKELCR_NORMAL_MODE 0x0
/*BTIF_SLEEP_EN bits*/
#define BTIF_SLEEP_EN_BIT (0x1 << 0) /*enable Sleep mode */
#define BTIF_SLEEP_DIS_BIT (0x0) /*disable sleep mode */
/*BTIF_DMA_EN bits*/
#define BTIF_DMA_EN_RX (0x1 << 0) /*Enable Rx DMA */
#define BTIF_DMA_EN_TX (0x1 << 1) /*Enable Tx DMA */
#define BTIF_DMA_EN_AUTORST_EN (0x1 << 2)
/*1: timeout counter will be auto reset */
#define BTIF_DMA_EN_AUTORST_DIS (0x0 << 2)
/* 0: after Rx timeout happens, */
/* SW shall reset the interrupt by reading BTIF 0x4C */
/*BTIF_TRI_LVL bits*/
#define BTIF_TRI_LVL_TX_MASK ((0xf) << 0)
#define BTIF_TRI_LVL_RX_MASK ((0x7) << 4)
#define BTIF_TRI_LVL_TX(x) ((x & 0xf) << 0)
#define BTIF_TRI_LVL_RX(x) ((x & 0x7) << 4)
#define BTIF_TRI_LOOP_EN (0x1 << 7)
#define BTIF_TRI_LOOP_DIS (0x0 << 7)
/*BTIF_WAK bits*/
#define BTIF_WAK_BIT (0x1 << 0)
/*BTIF_HANDSHAKE bits*/
#define BTIF_HANDSHAKE_EN_HANDSHAKE 1
#define BTIF_HANDSHAKE_DIS_HANDSHAKE 0
#define BTIF_TX_FIFO_SIZE 16
#define BTIF_RX_FIFO_SIZE 8
#define BTIF_TX_FIFO_THRE (BTIF_TX_FIFO_SIZE / 2)
#define BTIF_RX_FIFO_THRE 0x1 /* 0x5 */
#endif /*__HAL_BTIF_H_*/
@@ -0,0 +1,221 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __HAL_BTIF_PUB_H_
#define __HAL_BTIF_PUB_H_
#include "plat_common.h"
/*Enum Defination*/
/*BTIF Mode Enum */
enum _ENUM_BTIF_MODE_ {
BTIF_MODE_PIO = 0,
BTIF_MODE_DMA = BTIF_MODE_PIO + 1,
BTIF_MODE_MAX,
};
/*****************************************************************************
* FUNCTION
* hal_btif_info_get
* DESCRIPTION
* get btif's information included base address , irq related information
* PARAMETERS
* RETURNS
* BTIF's information
*****************************************************************************/
struct _MTK_BTIF_INFO_STR_ *hal_btif_info_get(void);
#if !defined(CONFIG_MTK_CLKMGR)
/*****************************************************************************
* FUNCTION
* hal_btif_clk_get_and_prepare
* DESCRIPTION
* get clock from device tree and prepare for enable/disable control
* PARAMETERS
* pdev device pointer
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_clk_get_and_prepare(struct platform_device *pdev);
/*****************************************************************************
* FUNCTION
* hal_btif_clk_unprepare
* DESCRIPTION
* unprepare btif clock and apdma clock
* PARAMETERS
* none
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_clk_unprepare(void);
#endif
/*****************************************************************************
* FUNCTION
* hal_btif_clk_ctrl
* DESCRIPTION
* control clock output enable/disable of BTIF module
* PARAMETERS
* p_base [IN] BTIF module's base address
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_clk_ctrl(struct _MTK_BTIF_INFO_STR_ *p_btif,
enum _ENUM_CLOCK_CTRL_ flag);
/*****************************************************************************
* FUNCTION
* hal_btif_hw_init
* DESCRIPTION
* BTIF module init, after this step, BTIF should enable to do tx/rx with PIO
* mode
* PARAMETERS
* p_base [IN] BTIF module's base address
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_hw_init(struct _MTK_BTIF_INFO_STR_ *p_btif);
/*****************************************************************************
* FUNCTION
* hal_btif_rx_cb_reg
* DESCRIPTION
* BTIF rx callback register API
* PARAMETERS
* p_btif_info [IN] pointer to BTIF's information
* rx_cb [IN] rx callback function
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_rx_cb_reg(struct _MTK_BTIF_INFO_STR_ *p_btif_info,
btif_rx_buf_write rx_cb);
/*****************************************************************************
* FUNCTION
* hal_btif_loopback_ctrl
* DESCRIPTION
* BTIF Tx/Rx loopback mode set, this operation can only be done
* after set BTIF to normal mode
* PARAMETERS
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_loopback_ctrl(struct _MTK_BTIF_INFO_STR_ *p_btif, bool en);
/*****************************************************************************
* FUNCTION
* hal_btif_rx_handler
* DESCRIPTION
* lower level interrupt handler
* PARAMETERS
* p_base [IN] BTIF module's base address
* p_buf [IN/OUT] pointer to rx data buffer
* max_len [IN] max length of rx buffer
* RETURNS
* 0 means success; negative means fail; positive means rx data length
*****************************************************************************/
int hal_btif_irq_handler(struct _MTK_BTIF_INFO_STR_ *p_btif,
unsigned char *p_buf, const unsigned int max_len);
/*****************************************************************************
* FUNCTION
* hal_btif_tx_mode_ctrl
* DESCRIPTION
* set BTIF tx to corresponding mode (PIO/DMA)
* PARAMETERS
* p_base [IN] BTIF module's base address
* mode [IN] rx mode <PIO/DMA>
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_tx_mode_ctrl(struct _MTK_BTIF_INFO_STR_ *p_btif,
enum _ENUM_BTIF_MODE_ mode);
/*****************************************************************************
* FUNCTION
* hal_btif_rx_mode_ctrl
* DESCRIPTION
* set BTIF rx to corresponding mode (PIO/DMA)
* PARAMETERS
* p_base [IN] BTIF module's base address
* mode [IN] rx mode <PIO/DMA>
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_rx_mode_ctrl(struct _MTK_BTIF_INFO_STR_ *p_btif,
enum _ENUM_BTIF_MODE_ mode);
/*****************************************************************************
* FUNCTION
* hal_btif_send_data
* DESCRIPTION
* send data through btif in FIFO mode
* PARAMETERS
* p_base [IN] BTIF module's base address
* p_buf [IN] pointer to rx data buffer
* max_len [IN] tx buffer length
* RETURNS
* positive means number of data sent;
* 0 means no data put to FIFO;
* negative means error happens
*****************************************************************************/
int hal_btif_send_data(struct _MTK_BTIF_INFO_STR_ *p_btif,
const unsigned char *p_buf, const unsigned int buf_len);
/*****************************************************************************
* FUNCTION
* hal_btif_raise_wak_sig
* DESCRIPTION
* raise wakeup signal to counterpart
* PARAMETERS
* p_base [IN] BTIF module's base address
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_raise_wak_sig(struct _MTK_BTIF_INFO_STR_ *p_btif);
/*****************************************************************************
* FUNCTION
* hal_btif_dump_reg
* DESCRIPTION
* dump BTIF module's information when needed
* PARAMETERS
* p_base [IN] BTIF module's base address
* flag [IN] register id flag
* RETURNS
* 0 means success, negative means fail
*****************************************************************************/
int hal_btif_dump_reg(struct _MTK_BTIF_INFO_STR_ *p_btif,
enum _ENUM_BTIF_REG_ID_ flag);
/*****************************************************************************
* FUNCTION
* hal_btif_is_tx_complete
* DESCRIPTION
* get tx complete flag
* PARAMETERS
* p_base [IN] BTIF module's base address
* RETURNS
* true means tx complete, false means tx in process
*****************************************************************************/
bool hal_btif_is_tx_complete(struct _MTK_BTIF_INFO_STR_ *p_btif);
/*****************************************************************************
* FUNCTION
* hal_btif_is_tx_allow
* DESCRIPTION
* whether tx is allowed
* PARAMETERS
* p_base [IN] BTIF module's base address
* RETURNS
* true if tx operation is allowed; false if tx is not allowed
*****************************************************************************/
bool hal_btif_is_tx_allow(struct _MTK_BTIF_INFO_STR_ *p_btif);
int hal_btif_pm_ops(struct _MTK_BTIF_INFO_STR_ *p_btif,
enum _MTK_BTIF_PM_OPID_ opid);
void mtk_btif_read_cpu_sw_rst_debug_plat(void);
#endif /*__HAL_BTIF_PUB_H_*/
@@ -0,0 +1,317 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2019 MediaTek Inc.
*/
#ifndef __HAL_PUB_H_
#define __HAL_PUB_H_
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
#include <linux/kfifo.h>
#include <linux/vmalloc.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/sched/rt.h>
#ifdef CONFIG_OF
#include <linux/of_irq.h>
#include <linux/of_address.h>
#include <linux/of.h>
#else
#include <mach/mt_reg_base.h>
#include <mach/mt_irq.h>
#endif
#if defined(CONFIG_MTK_CLKMGR)
#include <mach/mt_clkmgr.h>
#else
#include <linux/clk.h>
#include <linux/platform_device.h>
#endif /* defined(CONFIG_MTK_CLKMGR) */
extern int mtk_btif_hal_get_log_lvl(void);
#define MTK_BTIF_MARK_UNUSED_API
#define MTK_BTIF_ENABLE_CLK_CTL 1
#define MTK_BTIF_ENABLE_CLK_REF_COUNTER 1
#define DBG_LOG_STR_SIZE 256
/*Log defination*/
static int hal_log_print(const char *str, ...)
{
va_list args;
int ret;
char temp_sring[DBG_LOG_STR_SIZE];
va_start(args, str);
ret = vsnprintf(temp_sring, DBG_LOG_STR_SIZE, str, args);
va_end(args);
if (ret > 0)
pr_info("%s", temp_sring);
return ret;
}
#define BTIF_LOG_LOUD 4
#define BTIF_LOG_DBG 3
#define BTIF_LOG_INFO 2
#define BTIF_LOG_WARN 1
#define BTIF_LOG_ERR 0
#ifndef DFT_TAG
#define DFT_TAG "[BTIF-DFT]"
#endif
#define BTIF_LOUD_FUNC(fmt, arg ...) \
do { \
if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_LOUD) \
hal_log_print(DFT_TAG "[L]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define BTIF_INFO_FUNC(fmt, arg ...) \
do { \
if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_INFO)\
hal_log_print(DFT_TAG "[I]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define BTIF_WARN_FUNC(fmt, arg ...) \
do { \
if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_WARN)\
hal_log_print(DFT_TAG "[W]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define BTIF_ERR_FUNC(fmt, arg ...)\
do {\
if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_ERR)\
hal_log_print(DFT_TAG "[E]%s(%d):" fmt,\
__func__, __LINE__, ## arg);\
} while (0)
#define BTIF_DBG_FUNC(fmt, arg ...) \
do { \
if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_DBG) \
hal_log_print(DFT_TAG "[D]%s:" fmt, \
__func__, ## arg); \
} while (0)
#define BTIF_TRC_FUNC(f) \
do { \
if (mtk_btif_hal_get_log_lvl() >= BTIF_LOG_DBG) \
hal_log_print(DFT_TAG "<%s> <%d>\n", \
__func__, __LINE__); \
} while (0)
/*-------------------------------Enum Defination----------------------------*/
/*IRQ sensetive type */
enum _ENUM_IRQ_SENS_TYPE_ {
IRQ_SENS_EDGE = 0,
IRQ_SENS_LVL = IRQ_SENS_EDGE + 1,
IRQ_SENS_TYPE_MAX
};
/*IRQ level trigger type */
enum _ENUM_IRQ_LVL_TYPE_ {
IRQ_LVL_LOW = 0,
IRQ_LVL_HIGH = IRQ_LVL_LOW + 1,
IRQ_LVL_MAX
};
/*IRQ edge trigger type */
enum _ENUM_IRQ_EDGE_TYPE_ {
IRQ_EDGE_FALL = 0,
IRQ_EDGE_RAISE = IRQ_EDGE_FALL + 1,
IRQ_EDGE_BOTH = IRQ_EDGE_RAISE + 1,
IRQ_EDGE_MAX
};
enum _ENUM_CLOCK_CTRL_ {
CLK_OUT_DISABLE = 0,
CLK_OUT_ENABLE = CLK_OUT_DISABLE + 1,
CLK_OUT_MAX
};
/*Error No. table */
enum _ENUM_ERROR_CODE_ {
ERR_NO_ERROR = 0,
ERR_INVALID_PAR = ERR_NO_ERROR - 1,
ERR_MAX = ERR_INVALID_PAR - 1,
};
enum _ENUM_BTIF_DIR_ {
BTIF_TX = 0,
BTIF_RX = BTIF_TX + 1,
BTIF_DIR_MAX,
};
enum _ENUM_DMA_DIR_ {
DMA_DIR_RX = 0,
DMA_DIR_TX = DMA_DIR_RX + 1,
DMA_DIR_BOTH,
};
enum _ENUM_BTIF_REG_ID_ {
REG_IIR = 0, /*Interrupt Identification Register */
REG_LSR = 1, /*Line Status Register */
REG_FAKE_LCR = 2, /*Fake Lcr Regiseter */
REG_FIFO_CTRL = 3, /*FIFO Control Register */
REG_IER = 4, /*Interrupt Enable Register */
REG_SLEEP_EN = 5, /*Sleep Enable Register */
REG_RTO_COUNTER = 6, /*Rx Timeout Counter Register */
REG_DMA_EN = 7, /*DMA Enalbe Register */
REG_TRIG_LVL = 8, /*Tx/Rx Trigger Level Register */
REG_WAT_TIME = 9, /*Async Wait Time Register */
REG_HANDSHAKE = 10, /*New HandShake Mode Register */
REG_SLP_WAK = 11, /*Sleep Wakeup Reigster */
REG_ALL = 12, /*all registers */
REG_IRQ = 13, /*IRQ registers */
REG_MAX
};
enum _MTK_BTIF_PM_OPID_ {
BTIF_PM_DPIDLE_EN,
BTIF_PM_DPIDLE_DIS,
BTIF_PM_SUSPEND,
BTIF_PM_RESUME,
BTIF_PM_RESTORE_NOIRQ,
};
#define BTIF_HAL_TX_FIFO_SIZE (1024 * 4)
/*----------------------------Enum Defination End---------------------------*/
/*****************************structure definition***************************/
/*IRQ related information*/
struct _MTK_BTIF_IRQ_STR_ {
const char *name;
bool is_irq_sup;
unsigned int irq_id;
#ifdef CONFIG_OF
unsigned int irq_flags;
#else
enum _ENUM_IRQ_SENS_TYPE_ sens_type;
union {
enum _ENUM_IRQ_LVL_TYPE_ lvl_type;
enum _ENUM_IRQ_EDGE_TYPE_ edge_type;
};
#endif
bool reg_flag;
irq_handler_t p_irq_handler;
};
struct _DMA_VFIFO_ {
/*[Driver Access] vFIFO memory'svirtual address */
unsigned char *p_vir_addr;
/*[HW Access] dma handle, physical address, set to DMA's HW Register */
dma_addr_t phy_addr;
/*DMA's vFIFO size */
unsigned int vfifo_size;
/*DMA's threshold value */
unsigned int thre;
};
struct _MTK_DMA_INFO_STR_;
struct _MTK_BTIF_INFO_STR_;
typedef unsigned int (*dma_rx_buf_write) (
struct _MTK_DMA_INFO_STR_ *p_dma_info,
unsigned char *p_buf,
unsigned int buf_len);
typedef unsigned int (*btif_rx_buf_write) (
struct _MTK_BTIF_INFO_STR_ *p_btif_info,
unsigned char *p_buf,
unsigned int buf_len);
/*DMA related information*/
struct _MTK_DMA_INFO_STR_ {
unsigned long base;
enum _ENUM_DMA_DIR_ dir;
struct _MTK_BTIF_IRQ_STR_ *p_irq;
dma_rx_buf_write rx_cb;
struct _DMA_VFIFO_ *p_vfifo;
};
/*DMA related information*/
struct _MTK_BTIF_INFO_STR_ {
unsigned long base; /*base address */
struct _MTK_BTIF_IRQ_STR_ *p_irq; /*irq related information */
unsigned int tx_fifo_size; /*BTIF tx FIFO size */
unsigned int rx_fifo_size; /*BTIF rx FIFO size */
unsigned int tx_tri_lvl; /*BTIFtx trigger level in FIFO mode */
unsigned int rx_tri_lvl; /*BTIFrx trigger level in FIFO mode */
unsigned int clk_gat_addr; /*clock gating address */
unsigned int set_bit; /*enable clock gating bit */
unsigned int clr_bit; /*clear clock gating bit */
unsigned int rx_data_len; /*rx data length */
btif_rx_buf_write rx_cb;
struct kfifo *p_tx_fifo; /*tx fifo */
spinlock_t tx_fifo_spinlock; /*tx fifo spinlock */
};
/**********End of Structure Definition***********/
/***********register operation***********/
#ifdef __KERNEL__
/*byte write <1 byte> */
#define btif_reg_sync_writeb(v, a) \
do { \
writeb(v, (void __iomem *)a); \
/* call mb () */ \
mb(); \
} while (0)
/*word write <2 byte> */
#define btif_reg_sync_writew(v, a) \
do { \
writew(v, (void __iomem *)a); \
/* call mb () */ \
mb(); \
} while (0)
/*long write <4 byte> */
#define btif_reg_sync_writel(v, a) \
do { \
writel(v, (void __iomem *)a); \
/* call mb () */ \
mb(); \
} while (0)
#else
/*byte write <1 byte> */
#define btif_reg_sync_writeb(v, a) mt65xx_reg_sync_writeb(v, a)
/*word write <2 byte> */
#define btif_reg_sync_writew(v, a) mt65xx_reg_sync_writew(v, a)
/*long write <4 byte> */
#define btif_reg_sync_writel(v, a) mt65xx_reg_sync_writel(v, a)
#endif
#define BTIF_READ8(REG) __raw_readb((unsigned char *)(REG))
#define BTIF_READ16(REG) __raw_readw((unsigned short *)(REG))
#define BTIF_READ32(REG) __raw_readl((unsigned int *)(REG))
#define BTIF_SET_BIT(REG, BITVAL) do { \
writel(readl((unsigned int *)(REG)) | ((unsigned int)(BITVAL)), \
(unsigned int *)(REG)); \
mb(); /**/ \
} \
while (0)
#define BTIF_CLR_BIT(REG, BITVAL) do { \
writel(readl((unsigned int *)(REG)) & ~((unsigned int)(BITVAL)), \
(unsigned int *)(REG)); \
mb(); /**/\
} \
while (0)
/***********end of register operation *********/
#endif /*__HAL_PUB_H_*/