blob: 815ecf55c4df005ac0641a214b0b339823f5ed9e [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>
Simon Glass4e4bf942022-07-31 12:28:48 -06009#include <display_options.h>
Marek Vasut6b98b942019-05-17 20:32:17 +020010#include <dm.h>
Simon Glasscb3ef682019-11-14 12:57:50 -070011#include <eeprom.h>
Simon Glass52559322019-11-14 12:57:46 -070012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Simon Glass401d1c42020-10-30 21:38:53 -060014#include <asm/global_data.h>
Marek Vasut6b98b942019-05-17 20:32:17 +020015#include <dm/device-internal.h>
16#include <ahci.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060017#include <env.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090018#include <linux/errno.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020019#include <asm/gpio.h>
20#include <asm/io.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/crm_regs.h>
23#include <asm/arch/imx-regs.h>
24#include <asm/arch/iomux.h>
25#include <asm/arch/mxc_hdmi.h>
26#include <asm/arch/sys_proto.h>
Stefano Babic552a8482017-06-29 10:16:06 +020027#include <asm/mach-imx/boot_mode.h>
28#include <asm/mach-imx/iomux-v3.h>
29#include <asm/mach-imx/mxc_i2c.h>
30#include <asm/mach-imx/sata.h>
31#include <asm/mach-imx/video.h>
Marek Vasut6b98b942019-05-17 20:32:17 +020032#include <dwc_ahsata.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080033#include <fsl_esdhc_imx.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020034#include <i2c.h>
35#include <input.h>
36#include <ipu_pixfmt.h>
37#include <linux/fb.h>
38#include <linux/input.h>
39#include <malloc.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020040#include <mmc.h>
41#include <netdev.h>
42#include <power/pmic.h>
43#include <power/pfuze100_pmic.h>
44#include <stdio_dev.h>
Marek Vasut2f1c06c2019-05-17 20:32:20 +020045#include <video_console.h>
Marek Vasutf91c09a2014-10-24 23:39:07 +020046
Marek Vasutd59d7b92014-12-16 14:09:21 +010047#include "novena.h"
Marek Vasutf91c09a2014-10-24 23:39:07 +020048
Marek Vasutd59d7b92014-12-16 14:09:21 +010049DECLARE_GLOBAL_DATA_PTR;
Marek Vasutf91c09a2014-10-24 23:39:07 +020050
51/*
52 * GPIO button
53 */
54#ifdef CONFIG_KEYBOARD
55static struct input_config button_input;
56
57static int novena_gpio_button_read_keys(struct input_config *input)
58{
59 int key = KEY_ENTER;
60 if (gpio_get_value(NOVENA_BUTTON_GPIO))
61 return 0;
62 input_send_keycodes(&button_input, &key, 1);
63 return 1;
64}
65
66static int novena_gpio_button_getc(struct stdio_dev *dev)
67{
68 return input_getc(&button_input);
69}
70
71static int novena_gpio_button_tstc(struct stdio_dev *dev)
72{
73 return input_tstc(&button_input);
74}
75
76static int novena_gpio_button_init(struct stdio_dev *dev)
77{
78 gpio_direction_input(NOVENA_BUTTON_GPIO);
79 input_set_delays(&button_input, 250, 250);
80 return 0;
81}
82
83int drv_keyboard_init(void)
84{
85 int error;
86 struct stdio_dev dev = {
87 .name = "button",
Bin Meng1caf9342015-11-03 23:23:37 -080088 .flags = DEV_FLAGS_INPUT,
Marek Vasutf91c09a2014-10-24 23:39:07 +020089 .start = novena_gpio_button_init,
90 .getc = novena_gpio_button_getc,
91 .tstc = novena_gpio_button_tstc,
92 };
93
Marek Vasutc4e93f62019-05-17 20:32:16 +020094 gpio_request(NOVENA_BUTTON_GPIO, "button");
95
Marek Vasutf91c09a2014-10-24 23:39:07 +020096 error = input_init(&button_input, 0);
97 if (error) {
98 debug("%s: Cannot set up input\n", __func__);
99 return -1;
100 }
Simon Glassb1d7a182015-11-11 10:05:37 -0700101 input_add_tables(&button_input, false);
Marek Vasutf91c09a2014-10-24 23:39:07 +0200102 button_input.read_keys = novena_gpio_button_read_keys;
103
104 error = input_stdio_register(&dev);
105 if (error)
106 return error;
107
108 return 0;
109}
110#endif
111
Marek Vasutf91c09a2014-10-24 23:39:07 +0200112int board_early_init_f(void)
113{
114#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasutf2e4d6a2014-12-16 14:09:22 +0100115 setup_display_clock();
Marek Vasutf91c09a2014-10-24 23:39:07 +0200116#endif
117
Marek Vasutf91c09a2014-10-24 23:39:07 +0200118 return 0;
119}
120
121int board_init(void)
122{
123 /* address of boot parameters */
124 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
125
Marek Vasutf91c09a2014-10-24 23:39:07 +0200126 return 0;
127}
128
Marek Vasut331ae842014-12-16 14:09:23 +0100129int board_late_init(void)
130{
131#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut2f1c06c2019-05-17 20:32:20 +0200132 struct udevice *con;
133 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
134 int ret;
135
Marek Vasut331ae842014-12-16 14:09:23 +0100136 setup_display_lvds();
Marek Vasut2f1c06c2019-05-17 20:32:20 +0200137
138 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
139 if (ret)
140 return ret;
141
142 display_options_get_banner(false, buf, sizeof(buf));
143 vidconsole_position_cursor(con, 0, 0);
144 vidconsole_put_string(con, buf);
Marek Vasut331ae842014-12-16 14:09:23 +0100145#endif
146 return 0;
147}
148
Marek Vasutf91c09a2014-10-24 23:39:07 +0200149int checkboard(void)
150{
151 puts("Board: Novena 4x\n");
152 return 0;
153}
154
155int dram_init(void)
156{
157 gd->ram_size = imx_ddr_size();
158 return 0;
159}
160
161/* setup board specific PMIC */
162int power_init_board(void)
163{
164 struct pmic *p;
165 u32 reg;
166 int ret;
167
168 power_pfuze100_init(1);
169 p = pmic_get("PFUZE100");
170 if (!p)
171 return -EINVAL;
172
173 ret = pmic_probe(p);
174 if (ret)
175 return ret;
176
177 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
178 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
179
180 /* Set SWBST to 5.0V and enable (for USB) */
181 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
182 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut18e02ff2015-11-26 14:08:50 +0100183 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasutf91c09a2014-10-24 23:39:07 +0200184 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
185
186 return 0;
187}
188
189/* EEPROM configuration data */
190struct novena_eeprom_data {
191 uint8_t signature[6];
192 uint8_t version;
193 uint8_t reserved;
194 uint32_t serial;
195 uint8_t mac[6];
196 uint16_t features;
197};
198
199int misc_init_r(void)
200{
201 struct novena_eeprom_data data;
202 uchar *datap = (uchar *)&data;
203 const char *signature = "Novena";
204 int ret;
205
206 /* If 'ethaddr' is already set, do nothing. */
Simon Glass00caae62017-08-03 12:22:12 -0600207 if (env_get("ethaddr"))
Marek Vasutf91c09a2014-10-24 23:39:07 +0200208 return 0;
209
210 /* EEPROM is at bus 2. */
211 ret = i2c_set_bus_num(2);
212 if (ret) {
213 puts("Cannot select EEPROM I2C bus.\n");
214 return 0;
215 }
216
217 /* EEPROM is at address 0x56. */
218 ret = eeprom_read(0x56, 0, datap, sizeof(data));
219 if (ret) {
220 puts("Cannot read I2C EEPROM.\n");
221 return 0;
222 }
223
224 /* Check EEPROM signature. */
225 if (memcmp(data.signature, signature, 6)) {
226 puts("Invalid I2C EEPROM signature.\n");
227 return 0;
228 }
229
230 /* Set ethernet address from EEPROM. */
Simon Glassfd1e9592017-08-03 12:22:11 -0600231 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasutf91c09a2014-10-24 23:39:07 +0200232
233 return ret;
234}