Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 Free Electrons |
| 3 | * Copyright (C) 2015 NextThing Co |
| 4 | * |
| 5 | * Maxime Ripard <maxime.ripard@free-electrons.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <drm/drmP.h> |
| 14 | #include <drm/drm_atomic_helper.h> |
| 15 | #include <drm/drm_crtc.h> |
| 16 | #include <drm/drm_crtc_helper.h> |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 17 | #include <drm/drm_encoder.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 18 | #include <drm/drm_modes.h> |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 19 | #include <drm/drm_of.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 20 | |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 21 | #include <uapi/drm/drm_mode.h> |
| 22 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 23 | #include <linux/component.h> |
| 24 | #include <linux/ioport.h> |
| 25 | #include <linux/of_address.h> |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 26 | #include <linux/of_device.h> |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 27 | #include <linux/of_irq.h> |
| 28 | #include <linux/regmap.h> |
| 29 | #include <linux/reset.h> |
| 30 | |
| 31 | #include "sun4i_crtc.h" |
| 32 | #include "sun4i_dotclock.h" |
| 33 | #include "sun4i_drv.h" |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 34 | #include "sun4i_rgb.h" |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 35 | #include "sun4i_tcon.h" |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 36 | #include "sunxi_engine.h" |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 37 | |
Maxime Ripard | 45e88f9 | 2017-10-17 11:06:12 +0200 | [diff] [blame^] | 38 | static void sun4i_tcon_channel_set_status(struct sun4i_tcon *tcon, int channel, |
| 39 | bool enabled) |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 40 | { |
Maxime Ripard | 45e88f9 | 2017-10-17 11:06:12 +0200 | [diff] [blame^] | 41 | struct clk *clk; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 42 | |
Maxime Ripard | 45e88f9 | 2017-10-17 11:06:12 +0200 | [diff] [blame^] | 43 | switch (channel) { |
| 44 | case 0: |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 45 | regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, |
| 46 | SUN4I_TCON0_CTL_TCON_ENABLE, |
Maxime Ripard | 45e88f9 | 2017-10-17 11:06:12 +0200 | [diff] [blame^] | 47 | enabled ? SUN4I_TCON0_CTL_TCON_ENABLE : 0); |
| 48 | clk = tcon->dclk; |
| 49 | break; |
| 50 | case 1: |
| 51 | WARN_ON(!tcon->quirks->has_channel_1); |
| 52 | regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, |
| 53 | SUN4I_TCON1_CTL_TCON_ENABLE, |
| 54 | enabled ? SUN4I_TCON1_CTL_TCON_ENABLE : 0); |
| 55 | clk = tcon->sclk1; |
| 56 | break; |
| 57 | default: |
| 58 | DRM_WARN("Unknown channel... doing nothing\n"); |
Maxime Ripard | 8e92404 | 2016-01-07 12:32:07 +0100 | [diff] [blame] | 59 | return; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 60 | } |
Maxime Ripard | 8e92404 | 2016-01-07 12:32:07 +0100 | [diff] [blame] | 61 | |
Maxime Ripard | 45e88f9 | 2017-10-17 11:06:12 +0200 | [diff] [blame^] | 62 | if (enabled) |
| 63 | clk_prepare_enable(clk); |
| 64 | else |
| 65 | clk_disable_unprepare(clk); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 66 | } |
Maxime Ripard | 45e88f9 | 2017-10-17 11:06:12 +0200 | [diff] [blame^] | 67 | |
| 68 | void sun4i_tcon_set_status(struct sun4i_tcon *tcon, |
| 69 | const struct drm_encoder *encoder, |
| 70 | bool enabled) |
| 71 | { |
| 72 | int channel; |
| 73 | |
| 74 | switch (encoder->encoder_type) { |
| 75 | case DRM_MODE_ENCODER_NONE: |
| 76 | channel = 0; |
| 77 | break; |
| 78 | case DRM_MODE_ENCODER_TMDS: |
| 79 | case DRM_MODE_ENCODER_TVDAC: |
| 80 | channel = 1; |
| 81 | break; |
| 82 | default: |
| 83 | DRM_DEBUG_DRIVER("Unknown encoder type, doing nothing...\n"); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, |
| 88 | SUN4I_TCON_GCTL_TCON_ENABLE, |
| 89 | enabled ? SUN4I_TCON_GCTL_TCON_ENABLE : 0); |
| 90 | |
| 91 | sun4i_tcon_channel_set_status(tcon, channel, enabled); |
| 92 | } |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 93 | |
| 94 | void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable) |
| 95 | { |
| 96 | u32 mask, val = 0; |
| 97 | |
| 98 | DRM_DEBUG_DRIVER("%sabling VBLANK interrupt\n", enable ? "En" : "Dis"); |
| 99 | |
| 100 | mask = SUN4I_TCON_GINT0_VBLANK_ENABLE(0) | |
| 101 | SUN4I_TCON_GINT0_VBLANK_ENABLE(1); |
| 102 | |
| 103 | if (enable) |
| 104 | val = mask; |
| 105 | |
| 106 | regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val); |
| 107 | } |
| 108 | EXPORT_SYMBOL(sun4i_tcon_enable_vblank); |
| 109 | |
Chen-Yu Tsai | 67e3264 | 2017-10-10 11:19:59 +0800 | [diff] [blame] | 110 | /* |
| 111 | * This function is a helper for TCON output muxing. The TCON output |
| 112 | * muxing control register in earlier SoCs (without the TCON TOP block) |
| 113 | * are located in TCON0. This helper returns a pointer to TCON0's |
| 114 | * sun4i_tcon structure, or NULL if not found. |
| 115 | */ |
| 116 | static struct sun4i_tcon *sun4i_get_tcon0(struct drm_device *drm) |
| 117 | { |
| 118 | struct sun4i_drv *drv = drm->dev_private; |
| 119 | struct sun4i_tcon *tcon; |
| 120 | |
| 121 | list_for_each_entry(tcon, &drv->tcon_list, list) |
| 122 | if (tcon->id == 0) |
| 123 | return tcon; |
| 124 | |
| 125 | dev_warn(drm->dev, |
| 126 | "TCON0 not found, display output muxing may not work\n"); |
| 127 | |
| 128 | return NULL; |
| 129 | } |
| 130 | |
Maxime Ripard | f8c73f4 | 2017-05-27 18:09:27 +0200 | [diff] [blame] | 131 | void sun4i_tcon_set_mux(struct sun4i_tcon *tcon, int channel, |
Maxime Ripard | abcb876 | 2017-10-17 11:06:10 +0200 | [diff] [blame] | 132 | const struct drm_encoder *encoder) |
Maxime Ripard | f8c73f4 | 2017-05-27 18:09:27 +0200 | [diff] [blame] | 133 | { |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 134 | int ret = -ENOTSUPP; |
Maxime Ripard | b7cb9b9 | 2017-05-27 18:09:28 +0200 | [diff] [blame] | 135 | |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 136 | if (tcon->quirks->set_mux) |
| 137 | ret = tcon->quirks->set_mux(tcon, encoder); |
Maxime Ripard | f8c73f4 | 2017-05-27 18:09:27 +0200 | [diff] [blame] | 138 | |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 139 | DRM_DEBUG_DRIVER("Muxing encoder %s to CRTC %s: %d\n", |
| 140 | encoder->name, encoder->crtc->name, ret); |
Maxime Ripard | f8c73f4 | 2017-05-27 18:09:27 +0200 | [diff] [blame] | 141 | } |
| 142 | EXPORT_SYMBOL(sun4i_tcon_set_mux); |
| 143 | |
Maxime Ripard | 961c645 | 2017-10-17 11:06:11 +0200 | [diff] [blame] | 144 | static int sun4i_tcon_get_clk_delay(const struct drm_display_mode *mode, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 145 | int channel) |
| 146 | { |
| 147 | int delay = mode->vtotal - mode->vdisplay; |
| 148 | |
| 149 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 150 | delay /= 2; |
| 151 | |
| 152 | if (channel == 1) |
| 153 | delay -= 2; |
| 154 | |
| 155 | delay = min(delay, 30); |
| 156 | |
| 157 | DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay); |
| 158 | |
| 159 | return delay; |
| 160 | } |
| 161 | |
| 162 | void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon, |
| 163 | struct drm_display_mode *mode) |
| 164 | { |
| 165 | unsigned int bp, hsync, vsync; |
| 166 | u8 clk_delay; |
| 167 | u32 val = 0; |
| 168 | |
Chen-Yu Tsai | 86cf678 | 2017-04-25 23:25:04 +0800 | [diff] [blame] | 169 | /* Configure the dot clock */ |
| 170 | clk_set_rate(tcon->dclk, mode->crtc_clock * 1000); |
| 171 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 172 | /* Adjust clock delay */ |
| 173 | clk_delay = sun4i_tcon_get_clk_delay(mode, 0); |
| 174 | regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, |
| 175 | SUN4I_TCON0_CTL_CLK_DELAY_MASK, |
| 176 | SUN4I_TCON0_CTL_CLK_DELAY(clk_delay)); |
| 177 | |
| 178 | /* Set the resolution */ |
| 179 | regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG, |
| 180 | SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) | |
| 181 | SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay)); |
| 182 | |
| 183 | /* |
| 184 | * This is called a backporch in the register documentation, |
Chen-Yu Tsai | 23a1cb1 | 2017-03-09 18:05:25 +0800 | [diff] [blame] | 185 | * but it really is the back porch + hsync |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 186 | */ |
| 187 | bp = mode->crtc_htotal - mode->crtc_hsync_start; |
| 188 | DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n", |
| 189 | mode->crtc_htotal, bp); |
| 190 | |
| 191 | /* Set horizontal display timings */ |
| 192 | regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG, |
| 193 | SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) | |
| 194 | SUN4I_TCON0_BASIC1_H_BACKPORCH(bp)); |
| 195 | |
| 196 | /* |
| 197 | * This is called a backporch in the register documentation, |
Chen-Yu Tsai | 23a1cb1 | 2017-03-09 18:05:25 +0800 | [diff] [blame] | 198 | * but it really is the back porch + hsync |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 199 | */ |
| 200 | bp = mode->crtc_vtotal - mode->crtc_vsync_start; |
| 201 | DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n", |
| 202 | mode->crtc_vtotal, bp); |
| 203 | |
| 204 | /* Set vertical display timings */ |
| 205 | regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG, |
Maxime Ripard | a88cbbd | 2017-05-27 18:09:30 +0200 | [diff] [blame] | 206 | SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal * 2) | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 207 | SUN4I_TCON0_BASIC2_V_BACKPORCH(bp)); |
| 208 | |
| 209 | /* Set Hsync and Vsync length */ |
| 210 | hsync = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 211 | vsync = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 212 | DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync); |
| 213 | regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG, |
| 214 | SUN4I_TCON0_BASIC3_V_SYNC(vsync) | |
| 215 | SUN4I_TCON0_BASIC3_H_SYNC(hsync)); |
| 216 | |
| 217 | /* Setup the polarity of the various signals */ |
| 218 | if (!(mode->flags & DRM_MODE_FLAG_PHSYNC)) |
| 219 | val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE; |
| 220 | |
| 221 | if (!(mode->flags & DRM_MODE_FLAG_PVSYNC)) |
| 222 | val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE; |
| 223 | |
| 224 | regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG, |
| 225 | SUN4I_TCON0_IO_POL_HSYNC_POSITIVE | SUN4I_TCON0_IO_POL_VSYNC_POSITIVE, |
| 226 | val); |
| 227 | |
| 228 | /* Map output pins to channel 0 */ |
| 229 | regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, |
| 230 | SUN4I_TCON_GCTL_IOMAP_MASK, |
| 231 | SUN4I_TCON_GCTL_IOMAP_TCON0); |
| 232 | |
| 233 | /* Enable the output on the pins */ |
| 234 | regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0); |
| 235 | } |
| 236 | EXPORT_SYMBOL(sun4i_tcon0_mode_set); |
| 237 | |
| 238 | void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, |
| 239 | struct drm_display_mode *mode) |
| 240 | { |
Maxime Ripard | b8317a3 | 2017-05-27 18:09:31 +0200 | [diff] [blame] | 241 | unsigned int bp, hsync, vsync, vtotal; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 242 | u8 clk_delay; |
| 243 | u32 val; |
| 244 | |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 245 | WARN_ON(!tcon->quirks->has_channel_1); |
Maxime Ripard | 8e92404 | 2016-01-07 12:32:07 +0100 | [diff] [blame] | 246 | |
Chen-Yu Tsai | 86cf678 | 2017-04-25 23:25:04 +0800 | [diff] [blame] | 247 | /* Configure the dot clock */ |
| 248 | clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000); |
| 249 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 250 | /* Adjust clock delay */ |
| 251 | clk_delay = sun4i_tcon_get_clk_delay(mode, 1); |
| 252 | regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, |
| 253 | SUN4I_TCON1_CTL_CLK_DELAY_MASK, |
| 254 | SUN4I_TCON1_CTL_CLK_DELAY(clk_delay)); |
| 255 | |
| 256 | /* Set interlaced mode */ |
| 257 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 258 | val = SUN4I_TCON1_CTL_INTERLACE_ENABLE; |
| 259 | else |
| 260 | val = 0; |
| 261 | regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, |
| 262 | SUN4I_TCON1_CTL_INTERLACE_ENABLE, |
| 263 | val); |
| 264 | |
| 265 | /* Set the input resolution */ |
| 266 | regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG, |
| 267 | SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) | |
| 268 | SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay)); |
| 269 | |
| 270 | /* Set the upscaling resolution */ |
| 271 | regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG, |
| 272 | SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) | |
| 273 | SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay)); |
| 274 | |
| 275 | /* Set the output resolution */ |
| 276 | regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG, |
| 277 | SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) | |
| 278 | SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay)); |
| 279 | |
| 280 | /* Set horizontal display timings */ |
Maxime Ripard | 3cb2f46 | 2017-05-27 18:09:29 +0200 | [diff] [blame] | 281 | bp = mode->crtc_htotal - mode->crtc_hsync_start; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 282 | DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n", |
| 283 | mode->htotal, bp); |
| 284 | regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG, |
| 285 | SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) | |
| 286 | SUN4I_TCON1_BASIC3_H_BACKPORCH(bp)); |
| 287 | |
Maxime Ripard | 3cb2f46 | 2017-05-27 18:09:29 +0200 | [diff] [blame] | 288 | bp = mode->crtc_vtotal - mode->crtc_vsync_start; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 289 | DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n", |
Maxime Ripard | b8317a3 | 2017-05-27 18:09:31 +0200 | [diff] [blame] | 290 | mode->crtc_vtotal, bp); |
| 291 | |
| 292 | /* |
| 293 | * The vertical resolution needs to be doubled in all |
| 294 | * cases. We could use crtc_vtotal and always multiply by two, |
| 295 | * but that leads to a rounding error in interlace when vtotal |
| 296 | * is odd. |
| 297 | * |
| 298 | * This happens with TV's PAL for example, where vtotal will |
| 299 | * be 625, crtc_vtotal 312, and thus crtc_vtotal * 2 will be |
| 300 | * 624, which apparently confuses the hardware. |
| 301 | * |
| 302 | * To work around this, we will always use vtotal, and |
| 303 | * multiply by two only if we're not in interlace. |
| 304 | */ |
| 305 | vtotal = mode->vtotal; |
| 306 | if (!(mode->flags & DRM_MODE_FLAG_INTERLACE)) |
| 307 | vtotal = vtotal * 2; |
| 308 | |
| 309 | /* Set vertical display timings */ |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 310 | regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG, |
Maxime Ripard | b8317a3 | 2017-05-27 18:09:31 +0200 | [diff] [blame] | 311 | SUN4I_TCON1_BASIC4_V_TOTAL(vtotal) | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 312 | SUN4I_TCON1_BASIC4_V_BACKPORCH(bp)); |
| 313 | |
| 314 | /* Set Hsync and Vsync length */ |
| 315 | hsync = mode->crtc_hsync_end - mode->crtc_hsync_start; |
| 316 | vsync = mode->crtc_vsync_end - mode->crtc_vsync_start; |
| 317 | DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync); |
| 318 | regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG, |
| 319 | SUN4I_TCON1_BASIC5_V_SYNC(vsync) | |
| 320 | SUN4I_TCON1_BASIC5_H_SYNC(hsync)); |
| 321 | |
| 322 | /* Map output pins to channel 1 */ |
| 323 | regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, |
| 324 | SUN4I_TCON_GCTL_IOMAP_MASK, |
| 325 | SUN4I_TCON_GCTL_IOMAP_TCON1); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 326 | } |
| 327 | EXPORT_SYMBOL(sun4i_tcon1_mode_set); |
| 328 | |
| 329 | static void sun4i_tcon_finish_page_flip(struct drm_device *dev, |
| 330 | struct sun4i_crtc *scrtc) |
| 331 | { |
| 332 | unsigned long flags; |
| 333 | |
| 334 | spin_lock_irqsave(&dev->event_lock, flags); |
| 335 | if (scrtc->event) { |
| 336 | drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event); |
| 337 | drm_crtc_vblank_put(&scrtc->crtc); |
| 338 | scrtc->event = NULL; |
| 339 | } |
| 340 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 341 | } |
| 342 | |
| 343 | static irqreturn_t sun4i_tcon_handler(int irq, void *private) |
| 344 | { |
| 345 | struct sun4i_tcon *tcon = private; |
| 346 | struct drm_device *drm = tcon->drm; |
Chen-Yu Tsai | 46cce6d | 2017-02-23 16:05:37 +0800 | [diff] [blame] | 347 | struct sun4i_crtc *scrtc = tcon->crtc; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 348 | unsigned int status; |
| 349 | |
| 350 | regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status); |
| 351 | |
| 352 | if (!(status & (SUN4I_TCON_GINT0_VBLANK_INT(0) | |
| 353 | SUN4I_TCON_GINT0_VBLANK_INT(1)))) |
| 354 | return IRQ_NONE; |
| 355 | |
| 356 | drm_crtc_handle_vblank(&scrtc->crtc); |
| 357 | sun4i_tcon_finish_page_flip(drm, scrtc); |
| 358 | |
| 359 | /* Acknowledge the interrupt */ |
| 360 | regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, |
| 361 | SUN4I_TCON_GINT0_VBLANK_INT(0) | |
| 362 | SUN4I_TCON_GINT0_VBLANK_INT(1), |
| 363 | 0); |
| 364 | |
| 365 | return IRQ_HANDLED; |
| 366 | } |
| 367 | |
| 368 | static int sun4i_tcon_init_clocks(struct device *dev, |
| 369 | struct sun4i_tcon *tcon) |
| 370 | { |
| 371 | tcon->clk = devm_clk_get(dev, "ahb"); |
| 372 | if (IS_ERR(tcon->clk)) { |
| 373 | dev_err(dev, "Couldn't get the TCON bus clock\n"); |
| 374 | return PTR_ERR(tcon->clk); |
| 375 | } |
| 376 | clk_prepare_enable(tcon->clk); |
| 377 | |
| 378 | tcon->sclk0 = devm_clk_get(dev, "tcon-ch0"); |
| 379 | if (IS_ERR(tcon->sclk0)) { |
| 380 | dev_err(dev, "Couldn't get the TCON channel 0 clock\n"); |
| 381 | return PTR_ERR(tcon->sclk0); |
| 382 | } |
| 383 | |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 384 | if (tcon->quirks->has_channel_1) { |
Maxime Ripard | 8e92404 | 2016-01-07 12:32:07 +0100 | [diff] [blame] | 385 | tcon->sclk1 = devm_clk_get(dev, "tcon-ch1"); |
| 386 | if (IS_ERR(tcon->sclk1)) { |
| 387 | dev_err(dev, "Couldn't get the TCON channel 1 clock\n"); |
| 388 | return PTR_ERR(tcon->sclk1); |
| 389 | } |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 392 | return 0; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon) |
| 396 | { |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 397 | clk_disable_unprepare(tcon->clk); |
| 398 | } |
| 399 | |
| 400 | static int sun4i_tcon_init_irq(struct device *dev, |
| 401 | struct sun4i_tcon *tcon) |
| 402 | { |
| 403 | struct platform_device *pdev = to_platform_device(dev); |
| 404 | int irq, ret; |
| 405 | |
| 406 | irq = platform_get_irq(pdev, 0); |
| 407 | if (irq < 0) { |
| 408 | dev_err(dev, "Couldn't retrieve the TCON interrupt\n"); |
| 409 | return irq; |
| 410 | } |
| 411 | |
| 412 | ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0, |
| 413 | dev_name(dev), tcon); |
| 414 | if (ret) { |
| 415 | dev_err(dev, "Couldn't request the IRQ\n"); |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static struct regmap_config sun4i_tcon_regmap_config = { |
| 423 | .reg_bits = 32, |
| 424 | .val_bits = 32, |
| 425 | .reg_stride = 4, |
| 426 | .max_register = 0x800, |
| 427 | }; |
| 428 | |
| 429 | static int sun4i_tcon_init_regmap(struct device *dev, |
| 430 | struct sun4i_tcon *tcon) |
| 431 | { |
| 432 | struct platform_device *pdev = to_platform_device(dev); |
| 433 | struct resource *res; |
| 434 | void __iomem *regs; |
| 435 | |
| 436 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 437 | regs = devm_ioremap_resource(dev, res); |
Wei Yongjun | af346f5 | 2016-08-26 14:25:25 +0000 | [diff] [blame] | 438 | if (IS_ERR(regs)) |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 439 | return PTR_ERR(regs); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 440 | |
| 441 | tcon->regs = devm_regmap_init_mmio(dev, regs, |
| 442 | &sun4i_tcon_regmap_config); |
| 443 | if (IS_ERR(tcon->regs)) { |
| 444 | dev_err(dev, "Couldn't create the TCON regmap\n"); |
| 445 | return PTR_ERR(tcon->regs); |
| 446 | } |
| 447 | |
| 448 | /* Make sure the TCON is disabled and all IRQs are off */ |
| 449 | regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0); |
| 450 | regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0); |
| 451 | regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0); |
| 452 | |
| 453 | /* Disable IO lines and set them to tristate */ |
| 454 | regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0); |
| 455 | regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0); |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 460 | /* |
| 461 | * On SoCs with the old display pipeline design (Display Engine 1.0), |
| 462 | * the TCON is always tied to just one backend. Hence we can traverse |
| 463 | * the of_graph upwards to find the backend our tcon is connected to, |
| 464 | * and take its ID as our own. |
| 465 | * |
| 466 | * We can either identify backends from their compatible strings, which |
| 467 | * means maintaining a large list of them. Or, since the backend is |
| 468 | * registered and binded before the TCON, we can just go through the |
| 469 | * list of registered backends and compare the device node. |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 470 | * |
| 471 | * As the structures now store engines instead of backends, here this |
| 472 | * function in fact searches the corresponding engine, and the ID is |
| 473 | * requested via the get_id function of the engine. |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 474 | */ |
Chen-Yu Tsai | e8d5bbf | 2017-09-08 15:50:12 +0800 | [diff] [blame] | 475 | static struct sunxi_engine * |
| 476 | sun4i_tcon_find_engine_traverse(struct sun4i_drv *drv, |
| 477 | struct device_node *node) |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 478 | { |
| 479 | struct device_node *port, *ep, *remote; |
Chen-Yu Tsai | be3fe0f | 2017-09-08 15:50:13 +0800 | [diff] [blame] | 480 | struct sunxi_engine *engine = ERR_PTR(-EINVAL); |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 481 | |
| 482 | port = of_graph_get_port_by_id(node, 0); |
| 483 | if (!port) |
| 484 | return ERR_PTR(-EINVAL); |
| 485 | |
Chen-Yu Tsai | 1469619 | 2017-09-08 15:50:11 +0800 | [diff] [blame] | 486 | /* |
| 487 | * This only works if there is only one path from the TCON |
| 488 | * to any display engine. Otherwise the probe order of the |
| 489 | * TCONs and display engines is not guaranteed. They may |
| 490 | * either bind to the wrong one, or worse, bind to the same |
| 491 | * one if additional checks are not done. |
| 492 | * |
| 493 | * Bail out if there are multiple input connections. |
| 494 | */ |
Chen-Yu Tsai | be3fe0f | 2017-09-08 15:50:13 +0800 | [diff] [blame] | 495 | if (of_get_available_child_count(port) != 1) |
| 496 | goto out_put_port; |
Chen-Yu Tsai | 1469619 | 2017-09-08 15:50:11 +0800 | [diff] [blame] | 497 | |
Chen-Yu Tsai | be3fe0f | 2017-09-08 15:50:13 +0800 | [diff] [blame] | 498 | /* Get the first connection without specifying an ID */ |
| 499 | ep = of_get_next_available_child(port, NULL); |
| 500 | if (!ep) |
| 501 | goto out_put_port; |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 502 | |
Chen-Yu Tsai | be3fe0f | 2017-09-08 15:50:13 +0800 | [diff] [blame] | 503 | remote = of_graph_get_remote_port_parent(ep); |
| 504 | if (!remote) |
| 505 | goto out_put_ep; |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 506 | |
Chen-Yu Tsai | be3fe0f | 2017-09-08 15:50:13 +0800 | [diff] [blame] | 507 | /* does this node match any registered engines? */ |
| 508 | list_for_each_entry(engine, &drv->engine_list, list) |
| 509 | if (remote == engine->node) |
| 510 | goto out_put_remote; |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 511 | |
Chen-Yu Tsai | be3fe0f | 2017-09-08 15:50:13 +0800 | [diff] [blame] | 512 | /* keep looking through upstream ports */ |
| 513 | engine = sun4i_tcon_find_engine_traverse(drv, remote); |
| 514 | |
| 515 | out_put_remote: |
| 516 | of_node_put(remote); |
| 517 | out_put_ep: |
| 518 | of_node_put(ep); |
| 519 | out_put_port: |
| 520 | of_node_put(port); |
| 521 | |
| 522 | return engine; |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 523 | } |
| 524 | |
Chen-Yu Tsai | e8d5bbf | 2017-09-08 15:50:12 +0800 | [diff] [blame] | 525 | /* |
| 526 | * The device tree binding says that the remote endpoint ID of any |
| 527 | * connection between components, up to and including the TCON, of |
| 528 | * the display pipeline should be equal to the actual ID of the local |
| 529 | * component. Thus we can look at any one of the input connections of |
| 530 | * the TCONs, and use that connection's remote endpoint ID as our own. |
| 531 | * |
| 532 | * Since the user of this function already finds the input port, |
| 533 | * the port is passed in directly without further checks. |
| 534 | */ |
| 535 | static int sun4i_tcon_of_get_id_from_port(struct device_node *port) |
| 536 | { |
| 537 | struct device_node *ep; |
| 538 | int ret = -EINVAL; |
| 539 | |
| 540 | /* try finding an upstream endpoint */ |
| 541 | for_each_available_child_of_node(port, ep) { |
| 542 | struct device_node *remote; |
| 543 | u32 reg; |
| 544 | |
| 545 | remote = of_graph_get_remote_endpoint(ep); |
| 546 | if (!remote) |
| 547 | continue; |
| 548 | |
| 549 | ret = of_property_read_u32(remote, "reg", ®); |
| 550 | if (ret) |
| 551 | continue; |
| 552 | |
| 553 | ret = reg; |
| 554 | } |
| 555 | |
| 556 | return ret; |
| 557 | } |
| 558 | |
| 559 | /* |
| 560 | * Once we know the TCON's id, we can look through the list of |
| 561 | * engines to find a matching one. We assume all engines have |
| 562 | * been probed and added to the list. |
| 563 | */ |
| 564 | static struct sunxi_engine *sun4i_tcon_get_engine_by_id(struct sun4i_drv *drv, |
| 565 | int id) |
| 566 | { |
| 567 | struct sunxi_engine *engine; |
| 568 | |
| 569 | list_for_each_entry(engine, &drv->engine_list, list) |
| 570 | if (engine->id == id) |
| 571 | return engine; |
| 572 | |
| 573 | return ERR_PTR(-EINVAL); |
| 574 | } |
| 575 | |
| 576 | /* |
| 577 | * On SoCs with the old display pipeline design (Display Engine 1.0), |
| 578 | * we assumed the TCON was always tied to just one backend. However |
| 579 | * this proved not to be the case. On the A31, the TCON can select |
| 580 | * either backend as its source. On the A20 (and likely on the A10), |
| 581 | * the backend can choose which TCON to output to. |
| 582 | * |
| 583 | * The device tree binding says that the remote endpoint ID of any |
| 584 | * connection between components, up to and including the TCON, of |
| 585 | * the display pipeline should be equal to the actual ID of the local |
| 586 | * component. Thus we should be able to look at any one of the input |
| 587 | * connections of the TCONs, and use that connection's remote endpoint |
| 588 | * ID as our own. |
| 589 | * |
| 590 | * However the connections between the backend and TCON were assumed |
| 591 | * to be always singular, and their endpoit IDs were all incorrectly |
| 592 | * set to 0. This means for these old device trees, we cannot just look |
| 593 | * up the remote endpoint ID of a TCON input endpoint. TCON1 would be |
| 594 | * incorrectly identified as TCON0. |
| 595 | * |
| 596 | * This function first checks if the TCON node has 2 input endpoints. |
| 597 | * If so, then the device tree is a corrected version, and it will use |
| 598 | * sun4i_tcon_of_get_id() and sun4i_tcon_get_engine_by_id() from above |
| 599 | * to fetch the ID and engine directly. If not, then it is likely an |
| 600 | * old device trees, where the endpoint IDs were incorrect, but did not |
| 601 | * have endpoint connections between the backend and TCON across |
| 602 | * different display pipelines. It will fall back to the old method of |
| 603 | * traversing the of_graph to try and find a matching engine by device |
| 604 | * node. |
| 605 | * |
| 606 | * In the case of single display pipeline device trees, either method |
| 607 | * works. |
| 608 | */ |
| 609 | static struct sunxi_engine *sun4i_tcon_find_engine(struct sun4i_drv *drv, |
| 610 | struct device_node *node) |
| 611 | { |
| 612 | struct device_node *port; |
| 613 | struct sunxi_engine *engine; |
| 614 | |
| 615 | port = of_graph_get_port_by_id(node, 0); |
| 616 | if (!port) |
| 617 | return ERR_PTR(-EINVAL); |
| 618 | |
| 619 | /* |
| 620 | * Is this a corrected device tree with cross pipeline |
| 621 | * connections between the backend and TCON? |
| 622 | */ |
| 623 | if (of_get_child_count(port) > 1) { |
| 624 | /* Get our ID directly from an upstream endpoint */ |
| 625 | int id = sun4i_tcon_of_get_id_from_port(port); |
| 626 | |
| 627 | /* Get our engine by matching our ID */ |
| 628 | engine = sun4i_tcon_get_engine_by_id(drv, id); |
| 629 | |
| 630 | of_node_put(port); |
| 631 | return engine; |
| 632 | } |
| 633 | |
| 634 | /* Fallback to old method by traversing input endpoints */ |
| 635 | of_node_put(port); |
| 636 | return sun4i_tcon_find_engine_traverse(drv, node); |
| 637 | } |
| 638 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 639 | static int sun4i_tcon_bind(struct device *dev, struct device *master, |
| 640 | void *data) |
| 641 | { |
| 642 | struct drm_device *drm = data; |
| 643 | struct sun4i_drv *drv = drm->dev_private; |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 644 | struct sunxi_engine *engine; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 645 | struct sun4i_tcon *tcon; |
| 646 | int ret; |
| 647 | |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 648 | engine = sun4i_tcon_find_engine(drv, dev->of_node); |
| 649 | if (IS_ERR(engine)) { |
| 650 | dev_err(dev, "Couldn't find matching engine\n"); |
Chen-Yu Tsai | 80a5824 | 2017-04-21 16:38:50 +0800 | [diff] [blame] | 651 | return -EPROBE_DEFER; |
Chen-Yu Tsai | b317fa3 | 2017-04-21 16:38:54 +0800 | [diff] [blame] | 652 | } |
Chen-Yu Tsai | 80a5824 | 2017-04-21 16:38:50 +0800 | [diff] [blame] | 653 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 654 | tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL); |
| 655 | if (!tcon) |
| 656 | return -ENOMEM; |
| 657 | dev_set_drvdata(dev, tcon); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 658 | tcon->drm = drm; |
Maxime Ripard | ae55811 | 2016-07-19 15:17:27 +0200 | [diff] [blame] | 659 | tcon->dev = dev; |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 660 | tcon->id = engine->id; |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 661 | tcon->quirks = of_device_get_match_data(dev); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 662 | |
| 663 | tcon->lcd_rst = devm_reset_control_get(dev, "lcd"); |
| 664 | if (IS_ERR(tcon->lcd_rst)) { |
| 665 | dev_err(dev, "Couldn't get our reset line\n"); |
| 666 | return PTR_ERR(tcon->lcd_rst); |
| 667 | } |
| 668 | |
| 669 | /* Make sure our TCON is reset */ |
Chen-Yu Tsai | d57294c | 2017-09-08 17:00:16 +0800 | [diff] [blame] | 670 | ret = reset_control_reset(tcon->lcd_rst); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 671 | if (ret) { |
| 672 | dev_err(dev, "Couldn't deassert our reset line\n"); |
| 673 | return ret; |
| 674 | } |
| 675 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 676 | ret = sun4i_tcon_init_clocks(dev, tcon); |
| 677 | if (ret) { |
| 678 | dev_err(dev, "Couldn't init our TCON clocks\n"); |
| 679 | goto err_assert_reset; |
| 680 | } |
| 681 | |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 682 | ret = sun4i_tcon_init_regmap(dev, tcon); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 683 | if (ret) { |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 684 | dev_err(dev, "Couldn't init our TCON regmap\n"); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 685 | goto err_free_clocks; |
| 686 | } |
| 687 | |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 688 | ret = sun4i_dclk_create(dev, tcon); |
| 689 | if (ret) { |
| 690 | dev_err(dev, "Couldn't create our TCON dot clock\n"); |
| 691 | goto err_free_clocks; |
| 692 | } |
| 693 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 694 | ret = sun4i_tcon_init_irq(dev, tcon); |
| 695 | if (ret) { |
| 696 | dev_err(dev, "Couldn't init our TCON interrupts\n"); |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 697 | goto err_free_dotclock; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Icenowy Zheng | 8796933 | 2017-05-17 22:47:17 +0800 | [diff] [blame] | 700 | tcon->crtc = sun4i_crtc_init(drm, engine, tcon); |
Chen-Yu Tsai | 46cce6d | 2017-02-23 16:05:37 +0800 | [diff] [blame] | 701 | if (IS_ERR(tcon->crtc)) { |
| 702 | dev_err(dev, "Couldn't create our CRTC\n"); |
| 703 | ret = PTR_ERR(tcon->crtc); |
| 704 | goto err_free_clocks; |
| 705 | } |
| 706 | |
Chen-Yu Tsai | b9c8506 | 2017-02-23 16:05:41 +0800 | [diff] [blame] | 707 | ret = sun4i_rgb_init(drm, tcon); |
Chen-Yu Tsai | 13fef09 | 2016-05-17 23:56:06 +0800 | [diff] [blame] | 708 | if (ret < 0) |
| 709 | goto err_free_clocks; |
| 710 | |
Chen-Yu Tsai | 27e18de | 2017-09-08 15:50:14 +0800 | [diff] [blame] | 711 | if (tcon->quirks->needs_de_be_mux) { |
| 712 | /* |
| 713 | * We assume there is no dynamic muxing of backends |
| 714 | * and TCONs, so we select the backend with same ID. |
| 715 | * |
| 716 | * While dynamic selection might be interesting, since |
| 717 | * the CRTC is tied to the TCON, while the layers are |
| 718 | * tied to the backends, this means, we will need to |
| 719 | * switch between groups of layers. There might not be |
| 720 | * a way to represent this constraint in DRM. |
| 721 | */ |
| 722 | regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, |
| 723 | SUN4I_TCON0_CTL_SRC_SEL_MASK, |
| 724 | tcon->id); |
| 725 | regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, |
| 726 | SUN4I_TCON1_CTL_SRC_SEL_MASK, |
| 727 | tcon->id); |
| 728 | } |
| 729 | |
Chen-Yu Tsai | 80a5824 | 2017-04-21 16:38:50 +0800 | [diff] [blame] | 730 | list_add_tail(&tcon->list, &drv->tcon_list); |
| 731 | |
Chen-Yu Tsai | 13fef09 | 2016-05-17 23:56:06 +0800 | [diff] [blame] | 732 | return 0; |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 733 | |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 734 | err_free_dotclock: |
| 735 | sun4i_dclk_free(tcon); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 736 | err_free_clocks: |
| 737 | sun4i_tcon_free_clocks(tcon); |
| 738 | err_assert_reset: |
| 739 | reset_control_assert(tcon->lcd_rst); |
| 740 | return ret; |
| 741 | } |
| 742 | |
| 743 | static void sun4i_tcon_unbind(struct device *dev, struct device *master, |
| 744 | void *data) |
| 745 | { |
| 746 | struct sun4i_tcon *tcon = dev_get_drvdata(dev); |
| 747 | |
Chen-Yu Tsai | 80a5824 | 2017-04-21 16:38:50 +0800 | [diff] [blame] | 748 | list_del(&tcon->list); |
Chen-Yu Tsai | 4c7f16d | 2017-03-09 18:05:24 +0800 | [diff] [blame] | 749 | sun4i_dclk_free(tcon); |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 750 | sun4i_tcon_free_clocks(tcon); |
| 751 | } |
| 752 | |
Julia Lawall | dfeb693 | 2016-11-12 18:19:58 +0100 | [diff] [blame] | 753 | static const struct component_ops sun4i_tcon_ops = { |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 754 | .bind = sun4i_tcon_bind, |
| 755 | .unbind = sun4i_tcon_unbind, |
| 756 | }; |
| 757 | |
| 758 | static int sun4i_tcon_probe(struct platform_device *pdev) |
| 759 | { |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 760 | struct device_node *node = pdev->dev.of_node; |
Maxime Ripard | 894f5a9 | 2016-04-11 12:16:33 +0200 | [diff] [blame] | 761 | struct drm_bridge *bridge; |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 762 | struct drm_panel *panel; |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 763 | int ret; |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 764 | |
Rob Herring | ebc9446 | 2017-03-29 13:55:46 -0500 | [diff] [blame] | 765 | ret = drm_of_find_panel_or_bridge(node, 1, 0, &panel, &bridge); |
| 766 | if (ret == -EPROBE_DEFER) |
| 767 | return ret; |
Maxime Ripard | 29e57fa | 2015-10-29 09:37:32 +0100 | [diff] [blame] | 768 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 769 | return component_add(&pdev->dev, &sun4i_tcon_ops); |
| 770 | } |
| 771 | |
| 772 | static int sun4i_tcon_remove(struct platform_device *pdev) |
| 773 | { |
| 774 | component_del(&pdev->dev, &sun4i_tcon_ops); |
| 775 | |
| 776 | return 0; |
| 777 | } |
| 778 | |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 779 | /* platform specific TCON muxing callbacks */ |
| 780 | static int sun5i_a13_tcon_set_mux(struct sun4i_tcon *tcon, |
Maxime Ripard | abcb876 | 2017-10-17 11:06:10 +0200 | [diff] [blame] | 781 | const struct drm_encoder *encoder) |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 782 | { |
| 783 | u32 val; |
| 784 | |
| 785 | if (encoder->encoder_type == DRM_MODE_ENCODER_TVDAC) |
| 786 | val = 1; |
| 787 | else |
| 788 | val = 0; |
| 789 | |
| 790 | /* |
| 791 | * FIXME: Undocumented bits |
| 792 | */ |
| 793 | return regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, val); |
| 794 | } |
| 795 | |
Chen-Yu Tsai | 67e3264 | 2017-10-10 11:19:59 +0800 | [diff] [blame] | 796 | static int sun6i_tcon_set_mux(struct sun4i_tcon *tcon, |
Maxime Ripard | abcb876 | 2017-10-17 11:06:10 +0200 | [diff] [blame] | 797 | const struct drm_encoder *encoder) |
Chen-Yu Tsai | 67e3264 | 2017-10-10 11:19:59 +0800 | [diff] [blame] | 798 | { |
| 799 | struct sun4i_tcon *tcon0 = sun4i_get_tcon0(encoder->dev); |
| 800 | u32 shift; |
| 801 | |
| 802 | if (!tcon0) |
| 803 | return -EINVAL; |
| 804 | |
| 805 | switch (encoder->encoder_type) { |
| 806 | case DRM_MODE_ENCODER_TMDS: |
| 807 | /* HDMI */ |
| 808 | shift = 8; |
| 809 | break; |
| 810 | default: |
| 811 | /* TODO A31 has MIPI DSI but A31s does not */ |
| 812 | return -EINVAL; |
| 813 | } |
| 814 | |
| 815 | regmap_update_bits(tcon0->regs, SUN4I_TCON_MUX_CTRL_REG, |
| 816 | 0x3 << shift, tcon->id << shift); |
| 817 | |
| 818 | return 0; |
| 819 | } |
| 820 | |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 821 | static const struct sun4i_tcon_quirks sun5i_a13_quirks = { |
Chen-Yu Tsai | ad537fb | 2017-10-10 11:19:58 +0800 | [diff] [blame] | 822 | .has_channel_1 = true, |
| 823 | .set_mux = sun5i_a13_tcon_set_mux, |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 824 | }; |
| 825 | |
Chen-Yu Tsai | 93a5ec1 | 2016-10-20 11:43:40 +0800 | [diff] [blame] | 826 | static const struct sun4i_tcon_quirks sun6i_a31_quirks = { |
Chen-Yu Tsai | 27e18de | 2017-09-08 15:50:14 +0800 | [diff] [blame] | 827 | .has_channel_1 = true, |
| 828 | .needs_de_be_mux = true, |
Chen-Yu Tsai | 67e3264 | 2017-10-10 11:19:59 +0800 | [diff] [blame] | 829 | .set_mux = sun6i_tcon_set_mux, |
Chen-Yu Tsai | 93a5ec1 | 2016-10-20 11:43:40 +0800 | [diff] [blame] | 830 | }; |
| 831 | |
| 832 | static const struct sun4i_tcon_quirks sun6i_a31s_quirks = { |
Chen-Yu Tsai | 27e18de | 2017-09-08 15:50:14 +0800 | [diff] [blame] | 833 | .has_channel_1 = true, |
| 834 | .needs_de_be_mux = true, |
Chen-Yu Tsai | 93a5ec1 | 2016-10-20 11:43:40 +0800 | [diff] [blame] | 835 | }; |
| 836 | |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 837 | static const struct sun4i_tcon_quirks sun8i_a33_quirks = { |
| 838 | /* nothing is supported */ |
| 839 | }; |
| 840 | |
Icenowy Zheng | 1a0edb3 | 2017-05-17 22:47:22 +0800 | [diff] [blame] | 841 | static const struct sun4i_tcon_quirks sun8i_v3s_quirks = { |
| 842 | /* nothing is supported */ |
| 843 | }; |
| 844 | |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 845 | static const struct of_device_id sun4i_tcon_of_table[] = { |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 846 | { .compatible = "allwinner,sun5i-a13-tcon", .data = &sun5i_a13_quirks }, |
Chen-Yu Tsai | 93a5ec1 | 2016-10-20 11:43:40 +0800 | [diff] [blame] | 847 | { .compatible = "allwinner,sun6i-a31-tcon", .data = &sun6i_a31_quirks }, |
| 848 | { .compatible = "allwinner,sun6i-a31s-tcon", .data = &sun6i_a31s_quirks }, |
Chen-Yu Tsai | 91ea2f2 | 2016-10-20 11:43:39 +0800 | [diff] [blame] | 849 | { .compatible = "allwinner,sun8i-a33-tcon", .data = &sun8i_a33_quirks }, |
Icenowy Zheng | 1a0edb3 | 2017-05-17 22:47:22 +0800 | [diff] [blame] | 850 | { .compatible = "allwinner,sun8i-v3s-tcon", .data = &sun8i_v3s_quirks }, |
Maxime Ripard | 9026e0d | 2015-10-29 09:36:23 +0100 | [diff] [blame] | 851 | { } |
| 852 | }; |
| 853 | MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table); |
| 854 | |
| 855 | static struct platform_driver sun4i_tcon_platform_driver = { |
| 856 | .probe = sun4i_tcon_probe, |
| 857 | .remove = sun4i_tcon_remove, |
| 858 | .driver = { |
| 859 | .name = "sun4i-tcon", |
| 860 | .of_match_table = sun4i_tcon_of_table, |
| 861 | }, |
| 862 | }; |
| 863 | module_platform_driver(sun4i_tcon_platform_driver); |
| 864 | |
| 865 | MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); |
| 866 | MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver"); |
| 867 | MODULE_LICENSE("GPL"); |