]> git.ipfire.org Git - thirdparty/u-boot.git/blame - board/kosagi/novena/novena.c
common: Drop asm/global_data.h from common header
[thirdparty/u-boot.git] / board / kosagi / novena / novena.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
f91c09ac
MV
2/*
3 * Novena board support
4 *
5 * Copyright (C) 2014 Marek Vasut <marex@denx.de>
f91c09ac
MV
6 */
7
8#include <common.h>
6b98b94c 9#include <dm.h>
cb3ef681 10#include <eeprom.h>
5255932f 11#include <init.h>
f7ae49fc 12#include <log.h>
401d1c4f 13#include <asm/global_data.h>
6b98b94c
MV
14#include <dm/device-internal.h>
15#include <ahci.h>
9fb625ce 16#include <env.h>
1221ce45 17#include <linux/errno.h>
f91c09ac
MV
18#include <asm/gpio.h>
19#include <asm/io.h>
20#include <asm/arch/clock.h>
21#include <asm/arch/crm_regs.h>
22#include <asm/arch/imx-regs.h>
23#include <asm/arch/iomux.h>
24#include <asm/arch/mxc_hdmi.h>
25#include <asm/arch/sys_proto.h>
552a848e
SB
26#include <asm/mach-imx/boot_mode.h>
27#include <asm/mach-imx/iomux-v3.h>
28#include <asm/mach-imx/mxc_i2c.h>
29#include <asm/mach-imx/sata.h>
30#include <asm/mach-imx/video.h>
6b98b94c 31#include <dwc_ahsata.h>
e37ac717 32#include <fsl_esdhc_imx.h>
f91c09ac
MV
33#include <i2c.h>
34#include <input.h>
35#include <ipu_pixfmt.h>
36#include <linux/fb.h>
37#include <linux/input.h>
38#include <malloc.h>
f91c09ac
MV
39#include <mmc.h>
40#include <netdev.h>
41#include <power/pmic.h>
42#include <power/pfuze100_pmic.h>
43#include <stdio_dev.h>
2f1c06c7 44#include <video_console.h>
f91c09ac 45
d59d7b91 46#include "novena.h"
f91c09ac 47
d59d7b91 48DECLARE_GLOBAL_DATA_PTR;
f91c09ac
MV
49
50/*
51 * GPIO button
52 */
53#ifdef CONFIG_KEYBOARD
54static struct input_config button_input;
55
56static int novena_gpio_button_read_keys(struct input_config *input)
57{
58 int key = KEY_ENTER;
59 if (gpio_get_value(NOVENA_BUTTON_GPIO))
60 return 0;
61 input_send_keycodes(&button_input, &key, 1);
62 return 1;
63}
64
65static int novena_gpio_button_getc(struct stdio_dev *dev)
66{
67 return input_getc(&button_input);
68}
69
70static int novena_gpio_button_tstc(struct stdio_dev *dev)
71{
72 return input_tstc(&button_input);
73}
74
75static int novena_gpio_button_init(struct stdio_dev *dev)
76{
77 gpio_direction_input(NOVENA_BUTTON_GPIO);
78 input_set_delays(&button_input, 250, 250);
79 return 0;
80}
81
82int drv_keyboard_init(void)
83{
84 int error;
85 struct stdio_dev dev = {
86 .name = "button",
1caf934a 87 .flags = DEV_FLAGS_INPUT,
f91c09ac
MV
88 .start = novena_gpio_button_init,
89 .getc = novena_gpio_button_getc,
90 .tstc = novena_gpio_button_tstc,
91 };
92
c4e93f6a
MV
93 gpio_request(NOVENA_BUTTON_GPIO, "button");
94
f91c09ac
MV
95 error = input_init(&button_input, 0);
96 if (error) {
97 debug("%s: Cannot set up input\n", __func__);
98 return -1;
99 }
b1d7a187 100 input_add_tables(&button_input, false);
f91c09ac
MV
101 button_input.read_keys = novena_gpio_button_read_keys;
102
103 error = input_stdio_register(&dev);
104 if (error)
105 return error;
106
107 return 0;
108}
109#endif
110
f91c09ac
MV
111int board_early_init_f(void)
112{
113#if defined(CONFIG_VIDEO_IPUV3)
f2e4d6a5 114 setup_display_clock();
f91c09ac
MV
115#endif
116
f91c09ac
MV
117 return 0;
118}
119
120int board_init(void)
121{
122 /* address of boot parameters */
123 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
124
f91c09ac
MV
125 return 0;
126}
127
331ae846
MV
128int board_late_init(void)
129{
130#if defined(CONFIG_VIDEO_IPUV3)
2f1c06c7
MV
131 struct udevice *con;
132 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
133 int ret;
134
331ae846 135 setup_display_lvds();
2f1c06c7
MV
136
137 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
138 if (ret)
139 return ret;
140
141 display_options_get_banner(false, buf, sizeof(buf));
142 vidconsole_position_cursor(con, 0, 0);
143 vidconsole_put_string(con, buf);
331ae846
MV
144#endif
145 return 0;
146}
147
f91c09ac
MV
148int checkboard(void)
149{
150 puts("Board: Novena 4x\n");
151 return 0;
152}
153
154int dram_init(void)
155{
156 gd->ram_size = imx_ddr_size();
157 return 0;
158}
159
160/* setup board specific PMIC */
161int power_init_board(void)
162{
163 struct pmic *p;
164 u32 reg;
165 int ret;
166
167 power_pfuze100_init(1);
168 p = pmic_get("PFUZE100");
169 if (!p)
170 return -EINVAL;
171
172 ret = pmic_probe(p);
173 if (ret)
174 return ret;
175
176 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
177 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
178
179 /* Set SWBST to 5.0V and enable (for USB) */
180 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
181 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
18e02ffe 182 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
f91c09ac
MV
183 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
184
185 return 0;
186}
187
188/* EEPROM configuration data */
189struct novena_eeprom_data {
190 uint8_t signature[6];
191 uint8_t version;
192 uint8_t reserved;
193 uint32_t serial;
194 uint8_t mac[6];
195 uint16_t features;
196};
197
198int misc_init_r(void)
199{
200 struct novena_eeprom_data data;
201 uchar *datap = (uchar *)&data;
202 const char *signature = "Novena";
203 int ret;
204
205 /* If 'ethaddr' is already set, do nothing. */
00caae6d 206 if (env_get("ethaddr"))
f91c09ac
MV
207 return 0;
208
209 /* EEPROM is at bus 2. */
210 ret = i2c_set_bus_num(2);
211 if (ret) {
212 puts("Cannot select EEPROM I2C bus.\n");
213 return 0;
214 }
215
216 /* EEPROM is at address 0x56. */
217 ret = eeprom_read(0x56, 0, datap, sizeof(data));
218 if (ret) {
219 puts("Cannot read I2C EEPROM.\n");
220 return 0;
221 }
222
223 /* Check EEPROM signature. */
224 if (memcmp(data.signature, signature, 6)) {
225 puts("Invalid I2C EEPROM signature.\n");
226 return 0;
227 }
228
229 /* Set ethernet address from EEPROM. */
fd1e959e 230 eth_env_set_enetaddr("ethaddr", data.mac);
f91c09ac
MV
231
232 return ret;
233}