162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * Copyright (c) 2021, MediaTek Inc. 462306a36Sopenharmony_ci * Copyright (c) 2021-2022, Intel Corporation. 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Authors: 762306a36Sopenharmony_ci * Haijun Liu <haijun.liu@mediatek.com> 862306a36Sopenharmony_ci * Moises Veleta <moises.veleta@intel.com> 962306a36Sopenharmony_ci * Ricardo Martinez <ricardo.martinez@linux.intel.com> 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * Contributors: 1262306a36Sopenharmony_ci * Amir Hanania <amir.hanania@intel.com> 1362306a36Sopenharmony_ci * Andy Shevchenko <andriy.shevchenko@linux.intel.com> 1462306a36Sopenharmony_ci * Sreehari Kancharla <sreehari.kancharla@intel.com> 1562306a36Sopenharmony_ci */ 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#ifndef __T7XX_CLDMA_H__ 1862306a36Sopenharmony_ci#define __T7XX_CLDMA_H__ 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci#include <linux/bits.h> 2162306a36Sopenharmony_ci#include <linux/types.h> 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define CLDMA_TXQ_NUM 8 2462306a36Sopenharmony_ci#define CLDMA_RXQ_NUM 8 2562306a36Sopenharmony_ci#define CLDMA_ALL_Q GENMASK(7, 0) 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* Interrupt status bits */ 2862306a36Sopenharmony_ci#define EMPTY_STATUS_BITMASK GENMASK(15, 8) 2962306a36Sopenharmony_ci#define TXRX_STATUS_BITMASK GENMASK(7, 0) 3062306a36Sopenharmony_ci#define EQ_STA_BIT_OFFSET 8 3162306a36Sopenharmony_ci#define L2_INT_BIT_COUNT 16 3262306a36Sopenharmony_ci#define EQ_STA_BIT(index) (BIT((index) + EQ_STA_BIT_OFFSET) & EMPTY_STATUS_BITMASK) 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#define TQ_ERR_INT_BITMASK GENMASK(23, 16) 3562306a36Sopenharmony_ci#define TQ_ACTIVE_START_ERR_INT_BITMASK GENMASK(31, 24) 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#define RQ_ERR_INT_BITMASK GENMASK(23, 16) 3862306a36Sopenharmony_ci#define RQ_ACTIVE_START_ERR_INT_BITMASK GENMASK(31, 24) 3962306a36Sopenharmony_ci 4062306a36Sopenharmony_ci#define CLDMA0_AO_BASE 0x10049000 4162306a36Sopenharmony_ci#define CLDMA0_PD_BASE 0x1021d000 4262306a36Sopenharmony_ci#define CLDMA1_AO_BASE 0x1004b000 4362306a36Sopenharmony_ci#define CLDMA1_PD_BASE 0x1021f000 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci#define CLDMA_R_AO_BASE 0x10023000 4662306a36Sopenharmony_ci#define CLDMA_R_PD_BASE 0x1023d000 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci/* CLDMA TX */ 4962306a36Sopenharmony_ci#define REG_CLDMA_UL_START_ADDRL_0 0x0004 5062306a36Sopenharmony_ci#define REG_CLDMA_UL_START_ADDRH_0 0x0008 5162306a36Sopenharmony_ci#define REG_CLDMA_UL_CURRENT_ADDRL_0 0x0044 5262306a36Sopenharmony_ci#define REG_CLDMA_UL_CURRENT_ADDRH_0 0x0048 5362306a36Sopenharmony_ci#define REG_CLDMA_UL_STATUS 0x0084 5462306a36Sopenharmony_ci#define REG_CLDMA_UL_START_CMD 0x0088 5562306a36Sopenharmony_ci#define REG_CLDMA_UL_RESUME_CMD 0x008c 5662306a36Sopenharmony_ci#define REG_CLDMA_UL_STOP_CMD 0x0090 5762306a36Sopenharmony_ci#define REG_CLDMA_UL_ERROR 0x0094 5862306a36Sopenharmony_ci#define REG_CLDMA_UL_CFG 0x0098 5962306a36Sopenharmony_ci#define UL_CFG_BIT_MODE_36 BIT(5) 6062306a36Sopenharmony_ci#define UL_CFG_BIT_MODE_40 BIT(6) 6162306a36Sopenharmony_ci#define UL_CFG_BIT_MODE_64 BIT(7) 6262306a36Sopenharmony_ci#define UL_CFG_BIT_MODE_MASK GENMASK(7, 5) 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci#define REG_CLDMA_UL_MEM 0x009c 6562306a36Sopenharmony_ci#define UL_MEM_CHECK_DIS BIT(0) 6662306a36Sopenharmony_ci 6762306a36Sopenharmony_ci/* CLDMA RX */ 6862306a36Sopenharmony_ci#define REG_CLDMA_DL_START_CMD 0x05bc 6962306a36Sopenharmony_ci#define REG_CLDMA_DL_RESUME_CMD 0x05c0 7062306a36Sopenharmony_ci#define REG_CLDMA_DL_STOP_CMD 0x05c4 7162306a36Sopenharmony_ci#define REG_CLDMA_DL_MEM 0x0508 7262306a36Sopenharmony_ci#define DL_MEM_CHECK_DIS BIT(0) 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci#define REG_CLDMA_DL_CFG 0x0404 7562306a36Sopenharmony_ci#define DL_CFG_UP_HW_LAST BIT(2) 7662306a36Sopenharmony_ci#define DL_CFG_BIT_MODE_36 BIT(10) 7762306a36Sopenharmony_ci#define DL_CFG_BIT_MODE_40 BIT(11) 7862306a36Sopenharmony_ci#define DL_CFG_BIT_MODE_64 BIT(12) 7962306a36Sopenharmony_ci#define DL_CFG_BIT_MODE_MASK GENMASK(12, 10) 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci#define REG_CLDMA_DL_START_ADDRL_0 0x0478 8262306a36Sopenharmony_ci#define REG_CLDMA_DL_START_ADDRH_0 0x047c 8362306a36Sopenharmony_ci#define REG_CLDMA_DL_CURRENT_ADDRL_0 0x04b8 8462306a36Sopenharmony_ci#define REG_CLDMA_DL_CURRENT_ADDRH_0 0x04bc 8562306a36Sopenharmony_ci#define REG_CLDMA_DL_STATUS 0x04f8 8662306a36Sopenharmony_ci 8762306a36Sopenharmony_ci/* CLDMA MISC */ 8862306a36Sopenharmony_ci#define REG_CLDMA_L2TISAR0 0x0810 8962306a36Sopenharmony_ci#define REG_CLDMA_L2TISAR1 0x0814 9062306a36Sopenharmony_ci#define REG_CLDMA_L2TIMR0 0x0818 9162306a36Sopenharmony_ci#define REG_CLDMA_L2TIMR1 0x081c 9262306a36Sopenharmony_ci#define REG_CLDMA_L2TIMCR0 0x0820 9362306a36Sopenharmony_ci#define REG_CLDMA_L2TIMCR1 0x0824 9462306a36Sopenharmony_ci#define REG_CLDMA_L2TIMSR0 0x0828 9562306a36Sopenharmony_ci#define REG_CLDMA_L2TIMSR1 0x082c 9662306a36Sopenharmony_ci#define REG_CLDMA_L3TISAR0 0x0830 9762306a36Sopenharmony_ci#define REG_CLDMA_L3TISAR1 0x0834 9862306a36Sopenharmony_ci#define REG_CLDMA_L2RISAR0 0x0850 9962306a36Sopenharmony_ci#define REG_CLDMA_L2RISAR1 0x0854 10062306a36Sopenharmony_ci#define REG_CLDMA_L3RISAR0 0x0870 10162306a36Sopenharmony_ci#define REG_CLDMA_L3RISAR1 0x0874 10262306a36Sopenharmony_ci#define REG_CLDMA_IP_BUSY 0x08b4 10362306a36Sopenharmony_ci#define IP_BUSY_WAKEUP BIT(0) 10462306a36Sopenharmony_ci#define CLDMA_L2TISAR0_ALL_INT_MASK GENMASK(15, 0) 10562306a36Sopenharmony_ci#define CLDMA_L2RISAR0_ALL_INT_MASK GENMASK(15, 0) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci/* CLDMA MISC */ 10862306a36Sopenharmony_ci#define REG_CLDMA_L2RIMR0 0x0858 10962306a36Sopenharmony_ci#define REG_CLDMA_L2RIMR1 0x085c 11062306a36Sopenharmony_ci#define REG_CLDMA_L2RIMCR0 0x0860 11162306a36Sopenharmony_ci#define REG_CLDMA_L2RIMCR1 0x0864 11262306a36Sopenharmony_ci#define REG_CLDMA_L2RIMSR0 0x0868 11362306a36Sopenharmony_ci#define REG_CLDMA_L2RIMSR1 0x086c 11462306a36Sopenharmony_ci#define REG_CLDMA_BUSY_MASK 0x0954 11562306a36Sopenharmony_ci#define BUSY_MASK_PCIE BIT(0) 11662306a36Sopenharmony_ci#define BUSY_MASK_AP BIT(1) 11762306a36Sopenharmony_ci#define BUSY_MASK_MD BIT(2) 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci#define REG_CLDMA_INT_MASK 0x0960 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci/* CLDMA RESET */ 12262306a36Sopenharmony_ci#define REG_INFRA_RST4_SET 0x0730 12362306a36Sopenharmony_ci#define RST4_CLDMA1_SW_RST_SET BIT(20) 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci#define REG_INFRA_RST4_CLR 0x0734 12662306a36Sopenharmony_ci#define RST4_CLDMA1_SW_RST_CLR BIT(20) 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci#define REG_INFRA_RST2_SET 0x0140 12962306a36Sopenharmony_ci#define RST2_PMIC_SW_RST_SET BIT(18) 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci#define REG_INFRA_RST2_CLR 0x0144 13262306a36Sopenharmony_ci#define RST2_PMIC_SW_RST_CLR BIT(18) 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_cienum mtk_txrx { 13562306a36Sopenharmony_ci MTK_TX, 13662306a36Sopenharmony_ci MTK_RX, 13762306a36Sopenharmony_ci}; 13862306a36Sopenharmony_ci 13962306a36Sopenharmony_cienum t7xx_hw_mode { 14062306a36Sopenharmony_ci MODE_BIT_32, 14162306a36Sopenharmony_ci MODE_BIT_36, 14262306a36Sopenharmony_ci MODE_BIT_40, 14362306a36Sopenharmony_ci MODE_BIT_64, 14462306a36Sopenharmony_ci}; 14562306a36Sopenharmony_ci 14662306a36Sopenharmony_cistruct t7xx_cldma_hw { 14762306a36Sopenharmony_ci enum t7xx_hw_mode hw_mode; 14862306a36Sopenharmony_ci void __iomem *ap_ao_base; 14962306a36Sopenharmony_ci void __iomem *ap_pdn_base; 15062306a36Sopenharmony_ci u32 phy_interrupt_id; 15162306a36Sopenharmony_ci}; 15262306a36Sopenharmony_ci 15362306a36Sopenharmony_civoid t7xx_cldma_hw_irq_dis_txrx(struct t7xx_cldma_hw *hw_info, unsigned int qno, 15462306a36Sopenharmony_ci enum mtk_txrx tx_rx); 15562306a36Sopenharmony_civoid t7xx_cldma_hw_irq_dis_eq(struct t7xx_cldma_hw *hw_info, unsigned int qno, 15662306a36Sopenharmony_ci enum mtk_txrx tx_rx); 15762306a36Sopenharmony_civoid t7xx_cldma_hw_irq_en_txrx(struct t7xx_cldma_hw *hw_info, unsigned int qno, 15862306a36Sopenharmony_ci enum mtk_txrx tx_rx); 15962306a36Sopenharmony_civoid t7xx_cldma_hw_irq_en_eq(struct t7xx_cldma_hw *hw_info, unsigned int qno, enum mtk_txrx tx_rx); 16062306a36Sopenharmony_ciunsigned int t7xx_cldma_hw_queue_status(struct t7xx_cldma_hw *hw_info, unsigned int qno, 16162306a36Sopenharmony_ci enum mtk_txrx tx_rx); 16262306a36Sopenharmony_civoid t7xx_cldma_hw_init(struct t7xx_cldma_hw *hw_info); 16362306a36Sopenharmony_civoid t7xx_cldma_hw_resume_queue(struct t7xx_cldma_hw *hw_info, unsigned int qno, 16462306a36Sopenharmony_ci enum mtk_txrx tx_rx); 16562306a36Sopenharmony_civoid t7xx_cldma_hw_start(struct t7xx_cldma_hw *hw_info); 16662306a36Sopenharmony_civoid t7xx_cldma_hw_start_queue(struct t7xx_cldma_hw *hw_info, unsigned int qno, 16762306a36Sopenharmony_ci enum mtk_txrx tx_rx); 16862306a36Sopenharmony_civoid t7xx_cldma_hw_tx_done(struct t7xx_cldma_hw *hw_info, unsigned int bitmask); 16962306a36Sopenharmony_civoid t7xx_cldma_hw_rx_done(struct t7xx_cldma_hw *hw_info, unsigned int bitmask); 17062306a36Sopenharmony_civoid t7xx_cldma_hw_stop_all_qs(struct t7xx_cldma_hw *hw_info, enum mtk_txrx tx_rx); 17162306a36Sopenharmony_civoid t7xx_cldma_hw_set_start_addr(struct t7xx_cldma_hw *hw_info, 17262306a36Sopenharmony_ci unsigned int qno, u64 address, enum mtk_txrx tx_rx); 17362306a36Sopenharmony_civoid t7xx_cldma_hw_reset(void __iomem *ao_base); 17462306a36Sopenharmony_civoid t7xx_cldma_hw_stop(struct t7xx_cldma_hw *hw_info, enum mtk_txrx tx_rx); 17562306a36Sopenharmony_ciunsigned int t7xx_cldma_hw_int_status(struct t7xx_cldma_hw *hw_info, unsigned int bitmask, 17662306a36Sopenharmony_ci enum mtk_txrx tx_rx); 17762306a36Sopenharmony_civoid t7xx_cldma_hw_restore(struct t7xx_cldma_hw *hw_info); 17862306a36Sopenharmony_civoid t7xx_cldma_clear_ip_busy(struct t7xx_cldma_hw *hw_info); 17962306a36Sopenharmony_cibool t7xx_cldma_tx_addr_is_set(struct t7xx_cldma_hw *hw_info, unsigned int qno); 18062306a36Sopenharmony_ci#endif 181