xref: /openbmc/linux/drivers/gpu/drm/tegra/rgb.c (revision 5ee9cd065836e5934710ca35653bce7905add20b)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
2dee8268fSThierry Reding /*
3dee8268fSThierry Reding  * Copyright (C) 2012 Avionic Design GmbH
4dee8268fSThierry Reding  * Copyright (C) 2012 NVIDIA CORPORATION.  All rights reserved.
5dee8268fSThierry Reding  */
6dee8268fSThierry Reding 
7dee8268fSThierry Reding #include <linux/clk.h>
8f68b63ebSThomas Zimmermann #include <linux/of.h>
9dee8268fSThierry Reding 
104aa3df71SThierry Reding #include <drm/drm_atomic_helper.h>
1129efdc29SDmitry Osipenko #include <drm/drm_bridge_connector.h>
124d0e95e0SThomas Zimmermann #include <drm/drm_simple_kms_helper.h>
133b0e5855SThierry Reding 
14dee8268fSThierry Reding #include "drm.h"
15dee8268fSThierry Reding #include "dc.h"
16dee8268fSThierry Reding 
17dee8268fSThierry Reding struct tegra_rgb {
18dee8268fSThierry Reding 	struct tegra_output output;
197602fa1dSThierry Reding 	struct tegra_dc *dc;
207602fa1dSThierry Reding 
210c921b6dSDmitry Osipenko 	struct clk *pll_d_out0;
220c921b6dSDmitry Osipenko 	struct clk *pll_d2_out0;
23dee8268fSThierry Reding 	struct clk *clk_parent;
24dee8268fSThierry Reding 	struct clk *clk;
25dee8268fSThierry Reding };
26dee8268fSThierry Reding 
to_rgb(struct tegra_output * output)27dee8268fSThierry Reding static inline struct tegra_rgb *to_rgb(struct tegra_output *output)
28dee8268fSThierry Reding {
29dee8268fSThierry Reding 	return container_of(output, struct tegra_rgb, output);
30dee8268fSThierry Reding }
31dee8268fSThierry Reding 
32dee8268fSThierry Reding struct reg_entry {
33dee8268fSThierry Reding 	unsigned long offset;
34dee8268fSThierry Reding 	unsigned long value;
35dee8268fSThierry Reding };
36dee8268fSThierry Reding 
37dee8268fSThierry Reding static const struct reg_entry rgb_enable[] = {
38dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(0),   0x00000000 },
39dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(1),   0x00000000 },
40dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(2),   0x00000000 },
41dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(3),   0x00000000 },
42dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(0), 0x00000000 },
43dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(1), 0x01000000 },
44dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(2), 0x00000000 },
45dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(3), 0x00000000 },
46dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(0),     0x00000000 },
47dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(1),     0x00000000 },
48dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(2),     0x00000000 },
49dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(3),     0x00000000 },
50dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(0),   0x00000000 },
51dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(1),   0x00000000 },
52dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(2),   0x00000000 },
53dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(3),   0x00000000 },
54dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(4),   0x00210222 },
55dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(5),   0x00002200 },
56dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(6),   0x00020000 },
57dee8268fSThierry Reding };
58dee8268fSThierry Reding 
59dee8268fSThierry Reding static const struct reg_entry rgb_disable[] = {
60dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(6),   0x00000000 },
61dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(5),   0x00000000 },
62dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(4),   0x00000000 },
63dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(3),   0x00000000 },
64dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(2),   0x00000000 },
65dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(1),   0x00000000 },
66dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_SELECT(0),   0x00000000 },
67dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(3),     0xaaaaaaaa },
68dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(2),     0xaaaaaaaa },
69dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(1),     0xaaaaaaaa },
70dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_DATA(0),     0xaaaaaaaa },
71dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(3), 0x00000000 },
72dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(2), 0x00000000 },
73dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(1), 0x00000000 },
74dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_POLARITY(0), 0x00000000 },
75dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(3),   0x55555555 },
76dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(2),   0x55555555 },
77dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(1),   0x55150005 },
78dee8268fSThierry Reding 	{ DC_COM_PIN_OUTPUT_ENABLE(0),   0x55555555 },
79dee8268fSThierry Reding };
80dee8268fSThierry Reding 
tegra_dc_write_regs(struct tegra_dc * dc,const struct reg_entry * table,unsigned int num)81dee8268fSThierry Reding static void tegra_dc_write_regs(struct tegra_dc *dc,
82dee8268fSThierry Reding 				const struct reg_entry *table,
83dee8268fSThierry Reding 				unsigned int num)
84dee8268fSThierry Reding {
85dee8268fSThierry Reding 	unsigned int i;
86dee8268fSThierry Reding 
87dee8268fSThierry Reding 	for (i = 0; i < num; i++)
88dee8268fSThierry Reding 		tegra_dc_writel(dc, table[i].value, table[i].offset);
89dee8268fSThierry Reding }
90dee8268fSThierry Reding 
tegra_rgb_encoder_disable(struct drm_encoder * encoder)9132c3dee1SThierry Reding static void tegra_rgb_encoder_disable(struct drm_encoder *encoder)
923b0e5855SThierry Reding {
9332c3dee1SThierry Reding 	struct tegra_output *output = encoder_to_output(encoder);
9432c3dee1SThierry Reding 	struct tegra_rgb *rgb = to_rgb(output);
9532c3dee1SThierry Reding 
9632c3dee1SThierry Reding 	tegra_dc_write_regs(rgb->dc, rgb_disable, ARRAY_SIZE(rgb_disable));
9732c3dee1SThierry Reding 	tegra_dc_commit(rgb->dc);
983b0e5855SThierry Reding }
993b0e5855SThierry Reding 
tegra_rgb_encoder_enable(struct drm_encoder * encoder)10032c3dee1SThierry Reding static void tegra_rgb_encoder_enable(struct drm_encoder *encoder)
1013b0e5855SThierry Reding {
1023b0e5855SThierry Reding 	struct tegra_output *output = encoder_to_output(encoder);
1033b0e5855SThierry Reding 	struct tegra_rgb *rgb = to_rgb(output);
1043b0e5855SThierry Reding 	u32 value;
1053b0e5855SThierry Reding 
1067602fa1dSThierry Reding 	tegra_dc_write_regs(rgb->dc, rgb_enable, ARRAY_SIZE(rgb_enable));
107dee8268fSThierry Reding 
10872d30286SThierry Reding 	value = DE_SELECT_ACTIVE | DE_CONTROL_NORMAL;
10972d30286SThierry Reding 	tegra_dc_writel(rgb->dc, value, DC_DISP_DATA_ENABLE_OPTIONS);
11072d30286SThierry Reding 
11172d30286SThierry Reding 	/* XXX: parameterize? */
11272d30286SThierry Reding 	value = tegra_dc_readl(rgb->dc, DC_COM_PIN_OUTPUT_POLARITY(1));
11372d30286SThierry Reding 	value &= ~LVS_OUTPUT_POLARITY_LOW;
11472d30286SThierry Reding 	value &= ~LHS_OUTPUT_POLARITY_LOW;
11572d30286SThierry Reding 	tegra_dc_writel(rgb->dc, value, DC_COM_PIN_OUTPUT_POLARITY(1));
11672d30286SThierry Reding 
11772d30286SThierry Reding 	/* XXX: parameterize? */
11872d30286SThierry Reding 	value = DISP_DATA_FORMAT_DF1P1C | DISP_ALIGNMENT_MSB |
11972d30286SThierry Reding 		DISP_ORDER_RED_BLUE;
12072d30286SThierry Reding 	tegra_dc_writel(rgb->dc, value, DC_DISP_DISP_INTERFACE_CONTROL);
12172d30286SThierry Reding 
12262b9e063SThierry Reding 	tegra_dc_commit(rgb->dc);
123dee8268fSThierry Reding }
124dee8268fSThierry Reding 
tegra_rgb_pll_rate_change_allowed(struct tegra_rgb * rgb)1250c921b6dSDmitry Osipenko static bool tegra_rgb_pll_rate_change_allowed(struct tegra_rgb *rgb)
1260c921b6dSDmitry Osipenko {
1270c921b6dSDmitry Osipenko 	if (!rgb->pll_d2_out0)
1280c921b6dSDmitry Osipenko 		return false;
1290c921b6dSDmitry Osipenko 
1300c921b6dSDmitry Osipenko 	if (!clk_is_match(rgb->clk_parent, rgb->pll_d_out0) &&
1310c921b6dSDmitry Osipenko 	    !clk_is_match(rgb->clk_parent, rgb->pll_d2_out0))
1320c921b6dSDmitry Osipenko 		return false;
1330c921b6dSDmitry Osipenko 
1340c921b6dSDmitry Osipenko 	return true;
1350c921b6dSDmitry Osipenko }
1360c921b6dSDmitry Osipenko 
1373cebae67SThierry Reding static int
tegra_rgb_encoder_atomic_check(struct drm_encoder * encoder,struct drm_crtc_state * crtc_state,struct drm_connector_state * conn_state)1383cebae67SThierry Reding tegra_rgb_encoder_atomic_check(struct drm_encoder *encoder,
1393cebae67SThierry Reding 			       struct drm_crtc_state *crtc_state,
1403cebae67SThierry Reding 			       struct drm_connector_state *conn_state)
1413cebae67SThierry Reding {
1423cebae67SThierry Reding 	struct tegra_output *output = encoder_to_output(encoder);
1433cebae67SThierry Reding 	struct tegra_dc *dc = to_tegra_dc(conn_state->crtc);
1443cebae67SThierry Reding 	unsigned long pclk = crtc_state->mode.clock * 1000;
1453cebae67SThierry Reding 	struct tegra_rgb *rgb = to_rgb(output);
1463cebae67SThierry Reding 	unsigned int div;
1473cebae67SThierry Reding 	int err;
1483cebae67SThierry Reding 
1493cebae67SThierry Reding 	/*
1503cebae67SThierry Reding 	 * We may not want to change the frequency of the parent clock, since
1513cebae67SThierry Reding 	 * it may be a parent for other peripherals. This is due to the fact
1523cebae67SThierry Reding 	 * that on Tegra20 there's only a single clock dedicated to display
1533cebae67SThierry Reding 	 * (pll_d_out0), whereas later generations have a second one that can
1543cebae67SThierry Reding 	 * be used to independently drive a second output (pll_d2_out0).
1553cebae67SThierry Reding 	 *
1563cebae67SThierry Reding 	 * As a way to support multiple outputs on Tegra20 as well, pll_p is
1573cebae67SThierry Reding 	 * typically used as the parent clock for the display controllers.
1583cebae67SThierry Reding 	 * But this comes at a cost: pll_p is the parent of several other
1593cebae67SThierry Reding 	 * peripherals, so its frequency shouldn't change out of the blue.
1603cebae67SThierry Reding 	 *
1613cebae67SThierry Reding 	 * The best we can do at this point is to use the shift clock divider
1623cebae67SThierry Reding 	 * and hope that the desired frequency can be matched (or at least
1633cebae67SThierry Reding 	 * matched sufficiently close that the panel will still work).
1643cebae67SThierry Reding 	 */
1650c921b6dSDmitry Osipenko 	if (tegra_rgb_pll_rate_change_allowed(rgb)) {
1660c921b6dSDmitry Osipenko 		/*
1670c921b6dSDmitry Osipenko 		 * Set display controller clock to x2 of PCLK in order to
1680c921b6dSDmitry Osipenko 		 * produce higher resolution pulse positions.
1690c921b6dSDmitry Osipenko 		 */
1700c921b6dSDmitry Osipenko 		div = 2;
1710c921b6dSDmitry Osipenko 		pclk *= 2;
1720c921b6dSDmitry Osipenko 	} else {
1733cebae67SThierry Reding 		div = ((clk_get_rate(rgb->clk) * 2) / pclk) - 2;
1743cebae67SThierry Reding 		pclk = 0;
1750c921b6dSDmitry Osipenko 	}
1763cebae67SThierry Reding 
1773cebae67SThierry Reding 	err = tegra_dc_state_setup_clock(dc, crtc_state, rgb->clk_parent,
1783cebae67SThierry Reding 					 pclk, div);
1793cebae67SThierry Reding 	if (err < 0) {
1803cebae67SThierry Reding 		dev_err(output->dev, "failed to setup CRTC state: %d\n", err);
1813cebae67SThierry Reding 		return err;
1823cebae67SThierry Reding 	}
1833cebae67SThierry Reding 
1843cebae67SThierry Reding 	return err;
1853cebae67SThierry Reding }
1863cebae67SThierry Reding 
1873b0e5855SThierry Reding static const struct drm_encoder_helper_funcs tegra_rgb_encoder_helper_funcs = {
1883b0e5855SThierry Reding 	.disable = tegra_rgb_encoder_disable,
18932c3dee1SThierry Reding 	.enable = tegra_rgb_encoder_enable,
1903cebae67SThierry Reding 	.atomic_check = tegra_rgb_encoder_atomic_check,
191dee8268fSThierry Reding };
192dee8268fSThierry Reding 
tegra_dc_rgb_probe(struct tegra_dc * dc)193dee8268fSThierry Reding int tegra_dc_rgb_probe(struct tegra_dc *dc)
194dee8268fSThierry Reding {
195dee8268fSThierry Reding 	struct device_node *np;
196dee8268fSThierry Reding 	struct tegra_rgb *rgb;
197dee8268fSThierry Reding 	int err;
198dee8268fSThierry Reding 
199dee8268fSThierry Reding 	np = of_get_child_by_name(dc->dev->of_node, "rgb");
200dee8268fSThierry Reding 	if (!np || !of_device_is_available(np))
201dee8268fSThierry Reding 		return -ENODEV;
202dee8268fSThierry Reding 
203dee8268fSThierry Reding 	rgb = devm_kzalloc(dc->dev, sizeof(*rgb), GFP_KERNEL);
204dee8268fSThierry Reding 	if (!rgb)
205dee8268fSThierry Reding 		return -ENOMEM;
206dee8268fSThierry Reding 
207dee8268fSThierry Reding 	rgb->output.dev = dc->dev;
208dee8268fSThierry Reding 	rgb->output.of_node = np;
2097602fa1dSThierry Reding 	rgb->dc = dc;
210dee8268fSThierry Reding 
21159d29c0eSThierry Reding 	err = tegra_output_probe(&rgb->output);
212dee8268fSThierry Reding 	if (err < 0)
213dee8268fSThierry Reding 		return err;
214dee8268fSThierry Reding 
215dee8268fSThierry Reding 	rgb->clk = devm_clk_get(dc->dev, NULL);
216dee8268fSThierry Reding 	if (IS_ERR(rgb->clk)) {
217dee8268fSThierry Reding 		dev_err(dc->dev, "failed to get clock\n");
21820a176aeSChristophe JAILLET 		err = PTR_ERR(rgb->clk);
21920a176aeSChristophe JAILLET 		goto remove;
220dee8268fSThierry Reding 	}
221dee8268fSThierry Reding 
222dee8268fSThierry Reding 	rgb->clk_parent = devm_clk_get(dc->dev, "parent");
223dee8268fSThierry Reding 	if (IS_ERR(rgb->clk_parent)) {
224dee8268fSThierry Reding 		dev_err(dc->dev, "failed to get parent clock\n");
22520a176aeSChristophe JAILLET 		err = PTR_ERR(rgb->clk_parent);
22620a176aeSChristophe JAILLET 		goto remove;
227dee8268fSThierry Reding 	}
228dee8268fSThierry Reding 
229dee8268fSThierry Reding 	err = clk_set_parent(rgb->clk, rgb->clk_parent);
230dee8268fSThierry Reding 	if (err < 0) {
231dee8268fSThierry Reding 		dev_err(dc->dev, "failed to set parent clock: %d\n", err);
23220a176aeSChristophe JAILLET 		goto remove;
233dee8268fSThierry Reding 	}
234dee8268fSThierry Reding 
2350c921b6dSDmitry Osipenko 	rgb->pll_d_out0 = clk_get_sys(NULL, "pll_d_out0");
2360c921b6dSDmitry Osipenko 	if (IS_ERR(rgb->pll_d_out0)) {
2370c921b6dSDmitry Osipenko 		err = PTR_ERR(rgb->pll_d_out0);
2380c921b6dSDmitry Osipenko 		dev_err(dc->dev, "failed to get pll_d_out0: %d\n", err);
23920a176aeSChristophe JAILLET 		goto remove;
2400c921b6dSDmitry Osipenko 	}
2410c921b6dSDmitry Osipenko 
2420c921b6dSDmitry Osipenko 	if (dc->soc->has_pll_d2_out0) {
2430c921b6dSDmitry Osipenko 		rgb->pll_d2_out0 = clk_get_sys(NULL, "pll_d2_out0");
2440c921b6dSDmitry Osipenko 		if (IS_ERR(rgb->pll_d2_out0)) {
2450c921b6dSDmitry Osipenko 			err = PTR_ERR(rgb->pll_d2_out0);
2460c921b6dSDmitry Osipenko 			dev_err(dc->dev, "failed to get pll_d2_out0: %d\n", err);
247*845322a9SChristophe JAILLET 			goto put_pll;
2480c921b6dSDmitry Osipenko 		}
2490c921b6dSDmitry Osipenko 	}
2500c921b6dSDmitry Osipenko 
251dee8268fSThierry Reding 	dc->rgb = &rgb->output;
252dee8268fSThierry Reding 
253dee8268fSThierry Reding 	return 0;
25420a176aeSChristophe JAILLET 
255*845322a9SChristophe JAILLET put_pll:
256*845322a9SChristophe JAILLET 	clk_put(rgb->pll_d_out0);
25720a176aeSChristophe JAILLET remove:
25820a176aeSChristophe JAILLET 	tegra_output_remove(&rgb->output);
25920a176aeSChristophe JAILLET 	return err;
260dee8268fSThierry Reding }
261dee8268fSThierry Reding 
tegra_dc_rgb_remove(struct tegra_dc * dc)26243740540SUwe Kleine-König void tegra_dc_rgb_remove(struct tegra_dc *dc)
26359d29c0eSThierry Reding {
2640c921b6dSDmitry Osipenko 	struct tegra_rgb *rgb;
2650c921b6dSDmitry Osipenko 
26659d29c0eSThierry Reding 	if (!dc->rgb)
26743740540SUwe Kleine-König 		return;
26859d29c0eSThierry Reding 
2690c921b6dSDmitry Osipenko 	rgb = to_rgb(dc->rgb);
2700c921b6dSDmitry Osipenko 	clk_put(rgb->pll_d2_out0);
2710c921b6dSDmitry Osipenko 	clk_put(rgb->pll_d_out0);
2720c921b6dSDmitry Osipenko 
273328ec69eSThierry Reding 	tegra_output_remove(dc->rgb);
2743b0e5855SThierry Reding 	dc->rgb = NULL;
27559d29c0eSThierry Reding }
27659d29c0eSThierry Reding 
tegra_dc_rgb_init(struct drm_device * drm,struct tegra_dc * dc)277dee8268fSThierry Reding int tegra_dc_rgb_init(struct drm_device *drm, struct tegra_dc *dc)
278dee8268fSThierry Reding {
2793b0e5855SThierry Reding 	struct tegra_output *output = dc->rgb;
28029efdc29SDmitry Osipenko 	struct drm_connector *connector;
281dee8268fSThierry Reding 	int err;
282dee8268fSThierry Reding 
283dee8268fSThierry Reding 	if (!dc->rgb)
284dee8268fSThierry Reding 		return -ENODEV;
285dee8268fSThierry Reding 
28629efdc29SDmitry Osipenko 	drm_simple_encoder_init(drm, &output->encoder, DRM_MODE_ENCODER_LVDS);
28729efdc29SDmitry Osipenko 	drm_encoder_helper_add(&output->encoder,
28829efdc29SDmitry Osipenko 			       &tegra_rgb_encoder_helper_funcs);
28929efdc29SDmitry Osipenko 
29029efdc29SDmitry Osipenko 	/*
291d9f980ebSDmitry Osipenko 	 * Wrap directly-connected panel into DRM bridge in order to let
292d9f980ebSDmitry Osipenko 	 * DRM core to handle panel for us.
293d9f980ebSDmitry Osipenko 	 */
294d9f980ebSDmitry Osipenko 	if (output->panel) {
295d9f980ebSDmitry Osipenko 		output->bridge = devm_drm_panel_bridge_add(output->dev,
296d9f980ebSDmitry Osipenko 							   output->panel);
297d9f980ebSDmitry Osipenko 		if (IS_ERR(output->bridge)) {
298d9f980ebSDmitry Osipenko 			dev_err(output->dev,
299d9f980ebSDmitry Osipenko 				"failed to wrap panel into bridge: %pe\n",
300d9f980ebSDmitry Osipenko 				output->bridge);
301d9f980ebSDmitry Osipenko 			return PTR_ERR(output->bridge);
302d9f980ebSDmitry Osipenko 		}
303d9f980ebSDmitry Osipenko 
304d9f980ebSDmitry Osipenko 		output->panel = NULL;
305d9f980ebSDmitry Osipenko 	}
306d9f980ebSDmitry Osipenko 
307d9f980ebSDmitry Osipenko 	/*
30829efdc29SDmitry Osipenko 	 * Tegra devices that have LVDS panel utilize LVDS encoder bridge
30929efdc29SDmitry Osipenko 	 * for converting up to 28 LCD LVTTL lanes into 5/4 LVDS lanes that
31029efdc29SDmitry Osipenko 	 * go to display panel's receiver.
31129efdc29SDmitry Osipenko 	 *
31229efdc29SDmitry Osipenko 	 * Encoder usually have a power-down control which needs to be enabled
31329efdc29SDmitry Osipenko 	 * in order to transmit data to the panel.  Historically devices that
31429efdc29SDmitry Osipenko 	 * use an older device-tree version didn't model the bridge, assuming
31529efdc29SDmitry Osipenko 	 * that encoder is turned ON by default, while today's DRM allows us
31629efdc29SDmitry Osipenko 	 * to model LVDS encoder properly.
31729efdc29SDmitry Osipenko 	 *
31829efdc29SDmitry Osipenko 	 * Newer device-trees utilize LVDS encoder bridge, which provides
31929efdc29SDmitry Osipenko 	 * us with a connector and handles the display panel.
32029efdc29SDmitry Osipenko 	 *
321d9f980ebSDmitry Osipenko 	 * For older device-trees we wrapped panel into the panel-bridge.
32229efdc29SDmitry Osipenko 	 */
32329efdc29SDmitry Osipenko 	if (output->bridge) {
32429efdc29SDmitry Osipenko 		err = drm_bridge_attach(&output->encoder, output->bridge,
32529efdc29SDmitry Osipenko 					NULL, DRM_BRIDGE_ATTACH_NO_CONNECTOR);
326fb8d617fSLaurent Pinchart 		if (err)
32729efdc29SDmitry Osipenko 			return err;
32829efdc29SDmitry Osipenko 
32929efdc29SDmitry Osipenko 		connector = drm_bridge_connector_init(drm, &output->encoder);
33029efdc29SDmitry Osipenko 		if (IS_ERR(connector)) {
33129efdc29SDmitry Osipenko 			dev_err(output->dev,
33229efdc29SDmitry Osipenko 				"failed to initialize bridge connector: %pe\n",
33329efdc29SDmitry Osipenko 				connector);
33429efdc29SDmitry Osipenko 			return PTR_ERR(connector);
33529efdc29SDmitry Osipenko 		}
33629efdc29SDmitry Osipenko 
33729efdc29SDmitry Osipenko 		drm_connector_attach_encoder(connector, &output->encoder);
33829efdc29SDmitry Osipenko 	}
3393b0e5855SThierry Reding 
340ea130b24SThierry Reding 	err = tegra_output_init(drm, output);
341ea130b24SThierry Reding 	if (err < 0) {
342ea130b24SThierry Reding 		dev_err(output->dev, "failed to initialize output: %d\n", err);
343ea130b24SThierry Reding 		return err;
344ea130b24SThierry Reding 	}
345ea130b24SThierry Reding 
346dee8268fSThierry Reding 	/*
3473b0e5855SThierry Reding 	 * Other outputs can be attached to either display controller. The RGB
3483b0e5855SThierry Reding 	 * outputs are an exception and work only with their parent display
3493b0e5855SThierry Reding 	 * controller.
350dee8268fSThierry Reding 	 */
3513b0e5855SThierry Reding 	output->encoder.possible_crtcs = drm_crtc_mask(&dc->base);
352dee8268fSThierry Reding 
353dee8268fSThierry Reding 	return 0;
354dee8268fSThierry Reding }
355dee8268fSThierry Reding 
tegra_dc_rgb_exit(struct tegra_dc * dc)356dee8268fSThierry Reding int tegra_dc_rgb_exit(struct tegra_dc *dc)
357dee8268fSThierry Reding {
358328ec69eSThierry Reding 	if (dc->rgb)
359328ec69eSThierry Reding 		tegra_output_exit(dc->rgb);
3603b0e5855SThierry Reding 
361328ec69eSThierry Reding 	return 0;
362dee8268fSThierry Reding }
363