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