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