Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 2 | /* |
| 3 | * common.c |
| 4 | * |
| 5 | * common board functions for B&R boards |
| 6 | * |
Hannes Schmelzer | 7935f03 | 2015-05-28 15:41:12 +0200 | [diff] [blame] | 7 | * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 8 | * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com |
| 9 | * |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 10 | */ |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 11 | #include <version.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 12 | #include <common.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 13 | #include <environment.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 14 | #include <errno.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 15 | #include <asm/arch/cpu.h> |
| 16 | #include <asm/arch/hardware.h> |
| 17 | #include <asm/arch/omap.h> |
| 18 | #include <asm/arch/clock.h> |
| 19 | #include <asm/arch/gpio.h> |
| 20 | #include <asm/arch/sys_proto.h> |
Hannes Petermaier | 8e731ed | 2014-04-08 08:39:20 +0200 | [diff] [blame] | 21 | #include <asm/arch/mmc_host_def.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 22 | #include <asm/io.h> |
| 23 | #include <asm/gpio.h> |
| 24 | #include <i2c.h> |
| 25 | #include <miiphy.h> |
| 26 | #include <cpsw.h> |
| 27 | #include <power/tps65217.h> |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 28 | #include <lcd.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 29 | #include "bur_common.h" |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 30 | #include "../../../drivers/video/am335x-fb.h" |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 31 | #include <fdt_simplefb.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 32 | |
| 33 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 34 | |
| 35 | DECLARE_GLOBAL_DATA_PTR; |
| 36 | |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 37 | /* --------------------------------------------------------------------------*/ |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 38 | #if defined(CONFIG_LCD) && defined(CONFIG_AM335X_LCD) && \ |
| 39 | !defined(CONFIG_SPL_BUILD) |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 40 | void lcdbacklight(int on) |
| 41 | { |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 42 | unsigned int driver = env_get_ulong("ds1_bright_drv", 16, 0UL); |
| 43 | unsigned int bright = env_get_ulong("ds1_bright_def", 10, 50); |
| 44 | unsigned int pwmfrq = env_get_ulong("ds1_pwmfreq", 10, ~0UL); |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 45 | unsigned int tmp; |
Hannes Petermaier | 129fe97 | 2015-06-11 12:25:43 +0200 | [diff] [blame] | 46 | struct gptimer *timerhw; |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 47 | |
| 48 | if (on) |
| 49 | bright = bright != ~0UL ? bright : 50; |
| 50 | else |
| 51 | bright = 0; |
| 52 | |
| 53 | switch (driver) { |
Hannes Petermaier | 129fe97 | 2015-06-11 12:25:43 +0200 | [diff] [blame] | 54 | case 2: |
| 55 | timerhw = (struct gptimer *)DM_TIMER5_BASE; |
| 56 | break; |
| 57 | default: |
| 58 | timerhw = (struct gptimer *)DM_TIMER6_BASE; |
| 59 | } |
| 60 | |
| 61 | switch (driver) { |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 62 | case 0: /* PMIC LED-Driver */ |
| 63 | /* brightness level */ |
| 64 | tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, |
| 65 | TPS65217_WLEDCTRL2, bright, 0xFF); |
| 66 | /* current sink */ |
| 67 | tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, |
| 68 | TPS65217_WLEDCTRL1, |
| 69 | bright != 0 ? 0x0A : 0x02, |
| 70 | 0xFF); |
| 71 | break; |
Hannes Petermaier | 129fe97 | 2015-06-11 12:25:43 +0200 | [diff] [blame] | 72 | case 1: |
| 73 | case 2: /* PWM using timer */ |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 74 | if (pwmfrq != ~0UL) { |
| 75 | timerhw->tiocp_cfg = TCFG_RESET; |
| 76 | udelay(10); |
| 77 | while (timerhw->tiocp_cfg & TCFG_RESET) |
| 78 | ; |
| 79 | tmp = ~0UL-(V_OSCK/pwmfrq); /* bottom value */ |
| 80 | timerhw->tldr = tmp; |
| 81 | timerhw->tcrr = tmp; |
| 82 | tmp = tmp + ((V_OSCK/pwmfrq)/100) * bright; |
| 83 | timerhw->tmar = tmp; |
| 84 | timerhw->tclr = (TCLR_PT | (2 << TCLR_TRG_SHIFT) | |
| 85 | TCLR_CE | TCLR_AR | TCLR_ST); |
| 86 | } else { |
| 87 | puts("invalid pwmfrq in env/dtb! skip PWM-setup.\n"); |
| 88 | } |
| 89 | break; |
| 90 | default: |
| 91 | puts("no suitable backlightdriver in env/dtb!\n"); |
| 92 | break; |
| 93 | } |
| 94 | } |
| 95 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 96 | int load_lcdtiming(struct am335x_lcdpanel *panel) |
| 97 | { |
| 98 | struct am335x_lcdpanel pnltmp; |
Hannes Petermaier | d35cb79 | 2015-04-24 14:49:35 +0200 | [diff] [blame] | 99 | |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 100 | pnltmp.hactive = env_get_ulong("ds1_hactive", 10, ~0UL); |
| 101 | pnltmp.vactive = env_get_ulong("ds1_vactive", 10, ~0UL); |
| 102 | pnltmp.bpp = env_get_ulong("ds1_bpp", 10, ~0UL); |
| 103 | pnltmp.hfp = env_get_ulong("ds1_hfp", 10, ~0UL); |
| 104 | pnltmp.hbp = env_get_ulong("ds1_hbp", 10, ~0UL); |
| 105 | pnltmp.hsw = env_get_ulong("ds1_hsw", 10, ~0UL); |
| 106 | pnltmp.vfp = env_get_ulong("ds1_vfp", 10, ~0UL); |
| 107 | pnltmp.vbp = env_get_ulong("ds1_vbp", 10, ~0UL); |
| 108 | pnltmp.vsw = env_get_ulong("ds1_vsw", 10, ~0UL); |
Hannes Schmelzer | d6ace8e | 2018-01-09 19:01:35 +0100 | [diff] [blame] | 109 | pnltmp.pxl_clk = env_get_ulong("ds1_pxlclk", 10, ~0UL); |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 110 | pnltmp.pol = env_get_ulong("ds1_pol", 16, ~0UL); |
| 111 | pnltmp.pup_delay = env_get_ulong("ds1_pupdelay", 10, ~0UL); |
| 112 | pnltmp.pon_delay = env_get_ulong("ds1_tondelay", 10, ~0UL); |
| 113 | panel_info.vl_rot = env_get_ulong("ds1_rotation", 10, 0); |
Hannes Schmelzer | 90168e8 | 2018-07-06 15:41:18 +0200 | [diff] [blame^] | 114 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 115 | if ( |
| 116 | ~0UL == (pnltmp.hactive) || |
| 117 | ~0UL == (pnltmp.vactive) || |
| 118 | ~0UL == (pnltmp.bpp) || |
| 119 | ~0UL == (pnltmp.hfp) || |
| 120 | ~0UL == (pnltmp.hbp) || |
| 121 | ~0UL == (pnltmp.hsw) || |
| 122 | ~0UL == (pnltmp.vfp) || |
| 123 | ~0UL == (pnltmp.vbp) || |
| 124 | ~0UL == (pnltmp.vsw) || |
Hannes Schmelzer | d6ace8e | 2018-01-09 19:01:35 +0100 | [diff] [blame] | 125 | ~0UL == (pnltmp.pxl_clk) || |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 126 | ~0UL == (pnltmp.pol) || |
| 127 | ~0UL == (pnltmp.pup_delay) || |
| 128 | ~0UL == (pnltmp.pon_delay) |
| 129 | ) { |
| 130 | puts("lcd-settings in env/dtb incomplete!\n"); |
| 131 | printf("display-timings:\n" |
| 132 | "================\n" |
| 133 | "hactive: %d\n" |
| 134 | "vactive: %d\n" |
| 135 | "bpp : %d\n" |
| 136 | "hfp : %d\n" |
| 137 | "hbp : %d\n" |
| 138 | "hsw : %d\n" |
| 139 | "vfp : %d\n" |
| 140 | "vbp : %d\n" |
| 141 | "vsw : %d\n" |
| 142 | "pxlclk : %d\n" |
| 143 | "pol : 0x%08x\n" |
| 144 | "pondly : %d\n", |
| 145 | pnltmp.hactive, pnltmp.vactive, pnltmp.bpp, |
| 146 | pnltmp.hfp, pnltmp.hbp, pnltmp.hsw, |
| 147 | pnltmp.vfp, pnltmp.vbp, pnltmp.vsw, |
Hannes Schmelzer | d6ace8e | 2018-01-09 19:01:35 +0100 | [diff] [blame] | 148 | pnltmp.pxl_clk, pnltmp.pol, pnltmp.pon_delay); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 149 | |
| 150 | return -1; |
| 151 | } |
| 152 | debug("lcd-settings in env complete, taking over.\n"); |
| 153 | memcpy((void *)panel, |
| 154 | (void *)&pnltmp, |
| 155 | sizeof(struct am335x_lcdpanel)); |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 160 | int ft_board_setup(void *blob, bd_t *bd) |
| 161 | { |
| 162 | int nodeoffset; |
| 163 | |
| 164 | nodeoffset = fdt_path_offset(blob, "/factory-settings"); |
| 165 | if (nodeoffset < 0) { |
| 166 | puts("set bootloader version 'factory-settings' not in dtb!\n"); |
| 167 | return -1; |
| 168 | } |
| 169 | if (fdt_setprop(blob, nodeoffset, "bl-version", |
| 170 | PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) { |
| 171 | puts("set bootloader version 'bl-version' prop. not in dtb!\n"); |
| 172 | return -1; |
| 173 | } |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 174 | /* |
| 175 | * if no simplefb is requested through environment, we don't set up |
| 176 | * one, instead we turn off backlight. |
| 177 | */ |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 178 | if (env_get_ulong("simplefb", 10, 0) == 0) { |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 179 | lcdbacklight(0); |
| 180 | return 0; |
| 181 | } |
| 182 | /* Setup simplefb devicetree node, also adapt memory-node, |
| 183 | * upper limit for kernel e.g. linux is memtop-framebuffer alligned |
| 184 | * to a full megabyte. |
| 185 | */ |
| 186 | u64 start = gd->bd->bi_dram[0].start; |
| 187 | u64 size = (gd->fb_base - start) & ~0xFFFFF; |
| 188 | int rc = fdt_fixup_memory_banks(blob, &start, &size, 1); |
| 189 | |
| 190 | if (rc) { |
| 191 | puts("cannot setup simplefb: Error reserving memory!\n"); |
| 192 | return rc; |
| 193 | } |
| 194 | rc = lcd_dt_simplefb_enable_existing_node(blob); |
| 195 | if (rc) { |
| 196 | puts("cannot setup simplefb: error enabling simplefb node!\n"); |
| 197 | return rc; |
| 198 | } |
| 199 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 200 | return 0; |
| 201 | } |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 202 | |
| 203 | static void br_summaryscreen_printenv(char *prefix, |
| 204 | char *name, char *altname, |
| 205 | char *suffix) |
| 206 | { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 207 | char *envval = env_get(name); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 208 | if (0 != envval) { |
| 209 | lcd_printf("%s %s %s", prefix, envval, suffix); |
| 210 | } else if (0 != altname) { |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 211 | envval = env_get(altname); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 212 | if (0 != envval) |
| 213 | lcd_printf("%s %s %s", prefix, envval, suffix); |
| 214 | } else { |
| 215 | lcd_printf("\n"); |
| 216 | } |
| 217 | } |
Hannes Schmelzer | 90168e8 | 2018-07-06 15:41:18 +0200 | [diff] [blame^] | 218 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 219 | void br_summaryscreen(void) |
| 220 | { |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 221 | br_summaryscreen_printenv(" - B&R -", "br_orderno", 0, "-\n"); |
| 222 | br_summaryscreen_printenv(" Serial/Rev :", "br_serial", 0, "\n"); |
| 223 | br_summaryscreen_printenv(" MAC (IF1) :", "br_mac1", "ethaddr", "\n"); |
| 224 | br_summaryscreen_printenv(" MAC (IF2) :", "br_mac2", 0, "\n"); |
| 225 | lcd_puts(" Bootloader : " PLAIN_VERSION "\n"); |
| 226 | lcd_puts("\n"); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | void lcdpower(int on) |
| 230 | { |
| 231 | u32 pin, swval, i; |
Hannes Schmelzer | 90168e8 | 2018-07-06 15:41:18 +0200 | [diff] [blame^] | 232 | |
Simon Glass | 22c34c2 | 2017-08-03 12:22:13 -0600 | [diff] [blame] | 233 | pin = env_get_ulong("ds1_pwr", 16, ~0UL); |
Hannes Schmelzer | 90168e8 | 2018-07-06 15:41:18 +0200 | [diff] [blame^] | 234 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 235 | if (pin == ~0UL) { |
| 236 | puts("no pwrpin in dtb/env, cannot powerup display!\n"); |
| 237 | return; |
| 238 | } |
| 239 | |
| 240 | for (i = 0; i < 3; i++) { |
| 241 | if (pin != 0) { |
| 242 | swval = pin & 0x80 ? 0 : 1; |
| 243 | if (on) |
| 244 | gpio_direction_output(pin & 0x7F, swval); |
| 245 | else |
| 246 | gpio_direction_output(pin & 0x7F, !swval); |
| 247 | |
| 248 | debug("switched pin %d to %d\n", pin & 0x7F, swval); |
| 249 | } |
| 250 | pin >>= 8; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | vidinfo_t panel_info = { |
| 255 | .vl_col = 1366, /* |
| 256 | * give full resolution for allocating enough |
| 257 | * memory |
| 258 | */ |
| 259 | .vl_row = 768, |
| 260 | .vl_bpix = 5, |
| 261 | .priv = 0 |
| 262 | }; |
| 263 | |
| 264 | void lcd_ctrl_init(void *lcdbase) |
| 265 | { |
| 266 | struct am335x_lcdpanel lcd_panel; |
Hannes Schmelzer | 90168e8 | 2018-07-06 15:41:18 +0200 | [diff] [blame^] | 267 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 268 | memset(&lcd_panel, 0, sizeof(struct am335x_lcdpanel)); |
| 269 | if (load_lcdtiming(&lcd_panel) != 0) |
| 270 | return; |
| 271 | |
| 272 | lcd_panel.panel_power_ctrl = &lcdpower; |
| 273 | |
| 274 | if (0 != am335xfb_init(&lcd_panel)) |
| 275 | printf("ERROR: failed to initialize video!"); |
| 276 | /* |
| 277 | * modifiy panel info to 'real' resolution, to operate correct with |
| 278 | * lcd-framework. |
| 279 | */ |
| 280 | panel_info.vl_col = lcd_panel.hactive; |
| 281 | panel_info.vl_row = lcd_panel.vactive; |
| 282 | |
| 283 | lcd_set_flush_dcache(1); |
| 284 | } |
| 285 | |
| 286 | void lcd_enable(void) |
| 287 | { |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 288 | br_summaryscreen(); |
Hannes Petermaier | 1df983f | 2015-04-24 14:49:37 +0200 | [diff] [blame] | 289 | lcdbacklight(1); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 290 | } |
| 291 | #elif CONFIG_SPL_BUILD |
| 292 | #else |
| 293 | #error "LCD-support with a suitable FB-Driver is mandatory !" |
| 294 | #endif /* CONFIG_LCD */ |
| 295 | |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 296 | #ifdef CONFIG_SPL_BUILD |
| 297 | void pmicsetup(u32 mpupll) |
| 298 | { |
| 299 | int mpu_vdd; |
| 300 | int usb_cur_lim; |
| 301 | |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 302 | if (i2c_probe(TPS65217_CHIP_PM)) { |
| 303 | puts("PMIC (0x24) not found! skip further initalization.\n"); |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | /* Get the frequency which is defined by device fuses */ |
| 308 | dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); |
| 309 | printf("detected max. frequency: %d - ", dpll_mpu_opp100.m); |
| 310 | |
| 311 | if (0 != mpupll) { |
| 312 | dpll_mpu_opp100.m = MPUPLL_M_1000; |
| 313 | printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m); |
| 314 | } else { |
| 315 | puts("ok.\n"); |
| 316 | } |
| 317 | /* |
| 318 | * Increase USB current limit to 1300mA or 1800mA and set |
| 319 | * the MPU voltage controller as needed. |
| 320 | */ |
| 321 | if (dpll_mpu_opp100.m == MPUPLL_M_1000) { |
| 322 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA; |
| 323 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV; |
| 324 | } else { |
| 325 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA; |
| 326 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV; |
| 327 | } |
| 328 | |
| 329 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH, |
| 330 | usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK)) |
| 331 | puts("tps65217_reg_write failure\n"); |
| 332 | |
| 333 | /* Set DCDC3 (CORE) voltage to 1.125V */ |
| 334 | if (tps65217_voltage_update(TPS65217_DEFDCDC3, |
| 335 | TPS65217_DCDC_VOLT_SEL_1125MV)) { |
| 336 | puts("tps65217_voltage_update failure\n"); |
| 337 | return; |
| 338 | } |
| 339 | |
| 340 | /* Set CORE Frequencies to OPP100 */ |
| 341 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
| 342 | |
| 343 | /* Set DCDC2 (MPU) voltage */ |
| 344 | if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) { |
| 345 | puts("tps65217_voltage_update failure\n"); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | /* Set LDO3 to 1.8V */ |
| 350 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 351 | TPS65217_DEFLS1, |
| 352 | TPS65217_LDO_VOLTAGE_OUT_1_8, |
| 353 | TPS65217_LDO_MASK)) |
| 354 | puts("tps65217_reg_write failure\n"); |
| 355 | /* Set LDO4 to 3.3V */ |
| 356 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 357 | TPS65217_DEFLS2, |
| 358 | TPS65217_LDO_VOLTAGE_OUT_3_3, |
| 359 | TPS65217_LDO_MASK)) |
| 360 | puts("tps65217_reg_write failure\n"); |
| 361 | |
| 362 | /* Set MPU Frequency to what we detected now that voltages are set */ |
| 363 | do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 364 | /* Set PWR_EN bit in Status Register */ |
| 365 | tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, |
| 366 | TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF); |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | void set_uart_mux_conf(void) |
| 370 | { |
| 371 | enable_uart0_pin_mux(); |
| 372 | } |
| 373 | |
| 374 | void set_mux_conf_regs(void) |
| 375 | { |
| 376 | enable_board_pin_mux(); |
| 377 | } |
| 378 | |
| 379 | #endif /* CONFIG_SPL_BUILD */ |
| 380 | |
| 381 | #if (defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD)) || \ |
| 382 | (defined(CONFIG_SPL_ETH_SUPPORT) && defined(CONFIG_SPL_BUILD)) |
| 383 | static void cpsw_control(int enabled) |
| 384 | { |
| 385 | /* VTP can be added here */ |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | /* describing port offsets of TI's CPSW block */ |
| 390 | static struct cpsw_slave_data cpsw_slaves[] = { |
| 391 | { |
| 392 | .slave_reg_ofs = 0x208, |
| 393 | .sliver_reg_ofs = 0xd80, |
Hannes Petermaier | 12da051 | 2014-03-06 07:03:24 +0100 | [diff] [blame] | 394 | .phy_addr = 1, |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 395 | }, |
| 396 | { |
| 397 | .slave_reg_ofs = 0x308, |
| 398 | .sliver_reg_ofs = 0xdc0, |
Hannes Petermaier | 12da051 | 2014-03-06 07:03:24 +0100 | [diff] [blame] | 399 | .phy_addr = 2, |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 400 | }, |
| 401 | }; |
| 402 | |
| 403 | static struct cpsw_platform_data cpsw_data = { |
| 404 | .mdio_base = CPSW_MDIO_BASE, |
| 405 | .cpsw_base = CPSW_BASE, |
| 406 | .mdio_div = 0xff, |
| 407 | .channels = 8, |
| 408 | .cpdma_reg_ofs = 0x800, |
| 409 | .slaves = 1, |
| 410 | .slave_data = cpsw_slaves, |
| 411 | .ale_reg_ofs = 0xd00, |
| 412 | .ale_entries = 1024, |
| 413 | .host_port_reg_ofs = 0x108, |
| 414 | .hw_stats_reg_ofs = 0x900, |
| 415 | .bd_ram_ofs = 0x2000, |
| 416 | .mac_control = (1 << 5), |
| 417 | .control = cpsw_control, |
| 418 | .host_port_num = 0, |
| 419 | .version = CPSW_CTRL_VERSION_2, |
| 420 | }; |
| 421 | #endif /* CONFIG_DRIVER_TI_CPSW, ... */ |
| 422 | |
Hannes Schmelzer | 41bfcfb | 2016-02-19 12:09:42 +0100 | [diff] [blame] | 423 | #if defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD) |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 424 | int board_eth_init(bd_t *bis) |
| 425 | { |
| 426 | int rv = 0; |
Hannes Petermaier | 077f26c | 2015-02-03 13:22:27 +0100 | [diff] [blame] | 427 | char mac_addr[6]; |
| 428 | const char *mac = 0; |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 429 | uint32_t mac_hi, mac_lo; |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 430 | /* try reading mac address from efuse */ |
| 431 | mac_lo = readl(&cdev->macid0l); |
| 432 | mac_hi = readl(&cdev->macid0h); |
| 433 | mac_addr[0] = mac_hi & 0xFF; |
| 434 | mac_addr[1] = (mac_hi & 0xFF00) >> 8; |
| 435 | mac_addr[2] = (mac_hi & 0xFF0000) >> 16; |
| 436 | mac_addr[3] = (mac_hi & 0xFF000000) >> 24; |
| 437 | mac_addr[4] = mac_lo & 0xFF; |
| 438 | mac_addr[5] = (mac_lo & 0xFF00) >> 8; |
| 439 | |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 440 | if (!env_get("ethaddr")) { |
Hannes Petermaier | 077f26c | 2015-02-03 13:22:27 +0100 | [diff] [blame] | 441 | if (!mac) { |
| 442 | printf("<ethaddr> not set. validating E-fuse MAC ... "); |
Joe Hershberger | 8ecdbed | 2015-04-08 01:41:04 -0500 | [diff] [blame] | 443 | if (is_valid_ethaddr((const u8 *)mac_addr)) |
Hannes Petermaier | 077f26c | 2015-02-03 13:22:27 +0100 | [diff] [blame] | 444 | mac = (const char *)mac_addr; |
| 445 | } |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 446 | |
Hannes Petermaier | 077f26c | 2015-02-03 13:22:27 +0100 | [diff] [blame] | 447 | if (mac) { |
| 448 | printf("using: %pM on ", mac); |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 449 | eth_env_set_enetaddr("ethaddr", (const u8 *)mac); |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 450 | } |
| 451 | } |
| 452 | writel(MII_MODE_ENABLE, &cdev->miisel); |
| 453 | cpsw_slaves[0].phy_if = PHY_INTERFACE_MODE_MII; |
| 454 | cpsw_slaves[1].phy_if = PHY_INTERFACE_MODE_MII; |
| 455 | |
| 456 | rv = cpsw_register(&cpsw_data); |
| 457 | if (rv < 0) { |
| 458 | printf("Error %d registering CPSW switch\n", rv); |
| 459 | return 0; |
| 460 | } |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 461 | return rv; |
| 462 | } |
Hannes Schmelzer | 41bfcfb | 2016-02-19 12:09:42 +0100 | [diff] [blame] | 463 | #endif /* defined(CONFIG_DRIVER_TI_CPSW) && !defined(CONFIG_SPL_BUILD) */ |
Masahiro Yamada | 0a78017 | 2017-05-09 20:31:39 +0900 | [diff] [blame] | 464 | #if defined(CONFIG_MMC) |
Hannes Petermaier | 8e731ed | 2014-04-08 08:39:20 +0200 | [diff] [blame] | 465 | int board_mmc_init(bd_t *bis) |
| 466 | { |
Hannes Schmelzer | d58c06d | 2017-06-13 14:11:29 +0200 | [diff] [blame] | 467 | int rc = 0; |
| 468 | |
| 469 | rc |= omap_mmc_init(0, 0, 0, -1, -1); |
| 470 | rc |= omap_mmc_init(1, 0, 0, -1, -1); |
| 471 | |
| 472 | return rc; |
Hannes Petermaier | 8e731ed | 2014-04-08 08:39:20 +0200 | [diff] [blame] | 473 | } |
| 474 | #endif |
Hannes Petermaier | c84a889 | 2015-03-17 15:31:21 +0100 | [diff] [blame] | 475 | int overwrite_console(void) |
| 476 | { |
| 477 | return 1; |
| 478 | } |