blob: 3fcf8facb411ae00e693eeaf7d1a980edac47b2d [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
6#include <common.h>
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +02007#include <dm.h>
8#include <ns16550.h>
9#include <dm/platform_data/lpc32xx_hsuart.h>
10
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000011#include <asm/arch/clk.h>
12#include <asm/arch/uart.h>
Albert ARIBAUD \(3ADEV\)24bfa9d2015-03-31 11:40:47 +020013#include <asm/arch/mux.h>
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000014#include <asm/io.h>
15
16static struct clk_pm_regs *clk = (struct clk_pm_regs *)CLK_PM_BASE;
17static struct uart_ctrl_regs *ctrl = (struct uart_ctrl_regs *)UART_CTRL_BASE;
Albert ARIBAUD \(3ADEV\)24bfa9d2015-03-31 11:40:47 +020018static struct mux_regs *mux = (struct mux_regs *)MUX_BASE;
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000019
20void lpc32xx_uart_init(unsigned int uart_id)
21{
22 if (uart_id < 1 || uart_id > 7)
23 return;
24
25 /* Disable loopback mode, if it is set by S1L bootloader */
Trevor Woerner0b881ac2021-06-10 22:37:02 -040026 clrbits_le32(&ctrl->loop, UART_LOOPBACK(uart_id));
Vladimir Zapolskiy6b20ef82012-04-19 04:33:08 +000027
28 if (uart_id < 3 || uart_id > 6)
29 return;
30
31 /* Enable UART system clock */
32 setbits_le32(&clk->uartclk_ctrl, CLK_UART(uart_id));
33
34 /* Set UART into autoclock mode */
35 clrsetbits_le32(&ctrl->clkmode,
36 UART_CLKMODE_MASK(uart_id),
37 UART_CLKMODE_AUTO(uart_id));
38
39 /* Bypass pre-divider of UART clock */
40 writel(CLK_UART_X_DIV(1) | CLK_UART_Y_DIV(1),
41 &clk->u3clk + (uart_id - 3));
42}
Albert ARIBAUD \(3ADEV\)391e1632015-03-31 11:40:43 +020043
Vladimir Zapolskiy45e3fd92015-12-19 23:29:26 +020044#if !CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glassb75b15b2020-12-03 16:55:23 -070045static const struct ns16550_plat lpc32xx_uart[] = {
Heiko Schocher06f108e2017-01-18 08:05:49 +010046 { .base = UART3_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050047 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Heiko Schocher06f108e2017-01-18 08:05:49 +010048 { .base = UART4_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050049 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Heiko Schocher06f108e2017-01-18 08:05:49 +010050 { .base = UART5_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050051 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Heiko Schocher06f108e2017-01-18 08:05:49 +010052 { .base = UART6_BASE, .reg_shift = 2,
Tom Rinidf6a2152022-11-16 13:10:28 -050053 .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, },
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +020054};
55
56#if defined(CONFIG_LPC32XX_HSUART)
Simon Glassb75b15b2020-12-03 16:55:23 -070057static const struct lpc32xx_hsuart_plat lpc32xx_hsuart[] = {
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +020058 { HS_UART1_BASE, },
59 { HS_UART2_BASE, },
60 { HS_UART7_BASE, },
61};
62#endif
63
Simon Glass1d8364a2020-12-28 20:34:54 -070064U_BOOT_DRVINFOS(lpc32xx_uarts) = {
Vladimir Zapolskiy8bf94502015-12-19 23:29:25 +020065#if defined(CONFIG_LPC32XX_HSUART)
66 { "lpc32xx_hsuart", &lpc32xx_hsuart[0], },
67 { "lpc32xx_hsuart", &lpc32xx_hsuart[1], },
68#endif
69 { "ns16550_serial", &lpc32xx_uart[0], },
70 { "ns16550_serial", &lpc32xx_uart[1], },
71 { "ns16550_serial", &lpc32xx_uart[2], },
72 { "ns16550_serial", &lpc32xx_uart[3], },
73#if defined(CONFIG_LPC32XX_HSUART)
74 { "lpc32xx_hsuart", &lpc32xx_hsuart[2], },
75#endif
76};
77#endif
78
Sylvain Lemieux90a837f2015-08-10 08:16:31 -040079void lpc32xx_dma_init(void)
80{
81 /* Enable DMA interface */
Vladimir Zapolskiyb7f8ed22015-08-27 03:16:48 +030082 writel(CLK_DMA_ENABLE, &clk->dmaclk_ctrl);
Sylvain Lemieux90a837f2015-08-10 08:16:31 -040083}
84
Albert ARIBAUD \(3ADEV\)391e1632015-03-31 11:40:43 +020085void lpc32xx_mac_init(void)
86{
87 /* Enable MAC interface */
88 writel(CLK_MAC_REG | CLK_MAC_SLAVE | CLK_MAC_MASTER
Vladimir Zapolskiy8bffd712015-07-06 07:22:11 +030089#if defined(CONFIG_RMII)
90 | CLK_MAC_RMII,
91#else
92 | CLK_MAC_MII,
93#endif
94 &clk->macclk_ctrl);
Albert ARIBAUD \(3ADEV\)391e1632015-03-31 11:40:43 +020095}
Albert ARIBAUD \(3ADEV\)7c97f702015-03-31 11:40:44 +020096
97void lpc32xx_mlc_nand_init(void)
98{
99 /* Enable NAND interface */
100 writel(CLK_NAND_MLC | CLK_NAND_MLC_INT, &clk->flashclk_ctrl);
101}
Albert ARIBAUD \(3ADEV\)b23324c2015-03-31 11:40:45 +0200102
Vladimir Zapolskiy78f04f02015-07-18 03:07:52 +0300103void lpc32xx_slc_nand_init(void)
104{
105 /* Enable SLC NAND interface */
106 writel(CLK_NAND_SLC | CLK_NAND_SLC_SELECT, &clk->flashclk_ctrl);
107}
108
Sylvain Lemieux890cc772015-08-13 15:40:22 -0400109void lpc32xx_usb_init(void)
110{
111 /* Do not route the UART 5 Tx/Rx pins to the USB D+ and USB D- pins. */
112 clrbits_le32(&ctrl->ctrl, UART_CTRL_UART5_USB_MODE);
113}
114
Albert ARIBAUD \(3ADEV\)b23324c2015-03-31 11:40:45 +0200115void lpc32xx_i2c_init(unsigned int devnum)
116{
117 /* Enable I2C interface */
118 uint32_t ctrl = readl(&clk->i2cclk_ctrl);
119 if (devnum == 1)
120 ctrl |= CLK_I2C1_ENABLE;
121 if (devnum == 2)
122 ctrl |= CLK_I2C2_ENABLE;
123 writel(ctrl, &clk->i2cclk_ctrl);
124}
Albert ARIBAUD \(3ADEV\)eb135ad2015-03-31 11:40:46 +0200125
Simon Glass1d8364a2020-12-28 20:34:54 -0700126U_BOOT_DRVINFO(lpc32xx_gpios) = {
Albert ARIBAUD \(3ADEV\)eb135ad2015-03-31 11:40:46 +0200127 .name = "gpio_lpc32xx"
128};
Albert ARIBAUD \(3ADEV\)24bfa9d2015-03-31 11:40:47 +0200129
130/* Mux for SCK0, MISO0, MOSI0. We do not use SSEL0. */
131
132#define P_MUX_SET_SSP0 0x1600
133
134void lpc32xx_ssp_init(void)
135{
136 /* Enable SSP0 interface */
137 writel(CLK_SSP0_ENABLE_CLOCK, &clk->ssp_ctrl);
138 /* Mux SSP0 pins */
139 writel(P_MUX_SET_SSP0, &mux->p_mux_set);
140}