Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2008-2009 Samsung Electronics |
| 4 | * Minkyu Kang <mk7.kang@samsung.com> |
| 5 | * Kyungmin Park <kyungmin.park@samsung.com> |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Simon Glass | 37f1162 | 2014-10-20 19:48:37 -0600 | [diff] [blame] | 11 | #include <asm/gpio.h> |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 12 | #include <asm/arch/mmc.h> |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 13 | #include <dm.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 15 | #include <linux/printk.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 16 | #include <power/pmic.h> |
Marek Vasut | f1be9cb | 2015-12-04 02:51:20 +0100 | [diff] [blame] | 17 | #include <usb/dwc2_udc.h> |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 18 | #include <asm/arch/cpu.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 19 | #include <power/max8998_pmic.h> |
Piotr Wilczek | c88b89e | 2014-01-22 15:54:33 +0100 | [diff] [blame] | 20 | #include <samsung/misc.h> |
Mateusz Zalega | 381709a | 2014-04-28 21:13:30 +0200 | [diff] [blame] | 21 | #include <usb.h> |
| 22 | #include <usb_mass_storage.h> |
Simon Glass | 0ffb9d6 | 2017-05-31 19:47:48 -0600 | [diff] [blame] | 23 | #include <asm/mach-types.h> |
Piotr Wilczek | c88b89e | 2014-01-22 15:54:33 +0100 | [diff] [blame] | 24 | |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | int board_init(void) |
| 28 | { |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 29 | /* Set Initial global variables */ |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 30 | gd->bd->bi_arch_number = MACH_TYPE_GONI; |
| 31 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 32 | |
Łukasz Majewski | 0fcc9a5 | 2012-11-13 03:22:16 +0000 | [diff] [blame] | 33 | return 0; |
| 34 | } |
| 35 | |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 36 | int dram_init(void) |
| 37 | { |
Minkyu Kang | 00ab176 | 2010-11-22 20:27:44 +0900 | [diff] [blame] | 38 | gd->ram_size = PHYS_SDRAM_1_SIZE + PHYS_SDRAM_2_SIZE + |
| 39 | PHYS_SDRAM_3_SIZE; |
| 40 | |
| 41 | return 0; |
| 42 | } |
| 43 | |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 44 | int dram_init_banksize(void) |
Minkyu Kang | 00ab176 | 2010-11-22 20:27:44 +0900 | [diff] [blame] | 45 | { |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 46 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 47 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 48 | gd->bd->bi_dram[1].start = PHYS_SDRAM_2; |
| 49 | gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE; |
| 50 | gd->bd->bi_dram[2].start = PHYS_SDRAM_3; |
| 51 | gd->bd->bi_dram[2].size = PHYS_SDRAM_3_SIZE; |
Simon Glass | 2f949c3 | 2017-03-31 08:40:32 -0600 | [diff] [blame] | 52 | |
| 53 | return 0; |
Minkyu Kang | 194cbce | 2010-05-31 22:02:42 +0900 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | #ifdef CONFIG_DISPLAY_BOARDINFO |
| 57 | int checkboard(void) |
| 58 | { |
| 59 | puts("Board:\tGoni\n"); |
| 60 | return 0; |
| 61 | } |
| 62 | #endif |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 63 | |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 64 | #ifdef CONFIG_MMC |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 65 | int board_mmc_init(struct bd_info *bis) |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 66 | { |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 67 | int i, ret, ret_sd = 0; |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 68 | |
| 69 | /* MASSMEMORY_EN: XMSMDATA7: GPJ2[7] output high */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 70 | gpio_request(S5PC110_GPIO_J27, "massmemory_en"); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 71 | gpio_direction_output(S5PC110_GPIO_J27, 1); |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 72 | |
| 73 | /* |
| 74 | * MMC0 GPIO |
| 75 | * GPG0[0] SD_0_CLK |
| 76 | * GPG0[1] SD_0_CMD |
| 77 | * GPG0[2] SD_0_CDn -> Not used |
| 78 | * GPG0[3:6] SD_0_DATA[0:3] |
| 79 | */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 80 | for (i = S5PC110_GPIO_G00; i < S5PC110_GPIO_G07; i++) { |
| 81 | if (i == S5PC110_GPIO_G02) |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 82 | continue; |
| 83 | /* GPG0[0:6] special function 2 */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 84 | gpio_cfg_pin(i, 0x2); |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 85 | /* GPG0[0:6] pull disable */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 86 | gpio_set_pull(i, S5P_GPIO_PULL_NONE); |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 87 | /* GPG0[0:6] drv 4x */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 88 | gpio_set_drv(i, S5P_GPIO_DRV_4X); |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 89 | } |
| 90 | |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 91 | ret = s5p_mmc_init(0, 4); |
| 92 | if (ret) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 93 | pr_err("MMC: Failed to init MMC:0.\n"); |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 94 | |
| 95 | /* |
| 96 | * SD card (T_FLASH) detect and init |
| 97 | * T_FLASH_DETECT: EINT28: GPH3[4] input mode |
| 98 | */ |
Simon Glass | 4f83d3d | 2014-10-20 19:48:39 -0600 | [diff] [blame] | 99 | gpio_request(S5PC110_GPIO_H34, "t_flash_detect"); |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 100 | gpio_cfg_pin(S5PC110_GPIO_H34, S5P_GPIO_INPUT); |
| 101 | gpio_set_pull(S5PC110_GPIO_H34, S5P_GPIO_PULL_UP); |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 102 | |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 103 | if (!gpio_get_value(S5PC110_GPIO_H34)) { |
| 104 | for (i = S5PC110_GPIO_G20; i < S5PC110_GPIO_G27; i++) { |
| 105 | if (i == S5PC110_GPIO_G22) |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 106 | continue; |
| 107 | |
| 108 | /* GPG2[0:6] special function 2 */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 109 | gpio_cfg_pin(i, 0x2); |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 110 | /* GPG2[0:6] pull disable */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 111 | gpio_set_pull(i, S5P_GPIO_PULL_NONE); |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 112 | /* GPG2[0:6] drv 4x */ |
Akshay Saraswat | 1376cdd | 2014-05-13 10:30:14 +0530 | [diff] [blame] | 113 | gpio_set_drv(i, S5P_GPIO_DRV_4X); |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | ret_sd = s5p_mmc_init(2, 4); |
| 117 | if (ret_sd) |
Masahiro Yamada | 81e1042 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 118 | pr_err("MMC: Failed to init SD card (MMC:2).\n"); |
Przemyslaw Marczak | 151d23f | 2013-09-10 11:34:49 +0200 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return ret & ret_sd; |
Minkyu Kang | 2111b2d | 2010-07-06 20:58:41 +0900 | [diff] [blame] | 122 | } |
| 123 | #endif |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 124 | |
| 125 | #ifdef CONFIG_USB_GADGET |
| 126 | static int s5pc1xx_phy_control(int on) |
| 127 | { |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 128 | struct udevice *dev; |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 129 | static int status; |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 130 | int reg, ret; |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 131 | |
Jaehoon Chung | 5026af6 | 2017-01-05 16:55:14 +0900 | [diff] [blame] | 132 | ret = pmic_get("max8998-pmic", &dev); |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 133 | if (ret) |
| 134 | return ret; |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 135 | |
| 136 | if (on && !status) { |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 137 | reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1); |
| 138 | reg |= MAX8998_LDO3; |
| 139 | ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg); |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 140 | if (ret) { |
| 141 | puts("MAX8998 LDO setting error!\n"); |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 142 | return -EINVAL; |
| 143 | } |
| 144 | |
| 145 | reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2); |
| 146 | reg |= MAX8998_LDO8; |
| 147 | ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg); |
| 148 | if (ret) { |
| 149 | puts("MAX8998 LDO setting error!\n"); |
| 150 | return -EINVAL; |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 151 | } |
| 152 | status = 1; |
| 153 | } else if (!on && status) { |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 154 | reg = pmic_reg_read(dev, MAX8998_REG_ONOFF1); |
| 155 | reg &= ~MAX8998_LDO3; |
| 156 | ret = pmic_reg_write(dev, MAX8998_REG_ONOFF1, reg); |
| 157 | if (ret) { |
| 158 | puts("MAX8998 LDO setting error!\n"); |
| 159 | return -EINVAL; |
| 160 | } |
| 161 | |
| 162 | reg = pmic_reg_read(dev, MAX8998_REG_ONOFF2); |
| 163 | reg &= ~MAX8998_LDO8; |
| 164 | ret = pmic_reg_write(dev, MAX8998_REG_ONOFF2, reg); |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 165 | if (ret) { |
| 166 | puts("MAX8998 LDO setting error!\n"); |
Jaehoon Chung | e892d60 | 2017-01-03 09:43:28 +0900 | [diff] [blame] | 167 | return -EINVAL; |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 168 | } |
| 169 | status = 0; |
| 170 | } |
| 171 | udelay(10000); |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | |
Marek Vasut | 6939aca | 2015-12-04 02:23:29 +0100 | [diff] [blame] | 175 | struct dwc2_plat_otg_data s5pc110_otg_data = { |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 176 | .phy_control = s5pc1xx_phy_control, |
| 177 | .regs_phy = S5PC110_PHY_BASE, |
| 178 | .regs_otg = S5PC110_OTG_BASE, |
| 179 | .usb_phy_ctrl = S5PC110_USB_PHY_CONTROL, |
| 180 | }; |
Mateusz Zalega | 381709a | 2014-04-28 21:13:30 +0200 | [diff] [blame] | 181 | |
| 182 | int board_usb_init(int index, enum usb_init_type init) |
| 183 | { |
| 184 | debug("USB_udc_probe\n"); |
Marek Vasut | 01b61fa | 2015-12-04 02:26:33 +0100 | [diff] [blame] | 185 | return dwc2_udc_probe(&s5pc110_otg_data); |
Mateusz Zalega | 381709a | 2014-04-28 21:13:30 +0200 | [diff] [blame] | 186 | } |
Lukasz Majewski | 35be850 | 2011-10-27 10:36:47 +0200 | [diff] [blame] | 187 | #endif |
Piotr Wilczek | c88b89e | 2014-01-22 15:54:33 +0100 | [diff] [blame] | 188 | |
| 189 | #ifdef CONFIG_MISC_INIT_R |
| 190 | int misc_init_r(void) |
| 191 | { |
| 192 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 193 | set_board_info(); |
| 194 | #endif |
| 195 | return 0; |
| 196 | } |
| 197 | #endif |
Lukasz Majewski | 3de2570 | 2015-03-03 17:32:04 +0100 | [diff] [blame] | 198 | |
| 199 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 200 | { |
| 201 | return 0; |
| 202 | } |