-
Notifications
You must be signed in to change notification settings - Fork 176
/
board.c
80 lines (64 loc) · 1.63 KB
/
board.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <common.h>
#include <errno.h>
#include <asm/io.h>
#include <asm/arch/secure_apb.h>
#include <asm-generic/gpio.h>
#include <asm/arch/gpio.h>
#include <linux/kernel.h>
#include <odroid-common.h>
#define GPIO_LED_ALIVE 11 // GPIOAO_11
int board_led_alive(int status)
{
int ret = gpio_request(GPIO_LED_ALIVE, "alive");
if (ret < 0) {
printf("Failed to request GPIO pin %u\n", GPIO_LED_ALIVE);
return -EINVAL;
}
return gpio_direction_output(GPIO_LED_ALIVE, status & 1);
}
const char *boot_device_name(int n)
{
struct names {
int id;
const char* name;
} names[] = {
{ BOOT_DEVICE_RESERVED, "reserved" },
{ BOOT_DEVICE_EMMC, "emmc" },
{ BOOT_DEVICE_NAND, "nand" },
{ BOOT_DEVICE_SPI, "spi" },
{ BOOT_DEVICE_SD, "sd" },
{ BOOT_DEVICE_USB, "usb" },
};
int i;
for (i = 0; i < ARRAY_SIZE(names); i++)
if (names[i].id == n)
return names[i].name;
return NULL;
}
int get_boot_device(void)
{
return readl(AO_SEC_GP_CFG0) & 0xf;
}
static int board_rev = -1;
#define IS_RANGE(x, min, max) ((x) > (min) && (x) < (max))
static unsigned int get_hw_revision(void)
{
int hwrev = -1;
int adc = get_adc_value(1);
if (IS_RANGE(adc, 80, 90)) /* ave : 84 */
hwrev = BOARD_REVISION(2018, 7, 23);
else if (IS_RANGE(adc, 160, 170)) /* avg : 164 */
hwrev = BOARD_REVISION(2018, 12, 6);
else if (IS_RANGE(adc, 245, 255)) /* avg : 248 */
hwrev = BOARD_REVISION(2019, 1, 17);
else if (IS_RANGE(adc, 330, 350)) /* avg : 334 */
hwrev = BOARD_REVISION(2019, 2, 7);
debug("ADC=%d, hwrev=0x%x\n", adc, hwrev);
return hwrev;
}
int board_revision(void)
{
if (board_rev == -1)
board_rev = get_hw_revision();
return board_rev;
}