John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2009 DENX Software Engineering |
| 3 | * Author: John Rigby <jrigby@gmail.com> |
| 4 | * |
| 5 | * Based on imx27lite.c: |
| 6 | * Copyright (C) 2008,2009 Eric Jarrige <jorasse@users.sourceforge.net> |
| 7 | * Copyright (C) 2009 Ilya Yanok <yanok@emcraft.com> |
| 8 | * And: |
| 9 | * RedBoot tx25_misc.c Copyright (C) 2009 Red Hat |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
| 27 | #include <common.h> |
| 28 | #include <asm/io.h> |
| 29 | #include <asm/arch/imx-regs.h> |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 30 | #include <asm/arch/iomux-mx25.h> |
Fabio Estevam | 0fcce18 | 2011-08-29 04:27:06 +0000 | [diff] [blame] | 31 | #include <asm/gpio.h> |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 32 | |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
Benoît Thébaudeau | efb7c00 | 2013-04-11 09:35:51 +0000 | [diff] [blame] | 35 | #ifdef CONFIG_SPL_BUILD |
| 36 | void board_init_f(ulong bootflag) |
| 37 | { |
Albert ARIBAUD | 26a653b | 2013-05-19 01:48:13 +0000 | [diff] [blame] | 38 | /* |
| 39 | * copy ourselves from where we are running to where we were |
| 40 | * linked at. Use ulong pointers as all addresses involved |
| 41 | * are 4-byte-aligned. |
| 42 | */ |
| 43 | ulong *start_ptr, *end_ptr, *link_ptr, *run_ptr, *dst; |
| 44 | asm volatile ("ldr %0, =_start" : "=r"(start_ptr)); |
| 45 | asm volatile ("ldr %0, =_end" : "=r"(end_ptr)); |
| 46 | asm volatile ("ldr %0, =board_init_f" : "=r"(link_ptr)); |
| 47 | asm volatile ("adr %0, board_init_f" : "=r"(run_ptr)); |
| 48 | for (dst = start_ptr; dst < end_ptr; dst++) |
| 49 | *dst = *(dst+(run_ptr-link_ptr)); |
| 50 | /* |
| 51 | * branch to nand_boot's link-time address. |
| 52 | */ |
Benoît Thébaudeau | efb7c00 | 2013-04-11 09:35:51 +0000 | [diff] [blame] | 53 | asm volatile("ldr pc, =nand_boot"); |
| 54 | } |
| 55 | #endif |
| 56 | |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_FEC_MXC |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 58 | /* |
| 59 | * FIXME: need to revisit this |
| 60 | * The original code enabled PUE and 100-k pull-down without PKE, so the right |
| 61 | * value here is likely: |
| 62 | * 0 for no pull |
| 63 | * or: |
| 64 | * PAD_CTL_PUS_100K_DOWN for 100-k pull-down |
| 65 | */ |
| 66 | #define FEC_OUT_PAD_CTRL 0 |
| 67 | |
Stefano Babic | fc05b90 | 2012-08-19 21:33:50 +0000 | [diff] [blame] | 68 | #define GPIO_FEC_RESET_B IMX_GPIO_NR(4, 7) |
| 69 | #define GPIO_FEC_ENABLE_B IMX_GPIO_NR(4, 9) |
Wolfgang Denk | 72d6685 | 2012-09-02 00:44:09 +0200 | [diff] [blame] | 70 | |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 71 | void tx25_fec_init(void) |
| 72 | { |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 73 | static const iomux_v3_cfg_t fec_pads[] = { |
| 74 | MX25_PAD_FEC_TX_CLK__FEC_TX_CLK, |
| 75 | MX25_PAD_FEC_RX_DV__FEC_RX_DV, |
| 76 | MX25_PAD_FEC_RDATA0__FEC_RDATA0, |
| 77 | NEW_PAD_CTRL(MX25_PAD_FEC_TDATA0__FEC_TDATA0, FEC_OUT_PAD_CTRL), |
| 78 | NEW_PAD_CTRL(MX25_PAD_FEC_TX_EN__FEC_TX_EN, FEC_OUT_PAD_CTRL), |
| 79 | NEW_PAD_CTRL(MX25_PAD_FEC_MDC__FEC_MDC, FEC_OUT_PAD_CTRL), |
| 80 | MX25_PAD_FEC_MDIO__FEC_MDIO, |
| 81 | MX25_PAD_FEC_RDATA1__FEC_RDATA1, |
| 82 | NEW_PAD_CTRL(MX25_PAD_FEC_TDATA1__FEC_TDATA1, FEC_OUT_PAD_CTRL), |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 83 | |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 84 | NEW_PAD_CTRL(MX25_PAD_D13__GPIO_4_7, 0), /* FEC_RESET_B */ |
| 85 | NEW_PAD_CTRL(MX25_PAD_D11__GPIO_4_9, 0), /* FEC_ENABLE_B */ |
| 86 | }; |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 87 | |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 88 | static const iomux_v3_cfg_t fec_cfg_pads[] = { |
| 89 | MX25_PAD_FEC_RDATA0__GPIO_3_10, |
| 90 | MX25_PAD_FEC_RDATA1__GPIO_3_11, |
| 91 | MX25_PAD_FEC_RX_DV__GPIO_3_12, |
| 92 | }; |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 93 | |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 94 | debug("tx25_fec_init\n"); |
| 95 | imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads)); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 96 | |
| 97 | /* drop PHY power and assert reset (low) */ |
Vikram Narayanan | 2cbd40c | 2012-06-16 07:16:17 +0000 | [diff] [blame] | 98 | gpio_direction_output(GPIO_FEC_RESET_B, 0); |
| 99 | gpio_direction_output(GPIO_FEC_ENABLE_B, 0); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 100 | |
| 101 | mdelay(5); |
| 102 | |
| 103 | debug("resetting phy\n"); |
| 104 | |
| 105 | /* turn on PHY power leaving reset asserted */ |
Vikram Narayanan | 2cbd40c | 2012-06-16 07:16:17 +0000 | [diff] [blame] | 106 | gpio_set_value(GPIO_FEC_ENABLE_B, 1); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 107 | |
| 108 | mdelay(10); |
| 109 | |
| 110 | /* |
| 111 | * Setup some strapping pins that are latched by the PHY |
| 112 | * as reset goes high. |
| 113 | * |
| 114 | * Set PHY mode to 111 |
| 115 | * mode0 comes from FEC_RDATA0 which is GPIO 3_10 in mux mode 5 |
| 116 | * mode1 comes from FEC_RDATA1 which is GPIO 3_11 in mux mode 5 |
| 117 | * mode2 is tied high so nothing to do |
| 118 | * |
| 119 | * Turn on RMII mode |
| 120 | * RMII mode is selected by FEC_RX_DV which is GPIO 3_12 in mux mode |
| 121 | */ |
| 122 | /* |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 123 | * set each mux mode to gpio mode |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 124 | */ |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 125 | imx_iomux_v3_setup_multiple_pads(fec_cfg_pads, |
| 126 | ARRAY_SIZE(fec_cfg_pads)); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 127 | |
| 128 | /* |
| 129 | * set each to 1 and make each an output |
| 130 | */ |
Stefano Babic | fc05b90 | 2012-08-19 21:33:50 +0000 | [diff] [blame] | 131 | gpio_direction_output(IMX_GPIO_NR(3, 10), 1); |
| 132 | gpio_direction_output(IMX_GPIO_NR(3, 11), 1); |
| 133 | gpio_direction_output(IMX_GPIO_NR(3, 12), 1); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 134 | |
| 135 | mdelay(22); /* this value came from RedBoot */ |
| 136 | |
| 137 | /* |
| 138 | * deassert PHY reset |
| 139 | */ |
Vikram Narayanan | 2cbd40c | 2012-06-16 07:16:17 +0000 | [diff] [blame] | 140 | gpio_set_value(GPIO_FEC_RESET_B, 1); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 141 | |
| 142 | mdelay(5); |
| 143 | |
| 144 | /* |
| 145 | * set FEC pins back |
| 146 | */ |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 147 | imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads)); |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 148 | } |
| 149 | #else |
| 150 | #define tx25_fec_init() |
| 151 | #endif |
| 152 | |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 153 | #ifdef CONFIG_MXC_UART |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 154 | /* |
| 155 | * Set up input pins with hysteresis and 100-k pull-ups |
| 156 | */ |
| 157 | #define UART1_IN_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_UP) |
| 158 | /* |
| 159 | * FIXME: need to revisit this |
| 160 | * The original code enabled PUE and 100-k pull-down without PKE, so the right |
| 161 | * value here is likely: |
| 162 | * 0 for no pull |
| 163 | * or: |
| 164 | * PAD_CTL_PUS_100K_DOWN for 100-k pull-down |
| 165 | */ |
| 166 | #define UART1_OUT_PAD_CTRL 0 |
| 167 | |
| 168 | static void tx25_uart1_init(void) |
| 169 | { |
| 170 | static const iomux_v3_cfg_t uart1_pads[] = { |
| 171 | NEW_PAD_CTRL(MX25_PAD_UART1_RXD__UART1_RXD, UART1_IN_PAD_CTRL), |
| 172 | NEW_PAD_CTRL(MX25_PAD_UART1_TXD__UART1_TXD, UART1_OUT_PAD_CTRL), |
| 173 | NEW_PAD_CTRL(MX25_PAD_UART1_RTS__UART1_RTS, UART1_OUT_PAD_CTRL), |
| 174 | NEW_PAD_CTRL(MX25_PAD_UART1_CTS__UART1_CTS, UART1_IN_PAD_CTRL), |
| 175 | }; |
| 176 | |
| 177 | imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); |
| 178 | } |
| 179 | #else |
| 180 | #define tx25_uart1_init() |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 181 | #endif |
Benoît Thébaudeau | ad7bd0b | 2013-05-03 10:32:16 +0000 | [diff] [blame] | 182 | |
| 183 | int board_init() |
| 184 | { |
| 185 | tx25_uart1_init(); |
| 186 | |
Anatolij Gustschin | af3e12a | 2010-04-21 13:52:38 +0200 | [diff] [blame] | 187 | /* board id for linux */ |
Anatolij Gustschin | af3e12a | 2010-04-21 13:52:38 +0200 | [diff] [blame] | 188 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 189 | return 0; |
| 190 | } |
| 191 | |
| 192 | int board_late_init(void) |
| 193 | { |
| 194 | tx25_fec_init(); |
| 195 | return 0; |
| 196 | } |
| 197 | |
Fabio Estevam | f231efb | 2011-10-13 05:34:59 +0000 | [diff] [blame] | 198 | int dram_init(void) |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 199 | { |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 200 | /* dram_init must store complete ramsize in gd->ram_size */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 201 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM_1, |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 202 | PHYS_SDRAM_1_SIZE); |
| 203 | return 0; |
| 204 | } |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 205 | |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 206 | void dram_init_banksize(void) |
| 207 | { |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 208 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 209 | gd->bd->bi_dram[0].size = get_ram_size((void *)PHYS_SDRAM_1, |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 210 | PHYS_SDRAM_1_SIZE); |
| 211 | #if CONFIG_NR_DRAM_BANKS > 1 |
| 212 | gd->bd->bi_dram[1].start = PHYS_SDRAM_2; |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 213 | gd->bd->bi_dram[1].size = get_ram_size((void *)PHYS_SDRAM_2, |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 214 | PHYS_SDRAM_2_SIZE); |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 215 | #else |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 216 | |
Heiko Schocher | 0e2412a | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 217 | #endif |
John Rigby | 6478a75 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | int checkboard(void) |
| 221 | { |
| 222 | printf("KARO TX25\n"); |
| 223 | return 0; |
| 224 | } |