blob: 14942526f19db7955ed4b2c40986690e43bbe2cf [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stephen Warren6be3c9f2013-01-29 16:37:40 +00002/*
3 * (C) Copyright 2012 Stephen Warren
Stephen Warren6be3c9f2013-01-29 16:37:40 +00004 */
5
6#include <common.h>
Simon Glassea843b62017-04-05 16:23:44 -06007#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Simon Glassea843b62017-04-05 16:23:44 -06009#include <video.h>
Stephen Warren6be3c9f2013-01-29 16:37:40 +000010#include <asm/arch/mbox.h>
Simon Glass2e4170b2017-04-05 16:23:40 -060011#include <asm/arch/msg.h>
Simon Glass90526e92020-05-10 11:39:56 -060012#include <asm/cache.h>
Stephen Warren6be3c9f2013-01-29 16:37:40 +000013
Simon Glassea843b62017-04-05 16:23:44 -060014static int bcm2835_video_probe(struct udevice *dev)
Stephen Warren6be3c9f2013-01-29 16:37:40 +000015{
Simon Glass8a8d24b2020-12-03 16:55:23 -070016 struct video_uc_plat *plat = dev_get_uclass_plat(dev);
Simon Glassea843b62017-04-05 16:23:44 -060017 struct video_priv *uc_priv = dev_get_uclass_priv(dev);
Stephen Warren6be3c9f2013-01-29 16:37:40 +000018 int ret;
Simon Glassea843b62017-04-05 16:23:44 -060019 int w, h, pitch;
Simon Glass7cac2fc2017-04-05 16:23:41 -060020 ulong fb_base, fb_size, fb_start, fb_end;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000021
22 debug("bcm2835: Query resolution...\n");
Simon Glass2e4170b2017-04-05 16:23:40 -060023 ret = bcm2835_get_video_size(&w, &h);
Fabian Vogt970baf12019-07-11 16:56:24 +020024 if (ret || w == 0 || h == 0)
Simon Glassea843b62017-04-05 16:23:44 -060025 return -EIO;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000026
Stephen Warren6be3c9f2013-01-29 16:37:40 +000027 debug("bcm2835: Setting up display for %d x %d\n", w, h);
Simon Glass7cac2fc2017-04-05 16:23:41 -060028 ret = bcm2835_set_video_params(&w, &h, 32, BCM2835_MBOX_PIXEL_ORDER_RGB,
29 BCM2835_MBOX_ALPHA_MODE_IGNORED,
Simon Glassea843b62017-04-05 16:23:44 -060030 &fb_base, &fb_size, &pitch);
Fabian Vogt970baf12019-07-11 16:56:24 +020031 if (ret)
32 return -EIO;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000033
34 debug("bcm2835: Final resolution is %d x %d\n", w, h);
35
Alexander Graf99de2542016-03-24 10:31:11 +010036 /* Enable dcache for the frame buffer */
Simon Glass7cac2fc2017-04-05 16:23:41 -060037 fb_start = fb_base & ~(MMU_SECTION_SIZE - 1);
38 fb_end = fb_base + fb_size;
Alexander Graf99de2542016-03-24 10:31:11 +010039 fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
40 mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
Simon Glass7cac2fc2017-04-05 16:23:41 -060041 DCACHE_WRITEBACK);
Simon Glassea843b62017-04-05 16:23:44 -060042 video_set_flush_dcache(dev, true);
43
44 uc_priv->xsize = w;
45 uc_priv->ysize = h;
46 uc_priv->bpix = VIDEO_BPP32;
47 plat->base = fb_base;
48 plat->size = fb_size;
49
50 return 0;
Stephen Warren6be3c9f2013-01-29 16:37:40 +000051}
52
Simon Glassea843b62017-04-05 16:23:44 -060053static const struct udevice_id bcm2835_video_ids[] = {
54 { .compatible = "brcm,bcm2835-hdmi" },
Nicolas Saenz Julienne0059ef02021-01-12 13:55:31 +010055 { .compatible = "brcm,bcm2711-hdmi0" },
Emmanuel Vadot425daac2018-07-02 14:33:14 +020056 { .compatible = "brcm,bcm2708-fb" },
Jason Wessel28cd2442023-07-26 10:42:34 +080057#if !IS_ENABLED(CONFIG_VIDEO_DT_SIMPLEFB)
58 { .compatible = "simple-framebuffer" },
59#endif
Simon Glassea843b62017-04-05 16:23:44 -060060 { }
61};
Andre Heider44376ef2013-11-09 11:07:53 +010062
Simon Glassea843b62017-04-05 16:23:44 -060063U_BOOT_DRIVER(bcm2835_video) = {
64 .name = "bcm2835_video",
65 .id = UCLASS_VIDEO,
66 .of_match = bcm2835_video_ids,
67 .probe = bcm2835_video_probe,
68};