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 <video/sh_mobile_lcdc.h>
21 #include <asm/atomic.h>
25 struct sh_mobile_lcdc_priv
;
26 struct sh_mobile_lcdc_chan
{
27 struct sh_mobile_lcdc_priv
*lcdc
;
28 unsigned long *reg_offs
;
29 unsigned long ldmt1r_value
;
30 unsigned long enabled
; /* ME and SE in LDCNT2R */
31 struct sh_mobile_lcdc_chan_cfg cfg
;
32 u32 pseudo_palette
[PALETTE_NR
];
34 dma_addr_t dma_handle
;
35 struct fb_deferred_io defio
;
36 unsigned long frame_end
;
37 wait_queue_head_t frame_end_wait
;
40 struct sh_mobile_lcdc_priv
{
43 #ifdef CONFIG_HAVE_CLK
49 struct sh_mobile_lcdc_chan ch
[2];
52 /* shared registers */
54 #define _LDDCKSTPR 0x414
57 #define _LDCNT1R 0x470
58 #define _LDCNT2R 0x474
60 #define _LDDWD0R 0x800
65 /* per-channel registers */
66 enum { LDDCKPAT1R
, LDDCKPAT2R
, LDMT1R
, LDMT2R
, LDMT3R
, LDDFR
, LDSM1R
,
67 LDSM2R
, LDSA1R
, LDMLSR
, LDHCNR
, LDHSYNR
, LDVLNR
, LDVSYNR
, LDPMR
};
69 static unsigned long lcdc_offs_mainlcd
[] = {
87 static unsigned long lcdc_offs_sublcd
[] = {
105 #define START_LCDC 0x00000001
106 #define LCDC_RESET 0x00000100
107 #define DISPLAY_BEU 0x00000008
108 #define LCDC_ENABLE 0x00000001
109 #define LDINTR_FE 0x00000400
110 #define LDINTR_FS 0x00000004
112 static void lcdc_write_chan(struct sh_mobile_lcdc_chan
*chan
,
113 int reg_nr
, unsigned long data
)
115 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
118 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan
*chan
,
121 return ioread32(chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
124 static void lcdc_write(struct sh_mobile_lcdc_priv
*priv
,
125 unsigned long reg_offs
, unsigned long data
)
127 iowrite32(data
, priv
->base
+ reg_offs
);
130 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv
*priv
,
131 unsigned long reg_offs
)
133 return ioread32(priv
->base
+ reg_offs
);
136 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv
*priv
,
137 unsigned long reg_offs
,
138 unsigned long mask
, unsigned long until
)
140 while ((lcdc_read(priv
, reg_offs
) & mask
) != until
)
144 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan
*chan
)
146 return chan
->cfg
.chan
== LCDC_CHAN_SUBLCD
;
149 static void lcdc_sys_write_index(void *handle
, unsigned long data
)
151 struct sh_mobile_lcdc_chan
*ch
= handle
;
153 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x10000000);
154 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
155 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
158 static void lcdc_sys_write_data(void *handle
, unsigned long data
)
160 struct sh_mobile_lcdc_chan
*ch
= handle
;
162 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x11000000);
163 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
164 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
167 static unsigned long lcdc_sys_read_data(void *handle
)
169 struct sh_mobile_lcdc_chan
*ch
= handle
;
171 lcdc_write(ch
->lcdc
, _LDDRDR
, 0x01000000);
172 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
173 lcdc_write(ch
->lcdc
, _LDDRAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
176 return lcdc_read(ch
->lcdc
, _LDDRDR
) & 0xffff;
179 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops
= {
180 lcdc_sys_write_index
,
185 #ifdef CONFIG_HAVE_CLK
186 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
)
188 if (atomic_inc_and_test(&priv
->clk_usecnt
)) {
189 clk_enable(priv
->clk
);
191 clk_enable(priv
->dot_clk
);
195 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
)
197 if (atomic_sub_return(1, &priv
->clk_usecnt
) == -1) {
199 clk_disable(priv
->dot_clk
);
200 clk_disable(priv
->clk
);
204 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
) {}
205 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
) {}
208 static void sh_mobile_lcdc_deferred_io(struct fb_info
*info
,
209 struct list_head
*pagelist
)
211 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
213 /* enable clocks before accessing hardware */
214 sh_mobile_lcdc_clk_on(ch
->lcdc
);
216 /* trigger panel update */
217 lcdc_write_chan(ch
, LDSM2R
, 1);
220 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info
*info
)
222 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
225 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
228 static irqreturn_t
sh_mobile_lcdc_irq(int irq
, void *data
)
230 struct sh_mobile_lcdc_priv
*priv
= data
;
231 struct sh_mobile_lcdc_chan
*ch
;
236 /* acknowledge interrupt */
237 tmp
= lcdc_read(priv
, _LDINTR
);
238 tmp
&= 0xffffff00; /* mask in high 24 bits */
239 tmp
|= 0x000000ff ^ LDINTR_FS
; /* status in low 8 */
240 lcdc_write(priv
, _LDINTR
, tmp
);
242 /* figure out if this interrupt is for main or sub lcd */
243 is_sub
= (lcdc_read(priv
, _LDSR
) & (1 << 10)) ? 1 : 0;
245 /* wake up channel and disable clocks*/
246 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
252 if (is_sub
== lcdc_chan_is_sublcd(ch
)) {
254 wake_up(&ch
->frame_end_wait
);
256 sh_mobile_lcdc_clk_off(priv
);
263 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv
*priv
,
266 unsigned long tmp
= lcdc_read(priv
, _LDCNT2R
);
269 /* start or stop the lcdc */
271 lcdc_write(priv
, _LDCNT2R
, tmp
| START_LCDC
);
273 lcdc_write(priv
, _LDCNT2R
, tmp
& ~START_LCDC
);
275 /* wait until power is applied/stopped on all channels */
276 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
277 if (lcdc_read(priv
, _LDCNT2R
) & priv
->ch
[k
].enabled
)
279 tmp
= lcdc_read_chan(&priv
->ch
[k
], LDPMR
) & 3;
280 if (start
&& tmp
== 3)
282 if (!start
&& tmp
== 0)
288 lcdc_write(priv
, _LDDCKSTPR
, 1); /* stop dotclock */
291 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
293 struct sh_mobile_lcdc_chan
*ch
;
294 struct fb_videomode
*lcd_cfg
;
295 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
300 /* enable clocks before accessing the hardware */
301 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
302 if (priv
->ch
[k
].enabled
)
303 sh_mobile_lcdc_clk_on(priv
);
306 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) | LCDC_RESET
);
307 lcdc_wait_bit(priv
, _LDCNT2R
, LCDC_RESET
, 0);
309 /* enable LCDC channels */
310 tmp
= lcdc_read(priv
, _LDCNT2R
);
311 tmp
|= priv
->ch
[0].enabled
;
312 tmp
|= priv
->ch
[1].enabled
;
313 lcdc_write(priv
, _LDCNT2R
, tmp
);
315 /* read data from external memory, avoid using the BEU for now */
316 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) & ~DISPLAY_BEU
);
318 /* stop the lcdc first */
319 sh_mobile_lcdc_start_stop(priv
, 0);
321 /* configure clocks */
323 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
326 if (!priv
->ch
[k
].enabled
)
329 m
= ch
->cfg
.clock_divider
;
335 tmp
|= m
<< (lcdc_chan_is_sublcd(ch
) ? 8 : 0);
337 lcdc_write_chan(ch
, LDDCKPAT1R
, 0x00000000);
338 lcdc_write_chan(ch
, LDDCKPAT2R
, (1 << (m
/2)) - 1);
341 lcdc_write(priv
, _LDDCKR
, tmp
);
343 /* start dotclock again */
344 lcdc_write(priv
, _LDDCKSTPR
, 0);
345 lcdc_wait_bit(priv
, _LDDCKSTPR
, ~0, 0);
347 /* interrupts are disabled to begin with */
348 lcdc_write(priv
, _LDINTR
, 0);
350 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
352 lcd_cfg
= &ch
->cfg
.lcd_cfg
;
357 tmp
= ch
->ldmt1r_value
;
358 tmp
|= (lcd_cfg
->sync
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : 1 << 28;
359 tmp
|= (lcd_cfg
->sync
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : 1 << 27;
360 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWPOL
) ? 1 << 26 : 0;
361 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DIPOL
) ? 1 << 25 : 0;
362 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DAPOL
) ? 1 << 24 : 0;
363 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_HSCNT
) ? 1 << 17 : 0;
364 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWCNT
) ? 1 << 16 : 0;
365 lcdc_write_chan(ch
, LDMT1R
, tmp
);
368 lcdc_write_chan(ch
, LDMT2R
, ch
->cfg
.sys_bus_cfg
.ldmt2r
);
369 lcdc_write_chan(ch
, LDMT3R
, ch
->cfg
.sys_bus_cfg
.ldmt3r
);
371 /* horizontal configuration */
372 tmp
= lcd_cfg
->xres
+ lcd_cfg
->hsync_len
;
373 tmp
+= lcd_cfg
->left_margin
;
374 tmp
+= lcd_cfg
->right_margin
;
376 tmp
|= (lcd_cfg
->xres
/ 8) << 16; /* HDCN */
377 lcdc_write_chan(ch
, LDHCNR
, tmp
);
380 tmp
+= lcd_cfg
->right_margin
;
381 tmp
/= 8; /* HSYNP */
382 tmp
|= (lcd_cfg
->hsync_len
/ 8) << 16; /* HSYNW */
383 lcdc_write_chan(ch
, LDHSYNR
, tmp
);
386 lcdc_write_chan(ch
, LDPMR
, 0);
388 /* vertical configuration */
389 tmp
= lcd_cfg
->yres
+ lcd_cfg
->vsync_len
;
390 tmp
+= lcd_cfg
->upper_margin
;
391 tmp
+= lcd_cfg
->lower_margin
; /* VTLN */
392 tmp
|= lcd_cfg
->yres
<< 16; /* VDLN */
393 lcdc_write_chan(ch
, LDVLNR
, tmp
);
396 tmp
+= lcd_cfg
->lower_margin
; /* VSYNP */
397 tmp
|= lcd_cfg
->vsync_len
<< 16; /* VSYNW */
398 lcdc_write_chan(ch
, LDVSYNR
, tmp
);
400 board_cfg
= &ch
->cfg
.board_cfg
;
401 if (board_cfg
->setup_sys
)
402 ret
= board_cfg
->setup_sys(board_cfg
->board_data
, ch
,
403 &sh_mobile_lcdc_sys_bus_ops
);
408 /* word and long word swap */
409 lcdc_write(priv
, _LDDDSR
, lcdc_read(priv
, _LDDDSR
) | 6);
411 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
414 if (!priv
->ch
[k
].enabled
)
417 /* set bpp format in PKF[4:0] */
418 tmp
= lcdc_read_chan(ch
, LDDFR
);
419 tmp
&= ~(0x0001001f);
420 tmp
|= (priv
->ch
[k
].info
.var
.bits_per_pixel
== 16) ? 3 : 0;
421 lcdc_write_chan(ch
, LDDFR
, tmp
);
423 /* point out our frame buffer */
424 lcdc_write_chan(ch
, LDSA1R
, ch
->info
.fix
.smem_start
);
427 lcdc_write_chan(ch
, LDMLSR
, ch
->info
.fix
.line_length
);
429 /* setup deferred io if SYS bus */
430 tmp
= ch
->cfg
.sys_bus_cfg
.deferred_io_msec
;
431 if (ch
->ldmt1r_value
& (1 << 12) && tmp
) {
432 ch
->defio
.deferred_io
= sh_mobile_lcdc_deferred_io
;
433 ch
->defio
.delay
= msecs_to_jiffies(tmp
);
434 ch
->info
.fbdefio
= &ch
->defio
;
435 fb_deferred_io_init(&ch
->info
);
438 lcdc_write_chan(ch
, LDSM1R
, 1);
440 /* enable "Frame End Interrupt Enable" bit */
441 lcdc_write(priv
, _LDINTR
, LDINTR_FE
);
444 /* continuous read mode */
445 lcdc_write_chan(ch
, LDSM1R
, 0);
450 lcdc_write(priv
, _LDCNT1R
, LCDC_ENABLE
);
453 sh_mobile_lcdc_start_stop(priv
, 1);
455 /* tell the board code to enable the panel */
456 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
458 board_cfg
= &ch
->cfg
.board_cfg
;
459 if (board_cfg
->display_on
)
460 board_cfg
->display_on(board_cfg
->board_data
);
466 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
468 struct sh_mobile_lcdc_chan
*ch
;
469 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
472 /* clean up deferred io and ask board code to disable panel */
473 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
477 * flush frame, and wait for frame end interrupt
478 * clean up deferred io and enable clock
480 if (ch
->info
.fbdefio
) {
482 schedule_delayed_work(&ch
->info
.deferred_work
, 0);
483 wait_event(ch
->frame_end_wait
, ch
->frame_end
);
484 fb_deferred_io_cleanup(&ch
->info
);
485 ch
->info
.fbdefio
= NULL
;
486 sh_mobile_lcdc_clk_on(priv
);
489 board_cfg
= &ch
->cfg
.board_cfg
;
490 if (board_cfg
->display_off
)
491 board_cfg
->display_off(board_cfg
->board_data
);
496 sh_mobile_lcdc_start_stop(priv
, 0);
499 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
500 if (priv
->ch
[k
].enabled
)
501 sh_mobile_lcdc_clk_off(priv
);
504 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
508 switch (ch
->cfg
.interface_type
) {
509 case RGB8
: ifm
= 0; miftyp
= 0; break;
510 case RGB9
: ifm
= 0; miftyp
= 4; break;
511 case RGB12A
: ifm
= 0; miftyp
= 5; break;
512 case RGB12B
: ifm
= 0; miftyp
= 6; break;
513 case RGB16
: ifm
= 0; miftyp
= 7; break;
514 case RGB18
: ifm
= 0; miftyp
= 10; break;
515 case RGB24
: ifm
= 0; miftyp
= 11; break;
516 case SYS8A
: ifm
= 1; miftyp
= 0; break;
517 case SYS8B
: ifm
= 1; miftyp
= 1; break;
518 case SYS8C
: ifm
= 1; miftyp
= 2; break;
519 case SYS8D
: ifm
= 1; miftyp
= 3; break;
520 case SYS9
: ifm
= 1; miftyp
= 4; break;
521 case SYS12
: ifm
= 1; miftyp
= 5; break;
522 case SYS16A
: ifm
= 1; miftyp
= 7; break;
523 case SYS16B
: ifm
= 1; miftyp
= 8; break;
524 case SYS16C
: ifm
= 1; miftyp
= 9; break;
525 case SYS18
: ifm
= 1; miftyp
= 10; break;
526 case SYS24
: ifm
= 1; miftyp
= 11; break;
530 /* SUBLCD only supports SYS interface */
531 if (lcdc_chan_is_sublcd(ch
)) {
538 ch
->ldmt1r_value
= (ifm
<< 12) | miftyp
;
544 static int sh_mobile_lcdc_setup_clocks(struct platform_device
*pdev
,
546 struct sh_mobile_lcdc_priv
*priv
)
548 #ifdef CONFIG_HAVE_CLK
554 switch (clock_source
) {
555 case LCDC_CLK_BUS
: str
= "bus_clk"; icksel
= 0; break;
556 case LCDC_CLK_PERIPHERAL
: str
= "peripheral_clk"; icksel
= 1; break;
557 case LCDC_CLK_EXTERNAL
: str
= NULL
; icksel
= 2; break;
562 priv
->lddckr
= icksel
<< 16;
564 #ifdef CONFIG_HAVE_CLK
565 atomic_set(&priv
->clk_usecnt
, -1);
566 snprintf(clk_name
, sizeof(clk_name
), "lcdc%d", pdev
->id
);
567 priv
->clk
= clk_get(&pdev
->dev
, clk_name
);
568 if (IS_ERR(priv
->clk
)) {
569 dev_err(&pdev
->dev
, "cannot get clock \"%s\"\n", clk_name
);
570 return PTR_ERR(priv
->clk
);
574 priv
->dot_clk
= clk_get(&pdev
->dev
, str
);
575 if (IS_ERR(priv
->dot_clk
)) {
576 dev_err(&pdev
->dev
, "cannot get dot clock %s\n", str
);
578 return PTR_ERR(priv
->dot_clk
);
586 static int sh_mobile_lcdc_setcolreg(u_int regno
,
587 u_int red
, u_int green
, u_int blue
,
588 u_int transp
, struct fb_info
*info
)
590 u32
*palette
= info
->pseudo_palette
;
592 if (regno
>= PALETTE_NR
)
595 /* only FB_VISUAL_TRUECOLOR supported */
597 red
>>= 16 - info
->var
.red
.length
;
598 green
>>= 16 - info
->var
.green
.length
;
599 blue
>>= 16 - info
->var
.blue
.length
;
600 transp
>>= 16 - info
->var
.transp
.length
;
602 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
603 (green
<< info
->var
.green
.offset
) |
604 (blue
<< info
->var
.blue
.offset
) |
605 (transp
<< info
->var
.transp
.offset
);
610 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
611 .id
= "SH Mobile LCDC",
612 .type
= FB_TYPE_PACKED_PIXELS
,
613 .visual
= FB_VISUAL_TRUECOLOR
,
614 .accel
= FB_ACCEL_NONE
,
617 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
618 const struct fb_fillrect
*rect
)
620 sys_fillrect(info
, rect
);
621 sh_mobile_lcdc_deferred_io_touch(info
);
624 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
625 const struct fb_copyarea
*area
)
627 sys_copyarea(info
, area
);
628 sh_mobile_lcdc_deferred_io_touch(info
);
631 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
632 const struct fb_image
*image
)
634 sys_imageblit(info
, image
);
635 sh_mobile_lcdc_deferred_io_touch(info
);
638 static struct fb_ops sh_mobile_lcdc_ops
= {
639 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
640 .fb_read
= fb_sys_read
,
641 .fb_write
= fb_sys_write
,
642 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
643 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
644 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
647 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo
*var
, int bpp
)
650 case 16: /* PKF[4:0] = 00011 - RGB 565 */
651 var
->red
.offset
= 11;
653 var
->green
.offset
= 5;
654 var
->green
.length
= 6;
655 var
->blue
.offset
= 0;
656 var
->blue
.length
= 5;
657 var
->transp
.offset
= 0;
658 var
->transp
.length
= 0;
661 case 32: /* PKF[4:0] = 00000 - RGB 888
662 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
663 * this may be because LDDDSR has word swap enabled..
667 var
->green
.offset
= 24;
668 var
->green
.length
= 8;
669 var
->blue
.offset
= 16;
670 var
->blue
.length
= 8;
671 var
->transp
.offset
= 0;
672 var
->transp
.length
= 0;
677 var
->bits_per_pixel
= bpp
;
678 var
->red
.msb_right
= 0;
679 var
->green
.msb_right
= 0;
680 var
->blue
.msb_right
= 0;
681 var
->transp
.msb_right
= 0;
685 static int sh_mobile_lcdc_suspend(struct device
*dev
)
687 struct platform_device
*pdev
= to_platform_device(dev
);
689 sh_mobile_lcdc_stop(platform_get_drvdata(pdev
));
693 static int sh_mobile_lcdc_resume(struct device
*dev
)
695 struct platform_device
*pdev
= to_platform_device(dev
);
697 return sh_mobile_lcdc_start(platform_get_drvdata(pdev
));
700 static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops
= {
701 .suspend
= sh_mobile_lcdc_suspend
,
702 .resume
= sh_mobile_lcdc_resume
,
705 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
);
707 static int __init
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
709 struct fb_info
*info
;
710 struct sh_mobile_lcdc_priv
*priv
;
711 struct sh_mobile_lcdc_info
*pdata
;
712 struct sh_mobile_lcdc_chan_cfg
*cfg
;
713 struct resource
*res
;
718 if (!pdev
->dev
.platform_data
) {
719 dev_err(&pdev
->dev
, "no platform data defined\n");
724 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
725 i
= platform_get_irq(pdev
, 0);
727 dev_err(&pdev
->dev
, "cannot get platform resources\n");
732 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
734 dev_err(&pdev
->dev
, "cannot allocate device data\n");
739 error
= request_irq(i
, sh_mobile_lcdc_irq
, IRQF_DISABLED
,
740 dev_name(&pdev
->dev
), priv
);
742 dev_err(&pdev
->dev
, "unable to request irq\n");
747 platform_set_drvdata(pdev
, priv
);
748 pdata
= pdev
->dev
.platform_data
;
751 for (i
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
752 priv
->ch
[j
].lcdc
= priv
;
753 memcpy(&priv
->ch
[j
].cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
755 error
= sh_mobile_lcdc_check_interface(&priv
->ch
[i
]);
757 dev_err(&pdev
->dev
, "unsupported interface type\n");
760 init_waitqueue_head(&priv
->ch
[i
].frame_end_wait
);
762 switch (pdata
->ch
[i
].chan
) {
763 case LCDC_CHAN_MAINLCD
:
764 priv
->ch
[j
].enabled
= 1 << 1;
765 priv
->ch
[j
].reg_offs
= lcdc_offs_mainlcd
;
768 case LCDC_CHAN_SUBLCD
:
769 priv
->ch
[j
].enabled
= 1 << 2;
770 priv
->ch
[j
].reg_offs
= lcdc_offs_sublcd
;
777 dev_err(&pdev
->dev
, "no channels defined\n");
782 error
= sh_mobile_lcdc_setup_clocks(pdev
, pdata
->clock_source
, priv
);
784 dev_err(&pdev
->dev
, "unable to setup clocks\n");
788 priv
->base
= ioremap_nocache(res
->start
, (res
->end
- res
->start
) + 1);
790 for (i
= 0; i
< j
; i
++) {
791 info
= &priv
->ch
[i
].info
;
792 cfg
= &priv
->ch
[i
].cfg
;
794 info
->fbops
= &sh_mobile_lcdc_ops
;
795 info
->var
.xres
= info
->var
.xres_virtual
= cfg
->lcd_cfg
.xres
;
796 info
->var
.yres
= info
->var
.yres_virtual
= cfg
->lcd_cfg
.yres
;
797 info
->var
.width
= cfg
->lcd_size_cfg
.width
;
798 info
->var
.height
= cfg
->lcd_size_cfg
.height
;
799 info
->var
.activate
= FB_ACTIVATE_NOW
;
800 error
= sh_mobile_lcdc_set_bpp(&info
->var
, cfg
->bpp
);
804 info
->fix
= sh_mobile_lcdc_fix
;
805 info
->fix
.line_length
= cfg
->lcd_cfg
.xres
* (cfg
->bpp
/ 8);
806 info
->fix
.smem_len
= info
->fix
.line_length
* cfg
->lcd_cfg
.yres
;
808 buf
= dma_alloc_coherent(&pdev
->dev
, info
->fix
.smem_len
,
809 &priv
->ch
[i
].dma_handle
, GFP_KERNEL
);
811 dev_err(&pdev
->dev
, "unable to allocate buffer\n");
816 info
->pseudo_palette
= &priv
->ch
[i
].pseudo_palette
;
817 info
->flags
= FBINFO_FLAG_DEFAULT
;
819 error
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
821 dev_err(&pdev
->dev
, "unable to allocate cmap\n");
822 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
823 buf
, priv
->ch
[i
].dma_handle
);
827 memset(buf
, 0, info
->fix
.smem_len
);
828 info
->fix
.smem_start
= priv
->ch
[i
].dma_handle
;
829 info
->screen_base
= buf
;
830 info
->device
= &pdev
->dev
;
831 info
->par
= &priv
->ch
[i
];
837 error
= sh_mobile_lcdc_start(priv
);
839 dev_err(&pdev
->dev
, "unable to start hardware\n");
843 for (i
= 0; i
< j
; i
++) {
844 error
= register_framebuffer(&priv
->ch
[i
].info
);
849 for (i
= 0; i
< j
; i
++) {
850 info
= &priv
->ch
[i
].info
;
852 "registered %s/%s as %dx%d %dbpp.\n",
854 (priv
->ch
[i
].cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
855 "mainlcd" : "sublcd",
856 (int) priv
->ch
[i
].cfg
.lcd_cfg
.xres
,
857 (int) priv
->ch
[i
].cfg
.lcd_cfg
.yres
,
858 priv
->ch
[i
].cfg
.bpp
);
860 /* deferred io mode: disable clock to save power */
862 sh_mobile_lcdc_clk_off(priv
);
867 sh_mobile_lcdc_remove(pdev
);
872 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
874 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
875 struct fb_info
*info
;
878 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
879 if (priv
->ch
[i
].info
.dev
)
880 unregister_framebuffer(&priv
->ch
[i
].info
);
882 sh_mobile_lcdc_stop(priv
);
884 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
885 info
= &priv
->ch
[i
].info
;
890 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
891 info
->screen_base
, priv
->ch
[i
].dma_handle
);
892 fb_dealloc_cmap(&info
->cmap
);
895 #ifdef CONFIG_HAVE_CLK
897 clk_put(priv
->dot_clk
);
905 free_irq(priv
->irq
, priv
);
910 static struct platform_driver sh_mobile_lcdc_driver
= {
912 .name
= "sh_mobile_lcdc_fb",
913 .owner
= THIS_MODULE
,
914 .pm
= &sh_mobile_lcdc_dev_pm_ops
,
916 .probe
= sh_mobile_lcdc_probe
,
917 .remove
= sh_mobile_lcdc_remove
,
920 static int __init
sh_mobile_lcdc_init(void)
922 return platform_driver_register(&sh_mobile_lcdc_driver
);
925 static void __exit
sh_mobile_lcdc_exit(void)
927 platform_driver_unregister(&sh_mobile_lcdc_driver
);
930 module_init(sh_mobile_lcdc_init
);
931 module_exit(sh_mobile_lcdc_exit
);
933 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
934 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
935 MODULE_LICENSE("GPL v2");