16 #include <linux/kernel.h>
17 #include <linux/module.h>
23 #include <drm/exynos_drm.h>
37 #define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
38 #define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
40 #define VIDOSD_C_SIZE_W0 (VIDOSD_BASE + 0x08)
42 #define VIDOSD_C(win) (VIDOSD_BASE + 0x18 + (win) * 16)
44 #define VIDOSD_D(win) (VIDOSD_BASE + 0x0C + (win) * 16)
46 #define VIDWx_BUF_START(win, buf) (VIDW_BUF_START(buf) + (win) * 8)
47 #define VIDWx_BUF_END(win, buf) (VIDW_BUF_END(buf) + (win) * 8)
48 #define VIDWx_BUF_SIZE(win, buf) (VIDW_BUF_SIZE(buf) + (win) * 4)
51 #define WKEYCON0_BASE(x) ((WKEYCON0 + 0x140) + (x * 8))
53 #define WKEYCON1_BASE(x) ((WKEYCON1 + 0x140) + (x * 8))
58 #define get_fimd_context(dev) platform_get_drvdata(to_platform_device(dev))
69 .timing_base = 0x20000,
113 static bool fimd_display_is_connected(
struct device *
dev)
115 DRM_DEBUG_KMS(
"%s\n", __FILE__);
122 static void *fimd_get_panel(
struct device *
dev)
126 DRM_DEBUG_KMS(
"%s\n", __FILE__);
133 DRM_DEBUG_KMS(
"%s\n", __FILE__);
140 static int fimd_display_power_on(
struct device *
dev,
int mode)
142 DRM_DEBUG_KMS(
"%s\n", __FILE__);
151 .is_connected = fimd_display_is_connected,
152 .get_panel = fimd_get_panel,
153 .check_timing = fimd_check_timing,
154 .power_on = fimd_display_power_on,
157 static void fimd_dpms(
struct device *subdrv_dev,
int mode)
161 DRM_DEBUG_KMS(
"%s, %d\n", __FILE__, mode);
174 pm_runtime_get_sync(subdrv_dev);
180 pm_runtime_put_sync(subdrv_dev);
183 DRM_DEBUG_KMS(
"unspecified mode %d\n", mode);
190 static void fimd_apply(
struct device *subdrv_dev)
199 DRM_DEBUG_KMS(
"%s\n", __FILE__);
204 ovl_ops->
commit(subdrv_dev, i);
207 if (mgr_ops && mgr_ops->
commit)
208 mgr_ops->
commit(subdrv_dev);
211 static void fimd_commit(
struct device *
dev)
220 driver_data = drm_fimd_get_driver_data(pdev);
224 DRM_DEBUG_KMS(
"%s\n", __FILE__);
263 static int fimd_enable_vblank(
struct device *dev)
268 DRM_DEBUG_KMS(
"%s\n", __FILE__);
290 static void fimd_disable_vblank(
struct device *dev)
295 DRM_DEBUG_KMS(
"%s\n", __FILE__);
313 .commit = fimd_commit,
314 .enable_vblank = fimd_enable_vblank,
315 .disable_vblank = fimd_disable_vblank,
318 static void fimd_win_mode_set(
struct device *dev,
326 DRM_DEBUG_KMS(
"%s\n", __FILE__);
329 dev_err(dev,
"overlay is NULL\n");
337 if (win < 0 || win > WINDOWS_NR)
340 offset = overlay->
fb_x * (overlay->
bpp >> 3);
341 offset += overlay->
fb_y * overlay->
pitch;
343 DRM_DEBUG_KMS(
"offset = 0x%lx, pitch = %x\n", offset, overlay->
pitch);
355 win_data->
bpp = overlay->
bpp;
360 DRM_DEBUG_KMS(
"offset_x = %d, offset_y = %d\n",
362 DRM_DEBUG_KMS(
"ovl_width = %d, ovl_height = %d\n",
364 DRM_DEBUG_KMS(
"paddr = 0x%lx, vaddr = 0x%lx\n",
366 (
unsigned long)win_data->
vaddr);
367 DRM_DEBUG_KMS(
"fb_width = %d, crtc_width = %d\n",
371 static void fimd_win_set_pixfmt(
struct device *dev,
unsigned int win)
377 DRM_DEBUG_KMS(
"%s\n", __FILE__);
381 switch (win_data->
bpp) {
419 DRM_DEBUG_KMS(
"invalid pixel size so using unpacked 24bpp.\n");
427 DRM_DEBUG_KMS(
"bpp = %d\n", win_data->
bpp);
432 static void fimd_win_set_colkey(
struct device *dev,
unsigned int win)
435 unsigned int keycon0 = 0, keycon1 = 0;
437 DRM_DEBUG_KMS(
"%s\n", __FILE__);
448 static void fimd_win_commit(
struct device *dev,
int zpos)
455 DRM_DEBUG_KMS(
"%s\n", __FILE__);
463 if (win < 0 || win > WINDOWS_NR)
492 DRM_DEBUG_KMS(
"start addr = 0x%lx, end addr = 0x%lx, size = 0x%lx\n",
493 (
unsigned long)win_data->
dma_addr, val, size);
494 DRM_DEBUG_KMS(
"ovl_width = %d, ovl_height = %d\n",
513 DRM_DEBUG_KMS(
"osd pos: tx = %d, ty = %d, bx = %d, by = %d\n",
529 if (win != 3 && win != 4) {
536 DRM_DEBUG_KMS(
"osd size = 0x%x\n", (
unsigned int)val);
539 fimd_win_set_pixfmt(dev, win);
543 fimd_win_set_colkey(dev, win);
559 static void fimd_win_disable(
struct device *dev,
int zpos)
566 DRM_DEBUG_KMS(
"%s\n", __FILE__);
571 if (win < 0 || win > WINDOWS_NR)
595 static void fimd_wait_for_vblank(
struct device *dev)
603 DRM_DEBUG_KMS(
"vblank wait timed out.\n");
607 .mode_set = fimd_win_mode_set,
608 .commit = fimd_win_commit,
609 .disable = fimd_win_disable,
610 .wait_for_vblank = fimd_wait_for_vblank,
615 .ops = &fimd_manager_ops,
616 .overlay_ops = &fimd_overlay_ops,
617 .display_ops = &fimd_display_ops,
620 static void fimd_finish_pageflip(
struct drm_device *drm_dev,
int crtc)
623 struct drm_pending_vblank_event *
e, *
t;
626 bool is_checked =
false;
639 e->event.sequence = 0;
640 e->event.tv_sec = now.tv_sec;
641 e->event.tv_usec = now.tv_usec;
643 list_move_tail(&e->base.link, &e->base.file_priv->event_list);
652 if (
atomic_read(&drm_dev->vblank_refcount[crtc]) > 0)
659 if (!drm_dev->vblank_disable_allowed)
663 spin_unlock_irqrestore(&drm_dev->event_lock, flags);
681 if (manager->
pipe < 0)
685 fimd_finish_pageflip(drm_dev, manager->
pipe);
691 static int fimd_subdrv_probe(
struct drm_device *drm_dev,
struct device *dev)
693 DRM_DEBUG_KMS(
"%s\n", __FILE__);
703 drm_dev->irq_enabled = 1;
710 drm_dev->vblank_disable_allowed = 1;
715 static void fimd_subdrv_remove(
struct drm_device *drm_dev,
struct device *dev)
717 DRM_DEBUG_KMS(
"%s\n", __FILE__);
728 u32 best_framerate = 0;
731 DRM_DEBUG_KMS(
"%s\n", __FILE__);
744 for (clkdiv = 1; clkdiv < 0x100; clkdiv++) {
748 framerate = clk / clkdiv;
749 tmp = timing->
refresh - framerate;
751 best_framerate = framerate;
755 best_framerate = framerate;
756 else if (tmp < (best_framerate - framerate))
757 best_framerate = framerate;
765 static void fimd_clear_win(
struct fimd_context *ctx,
int win)
769 DRM_DEBUG_KMS(
"%s\n", __FILE__);
776 if (win == 1 || win == 2)
786 DRM_DEBUG_KMS(
"%s\n", __FILE__);
808 static int fimd_activate(
struct fimd_context *ctx,
bool enable)
814 ret = fimd_clock(ctx,
true);
822 fimd_enable_vblank(dev);
824 fimd_clock(ctx,
false);
842 DRM_DEBUG_KMS(
"%s\n", __FILE__);
844 pdata = pdev->
dev.platform_data;
846 dev_err(dev,
"no platform data specified\n");
850 panel = &pdata->
panel;
852 dev_err(dev,
"panel is null.\n");
862 dev_err(dev,
"failed to get bus clock\n");
869 dev_err(dev,
"failed to get lcd clock\n");
878 dev_err(dev,
"failed to map registers\n");
885 dev_err(dev,
"irq request failed.\n");
891 ret = devm_request_irq(&pdev->
dev, ctx->
irq, fimd_irq_handler,
894 dev_err(dev,
"irq request failed.\n");
906 subdrv->
manager = &fimd_manager;
907 subdrv->
probe = fimd_subdrv_probe;
908 subdrv->
remove = fimd_subdrv_remove;
912 platform_set_drvdata(pdev, ctx);
915 pm_runtime_get_sync(dev);
920 DRM_DEBUG_KMS(
"pixel clock = %d, clkdiv = %d\n",
924 fimd_clear_win(ctx, win);
947 DRM_DEBUG_KMS(
"%s\n", __FILE__);
957 pm_runtime_set_suspended(dev);
958 pm_runtime_put_sync(dev);
961 pm_runtime_disable(dev);
969 #ifdef CONFIG_PM_SLEEP
970 static int fimd_suspend(
struct device *dev)
979 if (!pm_runtime_suspended(dev))
980 return fimd_activate(ctx,
false);
985 static int fimd_resume(
struct device *dev)
994 if (pm_runtime_suspended(dev)) {
997 ret = fimd_activate(ctx,
true);
1014 #ifdef CONFIG_PM_RUNTIME
1015 static int fimd_runtime_suspend(
struct device *dev)
1019 DRM_DEBUG_KMS(
"%s\n", __FILE__);
1021 return fimd_activate(ctx,
false);
1024 static int fimd_runtime_resume(
struct device *dev)
1028 DRM_DEBUG_KMS(
"%s\n", __FILE__);
1030 return fimd_activate(ctx,
true);
1036 .name =
"exynos4-fb",
1037 .driver_data = (
unsigned long)&exynos4_fimd_driver_data,
1039 .name =
"exynos5-fb",
1040 .driver_data = (
unsigned long)&exynos5_fimd_driver_data,
1046 static const struct dev_pm_ops fimd_pm_ops = {
1052 .probe = fimd_probe,
1054 .id_table = fimd_driver_ids,
1056 .
name =
"exynos4-fb",