Blame view

board/freescale/mx7ulp_evk/mx7ulp_evk.c 6.04 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  // SPDX-License-Identifier: GPL-2.0+
77fa04577   Peng Fan   imx: imx7ulp: add...
2
3
  /*
   * Copyright (C) 2016 Freescale Semiconductor, Inc.
77fa04577   Peng Fan   imx: imx7ulp: add...
4
5
6
   */
  
  #include <common.h>
bd1cc6ae6   Peng Fan   i.MX7ULP: evk: Mo...
7
  #include <fdt_support.h>
77fa04577   Peng Fan   imx: imx7ulp: add...
8
9
10
11
  #include <asm/io.h>
  #include <asm/arch/sys_proto.h>
  #include <asm/arch/mx7ulp-pins.h>
  #include <asm/arch/iomux.h>
bd1cc6ae6   Peng Fan   i.MX7ULP: evk: Mo...
12
  #include <asm/mach-imx/boot_mode.h>
5018d79e2   Ye Li   MLK-14445-6 mx7ul...
13
14
15
  #include <asm/gpio.h>
  #include <usb.h>
  #include <dm.h>
77fa04577   Peng Fan   imx: imx7ulp: add...
16

d0f64bb82   Ji Luo   MA-17159 Implemen...
17
18
19
20
21
22
23
  #ifdef CONFIG_BOOTLOADER_MENU
  #include "video.h"
  #include "dm/uclass.h"
  #include "video_font_data.h"
  #include "video_console.h"
  #include "recovery.h"
  #endif
77fa04577   Peng Fan   imx: imx7ulp: add...
24
25
26
  DECLARE_GLOBAL_DATA_PTR;
  
  #define UART_PAD_CTRL	(PAD_CTL_PUS_UP)
94111fa65   Ye Li   MLK-14445-2 mx7ul...
27
  #define QSPI_PAD_CTRL1	(PAD_CTL_PUS_UP | PAD_CTL_DSE)
5018d79e2   Ye Li   MLK-14445-6 mx7ul...
28
  #define OTG_ID_GPIO_PAD_CTRL	(PAD_CTL_IBE_ENABLE)
77fa04577   Peng Fan   imx: imx7ulp: add...
29
30
31
  
  int dram_init(void)
  {
49cf320f7   Fabio Estevam   mx7ulp_evk: Use i...
32
  	gd->ram_size = imx_ddr_size();
77fa04577   Peng Fan   imx: imx7ulp: add...
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  
  	return 0;
  }
  
  static iomux_cfg_t const lpuart4_pads[] = {
  	MX7ULP_PAD_PTC3__LPUART4_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
  	MX7ULP_PAD_PTC2__LPUART4_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
  };
  
  static void setup_iomux_uart(void)
  {
  	mx7ulp_iomux_setup_multiple_pads(lpuart4_pads,
  					 ARRAY_SIZE(lpuart4_pads));
  }
94111fa65   Ye Li   MLK-14445-2 mx7ul...
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
  #ifdef CONFIG_FSL_QSPI
  #ifndef CONFIG_DM_SPI
  static iomux_cfg_t const quadspi_pads[] = {
  	MX7ULP_PAD_PTB8__QSPIA_SS0_B | MUX_PAD_CTRL(QSPI_PAD_CTRL1),
  	MX7ULP_PAD_PTB15__QSPIA_SCLK  | MUX_PAD_CTRL(QSPI_PAD_CTRL1),
  	MX7ULP_PAD_PTB16__QSPIA_DATA3 | MUX_PAD_CTRL(QSPI_PAD_CTRL1),
  	MX7ULP_PAD_PTB17__QSPIA_DATA2 | MUX_PAD_CTRL(QSPI_PAD_CTRL1),
  	MX7ULP_PAD_PTB18__QSPIA_DATA1 | MUX_PAD_CTRL(QSPI_PAD_CTRL1),
  	MX7ULP_PAD_PTB19__QSPIA_DATA0 | MUX_PAD_CTRL(QSPI_PAD_CTRL1),
  };
  #endif
  
  int board_qspi_init(void)
  {
  	u32 val;
  #ifndef CONFIG_DM_SPI
  	mx7ulp_iomux_setup_multiple_pads(quadspi_pads, ARRAY_SIZE(quadspi_pads));
  #endif
  
  	/* enable clock */
  	val = readl(PCC1_RBASE + 0x94);
  
  	if (!(val & 0x20000000)) {
  		writel(0x03000003, (PCC1_RBASE + 0x94));
  		writel(0x43000003, (PCC1_RBASE + 0x94));
  	}
a6300a4e9   Fabio Estevam   MLK-18318: mx7ulp...
73
74
75
76
  
  	/* Enable QSPI as a wakeup source on B0 */
  	if (soc_rev() >= CHIP_REV_2_0)
  		setbits_le32(SIM0_RBASE + WKPU_WAKEUP_EN, WKPU_QSPI_CHANNEL);
94111fa65   Ye Li   MLK-14445-2 mx7ul...
77
78
79
  	return 0;
  }
  #endif
