Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 2 | /* |
| 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 Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 8 | */ |
| 9 | |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 10 | #include <init.h> |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 11 | #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 Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 17 | #include <asm/gpio.h> |
Stefano Babic | 552a848 | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 18 | #include <asm/mach-imx/iomux-v3.h> |
| 19 | #include <asm/mach-imx/mxc_i2c.h> |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 20 | #include <asm/io.h> |
| 21 | #include <linux/sizes.h> |
| 22 | #include <common.h> |
| 23 | #include <watchdog.h> |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 24 | #include <fsl_esdhc_imx.h> |
Fabio Estevam | 44f98f9 | 2015-07-21 19:48:41 -0300 | [diff] [blame] | 25 | #include <i2c.h> |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 26 | #include <mmc.h> |
Fabio Estevam | 09ac7b5 | 2015-02-28 15:16:42 -0300 | [diff] [blame] | 27 | #include <usb.h> |
Fabio Estevam | 44f98f9 | 2015-07-21 19:48:41 -0300 | [diff] [blame] | 28 | #include <power/pmic.h> |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 29 | |
| 30 | DECLARE_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 Estevam | 44f98f9 | 2015-07-21 19:48:41 -0300 | [diff] [blame] | 42 | #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 Chung | e316aa5 | 2021-01-28 20:42:33 +0900 | [diff] [blame] | 47 | #define CONFIG_POWER_MAX77696_I2C_ADDR 0x3C |
| 48 | |
| 49 | enum { |
| 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 Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 94 | int dram_init(void) |
| 95 | { |
Fabio Estevam | a13d375 | 2016-07-23 13:23:38 -0300 | [diff] [blame] | 96 | gd->ram_size = imx_ddr_size(); |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 97 | |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | static 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 | |
| 111 | static struct fsl_esdhc_cfg usdhc_cfg[1] = { |
Peng Fan | f34ccce | 2017-06-12 17:50:55 +0800 | [diff] [blame] | 112 | {USDHC2_BASE_ADDR, 0, 0, 0, 1}, |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | int board_mmc_getcd(struct mmc *mmc) |
| 116 | { |
| 117 | return 1; /* Assume boot SD always present */ |
| 118 | } |
| 119 | |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 120 | int board_mmc_init(struct bd_info *bis) |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 121 | { |
| 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 Estevam | 09ac7b5 | 2015-02-28 15:16:42 -0300 | [diff] [blame] | 142 | int board_usb_phy_mode(int port) |
| 143 | { |
| 144 | return USB_INIT_DEVICE; |
| 145 | } |
| 146 | |
Fabio Estevam | 44f98f9 | 2015-07-21 19:48:41 -0300 | [diff] [blame] | 147 | /* I2C1 for PMIC */ |
| 148 | #define I2C_PMIC 0 |
| 149 | #define PC MUX_PAD_CTRL(I2C_PAD_CTRL) |
| 150 | struct 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 Chung | e316aa5 | 2021-01-28 20:42:33 +0900 | [diff] [blame] | 163 | static 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 Estevam | 44f98f9 | 2015-07-21 19:48:41 -0300 | [diff] [blame] | 183 | int 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, ®); |
| 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 Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 206 | int board_early_init_f(void) |
| 207 | { |
| 208 | setup_iomux_uart(); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | int board_init(void) |
| 213 | { |
| 214 | /* address of boot parameters */ |
| 215 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 216 | |
Fabio Estevam | 44f98f9 | 2015-07-21 19:48:41 -0300 | [diff] [blame] | 217 | setup_i2c(0, CONFIG_SYS_I2C_SPEED, 0x7f, &i2c_pad_info1); |
| 218 | |
Otavio Salvador | 4579dc3 | 2015-02-17 10:42:46 -0200 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | int board_late_init(void) |
| 223 | { |
| 224 | #ifdef CONFIG_HW_WATCHDOG |
| 225 | hw_watchdog_init(); |
| 226 | #endif |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | int checkboard(void) |
| 232 | { |
| 233 | puts("Board: WaRP Board\n"); |
| 234 | |
| 235 | return 0; |
| 236 | } |