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
++) {
484 board_cfg
= &ch
->cfg
.board_cfg
;
485 if (board_cfg
->display_on
)
486 board_cfg
->display_on(board_cfg
->board_data
);
492 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
494 struct sh_mobile_lcdc_chan
*ch
;
495 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
498 /* clean up deferred io and ask board code to disable panel */
499 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
503 * flush frame, and wait for frame end interrupt
504 * clean up deferred io and enable clock
506 if (ch
->info
->fbdefio
) {
508 schedule_delayed_work(&ch
->info
->deferred_work
, 0);
509 wait_event(ch
->frame_end_wait
, ch
->frame_end
);
510 fb_deferred_io_cleanup(ch
->info
);
511 ch
->info
->fbdefio
= NULL
;
512 sh_mobile_lcdc_clk_on(priv
);
515 board_cfg
= &ch
->cfg
.board_cfg
;
516 if (board_cfg
->display_off
)
517 board_cfg
->display_off(board_cfg
->board_data
);
523 sh_mobile_lcdc_start_stop(priv
, 0);
528 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
529 if (priv
->ch
[k
].enabled
)
530 sh_mobile_lcdc_clk_off(priv
);
533 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
537 switch (ch
->cfg
.interface_type
) {
538 case RGB8
: ifm
= 0; miftyp
= 0; break;
539 case RGB9
: ifm
= 0; miftyp
= 4; break;
540 case RGB12A
: ifm
= 0; miftyp
= 5; break;
541 case RGB12B
: ifm
= 0; miftyp
= 6; break;
542 case RGB16
: ifm
= 0; miftyp
= 7; break;
543 case RGB18
: ifm
= 0; miftyp
= 10; break;
544 case RGB24
: ifm
= 0; miftyp
= 11; break;
545 case SYS8A
: ifm
= 1; miftyp
= 0; break;
546 case SYS8B
: ifm
= 1; miftyp
= 1; break;
547 case SYS8C
: ifm
= 1; miftyp
= 2; break;
548 case SYS8D
: ifm
= 1; miftyp
= 3; break;
549 case SYS9
: ifm
= 1; miftyp
= 4; break;
550 case SYS12
: ifm
= 1; miftyp
= 5; break;
551 case SYS16A
: ifm
= 1; miftyp
= 7; break;
552 case SYS16B
: ifm
= 1; miftyp
= 8; break;
553 case SYS16C
: ifm
= 1; miftyp
= 9; break;
554 case SYS18
: ifm
= 1; miftyp
= 10; break;
555 case SYS24
: ifm
= 1; miftyp
= 11; break;
559 /* SUBLCD only supports SYS interface */
560 if (lcdc_chan_is_sublcd(ch
)) {
567 ch
->ldmt1r_value
= (ifm
<< 12) | miftyp
;
573 static int sh_mobile_lcdc_setup_clocks(struct platform_device
*pdev
,
575 struct sh_mobile_lcdc_priv
*priv
)
577 #ifdef CONFIG_HAVE_CLK
583 switch (clock_source
) {
584 case LCDC_CLK_BUS
: str
= "bus_clk"; icksel
= 0; break;
585 case LCDC_CLK_PERIPHERAL
: str
= "peripheral_clk"; icksel
= 1; break;
586 case LCDC_CLK_EXTERNAL
: str
= NULL
; icksel
= 2; break;
591 priv
->lddckr
= icksel
<< 16;
593 #ifdef CONFIG_HAVE_CLK
594 atomic_set(&priv
->clk_usecnt
, -1);
595 snprintf(clk_name
, sizeof(clk_name
), "lcdc%d", pdev
->id
);
596 priv
->clk
= clk_get(&pdev
->dev
, clk_name
);
597 if (IS_ERR(priv
->clk
)) {
598 dev_err(&pdev
->dev
, "cannot get clock \"%s\"\n", clk_name
);
599 return PTR_ERR(priv
->clk
);
603 priv
->dot_clk
= clk_get(&pdev
->dev
, str
);
604 if (IS_ERR(priv
->dot_clk
)) {
605 dev_err(&pdev
->dev
, "cannot get dot clock %s\n", str
);
607 return PTR_ERR(priv
->dot_clk
);
615 static int sh_mobile_lcdc_setcolreg(u_int regno
,
616 u_int red
, u_int green
, u_int blue
,
617 u_int transp
, struct fb_info
*info
)
619 u32
*palette
= info
->pseudo_palette
;
621 if (regno
>= PALETTE_NR
)
624 /* only FB_VISUAL_TRUECOLOR supported */
626 red
>>= 16 - info
->var
.red
.length
;
627 green
>>= 16 - info
->var
.green
.length
;
628 blue
>>= 16 - info
->var
.blue
.length
;
629 transp
>>= 16 - info
->var
.transp
.length
;
631 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
632 (green
<< info
->var
.green
.offset
) |
633 (blue
<< info
->var
.blue
.offset
) |
634 (transp
<< info
->var
.transp
.offset
);
639 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
640 .id
= "SH Mobile LCDC",
641 .type
= FB_TYPE_PACKED_PIXELS
,
642 .visual
= FB_VISUAL_TRUECOLOR
,
643 .accel
= FB_ACCEL_NONE
,
646 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
647 const struct fb_fillrect
*rect
)
649 sys_fillrect(info
, rect
);
650 sh_mobile_lcdc_deferred_io_touch(info
);
653 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
654 const struct fb_copyarea
*area
)
656 sys_copyarea(info
, area
);
657 sh_mobile_lcdc_deferred_io_touch(info
);
660 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
661 const struct fb_image
*image
)
663 sys_imageblit(info
, image
);
664 sh_mobile_lcdc_deferred_io_touch(info
);
667 static struct fb_ops sh_mobile_lcdc_ops
= {
668 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
669 .fb_read
= fb_sys_read
,
670 .fb_write
= fb_sys_write
,
671 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
672 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
673 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
676 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo
*var
, int bpp
)
679 case 16: /* PKF[4:0] = 00011 - RGB 565 */
680 var
->red
.offset
= 11;
682 var
->green
.offset
= 5;
683 var
->green
.length
= 6;
684 var
->blue
.offset
= 0;
685 var
->blue
.length
= 5;
686 var
->transp
.offset
= 0;
687 var
->transp
.length
= 0;
690 case 32: /* PKF[4:0] = 00000 - RGB 888
691 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
692 * this may be because LDDDSR has word swap enabled..
696 var
->green
.offset
= 24;
697 var
->green
.length
= 8;
698 var
->blue
.offset
= 16;
699 var
->blue
.length
= 8;
700 var
->transp
.offset
= 0;
701 var
->transp
.length
= 0;
706 var
->bits_per_pixel
= bpp
;
707 var
->red
.msb_right
= 0;
708 var
->green
.msb_right
= 0;
709 var
->blue
.msb_right
= 0;
710 var
->transp
.msb_right
= 0;
714 static int sh_mobile_lcdc_suspend(struct device
*dev
)
716 struct platform_device
*pdev
= to_platform_device(dev
);
718 sh_mobile_lcdc_stop(platform_get_drvdata(pdev
));
722 static int sh_mobile_lcdc_resume(struct device
*dev
)
724 struct platform_device
*pdev
= to_platform_device(dev
);
726 return sh_mobile_lcdc_start(platform_get_drvdata(pdev
));
729 static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops
= {
730 .suspend
= sh_mobile_lcdc_suspend
,
731 .resume
= sh_mobile_lcdc_resume
,
734 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
);
736 static int __init
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
738 struct fb_info
*info
;
739 struct sh_mobile_lcdc_priv
*priv
;
740 struct sh_mobile_lcdc_info
*pdata
;
741 struct sh_mobile_lcdc_chan_cfg
*cfg
;
742 struct resource
*res
;
747 if (!pdev
->dev
.platform_data
) {
748 dev_err(&pdev
->dev
, "no platform data defined\n");
753 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
754 i
= platform_get_irq(pdev
, 0);
756 dev_err(&pdev
->dev
, "cannot get platform resources\n");
761 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
763 dev_err(&pdev
->dev
, "cannot allocate device data\n");
768 error
= request_irq(i
, sh_mobile_lcdc_irq
, IRQF_DISABLED
,
769 dev_name(&pdev
->dev
), priv
);
771 dev_err(&pdev
->dev
, "unable to request irq\n");
776 platform_set_drvdata(pdev
, priv
);
777 pdata
= pdev
->dev
.platform_data
;
780 for (i
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
781 priv
->ch
[j
].lcdc
= priv
;
782 memcpy(&priv
->ch
[j
].cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
784 error
= sh_mobile_lcdc_check_interface(&priv
->ch
[i
]);
786 dev_err(&pdev
->dev
, "unsupported interface type\n");
789 init_waitqueue_head(&priv
->ch
[i
].frame_end_wait
);
791 switch (pdata
->ch
[i
].chan
) {
792 case LCDC_CHAN_MAINLCD
:
793 priv
->ch
[j
].enabled
= 1 << 1;
794 priv
->ch
[j
].reg_offs
= lcdc_offs_mainlcd
;
797 case LCDC_CHAN_SUBLCD
:
798 priv
->ch
[j
].enabled
= 1 << 2;
799 priv
->ch
[j
].reg_offs
= lcdc_offs_sublcd
;
806 dev_err(&pdev
->dev
, "no channels defined\n");
811 error
= sh_mobile_lcdc_setup_clocks(pdev
, pdata
->clock_source
, priv
);
813 dev_err(&pdev
->dev
, "unable to setup clocks\n");
817 priv
->base
= ioremap_nocache(res
->start
, (res
->end
- res
->start
) + 1);
819 for (i
= 0; i
< j
; i
++) {
820 cfg
= &priv
->ch
[i
].cfg
;
822 priv
->ch
[i
].info
= framebuffer_alloc(0, &pdev
->dev
);
823 if (!priv
->ch
[i
].info
) {
824 dev_err(&pdev
->dev
, "unable to allocate fb_info\n");
829 info
= priv
->ch
[i
].info
;
830 info
->fbops
= &sh_mobile_lcdc_ops
;
831 info
->var
.xres
= info
->var
.xres_virtual
= cfg
->lcd_cfg
.xres
;
832 info
->var
.yres
= info
->var
.yres_virtual
= cfg
->lcd_cfg
.yres
;
833 info
->var
.width
= cfg
->lcd_size_cfg
.width
;
834 info
->var
.height
= cfg
->lcd_size_cfg
.height
;
835 info
->var
.activate
= FB_ACTIVATE_NOW
;
836 error
= sh_mobile_lcdc_set_bpp(&info
->var
, cfg
->bpp
);
840 info
->fix
= sh_mobile_lcdc_fix
;
841 info
->fix
.line_length
= cfg
->lcd_cfg
.xres
* (cfg
->bpp
/ 8);
842 info
->fix
.smem_len
= info
->fix
.line_length
* cfg
->lcd_cfg
.yres
;
844 buf
= dma_alloc_coherent(&pdev
->dev
, info
->fix
.smem_len
,
845 &priv
->ch
[i
].dma_handle
, GFP_KERNEL
);
847 dev_err(&pdev
->dev
, "unable to allocate buffer\n");
852 info
->pseudo_palette
= &priv
->ch
[i
].pseudo_palette
;
853 info
->flags
= FBINFO_FLAG_DEFAULT
;
855 error
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
857 dev_err(&pdev
->dev
, "unable to allocate cmap\n");
858 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
859 buf
, priv
->ch
[i
].dma_handle
);
863 memset(buf
, 0, info
->fix
.smem_len
);
864 info
->fix
.smem_start
= priv
->ch
[i
].dma_handle
;
865 info
->screen_base
= buf
;
866 info
->device
= &pdev
->dev
;
867 info
->par
= &priv
->ch
[i
];
873 error
= sh_mobile_lcdc_start(priv
);
875 dev_err(&pdev
->dev
, "unable to start hardware\n");
879 for (i
= 0; i
< j
; i
++) {
880 struct sh_mobile_lcdc_chan
*ch
= priv
->ch
+ i
;
885 priv
->ch
->sglist
= vmalloc(sizeof(struct scatterlist
) *
886 info
->fix
.smem_len
>> PAGE_SHIFT
);
887 if (!priv
->ch
->sglist
) {
888 dev_err(&pdev
->dev
, "cannot allocate sglist\n");
893 error
= register_framebuffer(info
);
898 "registered %s/%s as %dx%d %dbpp.\n",
900 (ch
->cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
901 "mainlcd" : "sublcd",
902 (int) ch
->cfg
.lcd_cfg
.xres
,
903 (int) ch
->cfg
.lcd_cfg
.yres
,
906 /* deferred io mode: disable clock to save power */
908 sh_mobile_lcdc_clk_off(priv
);
913 sh_mobile_lcdc_remove(pdev
);
918 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
920 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
921 struct fb_info
*info
;
924 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
925 if (priv
->ch
[i
].info
->dev
)
926 unregister_framebuffer(priv
->ch
[i
].info
);
928 sh_mobile_lcdc_stop(priv
);
930 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
931 info
= priv
->ch
[i
].info
;
933 if (!info
|| !info
->device
)
936 if (priv
->ch
[i
].sglist
)
937 vfree(priv
->ch
[i
].sglist
);
939 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
940 info
->screen_base
, priv
->ch
[i
].dma_handle
);
941 fb_dealloc_cmap(&info
->cmap
);
942 framebuffer_release(info
);
945 #ifdef CONFIG_HAVE_CLK
947 clk_put(priv
->dot_clk
);
955 free_irq(priv
->irq
, priv
);
960 static struct platform_driver sh_mobile_lcdc_driver
= {
962 .name
= "sh_mobile_lcdc_fb",
963 .owner
= THIS_MODULE
,
964 .pm
= &sh_mobile_lcdc_dev_pm_ops
,
966 .probe
= sh_mobile_lcdc_probe
,
967 .remove
= sh_mobile_lcdc_remove
,
970 static int __init
sh_mobile_lcdc_init(void)
972 return platform_driver_register(&sh_mobile_lcdc_driver
);
975 static void __exit
sh_mobile_lcdc_exit(void)
977 platform_driver_unregister(&sh_mobile_lcdc_driver
);
980 module_init(sh_mobile_lcdc_init
);
981 module_exit(sh_mobile_lcdc_exit
);
983 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
984 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
985 MODULE_LICENSE("GPL v2");