blob: d897f8f1cd8d6da5d6f304855292821b99ff48a1 [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>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090012#include <linux/errno.h>
Marek Vasut408368f2014-10-24 23:39:07 +020013#include <asm/gpio.h>
14#include <asm/io.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/crm_regs.h>
17#include <asm/arch/imx-regs.h>
18#include <asm/arch/iomux.h>
19#include <asm/arch/mxc_hdmi.h>
20#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020021#include <asm/mach-imx/boot_mode.h>
22#include <asm/mach-imx/iomux-v3.h>
23#include <asm/mach-imx/mxc_i2c.h>
24#include <asm/mach-imx/sata.h>
25#include <asm/mach-imx/video.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +020026#include <dwc_ahsata.h>
Alex Kiernan9c215492018-04-01 09:22:38 +000027#include <environment.h>
Marek Vasut408368f2014-10-24 23:39:07 +020028#include <fsl_esdhc.h>
29#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>
42
Marek Vasut3653e972014-12-16 14:09:21 +010043#include "novena.h"
Marek Vasut408368f2014-10-24 23:39:07 +020044
Marek Vasut3653e972014-12-16 14:09:21 +010045DECLARE_GLOBAL_DATA_PTR;
Marek Vasut408368f2014-10-24 23:39:07 +020046
47/*
48 * GPIO button
49 */
50#ifdef CONFIG_KEYBOARD
51static struct input_config button_input;
52
53static int novena_gpio_button_read_keys(struct input_config *input)
54{
55 int key = KEY_ENTER;
56 if (gpio_get_value(NOVENA_BUTTON_GPIO))
57 return 0;
58 input_send_keycodes(&button_input, &key, 1);
59 return 1;
60}
61
62static int novena_gpio_button_getc(struct stdio_dev *dev)
63{
64 return input_getc(&button_input);
65}
66
67static int novena_gpio_button_tstc(struct stdio_dev *dev)
68{
69 return input_tstc(&button_input);
70}
71
72static int novena_gpio_button_init(struct stdio_dev *dev)
73{
74 gpio_direction_input(NOVENA_BUTTON_GPIO);
75 input_set_delays(&button_input, 250, 250);
76 return 0;
77}
78
79int drv_keyboard_init(void)
80{
81 int error;
82 struct stdio_dev dev = {
83 .name = "button",
Bin Meng6abe4b62015-11-03 23:23:37 -080084 .flags = DEV_FLAGS_INPUT,
Marek Vasut408368f2014-10-24 23:39:07 +020085 .start = novena_gpio_button_init,
86 .getc = novena_gpio_button_getc,
87 .tstc = novena_gpio_button_tstc,
88 };
89
Marek Vasut7149cc82019-05-17 20:32:16 +020090 gpio_request(NOVENA_BUTTON_GPIO, "button");
91
Marek Vasut408368f2014-10-24 23:39:07 +020092 error = input_init(&button_input, 0);
93 if (error) {
94 debug("%s: Cannot set up input\n", __func__);
95 return -1;
96 }
Simon Glasse6fa4852015-11-11 10:05:37 -070097 input_add_tables(&button_input, false);
Marek Vasut408368f2014-10-24 23:39:07 +020098 button_input.read_keys = novena_gpio_button_read_keys;
99
100 error = input_stdio_register(&dev);
101 if (error)
102 return error;
103
104 return 0;
105}
106#endif
107
Marek Vasut408368f2014-10-24 23:39:07 +0200108int board_early_init_f(void)
109{
110#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut5da39bf2014-12-16 14:09:22 +0100111 setup_display_clock();
Marek Vasut408368f2014-10-24 23:39:07 +0200112#endif
113
Marek Vasut408368f2014-10-24 23:39:07 +0200114 return 0;
115}
116
117int board_init(void)
118{
119 /* address of boot parameters */
120 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
121
Marek Vasut408368f2014-10-24 23:39:07 +0200122 return 0;
123}
124
Marek Vasut7d4dcba2014-12-16 14:09:23 +0100125int board_late_init(void)
126{
127#if defined(CONFIG_VIDEO_IPUV3)
128 setup_display_lvds();
129#endif
130 return 0;
131}
132
Marek Vasut408368f2014-10-24 23:39:07 +0200133int checkboard(void)
134{
135 puts("Board: Novena 4x\n");
136 return 0;
137}
138
139int dram_init(void)
140{
141 gd->ram_size = imx_ddr_size();
142 return 0;
143}
144
145/* setup board specific PMIC */
146int power_init_board(void)
147{
148 struct pmic *p;
149 u32 reg;
150 int ret;
151
152 power_pfuze100_init(1);
153 p = pmic_get("PFUZE100");
154 if (!p)
155 return -EINVAL;
156
157 ret = pmic_probe(p);
158 if (ret)
159 return ret;
160
161 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
162 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
163
164 /* Set SWBST to 5.0V and enable (for USB) */
165 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
166 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut2aaeb912015-11-26 14:08:50 +0100167 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasut408368f2014-10-24 23:39:07 +0200168 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
169
170 return 0;
171}
172
173/* EEPROM configuration data */
174struct novena_eeprom_data {
175 uint8_t signature[6];
176 uint8_t version;
177 uint8_t reserved;
178 uint32_t serial;
179 uint8_t mac[6];
180 uint16_t features;
181};
182
183int misc_init_r(void)
184{
185 struct novena_eeprom_data data;
186 uchar *datap = (uchar *)&data;
187 const char *signature = "Novena";
188 int ret;
189
190 /* If 'ethaddr' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -0600191 if (env_get("ethaddr"))
Marek Vasut408368f2014-10-24 23:39:07 +0200192 return 0;
193
194 /* EEPROM is at bus 2. */
195 ret = i2c_set_bus_num(2);
196 if (ret) {
197 puts("Cannot select EEPROM I2C bus.\n");
198 return 0;
199 }
200
201 /* EEPROM is at address 0x56. */
202 ret = eeprom_read(0x56, 0, datap, sizeof(data));
203 if (ret) {
204 puts("Cannot read I2C EEPROM.\n");
205 return 0;
206 }
207
208 /* Check EEPROM signature. */
209 if (memcmp(data.signature, signature, 6)) {
210 puts("Invalid I2C EEPROM signature.\n");
211 return 0;
212 }
213
214 /* Set ethernet address from EEPROM. */
Simon Glass8551d552017-08-03 12:22:11 -0600215 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasut408368f2014-10-24 23:39:07 +0200216
217 return ret;
218}