Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Stephen Warren |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 6 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 8 | #include <video.h> |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 9 | #include <asm/arch/mbox.h> |
Simon Glass | 31efc38 | 2017-04-05 16:23:40 -0600 | [diff] [blame] | 10 | #include <asm/arch/msg.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 11 | #include <asm/cache.h> |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 12 | |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 13 | static int bcm2835_video_probe(struct udevice *dev) |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 14 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 15 | struct video_uc_plat *plat = dev_get_uclass_plat(dev); |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 16 | struct video_priv *uc_priv = dev_get_uclass_priv(dev); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 17 | int ret; |
Ivan T. Ivanov | 408e3b6 | 2024-01-23 10:07:56 +0200 | [diff] [blame] | 18 | int w, h, pitch, bpp; |
Simon Glass | 929df01 | 2017-04-05 16:23:41 -0600 | [diff] [blame] | 19 | ulong fb_base, fb_size, fb_start, fb_end; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 20 | |
| 21 | debug("bcm2835: Query resolution...\n"); |
Simon Glass | 31efc38 | 2017-04-05 16:23:40 -0600 | [diff] [blame] | 22 | ret = bcm2835_get_video_size(&w, &h); |
Fabian Vogt | 26d33e5 | 2019-07-11 16:56:24 +0200 | [diff] [blame] | 23 | if (ret || w == 0 || h == 0) |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 24 | return -EIO; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 25 | |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 26 | debug("bcm2835: Setting up display for %d x %d\n", w, h); |
Simon Glass | 929df01 | 2017-04-05 16:23:41 -0600 | [diff] [blame] | 27 | ret = bcm2835_set_video_params(&w, &h, 32, BCM2835_MBOX_PIXEL_ORDER_RGB, |
| 28 | BCM2835_MBOX_ALPHA_MODE_IGNORED, |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 29 | &fb_base, &fb_size, &pitch); |
Fabian Vogt | 26d33e5 | 2019-07-11 16:56:24 +0200 | [diff] [blame] | 30 | if (ret) |
| 31 | return -EIO; |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 32 | |
| 33 | debug("bcm2835: Final resolution is %d x %d\n", w, h); |
| 34 | |
Alexander Graf | 2e1075c | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 35 | /* Enable dcache for the frame buffer */ |
Simon Glass | 929df01 | 2017-04-05 16:23:41 -0600 | [diff] [blame] | 36 | fb_start = fb_base & ~(MMU_SECTION_SIZE - 1); |
| 37 | fb_end = fb_base + fb_size; |
Alexander Graf | 2e1075c | 2016-03-24 10:31:11 +0100 | [diff] [blame] | 38 | fb_end = ALIGN(fb_end, 1 << MMU_SECTION_SHIFT); |
| 39 | mmu_set_region_dcache_behaviour(fb_start, fb_end - fb_start, |
Simon Glass | 929df01 | 2017-04-05 16:23:41 -0600 | [diff] [blame] | 40 | DCACHE_WRITEBACK); |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 41 | video_set_flush_dcache(dev, true); |
Stephen Warren | 4ecd498 | 2013-01-29 16:37:40 +0000 | [diff] [blame] | 42 | |
Ivan T. Ivanov | 408e3b6 | 2024-01-23 10:07:56 +0200 | [diff] [blame] | 43 | 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 Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 58 | uc_priv->xsize = w; |
| 59 | uc_priv->ysize = h; |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 60 | plat->base = fb_base; |
| 61 | plat->size = fb_size; |
| 62 | |
| 63 | return 0; |
Andre Heider | 191211c | 2013-11-09 11:07:53 +0100 | [diff] [blame] | 64 | } |
| 65 | |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 66 | static const struct udevice_id bcm2835_video_ids[] = { |
| 67 | { .compatible = "brcm,bcm2835-hdmi" }, |
Nicolas Saenz Julienne | 67a4188 | 2021-01-12 13:55:31 +0100 | [diff] [blame] | 68 | { .compatible = "brcm,bcm2711-hdmi0" }, |
Emmanuel Vadot | e270519 | 2018-07-02 14:33:14 +0200 | [diff] [blame] | 69 | { .compatible = "brcm,bcm2708-fb" }, |
Jason Wessel | 50d0ce9 | 2023-07-26 10:42:34 +0800 | [diff] [blame] | 70 | #if !IS_ENABLED(CONFIG_VIDEO_DT_SIMPLEFB) |
| 71 | { .compatible = "simple-framebuffer" }, |
| 72 | #endif |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 73 | { } |
| 74 | }; |
Simon Glass | 929df01 | 2017-04-05 16:23:41 -0600 | [diff] [blame] | 75 | |
Simon Glass | 39254d0 | 2017-04-05 16:23:44 -0600 | [diff] [blame] | 76 | U_BOOT_DRIVER(bcm2835_video) = { |
| 77 | .name = "bcm2835_video", |
| 78 | .id = UCLASS_VIDEO, |
| 79 | .of_match = bcm2835_video_ids, |
| 80 | .probe = bcm2835_video_probe, |
| 81 | }; |