162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci/* Altera TSE SGDMA and MSGDMA Linux driver 362306a36Sopenharmony_ci * Copyright (C) 2014 Altera Corporation. All rights reserved 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef __ALTERA_MSGDMAHW_H__ 762306a36Sopenharmony_ci#define __ALTERA_MSGDMAHW_H__ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci/* mSGDMA extended descriptor format 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_cistruct msgdma_extended_desc { 1262306a36Sopenharmony_ci u32 read_addr_lo; /* data buffer source address low bits */ 1362306a36Sopenharmony_ci u32 write_addr_lo; /* data buffer destination address low bits */ 1462306a36Sopenharmony_ci u32 len; /* the number of bytes to transfer 1562306a36Sopenharmony_ci * per descriptor 1662306a36Sopenharmony_ci */ 1762306a36Sopenharmony_ci u32 burst_seq_num; /* bit 31:24 write burst 1862306a36Sopenharmony_ci * bit 23:16 read burst 1962306a36Sopenharmony_ci * bit 15:0 sequence number 2062306a36Sopenharmony_ci */ 2162306a36Sopenharmony_ci u32 stride; /* bit 31:16 write stride 2262306a36Sopenharmony_ci * bit 15:0 read stride 2362306a36Sopenharmony_ci */ 2462306a36Sopenharmony_ci u32 read_addr_hi; /* data buffer source address high bits */ 2562306a36Sopenharmony_ci u32 write_addr_hi; /* data buffer destination address high bits */ 2662306a36Sopenharmony_ci u32 control; /* characteristics of the transfer */ 2762306a36Sopenharmony_ci}; 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci/* mSGDMA descriptor control field bit definitions 3062306a36Sopenharmony_ci */ 3162306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_SET_CH(x) ((x) & 0xff) 3262306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_GEN_SOP BIT(8) 3362306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_GEN_EOP BIT(9) 3462306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_PARK_READS BIT(10) 3562306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_PARK_WRITES BIT(11) 3662306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_END_ON_EOP BIT(12) 3762306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_END_ON_LEN BIT(13) 3862306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_TR_COMP_IRQ BIT(14) 3962306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_EARLY_IRQ BIT(15) 4062306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_TR_ERR_IRQ (0xff << 16) 4162306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_EARLY_DONE BIT(24) 4262306a36Sopenharmony_ci/* Writing ‘1’ to the ‘go’ bit commits the entire descriptor into the 4362306a36Sopenharmony_ci * descriptor FIFO(s) 4462306a36Sopenharmony_ci */ 4562306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_GO BIT(31) 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci/* Tx buffer control flags 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \ 5062306a36Sopenharmony_ci MSGDMA_DESC_CTL_GO) 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_GO) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \ 5562306a36Sopenharmony_ci MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 5662306a36Sopenharmony_ci MSGDMA_DESC_CTL_GO) 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \ 5962306a36Sopenharmony_ci MSGDMA_DESC_CTL_GEN_EOP | \ 6062306a36Sopenharmony_ci MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 6162306a36Sopenharmony_ci MSGDMA_DESC_CTL_GO) 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci#define MSGDMA_DESC_CTL_RX_SINGLE (MSGDMA_DESC_CTL_END_ON_EOP | \ 6462306a36Sopenharmony_ci MSGDMA_DESC_CTL_END_ON_LEN | \ 6562306a36Sopenharmony_ci MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 6662306a36Sopenharmony_ci MSGDMA_DESC_CTL_EARLY_IRQ | \ 6762306a36Sopenharmony_ci MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 6862306a36Sopenharmony_ci MSGDMA_DESC_CTL_GO) 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* mSGDMA extended descriptor stride definitions 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci#define MSGDMA_DESC_TX_STRIDE (0x00010001) 7362306a36Sopenharmony_ci#define MSGDMA_DESC_RX_STRIDE (0x00010001) 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci/* mSGDMA dispatcher control and status register map 7662306a36Sopenharmony_ci */ 7762306a36Sopenharmony_cistruct msgdma_csr { 7862306a36Sopenharmony_ci u32 status; /* Read/Clear */ 7962306a36Sopenharmony_ci u32 control; /* Read/Write */ 8062306a36Sopenharmony_ci u32 rw_fill_level; /* bit 31:16 - write fill level 8162306a36Sopenharmony_ci * bit 15:0 - read fill level 8262306a36Sopenharmony_ci */ 8362306a36Sopenharmony_ci u32 resp_fill_level; /* bit 15:0 */ 8462306a36Sopenharmony_ci u32 rw_seq_num; /* bit 31:16 - write sequence number 8562306a36Sopenharmony_ci * bit 15:0 - read sequence number 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_ci u32 pad[3]; /* reserved */ 8862306a36Sopenharmony_ci}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* mSGDMA CSR status register bit definitions 9162306a36Sopenharmony_ci */ 9262306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_BUSY BIT(0) 9362306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_DESC_BUF_EMPTY BIT(1) 9462306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_DESC_BUF_FULL BIT(2) 9562306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_RESP_BUF_EMPTY BIT(3) 9662306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_RESP_BUF_FULL BIT(4) 9762306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_STOPPED BIT(5) 9862306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_RESETTING BIT(6) 9962306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_STOPPED_ON_ERR BIT(7) 10062306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_STOPPED_ON_EARLY BIT(8) 10162306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_IRQ BIT(9) 10262306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_MASK 0x3FF 10362306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_MASK_WITHOUT_IRQ 0x1FF 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_BUSY_GET(v) GET_BIT_VALUE(v, 0) 10662306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_DESC_BUF_EMPTY_GET(v) GET_BIT_VALUE(v, 1) 10762306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_DESC_BUF_FULL_GET(v) GET_BIT_VALUE(v, 2) 10862306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_RESP_BUF_EMPTY_GET(v) GET_BIT_VALUE(v, 3) 10962306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_RESP_BUF_FULL_GET(v) GET_BIT_VALUE(v, 4) 11062306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_STOPPED_GET(v) GET_BIT_VALUE(v, 5) 11162306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_RESETTING_GET(v) GET_BIT_VALUE(v, 6) 11262306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_STOPPED_ON_ERR_GET(v) GET_BIT_VALUE(v, 7) 11362306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_STOPPED_ON_EARLY_GET(v) GET_BIT_VALUE(v, 8) 11462306a36Sopenharmony_ci#define MSGDMA_CSR_STAT_IRQ_GET(v) GET_BIT_VALUE(v, 9) 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/* mSGDMA CSR control register bit definitions 11762306a36Sopenharmony_ci */ 11862306a36Sopenharmony_ci#define MSGDMA_CSR_CTL_STOP BIT(0) 11962306a36Sopenharmony_ci#define MSGDMA_CSR_CTL_RESET BIT(1) 12062306a36Sopenharmony_ci#define MSGDMA_CSR_CTL_STOP_ON_ERR BIT(2) 12162306a36Sopenharmony_ci#define MSGDMA_CSR_CTL_STOP_ON_EARLY BIT(3) 12262306a36Sopenharmony_ci#define MSGDMA_CSR_CTL_GLOBAL_INTR BIT(4) 12362306a36Sopenharmony_ci#define MSGDMA_CSR_CTL_STOP_DESCS BIT(5) 12462306a36Sopenharmony_ci 12562306a36Sopenharmony_ci/* mSGDMA CSR fill level bits 12662306a36Sopenharmony_ci */ 12762306a36Sopenharmony_ci#define MSGDMA_CSR_WR_FILL_LEVEL_GET(v) (((v) & 0xffff0000) >> 16) 12862306a36Sopenharmony_ci#define MSGDMA_CSR_RD_FILL_LEVEL_GET(v) ((v) & 0x0000ffff) 12962306a36Sopenharmony_ci#define MSGDMA_CSR_RESP_FILL_LEVEL_GET(v) ((v) & 0x0000ffff) 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci/* mSGDMA response register map 13262306a36Sopenharmony_ci */ 13362306a36Sopenharmony_cistruct msgdma_response { 13462306a36Sopenharmony_ci u32 bytes_transferred; 13562306a36Sopenharmony_ci u32 status; 13662306a36Sopenharmony_ci}; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci#define msgdma_respoffs(a) (offsetof(struct msgdma_response, a)) 13962306a36Sopenharmony_ci#define msgdma_csroffs(a) (offsetof(struct msgdma_csr, a)) 14062306a36Sopenharmony_ci#define msgdma_descroffs(a) (offsetof(struct msgdma_extended_desc, a)) 14162306a36Sopenharmony_ci 14262306a36Sopenharmony_ci/* mSGDMA response register bit definitions 14362306a36Sopenharmony_ci */ 14462306a36Sopenharmony_ci#define MSGDMA_RESP_EARLY_TERM BIT(8) 14562306a36Sopenharmony_ci#define MSGDMA_RESP_ERR_MASK 0xFF 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci#endif /* __ALTERA_MSGDMA_H__*/ 148