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 <linux/atomic.h>
30 #include "sh_mobile_lcdcfb.h"
31 #include "sh_mobile_meram.h"
33 #define SIDE_B_OFFSET 0x1000
34 #define MIRROR_OFFSET 0x2000
36 /* shared registers */
38 #define _LDDCKSTPR 0x414
41 #define _LDCNT1R 0x470
42 #define _LDCNT2R 0x474
43 #define _LDRCNTR 0x478
45 #define _LDDWD0R 0x800
50 /* shared registers and their order for context save/restore */
51 static int lcdc_shared_regs
[] = {
59 #define NR_SHARED_REGS ARRAY_SIZE(lcdc_shared_regs)
64 static unsigned long lcdc_offs_mainlcd
[NR_CH_REGS
] = {
84 static unsigned long lcdc_offs_sublcd
[NR_CH_REGS
] = {
102 #define START_LCDC 0x00000001
103 #define LCDC_RESET 0x00000100
104 #define DISPLAY_BEU 0x00000008
105 #define LCDC_ENABLE 0x00000001
106 #define LDINTR_FE 0x00000400
107 #define LDINTR_VSE 0x00000200
108 #define LDINTR_VEE 0x00000100
109 #define LDINTR_FS 0x00000004
110 #define LDINTR_VSS 0x00000002
111 #define LDINTR_VES 0x00000001
112 #define LDRCNTR_SRS 0x00020000
113 #define LDRCNTR_SRC 0x00010000
114 #define LDRCNTR_MRS 0x00000002
115 #define LDRCNTR_MRC 0x00000001
116 #define LDSR_MRS 0x00000100
118 static const struct fb_videomode default_720p
= {
133 .sync
= FB_SYNC_VERT_HIGH_ACT
| FB_SYNC_HOR_HIGH_ACT
,
136 struct sh_mobile_lcdc_priv
{
142 unsigned long lddckr
;
143 struct sh_mobile_lcdc_chan ch
[2];
144 struct notifier_block notifier
;
145 unsigned long saved_shared_regs
[NR_SHARED_REGS
];
147 int forced_bpp
; /* 2 channel LCDC must share bpp setting */
148 struct sh_mobile_meram_info
*meram_dev
;
151 static bool banked(int reg_nr
)
171 static void lcdc_write_chan(struct sh_mobile_lcdc_chan
*chan
,
172 int reg_nr
, unsigned long data
)
174 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
176 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
] +
180 static void lcdc_write_chan_mirror(struct sh_mobile_lcdc_chan
*chan
,
181 int reg_nr
, unsigned long data
)
183 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
] +
187 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan
*chan
,
190 return ioread32(chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
193 static void lcdc_write(struct sh_mobile_lcdc_priv
*priv
,
194 unsigned long reg_offs
, unsigned long data
)
196 iowrite32(data
, priv
->base
+ reg_offs
);
199 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv
*priv
,
200 unsigned long reg_offs
)
202 return ioread32(priv
->base
+ reg_offs
);
205 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv
*priv
,
206 unsigned long reg_offs
,
207 unsigned long mask
, unsigned long until
)
209 while ((lcdc_read(priv
, reg_offs
) & mask
) != until
)
213 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan
*chan
)
215 return chan
->cfg
.chan
== LCDC_CHAN_SUBLCD
;
218 static void lcdc_sys_write_index(void *handle
, unsigned long data
)
220 struct sh_mobile_lcdc_chan
*ch
= handle
;
222 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x10000000);
223 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
224 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
225 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
228 static void lcdc_sys_write_data(void *handle
, unsigned long data
)
230 struct sh_mobile_lcdc_chan
*ch
= handle
;
232 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x11000000);
233 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
234 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
235 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
238 static unsigned long lcdc_sys_read_data(void *handle
)
240 struct sh_mobile_lcdc_chan
*ch
= handle
;
242 lcdc_write(ch
->lcdc
, _LDDRDR
, 0x01000000);
243 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
244 lcdc_write(ch
->lcdc
, _LDDRAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
246 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
248 return lcdc_read(ch
->lcdc
, _LDDRDR
) & 0x3ffff;
251 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops
= {
252 lcdc_sys_write_index
,
257 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
)
259 if (atomic_inc_and_test(&priv
->hw_usecnt
)) {
260 pm_runtime_get_sync(priv
->dev
);
262 clk_enable(priv
->dot_clk
);
266 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
)
268 if (atomic_sub_return(1, &priv
->hw_usecnt
) == -1) {
270 clk_disable(priv
->dot_clk
);
271 pm_runtime_put(priv
->dev
);
275 static int sh_mobile_lcdc_sginit(struct fb_info
*info
,
276 struct list_head
*pagelist
)
278 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
279 unsigned int nr_pages_max
= info
->fix
.smem_len
>> PAGE_SHIFT
;
283 sg_init_table(ch
->sglist
, nr_pages_max
);
285 list_for_each_entry(page
, pagelist
, lru
)
286 sg_set_page(&ch
->sglist
[nr_pages
++], page
, PAGE_SIZE
, 0);
291 static void sh_mobile_lcdc_deferred_io(struct fb_info
*info
,
292 struct list_head
*pagelist
)
294 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
295 struct sh_mobile_lcdc_board_cfg
*bcfg
= &ch
->cfg
.board_cfg
;
297 /* enable clocks before accessing hardware */
298 sh_mobile_lcdc_clk_on(ch
->lcdc
);
301 * It's possible to get here without anything on the pagelist via
302 * sh_mobile_lcdc_deferred_io_touch() or via a userspace fsync()
303 * invocation. In the former case, the acceleration routines are
304 * stepped in to when using the framebuffer console causing the
305 * workqueue to be scheduled without any dirty pages on the list.
307 * Despite this, a panel update is still needed given that the
308 * acceleration routines have their own methods for writing in
309 * that still need to be updated.
311 * The fsync() and empty pagelist case could be optimized for,
312 * but we don't bother, as any application exhibiting such
313 * behaviour is fundamentally broken anyways.
315 if (!list_empty(pagelist
)) {
316 unsigned int nr_pages
= sh_mobile_lcdc_sginit(info
, pagelist
);
318 /* trigger panel update */
319 dma_map_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
320 if (bcfg
->start_transfer
)
321 bcfg
->start_transfer(bcfg
->board_data
, ch
,
322 &sh_mobile_lcdc_sys_bus_ops
);
323 lcdc_write_chan(ch
, LDSM2R
, 1);
324 dma_unmap_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
326 if (bcfg
->start_transfer
)
327 bcfg
->start_transfer(bcfg
->board_data
, ch
,
328 &sh_mobile_lcdc_sys_bus_ops
);
329 lcdc_write_chan(ch
, LDSM2R
, 1);
333 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info
*info
)
335 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
338 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
341 static irqreturn_t
sh_mobile_lcdc_irq(int irq
, void *data
)
343 struct sh_mobile_lcdc_priv
*priv
= data
;
344 struct sh_mobile_lcdc_chan
*ch
;
346 unsigned long ldintr
;
350 /* acknowledge interrupt */
351 ldintr
= tmp
= lcdc_read(priv
, _LDINTR
);
353 * disable further VSYNC End IRQs, preserve all other enabled IRQs,
354 * write 0 to bits 0-6 to ack all triggered IRQs.
356 tmp
&= 0xffffff00 & ~LDINTR_VEE
;
357 lcdc_write(priv
, _LDINTR
, tmp
);
359 /* figure out if this interrupt is for main or sub lcd */
360 is_sub
= (lcdc_read(priv
, _LDSR
) & (1 << 10)) ? 1 : 0;
362 /* wake up channel and disable clocks */
363 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
370 if (ldintr
& LDINTR_FS
) {
371 if (is_sub
== lcdc_chan_is_sublcd(ch
)) {
373 wake_up(&ch
->frame_end_wait
);
375 sh_mobile_lcdc_clk_off(priv
);
380 if (ldintr
& LDINTR_VES
)
381 complete(&ch
->vsync_completion
);
387 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv
*priv
,
390 unsigned long tmp
= lcdc_read(priv
, _LDCNT2R
);
393 /* start or stop the lcdc */
395 lcdc_write(priv
, _LDCNT2R
, tmp
| START_LCDC
);
397 lcdc_write(priv
, _LDCNT2R
, tmp
& ~START_LCDC
);
399 /* wait until power is applied/stopped on all channels */
400 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
401 if (lcdc_read(priv
, _LDCNT2R
) & priv
->ch
[k
].enabled
)
403 tmp
= lcdc_read_chan(&priv
->ch
[k
], LDPMR
) & 3;
404 if (start
&& tmp
== 3)
406 if (!start
&& tmp
== 0)
412 lcdc_write(priv
, _LDDCKSTPR
, 1); /* stop dotclock */
415 static void sh_mobile_lcdc_geometry(struct sh_mobile_lcdc_chan
*ch
)
417 struct fb_var_screeninfo
*var
= &ch
->info
->var
, *display_var
= &ch
->display_var
;
418 unsigned long h_total
, hsync_pos
, display_h_total
;
421 tmp
= ch
->ldmt1r_value
;
422 tmp
|= (var
->sync
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : 1 << 28;
423 tmp
|= (var
->sync
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : 1 << 27;
424 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWPOL
) ? 1 << 26 : 0;
425 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DIPOL
) ? 1 << 25 : 0;
426 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DAPOL
) ? 1 << 24 : 0;
427 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_HSCNT
) ? 1 << 17 : 0;
428 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWCNT
) ? 1 << 16 : 0;
429 lcdc_write_chan(ch
, LDMT1R
, tmp
);
432 lcdc_write_chan(ch
, LDMT2R
, ch
->cfg
.sys_bus_cfg
.ldmt2r
);
433 lcdc_write_chan(ch
, LDMT3R
, ch
->cfg
.sys_bus_cfg
.ldmt3r
);
435 /* horizontal configuration */
436 h_total
= display_var
->xres
+ display_var
->hsync_len
+
437 display_var
->left_margin
+ display_var
->right_margin
;
438 tmp
= h_total
/ 8; /* HTCN */
439 tmp
|= (min(display_var
->xres
, var
->xres
) / 8) << 16; /* HDCN */
440 lcdc_write_chan(ch
, LDHCNR
, tmp
);
442 hsync_pos
= display_var
->xres
+ display_var
->right_margin
;
443 tmp
= hsync_pos
/ 8; /* HSYNP */
444 tmp
|= (display_var
->hsync_len
/ 8) << 16; /* HSYNW */
445 lcdc_write_chan(ch
, LDHSYNR
, tmp
);
447 /* vertical configuration */
448 tmp
= display_var
->yres
+ display_var
->vsync_len
+
449 display_var
->upper_margin
+ display_var
->lower_margin
; /* VTLN */
450 tmp
|= min(display_var
->yres
, var
->yres
) << 16; /* VDLN */
451 lcdc_write_chan(ch
, LDVLNR
, tmp
);
453 tmp
= display_var
->yres
+ display_var
->lower_margin
; /* VSYNP */
454 tmp
|= display_var
->vsync_len
<< 16; /* VSYNW */
455 lcdc_write_chan(ch
, LDVSYNR
, tmp
);
457 /* Adjust horizontal synchronisation for HDMI */
458 display_h_total
= display_var
->xres
+ display_var
->hsync_len
+
459 display_var
->left_margin
+ display_var
->right_margin
;
460 tmp
= ((display_var
->xres
& 7) << 24) |
461 ((display_h_total
& 7) << 16) |
462 ((display_var
->hsync_len
& 7) << 8) |
464 lcdc_write_chan(ch
, LDHAJR
, tmp
);
467 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
469 struct sh_mobile_lcdc_chan
*ch
;
470 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
473 unsigned long ldddsr
;
476 /* enable clocks before accessing the hardware */
477 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
478 if (priv
->ch
[k
].enabled
) {
479 sh_mobile_lcdc_clk_on(priv
);
481 bpp
= priv
->ch
[k
].info
->var
.bits_per_pixel
;
486 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) | LCDC_RESET
);
487 lcdc_wait_bit(priv
, _LDCNT2R
, LCDC_RESET
, 0);
489 /* enable LCDC channels */
490 tmp
= lcdc_read(priv
, _LDCNT2R
);
491 tmp
|= priv
->ch
[0].enabled
;
492 tmp
|= priv
->ch
[1].enabled
;
493 lcdc_write(priv
, _LDCNT2R
, tmp
);
495 /* read data from external memory, avoid using the BEU for now */
496 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) & ~DISPLAY_BEU
);
498 /* stop the lcdc first */
499 sh_mobile_lcdc_start_stop(priv
, 0);
501 /* configure clocks */
503 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
506 if (!priv
->ch
[k
].enabled
)
509 m
= ch
->cfg
.clock_divider
;
515 tmp
|= m
<< (lcdc_chan_is_sublcd(ch
) ? 8 : 0);
517 /* FIXME: sh7724 can only use 42, 48, 54 and 60 for the divider denominator */
518 lcdc_write_chan(ch
, LDDCKPAT1R
, 0);
519 lcdc_write_chan(ch
, LDDCKPAT2R
, (1 << (m
/2)) - 1);
522 lcdc_write(priv
, _LDDCKR
, tmp
);
524 /* start dotclock again */
525 lcdc_write(priv
, _LDDCKSTPR
, 0);
526 lcdc_wait_bit(priv
, _LDDCKSTPR
, ~0, 0);
528 /* interrupts are disabled to begin with */
529 lcdc_write(priv
, _LDINTR
, 0);
531 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
537 sh_mobile_lcdc_geometry(ch
);
540 lcdc_write_chan(ch
, LDPMR
, 0);
542 board_cfg
= &ch
->cfg
.board_cfg
;
543 if (board_cfg
->setup_sys
) {
544 ret
= board_cfg
->setup_sys(board_cfg
->board_data
,
545 ch
, &sh_mobile_lcdc_sys_bus_ops
);
551 /* word and long word swap */
552 ldddsr
= lcdc_read(priv
, _LDDDSR
);
553 if (priv
->ch
[0].info
->var
.nonstd
)
554 lcdc_write(priv
, _LDDDSR
, ldddsr
| 7);
558 lcdc_write(priv
, _LDDDSR
, ldddsr
| 6);
561 lcdc_write(priv
, _LDDDSR
, ldddsr
| 7);
564 lcdc_write(priv
, _LDDDSR
, ldddsr
| 4);
569 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
570 unsigned long base_addr_y
;
571 unsigned long base_addr_c
= 0;
575 if (!priv
->ch
[k
].enabled
)
578 /* set bpp format in PKF[4:0] */
579 tmp
= lcdc_read_chan(ch
, LDDFR
);
581 if (ch
->info
->var
.nonstd
) {
582 tmp
|= (ch
->info
->var
.nonstd
<< 16);
583 switch (ch
->info
->var
.bits_per_pixel
) {
594 switch (ch
->info
->var
.bits_per_pixel
) {
605 lcdc_write_chan(ch
, LDDFR
, tmp
);
607 base_addr_y
= ch
->info
->fix
.smem_start
;
608 base_addr_c
= base_addr_y
+
610 ch
->info
->var
.yres_virtual
;
611 pitch
= ch
->info
->fix
.line_length
;
613 /* test if we can enable meram */
614 if (ch
->cfg
.meram_cfg
&& priv
->meram_dev
&&
615 priv
->meram_dev
->ops
) {
616 struct sh_mobile_meram_cfg
*cfg
;
617 struct sh_mobile_meram_info
*mdev
;
618 unsigned long icb_addr_y
, icb_addr_c
;
622 cfg
= ch
->cfg
.meram_cfg
;
623 mdev
= priv
->meram_dev
;
624 /* we need to de-init configured ICBs before we
625 * we can re-initialize them.
627 if (ch
->meram_enabled
)
628 mdev
->ops
->meram_unregister(mdev
, cfg
);
630 ch
->meram_enabled
= 0;
632 if (ch
->info
->var
.nonstd
) {
633 if (ch
->info
->var
.bits_per_pixel
== 24)
634 pf
= SH_MOBILE_MERAM_PF_NV24
;
636 pf
= SH_MOBILE_MERAM_PF_NV
;
638 pf
= SH_MOBILE_MERAM_PF_RGB
;
641 ret
= mdev
->ops
->meram_register(mdev
, cfg
, pitch
,
650 /* set LDSA1R value */
651 base_addr_y
= icb_addr_y
;
654 /* set LDSA2R value if required */
656 base_addr_c
= icb_addr_c
;
658 ch
->meram_enabled
= 1;
662 /* point out our frame buffer */
663 lcdc_write_chan(ch
, LDSA1R
, base_addr_y
);
664 if (ch
->info
->var
.nonstd
)
665 lcdc_write_chan(ch
, LDSA2R
, base_addr_c
);
668 lcdc_write_chan(ch
, LDMLSR
, pitch
);
670 /* setup deferred io if SYS bus */
671 tmp
= ch
->cfg
.sys_bus_cfg
.deferred_io_msec
;
672 if (ch
->ldmt1r_value
& (1 << 12) && tmp
) {
673 ch
->defio
.deferred_io
= sh_mobile_lcdc_deferred_io
;
674 ch
->defio
.delay
= msecs_to_jiffies(tmp
);
675 ch
->info
->fbdefio
= &ch
->defio
;
676 fb_deferred_io_init(ch
->info
);
679 lcdc_write_chan(ch
, LDSM1R
, 1);
681 /* enable "Frame End Interrupt Enable" bit */
682 lcdc_write(priv
, _LDINTR
, LDINTR_FE
);
685 /* continuous read mode */
686 lcdc_write_chan(ch
, LDSM1R
, 0);
691 lcdc_write(priv
, _LDCNT1R
, LCDC_ENABLE
);
694 sh_mobile_lcdc_start_stop(priv
, 1);
697 /* tell the board code to enable the panel */
698 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
703 board_cfg
= &ch
->cfg
.board_cfg
;
704 if (board_cfg
->display_on
&& try_module_get(board_cfg
->owner
)) {
705 board_cfg
->display_on(board_cfg
->board_data
, ch
->info
);
706 module_put(board_cfg
->owner
);
710 ch
->bl
->props
.power
= FB_BLANK_UNBLANK
;
711 backlight_update_status(ch
->bl
);
718 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
720 struct sh_mobile_lcdc_chan
*ch
;
721 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
724 /* clean up deferred io and ask board code to disable panel */
725 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
731 * flush frame, and wait for frame end interrupt
732 * clean up deferred io and enable clock
734 if (ch
->info
&& ch
->info
->fbdefio
) {
736 schedule_delayed_work(&ch
->info
->deferred_work
, 0);
737 wait_event(ch
->frame_end_wait
, ch
->frame_end
);
738 fb_deferred_io_cleanup(ch
->info
);
739 ch
->info
->fbdefio
= NULL
;
740 sh_mobile_lcdc_clk_on(priv
);
744 ch
->bl
->props
.power
= FB_BLANK_POWERDOWN
;
745 backlight_update_status(ch
->bl
);
748 board_cfg
= &ch
->cfg
.board_cfg
;
749 if (board_cfg
->display_off
&& try_module_get(board_cfg
->owner
)) {
750 board_cfg
->display_off(board_cfg
->board_data
);
751 module_put(board_cfg
->owner
);
754 /* disable the meram */
755 if (ch
->meram_enabled
) {
756 struct sh_mobile_meram_cfg
*cfg
;
757 struct sh_mobile_meram_info
*mdev
;
758 cfg
= ch
->cfg
.meram_cfg
;
759 mdev
= priv
->meram_dev
;
760 mdev
->ops
->meram_unregister(mdev
, cfg
);
761 ch
->meram_enabled
= 0;
768 sh_mobile_lcdc_start_stop(priv
, 0);
773 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
774 if (priv
->ch
[k
].enabled
)
775 sh_mobile_lcdc_clk_off(priv
);
778 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
782 switch (ch
->cfg
.interface_type
) {
783 case RGB8
: ifm
= 0; miftyp
= 0; break;
784 case RGB9
: ifm
= 0; miftyp
= 4; break;
785 case RGB12A
: ifm
= 0; miftyp
= 5; break;
786 case RGB12B
: ifm
= 0; miftyp
= 6; break;
787 case RGB16
: ifm
= 0; miftyp
= 7; break;
788 case RGB18
: ifm
= 0; miftyp
= 10; break;
789 case RGB24
: ifm
= 0; miftyp
= 11; break;
790 case SYS8A
: ifm
= 1; miftyp
= 0; break;
791 case SYS8B
: ifm
= 1; miftyp
= 1; break;
792 case SYS8C
: ifm
= 1; miftyp
= 2; break;
793 case SYS8D
: ifm
= 1; miftyp
= 3; break;
794 case SYS9
: ifm
= 1; miftyp
= 4; break;
795 case SYS12
: ifm
= 1; miftyp
= 5; break;
796 case SYS16A
: ifm
= 1; miftyp
= 7; break;
797 case SYS16B
: ifm
= 1; miftyp
= 8; break;
798 case SYS16C
: ifm
= 1; miftyp
= 9; break;
799 case SYS18
: ifm
= 1; miftyp
= 10; break;
800 case SYS24
: ifm
= 1; miftyp
= 11; break;
804 /* SUBLCD only supports SYS interface */
805 if (lcdc_chan_is_sublcd(ch
)) {
812 ch
->ldmt1r_value
= (ifm
<< 12) | miftyp
;
818 static int sh_mobile_lcdc_setup_clocks(struct platform_device
*pdev
,
820 struct sh_mobile_lcdc_priv
*priv
)
825 switch (clock_source
) {
826 case LCDC_CLK_BUS
: str
= "bus_clk"; icksel
= 0; break;
827 case LCDC_CLK_PERIPHERAL
: str
= "peripheral_clk"; icksel
= 1; break;
828 case LCDC_CLK_EXTERNAL
: str
= NULL
; icksel
= 2; break;
833 priv
->lddckr
= icksel
<< 16;
836 priv
->dot_clk
= clk_get(&pdev
->dev
, str
);
837 if (IS_ERR(priv
->dot_clk
)) {
838 dev_err(&pdev
->dev
, "cannot get dot clock %s\n", str
);
839 return PTR_ERR(priv
->dot_clk
);
843 /* Runtime PM support involves two step for this driver:
844 * 1) Enable Runtime PM
845 * 2) Force Runtime PM Resume since hardware is accessed from probe()
847 priv
->dev
= &pdev
->dev
;
848 pm_runtime_enable(priv
->dev
);
849 pm_runtime_resume(priv
->dev
);
853 static int sh_mobile_lcdc_setcolreg(u_int regno
,
854 u_int red
, u_int green
, u_int blue
,
855 u_int transp
, struct fb_info
*info
)
857 u32
*palette
= info
->pseudo_palette
;
859 if (regno
>= PALETTE_NR
)
862 /* only FB_VISUAL_TRUECOLOR supported */
864 red
>>= 16 - info
->var
.red
.length
;
865 green
>>= 16 - info
->var
.green
.length
;
866 blue
>>= 16 - info
->var
.blue
.length
;
867 transp
>>= 16 - info
->var
.transp
.length
;
869 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
870 (green
<< info
->var
.green
.offset
) |
871 (blue
<< info
->var
.blue
.offset
) |
872 (transp
<< info
->var
.transp
.offset
);
877 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
878 .id
= "SH Mobile LCDC",
879 .type
= FB_TYPE_PACKED_PIXELS
,
880 .visual
= FB_VISUAL_TRUECOLOR
,
881 .accel
= FB_ACCEL_NONE
,
887 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
888 const struct fb_fillrect
*rect
)
890 sys_fillrect(info
, rect
);
891 sh_mobile_lcdc_deferred_io_touch(info
);
894 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
895 const struct fb_copyarea
*area
)
897 sys_copyarea(info
, area
);
898 sh_mobile_lcdc_deferred_io_touch(info
);
901 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
902 const struct fb_image
*image
)
904 sys_imageblit(info
, image
);
905 sh_mobile_lcdc_deferred_io_touch(info
);
908 static int sh_mobile_fb_pan_display(struct fb_var_screeninfo
*var
,
909 struct fb_info
*info
)
911 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
912 struct sh_mobile_lcdc_priv
*priv
= ch
->lcdc
;
913 unsigned long ldrcntr
;
914 unsigned long new_pan_offset
;
915 unsigned long base_addr_y
, base_addr_c
;
916 unsigned long c_offset
;
919 new_pan_offset
= (var
->yoffset
* info
->fix
.line_length
) +
920 (var
->xoffset
* (info
->var
.bits_per_pixel
/ 8));
922 new_pan_offset
= (var
->yoffset
* info
->fix
.line_length
) +
925 if (new_pan_offset
== ch
->pan_offset
)
926 return 0; /* No change, do nothing */
928 ldrcntr
= lcdc_read(priv
, _LDRCNTR
);
930 /* Set the source address for the next refresh */
931 base_addr_y
= ch
->dma_handle
+ new_pan_offset
;
934 c_offset
= (var
->yoffset
*
935 info
->fix
.line_length
*
936 (info
->var
.bits_per_pixel
- 8)) / 8;
937 base_addr_c
= ch
->dma_handle
+ var
->xres
* var
->yres_virtual
+
940 if (info
->var
.bits_per_pixel
== 24)
941 base_addr_c
+= 2 * var
->xoffset
;
943 base_addr_c
+= var
->xoffset
;
947 if (!ch
->meram_enabled
) {
948 lcdc_write_chan_mirror(ch
, LDSA1R
, base_addr_y
);
950 lcdc_write_chan_mirror(ch
, LDSA2R
, base_addr_c
);
952 struct sh_mobile_meram_cfg
*cfg
;
953 struct sh_mobile_meram_info
*mdev
;
954 unsigned long icb_addr_y
, icb_addr_c
;
957 cfg
= ch
->cfg
.meram_cfg
;
958 mdev
= priv
->meram_dev
;
959 ret
= mdev
->ops
->meram_update(mdev
, cfg
,
960 base_addr_y
, base_addr_c
,
961 &icb_addr_y
, &icb_addr_c
);
965 lcdc_write_chan_mirror(ch
, LDSA1R
, icb_addr_y
);
967 lcdc_write_chan_mirror(ch
, LDSA2R
, icb_addr_c
);
971 if (lcdc_chan_is_sublcd(ch
))
972 lcdc_write(ch
->lcdc
, _LDRCNTR
, ldrcntr
^ LDRCNTR_SRS
);
974 lcdc_write(ch
->lcdc
, _LDRCNTR
, ldrcntr
^ LDRCNTR_MRS
);
976 ch
->pan_offset
= new_pan_offset
;
978 sh_mobile_lcdc_deferred_io_touch(info
);
983 static int sh_mobile_wait_for_vsync(struct fb_info
*info
)
985 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
986 unsigned long ldintr
;
989 /* Enable VSync End interrupt */
990 ldintr
= lcdc_read(ch
->lcdc
, _LDINTR
);
991 ldintr
|= LDINTR_VEE
;
992 lcdc_write(ch
->lcdc
, _LDINTR
, ldintr
);
994 ret
= wait_for_completion_interruptible_timeout(&ch
->vsync_completion
,
995 msecs_to_jiffies(100));
1002 static int sh_mobile_ioctl(struct fb_info
*info
, unsigned int cmd
,
1008 case FBIO_WAITFORVSYNC
:
1009 retval
= sh_mobile_wait_for_vsync(info
);
1013 retval
= -ENOIOCTLCMD
;
1019 static void sh_mobile_fb_reconfig(struct fb_info
*info
)
1021 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1022 struct fb_videomode mode1
, mode2
;
1023 struct fb_event event
;
1024 int evnt
= FB_EVENT_MODE_CHANGE_ALL
;
1026 if (ch
->use_count
> 1 || (ch
->use_count
== 1 && !info
->fbcon_par
))
1027 /* More framebuffer users are active */
1030 fb_var_to_videomode(&mode1
, &ch
->display_var
);
1031 fb_var_to_videomode(&mode2
, &info
->var
);
1033 if (fb_mode_is_equal(&mode1
, &mode2
))
1036 /* Display has been re-plugged, framebuffer is free now, reconfigure */
1037 if (fb_set_var(info
, &ch
->display_var
) < 0)
1038 /* Couldn't reconfigure, hopefully, can continue as before */
1041 if (info
->var
.nonstd
)
1042 info
->fix
.line_length
= mode1
.xres
;
1044 info
->fix
.line_length
= mode1
.xres
* (ch
->cfg
.bpp
/ 8);
1047 * fb_set_var() calls the notifier change internally, only if
1048 * FBINFO_MISC_USEREVENT flag is set. Since we do not want to fake a
1049 * user event, we have to call the chain ourselves.
1052 event
.data
= &mode1
;
1053 fb_notifier_call_chain(evnt
, &event
);
1057 * Locking: both .fb_release() and .fb_open() are called with info->lock held if
1058 * user == 1, or with console sem held, if user == 0.
1060 static int sh_mobile_release(struct fb_info
*info
, int user
)
1062 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1064 mutex_lock(&ch
->open_lock
);
1065 dev_dbg(info
->dev
, "%s(): %d users\n", __func__
, ch
->use_count
);
1069 /* Nothing to reconfigure, when called from fbcon */
1072 sh_mobile_fb_reconfig(info
);
1076 mutex_unlock(&ch
->open_lock
);
1081 static int sh_mobile_open(struct fb_info
*info
, int user
)
1083 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1085 mutex_lock(&ch
->open_lock
);
1088 dev_dbg(info
->dev
, "%s(): %d users\n", __func__
, ch
->use_count
);
1089 mutex_unlock(&ch
->open_lock
);
1094 static int sh_mobile_check_var(struct fb_var_screeninfo
*var
, struct fb_info
*info
)
1096 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1097 struct sh_mobile_lcdc_priv
*p
= ch
->lcdc
;
1099 if (var
->xres
> MAX_XRES
|| var
->yres
> MAX_YRES
||
1100 var
->xres
* var
->yres
* (ch
->cfg
.bpp
/ 8) * 2 > info
->fix
.smem_len
) {
1101 dev_warn(info
->dev
, "Invalid info: %u-%u-%u-%u x %u-%u-%u-%u @ %lukHz!\n",
1102 var
->left_margin
, var
->xres
, var
->right_margin
, var
->hsync_len
,
1103 var
->upper_margin
, var
->yres
, var
->lower_margin
, var
->vsync_len
,
1104 PICOS2KHZ(var
->pixclock
));
1108 /* only accept the forced_bpp for dual channel configurations */
1109 if (p
->forced_bpp
&& p
->forced_bpp
!= var
->bits_per_pixel
)
1112 switch (var
->bits_per_pixel
) {
1113 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1114 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1115 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1125 * Screen blanking. Behavior is as follows:
1126 * FB_BLANK_UNBLANK: screen unblanked, clocks enabled
1127 * FB_BLANK_NORMAL: screen blanked, clocks enabled
1130 * FB_BLANK_POWEROFF: screen blanked, clocks disabled
1132 static int sh_mobile_lcdc_blank(int blank
, struct fb_info
*info
)
1134 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1135 struct sh_mobile_lcdc_priv
*p
= ch
->lcdc
;
1137 /* blank the screen? */
1138 if (blank
> FB_BLANK_UNBLANK
&& ch
->blank_status
== FB_BLANK_UNBLANK
) {
1139 struct fb_fillrect rect
= {
1140 .width
= info
->var
.xres
,
1141 .height
= info
->var
.yres
,
1143 sh_mobile_lcdc_fillrect(info
, &rect
);
1145 /* turn clocks on? */
1146 if (blank
<= FB_BLANK_NORMAL
&& ch
->blank_status
> FB_BLANK_NORMAL
) {
1147 sh_mobile_lcdc_clk_on(p
);
1149 /* turn clocks off? */
1150 if (blank
> FB_BLANK_NORMAL
&& ch
->blank_status
<= FB_BLANK_NORMAL
) {
1151 /* make sure the screen is updated with the black fill before
1152 * switching the clocks off. one vsync is not enough since
1153 * blanking may occur in the middle of a refresh. deferred io
1154 * mode will reenable the clocks and update the screen in time,
1155 * so it does not need this. */
1156 if (!info
->fbdefio
) {
1157 sh_mobile_wait_for_vsync(info
);
1158 sh_mobile_wait_for_vsync(info
);
1160 sh_mobile_lcdc_clk_off(p
);
1163 ch
->blank_status
= blank
;
1167 static struct fb_ops sh_mobile_lcdc_ops
= {
1168 .owner
= THIS_MODULE
,
1169 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
1170 .fb_read
= fb_sys_read
,
1171 .fb_write
= fb_sys_write
,
1172 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
1173 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
1174 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
1175 .fb_blank
= sh_mobile_lcdc_blank
,
1176 .fb_pan_display
= sh_mobile_fb_pan_display
,
1177 .fb_ioctl
= sh_mobile_ioctl
,
1178 .fb_open
= sh_mobile_open
,
1179 .fb_release
= sh_mobile_release
,
1180 .fb_check_var
= sh_mobile_check_var
,
1183 static int sh_mobile_lcdc_update_bl(struct backlight_device
*bdev
)
1185 struct sh_mobile_lcdc_chan
*ch
= bl_get_data(bdev
);
1186 struct sh_mobile_lcdc_board_cfg
*cfg
= &ch
->cfg
.board_cfg
;
1187 int brightness
= bdev
->props
.brightness
;
1189 if (bdev
->props
.power
!= FB_BLANK_UNBLANK
||
1190 bdev
->props
.state
& (BL_CORE_SUSPENDED
| BL_CORE_FBBLANK
))
1193 return cfg
->set_brightness(cfg
->board_data
, brightness
);
1196 static int sh_mobile_lcdc_get_brightness(struct backlight_device
*bdev
)
1198 struct sh_mobile_lcdc_chan
*ch
= bl_get_data(bdev
);
1199 struct sh_mobile_lcdc_board_cfg
*cfg
= &ch
->cfg
.board_cfg
;
1201 return cfg
->get_brightness(cfg
->board_data
);
1204 static int sh_mobile_lcdc_check_fb(struct backlight_device
*bdev
,
1205 struct fb_info
*info
)
1207 return (info
->bl_dev
== bdev
);
1210 static struct backlight_ops sh_mobile_lcdc_bl_ops
= {
1211 .options
= BL_CORE_SUSPENDRESUME
,
1212 .update_status
= sh_mobile_lcdc_update_bl
,
1213 .get_brightness
= sh_mobile_lcdc_get_brightness
,
1214 .check_fb
= sh_mobile_lcdc_check_fb
,
1217 static struct backlight_device
*sh_mobile_lcdc_bl_probe(struct device
*parent
,
1218 struct sh_mobile_lcdc_chan
*ch
)
1220 struct backlight_device
*bl
;
1222 bl
= backlight_device_register(ch
->cfg
.bl_info
.name
, parent
, ch
,
1223 &sh_mobile_lcdc_bl_ops
, NULL
);
1225 dev_err(parent
, "unable to register backlight device: %ld\n",
1230 bl
->props
.max_brightness
= ch
->cfg
.bl_info
.max_brightness
;
1231 bl
->props
.brightness
= bl
->props
.max_brightness
;
1232 backlight_update_status(bl
);
1237 static void sh_mobile_lcdc_bl_remove(struct backlight_device
*bdev
)
1239 backlight_device_unregister(bdev
);
1242 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo
*var
, int bpp
,
1250 var
->bits_per_pixel
= bpp
;
1251 var
->nonstd
= nonstd
;
1259 case 16: /* PKF[4:0] = 00011 - RGB 565 */
1260 var
->red
.offset
= 11;
1261 var
->red
.length
= 5;
1262 var
->green
.offset
= 5;
1263 var
->green
.length
= 6;
1264 var
->blue
.offset
= 0;
1265 var
->blue
.length
= 5;
1266 var
->transp
.offset
= 0;
1267 var
->transp
.length
= 0;
1270 case 24: /* PKF[4:0] = 01011 - RGB 888 */
1271 var
->red
.offset
= 16;
1272 var
->red
.length
= 8;
1273 var
->green
.offset
= 8;
1274 var
->green
.length
= 8;
1275 var
->blue
.offset
= 0;
1276 var
->blue
.length
= 8;
1277 var
->transp
.offset
= 0;
1278 var
->transp
.length
= 0;
1281 case 32: /* PKF[4:0] = 00000 - RGBA 888 */
1282 var
->red
.offset
= 16;
1283 var
->red
.length
= 8;
1284 var
->green
.offset
= 8;
1285 var
->green
.length
= 8;
1286 var
->blue
.offset
= 0;
1287 var
->blue
.length
= 8;
1288 var
->transp
.offset
= 24;
1289 var
->transp
.length
= 8;
1294 var
->bits_per_pixel
= bpp
;
1295 var
->red
.msb_right
= 0;
1296 var
->green
.msb_right
= 0;
1297 var
->blue
.msb_right
= 0;
1298 var
->transp
.msb_right
= 0;
1302 static int sh_mobile_lcdc_suspend(struct device
*dev
)
1304 struct platform_device
*pdev
= to_platform_device(dev
);
1306 sh_mobile_lcdc_stop(platform_get_drvdata(pdev
));
1310 static int sh_mobile_lcdc_resume(struct device
*dev
)
1312 struct platform_device
*pdev
= to_platform_device(dev
);
1314 return sh_mobile_lcdc_start(platform_get_drvdata(pdev
));
1317 static int sh_mobile_lcdc_runtime_suspend(struct device
*dev
)
1319 struct platform_device
*pdev
= to_platform_device(dev
);
1320 struct sh_mobile_lcdc_priv
*p
= platform_get_drvdata(pdev
);
1321 struct sh_mobile_lcdc_chan
*ch
;
1324 /* save per-channel registers */
1325 for (k
= 0; k
< ARRAY_SIZE(p
->ch
); k
++) {
1329 for (n
= 0; n
< NR_CH_REGS
; n
++)
1330 ch
->saved_ch_regs
[n
] = lcdc_read_chan(ch
, n
);
1333 /* save shared registers */
1334 for (n
= 0; n
< NR_SHARED_REGS
; n
++)
1335 p
->saved_shared_regs
[n
] = lcdc_read(p
, lcdc_shared_regs
[n
]);
1337 /* turn off LCDC hardware */
1338 lcdc_write(p
, _LDCNT1R
, 0);
1342 static int sh_mobile_lcdc_runtime_resume(struct device
*dev
)
1344 struct platform_device
*pdev
= to_platform_device(dev
);
1345 struct sh_mobile_lcdc_priv
*p
= platform_get_drvdata(pdev
);
1346 struct sh_mobile_lcdc_chan
*ch
;
1349 /* restore per-channel registers */
1350 for (k
= 0; k
< ARRAY_SIZE(p
->ch
); k
++) {
1354 for (n
= 0; n
< NR_CH_REGS
; n
++)
1355 lcdc_write_chan(ch
, n
, ch
->saved_ch_regs
[n
]);
1358 /* restore shared registers */
1359 for (n
= 0; n
< NR_SHARED_REGS
; n
++)
1360 lcdc_write(p
, lcdc_shared_regs
[n
], p
->saved_shared_regs
[n
]);
1365 static const struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops
= {
1366 .suspend
= sh_mobile_lcdc_suspend
,
1367 .resume
= sh_mobile_lcdc_resume
,
1368 .runtime_suspend
= sh_mobile_lcdc_runtime_suspend
,
1369 .runtime_resume
= sh_mobile_lcdc_runtime_resume
,
1372 /* locking: called with info->lock held */
1373 static int sh_mobile_lcdc_notify(struct notifier_block
*nb
,
1374 unsigned long action
, void *data
)
1376 struct fb_event
*event
= data
;
1377 struct fb_info
*info
= event
->info
;
1378 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
1379 struct sh_mobile_lcdc_board_cfg
*board_cfg
= &ch
->cfg
.board_cfg
;
1381 if (&ch
->lcdc
->notifier
!= nb
)
1384 dev_dbg(info
->dev
, "%s(): action = %lu, data = %p\n",
1385 __func__
, action
, event
->data
);
1388 case FB_EVENT_SUSPEND
:
1389 if (board_cfg
->display_off
&& try_module_get(board_cfg
->owner
)) {
1390 board_cfg
->display_off(board_cfg
->board_data
);
1391 module_put(board_cfg
->owner
);
1393 sh_mobile_lcdc_stop(ch
->lcdc
);
1395 case FB_EVENT_RESUME
:
1396 mutex_lock(&ch
->open_lock
);
1397 sh_mobile_fb_reconfig(info
);
1398 mutex_unlock(&ch
->open_lock
);
1400 /* HDMI must be enabled before LCDC configuration */
1401 if (board_cfg
->display_on
&& try_module_get(board_cfg
->owner
)) {
1402 board_cfg
->display_on(board_cfg
->board_data
, info
);
1403 module_put(board_cfg
->owner
);
1406 sh_mobile_lcdc_start(ch
->lcdc
);
1412 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
);
1414 static int __devinit
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
1416 struct fb_info
*info
;
1417 struct sh_mobile_lcdc_priv
*priv
;
1418 struct sh_mobile_lcdc_info
*pdata
= pdev
->dev
.platform_data
;
1419 struct resource
*res
;
1425 dev_err(&pdev
->dev
, "no platform data defined\n");
1429 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
1430 i
= platform_get_irq(pdev
, 0);
1431 if (!res
|| i
< 0) {
1432 dev_err(&pdev
->dev
, "cannot get platform resources\n");
1436 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
1438 dev_err(&pdev
->dev
, "cannot allocate device data\n");
1442 platform_set_drvdata(pdev
, priv
);
1444 error
= request_irq(i
, sh_mobile_lcdc_irq
, IRQF_DISABLED
,
1445 dev_name(&pdev
->dev
), priv
);
1447 dev_err(&pdev
->dev
, "unable to request irq\n");
1452 atomic_set(&priv
->hw_usecnt
, -1);
1455 for (i
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
1456 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ j
;
1459 memcpy(&ch
->cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
1461 error
= sh_mobile_lcdc_check_interface(ch
);
1463 dev_err(&pdev
->dev
, "unsupported interface type\n");
1466 init_waitqueue_head(&ch
->frame_end_wait
);
1467 init_completion(&ch
->vsync_completion
);
1470 /* probe the backlight is there is one defined */
1471 if (ch
->cfg
.bl_info
.max_brightness
)
1472 ch
->bl
= sh_mobile_lcdc_bl_probe(&pdev
->dev
, ch
);
1474 switch (pdata
->ch
[i
].chan
) {
1475 case LCDC_CHAN_MAINLCD
:
1476 ch
->enabled
= 1 << 1;
1477 ch
->reg_offs
= lcdc_offs_mainlcd
;
1480 case LCDC_CHAN_SUBLCD
:
1481 ch
->enabled
= 1 << 2;
1482 ch
->reg_offs
= lcdc_offs_sublcd
;
1489 dev_err(&pdev
->dev
, "no channels defined\n");
1494 /* for dual channel LCDC (MAIN + SUB) force shared bpp setting */
1496 priv
->forced_bpp
= pdata
->ch
[0].bpp
;
1498 priv
->base
= ioremap_nocache(res
->start
, resource_size(res
));
1502 error
= sh_mobile_lcdc_setup_clocks(pdev
, pdata
->clock_source
, priv
);
1504 dev_err(&pdev
->dev
, "unable to setup clocks\n");
1508 priv
->meram_dev
= pdata
->meram_dev
;
1510 for (i
= 0; i
< j
; i
++) {
1511 struct fb_var_screeninfo
*var
;
1512 const struct fb_videomode
*lcd_cfg
, *max_cfg
= NULL
;
1513 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
1514 struct sh_mobile_lcdc_chan_cfg
*cfg
= &ch
->cfg
;
1515 const struct fb_videomode
*mode
= cfg
->lcd_cfg
;
1516 unsigned long max_size
= 0;
1520 ch
->info
= framebuffer_alloc(0, &pdev
->dev
);
1522 dev_err(&pdev
->dev
, "unable to allocate fb_info\n");
1529 info
->fbops
= &sh_mobile_lcdc_ops
;
1532 mutex_init(&ch
->open_lock
);
1534 for (k
= 0, lcd_cfg
= mode
;
1535 k
< cfg
->num_cfg
&& lcd_cfg
;
1537 unsigned long size
= lcd_cfg
->yres
* lcd_cfg
->xres
;
1538 /* NV12 buffers must have even number of lines */
1539 if ((cfg
->nonstd
) && cfg
->bpp
== 12 &&
1540 (lcd_cfg
->yres
& 0x1)) {
1541 dev_err(&pdev
->dev
, "yres must be multiple of 2"
1542 " for YCbCr420 mode.\n");
1547 if (size
> max_size
) {
1554 max_size
= MAX_XRES
* MAX_YRES
;
1556 dev_dbg(&pdev
->dev
, "Found largest videomode %ux%u\n",
1557 max_cfg
->xres
, max_cfg
->yres
);
1559 info
->fix
= sh_mobile_lcdc_fix
;
1560 info
->fix
.smem_len
= max_size
* 2 * cfg
->bpp
/ 8;
1562 /* Only pan in 2 line steps for NV12 */
1563 if (cfg
->nonstd
&& cfg
->bpp
== 12)
1564 info
->fix
.ypanstep
= 2;
1567 mode
= &default_720p
;
1570 num_cfg
= cfg
->num_cfg
;
1573 fb_videomode_to_modelist(mode
, num_cfg
, &info
->modelist
);
1575 fb_videomode_to_var(var
, mode
);
1576 var
->width
= cfg
->lcd_size_cfg
.width
;
1577 var
->height
= cfg
->lcd_size_cfg
.height
;
1578 /* Default Y virtual resolution is 2x panel size */
1579 var
->yres_virtual
= var
->yres
* 2;
1580 var
->activate
= FB_ACTIVATE_NOW
;
1582 error
= sh_mobile_lcdc_set_bpp(var
, cfg
->bpp
, cfg
->nonstd
);
1586 buf
= dma_alloc_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1587 &ch
->dma_handle
, GFP_KERNEL
);
1589 dev_err(&pdev
->dev
, "unable to allocate buffer\n");
1594 info
->pseudo_palette
= &ch
->pseudo_palette
;
1595 info
->flags
= FBINFO_FLAG_DEFAULT
;
1597 error
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
1599 dev_err(&pdev
->dev
, "unable to allocate cmap\n");
1600 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1601 buf
, ch
->dma_handle
);
1605 info
->fix
.smem_start
= ch
->dma_handle
;
1607 info
->fix
.line_length
= var
->xres
;
1609 info
->fix
.line_length
= var
->xres
* (cfg
->bpp
/ 8);
1611 info
->screen_base
= buf
;
1612 info
->device
= &pdev
->dev
;
1613 ch
->display_var
= *var
;
1619 error
= sh_mobile_lcdc_start(priv
);
1621 dev_err(&pdev
->dev
, "unable to start hardware\n");
1625 for (i
= 0; i
< j
; i
++) {
1626 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
1630 if (info
->fbdefio
) {
1631 ch
->sglist
= vmalloc(sizeof(struct scatterlist
) *
1632 info
->fix
.smem_len
>> PAGE_SHIFT
);
1634 dev_err(&pdev
->dev
, "cannot allocate sglist\n");
1639 info
->bl_dev
= ch
->bl
;
1641 error
= register_framebuffer(info
);
1646 "registered %s/%s as %dx%d %dbpp.\n",
1648 (ch
->cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
1649 "mainlcd" : "sublcd",
1650 info
->var
.xres
, info
->var
.yres
,
1653 /* deferred io mode: disable clock to save power */
1654 if (info
->fbdefio
|| info
->state
== FBINFO_STATE_SUSPENDED
)
1655 sh_mobile_lcdc_clk_off(priv
);
1658 /* Failure ignored */
1659 priv
->notifier
.notifier_call
= sh_mobile_lcdc_notify
;
1660 fb_register_client(&priv
->notifier
);
1664 sh_mobile_lcdc_remove(pdev
);
1669 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
1671 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
1672 struct fb_info
*info
;
1675 fb_unregister_client(&priv
->notifier
);
1677 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
1678 if (priv
->ch
[i
].info
&& priv
->ch
[i
].info
->dev
)
1679 unregister_framebuffer(priv
->ch
[i
].info
);
1681 sh_mobile_lcdc_stop(priv
);
1683 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
1684 info
= priv
->ch
[i
].info
;
1686 if (!info
|| !info
->device
)
1689 if (priv
->ch
[i
].sglist
)
1690 vfree(priv
->ch
[i
].sglist
);
1692 if (info
->screen_base
)
1693 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
1695 priv
->ch
[i
].dma_handle
);
1696 fb_dealloc_cmap(&info
->cmap
);
1697 framebuffer_release(info
);
1700 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
1702 sh_mobile_lcdc_bl_remove(priv
->ch
[i
].bl
);
1706 clk_put(priv
->dot_clk
);
1709 pm_runtime_disable(priv
->dev
);
1712 iounmap(priv
->base
);
1715 free_irq(priv
->irq
, priv
);
1720 static struct platform_driver sh_mobile_lcdc_driver
= {
1722 .name
= "sh_mobile_lcdc_fb",
1723 .owner
= THIS_MODULE
,
1724 .pm
= &sh_mobile_lcdc_dev_pm_ops
,
1726 .probe
= sh_mobile_lcdc_probe
,
1727 .remove
= sh_mobile_lcdc_remove
,
1730 static int __init
sh_mobile_lcdc_init(void)
1732 return platform_driver_register(&sh_mobile_lcdc_driver
);
1735 static void __exit
sh_mobile_lcdc_exit(void)
1737 platform_driver_unregister(&sh_mobile_lcdc_driver
);
1740 module_init(sh_mobile_lcdc_init
);
1741 module_exit(sh_mobile_lcdc_exit
);
1743 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
1744 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
1745 MODULE_LICENSE("GPL v2");