Merge branch 'master' of git://git.denx.de/u-boot-mmc
[platform/kernel/u-boot.git] / board / nvidia / cardhu / cardhu.c
1 /*
2  *  (C) Copyright 2010-2013
3  *  NVIDIA Corporation <www.nvidia.com>
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #include <common.h>
9 #include <dm.h>
10 #include <asm/arch/pinmux.h>
11 #include <asm/arch/gp_padctrl.h>
12 #include "pinmux-config-cardhu.h"
13 #include <i2c.h>
14
15 #define PMU_I2C_ADDRESS         0x2D
16 #define MAX_I2C_RETRY           3
17
18 /*
19  * Routine: pinmux_init
20  * Description: Do individual peripheral pinmux configs
21  */
22 void pinmux_init(void)
23 {
24         pinmux_config_pingrp_table(tegra3_pinmux_common,
25                 ARRAY_SIZE(tegra3_pinmux_common));
26
27         pinmux_config_pingrp_table(unused_pins_lowpower,
28                 ARRAY_SIZE(unused_pins_lowpower));
29
30         /* Initialize any non-default pad configs (APB_MISC_GP regs) */
31         pinmux_config_drvgrp_table(cardhu_padctrl, ARRAY_SIZE(cardhu_padctrl));
32 }
33
34 #if defined(CONFIG_TEGRA_MMC)
35 /*
36  * Do I2C/PMU writes to bring up SD card bus power
37  *
38  */
39 void board_sdmmc_voltage_init(void)
40 {
41         struct udevice *dev;
42         uchar reg, data_buffer[1];
43         int ret;
44         int i;
45
46         ret = i2c_get_chip_for_busnum(0, PMU_I2C_ADDRESS, &dev);
47         if (ret) {
48                 debug("%s: Cannot find PMIC I2C chip\n", __func__);
49                 return;
50         }
51
52         /* TPS659110: LDO5_REG = 3.3v, ACTIVE to SDMMC1 */
53         data_buffer[0] = 0x65;
54         reg = 0x32;
55
56         for (i = 0; i < MAX_I2C_RETRY; ++i) {
57                 if (i2c_write(dev, reg, data_buffer, 1))
58                         udelay(100);
59         }
60
61         /* TPS659110: GPIO7_REG = PDEN, output a 1 to EN_3V3_SYS */
62         data_buffer[0] = 0x09;
63         reg = 0x67;
64
65         for (i = 0; i < MAX_I2C_RETRY; ++i) {
66                 if (i2c_write(dev, reg, data_buffer, 1))
67                         udelay(100);
68         }
69 }
70
71 /*
72  * Routine: pin_mux_mmc
73  * Description: setup the MMC muxes, power rails, etc.
74  */
75 void pin_mux_mmc(void)
76 {
77         /*
78          * NOTE: We don't do mmc-specific pin muxes here.
79          * They were done globally in pinmux_init().
80          */
81
82         /* Bring up the SDIO1 power rail */
83         board_sdmmc_voltage_init();
84 }
85 #endif  /* MMC */