blob: 9d395c676e070146b84fde7f16b6a6e90cbb29be [file] [log] [blame]
Alban Bedelcad39662013-11-14 10:58:30 +01001/*
2 * (C) Copyright 2013
3 * Avionic Design GmbH <www.avionic-design.de>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
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
29void pinmux_init(void)
30{
31 pinmux_config_table(tamonten_ng_pinmux_common,
32 ARRAY_SIZE(tamonten_ng_pinmux_common));
33 pinmux_config_table(unused_pins_lowpower,
34 ARRAY_SIZE(unused_pins_lowpower));
35
36 /* Initialize any non-default pad configs (APB_MISC_GP regs) */
37 padgrp_config_table(tamonten_ng_padctrl,
38 ARRAY_SIZE(tamonten_ng_padctrl));
39}
40
41void gpio_early_init(void)
42{
43 /* Turn on the alive signal */
44 gpio_request(GPIO_PV2, "ALIVE");
45 gpio_direction_output(GPIO_PV2, 1);
46
47 /* Remove the reset on the external periph */
48 gpio_request(GPIO_PI4, "nRST_PERIPH");
49 gpio_direction_output(GPIO_PI4, 1);
50}
51
52void pmu_write(uchar reg, uchar data)
53{
54 i2c_set_bus_num(4); /* PMU is on bus 4 */
55 i2c_write(PMU_I2C_ADDRESS, reg, 1, &data, 1);
56}
57
58/*
59 * Do I2C/PMU writes to bring up SD card bus power
60 *
61 */
62void board_sdmmc_voltage_init(void)
63{
64 /* Enable LDO5 with 3.3v for SDMMC3 */
65 pmu_write(PMU_REG_LDO5, PMU_LDO5(HIGH_POWER, 3300));
66
67 /* Switch the power on */
68 gpio_request(GPIO_PJ2, "EN_3V3_EMMC");
69 gpio_direction_output(GPIO_PJ2, 1);
70}
71
72/*
73 * Routine: pin_mux_mmc
74 * Description: setup the MMC muxes, power rails, etc.
75 */
76void pin_mux_mmc(void)
77{
78 /*
79 * NOTE: We don't do mmc-specific pin muxes here.
80 * They were done globally in pinmux_init().
81 */
82
83 /* Bring up the SDIO1 power rail */
84 board_sdmmc_voltage_init();
85}