blob: 6880b47a9ae5ee64af8fd6c9b56345f72bb509e3 [file] [log] [blame]
Kevin Wellsfc982e12010-07-27 08:42:46 -07001/*
2 * arch/arm/mach-lpc32xx/common.c
3 *
4 * Author: Kevin Wells <kevin.wells@nxp.com>
5 *
6 * Copyright (C) 2010 NXP Semiconductors
7 *
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.
12 *
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.
17 */
18
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>
26#include <linux/io.h>
27
28#include <asm/mach/map.h>
29
30#include <mach/i2c.h>
31#include <mach/hardware.h>
32#include <mach/platform.h>
33#include "common.h"
34
35/*
36 * Watchdog timer
37 */
38static struct resource watchdog_resources[] = {
39 [0] = {
40 .start = LPC32XX_WDTIM_BASE,
41 .end = LPC32XX_WDTIM_BASE + SZ_4K - 1,
42 .flags = IORESOURCE_MEM,
43 },
44};
45
46struct platform_device lpc32xx_watchdog_device = {
47 .name = "pnx4008-watchdog",
48 .id = -1,
49 .num_resources = ARRAY_SIZE(watchdog_resources),
50 .resource = watchdog_resources,
51};
52
53/*
54 * I2C busses
55 */
56static struct i2c_pnx_data i2c0_data = {
57 .name = I2C_CHIP_NAME "1",
58 .base = LPC32XX_I2C1_BASE,
59 .irq = IRQ_LPC32XX_I2C_1,
60};
61
62static struct i2c_pnx_data i2c1_data = {
63 .name = I2C_CHIP_NAME "2",
64 .base = LPC32XX_I2C2_BASE,
65 .irq = IRQ_LPC32XX_I2C_2,
66};
67
68static struct i2c_pnx_data i2c2_data = {
69 .name = "USB-I2C",
70 .base = LPC32XX_OTG_I2C_BASE,
71 .irq = IRQ_LPC32XX_USB_I2C,
72};
73
74struct platform_device lpc32xx_i2c0_device = {
75 .name = "pnx-i2c",
76 .id = 0,
77 .dev = {
78 .platform_data = &i2c0_data,
79 },
80};
81
82struct platform_device lpc32xx_i2c1_device = {
83 .name = "pnx-i2c",
84 .id = 1,
85 .dev = {
86 .platform_data = &i2c1_data,
87 },
88};
89
90struct platform_device lpc32xx_i2c2_device = {
91 .name = "pnx-i2c",
92 .id = 2,
93 .dev = {
94 .platform_data = &i2c2_data,
95 },
96};
97
Wolfram Sang7db2b3772011-03-21 16:14:43 +010098/* TSC (Touch Screen Controller) */
99
100static struct resource lpc32xx_tsc_resources[] = {
101 {
102 .start = LPC32XX_ADC_BASE,
103 .end = LPC32XX_ADC_BASE + SZ_4K - 1,
104 .flags = IORESOURCE_MEM,
105 }, {
106 .start = IRQ_LPC32XX_TS_IRQ,
107 .end = IRQ_LPC32XX_TS_IRQ,
108 .flags = IORESOURCE_IRQ,
109 },
110};
111
112struct platform_device lpc32xx_tsc_device = {
113 .name = "ts-lpc32xx",
114 .id = -1,
115 .num_resources = ARRAY_SIZE(lpc32xx_tsc_resources),
116 .resource = lpc32xx_tsc_resources,
117};
118
Kevin Wellsfc982e12010-07-27 08:42:46 -0700119/*
120 * Returns the unique ID for the device
121 */
122void lpc32xx_get_uid(u32 devid[4])
123{
124 int i;
125
126 for (i = 0; i < 4; i++)
127 devid[i] = __raw_readl(LPC32XX_CLKPWR_DEVID(i << 2));
128}
129
130/*
131 * Returns SYSCLK source
132 * 0 = PLL397, 1 = main oscillator
133 */
134int clk_is_sysclk_mainosc(void)
135{
136 if ((__raw_readl(LPC32XX_CLKPWR_SYSCLK_CTRL) &
137 LPC32XX_CLKPWR_SYSCTRL_SYSCLKMUX) == 0)
138 return 1;
139
140 return 0;
141}
142
143/*
144 * System reset via the watchdog timer
145 */
146void lpc32xx_watchdog_reset(void)
147{
148 /* Make sure WDT clocks are enabled */
149 __raw_writel(LPC32XX_CLKPWR_PWMCLK_WDOG_EN,
150 LPC32XX_CLKPWR_TIMER_CLK_CTRL);
151
152 /* Instant assert of RESETOUT_N with pulse length 1mS */
153 __raw_writel(13000, io_p2v(LPC32XX_WDTIM_BASE + 0x18));
154 __raw_writel(0x70, io_p2v(LPC32XX_WDTIM_BASE + 0xC));
155}
156
157/*
158 * Detects and returns IRAM size for the device variation
159 */
160#define LPC32XX_IRAM_BANK_SIZE SZ_128K
161static u32 iram_size;
162u32 lpc32xx_return_iram_size(void)
163{
164 if (iram_size == 0) {
165 u32 savedval1, savedval2;
166 void __iomem *iramptr1, *iramptr2;
167
168 iramptr1 = io_p2v(LPC32XX_IRAM_BASE);
169 iramptr2 = io_p2v(LPC32XX_IRAM_BASE + LPC32XX_IRAM_BANK_SIZE);
170 savedval1 = __raw_readl(iramptr1);
171 savedval2 = __raw_readl(iramptr2);
172
173 if (savedval1 == savedval2) {
174 __raw_writel(savedval2 + 1, iramptr2);
175 if (__raw_readl(iramptr1) == savedval2 + 1)
176 iram_size = LPC32XX_IRAM_BANK_SIZE;
177 else
178 iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
179 __raw_writel(savedval2, iramptr2);
180 } else
181 iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
182 }
183
184 return iram_size;
185}
186
187/*
188 * Computes PLL rate from PLL register and input clock
189 */
190u32 clk_check_pll_setup(u32 ifreq, struct clk_pll_setup *pllsetup)
191{
192 u32 ilfreq, p, m, n, fcco, fref, cfreq;
193 int mode;
194
195 /*
196 * PLL requirements
197 * ifreq must be >= 1MHz and <= 20MHz
198 * FCCO must be >= 156MHz and <= 320MHz
199 * FREF must be >= 1MHz and <= 27MHz
200 * Assume the passed input data is not valid
201 */
202
203 ilfreq = ifreq;
204 m = pllsetup->pll_m;
205 n = pllsetup->pll_n;
206 p = pllsetup->pll_p;
207
208 mode = (pllsetup->cco_bypass_b15 << 2) |
209 (pllsetup->direct_output_b14 << 1) |
210 pllsetup->fdbk_div_ctrl_b13;
211
212 switch (mode) {
213 case 0x0: /* Non-integer mode */
214 cfreq = (m * ilfreq) / (2 * p * n);
215 fcco = (m * ilfreq) / n;
216 fref = ilfreq / n;
217 break;
218
219 case 0x1: /* integer mode */
220 cfreq = (m * ilfreq) / n;
221 fcco = (m * ilfreq) / (n * 2 * p);
222 fref = ilfreq / n;
223 break;
224
225 case 0x2:
226 case 0x3: /* Direct mode */
227 cfreq = (m * ilfreq) / n;
228 fcco = cfreq;
229 fref = ilfreq / n;
230 break;
231
232 case 0x4:
233 case 0x5: /* Bypass mode */
234 cfreq = ilfreq / (2 * p);
235 fcco = 156000000;
236 fref = 1000000;
237 break;
238
239 case 0x6:
240 case 0x7: /* Direct bypass mode */
241 default:
242 cfreq = ilfreq;
243 fcco = 156000000;
244 fref = 1000000;
245 break;
246 }
247
248 if (fcco < 156000000 || fcco > 320000000)
249 cfreq = 0;
250
251 if (fref < 1000000 || fref > 27000000)
252 cfreq = 0;
253
254 return (u32) cfreq;
255}
256
257u32 clk_get_pclk_div(void)
258{
259 return 1 + ((__raw_readl(LPC32XX_CLKPWR_HCLK_DIV) >> 2) & 0x1F);
260}
261
262static struct map_desc lpc32xx_io_desc[] __initdata = {
263 {
264 .virtual = IO_ADDRESS(LPC32XX_AHB0_START),
265 .pfn = __phys_to_pfn(LPC32XX_AHB0_START),
266 .length = LPC32XX_AHB0_SIZE,
267 .type = MT_DEVICE
268 },
269 {
270 .virtual = IO_ADDRESS(LPC32XX_AHB1_START),
271 .pfn = __phys_to_pfn(LPC32XX_AHB1_START),
272 .length = LPC32XX_AHB1_SIZE,
273 .type = MT_DEVICE
274 },
275 {
276 .virtual = IO_ADDRESS(LPC32XX_FABAPB_START),
277 .pfn = __phys_to_pfn(LPC32XX_FABAPB_START),
278 .length = LPC32XX_FABAPB_SIZE,
279 .type = MT_DEVICE
280 },
281 {
282 .virtual = IO_ADDRESS(LPC32XX_IRAM_BASE),
283 .pfn = __phys_to_pfn(LPC32XX_IRAM_BASE),
284 .length = (LPC32XX_IRAM_BANK_SIZE * 2),
285 .type = MT_DEVICE
286 },
287};
288
289void __init lpc32xx_map_io(void)
290{
291 iotable_init(lpc32xx_io_desc, ARRAY_SIZE(lpc32xx_io_desc));
292}