blob: 4892accc5236b12076ffc340aa9295ded10b3322 [file] [log] [blame]
Svyatoslav Ryhel84686d82024-08-01 16:42:24 +03001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2024
4 * Svyatoslav Ryhel <clamor95@gmail.com>
5 */
6
7#include <env.h>
8#include <spl_gpio.h>
9
10#include <asm/gpio.h>
11#include <asm/arch/pinmux.h>
12
13/*
14 * PMIC_ID is GMI_CS2_N_PK3
15 * MODEM_ID is GMI_CS4_N_PK2
16 *
17 * Extended Project ID
18 * ====================================
19 * MODEM_ID PMIC_ID project name
20 * 0 0 grouper-E1565
21 * 0 1 grouper-PM269
22 * 1 0 tilapia
23 */
24enum project_rev {
25 E1565, PM269, TILAPIA, COUNT,
26};
27
28static const char * const project_id_to_fdt[] = {
29 [E1565] = "tegra30-asus-nexus7-grouper-E1565",
30 [PM269] = "tegra30-asus-nexus7-grouper-PM269",
31 [TILAPIA] = "tegra30-asus-nexus7-tilapia-E1565",
32};
33
34static int id_gpio_get_value(u32 pingrp, u32 pin)
35{
36 /* Configure pinmux */
37 pinmux_set_func(pingrp, PMUX_FUNC_GMI);
38 pinmux_set_pullupdown(pingrp, PMUX_PULL_DOWN);
39 pinmux_tristate_enable(pingrp);
40 pinmux_set_io(pingrp, PMUX_PIN_INPUT);
41
42 /*
43 * Since this function may be called
44 * during DM reload we should use SPL
45 * GPIO functions which do not depend
46 * on DM.
47 */
48 spl_gpio_input(NULL, pin);
49 return spl_gpio_get_value(NULL, pin);
50}
51
52static int get_project_id(void)
53{
54 u32 pmic_id, modem_id, proj_id;
55
56 modem_id = id_gpio_get_value(PMUX_PINGRP_GMI_CS4_N_PK2,
57 TEGRA_GPIO(K, 2));
58 pmic_id = id_gpio_get_value(PMUX_PINGRP_GMI_CS2_N_PK3,
59 TEGRA_GPIO(K, 3));
60
61 proj_id = (modem_id << 1 | pmic_id) & COUNT;
62
63 log_debug("[GROUPER]: project id %d (%s)\n", proj_id,
64 project_id_to_fdt[proj_id]);
65
66 return proj_id;
67}
68
69int board_fit_config_name_match(const char *name)
70{
71 if (!strcmp(name, project_id_to_fdt[get_project_id()]))
72 return 0;
73
74 return -1;
75}
76
77void nvidia_board_late_init(void)
78{
79 char dt_path[64] = { 0 };
80
81 snprintf(dt_path, sizeof(dt_path), "%s.dtb",
82 project_id_to_fdt[get_project_id()]);
83 env_set("fdtfile", dt_path);
84}