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
;
38 struct sh_mobile_lcdc_priv
{
41 #ifdef CONFIG_HAVE_CLK
47 struct sh_mobile_lcdc_chan ch
[2];
50 /* shared registers */
52 #define _LDDCKSTPR 0x414
55 #define _LDCNT1R 0x470
56 #define _LDCNT2R 0x474
58 #define _LDDWD0R 0x800
63 /* per-channel registers */
64 enum { LDDCKPAT1R
, LDDCKPAT2R
, LDMT1R
, LDMT2R
, LDMT3R
, LDDFR
, LDSM1R
,
65 LDSM2R
, LDSA1R
, LDMLSR
, LDHCNR
, LDHSYNR
, LDVLNR
, LDVSYNR
, LDPMR
};
67 static unsigned long lcdc_offs_mainlcd
[] = {
85 static unsigned long lcdc_offs_sublcd
[] = {
103 #define START_LCDC 0x00000001
104 #define LCDC_RESET 0x00000100
105 #define DISPLAY_BEU 0x00000008
106 #define LCDC_ENABLE 0x00000001
107 #define LDINTR_FE 0x00000400
108 #define LDINTR_FS 0x00000004
110 static void lcdc_write_chan(struct sh_mobile_lcdc_chan
*chan
,
111 int reg_nr
, unsigned long data
)
113 iowrite32(data
, chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
116 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan
*chan
,
119 return ioread32(chan
->lcdc
->base
+ chan
->reg_offs
[reg_nr
]);
122 static void lcdc_write(struct sh_mobile_lcdc_priv
*priv
,
123 unsigned long reg_offs
, unsigned long data
)
125 iowrite32(data
, priv
->base
+ reg_offs
);
128 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv
*priv
,
129 unsigned long reg_offs
)
131 return ioread32(priv
->base
+ reg_offs
);
134 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv
*priv
,
135 unsigned long reg_offs
,
136 unsigned long mask
, unsigned long until
)
138 while ((lcdc_read(priv
, reg_offs
) & mask
) != until
)
142 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan
*chan
)
144 return chan
->cfg
.chan
== LCDC_CHAN_SUBLCD
;
147 static void lcdc_sys_write_index(void *handle
, unsigned long data
)
149 struct sh_mobile_lcdc_chan
*ch
= handle
;
151 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x10000000);
152 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
153 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
156 static void lcdc_sys_write_data(void *handle
, unsigned long data
)
158 struct sh_mobile_lcdc_chan
*ch
= handle
;
160 lcdc_write(ch
->lcdc
, _LDDWD0R
, data
| 0x11000000);
161 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
162 lcdc_write(ch
->lcdc
, _LDDWAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
165 static unsigned long lcdc_sys_read_data(void *handle
)
167 struct sh_mobile_lcdc_chan
*ch
= handle
;
169 lcdc_write(ch
->lcdc
, _LDDRDR
, 0x01000000);
170 lcdc_wait_bit(ch
->lcdc
, _LDSR
, 2, 0);
171 lcdc_write(ch
->lcdc
, _LDDRAR
, 1 | (lcdc_chan_is_sublcd(ch
) ? 2 : 0));
174 return lcdc_read(ch
->lcdc
, _LDDRDR
) & 0xffff;
177 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops
= {
178 lcdc_sys_write_index
,
183 #ifdef CONFIG_HAVE_CLK
184 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
)
186 if (atomic_inc_and_test(&priv
->clk_usecnt
)) {
187 clk_enable(priv
->clk
);
189 clk_enable(priv
->dot_clk
);
193 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
)
195 if (atomic_sub_return(1, &priv
->clk_usecnt
) == -1) {
197 clk_disable(priv
->dot_clk
);
198 clk_disable(priv
->clk
);
202 static void sh_mobile_lcdc_clk_on(struct sh_mobile_lcdc_priv
*priv
) {}
203 static void sh_mobile_lcdc_clk_off(struct sh_mobile_lcdc_priv
*priv
) {}
206 static void sh_mobile_lcdc_deferred_io(struct fb_info
*info
,
207 struct list_head
*pagelist
)
209 struct sh_mobile_lcdc_chan
*ch
= info
->par
;
211 /* enable clocks before accessing hardware */
212 sh_mobile_lcdc_clk_on(ch
->lcdc
);
214 /* trigger panel update */
215 lcdc_write_chan(ch
, LDSM2R
, 1);
218 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info
*info
)
220 struct fb_deferred_io
*fbdefio
= info
->fbdefio
;
223 schedule_delayed_work(&info
->deferred_work
, fbdefio
->delay
);
226 static irqreturn_t
sh_mobile_lcdc_irq(int irq
, void *data
)
228 struct sh_mobile_lcdc_priv
*priv
= data
;
231 /* acknowledge interrupt */
232 tmp
= lcdc_read(priv
, _LDINTR
);
233 tmp
&= 0xffffff00; /* mask in high 24 bits */
234 tmp
|= 0x000000ff ^ LDINTR_FS
; /* status in low 8 */
235 lcdc_write(priv
, _LDINTR
, tmp
);
238 sh_mobile_lcdc_clk_off(priv
);
242 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv
*priv
,
245 unsigned long tmp
= lcdc_read(priv
, _LDCNT2R
);
248 /* start or stop the lcdc */
250 lcdc_write(priv
, _LDCNT2R
, tmp
| START_LCDC
);
252 lcdc_write(priv
, _LDCNT2R
, tmp
& ~START_LCDC
);
254 /* wait until power is applied/stopped on all channels */
255 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
256 if (lcdc_read(priv
, _LDCNT2R
) & priv
->ch
[k
].enabled
)
258 tmp
= lcdc_read_chan(&priv
->ch
[k
], LDPMR
) & 3;
259 if (start
&& tmp
== 3)
261 if (!start
&& tmp
== 0)
267 lcdc_write(priv
, _LDDCKSTPR
, 1); /* stop dotclock */
270 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv
*priv
)
272 struct sh_mobile_lcdc_chan
*ch
;
273 struct fb_videomode
*lcd_cfg
;
274 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
279 /* enable clocks before accessing the hardware */
280 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
281 if (priv
->ch
[k
].enabled
)
282 sh_mobile_lcdc_clk_on(priv
);
285 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) | LCDC_RESET
);
286 lcdc_wait_bit(priv
, _LDCNT2R
, LCDC_RESET
, 0);
288 /* enable LCDC channels */
289 tmp
= lcdc_read(priv
, _LDCNT2R
);
290 tmp
|= priv
->ch
[0].enabled
;
291 tmp
|= priv
->ch
[1].enabled
;
292 lcdc_write(priv
, _LDCNT2R
, tmp
);
294 /* read data from external memory, avoid using the BEU for now */
295 lcdc_write(priv
, _LDCNT2R
, lcdc_read(priv
, _LDCNT2R
) & ~DISPLAY_BEU
);
297 /* stop the lcdc first */
298 sh_mobile_lcdc_start_stop(priv
, 0);
300 /* configure clocks */
302 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
305 if (!priv
->ch
[k
].enabled
)
308 m
= ch
->cfg
.clock_divider
;
314 tmp
|= m
<< (lcdc_chan_is_sublcd(ch
) ? 8 : 0);
316 lcdc_write_chan(ch
, LDDCKPAT1R
, 0x00000000);
317 lcdc_write_chan(ch
, LDDCKPAT2R
, (1 << (m
/2)) - 1);
320 lcdc_write(priv
, _LDDCKR
, tmp
);
322 /* start dotclock again */
323 lcdc_write(priv
, _LDDCKSTPR
, 0);
324 lcdc_wait_bit(priv
, _LDDCKSTPR
, ~0, 0);
326 /* interrupts are disabled to begin with */
327 lcdc_write(priv
, _LDINTR
, 0);
329 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
331 lcd_cfg
= &ch
->cfg
.lcd_cfg
;
336 tmp
= ch
->ldmt1r_value
;
337 tmp
|= (lcd_cfg
->sync
& FB_SYNC_VERT_HIGH_ACT
) ? 0 : 1 << 28;
338 tmp
|= (lcd_cfg
->sync
& FB_SYNC_HOR_HIGH_ACT
) ? 0 : 1 << 27;
339 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWPOL
) ? 1 << 26 : 0;
340 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DIPOL
) ? 1 << 25 : 0;
341 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DAPOL
) ? 1 << 24 : 0;
342 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_HSCNT
) ? 1 << 17 : 0;
343 tmp
|= (ch
->cfg
.flags
& LCDC_FLAGS_DWCNT
) ? 1 << 16 : 0;
344 lcdc_write_chan(ch
, LDMT1R
, tmp
);
347 lcdc_write_chan(ch
, LDMT2R
, ch
->cfg
.sys_bus_cfg
.ldmt2r
);
348 lcdc_write_chan(ch
, LDMT3R
, ch
->cfg
.sys_bus_cfg
.ldmt3r
);
350 /* horizontal configuration */
351 tmp
= lcd_cfg
->xres
+ lcd_cfg
->hsync_len
;
352 tmp
+= lcd_cfg
->left_margin
;
353 tmp
+= lcd_cfg
->right_margin
;
355 tmp
|= (lcd_cfg
->xres
/ 8) << 16; /* HDCN */
356 lcdc_write_chan(ch
, LDHCNR
, tmp
);
359 tmp
+= lcd_cfg
->right_margin
;
360 tmp
/= 8; /* HSYNP */
361 tmp
|= (lcd_cfg
->hsync_len
/ 8) << 16; /* HSYNW */
362 lcdc_write_chan(ch
, LDHSYNR
, tmp
);
365 lcdc_write_chan(ch
, LDPMR
, 0);
367 /* vertical configuration */
368 tmp
= lcd_cfg
->yres
+ lcd_cfg
->vsync_len
;
369 tmp
+= lcd_cfg
->upper_margin
;
370 tmp
+= lcd_cfg
->lower_margin
; /* VTLN */
371 tmp
|= lcd_cfg
->yres
<< 16; /* VDLN */
372 lcdc_write_chan(ch
, LDVLNR
, tmp
);
375 tmp
+= lcd_cfg
->lower_margin
; /* VSYNP */
376 tmp
|= lcd_cfg
->vsync_len
<< 16; /* VSYNW */
377 lcdc_write_chan(ch
, LDVSYNR
, tmp
);
379 board_cfg
= &ch
->cfg
.board_cfg
;
380 if (board_cfg
->setup_sys
)
381 ret
= board_cfg
->setup_sys(board_cfg
->board_data
, ch
,
382 &sh_mobile_lcdc_sys_bus_ops
);
387 /* word and long word swap */
388 lcdc_write(priv
, _LDDDSR
, lcdc_read(priv
, _LDDDSR
) | 6);
390 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
393 if (!priv
->ch
[k
].enabled
)
396 /* set bpp format in PKF[4:0] */
397 tmp
= lcdc_read_chan(ch
, LDDFR
);
398 tmp
&= ~(0x0001001f);
399 tmp
|= (priv
->ch
[k
].info
.var
.bits_per_pixel
== 16) ? 3 : 0;
400 lcdc_write_chan(ch
, LDDFR
, tmp
);
402 /* point out our frame buffer */
403 lcdc_write_chan(ch
, LDSA1R
, ch
->info
.fix
.smem_start
);
406 lcdc_write_chan(ch
, LDMLSR
, ch
->info
.fix
.line_length
);
408 /* setup deferred io if SYS bus */
409 tmp
= ch
->cfg
.sys_bus_cfg
.deferred_io_msec
;
410 if (ch
->ldmt1r_value
& (1 << 12) && tmp
) {
411 ch
->defio
.deferred_io
= sh_mobile_lcdc_deferred_io
;
412 ch
->defio
.delay
= msecs_to_jiffies(tmp
);
413 ch
->info
.fbdefio
= &ch
->defio
;
414 fb_deferred_io_init(&ch
->info
);
417 lcdc_write_chan(ch
, LDSM1R
, 1);
419 /* enable "Frame End Interrupt Enable" bit */
420 lcdc_write(priv
, _LDINTR
, LDINTR_FE
);
423 /* continuous read mode */
424 lcdc_write_chan(ch
, LDSM1R
, 0);
429 lcdc_write(priv
, _LDCNT1R
, LCDC_ENABLE
);
432 sh_mobile_lcdc_start_stop(priv
, 1);
434 /* tell the board code to enable the panel */
435 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
437 board_cfg
= &ch
->cfg
.board_cfg
;
438 if (board_cfg
->display_on
)
439 board_cfg
->display_on(board_cfg
->board_data
);
445 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv
*priv
)
447 struct sh_mobile_lcdc_chan
*ch
;
448 struct sh_mobile_lcdc_board_cfg
*board_cfg
;
451 /* tell the board code to disable the panel */
452 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++) {
454 board_cfg
= &ch
->cfg
.board_cfg
;
455 if (board_cfg
->display_off
)
456 board_cfg
->display_off(board_cfg
->board_data
);
458 /* cleanup deferred io if enabled */
459 if (ch
->info
.fbdefio
) {
460 fb_deferred_io_cleanup(&ch
->info
);
461 ch
->info
.fbdefio
= NULL
;
466 sh_mobile_lcdc_start_stop(priv
, 0);
469 for (k
= 0; k
< ARRAY_SIZE(priv
->ch
); k
++)
470 if (priv
->ch
[k
].enabled
)
471 sh_mobile_lcdc_clk_off(priv
);
474 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan
*ch
)
478 switch (ch
->cfg
.interface_type
) {
479 case RGB8
: ifm
= 0; miftyp
= 0; break;
480 case RGB9
: ifm
= 0; miftyp
= 4; break;
481 case RGB12A
: ifm
= 0; miftyp
= 5; break;
482 case RGB12B
: ifm
= 0; miftyp
= 6; break;
483 case RGB16
: ifm
= 0; miftyp
= 7; break;
484 case RGB18
: ifm
= 0; miftyp
= 10; break;
485 case RGB24
: ifm
= 0; miftyp
= 11; break;
486 case SYS8A
: ifm
= 1; miftyp
= 0; break;
487 case SYS8B
: ifm
= 1; miftyp
= 1; break;
488 case SYS8C
: ifm
= 1; miftyp
= 2; break;
489 case SYS8D
: ifm
= 1; miftyp
= 3; break;
490 case SYS9
: ifm
= 1; miftyp
= 4; break;
491 case SYS12
: ifm
= 1; miftyp
= 5; break;
492 case SYS16A
: ifm
= 1; miftyp
= 7; break;
493 case SYS16B
: ifm
= 1; miftyp
= 8; break;
494 case SYS16C
: ifm
= 1; miftyp
= 9; break;
495 case SYS18
: ifm
= 1; miftyp
= 10; break;
496 case SYS24
: ifm
= 1; miftyp
= 11; break;
500 /* SUBLCD only supports SYS interface */
501 if (lcdc_chan_is_sublcd(ch
)) {
508 ch
->ldmt1r_value
= (ifm
<< 12) | miftyp
;
514 static int sh_mobile_lcdc_setup_clocks(struct platform_device
*pdev
,
516 struct sh_mobile_lcdc_priv
*priv
)
518 #ifdef CONFIG_HAVE_CLK
524 switch (clock_source
) {
525 case LCDC_CLK_BUS
: str
= "bus_clk"; icksel
= 0; break;
526 case LCDC_CLK_PERIPHERAL
: str
= "peripheral_clk"; icksel
= 1; break;
527 case LCDC_CLK_EXTERNAL
: str
= NULL
; icksel
= 2; break;
532 priv
->lddckr
= icksel
<< 16;
534 #ifdef CONFIG_HAVE_CLK
535 atomic_set(&priv
->clk_usecnt
, -1);
536 snprintf(clk_name
, sizeof(clk_name
), "lcdc%d", pdev
->id
);
537 priv
->clk
= clk_get(&pdev
->dev
, clk_name
);
538 if (IS_ERR(priv
->clk
)) {
539 dev_err(&pdev
->dev
, "cannot get clock \"%s\"\n", clk_name
);
540 return PTR_ERR(priv
->clk
);
544 priv
->dot_clk
= clk_get(&pdev
->dev
, str
);
545 if (IS_ERR(priv
->dot_clk
)) {
546 dev_err(&pdev
->dev
, "cannot get dot clock %s\n", str
);
548 return PTR_ERR(priv
->dot_clk
);
556 static int sh_mobile_lcdc_setcolreg(u_int regno
,
557 u_int red
, u_int green
, u_int blue
,
558 u_int transp
, struct fb_info
*info
)
560 u32
*palette
= info
->pseudo_palette
;
562 if (regno
>= PALETTE_NR
)
565 /* only FB_VISUAL_TRUECOLOR supported */
567 red
>>= 16 - info
->var
.red
.length
;
568 green
>>= 16 - info
->var
.green
.length
;
569 blue
>>= 16 - info
->var
.blue
.length
;
570 transp
>>= 16 - info
->var
.transp
.length
;
572 palette
[regno
] = (red
<< info
->var
.red
.offset
) |
573 (green
<< info
->var
.green
.offset
) |
574 (blue
<< info
->var
.blue
.offset
) |
575 (transp
<< info
->var
.transp
.offset
);
580 static struct fb_fix_screeninfo sh_mobile_lcdc_fix
= {
581 .id
= "SH Mobile LCDC",
582 .type
= FB_TYPE_PACKED_PIXELS
,
583 .visual
= FB_VISUAL_TRUECOLOR
,
584 .accel
= FB_ACCEL_NONE
,
587 static void sh_mobile_lcdc_fillrect(struct fb_info
*info
,
588 const struct fb_fillrect
*rect
)
590 sys_fillrect(info
, rect
);
591 sh_mobile_lcdc_deferred_io_touch(info
);
594 static void sh_mobile_lcdc_copyarea(struct fb_info
*info
,
595 const struct fb_copyarea
*area
)
597 sys_copyarea(info
, area
);
598 sh_mobile_lcdc_deferred_io_touch(info
);
601 static void sh_mobile_lcdc_imageblit(struct fb_info
*info
,
602 const struct fb_image
*image
)
604 sys_imageblit(info
, image
);
605 sh_mobile_lcdc_deferred_io_touch(info
);
608 static struct fb_ops sh_mobile_lcdc_ops
= {
609 .fb_setcolreg
= sh_mobile_lcdc_setcolreg
,
610 .fb_read
= fb_sys_read
,
611 .fb_write
= fb_sys_write
,
612 .fb_fillrect
= sh_mobile_lcdc_fillrect
,
613 .fb_copyarea
= sh_mobile_lcdc_copyarea
,
614 .fb_imageblit
= sh_mobile_lcdc_imageblit
,
617 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo
*var
, int bpp
)
620 case 16: /* PKF[4:0] = 00011 - RGB 565 */
621 var
->red
.offset
= 11;
623 var
->green
.offset
= 5;
624 var
->green
.length
= 6;
625 var
->blue
.offset
= 0;
626 var
->blue
.length
= 5;
627 var
->transp
.offset
= 0;
628 var
->transp
.length
= 0;
631 case 32: /* PKF[4:0] = 00000 - RGB 888
632 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
633 * this may be because LDDDSR has word swap enabled..
637 var
->green
.offset
= 24;
638 var
->green
.length
= 8;
639 var
->blue
.offset
= 16;
640 var
->blue
.length
= 8;
641 var
->transp
.offset
= 0;
642 var
->transp
.length
= 0;
647 var
->bits_per_pixel
= bpp
;
648 var
->red
.msb_right
= 0;
649 var
->green
.msb_right
= 0;
650 var
->blue
.msb_right
= 0;
651 var
->transp
.msb_right
= 0;
655 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
);
657 static int __init
sh_mobile_lcdc_probe(struct platform_device
*pdev
)
659 struct fb_info
*info
;
660 struct sh_mobile_lcdc_priv
*priv
;
661 struct sh_mobile_lcdc_info
*pdata
;
662 struct sh_mobile_lcdc_chan_cfg
*cfg
;
663 struct resource
*res
;
668 if (!pdev
->dev
.platform_data
) {
669 dev_err(&pdev
->dev
, "no platform data defined\n");
674 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
675 i
= platform_get_irq(pdev
, 0);
677 dev_err(&pdev
->dev
, "cannot get platform resources\n");
682 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
684 dev_err(&pdev
->dev
, "cannot allocate device data\n");
689 error
= request_irq(i
, sh_mobile_lcdc_irq
, IRQF_DISABLED
,
690 pdev
->dev
.bus_id
, priv
);
692 dev_err(&pdev
->dev
, "unable to request irq\n");
697 platform_set_drvdata(pdev
, priv
);
698 pdata
= pdev
->dev
.platform_data
;
701 for (i
= 0; i
< ARRAY_SIZE(pdata
->ch
); i
++) {
702 priv
->ch
[j
].lcdc
= priv
;
703 memcpy(&priv
->ch
[j
].cfg
, &pdata
->ch
[i
], sizeof(pdata
->ch
[i
]));
705 error
= sh_mobile_lcdc_check_interface(&priv
->ch
[i
]);
707 dev_err(&pdev
->dev
, "unsupported interface type\n");
711 switch (pdata
->ch
[i
].chan
) {
712 case LCDC_CHAN_MAINLCD
:
713 priv
->ch
[j
].enabled
= 1 << 1;
714 priv
->ch
[j
].reg_offs
= lcdc_offs_mainlcd
;
717 case LCDC_CHAN_SUBLCD
:
718 priv
->ch
[j
].enabled
= 1 << 2;
719 priv
->ch
[j
].reg_offs
= lcdc_offs_sublcd
;
726 dev_err(&pdev
->dev
, "no channels defined\n");
731 error
= sh_mobile_lcdc_setup_clocks(pdev
, pdata
->clock_source
, priv
);
733 dev_err(&pdev
->dev
, "unable to setup clocks\n");
737 priv
->base
= ioremap_nocache(res
->start
, (res
->end
- res
->start
) + 1);
739 for (i
= 0; i
< j
; i
++) {
740 info
= &priv
->ch
[i
].info
;
741 cfg
= &priv
->ch
[i
].cfg
;
743 info
->fbops
= &sh_mobile_lcdc_ops
;
744 info
->var
.xres
= info
->var
.xres_virtual
= cfg
->lcd_cfg
.xres
;
745 info
->var
.yres
= info
->var
.yres_virtual
= cfg
->lcd_cfg
.yres
;
746 info
->var
.width
= cfg
->lcd_size_cfg
.width
;
747 info
->var
.height
= cfg
->lcd_size_cfg
.height
;
748 info
->var
.activate
= FB_ACTIVATE_NOW
;
749 error
= sh_mobile_lcdc_set_bpp(&info
->var
, cfg
->bpp
);
753 info
->fix
= sh_mobile_lcdc_fix
;
754 info
->fix
.line_length
= cfg
->lcd_cfg
.xres
* (cfg
->bpp
/ 8);
755 info
->fix
.smem_len
= info
->fix
.line_length
* cfg
->lcd_cfg
.yres
;
757 buf
= dma_alloc_coherent(&pdev
->dev
, info
->fix
.smem_len
,
758 &priv
->ch
[i
].dma_handle
, GFP_KERNEL
);
760 dev_err(&pdev
->dev
, "unable to allocate buffer\n");
765 info
->pseudo_palette
= &priv
->ch
[i
].pseudo_palette
;
766 info
->flags
= FBINFO_FLAG_DEFAULT
;
768 error
= fb_alloc_cmap(&info
->cmap
, PALETTE_NR
, 0);
770 dev_err(&pdev
->dev
, "unable to allocate cmap\n");
771 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
772 buf
, priv
->ch
[i
].dma_handle
);
776 memset(buf
, 0, info
->fix
.smem_len
);
777 info
->fix
.smem_start
= priv
->ch
[i
].dma_handle
;
778 info
->screen_base
= buf
;
779 info
->device
= &pdev
->dev
;
780 info
->par
= &priv
->ch
[i
];
786 error
= sh_mobile_lcdc_start(priv
);
788 dev_err(&pdev
->dev
, "unable to start hardware\n");
792 for (i
= 0; i
< j
; i
++) {
793 error
= register_framebuffer(&priv
->ch
[i
].info
);
798 for (i
= 0; i
< j
; i
++) {
799 info
= &priv
->ch
[i
].info
;
801 "registered %s/%s as %dx%d %dbpp.\n",
803 (priv
->ch
[i
].cfg
.chan
== LCDC_CHAN_MAINLCD
) ?
804 "mainlcd" : "sublcd",
805 (int) priv
->ch
[i
].cfg
.lcd_cfg
.xres
,
806 (int) priv
->ch
[i
].cfg
.lcd_cfg
.yres
,
807 priv
->ch
[i
].cfg
.bpp
);
809 /* deferred io mode: disable clock to save power */
811 sh_mobile_lcdc_clk_off(priv
);
816 sh_mobile_lcdc_remove(pdev
);
821 static int sh_mobile_lcdc_remove(struct platform_device
*pdev
)
823 struct sh_mobile_lcdc_priv
*priv
= platform_get_drvdata(pdev
);
824 struct fb_info
*info
;
827 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++)
828 if (priv
->ch
[i
].info
.dev
)
829 unregister_framebuffer(&priv
->ch
[i
].info
);
831 sh_mobile_lcdc_stop(priv
);
833 for (i
= 0; i
< ARRAY_SIZE(priv
->ch
); i
++) {
834 info
= &priv
->ch
[i
].info
;
839 dma_free_coherent(&pdev
->dev
, info
->fix
.smem_len
,
840 info
->screen_base
, priv
->ch
[i
].dma_handle
);
841 fb_dealloc_cmap(&info
->cmap
);
844 #ifdef CONFIG_HAVE_CLK
846 clk_put(priv
->dot_clk
);
854 free_irq(priv
->irq
, priv
);
859 static struct platform_driver sh_mobile_lcdc_driver
= {
861 .name
= "sh_mobile_lcdc_fb",
862 .owner
= THIS_MODULE
,
864 .probe
= sh_mobile_lcdc_probe
,
865 .remove
= sh_mobile_lcdc_remove
,
868 static int __init
sh_mobile_lcdc_init(void)
870 return platform_driver_register(&sh_mobile_lcdc_driver
);
873 static void __exit
sh_mobile_lcdc_exit(void)
875 platform_driver_unregister(&sh_mobile_lcdc_driver
);
878 module_init(sh_mobile_lcdc_init
);
879 module_exit(sh_mobile_lcdc_exit
);
881 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
882 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
883 MODULE_LICENSE("GPL v2");