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 <linux/module.h>
27 #include <video/sh_mobile_lcdc.h>
28 #include <video/sh_mobile_meram.h>
29 #include <linux/atomic.h>
31 #include "sh_mobile_lcdcfb.h"
33 #define SIDE_B_OFFSET 0x1000
34 #define MIRROR_OFFSET 0x2000
39 static unsigned long lcdc_offs_mainlcd
[NR_CH_REGS
] = {
59 static unsigned long lcdc_offs_sublcd
[NR_CH_REGS
] = {
77 static const struct fb_videomode default_720p
= {
92 .sync
= FB_SYNC_VERT_HIGH_ACT
| FB_SYNC_HOR_HIGH_ACT
,
95 struct sh_mobile_lcdc_priv
{
101 unsigned long lddckr
;
102 struct sh_mobile_lcdc_chan ch
[2];
103 struct notifier_block notifier
;
105 int forced_bpp
; /* 2 channel LCDC must share bpp setting */
106 struct sh_mobile_meram_info
*meram_dev
;
109 static bool banked(int reg_nr
)
129 static void lcdc_write_chan(struct sh_mobile_lcdc_chan
*chan
,
130 int reg_nr
, unsigned long data
)
132 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
134 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
] +
138 static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan
*chan
,
139 int reg_nr
, unsigned long data
)
141 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
] +
145 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan
*chan
,
148 return ioread32(chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
151 static void lcdc_write(struct sh_mobile_lcdc_priv
*priv
,
152 unsigned long reg_offs
, unsigned long data
)
154 iowrite32(data
, priv
->base
+ reg_offs
);
157 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv
*priv
,
158 unsigned long reg_offs
)
160 return ioread32(priv
->base
+ reg_offs
);
163 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv
*priv
,
164 unsigned long reg_offs
,
165 unsigned long mask
, unsigned long until
)
167 while ((lcdc_read(priv
, reg_offs
) & mask
) != until
)
171 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan
*chan
)
173 return chan
->cfg
.chan
== LCDC_CHAN_SUBLCD
;
176 static void lcdc_sys_write_index(void *handle
, unsigned long data
)
178 struct sh_mobile_lcdc_chan
*ch
= handle
;
180 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| LDDWDxR_WDACT
);
181 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
182 lcdc_write(ch
->lcdc
, _LDDWAR
, LDDWAR_WA
|
183 (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
184 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
187 static void lcdc_sys_write_data(void *handle
, unsigned long data
)
189 struct sh_mobile_lcdc_chan
*ch
= handle
;
191 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| LDDWDxR_WDACT
| LDDWDxR_RSW
);
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 unsigned long lcdc_sys_read_data(void *handle
)
200 struct sh_mobile_lcdc_chan
*ch
= handle
;
202 lcdc_write(ch
->lcdc
, _LDDRDR
, LDDRDR_RSR
);
203 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
204 lcdc_write(ch
->lcdc
, _LDDRAR
, LDDRAR_RA
|
205 (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
207 lcdc_wait_bit(ch
->lcdc
, _LDSR
, LDSR_AS
, 0);
209 return lcdc_read(ch
->lcdc
, _LDDRDR
) & LDDRDR_DRD_MASK
;
212 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops
= {
213 lcdc_sys_write_index
,
218 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
)
220 if (atomic_inc_and_test(&priv
->hw_usecnt
)) {
222 clk_enable(priv
->dot_clk
);
223 pm_runtime_get_sync(priv
->dev
);
224 if (priv
->meram_dev
&& priv
->meram_dev
->pdev
)
225 pm_runtime_get_sync(&priv
->meram_dev
->pdev
->dev
);
229 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
)
231 if (atomic_sub_return(1, &priv
->hw_usecnt
) == -1) {
232 if (priv
->meram_dev
&& priv
->meram_dev
->pdev
)
233 pm_runtime_put_sync(&priv
->meram_dev
->pdev
->dev
);
234 pm_runtime_put(priv
->dev
);
236 clk_disable(priv
->dot_clk
);
240 static int sh_mobile_lcdc_sginit(struct fb_info
*info
,
241 struct list_head
*pagelist
)
243 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
244 unsigned int nr_pages_max
= info
->fix
.smem_len
>> PAGE_SHIFT
;
248 sg_init_table(ch
->sglist
, nr_pages_max
);
250 list_for_each_entry(page
, pagelist
, lru
)
251 sg_set_page(&ch
->sglist
[nr_pages
++], page
, PAGE_SIZE
, 0);
256 static void sh_mobile_lcdc_deferred_io(struct fb_info
*info
,
257 struct list_head
*pagelist
)
259 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
260 struct sh_mobile_lcdc_board_cfg
*bcfg
= &ch
->cfg
.board_cfg
;
262 /* enable clocks before accessing hardware */
263 sh_mobile_lcdc_clk_on(ch
->lcdc
);
266 * It's possible to get here without anything on the pagelist via
267 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
268 * invocation. In the former case, the acceleration routines are
269 * stepped in to when using the framebuffer console causing the
270 * workqueue to be scheduled without any dirty pages on the list.
272 * Despite this, a panel update is still needed given that the
273 * acceleration routines have their own methods for writing in
274 * that still need to be updated.
276 * The fsync() and empty pagelist case could be optimized for,
277 * but we don't bother, as any application exhibiting such
278 * behaviour is fundamentally broken anyways.
280 if (!list_empty(pagelist
)) {
281 unsigned int nr_pages
= sh_mobile_lcdc_sginit(info
, pagelist
);
283 /* trigger panel update */
284 dma_map_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
285 if (bcfg
->start_transfer
)
286 bcfg
->start_transfer(bcfg
->board_data
, ch
,
287 &sh_mobile_lcdc_sys_bus_ops
);
288 lcdc_write_chan(ch
, LDSM2R
, LDSM2R_OSTRG
);
289 dma_unmap_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
291 if (bcfg
->start_transfer
)
292 bcfg
->start_transfer(bcfg
->board_data
, ch
,
293 &sh_mobile_lcdc_sys_bus_ops
);
294 lcdc_write_chan(ch
, LDSM2R
, LDSM2R_OSTRG
);
298 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info
*info
)
300 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
303 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
306 static irqreturn_t
sh_mobile_lcdc_irq(int irq
, void *data
)
308 struct sh_mobile_lcdc_priv
*priv
= data
;
309 struct sh_mobile_lcdc_chan
*ch
;
310 unsigned long ldintr
;
314 /* Acknowledge interrupts and disable further VSYNC End IRQs. */
315 ldintr
= lcdc_read(priv
, _LDINTR
);
316 lcdc_write(priv
, _LDINTR
, (ldintr
^ LDINTR_STATUS_MASK
) & ~LDINTR_VEE
);
318 /* figure out if this interrupt is for main or sub lcd */
319 is_sub
= (lcdc_read(priv
, _LDSR
) & LDSR_MSS
) ? 1 : 0;
321 /* wake up channel and disable clocks */
322 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
329 if (ldintr
& LDINTR_FS
) {
330 if (is_sub
== lcdc_chan_is_sublcd(ch
)) {
332 wake_up(&ch
->frame_end_wait
);
334 sh_mobile_lcdc_clk_off(priv
);
339 if (ldintr
& LDINTR_VES
)
340 complete(&ch
->vsync_completion
);
346 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv
*priv
,
349 unsigned long tmp
= lcdc_read(priv
, _LDCNT2R
);
352 /* start or stop the lcdc */
354 lcdc_write(priv
, _LDCNT2R
, tmp
| LDCNT2R_DO
);
356 lcdc_write(priv
, _LDCNT2R
, tmp
& ~LDCNT2R_DO
);
358 /* wait until power is applied/stopped on all channels */
359 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
360 if (lcdc_read(priv
, _LDCNT2R
) & priv
->ch
[k
].enabled
)
362 tmp
= lcdc_read_chan(&priv
->ch
[k
], LDPMR
)
364 if (start
&& tmp
== LDPMR_LPS
)
366 if (!start
&& tmp
== 0)
372 lcdc_write(priv
, _LDDCKSTPR
, 1); /* stop dotclock */
375 static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan
*ch
)
377 struct fb_var_screeninfo
*var
= &ch
->info
->var
, *display_var
= &ch
->display_var
;
378 unsigned long h_total
, hsync_pos
, display_h_total
;
381 tmp
= ch
->ldmt1r_value
;
382 tmp
|= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : LDMT1R_VPOL
;
383 tmp
|= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : LDMT1R_HPOL
;
384 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWPOL
) ? LDMT1R_DWPOL
: 0;
385 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DIPOL
) ? LDMT1R_DIPOL
: 0;
386 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DAPOL
) ? LDMT1R_DAPOL
: 0;
387 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_HSCNT
) ? LDMT1R_HSCNT
: 0;
388 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWCNT
) ? LDMT1R_DWCNT
: 0;
389 lcdc_write_chan(ch
, LDMT1R
, tmp
);
392 lcdc_write_chan(ch
, LDMT2R
, ch
->cfg
.sys_bus_cfg
.ldmt2r
);
393 lcdc_write_chan(ch
, LDMT3R
, ch
->cfg
.sys_bus_cfg
.ldmt3r
);
395 /* horizontal configuration */
396 h_total
= display_var
->xres
+ display_var
->hsync_len
+
397 display_var
->left_margin
+ display_var
->right_margin
;
398 tmp
= h_total
/ 8; /* HTCN */
399 tmp
|= (min(display_var
->xres
, var
->xres
) / 8) << 16; /* HDCN */
400 lcdc_write_chan(ch
, LDHCNR
, tmp
);
402 hsync_pos
= display_var
->xres
+ display_var
->right_margin
;
403 tmp
= hsync_pos
/ 8; /* HSYNP */
404 tmp
|= (display_var
->hsync_len
/ 8) << 16; /* HSYNW */
405 lcdc_write_chan(ch
, LDHSYNR
, tmp
);
407 /* vertical configuration */
408 tmp
= display_var
->yres
+ display_var
->vsync_len
+
409 display_var
->upper_margin
+ display_var
->lower_margin
; /* VTLN */
410 tmp
|= min(display_var
->yres
, var
->yres
) << 16; /* VDLN */
411 lcdc_write_chan(ch
, LDVLNR
, tmp
);
413 tmp
= display_var
->yres
+ display_var
->lower_margin
; /* VSYNP */
414 tmp
|= display_var
->vsync_len
<< 16; /* VSYNW */
415 lcdc_write_chan(ch
, LDVSYNR
, tmp
);
417 /* Adjust horizontal synchronisation for HDMI */
418 display_h_total
= display_var
->xres
+ display_var
->hsync_len
+
419 display_var
->left_margin
+ display_var
->right_margin
;
420 tmp
= ((display_var
->xres
& 7) << 24) |
421 ((display_h_total
& 7) << 16) |
422 ((display_var
->hsync_len
& 7) << 8) |
424 lcdc_write_chan(ch
, LDHAJR
, tmp
);
428 * __sh_mobile_lcdc_start - Configure and tart the LCDC
431 * Configure all enabled channels and start the LCDC device. All external
432 * devices (clocks, MERAM, panels, ...) are not touched by this function.
434 static void __sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
436 struct sh_mobile_lcdc_chan
*ch
;
441 /* Enable LCDC channels. Read data from external memory, avoid using the
444 lcdc_write(priv
, _LDCNT2R
, priv
->ch
[0].enabled
| priv
->ch
[1].enabled
);
446 /* Stop the LCDC first and disable all interrupts. */
447 sh_mobile_lcdc_start_stop(priv
, 0);
448 lcdc_write(priv
, _LDINTR
, 0);
450 /* Configure power supply, dot clocks and start them. */
452 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
458 bpp
= ch
->info
->var
.bits_per_pixel
;
461 lcdc_write_chan(ch
, LDPMR
, 0);
463 m
= ch
->cfg
.clock_divider
;
467 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider
470 lcdc_write_chan(ch
, LDDCKPAT1R
, 0);
471 lcdc_write_chan(ch
, LDDCKPAT2R
, (1 << (m
/2)) - 1);
475 tmp
|= m
<< (lcdc_chan_is_sublcd(ch
) ? 8 : 0);
478 lcdc_write(priv
, _LDDCKR
, tmp
);
479 lcdc_write(priv
, _LDDCKSTPR
, 0);
480 lcdc_wait_bit(priv
, _LDDCKSTPR
, ~0, 0);
482 /* Setup geometry, format, frame buffer memory and operation mode. */
483 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
488 sh_mobile_lcdc_geometry(ch
);
490 if (ch
->info
->var
.nonstd
) {
491 tmp
= (ch
->info
->var
.nonstd
<< 16);
492 switch (ch
->info
->var
.bits_per_pixel
) {
505 switch (ch
->info
->var
.bits_per_pixel
) {
507 tmp
= LDDFR_PKF_RGB16
;
510 tmp
= LDDFR_PKF_RGB24
;
514 tmp
= LDDFR_PKF_ARGB32
;
519 lcdc_write_chan(ch
, LDDFR
, tmp
);
520 lcdc_write_chan(ch
, LDMLSR
, ch
->pitch
);
521 lcdc_write_chan(ch
, LDSA1R
, ch
->base_addr_y
);
522 if (ch
->info
->var
.nonstd
)
523 lcdc_write_chan(ch
, LDSA2R
, ch
->base_addr_c
);
525 /* When using deferred I/O mode, configure the LCDC for one-shot
526 * operation and enable the frame end interrupt. Otherwise use
527 * continuous read mode.
529 if (ch
->ldmt1r_value
& LDMT1R_IFM
&&
530 ch
->cfg
.sys_bus_cfg
.deferred_io_msec
) {
531 lcdc_write_chan(ch
, LDSM1R
, LDSM1R_OS
);
532 lcdc_write(priv
, _LDINTR
, LDINTR_FE
);
534 lcdc_write_chan(ch
, LDSM1R
, 0);
538 /* Word and long word swap. */
539 if (priv
->ch
[0].info
->var
.nonstd
)
540 tmp
= LDDDSR_LS
| LDDDSR_WS
| LDDDSR_BS
;
544 tmp
= LDDDSR_LS
| LDDDSR_WS
;
547 tmp
= LDDDSR_LS
| LDDDSR_WS
| LDDDSR_BS
;
555 lcdc_write(priv
, _LDDDSR
, tmp
);
557 /* Enable the display output. */
558 lcdc_write(priv
, _LDCNT1R
, LDCNT1R_DE
);
559 sh_mobile_lcdc_start_stop(priv
, 1);
563 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
565 struct sh_mobile_meram_info
*mdev
= priv
->meram_dev
;
566 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
567 struct sh_mobile_lcdc_chan
*ch
;
572 /* enable clocks before accessing the hardware */
573 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
574 if (priv
->ch
[k
].enabled
)
575 sh_mobile_lcdc_clk_on(priv
);
579 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) | LDCNT2R_BR
);
580 lcdc_wait_bit(priv
, _LDCNT2R
, LDCNT2R_BR
, 0);
582 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
588 board_cfg
= &ch
->cfg
.board_cfg
;
589 if (board_cfg
->setup_sys
) {
590 ret
= board_cfg
->setup_sys(board_cfg
->board_data
, ch
,
591 &sh_mobile_lcdc_sys_bus_ops
);
597 /* Compute frame buffer base address and pitch for each channel. */
598 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
599 struct sh_mobile_meram_cfg
*cfg
;
606 ch
->base_addr_y
= ch
->info
->fix
.smem_start
;
607 ch
->base_addr_c
= ch
->base_addr_y
609 * ch
->info
->var
.yres_virtual
;
610 ch
->pitch
= ch
->info
->fix
.line_length
;
612 /* Enable MERAM if possible. */
613 cfg
= ch
->cfg
.meram_cfg
;
614 if (mdev
== NULL
|| mdev
->ops
== NULL
|| cfg
== NULL
)
617 /* we need to de-init configured ICBs before we can
618 * re-initialize them.
620 if (ch
->meram_enabled
) {
621 mdev
->ops
->meram_unregister(mdev
, cfg
);
622 ch
->meram_enabled
= 0;
625 if (!ch
->info
->var
.nonstd
)
626 pixelformat
= SH_MOBILE_MERAM_PF_RGB
;
627 else if (ch
->info
->var
.bits_per_pixel
== 24)
628 pixelformat
= SH_MOBILE_MERAM_PF_NV24
;
630 pixelformat
= SH_MOBILE_MERAM_PF_NV
;
632 ret
= mdev
->ops
->meram_register(mdev
, cfg
, ch
->pitch
,
633 ch
->info
->var
.yres
, pixelformat
,
634 ch
->base_addr_y
, ch
->base_addr_c
,
635 &ch
->base_addr_y
, &ch
->base_addr_c
,
638 ch
->meram_enabled
= 1;
641 /* Start the LCDC. */
642 __sh_mobile_lcdc_start(priv
);
644 /* Setup deferred I/O, tell the board code to enable the panels, and
647 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
652 tmp
= ch
->cfg
.sys_bus_cfg
.deferred_io_msec
;
653 if (ch
->ldmt1r_value
& LDMT1R_IFM
&& tmp
) {
654 ch
->defio
.deferred_io
= sh_mobile_lcdc_deferred_io
;
655 ch
->defio
.delay
= msecs_to_jiffies(tmp
);
656 ch
->info
->fbdefio
= &ch
->defio
;
657 fb_deferred_io_init(ch
->info
);
660 board_cfg
= &ch
->cfg
.board_cfg
;
661 if (board_cfg
->display_on
&& try_module_get(board_cfg
->owner
)) {
662 board_cfg
->display_on(board_cfg
->board_data
, ch
->info
);
663 module_put(board_cfg
->owner
);
667 ch
->bl
->props
.power
= FB_BLANK_UNBLANK
;
668 backlight_update_status(ch
->bl
);
675 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
677 struct sh_mobile_lcdc_chan
*ch
;
678 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
681 /* clean up deferred io and ask board code to disable panel */
682 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
688 * flush frame, and wait for frame end interrupt
689 * clean up deferred io and enable clock
691 if (ch
->info
&& ch
->info
->fbdefio
) {
693 schedule_delayed_work(&ch
->info
->deferred_work
, 0);
694 wait_event(ch
->frame_end_wait
, ch
->frame_end
);
695 fb_deferred_io_cleanup(ch
->info
);
696 ch
->info
->fbdefio
= NULL
;
697 sh_mobile_lcdc_clk_on(priv
);
701 ch
->bl
->props
.power
= FB_BLANK_POWERDOWN
;
702 backlight_update_status(ch
->bl
);
705 board_cfg
= &ch
->cfg
.board_cfg
;
706 if (board_cfg
->display_off
&& try_module_get(board_cfg
->owner
)) {
707 board_cfg
->display_off(board_cfg
->board_data
);
708 module_put(board_cfg
->owner
);
711 /* disable the meram */
712 if (ch
->meram_enabled
) {
713 struct sh_mobile_meram_cfg
*cfg
;
714 struct sh_mobile_meram_info
*mdev
;
715 cfg
= ch
->cfg
.meram_cfg
;
716 mdev
= priv
->meram_dev
;
717 mdev
->ops
->meram_unregister(mdev
, cfg
);
718 ch
->meram_enabled
= 0;
725 sh_mobile_lcdc_start_stop(priv
, 0);
730 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
731 if (priv
->ch
[k
].enabled
)
732 sh_mobile_lcdc_clk_off(priv
);
735 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
737 int interface_type
= ch
->cfg
.interface_type
;
739 switch (interface_type
) {
763 /* SUBLCD only supports SYS interface */
764 if (lcdc_chan_is_sublcd(ch
)) {
765 if (!(interface_type
& LDMT1R_IFM
))
768 interface_type
&= ~LDMT1R_IFM
;
771 ch
->ldmt1r_value
= interface_type
;
775 static int sh_mobile_lcdc_setup_clocks(struct platform_device
*pdev
,
777 struct sh_mobile_lcdc_priv
*priv
)
781 switch (clock_source
) {
784 priv
->lddckr
= LDDCKR_ICKSEL_BUS
;
786 case LCDC_CLK_PERIPHERAL
:
787 str
= "peripheral_clk";
788 priv
->lddckr
= LDDCKR_ICKSEL_MIPI
;
790 case LCDC_CLK_EXTERNAL
:
792 priv
->lddckr
= LDDCKR_ICKSEL_HDMI
;
799 priv
->dot_clk
= clk_get(&pdev
->dev
, str
);
800 if (IS_ERR(priv
->dot_clk
)) {
801 dev_err(&pdev
->dev
, "cannot get dot clock %s\n", str
);
802 return PTR_ERR(priv
->dot_clk
);
806 /* Runtime PM support involves two step for this driver:
807 * 1) Enable Runtime PM
808 * 2) Force Runtime PM Resume since hardware is accessed from probe()
810 priv
->dev
= &pdev
->dev
;
811 pm_runtime_enable(priv
->dev
);
812 pm_runtime_resume(priv
->dev
);
816 static int sh_mobile_lcdc_setcolreg(u_int regno
,
817 u_int red
, u_int green
, u_int blue
,
818 u_int transp
, struct fb_info
*info
)
820 u32
*palette
= info
->pseudo_palette
;
822 if (regno
>= PALETTE_NR
)
825 /* only FB_VISUAL_TRUECOLOR supported */
827 red
>>= 16 - info
->var
.red
.length
;
828 green
>>= 16 - info
->var
.green
.length
;
829 blue
>>= 16 - info
->var
.blue
.length
;
830 transp
>>= 16 - info
->var
.transp
.length
;
832 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
833 (green
<< info
->var
.green
.offset
) |
834 (blue
<< info
->var
.blue
.offset
) |
835 (transp
<< info
->var
.transp
.offset
);
840 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
841 .id
= "SH Mobile LCDC",
842 .type
= FB_TYPE_PACKED_PIXELS
,
843 .visual
= FB_VISUAL_TRUECOLOR
,
844 .accel
= FB_ACCEL_NONE
,
850 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
851 const struct fb_fillrect
*rect
)
853 sys_fillrect(info
, rect
);
854 sh_mobile_lcdc_deferred_io_touch(info
);
857 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
858 const struct fb_copyarea
*area
)
860 sys_copyarea(info
, area
);
861 sh_mobile_lcdc_deferred_io_touch(info
);
864 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
865 const struct fb_image
*image
)
867 sys_imageblit(info
, image
);
868 sh_mobile_lcdc_deferred_io_touch(info
);
871 static int sh_mobile_fb_pan_display(struct fb_var_screeninfo
*var
,
872 struct fb_info
*info
)
874 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
875 struct sh_mobile_lcdc_priv
*priv
= ch
->lcdc
;
876 unsigned long ldrcntr
;
877 unsigned long new_pan_offset
;
878 unsigned long base_addr_y
, base_addr_c
;
879 unsigned long c_offset
;
882 new_pan_offset
= (var
->yoffset
* info
->fix
.line_length
) +
883 (var
->xoffset
* (info
->var
.bits_per_pixel
/ 8));
885 new_pan_offset
= (var
->yoffset
* info
->fix
.line_length
) +
888 if (new_pan_offset
== ch
->pan_offset
)
889 return 0; /* No change, do nothing */
891 ldrcntr
= lcdc_read(priv
, _LDRCNTR
);
893 /* Set the source address for the next refresh */
894 base_addr_y
= ch
->dma_handle
+ new_pan_offset
;
897 c_offset
= (var
->yoffset
*
898 info
->fix
.line_length
*
899 (info
->var
.bits_per_pixel
- 8)) / 8;
900 base_addr_c
= ch
->dma_handle
+ var
->xres
* var
->yres_virtual
+
903 if (info
->var
.bits_per_pixel
== 24)
904 base_addr_c
+= 2 * var
->xoffset
;
906 base_addr_c
+= var
->xoffset
;
909 if (ch
->meram_enabled
) {
910 struct sh_mobile_meram_cfg
*cfg
;
911 struct sh_mobile_meram_info
*mdev
;
914 cfg
= ch
->cfg
.meram_cfg
;
915 mdev
= priv
->meram_dev
;
916 ret
= mdev
->ops
->meram_update(mdev
, cfg
,
917 base_addr_y
, base_addr_c
,
918 &base_addr_y
, &base_addr_c
);
923 ch
->base_addr_y
= base_addr_y
;
924 ch
->base_addr_c
= base_addr_c
;
926 lcdc_write_chan_mirror(ch
, LDSA1R
, base_addr_y
);
928 lcdc_write_chan_mirror(ch
, LDSA2R
, base_addr_c
);
930 if (lcdc_chan_is_sublcd(ch
))
931 lcdc_write(ch
->lcdc
, _LDRCNTR
, ldrcntr
^ LDRCNTR_SRS
);
933 lcdc_write(ch
->lcdc
, _LDRCNTR
, ldrcntr
^ LDRCNTR_MRS
);
935 ch
->pan_offset
= new_pan_offset
;
937 sh_mobile_lcdc_deferred_io_touch(info
);
942 static int sh_mobile_wait_for_vsync(struct fb_info
*info
)
944 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
945 unsigned long ldintr
;
948 /* Enable VSync End interrupt and be careful not to acknowledge any
951 ldintr
= lcdc_read(ch
->lcdc
, _LDINTR
);
952 ldintr
|= LDINTR_VEE
| LDINTR_STATUS_MASK
;
953 lcdc_write(ch
->lcdc
, _LDINTR
, ldintr
);
955 ret
= wait_for_completion_interruptible_timeout(&ch
->vsync_completion
,
956 msecs_to_jiffies(100));
963 static int sh_mobile_ioctl(struct fb_info
*info
, unsigned int cmd
,
969 case FBIO_WAITFORVSYNC
:
970 retval
= sh_mobile_wait_for_vsync(info
);
974 retval
= -ENOIOCTLCMD
;
980 static void sh_mobile_fb_reconfig(struct fb_info
*info
)
982 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
983 struct fb_videomode mode1
, mode2
;
984 struct fb_event event
;
985 int evnt
= FB_EVENT_MODE_CHANGE_ALL
;
987 if (ch
->use_count
> 1 || (ch
->use_count
== 1 && !info
->fbcon_par
))
988 /* More framebuffer users are active */
991 fb_var_to_videomode(&mode1
, &ch
->display_var
);
992 fb_var_to_videomode(&mode2
, &info
->var
);
994 if (fb_mode_is_equal(&mode1
, &mode2
))
997 /* Display has been re-plugged, framebuffer is free now, reconfigure */
998 if (fb_set_var(info
, &ch
->display_var
) < 0)
999 /* Couldn't reconfigure, hopefully, can continue as before */
1002 if (info
->var
.nonstd
)
1003 info
->fix
.line_length
= mode1
.xres
;
1005 info
->fix
.line_length
= mode1
.xres
* (ch
->cfg
.bpp
/ 8);
1008 * fb_set_var() calls the notifier change internally, only if
1009 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1010 * user event, we have to call the chain ourselves.
1013 event
.data
= &mode1
;
1014 fb_notifier_call_chain(evnt
, &event
);
1018 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1019 * user == 1, or with console sem held, if user == 0.
1021 static int sh_mobile_release(struct fb_info
*info
, int user
)
1023 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1025 mutex_lock(&ch
->open_lock
);
1026 dev_dbg(info
->dev
, "%s(): %d users\n", __func__
, ch
->use_count
);
1030 /* Nothing to reconfigure, when called from fbcon */
1033 sh_mobile_fb_reconfig(info
);
1037 mutex_unlock(&ch
->open_lock
);
1042 static int sh_mobile_open(struct fb_info
*info
, int user
)
1044 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1046 mutex_lock(&ch
->open_lock
);
1049 dev_dbg(info
->dev
, "%s(): %d users\n", __func__
, ch
->use_count
);
1050 mutex_unlock(&ch
->open_lock
);
1055 static int sh_mobile_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1057 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1058 struct sh_mobile_lcdc_priv
*p
= ch
->lcdc
;
1060 if (var
->xres
> MAX_XRES
|| var
->yres
> MAX_YRES
||
1061 var
->xres
* var
->yres
* (ch
->cfg
.bpp
/ 8) * 2 > info
->fix
.smem_len
) {
1062 dev_warn(info
->dev
, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
1063 var
->left_margin
, var
->xres
, var
->right_margin
, var
->hsync_len
,
1064 var
->upper_margin
, var
->yres
, var
->lower_margin
, var
->vsync_len
,
1065 PICOS2KHZ(var
->pixclock
));
1069 /* only accept the forced_bpp for dual channel configurations */
1070 if (p
->forced_bpp
&& p
->forced_bpp
!= var
->bits_per_pixel
)
1073 switch (var
->bits_per_pixel
) {
1074 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1075 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1076 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1086 * Screen blanking. Behavior is as follows:
1087 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1088 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1091 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1093 static int sh_mobile_lcdc_blank(int blank
, struct fb_info
*info
)
1095 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1096 struct sh_mobile_lcdc_priv
*p
= ch
->lcdc
;
1098 /* blank the screen? */
1099 if (blank
> FB_BLANK_UNBLANK
&& ch
->blank_status
== FB_BLANK_UNBLANK
) {
1100 struct fb_fillrect rect
= {
1101 .width
= info
->var
.xres
,
1102 .height
= info
->var
.yres
,
1104 sh_mobile_lcdc_fillrect(info
, &rect
);
1106 /* turn clocks on? */
1107 if (blank
<= FB_BLANK_NORMAL
&& ch
->blank_status
> FB_BLANK_NORMAL
) {
1108 sh_mobile_lcdc_clk_on(p
);
1110 /* turn clocks off? */
1111 if (blank
> FB_BLANK_NORMAL
&& ch
->blank_status
<= FB_BLANK_NORMAL
) {
1112 /* make sure the screen is updated with the black fill before
1113 * switching the clocks off. one vsync is not enough since
1114 * blanking may occur in the middle of a refresh. deferred io
1115 * mode will reenable the clocks and update the screen in time,
1116 * so it does not need this. */
1117 if (!info
->fbdefio
) {
1118 sh_mobile_wait_for_vsync(info
);
1119 sh_mobile_wait_for_vsync(info
);
1121 sh_mobile_lcdc_clk_off(p
);
1124 ch
->blank_status
= blank
;
1128 static struct fb_ops sh_mobile_lcdc_ops
= {
1129 .owner
= THIS_MODULE
,
1130 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
1131 .fb_read
= fb_sys_read
,
1132 .fb_write
= fb_sys_write
,
1133 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
1134 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
1135 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
1136 .fb_blank
= sh_mobile_lcdc_blank
,
1137 .fb_pan_display
= sh_mobile_fb_pan_display
,
1138 .fb_ioctl
= sh_mobile_ioctl
,
1139 .fb_open
= sh_mobile_open
,
1140 .fb_release
= sh_mobile_release
,
1141 .fb_check_var
= sh_mobile_check_var
,
1144 static int sh_mobile_lcdc_update_bl(struct backlight_device
*bdev
)
1146 struct sh_mobile_lcdc_chan
*ch
= bl_get_data(bdev
);
1147 struct sh_mobile_lcdc_board_cfg
*cfg
= &ch
->cfg
.board_cfg
;
1148 int brightness
= bdev
->props
.brightness
;
1150 if (bdev
->props
.power
!= FB_BLANK_UNBLANK
||
1151 bdev
->props
.state
& (BL_CORE_SUSPENDED
| BL_CORE_FBBLANK
))
1154 return cfg
->set_brightness(cfg
->board_data
, brightness
);
1157 static int sh_mobile_lcdc_get_brightness(struct backlight_device
*bdev
)
1159 struct sh_mobile_lcdc_chan
*ch
= bl_get_data(bdev
);
1160 struct sh_mobile_lcdc_board_cfg
*cfg
= &ch
->cfg
.board_cfg
;
1162 return cfg
->get_brightness(cfg
->board_data
);
1165 static int sh_mobile_lcdc_check_fb(struct backlight_device
*bdev
,
1166 struct fb_info
*info
)
1168 return (info
->bl_dev
== bdev
);
1171 static struct backlight_ops sh_mobile_lcdc_bl_ops
= {
1172 .options
= BL_CORE_SUSPENDRESUME
,
1173 .update_status
= sh_mobile_lcdc_update_bl
,
1174 .get_brightness
= sh_mobile_lcdc_get_brightness
,
1175 .check_fb
= sh_mobile_lcdc_check_fb
,
1178 static struct backlight_device
*sh_mobile_lcdc_bl_probe(struct device
*parent
,
1179 struct sh_mobile_lcdc_chan
*ch
)
1181 struct backlight_device
*bl
;
1183 bl
= backlight_device_register(ch
->cfg
.bl_info
.name
, parent
, ch
,
1184 &sh_mobile_lcdc_bl_ops
, NULL
);
1186 dev_err(parent
, "unable to register backlight device: %ld\n",
1191 bl
->props
.max_brightness
= ch
->cfg
.bl_info
.max_brightness
;
1192 bl
->props
.brightness
= bl
->props
.max_brightness
;
1193 backlight_update_status(bl
);
1198 static void sh_mobile_lcdc_bl_remove(struct backlight_device
*bdev
)
1200 backlight_device_unregister(bdev
);
1203 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo
*var
, int bpp
,
1211 var
->bits_per_pixel
= bpp
;
1212 var
->nonstd
= nonstd
;
1220 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1221 var
->red
.offset
= 11;
1222 var
->red
.length
= 5;
1223 var
->green
.offset
= 5;
1224 var
->green
.length
= 6;
1225 var
->blue
.offset
= 0;
1226 var
->blue
.length
= 5;
1227 var
->transp
.offset
= 0;
1228 var
->transp
.length
= 0;
1231 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1232 var
->red
.offset
= 16;
1233 var
->red
.length
= 8;
1234 var
->green
.offset
= 8;
1235 var
->green
.length
= 8;
1236 var
->blue
.offset
= 0;
1237 var
->blue
.length
= 8;
1238 var
->transp
.offset
= 0;
1239 var
->transp
.length
= 0;
1242 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1243 var
->red
.offset
= 16;
1244 var
->red
.length
= 8;
1245 var
->green
.offset
= 8;
1246 var
->green
.length
= 8;
1247 var
->blue
.offset
= 0;
1248 var
->blue
.length
= 8;
1249 var
->transp
.offset
= 24;
1250 var
->transp
.length
= 8;
1255 var
->bits_per_pixel
= bpp
;
1256 var
->red
.msb_right
= 0;
1257 var
->green
.msb_right
= 0;
1258 var
->blue
.msb_right
= 0;
1259 var
->transp
.msb_right
= 0;
1263 static int sh_mobile_lcdc_suspend(struct device
*dev
)
1265 struct platform_device
*pdev
= to_platform_device(dev
);
1267 sh_mobile_lcdc_stop(platform_get_drvdata(pdev
));
1271 static int sh_mobile_lcdc_resume(struct device
*dev
)
1273 struct platform_device
*pdev
= to_platform_device(dev
);
1275 return sh_mobile_lcdc_start(platform_get_drvdata(pdev
));
1278 static int sh_mobile_lcdc_runtime_suspend(struct device
*dev
)
1280 struct platform_device
*pdev
= to_platform_device(dev
);
1281 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1283 /* turn off LCDC hardware */
1284 lcdc_write(priv
, _LDCNT1R
, 0);
1289 static int sh_mobile_lcdc_runtime_resume(struct device
*dev
)
1291 struct platform_device
*pdev
= to_platform_device(dev
);
1292 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1294 __sh_mobile_lcdc_start(priv
);
1299 static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops
= {
1300 .suspend
= sh_mobile_lcdc_suspend
,
1301 .resume
= sh_mobile_lcdc_resume
,
1302 .runtime_suspend
= sh_mobile_lcdc_runtime_suspend
,
1303 .runtime_resume
= sh_mobile_lcdc_runtime_resume
,
1306 /* locking: called with info->lock held */
1307 static int sh_mobile_lcdc_notify(struct notifier_block
*nb
,
1308 unsigned long action
, void *data
)
1310 struct fb_event
*event
= data
;
1311 struct fb_info
*info
= event
->info
;
1312 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1313 struct sh_mobile_lcdc_board_cfg
*board_cfg
= &ch
->cfg
.board_cfg
;
1315 if (&ch
->lcdc
->notifier
!= nb
)
1318 dev_dbg(info
->dev
, "%s(): action = %lu, data = %p\n",
1319 __func__
, action
, event
->data
);
1322 case FB_EVENT_SUSPEND
:
1323 if (board_cfg
->display_off
&& try_module_get(board_cfg
->owner
)) {
1324 board_cfg
->display_off(board_cfg
->board_data
);
1325 module_put(board_cfg
->owner
);
1327 sh_mobile_lcdc_stop(ch
->lcdc
);
1329 case FB_EVENT_RESUME
:
1330 mutex_lock(&ch
->open_lock
);
1331 sh_mobile_fb_reconfig(info
);
1332 mutex_unlock(&ch
->open_lock
);
1334 /* HDMI must be enabled before LCDC configuration */
1335 if (board_cfg
->display_on
&& try_module_get(board_cfg
->owner
)) {
1336 board_cfg
->display_on(board_cfg
->board_data
, info
);
1337 module_put(board_cfg
->owner
);
1340 sh_mobile_lcdc_start(ch
->lcdc
);
1346 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
);
1348 static int __devinit
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
1350 struct fb_info
*info
;
1351 struct sh_mobile_lcdc_priv
*priv
;
1352 struct sh_mobile_lcdc_info
*pdata
= pdev
->dev
.platform_data
;
1353 struct resource
*res
;
1359 dev_err(&pdev
->dev
, "no platform data defined\n");
1363 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1364 i
= platform_get_irq(pdev
, 0);
1365 if (!res
|| i
< 0) {
1366 dev_err(&pdev
->dev
, "cannot get platform resources\n");
1370 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1372 dev_err(&pdev
->dev
, "cannot allocate device data\n");
1376 platform_set_drvdata(pdev
, priv
);
1378 error
= request_irq(i
, sh_mobile_lcdc_irq
, IRQF_DISABLED
,
1379 dev_name(&pdev
->dev
), priv
);
1381 dev_err(&pdev
->dev
, "unable to request irq\n");
1386 atomic_set(&priv
->hw_usecnt
, -1);
1389 for (i
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
1390 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ j
;
1393 memcpy(&ch
->cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
1395 error
= sh_mobile_lcdc_check_interface(ch
);
1397 dev_err(&pdev
->dev
, "unsupported interface type\n");
1400 init_waitqueue_head(&ch
->frame_end_wait
);
1401 init_completion(&ch
->vsync_completion
);
1404 /* probe the backlight is there is one defined */
1405 if (ch
->cfg
.bl_info
.max_brightness
)
1406 ch
->bl
= sh_mobile_lcdc_bl_probe(&pdev
->dev
, ch
);
1408 switch (pdata
->ch
[i
].chan
) {
1409 case LCDC_CHAN_MAINLCD
:
1410 ch
->enabled
= LDCNT2R_ME
;
1411 ch
->reg_offs
= lcdc_offs_mainlcd
;
1414 case LCDC_CHAN_SUBLCD
:
1415 ch
->enabled
= LDCNT2R_SE
;
1416 ch
->reg_offs
= lcdc_offs_sublcd
;
1423 dev_err(&pdev
->dev
, "no channels defined\n");
1428 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1430 priv
->forced_bpp
= pdata
->ch
[0].bpp
;
1432 priv
->base
= ioremap_nocache(res
->start
, resource_size(res
));
1436 error
= sh_mobile_lcdc_setup_clocks(pdev
, pdata
->clock_source
, priv
);
1438 dev_err(&pdev
->dev
, "unable to setup clocks\n");
1442 priv
->meram_dev
= pdata
->meram_dev
;
1444 for (i
= 0; i
< j
; i
++) {
1445 struct fb_var_screeninfo
*var
;
1446 const struct fb_videomode
*lcd_cfg
, *max_cfg
= NULL
;
1447 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
1448 struct sh_mobile_lcdc_chan_cfg
*cfg
= &ch
->cfg
;
1449 const struct fb_videomode
*mode
= cfg
->lcd_cfg
;
1450 unsigned long max_size
= 0;
1454 ch
->info
= framebuffer_alloc(0, &pdev
->dev
);
1456 dev_err(&pdev
->dev
, "unable to allocate fb_info\n");
1463 info
->fbops
= &sh_mobile_lcdc_ops
;
1466 mutex_init(&ch
->open_lock
);
1468 for (k
= 0, lcd_cfg
= mode
;
1469 k
< cfg
->num_cfg
&& lcd_cfg
;
1471 unsigned long size
= lcd_cfg
->yres
* lcd_cfg
->xres
;
1472 /* NV12 buffers must have even number of lines */
1473 if ((cfg
->nonstd
) && cfg
->bpp
== 12 &&
1474 (lcd_cfg
->yres
& 0x1)) {
1475 dev_err(&pdev
->dev
, "yres must be multiple of 2"
1476 " for YCbCr420 mode.\n");
1481 if (size
> max_size
) {
1488 max_size
= MAX_XRES
* MAX_YRES
;
1490 dev_dbg(&pdev
->dev
, "Found largest videomode %ux%u\n",
1491 max_cfg
->xres
, max_cfg
->yres
);
1493 info
->fix
= sh_mobile_lcdc_fix
;
1494 info
->fix
.smem_len
= max_size
* 2 * cfg
->bpp
/ 8;
1496 /* Only pan in 2 line steps for NV12 */
1497 if (cfg
->nonstd
&& cfg
->bpp
== 12)
1498 info
->fix
.ypanstep
= 2;
1501 mode
= &default_720p
;
1504 num_cfg
= cfg
->num_cfg
;
1507 fb_videomode_to_modelist(mode
, num_cfg
, &info
->modelist
);
1509 fb_videomode_to_var(var
, mode
);
1510 var
->width
= cfg
->lcd_size_cfg
.width
;
1511 var
->height
= cfg
->lcd_size_cfg
.height
;
1512 /* Default Y virtual resolution is 2x panel size */
1513 var
->yres_virtual
= var
->yres
* 2;
1514 var
->activate
= FB_ACTIVATE_NOW
;
1516 error
= sh_mobile_lcdc_set_bpp(var
, cfg
->bpp
, cfg
->nonstd
);
1520 buf
= dma_alloc_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1521 &ch
->dma_handle
, GFP_KERNEL
);
1523 dev_err(&pdev
->dev
, "unable to allocate buffer\n");
1528 info
->pseudo_palette
= &ch
->pseudo_palette
;
1529 info
->flags
= FBINFO_FLAG_DEFAULT
;
1531 error
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
1533 dev_err(&pdev
->dev
, "unable to allocate cmap\n");
1534 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1535 buf
, ch
->dma_handle
);
1539 info
->fix
.smem_start
= ch
->dma_handle
;
1541 info
->fix
.line_length
= var
->xres
;
1543 info
->fix
.line_length
= var
->xres
* (cfg
->bpp
/ 8);
1545 info
->screen_base
= buf
;
1546 info
->device
= &pdev
->dev
;
1547 ch
->display_var
= *var
;
1553 error
= sh_mobile_lcdc_start(priv
);
1555 dev_err(&pdev
->dev
, "unable to start hardware\n");
1559 for (i
= 0; i
< j
; i
++) {
1560 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
1564 if (info
->fbdefio
) {
1565 ch
->sglist
= vmalloc(sizeof(struct scatterlist
) *
1566 info
->fix
.smem_len
>> PAGE_SHIFT
);
1568 dev_err(&pdev
->dev
, "cannot allocate sglist\n");
1573 info
->bl_dev
= ch
->bl
;
1575 error
= register_framebuffer(info
);
1580 "registered %s/%s as %dx%d %dbpp.\n",
1582 (ch
->cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
1583 "mainlcd" : "sublcd",
1584 info
->var
.xres
, info
->var
.yres
,
1587 /* deferred io mode: disable clock to save power */
1588 if (info
->fbdefio
|| info
->state
== FBINFO_STATE_SUSPENDED
)
1589 sh_mobile_lcdc_clk_off(priv
);
1592 /* Failure ignored */
1593 priv
->notifier
.notifier_call
= sh_mobile_lcdc_notify
;
1594 fb_register_client(&priv
->notifier
);
1598 sh_mobile_lcdc_remove(pdev
);
1603 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
1605 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1606 struct fb_info
*info
;
1609 fb_unregister_client(&priv
->notifier
);
1611 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
1612 if (priv
->ch
[i
].info
&& priv
->ch
[i
].info
->dev
)
1613 unregister_framebuffer(priv
->ch
[i
].info
);
1615 sh_mobile_lcdc_stop(priv
);
1617 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
1618 info
= priv
->ch
[i
].info
;
1620 if (!info
|| !info
->device
)
1623 if (priv
->ch
[i
].sglist
)
1624 vfree(priv
->ch
[i
].sglist
);
1626 if (info
->screen_base
)
1627 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1629 priv
->ch
[i
].dma_handle
);
1630 fb_dealloc_cmap(&info
->cmap
);
1631 framebuffer_release(info
);
1634 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
1636 sh_mobile_lcdc_bl_remove(priv
->ch
[i
].bl
);
1640 clk_put(priv
->dot_clk
);
1643 pm_runtime_disable(priv
->dev
);
1646 iounmap(priv
->base
);
1649 free_irq(priv
->irq
, priv
);
1654 static struct platform_driver sh_mobile_lcdc_driver
= {
1656 .name
= "sh_mobile_lcdc_fb",
1657 .owner
= THIS_MODULE
,
1658 .pm
= &sh_mobile_lcdc_dev_pm_ops
,
1660 .probe
= sh_mobile_lcdc_probe
,
1661 .remove
= sh_mobile_lcdc_remove
,
1664 static int __init
sh_mobile_lcdc_init(void)
1666 return platform_driver_register(&sh_mobile_lcdc_driver
);
1669 static void __exit
sh_mobile_lcdc_exit(void)
1671 platform_driver_unregister(&sh_mobile_lcdc_driver
);
1674 module_init(sh_mobile_lcdc_init
);
1675 module_exit(sh_mobile_lcdc_exit
);
1677 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1678 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1679 MODULE_LICENSE("GPL v2");