blob: d655fe099b51dcb7b37833d05b0bb5150672103f [file] [log] [blame]
Heiko Thiery05a3d952022-01-31 17:30:45 +01001// SPDX-License-Identifier: GPL-2.0+
2
3#include "pitx_misc.h"
4#include <common.h>
5#include <init.h>
6#include <mmc.h>
7#include <miiphy.h>
8#include <asm/arch/clock.h>
9#include <asm/arch/imx8mq_pins.h>
10#include <asm/arch/sys_proto.h>
11#include <asm-generic/gpio.h>
12#include <asm/mach-imx/gpio.h>
13#include <asm/mach-imx/iomux-v3.h>
14#include <linux/delay.h>
15
16
17DECLARE_GLOBAL_DATA_PTR;
18
19#define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1)
20#define WDOG_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE)
21
22static iomux_v3_cfg_t const wdog_pads[] = {
23 IMX8MQ_PAD_GPIO1_IO02__WDOG1_WDOG_B | MUX_PAD_CTRL(WDOG_PAD_CTRL),
24};
25
26static iomux_v3_cfg_t const uart_pads[] = {
27 IMX8MQ_PAD_UART3_RXD__UART3_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
28 IMX8MQ_PAD_UART3_TXD__UART3_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
29 IMX8MQ_PAD_ECSPI1_SS0__UART3_RTS_B | MUX_PAD_CTRL(UART_PAD_CTRL),
30 IMX8MQ_PAD_ECSPI1_MISO__UART3_CTS_B | MUX_PAD_CTRL(UART_PAD_CTRL),
31};
32
33int board_early_init_f(void)
34{
35 struct wdog_regs *wdog = (struct wdog_regs *)WDOG1_BASE_ADDR;
36
37 imx_iomux_v3_setup_multiple_pads(wdog_pads, ARRAY_SIZE(wdog_pads));
38 set_wdog_reset(wdog);
39
40 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
41
42 return 0;
43}
44
45int board_phys_sdram_size(phys_size_t *memsize)
46{
47 int variant = 0;
48
49 variant = get_pitx_board_variant();
50
51 switch(variant) {
52 case 2:
53 *memsize = 0x80000000;
54 break;
55 case 3:
56 *memsize = 0x100000000;
57 break;
58 default:
59 printf("Unknown DDR type!!!\n");
60 *memsize = 0x40000000;
61 break;
62 }
63
64 debug("Memsize: %d MiB\n", (int)(*memsize >> 20));
65
66 return 0;
67}
68
69
70#ifdef CONFIG_FEC_MXC
71#define FEC_RST_PAD IMX_GPIO_NR(1, 11)
72static iomux_v3_cfg_t const fec1_rst_pads[] = {
73 IMX8MQ_PAD_GPIO1_IO11__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
74};
75
76static void setup_iomux_fec(void)
77{
78 imx_iomux_v3_setup_multiple_pads(fec1_rst_pads,
79 ARRAY_SIZE(fec1_rst_pads));
80}
81
82static int setup_fec(void)
83{
84 struct iomuxc_gpr_base_regs *gpr =
85 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
86
87 setup_iomux_fec();
88
89 /* Use 125M anatop REF_CLK1 for ENET1, not from external */
90 clrsetbits_le32(&gpr->gpr[1], BIT(13) | BIT(17), 0);
91 return set_clk_enet(ENET_125MHZ);
92}
93
94int board_phy_config(struct phy_device *phydev)
95{
96 unsigned int val;
97
98 /*
99 * Set LED configuration register 1:
100 * LED2_SEL: 0b1011 (link established, blink on activity)
101 */
102 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x18);
103 val &= 0xf0ff;
104 phy_write(phydev, MDIO_DEVAD_NONE, 0x18, val | (0xb << 8));
105
106 if (phydev->drv->config)
107 phydev->drv->config(phydev);
108 return 0;
109}
110#endif
111
112int board_init(void)
113{
114#ifdef CONFIG_FEC_MXC
115 setup_fec();
116#endif
117
118#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_DWC3)
119 init_usb_clk();
120#endif
121
122 return 0;
123}
124
125#ifdef CONFIG_MISC_INIT_R
126#define TPM_RESET IMX_GPIO_NR(3, 2)
127#define USBHUB_RESET IMX_GPIO_NR(3, 4)
128
129static void reset_device_by_gpio(const char *label, int pin, int delay_ms)
130{
131 gpio_request(pin, label);
132 gpio_direction_output(pin, 0);
133 mdelay(delay_ms);
134 gpio_direction_output(pin, 1);
135}
136
137int misc_init_r(void)
138{
139 /*
140 * reset TPM chip (Infineon SLB9670) as required by datasheet
141 * (60ms minimum Reset Inactive Time, 70ms implemented)
142 */
143 reset_device_by_gpio("tpm_reset", TPM_RESET, 70);
144
145 /*
146 * reset USB hub as required by datasheet
147 * (3ms minimum reset duration, 10ms implemented)
148 */
149 reset_device_by_gpio("usbhub_reset", USBHUB_RESET, 10);
150
151 return 0;
152}
153#endif
154
155int board_mmc_get_env_dev(int devno)
156{
157 return devno;
158}
159
160uint mmc_get_env_part(struct mmc *mmc)
161{
162 /* part 1 for eMMC, part 1 for SD card */
163 return (mmc_get_env_dev() == 0) ? 1 : 0;
164}
165
166int board_late_init(void)
167{
168 return 0;
169}