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/atomic.h>
12 #include <linux/backlight.h>
13 #include <linux/clk.h>
14 #include <linux/console.h>
15 #include <linux/dma-mapping.h>
16 #include <linux/delay.h>
17 #include <linux/gpio.h>
18 #include <linux/init.h>
19 #include <linux/interrupt.h>
20 #include <linux/ioctl.h>
21 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/platform_device.h>
25 #include <linux/pm_runtime.h>
26 #include <linux/slab.h>
27 #include <linux/videodev2.h>
28 #include <linux/vmalloc.h>
30 #include <video/sh_mobile_lcdc.h>
31 #include <video/sh_mobile_meram.h>
33 #include "sh_mobile_lcdcfb.h"
35 #define SIDE_B_OFFSET 0x1000
36 #define MIRROR_OFFSET 0x2000
41 struct sh_mobile_lcdc_priv
{
48 struct sh_mobile_lcdc_chan ch
[2];
49 struct notifier_block notifier
;
51 int forced_fourcc
; /* 2 channel LCDC must share fourcc setting */
52 struct sh_mobile_meram_info
*meram_dev
;
55 /* -----------------------------------------------------------------------------
59 static unsigned long lcdc_offs_mainlcd
[NR_CH_REGS
] = {
79 static unsigned long lcdc_offs_sublcd
[NR_CH_REGS
] = {
97 static bool banked(int reg_nr
)
117 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan
*chan
)
119 return chan
->cfg
.chan
== LCDC_CHAN_SUBLCD
;
122 static void lcdc_write_chan(struct sh_mobile_lcdc_chan
*chan
,
123 int reg_nr
, unsigned long data
)
125 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
127 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
] +
131 static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan
*chan
,
132 int reg_nr
, unsigned long data
)
134 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
] +
138 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan
*chan
,
141 return ioread32(chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
144 static void lcdc_write(struct sh_mobile_lcdc_priv
*priv
,
145 unsigned long reg_offs
, unsigned long data
)
147 iowrite32(data
, priv
->base
+ reg_offs
);
150 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv
*priv
,
151 unsigned long reg_offs
)
153 return ioread32(priv
->base
+ reg_offs
);
156 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv
*priv
,
157 unsigned long reg_offs
,
158 unsigned long mask
, unsigned long until
)
160 while ((lcdc_read(priv
, reg_offs
) & mask
) != until
)
164 /* -----------------------------------------------------------------------------
168 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
)
170 if (atomic_inc_and_test(&priv
->hw_usecnt
)) {
172 clk_enable(priv
->dot_clk
);
173 pm_runtime_get_sync(priv
->dev
);
174 if (priv
->meram_dev
&& priv
->meram_dev
->pdev
)
175 pm_runtime_get_sync(&priv
->meram_dev
->pdev
->dev
);
179 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
)
181 if (atomic_sub_return(1, &priv
->hw_usecnt
) == -1) {
182 if (priv
->meram_dev
&& priv
->meram_dev
->pdev
)
183 pm_runtime_put_sync(&priv
->meram_dev
->pdev
->dev
);
184 pm_runtime_put(priv
->dev
);
186 clk_disable(priv
->dot_clk
);
190 static int sh_mobile_lcdc_setup_clocks(struct sh_mobile_lcdc_priv
*priv
,
196 switch (clock_source
) {
199 priv
->lddckr
= LDDCKR_ICKSEL_BUS
;
201 case LCDC_CLK_PERIPHERAL
:
202 str
= "peripheral_clk";
203 priv
->lddckr
= LDDCKR_ICKSEL_MIPI
;
205 case LCDC_CLK_EXTERNAL
:
207 priv
->lddckr
= LDDCKR_ICKSEL_HDMI
;
216 clk
= clk_get(priv
->dev
, str
);
218 dev_err(priv
->dev
, "cannot get dot clock %s\n", str
);
226 /* -----------------------------------------------------------------------------
227 * Display, panel and deferred I/O
230 static void lcdc_sys_write_index(void *handle
, unsigned long data
)
232 struct sh_mobile_lcdc_chan
*ch
= handle
;
234 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| LDDWDxR_WDACT
);
235 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
236 lcdc_write(ch
->lcdc
, _LDDWAR
, LDDWAR_WA
|
237 (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
238 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
241 static void lcdc_sys_write_data(void *handle
, unsigned long data
)
243 struct sh_mobile_lcdc_chan
*ch
= handle
;
245 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| LDDWDxR_WDACT
| LDDWDxR_RSW
);
246 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
247 lcdc_write(ch
->lcdc
, _LDDWAR
, LDDWAR_WA
|
248 (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
249 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
252 static unsigned long lcdc_sys_read_data(void *handle
)
254 struct sh_mobile_lcdc_chan
*ch
= handle
;
256 lcdc_write(ch
->lcdc
, _LDDRDR
, LDDRDR_RSR
);
257 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
258 lcdc_write(ch
->lcdc
, _LDDRAR
, LDDRAR_RA
|
259 (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
261 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
263 return lcdc_read(ch
->lcdc
, _LDDRDR
) & LDDRDR_DRD_MASK
;
266 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops
= {
267 lcdc_sys_write_index
,
272 static int sh_mobile_lcdc_sginit(struct fb_info
*info
,
273 struct list_head
*pagelist
)
275 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
276 unsigned int nr_pages_max
= info
->fix
.smem_len
>> PAGE_SHIFT
;
280 sg_init_table(ch
->sglist
, nr_pages_max
);
282 list_for_each_entry(page
, pagelist
, lru
)
283 sg_set_page(&ch
->sglist
[nr_pages
++], page
, PAGE_SIZE
, 0);
288 static void sh_mobile_lcdc_deferred_io(struct fb_info
*info
,
289 struct list_head
*pagelist
)
291 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
292 struct sh_mobile_lcdc_panel_cfg
*panel
= &ch
->cfg
.panel_cfg
;
294 /* enable clocks before accessing hardware */
295 sh_mobile_lcdc_clk_on(ch
->lcdc
);
298 * It's possible to get here without anything on the pagelist via
299 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
300 * invocation. In the former case, the acceleration routines are
301 * stepped in to when using the framebuffer console causing the
302 * workqueue to be scheduled without any dirty pages on the list.
304 * Despite this, a panel update is still needed given that the
305 * acceleration routines have their own methods for writing in
306 * that still need to be updated.
308 * The fsync() and empty pagelist case could be optimized for,
309 * but we don't bother, as any application exhibiting such
310 * behaviour is fundamentally broken anyways.
312 if (!list_empty(pagelist
)) {
313 unsigned int nr_pages
= sh_mobile_lcdc_sginit(info
, pagelist
);
315 /* trigger panel update */
316 dma_map_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
317 if (panel
->start_transfer
)
318 panel
->start_transfer(ch
, &sh_mobile_lcdc_sys_bus_ops
);
319 lcdc_write_chan(ch
, LDSM2R
, LDSM2R_OSTRG
);
320 dma_unmap_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
322 if (panel
->start_transfer
)
323 panel
->start_transfer(ch
, &sh_mobile_lcdc_sys_bus_ops
);
324 lcdc_write_chan(ch
, LDSM2R
, LDSM2R_OSTRG
);
328 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info
*info
)
330 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
333 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
336 static void sh_mobile_lcdc_display_on(struct sh_mobile_lcdc_chan
*ch
)
338 struct sh_mobile_lcdc_panel_cfg
*panel
= &ch
->cfg
.panel_cfg
;
343 ret
= ch
->tx_dev
->ops
->display_on(ch
->tx_dev
);
347 if (ret
== SH_MOBILE_LCDC_DISPLAY_DISCONNECTED
)
348 ch
->info
->state
= FBINFO_STATE_SUSPENDED
;
351 /* HDMI must be enabled before LCDC configuration */
352 if (panel
->display_on
)
356 static void sh_mobile_lcdc_display_off(struct sh_mobile_lcdc_chan
*ch
)
358 struct sh_mobile_lcdc_panel_cfg
*panel
= &ch
->cfg
.panel_cfg
;
360 if (panel
->display_off
)
361 panel
->display_off();
364 ch
->tx_dev
->ops
->display_off(ch
->tx_dev
);
368 sh_mobile_lcdc_must_reconfigure(struct sh_mobile_lcdc_chan
*ch
,
369 const struct fb_videomode
*new_mode
)
371 dev_dbg(ch
->info
->dev
, "Old %ux%u, new %ux%u\n",
372 ch
->display
.mode
.xres
, ch
->display
.mode
.yres
,
373 new_mode
->xres
, new_mode
->yres
);
375 /* It can be a different monitor with an equal video-mode */
376 if (fb_mode_is_equal(&ch
->display
.mode
, new_mode
))
379 dev_dbg(ch
->info
->dev
, "Switching %u -> %u lines\n",
380 ch
->display
.mode
.yres
, new_mode
->yres
);
381 ch
->display
.mode
= *new_mode
;
386 static int sh_mobile_check_var(struct fb_var_screeninfo
*var
,
387 struct fb_info
*info
);
389 static int sh_mobile_lcdc_display_notify(struct sh_mobile_lcdc_chan
*ch
,
390 enum sh_mobile_lcdc_entity_event event
,
391 const struct fb_videomode
*mode
,
392 const struct fb_monspecs
*monspec
)
394 struct fb_info
*info
= ch
->info
;
395 struct fb_var_screeninfo var
;
399 case SH_MOBILE_LCDC_EVENT_DISPLAY_CONNECT
:
401 if (lock_fb_info(info
)) {
404 ch
->display
.width
= monspec
->max_x
* 10;
405 ch
->display
.height
= monspec
->max_y
* 10;
407 if (!sh_mobile_lcdc_must_reconfigure(ch
, mode
) &&
408 info
->state
== FBINFO_STATE_RUNNING
) {
409 /* First activation with the default monitor.
410 * Just turn on, if we run a resume here, the
413 info
->var
.width
= monspec
->max_x
* 10;
414 info
->var
.height
= monspec
->max_y
* 10;
415 sh_mobile_lcdc_display_on(ch
);
417 /* New monitor or have to wake up */
418 fb_set_suspend(info
, 0);
422 unlock_fb_info(info
);
426 case SH_MOBILE_LCDC_EVENT_DISPLAY_DISCONNECT
:
427 /* HDMI disconnect */
428 if (lock_fb_info(info
)) {
430 fb_set_suspend(info
, 1);
432 unlock_fb_info(info
);
436 case SH_MOBILE_LCDC_EVENT_DISPLAY_MODE
:
437 /* Validate a proposed new mode */
438 fb_videomode_to_var(&var
, mode
);
439 var
.bits_per_pixel
= info
->var
.bits_per_pixel
;
440 var
.grayscale
= info
->var
.grayscale
;
441 ret
= sh_mobile_check_var(&var
, info
);
448 /* -----------------------------------------------------------------------------
452 static int sh_mobile_format_fourcc(const struct fb_var_screeninfo
*var
)
454 if (var
->grayscale
> 1)
455 return var
->grayscale
;
457 switch (var
->bits_per_pixel
) {
459 return V4L2_PIX_FMT_RGB565
;
461 return V4L2_PIX_FMT_BGR24
;
463 return V4L2_PIX_FMT_BGR32
;
469 static int sh_mobile_format_is_fourcc(const struct fb_var_screeninfo
*var
)
471 return var
->grayscale
> 1;
474 static bool sh_mobile_format_is_yuv(const struct fb_var_screeninfo
*var
)
476 if (var
->grayscale
<= 1)
479 switch (var
->grayscale
) {
480 case V4L2_PIX_FMT_NV12
:
481 case V4L2_PIX_FMT_NV21
:
482 case V4L2_PIX_FMT_NV16
:
483 case V4L2_PIX_FMT_NV61
:
484 case V4L2_PIX_FMT_NV24
:
485 case V4L2_PIX_FMT_NV42
:
493 /* -----------------------------------------------------------------------------
494 * Start, stop and IRQ
497 static irqreturn_t
sh_mobile_lcdc_irq(int irq
, void *data
)
499 struct sh_mobile_lcdc_priv
*priv
= data
;
500 struct sh_mobile_lcdc_chan
*ch
;
501 unsigned long ldintr
;
505 /* Acknowledge interrupts and disable further VSYNC End IRQs. */
506 ldintr
= lcdc_read(priv
, _LDINTR
);
507 lcdc_write(priv
, _LDINTR
, (ldintr
^ LDINTR_STATUS_MASK
) & ~LDINTR_VEE
);
509 /* figure out if this interrupt is for main or sub lcd */
510 is_sub
= (lcdc_read(priv
, _LDSR
) & LDSR_MSS
) ? 1 : 0;
512 /* wake up channel and disable clocks */
513 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
520 if (ldintr
& LDINTR_FS
) {
521 if (is_sub
== lcdc_chan_is_sublcd(ch
)) {
523 wake_up(&ch
->frame_end_wait
);
525 sh_mobile_lcdc_clk_off(priv
);
530 if (ldintr
& LDINTR_VES
)
531 complete(&ch
->vsync_completion
);
537 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv
*priv
,
540 unsigned long tmp
= lcdc_read(priv
, _LDCNT2R
);
543 /* start or stop the lcdc */
545 lcdc_write(priv
, _LDCNT2R
, tmp
| LDCNT2R_DO
);
547 lcdc_write(priv
, _LDCNT2R
, tmp
& ~LDCNT2R_DO
);
549 /* wait until power is applied/stopped on all channels */
550 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
551 if (lcdc_read(priv
, _LDCNT2R
) & priv
->ch
[k
].enabled
)
553 tmp
= lcdc_read_chan(&priv
->ch
[k
], LDPMR
)
555 if (start
&& tmp
== LDPMR_LPS
)
557 if (!start
&& tmp
== 0)
563 lcdc_write(priv
, _LDDCKSTPR
, 1); /* stop dotclock */
566 static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan
*ch
)
568 const struct fb_var_screeninfo
*var
= &ch
->info
->var
;
569 const struct fb_videomode
*mode
= &ch
->display
.mode
;
570 unsigned long h_total
, hsync_pos
, display_h_total
;
573 tmp
= ch
->ldmt1r_value
;
574 tmp
|= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : LDMT1R_VPOL
;
575 tmp
|= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : LDMT1R_HPOL
;
576 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWPOL
) ? LDMT1R_DWPOL
: 0;
577 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DIPOL
) ? LDMT1R_DIPOL
: 0;
578 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DAPOL
) ? LDMT1R_DAPOL
: 0;
579 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_HSCNT
) ? LDMT1R_HSCNT
: 0;
580 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWCNT
) ? LDMT1R_DWCNT
: 0;
581 lcdc_write_chan(ch
, LDMT1R
, tmp
);
584 lcdc_write_chan(ch
, LDMT2R
, ch
->cfg
.sys_bus_cfg
.ldmt2r
);
585 lcdc_write_chan(ch
, LDMT3R
, ch
->cfg
.sys_bus_cfg
.ldmt3r
);
587 /* horizontal configuration */
588 h_total
= mode
->xres
+ mode
->hsync_len
+ mode
->left_margin
589 + mode
->right_margin
;
590 tmp
= h_total
/ 8; /* HTCN */
591 tmp
|= (min(mode
->xres
, var
->xres
) / 8) << 16; /* HDCN */
592 lcdc_write_chan(ch
, LDHCNR
, tmp
);
594 hsync_pos
= mode
->xres
+ mode
->right_margin
;
595 tmp
= hsync_pos
/ 8; /* HSYNP */
596 tmp
|= (mode
->hsync_len
/ 8) << 16; /* HSYNW */
597 lcdc_write_chan(ch
, LDHSYNR
, tmp
);
599 /* vertical configuration */
600 tmp
= mode
->yres
+ mode
->vsync_len
+ mode
->upper_margin
601 + mode
->lower_margin
; /* VTLN */
602 tmp
|= min(mode
->yres
, var
->yres
) << 16; /* VDLN */
603 lcdc_write_chan(ch
, LDVLNR
, tmp
);
605 tmp
= mode
->yres
+ mode
->lower_margin
; /* VSYNP */
606 tmp
|= mode
->vsync_len
<< 16; /* VSYNW */
607 lcdc_write_chan(ch
, LDVSYNR
, tmp
);
609 /* Adjust horizontal synchronisation for HDMI */
610 display_h_total
= mode
->xres
+ mode
->hsync_len
+ mode
->left_margin
611 + mode
->right_margin
;
612 tmp
= ((mode
->xres
& 7) << 24) | ((display_h_total
& 7) << 16)
613 | ((mode
->hsync_len
& 7) << 8) | (hsync_pos
& 7);
614 lcdc_write_chan(ch
, LDHAJR
, tmp
);
618 * __sh_mobile_lcdc_start - Configure and tart the LCDC
621 * Configure all enabled channels and start the LCDC device. All external
622 * devices (clocks, MERAM, panels, ...) are not touched by this function.
624 static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
626 struct sh_mobile_lcdc_chan
*ch
;
630 /* Enable LCDC channels. Read data from external memory, avoid using the
633 lcdc_write(priv
, _LDCNT2R
, priv
->ch
[0].enabled
| priv
->ch
[1].enabled
);
635 /* Stop the LCDC first and disable all interrupts. */
636 sh_mobile_lcdc_start_stop(priv
, 0);
637 lcdc_write(priv
, _LDINTR
, 0);
639 /* Configure power supply, dot clocks and start them. */
641 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
647 lcdc_write_chan(ch
, LDPMR
, 0);
649 m
= ch
->cfg
.clock_divider
;
653 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
656 lcdc_write_chan(ch
, LDDCKPAT1R
, 0);
657 lcdc_write_chan(ch
, LDDCKPAT2R
, (1 << (m
/2)) - 1);
661 tmp
|= m
<< (lcdc_chan_is_sublcd(ch
) ? 8 : 0);
664 lcdc_write(priv
, _LDDCKR
, tmp
);
665 lcdc_write(priv
, _LDDCKSTPR
, 0);
666 lcdc_wait_bit(priv
, _LDDCKSTPR
, ~0, 0);
668 /* Setup geometry, format, frame buffer memory and operation mode. */
669 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
674 sh_mobile_lcdc_geometry(ch
);
676 switch (sh_mobile_format_fourcc(&ch
->info
->var
)) {
677 case V4L2_PIX_FMT_RGB565
:
678 tmp
= LDDFR_PKF_RGB16
;
680 case V4L2_PIX_FMT_BGR24
:
681 tmp
= LDDFR_PKF_RGB24
;
683 case V4L2_PIX_FMT_BGR32
:
684 tmp
= LDDFR_PKF_ARGB32
;
686 case V4L2_PIX_FMT_NV12
:
687 case V4L2_PIX_FMT_NV21
:
688 tmp
= LDDFR_CC
| LDDFR_YF_420
;
690 case V4L2_PIX_FMT_NV16
:
691 case V4L2_PIX_FMT_NV61
:
692 tmp
= LDDFR_CC
| LDDFR_YF_422
;
694 case V4L2_PIX_FMT_NV24
:
695 case V4L2_PIX_FMT_NV42
:
696 tmp
= LDDFR_CC
| LDDFR_YF_444
;
700 if (sh_mobile_format_is_yuv(&ch
->info
->var
)) {
701 switch (ch
->info
->var
.colorspace
) {
702 case V4L2_COLORSPACE_REC709
:
705 case V4L2_COLORSPACE_JPEG
:
711 lcdc_write_chan(ch
, LDDFR
, tmp
);
712 lcdc_write_chan(ch
, LDMLSR
, ch
->pitch
);
713 lcdc_write_chan(ch
, LDSA1R
, ch
->base_addr_y
);
714 if (sh_mobile_format_is_yuv(&ch
->info
->var
))
715 lcdc_write_chan(ch
, LDSA2R
, ch
->base_addr_c
);
717 /* When using deferred I/O mode, configure the LCDC for one-shot
718 * operation and enable the frame end interrupt. Otherwise use
719 * continuous read mode.
721 if (ch
->ldmt1r_value
& LDMT1R_IFM
&&
722 ch
->cfg
.sys_bus_cfg
.deferred_io_msec
) {
723 lcdc_write_chan(ch
, LDSM1R
, LDSM1R_OS
);
724 lcdc_write(priv
, _LDINTR
, LDINTR_FE
);
726 lcdc_write_chan(ch
, LDSM1R
, 0);
730 /* Word and long word swap. */
731 switch (sh_mobile_format_fourcc(&priv
->ch
[0].info
->var
)) {
732 case V4L2_PIX_FMT_RGB565
:
733 case V4L2_PIX_FMT_NV21
:
734 case V4L2_PIX_FMT_NV61
:
735 case V4L2_PIX_FMT_NV42
:
736 tmp
= LDDDSR_LS
| LDDDSR_WS
;
738 case V4L2_PIX_FMT_BGR24
:
739 case V4L2_PIX_FMT_NV12
:
740 case V4L2_PIX_FMT_NV16
:
741 case V4L2_PIX_FMT_NV24
:
742 tmp
= LDDDSR_LS
| LDDDSR_WS
| LDDDSR_BS
;
744 case V4L2_PIX_FMT_BGR32
:
749 lcdc_write(priv
, _LDDDSR
, tmp
);
751 /* Enable the display output. */
752 lcdc_write(priv
, _LDCNT1R
, LDCNT1R_DE
);
753 sh_mobile_lcdc_start_stop(priv
, 1);
757 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
759 struct sh_mobile_meram_info
*mdev
= priv
->meram_dev
;
760 struct sh_mobile_lcdc_chan
*ch
;
765 /* enable clocks before accessing the hardware */
766 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
767 if (priv
->ch
[k
].enabled
)
768 sh_mobile_lcdc_clk_on(priv
);
772 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) | LDCNT2R_BR
);
773 lcdc_wait_bit(priv
, _LDCNT2R
, LDCNT2R_BR
, 0);
775 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
776 struct sh_mobile_lcdc_panel_cfg
*panel
;
782 panel
= &ch
->cfg
.panel_cfg
;
783 if (panel
->setup_sys
) {
784 ret
= panel
->setup_sys(ch
, &sh_mobile_lcdc_sys_bus_ops
);
790 /* Compute frame buffer base address and pitch for each channel. */
791 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
792 struct sh_mobile_meram_cfg
*cfg
;
799 ch
->base_addr_y
= ch
->info
->fix
.smem_start
;
800 ch
->base_addr_c
= ch
->base_addr_y
802 * ch
->info
->var
.yres_virtual
;
803 ch
->pitch
= ch
->info
->fix
.line_length
;
805 /* Enable MERAM if possible. */
806 cfg
= ch
->cfg
.meram_cfg
;
807 if (mdev
== NULL
|| mdev
->ops
== NULL
|| cfg
== NULL
)
810 /* we need to de-init configured ICBs before we can
811 * re-initialize them.
813 if (ch
->meram_enabled
) {
814 mdev
->ops
->meram_unregister(mdev
, cfg
);
815 ch
->meram_enabled
= 0;
818 switch (sh_mobile_format_fourcc(&ch
->info
->var
)) {
819 case V4L2_PIX_FMT_NV12
:
820 case V4L2_PIX_FMT_NV21
:
821 case V4L2_PIX_FMT_NV16
:
822 case V4L2_PIX_FMT_NV61
:
823 pixelformat
= SH_MOBILE_MERAM_PF_NV
;
825 case V4L2_PIX_FMT_NV24
:
826 case V4L2_PIX_FMT_NV42
:
827 pixelformat
= SH_MOBILE_MERAM_PF_NV24
;
829 case V4L2_PIX_FMT_RGB565
:
830 case V4L2_PIX_FMT_BGR24
:
831 case V4L2_PIX_FMT_BGR32
:
833 pixelformat
= SH_MOBILE_MERAM_PF_RGB
;
837 ret
= mdev
->ops
->meram_register(mdev
, cfg
, ch
->pitch
,
838 ch
->info
->var
.yres
, pixelformat
,
839 ch
->base_addr_y
, ch
->base_addr_c
,
840 &ch
->base_addr_y
, &ch
->base_addr_c
,
843 ch
->meram_enabled
= 1;
846 /* Start the LCDC. */
847 __sh_mobile_lcdc_start(priv
);
849 /* Setup deferred I/O, tell the board code to enable the panels, and
852 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
857 tmp
= ch
->cfg
.sys_bus_cfg
.deferred_io_msec
;
858 if (ch
->ldmt1r_value
& LDMT1R_IFM
&& tmp
) {
859 ch
->defio
.deferred_io
= sh_mobile_lcdc_deferred_io
;
860 ch
->defio
.delay
= msecs_to_jiffies(tmp
);
861 ch
->info
->fbdefio
= &ch
->defio
;
862 fb_deferred_io_init(ch
->info
);
865 sh_mobile_lcdc_display_on(ch
);
868 ch
->bl
->props
.power
= FB_BLANK_UNBLANK
;
869 backlight_update_status(ch
->bl
);
876 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
878 struct sh_mobile_lcdc_chan
*ch
;
881 /* clean up deferred io and ask board code to disable panel */
882 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
888 * flush frame, and wait for frame end interrupt
889 * clean up deferred io and enable clock
891 if (ch
->info
&& ch
->info
->fbdefio
) {
893 schedule_delayed_work(&ch
->info
->deferred_work
, 0);
894 wait_event(ch
->frame_end_wait
, ch
->frame_end
);
895 fb_deferred_io_cleanup(ch
->info
);
896 ch
->info
->fbdefio
= NULL
;
897 sh_mobile_lcdc_clk_on(priv
);
901 ch
->bl
->props
.power
= FB_BLANK_POWERDOWN
;
902 backlight_update_status(ch
->bl
);
905 sh_mobile_lcdc_display_off(ch
);
907 /* disable the meram */
908 if (ch
->meram_enabled
) {
909 struct sh_mobile_meram_cfg
*cfg
;
910 struct sh_mobile_meram_info
*mdev
;
911 cfg
= ch
->cfg
.meram_cfg
;
912 mdev
= priv
->meram_dev
;
913 mdev
->ops
->meram_unregister(mdev
, cfg
);
914 ch
->meram_enabled
= 0;
921 sh_mobile_lcdc_start_stop(priv
, 0);
926 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
927 if (priv
->ch
[k
].enabled
)
928 sh_mobile_lcdc_clk_off(priv
);
931 /* -----------------------------------------------------------------------------
932 * Frame buffer operations
935 static int sh_mobile_lcdc_setcolreg(u_int regno
,
936 u_int red
, u_int green
, u_int blue
,
937 u_int transp
, struct fb_info
*info
)
939 u32
*palette
= info
->pseudo_palette
;
941 if (regno
>= PALETTE_NR
)
944 /* only FB_VISUAL_TRUECOLOR supported */
946 red
>>= 16 - info
->var
.red
.length
;
947 green
>>= 16 - info
->var
.green
.length
;
948 blue
>>= 16 - info
->var
.blue
.length
;
949 transp
>>= 16 - info
->var
.transp
.length
;
951 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
952 (green
<< info
->var
.green
.offset
) |
953 (blue
<< info
->var
.blue
.offset
) |
954 (transp
<< info
->var
.transp
.offset
);
959 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
960 .id
= "SH Mobile LCDC",
961 .type
= FB_TYPE_PACKED_PIXELS
,
962 .visual
= FB_VISUAL_TRUECOLOR
,
963 .accel
= FB_ACCEL_NONE
,
967 .capabilities
= FB_CAP_FOURCC
,
970 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
971 const struct fb_fillrect
*rect
)
973 sys_fillrect(info
, rect
);
974 sh_mobile_lcdc_deferred_io_touch(info
);
977 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
978 const struct fb_copyarea
*area
)
980 sys_copyarea(info
, area
);
981 sh_mobile_lcdc_deferred_io_touch(info
);
984 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
985 const struct fb_image
*image
)
987 sys_imageblit(info
, image
);
988 sh_mobile_lcdc_deferred_io_touch(info
);
991 static int sh_mobile_fb_pan_display(struct fb_var_screeninfo
*var
,
992 struct fb_info
*info
)
994 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
995 struct sh_mobile_lcdc_priv
*priv
= ch
->lcdc
;
996 unsigned long ldrcntr
;
997 unsigned long new_pan_offset
;
998 unsigned long base_addr_y
, base_addr_c
;
999 unsigned long c_offset
;
1000 bool yuv
= sh_mobile_format_is_yuv(&info
->var
);
1003 new_pan_offset
= var
->yoffset
* info
->fix
.line_length
1004 + var
->xoffset
* (info
->var
.bits_per_pixel
/ 8);
1006 new_pan_offset
= var
->yoffset
* info
->fix
.line_length
1009 if (new_pan_offset
== ch
->pan_offset
)
1010 return 0; /* No change, do nothing */
1012 ldrcntr
= lcdc_read(priv
, _LDRCNTR
);
1014 /* Set the source address for the next refresh */
1015 base_addr_y
= ch
->dma_handle
+ new_pan_offset
;
1018 c_offset
= var
->yoffset
* info
->fix
.line_length
1019 * (info
->var
.bits_per_pixel
- 8) / 8;
1020 base_addr_c
= ch
->dma_handle
1021 + info
->var
.xres
* info
->var
.yres_virtual
1024 if (sh_mobile_format_fourcc(&info
->var
) == V4L2_PIX_FMT_NV24
)
1025 base_addr_c
+= 2 * var
->xoffset
;
1027 base_addr_c
+= var
->xoffset
;
1030 if (ch
->meram_enabled
) {
1031 struct sh_mobile_meram_cfg
*cfg
;
1032 struct sh_mobile_meram_info
*mdev
;
1035 cfg
= ch
->cfg
.meram_cfg
;
1036 mdev
= priv
->meram_dev
;
1037 ret
= mdev
->ops
->meram_update(mdev
, cfg
,
1038 base_addr_y
, base_addr_c
,
1039 &base_addr_y
, &base_addr_c
);
1044 ch
->base_addr_y
= base_addr_y
;
1045 ch
->base_addr_c
= base_addr_c
;
1047 lcdc_write_chan_mirror(ch
, LDSA1R
, base_addr_y
);
1049 lcdc_write_chan_mirror(ch
, LDSA2R
, base_addr_c
);
1051 if (lcdc_chan_is_sublcd(ch
))
1052 lcdc_write(ch
->lcdc
, _LDRCNTR
, ldrcntr
^ LDRCNTR_SRS
);
1054 lcdc_write(ch
->lcdc
, _LDRCNTR
, ldrcntr
^ LDRCNTR_MRS
);
1056 ch
->pan_offset
= new_pan_offset
;
1058 sh_mobile_lcdc_deferred_io_touch(info
);
1063 static int sh_mobile_wait_for_vsync(struct fb_info
*info
)
1065 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1066 unsigned long ldintr
;
1069 /* Enable VSync End interrupt and be careful not to acknowledge any
1070 * pending interrupt.
1072 ldintr
= lcdc_read(ch
->lcdc
, _LDINTR
);
1073 ldintr
|= LDINTR_VEE
| LDINTR_STATUS_MASK
;
1074 lcdc_write(ch
->lcdc
, _LDINTR
, ldintr
);
1076 ret
= wait_for_completion_interruptible_timeout(&ch
->vsync_completion
,
1077 msecs_to_jiffies(100));
1084 static int sh_mobile_ioctl(struct fb_info
*info
, unsigned int cmd
,
1090 case FBIO_WAITFORVSYNC
:
1091 retval
= sh_mobile_wait_for_vsync(info
);
1095 retval
= -ENOIOCTLCMD
;
1101 static void sh_mobile_fb_reconfig(struct fb_info
*info
)
1103 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1104 struct fb_var_screeninfo var
;
1105 struct fb_videomode mode
;
1106 struct fb_event event
;
1107 int evnt
= FB_EVENT_MODE_CHANGE_ALL
;
1109 if (ch
->use_count
> 1 || (ch
->use_count
== 1 && !info
->fbcon_par
))
1110 /* More framebuffer users are active */
1113 fb_var_to_videomode(&mode
, &info
->var
);
1115 if (fb_mode_is_equal(&ch
->display
.mode
, &mode
))
1118 /* Display has been re-plugged, framebuffer is free now, reconfigure */
1120 fb_videomode_to_var(&var
, &ch
->display
.mode
);
1121 var
.width
= ch
->display
.width
;
1122 var
.height
= ch
->display
.height
;
1123 var
.activate
= FB_ACTIVATE_NOW
;
1125 if (fb_set_var(info
, &var
) < 0)
1126 /* Couldn't reconfigure, hopefully, can continue as before */
1130 * fb_set_var() calls the notifier change internally, only if
1131 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1132 * user event, we have to call the chain ourselves.
1135 event
.data
= &ch
->display
.mode
;
1136 fb_notifier_call_chain(evnt
, &event
);
1140 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1141 * user == 1, or with console sem held, if user == 0.
1143 static int sh_mobile_release(struct fb_info
*info
, int user
)
1145 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1147 mutex_lock(&ch
->open_lock
);
1148 dev_dbg(info
->dev
, "%s(): %d users\n", __func__
, ch
->use_count
);
1152 /* Nothing to reconfigure, when called from fbcon */
1155 sh_mobile_fb_reconfig(info
);
1159 mutex_unlock(&ch
->open_lock
);
1164 static int sh_mobile_open(struct fb_info
*info
, int user
)
1166 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1168 mutex_lock(&ch
->open_lock
);
1171 dev_dbg(info
->dev
, "%s(): %d users\n", __func__
, ch
->use_count
);
1172 mutex_unlock(&ch
->open_lock
);
1177 static int sh_mobile_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1179 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1180 struct sh_mobile_lcdc_priv
*p
= ch
->lcdc
;
1181 unsigned int best_dist
= (unsigned int)-1;
1182 unsigned int best_xres
= 0;
1183 unsigned int best_yres
= 0;
1186 if (var
->xres
> MAX_XRES
|| var
->yres
> MAX_YRES
)
1189 /* If board code provides us with a list of available modes, make sure
1190 * we use one of them. Find the mode closest to the requested one. The
1191 * distance between two modes is defined as the size of the
1192 * non-overlapping parts of the two rectangles.
1194 for (i
= 0; i
< ch
->cfg
.num_cfg
; ++i
) {
1195 const struct fb_videomode
*mode
= &ch
->cfg
.lcd_cfg
[i
];
1198 /* We can only round up. */
1199 if (var
->xres
> mode
->xres
|| var
->yres
> mode
->yres
)
1202 dist
= var
->xres
* var
->yres
+ mode
->xres
* mode
->yres
1203 - 2 * min(var
->xres
, mode
->xres
)
1204 * min(var
->yres
, mode
->yres
);
1206 if (dist
< best_dist
) {
1207 best_xres
= mode
->xres
;
1208 best_yres
= mode
->yres
;
1213 /* If no available mode can be used, return an error. */
1214 if (ch
->cfg
.num_cfg
!= 0) {
1215 if (best_dist
== (unsigned int)-1)
1218 var
->xres
= best_xres
;
1219 var
->yres
= best_yres
;
1222 /* Make sure the virtual resolution is at least as big as the visible
1225 if (var
->xres_virtual
< var
->xres
)
1226 var
->xres_virtual
= var
->xres
;
1227 if (var
->yres_virtual
< var
->yres
)
1228 var
->yres_virtual
= var
->yres
;
1230 if (sh_mobile_format_is_fourcc(var
)) {
1231 switch (var
->grayscale
) {
1232 case V4L2_PIX_FMT_NV12
:
1233 case V4L2_PIX_FMT_NV21
:
1234 var
->bits_per_pixel
= 12;
1236 case V4L2_PIX_FMT_RGB565
:
1237 case V4L2_PIX_FMT_NV16
:
1238 case V4L2_PIX_FMT_NV61
:
1239 var
->bits_per_pixel
= 16;
1241 case V4L2_PIX_FMT_BGR24
:
1242 case V4L2_PIX_FMT_NV24
:
1243 case V4L2_PIX_FMT_NV42
:
1244 var
->bits_per_pixel
= 24;
1246 case V4L2_PIX_FMT_BGR32
:
1247 var
->bits_per_pixel
= 32;
1253 /* Default to RGB and JPEG color-spaces for RGB and YUV formats
1256 if (!sh_mobile_format_is_yuv(var
))
1257 var
->colorspace
= V4L2_COLORSPACE_SRGB
;
1258 else if (var
->colorspace
!= V4L2_COLORSPACE_REC709
)
1259 var
->colorspace
= V4L2_COLORSPACE_JPEG
;
1261 if (var
->bits_per_pixel
<= 16) { /* RGB 565 */
1262 var
->bits_per_pixel
= 16;
1263 var
->red
.offset
= 11;
1264 var
->red
.length
= 5;
1265 var
->green
.offset
= 5;
1266 var
->green
.length
= 6;
1267 var
->blue
.offset
= 0;
1268 var
->blue
.length
= 5;
1269 var
->transp
.offset
= 0;
1270 var
->transp
.length
= 0;
1271 } else if (var
->bits_per_pixel
<= 24) { /* RGB 888 */
1272 var
->bits_per_pixel
= 24;
1273 var
->red
.offset
= 16;
1274 var
->red
.length
= 8;
1275 var
->green
.offset
= 8;
1276 var
->green
.length
= 8;
1277 var
->blue
.offset
= 0;
1278 var
->blue
.length
= 8;
1279 var
->transp
.offset
= 0;
1280 var
->transp
.length
= 0;
1281 } else if (var
->bits_per_pixel
<= 32) { /* RGBA 888 */
1282 var
->bits_per_pixel
= 32;
1283 var
->red
.offset
= 16;
1284 var
->red
.length
= 8;
1285 var
->green
.offset
= 8;
1286 var
->green
.length
= 8;
1287 var
->blue
.offset
= 0;
1288 var
->blue
.length
= 8;
1289 var
->transp
.offset
= 24;
1290 var
->transp
.length
= 8;
1294 var
->red
.msb_right
= 0;
1295 var
->green
.msb_right
= 0;
1296 var
->blue
.msb_right
= 0;
1297 var
->transp
.msb_right
= 0;
1300 /* Make sure we don't exceed our allocated memory. */
1301 if (var
->xres_virtual
* var
->yres_virtual
* var
->bits_per_pixel
/ 8 >
1305 /* only accept the forced_fourcc for dual channel configurations */
1306 if (p
->forced_fourcc
&&
1307 p
->forced_fourcc
!= sh_mobile_format_fourcc(var
))
1313 static int sh_mobile_set_par(struct fb_info
*info
)
1315 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1316 u32 line_length
= info
->fix
.line_length
;
1319 sh_mobile_lcdc_stop(ch
->lcdc
);
1321 if (sh_mobile_format_is_yuv(&info
->var
))
1322 info
->fix
.line_length
= info
->var
.xres
;
1324 info
->fix
.line_length
= info
->var
.xres
1325 * info
->var
.bits_per_pixel
/ 8;
1327 ret
= sh_mobile_lcdc_start(ch
->lcdc
);
1329 dev_err(info
->dev
, "%s: unable to restart LCDC\n", __func__
);
1330 info
->fix
.line_length
= line_length
;
1333 if (sh_mobile_format_is_fourcc(&info
->var
)) {
1334 info
->fix
.type
= FB_TYPE_FOURCC
;
1335 info
->fix
.visual
= FB_VISUAL_FOURCC
;
1337 info
->fix
.type
= FB_TYPE_PACKED_PIXELS
;
1338 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
1345 * Screen blanking. Behavior is as follows:
1346 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1347 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1350 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1352 static int sh_mobile_lcdc_blank(int blank
, struct fb_info
*info
)
1354 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1355 struct sh_mobile_lcdc_priv
*p
= ch
->lcdc
;
1357 /* blank the screen? */
1358 if (blank
> FB_BLANK_UNBLANK
&& ch
->blank_status
== FB_BLANK_UNBLANK
) {
1359 struct fb_fillrect rect
= {
1360 .width
= info
->var
.xres
,
1361 .height
= info
->var
.yres
,
1363 sh_mobile_lcdc_fillrect(info
, &rect
);
1365 /* turn clocks on? */
1366 if (blank
<= FB_BLANK_NORMAL
&& ch
->blank_status
> FB_BLANK_NORMAL
) {
1367 sh_mobile_lcdc_clk_on(p
);
1369 /* turn clocks off? */
1370 if (blank
> FB_BLANK_NORMAL
&& ch
->blank_status
<= FB_BLANK_NORMAL
) {
1371 /* make sure the screen is updated with the black fill before
1372 * switching the clocks off. one vsync is not enough since
1373 * blanking may occur in the middle of a refresh. deferred io
1374 * mode will reenable the clocks and update the screen in time,
1375 * so it does not need this. */
1376 if (!info
->fbdefio
) {
1377 sh_mobile_wait_for_vsync(info
);
1378 sh_mobile_wait_for_vsync(info
);
1380 sh_mobile_lcdc_clk_off(p
);
1383 ch
->blank_status
= blank
;
1387 static struct fb_ops sh_mobile_lcdc_ops
= {
1388 .owner
= THIS_MODULE
,
1389 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
1390 .fb_read
= fb_sys_read
,
1391 .fb_write
= fb_sys_write
,
1392 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
1393 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
1394 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
1395 .fb_blank
= sh_mobile_lcdc_blank
,
1396 .fb_pan_display
= sh_mobile_fb_pan_display
,
1397 .fb_ioctl
= sh_mobile_ioctl
,
1398 .fb_open
= sh_mobile_open
,
1399 .fb_release
= sh_mobile_release
,
1400 .fb_check_var
= sh_mobile_check_var
,
1401 .fb_set_par
= sh_mobile_set_par
,
1404 /* -----------------------------------------------------------------------------
1408 static int sh_mobile_lcdc_update_bl(struct backlight_device
*bdev
)
1410 struct sh_mobile_lcdc_chan
*ch
= bl_get_data(bdev
);
1411 int brightness
= bdev
->props
.brightness
;
1413 if (bdev
->props
.power
!= FB_BLANK_UNBLANK
||
1414 bdev
->props
.state
& (BL_CORE_SUSPENDED
| BL_CORE_FBBLANK
))
1417 return ch
->cfg
.bl_info
.set_brightness(brightness
);
1420 static int sh_mobile_lcdc_get_brightness(struct backlight_device
*bdev
)
1422 struct sh_mobile_lcdc_chan
*ch
= bl_get_data(bdev
);
1424 return ch
->cfg
.bl_info
.get_brightness();
1427 static int sh_mobile_lcdc_check_fb(struct backlight_device
*bdev
,
1428 struct fb_info
*info
)
1430 return (info
->bl_dev
== bdev
);
1433 static struct backlight_ops sh_mobile_lcdc_bl_ops
= {
1434 .options
= BL_CORE_SUSPENDRESUME
,
1435 .update_status
= sh_mobile_lcdc_update_bl
,
1436 .get_brightness
= sh_mobile_lcdc_get_brightness
,
1437 .check_fb
= sh_mobile_lcdc_check_fb
,
1440 static struct backlight_device
*sh_mobile_lcdc_bl_probe(struct device
*parent
,
1441 struct sh_mobile_lcdc_chan
*ch
)
1443 struct backlight_device
*bl
;
1445 bl
= backlight_device_register(ch
->cfg
.bl_info
.name
, parent
, ch
,
1446 &sh_mobile_lcdc_bl_ops
, NULL
);
1448 dev_err(parent
, "unable to register backlight device: %ld\n",
1453 bl
->props
.max_brightness
= ch
->cfg
.bl_info
.max_brightness
;
1454 bl
->props
.brightness
= bl
->props
.max_brightness
;
1455 backlight_update_status(bl
);
1460 static void sh_mobile_lcdc_bl_remove(struct backlight_device
*bdev
)
1462 backlight_device_unregister(bdev
);
1465 /* -----------------------------------------------------------------------------
1469 static int sh_mobile_lcdc_suspend(struct device
*dev
)
1471 struct platform_device
*pdev
= to_platform_device(dev
);
1473 sh_mobile_lcdc_stop(platform_get_drvdata(pdev
));
1477 static int sh_mobile_lcdc_resume(struct device
*dev
)
1479 struct platform_device
*pdev
= to_platform_device(dev
);
1481 return sh_mobile_lcdc_start(platform_get_drvdata(pdev
));
1484 static int sh_mobile_lcdc_runtime_suspend(struct device
*dev
)
1486 struct platform_device
*pdev
= to_platform_device(dev
);
1487 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1489 /* turn off LCDC hardware */
1490 lcdc_write(priv
, _LDCNT1R
, 0);
1495 static int sh_mobile_lcdc_runtime_resume(struct device
*dev
)
1497 struct platform_device
*pdev
= to_platform_device(dev
);
1498 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1500 __sh_mobile_lcdc_start(priv
);
1505 static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops
= {
1506 .suspend
= sh_mobile_lcdc_suspend
,
1507 .resume
= sh_mobile_lcdc_resume
,
1508 .runtime_suspend
= sh_mobile_lcdc_runtime_suspend
,
1509 .runtime_resume
= sh_mobile_lcdc_runtime_resume
,
1512 /* -----------------------------------------------------------------------------
1513 * Framebuffer notifier
1516 /* locking: called with info->lock held */
1517 static int sh_mobile_lcdc_notify(struct notifier_block
*nb
,
1518 unsigned long action
, void *data
)
1520 struct fb_event
*event
= data
;
1521 struct fb_info
*info
= event
->info
;
1522 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1524 if (&ch
->lcdc
->notifier
!= nb
)
1527 dev_dbg(info
->dev
, "%s(): action = %lu, data = %p\n",
1528 __func__
, action
, event
->data
);
1531 case FB_EVENT_SUSPEND
:
1532 sh_mobile_lcdc_display_off(ch
);
1533 sh_mobile_lcdc_stop(ch
->lcdc
);
1535 case FB_EVENT_RESUME
:
1536 mutex_lock(&ch
->open_lock
);
1537 sh_mobile_fb_reconfig(info
);
1538 mutex_unlock(&ch
->open_lock
);
1540 sh_mobile_lcdc_display_on(ch
);
1541 sh_mobile_lcdc_start(ch
->lcdc
);
1547 /* -----------------------------------------------------------------------------
1548 * Probe/remove and driver init/exit
1551 static const struct fb_videomode default_720p __devinitconst
= {
1552 .name
= "HDMI 720p",
1557 .right_margin
= 110,
1566 .sync
= FB_SYNC_VERT_HIGH_ACT
| FB_SYNC_HOR_HIGH_ACT
,
1569 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
1571 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1572 struct fb_info
*info
;
1575 fb_unregister_client(&priv
->notifier
);
1577 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
1578 if (priv
->ch
[i
].info
&& priv
->ch
[i
].info
->dev
)
1579 unregister_framebuffer(priv
->ch
[i
].info
);
1581 sh_mobile_lcdc_stop(priv
);
1583 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
1584 struct sh_mobile_lcdc_chan
*ch
= &priv
->ch
[i
];
1587 if (!info
|| !info
->device
)
1591 ch
->tx_dev
->lcdc
= NULL
;
1592 module_put(ch
->cfg
.tx_dev
->dev
.driver
->owner
);
1598 if (info
->screen_base
)
1599 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1600 info
->screen_base
, ch
->dma_handle
);
1601 fb_dealloc_cmap(&info
->cmap
);
1602 framebuffer_release(info
);
1605 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
1607 sh_mobile_lcdc_bl_remove(priv
->ch
[i
].bl
);
1610 if (priv
->dot_clk
) {
1611 pm_runtime_disable(&pdev
->dev
);
1612 clk_put(priv
->dot_clk
);
1616 iounmap(priv
->base
);
1619 free_irq(priv
->irq
, priv
);
1624 static int __devinit
sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
1626 int interface_type
= ch
->cfg
.interface_type
;
1628 switch (interface_type
) {
1652 /* SUBLCD only supports SYS interface */
1653 if (lcdc_chan_is_sublcd(ch
)) {
1654 if (!(interface_type
& LDMT1R_IFM
))
1657 interface_type
&= ~LDMT1R_IFM
;
1660 ch
->ldmt1r_value
= interface_type
;
1664 static int __devinit
1665 sh_mobile_lcdc_channel_init(struct sh_mobile_lcdc_priv
*priv
,
1666 struct sh_mobile_lcdc_chan
*ch
)
1668 struct sh_mobile_lcdc_chan_cfg
*cfg
= &ch
->cfg
;
1669 const struct fb_videomode
*max_mode
;
1670 const struct fb_videomode
*mode
;
1671 struct fb_var_screeninfo
*var
;
1672 struct fb_info
*info
;
1673 unsigned int max_size
;
1679 mutex_init(&ch
->open_lock
);
1680 ch
->notify
= sh_mobile_lcdc_display_notify
;
1682 /* Allocate the frame buffer device. */
1683 ch
->info
= framebuffer_alloc(0, priv
->dev
);
1685 dev_err(priv
->dev
, "unable to allocate fb_info\n");
1690 info
->fbops
= &sh_mobile_lcdc_ops
;
1692 info
->pseudo_palette
= &ch
->pseudo_palette
;
1693 info
->flags
= FBINFO_FLAG_DEFAULT
;
1695 /* Iterate through the modes to validate them and find the highest
1701 for (i
= 0, mode
= cfg
->lcd_cfg
; i
< cfg
->num_cfg
; i
++, mode
++) {
1702 unsigned int size
= mode
->yres
* mode
->xres
;
1704 /* NV12/NV21 buffers must have even number of lines */
1705 if ((cfg
->fourcc
== V4L2_PIX_FMT_NV12
||
1706 cfg
->fourcc
== V4L2_PIX_FMT_NV21
) && (mode
->yres
& 0x1)) {
1707 dev_err(priv
->dev
, "yres must be multiple of 2 for "
1708 "YCbCr420 mode.\n");
1712 if (size
> max_size
) {
1719 max_size
= MAX_XRES
* MAX_YRES
;
1721 dev_dbg(priv
->dev
, "Found largest videomode %ux%u\n",
1722 max_mode
->xres
, max_mode
->yres
);
1724 /* Create the mode list. */
1725 if (cfg
->lcd_cfg
== NULL
) {
1726 mode
= &default_720p
;
1729 mode
= cfg
->lcd_cfg
;
1730 num_cfg
= cfg
->num_cfg
;
1733 fb_videomode_to_modelist(mode
, num_cfg
, &info
->modelist
);
1735 /* Initialize the transmitter device if present. */
1737 if (!cfg
->tx_dev
->dev
.driver
||
1738 !try_module_get(cfg
->tx_dev
->dev
.driver
->owner
)) {
1740 "unable to get transmitter device\n");
1743 ch
->tx_dev
= platform_get_drvdata(cfg
->tx_dev
);
1744 ch
->tx_dev
->lcdc
= ch
;
1745 ch
->tx_dev
->def_mode
= *mode
;
1748 /* Initialize variable screen information using the first mode as
1749 * default. The default Y virtual resolution is twice the panel size to
1750 * allow for double-buffering.
1753 fb_videomode_to_var(var
, mode
);
1754 var
->width
= cfg
->panel_cfg
.width
;
1755 var
->height
= cfg
->panel_cfg
.height
;
1756 var
->yres_virtual
= var
->yres
* 2;
1757 var
->activate
= FB_ACTIVATE_NOW
;
1759 switch (cfg
->fourcc
) {
1760 case V4L2_PIX_FMT_RGB565
:
1761 var
->bits_per_pixel
= 16;
1763 case V4L2_PIX_FMT_BGR24
:
1764 var
->bits_per_pixel
= 24;
1766 case V4L2_PIX_FMT_BGR32
:
1767 var
->bits_per_pixel
= 32;
1770 var
->grayscale
= cfg
->fourcc
;
1774 /* Make sure the memory size check won't fail. smem_len is initialized
1775 * later based on var.
1777 info
->fix
.smem_len
= UINT_MAX
;
1778 ret
= sh_mobile_check_var(var
, info
);
1782 max_size
= max_size
* var
->bits_per_pixel
/ 8 * 2;
1784 /* Allocate frame buffer memory and color map. */
1785 buf
= dma_alloc_coherent(priv
->dev
, max_size
, &ch
->dma_handle
,
1788 dev_err(priv
->dev
, "unable to allocate buffer\n");
1792 ret
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
1794 dev_err(priv
->dev
, "unable to allocate cmap\n");
1795 dma_free_coherent(priv
->dev
, max_size
, buf
, ch
->dma_handle
);
1799 /* Initialize fixed screen information. Restrict pan to 2 lines steps
1800 * for NV12 and NV21.
1802 info
->fix
= sh_mobile_lcdc_fix
;
1803 info
->fix
.smem_start
= ch
->dma_handle
;
1804 info
->fix
.smem_len
= max_size
;
1805 if (cfg
->fourcc
== V4L2_PIX_FMT_NV12
||
1806 cfg
->fourcc
== V4L2_PIX_FMT_NV21
)
1807 info
->fix
.ypanstep
= 2;
1809 if (sh_mobile_format_is_yuv(var
)) {
1810 info
->fix
.line_length
= var
->xres
;
1811 info
->fix
.visual
= FB_VISUAL_FOURCC
;
1813 info
->fix
.line_length
= var
->xres
* var
->bits_per_pixel
/ 8;
1814 info
->fix
.visual
= FB_VISUAL_TRUECOLOR
;
1817 info
->screen_base
= buf
;
1818 info
->device
= priv
->dev
;
1820 ch
->display
.width
= cfg
->panel_cfg
.width
;
1821 ch
->display
.height
= cfg
->panel_cfg
.height
;
1822 ch
->display
.mode
= *mode
;
1827 static int __devinit
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
1829 struct sh_mobile_lcdc_info
*pdata
= pdev
->dev
.platform_data
;
1830 struct sh_mobile_lcdc_priv
*priv
;
1831 struct resource
*res
;
1837 dev_err(&pdev
->dev
, "no platform data defined\n");
1841 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1842 i
= platform_get_irq(pdev
, 0);
1843 if (!res
|| i
< 0) {
1844 dev_err(&pdev
->dev
, "cannot get platform resources\n");
1848 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1850 dev_err(&pdev
->dev
, "cannot allocate device data\n");
1854 priv
->dev
= &pdev
->dev
;
1855 priv
->meram_dev
= pdata
->meram_dev
;
1856 platform_set_drvdata(pdev
, priv
);
1858 error
= request_irq(i
, sh_mobile_lcdc_irq
, 0,
1859 dev_name(&pdev
->dev
), priv
);
1861 dev_err(&pdev
->dev
, "unable to request irq\n");
1866 atomic_set(&priv
->hw_usecnt
, -1);
1868 for (i
= 0, num_channels
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
1869 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ num_channels
;
1872 memcpy(&ch
->cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
1874 error
= sh_mobile_lcdc_check_interface(ch
);
1876 dev_err(&pdev
->dev
, "unsupported interface type\n");
1879 init_waitqueue_head(&ch
->frame_end_wait
);
1880 init_completion(&ch
->vsync_completion
);
1883 /* probe the backlight is there is one defined */
1884 if (ch
->cfg
.bl_info
.max_brightness
)
1885 ch
->bl
= sh_mobile_lcdc_bl_probe(&pdev
->dev
, ch
);
1887 switch (pdata
->ch
[i
].chan
) {
1888 case LCDC_CHAN_MAINLCD
:
1889 ch
->enabled
= LDCNT2R_ME
;
1890 ch
->reg_offs
= lcdc_offs_mainlcd
;
1893 case LCDC_CHAN_SUBLCD
:
1894 ch
->enabled
= LDCNT2R_SE
;
1895 ch
->reg_offs
= lcdc_offs_sublcd
;
1901 if (!num_channels
) {
1902 dev_err(&pdev
->dev
, "no channels defined\n");
1907 /* for dual channel LCDC (MAIN + SUB) force shared format setting */
1908 if (num_channels
== 2)
1909 priv
->forced_fourcc
= pdata
->ch
[0].fourcc
;
1911 priv
->base
= ioremap_nocache(res
->start
, resource_size(res
));
1915 error
= sh_mobile_lcdc_setup_clocks(priv
, pdata
->clock_source
);
1917 dev_err(&pdev
->dev
, "unable to setup clocks\n");
1921 /* Enable runtime PM. */
1922 pm_runtime_enable(&pdev
->dev
);
1924 for (i
= 0; i
< num_channels
; i
++) {
1925 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
1927 error
= sh_mobile_lcdc_channel_init(priv
, ch
);
1932 error
= sh_mobile_lcdc_start(priv
);
1934 dev_err(&pdev
->dev
, "unable to start hardware\n");
1938 for (i
= 0; i
< num_channels
; i
++) {
1939 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
1940 struct fb_info
*info
= ch
->info
;
1942 if (info
->fbdefio
) {
1943 ch
->sglist
= vmalloc(sizeof(struct scatterlist
) *
1944 info
->fix
.smem_len
>> PAGE_SHIFT
);
1946 dev_err(&pdev
->dev
, "cannot allocate sglist\n");
1951 info
->bl_dev
= ch
->bl
;
1953 error
= register_framebuffer(info
);
1957 dev_info(&pdev
->dev
, "registered %s/%s as %dx%d %dbpp.\n",
1958 pdev
->name
, (ch
->cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
1959 "mainlcd" : "sublcd", info
->var
.xres
, info
->var
.yres
,
1960 info
->var
.bits_per_pixel
);
1962 /* deferred io mode: disable clock to save power */
1963 if (info
->fbdefio
|| info
->state
== FBINFO_STATE_SUSPENDED
)
1964 sh_mobile_lcdc_clk_off(priv
);
1967 /* Failure ignored */
1968 priv
->notifier
.notifier_call
= sh_mobile_lcdc_notify
;
1969 fb_register_client(&priv
->notifier
);
1973 sh_mobile_lcdc_remove(pdev
);
1978 static struct platform_driver sh_mobile_lcdc_driver
= {
1980 .name
= "sh_mobile_lcdc_fb",
1981 .owner
= THIS_MODULE
,
1982 .pm
= &sh_mobile_lcdc_dev_pm_ops
,
1984 .probe
= sh_mobile_lcdc_probe
,
1985 .remove
= sh_mobile_lcdc_remove
,
1988 module_platform_driver(sh_mobile_lcdc_driver
);
1990 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1991 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1992 MODULE_LICENSE("GPL v2");