John Rigby | 6895d45 | 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> |
| 30 | #include <asm/arch/imx25-pinmux.h> |
Fabio Estevam | c2205f4 | 2011-08-29 04:27:06 +0000 | [diff] [blame] | 31 | #include <asm/gpio.h> |
Fabio Estevam | e6d9b97 | 2011-09-06 09:05:42 +0000 | [diff] [blame] | 32 | #include <asm/arch/sys_proto.h> |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 33 | |
| 34 | static void mdelay(int n) |
| 35 | { |
| 36 | while (n-- > 0) |
| 37 | udelay(1000); |
| 38 | } |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | #ifdef CONFIG_FEC_MXC |
| 43 | void tx25_fec_init(void) |
| 44 | { |
| 45 | struct iomuxc_mux_ctl *muxctl; |
| 46 | struct iomuxc_pad_ctl *padctl; |
| 47 | u32 val; |
| 48 | u32 gpio_mux_mode = MX25_PIN_MUX_MODE(5); |
| 49 | struct gpio_regs *gpio4 = (struct gpio_regs *)IMX_GPIO4_BASE; |
| 50 | struct gpio_regs *gpio3 = (struct gpio_regs *)IMX_GPIO3_BASE; |
| 51 | u32 saved_rdata0_mode, saved_rdata1_mode, saved_rx_dv_mode; |
| 52 | |
| 53 | debug("tx25_fec_init\n"); |
| 54 | /* |
| 55 | * fec pin init is generic |
| 56 | */ |
| 57 | mx25_fec_init_pins(); |
| 58 | |
| 59 | /* |
| 60 | * Set up the FEC_RESET_B and FEC_ENABLE GPIO pins. |
| 61 | * |
| 62 | * FEC_RESET_B: gpio4[7] is ALT 5 mode of pin D13 |
| 63 | * FEC_ENABLE_B: gpio4[9] is ALT 5 mode of pin D11 |
| 64 | */ |
| 65 | muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE; |
| 66 | padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE; |
| 67 | |
| 68 | writel(gpio_mux_mode, &muxctl->pad_d13); |
| 69 | writel(gpio_mux_mode, &muxctl->pad_d11); |
| 70 | |
| 71 | writel(0x0, &padctl->pad_d13); |
| 72 | writel(0x0, &padctl->pad_d11); |
| 73 | |
| 74 | /* drop PHY power and assert reset (low) */ |
Matthias Weisser | 95d1858 | 2011-07-06 00:28:32 +0000 | [diff] [blame] | 75 | val = readl(&gpio4->gpio_dr) & ~((1 << 7) | (1 << 9)); |
| 76 | writel(val, &gpio4->gpio_dr); |
| 77 | val = readl(&gpio4->gpio_dir) | (1 << 7) | (1 << 9); |
| 78 | writel(val, &gpio4->gpio_dir); |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 79 | |
| 80 | mdelay(5); |
| 81 | |
| 82 | debug("resetting phy\n"); |
| 83 | |
| 84 | /* turn on PHY power leaving reset asserted */ |
Matthias Weisser | 95d1858 | 2011-07-06 00:28:32 +0000 | [diff] [blame] | 85 | val = readl(&gpio4->gpio_dr) | 1 << 9; |
| 86 | writel(val, &gpio4->gpio_dr); |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 87 | |
| 88 | mdelay(10); |
| 89 | |
| 90 | /* |
| 91 | * Setup some strapping pins that are latched by the PHY |
| 92 | * as reset goes high. |
| 93 | * |
| 94 | * Set PHY mode to 111 |
| 95 | * mode0 comes from FEC_RDATA0 which is GPIO 3_10 in mux mode 5 |
| 96 | * mode1 comes from FEC_RDATA1 which is GPIO 3_11 in mux mode 5 |
| 97 | * mode2 is tied high so nothing to do |
| 98 | * |
| 99 | * Turn on RMII mode |
| 100 | * RMII mode is selected by FEC_RX_DV which is GPIO 3_12 in mux mode |
| 101 | */ |
| 102 | /* |
| 103 | * save three current mux modes and set each to gpio mode |
| 104 | */ |
| 105 | saved_rdata0_mode = readl(&muxctl->pad_fec_rdata0); |
| 106 | saved_rdata1_mode = readl(&muxctl->pad_fec_rdata1); |
| 107 | saved_rx_dv_mode = readl(&muxctl->pad_fec_rx_dv); |
| 108 | |
| 109 | writel(gpio_mux_mode, &muxctl->pad_fec_rdata0); |
| 110 | writel(gpio_mux_mode, &muxctl->pad_fec_rdata1); |
| 111 | writel(gpio_mux_mode, &muxctl->pad_fec_rx_dv); |
| 112 | |
| 113 | /* |
| 114 | * set each to 1 and make each an output |
| 115 | */ |
Matthias Weisser | 95d1858 | 2011-07-06 00:28:32 +0000 | [diff] [blame] | 116 | val = readl(&gpio3->gpio_dr) | (1 << 10) | (1 << 11) | (1 << 12); |
| 117 | writel(val, &gpio3->gpio_dr); |
| 118 | val = readl(&gpio3->gpio_dir) | (1 << 10) | (1 << 11) | (1 << 12); |
| 119 | writel(val, &gpio3->gpio_dir); |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 120 | |
| 121 | mdelay(22); /* this value came from RedBoot */ |
| 122 | |
| 123 | /* |
| 124 | * deassert PHY reset |
| 125 | */ |
Matthias Weisser | 95d1858 | 2011-07-06 00:28:32 +0000 | [diff] [blame] | 126 | val = readl(&gpio4->gpio_dr) | 1 << 7; |
| 127 | writel(val, &gpio4->gpio_dr); |
| 128 | writel(val, &gpio4->gpio_dr); |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 129 | |
| 130 | mdelay(5); |
| 131 | |
| 132 | /* |
| 133 | * set FEC pins back |
| 134 | */ |
| 135 | writel(saved_rdata0_mode, &muxctl->pad_fec_rdata0); |
| 136 | writel(saved_rdata1_mode, &muxctl->pad_fec_rdata1); |
| 137 | writel(saved_rx_dv_mode, &muxctl->pad_fec_rx_dv); |
| 138 | } |
| 139 | #else |
| 140 | #define tx25_fec_init() |
| 141 | #endif |
| 142 | |
| 143 | int board_init() |
| 144 | { |
| 145 | #ifdef CONFIG_MXC_UART |
Fabio Estevam | 9aa720b | 2011-03-02 10:14:27 +0100 | [diff] [blame] | 146 | mx25_uart1_init_pins(); |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 147 | #endif |
Anatolij Gustschin | 87db58d | 2010-04-21 13:52:38 +0200 | [diff] [blame] | 148 | /* board id for linux */ |
| 149 | gd->bd->bi_arch_number = MACH_TYPE_TX25; |
| 150 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int board_late_init(void) |
| 155 | { |
| 156 | tx25_fec_init(); |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | int dram_init (void) |
| 161 | { |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 162 | /* dram_init must store complete ramsize in gd->ram_size */ |
Albert ARIBAUD | a55d23c | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 163 | gd->ram_size = get_ram_size((void *)PHYS_SDRAM_1, |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 164 | PHYS_SDRAM_1_SIZE); |
| 165 | return 0; |
| 166 | } |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 167 | |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 168 | void dram_init_banksize(void) |
| 169 | { |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 170 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
Albert ARIBAUD | a55d23c | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 171 | gd->bd->bi_dram[0].size = get_ram_size((void *)PHYS_SDRAM_1, |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 172 | PHYS_SDRAM_1_SIZE); |
| 173 | #if CONFIG_NR_DRAM_BANKS > 1 |
| 174 | gd->bd->bi_dram[1].start = PHYS_SDRAM_2; |
Albert ARIBAUD | a55d23c | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 175 | gd->bd->bi_dram[1].size = get_ram_size((void *)PHYS_SDRAM_2, |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 176 | PHYS_SDRAM_2_SIZE); |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 177 | #else |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 178 | |
Heiko Schocher | ab86f72 | 2010-09-17 13:10:42 +0200 | [diff] [blame] | 179 | #endif |
John Rigby | 6895d45 | 2010-01-25 23:12:58 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | int checkboard(void) |
| 183 | { |
| 184 | printf("KARO TX25\n"); |
| 185 | return 0; |
| 186 | } |