blob: 69f5be3b9c167370e6f83e94424b4e84984c6b3a [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",
80 .flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM,
81 .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 }
91 button_input.read_keys = novena_gpio_button_read_keys;
92
93 error = input_stdio_register(&dev);
94 if (error)
95 return error;
96
97 return 0;
98}
99#endif
100
101/*
102 * SDHC
103 */
104#ifdef CONFIG_FSL_ESDHC
105static struct fsl_esdhc_cfg usdhc_cfg[] = {
106 { USDHC3_BASE_ADDR, 0, 4 }, /* Micro SD */
107 { USDHC2_BASE_ADDR, 0, 4 }, /* Big SD */
108};
109
110int board_mmc_getcd(struct mmc *mmc)
111{
112 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
113
114 /* There is no CD for a microSD card, assume always present. */
115 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
116 return 1;
117 else
118 return !gpio_get_value(NOVENA_SD_CD);
119}
120
121int board_mmc_getwp(struct mmc *mmc)
122{
123 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
124
125 /* There is no WP for a microSD card, assume always read-write. */
126 if (cfg->esdhc_base == USDHC3_BASE_ADDR)
127 return 0;
128 else
129 return gpio_get_value(NOVENA_SD_WP);
130}
131
132
133int board_mmc_init(bd_t *bis)
134{
135 s32 status = 0;
136 int index;
137
138 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
139 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
140
141 /* Big SD write-protect and card-detect */
142 gpio_direction_input(NOVENA_SD_WP);
143 gpio_direction_input(NOVENA_SD_CD);
144
145 for (index = 0; index < ARRAY_SIZE(usdhc_cfg); index++) {
146 status = fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
147 if (status)
148 return status;
149 }
150
151 return status;
152}
153#endif
154
Marek Vasutf91c09a2014-10-24 23:39:07 +0200155int board_early_init_f(void)
156{
157#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasutf2e4d6a2014-12-16 14:09:22 +0100158 setup_display_clock();
Marek Vasutf91c09a2014-10-24 23:39:07 +0200159#endif
160
Marek Vasutf91c09a2014-10-24 23:39:07 +0200161 return 0;
162}
163
164int board_init(void)
165{
166 /* address of boot parameters */
167 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
168
169#ifdef CONFIG_CMD_SATA
170 setup_sata();
171#endif
172
173 return 0;
174}
175
Marek Vasut331ae842014-12-16 14:09:23 +0100176int board_late_init(void)
177{
178#if defined(CONFIG_VIDEO_IPUV3)
179 setup_display_lvds();
180#endif
181 return 0;
182}
183
Marek Vasutf91c09a2014-10-24 23:39:07 +0200184int checkboard(void)
185{
186 puts("Board: Novena 4x\n");
187 return 0;
188}
189
190int dram_init(void)
191{
192 gd->ram_size = imx_ddr_size();
193 return 0;
194}
195
196/* setup board specific PMIC */
197int power_init_board(void)
198{
199 struct pmic *p;
200 u32 reg;
201 int ret;
202
203 power_pfuze100_init(1);
204 p = pmic_get("PFUZE100");
205 if (!p)
206 return -EINVAL;
207
208 ret = pmic_probe(p);
209 if (ret)
210 return ret;
211
212 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
213 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
214
215 /* Set SWBST to 5.0V and enable (for USB) */
216 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
217 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
218 reg |= (SWBST_5_00V | SWBST_MODE_AUTO);
219 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
220
221 return 0;
222}
223
224/* EEPROM configuration data */
225struct novena_eeprom_data {
226 uint8_t signature[6];
227 uint8_t version;
228 uint8_t reserved;
229 uint32_t serial;
230 uint8_t mac[6];
231 uint16_t features;
232};
233
234int misc_init_r(void)
235{
236 struct novena_eeprom_data data;
237 uchar *datap = (uchar *)&data;
238 const char *signature = "Novena";
239 int ret;
240
241 /* If 'ethaddr' is already set, do nothing. */
242 if (getenv("ethaddr"))
243 return 0;
244
245 /* EEPROM is at bus 2. */
246 ret = i2c_set_bus_num(2);
247 if (ret) {
248 puts("Cannot select EEPROM I2C bus.\n");
249 return 0;
250 }
251
252 /* EEPROM is at address 0x56. */
253 ret = eeprom_read(0x56, 0, datap, sizeof(data));
254 if (ret) {
255 puts("Cannot read I2C EEPROM.\n");
256 return 0;
257 }
258
259 /* Check EEPROM signature. */
260 if (memcmp(data.signature, signature, 6)) {
261 puts("Invalid I2C EEPROM signature.\n");
262 return 0;
263 }
264
265 /* Set ethernet address from EEPROM. */
266 eth_setenv_enetaddr("ethaddr", data.mac);
267
268 return ret;
269}