4 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
6 * SPDX-License-Identifier: GPL-2.0+
10 #include <linux/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/mach-imx/boot_mode.h>
20 #include <asm/mach-imx/iomux-v3.h>
21 #include <asm/mach-imx/mxc_i2c.h>
22 #include <asm/mach-imx/sata.h>
23 #include <asm/mach-imx/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,
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 input_add_tables(&button_input, false);
92 button_input.read_keys = novena_gpio_button_read_keys;
94 error = input_stdio_register(&dev);
105 #ifdef CONFIG_FSL_ESDHC
106 static struct fsl_esdhc_cfg usdhc_cfg[] = {
107 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */
108 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */
111 int board_mmc_getcd(struct mmc *mmc)
113 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
115 /* There is no CD for a microSD card, assume always present. */
116 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
119 return !gpio_get_value(NOVENA_SD_CD);
122 int board_mmc_getwp(struct mmc *mmc)
124 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
126 /* There is no WP for a microSD card, assume always read-write. */
127 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
130 return gpio_get_value(NOVENA_SD_WP);
134 int board_mmc_init(bd_t *bis)
139 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
140 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
142 /* Big SD write-protect and card-detect */
143 gpio_direction_input(NOVENA_SD_WP);
144 gpio_direction_input(NOVENA_SD_CD);
146 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
147 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
156 int board_early_init_f(void)
158 #if defined(CONFIG_VIDEO_IPUV3)
159 setup_display_clock();
167 /* address of boot parameters */
168 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
177 int board_late_init(void)
179 #if defined(CONFIG_VIDEO_IPUV3)
180 setup_display_lvds();
187 puts("Board: Novena 4x\n");
193 gd->ram_size = imx_ddr_size();
197 /* setup board specific PMIC */
198 int power_init_board(void)
204 power_pfuze100_init(1);
205 p = pmic_get("PFUZE100");
213 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
214 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
216 /* Set SWBST to 5.0V and enable (for USB) */
217 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®);
218 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
219 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
220 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
225 /* EEPROM configuration data */
226 struct novena_eeprom_data {
227 uint8_t signature[6];
235 int misc_init_r(void)
237 struct novena_eeprom_data data;
238 uchar *datap = (uchar *)&data;
239 const char *signature = "Novena";
242 /* If 'ethaddr' is already set, do nothing. */
243 if (env_get("ethaddr"))
246 /* EEPROM is at bus 2. */
247 ret = i2c_set_bus_num(2);
249 puts("Cannot select EEPROM I2C bus.\n");
253 /* EEPROM is at address 0x56. */
254 ret = eeprom_read(0x56, 0, datap, sizeof(data));
256 puts("Cannot read I2C EEPROM.\n");
260 /* Check EEPROM signature. */
261 if (memcmp(data.signature, signature, 6)) {
262 puts("Invalid I2C EEPROM signature.\n");
266 /* Set ethernet address from EEPROM. */
267 eth_env_set_enetaddr("ethaddr", data.mac);