1
2
3
4
5
6
7
8
9
10
11#include <common.h>
12#include <errno.h>
13#include <spl.h>
14#include <serial.h>
15#include <asm/arch/cpu.h>
16#include <asm/arch/hardware.h>
17#include <asm/arch/omap.h>
18#include <asm/arch/ddr_defs.h>
19#include <asm/arch/clock.h>
20#include <asm/arch/clk_synthesizer.h>
21#include <asm/arch/gpio.h>
22#include <asm/arch/mmc_host_def.h>
23#include <asm/arch/sys_proto.h>
24#include <asm/arch/mem.h>
25#include <asm/io.h>
26#include <asm/emif.h>
27#include <asm/gpio.h>
28#include <asm/omap_sec_common.h>
29#include <i2c.h>
30#include <miiphy.h>
31#include <cpsw.h>
32#include <power/tps65217.h>
33#include <power/tps65910.h>
34#include <environment.h>
35#include <watchdog.h>
36#include <environment.h>
37#include "../common/board_detect.h"
38#include "board.h"
39
40DECLARE_GLOBAL_DATA_PTR;
41
42
43#define GPIO_TO_PIN(bank, gpio) (32 * (bank) + (gpio))
44#define GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 7)
45#define ICE_GPIO_DDR_VTT_EN GPIO_TO_PIN(0, 18)
46#define GPIO_PR1_MII_CTRL GPIO_TO_PIN(3, 4)
47#define GPIO_MUX_MII_CTRL GPIO_TO_PIN(3, 10)
48#define GPIO_FET_SWITCH_CTRL GPIO_TO_PIN(0, 7)
49#define GPIO_PHY_RESET GPIO_TO_PIN(2, 5)
50#define GPIO_ETH0_MODE GPIO_TO_PIN(0, 11)
51#define GPIO_ETH1_MODE GPIO_TO_PIN(1, 26)
52
53static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
54
55#define GPIO0_RISINGDETECT (AM33XX_GPIO0_BASE + OMAP_GPIO_RISINGDETECT)
56#define GPIO1_RISINGDETECT (AM33XX_GPIO1_BASE + OMAP_GPIO_RISINGDETECT)
57
58#define GPIO0_IRQSTATUS1 (AM33XX_GPIO0_BASE + OMAP_GPIO_IRQSTATUS1)
59#define GPIO1_IRQSTATUS1 (AM33XX_GPIO1_BASE + OMAP_GPIO_IRQSTATUS1)
60
61#define GPIO0_IRQSTATUSRAW (AM33XX_GPIO0_BASE + 0x024)
62#define GPIO1_IRQSTATUSRAW (AM33XX_GPIO1_BASE + 0x024)
63
64
65
66
67#ifdef CONFIG_TI_I2C_BOARD_DETECT
68void do_board_detect(void)
69{
70 enable_i2c0_pin_mux();
71 i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
72
73 if (ti_i2c_eeprom_am_get(-1, CONFIG_SYS_I2C_EEPROM_ADDR))
74 printf("ti_i2c_eeprom_init failed\n");
75}
76#endif
77
78#ifndef CONFIG_DM_SERIAL
79struct serial_device *default_serial_console(void)
80{
81 if (board_is_icev2())
82 return &eserial4_device;
83 else
84 return &eserial1_device;
85}
86#endif
87
88#ifndef CONFIG_SKIP_LOWLEVEL_INIT
89static const struct ddr_data ddr2_data = {
90 .datardsratio0 = MT47H128M16RT25E_RD_DQS,
91 .datafwsratio0 = MT47H128M16RT25E_PHY_FIFO_WE,
92 .datawrsratio0 = MT47H128M16RT25E_PHY_WR_DATA,
93};
94
95static const struct cmd_control ddr2_cmd_ctrl_data = {
96 .cmd0csratio = MT47H128M16RT25E_RATIO,
97
98 .cmd1csratio = MT47H128M16RT25E_RATIO,
99
100 .cmd2csratio = MT47H128M16RT25E_RATIO,
101};
102
103static const struct emif_regs ddr2_emif_reg_data = {
104 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
105 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
106 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
107 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
108 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
109 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
110};
111
112static const struct emif_regs ddr2_evm_emif_reg_data = {
113 .sdram_config = MT47H128M16RT25E_EMIF_SDCFG,
114 .ref_ctrl = MT47H128M16RT25E_EMIF_SDREF,
115 .sdram_tim1 = MT47H128M16RT25E_EMIF_TIM1,
116 .sdram_tim2 = MT47H128M16RT25E_EMIF_TIM2,
117 .sdram_tim3 = MT47H128M16RT25E_EMIF_TIM3,
118 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
119 .emif_ddr_phy_ctlr_1 = MT47H128M16RT25E_EMIF_READ_LATENCY,
120};
121
122static const struct ddr_data ddr3_data = {
123 .datardsratio0 = MT41J128MJT125_RD_DQS,
124 .datawdsratio0 = MT41J128MJT125_WR_DQS,
125 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE,
126 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA,
127};
128
129static const struct ddr_data ddr3_beagleblack_data = {
130 .datardsratio0 = MT41K256M16HA125E_RD_DQS,
131 .datawdsratio0 = MT41K256M16HA125E_WR_DQS,
132 .datafwsratio0 = MT41K256M16HA125E_PHY_FIFO_WE,
133 .datawrsratio0 = MT41K256M16HA125E_PHY_WR_DATA,
134};
135
136static const struct ddr_data ddr3_evm_data = {
137 .datardsratio0 = MT41J512M8RH125_RD_DQS,
138 .datawdsratio0 = MT41J512M8RH125_WR_DQS,
139 .datafwsratio0 = MT41J512M8RH125_PHY_FIFO_WE,
140 .datawrsratio0 = MT41J512M8RH125_PHY_WR_DATA,
141};
142
143static const struct ddr_data ddr3_icev2_data = {
144 .datardsratio0 = MT41J128MJT125_RD_DQS_400MHz,
145 .datawdsratio0 = MT41J128MJT125_WR_DQS_400MHz,
146 .datafwsratio0 = MT41J128MJT125_PHY_FIFO_WE_400MHz,
147 .datawrsratio0 = MT41J128MJT125_PHY_WR_DATA_400MHz,
148};
149
150static const struct cmd_control ddr3_cmd_ctrl_data = {
151 .cmd0csratio = MT41J128MJT125_RATIO,
152 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT,
153
154 .cmd1csratio = MT41J128MJT125_RATIO,
155 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT,
156
157 .cmd2csratio = MT41J128MJT125_RATIO,
158 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT,
159};
160
161static const struct cmd_control ddr3_beagleblack_cmd_ctrl_data = {
162 .cmd0csratio = MT41K256M16HA125E_RATIO,
163 .cmd0iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
164
165 .cmd1csratio = MT41K256M16HA125E_RATIO,
166 .cmd1iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
167
168 .cmd2csratio = MT41K256M16HA125E_RATIO,
169 .cmd2iclkout = MT41K256M16HA125E_INVERT_CLKOUT,
170};
171
172static const struct cmd_control ddr3_evm_cmd_ctrl_data = {
173 .cmd0csratio = MT41J512M8RH125_RATIO,
174 .cmd0iclkout = MT41J512M8RH125_INVERT_CLKOUT,
175
176 .cmd1csratio = MT41J512M8RH125_RATIO,
177 .cmd1iclkout = MT41J512M8RH125_INVERT_CLKOUT,
178
179 .cmd2csratio = MT41J512M8RH125_RATIO,
180 .cmd2iclkout = MT41J512M8RH125_INVERT_CLKOUT,
181};
182
183static const struct cmd_control ddr3_icev2_cmd_ctrl_data = {
184 .cmd0csratio = MT41J128MJT125_RATIO_400MHz,
185 .cmd0iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
186
187 .cmd1csratio = MT41J128MJT125_RATIO_400MHz,
188 .cmd1iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
189
190 .cmd2csratio = MT41J128MJT125_RATIO_400MHz,
191 .cmd2iclkout = MT41J128MJT125_INVERT_CLKOUT_400MHz,
192};
193
194static struct emif_regs ddr3_emif_reg_data = {
195 .sdram_config = MT41J128MJT125_EMIF_SDCFG,
196 .ref_ctrl = MT41J128MJT125_EMIF_SDREF,
197 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1,
198 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2,
199 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3,
200 .zq_config = MT41J128MJT125_ZQ_CFG,
201 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY |
202 PHY_EN_DYN_PWRDN,
203};
204
205static struct emif_regs ddr3_beagleblack_emif_reg_data = {
206 .sdram_config = MT41K256M16HA125E_EMIF_SDCFG,
207 .ref_ctrl = MT41K256M16HA125E_EMIF_SDREF,
208 .sdram_tim1 = MT41K256M16HA125E_EMIF_TIM1,
209 .sdram_tim2 = MT41K256M16HA125E_EMIF_TIM2,
210 .sdram_tim3 = MT41K256M16HA125E_EMIF_TIM3,
211 .ocp_config = EMIF_OCP_CONFIG_BEAGLEBONE_BLACK,
212 .zq_config = MT41K256M16HA125E_ZQ_CFG,
213 .emif_ddr_phy_ctlr_1 = MT41K256M16HA125E_EMIF_READ_LATENCY,
214};
215
216static struct emif_regs ddr3_evm_emif_reg_data = {
217 .sdram_config = MT41J512M8RH125_EMIF_SDCFG,
218 .ref_ctrl = MT41J512M8RH125_EMIF_SDREF,
219 .sdram_tim1 = MT41J512M8RH125_EMIF_TIM1,
220 .sdram_tim2 = MT41J512M8RH125_EMIF_TIM2,
221 .sdram_tim3 = MT41J512M8RH125_EMIF_TIM3,
222 .ocp_config = EMIF_OCP_CONFIG_AM335X_EVM,
223 .zq_config = MT41J512M8RH125_ZQ_CFG,
224 .emif_ddr_phy_ctlr_1 = MT41J512M8RH125_EMIF_READ_LATENCY |
225 PHY_EN_DYN_PWRDN,
226};
227
228static struct emif_regs ddr3_icev2_emif_reg_data = {
229 .sdram_config = MT41J128MJT125_EMIF_SDCFG_400MHz,
230 .ref_ctrl = MT41J128MJT125_EMIF_SDREF_400MHz,
231 .sdram_tim1 = MT41J128MJT125_EMIF_TIM1_400MHz,
232 .sdram_tim2 = MT41J128MJT125_EMIF_TIM2_400MHz,
233 .sdram_tim3 = MT41J128MJT125_EMIF_TIM3_400MHz,
234 .zq_config = MT41J128MJT125_ZQ_CFG_400MHz,
235 .emif_ddr_phy_ctlr_1 = MT41J128MJT125_EMIF_READ_LATENCY_400MHz |
236 PHY_EN_DYN_PWRDN,
237};
238
239#ifdef CONFIG_SPL_OS_BOOT
240int spl_start_uboot(void)
241{
242
243 if (serial_tstc() && serial_getc() == 'c')
244 return 1;
245
246#ifdef CONFIG_SPL_ENV_SUPPORT
247 env_init();
248 env_relocate_spec();
249 if (getenv_yesno("boot_os") != 1)
250 return 1;
251#endif
252
253 return 0;
254}
255#endif
256
257#define OSC (V_OSCK/1000000)
258const struct dpll_params dpll_ddr = {
259 266, OSC-1, 1, -1, -1, -1, -1};
260const struct dpll_params dpll_ddr_evm_sk = {
261 303, OSC-1, 1, -1, -1, -1, -1};
262const struct dpll_params dpll_ddr_bone_black = {
263 400, OSC-1, 1, -1, -1, -1, -1};
264
265void am33xx_spl_board_init(void)
266{
267 int mpu_vdd;
268
269
270 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
271
272 if (board_is_bone() || board_is_bone_lt()) {
273
274 int usb_cur_lim;
275
276
277
278
279
280 if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
281 return;
282
283 if (i2c_probe(TPS65217_CHIP_PM))
284 return;
285
286
287
288
289
290 if (board_is_bone()) {
291 uchar pmic_status_reg;
292 if (tps65217_reg_read(TPS65217_STATUS,
293 &pmic_status_reg))
294 return;
295 if (!(pmic_status_reg & TPS65217_PWR_SRC_AC_BITMASK)) {
296 puts("No AC power, disabling frequency switch\n");
297 return;
298 }
299 }
300
301
302
303
304
305 if (board_is_bone_lt())
306 dpll_mpu_opp100.m = MPUPLL_M_1000;
307
308
309
310
311
312 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
313 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
314 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
315 } else {
316 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
317 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
318 }
319
320 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
321 TPS65217_POWER_PATH,
322 usb_cur_lim,
323 TPS65217_USB_INPUT_CUR_LIMIT_MASK))
324 puts("tps65217_reg_write failure\n");
325
326
327 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
328 TPS65217_DCDC_VOLT_SEL_1125MV)) {
329 puts("tps65217_voltage_update failure\n");
330 return;
331 }
332
333
334 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
335
336
337 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
338 puts("tps65217_voltage_update failure\n");
339 return;
340 }
341
342
343
344
345
346 if (board_is_bone()) {
347 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
348 TPS65217_DEFLS1,
349 TPS65217_LDO_VOLTAGE_OUT_3_3,
350 TPS65217_LDO_MASK))
351 puts("tps65217_reg_write failure\n");
352 } else {
353 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
354 TPS65217_DEFLS1,
355 TPS65217_LDO_VOLTAGE_OUT_1_8,
356 TPS65217_LDO_MASK))
357 puts("tps65217_reg_write failure\n");
358 }
359
360 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
361 TPS65217_DEFLS2,
362 TPS65217_LDO_VOLTAGE_OUT_3_3,
363 TPS65217_LDO_MASK))
364 puts("tps65217_reg_write failure\n");
365 } else {
366 int sil_rev;
367
368
369
370
371
372
373
374 if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
375 return;
376
377
378
379
380
381 sil_rev = readl(&cdev->deviceid) >> 28;
382 mpu_vdd = am335x_get_tps65910_mpu_vdd(sil_rev,
383 dpll_mpu_opp100.m);
384
385
386 tps65910_set_i2c_control();
387
388
389 if (tps65910_voltage_update(MPU, mpu_vdd))
390 return;
391
392
393 if (tps65910_voltage_update(CORE, TPS65910_OP_REG_SEL_1_1_3))
394 return;
395
396
397 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
398 }
399
400
401 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
402}
403
404const struct dpll_params *get_dpll_ddr_params(void)
405{
406 if (board_is_evm_sk())
407 return &dpll_ddr_evm_sk;
408 else if (board_is_bone_lt() || board_is_icev2())
409 return &dpll_ddr_bone_black;
410 else if (board_is_evm_15_or_later())
411 return &dpll_ddr_evm_sk;
412 else
413 return &dpll_ddr;
414}
415
416void set_uart_mux_conf(void)
417{
418#if CONFIG_CONS_INDEX == 1
419 enable_uart0_pin_mux();
420#elif CONFIG_CONS_INDEX == 2
421 enable_uart1_pin_mux();
422#elif CONFIG_CONS_INDEX == 3
423 enable_uart2_pin_mux();
424#elif CONFIG_CONS_INDEX == 4
425 enable_uart3_pin_mux();
426#elif CONFIG_CONS_INDEX == 5
427 enable_uart4_pin_mux();
428#elif CONFIG_CONS_INDEX == 6
429 enable_uart5_pin_mux();
430#endif
431}
432
433void set_mux_conf_regs(void)
434{
435 enable_board_pin_mux();
436}
437
438const struct ctrl_ioregs ioregs_evmsk = {
439 .cm0ioctl = MT41J128MJT125_IOCTRL_VALUE,
440 .cm1ioctl = MT41J128MJT125_IOCTRL_VALUE,
441 .cm2ioctl = MT41J128MJT125_IOCTRL_VALUE,
442 .dt0ioctl = MT41J128MJT125_IOCTRL_VALUE,
443 .dt1ioctl = MT41J128MJT125_IOCTRL_VALUE,
444};
445
446const struct ctrl_ioregs ioregs_bonelt = {
447 .cm0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
448 .cm1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
449 .cm2ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
450 .dt0ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
451 .dt1ioctl = MT41K256M16HA125E_IOCTRL_VALUE,
452};
453
454const struct ctrl_ioregs ioregs_evm15 = {
455 .cm0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
456 .cm1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
457 .cm2ioctl = MT41J512M8RH125_IOCTRL_VALUE,
458 .dt0ioctl = MT41J512M8RH125_IOCTRL_VALUE,
459 .dt1ioctl = MT41J512M8RH125_IOCTRL_VALUE,
460};
461
462const struct ctrl_ioregs ioregs = {
463 .cm0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
464 .cm1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
465 .cm2ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
466 .dt0ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
467 .dt1ioctl = MT47H128M16RT25E_IOCTRL_VALUE,
468};
469
470void sdram_init(void)
471{
472 if (board_is_evm_sk()) {
473
474
475
476
477 gpio_request(GPIO_DDR_VTT_EN, "ddr_vtt_en");
478 gpio_direction_output(GPIO_DDR_VTT_EN, 1);
479 }
480
481 if (board_is_icev2()) {
482 gpio_request(ICE_GPIO_DDR_VTT_EN, "ddr_vtt_en");
483 gpio_direction_output(ICE_GPIO_DDR_VTT_EN, 1);
484 }
485
486 if (board_is_evm_sk())
487 config_ddr(303, &ioregs_evmsk, &ddr3_data,
488 &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0);
489 else if (board_is_bone_lt())
490 config_ddr(400, &ioregs_bonelt,
491 &ddr3_beagleblack_data,
492 &ddr3_beagleblack_cmd_ctrl_data,
493 &ddr3_beagleblack_emif_reg_data, 0);
494 else if (board_is_evm_15_or_later())
495 config_ddr(303, &ioregs_evm15, &ddr3_evm_data,
496 &ddr3_evm_cmd_ctrl_data, &ddr3_evm_emif_reg_data, 0);
497 else if (board_is_icev2())
498 config_ddr(400, &ioregs_evmsk, &ddr3_icev2_data,
499 &ddr3_icev2_cmd_ctrl_data, &ddr3_icev2_emif_reg_data,
500 0);
501 else if (board_is_gp_evm())
502 config_ddr(266, &ioregs, &ddr2_data,
503 &ddr2_cmd_ctrl_data, &ddr2_evm_emif_reg_data, 0);
504 else
505 config_ddr(266, &ioregs, &ddr2_data,
506 &ddr2_cmd_ctrl_data, &ddr2_emif_reg_data, 0);
507}
508#endif
509
510#if !defined(CONFIG_SPL_BUILD) || \
511 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
512static void request_and_set_gpio(int gpio, char *name, int val)
513{
514 int ret;
515
516 ret = gpio_request(gpio, name);
517 if (ret < 0) {
518 printf("%s: Unable to request %s\n", __func__, name);
519 return;
520 }
521
522 ret = gpio_direction_output(gpio, 0);
523 if (ret < 0) {
524 printf("%s: Unable to set %s as output\n", __func__, name);
525 goto err_free_gpio;
526 }
527
528 gpio_set_value(gpio, val);
529
530 return;
531
532err_free_gpio:
533 gpio_free(gpio);
534}
535
536#define REQUEST_AND_SET_GPIO(N) request_and_set_gpio(N, #N, 1);
537#define REQUEST_AND_CLR_GPIO(N) request_and_set_gpio(N, #N, 0);
538
539
540
541
542
543
544
545static struct clk_synth cdce913_data = {
546 .id = 0x81,
547 .capacitor = 0x90,
548 .mux = 0x6d,
549 .pdiv2 = 0x2,
550 .pdiv3 = 0x2,
551};
552#endif
553
554
555
556
557int board_init(void)
558{
559#if defined(CONFIG_HW_WATCHDOG)
560 hw_watchdog_init();
561#endif
562
563 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
564#if defined(CONFIG_NOR) || defined(CONFIG_NAND)
565 gpmc_init();
566#endif
567
568#if !defined(CONFIG_SPL_BUILD) || \
569 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
570 if (board_is_icev2()) {
571 int rv;
572 u32 reg;
573
574 REQUEST_AND_SET_GPIO(GPIO_PR1_MII_CTRL);
575
576 REQUEST_AND_CLR_GPIO(GPIO_MUX_MII_CTRL);
577
578 REQUEST_AND_SET_GPIO(GPIO_FET_SWITCH_CTRL);
579
580
581
582
583
584
585
586
587 REQUEST_AND_SET_GPIO(GPIO_PHY_RESET);
588
589 reg = readl(GPIO0_RISINGDETECT) | BIT(11);
590 writel(reg, GPIO0_RISINGDETECT);
591 reg = readl(GPIO1_RISINGDETECT) | BIT(26);
592 writel(reg, GPIO1_RISINGDETECT);
593
594 gpio_set_value(GPIO_PHY_RESET, 0);
595 udelay(2);
596 gpio_set_value(GPIO_PHY_RESET, 1);
597
598 reg = readl(GPIO0_IRQSTATUSRAW) & BIT(11);
599 if (reg) {
600 writel(reg, GPIO0_IRQSTATUS1);
601
602 printf("ETH0, CPSW\n");
603 } else {
604
605 printf("ETH0, PRU\n");
606 cdce913_data.pdiv3 = 4;
607 }
608
609 reg = readl(GPIO1_IRQSTATUSRAW) & BIT(26);
610 if (reg) {
611 writel(reg, GPIO1_IRQSTATUS1);
612
613 printf("ETH1, CPSW\n");
614 gpio_set_value(GPIO_MUX_MII_CTRL, 1);
615 } else {
616
617 printf("ETH1, PRU\n");
618 cdce913_data.pdiv2 = 4;
619 }
620
621
622 reg = readl(GPIO0_RISINGDETECT) & ~BIT(11);
623 writel(reg, GPIO0_RISINGDETECT);
624 reg = readl(GPIO1_RISINGDETECT) & ~BIT(26);
625 writel(reg, GPIO1_RISINGDETECT);
626
627 rv = setup_clock_synthesizer(&cdce913_data);
628 if (rv) {
629 printf("Clock synthesizer setup failed %d\n", rv);
630 return rv;
631 }
632
633
634 gpio_set_value(GPIO_PHY_RESET, 0);
635 udelay(2);
636 gpio_set_value(GPIO_PHY_RESET, 1);
637 }
638#endif
639
640 return 0;
641}
642
643#ifdef CONFIG_BOARD_LATE_INIT
644int board_late_init(void)
645{
646#if !defined(CONFIG_SPL_BUILD)
647 uint8_t mac_addr[6];
648 uint32_t mac_hi, mac_lo;
649#endif
650
651#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
652 char *name = NULL;
653
654 if (board_is_bbg1())
655 name = "BBG1";
656 set_board_info_env(name);
657
658
659
660
661
662 if (get_device_type() == HS_DEVICE)
663 setenv("boot_fit", "1");
664#endif
665
666#if !defined(CONFIG_SPL_BUILD)
667
668 mac_lo = readl(&cdev->macid0l);
669 mac_hi = readl(&cdev->macid0h);
670 mac_addr[0] = mac_hi & 0xFF;
671 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
672 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
673 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
674 mac_addr[4] = mac_lo & 0xFF;
675 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
676
677 if (!getenv("ethaddr")) {
678 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
679
680 if (is_valid_ethaddr(mac_addr))
681 eth_setenv_enetaddr("ethaddr", mac_addr);
682 }
683
684 mac_lo = readl(&cdev->macid1l);
685 mac_hi = readl(&cdev->macid1h);
686 mac_addr[0] = mac_hi & 0xFF;
687 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
688 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
689 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
690 mac_addr[4] = mac_lo & 0xFF;
691 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
692
693 if (!getenv("eth1addr")) {
694 if (is_valid_ethaddr(mac_addr))
695 eth_setenv_enetaddr("eth1addr", mac_addr);
696 }
697#endif
698
699 return 0;
700}
701#endif
702
703#ifndef CONFIG_DM_ETH
704
705#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
706 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
707static void cpsw_control(int enabled)
708{
709
710
711 return;
712}
713
714static struct cpsw_slave_data cpsw_slaves[] = {
715 {
716 .slave_reg_ofs = 0x208,
717 .sliver_reg_ofs = 0xd80,
718 .phy_addr = 0,
719 },
720 {
721 .slave_reg_ofs = 0x308,
722 .sliver_reg_ofs = 0xdc0,
723 .phy_addr = 1,
724 },
725};
726
727static struct cpsw_platform_data cpsw_data = {
728 .mdio_base = CPSW_MDIO_BASE,
729 .cpsw_base = CPSW_BASE,
730 .mdio_div = 0xff,
731 .channels = 8,
732 .cpdma_reg_ofs = 0x800,
733 .slaves = 1,
734 .slave_data = cpsw_slaves,
735 .ale_reg_ofs = 0xd00,
736 .ale_entries = 1024,
737 .host_port_reg_ofs = 0x108,
738 .hw_stats_reg_ofs = 0x900,
739 .bd_ram_ofs = 0x2000,
740 .mac_control = (1 << 5),
741 .control = cpsw_control,
742 .host_port_num = 0,
743 .version = CPSW_CTRL_VERSION_2,
744};
745#endif
746
747#if ((defined(CONFIG_SPL_ETH_SUPPORT) || defined(CONFIG_SPL_USBETH_SUPPORT)) &&\
748 defined(CONFIG_SPL_BUILD)) || \
749 ((defined(CONFIG_DRIVER_TI_CPSW) || \
750 defined(CONFIG_USB_ETHER) && defined(CONFIG_MUSB_GADGET)) && \
751 !defined(CONFIG_SPL_BUILD))
752
753
754
755
756
757
758
759
760
761
762
763
764int board_eth_init(bd_t *bis)
765{
766 int rv, n = 0;
767#if defined(CONFIG_USB_ETHER) && \
768 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
769 uint8_t mac_addr[6];
770 uint32_t mac_hi, mac_lo;
771
772
773
774
775
776 mac_lo = readl(&cdev->macid0l);
777 mac_hi = readl(&cdev->macid0h);
778 mac_addr[0] = mac_hi & 0xFF;
779 mac_addr[1] = (mac_hi & 0xFF00) >> 8;
780 mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
781 mac_addr[3] = (mac_hi & 0xFF000000) >> 24;
782 mac_addr[4] = mac_lo & 0xFF;
783 mac_addr[5] = (mac_lo & 0xFF00) >> 8;
784#endif
785
786
787#if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \
788 (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD))
789
790#ifdef CONFIG_DRIVER_TI_CPSW
791 if (board_is_bone() || board_is_bone_lt() ||
792 board_is_idk()) {
793 writel(MII_MODE_ENABLE, &cdev->miisel);
794 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
795 PHY_INTERFACE_MODE_MII;
796 } else if (board_is_icev2()) {
797 writel(RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE, &cdev->miisel);
798 cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_RMII;
799 cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_RMII;
800 cpsw_slaves[0].phy_addr = 1;
801 cpsw_slaves[1].phy_addr = 3;
802 } else {
803 writel((RGMII_MODE_ENABLE | RGMII_INT_DELAY), &cdev->miisel);
804 cpsw_slaves[0].phy_if = cpsw_slaves[1].phy_if =
805 PHY_INTERFACE_MODE_RGMII;
806 }
807
808 rv = cpsw_register(&cpsw_data);
809 if (rv < 0)
810 printf("Error %d registering CPSW switch\n", rv);
811 else
812 n += rv;
813#endif
814
815
816
817
818
819
820
821
822#define AR8051_PHY_DEBUG_ADDR_REG 0x1d
823#define AR8051_PHY_DEBUG_DATA_REG 0x1e
824#define AR8051_DEBUG_RGMII_CLK_DLY_REG 0x5
825#define AR8051_RGMII_TX_CLK_DLY 0x100
826
827 if (board_is_evm_sk() || board_is_gp_evm()) {
828 const char *devname;
829 devname = miiphy_get_current_dev();
830
831 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_ADDR_REG,
832 AR8051_DEBUG_RGMII_CLK_DLY_REG);
833 miiphy_write(devname, 0x0, AR8051_PHY_DEBUG_DATA_REG,
834 AR8051_RGMII_TX_CLK_DLY);
835 }
836#endif
837#if defined(CONFIG_USB_ETHER) && \
838 (!defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_USBETH_SUPPORT))
839 if (is_valid_ethaddr(mac_addr))
840 eth_setenv_enetaddr("usbnet_devaddr", mac_addr);
841
842 rv = usb_eth_initialize(bis);
843 if (rv < 0)
844 printf("Error %d registering USB_ETHER\n", rv);
845 else
846 n += rv;
847#endif
848 return n;
849}
850#endif
851
852#endif
853
854#ifdef CONFIG_SPL_LOAD_FIT
855int board_fit_config_name_match(const char *name)
856{
857 if (board_is_gp_evm() && !strcmp(name, "am335x-evm"))
858 return 0;
859 else if (board_is_bone() && !strcmp(name, "am335x-bone"))
860 return 0;
861 else if (board_is_bone_lt() && !strcmp(name, "am335x-boneblack"))
862 return 0;
863 else if (board_is_evm_sk() && !strcmp(name, "am335x-evmsk"))
864 return 0;
865 else if (board_is_bbg1() && !strcmp(name, "am335x-bonegreen"))
866 return 0;
867 else if (board_is_icev2() && !strcmp(name, "am335x-icev2"))
868 return 0;
869 else
870 return -1;
871}
872#endif
873
874#ifdef CONFIG_TI_SECURE_DEVICE
875void board_fit_image_post_process(void **p_image, size_t *p_size)
876{
877 secure_boot_verify_image(p_image, p_size);
878}
879#endif
880