1 // SPDX-License-Identifier: GPL-2.0+
13 #include <asm/global_data.h>
14 #include <dm/device-internal.h>
17 #include <linux/errno.h>
20 #include <asm/arch/clock.h>
21 #include <asm/arch/crm_regs.h>
22 #include <asm/arch/imx-regs.h>
23 #include <asm/arch/iomux.h>
24 #include <asm/arch/mxc_hdmi.h>
25 #include <asm/arch/sys_proto.h>
26 #include <asm/mach-imx/boot_mode.h>
27 #include <asm/mach-imx/iomux-v3.h>
28 #include <asm/mach-imx/mxc_i2c.h>
29 #include <asm/mach-imx/sata.h>
30 #include <asm/mach-imx/video.h>
31 #include <dwc_ahsata.h>
32 #include <fsl_esdhc_imx.h>
35 #include <ipu_pixfmt.h>
37 #include <linux/input.h>
41 #include <power/pmic.h>
42 #include <power/pfuze100_pmic.h>
43 #include <stdio_dev.h>
44 #include <video_console.h>
48 DECLARE_GLOBAL_DATA_PTR;
53 #ifdef CONFIG_KEYBOARD
54 static struct input_config button_input;
56 static int novena_gpio_button_read_keys(struct input_config *input)
59 if (gpio_get_value(NOVENA_BUTTON_GPIO))
61 input_send_keycodes(&button_input, &key, 1);
65 static int novena_gpio_button_getc(struct stdio_dev *dev)
67 return input_getc(&button_input);
70 static int novena_gpio_button_tstc(struct stdio_dev *dev)
72 return input_tstc(&button_input);
75 static int novena_gpio_button_init(struct stdio_dev *dev)
77 gpio_direction_input(NOVENA_BUTTON_GPIO);
78 input_set_delays(&button_input, 250, 250);
82 int drv_keyboard_init(void)
85 struct stdio_dev dev = {
87 .flags = DEV_FLAGS_INPUT,
88 .start = novena_gpio_button_init,
89 .getc = novena_gpio_button_getc,
90 .tstc = novena_gpio_button_tstc,
93 gpio_request(NOVENA_BUTTON_GPIO, "button");
95 error = input_init(&button_input, 0);
97 debug("%s: Cannot set up input\n", __func__);
100 input_add_tables(&button_input, false);
101 button_input.read_keys = novena_gpio_button_read_keys;
103 error = input_stdio_register(&dev);
111 int board_early_init_f(void)
113 #if defined(CONFIG_VIDEO_IPUV3)
114 setup_display_clock();
122 /* address of boot parameters */
123 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
128 int board_late_init(void)
130 #if defined(CONFIG_VIDEO_IPUV3)
132 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
135 setup_display_lvds();
137 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
141 display_options_get_banner(false, buf, sizeof(buf));
142 vidconsole_position_cursor(con, 0, 0);
143 vidconsole_put_string(con, buf);
150 puts("Board: Novena 4x\n");
156 gd->ram_size = imx_ddr_size();
160 /* setup board specific PMIC */
161 int power_init_board(void)
167 power_pfuze100_init(1);
168 p = pmic_get("PFUZE100");
176 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
177 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
179 /* Set SWBST to 5.0V and enable (for USB) */
180 pmic_reg_read(p, PFUZE100_SWBSTCON1, ®);
181 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
182 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
183 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
188 /* EEPROM configuration data */
189 struct novena_eeprom_data {
190 uint8_t signature[6];
198 int misc_init_r(void)
200 struct novena_eeprom_data data;
201 uchar *datap = (uchar *)&data;
202 const char *signature = "Novena";
205 /* If 'ethaddr' is already set, do nothing. */
206 if (env_get("ethaddr"))
209 /* EEPROM is at bus 2. */
210 ret = i2c_set_bus_num(2);
212 puts("Cannot select EEPROM I2C bus.\n");
216 /* EEPROM is at address 0x56. */
217 ret = eeprom_read(0x56, 0, datap, sizeof(data));
219 puts("Cannot read I2C EEPROM.\n");
223 /* Check EEPROM signature. */
224 if (memcmp(data.signature, signature, 6)) {
225 puts("Invalid I2C EEPROM signature.\n");
229 /* Set ethernet address from EEPROM. */
230 eth_env_set_enetaddr("ethaddr", data.mac);