Tom Rini | af48948 | 2018-05-18 17:54:39 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018 |
| 4 | * Lukasz Majewski, DENX Software Engineering, lukma@denx.de |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <asm/io.h> |
| 9 | #include <asm/arch/imx-regs.h> |
| 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <asm/arch/crm_regs.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/iomux-mx53.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/gpio.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame^] | 16 | #include <env.h> |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 17 | #include <power/pmic.h> |
| 18 | #include <fsl_pmic.h> |
| 19 | #include "kp_id_rev.h" |
| 20 | |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 21 | #define BOOSTER_OFF IMX_GPIO_NR(2, 23) |
Lukasz Majewski | 618d4b6 | 2018-05-20 08:33:14 +0200 | [diff] [blame] | 22 | #define LCD_BACKLIGHT IMX_GPIO_NR(1, 1) |
Lukasz Majewski | 097cfe3 | 2018-05-20 08:33:16 +0200 | [diff] [blame] | 23 | #define KEY1 IMX_GPIO_NR(2, 26) |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | int dram_init(void) |
| 28 | { |
| 29 | u32 size; |
| 30 | |
| 31 | size = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE); |
| 32 | gd->ram_size = size; |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | int dram_init_banksize(void) |
| 38 | { |
| 39 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 40 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 41 | |
| 42 | return 0; |
| 43 | } |
| 44 | |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 45 | static int power_init(void) |
| 46 | { |
| 47 | struct udevice *dev; |
| 48 | int ret; |
| 49 | |
| 50 | ret = pmic_get("mc34708", &dev); |
| 51 | if (ret) { |
| 52 | printf("%s: mc34708 not found !\n", __func__); |
| 53 | return ret; |
| 54 | } |
| 55 | |
| 56 | /* Set VDDGP to 1.110V for 800 MHz on SW1 */ |
| 57 | pmic_clrsetbits(dev, REG_SW_0, SWx_VOLT_MASK_MC34708, |
| 58 | SWx_1_110V_MC34708); |
| 59 | |
| 60 | /* Set VCC as 1.30V on SW2 */ |
| 61 | pmic_clrsetbits(dev, REG_SW_1, SWx_VOLT_MASK_MC34708, |
| 62 | SWx_1_300V_MC34708); |
| 63 | |
| 64 | /* Set global reset timer to 4s */ |
| 65 | pmic_clrsetbits(dev, REG_POWER_CTL2, TIMER_MASK_MC34708, |
| 66 | TIMER_4S_MC34708); |
| 67 | |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | static void setup_clocks(void) |
| 72 | { |
| 73 | int ret; |
| 74 | u32 ref_clk = MXC_HCLK; |
| 75 | /* |
| 76 | * CPU clock set to 800MHz and DDR to 400MHz |
| 77 | */ |
| 78 | ret = mxc_set_clock(ref_clk, 800, MXC_ARM_CLK); |
| 79 | if (ret) |
| 80 | printf("CPU: Switch CPU clock to 800MHZ failed\n"); |
| 81 | |
| 82 | ret = mxc_set_clock(ref_clk, 400, MXC_PERIPH_CLK); |
| 83 | ret |= mxc_set_clock(ref_clk, 400, MXC_DDR_CLK); |
| 84 | if (ret) |
| 85 | printf("CPU: Switch DDR clock to 400MHz failed\n"); |
| 86 | } |
| 87 | |
| 88 | static void setup_ups(void) |
| 89 | { |
| 90 | gpio_request(BOOSTER_OFF, "BOOSTER_OFF"); |
| 91 | gpio_direction_output(BOOSTER_OFF, 0); |
| 92 | } |
| 93 | |
| 94 | int board_early_init_f(void) |
| 95 | { |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Do not overwrite the console |
| 101 | * Use always serial for U-Boot console |
| 102 | */ |
| 103 | int overwrite_console(void) |
| 104 | { |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | int board_init(void) |
| 109 | { |
| 110 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Lukasz Majewski | 618d4b6 | 2018-05-20 08:33:14 +0200 | [diff] [blame] | 115 | void board_disable_display(void) |
| 116 | { |
| 117 | gpio_request(LCD_BACKLIGHT, "LCD_BACKLIGHT"); |
| 118 | gpio_direction_output(LCD_BACKLIGHT, 0); |
| 119 | } |
| 120 | |
Lukasz Majewski | 097cfe3 | 2018-05-20 08:33:16 +0200 | [diff] [blame] | 121 | void board_misc_setup(void) |
| 122 | { |
| 123 | gpio_request(KEY1, "KEY1_GPIO"); |
| 124 | gpio_direction_input(KEY1); |
| 125 | |
| 126 | if (gpio_get_value(KEY1)) |
| 127 | env_set("key1", "off"); |
| 128 | else |
| 129 | env_set("key1", "on"); |
| 130 | } |
| 131 | |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 132 | int board_late_init(void) |
| 133 | { |
| 134 | int ret = 0; |
| 135 | |
Lukasz Majewski | 618d4b6 | 2018-05-20 08:33:14 +0200 | [diff] [blame] | 136 | board_disable_display(); |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 137 | setup_ups(); |
| 138 | |
| 139 | if (!power_init()) |
| 140 | setup_clocks(); |
| 141 | |
| 142 | ret = read_eeprom(); |
| 143 | if (ret) |
| 144 | printf("Error %d reading EEPROM content!\n", ret); |
| 145 | |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 146 | show_eeprom(); |
| 147 | read_board_id(); |
| 148 | |
Lukasz Majewski | 097cfe3 | 2018-05-20 08:33:16 +0200 | [diff] [blame] | 149 | board_misc_setup(); |
| 150 | |
Lukasz Majewski | 7515a6f | 2018-04-26 15:07:18 +0200 | [diff] [blame] | 151 | return ret; |
| 152 | } |