Helmut Raiger | e5ecbb7 | 2011-10-27 01:31:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2011 HALE electronic <helmut.raiger@hale.at> |
| 3 | * (C) Copyright 2009 Magnus Lilja <lilja.magnus@gmail.com> |
| 4 | * (c) 2007 Pengutronix, Sascha Hauer <s.hauer@pengutronix.de> |
| 5 | * |
| 6 | * See file CREDITS for list of people who contributed to this |
| 7 | * project. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License as |
| 11 | * published by the Free Software Foundation; either version 2 of |
| 12 | * the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 22 | * MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <common.h> |
| 26 | #include <netdev.h> |
| 27 | #include <command.h> |
| 28 | #include <pmic.h> |
Helmut Raiger | 49989c7 | 2012-01-18 21:27:13 +0000 | [diff] [blame] | 29 | #include <fsl_pmic.h> |
| 30 | #include <mc13783.h> |
Helmut Raiger | e5ecbb7 | 2011-10-27 01:31:15 +0000 | [diff] [blame] | 31 | #include <asm/arch/clock.h> |
| 32 | #include <asm/arch/sys_proto.h> |
| 33 | #include <asm/io.h> |
| 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
| 37 | #define BOARD_STRING "Board: HALE TT-01" |
| 38 | |
| 39 | /* Clock configuration */ |
| 40 | #define CCM_CCMR_SETUP 0x074B0BF5 |
| 41 | |
| 42 | static void board_setup_clocks(void) |
| 43 | { |
| 44 | struct clock_control_regs *ccm = (struct clock_control_regs *) CCM_BASE; |
| 45 | volatile int wait = 0x10000; |
| 46 | |
| 47 | writel(CCM_CCMR_SETUP, &ccm->ccmr); |
| 48 | while (wait--) |
| 49 | ; |
| 50 | |
| 51 | writel(CCM_CCMR_SETUP | CCMR_MPE, &ccm->ccmr); |
| 52 | writel((CCM_CCMR_SETUP | CCMR_MPE) & ~CCMR_MDS, &ccm->ccmr); |
| 53 | |
| 54 | /* Set up clock to 532MHz */ |
| 55 | writel(PDR0_CSI_PODF(0x1ff) | PDR0_PER_PODF(7) | |
| 56 | PDR0_HSP_PODF(3) | PDR0_NFC_PODF(5) | |
| 57 | PDR0_IPG_PODF(1) | PDR0_MAX_PODF(3) | |
| 58 | PDR0_MCU_PODF(0), &ccm->pdr0); |
| 59 | writel(PLL_PD(0) | PLL_MFD(51) | PLL_MFI(10) | PLL_MFN(12), |
| 60 | &ccm->mpctl); |
| 61 | writel(PLL_PD(1) | PLL_MFD(4) | PLL_MFI(12) | PLL_MFN(1), |
| 62 | &ccm->spctl); |
| 63 | } |
| 64 | |
| 65 | /* DRAM configuration */ |
| 66 | |
| 67 | #define ESDMISC_MDDR_SETUP 0x00000004 |
| 68 | #define ESDMISC_MDDR_RESET_DL 0x0000000c |
| 69 | /* |
| 70 | * decoding magic 0x6ac73a = 0b 0110 1010 1100 0111 0011 1010 below: |
| 71 | * tXP = 11, tWTR = 0, tRP = 10, tMRD = 10 |
| 72 | * tWR = 1, tRAS = 100, tRRD = 01, tCAS = 11 |
| 73 | * tRCD = 011, tRC = 010 |
| 74 | * note: all but tWTR (1), tRC (111) are reset defaults, |
| 75 | * the same values work in the jtag configuration |
| 76 | * |
| 77 | * Bluetechnix setup has 0x75e73a (for 128MB) = |
| 78 | * 0b 0111 0101 1110 0111 0011 1010 |
| 79 | * tXP = 11, tWTR = 1, tRP = 01, tMRD = 01 |
| 80 | * tWR = 1, tRAS = 110, tRRD = 01, tCAS = 11 |
| 81 | * tRCD = 011, tRC = 010 |
| 82 | */ |
| 83 | #define ESDCFG0_MDDR_SETUP 0x006ac73a |
| 84 | #define ESDCTL_ROW_COL (ESDCTL_SDE | ESDCTL_ROW(2) | ESDCTL_COL(2)) |
| 85 | #define ESDCTL_SETTINGS (ESDCTL_ROW_COL | ESDCTL_SREFR(3) | \ |
| 86 | ESDCTL_DSIZ(2) | ESDCTL_BL(1)) |
| 87 | #define ESDCTL_PRECHARGE (ESDCTL_ROW_COL | ESDCTL_CMD_PRECHARGE) |
| 88 | #define ESDCTL_AUTOREFRESH (ESDCTL_ROW_COL | ESDCTL_CMD_AUTOREFRESH) |
| 89 | #define ESDCTL_LOADMODEREG (ESDCTL_ROW_COL | ESDCTL_CMD_LOADMODEREG) |
| 90 | #define ESDCTL_RW ESDCTL_SETTINGS |
| 91 | |
| 92 | static void board_setup_sdram(void) |
| 93 | { |
| 94 | u32 *pad; |
| 95 | struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR; |
| 96 | |
| 97 | /* |
| 98 | * setup pad control for the controller pins |
| 99 | * no loopback, no pull, no keeper, no open drain, |
| 100 | * standard input, standard drive, slow slew rate |
| 101 | */ |
| 102 | for (pad = (u32 *) IOMUXC_SW_PAD_CTL_SDCKE1_SDCLK_SDCLK_B; |
| 103 | pad <= (u32 *) IOMUXC_SW_PAD_CTL_VPG0_VPG1_A0; pad++) |
| 104 | *pad = 0; |
| 105 | |
| 106 | /* set up MX31 DDR Memory Controller */ |
| 107 | writel(ESDMISC_MDDR_SETUP, &esdc->misc); |
| 108 | writel(ESDCFG0_MDDR_SETUP, &esdc->cfg0); |
| 109 | |
| 110 | /* perform DDR init sequence for CSD0 */ |
| 111 | writel(ESDCTL_PRECHARGE, &esdc->ctl0); |
| 112 | writel(0x12344321, CSD0_BASE+0x0f00); |
| 113 | writel(ESDCTL_AUTOREFRESH, &esdc->ctl0); |
| 114 | writel(0x12344321, CSD0_BASE); |
| 115 | writel(0x12344321, CSD0_BASE); |
| 116 | writel(ESDCTL_LOADMODEREG, &esdc->ctl0); |
| 117 | writeb(0xda, CSD0_BASE+0x33); |
| 118 | writeb(0xff, CSD0_BASE+0x1000000); |
| 119 | writel(ESDCTL_RW, &esdc->ctl0); |
| 120 | writel(0xDEADBEEF, CSD0_BASE); |
| 121 | writel(ESDMISC_MDDR_RESET_DL, &esdc->misc); |
| 122 | } |
| 123 | |
| 124 | static void tt01_spi3_hw_init(void) |
| 125 | { |
| 126 | /* CSPI3 */ |
| 127 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CSPI3_MISO, MUX_CTL_FUNC)); |
| 128 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CSPI3_MOSI, MUX_CTL_FUNC)); |
| 129 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CSPI3_SCLK, MUX_CTL_FUNC)); |
| 130 | /* CSPI3, SS0 = Atlas */ |
| 131 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_CSPI2_SS0, MUX_CTL_ALT1)); |
| 132 | |
| 133 | /* start CSPI3 clock (3 = always on except if PLL off) */ |
| 134 | setbits_le32(CCM_CGR0, 3 << 16); |
| 135 | } |
| 136 | |
| 137 | int dram_init(void) |
| 138 | { |
| 139 | /* dram_init must store complete ramsize in gd->ram_size */ |
| 140 | gd->ram_size = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, |
| 141 | PHYS_SDRAM_1_SIZE); |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | int board_early_init_f(void) |
| 146 | { |
| 147 | /* CS4: FPGA incl. network controller */ |
| 148 | struct mxc_weimcs cs4 = { |
| 149 | /* sp wp bcd bcs psz pme sync dol cnc wsc ew wws edc */ |
| 150 | CSCR_U(0, 0, 0, 0, 0, 0, 0, 0, 3, 28, 1, 7, 6), |
| 151 | /* oea oen ebwa ebwn csa ebc dsz csn psr cre wrap csen */ |
| 152 | CSCR_L(4, 4, 4, 10, 4, 0, 5, 4, 0, 0, 0, 1), |
| 153 | /* ebra ebrn rwa rwn mum lah lbn lba dww dct wwu age cnc2 fce*/ |
| 154 | CSCR_A(4, 4, 4, 4, 0, 1, 4, 3, 0, 0, 0, 0, 1, 0) |
| 155 | }; |
| 156 | |
| 157 | /* this seems essential, won't start without, but why? */ |
| 158 | writel(IPU_CONF_DI_EN, (u32 *) IPU_CONF); |
| 159 | |
| 160 | board_setup_clocks(); |
| 161 | board_setup_sdram(); |
| 162 | mxc_setup_weimcs(4, &cs4); |
| 163 | |
| 164 | /* Setup UART2 and SPI3 pins */ |
| 165 | mx31_uart2_hw_init(); |
| 166 | tt01_spi3_hw_init(); |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int board_init(void) |
| 172 | { |
| 173 | /* address of boot parameters */ |
| 174 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | int board_late_init(void) |
| 179 | { |
Helmut Raiger | e5ecbb7 | 2011-10-27 01:31:15 +0000 | [diff] [blame] | 180 | #ifdef CONFIG_HW_WATCHDOG |
| 181 | mxc_hw_watchdog_enable(); |
| 182 | #endif |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | int checkboard(void) |
| 188 | { |
| 189 | puts(BOARD_STRING "\n"); |
| 190 | return 0; |
| 191 | } |
Helmut Raiger | 49989c7 | 2012-01-18 21:27:13 +0000 | [diff] [blame] | 192 | |
| 193 | #ifdef CONFIG_MXC_MMC |
| 194 | int board_mmc_init(bd_t *bis) |
| 195 | { |
| 196 | u32 val; |
| 197 | struct pmic *p; |
| 198 | |
| 199 | /* |
| 200 | * this is the first driver to use the pmic, so call |
| 201 | * pmic_init() here. board_late_init() is too late for |
| 202 | * the MMC driver. |
| 203 | */ |
| 204 | pmic_init(); |
| 205 | p = get_pmic(); |
| 206 | |
| 207 | /* configure pins for SDHC1 only */ |
| 208 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_CLK, MUX_CTL_FUNC)); |
| 209 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_CMD, MUX_CTL_FUNC)); |
| 210 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_DATA0, MUX_CTL_FUNC)); |
| 211 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_DATA1, MUX_CTL_FUNC)); |
| 212 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_DATA2, MUX_CTL_FUNC)); |
| 213 | mx31_gpio_mux(IOMUX_MODE(MUX_CTL_SD1_DATA3, MUX_CTL_FUNC)); |
| 214 | |
| 215 | /* turn on power V_MMC1 */ |
| 216 | if (pmic_reg_read(p, REG_MODE_1, &val) < 0) |
| 217 | pmic_reg_write(p, REG_MODE_1, val | VMMC1EN); |
| 218 | |
| 219 | return mxc_mmc_init(bis); |
| 220 | } |
| 221 | #endif |
Helmut Raiger | e5ecbb7 | 2011-10-27 01:31:15 +0000 | [diff] [blame] | 222 | |
| 223 | int board_eth_init(bd_t *bis) |
| 224 | { |
| 225 | int rc = 0; |
| 226 | #ifdef CONFIG_SMC911X |
| 227 | rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 228 | #endif |
| 229 | return rc; |
| 230 | } |
Helmut Raiger | 8deec39 | 2012-02-15 22:40:12 +0000 | [diff] [blame] | 231 | |
| 232 | #ifdef CONFIG_CONSOLE_EXTRA_INFO |
| 233 | void video_get_info_str(int line_number, char *info) |
| 234 | { |
| 235 | u32 srev = get_cpu_rev(); |
| 236 | |
| 237 | switch (line_number) { |
| 238 | case 2: |
| 239 | sprintf(info, " CPU : Freescale i.MX31 rev %d.%d%s at %d MHz", |
| 240 | (srev & 0xF0) >> 4, (srev & 0x0F), |
| 241 | ((srev & 0x8000) ? " unknown" : ""), |
| 242 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 243 | break; |
| 244 | case 3: |
| 245 | strcpy(info, " " BOARD_STRING); |
| 246 | break; |
| 247 | default: |
| 248 | info[0] = 0; |
| 249 | } |
| 250 | } |
| 251 | #endif |