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