Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Novena board support |
| 4 | * |
| 5 | * Copyright (C) 2014 Marek Vasut <marex@denx.de> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | 1ab1692 | 2022-07-31 12:28:48 -0600 | [diff] [blame] | 8 | #include <display_options.h> |
Marek Vasut | 91cb3b0 | 2019-05-17 20:32:17 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | eba6b8d | 2019-11-14 12:57:50 -0700 | [diff] [blame] | 10 | #include <eeprom.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Marek Vasut | 91cb3b0 | 2019-05-17 20:32:17 +0200 | [diff] [blame] | 14 | #include <dm/device-internal.h> |
| 15 | #include <ahci.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 16 | #include <env.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 17 | #include <linux/errno.h> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 18 | #include <asm/gpio.h> |
| 19 | #include <asm/io.h> |
| 20 | #include <asm/arch/clock.h> |
| 21 | #include <asm/arch/crm_regs.h> |
| 22 | #include <asm/arch/imx-regs.h> |
| 23 | #include <asm/arch/iomux.h> |
| 24 | #include <asm/arch/mxc_hdmi.h> |
| 25 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 26 | #include <asm/mach-imx/boot_mode.h> |
| 27 | #include <asm/mach-imx/iomux-v3.h> |
| 28 | #include <asm/mach-imx/mxc_i2c.h> |
| 29 | #include <asm/mach-imx/sata.h> |
| 30 | #include <asm/mach-imx/video.h> |
Marek Vasut | 91cb3b0 | 2019-05-17 20:32:17 +0200 | [diff] [blame] | 31 | #include <dwc_ahsata.h> |
Yangbo Lu | 7334038 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 32 | #include <fsl_esdhc_imx.h> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 33 | #include <i2c.h> |
| 34 | #include <input.h> |
| 35 | #include <ipu_pixfmt.h> |
| 36 | #include <linux/fb.h> |
| 37 | #include <linux/input.h> |
| 38 | #include <malloc.h> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 39 | #include <mmc.h> |
| 40 | #include <netdev.h> |
| 41 | #include <power/pmic.h> |
| 42 | #include <power/pfuze100_pmic.h> |
| 43 | #include <stdio_dev.h> |
Marek Vasut | 6e30320 | 2019-05-17 20:32:20 +0200 | [diff] [blame] | 44 | #include <video_console.h> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 45 | |
Marek Vasut | 3653e97 | 2014-12-16 14:09:21 +0100 | [diff] [blame] | 46 | #include "novena.h" |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 47 | |
Marek Vasut | 3653e97 | 2014-12-16 14:09:21 +0100 | [diff] [blame] | 48 | DECLARE_GLOBAL_DATA_PTR; |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 49 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 50 | int board_early_init_f(void) |
| 51 | { |
| 52 | #if defined(CONFIG_VIDEO_IPUV3) |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 53 | setup_display_clock(); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 54 | #endif |
| 55 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | int board_init(void) |
| 60 | { |
| 61 | /* address of boot parameters */ |
| 62 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 63 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 67 | int board_late_init(void) |
| 68 | { |
| 69 | #if defined(CONFIG_VIDEO_IPUV3) |
Marek Vasut | 6e30320 | 2019-05-17 20:32:20 +0200 | [diff] [blame] | 70 | struct udevice *con; |
| 71 | char buf[DISPLAY_OPTIONS_BANNER_LENGTH]; |
| 72 | int ret; |
| 73 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 74 | setup_display_lvds(); |
Marek Vasut | 6e30320 | 2019-05-17 20:32:20 +0200 | [diff] [blame] | 75 | |
| 76 | ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con); |
| 77 | if (ret) |
| 78 | return ret; |
| 79 | |
| 80 | display_options_get_banner(false, buf, sizeof(buf)); |
| 81 | vidconsole_position_cursor(con, 0, 0); |
| 82 | vidconsole_put_string(con, buf); |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 83 | #endif |
| 84 | return 0; |
| 85 | } |
| 86 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 87 | int checkboard(void) |
| 88 | { |
| 89 | puts("Board: Novena 4x\n"); |
| 90 | return 0; |
| 91 | } |
| 92 | |
| 93 | int dram_init(void) |
| 94 | { |
| 95 | gd->ram_size = imx_ddr_size(); |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /* setup board specific PMIC */ |
| 100 | int power_init_board(void) |
| 101 | { |
| 102 | struct pmic *p; |
| 103 | u32 reg; |
| 104 | int ret; |
| 105 | |
| 106 | power_pfuze100_init(1); |
| 107 | p = pmic_get("PFUZE100"); |
| 108 | if (!p) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | ret = pmic_probe(p); |
| 112 | if (ret) |
| 113 | return ret; |
| 114 | |
| 115 | pmic_reg_read(p, PFUZE100_DEVICEID, ®); |
| 116 | printf("PMIC: PFUZE100 ID=0x%02x\n", reg); |
| 117 | |
| 118 | /* Set SWBST to 5.0V and enable (for USB) */ |
| 119 | pmic_reg_read(p, PFUZE100_SWBSTCON1, ®); |
| 120 | reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK); |
Marek Vasut | 2aaeb91 | 2015-11-26 14:08:50 +0100 | [diff] [blame] | 121 | reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT)); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 122 | pmic_reg_write(p, PFUZE100_SWBSTCON1, reg); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
| 127 | /* EEPROM configuration data */ |
| 128 | struct novena_eeprom_data { |
| 129 | uint8_t signature[6]; |
| 130 | uint8_t version; |
| 131 | uint8_t reserved; |
| 132 | uint32_t serial; |
| 133 | uint8_t mac[6]; |
| 134 | uint16_t features; |
| 135 | }; |
| 136 | |
| 137 | int misc_init_r(void) |
| 138 | { |
| 139 | struct novena_eeprom_data data; |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 140 | uint8_t *datap = (uint8_t *)&data; |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 141 | const char *signature = "Novena"; |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 142 | struct udevice *eeprom; |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 143 | int ret; |
| 144 | |
| 145 | /* If 'ethaddr' is already set, do nothing. */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 146 | if (env_get("ethaddr")) |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 147 | return 0; |
| 148 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 149 | /* EEPROM is at bus 2, address 0x56 */ |
| 150 | ret = i2c_get_chip_for_busnum(2, 0x56, 1, &eeprom); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 151 | if (ret) { |
| 152 | puts("Cannot select EEPROM I2C bus.\n"); |
| 153 | return 0; |
| 154 | } |
| 155 | |
Anatolij Gustschin | 1b6a7ca | 2024-08-03 18:15:09 +0200 | [diff] [blame] | 156 | ret = dm_i2c_read(eeprom, 0, datap, sizeof(data)); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 157 | if (ret) { |
| 158 | puts("Cannot read I2C EEPROM.\n"); |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | /* Check EEPROM signature. */ |
| 163 | if (memcmp(data.signature, signature, 6)) { |
| 164 | puts("Invalid I2C EEPROM signature.\n"); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | /* Set ethernet address from EEPROM. */ |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 169 | eth_env_set_enetaddr("ethaddr", data.mac); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 170 | |
| 171 | return ret; |
| 172 | } |