162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci *  Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com
462306a36Sopenharmony_ci *  Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#include <linux/kernel.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include "k3-psil-priv.h"
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci#define PSIL_PDMA_XY_TR(x)					\
1262306a36Sopenharmony_ci	{							\
1362306a36Sopenharmony_ci		.thread_id = x,					\
1462306a36Sopenharmony_ci		.ep_config = {					\
1562306a36Sopenharmony_ci			.ep_type = PSIL_EP_PDMA_XY,		\
1662306a36Sopenharmony_ci			.mapped_channel_id = -1,		\
1762306a36Sopenharmony_ci			.default_flow_id = -1,			\
1862306a36Sopenharmony_ci		},						\
1962306a36Sopenharmony_ci	}
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ci#define PSIL_PDMA_XY_PKT(x)					\
2262306a36Sopenharmony_ci	{							\
2362306a36Sopenharmony_ci		.thread_id = x,					\
2462306a36Sopenharmony_ci		.ep_config = {					\
2562306a36Sopenharmony_ci			.ep_type = PSIL_EP_PDMA_XY,		\
2662306a36Sopenharmony_ci			.mapped_channel_id = -1,		\
2762306a36Sopenharmony_ci			.default_flow_id = -1,			\
2862306a36Sopenharmony_ci			.pkt_mode = 1,				\
2962306a36Sopenharmony_ci		},						\
3062306a36Sopenharmony_ci	}
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define PSIL_ETHERNET(x, ch, flow_base, flow_cnt)		\
3362306a36Sopenharmony_ci	{							\
3462306a36Sopenharmony_ci		.thread_id = x,					\
3562306a36Sopenharmony_ci		.ep_config = {					\
3662306a36Sopenharmony_ci			.ep_type = PSIL_EP_NATIVE,		\
3762306a36Sopenharmony_ci			.pkt_mode = 1,				\
3862306a36Sopenharmony_ci			.needs_epib = 1,			\
3962306a36Sopenharmony_ci			.psd_size = 16,				\
4062306a36Sopenharmony_ci			.mapped_channel_id = ch,		\
4162306a36Sopenharmony_ci			.flow_start = flow_base,		\
4262306a36Sopenharmony_ci			.flow_num = flow_cnt,			\
4362306a36Sopenharmony_ci			.default_flow_id = flow_base,		\
4462306a36Sopenharmony_ci		},						\
4562306a36Sopenharmony_ci	}
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci#define PSIL_SAUL(x, ch, flow_base, flow_cnt, default_flow, tx)	\
4862306a36Sopenharmony_ci	{							\
4962306a36Sopenharmony_ci		.thread_id = x,					\
5062306a36Sopenharmony_ci		.ep_config = {					\
5162306a36Sopenharmony_ci			.ep_type = PSIL_EP_NATIVE,		\
5262306a36Sopenharmony_ci			.pkt_mode = 1,				\
5362306a36Sopenharmony_ci			.needs_epib = 1,			\
5462306a36Sopenharmony_ci			.psd_size = 64,				\
5562306a36Sopenharmony_ci			.mapped_channel_id = ch,		\
5662306a36Sopenharmony_ci			.flow_start = flow_base,		\
5762306a36Sopenharmony_ci			.flow_num = flow_cnt,			\
5862306a36Sopenharmony_ci			.default_flow_id = default_flow,	\
5962306a36Sopenharmony_ci			.notdpkt = tx,				\
6062306a36Sopenharmony_ci		},						\
6162306a36Sopenharmony_ci	}
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci/* PSI-L source thread IDs, used for RX (DMA_DEV_TO_MEM) */
6462306a36Sopenharmony_cistatic struct psil_ep am64_src_ep_map[] = {
6562306a36Sopenharmony_ci	/* SAUL */
6662306a36Sopenharmony_ci	PSIL_SAUL(0x4000, 17, 32, 8, 32, 0),
6762306a36Sopenharmony_ci	PSIL_SAUL(0x4001, 18, 32, 8, 33, 0),
6862306a36Sopenharmony_ci	PSIL_SAUL(0x4002, 19, 40, 8, 40, 0),
6962306a36Sopenharmony_ci	PSIL_SAUL(0x4003, 20, 40, 8, 41, 0),
7062306a36Sopenharmony_ci	/* ICSS_G0 */
7162306a36Sopenharmony_ci	PSIL_ETHERNET(0x4100, 21, 48, 16),
7262306a36Sopenharmony_ci	PSIL_ETHERNET(0x4101, 22, 64, 16),
7362306a36Sopenharmony_ci	PSIL_ETHERNET(0x4102, 23, 80, 16),
7462306a36Sopenharmony_ci	PSIL_ETHERNET(0x4103, 24, 96, 16),
7562306a36Sopenharmony_ci	/* ICSS_G1 */
7662306a36Sopenharmony_ci	PSIL_ETHERNET(0x4200, 25, 112, 16),
7762306a36Sopenharmony_ci	PSIL_ETHERNET(0x4201, 26, 128, 16),
7862306a36Sopenharmony_ci	PSIL_ETHERNET(0x4202, 27, 144, 16),
7962306a36Sopenharmony_ci	PSIL_ETHERNET(0x4203, 28, 160, 16),
8062306a36Sopenharmony_ci	/* PDMA_MAIN0 - SPI0-3 */
8162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4300),
8262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4301),
8362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4302),
8462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4303),
8562306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4304),
8662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4305),
8762306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4306),
8862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4307),
8962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4308),
9062306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4309),
9162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430a),
9262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430b),
9362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430c),
9462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430d),
9562306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430e),
9662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x430f),
9762306a36Sopenharmony_ci	/* PDMA_MAIN0 - USART0-1 */
9862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4310),
9962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4311),
10062306a36Sopenharmony_ci	/* PDMA_MAIN1 - SPI4 */
10162306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4400),
10262306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4401),
10362306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4402),
10462306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4403),
10562306a36Sopenharmony_ci	/* PDMA_MAIN1 - USART2-6 */
10662306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4404),
10762306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4405),
10862306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4406),
10962306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4407),
11062306a36Sopenharmony_ci	PSIL_PDMA_XY_PKT(0x4408),
11162306a36Sopenharmony_ci	/* PDMA_MAIN1 - ADCs */
11262306a36Sopenharmony_ci	PSIL_PDMA_XY_TR(0x440f),
11362306a36Sopenharmony_ci	PSIL_PDMA_XY_TR(0x4410),
11462306a36Sopenharmony_ci	/* CPSW2 */
11562306a36Sopenharmony_ci	PSIL_ETHERNET(0x4500, 16, 16, 16),
11662306a36Sopenharmony_ci};
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci/* PSI-L destination thread IDs, used for TX (DMA_MEM_TO_DEV) */
11962306a36Sopenharmony_cistatic struct psil_ep am64_dst_ep_map[] = {
12062306a36Sopenharmony_ci	/* SAUL */
12162306a36Sopenharmony_ci	PSIL_SAUL(0xc000, 24, 80, 8, 80, 1),
12262306a36Sopenharmony_ci	PSIL_SAUL(0xc001, 25, 88, 8, 88, 1),
12362306a36Sopenharmony_ci	/* ICSS_G0 */
12462306a36Sopenharmony_ci	PSIL_ETHERNET(0xc100, 26, 96, 1),
12562306a36Sopenharmony_ci	PSIL_ETHERNET(0xc101, 27, 97, 1),
12662306a36Sopenharmony_ci	PSIL_ETHERNET(0xc102, 28, 98, 1),
12762306a36Sopenharmony_ci	PSIL_ETHERNET(0xc103, 29, 99, 1),
12862306a36Sopenharmony_ci	PSIL_ETHERNET(0xc104, 30, 100, 1),
12962306a36Sopenharmony_ci	PSIL_ETHERNET(0xc105, 31, 101, 1),
13062306a36Sopenharmony_ci	PSIL_ETHERNET(0xc106, 32, 102, 1),
13162306a36Sopenharmony_ci	PSIL_ETHERNET(0xc107, 33, 103, 1),
13262306a36Sopenharmony_ci	/* ICSS_G1 */
13362306a36Sopenharmony_ci	PSIL_ETHERNET(0xc200, 34, 104, 1),
13462306a36Sopenharmony_ci	PSIL_ETHERNET(0xc201, 35, 105, 1),
13562306a36Sopenharmony_ci	PSIL_ETHERNET(0xc202, 36, 106, 1),
13662306a36Sopenharmony_ci	PSIL_ETHERNET(0xc203, 37, 107, 1),
13762306a36Sopenharmony_ci	PSIL_ETHERNET(0xc204, 38, 108, 1),
13862306a36Sopenharmony_ci	PSIL_ETHERNET(0xc205, 39, 109, 1),
13962306a36Sopenharmony_ci	PSIL_ETHERNET(0xc206, 40, 110, 1),
14062306a36Sopenharmony_ci	PSIL_ETHERNET(0xc207, 41, 111, 1),
14162306a36Sopenharmony_ci	/* CPSW2 */
14262306a36Sopenharmony_ci	PSIL_ETHERNET(0xc500, 16, 16, 8),
14362306a36Sopenharmony_ci	PSIL_ETHERNET(0xc501, 17, 24, 8),
14462306a36Sopenharmony_ci	PSIL_ETHERNET(0xc502, 18, 32, 8),
14562306a36Sopenharmony_ci	PSIL_ETHERNET(0xc503, 19, 40, 8),
14662306a36Sopenharmony_ci	PSIL_ETHERNET(0xc504, 20, 48, 8),
14762306a36Sopenharmony_ci	PSIL_ETHERNET(0xc505, 21, 56, 8),
14862306a36Sopenharmony_ci	PSIL_ETHERNET(0xc506, 22, 64, 8),
14962306a36Sopenharmony_ci	PSIL_ETHERNET(0xc507, 23, 72, 8),
15062306a36Sopenharmony_ci};
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cistruct psil_ep_map am64_ep_map = {
15362306a36Sopenharmony_ci	.name = "am64",
15462306a36Sopenharmony_ci	.src = am64_src_ep_map,
15562306a36Sopenharmony_ci	.src_count = ARRAY_SIZE(am64_src_ep_map),
15662306a36Sopenharmony_ci	.dst = am64_dst_ep_map,
15762306a36Sopenharmony_ci	.dst_count = ARRAY_SIZE(am64_dst_ep_map),
15862306a36Sopenharmony_ci};
159