1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2fc982e1cSKevin Wells /*
3fc982e1cSKevin Wells * arch/arm/mach-lpc32xx/common.c
4fc982e1cSKevin Wells *
5fc982e1cSKevin Wells * Author: Kevin Wells <kevin.wells@nxp.com>
6fc982e1cSKevin Wells *
7fc982e1cSKevin Wells * Copyright (C) 2010 NXP Semiconductors
8fc982e1cSKevin Wells */
9fc982e1cSKevin Wells
10fc982e1cSKevin Wells #include <linux/init.h>
119dc03ffdSArnd Bergmann #include <linux/soc/nxp/lpc32xx-misc.h>
12fc982e1cSKevin Wells
13fc982e1cSKevin Wells #include <asm/mach/map.h>
14e39942f5SAlexandre Pereira da Silva #include <asm/system_info.h>
15fc982e1cSKevin Wells
16*d3532910SArnd Bergmann #include "lpc32xx.h"
17fc982e1cSKevin Wells #include "common.h"
18fc982e1cSKevin Wells
19fc982e1cSKevin Wells /*
20fc982e1cSKevin Wells * Returns the unique ID for the device
21fc982e1cSKevin Wells */
lpc32xx_get_uid(u32 devid[4])22fc982e1cSKevin Wells void lpc32xx_get_uid(u32 devid[4])
23fc982e1cSKevin Wells {
24fc982e1cSKevin Wells int i;
25fc982e1cSKevin Wells
26fc982e1cSKevin Wells for (i = 0; i < 4; i++)
27fc982e1cSKevin Wells devid[i] = __raw_readl(LPC32XX_CLKPWR_DEVID(i << 2));
28fc982e1cSKevin Wells }
29fc982e1cSKevin Wells
30fc982e1cSKevin Wells /*
31fc982e1cSKevin Wells * Detects and returns IRAM size for the device variation
32fc982e1cSKevin Wells */
33fc982e1cSKevin Wells #define LPC32XX_IRAM_BANK_SIZE SZ_128K
34fc982e1cSKevin Wells static u32 iram_size;
lpc32xx_return_iram(void __iomem ** mapbase,dma_addr_t * dmaaddr)359dc03ffdSArnd Bergmann u32 lpc32xx_return_iram(void __iomem **mapbase, dma_addr_t *dmaaddr)
36fc982e1cSKevin Wells {
37fc982e1cSKevin Wells if (iram_size == 0) {
38fc982e1cSKevin Wells u32 savedval1, savedval2;
39fc982e1cSKevin Wells void __iomem *iramptr1, *iramptr2;
40fc982e1cSKevin Wells
41fc982e1cSKevin Wells iramptr1 = io_p2v(LPC32XX_IRAM_BASE);
42fc982e1cSKevin Wells iramptr2 = io_p2v(LPC32XX_IRAM_BASE + LPC32XX_IRAM_BANK_SIZE);
43fc982e1cSKevin Wells savedval1 = __raw_readl(iramptr1);
44fc982e1cSKevin Wells savedval2 = __raw_readl(iramptr2);
45fc982e1cSKevin Wells
46fc982e1cSKevin Wells if (savedval1 == savedval2) {
47fc982e1cSKevin Wells __raw_writel(savedval2 + 1, iramptr2);
48fc982e1cSKevin Wells if (__raw_readl(iramptr1) == savedval2 + 1)
49fc982e1cSKevin Wells iram_size = LPC32XX_IRAM_BANK_SIZE;
50fc982e1cSKevin Wells else
51fc982e1cSKevin Wells iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
52fc982e1cSKevin Wells __raw_writel(savedval2, iramptr2);
53fc982e1cSKevin Wells } else
54fc982e1cSKevin Wells iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
55fc982e1cSKevin Wells }
569dc03ffdSArnd Bergmann if (dmaaddr)
579dc03ffdSArnd Bergmann *dmaaddr = LPC32XX_IRAM_BASE;
589dc03ffdSArnd Bergmann if (mapbase)
599dc03ffdSArnd Bergmann *mapbase = io_p2v(LPC32XX_IRAM_BASE);
60fc982e1cSKevin Wells
61fc982e1cSKevin Wells return iram_size;
62fc982e1cSKevin Wells }
639dc03ffdSArnd Bergmann EXPORT_SYMBOL_GPL(lpc32xx_return_iram);
64fc982e1cSKevin Wells
lpc32xx_set_phy_interface_mode(phy_interface_t mode)65ecca1a62SArnd Bergmann void lpc32xx_set_phy_interface_mode(phy_interface_t mode)
66ecca1a62SArnd Bergmann {
67ecca1a62SArnd Bergmann u32 tmp = __raw_readl(LPC32XX_CLKPWR_MACCLK_CTRL);
68ecca1a62SArnd Bergmann tmp &= ~LPC32XX_CLKPWR_MACCTRL_PINS_MSK;
69ecca1a62SArnd Bergmann if (mode == PHY_INTERFACE_MODE_MII)
70ecca1a62SArnd Bergmann tmp |= LPC32XX_CLKPWR_MACCTRL_USE_MII_PINS;
71ecca1a62SArnd Bergmann else
72ecca1a62SArnd Bergmann tmp |= LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS;
73ecca1a62SArnd Bergmann __raw_writel(tmp, LPC32XX_CLKPWR_MACCLK_CTRL);
74ecca1a62SArnd Bergmann }
75ecca1a62SArnd Bergmann EXPORT_SYMBOL_GPL(lpc32xx_set_phy_interface_mode);
76ecca1a62SArnd Bergmann
77fc982e1cSKevin Wells static struct map_desc lpc32xx_io_desc[] __initdata = {
78fc982e1cSKevin Wells {
79df38b24fSArnd Bergmann .virtual = (unsigned long)IO_ADDRESS(LPC32XX_AHB0_START),
80fc982e1cSKevin Wells .pfn = __phys_to_pfn(LPC32XX_AHB0_START),
81fc982e1cSKevin Wells .length = LPC32XX_AHB0_SIZE,
82fc982e1cSKevin Wells .type = MT_DEVICE
83fc982e1cSKevin Wells },
84fc982e1cSKevin Wells {
85df38b24fSArnd Bergmann .virtual = (unsigned long)IO_ADDRESS(LPC32XX_AHB1_START),
86fc982e1cSKevin Wells .pfn = __phys_to_pfn(LPC32XX_AHB1_START),
87fc982e1cSKevin Wells .length = LPC32XX_AHB1_SIZE,
88fc982e1cSKevin Wells .type = MT_DEVICE
89fc982e1cSKevin Wells },
90fc982e1cSKevin Wells {
91df38b24fSArnd Bergmann .virtual = (unsigned long)IO_ADDRESS(LPC32XX_FABAPB_START),
92fc982e1cSKevin Wells .pfn = __phys_to_pfn(LPC32XX_FABAPB_START),
93fc982e1cSKevin Wells .length = LPC32XX_FABAPB_SIZE,
94fc982e1cSKevin Wells .type = MT_DEVICE
95fc982e1cSKevin Wells },
96fc982e1cSKevin Wells {
97df38b24fSArnd Bergmann .virtual = (unsigned long)IO_ADDRESS(LPC32XX_IRAM_BASE),
98fc982e1cSKevin Wells .pfn = __phys_to_pfn(LPC32XX_IRAM_BASE),
99fc982e1cSKevin Wells .length = (LPC32XX_IRAM_BANK_SIZE * 2),
100fc982e1cSKevin Wells .type = MT_DEVICE
101fc982e1cSKevin Wells },
102fc982e1cSKevin Wells };
103fc982e1cSKevin Wells
lpc32xx_map_io(void)104fc982e1cSKevin Wells void __init lpc32xx_map_io(void)
105fc982e1cSKevin Wells {
106fc982e1cSKevin Wells iotable_init(lpc32xx_io_desc, ARRAY_SIZE(lpc32xx_io_desc));
107fc982e1cSKevin Wells }
108b23fcd90SRussell King
lpc32xx_check_uid(void)109e39942f5SAlexandre Pereira da Silva static int __init lpc32xx_check_uid(void)
110be20dbc8SRoland Stigge {
111be20dbc8SRoland Stigge u32 uid[4];
112be20dbc8SRoland Stigge
113be20dbc8SRoland Stigge lpc32xx_get_uid(uid);
114be20dbc8SRoland Stigge
115be20dbc8SRoland Stigge printk(KERN_INFO "LPC32XX unique ID: %08x%08x%08x%08x\n",
116be20dbc8SRoland Stigge uid[3], uid[2], uid[1], uid[0]);
117be20dbc8SRoland Stigge
118e39942f5SAlexandre Pereira da Silva if (!system_serial_low && !system_serial_high) {
119e39942f5SAlexandre Pereira da Silva system_serial_low = uid[0];
120e39942f5SAlexandre Pereira da Silva system_serial_high = uid[1];
121e39942f5SAlexandre Pereira da Silva }
122e39942f5SAlexandre Pereira da Silva
123be20dbc8SRoland Stigge return 1;
124be20dbc8SRoland Stigge }
125e39942f5SAlexandre Pereira da Silva arch_initcall(lpc32xx_check_uid);
126