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> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 9 | #include <linux/errno.h> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 10 | #include <asm/gpio.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <asm/arch/clock.h> |
| 13 | #include <asm/arch/crm_regs.h> |
| 14 | #include <asm/arch/imx-regs.h> |
| 15 | #include <asm/arch/iomux.h> |
| 16 | #include <asm/arch/mxc_hdmi.h> |
| 17 | #include <asm/arch/sys_proto.h> |
Stefano Babic | 33731bc | 2017-06-29 10:16:06 +0200 | [diff] [blame] | 18 | #include <asm/mach-imx/boot_mode.h> |
| 19 | #include <asm/mach-imx/iomux-v3.h> |
| 20 | #include <asm/mach-imx/mxc_i2c.h> |
| 21 | #include <asm/mach-imx/sata.h> |
| 22 | #include <asm/mach-imx/video.h> |
Alex Kiernan | 9c21549 | 2018-04-01 09:22:38 +0000 | [diff] [blame] | 23 | #include <environment.h> |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 24 | #include <fsl_esdhc.h> |
| 25 | #include <i2c.h> |
| 26 | #include <input.h> |
| 27 | #include <ipu_pixfmt.h> |
| 28 | #include <linux/fb.h> |
| 29 | #include <linux/input.h> |
| 30 | #include <malloc.h> |
| 31 | #include <micrel.h> |
| 32 | #include <miiphy.h> |
| 33 | #include <mmc.h> |
| 34 | #include <netdev.h> |
| 35 | #include <power/pmic.h> |
| 36 | #include <power/pfuze100_pmic.h> |
| 37 | #include <stdio_dev.h> |
| 38 | |
Marek Vasut | 3653e97 | 2014-12-16 14:09:21 +0100 | [diff] [blame] | 39 | #include "novena.h" |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 40 | |
Marek Vasut | 3653e97 | 2014-12-16 14:09:21 +0100 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * GPIO button |
| 45 | */ |
| 46 | #ifdef CONFIG_KEYBOARD |
| 47 | static struct input_config button_input; |
| 48 | |
| 49 | static int novena_gpio_button_read_keys(struct input_config *input) |
| 50 | { |
| 51 | int key = KEY_ENTER; |
| 52 | if (gpio_get_value(NOVENA_BUTTON_GPIO)) |
| 53 | return 0; |
| 54 | input_send_keycodes(&button_input, &key, 1); |
| 55 | return 1; |
| 56 | } |
| 57 | |
| 58 | static int novena_gpio_button_getc(struct stdio_dev *dev) |
| 59 | { |
| 60 | return input_getc(&button_input); |
| 61 | } |
| 62 | |
| 63 | static int novena_gpio_button_tstc(struct stdio_dev *dev) |
| 64 | { |
| 65 | return input_tstc(&button_input); |
| 66 | } |
| 67 | |
| 68 | static int novena_gpio_button_init(struct stdio_dev *dev) |
| 69 | { |
| 70 | gpio_direction_input(NOVENA_BUTTON_GPIO); |
| 71 | input_set_delays(&button_input, 250, 250); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | int drv_keyboard_init(void) |
| 76 | { |
| 77 | int error; |
| 78 | struct stdio_dev dev = { |
| 79 | .name = "button", |
Bin Meng | 6abe4b6 | 2015-11-03 23:23:37 -0800 | [diff] [blame] | 80 | .flags = DEV_FLAGS_INPUT, |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 81 | .start = novena_gpio_button_init, |
| 82 | .getc = novena_gpio_button_getc, |
| 83 | .tstc = novena_gpio_button_tstc, |
| 84 | }; |
| 85 | |
Marek Vasut | 7149cc8 | 2019-05-17 20:32:16 +0200 | [diff] [blame^] | 86 | gpio_request(NOVENA_BUTTON_GPIO, "button"); |
| 87 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 88 | error = input_init(&button_input, 0); |
| 89 | if (error) { |
| 90 | debug("%s: Cannot set up input\n", __func__); |
| 91 | return -1; |
| 92 | } |
Simon Glass | e6fa485 | 2015-11-11 10:05:37 -0700 | [diff] [blame] | 93 | input_add_tables(&button_input, false); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 94 | button_input.read_keys = novena_gpio_button_read_keys; |
| 95 | |
| 96 | error = input_stdio_register(&dev); |
| 97 | if (error) |
| 98 | return error; |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | #endif |
| 103 | |
| 104 | /* |
| 105 | * SDHC |
| 106 | */ |
| 107 | #ifdef CONFIG_FSL_ESDHC |
| 108 | static struct fsl_esdhc_cfg usdhc_cfg[] = { |
| 109 | { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */ |
| 110 | { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */ |
| 111 | }; |
| 112 | |
| 113 | int board_mmc_getcd(struct mmc *mmc) |
| 114 | { |
| 115 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 116 | |
| 117 | /* There is no CD for a microSD card, assume always present. */ |
| 118 | if (cfg->esdhc_base == USDHC3_BASE_ADDR) |
| 119 | return 1; |
| 120 | else |
| 121 | return !gpio_get_value(NOVENA_SD_CD); |
| 122 | } |
| 123 | |
| 124 | int board_mmc_getwp(struct mmc *mmc) |
| 125 | { |
| 126 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 127 | |
| 128 | /* There is no WP for a microSD card, assume always read-write. */ |
| 129 | if (cfg->esdhc_base == USDHC3_BASE_ADDR) |
| 130 | return 0; |
| 131 | else |
| 132 | return gpio_get_value(NOVENA_SD_WP); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | int board_mmc_init(bd_t *bis) |
| 137 | { |
| 138 | s32 status = 0; |
| 139 | int index; |
| 140 | |
| 141 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); |
| 142 | usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); |
| 143 | |
| 144 | /* Big SD write-protect and card-detect */ |
| 145 | gpio_direction_input(NOVENA_SD_WP); |
| 146 | gpio_direction_input(NOVENA_SD_CD); |
| 147 | |
| 148 | for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) { |
| 149 | status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]); |
| 150 | if (status) |
| 151 | return status; |
| 152 | } |
| 153 | |
| 154 | return status; |
| 155 | } |
| 156 | #endif |
| 157 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 158 | int board_early_init_f(void) |
| 159 | { |
| 160 | #if defined(CONFIG_VIDEO_IPUV3) |
Marek Vasut | 5da39bf | 2014-12-16 14:09:22 +0100 | [diff] [blame] | 161 | setup_display_clock(); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 162 | #endif |
| 163 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | int board_init(void) |
| 168 | { |
| 169 | /* address of boot parameters */ |
| 170 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 171 | |
Simon Glass | ab3055a | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 172 | #ifdef CONFIG_SATA |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 173 | setup_sata(); |
| 174 | #endif |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
Marek Vasut | 7d4dcba | 2014-12-16 14:09:23 +0100 | [diff] [blame] | 179 | int board_late_init(void) |
| 180 | { |
| 181 | #if defined(CONFIG_VIDEO_IPUV3) |
| 182 | setup_display_lvds(); |
| 183 | #endif |
| 184 | return 0; |
| 185 | } |
| 186 | |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 187 | int checkboard(void) |
| 188 | { |
| 189 | puts("Board: Novena 4x\n"); |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | int dram_init(void) |
| 194 | { |
| 195 | gd->ram_size = imx_ddr_size(); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | /* setup board specific PMIC */ |
| 200 | int power_init_board(void) |
| 201 | { |
| 202 | struct pmic *p; |
| 203 | u32 reg; |
| 204 | int ret; |
| 205 | |
| 206 | power_pfuze100_init(1); |
| 207 | p = pmic_get("PFUZE100"); |
| 208 | if (!p) |
| 209 | return -EINVAL; |
| 210 | |
| 211 | ret = pmic_probe(p); |
| 212 | if (ret) |
| 213 | return ret; |
| 214 | |
| 215 | pmic_reg_read(p, PFUZE100_DEVICEID, ®); |
| 216 | printf("PMIC: PFUZE100 ID=0x%02x\n", reg); |
| 217 | |
| 218 | /* Set SWBST to 5.0V and enable (for USB) */ |
| 219 | pmic_reg_read(p, PFUZE100_SWBSTCON1, ®); |
| 220 | reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK); |
Marek Vasut | 2aaeb91 | 2015-11-26 14:08:50 +0100 | [diff] [blame] | 221 | reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT)); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 222 | pmic_reg_write(p, PFUZE100_SWBSTCON1, reg); |
| 223 | |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | /* EEPROM configuration data */ |
| 228 | struct novena_eeprom_data { |
| 229 | uint8_t signature[6]; |
| 230 | uint8_t version; |
| 231 | uint8_t reserved; |
| 232 | uint32_t serial; |
| 233 | uint8_t mac[6]; |
| 234 | uint16_t features; |
| 235 | }; |
| 236 | |
| 237 | int misc_init_r(void) |
| 238 | { |
| 239 | struct novena_eeprom_data data; |
| 240 | uchar *datap = (uchar *)&data; |
| 241 | const char *signature = "Novena"; |
| 242 | int ret; |
| 243 | |
| 244 | /* If 'ethaddr' is already set, do nothing. */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 245 | if (env_get("ethaddr")) |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 246 | return 0; |
| 247 | |
| 248 | /* EEPROM is at bus 2. */ |
| 249 | ret = i2c_set_bus_num(2); |
| 250 | if (ret) { |
| 251 | puts("Cannot select EEPROM I2C bus.\n"); |
| 252 | return 0; |
| 253 | } |
| 254 | |
| 255 | /* EEPROM is at address 0x56. */ |
| 256 | ret = eeprom_read(0x56, 0, datap, sizeof(data)); |
| 257 | if (ret) { |
| 258 | puts("Cannot read I2C EEPROM.\n"); |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | /* Check EEPROM signature. */ |
| 263 | if (memcmp(data.signature, signature, 6)) { |
| 264 | puts("Invalid I2C EEPROM signature.\n"); |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | /* Set ethernet address from EEPROM. */ |
Simon Glass | 8551d55 | 2017-08-03 12:22:11 -0600 | [diff] [blame] | 269 | eth_env_set_enetaddr("ethaddr", data.mac); |
Marek Vasut | 408368f | 2014-10-24 23:39:07 +0200 | [diff] [blame] | 270 | |
| 271 | return ret; |
| 272 | } |