blob: 562ec96b8930ded801ba863d5e4167103a23ff1c [file] [log] [blame]
Kevin Wells19d95e12010-07-27 08:44:37 -07001/*
2 * arch/arm/mach-lpc32xx/phy3250.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>
Kay Sieversedbaa602011-12-21 16:26:03 -080021#include <linux/device.h>
Kevin Wells19d95e12010-07-27 08:44:37 -070022#include <linux/interrupt.h>
23#include <linux/irq.h>
24#include <linux/dma-mapping.h>
25#include <linux/device.h>
26#include <linux/spi/spi.h>
27#include <linux/spi/eeprom.h>
28#include <linux/leds.h>
29#include <linux/gpio.h>
30#include <linux/amba/bus.h>
31#include <linux/amba/clcd.h>
32#include <linux/amba/pl022.h>
33
34#include <asm/setup.h>
35#include <asm/mach-types.h>
36#include <asm/mach/arch.h>
37
38#include <mach/hardware.h>
39#include <mach/platform.h>
Roland Stiggec20b9092012-03-12 22:27:28 +010040#include <mach/board.h>
Linus Walleij9c587c02011-08-22 08:45:15 +010041#include <mach/gpio-lpc32xx.h>
Kevin Wells19d95e12010-07-27 08:44:37 -070042#include "common.h"
43
44/*
45 * Mapped GPIOLIB GPIOs
46 */
47#define SPI0_CS_GPIO LPC32XX_GPIO(LPC32XX_GPIO_P3_GRP, 5)
48#define LCD_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 0)
49#define BKL_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 4)
50#define LED_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 1)
51
52/*
53 * AMBA LCD controller
54 */
55static struct clcd_panel conn_lcd_panel = {
56 .mode = {
57 .name = "QVGA portrait",
58 .refresh = 60,
59 .xres = 240,
60 .yres = 320,
61 .pixclock = 191828,
62 .left_margin = 22,
63 .right_margin = 11,
64 .upper_margin = 2,
65 .lower_margin = 1,
66 .hsync_len = 5,
67 .vsync_len = 2,
68 .sync = 0,
69 .vmode = FB_VMODE_NONINTERLACED,
70 },
71 .width = -1,
72 .height = -1,
73 .tim2 = (TIM2_IVS | TIM2_IHS),
74 .cntl = (CNTL_BGR | CNTL_LCDTFT | CNTL_LCDVCOMP(1) |
75 CNTL_LCDBPP16_565),
76 .bpp = 16,
77};
78#define PANEL_SIZE (3 * SZ_64K)
79
80static int lpc32xx_clcd_setup(struct clcd_fb *fb)
81{
82 dma_addr_t dma;
83
84 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev,
85 PANEL_SIZE, &dma, GFP_KERNEL);
86 if (!fb->fb.screen_base) {
87 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
88 return -ENOMEM;
89 }
90
91 fb->fb.fix.smem_start = dma;
92 fb->fb.fix.smem_len = PANEL_SIZE;
93 fb->panel = &conn_lcd_panel;
94
95 if (gpio_request(LCD_POWER_GPIO, "LCD power"))
96 printk(KERN_ERR "Error requesting gpio %u",
97 LCD_POWER_GPIO);
98 else if (gpio_direction_output(LCD_POWER_GPIO, 1))
99 printk(KERN_ERR "Error setting gpio %u to output",
100 LCD_POWER_GPIO);
101
102 if (gpio_request(BKL_POWER_GPIO, "LCD backlight power"))
103 printk(KERN_ERR "Error requesting gpio %u",
104 BKL_POWER_GPIO);
105 else if (gpio_direction_output(BKL_POWER_GPIO, 1))
106 printk(KERN_ERR "Error setting gpio %u to output",
107 BKL_POWER_GPIO);
108
109 return 0;
110}
111
112static int lpc32xx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
113{
114 return dma_mmap_writecombine(&fb->dev->dev, vma,
115 fb->fb.screen_base, fb->fb.fix.smem_start,
116 fb->fb.fix.smem_len);
117}
118
119static void lpc32xx_clcd_remove(struct clcd_fb *fb)
120{
121 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
122 fb->fb.screen_base, fb->fb.fix.smem_start);
123}
124
125/*
126 * On some early LCD modules (1307.0), the backlight logic is inverted.
127 * For those board variants, swap the disable and enable states for
128 * BKL_POWER_GPIO.
129*/
130static void clcd_disable(struct clcd_fb *fb)
131{
132 gpio_set_value(BKL_POWER_GPIO, 0);
133 gpio_set_value(LCD_POWER_GPIO, 0);
134}
135
136static void clcd_enable(struct clcd_fb *fb)
137{
138 gpio_set_value(BKL_POWER_GPIO, 1);
139 gpio_set_value(LCD_POWER_GPIO, 1);
140}
141
142static struct clcd_board lpc32xx_clcd_data = {
143 .name = "Phytec LCD",
144 .check = clcdfb_check,
145 .decode = clcdfb_decode,
146 .disable = clcd_disable,
147 .enable = clcd_enable,
148 .setup = lpc32xx_clcd_setup,
149 .mmap = lpc32xx_clcd_mmap,
150 .remove = lpc32xx_clcd_remove,
151};
152
153static struct amba_device lpc32xx_clcd_device = {
154 .dev = {
155 .coherent_dma_mask = ~0,
156 .init_name = "dev:clcd",
157 .platform_data = &lpc32xx_clcd_data,
158 },
159 .res = {
160 .start = LPC32XX_LCD_BASE,
161 .end = (LPC32XX_LCD_BASE + SZ_4K - 1),
162 .flags = IORESOURCE_MEM,
163 },
164 .dma_mask = ~0,
165 .irq = {IRQ_LPC32XX_LCD, NO_IRQ},
166};
167
168/*
169 * AMBA SSP (SPI)
170 */
171static void phy3250_spi_cs_set(u32 control)
172{
173 gpio_set_value(SPI0_CS_GPIO, (int) control);
174}
175
176static struct pl022_config_chip spi0_chip_info = {
Kevin Wells19d95e12010-07-27 08:44:37 -0700177 .com_mode = INTERRUPT_TRANSFER,
178 .iface = SSP_INTERFACE_MOTOROLA_SPI,
179 .hierarchy = SSP_MASTER,
180 .slave_tx_disable = 0,
Kevin Wells19d95e12010-07-27 08:44:37 -0700181 .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
182 .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
Kevin Wells19d95e12010-07-27 08:44:37 -0700183 .ctrl_len = SSP_BITS_8,
184 .wait_state = SSP_MWIRE_WAIT_ZERO,
185 .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
186 .cs_control = phy3250_spi_cs_set,
187};
188
189static struct pl022_ssp_controller lpc32xx_ssp0_data = {
190 .bus_id = 0,
191 .num_chipselect = 1,
192 .enable_dma = 0,
193};
194
195static struct amba_device lpc32xx_ssp0_device = {
196 .dev = {
197 .coherent_dma_mask = ~0,
198 .init_name = "dev:ssp0",
199 .platform_data = &lpc32xx_ssp0_data,
200 },
201 .res = {
202 .start = LPC32XX_SSP0_BASE,
203 .end = (LPC32XX_SSP0_BASE + SZ_4K - 1),
204 .flags = IORESOURCE_MEM,
205 },
206 .dma_mask = ~0,
207 .irq = {IRQ_LPC32XX_SSP0, NO_IRQ},
208};
209
210/* AT25 driver registration */
211static int __init phy3250_spi_board_register(void)
212{
213#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
214 static struct spi_board_info info[] = {
215 {
216 .modalias = "spidev",
217 .max_speed_hz = 5000000,
218 .bus_num = 0,
219 .chip_select = 0,
220 .controller_data = &spi0_chip_info,
221 },
222 };
223
224#else
225 static struct spi_eeprom eeprom = {
226 .name = "at25256a",
227 .byte_len = 0x8000,
228 .page_size = 64,
229 .flags = EE_ADDR2,
230 };
231
232 static struct spi_board_info info[] = {
233 {
234 .modalias = "at25",
235 .max_speed_hz = 5000000,
236 .bus_num = 0,
237 .chip_select = 0,
Kevin Wellsbde435a2010-09-16 06:18:50 -0700238 .mode = SPI_MODE_0,
Kevin Wells19d95e12010-07-27 08:44:37 -0700239 .platform_data = &eeprom,
240 .controller_data = &spi0_chip_info,
241 },
242 };
243#endif
244 return spi_register_board_info(info, ARRAY_SIZE(info));
245}
246arch_initcall(phy3250_spi_board_register);
247
248static struct i2c_board_info __initdata phy3250_i2c_board_info[] = {
249 {
250 I2C_BOARD_INFO("pcf8563", 0x51),
251 },
252};
253
254static struct gpio_led phy_leds[] = {
255 {
256 .name = "led0",
257 .gpio = LED_GPIO,
258 .active_low = 1,
259 .default_trigger = "heartbeat",
260 },
261};
262
263static struct gpio_led_platform_data led_data = {
264 .leds = phy_leds,
265 .num_leds = ARRAY_SIZE(phy_leds),
266};
267
268static struct platform_device lpc32xx_gpio_led_device = {
269 .name = "leds-gpio",
270 .id = -1,
271 .dev.platform_data = &led_data,
272};
273
274static struct platform_device *phy3250_devs[] __initdata = {
Wolfram Sang737a2cb2012-02-16 15:51:28 +0100275 &lpc32xx_rtc_device,
276 &lpc32xx_tsc_device,
Kevin Wells19d95e12010-07-27 08:44:37 -0700277 &lpc32xx_i2c0_device,
278 &lpc32xx_i2c1_device,
279 &lpc32xx_i2c2_device,
280 &lpc32xx_watchdog_device,
281 &lpc32xx_gpio_led_device,
Roland Stigge678a0222012-02-17 14:58:14 +0100282 &lpc32xx_adc_device,
Roland Stigge48a5ded2012-03-12 22:23:43 +0100283 &lpc32xx_ohci_device,
Roland Stiggec20b9092012-03-12 22:27:28 +0100284 &lpc32xx_net_device,
Kevin Wells19d95e12010-07-27 08:44:37 -0700285};
286
287static struct amba_device *amba_devs[] __initdata = {
288 &lpc32xx_clcd_device,
289 &lpc32xx_ssp0_device,
290};
291
292/*
293 * Board specific functions
294 */
295static void __init phy3250_board_init(void)
296{
297 u32 tmp;
298 int i;
299
300 lpc32xx_gpio_init();
301
302 /* Register GPIOs used on this board */
303 if (gpio_request(SPI0_CS_GPIO, "spi0 cs"))
304 printk(KERN_ERR "Error requesting gpio %u",
305 SPI0_CS_GPIO);
306 else if (gpio_direction_output(SPI0_CS_GPIO, 1))
307 printk(KERN_ERR "Error setting gpio %u to output",
308 SPI0_CS_GPIO);
309
310 /* Setup network interface for RMII mode */
311 tmp = __raw_readl(LPC32XX_CLKPWR_MACCLK_CTRL);
312 tmp &= ~LPC32XX_CLKPWR_MACCTRL_PINS_MSK;
313 tmp |= LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS;
314 __raw_writel(tmp, LPC32XX_CLKPWR_MACCLK_CTRL);
315
316 /* Setup SLC NAND controller muxing */
317 __raw_writel(LPC32XX_CLKPWR_NANDCLK_SEL_SLC,
318 LPC32XX_CLKPWR_NAND_CLK_CTRL);
319
320 /* Setup LCD muxing to RGB565 */
321 tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
322 ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
323 LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
324 tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
325 __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
326
327 /* Set up I2C pull levels */
328 tmp = __raw_readl(LPC32XX_CLKPWR_I2C_CLK_CTRL);
329 tmp |= LPC32XX_CLKPWR_I2CCLK_USBI2CHI_DRIVE |
330 LPC32XX_CLKPWR_I2CCLK_I2C2HI_DRIVE;
331 __raw_writel(tmp, LPC32XX_CLKPWR_I2C_CLK_CTRL);
332
333 /* Disable IrDA pulsing support on UART6 */
334 tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
335 tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
336 __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
337
338 /* Enable DMA for I2S1 channel */
339 tmp = __raw_readl(LPC32XX_CLKPWR_I2S_CLK_CTRL);
340 tmp = LPC32XX_CLKPWR_I2SCTRL_I2S1_USE_DMA;
341 __raw_writel(tmp, LPC32XX_CLKPWR_I2S_CLK_CTRL);
342
343 lpc32xx_serial_init();
344
345 /*
346 * AMBA peripheral clocks need to be enabled prior to AMBA device
347 * detection or a data fault will occur, so enable the clocks
348 * here. However, we don't want to enable them if the peripheral
349 * isn't included in the image
350 */
351#ifdef CONFIG_FB_ARMCLCD
352 tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
353 __raw_writel((tmp | LPC32XX_CLKPWR_LCDCTRL_CLK_EN),
354 LPC32XX_CLKPWR_LCDCLK_CTRL);
355#endif
356#ifdef CONFIG_SPI_PL022
357 tmp = __raw_readl(LPC32XX_CLKPWR_SSP_CLK_CTRL);
358 __raw_writel((tmp | LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN),
359 LPC32XX_CLKPWR_SSP_CLK_CTRL);
360#endif
361
362 platform_add_devices(phy3250_devs, ARRAY_SIZE(phy3250_devs));
363 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
364 struct amba_device *d = amba_devs[i];
365 amba_device_register(d, &iomem_resource);
366 }
367
368 /* Test clock needed for UDA1380 initial init */
369 __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
370 LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
371 LPC32XX_CLKPWR_TEST_CLK_SEL);
372
373 i2c_register_board_info(0, phy3250_i2c_board_info,
374 ARRAY_SIZE(phy3250_i2c_board_info));
375}
376
377static int __init lpc32xx_display_uid(void)
378{
379 u32 uid[4];
380
381 lpc32xx_get_uid(uid);
382
383 printk(KERN_INFO "LPC32XX unique ID: %08x%08x%08x%08x\n",
384 uid[3], uid[2], uid[1], uid[0]);
385
386 return 1;
387}
388arch_initcall(lpc32xx_display_uid);
389
390MACHINE_START(PHY3250, "Phytec 3250 board with the LPC3250 Microcontroller")
391 /* Maintainer: Kevin Wells, NXP Semiconductors */
Nicolas Pitrebdec5dd2011-07-05 22:38:14 -0400392 .atag_offset = 0x100,
Kevin Wells19d95e12010-07-27 08:44:37 -0700393 .map_io = lpc32xx_map_io,
394 .init_irq = lpc32xx_init_irq,
395 .timer = &lpc32xx_timer,
396 .init_machine = phy3250_board_init,
Russell Kingb23fcd92011-11-05 12:17:40 +0000397 .restart = lpc23xx_restart,
Kevin Wells19d95e12010-07-27 08:44:37 -0700398MACHINE_END