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 {
49 struct sh_mobile_lcdc_chan ch[2];
53 /* shared registers */
55 #define _LDDCKSTPR 0x414
58 #define _LDCNT1R 0x470
59 #define _LDCNT2R 0x474
61 #define _LDDWD0R 0x800
66 /* per-channel registers */
67 enum { LDDCKPAT1R, LDDCKPAT2R, LDMT1R, LDMT2R, LDMT3R, LDDFR, LDSM1R,
68 LDSM2R, LDSA1R, LDMLSR, LDHCNR, LDHSYNR, LDVLNR, LDVSYNR, LDPMR };
70 static unsigned long lcdc_offs_mainlcd[] = {
88 static unsigned long lcdc_offs_sublcd[] = {
106 #define START_LCDC 0x00000001
107 #define LCDC_RESET 0x00000100
108 #define DISPLAY_BEU 0x00000008
109 #define LCDC_ENABLE 0x00000001
110 #define LDINTR_FE 0x00000400
111 #define LDINTR_FS 0x00000004
113 static void lcdc_write_chan(struct sh_mobile_lcdc_chan *chan,
114 int reg_nr, unsigned long data)
116 iowrite32(data, chan->lcdc->base + chan->reg_offs[reg_nr]);
119 static unsigned long lcdc_read_chan(struct sh_mobile_lcdc_chan *chan,
122 return ioread32(chan->lcdc->base + chan->reg_offs[reg_nr]);
125 static void lcdc_write(struct sh_mobile_lcdc_priv *priv,
126 unsigned long reg_offs, unsigned long data)
128 iowrite32(data, priv->base + reg_offs);
131 static unsigned long lcdc_read(struct sh_mobile_lcdc_priv *priv,
132 unsigned long reg_offs)
134 return ioread32(priv->base + reg_offs);
137 static void lcdc_wait_bit(struct sh_mobile_lcdc_priv *priv,
138 unsigned long reg_offs,
139 unsigned long mask, unsigned long until)
141 while ((lcdc_read(priv, reg_offs) & mask) != until)
145 static int lcdc_chan_is_sublcd(struct sh_mobile_lcdc_chan *chan)
147 return chan->cfg.chan == LCDC_CHAN_SUBLCD;
150 static void lcdc_sys_write_index(void *handle, unsigned long data)
152 struct sh_mobile_lcdc_chan *ch = handle;
154 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x10000000);
155 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
156 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
157 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
160 static void lcdc_sys_write_data(void *handle, unsigned long data)
162 struct sh_mobile_lcdc_chan *ch = handle;
164 lcdc_write(ch->lcdc, _LDDWD0R, data | 0x11000000);
165 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
166 lcdc_write(ch->lcdc, _LDDWAR, 1 | (lcdc_chan_is_sublcd(ch) ? 2 : 0));
167 lcdc_wait_bit(ch->lcdc, _LDSR, 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));
178 lcdc_wait_bit(ch->lcdc, _LDSR, 2, 0);
180 return lcdc_read(ch->lcdc, _LDDRDR) & 0x3ffff;
183 struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
184 lcdc_sys_write_index,
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 int sh_mobile_lcdc_sginit(struct fb_info *info,
208 struct list_head *pagelist)
210 struct sh_mobile_lcdc_chan *ch = info->par;
211 unsigned int nr_pages_max = info->fix.smem_len >> PAGE_SHIFT;
215 sg_init_table(ch->sglist, nr_pages_max);
217 list_for_each_entry(page, pagelist, lru)
218 sg_set_page(&ch->sglist[nr_pages++], page, PAGE_SIZE, 0);
223 static void sh_mobile_lcdc_deferred_io(struct fb_info *info,
224 struct list_head *pagelist)
226 struct sh_mobile_lcdc_chan *ch = info->par;
227 unsigned int nr_pages;
229 /* enable clocks before accessing hardware */
230 sh_mobile_lcdc_clk_on(ch->lcdc);
232 nr_pages = sh_mobile_lcdc_sginit(info, pagelist);
233 dma_map_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
235 /* trigger panel update */
236 lcdc_write_chan(ch, LDSM2R, 1);
238 dma_unmap_sg(info->dev, ch->sglist, nr_pages, DMA_TO_DEVICE);
241 static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
243 struct fb_deferred_io *fbdefio = info->fbdefio;
246 schedule_delayed_work(&info->deferred_work, fbdefio->delay);
249 static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
251 struct sh_mobile_lcdc_priv *priv = data;
252 struct sh_mobile_lcdc_chan *ch;
257 /* acknowledge interrupt */
258 tmp = lcdc_read(priv, _LDINTR);
259 tmp &= 0xffffff00; /* mask in high 24 bits */
260 tmp |= 0x000000ff ^ LDINTR_FS; /* status in low 8 */
261 lcdc_write(priv, _LDINTR, tmp);
263 /* figure out if this interrupt is for main or sub lcd */
264 is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
266 /* wake up channel and disable clocks*/
267 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
273 if (is_sub == lcdc_chan_is_sublcd(ch)) {
275 wake_up(&ch->frame_end_wait);
277 sh_mobile_lcdc_clk_off(priv);
284 static void sh_mobile_lcdc_start_stop(struct sh_mobile_lcdc_priv *priv,
287 unsigned long tmp = lcdc_read(priv, _LDCNT2R);
290 /* start or stop the lcdc */
292 lcdc_write(priv, _LDCNT2R, tmp | START_LCDC);
294 lcdc_write(priv, _LDCNT2R, tmp & ~START_LCDC);
296 /* wait until power is applied/stopped on all channels */
297 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
298 if (lcdc_read(priv, _LDCNT2R) & priv->ch[k].enabled)
300 tmp = lcdc_read_chan(&priv->ch[k], LDPMR) & 3;
301 if (start && tmp == 3)
303 if (!start && tmp == 0)
309 lcdc_write(priv, _LDDCKSTPR, 1); /* stop dotclock */
312 static int sh_mobile_lcdc_start(struct sh_mobile_lcdc_priv *priv)
314 struct sh_mobile_lcdc_chan *ch;
315 struct fb_videomode *lcd_cfg;
316 struct sh_mobile_lcdc_board_cfg *board_cfg;
321 /* enable clocks before accessing the hardware */
322 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
323 if (priv->ch[k].enabled)
324 sh_mobile_lcdc_clk_on(priv);
327 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) | LCDC_RESET);
328 lcdc_wait_bit(priv, _LDCNT2R, LCDC_RESET, 0);
330 /* enable LCDC channels */
331 tmp = lcdc_read(priv, _LDCNT2R);
332 tmp |= priv->ch[0].enabled;
333 tmp |= priv->ch[1].enabled;
334 lcdc_write(priv, _LDCNT2R, tmp);
336 /* read data from external memory, avoid using the BEU for now */
337 lcdc_write(priv, _LDCNT2R, lcdc_read(priv, _LDCNT2R) & ~DISPLAY_BEU);
339 /* stop the lcdc first */
340 sh_mobile_lcdc_start_stop(priv, 0);
342 /* configure clocks */
344 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
347 if (!priv->ch[k].enabled)
350 m = ch->cfg.clock_divider;
356 tmp |= m << (lcdc_chan_is_sublcd(ch) ? 8 : 0);
358 lcdc_write_chan(ch, LDDCKPAT1R, 0x00000000);
359 lcdc_write_chan(ch, LDDCKPAT2R, (1 << (m/2)) - 1);
362 lcdc_write(priv, _LDDCKR, tmp);
364 /* start dotclock again */
365 lcdc_write(priv, _LDDCKSTPR, 0);
366 lcdc_wait_bit(priv, _LDDCKSTPR, ~0, 0);
368 /* interrupts are disabled to begin with */
369 lcdc_write(priv, _LDINTR, 0);
371 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
373 lcd_cfg = &ch->cfg.lcd_cfg;
378 tmp = ch->ldmt1r_value;
379 tmp |= (lcd_cfg->sync & FB_SYNC_VERT_HIGH_ACT) ? 0 : 1 << 28;
380 tmp |= (lcd_cfg->sync & FB_SYNC_HOR_HIGH_ACT) ? 0 : 1 << 27;
381 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWPOL) ? 1 << 26 : 0;
382 tmp |= (ch->cfg.flags & LCDC_FLAGS_DIPOL) ? 1 << 25 : 0;
383 tmp |= (ch->cfg.flags & LCDC_FLAGS_DAPOL) ? 1 << 24 : 0;
384 tmp |= (ch->cfg.flags & LCDC_FLAGS_HSCNT) ? 1 << 17 : 0;
385 tmp |= (ch->cfg.flags & LCDC_FLAGS_DWCNT) ? 1 << 16 : 0;
386 lcdc_write_chan(ch, LDMT1R, tmp);
389 lcdc_write_chan(ch, LDMT2R, ch->cfg.sys_bus_cfg.ldmt2r);
390 lcdc_write_chan(ch, LDMT3R, ch->cfg.sys_bus_cfg.ldmt3r);
392 /* horizontal configuration */
393 tmp = lcd_cfg->xres + lcd_cfg->hsync_len;
394 tmp += lcd_cfg->left_margin;
395 tmp += lcd_cfg->right_margin;
397 tmp |= (lcd_cfg->xres / 8) << 16; /* HDCN */
398 lcdc_write_chan(ch, LDHCNR, tmp);
401 tmp += lcd_cfg->right_margin;
402 tmp /= 8; /* HSYNP */
403 tmp |= (lcd_cfg->hsync_len / 8) << 16; /* HSYNW */
404 lcdc_write_chan(ch, LDHSYNR, tmp);
407 lcdc_write_chan(ch, LDPMR, 0);
409 /* vertical configuration */
410 tmp = lcd_cfg->yres + lcd_cfg->vsync_len;
411 tmp += lcd_cfg->upper_margin;
412 tmp += lcd_cfg->lower_margin; /* VTLN */
413 tmp |= lcd_cfg->yres << 16; /* VDLN */
414 lcdc_write_chan(ch, LDVLNR, tmp);
417 tmp += lcd_cfg->lower_margin; /* VSYNP */
418 tmp |= lcd_cfg->vsync_len << 16; /* VSYNW */
419 lcdc_write_chan(ch, LDVSYNR, tmp);
421 board_cfg = &ch->cfg.board_cfg;
422 if (board_cfg->setup_sys)
423 ret = board_cfg->setup_sys(board_cfg->board_data, ch,
424 &sh_mobile_lcdc_sys_bus_ops);
429 /* word and long word swap */
430 lcdc_write(priv, _LDDDSR, lcdc_read(priv, _LDDDSR) | 6);
432 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
435 if (!priv->ch[k].enabled)
438 /* set bpp format in PKF[4:0] */
439 tmp = lcdc_read_chan(ch, LDDFR);
440 tmp &= ~(0x0001001f);
441 tmp |= (ch->info->var.bits_per_pixel == 16) ? 3 : 0;
442 lcdc_write_chan(ch, LDDFR, tmp);
444 /* point out our frame buffer */
445 lcdc_write_chan(ch, LDSA1R, ch->info->fix.smem_start);
448 lcdc_write_chan(ch, LDMLSR, ch->info->fix.line_length);
450 /* setup deferred io if SYS bus */
451 tmp = ch->cfg.sys_bus_cfg.deferred_io_msec;
452 if (ch->ldmt1r_value & (1 << 12) && tmp) {
453 ch->defio.deferred_io = sh_mobile_lcdc_deferred_io;
454 ch->defio.delay = msecs_to_jiffies(tmp);
455 ch->info->fbdefio = &ch->defio;
456 fb_deferred_io_init(ch->info);
459 lcdc_write_chan(ch, LDSM1R, 1);
461 /* enable "Frame End Interrupt Enable" bit */
462 lcdc_write(priv, _LDINTR, LDINTR_FE);
465 /* continuous read mode */
466 lcdc_write_chan(ch, LDSM1R, 0);
471 lcdc_write(priv, _LDCNT1R, LCDC_ENABLE);
474 sh_mobile_lcdc_start_stop(priv, 1);
477 /* tell the board code to enable the panel */
478 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
480 board_cfg = &ch->cfg.board_cfg;
481 if (board_cfg->display_on)
482 board_cfg->display_on(board_cfg->board_data);
488 static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
490 struct sh_mobile_lcdc_chan *ch;
491 struct sh_mobile_lcdc_board_cfg *board_cfg;
494 /* clean up deferred io and ask board code to disable panel */
495 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
499 * flush frame, and wait for frame end interrupt
500 * clean up deferred io and enable clock
502 if (ch->info->fbdefio) {
504 schedule_delayed_work(&ch->info->deferred_work, 0);
505 wait_event(ch->frame_end_wait, ch->frame_end);
506 fb_deferred_io_cleanup(ch->info);
507 ch->info->fbdefio = NULL;
508 sh_mobile_lcdc_clk_on(priv);
511 board_cfg = &ch->cfg.board_cfg;
512 if (board_cfg->display_off)
513 board_cfg->display_off(board_cfg->board_data);
518 sh_mobile_lcdc_start_stop(priv, 0);
523 for (k = 0; k < ARRAY_SIZE(priv->ch); k++)
524 if (priv->ch[k].enabled)
525 sh_mobile_lcdc_clk_off(priv);
528 static int sh_mobile_lcdc_check_interface(struct sh_mobile_lcdc_chan *ch)
532 switch (ch->cfg.interface_type) {
533 case RGB8: ifm = 0; miftyp = 0; break;
534 case RGB9: ifm = 0; miftyp = 4; break;
535 case RGB12A: ifm = 0; miftyp = 5; break;
536 case RGB12B: ifm = 0; miftyp = 6; break;
537 case RGB16: ifm = 0; miftyp = 7; break;
538 case RGB18: ifm = 0; miftyp = 10; break;
539 case RGB24: ifm = 0; miftyp = 11; break;
540 case SYS8A: ifm = 1; miftyp = 0; break;
541 case SYS8B: ifm = 1; miftyp = 1; break;
542 case SYS8C: ifm = 1; miftyp = 2; break;
543 case SYS8D: ifm = 1; miftyp = 3; break;
544 case SYS9: ifm = 1; miftyp = 4; break;
545 case SYS12: ifm = 1; miftyp = 5; break;
546 case SYS16A: ifm = 1; miftyp = 7; break;
547 case SYS16B: ifm = 1; miftyp = 8; break;
548 case SYS16C: ifm = 1; miftyp = 9; break;
549 case SYS18: ifm = 1; miftyp = 10; break;
550 case SYS24: ifm = 1; miftyp = 11; break;
554 /* SUBLCD only supports SYS interface */
555 if (lcdc_chan_is_sublcd(ch)) {
562 ch->ldmt1r_value = (ifm << 12) | miftyp;
568 static int sh_mobile_lcdc_setup_clocks(struct platform_device *pdev,
570 struct sh_mobile_lcdc_priv *priv)
576 switch (clock_source) {
577 case LCDC_CLK_BUS: str = "bus_clk"; icksel = 0; break;
578 case LCDC_CLK_PERIPHERAL: str = "peripheral_clk"; icksel = 1; break;
579 case LCDC_CLK_EXTERNAL: str = NULL; icksel = 2; break;
584 priv->lddckr = icksel << 16;
586 atomic_set(&priv->clk_usecnt, -1);
587 snprintf(clk_name, sizeof(clk_name), "lcdc%d", pdev->id);
588 priv->clk = clk_get(&pdev->dev, clk_name);
589 if (IS_ERR(priv->clk)) {
590 dev_err(&pdev->dev, "cannot get clock \"%s\"\n", clk_name);
591 return PTR_ERR(priv->clk);
595 priv->dot_clk = clk_get(&pdev->dev, str);
596 if (IS_ERR(priv->dot_clk)) {
597 dev_err(&pdev->dev, "cannot get dot clock %s\n", str);
599 return PTR_ERR(priv->dot_clk);
606 static int sh_mobile_lcdc_setcolreg(u_int regno,
607 u_int red, u_int green, u_int blue,
608 u_int transp, struct fb_info *info)
610 u32 *palette = info->pseudo_palette;
612 if (regno >= PALETTE_NR)
615 /* only FB_VISUAL_TRUECOLOR supported */
617 red >>= 16 - info->var.red.length;
618 green >>= 16 - info->var.green.length;
619 blue >>= 16 - info->var.blue.length;
620 transp >>= 16 - info->var.transp.length;
622 palette[regno] = (red << info->var.red.offset) |
623 (green << info->var.green.offset) |
624 (blue << info->var.blue.offset) |
625 (transp << info->var.transp.offset);
630 static struct fb_fix_screeninfo sh_mobile_lcdc_fix = {
631 .id = "SH Mobile LCDC",
632 .type = FB_TYPE_PACKED_PIXELS,
633 .visual = FB_VISUAL_TRUECOLOR,
634 .accel = FB_ACCEL_NONE,
637 static void sh_mobile_lcdc_fillrect(struct fb_info *info,
638 const struct fb_fillrect *rect)
640 sys_fillrect(info, rect);
641 sh_mobile_lcdc_deferred_io_touch(info);
644 static void sh_mobile_lcdc_copyarea(struct fb_info *info,
645 const struct fb_copyarea *area)
647 sys_copyarea(info, area);
648 sh_mobile_lcdc_deferred_io_touch(info);
651 static void sh_mobile_lcdc_imageblit(struct fb_info *info,
652 const struct fb_image *image)
654 sys_imageblit(info, image);
655 sh_mobile_lcdc_deferred_io_touch(info);
658 static struct fb_ops sh_mobile_lcdc_ops = {
659 .fb_setcolreg = sh_mobile_lcdc_setcolreg,
660 .fb_read = fb_sys_read,
661 .fb_write = fb_sys_write,
662 .fb_fillrect = sh_mobile_lcdc_fillrect,
663 .fb_copyarea = sh_mobile_lcdc_copyarea,
664 .fb_imageblit = sh_mobile_lcdc_imageblit,
667 static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
670 case 16: /* PKF[4:0] = 00011 - RGB 565 */
671 var->red.offset = 11;
673 var->green.offset = 5;
674 var->green.length = 6;
675 var->blue.offset = 0;
676 var->blue.length = 5;
677 var->transp.offset = 0;
678 var->transp.length = 0;
681 case 32: /* PKF[4:0] = 00000 - RGB 888
682 * sh7722 pdf says 00RRGGBB but reality is GGBB00RR
683 * this may be because LDDDSR has word swap enabled..
687 var->green.offset = 24;
688 var->green.length = 8;
689 var->blue.offset = 16;
690 var->blue.length = 8;
691 var->transp.offset = 0;
692 var->transp.length = 0;
697 var->bits_per_pixel = bpp;
698 var->red.msb_right = 0;
699 var->green.msb_right = 0;
700 var->blue.msb_right = 0;
701 var->transp.msb_right = 0;
705 static int sh_mobile_lcdc_suspend(struct device *dev)
707 struct platform_device *pdev = to_platform_device(dev);
709 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
713 static int sh_mobile_lcdc_resume(struct device *dev)
715 struct platform_device *pdev = to_platform_device(dev);
717 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
720 static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
721 .suspend = sh_mobile_lcdc_suspend,
722 .resume = sh_mobile_lcdc_resume,
725 static int sh_mobile_lcdc_remove(struct platform_device *pdev);
727 static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
729 struct fb_info *info;
730 struct sh_mobile_lcdc_priv *priv;
731 struct sh_mobile_lcdc_info *pdata;
732 struct sh_mobile_lcdc_chan_cfg *cfg;
733 struct resource *res;
738 if (!pdev->dev.platform_data) {
739 dev_err(&pdev->dev, "no platform data defined\n");
744 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
745 i = platform_get_irq(pdev, 0);
747 dev_err(&pdev->dev, "cannot get platform resources\n");
752 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
754 dev_err(&pdev->dev, "cannot allocate device data\n");
759 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
760 dev_name(&pdev->dev), priv);
762 dev_err(&pdev->dev, "unable to request irq\n");
767 platform_set_drvdata(pdev, priv);
768 pdata = pdev->dev.platform_data;
771 for (i = 0; i < ARRAY_SIZE(pdata->ch); i++) {
772 priv->ch[j].lcdc = priv;
773 memcpy(&priv->ch[j].cfg, &pdata->ch[i], sizeof(pdata->ch[i]));
775 error = sh_mobile_lcdc_check_interface(&priv->ch[i]);
777 dev_err(&pdev->dev, "unsupported interface type\n");
780 init_waitqueue_head(&priv->ch[i].frame_end_wait);
782 switch (pdata->ch[i].chan) {
783 case LCDC_CHAN_MAINLCD:
784 priv->ch[j].enabled = 1 << 1;
785 priv->ch[j].reg_offs = lcdc_offs_mainlcd;
788 case LCDC_CHAN_SUBLCD:
789 priv->ch[j].enabled = 1 << 2;
790 priv->ch[j].reg_offs = lcdc_offs_sublcd;
797 dev_err(&pdev->dev, "no channels defined\n");
802 error = sh_mobile_lcdc_setup_clocks(pdev, pdata->clock_source, priv);
804 dev_err(&pdev->dev, "unable to setup clocks\n");
808 priv->base = ioremap_nocache(res->start, (res->end - res->start) + 1);
810 for (i = 0; i < j; i++) {
811 cfg = &priv->ch[i].cfg;
813 priv->ch[i].info = framebuffer_alloc(0, &pdev->dev);
814 if (!priv->ch[i].info) {
815 dev_err(&pdev->dev, "unable to allocate fb_info\n");
820 info = priv->ch[i].info;
821 info->fbops = &sh_mobile_lcdc_ops;
822 info->var.xres = info->var.xres_virtual = cfg->lcd_cfg.xres;
823 info->var.yres = info->var.yres_virtual = cfg->lcd_cfg.yres;
824 info->var.width = cfg->lcd_size_cfg.width;
825 info->var.height = cfg->lcd_size_cfg.height;
826 info->var.activate = FB_ACTIVATE_NOW;
827 error = sh_mobile_lcdc_set_bpp(&info->var, cfg->bpp);
831 info->fix = sh_mobile_lcdc_fix;
832 info->fix.line_length = cfg->lcd_cfg.xres * (cfg->bpp / 8);
833 info->fix.smem_len = info->fix.line_length * cfg->lcd_cfg.yres;
835 buf = dma_alloc_coherent(&pdev->dev, info->fix.smem_len,
836 &priv->ch[i].dma_handle, GFP_KERNEL);
838 dev_err(&pdev->dev, "unable to allocate buffer\n");
843 info->pseudo_palette = &priv->ch[i].pseudo_palette;
844 info->flags = FBINFO_FLAG_DEFAULT;
846 error = fb_alloc_cmap(&info->cmap, PALETTE_NR, 0);
848 dev_err(&pdev->dev, "unable to allocate cmap\n");
849 dma_free_coherent(&pdev->dev, info->fix.smem_len,
850 buf, priv->ch[i].dma_handle);
854 memset(buf, 0, info->fix.smem_len);
855 info->fix.smem_start = priv->ch[i].dma_handle;
856 info->screen_base = buf;
857 info->device = &pdev->dev;
858 info->par = &priv->ch[i];
864 error = sh_mobile_lcdc_start(priv);
866 dev_err(&pdev->dev, "unable to start hardware\n");
870 for (i = 0; i < j; i++) {
871 struct sh_mobile_lcdc_chan *ch = priv->ch + i;
876 priv->ch->sglist = vmalloc(sizeof(struct scatterlist) *
877 info->fix.smem_len >> PAGE_SHIFT);
878 if (!priv->ch->sglist) {
879 dev_err(&pdev->dev, "cannot allocate sglist\n");
884 error = register_framebuffer(info);
889 "registered %s/%s as %dx%d %dbpp.\n",
891 (ch->cfg.chan == LCDC_CHAN_MAINLCD) ?
892 "mainlcd" : "sublcd",
893 (int) ch->cfg.lcd_cfg.xres,
894 (int) ch->cfg.lcd_cfg.yres,
897 /* deferred io mode: disable clock to save power */
899 sh_mobile_lcdc_clk_off(priv);
904 sh_mobile_lcdc_remove(pdev);
909 static int sh_mobile_lcdc_remove(struct platform_device *pdev)
911 struct sh_mobile_lcdc_priv *priv = platform_get_drvdata(pdev);
912 struct fb_info *info;
915 for (i = 0; i < ARRAY_SIZE(priv->ch); i++)
916 if (priv->ch[i].info->dev)
917 unregister_framebuffer(priv->ch[i].info);
919 sh_mobile_lcdc_stop(priv);
921 for (i = 0; i < ARRAY_SIZE(priv->ch); i++) {
922 info = priv->ch[i].info;
924 if (!info || !info->device)
927 if (priv->ch[i].sglist)
928 vfree(priv->ch[i].sglist);
930 dma_free_coherent(&pdev->dev, info->fix.smem_len,
931 info->screen_base, priv->ch[i].dma_handle);
932 fb_dealloc_cmap(&info->cmap);
933 framebuffer_release(info);
937 clk_put(priv->dot_clk);
944 free_irq(priv->irq, priv);
949 static struct platform_driver sh_mobile_lcdc_driver = {
951 .name = "sh_mobile_lcdc_fb",
952 .owner = THIS_MODULE,
953 .pm = &sh_mobile_lcdc_dev_pm_ops,
955 .probe = sh_mobile_lcdc_probe,
956 .remove = sh_mobile_lcdc_remove,
959 static int __init sh_mobile_lcdc_init(void)
961 return platform_driver_register(&sh_mobile_lcdc_driver);
964 static void __exit sh_mobile_lcdc_exit(void)
966 platform_driver_unregister(&sh_mobile_lcdc_driver);
969 module_init(sh_mobile_lcdc_init);
970 module_exit(sh_mobile_lcdc_exit);
972 MODULE_DESCRIPTION("SuperH Mobile LCDC Framebuffer driver");
973 MODULE_AUTHOR("Magnus Damm <damm@opensource.se>");
974 MODULE_LICENSE("GPL v2");