blob: 0750c4667ee5859ad24629b245d0d728aaee3c7a [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>
Masahiro Yamada56a931c2016-09-21 11:28:55 +09009#include <linux/errno.h>
Marek Vasut408368f2014-10-24 23:39:07 +020010#include <asm/gpio.h>
11#include <asm/io.h>
12#include <asm/arch/clock.h>
13#include <asm/arch/crm_regs.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/iomux.h>
16#include <asm/arch/mxc_hdmi.h>
17#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/boot_mode.h>
19#include <asm/mach-imx/iomux-v3.h>
20#include <asm/mach-imx/mxc_i2c.h>
21#include <asm/mach-imx/sata.h>
22#include <asm/mach-imx/video.h>
Alex Kiernan9c215492018-04-01 09:22:38 +000023#include <environment.h>
Marek Vasut408368f2014-10-24 23:39:07 +020024#include <fsl_esdhc.h>
25#include <i2c.h>
26#include <input.h>
27#include <ipu_pixfmt.h>
28#include <linux/fb.h>
29#include <linux/input.h>
30#include <malloc.h>
31#include <micrel.h>
32#include <miiphy.h>
33#include <mmc.h>
34#include <netdev.h>
35#include <power/pmic.h>
36#include <power/pfuze100_pmic.h>
37#include <stdio_dev.h>
38
Marek Vasut3653e972014-12-16 14:09:21 +010039#include "novena.h"
Marek Vasut408368f2014-10-24 23:39:07 +020040
Marek Vasut3653e972014-12-16 14:09:21 +010041DECLARE_GLOBAL_DATA_PTR;
Marek Vasut408368f2014-10-24 23:39:07 +020042
43/*
44 * GPIO button
45 */
46#ifdef CONFIG_KEYBOARD
47static struct input_config button_input;
48
49static int novena_gpio_button_read_keys(struct input_config *input)
50{
51 int key = KEY_ENTER;
52 if (gpio_get_value(NOVENA_BUTTON_GPIO))
53 return 0;
54 input_send_keycodes(&button_input, &key, 1);
55 return 1;
56}
57
58static int novena_gpio_button_getc(struct stdio_dev *dev)
59{
60 return input_getc(&button_input);
61}
62
63static int novena_gpio_button_tstc(struct stdio_dev *dev)
64{
65 return input_tstc(&button_input);
66}
67
68static int novena_gpio_button_init(struct stdio_dev *dev)
69{
70 gpio_direction_input(NOVENA_BUTTON_GPIO);
71 input_set_delays(&button_input, 250, 250);
72 return 0;
73}
74
75int drv_keyboard_init(void)
76{
77 int error;
78 struct stdio_dev dev = {
79 .name = "button",
Bin Meng6abe4b62015-11-03 23:23:37 -080080 .flags = DEV_FLAGS_INPUT,
Marek Vasut408368f2014-10-24 23:39:07 +020081 .start = novena_gpio_button_init,
82 .getc = novena_gpio_button_getc,
83 .tstc = novena_gpio_button_tstc,
84 };
85
Marek Vasut7149cc82019-05-17 20:32:16 +020086 gpio_request(NOVENA_BUTTON_GPIO, "button");
87
Marek Vasut408368f2014-10-24 23:39:07 +020088 error = input_init(&button_input, 0);
89 if (error) {
90 debug("%s: Cannot set up input\n", __func__);
91 return -1;
92 }
Simon Glasse6fa4852015-11-11 10:05:37 -070093 input_add_tables(&button_input, false);
Marek Vasut408368f2014-10-24 23:39:07 +020094 button_input.read_keys = novena_gpio_button_read_keys;
95
96 error = input_stdio_register(&dev);
97 if (error)
98 return error;
99
100 return 0;
101}
102#endif
103
104/*
105 * SDHC
106 */
107#ifdef CONFIG_FSL_ESDHC
108static struct fsl_esdhc_cfg usdhc_cfg[] = {
109 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */
110 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */
111};
112
113int board_mmc_getcd(struct mmc *mmc)
114{
115 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
116
117 /* There is no CD for a microSD card, assume always present. */
118 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
119 return 1;
120 else
121 return !gpio_get_value(NOVENA_SD_CD);
122}
123
124int board_mmc_getwp(struct mmc *mmc)
125{
126 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
127
128 /* There is no WP for a microSD card, assume always read-write. */
129 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
130 return 0;
131 else
132 return gpio_get_value(NOVENA_SD_WP);
133}
134
135
136int board_mmc_init(bd_t *bis)
137{
138 s32 status = 0;
139 int index;
140
141 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
142 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
143
144 /* Big SD write-protect and card-detect */
145 gpio_direction_input(NOVENA_SD_WP);
146 gpio_direction_input(NOVENA_SD_CD);
147
148 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
149 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
150 if (status)
151 return status;
152 }
153
154 return status;
155}
156#endif
157
Marek Vasut408368f2014-10-24 23:39:07 +0200158int board_early_init_f(void)
159{
160#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut5da39bf2014-12-16 14:09:22 +0100161 setup_display_clock();
Marek Vasut408368f2014-10-24 23:39:07 +0200162#endif
163
Marek Vasut408368f2014-10-24 23:39:07 +0200164 return 0;
165}
166
167int board_init(void)
168{
169 /* address of boot parameters */
170 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
171
Simon Glassab3055a2017-06-14 21:28:25 -0600172#ifdef CONFIG_SATA
Marek Vasut408368f2014-10-24 23:39:07 +0200173 setup_sata();
174#endif
175
176 return 0;
177}
178
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100179int board_late_init(void)
180{
181#if defined(CONFIG_VIDEO_IPUV3)
182 setup_display_lvds();
183#endif
184 return 0;
185}
186
Marek Vasut408368f2014-10-24 23:39:07 +0200187int checkboard(void)
188{
189 puts("Board: Novena 4x\n");
190 return 0;
191}
192
193int dram_init(void)
194{
195 gd->ram_size = imx_ddr_size();
196 return 0;
197}
198
199/* setup board specific PMIC */
200int power_init_board(void)
201{
202 struct pmic *p;
203 u32 reg;
204 int ret;
205
206 power_pfuze100_init(1);
207 p = pmic_get("PFUZE100");
208 if (!p)
209 return -EINVAL;
210
211 ret = pmic_probe(p);
212 if (ret)
213 return ret;
214
215 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
216 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
217
218 /* Set SWBST to 5.0V and enable (for USB) */
219 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
220 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut2aaeb912015-11-26 14:08:50 +0100221 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasut408368f2014-10-24 23:39:07 +0200222 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
223
224 return 0;
225}
226
227/* EEPROM configuration data */
228struct novena_eeprom_data {
229 uint8_t signature[6];
230 uint8_t version;
231 uint8_t reserved;
232 uint32_t serial;
233 uint8_t mac[6];
234 uint16_t features;
235};
236
237int misc_init_r(void)
238{
239 struct novena_eeprom_data data;
240 uchar *datap = (uchar *)&data;
241 const char *signature = "Novena";
242 int ret;
243
244 /* If 'ethaddr' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -0600245 if (env_get("ethaddr"))
Marek Vasut408368f2014-10-24 23:39:07 +0200246 return 0;
247
248 /* EEPROM is at bus 2. */
249 ret = i2c_set_bus_num(2);
250 if (ret) {
251 puts("Cannot select EEPROM I2C bus.\n");
252 return 0;
253 }
254
255 /* EEPROM is at address 0x56. */
256 ret = eeprom_read(0x56, 0, datap, sizeof(data));
257 if (ret) {
258 puts("Cannot read I2C EEPROM.\n");
259 return 0;
260 }
261
262 /* Check EEPROM signature. */
263 if (memcmp(data.signature, signature, 6)) {
264 puts("Invalid I2C EEPROM signature.\n");
265 return 0;
266 }
267
268 /* Set ethernet address from EEPROM. */
Simon Glass8551d552017-08-03 12:22:11 -0600269 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasut408368f2014-10-24 23:39:07 +0200270
271 return ret;
272}