Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2022 Marek Vasut <marex@denx.de> |
| 4 | */ |
| 5 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame] | 6 | #include <common.h> |
Marek Vasut | f670cd7 | 2022-05-21 16:56:26 +0200 | [diff] [blame] | 7 | #include <asm/io.h> |
| 8 | #include <asm-generic/gpio.h> |
| 9 | |
| 10 | #include "lpddr4_timing.h" |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | u8 dh_get_memcfg(void) |
| 15 | { |
| 16 | struct gpio_desc gpio[4]; |
| 17 | u8 memcfg = 0; |
| 18 | ofnode node; |
| 19 | int i, ret; |
| 20 | |
| 21 | node = ofnode_path("/config"); |
| 22 | if (!ofnode_valid(node)) { |
| 23 | printf("%s: no /config node?\n", __func__); |
| 24 | return BIT(2) | BIT(0); |
| 25 | } |
| 26 | |
| 27 | ret = gpio_request_list_by_name_nodev(node, |
| 28 | "dh,ram-coding-gpios", |
| 29 | gpio, ARRAY_SIZE(gpio), |
| 30 | GPIOD_IS_IN); |
| 31 | for (i = 0; i < ret; i++) |
| 32 | memcfg |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 33 | |
| 34 | gpio_free_list_nodev(gpio, ret); |
| 35 | |
| 36 | return memcfg; |
| 37 | } |