1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3 * Novena board support
4 *
5 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
6 */
7
8 #include <common.h>
9 #include <dm.h>
10 #include <eeprom.h>
11 #include <init.h>
12 #include <dm/device-internal.h>
13 #include <ahci.h>
14 #include <env.h>
15 #include <linux/errno.h>
16 #include <asm/gpio.h>
17 #include <asm/io.h>
18 #include <asm/arch/clock.h>
19 #include <asm/arch/crm_regs.h>
20 #include <asm/arch/imx-regs.h>
21 #include <asm/arch/iomux.h>
22 #include <asm/arch/mxc_hdmi.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/mach-imx/boot_mode.h>
25 #include <asm/mach-imx/iomux-v3.h>
26 #include <asm/mach-imx/mxc_i2c.h>
27 #include <asm/mach-imx/sata.h>
28 #include <asm/mach-imx/video.h>
29 #include <dwc_ahsata.h>
30 #include <fsl_esdhc_imx.h>
31 #include <i2c.h>
32 #include <input.h>
33 #include <ipu_pixfmt.h>
34 #include <linux/fb.h>
35 #include <linux/input.h>
36 #include <malloc.h>
37 #include <mmc.h>
38 #include <netdev.h>
39 #include <power/pmic.h>
40 #include <power/pfuze100_pmic.h>
41 #include <stdio_dev.h>
42 #include <video_console.h>
43
44 #include "novena.h"
45
46 DECLARE_GLOBAL_DATA_PTR;
47
48 /*
49 * GPIO button
50 */
51 #ifdef CONFIG_KEYBOARD
52 static struct input_config button_input;
53
novena_gpio_button_read_keys(struct input_config * input)54 static int novena_gpio_button_read_keys(struct input_config *input)
55 {
56 int key = KEY_ENTER;
57 if (gpio_get_value(NOVENA_BUTTON_GPIO))
58 return 0;
59 input_send_keycodes(&button_input, &key, 1);
60 return 1;
61 }
62
novena_gpio_button_getc(struct stdio_dev * dev)63 static int novena_gpio_button_getc(struct stdio_dev *dev)
64 {
65 return input_getc(&button_input);
66 }
67
novena_gpio_button_tstc(struct stdio_dev * dev)68 static int novena_gpio_button_tstc(struct stdio_dev *dev)
69 {
70 return input_tstc(&button_input);
71 }
72
novena_gpio_button_init(struct stdio_dev * dev)73 static int novena_gpio_button_init(struct stdio_dev *dev)
74 {
75 gpio_direction_input(NOVENA_BUTTON_GPIO);
76 input_set_delays(&button_input, 250, 250);
77 return 0;
78 }
79
drv_keyboard_init(void)80 int drv_keyboard_init(void)
81 {
82 int error;
83 struct stdio_dev dev = {
84 .name = "button",
85 .flags = DEV_FLAGS_INPUT,
86 .start = novena_gpio_button_init,
87 .getc = novena_gpio_button_getc,
88 .tstc = novena_gpio_button_tstc,
89 };
90
91 gpio_request(NOVENA_BUTTON_GPIO, "button");
92
93 error = input_init(&button_input, 0);
94 if (error) {
95 debug("%s: Cannot set up input\n", __func__);
96 return -1;
97 }
98 input_add_tables(&button_input, false);
99 button_input.read_keys = novena_gpio_button_read_keys;
100
101 error = input_stdio_register(&dev);
102 if (error)
103 return error;
104
105 return 0;
106 }
107 #endif
108
board_early_init_f(void)109 int board_early_init_f(void)
110 {
111 #if defined(CONFIG_VIDEO_IPUV3)
112 setup_display_clock();
113 #endif
114
115 return 0;
116 }
117
board_init(void)118 int board_init(void)
119 {
120 /* address of boot parameters */
121 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
122
123 return 0;
124 }
125
board_late_init(void)126 int board_late_init(void)
127 {
128 #if defined(CONFIG_VIDEO_IPUV3)
129 struct udevice *con;
130 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
131 int ret;
132
133 setup_display_lvds();
134
135 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
136 if (ret)
137 return ret;
138
139 display_options_get_banner(false, buf, sizeof(buf));
140 vidconsole_position_cursor(con, 0, 0);
141 vidconsole_put_string(con, buf);
142 #endif
143 return 0;
144 }
145
checkboard(void)146 int checkboard(void)
147 {
148 puts("Board: Novena 4x\n");
149 return 0;
150 }
151
dram_init(void)152 int dram_init(void)
153 {
154 gd->ram_size = imx_ddr_size();
155 return 0;
156 }
157
158 /* setup board specific PMIC */
power_init_board(void)159 int power_init_board(void)
160 {
161 struct pmic *p;
162 u32 reg;
163 int ret;
164
165 power_pfuze100_init(1);
166 p = pmic_get("PFUZE100");
167 if (!p)
168 return -EINVAL;
169
170 ret = pmic_probe(p);
171 if (ret)
172 return ret;
173
174 pmic_reg_read(p, PFUZE100_DEVICEID, ®);
175 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
176
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);
182
183 return 0;
184 }
185
186 /* EEPROM configuration data */
187 struct novena_eeprom_data {
188 uint8_t signature[6];
189 uint8_t version;
190 uint8_t reserved;
191 uint32_t serial;
192 uint8_t mac[6];
193 uint16_t features;
194 };
195
misc_init_r(void)196 int misc_init_r(void)
197 {
198 struct novena_eeprom_data data;
199 uchar *datap = (uchar *)&data;
200 const char *signature = "Novena";
201 int ret;
202
203 /* If 'ethaddr' is already set, do nothing. */
204 if (env_get("ethaddr"))
205 return 0;
206
207 /* EEPROM is at bus 2. */
208 ret = i2c_set_bus_num(2);
209 if (ret) {
210 puts("Cannot select EEPROM I2C bus.\n");
211 return 0;
212 }
213
214 /* EEPROM is at address 0x56. */
215 ret = eeprom_read(0x56, 0, datap, sizeof(data));
216 if (ret) {
217 puts("Cannot read I2C EEPROM.\n");
218 return 0;
219 }
220
221 /* Check EEPROM signature. */
222 if (memcmp(data.signature, signature, 6)) {
223 puts("Invalid I2C EEPROM signature.\n");
224 return 0;
225 }
226
227 /* Set ethernet address from EEPROM. */
228 eth_env_set_enetaddr("ethaddr", data.mac);
229
230 return ret;
231 }
232