1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2012 Stephen Warren
4  */
5 
6 #include <common.h>
7 #include <dm.h>
8 #include <log.h>
9 #include <video.h>
10 #include <asm/arch/mbox.h>
11 #include <asm/arch/msg.h>
12 #include <asm/cache.h>
13 
bcm2835_video_probe(struct udevice * dev)14 static int bcm2835_video_probe(struct udevice *dev)
15 {
16 	struct video_uc_plat *plat = dev_get_uclass_plat(dev);
17 	struct video_priv *uc_priv = dev_get_uclass_priv(dev);
18 	int ret;
19 	int w, h, pitch;
20 	ulong fb_base, fb_size, fb_start, fb_end;
21 
22 	debug("bcm2835: Query resolution...\n");
23 	ret = bcm2835_get_video_size(&w, &h);
24 	if (ret || w == 0 || h == 0)
25 		return -EIO;
26 
27 	debug("bcm2835: Setting up display for %d x %d\n", w, h);
28 	ret = bcm2835_set_video_params(&w, &h, 32, BCM2835_MBOX_PIXEL_ORDER_RGB,
29 				       BCM2835_MBOX_ALPHA_MODE_IGNORED,
30 				       &fb_base, &fb_size, &pitch);
31 	if (ret)
32 		return -EIO;
33 
34 	debug("bcm2835: Final resolution is %d x %d\n", w, h);
35 
36 	/* Enable dcache for the frame buffer */
37 	fb_start = fb_base & ~(MMU_SECTION_SIZE - 1);
38 	fb_end = fb_base + fb_size;
39 	fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT);
40 	mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start,
41 					DCACHE_WRITEBACK);
42 	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;
51 }
52 
53 static const struct udevice_id bcm2835_video_ids[] = {
54 	{ .compatible = "brcm,bcm2835-hdmi" },
55 	{ .compatible = "brcm,bcm2711-hdmi0" },
56 	{ .compatible = "brcm,bcm2708-fb" },
57 	{ }
58 };
59 
60 U_BOOT_DRIVER(bcm2835_video) = {
61 	.name	= "bcm2835_video",
62 	.id	= UCLASS_VIDEO,
63 	.of_match = bcm2835_video_ids,
64 	.probe	= bcm2835_video_probe,
65 };
66