blob: 3220727f236601a4e5c76af1f0a0ec444f56c0fd [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
Simon Glass1ab16922022-07-31 12:28:48 -06008#include <display_options.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +02009#include <dm.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -070010#include <eeprom.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +020014#include <dm/device-internal.h>
15#include <ahci.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060016#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090017#include <linux/errno.h>
Marek Vasut408368f2014-10-24 23:39:07 +020018#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>
Stefano Babic33731bc2017-06-29 10:16:06 +020026#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>
Marek Vasut91cb3b02019-05-17 20:32:17 +020031#include <dwc_ahsata.h>
Yangbo Lu73340382019-06-21 11:42:28 +080032#include <fsl_esdhc_imx.h>
Marek Vasut408368f2014-10-24 23:39:07 +020033#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>
Marek Vasut408368f2014-10-24 23:39:07 +020039#include <mmc.h>
40#include <netdev.h>
41#include <power/pmic.h>
42#include <power/pfuze100_pmic.h>
43#include <stdio_dev.h>
Marek Vasut6e303202019-05-17 20:32:20 +020044#include <video_console.h>
Marek Vasut408368f2014-10-24 23:39:07 +020045
Marek Vasut3653e972014-12-16 14:09:21 +010046#include "novena.h"
Marek Vasut408368f2014-10-24 23:39:07 +020047
Marek Vasut3653e972014-12-16 14:09:21 +010048DECLARE_GLOBAL_DATA_PTR;
Marek Vasut408368f2014-10-24 23:39:07 +020049
Marek Vasut408368f2014-10-24 23:39:07 +020050int board_early_init_f(void)
51{
52#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut5da39bf2014-12-16 14:09:22 +010053 setup_display_clock();
Marek Vasut408368f2014-10-24 23:39:07 +020054#endif
55
Marek Vasut408368f2014-10-24 23:39:07 +020056 return 0;
57}
58
59int board_init(void)
60{
61 /* address of boot parameters */
62 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
63
Marek Vasut408368f2014-10-24 23:39:07 +020064 return 0;
65}
66
Marek Vasut7d4dcba2014-12-16 14:09:23 +010067int board_late_init(void)
68{
69#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut6e303202019-05-17 20:32:20 +020070 struct udevice *con;
71 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
72 int ret;
73
Marek Vasut7d4dcba2014-12-16 14:09:23 +010074 setup_display_lvds();
Marek Vasut6e303202019-05-17 20:32:20 +020075
76 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
77 if (ret)
78 return ret;
79
80 display_options_get_banner(false, buf, sizeof(buf));
81 vidconsole_position_cursor(con, 0, 0);
82 vidconsole_put_string(con, buf);
Marek Vasut7d4dcba2014-12-16 14:09:23 +010083#endif
84 return 0;
85}
86
Marek Vasut408368f2014-10-24 23:39:07 +020087int checkboard(void)
88{
89 puts("Board: Novena 4x\n");
90 return 0;
91}
92
93int dram_init(void)
94{
95 gd->ram_size = imx_ddr_size();
96 return 0;
97}
98
99/* setup board specific PMIC */
100int power_init_board(void)
101{
102 struct pmic *p;
103 u32 reg;
104 int ret;
105
106 power_pfuze100_init(1);
107 p = pmic_get("PFUZE100");
108 if (!p)
109 return -EINVAL;
110
111 ret = pmic_probe(p);
112 if (ret)
113 return ret;
114
115 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
116 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
117
118 /* Set SWBST to 5.0V and enable (for USB) */
119 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
120 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut2aaeb912015-11-26 14:08:50 +0100121 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasut408368f2014-10-24 23:39:07 +0200122 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
123
124 return 0;
125}
126
127/* EEPROM configuration data */
128struct novena_eeprom_data {
129 uint8_t signature[6];
130 uint8_t version;
131 uint8_t reserved;
132 uint32_t serial;
133 uint8_t mac[6];
134 uint16_t features;
135};
136
137int misc_init_r(void)
138{
139 struct novena_eeprom_data data;
140 uchar *datap = (uchar *)&data;
141 const char *signature = "Novena";
142 int ret;
143
144 /* If 'ethaddr' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -0600145 if (env_get("ethaddr"))
Marek Vasut408368f2014-10-24 23:39:07 +0200146 return 0;
147
148 /* EEPROM is at bus 2. */
149 ret = i2c_set_bus_num(2);
150 if (ret) {
151 puts("Cannot select EEPROM I2C bus.\n");
152 return 0;
153 }
154
155 /* EEPROM is at address 0x56. */
156 ret = eeprom_read(0x56, 0, datap, sizeof(data));
157 if (ret) {
158 puts("Cannot read I2C EEPROM.\n");
159 return 0;
160 }
161
162 /* Check EEPROM signature. */
163 if (memcmp(data.signature, signature, 6)) {
164 puts("Invalid I2C EEPROM signature.\n");
165 return 0;
166 }
167
168 /* Set ethernet address from EEPROM. */
Simon Glass8551d552017-08-03 12:22:11 -0600169 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasut408368f2014-10-24 23:39:07 +0200170
171 return ret;
172}