blob: 0e1b4a0a46ce558e8c2f4e731bba4820b6ae6628 [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>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Marek Vasut6b98b942019-05-17 20:32:17 +020014#include <dm/device-internal.h>
15#include <ahci.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060016#include <env.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090017#include <linux/errno.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020018#include <asm/gpio.h>
19#include <asm/io.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>
Stefano Babic552a8482017-06-29 10:16:06 +020026#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>
Marek Vasut6b98b942019-05-17 20:32:17 +020031#include <dwc_ahsata.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080032#include <fsl_esdhc_imx.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020033#include <i2c.h>
34#include <input.h>
35#include <ipu_pixfmt.h>
36#include <linux/fb.h>
37#include <linux/input.h>
38#include <malloc.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020039#include <mmc.h>
40#include <netdev.h>
41#include <power/pmic.h>
42#include <power/pfuze100_pmic.h>
43#include <stdio_dev.h>
Marek Vasut2f1c06c2019-05-17 20:32:20 +020044#include <video_console.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020045
Marek Vasutd59d7b92014-12-16 14:09:21 +010046#include "novena.h"
Marek Vasutf91c09a2014-10-24 23:39:07 +020047
Marek Vasutd59d7b92014-12-16 14:09:21 +010048DECLARE_GLOBAL_DATA_PTR;
Marek Vasutf91c09a2014-10-24 23:39:07 +020049
50/*
51 * GPIO button
52 */
53#ifdef CONFIG_KEYBOARD
54static struct input_config button_input;
55
56static int novena_gpio_button_read_keys(struct input_config *input)
57{
58 int key = KEY_ENTER;
59 if (gpio_get_value(NOVENA_BUTTON_GPIO))
60 return 0;
61 input_send_keycodes(&button_input, &key, 1);
62 return 1;
63}
64
65static int novena_gpio_button_getc(struct stdio_dev *dev)
66{
67 return input_getc(&button_input);
68}
69
70static int novena_gpio_button_tstc(struct stdio_dev *dev)
71{
72 return input_tstc(&button_input);
73}
74
75static int novena_gpio_button_init(struct stdio_dev *dev)
76{
77 gpio_direction_input(NOVENA_BUTTON_GPIO);
78 input_set_delays(&button_input, 250, 250);
79 return 0;
80}
81
82int drv_keyboard_init(void)
83{
84 int error;
85 struct stdio_dev dev = {
86 .name = "button",
Bin Meng1caf9342015-11-03 23:23:37 -080087 .flags = DEV_FLAGS_INPUT,
Marek Vasutf91c09a2014-10-24 23:39:07 +020088 .start = novena_gpio_button_init,
89 .getc = novena_gpio_button_getc,
90 .tstc = novena_gpio_button_tstc,
91 };
92
Marek Vasutc4e93f62019-05-17 20:32:16 +020093 gpio_request(NOVENA_BUTTON_GPIO, "button");
94
Marek Vasutf91c09a2014-10-24 23:39:07 +020095 error = input_init(&button_input, 0);
96 if (error) {
97 debug("%s: Cannot set up input\n", __func__);
98 return -1;
99 }
Simon Glassb1d7a182015-11-11 10:05:37 -0700100 input_add_tables(&button_input, false);
Marek Vasutf91c09a2014-10-24 23:39:07 +0200101 button_input.read_keys = novena_gpio_button_read_keys;
102
103 error = input_stdio_register(&dev);
104 if (error)
105 return error;
106
107 return 0;
108}
109#endif
110
Marek Vasutf91c09a2014-10-24 23:39:07 +0200111int board_early_init_f(void)
112{
113#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasutf2e4d6a2014-12-16 14:09:22 +0100114 setup_display_clock();
Marek Vasutf91c09a2014-10-24 23:39:07 +0200115#endif
116
Marek Vasutf91c09a2014-10-24 23:39:07 +0200117 return 0;
118}
119
120int board_init(void)
121{
122 /* address of boot parameters */
123 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
124
Marek Vasutf91c09a2014-10-24 23:39:07 +0200125 return 0;
126}
127
Marek Vasut331ae842014-12-16 14:09:23 +0100128int board_late_init(void)
129{
130#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut2f1c06c2019-05-17 20:32:20 +0200131 struct udevice *con;
132 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
133 int ret;
134
Marek Vasut331ae842014-12-16 14:09:23 +0100135 setup_display_lvds();
Marek Vasut2f1c06c2019-05-17 20:32:20 +0200136
137 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
138 if (ret)
139 return ret;
140
141 display_options_get_banner(false, buf, sizeof(buf));
142 vidconsole_position_cursor(con, 0, 0);
143 vidconsole_put_string(con, buf);
Marek Vasut331ae842014-12-16 14:09:23 +0100144#endif
145 return 0;
146}
147
Marek Vasutf91c09a2014-10-24 23:39:07 +0200148int checkboard(void)
149{
150 puts("Board: Novena 4x\n");
151 return 0;
152}
153
154int dram_init(void)
155{
156 gd->ram_size = imx_ddr_size();
157 return 0;
158}
159
160/* setup board specific PMIC */
161int power_init_board(void)
162{
163 struct pmic *p;
164 u32 reg;
165 int ret;
166
167 power_pfuze100_init(1);
168 p = pmic_get("PFUZE100");
169 if (!p)
170 return -EINVAL;
171
172 ret = pmic_probe(p);
173 if (ret)
174 return ret;
175
176 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
177 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
178
179 /* Set SWBST to 5.0V and enable (for USB) */
180 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
181 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut18e02ff2015-11-26 14:08:50 +0100182 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasutf91c09a2014-10-24 23:39:07 +0200183 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
184
185 return 0;
186}
187
188/* EEPROM configuration data */
189struct novena_eeprom_data {
190 uint8_t signature[6];
191 uint8_t version;
192 uint8_t reserved;
193 uint32_t serial;
194 uint8_t mac[6];
195 uint16_t features;
196};
197
198int misc_init_r(void)
199{
200 struct novena_eeprom_data data;
201 uchar *datap = (uchar *)&data;
202 const char *signature = "Novena";
203 int ret;
204
205 /* If 'ethaddr' is already set, do nothing. */
Simon Glass00caae62017-08-03 12:22:12 -0600206 if (env_get("ethaddr"))
Marek Vasutf91c09a2014-10-24 23:39:07 +0200207 return 0;
208
209 /* EEPROM is at bus 2. */
210 ret = i2c_set_bus_num(2);
211 if (ret) {
212 puts("Cannot select EEPROM I2C bus.\n");
213 return 0;
214 }
215
216 /* EEPROM is at address 0x56. */
217 ret = eeprom_read(0x56, 0, datap, sizeof(data));
218 if (ret) {
219 puts("Cannot read I2C EEPROM.\n");
220 return 0;
221 }
222
223 /* Check EEPROM signature. */
224 if (memcmp(data.signature, signature, 6)) {
225 puts("Invalid I2C EEPROM signature.\n");
226 return 0;
227 }
228
229 /* Set ethernet address from EEPROM. */
Simon Glassfd1e9592017-08-03 12:22:11 -0600230 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasutf91c09a2014-10-24 23:39:07 +0200231
232 return ret;
233}