提交 111e6055 编写于 作者: A Andrzej Hajda 提交者: Inki Dae

drm/exynos: fimd: replace struct fb_videomode with videomode

The patch replaces all occurrences of struct fb_videomode by
more accurate struct videomode. The change allows to remove
mode conversion function and simplifies clock divider calculation.
Clock configuration is moved to separate function.
Signed-off-by: NAndrzej Hajda <a.hajda@samsung.com>
Signed-off-by: NKyungmin Park <kyungmin.park@samsung.com>
Signed-off-by: NInki Dae <inki.dae@samsung.com>
上级 5cc4621a
...@@ -29,35 +29,6 @@ struct exynos_drm_connector { ...@@ -29,35 +29,6 @@ struct exynos_drm_connector {
uint32_t dpms; uint32_t dpms;
}; };
/* convert exynos_video_timings to drm_display_mode */
static inline void
convert_to_display_mode(struct drm_display_mode *mode,
struct exynos_drm_panel_info *panel)
{
struct fb_videomode *timing = &panel->timing;
mode->clock = timing->pixclock / 1000;
mode->vrefresh = timing->refresh;
mode->hdisplay = timing->xres;
mode->hsync_start = mode->hdisplay + timing->right_margin;
mode->hsync_end = mode->hsync_start + timing->hsync_len;
mode->htotal = mode->hsync_end + timing->left_margin;
mode->vdisplay = timing->yres;
mode->vsync_start = mode->vdisplay + timing->lower_margin;
mode->vsync_end = mode->vsync_start + timing->vsync_len;
mode->vtotal = mode->vsync_end + timing->upper_margin;
mode->width_mm = panel->width_mm;
mode->height_mm = panel->height_mm;
if (timing->vmode & FB_VMODE_INTERLACED)
mode->flags |= DRM_MODE_FLAG_INTERLACE;
if (timing->vmode & FB_VMODE_DOUBLE)
mode->flags |= DRM_MODE_FLAG_DBLSCAN;
}
static int exynos_drm_connector_get_modes(struct drm_connector *connector) static int exynos_drm_connector_get_modes(struct drm_connector *connector)
{ {
struct exynos_drm_connector *exynos_connector = struct exynos_drm_connector *exynos_connector =
...@@ -112,7 +83,9 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector) ...@@ -112,7 +83,9 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector)
return 0; return 0;
} }
convert_to_display_mode(mode, panel); drm_display_mode_from_videomode(&panel->vm, mode);
mode->width_mm = panel->width_mm;
mode->height_mm = panel->height_mm;
connector->display_info.width_mm = mode->width_mm; connector->display_info.width_mm = mode->width_mm;
connector->display_info.height_mm = mode->height_mm; connector->display_info.height_mm = mode->height_mm;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <video/of_display_timing.h> #include <video/of_display_timing.h>
#include <video/of_videomode.h>
#include <video/samsung_fimd.h> #include <video/samsung_fimd.h>
#include <drm/exynos_drm.h> #include <drm/exynos_drm.h>
...@@ -36,6 +37,8 @@ ...@@ -36,6 +37,8 @@
* CPU Interface. * CPU Interface.
*/ */
#define FIMD_DEFAULT_FRAMERATE 60
/* position control register for hardware window 0, 2 ~ 4.*/ /* position control register for hardware window 0, 2 ~ 4.*/
#define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16) #define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
#define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16) #define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
...@@ -242,7 +245,7 @@ static void fimd_commit(struct device *dev) ...@@ -242,7 +245,7 @@ static void fimd_commit(struct device *dev)
{ {
struct fimd_context *ctx = get_fimd_context(dev); struct fimd_context *ctx = get_fimd_context(dev);
struct exynos_drm_panel_info *panel = ctx->panel; struct exynos_drm_panel_info *panel = ctx->panel;
struct fb_videomode *timing = &panel->timing; struct videomode *vm = &panel->vm;
struct fimd_driver_data *driver_data; struct fimd_driver_data *driver_data;
u32 val; u32 val;
...@@ -254,22 +257,22 @@ static void fimd_commit(struct device *dev) ...@@ -254,22 +257,22 @@ static void fimd_commit(struct device *dev)
writel(ctx->vidcon1, ctx->regs + driver_data->timing_base + VIDCON1); writel(ctx->vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
/* setup vertical timing values. */ /* setup vertical timing values. */
val = VIDTCON0_VBPD(timing->upper_margin - 1) | val = VIDTCON0_VBPD(vm->vback_porch - 1) |
VIDTCON0_VFPD(timing->lower_margin - 1) | VIDTCON0_VFPD(vm->vfront_porch - 1) |
VIDTCON0_VSPW(timing->vsync_len - 1); VIDTCON0_VSPW(vm->vsync_len - 1);
writel(val, ctx->regs + driver_data->timing_base + VIDTCON0); writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
/* setup horizontal timing values. */ /* setup horizontal timing values. */
val = VIDTCON1_HBPD(timing->left_margin - 1) | val = VIDTCON1_HBPD(vm->hback_porch - 1) |
VIDTCON1_HFPD(timing->right_margin - 1) | VIDTCON1_HFPD(vm->hfront_porch - 1) |
VIDTCON1_HSPW(timing->hsync_len - 1); VIDTCON1_HSPW(vm->hsync_len - 1);
writel(val, ctx->regs + driver_data->timing_base + VIDTCON1); writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
/* setup horizontal and vertical display size. */ /* setup horizontal and vertical display size. */
val = VIDTCON2_LINEVAL(timing->yres - 1) | val = VIDTCON2_LINEVAL(vm->vactive - 1) |
VIDTCON2_HOZVAL(timing->xres - 1) | VIDTCON2_HOZVAL(vm->hactive - 1) |
VIDTCON2_LINEVAL_E(timing->yres - 1) | VIDTCON2_LINEVAL_E(vm->vactive - 1) |
VIDTCON2_HOZVAL_E(timing->xres - 1); VIDTCON2_HOZVAL_E(vm->hactive - 1);
writel(val, ctx->regs + driver_data->timing_base + VIDTCON2); writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
/* setup clock source, clock divider, enable dma. */ /* setup clock source, clock divider, enable dma. */
...@@ -750,45 +753,54 @@ static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev) ...@@ -750,45 +753,54 @@ static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev)
drm_iommu_detach_device(drm_dev, dev); drm_iommu_detach_device(drm_dev, dev);
} }
static int fimd_calc_clkdiv(struct fimd_context *ctx, static int fimd_configure_clocks(struct fimd_context *ctx, struct device *dev)
struct fb_videomode *timing)
{ {
unsigned long clk = clk_get_rate(ctx->lcd_clk); struct videomode *vm = &ctx->panel->vm;
u32 retrace; unsigned long clk;
u32 clkdiv;
u32 best_framerate = 0; ctx->bus_clk = devm_clk_get(dev, "fimd");
u32 framerate; if (IS_ERR(ctx->bus_clk)) {
dev_err(dev, "failed to get bus clock\n");
retrace = timing->left_margin + timing->hsync_len + return PTR_ERR(ctx->bus_clk);
timing->right_margin + timing->xres; }
retrace *= timing->upper_margin + timing->vsync_len +
timing->lower_margin + timing->yres; ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
if (IS_ERR(ctx->lcd_clk)) {
/* default framerate is 60Hz */ dev_err(dev, "failed to get lcd clock\n");
if (!timing->refresh) return PTR_ERR(ctx->lcd_clk);
timing->refresh = 60; }
clk /= retrace; clk = clk_get_rate(ctx->lcd_clk);
if (clk == 0) {
for (clkdiv = 1; clkdiv < 0x100; clkdiv++) { dev_err(dev, "error getting sclk_fimd clock rate\n");
int tmp; return -EINVAL;
}
/* get best framerate */
framerate = clk / clkdiv; if (vm->pixelclock == 0) {
tmp = timing->refresh - framerate; unsigned long c;
if (tmp < 0) { c = vm->hactive + vm->hback_porch + vm->hfront_porch +
best_framerate = framerate; vm->hsync_len;
continue; c *= vm->vactive + vm->vback_porch + vm->vfront_porch +
} else { vm->vsync_len;
if (!best_framerate) vm->pixelclock = c * FIMD_DEFAULT_FRAMERATE;
best_framerate = framerate; if (vm->pixelclock == 0) {
else if (tmp < (best_framerate - framerate)) dev_err(dev, "incorrect display timings\n");
best_framerate = framerate; return -EINVAL;
break; }
dev_warn(dev, "pixel clock recalculated to %luHz (%dHz frame rate)\n",
vm->pixelclock, FIMD_DEFAULT_FRAMERATE);
} }
ctx->clkdiv = DIV_ROUND_UP(clk, vm->pixelclock);
if (ctx->clkdiv > 256) {
dev_warn(dev, "calculated pixel clock divider too high (%u), lowered to 256\n",
ctx->clkdiv);
ctx->clkdiv = 256;
} }
vm->pixelclock = clk / ctx->clkdiv;
DRM_DEBUG_KMS("pixel clock = %lu, clkdiv = %d\n", vm->pixelclock,
ctx->clkdiv);
return clkdiv; return 0;
} }
static void fimd_clear_win(struct fimd_context *ctx, int win) static void fimd_clear_win(struct fimd_context *ctx, int win)
...@@ -892,14 +904,15 @@ static int fimd_probe(struct platform_device *pdev) ...@@ -892,14 +904,15 @@ static int fimd_probe(struct platform_device *pdev)
int ret = -EINVAL; int ret = -EINVAL;
if (dev->of_node) { if (dev->of_node) {
struct videomode *vm;
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata) if (!pdata)
return -ENOMEM; return -ENOMEM;
ret = of_get_fb_videomode(dev->of_node, &pdata->panel.timing, vm = &pdata->panel.vm;
OF_USE_NATIVE_MODE); ret = of_get_videomode(dev->of_node, vm, OF_USE_NATIVE_MODE);
if (ret) { if (ret) {
DRM_ERROR("failed: of_get_fb_videomode() : %d\n", ret); DRM_ERROR("failed: of_get_videomode() : %d\n", ret);
return ret; return ret;
} }
} else { } else {
...@@ -920,17 +933,9 @@ static int fimd_probe(struct platform_device *pdev) ...@@ -920,17 +933,9 @@ static int fimd_probe(struct platform_device *pdev)
if (!ctx) if (!ctx)
return -ENOMEM; return -ENOMEM;
ctx->bus_clk = devm_clk_get(dev, "fimd"); ret = fimd_configure_clocks(ctx, dev);
if (IS_ERR(ctx->bus_clk)) { if (ret)
dev_err(dev, "failed to get bus clock\n"); return ret;
return PTR_ERR(ctx->bus_clk);
}
ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
if (IS_ERR(ctx->lcd_clk)) {
dev_err(dev, "failed to get lcd clock\n");
return PTR_ERR(ctx->lcd_clk);
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
...@@ -975,12 +980,6 @@ static int fimd_probe(struct platform_device *pdev) ...@@ -975,12 +980,6 @@ static int fimd_probe(struct platform_device *pdev)
pm_runtime_enable(dev); pm_runtime_enable(dev);
pm_runtime_get_sync(dev); pm_runtime_get_sync(dev);
ctx->clkdiv = fimd_calc_clkdiv(ctx, &panel->timing);
panel->timing.pixclock = clk_get_rate(ctx->lcd_clk) / ctx->clkdiv;
DRM_DEBUG_KMS("pixel clock = %d, clkdiv = %d\n",
panel->timing.pixclock, ctx->clkdiv);
for (win = 0; win < WINDOWS_NR; win++) for (win = 0; win < WINDOWS_NR; win++)
fimd_clear_win(ctx, win); fimd_clear_win(ctx, win);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#define _EXYNOS_DRM_H_ #define _EXYNOS_DRM_H_
#include <uapi/drm/exynos_drm.h> #include <uapi/drm/exynos_drm.h>
#include <video/videomode.h>
/** /**
* A structure for lcd panel information. * A structure for lcd panel information.
...@@ -24,7 +25,7 @@ ...@@ -24,7 +25,7 @@
* @height_mm: physical size of lcd height. * @height_mm: physical size of lcd height.
*/ */
struct exynos_drm_panel_info { struct exynos_drm_panel_info {
struct fb_videomode timing; struct videomode vm;
u32 width_mm; u32 width_mm;
u32 height_mm; u32 height_mm;
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册