Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1 | /* exynos_drm_fimd.c |
| 2 | * |
| 3 | * Copyright (C) 2011 Samsung Electronics Co.Ltd |
| 4 | * Authors: |
| 5 | * Joonyoung Shim <jy0922.shim@samsung.com> |
| 6 | * Inki Dae <inki.dae@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 14 | #include <drm/drmP.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 15 | |
| 16 | #include <linux/kernel.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/clk.h> |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 20 | #include <linux/of_device.h> |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 22 | |
Vikas Sajjan | 7f4596f | 2013-03-07 12:15:21 +0530 | [diff] [blame] | 23 | #include <video/of_display_timing.h> |
Leela Krishna Amudala | 5a213a5 | 2012-08-08 09:44:49 +0900 | [diff] [blame] | 24 | #include <video/samsung_fimd.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 25 | #include <drm/exynos_drm.h> |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 26 | |
| 27 | #include "exynos_drm_drv.h" |
| 28 | #include "exynos_drm_fbdev.h" |
| 29 | #include "exynos_drm_crtc.h" |
Inki Dae | bcc5cd1c | 2012-10-19 17:16:36 +0900 | [diff] [blame] | 30 | #include "exynos_drm_iommu.h" |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 31 | |
| 32 | /* |
| 33 | * FIMD is stand for Fully Interactive Mobile Display and |
| 34 | * as a display controller, it transfers contents drawn on memory |
| 35 | * to a LCD Panel through Display Interfaces such as RGB or |
| 36 | * CPU Interface. |
| 37 | */ |
| 38 | |
| 39 | /* position control register for hardware window 0, 2 ~ 4.*/ |
| 40 | #define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16) |
| 41 | #define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16) |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 42 | /* |
| 43 | * size control register for hardware windows 0 and alpha control register |
| 44 | * for hardware windows 1 ~ 4 |
| 45 | */ |
| 46 | #define VIDOSD_C(win) (VIDOSD_BASE + 0x08 + (win) * 16) |
| 47 | /* size control register for hardware windows 1 ~ 2. */ |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 48 | #define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16) |
| 49 | |
| 50 | #define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8) |
| 51 | #define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8) |
| 52 | #define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4) |
| 53 | |
| 54 | /* color key control register for hardware window 1 ~ 4. */ |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 55 | #define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + ((x - 1) * 8)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 56 | /* color key value register for hardware window 1 ~ 4. */ |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 57 | #define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + ((x - 1) * 8)) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 58 | |
| 59 | /* FIMD has totally five hardware windows. */ |
| 60 | #define WINDOWS_NR 5 |
| 61 | |
| 62 | #define get_fimd_context(dev) platform_get_drvdata(to_platform_device(dev)) |
| 63 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 64 | struct fimd_driver_data { |
| 65 | unsigned int timing_base; |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 66 | |
| 67 | unsigned int has_shadowcon:1; |
Tomasz Figa | 411d9ed | 2013-05-01 21:02:28 +0200 | [diff] [blame] | 68 | unsigned int has_clksel:1; |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 69 | }; |
| 70 | |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 71 | static struct fimd_driver_data s3c64xx_fimd_driver_data = { |
| 72 | .timing_base = 0x0, |
| 73 | .has_clksel = 1, |
| 74 | }; |
| 75 | |
Sachin Kamat | 6ecf18f | 2012-11-19 15:22:54 +0530 | [diff] [blame] | 76 | static struct fimd_driver_data exynos4_fimd_driver_data = { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 77 | .timing_base = 0x0, |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 78 | .has_shadowcon = 1, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 79 | }; |
| 80 | |
Sachin Kamat | 6ecf18f | 2012-11-19 15:22:54 +0530 | [diff] [blame] | 81 | static struct fimd_driver_data exynos5_fimd_driver_data = { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 82 | .timing_base = 0x20000, |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 83 | .has_shadowcon = 1, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 84 | }; |
| 85 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 86 | struct fimd_win_data { |
| 87 | unsigned int offset_x; |
| 88 | unsigned int offset_y; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 89 | unsigned int ovl_width; |
| 90 | unsigned int ovl_height; |
| 91 | unsigned int fb_width; |
| 92 | unsigned int fb_height; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 93 | unsigned int bpp; |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 94 | dma_addr_t dma_addr; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 95 | unsigned int buf_offsize; |
| 96 | unsigned int line_size; /* bytes */ |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 97 | bool enabled; |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 98 | bool resume; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | struct fimd_context { |
| 102 | struct exynos_drm_subdrv subdrv; |
| 103 | int irq; |
| 104 | struct drm_crtc *crtc; |
| 105 | struct clk *bus_clk; |
| 106 | struct clk *lcd_clk; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 107 | void __iomem *regs; |
| 108 | struct fimd_win_data win_data[WINDOWS_NR]; |
| 109 | unsigned int clkdiv; |
| 110 | unsigned int default_win; |
| 111 | unsigned long irq_flags; |
| 112 | u32 vidcon0; |
| 113 | u32 vidcon1; |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 114 | bool suspended; |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 115 | struct mutex lock; |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 116 | wait_queue_head_t wait_vsync_queue; |
| 117 | atomic_t wait_vsync_event; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 118 | |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 119 | struct exynos_drm_panel_info *panel; |
Tomasz Figa | 1887346 | 2013-05-01 21:02:26 +0200 | [diff] [blame] | 120 | struct fimd_driver_data *driver_data; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 121 | }; |
| 122 | |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 123 | #ifdef CONFIG_OF |
| 124 | static const struct of_device_id fimd_driver_dt_match[] = { |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 125 | { .compatible = "samsung,s3c6400-fimd", |
| 126 | .data = &s3c64xx_fimd_driver_data }, |
Vikas Sajjan | 5830daf | 2013-02-27 16:02:58 +0530 | [diff] [blame] | 127 | { .compatible = "samsung,exynos4210-fimd", |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 128 | .data = &exynos4_fimd_driver_data }, |
Vikas Sajjan | 5830daf | 2013-02-27 16:02:58 +0530 | [diff] [blame] | 129 | { .compatible = "samsung,exynos5250-fimd", |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 130 | .data = &exynos5_fimd_driver_data }, |
| 131 | {}, |
| 132 | }; |
| 133 | MODULE_DEVICE_TABLE(of, fimd_driver_dt_match); |
| 134 | #endif |
| 135 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 136 | static inline struct fimd_driver_data *drm_fimd_get_driver_data( |
| 137 | struct platform_device *pdev) |
| 138 | { |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 139 | #ifdef CONFIG_OF |
| 140 | const struct of_device_id *of_id = |
| 141 | of_match_device(fimd_driver_dt_match, &pdev->dev); |
| 142 | |
| 143 | if (of_id) |
| 144 | return (struct fimd_driver_data *)of_id->data; |
| 145 | #endif |
| 146 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 147 | return (struct fimd_driver_data *) |
| 148 | platform_get_device_id(pdev)->driver_data; |
| 149 | } |
| 150 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 151 | static bool fimd_display_is_connected(struct device *dev) |
| 152 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 153 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 154 | |
| 155 | /* TODO. */ |
| 156 | |
| 157 | return true; |
| 158 | } |
| 159 | |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 160 | static void *fimd_get_panel(struct device *dev) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 161 | { |
| 162 | struct fimd_context *ctx = get_fimd_context(dev); |
| 163 | |
| 164 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 165 | |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 166 | return ctx->panel; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 167 | } |
| 168 | |
Rahul Sharma | 16844fb | 2013-06-10 14:50:00 +0530 | [diff] [blame^] | 169 | static int fimd_check_mode(struct device *dev, struct drm_display_mode *mode) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 170 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 171 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 172 | |
| 173 | /* TODO. */ |
| 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static int fimd_display_power_on(struct device *dev, int mode) |
| 179 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 180 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 181 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 182 | /* TODO */ |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
Inki Dae | 74ccc53 | 2011-10-19 17:23:07 +0900 | [diff] [blame] | 187 | static struct exynos_drm_display_ops fimd_display_ops = { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 188 | .type = EXYNOS_DISPLAY_TYPE_LCD, |
| 189 | .is_connected = fimd_display_is_connected, |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 190 | .get_panel = fimd_get_panel, |
Rahul Sharma | 16844fb | 2013-06-10 14:50:00 +0530 | [diff] [blame^] | 191 | .check_mode = fimd_check_mode, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 192 | .power_on = fimd_display_power_on, |
| 193 | }; |
| 194 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 195 | static void fimd_dpms(struct device *subdrv_dev, int mode) |
| 196 | { |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 197 | struct fimd_context *ctx = get_fimd_context(subdrv_dev); |
| 198 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 199 | DRM_DEBUG_KMS("%s, %d\n", __FILE__, mode); |
| 200 | |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 201 | mutex_lock(&ctx->lock); |
| 202 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 203 | switch (mode) { |
| 204 | case DRM_MODE_DPMS_ON: |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 205 | /* |
| 206 | * enable fimd hardware only if suspended status. |
| 207 | * |
| 208 | * P.S. fimd_dpms function would be called at booting time so |
| 209 | * clk_enable could be called double time. |
| 210 | */ |
| 211 | if (ctx->suspended) |
| 212 | pm_runtime_get_sync(subdrv_dev); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 213 | break; |
| 214 | case DRM_MODE_DPMS_STANDBY: |
| 215 | case DRM_MODE_DPMS_SUSPEND: |
| 216 | case DRM_MODE_DPMS_OFF: |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 217 | if (!ctx->suspended) |
| 218 | pm_runtime_put_sync(subdrv_dev); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 219 | break; |
| 220 | default: |
| 221 | DRM_DEBUG_KMS("unspecified mode %d\n", mode); |
| 222 | break; |
| 223 | } |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 224 | |
| 225 | mutex_unlock(&ctx->lock); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | static void fimd_apply(struct device *subdrv_dev) |
| 229 | { |
| 230 | struct fimd_context *ctx = get_fimd_context(subdrv_dev); |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 231 | struct exynos_drm_manager *mgr = ctx->subdrv.manager; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 232 | struct exynos_drm_manager_ops *mgr_ops = mgr->ops; |
| 233 | struct exynos_drm_overlay_ops *ovl_ops = mgr->overlay_ops; |
| 234 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 235 | int i; |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 236 | |
| 237 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 238 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 239 | for (i = 0; i < WINDOWS_NR; i++) { |
| 240 | win_data = &ctx->win_data[i]; |
| 241 | if (win_data->enabled && (ovl_ops && ovl_ops->commit)) |
| 242 | ovl_ops->commit(subdrv_dev, i); |
| 243 | } |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 244 | |
| 245 | if (mgr_ops && mgr_ops->commit) |
| 246 | mgr_ops->commit(subdrv_dev); |
| 247 | } |
| 248 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 249 | static void fimd_commit(struct device *dev) |
| 250 | { |
| 251 | struct fimd_context *ctx = get_fimd_context(dev); |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 252 | struct exynos_drm_panel_info *panel = ctx->panel; |
| 253 | struct fb_videomode *timing = &panel->timing; |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 254 | struct fimd_driver_data *driver_data; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 255 | u32 val; |
| 256 | |
Tomasz Figa | 1887346 | 2013-05-01 21:02:26 +0200 | [diff] [blame] | 257 | driver_data = ctx->driver_data; |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 258 | if (ctx->suspended) |
| 259 | return; |
| 260 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 261 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 262 | |
| 263 | /* setup polarity values from machine code. */ |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 264 | writel(ctx->vidcon1, ctx->regs + driver_data->timing_base + VIDCON1); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 265 | |
| 266 | /* setup vertical timing values. */ |
| 267 | val = VIDTCON0_VBPD(timing->upper_margin - 1) | |
| 268 | VIDTCON0_VFPD(timing->lower_margin - 1) | |
| 269 | VIDTCON0_VSPW(timing->vsync_len - 1); |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 270 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 271 | |
| 272 | /* setup horizontal timing values. */ |
| 273 | val = VIDTCON1_HBPD(timing->left_margin - 1) | |
| 274 | VIDTCON1_HFPD(timing->right_margin - 1) | |
| 275 | VIDTCON1_HSPW(timing->hsync_len - 1); |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 276 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON1); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 277 | |
| 278 | /* setup horizontal and vertical display size. */ |
| 279 | val = VIDTCON2_LINEVAL(timing->yres - 1) | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 280 | VIDTCON2_HOZVAL(timing->xres - 1) | |
| 281 | VIDTCON2_LINEVAL_E(timing->yres - 1) | |
| 282 | VIDTCON2_HOZVAL_E(timing->xres - 1); |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 283 | writel(val, ctx->regs + driver_data->timing_base + VIDTCON2); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 284 | |
| 285 | /* setup clock source, clock divider, enable dma. */ |
| 286 | val = ctx->vidcon0; |
| 287 | val &= ~(VIDCON0_CLKVAL_F_MASK | VIDCON0_CLKDIR); |
| 288 | |
Tomasz Figa | 411d9ed | 2013-05-01 21:02:28 +0200 | [diff] [blame] | 289 | if (ctx->driver_data->has_clksel) { |
| 290 | val &= ~VIDCON0_CLKSEL_MASK; |
| 291 | val |= VIDCON0_CLKSEL_LCD; |
| 292 | } |
| 293 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 294 | if (ctx->clkdiv > 1) |
| 295 | val |= VIDCON0_CLKVAL_F(ctx->clkdiv - 1) | VIDCON0_CLKDIR; |
| 296 | else |
| 297 | val &= ~VIDCON0_CLKDIR; /* 1:1 clock */ |
| 298 | |
| 299 | /* |
| 300 | * fields of register with prefix '_F' would be updated |
| 301 | * at vsync(same as dma start) |
| 302 | */ |
| 303 | val |= VIDCON0_ENVID | VIDCON0_ENVID_F; |
| 304 | writel(val, ctx->regs + VIDCON0); |
| 305 | } |
| 306 | |
| 307 | static int fimd_enable_vblank(struct device *dev) |
| 308 | { |
| 309 | struct fimd_context *ctx = get_fimd_context(dev); |
| 310 | u32 val; |
| 311 | |
| 312 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 313 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 314 | if (ctx->suspended) |
| 315 | return -EPERM; |
| 316 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 317 | if (!test_and_set_bit(0, &ctx->irq_flags)) { |
| 318 | val = readl(ctx->regs + VIDINTCON0); |
| 319 | |
| 320 | val |= VIDINTCON0_INT_ENABLE; |
| 321 | val |= VIDINTCON0_INT_FRAME; |
| 322 | |
| 323 | val &= ~VIDINTCON0_FRAMESEL0_MASK; |
| 324 | val |= VIDINTCON0_FRAMESEL0_VSYNC; |
| 325 | val &= ~VIDINTCON0_FRAMESEL1_MASK; |
| 326 | val |= VIDINTCON0_FRAMESEL1_NONE; |
| 327 | |
| 328 | writel(val, ctx->regs + VIDINTCON0); |
| 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static void fimd_disable_vblank(struct device *dev) |
| 335 | { |
| 336 | struct fimd_context *ctx = get_fimd_context(dev); |
| 337 | u32 val; |
| 338 | |
| 339 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 340 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 341 | if (ctx->suspended) |
| 342 | return; |
| 343 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 344 | if (test_and_clear_bit(0, &ctx->irq_flags)) { |
| 345 | val = readl(ctx->regs + VIDINTCON0); |
| 346 | |
| 347 | val &= ~VIDINTCON0_INT_FRAME; |
| 348 | val &= ~VIDINTCON0_INT_ENABLE; |
| 349 | |
| 350 | writel(val, ctx->regs + VIDINTCON0); |
| 351 | } |
| 352 | } |
| 353 | |
Prathyush K | 0703397 | 2012-12-06 20:16:02 +0530 | [diff] [blame] | 354 | static void fimd_wait_for_vblank(struct device *dev) |
| 355 | { |
| 356 | struct fimd_context *ctx = get_fimd_context(dev); |
Prathyush K | 0703397 | 2012-12-06 20:16:02 +0530 | [diff] [blame] | 357 | |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 358 | if (ctx->suspended) |
| 359 | return; |
| 360 | |
| 361 | atomic_set(&ctx->wait_vsync_event, 1); |
| 362 | |
| 363 | /* |
| 364 | * wait for FIMD to signal VSYNC interrupt or return after |
| 365 | * timeout which is set to 50ms (refresh rate of 20). |
| 366 | */ |
| 367 | if (!wait_event_timeout(ctx->wait_vsync_queue, |
| 368 | !atomic_read(&ctx->wait_vsync_event), |
| 369 | DRM_HZ/20)) |
Prathyush K | 0703397 | 2012-12-06 20:16:02 +0530 | [diff] [blame] | 370 | DRM_DEBUG_KMS("vblank wait timed out.\n"); |
| 371 | } |
| 372 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 373 | static struct exynos_drm_manager_ops fimd_manager_ops = { |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 374 | .dpms = fimd_dpms, |
| 375 | .apply = fimd_apply, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 376 | .commit = fimd_commit, |
| 377 | .enable_vblank = fimd_enable_vblank, |
| 378 | .disable_vblank = fimd_disable_vblank, |
Prathyush K | 0703397 | 2012-12-06 20:16:02 +0530 | [diff] [blame] | 379 | .wait_for_vblank = fimd_wait_for_vblank, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 380 | }; |
| 381 | |
| 382 | static void fimd_win_mode_set(struct device *dev, |
| 383 | struct exynos_drm_overlay *overlay) |
| 384 | { |
| 385 | struct fimd_context *ctx = get_fimd_context(dev); |
| 386 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 387 | int win; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 388 | unsigned long offset; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 389 | |
| 390 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 391 | |
| 392 | if (!overlay) { |
| 393 | dev_err(dev, "overlay is NULL\n"); |
| 394 | return; |
| 395 | } |
| 396 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 397 | win = overlay->zpos; |
| 398 | if (win == DEFAULT_ZPOS) |
| 399 | win = ctx->default_win; |
| 400 | |
Krzysztof Kozlowski | 37b006e | 2013-05-27 11:56:26 +0200 | [diff] [blame] | 401 | if (win < 0 || win >= WINDOWS_NR) |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 402 | return; |
| 403 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 404 | offset = overlay->fb_x * (overlay->bpp >> 3); |
| 405 | offset += overlay->fb_y * overlay->pitch; |
| 406 | |
| 407 | DRM_DEBUG_KMS("offset = 0x%lx, pitch = %x\n", offset, overlay->pitch); |
| 408 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 409 | win_data = &ctx->win_data[win]; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 410 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 411 | win_data->offset_x = overlay->crtc_x; |
| 412 | win_data->offset_y = overlay->crtc_y; |
| 413 | win_data->ovl_width = overlay->crtc_width; |
| 414 | win_data->ovl_height = overlay->crtc_height; |
| 415 | win_data->fb_width = overlay->fb_width; |
| 416 | win_data->fb_height = overlay->fb_height; |
Seung-Woo Kim | 229d353 | 2011-12-15 14:36:22 +0900 | [diff] [blame] | 417 | win_data->dma_addr = overlay->dma_addr[0] + offset; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 418 | win_data->bpp = overlay->bpp; |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 419 | win_data->buf_offsize = (overlay->fb_width - overlay->crtc_width) * |
| 420 | (overlay->bpp >> 3); |
| 421 | win_data->line_size = overlay->crtc_width * (overlay->bpp >> 3); |
| 422 | |
| 423 | DRM_DEBUG_KMS("offset_x = %d, offset_y = %d\n", |
| 424 | win_data->offset_x, win_data->offset_y); |
| 425 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
| 426 | win_data->ovl_width, win_data->ovl_height); |
YoungJun Cho | ddd8e95 | 2012-12-10 15:44:58 +0900 | [diff] [blame] | 427 | DRM_DEBUG_KMS("paddr = 0x%lx\n", (unsigned long)win_data->dma_addr); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 428 | DRM_DEBUG_KMS("fb_width = %d, crtc_width = %d\n", |
| 429 | overlay->fb_width, overlay->crtc_width); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | static void fimd_win_set_pixfmt(struct device *dev, unsigned int win) |
| 433 | { |
| 434 | struct fimd_context *ctx = get_fimd_context(dev); |
| 435 | struct fimd_win_data *win_data = &ctx->win_data[win]; |
| 436 | unsigned long val; |
| 437 | |
| 438 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 439 | |
| 440 | val = WINCONx_ENWIN; |
| 441 | |
| 442 | switch (win_data->bpp) { |
| 443 | case 1: |
| 444 | val |= WINCON0_BPPMODE_1BPP; |
| 445 | val |= WINCONx_BITSWP; |
| 446 | val |= WINCONx_BURSTLEN_4WORD; |
| 447 | break; |
| 448 | case 2: |
| 449 | val |= WINCON0_BPPMODE_2BPP; |
| 450 | val |= WINCONx_BITSWP; |
| 451 | val |= WINCONx_BURSTLEN_8WORD; |
| 452 | break; |
| 453 | case 4: |
| 454 | val |= WINCON0_BPPMODE_4BPP; |
| 455 | val |= WINCONx_BITSWP; |
| 456 | val |= WINCONx_BURSTLEN_8WORD; |
| 457 | break; |
| 458 | case 8: |
| 459 | val |= WINCON0_BPPMODE_8BPP_PALETTE; |
| 460 | val |= WINCONx_BURSTLEN_8WORD; |
| 461 | val |= WINCONx_BYTSWP; |
| 462 | break; |
| 463 | case 16: |
| 464 | val |= WINCON0_BPPMODE_16BPP_565; |
| 465 | val |= WINCONx_HAWSWP; |
| 466 | val |= WINCONx_BURSTLEN_16WORD; |
| 467 | break; |
| 468 | case 24: |
| 469 | val |= WINCON0_BPPMODE_24BPP_888; |
| 470 | val |= WINCONx_WSWP; |
| 471 | val |= WINCONx_BURSTLEN_16WORD; |
| 472 | break; |
| 473 | case 32: |
| 474 | val |= WINCON1_BPPMODE_28BPP_A4888 |
| 475 | | WINCON1_BLD_PIX | WINCON1_ALPHA_SEL; |
| 476 | val |= WINCONx_WSWP; |
| 477 | val |= WINCONx_BURSTLEN_16WORD; |
| 478 | break; |
| 479 | default: |
| 480 | DRM_DEBUG_KMS("invalid pixel size so using unpacked 24bpp.\n"); |
| 481 | |
| 482 | val |= WINCON0_BPPMODE_24BPP_888; |
| 483 | val |= WINCONx_WSWP; |
| 484 | val |= WINCONx_BURSTLEN_16WORD; |
| 485 | break; |
| 486 | } |
| 487 | |
| 488 | DRM_DEBUG_KMS("bpp = %d\n", win_data->bpp); |
| 489 | |
| 490 | writel(val, ctx->regs + WINCON(win)); |
| 491 | } |
| 492 | |
| 493 | static void fimd_win_set_colkey(struct device *dev, unsigned int win) |
| 494 | { |
| 495 | struct fimd_context *ctx = get_fimd_context(dev); |
| 496 | unsigned int keycon0 = 0, keycon1 = 0; |
| 497 | |
| 498 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 499 | |
| 500 | keycon0 = ~(WxKEYCON0_KEYBL_EN | WxKEYCON0_KEYEN_F | |
| 501 | WxKEYCON0_DIRCON) | WxKEYCON0_COMPKEY(0); |
| 502 | |
| 503 | keycon1 = WxKEYCON1_COLVAL(0xffffffff); |
| 504 | |
| 505 | writel(keycon0, ctx->regs + WKEYCON0_BASE(win)); |
| 506 | writel(keycon1, ctx->regs + WKEYCON1_BASE(win)); |
| 507 | } |
| 508 | |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 509 | /** |
| 510 | * shadow_protect_win() - disable updating values from shadow registers at vsync |
| 511 | * |
| 512 | * @win: window to protect registers for |
| 513 | * @protect: 1 to protect (disable updates) |
| 514 | */ |
| 515 | static void fimd_shadow_protect_win(struct fimd_context *ctx, |
| 516 | int win, bool protect) |
| 517 | { |
| 518 | u32 reg, bits, val; |
| 519 | |
| 520 | if (ctx->driver_data->has_shadowcon) { |
| 521 | reg = SHADOWCON; |
| 522 | bits = SHADOWCON_WINx_PROTECT(win); |
| 523 | } else { |
| 524 | reg = PRTCON; |
| 525 | bits = PRTCON_PROTECT; |
| 526 | } |
| 527 | |
| 528 | val = readl(ctx->regs + reg); |
| 529 | if (protect) |
| 530 | val |= bits; |
| 531 | else |
| 532 | val &= ~bits; |
| 533 | writel(val, ctx->regs + reg); |
| 534 | } |
| 535 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 536 | static void fimd_win_commit(struct device *dev, int zpos) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 537 | { |
| 538 | struct fimd_context *ctx = get_fimd_context(dev); |
| 539 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 540 | int win = zpos; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 541 | unsigned long val, alpha, size; |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 542 | unsigned int last_x; |
| 543 | unsigned int last_y; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 544 | |
| 545 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 546 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 547 | if (ctx->suspended) |
| 548 | return; |
| 549 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 550 | if (win == DEFAULT_ZPOS) |
| 551 | win = ctx->default_win; |
| 552 | |
Krzysztof Kozlowski | 37b006e | 2013-05-27 11:56:26 +0200 | [diff] [blame] | 553 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 554 | return; |
| 555 | |
| 556 | win_data = &ctx->win_data[win]; |
| 557 | |
| 558 | /* |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 559 | * SHADOWCON/PRTCON register is used for enabling timing. |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 560 | * |
| 561 | * for example, once only width value of a register is set, |
| 562 | * if the dma is started then fimd hardware could malfunction so |
| 563 | * with protect window setting, the register fields with prefix '_F' |
| 564 | * wouldn't be updated at vsync also but updated once unprotect window |
| 565 | * is set. |
| 566 | */ |
| 567 | |
| 568 | /* protect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 569 | fimd_shadow_protect_win(ctx, win, true); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 570 | |
| 571 | /* buffer start address */ |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 572 | val = (unsigned long)win_data->dma_addr; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 573 | writel(val, ctx->regs + VIDWx_BUF_START(win, 0)); |
| 574 | |
| 575 | /* buffer end address */ |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 576 | size = win_data->fb_width * win_data->ovl_height * (win_data->bpp >> 3); |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 577 | val = (unsigned long)(win_data->dma_addr + size); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 578 | writel(val, ctx->regs + VIDWx_BUF_END(win, 0)); |
| 579 | |
| 580 | DRM_DEBUG_KMS("start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n", |
Inki Dae | 2c87112 | 2011-11-12 15:23:32 +0900 | [diff] [blame] | 581 | (unsigned long)win_data->dma_addr, val, size); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 582 | DRM_DEBUG_KMS("ovl_width = %d, ovl_height = %d\n", |
| 583 | win_data->ovl_width, win_data->ovl_height); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 584 | |
| 585 | /* buffer size */ |
| 586 | val = VIDW_BUF_SIZE_OFFSET(win_data->buf_offsize) | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 587 | VIDW_BUF_SIZE_PAGEWIDTH(win_data->line_size) | |
| 588 | VIDW_BUF_SIZE_OFFSET_E(win_data->buf_offsize) | |
| 589 | VIDW_BUF_SIZE_PAGEWIDTH_E(win_data->line_size); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 590 | writel(val, ctx->regs + VIDWx_BUF_SIZE(win, 0)); |
| 591 | |
| 592 | /* OSD position */ |
| 593 | val = VIDOSDxA_TOPLEFT_X(win_data->offset_x) | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 594 | VIDOSDxA_TOPLEFT_Y(win_data->offset_y) | |
| 595 | VIDOSDxA_TOPLEFT_X_E(win_data->offset_x) | |
| 596 | VIDOSDxA_TOPLEFT_Y_E(win_data->offset_y); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 597 | writel(val, ctx->regs + VIDOSD_A(win)); |
| 598 | |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 599 | last_x = win_data->offset_x + win_data->ovl_width; |
| 600 | if (last_x) |
| 601 | last_x--; |
| 602 | last_y = win_data->offset_y + win_data->ovl_height; |
| 603 | if (last_y) |
| 604 | last_y--; |
| 605 | |
Joonyoung Shim | ca555e5 | 2012-12-14 15:48:24 +0900 | [diff] [blame] | 606 | val = VIDOSDxB_BOTRIGHT_X(last_x) | VIDOSDxB_BOTRIGHT_Y(last_y) | |
| 607 | VIDOSDxB_BOTRIGHT_X_E(last_x) | VIDOSDxB_BOTRIGHT_Y_E(last_y); |
| 608 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 609 | writel(val, ctx->regs + VIDOSD_B(win)); |
| 610 | |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 611 | DRM_DEBUG_KMS("osd pos: tx = %d, ty = %d, bx = %d, by = %d\n", |
Joonyoung Shim | f56aad3 | 2012-12-14 15:48:23 +0900 | [diff] [blame] | 612 | win_data->offset_x, win_data->offset_y, last_x, last_y); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 613 | |
| 614 | /* hardware window 0 doesn't support alpha channel. */ |
| 615 | if (win != 0) { |
| 616 | /* OSD alpha */ |
| 617 | alpha = VIDISD14C_ALPHA1_R(0xf) | |
| 618 | VIDISD14C_ALPHA1_G(0xf) | |
| 619 | VIDISD14C_ALPHA1_B(0xf); |
| 620 | |
| 621 | writel(alpha, ctx->regs + VIDOSD_C(win)); |
| 622 | } |
| 623 | |
| 624 | /* OSD size */ |
| 625 | if (win != 3 && win != 4) { |
| 626 | u32 offset = VIDOSD_D(win); |
| 627 | if (win == 0) |
Leela Krishna Amudala | 0f10cf1 | 2013-03-07 23:28:52 -0500 | [diff] [blame] | 628 | offset = VIDOSD_C(win); |
Inki Dae | 19c8b83 | 2011-10-14 13:29:46 +0900 | [diff] [blame] | 629 | val = win_data->ovl_width * win_data->ovl_height; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 630 | writel(val, ctx->regs + offset); |
| 631 | |
| 632 | DRM_DEBUG_KMS("osd size = 0x%x\n", (unsigned int)val); |
| 633 | } |
| 634 | |
| 635 | fimd_win_set_pixfmt(dev, win); |
| 636 | |
| 637 | /* hardware window 0 doesn't support color key. */ |
| 638 | if (win != 0) |
| 639 | fimd_win_set_colkey(dev, win); |
| 640 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 641 | /* wincon */ |
| 642 | val = readl(ctx->regs + WINCON(win)); |
| 643 | val |= WINCONx_ENWIN; |
| 644 | writel(val, ctx->regs + WINCON(win)); |
| 645 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 646 | /* Enable DMA channel and unprotect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 647 | fimd_shadow_protect_win(ctx, win, false); |
| 648 | |
| 649 | if (ctx->driver_data->has_shadowcon) { |
| 650 | val = readl(ctx->regs + SHADOWCON); |
| 651 | val |= SHADOWCON_CHx_ENABLE(win); |
| 652 | writel(val, ctx->regs + SHADOWCON); |
| 653 | } |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 654 | |
| 655 | win_data->enabled = true; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 656 | } |
| 657 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 658 | static void fimd_win_disable(struct device *dev, int zpos) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 659 | { |
| 660 | struct fimd_context *ctx = get_fimd_context(dev); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 661 | struct fimd_win_data *win_data; |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 662 | int win = zpos; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 663 | u32 val; |
| 664 | |
| 665 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 666 | |
Joonyoung Shim | 864ee9e | 2011-12-08 17:54:07 +0900 | [diff] [blame] | 667 | if (win == DEFAULT_ZPOS) |
| 668 | win = ctx->default_win; |
| 669 | |
Krzysztof Kozlowski | 37b006e | 2013-05-27 11:56:26 +0200 | [diff] [blame] | 670 | if (win < 0 || win >= WINDOWS_NR) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 671 | return; |
| 672 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 673 | win_data = &ctx->win_data[win]; |
| 674 | |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 675 | if (ctx->suspended) { |
| 676 | /* do not resume this window*/ |
| 677 | win_data->resume = false; |
| 678 | return; |
| 679 | } |
| 680 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 681 | /* protect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 682 | fimd_shadow_protect_win(ctx, win, true); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 683 | |
| 684 | /* wincon */ |
| 685 | val = readl(ctx->regs + WINCON(win)); |
| 686 | val &= ~WINCONx_ENWIN; |
| 687 | writel(val, ctx->regs + WINCON(win)); |
| 688 | |
| 689 | /* unprotect windows */ |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 690 | if (ctx->driver_data->has_shadowcon) { |
| 691 | val = readl(ctx->regs + SHADOWCON); |
| 692 | val &= ~SHADOWCON_CHx_ENABLE(win); |
| 693 | writel(val, ctx->regs + SHADOWCON); |
| 694 | } |
| 695 | |
| 696 | fimd_shadow_protect_win(ctx, win, false); |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 697 | |
| 698 | win_data->enabled = false; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | static struct exynos_drm_overlay_ops fimd_overlay_ops = { |
| 702 | .mode_set = fimd_win_mode_set, |
| 703 | .commit = fimd_win_commit, |
| 704 | .disable = fimd_win_disable, |
| 705 | }; |
| 706 | |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 707 | static struct exynos_drm_manager fimd_manager = { |
| 708 | .pipe = -1, |
| 709 | .ops = &fimd_manager_ops, |
| 710 | .overlay_ops = &fimd_overlay_ops, |
| 711 | .display_ops = &fimd_display_ops, |
| 712 | }; |
| 713 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 714 | static irqreturn_t fimd_irq_handler(int irq, void *dev_id) |
| 715 | { |
| 716 | struct fimd_context *ctx = (struct fimd_context *)dev_id; |
| 717 | struct exynos_drm_subdrv *subdrv = &ctx->subdrv; |
| 718 | struct drm_device *drm_dev = subdrv->drm_dev; |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 719 | struct exynos_drm_manager *manager = subdrv->manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 720 | u32 val; |
| 721 | |
| 722 | val = readl(ctx->regs + VIDINTCON1); |
| 723 | |
| 724 | if (val & VIDINTCON1_INT_FRAME) |
| 725 | /* VSYNC interrupt */ |
| 726 | writel(VIDINTCON1_INT_FRAME, ctx->regs + VIDINTCON1); |
| 727 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 728 | /* check the crtc is detached already from encoder */ |
| 729 | if (manager->pipe < 0) |
| 730 | goto out; |
Inki Dae | 483b88f | 2011-11-11 21:28:00 +0900 | [diff] [blame] | 731 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 732 | drm_handle_vblank(drm_dev, manager->pipe); |
Rahul Sharma | 663d876 | 2013-01-03 05:44:04 -0500 | [diff] [blame] | 733 | exynos_drm_crtc_finish_pageflip(drm_dev, manager->pipe); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 734 | |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 735 | /* set wait vsync event to zero and wake up queue. */ |
| 736 | if (atomic_read(&ctx->wait_vsync_event)) { |
| 737 | atomic_set(&ctx->wait_vsync_event, 0); |
| 738 | DRM_WAKEUP(&ctx->wait_vsync_queue); |
| 739 | } |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 740 | out: |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 741 | return IRQ_HANDLED; |
| 742 | } |
| 743 | |
Inki Dae | 41c2434 | 2011-10-14 13:29:48 +0900 | [diff] [blame] | 744 | static int fimd_subdrv_probe(struct drm_device *drm_dev, struct device *dev) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 745 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 746 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 747 | |
| 748 | /* |
| 749 | * enable drm irq mode. |
| 750 | * - with irq_enabled = 1, we can use the vblank feature. |
| 751 | * |
| 752 | * P.S. note that we wouldn't use drm irq handler but |
| 753 | * just specific driver own one instead because |
| 754 | * drm framework supports only one irq handler. |
| 755 | */ |
| 756 | drm_dev->irq_enabled = 1; |
| 757 | |
Inki Dae | ec05da9 | 2011-12-06 11:06:54 +0900 | [diff] [blame] | 758 | /* |
| 759 | * with vblank_disable_allowed = 1, vblank interrupt will be disabled |
| 760 | * by drm timer once a current process gives up ownership of |
| 761 | * vblank event.(after drm_vblank_put function is called) |
| 762 | */ |
| 763 | drm_dev->vblank_disable_allowed = 1; |
| 764 | |
Inki Dae | bcc5cd1c | 2012-10-19 17:16:36 +0900 | [diff] [blame] | 765 | /* attach this sub driver to iommu mapping if supported. */ |
| 766 | if (is_drm_iommu_supported(drm_dev)) |
| 767 | drm_iommu_attach_device(drm_dev, dev); |
| 768 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 769 | return 0; |
| 770 | } |
| 771 | |
Inki Dae | 29cb602 | 2012-09-05 14:12:06 +0900 | [diff] [blame] | 772 | static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 773 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 774 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 775 | |
Inki Dae | bcc5cd1c | 2012-10-19 17:16:36 +0900 | [diff] [blame] | 776 | /* detach this sub driver from iommu mapping if supported. */ |
| 777 | if (is_drm_iommu_supported(drm_dev)) |
| 778 | drm_iommu_detach_device(drm_dev, dev); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static int fimd_calc_clkdiv(struct fimd_context *ctx, |
| 782 | struct fb_videomode *timing) |
| 783 | { |
| 784 | unsigned long clk = clk_get_rate(ctx->lcd_clk); |
| 785 | u32 retrace; |
| 786 | u32 clkdiv; |
| 787 | u32 best_framerate = 0; |
| 788 | u32 framerate; |
| 789 | |
| 790 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 791 | |
| 792 | retrace = timing->left_margin + timing->hsync_len + |
| 793 | timing->right_margin + timing->xres; |
| 794 | retrace *= timing->upper_margin + timing->vsync_len + |
| 795 | timing->lower_margin + timing->yres; |
| 796 | |
| 797 | /* default framerate is 60Hz */ |
| 798 | if (!timing->refresh) |
| 799 | timing->refresh = 60; |
| 800 | |
| 801 | clk /= retrace; |
| 802 | |
| 803 | for (clkdiv = 1; clkdiv < 0x100; clkdiv++) { |
| 804 | int tmp; |
| 805 | |
| 806 | /* get best framerate */ |
| 807 | framerate = clk / clkdiv; |
| 808 | tmp = timing->refresh - framerate; |
| 809 | if (tmp < 0) { |
| 810 | best_framerate = framerate; |
| 811 | continue; |
| 812 | } else { |
| 813 | if (!best_framerate) |
| 814 | best_framerate = framerate; |
| 815 | else if (tmp < (best_framerate - framerate)) |
| 816 | best_framerate = framerate; |
| 817 | break; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | return clkdiv; |
| 822 | } |
| 823 | |
| 824 | static void fimd_clear_win(struct fimd_context *ctx, int win) |
| 825 | { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 826 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 827 | |
| 828 | writel(0, ctx->regs + WINCON(win)); |
| 829 | writel(0, ctx->regs + VIDOSD_A(win)); |
| 830 | writel(0, ctx->regs + VIDOSD_B(win)); |
| 831 | writel(0, ctx->regs + VIDOSD_C(win)); |
| 832 | |
| 833 | if (win == 1 || win == 2) |
| 834 | writel(0, ctx->regs + VIDOSD_D(win)); |
| 835 | |
Tomasz Figa | de7af10 | 2013-05-01 21:02:27 +0200 | [diff] [blame] | 836 | fimd_shadow_protect_win(ctx, win, false); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 837 | } |
| 838 | |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 839 | static int fimd_clock(struct fimd_context *ctx, bool enable) |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 840 | { |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 841 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 842 | |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 843 | if (enable) { |
| 844 | int ret; |
| 845 | |
Vikas Sajjan | 11963a6 | 2013-04-23 17:19:50 +0530 | [diff] [blame] | 846 | ret = clk_prepare_enable(ctx->bus_clk); |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 847 | if (ret < 0) |
| 848 | return ret; |
| 849 | |
Vikas Sajjan | 11963a6 | 2013-04-23 17:19:50 +0530 | [diff] [blame] | 850 | ret = clk_prepare_enable(ctx->lcd_clk); |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 851 | if (ret < 0) { |
Vikas Sajjan | 11963a6 | 2013-04-23 17:19:50 +0530 | [diff] [blame] | 852 | clk_disable_unprepare(ctx->bus_clk); |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 853 | return ret; |
| 854 | } |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 855 | } else { |
Vikas Sajjan | 11963a6 | 2013-04-23 17:19:50 +0530 | [diff] [blame] | 856 | clk_disable_unprepare(ctx->lcd_clk); |
| 857 | clk_disable_unprepare(ctx->bus_clk); |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | return 0; |
| 861 | } |
| 862 | |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 863 | static void fimd_window_suspend(struct device *dev) |
| 864 | { |
| 865 | struct fimd_context *ctx = get_fimd_context(dev); |
| 866 | struct fimd_win_data *win_data; |
| 867 | int i; |
| 868 | |
| 869 | for (i = 0; i < WINDOWS_NR; i++) { |
| 870 | win_data = &ctx->win_data[i]; |
| 871 | win_data->resume = win_data->enabled; |
| 872 | fimd_win_disable(dev, i); |
| 873 | } |
| 874 | fimd_wait_for_vblank(dev); |
| 875 | } |
| 876 | |
| 877 | static void fimd_window_resume(struct device *dev) |
| 878 | { |
| 879 | struct fimd_context *ctx = get_fimd_context(dev); |
| 880 | struct fimd_win_data *win_data; |
| 881 | int i; |
| 882 | |
| 883 | for (i = 0; i < WINDOWS_NR; i++) { |
| 884 | win_data = &ctx->win_data[i]; |
| 885 | win_data->enabled = win_data->resume; |
| 886 | win_data->resume = false; |
| 887 | } |
| 888 | } |
| 889 | |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 890 | static int fimd_activate(struct fimd_context *ctx, bool enable) |
| 891 | { |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 892 | struct device *dev = ctx->subdrv.dev; |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 893 | if (enable) { |
| 894 | int ret; |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 895 | |
| 896 | ret = fimd_clock(ctx, true); |
| 897 | if (ret < 0) |
| 898 | return ret; |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 899 | |
| 900 | ctx->suspended = false; |
| 901 | |
| 902 | /* if vblank was enabled status, enable it again. */ |
| 903 | if (test_and_clear_bit(0, &ctx->irq_flags)) |
| 904 | fimd_enable_vblank(dev); |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 905 | |
| 906 | fimd_window_resume(dev); |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 907 | } else { |
Prathyush K | db7e55a | 2012-12-06 20:16:06 +0530 | [diff] [blame] | 908 | fimd_window_suspend(dev); |
| 909 | |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 910 | fimd_clock(ctx, false); |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 911 | ctx->suspended = true; |
| 912 | } |
| 913 | |
| 914 | return 0; |
| 915 | } |
| 916 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 917 | static int fimd_probe(struct platform_device *pdev) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 918 | { |
| 919 | struct device *dev = &pdev->dev; |
| 920 | struct fimd_context *ctx; |
| 921 | struct exynos_drm_subdrv *subdrv; |
| 922 | struct exynos_drm_fimd_pdata *pdata; |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 923 | struct exynos_drm_panel_info *panel; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 924 | struct resource *res; |
| 925 | int win; |
| 926 | int ret = -EINVAL; |
| 927 | |
| 928 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 929 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 930 | if (dev->of_node) { |
Vikas Sajjan | 7f4596f | 2013-03-07 12:15:21 +0530 | [diff] [blame] | 931 | pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); |
| 932 | if (!pdata) { |
| 933 | DRM_ERROR("memory allocation for pdata failed\n"); |
| 934 | return -ENOMEM; |
| 935 | } |
| 936 | |
| 937 | ret = of_get_fb_videomode(dev->of_node, &pdata->panel.timing, |
| 938 | OF_USE_NATIVE_MODE); |
| 939 | if (ret) { |
| 940 | DRM_ERROR("failed: of_get_fb_videomode() : %d\n", ret); |
| 941 | return ret; |
| 942 | } |
| 943 | } else { |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 944 | pdata = dev->platform_data; |
Vikas Sajjan | 7f4596f | 2013-03-07 12:15:21 +0530 | [diff] [blame] | 945 | if (!pdata) { |
| 946 | DRM_ERROR("no platform data specified\n"); |
| 947 | return -EINVAL; |
| 948 | } |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 949 | } |
| 950 | |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 951 | panel = &pdata->panel; |
| 952 | if (!panel) { |
| 953 | dev_err(dev, "panel is null.\n"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 954 | return -EINVAL; |
| 955 | } |
| 956 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 957 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 958 | if (!ctx) |
| 959 | return -ENOMEM; |
| 960 | |
Sachin Kamat | a4d8de5 | 2012-11-26 09:47:14 +0530 | [diff] [blame] | 961 | ctx->bus_clk = devm_clk_get(dev, "fimd"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 962 | if (IS_ERR(ctx->bus_clk)) { |
| 963 | dev_err(dev, "failed to get bus clock\n"); |
Sachin Kamat | a4d8de5 | 2012-11-26 09:47:14 +0530 | [diff] [blame] | 964 | return PTR_ERR(ctx->bus_clk); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 965 | } |
| 966 | |
Sachin Kamat | a4d8de5 | 2012-11-26 09:47:14 +0530 | [diff] [blame] | 967 | ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 968 | if (IS_ERR(ctx->lcd_clk)) { |
| 969 | dev_err(dev, "failed to get lcd clock\n"); |
Sachin Kamat | a4d8de5 | 2012-11-26 09:47:14 +0530 | [diff] [blame] | 970 | return PTR_ERR(ctx->lcd_clk); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 971 | } |
| 972 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 973 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 974 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 975 | ctx->regs = devm_ioremap_resource(dev, res); |
Thierry Reding | d4ed602 | 2013-01-21 11:09:02 +0100 | [diff] [blame] | 976 | if (IS_ERR(ctx->regs)) |
| 977 | return PTR_ERR(ctx->regs); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 978 | |
Vikas Sajjan | 1977e6d | 2013-04-02 17:53:01 +0900 | [diff] [blame] | 979 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "vsync"); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 980 | if (!res) { |
| 981 | dev_err(dev, "irq request failed.\n"); |
Sachin Kamat | a4d8de5 | 2012-11-26 09:47:14 +0530 | [diff] [blame] | 982 | return -ENXIO; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | ctx->irq = res->start; |
| 986 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 987 | ret = devm_request_irq(dev, ctx->irq, fimd_irq_handler, |
Sachin Kamat | edc5726 | 2012-06-19 11:47:39 +0530 | [diff] [blame] | 988 | 0, "drm_fimd", ctx); |
| 989 | if (ret) { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 990 | dev_err(dev, "irq request failed.\n"); |
Sachin Kamat | a4d8de5 | 2012-11-26 09:47:14 +0530 | [diff] [blame] | 991 | return ret; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 992 | } |
| 993 | |
Tomasz Figa | 1887346 | 2013-05-01 21:02:26 +0200 | [diff] [blame] | 994 | ctx->driver_data = drm_fimd_get_driver_data(pdev); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 995 | ctx->vidcon0 = pdata->vidcon0; |
| 996 | ctx->vidcon1 = pdata->vidcon1; |
| 997 | ctx->default_win = pdata->default_win; |
Eun-Chul Kim | 607c50d | 2012-02-14 15:59:46 +0900 | [diff] [blame] | 998 | ctx->panel = panel; |
Prathyush K | 01ce113 | 2012-12-06 20:16:04 +0530 | [diff] [blame] | 999 | DRM_INIT_WAITQUEUE(&ctx->wait_vsync_queue); |
| 1000 | atomic_set(&ctx->wait_vsync_event, 0); |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1001 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1002 | subdrv = &ctx->subdrv; |
| 1003 | |
Joonyoung Shim | 677e84c | 2012-04-05 20:49:27 +0900 | [diff] [blame] | 1004 | subdrv->dev = dev; |
| 1005 | subdrv->manager = &fimd_manager; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1006 | subdrv->probe = fimd_subdrv_probe; |
| 1007 | subdrv->remove = fimd_subdrv_remove; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1008 | |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 1009 | mutex_init(&ctx->lock); |
| 1010 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1011 | platform_set_drvdata(pdev, ctx); |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 1012 | |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 1013 | pm_runtime_enable(dev); |
| 1014 | pm_runtime_get_sync(dev); |
| 1015 | |
Marek Szyprowski | 0d8ce3a | 2012-03-08 10:28:56 +0900 | [diff] [blame] | 1016 | ctx->clkdiv = fimd_calc_clkdiv(ctx, &panel->timing); |
| 1017 | panel->timing.pixclock = clk_get_rate(ctx->lcd_clk) / ctx->clkdiv; |
| 1018 | |
| 1019 | DRM_DEBUG_KMS("pixel clock = %d, clkdiv = %d\n", |
| 1020 | panel->timing.pixclock, ctx->clkdiv); |
| 1021 | |
Inki Dae | c32b06e | 2011-12-16 21:49:03 +0900 | [diff] [blame] | 1022 | for (win = 0; win < WINDOWS_NR; win++) |
| 1023 | fimd_clear_win(ctx, win); |
| 1024 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1025 | exynos_drm_subdrv_register(subdrv); |
| 1026 | |
| 1027 | return 0; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1028 | } |
| 1029 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1030 | static int fimd_remove(struct platform_device *pdev) |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1031 | { |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1032 | struct device *dev = &pdev->dev; |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1033 | struct fimd_context *ctx = platform_get_drvdata(pdev); |
| 1034 | |
| 1035 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 1036 | |
| 1037 | exynos_drm_subdrv_unregister(&ctx->subdrv); |
| 1038 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1039 | if (ctx->suspended) |
| 1040 | goto out; |
| 1041 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1042 | pm_runtime_set_suspended(dev); |
| 1043 | pm_runtime_put_sync(dev); |
| 1044 | |
| 1045 | out: |
| 1046 | pm_runtime_disable(dev); |
| 1047 | |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1048 | return 0; |
| 1049 | } |
| 1050 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1051 | #ifdef CONFIG_PM_SLEEP |
| 1052 | static int fimd_suspend(struct device *dev) |
| 1053 | { |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 1054 | struct fimd_context *ctx = get_fimd_context(dev); |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1055 | |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 1056 | /* |
| 1057 | * do not use pm_runtime_suspend(). if pm_runtime_suspend() is |
| 1058 | * called here, an error would be returned by that interface |
| 1059 | * because the usage_count of pm runtime is more than 1. |
| 1060 | */ |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 1061 | if (!pm_runtime_suspended(dev)) |
| 1062 | return fimd_activate(ctx, false); |
| 1063 | |
| 1064 | return 0; |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | static int fimd_resume(struct device *dev) |
| 1068 | { |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 1069 | struct fimd_context *ctx = get_fimd_context(dev); |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1070 | |
Inki Dae | 373af0c | 2012-01-27 11:54:58 +0900 | [diff] [blame] | 1071 | /* |
| 1072 | * if entered to sleep when lcd panel was on, the usage_count |
| 1073 | * of pm runtime would still be 1 so in this case, fimd driver |
| 1074 | * should be on directly not drawing on pm runtime interface. |
| 1075 | */ |
Prathyush K | 28998af | 2012-12-27 06:40:13 -0500 | [diff] [blame] | 1076 | if (!pm_runtime_suspended(dev)) { |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 1077 | int ret; |
| 1078 | |
| 1079 | ret = fimd_activate(ctx, true); |
| 1080 | if (ret < 0) |
| 1081 | return ret; |
| 1082 | |
| 1083 | /* |
| 1084 | * in case of dpms on(standby), fimd_apply function will |
| 1085 | * be called by encoder's dpms callback to update fimd's |
| 1086 | * registers but in case of sleep wakeup, it's not. |
| 1087 | * so fimd_apply function should be called at here. |
| 1088 | */ |
| 1089 | fimd_apply(dev); |
| 1090 | } |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1091 | |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1092 | return 0; |
| 1093 | } |
| 1094 | #endif |
| 1095 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1096 | #ifdef CONFIG_PM_RUNTIME |
| 1097 | static int fimd_runtime_suspend(struct device *dev) |
| 1098 | { |
| 1099 | struct fimd_context *ctx = get_fimd_context(dev); |
| 1100 | |
| 1101 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 1102 | |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 1103 | return fimd_activate(ctx, false); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | static int fimd_runtime_resume(struct device *dev) |
| 1107 | { |
| 1108 | struct fimd_context *ctx = get_fimd_context(dev); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1109 | |
| 1110 | DRM_DEBUG_KMS("%s\n", __FILE__); |
| 1111 | |
Inki Dae | 5d55393 | 2012-08-17 17:08:04 +0900 | [diff] [blame] | 1112 | return fimd_activate(ctx, true); |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1113 | } |
| 1114 | #endif |
| 1115 | |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 1116 | static struct platform_device_id fimd_driver_ids[] = { |
| 1117 | { |
Tomasz Figa | 725ddea | 2013-05-01 21:02:29 +0200 | [diff] [blame] | 1118 | .name = "s3c64xx-fb", |
| 1119 | .driver_data = (unsigned long)&s3c64xx_fimd_driver_data, |
| 1120 | }, { |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 1121 | .name = "exynos4-fb", |
| 1122 | .driver_data = (unsigned long)&exynos4_fimd_driver_data, |
| 1123 | }, { |
| 1124 | .name = "exynos5-fb", |
| 1125 | .driver_data = (unsigned long)&exynos5_fimd_driver_data, |
| 1126 | }, |
| 1127 | {}, |
| 1128 | }; |
| 1129 | MODULE_DEVICE_TABLE(platform, fimd_driver_ids); |
| 1130 | |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1131 | static const struct dev_pm_ops fimd_pm_ops = { |
Inki Dae | e30d4bc | 2011-12-12 16:35:20 +0900 | [diff] [blame] | 1132 | SET_SYSTEM_SLEEP_PM_OPS(fimd_suspend, fimd_resume) |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1133 | SET_RUNTIME_PM_OPS(fimd_runtime_suspend, fimd_runtime_resume, NULL) |
| 1134 | }; |
| 1135 | |
Joonyoung Shim | 132a5b9 | 2012-03-16 18:47:08 +0900 | [diff] [blame] | 1136 | struct platform_driver fimd_driver = { |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1137 | .probe = fimd_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1138 | .remove = fimd_remove, |
Leela Krishna Amudala | e2e1338 | 2012-09-21 16:52:15 +0530 | [diff] [blame] | 1139 | .id_table = fimd_driver_ids, |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1140 | .driver = { |
| 1141 | .name = "exynos4-fb", |
| 1142 | .owner = THIS_MODULE, |
Joonyoung Shim | cb91f6a | 2011-12-09 16:52:11 +0900 | [diff] [blame] | 1143 | .pm = &fimd_pm_ops, |
Joonyoung Shim | d636ead | 2012-12-14 15:48:25 +0900 | [diff] [blame] | 1144 | .of_match_table = of_match_ptr(fimd_driver_dt_match), |
Inki Dae | 1c248b7 | 2011-10-04 19:19:01 +0900 | [diff] [blame] | 1145 | }, |
| 1146 | }; |