rockchip: check download key before bootup
Enter download mode if the download key pressed. Signed-off-by: Andy Yan <andy.yan@rock-chips.com> Acked-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> Reviewed-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com> [Converted printfs in boot_mode.c to debug/pr_err:] Signed-off-by: Philipp Tomsich <philipp.tomsich@theobroma-systems.com>
This commit is contained in:
		
							parent
							
								
									b4d23f7643
								
							
						
					
					
						commit
						ecb103bf68
					
				| 
						 | 
					@ -5,26 +5,69 @@
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <common.h>
 | 
					#include <common.h>
 | 
				
			||||||
 | 
					#include <adc.h>
 | 
				
			||||||
#include <asm/io.h>
 | 
					#include <asm/io.h>
 | 
				
			||||||
#include <asm/arch/boot_mode.h>
 | 
					#include <asm/arch/boot_mode.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void set_back_to_bootrom_dnl_flag(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						writel(BOOT_BROM_DOWNLOAD, CONFIG_ROCKCHIP_BOOT_MODE_REG);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * detect download key status by adc, most rockchip
 | 
				
			||||||
 | 
					 * based boards use adc sample the download key status,
 | 
				
			||||||
 | 
					 * but there are also some use gpio. So it's better to
 | 
				
			||||||
 | 
					 * make this a weak function that can be override by
 | 
				
			||||||
 | 
					 * some special boards.
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					#define KEY_DOWN_MIN_VAL	0
 | 
				
			||||||
 | 
					#define KEY_DOWN_MAX_VAL	30
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					__weak int rockchip_dnl_key_pressed(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						unsigned int val;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (adc_channel_single_shot("saradc", 1, &val)) {
 | 
				
			||||||
 | 
							pr_err("%s: adc_channel_single_shot fail!\n", __func__);
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if ((val >= KEY_DOWN_MIN_VAL) && (val <= KEY_DOWN_MAX_VAL))
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void rockchip_dnl_mode_check(void)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						if (rockchip_dnl_key_pressed()) {
 | 
				
			||||||
 | 
							printf("download key pressed, entering download mode...");
 | 
				
			||||||
 | 
							set_back_to_bootrom_dnl_flag();
 | 
				
			||||||
 | 
							do_reset(NULL, 0, 0, NULL);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int setup_boot_mode(void)
 | 
					int setup_boot_mode(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
 | 
						void *reg = (void *)CONFIG_ROCKCHIP_BOOT_MODE_REG;
 | 
				
			||||||
	int boot_mode = readl(reg);
 | 
						int boot_mode = readl(reg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	debug("boot mode %x.\n", boot_mode);
 | 
						rockchip_dnl_mode_check();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						boot_mode = readl(reg);
 | 
				
			||||||
 | 
						debug("%s: boot mode 0x%08x\n", __func__, boot_mode);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/* Clear boot mode */
 | 
						/* Clear boot mode */
 | 
				
			||||||
	writel(BOOT_NORMAL, reg);
 | 
						writel(BOOT_NORMAL, reg);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch (boot_mode) {
 | 
						switch (boot_mode) {
 | 
				
			||||||
	case BOOT_FASTBOOT:
 | 
						case BOOT_FASTBOOT:
 | 
				
			||||||
		printf("enter fastboot!\n");
 | 
							debug("%s: enter fastboot!\n", __func__);
 | 
				
			||||||
		env_set("preboot", "setenv preboot; fastboot usb0");
 | 
							env_set("preboot", "setenv preboot; fastboot usb0");
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	case BOOT_UMS:
 | 
						case BOOT_UMS:
 | 
				
			||||||
		printf("enter UMS!\n");
 | 
							debug("%s: enter UMS!\n", __func__);
 | 
				
			||||||
		env_set("preboot", "setenv preboot; ums mmc 0");
 | 
							env_set("preboot", "setenv preboot; ums mmc 0");
 | 
				
			||||||
		break;
 | 
							break;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue