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