blob: d7df4f976a2e347a258ede7b40379adc933fae73 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Markus Niebelee2cd2b2014-07-18 16:52:44 +02002/*
3 * Copyright (C) 2012 Freescale Semiconductor, Inc.
4 * Author: Fabio Estevam <fabio.estevam@freescale.com>
5 *
6 * Copyright (C) 2013, 2014 TQ Systems (ported SabreSD to TQMa6x)
7 * Author: Markus Niebel <markus.niebel@tq-group.com>
Markus Niebelee2cd2b2014-07-18 16:52:44 +02008 */
9
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020011#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 Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060017#include <fdt_support.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090018#include <linux/errno.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020019#include <asm/gpio.h>
20#include <asm/io.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/mxc_i2c.h>
22#include <asm/mach-imx/spi.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020023#include <common.h>
Yangbo Lu73340382019-06-21 11:42:28 +080024#include <fsl_esdhc_imx.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090025#include <linux/libfdt.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020026#include <i2c.h>
27#include <mmc.h>
28#include <power/pfuze100_pmic.h>
29#include <power/pmic.h>
Stefan Roese4630f262015-08-05 10:50:50 +020030#include <spi_flash.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020031
32#include "tqma6_bb.h"
33
34DECLARE_GLOBAL_DATA_PTR;
35
36#define USDHC_CLK_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
37 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
38
39#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
40 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
41
42#define GPIO_OUT_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_LOW | \
43 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
44
45#define GPIO_IN_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_LOW | \
46 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
47
48#define SPI_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
49 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
50
51#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
Markus Niebel28a49532017-02-03 16:24:59 +010052 PAD_CTL_DSE_80ohm | PAD_CTL_HYS | \
Markus Niebelee2cd2b2014-07-18 16:52:44 +020053 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
54
55int dram_init(void)
56{
Markus Niebela87a7832014-11-18 13:22:57 +010057 gd->ram_size = imx_ddr_size();
Markus Niebelee2cd2b2014-07-18 16:52:44 +020058
59 return 0;
60}
61
62static const uint16_t tqma6_emmc_dsr = 0x0100;
63
Michael Krummsdorfade873e2020-04-09 15:21:41 +020064#ifndef CONFIG_DM_MMC
Markus Niebelee2cd2b2014-07-18 16:52:44 +020065/* eMMC on USDHCI3 always present */
66static iomux_v3_cfg_t const tqma6_usdhc3_pads[] = {
67 NEW_PAD_CTRL(MX6_PAD_SD3_CLK__SD3_CLK, USDHC_PAD_CTRL),
68 NEW_PAD_CTRL(MX6_PAD_SD3_CMD__SD3_CMD, USDHC_PAD_CTRL),
69 NEW_PAD_CTRL(MX6_PAD_SD3_DAT0__SD3_DATA0, USDHC_PAD_CTRL),
70 NEW_PAD_CTRL(MX6_PAD_SD3_DAT1__SD3_DATA1, USDHC_PAD_CTRL),
71 NEW_PAD_CTRL(MX6_PAD_SD3_DAT2__SD3_DATA2, USDHC_PAD_CTRL),
72 NEW_PAD_CTRL(MX6_PAD_SD3_DAT3__SD3_DATA3, USDHC_PAD_CTRL),
73 NEW_PAD_CTRL(MX6_PAD_SD3_DAT4__SD3_DATA4, USDHC_PAD_CTRL),
74 NEW_PAD_CTRL(MX6_PAD_SD3_DAT5__SD3_DATA5, USDHC_PAD_CTRL),
75 NEW_PAD_CTRL(MX6_PAD_SD3_DAT6__SD3_DATA6, USDHC_PAD_CTRL),
76 NEW_PAD_CTRL(MX6_PAD_SD3_DAT7__SD3_DATA7, USDHC_PAD_CTRL),
77 /* eMMC reset */
78 NEW_PAD_CTRL(MX6_PAD_SD3_RST__SD3_RESET, GPIO_OUT_PAD_CTRL),
79};
80
81/*
82 * According to board_mmc_init() the following map is done:
Bin Meng75574052016-02-05 19:30:11 -080083 * (U-Boot device node) (Physical Port)
Markus Niebelee2cd2b2014-07-18 16:52:44 +020084 * mmc0 eMMC (SD3) on TQMa6
85 * mmc1 .. n optional slots used on baseboard
86 */
87struct fsl_esdhc_cfg tqma6_usdhc_cfg = {
88 .esdhc_base = USDHC3_BASE_ADDR,
89 .max_bus_width = 8,
90};
91
92int board_mmc_getcd(struct mmc *mmc)
93{
94 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
95 int ret = 0;
96
97 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
98 /* eMMC/uSDHC3 is always present */
99 ret = 1;
100 else
101 ret = tqma6_bb_board_mmc_getcd(mmc);
102
103 return ret;
104}
105
106int board_mmc_getwp(struct mmc *mmc)
107{
108 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
109 int ret = 0;
110
111 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
112 /* eMMC/uSDHC3 is always present */
113 ret = 0;
114 else
115 ret = tqma6_bb_board_mmc_getwp(mmc);
116
117 return ret;
118}
119
120int board_mmc_init(bd_t *bis)
121{
122 imx_iomux_v3_setup_multiple_pads(tqma6_usdhc3_pads,
123 ARRAY_SIZE(tqma6_usdhc3_pads));
124 tqma6_usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
125 if (fsl_esdhc_initialize(bis, &tqma6_usdhc_cfg)) {
126 puts("Warning: failed to initialize eMMC dev\n");
127 } else {
128 struct mmc *mmc = find_mmc_device(0);
129 if (mmc)
130 mmc_set_dsr(mmc, tqma6_emmc_dsr);
131 }
132
133 tqma6_bb_board_mmc_init(bis);
134
135 return 0;
136}
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200137#endif
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200138
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200139#ifndef CONFIG_DM_SPI
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200140static iomux_v3_cfg_t const tqma6_ecspi1_pads[] = {
141 /* SS1 */
142 NEW_PAD_CTRL(MX6_PAD_EIM_D19__GPIO3_IO19, SPI_PAD_CTRL),
143 NEW_PAD_CTRL(MX6_PAD_EIM_D16__ECSPI1_SCLK, SPI_PAD_CTRL),
144 NEW_PAD_CTRL(MX6_PAD_EIM_D17__ECSPI1_MISO, SPI_PAD_CTRL),
145 NEW_PAD_CTRL(MX6_PAD_EIM_D18__ECSPI1_MOSI, SPI_PAD_CTRL),
146};
147
Markus Niebela116f6f2014-10-23 15:47:05 +0200148#define TQMA6_SF_CS_GPIO IMX_GPIO_NR(3, 19)
149
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200150static unsigned const tqma6_ecspi1_cs[] = {
Markus Niebela116f6f2014-10-23 15:47:05 +0200151 TQMA6_SF_CS_GPIO,
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200152};
153
Stefan Roesed56cb172015-03-12 13:34:30 +0100154__weak void tqma6_iomuxc_spi(void)
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200155{
156 unsigned i;
157
158 for (i = 0; i < ARRAY_SIZE(tqma6_ecspi1_cs); ++i)
159 gpio_direction_output(tqma6_ecspi1_cs[i], 1);
160 imx_iomux_v3_setup_multiple_pads(tqma6_ecspi1_pads,
161 ARRAY_SIZE(tqma6_ecspi1_pads));
162}
163
Patrick Delaunayc4468072019-02-27 15:20:35 +0100164#if defined(CONFIG_SF_DEFAULT_BUS) && defined(CONFIG_SF_DEFAULT_CS)
Markus Niebela116f6f2014-10-23 15:47:05 +0200165int board_spi_cs_gpio(unsigned bus, unsigned cs)
166{
167 return ((bus == CONFIG_SF_DEFAULT_BUS) &&
168 (cs == CONFIG_SF_DEFAULT_CS)) ? TQMA6_SF_CS_GPIO : -1;
169}
Patrick Delaunayc4468072019-02-27 15:20:35 +0100170#endif
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200171#endif
Markus Niebela116f6f2014-10-23 15:47:05 +0200172
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200173#ifdef CONFIG_SYS_I2C
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200174static struct i2c_pads_info tqma6_i2c3_pads = {
175 /* I2C3: on board LM75, M24C64, */
176 .scl = {
177 .i2c_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_5__I2C3_SCL,
178 I2C_PAD_CTRL),
179 .gpio_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_5__GPIO1_IO05,
180 I2C_PAD_CTRL),
181 .gp = IMX_GPIO_NR(1, 5)
182 },
183 .sda = {
184 .i2c_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_6__I2C3_SDA,
185 I2C_PAD_CTRL),
186 .gpio_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_6__GPIO1_IO06,
187 I2C_PAD_CTRL),
188 .gp = IMX_GPIO_NR(1, 6)
189 }
190};
191
192static void tqma6_setup_i2c(void)
193{
Markus Niebel1184ac32014-11-18 13:22:56 +0100194 int ret;
195 /*
196 * use logical index for bus, e.g. I2C1 -> 0
197 * warn on error
198 */
199 ret = setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &tqma6_i2c3_pads);
200 if (ret)
201 printf("setup I2C3 failed: %d\n", ret);
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200202}
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200203#endif
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200204
205int board_early_init_f(void)
206{
207 return tqma6_bb_board_early_init_f();
208}
209
210int board_init(void)
211{
212 /* address of boot parameters */
213 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
214
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200215#ifndef CONFIG_DM_SPI
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200216 tqma6_iomuxc_spi();
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200217#endif
218#ifdef CONFIG_SYS_I2C
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200219 tqma6_setup_i2c();
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200220#endif
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200221
222 tqma6_bb_board_init();
223
224 return 0;
225}
226
227static const char *tqma6_get_boardname(void)
228{
229 u32 cpurev = get_cpu_rev();
230
231 switch ((cpurev & 0xFF000) >> 12) {
232 case MXC_CPU_MX6SOLO:
233 return "TQMa6S";
234 break;
235 case MXC_CPU_MX6DL:
236 return "TQMa6DL";
237 break;
238 case MXC_CPU_MX6D:
239 return "TQMa6D";
240 break;
241 case MXC_CPU_MX6Q:
242 return "TQMa6Q";
243 break;
244 default:
245 return "??";
246 };
247}
248
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200249#ifdef CONFIG_POWER
Markus Niebel00bb1872017-02-03 16:24:58 +0100250/* setup board specific PMIC */
251int power_init_board(void)
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200252{
253 struct pmic *p;
Markus Niebel00bb1872017-02-03 16:24:58 +0100254 u32 reg, rev;
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200255
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200256 power_pfuze100_init(TQMA6_PFUZE100_I2C_BUS);
Fabio Estevamb96df4f2014-08-01 08:50:03 -0300257 p = pmic_get("PFUZE100");
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200258 if (p && !pmic_probe(p)) {
259 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
Markus Niebel00bb1872017-02-03 16:24:58 +0100260 pmic_reg_read(p, PFUZE100_REVID, &rev);
261 printf("PMIC: PFUZE100 ID=0x%02x REV=0x%02x\n", reg, rev);
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200262 }
263
Markus Niebel00bb1872017-02-03 16:24:58 +0100264 return 0;
265}
Michael Krummsdorfade873e2020-04-09 15:21:41 +0200266#endif
Markus Niebel00bb1872017-02-03 16:24:58 +0100267
268int board_late_init(void)
269{
Simon Glass6a38e412017-08-03 12:22:09 -0600270 env_set("board_name", tqma6_get_boardname());
Markus Niebel00bb1872017-02-03 16:24:58 +0100271
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200272 tqma6_bb_board_late_init();
273
274 return 0;
275}
276
277int checkboard(void)
278{
279 printf("Board: %s on a %s\n", tqma6_get_boardname(),
280 tqma6_bb_get_boardname());
281 return 0;
282}
283
284/*
285 * Device Tree Support
286 */
287#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
Markus Niebelc01ca162017-02-28 16:37:33 +0100288#define MODELSTRLEN 32u
Simon Glass2aec3cc2014-10-23 18:58:47 -0600289int ft_board_setup(void *blob, bd_t *bd)
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200290{
Markus Niebelc01ca162017-02-28 16:37:33 +0100291 char modelstr[MODELSTRLEN];
292
293 snprintf(modelstr, MODELSTRLEN, "TQ %s on %s", tqma6_get_boardname(),
294 tqma6_bb_get_boardname());
295 do_fixup_by_path_string(blob, "/", "model", modelstr);
296 fdt_fixup_memory(blob, (u64)PHYS_SDRAM, (u64)gd->ram_size);
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200297 /* bring in eMMC dsr settings */
298 do_fixup_by_path_u32(blob,
299 "/soc/aips-bus@02100000/usdhc@02198000",
300 "dsr", tqma6_emmc_dsr, 2);
301 tqma6_bb_ft_board_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600302
303 return 0;
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200304}
305#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */