Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / x86 / lib / fsp2 / fsp_silicon_init.c
1 // SPDX-License-Identifier: Intel
2 /*
3  * Copyright (C) 2015-2016 Intel Corp.
4  * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
5  *
6  * Mostly taken from coreboot fsp2_0/silicon_init.c
7  */
8
9 #define LOG_CATEGORY UCLASS_NORTHBRIDGE
10
11 #include <common.h>
12 #include <binman.h>
13 #include <bootstage.h>
14 #include <dm.h>
15 #include <log.h>
16 #include <asm/arch/fsp/fsp_configs.h>
17 #include <asm/arch/fsp/fsp_s_upd.h>
18 #include <asm/fsp/fsp_infoheader.h>
19 #include <asm/fsp2/fsp_internal.h>
20
21 int fsp_silicon_init(bool s3wake, bool use_spi_flash)
22 {
23         struct fsps_upd upd, *fsp_upd;
24         fsp_silicon_init_func func;
25         struct fsp_header *hdr;
26         struct binman_entry entry;
27         struct udevice *dev;
28         ulong rom_offset = 0;
29         int ret;
30
31         ret = fsp_locate_fsp(FSP_S, &entry, use_spi_flash, &dev, &hdr,
32                              &rom_offset);
33         if (ret)
34                 return log_msg_ret("locate FSP", ret);
35         gd->arch.fsp_s_hdr = hdr;
36
37         /* Copy over the default config */
38         fsp_upd = (struct fsps_upd *)(hdr->img_base + hdr->cfg_region_off);
39         if (fsp_upd->header.signature != FSPS_UPD_SIGNATURE)
40                 return log_msg_ret("Bad UPD signature", -EPERM);
41         memcpy(&upd, fsp_upd, sizeof(upd));
42
43         ret = fsps_update_config(dev, rom_offset, &upd);
44         if (ret)
45                 return log_msg_ret("Could not setup config", ret);
46         log_debug("Silicon init...");
47         bootstage_start(BOOTSTAGE_ID_ACCUM_FSP_S, "fsp-s");
48         func = (fsp_silicon_init_func)(hdr->img_base + hdr->fsp_silicon_init);
49         ret = func(&upd);
50         bootstage_accum(BOOTSTAGE_ID_ACCUM_FSP_S);
51         if (ret)
52                 return log_msg_ret("Silicon init fail\n", ret);
53         log_debug("done\n");
54
55         return 0;
56 }