162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#include <linux/kernel.h>
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci#include "k3-psil-priv.h"
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#define PSIL_PDMA_XY_PKT(x)					\
1162306a36Sopenharmony_ci	{							\
1262306a36Sopenharmony_ci		.thread_id = x,					\
1362306a36Sopenharmony_ci		.ep_config = {					\
1462306a36Sopenharmony_ci			.ep_type = PSIL_EP_PDMA_XY,		\
1562306a36Sopenharmony_ci			.mapped_channel_id = -1,		\
1662306a36Sopenharmony_ci			.default_flow_id = -1,			\
1762306a36Sopenharmony_ci			.pkt_mode = 1,				\
1862306a36Sopenharmony_ci		},						\
1962306a36Sopenharmony_ci	}
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define PSIL_ETHERNET(x, ch, flow_base, flow_cnt)		\
2262306a36Sopenharmony_ci	{							\
2362306a36Sopenharmony_ci		.thread_id = x,					\
2462306a36Sopenharmony_ci		.ep_config = {					\
2562306a36Sopenharmony_ci			.ep_type = PSIL_EP_NATIVE,		\
2662306a36Sopenharmony_ci			.pkt_mode = 1,				\
2762306a36Sopenharmony_ci			.needs_epib = 1,			\
2862306a36Sopenharmony_ci			.psd_size = 16,				\
2962306a36Sopenharmony_ci			.mapped_channel_id = ch,		\
3062306a36Sopenharmony_ci			.flow_start = flow_base,		\
3162306a36Sopenharmony_ci			.flow_num = flow_cnt,			\
3262306a36Sopenharmony_ci			.default_flow_id = flow_base,		\
3362306a36Sopenharmony_ci		},						\
3462306a36Sopenharmony_ci	}
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci#define PSIL_SAUL(x, ch, flow_base, flow_cnt, default_flow, tx)	\
3762306a36Sopenharmony_ci	{							\
3862306a36Sopenharmony_ci		.thread_id = x,					\
3962306a36Sopenharmony_ci		.ep_config = {					\
4062306a36Sopenharmony_ci			.ep_type = PSIL_EP_NATIVE,		\
4162306a36Sopenharmony_ci			.pkt_mode = 1,				\
4262306a36Sopenharmony_ci			.needs_epib = 1,			\
4362306a36Sopenharmony_ci			.psd_size = 64,				\
4462306a36Sopenharmony_ci			.mapped_channel_id = ch,		\
4562306a36Sopenharmony_ci			.flow_start = flow_base,		\
4662306a36Sopenharmony_ci			.flow_num = flow_cnt,			\
4762306a36Sopenharmony_ci			.default_flow_id = default_flow,	\
4862306a36Sopenharmony_ci			.notdpkt = tx,				\
4962306a36Sopenharmony_ci		},						\
5062306a36Sopenharmony_ci	}
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci#define PSIL_PDMA_MCASP(x)				\
5362306a36Sopenharmony_ci	{						\
5462306a36Sopenharmony_ci		.thread_id = x,				\
5562306a36Sopenharmony_ci		.ep_config = {				\
5662306a36Sopenharmony_ci			.ep_type = PSIL_EP_PDMA_XY,	\
5762306a36Sopenharmony_ci			.pdma_acc32 = 1,		\
5862306a36Sopenharmony_ci			.pdma_burst = 1,		\
5962306a36Sopenharmony_ci		},					\
6062306a36Sopenharmony_ci	}
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci#define PSIL_CSI2RX(x)					\
6362306a36Sopenharmony_ci	{						\
6462306a36Sopenharmony_ci		.thread_id = x,				\
6562306a36Sopenharmony_ci		.ep_config = {				\
6662306a36Sopenharmony_ci			.ep_type = PSIL_EP_NATIVE,	\
6762306a36Sopenharmony_ci		},					\
6862306a36Sopenharmony_ci	}
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* PSI-L source thread IDs, used for RX (DMA_DEV_TO_MEM) */
7162306a36Sopenharmony_cistatic struct psil_ep am62_src_ep_map[] = {
7262306a36Sopenharmony_ci	/* SAUL */
7362306a36Sopenharmony_ci	PSIL_SAUL(0x7504, 20, 35, 8, 35, 0),
7462306a36Sopenharmony_ci	PSIL_SAUL(0x7505, 21, 35, 8, 36, 0),
7562306a36Sopenharmony_ci	PSIL_SAUL(0x7506, 22, 43, 8, 43, 0),
7662306a36Sopenharmony_ci	PSIL_SAUL(0x7507, 23, 43, 8, 44, 0),
7762306a36Sopenharmony_ci	/* PDMA_MAIN0 - SPI0-2 */
7862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4300),
7962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4301),
8062306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4302),
8162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4303),
8262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4304),
8362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4305),
8462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4306),
8562306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4307),
8662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4308),
8762306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4309),
8862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430a),
8962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430b),
9062306a36Sopenharmony_ci	/* PDMA_MAIN1 - UART0-6 */
9162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4400),
9262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4401),
9362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4402),
9462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4403),
9562306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4404),
9662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4405),
9762306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4406),
9862306a36Sopenharmony_ci	/* PDMA_MAIN2 - MCASP0-2 */
9962306a36Sopenharmony_ci	PSIL_PDMA_MCASP(0x4500),
10062306a36Sopenharmony_ci	PSIL_PDMA_MCASP(0x4501),
10162306a36Sopenharmony_ci	PSIL_PDMA_MCASP(0x4502),
10262306a36Sopenharmony_ci	/* CPSW3G */
10362306a36Sopenharmony_ci	PSIL_ETHERNET(0x4600, 19, 19, 16),
10462306a36Sopenharmony_ci	/* CSI2RX */
10562306a36Sopenharmony_ci	PSIL_CSI2RX(0x4700),
10662306a36Sopenharmony_ci	PSIL_CSI2RX(0x4701),
10762306a36Sopenharmony_ci	PSIL_CSI2RX(0x4702),
10862306a36Sopenharmony_ci	PSIL_CSI2RX(0x4703),
10962306a36Sopenharmony_ci	PSIL_CSI2RX(0x4704),
11062306a36Sopenharmony_ci	PSIL_CSI2RX(0x4705),
11162306a36Sopenharmony_ci	PSIL_CSI2RX(0x4706),
11262306a36Sopenharmony_ci	PSIL_CSI2RX(0x4707),
11362306a36Sopenharmony_ci	PSIL_CSI2RX(0x4708),
11462306a36Sopenharmony_ci	PSIL_CSI2RX(0x4709),
11562306a36Sopenharmony_ci	PSIL_CSI2RX(0x470a),
11662306a36Sopenharmony_ci	PSIL_CSI2RX(0x470b),
11762306a36Sopenharmony_ci	PSIL_CSI2RX(0x470c),
11862306a36Sopenharmony_ci	PSIL_CSI2RX(0x470d),
11962306a36Sopenharmony_ci	PSIL_CSI2RX(0x470e),
12062306a36Sopenharmony_ci	PSIL_CSI2RX(0x470f),
12162306a36Sopenharmony_ci	PSIL_CSI2RX(0x4710),
12262306a36Sopenharmony_ci	PSIL_CSI2RX(0x4711),
12362306a36Sopenharmony_ci	PSIL_CSI2RX(0x4712),
12462306a36Sopenharmony_ci	PSIL_CSI2RX(0x4713),
12562306a36Sopenharmony_ci	PSIL_CSI2RX(0x4714),
12662306a36Sopenharmony_ci	PSIL_CSI2RX(0x4715),
12762306a36Sopenharmony_ci	PSIL_CSI2RX(0x4716),
12862306a36Sopenharmony_ci	PSIL_CSI2RX(0x4717),
12962306a36Sopenharmony_ci	PSIL_CSI2RX(0x4718),
13062306a36Sopenharmony_ci	PSIL_CSI2RX(0x4719),
13162306a36Sopenharmony_ci	PSIL_CSI2RX(0x471a),
13262306a36Sopenharmony_ci	PSIL_CSI2RX(0x471b),
13362306a36Sopenharmony_ci	PSIL_CSI2RX(0x471c),
13462306a36Sopenharmony_ci	PSIL_CSI2RX(0x471d),
13562306a36Sopenharmony_ci	PSIL_CSI2RX(0x471e),
13662306a36Sopenharmony_ci	PSIL_CSI2RX(0x471f),
13762306a36Sopenharmony_ci};
13862306a36Sopenharmony_ci
13962306a36Sopenharmony_ci/* PSI-L destination thread IDs, used for TX (DMA_MEM_TO_DEV) */
14062306a36Sopenharmony_cistatic struct psil_ep am62_dst_ep_map[] = {
14162306a36Sopenharmony_ci	/* SAUL */
14262306a36Sopenharmony_ci	PSIL_SAUL(0xf500, 27, 83, 8, 83, 1),
14362306a36Sopenharmony_ci	PSIL_SAUL(0xf501, 28, 91, 8, 91, 1),
14462306a36Sopenharmony_ci	/* PDMA_MAIN0 - SPI0-2 */
14562306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc300),
14662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc301),
14762306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc302),
14862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc303),
14962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc304),
15062306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc305),
15162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc306),
15262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc307),
15362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc308),
15462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc309),
15562306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc30a),
15662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc30b),
15762306a36Sopenharmony_ci	/* PDMA_MAIN1 - UART0-6 */
15862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc400),
15962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc401),
16062306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc402),
16162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc403),
16262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc404),
16362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc405),
16462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0xc406),
16562306a36Sopenharmony_ci	/* PDMA_MAIN2 - MCASP0-2 */
16662306a36Sopenharmony_ci	PSIL_PDMA_MCASP(0xc500),
16762306a36Sopenharmony_ci	PSIL_PDMA_MCASP(0xc501),
16862306a36Sopenharmony_ci	PSIL_PDMA_MCASP(0xc502),
16962306a36Sopenharmony_ci	/* CPSW3G */
17062306a36Sopenharmony_ci	PSIL_ETHERNET(0xc600, 19, 19, 8),
17162306a36Sopenharmony_ci	PSIL_ETHERNET(0xc601, 20, 27, 8),
17262306a36Sopenharmony_ci	PSIL_ETHERNET(0xc602, 21, 35, 8),
17362306a36Sopenharmony_ci	PSIL_ETHERNET(0xc603, 22, 43, 8),
17462306a36Sopenharmony_ci	PSIL_ETHERNET(0xc604, 23, 51, 8),
17562306a36Sopenharmony_ci	PSIL_ETHERNET(0xc605, 24, 59, 8),
17662306a36Sopenharmony_ci	PSIL_ETHERNET(0xc606, 25, 67, 8),
17762306a36Sopenharmony_ci	PSIL_ETHERNET(0xc607, 26, 75, 8),
17862306a36Sopenharmony_ci};
17962306a36Sopenharmony_ci
18062306a36Sopenharmony_cistruct psil_ep_map am62_ep_map = {
18162306a36Sopenharmony_ci	.name = "am62",
18262306a36Sopenharmony_ci	.src = am62_src_ep_map,
18362306a36Sopenharmony_ci	.src_count = ARRAY_SIZE(am62_src_ep_map),
18462306a36Sopenharmony_ci	.dst = am62_dst_ep_map,
18562306a36Sopenharmony_ci	.dst_count = ARRAY_SIZE(am62_dst_ep_map),
18662306a36Sopenharmony_ci};
187