Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vladimir Zapolskiy | 6b20ef8 | 2012-04-19 04:33:08 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2011 by Vladimir Zapolskiy <vz@mleia.com> |
Vladimir Zapolskiy | 6b20ef8 | 2012-04-19 04:33:08 +0000 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | 3a2f576 | 2024-04-30 07:35:47 -0600 | [diff] [blame^] | 6 | #include <config.h> |
Vladimir Zapolskiy | 8bf9450 | 2015-12-19 23:29:25 +0200 | [diff] [blame] | 7 | #include <dm.h> |
| 8 | #include <ns16550.h> |
Vladimir Zapolskiy | 8bf9450 | 2015-12-19 23:29:25 +0200 | [diff] [blame] | 9 | |
Vladimir Zapolskiy | 6b20ef8 | 2012-04-19 04:33:08 +0000 | [diff] [blame] | 10 | #include <asm/arch/clk.h> |
| 11 | #include <asm/arch/uart.h> |
Albert ARIBAUD \(3ADEV\) | 24bfa9d | 2015-03-31 11:40:47 +0200 | [diff] [blame] | 12 | #include <asm/arch/mux.h> |
Vladimir Zapolskiy | 6b20ef8 | 2012-04-19 04:33:08 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | |
| 15 | static struct clk_pm_regs *clk = (struct clk_pm_regs *)CLK_PM_BASE; |
| 16 | static struct uart_ctrl_regs *ctrl = (struct uart_ctrl_regs *)UART_CTRL_BASE; |
Albert ARIBAUD \(3ADEV\) | 24bfa9d | 2015-03-31 11:40:47 +0200 | [diff] [blame] | 17 | static struct mux_regs *mux = (struct mux_regs *)MUX_BASE; |
Vladimir Zapolskiy | 6b20ef8 | 2012-04-19 04:33:08 +0000 | [diff] [blame] | 18 | |
| 19 | void 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 Woerner | 0b881ac | 2021-06-10 22:37:02 -0400 | [diff] [blame] | 25 | clrbits_le32(&ctrl->loop, UART_LOOPBACK(uart_id)); |
Vladimir Zapolskiy | 6b20ef8 | 2012-04-19 04:33:08 +0000 | [diff] [blame] | 26 | |
| 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\) | 391e163 | 2015-03-31 11:40:43 +0200 | [diff] [blame] | 42 | |
Vladimir Zapolskiy | 45e3fd9 | 2015-12-19 23:29:26 +0200 | [diff] [blame] | 43 | #if !CONFIG_IS_ENABLED(OF_CONTROL) |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 44 | static const struct ns16550_plat lpc32xx_uart[] = { |
Heiko Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 45 | { .base = UART3_BASE, .reg_shift = 2, |
Tom Rini | df6a215 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 46 | .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, }, |
Heiko Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 47 | { .base = UART4_BASE, .reg_shift = 2, |
Tom Rini | df6a215 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 48 | .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, }, |
Heiko Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 49 | { .base = UART5_BASE, .reg_shift = 2, |
Tom Rini | df6a215 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 50 | .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, }, |
Heiko Schocher | 06f108e | 2017-01-18 08:05:49 +0100 | [diff] [blame] | 51 | { .base = UART6_BASE, .reg_shift = 2, |
Tom Rini | df6a215 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 52 | .clock = CFG_SYS_NS16550_CLK, .fcr = UART_FCR_DEFVAL, }, |
Vladimir Zapolskiy | 8bf9450 | 2015-12-19 23:29:25 +0200 | [diff] [blame] | 53 | }; |
| 54 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 55 | U_BOOT_DRVINFOS(lpc32xx_uarts) = { |
Vladimir Zapolskiy | 8bf9450 | 2015-12-19 23:29:25 +0200 | [diff] [blame] | 56 | { "ns16550_serial", &lpc32xx_uart[0], }, |
| 57 | { "ns16550_serial", &lpc32xx_uart[1], }, |
| 58 | { "ns16550_serial", &lpc32xx_uart[2], }, |
| 59 | { "ns16550_serial", &lpc32xx_uart[3], }, |
Vladimir Zapolskiy | 8bf9450 | 2015-12-19 23:29:25 +0200 | [diff] [blame] | 60 | }; |
| 61 | #endif |
| 62 | |
Sylvain Lemieux | 90a837f | 2015-08-10 08:16:31 -0400 | [diff] [blame] | 63 | void lpc32xx_dma_init(void) |
| 64 | { |
| 65 | /* Enable DMA interface */ |
Vladimir Zapolskiy | b7f8ed2 | 2015-08-27 03:16:48 +0300 | [diff] [blame] | 66 | writel(CLK_DMA_ENABLE, &clk->dmaclk_ctrl); |
Sylvain Lemieux | 90a837f | 2015-08-10 08:16:31 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Albert ARIBAUD \(3ADEV\) | 391e163 | 2015-03-31 11:40:43 +0200 | [diff] [blame] | 69 | void lpc32xx_mac_init(void) |
| 70 | { |
| 71 | /* Enable MAC interface */ |
| 72 | writel(CLK_MAC_REG | CLK_MAC_SLAVE | CLK_MAC_MASTER |
Vladimir Zapolskiy | 8bffd71 | 2015-07-06 07:22:11 +0300 | [diff] [blame] | 73 | #if defined(CONFIG_RMII) |
| 74 | | CLK_MAC_RMII, |
| 75 | #else |
| 76 | | CLK_MAC_MII, |
| 77 | #endif |
| 78 | &clk->macclk_ctrl); |
Albert ARIBAUD \(3ADEV\) | 391e163 | 2015-03-31 11:40:43 +0200 | [diff] [blame] | 79 | } |
Albert ARIBAUD \(3ADEV\) | 7c97f70 | 2015-03-31 11:40:44 +0200 | [diff] [blame] | 80 | |
| 81 | void 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\) | b23324c | 2015-03-31 11:40:45 +0200 | [diff] [blame] | 86 | |
Vladimir Zapolskiy | 78f04f0 | 2015-07-18 03:07:52 +0300 | [diff] [blame] | 87 | void 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 Lemieux | 890cc77 | 2015-08-13 15:40:22 -0400 | [diff] [blame] | 93 | void 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\) | b23324c | 2015-03-31 11:40:45 +0200 | [diff] [blame] | 99 | void 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\) | eb135ad | 2015-03-31 11:40:46 +0200 | [diff] [blame] | 109 | |
Simon Glass | 1d8364a | 2020-12-28 20:34:54 -0700 | [diff] [blame] | 110 | U_BOOT_DRVINFO(lpc32xx_gpios) = { |
Albert ARIBAUD \(3ADEV\) | eb135ad | 2015-03-31 11:40:46 +0200 | [diff] [blame] | 111 | .name = "gpio_lpc32xx" |
| 112 | }; |
Albert ARIBAUD \(3ADEV\) | 24bfa9d | 2015-03-31 11:40:47 +0200 | [diff] [blame] | 113 | |
| 114 | /* Mux for SCK0, MISO0, MOSI0. We do not use SSEL0. */ |
| 115 | |
| 116 | #define P_MUX_SET_SSP0 0x1600 |
| 117 | |
| 118 | void 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 | } |