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
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)
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)
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)
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
794806static void fimd_clear_win (struct fimd_context * ctx , int win )
@@ -892,14 +904,15 @@ static int fimd_probe(struct platform_device *pdev)
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)
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)
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
0 commit comments