2 * arch/arm/mach-lpc32xx/common.c
4 * Author: Kevin Wells <kevin.wells@nxp.com>
6 * Copyright (C) 2010 NXP Semiconductors
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21 #include <linux/interrupt.h>
22 #include <linux/irq.h>
23 #include <linux/err.h>
24 #include <linux/i2c.h>
25 #include <linux/i2c-pnx.h>
28 #include <asm/mach/map.h>
31 #include <mach/hardware.h>
32 #include <mach/platform.h>
38 static struct resource watchdog_resources[] = {
40 .start = LPC32XX_WDTIM_BASE,
41 .end = LPC32XX_WDTIM_BASE + SZ_4K - 1,
42 .flags = IORESOURCE_MEM,
46 struct platform_device lpc32xx_watchdog_device = {
47 .name = "pnx4008-watchdog",
49 .num_resources = ARRAY_SIZE(watchdog_resources),
50 .resource = watchdog_resources,
56 static struct i2c_pnx_data i2c0_data = {
57 .name = I2C_CHIP_NAME "1",
58 .base = LPC32XX_I2C1_BASE,
59 .irq = IRQ_LPC32XX_I2C_1,
62 static struct i2c_pnx_data i2c1_data = {
63 .name = I2C_CHIP_NAME "2",
64 .base = LPC32XX_I2C2_BASE,
65 .irq = IRQ_LPC32XX_I2C_2,
68 static struct i2c_pnx_data i2c2_data = {
70 .base = LPC32XX_OTG_I2C_BASE,
71 .irq = IRQ_LPC32XX_USB_I2C,
74 struct platform_device lpc32xx_i2c0_device = {
78 .platform_data = &i2c0_data,
82 struct platform_device lpc32xx_i2c1_device = {
86 .platform_data = &i2c1_data,
90 struct platform_device lpc32xx_i2c2_device = {
94 .platform_data = &i2c2_data,
98 /* TSC (Touch Screen Controller) */
100 static struct resource lpc32xx_tsc_resources[] = {
102 .start = LPC32XX_ADC_BASE,
103 .end = LPC32XX_ADC_BASE + SZ_4K - 1,
104 .flags = IORESOURCE_MEM,
106 .start = IRQ_LPC32XX_TS_IRQ,
107 .end = IRQ_LPC32XX_TS_IRQ,
108 .flags = IORESOURCE_IRQ,
112 struct platform_device lpc32xx_tsc_device = {
113 .name = "ts-lpc32xx",
115 .num_resources = ARRAY_SIZE(lpc32xx_tsc_resources),
116 .resource = lpc32xx_tsc_resources,
121 static struct resource lpc32xx_rtc_resources[] = {
123 .start = LPC32XX_RTC_BASE,
124 .end = LPC32XX_RTC_BASE + SZ_4K - 1,
125 .flags = IORESOURCE_MEM,
127 .start = IRQ_LPC32XX_RTC,
128 .end = IRQ_LPC32XX_RTC,
129 .flags = IORESOURCE_IRQ,
133 struct platform_device lpc32xx_rtc_device = {
134 .name = "rtc-lpc32xx",
136 .num_resources = ARRAY_SIZE(lpc32xx_rtc_resources),
137 .resource = lpc32xx_rtc_resources,
143 static struct resource adc_resources[] = {
145 .start = LPC32XX_ADC_BASE,
146 .end = LPC32XX_ADC_BASE + SZ_4K - 1,
147 .flags = IORESOURCE_MEM,
149 .start = IRQ_LPC32XX_TS_IRQ,
150 .end = IRQ_LPC32XX_TS_IRQ,
151 .flags = IORESOURCE_IRQ,
155 struct platform_device lpc32xx_adc_device = {
156 .name = "lpc32xx-adc",
158 .num_resources = ARRAY_SIZE(adc_resources),
159 .resource = adc_resources,
165 /* The dmamask must be set for OHCI to work */
166 static u64 ohci_dmamask = ~(u32) 0;
167 static struct resource ohci_resources[] = {
169 .start = IO_ADDRESS(LPC32XX_USB_BASE),
170 .end = IO_ADDRESS(LPC32XX_USB_BASE + 0x100 - 1),
171 .flags = IORESOURCE_MEM,
173 .start = IRQ_LPC32XX_USB_HOST,
174 .flags = IORESOURCE_IRQ,
177 struct platform_device lpc32xx_ohci_device = {
181 .dma_mask = &ohci_dmamask,
182 .coherent_dma_mask = 0xFFFFFFFF,
184 .num_resources = ARRAY_SIZE(ohci_resources),
185 .resource = ohci_resources,
191 static struct resource net_resources[] = {
192 [0] = DEFINE_RES_MEM(LPC32XX_ETHERNET_BASE, SZ_4K),
193 [1] = DEFINE_RES_MEM(LPC32XX_IRAM_BASE, SZ_128K),
194 [2] = DEFINE_RES_IRQ(IRQ_LPC32XX_ETHERNET),
197 static u64 lpc32xx_mac_dma_mask = 0xffffffffUL;
198 struct platform_device lpc32xx_net_device = {
202 .dma_mask = &lpc32xx_mac_dma_mask,
203 .coherent_dma_mask = 0xffffffffUL,
205 .num_resources = ARRAY_SIZE(net_resources),
206 .resource = net_resources,
210 * Returns the unique ID for the device
212 void lpc32xx_get_uid(u32 devid[4])
216 for (i = 0; i < 4; i++)
217 devid[i] = __raw_readl(LPC32XX_CLKPWR_DEVID(i << 2));
221 * Returns SYSCLK source
222 * 0 = PLL397, 1 = main oscillator
224 int clk_is_sysclk_mainosc(void)
226 if ((__raw_readl(LPC32XX_CLKPWR_SYSCLK_CTRL) &
227 LPC32XX_CLKPWR_SYSCTRL_SYSCLKMUX) == 0)
234 * System reset via the watchdog timer
236 static void lpc32xx_watchdog_reset(void)
238 /* Make sure WDT clocks are enabled */
239 __raw_writel(LPC32XX_CLKPWR_PWMCLK_WDOG_EN,
240 LPC32XX_CLKPWR_TIMER_CLK_CTRL);
242 /* Instant assert of RESETOUT_N with pulse length 1mS */
243 __raw_writel(13000, io_p2v(LPC32XX_WDTIM_BASE + 0x18));
244 __raw_writel(0x70, io_p2v(LPC32XX_WDTIM_BASE + 0xC));
248 * Detects and returns IRAM size for the device variation
250 #define LPC32XX_IRAM_BANK_SIZE SZ_128K
251 static u32 iram_size;
252 u32 lpc32xx_return_iram_size(void)
254 if (iram_size == 0) {
255 u32 savedval1, savedval2;
256 void __iomem *iramptr1, *iramptr2;
258 iramptr1 = io_p2v(LPC32XX_IRAM_BASE);
259 iramptr2 = io_p2v(LPC32XX_IRAM_BASE + LPC32XX_IRAM_BANK_SIZE);
260 savedval1 = __raw_readl(iramptr1);
261 savedval2 = __raw_readl(iramptr2);
263 if (savedval1 == savedval2) {
264 __raw_writel(savedval2 + 1, iramptr2);
265 if (__raw_readl(iramptr1) == savedval2 + 1)
266 iram_size = LPC32XX_IRAM_BANK_SIZE;
268 iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
269 __raw_writel(savedval2, iramptr2);
271 iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
278 * Computes PLL rate from PLL register and input clock
280 u32 clk_check_pll_setup(u32 ifreq, struct clk_pll_setup *pllsetup)
282 u32 ilfreq, p, m, n, fcco, fref, cfreq;
287 * ifreq must be >= 1MHz and <= 20MHz
288 * FCCO must be >= 156MHz and <= 320MHz
289 * FREF must be >= 1MHz and <= 27MHz
290 * Assume the passed input data is not valid
298 mode = (pllsetup->cco_bypass_b15 << 2) |
299 (pllsetup->direct_output_b14 << 1) |
300 pllsetup->fdbk_div_ctrl_b13;
303 case 0x0: /* Non-integer mode */
304 cfreq = (m * ilfreq) / (2 * p * n);
305 fcco = (m * ilfreq) / n;
309 case 0x1: /* integer mode */
310 cfreq = (m * ilfreq) / n;
311 fcco = (m * ilfreq) / (n * 2 * p);
316 case 0x3: /* Direct mode */
317 cfreq = (m * ilfreq) / n;
323 case 0x5: /* Bypass mode */
324 cfreq = ilfreq / (2 * p);
330 case 0x7: /* Direct bypass mode */
338 if (fcco < 156000000 || fcco > 320000000)
341 if (fref < 1000000 || fref > 27000000)
347 u32 clk_get_pclk_div(void)
349 return 1 + ((__raw_readl(LPC32XX_CLKPWR_HCLK_DIV) >> 2) & 0x1F);
352 static struct map_desc lpc32xx_io_desc[] __initdata = {
354 .virtual = IO_ADDRESS(LPC32XX_AHB0_START),
355 .pfn = __phys_to_pfn(LPC32XX_AHB0_START),
356 .length = LPC32XX_AHB0_SIZE,
360 .virtual = IO_ADDRESS(LPC32XX_AHB1_START),
361 .pfn = __phys_to_pfn(LPC32XX_AHB1_START),
362 .length = LPC32XX_AHB1_SIZE,
366 .virtual = IO_ADDRESS(LPC32XX_FABAPB_START),
367 .pfn = __phys_to_pfn(LPC32XX_FABAPB_START),
368 .length = LPC32XX_FABAPB_SIZE,
372 .virtual = IO_ADDRESS(LPC32XX_IRAM_BASE),
373 .pfn = __phys_to_pfn(LPC32XX_IRAM_BASE),
374 .length = (LPC32XX_IRAM_BANK_SIZE * 2),
379 void __init lpc32xx_map_io(void)
381 iotable_init(lpc32xx_io_desc, ARRAY_SIZE(lpc32xx_io_desc));
384 void lpc23xx_restart(char mode, const char *cmd)
389 lpc32xx_watchdog_reset();
397 /* Wait for watchdog to reset system */