]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/samsung/goni/goni.c
arm:goni:mmc: Add sd card detection and initialization.
[karo-tx-uboot.git] / board / samsung / goni / goni.c
1 /*
2  *  Copyright (C) 2008-2009 Samsung Electronics
3  *  Minkyu Kang <mk7.kang@samsung.com>
4  *  Kyungmin Park <kyungmin.park@samsung.com>
5  *
6  * SPDX-License-Identifier:     GPL-2.0+
7  */
8
9 #include <common.h>
10 #include <asm/arch/gpio.h>
11 #include <asm/arch/mmc.h>
12 #include <power/pmic.h>
13 #include <usb/s3c_udc.h>
14 #include <asm/arch/cpu.h>
15 #include <power/max8998_pmic.h>
16 DECLARE_GLOBAL_DATA_PTR;
17
18 static struct s5pc110_gpio *s5pc110_gpio;
19
20 int board_init(void)
21 {
22         /* Set Initial global variables */
23         s5pc110_gpio = (struct s5pc110_gpio *)S5PC110_GPIO_BASE;
24
25         gd->bd->bi_arch_number = MACH_TYPE_GONI;
26         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
27
28         return 0;
29 }
30
31 int power_init_board(void)
32 {
33         int ret;
34
35         ret = pmic_init(I2C_5);
36         if (ret)
37                 return ret;
38
39         return 0;
40 }
41
42 int dram_init(void)
43 {
44         gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE +
45                         PHYS_SDRAM_3_SIZE;
46
47         return 0;
48 }
49
50 void dram_init_banksize(void)
51 {
52         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
53         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
54         gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
55         gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
56         gd->bd->bi_dram[2].start = PHYS_SDRAM_3;
57         gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE;
58 }
59
60 #ifdef CONFIG_DISPLAY_BOARDINFO
61 int checkboard(void)
62 {
63         puts("Board:\tGoni\n");
64         return 0;
65 }
66 #endif
67
68 #ifdef CONFIG_GENERIC_MMC
69 int board_mmc_init(bd_t *bis)
70 {
71         int i, ret, ret_sd = 0;
72
73         /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */
74         s5p_gpio_direction_output(&s5pc110_gpio->j2, 7, 1);
75
76         /*
77          * MMC0 GPIO
78          * GPG0[0]      SD_0_CLK
79          * GPG0[1]      SD_0_CMD
80          * GPG0[2]      SD_0_CDn        -> Not used
81          * GPG0[3:6]    SD_0_DATA[0:3]
82          */
83         for (i = 0; i < 7; i++) {
84                 if (i == 2)
85                         continue;
86                 /* GPG0[0:6] special function 2 */
87                 s5p_gpio_cfg_pin(&s5pc110_gpio->g0, i, 0x2);
88                 /* GPG0[0:6] pull disable */
89                 s5p_gpio_set_pull(&s5pc110_gpio->g0, i, GPIO_PULL_NONE);
90                 /* GPG0[0:6] drv 4x */
91                 s5p_gpio_set_drv(&s5pc110_gpio->g0, i, GPIO_DRV_4X);
92         }
93
94         ret = s5p_mmc_init(0, 4);
95         if (ret)
96                 error("MMC: Failed to init MMC:0.\n");
97
98         /*
99          * SD card (T_FLASH) detect and init
100          * T_FLASH_DETECT: EINT28: GPH3[4] input mode
101          */
102         s5p_gpio_cfg_pin(&s5pc110_gpio->h3, 4, GPIO_INPUT);
103         s5p_gpio_set_pull(&s5pc110_gpio->h3, 4, GPIO_PULL_UP);
104
105         if (!s5p_gpio_get_value(&s5pc110_gpio->h3, 4)) {
106                 for (i = 0; i < 7; i++) {
107                         if (i == 2)
108                                 continue;
109
110                         /* GPG2[0:6] special function 2 */
111                         s5p_gpio_cfg_pin(&s5pc110_gpio->g2, i, 0x2);
112                         /* GPG2[0:6] pull disable */
113                         s5p_gpio_set_pull(&s5pc110_gpio->g2, i, GPIO_PULL_NONE);
114                         /* GPG2[0:6] drv 4x */
115                         s5p_gpio_set_drv(&s5pc110_gpio->g2, i, GPIO_DRV_4X);
116                 }
117
118                 ret_sd = s5p_mmc_init(2, 4);
119                 if (ret_sd)
120                         error("MMC: Failed to init SD card (MMC:2).\n");
121         }
122
123         return ret & ret_sd;
124 }
125 #endif
126
127 #ifdef CONFIG_USB_GADGET
128 static int s5pc1xx_phy_control(int on)
129 {
130         int ret;
131         static int status;
132         struct pmic *p = pmic_get("MAX8998_PMIC");
133         if (!p)
134                 return -ENODEV;
135
136         if (pmic_probe(p))
137                 return -1;
138
139         if (on && !status) {
140                 ret = pmic_set_output(p, MAX8998_REG_ONOFF1,
141                                       MAX8998_LDO3, LDO_ON);
142                 ret = pmic_set_output(p, MAX8998_REG_ONOFF2,
143                                       MAX8998_LDO8, LDO_ON);
144                 if (ret) {
145                         puts("MAX8998 LDO setting error!\n");
146                         return -1;
147                 }
148                 status = 1;
149         } else if (!on && status) {
150                 ret = pmic_set_output(p, MAX8998_REG_ONOFF1,
151                                       MAX8998_LDO3, LDO_OFF);
152                 ret = pmic_set_output(p, MAX8998_REG_ONOFF2,
153                                       MAX8998_LDO8, LDO_OFF);
154                 if (ret) {
155                         puts("MAX8998 LDO setting error!\n");
156                         return -1;
157                 }
158                 status = 0;
159         }
160         udelay(10000);
161
162         return 0;
163 }
164
165 struct s3c_plat_otg_data s5pc110_otg_data = {
166         .phy_control = s5pc1xx_phy_control,
167         .regs_phy = S5PC110_PHY_BASE,
168         .regs_otg = S5PC110_OTG_BASE,
169         .usb_phy_ctrl = S5PC110_USB_PHY_CONTROL,
170 };
171 #endif