blob: 2ee97169c6f5b125f52efa5d72163430582f3eef [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
Heiko Thiery05a3d952022-01-31 17:30:45 +010087#ifdef CONFIG_FEC_MXC
88#define FEC_RST_PAD IMX_GPIO_NR(1, 11)
89static iomux_v3_cfg_t const fec1_rst_pads[] = {
90 IMX8MQ_PAD_GPIO1_IO11__GPIO1_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
91};
92
Marek Vasutfbf73e52023-03-06 15:53:54 +010093static void setup_fec(void)
Heiko Thiery05a3d952022-01-31 17:30:45 +010094{
95 imx_iomux_v3_setup_multiple_pads(fec1_rst_pads,
96 ARRAY_SIZE(fec1_rst_pads));
97}
98
Heiko Thiery05a3d952022-01-31 17:30:45 +010099int board_phy_config(struct phy_device *phydev)
100{
101 unsigned int val;
102
103 /*
104 * Set LED configuration register 1:
105 * LED2_SEL: 0b1011 (link established, blink on activity)
106 */
107 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x18);
108 val &= 0xf0ff;
109 phy_write(phydev, MDIO_DEVAD_NONE, 0x18, val | (0xb << 8));
110
111 if (phydev->drv->config)
112 phydev->drv->config(phydev);
113 return 0;
114}
115#endif
116
117int board_init(void)
118{
119#ifdef CONFIG_FEC_MXC
120 setup_fec();
121#endif
122
123#if defined(CONFIG_USB_DWC3) || defined(CONFIG_USB_XHCI_DWC3)
124 init_usb_clk();
125#endif
126
127 return 0;
128}
129
130#ifdef CONFIG_MISC_INIT_R
131#define TPM_RESET IMX_GPIO_NR(3, 2)
132#define USBHUB_RESET IMX_GPIO_NR(3, 4)
133
134static void reset_device_by_gpio(const char *label, int pin, int delay_ms)
135{
136 gpio_request(pin, label);
137 gpio_direction_output(pin, 0);
138 mdelay(delay_ms);
139 gpio_direction_output(pin, 1);
140}
141
142int misc_init_r(void)
143{
144 /*
145 * reset TPM chip (Infineon SLB9670) as required by datasheet
146 * (60ms minimum Reset Inactive Time, 70ms implemented)
147 */
148 reset_device_by_gpio("tpm_reset", TPM_RESET, 70);
149
150 /*
151 * reset USB hub as required by datasheet
152 * (3ms minimum reset duration, 10ms implemented)
153 */
154 reset_device_by_gpio("usbhub_reset", USBHUB_RESET, 10);
155
156 return 0;
157}
158#endif
159
160int board_mmc_get_env_dev(int devno)
161{
162 return devno;
163}
164
165uint mmc_get_env_part(struct mmc *mmc)
166{
167 /* part 1 for eMMC, part 1 for SD card */
168 return (mmc_get_env_dev() == 0) ? 1 : 0;
169}
170
171int board_late_init(void)
172{
173 return 0;
174}