blob: b1e23a48a803b3483988fd7b7def12cdd9ab2a00 [file] [log] [blame]
Stefan Boschb4bb31d2020-07-10 19:07:37 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) Guangzhou FriendlyARM Computer Tech. Co., Ltd.
4 * (http://www.friendlyarm.com)
5 */
6
7#include <config.h>
8#include <common.h>
9#include <i2c.h>
10#include <asm/io.h>
11
12#include <asm/arch/nexell.h>
13#include <asm/arch/nx_gpio.h>
14
15/* Board revision list: <PCB3 | PCB2 | PCB1>
16 * 0b000 - NanoPi 2
17 * 0b001 - NanoPC-T2
18 * 0b010 - NanoPi S2
19 * 0b011 - Smart4418
20 * 0b100 - NanoPi Fire 2A
21 * 0b111 - NanoPi M2A
22 *
23 * Extented revision:
24 * 0b001 - Smart4418-SDK
25 */
26#define __IO_GRP 2 /* GPIO_C */
27#define __IO_PCB1 26
28#define __IO_PCB2 27
29#define __IO_PCB3 25
30
31static int pcb_rev = -1;
32static int base_rev;
33
34static void bd_hwrev_config_gpio(void)
35{
36 int gpios[3][2] = {
37 { __IO_PCB1, 1 },
38 { __IO_PCB2, 1 },
39 { __IO_PCB3, 1 },
40 };
41 int i;
42
43 /* gpio input mode, pull-down */
44 for (i = 0; i < 3; i++) {
45 nx_gpio_set_pad_function(__IO_GRP, gpios[i][0], gpios[i][1]);
46 nx_gpio_set_output_enable(__IO_GRP, gpios[i][0], 0);
47 nx_gpio_set_pull_mode(__IO_GRP, gpios[i][0], 0);
48 }
49}
50
51void bd_hwrev_init(void)
52{
53 if (pcb_rev >= 0)
54 return;
55
56 bd_hwrev_config_gpio();
57
58 pcb_rev = nx_gpio_get_input_value(__IO_GRP, __IO_PCB1);
59 pcb_rev |= nx_gpio_get_input_value(__IO_GRP, __IO_PCB2) << 1;
60 pcb_rev |= nx_gpio_get_input_value(__IO_GRP, __IO_PCB3) << 2;
61}
62
63/* Get extended revision for SmartXX18 */
64void bd_base_rev_init(void)
65{
66 struct udevice *dev;
67 u8 val = 0;
68
69 if (pcb_rev != 0x3)
70 return;
71
72#define PCA9536_I2C_BUS 2
73#define PCA9636_I2C_ADDR 0x41
74 if (i2c_get_chip_for_busnum
75 (PCA9536_I2C_BUS, PCA9636_I2C_ADDR, 1, &dev))
76 return;
77
78 if (!dm_i2c_read(dev, 0, &val, 1))
79 base_rev = (val & 0xf);
80}
81
82/* To override __weak symbols */
83u32 get_board_rev(void)
84{
85 return (base_rev << 8) | pcb_rev;
86}
87
88const char *get_board_name(void)
89{
90 bd_hwrev_init();
91
92 switch (pcb_rev) {
93 case 0:
94 return "NanoPi 2";
95 case 1:
96 return "NanoPC-T2";
97 case 2:
98 return "NanoPi S2";
99 case 3:
100 return "Smart4418";
101 case 4:
102 return "NanoPi Fire 2A";
103 case 7:
104 return "NanoPi M2A";
105 default:
106 return "s5p4418-X";
107 }
108}