diff options
author | Felix Held <felix-coreboot@felixheld.de> | 2022-10-18 20:22:24 +0200 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2022-10-20 16:45:17 +0000 |
commit | 957e232277072dfd9998d19c948fb9c1870ef4e3 (patch) | |
tree | c0f0d399fa7574ace3e5a3f5dbfb20828f92b20c /src/soc/amd/morgana | |
parent | ceab0fbc59e19b89c429e0aef9c8fa200c276e4f (diff) |
soc/amd/morgana/uart: introduce and use soc_get_uart_ctrlr_info
Introduce and use soc_get_uart_ctrlr_info to access the uart_info array
to further decouple uart_info from the code as preparation to factor out
most of the code to a common implementation. In order to slightly reduce
the number of function calls, pass the size of and pointer to uart_info
to get_uart_idx as a parameter instead of calling again
soc_get_uart_ctrlr_info in get_uart_idx despite all callers already
having the information form the soc_get_uart_ctrlr_info call.
Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I80278f1a098b389d78f8e9a9fb875c4e466dc5db
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68537
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Fred Reitberger <reitbergerfred@gmail.com>
Diffstat (limited to 'src/soc/amd/morgana')
-rw-r--r-- | src/soc/amd/morgana/uart.c | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/src/soc/amd/morgana/uart.c b/src/soc/amd/morgana/uart.c index 8a77c87931..f6c552c8d4 100644 --- a/src/soc/amd/morgana/uart.c +++ b/src/soc/amd/morgana/uart.c @@ -39,19 +39,29 @@ static const struct soc_uart_ctrlr_info uart_info[] = { } }, }; +static const struct soc_uart_ctrlr_info *soc_get_uart_ctrlr_info(size_t *num_ctrlrs) +{ + *num_ctrlrs = ARRAY_SIZE(uart_info); + return uart_info; +} + uintptr_t get_uart_base(unsigned int idx) { - if (idx >= ARRAY_SIZE(uart_info)) + size_t num_ctrlrs; + const struct soc_uart_ctrlr_info *ctrlr = soc_get_uart_ctrlr_info(&num_ctrlrs); + + if (idx >= num_ctrlrs) return 0; - return uart_info[idx].base; + return ctrlr[idx].base; } -static enum cb_err get_uart_idx(uintptr_t base, unsigned int *idx) +static enum cb_err get_uart_idx(uintptr_t base, const struct soc_uart_ctrlr_info *ctrlr, + size_t num_ctrlrs, unsigned int *idx) { unsigned int i; - for (i = 0; i < ARRAY_SIZE(uart_info); i++) { - if (base == uart_info[i].base) { + for (i = 0; i < num_ctrlrs; i++) { + if (base == ctrlr[i].base) { *idx = i; return CB_SUCCESS; } @@ -62,10 +72,13 @@ static enum cb_err get_uart_idx(uintptr_t base, unsigned int *idx) static enum cb_err get_uart_aoac_device(uintptr_t base, unsigned int *aoac_dev) { unsigned int idx; - if (get_uart_idx(base, &idx) == CB_ERR) + size_t num_ctrlrs; + const struct soc_uart_ctrlr_info *ctrlr = soc_get_uart_ctrlr_info(&num_ctrlrs); + + if (get_uart_idx(base, ctrlr, num_ctrlrs, &idx) == CB_ERR) return CB_ERR; - *aoac_dev = uart_info[idx].aoac_device; + *aoac_dev = ctrlr[idx].aoac_device; return CB_SUCCESS; } @@ -76,17 +89,23 @@ void clear_uart_legacy_config(void) void set_uart_config(unsigned int idx) { - if (idx >= ARRAY_SIZE(uart_info)) + size_t num_ctrlrs; + const struct soc_uart_ctrlr_info *ctrlr = soc_get_uart_ctrlr_info(&num_ctrlrs); + + if (idx >= num_ctrlrs) return; - gpio_configure_pads(uart_info[idx].mux, 2); + gpio_configure_pads(ctrlr[idx].mux, 2); } static const char *uart_acpi_name(const struct device *dev) { unsigned int idx; - if (get_uart_idx(dev->path.mmio.addr, &idx) == CB_SUCCESS) - return uart_info[idx].acpi_name; + size_t num_ctrlrs; + const struct soc_uart_ctrlr_info *ctrlr = soc_get_uart_ctrlr_info(&num_ctrlrs); + + if (get_uart_idx(dev->path.mmio.addr, ctrlr, num_ctrlrs, &idx) == CB_SUCCESS) + return ctrlr[idx].acpi_name; else return NULL; } |