blob: 764aaa8b6b1bbc0ea5a4a80c0ecac317fe6a825d [file] [log] [blame]
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2015-2019 Variscite Ltd.
4 * Copyright (C) 2019 Parthiban Nallathambi <parthitce@gmail.com>
Marc Ferland8fa9d092021-01-04 10:41:57 -05005 * Copyright (C) 2021 Marc Ferland, Amotus Solutions Inc., <ferlandm@amotus.ca>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +02006 */
7
Simon Glass97589732020-05-10 11:40:02 -06008#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -06009#include <net.h>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +020010#include <asm/arch/clock.h>
11#include <asm/arch/crm_regs.h>
12#include <asm/arch/mx6-pins.h>
13#include <asm/arch/sys_proto.h>
14#include <asm/mach-imx/iomux-v3.h>
15#include <asm/mach-imx/mxc_i2c.h>
Marc Ferland56122702020-12-22 14:24:12 -050016#include <dm.h>
Yangbo Lu73340382019-06-21 11:42:28 +080017#include <fsl_esdhc_imx.h>
Marc Ferland56122702020-12-22 14:24:12 -050018#include <i2c_eeprom.h>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +020019#include <linux/bitops.h>
Marc Ferland56122702020-12-22 14:24:12 -050020#include <malloc.h>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +020021#include <miiphy.h>
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +020022
23DECLARE_GLOBAL_DATA_PTR;
24
25int dram_init(void)
26{
27 gd->ram_size = imx_ddr_size();
28
29 return 0;
30}
31
32#ifdef CONFIG_NAND_MXS
33#define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
34#define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
35 PAD_CTL_SRE_FAST)
36#define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
37static iomux_v3_cfg_t const nand_pads[] = {
38 MX6_PAD_NAND_DATA00__RAWNAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
39 MX6_PAD_NAND_DATA01__RAWNAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
40 MX6_PAD_NAND_DATA02__RAWNAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
41 MX6_PAD_NAND_DATA03__RAWNAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
42 MX6_PAD_NAND_DATA04__RAWNAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
43 MX6_PAD_NAND_DATA05__RAWNAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
44 MX6_PAD_NAND_DATA06__RAWNAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
45 MX6_PAD_NAND_DATA07__RAWNAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
46 MX6_PAD_NAND_CLE__RAWNAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
47 MX6_PAD_NAND_ALE__RAWNAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
48 MX6_PAD_NAND_CE0_B__RAWNAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
49 MX6_PAD_NAND_RE_B__RAWNAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
50 MX6_PAD_NAND_WE_B__RAWNAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
51 MX6_PAD_NAND_WP_B__RAWNAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
52 MX6_PAD_NAND_READY_B__RAWNAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
53 MX6_PAD_NAND_DQS__RAWNAND_DQS | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
54};
55
56static void setup_gpmi_nand(void)
57{
58 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
59
60 /* config gpmi nand iomux */
61 imx_iomux_v3_setup_multiple_pads(nand_pads, ARRAY_SIZE(nand_pads));
62
63 clrbits_le32(&mxc_ccm->CCGR4,
64 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
65 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
66 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
67 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
68 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
69
70 /*
71 * config gpmi and bch clock to 100 MHz
72 * bch/gpmi select PLL2 PFD2 400M
73 * 100M = 400M / 4
74 */
75 clrbits_le32(&mxc_ccm->cscmr1,
76 MXC_CCM_CSCMR1_BCH_CLK_SEL |
77 MXC_CCM_CSCMR1_GPMI_CLK_SEL);
78 clrsetbits_le32(&mxc_ccm->cscdr1,
79 MXC_CCM_CSCDR1_BCH_PODF_MASK |
80 MXC_CCM_CSCDR1_GPMI_PODF_MASK,
81 (3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
82 (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
83
84 /* enable gpmi and bch clock gating */
85 setbits_le32(&mxc_ccm->CCGR4,
86 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
87 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
88 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
89 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
90 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
91
92 /* enable apbh clock gating */
93 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
94}
95#endif
96
97#ifdef CONFIG_FEC_MXC
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +020098static int setup_fec(int fec_id)
99{
100 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
101 int ret;
102
103 if (fec_id == 0) {
104 /*
105 * Use 50M anatop loopback REF_CLK1 for ENET1,
106 * clear gpr1[13], set gpr1[17].
107 */
108 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC1_MASK,
109 IOMUX_GPR1_FEC1_CLOCK_MUX1_SEL_MASK);
110 } else {
111 /*
112 * Use 50M anatop loopback REF_CLK2 for ENET2,
113 * clear gpr1[14], set gpr1[18].
114 */
115 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC2_MASK,
116 IOMUX_GPR1_FEC2_CLOCK_MUX1_SEL_MASK);
117 }
118
119 ret = enable_fec_anatop_clock(fec_id, ENET_50MHZ);
120 if (ret)
121 return ret;
122
123 enable_enet_clk(1);
124
125 return 0;
126}
127
128int board_phy_config(struct phy_device *phydev)
129{
130 /*
131 * Defaults + Enable status LEDs (LED1: Activity, LED0: Link) & select
132 * 50 MHz RMII clock mode.
133 */
134 phy_write(phydev, MDIO_DEVAD_NONE, 0x1f, 0x8190);
135
136 if (phydev->drv->config)
137 phydev->drv->config(phydev);
138
139 return 0;
140}
141#endif /* CONFIG_FEC_MXC */
142
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +0200143int board_init(void)
144{
145 /* Address of boot parameters */
146 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
147
148#ifdef CONFIG_FEC_MXC
149 setup_fec(CONFIG_FEC_ENET_DEV);
150#endif
151
152#ifdef CONFIG_NAND_MXS
153 setup_gpmi_nand();
154#endif
155 return 0;
156}
157
Marc Ferland56122702020-12-22 14:24:12 -0500158/* length of strings stored in the eeprom */
159#define DART6UL_PN_LEN 16
160#define DART6UL_ASSY_LEN 16
161#define DART6UL_DATE_LEN 12
162
163/* eeprom content, 512 bytes */
164struct dart6ul_info {
165 u32 magic;
166 u8 partnumber[DART6UL_PN_LEN];
167 u8 assy[DART6UL_ASSY_LEN];
168 u8 date[DART6UL_DATE_LEN];
169 u32 custom_addr_val[32];
170 struct cmd {
171 u8 addr;
172 u8 index;
173 } custom_cmd[150];
174 u8 res[33];
175 u8 som_info;
176 u8 ddr_size;
177 u8 crc;
178} __attribute__ ((__packed__));
179
180#define DART6UL_INFO_STORAGE_GET(n) ((n) & 0x3)
181#define DART6UL_INFO_WIFI_GET(n) ((n) >> 2 & 0x1)
182#define DART6UL_INFO_REV_GET(n) ((n) >> 3 & 0x3)
Marc Ferlanddabdbbb2021-01-04 14:07:53 -0500183#define DART6UL_DDRSIZE(n) ((n) * SZ_128M)
Marc Ferland56122702020-12-22 14:24:12 -0500184#define DART6UL_INFO_MAGIC 0x32524156
185
186static const char *som_info_storage_to_str(u8 som_info)
187{
188 switch (DART6UL_INFO_STORAGE_GET(som_info)) {
189 case 0x0: return "none (SD only)";
190 case 0x1: return "NAND";
191 case 0x2: return "eMMC";
192 default: return "unknown";
193 }
194}
195
196static const char *som_info_rev_to_str(u8 som_info)
197{
198 switch (DART6UL_INFO_REV_GET(som_info)) {
199 case 0x0: return "2.4G";
200 case 0x1: return "5G";
201 default: return "unknown";
202 }
203}
204
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +0200205int checkboard(void)
206{
Marc Ferland56122702020-12-22 14:24:12 -0500207 const char *path = "eeprom0";
208 struct dart6ul_info *info;
209 struct udevice *dev;
210 int ret, off;
211
212 off = fdt_path_offset(gd->fdt_blob, path);
213 if (off < 0) {
214 printf("%s: fdt_path_offset() failed: %d\n", __func__, off);
215 return off;
216 }
217
218 ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev);
219 if (ret) {
220 printf("%s: uclass_get_device_by_of_offset() failed: %d\n", __func__, ret);
221 return ret;
222 }
223
224 info = malloc(sizeof(struct dart6ul_info));
225 if (!info)
226 return -ENOMEM;
227
228 ret = i2c_eeprom_read(dev, 0, (uint8_t *)info,
229 sizeof(struct dart6ul_info));
230 if (ret) {
231 printf("%s: i2c_eeprom_read() failed: %d\n", __func__, ret);
232 free(info);
233 return ret;
234 }
235
236 if (info->magic != DART6UL_INFO_MAGIC) {
237 printf("Board: Invalid board info magic: 0x%08x, expected 0x%08x\n",
238 info->magic, DART6UL_INFO_MAGIC);
239 /* do not fail if the content is invalid */
240 free(info);
241 return 0;
242 }
243
244 /* make sure strings are null terminated */
245 info->partnumber[DART6UL_PN_LEN - 1] = '\0';
246 info->assy[DART6UL_ASSY_LEN - 1] = '\0';
247 info->date[DART6UL_DATE_LEN - 1] = '\0';
248
249 printf("Board: PN: %s, Assy: %s, Date: %s\n"
250 " Storage: %s, Wifi: %s, DDR: %d MiB, Rev: %s\n",
251 info->partnumber,
252 info->assy,
253 info->date,
254 som_info_storage_to_str(info->som_info),
255 DART6UL_INFO_WIFI_GET(info->som_info) ? "yes" : "no",
Marc Ferlanddabdbbb2021-01-04 14:07:53 -0500256 DART6UL_DDRSIZE(info->ddr_size) / SZ_1M,
Marc Ferland56122702020-12-22 14:24:12 -0500257 som_info_rev_to_str(info->som_info));
258
259 free(info);
Parthiban Nallathambi5e9147d2019-04-18 00:04:09 +0200260
261 return 0;
262}