blob: c6126e251ecc44a59a5dab6882b9a94a0b056288 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Hannes Petermaierfb003662014-02-07 08:07:36 +01002/*
3 * common.c
4 *
5 * common board functions for B&R boards
6 *
Hannes Schmelzer7935f032015-05-28 15:41:12 +02007 * Copyright (C) 2013 Hannes Schmelzer <oe5hpm@oevsv.at>
Hannes Petermaierfb003662014-02-07 08:07:36 +01008 * Bernecker & Rainer Industrieelektronik GmbH - http://www.br-automation.com
9 *
Hannes Petermaierfb003662014-02-07 08:07:36 +010010 */
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +010012#include <version.h>
Hannes Petermaierfb003662014-02-07 08:07:36 +010013#include <common.h>
Simon Glass313112a2019-08-01 09:46:46 -060014#include <env.h>
Hannes Schmelzer1386d412019-04-10 14:13:11 +020015#include <fdtdec.h>
Hannes Petermaierfb003662014-02-07 08:07:36 +010016#include <i2c.h>
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +010017#include <lcd.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Simon Glassdbd79542020-05-10 11:40:11 -060019#include <linux/delay.h>
Hannes Petermaierfb003662014-02-07 08:07:36 +010020#include "bur_common.h"
21
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +010022DECLARE_GLOBAL_DATA_PTR;
23
Hannes Petermaierfb003662014-02-07 08:07:36 +010024/* --------------------------------------------------------------------------*/
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +010025
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090026int ft_board_setup(void *blob, struct bd_info *bd)
Hannes Schmelzera21ed272018-07-06 15:41:20 +020027{
28 int nodeoffset;
29
30 nodeoffset = fdt_path_offset(blob, "/factory-settings");
31 if (nodeoffset < 0) {
Hannes Schmelzerde4225b2018-07-06 15:41:25 +020032 printf("%s: cannot find /factory-settings, trying /fset\n",
33 __func__);
34 nodeoffset = fdt_path_offset(blob, "/fset");
35 if (nodeoffset < 0) {
36 printf("%s: cannot find /fset.\n", __func__);
37 return 0;
38 }
Hannes Schmelzera21ed272018-07-06 15:41:20 +020039 }
Hannes Schmelzerde4225b2018-07-06 15:41:25 +020040
Hannes Schmelzera21ed272018-07-06 15:41:20 +020041 if (fdt_setprop(blob, nodeoffset, "bl-version",
42 PLAIN_VERSION, strlen(PLAIN_VERSION)) != 0) {
Hannes Schmelzerde4225b2018-07-06 15:41:25 +020043 printf("%s: no 'bl-version' prop in fdt!\n", __func__);
44 return 0;
Hannes Schmelzera21ed272018-07-06 15:41:20 +020045 }
Hannes Schmelzera21ed272018-07-06 15:41:20 +020046 return 0;
47}
48
Hannes Schmelzer6cd12ce2019-04-10 14:13:13 +020049int brdefaultip_setup(int bus, int chip)
50{
51 int rc;
52 struct udevice *i2cdev;
53 u8 u8buf = 0;
54 char defip[256] = { 0 };
55
56 rc = i2c_get_chip_for_busnum(bus, chip, 2, &i2cdev);
57 if (rc != 0) {
58 printf("WARN: cannot probe baseboard EEPROM!\n");
59 return -1;
60 }
61
62 rc = dm_i2c_read(i2cdev, 0, &u8buf, 1);
63 if (rc != 0) {
64 printf("WARN: cannot read baseboard EEPROM!\n");
65 return -1;
66 }
67
68 if (u8buf != 0xFF)
69 snprintf(defip, sizeof(defip),
70 "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;",
71 u8buf);
72 else
73 strncpy(defip,
74 "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;",
75 sizeof(defip));
76
77 env_set("brdefaultip", defip);
78 env_set_hex("board_id", u8buf);
79
80 return 0;
81}
82
Hannes Schmelzer9df7d732019-04-10 14:13:12 +020083int overwrite_console(void)
84{
85 return 1;
86}
87
Hannes Schmelzer1386d412019-04-10 14:13:11 +020088#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_AM33XX)
89#include <asm/arch/hardware.h>
90#include <asm/arch/omap.h>
91#include <asm/arch/clock.h>
92#include <asm/arch/sys_proto.h>
93#include <power/tps65217.h>
Hannes Schmelzer5639eeb2018-07-06 15:41:28 +020094
95static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
96
Hannes Schmelzer717ee362019-01-31 09:24:45 +010097void pmicsetup(u32 mpupll, unsigned int bus)
Hannes Petermaierfb003662014-02-07 08:07:36 +010098{
99 int mpu_vdd;
100 int usb_cur_lim;
101
Hannes Schmelzer717ee362019-01-31 09:24:45 +0100102 if (power_tps65217_init(bus)) {
103 printf("WARN: cannot setup PMIC 0x24 @ bus #%d, not found!.\n",
104 bus);
Hannes Petermaierfb003662014-02-07 08:07:36 +0100105 return;
106 }
107
108 /* Get the frequency which is defined by device fuses */
109 dpll_mpu_opp100.m = am335x_get_efuse_mpu_max_freq(cdev);
110 printf("detected max. frequency: %d - ", dpll_mpu_opp100.m);
111
112 if (0 != mpupll) {
Hannes Schmelzer29bea942018-07-06 15:41:23 +0200113 dpll_mpu_opp100.m = mpupll;
Hannes Petermaierfb003662014-02-07 08:07:36 +0100114 printf("retuning MPU-PLL to: %d MHz.\n", dpll_mpu_opp100.m);
115 } else {
116 puts("ok.\n");
117 }
118 /*
119 * Increase USB current limit to 1300mA or 1800mA and set
120 * the MPU voltage controller as needed.
121 */
122 if (dpll_mpu_opp100.m == MPUPLL_M_1000) {
123 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1800MA;
124 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1325MV;
125 } else {
126 usb_cur_lim = TPS65217_USB_INPUT_CUR_LIMIT_1300MA;
127 mpu_vdd = TPS65217_DCDC_VOLT_SEL_1275MV;
128 }
129
130 if (tps65217_reg_write(TPS65217_PROT_LEVEL_NONE, TPS65217_POWER_PATH,
131 usb_cur_lim, TPS65217_USB_INPUT_CUR_LIMIT_MASK))
132 puts("tps65217_reg_write failure\n");
133
134 /* Set DCDC3 (CORE) voltage to 1.125V */
135 if (tps65217_voltage_update(TPS65217_DEFDCDC3,
136 TPS65217_DCDC_VOLT_SEL_1125MV)) {
137 puts("tps65217_voltage_update failure\n");
138 return;
139 }
140
141 /* Set CORE Frequencies to OPP100 */
142 do_setup_dpll(&dpll_core_regs, &dpll_core_opp100);
143
144 /* Set DCDC2 (MPU) voltage */
145 if (tps65217_voltage_update(TPS65217_DEFDCDC2, mpu_vdd)) {
146 puts("tps65217_voltage_update failure\n");
147 return;
148 }
149
150 /* Set LDO3 to 1.8V */
151 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
152 TPS65217_DEFLS1,
153 TPS65217_LDO_VOLTAGE_OUT_1_8,
154 TPS65217_LDO_MASK))
155 puts("tps65217_reg_write failure\n");
156 /* Set LDO4 to 3.3V */
157 if (tps65217_reg_write(TPS65217_PROT_LEVEL_2,
158 TPS65217_DEFLS2,
159 TPS65217_LDO_VOLTAGE_OUT_3_3,
160 TPS65217_LDO_MASK))
161 puts("tps65217_reg_write failure\n");
162
163 /* Set MPU Frequency to what we detected now that voltages are set */
164 do_setup_dpll(&dpll_mpu_regs, &dpll_mpu_opp100);
Hannes Petermaier69d0d7d2015-02-03 13:22:26 +0100165 /* Set PWR_EN bit in Status Register */
166 tps65217_reg_write(TPS65217_PROT_LEVEL_NONE,
167 TPS65217_STATUS, TPS65217_PWR_OFF, TPS65217_PWR_OFF);
Hannes Petermaierfb003662014-02-07 08:07:36 +0100168}
169
170void set_uart_mux_conf(void)
171{
172 enable_uart0_pin_mux();
173}
174
175void set_mux_conf_regs(void)
176{
177 enable_board_pin_mux();
178}
179
Hannes Schmelzer1386d412019-04-10 14:13:11 +0200180#endif /* CONFIG_SPL_BUILD && CONFIG_AM33XX */