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