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 | */ |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 12 | #include <version.h> |
Simon Glass | 313112a | 2019-08-01 09:46:46 -0600 | [diff] [blame] | 13 | #include <env.h> |
Hannes Schmelzer | 1386d41 | 2019-04-10 14:13:11 +0200 | [diff] [blame] | 14 | #include <fdtdec.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 15 | #include <i2c.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 16 | #include <asm/global_data.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 17 | #include <linux/delay.h> |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 18 | #include "bur_common.h" |
| 19 | |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 22 | /* --------------------------------------------------------------------------*/ |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 23 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 24 | int ft_board_setup(void *blob, struct bd_info *bd) |
Hannes Schmelzer | a21ed27 | 2018-07-06 15:41:20 +0200 | [diff] [blame] | 25 | { |
| 26 | int nodeoffset; |
| 27 | |
| 28 | nodeoffset = fdt_path_offset(blob, "/factory-settings"); |
| 29 | if (nodeoffset < 0) { |
Hannes Schmelzer | de4225b | 2018-07-06 15:41:25 +0200 | [diff] [blame] | 30 | printf("%s: cannot find /factory-settings, trying /fset\n", |
| 31 | __func__); |
| 32 | nodeoffset = fdt_path_offset(blob, "/fset"); |
| 33 | if (nodeoffset < 0) { |
| 34 | printf("%s: cannot find /fset.\n", __func__); |
| 35 | return 0; |
| 36 | } |
Hannes Schmelzer | a21ed27 | 2018-07-06 15:41:20 +0200 | [diff] [blame] | 37 | } |
Hannes Schmelzer | de4225b | 2018-07-06 15:41:25 +0200 | [diff] [blame] | 38 | |
Hannes Schmelzer | a21ed27 | 2018-07-06 15:41:20 +0200 | [diff] [blame] | 39 | if (fdt_setprop(blob, nodeoffset, "bl-version", |
| 40 | PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) { |
Hannes Schmelzer | de4225b | 2018-07-06 15:41:25 +0200 | [diff] [blame] | 41 | printf("%s: no 'bl-version' prop in fdt!\n", __func__); |
| 42 | return 0; |
Hannes Schmelzer | a21ed27 | 2018-07-06 15:41:20 +0200 | [diff] [blame] | 43 | } |
Hannes Schmelzer | a21ed27 | 2018-07-06 15:41:20 +0200 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | |
Hannes Schmelzer | 6cd12ce | 2019-04-10 14:13:13 +0200 | [diff] [blame] | 47 | int brdefaultip_setup(int bus, int chip) |
| 48 | { |
| 49 | int rc; |
| 50 | struct udevice *i2cdev; |
| 51 | u8 u8buf = 0; |
| 52 | char defip[256] = { 0 }; |
| 53 | |
| 54 | rc = i2c_get_chip_for_busnum(bus, chip, 2, &i2cdev); |
| 55 | if (rc != 0) { |
| 56 | printf("WARN: cannot probe baseboard EEPROM!\n"); |
| 57 | return -1; |
| 58 | } |
| 59 | |
| 60 | rc = dm_i2c_read(i2cdev, 0, &u8buf, 1); |
| 61 | if (rc != 0) { |
| 62 | printf("WARN: cannot read baseboard EEPROM!\n"); |
| 63 | return -1; |
| 64 | } |
| 65 | |
| 66 | if (u8buf != 0xFF) |
| 67 | snprintf(defip, sizeof(defip), |
| 68 | "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.%d; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;", |
| 69 | u8buf); |
| 70 | else |
| 71 | strncpy(defip, |
| 72 | "if test -r ${ipaddr}; then; else setenv ipaddr 192.168.60.1; setenv serverip 192.168.60.254; setenv gatewayip 192.168.60.254; setenv netmask 255.255.255.0; fi;", |
| 73 | sizeof(defip)); |
| 74 | |
| 75 | env_set("brdefaultip", defip); |
| 76 | env_set_hex("board_id", u8buf); |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
Hannes Schmelzer | 9df7d73 | 2019-04-10 14:13:12 +0200 | [diff] [blame] | 81 | int overwrite_console(void) |
| 82 | { |
| 83 | return 1; |
| 84 | } |
| 85 | |
Simon Glass | 49c24a8 | 2024-09-29 19:49:47 -0600 | [diff] [blame] | 86 | #if defined(CONFIG_XPL_BUILD) && defined(CONFIG_AM33XX) |
Hannes Schmelzer | 1386d41 | 2019-04-10 14:13:11 +0200 | [diff] [blame] | 87 | #include <asm/arch/hardware.h> |
| 88 | #include <asm/arch/omap.h> |
| 89 | #include <asm/arch/clock.h> |
| 90 | #include <asm/arch/sys_proto.h> |
| 91 | #include <power/tps65217.h> |
Hannes Schmelzer | 5639eeb | 2018-07-06 15:41:28 +0200 | [diff] [blame] | 92 | |
| 93 | static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE; |
| 94 | |
Hannes Schmelzer | 717ee36 | 2019-01-31 09:24:45 +0100 | [diff] [blame] | 95 | void pmicsetup(u32 mpupll, unsigned int bus) |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 96 | { |
| 97 | int mpu_vdd; |
| 98 | int usb_cur_lim; |
| 99 | |
Hannes Schmelzer | 717ee36 | 2019-01-31 09:24:45 +0100 | [diff] [blame] | 100 | if (power_tps65217_init(bus)) { |
| 101 | printf("WARN: cannot setup PMIC 0x24 @ bus #%d, not found!.\n", |
| 102 | bus); |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 103 | return; |
| 104 | } |
| 105 | |
| 106 | /* Get the frequency which is defined by device fuses */ |
| 107 | dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev); |
| 108 | printf("detected max. frequency: %d - ", dpll_mpu_opp100.m); |
| 109 | |
| 110 | if (0 != mpupll) { |
Hannes Schmelzer | 29bea94 | 2018-07-06 15:41:23 +0200 | [diff] [blame] | 111 | dpll_mpu_opp100.m = mpupll; |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 112 | printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m); |
| 113 | } else { |
| 114 | puts("ok.\n"); |
| 115 | } |
| 116 | /* |
| 117 | * Increase USB current limit to 1300mA or 1800mA and set |
| 118 | * the MPU voltage controller as needed. |
| 119 | */ |
| 120 | if (dpll_mpu_opp100.m == MPUPLL_M_1000) { |
| 121 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA; |
| 122 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV; |
| 123 | } else { |
| 124 | usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA; |
| 125 | mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV; |
| 126 | } |
| 127 | |
| 128 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH, |
| 129 | usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK)) |
| 130 | puts("tps65217_reg_write failure\n"); |
| 131 | |
| 132 | /* Set DCDC3 (CORE) voltage to 1.125V */ |
| 133 | if (tps65217_voltage_update(TPS65217_DEFDCDC3, |
| 134 | TPS65217_DCDC_VOLT_SEL_1125MV)) { |
| 135 | puts("tps65217_voltage_update failure\n"); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | /* Set CORE Frequencies to OPP100 */ |
| 140 | do_setup_dpll(&dpll_core_regs, &dpll_core_opp100); |
| 141 | |
| 142 | /* Set DCDC2 (MPU) voltage */ |
| 143 | if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) { |
| 144 | puts("tps65217_voltage_update failure\n"); |
| 145 | return; |
| 146 | } |
| 147 | |
| 148 | /* Set LDO3 to 1.8V */ |
| 149 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 150 | TPS65217_DEFLS1, |
| 151 | TPS65217_LDO_VOLTAGE_OUT_1_8, |
| 152 | TPS65217_LDO_MASK)) |
| 153 | puts("tps65217_reg_write failure\n"); |
| 154 | /* Set LDO4 to 3.3V */ |
| 155 | if (tps65217_reg_write(TPS65217_PROT_LEVEL_2, |
| 156 | TPS65217_DEFLS2, |
| 157 | TPS65217_LDO_VOLTAGE_OUT_3_3, |
| 158 | TPS65217_LDO_MASK)) |
| 159 | puts("tps65217_reg_write failure\n"); |
| 160 | |
| 161 | /* Set MPU Frequency to what we detected now that voltages are set */ |
| 162 | do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100); |
Hannes Petermaier | 69d0d7d | 2015-02-03 13:22:26 +0100 | [diff] [blame] | 163 | /* Set PWR_EN bit in Status Register */ |
| 164 | tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, |
| 165 | TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF); |
Hannes Petermaier | fb00366 | 2014-02-07 08:07:36 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | void set_uart_mux_conf(void) |
| 169 | { |
| 170 | enable_uart0_pin_mux(); |
| 171 | } |
| 172 | |
| 173 | void set_mux_conf_regs(void) |
| 174 | { |
| 175 | enable_board_pin_mux(); |
| 176 | } |
| 177 | |
Simon Glass | 49c24a8 | 2024-09-29 19:49:47 -0600 | [diff] [blame] | 178 | #endif /* CONFIG_XPL_BUILD && CONFIG_AM33XX */ |