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