blob: a4a43b3684efa352b0e39d0a1b8860eaf6151f6d [file] [log] [blame]
Kevin Wells19d95e12010-07-27 08:44:37 -07001/*
Roland Stiggef5c42272012-04-22 12:01:19 +02002 * Platform support for LPC32xx SoC
Kevin Wells19d95e12010-07-27 08:44:37 -07003 *
4 * Author: Kevin Wells <kevin.wells@nxp.com>
5 *
Roland Stiggef5c42272012-04-22 12:01:19 +02006 * Copyright (C) 2012 Roland Stigge <stigge@antcom.de>
Kevin Wells19d95e12010-07-27 08:44:37 -07007 * Copyright (C) 2010 NXP Semiconductors
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/init.h>
21#include <linux/platform_device.h>
Kay Sieversedbaa602011-12-21 16:26:03 -080022#include <linux/device.h>
Kevin Wells19d95e12010-07-27 08:44:37 -070023#include <linux/interrupt.h>
24#include <linux/irq.h>
25#include <linux/dma-mapping.h>
26#include <linux/device.h>
27#include <linux/spi/spi.h>
28#include <linux/spi/eeprom.h>
Kevin Wells19d95e12010-07-27 08:44:37 -070029#include <linux/gpio.h>
30#include <linux/amba/bus.h>
31#include <linux/amba/clcd.h>
32#include <linux/amba/pl022.h>
Roland Stigge291dd712012-06-14 16:16:17 +020033#include <linux/amba/pl08x.h>
34#include <linux/amba/mmci.h>
Roland Stiggef5c42272012-04-22 12:01:19 +020035#include <linux/of.h>
36#include <linux/of_address.h>
37#include <linux/of_irq.h>
38#include <linux/of_platform.h>
39#include <linux/clk.h>
Roland Stigge5b941232012-09-06 11:39:18 +020040#include <linux/mtd/lpc32xx_slc.h>
41#include <linux/mtd/lpc32xx_mlc.h>
Kevin Wells19d95e12010-07-27 08:44:37 -070042
43#include <asm/setup.h>
44#include <asm/mach-types.h>
45#include <asm/mach/arch.h>
46
47#include <mach/hardware.h>
48#include <mach/platform.h>
Roland Stiggec20b9092012-03-12 22:27:28 +010049#include <mach/board.h>
Linus Walleij9c587c02011-08-22 08:45:15 +010050#include <mach/gpio-lpc32xx.h>
Kevin Wells19d95e12010-07-27 08:44:37 -070051#include "common.h"
52
53/*
54 * Mapped GPIOLIB GPIOs
55 */
Roland Stigge291dd712012-06-14 16:16:17 +020056#define LCD_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 0)
57#define BKL_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 4)
58#define MMC_PWR_ENABLE_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 5)
Kevin Wells19d95e12010-07-27 08:44:37 -070059
60/*
61 * AMBA LCD controller
62 */
63static struct clcd_panel conn_lcd_panel = {
64 .mode = {
65 .name = "QVGA portrait",
66 .refresh = 60,
67 .xres = 240,
68 .yres = 320,
69 .pixclock = 191828,
70 .left_margin = 22,
71 .right_margin = 11,
72 .upper_margin = 2,
73 .lower_margin = 1,
74 .hsync_len = 5,
75 .vsync_len = 2,
76 .sync = 0,
77 .vmode = FB_VMODE_NONINTERLACED,
78 },
79 .width = -1,
80 .height = -1,
81 .tim2 = (TIM2_IVS | TIM2_IHS),
82 .cntl = (CNTL_BGR | CNTL_LCDTFT | CNTL_LCDVCOMP(1) |
83 CNTL_LCDBPP16_565),
84 .bpp = 16,
85};
86#define PANEL_SIZE (3 * SZ_64K)
87
88static int lpc32xx_clcd_setup(struct clcd_fb *fb)
89{
90 dma_addr_t dma;
91
92 fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev,
93 PANEL_SIZE, &dma, GFP_KERNEL);
94 if (!fb->fb.screen_base) {
95 printk(KERN_ERR "CLCD: unable to map framebuffer\n");
96 return -ENOMEM;
97 }
98
99 fb->fb.fix.smem_start = dma;
100 fb->fb.fix.smem_len = PANEL_SIZE;
101 fb->panel = &conn_lcd_panel;
102
103 if (gpio_request(LCD_POWER_GPIO, "LCD power"))
104 printk(KERN_ERR "Error requesting gpio %u",
105 LCD_POWER_GPIO);
106 else if (gpio_direction_output(LCD_POWER_GPIO, 1))
107 printk(KERN_ERR "Error setting gpio %u to output",
108 LCD_POWER_GPIO);
109
110 if (gpio_request(BKL_POWER_GPIO, "LCD backlight power"))
111 printk(KERN_ERR "Error requesting gpio %u",
112 BKL_POWER_GPIO);
113 else if (gpio_direction_output(BKL_POWER_GPIO, 1))
114 printk(KERN_ERR "Error setting gpio %u to output",
115 BKL_POWER_GPIO);
116
117 return 0;
118}
119
120static int lpc32xx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
121{
122 return dma_mmap_writecombine(&fb->dev->dev, vma,
123 fb->fb.screen_base, fb->fb.fix.smem_start,
124 fb->fb.fix.smem_len);
125}
126
127static void lpc32xx_clcd_remove(struct clcd_fb *fb)
128{
129 dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
130 fb->fb.screen_base, fb->fb.fix.smem_start);
131}
132
133/*
134 * On some early LCD modules (1307.0), the backlight logic is inverted.
135 * For those board variants, swap the disable and enable states for
136 * BKL_POWER_GPIO.
137*/
138static void clcd_disable(struct clcd_fb *fb)
139{
140 gpio_set_value(BKL_POWER_GPIO, 0);
141 gpio_set_value(LCD_POWER_GPIO, 0);
142}
143
144static void clcd_enable(struct clcd_fb *fb)
145{
146 gpio_set_value(BKL_POWER_GPIO, 1);
147 gpio_set_value(LCD_POWER_GPIO, 1);
148}
149
150static struct clcd_board lpc32xx_clcd_data = {
151 .name = "Phytec LCD",
152 .check = clcdfb_check,
153 .decode = clcdfb_decode,
154 .disable = clcd_disable,
155 .enable = clcd_enable,
156 .setup = lpc32xx_clcd_setup,
157 .mmap = lpc32xx_clcd_mmap,
158 .remove = lpc32xx_clcd_remove,
159};
160
Kevin Wells19d95e12010-07-27 08:44:37 -0700161/*
162 * AMBA SSP (SPI)
163 */
Kevin Wells19d95e12010-07-27 08:44:37 -0700164static struct pl022_ssp_controller lpc32xx_ssp0_data = {
165 .bus_id = 0,
166 .num_chipselect = 1,
167 .enable_dma = 0,
168};
169
Roland Stiggef5c42272012-04-22 12:01:19 +0200170static struct pl022_ssp_controller lpc32xx_ssp1_data = {
171 .bus_id = 1,
172 .num_chipselect = 1,
173 .enable_dma = 0,
174};
Kevin Wells19d95e12010-07-27 08:44:37 -0700175
Roland Stigged807af42012-06-14 16:16:17 +0200176static struct pl08x_channel_data pl08x_slave_channels[] = {
177 {
178 .bus_id = "nand-slc",
179 .min_signal = 1, /* SLC NAND Flash */
180 .max_signal = 1,
181 .periph_buses = PL08X_AHB1,
182 },
183 {
184 .bus_id = "nand-mlc",
185 .min_signal = 12, /* MLC NAND Flash */
186 .max_signal = 12,
187 .periph_buses = PL08X_AHB1,
188 },
189};
190
Roland Stigge8ba85f82012-07-12 14:01:04 +0200191static int pl08x_get_signal(const struct pl08x_channel_data *cd)
Roland Stigged807af42012-06-14 16:16:17 +0200192{
Roland Stigge8ba85f82012-07-12 14:01:04 +0200193 return cd->min_signal;
Roland Stigged807af42012-06-14 16:16:17 +0200194}
195
Roland Stigge8ba85f82012-07-12 14:01:04 +0200196static void pl08x_put_signal(const struct pl08x_channel_data *cd, int ch)
Roland Stigged807af42012-06-14 16:16:17 +0200197{
198}
199
Roland Stiggef5c42272012-04-22 12:01:19 +0200200static struct pl08x_platform_data pl08x_pd = {
Roland Stigged807af42012-06-14 16:16:17 +0200201 .slave_channels = &pl08x_slave_channels[0],
202 .num_slave_channels = ARRAY_SIZE(pl08x_slave_channels),
203 .get_signal = pl08x_get_signal,
204 .put_signal = pl08x_put_signal,
205 .lli_buses = PL08X_AHB1,
206 .mem_buses = PL08X_AHB1,
Kevin Wells19d95e12010-07-27 08:44:37 -0700207};
208
Roland Stigge291dd712012-06-14 16:16:17 +0200209static int mmc_handle_ios(struct device *dev, struct mmc_ios *ios)
210{
211 /* Only on and off are supported */
212 if (ios->power_mode == MMC_POWER_OFF)
213 gpio_set_value(MMC_PWR_ENABLE_GPIO, 0);
214 else
215 gpio_set_value(MMC_PWR_ENABLE_GPIO, 1);
216 return 0;
217}
218
219static struct mmci_platform_data lpc32xx_mmci_data = {
220 .ocr_mask = MMC_VDD_30_31 | MMC_VDD_31_32 |
221 MMC_VDD_32_33 | MMC_VDD_33_34,
222 .ios_handler = mmc_handle_ios,
223 .dma_filter = NULL,
224 /* No DMA for now since AMBA PL080 dmaengine driver only does scatter
225 * gather, and the MMCI driver doesn't do it this way */
226};
227
Roland Stigge5b941232012-09-06 11:39:18 +0200228static struct lpc32xx_slc_platform_data lpc32xx_slc_data = {
229 .dma_filter = pl08x_filter_id,
230};
231
232static struct lpc32xx_mlc_platform_data lpc32xx_mlc_data = {
233 .dma_filter = pl08x_filter_id,
234};
235
Roland Stiggef5c42272012-04-22 12:01:19 +0200236static const struct of_dev_auxdata lpc32xx_auxdata_lookup[] __initconst = {
237 OF_DEV_AUXDATA("arm,pl022", 0x20084000, "dev:ssp0", &lpc32xx_ssp0_data),
238 OF_DEV_AUXDATA("arm,pl022", 0x2008C000, "dev:ssp1", &lpc32xx_ssp1_data),
239 OF_DEV_AUXDATA("arm,pl110", 0x31040000, "dev:clcd", &lpc32xx_clcd_data),
240 OF_DEV_AUXDATA("arm,pl080", 0x31000000, "pl08xdmac", &pl08x_pd),
Roland Stigge291dd712012-06-14 16:16:17 +0200241 OF_DEV_AUXDATA("arm,pl18x", 0x20098000, "20098000.sd",
242 &lpc32xx_mmci_data),
Roland Stigge5b941232012-09-06 11:39:18 +0200243 OF_DEV_AUXDATA("nxp,lpc3220-slc", 0x20020000, "20020000.flash",
244 &lpc32xx_slc_data),
245 OF_DEV_AUXDATA("nxp,lpc3220-mlc", 0x200a8000, "200a8000.flash",
246 &lpc32xx_mlc_data),
Roland Stiggef5c42272012-04-22 12:01:19 +0200247 { }
Kevin Wells19d95e12010-07-27 08:44:37 -0700248};
249
Roland Stiggef5c42272012-04-22 12:01:19 +0200250static void __init lpc3250_machine_init(void)
Kevin Wells19d95e12010-07-27 08:44:37 -0700251{
252 u32 tmp;
Kevin Wells19d95e12010-07-27 08:44:37 -0700253
Kevin Wells19d95e12010-07-27 08:44:37 -0700254 /* Setup LCD muxing to RGB565 */
255 tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
256 ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
257 LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
258 tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
259 __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
260
Kevin Wells19d95e12010-07-27 08:44:37 -0700261 lpc32xx_serial_init();
262
Kevin Wells19d95e12010-07-27 08:44:37 -0700263 /* Test clock needed for UDA1380 initial init */
264 __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
265 LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
266 LPC32XX_CLKPWR_TEST_CLK_SEL);
267
Roland Stiggef5c42272012-04-22 12:01:19 +0200268 of_platform_populate(NULL, of_default_bus_match_table,
269 lpc32xx_auxdata_lookup, NULL);
270
271 /* Register GPIOs used on this board */
Roland Stigge291dd712012-06-14 16:16:17 +0200272 if (gpio_request(MMC_PWR_ENABLE_GPIO, "mmc_power_en"))
273 pr_err("Error requesting gpio %u", MMC_PWR_ENABLE_GPIO);
274 else if (gpio_direction_output(MMC_PWR_ENABLE_GPIO, 1))
275 pr_err("Error setting gpio %u to output", MMC_PWR_ENABLE_GPIO);
Kevin Wells19d95e12010-07-27 08:44:37 -0700276}
277
Roland Stiggef5c42272012-04-22 12:01:19 +0200278static char const *lpc32xx_dt_compat[] __initdata = {
279 "nxp,lpc3220",
280 "nxp,lpc3230",
281 "nxp,lpc3240",
282 "nxp,lpc3250",
283 NULL
284};
285
286DT_MACHINE_START(LPC32XX_DT, "LPC32XX SoC (Flattened Device Tree)")
Nicolas Pitrebdec5dd2011-07-05 22:38:14 -0400287 .atag_offset = 0x100,
Kevin Wells19d95e12010-07-27 08:44:37 -0700288 .map_io = lpc32xx_map_io,
289 .init_irq = lpc32xx_init_irq,
290 .timer = &lpc32xx_timer,
Roland Stiggef5c42272012-04-22 12:01:19 +0200291 .init_machine = lpc3250_machine_init,
292 .dt_compat = lpc32xx_dt_compat,
Russell Kingb23fcd92011-11-05 12:17:40 +0000293 .restart = lpc23xx_restart,
Kevin Wells19d95e12010-07-27 08:44:37 -0700294MACHINE_END