2 * SuperH Mobile LCDC Framebuffer
4 * Copyright (c) 2008 Magnus Damm
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/delay.h>
15 #include <linux/clk.h>
16 #include <linux/pm_runtime.h>
17 #include <linux/platform_device.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/interrupt.h>
20 #include <linux/vmalloc.h>
21 #include <linux/ioctl.h>
22 #include <linux/slab.h>
23 #include <linux/console.h>
24 #include <linux/backlight.h>
25 #include <linux/gpio.h>
26 #include <video/sh_mobile_lcdc.h>
27 #include <linux/atomic.h>
29 #include "sh_mobile_lcdcfb.h"
30 #include "sh_mobile_meram.h"
32 #define SIDE_B_OFFSET 0x1000
33 #define MIRROR_OFFSET 0x2000
35 /* shared registers and their order for context save/restore */
36 static int lcdc_shared_regs[] = {
44 #define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
49 static unsigned long lcdc_offs_mainlcd[NR_CH_REGS] = {
69 static unsigned long lcdc_offs_sublcd[NR_CH_REGS] = {
87 static const struct fb_videomode default_720p = {
102 .sync = FB_SYNC_VERT_HIGH_ACT | FB_SYNC_HOR_HIGH_ACT,
105 struct sh_mobile_lcdc_priv {
111 unsigned long lddckr;
112 struct sh_mobile_lcdc_chan ch[2];
113 struct notifier_block notifier;
114 unsigned long saved_shared_regs[NR_SHARED_REGS];
116 int forced_bpp; /* 2 channel LCDC must share bpp setting */
117 struct sh_mobile_meram_info *meram_dev;
120 static bool banked(int reg_nr)
140 static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
141 int reg_nr, unsigned long data)
143 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
145 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
149 static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan *chan,
150 int reg_nr, unsigned long data)
152 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr] +
156 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
159 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
162 static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
163 unsigned long reg_offs, unsigned long data)
165 iowrite32(data, priv->base + reg_offs);
168 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
169 unsigned long reg_offs)
171 return ioread32(priv->base + reg_offs);
174 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
175 unsigned long reg_offs,
176 unsigned long mask, unsigned long until)
178 while ((lcdc_read(priv, reg_offs) & mask) != until)
182 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
184 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
187 static void lcdc_sys_write_index(void *handle, unsigned long data)
189 struct sh_mobile_lcdc_chan *ch = handle;
191 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT);
192 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
193 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
194 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
195 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
198 static void lcdc_sys_write_data(void *handle, unsigned long data)
200 struct sh_mobile_lcdc_chan *ch = handle;
202 lcdc_write(ch->lcdc, _LDDWD0R, data | LDDWDxR_WDACT | LDDWDxR_RSW);
203 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
204 lcdc_write(ch->lcdc, _LDDWAR, LDDWAR_WA |
205 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
206 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
209 static unsigned long lcdc_sys_read_data(void *handle)
211 struct sh_mobile_lcdc_chan *ch = handle;
213 lcdc_write(ch->lcdc, _LDDRDR, LDDRDR_RSR);
214 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
215 lcdc_write(ch->lcdc, _LDDRAR, LDDRAR_RA |
216 (lcdc_chan_is_sublcd(ch) ? 2 : 0));
218 lcdc_wait_bit(ch->lcdc, _LDSR, LDSR_AS, 0);
220 return lcdc_read(ch->lcdc, _LDDRDR) & LDDRDR_DRD_MASK;
223 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
224 lcdc_sys_write_index,
229 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv *priv)
231 if (atomic_inc_and_test(&priv->hw_usecnt)) {
233 clk_enable(priv->dot_clk);
234 pm_runtime_get_sync(priv->dev);
235 if (priv->meram_dev && priv->meram_dev->pdev)
236 pm_runtime_get_sync(&priv->meram_dev->pdev->dev);
240 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv *priv)
242 if (atomic_sub_return(1, &priv->hw_usecnt) == -1) {
243 if (priv->meram_dev && priv->meram_dev->pdev)
244 pm_runtime_put_sync(&priv->meram_dev->pdev->dev);
245 pm_runtime_put(priv->dev);
247 clk_disable(priv->dot_clk);
251 static int sh_mobile_lcdc_sginit(struct fb_info *info,
252 struct list_head *pagelist)
254 struct sh_mobile_lcdc_chan *ch = info->par;
255 unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
259 sg_init_table(ch->sglist, nr_pages_max);
261 list_for_each_entry(page, pagelist, lru)
262 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
267 static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
268 struct list_head *pagelist)
270 struct sh_mobile_lcdc_chan *ch = info->par;
271 struct sh_mobile_lcdc_board_cfg *bcfg = &ch->cfg.board_cfg;
273 /* enable clocks before accessing hardware */
274 sh_mobile_lcdc_clk_on(ch->lcdc);
277 * It's possible to get here without anything on the pagelist via
278 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
279 * invocation. In the former case, the acceleration routines are
280 * stepped in to when using the framebuffer console causing the
281 * workqueue to be scheduled without any dirty pages on the list.
283 * Despite this, a panel update is still needed given that the
284 * acceleration routines have their own methods for writing in
285 * that still need to be updated.
287 * The fsync() and empty pagelist case could be optimized for,
288 * but we don't bother, as any application exhibiting such
289 * behaviour is fundamentally broken anyways.
291 if (!list_empty(pagelist)) {
292 unsigned int nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
294 /* trigger panel update */
295 dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
296 if (bcfg->start_transfer)
297 bcfg->start_transfer(bcfg->board_data, ch,
298 &sh_mobile_lcdc_sys_bus_ops);
299 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
300 dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
302 if (bcfg->start_transfer)
303 bcfg->start_transfer(bcfg->board_data, ch,
304 &sh_mobile_lcdc_sys_bus_ops);
305 lcdc_write_chan(ch, LDSM2R, LDSM2R_OSTRG);
309 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
311 struct fb_deferred_io *fbdefio = info->fbdefio;
314 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
317 static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
319 struct sh_mobile_lcdc_priv *priv = data;
320 struct sh_mobile_lcdc_chan *ch;
321 unsigned long ldintr;
325 /* Acknowledge interrupts and disable further VSYNC End IRQs. */
326 ldintr = lcdc_read(priv, _LDINTR);
327 lcdc_write(priv, _LDINTR, (ldintr ^ LDINTR_STATUS_MASK) & ~LDINTR_VEE);
329 /* figure out if this interrupt is for main or sub lcd */
330 is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
332 /* wake up channel and disable clocks */
333 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
340 if (ldintr & LDINTR_FS) {
341 if (is_sub == lcdc_chan_is_sublcd(ch)) {
343 wake_up(&ch->frame_end_wait);
345 sh_mobile_lcdc_clk_off(priv);
350 if (ldintr & LDINTR_VES)
351 complete(&ch->vsync_completion);
357 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
360 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
363 /* start or stop the lcdc */
365 lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
367 lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
369 /* wait until power is applied/stopped on all channels */
370 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
371 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
373 tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
375 if (start && tmp == LDPMR_LPS)
377 if (!start && tmp == 0)
383 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
386 static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
388 struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
389 unsigned long h_total, hsync_pos, display_h_total;
392 tmp = ch->ldmt1r_value;
393 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
394 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
395 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
396 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
397 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
398 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
399 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
400 lcdc_write_chan(ch, LDMT1R, tmp);
403 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
404 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
406 /* horizontal configuration */
407 h_total = display_var->xres + display_var->hsync_len +
408 display_var->left_margin + display_var->right_margin;
409 tmp = h_total / 8; /* HTCN */
410 tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
411 lcdc_write_chan(ch, LDHCNR, tmp);
413 hsync_pos = display_var->xres + display_var->right_margin;
414 tmp = hsync_pos / 8; /* HSYNP */
415 tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
416 lcdc_write_chan(ch, LDHSYNR, tmp);
418 /* vertical configuration */
419 tmp = display_var->yres + display_var->vsync_len +
420 display_var->upper_margin + display_var->lower_margin; /* VTLN */
421 tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
422 lcdc_write_chan(ch, LDVLNR, tmp);
424 tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
425 tmp |= display_var->vsync_len << 16; /* VSYNW */
426 lcdc_write_chan(ch, LDVSYNR, tmp);
428 /* Adjust horizontal synchronisation for HDMI */
429 display_h_total = display_var->xres + display_var->hsync_len +
430 display_var->left_margin + display_var->right_margin;
431 tmp = ((display_var->xres & 7) << 24) |
432 ((display_h_total & 7) << 16) |
433 ((display_var->hsync_len & 7) << 8) |
435 lcdc_write_chan(ch, LDHAJR, tmp);
438 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
440 struct sh_mobile_lcdc_chan *ch;
441 struct sh_mobile_lcdc_board_cfg *board_cfg;
444 unsigned long ldddsr;
447 /* enable clocks before accessing the hardware */
448 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
449 if (priv->ch[k].enabled) {
450 sh_mobile_lcdc_clk_on(priv);
452 bpp = priv->ch[k].info->var.bits_per_pixel;
457 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
458 lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
460 /* enable LCDC channels */
461 tmp = lcdc_read(priv, _LDCNT2R);
462 tmp |= priv->ch[0].enabled;
463 tmp |= priv->ch[1].enabled;
464 lcdc_write(priv, _LDCNT2R, tmp);
466 /* read data from external memory, avoid using the BEU for now */
467 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~LDCNT2R_MD);
469 /* stop the lcdc first */
470 sh_mobile_lcdc_start_stop(priv, 0);
472 /* configure clocks */
474 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
477 if (!priv->ch[k].enabled)
480 m = ch->cfg.clock_divider;
486 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
488 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
489 lcdc_write_chan(ch, LDDCKPAT1R, 0);
490 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
493 lcdc_write(priv, _LDDCKR, tmp);
495 /* start dotclock again */
496 lcdc_write(priv, _LDDCKSTPR, 0);
497 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
499 /* interrupts are disabled to begin with */
500 lcdc_write(priv, _LDINTR, 0);
502 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
508 sh_mobile_lcdc_geometry(ch);
511 lcdc_write_chan(ch, LDPMR, 0);
513 board_cfg = &ch->cfg.board_cfg;
514 if (board_cfg->setup_sys) {
515 ret = board_cfg->setup_sys(board_cfg->board_data,
516 ch, &sh_mobile_lcdc_sys_bus_ops);
522 /* word and long word swap */
523 ldddsr = lcdc_read(priv, _LDDDSR);
524 if (priv->ch[0].info->var.nonstd)
525 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
529 ldddsr |= LDDDSR_LS | LDDDSR_WS;
532 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
539 lcdc_write(priv, _LDDDSR, ldddsr);
541 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
542 unsigned long base_addr_y;
543 unsigned long base_addr_c = 0;
547 if (!priv->ch[k].enabled)
550 /* set bpp format in PKF[4:0] */
551 tmp = lcdc_read_chan(ch, LDDFR);
552 tmp &= ~(LDDFR_CF0 | LDDFR_CC | LDDFR_YF_MASK | LDDFR_PKF_MASK);
553 if (ch->info->var.nonstd) {
554 tmp |= (ch->info->var.nonstd << 16);
555 switch (ch->info->var.bits_per_pixel) {
566 switch (ch->info->var.bits_per_pixel) {
568 tmp |= LDDFR_PKF_RGB16;
571 tmp |= LDDFR_PKF_RGB24;
574 tmp |= LDDFR_PKF_ARGB32;
578 lcdc_write_chan(ch, LDDFR, tmp);
580 base_addr_y = ch->info->fix.smem_start;
581 base_addr_c = base_addr_y +
583 ch->info->var.yres_virtual;
584 pitch = ch->info->fix.line_length;
586 /* test if we can enable meram */
587 if (ch->cfg.meram_cfg && priv->meram_dev &&
588 priv->meram_dev->ops) {
589 struct sh_mobile_meram_cfg *cfg;
590 struct sh_mobile_meram_info *mdev;
591 unsigned long icb_addr_y, icb_addr_c;
595 cfg = ch->cfg.meram_cfg;
596 mdev = priv->meram_dev;
597 /* we need to de-init configured ICBs before we
598 * we can re-initialize them.
600 if (ch->meram_enabled)
601 mdev->ops->meram_unregister(mdev, cfg);
603 ch->meram_enabled = 0;
605 if (ch->info->var.nonstd) {
606 if (ch->info->var.bits_per_pixel == 24)
607 pf = SH_MOBILE_MERAM_PF_NV24;
609 pf = SH_MOBILE_MERAM_PF_NV;
611 pf = SH_MOBILE_MERAM_PF_RGB;
614 ret = mdev->ops->meram_register(mdev, cfg, pitch,
623 /* set LDSA1R value */
624 base_addr_y = icb_addr_y;
627 /* set LDSA2R value if required */
629 base_addr_c = icb_addr_c;
631 ch->meram_enabled = 1;
635 /* point out our frame buffer */
636 lcdc_write_chan(ch, LDSA1R, base_addr_y);
637 if (ch->info->var.nonstd)
638 lcdc_write_chan(ch, LDSA2R, base_addr_c);
641 lcdc_write_chan(ch, LDMLSR, pitch);
643 /* setup deferred io if SYS bus */
644 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
645 if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
646 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
647 ch->defio.delay = msecs_to_jiffies(tmp);
648 ch->info->fbdefio = &ch->defio;
649 fb_deferred_io_init(ch->info);
652 lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
654 /* enable "Frame End Interrupt Enable" bit */
655 lcdc_write(priv, _LDINTR, LDINTR_FE);
658 /* continuous read mode */
659 lcdc_write_chan(ch, LDSM1R, 0);
664 lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
667 sh_mobile_lcdc_start_stop(priv, 1);
670 /* tell the board code to enable the panel */
671 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
676 board_cfg = &ch->cfg.board_cfg;
677 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
678 board_cfg->display_on(board_cfg->board_data, ch->info);
679 module_put(board_cfg->owner);
683 ch->bl->props.power = FB_BLANK_UNBLANK;
684 backlight_update_status(ch->bl);
691 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
693 struct sh_mobile_lcdc_chan *ch;
694 struct sh_mobile_lcdc_board_cfg *board_cfg;
697 /* clean up deferred io and ask board code to disable panel */
698 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
704 * flush frame, and wait for frame end interrupt
705 * clean up deferred io and enable clock
707 if (ch->info && ch->info->fbdefio) {
709 schedule_delayed_work(&ch->info->deferred_work, 0);
710 wait_event(ch->frame_end_wait, ch->frame_end);
711 fb_deferred_io_cleanup(ch->info);
712 ch->info->fbdefio = NULL;
713 sh_mobile_lcdc_clk_on(priv);
717 ch->bl->props.power = FB_BLANK_POWERDOWN;
718 backlight_update_status(ch->bl);
721 board_cfg = &ch->cfg.board_cfg;
722 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
723 board_cfg->display_off(board_cfg->board_data);
724 module_put(board_cfg->owner);
727 /* disable the meram */
728 if (ch->meram_enabled) {
729 struct sh_mobile_meram_cfg *cfg;
730 struct sh_mobile_meram_info *mdev;
731 cfg = ch->cfg.meram_cfg;
732 mdev = priv->meram_dev;
733 mdev->ops->meram_unregister(mdev, cfg);
734 ch->meram_enabled = 0;
741 sh_mobile_lcdc_start_stop(priv, 0);
746 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
747 if (priv->ch[k].enabled)
748 sh_mobile_lcdc_clk_off(priv);
751 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
753 int interface_type = ch->cfg.interface_type;
755 switch (interface_type) {
779 /* SUBLCD only supports SYS interface */
780 if (lcdc_chan_is_sublcd(ch)) {
781 if (!(interface_type & LDMT1R_IFM))
784 interface_type &= ~LDMT1R_IFM;
787 ch->ldmt1r_value = interface_type;
791 static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
793 struct sh_mobile_lcdc_priv *priv)
797 switch (clock_source) {
800 priv->lddckr = LDDCKR_ICKSEL_BUS;
802 case LCDC_CLK_PERIPHERAL:
803 str = "peripheral_clk";
804 priv->lddckr = LDDCKR_ICKSEL_MIPI;
806 case LCDC_CLK_EXTERNAL:
808 priv->lddckr = LDDCKR_ICKSEL_HDMI;
815 priv->dot_clk = clk_get(&pdev->dev, str);
816 if (IS_ERR(priv->dot_clk)) {
817 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
818 return PTR_ERR(priv->dot_clk);
822 /* Runtime PM support involves two step for this driver:
823 * 1) Enable Runtime PM
824 * 2) Force Runtime PM Resume since hardware is accessed from probe()
826 priv->dev = &pdev->dev;
827 pm_runtime_enable(priv->dev);
828 pm_runtime_resume(priv->dev);
832 static int sh_mobile_lcdc_setcolreg(u_int regno,
833 u_int red, u_int green, u_int blue,
834 u_int transp, struct fb_info *info)
836 u32 *palette = info->pseudo_palette;
838 if (regno >= PALETTE_NR)
841 /* only FB_VISUAL_TRUECOLOR supported */
843 red >>= 16 - info->var.red.length;
844 green >>= 16 - info->var.green.length;
845 blue >>= 16 - info->var.blue.length;
846 transp >>= 16 - info->var.transp.length;
848 palette[regno] = (red << info->var.red.offset) |
849 (green << info->var.green.offset) |
850 (blue << info->var.blue.offset) |
851 (transp << info->var.transp.offset);
856 static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
857 .id = "SH Mobile LCDC",
858 .type = FB_TYPE_PACKED_PIXELS,
859 .visual = FB_VISUAL_TRUECOLOR,
860 .accel = FB_ACCEL_NONE,
866 static void sh_mobile_lcdc_fillrect(struct fb_info *info,
867 const struct fb_fillrect *rect)
869 sys_fillrect(info, rect);
870 sh_mobile_lcdc_deferred_io_touch(info);
873 static void sh_mobile_lcdc_copyarea(struct fb_info *info,
874 const struct fb_copyarea *area)
876 sys_copyarea(info, area);
877 sh_mobile_lcdc_deferred_io_touch(info);
880 static void sh_mobile_lcdc_imageblit(struct fb_info *info,
881 const struct fb_image *image)
883 sys_imageblit(info, image);
884 sh_mobile_lcdc_deferred_io_touch(info);
887 static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
888 struct fb_info *info)
890 struct sh_mobile_lcdc_chan *ch = info->par;
891 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
892 unsigned long ldrcntr;
893 unsigned long new_pan_offset;
894 unsigned long base_addr_y, base_addr_c;
895 unsigned long c_offset;
898 new_pan_offset = (var->yoffset * info->fix.line_length) +
899 (var->xoffset * (info->var.bits_per_pixel / 8));
901 new_pan_offset = (var->yoffset * info->fix.line_length) +
904 if (new_pan_offset == ch->pan_offset)
905 return 0; /* No change, do nothing */
907 ldrcntr = lcdc_read(priv, _LDRCNTR);
909 /* Set the source address for the next refresh */
910 base_addr_y = ch->dma_handle + new_pan_offset;
913 c_offset = (var->yoffset *
914 info->fix.line_length *
915 (info->var.bits_per_pixel - 8)) / 8;
916 base_addr_c = ch->dma_handle + var->xres * var->yres_virtual +
919 if (info->var.bits_per_pixel == 24)
920 base_addr_c += 2 * var->xoffset;
922 base_addr_c += var->xoffset;
926 if (!ch->meram_enabled) {
927 lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
929 lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
931 struct sh_mobile_meram_cfg *cfg;
932 struct sh_mobile_meram_info *mdev;
933 unsigned long icb_addr_y, icb_addr_c;
936 cfg = ch->cfg.meram_cfg;
937 mdev = priv->meram_dev;
938 ret = mdev->ops->meram_update(mdev, cfg,
939 base_addr_y, base_addr_c,
940 &icb_addr_y, &icb_addr_c);
944 lcdc_write_chan_mirror(ch, LDSA1R, icb_addr_y);
946 lcdc_write_chan_mirror(ch, LDSA2R, icb_addr_c);
950 if (lcdc_chan_is_sublcd(ch))
951 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
953 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
955 ch->pan_offset = new_pan_offset;
957 sh_mobile_lcdc_deferred_io_touch(info);
962 static int sh_mobile_wait_for_vsync(struct fb_info *info)
964 struct sh_mobile_lcdc_chan *ch = info->par;
965 unsigned long ldintr;
968 /* Enable VSync End interrupt and be careful not to acknowledge any
971 ldintr = lcdc_read(ch->lcdc, _LDINTR);
972 ldintr |= LDINTR_VEE | LDINTR_STATUS_MASK;
973 lcdc_write(ch->lcdc, _LDINTR, ldintr);
975 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
976 msecs_to_jiffies(100));
983 static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
989 case FBIO_WAITFORVSYNC:
990 retval = sh_mobile_wait_for_vsync(info);
994 retval = -ENOIOCTLCMD;
1000 static void sh_mobile_fb_reconfig(struct fb_info *info)
1002 struct sh_mobile_lcdc_chan *ch = info->par;
1003 struct fb_videomode mode1, mode2;
1004 struct fb_event event;
1005 int evnt = FB_EVENT_MODE_CHANGE_ALL;
1007 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
1008 /* More framebuffer users are active */
1011 fb_var_to_videomode(&mode1, &ch->display_var);
1012 fb_var_to_videomode(&mode2, &info->var);
1014 if (fb_mode_is_equal(&mode1, &mode2))
1017 /* Display has been re-plugged, framebuffer is free now, reconfigure */
1018 if (fb_set_var(info, &ch->display_var) < 0)
1019 /* Couldn't reconfigure, hopefully, can continue as before */
1022 if (info->var.nonstd)
1023 info->fix.line_length = mode1.xres;
1025 info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
1028 * fb_set_var() calls the notifier change internally, only if
1029 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1030 * user event, we have to call the chain ourselves.
1033 event.data = &mode1;
1034 fb_notifier_call_chain(evnt, &event);
1038 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1039 * user == 1, or with console sem held, if user == 0.
1041 static int sh_mobile_release(struct fb_info *info, int user)
1043 struct sh_mobile_lcdc_chan *ch = info->par;
1045 mutex_lock(&ch->open_lock);
1046 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1050 /* Nothing to reconfigure, when called from fbcon */
1053 sh_mobile_fb_reconfig(info);
1057 mutex_unlock(&ch->open_lock);
1062 static int sh_mobile_open(struct fb_info *info, int user)
1064 struct sh_mobile_lcdc_chan *ch = info->par;
1066 mutex_lock(&ch->open_lock);
1069 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1070 mutex_unlock(&ch->open_lock);
1075 static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1077 struct sh_mobile_lcdc_chan *ch = info->par;
1078 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1080 if (var->xres > MAX_XRES || var->yres > MAX_YRES ||
1081 var->xres * var->yres * (ch->cfg.bpp / 8) * 2 > info->fix.smem_len) {
1082 dev_warn(info->dev, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
1083 var->left_margin, var->xres, var->right_margin, var->hsync_len,
1084 var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
1085 PICOS2KHZ(var->pixclock));
1089 /* only accept the forced_bpp for dual channel configurations */
1090 if (p->forced_bpp && p->forced_bpp != var->bits_per_pixel)
1093 switch (var->bits_per_pixel) {
1094 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1095 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1096 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1106 * Screen blanking. Behavior is as follows:
1107 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1108 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1111 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1113 static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
1115 struct sh_mobile_lcdc_chan *ch = info->par;
1116 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1118 /* blank the screen? */
1119 if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
1120 struct fb_fillrect rect = {
1121 .width = info->var.xres,
1122 .height = info->var.yres,
1124 sh_mobile_lcdc_fillrect(info, &rect);
1126 /* turn clocks on? */
1127 if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
1128 sh_mobile_lcdc_clk_on(p);
1130 /* turn clocks off? */
1131 if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
1132 /* make sure the screen is updated with the black fill before
1133 * switching the clocks off. one vsync is not enough since
1134 * blanking may occur in the middle of a refresh. deferred io
1135 * mode will reenable the clocks and update the screen in time,
1136 * so it does not need this. */
1137 if (!info->fbdefio) {
1138 sh_mobile_wait_for_vsync(info);
1139 sh_mobile_wait_for_vsync(info);
1141 sh_mobile_lcdc_clk_off(p);
1144 ch->blank_status = blank;
1148 static struct fb_ops sh_mobile_lcdc_ops = {
1149 .owner = THIS_MODULE,
1150 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
1151 .fb_read = fb_sys_read,
1152 .fb_write = fb_sys_write,
1153 .fb_fillrect = sh_mobile_lcdc_fillrect,
1154 .fb_copyarea = sh_mobile_lcdc_copyarea,
1155 .fb_imageblit = sh_mobile_lcdc_imageblit,
1156 .fb_blank = sh_mobile_lcdc_blank,
1157 .fb_pan_display = sh_mobile_fb_pan_display,
1158 .fb_ioctl = sh_mobile_ioctl,
1159 .fb_open = sh_mobile_open,
1160 .fb_release = sh_mobile_release,
1161 .fb_check_var = sh_mobile_check_var,
1164 static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
1166 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1167 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1168 int brightness = bdev->props.brightness;
1170 if (bdev->props.power != FB_BLANK_UNBLANK ||
1171 bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
1174 return cfg->set_brightness(cfg->board_data, brightness);
1177 static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
1179 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1180 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1182 return cfg->get_brightness(cfg->board_data);
1185 static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
1186 struct fb_info *info)
1188 return (info->bl_dev == bdev);
1191 static struct backlight_ops sh_mobile_lcdc_bl_ops = {
1192 .options = BL_CORE_SUSPENDRESUME,
1193 .update_status = sh_mobile_lcdc_update_bl,
1194 .get_brightness = sh_mobile_lcdc_get_brightness,
1195 .check_fb = sh_mobile_lcdc_check_fb,
1198 static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
1199 struct sh_mobile_lcdc_chan *ch)
1201 struct backlight_device *bl;
1203 bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch,
1204 &sh_mobile_lcdc_bl_ops, NULL);
1206 dev_err(parent, "unable to register backlight device: %ld\n",
1211 bl->props.max_brightness = ch->cfg.bl_info.max_brightness;
1212 bl->props.brightness = bl->props.max_brightness;
1213 backlight_update_status(bl);
1218 static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
1220 backlight_device_unregister(bdev);
1223 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp,
1231 var->bits_per_pixel = bpp;
1232 var->nonstd = nonstd;
1240 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1241 var->red.offset = 11;
1242 var->red.length = 5;
1243 var->green.offset = 5;
1244 var->green.length = 6;
1245 var->blue.offset = 0;
1246 var->blue.length = 5;
1247 var->transp.offset = 0;
1248 var->transp.length = 0;
1251 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1252 var->red.offset = 16;
1253 var->red.length = 8;
1254 var->green.offset = 8;
1255 var->green.length = 8;
1256 var->blue.offset = 0;
1257 var->blue.length = 8;
1258 var->transp.offset = 0;
1259 var->transp.length = 0;
1262 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1263 var->red.offset = 16;
1264 var->red.length = 8;
1265 var->green.offset = 8;
1266 var->green.length = 8;
1267 var->blue.offset = 0;
1268 var->blue.length = 8;
1269 var->transp.offset = 24;
1270 var->transp.length = 8;
1275 var->bits_per_pixel = bpp;
1276 var->red.msb_right = 0;
1277 var->green.msb_right = 0;
1278 var->blue.msb_right = 0;
1279 var->transp.msb_right = 0;
1283 static int sh_mobile_lcdc_suspend(struct device *dev)
1285 struct platform_device *pdev = to_platform_device(dev);
1287 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
1291 static int sh_mobile_lcdc_resume(struct device *dev)
1293 struct platform_device *pdev = to_platform_device(dev);
1295 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
1298 static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
1300 struct platform_device *pdev = to_platform_device(dev);
1301 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1302 struct sh_mobile_lcdc_chan *ch;
1305 /* save per-channel registers */
1306 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1310 for (n = 0; n < NR_CH_REGS; n++)
1311 ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
1314 /* save shared registers */
1315 for (n = 0; n < NR_SHARED_REGS; n++)
1316 p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
1318 /* turn off LCDC hardware */
1319 lcdc_write(p, _LDCNT1R, 0);
1323 static int sh_mobile_lcdc_runtime_resume(struct device *dev)
1325 struct platform_device *pdev = to_platform_device(dev);
1326 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1327 struct sh_mobile_lcdc_chan *ch;
1330 /* restore per-channel registers */
1331 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1335 for (n = 0; n < NR_CH_REGS; n++)
1336 lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
1339 /* restore shared registers */
1340 for (n = 0; n < NR_SHARED_REGS; n++)
1341 lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
1346 static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
1347 .suspend = sh_mobile_lcdc_suspend,
1348 .resume = sh_mobile_lcdc_resume,
1349 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
1350 .runtime_resume = sh_mobile_lcdc_runtime_resume,
1353 /* locking: called with info->lock held */
1354 static int sh_mobile_lcdc_notify(struct notifier_block *nb,
1355 unsigned long action, void *data)
1357 struct fb_event *event = data;
1358 struct fb_info *info = event->info;
1359 struct sh_mobile_lcdc_chan *ch = info->par;
1360 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
1362 if (&ch->lcdc->notifier != nb)
1365 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
1366 __func__, action, event->data);
1369 case FB_EVENT_SUSPEND:
1370 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
1371 board_cfg->display_off(board_cfg->board_data);
1372 module_put(board_cfg->owner);
1374 sh_mobile_lcdc_stop(ch->lcdc);
1376 case FB_EVENT_RESUME:
1377 mutex_lock(&ch->open_lock);
1378 sh_mobile_fb_reconfig(info);
1379 mutex_unlock(&ch->open_lock);
1381 /* HDMI must be enabled before LCDC configuration */
1382 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
1383 board_cfg->display_on(board_cfg->board_data, info);
1384 module_put(board_cfg->owner);
1387 sh_mobile_lcdc_start(ch->lcdc);
1393 static int sh_mobile_lcdc_remove(struct platform_device *pdev);
1395 static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1397 struct fb_info *info;
1398 struct sh_mobile_lcdc_priv *priv;
1399 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
1400 struct resource *res;
1406 dev_err(&pdev->dev, "no platform data defined\n");
1410 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1411 i = platform_get_irq(pdev, 0);
1412 if (!res || i < 0) {
1413 dev_err(&pdev->dev, "cannot get platform resources\n");
1417 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1419 dev_err(&pdev->dev, "cannot allocate device data\n");
1423 platform_set_drvdata(pdev, priv);
1425 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
1426 dev_name(&pdev->dev), priv);
1428 dev_err(&pdev->dev, "unable to request irq\n");
1433 atomic_set(&priv->hw_usecnt, -1);
1436 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
1437 struct sh_mobile_lcdc_chan *ch = priv->ch + j;
1440 memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
1442 error = sh_mobile_lcdc_check_interface(ch);
1444 dev_err(&pdev->dev, "unsupported interface type\n");
1447 init_waitqueue_head(&ch->frame_end_wait);
1448 init_completion(&ch->vsync_completion);
1451 /* probe the backlight is there is one defined */
1452 if (ch->cfg.bl_info.max_brightness)
1453 ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
1455 switch (pdata->ch[i].chan) {
1456 case LCDC_CHAN_MAINLCD:
1457 ch->enabled = LDCNT2R_ME;
1458 ch->reg_offs = lcdc_offs_mainlcd;
1461 case LCDC_CHAN_SUBLCD:
1462 ch->enabled = LDCNT2R_SE;
1463 ch->reg_offs = lcdc_offs_sublcd;
1470 dev_err(&pdev->dev, "no channels defined\n");
1475 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1477 priv->forced_bpp = pdata->ch[0].bpp;
1479 priv->base = ioremap_nocache(res->start, resource_size(res));
1483 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
1485 dev_err(&pdev->dev, "unable to setup clocks\n");
1489 priv->meram_dev = pdata->meram_dev;
1491 for (i = 0; i < j; i++) {
1492 struct fb_var_screeninfo *var;
1493 const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
1494 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1495 struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
1496 const struct fb_videomode *mode = cfg->lcd_cfg;
1497 unsigned long max_size = 0;
1501 ch->info = framebuffer_alloc(0, &pdev->dev);
1503 dev_err(&pdev->dev, "unable to allocate fb_info\n");
1510 info->fbops = &sh_mobile_lcdc_ops;
1513 mutex_init(&ch->open_lock);
1515 for (k = 0, lcd_cfg = mode;
1516 k < cfg->num_cfg && lcd_cfg;
1518 unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
1519 /* NV12 buffers must have even number of lines */
1520 if ((cfg->nonstd) && cfg->bpp == 12 &&
1521 (lcd_cfg->yres & 0x1)) {
1522 dev_err(&pdev->dev, "yres must be multiple of 2"
1523 " for YCbCr420 mode.\n");
1528 if (size > max_size) {
1535 max_size = MAX_XRES * MAX_YRES;
1537 dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
1538 max_cfg->xres, max_cfg->yres);
1540 info->fix = sh_mobile_lcdc_fix;
1541 info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
1543 /* Only pan in 2 line steps for NV12 */
1544 if (cfg->nonstd && cfg->bpp == 12)
1545 info->fix.ypanstep = 2;
1548 mode = &default_720p;
1551 num_cfg = cfg->num_cfg;
1554 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
1556 fb_videomode_to_var(var, mode);
1557 var->width = cfg->lcd_size_cfg.width;
1558 var->height = cfg->lcd_size_cfg.height;
1559 /* Default Y virtual resolution is 2x panel size */
1560 var->yres_virtual = var->yres * 2;
1561 var->activate = FB_ACTIVATE_NOW;
1563 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp, cfg->nonstd);
1567 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
1568 &ch->dma_handle, GFP_KERNEL);
1570 dev_err(&pdev->dev, "unable to allocate buffer\n");
1575 info->pseudo_palette = &ch->pseudo_palette;
1576 info->flags = FBINFO_FLAG_DEFAULT;
1578 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
1580 dev_err(&pdev->dev, "unable to allocate cmap\n");
1581 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1582 buf, ch->dma_handle);
1586 info->fix.smem_start = ch->dma_handle;
1588 info->fix.line_length = var->xres;
1590 info->fix.line_length = var->xres * (cfg->bpp / 8);
1592 info->screen_base = buf;
1593 info->device = &pdev->dev;
1594 ch->display_var = *var;
1600 error = sh_mobile_lcdc_start(priv);
1602 dev_err(&pdev->dev, "unable to start hardware\n");
1606 for (i = 0; i < j; i++) {
1607 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1611 if (info->fbdefio) {
1612 ch->sglist = vmalloc(sizeof(struct scatterlist) *
1613 info->fix.smem_len >> PAGE_SHIFT);
1615 dev_err(&pdev->dev, "cannot allocate sglist\n");
1620 info->bl_dev = ch->bl;
1622 error = register_framebuffer(info);
1627 "registered %s/%s as %dx%d %dbpp.\n",
1629 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
1630 "mainlcd" : "sublcd",
1631 info->var.xres, info->var.yres,
1634 /* deferred io mode: disable clock to save power */
1635 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
1636 sh_mobile_lcdc_clk_off(priv);
1639 /* Failure ignored */
1640 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1641 fb_register_client(&priv->notifier);
1645 sh_mobile_lcdc_remove(pdev);
1650 static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1652 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
1653 struct fb_info *info;
1656 fb_unregister_client(&priv->notifier);
1658 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
1659 if (priv->ch[i].info && priv->ch[i].info->dev)
1660 unregister_framebuffer(priv->ch[i].info);
1662 sh_mobile_lcdc_stop(priv);
1664 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1665 info = priv->ch[i].info;
1667 if (!info || !info->device)
1670 if (priv->ch[i].sglist)
1671 vfree(priv->ch[i].sglist);
1673 if (info->screen_base)
1674 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1676 priv->ch[i].dma_handle);
1677 fb_dealloc_cmap(&info->cmap);
1678 framebuffer_release(info);
1681 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1683 sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
1687 clk_put(priv->dot_clk);
1690 pm_runtime_disable(priv->dev);
1693 iounmap(priv->base);
1696 free_irq(priv->irq, priv);
1701 static struct platform_driver sh_mobile_lcdc_driver = {
1703 .name = "sh_mobile_lcdc_fb",
1704 .owner = THIS_MODULE,
1705 .pm = &sh_mobile_lcdc_dev_pm_ops,
1707 .probe = sh_mobile_lcdc_probe,
1708 .remove = sh_mobile_lcdc_remove,
1711 static int __init sh_mobile_lcdc_init(void)
1713 return platform_driver_register(&sh_mobile_lcdc_driver);
1716 static void __exit sh_mobile_lcdc_exit(void)
1718 platform_driver_unregister(&sh_mobile_lcdc_driver);
1721 module_init(sh_mobile_lcdc_init);
1722 module_exit(sh_mobile_lcdc_exit);
1724 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1725 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1726 MODULE_LICENSE("GPL v2");