Yidi Lin | 7ba3775 | 2020-10-29 13:01:28 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <arch/barrier.h> |
| 4 | #include <cbfs.h> |
| 5 | #include <console/console.h> |
| 6 | #include <soc/mcu_common.h> |
| 7 | #include <soc/symbols.h> |
| 8 | #include <timer.h> |
| 9 | |
Elyes Haouas | 8168e28 | 2022-10-08 16:22:41 +0200 | [diff] [blame] | 10 | enum cb_err mtk_init_mcu(struct mtk_mcu *mcu) |
Yidi Lin | 7ba3775 | 2020-10-29 13:01:28 +0800 | [diff] [blame] | 11 | { |
| 12 | struct stopwatch sw; |
| 13 | |
| 14 | if (!mcu) |
| 15 | return CB_ERR_ARG; |
| 16 | |
| 17 | stopwatch_init(&sw); |
| 18 | |
| 19 | mcu->run_size = cbfs_load(mcu->firmware_name, mcu->load_buffer, mcu->buffer_size); |
| 20 | if (mcu->run_size == 0) { |
| 21 | printk(BIOS_ERR, "%s: Failed to load %s\n", __func__, mcu->firmware_name); |
| 22 | return CB_ERR; |
| 23 | } |
| 24 | |
| 25 | if (mcu->run_address) { |
| 26 | memcpy(mcu->run_address, mcu->load_buffer, mcu->run_size); |
| 27 | /* Memory barrier to ensure data is flushed before resetting MCU. */ |
| 28 | mb(); |
| 29 | } |
| 30 | |
| 31 | if (mcu->reset) |
| 32 | mcu->reset(mcu); |
| 33 | |
Rob Barnes | d522f38 | 2022-09-12 06:31:47 -0600 | [diff] [blame] | 34 | printk(BIOS_DEBUG, "%s: Loaded (and reset) %s in %lld msecs (%zd bytes)\n", |
Yidi Lin | 7ba3775 | 2020-10-29 13:01:28 +0800 | [diff] [blame] | 35 | __func__, mcu->firmware_name, stopwatch_duration_msecs(&sw), mcu->run_size); |
| 36 | |
| 37 | return CB_SUCCESS; |
| 38 | } |