]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/karo/tx28/tx28.c
Add missing mmc write protect callback
[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 <errno.h>
26 #include <asm/io.h>
27 #include <asm/gpio.h>
28 #include <asm/arch/iomux-mx28.h>
29 #include <asm/arch/clock.h>
30 #include <asm/arch/imx-regs.h>
31 #include <asm/arch/regs-pinctrl.h>
32 #include <asm/arch/regs-clkctrl.h>
33 #include <asm/arch/regs-ocotp.h>
34 #include <asm/arch/sys_proto.h>
35
36 #include <mmc.h>
37 #include <netdev.h>
38 #include <imx_ssp_mmc.h>
39
40 DECLARE_GLOBAL_DATA_PTR;
41
42 /*
43  * Functions
44  */
45 int board_early_init_f(void)
46 {
47         /* IO0 clock at 480MHz */
48         mx28_set_ioclk(MXC_IOCLK0, 480000);
49         /* IO1 clock at 480MHz */
50         mx28_set_ioclk(MXC_IOCLK1, 480000);
51
52         /* SSP0 clock at 96MHz */
53         mx28_set_sspclk(MXC_SSPCLK0, 96000, 0);
54         /* SSP2 clock at 96MHz */
55         mx28_set_sspclk(MXC_SSPCLK2, 96000, 0);
56
57         return 0;
58 }
59
60 void coloured_LED_init(void)
61 {
62         /* Switch LED off */
63         gpio_set_value(MX28_PAD_ENET0_RXD3__GPIO_4_10, 0);
64 }
65
66 int board_init(void)
67 {
68         /* Address of boot parameters */
69         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x1000;
70         return 0;
71 }
72
73 int dram_init(void)
74 {
75         return mx28_dram_init();
76 }
77
78 #ifdef  CONFIG_CMD_MMC
79 static int tx28_mmc_wp(int dev_no)
80 {
81         return 0;
82 }
83
84 int board_mmc_init(bd_t *bis)
85 {
86         return mxsmmc_initialize(bis, 0, tx28_mmc_wp);
87 }
88 #endif /* CONFIG_CMD_MMC */
89
90 #ifdef CONFIG_FEC_MXC
91 #ifdef CONFIG_GET_FEC_MAC_ADDR_FROM_IIM
92
93 #ifdef CONFIG_FEC_MXC_MULTI
94 #define FEC_MAX_IDX                     1
95 #else
96 #define FEC_MAX_IDX                     0
97 #endif
98
99 static int fec_get_mac_addr(int index)
100 {
101         u32 val1, val2;
102         int timeout = 1000;
103         struct mx28_ocotp_regs *ocotp_regs =
104                 (struct mx28_ocotp_regs *)MXS_OCOTP_BASE;
105         u32 *cust = &ocotp_regs->hw_ocotp_cust0;
106         char mac[6 * 3];
107         char env_name[] = "eth.addr";
108
109         if (index < 0 || index > FEC_MAX_IDX)
110                 return -EINVAL;
111
112         /* set this bit to open the OTP banks for reading */
113         writel(OCOTP_CTRL_RD_BANK_OPEN,
114                 &ocotp_regs->hw_ocotp_ctrl_set);
115
116         /* wait until OTP contents are readable */
117         while (OCOTP_CTRL_BUSY & readl(&ocotp_regs->hw_ocotp_ctrl)) {
118                 if (timeout-- < 0)
119                         return -ETIMEDOUT;
120                 udelay(100);
121         }
122
123         val1 = readl(&cust[index * 8]);
124         val2 = readl(&cust[index * 8 + 4]);
125         if ((val1 | val2) == 0)
126                 return 0;
127         snprintf(mac, sizeof(mac), "%02x:%02x:%02x:%02x:%02x:%02x",
128                 (val1 >> 24) & 0xFF, (val1 >> 16) & 0xFF,
129                 (val1 >> 8) & 0xFF, (val1 >> 0) & 0xFF,
130                 (val2 >> 24) & 0xFF, (val2 >> 16) & 0xFF);
131         if (index == 0)
132                 snprintf(env_name, sizeof(env_name), "ethaddr");
133         else
134                 snprintf(env_name, sizeof(env_name), "eth%daddr", index);
135
136         setenv(env_name, mac);
137         return 0;
138 }
139 #endif /* CONFIG_GET_FEC_MAC_ADDR_FROM_IIM */
140
141 static iomux_cfg_t tx28_fec_pads[] = {
142         MX28_PAD_ENET0_RX_EN__ENET0_RX_EN,
143         MX28_PAD_ENET0_RXD0__ENET0_RXD0,
144         MX28_PAD_ENET0_RXD1__ENET0_RXD1,
145 };
146
147 int board_eth_init(bd_t *bis)
148 {
149         int ret;
150
151         /* Reset the external phy */
152         gpio_direction_output(MX28_PAD_ENET0_RX_CLK__GPIO_4_13, 0);
153
154         /* Power on the external phy */
155         gpio_direction_output(MX28_PAD_PWM4__GPIO_3_29, 1);
156
157         /* Pull strap pins to high */
158         gpio_direction_output(MX28_PAD_ENET0_RX_EN__GPIO_4_2, 1);
159         gpio_direction_output(MX28_PAD_ENET0_RXD0__GPIO_4_3, 1);
160         gpio_direction_output(MX28_PAD_ENET0_RXD1__GPIO_4_4, 1);
161         gpio_direction_input(MX28_PAD_ENET0_TX_CLK__GPIO_4_5);
162
163         udelay(25000);
164         gpio_set_value(MX28_PAD_ENET0_RX_CLK__GPIO_4_13, 1);
165         udelay(100);
166
167         mxs_iomux_setup_multiple_pads(tx28_fec_pads, ARRAY_SIZE(tx28_fec_pads));
168
169         ret = cpu_eth_init(bis);
170         if (ret) {
171                 printf("cpu_eth_init() failed: %d\n", ret);
172                 return ret;
173         }
174
175         ret = fec_get_mac_addr(0);
176         if (ret < 0) {
177                 printf("Failed to read FEC0 MAC address from OCOTP\n");
178                 return ret;
179         }
180 #ifdef CONFIG_FEC_MXC_MULTI
181         if (getenv("ethaddr")) {
182                 ret = fecmxc_initialize_multi(bis, 0, 0, MXS_ENET0_BASE);
183                 if (ret) {
184                         printf("FEC MXS: Unable to init FEC0\n");
185                         return ret;
186                 }
187         }
188
189         ret = fec_get_mac_addr(1);
190         if (ret < 0) {
191                 printf("Failed to read FEC1 MAC address from OCOTP\n");
192                 return ret;
193         }
194         if (getenv("eth1addr")) {
195                 ret = fecmxc_initialize_multi(bis, 1, 1, MXS_ENET1_BASE);
196                 if (ret) {
197                         printf("FEC MXS: Unable to init FEC1\n");
198                         return ret;
199                 }
200         }
201         return 0;
202 #else
203         if (getenv("ethaddr")) {
204                 ret = fecmxc_initialize(bis);
205         }
206         return ret;
207 #endif
208 }
209 #endif /* CONFIG_FEC_MXC */
210
211 enum {
212         LED_STATE_INIT = -1,
213         LED_STATE_OFF,
214         LED_STATE_ON,
215 };
216
217 void show_activity(int arg)
218 {
219         static int led_state = LED_STATE_INIT;
220         static ulong last;
221
222         if (led_state == LED_STATE_INIT) {
223                 last = get_timer(0);
224                 gpio_set_value(MX28_PAD_ENET0_RXD3__GPIO_4_10, 1);
225                 led_state = LED_STATE_ON;
226         } else {
227                 if (get_timer(last) > CONFIG_SYS_HZ) {
228                         last = get_timer(0);
229                         if (led_state == LED_STATE_ON) {
230                                 gpio_set_value(MX28_PAD_ENET0_RXD3__GPIO_4_10, 0);
231                         } else {
232                                 gpio_set_value(MX28_PAD_ENET0_RXD3__GPIO_4_10, 1);
233                         }
234                         led_state = 1 - led_state;
235                 }
236         }
237 }