194fb0ef4SVince Bridgers /* Altera TSE SGDMA and MSGDMA Linux driver 294fb0ef4SVince Bridgers * Copyright (C) 2014 Altera Corporation. All rights reserved 394fb0ef4SVince Bridgers * 494fb0ef4SVince Bridgers * This program is free software; you can redistribute it and/or modify it 594fb0ef4SVince Bridgers * under the terms and conditions of the GNU General Public License, 694fb0ef4SVince Bridgers * version 2, as published by the Free Software Foundation. 794fb0ef4SVince Bridgers * 894fb0ef4SVince Bridgers * This program is distributed in the hope it will be useful, but WITHOUT 994fb0ef4SVince Bridgers * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1094fb0ef4SVince Bridgers * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 1194fb0ef4SVince Bridgers * more details. 1294fb0ef4SVince Bridgers * 1394fb0ef4SVince Bridgers * You should have received a copy of the GNU General Public License along with 1494fb0ef4SVince Bridgers * this program. If not, see <http://www.gnu.org/licenses/>. 1594fb0ef4SVince Bridgers */ 1694fb0ef4SVince Bridgers 1794fb0ef4SVince Bridgers #ifndef __ALTERA_MSGDMAHW_H__ 1894fb0ef4SVince Bridgers #define __ALTERA_MSGDMAHW_H__ 1994fb0ef4SVince Bridgers 2094fb0ef4SVince Bridgers /* mSGDMA extended descriptor format 2194fb0ef4SVince Bridgers */ 2294fb0ef4SVince Bridgers struct msgdma_extended_desc { 2394fb0ef4SVince Bridgers u32 read_addr_lo; /* data buffer source address low bits */ 2494fb0ef4SVince Bridgers u32 write_addr_lo; /* data buffer destination address low bits */ 2594fb0ef4SVince Bridgers u32 len; /* the number of bytes to transfer 2694fb0ef4SVince Bridgers * per descriptor 2794fb0ef4SVince Bridgers */ 2894fb0ef4SVince Bridgers u32 burst_seq_num; /* bit 31:24 write burst 2994fb0ef4SVince Bridgers * bit 23:16 read burst 3094fb0ef4SVince Bridgers * bit 15:0 sequence number 3194fb0ef4SVince Bridgers */ 3294fb0ef4SVince Bridgers u32 stride; /* bit 31:16 write stride 3394fb0ef4SVince Bridgers * bit 15:0 read stride 3494fb0ef4SVince Bridgers */ 3594fb0ef4SVince Bridgers u32 read_addr_hi; /* data buffer source address high bits */ 3694fb0ef4SVince Bridgers u32 write_addr_hi; /* data buffer destination address high bits */ 3794fb0ef4SVince Bridgers u32 control; /* characteristics of the transfer */ 3894fb0ef4SVince Bridgers }; 3994fb0ef4SVince Bridgers 4094fb0ef4SVince Bridgers /* mSGDMA descriptor control field bit definitions 4194fb0ef4SVince Bridgers */ 4294fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_SET_CH(x) ((x) & 0xff) 4394fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GEN_SOP BIT(8) 4494fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GEN_EOP BIT(9) 4594fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_PARK_READS BIT(10) 4694fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_PARK_WRITES BIT(11) 4794fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_END_ON_EOP BIT(12) 4894fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_END_ON_LEN BIT(13) 4994fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TR_COMP_IRQ BIT(14) 5094fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_EARLY_IRQ BIT(15) 5194fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TR_ERR_IRQ (0xff << 16) 5294fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_EARLY_DONE BIT(24) 5394fb0ef4SVince Bridgers /* Writing ‘1’ to the ‘go’ bit commits the entire descriptor into the 5494fb0ef4SVince Bridgers * descriptor FIFO(s) 5594fb0ef4SVince Bridgers */ 5694fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_GO BIT(31) 5794fb0ef4SVince Bridgers 5894fb0ef4SVince Bridgers /* Tx buffer control flags 5994fb0ef4SVince Bridgers */ 6094fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_FIRST (MSGDMA_DESC_CTL_GEN_SOP | \ 6194fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 6294fb0ef4SVince Bridgers 63*20d96964SChee Nouk Phoon #define MSGDMA_DESC_CTL_TX_MIDDLE (MSGDMA_DESC_CTL_GO) 6494fb0ef4SVince Bridgers 6594fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_LAST (MSGDMA_DESC_CTL_GEN_EOP | \ 6694fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 6794fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 6894fb0ef4SVince Bridgers 6994fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_TX_SINGLE (MSGDMA_DESC_CTL_GEN_SOP | \ 7094fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GEN_EOP | \ 7194fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 7294fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 7394fb0ef4SVince Bridgers 7494fb0ef4SVince Bridgers #define MSGDMA_DESC_CTL_RX_SINGLE (MSGDMA_DESC_CTL_END_ON_EOP | \ 7594fb0ef4SVince Bridgers MSGDMA_DESC_CTL_END_ON_LEN | \ 7694fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_COMP_IRQ | \ 7794fb0ef4SVince Bridgers MSGDMA_DESC_CTL_EARLY_IRQ | \ 7894fb0ef4SVince Bridgers MSGDMA_DESC_CTL_TR_ERR_IRQ | \ 7994fb0ef4SVince Bridgers MSGDMA_DESC_CTL_GO) 8094fb0ef4SVince Bridgers 8194fb0ef4SVince Bridgers /* mSGDMA extended descriptor stride definitions 8294fb0ef4SVince Bridgers */ 8394fb0ef4SVince Bridgers #define MSGDMA_DESC_TX_STRIDE (0x00010001) 8494fb0ef4SVince Bridgers #define MSGDMA_DESC_RX_STRIDE (0x00010001) 8594fb0ef4SVince Bridgers 8694fb0ef4SVince Bridgers /* mSGDMA dispatcher control and status register map 8794fb0ef4SVince Bridgers */ 8894fb0ef4SVince Bridgers struct msgdma_csr { 8994fb0ef4SVince Bridgers u32 status; /* Read/Clear */ 9094fb0ef4SVince Bridgers u32 control; /* Read/Write */ 9194fb0ef4SVince Bridgers u32 rw_fill_level; /* bit 31:16 - write fill level 9294fb0ef4SVince Bridgers * bit 15:0 - read fill level 9394fb0ef4SVince Bridgers */ 9494fb0ef4SVince Bridgers u32 resp_fill_level; /* bit 15:0 */ 9594fb0ef4SVince Bridgers u32 rw_seq_num; /* bit 31:16 - write sequence number 9694fb0ef4SVince Bridgers * bit 15:0 - read sequence number 9794fb0ef4SVince Bridgers */ 9894fb0ef4SVince Bridgers u32 pad[3]; /* reserved */ 9994fb0ef4SVince Bridgers }; 10094fb0ef4SVince Bridgers 10194fb0ef4SVince Bridgers /* mSGDMA CSR status register bit definitions 10294fb0ef4SVince Bridgers */ 10394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_BUSY BIT(0) 10494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_EMPTY BIT(1) 10594fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_FULL BIT(2) 10694fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_EMPTY BIT(3) 10794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_FULL BIT(4) 10894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED BIT(5) 10994fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESETTING BIT(6) 11094fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_ERR BIT(7) 11194fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_EARLY BIT(8) 11294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_IRQ BIT(9) 11394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_MASK 0x3FF 11494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_MASK_WITHOUT_IRQ 0x1FF 11594fb0ef4SVince Bridgers 11694fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_BUSY_GET(v) GET_BIT_VALUE(v, 0) 11794fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_EMPTY_GET(v) GET_BIT_VALUE(v, 1) 11894fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_DESC_BUF_FULL_GET(v) GET_BIT_VALUE(v, 2) 11994fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_EMPTY_GET(v) GET_BIT_VALUE(v, 3) 12094fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESP_BUF_FULL_GET(v) GET_BIT_VALUE(v, 4) 12194fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_GET(v) GET_BIT_VALUE(v, 5) 12294fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_RESETTING_GET(v) GET_BIT_VALUE(v, 6) 12394fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_ERR_GET(v) GET_BIT_VALUE(v, 7) 12494fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_STOPPED_ON_EARLY_GET(v) GET_BIT_VALUE(v, 8) 12594fb0ef4SVince Bridgers #define MSGDMA_CSR_STAT_IRQ_GET(v) GET_BIT_VALUE(v, 9) 12694fb0ef4SVince Bridgers 12794fb0ef4SVince Bridgers /* mSGDMA CSR control register bit definitions 12894fb0ef4SVince Bridgers */ 12994fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP BIT(0) 13094fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_RESET BIT(1) 13194fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_ON_ERR BIT(2) 13294fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_ON_EARLY BIT(3) 13394fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_GLOBAL_INTR BIT(4) 13494fb0ef4SVince Bridgers #define MSGDMA_CSR_CTL_STOP_DESCS BIT(5) 13594fb0ef4SVince Bridgers 13694fb0ef4SVince Bridgers /* mSGDMA CSR fill level bits 13794fb0ef4SVince Bridgers */ 13894fb0ef4SVince Bridgers #define MSGDMA_CSR_WR_FILL_LEVEL_GET(v) (((v) & 0xffff0000) >> 16) 13994fb0ef4SVince Bridgers #define MSGDMA_CSR_RD_FILL_LEVEL_GET(v) ((v) & 0x0000ffff) 14094fb0ef4SVince Bridgers #define MSGDMA_CSR_RESP_FILL_LEVEL_GET(v) ((v) & 0x0000ffff) 14194fb0ef4SVince Bridgers 14294fb0ef4SVince Bridgers /* mSGDMA response register map 14394fb0ef4SVince Bridgers */ 14494fb0ef4SVince Bridgers struct msgdma_response { 14594fb0ef4SVince Bridgers u32 bytes_transferred; 14694fb0ef4SVince Bridgers u32 status; 14794fb0ef4SVince Bridgers }; 14894fb0ef4SVince Bridgers 14989830580SVince Bridgers #define msgdma_respoffs(a) (offsetof(struct msgdma_response, a)) 15089830580SVince Bridgers #define msgdma_csroffs(a) (offsetof(struct msgdma_csr, a)) 15189830580SVince Bridgers #define msgdma_descroffs(a) (offsetof(struct msgdma_extended_desc, a)) 15289830580SVince Bridgers 15394fb0ef4SVince Bridgers /* mSGDMA response register bit definitions 15494fb0ef4SVince Bridgers */ 15594fb0ef4SVince Bridgers #define MSGDMA_RESP_EARLY_TERM BIT(8) 15694fb0ef4SVince Bridgers #define MSGDMA_RESP_ERR_MASK 0xFF 15794fb0ef4SVince Bridgers 15894fb0ef4SVince Bridgers #endif /* __ALTERA_MSGDMA_H__*/ 159