Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Freescale Semiconductor, Inc. |
| 4 | * Author: Fabio Estevam <fabio.estevam@freescale.com> |
| 5 | * |
Matthias Schiffer | b50ae03 | 2021-11-02 11:36:46 +0100 | [diff] [blame] | 6 | * Copyright (C) 2013, 2014 TQ-Systems (ported SabreSD to TQMa6x) |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 7 | * Author: Markus Niebel <markus.niebel@tq-group.com> |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/mx6-pins.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/iomux.h> |
| 15 | #include <asm/arch/sys_proto.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 16 | #include <env.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 17 | #include <fdt_support.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 19 | #include <linux/errno.h> |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 20 | #include <asm/gpio.h> |
| 21 | #include <asm/io.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 22 | #include <asm/mach-imx/spi.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 23 | #include <fsl_esdhc_imx.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 24 | #include <linux/libfdt.h> |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 25 | #include <mmc.h> |
| 26 | #include <power/pfuze100_pmic.h> |
| 27 | #include <power/pmic.h> |
Stefan Roese | 4630f26 | 2015-08-05 10:50:50 +0200 | [diff] [blame] | 28 | #include <spi_flash.h> |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 29 | |
| 30 | #include "tqma6_bb.h" |
| 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | #define USDHC_CLK_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \ |
| 35 | PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 36 | |
| 37 | #define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \ |
| 38 | PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 39 | |
| 40 | #define GPIO_OUT_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_LOW | \ |
| 41 | PAD_CTL_DSE_40ohm | PAD_CTL_HYS) |
| 42 | |
| 43 | #define GPIO_IN_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_LOW | \ |
| 44 | PAD_CTL_DSE_40ohm | PAD_CTL_HYS) |
| 45 | |
| 46 | #define SPI_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \ |
| 47 | PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 48 | |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 49 | int dram_init(void) |
| 50 | { |
Markus Niebel | a87a783 | 2014-11-18 13:22:57 +0100 | [diff] [blame] | 51 | gd->ram_size = imx_ddr_size(); |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | static const uint16_t tqma6_emmc_dsr = 0x0100; |
| 57 | |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 58 | #ifndef CONFIG_DM_MMC |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 59 | /* eMMC on USDHCI3 always present */ |
| 60 | static iomux_v3_cfg_t const tqma6_usdhc3_pads[] = { |
| 61 | NEW_PAD_CTRL(MX6_PAD_SD3_CLK__SD3_CLK, USDHC_PAD_CTRL), |
| 62 | NEW_PAD_CTRL(MX6_PAD_SD3_CMD__SD3_CMD, USDHC_PAD_CTRL), |
| 63 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT0__SD3_DATA0, USDHC_PAD_CTRL), |
| 64 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT1__SD3_DATA1, USDHC_PAD_CTRL), |
| 65 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT2__SD3_DATA2, USDHC_PAD_CTRL), |
| 66 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT3__SD3_DATA3, USDHC_PAD_CTRL), |
| 67 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT4__SD3_DATA4, USDHC_PAD_CTRL), |
| 68 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT5__SD3_DATA5, USDHC_PAD_CTRL), |
| 69 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT6__SD3_DATA6, USDHC_PAD_CTRL), |
| 70 | NEW_PAD_CTRL(MX6_PAD_SD3_DAT7__SD3_DATA7, USDHC_PAD_CTRL), |
| 71 | /* eMMC reset */ |
| 72 | NEW_PAD_CTRL(MX6_PAD_SD3_RST__SD3_RESET, GPIO_OUT_PAD_CTRL), |
| 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * According to board_mmc_init() the following map is done: |
Bin Meng | 7557405 | 2016-02-05 19:30:11 -0800 | [diff] [blame] | 77 | * (U-Boot device node) (Physical Port) |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 78 | * mmc0 eMMC (SD3) on TQMa6 |
| 79 | * mmc1 .. n optional slots used on baseboard |
| 80 | */ |
| 81 | struct fsl_esdhc_cfg tqma6_usdhc_cfg = { |
| 82 | .esdhc_base = USDHC3_BASE_ADDR, |
| 83 | .max_bus_width = 8, |
| 84 | }; |
| 85 | |
| 86 | int board_mmc_getcd(struct mmc *mmc) |
| 87 | { |
| 88 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 89 | int ret = 0; |
| 90 | |
| 91 | if (cfg->esdhc_base == USDHC3_BASE_ADDR) |
| 92 | /* eMMC/uSDHC3 is always present */ |
| 93 | ret = 1; |
| 94 | else |
| 95 | ret = tqma6_bb_board_mmc_getcd(mmc); |
| 96 | |
| 97 | return ret; |
| 98 | } |
| 99 | |
| 100 | int board_mmc_getwp(struct mmc *mmc) |
| 101 | { |
| 102 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 103 | int ret = 0; |
| 104 | |
| 105 | if (cfg->esdhc_base == USDHC3_BASE_ADDR) |
| 106 | /* eMMC/uSDHC3 is always present */ |
| 107 | ret = 0; |
| 108 | else |
| 109 | ret = tqma6_bb_board_mmc_getwp(mmc); |
| 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 114 | int board_mmc_init(struct bd_info *bis) |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 115 | { |
| 116 | imx_iomux_v3_setup_multiple_pads(tqma6_usdhc3_pads, |
| 117 | ARRAY_SIZE(tqma6_usdhc3_pads)); |
| 118 | tqma6_usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); |
| 119 | if (fsl_esdhc_initialize(bis, &tqma6_usdhc_cfg)) { |
| 120 | puts("Warning: failed to initialize eMMC dev\n"); |
| 121 | } else { |
| 122 | struct mmc *mmc = find_mmc_device(0); |
| 123 | if (mmc) |
| 124 | mmc_set_dsr(mmc, tqma6_emmc_dsr); |
| 125 | } |
| 126 | |
| 127 | tqma6_bb_board_mmc_init(bis); |
| 128 | |
| 129 | return 0; |
| 130 | } |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 131 | #endif |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 132 | |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 133 | #ifndef CONFIG_DM_SPI |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 134 | static iomux_v3_cfg_t const tqma6_ecspi1_pads[] = { |
| 135 | /* SS1 */ |
| 136 | NEW_PAD_CTRL(MX6_PAD_EIM_D19__GPIO3_IO19, SPI_PAD_CTRL), |
| 137 | NEW_PAD_CTRL(MX6_PAD_EIM_D16__ECSPI1_SCLK, SPI_PAD_CTRL), |
| 138 | NEW_PAD_CTRL(MX6_PAD_EIM_D17__ECSPI1_MISO, SPI_PAD_CTRL), |
| 139 | NEW_PAD_CTRL(MX6_PAD_EIM_D18__ECSPI1_MOSI, SPI_PAD_CTRL), |
| 140 | }; |
| 141 | |
Markus Niebel | a116f6f | 2014-10-23 15:47:05 +0200 | [diff] [blame] | 142 | #define TQMA6_SF_CS_GPIO IMX_GPIO_NR(3, 19) |
| 143 | |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 144 | static unsigned const tqma6_ecspi1_cs[] = { |
Markus Niebel | a116f6f | 2014-10-23 15:47:05 +0200 | [diff] [blame] | 145 | TQMA6_SF_CS_GPIO, |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 146 | }; |
| 147 | |
Stefan Roese | d56cb17 | 2015-03-12 13:34:30 +0100 | [diff] [blame] | 148 | __weak void tqma6_iomuxc_spi(void) |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 149 | { |
| 150 | unsigned i; |
| 151 | |
| 152 | for (i = 0; i < ARRAY_SIZE(tqma6_ecspi1_cs); ++i) |
| 153 | gpio_direction_output(tqma6_ecspi1_cs[i], 1); |
| 154 | imx_iomux_v3_setup_multiple_pads(tqma6_ecspi1_pads, |
| 155 | ARRAY_SIZE(tqma6_ecspi1_pads)); |
| 156 | } |
| 157 | |
Patrick Delaunay | c446807 | 2019-02-27 15:20:35 +0100 | [diff] [blame] | 158 | #if defined(CONFIG_SF_DEFAULT_BUS) && defined(CONFIG_SF_DEFAULT_CS) |
Markus Niebel | a116f6f | 2014-10-23 15:47:05 +0200 | [diff] [blame] | 159 | int board_spi_cs_gpio(unsigned bus, unsigned cs) |
| 160 | { |
| 161 | return ((bus == CONFIG_SF_DEFAULT_BUS) && |
| 162 | (cs == CONFIG_SF_DEFAULT_CS)) ? TQMA6_SF_CS_GPIO : -1; |
| 163 | } |
Patrick Delaunay | c446807 | 2019-02-27 15:20:35 +0100 | [diff] [blame] | 164 | #endif |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 165 | #endif |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 166 | |
| 167 | int board_early_init_f(void) |
| 168 | { |
| 169 | return tqma6_bb_board_early_init_f(); |
| 170 | } |
| 171 | |
| 172 | int board_init(void) |
| 173 | { |
| 174 | /* address of boot parameters */ |
| 175 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 176 | |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 177 | #ifndef CONFIG_DM_SPI |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 178 | tqma6_iomuxc_spi(); |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 179 | #endif |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 180 | tqma6_bb_board_init(); |
| 181 | |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | static const char *tqma6_get_boardname(void) |
| 186 | { |
| 187 | u32 cpurev = get_cpu_rev(); |
| 188 | |
| 189 | switch ((cpurev & 0xFF000) >> 12) { |
| 190 | case MXC_CPU_MX6SOLO: |
| 191 | return "TQMa6S"; |
| 192 | break; |
| 193 | case MXC_CPU_MX6DL: |
| 194 | return "TQMa6DL"; |
| 195 | break; |
| 196 | case MXC_CPU_MX6D: |
| 197 | return "TQMa6D"; |
| 198 | break; |
| 199 | case MXC_CPU_MX6Q: |
| 200 | return "TQMa6Q"; |
| 201 | break; |
| 202 | default: |
| 203 | return "??"; |
| 204 | }; |
| 205 | } |
| 206 | |
Fabio Estevam | ba1015b | 2024-08-09 14:58:08 -0300 | [diff] [blame] | 207 | #if CONFIG_IS_ENABLED(DM_PMIC) |
Markus Niebel | 00bb187 | 2017-02-03 16:24:58 +0100 | [diff] [blame] | 208 | /* setup board specific PMIC */ |
| 209 | int power_init_board(void) |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 210 | { |
Fabio Estevam | ba1015b | 2024-08-09 14:58:08 -0300 | [diff] [blame] | 211 | struct udevice *dev; |
Markus Niebel | 00bb187 | 2017-02-03 16:24:58 +0100 | [diff] [blame] | 212 | u32 reg, rev; |
Fabio Estevam | ba1015b | 2024-08-09 14:58:08 -0300 | [diff] [blame] | 213 | int ret; |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 214 | |
Fabio Estevam | ba1015b | 2024-08-09 14:58:08 -0300 | [diff] [blame] | 215 | ret = pmic_get("pmic@8", &dev); |
| 216 | if (ret < 0) |
| 217 | return 0; |
| 218 | |
| 219 | reg = pmic_reg_read(dev, PFUZE100_DEVICEID); |
| 220 | rev = pmic_reg_read(dev, PFUZE100_REVID); |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 221 | |
Fabio Estevam | ba1015b | 2024-08-09 14:58:08 -0300 | [diff] [blame] | 222 | printf("PMIC: PFUZE100 ID=0x%02x REV=0x%02x\n", reg, rev); |
Markus Niebel | 00bb187 | 2017-02-03 16:24:58 +0100 | [diff] [blame] | 223 | return 0; |
| 224 | } |
Michael Krummsdorf | ade873e | 2020-04-09 15:21:41 +0200 | [diff] [blame] | 225 | #endif |
Markus Niebel | 00bb187 | 2017-02-03 16:24:58 +0100 | [diff] [blame] | 226 | |
| 227 | int board_late_init(void) |
| 228 | { |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 229 | env_set("board_name", tqma6_get_boardname()); |
Markus Niebel | 00bb187 | 2017-02-03 16:24:58 +0100 | [diff] [blame] | 230 | |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 231 | tqma6_bb_board_late_init(); |
| 232 | |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 233 | printf("Board: %s on a %s\n", tqma6_get_boardname(), |
| 234 | tqma6_bb_get_boardname()); |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | /* |
| 239 | * Device Tree Support |
| 240 | */ |
| 241 | #if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) |
Markus Niebel | c01ca16 | 2017-02-28 16:37:33 +0100 | [diff] [blame] | 242 | #define MODELSTRLEN 32u |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 243 | int ft_board_setup(void *blob, struct bd_info *bd) |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 244 | { |
Markus Niebel | c01ca16 | 2017-02-28 16:37:33 +0100 | [diff] [blame] | 245 | char modelstr[MODELSTRLEN]; |
| 246 | |
| 247 | snprintf(modelstr, MODELSTRLEN, "TQ %s on %s", tqma6_get_boardname(), |
| 248 | tqma6_bb_get_boardname()); |
| 249 | do_fixup_by_path_string(blob, "/", "model", modelstr); |
| 250 | fdt_fixup_memory(blob, (u64)PHYS_SDRAM, (u64)gd->ram_size); |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 251 | /* bring in eMMC dsr settings */ |
| 252 | do_fixup_by_path_u32(blob, |
| 253 | "/soc/aips-bus@02100000/usdhc@02198000", |
| 254 | "dsr", tqma6_emmc_dsr, 2); |
| 255 | tqma6_bb_ft_board_setup(blob, bd); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 256 | |
| 257 | return 0; |
Markus Niebel | ee2cd2b | 2014-07-18 16:52:44 +0200 | [diff] [blame] | 258 | } |
| 259 | #endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */ |