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>
16 #include <linux/clk.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 <video/sh_mobile_lcdc.h>
22 #include <asm/atomic.h>
26 struct sh_mobile_lcdc_priv
;
27 struct sh_mobile_lcdc_chan
{
28 struct sh_mobile_lcdc_priv
*lcdc
;
29 unsigned long *reg_offs
;
30 unsigned long ldmt1r_value
;
31 unsigned long enabled
; /* ME and SE in LDCNT2R */
32 struct sh_mobile_lcdc_chan_cfg cfg
;
33 u32 pseudo_palette
[PALETTE_NR
];
35 dma_addr_t dma_handle
;
36 struct fb_deferred_io defio
;
37 struct scatterlist
*sglist
;
38 unsigned long frame_end
;
39 wait_queue_head_t frame_end_wait
;
42 struct sh_mobile_lcdc_priv
{
45 #ifdef CONFIG_HAVE_CLK
51 struct sh_mobile_lcdc_chan ch
[2];
55 /* shared registers */
57 #define _LDDCKSTPR 0x414
60 #define _LDCNT1R 0x470
61 #define _LDCNT2R 0x474
63 #define _LDDWD0R 0x800
68 /* per-channel registers */
69 enum { LDDCKPAT1R
, LDDCKPAT2R
, LDMT1R
, LDMT2R
, LDMT3R
, LDDFR
, LDSM1R
,
70 LDSM2R
, LDSA1R
, LDMLSR
, LDHCNR
, LDHSYNR
, LDVLNR
, LDVSYNR
, LDPMR
};
72 static unsigned long lcdc_offs_mainlcd
[] = {
90 static unsigned long lcdc_offs_sublcd
[] = {
108 #define START_LCDC 0x00000001
109 #define LCDC_RESET 0x00000100
110 #define DISPLAY_BEU 0x00000008
111 #define LCDC_ENABLE 0x00000001
112 #define LDINTR_FE 0x00000400
113 #define LDINTR_FS 0x00000004
115 static void lcdc_write_chan(struct sh_mobile_lcdc_chan
*chan
,
116 int reg_nr
, unsigned long data
)
118 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
121 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan
*chan
,
124 return ioread32(chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
127 static void lcdc_write(struct sh_mobile_lcdc_priv
*priv
,
128 unsigned long reg_offs
, unsigned long data
)
130 iowrite32(data
, priv
->base
+ reg_offs
);
133 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv
*priv
,
134 unsigned long reg_offs
)
136 return ioread32(priv
->base
+ reg_offs
);
139 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv
*priv
,
140 unsigned long reg_offs
,
141 unsigned long mask
, unsigned long until
)
143 while ((lcdc_read(priv
, reg_offs
) & mask
) != until
)
147 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan
*chan
)
149 return chan
->cfg
.chan
== LCDC_CHAN_SUBLCD
;
152 static void lcdc_sys_write_index(void *handle
, unsigned long data
)
154 struct sh_mobile_lcdc_chan
*ch
= handle
;
156 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x10000000);
157 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
158 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
161 static void lcdc_sys_write_data(void *handle
, unsigned long data
)
163 struct sh_mobile_lcdc_chan
*ch
= handle
;
165 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x11000000);
166 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
167 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
170 static unsigned long lcdc_sys_read_data(void *handle
)
172 struct sh_mobile_lcdc_chan
*ch
= handle
;
174 lcdc_write(ch
->lcdc
, _LDDRDR
, 0x01000000);
175 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
176 lcdc_write(ch
->lcdc
, _LDDRAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
179 return lcdc_read(ch
->lcdc
, _LDDRDR
) & 0xffff;
182 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops
= {
183 lcdc_sys_write_index
,
188 #ifdef CONFIG_HAVE_CLK
189 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
)
191 if (atomic_inc_and_test(&priv
->clk_usecnt
)) {
192 clk_enable(priv
->clk
);
194 clk_enable(priv
->dot_clk
);
198 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
)
200 if (atomic_sub_return(1, &priv
->clk_usecnt
) == -1) {
202 clk_disable(priv
->dot_clk
);
203 clk_disable(priv
->clk
);
207 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
) {}
208 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
) {}
211 static int sh_mobile_lcdc_sginit(struct fb_info
*info
,
212 struct list_head
*pagelist
)
214 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
215 unsigned int nr_pages_max
= info
->fix
.smem_len
>> PAGE_SHIFT
;
219 sg_init_table(ch
->sglist
, nr_pages_max
);
221 list_for_each_entry(page
, pagelist
, lru
)
222 sg_set_page(&ch
->sglist
[nr_pages
++], page
, PAGE_SIZE
, 0);
227 static void sh_mobile_lcdc_deferred_io(struct fb_info
*info
,
228 struct list_head
*pagelist
)
230 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
231 unsigned int nr_pages
;
233 /* enable clocks before accessing hardware */
234 sh_mobile_lcdc_clk_on(ch
->lcdc
);
236 nr_pages
= sh_mobile_lcdc_sginit(info
, pagelist
);
237 dma_map_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
239 /* trigger panel update */
240 lcdc_write_chan(ch
, LDSM2R
, 1);
242 dma_unmap_sg(info
->dev
, ch
->sglist
, nr_pages
, DMA_TO_DEVICE
);
245 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info
*info
)
247 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
250 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
253 static irqreturn_t
sh_mobile_lcdc_irq(int irq
, void *data
)
255 struct sh_mobile_lcdc_priv
*priv
= data
;
256 struct sh_mobile_lcdc_chan
*ch
;
261 /* acknowledge interrupt */
262 tmp
= lcdc_read(priv
, _LDINTR
);
263 tmp
&= 0xffffff00; /* mask in high 24 bits */
264 tmp
|= 0x000000ff ^ LDINTR_FS
; /* status in low 8 */
265 lcdc_write(priv
, _LDINTR
, tmp
);
267 /* figure out if this interrupt is for main or sub lcd */
268 is_sub
= (lcdc_read(priv
, _LDSR
) & (1 << 10)) ? 1 : 0;
270 /* wake up channel and disable clocks*/
271 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
277 if (is_sub
== lcdc_chan_is_sublcd(ch
)) {
279 wake_up(&ch
->frame_end_wait
);
281 sh_mobile_lcdc_clk_off(priv
);
288 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv
*priv
,
291 unsigned long tmp
= lcdc_read(priv
, _LDCNT2R
);
294 /* start or stop the lcdc */
296 lcdc_write(priv
, _LDCNT2R
, tmp
| START_LCDC
);
298 lcdc_write(priv
, _LDCNT2R
, tmp
& ~START_LCDC
);
300 /* wait until power is applied/stopped on all channels */
301 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
302 if (lcdc_read(priv
, _LDCNT2R
) & priv
->ch
[k
].enabled
)
304 tmp
= lcdc_read_chan(&priv
->ch
[k
], LDPMR
) & 3;
305 if (start
&& tmp
== 3)
307 if (!start
&& tmp
== 0)
313 lcdc_write(priv
, _LDDCKSTPR
, 1); /* stop dotclock */
316 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
318 struct sh_mobile_lcdc_chan
*ch
;
319 struct fb_videomode
*lcd_cfg
;
320 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
325 /* enable clocks before accessing the hardware */
326 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
327 if (priv
->ch
[k
].enabled
)
328 sh_mobile_lcdc_clk_on(priv
);
331 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) | LCDC_RESET
);
332 lcdc_wait_bit(priv
, _LDCNT2R
, LCDC_RESET
, 0);
334 /* enable LCDC channels */
335 tmp
= lcdc_read(priv
, _LDCNT2R
);
336 tmp
|= priv
->ch
[0].enabled
;
337 tmp
|= priv
->ch
[1].enabled
;
338 lcdc_write(priv
, _LDCNT2R
, tmp
);
340 /* read data from external memory, avoid using the BEU for now */
341 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) & ~DISPLAY_BEU
);
343 /* stop the lcdc first */
344 sh_mobile_lcdc_start_stop(priv
, 0);
346 /* configure clocks */
348 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
351 if (!priv
->ch
[k
].enabled
)
354 m
= ch
->cfg
.clock_divider
;
360 tmp
|= m
<< (lcdc_chan_is_sublcd(ch
) ? 8 : 0);
362 lcdc_write_chan(ch
, LDDCKPAT1R
, 0x00000000);
363 lcdc_write_chan(ch
, LDDCKPAT2R
, (1 << (m
/2)) - 1);
366 lcdc_write(priv
, _LDDCKR
, tmp
);
368 /* start dotclock again */
369 lcdc_write(priv
, _LDDCKSTPR
, 0);
370 lcdc_wait_bit(priv
, _LDDCKSTPR
, ~0, 0);
372 /* interrupts are disabled to begin with */
373 lcdc_write(priv
, _LDINTR
, 0);
375 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
377 lcd_cfg
= &ch
->cfg
.lcd_cfg
;
382 tmp
= ch
->ldmt1r_value
;
383 tmp
|= (lcd_cfg
->sync
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : 1 << 28;
384 tmp
|= (lcd_cfg
->sync
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : 1 << 27;
385 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWPOL
) ? 1 << 26 : 0;
386 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DIPOL
) ? 1 << 25 : 0;
387 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DAPOL
) ? 1 << 24 : 0;
388 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_HSCNT
) ? 1 << 17 : 0;
389 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWCNT
) ? 1 << 16 : 0;
390 lcdc_write_chan(ch
, LDMT1R
, tmp
);
393 lcdc_write_chan(ch
, LDMT2R
, ch
->cfg
.sys_bus_cfg
.ldmt2r
);
394 lcdc_write_chan(ch
, LDMT3R
, ch
->cfg
.sys_bus_cfg
.ldmt3r
);
396 /* horizontal configuration */
397 tmp
= lcd_cfg
->xres
+ lcd_cfg
->hsync_len
;
398 tmp
+= lcd_cfg
->left_margin
;
399 tmp
+= lcd_cfg
->right_margin
;
401 tmp
|= (lcd_cfg
->xres
/ 8) << 16; /* HDCN */
402 lcdc_write_chan(ch
, LDHCNR
, tmp
);
405 tmp
+= lcd_cfg
->right_margin
;
406 tmp
/= 8; /* HSYNP */
407 tmp
|= (lcd_cfg
->hsync_len
/ 8) << 16; /* HSYNW */
408 lcdc_write_chan(ch
, LDHSYNR
, tmp
);
411 lcdc_write_chan(ch
, LDPMR
, 0);
413 /* vertical configuration */
414 tmp
= lcd_cfg
->yres
+ lcd_cfg
->vsync_len
;
415 tmp
+= lcd_cfg
->upper_margin
;
416 tmp
+= lcd_cfg
->lower_margin
; /* VTLN */
417 tmp
|= lcd_cfg
->yres
<< 16; /* VDLN */
418 lcdc_write_chan(ch
, LDVLNR
, tmp
);
421 tmp
+= lcd_cfg
->lower_margin
; /* VSYNP */
422 tmp
|= lcd_cfg
->vsync_len
<< 16; /* VSYNW */
423 lcdc_write_chan(ch
, LDVSYNR
, tmp
);
425 board_cfg
= &ch
->cfg
.board_cfg
;
426 if (board_cfg
->setup_sys
)
427 ret
= board_cfg
->setup_sys(board_cfg
->board_data
, ch
,
428 &sh_mobile_lcdc_sys_bus_ops
);
433 /* word and long word swap */
434 lcdc_write(priv
, _LDDDSR
, lcdc_read(priv
, _LDDDSR
) | 6);
436 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
439 if (!priv
->ch
[k
].enabled
)
442 /* set bpp format in PKF[4:0] */
443 tmp
= lcdc_read_chan(ch
, LDDFR
);
444 tmp
&= ~(0x0001001f);
445 tmp
|= (ch
->info
->var
.bits_per_pixel
== 16) ? 3 : 0;
446 lcdc_write_chan(ch
, LDDFR
, tmp
);
448 /* point out our frame buffer */
449 lcdc_write_chan(ch
, LDSA1R
, ch
->info
->fix
.smem_start
);
452 lcdc_write_chan(ch
, LDMLSR
, ch
->info
->fix
.line_length
);
454 /* setup deferred io if SYS bus */
455 tmp
= ch
->cfg
.sys_bus_cfg
.deferred_io_msec
;
456 if (ch
->ldmt1r_value
& (1 << 12) && tmp
) {
457 ch
->defio
.deferred_io
= sh_mobile_lcdc_deferred_io
;
458 ch
->defio
.delay
= msecs_to_jiffies(tmp
);
459 ch
->info
->fbdefio
= &ch
->defio
;
460 fb_deferred_io_init(ch
->info
);
463 lcdc_write_chan(ch
, LDSM1R
, 1);
465 /* enable "Frame End Interrupt Enable" bit */
466 lcdc_write(priv
, _LDINTR
, LDINTR_FE
);
469 /* continuous read mode */
470 lcdc_write_chan(ch
, LDSM1R
, 0);
475 lcdc_write(priv
, _LDCNT1R
, LCDC_ENABLE
);
478 sh_mobile_lcdc_start_stop(priv
, 1);
481 /* tell the board code to enable the panel */
482 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
487 board_cfg
= &ch
->cfg
.board_cfg
;
488 if (board_cfg
->display_on
)
489 board_cfg
->display_on(board_cfg
->board_data
);
495 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
497 struct sh_mobile_lcdc_chan
*ch
;
498 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
501 /* clean up deferred io and ask board code to disable panel */
502 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
508 * flush frame, and wait for frame end interrupt
509 * clean up deferred io and enable clock
511 if (ch
->info
->fbdefio
) {
513 schedule_delayed_work(&ch
->info
->deferred_work
, 0);
514 wait_event(ch
->frame_end_wait
, ch
->frame_end
);
515 fb_deferred_io_cleanup(ch
->info
);
516 ch
->info
->fbdefio
= NULL
;
517 sh_mobile_lcdc_clk_on(priv
);
520 board_cfg
= &ch
->cfg
.board_cfg
;
521 if (board_cfg
->display_off
)
522 board_cfg
->display_off(board_cfg
->board_data
);
528 sh_mobile_lcdc_start_stop(priv
, 0);
533 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
534 if (priv
->ch
[k
].enabled
)
535 sh_mobile_lcdc_clk_off(priv
);
538 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
542 switch (ch
->cfg
.interface_type
) {
543 case RGB8
: ifm
= 0; miftyp
= 0; break;
544 case RGB9
: ifm
= 0; miftyp
= 4; break;
545 case RGB12A
: ifm
= 0; miftyp
= 5; break;
546 case RGB12B
: ifm
= 0; miftyp
= 6; break;
547 case RGB16
: ifm
= 0; miftyp
= 7; break;
548 case RGB18
: ifm
= 0; miftyp
= 10; break;
549 case RGB24
: ifm
= 0; miftyp
= 11; break;
550 case SYS8A
: ifm
= 1; miftyp
= 0; break;
551 case SYS8B
: ifm
= 1; miftyp
= 1; break;
552 case SYS8C
: ifm
= 1; miftyp
= 2; break;
553 case SYS8D
: ifm
= 1; miftyp
= 3; break;
554 case SYS9
: ifm
= 1; miftyp
= 4; break;
555 case SYS12
: ifm
= 1; miftyp
= 5; break;
556 case SYS16A
: ifm
= 1; miftyp
= 7; break;
557 case SYS16B
: ifm
= 1; miftyp
= 8; break;
558 case SYS16C
: ifm
= 1; miftyp
= 9; break;
559 case SYS18
: ifm
= 1; miftyp
= 10; break;
560 case SYS24
: ifm
= 1; miftyp
= 11; break;
564 /* SUBLCD only supports SYS interface */
565 if (lcdc_chan_is_sublcd(ch
)) {
572 ch
->ldmt1r_value
= (ifm
<< 12) | miftyp
;
578 static int sh_mobile_lcdc_setup_clocks(struct platform_device
*pdev
,
580 struct sh_mobile_lcdc_priv
*priv
)
582 #ifdef CONFIG_HAVE_CLK
588 switch (clock_source
) {
589 case LCDC_CLK_BUS
: str
= "bus_clk"; icksel
= 0; break;
590 case LCDC_CLK_PERIPHERAL
: str
= "peripheral_clk"; icksel
= 1; break;
591 case LCDC_CLK_EXTERNAL
: str
= NULL
; icksel
= 2; break;
596 priv
->lddckr
= icksel
<< 16;
598 #ifdef CONFIG_HAVE_CLK
599 atomic_set(&priv
->clk_usecnt
, -1);
600 snprintf(clk_name
, sizeof(clk_name
), "lcdc%d", pdev
->id
);
601 priv
->clk
= clk_get(&pdev
->dev
, clk_name
);
602 if (IS_ERR(priv
->clk
)) {
603 dev_err(&pdev
->dev
, "cannot get clock \"%s\"\n", clk_name
);
604 return PTR_ERR(priv
->clk
);
608 priv
->dot_clk
= clk_get(&pdev
->dev
, str
);
609 if (IS_ERR(priv
->dot_clk
)) {
610 dev_err(&pdev
->dev
, "cannot get dot clock %s\n", str
);
612 return PTR_ERR(priv
->dot_clk
);
620 static int sh_mobile_lcdc_setcolreg(u_int regno
,
621 u_int red
, u_int green
, u_int blue
,
622 u_int transp
, struct fb_info
*info
)
624 u32
*palette
= info
->pseudo_palette
;
626 if (regno
>= PALETTE_NR
)
629 /* only FB_VISUAL_TRUECOLOR supported */
631 red
>>= 16 - info
->var
.red
.length
;
632 green
>>= 16 - info
->var
.green
.length
;
633 blue
>>= 16 - info
->var
.blue
.length
;
634 transp
>>= 16 - info
->var
.transp
.length
;
636 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
637 (green
<< info
->var
.green
.offset
) |
638 (blue
<< info
->var
.blue
.offset
) |
639 (transp
<< info
->var
.transp
.offset
);
644 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
645 .id
= "SH Mobile LCDC",
646 .type
= FB_TYPE_PACKED_PIXELS
,
647 .visual
= FB_VISUAL_TRUECOLOR
,
648 .accel
= FB_ACCEL_NONE
,
651 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
652 const struct fb_fillrect
*rect
)
654 sys_fillrect(info
, rect
);
655 sh_mobile_lcdc_deferred_io_touch(info
);
658 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
659 const struct fb_copyarea
*area
)
661 sys_copyarea(info
, area
);
662 sh_mobile_lcdc_deferred_io_touch(info
);
665 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
666 const struct fb_image
*image
)
668 sys_imageblit(info
, image
);
669 sh_mobile_lcdc_deferred_io_touch(info
);
672 static struct fb_ops sh_mobile_lcdc_ops
= {
673 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
674 .fb_read
= fb_sys_read
,
675 .fb_write
= fb_sys_write
,
676 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
677 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
678 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
681 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo
*var
, int bpp
)
684 case 16: /* PKF[4:0] = 00011 - RGB 565 */
685 var
->red
.offset
= 11;
687 var
->green
.offset
= 5;
688 var
->green
.length
= 6;
689 var
->blue
.offset
= 0;
690 var
->blue
.length
= 5;
691 var
->transp
.offset
= 0;
692 var
->transp
.length
= 0;
695 case 32: /* PKF[4:0] = 00000 - RGB 888
696 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
697 * this may be because LDDDSR has word swap enabled..
701 var
->green
.offset
= 24;
702 var
->green
.length
= 8;
703 var
->blue
.offset
= 16;
704 var
->blue
.length
= 8;
705 var
->transp
.offset
= 0;
706 var
->transp
.length
= 0;
711 var
->bits_per_pixel
= bpp
;
712 var
->red
.msb_right
= 0;
713 var
->green
.msb_right
= 0;
714 var
->blue
.msb_right
= 0;
715 var
->transp
.msb_right
= 0;
719 static int sh_mobile_lcdc_suspend(struct device
*dev
)
721 struct platform_device
*pdev
= to_platform_device(dev
);
723 sh_mobile_lcdc_stop(platform_get_drvdata(pdev
));
727 static int sh_mobile_lcdc_resume(struct device
*dev
)
729 struct platform_device
*pdev
= to_platform_device(dev
);
731 return sh_mobile_lcdc_start(platform_get_drvdata(pdev
));
734 static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops
= {
735 .suspend
= sh_mobile_lcdc_suspend
,
736 .resume
= sh_mobile_lcdc_resume
,
739 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
);
741 static int __init
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
743 struct fb_info
*info
;
744 struct sh_mobile_lcdc_priv
*priv
;
745 struct sh_mobile_lcdc_info
*pdata
;
746 struct sh_mobile_lcdc_chan_cfg
*cfg
;
747 struct resource
*res
;
752 if (!pdev
->dev
.platform_data
) {
753 dev_err(&pdev
->dev
, "no platform data defined\n");
758 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
759 i
= platform_get_irq(pdev
, 0);
761 dev_err(&pdev
->dev
, "cannot get platform resources\n");
766 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
768 dev_err(&pdev
->dev
, "cannot allocate device data\n");
773 error
= request_irq(i
, sh_mobile_lcdc_irq
, IRQF_DISABLED
,
774 dev_name(&pdev
->dev
), priv
);
776 dev_err(&pdev
->dev
, "unable to request irq\n");
781 platform_set_drvdata(pdev
, priv
);
782 pdata
= pdev
->dev
.platform_data
;
785 for (i
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
786 priv
->ch
[j
].lcdc
= priv
;
787 memcpy(&priv
->ch
[j
].cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
789 error
= sh_mobile_lcdc_check_interface(&priv
->ch
[i
]);
791 dev_err(&pdev
->dev
, "unsupported interface type\n");
794 init_waitqueue_head(&priv
->ch
[i
].frame_end_wait
);
796 switch (pdata
->ch
[i
].chan
) {
797 case LCDC_CHAN_MAINLCD
:
798 priv
->ch
[j
].enabled
= 1 << 1;
799 priv
->ch
[j
].reg_offs
= lcdc_offs_mainlcd
;
802 case LCDC_CHAN_SUBLCD
:
803 priv
->ch
[j
].enabled
= 1 << 2;
804 priv
->ch
[j
].reg_offs
= lcdc_offs_sublcd
;
811 dev_err(&pdev
->dev
, "no channels defined\n");
816 error
= sh_mobile_lcdc_setup_clocks(pdev
, pdata
->clock_source
, priv
);
818 dev_err(&pdev
->dev
, "unable to setup clocks\n");
822 priv
->base
= ioremap_nocache(res
->start
, (res
->end
- res
->start
) + 1);
824 for (i
= 0; i
< j
; i
++) {
825 cfg
= &priv
->ch
[i
].cfg
;
827 priv
->ch
[i
].info
= framebuffer_alloc(0, &pdev
->dev
);
828 if (!priv
->ch
[i
].info
) {
829 dev_err(&pdev
->dev
, "unable to allocate fb_info\n");
834 info
= priv
->ch
[i
].info
;
835 info
->fbops
= &sh_mobile_lcdc_ops
;
836 info
->var
.xres
= info
->var
.xres_virtual
= cfg
->lcd_cfg
.xres
;
837 info
->var
.yres
= info
->var
.yres_virtual
= cfg
->lcd_cfg
.yres
;
838 info
->var
.width
= cfg
->lcd_size_cfg
.width
;
839 info
->var
.height
= cfg
->lcd_size_cfg
.height
;
840 info
->var
.activate
= FB_ACTIVATE_NOW
;
841 error
= sh_mobile_lcdc_set_bpp(&info
->var
, cfg
->bpp
);
845 info
->fix
= sh_mobile_lcdc_fix
;
846 info
->fix
.line_length
= cfg
->lcd_cfg
.xres
* (cfg
->bpp
/ 8);
847 info
->fix
.smem_len
= info
->fix
.line_length
* cfg
->lcd_cfg
.yres
;
849 buf
= dma_alloc_coherent(&pdev
->dev
, info
->fix
.smem_len
,
850 &priv
->ch
[i
].dma_handle
, GFP_KERNEL
);
852 dev_err(&pdev
->dev
, "unable to allocate buffer\n");
857 info
->pseudo_palette
= &priv
->ch
[i
].pseudo_palette
;
858 info
->flags
= FBINFO_FLAG_DEFAULT
;
860 error
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
862 dev_err(&pdev
->dev
, "unable to allocate cmap\n");
863 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
864 buf
, priv
->ch
[i
].dma_handle
);
868 memset(buf
, 0, info
->fix
.smem_len
);
869 info
->fix
.smem_start
= priv
->ch
[i
].dma_handle
;
870 info
->screen_base
= buf
;
871 info
->device
= &pdev
->dev
;
872 info
->par
= &priv
->ch
[i
];
878 error
= sh_mobile_lcdc_start(priv
);
880 dev_err(&pdev
->dev
, "unable to start hardware\n");
884 for (i
= 0; i
< j
; i
++) {
885 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
890 priv
->ch
->sglist
= vmalloc(sizeof(struct scatterlist
) *
891 info
->fix
.smem_len
>> PAGE_SHIFT
);
892 if (!priv
->ch
->sglist
) {
893 dev_err(&pdev
->dev
, "cannot allocate sglist\n");
898 error
= register_framebuffer(info
);
903 "registered %s/%s as %dx%d %dbpp.\n",
905 (ch
->cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
906 "mainlcd" : "sublcd",
907 (int) ch
->cfg
.lcd_cfg
.xres
,
908 (int) ch
->cfg
.lcd_cfg
.yres
,
911 /* deferred io mode: disable clock to save power */
913 sh_mobile_lcdc_clk_off(priv
);
918 sh_mobile_lcdc_remove(pdev
);
923 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
925 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
926 struct fb_info
*info
;
929 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
930 if (priv
->ch
[i
].info
->dev
)
931 unregister_framebuffer(priv
->ch
[i
].info
);
933 sh_mobile_lcdc_stop(priv
);
935 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
936 info
= priv
->ch
[i
].info
;
938 if (!info
|| !info
->device
)
941 if (priv
->ch
[i
].sglist
)
942 vfree(priv
->ch
[i
].sglist
);
944 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
945 info
->screen_base
, priv
->ch
[i
].dma_handle
);
946 fb_dealloc_cmap(&info
->cmap
);
947 framebuffer_release(info
);
950 #ifdef CONFIG_HAVE_CLK
952 clk_put(priv
->dot_clk
);
960 free_irq(priv
->irq
, priv
);
965 static struct platform_driver sh_mobile_lcdc_driver
= {
967 .name
= "sh_mobile_lcdc_fb",
968 .owner
= THIS_MODULE
,
969 .pm
= &sh_mobile_lcdc_dev_pm_ops
,
971 .probe
= sh_mobile_lcdc_probe
,
972 .remove
= sh_mobile_lcdc_remove
,
975 static int __init
sh_mobile_lcdc_init(void)
977 return platform_driver_register(&sh_mobile_lcdc_driver
);
980 static void __exit
sh_mobile_lcdc_exit(void)
982 platform_driver_unregister(&sh_mobile_lcdc_driver
);
985 module_init(sh_mobile_lcdc_init
);
986 module_exit(sh_mobile_lcdc_exit
);
988 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
989 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
990 MODULE_LICENSE("GPL v2");