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;
322 unsigned long ldintr;
326 /* acknowledge interrupt */
327 ldintr = tmp = lcdc_read(priv, _LDINTR);
329 * disable further VSYNC End IRQs, preserve all other enabled IRQs,
330 * write 0 to bits 0-6 to ack all triggered IRQs.
332 tmp &= ~LDINTR_STATUS_MASK & ~LDINTR_VEE;
333 lcdc_write(priv, _LDINTR, tmp);
335 /* figure out if this interrupt is for main or sub lcd */
336 is_sub = (lcdc_read(priv, _LDSR) & LDSR_MSS) ? 1 : 0;
338 /* wake up channel and disable clocks */
339 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
346 if (ldintr & LDINTR_FS) {
347 if (is_sub == lcdc_chan_is_sublcd(ch)) {
349 wake_up(&ch->frame_end_wait);
351 sh_mobile_lcdc_clk_off(priv);
356 if (ldintr & LDINTR_VES)
357 complete(&ch->vsync_completion);
363 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
366 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
369 /* start or stop the lcdc */
371 lcdc_write(priv, _LDCNT2R, tmp | LDCNT2R_DO);
373 lcdc_write(priv, _LDCNT2R, tmp & ~LDCNT2R_DO);
375 /* wait until power is applied/stopped on all channels */
376 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
377 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
379 tmp = lcdc_read_chan(&priv->ch[k], LDPMR)
381 if (start && tmp == LDPMR_LPS)
383 if (!start && tmp == 0)
389 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
392 static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan *ch)
394 struct fb_var_screeninfo *var = &ch->info->var, *display_var = &ch->display_var;
395 unsigned long h_total, hsync_pos, display_h_total;
398 tmp = ch->ldmt1r_value;
399 tmp |= (var->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : LDMT1R_VPOL;
400 tmp |= (var->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : LDMT1R_HPOL;
401 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? LDMT1R_DWPOL : 0;
402 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? LDMT1R_DIPOL : 0;
403 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? LDMT1R_DAPOL : 0;
404 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? LDMT1R_HSCNT : 0;
405 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? LDMT1R_DWCNT : 0;
406 lcdc_write_chan(ch, LDMT1R, tmp);
409 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
410 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
412 /* horizontal configuration */
413 h_total = display_var->xres + display_var->hsync_len +
414 display_var->left_margin + display_var->right_margin;
415 tmp = h_total / 8; /* HTCN */
416 tmp |= (min(display_var->xres, var->xres) / 8) << 16; /* HDCN */
417 lcdc_write_chan(ch, LDHCNR, tmp);
419 hsync_pos = display_var->xres + display_var->right_margin;
420 tmp = hsync_pos / 8; /* HSYNP */
421 tmp |= (display_var->hsync_len / 8) << 16; /* HSYNW */
422 lcdc_write_chan(ch, LDHSYNR, tmp);
424 /* vertical configuration */
425 tmp = display_var->yres + display_var->vsync_len +
426 display_var->upper_margin + display_var->lower_margin; /* VTLN */
427 tmp |= min(display_var->yres, var->yres) << 16; /* VDLN */
428 lcdc_write_chan(ch, LDVLNR, tmp);
430 tmp = display_var->yres + display_var->lower_margin; /* VSYNP */
431 tmp |= display_var->vsync_len << 16; /* VSYNW */
432 lcdc_write_chan(ch, LDVSYNR, tmp);
434 /* Adjust horizontal synchronisation for HDMI */
435 display_h_total = display_var->xres + display_var->hsync_len +
436 display_var->left_margin + display_var->right_margin;
437 tmp = ((display_var->xres & 7) << 24) |
438 ((display_h_total & 7) << 16) |
439 ((display_var->hsync_len & 7) << 8) |
441 lcdc_write_chan(ch, LDHAJR, tmp);
444 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
446 struct sh_mobile_lcdc_chan *ch;
447 struct sh_mobile_lcdc_board_cfg *board_cfg;
450 unsigned long ldddsr;
453 /* enable clocks before accessing the hardware */
454 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
455 if (priv->ch[k].enabled) {
456 sh_mobile_lcdc_clk_on(priv);
458 bpp = priv->ch[k].info->var.bits_per_pixel;
463 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LDCNT2R_BR);
464 lcdc_wait_bit(priv, _LDCNT2R, LDCNT2R_BR, 0);
466 /* enable LCDC channels */
467 tmp = lcdc_read(priv, _LDCNT2R);
468 tmp |= priv->ch[0].enabled;
469 tmp |= priv->ch[1].enabled;
470 lcdc_write(priv, _LDCNT2R, tmp);
472 /* read data from external memory, avoid using the BEU for now */
473 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~LDCNT2R_MD);
475 /* stop the lcdc first */
476 sh_mobile_lcdc_start_stop(priv, 0);
478 /* configure clocks */
480 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
483 if (!priv->ch[k].enabled)
486 m = ch->cfg.clock_divider;
492 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
494 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
495 lcdc_write_chan(ch, LDDCKPAT1R, 0);
496 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
499 lcdc_write(priv, _LDDCKR, tmp);
501 /* start dotclock again */
502 lcdc_write(priv, _LDDCKSTPR, 0);
503 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
505 /* interrupts are disabled to begin with */
506 lcdc_write(priv, _LDINTR, 0);
508 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
514 sh_mobile_lcdc_geometry(ch);
517 lcdc_write_chan(ch, LDPMR, 0);
519 board_cfg = &ch->cfg.board_cfg;
520 if (board_cfg->setup_sys) {
521 ret = board_cfg->setup_sys(board_cfg->board_data,
522 ch, &sh_mobile_lcdc_sys_bus_ops);
528 /* word and long word swap */
529 ldddsr = lcdc_read(priv, _LDDDSR);
530 if (priv->ch[0].info->var.nonstd)
531 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
535 ldddsr |= LDDDSR_LS | LDDDSR_WS;
538 ldddsr |= LDDDSR_LS | LDDDSR_WS | LDDDSR_BS;
545 lcdc_write(priv, _LDDDSR, ldddsr);
547 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
548 unsigned long base_addr_y;
549 unsigned long base_addr_c = 0;
553 if (!priv->ch[k].enabled)
556 /* set bpp format in PKF[4:0] */
557 tmp = lcdc_read_chan(ch, LDDFR);
558 tmp &= ~(LDDFR_CF0 | LDDFR_CC | LDDFR_YF_MASK | LDDFR_PKF_MASK);
559 if (ch->info->var.nonstd) {
560 tmp |= (ch->info->var.nonstd << 16);
561 switch (ch->info->var.bits_per_pixel) {
572 switch (ch->info->var.bits_per_pixel) {
574 tmp |= LDDFR_PKF_RGB16;
577 tmp |= LDDFR_PKF_RGB24;
580 tmp |= LDDFR_PKF_ARGB32;
584 lcdc_write_chan(ch, LDDFR, tmp);
586 base_addr_y = ch->info->fix.smem_start;
587 base_addr_c = base_addr_y +
589 ch->info->var.yres_virtual;
590 pitch = ch->info->fix.line_length;
592 /* test if we can enable meram */
593 if (ch->cfg.meram_cfg && priv->meram_dev &&
594 priv->meram_dev->ops) {
595 struct sh_mobile_meram_cfg *cfg;
596 struct sh_mobile_meram_info *mdev;
597 unsigned long icb_addr_y, icb_addr_c;
601 cfg = ch->cfg.meram_cfg;
602 mdev = priv->meram_dev;
603 /* we need to de-init configured ICBs before we
604 * we can re-initialize them.
606 if (ch->meram_enabled)
607 mdev->ops->meram_unregister(mdev, cfg);
609 ch->meram_enabled = 0;
611 if (ch->info->var.nonstd) {
612 if (ch->info->var.bits_per_pixel == 24)
613 pf = SH_MOBILE_MERAM_PF_NV24;
615 pf = SH_MOBILE_MERAM_PF_NV;
617 pf = SH_MOBILE_MERAM_PF_RGB;
620 ret = mdev->ops->meram_register(mdev, cfg, pitch,
629 /* set LDSA1R value */
630 base_addr_y = icb_addr_y;
633 /* set LDSA2R value if required */
635 base_addr_c = icb_addr_c;
637 ch->meram_enabled = 1;
641 /* point out our frame buffer */
642 lcdc_write_chan(ch, LDSA1R, base_addr_y);
643 if (ch->info->var.nonstd)
644 lcdc_write_chan(ch, LDSA2R, base_addr_c);
647 lcdc_write_chan(ch, LDMLSR, pitch);
649 /* setup deferred io if SYS bus */
650 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
651 if (ch->ldmt1r_value & LDMT1R_IFM && tmp) {
652 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
653 ch->defio.delay = msecs_to_jiffies(tmp);
654 ch->info->fbdefio = &ch->defio;
655 fb_deferred_io_init(ch->info);
658 lcdc_write_chan(ch, LDSM1R, LDSM1R_OS);
660 /* enable "Frame End Interrupt Enable" bit */
661 lcdc_write(priv, _LDINTR, LDINTR_FE);
664 /* continuous read mode */
665 lcdc_write_chan(ch, LDSM1R, 0);
670 lcdc_write(priv, _LDCNT1R, LDCNT1R_DE);
673 sh_mobile_lcdc_start_stop(priv, 1);
676 /* tell the board code to enable the panel */
677 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
682 board_cfg = &ch->cfg.board_cfg;
683 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
684 board_cfg->display_on(board_cfg->board_data, ch->info);
685 module_put(board_cfg->owner);
689 ch->bl->props.power = FB_BLANK_UNBLANK;
690 backlight_update_status(ch->bl);
697 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
699 struct sh_mobile_lcdc_chan *ch;
700 struct sh_mobile_lcdc_board_cfg *board_cfg;
703 /* clean up deferred io and ask board code to disable panel */
704 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
710 * flush frame, and wait for frame end interrupt
711 * clean up deferred io and enable clock
713 if (ch->info && ch->info->fbdefio) {
715 schedule_delayed_work(&ch->info->deferred_work, 0);
716 wait_event(ch->frame_end_wait, ch->frame_end);
717 fb_deferred_io_cleanup(ch->info);
718 ch->info->fbdefio = NULL;
719 sh_mobile_lcdc_clk_on(priv);
723 ch->bl->props.power = FB_BLANK_POWERDOWN;
724 backlight_update_status(ch->bl);
727 board_cfg = &ch->cfg.board_cfg;
728 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
729 board_cfg->display_off(board_cfg->board_data);
730 module_put(board_cfg->owner);
733 /* disable the meram */
734 if (ch->meram_enabled) {
735 struct sh_mobile_meram_cfg *cfg;
736 struct sh_mobile_meram_info *mdev;
737 cfg = ch->cfg.meram_cfg;
738 mdev = priv->meram_dev;
739 mdev->ops->meram_unregister(mdev, cfg);
740 ch->meram_enabled = 0;
747 sh_mobile_lcdc_start_stop(priv, 0);
752 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
753 if (priv->ch[k].enabled)
754 sh_mobile_lcdc_clk_off(priv);
757 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
759 int interface_type = ch->cfg.interface_type;
761 switch (interface_type) {
785 /* SUBLCD only supports SYS interface */
786 if (lcdc_chan_is_sublcd(ch)) {
787 if (!(interface_type & LDMT1R_IFM))
790 interface_type &= ~LDMT1R_IFM;
793 ch->ldmt1r_value = interface_type;
797 static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
799 struct sh_mobile_lcdc_priv *priv)
803 switch (clock_source) {
806 priv->lddckr = LDDCKR_ICKSEL_BUS;
808 case LCDC_CLK_PERIPHERAL:
809 str = "peripheral_clk";
810 priv->lddckr = LDDCKR_ICKSEL_MIPI;
812 case LCDC_CLK_EXTERNAL:
814 priv->lddckr = LDDCKR_ICKSEL_HDMI;
821 priv->dot_clk = clk_get(&pdev->dev, str);
822 if (IS_ERR(priv->dot_clk)) {
823 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
824 return PTR_ERR(priv->dot_clk);
828 /* Runtime PM support involves two step for this driver:
829 * 1) Enable Runtime PM
830 * 2) Force Runtime PM Resume since hardware is accessed from probe()
832 priv->dev = &pdev->dev;
833 pm_runtime_enable(priv->dev);
834 pm_runtime_resume(priv->dev);
838 static int sh_mobile_lcdc_setcolreg(u_int regno,
839 u_int red, u_int green, u_int blue,
840 u_int transp, struct fb_info *info)
842 u32 *palette = info->pseudo_palette;
844 if (regno >= PALETTE_NR)
847 /* only FB_VISUAL_TRUECOLOR supported */
849 red >>= 16 - info->var.red.length;
850 green >>= 16 - info->var.green.length;
851 blue >>= 16 - info->var.blue.length;
852 transp >>= 16 - info->var.transp.length;
854 palette[regno] = (red << info->var.red.offset) |
855 (green << info->var.green.offset) |
856 (blue << info->var.blue.offset) |
857 (transp << info->var.transp.offset);
862 static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
863 .id = "SH Mobile LCDC",
864 .type = FB_TYPE_PACKED_PIXELS,
865 .visual = FB_VISUAL_TRUECOLOR,
866 .accel = FB_ACCEL_NONE,
872 static void sh_mobile_lcdc_fillrect(struct fb_info *info,
873 const struct fb_fillrect *rect)
875 sys_fillrect(info, rect);
876 sh_mobile_lcdc_deferred_io_touch(info);
879 static void sh_mobile_lcdc_copyarea(struct fb_info *info,
880 const struct fb_copyarea *area)
882 sys_copyarea(info, area);
883 sh_mobile_lcdc_deferred_io_touch(info);
886 static void sh_mobile_lcdc_imageblit(struct fb_info *info,
887 const struct fb_image *image)
889 sys_imageblit(info, image);
890 sh_mobile_lcdc_deferred_io_touch(info);
893 static int sh_mobile_fb_pan_display(struct fb_var_screeninfo *var,
894 struct fb_info *info)
896 struct sh_mobile_lcdc_chan *ch = info->par;
897 struct sh_mobile_lcdc_priv *priv = ch->lcdc;
898 unsigned long ldrcntr;
899 unsigned long new_pan_offset;
900 unsigned long base_addr_y, base_addr_c;
901 unsigned long c_offset;
904 new_pan_offset = (var->yoffset * info->fix.line_length) +
905 (var->xoffset * (info->var.bits_per_pixel / 8));
907 new_pan_offset = (var->yoffset * info->fix.line_length) +
910 if (new_pan_offset == ch->pan_offset)
911 return 0; /* No change, do nothing */
913 ldrcntr = lcdc_read(priv, _LDRCNTR);
915 /* Set the source address for the next refresh */
916 base_addr_y = ch->dma_handle + new_pan_offset;
919 c_offset = (var->yoffset *
920 info->fix.line_length *
921 (info->var.bits_per_pixel - 8)) / 8;
922 base_addr_c = ch->dma_handle + var->xres * var->yres_virtual +
925 if (info->var.bits_per_pixel == 24)
926 base_addr_c += 2 * var->xoffset;
928 base_addr_c += var->xoffset;
932 if (!ch->meram_enabled) {
933 lcdc_write_chan_mirror(ch, LDSA1R, base_addr_y);
935 lcdc_write_chan_mirror(ch, LDSA2R, base_addr_c);
937 struct sh_mobile_meram_cfg *cfg;
938 struct sh_mobile_meram_info *mdev;
939 unsigned long icb_addr_y, icb_addr_c;
942 cfg = ch->cfg.meram_cfg;
943 mdev = priv->meram_dev;
944 ret = mdev->ops->meram_update(mdev, cfg,
945 base_addr_y, base_addr_c,
946 &icb_addr_y, &icb_addr_c);
950 lcdc_write_chan_mirror(ch, LDSA1R, icb_addr_y);
952 lcdc_write_chan_mirror(ch, LDSA2R, icb_addr_c);
956 if (lcdc_chan_is_sublcd(ch))
957 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_SRS);
959 lcdc_write(ch->lcdc, _LDRCNTR, ldrcntr ^ LDRCNTR_MRS);
961 ch->pan_offset = new_pan_offset;
963 sh_mobile_lcdc_deferred_io_touch(info);
968 static int sh_mobile_wait_for_vsync(struct fb_info *info)
970 struct sh_mobile_lcdc_chan *ch = info->par;
971 unsigned long ldintr;
974 /* Enable VSync End interrupt */
975 ldintr = lcdc_read(ch->lcdc, _LDINTR);
976 ldintr |= LDINTR_VEE;
977 lcdc_write(ch->lcdc, _LDINTR, ldintr);
979 ret = wait_for_completion_interruptible_timeout(&ch->vsync_completion,
980 msecs_to_jiffies(100));
987 static int sh_mobile_ioctl(struct fb_info *info, unsigned int cmd,
993 case FBIO_WAITFORVSYNC:
994 retval = sh_mobile_wait_for_vsync(info);
998 retval = -ENOIOCTLCMD;
1004 static void sh_mobile_fb_reconfig(struct fb_info *info)
1006 struct sh_mobile_lcdc_chan *ch = info->par;
1007 struct fb_videomode mode1, mode2;
1008 struct fb_event event;
1009 int evnt = FB_EVENT_MODE_CHANGE_ALL;
1011 if (ch->use_count > 1 || (ch->use_count == 1 && !info->fbcon_par))
1012 /* More framebuffer users are active */
1015 fb_var_to_videomode(&mode1, &ch->display_var);
1016 fb_var_to_videomode(&mode2, &info->var);
1018 if (fb_mode_is_equal(&mode1, &mode2))
1021 /* Display has been re-plugged, framebuffer is free now, reconfigure */
1022 if (fb_set_var(info, &ch->display_var) < 0)
1023 /* Couldn't reconfigure, hopefully, can continue as before */
1026 if (info->var.nonstd)
1027 info->fix.line_length = mode1.xres;
1029 info->fix.line_length = mode1.xres * (ch->cfg.bpp / 8);
1032 * fb_set_var() calls the notifier change internally, only if
1033 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1034 * user event, we have to call the chain ourselves.
1037 event.data = &mode1;
1038 fb_notifier_call_chain(evnt, &event);
1042 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1043 * user == 1, or with console sem held, if user == 0.
1045 static int sh_mobile_release(struct fb_info *info, int user)
1047 struct sh_mobile_lcdc_chan *ch = info->par;
1049 mutex_lock(&ch->open_lock);
1050 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1054 /* Nothing to reconfigure, when called from fbcon */
1057 sh_mobile_fb_reconfig(info);
1061 mutex_unlock(&ch->open_lock);
1066 static int sh_mobile_open(struct fb_info *info, int user)
1068 struct sh_mobile_lcdc_chan *ch = info->par;
1070 mutex_lock(&ch->open_lock);
1073 dev_dbg(info->dev, "%s(): %d users\n", __func__, ch->use_count);
1074 mutex_unlock(&ch->open_lock);
1079 static int sh_mobile_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
1081 struct sh_mobile_lcdc_chan *ch = info->par;
1082 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1084 if (var->xres > MAX_XRES || var->yres > MAX_YRES ||
1085 var->xres * var->yres * (ch->cfg.bpp / 8) * 2 > info->fix.smem_len) {
1086 dev_warn(info->dev, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
1087 var->left_margin, var->xres, var->right_margin, var->hsync_len,
1088 var->upper_margin, var->yres, var->lower_margin, var->vsync_len,
1089 PICOS2KHZ(var->pixclock));
1093 /* only accept the forced_bpp for dual channel configurations */
1094 if (p->forced_bpp && p->forced_bpp != var->bits_per_pixel)
1097 switch (var->bits_per_pixel) {
1098 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1099 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1100 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1110 * Screen blanking. Behavior is as follows:
1111 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1112 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1115 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1117 static int sh_mobile_lcdc_blank(int blank, struct fb_info *info)
1119 struct sh_mobile_lcdc_chan *ch = info->par;
1120 struct sh_mobile_lcdc_priv *p = ch->lcdc;
1122 /* blank the screen? */
1123 if (blank > FB_BLANK_UNBLANK && ch->blank_status == FB_BLANK_UNBLANK) {
1124 struct fb_fillrect rect = {
1125 .width = info->var.xres,
1126 .height = info->var.yres,
1128 sh_mobile_lcdc_fillrect(info, &rect);
1130 /* turn clocks on? */
1131 if (blank <= FB_BLANK_NORMAL && ch->blank_status > FB_BLANK_NORMAL) {
1132 sh_mobile_lcdc_clk_on(p);
1134 /* turn clocks off? */
1135 if (blank > FB_BLANK_NORMAL && ch->blank_status <= FB_BLANK_NORMAL) {
1136 /* make sure the screen is updated with the black fill before
1137 * switching the clocks off. one vsync is not enough since
1138 * blanking may occur in the middle of a refresh. deferred io
1139 * mode will reenable the clocks and update the screen in time,
1140 * so it does not need this. */
1141 if (!info->fbdefio) {
1142 sh_mobile_wait_for_vsync(info);
1143 sh_mobile_wait_for_vsync(info);
1145 sh_mobile_lcdc_clk_off(p);
1148 ch->blank_status = blank;
1152 static struct fb_ops sh_mobile_lcdc_ops = {
1153 .owner = THIS_MODULE,
1154 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
1155 .fb_read = fb_sys_read,
1156 .fb_write = fb_sys_write,
1157 .fb_fillrect = sh_mobile_lcdc_fillrect,
1158 .fb_copyarea = sh_mobile_lcdc_copyarea,
1159 .fb_imageblit = sh_mobile_lcdc_imageblit,
1160 .fb_blank = sh_mobile_lcdc_blank,
1161 .fb_pan_display = sh_mobile_fb_pan_display,
1162 .fb_ioctl = sh_mobile_ioctl,
1163 .fb_open = sh_mobile_open,
1164 .fb_release = sh_mobile_release,
1165 .fb_check_var = sh_mobile_check_var,
1168 static int sh_mobile_lcdc_update_bl(struct backlight_device *bdev)
1170 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1171 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1172 int brightness = bdev->props.brightness;
1174 if (bdev->props.power != FB_BLANK_UNBLANK ||
1175 bdev->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
1178 return cfg->set_brightness(cfg->board_data, brightness);
1181 static int sh_mobile_lcdc_get_brightness(struct backlight_device *bdev)
1183 struct sh_mobile_lcdc_chan *ch = bl_get_data(bdev);
1184 struct sh_mobile_lcdc_board_cfg *cfg = &ch->cfg.board_cfg;
1186 return cfg->get_brightness(cfg->board_data);
1189 static int sh_mobile_lcdc_check_fb(struct backlight_device *bdev,
1190 struct fb_info *info)
1192 return (info->bl_dev == bdev);
1195 static struct backlight_ops sh_mobile_lcdc_bl_ops = {
1196 .options = BL_CORE_SUSPENDRESUME,
1197 .update_status = sh_mobile_lcdc_update_bl,
1198 .get_brightness = sh_mobile_lcdc_get_brightness,
1199 .check_fb = sh_mobile_lcdc_check_fb,
1202 static struct backlight_device *sh_mobile_lcdc_bl_probe(struct device *parent,
1203 struct sh_mobile_lcdc_chan *ch)
1205 struct backlight_device *bl;
1207 bl = backlight_device_register(ch->cfg.bl_info.name, parent, ch,
1208 &sh_mobile_lcdc_bl_ops, NULL);
1210 dev_err(parent, "unable to register backlight device: %ld\n",
1215 bl->props.max_brightness = ch->cfg.bl_info.max_brightness;
1216 bl->props.brightness = bl->props.max_brightness;
1217 backlight_update_status(bl);
1222 static void sh_mobile_lcdc_bl_remove(struct backlight_device *bdev)
1224 backlight_device_unregister(bdev);
1227 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp,
1235 var->bits_per_pixel = bpp;
1236 var->nonstd = nonstd;
1244 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1245 var->red.offset = 11;
1246 var->red.length = 5;
1247 var->green.offset = 5;
1248 var->green.length = 6;
1249 var->blue.offset = 0;
1250 var->blue.length = 5;
1251 var->transp.offset = 0;
1252 var->transp.length = 0;
1255 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1256 var->red.offset = 16;
1257 var->red.length = 8;
1258 var->green.offset = 8;
1259 var->green.length = 8;
1260 var->blue.offset = 0;
1261 var->blue.length = 8;
1262 var->transp.offset = 0;
1263 var->transp.length = 0;
1266 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1267 var->red.offset = 16;
1268 var->red.length = 8;
1269 var->green.offset = 8;
1270 var->green.length = 8;
1271 var->blue.offset = 0;
1272 var->blue.length = 8;
1273 var->transp.offset = 24;
1274 var->transp.length = 8;
1279 var->bits_per_pixel = bpp;
1280 var->red.msb_right = 0;
1281 var->green.msb_right = 0;
1282 var->blue.msb_right = 0;
1283 var->transp.msb_right = 0;
1287 static int sh_mobile_lcdc_suspend(struct device *dev)
1289 struct platform_device *pdev = to_platform_device(dev);
1291 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
1295 static int sh_mobile_lcdc_resume(struct device *dev)
1297 struct platform_device *pdev = to_platform_device(dev);
1299 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
1302 static int sh_mobile_lcdc_runtime_suspend(struct device *dev)
1304 struct platform_device *pdev = to_platform_device(dev);
1305 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1306 struct sh_mobile_lcdc_chan *ch;
1309 /* save per-channel registers */
1310 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1314 for (n = 0; n < NR_CH_REGS; n++)
1315 ch->saved_ch_regs[n] = lcdc_read_chan(ch, n);
1318 /* save shared registers */
1319 for (n = 0; n < NR_SHARED_REGS; n++)
1320 p->saved_shared_regs[n] = lcdc_read(p, lcdc_shared_regs[n]);
1322 /* turn off LCDC hardware */
1323 lcdc_write(p, _LDCNT1R, 0);
1327 static int sh_mobile_lcdc_runtime_resume(struct device *dev)
1329 struct platform_device *pdev = to_platform_device(dev);
1330 struct sh_mobile_lcdc_priv *p = platform_get_drvdata(pdev);
1331 struct sh_mobile_lcdc_chan *ch;
1334 /* restore per-channel registers */
1335 for (k = 0; k < ARRAY_SIZE(p->ch); k++) {
1339 for (n = 0; n < NR_CH_REGS; n++)
1340 lcdc_write_chan(ch, n, ch->saved_ch_regs[n]);
1343 /* restore shared registers */
1344 for (n = 0; n < NR_SHARED_REGS; n++)
1345 lcdc_write(p, lcdc_shared_regs[n], p->saved_shared_regs[n]);
1350 static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
1351 .suspend = sh_mobile_lcdc_suspend,
1352 .resume = sh_mobile_lcdc_resume,
1353 .runtime_suspend = sh_mobile_lcdc_runtime_suspend,
1354 .runtime_resume = sh_mobile_lcdc_runtime_resume,
1357 /* locking: called with info->lock held */
1358 static int sh_mobile_lcdc_notify(struct notifier_block *nb,
1359 unsigned long action, void *data)
1361 struct fb_event *event = data;
1362 struct fb_info *info = event->info;
1363 struct sh_mobile_lcdc_chan *ch = info->par;
1364 struct sh_mobile_lcdc_board_cfg *board_cfg = &ch->cfg.board_cfg;
1366 if (&ch->lcdc->notifier != nb)
1369 dev_dbg(info->dev, "%s(): action = %lu, data = %p\n",
1370 __func__, action, event->data);
1373 case FB_EVENT_SUSPEND:
1374 if (board_cfg->display_off && try_module_get(board_cfg->owner)) {
1375 board_cfg->display_off(board_cfg->board_data);
1376 module_put(board_cfg->owner);
1378 sh_mobile_lcdc_stop(ch->lcdc);
1380 case FB_EVENT_RESUME:
1381 mutex_lock(&ch->open_lock);
1382 sh_mobile_fb_reconfig(info);
1383 mutex_unlock(&ch->open_lock);
1385 /* HDMI must be enabled before LCDC configuration */
1386 if (board_cfg->display_on && try_module_get(board_cfg->owner)) {
1387 board_cfg->display_on(board_cfg->board_data, info);
1388 module_put(board_cfg->owner);
1391 sh_mobile_lcdc_start(ch->lcdc);
1397 static int sh_mobile_lcdc_remove(struct platform_device *pdev);
1399 static int __devinit sh_mobile_lcdc_probe(struct platform_device *pdev)
1401 struct fb_info *info;
1402 struct sh_mobile_lcdc_priv *priv;
1403 struct sh_mobile_lcdc_info *pdata = pdev->dev.platform_data;
1404 struct resource *res;
1410 dev_err(&pdev->dev, "no platform data defined\n");
1414 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1415 i = platform_get_irq(pdev, 0);
1416 if (!res || i < 0) {
1417 dev_err(&pdev->dev, "cannot get platform resources\n");
1421 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1423 dev_err(&pdev->dev, "cannot allocate device data\n");
1427 platform_set_drvdata(pdev, priv);
1429 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
1430 dev_name(&pdev->dev), priv);
1432 dev_err(&pdev->dev, "unable to request irq\n");
1437 atomic_set(&priv->hw_usecnt, -1);
1440 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
1441 struct sh_mobile_lcdc_chan *ch = priv->ch + j;
1444 memcpy(&ch->cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
1446 error = sh_mobile_lcdc_check_interface(ch);
1448 dev_err(&pdev->dev, "unsupported interface type\n");
1451 init_waitqueue_head(&ch->frame_end_wait);
1452 init_completion(&ch->vsync_completion);
1455 /* probe the backlight is there is one defined */
1456 if (ch->cfg.bl_info.max_brightness)
1457 ch->bl = sh_mobile_lcdc_bl_probe(&pdev->dev, ch);
1459 switch (pdata->ch[i].chan) {
1460 case LCDC_CHAN_MAINLCD:
1461 ch->enabled = LDCNT2R_ME;
1462 ch->reg_offs = lcdc_offs_mainlcd;
1465 case LCDC_CHAN_SUBLCD:
1466 ch->enabled = LDCNT2R_SE;
1467 ch->reg_offs = lcdc_offs_sublcd;
1474 dev_err(&pdev->dev, "no channels defined\n");
1479 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1481 priv->forced_bpp = pdata->ch[0].bpp;
1483 priv->base = ioremap_nocache(res->start, resource_size(res));
1487 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
1489 dev_err(&pdev->dev, "unable to setup clocks\n");
1493 priv->meram_dev = pdata->meram_dev;
1495 for (i = 0; i < j; i++) {
1496 struct fb_var_screeninfo *var;
1497 const struct fb_videomode *lcd_cfg, *max_cfg = NULL;
1498 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1499 struct sh_mobile_lcdc_chan_cfg *cfg = &ch->cfg;
1500 const struct fb_videomode *mode = cfg->lcd_cfg;
1501 unsigned long max_size = 0;
1505 ch->info = framebuffer_alloc(0, &pdev->dev);
1507 dev_err(&pdev->dev, "unable to allocate fb_info\n");
1514 info->fbops = &sh_mobile_lcdc_ops;
1517 mutex_init(&ch->open_lock);
1519 for (k = 0, lcd_cfg = mode;
1520 k < cfg->num_cfg && lcd_cfg;
1522 unsigned long size = lcd_cfg->yres * lcd_cfg->xres;
1523 /* NV12 buffers must have even number of lines */
1524 if ((cfg->nonstd) && cfg->bpp == 12 &&
1525 (lcd_cfg->yres & 0x1)) {
1526 dev_err(&pdev->dev, "yres must be multiple of 2"
1527 " for YCbCr420 mode.\n");
1532 if (size > max_size) {
1539 max_size = MAX_XRES * MAX_YRES;
1541 dev_dbg(&pdev->dev, "Found largest videomode %ux%u\n",
1542 max_cfg->xres, max_cfg->yres);
1544 info->fix = sh_mobile_lcdc_fix;
1545 info->fix.smem_len = max_size * 2 * cfg->bpp / 8;
1547 /* Only pan in 2 line steps for NV12 */
1548 if (cfg->nonstd && cfg->bpp == 12)
1549 info->fix.ypanstep = 2;
1552 mode = &default_720p;
1555 num_cfg = cfg->num_cfg;
1558 fb_videomode_to_modelist(mode, num_cfg, &info->modelist);
1560 fb_videomode_to_var(var, mode);
1561 var->width = cfg->lcd_size_cfg.width;
1562 var->height = cfg->lcd_size_cfg.height;
1563 /* Default Y virtual resolution is 2x panel size */
1564 var->yres_virtual = var->yres * 2;
1565 var->activate = FB_ACTIVATE_NOW;
1567 error = sh_mobile_lcdc_set_bpp(var, cfg->bpp, cfg->nonstd);
1571 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
1572 &ch->dma_handle, GFP_KERNEL);
1574 dev_err(&pdev->dev, "unable to allocate buffer\n");
1579 info->pseudo_palette = &ch->pseudo_palette;
1580 info->flags = FBINFO_FLAG_DEFAULT;
1582 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
1584 dev_err(&pdev->dev, "unable to allocate cmap\n");
1585 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1586 buf, ch->dma_handle);
1590 info->fix.smem_start = ch->dma_handle;
1592 info->fix.line_length = var->xres;
1594 info->fix.line_length = var->xres * (cfg->bpp / 8);
1596 info->screen_base = buf;
1597 info->device = &pdev->dev;
1598 ch->display_var = *var;
1604 error = sh_mobile_lcdc_start(priv);
1606 dev_err(&pdev->dev, "unable to start hardware\n");
1610 for (i = 0; i < j; i++) {
1611 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
1615 if (info->fbdefio) {
1616 ch->sglist = vmalloc(sizeof(struct scatterlist) *
1617 info->fix.smem_len >> PAGE_SHIFT);
1619 dev_err(&pdev->dev, "cannot allocate sglist\n");
1624 info->bl_dev = ch->bl;
1626 error = register_framebuffer(info);
1631 "registered %s/%s as %dx%d %dbpp.\n",
1633 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
1634 "mainlcd" : "sublcd",
1635 info->var.xres, info->var.yres,
1638 /* deferred io mode: disable clock to save power */
1639 if (info->fbdefio || info->state == FBINFO_STATE_SUSPENDED)
1640 sh_mobile_lcdc_clk_off(priv);
1643 /* Failure ignored */
1644 priv->notifier.notifier_call = sh_mobile_lcdc_notify;
1645 fb_register_client(&priv->notifier);
1649 sh_mobile_lcdc_remove(pdev);
1654 static int sh_mobile_lcdc_remove(struct platform_device *pdev)
1656 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
1657 struct fb_info *info;
1660 fb_unregister_client(&priv->notifier);
1662 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
1663 if (priv->ch[i].info && priv->ch[i].info->dev)
1664 unregister_framebuffer(priv->ch[i].info);
1666 sh_mobile_lcdc_stop(priv);
1668 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1669 info = priv->ch[i].info;
1671 if (!info || !info->device)
1674 if (priv->ch[i].sglist)
1675 vfree(priv->ch[i].sglist);
1677 if (info->screen_base)
1678 dma_free_coherent(&pdev->dev, info->fix.smem_len,
1680 priv->ch[i].dma_handle);
1681 fb_dealloc_cmap(&info->cmap);
1682 framebuffer_release(info);
1685 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
1687 sh_mobile_lcdc_bl_remove(priv->ch[i].bl);
1691 clk_put(priv->dot_clk);
1694 pm_runtime_disable(priv->dev);
1697 iounmap(priv->base);
1700 free_irq(priv->irq, priv);
1705 static struct platform_driver sh_mobile_lcdc_driver = {
1707 .name = "sh_mobile_lcdc_fb",
1708 .owner = THIS_MODULE,
1709 .pm = &sh_mobile_lcdc_dev_pm_ops,
1711 .probe = sh_mobile_lcdc_probe,
1712 .remove = sh_mobile_lcdc_remove,
1715 static int __init sh_mobile_lcdc_init(void)
1717 return platform_driver_register(&sh_mobile_lcdc_driver);
1720 static void __exit sh_mobile_lcdc_exit(void)
1722 platform_driver_unregister(&sh_mobile_lcdc_driver);
1725 module_init(sh_mobile_lcdc_init);
1726 module_exit(sh_mobile_lcdc_exit);
1728 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1729 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1730 MODULE_LICENSE("GPL v2");