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 <environment.h>
25 #include <fsl_esdhc.h>
28 #include <ipu_pixfmt.h>
30 #include <linux/input.h>
36 #include <power/pmic.h>
37 #include <power/pfuze100_pmic.h>
38 #include <stdio_dev.h>
42 DECLARE_GLOBAL_DATA_PTR;
47 #ifdef CONFIG_KEYBOARD
48 static struct input_config button_input;
50 static int novena_gpio_button_read_keys(struct input_config *input)
53 if (gpio_get_value(NOVENA_BUTTON_GPIO))
55 input_send_keycodes(&button_input, &key, 1);
59 static int novena_gpio_button_getc(struct stdio_dev *dev)
61 return input_getc(&button_input);
64 static int novena_gpio_button_tstc(struct stdio_dev *dev)
66 return input_tstc(&button_input);
69 static int novena_gpio_button_init(struct stdio_dev *dev)
71 gpio_direction_input(NOVENA_BUTTON_GPIO);
72 input_set_delays(&button_input, 250, 250);
76 int drv_keyboard_init(void)
79 struct stdio_dev dev = {
81 .flags = DEV_FLAGS_INPUT,
82 .start = novena_gpio_button_init,
83 .getc = novena_gpio_button_getc,
84 .tstc = novena_gpio_button_tstc,
87 error = input_init(&button_input, 0);
89 debug("%s: Cannot set up input\n", __func__);
92 input_add_tables(&button_input, false);
93 button_input.read_keys = novena_gpio_button_read_keys;
95 error = input_stdio_register(&dev);
106 #ifdef CONFIG_FSL_ESDHC
107 static struct fsl_esdhc_cfg usdhc_cfg[] = {
108 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */
109 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */
112 int board_mmc_getcd(struct mmc *mmc)
114 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
116 /* There is no CD for a microSD card, assume always present. */
117 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
120 return !gpio_get_value(NOVENA_SD_CD);
123 int board_mmc_getwp(struct mmc *mmc)
125 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
127 /* There is no WP for a microSD card, assume always read-write. */
128 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
131 return gpio_get_value(NOVENA_SD_WP);
135 int board_mmc_init(bd_t *bis)
140 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
141 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
143 /* Big SD write-protect and card-detect */
144 gpio_direction_input(NOVENA_SD_WP);
145 gpio_direction_input(NOVENA_SD_CD);
147 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
148 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
157 int board_early_init_f(void)
159 #if defined(CONFIG_VIDEO_IPUV3)
160 setup_display_clock();
168 /* address of boot parameters */
169 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
178 int board_late_init(void)
180 #if defined(CONFIG_VIDEO_IPUV3)
181 setup_display_lvds();
188 puts("Board: Novena 4x\n");
194 gd->ram_size = imx_ddr_size();
198 /* setup board specific PMIC */
199 int power_init_board(void)
205 power_pfuze100_init(1);
206 p = pmic_get("PFUZE100");
214 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
215 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
217 /* Set SWBST to 5.0V and enable (for USB) */
218 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®);
219 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
220 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
221 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
226 /* EEPROM configuration data */
227 struct novena_eeprom_data {
228 uint8_t signature[6];
236 int misc_init_r(void)
238 struct novena_eeprom_data data;
239 uchar *datap = (uchar *)&data;
240 const char *signature = "Novena";
243 /* If 'ethaddr' is already set, do nothing. */
244 if (env_get("ethaddr"))
247 /* EEPROM is at bus 2. */
248 ret = i2c_set_bus_num(2);
250 puts("Cannot select EEPROM I2C bus.\n");
254 /* EEPROM is at address 0x56. */
255 ret = eeprom_read(0x56, 0, datap, sizeof(data));
257 puts("Cannot read I2C EEPROM.\n");
261 /* Check EEPROM signature. */
262 if (memcmp(data.signature, signature, 6)) {
263 puts("Invalid I2C EEPROM signature.\n");
267 /* Set ethernet address from EEPROM. */
268 eth_env_set_enetaddr("ethaddr", data.mac);