]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/tx28/tx28.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / board / karo / tx28 / tx28.c
1 /*
2  * Copyright (C) 2011 Lothar Waßmann <LW@KARO-electronics.de>
3  * based on: board/freesclae/mx28_evk.c (C) 2010 Freescale Semiconductor, Inc.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  */
23
24 #include <common.h>
25 #include <asm/arch/regs-pinctrl.h>
26 #include <asm/arch/pinctrl.h>
27 #include <asm/arch/regs-clkctrl.h>
28 #include <asm/arch/regs-ocotp.h>
29 #include <asm/errno.h>
30
31 #include <mmc.h>
32 #include <imx_ssp_mmc.h>
33
34 /* This should be removed after it's added into mach-types.h */
35
36 static const int mach_type = MACH_TYPE_TX28;
37
38 DECLARE_GLOBAL_DATA_PTR;
39
40 #ifdef CONFIG_IMX_SSP_MMC
41
42 /* MMC pins */
43 static struct pin_desc mmc0_pins_desc[] = {
44         { PINID_SSP0_DATA0, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
45         { PINID_SSP0_DATA1, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
46         { PINID_SSP0_DATA2, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
47         { PINID_SSP0_DATA3, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
48         { PINID_SSP0_DATA4, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
49         { PINID_SSP0_DATA5, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
50         { PINID_SSP0_DATA6, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
51         { PINID_SSP0_DATA7, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
52         { PINID_SSP0_CMD, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
53         { PINID_SSP0_DETECT, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
54         { PINID_SSP0_SCK, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
55 };
56
57 static struct pin_desc mmc1_pins_desc[] = {
58         { PINID_GPMI_D00, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
59         { PINID_GPMI_D01, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
60         { PINID_GPMI_D02, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
61         { PINID_GPMI_D03, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
62         { PINID_GPMI_D04, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
63         { PINID_GPMI_D05, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
64         { PINID_GPMI_D06, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
65         { PINID_GPMI_D07, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
66         { PINID_GPMI_RDY1, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
67         { PINID_GPMI_RDY0, PIN_FUN2, PAD_8MA, PAD_3V3, 1 },
68         { PINID_GPMI_WRN, PIN_FUN2, PAD_8MA, PAD_3V3, 1 }
69 };
70
71 static struct pin_group mmc0_pins = {
72         .pins           = mmc0_pins_desc,
73         .nr_pins        = ARRAY_SIZE(mmc0_pins_desc)
74 };
75
76 static struct pin_group mmc1_pins = {
77         .pins           = mmc1_pins_desc,
78         .nr_pins        = ARRAY_SIZE(mmc1_pins_desc)
79 };
80
81 struct imx_ssp_mmc_cfg ssp_mmc_cfg[2] = {
82         {REGS_SSP0_BASE, HW_CLKCTRL_SSP0, BM_CLKCTRL_CLKSEQ_BYPASS_SSP0},
83         {REGS_SSP1_BASE, HW_CLKCTRL_SSP1, BM_CLKCTRL_CLKSEQ_BYPASS_SSP1},
84 };
85 #endif
86
87 /* ENET pins */
88 static struct pin_desc enet_pins_desc[] = {
89         { PINID_ENET0_MDC, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
90         { PINID_ENET0_MDIO, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
91         { PINID_ENET0_RX_EN, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
92         { PINID_ENET0_RXD0, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
93         { PINID_ENET0_RXD1, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
94         { PINID_ENET0_TX_EN, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
95         { PINID_ENET0_TXD0, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
96         { PINID_ENET0_TXD1, PIN_FUN1, PAD_8MA, PAD_3V3, 1 },
97         { PINID_ENET_CLK, PIN_FUN1, PAD_8MA, PAD_3V3, 1 }
98 };
99
100 static struct pin_group enet_pins = {
101         .pins           = enet_pins_desc,
102         .nr_pins        = ARRAY_SIZE(enet_pins_desc),
103 };
104
105 static struct pin_desc duart_pins_desc[] = {
106         { PINID_PWM0, PIN_GPIO, PAD_8MA, PAD_3V3, 1 },
107         { PINID_PWM1, PIN_GPIO, PAD_8MA, PAD_3V3, 1 },
108         { PINID_I2C0_SCL, PIN_GPIO, PAD_8MA, PAD_3V3, 1 },
109         { PINID_I2C0_SDA, PIN_GPIO, PAD_8MA, PAD_3V3, 1 },
110
111         { PINID_AUART0_RTS, PIN_FUN3, PAD_8MA, PAD_3V3, 1 },
112         { PINID_AUART0_CTS, PIN_FUN3, PAD_8MA, PAD_3V3, 1 },
113         { PINID_AUART0_TX, PIN_FUN3, PAD_8MA, PAD_3V3, 1 },
114         { PINID_AUART0_RX, PIN_FUN3, PAD_8MA, PAD_3V3, 1 },
115 };
116
117 static struct pin_group duart_pins = {
118         .pins = duart_pins_desc,
119         .nr_pins = ARRAY_SIZE(duart_pins_desc),
120 };
121
122 /*
123  * Functions
124  */
125 static void duart_init(void)
126 {
127         pin_set_group(&duart_pins);
128 }
129
130 int board_init(void)
131 {
132         gd->bd->bi_arch_number = mach_type;
133
134         /* Address of boot parameters */
135         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x1000;
136
137         duart_init();
138         return 0;
139 }
140
141 int dram_init(void)
142 {
143         gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
144         gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
145
146         return 0;
147 }
148
149 #ifdef CONFIG_IMX_SSP_MMC
150
151 #ifdef CONFIG_DYNAMIC_MMC_DEVNO
152 int get_mmc_env_devno(void)
153 {
154         unsigned long global_boot_mode;
155
156         global_boot_mode = REG_RD_ADDR(GLOBAL_BOOT_MODE_ADDR);
157         return ((global_boot_mode & 0xf) == BOOT_MODE_SD1) ? 1 : 0;
158 }
159 #endif
160
161 #define PINID_SSP0_GPIO_WP PINID_SSP1_SCK
162 #define PINID_SSP1_GPIO_WP PINID_GPMI_RESETN
163
164 u32 ssp_mmc_is_wp(struct mmc *mmc)
165 {
166         return 0;
167 }
168
169 int ssp_mmc_gpio_init(bd_t *bis)
170 {
171         s32 status = 0;
172         u32 index = 0;
173
174         for (index = 0; index < CONFIG_SYS_SSP_MMC_NUM; index++) {
175                 switch (index) {
176                 case 0:
177                         /* Set up MMC pins */
178                         pin_set_group(&mmc0_pins);
179                         break;
180
181                 case 1:
182                         /* Set up MMC pins */
183                         pin_set_group(&mmc1_pins);
184                         break;
185
186                 default:
187                         printf("Warning: more ssp mmc controllers configured(%d) than supported by the board(2)\n",
188                                 CONFIG_SYS_SSP_MMC_NUM);
189                         return status;
190                 }
191                 status |= imx_ssp_mmc_initialize(bis, &ssp_mmc_cfg[index]);
192         }
193
194         return status;
195 }
196
197 int board_mmc_init(bd_t *bis)
198 {
199         if (!ssp_mmc_gpio_init(bis))
200                 return 0;
201         else
202                 return -1;
203 }
204
205 #endif
206
207 #if defined(CONFIG_MXC_FEC) && defined(CONFIG_GET_FEC_MAC_ADDR_FROM_IIM)
208 int fec_get_mac_addr(unsigned char *mac)
209 {
210         u32 val;
211         int timeout = 1000;
212
213         /* set this bit to open the OTP banks for reading */
214         REG_WR(REGS_OCOTP_BASE, HW_OCOTP_CTRL_SET,
215                 BM_OCOTP_CTRL_RD_BANK_OPEN);
216
217         /* wait until OTP contents are readable */
218         while (BM_OCOTP_CTRL_BUSY & REG_RD(REGS_OCOTP_BASE, HW_OCOTP_CTRL)) {
219                 if (timeout-- < 0)
220                         return -ETIMEDOUT;
221                 udelay(100);
222         }
223
224         val = REG_RD(REGS_OCOTP_BASE, HW_OCOTP_CUSTn(0));
225         mac[0] = (val >> 24) & 0xFF;
226         mac[1] = (val >> 16) & 0xFF;
227         mac[2] = (val >> 8) & 0xFF;
228         mac[3] = (val >> 0) & 0xFF;
229         val = REG_RD(REGS_OCOTP_BASE, HW_OCOTP_CUSTn(1));
230         mac[4] = (val >> 24) & 0xFF;
231         mac[5] = (val >> 16) & 0xFF;
232
233         return 0;
234 }
235 #endif
236
237 void enet_board_init(void)
238 {
239         /* Set up ENET pins */
240         pin_set_group(&enet_pins);
241
242         /* Power on the external phy */
243         pin_gpio_set(PINID_PWM4, 1);
244         pin_gpio_direction(PINID_PWM4, 1);
245         pin_set_type(PINID_PWM4, PIN_GPIO);
246
247         /* Reset the external phy */
248         pin_gpio_set(PINID_ENET0_RX_CLK, 0);
249         pin_gpio_direction(PINID_ENET0_RX_CLK, 1);
250         pin_set_type(PINID_ENET0_RX_CLK, PIN_GPIO);
251         udelay(200);
252         pin_gpio_set(PINID_ENET0_RX_CLK, 1);
253 }
254
255 int checkboard(void)
256 {
257         printf("Board: Ka-Ro TX28\n");
258
259         return 0;
260 }