Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 1 | /* |
Enric Balletbo i Serra | 3a2f040 | 2013-07-25 09:27:38 +0200 | [diff] [blame] | 2 | * Board functions for IGEP COM AQUILA based boards |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2013, ISEE 2007 SL - http://www.isee.biz/ |
| 5 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <errno.h> |
| 11 | #include <spl.h> |
| 12 | #include <asm/arch/cpu.h> |
| 13 | #include <asm/arch/hardware.h> |
| 14 | #include <asm/arch/omap.h> |
| 15 | #include <asm/arch/ddr_defs.h> |
| 16 | #include <asm/arch/clock.h> |
| 17 | #include <asm/arch/gpio.h> |
| 18 | #include <asm/arch/mmc_host_def.h> |
| 19 | #include <asm/arch/sys_proto.h> |
| 20 | #include <asm/io.h> |
| 21 | #include <asm/emif.h> |
| 22 | #include <asm/gpio.h> |
| 23 | #include <i2c.h> |
| 24 | #include <miiphy.h> |
| 25 | #include <cpsw.h> |
| 26 | #include "board.h" |
| 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 30 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 31 | |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 32 | #ifdef CONFIG_SPL_BUILD |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 33 | static const struct ddr_data ddr3_data = { |
| 34 | .datardsratio0 = K4B2G1646EBIH9_RD_DQS, |
| 35 | .datawdsratio0 = K4B2G1646EBIH9_WR_DQS, |
| 36 | .datafwsratio0 = K4B2G1646EBIH9_PHY_FIFO_WE, |
| 37 | .datawrsratio0 = K4B2G1646EBIH9_PHY_WR_DATA, |
| 38 | .datadldiff0 = PHY_DLL_LOCK_DIFF, |
| 39 | }; |
| 40 | |
| 41 | static const struct cmd_control ddr3_cmd_ctrl_data = { |
| 42 | .cmd0csratio = K4B2G1646EBIH9_RATIO, |
| 43 | .cmd0dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 44 | .cmd0iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 45 | |
| 46 | .cmd1csratio = K4B2G1646EBIH9_RATIO, |
| 47 | .cmd1dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 48 | .cmd1iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 49 | |
| 50 | .cmd2csratio = K4B2G1646EBIH9_RATIO, |
| 51 | .cmd2dldiff = K4B2G1646EBIH9_DLL_LOCK_DIFF, |
| 52 | .cmd2iclkout = K4B2G1646EBIH9_INVERT_CLKOUT, |
| 53 | }; |
| 54 | |
| 55 | static struct emif_regs ddr3_emif_reg_data = { |
| 56 | .sdram_config = K4B2G1646EBIH9_EMIF_SDCFG, |
| 57 | .ref_ctrl = K4B2G1646EBIH9_EMIF_SDREF, |
| 58 | .sdram_tim1 = K4B2G1646EBIH9_EMIF_TIM1, |
| 59 | .sdram_tim2 = K4B2G1646EBIH9_EMIF_TIM2, |
| 60 | .sdram_tim3 = K4B2G1646EBIH9_EMIF_TIM3, |
| 61 | .zq_config = K4B2G1646EBIH9_ZQ_CFG, |
| 62 | .emif_ddr_phy_ctlr_1 = K4B2G1646EBIH9_EMIF_READ_LATENCY, |
| 63 | }; |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 64 | |
| 65 | #define OSC (V_OSCK/1000000) |
| 66 | const struct dpll_params dpll_ddr = { |
Enric Balletbo i Serra | 94b32f6 | 2013-09-10 11:12:26 +0200 | [diff] [blame^] | 67 | 400, OSC-1, 1, -1, -1, -1, -1}; |
Lokesh Vutla | 94d77fb | 2013-07-30 10:48:52 +0530 | [diff] [blame] | 68 | |
| 69 | const struct dpll_params *get_dpll_ddr_params(void) |
| 70 | { |
| 71 | return &dpll_ddr; |
| 72 | } |
| 73 | |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 74 | void set_uart_mux_conf(void) |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 75 | { |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 76 | enable_uart0_pin_mux(); |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 77 | } |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 78 | |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 79 | void set_mux_conf_regs(void) |
| 80 | { |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 81 | enable_board_pin_mux(); |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 82 | } |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 83 | |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 84 | void sdram_init(void) |
| 85 | { |
Enric Balletbo i Serra | 94b32f6 | 2013-09-10 11:12:26 +0200 | [diff] [blame^] | 86 | config_ddr(400, K4B2G1646EBIH9_IOCTRL_VALUE, &ddr3_data, |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 87 | &ddr3_cmd_ctrl_data, &ddr3_emif_reg_data, 0); |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 88 | } |
Heiko Schocher | 0660481 | 2013-07-30 10:48:54 +0530 | [diff] [blame] | 89 | #endif |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Basic board specific setup. Pinmux has been handled already. |
| 93 | */ |
| 94 | int board_init(void) |
| 95 | { |
Tom Rini | 73feefd | 2013-08-09 11:22:13 -0400 | [diff] [blame] | 96 | gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100; |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 97 | |
| 98 | gpmc_init(); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
| 103 | #if defined(CONFIG_DRIVER_TI_CPSW) |
| 104 | static void cpsw_control(int enabled) |
| 105 | { |
| 106 | /* VTP can be added here */ |
| 107 | |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 112 | { |
| 113 | .slave_reg_ofs = 0x208, |
| 114 | .sliver_reg_ofs = 0xd80, |
| 115 | .phy_id = 0, |
| 116 | .phy_if = PHY_INTERFACE_MODE_RMII, |
| 117 | }, |
| 118 | }; |
| 119 | |
| 120 | static struct cpsw_platform_data cpsw_data = { |
| 121 | .mdio_base = CPSW_MDIO_BASE, |
| 122 | .cpsw_base = CPSW_BASE, |
| 123 | .mdio_div = 0xff, |
| 124 | .channels = 8, |
| 125 | .cpdma_reg_ofs = 0x800, |
| 126 | .slaves = 1, |
| 127 | .slave_data = cpsw_slaves, |
| 128 | .ale_reg_ofs = 0xd00, |
| 129 | .ale_entries = 1024, |
| 130 | .host_port_reg_ofs = 0x108, |
| 131 | .hw_stats_reg_ofs = 0x900, |
| 132 | .mac_control = (1 << 5), |
| 133 | .control = cpsw_control, |
| 134 | .host_port_num = 0, |
| 135 | .version = CPSW_CTRL_VERSION_2, |
| 136 | }; |
| 137 | |
| 138 | int board_eth_init(bd_t *bis) |
| 139 | { |
| 140 | int rv, ret = 0; |
| 141 | uint8_t mac_addr[6]; |
| 142 | uint32_t mac_hi, mac_lo; |
| 143 | |
| 144 | if (!eth_getenv_enetaddr("ethaddr", mac_addr)) { |
| 145 | /* try reading mac address from efuse */ |
| 146 | mac_lo = readl(&cdev->macid0l); |
| 147 | mac_hi = readl(&cdev->macid0h); |
| 148 | mac_addr[0] = mac_hi & 0xFF; |
| 149 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 150 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 151 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 152 | mac_addr[4] = mac_lo & 0xFF; |
| 153 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 154 | if (is_valid_ether_addr(mac_addr)) |
| 155 | eth_setenv_enetaddr("ethaddr", mac_addr); |
| 156 | } |
| 157 | |
Heiko Schocher | dafd4db | 2013-08-19 16:38:56 +0200 | [diff] [blame] | 158 | writel((GMII1_SEL_RMII | RMII1_IO_CLK_EN), |
| 159 | &cdev->miisel); |
Enric Balletbo i Serra | 5f5c1d1 | 2013-04-04 22:27:58 +0000 | [diff] [blame] | 160 | |
| 161 | rv = cpsw_register(&cpsw_data); |
| 162 | if (rv < 0) |
| 163 | printf("Error %d registering CPSW switch\n", rv); |
| 164 | else |
| 165 | ret += rv; |
| 166 | |
| 167 | return ret; |
| 168 | } |
| 169 | #endif |
| 170 | |