12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
29026e0d1SMaxime Ripard /*
39026e0d1SMaxime Ripard * Copyright (C) 2015 Free Electrons
49026e0d1SMaxime Ripard * Copyright (C) 2015 NextThing Co
59026e0d1SMaxime Ripard *
69026e0d1SMaxime Ripard * Maxime Ripard <maxime.ripard@free-electrons.com>
79026e0d1SMaxime Ripard */
89026e0d1SMaxime Ripard
99c25a297SSam Ravnborg #include <linux/component.h>
109c25a297SSam Ravnborg #include <linux/ioport.h>
1172bd9ea3SVille Syrjälä #include <linux/media-bus-format.h>
129c25a297SSam Ravnborg #include <linux/module.h>
13*722d4f06SRob Herring #include <linux/of.h>
14*722d4f06SRob Herring #include <linux/of_platform.h>
15*722d4f06SRob Herring #include <linux/platform_device.h>
169c25a297SSam Ravnborg #include <linux/regmap.h>
179c25a297SSam Ravnborg #include <linux/reset.h>
189c25a297SSam Ravnborg
199026e0d1SMaxime Ripard #include <drm/drm_atomic_helper.h>
20ee68c743SBoris Brezillon #include <drm/drm_bridge.h>
21f11adcecSJonathan Liu #include <drm/drm_connector.h>
229026e0d1SMaxime Ripard #include <drm/drm_crtc.h>
23ad537fb2SChen-Yu Tsai #include <drm/drm_encoder.h>
249026e0d1SMaxime Ripard #include <drm/drm_modes.h>
25ebc94461SRob Herring #include <drm/drm_of.h>
26490cda5aSGiulio Benetti #include <drm/drm_panel.h>
279c25a297SSam Ravnborg #include <drm/drm_print.h>
28fcd70cd3SDaniel Vetter #include <drm/drm_probe_helper.h>
299c25a297SSam Ravnborg #include <drm/drm_vblank.h>
309026e0d1SMaxime Ripard
31ad537fb2SChen-Yu Tsai #include <uapi/drm/drm_mode.h>
32ad537fb2SChen-Yu Tsai
339026e0d1SMaxime Ripard #include "sun4i_crtc.h"
349026e0d1SMaxime Ripard #include "sun4i_drv.h"
35a0c1214eSMaxime Ripard #include "sun4i_lvds.h"
3629e57fabSMaxime Ripard #include "sun4i_rgb.h"
379026e0d1SMaxime Ripard #include "sun4i_tcon.h"
38a08fc7c8SMaxime Ripard #include "sun6i_mipi_dsi.h"
3971ffeafbSRoman Beranek #include "sun4i_tcon_dclk.h"
40cf77d79bSJernej Skrabec #include "sun8i_tcon_top.h"
4187969338SIcenowy Zheng #include "sunxi_engine.h"
429026e0d1SMaxime Ripard
sun4i_tcon_get_connector(const struct drm_encoder * encoder)43a0c1214eSMaxime Ripard static struct drm_connector *sun4i_tcon_get_connector(const struct drm_encoder *encoder)
44a0c1214eSMaxime Ripard {
45a0c1214eSMaxime Ripard struct drm_connector *connector;
46a0c1214eSMaxime Ripard struct drm_connector_list_iter iter;
47a0c1214eSMaxime Ripard
48a0c1214eSMaxime Ripard drm_connector_list_iter_begin(encoder->dev, &iter);
49a0c1214eSMaxime Ripard drm_for_each_connector_iter(connector, &iter)
50a0c1214eSMaxime Ripard if (connector->encoder == encoder) {
51a0c1214eSMaxime Ripard drm_connector_list_iter_end(&iter);
52a0c1214eSMaxime Ripard return connector;
53a0c1214eSMaxime Ripard }
54a0c1214eSMaxime Ripard drm_connector_list_iter_end(&iter);
55a0c1214eSMaxime Ripard
56a0c1214eSMaxime Ripard return NULL;
57a0c1214eSMaxime Ripard }
58a0c1214eSMaxime Ripard
sun4i_tcon_get_pixel_depth(const struct drm_encoder * encoder)59a0c1214eSMaxime Ripard static int sun4i_tcon_get_pixel_depth(const struct drm_encoder *encoder)
60a0c1214eSMaxime Ripard {
61a0c1214eSMaxime Ripard struct drm_connector *connector;
62a0c1214eSMaxime Ripard struct drm_display_info *info;
63a0c1214eSMaxime Ripard
64a0c1214eSMaxime Ripard connector = sun4i_tcon_get_connector(encoder);
65a0c1214eSMaxime Ripard if (!connector)
66a0c1214eSMaxime Ripard return -EINVAL;
67a0c1214eSMaxime Ripard
68a0c1214eSMaxime Ripard info = &connector->display_info;
69a0c1214eSMaxime Ripard if (info->num_bus_formats != 1)
70a0c1214eSMaxime Ripard return -EINVAL;
71a0c1214eSMaxime Ripard
72a0c1214eSMaxime Ripard switch (info->bus_formats[0]) {
73a0c1214eSMaxime Ripard case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
74a0c1214eSMaxime Ripard return 18;
75a0c1214eSMaxime Ripard
76a0c1214eSMaxime Ripard case MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA:
77a0c1214eSMaxime Ripard case MEDIA_BUS_FMT_RGB888_1X7X4_SPWG:
78a0c1214eSMaxime Ripard return 24;
79a0c1214eSMaxime Ripard }
80a0c1214eSMaxime Ripard
81a0c1214eSMaxime Ripard return -EINVAL;
82a0c1214eSMaxime Ripard }
83a0c1214eSMaxime Ripard
sun4i_tcon_channel_set_status(struct sun4i_tcon * tcon,int channel,bool enabled)8445e88f99SMaxime Ripard static void sun4i_tcon_channel_set_status(struct sun4i_tcon *tcon, int channel,
8545e88f99SMaxime Ripard bool enabled)
869026e0d1SMaxime Ripard {
8745e88f99SMaxime Ripard struct clk *clk;
889026e0d1SMaxime Ripard
8945e88f99SMaxime Ripard switch (channel) {
9045e88f99SMaxime Ripard case 0:
9134d698f6SJernej Skrabec WARN_ON(!tcon->quirks->has_channel_0);
929026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
939026e0d1SMaxime Ripard SUN4I_TCON0_CTL_TCON_ENABLE,
9445e88f99SMaxime Ripard enabled ? SUN4I_TCON0_CTL_TCON_ENABLE : 0);
9545e88f99SMaxime Ripard clk = tcon->dclk;
9645e88f99SMaxime Ripard break;
9745e88f99SMaxime Ripard case 1:
9891ea2f29SChen-Yu Tsai WARN_ON(!tcon->quirks->has_channel_1);
999026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
1009026e0d1SMaxime Ripard SUN4I_TCON1_CTL_TCON_ENABLE,
10145e88f99SMaxime Ripard enabled ? SUN4I_TCON1_CTL_TCON_ENABLE : 0);
10245e88f99SMaxime Ripard clk = tcon->sclk1;
10345e88f99SMaxime Ripard break;
10445e88f99SMaxime Ripard default:
10545e88f99SMaxime Ripard DRM_WARN("Unknown channel... doing nothing\n");
10645e88f99SMaxime Ripard return;
1079026e0d1SMaxime Ripard }
10845e88f99SMaxime Ripard
109f3e5feebSJernej Skrabec if (enabled) {
11045e88f99SMaxime Ripard clk_prepare_enable(clk);
1117035046dSOndrej Jirman clk_rate_exclusive_get(clk);
112f3e5feebSJernej Skrabec } else {
113f3e5feebSJernej Skrabec clk_rate_exclusive_put(clk);
11445e88f99SMaxime Ripard clk_disable_unprepare(clk);
11545e88f99SMaxime Ripard }
116f3e5feebSJernej Skrabec }
11745e88f99SMaxime Ripard
sun4i_tcon_setup_lvds_phy(struct sun4i_tcon * tcon,const struct drm_encoder * encoder)118d718e53aSAndrey Lebedev static void sun4i_tcon_setup_lvds_phy(struct sun4i_tcon *tcon,
119d718e53aSAndrey Lebedev const struct drm_encoder *encoder)
120d718e53aSAndrey Lebedev {
121d718e53aSAndrey Lebedev regmap_write(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG,
122d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_CK_EN |
123d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_REG_V |
124d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_REG_C |
125d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_EN_MB |
126d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_PD |
127d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_DCHS);
128d718e53aSAndrey Lebedev
129d718e53aSAndrey Lebedev udelay(2); /* delay at least 1200 ns */
130d718e53aSAndrey Lebedev regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA1_REG,
131d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA1_INIT,
132d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA1_INIT);
133d718e53aSAndrey Lebedev udelay(1); /* delay at least 120 ns */
134d718e53aSAndrey Lebedev regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA1_REG,
135d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA1_UPDATE,
136d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA1_UPDATE);
137d718e53aSAndrey Lebedev regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG,
138d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_EN_MB,
139d718e53aSAndrey Lebedev SUN4I_TCON0_LVDS_ANA0_EN_MB);
140d718e53aSAndrey Lebedev }
141d718e53aSAndrey Lebedev
sun6i_tcon_setup_lvds_phy(struct sun4i_tcon * tcon,const struct drm_encoder * encoder)1425627c9d8SAndrey Lebedev static void sun6i_tcon_setup_lvds_phy(struct sun4i_tcon *tcon,
1435627c9d8SAndrey Lebedev const struct drm_encoder *encoder)
144a0c1214eSMaxime Ripard {
145a0c1214eSMaxime Ripard u8 val;
146a0c1214eSMaxime Ripard
147a0c1214eSMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG,
148a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_C(2) |
149a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_V(3) |
150a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_PD(2) |
151a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_LDO);
152a0c1214eSMaxime Ripard udelay(2);
153a0c1214eSMaxime Ripard
154a0c1214eSMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG,
155a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_MB,
156a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_MB);
157a0c1214eSMaxime Ripard udelay(2);
158a0c1214eSMaxime Ripard
159a0c1214eSMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG,
160a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_DRVC,
161a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_DRVC);
162a0c1214eSMaxime Ripard
163a0c1214eSMaxime Ripard if (sun4i_tcon_get_pixel_depth(encoder) == 18)
164a0c1214eSMaxime Ripard val = 7;
165a0c1214eSMaxime Ripard else
166a0c1214eSMaxime Ripard val = 0xf;
167a0c1214eSMaxime Ripard
168a0c1214eSMaxime Ripard regmap_write_bits(tcon->regs, SUN4I_TCON0_LVDS_ANA0_REG,
169a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_DRVD(0xf),
170a0c1214eSMaxime Ripard SUN6I_TCON0_LVDS_ANA0_EN_DRVD(val));
1715627c9d8SAndrey Lebedev }
1725627c9d8SAndrey Lebedev
sun4i_tcon_lvds_set_status(struct sun4i_tcon * tcon,const struct drm_encoder * encoder,bool enabled)1735627c9d8SAndrey Lebedev static void sun4i_tcon_lvds_set_status(struct sun4i_tcon *tcon,
1745627c9d8SAndrey Lebedev const struct drm_encoder *encoder,
1755627c9d8SAndrey Lebedev bool enabled)
1765627c9d8SAndrey Lebedev {
1775627c9d8SAndrey Lebedev if (enabled) {
1785627c9d8SAndrey Lebedev regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_IF_REG,
1795627c9d8SAndrey Lebedev SUN4I_TCON0_LVDS_IF_EN,
1805627c9d8SAndrey Lebedev SUN4I_TCON0_LVDS_IF_EN);
1815627c9d8SAndrey Lebedev if (tcon->quirks->setup_lvds_phy)
1825627c9d8SAndrey Lebedev tcon->quirks->setup_lvds_phy(tcon, encoder);
183a0c1214eSMaxime Ripard } else {
184a0c1214eSMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_LVDS_IF_REG,
185a0c1214eSMaxime Ripard SUN4I_TCON0_LVDS_IF_EN, 0);
186a0c1214eSMaxime Ripard }
187a0c1214eSMaxime Ripard }
188a0c1214eSMaxime Ripard
sun4i_tcon_set_status(struct sun4i_tcon * tcon,const struct drm_encoder * encoder,bool enabled)18945e88f99SMaxime Ripard void sun4i_tcon_set_status(struct sun4i_tcon *tcon,
19045e88f99SMaxime Ripard const struct drm_encoder *encoder,
19145e88f99SMaxime Ripard bool enabled)
19245e88f99SMaxime Ripard {
193a0c1214eSMaxime Ripard bool is_lvds = false;
19445e88f99SMaxime Ripard int channel;
19545e88f99SMaxime Ripard
19645e88f99SMaxime Ripard switch (encoder->encoder_type) {
197a0c1214eSMaxime Ripard case DRM_MODE_ENCODER_LVDS:
198a0c1214eSMaxime Ripard is_lvds = true;
199df561f66SGustavo A. R. Silva fallthrough;
200a08fc7c8SMaxime Ripard case DRM_MODE_ENCODER_DSI:
20145e88f99SMaxime Ripard case DRM_MODE_ENCODER_NONE:
20245e88f99SMaxime Ripard channel = 0;
20345e88f99SMaxime Ripard break;
20445e88f99SMaxime Ripard case DRM_MODE_ENCODER_TMDS:
20545e88f99SMaxime Ripard case DRM_MODE_ENCODER_TVDAC:
20645e88f99SMaxime Ripard channel = 1;
20745e88f99SMaxime Ripard break;
20845e88f99SMaxime Ripard default:
20945e88f99SMaxime Ripard DRM_DEBUG_DRIVER("Unknown encoder type, doing nothing...\n");
21045e88f99SMaxime Ripard return;
21145e88f99SMaxime Ripard }
21245e88f99SMaxime Ripard
213a0c1214eSMaxime Ripard if (is_lvds && !enabled)
214a0c1214eSMaxime Ripard sun4i_tcon_lvds_set_status(tcon, encoder, false);
215a0c1214eSMaxime Ripard
21645e88f99SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
21745e88f99SMaxime Ripard SUN4I_TCON_GCTL_TCON_ENABLE,
21845e88f99SMaxime Ripard enabled ? SUN4I_TCON_GCTL_TCON_ENABLE : 0);
21945e88f99SMaxime Ripard
220a0c1214eSMaxime Ripard if (is_lvds && enabled)
221a0c1214eSMaxime Ripard sun4i_tcon_lvds_set_status(tcon, encoder, true);
222a0c1214eSMaxime Ripard
22345e88f99SMaxime Ripard sun4i_tcon_channel_set_status(tcon, channel, enabled);
22445e88f99SMaxime Ripard }
2259026e0d1SMaxime Ripard
sun4i_tcon_enable_vblank(struct sun4i_tcon * tcon,bool enable)2269026e0d1SMaxime Ripard void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable)
2279026e0d1SMaxime Ripard {
2289026e0d1SMaxime Ripard u32 mask, val = 0;
2299026e0d1SMaxime Ripard
2309026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("%sabling VBLANK interrupt\n", enable ? "En" : "Dis");
2319026e0d1SMaxime Ripard
2329026e0d1SMaxime Ripard mask = SUN4I_TCON_GINT0_VBLANK_ENABLE(0) |
233a493ceaeSMaxime Ripard SUN4I_TCON_GINT0_VBLANK_ENABLE(1) |
234a493ceaeSMaxime Ripard SUN4I_TCON_GINT0_TCON0_TRI_FINISH_ENABLE;
2359026e0d1SMaxime Ripard
2369026e0d1SMaxime Ripard if (enable)
2379026e0d1SMaxime Ripard val = mask;
2389026e0d1SMaxime Ripard
2399026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val);
2409026e0d1SMaxime Ripard }
2419026e0d1SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_enable_vblank);
2429026e0d1SMaxime Ripard
24367e32645SChen-Yu Tsai /*
24467e32645SChen-Yu Tsai * This function is a helper for TCON output muxing. The TCON output
24567e32645SChen-Yu Tsai * muxing control register in earlier SoCs (without the TCON TOP block)
24667e32645SChen-Yu Tsai * are located in TCON0. This helper returns a pointer to TCON0's
24767e32645SChen-Yu Tsai * sun4i_tcon structure, or NULL if not found.
24867e32645SChen-Yu Tsai */
sun4i_get_tcon0(struct drm_device * drm)24967e32645SChen-Yu Tsai static struct sun4i_tcon *sun4i_get_tcon0(struct drm_device *drm)
25067e32645SChen-Yu Tsai {
25167e32645SChen-Yu Tsai struct sun4i_drv *drv = drm->dev_private;
25267e32645SChen-Yu Tsai struct sun4i_tcon *tcon;
25367e32645SChen-Yu Tsai
25467e32645SChen-Yu Tsai list_for_each_entry(tcon, &drv->tcon_list, list)
25567e32645SChen-Yu Tsai if (tcon->id == 0)
25667e32645SChen-Yu Tsai return tcon;
25767e32645SChen-Yu Tsai
25867e32645SChen-Yu Tsai dev_warn(drm->dev,
25967e32645SChen-Yu Tsai "TCON0 not found, display output muxing may not work\n");
26067e32645SChen-Yu Tsai
26167e32645SChen-Yu Tsai return NULL;
26267e32645SChen-Yu Tsai }
26367e32645SChen-Yu Tsai
sun4i_tcon_set_mux(struct sun4i_tcon * tcon,int channel,const struct drm_encoder * encoder)2641f2f0599SYueHaibing static void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel,
265abcb8766SMaxime Ripard const struct drm_encoder *encoder)
266f8c73f4fSMaxime Ripard {
267ad537fb2SChen-Yu Tsai int ret = -ENOTSUPP;
268b7cb9b91SMaxime Ripard
269ad537fb2SChen-Yu Tsai if (tcon->quirks->set_mux)
270ad537fb2SChen-Yu Tsai ret = tcon->quirks->set_mux(tcon, encoder);
271f8c73f4fSMaxime Ripard
272ad537fb2SChen-Yu Tsai DRM_DEBUG_DRIVER("Muxing encoder %s to CRTC %s: %d\n",
273ad537fb2SChen-Yu Tsai encoder->name, encoder->crtc->name, ret);
274f8c73f4fSMaxime Ripard }
275f8c73f4fSMaxime Ripard
sun4i_tcon_get_clk_delay(const struct drm_display_mode * mode,int channel)276961c645cSMaxime Ripard static int sun4i_tcon_get_clk_delay(const struct drm_display_mode *mode,
2779026e0d1SMaxime Ripard int channel)
2789026e0d1SMaxime Ripard {
2799026e0d1SMaxime Ripard int delay = mode->vtotal - mode->vdisplay;
2809026e0d1SMaxime Ripard
2819026e0d1SMaxime Ripard if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2829026e0d1SMaxime Ripard delay /= 2;
2839026e0d1SMaxime Ripard
2849026e0d1SMaxime Ripard if (channel == 1)
2859026e0d1SMaxime Ripard delay -= 2;
2869026e0d1SMaxime Ripard
2879026e0d1SMaxime Ripard delay = min(delay, 30);
2889026e0d1SMaxime Ripard
2899026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay);
2909026e0d1SMaxime Ripard
2919026e0d1SMaxime Ripard return delay;
2929026e0d1SMaxime Ripard }
2939026e0d1SMaxime Ripard
sun4i_tcon0_mode_set_dithering(struct sun4i_tcon * tcon,const struct drm_connector * connector)294f11adcecSJonathan Liu static void sun4i_tcon0_mode_set_dithering(struct sun4i_tcon *tcon,
295f11adcecSJonathan Liu const struct drm_connector *connector)
296f11adcecSJonathan Liu {
297f11adcecSJonathan Liu u32 bus_format = 0;
298f11adcecSJonathan Liu u32 val = 0;
299f11adcecSJonathan Liu
300f11adcecSJonathan Liu /* XXX Would this ever happen? */
301f11adcecSJonathan Liu if (!connector)
302f11adcecSJonathan Liu return;
303f11adcecSJonathan Liu
304f11adcecSJonathan Liu /*
305f11adcecSJonathan Liu * FIXME: Undocumented bits
306f11adcecSJonathan Liu *
307f11adcecSJonathan Liu * The whole dithering process and these parameters are not
308f11adcecSJonathan Liu * explained in the vendor documents or BSP kernel code.
309f11adcecSJonathan Liu */
310f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PR_REG, 0x11111111);
311f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PG_REG, 0x11111111);
312f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_PB_REG, 0x11111111);
313f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LR_REG, 0x11111111);
314f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LG_REG, 0x11111111);
315f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_SEED_LB_REG, 0x11111111);
316f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL0_REG, 0x01010000);
317f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL1_REG, 0x15151111);
318f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL2_REG, 0x57575555);
319f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON0_FRM_TBL3_REG, 0x7f7f7777);
320f11adcecSJonathan Liu
321f11adcecSJonathan Liu /* Do dithering if panel only supports 6 bits per color */
322f11adcecSJonathan Liu if (connector->display_info.bpc == 6)
323f11adcecSJonathan Liu val |= SUN4I_TCON0_FRM_CTL_EN;
324f11adcecSJonathan Liu
325f11adcecSJonathan Liu if (connector->display_info.num_bus_formats == 1)
326f11adcecSJonathan Liu bus_format = connector->display_info.bus_formats[0];
327f11adcecSJonathan Liu
328f11adcecSJonathan Liu /* Check the connection format */
329f11adcecSJonathan Liu switch (bus_format) {
330f11adcecSJonathan Liu case MEDIA_BUS_FMT_RGB565_1X16:
331f11adcecSJonathan Liu /* R and B components are only 5 bits deep */
332f11adcecSJonathan Liu val |= SUN4I_TCON0_FRM_CTL_MODE_R;
333f11adcecSJonathan Liu val |= SUN4I_TCON0_FRM_CTL_MODE_B;
334df561f66SGustavo A. R. Silva fallthrough;
335f11adcecSJonathan Liu case MEDIA_BUS_FMT_RGB666_1X18:
336f11adcecSJonathan Liu case MEDIA_BUS_FMT_RGB666_1X7X3_SPWG:
337f11adcecSJonathan Liu /* Fall through: enable dithering */
338f11adcecSJonathan Liu val |= SUN4I_TCON0_FRM_CTL_EN;
339f11adcecSJonathan Liu break;
340f11adcecSJonathan Liu }
341f11adcecSJonathan Liu
342f11adcecSJonathan Liu /* Write dithering settings */
343f11adcecSJonathan Liu regmap_write(tcon->regs, SUN4I_TCON_FRM_CTL_REG, val);
344f11adcecSJonathan Liu }
345f11adcecSJonathan Liu
sun4i_tcon0_mode_set_cpu(struct sun4i_tcon * tcon,const struct drm_encoder * encoder,const struct drm_display_mode * mode)346a08fc7c8SMaxime Ripard static void sun4i_tcon0_mode_set_cpu(struct sun4i_tcon *tcon,
34779891d56SChen-Yu Tsai const struct drm_encoder *encoder,
348a08fc7c8SMaxime Ripard const struct drm_display_mode *mode)
349a08fc7c8SMaxime Ripard {
35079891d56SChen-Yu Tsai /* TODO support normal CPU interface modes */
35179891d56SChen-Yu Tsai struct sun6i_dsi *dsi = encoder_to_sun6i_dsi(encoder);
35279891d56SChen-Yu Tsai struct mipi_dsi_device *device = dsi->device;
353a08fc7c8SMaxime Ripard u8 bpp = mipi_dsi_pixel_format_to_bpp(device->format);
354a08fc7c8SMaxime Ripard u8 lanes = device->lanes;
355a08fc7c8SMaxime Ripard u32 block_space, start_delay;
356a08fc7c8SMaxime Ripard u32 tcon_div;
357a08fc7c8SMaxime Ripard
3584795c787SRoman Beranek /*
3594795c787SRoman Beranek * dclk is required to run at 1/4 the DSI per-lane bit rate.
3604795c787SRoman Beranek */
36185fb3526SMaxime Ripard tcon->dclk_min_div = SUN6I_DSI_TCON_DIV;
36285fb3526SMaxime Ripard tcon->dclk_max_div = SUN6I_DSI_TCON_DIV;
3634795c787SRoman Beranek clk_set_rate(tcon->dclk, mode->crtc_clock * 1000 * (bpp / lanes)
3644795c787SRoman Beranek / SUN6I_DSI_TCON_DIV);
365a08fc7c8SMaxime Ripard
3664795c787SRoman Beranek /* Set the resolution */
3674795c787SRoman Beranek regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG,
3684795c787SRoman Beranek SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) |
3694795c787SRoman Beranek SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
370a08fc7c8SMaxime Ripard
371f11adcecSJonathan Liu /* Set dithering if needed */
372f11adcecSJonathan Liu sun4i_tcon0_mode_set_dithering(tcon, sun4i_tcon_get_connector(encoder));
373f11adcecSJonathan Liu
374a08fc7c8SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
375a08fc7c8SMaxime Ripard SUN4I_TCON0_CTL_IF_MASK,
376a08fc7c8SMaxime Ripard SUN4I_TCON0_CTL_IF_8080);
377a08fc7c8SMaxime Ripard
378a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON_ECC_FIFO_REG,
379a08fc7c8SMaxime Ripard SUN4I_TCON_ECC_FIFO_EN);
380a08fc7c8SMaxime Ripard
381a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_CPU_IF_REG,
382a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_IF_MODE_DSI |
383a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_IF_TRI_FIFO_FLUSH |
384a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_IF_TRI_FIFO_EN |
385a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_IF_TRI_EN);
386a08fc7c8SMaxime Ripard
387a08fc7c8SMaxime Ripard /*
388a08fc7c8SMaxime Ripard * This looks suspicious, but it works...
389a08fc7c8SMaxime Ripard *
390a08fc7c8SMaxime Ripard * The datasheet says that this should be set higher than 20 *
391a08fc7c8SMaxime Ripard * pixel cycle, but it's not clear what a pixel cycle is.
392a08fc7c8SMaxime Ripard */
393a08fc7c8SMaxime Ripard regmap_read(tcon->regs, SUN4I_TCON0_DCLK_REG, &tcon_div);
394a08fc7c8SMaxime Ripard tcon_div &= GENMASK(6, 0);
395a08fc7c8SMaxime Ripard block_space = mode->htotal * bpp / (tcon_div * lanes);
396a08fc7c8SMaxime Ripard block_space -= mode->hdisplay + 40;
397a08fc7c8SMaxime Ripard
398a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_CPU_TRI0_REG,
399a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_TRI0_BLOCK_SPACE(block_space) |
400a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_TRI0_BLOCK_SIZE(mode->hdisplay));
401a08fc7c8SMaxime Ripard
402a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_CPU_TRI1_REG,
403a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_TRI1_BLOCK_NUM(mode->vdisplay));
404a08fc7c8SMaxime Ripard
405a08fc7c8SMaxime Ripard start_delay = (mode->crtc_vtotal - mode->crtc_vdisplay - 10 - 1);
406a08fc7c8SMaxime Ripard start_delay = start_delay * mode->crtc_htotal * 149;
407a08fc7c8SMaxime Ripard start_delay = start_delay / (mode->crtc_clock / 1000) / 8;
408a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_CPU_TRI2_REG,
409a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_TRI2_TRANS_START_SET(10) |
410a08fc7c8SMaxime Ripard SUN4I_TCON0_CPU_TRI2_START_DELAY(start_delay));
411a08fc7c8SMaxime Ripard
412a08fc7c8SMaxime Ripard /*
413a08fc7c8SMaxime Ripard * The Allwinner BSP has a comment that the period should be
414a08fc7c8SMaxime Ripard * the display clock * 15, but uses an hardcoded 3000...
415a08fc7c8SMaxime Ripard */
416a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON_SAFE_PERIOD_REG,
417a08fc7c8SMaxime Ripard SUN4I_TCON_SAFE_PERIOD_NUM(3000) |
418a08fc7c8SMaxime Ripard SUN4I_TCON_SAFE_PERIOD_MODE(3));
419a08fc7c8SMaxime Ripard
420a08fc7c8SMaxime Ripard /* Enable the output on the pins */
421a08fc7c8SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG,
422a08fc7c8SMaxime Ripard 0xe0000000);
423a08fc7c8SMaxime Ripard }
424a08fc7c8SMaxime Ripard
sun4i_tcon0_mode_set_lvds(struct sun4i_tcon * tcon,const struct drm_encoder * encoder,const struct drm_display_mode * mode)425a0c1214eSMaxime Ripard static void sun4i_tcon0_mode_set_lvds(struct sun4i_tcon *tcon,
426a0c1214eSMaxime Ripard const struct drm_encoder *encoder,
427a0c1214eSMaxime Ripard const struct drm_display_mode *mode)
428a0c1214eSMaxime Ripard {
429a0c1214eSMaxime Ripard unsigned int bp;
430a0c1214eSMaxime Ripard u8 clk_delay;
431a0c1214eSMaxime Ripard u32 reg, val = 0;
432a0c1214eSMaxime Ripard
43334d698f6SJernej Skrabec WARN_ON(!tcon->quirks->has_channel_0);
43434d698f6SJernej Skrabec
435a0c1214eSMaxime Ripard tcon->dclk_min_div = 7;
436a0c1214eSMaxime Ripard tcon->dclk_max_div = 7;
4374795c787SRoman Beranek clk_set_rate(tcon->dclk, mode->crtc_clock * 1000);
4384795c787SRoman Beranek
4394795c787SRoman Beranek /* Set the resolution */
4404795c787SRoman Beranek regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG,
4414795c787SRoman Beranek SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) |
4424795c787SRoman Beranek SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
443a0c1214eSMaxime Ripard
444f11adcecSJonathan Liu /* Set dithering if needed */
445f11adcecSJonathan Liu sun4i_tcon0_mode_set_dithering(tcon, sun4i_tcon_get_connector(encoder));
446f11adcecSJonathan Liu
447a0c1214eSMaxime Ripard /* Adjust clock delay */
448a0c1214eSMaxime Ripard clk_delay = sun4i_tcon_get_clk_delay(mode, 0);
449a0c1214eSMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
450a0c1214eSMaxime Ripard SUN4I_TCON0_CTL_CLK_DELAY_MASK,
451a0c1214eSMaxime Ripard SUN4I_TCON0_CTL_CLK_DELAY(clk_delay));
452a0c1214eSMaxime Ripard
453a0c1214eSMaxime Ripard /*
454a0c1214eSMaxime Ripard * This is called a backporch in the register documentation,
455a0c1214eSMaxime Ripard * but it really is the back porch + hsync
456a0c1214eSMaxime Ripard */
457a0c1214eSMaxime Ripard bp = mode->crtc_htotal - mode->crtc_hsync_start;
458a0c1214eSMaxime Ripard DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
459a0c1214eSMaxime Ripard mode->crtc_htotal, bp);
460a0c1214eSMaxime Ripard
461a0c1214eSMaxime Ripard /* Set horizontal display timings */
462a0c1214eSMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG,
463a0c1214eSMaxime Ripard SUN4I_TCON0_BASIC1_H_TOTAL(mode->htotal) |
464a0c1214eSMaxime Ripard SUN4I_TCON0_BASIC1_H_BACKPORCH(bp));
465a0c1214eSMaxime Ripard
466a0c1214eSMaxime Ripard /*
467a0c1214eSMaxime Ripard * This is called a backporch in the register documentation,
468a0c1214eSMaxime Ripard * but it really is the back porch + hsync
469a0c1214eSMaxime Ripard */
470a0c1214eSMaxime Ripard bp = mode->crtc_vtotal - mode->crtc_vsync_start;
471a0c1214eSMaxime Ripard DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
472a0c1214eSMaxime Ripard mode->crtc_vtotal, bp);
473a0c1214eSMaxime Ripard
474a0c1214eSMaxime Ripard /* Set vertical display timings */
475a0c1214eSMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG,
476a0c1214eSMaxime Ripard SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) |
477a0c1214eSMaxime Ripard SUN4I_TCON0_BASIC2_V_BACKPORCH(bp));
478a0c1214eSMaxime Ripard
4793bc46a08SMaxime Ripard reg = SUN4I_TCON0_LVDS_IF_CLK_SEL_TCON0;
480a0c1214eSMaxime Ripard if (sun4i_tcon_get_pixel_depth(encoder) == 24)
481a0c1214eSMaxime Ripard reg |= SUN4I_TCON0_LVDS_IF_BITWIDTH_24BITS;
482a0c1214eSMaxime Ripard else
483a0c1214eSMaxime Ripard reg |= SUN4I_TCON0_LVDS_IF_BITWIDTH_18BITS;
484a0c1214eSMaxime Ripard
485a0c1214eSMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_LVDS_IF_REG, reg);
486a0c1214eSMaxime Ripard
487a0c1214eSMaxime Ripard /* Setup the polarity of the various signals */
488a0c1214eSMaxime Ripard if (!(mode->flags & DRM_MODE_FLAG_PHSYNC))
489a0c1214eSMaxime Ripard val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE;
490a0c1214eSMaxime Ripard
491a0c1214eSMaxime Ripard if (!(mode->flags & DRM_MODE_FLAG_PVSYNC))
492a0c1214eSMaxime Ripard val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE;
493a0c1214eSMaxime Ripard
494a0c1214eSMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_IO_POL_REG, val);
495a0c1214eSMaxime Ripard
496a0c1214eSMaxime Ripard /* Map output pins to channel 0 */
497a0c1214eSMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
498a0c1214eSMaxime Ripard SUN4I_TCON_GCTL_IOMAP_MASK,
499a0c1214eSMaxime Ripard SUN4I_TCON_GCTL_IOMAP_TCON0);
50080b79e31SOndrej Jirman
50180b79e31SOndrej Jirman /* Enable the output on the pins */
50280b79e31SOndrej Jirman regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0xe0000000);
503a0c1214eSMaxime Ripard }
504a0c1214eSMaxime Ripard
sun4i_tcon0_mode_set_rgb(struct sun4i_tcon * tcon,const struct drm_encoder * encoder,const struct drm_display_mode * mode)505ba19c537SMaxime Ripard static void sun4i_tcon0_mode_set_rgb(struct sun4i_tcon *tcon,
506b842e2c9SPaul Kocialkowski const struct drm_encoder *encoder,
5075b8f0910SMaxime Ripard const struct drm_display_mode *mode)
5089026e0d1SMaxime Ripard {
5094843c9a2SPaul Kocialkowski struct drm_connector *connector = sun4i_tcon_get_connector(encoder);
5101e612a0fSVille Syrjälä const struct drm_display_info *info = &connector->display_info;
5119026e0d1SMaxime Ripard unsigned int bp, hsync, vsync;
5129026e0d1SMaxime Ripard u8 clk_delay;
5139026e0d1SMaxime Ripard u32 val = 0;
5149026e0d1SMaxime Ripard
51534d698f6SJernej Skrabec WARN_ON(!tcon->quirks->has_channel_0);
51634d698f6SJernej Skrabec
5174396393fSChen-Yu Tsai tcon->dclk_min_div = tcon->quirks->dclk_min_div;
518ec08d596SMaxime Ripard tcon->dclk_max_div = 127;
5194795c787SRoman Beranek clk_set_rate(tcon->dclk, mode->crtc_clock * 1000);
5204795c787SRoman Beranek
5214795c787SRoman Beranek /* Set the resolution */
5224795c787SRoman Beranek regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG,
5234795c787SRoman Beranek SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) |
5244795c787SRoman Beranek SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay));
52586cf6788SChen-Yu Tsai
526f11adcecSJonathan Liu /* Set dithering if needed */
5274843c9a2SPaul Kocialkowski sun4i_tcon0_mode_set_dithering(tcon, connector);
528f11adcecSJonathan Liu
5299026e0d1SMaxime Ripard /* Adjust clock delay */
5309026e0d1SMaxime Ripard clk_delay = sun4i_tcon_get_clk_delay(mode, 0);
5319026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
5329026e0d1SMaxime Ripard SUN4I_TCON0_CTL_CLK_DELAY_MASK,
5339026e0d1SMaxime Ripard SUN4I_TCON0_CTL_CLK_DELAY(clk_delay));
5349026e0d1SMaxime Ripard
5359026e0d1SMaxime Ripard /*
5369026e0d1SMaxime Ripard * This is called a backporch in the register documentation,
53723a1cb11SChen-Yu Tsai * but it really is the back porch + hsync
5389026e0d1SMaxime Ripard */
5399026e0d1SMaxime Ripard bp = mode->crtc_htotal - mode->crtc_hsync_start;
5409026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
5419026e0d1SMaxime Ripard mode->crtc_htotal, bp);
5429026e0d1SMaxime Ripard
5439026e0d1SMaxime Ripard /* Set horizontal display timings */
5449026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG,
5459026e0d1SMaxime Ripard SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) |
5469026e0d1SMaxime Ripard SUN4I_TCON0_BASIC1_H_BACKPORCH(bp));
5479026e0d1SMaxime Ripard
5489026e0d1SMaxime Ripard /*
5499026e0d1SMaxime Ripard * This is called a backporch in the register documentation,
55023a1cb11SChen-Yu Tsai * but it really is the back porch + hsync
5519026e0d1SMaxime Ripard */
5529026e0d1SMaxime Ripard bp = mode->crtc_vtotal - mode->crtc_vsync_start;
5539026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
5549026e0d1SMaxime Ripard mode->crtc_vtotal, bp);
5559026e0d1SMaxime Ripard
5569026e0d1SMaxime Ripard /* Set vertical display timings */
5579026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG,
558a88cbbd4SMaxime Ripard SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) |
5599026e0d1SMaxime Ripard SUN4I_TCON0_BASIC2_V_BACKPORCH(bp));
5609026e0d1SMaxime Ripard
5619026e0d1SMaxime Ripard /* Set Hsync and Vsync length */
5629026e0d1SMaxime Ripard hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
5639026e0d1SMaxime Ripard vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
5649026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
5659026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG,
5669026e0d1SMaxime Ripard SUN4I_TCON0_BASIC3_V_SYNC(vsync) |
5679026e0d1SMaxime Ripard SUN4I_TCON0_BASIC3_H_SYNC(hsync));
5689026e0d1SMaxime Ripard
5699026e0d1SMaxime Ripard /* Setup the polarity of the various signals */
570fa4127c5SGiulio Benetti if (mode->flags & DRM_MODE_FLAG_PHSYNC)
5719026e0d1SMaxime Ripard val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE;
5729026e0d1SMaxime Ripard
573fa4127c5SGiulio Benetti if (mode->flags & DRM_MODE_FLAG_PVSYNC)
5749026e0d1SMaxime Ripard val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE;
5759026e0d1SMaxime Ripard
5761e612a0fSVille Syrjälä if (info->bus_flags & DRM_BUS_FLAG_DE_LOW)
57765bf2d54SPaul Kocialkowski val |= SUN4I_TCON0_IO_POL_DE_NEGATIVE;
57865bf2d54SPaul Kocialkowski
5791e612a0fSVille Syrjälä if (info->bus_flags & DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE)
58067f4aeb2SGiulio Benetti val |= SUN4I_TCON0_IO_POL_DCLK_DRIVE_NEGEDGE;
581490cda5aSGiulio Benetti
5829026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG,
58365bf2d54SPaul Kocialkowski SUN4I_TCON0_IO_POL_HSYNC_POSITIVE |
58465bf2d54SPaul Kocialkowski SUN4I_TCON0_IO_POL_VSYNC_POSITIVE |
58567f4aeb2SGiulio Benetti SUN4I_TCON0_IO_POL_DCLK_DRIVE_NEGEDGE |
58665bf2d54SPaul Kocialkowski SUN4I_TCON0_IO_POL_DE_NEGATIVE,
5879026e0d1SMaxime Ripard val);
5889026e0d1SMaxime Ripard
5899026e0d1SMaxime Ripard /* Map output pins to channel 0 */
5909026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
5919026e0d1SMaxime Ripard SUN4I_TCON_GCTL_IOMAP_MASK,
5929026e0d1SMaxime Ripard SUN4I_TCON_GCTL_IOMAP_TCON0);
5939026e0d1SMaxime Ripard
5949026e0d1SMaxime Ripard /* Enable the output on the pins */
5959026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0);
5969026e0d1SMaxime Ripard }
5979026e0d1SMaxime Ripard
sun4i_tcon1_mode_set(struct sun4i_tcon * tcon,const struct drm_display_mode * mode)5985b8f0910SMaxime Ripard static void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
5995b8f0910SMaxime Ripard const struct drm_display_mode *mode)
6009026e0d1SMaxime Ripard {
601b8317a3dSMaxime Ripard unsigned int bp, hsync, vsync, vtotal;
6029026e0d1SMaxime Ripard u8 clk_delay;
6039026e0d1SMaxime Ripard u32 val;
6049026e0d1SMaxime Ripard
60591ea2f29SChen-Yu Tsai WARN_ON(!tcon->quirks->has_channel_1);
6068e924047SMaxime Ripard
60786cf6788SChen-Yu Tsai /* Configure the dot clock */
60886cf6788SChen-Yu Tsai clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000);
60986cf6788SChen-Yu Tsai
6109026e0d1SMaxime Ripard /* Adjust clock delay */
6119026e0d1SMaxime Ripard clk_delay = sun4i_tcon_get_clk_delay(mode, 1);
6129026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
6139026e0d1SMaxime Ripard SUN4I_TCON1_CTL_CLK_DELAY_MASK,
6149026e0d1SMaxime Ripard SUN4I_TCON1_CTL_CLK_DELAY(clk_delay));
6159026e0d1SMaxime Ripard
6169026e0d1SMaxime Ripard /* Set interlaced mode */
6179026e0d1SMaxime Ripard if (mode->flags & DRM_MODE_FLAG_INTERLACE)
6189026e0d1SMaxime Ripard val = SUN4I_TCON1_CTL_INTERLACE_ENABLE;
6199026e0d1SMaxime Ripard else
6209026e0d1SMaxime Ripard val = 0;
6219026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
6229026e0d1SMaxime Ripard SUN4I_TCON1_CTL_INTERLACE_ENABLE,
6239026e0d1SMaxime Ripard val);
6249026e0d1SMaxime Ripard
6259026e0d1SMaxime Ripard /* Set the input resolution */
6269026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG,
6279026e0d1SMaxime Ripard SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) |
6289026e0d1SMaxime Ripard SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay));
6299026e0d1SMaxime Ripard
6309026e0d1SMaxime Ripard /* Set the upscaling resolution */
6319026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG,
6329026e0d1SMaxime Ripard SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) |
6339026e0d1SMaxime Ripard SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay));
6349026e0d1SMaxime Ripard
6359026e0d1SMaxime Ripard /* Set the output resolution */
6369026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG,
6379026e0d1SMaxime Ripard SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) |
6389026e0d1SMaxime Ripard SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay));
6399026e0d1SMaxime Ripard
6409026e0d1SMaxime Ripard /* Set horizontal display timings */
6413cb2f46bSMaxime Ripard bp = mode->crtc_htotal - mode->crtc_hsync_start;
6429026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n",
6439026e0d1SMaxime Ripard mode->htotal, bp);
6449026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG,
6459026e0d1SMaxime Ripard SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) |
6469026e0d1SMaxime Ripard SUN4I_TCON1_BASIC3_H_BACKPORCH(bp));
6479026e0d1SMaxime Ripard
6483cb2f46bSMaxime Ripard bp = mode->crtc_vtotal - mode->crtc_vsync_start;
6499026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n",
650b8317a3dSMaxime Ripard mode->crtc_vtotal, bp);
651b8317a3dSMaxime Ripard
652b8317a3dSMaxime Ripard /*
653b8317a3dSMaxime Ripard * The vertical resolution needs to be doubled in all
654b8317a3dSMaxime Ripard * cases. We could use crtc_vtotal and always multiply by two,
655b8317a3dSMaxime Ripard * but that leads to a rounding error in interlace when vtotal
656b8317a3dSMaxime Ripard * is odd.
657b8317a3dSMaxime Ripard *
658b8317a3dSMaxime Ripard * This happens with TV's PAL for example, where vtotal will
659b8317a3dSMaxime Ripard * be 625, crtc_vtotal 312, and thus crtc_vtotal * 2 will be
660b8317a3dSMaxime Ripard * 624, which apparently confuses the hardware.
661b8317a3dSMaxime Ripard *
662b8317a3dSMaxime Ripard * To work around this, we will always use vtotal, and
663b8317a3dSMaxime Ripard * multiply by two only if we're not in interlace.
664b8317a3dSMaxime Ripard */
665b8317a3dSMaxime Ripard vtotal = mode->vtotal;
666b8317a3dSMaxime Ripard if (!(mode->flags & DRM_MODE_FLAG_INTERLACE))
667b8317a3dSMaxime Ripard vtotal = vtotal * 2;
668b8317a3dSMaxime Ripard
669b8317a3dSMaxime Ripard /* Set vertical display timings */
6709026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG,
671b8317a3dSMaxime Ripard SUN4I_TCON1_BASIC4_V_TOTAL(vtotal) |
6729026e0d1SMaxime Ripard SUN4I_TCON1_BASIC4_V_BACKPORCH(bp));
6739026e0d1SMaxime Ripard
6749026e0d1SMaxime Ripard /* Set Hsync and Vsync length */
6759026e0d1SMaxime Ripard hsync = mode->crtc_hsync_end - mode->crtc_hsync_start;
6769026e0d1SMaxime Ripard vsync = mode->crtc_vsync_end - mode->crtc_vsync_start;
6779026e0d1SMaxime Ripard DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync);
6789026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG,
6799026e0d1SMaxime Ripard SUN4I_TCON1_BASIC5_V_SYNC(vsync) |
6809026e0d1SMaxime Ripard SUN4I_TCON1_BASIC5_H_SYNC(hsync));
6819026e0d1SMaxime Ripard
68250791f5dSJernej Skrabec /* Setup the polarity of multiple signals */
68350791f5dSJernej Skrabec if (tcon->quirks->polarity_in_ch0) {
68450791f5dSJernej Skrabec val = 0;
68550791f5dSJernej Skrabec
68650791f5dSJernej Skrabec if (mode->flags & DRM_MODE_FLAG_PHSYNC)
68750791f5dSJernej Skrabec val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE;
68850791f5dSJernej Skrabec
68950791f5dSJernej Skrabec if (mode->flags & DRM_MODE_FLAG_PVSYNC)
69050791f5dSJernej Skrabec val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE;
69150791f5dSJernej Skrabec
69250791f5dSJernej Skrabec regmap_write(tcon->regs, SUN4I_TCON0_IO_POL_REG, val);
69350791f5dSJernej Skrabec } else {
69450791f5dSJernej Skrabec /* according to vendor driver, this bit must be always set */
69550791f5dSJernej Skrabec val = SUN4I_TCON1_IO_POL_UNKNOWN;
69650791f5dSJernej Skrabec
69750791f5dSJernej Skrabec if (mode->flags & DRM_MODE_FLAG_PHSYNC)
69850791f5dSJernej Skrabec val |= SUN4I_TCON1_IO_POL_HSYNC_POSITIVE;
69950791f5dSJernej Skrabec
70050791f5dSJernej Skrabec if (mode->flags & DRM_MODE_FLAG_PVSYNC)
70150791f5dSJernej Skrabec val |= SUN4I_TCON1_IO_POL_VSYNC_POSITIVE;
70250791f5dSJernej Skrabec
70350791f5dSJernej Skrabec regmap_write(tcon->regs, SUN4I_TCON1_IO_POL_REG, val);
70450791f5dSJernej Skrabec }
70550791f5dSJernej Skrabec
7069026e0d1SMaxime Ripard /* Map output pins to channel 1 */
7079026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG,
7089026e0d1SMaxime Ripard SUN4I_TCON_GCTL_IOMAP_MASK,
7099026e0d1SMaxime Ripard SUN4I_TCON_GCTL_IOMAP_TCON1);
7109026e0d1SMaxime Ripard }
7115b8f0910SMaxime Ripard
sun4i_tcon_mode_set(struct sun4i_tcon * tcon,const struct drm_encoder * encoder,const struct drm_display_mode * mode)7125b8f0910SMaxime Ripard void sun4i_tcon_mode_set(struct sun4i_tcon *tcon,
7135b8f0910SMaxime Ripard const struct drm_encoder *encoder,
7145b8f0910SMaxime Ripard const struct drm_display_mode *mode)
7155b8f0910SMaxime Ripard {
7165b8f0910SMaxime Ripard switch (encoder->encoder_type) {
717a08fc7c8SMaxime Ripard case DRM_MODE_ENCODER_DSI:
71879891d56SChen-Yu Tsai /* DSI is tied to special case of CPU interface */
71979891d56SChen-Yu Tsai sun4i_tcon0_mode_set_cpu(tcon, encoder, mode);
720a08fc7c8SMaxime Ripard break;
721a0c1214eSMaxime Ripard case DRM_MODE_ENCODER_LVDS:
722a0c1214eSMaxime Ripard sun4i_tcon0_mode_set_lvds(tcon, encoder, mode);
723a0c1214eSMaxime Ripard break;
7245b8f0910SMaxime Ripard case DRM_MODE_ENCODER_NONE:
725b842e2c9SPaul Kocialkowski sun4i_tcon0_mode_set_rgb(tcon, encoder, mode);
7265b8f0910SMaxime Ripard sun4i_tcon_set_mux(tcon, 0, encoder);
7275b8f0910SMaxime Ripard break;
7285b8f0910SMaxime Ripard case DRM_MODE_ENCODER_TVDAC:
7295b8f0910SMaxime Ripard case DRM_MODE_ENCODER_TMDS:
7305b8f0910SMaxime Ripard sun4i_tcon1_mode_set(tcon, mode);
7315b8f0910SMaxime Ripard sun4i_tcon_set_mux(tcon, 1, encoder);
7325b8f0910SMaxime Ripard break;
7335b8f0910SMaxime Ripard default:
7345b8f0910SMaxime Ripard DRM_DEBUG_DRIVER("Unknown encoder type, doing nothing...\n");
7355b8f0910SMaxime Ripard }
7365b8f0910SMaxime Ripard }
7375b8f0910SMaxime Ripard EXPORT_SYMBOL(sun4i_tcon_mode_set);
7389026e0d1SMaxime Ripard
sun4i_tcon_finish_page_flip(struct drm_device * dev,struct sun4i_crtc * scrtc)7399026e0d1SMaxime Ripard static void sun4i_tcon_finish_page_flip(struct drm_device *dev,
7409026e0d1SMaxime Ripard struct sun4i_crtc *scrtc)
7419026e0d1SMaxime Ripard {
7429026e0d1SMaxime Ripard unsigned long flags;
7439026e0d1SMaxime Ripard
7449026e0d1SMaxime Ripard spin_lock_irqsave(&dev->event_lock, flags);
7459026e0d1SMaxime Ripard if (scrtc->event) {
7469026e0d1SMaxime Ripard drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event);
7479026e0d1SMaxime Ripard drm_crtc_vblank_put(&scrtc->crtc);
7489026e0d1SMaxime Ripard scrtc->event = NULL;
7499026e0d1SMaxime Ripard }
7509026e0d1SMaxime Ripard spin_unlock_irqrestore(&dev->event_lock, flags);
7519026e0d1SMaxime Ripard }
7529026e0d1SMaxime Ripard
sun4i_tcon_handler(int irq,void * private)7539026e0d1SMaxime Ripard static irqreturn_t sun4i_tcon_handler(int irq, void *private)
7549026e0d1SMaxime Ripard {
7559026e0d1SMaxime Ripard struct sun4i_tcon *tcon = private;
7569026e0d1SMaxime Ripard struct drm_device *drm = tcon->drm;
75746cce6daSChen-Yu Tsai struct sun4i_crtc *scrtc = tcon->crtc;
7583004f75fSMaxime Ripard struct sunxi_engine *engine = scrtc->engine;
7599026e0d1SMaxime Ripard unsigned int status;
7609026e0d1SMaxime Ripard
7619026e0d1SMaxime Ripard regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status);
7629026e0d1SMaxime Ripard
7639026e0d1SMaxime Ripard if (!(status & (SUN4I_TCON_GINT0_VBLANK_INT(0) |
764a493ceaeSMaxime Ripard SUN4I_TCON_GINT0_VBLANK_INT(1) |
765a493ceaeSMaxime Ripard SUN4I_TCON_GINT0_TCON0_TRI_FINISH_INT)))
7669026e0d1SMaxime Ripard return IRQ_NONE;
7679026e0d1SMaxime Ripard
7689026e0d1SMaxime Ripard drm_crtc_handle_vblank(&scrtc->crtc);
7699026e0d1SMaxime Ripard sun4i_tcon_finish_page_flip(drm, scrtc);
7709026e0d1SMaxime Ripard
7719026e0d1SMaxime Ripard /* Acknowledge the interrupt */
7729026e0d1SMaxime Ripard regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG,
7739026e0d1SMaxime Ripard SUN4I_TCON_GINT0_VBLANK_INT(0) |
774a493ceaeSMaxime Ripard SUN4I_TCON_GINT0_VBLANK_INT(1) |
775a493ceaeSMaxime Ripard SUN4I_TCON_GINT0_TCON0_TRI_FINISH_INT,
7769026e0d1SMaxime Ripard 0);
7779026e0d1SMaxime Ripard
7783004f75fSMaxime Ripard if (engine->ops->vblank_quirk)
7793004f75fSMaxime Ripard engine->ops->vblank_quirk(engine);
7803004f75fSMaxime Ripard
7819026e0d1SMaxime Ripard return IRQ_HANDLED;
7829026e0d1SMaxime Ripard }
7839026e0d1SMaxime Ripard
sun4i_tcon_init_clocks(struct device * dev,struct sun4i_tcon * tcon)7849026e0d1SMaxime Ripard static int sun4i_tcon_init_clocks(struct device *dev,
7859026e0d1SMaxime Ripard struct sun4i_tcon *tcon)
7869026e0d1SMaxime Ripard {
787123ee07bSXuDong Liu tcon->clk = devm_clk_get_enabled(dev, "ahb");
7889026e0d1SMaxime Ripard if (IS_ERR(tcon->clk)) {
7899026e0d1SMaxime Ripard dev_err(dev, "Couldn't get the TCON bus clock\n");
7909026e0d1SMaxime Ripard return PTR_ERR(tcon->clk);
7919026e0d1SMaxime Ripard }
7929026e0d1SMaxime Ripard
79334d698f6SJernej Skrabec if (tcon->quirks->has_channel_0) {
794123ee07bSXuDong Liu tcon->sclk0 = devm_clk_get_enabled(dev, "tcon-ch0");
7959026e0d1SMaxime Ripard if (IS_ERR(tcon->sclk0)) {
7969026e0d1SMaxime Ripard dev_err(dev, "Couldn't get the TCON channel 0 clock\n");
7979026e0d1SMaxime Ripard return PTR_ERR(tcon->sclk0);
7989026e0d1SMaxime Ripard }
79934d698f6SJernej Skrabec }
8009026e0d1SMaxime Ripard
80191ea2f29SChen-Yu Tsai if (tcon->quirks->has_channel_1) {
8029026e0d1SMaxime Ripard tcon->sclk1 = devm_clk_get(dev, "tcon-ch1");
8039026e0d1SMaxime Ripard if (IS_ERR(tcon->sclk1)) {
8049026e0d1SMaxime Ripard dev_err(dev, "Couldn't get the TCON channel 1 clock\n");
8059026e0d1SMaxime Ripard return PTR_ERR(tcon->sclk1);
8069026e0d1SMaxime Ripard }
8078e924047SMaxime Ripard }
8089026e0d1SMaxime Ripard
8094c7f16d1SChen-Yu Tsai return 0;
8109026e0d1SMaxime Ripard }
8119026e0d1SMaxime Ripard
sun4i_tcon_init_irq(struct device * dev,struct sun4i_tcon * tcon)8129026e0d1SMaxime Ripard static int sun4i_tcon_init_irq(struct device *dev,
8139026e0d1SMaxime Ripard struct sun4i_tcon *tcon)
8149026e0d1SMaxime Ripard {
8159026e0d1SMaxime Ripard struct platform_device *pdev = to_platform_device(dev);
8169026e0d1SMaxime Ripard int irq, ret;
8179026e0d1SMaxime Ripard
8189026e0d1SMaxime Ripard irq = platform_get_irq(pdev, 0);
819ed7cca1fSMarkus Elfring if (irq < 0)
8209026e0d1SMaxime Ripard return irq;
8219026e0d1SMaxime Ripard
8229026e0d1SMaxime Ripard ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0,
8239026e0d1SMaxime Ripard dev_name(dev), tcon);
8249026e0d1SMaxime Ripard if (ret) {
8259026e0d1SMaxime Ripard dev_err(dev, "Couldn't request the IRQ\n");
8269026e0d1SMaxime Ripard return ret;
8279026e0d1SMaxime Ripard }
8289026e0d1SMaxime Ripard
8299026e0d1SMaxime Ripard return 0;
8309026e0d1SMaxime Ripard }
8319026e0d1SMaxime Ripard
832f13478c9SRikard Falkeborn static const struct regmap_config sun4i_tcon_regmap_config = {
8339026e0d1SMaxime Ripard .reg_bits = 32,
8349026e0d1SMaxime Ripard .val_bits = 32,
8359026e0d1SMaxime Ripard .reg_stride = 4,
8369026e0d1SMaxime Ripard .max_register = 0x800,
8379026e0d1SMaxime Ripard };
8389026e0d1SMaxime Ripard
sun4i_tcon_init_regmap(struct device * dev,struct sun4i_tcon * tcon)8399026e0d1SMaxime Ripard static int sun4i_tcon_init_regmap(struct device *dev,
8409026e0d1SMaxime Ripard struct sun4i_tcon *tcon)
8419026e0d1SMaxime Ripard {
8429026e0d1SMaxime Ripard struct platform_device *pdev = to_platform_device(dev);
8439026e0d1SMaxime Ripard void __iomem *regs;
8449026e0d1SMaxime Ripard
845f5df171fSCai Huoqing regs = devm_platform_ioremap_resource(pdev, 0);
846af346f55SWei Yongjun if (IS_ERR(regs))
8479026e0d1SMaxime Ripard return PTR_ERR(regs);
8489026e0d1SMaxime Ripard
8499026e0d1SMaxime Ripard tcon->regs = devm_regmap_init_mmio(dev, regs,
8509026e0d1SMaxime Ripard &sun4i_tcon_regmap_config);
8519026e0d1SMaxime Ripard if (IS_ERR(tcon->regs)) {
8529026e0d1SMaxime Ripard dev_err(dev, "Couldn't create the TCON regmap\n");
8539026e0d1SMaxime Ripard return PTR_ERR(tcon->regs);
8549026e0d1SMaxime Ripard }
8559026e0d1SMaxime Ripard
8569026e0d1SMaxime Ripard /* Make sure the TCON is disabled and all IRQs are off */
8579026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0);
8589026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0);
8599026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0);
8609026e0d1SMaxime Ripard
8619026e0d1SMaxime Ripard /* Disable IO lines and set them to tristate */
8629026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0);
8639026e0d1SMaxime Ripard regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0);
8649026e0d1SMaxime Ripard
8659026e0d1SMaxime Ripard return 0;
8669026e0d1SMaxime Ripard }
8679026e0d1SMaxime Ripard
868b317fa3bSChen-Yu Tsai /*
869b317fa3bSChen-Yu Tsai * On SoCs with the old display pipeline design (Display Engine 1.0),
870b317fa3bSChen-Yu Tsai * the TCON is always tied to just one backend. Hence we can traverse
871b317fa3bSChen-Yu Tsai * the of_graph upwards to find the backend our tcon is connected to,
872b317fa3bSChen-Yu Tsai * and take its ID as our own.
873b317fa3bSChen-Yu Tsai *
874b317fa3bSChen-Yu Tsai * We can either identify backends from their compatible strings, which
875b317fa3bSChen-Yu Tsai * means maintaining a large list of them. Or, since the backend is
876b317fa3bSChen-Yu Tsai * registered and binded before the TCON, we can just go through the
877b317fa3bSChen-Yu Tsai * list of registered backends and compare the device node.
87887969338SIcenowy Zheng *
87987969338SIcenowy Zheng * As the structures now store engines instead of backends, here this
88087969338SIcenowy Zheng * function in fact searches the corresponding engine, and the ID is
88187969338SIcenowy Zheng * requested via the get_id function of the engine.
882b317fa3bSChen-Yu Tsai */
883e8d5bbf7SChen-Yu Tsai static struct sunxi_engine *
sun4i_tcon_find_engine_traverse(struct sun4i_drv * drv,struct device_node * node,u32 port_id)884e8d5bbf7SChen-Yu Tsai sun4i_tcon_find_engine_traverse(struct sun4i_drv *drv,
88549836b11SJernej Skrabec struct device_node *node,
88649836b11SJernej Skrabec u32 port_id)
887b317fa3bSChen-Yu Tsai {
888b317fa3bSChen-Yu Tsai struct device_node *port, *ep, *remote;
889be3fe0f9SChen-Yu Tsai struct sunxi_engine *engine = ERR_PTR(-EINVAL);
89049836b11SJernej Skrabec u32 reg = 0;
891b317fa3bSChen-Yu Tsai
89249836b11SJernej Skrabec port = of_graph_get_port_by_id(node, port_id);
893b317fa3bSChen-Yu Tsai if (!port)
894b317fa3bSChen-Yu Tsai return ERR_PTR(-EINVAL);
895b317fa3bSChen-Yu Tsai
8961469619dSChen-Yu Tsai /*
8971469619dSChen-Yu Tsai * This only works if there is only one path from the TCON
8981469619dSChen-Yu Tsai * to any display engine. Otherwise the probe order of the
8991469619dSChen-Yu Tsai * TCONs and display engines is not guaranteed. They may
9001469619dSChen-Yu Tsai * either bind to the wrong one, or worse, bind to the same
9011469619dSChen-Yu Tsai * one if additional checks are not done.
9021469619dSChen-Yu Tsai *
9031469619dSChen-Yu Tsai * Bail out if there are multiple input connections.
9041469619dSChen-Yu Tsai */
905be3fe0f9SChen-Yu Tsai if (of_get_available_child_count(port) != 1)
906be3fe0f9SChen-Yu Tsai goto out_put_port;
9071469619dSChen-Yu Tsai
908be3fe0f9SChen-Yu Tsai /* Get the first connection without specifying an ID */
909be3fe0f9SChen-Yu Tsai ep = of_get_next_available_child(port, NULL);
910be3fe0f9SChen-Yu Tsai if (!ep)
911be3fe0f9SChen-Yu Tsai goto out_put_port;
912be3fe0f9SChen-Yu Tsai
913b317fa3bSChen-Yu Tsai remote = of_graph_get_remote_port_parent(ep);
914b317fa3bSChen-Yu Tsai if (!remote)
915be3fe0f9SChen-Yu Tsai goto out_put_ep;
916b317fa3bSChen-Yu Tsai
91787969338SIcenowy Zheng /* does this node match any registered engines? */
918be3fe0f9SChen-Yu Tsai list_for_each_entry(engine, &drv->engine_list, list)
919be3fe0f9SChen-Yu Tsai if (remote == engine->node)
920be3fe0f9SChen-Yu Tsai goto out_put_remote;
921b317fa3bSChen-Yu Tsai
92249836b11SJernej Skrabec /*
92349836b11SJernej Skrabec * According to device tree binding input ports have even id
92449836b11SJernej Skrabec * number and output ports have odd id. Since component with
92549836b11SJernej Skrabec * more than one input and one output (TCON TOP) exits, correct
92649836b11SJernej Skrabec * remote input id has to be calculated by subtracting 1 from
92749836b11SJernej Skrabec * remote output id. If this for some reason can't be done, 0
92849836b11SJernej Skrabec * is used as input port id.
92949836b11SJernej Skrabec */
930da82107eSJernej Skrabec of_node_put(port);
93149836b11SJernej Skrabec port = of_graph_get_remote_port(ep);
93249836b11SJernej Skrabec if (!of_property_read_u32(port, "reg", ®) && reg > 0)
93349836b11SJernej Skrabec reg -= 1;
93449836b11SJernej Skrabec
935b317fa3bSChen-Yu Tsai /* keep looking through upstream ports */
93649836b11SJernej Skrabec engine = sun4i_tcon_find_engine_traverse(drv, remote, reg);
937b317fa3bSChen-Yu Tsai
938be3fe0f9SChen-Yu Tsai out_put_remote:
939be3fe0f9SChen-Yu Tsai of_node_put(remote);
940be3fe0f9SChen-Yu Tsai out_put_ep:
941be3fe0f9SChen-Yu Tsai of_node_put(ep);
942be3fe0f9SChen-Yu Tsai out_put_port:
943be3fe0f9SChen-Yu Tsai of_node_put(port);
944be3fe0f9SChen-Yu Tsai
945be3fe0f9SChen-Yu Tsai return engine;
946b317fa3bSChen-Yu Tsai }
947b317fa3bSChen-Yu Tsai
948e8d5bbf7SChen-Yu Tsai /*
949e8d5bbf7SChen-Yu Tsai * The device tree binding says that the remote endpoint ID of any
950e8d5bbf7SChen-Yu Tsai * connection between components, up to and including the TCON, of
951e8d5bbf7SChen-Yu Tsai * the display pipeline should be equal to the actual ID of the local
952e8d5bbf7SChen-Yu Tsai * component. Thus we can look at any one of the input connections of
953e8d5bbf7SChen-Yu Tsai * the TCONs, and use that connection's remote endpoint ID as our own.
954e8d5bbf7SChen-Yu Tsai *
955e8d5bbf7SChen-Yu Tsai * Since the user of this function already finds the input port,
956e8d5bbf7SChen-Yu Tsai * the port is passed in directly without further checks.
957e8d5bbf7SChen-Yu Tsai */
sun4i_tcon_of_get_id_from_port(struct device_node * port)958e8d5bbf7SChen-Yu Tsai static int sun4i_tcon_of_get_id_from_port(struct device_node *port)
959e8d5bbf7SChen-Yu Tsai {
960e8d5bbf7SChen-Yu Tsai struct device_node *ep;
961e8d5bbf7SChen-Yu Tsai int ret = -EINVAL;
962e8d5bbf7SChen-Yu Tsai
963e8d5bbf7SChen-Yu Tsai /* try finding an upstream endpoint */
964e8d5bbf7SChen-Yu Tsai for_each_available_child_of_node(port, ep) {
965e8d5bbf7SChen-Yu Tsai struct device_node *remote;
966e8d5bbf7SChen-Yu Tsai u32 reg;
967e8d5bbf7SChen-Yu Tsai
968e8d5bbf7SChen-Yu Tsai remote = of_graph_get_remote_endpoint(ep);
969e8d5bbf7SChen-Yu Tsai if (!remote)
970e8d5bbf7SChen-Yu Tsai continue;
971e8d5bbf7SChen-Yu Tsai
972e8d5bbf7SChen-Yu Tsai ret = of_property_read_u32(remote, "reg", ®);
973e8d5bbf7SChen-Yu Tsai if (ret)
974e8d5bbf7SChen-Yu Tsai continue;
975e8d5bbf7SChen-Yu Tsai
976e8d5bbf7SChen-Yu Tsai ret = reg;
977e8d5bbf7SChen-Yu Tsai }
978e8d5bbf7SChen-Yu Tsai
979e8d5bbf7SChen-Yu Tsai return ret;
980e8d5bbf7SChen-Yu Tsai }
981e8d5bbf7SChen-Yu Tsai
982e8d5bbf7SChen-Yu Tsai /*
983e8d5bbf7SChen-Yu Tsai * Once we know the TCON's id, we can look through the list of
984e8d5bbf7SChen-Yu Tsai * engines to find a matching one. We assume all engines have
985e8d5bbf7SChen-Yu Tsai * been probed and added to the list.
986e8d5bbf7SChen-Yu Tsai */
sun4i_tcon_get_engine_by_id(struct sun4i_drv * drv,int id)987e8d5bbf7SChen-Yu Tsai static struct sunxi_engine *sun4i_tcon_get_engine_by_id(struct sun4i_drv *drv,
988e8d5bbf7SChen-Yu Tsai int id)
989e8d5bbf7SChen-Yu Tsai {
990e8d5bbf7SChen-Yu Tsai struct sunxi_engine *engine;
991e8d5bbf7SChen-Yu Tsai
992e8d5bbf7SChen-Yu Tsai list_for_each_entry(engine, &drv->engine_list, list)
993e8d5bbf7SChen-Yu Tsai if (engine->id == id)
994e8d5bbf7SChen-Yu Tsai return engine;
995e8d5bbf7SChen-Yu Tsai
996e8d5bbf7SChen-Yu Tsai return ERR_PTR(-EINVAL);
997e8d5bbf7SChen-Yu Tsai }
998e8d5bbf7SChen-Yu Tsai
sun4i_tcon_connected_to_tcon_top(struct device_node * node)999cf77d79bSJernej Skrabec static bool sun4i_tcon_connected_to_tcon_top(struct device_node *node)
1000cf77d79bSJernej Skrabec {
1001cf77d79bSJernej Skrabec struct device_node *remote;
1002cf77d79bSJernej Skrabec bool ret = false;
1003cf77d79bSJernej Skrabec
1004cf77d79bSJernej Skrabec remote = of_graph_get_remote_node(node, 0, -1);
1005cf77d79bSJernej Skrabec if (remote) {
1006185e0bebSMaxime Ripard ret = !!(IS_ENABLED(CONFIG_DRM_SUN8I_TCON_TOP) &&
1007185e0bebSMaxime Ripard of_match_node(sun8i_tcon_top_of_table, remote));
1008cf77d79bSJernej Skrabec of_node_put(remote);
1009cf77d79bSJernej Skrabec }
1010cf77d79bSJernej Skrabec
1011cf77d79bSJernej Skrabec return ret;
1012cf77d79bSJernej Skrabec }
1013cf77d79bSJernej Skrabec
sun4i_tcon_get_index(struct sun4i_drv * drv)1014cf77d79bSJernej Skrabec static int sun4i_tcon_get_index(struct sun4i_drv *drv)
1015cf77d79bSJernej Skrabec {
1016cf77d79bSJernej Skrabec struct list_head *pos;
1017cf77d79bSJernej Skrabec int size = 0;
1018cf77d79bSJernej Skrabec
1019cf77d79bSJernej Skrabec /*
1020cf77d79bSJernej Skrabec * Because TCON is added to the list at the end of the probe
1021cf77d79bSJernej Skrabec * (after this function is called), index of the current TCON
1022cf77d79bSJernej Skrabec * will be same as current TCON list size.
1023cf77d79bSJernej Skrabec */
1024cf77d79bSJernej Skrabec list_for_each(pos, &drv->tcon_list)
1025cf77d79bSJernej Skrabec ++size;
1026cf77d79bSJernej Skrabec
1027cf77d79bSJernej Skrabec return size;
1028cf77d79bSJernej Skrabec }
1029cf77d79bSJernej Skrabec
1030e8d5bbf7SChen-Yu Tsai /*
1031e8d5bbf7SChen-Yu Tsai * On SoCs with the old display pipeline design (Display Engine 1.0),
1032e8d5bbf7SChen-Yu Tsai * we assumed the TCON was always tied to just one backend. However
1033e8d5bbf7SChen-Yu Tsai * this proved not to be the case. On the A31, the TCON can select
1034e8d5bbf7SChen-Yu Tsai * either backend as its source. On the A20 (and likely on the A10),
1035e8d5bbf7SChen-Yu Tsai * the backend can choose which TCON to output to.
1036e8d5bbf7SChen-Yu Tsai *
1037e8d5bbf7SChen-Yu Tsai * The device tree binding says that the remote endpoint ID of any
1038e8d5bbf7SChen-Yu Tsai * connection between components, up to and including the TCON, of
1039e8d5bbf7SChen-Yu Tsai * the display pipeline should be equal to the actual ID of the local
1040e8d5bbf7SChen-Yu Tsai * component. Thus we should be able to look at any one of the input
1041e8d5bbf7SChen-Yu Tsai * connections of the TCONs, and use that connection's remote endpoint
1042e8d5bbf7SChen-Yu Tsai * ID as our own.
1043e8d5bbf7SChen-Yu Tsai *
1044e8d5bbf7SChen-Yu Tsai * However the connections between the backend and TCON were assumed
1045e8d5bbf7SChen-Yu Tsai * to be always singular, and their endpoit IDs were all incorrectly
1046e8d5bbf7SChen-Yu Tsai * set to 0. This means for these old device trees, we cannot just look
1047e8d5bbf7SChen-Yu Tsai * up the remote endpoint ID of a TCON input endpoint. TCON1 would be
1048e8d5bbf7SChen-Yu Tsai * incorrectly identified as TCON0.
1049e8d5bbf7SChen-Yu Tsai *
1050e8d5bbf7SChen-Yu Tsai * This function first checks if the TCON node has 2 input endpoints.
1051e8d5bbf7SChen-Yu Tsai * If so, then the device tree is a corrected version, and it will use
1052e8d5bbf7SChen-Yu Tsai * sun4i_tcon_of_get_id() and sun4i_tcon_get_engine_by_id() from above
1053e8d5bbf7SChen-Yu Tsai * to fetch the ID and engine directly. If not, then it is likely an
1054e8d5bbf7SChen-Yu Tsai * old device trees, where the endpoint IDs were incorrect, but did not
1055e8d5bbf7SChen-Yu Tsai * have endpoint connections between the backend and TCON across
1056e8d5bbf7SChen-Yu Tsai * different display pipelines. It will fall back to the old method of
1057e8d5bbf7SChen-Yu Tsai * traversing the of_graph to try and find a matching engine by device
1058e8d5bbf7SChen-Yu Tsai * node.
1059e8d5bbf7SChen-Yu Tsai *
1060e8d5bbf7SChen-Yu Tsai * In the case of single display pipeline device trees, either method
1061e8d5bbf7SChen-Yu Tsai * works.
1062e8d5bbf7SChen-Yu Tsai */
sun4i_tcon_find_engine(struct sun4i_drv * drv,struct device_node * node)1063e8d5bbf7SChen-Yu Tsai static struct sunxi_engine *sun4i_tcon_find_engine(struct sun4i_drv *drv,
1064e8d5bbf7SChen-Yu Tsai struct device_node *node)
1065e8d5bbf7SChen-Yu Tsai {
1066e8d5bbf7SChen-Yu Tsai struct device_node *port;
1067e8d5bbf7SChen-Yu Tsai struct sunxi_engine *engine;
1068e8d5bbf7SChen-Yu Tsai
1069e8d5bbf7SChen-Yu Tsai port = of_graph_get_port_by_id(node, 0);
1070e8d5bbf7SChen-Yu Tsai if (!port)
1071e8d5bbf7SChen-Yu Tsai return ERR_PTR(-EINVAL);
1072e8d5bbf7SChen-Yu Tsai
1073e8d5bbf7SChen-Yu Tsai /*
1074e8d5bbf7SChen-Yu Tsai * Is this a corrected device tree with cross pipeline
1075e8d5bbf7SChen-Yu Tsai * connections between the backend and TCON?
1076e8d5bbf7SChen-Yu Tsai */
1077e8d5bbf7SChen-Yu Tsai if (of_get_child_count(port) > 1) {
1078cf77d79bSJernej Skrabec int id;
1079cf77d79bSJernej Skrabec
1080cf77d79bSJernej Skrabec /*
1081cf77d79bSJernej Skrabec * When pipeline has the same number of TCONs and engines which
1082cf77d79bSJernej Skrabec * are represented by frontends/backends (DE1) or mixers (DE2),
1083cf77d79bSJernej Skrabec * we match them by their respective IDs. However, if pipeline
1084cf77d79bSJernej Skrabec * contains TCON TOP, chances are that there are either more
1085cf77d79bSJernej Skrabec * TCONs than engines (R40) or TCONs with non-consecutive ids.
1086cf77d79bSJernej Skrabec * (H6). In that case it's easier just use TCON index in list
1087cf77d79bSJernej Skrabec * as an id. That means that on R40, any 2 TCONs can be enabled
1088cf77d79bSJernej Skrabec * in DT out of 4 (there are 2 mixers). Due to the design of
1089cf77d79bSJernej Skrabec * TCON TOP, remaining 2 TCONs can't be connected to anything
1090cf77d79bSJernej Skrabec * anyway.
1091cf77d79bSJernej Skrabec */
1092cf77d79bSJernej Skrabec if (sun4i_tcon_connected_to_tcon_top(node))
1093cf77d79bSJernej Skrabec id = sun4i_tcon_get_index(drv);
1094cf77d79bSJernej Skrabec else
1095cf77d79bSJernej Skrabec id = sun4i_tcon_of_get_id_from_port(port);
1096e8d5bbf7SChen-Yu Tsai
1097e8d5bbf7SChen-Yu Tsai /* Get our engine by matching our ID */
1098e8d5bbf7SChen-Yu Tsai engine = sun4i_tcon_get_engine_by_id(drv, id);
1099e8d5bbf7SChen-Yu Tsai
1100e8d5bbf7SChen-Yu Tsai of_node_put(port);
1101e8d5bbf7SChen-Yu Tsai return engine;
1102e8d5bbf7SChen-Yu Tsai }
1103e8d5bbf7SChen-Yu Tsai
1104e8d5bbf7SChen-Yu Tsai /* Fallback to old method by traversing input endpoints */
1105e8d5bbf7SChen-Yu Tsai of_node_put(port);
110649836b11SJernej Skrabec return sun4i_tcon_find_engine_traverse(drv, node, 0);
1107e8d5bbf7SChen-Yu Tsai }
1108e8d5bbf7SChen-Yu Tsai
sun4i_tcon_bind(struct device * dev,struct device * master,void * data)11099026e0d1SMaxime Ripard static int sun4i_tcon_bind(struct device *dev, struct device *master,
11109026e0d1SMaxime Ripard void *data)
11119026e0d1SMaxime Ripard {
11129026e0d1SMaxime Ripard struct drm_device *drm = data;
11139026e0d1SMaxime Ripard struct sun4i_drv *drv = drm->dev_private;
111487969338SIcenowy Zheng struct sunxi_engine *engine;
1115a0c1214eSMaxime Ripard struct device_node *remote;
11169026e0d1SMaxime Ripard struct sun4i_tcon *tcon;
11176664e9dcSChen-Yu Tsai struct reset_control *edp_rstc;
1118a0c1214eSMaxime Ripard bool has_lvds_rst, has_lvds_alt, can_lvds;
11199026e0d1SMaxime Ripard int ret;
11209026e0d1SMaxime Ripard
112187969338SIcenowy Zheng engine = sun4i_tcon_find_engine(drv, dev->of_node);
112287969338SIcenowy Zheng if (IS_ERR(engine)) {
112387969338SIcenowy Zheng dev_err(dev, "Couldn't find matching engine\n");
112480a58240SChen-Yu Tsai return -EPROBE_DEFER;
1125b317fa3bSChen-Yu Tsai }
112680a58240SChen-Yu Tsai
11279026e0d1SMaxime Ripard tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL);
11289026e0d1SMaxime Ripard if (!tcon)
11299026e0d1SMaxime Ripard return -ENOMEM;
11309026e0d1SMaxime Ripard dev_set_drvdata(dev, tcon);
11319026e0d1SMaxime Ripard tcon->drm = drm;
1132ae558110SMaxime Ripard tcon->dev = dev;
113387969338SIcenowy Zheng tcon->id = engine->id;
113491ea2f29SChen-Yu Tsai tcon->quirks = of_device_get_match_data(dev);
11359026e0d1SMaxime Ripard
11369026e0d1SMaxime Ripard tcon->lcd_rst = devm_reset_control_get(dev, "lcd");
11379026e0d1SMaxime Ripard if (IS_ERR(tcon->lcd_rst)) {
11389026e0d1SMaxime Ripard dev_err(dev, "Couldn't get our reset line\n");
11399026e0d1SMaxime Ripard return PTR_ERR(tcon->lcd_rst);
11409026e0d1SMaxime Ripard }
11419026e0d1SMaxime Ripard
11426664e9dcSChen-Yu Tsai if (tcon->quirks->needs_edp_reset) {
11436664e9dcSChen-Yu Tsai edp_rstc = devm_reset_control_get_shared(dev, "edp");
11446664e9dcSChen-Yu Tsai if (IS_ERR(edp_rstc)) {
11456664e9dcSChen-Yu Tsai dev_err(dev, "Couldn't get edp reset line\n");
11466664e9dcSChen-Yu Tsai return PTR_ERR(edp_rstc);
11476664e9dcSChen-Yu Tsai }
11486664e9dcSChen-Yu Tsai
11496664e9dcSChen-Yu Tsai ret = reset_control_deassert(edp_rstc);
11506664e9dcSChen-Yu Tsai if (ret) {
11516664e9dcSChen-Yu Tsai dev_err(dev, "Couldn't deassert edp reset line\n");
11526664e9dcSChen-Yu Tsai return ret;
11536664e9dcSChen-Yu Tsai }
11546664e9dcSChen-Yu Tsai }
11556664e9dcSChen-Yu Tsai
11569026e0d1SMaxime Ripard /* Make sure our TCON is reset */
1157d57294c1SChen-Yu Tsai ret = reset_control_reset(tcon->lcd_rst);
11589026e0d1SMaxime Ripard if (ret) {
11599026e0d1SMaxime Ripard dev_err(dev, "Couldn't deassert our reset line\n");
11609026e0d1SMaxime Ripard return ret;
11619026e0d1SMaxime Ripard }
11629026e0d1SMaxime Ripard
1163e742a17cSMaxime Ripard if (tcon->quirks->supports_lvds) {
1164a0c1214eSMaxime Ripard /*
1165e742a17cSMaxime Ripard * This can only be made optional since we've had DT
1166e742a17cSMaxime Ripard * nodes without the LVDS reset properties.
1167a0c1214eSMaxime Ripard *
1168e742a17cSMaxime Ripard * If the property is missing, just disable LVDS, and
1169e742a17cSMaxime Ripard * print a warning.
1170a0c1214eSMaxime Ripard */
1171a0c1214eSMaxime Ripard tcon->lvds_rst = devm_reset_control_get_optional(dev, "lvds");
1172a0c1214eSMaxime Ripard if (IS_ERR(tcon->lvds_rst)) {
1173a0c1214eSMaxime Ripard dev_err(dev, "Couldn't get our reset line\n");
1174a0c1214eSMaxime Ripard return PTR_ERR(tcon->lvds_rst);
1175a0c1214eSMaxime Ripard } else if (tcon->lvds_rst) {
1176a0c1214eSMaxime Ripard has_lvds_rst = true;
1177a0c1214eSMaxime Ripard reset_control_reset(tcon->lvds_rst);
1178a0c1214eSMaxime Ripard } else {
1179a0c1214eSMaxime Ripard has_lvds_rst = false;
1180a0c1214eSMaxime Ripard }
1181a0c1214eSMaxime Ripard
1182a0c1214eSMaxime Ripard /*
1183e742a17cSMaxime Ripard * This can only be made optional since we've had DT
1184e742a17cSMaxime Ripard * nodes without the LVDS reset properties.
1185a0c1214eSMaxime Ripard *
1186e742a17cSMaxime Ripard * If the property is missing, just disable LVDS, and
1187e742a17cSMaxime Ripard * print a warning.
1188a0c1214eSMaxime Ripard */
1189a0c1214eSMaxime Ripard if (tcon->quirks->has_lvds_alt) {
1190a0c1214eSMaxime Ripard tcon->lvds_pll = devm_clk_get(dev, "lvds-alt");
1191a0c1214eSMaxime Ripard if (IS_ERR(tcon->lvds_pll)) {
1192a0c1214eSMaxime Ripard if (PTR_ERR(tcon->lvds_pll) == -ENOENT) {
1193a0c1214eSMaxime Ripard has_lvds_alt = false;
1194a0c1214eSMaxime Ripard } else {
1195a0c1214eSMaxime Ripard dev_err(dev, "Couldn't get the LVDS PLL\n");
119686a3ae58SDan Carpenter return PTR_ERR(tcon->lvds_pll);
1197a0c1214eSMaxime Ripard }
1198a0c1214eSMaxime Ripard } else {
1199a0c1214eSMaxime Ripard has_lvds_alt = true;
1200a0c1214eSMaxime Ripard }
1201a0c1214eSMaxime Ripard }
1202a0c1214eSMaxime Ripard
1203e742a17cSMaxime Ripard if (!has_lvds_rst ||
1204e742a17cSMaxime Ripard (tcon->quirks->has_lvds_alt && !has_lvds_alt)) {
1205e742a17cSMaxime Ripard dev_warn(dev, "Missing LVDS properties, Please upgrade your DT\n");
1206a0c1214eSMaxime Ripard dev_warn(dev, "LVDS output disabled\n");
1207a0c1214eSMaxime Ripard can_lvds = false;
1208a0c1214eSMaxime Ripard } else {
1209a0c1214eSMaxime Ripard can_lvds = true;
1210a0c1214eSMaxime Ripard }
1211e742a17cSMaxime Ripard } else {
1212e742a17cSMaxime Ripard can_lvds = false;
1213e742a17cSMaxime Ripard }
1214a0c1214eSMaxime Ripard
12159026e0d1SMaxime Ripard ret = sun4i_tcon_init_clocks(dev, tcon);
12169026e0d1SMaxime Ripard if (ret) {
12179026e0d1SMaxime Ripard dev_err(dev, "Couldn't init our TCON clocks\n");
12189026e0d1SMaxime Ripard goto err_assert_reset;
12199026e0d1SMaxime Ripard }
12209026e0d1SMaxime Ripard
12214c7f16d1SChen-Yu Tsai ret = sun4i_tcon_init_regmap(dev, tcon);
12229026e0d1SMaxime Ripard if (ret) {
12234c7f16d1SChen-Yu Tsai dev_err(dev, "Couldn't init our TCON regmap\n");
1224123ee07bSXuDong Liu goto err_assert_reset;
12259026e0d1SMaxime Ripard }
12269026e0d1SMaxime Ripard
122734d698f6SJernej Skrabec if (tcon->quirks->has_channel_0) {
12284c7f16d1SChen-Yu Tsai ret = sun4i_dclk_create(dev, tcon);
12294c7f16d1SChen-Yu Tsai if (ret) {
12304c7f16d1SChen-Yu Tsai dev_err(dev, "Couldn't create our TCON dot clock\n");
1231123ee07bSXuDong Liu goto err_assert_reset;
12324c7f16d1SChen-Yu Tsai }
123334d698f6SJernej Skrabec }
12344c7f16d1SChen-Yu Tsai
12359026e0d1SMaxime Ripard ret = sun4i_tcon_init_irq(dev, tcon);
12369026e0d1SMaxime Ripard if (ret) {
12379026e0d1SMaxime Ripard dev_err(dev, "Couldn't init our TCON interrupts\n");
123871ffeafbSRoman Beranek goto err_free_dclk;
12399026e0d1SMaxime Ripard }
12409026e0d1SMaxime Ripard
124187969338SIcenowy Zheng tcon->crtc = sun4i_crtc_init(drm, engine, tcon);
124246cce6daSChen-Yu Tsai if (IS_ERR(tcon->crtc)) {
124346cce6daSChen-Yu Tsai dev_err(dev, "Couldn't create our CRTC\n");
124446cce6daSChen-Yu Tsai ret = PTR_ERR(tcon->crtc);
124571ffeafbSRoman Beranek goto err_free_dclk;
124646cce6daSChen-Yu Tsai }
124746cce6daSChen-Yu Tsai
12482a72d0c5SJernej Skrabec if (tcon->quirks->has_channel_0) {
1249a0c1214eSMaxime Ripard /*
1250a0c1214eSMaxime Ripard * If we have an LVDS panel connected to the TCON, we should
1251a0c1214eSMaxime Ripard * just probe the LVDS connector. Otherwise, just probe RGB as
1252a0c1214eSMaxime Ripard * we used to.
1253a0c1214eSMaxime Ripard */
1254a0c1214eSMaxime Ripard remote = of_graph_get_remote_node(dev->of_node, 1, 0);
1255a0c1214eSMaxime Ripard if (of_device_is_compatible(remote, "panel-lvds"))
1256a0c1214eSMaxime Ripard if (can_lvds)
1257a0c1214eSMaxime Ripard ret = sun4i_lvds_init(drm, tcon);
1258a0c1214eSMaxime Ripard else
1259a0c1214eSMaxime Ripard ret = -EINVAL;
1260a0c1214eSMaxime Ripard else
1261b9c8506cSChen-Yu Tsai ret = sun4i_rgb_init(drm, tcon);
1262a0c1214eSMaxime Ripard of_node_put(remote);
1263a0c1214eSMaxime Ripard
126413fef095SChen-Yu Tsai if (ret < 0)
126571ffeafbSRoman Beranek goto err_free_dclk;
12662a72d0c5SJernej Skrabec }
126713fef095SChen-Yu Tsai
126827e18de7SChen-Yu Tsai if (tcon->quirks->needs_de_be_mux) {
126927e18de7SChen-Yu Tsai /*
127027e18de7SChen-Yu Tsai * We assume there is no dynamic muxing of backends
127127e18de7SChen-Yu Tsai * and TCONs, so we select the backend with same ID.
127227e18de7SChen-Yu Tsai *
127327e18de7SChen-Yu Tsai * While dynamic selection might be interesting, since
127427e18de7SChen-Yu Tsai * the CRTC is tied to the TCON, while the layers are
127527e18de7SChen-Yu Tsai * tied to the backends, this means, we will need to
127627e18de7SChen-Yu Tsai * switch between groups of layers. There might not be
127727e18de7SChen-Yu Tsai * a way to represent this constraint in DRM.
127827e18de7SChen-Yu Tsai */
127927e18de7SChen-Yu Tsai regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG,
128027e18de7SChen-Yu Tsai SUN4I_TCON0_CTL_SRC_SEL_MASK,
128127e18de7SChen-Yu Tsai tcon->id);
128227e18de7SChen-Yu Tsai regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG,
128327e18de7SChen-Yu Tsai SUN4I_TCON1_CTL_SRC_SEL_MASK,
128427e18de7SChen-Yu Tsai tcon->id);
128527e18de7SChen-Yu Tsai }
128627e18de7SChen-Yu Tsai
128780a58240SChen-Yu Tsai list_add_tail(&tcon->list, &drv->tcon_list);
128880a58240SChen-Yu Tsai
128913fef095SChen-Yu Tsai return 0;
12909026e0d1SMaxime Ripard
129171ffeafbSRoman Beranek err_free_dclk:
129234d698f6SJernej Skrabec if (tcon->quirks->has_channel_0)
12934c7f16d1SChen-Yu Tsai sun4i_dclk_free(tcon);
12949026e0d1SMaxime Ripard err_assert_reset:
12959026e0d1SMaxime Ripard reset_control_assert(tcon->lcd_rst);
12969026e0d1SMaxime Ripard return ret;
12979026e0d1SMaxime Ripard }
12989026e0d1SMaxime Ripard
sun4i_tcon_unbind(struct device * dev,struct device * master,void * data)12999026e0d1SMaxime Ripard static void sun4i_tcon_unbind(struct device *dev, struct device *master,
13009026e0d1SMaxime Ripard void *data)
13019026e0d1SMaxime Ripard {
13029026e0d1SMaxime Ripard struct sun4i_tcon *tcon = dev_get_drvdata(dev);
13039026e0d1SMaxime Ripard
130480a58240SChen-Yu Tsai list_del(&tcon->list);
130534d698f6SJernej Skrabec if (tcon->quirks->has_channel_0)
13064c7f16d1SChen-Yu Tsai sun4i_dclk_free(tcon);
13079026e0d1SMaxime Ripard }
13089026e0d1SMaxime Ripard
1309dfeb693dSJulia Lawall static const struct component_ops sun4i_tcon_ops = {
13109026e0d1SMaxime Ripard .bind = sun4i_tcon_bind,
13119026e0d1SMaxime Ripard .unbind = sun4i_tcon_unbind,
13129026e0d1SMaxime Ripard };
13139026e0d1SMaxime Ripard
sun4i_tcon_probe(struct platform_device * pdev)13149026e0d1SMaxime Ripard static int sun4i_tcon_probe(struct platform_device *pdev)
13159026e0d1SMaxime Ripard {
131629e57fabSMaxime Ripard struct device_node *node = pdev->dev.of_node;
131763d6310fSJernej Skrabec const struct sun4i_tcon_quirks *quirks;
1318894f5a9fSMaxime Ripard struct drm_bridge *bridge;
131929e57fabSMaxime Ripard struct drm_panel *panel;
1320ebc94461SRob Herring int ret;
132129e57fabSMaxime Ripard
132263d6310fSJernej Skrabec quirks = of_device_get_match_data(&pdev->dev);
132363d6310fSJernej Skrabec
132463d6310fSJernej Skrabec /* panels and bridges are present only on TCONs with channel 0 */
132563d6310fSJernej Skrabec if (quirks->has_channel_0) {
1326ebc94461SRob Herring ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge);
1327ebc94461SRob Herring if (ret == -EPROBE_DEFER)
1328ebc94461SRob Herring return ret;
132963d6310fSJernej Skrabec }
133029e57fabSMaxime Ripard
13319026e0d1SMaxime Ripard return component_add(&pdev->dev, &sun4i_tcon_ops);
13329026e0d1SMaxime Ripard }
13339026e0d1SMaxime Ripard
sun4i_tcon_remove(struct platform_device * pdev)1334d665e3c9SUwe Kleine-König static void sun4i_tcon_remove(struct platform_device *pdev)
13359026e0d1SMaxime Ripard {
13369026e0d1SMaxime Ripard component_del(&pdev->dev, &sun4i_tcon_ops);
13379026e0d1SMaxime Ripard }
13389026e0d1SMaxime Ripard
1339ad537fb2SChen-Yu Tsai /* platform specific TCON muxing callbacks */
sun4i_a10_tcon_set_mux(struct sun4i_tcon * tcon,const struct drm_encoder * encoder)13404bb206bfSJonathan Liu static int sun4i_a10_tcon_set_mux(struct sun4i_tcon *tcon,
13414bb206bfSJonathan Liu const struct drm_encoder *encoder)
13424bb206bfSJonathan Liu {
13434bb206bfSJonathan Liu struct sun4i_tcon *tcon0 = sun4i_get_tcon0(encoder->dev);
13444bb206bfSJonathan Liu u32 shift;
13454bb206bfSJonathan Liu
13464bb206bfSJonathan Liu if (!tcon0)
13474bb206bfSJonathan Liu return -EINVAL;
13484bb206bfSJonathan Liu
13494bb206bfSJonathan Liu switch (encoder->encoder_type) {
13504bb206bfSJonathan Liu case DRM_MODE_ENCODER_TMDS:
13514bb206bfSJonathan Liu /* HDMI */
13524bb206bfSJonathan Liu shift = 8;
13534bb206bfSJonathan Liu break;
13544bb206bfSJonathan Liu default:
13554bb206bfSJonathan Liu return -EINVAL;
13564bb206bfSJonathan Liu }
13574bb206bfSJonathan Liu
13584bb206bfSJonathan Liu regmap_update_bits(tcon0->regs, SUN4I_TCON_MUX_CTRL_REG,
13594bb206bfSJonathan Liu 0x3 << shift, tcon->id << shift);
13604bb206bfSJonathan Liu
13614bb206bfSJonathan Liu return 0;
13624bb206bfSJonathan Liu }
13634bb206bfSJonathan Liu
sun5i_a13_tcon_set_mux(struct sun4i_tcon * tcon,const struct drm_encoder * encoder)1364ad537fb2SChen-Yu Tsai static int sun5i_a13_tcon_set_mux(struct sun4i_tcon *tcon,
1365abcb8766SMaxime Ripard const struct drm_encoder *encoder)
1366ad537fb2SChen-Yu Tsai {
1367ad537fb2SChen-Yu Tsai u32 val;
1368ad537fb2SChen-Yu Tsai
1369ad537fb2SChen-Yu Tsai if (encoder->encoder_type == DRM_MODE_ENCODER_TVDAC)
1370ad537fb2SChen-Yu Tsai val = 1;
1371ad537fb2SChen-Yu Tsai else
1372ad537fb2SChen-Yu Tsai val = 0;
1373ad537fb2SChen-Yu Tsai
1374ad537fb2SChen-Yu Tsai /*
1375ad537fb2SChen-Yu Tsai * FIXME: Undocumented bits
1376ad537fb2SChen-Yu Tsai */
1377ad537fb2SChen-Yu Tsai return regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, val);
1378ad537fb2SChen-Yu Tsai }
1379ad537fb2SChen-Yu Tsai
sun6i_tcon_set_mux(struct sun4i_tcon * tcon,const struct drm_encoder * encoder)138067e32645SChen-Yu Tsai static int sun6i_tcon_set_mux(struct sun4i_tcon *tcon,
1381abcb8766SMaxime Ripard const struct drm_encoder *encoder)
138267e32645SChen-Yu Tsai {
138367e32645SChen-Yu Tsai struct sun4i_tcon *tcon0 = sun4i_get_tcon0(encoder->dev);
138467e32645SChen-Yu Tsai u32 shift;
138567e32645SChen-Yu Tsai
138667e32645SChen-Yu Tsai if (!tcon0)
138767e32645SChen-Yu Tsai return -EINVAL;
138867e32645SChen-Yu Tsai
138967e32645SChen-Yu Tsai switch (encoder->encoder_type) {
139067e32645SChen-Yu Tsai case DRM_MODE_ENCODER_TMDS:
139167e32645SChen-Yu Tsai /* HDMI */
139267e32645SChen-Yu Tsai shift = 8;
139367e32645SChen-Yu Tsai break;
139467e32645SChen-Yu Tsai default:
139567e32645SChen-Yu Tsai /* TODO A31 has MIPI DSI but A31s does not */
139667e32645SChen-Yu Tsai return -EINVAL;
139767e32645SChen-Yu Tsai }
139867e32645SChen-Yu Tsai
139967e32645SChen-Yu Tsai regmap_update_bits(tcon0->regs, SUN4I_TCON_MUX_CTRL_REG,
140067e32645SChen-Yu Tsai 0x3 << shift, tcon->id << shift);
140167e32645SChen-Yu Tsai
140267e32645SChen-Yu Tsai return 0;
140367e32645SChen-Yu Tsai }
140467e32645SChen-Yu Tsai
sun8i_r40_tcon_tv_set_mux(struct sun4i_tcon * tcon,const struct drm_encoder * encoder)14050305189aSJernej Skrabec static int sun8i_r40_tcon_tv_set_mux(struct sun4i_tcon *tcon,
14060305189aSJernej Skrabec const struct drm_encoder *encoder)
14070305189aSJernej Skrabec {
14080305189aSJernej Skrabec struct device_node *port, *remote;
14090305189aSJernej Skrabec struct platform_device *pdev;
14100305189aSJernej Skrabec int id, ret;
14110305189aSJernej Skrabec
14120305189aSJernej Skrabec /* find TCON TOP platform device and TCON id */
14130305189aSJernej Skrabec
14140305189aSJernej Skrabec port = of_graph_get_port_by_id(tcon->dev->of_node, 0);
14150305189aSJernej Skrabec if (!port)
14160305189aSJernej Skrabec return -EINVAL;
14170305189aSJernej Skrabec
14180305189aSJernej Skrabec id = sun4i_tcon_of_get_id_from_port(port);
14190305189aSJernej Skrabec of_node_put(port);
14200305189aSJernej Skrabec
14210305189aSJernej Skrabec remote = of_graph_get_remote_node(tcon->dev->of_node, 0, -1);
14220305189aSJernej Skrabec if (!remote)
14230305189aSJernej Skrabec return -EINVAL;
14240305189aSJernej Skrabec
14250305189aSJernej Skrabec pdev = of_find_device_by_node(remote);
14260305189aSJernej Skrabec of_node_put(remote);
14270305189aSJernej Skrabec if (!pdev)
14280305189aSJernej Skrabec return -EINVAL;
14290305189aSJernej Skrabec
1430185e0bebSMaxime Ripard if (IS_ENABLED(CONFIG_DRM_SUN8I_TCON_TOP) &&
1431185e0bebSMaxime Ripard encoder->encoder_type == DRM_MODE_ENCODER_TMDS) {
14320305189aSJernej Skrabec ret = sun8i_tcon_top_set_hdmi_src(&pdev->dev, id);
143307b5b12dSYu Kuai if (ret) {
143407b5b12dSYu Kuai put_device(&pdev->dev);
14350305189aSJernej Skrabec return ret;
14360305189aSJernej Skrabec }
143707b5b12dSYu Kuai }
14380305189aSJernej Skrabec
1439185e0bebSMaxime Ripard if (IS_ENABLED(CONFIG_DRM_SUN8I_TCON_TOP)) {
1440185e0bebSMaxime Ripard ret = sun8i_tcon_top_de_config(&pdev->dev, tcon->id, id);
144107b5b12dSYu Kuai if (ret) {
144207b5b12dSYu Kuai put_device(&pdev->dev);
1443185e0bebSMaxime Ripard return ret;
1444185e0bebSMaxime Ripard }
144507b5b12dSYu Kuai }
1446185e0bebSMaxime Ripard
1447185e0bebSMaxime Ripard return 0;
14480305189aSJernej Skrabec }
14490305189aSJernej Skrabec
14504bb206bfSJonathan Liu static const struct sun4i_tcon_quirks sun4i_a10_quirks = {
145134d698f6SJernej Skrabec .has_channel_0 = true,
14524bb206bfSJonathan Liu .has_channel_1 = true,
14534396393fSChen-Yu Tsai .dclk_min_div = 4,
14544bb206bfSJonathan Liu .set_mux = sun4i_a10_tcon_set_mux,
14554bb206bfSJonathan Liu };
14564bb206bfSJonathan Liu
145791ea2f29SChen-Yu Tsai static const struct sun4i_tcon_quirks sun5i_a13_quirks = {
145834d698f6SJernej Skrabec .has_channel_0 = true,
145991ea2f29SChen-Yu Tsai .has_channel_1 = true,
14604396393fSChen-Yu Tsai .dclk_min_div = 4,
1461ad537fb2SChen-Yu Tsai .set_mux = sun5i_a13_tcon_set_mux,
146291ea2f29SChen-Yu Tsai };
146391ea2f29SChen-Yu Tsai
146493a5ec14SChen-Yu Tsai static const struct sun4i_tcon_quirks sun6i_a31_quirks = {
146534d698f6SJernej Skrabec .has_channel_0 = true,
146693a5ec14SChen-Yu Tsai .has_channel_1 = true,
1467a0c1214eSMaxime Ripard .has_lvds_alt = true,
146827e18de7SChen-Yu Tsai .needs_de_be_mux = true,
14694396393fSChen-Yu Tsai .dclk_min_div = 1,
147067e32645SChen-Yu Tsai .set_mux = sun6i_tcon_set_mux,
147193a5ec14SChen-Yu Tsai };
147293a5ec14SChen-Yu Tsai
147393a5ec14SChen-Yu Tsai static const struct sun4i_tcon_quirks sun6i_a31s_quirks = {
147434d698f6SJernej Skrabec .has_channel_0 = true,
147593a5ec14SChen-Yu Tsai .has_channel_1 = true,
147627e18de7SChen-Yu Tsai .needs_de_be_mux = true,
14774396393fSChen-Yu Tsai .dclk_min_div = 1,
147893a5ec14SChen-Yu Tsai };
147993a5ec14SChen-Yu Tsai
1480d718e53aSAndrey Lebedev static const struct sun4i_tcon_quirks sun7i_a20_tcon0_quirks = {
1481d718e53aSAndrey Lebedev .supports_lvds = true,
1482d718e53aSAndrey Lebedev .has_channel_0 = true,
1483d718e53aSAndrey Lebedev .has_channel_1 = true,
1484d718e53aSAndrey Lebedev .dclk_min_div = 4,
1485d718e53aSAndrey Lebedev /* Same display pipeline structure as A10 */
1486d718e53aSAndrey Lebedev .set_mux = sun4i_a10_tcon_set_mux,
1487d718e53aSAndrey Lebedev .setup_lvds_phy = sun4i_tcon_setup_lvds_phy,
1488d718e53aSAndrey Lebedev };
1489d718e53aSAndrey Lebedev
1490aaddb6d2SJonathan Liu static const struct sun4i_tcon_quirks sun7i_a20_quirks = {
149134d698f6SJernej Skrabec .has_channel_0 = true,
1492aaddb6d2SJonathan Liu .has_channel_1 = true,
14934396393fSChen-Yu Tsai .dclk_min_div = 4,
1494aaddb6d2SJonathan Liu /* Same display pipeline structure as A10 */
1495aaddb6d2SJonathan Liu .set_mux = sun4i_a10_tcon_set_mux,
1496aaddb6d2SJonathan Liu };
1497aaddb6d2SJonathan Liu
149891ea2f29SChen-Yu Tsai static const struct sun4i_tcon_quirks sun8i_a33_quirks = {
149934d698f6SJernej Skrabec .has_channel_0 = true,
1500a0c1214eSMaxime Ripard .has_lvds_alt = true,
15014396393fSChen-Yu Tsai .dclk_min_div = 1,
15025627c9d8SAndrey Lebedev .setup_lvds_phy = sun6i_tcon_setup_lvds_phy,
1503cf650f2cSMaxime Ripard .supports_lvds = true,
150491ea2f29SChen-Yu Tsai };
150591ea2f29SChen-Yu Tsai
15062f0d7bb1SMaxime Ripard static const struct sun4i_tcon_quirks sun8i_a83t_lcd_quirks = {
1507e742a17cSMaxime Ripard .supports_lvds = true,
150834d698f6SJernej Skrabec .has_channel_0 = true,
15094396393fSChen-Yu Tsai .dclk_min_div = 1,
15105627c9d8SAndrey Lebedev .setup_lvds_phy = sun6i_tcon_setup_lvds_phy,
15112f0d7bb1SMaxime Ripard };
15122f0d7bb1SMaxime Ripard
151305adc89bSJernej Skrabec static const struct sun4i_tcon_quirks sun8i_a83t_tv_quirks = {
151405adc89bSJernej Skrabec .has_channel_1 = true,
151505adc89bSJernej Skrabec };
151605adc89bSJernej Skrabec
15170305189aSJernej Skrabec static const struct sun4i_tcon_quirks sun8i_r40_tv_quirks = {
15180305189aSJernej Skrabec .has_channel_1 = true,
151950791f5dSJernej Skrabec .polarity_in_ch0 = true,
15200305189aSJernej Skrabec .set_mux = sun8i_r40_tcon_tv_set_mux,
15210305189aSJernej Skrabec };
15220305189aSJernej Skrabec
15231a0edb3fSIcenowy Zheng static const struct sun4i_tcon_quirks sun8i_v3s_quirks = {
152434d698f6SJernej Skrabec .has_channel_0 = true,
15254396393fSChen-Yu Tsai .dclk_min_div = 1,
15261a0edb3fSIcenowy Zheng };
15271a0edb3fSIcenowy Zheng
15286664e9dcSChen-Yu Tsai static const struct sun4i_tcon_quirks sun9i_a80_tcon_lcd_quirks = {
15296664e9dcSChen-Yu Tsai .has_channel_0 = true,
15306664e9dcSChen-Yu Tsai .needs_edp_reset = true,
15314396393fSChen-Yu Tsai .dclk_min_div = 1,
15326664e9dcSChen-Yu Tsai };
15336664e9dcSChen-Yu Tsai
15346664e9dcSChen-Yu Tsai static const struct sun4i_tcon_quirks sun9i_a80_tcon_tv_quirks = {
15356664e9dcSChen-Yu Tsai .has_channel_1 = true,
15366664e9dcSChen-Yu Tsai .needs_edp_reset = true,
15376664e9dcSChen-Yu Tsai };
15386664e9dcSChen-Yu Tsai
1539b9b52d2fSSamuel Holland static const struct sun4i_tcon_quirks sun20i_d1_lcd_quirks = {
1540b9b52d2fSSamuel Holland .has_channel_0 = true,
1541b9b52d2fSSamuel Holland .dclk_min_div = 1,
1542b9b52d2fSSamuel Holland .set_mux = sun8i_r40_tcon_tv_set_mux,
1543b9b52d2fSSamuel Holland };
1544b9b52d2fSSamuel Holland
1545ff71c2cfSChen-Yu Tsai /* sun4i_drv uses this list to check if a device node is a TCON */
1546ff71c2cfSChen-Yu Tsai const struct of_device_id sun4i_tcon_of_table[] = {
15474bb206bfSJonathan Liu { .compatible = "allwinner,sun4i-a10-tcon", .data = &sun4i_a10_quirks },
154891ea2f29SChen-Yu Tsai { .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks },
154993a5ec14SChen-Yu Tsai { .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks },
155093a5ec14SChen-Yu Tsai { .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks },
1551aaddb6d2SJonathan Liu { .compatible = "allwinner,sun7i-a20-tcon", .data = &sun7i_a20_quirks },
1552d718e53aSAndrey Lebedev { .compatible = "allwinner,sun7i-a20-tcon0", .data = &sun7i_a20_tcon0_quirks },
1553cd0ecabdSAndrey Lebedev { .compatible = "allwinner,sun7i-a20-tcon1", .data = &sun7i_a20_quirks },
1554d0ec0a3eSChen-Yu Tsai { .compatible = "allwinner,sun8i-a23-tcon", .data = &sun8i_a33_quirks },
155591ea2f29SChen-Yu Tsai { .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks },
15562f0d7bb1SMaxime Ripard { .compatible = "allwinner,sun8i-a83t-tcon-lcd", .data = &sun8i_a83t_lcd_quirks },
155705adc89bSJernej Skrabec { .compatible = "allwinner,sun8i-a83t-tcon-tv", .data = &sun8i_a83t_tv_quirks },
15580305189aSJernej Skrabec { .compatible = "allwinner,sun8i-r40-tcon-tv", .data = &sun8i_r40_tv_quirks },
15591a0edb3fSIcenowy Zheng { .compatible = "allwinner,sun8i-v3s-tcon", .data = &sun8i_v3s_quirks },
15606664e9dcSChen-Yu Tsai { .compatible = "allwinner,sun9i-a80-tcon-lcd", .data = &sun9i_a80_tcon_lcd_quirks },
15616664e9dcSChen-Yu Tsai { .compatible = "allwinner,sun9i-a80-tcon-tv", .data = &sun9i_a80_tcon_tv_quirks },
1562b9b52d2fSSamuel Holland { .compatible = "allwinner,sun20i-d1-tcon-lcd", .data = &sun20i_d1_lcd_quirks },
1563b9b52d2fSSamuel Holland { .compatible = "allwinner,sun20i-d1-tcon-tv", .data = &sun8i_r40_tv_quirks },
15649026e0d1SMaxime Ripard { }
15659026e0d1SMaxime Ripard };
15669026e0d1SMaxime Ripard MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table);
1567ff71c2cfSChen-Yu Tsai EXPORT_SYMBOL(sun4i_tcon_of_table);
15689026e0d1SMaxime Ripard
15699026e0d1SMaxime Ripard static struct platform_driver sun4i_tcon_platform_driver = {
15709026e0d1SMaxime Ripard .probe = sun4i_tcon_probe,
1571d665e3c9SUwe Kleine-König .remove_new = sun4i_tcon_remove,
15729026e0d1SMaxime Ripard .driver = {
15739026e0d1SMaxime Ripard .name = "sun4i-tcon",
15749026e0d1SMaxime Ripard .of_match_table = sun4i_tcon_of_table,
15759026e0d1SMaxime Ripard },
15769026e0d1SMaxime Ripard };
15779026e0d1SMaxime Ripard module_platform_driver(sun4i_tcon_platform_driver);
15789026e0d1SMaxime Ripard
15799026e0d1SMaxime Ripard MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>");
15809026e0d1SMaxime Ripard MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver");
15819026e0d1SMaxime Ripard MODULE_LICENSE("GPL");
1582