1
2
3
4
5
6
7#include <common.h>
8#include <dm.h>
9#include <ns16550.h>
10#include <dm/platform_data/lpc32xx_hsuart.h>
11
12#include <asm/arch/clk.h>
13#include <asm/arch/uart.h>
14#include <asm/arch/mux.h>
15#include <asm/io.h>
16
17static struct clk_pm_regs *clk = (struct clk_pm_regs *)CLK_PM_BASE;
18static struct uart_ctrl_regs *ctrl = (struct uart_ctrl_regs *)UART_CTRL_BASE;
19static struct mux_regs *mux = (struct mux_regs *)MUX_BASE;
20
21void lpc32xx_uart_init(unsigned int uart_id)
22{
23 if (uart_id < 1 || uart_id > 7)
24 return;
25
26
27 clrbits_le32(&ctrl->loop,
28 UART_LOOPBACK(CONFIG_SYS_LPC32XX_UART));
29
30 if (uart_id < 3 || uart_id > 6)
31 return;
32
33
34 setbits_le32(&clk->uartclk_ctrl, CLK_UART(uart_id));
35
36
37 clrsetbits_le32(&ctrl->clkmode,
38 UART_CLKMODE_MASK(uart_id),
39 UART_CLKMODE_AUTO(uart_id));
40
41
42 writel(CLK_UART_X_DIV(1) | CLK_UART_Y_DIV(1),
43 &clk->u3clk + (uart_id - 3));
44}
45
46#if !CONFIG_IS_ENABLED(OF_CONTROL)
47static const struct ns16550_platdata lpc32xx_uart[] = {
48 { .base = UART3_BASE, .reg_shift = 2, .clock = CONFIG_SYS_NS16550_CLK },
49 { .base = UART4_BASE, .reg_shift = 2, .clock = CONFIG_SYS_NS16550_CLK },
50 { .base = UART5_BASE, .reg_shift = 2, .clock = CONFIG_SYS_NS16550_CLK },
51 { .base = UART6_BASE, .reg_shift = 2, .clock = CONFIG_SYS_NS16550_CLK },
52};
53
54#if defined(CONFIG_LPC32XX_HSUART)
55static const struct lpc32xx_hsuart_platdata lpc32xx_hsuart[] = {
56 { HS_UART1_BASE, },
57 { HS_UART2_BASE, },
58 { HS_UART7_BASE, },
59};
60#endif
61
62U_BOOT_DEVICES(lpc32xx_uarts) = {
63#if defined(CONFIG_LPC32XX_HSUART)
64 { "lpc32xx_hsuart", &lpc32xx_hsuart[0], },
65 { "lpc32xx_hsuart", &lpc32xx_hsuart[1], },
66#endif
67 { "ns16550_serial", &lpc32xx_uart[0], },
68 { "ns16550_serial", &lpc32xx_uart[1], },
69 { "ns16550_serial", &lpc32xx_uart[2], },
70 { "ns16550_serial", &lpc32xx_uart[3], },
71#if defined(CONFIG_LPC32XX_HSUART)
72 { "lpc32xx_hsuart", &lpc32xx_hsuart[2], },
73#endif
74};
75#endif
76
77void lpc32xx_dma_init(void)
78{
79
80 writel(CLK_DMA_ENABLE, &clk->dmaclk_ctrl);
81}
82
83void lpc32xx_mac_init(void)
84{
85
86 writel(CLK_MAC_REG | CLK_MAC_SLAVE | CLK_MAC_MASTER
87#if defined(CONFIG_RMII)
88 | CLK_MAC_RMII,
89#else
90 | CLK_MAC_MII,
91#endif
92 &clk->macclk_ctrl);
93}
94
95void lpc32xx_mlc_nand_init(void)
96{
97
98 writel(CLK_NAND_MLC | CLK_NAND_MLC_INT, &clk->flashclk_ctrl);
99}
100
101void lpc32xx_slc_nand_init(void)
102{
103
104 writel(CLK_NAND_SLC | CLK_NAND_SLC_SELECT, &clk->flashclk_ctrl);
105}
106
107void lpc32xx_usb_init(void)
108{
109
110 clrbits_le32(&ctrl->ctrl, UART_CTRL_UART5_USB_MODE);
111}
112
113void lpc32xx_i2c_init(unsigned int devnum)
114{
115
116 uint32_t ctrl = readl(&clk->i2cclk_ctrl);
117 if (devnum == 1)
118 ctrl |= CLK_I2C1_ENABLE;
119 if (devnum == 2)
120 ctrl |= CLK_I2C2_ENABLE;
121 writel(ctrl, &clk->i2cclk_ctrl);
122}
123
124U_BOOT_DEVICE(lpc32xx_gpios) = {
125 .name = "gpio_lpc32xx"
126};
127
128
129
130#define P_MUX_SET_SSP0 0x1600
131
132void lpc32xx_ssp_init(void)
133{
134
135 writel(CLK_SSP0_ENABLE_CLOCK, &clk->ssp_ctrl);
136
137 writel(P_MUX_SET_SSP0, &mux->p_mux_set);
138}
139