@@ -379,6 +379,35 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
379379 return 0 ;
380380}
381381
382+ /*
383+ * LCD reset sequence
384+ */
385+ static void atmel_lcdfb_reset (struct atmel_lcdfb_info * sinfo )
386+ {
387+ might_sleep ();
388+
389+ /* LCD power off */
390+ lcdc_writel (sinfo , ATMEL_LCDC_PWRCON , sinfo -> guard_time << ATMEL_LCDC_GUARDT_OFFSET );
391+
392+ /* wait for the LCDC core to become idle */
393+ while (lcdc_readl (sinfo , ATMEL_LCDC_PWRCON ) & ATMEL_LCDC_BUSY )
394+ msleep (10 );
395+
396+ /* DMA disable */
397+ lcdc_writel (sinfo , ATMEL_LCDC_DMACON , 0 );
398+
399+ /* wait for DMA engine to become idle */
400+ while (lcdc_readl (sinfo , ATMEL_LCDC_DMACON ) & ATMEL_LCDC_DMABUSY )
401+ msleep (10 );
402+
403+ /* LCD power on */
404+ lcdc_writel (sinfo , ATMEL_LCDC_PWRCON ,
405+ (sinfo -> guard_time << ATMEL_LCDC_GUARDT_OFFSET ) | ATMEL_LCDC_PWR );
406+
407+ /* DMA enable */
408+ lcdc_writel (sinfo , ATMEL_LCDC_DMACON , sinfo -> default_dmacon );
409+ }
410+
382411/**
383412 * atmel_lcdfb_set_par - Alters the hardware state.
384413 * @info: frame buffer structure that represents a single frame buffer
@@ -401,6 +430,8 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
401430 unsigned long clk_value_khz ;
402431 unsigned long bits_per_line ;
403432
433+ might_sleep ();
434+
404435 dev_dbg (info -> device , "%s:\n" , __func__ );
405436 dev_dbg (info -> device , " * resolution: %ux%u (%ux%u virtual)\n" ,
406437 info -> var .xres , info -> var .yres ,
@@ -511,6 +542,8 @@ static int atmel_lcdfb_set_par(struct fb_info *info)
511542
512543 /* Disable all interrupts */
513544 lcdc_writel (sinfo , ATMEL_LCDC_IDR , ~0UL );
545+ /* Enable FIFO & DMA errors */
546+ lcdc_writel (sinfo , ATMEL_LCDC_IER , ATMEL_LCDC_UFLWI | ATMEL_LCDC_OWRI | ATMEL_LCDC_MERI );
514547
515548 /* ...wait for DMA engine to become idle... */
516549 while (lcdc_readl (sinfo , ATMEL_LCDC_DMACON ) & ATMEL_LCDC_DMABUSY )
@@ -645,10 +678,26 @@ static irqreturn_t atmel_lcdfb_interrupt(int irq, void *dev_id)
645678 u32 status ;
646679
647680 status = lcdc_readl (sinfo , ATMEL_LCDC_ISR );
648- lcdc_writel (sinfo , ATMEL_LCDC_IDR , status );
681+ if (status & ATMEL_LCDC_UFLWI ) {
682+ dev_warn (info -> device , "FIFO underflow %#x\n" , status );
683+ /* reset DMA and FIFO to avoid screen shifting */
684+ schedule_work (& sinfo -> task );
685+ }
686+ lcdc_writel (sinfo , ATMEL_LCDC_ICR , status );
649687 return IRQ_HANDLED ;
650688}
651689
690+ /*
691+ * LCD controller task (to reset the LCD)
692+ */
693+ static void atmel_lcdfb_task (struct work_struct * work )
694+ {
695+ struct atmel_lcdfb_info * sinfo =
696+ container_of (work , struct atmel_lcdfb_info , task );
697+
698+ atmel_lcdfb_reset (sinfo );
699+ }
700+
652701static int __init atmel_lcdfb_init_fbinfo (struct atmel_lcdfb_info * sinfo )
653702{
654703 struct fb_info * info = sinfo -> info ;
@@ -824,6 +873,10 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
824873 goto unmap_mmio ;
825874 }
826875
876+ /* Some operations on the LCDC might sleep and
877+ * require a preemptible task context */
878+ INIT_WORK (& sinfo -> task , atmel_lcdfb_task );
879+
827880 ret = atmel_lcdfb_init_fbinfo (sinfo );
828881 if (ret < 0 ) {
829882 dev_err (dev , "init fbinfo failed: %d\n" , ret );
@@ -866,6 +919,7 @@ static int __init atmel_lcdfb_probe(struct platform_device *pdev)
866919free_cmap :
867920 fb_dealloc_cmap (& info -> cmap );
868921unregister_irqs :
922+ cancel_work_sync (& sinfo -> task );
869923 free_irq (sinfo -> irq_base , info );
870924unmap_mmio :
871925 exit_backlight (sinfo );
@@ -903,6 +957,7 @@ static int __exit atmel_lcdfb_remove(struct platform_device *pdev)
903957 if (!sinfo )
904958 return 0 ;
905959
960+ cancel_work_sync (& sinfo -> task );
906961 exit_backlight (sinfo );
907962 if (sinfo -> atmel_lcdfb_power_control )
908963 sinfo -> atmel_lcdfb_power_control (0 );
0 commit comments