18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * NWL MIPI DSI host driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2017 NXP
68c2ecf20Sopenharmony_ci * Copyright (C) 2019 Purism SPC
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci#ifndef __NWL_DSI_H__
98c2ecf20Sopenharmony_ci#define __NWL_DSI_H__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci/* DSI HOST registers */
128c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_NUM_LANES			0x0
138c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_NONCONTINUOUS_CLK		0x4
148c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_T_PRE			0x8
158c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_T_POST			0xc
168c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_TX_GAP			0x10
178c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_AUTOINSERT_EOTP		0x14
188c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_EXTRA_CMDS_AFTER_EOTP	0x18
198c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_HTX_TO_COUNT		0x1c
208c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_LRX_H_TO_COUNT		0x20
218c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_BTA_H_TO_COUNT		0x24
228c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_TWAKEUP			0x28
238c2ecf20Sopenharmony_ci#define NWL_DSI_CFG_STATUS_OUT			0x2c
248c2ecf20Sopenharmony_ci#define NWL_DSI_RX_ERROR_STATUS			0x30
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* DSI DPI registers */
278c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_PAYLOAD_SIZE		0x200
288c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_FIFO_SEND_LEVEL		0x204
298c2ecf20Sopenharmony_ci#define NWL_DSI_INTERFACE_COLOR_CODING		0x208
308c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_FORMAT			0x20c
318c2ecf20Sopenharmony_ci#define NWL_DSI_VSYNC_POLARITY			0x210
328c2ecf20Sopenharmony_ci#define NWL_DSI_VSYNC_POLARITY_ACTIVE_LOW	0
338c2ecf20Sopenharmony_ci#define NWL_DSI_VSYNC_POLARITY_ACTIVE_HIGH	BIT(1)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define NWL_DSI_HSYNC_POLARITY			0x214
368c2ecf20Sopenharmony_ci#define NWL_DSI_HSYNC_POLARITY_ACTIVE_LOW	0
378c2ecf20Sopenharmony_ci#define NWL_DSI_HSYNC_POLARITY_ACTIVE_HIGH	BIT(1)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define NWL_DSI_VIDEO_MODE			0x218
408c2ecf20Sopenharmony_ci#define NWL_DSI_HFP				0x21c
418c2ecf20Sopenharmony_ci#define NWL_DSI_HBP				0x220
428c2ecf20Sopenharmony_ci#define NWL_DSI_HSA				0x224
438c2ecf20Sopenharmony_ci#define NWL_DSI_ENABLE_MULT_PKTS		0x228
448c2ecf20Sopenharmony_ci#define NWL_DSI_VBP				0x22c
458c2ecf20Sopenharmony_ci#define NWL_DSI_VFP				0x230
468c2ecf20Sopenharmony_ci#define NWL_DSI_BLLP_MODE			0x234
478c2ecf20Sopenharmony_ci#define NWL_DSI_USE_NULL_PKT_BLLP		0x238
488c2ecf20Sopenharmony_ci#define NWL_DSI_VACTIVE				0x23c
498c2ecf20Sopenharmony_ci#define NWL_DSI_VC				0x240
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/* DSI APB PKT control */
528c2ecf20Sopenharmony_ci#define NWL_DSI_TX_PAYLOAD			0x280
538c2ecf20Sopenharmony_ci#define NWL_DSI_PKT_CONTROL			0x284
548c2ecf20Sopenharmony_ci#define NWL_DSI_SEND_PACKET			0x288
558c2ecf20Sopenharmony_ci#define NWL_DSI_PKT_STATUS			0x28c
568c2ecf20Sopenharmony_ci#define NWL_DSI_PKT_FIFO_WR_LEVEL		0x290
578c2ecf20Sopenharmony_ci#define NWL_DSI_PKT_FIFO_RD_LEVEL		0x294
588c2ecf20Sopenharmony_ci#define NWL_DSI_RX_PAYLOAD			0x298
598c2ecf20Sopenharmony_ci#define NWL_DSI_RX_PKT_HEADER			0x29c
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci/* DSI IRQ handling */
628c2ecf20Sopenharmony_ci#define NWL_DSI_IRQ_STATUS			0x2a0
638c2ecf20Sopenharmony_ci#define NWL_DSI_SM_NOT_IDLE			BIT(0)
648c2ecf20Sopenharmony_ci#define NWL_DSI_TX_PKT_DONE			BIT(1)
658c2ecf20Sopenharmony_ci#define NWL_DSI_DPHY_DIRECTION			BIT(2)
668c2ecf20Sopenharmony_ci#define NWL_DSI_TX_FIFO_OVFLW			BIT(3)
678c2ecf20Sopenharmony_ci#define NWL_DSI_TX_FIFO_UDFLW			BIT(4)
688c2ecf20Sopenharmony_ci#define NWL_DSI_RX_FIFO_OVFLW			BIT(5)
698c2ecf20Sopenharmony_ci#define NWL_DSI_RX_FIFO_UDFLW			BIT(6)
708c2ecf20Sopenharmony_ci#define NWL_DSI_RX_PKT_HDR_RCVD			BIT(7)
718c2ecf20Sopenharmony_ci#define NWL_DSI_RX_PKT_PAYLOAD_DATA_RCVD	BIT(8)
728c2ecf20Sopenharmony_ci#define NWL_DSI_BTA_TIMEOUT			BIT(29)
738c2ecf20Sopenharmony_ci#define NWL_DSI_LP_RX_TIMEOUT			BIT(30)
748c2ecf20Sopenharmony_ci#define NWL_DSI_HS_TX_TIMEOUT			BIT(31)
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci#define NWL_DSI_IRQ_STATUS2			0x2a4
778c2ecf20Sopenharmony_ci#define NWL_DSI_SINGLE_BIT_ECC_ERR		BIT(0)
788c2ecf20Sopenharmony_ci#define NWL_DSI_MULTI_BIT_ECC_ERR		BIT(1)
798c2ecf20Sopenharmony_ci#define NWL_DSI_CRC_ERR				BIT(2)
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define NWL_DSI_IRQ_MASK			0x2a8
828c2ecf20Sopenharmony_ci#define NWL_DSI_SM_NOT_IDLE_MASK		BIT(0)
838c2ecf20Sopenharmony_ci#define NWL_DSI_TX_PKT_DONE_MASK		BIT(1)
848c2ecf20Sopenharmony_ci#define NWL_DSI_DPHY_DIRECTION_MASK		BIT(2)
858c2ecf20Sopenharmony_ci#define NWL_DSI_TX_FIFO_OVFLW_MASK		BIT(3)
868c2ecf20Sopenharmony_ci#define NWL_DSI_TX_FIFO_UDFLW_MASK		BIT(4)
878c2ecf20Sopenharmony_ci#define NWL_DSI_RX_FIFO_OVFLW_MASK		BIT(5)
888c2ecf20Sopenharmony_ci#define NWL_DSI_RX_FIFO_UDFLW_MASK		BIT(6)
898c2ecf20Sopenharmony_ci#define NWL_DSI_RX_PKT_HDR_RCVD_MASK		BIT(7)
908c2ecf20Sopenharmony_ci#define NWL_DSI_RX_PKT_PAYLOAD_DATA_RCVD_MASK	BIT(8)
918c2ecf20Sopenharmony_ci#define NWL_DSI_BTA_TIMEOUT_MASK		BIT(29)
928c2ecf20Sopenharmony_ci#define NWL_DSI_LP_RX_TIMEOUT_MASK		BIT(30)
938c2ecf20Sopenharmony_ci#define NWL_DSI_HS_TX_TIMEOUT_MASK		BIT(31)
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_ci#define NWL_DSI_IRQ_MASK2			0x2ac
968c2ecf20Sopenharmony_ci#define NWL_DSI_SINGLE_BIT_ECC_ERR_MASK		BIT(0)
978c2ecf20Sopenharmony_ci#define NWL_DSI_MULTI_BIT_ECC_ERR_MASK		BIT(1)
988c2ecf20Sopenharmony_ci#define NWL_DSI_CRC_ERR_MASK			BIT(2)
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * PKT_CONTROL format:
1028c2ecf20Sopenharmony_ci * [15: 0] - word count
1038c2ecf20Sopenharmony_ci * [17:16] - virtual channel
1048c2ecf20Sopenharmony_ci * [23:18] - data type
1058c2ecf20Sopenharmony_ci * [24]	   - LP or HS select (0 - LP, 1 - HS)
1068c2ecf20Sopenharmony_ci * [25]	   - perform BTA after packet is sent
1078c2ecf20Sopenharmony_ci * [26]	   - perform BTA only, no packet tx
1088c2ecf20Sopenharmony_ci */
1098c2ecf20Sopenharmony_ci#define NWL_DSI_WC(x)		FIELD_PREP(GENMASK(15, 0), (x))
1108c2ecf20Sopenharmony_ci#define NWL_DSI_TX_VC(x)	FIELD_PREP(GENMASK(17, 16), (x))
1118c2ecf20Sopenharmony_ci#define NWL_DSI_TX_DT(x)	FIELD_PREP(GENMASK(23, 18), (x))
1128c2ecf20Sopenharmony_ci#define NWL_DSI_HS_SEL(x)	FIELD_PREP(GENMASK(24, 24), (x))
1138c2ecf20Sopenharmony_ci#define NWL_DSI_BTA_TX(x)	FIELD_PREP(GENMASK(25, 25), (x))
1148c2ecf20Sopenharmony_ci#define NWL_DSI_BTA_NO_TX(x)	FIELD_PREP(GENMASK(26, 26), (x))
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/*
1178c2ecf20Sopenharmony_ci * RX_PKT_HEADER format:
1188c2ecf20Sopenharmony_ci * [15: 0] - word count
1198c2ecf20Sopenharmony_ci * [21:16] - data type
1208c2ecf20Sopenharmony_ci * [23:22] - virtual channel
1218c2ecf20Sopenharmony_ci */
1228c2ecf20Sopenharmony_ci#define NWL_DSI_RX_DT(x)	FIELD_GET(GENMASK(21, 16), (x))
1238c2ecf20Sopenharmony_ci#define NWL_DSI_RX_VC(x)	FIELD_GET(GENMASK(23, 22), (x))
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci/* DSI Video mode */
1268c2ecf20Sopenharmony_ci#define NWL_DSI_VM_BURST_MODE_WITH_SYNC_PULSES		0
1278c2ecf20Sopenharmony_ci#define NWL_DSI_VM_NON_BURST_MODE_WITH_SYNC_EVENTS	BIT(0)
1288c2ecf20Sopenharmony_ci#define NWL_DSI_VM_BURST_MODE				BIT(1)
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_ci/* * DPI color coding */
1318c2ecf20Sopenharmony_ci#define NWL_DSI_DPI_16_BIT_565_PACKED	0
1328c2ecf20Sopenharmony_ci#define NWL_DSI_DPI_16_BIT_565_ALIGNED	1
1338c2ecf20Sopenharmony_ci#define NWL_DSI_DPI_16_BIT_565_SHIFTED	2
1348c2ecf20Sopenharmony_ci#define NWL_DSI_DPI_18_BIT_PACKED	3
1358c2ecf20Sopenharmony_ci#define NWL_DSI_DPI_18_BIT_ALIGNED	4
1368c2ecf20Sopenharmony_ci#define NWL_DSI_DPI_24_BIT		5
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci/* * DPI Pixel format */
1398c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_FORMAT_16  0
1408c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_FORMAT_18  BIT(0)
1418c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_FORMAT_18L BIT(1)
1428c2ecf20Sopenharmony_ci#define NWL_DSI_PIXEL_FORMAT_24  (BIT(0) | BIT(1))
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci#endif /* __NWL_DSI_H__ */
145