1 // SPDX-License-Identifier: GPL-2.0+
5 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
10 #include <dm/device-internal.h>
13 #include <linux/errno.h>
16 #include <asm/arch/clock.h>
17 #include <asm/arch/crm_regs.h>
18 #include <asm/arch/imx-regs.h>
19 #include <asm/arch/iomux.h>
20 #include <asm/arch/mxc_hdmi.h>
21 #include <asm/arch/sys_proto.h>
22 #include <asm/mach-imx/boot_mode.h>
23 #include <asm/mach-imx/iomux-v3.h>
24 #include <asm/mach-imx/mxc_i2c.h>
25 #include <asm/mach-imx/sata.h>
26 #include <asm/mach-imx/video.h>
27 #include <dwc_ahsata.h>
28 #include <fsl_esdhc_imx.h>
31 #include <ipu_pixfmt.h>
33 #include <linux/input.h>
39 #include <power/pmic.h>
40 #include <power/pfuze100_pmic.h>
41 #include <stdio_dev.h>
42 #include <video_console.h>
46 DECLARE_GLOBAL_DATA_PTR;
51 #ifdef CONFIG_KEYBOARD
52 static struct input_config button_input;
54 static int novena_gpio_button_read_keys(struct input_config *input)
57 if (gpio_get_value(NOVENA_BUTTON_GPIO))
59 input_send_keycodes(&button_input, &key, 1);
63 static int novena_gpio_button_getc(struct stdio_dev *dev)
65 return input_getc(&button_input);
68 static int novena_gpio_button_tstc(struct stdio_dev *dev)
70 return input_tstc(&button_input);
73 static int novena_gpio_button_init(struct stdio_dev *dev)
75 gpio_direction_input(NOVENA_BUTTON_GPIO);
76 input_set_delays(&button_input, 250, 250);
80 int drv_keyboard_init(void)
83 struct stdio_dev dev = {
85 .flags = DEV_FLAGS_INPUT,
86 .start = novena_gpio_button_init,
87 .getc = novena_gpio_button_getc,
88 .tstc = novena_gpio_button_tstc,
91 gpio_request(NOVENA_BUTTON_GPIO, "button");
93 error = input_init(&button_input, 0);
95 debug("%s: Cannot set up input\n", __func__);
98 input_add_tables(&button_input, false);
99 button_input.read_keys = novena_gpio_button_read_keys;
101 error = input_stdio_register(&dev);
109 int board_early_init_f(void)
111 #if defined(CONFIG_VIDEO_IPUV3)
112 setup_display_clock();
120 /* address of boot parameters */
121 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
126 int board_late_init(void)
128 #if defined(CONFIG_VIDEO_IPUV3)
130 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
133 setup_display_lvds();
135 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
139 display_options_get_banner(false, buf, sizeof(buf));
140 vidconsole_position_cursor(con, 0, 0);
141 vidconsole_put_string(con, buf);
148 puts("Board: Novena 4x\n");
154 gd->ram_size = imx_ddr_size();
158 /* setup board specific PMIC */
159 int power_init_board(void)
165 power_pfuze100_init(1);
166 p = pmic_get("PFUZE100");
174 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
175 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
177 /* Set SWBST to 5.0V and enable (for USB) */
178 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®);
179 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
180 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
181 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
186 /* EEPROM configuration data */
187 struct novena_eeprom_data {
188 uint8_t signature[6];
196 int misc_init_r(void)
198 struct novena_eeprom_data data;
199 uchar *datap = (uchar *)&data;
200 const char *signature = "Novena";
203 /* If 'ethaddr' is already set, do nothing. */
204 if (env_get("ethaddr"))
207 /* EEPROM is at bus 2. */
208 ret = i2c_set_bus_num(2);
210 puts("Cannot select EEPROM I2C bus.\n");
214 /* EEPROM is at address 0x56. */
215 ret = eeprom_read(0x56, 0, datap, sizeof(data));
217 puts("Cannot read I2C EEPROM.\n");
221 /* Check EEPROM signature. */
222 if (memcmp(data.signature, signature, 6)) {
223 puts("Invalid I2C EEPROM signature.\n");
227 /* Set ethernet address from EEPROM. */
228 eth_env_set_enetaddr("ethaddr", data.mac);