18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef __CPM_H
38c2ecf20Sopenharmony_ci#define __CPM_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci#include <linux/compiler.h>
68c2ecf20Sopenharmony_ci#include <linux/types.h>
78c2ecf20Sopenharmony_ci#include <linux/errno.h>
88c2ecf20Sopenharmony_ci#include <linux/of.h>
98c2ecf20Sopenharmony_ci#include <soc/fsl/qe/qe.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/*
128c2ecf20Sopenharmony_ci * SPI Parameter RAM common to QE and CPM.
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_cistruct spi_pram {
158c2ecf20Sopenharmony_ci	__be16	rbase;	/* Rx Buffer descriptor base address */
168c2ecf20Sopenharmony_ci	__be16	tbase;	/* Tx Buffer descriptor base address */
178c2ecf20Sopenharmony_ci	u8	rfcr;	/* Rx function code */
188c2ecf20Sopenharmony_ci	u8	tfcr;	/* Tx function code */
198c2ecf20Sopenharmony_ci	__be16	mrblr;	/* Max receive buffer length */
208c2ecf20Sopenharmony_ci	__be32	rstate;	/* Internal */
218c2ecf20Sopenharmony_ci	__be32	rdp;	/* Internal */
228c2ecf20Sopenharmony_ci	__be16	rbptr;	/* Internal */
238c2ecf20Sopenharmony_ci	__be16	rbc;	/* Internal */
248c2ecf20Sopenharmony_ci	__be32	rxtmp;	/* Internal */
258c2ecf20Sopenharmony_ci	__be32	tstate;	/* Internal */
268c2ecf20Sopenharmony_ci	__be32	tdp;	/* Internal */
278c2ecf20Sopenharmony_ci	__be16	tbptr;	/* Internal */
288c2ecf20Sopenharmony_ci	__be16	tbc;	/* Internal */
298c2ecf20Sopenharmony_ci	__be32	txtmp;	/* Internal */
308c2ecf20Sopenharmony_ci	__be32	res;	/* Tx temp. */
318c2ecf20Sopenharmony_ci	__be16  rpbase;	/* Relocation pointer (CPM1 only) */
328c2ecf20Sopenharmony_ci	__be16	res1;	/* Reserved */
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci/*
368c2ecf20Sopenharmony_ci * USB Controller pram common to QE and CPM.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cistruct usb_ctlr {
398c2ecf20Sopenharmony_ci	u8	usb_usmod;
408c2ecf20Sopenharmony_ci	u8	usb_usadr;
418c2ecf20Sopenharmony_ci	u8	usb_uscom;
428c2ecf20Sopenharmony_ci	u8	res1[1];
438c2ecf20Sopenharmony_ci	__be16	usb_usep[4];
448c2ecf20Sopenharmony_ci	u8	res2[4];
458c2ecf20Sopenharmony_ci	__be16	usb_usber;
468c2ecf20Sopenharmony_ci	u8	res3[2];
478c2ecf20Sopenharmony_ci	__be16	usb_usbmr;
488c2ecf20Sopenharmony_ci	u8	res4[1];
498c2ecf20Sopenharmony_ci	u8	usb_usbs;
508c2ecf20Sopenharmony_ci	/* Fields down below are QE-only */
518c2ecf20Sopenharmony_ci	__be16	usb_ussft;
528c2ecf20Sopenharmony_ci	u8	res5[2];
538c2ecf20Sopenharmony_ci	__be16	usb_usfrn;
548c2ecf20Sopenharmony_ci	u8	res6[0x22];
558c2ecf20Sopenharmony_ci} __attribute__ ((packed));
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci/*
588c2ecf20Sopenharmony_ci * Function code bits, usually generic to devices.
598c2ecf20Sopenharmony_ci */
608c2ecf20Sopenharmony_ci#ifdef CONFIG_CPM1
618c2ecf20Sopenharmony_ci#define CPMFCR_GBL	((u_char)0x00)	/* Flag doesn't exist in CPM1 */
628c2ecf20Sopenharmony_ci#define CPMFCR_TC2	((u_char)0x00)	/* Flag doesn't exist in CPM1 */
638c2ecf20Sopenharmony_ci#define CPMFCR_DTB	((u_char)0x00)	/* Flag doesn't exist in CPM1 */
648c2ecf20Sopenharmony_ci#define CPMFCR_BDB	((u_char)0x00)	/* Flag doesn't exist in CPM1 */
658c2ecf20Sopenharmony_ci#else
668c2ecf20Sopenharmony_ci#define CPMFCR_GBL	((u_char)0x20)	/* Set memory snooping */
678c2ecf20Sopenharmony_ci#define CPMFCR_TC2	((u_char)0x04)	/* Transfer code 2 value */
688c2ecf20Sopenharmony_ci#define CPMFCR_DTB	((u_char)0x02)	/* Use local bus for data when set */
698c2ecf20Sopenharmony_ci#define CPMFCR_BDB	((u_char)0x01)	/* Use local bus for BD when set */
708c2ecf20Sopenharmony_ci#endif
718c2ecf20Sopenharmony_ci#define CPMFCR_EB	((u_char)0x10)	/* Set big endian byte order */
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* Opcodes common to CPM1 and CPM2
748c2ecf20Sopenharmony_ci*/
758c2ecf20Sopenharmony_ci#define CPM_CR_INIT_TRX		((ushort)0x0000)
768c2ecf20Sopenharmony_ci#define CPM_CR_INIT_RX		((ushort)0x0001)
778c2ecf20Sopenharmony_ci#define CPM_CR_INIT_TX		((ushort)0x0002)
788c2ecf20Sopenharmony_ci#define CPM_CR_HUNT_MODE	((ushort)0x0003)
798c2ecf20Sopenharmony_ci#define CPM_CR_STOP_TX		((ushort)0x0004)
808c2ecf20Sopenharmony_ci#define CPM_CR_GRA_STOP_TX	((ushort)0x0005)
818c2ecf20Sopenharmony_ci#define CPM_CR_RESTART_TX	((ushort)0x0006)
828c2ecf20Sopenharmony_ci#define CPM_CR_CLOSE_RX_BD	((ushort)0x0007)
838c2ecf20Sopenharmony_ci#define CPM_CR_SET_GADDR	((ushort)0x0008)
848c2ecf20Sopenharmony_ci#define CPM_CR_SET_TIMER	((ushort)0x0008)
858c2ecf20Sopenharmony_ci#define CPM_CR_STOP_IDMA	((ushort)0x000b)
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci/* Buffer descriptors used by many of the CPM protocols. */
888c2ecf20Sopenharmony_citypedef struct cpm_buf_desc {
898c2ecf20Sopenharmony_ci	ushort	cbd_sc;		/* Status and Control */
908c2ecf20Sopenharmony_ci	ushort	cbd_datlen;	/* Data length in buffer */
918c2ecf20Sopenharmony_ci	uint	cbd_bufaddr;	/* Buffer address in host memory */
928c2ecf20Sopenharmony_ci} cbd_t;
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/* Buffer descriptor control/status used by serial
958c2ecf20Sopenharmony_ci */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define BD_SC_EMPTY	(0x8000)	/* Receive is empty */
988c2ecf20Sopenharmony_ci#define BD_SC_READY	(0x8000)	/* Transmit is ready */
998c2ecf20Sopenharmony_ci#define BD_SC_WRAP	(0x2000)	/* Last buffer descriptor */
1008c2ecf20Sopenharmony_ci#define BD_SC_INTRPT	(0x1000)	/* Interrupt on change */
1018c2ecf20Sopenharmony_ci#define BD_SC_LAST	(0x0800)	/* Last buffer in frame */
1028c2ecf20Sopenharmony_ci#define BD_SC_TC	(0x0400)	/* Transmit CRC */
1038c2ecf20Sopenharmony_ci#define BD_SC_CM	(0x0200)	/* Continuous mode */
1048c2ecf20Sopenharmony_ci#define BD_SC_ID	(0x0100)	/* Rec'd too many idles */
1058c2ecf20Sopenharmony_ci#define BD_SC_P		(0x0100)	/* xmt preamble */
1068c2ecf20Sopenharmony_ci#define BD_SC_BR	(0x0020)	/* Break received */
1078c2ecf20Sopenharmony_ci#define BD_SC_FR	(0x0010)	/* Framing error */
1088c2ecf20Sopenharmony_ci#define BD_SC_PR	(0x0008)	/* Parity error */
1098c2ecf20Sopenharmony_ci#define BD_SC_NAK	(0x0004)	/* NAK - did not respond */
1108c2ecf20Sopenharmony_ci#define BD_SC_OV	(0x0002)	/* Overrun */
1118c2ecf20Sopenharmony_ci#define BD_SC_UN	(0x0002)	/* Underrun */
1128c2ecf20Sopenharmony_ci#define BD_SC_CD	(0x0001)	/* */
1138c2ecf20Sopenharmony_ci#define BD_SC_CL	(0x0001)	/* Collision */
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* Buffer descriptor control/status used by Ethernet receive.
1168c2ecf20Sopenharmony_ci * Common to SCC and FCC.
1178c2ecf20Sopenharmony_ci */
1188c2ecf20Sopenharmony_ci#define BD_ENET_RX_EMPTY	(0x8000)
1198c2ecf20Sopenharmony_ci#define BD_ENET_RX_WRAP		(0x2000)
1208c2ecf20Sopenharmony_ci#define BD_ENET_RX_INTR		(0x1000)
1218c2ecf20Sopenharmony_ci#define BD_ENET_RX_LAST		(0x0800)
1228c2ecf20Sopenharmony_ci#define BD_ENET_RX_FIRST	(0x0400)
1238c2ecf20Sopenharmony_ci#define BD_ENET_RX_MISS		(0x0100)
1248c2ecf20Sopenharmony_ci#define BD_ENET_RX_BC		(0x0080)	/* FCC Only */
1258c2ecf20Sopenharmony_ci#define BD_ENET_RX_MC		(0x0040)	/* FCC Only */
1268c2ecf20Sopenharmony_ci#define BD_ENET_RX_LG		(0x0020)
1278c2ecf20Sopenharmony_ci#define BD_ENET_RX_NO		(0x0010)
1288c2ecf20Sopenharmony_ci#define BD_ENET_RX_SH		(0x0008)
1298c2ecf20Sopenharmony_ci#define BD_ENET_RX_CR		(0x0004)
1308c2ecf20Sopenharmony_ci#define BD_ENET_RX_OV		(0x0002)
1318c2ecf20Sopenharmony_ci#define BD_ENET_RX_CL		(0x0001)
1328c2ecf20Sopenharmony_ci#define BD_ENET_RX_STATS	(0x01ff)	/* All status bits */
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci/* Buffer descriptor control/status used by Ethernet transmit.
1358c2ecf20Sopenharmony_ci * Common to SCC and FCC.
1368c2ecf20Sopenharmony_ci */
1378c2ecf20Sopenharmony_ci#define BD_ENET_TX_READY	(0x8000)
1388c2ecf20Sopenharmony_ci#define BD_ENET_TX_PAD		(0x4000)
1398c2ecf20Sopenharmony_ci#define BD_ENET_TX_WRAP		(0x2000)
1408c2ecf20Sopenharmony_ci#define BD_ENET_TX_INTR		(0x1000)
1418c2ecf20Sopenharmony_ci#define BD_ENET_TX_LAST		(0x0800)
1428c2ecf20Sopenharmony_ci#define BD_ENET_TX_TC		(0x0400)
1438c2ecf20Sopenharmony_ci#define BD_ENET_TX_DEF		(0x0200)
1448c2ecf20Sopenharmony_ci#define BD_ENET_TX_HB		(0x0100)
1458c2ecf20Sopenharmony_ci#define BD_ENET_TX_LC		(0x0080)
1468c2ecf20Sopenharmony_ci#define BD_ENET_TX_RL		(0x0040)
1478c2ecf20Sopenharmony_ci#define BD_ENET_TX_RCMASK	(0x003c)
1488c2ecf20Sopenharmony_ci#define BD_ENET_TX_UN		(0x0002)
1498c2ecf20Sopenharmony_ci#define BD_ENET_TX_CSL		(0x0001)
1508c2ecf20Sopenharmony_ci#define BD_ENET_TX_STATS	(0x03ff)	/* All status bits */
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/* Buffer descriptor control/status used by Transparent mode SCC.
1538c2ecf20Sopenharmony_ci */
1548c2ecf20Sopenharmony_ci#define BD_SCC_TX_LAST		(0x0800)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* Buffer descriptor control/status used by I2C.
1578c2ecf20Sopenharmony_ci */
1588c2ecf20Sopenharmony_ci#define BD_I2C_START		(0x0400)
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#ifdef CONFIG_CPM
1618c2ecf20Sopenharmony_ciint cpm_command(u32 command, u8 opcode);
1628c2ecf20Sopenharmony_ci#else
1638c2ecf20Sopenharmony_cistatic inline int cpm_command(u32 command, u8 opcode)
1648c2ecf20Sopenharmony_ci{
1658c2ecf20Sopenharmony_ci	return -ENOSYS;
1668c2ecf20Sopenharmony_ci}
1678c2ecf20Sopenharmony_ci#endif /* CONFIG_CPM */
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ciint cpm2_gpiochip_add32(struct device *dev);
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci#endif
172