Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 2 | /* |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 3 | * Board functions for TI AM335X based draco board |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 4 | * (C) Copyright 2013 Siemens Schweiz AG |
| 5 | * (C) Heiko Schocher, DENX Software Engineering, hs@denx.de. |
| 6 | * |
| 7 | * Based on: |
| 8 | * |
| 9 | * Board functions for TI AM335X based boards |
| 10 | * u-boot:/board/ti/am335x/board.c |
| 11 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 12 | * Copyright (C) 2011, Texas Instruments, Incorporated - https://www.ti.com/ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 13 | */ |
| 14 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 15 | #include <command.h> |
Enrico Leto | fce9179 | 2024-01-24 15:43:54 +0100 | [diff] [blame] | 16 | #include <cpsw.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 17 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 18 | #include <init.h> |
Enrico Leto | fce9179 | 2024-01-24 15:43:54 +0100 | [diff] [blame] | 19 | #include <linux/delay.h> |
| 20 | #include <nand.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 21 | #include <asm/arch/clock.h> |
Enrico Leto | fce9179 | 2024-01-24 15:43:54 +0100 | [diff] [blame] | 22 | #include <asm/arch/ddr_defs.h> |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 23 | #include <asm/arch/mem.h> |
Enrico Leto | fce9179 | 2024-01-24 15:43:54 +0100 | [diff] [blame] | 24 | #include <asm/arch/sys_proto.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 25 | #include <asm/gpio.h> |
Enrico Leto | fce9179 | 2024-01-24 15:43:54 +0100 | [diff] [blame] | 26 | #include <asm/io.h> |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 27 | #include "board.h" |
Enrico Leto | 096bfdc | 2024-01-24 15:43:49 +0100 | [diff] [blame] | 28 | #include "../common/eeprom.h" |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 29 | #include "../common/factoryset.h" |
| 30 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 31 | #ifdef CONFIG_SPL_BUILD |
Marek BehĂșn | 4bebdd3 | 2021-05-20 13:23:52 +0200 | [diff] [blame] | 32 | static struct draco_baseboard_id __section(".data") settings; |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 33 | |
| 34 | #if DDR_PLL_FREQ == 303 |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 35 | #if !defined(CONFIG_TARGET_ETAMIN) |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 36 | /* Default@303MHz-i0 */ |
| 37 | const struct ddr3_data ddr3_default = { |
| 38 | 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x003A, 0x003F, 0x009F, |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 39 | 0x0079, 0x0888A39B, 0x26517FDA, 0x501F84EF, 0x00100206, 0x61A44A32, |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 40 | 0x0000093B, 0x0000014A, |
| 41 | "default name @303MHz \0", |
| 42 | "default marking \0", |
| 43 | }; |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 44 | #else |
| 45 | /* etamin board */ |
| 46 | const struct ddr3_data ddr3_default = { |
| 47 | 0x33524444, 0x56312e36, 0x0080, 0x0000, 0x003A, 0x0010, 0x009F, |
| 48 | 0x0050, 0x0888A39B, 0x266D7FDA, 0x501F86AF, 0x00100206, 0x61A44BB2, |
| 49 | 0x0000093B, 0x0000018A, |
| 50 | "test-etamin \0", |
| 51 | "generic-8Gbit \0", |
| 52 | }; |
| 53 | #endif |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 54 | #elif DDR_PLL_FREQ == 400 |
| 55 | /* Default@400MHz-i0 */ |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 56 | const struct ddr3_data ddr3_default = { |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 57 | 0x33524444, 0x56312e35, 0x0080, 0x0000, 0x0039, 0x0046, 0x00ab, |
| 58 | 0x0080, 0x0AAAA4DB, 0x26307FDA, 0x501F821F, 0x00100207, 0x61A45232, |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 59 | 0x00000618, 0x0000014A, |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 60 | "default name @400MHz \0", |
| 61 | "default marking \0", |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 62 | }; |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 63 | #endif |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 64 | |
| 65 | static void set_default_ddr3_timings(void) |
| 66 | { |
| 67 | printf("Set default DDR3 settings\n"); |
| 68 | settings.ddr3 = ddr3_default; |
| 69 | } |
| 70 | |
| 71 | static void print_ddr3_timings(void) |
| 72 | { |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 73 | printf("\nDDR3\n"); |
| 74 | printf("clock:\t\t%d MHz\n", DDR_PLL_FREQ); |
| 75 | printf("device:\t\t%s\n", settings.ddr3.manu_name); |
| 76 | printf("marking:\t%s\n", settings.ddr3.manu_marking); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 77 | printf("%-20s, %-8s, %-8s, %-4s\n", "timing parameters", "eeprom", |
| 78 | "default", "diff"); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 79 | PRINTARGS(magic); |
| 80 | PRINTARGS(version); |
| 81 | PRINTARGS(ddr3_sratio); |
| 82 | PRINTARGS(iclkout); |
| 83 | |
| 84 | PRINTARGS(dt0rdsratio0); |
| 85 | PRINTARGS(dt0wdsratio0); |
| 86 | PRINTARGS(dt0fwsratio0); |
| 87 | PRINTARGS(dt0wrsratio0); |
| 88 | |
| 89 | PRINTARGS(sdram_tim1); |
| 90 | PRINTARGS(sdram_tim2); |
| 91 | PRINTARGS(sdram_tim3); |
| 92 | |
| 93 | PRINTARGS(emif_ddr_phy_ctlr_1); |
| 94 | |
| 95 | PRINTARGS(sdram_config); |
| 96 | PRINTARGS(ref_ctrl); |
Samuel Egli | 8069bfe | 2013-11-04 14:05:03 +0100 | [diff] [blame] | 97 | PRINTARGS(ioctr_val); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | static void print_chip_data(void) |
| 101 | { |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 102 | struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 103 | dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 104 | printf("\nCPU BOARD\n"); |
| 105 | printf("device: \t'%s'\n", settings.chip.sdevname); |
| 106 | printf("hw version: \t'%s'\n", settings.chip.shwver); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 107 | printf("max freq: \t%d MHz\n", dpll_mpu_opp100.m); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 108 | } |
| 109 | #endif /* CONFIG_SPL_BUILD */ |
| 110 | |
Heiko Schocher | 4453d7a | 2016-06-07 08:55:43 +0200 | [diff] [blame] | 111 | #define AM335X_NAND_ECC_MASK 0x0f |
| 112 | #define AM335X_NAND_ECC_TYPE_16 0x02 |
| 113 | |
| 114 | static int ecc_type; |
| 115 | |
| 116 | struct am335x_nand_geometry { |
| 117 | u32 magic; |
| 118 | u8 nand_geo_addr; |
| 119 | u8 nand_geo_page; |
| 120 | u8 nand_bus; |
| 121 | }; |
| 122 | |
| 123 | static int draco_read_nand_geometry(void) |
| 124 | { |
| 125 | struct am335x_nand_geometry geo; |
| 126 | |
| 127 | /* Read NAND geometry */ |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 128 | if (siemens_ee_read_data(SIEMENS_EE_ADDR_NAND_GEO, (uchar *)&geo, |
| 129 | sizeof(struct am335x_nand_geometry))) { |
Heiko Schocher | 4453d7a | 2016-06-07 08:55:43 +0200 | [diff] [blame] | 130 | printf("Could not read the NAND geomtery; something fundamentally wrong on the I2C bus.\n"); |
| 131 | return -EIO; |
| 132 | } |
| 133 | if (geo.magic != 0xa657b310) { |
| 134 | printf("%s: bad magic: %x\n", __func__, geo.magic); |
| 135 | return -EFAULT; |
| 136 | } |
| 137 | if ((geo.nand_bus & AM335X_NAND_ECC_MASK) == AM335X_NAND_ECC_TYPE_16) |
| 138 | ecc_type = 16; |
| 139 | else |
| 140 | ecc_type = 8; |
| 141 | |
| 142 | return 0; |
| 143 | } |
| 144 | |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 145 | #ifdef CONFIG_SPL_BUILD |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 146 | /* |
| 147 | * Read header information from EEPROM into global structure. |
| 148 | */ |
Enrico Leto | 2e74050 | 2024-01-24 15:43:53 +0100 | [diff] [blame] | 149 | int draco_read_eeprom(void) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 150 | { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 151 | /* Read Siemens eeprom data (DDR3) */ |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 152 | if (siemens_ee_read_data(SIEMENS_EE_ADDR_DDR3, (uchar *)&settings.ddr3, |
| 153 | sizeof(struct ddr3_data))) { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 154 | printf("Could not read the EEPROM; something fundamentally wrong on the I2C bus.\nUse default DDR3 timings\n"); |
| 155 | set_default_ddr3_timings(); |
| 156 | } |
| 157 | /* Read Siemens eeprom data (CHIP) */ |
Enrico Leto | 32f433f | 2024-01-24 15:43:50 +0100 | [diff] [blame] | 158 | if (siemens_ee_read_data(SIEMENS_EE_ADDR_CHIP, (uchar *)&settings.chip, |
| 159 | sizeof(settings.chip))) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 160 | printf("Could not read chip settings\n"); |
| 161 | |
| 162 | if (ddr3_default.magic == settings.ddr3.magic && |
| 163 | ddr3_default.version == settings.ddr3.version) { |
| 164 | printf("Using DDR3 settings from EEPROM\n"); |
| 165 | } else { |
| 166 | if (ddr3_default.magic != settings.ddr3.magic) |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 167 | printf("Warning: No valid DDR3 data in eeprom.\n"); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 168 | if (ddr3_default.version != settings.ddr3.version) |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 169 | printf("Warning: DDR3 data version does not match.\n"); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 170 | |
| 171 | printf("Using default settings\n"); |
| 172 | set_default_ddr3_timings(); |
| 173 | } |
| 174 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 175 | if (MAGIC_CHIP == settings.chip.magic) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 176 | print_chip_data(); |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 177 | else |
Egli, Samuel | bc38fa4 | 2014-04-24 17:57:53 +0200 | [diff] [blame] | 178 | printf("Warning: No chip data in eeprom\n"); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 179 | |
| 180 | print_ddr3_timings(); |
Heiko Schocher | 4453d7a | 2016-06-07 08:55:43 +0200 | [diff] [blame] | 181 | |
| 182 | return draco_read_nand_geometry(); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Enrico Leto | 2e74050 | 2024-01-24 15:43:53 +0100 | [diff] [blame] | 185 | void draco_init_ddr(void) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 186 | { |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 187 | struct emif_regs draco_ddr3_emif_reg_data = { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 188 | .zq_config = 0x50074BE4, |
| 189 | }; |
| 190 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 191 | struct ddr_data draco_ddr3_data = { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 192 | }; |
| 193 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 194 | struct cmd_control draco_ddr3_cmd_ctrl_data = { |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 195 | }; |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 196 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 197 | struct ctrl_ioregs draco_ddr3_ioregs = { |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 198 | }; |
| 199 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 200 | /* pass values from eeprom */ |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 201 | draco_ddr3_emif_reg_data.sdram_tim1 = settings.ddr3.sdram_tim1; |
| 202 | draco_ddr3_emif_reg_data.sdram_tim2 = settings.ddr3.sdram_tim2; |
| 203 | draco_ddr3_emif_reg_data.sdram_tim3 = settings.ddr3.sdram_tim3; |
| 204 | draco_ddr3_emif_reg_data.emif_ddr_phy_ctlr_1 = |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 205 | settings.ddr3.emif_ddr_phy_ctlr_1; |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 206 | draco_ddr3_emif_reg_data.sdram_config = settings.ddr3.sdram_config; |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 207 | draco_ddr3_emif_reg_data.sdram_config2 = 0x08000000; |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 208 | draco_ddr3_emif_reg_data.ref_ctrl = settings.ddr3.ref_ctrl; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 209 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 210 | draco_ddr3_data.datardsratio0 = settings.ddr3.dt0rdsratio0; |
| 211 | draco_ddr3_data.datawdsratio0 = settings.ddr3.dt0wdsratio0; |
| 212 | draco_ddr3_data.datafwsratio0 = settings.ddr3.dt0fwsratio0; |
| 213 | draco_ddr3_data.datawrsratio0 = settings.ddr3.dt0wrsratio0; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 214 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 215 | draco_ddr3_cmd_ctrl_data.cmd0csratio = settings.ddr3.ddr3_sratio; |
| 216 | draco_ddr3_cmd_ctrl_data.cmd0iclkout = settings.ddr3.iclkout; |
| 217 | draco_ddr3_cmd_ctrl_data.cmd1csratio = settings.ddr3.ddr3_sratio; |
| 218 | draco_ddr3_cmd_ctrl_data.cmd1iclkout = settings.ddr3.iclkout; |
| 219 | draco_ddr3_cmd_ctrl_data.cmd2csratio = settings.ddr3.ddr3_sratio; |
| 220 | draco_ddr3_cmd_ctrl_data.cmd2iclkout = settings.ddr3.iclkout; |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 221 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 222 | draco_ddr3_ioregs.cm0ioctl = settings.ddr3.ioctr_val, |
| 223 | draco_ddr3_ioregs.cm1ioctl = settings.ddr3.ioctr_val, |
| 224 | draco_ddr3_ioregs.cm2ioctl = settings.ddr3.ioctr_val, |
| 225 | draco_ddr3_ioregs.dt0ioctl = settings.ddr3.ioctr_val, |
| 226 | draco_ddr3_ioregs.dt1ioctl = settings.ddr3.ioctr_val, |
Lokesh Vutla | 303b267 | 2013-12-10 15:02:21 +0530 | [diff] [blame] | 227 | |
Egli, Samuel | 097951b | 2014-05-05 16:50:43 +0200 | [diff] [blame] | 228 | config_ddr(DDR_PLL_FREQ, &draco_ddr3_ioregs, &draco_ddr3_data, |
| 229 | &draco_ddr3_cmd_ctrl_data, &draco_ddr3_emif_reg_data, 0); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 230 | } |
| 231 | |
Enrico Leto | 2e74050 | 2024-01-24 15:43:53 +0100 | [diff] [blame] | 232 | void spl_draco_board_init(void) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 233 | { |
| 234 | return; |
| 235 | } |
| 236 | #endif /* if def CONFIG_SPL_BUILD */ |
| 237 | |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 238 | #ifdef CONFIG_BOARD_LATE_INIT |
| 239 | int board_late_init(void) |
| 240 | { |
Heiko Schocher | 4453d7a | 2016-06-07 08:55:43 +0200 | [diff] [blame] | 241 | int ret; |
| 242 | |
| 243 | ret = draco_read_nand_geometry(); |
| 244 | if (ret != 0) |
| 245 | return ret; |
| 246 | |
| 247 | nand_curr_device = 0; |
| 248 | omap_nand_switch_ecc(1, ecc_type); |
Heiko Schocher | cbec11a | 2016-06-07 08:55:45 +0200 | [diff] [blame] | 249 | #ifdef CONFIG_TARGET_ETAMIN |
| 250 | nand_curr_device = 1; |
| 251 | omap_nand_switch_ecc(1, ecc_type); |
| 252 | #endif |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 253 | #ifdef CONFIG_FACTORYSET |
| 254 | /* Set ASN in environment*/ |
| 255 | if (factory_dat.asn[0] != 0) { |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 256 | env_set("dtb_name", (char *)factory_dat.asn); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 257 | } else { |
| 258 | /* dtb suffix gets added in load script */ |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 259 | env_set("dtb_name", "am335x-draco"); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 260 | } |
| 261 | #else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 262 | env_set("dtb_name", "am335x-draco"); |
Heiko Schocher | d17c3fc | 2015-06-16 14:59:34 +0200 | [diff] [blame] | 263 | #endif |
| 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | #endif |
| 268 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 269 | #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ |
Simon Glass | e5cd9a4 | 2021-07-10 21:14:26 -0600 | [diff] [blame] | 270 | (defined(CONFIG_SPL_ETH) && defined(CONFIG_SPL_BUILD)) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 271 | static void cpsw_control(int enabled) |
| 272 | { |
| 273 | /* VTP can be added here */ |
| 274 | |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 279 | { |
| 280 | .slave_reg_ofs = 0x208, |
| 281 | .sliver_reg_ofs = 0xd80, |
Mugunthan V N | 4944f37 | 2014-02-18 07:31:52 -0500 | [diff] [blame] | 282 | .phy_addr = 0, |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 283 | .phy_if = PHY_INTERFACE_MODE_MII, |
| 284 | }, |
| 285 | }; |
| 286 | |
| 287 | static struct cpsw_platform_data cpsw_data = { |
| 288 | .mdio_base = CPSW_MDIO_BASE, |
| 289 | .cpsw_base = CPSW_BASE, |
| 290 | .mdio_div = 0xff, |
| 291 | .channels = 4, |
| 292 | .cpdma_reg_ofs = 0x800, |
| 293 | .slaves = 1, |
| 294 | .slave_data = cpsw_slaves, |
| 295 | .ale_reg_ofs = 0xd00, |
| 296 | .ale_entries = 1024, |
| 297 | .host_port_reg_ofs = 0x108, |
| 298 | .hw_stats_reg_ofs = 0x900, |
| 299 | .bd_ram_ofs = 0x2000, |
| 300 | .mac_control = (1 << 5), |
| 301 | .control = cpsw_control, |
| 302 | .host_port_num = 0, |
| 303 | .version = CPSW_CTRL_VERSION_2, |
| 304 | }; |
| 305 | |
| 306 | #if defined(CONFIG_DRIVER_TI_CPSW) || \ |
Paul Kocialkowski | f34dfcb | 2015-08-04 17:04:06 +0200 | [diff] [blame] | 307 | (defined(CONFIG_USB_ETHER) && defined(CONFIG_USB_MUSB_GADGET)) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 308 | int board_eth_init(struct bd_info *bis) |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 309 | { |
| 310 | struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 311 | int n = 0; |
| 312 | int rv; |
| 313 | |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 314 | factoryset_env_set(); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 315 | |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 316 | /* Set rgmii mode and enable rmii clock to be sourced from chip */ |
| 317 | writel((RMII_MODE_ENABLE | RMII_CHIPCKL_ENABLE), &cdev->miisel); |
| 318 | |
| 319 | rv = cpsw_register(&cpsw_data); |
| 320 | if (rv < 0) |
| 321 | printf("Error %d registering CPSW switch\n", rv); |
| 322 | else |
| 323 | n += rv; |
| 324 | return n; |
| 325 | } |
Stefan Roese | 9aee57f | 2014-03-12 10:45:41 +0100 | [diff] [blame] | 326 | |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 327 | static int do_switch_reset(struct cmd_tbl *cmdtp, int flag, int argc, |
| 328 | char *const argv[]) |
Stefan Roese | 9aee57f | 2014-03-12 10:45:41 +0100 | [diff] [blame] | 329 | { |
| 330 | /* Reset SMSC LAN9303 switch for default configuration */ |
| 331 | gpio_request(GPIO_LAN9303_NRST, "nRST"); |
| 332 | gpio_direction_output(GPIO_LAN9303_NRST, 0); |
| 333 | /* assert active low reset for 200us */ |
| 334 | udelay(200); |
| 335 | gpio_set_value(GPIO_LAN9303_NRST, 1); |
| 336 | |
| 337 | return 0; |
| 338 | }; |
| 339 | |
| 340 | U_BOOT_CMD( |
| 341 | switch_rst, CONFIG_SYS_MAXARGS, 1, do_switch_reset, |
| 342 | "Reset LAN9303 switch via its reset pin", |
| 343 | "" |
| 344 | ); |
Heiko Schocher | 499c498 | 2013-08-19 16:39:01 +0200 | [diff] [blame] | 345 | #endif /* #if defined(CONFIG_DRIVER_TI_CPSW) */ |
| 346 | #endif /* #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) */ |