Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | f91c09a | 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 | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Marek Vasut | 6b98b94 | 2019-05-17 20:32:17 +0200 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | cb3ef68 | 2019-11-14 12:57:50 -0700 | [diff] [blame] | 10 | #include <eeprom.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Marek Vasut | 6b98b94 | 2019-05-17 20:32:17 +0200 | [diff] [blame] | 14 | #include <dm/device-internal.h> |
| 15 | #include <ahci.h> |
Simon Glass | 9fb625c | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 16 | #include <env.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 17 | #include <linux/errno.h> |
Marek Vasut | f91c09a | 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 | 552a848 | 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 | 6b98b94 | 2019-05-17 20:32:17 +0200 | [diff] [blame] | 31 | #include <dwc_ahsata.h> |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 32 | #include <fsl_esdhc_imx.h> |
Marek Vasut | f91c09a | 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 | f91c09a | 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 | 2f1c06c | 2019-05-17 20:32:20 +0200 | [diff] [blame] | 44 | #include <video_console.h> |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 45 | |
Marek Vasut | d59d7b9 | 2014-12-16 14:09:21 +0100 | [diff] [blame] | 46 | #include "novena.h" |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 47 | |
Marek Vasut | d59d7b9 | 2014-12-16 14:09:21 +0100 | [diff] [blame] | 48 | DECLARE_GLOBAL_DATA_PTR; |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 49 | |
| 50 | /* |
| 51 | * GPIO button |
| 52 | */ |
| 53 | #ifdef CONFIG_KEYBOARD |
| 54 | static struct input_config button_input; |
| 55 | |
| 56 | static int novena_gpio_button_read_keys(struct input_config *input) |
| 57 | { |
| 58 | int key = KEY_ENTER; |
| 59 | if (gpio_get_value(NOVENA_BUTTON_GPIO)) |
| 60 | return 0; |
| 61 | input_send_keycodes(&button_input, &key, 1); |
| 62 | return 1; |
| 63 | } |
| 64 | |
| 65 | static int novena_gpio_button_getc(struct stdio_dev *dev) |
| 66 | { |
| 67 | return input_getc(&button_input); |
| 68 | } |
| 69 | |
| 70 | static int novena_gpio_button_tstc(struct stdio_dev *dev) |
| 71 | { |
| 72 | return input_tstc(&button_input); |
| 73 | } |
| 74 | |
| 75 | static int novena_gpio_button_init(struct stdio_dev *dev) |
| 76 | { |
| 77 | gpio_direction_input(NOVENA_BUTTON_GPIO); |
| 78 | input_set_delays(&button_input, 250, 250); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | int drv_keyboard_init(void) |
| 83 | { |
| 84 | int error; |
| 85 | struct stdio_dev dev = { |
| 86 | .name = "button", |
Bin Meng | 1caf934 | 2015-11-03 23:23:37 -0800 | [diff] [blame] | 87 | .flags = DEV_FLAGS_INPUT, |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 88 | .start = novena_gpio_button_init, |
| 89 | .getc = novena_gpio_button_getc, |
| 90 | .tstc = novena_gpio_button_tstc, |
| 91 | }; |
| 92 | |
Marek Vasut | c4e93f6 | 2019-05-17 20:32:16 +0200 | [diff] [blame] | 93 | gpio_request(NOVENA_BUTTON_GPIO, "button"); |
| 94 | |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 95 | error = input_init(&button_input, 0); |
| 96 | if (error) { |
| 97 | debug("%s: Cannot set up input\n", __func__); |
| 98 | return -1; |
| 99 | } |
Simon Glass | b1d7a18 | 2015-11-11 10:05:37 -0700 | [diff] [blame] | 100 | input_add_tables(&button_input, false); |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 101 | button_input.read_keys = novena_gpio_button_read_keys; |
| 102 | |
| 103 | error = input_stdio_register(&dev); |
| 104 | if (error) |
| 105 | return error; |
| 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | #endif |
| 110 | |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 111 | int board_early_init_f(void) |
| 112 | { |
| 113 | #if defined(CONFIG_VIDEO_IPUV3) |
Marek Vasut | f2e4d6a | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 114 | setup_display_clock(); |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 115 | #endif |
| 116 | |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | int board_init(void) |
| 121 | { |
| 122 | /* address of boot parameters */ |
| 123 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 124 | |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Marek Vasut | 331ae84 | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 128 | int board_late_init(void) |
| 129 | { |
| 130 | #if defined(CONFIG_VIDEO_IPUV3) |
Marek Vasut | 2f1c06c | 2019-05-17 20:32:20 +0200 | [diff] [blame] | 131 | struct udevice *con; |
| 132 | char buf[DISPLAY_OPTIONS_BANNER_LENGTH]; |
| 133 | int ret; |
| 134 | |
Marek Vasut | 331ae84 | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 135 | setup_display_lvds(); |
Marek Vasut | 2f1c06c | 2019-05-17 20:32:20 +0200 | [diff] [blame] | 136 | |
| 137 | ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con); |
| 138 | if (ret) |
| 139 | return ret; |
| 140 | |
| 141 | display_options_get_banner(false, buf, sizeof(buf)); |
| 142 | vidconsole_position_cursor(con, 0, 0); |
| 143 | vidconsole_put_string(con, buf); |
Marek Vasut | 331ae84 | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 144 | #endif |
| 145 | return 0; |
| 146 | } |
| 147 | |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 148 | int checkboard(void) |
| 149 | { |
| 150 | puts("Board: Novena 4x\n"); |
| 151 | return 0; |
| 152 | } |
| 153 | |
| 154 | int dram_init(void) |
| 155 | { |
| 156 | gd->ram_size = imx_ddr_size(); |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | /* setup board specific PMIC */ |
| 161 | int power_init_board(void) |
| 162 | { |
| 163 | struct pmic *p; |
| 164 | u32 reg; |
| 165 | int ret; |
| 166 | |
| 167 | power_pfuze100_init(1); |
| 168 | p = pmic_get("PFUZE100"); |
| 169 | if (!p) |
| 170 | return -EINVAL; |
| 171 | |
| 172 | ret = pmic_probe(p); |
| 173 | if (ret) |
| 174 | return ret; |
| 175 | |
| 176 | pmic_reg_read(p, PFUZE100_DEVICEID, ®); |
| 177 | printf("PMIC: PFUZE100 ID=0x%02x\n", reg); |
| 178 | |
| 179 | /* Set SWBST to 5.0V and enable (for USB) */ |
| 180 | pmic_reg_read(p, PFUZE100_SWBSTCON1, ®); |
| 181 | reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK); |
Marek Vasut | 18e02ff | 2015-11-26 14:08:50 +0100 | [diff] [blame] | 182 | reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT)); |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 183 | pmic_reg_write(p, PFUZE100_SWBSTCON1, reg); |
| 184 | |
| 185 | return 0; |
| 186 | } |
| 187 | |
| 188 | /* EEPROM configuration data */ |
| 189 | struct novena_eeprom_data { |
| 190 | uint8_t signature[6]; |
| 191 | uint8_t version; |
| 192 | uint8_t reserved; |
| 193 | uint32_t serial; |
| 194 | uint8_t mac[6]; |
| 195 | uint16_t features; |
| 196 | }; |
| 197 | |
| 198 | int misc_init_r(void) |
| 199 | { |
| 200 | struct novena_eeprom_data data; |
| 201 | uchar *datap = (uchar *)&data; |
| 202 | const char *signature = "Novena"; |
| 203 | int ret; |
| 204 | |
| 205 | /* If 'ethaddr' is already set, do nothing. */ |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 206 | if (env_get("ethaddr")) |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 207 | return 0; |
| 208 | |
| 209 | /* EEPROM is at bus 2. */ |
| 210 | ret = i2c_set_bus_num(2); |
| 211 | if (ret) { |
| 212 | puts("Cannot select EEPROM I2C bus.\n"); |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | /* EEPROM is at address 0x56. */ |
| 217 | ret = eeprom_read(0x56, 0, datap, sizeof(data)); |
| 218 | if (ret) { |
| 219 | puts("Cannot read I2C EEPROM.\n"); |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /* Check EEPROM signature. */ |
| 224 | if (memcmp(data.signature, signature, 6)) { |
| 225 | puts("Invalid I2C EEPROM signature.\n"); |
| 226 | return 0; |
| 227 | } |
| 228 | |
| 229 | /* Set ethernet address from EEPROM. */ |
Simon Glass | fd1e959 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 230 | eth_env_set_enetaddr("ethaddr", data.mac); |
Marek Vasut | f91c09a | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 231 | |
| 232 | return ret; |
| 233 | } |