]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/lpc32xx/devices.c
lpc32xx: i2c: add LPC32xx I2C interface support
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / lpc32xx / devices.c
1 /*
2  * Copyright (C) 2011 by Vladimir Zapolskiy <vz@mleia.com>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <asm/arch/cpu.h>
9 #include <asm/arch/clk.h>
10 #include <asm/arch/uart.h>
11 #include <asm/io.h>
12
13 static struct clk_pm_regs    *clk  = (struct clk_pm_regs *)CLK_PM_BASE;
14 static struct uart_ctrl_regs *ctrl = (struct uart_ctrl_regs *)UART_CTRL_BASE;
15
16 void lpc32xx_uart_init(unsigned int uart_id)
17 {
18         if (uart_id < 1 || uart_id > 7)
19                 return;
20
21         /* Disable loopback mode, if it is set by S1L bootloader */
22         clrbits_le32(&ctrl->loop,
23                      UART_LOOPBACK(CONFIG_SYS_LPC32XX_UART));
24
25         if (uart_id < 3 || uart_id > 6)
26                 return;
27
28         /* Enable UART system clock */
29         setbits_le32(&clk->uartclk_ctrl, CLK_UART(uart_id));
30
31         /* Set UART into autoclock mode */
32         clrsetbits_le32(&ctrl->clkmode,
33                         UART_CLKMODE_MASK(uart_id),
34                         UART_CLKMODE_AUTO(uart_id));
35
36         /* Bypass pre-divider of UART clock */
37         writel(CLK_UART_X_DIV(1) | CLK_UART_Y_DIV(1),
38                &clk->u3clk + (uart_id - 3));
39 }
40
41 void lpc32xx_mac_init(void)
42 {
43         /* Enable MAC interface */
44         writel(CLK_MAC_REG | CLK_MAC_SLAVE | CLK_MAC_MASTER
45                 | CLK_MAC_MII, &clk->macclk_ctrl);
46 }
47
48 void lpc32xx_mlc_nand_init(void)
49 {
50         /* Enable NAND interface */
51         writel(CLK_NAND_MLC | CLK_NAND_MLC_INT, &clk->flashclk_ctrl);
52 }
53
54 void lpc32xx_i2c_init(unsigned int devnum)
55 {
56         /* Enable I2C interface */
57         uint32_t ctrl = readl(&clk->i2cclk_ctrl);
58         if (devnum == 1)
59                 ctrl |= CLK_I2C1_ENABLE;
60         if (devnum == 2)
61                 ctrl |= CLK_I2C2_ENABLE;
62         writel(ctrl, &clk->i2cclk_ctrl);
63 }