blob: f009a8afd48c32507b3172402a4ae78a6b5affa7 [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>
Simon Glass1ab16922022-07-31 12:28:48 -06009#include <display_options.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +020010#include <dm.h>
Simon Glasseba6b8d2019-11-14 12:57:50 -070011#include <eeprom.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +020015#include <dm/device-internal.h>
16#include <ahci.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060017#include <env.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090018#include <linux/errno.h>
Marek Vasut408368f2014-10-24 23:39:07 +020019#include <asm/gpio.h>
20#include <asm/io.h>
21#include <asm/arch/clock.h>
22#include <asm/arch/crm_regs.h>
23#include <asm/arch/imx-regs.h>
24#include <asm/arch/iomux.h>
25#include <asm/arch/mxc_hdmi.h>
26#include <asm/arch/sys_proto.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020027#include <asm/mach-imx/boot_mode.h>
28#include <asm/mach-imx/iomux-v3.h>
29#include <asm/mach-imx/mxc_i2c.h>
30#include <asm/mach-imx/sata.h>
31#include <asm/mach-imx/video.h>
Marek Vasut91cb3b02019-05-17 20:32:17 +020032#include <dwc_ahsata.h>
Yangbo Lu73340382019-06-21 11:42:28 +080033#include <fsl_esdhc_imx.h>
Marek Vasut408368f2014-10-24 23:39:07 +020034#include <i2c.h>
35#include <input.h>
36#include <ipu_pixfmt.h>
37#include <linux/fb.h>
38#include <linux/input.h>
39#include <malloc.h>
Marek Vasut408368f2014-10-24 23:39:07 +020040#include <mmc.h>
41#include <netdev.h>
42#include <power/pmic.h>
43#include <power/pfuze100_pmic.h>
44#include <stdio_dev.h>
Marek Vasut6e303202019-05-17 20:32:20 +020045#include <video_console.h>
Marek Vasut408368f2014-10-24 23:39:07 +020046
Marek Vasut3653e972014-12-16 14:09:21 +010047#include "novena.h"
Marek Vasut408368f2014-10-24 23:39:07 +020048
Marek Vasut3653e972014-12-16 14:09:21 +010049DECLARE_GLOBAL_DATA_PTR;
Marek Vasut408368f2014-10-24 23:39:07 +020050
Marek Vasut408368f2014-10-24 23:39:07 +020051int board_early_init_f(void)
52{
53#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut5da39bf2014-12-16 14:09:22 +010054 setup_display_clock();
Marek Vasut408368f2014-10-24 23:39:07 +020055#endif
56
Marek Vasut408368f2014-10-24 23:39:07 +020057 return 0;
58}
59
60int board_init(void)
61{
62 /* address of boot parameters */
63 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
64
Marek Vasut408368f2014-10-24 23:39:07 +020065 return 0;
66}
67
Marek Vasut7d4dcba2014-12-16 14:09:23 +010068int board_late_init(void)
69{
70#if defined(CONFIG_VIDEO_IPUV3)
Marek Vasut6e303202019-05-17 20:32:20 +020071 struct udevice *con;
72 char buf[DISPLAY_OPTIONS_BANNER_LENGTH];
73 int ret;
74
Marek Vasut7d4dcba2014-12-16 14:09:23 +010075 setup_display_lvds();
Marek Vasut6e303202019-05-17 20:32:20 +020076
77 ret = uclass_get_device(UCLASS_VIDEO_CONSOLE, 0, &con);
78 if (ret)
79 return ret;
80
81 display_options_get_banner(false, buf, sizeof(buf));
82 vidconsole_position_cursor(con, 0, 0);
83 vidconsole_put_string(con, buf);
Marek Vasut7d4dcba2014-12-16 14:09:23 +010084#endif
85 return 0;
86}
87
Marek Vasut408368f2014-10-24 23:39:07 +020088int checkboard(void)
89{
90 puts("Board: Novena 4x\n");
91 return 0;
92}
93
94int dram_init(void)
95{
96 gd->ram_size = imx_ddr_size();
97 return 0;
98}
99
100/* setup board specific PMIC */
101int power_init_board(void)
102{
103 struct pmic *p;
104 u32 reg;
105 int ret;
106
107 power_pfuze100_init(1);
108 p = pmic_get("PFUZE100");
109 if (!p)
110 return -EINVAL;
111
112 ret = pmic_probe(p);
113 if (ret)
114 return ret;
115
116 pmic_reg_read(p, PFUZE100_DEVICEID, &reg);
117 printf("PMIC: PFUZE100 ID=0x%02x\n", reg);
118
119 /* Set SWBST to 5.0V and enable (for USB) */
120 pmic_reg_read(p, PFUZE100_SWBSTCON1, &reg);
121 reg &= ~(SWBST_MODE_MASK | SWBST_VOL_MASK);
Marek Vasut2aaeb912015-11-26 14:08:50 +0100122 reg |= (SWBST_5_00V | (SWBST_MODE_AUTO << SWBST_MODE_SHIFT));
Marek Vasut408368f2014-10-24 23:39:07 +0200123 pmic_reg_write(p, PFUZE100_SWBSTCON1, reg);
124
125 return 0;
126}
127
128/* EEPROM configuration data */
129struct novena_eeprom_data {
130 uint8_t signature[6];
131 uint8_t version;
132 uint8_t reserved;
133 uint32_t serial;
134 uint8_t mac[6];
135 uint16_t features;
136};
137
138int misc_init_r(void)
139{
140 struct novena_eeprom_data data;
141 uchar *datap = (uchar *)&data;
142 const char *signature = "Novena";
143 int ret;
144
145 /* If 'ethaddr' is already set, do nothing. */
Simon Glass64b723f2017-08-03 12:22:12 -0600146 if (env_get("ethaddr"))
Marek Vasut408368f2014-10-24 23:39:07 +0200147 return 0;
148
149 /* EEPROM is at bus 2. */
150 ret = i2c_set_bus_num(2);
151 if (ret) {
152 puts("Cannot select EEPROM I2C bus.\n");
153 return 0;
154 }
155
156 /* EEPROM is at address 0x56. */
157 ret = eeprom_read(0x56, 0, datap, sizeof(data));
158 if (ret) {
159 puts("Cannot read I2C EEPROM.\n");
160 return 0;
161 }
162
163 /* Check EEPROM signature. */
164 if (memcmp(data.signature, signature, 6)) {
165 puts("Invalid I2C EEPROM signature.\n");
166 return 0;
167 }
168
169 /* Set ethernet address from EEPROM. */
Simon Glass8551d552017-08-03 12:22:11 -0600170 eth_env_set_enetaddr("ethaddr", data.mac);
Marek Vasut408368f2014-10-24 23:39:07 +0200171
172 return ret;
173}