blob: b7b747d196583f812195ec999e34c3e8135fcc52 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Marek Vasut408368f2014-10-24 23:39:07 +02002/*
3 * Novena board support
4 *
5 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
Marek Vasut408368f2014-10-24 23:39:07 +02006 */
7
8#include <common.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +02009#include <dm.h>
10#include <dm/device-internal.h>
11#include <ahci.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060012#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090013#include <linux/errno.h>
Marek Vasut408368f2014-10-24 23:39:07 +020014#include <asm/gpio.h>
15#include <asm/io.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/crm_regs.h>
18#include <asm/arch/imx-regs.h>
19#include <asm/arch/iomux.h>
20#include <asm/arch/mxc_hdmi.h>
21#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020022#include <asm/mach-imx/boot_mode.h>
23#include <asm/mach-imx/iomux-v3.h>
24#include <asm/mach-imx/mxc_i2c.h>
25#include <asm/mach-imx/sata.h>
26#include <asm/mach-imx/video.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +020027#include <dwc_ahsata.h>
Yangbo Lu73340382019-06-21 11:42:28 +080028#include <fsl_esdhc_imx.h>
Marek Vasut408368f2014-10-24 23:39:07 +020029#include <i2c.h>
30#include <input.h>
31#include <ipu_pixfmt.h>
32#include <linux/fb.h>
33#include <linux/input.h>
34#include <malloc.h>
35#include <micrel.h>
36#include <miiphy.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>
Marek Vasut6e303202019-05-17 20:32:20 +020042#include <video_console.h>
Marek Vasut408368f2014-10-24 23:39:07 +020043
Marek Vasut3653e972014-12-16 14:09:21 +010044#include "novena.h"
Marek Vasut408368f2014-10-24 23:39:07 +020045
Marek Vasut3653e972014-12-16 14:09:21 +010046DECLARE_GLOBAL_DATA_PTR;
Marek Vasut408368f2014-10-24 23:39:07 +020047
48/*
49 * GPIO button
50 */
51#ifdef CONFIG_KEYBOARD
52static struct input_config button_input;
53
54static 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
63static int novena_gpio_button_getc(struct stdio_dev *dev)
64{
65 return input_getc(&button_input);
66}
67
68static int novena_gpio_button_tstc(struct stdio_dev *dev)
69{
70 return input_tstc(&button_input);
71}
72
73static 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
80int drv_keyboard_init(void)
81{
82 int error;
83 struct stdio_dev dev = {
84 .name = "button",
Bin Meng6abe4b62015-11-03 23:23:37 -080085 .flags = DEV_FLAGS_INPUT,
Marek Vasut408368f2014-10-24 23:39:07 +020086 .start = novena_gpio_button_init,
87 .getc = novena_gpio_button_getc,
88 .tstc = novena_gpio_button_tstc,
89 };
90
Marek Vasut7149cc82019-05-17 20:32:16 +020091 gpio_request(NOVENA_BUTTON_GPIO, "button");
92
Marek Vasut408368f2014-10-24 23:39:07 +020093 error = input_init(&button_input, 0);
94 if (error) {
95 debug("%s: Cannot set up input\n", __func__);
96 return -1;
97 }
Simon Glasse6fa4852015-11-11 10:05:37 -070098 input_add_tables(&button_input, false);
Marek Vasut408368f2014-10-24 23:39:07 +020099 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
Marek Vasut408368f2014-10-24 23:39:07 +0200109int board_early_init_f(void)
110{
111#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut5da39bf2014-12-16 14:09:22 +0100112 setup_display_clock();
Marek Vasut408368f2014-10-24 23:39:07 +0200113#endif
114
Marek Vasut408368f2014-10-24 23:39:07 +0200115 return 0;
116}
117
118int board_init(void)
119{
120 /* address of boot parameters */
121 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
122
Marek Vasut408368f2014-10-24 23:39:07 +0200123 return 0;
124}
125
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100126int board_late_init(void)
127{
128#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut6e303202019-05-17 20:32:20 +0200129 struct udevice *con;
130 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
131 int ret;
132
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100133 setup_display_lvds();
Marek Vasut6e303202019-05-17 20:32:20 +0200134
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);
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100142#endif
143 return 0;
144}
145
Marek Vasut408368f2014-10-24 23:39:07 +0200146int checkboard(void)
147{
148 puts("Board: Novena 4x\n");
149 return 0;
150}
151
152int dram_init(void)
153{
154 gd->ram_size = imx_ddr_size();
155 return 0;
156}
157
158/* setup board specific PMIC */
159int 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, &reg);
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, &reg);
179 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut2aaeb912015-11-26 14:08:50 +0100180 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasut408368f2014-10-24 23:39:07 +0200181 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
182
183 return 0;
184}
185
186/* EEPROM configuration data */
187struct 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
196int 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. */
Simon Glass64b723f2017-08-03 12:22:12 -0600204 if (env_get("ethaddr"))
Marek Vasut408368f2014-10-24 23:39:07 +0200205 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. */
Simon Glass8551d552017-08-03 12:22:11 -0600228 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasut408368f2014-10-24 23:39:07 +0200229
230 return ret;
231}