1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
9 #include <linux/errno.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>
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>
23 #include <environment.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 gpio_request(NOVENA_BUTTON_GPIO, "button");
88 error = input_init(&button_input, 0);
90 debug("%s: Cannot set up input\n", __func__);
93 input_add_tables(&button_input, false);
94 button_input.read_keys = novena_gpio_button_read_keys;
96 error = input_stdio_register(&dev);
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 */
113 int board_mmc_getcd(struct mmc *mmc)
115 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
117 /* There is no CD for a microSD card, assume always present. */
118 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
121 return !gpio_get_value(NOVENA_SD_CD);
124 int board_mmc_getwp(struct mmc *mmc)
126 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
128 /* There is no WP for a microSD card, assume always read-write. */
129 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
132 return gpio_get_value(NOVENA_SD_WP);
136 int board_mmc_init(bd_t *bis)
141 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
142 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
144 /* Big SD write-protect and card-detect */
145 gpio_direction_input(NOVENA_SD_WP);
146 gpio_direction_input(NOVENA_SD_CD);
148 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
149 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
158 int board_early_init_f(void)
160 #if defined(CONFIG_VIDEO_IPUV3)
161 setup_display_clock();
169 /* address of boot parameters */
170 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
179 int board_late_init(void)
181 #if defined(CONFIG_VIDEO_IPUV3)
182 setup_display_lvds();
189 puts("Board: Novena 4x\n");
195 gd->ram_size = imx_ddr_size();
199 /* setup board specific PMIC */
200 int power_init_board(void)
206 power_pfuze100_init(1);
207 p = pmic_get("PFUZE100");
215 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
216 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
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);
221 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
222 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
227 /* EEPROM configuration data */
228 struct novena_eeprom_data {
229 uint8_t signature[6];
237 int misc_init_r(void)
239 struct novena_eeprom_data data;
240 uchar *datap = (uchar *)&data;
241 const char *signature = "Novena";
244 /* If 'ethaddr' is already set, do nothing. */
245 if (env_get("ethaddr"))
248 /* EEPROM is at bus 2. */
249 ret = i2c_set_bus_num(2);
251 puts("Cannot select EEPROM I2C bus.\n");
255 /* EEPROM is at address 0x56. */
256 ret = eeprom_read(0x56, 0, datap, sizeof(data));
258 puts("Cannot read I2C EEPROM.\n");
262 /* Check EEPROM signature. */
263 if (memcmp(data.signature, signature, 6)) {
264 puts("Invalid I2C EEPROM signature.\n");
268 /* Set ethernet address from EEPROM. */
269 eth_env_set_enetaddr("ethaddr", data.mac);