18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * tegra210_i2s.h - Definitions for Tegra210 I2S driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2020 NVIDIA CORPORATION. All rights reserved.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef __TEGRA210_I2S_H__
108c2ecf20Sopenharmony_ci#define __TEGRA210_I2S_H__
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/* Register offsets from I2S*_BASE */
138c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_ENABLE			0x0
148c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_SOFT_RESET		0x4
158c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_STATUS			0x0c
168c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_INT_STATUS		0x10
178c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_INT_MASK		0x14
188c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_INT_SET			0x18
198c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_INT_CLEAR		0x1c
208c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_CIF_CTRL		0x20
218c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_CTRL			0x24
228c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_SLOT_CTRL		0x28
238c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_CLK_TRIM		0x2c
248c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_CYA			0x30
258c2ecf20Sopenharmony_ci#define TEGRA210_I2S_RX_CIF_FIFO_STATUS		0x34
268c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_ENABLE			0x40
278c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_SOFT_RESET		0x44
288c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_STATUS			0x4c
298c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_INT_STATUS		0x50
308c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_INT_MASK		0x54
318c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_INT_SET			0x58
328c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_INT_CLEAR		0x5c
338c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_CIF_CTRL		0x60
348c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_CTRL			0x64
358c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_SLOT_CTRL		0x68
368c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_CLK_TRIM		0x6c
378c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_CYA			0x70
388c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TX_CIF_FIFO_STATUS		0x74
398c2ecf20Sopenharmony_ci#define TEGRA210_I2S_ENABLE			0x80
408c2ecf20Sopenharmony_ci#define TEGRA210_I2S_SOFT_RESET			0x84
418c2ecf20Sopenharmony_ci#define TEGRA210_I2S_CG				0x88
428c2ecf20Sopenharmony_ci#define TEGRA210_I2S_STATUS			0x8c
438c2ecf20Sopenharmony_ci#define TEGRA210_I2S_INT_STATUS			0x90
448c2ecf20Sopenharmony_ci#define TEGRA210_I2S_CTRL			0xa0
458c2ecf20Sopenharmony_ci#define TEGRA210_I2S_TIMING			0xa4
468c2ecf20Sopenharmony_ci#define TEGRA210_I2S_SLOT_CTRL			0xa8
478c2ecf20Sopenharmony_ci#define TEGRA210_I2S_CLK_TRIM			0xac
488c2ecf20Sopenharmony_ci#define TEGRA210_I2S_CYA			0xb0
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci/* Bit fields, shifts and masks */
518c2ecf20Sopenharmony_ci#define I2S_DATA_SHIFT				8
528c2ecf20Sopenharmony_ci#define I2S_CTRL_DATA_OFFSET_MASK		(0x7ff << I2S_DATA_SHIFT)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci#define I2S_EN_SHIFT				0
558c2ecf20Sopenharmony_ci#define I2S_EN_MASK				BIT(I2S_EN_SHIFT)
568c2ecf20Sopenharmony_ci#define I2S_EN					BIT(I2S_EN_SHIFT)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci#define I2S_FSYNC_WIDTH_SHIFT			24
598c2ecf20Sopenharmony_ci#define I2S_CTRL_FSYNC_WIDTH_MASK		(0xff << I2S_FSYNC_WIDTH_SHIFT)
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci#define I2S_POS_EDGE				0
628c2ecf20Sopenharmony_ci#define I2S_NEG_EDGE				1
638c2ecf20Sopenharmony_ci#define I2S_EDGE_SHIFT				20
648c2ecf20Sopenharmony_ci#define I2S_CTRL_EDGE_CTRL_MASK			BIT(I2S_EDGE_SHIFT)
658c2ecf20Sopenharmony_ci#define I2S_CTRL_EDGE_CTRL_POS_EDGE		(I2S_POS_EDGE << I2S_EDGE_SHIFT)
668c2ecf20Sopenharmony_ci#define I2S_CTRL_EDGE_CTRL_NEG_EDGE		(I2S_NEG_EDGE << I2S_EDGE_SHIFT)
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci#define I2S_FMT_LRCK				0
698c2ecf20Sopenharmony_ci#define I2S_FMT_FSYNC				1
708c2ecf20Sopenharmony_ci#define I2S_FMT_SHIFT				12
718c2ecf20Sopenharmony_ci#define I2S_CTRL_FRAME_FMT_MASK			(7 << I2S_FMT_SHIFT)
728c2ecf20Sopenharmony_ci#define I2S_CTRL_FRAME_FMT_LRCK_MODE		(I2S_FMT_LRCK << I2S_FMT_SHIFT)
738c2ecf20Sopenharmony_ci#define I2S_CTRL_FRAME_FMT_FSYNC_MODE		(I2S_FMT_FSYNC << I2S_FMT_SHIFT)
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define I2S_CTRL_MASTER_EN_SHIFT		10
768c2ecf20Sopenharmony_ci#define I2S_CTRL_MASTER_EN_MASK			BIT(I2S_CTRL_MASTER_EN_SHIFT)
778c2ecf20Sopenharmony_ci#define I2S_CTRL_MASTER_EN			BIT(I2S_CTRL_MASTER_EN_SHIFT)
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci#define I2S_CTRL_LRCK_POL_SHIFT			9
808c2ecf20Sopenharmony_ci#define I2S_CTRL_LRCK_POL_MASK			BIT(I2S_CTRL_LRCK_POL_SHIFT)
818c2ecf20Sopenharmony_ci#define I2S_CTRL_LRCK_POL_LOW			(0 << I2S_CTRL_LRCK_POL_SHIFT)
828c2ecf20Sopenharmony_ci#define I2S_CTRL_LRCK_POL_HIGH			BIT(I2S_CTRL_LRCK_POL_SHIFT)
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci#define I2S_CTRL_LPBK_SHIFT			8
858c2ecf20Sopenharmony_ci#define I2S_CTRL_LPBK_MASK			BIT(I2S_CTRL_LPBK_SHIFT)
868c2ecf20Sopenharmony_ci#define I2S_CTRL_LPBK_EN			BIT(I2S_CTRL_LPBK_SHIFT)
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define I2S_BITS_8				1
898c2ecf20Sopenharmony_ci#define I2S_BITS_16				3
908c2ecf20Sopenharmony_ci#define I2S_BITS_32				7
918c2ecf20Sopenharmony_ci#define I2S_CTRL_BIT_SIZE_MASK			0x7
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define I2S_TIMING_CH_BIT_CNT_MASK		0x7ff
948c2ecf20Sopenharmony_ci#define I2S_TIMING_CH_BIT_CNT_SHIFT		0
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define I2S_SOFT_RESET_SHIFT			0
978c2ecf20Sopenharmony_ci#define I2S_SOFT_RESET_MASK			BIT(I2S_SOFT_RESET_SHIFT)
988c2ecf20Sopenharmony_ci#define I2S_SOFT_RESET_EN			BIT(I2S_SOFT_RESET_SHIFT)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci#define I2S_RX_FIFO_DEPTH			64
1018c2ecf20Sopenharmony_ci#define DEFAULT_I2S_RX_FIFO_THRESHOLD		3
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci#define DEFAULT_I2S_SLOT_MASK			0xffff
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cienum tegra210_i2s_path {
1068c2ecf20Sopenharmony_ci	I2S_RX_PATH,
1078c2ecf20Sopenharmony_ci	I2S_TX_PATH,
1088c2ecf20Sopenharmony_ci	I2S_PATHS,
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistruct tegra210_i2s {
1128c2ecf20Sopenharmony_ci	struct clk *clk_i2s;
1138c2ecf20Sopenharmony_ci	struct clk *clk_sync_input;
1148c2ecf20Sopenharmony_ci	struct regmap *regmap;
1158c2ecf20Sopenharmony_ci	unsigned int stereo_to_mono[I2S_PATHS];
1168c2ecf20Sopenharmony_ci	unsigned int mono_to_stereo[I2S_PATHS];
1178c2ecf20Sopenharmony_ci	unsigned int dai_fmt;
1188c2ecf20Sopenharmony_ci	unsigned int fsync_width;
1198c2ecf20Sopenharmony_ci	unsigned int bclk_ratio;
1208c2ecf20Sopenharmony_ci	unsigned int tx_mask;
1218c2ecf20Sopenharmony_ci	unsigned int rx_mask;
1228c2ecf20Sopenharmony_ci	unsigned int rx_fifo_th;
1238c2ecf20Sopenharmony_ci	bool loopback;
1248c2ecf20Sopenharmony_ci};
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#endif
127