blob: c0c9c6c3122a0984e1d5bd7e5cb083f39f7efa94 [file] [log] [blame]
Vladimir Zapolskiy52f69f82012-04-19 04:33:08 +00001/*
2 * Copyright (C) 2011 by Vladimir Zapolskiy <vz@mleia.com>
3 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Vladimir Zapolskiy52f69f82012-04-19 04:33:08 +00005 */
6
7#include <common.h>
8#include <asm/arch/cpu.h>
9#include <asm/arch/clk.h>
10#include <asm/arch/uart.h>
Albert ARIBAUD \(3ADEV\)981219e2015-03-31 11:40:47 +020011#include <asm/arch/mux.h>
Vladimir Zapolskiy52f69f82012-04-19 04:33:08 +000012#include <asm/io.h>
Albert ARIBAUD \(3ADEV\)606f7042015-03-31 11:40:46 +020013#include <dm.h>
Vladimir Zapolskiy52f69f82012-04-19 04:33:08 +000014
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\)981219e2015-03-31 11:40:47 +020017static struct mux_regs *mux = (struct mux_regs *)MUX_BASE;
Vladimir Zapolskiy52f69f82012-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 */
25 clrbits_le32(&ctrl->loop,
26 UART_LOOPBACK(CONFIG_SYS_LPC32XX_UART));
27
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\)ac2916a2015-03-31 11:40:43 +020043
44void lpc32xx_mac_init(void)
45{
46 /* Enable MAC interface */
47 writel(CLK_MAC_REG | CLK_MAC_SLAVE | CLK_MAC_MASTER
Vladimir Zapolskiy1a791892015-07-06 07:22:11 +030048#if defined(CONFIG_RMII)
49 | CLK_MAC_RMII,
50#else
51 | CLK_MAC_MII,
52#endif
53 &clk->macclk_ctrl);
Albert ARIBAUD \(3ADEV\)ac2916a2015-03-31 11:40:43 +020054}
Albert ARIBAUD \(3ADEV\)c8381bf2015-03-31 11:40:44 +020055
56void lpc32xx_mlc_nand_init(void)
57{
58 /* Enable NAND interface */
59 writel(CLK_NAND_MLC | CLK_NAND_MLC_INT, &clk->flashclk_ctrl);
60}
Albert ARIBAUD \(3ADEV\)5e862b92015-03-31 11:40:45 +020061
Vladimir Zapolskiydcfd37e2015-07-18 03:07:52 +030062void lpc32xx_slc_nand_init(void)
63{
64 /* Enable SLC NAND interface */
65 writel(CLK_NAND_SLC | CLK_NAND_SLC_SELECT, &clk->flashclk_ctrl);
66}
67
Albert ARIBAUD \(3ADEV\)5e862b92015-03-31 11:40:45 +020068void lpc32xx_i2c_init(unsigned int devnum)
69{
70 /* Enable I2C interface */
71 uint32_t ctrl = readl(&clk->i2cclk_ctrl);
72 if (devnum == 1)
73 ctrl |= CLK_I2C1_ENABLE;
74 if (devnum == 2)
75 ctrl |= CLK_I2C2_ENABLE;
76 writel(ctrl, &clk->i2cclk_ctrl);
77}
Albert ARIBAUD \(3ADEV\)606f7042015-03-31 11:40:46 +020078
79U_BOOT_DEVICE(lpc32xx_gpios) = {
80 .name = "gpio_lpc32xx"
81};
Albert ARIBAUD \(3ADEV\)981219e2015-03-31 11:40:47 +020082
83/* Mux for SCK0, MISO0, MOSI0. We do not use SSEL0. */
84
85#define P_MUX_SET_SSP0 0x1600
86
87void lpc32xx_ssp_init(void)
88{
89 /* Enable SSP0 interface */
90 writel(CLK_SSP0_ENABLE_CLOCK, &clk->ssp_ctrl);
91 /* Mux SSP0 pins */
92 writel(P_MUX_SET_SSP0, &mux->p_mux_set);
93}