1 /*
2  *  (C) Copyright 2014-2016
3  *  Marcel Ziswiler <marcel@ziswiler.com>
4  *
5  * SPDX-License-Identifier:	GPL-2.0+
6  */
7 
8 #include <common.h>
9 #include <asm/arch/gp_padctrl.h>
10 #include <asm/arch/pinmux.h>
11 #include <asm/arch-tegra/ap.h>
12 #include <asm/arch-tegra/tegra.h>
13 #include <asm/gpio.h>
14 #include <asm/io.h>
15 #include <dm.h>
16 #include <i2c.h>
17 #include "../common/tdx-common.h"
18 
19 #include "pinmux-config-apalis_t30.h"
20 
21 DECLARE_GLOBAL_DATA_PTR;
22 
23 #define PMU_I2C_ADDRESS		0x2D
24 #define MAX_I2C_RETRY		3
25 
26 int arch_misc_init(void)
27 {
28 	if (readl(NV_PA_BASE_SRAM + NVBOOTINFOTABLE_BOOTTYPE) ==
29 	    NVBOOTTYPE_RECOVERY)
30 		printf("USB recovery mode\n");
31 
32 	return 0;
33 }
34 
35 int checkboard(void)
36 {
37 	printf("Model: Toradex Apalis T30 %dGB\n",
38 	       (gd->ram_size == 0x40000000) ? 1 : 2);
39 
40 	return 0;
41 }
42 
43 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
44 int ft_board_setup(void *blob, bd_t *bd)
45 {
46 	return ft_common_board_setup(blob, bd);
47 }
48 #endif
49 
50 /*
51  * Routine: pinmux_init
52  * Description: Do individual peripheral pinmux configs
53  */
54 void pinmux_init(void)
55 {
56 	pinmux_config_pingrp_table(tegra3_pinmux_common,
57 				   ARRAY_SIZE(tegra3_pinmux_common));
58 
59 	pinmux_config_pingrp_table(unused_pins_lowpower,
60 				   ARRAY_SIZE(unused_pins_lowpower));
61 
62 	/* Initialize any non-default pad configs (APB_MISC_GP regs) */
63 	pinmux_config_drvgrp_table(apalis_t30_padctrl,
64 				   ARRAY_SIZE(apalis_t30_padctrl));
65 }
66 
67 #ifdef CONFIG_PCI_TEGRA
68 int tegra_pcie_board_init(void)
69 {
70 	struct udevice *dev;
71 	u8 addr, data[1];
72 	int err;
73 
74 	err = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, 1, &dev);
75 	if (err) {
76 		debug("%s: Cannot find PMIC I2C chip\n", __func__);
77 		return err;
78 	}
79 
80 	/* TPS659110: VDD2_OP_REG = 1.05V */
81 	data[0] = 0x27;
82 	addr = 0x25;
83 
84 	err = dm_i2c_write(dev, addr, data, 1);
85 	if (err) {
86 		debug("failed to set VDD supply\n");
87 		return err;
88 	}
89 
90 	/* TPS659110: VDD2_REG 7.5 mV/us, ACTIVE */
91 	data[0] = 0x0D;
92 	addr = 0x24;
93 
94 	err = dm_i2c_write(dev, addr, data, 1);
95 	if (err) {
96 		debug("failed to enable VDD supply\n");
97 		return err;
98 	}
99 
100 	/* TPS659110: LDO6_REG = 1.1V, ACTIVE */
101 	data[0] = 0x0D;
102 	addr = 0x35;
103 
104 	err = dm_i2c_write(dev, addr, data, 1);
105 	if (err) {
106 		debug("failed to set AVDD supply\n");
107 		return err;
108 	}
109 
110 	return 0;
111 }
112 #endif /* CONFIG_PCI_TEGRA */
113