blob: 49308d6d4be0127c1f25321fc35df786ab8cb16a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +00002/*
3 * Copyright (C) 2011 by Vladimir Zapolskiy <vz@mleia.com>
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +00004 */
5
Tom Rini3a2f5762024-04-30 07:35:47 -06006#include <config.h>
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +02007#include <dm.h>
8#include <ns16550.h>
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +02009
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000010#include <asm/arch/clk.h>
11#include <asm/arch/uart.h>
Albert ARIBAUD \(3ADEV\)24bfa9d2015-03-31 11:40:47 +020012#include <asm/arch/mux.h>
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000013#include <asm/io.h>
14
15static struct clk_pm_regs *clk = (struct clk_pm_regs *)CLK_PM_BASE;
16static struct uart_ctrl_regs *ctrl = (struct uart_ctrl_regs *)UART_CTRL_BASE;
Albert ARIBAUD \(3ADEV\)24bfa9d2015-03-31 11:40:47 +020017static struct mux_regs *mux = (struct mux_regs *)MUX_BASE;
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000018
19void lpc32xx_uart_init(unsigned int uart_id)
20{
21 if (uart_id < 1 || uart_id > 7)
22 return;
23
24 /* Disable loopback mode, if it is set by S1L bootloader */
Trevor Woerner0b881ac2021-06-10 22:37:02 -040025 clrbits_le32(&ctrl->loop, UART_LOOPBACK(uart_id));
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000026
27 if (uart_id < 3 || uart_id > 6)
28 return;
29
30 /* Enable UART system clock */
31 setbits_le32(&clk->uartclk_ctrl, CLK_UART(uart_id));
32
33 /* Set UART into autoclock mode */
34 clrsetbits_le32(&ctrl->clkmode,
35 UART_CLKMODE_MASK(uart_id),
36 UART_CLKMODE_AUTO(uart_id));
37
38 /* Bypass pre-divider of UART clock */
39 writel(CLK_UART_X_DIV(1) | CLK_UART_Y_DIV(1),
40 &clk->u3clk + (uart_id - 3));
41}
Albert ARIBAUD \(3ADEV\)391e1632015-03-31 11:40:43 +020042
Vladimir Zapolskiy45e3fd92015-12-19 23:29:26 +020043#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassb75b15b2020-12-03 16:55:23 -070044static const struct ns16550_plat lpc32xx_uart[] = {
Heiko Schocher06f108e2017-01-18 08:05:49 +010045 { .base = UART3_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050046 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Heiko Schocher06f108e2017-01-18 08:05:49 +010047 { .base = UART4_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050048 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Heiko Schocher06f108e2017-01-18 08:05:49 +010049 { .base = UART5_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050050 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Heiko Schocher06f108e2017-01-18 08:05:49 +010051 { .base = UART6_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050052 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +020053};
54
Simon Glass1d8364a2020-12-28 20:34:54 -070055U_BOOT_DRVINFOS(lpc32xx_uarts) = {
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +020056 { "ns16550_serial", &lpc32xx_uart[0], },
57 { "ns16550_serial", &lpc32xx_uart[1], },
58 { "ns16550_serial", &lpc32xx_uart[2], },
59 { "ns16550_serial", &lpc32xx_uart[3], },
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +020060};
61#endif
62
Sylvain Lemieux90a837f2015-08-10 08:16:31 -040063void lpc32xx_dma_init(void)
64{
65 /* Enable DMA interface */
Vladimir Zapolskiyb7f8ed22015-08-27 03:16:48 +030066 writel(CLK_DMA_ENABLE, &clk->dmaclk_ctrl);
Sylvain Lemieux90a837f2015-08-10 08:16:31 -040067}
68
Albert ARIBAUD \(3ADEV\)391e1632015-03-31 11:40:43 +020069void lpc32xx_mac_init(void)
70{
71 /* Enable MAC interface */
72 writel(CLK_MAC_REG | CLK_MAC_SLAVE | CLK_MAC_MASTER
Vladimir Zapolskiy8bffd712015-07-06 07:22:11 +030073#if defined(CONFIG_RMII)
74 | CLK_MAC_RMII,
75#else
76 | CLK_MAC_MII,
77#endif
78 &clk->macclk_ctrl);
Albert ARIBAUD \(3ADEV\)391e1632015-03-31 11:40:43 +020079}
Albert ARIBAUD \(3ADEV\)7c97f702015-03-31 11:40:44 +020080
81void lpc32xx_mlc_nand_init(void)
82{
83 /* Enable NAND interface */
84 writel(CLK_NAND_MLC | CLK_NAND_MLC_INT, &clk->flashclk_ctrl);
85}
Albert ARIBAUD \(3ADEV\)b23324c2015-03-31 11:40:45 +020086
Vladimir Zapolskiy78f04f02015-07-18 03:07:52 +030087void lpc32xx_slc_nand_init(void)
88{
89 /* Enable SLC NAND interface */
90 writel(CLK_NAND_SLC | CLK_NAND_SLC_SELECT, &clk->flashclk_ctrl);
91}
92
Sylvain Lemieux890cc772015-08-13 15:40:22 -040093void lpc32xx_usb_init(void)
94{
95 /* Do not route the UART 5 Tx/Rx pins to the USB D+ and USB D- pins. */
96 clrbits_le32(&ctrl->ctrl, UART_CTRL_UART5_USB_MODE);
97}
98
Albert ARIBAUD \(3ADEV\)b23324c2015-03-31 11:40:45 +020099void lpc32xx_i2c_init(unsigned int devnum)
100{
101 /* Enable I2C interface */
102 uint32_t ctrl = readl(&clk->i2cclk_ctrl);
103 if (devnum == 1)
104 ctrl |= CLK_I2C1_ENABLE;
105 if (devnum == 2)
106 ctrl |= CLK_I2C2_ENABLE;
107 writel(ctrl, &clk->i2cclk_ctrl);
108}
Albert ARIBAUD \(3ADEV\)eb135ad2015-03-31 11:40:46 +0200109
Simon Glass1d8364a2020-12-28 20:34:54 -0700110U_BOOT_DRVINFO(lpc32xx_gpios) = {
Albert ARIBAUD \(3ADEV\)eb135ad2015-03-31 11:40:46 +0200111 .name = "gpio_lpc32xx"
112};
Albert ARIBAUD \(3ADEV\)24bfa9d2015-03-31 11:40:47 +0200113
114/* Mux for SCK0, MISO0, MOSI0. We do not use SSEL0. */
115
116#define P_MUX_SET_SSP0 0x1600
117
118void lpc32xx_ssp_init(void)
119{
120 /* Enable SSP0 interface */
121 writel(CLK_SSP0_ENABLE_CLOCK, &clk->ssp_ctrl);
122 /* Mux SSP0 pins */
123 writel(P_MUX_SET_SSP0, &mux->p_mux_set);
124}