Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 |
| 4 | * Avionic Design GmbH <www.avionic-design.de> |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 667aee9 | 2014-12-10 08:55:57 -0700 | [diff] [blame] | 8 | #include <dm.h> |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 9 | #include <asm/arch/pinmux.h> |
| 10 | #include <asm/arch/gp_padctrl.h> |
| 11 | #include <asm/arch/gpio.h> |
| 12 | #include <asm/gpio.h> |
| 13 | #include "pinmux-config-tamonten-ng.h" |
| 14 | #include <i2c.h> |
| 15 | |
| 16 | #define PMU_I2C_ADDRESS 0x2D |
| 17 | |
| 18 | #define PMU_REG_LDO5 0x32 |
| 19 | |
| 20 | #define PMU_REG_LDO_HIGH_POWER 1 |
| 21 | |
| 22 | /* Voltage selection for the LDOs with 100mV resolution */ |
| 23 | #define PMU_REG_LDO_SEL_100(mV) ((((mV - 1000) / 100) + 2) << 2) |
| 24 | |
| 25 | #define PMU_REG_LDO_100(st, mV) (PMU_REG_LDO_##st | PMU_REG_LDO_SEL_100(mV)) |
| 26 | |
| 27 | #define PMU_LDO5(st, mV) PMU_REG_LDO_100(st, mV) |
| 28 | |
| 29 | void pinmux_init(void) |
| 30 | { |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 31 | pinmux_config_pingrp_table(tamonten_ng_pinmux_common, |
| 32 | ARRAY_SIZE(tamonten_ng_pinmux_common)); |
| 33 | pinmux_config_pingrp_table(unused_pins_lowpower, |
| 34 | ARRAY_SIZE(unused_pins_lowpower)); |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 35 | |
| 36 | /* Initialize any non-default pad configs (APB_MISC_GP regs) */ |
Stephen Warren | f4df605 | 2014-03-21 12:28:56 -0600 | [diff] [blame] | 37 | pinmux_config_drvgrp_table(tamonten_ng_padctrl, |
| 38 | ARRAY_SIZE(tamonten_ng_padctrl)); |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | void gpio_early_init(void) |
| 42 | { |
| 43 | /* Turn on the alive signal */ |
Stephen Warren | 7f20bb2 | 2016-05-12 12:07:39 -0600 | [diff] [blame] | 44 | gpio_request(TEGRA_GPIO(V, 2), "ALIVE"); |
| 45 | gpio_direction_output(TEGRA_GPIO(V, 2), 1); |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 46 | |
| 47 | /* Remove the reset on the external periph */ |
Stephen Warren | 7f20bb2 | 2016-05-12 12:07:39 -0600 | [diff] [blame] | 48 | gpio_request(TEGRA_GPIO(I, 4), "nRST_PERIPH"); |
| 49 | gpio_direction_output(TEGRA_GPIO(I, 4), 1); |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void pmu_write(uchar reg, uchar data) |
| 53 | { |
Simon Glass | 667aee9 | 2014-12-10 08:55:57 -0700 | [diff] [blame] | 54 | struct udevice *dev; |
| 55 | int ret; |
| 56 | |
Simon Glass | a2723ae | 2015-01-25 08:26:55 -0700 | [diff] [blame] | 57 | ret = i2c_get_chip_for_busnum(4, PMU_I2C_ADDRESS, 1, &dev); |
Simon Glass | 667aee9 | 2014-12-10 08:55:57 -0700 | [diff] [blame] | 58 | if (ret) { |
| 59 | debug("%s: Cannot find PMIC I2C chip\n", __func__); |
| 60 | return; |
| 61 | } |
Simon Glass | 7d72276 | 2015-01-12 18:02:07 -0700 | [diff] [blame] | 62 | dm_i2c_write(dev, reg, &data, 1); |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Do I2C/PMU writes to bring up SD card bus power |
| 67 | * |
| 68 | */ |
| 69 | void board_sdmmc_voltage_init(void) |
| 70 | { |
| 71 | /* Enable LDO5 with 3.3v for SDMMC3 */ |
| 72 | pmu_write(PMU_REG_LDO5, PMU_LDO5(HIGH_POWER, 3300)); |
| 73 | |
| 74 | /* Switch the power on */ |
Stephen Warren | 7f20bb2 | 2016-05-12 12:07:39 -0600 | [diff] [blame] | 75 | gpio_request(TEGRA_GPIO(J, 2), "EN_3V3_EMMC"); |
| 76 | gpio_direction_output(TEGRA_GPIO(J, 2), 1); |
Alban Bedel | cad3966 | 2013-11-14 10:58:30 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Routine: pin_mux_mmc |
| 81 | * Description: setup the MMC muxes, power rails, etc. |
| 82 | */ |
| 83 | void pin_mux_mmc(void) |
| 84 | { |
| 85 | /* |
| 86 | * NOTE: We don't do mmc-specific pin muxes here. |
| 87 | * They were done globally in pinmux_init(). |
| 88 | */ |
| 89 | |
| 90 | /* Bring up the SDIO1 power rail */ |
| 91 | board_sdmmc_voltage_init(); |
| 92 | } |