Lines Matching +full:imx21 +full:- +full:fb
1 // SPDX-License-Identifier: GPL-2.0-only
11 * linux-arm-kernel@lists.arm.linux.org.uk
21 #include <linux/fb.h>
28 #include <linux/dma-mapping.h>
54 #define DRIVER_NAME "imx-fb"
134 /* Used fb-mode. Can be set on kernel command line, therefore file-static. */
198 .name = "imx1-fb",
201 .name = "imx21-fb",
211 .compatible = "fsl,imx1-fb",
214 .compatible = "fsl,imx21-fb",
224 return fbi->devtype == IMX1_FB; in is_imx1_fb()
273 chan >>= 16 - bf->length; in chan_to_field()
274 return chan << bf->offset; in chan_to_field()
280 struct imxfb_info *fbi = info->par; in imxfb_setpalettereg()
283 #define CNVT_TOHW(val, width) ((((val)<<(width))+0x7FFF-(val))>>16) in imxfb_setpalettereg()
284 if (regno < fbi->palette_size) { in imxfb_setpalettereg()
289 writel(val, fbi->regs + 0x800 + (regno << 2)); in imxfb_setpalettereg()
298 struct imxfb_info *fbi = info->par; in imxfb_setcolreg()
308 if (fbi->cmap_inverse) { in imxfb_setcolreg()
309 red = 0xffff - red; in imxfb_setcolreg()
310 green = 0xffff - green; in imxfb_setcolreg()
311 blue = 0xffff - blue; in imxfb_setcolreg()
318 if (info->var.grayscale) in imxfb_setcolreg()
322 switch (info->fix.visual) { in imxfb_setcolreg()
325 * 12 or 16-bit True Colour. We encode the RGB value in imxfb_setcolreg()
329 u32 *pal = info->pseudo_palette; in imxfb_setcolreg()
331 val = chan_to_field(red, &info->var.red); in imxfb_setcolreg()
332 val |= chan_to_field(green, &info->var.green); in imxfb_setcolreg()
333 val |= chan_to_field(blue, &info->var.blue); in imxfb_setcolreg()
355 return &fbi->mode[0]; in imxfb_find_mode()
357 for (i = 0, m = &fbi->mode[0]; i < fbi->num_modes; i++, m++) { in imxfb_find_mode()
358 if (!strcmp(m->mode.name, fb_mode)) in imxfb_find_mode()
372 struct imxfb_info *fbi = info->par; in imxfb_check_var()
379 if (var->xres < MIN_XRES) in imxfb_check_var()
380 var->xres = MIN_XRES; in imxfb_check_var()
381 if (var->yres < MIN_YRES) in imxfb_check_var()
382 var->yres = MIN_YRES; in imxfb_check_var()
386 return -EINVAL; in imxfb_check_var()
388 var->xres = imxfb_mode->mode.xres; in imxfb_check_var()
389 var->yres = imxfb_mode->mode.yres; in imxfb_check_var()
390 var->bits_per_pixel = imxfb_mode->bpp; in imxfb_check_var()
391 var->pixclock = imxfb_mode->mode.pixclock; in imxfb_check_var()
392 var->hsync_len = imxfb_mode->mode.hsync_len; in imxfb_check_var()
393 var->left_margin = imxfb_mode->mode.left_margin; in imxfb_check_var()
394 var->right_margin = imxfb_mode->mode.right_margin; in imxfb_check_var()
395 var->vsync_len = imxfb_mode->mode.vsync_len; in imxfb_check_var()
396 var->upper_margin = imxfb_mode->mode.upper_margin; in imxfb_check_var()
397 var->lower_margin = imxfb_mode->mode.lower_margin; in imxfb_check_var()
398 var->sync = imxfb_mode->mode.sync; in imxfb_check_var()
399 var->xres_virtual = max(var->xres_virtual, var->xres); in imxfb_check_var()
400 var->yres_virtual = max(var->yres_virtual, var->yres); in imxfb_check_var()
402 pr_debug("var->bits_per_pixel=%d\n", var->bits_per_pixel); in imxfb_check_var()
404 lcd_clk = clk_get_rate(fbi->clk_per); in imxfb_check_var()
406 tmp = var->pixclock * (unsigned long long)lcd_clk; in imxfb_check_var()
415 if (--pcr > PCR_PCD_MASK) { in imxfb_check_var()
417 dev_warn(&fbi->pdev->dev, "Must limit pixel clock to %luHz\n", in imxfb_check_var()
421 switch (var->bits_per_pixel) { in imxfb_check_var()
433 if (imxfb_mode->pcr & PCR_TFT) in imxfb_check_var()
445 pcr |= imxfb_mode->pcr & ~(PCR_PCD_MASK | PCR_BPIX_MASK); in imxfb_check_var()
447 fbi->pcr = pcr; in imxfb_check_var()
451 if (!is_imx1_fb(fbi) && imxfb_mode->aus_mode) in imxfb_check_var()
452 fbi->lauscr = LAUSCR_AUS_MODE; in imxfb_check_var()
454 if (imxfb_mode->pcr & PCR_TFT) in imxfb_check_var()
455 fbi->panel_type = PANEL_TYPE_TFT; in imxfb_check_var()
456 else if (imxfb_mode->pcr & PCR_COLOR) in imxfb_check_var()
457 fbi->panel_type = PANEL_TYPE_CSTN; in imxfb_check_var()
459 fbi->panel_type = PANEL_TYPE_MONOCHROME; in imxfb_check_var()
465 var->red = rgb->red; in imxfb_check_var()
466 var->green = rgb->green; in imxfb_check_var()
467 var->blue = rgb->blue; in imxfb_check_var()
468 var->transp = rgb->transp; in imxfb_check_var()
471 var->red.length, var->green.length, var->blue.length, in imxfb_check_var()
472 var->transp.length); in imxfb_check_var()
475 var->red.offset, var->green.offset, var->blue.offset, in imxfb_check_var()
476 var->transp.offset); in imxfb_check_var()
487 struct imxfb_info *fbi = info->par; in imxfb_set_par()
488 struct fb_var_screeninfo *var = &info->var; in imxfb_set_par()
490 if (var->bits_per_pixel == 16 || var->bits_per_pixel == 32) in imxfb_set_par()
491 info->fix.visual = FB_VISUAL_TRUECOLOR; in imxfb_set_par()
492 else if (!fbi->cmap_static) in imxfb_set_par()
493 info->fix.visual = FB_VISUAL_PSEUDOCOLOR; in imxfb_set_par()
500 info->fix.visual = FB_VISUAL_STATIC_PSEUDOCOLOR; in imxfb_set_par()
503 info->fix.line_length = var->xres_virtual * var->bits_per_pixel / 8; in imxfb_set_par()
504 fbi->palette_size = var->bits_per_pixel == 8 ? 256 : 16; in imxfb_set_par()
515 if (fbi->enabled) in imxfb_enable_controller()
520 writel(fbi->map_dma, fbi->regs + LCDC_SSA); in imxfb_enable_controller()
523 writel(FIELD_PREP(POS_POS_MASK, 0), fbi->regs + LCDC_POS); in imxfb_enable_controller()
526 writel(readl(fbi->regs + LCDC_CPOS) & ~(CPOS_CC0 | CPOS_CC1), in imxfb_enable_controller()
527 fbi->regs + LCDC_CPOS); in imxfb_enable_controller()
533 writel(RMCR_LCDC_EN_MX1, fbi->regs + LCDC_RMCR); in imxfb_enable_controller()
535 ret = clk_prepare_enable(fbi->clk_ipg); in imxfb_enable_controller()
539 ret = clk_prepare_enable(fbi->clk_ahb); in imxfb_enable_controller()
543 ret = clk_prepare_enable(fbi->clk_per); in imxfb_enable_controller()
547 fbi->enabled = true; in imxfb_enable_controller()
551 clk_disable_unprepare(fbi->clk_ahb); in imxfb_enable_controller()
553 clk_disable_unprepare(fbi->clk_ipg); in imxfb_enable_controller()
555 writel(0, fbi->regs + LCDC_RMCR); in imxfb_enable_controller()
562 if (!fbi->enabled) in imxfb_disable_controller()
567 clk_disable_unprepare(fbi->clk_per); in imxfb_disable_controller()
568 clk_disable_unprepare(fbi->clk_ahb); in imxfb_disable_controller()
569 clk_disable_unprepare(fbi->clk_ipg); in imxfb_disable_controller()
570 fbi->enabled = false; in imxfb_disable_controller()
572 writel(0, fbi->regs + LCDC_RMCR); in imxfb_disable_controller()
577 struct imxfb_info *fbi = info->par; in imxfb_blank()
611 struct imxfb_info *fbi = info->par; in imxfb_activate_var()
616 var->xres, var->hsync_len, in imxfb_activate_var()
617 var->left_margin, var->right_margin); in imxfb_activate_var()
619 var->yres, var->vsync_len, in imxfb_activate_var()
620 var->upper_margin, var->lower_margin); in imxfb_activate_var()
622 if (fbi->panel_type == PANEL_TYPE_TFT) in imxfb_activate_var()
624 else if (fbi->panel_type == PANEL_TYPE_CSTN) in imxfb_activate_var()
630 if (var->xres < 16 || var->xres > 1024) in imxfb_activate_var()
631 dev_err(&fbi->pdev->dev, "%s: invalid xres %d\n", in imxfb_activate_var()
632 info->fix.id, var->xres); in imxfb_activate_var()
633 if (var->hsync_len < 1 || var->hsync_len > 64) in imxfb_activate_var()
634 dev_err(&fbi->pdev->dev, "%s: invalid hsync_len %d\n", in imxfb_activate_var()
635 info->fix.id, var->hsync_len); in imxfb_activate_var()
636 if (var->left_margin < left_margin_low || var->left_margin > 255) in imxfb_activate_var()
637 dev_err(&fbi->pdev->dev, "%s: invalid left_margin %d\n", in imxfb_activate_var()
638 info->fix.id, var->left_margin); in imxfb_activate_var()
639 if (var->right_margin < 1 || var->right_margin > 255) in imxfb_activate_var()
640 dev_err(&fbi->pdev->dev, "%s: invalid right_margin %d\n", in imxfb_activate_var()
641 info->fix.id, var->right_margin); in imxfb_activate_var()
642 if (var->yres < 1 || var->yres > ymax_mask) in imxfb_activate_var()
643 dev_err(&fbi->pdev->dev, "%s: invalid yres %d\n", in imxfb_activate_var()
644 info->fix.id, var->yres); in imxfb_activate_var()
645 if (var->vsync_len > 100) in imxfb_activate_var()
646 dev_err(&fbi->pdev->dev, "%s: invalid vsync_len %d\n", in imxfb_activate_var()
647 info->fix.id, var->vsync_len); in imxfb_activate_var()
648 if (var->upper_margin > 63) in imxfb_activate_var()
649 dev_err(&fbi->pdev->dev, "%s: invalid upper_margin %d\n", in imxfb_activate_var()
650 info->fix.id, var->upper_margin); in imxfb_activate_var()
651 if (var->lower_margin > 255) in imxfb_activate_var()
652 dev_err(&fbi->pdev->dev, "%s: invalid lower_margin %d\n", in imxfb_activate_var()
653 info->fix.id, var->lower_margin); in imxfb_activate_var()
658 var->xres * var->bits_per_pixel / 8 / 4), in imxfb_activate_var()
659 fbi->regs + LCDC_VPW); in imxfb_activate_var()
661 writel(FIELD_PREP(HCR_H_WIDTH_MASK, var->hsync_len - 1) | in imxfb_activate_var()
662 FIELD_PREP(HCR_H_WAIT_1_MASK, var->right_margin - 1) | in imxfb_activate_var()
664 var->left_margin - left_margin_low), in imxfb_activate_var()
665 fbi->regs + LCDC_HCR); in imxfb_activate_var()
667 writel(FIELD_PREP(VCR_V_WIDTH_MASK, var->vsync_len) | in imxfb_activate_var()
668 FIELD_PREP(VCR_V_WAIT_1_MASK, var->lower_margin) | in imxfb_activate_var()
669 FIELD_PREP(VCR_V_WAIT_2_MASK, var->upper_margin), in imxfb_activate_var()
670 fbi->regs + LCDC_VCR); in imxfb_activate_var()
672 writel(FIELD_PREP(SIZE_XMAX_MASK, var->xres >> 4) | in imxfb_activate_var()
673 (var->yres & ymax_mask), in imxfb_activate_var()
674 fbi->regs + LCDC_SIZE); in imxfb_activate_var()
676 writel(fbi->pcr, fbi->regs + LCDC_PCR); in imxfb_activate_var()
677 if (fbi->pwmr) in imxfb_activate_var()
678 writel(fbi->pwmr, fbi->regs + LCDC_PWMR); in imxfb_activate_var()
679 writel(fbi->lscr1, fbi->regs + LCDC_LSCR1); in imxfb_activate_var()
682 if (fbi->dmacr) in imxfb_activate_var()
683 writel(fbi->dmacr, fbi->regs + LCDC_DMACR); in imxfb_activate_var()
685 if (fbi->lauscr) in imxfb_activate_var()
686 writel(fbi->lauscr, fbi->regs + LCDC_LAUSCR); in imxfb_activate_var()
694 struct imxfb_info *fbi = info->par; in imxfb_init_fbinfo()
697 info->pseudo_palette = devm_kmalloc_array(&pdev->dev, 16, in imxfb_init_fbinfo()
699 if (!info->pseudo_palette) in imxfb_init_fbinfo()
700 return -ENOMEM; in imxfb_init_fbinfo()
704 fbi->pdev = pdev; in imxfb_init_fbinfo()
705 fbi->devtype = pdev->id_entry->driver_data; in imxfb_init_fbinfo()
707 strscpy(info->fix.id, IMX_NAME, sizeof(info->fix.id)); in imxfb_init_fbinfo()
709 info->fix.type = FB_TYPE_PACKED_PIXELS; in imxfb_init_fbinfo()
710 info->fix.type_aux = 0; in imxfb_init_fbinfo()
711 info->fix.xpanstep = 0; in imxfb_init_fbinfo()
712 info->fix.ypanstep = 0; in imxfb_init_fbinfo()
713 info->fix.ywrapstep = 0; in imxfb_init_fbinfo()
714 info->fix.accel = FB_ACCEL_NONE; in imxfb_init_fbinfo()
716 info->var.nonstd = 0; in imxfb_init_fbinfo()
717 info->var.activate = FB_ACTIVATE_NOW; in imxfb_init_fbinfo()
718 info->var.height = -1; in imxfb_init_fbinfo()
719 info->var.width = -1; in imxfb_init_fbinfo()
720 info->var.accel_flags = 0; in imxfb_init_fbinfo()
721 info->var.vmode = FB_VMODE_NONINTERLACED; in imxfb_init_fbinfo()
723 info->fbops = &imxfb_ops; in imxfb_init_fbinfo()
724 info->flags = FBINFO_READS_FAST; in imxfb_init_fbinfo()
726 np = pdev->dev.of_node; in imxfb_init_fbinfo()
727 info->var.grayscale = of_property_read_bool(np, in imxfb_init_fbinfo()
728 "cmap-greyscale"); in imxfb_init_fbinfo()
729 fbi->cmap_inverse = of_property_read_bool(np, "cmap-inverse"); in imxfb_init_fbinfo()
730 fbi->cmap_static = of_property_read_bool(np, "cmap-static"); in imxfb_init_fbinfo()
732 fbi->lscr1 = IMXFB_LSCR1_DEFAULT; in imxfb_init_fbinfo()
734 of_property_read_u32(np, "fsl,lpccr", &fbi->pwmr); in imxfb_init_fbinfo()
736 of_property_read_u32(np, "fsl,lscr1", &fbi->lscr1); in imxfb_init_fbinfo()
738 of_property_read_u32(np, "fsl,dmacr", &fbi->dmacr); in imxfb_init_fbinfo()
747 struct fb_videomode *of_mode = &imxfb_mode->mode; in imxfb_of_read_mode()
751 ret = of_property_read_string(np, "model", &of_mode->name); in imxfb_of_read_mode()
753 of_mode->name = NULL; in imxfb_of_read_mode()
761 ret = of_property_read_u32(np, "bits-per-pixel", &bpp); in imxfb_of_read_mode()
766 return -EINVAL; in imxfb_of_read_mode()
771 return -EINVAL; in imxfb_of_read_mode()
774 imxfb_mode->bpp = bpp; in imxfb_of_read_mode()
775 imxfb_mode->pcr = pcr; in imxfb_of_read_mode()
778 * fsl,aus-mode is optional in imxfb_of_read_mode()
780 imxfb_mode->aus_mode = of_property_read_bool(np, "fsl,aus-mode"); in imxfb_of_read_mode()
787 struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev); in imxfb_lcd_get_contrast()
789 return fbi->pwmr & 0xff; in imxfb_lcd_get_contrast()
794 struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev); in imxfb_lcd_set_contrast()
796 if (fbi->pwmr && fbi->enabled) { in imxfb_lcd_set_contrast()
802 fbi->pwmr &= ~0xff; in imxfb_lcd_set_contrast()
803 fbi->pwmr |= contrast; in imxfb_lcd_set_contrast()
805 writel(fbi->pwmr, fbi->regs + LCDC_PWMR); in imxfb_lcd_set_contrast()
813 struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev); in imxfb_lcd_get_power()
815 if (!IS_ERR(fbi->lcd_pwr) && in imxfb_lcd_get_power()
816 !regulator_is_enabled(fbi->lcd_pwr)) in imxfb_lcd_get_power()
826 if (enable == fbi->lcd_pwr_enabled) in imxfb_regulator_set()
830 ret = regulator_enable(fbi->lcd_pwr); in imxfb_regulator_set()
832 ret = regulator_disable(fbi->lcd_pwr); in imxfb_regulator_set()
835 fbi->lcd_pwr_enabled = enable; in imxfb_regulator_set()
842 struct imxfb_info *fbi = dev_get_drvdata(&lcddev->dev); in imxfb_lcd_set_power()
844 if (!IS_ERR(fbi->lcd_pwr)) in imxfb_lcd_set_power()
862 return -ENODEV; in imxfb_setup()
888 dev_info(&pdev->dev, "i.MX Framebuffer driver\n"); in imxfb_probe()
894 of_id = of_match_device(imxfb_of_dev_id, &pdev->dev); in imxfb_probe()
896 pdev->id_entry = of_id->data; in imxfb_probe()
898 info = framebuffer_alloc(sizeof(struct imxfb_info), &pdev->dev); in imxfb_probe()
900 return -ENOMEM; in imxfb_probe()
902 fbi = info->par; in imxfb_probe()
912 display_np = of_parse_phandle(pdev->dev.of_node, "display", 0); in imxfb_probe()
914 dev_err(&pdev->dev, "No display defined in devicetree\n"); in imxfb_probe()
915 ret = -EINVAL; in imxfb_probe()
923 fbi->num_modes = 1; in imxfb_probe()
925 fbi->mode = devm_kzalloc(&pdev->dev, in imxfb_probe()
927 if (!fbi->mode) { in imxfb_probe()
928 ret = -ENOMEM; in imxfb_probe()
933 ret = imxfb_of_read_mode(&pdev->dev, display_np, fbi->mode); in imxfb_probe()
940 * be the same as m->bpp/8 in imxfb_probe()
942 m = &fbi->mode[0]; in imxfb_probe()
943 bytes_per_pixel = (m->bpp + 7) / 8; in imxfb_probe()
944 for (i = 0; i < fbi->num_modes; i++, m++) in imxfb_probe()
945 info->fix.smem_len = max_t(size_t, info->fix.smem_len, in imxfb_probe()
946 m->mode.xres * m->mode.yres * bytes_per_pixel); in imxfb_probe()
948 fbi->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); in imxfb_probe()
949 if (IS_ERR(fbi->clk_ipg)) { in imxfb_probe()
950 ret = PTR_ERR(fbi->clk_ipg); in imxfb_probe()
964 ret = clk_prepare_enable(fbi->clk_ipg); in imxfb_probe()
967 clk_disable_unprepare(fbi->clk_ipg); in imxfb_probe()
969 fbi->clk_ahb = devm_clk_get(&pdev->dev, "ahb"); in imxfb_probe()
970 if (IS_ERR(fbi->clk_ahb)) { in imxfb_probe()
971 ret = PTR_ERR(fbi->clk_ahb); in imxfb_probe()
975 fbi->clk_per = devm_clk_get(&pdev->dev, "per"); in imxfb_probe()
976 if (IS_ERR(fbi->clk_per)) { in imxfb_probe()
977 ret = PTR_ERR(fbi->clk_per); in imxfb_probe()
981 fbi->regs = devm_platform_ioremap_resource(pdev, 0); in imxfb_probe()
982 if (IS_ERR(fbi->regs)) { in imxfb_probe()
983 ret = PTR_ERR(fbi->regs); in imxfb_probe()
987 fbi->map_size = PAGE_ALIGN(info->fix.smem_len); in imxfb_probe()
988 info->screen_buffer = dma_alloc_wc(&pdev->dev, fbi->map_size, in imxfb_probe()
989 &fbi->map_dma, GFP_KERNEL); in imxfb_probe()
990 if (!info->screen_buffer) { in imxfb_probe()
991 dev_err(&pdev->dev, "Failed to allocate video RAM\n"); in imxfb_probe()
992 ret = -ENOMEM; in imxfb_probe()
996 info->fix.smem_start = fbi->map_dma; in imxfb_probe()
998 INIT_LIST_HEAD(&info->modelist); in imxfb_probe()
999 for (i = 0; i < fbi->num_modes; i++) in imxfb_probe()
1000 fb_add_videomode(&fbi->mode[i].mode, &info->modelist); in imxfb_probe()
1006 imxfb_check_var(&info->var, info); in imxfb_probe()
1012 ret = fb_alloc_cmap(&info->cmap, 256, 0); in imxfb_probe()
1018 fbi->lcd_pwr = devm_regulator_get(&pdev->dev, "lcd"); in imxfb_probe()
1019 if (PTR_ERR(fbi->lcd_pwr) == -EPROBE_DEFER) { in imxfb_probe()
1020 ret = -EPROBE_DEFER; in imxfb_probe()
1024 lcd = devm_lcd_device_register(&pdev->dev, "imxfb-lcd", &pdev->dev, fbi, in imxfb_probe()
1031 lcd->props.max_contrast = 0xff; in imxfb_probe()
1033 info->lcd_dev = lcd; in imxfb_probe()
1037 dev_err(&pdev->dev, "failed to register framebuffer\n"); in imxfb_probe()
1046 fb_dealloc_cmap(&info->cmap); in imxfb_probe()
1048 dma_free_wc(&pdev->dev, fbi->map_size, info->screen_buffer, in imxfb_probe()
1049 fbi->map_dma); in imxfb_probe()
1058 struct imxfb_info *fbi = info->par; in imxfb_remove()
1063 fb_dealloc_cmap(&info->cmap); in imxfb_remove()
1064 dma_free_wc(&pdev->dev, fbi->map_size, info->screen_buffer, in imxfb_remove()
1065 fbi->map_dma); in imxfb_remove()
1072 struct imxfb_info *fbi = info->par; in imxfb_suspend()
1082 struct imxfb_info *fbi = info->par; in imxfb_resume()