drivers/mipi: Add support for KD_KD110N11_51IE panel
[coreboot2.git] / src / soc / mediatek / common / mtk_fsp.c
blobbc1b5d5f08cc81d991da43ed715612a2d93ee4d6
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cbfs.h>
4 #include <console/console.h>
5 #include <soc/mtk_fsp.h>
7 #define MAX_PARAM_ENTRIES 32
8 #define FSP_INTF_SIZE (sizeof(struct mtk_fsp_intf) + \
9 sizeof(struct mtk_fsp_param) * MAX_PARAM_ENTRIES)
11 static struct mtk_fsp_intf *intf;
12 static uint8_t fsp_intf_buf[FSP_INTF_SIZE] __aligned(8);
14 static int vprintf_wrapper(const char *fmt, va_list args)
16 return vprintk(BIOS_INFO, fmt, args);
19 void mtk_fsp_init(enum fsp_phase phase)
21 intf = (struct mtk_fsp_intf *)fsp_intf_buf;
22 intf->major_version = INTF_MAJOR_VER;
23 intf->minor_version = INTF_MINOR_VER;
24 intf->header_size = sizeof(struct mtk_fsp_intf);
25 intf->entry_size = sizeof(struct mtk_fsp_param);
26 intf->num_entries = 0;
27 intf->phase = phase;
28 intf->do_vprintf = vprintf_wrapper;
31 enum cb_err mtk_fsp_add_param(enum fsp_param_type type, size_t param_size,
32 void *param)
34 struct mtk_fsp_param *entry;
36 if (!intf) {
37 printk(BIOS_ERR, "%s: intf is not initialized\n", __func__);
38 return CB_ERR;
41 if (intf->num_entries == MAX_PARAM_ENTRIES) {
42 printk(BIOS_ERR, "%s: run out all entries\n", __func__);
43 return CB_ERR;
46 entry = &intf->entries[intf->num_entries];
48 entry->param_type = type;
49 entry->param_size = param_size;
50 entry->param = param;
51 intf->num_entries++;
53 return CB_SUCCESS;
56 static void mtk_fsp_dump_intf(void)
58 struct mtk_fsp_param *entry;
60 if (!intf) {
61 printk(BIOS_ERR, "%s: intf is not initialized\n", __func__);
62 return;
65 printk(BIOS_DEBUG, "%s: major version: %u, minor version: %u\n",
66 __func__, intf->major_version, intf->minor_version);
67 printk(BIOS_DEBUG, "%s: FSP phase: %u, status: %d\n",
68 __func__, intf->phase, intf->status);
69 printk(BIOS_DEBUG, "%-5s %-10s %-10s %s\n", "Param", "type", "size", "address");
70 for (int i = 0; i < intf->num_entries; i++) {
71 entry = &intf->entries[i];
72 printk(BIOS_DEBUG, "%-5u %-10u %-10u %p\n",
73 i, entry->param_type, entry->param_size, entry->param);
77 static const char *mtk_fsp_file(void)
79 return CONFIG_CBFS_PREFIX "/mtk_fsp_" ENV_STRING;
82 enum cb_err mtk_fsp_load_and_run(void)
84 struct prog fsp = PROG_INIT(PROG_REFCODE, mtk_fsp_file());
86 if (cbfs_prog_stage_load(&fsp)) {
87 printk(BIOS_ERR, "%s: CBFS load program failed\n", __func__);
88 return CB_ERR;
91 if (!intf) {
92 printk(BIOS_ERR, "%s: intf is not initialized\n", __func__);
93 return CB_ERR;
96 prog_set_arg(&fsp, intf);
97 prog_run(&fsp);
99 if (intf->status != FSP_STATUS_SUCCESS) {
100 mtk_fsp_dump_intf();
101 return CB_ERR;
104 printk(BIOS_INFO, "%s: run %s at phase %#x done\n",
105 __func__, mtk_fsp_file(), intf->phase);
107 return CB_SUCCESS;