blob: 10a00c990031bfe96f0bb1a7a1789842116fee62 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
/*
* Copyright (c) 2023, Pengutronix. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <lib/mmio.h>
#include <platform_def.h>
#define UCR1 0x80
#define UCR1_UARTEN BIT(0)
#define DOMAIN0_RUNNING(d) (((d) & 0x3) != 0)
static struct imx_uart {
unsigned int ccm_reg;
unsigned int uart_base;
} imx8m_uart_info[] = {
{ /* UART 1 */
.ccm_reg = 0x4490,
.uart_base = 0x30860000,
}, { /* UART 2 */
.ccm_reg = 0x44a0,
.uart_base = 0x30890000,
}, { /* UART 3 */
.ccm_reg = 0x44b0,
.uart_base = 0x30880000,
}, { /* UART 4 */
.ccm_reg = 0x44c0,
.uart_base = 0x30a60000,
}
};
unsigned int imx8m_uart_get_base(void)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(imx8m_uart_info); i++) {
uint32_t val;
/*
* At least check that the clock-gate is ungated before we
* access the UART register.
*/
val = mmio_read_32(IMX_CCM_BASE + imx8m_uart_info[i].ccm_reg);
if (DOMAIN0_RUNNING(val)) {
val = mmio_read_32(imx8m_uart_info[i].uart_base + UCR1);
if (val & UCR1_UARTEN) {
return imx8m_uart_info[i].uart_base;
}
}
}
/*
* We should return an error and inform the user but we can't do it
* this early.
*/
return 0;
}
|