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