blob: b1939f8a56e259b7a6635d03749f71ca927c1b69 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasutf91c09a2014-10-24 23:39:07 +02002/*
3 * Novena board support
4 *
5 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
Marek Vasutf91c09a2014-10-24 23:39:07 +02006 */
7
8#include <common.h>
Marek Vasut6b98b942019-05-17 20:32:17 +02009#include <dm.h>
Simon Glasscb3ef682019-11-14 12:57:50 -070010#include <eeprom.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060012#include <log.h>
Marek Vasut6b98b942019-05-17 20:32:17 +020013#include <dm/device-internal.h>
14#include <ahci.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060015#include <env.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090016#include <linux/errno.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020017#include <asm/gpio.h>
18#include <asm/io.h>
19#include <asm/arch/clock.h>
20#include <asm/arch/crm_regs.h>
21#include <asm/arch/imx-regs.h>
22#include <asm/arch/iomux.h>
23#include <asm/arch/mxc_hdmi.h>
24#include <asm/arch/sys_proto.h>
Stefano Babic552a8482017-06-29 10:16:06 +020025#include <asm/mach-imx/boot_mode.h>
26#include <asm/mach-imx/iomux-v3.h>
27#include <asm/mach-imx/mxc_i2c.h>
28#include <asm/mach-imx/sata.h>
29#include <asm/mach-imx/video.h>
Marek Vasut6b98b942019-05-17 20:32:17 +020030#include <dwc_ahsata.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080031#include <fsl_esdhc_imx.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020032#include <i2c.h>
33#include <input.h>
34#include <ipu_pixfmt.h>
35#include <linux/fb.h>
36#include <linux/input.h>
37#include <malloc.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020038#include <mmc.h>
39#include <netdev.h>
40#include <power/pmic.h>
41#include <power/pfuze100_pmic.h>
42#include <stdio_dev.h>
Marek Vasut2f1c06c2019-05-17 20:32:20 +020043#include <video_console.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020044
Marek Vasutd59d7b92014-12-16 14:09:21 +010045#include "novena.h"
Marek Vasutf91c09a2014-10-24 23:39:07 +020046
Marek Vasutd59d7b92014-12-16 14:09:21 +010047DECLARE_GLOBAL_DATA_PTR;
Marek Vasutf91c09a2014-10-24 23:39:07 +020048
49/*
50 * GPIO button
51 */
52#ifdef CONFIG_KEYBOARD
53static struct input_config button_input;
54
55static int novena_gpio_button_read_keys(struct input_config *input)
56{
57 int key = KEY_ENTER;
58 if (gpio_get_value(NOVENA_BUTTON_GPIO))
59 return 0;
60 input_send_keycodes(&button_input, &key, 1);
61 return 1;
62}
63
64static int novena_gpio_button_getc(struct stdio_dev *dev)
65{
66 return input_getc(&button_input);
67}
68
69static int novena_gpio_button_tstc(struct stdio_dev *dev)
70{
71 return input_tstc(&button_input);
72}
73
74static int novena_gpio_button_init(struct stdio_dev *dev)
75{
76 gpio_direction_input(NOVENA_BUTTON_GPIO);
77 input_set_delays(&button_input, 250, 250);
78 return 0;
79}
80
81int drv_keyboard_init(void)
82{
83 int error;
84 struct stdio_dev dev = {
85 .name = "button",
Bin Meng1caf9342015-11-03 23:23:37 -080086 .flags = DEV_FLAGS_INPUT,
Marek Vasutf91c09a2014-10-24 23:39:07 +020087 .start = novena_gpio_button_init,
88 .getc = novena_gpio_button_getc,
89 .tstc = novena_gpio_button_tstc,
90 };
91
Marek Vasutc4e93f62019-05-17 20:32:16 +020092 gpio_request(NOVENA_BUTTON_GPIO, "button");
93
Marek Vasutf91c09a2014-10-24 23:39:07 +020094 error = input_init(&button_input, 0);
95 if (error) {
96 debug("%s: Cannot set up input\n", __func__);
97 return -1;
98 }
Simon Glassb1d7a182015-11-11 10:05:37 -070099 input_add_tables(&button_input, false);
Marek Vasutf91c09a2014-10-24 23:39:07 +0200100 button_input.read_keys = novena_gpio_button_read_keys;
101
102 error = input_stdio_register(&dev);
103 if (error)
104 return error;
105
106 return 0;
107}
108#endif
109
Marek Vasutf91c09a2014-10-24 23:39:07 +0200110int board_early_init_f(void)
111{
112#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasutf2e4d6a2014-12-16 14:09:22 +0100113 setup_display_clock();
Marek Vasutf91c09a2014-10-24 23:39:07 +0200114#endif
115
Marek Vasutf91c09a2014-10-24 23:39:07 +0200116 return 0;
117}
118
119int board_init(void)
120{
121 /* address of boot parameters */
122 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
123
Marek Vasutf91c09a2014-10-24 23:39:07 +0200124 return 0;
125}
126
Marek Vasut331ae842014-12-16 14:09:23 +0100127int board_late_init(void)
128{
129#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut2f1c06c2019-05-17 20:32:20 +0200130 struct udevice *con;
131 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
132 int ret;
133
Marek Vasut331ae842014-12-16 14:09:23 +0100134 setup_display_lvds();
Marek Vasut2f1c06c2019-05-17 20:32:20 +0200135
136 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
137 if (ret)
138 return ret;
139
140 display_options_get_banner(false, buf, sizeof(buf));
141 vidconsole_position_cursor(con, 0, 0);
142 vidconsole_put_string(con, buf);
Marek Vasut331ae842014-12-16 14:09:23 +0100143#endif
144 return 0;
145}
146
Marek Vasutf91c09a2014-10-24 23:39:07 +0200147int checkboard(void)
148{
149 puts("Board: Novena 4x\n");
150 return 0;
151}
152
153int dram_init(void)
154{
155 gd->ram_size = imx_ddr_size();
156 return 0;
157}
158
159/* setup board specific PMIC */
160int power_init_board(void)
161{
162 struct pmic *p;
163 u32 reg;
164 int ret;
165
166 power_pfuze100_init(1);
167 p = pmic_get("PFUZE100");
168 if (!p)
169 return -EINVAL;
170
171 ret = pmic_probe(p);
172 if (ret)
173 return ret;
174
175 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
176 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
177
178 /* Set SWBST to 5.0V and enable (for USB) */
179 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
180 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut18e02ff2015-11-26 14:08:50 +0100181 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasutf91c09a2014-10-24 23:39:07 +0200182 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
183
184 return 0;
185}
186
187/* EEPROM configuration data */
188struct novena_eeprom_data {
189 uint8_t signature[6];
190 uint8_t version;
191 uint8_t reserved;
192 uint32_t serial;
193 uint8_t mac[6];
194 uint16_t features;
195};
196
197int misc_init_r(void)
198{
199 struct novena_eeprom_data data;
200 uchar *datap = (uchar *)&data;
201 const char *signature = "Novena";
202 int ret;
203
204 /* If 'ethaddr' is already set, do nothing. */
Simon Glass00caae62017-08-03 12:22:12 -0600205 if (env_get("ethaddr"))
Marek Vasutf91c09a2014-10-24 23:39:07 +0200206 return 0;
207
208 /* EEPROM is at bus 2. */
209 ret = i2c_set_bus_num(2);
210 if (ret) {
211 puts("Cannot select EEPROM I2C bus.\n");
212 return 0;
213 }
214
215 /* EEPROM is at address 0x56. */
216 ret = eeprom_read(0x56, 0, datap, sizeof(data));
217 if (ret) {
218 puts("Cannot read I2C EEPROM.\n");
219 return 0;
220 }
221
222 /* Check EEPROM signature. */
223 if (memcmp(data.signature, signature, 6)) {
224 puts("Invalid I2C EEPROM signature.\n");
225 return 0;
226 }
227
228 /* Set ethernet address from EEPROM. */
Simon Glassfd1e9592017-08-03 12:22:11 -0600229 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasutf91c09a2014-10-24 23:39:07 +0200230
231 return ret;
232}