blob: b3159d3a95b0e1ee11139e99c9799ea76c568bec [file] [log] [blame]
Marek Vasutf91c09a2014-10-24 23:39:07 +02001/*
2 * Novena board support
3 *
4 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <asm/errno.h>
11#include <asm/gpio.h>
12#include <asm/io.h>
13#include <asm/arch/clock.h>
14#include <asm/arch/crm_regs.h>
15#include <asm/arch/imx-regs.h>
16#include <asm/arch/iomux.h>
17#include <asm/arch/mxc_hdmi.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/imx-common/boot_mode.h>
20#include <asm/imx-common/iomux-v3.h>
21#include <asm/imx-common/mxc_i2c.h>
22#include <asm/imx-common/sata.h>
23#include <asm/imx-common/video.h>
24#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 Vasutd59d7b92014-12-16 14:09:21 +010039#include "novena.h"
Marek Vasutf91c09a2014-10-24 23:39:07 +020040
Marek Vasutd59d7b92014-12-16 14:09:21 +010041DECLARE_GLOBAL_DATA_PTR;
Marek Vasutf91c09a2014-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 Meng1caf9342015-11-03 23:23:37 -080080 .flags = DEV_FLAGS_INPUT,
Marek Vasutf91c09a2014-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
86 error = input_init(&button_input, 0);
87 if (error) {
88 debug("%s: Cannot set up input\n", __func__);
89 return -1;
90 }
Simon Glassb1d7a182015-11-11 10:05:37 -070091 input_add_tables(&button_input, false);
Marek Vasutf91c09a2014-10-24 23:39:07 +020092 button_input.read_keys = novena_gpio_button_read_keys;
93
94 error = input_stdio_register(&dev);
95 if (error)
96 return error;
97
98 return 0;
99}
100#endif
101
102/*
103 * SDHC
104 */
105#ifdef CONFIG_FSL_ESDHC
106static struct fsl_esdhc_cfg usdhc_cfg[] = {
107 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */
108 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */
109};
110
111int board_mmc_getcd(struct mmc *mmc)
112{
113 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
114
115 /* There is no CD for a microSD card, assume always present. */
116 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
117 return 1;
118 else
119 return !gpio_get_value(NOVENA_SD_CD);
120}
121
122int board_mmc_getwp(struct mmc *mmc)
123{
124 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
125
126 /* There is no WP for a microSD card, assume always read-write. */
127 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
128 return 0;
129 else
130 return gpio_get_value(NOVENA_SD_WP);
131}
132
133
134int board_mmc_init(bd_t *bis)
135{
136 s32 status = 0;
137 int index;
138
139 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
140 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
141
142 /* Big SD write-protect and card-detect */
143 gpio_direction_input(NOVENA_SD_WP);
144 gpio_direction_input(NOVENA_SD_CD);
145
146 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
147 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
148 if (status)
149 return status;
150 }
151
152 return status;
153}
154#endif
155
Marek Vasutf91c09a2014-10-24 23:39:07 +0200156int board_early_init_f(void)
157{
158#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasutf2e4d6a2014-12-16 14:09:22 +0100159 setup_display_clock();
Marek Vasutf91c09a2014-10-24 23:39:07 +0200160#endif
161
Marek Vasutf91c09a2014-10-24 23:39:07 +0200162 return 0;
163}
164
165int board_init(void)
166{
167 /* address of boot parameters */
168 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
169
170#ifdef CONFIG_CMD_SATA
171 setup_sata();
172#endif
173
174 return 0;
175}
176
Marek Vasut331ae842014-12-16 14:09:23 +0100177int board_late_init(void)
178{
179#if defined(CONFIG_VIDEO_IPUV3)
180 setup_display_lvds();
181#endif
182 return 0;
183}
184
Marek Vasutf91c09a2014-10-24 23:39:07 +0200185int checkboard(void)
186{
187 puts("Board: Novena 4x\n");
188 return 0;
189}
190
191int dram_init(void)
192{
193 gd->ram_size = imx_ddr_size();
194 return 0;
195}
196
197/* setup board specific PMIC */
198int power_init_board(void)
199{
200 struct pmic *p;
201 u32 reg;
202 int ret;
203
204 power_pfuze100_init(1);
205 p = pmic_get("PFUZE100");
206 if (!p)
207 return -EINVAL;
208
209 ret = pmic_probe(p);
210 if (ret)
211 return ret;
212
213 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
214 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
215
216 /* Set SWBST to 5.0V and enable (for USB) */
217 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
218 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut18e02ff2015-11-26 14:08:50 +0100219 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasutf91c09a2014-10-24 23:39:07 +0200220 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
221
222 return 0;
223}
224
225/* EEPROM configuration data */
226struct novena_eeprom_data {
227 uint8_t signature[6];
228 uint8_t version;
229 uint8_t reserved;
230 uint32_t serial;
231 uint8_t mac[6];
232 uint16_t features;
233};
234
235int misc_init_r(void)
236{
237 struct novena_eeprom_data data;
238 uchar *datap = (uchar *)&data;
239 const char *signature = "Novena";
240 int ret;
241
242 /* If 'ethaddr' is already set, do nothing. */
243 if (getenv("ethaddr"))
244 return 0;
245
246 /* EEPROM is at bus 2. */
247 ret = i2c_set_bus_num(2);
248 if (ret) {
249 puts("Cannot select EEPROM I2C bus.\n");
250 return 0;
251 }
252
253 /* EEPROM is at address 0x56. */
254 ret = eeprom_read(0x56, 0, datap, sizeof(data));
255 if (ret) {
256 puts("Cannot read I2C EEPROM.\n");
257 return 0;
258 }
259
260 /* Check EEPROM signature. */
261 if (memcmp(data.signature, signature, 6)) {
262 puts("Invalid I2C EEPROM signature.\n");
263 return 0;
264 }
265
266 /* Set ethernet address from EEPROM. */
267 eth_setenv_enetaddr("ethaddr", data.mac);
268
269 return ret;
270}