blob: 0c81e6066229049c8185d71bf8a3ca5e0364835a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stephen Warren4ecd4982013-01-29 16:37:40 +00002/*
3 * (C) Copyright 2012 Stephen Warren
Stephen Warren4ecd4982013-01-29 16:37:40 +00004 */
5
Simon Glass39254d02017-04-05 16:23:44 -06006#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Simon Glass39254d02017-04-05 16:23:44 -06008#include <video.h>
Stephen Warren4ecd4982013-01-29 16:37:40 +00009#include <asm/arch/mbox.h>
Simon Glass31efc382017-04-05 16:23:40 -060010#include <asm/arch/msg.h>
Simon Glass274e0b02020-05-10 11:39:56 -060011#include <asm/cache.h>
Stephen Warren4ecd4982013-01-29 16:37:40 +000012
Simon Glass39254d02017-04-05 16:23:44 -060013static int bcm2835_video_probe(struct udevice *dev)
Stephen Warren4ecd4982013-01-29 16:37:40 +000014{
Simon Glassb75b15b2020-12-03 16:55:23 -070015 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glass39254d02017-04-05 16:23:44 -060016 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Stephen Warren4ecd4982013-01-29 16:37:40 +000017 int ret;
Ivan T. Ivanov408e3b62024-01-23 10:07:56 +020018 int w, h, pitch, bpp;
Simon Glass929df012017-04-05 16:23:41 -060019 ulong fb_base, fb_size, fb_start, fb_end;
Stephen Warren4ecd4982013-01-29 16:37:40 +000020
21 debug("bcm2835: Query resolution...\n");
Simon Glass31efc382017-04-05 16:23:40 -060022 ret = bcm2835_get_video_size(&w, &h);
Fabian Vogt26d33e52019-07-11 16:56:24 +020023 if (ret || w == 0 || h == 0)
Simon Glass39254d02017-04-05 16:23:44 -060024 return -EIO;
Stephen Warren4ecd4982013-01-29 16:37:40 +000025
Stephen Warren4ecd4982013-01-29 16:37:40 +000026 debug("bcm2835: Setting up display for %d x %d\n", w, h);
Simon Glass929df012017-04-05 16:23:41 -060027 ret = bcm2835_set_video_params(&w, &h, 32, BCM2835_MBOX_PIXEL_ORDER_RGB,
28 BCM2835_MBOX_ALPHA_MODE_IGNORED,
Simon Glass39254d02017-04-05 16:23:44 -060029 &fb_base, &fb_size, &pitch);
Fabian Vogt26d33e52019-07-11 16:56:24 +020030 if (ret)
31 return -EIO;
Stephen Warren4ecd4982013-01-29 16:37:40 +000032
33 debug("bcm2835: Final resolution is %d x %d\n", w, h);
34
Alexander Graf2e1075c2016-03-24 10:31:11 +010035 /* Enable dcache for the frame buffer */
Simon Glass929df012017-04-05 16:23:41 -060036 fb_start = fb_base & ~(MMU_SECTION_SIZE - 1);
37 fb_end = fb_base + fb_size;
Alexander Graf2e1075c2016-03-24 10:31:11 +010038 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
39 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
Simon Glass929df012017-04-05 16:23:41 -060040 DCACHE_WRITEBACK);
Simon Glass39254d02017-04-05 16:23:44 -060041 video_set_flush_dcache(dev, true);
Stephen Warren4ecd4982013-01-29 16:37:40 +000042
Ivan T. Ivanov408e3b62024-01-23 10:07:56 +020043 bpp = pitch / w;
44 switch (bpp) {
45 case 2:
46 uc_priv->bpix = VIDEO_BPP16;
47 break;
48 case 4:
49 uc_priv->bpix = VIDEO_BPP32;
50 break;
51 default:
52 printf("bcm2835: unexpected bpp %d, pitch %d, width %d\n",
53 bpp, pitch, w);
54 uc_priv->bpix = VIDEO_BPP32;
55 break;
56 }
57
Simon Glass39254d02017-04-05 16:23:44 -060058 uc_priv->xsize = w;
59 uc_priv->ysize = h;
Simon Glass39254d02017-04-05 16:23:44 -060060 plat->base = fb_base;
61 plat->size = fb_size;
62
63 return 0;
Andre Heider191211c2013-11-09 11:07:53 +010064}
65
Simon Glass39254d02017-04-05 16:23:44 -060066static const struct udevice_id bcm2835_video_ids[] = {
67 { .compatible = "brcm,bcm2835-hdmi" },
Nicolas Saenz Julienne67a41882021-01-12 13:55:31 +010068 { .compatible = "brcm,bcm2711-hdmi0" },
Emmanuel Vadote2705192018-07-02 14:33:14 +020069 { .compatible = "brcm,bcm2708-fb" },
Jason Wessel50d0ce92023-07-26 10:42:34 +080070#if !IS_ENABLED(CONFIG_VIDEO_DT_SIMPLEFB)
71 { .compatible = "simple-framebuffer" },
72#endif
Simon Glass39254d02017-04-05 16:23:44 -060073 { }
74};
Simon Glass929df012017-04-05 16:23:41 -060075
Simon Glass39254d02017-04-05 16:23:44 -060076U_BOOT_DRIVER(bcm2835_video) = {
77 .name = "bcm2835_video",
78 .id = UCLASS_VIDEO,
79 .of_match = bcm2835_video_ids,
80 .probe = bcm2835_video_probe,
81};