3 * arch/arm/mach-u300/core.c
6 * Copyright (C) 2007-2012 ST-Ericsson SA
7 * License terms: GNU General Public License (GPL) version 2
8 * Core platform support, IRQ handling and device definitions.
9 * Author: Linus Walleij <linus.walleij@stericsson.com>
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/spinlock.h>
14 #include <linux/interrupt.h>
15 #include <linux/bitops.h>
16 #include <linux/device.h>
18 #include <linux/termios.h>
19 #include <linux/dmaengine.h>
20 #include <linux/amba/bus.h>
21 #include <linux/amba/mmci.h>
22 #include <linux/amba/serial.h>
23 #include <linux/platform_device.h>
24 #include <linux/gpio.h>
25 #include <linux/clk.h>
26 #include <linux/err.h>
27 #include <linux/mtd/nand.h>
28 #include <linux/mtd/fsmc.h>
29 #include <linux/pinctrl/machine.h>
30 #include <linux/pinctrl/pinconf-generic.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/platform_data/clk-u300.h>
33 #include <linux/platform_data/pinctrl-coh901.h>
34 #include <linux/platform_data/dma-coh901318.h>
35 #include <linux/irqchip/arm-vic.h>
37 #include <asm/types.h>
38 #include <asm/setup.h>
39 #include <asm/memory.h>
40 #include <asm/mach/map.h>
41 #include <asm/mach-types.h>
42 #include <asm/mach/arch.h>
44 #include <mach/hardware.h>
45 #include <mach/syscon.h>
46 #include <mach/irqs.h>
51 #include "u300-gpio.h"
54 * Static I/O mappings that are needed for booting the U300 platforms. The
55 * only things we need are the areas where we find the timer, syscon and
56 * intcon, since the remaining device drivers will map their own memory
57 * physical to virtual as the need arise.
59 static struct map_desc u300_io_desc[] __initdata = {
61 .virtual = U300_SLOW_PER_VIRT_BASE,
62 .pfn = __phys_to_pfn(U300_SLOW_PER_PHYS_BASE),
67 .virtual = U300_AHB_PER_VIRT_BASE,
68 .pfn = __phys_to_pfn(U300_AHB_PER_PHYS_BASE),
73 .virtual = U300_FAST_PER_VIRT_BASE,
74 .pfn = __phys_to_pfn(U300_FAST_PER_PHYS_BASE),
80 static void __init u300_map_io(void)
82 iotable_init(u300_io_desc, ARRAY_SIZE(u300_io_desc));
86 * Declaration of devices found on the U300 board and
87 * their respective memory locations.
90 static struct amba_pl011_data uart0_plat_data = {
91 #ifdef CONFIG_COH901318
92 .dma_filter = coh901318_filter_id,
93 .dma_rx_param = (void *) U300_DMA_UART0_RX,
94 .dma_tx_param = (void *) U300_DMA_UART0_TX,
98 /* Slow device at 0x3000 offset */
99 static AMBA_APB_DEVICE(uart0, "uart0", 0, U300_UART0_BASE,
100 { IRQ_U300_UART0 }, &uart0_plat_data);
102 /* The U335 have an additional UART1 on the APP CPU */
103 static struct amba_pl011_data uart1_plat_data = {
104 #ifdef CONFIG_COH901318
105 .dma_filter = coh901318_filter_id,
106 .dma_rx_param = (void *) U300_DMA_UART1_RX,
107 .dma_tx_param = (void *) U300_DMA_UART1_TX,
111 /* Fast device at 0x7000 offset */
112 static AMBA_APB_DEVICE(uart1, "uart1", 0, U300_UART1_BASE,
113 { IRQ_U300_UART1 }, &uart1_plat_data);
115 /* AHB device at 0x4000 offset */
116 static AMBA_APB_DEVICE(pl172, "pl172", 0, U300_EMIF_CFG_BASE, { }, NULL);
118 /* Fast device at 0x6000 offset */
119 static AMBA_APB_DEVICE(pl022, "pl022", 0, U300_SPI_BASE,
120 { IRQ_U300_SPI }, NULL);
122 /* Fast device at 0x1000 offset */
123 #define U300_MMCSD_IRQS { IRQ_U300_MMCSD_MCIINTR0, IRQ_U300_MMCSD_MCIINTR1 }
125 static struct mmci_platform_data mmcsd_platform_data = {
127 * Do not set ocr_mask or voltage translation function,
128 * we have a regulator we can control instead.
132 .gpio_cd = U300_GPIO_PIN_MMC_CD,
134 .capabilities = MMC_CAP_MMC_HIGHSPEED |
135 MMC_CAP_SD_HIGHSPEED | MMC_CAP_4_BIT_DATA | MMC_CAP_8_BIT_DATA,
136 #ifdef CONFIG_COH901318
137 .dma_filter = coh901318_filter_id,
138 .dma_rx_param = (void *) U300_DMA_MMCSD_RX_TX,
139 /* Don't specify a TX channel, this RX channel is bidirectional */
143 static AMBA_APB_DEVICE(mmcsd, "mmci", 0, U300_MMCSD_BASE,
144 U300_MMCSD_IRQS, &mmcsd_platform_data);
147 * The order of device declaration may be important, since some devices
148 * have dependencies on other devices being initialized first.
150 static struct amba_device *amba_devs[] __initdata = {
158 /* Here follows a list of all hw resources that the platform devices
159 * allocate. Note, clock dependencies are not included
162 static struct resource gpio_resources[] = {
164 .start = U300_GPIO_BASE,
165 .end = (U300_GPIO_BASE + SZ_4K - 1),
166 .flags = IORESOURCE_MEM,
170 .start = IRQ_U300_GPIO_PORT0,
171 .end = IRQ_U300_GPIO_PORT0,
172 .flags = IORESOURCE_IRQ,
176 .start = IRQ_U300_GPIO_PORT1,
177 .end = IRQ_U300_GPIO_PORT1,
178 .flags = IORESOURCE_IRQ,
182 .start = IRQ_U300_GPIO_PORT2,
183 .end = IRQ_U300_GPIO_PORT2,
184 .flags = IORESOURCE_IRQ,
188 .start = IRQ_U300_GPIO_PORT3,
189 .end = IRQ_U300_GPIO_PORT3,
190 .flags = IORESOURCE_IRQ,
194 .start = IRQ_U300_GPIO_PORT4,
195 .end = IRQ_U300_GPIO_PORT4,
196 .flags = IORESOURCE_IRQ,
200 .start = IRQ_U300_GPIO_PORT5,
201 .end = IRQ_U300_GPIO_PORT5,
202 .flags = IORESOURCE_IRQ,
206 .start = IRQ_U300_GPIO_PORT6,
207 .end = IRQ_U300_GPIO_PORT6,
208 .flags = IORESOURCE_IRQ,
212 static struct resource keypad_resources[] = {
214 .start = U300_KEYPAD_BASE,
215 .end = U300_KEYPAD_BASE + SZ_4K - 1,
216 .flags = IORESOURCE_MEM,
219 .name = "coh901461-press",
220 .start = IRQ_U300_KEYPAD_KEYBF,
221 .end = IRQ_U300_KEYPAD_KEYBF,
222 .flags = IORESOURCE_IRQ,
225 .name = "coh901461-release",
226 .start = IRQ_U300_KEYPAD_KEYBR,
227 .end = IRQ_U300_KEYPAD_KEYBR,
228 .flags = IORESOURCE_IRQ,
232 static struct resource rtc_resources[] = {
234 .start = U300_RTC_BASE,
235 .end = U300_RTC_BASE + SZ_4K - 1,
236 .flags = IORESOURCE_MEM,
239 .start = IRQ_U300_RTC,
241 .flags = IORESOURCE_IRQ,
246 * Fsmc does have IRQs: #43 and #44 (NFIF and NFIF2)
247 * but these are not yet used by the driver.
249 static struct resource fsmc_resources[] = {
252 .start = U300_NAND_CS0_PHYS_BASE + PLAT_NAND_ALE,
253 .end = U300_NAND_CS0_PHYS_BASE + PLAT_NAND_ALE + SZ_16K - 1,
254 .flags = IORESOURCE_MEM,
258 .start = U300_NAND_CS0_PHYS_BASE + PLAT_NAND_CLE,
259 .end = U300_NAND_CS0_PHYS_BASE + PLAT_NAND_CLE + SZ_16K - 1,
260 .flags = IORESOURCE_MEM,
264 .start = U300_NAND_CS0_PHYS_BASE,
265 .end = U300_NAND_CS0_PHYS_BASE + SZ_16K - 1,
266 .flags = IORESOURCE_MEM,
270 .start = U300_NAND_IF_PHYS_BASE,
271 .end = U300_NAND_IF_PHYS_BASE + SZ_4K - 1,
272 .flags = IORESOURCE_MEM,
276 static struct resource i2c0_resources[] = {
278 .start = U300_I2C0_BASE,
279 .end = U300_I2C0_BASE + SZ_4K - 1,
280 .flags = IORESOURCE_MEM,
283 .start = IRQ_U300_I2C0,
284 .end = IRQ_U300_I2C0,
285 .flags = IORESOURCE_IRQ,
289 static struct resource i2c1_resources[] = {
291 .start = U300_I2C1_BASE,
292 .end = U300_I2C1_BASE + SZ_4K - 1,
293 .flags = IORESOURCE_MEM,
296 .start = IRQ_U300_I2C1,
297 .end = IRQ_U300_I2C1,
298 .flags = IORESOURCE_IRQ,
303 static struct resource wdog_resources[] = {
305 .start = U300_WDOG_BASE,
306 .end = U300_WDOG_BASE + SZ_4K - 1,
307 .flags = IORESOURCE_MEM,
310 .start = IRQ_U300_WDOG,
311 .end = IRQ_U300_WDOG,
312 .flags = IORESOURCE_IRQ,
316 static struct resource dma_resource[] = {
318 .start = U300_DMAC_BASE,
319 .end = U300_DMAC_BASE + PAGE_SIZE - 1,
320 .flags = IORESOURCE_MEM,
323 .start = IRQ_U300_DMA,
325 .flags = IORESOURCE_IRQ,
330 static struct resource pinctrl_resources[] = {
332 .start = U300_SYSCON_BASE,
333 .end = U300_SYSCON_BASE + SZ_4K - 1,
334 .flags = IORESOURCE_MEM,
338 static struct platform_device wdog_device = {
339 .name = "coh901327_wdog",
341 .num_resources = ARRAY_SIZE(wdog_resources),
342 .resource = wdog_resources,
345 static struct platform_device i2c0_device = {
348 .num_resources = ARRAY_SIZE(i2c0_resources),
349 .resource = i2c0_resources,
352 static struct platform_device i2c1_device = {
355 .num_resources = ARRAY_SIZE(i2c1_resources),
356 .resource = i2c1_resources,
359 static struct platform_device pinctrl_device = {
360 .name = "pinctrl-u300",
362 .num_resources = ARRAY_SIZE(pinctrl_resources),
363 .resource = pinctrl_resources,
367 * The different variants have a few different versions of the
368 * GPIO block, with different number of ports.
370 static struct u300_gpio_platform u300_gpio_plat = {
375 static struct platform_device gpio_device = {
378 .num_resources = ARRAY_SIZE(gpio_resources),
379 .resource = gpio_resources,
381 .platform_data = &u300_gpio_plat,
385 static struct platform_device keypad_device = {
388 .num_resources = ARRAY_SIZE(keypad_resources),
389 .resource = keypad_resources,
392 static struct platform_device rtc_device = {
393 .name = "rtc-coh901331",
395 .num_resources = ARRAY_SIZE(rtc_resources),
396 .resource = rtc_resources,
399 static struct mtd_partition u300_partitions[] = {
401 .name = "bootrecords",
408 .size = 8064 * SZ_1K,
412 .offset = 8192 * SZ_1K,
413 .size = 253952 * SZ_1K,
417 static struct fsmc_nand_platform_data nand_platform_data = {
418 .partitions = u300_partitions,
419 .nr_partitions = ARRAY_SIZE(u300_partitions),
420 .options = NAND_SKIP_BBTSCAN,
421 .width = FSMC_NAND_BW8,
424 static struct platform_device nand_device = {
427 .resource = fsmc_resources,
428 .num_resources = ARRAY_SIZE(fsmc_resources),
430 .platform_data = &nand_platform_data,
434 static struct platform_device dma_device = {
437 .resource = dma_resource,
438 .num_resources = ARRAY_SIZE(dma_resource),
440 .coherent_dma_mask = ~0,
444 static unsigned long pin_pullup_conf[] = {
445 PIN_CONF_PACKED(PIN_CONFIG_BIAS_PULL_UP, 1),
448 static unsigned long pin_highz_conf[] = {
449 PIN_CONF_PACKED(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, 0),
452 /* Pin control settings */
453 static struct pinctrl_map __initdata u300_pinmux_map[] = {
454 /* anonymous maps for chip power and EMIFs */
455 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "power"),
456 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif0"),
457 PIN_MAP_MUX_GROUP_HOG_DEFAULT("pinctrl-u300", NULL, "emif1"),
458 /* per-device maps for MMC/SD, SPI and UART */
459 PIN_MAP_MUX_GROUP_DEFAULT("mmci", "pinctrl-u300", NULL, "mmc0"),
460 PIN_MAP_MUX_GROUP_DEFAULT("pl022", "pinctrl-u300", NULL, "spi0"),
461 PIN_MAP_MUX_GROUP_DEFAULT("uart0", "pinctrl-u300", NULL, "uart0"),
462 /* This pin is used for clock return rather than GPIO */
463 PIN_MAP_CONFIGS_PIN_DEFAULT("mmci", "pinctrl-u300", "PIO APP GPIO 11",
465 /* This pin is used for card detect */
466 PIN_MAP_CONFIGS_PIN_DEFAULT("mmci", "pinctrl-u300", "PIO MS INS",
471 * Notice that AMBA devices are initialized before platform devices.
474 static struct platform_device *platform_devs[] __initdata = {
487 * Interrupts: the U300 platforms have two pl190 ARM PrimeCells connected
488 * together so some interrupts are connected to the first one and some
491 static void __init u300_init_irq(void)
493 u32 mask[2] = {0, 0};
497 /* initialize clocking early, we want to clock the INTCON */
498 u300_clk_init(U300_SYSCON_VBASE);
500 /* Bootstrap EMIF and SEMI clocks */
501 clk = clk_get_sys("pl172", NULL);
503 clk_prepare_enable(clk);
504 clk = clk_get_sys("semi", NULL);
506 clk_prepare_enable(clk);
508 /* Clock the interrupt controller */
509 clk = clk_get_sys("intcon", NULL);
511 clk_prepare_enable(clk);
513 for (i = 0; i < U300_VIC_IRQS_END; i++)
514 set_bit(i, (unsigned long *) &mask[0]);
515 vic_init((void __iomem *) U300_INTCON0_VBASE, IRQ_U300_INTCON0_START,
517 vic_init((void __iomem *) U300_INTCON1_VBASE, IRQ_U300_INTCON1_START,
523 * U300 platforms peripheral handling
531 * This is a list of the Digital Baseband chips used in the U300 platform.
533 static struct db_chip db_chips[] __initdata = {
560 .name = "DB3350 P1x",
564 .name = "DB3350 P2x",
567 .chipid = 0x0000, /* List terminator */
572 static void __init u300_init_check_chip(void)
576 struct db_chip *chip;
577 const char *chipname;
578 const char unknown[] = "UNKNOWN";
580 /* Read out and print chip ID */
581 val = readw(U300_SYSCON_VBASE + U300_SYSCON_CIDR);
582 /* This is in funky bigendian order... */
583 val = (val & 0xFFU) << 8 | (val >> 8);
587 for ( ; chip->chipid; chip++) {
588 if (chip->chipid == (val & 0xFF00U)) {
589 chipname = chip->name;
593 printk(KERN_INFO "Initializing U300 system on %s baseband chip " \
594 "(chip ID 0x%04x)\n", chipname, val);
596 if ((val & 0xFF00U) != 0xf000 && (val & 0xFF00U) != 0xf100) {
597 printk(KERN_ERR "Platform configured for BS335 " \
598 " with DB3350 but %s detected, expect problems!",
604 * Some devices and their resources require reserved physical memory from
605 * the end of the available RAM. This function traverses the list of devices
606 * and assigns actual addresses to these.
608 static void __init u300_assign_physmem(void)
610 unsigned long curr_start = __pa(high_memory);
613 for (i = 0; i < ARRAY_SIZE(platform_devs); i++) {
614 for (j = 0; j < platform_devs[i]->num_resources; j++) {
615 struct resource *const res =
616 &platform_devs[i]->resource[j];
618 if (IORESOURCE_MEM == res->flags &&
620 res->start = curr_start;
621 res->end += curr_start;
622 curr_start += resource_size(res);
624 printk(KERN_INFO "core.c: Mapping RAM " \
625 "%#x-%#x to device %s:%s\n",
626 res->start, res->end,
627 platform_devs[i]->name, res->name);
633 static void __init u300_init_machine(void)
638 /* Check what platform we run and print some status information */
639 u300_init_check_chip();
641 /* Initialize SPI device with some board specifics */
642 u300_spi_init(&pl022_device);
644 /* Register the AMBA devices in the AMBA bus abstraction layer */
645 for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
646 struct amba_device *d = amba_devs[i];
647 amba_device_register(d, &iomem_resource);
650 u300_assign_physmem();
652 /* Initialize pinmuxing */
653 pinctrl_register_mappings(u300_pinmux_map,
654 ARRAY_SIZE(u300_pinmux_map));
656 /* Register subdevices on the I2C buses */
657 u300_i2c_register_board_devices();
659 /* Register the platform devices */
660 platform_add_devices(platform_devs, ARRAY_SIZE(platform_devs));
662 /* Register subdevices on the SPI bus */
663 u300_spi_register_board_devices();
665 /* Enable SEMI self refresh */
666 val = readw(U300_SYSCON_VBASE + U300_SYSCON_SMCR) |
667 U300_SYSCON_SMCR_SEMI_SREFREQ_ENABLE;
668 writew(val, U300_SYSCON_VBASE + U300_SYSCON_SMCR);
671 /* Forward declare this function from the watchdog */
672 void coh901327_watchdog_reset(void);
674 static void u300_restart(char mode, const char *cmd)
679 #ifdef CONFIG_COH901327_WATCHDOG
680 coh901327_watchdog_reset();
687 /* Wait for system do die/reset. */
691 MACHINE_START(U300, "Ericsson AB U335 S335/B335 Prototype Board")
692 /* Maintainer: Linus Walleij <linus.walleij@stericsson.com> */
693 .atag_offset = 0x100,
694 .map_io = u300_map_io,
696 .init_irq = u300_init_irq,
697 .init_time = u300_timer_init,
698 .init_machine = u300_init_machine,
699 .restart = u300_restart,