History

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.

Andrzej Hajda committed 13 years ago

Commit 111e6051 parent 5cc46213 files · +70 −97Browse files

Unified · Split

3 files
  1. drivers/gpu/drm/exynos/exynos_drm_connector.c +3 −30
  2. drivers/gpu/drm/exynos/exynos_drm_fimd.c +65 −66
  3. include/drm/exynos_drm.h +2 −1
drivers/gpu/drm/exynos/exynos_drm_connector.c+3−30
@@ -29,35 +29,6 @@ struct exynos_drm_connector { · 28 unmodified lines
2929 uint32_t dpms;
3030 };
3131
32−/* convert exynos_video_timings to drm_display_mode */
33−static inline void
34−convert_to_display_mode(struct drm_display_mode *mode,
35− struct exynos_drm_panel_info *panel)
36−{
37− struct fb_videomode *timing = &panel->timing;
38−
39− mode->clock = timing->pixclock / 1000;
40− mode->vrefresh = timing->refresh;
41−
42− mode->hdisplay = timing->xres;
43− mode->hsync_start = mode->hdisplay + timing->right_margin;
44− mode->hsync_end = mode->hsync_start + timing->hsync_len;
45− mode->htotal = mode->hsync_end + timing->left_margin;
46−
47− mode->vdisplay = timing->yres;
48− mode->vsync_start = mode->vdisplay + timing->lower_margin;
49− mode->vsync_end = mode->vsync_start + timing->vsync_len;
50− mode->vtotal = mode->vsync_end + timing->upper_margin;
51− mode->width_mm = panel->width_mm;
52− mode->height_mm = panel->height_mm;
53−
54− if (timing->vmode & FB_VMODE_INTERLACED)
55− mode->flags |= DRM_MODE_FLAG_INTERLACE;
56−
57− if (timing->vmode & FB_VMODE_DOUBLE)
58− mode->flags |= DRM_MODE_FLAG_DBLSCAN;
59−}
60−
6132 static int exynos_drm_connector_get_modes(struct drm_connector *connector)
6233 {
6334 struct exynos_drm_connector *exynos_connector =
@@ -112,7 +83,9 @@ static int exynos_drm_connector_get_modes(struct drm_connector *connector) · 48 unmodified lines
11283 return 0;
11384 }
11485
115− convert_to_display_mode(mode, panel);
86+ drm_display_mode_from_videomode(&panel->vm, mode);
87+ mode->width_mm = panel->width_mm;
88+ mode->height_mm = panel->height_mm;
11689 connector->display_info.width_mm = mode->width_mm;
11790 connector->display_info.height_mm = mode->height_mm;
11891
drivers/gpu/drm/exynos/exynos_drm_fimd.c+65−66
@@ -21,6 +21,7 @@ · 20 unmodified lines
2121 #include <linux/pm_runtime.h>
2222
2323 #include <video/of_display_timing.h>
24+#include <video/of_videomode.h>
2425 #include <video/samsung_fimd.h>
2526 #include <drm/exynos_drm.h>
2627
@@ -36,6 +37,8 @@ · 9 unmodified lines
3637 * CPU Interface.
3738 */
3839
40+#define FIMD_DEFAULT_FRAMERATE 60
41+
3942 /* position control register for hardware window 0, 2 ~ 4.*/
4043 #define VIDOSD_A(win) (VIDOSD_BASE + 0x00 + (win) * 16)
4144 #define VIDOSD_B(win) (VIDOSD_BASE + 0x04 + (win) * 16)
@@ -242,7 +245,7 @@ static void fimd_commit(struct device *dev) · 200 unmodified lines
242245 {
243246 struct fimd_context *ctx = get_fimd_context(dev);
244247 struct exynos_drm_panel_info *panel = ctx->panel;
245− struct fb_videomode *timing = &panel->timing;
248+ struct videomode *vm = &panel->vm;
246249 struct fimd_driver_data *driver_data;
247250 u32 val;
248251
@@ -254,22 +257,22 @@ static void fimd_commit(struct device *dev) · 5 unmodified lines
254257 writel(ctx->vidcon1, ctx->regs + driver_data->timing_base + VIDCON1);
255258
256259 /* setup vertical timing values. */
257− val = VIDTCON0_VBPD(timing->upper_margin - 1) |
258− VIDTCON0_VFPD(timing->lower_margin - 1) |
259− VIDTCON0_VSPW(timing->vsync_len - 1);
260+ val = VIDTCON0_VBPD(vm->vback_porch - 1) |
261+ VIDTCON0_VFPD(vm->vfront_porch - 1) |
262+ VIDTCON0_VSPW(vm->vsync_len - 1);
260263 writel(val, ctx->regs + driver_data->timing_base + VIDTCON0);
261264
262265 /* setup horizontal timing values. */
263− val = VIDTCON1_HBPD(timing->left_margin - 1) |
264− VIDTCON1_HFPD(timing->right_margin - 1) |
265− VIDTCON1_HSPW(timing->hsync_len - 1);
266+ val = VIDTCON1_HBPD(vm->hback_porch - 1) |
267+ VIDTCON1_HFPD(vm->hfront_porch - 1) |
268+ VIDTCON1_HSPW(vm->hsync_len - 1);
266269 writel(val, ctx->regs + driver_data->timing_base + VIDTCON1);
267270
268271 /* setup horizontal and vertical display size. */
269− val = VIDTCON2_LINEVAL(timing->yres - 1) |
270− VIDTCON2_HOZVAL(timing->xres - 1) |
271− VIDTCON2_LINEVAL_E(timing->yres - 1) |
272− VIDTCON2_HOZVAL_E(timing->xres - 1);
272+ val = VIDTCON2_LINEVAL(vm->vactive - 1) |
273+ VIDTCON2_HOZVAL(vm->hactive - 1) |
274+ VIDTCON2_LINEVAL_E(vm->vactive - 1) |
275+ VIDTCON2_HOZVAL_E(vm->hactive - 1);
273276 writel(val, ctx->regs + driver_data->timing_base + VIDTCON2);
274277
275278 /* setup clock source, clock divider, enable dma. */
@@ -750,45 +753,54 @@ static void fimd_subdrv_remove(struct drm_device *drm_dev, struct device *dev) · 474 unmodified lines
750753 drm_iommu_detach_device(drm_dev, dev);
751754 }
752755
753−static int fimd_calc_clkdiv(struct fimd_context *ctx,
754− struct fb_videomode *timing)
756+static int fimd_configure_clocks(struct fimd_context *ctx, struct device *dev)
755757 {
756− unsigned long clk = clk_get_rate(ctx->lcd_clk);
757− u32 retrace;
758− u32 clkdiv;
759− u32 best_framerate = 0;
760− u32 framerate;
761−
762− retrace = timing->left_margin + timing->hsync_len +
763− timing->right_margin + timing->xres;
764− retrace *= timing->upper_margin + timing->vsync_len +
765− timing->lower_margin + timing->yres;
766−
767− /* default framerate is 60Hz */
768− if (!timing->refresh)
769− timing->refresh = 60;
770−
771− clk /= retrace;
772−
773− for (clkdiv = 1; clkdiv < 0x100; clkdiv++) {
774− int tmp;
775−
776− /* get best framerate */
777− framerate = clk / clkdiv;
778− tmp = timing->refresh - framerate;
779− if (tmp < 0) {
780− best_framerate = framerate;
781− continue;
782− } else {
783− if (!best_framerate)
784− best_framerate = framerate;
785− else if (tmp < (best_framerate - framerate))
786− best_framerate = framerate;
787− break;
758+ struct videomode *vm = &ctx->panel->vm;
759+ unsigned long clk;
760+
761+ ctx->bus_clk = devm_clk_get(dev, "fimd");
762+ if (IS_ERR(ctx->bus_clk)) {
763+ dev_err(dev, "failed to get bus clock\n");
764+ return PTR_ERR(ctx->bus_clk);
765+ }
766+
767+ ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
768+ if (IS_ERR(ctx->lcd_clk)) {
769+ dev_err(dev, "failed to get lcd clock\n");
770+ return PTR_ERR(ctx->lcd_clk);
771+ }
772+
773+ clk = clk_get_rate(ctx->lcd_clk);
774+ if (clk == 0) {
775+ dev_err(dev, "error getting sclk_fimd clock rate\n");
776+ return -EINVAL;
777+ }
778+
779+ if (vm->pixelclock == 0) {
780+ unsigned long c;
781+ c = vm->hactive + vm->hback_porch + vm->hfront_porch +
782+ vm->hsync_len;
783+ c *= vm->vactive + vm->vback_porch + vm->vfront_porch +
784+ vm->vsync_len;
785+ vm->pixelclock = c * FIMD_DEFAULT_FRAMERATE;
786+ if (vm->pixelclock == 0) {
787+ dev_err(dev, "incorrect display timings\n");
788+ return -EINVAL;
788789 }
790+ dev_warn(dev, "pixel clock recalculated to %luHz (%dHz frame rate)\n",
791+ vm->pixelclock, FIMD_DEFAULT_FRAMERATE);
792+ }
793+ ctx->clkdiv = DIV_ROUND_UP(clk, vm->pixelclock);
794+ if (ctx->clkdiv > 256) {
795+ dev_warn(dev, "calculated pixel clock divider too high (%u), lowered to 256\n",
796+ ctx->clkdiv);
797+ ctx->clkdiv = 256;
789798 }
799+ vm->pixelclock = clk / ctx->clkdiv;
800+ DRM_DEBUG_KMS("pixel clock = %lu, clkdiv = %d\n", vm->pixelclock,
801+ ctx->clkdiv);
790802
791− return clkdiv;
803+ return 0;
792804 }
793805
794806 static void fimd_clear_win(struct fimd_context *ctx, int win)
@@ -892,14 +904,15 @@ static int fimd_probe(struct platform_device *pdev) · 97 unmodified lines
892904 int ret = -EINVAL;
893905
894906 if (dev->of_node) {
907+ struct videomode *vm;
895908 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
896909 if (!pdata)
897910 return -ENOMEM;
898911
899− ret = of_get_fb_videomode(dev->of_node, &pdata->panel.timing,
900− OF_USE_NATIVE_MODE);
912+ vm = &pdata->panel.vm;
913+ ret = of_get_videomode(dev->of_node, vm, OF_USE_NATIVE_MODE);
901914 if (ret) {
902− DRM_ERROR("failed: of_get_fb_videomode() : %d\n", ret);
915+ DRM_ERROR("failed: of_get_videomode() : %d\n", ret);
903916 return ret;
904917 }
905918 } else {
@@ -920,17 +933,9 @@ static int fimd_probe(struct platform_device *pdev) · 14 unmodified lines
920933 if (!ctx)
921934 return -ENOMEM;
922935
923− ctx->bus_clk = devm_clk_get(dev, "fimd");
924− if (IS_ERR(ctx->bus_clk)) {
925− dev_err(dev, "failed to get bus clock\n");
926− return PTR_ERR(ctx->bus_clk);
927− }
928−
929− ctx->lcd_clk = devm_clk_get(dev, "sclk_fimd");
930− if (IS_ERR(ctx->lcd_clk)) {
931− dev_err(dev, "failed to get lcd clock\n");
932− return PTR_ERR(ctx->lcd_clk);
933− }
936+ ret = fimd_configure_clocks(ctx, dev);
937+ if (ret)
938+ return ret;
934939
935940 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
936941
@@ -975,12 +980,6 @@ static int fimd_probe(struct platform_device *pdev) · 38 unmodified lines
975980 pm_runtime_enable(dev);
976981 pm_runtime_get_sync(dev);
977982
978− ctx->clkdiv = fimd_calc_clkdiv(ctx, &panel->timing);
979− panel->timing.pixclock = clk_get_rate(ctx->lcd_clk) / ctx->clkdiv;
980−
981− DRM_DEBUG_KMS("pixel clock = %d, clkdiv = %d\n",
982− panel->timing.pixclock, ctx->clkdiv);
983−
984983 for (win = 0; win < WINDOWS_NR; win++)
985984 fimd_clear_win(ctx, win);
986985
include/drm/exynos_drm.h+2−1
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #define _EXYNOS_DRM_H_
1616
1717 #include <uapi/drm/exynos_drm.h>
18+#include <video/videomode.h>
1819
1920 /**
2021 * A structure for lcd panel information.
@@ -24,7 +25,7 @@ · 3 unmodified lines
2425 * @height_mm: physical size of lcd height.
2526 */
2627 struct exynos_drm_panel_info {
27− struct fb_videomode timing;
28+ struct videomode vm;
2829 u32 width_mm;
2930 u32 height_mm;
3031 };

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t