Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <stdint.h> |
| 4 | #include <amdblocks/acpimmio.h> |
Felix Held | 5b3831c | 2020-11-30 17:56:59 +0100 | [diff] [blame] | 5 | #include <amdblocks/aoac.h> |
Felix Held | 038ed9e | 2021-06-15 16:24:10 +0200 | [diff] [blame] | 6 | #include <soc/aoac_defs.h> |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 7 | #include <soc/southbridge.h> |
| 8 | #include <delay.h> |
| 9 | |
| 10 | #define FCH_AOAC_UART_FOR_CONSOLE \ |
| 11 | (CONFIG_UART_FOR_CONSOLE == 0 ? FCH_AOAC_DEV_UART0 \ |
| 12 | : CONFIG_UART_FOR_CONSOLE == 1 ? FCH_AOAC_DEV_UART1 \ |
| 13 | : CONFIG_UART_FOR_CONSOLE == 2 ? FCH_AOAC_DEV_UART2 \ |
| 14 | : CONFIG_UART_FOR_CONSOLE == 3 ? FCH_AOAC_DEV_UART3 \ |
| 15 | : -1) |
Felix Held | 0dfaf33 | 2020-12-09 16:25:18 +0100 | [diff] [blame] | 16 | #if CONFIG(AMD_SOC_CONSOLE_UART) && FCH_AOAC_UART_FOR_CONSOLE == -1 |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 17 | # error Unsupported UART_FOR_CONSOLE chosen |
| 18 | #endif |
| 19 | |
| 20 | /* |
| 21 | * Table of devices that need their AOAC registers enabled and waited |
| 22 | * upon (usually about .55 milliseconds). Instead of individual delays |
| 23 | * waiting for each device to become available, a single delay will be |
| 24 | * executed. The console UART is handled separately from this table. |
| 25 | */ |
Elyes Haouas | 2476942 | 2023-01-12 06:21:42 +0100 | [diff] [blame] | 26 | static const unsigned int aoac_devs[] = { |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 27 | FCH_AOAC_DEV_AMBA, |
| 28 | FCH_AOAC_DEV_I2C2, |
| 29 | FCH_AOAC_DEV_I2C3, |
| 30 | FCH_AOAC_DEV_I2C4, |
| 31 | FCH_AOAC_DEV_ESPI, |
| 32 | }; |
| 33 | |
Felix Held | 6c61b4b | 2020-09-12 01:01:43 +0200 | [diff] [blame] | 34 | void wait_for_aoac_enabled(unsigned int dev) |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 35 | { |
Raul E Rangel | 5591b91 | 2020-06-11 16:53:57 -0600 | [diff] [blame] | 36 | while (!is_aoac_device_enabled(dev)) |
| 37 | udelay(100); |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void enable_aoac_devices(void) |
| 41 | { |
Felix Held | 6c61b4b | 2020-09-12 01:01:43 +0200 | [diff] [blame] | 42 | unsigned int i; |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 43 | |
| 44 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 45 | power_on_aoac_device(aoac_devs[i]); |
Raul E Rangel | 5591b91 | 2020-06-11 16:53:57 -0600 | [diff] [blame] | 46 | |
Felix Held | 0dfaf33 | 2020-12-09 16:25:18 +0100 | [diff] [blame] | 47 | if (CONFIG(AMD_SOC_CONSOLE_UART)) |
Raul E Rangel | 5591b91 | 2020-06-11 16:53:57 -0600 | [diff] [blame] | 48 | power_on_aoac_device(FCH_AOAC_UART_FOR_CONSOLE); |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 49 | |
| 50 | /* Wait for AOAC devices to indicate power and clock OK */ |
Raul E Rangel | 5591b91 | 2020-06-11 16:53:57 -0600 | [diff] [blame] | 51 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 52 | wait_for_aoac_enabled(aoac_devs[i]); |
| 53 | |
Felix Held | 0dfaf33 | 2020-12-09 16:25:18 +0100 | [diff] [blame] | 54 | if (CONFIG(AMD_SOC_CONSOLE_UART)) |
Raul E Rangel | 5591b91 | 2020-06-11 16:53:57 -0600 | [diff] [blame] | 55 | wait_for_aoac_enabled(FCH_AOAC_UART_FOR_CONSOLE); |
Raul E Rangel | d53c281 | 2020-06-11 14:06:11 -0600 | [diff] [blame] | 56 | } |