4 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <asm/errno.h>
13 #include <asm/arch/clock.h>
14 #include <asm/arch/crm_regs.h>
15 #include <asm/arch/imx-regs.h>
16 #include <asm/arch/iomux.h>
17 #include <asm/arch/mxc_hdmi.h>
18 #include <asm/arch/sys_proto.h>
19 #include <asm/imx-common/boot_mode.h>
20 #include <asm/imx-common/iomux-v3.h>
21 #include <asm/imx-common/mxc_i2c.h>
22 #include <asm/imx-common/sata.h>
23 #include <asm/imx-common/video.h>
24 #include <fsl_esdhc.h>
27 #include <ipu_pixfmt.h>
29 #include <linux/input.h>
35 #include <power/pmic.h>
36 #include <power/pfuze100_pmic.h>
37 #include <stdio_dev.h>
41 DECLARE_GLOBAL_DATA_PTR;
46 #ifdef CONFIG_KEYBOARD
47 static struct input_config button_input;
49 static int novena_gpio_button_read_keys(struct input_config *input)
52 if (gpio_get_value(NOVENA_BUTTON_GPIO))
54 input_send_keycodes(&button_input, &key, 1);
58 static int novena_gpio_button_getc(struct stdio_dev *dev)
60 return input_getc(&button_input);
63 static int novena_gpio_button_tstc(struct stdio_dev *dev)
65 return input_tstc(&button_input);
68 static int novena_gpio_button_init(struct stdio_dev *dev)
70 gpio_direction_input(NOVENA_BUTTON_GPIO);
71 input_set_delays(&button_input, 250, 250);
75 int drv_keyboard_init(void)
78 struct stdio_dev dev = {
80 .flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM,
81 .start = novena_gpio_button_init,
82 .getc = novena_gpio_button_getc,
83 .tstc = novena_gpio_button_tstc,
86 error = input_init(&button_input, 0);
88 debug("%s: Cannot set up input\n", __func__);
91 button_input.read_keys = novena_gpio_button_read_keys;
93 error = input_stdio_register(&dev);
104 #ifdef CONFIG_FSL_ESDHC
105 static struct fsl_esdhc_cfg usdhc_cfg[] = {
106 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */
107 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */
110 int board_mmc_getcd(struct mmc *mmc)
112 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
114 /* There is no CD for a microSD card, assume always present. */
115 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
118 return !gpio_get_value(NOVENA_SD_CD);
121 int board_mmc_getwp(struct mmc *mmc)
123 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
125 /* There is no WP for a microSD card, assume always read-write. */
126 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
129 return gpio_get_value(NOVENA_SD_WP);
133 int board_mmc_init(bd_t *bis)
138 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
139 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
141 /* Big SD write-protect and card-detect */
142 gpio_direction_input(NOVENA_SD_WP);
143 gpio_direction_input(NOVENA_SD_CD);
145 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
146 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
155 int board_early_init_f(void)
157 #if defined(CONFIG_VIDEO_IPUV3)
158 setup_display_clock();
166 /* address of boot parameters */
167 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
169 #ifdef CONFIG_CMD_SATA
176 int board_late_init(void)
178 #if defined(CONFIG_VIDEO_IPUV3)
179 setup_display_lvds();
186 puts("Board: Novena 4x\n");
192 gd->ram_size = imx_ddr_size();
196 /* setup board specific PMIC */
197 int power_init_board(void)
203 power_pfuze100_init(1);
204 p = pmic_get("PFUZE100");
212 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
213 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
215 /* Set SWBST to 5.0V and enable (for USB) */
216 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®);
217 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
218 reg |= (SWBST_5_00V | SWBST_MODE_AUTO);
219 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
224 /* EEPROM configuration data */
225 struct novena_eeprom_data {
226 uint8_t signature[6];
234 int misc_init_r(void)
236 struct novena_eeprom_data data;
237 uchar *datap = (uchar *)&data;
238 const char *signature = "Novena";
241 /* If 'ethaddr' is already set, do nothing. */
242 if (getenv("ethaddr"))
245 /* EEPROM is at bus 2. */
246 ret = i2c_set_bus_num(2);
248 puts("Cannot select EEPROM I2C bus.\n");
252 /* EEPROM is at address 0x56. */
253 ret = eeprom_read(0x56, 0, datap, sizeof(data));
255 puts("Cannot read I2C EEPROM.\n");
259 /* Check EEPROM signature. */
260 if (memcmp(data.signature, signature, 6)) {
261 puts("Invalid I2C EEPROM signature.\n");
265 /* Set ethernet address from EEPROM. */
266 eth_setenv_enetaddr("ethaddr", data.mac);