blob: c03b6488507a5fd11b3ec5302a65702703f0439a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Otavio Salvador4579dc32015-02-17 10:42:46 -02002/*
3 * Copyright (C) 2014, 2015 O.S. Systems Software LTDA.
4 * Copyright (C) 2014 Kynetics LLC.
5 * Copyright (C) 2014 Revolution Robotics, Inc.
6 *
7 * Author: Otavio Salvador <otavio@ossystems.com.br>
Otavio Salvador4579dc32015-02-17 10:42:46 -02008 */
9
Simon Glass52559322019-11-14 12:57:46 -070010#include <init.h>
Otavio Salvador4579dc32015-02-17 10:42:46 -020011#include <asm/arch/clock.h>
12#include <asm/arch/iomux.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/mx6-pins.h>
15#include <asm/arch/sys_proto.h>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Otavio Salvador4579dc32015-02-17 10:42:46 -020017#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020018#include <asm/mach-imx/iomux-v3.h>
19#include <asm/mach-imx/mxc_i2c.h>
Otavio Salvador4579dc32015-02-17 10:42:46 -020020#include <asm/io.h>
21#include <linux/sizes.h>
22#include <common.h>
23#include <watchdog.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080024#include <fsl_esdhc_imx.h>
Fabio Estevam44f98f92015-07-21 19:48:41 -030025#include <i2c.h>
Otavio Salvador4579dc32015-02-17 10:42:46 -020026#include <mmc.h>
Fabio Estevam09ac7b52015-02-28 15:16:42 -030027#include <usb.h>
Fabio Estevam44f98f92015-07-21 19:48:41 -030028#include <power/pmic.h>
Otavio Salvador4579dc32015-02-17 10:42:46 -020029
30DECLARE_GLOBAL_DATA_PTR;
31
32#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
33 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
34 PAD_CTL_SRE_FAST | PAD_CTL_HYS | \
35 PAD_CTL_LVE)
36
37#define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP | \
38 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
39 PAD_CTL_SRE_FAST | PAD_CTL_HYS | \
40 PAD_CTL_LVE)
41
Fabio Estevam44f98f92015-07-21 19:48:41 -030042#define I2C_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
43 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
44 PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
45 PAD_CTL_ODE | PAD_CTL_SRE_FAST)
46
Jaehoon Chunge316aa52021-01-28 20:42:33 +090047#define CONFIG_POWER_MAX77696_I2C_ADDR 0x3C
48
49enum {
50 L01_CNFG1 = 0x43,
51 L01_CNFG2,
52 L02_CNFG1,
53 L02_CNFG2,
54 L03_CNFG1,
55 L03_CNFG2,
56 L04_CNFG1,
57 L04_CNFG2,
58 L05_CNFG1,
59 L05_CNFG2,
60 L06_CNFG1,
61 L06_CNFG2,
62 L07_CNFG1,
63 L07_CNFG2,
64 L08_CNFG1,
65 L08_CNFG2,
66 L09_CNFG1,
67 L09_CNFG2,
68 L10_CNFG1,
69 L10_CNFG2,
70 LDO_INT1,
71 LDO_INT2,
72 LDO_INT1M,
73 LDO_INT2M,
74 LDO_CNFG3,
75 SW1_CNTRL,
76 SW2_CNTRL,
77 SW3_CNTRL,
78 SW4_CNTRL,
79 EPDCNFG,
80 EPDINTS,
81 EPDINT,
82 EPDINTM,
83 EPDVCOM,
84 EPDVEE,
85 EPDVNEG,
86 EPDVPOS,
87 EPDVDDH,
88 EPDSEQ,
89 EPDOKINTS,
90 CID = 0x9c,
91 PMIC_NUM_OF_REGS,
92};
93
Otavio Salvador4579dc32015-02-17 10:42:46 -020094int dram_init(void)
95{
Fabio Estevama13d3752016-07-23 13:23:38 -030096 gd->ram_size = imx_ddr_size();
Otavio Salvador4579dc32015-02-17 10:42:46 -020097
98 return 0;
99}
100
101static void setup_iomux_uart(void)
102{
103 static iomux_v3_cfg_t const uart1_pads[] = {
104 MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
105 MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
106 };
107
108 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
109}
110
111static struct fsl_esdhc_cfg usdhc_cfg[1] = {
Peng Fanf34ccce2017-06-12 17:50:55 +0800112 {USDHC2_BASE_ADDR, 0, 0, 0, 1},
Otavio Salvador4579dc32015-02-17 10:42:46 -0200113};
114
115int board_mmc_getcd(struct mmc *mmc)
116{
117 return 1; /* Assume boot SD always present */
118}
119
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900120int board_mmc_init(struct bd_info *bis)
Otavio Salvador4579dc32015-02-17 10:42:46 -0200121{
122 static iomux_v3_cfg_t const usdhc2_pads[] = {
123 MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
124 MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
125 MX6_PAD_SD2_RST__USDHC2_RST | MUX_PAD_CTRL(USDHC_PAD_CTRL),
126 MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
127 MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
128 MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
129 MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
130 MX6_PAD_SD2_DAT4__USDHC2_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
131 MX6_PAD_SD2_DAT5__USDHC2_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
132 MX6_PAD_SD2_DAT6__USDHC2_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
133 MX6_PAD_SD2_DAT7__USDHC2_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
134 };
135
136 imx_iomux_v3_setup_multiple_pads(usdhc2_pads, ARRAY_SIZE(usdhc2_pads));
137
138 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
139 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
140}
141
Fabio Estevam09ac7b52015-02-28 15:16:42 -0300142int board_usb_phy_mode(int port)
143{
144 return USB_INIT_DEVICE;
145}
146
Fabio Estevam44f98f92015-07-21 19:48:41 -0300147/* I2C1 for PMIC */
148#define I2C_PMIC 0
149#define PC MUX_PAD_CTRL(I2C_PAD_CTRL)
150struct i2c_pads_info i2c_pad_info1 = {
151 .sda = {
152 .i2c_mode = MX6_PAD_I2C1_SDA__I2C1_SDA | PC,
153 .gpio_mode = MX6_PAD_I2C1_SDA__GPIO_3_13 | PC,
154 .gp = IMX_GPIO_NR(3, 13),
155 },
156 .scl = {
157 .i2c_mode = MX6_PAD_I2C1_SCL__I2C1_SCL | PC,
158 .gpio_mode = MX6_PAD_I2C1_SCL__GPIO_3_12 | PC,
159 .gp = IMX_GPIO_NR(3, 12),
160 },
161};
162
Jaehoon Chunge316aa52021-01-28 20:42:33 +0900163static int power_max77696_init(unsigned char bus)
164{
165 static const char name[] = "MAX77696";
166 struct pmic *p = pmic_alloc();
167
168 if (!p) {
169 printf("%s: POWER allocation error!\n", __func__);
170 return -ENOMEM;
171 }
172
173 p->name = name;
174 p->interface = PMIC_I2C;
175 p->number_of_regs = PMIC_NUM_OF_REGS;
176 p->hw.i2c.addr = CONFIG_POWER_MAX77696_I2C_ADDR;
177 p->hw.i2c.tx_num = 1;
178 p->bus = bus;
179
180 return 0;
181}
182
Fabio Estevam44f98f92015-07-21 19:48:41 -0300183int power_init_board(void)
184{
185 struct pmic *p;
186 int ret;
187 unsigned int reg;
188
189 ret = power_max77696_init(I2C_PMIC);
190 if (ret)
191 return ret;
192
193 p = pmic_get("MAX77696");
194 if (!p)
195 return -EINVAL;
196
197 ret = pmic_reg_read(p, CID, &reg);
198 if (ret)
199 return ret;
200
201 printf("PMIC: MAX77696 detected, rev=0x%x\n", reg);
202
203 return pmic_probe(p);
204}
205
Otavio Salvador4579dc32015-02-17 10:42:46 -0200206int board_early_init_f(void)
207{
208 setup_iomux_uart();
209 return 0;
210}
211
212int board_init(void)
213{
214 /* address of boot parameters */
215 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
216
Fabio Estevam44f98f92015-07-21 19:48:41 -0300217 setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1);
218
Otavio Salvador4579dc32015-02-17 10:42:46 -0200219 return 0;
220}
221
222int board_late_init(void)
223{
224#ifdef CONFIG_HW_WATCHDOG
225 hw_watchdog_init();
226#endif
227
228 return 0;
229}
230
231int checkboard(void)
232{
233 puts("Board: WaRP Board\n");
234
235 return 0;
236}