Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de> |
| 4 | * |
| 5 | * (C) Copyright 2008-2010 Freescale Semiconductor, Inc. |
| 6 | * |
| 7 | * Copyright (C) 2011, Stefano Babic <sbabic@denx.de> |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 11 | #include <init.h> |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 12 | #include <asm/io.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 13 | #include <env.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 14 | #include <linux/errno.h> |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 15 | #include <asm/arch/imx-regs.h> |
| 16 | #include <asm/arch/crm_regs.h> |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 17 | #include <asm/arch/iomux-mx35.h> |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 18 | #include <i2c.h> |
| 19 | #include <linux/types.h> |
| 20 | #include <asm/gpio.h> |
| 21 | #include <asm/arch/sys_proto.h> |
| 22 | #include <netdev.h> |
Heiko Schocher | a459d34 | 2016-10-17 15:51:32 +0200 | [diff] [blame] | 23 | #include <fdt_support.h> |
| 24 | #include <mtd_node.h> |
| 25 | #include <jffs2/load_kernel.h> |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 26 | |
| 27 | #ifndef CONFIG_BOARD_EARLY_INIT_F |
| 28 | #error "CONFIG_BOARD_EARLY_INIT_F must be set for this board" |
| 29 | #endif |
| 30 | |
| 31 | #define CCM_CCMR_CONFIG 0x003F4208 |
| 32 | |
| 33 | #define ESDCTL_DDR2_CONFIG 0x007FFC3F |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 34 | |
| 35 | static inline void dram_wait(unsigned int count) |
| 36 | { |
| 37 | volatile unsigned int wait = count; |
| 38 | |
| 39 | while (wait--) |
| 40 | ; |
| 41 | } |
| 42 | |
| 43 | DECLARE_GLOBAL_DATA_PTR; |
| 44 | |
| 45 | int dram_init(void) |
| 46 | { |
| 47 | gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1, |
| 48 | PHYS_SDRAM_1_SIZE); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 53 | static void board_setup_sdram(void) |
| 54 | { |
| 55 | struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR; |
| 56 | |
| 57 | /* Initialize with default values both CSD0/1 */ |
| 58 | writel(0x2000, &esdc->esdctl0); |
| 59 | writel(0x2000, &esdc->esdctl1); |
| 60 | |
Stefano Babic | 32e5668 | 2016-10-17 15:51:33 +0200 | [diff] [blame] | 61 | |
| 62 | mx3_setup_sdram_bank(CSD0_BASE_ADDR, ESDCTL_DDR2_CONFIG, |
| 63 | 13, 10, 2, 0x8080); |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | static void setup_iomux_uart3(void) |
| 67 | { |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 68 | static const iomux_v3_cfg_t uart3_pads[] = { |
| 69 | MX35_PAD_RTS2__UART3_RXD_MUX, |
| 70 | MX35_PAD_CTS2__UART3_TXD_MUX, |
| 71 | }; |
| 72 | |
| 73 | imx_iomux_v3_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads)); |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 76 | #define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_ODE) |
| 77 | |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 78 | static void setup_iomux_i2c(void) |
| 79 | { |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 80 | static const iomux_v3_cfg_t i2c_pads[] = { |
| 81 | NEW_PAD_CTRL(MX35_PAD_I2C1_CLK__I2C1_SCL, I2C_PAD_CTRL), |
| 82 | NEW_PAD_CTRL(MX35_PAD_I2C1_DAT__I2C1_SDA, I2C_PAD_CTRL), |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 83 | |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 84 | NEW_PAD_CTRL(MX35_PAD_TX3_RX2__I2C3_SCL, I2C_PAD_CTRL), |
| 85 | NEW_PAD_CTRL(MX35_PAD_TX2_RX3__I2C3_SDA, I2C_PAD_CTRL), |
| 86 | }; |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 87 | |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 88 | imx_iomux_v3_setup_multiple_pads(i2c_pads, ARRAY_SIZE(i2c_pads)); |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | |
| 92 | static void setup_iomux_spi(void) |
| 93 | { |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 94 | static const iomux_v3_cfg_t spi_pads[] = { |
| 95 | MX35_PAD_CSPI1_MOSI__CSPI1_MOSI, |
| 96 | MX35_PAD_CSPI1_MISO__CSPI1_MISO, |
| 97 | MX35_PAD_CSPI1_SS0__CSPI1_SS0, |
| 98 | MX35_PAD_CSPI1_SS1__CSPI1_SS1, |
| 99 | MX35_PAD_CSPI1_SCLK__CSPI1_SCLK, |
| 100 | }; |
| 101 | |
| 102 | imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads)); |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static void setup_iomux_fec(void) |
| 106 | { |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 107 | static const iomux_v3_cfg_t fec_pads[] = { |
| 108 | MX35_PAD_FEC_TX_CLK__FEC_TX_CLK, |
| 109 | MX35_PAD_FEC_RX_CLK__FEC_RX_CLK, |
| 110 | MX35_PAD_FEC_RX_DV__FEC_RX_DV, |
| 111 | MX35_PAD_FEC_COL__FEC_COL, |
| 112 | MX35_PAD_FEC_RDATA0__FEC_RDATA_0, |
| 113 | MX35_PAD_FEC_TDATA0__FEC_TDATA_0, |
| 114 | MX35_PAD_FEC_TX_EN__FEC_TX_EN, |
| 115 | MX35_PAD_FEC_MDC__FEC_MDC, |
| 116 | MX35_PAD_FEC_MDIO__FEC_MDIO, |
| 117 | MX35_PAD_FEC_TX_ERR__FEC_TX_ERR, |
| 118 | MX35_PAD_FEC_RX_ERR__FEC_RX_ERR, |
| 119 | MX35_PAD_FEC_CRS__FEC_CRS, |
| 120 | MX35_PAD_FEC_RDATA1__FEC_RDATA_1, |
| 121 | MX35_PAD_FEC_TDATA1__FEC_TDATA_1, |
| 122 | MX35_PAD_FEC_RDATA2__FEC_RDATA_2, |
| 123 | MX35_PAD_FEC_TDATA2__FEC_TDATA_2, |
| 124 | MX35_PAD_FEC_RDATA3__FEC_RDATA_3, |
| 125 | MX35_PAD_FEC_TDATA3__FEC_TDATA_3, |
Stefano Babic | eca819e | 2016-10-17 15:51:34 +0200 | [diff] [blame] | 126 | /* GPIO used to power off ethernet */ |
| 127 | MX35_PAD_STXFS4__GPIO2_31, |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 128 | }; |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 129 | |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 130 | /* setup pins for FEC */ |
| 131 | imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads)); |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | int board_early_init_f(void) |
| 135 | { |
| 136 | struct ccm_regs *ccm = |
| 137 | (struct ccm_regs *)IMX_CCM_BASE; |
| 138 | |
| 139 | /* setup GPIO3_1 to set HighVCore signal */ |
Benoît Thébaudeau | 2cc311e | 2013-05-03 10:32:20 +0000 | [diff] [blame] | 140 | imx_iomux_v3_setup_pad(MX35_PAD_ATA_DA1__GPIO3_1); |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 141 | gpio_direction_output(65, 1); |
| 142 | |
| 143 | /* initialize PLL and clock configuration */ |
| 144 | writel(CCM_CCMR_CONFIG, &ccm->ccmr); |
| 145 | |
| 146 | writel(CCM_MPLL_532_HZ, &ccm->mpctl); |
| 147 | writel(CCM_PPLL_300_HZ, &ccm->ppctl); |
| 148 | |
| 149 | /* Set the core to run at 532 Mhz */ |
| 150 | writel(0x00001000, &ccm->pdr0); |
| 151 | |
| 152 | /* Set-up RAM */ |
| 153 | board_setup_sdram(); |
| 154 | |
| 155 | /* enable clocks */ |
| 156 | writel(readl(&ccm->cgr0) | |
| 157 | MXC_CCM_CGR0_EMI_MASK | |
Benoît Thébaudeau | 8ce8777 | 2012-08-14 03:28:24 +0000 | [diff] [blame] | 158 | MXC_CCM_CGR0_EDIO_MASK | |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 159 | MXC_CCM_CGR0_EPIT1_MASK, |
| 160 | &ccm->cgr0); |
| 161 | |
| 162 | writel(readl(&ccm->cgr1) | |
| 163 | MXC_CCM_CGR1_FEC_MASK | |
| 164 | MXC_CCM_CGR1_GPIO1_MASK | |
| 165 | MXC_CCM_CGR1_GPIO2_MASK | |
| 166 | MXC_CCM_CGR1_GPIO3_MASK | |
| 167 | MXC_CCM_CGR1_I2C1_MASK | |
| 168 | MXC_CCM_CGR1_I2C2_MASK | |
| 169 | MXC_CCM_CGR1_I2C3_MASK, |
| 170 | &ccm->cgr1); |
| 171 | |
| 172 | /* Set-up NAND */ |
| 173 | __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr); |
| 174 | |
| 175 | /* Set pinmux for the required peripherals */ |
| 176 | setup_iomux_uart3(); |
| 177 | setup_iomux_i2c(); |
| 178 | setup_iomux_fec(); |
| 179 | setup_iomux_spi(); |
| 180 | |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | int board_init(void) |
| 185 | { |
| 186 | /* address of boot parameters */ |
| 187 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 188 | |
Stefano Babic | eca819e | 2016-10-17 15:51:34 +0200 | [diff] [blame] | 189 | /* Enable power for ethernet */ |
| 190 | gpio_direction_output(63, 0); |
| 191 | |
| 192 | udelay(2000); |
| 193 | |
Stefano Babic | d67cdcd | 2011-10-23 23:58:20 +0000 | [diff] [blame] | 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | u32 get_board_rev(void) |
| 198 | { |
| 199 | int rev = 0; |
| 200 | |
| 201 | return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8; |
| 202 | } |
Heiko Schocher | a459d34 | 2016-10-17 15:51:32 +0200 | [diff] [blame] | 203 | |
| 204 | /* |
| 205 | * called prior to booting kernel or by 'fdt boardsetup' command |
| 206 | * |
| 207 | */ |
| 208 | int ft_board_setup(void *blob, bd_t *bd) |
| 209 | { |
Masahiro Yamada | 20ead6f | 2018-07-19 16:28:23 +0900 | [diff] [blame] | 210 | static const struct node_info nodes[] = { |
Heiko Schocher | a459d34 | 2016-10-17 15:51:32 +0200 | [diff] [blame] | 211 | { "physmap-flash.0", MTD_DEV_TYPE_NOR, }, /* NOR flash */ |
| 212 | { "mxc_nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */ |
| 213 | }; |
| 214 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 215 | if (env_get("fdt_noauto")) { |
Heiko Schocher | a459d34 | 2016-10-17 15:51:32 +0200 | [diff] [blame] | 216 | puts(" Skiping ft_board_setup (fdt_noauto defined)\n"); |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); |
| 221 | |
| 222 | return 0; |
| 223 | } |