HACK: ARM: DRA7xx: Add VPE crossbar setting
[glsdk/glsdk-u-boot.git] / board / ti / dra7xx / evm.c
1 /*
2  * (C) Copyright 2013
3  * Texas Instruments Incorporated, <www.ti.com>
4  *
5  * Lokesh Vutla <lokeshvutla@ti.com>
6  *
7  * Based on previous work by:
8  * Aneesh V       <aneesh@ti.com>
9  * Steve Sakoman  <steve@sakoman.com>
10  *
11  * See file CREDITS for list of people who contributed to this
12  * project.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation; either version 2 of
17  * the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27  * MA 02111-1307 USA
28  */
29 #include <common.h>
30 #include <palmas.h>
31 #include <asm/arch/sys_proto.h>
32 #include <asm/arch/mmc_host_def.h>
34 #include "mux_data.h"
36 #ifdef CONFIG_USB_EHCI
37 #include <usb.h>
38 #include <asm/arch/ehci.h>
39 #include <asm/ehci-omap.h>
40 #endif
42 #ifdef CONFIG_DRIVER_TI_CPSW
43 #include <cpsw.h>
44 #endif
46 #define CTRL_CORE_MPU_IRQ_159_REG                       0x4a002b76
47 #define CTRL_CORE_MPU_IRQ_158_REG                       0x4a002b74
48 #define CTRL_CORE_MPU_IRQ_155_REG                       0x4a002b6e
49 #define CTRL_CORE_MPU_IRQ_154_REG                       0x4a002b6c
50 #define CTRL_CORE_MPU_IRQ_156_REG                       0x4a002b70
51 #define CTRL_CORE_MPU_IRQ_157_REG                       0x4a002b72
52 #define CTRL_CORE_MPU_IRQ_136_REG                       0x4a002b48
53 #define CTRL_CORE_MPU_IRQ_141_REG                       0x4a002b52
54 #define CTRL_CORE_MPU_IRQ_142_REG                       0x4a002b54
55 #define CTRL_CORE_MPU_IRQ_143_REG                       0x4a002b56
56 #define CTRL_CORE_MPU_IRQ_144_REG                       0x4a002b58
57 #define CTRL_CORE_MPU_IRQ_145_REG                       0x4a002b5a
58 #define CTRL_CORE_MPU_IRQ_124_REG                       0x4a002b34
59 #define CTRL_CORE_MPU_IRQ_50_REG                        0x4a002aa0
60 #define CTRL_CORE_MPU_IRQ_51_REG                        0x4a002aa2
61 #define CTRL_CORE_MPU_IRQ_52_REG                        0x4a002aa4
62 #define CTRL_CORE_MPU_IRQ_53_REG                        0x4a002aa6
64 #define CTRL_CORE_DMA_SYSTEM_DREQ_79_REG                0x4a002c16
65 #define CTRL_CORE_DMA_SYSTEM_DREQ_78_REG                0x4a002c14
66 #define CTRL_CORE_DMA_SYSTEM_DREQ_63_REG                0x4a002bf6
67 #define CTRL_CORE_DMA_SYSTEM_DREQ_62_REG                0x4a002bf4
69 DECLARE_GLOBAL_DATA_PTR;
71 const struct omap_sysinfo sysinfo = {
72         "Board: DRA7xx\n"
73 };
75 /*
76  * Adjust I/O delays on the Tx control and data lines of each MAC port. This
77  * is a workaround in order to work properly with the DP83865 PHYs on the EVM.
78  * In 3COM RGMII mode this PHY applies it's own internal clock delay, so we
79  * essentially need to counteract the DRA7xx internal delay, and we do this
80  * by delaying the control and data lines. If not using this PHY, you probably
81  * don't need to do this stuff!
82  */
83 static void dra7xx_adj_io_delay(const struct io_delay *io_dly)
84 {
85         int i = 0;
86         u32 reg_val;
87         u32 delta;
88         u32 coarse;
89         u32 fine;
91         writel(CFG_IO_DELAY_UNLOCK_KEY, CFG_IO_DELAY_LOCK);
93         while(io_dly[i].addr) {
94                 writel(CFG_IO_DELAY_ACCESS_PATTERN & ~CFG_IO_DELAY_LOCK_MASK,
95                        io_dly[i].addr);
96                 delta = io_dly[i].dly;
97                 reg_val = readl(io_dly[i].addr) & 0x3ff;
98                 coarse = ((reg_val >> 5) & 0x1F) + ((delta >> 5) & 0x1F);
99                 coarse = (coarse > 0x1F) ? (0x1F) : (coarse);
100                 fine = (reg_val & 0x1F) + (delta & 0x1F);
101                 fine = (fine > 0x1F) ? (0x1F) : (fine);
102                 reg_val = CFG_IO_DELAY_ACCESS_PATTERN |
103                                 CFG_IO_DELAY_LOCK_MASK |
104                                 ((coarse << 5) | (fine));
105                 writel(reg_val, io_dly[i].addr);
106                 i++;
107         }
109         writel(CFG_IO_DELAY_LOCK_KEY, CFG_IO_DELAY_LOCK);
112 /**
113  * @brief board_init
114  *
115  * @return 0
116  */
117 int board_init(void)
119         gpmc_init();
120         gd->bd->bi_boot_params = (0x80000000 + 0x100); /* boot param addr */
122         return 0;
125 /**
126  * @brief misc_init_r - Configure EVM board specific configurations
127  * such as power configurations, ethernet initialization as phase2 of
128  * boot sequence
129  *
130  * @return 0
131  */
132 int misc_init_r(void)
134         return 0;
137 static void do_set_mux32(u32 base,
138                          struct pad_conf_entry const *array, int size)
140         int i;
141         struct pad_conf_entry *pad = (struct pad_conf_entry *)array;
143         for (i = 0; i < size; i++, pad++)
144                 writel(pad->val, base + pad->offset);
147 void set_muxconf_regs_essential(void)
149         do_set_mux32((*ctrl)->control_padconf_core_base,
150                      core_padconf_array_essential,
151                      sizeof(core_padconf_array_essential) /
152                      sizeof(struct pad_conf_entry));
155 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_GENERIC_MMC)
156 int board_mmc_init(bd_t *bis)
158         omap_mmc_init(0, 0, 0, -1, -1);
159         omap_mmc_init(1, 0, 0, -1, -1);
160         return 0;
162 #endif
164 static void set_crossbar_mpu_irq()
166         /* MPU_IRQ mapping to CROSSBAR_IRQ */
167         writew(217, CTRL_CORE_MPU_IRQ_159_REG); /* RTC_IRQ */
168         writew(354, CTRL_CORE_MPU_IRQ_158_REG); /* VPE_IRQ */
169         writew(150, CTRL_CORE_MPU_IRQ_155_REG); /* MCASP3_IRQ_AREVT */
170         writew(151, CTRL_CORE_MPU_IRQ_154_REG); /* MCASP3_IRQ_AXEVT */
171         writew(156, CTRL_CORE_MPU_IRQ_156_REG); /* MCASP6_IRQ_AREVT */
172         writew(157, CTRL_CORE_MPU_IRQ_157_REG); /* MCASP6_IRQ_AXEVT */
173         writew(251, CTRL_CORE_MPU_IRQ_136_REG); /* MAILBOX5 */
174         writew(255, CTRL_CORE_MPU_IRQ_141_REG); /* MAILBOX6 */
175         writew(396, CTRL_CORE_MPU_IRQ_142_REG); /* IPU2 MMU */
176         writew(145, CTRL_CORE_MPU_IRQ_143_REG); /* DSP1 MMU1 */
177         writew(146, CTRL_CORE_MPU_IRQ_144_REG); /* DSP2 MMU0 */
178         writew(147, CTRL_CORE_MPU_IRQ_145_REG); /* DSP2 MMU1 */
179         writew(343, CTRL_CORE_MPU_IRQ_124_REG); /* QSPI */
180         writew(334, CTRL_CORE_MPU_IRQ_50_REG);  /* CPSW_RX_THRESH */
181         writew(335, CTRL_CORE_MPU_IRQ_51_REG);  /* CPSW_RX */
182         writew(336, CTRL_CORE_MPU_IRQ_52_REG);  /* CPSW_TX */
183         writew(337, CTRL_CORE_MPU_IRQ_53_REG);  /* CPSW_MISC */
186 static void set_crossbar_sdma_dreq()
188         /* SDMA_DREQ mapping to CROSSBAR_IRQ */
189         writew(132, CTRL_CORE_DMA_SYSTEM_DREQ_79_REG);  /* MCASP3_DREQ_RX */
190         writew(133, CTRL_CORE_DMA_SYSTEM_DREQ_78_REG);  /* MCASP3_DREQ_TX */
191         writew(138, CTRL_CORE_DMA_SYSTEM_DREQ_63_REG);  /* MCASP6_DREQ_RX */
192         writew(139, CTRL_CORE_DMA_SYSTEM_DREQ_62_REG);  /* MCASP6_DREQ_TX */
195 void set_crossbar_regs(void)
197         set_crossbar_mpu_irq();
198         set_crossbar_sdma_dreq();
201 #ifdef CONFIG_DRIVER_TI_CPSW
203 /* Delay value to add to calibrated value */
204 #define RGMII0_TXCTL_DLY_VAL            ((0x3 << 5) + 0x8)
205 #define RGMII0_TXD0_DLY_VAL             ((0x3 << 5) + 0x8)
206 #define RGMII0_TXD1_DLY_VAL             ((0x3 << 5) + 0x2)
207 #define RGMII0_TXD2_DLY_VAL             ((0x4 << 5) + 0x0)
208 #define RGMII0_TXD3_DLY_VAL             ((0x4 << 5) + 0x0)
209 #define VIN2A_D13_DLY_VAL               ((0x3 << 5) + 0x8)
210 #define VIN2A_D17_DLY_VAL               ((0x3 << 5) + 0x8)
211 #define VIN2A_D16_DLY_VAL               ((0x3 << 5) + 0x2)
212 #define VIN2A_D15_DLY_VAL               ((0x4 << 5) + 0x0)
213 #define VIN2A_D14_DLY_VAL               ((0x4 << 5) + 0x0)
215 static void cpsw_control(int enabled)
217         /* VTP can be added here */
219         return;
222 static struct cpsw_slave_data cpsw_slaves[] = {
223         {
224                 .slave_reg_ofs  = 0x208,
225                 .sliver_reg_ofs = 0xd80,
226                 .phy_id         = 0,
227         },
228         {
229                 .slave_reg_ofs  = 0x308,
230                 .sliver_reg_ofs = 0xdc0,
231                 .phy_id         = 1,
232         },
233 };
235 static struct cpsw_platform_data cpsw_data = {
236         .mdio_base              = CPSW_MDIO_BASE,
237         .cpsw_base              = CPSW_BASE,
238         .mdio_div               = 0xff,
239         .channels               = 8,
240         .cpdma_reg_ofs          = 0x800,
241         .slaves                 = 1,
242         .slave_data             = cpsw_slaves,
243         .ale_reg_ofs            = 0xd00,
244         .ale_entries            = 1024,
245         .host_port_reg_ofs      = 0x108,
246         .hw_stats_reg_ofs       = 0x900,
247         .bd_ram_ofs             = 0x2000,
248         .mac_control            = (1 << 5),
249         .control                = cpsw_control,
250         .host_port_num          = 0,
251         .version                = CPSW_CTRL_VERSION_2,
252 };
254 int board_eth_init(bd_t *bis)
256         int ret;
257         uint8_t mac_addr[6];
258         uint32_t mac_hi, mac_lo;
259         uint32_t ctrl_val;
260         const struct io_delay io_dly[] = {
261                 {CFG_RGMII0_TXCTL, RGMII0_TXCTL_DLY_VAL},
262                 {CFG_RGMII0_TXD0, RGMII0_TXD0_DLY_VAL},
263                 {CFG_RGMII0_TXD1, RGMII0_TXD1_DLY_VAL},
264                 {CFG_RGMII0_TXD2, RGMII0_TXD2_DLY_VAL},
265                 {CFG_RGMII0_TXD3, RGMII0_TXD3_DLY_VAL},
266                 {CFG_VIN2A_D13, VIN2A_D13_DLY_VAL},
267                 {CFG_VIN2A_D17, VIN2A_D17_DLY_VAL},
268                 {CFG_VIN2A_D16, VIN2A_D16_DLY_VAL},
269                 {CFG_VIN2A_D15, VIN2A_D15_DLY_VAL},
270                 {CFG_VIN2A_D14, VIN2A_D14_DLY_VAL},
271                 {0}
272         };
274         /* Adjust IO delay for RGMII tx path */
275         dra7xx_adj_io_delay(io_dly);
277         /* try reading mac address from efuse */
278         mac_lo = readl((*ctrl)->control_core_mac_id_0_lo);
279         mac_hi = readl((*ctrl)->control_core_mac_id_0_hi);
280         mac_addr[0] = mac_hi & 0xFF;
281         mac_addr[1] = (mac_hi & 0xFF00) >> 8;
282         mac_addr[2] = (mac_hi & 0xFF0000) >> 16;
283         mac_addr[3] = mac_lo & 0xFF;
284         mac_addr[4] = (mac_lo & 0xFF00) >> 8;
285         mac_addr[5] = (mac_lo & 0xFF0000) >> 16;
287         if (!getenv("ethaddr")) {
288                 printf("<ethaddr> not set. Validating first E-fuse MAC\n");
290                 if (is_valid_ether_addr(mac_addr))
291                         eth_setenv_enetaddr("ethaddr", mac_addr);
292         }
293         ctrl_val = readl((*ctrl)->control_core_control_io1) & (~0x33);
294         ctrl_val |= 0x22;
295         writel(ctrl_val, (*ctrl)->control_core_control_io1);
297         ret = cpsw_register(&cpsw_data);
298         if (ret < 0)
299                 printf("Error %d registering CPSW switch\n", ret);
301         return ret;
303 #endif