Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 Google LLC |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | */ |
| 6 | |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 7 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 9 | #include <asm/arch/iomap.h> |
Bernhard Messerklinger | d9461aa | 2020-05-18 12:33:34 +0200 | [diff] [blame] | 10 | #include <asm/arch/fsp_bindings.h> |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 11 | #include <asm/fsp2/fsp_internal.h> |
| 12 | #include <dm/uclass-internal.h> |
| 13 | |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 14 | int fspm_update_config(struct udevice *dev, struct fspm_upd *upd) |
| 15 | { |
| 16 | struct fsp_m_config *cfg = &upd->config; |
| 17 | struct fspm_arch_upd *arch = &upd->arch; |
Simon Glass | 1d2a334 | 2020-07-09 18:43:17 -0600 | [diff] [blame] | 18 | int cache_ret = 0; |
Bernhard Messerklinger | d9461aa | 2020-05-18 12:33:34 +0200 | [diff] [blame] | 19 | ofnode node; |
Simon Glass | 1d2a334 | 2020-07-09 18:43:17 -0600 | [diff] [blame] | 20 | int ret; |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 21 | |
| 22 | arch->nvs_buffer_ptr = NULL; |
Simon Glass | 1d2a334 | 2020-07-09 18:43:17 -0600 | [diff] [blame] | 23 | cache_ret = prepare_mrc_cache(upd); |
| 24 | if (cache_ret && cache_ret != -ENOENT) |
| 25 | return log_msg_ret("mrc", cache_ret); |
Simon Glass | c28a1e0 | 2020-07-16 21:22:33 -0600 | [diff] [blame] | 26 | arch->stack_base = (void *)(CONFIG_SYS_CAR_ADDR + CONFIG_SYS_CAR_SIZE - |
| 27 | arch->stack_size); |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 28 | arch->boot_loader_tolum_size = 0; |
Simon Glass | a929b93 | 2020-07-16 21:22:32 -0600 | [diff] [blame] | 29 | arch->boot_mode = cache_ret ? FSP_BOOT_WITH_FULL_CONFIGURATION : |
| 30 | FSP_BOOT_ASSUMING_NO_CONFIGURATION_CHANGES; |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 31 | |
Bernhard Messerklinger | d9461aa | 2020-05-18 12:33:34 +0200 | [diff] [blame] | 32 | node = dev_ofnode(dev); |
| 33 | if (!ofnode_valid(node)) |
Simon Glass | 2e5398b | 2020-12-23 08:11:28 -0700 | [diff] [blame] | 34 | return log_msg_ret("node", -ENOENT); |
| 35 | node = ofnode_find_subnode(node, "fsp-m"); |
| 36 | if (!ofnode_valid(node)) |
| 37 | return log_msg_ret("fspm", -ENOENT); |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 38 | |
Simon Glass | 1d2a334 | 2020-07-09 18:43:17 -0600 | [diff] [blame] | 39 | ret = fsp_m_update_config_from_dtb(node, cfg); |
| 40 | if (ret) |
| 41 | return log_msg_ret("dtb", cache_ret); |
| 42 | |
| 43 | return cache_ret; |
Simon Glass | 42bf7db | 2019-12-08 17:40:19 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | /* |
| 47 | * The FSP-M binary appears to break the SPI controller. It can be fixed by |
| 48 | * writing the BAR again, so do that here |
| 49 | */ |
| 50 | int fspm_done(struct udevice *dev) |
| 51 | { |
| 52 | struct udevice *spi; |
| 53 | int ret; |
| 54 | |
| 55 | /* Don't probe the device, since that reads the BAR */ |
| 56 | ret = uclass_find_first_device(UCLASS_SPI, &spi); |
| 57 | if (ret) |
| 58 | return log_msg_ret("SPI", ret); |
| 59 | if (!spi) |
| 60 | return log_msg_ret("no SPI", -ENODEV); |
| 61 | |
| 62 | dm_pci_write_config32(spi, PCI_BASE_ADDRESS_0, |
| 63 | IOMAP_SPI_BASE | PCI_BASE_ADDRESS_SPACE_MEMORY); |
| 64 | |
| 65 | return 0; |
| 66 | } |