77fa04577   Peng Fan   imx: imx7ulp: add...
80
81
82
83
84
85
86
87
88
89
90
  int board_early_init_f(void)
  {
  	setup_iomux_uart();
  
  	return 0;
  }
  
  int board_init(void)
  {
  	/* address of boot parameters */
  	gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
94111fa65   Ye Li   MLK-14445-2 mx7ul...
91
92
93
  #ifdef CONFIG_FSL_QSPI
  	board_qspi_init();
  #endif
77fa04577   Peng Fan   imx: imx7ulp: add...
94
95
  	return 0;
  }
bd1cc6ae6   Peng Fan   i.MX7ULP: evk: Mo...
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
  
  #if IS_ENABLED(CONFIG_OF_BOARD_SETUP)
  int ft_board_setup(void *blob, bd_t *bd)
  {
  	const char *path;
  	int rc, nodeoff;
  
  	if (get_boot_device() == USB_BOOT) {
  		path = fdt_get_alias(blob, "mmc0");
  		if (!path) {
  			puts("Not found mmc0
  ");
  			return 0;
  		}
  
  		nodeoff = fdt_path_offset(blob, path);
  		if (nodeoff < 0)
  			return 0;
  
  		printf("Found usdhc0 node
  ");
  		if (fdt_get_property(blob, nodeoff, "vqmmc-supply",
  		    NULL) != NULL) {
  			rc = fdt_delprop(blob, nodeoff, "vqmmc-supply");
  			if (!rc) {
  				puts("Removed vqmmc-supply property
  ");
  add:
  				rc = fdt_setprop(blob, nodeoff,
  						 "no-1-8-v", NULL, 0);
  				if (rc == -FDT_ERR_NOSPACE) {
  					rc = fdt_increase_size(blob, 32);
  					if (!rc)
  						goto add;
  				} else if (rc) {
  					printf("Failed to add no-1-8-v property, %d
  ", rc);
  				} else {
  					puts("Added no-1-8-v property
  ");
  				}
  			} else {
  				printf("Failed to remove vqmmc-supply property, %d
  ", rc);
  			}
  		}
  	}
  
  	return 0;
  }
  #endif
c7776df15   Ye Li   MLK-14445-8 mx7ul...
147

d0f64bb82   Ji Luo   MA-17159 Implemen...
148
149
150
151
152
153
154
155
  #ifdef CONFIG_BOOTLOADER_MENU
  static iomux_cfg_t const vol_pad[] = {
  	MX7ULP_PAD_PTA3__PTA3 | MUX_PAD_CTRL(PAD_CTL_IBE_ENABLE),
  };
  #define VOLP_GPIO	IMX_GPIO_NR(1, 3)
  bool is_vol_key_pressed(void);
  int show_bootloader_menu(void);
  #endif
c7776df15   Ye Li   MLK-14445-8 mx7ul...
156
157
  int board_late_init(void)
  {
9b9722822   Peng Fan   MLK-16753-9 imx: ...
158
159
160
161
  	env_set("tee", "no");
  #ifdef CONFIG_IMX_OPTEE
  	env_set("tee", "yes");
  #endif
c7776df15   Ye Li   MLK-14445-8 mx7ul...
162
163
164
  #ifdef CONFIG_ENV_IS_IN_MMC
  	board_late_mmc_env_init();
  #endif
d0f64bb82   Ji Luo   MA-17159 Implemen...
165
166
167
168
169
170
171
172
173
174
  #ifdef CONFIG_BOOTLOADER_MENU
  	mx7ulp_iomux_setup_multiple_pads(vol_pad, ARRAY_SIZE(vol_pad));
  	if (gpio_request(VOLP_GPIO, "volp"))
  		printf("request error
  ");
  	gpio_direction_input(VOLP_GPIO);
  
  	if (is_vol_key_pressed())
  		show_bootloader_menu();
  #endif
c7776df15   Ye Li   MLK-14445-8 mx7ul...
175
176
  	return 0;
  }
e0f8c7f6f   Ji Luo   MA-17129 Android:...
177
178
179
180
181
182
183
184
185
  
  #ifdef CONFIG_FSL_FASTBOOT
  #ifdef CONFIG_ANDROID_RECOVERY
  int is_recovery_key_pressing(void)
  {
  	return 0; /*TODO*/
  }
  #endif /*CONFIG_ANDROID_RECOVERY*/
  #endif /*CONFIG_FSL_FASTBOOT*/
89e3d51b4   Ji Luo   MA-17046-3 Add im...
186
187
188
189
190
191
  
  #ifdef CONFIG_ANDROID_SUPPORT
  bool is_power_key_pressed(void) {
  	/* the onoff button is 'pressed' by default on evk board */
  	return (bool)(!(readl(SNVS_HPSR_REVB) & (0x1 << 6)));
  }
d0f64bb82   Ji Luo   MA-17159 Implemen...
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
  
  #ifdef CONFIG_BOOTLOADER_MENU
  char bootloader_menu[4][40] = {
  	"   * Power off the device
  ",
  	"   * Start the device normally
  ",
  	"   * Restart the bootloader
  ",
  	"   * Boot into recovery mode
  "
  };
  
  bool is_vol_key_pressed(void) {
  	int ret = 0;
  	ret = gpio_get_value(VOLP_GPIO);
  	return (bool)(!!ret);
  }
  
  int show_bootloader_menu(void) {
  	struct udevice *dev, *dev_console;
  	uint32_t focus = 0, i;
  	bool stop_menu = false;
  
  	/* clear screen first */
  	if (uclass_first_device_err(UCLASS_VIDEO, &dev)) {
  		printf("no video device found!
  ");
  		return -1;
  	}
  	video_clear(dev);
  
  	if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev_console)) {
  		printf("no text console device found!
  ");
  		return -1;
  	}
  
  	vidconsole_position_cursor(dev_console, 0, 1);
  	vidconsole_put_string(dev_console, "Press 'vol+' to choose an item, press
  ");
  	vidconsole_put_string(dev_console, "power key to confirm:
  ");
  	while (!stop_menu) {
  		/* reset the cursor position. */
  		vidconsole_position_cursor(dev_console, 0, 4);
  		/* show menu */
  		for (i = 0; i < 4; i++) {
  			/* reverse color for the 'focus' line. */
  			if (i == focus)
  				vidconsole_put_string(dev_console, "\x1b[7m");
  			/* show text */
  			vidconsole_put_string(dev_console, bootloader_menu[i]);
  			/* reset color back for the 'next' line. */
  			if (i == focus)
  				vidconsole_put_string(dev_console, "\x1b[0m");
  		}
  		/* check button status */
  		while (1) {
  			if (is_power_key_pressed()) {
  				switch (focus) {
  					case 0: /*TODO*/
  					case 1:
  						break;
  					case 2:
  						do_reset(NULL, 0, 0, NULL);
  					case 3:
  						board_recovery_setup();
  						break;
  					default:
  						break;
  				}
  				stop_menu = true;
  				break;
  			} else if (is_vol_key_pressed()) {
  				focus++;
d0f64bb82   Ji Luo   MA-17159 Implemen...
268
269
270
271
272
273
274
275
276
277
278
279
280
281
  				if (focus > 3)
  					focus = 0;
  				mdelay(400);
  				break;
  			}
  		}
  	}
  
  	/* clear screen before exit */
  	video_clear(dev);
  	return 0;
  }
  #endif /* CONFIG_BOOTLOADER_MENU */
  #endif /* CONFIG_ANDROID_SUPPORT*/