Stefan Bosch | b4bb31d | 2020-07-10 19:07:37 +0200 | [diff] [blame] | 1 | // 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 | |
| 31 | static int pcb_rev = -1; |
| 32 | static int base_rev; |
| 33 | |
| 34 | static 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 | |
| 51 | void 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 */ |
| 64 | void 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 */ |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 83 | u32 get_board_revision(void) |
Stefan Bosch | b4bb31d | 2020-07-10 19:07:37 +0200 | [diff] [blame] | 84 | { |
| 85 | return (base_rev << 8) | pcb_rev; |
| 86 | } |
Tom Rini | 4cc3885 | 2021-08-30 09:16:30 -0400 | [diff] [blame] | 87 | |
| 88 | #ifdef CONFIG_REVISION_TAG |
| 89 | u32 get_board_rev(void) |
| 90 | { |
| 91 | return get_board_revision(); |
| 92 | } |
| 93 | #endif |
Stefan Bosch | b4bb31d | 2020-07-10 19:07:37 +0200 | [diff] [blame] | 94 | |
| 95 | const char *get_board_name(void) |
| 96 | { |
| 97 | bd_hwrev_init(); |
| 98 | |
| 99 | switch (pcb_rev) { |
| 100 | case 0: |
| 101 | return "NanoPi 2"; |
| 102 | case 1: |
| 103 | return "NanoPC-T2"; |
| 104 | case 2: |
| 105 | return "NanoPi S2"; |
| 106 | case 3: |
| 107 | return "Smart4418"; |
| 108 | case 4: |
| 109 | return "NanoPi Fire 2A"; |
| 110 | case 7: |
| 111 | return "NanoPi M2A"; |
| 112 | default: |
| 113 | return "s5p4418-X"; |
| 114 | } |
| 115 | } |