summaryrefslogtreecommitdiff
path: root/board/avionic-design/common/tamonten-ng.c
blob: 106be9b761bde349506188589f0ba77af1a88544 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
 * (C) Copyright 2013
 * Avionic Design GmbH <www.avionic-design.de>
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <dm.h>
#include <asm/arch/pinmux.h>
#include <asm/arch/gp_padctrl.h>
#include <asm/arch/gpio.h>
#include <asm/gpio.h>
#include "pinmux-config-tamonten-ng.h"
#include <i2c.h>

#define PMU_I2C_ADDRESS		0x2D

#define PMU_REG_LDO5		0x32

#define PMU_REG_LDO_HIGH_POWER	1

/* Voltage selection for the LDOs with 100mV resolution */
#define PMU_REG_LDO_SEL_100(mV)	((((mV - 1000) / 100) + 2) << 2)

#define PMU_REG_LDO_100(st, mV)	(PMU_REG_LDO_##st | PMU_REG_LDO_SEL_100(mV))

#define PMU_LDO5(st, mV)	PMU_REG_LDO_100(st, mV)

void pinmux_init(void)
{
	pinmux_config_pingrp_table(tamonten_ng_pinmux_common,
		ARRAY_SIZE(tamonten_ng_pinmux_common));
	pinmux_config_pingrp_table(unused_pins_lowpower,
		ARRAY_SIZE(unused_pins_lowpower));

	/* Initialize any non-default pad configs (APB_MISC_GP regs) */
	pinmux_config_drvgrp_table(tamonten_ng_padctrl,
		ARRAY_SIZE(tamonten_ng_padctrl));
}

void gpio_early_init(void)
{
	/* Turn on the alive signal */
	gpio_request(TEGRA_GPIO(V, 2), "ALIVE");
	gpio_direction_output(TEGRA_GPIO(V, 2), 1);

	/* Remove the reset on the external periph */
	gpio_request(TEGRA_GPIO(I, 4), "nRST_PERIPH");
	gpio_direction_output(TEGRA_GPIO(I, 4), 1);
}

void pmu_write(uchar reg, uchar data)
{
	struct udevice *dev;
	int ret;

	ret = i2c_get_chip_for_busnum(4, PMU_I2C_ADDRESS, 1, &dev);
	if (ret) {
		debug("%s: Cannot find PMIC I2C chip\n", __func__);
		return;
	}
	dm_i2c_write(dev, reg, &data, 1);
}

/*
 * Do I2C/PMU writes to bring up SD card bus power
 *
 */
void board_sdmmc_voltage_init(void)
{
	/* Enable LDO5 with 3.3v for SDMMC3 */
	pmu_write(PMU_REG_LDO5, PMU_LDO5(HIGH_POWER, 3300));

	/* Switch the power on */
	gpio_request(TEGRA_GPIO(J, 2), "EN_3V3_EMMC");
	gpio_direction_output(TEGRA_GPIO(J, 2), 1);
}

/*
 * Routine: pin_mux_mmc
 * Description: setup the MMC muxes, power rails, etc.
 */
void pin_mux_mmc(void)
{
	/*
	 * NOTE: We don't do mmc-specific pin muxes here.
	 * They were done globally in pinmux_init().
	 */

	/* Bring up the SDIO1 power rail */
	board_sdmmc_voltage_init();
}