blob: 816672edc6b808849a5772534dcc893fbc04566e [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
10#include <asm/arch/clock.h>
11#include <asm/arch/mx6-pins.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/iomux.h>
14#include <asm/arch/sys_proto.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020016#include <asm/gpio.h>
17#include <asm/io.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/mxc_i2c.h>
19#include <asm/mach-imx/spi.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020020#include <common.h>
21#include <fsl_esdhc.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090022#include <linux/libfdt.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020023#include <i2c.h>
24#include <mmc.h>
25#include <power/pfuze100_pmic.h>
26#include <power/pmic.h>
Stefan Roese4630f262015-08-05 10:50:50 +020027#include <spi_flash.h>
Markus Niebelee2cd2b2014-07-18 16:52:44 +020028
29#include "tqma6_bb.h"
30
31DECLARE_GLOBAL_DATA_PTR;
32
33#define USDHC_CLK_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
34 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
35
36#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW | \
37 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
38
39#define GPIO_OUT_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_LOW | \
40 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
41
42#define GPIO_IN_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_LOW | \
43 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
44
45#define SPI_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
46 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
47
48#define I2C_PAD_CTRL (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
Markus Niebel28a49532017-02-03 16:24:59 +010049 PAD_CTL_DSE_80ohm | PAD_CTL_HYS | \
Markus Niebelee2cd2b2014-07-18 16:52:44 +020050 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
51
52int dram_init(void)
53{
Markus Niebela87a7832014-11-18 13:22:57 +010054 gd->ram_size = imx_ddr_size();
Markus Niebelee2cd2b2014-07-18 16:52:44 +020055
56 return 0;
57}
58
59static const uint16_t tqma6_emmc_dsr = 0x0100;
60
61/* eMMC on USDHCI3 always present */
62static iomux_v3_cfg_t const tqma6_usdhc3_pads[] = {
63 NEW_PAD_CTRL(MX6_PAD_SD3_CLK__SD3_CLK, USDHC_PAD_CTRL),
64 NEW_PAD_CTRL(MX6_PAD_SD3_CMD__SD3_CMD, USDHC_PAD_CTRL),
65 NEW_PAD_CTRL(MX6_PAD_SD3_DAT0__SD3_DATA0, USDHC_PAD_CTRL),
66 NEW_PAD_CTRL(MX6_PAD_SD3_DAT1__SD3_DATA1, USDHC_PAD_CTRL),
67 NEW_PAD_CTRL(MX6_PAD_SD3_DAT2__SD3_DATA2, USDHC_PAD_CTRL),
68 NEW_PAD_CTRL(MX6_PAD_SD3_DAT3__SD3_DATA3, USDHC_PAD_CTRL),
69 NEW_PAD_CTRL(MX6_PAD_SD3_DAT4__SD3_DATA4, USDHC_PAD_CTRL),
70 NEW_PAD_CTRL(MX6_PAD_SD3_DAT5__SD3_DATA5, USDHC_PAD_CTRL),
71 NEW_PAD_CTRL(MX6_PAD_SD3_DAT6__SD3_DATA6, USDHC_PAD_CTRL),
72 NEW_PAD_CTRL(MX6_PAD_SD3_DAT7__SD3_DATA7, USDHC_PAD_CTRL),
73 /* eMMC reset */
74 NEW_PAD_CTRL(MX6_PAD_SD3_RST__SD3_RESET, GPIO_OUT_PAD_CTRL),
75};
76
77/*
78 * According to board_mmc_init() the following map is done:
Bin Meng75574052016-02-05 19:30:11 -080079 * (U-Boot device node) (Physical Port)
Markus Niebelee2cd2b2014-07-18 16:52:44 +020080 * mmc0 eMMC (SD3) on TQMa6
81 * mmc1 .. n optional slots used on baseboard
82 */
83struct fsl_esdhc_cfg tqma6_usdhc_cfg = {
84 .esdhc_base = USDHC3_BASE_ADDR,
85 .max_bus_width = 8,
86};
87
88int board_mmc_getcd(struct mmc *mmc)
89{
90 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
91 int ret = 0;
92
93 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
94 /* eMMC/uSDHC3 is always present */
95 ret = 1;
96 else
97 ret = tqma6_bb_board_mmc_getcd(mmc);
98
99 return ret;
100}
101
102int board_mmc_getwp(struct mmc *mmc)
103{
104 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
105 int ret = 0;
106
107 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
108 /* eMMC/uSDHC3 is always present */
109 ret = 0;
110 else
111 ret = tqma6_bb_board_mmc_getwp(mmc);
112
113 return ret;
114}
115
116int board_mmc_init(bd_t *bis)
117{
118 imx_iomux_v3_setup_multiple_pads(tqma6_usdhc3_pads,
119 ARRAY_SIZE(tqma6_usdhc3_pads));
120 tqma6_usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
121 if (fsl_esdhc_initialize(bis, &tqma6_usdhc_cfg)) {
122 puts("Warning: failed to initialize eMMC dev\n");
123 } else {
124 struct mmc *mmc = find_mmc_device(0);
125 if (mmc)
126 mmc_set_dsr(mmc, tqma6_emmc_dsr);
127 }
128
129 tqma6_bb_board_mmc_init(bis);
130
131 return 0;
132}
133
134static 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 Niebela116f6f2014-10-23 15:47:05 +0200142#define TQMA6_SF_CS_GPIO IMX_GPIO_NR(3, 19)
143
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200144static unsigned const tqma6_ecspi1_cs[] = {
Markus Niebela116f6f2014-10-23 15:47:05 +0200145 TQMA6_SF_CS_GPIO,
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200146};
147
Stefan Roesed56cb172015-03-12 13:34:30 +0100148__weak void tqma6_iomuxc_spi(void)
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200149{
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
Markus Niebela116f6f2014-10-23 15:47:05 +0200158int board_spi_cs_gpio(unsigned bus, unsigned cs)
159{
160 return ((bus == CONFIG_SF_DEFAULT_BUS) &&
161 (cs == CONFIG_SF_DEFAULT_CS)) ? TQMA6_SF_CS_GPIO : -1;
162}
163
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200164static struct i2c_pads_info tqma6_i2c3_pads = {
165 /* I2C3: on board LM75, M24C64, */
166 .scl = {
167 .i2c_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_5__I2C3_SCL,
168 I2C_PAD_CTRL),
169 .gpio_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_5__GPIO1_IO05,
170 I2C_PAD_CTRL),
171 .gp = IMX_GPIO_NR(1, 5)
172 },
173 .sda = {
174 .i2c_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_6__I2C3_SDA,
175 I2C_PAD_CTRL),
176 .gpio_mode = NEW_PAD_CTRL(MX6_PAD_GPIO_6__GPIO1_IO06,
177 I2C_PAD_CTRL),
178 .gp = IMX_GPIO_NR(1, 6)
179 }
180};
181
182static void tqma6_setup_i2c(void)
183{
Markus Niebel1184ac32014-11-18 13:22:56 +0100184 int ret;
185 /*
186 * use logical index for bus, e.g. I2C1 -> 0
187 * warn on error
188 */
189 ret = setup_i2c(2, CONFIG_SYS_I2C_SPEED, 0x7f, &tqma6_i2c3_pads);
190 if (ret)
191 printf("setup I2C3 failed: %d\n", ret);
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200192}
193
194int board_early_init_f(void)
195{
196 return tqma6_bb_board_early_init_f();
197}
198
199int board_init(void)
200{
201 /* address of boot parameters */
202 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
203
204 tqma6_iomuxc_spi();
205 tqma6_setup_i2c();
206
207 tqma6_bb_board_init();
208
209 return 0;
210}
211
212static const char *tqma6_get_boardname(void)
213{
214 u32 cpurev = get_cpu_rev();
215
216 switch ((cpurev & 0xFF000) >> 12) {
217 case MXC_CPU_MX6SOLO:
218 return "TQMa6S";
219 break;
220 case MXC_CPU_MX6DL:
221 return "TQMa6DL";
222 break;
223 case MXC_CPU_MX6D:
224 return "TQMa6D";
225 break;
226 case MXC_CPU_MX6Q:
227 return "TQMa6Q";
228 break;
229 default:
230 return "??";
231 };
232}
233
Markus Niebel00bb1872017-02-03 16:24:58 +0100234/* setup board specific PMIC */
235int power_init_board(void)
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200236{
237 struct pmic *p;
Markus Niebel00bb1872017-02-03 16:24:58 +0100238 u32 reg, rev;
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200239
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200240 power_pfuze100_init(TQMA6_PFUZE100_I2C_BUS);
Fabio Estevamb96df4f2014-08-01 08:50:03 -0300241 p = pmic_get("PFUZE100");
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200242 if (p && !pmic_probe(p)) {
243 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
Markus Niebel00bb1872017-02-03 16:24:58 +0100244 pmic_reg_read(p, PFUZE100_REVID, &rev);
245 printf("PMIC: PFUZE100 ID=0x%02x REV=0x%02x\n", reg, rev);
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200246 }
247
Markus Niebel00bb1872017-02-03 16:24:58 +0100248 return 0;
249}
250
251int board_late_init(void)
252{
Simon Glass6a38e412017-08-03 12:22:09 -0600253 env_set("board_name", tqma6_get_boardname());
Markus Niebel00bb1872017-02-03 16:24:58 +0100254
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200255 tqma6_bb_board_late_init();
256
257 return 0;
258}
259
260int checkboard(void)
261{
262 printf("Board: %s on a %s\n", tqma6_get_boardname(),
263 tqma6_bb_get_boardname());
264 return 0;
265}
266
267/*
268 * Device Tree Support
269 */
270#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
Markus Niebelc01ca162017-02-28 16:37:33 +0100271#define MODELSTRLEN 32u
Simon Glass2aec3cc2014-10-23 18:58:47 -0600272int ft_board_setup(void *blob, bd_t *bd)
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200273{
Markus Niebelc01ca162017-02-28 16:37:33 +0100274 char modelstr[MODELSTRLEN];
275
276 snprintf(modelstr, MODELSTRLEN, "TQ %s on %s", tqma6_get_boardname(),
277 tqma6_bb_get_boardname());
278 do_fixup_by_path_string(blob, "/", "model", modelstr);
279 fdt_fixup_memory(blob, (u64)PHYS_SDRAM, (u64)gd->ram_size);
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200280 /* bring in eMMC dsr settings */
281 do_fixup_by_path_u32(blob,
282 "/soc/aips-bus@02100000/usdhc@02198000",
283 "dsr", tqma6_emmc_dsr, 2);
284 tqma6_bb_ft_board_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600285
286 return 0;
Markus Niebelee2cd2b2014-07-18 16:52:44 +0200287}
288#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */