1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright 2017-2019 NXP
*
* Copyright 2019 Siemens AG
*
*/
#include <common.h>
#include <command.h>
#include <dm.h>
#include <env.h>
#include <errno.h>
#include <init.h>
#include <log.h>
#include <netdev.h>
#include <env_internal.h>
#include <fsl_esdhc_imx.h>
#include <i2c.h>
#include <led.h>
#include <pca953x.h>
#include <power-domain.h>
#include <asm/gpio.h>
#include <asm/arch/imx8-pins.h>
#include <asm/arch/iomux.h>
#include <firmware/imx/sci/sci.h>
#include <asm/arch/sys_proto.h>
#ifndef CONFIG_SPL
#include <asm/arch-imx8/clock.h>
#endif
#include <linux/delay.h>
#include "../common/factoryset.h"
#define GPIO_PAD_CTRL \
((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
(SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
(SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
(SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
#define ENET_NORMAL_PAD_CTRL \
((SC_PAD_CONFIG_NORMAL << PADRING_CONFIG_SHIFT) | \
(SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
(SC_PAD_28FDSOI_DSE_18V_10MA << PADRING_DSE_SHIFT) | \
(SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
#define UART_PAD_CTRL \
((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \
(SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \
(SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \
(SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT))
static iomux_cfg_t uart2_pads[] = {
SC_P_UART2_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
SC_P_UART2_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
};
static void setup_iomux_uart(void)
{
imx8_iomux_setup_multiple_pads(uart2_pads, ARRAY_SIZE(uart2_pads));
}
int board_early_init_f(void)
{
/* Set UART clock root to 80 MHz */
sc_pm_clock_rate_t rate = SC_80MHZ;
int ret;
ret = sc_pm_setup_uart(SC_R_UART_0, rate);
ret |= sc_pm_setup_uart(SC_R_UART_2, rate);
if (ret)
return ret;
setup_iomux_uart();
return 0;
}
#define ENET_PHY_RESET IMX_GPIO_NR(0, 3)
#define ENET_TEST_1 IMX_GPIO_NR(0, 8)
#define ENET_TEST_2 IMX_GPIO_NR(0, 9)
/*#define ETH_IO_TEST*/
static iomux_cfg_t enet_reset[] = {
SC_P_ESAI0_SCKT | MUX_MODE_ALT(4) | MUX_PAD_CTRL(GPIO_PAD_CTRL),
#ifdef ETH_IO_TEST
/* GPIO0.IO08 MODE3: TXD0 */
SC_P_ESAI0_TX4_RX1 | MUX_MODE_ALT(4) |
MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
/* GPIO0.IO09 MODE3: TXD1 */
SC_P_ESAI0_TX5_RX0 | MUX_MODE_ALT(4) |
MUX_PAD_CTRL(ENET_NORMAL_PAD_CTRL),
#endif
};
static void enet_device_phy_reset(void)
{
int ret = 0;
imx8_iomux_setup_multiple_pads(enet_reset, ARRAY_SIZE(enet_reset));
ret = gpio_request(ENET_PHY_RESET, "enet_phy_reset");
if (!ret) {
gpio_direction_output(ENET_PHY_RESET, 1);
gpio_set_value(ENET_PHY_RESET, 0);
/* SMSC9303 TRM chapter 14.5.2 */
udelay(200);
gpio_set_value(ENET_PHY_RESET, 1);
} else {
printf("ENET RESET failed!\n");
}
#ifdef ETH_IO_TEST
ret = gpio_request(ENET_TEST_1, "enet_test1");
if (!ret) {
int i;
printf("ENET TEST 1!\n");
for (i = 0; i < 20; i++) {
gpio_direction_output(ENET_TEST_1, 1);
gpio_set_value(ENET_TEST_1, 0);
udelay(50);
gpio_set_value(ENET_TEST_1, 1);
udelay(50);
}
gpio_free(ENET_TEST_1);
} else {
printf("GPIO for ENET TEST 1 failed!\n");
}
ret = gpio_request(ENET_TEST_2, "enet_test2");
if (!ret) {
int i;
printf("ENET TEST 2!\n");
for (i = 0; i < 20; i++) {
gpio_direction_output(ENET_TEST_2, 1);
gpio_set_value(ENET_TEST_2, 0);
udelay(50);
gpio_set_value(ENET_TEST_2, 1);
udelay(50);
}
gpio_free(ENET_TEST_2);
} else {
printf("GPIO for ENET TEST 2 failed!\n");
}
#endif
}
int setup_gpr_fec(void)
{
sc_ipc_t ipc_handle = -1;
int err = 0;
unsigned int test;
/*
* TX_CLK_SEL: it controls a mux between clock coming from the pad 50M
* input pin and clock generated internally to connectivity subsystem
* 0: internal clock
* 1: external clock ---> your choice for RMII
*
* CLKDIV_SEL: it controls a div by 2 on the internal clock path à
* it should be don’t care when using external clock
* 0: non-divided clock
* 1: clock divided by 2
* 50_DISABLE or 125_DISABLE:
* it’s used to disable the clock tree going outside the chip
* when reference clock is generated internally.
* It should be don’t care when reference clock is provided
* externally.
* 0: clock is enabled
* 1: clock is disabled
*
* SC_C_TXCLK = 24,
* SC_C_CLKDIV = 25,
* SC_C_DISABLE_50 = 26,
* SC_C_DISABLE_125 = 27,
*/
err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, 1);
if (err)
printf("Error in setting up SC_C %d\n\r", SC_C_TXCLK);
sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
debug("TEST SC_C %d-->%d\n\r", SC_C_TXCLK, test);
err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, 0);
if (err)
printf("Error in setting up SC_C %d\n\r", SC_C_CLKDIV);
sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_CLKDIV, &test);
debug("TEST SC_C %d-->%d\n\r", SC_C_CLKDIV, test);
err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_50, 0);
if (err)
printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_50);
sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_50, test);
err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_DISABLE_125, 1);
if (err)
printf("Error in setting up SC_C %d\n\r", SC_C_DISABLE_125);
sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_TXCLK, &test);
debug("TEST SC_C %d-->%d\n\r", SC_C_DISABLE_125, test);
err = sc_misc_set_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, 1);
if (err)
printf("Error in setting up SC_C %d\n\r", SC_C_SEL_125);
sc_misc_get_control(ipc_handle, SC_R_ENET_1, SC_C_SEL_125, &test);
debug("TEST SC_C %d-->%d\n\r", SC_C_SEL_125, test);
return 0;
}
#if IS_ENABLED(CONFIG_FEC_MXC)
#include <miiphy.h>
int board_phy_config(struct phy_device *phydev)
{
if (phydev->drv->config)
phydev->drv->config(phydev);
return 0;
}
#endif
static int setup_fec(void)
{
setup_gpr_fec();
/* Reset ENET PHY */
enet_device_phy_reset();
return 0;
}
void reset_cpu(void)
{
}
#ifndef CONFIG_SPL_BUILD
/* LED's */
static int board_led_init(void)
{
struct udevice *bus, *dev;
u8 pca_led[2] = { 0x00, 0x00 };
int ret;
/* enable all leds on PCA9552 */
ret = uclass_get_device_by_seq(UCLASS_I2C, PCA9552_1_I2C_BUS, &bus);
if (ret) {
printf("ERROR: I2C get %d\n", ret);
return ret;
}
ret = dm_i2c_probe(bus, PCA9552_1_I2C_ADDR, 0, &dev);
if (ret) {
printf("ERROR: PCA9552 probe failed\n");
return ret;
}
ret = dm_i2c_write(dev, 0x16, pca_led, sizeof(pca_led));
if (ret) {
printf("ERROR: PCA9552 write failed\n");
return ret;
}
mdelay(1);
return ret;
}
#endif /* !CONFIG_SPL_BUILD */
int checkboard(void)
{
puts("Board: Capricorn\n");
/*
* Running build_info() doesn't work with current SCFW blob.
* Uncomment below call when new blob is available.
*/
/*build_info();*/
print_bootinfo();
return 0;
}
int board_init(void)
{
setup_fec();
return 0;
}
#ifdef CONFIG_OF_BOARD_SETUP
int ft_board_setup(void *blob, struct bd_info *bd)
{
return 0;
}
#endif
int board_mmc_get_env_dev(int devno)
{
return devno;
}
static int check_mmc_autodetect(void)
{
char *autodetect_str = env_get("mmcautodetect");
if (autodetect_str && (strcmp(autodetect_str, "yes") == 0))
return 1;
return 0;
}
/* This should be defined for each board */
__weak int mmc_map_to_kernel_blk(int dev_no)
{
return dev_no;
}
void board_late_mmc_env_init(void)
{
char cmd[32];
char mmcblk[32];
u32 dev_no = mmc_get_env_dev();
if (!check_mmc_autodetect())
return;
env_set_ulong("mmcdev", dev_no);
/* Set mmcblk env */
sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw",
mmc_map_to_kernel_blk(dev_no));
env_set("mmcroot", mmcblk);
sprintf(cmd, "mmc dev %d", dev_no);
run_command(cmd, 0);
}
#ifndef CONFIG_SPL_BUILD
int factoryset_read_eeprom(int i2c_addr);
static int load_parameters_from_factoryset(void)
{
int ret;
ret = factoryset_read_eeprom(EEPROM_I2C_ADDR);
if (ret)
return ret;
return factoryset_env_set();
}
int board_late_init(void)
{
env_set("sec_boot", "no");
#ifdef CONFIG_AHAB_BOOT
env_set("sec_boot", "yes");
#endif
#ifdef CONFIG_ENV_IS_IN_MMC
board_late_mmc_env_init();
#endif
/* Init LEDs */
if (board_led_init())
printf("I2C LED init failed\n");
/* Set environment from factoryset */
if (load_parameters_from_factoryset())
printf("Loading factoryset parameters failed!\n");
return 0;
}
/* Service button */
#define MAX_PIN_NUMBER 128
#define BOARD_DEFAULT_BUTTON_GPIO IMX_GPIO_NR(1, 31)
unsigned char get_button_state(char * const envname, unsigned char def)
{
int button = 0;
int gpio;
char *ptr_env;
/* If button is not found we take default */
ptr_env = env_get(envname);
if (!ptr_env) {
printf("Using default: %u\n", def);
gpio = def;
} else {
gpio = (unsigned char)simple_strtoul(ptr_env, NULL, 0);
if (gpio > MAX_PIN_NUMBER)
gpio = def;
}
gpio_request(gpio, "");
gpio_direction_input(gpio);
if (gpio_get_value(gpio))
button = 1;
else
button = 0;
gpio_free(gpio);
return button;
}
/*
* This command returns the status of the user button on
* Input - none
* Returns - 1 if button is held down
* 0 if button is not held down
*/
static int
do_userbutton(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
int button = 0;
button = get_button_state("button_usr1", BOARD_DEFAULT_BUTTON_GPIO);
if (argc > 1)
printf("Button state: %u\n", button);
return button;
}
U_BOOT_CMD(
usrbutton, CONFIG_SYS_MAXARGS, 2, do_userbutton,
"Return the status of user button",
"[print]"
);
#define ERST IMX_GPIO_NR(0, 3)
static int
do_eth_reset(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
gpio_request(ERST, "ERST");
gpio_direction_output(ERST, 0);
udelay(200);
gpio_set_value(ERST, 1);
return 0;
}
U_BOOT_CMD(
switch_rst, CONFIG_SYS_MAXARGS, 2, do_eth_reset,
"Reset eth phy",
"[print]"
);
#endif /* ! CONFIG_SPL_BUILD */
|