Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'sun4i-drm-for-4.7' of https://git.kernel.org/pub/scm/linux/kernel/git/mripard/linux into drm-next

Allwinner DRM driver for 4.7

This pull request introduces the sun4i driver, meant to be used on the
older Allwinner SoCs (A10, A13, A20, A23, A31 and A33).

It currently supports only the A13, which has one of the simplest video
pipeline. Support for other video components and SoCs will be added
eventually.

It supports only a RGB or composite output. It doesn't do HDMI, VGA, LVDS
or power management yet, but that will come in time as well.

* tag 'sun4i-drm-for-4.7' of https://git.kernel.org/pub/scm/linux/kernel/git/mripard/linux:
MAINTAINERS: Add a maintainer for the Allwinner DRM driver
drm: sun4i: tv: Add NTSC output standard
drm: sun4i: tv: Add PAL output standard
drm: sun4i: Add composite output
drm: sun4i: Add RGB output
drm: Add Allwinner A10 Display Engine support
drm: sun4i: Add DT bindings documentation
drm: fb: Add seq_file definition

+3533 -1
+258
Documentation/devicetree/bindings/display/sunxi/sun4i-drm.txt
··· 1 + Allwinner A10 Display Pipeline 2 + ============================== 3 + 4 + The Allwinner A10 Display pipeline is composed of several components 5 + that are going to be documented below: 6 + 7 + TV Encoder 8 + ---------- 9 + 10 + The TV Encoder supports the composite and VGA output. It is one end of 11 + the pipeline. 12 + 13 + Required properties: 14 + - compatible: value should be "allwinner,sun4i-a10-tv-encoder". 15 + - reg: base address and size of memory-mapped region 16 + - clocks: the clocks driving the TV encoder 17 + - resets: phandle to the reset controller driving the encoder 18 + 19 + - ports: A ports node with endpoint definitions as defined in 20 + Documentation/devicetree/bindings/media/video-interfaces.txt. The 21 + first port should be the input endpoint. 22 + 23 + TCON 24 + ---- 25 + 26 + The TCON acts as a timing controller for RGB, LVDS and TV interfaces. 27 + 28 + Required properties: 29 + - compatible: value should be "allwinner,sun5i-a13-tcon". 30 + - reg: base address and size of memory-mapped region 31 + - interrupts: interrupt associated to this IP 32 + - clocks: phandles to the clocks feeding the TCON. Three are needed: 33 + - 'ahb': the interface clocks 34 + - 'tcon-ch0': The clock driving the TCON channel 0 35 + - 'tcon-ch1': The clock driving the TCON channel 1 36 + - resets: phandles to the reset controllers driving the encoder 37 + - "lcd": the reset line for the TCON channel 0 38 + 39 + - clock-names: the clock names mentioned above 40 + - reset-names: the reset names mentioned above 41 + - clock-output-names: Name of the pixel clock created 42 + 43 + - ports: A ports node with endpoint definitions as defined in 44 + Documentation/devicetree/bindings/media/video-interfaces.txt. The 45 + first port should be the input endpoint, the second one the output 46 + 47 + The output should have two endpoints. The first is the block 48 + connected to the TCON channel 0 (usually a panel or a bridge), the 49 + second the block connected to the TCON channel 1 (usually the TV 50 + encoder) 51 + 52 + 53 + Display Engine Backend 54 + ---------------------- 55 + 56 + The display engine backend exposes layers and sprites to the 57 + system. 58 + 59 + Required properties: 60 + - compatible: value must be one of: 61 + * allwinner,sun5i-a13-display-backend 62 + - reg: base address and size of the memory-mapped region. 63 + - clocks: phandles to the clocks feeding the frontend and backend 64 + * ahb: the backend interface clock 65 + * mod: the backend module clock 66 + * ram: the backend DRAM clock 67 + - clock-names: the clock names mentioned above 68 + - resets: phandles to the reset controllers driving the backend 69 + 70 + - ports: A ports node with endpoint definitions as defined in 71 + Documentation/devicetree/bindings/media/video-interfaces.txt. The 72 + first port should be the input endpoints, the second one the output 73 + 74 + Display Engine Frontend 75 + ----------------------- 76 + 77 + The display engine frontend does formats conversion, scaling, 78 + deinterlacing and color space conversion. 79 + 80 + Required properties: 81 + - compatible: value must be one of: 82 + * allwinner,sun5i-a13-display-frontend 83 + - reg: base address and size of the memory-mapped region. 84 + - interrupts: interrupt associated to this IP 85 + - clocks: phandles to the clocks feeding the frontend and backend 86 + * ahb: the backend interface clock 87 + * mod: the backend module clock 88 + * ram: the backend DRAM clock 89 + - clock-names: the clock names mentioned above 90 + - resets: phandles to the reset controllers driving the backend 91 + 92 + - ports: A ports node with endpoint definitions as defined in 93 + Documentation/devicetree/bindings/media/video-interfaces.txt. The 94 + first port should be the input endpoints, the second one the outputs 95 + 96 + 97 + Display Engine Pipeline 98 + ----------------------- 99 + 100 + The display engine pipeline (and its entry point, since it can be 101 + either directly the backend or the frontend) is represented as an 102 + extra node. 103 + 104 + Required properties: 105 + - compatible: value must be one of: 106 + * allwinner,sun5i-a13-display-engine 107 + 108 + - allwinner,pipelines: list of phandle to the display engine 109 + frontends available. 110 + 111 + Example: 112 + 113 + panel: panel { 114 + compatible = "olimex,lcd-olinuxino-43-ts"; 115 + #address-cells = <1>; 116 + #size-cells = <0>; 117 + 118 + port { 119 + #address-cells = <1>; 120 + #size-cells = <0>; 121 + 122 + panel_input: endpoint { 123 + remote-endpoint = <&tcon0_out_panel>; 124 + }; 125 + }; 126 + }; 127 + 128 + tve0: tv-encoder@01c0a000 { 129 + compatible = "allwinner,sun4i-a10-tv-encoder"; 130 + reg = <0x01c0a000 0x1000>; 131 + clocks = <&ahb_gates 34>; 132 + resets = <&tcon_ch0_clk 0>; 133 + 134 + port { 135 + #address-cells = <1>; 136 + #size-cells = <0>; 137 + 138 + tve0_in_tcon0: endpoint@0 { 139 + reg = <0>; 140 + remote-endpoint = <&tcon0_out_tve0>; 141 + }; 142 + }; 143 + }; 144 + 145 + tcon0: lcd-controller@1c0c000 { 146 + compatible = "allwinner,sun5i-a13-tcon"; 147 + reg = <0x01c0c000 0x1000>; 148 + interrupts = <44>; 149 + resets = <&tcon_ch0_clk 1>; 150 + reset-names = "lcd"; 151 + clocks = <&ahb_gates 36>, 152 + <&tcon_ch0_clk>, 153 + <&tcon_ch1_clk>; 154 + clock-names = "ahb", 155 + "tcon-ch0", 156 + "tcon-ch1"; 157 + clock-output-names = "tcon-pixel-clock"; 158 + 159 + ports { 160 + #address-cells = <1>; 161 + #size-cells = <0>; 162 + 163 + tcon0_in: port@0 { 164 + #address-cells = <1>; 165 + #size-cells = <0>; 166 + reg = <0>; 167 + 168 + tcon0_in_be0: endpoint@0 { 169 + reg = <0>; 170 + remote-endpoint = <&be0_out_tcon0>; 171 + }; 172 + }; 173 + 174 + tcon0_out: port@1 { 175 + #address-cells = <1>; 176 + #size-cells = <0>; 177 + reg = <1>; 178 + 179 + tcon0_out_panel: endpoint@0 { 180 + reg = <0>; 181 + remote-endpoint = <&panel_input>; 182 + }; 183 + 184 + tcon0_out_tve0: endpoint@1 { 185 + reg = <1>; 186 + remote-endpoint = <&tve0_in_tcon0>; 187 + }; 188 + }; 189 + }; 190 + }; 191 + 192 + fe0: display-frontend@1e00000 { 193 + compatible = "allwinner,sun5i-a13-display-frontend"; 194 + reg = <0x01e00000 0x20000>; 195 + interrupts = <47>; 196 + clocks = <&ahb_gates 46>, <&de_fe_clk>, 197 + <&dram_gates 25>; 198 + clock-names = "ahb", "mod", 199 + "ram"; 200 + resets = <&de_fe_clk>; 201 + 202 + ports { 203 + #address-cells = <1>; 204 + #size-cells = <0>; 205 + 206 + fe0_out: port@1 { 207 + #address-cells = <1>; 208 + #size-cells = <0>; 209 + reg = <1>; 210 + 211 + fe0_out_be0: endpoint { 212 + remote-endpoint = <&be0_in_fe0>; 213 + }; 214 + }; 215 + }; 216 + }; 217 + 218 + be0: display-backend@1e60000 { 219 + compatible = "allwinner,sun5i-a13-display-backend"; 220 + reg = <0x01e60000 0x10000>; 221 + clocks = <&ahb_gates 44>, <&de_be_clk>, 222 + <&dram_gates 26>; 223 + clock-names = "ahb", "mod", 224 + "ram"; 225 + resets = <&de_be_clk>; 226 + 227 + ports { 228 + #address-cells = <1>; 229 + #size-cells = <0>; 230 + 231 + be0_in: port@0 { 232 + #address-cells = <1>; 233 + #size-cells = <0>; 234 + reg = <0>; 235 + 236 + be0_in_fe0: endpoint@0 { 237 + reg = <0>; 238 + remote-endpoint = <&fe0_out_be0>; 239 + }; 240 + }; 241 + 242 + be0_out: port@1 { 243 + #address-cells = <1>; 244 + #size-cells = <0>; 245 + reg = <1>; 246 + 247 + be0_out_tcon0: endpoint@0 { 248 + reg = <0>; 249 + remote-endpoint = <&tcon0_in_be0>; 250 + }; 251 + }; 252 + }; 253 + }; 254 + 255 + display-engine { 256 + compatible = "allwinner,sun5i-a13-display-engine"; 257 + allwinner,pipelines = <&fe0>; 258 + };
+7
MAINTAINERS
··· 3809 3809 F: drivers/gpu/drm/atmel-hlcdc/ 3810 3810 F: Documentation/devicetree/bindings/drm/atmel/ 3811 3811 3812 + DRM DRIVERS FOR ALLWINNER A10 3813 + M: Maxime Ripard <maxime.ripard@free-electrons.com> 3814 + L: dri-devel@lists.freedesktop.org 3815 + S: Supported 3816 + F: drivers/gpu/drm/sun4i/ 3817 + F: Documentation/devicetree/bindings/display/sunxi/sun4i-drm.txt 3818 + 3812 3819 DRM DRIVERS FOR EXYNOS 3813 3820 M: Inki Dae <inki.dae@samsung.com> 3814 3821 M: Joonyoung Shim <jy0922.shim@samsung.com>
+2
drivers/gpu/drm/Kconfig
··· 252 252 253 253 source "drivers/gpu/drm/shmobile/Kconfig" 254 254 255 + source "drivers/gpu/drm/sun4i/Kconfig" 256 + 255 257 source "drivers/gpu/drm/omapdrm/Kconfig" 256 258 257 259 source "drivers/gpu/drm/tilcdc/Kconfig"
+2 -1
drivers/gpu/drm/Makefile
··· 1 - # 1 + 2 2 # Makefile for the drm device driver. This driver provides support for the 3 3 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. 4 4 ··· 65 65 obj-$(CONFIG_DRM_RCAR_DU) += rcar-du/ 66 66 obj-$(CONFIG_DRM_SHMOBILE) +=shmobile/ 67 67 obj-y += omapdrm/ 68 + obj-$(CONFIG_DRM_SUN4I) += sun4i/ 68 69 obj-y += tilcdc/ 69 70 obj-$(CONFIG_DRM_QXL) += qxl/ 70 71 obj-$(CONFIG_DRM_BOCHS) += bochs/
+14
drivers/gpu/drm/sun4i/Kconfig
··· 1 + config DRM_SUN4I 2 + tristate "DRM Support for Allwinner A10 Display Engine" 3 + depends on DRM && ARM 4 + depends on ARCH_SUNXI || COMPILE_TEST 5 + select DRM_GEM_CMA_HELPER 6 + select DRM_KMS_HELPER 7 + select DRM_KMS_CMA_HELPER 8 + select DRM_PANEL 9 + select REGMAP_MMIO 10 + select VIDEOMODE_HELPERS 11 + help 12 + Choose this option if you have an Allwinner SoC with a 13 + Display Engine. If M is selected the module will be called 14 + sun4i-drm.
+13
drivers/gpu/drm/sun4i/Makefile
··· 1 + sun4i-drm-y += sun4i_crtc.o 2 + sun4i-drm-y += sun4i_drv.o 3 + sun4i-drm-y += sun4i_framebuffer.o 4 + sun4i-drm-y += sun4i_layer.o 5 + 6 + sun4i-tcon-y += sun4i_tcon.o 7 + sun4i-tcon-y += sun4i_rgb.o 8 + sun4i-tcon-y += sun4i_dotclock.o 9 + 10 + obj-$(CONFIG_DRM_SUN4I) += sun4i-drm.o sun4i-tcon.o 11 + obj-$(CONFIG_DRM_SUN4I) += sun4i_backend.o 12 + 13 + obj-$(CONFIG_DRM_SUN4I) += sun4i_tv.o
+364
drivers/gpu/drm/sun4i/sun4i_backend.c
··· 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_fb_cma_helper.h> 18 + #include <drm/drm_gem_cma_helper.h> 19 + #include <drm/drm_plane_helper.h> 20 + 21 + #include <linux/component.h> 22 + #include <linux/reset.h> 23 + 24 + #include "sun4i_backend.h" 25 + #include "sun4i_drv.h" 26 + 27 + static u32 sunxi_rgb2yuv_coef[12] = { 28 + 0x00000107, 0x00000204, 0x00000064, 0x00000108, 29 + 0x00003f69, 0x00003ed6, 0x000001c1, 0x00000808, 30 + 0x000001c1, 0x00003e88, 0x00003fb8, 0x00000808 31 + }; 32 + 33 + void sun4i_backend_apply_color_correction(struct sun4i_backend *backend) 34 + { 35 + int i; 36 + 37 + DRM_DEBUG_DRIVER("Applying RGB to YUV color correction\n"); 38 + 39 + /* Set color correction */ 40 + regmap_write(backend->regs, SUN4I_BACKEND_OCCTL_REG, 41 + SUN4I_BACKEND_OCCTL_ENABLE); 42 + 43 + for (i = 0; i < 12; i++) 44 + regmap_write(backend->regs, SUN4I_BACKEND_OCRCOEF_REG(i), 45 + sunxi_rgb2yuv_coef[i]); 46 + } 47 + EXPORT_SYMBOL(sun4i_backend_apply_color_correction); 48 + 49 + void sun4i_backend_disable_color_correction(struct sun4i_backend *backend) 50 + { 51 + DRM_DEBUG_DRIVER("Disabling color correction\n"); 52 + 53 + /* Disable color correction */ 54 + regmap_update_bits(backend->regs, SUN4I_BACKEND_OCCTL_REG, 55 + SUN4I_BACKEND_OCCTL_ENABLE, 0); 56 + } 57 + EXPORT_SYMBOL(sun4i_backend_disable_color_correction); 58 + 59 + void sun4i_backend_commit(struct sun4i_backend *backend) 60 + { 61 + DRM_DEBUG_DRIVER("Committing changes\n"); 62 + 63 + regmap_write(backend->regs, SUN4I_BACKEND_REGBUFFCTL_REG, 64 + SUN4I_BACKEND_REGBUFFCTL_AUTOLOAD_DIS | 65 + SUN4I_BACKEND_REGBUFFCTL_LOADCTL); 66 + } 67 + EXPORT_SYMBOL(sun4i_backend_commit); 68 + 69 + void sun4i_backend_layer_enable(struct sun4i_backend *backend, 70 + int layer, bool enable) 71 + { 72 + u32 val; 73 + 74 + DRM_DEBUG_DRIVER("Enabling layer %d\n", layer); 75 + 76 + if (enable) 77 + val = SUN4I_BACKEND_MODCTL_LAY_EN(layer); 78 + else 79 + val = 0; 80 + 81 + regmap_update_bits(backend->regs, SUN4I_BACKEND_MODCTL_REG, 82 + SUN4I_BACKEND_MODCTL_LAY_EN(layer), val); 83 + } 84 + EXPORT_SYMBOL(sun4i_backend_layer_enable); 85 + 86 + static int sun4i_backend_drm_format_to_layer(u32 format, u32 *mode) 87 + { 88 + switch (format) { 89 + case DRM_FORMAT_ARGB8888: 90 + *mode = SUN4I_BACKEND_LAY_FBFMT_ARGB8888; 91 + break; 92 + 93 + case DRM_FORMAT_XRGB8888: 94 + *mode = SUN4I_BACKEND_LAY_FBFMT_XRGB8888; 95 + break; 96 + 97 + case DRM_FORMAT_RGB888: 98 + *mode = SUN4I_BACKEND_LAY_FBFMT_RGB888; 99 + break; 100 + 101 + default: 102 + return -EINVAL; 103 + } 104 + 105 + return 0; 106 + } 107 + 108 + int sun4i_backend_update_layer_coord(struct sun4i_backend *backend, 109 + int layer, struct drm_plane *plane) 110 + { 111 + struct drm_plane_state *state = plane->state; 112 + struct drm_framebuffer *fb = state->fb; 113 + 114 + DRM_DEBUG_DRIVER("Updating layer %d\n", layer); 115 + 116 + if (plane->type == DRM_PLANE_TYPE_PRIMARY) { 117 + DRM_DEBUG_DRIVER("Primary layer, updating global size W: %u H: %u\n", 118 + state->crtc_w, state->crtc_h); 119 + regmap_write(backend->regs, SUN4I_BACKEND_DISSIZE_REG, 120 + SUN4I_BACKEND_DISSIZE(state->crtc_w, 121 + state->crtc_h)); 122 + } 123 + 124 + /* Set the line width */ 125 + DRM_DEBUG_DRIVER("Layer line width: %d bits\n", fb->pitches[0] * 8); 126 + regmap_write(backend->regs, SUN4I_BACKEND_LAYLINEWIDTH_REG(layer), 127 + fb->pitches[0] * 8); 128 + 129 + /* Set height and width */ 130 + DRM_DEBUG_DRIVER("Layer size W: %u H: %u\n", 131 + state->crtc_w, state->crtc_h); 132 + regmap_write(backend->regs, SUN4I_BACKEND_LAYSIZE_REG(layer), 133 + SUN4I_BACKEND_LAYSIZE(state->crtc_w, 134 + state->crtc_h)); 135 + 136 + /* Set base coordinates */ 137 + DRM_DEBUG_DRIVER("Layer coordinates X: %d Y: %d\n", 138 + state->crtc_x, state->crtc_y); 139 + regmap_write(backend->regs, SUN4I_BACKEND_LAYCOOR_REG(layer), 140 + SUN4I_BACKEND_LAYCOOR(state->crtc_x, 141 + state->crtc_y)); 142 + 143 + return 0; 144 + } 145 + EXPORT_SYMBOL(sun4i_backend_update_layer_coord); 146 + 147 + int sun4i_backend_update_layer_formats(struct sun4i_backend *backend, 148 + int layer, struct drm_plane *plane) 149 + { 150 + struct drm_plane_state *state = plane->state; 151 + struct drm_framebuffer *fb = state->fb; 152 + bool interlaced = false; 153 + u32 val; 154 + int ret; 155 + 156 + if (plane->state->crtc) 157 + interlaced = plane->state->crtc->state->adjusted_mode.flags 158 + & DRM_MODE_FLAG_INTERLACE; 159 + 160 + regmap_update_bits(backend->regs, SUN4I_BACKEND_MODCTL_REG, 161 + SUN4I_BACKEND_MODCTL_ITLMOD_EN, 162 + interlaced ? SUN4I_BACKEND_MODCTL_ITLMOD_EN : 0); 163 + 164 + DRM_DEBUG_DRIVER("Switching display backend interlaced mode %s\n", 165 + interlaced ? "on" : "off"); 166 + 167 + ret = sun4i_backend_drm_format_to_layer(fb->pixel_format, &val); 168 + if (ret) { 169 + DRM_DEBUG_DRIVER("Invalid format\n"); 170 + return val; 171 + } 172 + 173 + regmap_update_bits(backend->regs, SUN4I_BACKEND_ATTCTL_REG1(layer), 174 + SUN4I_BACKEND_ATTCTL_REG1_LAY_FBFMT, val); 175 + 176 + return 0; 177 + } 178 + EXPORT_SYMBOL(sun4i_backend_update_layer_formats); 179 + 180 + int sun4i_backend_update_layer_buffer(struct sun4i_backend *backend, 181 + int layer, struct drm_plane *plane) 182 + { 183 + struct drm_plane_state *state = plane->state; 184 + struct drm_framebuffer *fb = state->fb; 185 + struct drm_gem_cma_object *gem; 186 + u32 lo_paddr, hi_paddr; 187 + dma_addr_t paddr; 188 + int bpp; 189 + 190 + /* Get the physical address of the buffer in memory */ 191 + gem = drm_fb_cma_get_gem_obj(fb, 0); 192 + 193 + DRM_DEBUG_DRIVER("Using GEM @ 0x%x\n", gem->paddr); 194 + 195 + /* Compute the start of the displayed memory */ 196 + bpp = drm_format_plane_cpp(fb->pixel_format, 0); 197 + paddr = gem->paddr + fb->offsets[0]; 198 + paddr += (state->src_x >> 16) * bpp; 199 + paddr += (state->src_y >> 16) * fb->pitches[0]; 200 + 201 + DRM_DEBUG_DRIVER("Setting buffer address to 0x%x\n", paddr); 202 + 203 + /* Write the 32 lower bits of the address (in bits) */ 204 + lo_paddr = paddr << 3; 205 + DRM_DEBUG_DRIVER("Setting address lower bits to 0x%x\n", lo_paddr); 206 + regmap_write(backend->regs, SUN4I_BACKEND_LAYFB_L32ADD_REG(layer), 207 + lo_paddr); 208 + 209 + /* And the upper bits */ 210 + hi_paddr = paddr >> 29; 211 + DRM_DEBUG_DRIVER("Setting address high bits to 0x%x\n", hi_paddr); 212 + regmap_update_bits(backend->regs, SUN4I_BACKEND_LAYFB_H4ADD_REG, 213 + SUN4I_BACKEND_LAYFB_H4ADD_MSK(layer), 214 + SUN4I_BACKEND_LAYFB_H4ADD(layer, hi_paddr)); 215 + 216 + return 0; 217 + } 218 + EXPORT_SYMBOL(sun4i_backend_update_layer_buffer); 219 + 220 + static struct regmap_config sun4i_backend_regmap_config = { 221 + .reg_bits = 32, 222 + .val_bits = 32, 223 + .reg_stride = 4, 224 + .max_register = 0x5800, 225 + }; 226 + 227 + static int sun4i_backend_bind(struct device *dev, struct device *master, 228 + void *data) 229 + { 230 + struct platform_device *pdev = to_platform_device(dev); 231 + struct drm_device *drm = data; 232 + struct sun4i_drv *drv = drm->dev_private; 233 + struct sun4i_backend *backend; 234 + struct resource *res; 235 + void __iomem *regs; 236 + int i, ret; 237 + 238 + backend = devm_kzalloc(dev, sizeof(*backend), GFP_KERNEL); 239 + if (!backend) 240 + return -ENOMEM; 241 + dev_set_drvdata(dev, backend); 242 + drv->backend = backend; 243 + 244 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 245 + regs = devm_ioremap_resource(dev, res); 246 + if (IS_ERR(regs)) { 247 + dev_err(dev, "Couldn't map the backend registers\n"); 248 + return PTR_ERR(regs); 249 + } 250 + 251 + backend->regs = devm_regmap_init_mmio(dev, regs, 252 + &sun4i_backend_regmap_config); 253 + if (IS_ERR(backend->regs)) { 254 + dev_err(dev, "Couldn't create the backend0 regmap\n"); 255 + return PTR_ERR(backend->regs); 256 + } 257 + 258 + backend->reset = devm_reset_control_get(dev, NULL); 259 + if (IS_ERR(backend->reset)) { 260 + dev_err(dev, "Couldn't get our reset line\n"); 261 + return PTR_ERR(backend->reset); 262 + } 263 + 264 + ret = reset_control_deassert(backend->reset); 265 + if (ret) { 266 + dev_err(dev, "Couldn't deassert our reset line\n"); 267 + return ret; 268 + } 269 + 270 + backend->bus_clk = devm_clk_get(dev, "ahb"); 271 + if (IS_ERR(backend->bus_clk)) { 272 + dev_err(dev, "Couldn't get the backend bus clock\n"); 273 + ret = PTR_ERR(backend->bus_clk); 274 + goto err_assert_reset; 275 + } 276 + clk_prepare_enable(backend->bus_clk); 277 + 278 + backend->mod_clk = devm_clk_get(dev, "mod"); 279 + if (IS_ERR(backend->mod_clk)) { 280 + dev_err(dev, "Couldn't get the backend module clock\n"); 281 + ret = PTR_ERR(backend->mod_clk); 282 + goto err_disable_bus_clk; 283 + } 284 + clk_prepare_enable(backend->mod_clk); 285 + 286 + backend->ram_clk = devm_clk_get(dev, "ram"); 287 + if (IS_ERR(backend->ram_clk)) { 288 + dev_err(dev, "Couldn't get the backend RAM clock\n"); 289 + ret = PTR_ERR(backend->ram_clk); 290 + goto err_disable_mod_clk; 291 + } 292 + clk_prepare_enable(backend->ram_clk); 293 + 294 + /* Reset the registers */ 295 + for (i = 0x800; i < 0x1000; i += 4) 296 + regmap_write(backend->regs, i, 0); 297 + 298 + /* Disable registers autoloading */ 299 + regmap_write(backend->regs, SUN4I_BACKEND_REGBUFFCTL_REG, 300 + SUN4I_BACKEND_REGBUFFCTL_AUTOLOAD_DIS); 301 + 302 + /* Enable the backend */ 303 + regmap_write(backend->regs, SUN4I_BACKEND_MODCTL_REG, 304 + SUN4I_BACKEND_MODCTL_DEBE_EN | 305 + SUN4I_BACKEND_MODCTL_START_CTL); 306 + 307 + return 0; 308 + 309 + err_disable_mod_clk: 310 + clk_disable_unprepare(backend->mod_clk); 311 + err_disable_bus_clk: 312 + clk_disable_unprepare(backend->bus_clk); 313 + err_assert_reset: 314 + reset_control_assert(backend->reset); 315 + return ret; 316 + } 317 + 318 + static void sun4i_backend_unbind(struct device *dev, struct device *master, 319 + void *data) 320 + { 321 + struct sun4i_backend *backend = dev_get_drvdata(dev); 322 + 323 + clk_disable_unprepare(backend->ram_clk); 324 + clk_disable_unprepare(backend->mod_clk); 325 + clk_disable_unprepare(backend->bus_clk); 326 + reset_control_assert(backend->reset); 327 + } 328 + 329 + static struct component_ops sun4i_backend_ops = { 330 + .bind = sun4i_backend_bind, 331 + .unbind = sun4i_backend_unbind, 332 + }; 333 + 334 + static int sun4i_backend_probe(struct platform_device *pdev) 335 + { 336 + return component_add(&pdev->dev, &sun4i_backend_ops); 337 + } 338 + 339 + static int sun4i_backend_remove(struct platform_device *pdev) 340 + { 341 + component_del(&pdev->dev, &sun4i_backend_ops); 342 + 343 + return 0; 344 + } 345 + 346 + static const struct of_device_id sun4i_backend_of_table[] = { 347 + { .compatible = "allwinner,sun5i-a13-display-backend" }, 348 + { } 349 + }; 350 + MODULE_DEVICE_TABLE(of, sun4i_backend_of_table); 351 + 352 + static struct platform_driver sun4i_backend_platform_driver = { 353 + .probe = sun4i_backend_probe, 354 + .remove = sun4i_backend_remove, 355 + .driver = { 356 + .name = "sun4i-backend", 357 + .of_match_table = sun4i_backend_of_table, 358 + }, 359 + }; 360 + module_platform_driver(sun4i_backend_platform_driver); 361 + 362 + MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 363 + MODULE_DESCRIPTION("Allwinner A10 Display Backend Driver"); 364 + MODULE_LICENSE("GPL");
+165
drivers/gpu/drm/sun4i/sun4i_backend.h
··· 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 + #ifndef _SUN4I_BACKEND_H_ 14 + #define _SUN4I_BACKEND_H_ 15 + 16 + #include <linux/clk.h> 17 + #include <linux/regmap.h> 18 + #include <linux/reset.h> 19 + 20 + #define SUN4I_BACKEND_MODCTL_REG 0x800 21 + #define SUN4I_BACKEND_MODCTL_LINE_SEL BIT(29) 22 + #define SUN4I_BACKEND_MODCTL_ITLMOD_EN BIT(28) 23 + #define SUN4I_BACKEND_MODCTL_OUT_SEL GENMASK(22, 20) 24 + #define SUN4I_BACKEND_MODCTL_OUT_LCD (0 << 20) 25 + #define SUN4I_BACKEND_MODCTL_OUT_FE0 (6 << 20) 26 + #define SUN4I_BACKEND_MODCTL_OUT_FE1 (7 << 20) 27 + #define SUN4I_BACKEND_MODCTL_HWC_EN BIT(16) 28 + #define SUN4I_BACKEND_MODCTL_LAY_EN(l) BIT(8 + l) 29 + #define SUN4I_BACKEND_MODCTL_OCSC_EN BIT(5) 30 + #define SUN4I_BACKEND_MODCTL_DFLK_EN BIT(4) 31 + #define SUN4I_BACKEND_MODCTL_DLP_START_CTL BIT(2) 32 + #define SUN4I_BACKEND_MODCTL_START_CTL BIT(1) 33 + #define SUN4I_BACKEND_MODCTL_DEBE_EN BIT(0) 34 + 35 + #define SUN4I_BACKEND_BACKCOLOR_REG 0x804 36 + #define SUN4I_BACKEND_BACKCOLOR(r, g, b) (((r) << 16) | ((g) << 8) | (b)) 37 + 38 + #define SUN4I_BACKEND_DISSIZE_REG 0x808 39 + #define SUN4I_BACKEND_DISSIZE(w, h) (((((h) - 1) & 0xffff) << 16) | \ 40 + (((w) - 1) & 0xffff)) 41 + 42 + #define SUN4I_BACKEND_LAYSIZE_REG(l) (0x810 + (0x4 * (l))) 43 + #define SUN4I_BACKEND_LAYSIZE(w, h) (((((h) - 1) & 0x1fff) << 16) | \ 44 + (((w) - 1) & 0x1fff)) 45 + 46 + #define SUN4I_BACKEND_LAYCOOR_REG(l) (0x820 + (0x4 * (l))) 47 + #define SUN4I_BACKEND_LAYCOOR(x, y) ((((u32)(y) & 0xffff) << 16) | \ 48 + ((u32)(x) & 0xffff)) 49 + 50 + #define SUN4I_BACKEND_LAYLINEWIDTH_REG(l) (0x840 + (0x4 * (l))) 51 + 52 + #define SUN4I_BACKEND_LAYFB_L32ADD_REG(l) (0x850 + (0x4 * (l))) 53 + 54 + #define SUN4I_BACKEND_LAYFB_H4ADD_REG 0x860 55 + #define SUN4I_BACKEND_LAYFB_H4ADD_MSK(l) GENMASK(3 + ((l) * 8), 0) 56 + #define SUN4I_BACKEND_LAYFB_H4ADD(l, val) ((val) << ((l) * 8)) 57 + 58 + #define SUN4I_BACKEND_REGBUFFCTL_REG 0x870 59 + #define SUN4I_BACKEND_REGBUFFCTL_AUTOLOAD_DIS BIT(1) 60 + #define SUN4I_BACKEND_REGBUFFCTL_LOADCTL BIT(0) 61 + 62 + #define SUN4I_BACKEND_CKMAX_REG 0x880 63 + #define SUN4I_BACKEND_CKMIN_REG 0x884 64 + #define SUN4I_BACKEND_CKCFG_REG 0x888 65 + #define SUN4I_BACKEND_ATTCTL_REG0(l) (0x890 + (0x4 * (l))) 66 + #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL_MASK BIT(15) 67 + #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL(x) ((x) << 15) 68 + #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PRISEL_MASK GENMASK(11, 10) 69 + #define SUN4I_BACKEND_ATTCTL_REG0_LAY_PRISEL(x) ((x) << 10) 70 + 71 + #define SUN4I_BACKEND_ATTCTL_REG1(l) (0x8a0 + (0x4 * (l))) 72 + #define SUN4I_BACKEND_ATTCTL_REG1_LAY_HSCAFCT GENMASK(15, 14) 73 + #define SUN4I_BACKEND_ATTCTL_REG1_LAY_WSCAFCT GENMASK(13, 12) 74 + #define SUN4I_BACKEND_ATTCTL_REG1_LAY_FBFMT GENMASK(11, 8) 75 + #define SUN4I_BACKEND_LAY_FBFMT_1BPP (0 << 8) 76 + #define SUN4I_BACKEND_LAY_FBFMT_2BPP (1 << 8) 77 + #define SUN4I_BACKEND_LAY_FBFMT_4BPP (2 << 8) 78 + #define SUN4I_BACKEND_LAY_FBFMT_8BPP (3 << 8) 79 + #define SUN4I_BACKEND_LAY_FBFMT_RGB655 (4 << 8) 80 + #define SUN4I_BACKEND_LAY_FBFMT_RGB565 (5 << 8) 81 + #define SUN4I_BACKEND_LAY_FBFMT_RGB556 (6 << 8) 82 + #define SUN4I_BACKEND_LAY_FBFMT_ARGB1555 (7 << 8) 83 + #define SUN4I_BACKEND_LAY_FBFMT_RGBA5551 (8 << 8) 84 + #define SUN4I_BACKEND_LAY_FBFMT_XRGB8888 (9 << 8) 85 + #define SUN4I_BACKEND_LAY_FBFMT_ARGB8888 (10 << 8) 86 + #define SUN4I_BACKEND_LAY_FBFMT_RGB888 (11 << 8) 87 + #define SUN4I_BACKEND_LAY_FBFMT_ARGB4444 (12 << 8) 88 + #define SUN4I_BACKEND_LAY_FBFMT_RGBA4444 (13 << 8) 89 + 90 + #define SUN4I_BACKEND_DLCDPCTL_REG 0x8b0 91 + #define SUN4I_BACKEND_DLCDPFRMBUF_ADDRCTL_REG 0x8b4 92 + #define SUN4I_BACKEND_DLCDPCOOR_REG0 0x8b8 93 + #define SUN4I_BACKEND_DLCDPCOOR_REG1 0x8bc 94 + 95 + #define SUN4I_BACKEND_INT_EN_REG 0x8c0 96 + #define SUN4I_BACKEND_INT_FLAG_REG 0x8c4 97 + #define SUN4I_BACKEND_REG_LOAD_FINISHED BIT(1) 98 + 99 + #define SUN4I_BACKEND_HWCCTL_REG 0x8d8 100 + #define SUN4I_BACKEND_HWCFBCTL_REG 0x8e0 101 + #define SUN4I_BACKEND_WBCTL_REG 0x8f0 102 + #define SUN4I_BACKEND_WBADD_REG 0x8f4 103 + #define SUN4I_BACKEND_WBLINEWIDTH_REG 0x8f8 104 + #define SUN4I_BACKEND_SPREN_REG 0x900 105 + #define SUN4I_BACKEND_SPRFMTCTL_REG 0x908 106 + #define SUN4I_BACKEND_SPRALPHACTL_REG 0x90c 107 + #define SUN4I_BACKEND_IYUVCTL_REG 0x920 108 + #define SUN4I_BACKEND_IYUVADD_REG(c) (0x930 + (0x4 * (c))) 109 + #define SUN4I_BACKEND_IYUVLINEWITDTH_REG(c) (0x940 + (0x4 * (c))) 110 + #define SUN4I_BACKEND_YGCOEF_REG(c) (0x950 + (0x4 * (c))) 111 + #define SUN4I_BACKEND_YGCONS_REG 0x95c 112 + #define SUN4I_BACKEND_URCOEF_REG(c) (0x960 + (0x4 * (c))) 113 + #define SUN4I_BACKEND_URCONS_REG 0x96c 114 + #define SUN4I_BACKEND_VBCOEF_REG(c) (0x970 + (0x4 * (c))) 115 + #define SUN4I_BACKEND_VBCONS_REG 0x97c 116 + #define SUN4I_BACKEND_KSCTL_REG 0x980 117 + #define SUN4I_BACKEND_KSBKCOLOR_REG 0x984 118 + #define SUN4I_BACKEND_KSFSTLINEWIDTH_REG 0x988 119 + #define SUN4I_BACKEND_KSVSCAFCT_REG 0x98c 120 + #define SUN4I_BACKEND_KSHSCACOEF_REG(x) (0x9a0 + (0x4 * (x))) 121 + #define SUN4I_BACKEND_OCCTL_REG 0x9c0 122 + #define SUN4I_BACKEND_OCCTL_ENABLE BIT(0) 123 + 124 + #define SUN4I_BACKEND_OCRCOEF_REG(x) (0x9d0 + (0x4 * (x))) 125 + #define SUN4I_BACKEND_OCRCONS_REG 0x9dc 126 + #define SUN4I_BACKEND_OCGCOEF_REG(x) (0x9e0 + (0x4 * (x))) 127 + #define SUN4I_BACKEND_OCGCONS_REG 0x9ec 128 + #define SUN4I_BACKEND_OCBCOEF_REG(x) (0x9f0 + (0x4 * (x))) 129 + #define SUN4I_BACKEND_OCBCONS_REG 0x9fc 130 + #define SUN4I_BACKEND_SPRCOORCTL_REG(s) (0xa00 + (0x4 * (s))) 131 + #define SUN4I_BACKEND_SPRATTCTL_REG(s) (0xb00 + (0x4 * (s))) 132 + #define SUN4I_BACKEND_SPRADD_REG(s) (0xc00 + (0x4 * (s))) 133 + #define SUN4I_BACKEND_SPRLINEWIDTH_REG(s) (0xd00 + (0x4 * (s))) 134 + 135 + #define SUN4I_BACKEND_SPRPALTAB_OFF 0x4000 136 + #define SUN4I_BACKEND_GAMMATAB_OFF 0x4400 137 + #define SUN4I_BACKEND_HWCPATTERN_OFF 0x4800 138 + #define SUN4I_BACKEND_HWCCOLORTAB_OFF 0x4c00 139 + #define SUN4I_BACKEND_PIPE_OFF(p) (0x5000 + (0x400 * (p))) 140 + 141 + struct sun4i_backend { 142 + struct regmap *regs; 143 + 144 + struct reset_control *reset; 145 + 146 + struct clk *bus_clk; 147 + struct clk *mod_clk; 148 + struct clk *ram_clk; 149 + }; 150 + 151 + void sun4i_backend_apply_color_correction(struct sun4i_backend *backend); 152 + void sun4i_backend_disable_color_correction(struct sun4i_backend *backend); 153 + 154 + void sun4i_backend_commit(struct sun4i_backend *backend); 155 + 156 + void sun4i_backend_layer_enable(struct sun4i_backend *backend, 157 + int layer, bool enable); 158 + int sun4i_backend_update_layer_coord(struct sun4i_backend *backend, 159 + int layer, struct drm_plane *plane); 160 + int sun4i_backend_update_layer_formats(struct sun4i_backend *backend, 161 + int layer, struct drm_plane *plane); 162 + int sun4i_backend_update_layer_buffer(struct sun4i_backend *backend, 163 + int layer, struct drm_plane *plane); 164 + 165 + #endif /* _SUN4I_BACKEND_H_ */
+120
drivers/gpu/drm/sun4i/sun4i_crtc.c
··· 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> 18 + 19 + #include <linux/clk-provider.h> 20 + #include <linux/ioport.h> 21 + #include <linux/of_address.h> 22 + #include <linux/of_irq.h> 23 + #include <linux/regmap.h> 24 + 25 + #include <video/videomode.h> 26 + 27 + #include "sun4i_backend.h" 28 + #include "sun4i_crtc.h" 29 + #include "sun4i_drv.h" 30 + #include "sun4i_tcon.h" 31 + 32 + static void sun4i_crtc_atomic_begin(struct drm_crtc *crtc, 33 + struct drm_crtc_state *old_state) 34 + { 35 + struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc); 36 + struct drm_device *dev = crtc->dev; 37 + unsigned long flags; 38 + 39 + if (crtc->state->event) { 40 + WARN_ON(drm_crtc_vblank_get(crtc) != 0); 41 + 42 + spin_lock_irqsave(&dev->event_lock, flags); 43 + scrtc->event = crtc->state->event; 44 + spin_unlock_irqrestore(&dev->event_lock, flags); 45 + crtc->state->event = NULL; 46 + } 47 + } 48 + 49 + static void sun4i_crtc_atomic_flush(struct drm_crtc *crtc, 50 + struct drm_crtc_state *old_state) 51 + { 52 + struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc); 53 + struct sun4i_drv *drv = scrtc->drv; 54 + 55 + DRM_DEBUG_DRIVER("Committing plane changes\n"); 56 + 57 + sun4i_backend_commit(drv->backend); 58 + } 59 + 60 + static void sun4i_crtc_disable(struct drm_crtc *crtc) 61 + { 62 + struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc); 63 + struct sun4i_drv *drv = scrtc->drv; 64 + 65 + DRM_DEBUG_DRIVER("Disabling the CRTC\n"); 66 + 67 + sun4i_tcon_disable(drv->tcon); 68 + } 69 + 70 + static void sun4i_crtc_enable(struct drm_crtc *crtc) 71 + { 72 + struct sun4i_crtc *scrtc = drm_crtc_to_sun4i_crtc(crtc); 73 + struct sun4i_drv *drv = scrtc->drv; 74 + 75 + DRM_DEBUG_DRIVER("Enabling the CRTC\n"); 76 + 77 + sun4i_tcon_enable(drv->tcon); 78 + } 79 + 80 + static const struct drm_crtc_helper_funcs sun4i_crtc_helper_funcs = { 81 + .atomic_begin = sun4i_crtc_atomic_begin, 82 + .atomic_flush = sun4i_crtc_atomic_flush, 83 + .disable = sun4i_crtc_disable, 84 + .enable = sun4i_crtc_enable, 85 + }; 86 + 87 + static const struct drm_crtc_funcs sun4i_crtc_funcs = { 88 + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, 89 + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, 90 + .destroy = drm_crtc_cleanup, 91 + .page_flip = drm_atomic_helper_page_flip, 92 + .reset = drm_atomic_helper_crtc_reset, 93 + .set_config = drm_atomic_helper_set_config, 94 + }; 95 + 96 + struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm) 97 + { 98 + struct sun4i_drv *drv = drm->dev_private; 99 + struct sun4i_crtc *scrtc; 100 + int ret; 101 + 102 + scrtc = devm_kzalloc(drm->dev, sizeof(*scrtc), GFP_KERNEL); 103 + if (!scrtc) 104 + return NULL; 105 + scrtc->drv = drv; 106 + 107 + ret = drm_crtc_init_with_planes(drm, &scrtc->crtc, 108 + drv->primary, 109 + NULL, 110 + &sun4i_crtc_funcs, 111 + NULL); 112 + if (ret) { 113 + dev_err(drm->dev, "Couldn't init DRM CRTC\n"); 114 + return NULL; 115 + } 116 + 117 + drm_crtc_helper_add(&scrtc->crtc, &sun4i_crtc_helper_funcs); 118 + 119 + return scrtc; 120 + }
+30
drivers/gpu/drm/sun4i/sun4i_crtc.h
··· 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 + #ifndef _SUN4I_CRTC_H_ 14 + #define _SUN4I_CRTC_H_ 15 + 16 + struct sun4i_crtc { 17 + struct drm_crtc crtc; 18 + struct drm_pending_vblank_event *event; 19 + 20 + struct sun4i_drv *drv; 21 + }; 22 + 23 + static inline struct sun4i_crtc *drm_crtc_to_sun4i_crtc(struct drm_crtc *crtc) 24 + { 25 + return container_of(crtc, struct sun4i_crtc, crtc); 26 + } 27 + 28 + struct sun4i_crtc *sun4i_crtc_init(struct drm_device *drm); 29 + 30 + #endif /* _SUN4I_CRTC_H_ */
+160
drivers/gpu/drm/sun4i/sun4i_dotclock.c
··· 1 + /* 2 + * Copyright (C) 2016 Free Electrons 3 + * Copyright (C) 2016 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 <linux/clk-provider.h> 14 + #include <linux/regmap.h> 15 + 16 + #include "sun4i_tcon.h" 17 + 18 + struct sun4i_dclk { 19 + struct clk_hw hw; 20 + struct regmap *regmap; 21 + }; 22 + 23 + static inline struct sun4i_dclk *hw_to_dclk(struct clk_hw *hw) 24 + { 25 + return container_of(hw, struct sun4i_dclk, hw); 26 + } 27 + 28 + static void sun4i_dclk_disable(struct clk_hw *hw) 29 + { 30 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 31 + 32 + regmap_update_bits(dclk->regmap, SUN4I_TCON0_DCLK_REG, 33 + BIT(SUN4I_TCON0_DCLK_GATE_BIT), 0); 34 + } 35 + 36 + static int sun4i_dclk_enable(struct clk_hw *hw) 37 + { 38 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 39 + 40 + return regmap_update_bits(dclk->regmap, SUN4I_TCON0_DCLK_REG, 41 + BIT(SUN4I_TCON0_DCLK_GATE_BIT), 42 + BIT(SUN4I_TCON0_DCLK_GATE_BIT)); 43 + } 44 + 45 + static int sun4i_dclk_is_enabled(struct clk_hw *hw) 46 + { 47 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 48 + u32 val; 49 + 50 + regmap_read(dclk->regmap, SUN4I_TCON0_DCLK_REG, &val); 51 + 52 + return val & BIT(SUN4I_TCON0_DCLK_GATE_BIT); 53 + } 54 + 55 + static unsigned long sun4i_dclk_recalc_rate(struct clk_hw *hw, 56 + unsigned long parent_rate) 57 + { 58 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 59 + u32 val; 60 + 61 + regmap_read(dclk->regmap, SUN4I_TCON0_DCLK_REG, &val); 62 + 63 + val >>= SUN4I_TCON0_DCLK_DIV_SHIFT; 64 + val &= SUN4I_TCON0_DCLK_DIV_WIDTH; 65 + 66 + if (!val) 67 + val = 1; 68 + 69 + return parent_rate / val; 70 + } 71 + 72 + static long sun4i_dclk_round_rate(struct clk_hw *hw, unsigned long rate, 73 + unsigned long *parent_rate) 74 + { 75 + return *parent_rate / DIV_ROUND_CLOSEST(*parent_rate, rate); 76 + } 77 + 78 + static int sun4i_dclk_set_rate(struct clk_hw *hw, unsigned long rate, 79 + unsigned long parent_rate) 80 + { 81 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 82 + int div = DIV_ROUND_CLOSEST(parent_rate, rate); 83 + 84 + return regmap_update_bits(dclk->regmap, SUN4I_TCON0_DCLK_REG, 85 + GENMASK(6, 0), div); 86 + } 87 + 88 + static int sun4i_dclk_get_phase(struct clk_hw *hw) 89 + { 90 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 91 + u32 val; 92 + 93 + regmap_read(dclk->regmap, SUN4I_TCON0_IO_POL_REG, &val); 94 + 95 + val >>= 28; 96 + val &= 3; 97 + 98 + return val * 120; 99 + } 100 + 101 + static int sun4i_dclk_set_phase(struct clk_hw *hw, int degrees) 102 + { 103 + struct sun4i_dclk *dclk = hw_to_dclk(hw); 104 + 105 + regmap_update_bits(dclk->regmap, SUN4I_TCON0_IO_POL_REG, 106 + GENMASK(29, 28), 107 + degrees / 120); 108 + 109 + return 0; 110 + } 111 + 112 + static const struct clk_ops sun4i_dclk_ops = { 113 + .disable = sun4i_dclk_disable, 114 + .enable = sun4i_dclk_enable, 115 + .is_enabled = sun4i_dclk_is_enabled, 116 + 117 + .recalc_rate = sun4i_dclk_recalc_rate, 118 + .round_rate = sun4i_dclk_round_rate, 119 + .set_rate = sun4i_dclk_set_rate, 120 + 121 + .get_phase = sun4i_dclk_get_phase, 122 + .set_phase = sun4i_dclk_set_phase, 123 + }; 124 + 125 + int sun4i_dclk_create(struct device *dev, struct sun4i_tcon *tcon) 126 + { 127 + const char *clk_name, *parent_name; 128 + struct clk_init_data init; 129 + struct sun4i_dclk *dclk; 130 + 131 + parent_name = __clk_get_name(tcon->sclk0); 132 + of_property_read_string_index(dev->of_node, "clock-output-names", 0, 133 + &clk_name); 134 + 135 + dclk = devm_kzalloc(dev, sizeof(*dclk), GFP_KERNEL); 136 + if (!dclk) 137 + return -ENOMEM; 138 + 139 + init.name = clk_name; 140 + init.ops = &sun4i_dclk_ops; 141 + init.parent_names = &parent_name; 142 + init.num_parents = 1; 143 + 144 + dclk->regmap = tcon->regs; 145 + dclk->hw.init = &init; 146 + 147 + tcon->dclk = clk_register(dev, &dclk->hw); 148 + if (IS_ERR(tcon->dclk)) 149 + return PTR_ERR(tcon->dclk); 150 + 151 + return 0; 152 + } 153 + EXPORT_SYMBOL(sun4i_dclk_create); 154 + 155 + int sun4i_dclk_free(struct sun4i_tcon *tcon) 156 + { 157 + clk_unregister(tcon->dclk); 158 + return 0; 159 + } 160 + EXPORT_SYMBOL(sun4i_dclk_free);
+21
drivers/gpu/drm/sun4i/sun4i_dotclock.h
··· 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 + #ifndef _SUN4I_DOTCLOCK_H_ 14 + #define _SUN4I_DOTCLOCK_H_ 15 + 16 + struct sun4i_tcon; 17 + 18 + int sun4i_dclk_create(struct device *dev, struct sun4i_tcon *tcon); 19 + int sun4i_dclk_free(struct sun4i_tcon *tcon); 20 + 21 + #endif /* _SUN4I_DOTCLOCK_H_ */
+358
drivers/gpu/drm/sun4i/sun4i_drv.c
··· 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 <linux/component.h> 14 + #include <linux/of_graph.h> 15 + 16 + #include <drm/drmP.h> 17 + #include <drm/drm_crtc_helper.h> 18 + #include <drm/drm_fb_cma_helper.h> 19 + #include <drm/drm_gem_cma_helper.h> 20 + 21 + #include "sun4i_crtc.h" 22 + #include "sun4i_drv.h" 23 + #include "sun4i_framebuffer.h" 24 + #include "sun4i_layer.h" 25 + #include "sun4i_tcon.h" 26 + 27 + static int sun4i_drv_connector_plug_all(struct drm_device *drm) 28 + { 29 + struct drm_connector *connector, *failed; 30 + int ret; 31 + 32 + mutex_lock(&drm->mode_config.mutex); 33 + list_for_each_entry(connector, &drm->mode_config.connector_list, head) { 34 + ret = drm_connector_register(connector); 35 + if (ret) { 36 + failed = connector; 37 + goto err; 38 + } 39 + } 40 + mutex_unlock(&drm->mode_config.mutex); 41 + return 0; 42 + 43 + err: 44 + list_for_each_entry(connector, &drm->mode_config.connector_list, head) { 45 + if (failed == connector) 46 + break; 47 + 48 + drm_connector_unregister(connector); 49 + } 50 + mutex_unlock(&drm->mode_config.mutex); 51 + 52 + return ret; 53 + } 54 + 55 + static int sun4i_drv_enable_vblank(struct drm_device *drm, unsigned int pipe) 56 + { 57 + struct sun4i_drv *drv = drm->dev_private; 58 + struct sun4i_tcon *tcon = drv->tcon; 59 + 60 + DRM_DEBUG_DRIVER("Enabling VBLANK on pipe %d\n", pipe); 61 + 62 + sun4i_tcon_enable_vblank(tcon, true); 63 + 64 + return 0; 65 + } 66 + 67 + static void sun4i_drv_disable_vblank(struct drm_device *drm, unsigned int pipe) 68 + { 69 + struct sun4i_drv *drv = drm->dev_private; 70 + struct sun4i_tcon *tcon = drv->tcon; 71 + 72 + DRM_DEBUG_DRIVER("Disabling VBLANK on pipe %d\n", pipe); 73 + 74 + sun4i_tcon_enable_vblank(tcon, false); 75 + } 76 + 77 + static const struct file_operations sun4i_drv_fops = { 78 + .owner = THIS_MODULE, 79 + .open = drm_open, 80 + .release = drm_release, 81 + .unlocked_ioctl = drm_ioctl, 82 + #ifdef CONFIG_COMPAT 83 + .compat_ioctl = drm_compat_ioctl, 84 + #endif 85 + .poll = drm_poll, 86 + .read = drm_read, 87 + .llseek = no_llseek, 88 + .mmap = drm_gem_cma_mmap, 89 + }; 90 + 91 + static struct drm_driver sun4i_drv_driver = { 92 + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_ATOMIC, 93 + 94 + /* Generic Operations */ 95 + .fops = &sun4i_drv_fops, 96 + .name = "sun4i-drm", 97 + .desc = "Allwinner sun4i Display Engine", 98 + .date = "20150629", 99 + .major = 1, 100 + .minor = 0, 101 + 102 + /* GEM Operations */ 103 + .dumb_create = drm_gem_cma_dumb_create, 104 + .dumb_destroy = drm_gem_dumb_destroy, 105 + .dumb_map_offset = drm_gem_cma_dumb_map_offset, 106 + .gem_free_object = drm_gem_cma_free_object, 107 + .gem_vm_ops = &drm_gem_cma_vm_ops, 108 + 109 + /* PRIME Operations */ 110 + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, 111 + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, 112 + .gem_prime_import = drm_gem_prime_import, 113 + .gem_prime_export = drm_gem_prime_export, 114 + .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table, 115 + .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table, 116 + .gem_prime_vmap = drm_gem_cma_prime_vmap, 117 + .gem_prime_vunmap = drm_gem_cma_prime_vunmap, 118 + .gem_prime_mmap = drm_gem_cma_prime_mmap, 119 + 120 + /* Frame Buffer Operations */ 121 + 122 + /* VBlank Operations */ 123 + .get_vblank_counter = drm_vblank_count, 124 + .enable_vblank = sun4i_drv_enable_vblank, 125 + .disable_vblank = sun4i_drv_disable_vblank, 126 + }; 127 + 128 + static int sun4i_drv_bind(struct device *dev) 129 + { 130 + struct drm_device *drm; 131 + struct sun4i_drv *drv; 132 + int ret; 133 + 134 + drm = drm_dev_alloc(&sun4i_drv_driver, dev); 135 + if (!drm) 136 + return -ENOMEM; 137 + 138 + ret = drm_dev_set_unique(drm, dev_name(drm->dev)); 139 + if (ret) 140 + goto free_drm; 141 + 142 + drv = devm_kzalloc(dev, sizeof(*drv), GFP_KERNEL); 143 + if (!drv) { 144 + ret = -ENOMEM; 145 + goto free_drm; 146 + } 147 + drm->dev_private = drv; 148 + 149 + drm_vblank_init(drm, 1); 150 + drm_mode_config_init(drm); 151 + 152 + ret = component_bind_all(drm->dev, drm); 153 + if (ret) { 154 + dev_err(drm->dev, "Couldn't bind all pipelines components\n"); 155 + goto free_drm; 156 + } 157 + 158 + /* Create our layers */ 159 + drv->layers = sun4i_layers_init(drm); 160 + if (!drv->layers) { 161 + dev_err(drm->dev, "Couldn't create the planes\n"); 162 + ret = -EINVAL; 163 + goto free_drm; 164 + } 165 + 166 + /* Create our CRTC */ 167 + drv->crtc = sun4i_crtc_init(drm); 168 + if (!drv->crtc) { 169 + dev_err(drm->dev, "Couldn't create the CRTC\n"); 170 + ret = -EINVAL; 171 + goto free_drm; 172 + } 173 + drm->irq_enabled = true; 174 + 175 + /* Create our framebuffer */ 176 + drv->fbdev = sun4i_framebuffer_init(drm); 177 + if (IS_ERR(drv->fbdev)) { 178 + dev_err(drm->dev, "Couldn't create our framebuffer\n"); 179 + ret = PTR_ERR(drv->fbdev); 180 + goto free_drm; 181 + } 182 + 183 + /* Enable connectors polling */ 184 + drm_kms_helper_poll_init(drm); 185 + 186 + ret = drm_dev_register(drm, 0); 187 + if (ret) 188 + goto free_drm; 189 + 190 + ret = sun4i_drv_connector_plug_all(drm); 191 + if (ret) 192 + goto unregister_drm; 193 + 194 + return 0; 195 + 196 + unregister_drm: 197 + drm_dev_unregister(drm); 198 + free_drm: 199 + drm_dev_unref(drm); 200 + return ret; 201 + } 202 + 203 + static void sun4i_drv_unbind(struct device *dev) 204 + { 205 + struct drm_device *drm = dev_get_drvdata(dev); 206 + 207 + drm_dev_unregister(drm); 208 + drm_kms_helper_poll_fini(drm); 209 + sun4i_framebuffer_free(drm); 210 + drm_vblank_cleanup(drm); 211 + drm_dev_unref(drm); 212 + } 213 + 214 + static const struct component_master_ops sun4i_drv_master_ops = { 215 + .bind = sun4i_drv_bind, 216 + .unbind = sun4i_drv_unbind, 217 + }; 218 + 219 + static bool sun4i_drv_node_is_frontend(struct device_node *node) 220 + { 221 + return of_device_is_compatible(node, 222 + "allwinner,sun5i-a13-display-frontend"); 223 + } 224 + 225 + static bool sun4i_drv_node_is_tcon(struct device_node *node) 226 + { 227 + return of_device_is_compatible(node, "allwinner,sun5i-a13-tcon"); 228 + } 229 + 230 + static int compare_of(struct device *dev, void *data) 231 + { 232 + DRM_DEBUG_DRIVER("Comparing of node %s with %s\n", 233 + of_node_full_name(dev->of_node), 234 + of_node_full_name(data)); 235 + 236 + return dev->of_node == data; 237 + } 238 + 239 + static int sun4i_drv_add_endpoints(struct device *dev, 240 + struct component_match **match, 241 + struct device_node *node) 242 + { 243 + struct device_node *port, *ep, *remote; 244 + int count = 0; 245 + 246 + /* 247 + * We don't support the frontend for now, so we will never 248 + * have a device bound. Just skip over it, but we still want 249 + * the rest our pipeline to be added. 250 + */ 251 + if (!sun4i_drv_node_is_frontend(node) && 252 + !of_device_is_available(node)) 253 + return 0; 254 + 255 + if (!sun4i_drv_node_is_frontend(node)) { 256 + /* Add current component */ 257 + DRM_DEBUG_DRIVER("Adding component %s\n", 258 + of_node_full_name(node)); 259 + component_match_add(dev, match, compare_of, node); 260 + count++; 261 + } 262 + 263 + /* Inputs are listed first, then outputs */ 264 + port = of_graph_get_port_by_id(node, 1); 265 + if (!port) { 266 + DRM_DEBUG_DRIVER("No output to bind\n"); 267 + return count; 268 + } 269 + 270 + for_each_available_child_of_node(port, ep) { 271 + remote = of_graph_get_remote_port_parent(ep); 272 + if (!remote) { 273 + DRM_DEBUG_DRIVER("Error retrieving the output node\n"); 274 + of_node_put(remote); 275 + continue; 276 + } 277 + 278 + /* 279 + * If the node is our TCON, the first port is used for our 280 + * panel, and will not be part of the 281 + * component framework. 282 + */ 283 + if (sun4i_drv_node_is_tcon(node)) { 284 + struct of_endpoint endpoint; 285 + 286 + if (of_graph_parse_endpoint(ep, &endpoint)) { 287 + DRM_DEBUG_DRIVER("Couldn't parse endpoint\n"); 288 + continue; 289 + } 290 + 291 + if (!endpoint.id) { 292 + DRM_DEBUG_DRIVER("Endpoint is our panel... skipping\n"); 293 + continue; 294 + } 295 + } 296 + 297 + /* Walk down our tree */ 298 + count += sun4i_drv_add_endpoints(dev, match, remote); 299 + 300 + of_node_put(remote); 301 + } 302 + 303 + return count; 304 + } 305 + 306 + static int sun4i_drv_probe(struct platform_device *pdev) 307 + { 308 + struct component_match *match = NULL; 309 + struct device_node *np = pdev->dev.of_node; 310 + int i, count = 0; 311 + 312 + for (i = 0;; i++) { 313 + struct device_node *pipeline = of_parse_phandle(np, 314 + "allwinner,pipelines", 315 + i); 316 + if (!pipeline) 317 + break; 318 + 319 + count += sun4i_drv_add_endpoints(&pdev->dev, &match, 320 + pipeline); 321 + 322 + DRM_DEBUG_DRIVER("Queued %d outputs on pipeline %d\n", 323 + count, i); 324 + } 325 + 326 + if (count) 327 + return component_master_add_with_match(&pdev->dev, 328 + &sun4i_drv_master_ops, 329 + match); 330 + else 331 + return 0; 332 + } 333 + 334 + static int sun4i_drv_remove(struct platform_device *pdev) 335 + { 336 + return 0; 337 + } 338 + 339 + static const struct of_device_id sun4i_drv_of_table[] = { 340 + { .compatible = "allwinner,sun5i-a13-display-engine" }, 341 + { } 342 + }; 343 + MODULE_DEVICE_TABLE(of, sun4i_drv_of_table); 344 + 345 + static struct platform_driver sun4i_drv_platform_driver = { 346 + .probe = sun4i_drv_probe, 347 + .remove = sun4i_drv_remove, 348 + .driver = { 349 + .name = "sun4i-drm", 350 + .of_match_table = sun4i_drv_of_table, 351 + }, 352 + }; 353 + module_platform_driver(sun4i_drv_platform_driver); 354 + 355 + MODULE_AUTHOR("Boris Brezillon <boris.brezillon@free-electrons.com>"); 356 + MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 357 + MODULE_DESCRIPTION("Allwinner A10 Display Engine DRM/KMS Driver"); 358 + MODULE_LICENSE("GPL");
+30
drivers/gpu/drm/sun4i/sun4i_drv.h
··· 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 + #ifndef _SUN4I_DRV_H_ 14 + #define _SUN4I_DRV_H_ 15 + 16 + #include <linux/clk.h> 17 + #include <linux/regmap.h> 18 + 19 + struct sun4i_drv { 20 + struct sun4i_backend *backend; 21 + struct sun4i_crtc *crtc; 22 + struct sun4i_tcon *tcon; 23 + 24 + struct drm_plane *primary; 25 + struct drm_fbdev_cma *fbdev; 26 + 27 + struct sun4i_layer **layers; 28 + }; 29 + 30 + #endif /* _SUN4I_DRV_H_ */
+54
drivers/gpu/drm/sun4i/sun4i_framebuffer.c
··· 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/drm_atomic_helper.h> 14 + #include <drm/drm_fb_cma_helper.h> 15 + #include <drm/drmP.h> 16 + 17 + #include "sun4i_drv.h" 18 + 19 + static void sun4i_de_output_poll_changed(struct drm_device *drm) 20 + { 21 + struct sun4i_drv *drv = drm->dev_private; 22 + 23 + if (drv->fbdev) 24 + drm_fbdev_cma_hotplug_event(drv->fbdev); 25 + } 26 + 27 + static const struct drm_mode_config_funcs sun4i_de_mode_config_funcs = { 28 + .output_poll_changed = sun4i_de_output_poll_changed, 29 + .atomic_check = drm_atomic_helper_check, 30 + .atomic_commit = drm_atomic_helper_commit, 31 + .fb_create = drm_fb_cma_create, 32 + }; 33 + 34 + struct drm_fbdev_cma *sun4i_framebuffer_init(struct drm_device *drm) 35 + { 36 + drm_mode_config_reset(drm); 37 + 38 + drm->mode_config.max_width = 8192; 39 + drm->mode_config.max_height = 8192; 40 + 41 + drm->mode_config.funcs = &sun4i_de_mode_config_funcs; 42 + 43 + return drm_fbdev_cma_init(drm, 32, 44 + drm->mode_config.num_crtc, 45 + drm->mode_config.num_connector); 46 + } 47 + 48 + void sun4i_framebuffer_free(struct drm_device *drm) 49 + { 50 + struct sun4i_drv *drv = drm->dev_private; 51 + 52 + drm_fbdev_cma_fini(drv->fbdev); 53 + drm_mode_config_cleanup(drm); 54 + }
+19
drivers/gpu/drm/sun4i/sun4i_framebuffer.h
··· 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 + #ifndef _SUN4I_FRAMEBUFFER_H_ 14 + #define _SUN4I_FRAMEBUFFER_H_ 15 + 16 + struct drm_fbdev_cma *sun4i_framebuffer_init(struct drm_device *drm); 17 + void sun4i_framebuffer_free(struct drm_device *drm); 18 + 19 + #endif /* _SUN4I_FRAMEBUFFER_H_ */
+161
drivers/gpu/drm/sun4i/sun4i_layer.c
··· 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/drm_atomic_helper.h> 14 + #include <drm/drm_crtc.h> 15 + #include <drm/drm_plane_helper.h> 16 + #include <drm/drmP.h> 17 + 18 + #include "sun4i_backend.h" 19 + #include "sun4i_drv.h" 20 + #include "sun4i_layer.h" 21 + 22 + #define SUN4I_NUM_LAYERS 2 23 + 24 + static int sun4i_backend_layer_atomic_check(struct drm_plane *plane, 25 + struct drm_plane_state *state) 26 + { 27 + return 0; 28 + } 29 + 30 + static void sun4i_backend_layer_atomic_disable(struct drm_plane *plane, 31 + struct drm_plane_state *old_state) 32 + { 33 + struct sun4i_layer *layer = plane_to_sun4i_layer(plane); 34 + struct sun4i_drv *drv = layer->drv; 35 + struct sun4i_backend *backend = drv->backend; 36 + 37 + sun4i_backend_layer_enable(backend, layer->id, false); 38 + } 39 + 40 + static void sun4i_backend_layer_atomic_update(struct drm_plane *plane, 41 + struct drm_plane_state *old_state) 42 + { 43 + struct sun4i_layer *layer = plane_to_sun4i_layer(plane); 44 + struct sun4i_drv *drv = layer->drv; 45 + struct sun4i_backend *backend = drv->backend; 46 + 47 + sun4i_backend_update_layer_coord(backend, layer->id, plane); 48 + sun4i_backend_update_layer_formats(backend, layer->id, plane); 49 + sun4i_backend_update_layer_buffer(backend, layer->id, plane); 50 + sun4i_backend_layer_enable(backend, layer->id, true); 51 + } 52 + 53 + static struct drm_plane_helper_funcs sun4i_backend_layer_helper_funcs = { 54 + .atomic_check = sun4i_backend_layer_atomic_check, 55 + .atomic_disable = sun4i_backend_layer_atomic_disable, 56 + .atomic_update = sun4i_backend_layer_atomic_update, 57 + }; 58 + 59 + static const struct drm_plane_funcs sun4i_backend_layer_funcs = { 60 + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, 61 + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, 62 + .destroy = drm_plane_cleanup, 63 + .disable_plane = drm_atomic_helper_disable_plane, 64 + .reset = drm_atomic_helper_plane_reset, 65 + .update_plane = drm_atomic_helper_update_plane, 66 + }; 67 + 68 + static const uint32_t sun4i_backend_layer_formats[] = { 69 + DRM_FORMAT_ARGB8888, 70 + DRM_FORMAT_XRGB8888, 71 + DRM_FORMAT_RGB888, 72 + }; 73 + 74 + static struct sun4i_layer *sun4i_layer_init_one(struct drm_device *drm, 75 + enum drm_plane_type type) 76 + { 77 + struct sun4i_drv *drv = drm->dev_private; 78 + struct sun4i_layer *layer; 79 + int ret; 80 + 81 + layer = devm_kzalloc(drm->dev, sizeof(*layer), GFP_KERNEL); 82 + if (!layer) 83 + return ERR_PTR(-ENOMEM); 84 + 85 + ret = drm_universal_plane_init(drm, &layer->plane, BIT(0), 86 + &sun4i_backend_layer_funcs, 87 + sun4i_backend_layer_formats, 88 + ARRAY_SIZE(sun4i_backend_layer_formats), 89 + type, 90 + NULL); 91 + if (ret) { 92 + dev_err(drm->dev, "Couldn't initialize layer\n"); 93 + return ERR_PTR(ret); 94 + } 95 + 96 + drm_plane_helper_add(&layer->plane, 97 + &sun4i_backend_layer_helper_funcs); 98 + layer->drv = drv; 99 + 100 + if (type == DRM_PLANE_TYPE_PRIMARY) 101 + drv->primary = &layer->plane; 102 + 103 + return layer; 104 + } 105 + 106 + struct sun4i_layer **sun4i_layers_init(struct drm_device *drm) 107 + { 108 + struct sun4i_drv *drv = drm->dev_private; 109 + struct sun4i_layer **layers; 110 + int i; 111 + 112 + layers = devm_kcalloc(drm->dev, SUN4I_NUM_LAYERS, sizeof(**layers), 113 + GFP_KERNEL); 114 + if (!layers) 115 + return ERR_PTR(-ENOMEM); 116 + 117 + /* 118 + * The hardware is a bit unusual here. 119 + * 120 + * Even though it supports 4 layers, it does the composition 121 + * in two separate steps. 122 + * 123 + * The first one is assigning a layer to one of its two 124 + * pipes. If more that 1 layer is assigned to the same pipe, 125 + * and if pixels overlaps, the pipe will take the pixel from 126 + * the layer with the highest priority. 127 + * 128 + * The second step is the actual alpha blending, that takes 129 + * the two pipes as input, and uses the eventual alpha 130 + * component to do the transparency between the two. 131 + * 132 + * This two steps scenario makes us unable to guarantee a 133 + * robust alpha blending between the 4 layers in all 134 + * situations. So we just expose two layers, one per pipe. On 135 + * SoCs that support it, sprites could fill the need for more 136 + * layers. 137 + */ 138 + for (i = 0; i < SUN4I_NUM_LAYERS; i++) { 139 + enum drm_plane_type type = (i == 0) 140 + ? DRM_PLANE_TYPE_PRIMARY 141 + : DRM_PLANE_TYPE_OVERLAY; 142 + struct sun4i_layer *layer = layers[i]; 143 + 144 + layer = sun4i_layer_init_one(drm, type); 145 + if (IS_ERR(layer)) { 146 + dev_err(drm->dev, "Couldn't initialize %s plane\n", 147 + i ? "overlay" : "primary"); 148 + return ERR_CAST(layer); 149 + }; 150 + 151 + DRM_DEBUG_DRIVER("Assigning %s plane to pipe %d\n", 152 + i ? "overlay" : "primary", i); 153 + regmap_update_bits(drv->backend->regs, SUN4I_BACKEND_ATTCTL_REG0(i), 154 + SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL_MASK, 155 + SUN4I_BACKEND_ATTCTL_REG0_LAY_PIPESEL(i)); 156 + 157 + layer->id = i; 158 + }; 159 + 160 + return layers; 161 + }
+30
drivers/gpu/drm/sun4i/sun4i_layer.h
··· 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 + #ifndef _SUN4I_LAYER_H_ 14 + #define _SUN4I_LAYER_H_ 15 + 16 + struct sun4i_layer { 17 + struct drm_plane plane; 18 + struct sun4i_drv *drv; 19 + int id; 20 + }; 21 + 22 + static inline struct sun4i_layer * 23 + plane_to_sun4i_layer(struct drm_plane *plane) 24 + { 25 + return container_of(plane, struct sun4i_layer, plane); 26 + } 27 + 28 + struct sun4i_layer **sun4i_layers_init(struct drm_device *drm); 29 + 30 + #endif /* _SUN4I_LAYER_H_ */
+250
drivers/gpu/drm/sun4i/sun4i_rgb.c
··· 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 <linux/clk.h> 14 + 15 + #include <drm/drmP.h> 16 + #include <drm/drm_atomic_helper.h> 17 + #include <drm/drm_crtc_helper.h> 18 + #include <drm/drm_panel.h> 19 + 20 + #include "sun4i_drv.h" 21 + #include "sun4i_tcon.h" 22 + 23 + struct sun4i_rgb { 24 + struct drm_connector connector; 25 + struct drm_encoder encoder; 26 + 27 + struct sun4i_drv *drv; 28 + }; 29 + 30 + static inline struct sun4i_rgb * 31 + drm_connector_to_sun4i_rgb(struct drm_connector *connector) 32 + { 33 + return container_of(connector, struct sun4i_rgb, 34 + connector); 35 + } 36 + 37 + static inline struct sun4i_rgb * 38 + drm_encoder_to_sun4i_rgb(struct drm_encoder *encoder) 39 + { 40 + return container_of(encoder, struct sun4i_rgb, 41 + encoder); 42 + } 43 + 44 + static int sun4i_rgb_get_modes(struct drm_connector *connector) 45 + { 46 + struct sun4i_rgb *rgb = 47 + drm_connector_to_sun4i_rgb(connector); 48 + struct sun4i_drv *drv = rgb->drv; 49 + struct sun4i_tcon *tcon = drv->tcon; 50 + 51 + return drm_panel_get_modes(tcon->panel); 52 + } 53 + 54 + static int sun4i_rgb_mode_valid(struct drm_connector *connector, 55 + struct drm_display_mode *mode) 56 + { 57 + u32 hsync = mode->hsync_end - mode->hsync_start; 58 + u32 vsync = mode->vsync_end - mode->vsync_start; 59 + 60 + DRM_DEBUG_DRIVER("Validating modes...\n"); 61 + 62 + if (hsync < 1) 63 + return MODE_HSYNC_NARROW; 64 + 65 + if (hsync > 0x3ff) 66 + return MODE_HSYNC_WIDE; 67 + 68 + if ((mode->hdisplay < 1) || (mode->htotal < 1)) 69 + return MODE_H_ILLEGAL; 70 + 71 + if ((mode->hdisplay > 0x7ff) || (mode->htotal > 0xfff)) 72 + return MODE_BAD_HVALUE; 73 + 74 + DRM_DEBUG_DRIVER("Horizontal parameters OK\n"); 75 + 76 + if (vsync < 1) 77 + return MODE_VSYNC_NARROW; 78 + 79 + if (vsync > 0x3ff) 80 + return MODE_VSYNC_WIDE; 81 + 82 + if ((mode->vdisplay < 1) || (mode->vtotal < 1)) 83 + return MODE_V_ILLEGAL; 84 + 85 + if ((mode->vdisplay > 0x7ff) || (mode->vtotal > 0xfff)) 86 + return MODE_BAD_VVALUE; 87 + 88 + DRM_DEBUG_DRIVER("Vertical parameters OK\n"); 89 + 90 + return MODE_OK; 91 + } 92 + 93 + static struct drm_encoder * 94 + sun4i_rgb_best_encoder(struct drm_connector *connector) 95 + { 96 + struct sun4i_rgb *rgb = 97 + drm_connector_to_sun4i_rgb(connector); 98 + 99 + return &rgb->encoder; 100 + } 101 + 102 + static struct drm_connector_helper_funcs sun4i_rgb_con_helper_funcs = { 103 + .get_modes = sun4i_rgb_get_modes, 104 + .mode_valid = sun4i_rgb_mode_valid, 105 + .best_encoder = sun4i_rgb_best_encoder, 106 + }; 107 + 108 + static enum drm_connector_status 109 + sun4i_rgb_connector_detect(struct drm_connector *connector, bool force) 110 + { 111 + return connector_status_connected; 112 + } 113 + 114 + static void 115 + sun4i_rgb_connector_destroy(struct drm_connector *connector) 116 + { 117 + struct sun4i_rgb *rgb = drm_connector_to_sun4i_rgb(connector); 118 + struct sun4i_drv *drv = rgb->drv; 119 + struct sun4i_tcon *tcon = drv->tcon; 120 + 121 + drm_panel_detach(tcon->panel); 122 + drm_connector_cleanup(connector); 123 + } 124 + 125 + static struct drm_connector_funcs sun4i_rgb_con_funcs = { 126 + .dpms = drm_atomic_helper_connector_dpms, 127 + .detect = sun4i_rgb_connector_detect, 128 + .fill_modes = drm_helper_probe_single_connector_modes, 129 + .destroy = sun4i_rgb_connector_destroy, 130 + .reset = drm_atomic_helper_connector_reset, 131 + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 132 + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 133 + }; 134 + 135 + static int sun4i_rgb_atomic_check(struct drm_encoder *encoder, 136 + struct drm_crtc_state *crtc_state, 137 + struct drm_connector_state *conn_state) 138 + { 139 + return 0; 140 + } 141 + 142 + static void sun4i_rgb_encoder_enable(struct drm_encoder *encoder) 143 + { 144 + struct sun4i_rgb *rgb = drm_encoder_to_sun4i_rgb(encoder); 145 + struct sun4i_drv *drv = rgb->drv; 146 + struct sun4i_tcon *tcon = drv->tcon; 147 + 148 + DRM_DEBUG_DRIVER("Enabling RGB output\n"); 149 + 150 + drm_panel_enable(tcon->panel); 151 + sun4i_tcon_channel_enable(tcon, 0); 152 + } 153 + 154 + static void sun4i_rgb_encoder_disable(struct drm_encoder *encoder) 155 + { 156 + struct sun4i_rgb *rgb = drm_encoder_to_sun4i_rgb(encoder); 157 + struct sun4i_drv *drv = rgb->drv; 158 + struct sun4i_tcon *tcon = drv->tcon; 159 + 160 + DRM_DEBUG_DRIVER("Disabling RGB output\n"); 161 + 162 + sun4i_tcon_channel_disable(tcon, 0); 163 + drm_panel_disable(tcon->panel); 164 + } 165 + 166 + static void sun4i_rgb_encoder_mode_set(struct drm_encoder *encoder, 167 + struct drm_display_mode *mode, 168 + struct drm_display_mode *adjusted_mode) 169 + { 170 + struct sun4i_rgb *rgb = drm_encoder_to_sun4i_rgb(encoder); 171 + struct sun4i_drv *drv = rgb->drv; 172 + struct sun4i_tcon *tcon = drv->tcon; 173 + 174 + sun4i_tcon0_mode_set(tcon, mode); 175 + 176 + clk_set_rate(tcon->dclk, mode->crtc_clock * 1000); 177 + 178 + /* FIXME: This seems to be board specific */ 179 + clk_set_phase(tcon->dclk, 120); 180 + } 181 + 182 + static struct drm_encoder_helper_funcs sun4i_rgb_enc_helper_funcs = { 183 + .atomic_check = sun4i_rgb_atomic_check, 184 + .mode_set = sun4i_rgb_encoder_mode_set, 185 + .disable = sun4i_rgb_encoder_disable, 186 + .enable = sun4i_rgb_encoder_enable, 187 + }; 188 + 189 + static void sun4i_rgb_enc_destroy(struct drm_encoder *encoder) 190 + { 191 + drm_encoder_cleanup(encoder); 192 + } 193 + 194 + static struct drm_encoder_funcs sun4i_rgb_enc_funcs = { 195 + .destroy = sun4i_rgb_enc_destroy, 196 + }; 197 + 198 + int sun4i_rgb_init(struct drm_device *drm) 199 + { 200 + struct sun4i_drv *drv = drm->dev_private; 201 + struct sun4i_tcon *tcon = drv->tcon; 202 + struct sun4i_rgb *rgb; 203 + int ret; 204 + 205 + /* If we don't have a panel, there's no point in going on */ 206 + if (!tcon->panel) 207 + return -ENODEV; 208 + 209 + rgb = devm_kzalloc(drm->dev, sizeof(*rgb), GFP_KERNEL); 210 + if (!rgb) 211 + return -ENOMEM; 212 + rgb->drv = drv; 213 + 214 + drm_encoder_helper_add(&rgb->encoder, 215 + &sun4i_rgb_enc_helper_funcs); 216 + ret = drm_encoder_init(drm, 217 + &rgb->encoder, 218 + &sun4i_rgb_enc_funcs, 219 + DRM_MODE_ENCODER_NONE, 220 + NULL); 221 + if (ret) { 222 + dev_err(drm->dev, "Couldn't initialise the rgb encoder\n"); 223 + goto err_out; 224 + } 225 + 226 + /* The RGB encoder can only work with the TCON channel 0 */ 227 + rgb->encoder.possible_crtcs = BIT(0); 228 + 229 + drm_connector_helper_add(&rgb->connector, 230 + &sun4i_rgb_con_helper_funcs); 231 + ret = drm_connector_init(drm, &rgb->connector, 232 + &sun4i_rgb_con_funcs, 233 + DRM_MODE_CONNECTOR_Unknown); 234 + if (ret) { 235 + dev_err(drm->dev, "Couldn't initialise the rgb connector\n"); 236 + goto err_cleanup_connector; 237 + } 238 + 239 + drm_mode_connector_attach_encoder(&rgb->connector, &rgb->encoder); 240 + 241 + drm_panel_attach(tcon->panel, &rgb->connector); 242 + 243 + return 0; 244 + 245 + err_cleanup_connector: 246 + drm_encoder_cleanup(&rgb->encoder); 247 + err_out: 248 + return ret; 249 + } 250 + EXPORT_SYMBOL(sun4i_rgb_init);
+18
drivers/gpu/drm/sun4i/sun4i_rgb.h
··· 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 + #ifndef _SUN4I_RGB_H_ 14 + #define _SUN4I_RGB_H_ 15 + 16 + int sun4i_rgb_init(struct drm_device *drm); 17 + 18 + #endif /* _SUN4I_RGB_H_ */
+561
drivers/gpu/drm/sun4i/sun4i_tcon.c
··· 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> 18 + #include <drm/drm_panel.h> 19 + 20 + #include <linux/component.h> 21 + #include <linux/ioport.h> 22 + #include <linux/of_address.h> 23 + #include <linux/of_graph.h> 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" 31 + #include "sun4i_rgb.h" 32 + #include "sun4i_tcon.h" 33 + 34 + void sun4i_tcon_disable(struct sun4i_tcon *tcon) 35 + { 36 + DRM_DEBUG_DRIVER("Disabling TCON\n"); 37 + 38 + /* Disable the TCON */ 39 + regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, 40 + SUN4I_TCON_GCTL_TCON_ENABLE, 0); 41 + } 42 + EXPORT_SYMBOL(sun4i_tcon_disable); 43 + 44 + void sun4i_tcon_enable(struct sun4i_tcon *tcon) 45 + { 46 + DRM_DEBUG_DRIVER("Enabling TCON\n"); 47 + 48 + /* Enable the TCON */ 49 + regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, 50 + SUN4I_TCON_GCTL_TCON_ENABLE, 51 + SUN4I_TCON_GCTL_TCON_ENABLE); 52 + } 53 + EXPORT_SYMBOL(sun4i_tcon_enable); 54 + 55 + void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel) 56 + { 57 + /* Disable the TCON's channel */ 58 + if (channel == 0) { 59 + regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, 60 + SUN4I_TCON0_CTL_TCON_ENABLE, 0); 61 + clk_disable_unprepare(tcon->dclk); 62 + } else if (channel == 1) { 63 + regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, 64 + SUN4I_TCON1_CTL_TCON_ENABLE, 0); 65 + clk_disable_unprepare(tcon->sclk1); 66 + } 67 + } 68 + EXPORT_SYMBOL(sun4i_tcon_channel_disable); 69 + 70 + void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel) 71 + { 72 + /* Enable the TCON's channel */ 73 + if (channel == 0) { 74 + regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, 75 + SUN4I_TCON0_CTL_TCON_ENABLE, 76 + SUN4I_TCON0_CTL_TCON_ENABLE); 77 + clk_prepare_enable(tcon->dclk); 78 + } else if (channel == 1) { 79 + regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, 80 + SUN4I_TCON1_CTL_TCON_ENABLE, 81 + SUN4I_TCON1_CTL_TCON_ENABLE); 82 + clk_prepare_enable(tcon->sclk1); 83 + } 84 + } 85 + EXPORT_SYMBOL(sun4i_tcon_channel_enable); 86 + 87 + void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable) 88 + { 89 + u32 mask, val = 0; 90 + 91 + DRM_DEBUG_DRIVER("%sabling VBLANK interrupt\n", enable ? "En" : "Dis"); 92 + 93 + mask = SUN4I_TCON_GINT0_VBLANK_ENABLE(0) | 94 + SUN4I_TCON_GINT0_VBLANK_ENABLE(1); 95 + 96 + if (enable) 97 + val = mask; 98 + 99 + regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, mask, val); 100 + } 101 + EXPORT_SYMBOL(sun4i_tcon_enable_vblank); 102 + 103 + static int sun4i_tcon_get_clk_delay(struct drm_display_mode *mode, 104 + int channel) 105 + { 106 + int delay = mode->vtotal - mode->vdisplay; 107 + 108 + if (mode->flags & DRM_MODE_FLAG_INTERLACE) 109 + delay /= 2; 110 + 111 + if (channel == 1) 112 + delay -= 2; 113 + 114 + delay = min(delay, 30); 115 + 116 + DRM_DEBUG_DRIVER("TCON %d clock delay %u\n", channel, delay); 117 + 118 + return delay; 119 + } 120 + 121 + void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon, 122 + struct drm_display_mode *mode) 123 + { 124 + unsigned int bp, hsync, vsync; 125 + u8 clk_delay; 126 + u32 val = 0; 127 + 128 + /* Adjust clock delay */ 129 + clk_delay = sun4i_tcon_get_clk_delay(mode, 0); 130 + regmap_update_bits(tcon->regs, SUN4I_TCON0_CTL_REG, 131 + SUN4I_TCON0_CTL_CLK_DELAY_MASK, 132 + SUN4I_TCON0_CTL_CLK_DELAY(clk_delay)); 133 + 134 + /* Set the resolution */ 135 + regmap_write(tcon->regs, SUN4I_TCON0_BASIC0_REG, 136 + SUN4I_TCON0_BASIC0_X(mode->crtc_hdisplay) | 137 + SUN4I_TCON0_BASIC0_Y(mode->crtc_vdisplay)); 138 + 139 + /* 140 + * This is called a backporch in the register documentation, 141 + * but it really is the front porch + hsync 142 + */ 143 + bp = mode->crtc_htotal - mode->crtc_hsync_start; 144 + DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n", 145 + mode->crtc_htotal, bp); 146 + 147 + /* Set horizontal display timings */ 148 + regmap_write(tcon->regs, SUN4I_TCON0_BASIC1_REG, 149 + SUN4I_TCON0_BASIC1_H_TOTAL(mode->crtc_htotal) | 150 + SUN4I_TCON0_BASIC1_H_BACKPORCH(bp)); 151 + 152 + /* 153 + * This is called a backporch in the register documentation, 154 + * but it really is the front porch + hsync 155 + */ 156 + bp = mode->crtc_vtotal - mode->crtc_vsync_start; 157 + DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n", 158 + mode->crtc_vtotal, bp); 159 + 160 + /* Set vertical display timings */ 161 + regmap_write(tcon->regs, SUN4I_TCON0_BASIC2_REG, 162 + SUN4I_TCON0_BASIC2_V_TOTAL(mode->crtc_vtotal) | 163 + SUN4I_TCON0_BASIC2_V_BACKPORCH(bp)); 164 + 165 + /* Set Hsync and Vsync length */ 166 + hsync = mode->crtc_hsync_end - mode->crtc_hsync_start; 167 + vsync = mode->crtc_vsync_end - mode->crtc_vsync_start; 168 + DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync); 169 + regmap_write(tcon->regs, SUN4I_TCON0_BASIC3_REG, 170 + SUN4I_TCON0_BASIC3_V_SYNC(vsync) | 171 + SUN4I_TCON0_BASIC3_H_SYNC(hsync)); 172 + 173 + /* Setup the polarity of the various signals */ 174 + if (!(mode->flags & DRM_MODE_FLAG_PHSYNC)) 175 + val |= SUN4I_TCON0_IO_POL_HSYNC_POSITIVE; 176 + 177 + if (!(mode->flags & DRM_MODE_FLAG_PVSYNC)) 178 + val |= SUN4I_TCON0_IO_POL_VSYNC_POSITIVE; 179 + 180 + regmap_update_bits(tcon->regs, SUN4I_TCON0_IO_POL_REG, 181 + SUN4I_TCON0_IO_POL_HSYNC_POSITIVE | SUN4I_TCON0_IO_POL_VSYNC_POSITIVE, 182 + val); 183 + 184 + /* Map output pins to channel 0 */ 185 + regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, 186 + SUN4I_TCON_GCTL_IOMAP_MASK, 187 + SUN4I_TCON_GCTL_IOMAP_TCON0); 188 + 189 + /* Enable the output on the pins */ 190 + regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, 0); 191 + } 192 + EXPORT_SYMBOL(sun4i_tcon0_mode_set); 193 + 194 + void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, 195 + struct drm_display_mode *mode) 196 + { 197 + unsigned int bp, hsync, vsync; 198 + u8 clk_delay; 199 + u32 val; 200 + 201 + /* Adjust clock delay */ 202 + clk_delay = sun4i_tcon_get_clk_delay(mode, 1); 203 + regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, 204 + SUN4I_TCON1_CTL_CLK_DELAY_MASK, 205 + SUN4I_TCON1_CTL_CLK_DELAY(clk_delay)); 206 + 207 + /* Set interlaced mode */ 208 + if (mode->flags & DRM_MODE_FLAG_INTERLACE) 209 + val = SUN4I_TCON1_CTL_INTERLACE_ENABLE; 210 + else 211 + val = 0; 212 + regmap_update_bits(tcon->regs, SUN4I_TCON1_CTL_REG, 213 + SUN4I_TCON1_CTL_INTERLACE_ENABLE, 214 + val); 215 + 216 + /* Set the input resolution */ 217 + regmap_write(tcon->regs, SUN4I_TCON1_BASIC0_REG, 218 + SUN4I_TCON1_BASIC0_X(mode->crtc_hdisplay) | 219 + SUN4I_TCON1_BASIC0_Y(mode->crtc_vdisplay)); 220 + 221 + /* Set the upscaling resolution */ 222 + regmap_write(tcon->regs, SUN4I_TCON1_BASIC1_REG, 223 + SUN4I_TCON1_BASIC1_X(mode->crtc_hdisplay) | 224 + SUN4I_TCON1_BASIC1_Y(mode->crtc_vdisplay)); 225 + 226 + /* Set the output resolution */ 227 + regmap_write(tcon->regs, SUN4I_TCON1_BASIC2_REG, 228 + SUN4I_TCON1_BASIC2_X(mode->crtc_hdisplay) | 229 + SUN4I_TCON1_BASIC2_Y(mode->crtc_vdisplay)); 230 + 231 + /* Set horizontal display timings */ 232 + bp = mode->crtc_htotal - mode->crtc_hsync_end; 233 + DRM_DEBUG_DRIVER("Setting horizontal total %d, backporch %d\n", 234 + mode->htotal, bp); 235 + regmap_write(tcon->regs, SUN4I_TCON1_BASIC3_REG, 236 + SUN4I_TCON1_BASIC3_H_TOTAL(mode->crtc_htotal) | 237 + SUN4I_TCON1_BASIC3_H_BACKPORCH(bp)); 238 + 239 + /* Set vertical display timings */ 240 + bp = mode->crtc_vtotal - mode->crtc_vsync_end; 241 + DRM_DEBUG_DRIVER("Setting vertical total %d, backporch %d\n", 242 + mode->vtotal, bp); 243 + regmap_write(tcon->regs, SUN4I_TCON1_BASIC4_REG, 244 + SUN4I_TCON1_BASIC4_V_TOTAL(mode->vtotal) | 245 + SUN4I_TCON1_BASIC4_V_BACKPORCH(bp)); 246 + 247 + /* Set Hsync and Vsync length */ 248 + hsync = mode->crtc_hsync_end - mode->crtc_hsync_start; 249 + vsync = mode->crtc_vsync_end - mode->crtc_vsync_start; 250 + DRM_DEBUG_DRIVER("Setting HSYNC %d, VSYNC %d\n", hsync, vsync); 251 + regmap_write(tcon->regs, SUN4I_TCON1_BASIC5_REG, 252 + SUN4I_TCON1_BASIC5_V_SYNC(vsync) | 253 + SUN4I_TCON1_BASIC5_H_SYNC(hsync)); 254 + 255 + /* Map output pins to channel 1 */ 256 + regmap_update_bits(tcon->regs, SUN4I_TCON_GCTL_REG, 257 + SUN4I_TCON_GCTL_IOMAP_MASK, 258 + SUN4I_TCON_GCTL_IOMAP_TCON1); 259 + 260 + /* 261 + * FIXME: Undocumented bits 262 + */ 263 + if (tcon->has_mux) 264 + regmap_write(tcon->regs, SUN4I_TCON_MUX_CTRL_REG, 1); 265 + } 266 + EXPORT_SYMBOL(sun4i_tcon1_mode_set); 267 + 268 + static void sun4i_tcon_finish_page_flip(struct drm_device *dev, 269 + struct sun4i_crtc *scrtc) 270 + { 271 + unsigned long flags; 272 + 273 + spin_lock_irqsave(&dev->event_lock, flags); 274 + if (scrtc->event) { 275 + drm_crtc_send_vblank_event(&scrtc->crtc, scrtc->event); 276 + drm_crtc_vblank_put(&scrtc->crtc); 277 + scrtc->event = NULL; 278 + } 279 + spin_unlock_irqrestore(&dev->event_lock, flags); 280 + } 281 + 282 + static irqreturn_t sun4i_tcon_handler(int irq, void *private) 283 + { 284 + struct sun4i_tcon *tcon = private; 285 + struct drm_device *drm = tcon->drm; 286 + struct sun4i_drv *drv = drm->dev_private; 287 + struct sun4i_crtc *scrtc = drv->crtc; 288 + unsigned int status; 289 + 290 + regmap_read(tcon->regs, SUN4I_TCON_GINT0_REG, &status); 291 + 292 + if (!(status & (SUN4I_TCON_GINT0_VBLANK_INT(0) | 293 + SUN4I_TCON_GINT0_VBLANK_INT(1)))) 294 + return IRQ_NONE; 295 + 296 + drm_crtc_handle_vblank(&scrtc->crtc); 297 + sun4i_tcon_finish_page_flip(drm, scrtc); 298 + 299 + /* Acknowledge the interrupt */ 300 + regmap_update_bits(tcon->regs, SUN4I_TCON_GINT0_REG, 301 + SUN4I_TCON_GINT0_VBLANK_INT(0) | 302 + SUN4I_TCON_GINT0_VBLANK_INT(1), 303 + 0); 304 + 305 + return IRQ_HANDLED; 306 + } 307 + 308 + static int sun4i_tcon_init_clocks(struct device *dev, 309 + struct sun4i_tcon *tcon) 310 + { 311 + tcon->clk = devm_clk_get(dev, "ahb"); 312 + if (IS_ERR(tcon->clk)) { 313 + dev_err(dev, "Couldn't get the TCON bus clock\n"); 314 + return PTR_ERR(tcon->clk); 315 + } 316 + clk_prepare_enable(tcon->clk); 317 + 318 + tcon->sclk0 = devm_clk_get(dev, "tcon-ch0"); 319 + if (IS_ERR(tcon->sclk0)) { 320 + dev_err(dev, "Couldn't get the TCON channel 0 clock\n"); 321 + return PTR_ERR(tcon->sclk0); 322 + } 323 + 324 + tcon->sclk1 = devm_clk_get(dev, "tcon-ch1"); 325 + if (IS_ERR(tcon->sclk1)) { 326 + dev_err(dev, "Couldn't get the TCON channel 1 clock\n"); 327 + return PTR_ERR(tcon->sclk1); 328 + } 329 + 330 + return sun4i_dclk_create(dev, tcon); 331 + } 332 + 333 + static void sun4i_tcon_free_clocks(struct sun4i_tcon *tcon) 334 + { 335 + sun4i_dclk_free(tcon); 336 + clk_disable_unprepare(tcon->clk); 337 + } 338 + 339 + static int sun4i_tcon_init_irq(struct device *dev, 340 + struct sun4i_tcon *tcon) 341 + { 342 + struct platform_device *pdev = to_platform_device(dev); 343 + int irq, ret; 344 + 345 + irq = platform_get_irq(pdev, 0); 346 + if (irq < 0) { 347 + dev_err(dev, "Couldn't retrieve the TCON interrupt\n"); 348 + return irq; 349 + } 350 + 351 + ret = devm_request_irq(dev, irq, sun4i_tcon_handler, 0, 352 + dev_name(dev), tcon); 353 + if (ret) { 354 + dev_err(dev, "Couldn't request the IRQ\n"); 355 + return ret; 356 + } 357 + 358 + return 0; 359 + } 360 + 361 + static struct regmap_config sun4i_tcon_regmap_config = { 362 + .reg_bits = 32, 363 + .val_bits = 32, 364 + .reg_stride = 4, 365 + .max_register = 0x800, 366 + }; 367 + 368 + static int sun4i_tcon_init_regmap(struct device *dev, 369 + struct sun4i_tcon *tcon) 370 + { 371 + struct platform_device *pdev = to_platform_device(dev); 372 + struct resource *res; 373 + void __iomem *regs; 374 + 375 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 376 + regs = devm_ioremap_resource(dev, res); 377 + if (IS_ERR(regs)) { 378 + dev_err(dev, "Couldn't map the TCON registers\n"); 379 + return PTR_ERR(regs); 380 + } 381 + 382 + tcon->regs = devm_regmap_init_mmio(dev, regs, 383 + &sun4i_tcon_regmap_config); 384 + if (IS_ERR(tcon->regs)) { 385 + dev_err(dev, "Couldn't create the TCON regmap\n"); 386 + return PTR_ERR(tcon->regs); 387 + } 388 + 389 + /* Make sure the TCON is disabled and all IRQs are off */ 390 + regmap_write(tcon->regs, SUN4I_TCON_GCTL_REG, 0); 391 + regmap_write(tcon->regs, SUN4I_TCON_GINT0_REG, 0); 392 + regmap_write(tcon->regs, SUN4I_TCON_GINT1_REG, 0); 393 + 394 + /* Disable IO lines and set them to tristate */ 395 + regmap_write(tcon->regs, SUN4I_TCON0_IO_TRI_REG, ~0); 396 + regmap_write(tcon->regs, SUN4I_TCON1_IO_TRI_REG, ~0); 397 + 398 + return 0; 399 + } 400 + 401 + static struct drm_panel *sun4i_tcon_find_panel(struct device_node *node) 402 + { 403 + struct device_node *port, *remote, *child; 404 + struct device_node *end_node = NULL; 405 + 406 + /* Inputs are listed first, then outputs */ 407 + port = of_graph_get_port_by_id(node, 1); 408 + 409 + /* 410 + * Our first output is the RGB interface where the panel will 411 + * be connected. 412 + */ 413 + for_each_child_of_node(port, child) { 414 + u32 reg; 415 + 416 + of_property_read_u32(child, "reg", &reg); 417 + if (reg == 0) 418 + end_node = child; 419 + } 420 + 421 + if (!end_node) { 422 + DRM_DEBUG_DRIVER("Missing panel endpoint\n"); 423 + return ERR_PTR(-ENODEV); 424 + } 425 + 426 + remote = of_graph_get_remote_port_parent(end_node); 427 + if (!remote) { 428 + DRM_DEBUG_DRIVER("Enable to parse remote node\n"); 429 + return ERR_PTR(-EINVAL); 430 + } 431 + 432 + return of_drm_find_panel(remote); 433 + } 434 + 435 + static int sun4i_tcon_bind(struct device *dev, struct device *master, 436 + void *data) 437 + { 438 + struct drm_device *drm = data; 439 + struct sun4i_drv *drv = drm->dev_private; 440 + struct sun4i_tcon *tcon; 441 + int ret; 442 + 443 + tcon = devm_kzalloc(dev, sizeof(*tcon), GFP_KERNEL); 444 + if (!tcon) 445 + return -ENOMEM; 446 + dev_set_drvdata(dev, tcon); 447 + drv->tcon = tcon; 448 + tcon->drm = drm; 449 + 450 + if (of_device_is_compatible(dev->of_node, "allwinner,sun5i-a13-tcon")) 451 + tcon->has_mux = true; 452 + 453 + tcon->lcd_rst = devm_reset_control_get(dev, "lcd"); 454 + if (IS_ERR(tcon->lcd_rst)) { 455 + dev_err(dev, "Couldn't get our reset line\n"); 456 + return PTR_ERR(tcon->lcd_rst); 457 + } 458 + 459 + /* Make sure our TCON is reset */ 460 + if (!reset_control_status(tcon->lcd_rst)) 461 + reset_control_assert(tcon->lcd_rst); 462 + 463 + ret = reset_control_deassert(tcon->lcd_rst); 464 + if (ret) { 465 + dev_err(dev, "Couldn't deassert our reset line\n"); 466 + return ret; 467 + } 468 + 469 + ret = sun4i_tcon_init_regmap(dev, tcon); 470 + if (ret) { 471 + dev_err(dev, "Couldn't init our TCON regmap\n"); 472 + goto err_assert_reset; 473 + } 474 + 475 + ret = sun4i_tcon_init_clocks(dev, tcon); 476 + if (ret) { 477 + dev_err(dev, "Couldn't init our TCON clocks\n"); 478 + goto err_assert_reset; 479 + } 480 + 481 + ret = sun4i_tcon_init_irq(dev, tcon); 482 + if (ret) { 483 + dev_err(dev, "Couldn't init our TCON interrupts\n"); 484 + goto err_free_clocks; 485 + } 486 + 487 + tcon->panel = sun4i_tcon_find_panel(dev->of_node); 488 + if (IS_ERR(tcon->panel)) { 489 + dev_info(dev, "No panel found... RGB output disabled\n"); 490 + return 0; 491 + } 492 + 493 + return sun4i_rgb_init(drm); 494 + 495 + err_free_clocks: 496 + sun4i_tcon_free_clocks(tcon); 497 + err_assert_reset: 498 + reset_control_assert(tcon->lcd_rst); 499 + return ret; 500 + } 501 + 502 + static void sun4i_tcon_unbind(struct device *dev, struct device *master, 503 + void *data) 504 + { 505 + struct sun4i_tcon *tcon = dev_get_drvdata(dev); 506 + 507 + sun4i_tcon_free_clocks(tcon); 508 + } 509 + 510 + static struct component_ops sun4i_tcon_ops = { 511 + .bind = sun4i_tcon_bind, 512 + .unbind = sun4i_tcon_unbind, 513 + }; 514 + 515 + static int sun4i_tcon_probe(struct platform_device *pdev) 516 + { 517 + struct device_node *node = pdev->dev.of_node; 518 + struct drm_panel *panel; 519 + 520 + /* 521 + * The panel is not ready. 522 + * Defer the probe. 523 + */ 524 + panel = sun4i_tcon_find_panel(node); 525 + if (IS_ERR(panel)) { 526 + /* 527 + * If we don't have a panel endpoint, just go on 528 + */ 529 + if (PTR_ERR(panel) != -ENODEV) 530 + return -EPROBE_DEFER; 531 + } 532 + 533 + return component_add(&pdev->dev, &sun4i_tcon_ops); 534 + } 535 + 536 + static int sun4i_tcon_remove(struct platform_device *pdev) 537 + { 538 + component_del(&pdev->dev, &sun4i_tcon_ops); 539 + 540 + return 0; 541 + } 542 + 543 + static const struct of_device_id sun4i_tcon_of_table[] = { 544 + { .compatible = "allwinner,sun5i-a13-tcon" }, 545 + { } 546 + }; 547 + MODULE_DEVICE_TABLE(of, sun4i_tcon_of_table); 548 + 549 + static struct platform_driver sun4i_tcon_platform_driver = { 550 + .probe = sun4i_tcon_probe, 551 + .remove = sun4i_tcon_remove, 552 + .driver = { 553 + .name = "sun4i-tcon", 554 + .of_match_table = sun4i_tcon_of_table, 555 + }, 556 + }; 557 + module_platform_driver(sun4i_tcon_platform_driver); 558 + 559 + MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 560 + MODULE_DESCRIPTION("Allwinner A10 Timing Controller Driver"); 561 + MODULE_LICENSE("GPL");
+186
drivers/gpu/drm/sun4i/sun4i_tcon.h
··· 1 + /* 2 + * Copyright (C) 2015 Free Electrons 3 + * Copyright (C) 2015 NextThing Co 4 + * 5 + * Boris Brezillon <boris.brezillon@free-electrons.com> 6 + * Maxime Ripard <maxime.ripard@free-electrons.com> 7 + * 8 + * This program is free software; you can redistribute it and/or 9 + * modify it under the terms of the GNU General Public License as 10 + * published by the Free Software Foundation; either version 2 of 11 + * the License, or (at your option) any later version. 12 + */ 13 + 14 + #ifndef __SUN4I_TCON_H__ 15 + #define __SUN4I_TCON_H__ 16 + 17 + #include <drm/drm_crtc.h> 18 + 19 + #include <linux/kernel.h> 20 + #include <linux/reset.h> 21 + 22 + #define SUN4I_TCON_GCTL_REG 0x0 23 + #define SUN4I_TCON_GCTL_TCON_ENABLE BIT(31) 24 + #define SUN4I_TCON_GCTL_IOMAP_MASK BIT(0) 25 + #define SUN4I_TCON_GCTL_IOMAP_TCON1 (1 << 0) 26 + #define SUN4I_TCON_GCTL_IOMAP_TCON0 (0 << 0) 27 + 28 + #define SUN4I_TCON_GINT0_REG 0x4 29 + #define SUN4I_TCON_GINT0_VBLANK_ENABLE(pipe) BIT(31 - (pipe)) 30 + #define SUN4I_TCON_GINT0_VBLANK_INT(pipe) BIT(15 - (pipe)) 31 + 32 + #define SUN4I_TCON_GINT1_REG 0x8 33 + #define SUN4I_TCON_FRM_CTL_REG 0x10 34 + 35 + #define SUN4I_TCON0_CTL_REG 0x40 36 + #define SUN4I_TCON0_CTL_TCON_ENABLE BIT(31) 37 + #define SUN4I_TCON0_CTL_CLK_DELAY_MASK GENMASK(8, 4) 38 + #define SUN4I_TCON0_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK) 39 + 40 + #define SUN4I_TCON0_DCLK_REG 0x44 41 + #define SUN4I_TCON0_DCLK_GATE_BIT (31) 42 + #define SUN4I_TCON0_DCLK_DIV_SHIFT (0) 43 + #define SUN4I_TCON0_DCLK_DIV_WIDTH (7) 44 + 45 + #define SUN4I_TCON0_BASIC0_REG 0x48 46 + #define SUN4I_TCON0_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 47 + #define SUN4I_TCON0_BASIC0_Y(height) (((height) - 1) & 0xfff) 48 + 49 + #define SUN4I_TCON0_BASIC1_REG 0x4c 50 + #define SUN4I_TCON0_BASIC1_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 51 + #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 52 + 53 + #define SUN4I_TCON0_BASIC2_REG 0x50 54 + #define SUN4I_TCON0_BASIC2_V_TOTAL(total) ((((total) * 2) & 0x1fff) << 16) 55 + #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 56 + 57 + #define SUN4I_TCON0_BASIC3_REG 0x54 58 + #define SUN4I_TCON0_BASIC3_H_SYNC(width) ((((width) - 1) & 0x7ff) << 16) 59 + #define SUN4I_TCON0_BASIC3_V_SYNC(height) (((height) - 1) & 0x7ff) 60 + 61 + #define SUN4I_TCON0_HV_IF_REG 0x58 62 + #define SUN4I_TCON0_CPU_IF_REG 0x60 63 + #define SUN4I_TCON0_CPU_WR_REG 0x64 64 + #define SUN4I_TCON0_CPU_RD0_REG 0x68 65 + #define SUN4I_TCON0_CPU_RDA_REG 0x6c 66 + #define SUN4I_TCON0_TTL0_REG 0x70 67 + #define SUN4I_TCON0_TTL1_REG 0x74 68 + #define SUN4I_TCON0_TTL2_REG 0x78 69 + #define SUN4I_TCON0_TTL3_REG 0x7c 70 + #define SUN4I_TCON0_TTL4_REG 0x80 71 + #define SUN4I_TCON0_LVDS_IF_REG 0x84 72 + #define SUN4I_TCON0_IO_POL_REG 0x88 73 + #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase) ((phase & 3) << 28) 74 + #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE BIT(25) 75 + #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE BIT(24) 76 + 77 + #define SUN4I_TCON0_IO_TRI_REG 0x8c 78 + #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE BIT(25) 79 + #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE BIT(24) 80 + #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins) GENMASK(pins, 0) 81 + 82 + #define SUN4I_TCON1_CTL_REG 0x90 83 + #define SUN4I_TCON1_CTL_TCON_ENABLE BIT(31) 84 + #define SUN4I_TCON1_CTL_INTERLACE_ENABLE BIT(20) 85 + #define SUN4I_TCON1_CTL_CLK_DELAY_MASK GENMASK(8, 4) 86 + #define SUN4I_TCON1_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK) 87 + 88 + #define SUN4I_TCON1_BASIC0_REG 0x94 89 + #define SUN4I_TCON1_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16) 90 + #define SUN4I_TCON1_BASIC0_Y(height) (((height) - 1) & 0xfff) 91 + 92 + #define SUN4I_TCON1_BASIC1_REG 0x98 93 + #define SUN4I_TCON1_BASIC1_X(width) ((((width) - 1) & 0xfff) << 16) 94 + #define SUN4I_TCON1_BASIC1_Y(height) (((height) - 1) & 0xfff) 95 + 96 + #define SUN4I_TCON1_BASIC2_REG 0x9c 97 + #define SUN4I_TCON1_BASIC2_X(width) ((((width) - 1) & 0xfff) << 16) 98 + #define SUN4I_TCON1_BASIC2_Y(height) (((height) - 1) & 0xfff) 99 + 100 + #define SUN4I_TCON1_BASIC3_REG 0xa0 101 + #define SUN4I_TCON1_BASIC3_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16) 102 + #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp) (((bp) - 1) & 0xfff) 103 + 104 + #define SUN4I_TCON1_BASIC4_REG 0xa4 105 + #define SUN4I_TCON1_BASIC4_V_TOTAL(total) (((total) & 0x1fff) << 16) 106 + #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp) (((bp) - 1) & 0xfff) 107 + 108 + #define SUN4I_TCON1_BASIC5_REG 0xa8 109 + #define SUN4I_TCON1_BASIC5_H_SYNC(width) ((((width) - 1) & 0x3ff) << 16) 110 + #define SUN4I_TCON1_BASIC5_V_SYNC(height) (((height) - 1) & 0x3ff) 111 + 112 + #define SUN4I_TCON1_IO_POL_REG 0xf0 113 + #define SUN4I_TCON1_IO_TRI_REG 0xf4 114 + #define SUN4I_TCON_CEU_CTL_REG 0x100 115 + #define SUN4I_TCON_CEU_MUL_RR_REG 0x110 116 + #define SUN4I_TCON_CEU_MUL_RG_REG 0x114 117 + #define SUN4I_TCON_CEU_MUL_RB_REG 0x118 118 + #define SUN4I_TCON_CEU_ADD_RC_REG 0x11c 119 + #define SUN4I_TCON_CEU_MUL_GR_REG 0x120 120 + #define SUN4I_TCON_CEU_MUL_GG_REG 0x124 121 + #define SUN4I_TCON_CEU_MUL_GB_REG 0x128 122 + #define SUN4I_TCON_CEU_ADD_GC_REG 0x12c 123 + #define SUN4I_TCON_CEU_MUL_BR_REG 0x130 124 + #define SUN4I_TCON_CEU_MUL_BG_REG 0x134 125 + #define SUN4I_TCON_CEU_MUL_BB_REG 0x138 126 + #define SUN4I_TCON_CEU_ADD_BC_REG 0x13c 127 + #define SUN4I_TCON_CEU_RANGE_R_REG 0x140 128 + #define SUN4I_TCON_CEU_RANGE_G_REG 0x144 129 + #define SUN4I_TCON_CEU_RANGE_B_REG 0x148 130 + #define SUN4I_TCON_MUX_CTRL_REG 0x200 131 + #define SUN4I_TCON1_FILL_CTL_REG 0x300 132 + #define SUN4I_TCON1_FILL_BEG0_REG 0x304 133 + #define SUN4I_TCON1_FILL_END0_REG 0x308 134 + #define SUN4I_TCON1_FILL_DATA0_REG 0x30c 135 + #define SUN4I_TCON1_FILL_BEG1_REG 0x310 136 + #define SUN4I_TCON1_FILL_END1_REG 0x314 137 + #define SUN4I_TCON1_FILL_DATA1_REG 0x318 138 + #define SUN4I_TCON1_FILL_BEG2_REG 0x31c 139 + #define SUN4I_TCON1_FILL_END2_REG 0x320 140 + #define SUN4I_TCON1_FILL_DATA2_REG 0x324 141 + #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400 142 + 143 + #define SUN4I_TCON_MAX_CHANNELS 2 144 + 145 + struct sun4i_tcon { 146 + struct drm_device *drm; 147 + struct regmap *regs; 148 + 149 + /* Main bus clock */ 150 + struct clk *clk; 151 + 152 + /* Clocks for the TCON channels */ 153 + struct clk *sclk0; 154 + struct clk *sclk1; 155 + 156 + /* Pixel clock */ 157 + struct clk *dclk; 158 + 159 + /* Reset control */ 160 + struct reset_control *lcd_rst; 161 + 162 + /* Platform adjustments */ 163 + bool has_mux; 164 + 165 + struct drm_panel *panel; 166 + }; 167 + 168 + /* Global Control */ 169 + void sun4i_tcon_disable(struct sun4i_tcon *tcon); 170 + void sun4i_tcon_enable(struct sun4i_tcon *tcon); 171 + 172 + /* Channel Control */ 173 + void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel); 174 + void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel); 175 + 176 + void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable); 177 + 178 + /* Mode Related Controls */ 179 + void sun4i_tcon_switch_interlace(struct sun4i_tcon *tcon, 180 + bool enable); 181 + void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon, 182 + struct drm_display_mode *mode); 183 + void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon, 184 + struct drm_display_mode *mode); 185 + 186 + #endif /* __SUN4I_TCON_H__ */
+708
drivers/gpu/drm/sun4i/sun4i_tv.c
··· 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 <linux/clk.h> 14 + #include <linux/component.h> 15 + #include <linux/of_address.h> 16 + #include <linux/regmap.h> 17 + #include <linux/reset.h> 18 + 19 + #include <drm/drmP.h> 20 + #include <drm/drm_atomic_helper.h> 21 + #include <drm/drm_crtc_helper.h> 22 + #include <drm/drm_panel.h> 23 + 24 + #include "sun4i_backend.h" 25 + #include "sun4i_drv.h" 26 + #include "sun4i_tcon.h" 27 + 28 + #define SUN4I_TVE_EN_REG 0x000 29 + #define SUN4I_TVE_EN_DAC_MAP_MASK GENMASK(19, 4) 30 + #define SUN4I_TVE_EN_DAC_MAP(dac, out) (((out) & 0xf) << (dac + 1) * 4) 31 + #define SUN4I_TVE_EN_ENABLE BIT(0) 32 + 33 + #define SUN4I_TVE_CFG0_REG 0x004 34 + #define SUN4I_TVE_CFG0_DAC_CONTROL_54M BIT(26) 35 + #define SUN4I_TVE_CFG0_CORE_DATAPATH_54M BIT(25) 36 + #define SUN4I_TVE_CFG0_CORE_CONTROL_54M BIT(24) 37 + #define SUN4I_TVE_CFG0_YC_EN BIT(17) 38 + #define SUN4I_TVE_CFG0_COMP_EN BIT(16) 39 + #define SUN4I_TVE_CFG0_RES(x) ((x) & 0xf) 40 + #define SUN4I_TVE_CFG0_RES_480i SUN4I_TVE_CFG0_RES(0) 41 + #define SUN4I_TVE_CFG0_RES_576i SUN4I_TVE_CFG0_RES(1) 42 + 43 + #define SUN4I_TVE_DAC0_REG 0x008 44 + #define SUN4I_TVE_DAC0_CLOCK_INVERT BIT(24) 45 + #define SUN4I_TVE_DAC0_LUMA(x) (((x) & 3) << 20) 46 + #define SUN4I_TVE_DAC0_LUMA_0_4 SUN4I_TVE_DAC0_LUMA(3) 47 + #define SUN4I_TVE_DAC0_CHROMA(x) (((x) & 3) << 18) 48 + #define SUN4I_TVE_DAC0_CHROMA_0_75 SUN4I_TVE_DAC0_CHROMA(3) 49 + #define SUN4I_TVE_DAC0_INTERNAL_DAC(x) (((x) & 3) << 16) 50 + #define SUN4I_TVE_DAC0_INTERNAL_DAC_37_5_OHMS SUN4I_TVE_DAC0_INTERNAL_DAC(3) 51 + #define SUN4I_TVE_DAC0_DAC_EN(dac) BIT(dac) 52 + 53 + #define SUN4I_TVE_NOTCH_REG 0x00c 54 + #define SUN4I_TVE_NOTCH_DAC0_TO_DAC_DLY(dac, x) ((4 - (x)) << (dac * 3)) 55 + 56 + #define SUN4I_TVE_CHROMA_FREQ_REG 0x010 57 + 58 + #define SUN4I_TVE_PORCH_REG 0x014 59 + #define SUN4I_TVE_PORCH_BACK(x) ((x) << 16) 60 + #define SUN4I_TVE_PORCH_FRONT(x) (x) 61 + 62 + #define SUN4I_TVE_LINE_REG 0x01c 63 + #define SUN4I_TVE_LINE_FIRST(x) ((x) << 16) 64 + #define SUN4I_TVE_LINE_NUMBER(x) (x) 65 + 66 + #define SUN4I_TVE_LEVEL_REG 0x020 67 + #define SUN4I_TVE_LEVEL_BLANK(x) ((x) << 16) 68 + #define SUN4I_TVE_LEVEL_BLACK(x) (x) 69 + 70 + #define SUN4I_TVE_DAC1_REG 0x024 71 + #define SUN4I_TVE_DAC1_AMPLITUDE(dac, x) ((x) << (dac * 8)) 72 + 73 + #define SUN4I_TVE_DETECT_STA_REG 0x038 74 + #define SUN4I_TVE_DETECT_STA_DAC(dac) BIT((dac * 8)) 75 + #define SUN4I_TVE_DETECT_STA_UNCONNECTED 0 76 + #define SUN4I_TVE_DETECT_STA_CONNECTED 1 77 + #define SUN4I_TVE_DETECT_STA_GROUND 2 78 + 79 + #define SUN4I_TVE_CB_CR_LVL_REG 0x10c 80 + #define SUN4I_TVE_CB_CR_LVL_CR_BURST(x) ((x) << 8) 81 + #define SUN4I_TVE_CB_CR_LVL_CB_BURST(x) (x) 82 + 83 + #define SUN4I_TVE_TINT_BURST_PHASE_REG 0x110 84 + #define SUN4I_TVE_TINT_BURST_PHASE_CHROMA(x) (x) 85 + 86 + #define SUN4I_TVE_BURST_WIDTH_REG 0x114 87 + #define SUN4I_TVE_BURST_WIDTH_BREEZEWAY(x) ((x) << 16) 88 + #define SUN4I_TVE_BURST_WIDTH_BURST_WIDTH(x) ((x) << 8) 89 + #define SUN4I_TVE_BURST_WIDTH_HSYNC_WIDTH(x) (x) 90 + 91 + #define SUN4I_TVE_CB_CR_GAIN_REG 0x118 92 + #define SUN4I_TVE_CB_CR_GAIN_CR(x) ((x) << 8) 93 + #define SUN4I_TVE_CB_CR_GAIN_CB(x) (x) 94 + 95 + #define SUN4I_TVE_SYNC_VBI_REG 0x11c 96 + #define SUN4I_TVE_SYNC_VBI_SYNC(x) ((x) << 16) 97 + #define SUN4I_TVE_SYNC_VBI_VBLANK(x) (x) 98 + 99 + #define SUN4I_TVE_ACTIVE_LINE_REG 0x124 100 + #define SUN4I_TVE_ACTIVE_LINE(x) (x) 101 + 102 + #define SUN4I_TVE_CHROMA_REG 0x128 103 + #define SUN4I_TVE_CHROMA_COMP_GAIN(x) ((x) & 3) 104 + #define SUN4I_TVE_CHROMA_COMP_GAIN_50 SUN4I_TVE_CHROMA_COMP_GAIN(2) 105 + 106 + #define SUN4I_TVE_12C_REG 0x12c 107 + #define SUN4I_TVE_12C_NOTCH_WIDTH_WIDE BIT(8) 108 + #define SUN4I_TVE_12C_COMP_YUV_EN BIT(0) 109 + 110 + #define SUN4I_TVE_RESYNC_REG 0x130 111 + #define SUN4I_TVE_RESYNC_FIELD BIT(31) 112 + #define SUN4I_TVE_RESYNC_LINE(x) ((x) << 16) 113 + #define SUN4I_TVE_RESYNC_PIXEL(x) (x) 114 + 115 + #define SUN4I_TVE_SLAVE_REG 0x134 116 + 117 + #define SUN4I_TVE_WSS_DATA2_REG 0x244 118 + 119 + struct color_gains { 120 + u16 cb; 121 + u16 cr; 122 + }; 123 + 124 + struct burst_levels { 125 + u16 cb; 126 + u16 cr; 127 + }; 128 + 129 + struct video_levels { 130 + u16 black; 131 + u16 blank; 132 + }; 133 + 134 + struct resync_parameters { 135 + bool field; 136 + u16 line; 137 + u16 pixel; 138 + }; 139 + 140 + struct tv_mode { 141 + char *name; 142 + 143 + u32 mode; 144 + u32 chroma_freq; 145 + u16 back_porch; 146 + u16 front_porch; 147 + u16 line_number; 148 + u16 vblank_level; 149 + 150 + u32 hdisplay; 151 + u16 hfront_porch; 152 + u16 hsync_len; 153 + u16 hback_porch; 154 + 155 + u32 vdisplay; 156 + u16 vfront_porch; 157 + u16 vsync_len; 158 + u16 vback_porch; 159 + 160 + bool yc_en; 161 + bool dac3_en; 162 + bool dac_bit25_en; 163 + 164 + struct color_gains *color_gains; 165 + struct burst_levels *burst_levels; 166 + struct video_levels *video_levels; 167 + struct resync_parameters *resync_params; 168 + }; 169 + 170 + struct sun4i_tv { 171 + struct drm_connector connector; 172 + struct drm_encoder encoder; 173 + 174 + struct clk *clk; 175 + struct regmap *regs; 176 + struct reset_control *reset; 177 + 178 + struct sun4i_drv *drv; 179 + }; 180 + 181 + struct video_levels ntsc_video_levels = { 182 + .black = 282, .blank = 240, 183 + }; 184 + 185 + struct video_levels pal_video_levels = { 186 + .black = 252, .blank = 252, 187 + }; 188 + 189 + struct burst_levels ntsc_burst_levels = { 190 + .cb = 79, .cr = 0, 191 + }; 192 + 193 + struct burst_levels pal_burst_levels = { 194 + .cb = 40, .cr = 40, 195 + }; 196 + 197 + struct color_gains ntsc_color_gains = { 198 + .cb = 160, .cr = 160, 199 + }; 200 + 201 + struct color_gains pal_color_gains = { 202 + .cb = 224, .cr = 224, 203 + }; 204 + 205 + struct resync_parameters ntsc_resync_parameters = { 206 + .field = false, .line = 14, .pixel = 12, 207 + }; 208 + 209 + struct resync_parameters pal_resync_parameters = { 210 + .field = true, .line = 13, .pixel = 12, 211 + }; 212 + 213 + struct tv_mode tv_modes[] = { 214 + { 215 + .name = "NTSC", 216 + .mode = SUN4I_TVE_CFG0_RES_480i, 217 + .chroma_freq = 0x21f07c1f, 218 + .yc_en = true, 219 + .dac3_en = true, 220 + .dac_bit25_en = true, 221 + 222 + .back_porch = 118, 223 + .front_porch = 32, 224 + .line_number = 525, 225 + 226 + .hdisplay = 720, 227 + .hfront_porch = 18, 228 + .hsync_len = 2, 229 + .hback_porch = 118, 230 + 231 + .vdisplay = 480, 232 + .vfront_porch = 26, 233 + .vsync_len = 2, 234 + .vback_porch = 17, 235 + 236 + .vblank_level = 240, 237 + 238 + .color_gains = &ntsc_color_gains, 239 + .burst_levels = &ntsc_burst_levels, 240 + .video_levels = &ntsc_video_levels, 241 + .resync_params = &ntsc_resync_parameters, 242 + }, 243 + { 244 + .name = "PAL", 245 + .mode = SUN4I_TVE_CFG0_RES_576i, 246 + .chroma_freq = 0x2a098acb, 247 + 248 + .back_porch = 138, 249 + .front_porch = 24, 250 + .line_number = 625, 251 + 252 + .hdisplay = 720, 253 + .hfront_porch = 3, 254 + .hsync_len = 2, 255 + .hback_porch = 139, 256 + 257 + .vdisplay = 576, 258 + .vfront_porch = 28, 259 + .vsync_len = 2, 260 + .vback_porch = 19, 261 + 262 + .vblank_level = 252, 263 + 264 + .color_gains = &pal_color_gains, 265 + .burst_levels = &pal_burst_levels, 266 + .video_levels = &pal_video_levels, 267 + .resync_params = &pal_resync_parameters, 268 + }, 269 + }; 270 + 271 + static inline struct sun4i_tv * 272 + drm_encoder_to_sun4i_tv(struct drm_encoder *encoder) 273 + { 274 + return container_of(encoder, struct sun4i_tv, 275 + encoder); 276 + } 277 + 278 + static inline struct sun4i_tv * 279 + drm_connector_to_sun4i_tv(struct drm_connector *connector) 280 + { 281 + return container_of(connector, struct sun4i_tv, 282 + connector); 283 + } 284 + 285 + /* 286 + * FIXME: If only the drm_display_mode private field was usable, this 287 + * could go away... 288 + * 289 + * So far, it doesn't seem to be preserved when the mode is passed by 290 + * to mode_set for some reason. 291 + */ 292 + static struct tv_mode *sun4i_tv_find_tv_by_mode(struct drm_display_mode *mode) 293 + { 294 + int i; 295 + 296 + /* First try to identify the mode by name */ 297 + for (i = 0; i < ARRAY_SIZE(tv_modes); i++) { 298 + struct tv_mode *tv_mode = &tv_modes[i]; 299 + 300 + DRM_DEBUG_DRIVER("Comparing mode %s vs %s", 301 + mode->name, tv_mode->name); 302 + 303 + if (!strcmp(mode->name, tv_mode->name)) 304 + return tv_mode; 305 + } 306 + 307 + /* Then by number of lines */ 308 + for (i = 0; i < ARRAY_SIZE(tv_modes); i++) { 309 + struct tv_mode *tv_mode = &tv_modes[i]; 310 + 311 + DRM_DEBUG_DRIVER("Comparing mode %s vs %s (X: %d vs %d)", 312 + mode->name, tv_mode->name, 313 + mode->vdisplay, tv_mode->vdisplay); 314 + 315 + if (mode->vdisplay == tv_mode->vdisplay) 316 + return tv_mode; 317 + } 318 + 319 + return NULL; 320 + } 321 + 322 + static void sun4i_tv_mode_to_drm_mode(struct tv_mode *tv_mode, 323 + struct drm_display_mode *mode) 324 + { 325 + DRM_DEBUG_DRIVER("Creating mode %s\n", mode->name); 326 + 327 + mode->type = DRM_MODE_TYPE_DRIVER; 328 + mode->clock = 13500; 329 + mode->flags = DRM_MODE_FLAG_INTERLACE; 330 + 331 + mode->hdisplay = tv_mode->hdisplay; 332 + mode->hsync_start = mode->hdisplay + tv_mode->hfront_porch; 333 + mode->hsync_end = mode->hsync_start + tv_mode->hsync_len; 334 + mode->htotal = mode->hsync_end + tv_mode->hback_porch; 335 + 336 + mode->vdisplay = tv_mode->vdisplay; 337 + mode->vsync_start = mode->vdisplay + tv_mode->vfront_porch; 338 + mode->vsync_end = mode->vsync_start + tv_mode->vsync_len; 339 + mode->vtotal = mode->vsync_end + tv_mode->vback_porch; 340 + } 341 + 342 + static int sun4i_tv_atomic_check(struct drm_encoder *encoder, 343 + struct drm_crtc_state *crtc_state, 344 + struct drm_connector_state *conn_state) 345 + { 346 + return 0; 347 + } 348 + 349 + static void sun4i_tv_disable(struct drm_encoder *encoder) 350 + { 351 + struct sun4i_tv *tv = drm_encoder_to_sun4i_tv(encoder); 352 + struct sun4i_drv *drv = tv->drv; 353 + struct sun4i_tcon *tcon = drv->tcon; 354 + 355 + DRM_DEBUG_DRIVER("Disabling the TV Output\n"); 356 + 357 + sun4i_tcon_channel_disable(tcon, 1); 358 + 359 + regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG, 360 + SUN4I_TVE_EN_ENABLE, 361 + 0); 362 + sun4i_backend_disable_color_correction(drv->backend); 363 + } 364 + 365 + static void sun4i_tv_enable(struct drm_encoder *encoder) 366 + { 367 + struct sun4i_tv *tv = drm_encoder_to_sun4i_tv(encoder); 368 + struct sun4i_drv *drv = tv->drv; 369 + struct sun4i_tcon *tcon = drv->tcon; 370 + 371 + DRM_DEBUG_DRIVER("Enabling the TV Output\n"); 372 + 373 + sun4i_backend_apply_color_correction(drv->backend); 374 + 375 + regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG, 376 + SUN4I_TVE_EN_ENABLE, 377 + SUN4I_TVE_EN_ENABLE); 378 + 379 + sun4i_tcon_channel_enable(tcon, 1); 380 + } 381 + 382 + static void sun4i_tv_mode_set(struct drm_encoder *encoder, 383 + struct drm_display_mode *mode, 384 + struct drm_display_mode *adjusted_mode) 385 + { 386 + struct sun4i_tv *tv = drm_encoder_to_sun4i_tv(encoder); 387 + struct sun4i_drv *drv = tv->drv; 388 + struct sun4i_tcon *tcon = drv->tcon; 389 + struct tv_mode *tv_mode = sun4i_tv_find_tv_by_mode(mode); 390 + 391 + sun4i_tcon1_mode_set(tcon, mode); 392 + 393 + /* Enable and map the DAC to the output */ 394 + regmap_update_bits(tv->regs, SUN4I_TVE_EN_REG, 395 + SUN4I_TVE_EN_DAC_MAP_MASK, 396 + SUN4I_TVE_EN_DAC_MAP(0, 1) | 397 + SUN4I_TVE_EN_DAC_MAP(1, 2) | 398 + SUN4I_TVE_EN_DAC_MAP(2, 3) | 399 + SUN4I_TVE_EN_DAC_MAP(3, 4)); 400 + 401 + /* Set PAL settings */ 402 + regmap_write(tv->regs, SUN4I_TVE_CFG0_REG, 403 + tv_mode->mode | 404 + (tv_mode->yc_en ? SUN4I_TVE_CFG0_YC_EN : 0) | 405 + SUN4I_TVE_CFG0_COMP_EN | 406 + SUN4I_TVE_CFG0_DAC_CONTROL_54M | 407 + SUN4I_TVE_CFG0_CORE_DATAPATH_54M | 408 + SUN4I_TVE_CFG0_CORE_CONTROL_54M); 409 + 410 + /* Configure the DAC for a composite output */ 411 + regmap_write(tv->regs, SUN4I_TVE_DAC0_REG, 412 + SUN4I_TVE_DAC0_DAC_EN(0) | 413 + (tv_mode->dac3_en ? SUN4I_TVE_DAC0_DAC_EN(3) : 0) | 414 + SUN4I_TVE_DAC0_INTERNAL_DAC_37_5_OHMS | 415 + SUN4I_TVE_DAC0_CHROMA_0_75 | 416 + SUN4I_TVE_DAC0_LUMA_0_4 | 417 + SUN4I_TVE_DAC0_CLOCK_INVERT | 418 + (tv_mode->dac_bit25_en ? BIT(25) : 0) | 419 + BIT(30)); 420 + 421 + /* Configure the sample delay between DAC0 and the other DAC */ 422 + regmap_write(tv->regs, SUN4I_TVE_NOTCH_REG, 423 + SUN4I_TVE_NOTCH_DAC0_TO_DAC_DLY(1, 0) | 424 + SUN4I_TVE_NOTCH_DAC0_TO_DAC_DLY(2, 0)); 425 + 426 + regmap_write(tv->regs, SUN4I_TVE_CHROMA_FREQ_REG, 427 + tv_mode->chroma_freq); 428 + 429 + /* Set the front and back porch */ 430 + regmap_write(tv->regs, SUN4I_TVE_PORCH_REG, 431 + SUN4I_TVE_PORCH_BACK(tv_mode->back_porch) | 432 + SUN4I_TVE_PORCH_FRONT(tv_mode->front_porch)); 433 + 434 + /* Set the lines setup */ 435 + regmap_write(tv->regs, SUN4I_TVE_LINE_REG, 436 + SUN4I_TVE_LINE_FIRST(22) | 437 + SUN4I_TVE_LINE_NUMBER(tv_mode->line_number)); 438 + 439 + regmap_write(tv->regs, SUN4I_TVE_LEVEL_REG, 440 + SUN4I_TVE_LEVEL_BLANK(tv_mode->video_levels->blank) | 441 + SUN4I_TVE_LEVEL_BLACK(tv_mode->video_levels->black)); 442 + 443 + regmap_write(tv->regs, SUN4I_TVE_DAC1_REG, 444 + SUN4I_TVE_DAC1_AMPLITUDE(0, 0x18) | 445 + SUN4I_TVE_DAC1_AMPLITUDE(1, 0x18) | 446 + SUN4I_TVE_DAC1_AMPLITUDE(2, 0x18) | 447 + SUN4I_TVE_DAC1_AMPLITUDE(3, 0x18)); 448 + 449 + regmap_write(tv->regs, SUN4I_TVE_CB_CR_LVL_REG, 450 + SUN4I_TVE_CB_CR_LVL_CB_BURST(tv_mode->burst_levels->cb) | 451 + SUN4I_TVE_CB_CR_LVL_CR_BURST(tv_mode->burst_levels->cr)); 452 + 453 + /* Set burst width for a composite output */ 454 + regmap_write(tv->regs, SUN4I_TVE_BURST_WIDTH_REG, 455 + SUN4I_TVE_BURST_WIDTH_HSYNC_WIDTH(126) | 456 + SUN4I_TVE_BURST_WIDTH_BURST_WIDTH(68) | 457 + SUN4I_TVE_BURST_WIDTH_BREEZEWAY(22)); 458 + 459 + regmap_write(tv->regs, SUN4I_TVE_CB_CR_GAIN_REG, 460 + SUN4I_TVE_CB_CR_GAIN_CB(tv_mode->color_gains->cb) | 461 + SUN4I_TVE_CB_CR_GAIN_CR(tv_mode->color_gains->cr)); 462 + 463 + regmap_write(tv->regs, SUN4I_TVE_SYNC_VBI_REG, 464 + SUN4I_TVE_SYNC_VBI_SYNC(0x10) | 465 + SUN4I_TVE_SYNC_VBI_VBLANK(tv_mode->vblank_level)); 466 + 467 + regmap_write(tv->regs, SUN4I_TVE_ACTIVE_LINE_REG, 468 + SUN4I_TVE_ACTIVE_LINE(1440)); 469 + 470 + /* Set composite chroma gain to 50 % */ 471 + regmap_write(tv->regs, SUN4I_TVE_CHROMA_REG, 472 + SUN4I_TVE_CHROMA_COMP_GAIN_50); 473 + 474 + regmap_write(tv->regs, SUN4I_TVE_12C_REG, 475 + SUN4I_TVE_12C_COMP_YUV_EN | 476 + SUN4I_TVE_12C_NOTCH_WIDTH_WIDE); 477 + 478 + regmap_write(tv->regs, SUN4I_TVE_RESYNC_REG, 479 + SUN4I_TVE_RESYNC_PIXEL(tv_mode->resync_params->pixel) | 480 + SUN4I_TVE_RESYNC_LINE(tv_mode->resync_params->line) | 481 + (tv_mode->resync_params->field ? 482 + SUN4I_TVE_RESYNC_FIELD : 0)); 483 + 484 + regmap_write(tv->regs, SUN4I_TVE_SLAVE_REG, 0); 485 + 486 + clk_set_rate(tcon->sclk1, mode->crtc_clock * 1000); 487 + } 488 + 489 + static struct drm_encoder_helper_funcs sun4i_tv_helper_funcs = { 490 + .atomic_check = sun4i_tv_atomic_check, 491 + .disable = sun4i_tv_disable, 492 + .enable = sun4i_tv_enable, 493 + .mode_set = sun4i_tv_mode_set, 494 + }; 495 + 496 + static void sun4i_tv_destroy(struct drm_encoder *encoder) 497 + { 498 + drm_encoder_cleanup(encoder); 499 + } 500 + 501 + static struct drm_encoder_funcs sun4i_tv_funcs = { 502 + .destroy = sun4i_tv_destroy, 503 + }; 504 + 505 + static int sun4i_tv_comp_get_modes(struct drm_connector *connector) 506 + { 507 + int i; 508 + 509 + for (i = 0; i < ARRAY_SIZE(tv_modes); i++) { 510 + struct drm_display_mode *mode = drm_mode_create(connector->dev); 511 + struct tv_mode *tv_mode = &tv_modes[i]; 512 + 513 + strcpy(mode->name, tv_mode->name); 514 + 515 + sun4i_tv_mode_to_drm_mode(tv_mode, mode); 516 + drm_mode_probed_add(connector, mode); 517 + } 518 + 519 + return i; 520 + } 521 + 522 + static int sun4i_tv_comp_mode_valid(struct drm_connector *connector, 523 + struct drm_display_mode *mode) 524 + { 525 + /* TODO */ 526 + return MODE_OK; 527 + } 528 + 529 + static struct drm_encoder * 530 + sun4i_tv_comp_best_encoder(struct drm_connector *connector) 531 + { 532 + struct sun4i_tv *tv = drm_connector_to_sun4i_tv(connector); 533 + 534 + return &tv->encoder; 535 + } 536 + 537 + static struct drm_connector_helper_funcs sun4i_tv_comp_connector_helper_funcs = { 538 + .get_modes = sun4i_tv_comp_get_modes, 539 + .mode_valid = sun4i_tv_comp_mode_valid, 540 + .best_encoder = sun4i_tv_comp_best_encoder, 541 + }; 542 + 543 + static enum drm_connector_status 544 + sun4i_tv_comp_connector_detect(struct drm_connector *connector, bool force) 545 + { 546 + return connector_status_connected; 547 + } 548 + 549 + static void 550 + sun4i_tv_comp_connector_destroy(struct drm_connector *connector) 551 + { 552 + drm_connector_cleanup(connector); 553 + } 554 + 555 + static struct drm_connector_funcs sun4i_tv_comp_connector_funcs = { 556 + .dpms = drm_atomic_helper_connector_dpms, 557 + .detect = sun4i_tv_comp_connector_detect, 558 + .fill_modes = drm_helper_probe_single_connector_modes, 559 + .destroy = sun4i_tv_comp_connector_destroy, 560 + .reset = drm_atomic_helper_connector_reset, 561 + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, 562 + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, 563 + }; 564 + 565 + static struct regmap_config sun4i_tv_regmap_config = { 566 + .reg_bits = 32, 567 + .val_bits = 32, 568 + .reg_stride = 4, 569 + .max_register = SUN4I_TVE_WSS_DATA2_REG, 570 + .name = "tv-encoder", 571 + }; 572 + 573 + static int sun4i_tv_bind(struct device *dev, struct device *master, 574 + void *data) 575 + { 576 + struct platform_device *pdev = to_platform_device(dev); 577 + struct drm_device *drm = data; 578 + struct sun4i_drv *drv = drm->dev_private; 579 + struct sun4i_tv *tv; 580 + struct resource *res; 581 + void __iomem *regs; 582 + int ret; 583 + 584 + tv = devm_kzalloc(dev, sizeof(*tv), GFP_KERNEL); 585 + if (!tv) 586 + return -ENOMEM; 587 + tv->drv = drv; 588 + dev_set_drvdata(dev, tv); 589 + 590 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 591 + regs = devm_ioremap_resource(dev, res); 592 + if (IS_ERR(regs)) { 593 + dev_err(dev, "Couldn't map the TV encoder registers\n"); 594 + return PTR_ERR(regs); 595 + } 596 + 597 + tv->regs = devm_regmap_init_mmio(dev, regs, 598 + &sun4i_tv_regmap_config); 599 + if (IS_ERR(tv->regs)) { 600 + dev_err(dev, "Couldn't create the TV encoder regmap\n"); 601 + return PTR_ERR(tv->regs); 602 + } 603 + 604 + tv->reset = devm_reset_control_get(dev, NULL); 605 + if (IS_ERR(tv->reset)) { 606 + dev_err(dev, "Couldn't get our reset line\n"); 607 + return PTR_ERR(tv->reset); 608 + } 609 + 610 + ret = reset_control_deassert(tv->reset); 611 + if (ret) { 612 + dev_err(dev, "Couldn't deassert our reset line\n"); 613 + return ret; 614 + } 615 + 616 + tv->clk = devm_clk_get(dev, NULL); 617 + if (IS_ERR(tv->clk)) { 618 + dev_err(dev, "Couldn't get the TV encoder clock\n"); 619 + ret = PTR_ERR(tv->clk); 620 + goto err_assert_reset; 621 + } 622 + clk_prepare_enable(tv->clk); 623 + 624 + drm_encoder_helper_add(&tv->encoder, 625 + &sun4i_tv_helper_funcs); 626 + ret = drm_encoder_init(drm, 627 + &tv->encoder, 628 + &sun4i_tv_funcs, 629 + DRM_MODE_ENCODER_TVDAC, 630 + NULL); 631 + if (ret) { 632 + dev_err(dev, "Couldn't initialise the TV encoder\n"); 633 + goto err_disable_clk; 634 + } 635 + 636 + tv->encoder.possible_crtcs = BIT(0); 637 + 638 + drm_connector_helper_add(&tv->connector, 639 + &sun4i_tv_comp_connector_helper_funcs); 640 + ret = drm_connector_init(drm, &tv->connector, 641 + &sun4i_tv_comp_connector_funcs, 642 + DRM_MODE_CONNECTOR_Composite); 643 + if (ret) { 644 + dev_err(dev, 645 + "Couldn't initialise the Composite connector\n"); 646 + goto err_cleanup_connector; 647 + } 648 + tv->connector.interlace_allowed = true; 649 + 650 + drm_mode_connector_attach_encoder(&tv->connector, &tv->encoder); 651 + 652 + return 0; 653 + 654 + err_cleanup_connector: 655 + drm_encoder_cleanup(&tv->encoder); 656 + err_disable_clk: 657 + clk_disable_unprepare(tv->clk); 658 + err_assert_reset: 659 + reset_control_assert(tv->reset); 660 + return ret; 661 + } 662 + 663 + static void sun4i_tv_unbind(struct device *dev, struct device *master, 664 + void *data) 665 + { 666 + struct sun4i_tv *tv = dev_get_drvdata(dev); 667 + 668 + drm_connector_cleanup(&tv->connector); 669 + drm_encoder_cleanup(&tv->encoder); 670 + clk_disable_unprepare(tv->clk); 671 + } 672 + 673 + static struct component_ops sun4i_tv_ops = { 674 + .bind = sun4i_tv_bind, 675 + .unbind = sun4i_tv_unbind, 676 + }; 677 + 678 + static int sun4i_tv_probe(struct platform_device *pdev) 679 + { 680 + return component_add(&pdev->dev, &sun4i_tv_ops); 681 + } 682 + 683 + static int sun4i_tv_remove(struct platform_device *pdev) 684 + { 685 + component_del(&pdev->dev, &sun4i_tv_ops); 686 + 687 + return 0; 688 + } 689 + 690 + static const struct of_device_id sun4i_tv_of_table[] = { 691 + { .compatible = "allwinner,sun4i-a10-tv-encoder" }, 692 + { } 693 + }; 694 + MODULE_DEVICE_TABLE(of, sun4i_tv_of_table); 695 + 696 + static struct platform_driver sun4i_tv_platform_driver = { 697 + .probe = sun4i_tv_probe, 698 + .remove = sun4i_tv_remove, 699 + .driver = { 700 + .name = "sun4i-tve", 701 + .of_match_table = sun4i_tv_of_table, 702 + }, 703 + }; 704 + module_platform_driver(sun4i_tv_platform_driver); 705 + 706 + MODULE_AUTHOR("Maxime Ripard <maxime.ripard@free-electrons.com>"); 707 + MODULE_DESCRIPTION("Allwinner A10 TV Encoder Driver"); 708 + MODULE_LICENSE("GPL");
+2
include/drm/drm_fb_cma_helper.h
··· 24 24 unsigned int plane); 25 25 26 26 #ifdef CONFIG_DEBUG_FS 27 + struct seq_file; 28 + 27 29 int drm_fb_cma_debugfs_show(struct seq_file *m, void *arg); 28 30 #endif 29 31