blob: c8a1d841749ae703dc8b9677aa1e8ec6f0828f0b [file] [log] [blame]
Jeremy Compostella47f154c2022-12-01 15:55:06 -07001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
3#include <device/pci.h>
4#include <drivers/intel/gma/libgfxinit.h>
5#include <intelblocks/early_graphics.h>
Tarun Tuli33c66652023-05-04 12:41:13 +00006#include <soc/gpio.h>
Jeremy Compostella47f154c2022-12-01 15:55:06 -07007#include <soc/pci_devs.h>
8
Jeremy Compostella47f154c2022-12-01 15:55:06 -07009static void device_init(void)
10{
11 /* Disable response in IO and MMIO space. */
12 pci_and_config16(SA_DEV_IGD, PCI_COMMAND,
13 ~(PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
14
15 /* Program IGD Base Address Register 0. */
16 pci_write_config32(SA_DEV_IGD, PCI_BASE_ADDRESS_0,
17 CONFIG_GFX_GMA_DEFAULT_MMIO);
18
19 /* Enable response in IO and MMIO space. */
20 pci_or_config16(SA_DEV_IGD, PCI_COMMAND,
21 (PCI_COMMAND_IO | PCI_COMMAND_MEMORY));
22}
23
Tarun Tuli33c66652023-05-04 12:41:13 +000024__weak const struct pad_config *variant_early_graphics_gpio_table(size_t *num)
25{
26 *num = 0;
27 return NULL;
28}
29
Jeremy Compostella47f154c2022-12-01 15:55:06 -070030bool early_graphics_init(void)
31{
32 int ret;
Tarun Tuli33c66652023-05-04 12:41:13 +000033 const struct pad_config *pads;
34 size_t pads_num;
Jeremy Compostella47f154c2022-12-01 15:55:06 -070035
36 if (!CONFIG(MAINBOARD_USE_EARLY_LIBGFXINIT))
37 return false;
38
39 /* Perform minimal graphic MMIO configuration. */
40 device_init();
41
Tarun Tuli33c66652023-05-04 12:41:13 +000042 /* Optionally configure any required display related GPIOs */
43 pads = variant_early_graphics_gpio_table(&pads_num);
44 gpio_configure_pads(pads, pads_num);
45
Jeremy Compostella47f154c2022-12-01 15:55:06 -070046 /* Configure display panel. */
47 early_graphics_soc_panel_init();
48
49 gma_gfxinit(&ret);
Jeremy Compostellab628bec2023-01-19 18:58:30 -070050 return !!ret;
Jeremy Compostella47f154c2022-12-01 15:55:06 -070051}
52
53void early_graphics_stop(void)
54{
Jeremy Compostellab628bec2023-01-19 18:58:30 -070055 if (!CONFIG(MAINBOARD_USE_EARLY_LIBGFXINIT))
Jeremy Compostella47f154c2022-12-01 15:55:06 -070056 return;
57
Jeremy Compostellab628bec2023-01-19 18:58:30 -070058 gma_gfxstop();
Jeremy Compostella47f154c2022-12-01 15:55:06 -070059}