xref: /openbmc/linux/drivers/gpu/drm/msm/dp/dp_catalog.c (revision a8e981ac)
1c943b494SChandan Uddaraju // SPDX-License-Identifier: GPL-2.0-only
2c943b494SChandan Uddaraju /*
3c943b494SChandan Uddaraju  * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
4c943b494SChandan Uddaraju  */
5c943b494SChandan Uddaraju 
6c943b494SChandan Uddaraju #define pr_fmt(fmt)	"[drm-dp] %s: " fmt, __func__
7c943b494SChandan Uddaraju 
8c943b494SChandan Uddaraju #include <linux/delay.h>
9c943b494SChandan Uddaraju #include <linux/iopoll.h>
10937f941cSStephen Boyd #include <linux/phy/phy.h>
11937f941cSStephen Boyd #include <linux/phy/phy-dp.h>
12c943b494SChandan Uddaraju #include <linux/rational.h>
13da68386dSThomas Zimmermann #include <drm/display/drm_dp_helper.h>
14937f941cSStephen Boyd #include <drm/drm_print.h>
15c943b494SChandan Uddaraju 
16c943b494SChandan Uddaraju #include "dp_catalog.h"
17c943b494SChandan Uddaraju #include "dp_reg.h"
18c943b494SChandan Uddaraju 
19c943b494SChandan Uddaraju #define POLLING_SLEEP_US			1000
20c943b494SChandan Uddaraju #define POLLING_TIMEOUT_US			10000
21c943b494SChandan Uddaraju 
22c943b494SChandan Uddaraju #define SCRAMBLER_RESET_COUNT_VALUE		0xFC
23c943b494SChandan Uddaraju 
24c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS_ACK_SHIFT	1
25c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS_MASK_SHIFT	2
26c943b494SChandan Uddaraju 
27757a2f36SKuogee Hsieh #define DP_INTF_CONFIG_DATABUS_WIDEN     BIT(4)
28757a2f36SKuogee Hsieh 
29c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS1 \
30b20566cdSDouglas Anderson 	(DP_INTR_AUX_XFER_DONE| \
31c943b494SChandan Uddaraju 	DP_INTR_WRONG_ADDR | DP_INTR_TIMEOUT | \
32c943b494SChandan Uddaraju 	DP_INTR_NACK_DEFER | DP_INTR_WRONG_DATA_CNT | \
33c943b494SChandan Uddaraju 	DP_INTR_I2C_NACK | DP_INTR_I2C_DEFER | \
34c943b494SChandan Uddaraju 	DP_INTR_PLL_UNLOCKED | DP_INTR_AUX_ERROR)
35c943b494SChandan Uddaraju 
36c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS1_ACK \
37c943b494SChandan Uddaraju 	(DP_INTERRUPT_STATUS1 << DP_INTERRUPT_STATUS_ACK_SHIFT)
38c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS1_MASK \
39c943b494SChandan Uddaraju 	(DP_INTERRUPT_STATUS1 << DP_INTERRUPT_STATUS_MASK_SHIFT)
40c943b494SChandan Uddaraju 
41c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS2 \
42c943b494SChandan Uddaraju 	(DP_INTR_READY_FOR_VIDEO | DP_INTR_IDLE_PATTERN_SENT | \
43c943b494SChandan Uddaraju 	DP_INTR_FRAME_END | DP_INTR_CRC_UPDATED)
44c943b494SChandan Uddaraju 
45c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS2_ACK \
46c943b494SChandan Uddaraju 	(DP_INTERRUPT_STATUS2 << DP_INTERRUPT_STATUS_ACK_SHIFT)
47c943b494SChandan Uddaraju #define DP_INTERRUPT_STATUS2_MASK \
48c943b494SChandan Uddaraju 	(DP_INTERRUPT_STATUS2 << DP_INTERRUPT_STATUS_MASK_SHIFT)
49c943b494SChandan Uddaraju 
50cd779808SVinod Polimera #define DP_INTERRUPT_STATUS4 \
51cd779808SVinod Polimera 	(PSR_UPDATE_INT | PSR_CAPTURE_INT | PSR_EXIT_INT | \
52cd779808SVinod Polimera 	PSR_UPDATE_ERROR_INT | PSR_WAKE_ERROR_INT)
53cd779808SVinod Polimera 
54cd779808SVinod Polimera #define DP_INTERRUPT_MASK4 \
55cd779808SVinod Polimera 	(PSR_UPDATE_MASK | PSR_CAPTURE_MASK | PSR_EXIT_MASK | \
56cd779808SVinod Polimera 	PSR_UPDATE_ERROR_MASK | PSR_WAKE_ERROR_MASK)
57cd779808SVinod Polimera 
58c943b494SChandan Uddaraju struct dp_catalog_private {
59c943b494SChandan Uddaraju 	struct device *dev;
60202aceacSKuogee Hsieh 	struct drm_device *drm_dev;
61c943b494SChandan Uddaraju 	struct dp_io *io;
62d13e36d7SAbhinav Kumar 	u32 (*audio_map)[DP_AUDIO_SDP_HEADER_MAX];
63c943b494SChandan Uddaraju 	struct dp_catalog dp_catalog;
64c943b494SChandan Uddaraju 	u8 aux_lut_cfg_index[PHY_AUX_CFG_MAX];
65c943b494SChandan Uddaraju };
66c943b494SChandan Uddaraju 
dp_catalog_snapshot(struct dp_catalog * dp_catalog,struct msm_disp_state * disp_state)670f6090f3SAbhinav Kumar void dp_catalog_snapshot(struct dp_catalog *dp_catalog, struct msm_disp_state *disp_state)
680f6090f3SAbhinav Kumar {
690f6090f3SAbhinav Kumar 	struct dp_catalog_private *catalog = container_of(dp_catalog,
700f6090f3SAbhinav Kumar 			struct dp_catalog_private, dp_catalog);
71060c160fSBjorn Andersson 	struct dss_io_data *dss = &catalog->io->dp_controller;
720f6090f3SAbhinav Kumar 
73060c160fSBjorn Andersson 	msm_disp_snapshot_add_block(disp_state, dss->ahb.len, dss->ahb.base, "dp_ahb");
74060c160fSBjorn Andersson 	msm_disp_snapshot_add_block(disp_state, dss->aux.len, dss->aux.base, "dp_aux");
75060c160fSBjorn Andersson 	msm_disp_snapshot_add_block(disp_state, dss->link.len, dss->link.base, "dp_link");
76060c160fSBjorn Andersson 	msm_disp_snapshot_add_block(disp_state, dss->p0.len, dss->p0.base, "dp_p0");
770f6090f3SAbhinav Kumar }
780f6090f3SAbhinav Kumar 
dp_read_aux(struct dp_catalog_private * catalog,u32 offset)79c943b494SChandan Uddaraju static inline u32 dp_read_aux(struct dp_catalog_private *catalog, u32 offset)
80c943b494SChandan Uddaraju {
81060c160fSBjorn Andersson 	return readl_relaxed(catalog->io->dp_controller.aux.base + offset);
82c943b494SChandan Uddaraju }
83c943b494SChandan Uddaraju 
dp_write_aux(struct dp_catalog_private * catalog,u32 offset,u32 data)84c943b494SChandan Uddaraju static inline void dp_write_aux(struct dp_catalog_private *catalog,
85c943b494SChandan Uddaraju 			       u32 offset, u32 data)
86c943b494SChandan Uddaraju {
87c943b494SChandan Uddaraju 	/*
88c943b494SChandan Uddaraju 	 * To make sure aux reg writes happens before any other operation,
89c943b494SChandan Uddaraju 	 * this function uses writel() instread of writel_relaxed()
90c943b494SChandan Uddaraju 	 */
91060c160fSBjorn Andersson 	writel(data, catalog->io->dp_controller.aux.base + offset);
92c943b494SChandan Uddaraju }
93c943b494SChandan Uddaraju 
dp_read_ahb(const struct dp_catalog_private * catalog,u32 offset)94757a2f36SKuogee Hsieh static inline u32 dp_read_ahb(const struct dp_catalog_private *catalog, u32 offset)
95c943b494SChandan Uddaraju {
96060c160fSBjorn Andersson 	return readl_relaxed(catalog->io->dp_controller.ahb.base + offset);
97c943b494SChandan Uddaraju }
98c943b494SChandan Uddaraju 
dp_write_ahb(struct dp_catalog_private * catalog,u32 offset,u32 data)99c943b494SChandan Uddaraju static inline void dp_write_ahb(struct dp_catalog_private *catalog,
100c943b494SChandan Uddaraju 			       u32 offset, u32 data)
101c943b494SChandan Uddaraju {
102c943b494SChandan Uddaraju 	/*
103c943b494SChandan Uddaraju 	 * To make sure phy reg writes happens before any other operation,
104c943b494SChandan Uddaraju 	 * this function uses writel() instread of writel_relaxed()
105c943b494SChandan Uddaraju 	 */
106060c160fSBjorn Andersson 	writel(data, catalog->io->dp_controller.ahb.base + offset);
107c943b494SChandan Uddaraju }
108c943b494SChandan Uddaraju 
dp_write_p0(struct dp_catalog_private * catalog,u32 offset,u32 data)109c943b494SChandan Uddaraju static inline void dp_write_p0(struct dp_catalog_private *catalog,
110c943b494SChandan Uddaraju 			       u32 offset, u32 data)
111c943b494SChandan Uddaraju {
112c943b494SChandan Uddaraju 	/*
113c943b494SChandan Uddaraju 	 * To make sure interface reg writes happens before any other operation,
114c943b494SChandan Uddaraju 	 * this function uses writel() instread of writel_relaxed()
115c943b494SChandan Uddaraju 	 */
116060c160fSBjorn Andersson 	writel(data, catalog->io->dp_controller.p0.base + offset);
117c943b494SChandan Uddaraju }
118c943b494SChandan Uddaraju 
dp_read_p0(struct dp_catalog_private * catalog,u32 offset)119c943b494SChandan Uddaraju static inline u32 dp_read_p0(struct dp_catalog_private *catalog,
120c943b494SChandan Uddaraju 			       u32 offset)
121c943b494SChandan Uddaraju {
122c943b494SChandan Uddaraju 	/*
123c943b494SChandan Uddaraju 	 * To make sure interface reg writes happens before any other operation,
124c943b494SChandan Uddaraju 	 * this function uses writel() instread of writel_relaxed()
125c943b494SChandan Uddaraju 	 */
126060c160fSBjorn Andersson 	return readl_relaxed(catalog->io->dp_controller.p0.base + offset);
127c943b494SChandan Uddaraju }
128c943b494SChandan Uddaraju 
dp_read_link(struct dp_catalog_private * catalog,u32 offset)129c943b494SChandan Uddaraju static inline u32 dp_read_link(struct dp_catalog_private *catalog, u32 offset)
130c943b494SChandan Uddaraju {
131060c160fSBjorn Andersson 	return readl_relaxed(catalog->io->dp_controller.link.base + offset);
132c943b494SChandan Uddaraju }
133c943b494SChandan Uddaraju 
dp_write_link(struct dp_catalog_private * catalog,u32 offset,u32 data)134c943b494SChandan Uddaraju static inline void dp_write_link(struct dp_catalog_private *catalog,
135c943b494SChandan Uddaraju 			       u32 offset, u32 data)
136c943b494SChandan Uddaraju {
137c943b494SChandan Uddaraju 	/*
138c943b494SChandan Uddaraju 	 * To make sure link reg writes happens before any other operation,
139c943b494SChandan Uddaraju 	 * this function uses writel() instread of writel_relaxed()
140c943b494SChandan Uddaraju 	 */
141060c160fSBjorn Andersson 	writel(data, catalog->io->dp_controller.link.base + offset);
142c943b494SChandan Uddaraju }
143c943b494SChandan Uddaraju 
144c943b494SChandan Uddaraju /* aux related catalog functions */
dp_catalog_aux_read_data(struct dp_catalog * dp_catalog)145c943b494SChandan Uddaraju u32 dp_catalog_aux_read_data(struct dp_catalog *dp_catalog)
146c943b494SChandan Uddaraju {
147c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
148c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
149c943b494SChandan Uddaraju 
150c943b494SChandan Uddaraju 	return dp_read_aux(catalog, REG_DP_AUX_DATA);
151c943b494SChandan Uddaraju }
152c943b494SChandan Uddaraju 
dp_catalog_aux_write_data(struct dp_catalog * dp_catalog)153c943b494SChandan Uddaraju int dp_catalog_aux_write_data(struct dp_catalog *dp_catalog)
154c943b494SChandan Uddaraju {
155c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
156c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
157c943b494SChandan Uddaraju 
158c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_AUX_DATA, dp_catalog->aux_data);
159c943b494SChandan Uddaraju 	return 0;
160c943b494SChandan Uddaraju }
161c943b494SChandan Uddaraju 
dp_catalog_aux_write_trans(struct dp_catalog * dp_catalog)162c943b494SChandan Uddaraju int dp_catalog_aux_write_trans(struct dp_catalog *dp_catalog)
163c943b494SChandan Uddaraju {
164c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
165c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
166c943b494SChandan Uddaraju 
167c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_AUX_TRANS_CTRL, dp_catalog->aux_data);
168c943b494SChandan Uddaraju 	return 0;
169c943b494SChandan Uddaraju }
170c943b494SChandan Uddaraju 
dp_catalog_aux_clear_trans(struct dp_catalog * dp_catalog,bool read)171c943b494SChandan Uddaraju int dp_catalog_aux_clear_trans(struct dp_catalog *dp_catalog, bool read)
172c943b494SChandan Uddaraju {
173c943b494SChandan Uddaraju 	u32 data;
174c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
175c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
176c943b494SChandan Uddaraju 
177c943b494SChandan Uddaraju 	if (read) {
178c943b494SChandan Uddaraju 		data = dp_read_aux(catalog, REG_DP_AUX_TRANS_CTRL);
179c943b494SChandan Uddaraju 		data &= ~DP_AUX_TRANS_CTRL_GO;
180c943b494SChandan Uddaraju 		dp_write_aux(catalog, REG_DP_AUX_TRANS_CTRL, data);
181c943b494SChandan Uddaraju 	} else {
182c943b494SChandan Uddaraju 		dp_write_aux(catalog, REG_DP_AUX_TRANS_CTRL, 0);
183c943b494SChandan Uddaraju 	}
184c943b494SChandan Uddaraju 	return 0;
185c943b494SChandan Uddaraju }
186c943b494SChandan Uddaraju 
dp_catalog_aux_clear_hw_interrupts(struct dp_catalog * dp_catalog)187c943b494SChandan Uddaraju int dp_catalog_aux_clear_hw_interrupts(struct dp_catalog *dp_catalog)
188c943b494SChandan Uddaraju {
189c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
190c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
191c943b494SChandan Uddaraju 
192c943b494SChandan Uddaraju 	dp_read_aux(catalog, REG_DP_PHY_AUX_INTERRUPT_STATUS);
193c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_PHY_AUX_INTERRUPT_CLEAR, 0x1f);
194c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_PHY_AUX_INTERRUPT_CLEAR, 0x9f);
195c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_PHY_AUX_INTERRUPT_CLEAR, 0);
196c943b494SChandan Uddaraju 	return 0;
197c943b494SChandan Uddaraju }
198c943b494SChandan Uddaraju 
1999fc41843SKuogee Hsieh /**
2009fc41843SKuogee Hsieh  * dp_catalog_aux_reset() - reset AUX controller
2019fc41843SKuogee Hsieh  *
2022eb4bfc0SLee Jones  * @dp_catalog: DP catalog structure
2039fc41843SKuogee Hsieh  *
2049fc41843SKuogee Hsieh  * return: void
2059fc41843SKuogee Hsieh  *
2069fc41843SKuogee Hsieh  * This function reset AUX controller
2079fc41843SKuogee Hsieh  *
2089fc41843SKuogee Hsieh  * NOTE: reset AUX controller will also clear any pending HPD related interrupts
2099fc41843SKuogee Hsieh  *
2109fc41843SKuogee Hsieh  */
dp_catalog_aux_reset(struct dp_catalog * dp_catalog)211c943b494SChandan Uddaraju void dp_catalog_aux_reset(struct dp_catalog *dp_catalog)
212c943b494SChandan Uddaraju {
213c943b494SChandan Uddaraju 	u32 aux_ctrl;
214c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
215c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
216c943b494SChandan Uddaraju 
217c943b494SChandan Uddaraju 	aux_ctrl = dp_read_aux(catalog, REG_DP_AUX_CTRL);
218c943b494SChandan Uddaraju 
219c943b494SChandan Uddaraju 	aux_ctrl |= DP_AUX_CTRL_RESET;
220c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_AUX_CTRL, aux_ctrl);
221c943b494SChandan Uddaraju 	usleep_range(1000, 1100); /* h/w recommended delay */
222c943b494SChandan Uddaraju 
223c943b494SChandan Uddaraju 	aux_ctrl &= ~DP_AUX_CTRL_RESET;
224c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_AUX_CTRL, aux_ctrl);
225c943b494SChandan Uddaraju }
226c943b494SChandan Uddaraju 
dp_catalog_aux_enable(struct dp_catalog * dp_catalog,bool enable)227c943b494SChandan Uddaraju void dp_catalog_aux_enable(struct dp_catalog *dp_catalog, bool enable)
228c943b494SChandan Uddaraju {
229c943b494SChandan Uddaraju 	u32 aux_ctrl;
230c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
231c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
232c943b494SChandan Uddaraju 
233c943b494SChandan Uddaraju 	aux_ctrl = dp_read_aux(catalog, REG_DP_AUX_CTRL);
234c943b494SChandan Uddaraju 
235c943b494SChandan Uddaraju 	if (enable) {
236c943b494SChandan Uddaraju 		dp_write_aux(catalog, REG_DP_TIMEOUT_COUNT, 0xffff);
237c943b494SChandan Uddaraju 		dp_write_aux(catalog, REG_DP_AUX_LIMITS, 0xffff);
238c943b494SChandan Uddaraju 		aux_ctrl |= DP_AUX_CTRL_ENABLE;
239c943b494SChandan Uddaraju 	} else {
240c943b494SChandan Uddaraju 		aux_ctrl &= ~DP_AUX_CTRL_ENABLE;
241c943b494SChandan Uddaraju 	}
242c943b494SChandan Uddaraju 
243c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_AUX_CTRL, aux_ctrl);
244c943b494SChandan Uddaraju }
245c943b494SChandan Uddaraju 
dp_catalog_aux_update_cfg(struct dp_catalog * dp_catalog)246937f941cSStephen Boyd void dp_catalog_aux_update_cfg(struct dp_catalog *dp_catalog)
247c943b494SChandan Uddaraju {
248c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
249c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
250937f941cSStephen Boyd 	struct dp_io *dp_io = catalog->io;
251937f941cSStephen Boyd 	struct phy *phy = dp_io->phy;
252c943b494SChandan Uddaraju 
253937f941cSStephen Boyd 	phy_calibrate(phy);
254c943b494SChandan Uddaraju }
255c943b494SChandan Uddaraju 
dp_catalog_aux_wait_for_hpd_connect_state(struct dp_catalog * dp_catalog)25686d56a77SSankeerth Billakanti int dp_catalog_aux_wait_for_hpd_connect_state(struct dp_catalog *dp_catalog)
25786d56a77SSankeerth Billakanti {
25886d56a77SSankeerth Billakanti 	u32 state;
25986d56a77SSankeerth Billakanti 	struct dp_catalog_private *catalog = container_of(dp_catalog,
26086d56a77SSankeerth Billakanti 				struct dp_catalog_private, dp_catalog);
26186d56a77SSankeerth Billakanti 
26286d56a77SSankeerth Billakanti 	/* poll for hpd connected status every 2ms and timeout after 500ms */
26386d56a77SSankeerth Billakanti 	return readl_poll_timeout(catalog->io->dp_controller.aux.base +
26486d56a77SSankeerth Billakanti 				REG_DP_DP_HPD_INT_STATUS,
26586d56a77SSankeerth Billakanti 				state, state & DP_DP_HPD_STATE_STATUS_CONNECTED,
26686d56a77SSankeerth Billakanti 				2000, 500000);
26786d56a77SSankeerth Billakanti }
26886d56a77SSankeerth Billakanti 
dump_regs(void __iomem * base,int len)269c943b494SChandan Uddaraju static void dump_regs(void __iomem *base, int len)
270c943b494SChandan Uddaraju {
271c943b494SChandan Uddaraju 	int i;
272c943b494SChandan Uddaraju 	u32 x0, x4, x8, xc;
273c943b494SChandan Uddaraju 	u32 addr_off = 0;
274c943b494SChandan Uddaraju 
275c943b494SChandan Uddaraju 	len = DIV_ROUND_UP(len, 16);
276c943b494SChandan Uddaraju 	for (i = 0; i < len; i++) {
277c943b494SChandan Uddaraju 		x0 = readl_relaxed(base + addr_off);
278c943b494SChandan Uddaraju 		x4 = readl_relaxed(base + addr_off + 0x04);
279c943b494SChandan Uddaraju 		x8 = readl_relaxed(base + addr_off + 0x08);
280c943b494SChandan Uddaraju 		xc = readl_relaxed(base + addr_off + 0x0c);
281c943b494SChandan Uddaraju 
282c943b494SChandan Uddaraju 		pr_info("%08x: %08x %08x %08x %08x", addr_off, x0, x4, x8, xc);
283c943b494SChandan Uddaraju 		addr_off += 16;
284c943b494SChandan Uddaraju 	}
285c943b494SChandan Uddaraju }
286c943b494SChandan Uddaraju 
dp_catalog_dump_regs(struct dp_catalog * dp_catalog)287c943b494SChandan Uddaraju void dp_catalog_dump_regs(struct dp_catalog *dp_catalog)
288c943b494SChandan Uddaraju {
289c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
290c943b494SChandan Uddaraju 		struct dp_catalog_private, dp_catalog);
291060c160fSBjorn Andersson 	struct dss_io_data *io = &catalog->io->dp_controller;
292c943b494SChandan Uddaraju 
293c943b494SChandan Uddaraju 	pr_info("AHB regs\n");
294060c160fSBjorn Andersson 	dump_regs(io->ahb.base, io->ahb.len);
295c943b494SChandan Uddaraju 
296c943b494SChandan Uddaraju 	pr_info("AUXCLK regs\n");
297060c160fSBjorn Andersson 	dump_regs(io->aux.base, io->aux.len);
298c943b494SChandan Uddaraju 
299c943b494SChandan Uddaraju 	pr_info("LCLK regs\n");
300060c160fSBjorn Andersson 	dump_regs(io->link.base, io->link.len);
301c943b494SChandan Uddaraju 
302c943b494SChandan Uddaraju 	pr_info("P0CLK regs\n");
303060c160fSBjorn Andersson 	dump_regs(io->p0.base, io->p0.len);
304c943b494SChandan Uddaraju }
305c943b494SChandan Uddaraju 
dp_catalog_aux_get_irq(struct dp_catalog * dp_catalog)30624c7861bSStephen Boyd u32 dp_catalog_aux_get_irq(struct dp_catalog *dp_catalog)
307c943b494SChandan Uddaraju {
308c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
309c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
310c943b494SChandan Uddaraju 	u32 intr, intr_ack;
311c943b494SChandan Uddaraju 
312c943b494SChandan Uddaraju 	intr = dp_read_ahb(catalog, REG_DP_INTR_STATUS);
313c943b494SChandan Uddaraju 	intr &= ~DP_INTERRUPT_STATUS1_MASK;
314c943b494SChandan Uddaraju 	intr_ack = (intr & DP_INTERRUPT_STATUS1)
315c943b494SChandan Uddaraju 			<< DP_INTERRUPT_STATUS_ACK_SHIFT;
316c943b494SChandan Uddaraju 	dp_write_ahb(catalog, REG_DP_INTR_STATUS, intr_ack |
317c943b494SChandan Uddaraju 			DP_INTERRUPT_STATUS1_MASK);
318c943b494SChandan Uddaraju 
319c943b494SChandan Uddaraju 	return intr;
320c943b494SChandan Uddaraju 
321c943b494SChandan Uddaraju }
322c943b494SChandan Uddaraju 
323c943b494SChandan Uddaraju /* controller related catalog functions */
dp_catalog_ctrl_update_transfer_unit(struct dp_catalog * dp_catalog,u32 dp_tu,u32 valid_boundary,u32 valid_boundary2)324c943b494SChandan Uddaraju void dp_catalog_ctrl_update_transfer_unit(struct dp_catalog *dp_catalog,
325c943b494SChandan Uddaraju 				u32 dp_tu, u32 valid_boundary,
326c943b494SChandan Uddaraju 				u32 valid_boundary2)
327c943b494SChandan Uddaraju {
328c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
329c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
330c943b494SChandan Uddaraju 
331c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_VALID_BOUNDARY, valid_boundary);
332c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_TU, dp_tu);
333c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_VALID_BOUNDARY_2, valid_boundary2);
334c943b494SChandan Uddaraju }
335c943b494SChandan Uddaraju 
dp_catalog_ctrl_state_ctrl(struct dp_catalog * dp_catalog,u32 state)336c943b494SChandan Uddaraju void dp_catalog_ctrl_state_ctrl(struct dp_catalog *dp_catalog, u32 state)
337c943b494SChandan Uddaraju {
338c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
339c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
340c943b494SChandan Uddaraju 
341c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_STATE_CTRL, state);
342c943b494SChandan Uddaraju }
343c943b494SChandan Uddaraju 
dp_catalog_ctrl_config_ctrl(struct dp_catalog * dp_catalog,u32 cfg)344c943b494SChandan Uddaraju void dp_catalog_ctrl_config_ctrl(struct dp_catalog *dp_catalog, u32 cfg)
345c943b494SChandan Uddaraju {
346c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
347c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
348c943b494SChandan Uddaraju 
349202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "DP_CONFIGURATION_CTRL=0x%x\n", cfg);
350c943b494SChandan Uddaraju 
351c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_CONFIGURATION_CTRL, cfg);
352c943b494SChandan Uddaraju }
353c943b494SChandan Uddaraju 
dp_catalog_ctrl_lane_mapping(struct dp_catalog * dp_catalog)354c943b494SChandan Uddaraju void dp_catalog_ctrl_lane_mapping(struct dp_catalog *dp_catalog)
355c943b494SChandan Uddaraju {
356c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
357c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
358c943b494SChandan Uddaraju 	u32 ln_0 = 0, ln_1 = 1, ln_2 = 2, ln_3 = 3; /* One-to-One mapping */
359c943b494SChandan Uddaraju 	u32 ln_mapping;
360c943b494SChandan Uddaraju 
361c943b494SChandan Uddaraju 	ln_mapping = ln_0 << LANE0_MAPPING_SHIFT;
362c943b494SChandan Uddaraju 	ln_mapping |= ln_1 << LANE1_MAPPING_SHIFT;
363c943b494SChandan Uddaraju 	ln_mapping |= ln_2 << LANE2_MAPPING_SHIFT;
364c943b494SChandan Uddaraju 	ln_mapping |= ln_3 << LANE3_MAPPING_SHIFT;
365c943b494SChandan Uddaraju 
366c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_LOGICAL2PHYSICAL_LANE_MAPPING,
367c943b494SChandan Uddaraju 			ln_mapping);
368c943b494SChandan Uddaraju }
369c943b494SChandan Uddaraju 
dp_catalog_ctrl_psr_mainlink_enable(struct dp_catalog * dp_catalog,bool enable)370cd779808SVinod Polimera void dp_catalog_ctrl_psr_mainlink_enable(struct dp_catalog *dp_catalog,
371cd779808SVinod Polimera 						bool enable)
372cd779808SVinod Polimera {
373cd779808SVinod Polimera 	u32 val;
374cd779808SVinod Polimera 	struct dp_catalog_private *catalog = container_of(dp_catalog,
375cd779808SVinod Polimera 				struct dp_catalog_private, dp_catalog);
376cd779808SVinod Polimera 
377cd779808SVinod Polimera 	val = dp_read_link(catalog, REG_DP_MAINLINK_CTRL);
378cd779808SVinod Polimera 
379cd779808SVinod Polimera 	if (enable)
380cd779808SVinod Polimera 		val |= DP_MAINLINK_CTRL_ENABLE;
381cd779808SVinod Polimera 	else
382cd779808SVinod Polimera 		val &= ~DP_MAINLINK_CTRL_ENABLE;
383cd779808SVinod Polimera 
384cd779808SVinod Polimera 	dp_write_link(catalog, REG_DP_MAINLINK_CTRL, val);
385cd779808SVinod Polimera }
386cd779808SVinod Polimera 
dp_catalog_ctrl_mainlink_ctrl(struct dp_catalog * dp_catalog,bool enable)387c943b494SChandan Uddaraju void dp_catalog_ctrl_mainlink_ctrl(struct dp_catalog *dp_catalog,
388c943b494SChandan Uddaraju 						bool enable)
389c943b494SChandan Uddaraju {
390c943b494SChandan Uddaraju 	u32 mainlink_ctrl;
391c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
392c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
393c943b494SChandan Uddaraju 
394202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "enable=%d\n", enable);
395c943b494SChandan Uddaraju 	if (enable) {
396c943b494SChandan Uddaraju 		/*
397c943b494SChandan Uddaraju 		 * To make sure link reg writes happens before other operation,
398c943b494SChandan Uddaraju 		 * dp_write_link() function uses writel()
399c943b494SChandan Uddaraju 		 */
4008ede2eccSKuogee Hsieh 		mainlink_ctrl = dp_read_link(catalog, REG_DP_MAINLINK_CTRL);
4018ede2eccSKuogee Hsieh 
4028ede2eccSKuogee Hsieh 		mainlink_ctrl &= ~(DP_MAINLINK_CTRL_RESET |
403c943b494SChandan Uddaraju 						DP_MAINLINK_CTRL_ENABLE);
4048ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, mainlink_ctrl);
4058ede2eccSKuogee Hsieh 
4068ede2eccSKuogee Hsieh 		mainlink_ctrl |= DP_MAINLINK_CTRL_RESET;
4078ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, mainlink_ctrl);
4088ede2eccSKuogee Hsieh 
4098ede2eccSKuogee Hsieh 		mainlink_ctrl &= ~DP_MAINLINK_CTRL_RESET;
4108ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, mainlink_ctrl);
4118ede2eccSKuogee Hsieh 
4128ede2eccSKuogee Hsieh 		mainlink_ctrl |= (DP_MAINLINK_CTRL_ENABLE |
4138ede2eccSKuogee Hsieh 					DP_MAINLINK_FB_BOUNDARY_SEL);
4148ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, mainlink_ctrl);
415c943b494SChandan Uddaraju 	} else {
416c943b494SChandan Uddaraju 		mainlink_ctrl = dp_read_link(catalog, REG_DP_MAINLINK_CTRL);
417c943b494SChandan Uddaraju 		mainlink_ctrl &= ~DP_MAINLINK_CTRL_ENABLE;
418c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, mainlink_ctrl);
419c943b494SChandan Uddaraju 	}
420c943b494SChandan Uddaraju }
421c943b494SChandan Uddaraju 
dp_catalog_ctrl_config_misc(struct dp_catalog * dp_catalog,u32 colorimetry_cfg,u32 test_bits_depth)422c943b494SChandan Uddaraju void dp_catalog_ctrl_config_misc(struct dp_catalog *dp_catalog,
423c943b494SChandan Uddaraju 					u32 colorimetry_cfg,
424c943b494SChandan Uddaraju 					u32 test_bits_depth)
425c943b494SChandan Uddaraju {
426c943b494SChandan Uddaraju 	u32 misc_val;
427c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
428c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
429c943b494SChandan Uddaraju 
430c943b494SChandan Uddaraju 	misc_val = dp_read_link(catalog, REG_DP_MISC1_MISC0);
431c943b494SChandan Uddaraju 
432c943b494SChandan Uddaraju 	/* clear bpp bits */
433c943b494SChandan Uddaraju 	misc_val &= ~(0x07 << DP_MISC0_TEST_BITS_DEPTH_SHIFT);
434c943b494SChandan Uddaraju 	misc_val |= colorimetry_cfg << DP_MISC0_COLORIMETRY_CFG_SHIFT;
435c943b494SChandan Uddaraju 	misc_val |= test_bits_depth << DP_MISC0_TEST_BITS_DEPTH_SHIFT;
436c943b494SChandan Uddaraju 	/* Configure clock to synchronous mode */
437c943b494SChandan Uddaraju 	misc_val |= DP_MISC0_SYNCHRONOUS_CLK;
438c943b494SChandan Uddaraju 
439202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "misc settings = 0x%x\n", misc_val);
440c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_MISC1_MISC0, misc_val);
441c943b494SChandan Uddaraju }
442c943b494SChandan Uddaraju 
dp_catalog_ctrl_config_msa(struct dp_catalog * dp_catalog,u32 rate,u32 stream_rate_khz,bool fixed_nvid)443c943b494SChandan Uddaraju void dp_catalog_ctrl_config_msa(struct dp_catalog *dp_catalog,
444c943b494SChandan Uddaraju 					u32 rate, u32 stream_rate_khz,
445c943b494SChandan Uddaraju 					bool fixed_nvid)
446c943b494SChandan Uddaraju {
447c943b494SChandan Uddaraju 	u32 pixel_m, pixel_n;
448937f941cSStephen Boyd 	u32 mvid, nvid, pixel_div = 0, dispcc_input_rate;
449c943b494SChandan Uddaraju 	u32 const nvid_fixed = DP_LINK_CONSTANT_N_VALUE;
450c943b494SChandan Uddaraju 	u32 const link_rate_hbr2 = 540000;
451c943b494SChandan Uddaraju 	u32 const link_rate_hbr3 = 810000;
452c943b494SChandan Uddaraju 	unsigned long den, num;
453c943b494SChandan Uddaraju 
454c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
455c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
456c943b494SChandan Uddaraju 
457937f941cSStephen Boyd 	if (rate == link_rate_hbr3)
458c943b494SChandan Uddaraju 		pixel_div = 6;
459aa0bff10SKuogee Hsieh 	else if (rate == 162000 || rate == 270000)
460c943b494SChandan Uddaraju 		pixel_div = 2;
461937f941cSStephen Boyd 	else if (rate == link_rate_hbr2)
462c943b494SChandan Uddaraju 		pixel_div = 4;
463c943b494SChandan Uddaraju 	else
464c943b494SChandan Uddaraju 		DRM_ERROR("Invalid pixel mux divider\n");
465c943b494SChandan Uddaraju 
466c943b494SChandan Uddaraju 	dispcc_input_rate = (rate * 10) / pixel_div;
467c943b494SChandan Uddaraju 
468c943b494SChandan Uddaraju 	rational_best_approximation(dispcc_input_rate, stream_rate_khz,
469c943b494SChandan Uddaraju 			(unsigned long)(1 << 16) - 1,
470c943b494SChandan Uddaraju 			(unsigned long)(1 << 16) - 1, &den, &num);
471c943b494SChandan Uddaraju 
472c943b494SChandan Uddaraju 	den = ~(den - num);
473c943b494SChandan Uddaraju 	den = den & 0xFFFF;
474c943b494SChandan Uddaraju 	pixel_m = num;
475c943b494SChandan Uddaraju 	pixel_n = den;
476c943b494SChandan Uddaraju 
477c943b494SChandan Uddaraju 	mvid = (pixel_m & 0xFFFF) * 5;
478c943b494SChandan Uddaraju 	nvid = (0xFFFF & (~pixel_n)) + (pixel_m & 0xFFFF);
479c943b494SChandan Uddaraju 
480c943b494SChandan Uddaraju 	if (nvid < nvid_fixed) {
481c943b494SChandan Uddaraju 		u32 temp;
482c943b494SChandan Uddaraju 
483c943b494SChandan Uddaraju 		temp = (nvid_fixed / nvid) * nvid;
484c943b494SChandan Uddaraju 		mvid = (nvid_fixed / nvid) * mvid;
485c943b494SChandan Uddaraju 		nvid = temp;
486c943b494SChandan Uddaraju 	}
487c943b494SChandan Uddaraju 
488c943b494SChandan Uddaraju 	if (link_rate_hbr2 == rate)
489c943b494SChandan Uddaraju 		nvid *= 2;
490c943b494SChandan Uddaraju 
491c943b494SChandan Uddaraju 	if (link_rate_hbr3 == rate)
492c943b494SChandan Uddaraju 		nvid *= 3;
493c943b494SChandan Uddaraju 
494202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "mvid=0x%x, nvid=0x%x\n", mvid, nvid);
495c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_SOFTWARE_MVID, mvid);
496c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_SOFTWARE_NVID, nvid);
497c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_DSC_DTO, 0x0);
498c943b494SChandan Uddaraju }
499c943b494SChandan Uddaraju 
dp_catalog_ctrl_set_pattern_state_bit(struct dp_catalog * dp_catalog,u32 state_bit)50095665325SKuogee Hsieh int dp_catalog_ctrl_set_pattern_state_bit(struct dp_catalog *dp_catalog,
50195665325SKuogee Hsieh 					u32 state_bit)
502c943b494SChandan Uddaraju {
503c943b494SChandan Uddaraju 	int bit, ret;
504c943b494SChandan Uddaraju 	u32 data;
505c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
506c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
507c943b494SChandan Uddaraju 
50895665325SKuogee Hsieh 	bit = BIT(state_bit - 1);
509202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "hw: bit=%d train=%d\n", bit, state_bit);
5108ede2eccSKuogee Hsieh 	dp_catalog_ctrl_state_ctrl(dp_catalog, bit);
511c943b494SChandan Uddaraju 
51295665325SKuogee Hsieh 	bit = BIT(state_bit - 1) << DP_MAINLINK_READY_LINK_TRAINING_SHIFT;
513c943b494SChandan Uddaraju 
514c943b494SChandan Uddaraju 	/* Poll for mainlink ready status */
515060c160fSBjorn Andersson 	ret = readx_poll_timeout(readl, catalog->io->dp_controller.link.base +
516c943b494SChandan Uddaraju 					REG_DP_MAINLINK_READY,
517c943b494SChandan Uddaraju 					data, data & bit,
518c943b494SChandan Uddaraju 					POLLING_SLEEP_US, POLLING_TIMEOUT_US);
519c943b494SChandan Uddaraju 	if (ret < 0) {
52095665325SKuogee Hsieh 		DRM_ERROR("set state_bit for link_train=%d failed\n", state_bit);
521c943b494SChandan Uddaraju 		return ret;
522c943b494SChandan Uddaraju 	}
523c943b494SChandan Uddaraju 	return 0;
524c943b494SChandan Uddaraju }
525c943b494SChandan Uddaraju 
5269fc41843SKuogee Hsieh /**
527757a2f36SKuogee Hsieh  * dp_catalog_hw_revision() - retrieve DP hw revision
528757a2f36SKuogee Hsieh  *
529757a2f36SKuogee Hsieh  * @dp_catalog: DP catalog structure
530757a2f36SKuogee Hsieh  *
531757a2f36SKuogee Hsieh  * Return: DP controller hw revision
532757a2f36SKuogee Hsieh  *
533757a2f36SKuogee Hsieh  */
dp_catalog_hw_revision(const struct dp_catalog * dp_catalog)534757a2f36SKuogee Hsieh u32 dp_catalog_hw_revision(const struct dp_catalog *dp_catalog)
535757a2f36SKuogee Hsieh {
536757a2f36SKuogee Hsieh 	const struct dp_catalog_private *catalog = container_of(dp_catalog,
537757a2f36SKuogee Hsieh 				struct dp_catalog_private, dp_catalog);
538757a2f36SKuogee Hsieh 
539757a2f36SKuogee Hsieh 	return dp_read_ahb(catalog, REG_DP_HW_VERSION);
540757a2f36SKuogee Hsieh }
541757a2f36SKuogee Hsieh 
542757a2f36SKuogee Hsieh /**
5439fc41843SKuogee Hsieh  * dp_catalog_ctrl_reset() - reset DP controller
5449fc41843SKuogee Hsieh  *
5459fc41843SKuogee Hsieh  * @dp_catalog: DP catalog structure
5469fc41843SKuogee Hsieh  *
5479fc41843SKuogee Hsieh  * return: void
5489fc41843SKuogee Hsieh  *
5499fc41843SKuogee Hsieh  * This function reset the DP controller
5509fc41843SKuogee Hsieh  *
5519fc41843SKuogee Hsieh  * NOTE: reset DP controller will also clear any pending HPD related interrupts
5529fc41843SKuogee Hsieh  *
5539fc41843SKuogee Hsieh  */
dp_catalog_ctrl_reset(struct dp_catalog * dp_catalog)554c943b494SChandan Uddaraju void dp_catalog_ctrl_reset(struct dp_catalog *dp_catalog)
555c943b494SChandan Uddaraju {
556c943b494SChandan Uddaraju 	u32 sw_reset;
557c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
558c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
559c943b494SChandan Uddaraju 
560c943b494SChandan Uddaraju 	sw_reset = dp_read_ahb(catalog, REG_DP_SW_RESET);
561c943b494SChandan Uddaraju 
562c943b494SChandan Uddaraju 	sw_reset |= DP_SW_RESET;
563c943b494SChandan Uddaraju 	dp_write_ahb(catalog, REG_DP_SW_RESET, sw_reset);
564c943b494SChandan Uddaraju 	usleep_range(1000, 1100); /* h/w recommended delay */
565c943b494SChandan Uddaraju 
566c943b494SChandan Uddaraju 	sw_reset &= ~DP_SW_RESET;
567c943b494SChandan Uddaraju 	dp_write_ahb(catalog, REG_DP_SW_RESET, sw_reset);
568c943b494SChandan Uddaraju }
569c943b494SChandan Uddaraju 
dp_catalog_ctrl_mainlink_ready(struct dp_catalog * dp_catalog)570c943b494SChandan Uddaraju bool dp_catalog_ctrl_mainlink_ready(struct dp_catalog *dp_catalog)
571c943b494SChandan Uddaraju {
572c943b494SChandan Uddaraju 	u32 data;
573c943b494SChandan Uddaraju 	int ret;
574c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
575c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
576c943b494SChandan Uddaraju 
577c943b494SChandan Uddaraju 	/* Poll for mainlink ready status */
578060c160fSBjorn Andersson 	ret = readl_poll_timeout(catalog->io->dp_controller.link.base +
579c943b494SChandan Uddaraju 				REG_DP_MAINLINK_READY,
580c943b494SChandan Uddaraju 				data, data & DP_MAINLINK_READY_FOR_VIDEO,
581c943b494SChandan Uddaraju 				POLLING_SLEEP_US, POLLING_TIMEOUT_US);
582c943b494SChandan Uddaraju 	if (ret < 0) {
583c943b494SChandan Uddaraju 		DRM_ERROR("mainlink not ready\n");
584c943b494SChandan Uddaraju 		return false;
585c943b494SChandan Uddaraju 	}
586c943b494SChandan Uddaraju 
587c943b494SChandan Uddaraju 	return true;
588c943b494SChandan Uddaraju }
589c943b494SChandan Uddaraju 
dp_catalog_ctrl_enable_irq(struct dp_catalog * dp_catalog,bool enable)590c943b494SChandan Uddaraju void dp_catalog_ctrl_enable_irq(struct dp_catalog *dp_catalog,
591c943b494SChandan Uddaraju 						bool enable)
592c943b494SChandan Uddaraju {
593c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
594c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
595c943b494SChandan Uddaraju 
596c943b494SChandan Uddaraju 	if (enable) {
597c943b494SChandan Uddaraju 		dp_write_ahb(catalog, REG_DP_INTR_STATUS,
598c943b494SChandan Uddaraju 				DP_INTERRUPT_STATUS1_MASK);
599c943b494SChandan Uddaraju 		dp_write_ahb(catalog, REG_DP_INTR_STATUS2,
600c943b494SChandan Uddaraju 				DP_INTERRUPT_STATUS2_MASK);
601c943b494SChandan Uddaraju 	} else {
602c943b494SChandan Uddaraju 		dp_write_ahb(catalog, REG_DP_INTR_STATUS, 0x00);
603c943b494SChandan Uddaraju 		dp_write_ahb(catalog, REG_DP_INTR_STATUS2, 0x00);
604c943b494SChandan Uddaraju 	}
605c943b494SChandan Uddaraju }
606c943b494SChandan Uddaraju 
dp_catalog_hpd_config_intr(struct dp_catalog * dp_catalog,u32 intr_mask,bool en)607220b856aSTanmay Shah void dp_catalog_hpd_config_intr(struct dp_catalog *dp_catalog,
608220b856aSTanmay Shah 			u32 intr_mask, bool en)
609c943b494SChandan Uddaraju {
610c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
611c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
612c943b494SChandan Uddaraju 
613220b856aSTanmay Shah 	u32 config = dp_read_aux(catalog, REG_DP_DP_HPD_INT_MASK);
614220b856aSTanmay Shah 
615220b856aSTanmay Shah 	config = (en ? config | intr_mask : config & ~intr_mask);
616220b856aSTanmay Shah 
617202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "intr_mask=%#x config=%#x\n",
618202aceacSKuogee Hsieh 					intr_mask, config);
619220b856aSTanmay Shah 	dp_write_aux(catalog, REG_DP_DP_HPD_INT_MASK,
620220b856aSTanmay Shah 				config & DP_DP_HPD_INT_MASK);
621220b856aSTanmay Shah }
622220b856aSTanmay Shah 
dp_catalog_ctrl_hpd_enable(struct dp_catalog * dp_catalog)623*a8e981acSKuogee Hsieh void dp_catalog_ctrl_hpd_enable(struct dp_catalog *dp_catalog)
624220b856aSTanmay Shah {
625220b856aSTanmay Shah 	struct dp_catalog_private *catalog = container_of(dp_catalog,
626220b856aSTanmay Shah 				struct dp_catalog_private, dp_catalog);
627220b856aSTanmay Shah 
628c943b494SChandan Uddaraju 	u32 reftimer = dp_read_aux(catalog, REG_DP_DP_HPD_REFTIMER);
629c943b494SChandan Uddaraju 
630220b856aSTanmay Shah 	/* Configure REFTIMER and enable it */
631220b856aSTanmay Shah 	reftimer |= DP_DP_HPD_REFTIMER_ENABLE;
632c943b494SChandan Uddaraju 	dp_write_aux(catalog, REG_DP_DP_HPD_REFTIMER, reftimer);
633220b856aSTanmay Shah 
634c943b494SChandan Uddaraju 	/* Enable HPD */
635220b856aSTanmay Shah 	dp_write_aux(catalog, REG_DP_DP_HPD_CTRL, DP_DP_HPD_CTRL_HPD_EN);
636c943b494SChandan Uddaraju }
637220b856aSTanmay Shah 
dp_catalog_ctrl_hpd_disable(struct dp_catalog * dp_catalog)638*a8e981acSKuogee Hsieh void dp_catalog_ctrl_hpd_disable(struct dp_catalog *dp_catalog)
639*a8e981acSKuogee Hsieh {
640*a8e981acSKuogee Hsieh 	struct dp_catalog_private *catalog = container_of(dp_catalog,
641*a8e981acSKuogee Hsieh 				struct dp_catalog_private, dp_catalog);
642*a8e981acSKuogee Hsieh 
643*a8e981acSKuogee Hsieh 	u32 reftimer = dp_read_aux(catalog, REG_DP_DP_HPD_REFTIMER);
644*a8e981acSKuogee Hsieh 
645*a8e981acSKuogee Hsieh 	reftimer &= ~DP_DP_HPD_REFTIMER_ENABLE;
646*a8e981acSKuogee Hsieh 	dp_write_aux(catalog, REG_DP_DP_HPD_REFTIMER, reftimer);
647*a8e981acSKuogee Hsieh 
648*a8e981acSKuogee Hsieh 	dp_write_aux(catalog, REG_DP_DP_HPD_CTRL, 0);
649*a8e981acSKuogee Hsieh }
650*a8e981acSKuogee Hsieh 
dp_catalog_enable_sdp(struct dp_catalog_private * catalog)651cd779808SVinod Polimera static void dp_catalog_enable_sdp(struct dp_catalog_private *catalog)
652cd779808SVinod Polimera {
653cd779808SVinod Polimera 	/* trigger sdp */
654cd779808SVinod Polimera 	dp_write_link(catalog, MMSS_DP_SDP_CFG3, UPDATE_SDP);
655cd779808SVinod Polimera 	dp_write_link(catalog, MMSS_DP_SDP_CFG3, 0x0);
656cd779808SVinod Polimera }
657cd779808SVinod Polimera 
dp_catalog_ctrl_config_psr(struct dp_catalog * dp_catalog)658cd779808SVinod Polimera void dp_catalog_ctrl_config_psr(struct dp_catalog *dp_catalog)
659cd779808SVinod Polimera {
660cd779808SVinod Polimera 	struct dp_catalog_private *catalog = container_of(dp_catalog,
661cd779808SVinod Polimera 				struct dp_catalog_private, dp_catalog);
662cd779808SVinod Polimera 	u32 config;
663cd779808SVinod Polimera 
664cd779808SVinod Polimera 	/* enable PSR1 function */
665cd779808SVinod Polimera 	config = dp_read_link(catalog, REG_PSR_CONFIG);
666cd779808SVinod Polimera 	config |= PSR1_SUPPORTED;
667cd779808SVinod Polimera 	dp_write_link(catalog, REG_PSR_CONFIG, config);
668cd779808SVinod Polimera 
669cd779808SVinod Polimera 	dp_write_ahb(catalog, REG_DP_INTR_MASK4, DP_INTERRUPT_MASK4);
670cd779808SVinod Polimera 	dp_catalog_enable_sdp(catalog);
671cd779808SVinod Polimera }
672cd779808SVinod Polimera 
dp_catalog_ctrl_set_psr(struct dp_catalog * dp_catalog,bool enter)673cd779808SVinod Polimera void dp_catalog_ctrl_set_psr(struct dp_catalog *dp_catalog, bool enter)
674cd779808SVinod Polimera {
675cd779808SVinod Polimera 	struct dp_catalog_private *catalog = container_of(dp_catalog,
676cd779808SVinod Polimera 			struct dp_catalog_private, dp_catalog);
677cd779808SVinod Polimera 	u32 cmd;
678cd779808SVinod Polimera 
679cd779808SVinod Polimera 	cmd = dp_read_link(catalog, REG_PSR_CMD);
680cd779808SVinod Polimera 
681cd779808SVinod Polimera 	cmd &= ~(PSR_ENTER | PSR_EXIT);
682cd779808SVinod Polimera 
683cd779808SVinod Polimera 	if (enter)
684cd779808SVinod Polimera 		cmd |= PSR_ENTER;
685cd779808SVinod Polimera 	else
686cd779808SVinod Polimera 		cmd |= PSR_EXIT;
687cd779808SVinod Polimera 
688cd779808SVinod Polimera 	dp_catalog_enable_sdp(catalog);
689cd779808SVinod Polimera 	dp_write_link(catalog, REG_PSR_CMD, cmd);
690cd779808SVinod Polimera }
691cd779808SVinod Polimera 
dp_catalog_link_is_connected(struct dp_catalog * dp_catalog)692231a04fcSKuogee Hsieh u32 dp_catalog_link_is_connected(struct dp_catalog *dp_catalog)
69319e52bcbSKuogee Hsieh {
69419e52bcbSKuogee Hsieh 	struct dp_catalog_private *catalog = container_of(dp_catalog,
69519e52bcbSKuogee Hsieh 				struct dp_catalog_private, dp_catalog);
69619e52bcbSKuogee Hsieh 	u32 status;
69719e52bcbSKuogee Hsieh 
69819e52bcbSKuogee Hsieh 	status = dp_read_aux(catalog, REG_DP_DP_HPD_INT_STATUS);
699202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "aux status: %#x\n", status);
70019e52bcbSKuogee Hsieh 	status >>= DP_DP_HPD_STATE_STATUS_BITS_SHIFT;
70119e52bcbSKuogee Hsieh 	status &= DP_DP_HPD_STATE_STATUS_BITS_MASK;
70219e52bcbSKuogee Hsieh 
70319e52bcbSKuogee Hsieh 	return status;
70419e52bcbSKuogee Hsieh }
70519e52bcbSKuogee Hsieh 
dp_catalog_hpd_get_intr_status(struct dp_catalog * dp_catalog)706220b856aSTanmay Shah u32 dp_catalog_hpd_get_intr_status(struct dp_catalog *dp_catalog)
707220b856aSTanmay Shah {
708220b856aSTanmay Shah 	struct dp_catalog_private *catalog = container_of(dp_catalog,
709220b856aSTanmay Shah 				struct dp_catalog_private, dp_catalog);
710391c96ffSSankeerth Billakanti 	int isr, mask;
711220b856aSTanmay Shah 
712220b856aSTanmay Shah 	isr = dp_read_aux(catalog, REG_DP_DP_HPD_INT_STATUS);
713220b856aSTanmay Shah 	dp_write_aux(catalog, REG_DP_DP_HPD_INT_ACK,
714220b856aSTanmay Shah 				 (isr & DP_DP_HPD_INT_MASK));
715391c96ffSSankeerth Billakanti 	mask = dp_read_aux(catalog, REG_DP_DP_HPD_INT_MASK);
716220b856aSTanmay Shah 
717391c96ffSSankeerth Billakanti 	/*
718391c96ffSSankeerth Billakanti 	 * We only want to return interrupts that are unmasked to the caller.
719391c96ffSSankeerth Billakanti 	 * However, the interrupt status field also contains other
720391c96ffSSankeerth Billakanti 	 * informational bits about the HPD state status, so we only mask
721391c96ffSSankeerth Billakanti 	 * out the part of the register that tells us about which interrupts
722391c96ffSSankeerth Billakanti 	 * are pending.
723391c96ffSSankeerth Billakanti 	 */
724391c96ffSSankeerth Billakanti 	return isr & (mask | ~DP_DP_HPD_INT_MASK);
725c943b494SChandan Uddaraju }
726c943b494SChandan Uddaraju 
dp_catalog_ctrl_read_psr_interrupt_status(struct dp_catalog * dp_catalog)727cd779808SVinod Polimera u32 dp_catalog_ctrl_read_psr_interrupt_status(struct dp_catalog *dp_catalog)
728cd779808SVinod Polimera {
729cd779808SVinod Polimera 	struct dp_catalog_private *catalog = container_of(dp_catalog,
730cd779808SVinod Polimera 				struct dp_catalog_private, dp_catalog);
731cd779808SVinod Polimera 	u32 intr, intr_ack;
732cd779808SVinod Polimera 
733cd779808SVinod Polimera 	intr = dp_read_ahb(catalog, REG_DP_INTR_STATUS4);
734cd779808SVinod Polimera 	intr_ack = (intr & DP_INTERRUPT_STATUS4)
735cd779808SVinod Polimera 			<< DP_INTERRUPT_STATUS_ACK_SHIFT;
736cd779808SVinod Polimera 	dp_write_ahb(catalog, REG_DP_INTR_STATUS4, intr_ack);
737cd779808SVinod Polimera 
738cd779808SVinod Polimera 	return intr;
739cd779808SVinod Polimera }
740cd779808SVinod Polimera 
dp_catalog_ctrl_get_interrupt(struct dp_catalog * dp_catalog)741c943b494SChandan Uddaraju int dp_catalog_ctrl_get_interrupt(struct dp_catalog *dp_catalog)
742c943b494SChandan Uddaraju {
743c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
744c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
745c943b494SChandan Uddaraju 	u32 intr, intr_ack;
746c943b494SChandan Uddaraju 
747c943b494SChandan Uddaraju 	intr = dp_read_ahb(catalog, REG_DP_INTR_STATUS2);
748c943b494SChandan Uddaraju 	intr &= ~DP_INTERRUPT_STATUS2_MASK;
749c943b494SChandan Uddaraju 	intr_ack = (intr & DP_INTERRUPT_STATUS2)
750c943b494SChandan Uddaraju 			<< DP_INTERRUPT_STATUS_ACK_SHIFT;
751c943b494SChandan Uddaraju 	dp_write_ahb(catalog, REG_DP_INTR_STATUS2,
752c943b494SChandan Uddaraju 			intr_ack | DP_INTERRUPT_STATUS2_MASK);
753c943b494SChandan Uddaraju 
754c943b494SChandan Uddaraju 	return intr;
755c943b494SChandan Uddaraju }
756c943b494SChandan Uddaraju 
dp_catalog_ctrl_phy_reset(struct dp_catalog * dp_catalog)757c943b494SChandan Uddaraju void dp_catalog_ctrl_phy_reset(struct dp_catalog *dp_catalog)
758c943b494SChandan Uddaraju {
759c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
760c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
761c943b494SChandan Uddaraju 
762c943b494SChandan Uddaraju 	dp_write_ahb(catalog, REG_DP_PHY_CTRL,
763937f941cSStephen Boyd 			DP_PHY_CTRL_SW_RESET | DP_PHY_CTRL_SW_RESET_PLL);
764c943b494SChandan Uddaraju 	usleep_range(1000, 1100); /* h/w recommended delay */
765c943b494SChandan Uddaraju 	dp_write_ahb(catalog, REG_DP_PHY_CTRL, 0x0);
766c943b494SChandan Uddaraju }
767c943b494SChandan Uddaraju 
dp_catalog_ctrl_update_vx_px(struct dp_catalog * dp_catalog,u8 v_level,u8 p_level)768c943b494SChandan Uddaraju int dp_catalog_ctrl_update_vx_px(struct dp_catalog *dp_catalog,
769c943b494SChandan Uddaraju 		u8 v_level, u8 p_level)
770c943b494SChandan Uddaraju {
771c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
772c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
773937f941cSStephen Boyd 	struct dp_io *dp_io = catalog->io;
774937f941cSStephen Boyd 	struct phy *phy = dp_io->phy;
775937f941cSStephen Boyd 	struct phy_configure_opts_dp *opts_dp = &dp_io->phy_opts.dp;
776c943b494SChandan Uddaraju 
777937f941cSStephen Boyd 	/* TODO: Update for all lanes instead of just first one */
778937f941cSStephen Boyd 	opts_dp->voltage[0] = v_level;
779937f941cSStephen Boyd 	opts_dp->pre[0] = p_level;
780937f941cSStephen Boyd 	opts_dp->set_voltages = 1;
781937f941cSStephen Boyd 	phy_configure(phy, &dp_io->phy_opts);
782937f941cSStephen Boyd 	opts_dp->set_voltages = 0;
783c943b494SChandan Uddaraju 
784c943b494SChandan Uddaraju 	return 0;
785c943b494SChandan Uddaraju }
786c943b494SChandan Uddaraju 
dp_catalog_ctrl_send_phy_pattern(struct dp_catalog * dp_catalog,u32 pattern)787c943b494SChandan Uddaraju void dp_catalog_ctrl_send_phy_pattern(struct dp_catalog *dp_catalog,
788c943b494SChandan Uddaraju 			u32 pattern)
789c943b494SChandan Uddaraju {
790c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
791c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
792c943b494SChandan Uddaraju 	u32 value = 0x0;
793c943b494SChandan Uddaraju 
794c943b494SChandan Uddaraju 	/* Make sure to clear the current pattern before starting a new one */
795c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_STATE_CTRL, 0x0);
796c943b494SChandan Uddaraju 
797202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "pattern: %#x\n", pattern);
798c943b494SChandan Uddaraju 	switch (pattern) {
7998ede2eccSKuogee Hsieh 	case DP_PHY_TEST_PATTERN_D10_2:
800c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_STATE_CTRL,
801c943b494SChandan Uddaraju 				DP_STATE_CTRL_LINK_TRAINING_PATTERN1);
8028ede2eccSKuogee Hsieh 		break;
8038ede2eccSKuogee Hsieh 	case DP_PHY_TEST_PATTERN_ERROR_COUNT:
8048ede2eccSKuogee Hsieh 		value &= ~(1 << 16);
8058ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_HBR2_COMPLIANCE_SCRAMBLER_RESET,
8068ede2eccSKuogee Hsieh 					value);
8078ede2eccSKuogee Hsieh 		value |= SCRAMBLER_RESET_COUNT_VALUE;
8088ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_HBR2_COMPLIANCE_SCRAMBLER_RESET,
8098ede2eccSKuogee Hsieh 					value);
8108ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_LEVELS,
8118ede2eccSKuogee Hsieh 					DP_MAINLINK_SAFE_TO_EXIT_LEVEL_2);
8128ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_STATE_CTRL,
8138ede2eccSKuogee Hsieh 					DP_STATE_CTRL_LINK_SYMBOL_ERR_MEASURE);
8148ede2eccSKuogee Hsieh 		break;
8158ede2eccSKuogee Hsieh 	case DP_PHY_TEST_PATTERN_PRBS7:
816c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_STATE_CTRL,
817c943b494SChandan Uddaraju 				DP_STATE_CTRL_LINK_PRBS7);
8188ede2eccSKuogee Hsieh 		break;
8198ede2eccSKuogee Hsieh 	case DP_PHY_TEST_PATTERN_80BIT_CUSTOM:
820c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_STATE_CTRL,
821c943b494SChandan Uddaraju 				DP_STATE_CTRL_LINK_TEST_CUSTOM_PATTERN);
822c943b494SChandan Uddaraju 		/* 00111110000011111000001111100000 */
823c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_TEST_80BIT_CUSTOM_PATTERN_REG0,
824c943b494SChandan Uddaraju 				0x3E0F83E0);
825c943b494SChandan Uddaraju 		/* 00001111100000111110000011111000 */
826c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_TEST_80BIT_CUSTOM_PATTERN_REG1,
827c943b494SChandan Uddaraju 				0x0F83E0F8);
828c943b494SChandan Uddaraju 		/* 1111100000111110 */
829c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_TEST_80BIT_CUSTOM_PATTERN_REG2,
830c943b494SChandan Uddaraju 				0x0000F83E);
8318ede2eccSKuogee Hsieh 		break;
8328ede2eccSKuogee Hsieh 	case DP_PHY_TEST_PATTERN_CP2520:
8338ede2eccSKuogee Hsieh 		value = dp_read_link(catalog, REG_DP_MAINLINK_CTRL);
8348ede2eccSKuogee Hsieh 		value &= ~DP_MAINLINK_CTRL_SW_BYPASS_SCRAMBLER;
8358ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, value);
8368ede2eccSKuogee Hsieh 
837c943b494SChandan Uddaraju 		value = DP_HBR2_ERM_PATTERN;
838c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_HBR2_COMPLIANCE_SCRAMBLER_RESET,
839c943b494SChandan Uddaraju 				value);
840c943b494SChandan Uddaraju 		value |= SCRAMBLER_RESET_COUNT_VALUE;
841c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_HBR2_COMPLIANCE_SCRAMBLER_RESET,
842c943b494SChandan Uddaraju 					value);
843c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_MAINLINK_LEVELS,
844c943b494SChandan Uddaraju 					DP_MAINLINK_SAFE_TO_EXIT_LEVEL_2);
845c943b494SChandan Uddaraju 		dp_write_link(catalog, REG_DP_STATE_CTRL,
846c943b494SChandan Uddaraju 					DP_STATE_CTRL_LINK_SYMBOL_ERR_MEASURE);
8478ede2eccSKuogee Hsieh 		value = dp_read_link(catalog, REG_DP_MAINLINK_CTRL);
8488ede2eccSKuogee Hsieh 		value |= DP_MAINLINK_CTRL_ENABLE;
8498ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL, value);
8508ede2eccSKuogee Hsieh 		break;
8518ede2eccSKuogee Hsieh 	case DP_PHY_TEST_PATTERN_SEL_MASK:
8528ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_MAINLINK_CTRL,
8538ede2eccSKuogee Hsieh 				DP_MAINLINK_CTRL_ENABLE);
8548ede2eccSKuogee Hsieh 		dp_write_link(catalog, REG_DP_STATE_CTRL,
8558ede2eccSKuogee Hsieh 				DP_STATE_CTRL_LINK_TRAINING_PATTERN4);
8568ede2eccSKuogee Hsieh 		break;
857c943b494SChandan Uddaraju 	default:
858202aceacSKuogee Hsieh 		drm_dbg_dp(catalog->drm_dev,
859202aceacSKuogee Hsieh 				"No valid test pattern requested: %#x\n", pattern);
8608ede2eccSKuogee Hsieh 		break;
861c943b494SChandan Uddaraju 	}
862c943b494SChandan Uddaraju }
863c943b494SChandan Uddaraju 
dp_catalog_ctrl_read_phy_pattern(struct dp_catalog * dp_catalog)864c943b494SChandan Uddaraju u32 dp_catalog_ctrl_read_phy_pattern(struct dp_catalog *dp_catalog)
865c943b494SChandan Uddaraju {
866c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
867c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
868c943b494SChandan Uddaraju 
869c943b494SChandan Uddaraju 	return dp_read_link(catalog, REG_DP_MAINLINK_READY);
870c943b494SChandan Uddaraju }
871c943b494SChandan Uddaraju 
872c943b494SChandan Uddaraju /* panel related catalog functions */
dp_catalog_panel_timing_cfg(struct dp_catalog * dp_catalog)873c943b494SChandan Uddaraju int dp_catalog_panel_timing_cfg(struct dp_catalog *dp_catalog)
874c943b494SChandan Uddaraju {
875c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
876c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
877757a2f36SKuogee Hsieh 	u32 reg;
878c943b494SChandan Uddaraju 
879c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_TOTAL_HOR_VER,
880c943b494SChandan Uddaraju 				dp_catalog->total);
881c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_START_HOR_VER_FROM_SYNC,
882c943b494SChandan Uddaraju 				dp_catalog->sync_start);
883c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_HSYNC_VSYNC_WIDTH_POLARITY,
884c943b494SChandan Uddaraju 				dp_catalog->width_blanking);
885c943b494SChandan Uddaraju 	dp_write_link(catalog, REG_DP_ACTIVE_HOR_VER, dp_catalog->dp_active);
886757a2f36SKuogee Hsieh 
887757a2f36SKuogee Hsieh 	reg = dp_read_p0(catalog, MMSS_DP_INTF_CONFIG);
888757a2f36SKuogee Hsieh 
889757a2f36SKuogee Hsieh 	if (dp_catalog->wide_bus_en)
890757a2f36SKuogee Hsieh 		reg |= DP_INTF_CONFIG_DATABUS_WIDEN;
891757a2f36SKuogee Hsieh 	else
892757a2f36SKuogee Hsieh 		reg &= ~DP_INTF_CONFIG_DATABUS_WIDEN;
893757a2f36SKuogee Hsieh 
894757a2f36SKuogee Hsieh 
895757a2f36SKuogee Hsieh 	DRM_DEBUG_DP("wide_bus_en=%d reg=%#x\n", dp_catalog->wide_bus_en, reg);
896757a2f36SKuogee Hsieh 
897757a2f36SKuogee Hsieh 	dp_write_p0(catalog, MMSS_DP_INTF_CONFIG, reg);
898c943b494SChandan Uddaraju 	return 0;
899c943b494SChandan Uddaraju }
900c943b494SChandan Uddaraju 
dp_catalog_panel_tpg_enable(struct dp_catalog * dp_catalog,struct drm_display_mode * drm_mode)901c943b494SChandan Uddaraju void dp_catalog_panel_tpg_enable(struct dp_catalog *dp_catalog,
902c943b494SChandan Uddaraju 				struct drm_display_mode *drm_mode)
903c943b494SChandan Uddaraju {
904c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
905c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
906c943b494SChandan Uddaraju 	u32 hsync_period, vsync_period;
907c943b494SChandan Uddaraju 	u32 display_v_start, display_v_end;
908c943b494SChandan Uddaraju 	u32 hsync_start_x, hsync_end_x;
909c943b494SChandan Uddaraju 	u32 v_sync_width;
910c943b494SChandan Uddaraju 	u32 hsync_ctl;
911c943b494SChandan Uddaraju 	u32 display_hctl;
912c943b494SChandan Uddaraju 
913c943b494SChandan Uddaraju 	/* TPG config parameters*/
914c943b494SChandan Uddaraju 	hsync_period = drm_mode->htotal;
915c943b494SChandan Uddaraju 	vsync_period = drm_mode->vtotal;
916c943b494SChandan Uddaraju 
917c943b494SChandan Uddaraju 	display_v_start = ((drm_mode->vtotal - drm_mode->vsync_start) *
918c943b494SChandan Uddaraju 					hsync_period);
919c943b494SChandan Uddaraju 	display_v_end = ((vsync_period - (drm_mode->vsync_start -
920c943b494SChandan Uddaraju 					drm_mode->vdisplay))
921c943b494SChandan Uddaraju 					* hsync_period) - 1;
922c943b494SChandan Uddaraju 
923c943b494SChandan Uddaraju 	display_v_start += drm_mode->htotal - drm_mode->hsync_start;
924c943b494SChandan Uddaraju 	display_v_end -= (drm_mode->hsync_start - drm_mode->hdisplay);
925c943b494SChandan Uddaraju 
926c943b494SChandan Uddaraju 	hsync_start_x = drm_mode->htotal - drm_mode->hsync_start;
927c943b494SChandan Uddaraju 	hsync_end_x = hsync_period - (drm_mode->hsync_start -
928c943b494SChandan Uddaraju 					drm_mode->hdisplay) - 1;
929c943b494SChandan Uddaraju 
930c943b494SChandan Uddaraju 	v_sync_width = drm_mode->vsync_end - drm_mode->vsync_start;
931c943b494SChandan Uddaraju 
932c943b494SChandan Uddaraju 	hsync_ctl = (hsync_period << 16) |
933c943b494SChandan Uddaraju 			(drm_mode->hsync_end - drm_mode->hsync_start);
934c943b494SChandan Uddaraju 	display_hctl = (hsync_end_x << 16) | hsync_start_x;
935c943b494SChandan Uddaraju 
936c943b494SChandan Uddaraju 
937c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_CONFIG, 0x0);
938c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_HSYNC_CTL, hsync_ctl);
939c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_VSYNC_PERIOD_F0, vsync_period *
940c943b494SChandan Uddaraju 			hsync_period);
941c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_VSYNC_PULSE_WIDTH_F0, v_sync_width *
942c943b494SChandan Uddaraju 			hsync_period);
943c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_VSYNC_PERIOD_F1, 0);
944c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_VSYNC_PULSE_WIDTH_F1, 0);
945c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_DISPLAY_HCTL, display_hctl);
946c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_ACTIVE_HCTL, 0);
947c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_INTF_DISPLAY_V_START_F0, display_v_start);
948c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_DISPLAY_V_END_F0, display_v_end);
949c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_INTF_DISPLAY_V_START_F1, 0);
950c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_DISPLAY_V_END_F1, 0);
951c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_ACTIVE_V_START_F0, 0);
952c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_ACTIVE_V_END_F0, 0);
953c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_ACTIVE_V_START_F1, 0);
954c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_ACTIVE_V_END_F1, 0);
955c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_INTF_POLARITY_CTL, 0);
956c943b494SChandan Uddaraju 
957c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_TPG_MAIN_CONTROL,
958c943b494SChandan Uddaraju 				DP_TPG_CHECKERED_RECT_PATTERN);
959c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_TPG_VIDEO_CONFIG,
960c943b494SChandan Uddaraju 				DP_TPG_VIDEO_CONFIG_BPP_8BIT |
961c943b494SChandan Uddaraju 				DP_TPG_VIDEO_CONFIG_RGB);
962c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_BIST_ENABLE,
963c943b494SChandan Uddaraju 				DP_BIST_ENABLE_DPBIST_EN);
964c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_TIMING_ENGINE_EN,
965c943b494SChandan Uddaraju 				DP_TIMING_ENGINE_EN_EN);
966202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "%s: enabled tpg\n", __func__);
967c943b494SChandan Uddaraju }
968c943b494SChandan Uddaraju 
dp_catalog_panel_tpg_disable(struct dp_catalog * dp_catalog)969c943b494SChandan Uddaraju void dp_catalog_panel_tpg_disable(struct dp_catalog *dp_catalog)
970c943b494SChandan Uddaraju {
971c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog = container_of(dp_catalog,
972c943b494SChandan Uddaraju 				struct dp_catalog_private, dp_catalog);
973c943b494SChandan Uddaraju 
974c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_TPG_MAIN_CONTROL, 0x0);
975c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_BIST_ENABLE, 0x0);
976c943b494SChandan Uddaraju 	dp_write_p0(catalog, MMSS_DP_TIMING_ENGINE_EN, 0x0);
977c943b494SChandan Uddaraju }
978c943b494SChandan Uddaraju 
dp_catalog_get(struct device * dev,struct dp_io * io)979c943b494SChandan Uddaraju struct dp_catalog *dp_catalog_get(struct device *dev, struct dp_io *io)
980c943b494SChandan Uddaraju {
981c943b494SChandan Uddaraju 	struct dp_catalog_private *catalog;
982c943b494SChandan Uddaraju 
983c943b494SChandan Uddaraju 	if (!io) {
984c943b494SChandan Uddaraju 		DRM_ERROR("invalid input\n");
985c943b494SChandan Uddaraju 		return ERR_PTR(-EINVAL);
986c943b494SChandan Uddaraju 	}
987c943b494SChandan Uddaraju 
988c943b494SChandan Uddaraju 	catalog  = devm_kzalloc(dev, sizeof(*catalog), GFP_KERNEL);
989c943b494SChandan Uddaraju 	if (!catalog)
990c943b494SChandan Uddaraju 		return ERR_PTR(-ENOMEM);
991c943b494SChandan Uddaraju 
992c943b494SChandan Uddaraju 	catalog->dev = dev;
993c943b494SChandan Uddaraju 	catalog->io = io;
994c943b494SChandan Uddaraju 
995c943b494SChandan Uddaraju 	return &catalog->dp_catalog;
996c943b494SChandan Uddaraju }
997d13e36d7SAbhinav Kumar 
dp_catalog_audio_get_header(struct dp_catalog * dp_catalog)998d13e36d7SAbhinav Kumar void dp_catalog_audio_get_header(struct dp_catalog *dp_catalog)
999d13e36d7SAbhinav Kumar {
1000d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1001d13e36d7SAbhinav Kumar 	u32 (*sdp_map)[DP_AUDIO_SDP_HEADER_MAX];
1002d13e36d7SAbhinav Kumar 	enum dp_catalog_audio_sdp_type sdp;
1003d13e36d7SAbhinav Kumar 	enum dp_catalog_audio_header_type header;
1004d13e36d7SAbhinav Kumar 
1005d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1006d13e36d7SAbhinav Kumar 		return;
1007d13e36d7SAbhinav Kumar 
1008d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1009d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1010d13e36d7SAbhinav Kumar 
1011d13e36d7SAbhinav Kumar 	sdp_map = catalog->audio_map;
1012d13e36d7SAbhinav Kumar 	sdp     = dp_catalog->sdp_type;
1013d13e36d7SAbhinav Kumar 	header  = dp_catalog->sdp_header;
1014d13e36d7SAbhinav Kumar 
1015d13e36d7SAbhinav Kumar 	dp_catalog->audio_data = dp_read_link(catalog,
1016d13e36d7SAbhinav Kumar 			sdp_map[sdp][header]);
1017d13e36d7SAbhinav Kumar }
1018d13e36d7SAbhinav Kumar 
dp_catalog_audio_set_header(struct dp_catalog * dp_catalog)1019d13e36d7SAbhinav Kumar void dp_catalog_audio_set_header(struct dp_catalog *dp_catalog)
1020d13e36d7SAbhinav Kumar {
1021d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1022d13e36d7SAbhinav Kumar 	u32 (*sdp_map)[DP_AUDIO_SDP_HEADER_MAX];
1023d13e36d7SAbhinav Kumar 	enum dp_catalog_audio_sdp_type sdp;
1024d13e36d7SAbhinav Kumar 	enum dp_catalog_audio_header_type header;
1025d13e36d7SAbhinav Kumar 	u32 data;
1026d13e36d7SAbhinav Kumar 
1027d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1028d13e36d7SAbhinav Kumar 		return;
1029d13e36d7SAbhinav Kumar 
1030d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1031d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1032d13e36d7SAbhinav Kumar 
1033d13e36d7SAbhinav Kumar 	sdp_map = catalog->audio_map;
1034d13e36d7SAbhinav Kumar 	sdp     = dp_catalog->sdp_type;
1035d13e36d7SAbhinav Kumar 	header  = dp_catalog->sdp_header;
1036d13e36d7SAbhinav Kumar 	data    = dp_catalog->audio_data;
1037d13e36d7SAbhinav Kumar 
1038d13e36d7SAbhinav Kumar 	dp_write_link(catalog, sdp_map[sdp][header], data);
1039d13e36d7SAbhinav Kumar }
1040d13e36d7SAbhinav Kumar 
dp_catalog_audio_config_acr(struct dp_catalog * dp_catalog)1041d13e36d7SAbhinav Kumar void dp_catalog_audio_config_acr(struct dp_catalog *dp_catalog)
1042d13e36d7SAbhinav Kumar {
1043d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1044d13e36d7SAbhinav Kumar 	u32 acr_ctrl, select;
1045d13e36d7SAbhinav Kumar 
1046d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1047d13e36d7SAbhinav Kumar 		return;
1048d13e36d7SAbhinav Kumar 
1049d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1050d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1051d13e36d7SAbhinav Kumar 
1052d13e36d7SAbhinav Kumar 	select = dp_catalog->audio_data;
1053d13e36d7SAbhinav Kumar 	acr_ctrl = select << 4 | BIT(31) | BIT(8) | BIT(14);
1054d13e36d7SAbhinav Kumar 
1055202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "select: %#x, acr_ctrl: %#x\n",
1056202aceacSKuogee Hsieh 					select, acr_ctrl);
1057d13e36d7SAbhinav Kumar 
1058d13e36d7SAbhinav Kumar 	dp_write_link(catalog, MMSS_DP_AUDIO_ACR_CTRL, acr_ctrl);
1059d13e36d7SAbhinav Kumar }
1060d13e36d7SAbhinav Kumar 
dp_catalog_audio_enable(struct dp_catalog * dp_catalog)1061d13e36d7SAbhinav Kumar void dp_catalog_audio_enable(struct dp_catalog *dp_catalog)
1062d13e36d7SAbhinav Kumar {
1063d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1064d13e36d7SAbhinav Kumar 	bool enable;
1065d13e36d7SAbhinav Kumar 	u32 audio_ctrl;
1066d13e36d7SAbhinav Kumar 
1067d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1068d13e36d7SAbhinav Kumar 		return;
1069d13e36d7SAbhinav Kumar 
1070d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1071d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1072d13e36d7SAbhinav Kumar 
1073d13e36d7SAbhinav Kumar 	enable = !!dp_catalog->audio_data;
1074d13e36d7SAbhinav Kumar 	audio_ctrl = dp_read_link(catalog, MMSS_DP_AUDIO_CFG);
1075d13e36d7SAbhinav Kumar 
1076d13e36d7SAbhinav Kumar 	if (enable)
1077d13e36d7SAbhinav Kumar 		audio_ctrl |= BIT(0);
1078d13e36d7SAbhinav Kumar 	else
1079d13e36d7SAbhinav Kumar 		audio_ctrl &= ~BIT(0);
1080d13e36d7SAbhinav Kumar 
1081202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "dp_audio_cfg = 0x%x\n", audio_ctrl);
1082d13e36d7SAbhinav Kumar 
1083d13e36d7SAbhinav Kumar 	dp_write_link(catalog, MMSS_DP_AUDIO_CFG, audio_ctrl);
1084d13e36d7SAbhinav Kumar 	/* make sure audio engine is disabled */
1085d13e36d7SAbhinav Kumar 	wmb();
1086d13e36d7SAbhinav Kumar }
1087d13e36d7SAbhinav Kumar 
dp_catalog_audio_config_sdp(struct dp_catalog * dp_catalog)1088d13e36d7SAbhinav Kumar void dp_catalog_audio_config_sdp(struct dp_catalog *dp_catalog)
1089d13e36d7SAbhinav Kumar {
1090d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1091d13e36d7SAbhinav Kumar 	u32 sdp_cfg = 0;
1092d13e36d7SAbhinav Kumar 	u32 sdp_cfg2 = 0;
1093d13e36d7SAbhinav Kumar 
1094d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1095d13e36d7SAbhinav Kumar 		return;
1096d13e36d7SAbhinav Kumar 
1097d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1098d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1099d13e36d7SAbhinav Kumar 
1100d13e36d7SAbhinav Kumar 	sdp_cfg = dp_read_link(catalog, MMSS_DP_SDP_CFG);
1101d13e36d7SAbhinav Kumar 	/* AUDIO_TIMESTAMP_SDP_EN */
1102d13e36d7SAbhinav Kumar 	sdp_cfg |= BIT(1);
1103d13e36d7SAbhinav Kumar 	/* AUDIO_STREAM_SDP_EN */
1104d13e36d7SAbhinav Kumar 	sdp_cfg |= BIT(2);
1105d13e36d7SAbhinav Kumar 	/* AUDIO_COPY_MANAGEMENT_SDP_EN */
1106d13e36d7SAbhinav Kumar 	sdp_cfg |= BIT(5);
1107d13e36d7SAbhinav Kumar 	/* AUDIO_ISRC_SDP_EN  */
1108d13e36d7SAbhinav Kumar 	sdp_cfg |= BIT(6);
1109d13e36d7SAbhinav Kumar 	/* AUDIO_INFOFRAME_SDP_EN  */
1110d13e36d7SAbhinav Kumar 	sdp_cfg |= BIT(20);
1111d13e36d7SAbhinav Kumar 
1112202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "sdp_cfg = 0x%x\n", sdp_cfg);
1113d13e36d7SAbhinav Kumar 
1114d13e36d7SAbhinav Kumar 	dp_write_link(catalog, MMSS_DP_SDP_CFG, sdp_cfg);
1115d13e36d7SAbhinav Kumar 
1116d13e36d7SAbhinav Kumar 	sdp_cfg2 = dp_read_link(catalog, MMSS_DP_SDP_CFG2);
1117d13e36d7SAbhinav Kumar 	/* IFRM_REGSRC -> Do not use reg values */
1118d13e36d7SAbhinav Kumar 	sdp_cfg2 &= ~BIT(0);
1119d13e36d7SAbhinav Kumar 	/* AUDIO_STREAM_HB3_REGSRC-> Do not use reg values */
1120d13e36d7SAbhinav Kumar 	sdp_cfg2 &= ~BIT(1);
1121d13e36d7SAbhinav Kumar 
1122202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev, "sdp_cfg2 = 0x%x\n", sdp_cfg2);
1123d13e36d7SAbhinav Kumar 
1124d13e36d7SAbhinav Kumar 	dp_write_link(catalog, MMSS_DP_SDP_CFG2, sdp_cfg2);
1125d13e36d7SAbhinav Kumar }
1126d13e36d7SAbhinav Kumar 
dp_catalog_audio_init(struct dp_catalog * dp_catalog)1127d13e36d7SAbhinav Kumar void dp_catalog_audio_init(struct dp_catalog *dp_catalog)
1128d13e36d7SAbhinav Kumar {
1129d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1130d13e36d7SAbhinav Kumar 
1131d13e36d7SAbhinav Kumar 	static u32 sdp_map[][DP_AUDIO_SDP_HEADER_MAX] = {
1132d13e36d7SAbhinav Kumar 		{
1133d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_STREAM_0,
1134d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_STREAM_1,
1135d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_STREAM_1,
1136d13e36d7SAbhinav Kumar 		},
1137d13e36d7SAbhinav Kumar 		{
1138d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_TIMESTAMP_0,
1139d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_TIMESTAMP_1,
1140d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_TIMESTAMP_1,
1141d13e36d7SAbhinav Kumar 		},
1142d13e36d7SAbhinav Kumar 		{
1143d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_INFOFRAME_0,
1144d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_INFOFRAME_1,
1145d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_INFOFRAME_1,
1146d13e36d7SAbhinav Kumar 		},
1147d13e36d7SAbhinav Kumar 		{
1148d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_COPYMANAGEMENT_0,
1149d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_COPYMANAGEMENT_1,
1150d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_COPYMANAGEMENT_1,
1151d13e36d7SAbhinav Kumar 		},
1152d13e36d7SAbhinav Kumar 		{
1153d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_ISRC_0,
1154d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_ISRC_1,
1155d13e36d7SAbhinav Kumar 			MMSS_DP_AUDIO_ISRC_1,
1156d13e36d7SAbhinav Kumar 		},
1157d13e36d7SAbhinav Kumar 	};
1158d13e36d7SAbhinav Kumar 
1159d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1160d13e36d7SAbhinav Kumar 		return;
1161d13e36d7SAbhinav Kumar 
1162d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1163d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1164d13e36d7SAbhinav Kumar 
1165d13e36d7SAbhinav Kumar 	catalog->audio_map = sdp_map;
1166d13e36d7SAbhinav Kumar }
1167d13e36d7SAbhinav Kumar 
dp_catalog_audio_sfe_level(struct dp_catalog * dp_catalog)1168d13e36d7SAbhinav Kumar void dp_catalog_audio_sfe_level(struct dp_catalog *dp_catalog)
1169d13e36d7SAbhinav Kumar {
1170d13e36d7SAbhinav Kumar 	struct dp_catalog_private *catalog;
1171d13e36d7SAbhinav Kumar 	u32 mainlink_levels, safe_to_exit_level;
1172d13e36d7SAbhinav Kumar 
1173d13e36d7SAbhinav Kumar 	if (!dp_catalog)
1174d13e36d7SAbhinav Kumar 		return;
1175d13e36d7SAbhinav Kumar 
1176d13e36d7SAbhinav Kumar 	catalog = container_of(dp_catalog,
1177d13e36d7SAbhinav Kumar 		struct dp_catalog_private, dp_catalog);
1178d13e36d7SAbhinav Kumar 
1179d13e36d7SAbhinav Kumar 	safe_to_exit_level = dp_catalog->audio_data;
1180d13e36d7SAbhinav Kumar 	mainlink_levels = dp_read_link(catalog, REG_DP_MAINLINK_LEVELS);
1181d13e36d7SAbhinav Kumar 	mainlink_levels &= 0xFE0;
1182d13e36d7SAbhinav Kumar 	mainlink_levels |= safe_to_exit_level;
1183d13e36d7SAbhinav Kumar 
1184202aceacSKuogee Hsieh 	drm_dbg_dp(catalog->drm_dev,
1185202aceacSKuogee Hsieh 			"mainlink_level = 0x%x, safe_to_exit_level = 0x%x\n",
1186d13e36d7SAbhinav Kumar 			 mainlink_levels, safe_to_exit_level);
1187d13e36d7SAbhinav Kumar 
1188d13e36d7SAbhinav Kumar 	dp_write_link(catalog, REG_DP_MAINLINK_LEVELS, mainlink_levels);
1189d13e36d7SAbhinav Kumar }
1190