/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.3*4* Authors: Shlomi Gridish <[email protected]>5* Li Yang <[email protected]>6*7* Description:8* Internal header file for UCC SLOW unit routines.9*/10#ifndef __UCC_SLOW_H__11#define __UCC_SLOW_H__1213#include <linux/types.h>1415#include <soc/fsl/qe/immap_qe.h>16#include <soc/fsl/qe/qe.h>1718#include <soc/fsl/qe/ucc.h>1920/* transmit BD's status */21#define T_R 0x80000000 /* ready bit */22#define T_PAD 0x40000000 /* add pads to short frames */23#define T_W 0x20000000 /* wrap bit */24#define T_I 0x10000000 /* interrupt on completion */25#define T_L 0x08000000 /* last */2627#define T_A 0x04000000 /* Address - the data transmitted as address28chars */29#define T_TC 0x04000000 /* transmit CRC */30#define T_CM 0x02000000 /* continuous mode */31#define T_DEF 0x02000000 /* collision on previous attempt to transmit */32#define T_P 0x01000000 /* Preamble - send Preamble sequence before33data */34#define T_HB 0x01000000 /* heartbeat */35#define T_NS 0x00800000 /* No Stop */36#define T_LC 0x00800000 /* late collision */37#define T_RL 0x00400000 /* retransmission limit */38#define T_UN 0x00020000 /* underrun */39#define T_CT 0x00010000 /* CTS lost */40#define T_CSL 0x00010000 /* carrier sense lost */41#define T_RC 0x003c0000 /* retry count */4243/* Receive BD's status */44#define R_E 0x80000000 /* buffer empty */45#define R_W 0x20000000 /* wrap bit */46#define R_I 0x10000000 /* interrupt on reception */47#define R_L 0x08000000 /* last */48#define R_C 0x08000000 /* the last byte in this buffer is a cntl49char */50#define R_F 0x04000000 /* first */51#define R_A 0x04000000 /* the first byte in this buffer is address52byte */53#define R_CM 0x02000000 /* continuous mode */54#define R_ID 0x01000000 /* buffer close on reception of idles */55#define R_M 0x01000000 /* Frame received because of promiscuous56mode */57#define R_AM 0x00800000 /* Address match */58#define R_DE 0x00800000 /* Address match */59#define R_LG 0x00200000 /* Break received */60#define R_BR 0x00200000 /* Frame length violation */61#define R_NO 0x00100000 /* Rx Non Octet Aligned Packet */62#define R_FR 0x00100000 /* Framing Error (no stop bit) character63received */64#define R_PR 0x00080000 /* Parity Error character received */65#define R_AB 0x00080000 /* Frame Aborted */66#define R_SH 0x00080000 /* frame is too short */67#define R_CR 0x00040000 /* CRC Error */68#define R_OV 0x00020000 /* Overrun */69#define R_CD 0x00010000 /* CD lost */70#define R_CL 0x00010000 /* this frame is closed because of a71collision */7273/* Rx Data buffer must be 4 bytes aligned in most cases.*/74#define UCC_SLOW_RX_ALIGN 475#define UCC_SLOW_MRBLR_ALIGNMENT 476#define UCC_SLOW_PRAM_SIZE 0x10077#define ALIGNMENT_OF_UCC_SLOW_PRAM 647879/* UCC Slow Channel Protocol Mode */80enum ucc_slow_channel_protocol_mode {81UCC_SLOW_CHANNEL_PROTOCOL_MODE_QMC = 0x00000002,82UCC_SLOW_CHANNEL_PROTOCOL_MODE_UART = 0x00000004,83UCC_SLOW_CHANNEL_PROTOCOL_MODE_BISYNC = 0x00000008,84};8586/* UCC Slow Transparent Transmit CRC (TCRC) */87enum ucc_slow_transparent_tcrc {88/* 16-bit CCITT CRC (HDLC). (X16 + X12 + X5 + 1) */89UCC_SLOW_TRANSPARENT_TCRC_CCITT_CRC16 = 0x00000000,90/* CRC16 (BISYNC). (X16 + X15 + X2 + 1) */91UCC_SLOW_TRANSPARENT_TCRC_CRC16 = 0x00004000,92/* 32-bit CCITT CRC (Ethernet and HDLC) */93UCC_SLOW_TRANSPARENT_TCRC_CCITT_CRC32 = 0x00008000,94};9596/* UCC Slow oversampling rate for transmitter (TDCR) */97enum ucc_slow_tx_oversampling_rate {98/* 1x clock mode */99UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_1 = 0x00000000,100/* 8x clock mode */101UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_8 = 0x00010000,102/* 16x clock mode */103UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_16 = 0x00020000,104/* 32x clock mode */105UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_32 = 0x00030000,106};107108/* UCC Slow Oversampling rate for receiver (RDCR)109*/110enum ucc_slow_rx_oversampling_rate {111/* 1x clock mode */112UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_1 = 0x00000000,113/* 8x clock mode */114UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_8 = 0x00004000,115/* 16x clock mode */116UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_16 = 0x00008000,117/* 32x clock mode */118UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_32 = 0x0000c000,119};120121/* UCC Slow Transmitter encoding method (TENC)122*/123enum ucc_slow_tx_encoding_method {124UCC_SLOW_TRANSMITTER_ENCODING_METHOD_TENC_NRZ = 0x00000000,125UCC_SLOW_TRANSMITTER_ENCODING_METHOD_TENC_NRZI = 0x00000100126};127128/* UCC Slow Receiver decoding method (RENC)129*/130enum ucc_slow_rx_decoding_method {131UCC_SLOW_RECEIVER_DECODING_METHOD_RENC_NRZ = 0x00000000,132UCC_SLOW_RECEIVER_DECODING_METHOD_RENC_NRZI = 0x00000800133};134135/* UCC Slow Diagnostic mode (DIAG)136*/137enum ucc_slow_diag_mode {138UCC_SLOW_DIAG_MODE_NORMAL = 0x00000000,139UCC_SLOW_DIAG_MODE_LOOPBACK = 0x00000040,140UCC_SLOW_DIAG_MODE_ECHO = 0x00000080,141UCC_SLOW_DIAG_MODE_LOOPBACK_ECHO = 0x000000c0142};143144struct ucc_slow_info {145int ucc_num;146int protocol; /* QE_CR_PROTOCOL_xxx */147enum qe_clock rx_clock;148enum qe_clock tx_clock;149phys_addr_t regs;150int irq;151u16 uccm_mask;152int data_mem_part;153int init_tx;154int init_rx;155u32 tx_bd_ring_len;156u32 rx_bd_ring_len;157int rx_interrupts;158int brkpt_support;159int grant_support;160int tsa;161int cdp;162int cds;163int ctsp;164int ctss;165int rinv;166int tinv;167int rtsm;168int rfw;169int tci;170int tend;171int tfl;172int txsy;173u16 max_rx_buf_length;174enum ucc_slow_transparent_tcrc tcrc;175enum ucc_slow_channel_protocol_mode mode;176enum ucc_slow_diag_mode diag;177enum ucc_slow_tx_oversampling_rate tdcr;178enum ucc_slow_rx_oversampling_rate rdcr;179enum ucc_slow_tx_encoding_method tenc;180enum ucc_slow_rx_decoding_method renc;181};182183struct ucc_slow_private {184struct ucc_slow_info *us_info;185struct ucc_slow __iomem *us_regs; /* Ptr to memory map of UCC regs */186struct ucc_slow_pram __iomem *us_pram; /* a pointer to the parameter RAM */187s32 us_pram_offset;188int enabled_tx; /* Whether channel is enabled for Tx (ENT) */189int enabled_rx; /* Whether channel is enabled for Rx (ENR) */190int stopped_tx; /* Whether channel has been stopped for Tx191(STOP_TX, etc.) */192int stopped_rx; /* Whether channel has been stopped for Rx */193struct list_head confQ; /* frames passed to chip waiting for tx */194u32 first_tx_bd_mask; /* mask is used in Tx routine to save status195and length for first BD in a frame */196s32 tx_base_offset; /* first BD in Tx BD table offset (In MURAM) */197s32 rx_base_offset; /* first BD in Rx BD table offset (In MURAM) */198struct qe_bd __iomem *confBd; /* next BD for confirm after Tx */199struct qe_bd __iomem *tx_bd; /* next BD for new Tx request */200struct qe_bd __iomem *rx_bd; /* next BD to collect after Rx */201void *p_rx_frame; /* accumulating receive frame */202__be16 __iomem *p_ucce; /* a pointer to the event register in memory */203__be16 __iomem *p_uccm; /* a pointer to the mask register in memory */204u16 saved_uccm; /* a saved mask for the RX Interrupt bits */205#ifdef STATISTICS206u32 tx_frames; /* Transmitted frames counters */207u32 rx_frames; /* Received frames counters (only frames208passed to application) */209u32 rx_discarded; /* Discarded frames counters (frames that210were discarded by the driver due to211errors) */212#endif /* STATISTICS */213};214215/* ucc_slow_init216* Initializes Slow UCC according to provided parameters.217*218* us_info - (In) pointer to the slow UCC info structure.219* uccs_ret - (Out) pointer to the slow UCC structure.220*/221int ucc_slow_init(struct ucc_slow_info * us_info, struct ucc_slow_private ** uccs_ret);222223/* ucc_slow_free224* Frees all resources for slow UCC.225*226* uccs - (In) pointer to the slow UCC structure.227*/228void ucc_slow_free(struct ucc_slow_private * uccs);229230/* ucc_slow_enable231* Enables a fast UCC port.232* This routine enables Tx and/or Rx through the General UCC Mode Register.233*234* uccs - (In) pointer to the slow UCC structure.235* mode - (In) TX, RX, or both.236*/237void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode);238239/* ucc_slow_disable240* Disables a fast UCC port.241* This routine disables Tx and/or Rx through the General UCC Mode Register.242*243* uccs - (In) pointer to the slow UCC structure.244* mode - (In) TX, RX, or both.245*/246void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode);247248/* ucc_slow_graceful_stop_tx249* Smoothly stops transmission on a specified slow UCC.250*251* uccs - (In) pointer to the slow UCC structure.252*/253void ucc_slow_graceful_stop_tx(struct ucc_slow_private * uccs);254255/* ucc_slow_stop_tx256* Stops transmission on a specified slow UCC.257*258* uccs - (In) pointer to the slow UCC structure.259*/260void ucc_slow_stop_tx(struct ucc_slow_private * uccs);261262/* ucc_slow_restart_tx263* Restarts transmitting on a specified slow UCC.264*265* uccs - (In) pointer to the slow UCC structure.266*/267void ucc_slow_restart_tx(struct ucc_slow_private *uccs);268269u32 ucc_slow_get_qe_cr_subblock(int uccs_num);270271#endif /* __UCC_SLOW_H__ */272273274