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