18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef K3_UDMA_H_
78c2ecf20Sopenharmony_ci#define K3_UDMA_H_
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/soc/ti/ti_sci_protocol.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* Global registers */
128c2ecf20Sopenharmony_ci#define UDMA_REV_REG			0x0
138c2ecf20Sopenharmony_ci#define UDMA_PERF_CTL_REG		0x4
148c2ecf20Sopenharmony_ci#define UDMA_EMU_CTL_REG		0x8
158c2ecf20Sopenharmony_ci#define UDMA_PSIL_TO_REG		0x10
168c2ecf20Sopenharmony_ci#define UDMA_UTC_CTL_REG		0x1c
178c2ecf20Sopenharmony_ci#define UDMA_CAP_REG(i)			(0x20 + ((i) * 4))
188c2ecf20Sopenharmony_ci#define UDMA_RX_FLOW_ID_FW_OES_REG	0x80
198c2ecf20Sopenharmony_ci#define UDMA_RX_FLOW_ID_FW_STATUS_REG	0x88
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/* TCHANRT/RCHANRT registers */
228c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_CTL_REG		0x0
238c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_SWTRIG_REG		0x8
248c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_STDATA_REG		0x80
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_PEER_REG(i)	(0x200 + ((i) * 0x4))
278c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_PEER_STATIC_TR_XY_REG	\
288c2ecf20Sopenharmony_ci	UDMA_CHAN_RT_PEER_REG(0)	/* PSI-L: 0x400 */
298c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_PEER_STATIC_TR_Z_REG	\
308c2ecf20Sopenharmony_ci	UDMA_CHAN_RT_PEER_REG(1)	/* PSI-L: 0x401 */
318c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_PEER_BCNT_REG		\
328c2ecf20Sopenharmony_ci	UDMA_CHAN_RT_PEER_REG(4)	/* PSI-L: 0x404 */
338c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_PEER_RT_EN_REG		\
348c2ecf20Sopenharmony_ci	UDMA_CHAN_RT_PEER_REG(8)	/* PSI-L: 0x408 */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_PCNT_REG		0x400
378c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_BCNT_REG		0x408
388c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_SBCNT_REG		0x410
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci/* UDMA_CAP Registers */
418c2ecf20Sopenharmony_ci#define UDMA_CAP2_TCHAN_CNT(val)	((val) & 0x1ff)
428c2ecf20Sopenharmony_ci#define UDMA_CAP2_ECHAN_CNT(val)	(((val) >> 9) & 0x1ff)
438c2ecf20Sopenharmony_ci#define UDMA_CAP2_RCHAN_CNT(val)	(((val) >> 18) & 0x1ff)
448c2ecf20Sopenharmony_ci#define UDMA_CAP3_RFLOW_CNT(val)	((val) & 0x3fff)
458c2ecf20Sopenharmony_ci#define UDMA_CAP3_HCHAN_CNT(val)	(((val) >> 14) & 0x1ff)
468c2ecf20Sopenharmony_ci#define UDMA_CAP3_UCHAN_CNT(val)	(((val) >> 23) & 0x1ff)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* UDMA_CHAN_RT_CTL_REG */
498c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_CTL_EN		BIT(31)
508c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_CTL_TDOWN		BIT(30)
518c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_CTL_PAUSE		BIT(29)
528c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_CTL_FTDOWN		BIT(28)
538c2ecf20Sopenharmony_ci#define UDMA_CHAN_RT_CTL_ERROR		BIT(0)
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/* UDMA_CHAN_RT_PEER_RT_EN_REG */
568c2ecf20Sopenharmony_ci#define UDMA_PEER_RT_EN_ENABLE		BIT(31)
578c2ecf20Sopenharmony_ci#define UDMA_PEER_RT_EN_TEARDOWN	BIT(30)
588c2ecf20Sopenharmony_ci#define UDMA_PEER_RT_EN_PAUSE		BIT(29)
598c2ecf20Sopenharmony_ci#define UDMA_PEER_RT_EN_FLUSH		BIT(28)
608c2ecf20Sopenharmony_ci#define UDMA_PEER_RT_EN_IDLE		BIT(1)
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci/*
638c2ecf20Sopenharmony_ci * UDMA_TCHAN_RT_PEER_STATIC_TR_XY_REG /
648c2ecf20Sopenharmony_ci * UDMA_RCHAN_RT_PEER_STATIC_TR_XY_REG
658c2ecf20Sopenharmony_ci */
668c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_X_MASK		GENMASK(26, 24)
678c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_X_SHIFT		(24)
688c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_Y_MASK		GENMASK(11, 0)
698c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_Y_SHIFT		(0)
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_Y(x)	\
728c2ecf20Sopenharmony_ci	(((x) << PDMA_STATIC_TR_Y_SHIFT) & PDMA_STATIC_TR_Y_MASK)
738c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_X(x)	\
748c2ecf20Sopenharmony_ci	(((x) << PDMA_STATIC_TR_X_SHIFT) & PDMA_STATIC_TR_X_MASK)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_XY_ACC32		BIT(30)
778c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_XY_BURST		BIT(31)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/*
808c2ecf20Sopenharmony_ci * UDMA_TCHAN_RT_PEER_STATIC_TR_Z_REG /
818c2ecf20Sopenharmony_ci * UDMA_RCHAN_RT_PEER_STATIC_TR_Z_REG
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_ci#define PDMA_STATIC_TR_Z(x, mask)	((x) & (mask))
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistruct udma_dev;
868c2ecf20Sopenharmony_cistruct udma_tchan;
878c2ecf20Sopenharmony_cistruct udma_rchan;
888c2ecf20Sopenharmony_cistruct udma_rflow;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cienum udma_rm_range {
918c2ecf20Sopenharmony_ci	RM_RANGE_TCHAN = 0,
928c2ecf20Sopenharmony_ci	RM_RANGE_RCHAN,
938c2ecf20Sopenharmony_ci	RM_RANGE_RFLOW,
948c2ecf20Sopenharmony_ci	RM_RANGE_LAST,
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistruct udma_tisci_rm {
988c2ecf20Sopenharmony_ci	const struct ti_sci_handle *tisci;
998c2ecf20Sopenharmony_ci	const struct ti_sci_rm_udmap_ops *tisci_udmap_ops;
1008c2ecf20Sopenharmony_ci	u32  tisci_dev_id;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	/* tisci information for PSI-L thread pairing/unpairing */
1038c2ecf20Sopenharmony_ci	const struct ti_sci_rm_psil_ops *tisci_psil_ops;
1048c2ecf20Sopenharmony_ci	u32  tisci_navss_dev_id;
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci	struct ti_sci_resource *rm_ranges[RM_RANGE_LAST];
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci/* Direct access to UDMA low lever resources for the glue layer */
1108c2ecf20Sopenharmony_ciint xudma_navss_psil_pair(struct udma_dev *ud, u32 src_thread, u32 dst_thread);
1118c2ecf20Sopenharmony_ciint xudma_navss_psil_unpair(struct udma_dev *ud, u32 src_thread,
1128c2ecf20Sopenharmony_ci			    u32 dst_thread);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistruct udma_dev *of_xudma_dev_get(struct device_node *np, const char *property);
1158c2ecf20Sopenharmony_civoid xudma_dev_put(struct udma_dev *ud);
1168c2ecf20Sopenharmony_ciu32 xudma_dev_get_psil_base(struct udma_dev *ud);
1178c2ecf20Sopenharmony_cistruct udma_tisci_rm *xudma_dev_get_tisci_rm(struct udma_dev *ud);
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciint xudma_alloc_gp_rflow_range(struct udma_dev *ud, int from, int cnt);
1208c2ecf20Sopenharmony_ciint xudma_free_gp_rflow_range(struct udma_dev *ud, int from, int cnt);
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct udma_tchan *xudma_tchan_get(struct udma_dev *ud, int id);
1238c2ecf20Sopenharmony_cistruct udma_rchan *xudma_rchan_get(struct udma_dev *ud, int id);
1248c2ecf20Sopenharmony_cistruct udma_rflow *xudma_rflow_get(struct udma_dev *ud, int id);
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_civoid xudma_tchan_put(struct udma_dev *ud, struct udma_tchan *p);
1278c2ecf20Sopenharmony_civoid xudma_rchan_put(struct udma_dev *ud, struct udma_rchan *p);
1288c2ecf20Sopenharmony_civoid xudma_rflow_put(struct udma_dev *ud, struct udma_rflow *p);
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ciint xudma_tchan_get_id(struct udma_tchan *p);
1318c2ecf20Sopenharmony_ciint xudma_rchan_get_id(struct udma_rchan *p);
1328c2ecf20Sopenharmony_ciint xudma_rflow_get_id(struct udma_rflow *p);
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ciu32 xudma_tchanrt_read(struct udma_tchan *tchan, int reg);
1358c2ecf20Sopenharmony_civoid xudma_tchanrt_write(struct udma_tchan *tchan, int reg, u32 val);
1368c2ecf20Sopenharmony_ciu32 xudma_rchanrt_read(struct udma_rchan *rchan, int reg);
1378c2ecf20Sopenharmony_civoid xudma_rchanrt_write(struct udma_rchan *rchan, int reg, u32 val);
1388c2ecf20Sopenharmony_cibool xudma_rflow_is_gp(struct udma_dev *ud, int id);
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#endif /* K3_UDMA_H_ */
141