ep93xx: Convert the watchdog driver into a platform device.
[linux-2.6/btrfs-unstable.git] / arch / arm / mach-ep93xx / core.c
blob3134baf6c7a4071a0d25034841871ac856f456d5
1 /*
2 * arch/arm/mach-ep93xx/core.c
3 * Core routines for Cirrus EP93xx chips.
5 * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
6 * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
8 * Thanks go to Michael Burian and Ray Lehtiniemi for their key
9 * role in the ep93xx linux community.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or (at
14 * your option) any later version.
17 #define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/platform_device.h>
22 #include <linux/interrupt.h>
23 #include <linux/dma-mapping.h>
24 #include <linux/timex.h>
25 #include <linux/irq.h>
26 #include <linux/io.h>
27 #include <linux/gpio.h>
28 #include <linux/leds.h>
29 #include <linux/termios.h>
30 #include <linux/amba/bus.h>
31 #include <linux/amba/serial.h>
32 #include <linux/mtd/physmap.h>
33 #include <linux/i2c.h>
34 #include <linux/i2c-gpio.h>
35 #include <linux/spi/spi.h>
36 #include <linux/export.h>
38 #include <mach/hardware.h>
39 #include <mach/fb.h>
40 #include <mach/ep93xx_keypad.h>
41 #include <mach/ep93xx_spi.h>
42 #include <mach/gpio-ep93xx.h>
44 #include <asm/mach/map.h>
45 #include <asm/mach/time.h>
47 #include <asm/hardware/vic.h>
50 /*************************************************************************
51 * Static I/O mappings that are needed for all EP93xx platforms
52 *************************************************************************/
53 static struct map_desc ep93xx_io_desc[] __initdata = {
55 .virtual = EP93XX_AHB_VIRT_BASE,
56 .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
57 .length = EP93XX_AHB_SIZE,
58 .type = MT_DEVICE,
59 }, {
60 .virtual = EP93XX_APB_VIRT_BASE,
61 .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
62 .length = EP93XX_APB_SIZE,
63 .type = MT_DEVICE,
67 void __init ep93xx_map_io(void)
69 iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
73 /*************************************************************************
74 * Timer handling for EP93xx
75 *************************************************************************
76 * The ep93xx has four internal timers. Timers 1, 2 (both 16 bit) and
77 * 3 (32 bit) count down at 508 kHz, are self-reloading, and can generate
78 * an interrupt on underflow. Timer 4 (40 bit) counts down at 983.04 kHz,
79 * is free-running, and can't generate interrupts.
81 * The 508 kHz timers are ideal for use for the timer interrupt, as the
82 * most common values of HZ divide 508 kHz nicely. We pick one of the 16
83 * bit timers (timer 1) since we don't need more than 16 bits of reload
84 * value as long as HZ >= 8.
86 * The higher clock rate of timer 4 makes it a better choice than the
87 * other timers for use in gettimeoffset(), while the fact that it can't
88 * generate interrupts means we don't have to worry about not being able
89 * to use this timer for something else. We also use timer 4 for keeping
90 * track of lost jiffies.
92 #define EP93XX_TIMER_REG(x) (EP93XX_TIMER_BASE + (x))
93 #define EP93XX_TIMER1_LOAD EP93XX_TIMER_REG(0x00)
94 #define EP93XX_TIMER1_VALUE EP93XX_TIMER_REG(0x04)
95 #define EP93XX_TIMER1_CONTROL EP93XX_TIMER_REG(0x08)
96 #define EP93XX_TIMER123_CONTROL_ENABLE (1 << 7)
97 #define EP93XX_TIMER123_CONTROL_MODE (1 << 6)
98 #define EP93XX_TIMER123_CONTROL_CLKSEL (1 << 3)
99 #define EP93XX_TIMER1_CLEAR EP93XX_TIMER_REG(0x0c)
100 #define EP93XX_TIMER2_LOAD EP93XX_TIMER_REG(0x20)
101 #define EP93XX_TIMER2_VALUE EP93XX_TIMER_REG(0x24)
102 #define EP93XX_TIMER2_CONTROL EP93XX_TIMER_REG(0x28)
103 #define EP93XX_TIMER2_CLEAR EP93XX_TIMER_REG(0x2c)
104 #define EP93XX_TIMER4_VALUE_LOW EP93XX_TIMER_REG(0x60)
105 #define EP93XX_TIMER4_VALUE_HIGH EP93XX_TIMER_REG(0x64)
106 #define EP93XX_TIMER4_VALUE_HIGH_ENABLE (1 << 8)
107 #define EP93XX_TIMER3_LOAD EP93XX_TIMER_REG(0x80)
108 #define EP93XX_TIMER3_VALUE EP93XX_TIMER_REG(0x84)
109 #define EP93XX_TIMER3_CONTROL EP93XX_TIMER_REG(0x88)
110 #define EP93XX_TIMER3_CLEAR EP93XX_TIMER_REG(0x8c)
112 #define EP93XX_TIMER123_CLOCK 508469
113 #define EP93XX_TIMER4_CLOCK 983040
115 #define TIMER1_RELOAD ((EP93XX_TIMER123_CLOCK / HZ) - 1)
116 #define TIMER4_TICKS_PER_JIFFY DIV_ROUND_CLOSEST(CLOCK_TICK_RATE, HZ)
118 static unsigned int last_jiffy_time;
120 static irqreturn_t ep93xx_timer_interrupt(int irq, void *dev_id)
122 /* Writing any value clears the timer interrupt */
123 __raw_writel(1, EP93XX_TIMER1_CLEAR);
125 /* Recover lost jiffies */
126 while ((signed long)
127 (__raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time)
128 >= TIMER4_TICKS_PER_JIFFY) {
129 last_jiffy_time += TIMER4_TICKS_PER_JIFFY;
130 timer_tick();
133 return IRQ_HANDLED;
136 static struct irqaction ep93xx_timer_irq = {
137 .name = "ep93xx timer",
138 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
139 .handler = ep93xx_timer_interrupt,
142 static void __init ep93xx_timer_init(void)
144 u32 tmode = EP93XX_TIMER123_CONTROL_MODE |
145 EP93XX_TIMER123_CONTROL_CLKSEL;
147 /* Enable periodic HZ timer. */
148 __raw_writel(tmode, EP93XX_TIMER1_CONTROL);
149 __raw_writel(TIMER1_RELOAD, EP93XX_TIMER1_LOAD);
150 __raw_writel(tmode | EP93XX_TIMER123_CONTROL_ENABLE,
151 EP93XX_TIMER1_CONTROL);
153 /* Enable lost jiffy timer. */
154 __raw_writel(EP93XX_TIMER4_VALUE_HIGH_ENABLE,
155 EP93XX_TIMER4_VALUE_HIGH);
157 setup_irq(IRQ_EP93XX_TIMER1, &ep93xx_timer_irq);
160 static unsigned long ep93xx_gettimeoffset(void)
162 int offset;
164 offset = __raw_readl(EP93XX_TIMER4_VALUE_LOW) - last_jiffy_time;
166 /* Calculate (1000000 / 983040) * offset. */
167 return offset + (53 * offset / 3072);
170 struct sys_timer ep93xx_timer = {
171 .init = ep93xx_timer_init,
172 .offset = ep93xx_gettimeoffset,
176 /*************************************************************************
177 * EP93xx IRQ handling
178 *************************************************************************/
179 void __init ep93xx_init_irq(void)
181 vic_init(EP93XX_VIC1_BASE, 0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
182 vic_init(EP93XX_VIC2_BASE, 32, EP93XX_VIC2_VALID_IRQ_MASK, 0);
186 /*************************************************************************
187 * EP93xx System Controller Software Locked register handling
188 *************************************************************************/
191 * syscon_swlock prevents anything else from writing to the syscon
192 * block while a software locked register is being written.
194 static DEFINE_SPINLOCK(syscon_swlock);
196 void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
198 unsigned long flags;
200 spin_lock_irqsave(&syscon_swlock, flags);
202 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
203 __raw_writel(val, reg);
205 spin_unlock_irqrestore(&syscon_swlock, flags);
207 EXPORT_SYMBOL(ep93xx_syscon_swlocked_write);
209 void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
211 unsigned long flags;
212 unsigned int val;
214 spin_lock_irqsave(&syscon_swlock, flags);
216 val = __raw_readl(EP93XX_SYSCON_DEVCFG);
217 val &= ~clear_bits;
218 val |= set_bits;
219 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
220 __raw_writel(val, EP93XX_SYSCON_DEVCFG);
222 spin_unlock_irqrestore(&syscon_swlock, flags);
224 EXPORT_SYMBOL(ep93xx_devcfg_set_clear);
227 * ep93xx_chip_revision() - returns the EP93xx chip revision
229 * See <mach/platform.h> for more information.
231 unsigned int ep93xx_chip_revision(void)
233 unsigned int v;
235 v = __raw_readl(EP93XX_SYSCON_SYSCFG);
236 v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
237 v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
238 return v;
241 /*************************************************************************
242 * EP93xx GPIO
243 *************************************************************************/
244 static struct resource ep93xx_gpio_resource[] = {
246 .start = EP93XX_GPIO_PHYS_BASE,
247 .end = EP93XX_GPIO_PHYS_BASE + 0xcc - 1,
248 .flags = IORESOURCE_MEM,
252 static struct platform_device ep93xx_gpio_device = {
253 .name = "gpio-ep93xx",
254 .id = -1,
255 .num_resources = ARRAY_SIZE(ep93xx_gpio_resource),
256 .resource = ep93xx_gpio_resource,
259 /*************************************************************************
260 * EP93xx peripheral handling
261 *************************************************************************/
262 #define EP93XX_UART_MCR_OFFSET (0x0100)
264 static void ep93xx_uart_set_mctrl(struct amba_device *dev,
265 void __iomem *base, unsigned int mctrl)
267 unsigned int mcr;
269 mcr = 0;
270 if (mctrl & TIOCM_RTS)
271 mcr |= 2;
272 if (mctrl & TIOCM_DTR)
273 mcr |= 1;
275 __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
278 static struct amba_pl010_data ep93xx_uart_data = {
279 .set_mctrl = ep93xx_uart_set_mctrl,
282 static struct amba_device uart1_device = {
283 .dev = {
284 .init_name = "apb:uart1",
285 .platform_data = &ep93xx_uart_data,
287 .res = {
288 .start = EP93XX_UART1_PHYS_BASE,
289 .end = EP93XX_UART1_PHYS_BASE + 0x0fff,
290 .flags = IORESOURCE_MEM,
292 .irq = { IRQ_EP93XX_UART1, NO_IRQ },
293 .periphid = 0x00041010,
296 static struct amba_device uart2_device = {
297 .dev = {
298 .init_name = "apb:uart2",
299 .platform_data = &ep93xx_uart_data,
301 .res = {
302 .start = EP93XX_UART2_PHYS_BASE,
303 .end = EP93XX_UART2_PHYS_BASE + 0x0fff,
304 .flags = IORESOURCE_MEM,
306 .irq = { IRQ_EP93XX_UART2, NO_IRQ },
307 .periphid = 0x00041010,
310 static struct amba_device uart3_device = {
311 .dev = {
312 .init_name = "apb:uart3",
313 .platform_data = &ep93xx_uart_data,
315 .res = {
316 .start = EP93XX_UART3_PHYS_BASE,
317 .end = EP93XX_UART3_PHYS_BASE + 0x0fff,
318 .flags = IORESOURCE_MEM,
320 .irq = { IRQ_EP93XX_UART3, NO_IRQ },
321 .periphid = 0x00041010,
325 static struct resource ep93xx_rtc_resource[] = {
327 .start = EP93XX_RTC_PHYS_BASE,
328 .end = EP93XX_RTC_PHYS_BASE + 0x10c - 1,
329 .flags = IORESOURCE_MEM,
333 static struct platform_device ep93xx_rtc_device = {
334 .name = "ep93xx-rtc",
335 .id = -1,
336 .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
337 .resource = ep93xx_rtc_resource,
341 static struct resource ep93xx_ohci_resources[] = {
342 [0] = {
343 .start = EP93XX_USB_PHYS_BASE,
344 .end = EP93XX_USB_PHYS_BASE + 0x0fff,
345 .flags = IORESOURCE_MEM,
347 [1] = {
348 .start = IRQ_EP93XX_USB,
349 .end = IRQ_EP93XX_USB,
350 .flags = IORESOURCE_IRQ,
355 static struct platform_device ep93xx_ohci_device = {
356 .name = "ep93xx-ohci",
357 .id = -1,
358 .dev = {
359 .dma_mask = &ep93xx_ohci_device.dev.coherent_dma_mask,
360 .coherent_dma_mask = DMA_BIT_MASK(32),
362 .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
363 .resource = ep93xx_ohci_resources,
367 /*************************************************************************
368 * EP93xx physmap'ed flash
369 *************************************************************************/
370 static struct physmap_flash_data ep93xx_flash_data;
372 static struct resource ep93xx_flash_resource = {
373 .flags = IORESOURCE_MEM,
376 static struct platform_device ep93xx_flash = {
377 .name = "physmap-flash",
378 .id = 0,
379 .dev = {
380 .platform_data = &ep93xx_flash_data,
382 .num_resources = 1,
383 .resource = &ep93xx_flash_resource,
387 * ep93xx_register_flash() - Register the external flash device.
388 * @width: bank width in octets
389 * @start: resource start address
390 * @size: resource size
392 void __init ep93xx_register_flash(unsigned int width,
393 resource_size_t start, resource_size_t size)
395 ep93xx_flash_data.width = width;
397 ep93xx_flash_resource.start = start;
398 ep93xx_flash_resource.end = start + size - 1;
400 platform_device_register(&ep93xx_flash);
404 /*************************************************************************
405 * EP93xx ethernet peripheral handling
406 *************************************************************************/
407 static struct ep93xx_eth_data ep93xx_eth_data;
409 static struct resource ep93xx_eth_resource[] = {
411 .start = EP93XX_ETHERNET_PHYS_BASE,
412 .end = EP93XX_ETHERNET_PHYS_BASE + 0xffff,
413 .flags = IORESOURCE_MEM,
414 }, {
415 .start = IRQ_EP93XX_ETHERNET,
416 .end = IRQ_EP93XX_ETHERNET,
417 .flags = IORESOURCE_IRQ,
421 static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
423 static struct platform_device ep93xx_eth_device = {
424 .name = "ep93xx-eth",
425 .id = -1,
426 .dev = {
427 .platform_data = &ep93xx_eth_data,
428 .coherent_dma_mask = DMA_BIT_MASK(32),
429 .dma_mask = &ep93xx_eth_dma_mask,
431 .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
432 .resource = ep93xx_eth_resource,
436 * ep93xx_register_eth - Register the built-in ethernet platform device.
437 * @data: platform specific ethernet configuration (__initdata)
438 * @copy_addr: flag indicating that the MAC address should be copied
439 * from the IndAd registers (as programmed by the bootloader)
441 void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
443 if (copy_addr)
444 memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
446 ep93xx_eth_data = *data;
447 platform_device_register(&ep93xx_eth_device);
451 /*************************************************************************
452 * EP93xx i2c peripheral handling
453 *************************************************************************/
454 static struct i2c_gpio_platform_data ep93xx_i2c_data;
456 static struct platform_device ep93xx_i2c_device = {
457 .name = "i2c-gpio",
458 .id = 0,
459 .dev = {
460 .platform_data = &ep93xx_i2c_data,
465 * ep93xx_register_i2c - Register the i2c platform device.
466 * @data: platform specific i2c-gpio configuration (__initdata)
467 * @devices: platform specific i2c bus device information (__initdata)
468 * @num: the number of devices on the i2c bus
470 void __init ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
471 struct i2c_board_info *devices, int num)
474 * Set the EEPROM interface pin drive type control.
475 * Defines the driver type for the EECLK and EEDAT pins as either
476 * open drain, which will require an external pull-up, or a normal
477 * CMOS driver.
479 if (data->sda_is_open_drain && data->sda_pin != EP93XX_GPIO_LINE_EEDAT)
480 pr_warning("sda != EEDAT, open drain has no effect\n");
481 if (data->scl_is_open_drain && data->scl_pin != EP93XX_GPIO_LINE_EECLK)
482 pr_warning("scl != EECLK, open drain has no effect\n");
484 __raw_writel((data->sda_is_open_drain << 1) |
485 (data->scl_is_open_drain << 0),
486 EP93XX_GPIO_EEDRIVE);
488 ep93xx_i2c_data = *data;
489 i2c_register_board_info(0, devices, num);
490 platform_device_register(&ep93xx_i2c_device);
493 /*************************************************************************
494 * EP93xx SPI peripheral handling
495 *************************************************************************/
496 static struct ep93xx_spi_info ep93xx_spi_master_data;
498 static struct resource ep93xx_spi_resources[] = {
500 .start = EP93XX_SPI_PHYS_BASE,
501 .end = EP93XX_SPI_PHYS_BASE + 0x18 - 1,
502 .flags = IORESOURCE_MEM,
505 .start = IRQ_EP93XX_SSP,
506 .end = IRQ_EP93XX_SSP,
507 .flags = IORESOURCE_IRQ,
511 static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
513 static struct platform_device ep93xx_spi_device = {
514 .name = "ep93xx-spi",
515 .id = 0,
516 .dev = {
517 .platform_data = &ep93xx_spi_master_data,
518 .coherent_dma_mask = DMA_BIT_MASK(32),
519 .dma_mask = &ep93xx_spi_dma_mask,
521 .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
522 .resource = ep93xx_spi_resources,
526 * ep93xx_register_spi() - registers spi platform device
527 * @info: ep93xx board specific spi master info (__initdata)
528 * @devices: SPI devices to register (__initdata)
529 * @num: number of SPI devices to register
531 * This function registers platform device for the EP93xx SPI controller and
532 * also makes sure that SPI pins are muxed so that I2S is not using those pins.
534 void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
535 struct spi_board_info *devices, int num)
538 * When SPI is used, we need to make sure that I2S is muxed off from
539 * SPI pins.
541 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
543 ep93xx_spi_master_data = *info;
544 spi_register_board_info(devices, num);
545 platform_device_register(&ep93xx_spi_device);
548 /*************************************************************************
549 * EP93xx LEDs
550 *************************************************************************/
551 static struct gpio_led ep93xx_led_pins[] = {
553 .name = "platform:grled",
554 .gpio = EP93XX_GPIO_LINE_GRLED,
555 }, {
556 .name = "platform:rdled",
557 .gpio = EP93XX_GPIO_LINE_RDLED,
561 static struct gpio_led_platform_data ep93xx_led_data = {
562 .num_leds = ARRAY_SIZE(ep93xx_led_pins),
563 .leds = ep93xx_led_pins,
566 static struct platform_device ep93xx_leds = {
567 .name = "leds-gpio",
568 .id = -1,
569 .dev = {
570 .platform_data = &ep93xx_led_data,
575 /*************************************************************************
576 * EP93xx pwm peripheral handling
577 *************************************************************************/
578 static struct resource ep93xx_pwm0_resource[] = {
580 .start = EP93XX_PWM_PHYS_BASE,
581 .end = EP93XX_PWM_PHYS_BASE + 0x10 - 1,
582 .flags = IORESOURCE_MEM,
586 static struct platform_device ep93xx_pwm0_device = {
587 .name = "ep93xx-pwm",
588 .id = 0,
589 .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
590 .resource = ep93xx_pwm0_resource,
593 static struct resource ep93xx_pwm1_resource[] = {
595 .start = EP93XX_PWM_PHYS_BASE + 0x20,
596 .end = EP93XX_PWM_PHYS_BASE + 0x30 - 1,
597 .flags = IORESOURCE_MEM,
601 static struct platform_device ep93xx_pwm1_device = {
602 .name = "ep93xx-pwm",
603 .id = 1,
604 .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
605 .resource = ep93xx_pwm1_resource,
608 void __init ep93xx_register_pwm(int pwm0, int pwm1)
610 if (pwm0)
611 platform_device_register(&ep93xx_pwm0_device);
613 /* NOTE: EP9307 does not have PWMOUT1 (pin EGPIO14) */
614 if (pwm1)
615 platform_device_register(&ep93xx_pwm1_device);
618 int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
620 int err;
622 if (pdev->id == 0) {
623 err = 0;
624 } else if (pdev->id == 1) {
625 err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
626 dev_name(&pdev->dev));
627 if (err)
628 return err;
629 err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
630 if (err)
631 goto fail;
633 /* PWM 1 output on EGPIO[14] */
634 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
635 } else {
636 err = -ENODEV;
639 return err;
641 fail:
642 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
643 return err;
645 EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
647 void ep93xx_pwm_release_gpio(struct platform_device *pdev)
649 if (pdev->id == 1) {
650 gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
651 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
653 /* EGPIO[14] used for GPIO */
654 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
657 EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
660 /*************************************************************************
661 * EP93xx video peripheral handling
662 *************************************************************************/
663 static struct ep93xxfb_mach_info ep93xxfb_data;
665 static struct resource ep93xx_fb_resource[] = {
667 .start = EP93XX_RASTER_PHYS_BASE,
668 .end = EP93XX_RASTER_PHYS_BASE + 0x800 - 1,
669 .flags = IORESOURCE_MEM,
673 static struct platform_device ep93xx_fb_device = {
674 .name = "ep93xx-fb",
675 .id = -1,
676 .dev = {
677 .platform_data = &ep93xxfb_data,
678 .coherent_dma_mask = DMA_BIT_MASK(32),
679 .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
681 .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
682 .resource = ep93xx_fb_resource,
685 /* The backlight use a single register in the framebuffer's register space */
686 #define EP93XX_RASTER_REG_BRIGHTNESS 0x20
688 static struct resource ep93xx_bl_resources[] = {
689 DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE +
690 EP93XX_RASTER_REG_BRIGHTNESS, 0x04),
693 static struct platform_device ep93xx_bl_device = {
694 .name = "ep93xx-bl",
695 .id = -1,
696 .num_resources = ARRAY_SIZE(ep93xx_bl_resources),
697 .resource = ep93xx_bl_resources,
701 * ep93xx_register_fb - Register the framebuffer platform device.
702 * @data: platform specific framebuffer configuration (__initdata)
704 void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
706 ep93xxfb_data = *data;
707 platform_device_register(&ep93xx_fb_device);
708 platform_device_register(&ep93xx_bl_device);
712 /*************************************************************************
713 * EP93xx matrix keypad peripheral handling
714 *************************************************************************/
715 static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
717 static struct resource ep93xx_keypad_resource[] = {
719 .start = EP93XX_KEY_MATRIX_PHYS_BASE,
720 .end = EP93XX_KEY_MATRIX_PHYS_BASE + 0x0c - 1,
721 .flags = IORESOURCE_MEM,
722 }, {
723 .start = IRQ_EP93XX_KEY,
724 .end = IRQ_EP93XX_KEY,
725 .flags = IORESOURCE_IRQ,
729 static struct platform_device ep93xx_keypad_device = {
730 .name = "ep93xx-keypad",
731 .id = -1,
732 .dev = {
733 .platform_data = &ep93xx_keypad_data,
735 .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
736 .resource = ep93xx_keypad_resource,
740 * ep93xx_register_keypad - Register the keypad platform device.
741 * @data: platform specific keypad configuration (__initdata)
743 void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
745 ep93xx_keypad_data = *data;
746 platform_device_register(&ep93xx_keypad_device);
749 int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
751 int err;
752 int i;
754 for (i = 0; i < 8; i++) {
755 err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
756 if (err)
757 goto fail_gpio_c;
758 err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
759 if (err)
760 goto fail_gpio_d;
763 /* Enable the keypad controller; GPIO ports C and D used for keypad */
764 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
765 EP93XX_SYSCON_DEVCFG_GONK);
767 return 0;
769 fail_gpio_d:
770 gpio_free(EP93XX_GPIO_LINE_C(i));
771 fail_gpio_c:
772 for ( ; i >= 0; --i) {
773 gpio_free(EP93XX_GPIO_LINE_C(i));
774 gpio_free(EP93XX_GPIO_LINE_D(i));
776 return err;
778 EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
780 void ep93xx_keypad_release_gpio(struct platform_device *pdev)
782 int i;
784 for (i = 0; i < 8; i++) {
785 gpio_free(EP93XX_GPIO_LINE_C(i));
786 gpio_free(EP93XX_GPIO_LINE_D(i));
789 /* Disable the keypad controller; GPIO ports C and D used for GPIO */
790 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
791 EP93XX_SYSCON_DEVCFG_GONK);
793 EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
795 /*************************************************************************
796 * EP93xx I2S audio peripheral handling
797 *************************************************************************/
798 static struct resource ep93xx_i2s_resource[] = {
800 .start = EP93XX_I2S_PHYS_BASE,
801 .end = EP93XX_I2S_PHYS_BASE + 0x100 - 1,
802 .flags = IORESOURCE_MEM,
806 static struct platform_device ep93xx_i2s_device = {
807 .name = "ep93xx-i2s",
808 .id = -1,
809 .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
810 .resource = ep93xx_i2s_resource,
813 static struct platform_device ep93xx_pcm_device = {
814 .name = "ep93xx-pcm-audio",
815 .id = -1,
818 void __init ep93xx_register_i2s(void)
820 platform_device_register(&ep93xx_i2s_device);
821 platform_device_register(&ep93xx_pcm_device);
824 #define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \
825 EP93XX_SYSCON_DEVCFG_I2SONAC97)
827 #define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
828 EP93XX_SYSCON_I2SCLKDIV_SPOL)
830 int ep93xx_i2s_acquire(void)
832 unsigned val;
834 ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_I2SONAC97,
835 EP93XX_SYSCON_DEVCFG_I2S_MASK);
838 * This is potentially racy with the clock api for i2s_mclk, sclk and
839 * lrclk. Since the i2s driver is the only user of those clocks we
840 * rely on it to prevent parallel use of this function and the
841 * clock api for the i2s clocks.
843 val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
844 val &= ~EP93XX_I2SCLKDIV_MASK;
845 val |= EP93XX_SYSCON_I2SCLKDIV_ORIDE | EP93XX_SYSCON_I2SCLKDIV_SPOL;
846 ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
848 return 0;
850 EXPORT_SYMBOL(ep93xx_i2s_acquire);
852 void ep93xx_i2s_release(void)
854 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
856 EXPORT_SYMBOL(ep93xx_i2s_release);
858 /*************************************************************************
859 * EP93xx AC97 audio peripheral handling
860 *************************************************************************/
861 static struct resource ep93xx_ac97_resources[] = {
863 .start = EP93XX_AAC_PHYS_BASE,
864 .end = EP93XX_AAC_PHYS_BASE + 0xac - 1,
865 .flags = IORESOURCE_MEM,
868 .start = IRQ_EP93XX_AACINTR,
869 .end = IRQ_EP93XX_AACINTR,
870 .flags = IORESOURCE_IRQ,
874 static struct platform_device ep93xx_ac97_device = {
875 .name = "ep93xx-ac97",
876 .id = -1,
877 .num_resources = ARRAY_SIZE(ep93xx_ac97_resources),
878 .resource = ep93xx_ac97_resources,
881 void __init ep93xx_register_ac97(void)
884 * Make sure that the AC97 pins are not used by I2S.
886 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
888 platform_device_register(&ep93xx_ac97_device);
889 platform_device_register(&ep93xx_pcm_device);
892 /*************************************************************************
893 * EP93xx Watchdog
894 *************************************************************************/
895 static struct resource ep93xx_wdt_resources[] = {
896 DEFINE_RES_MEM(EP93XX_WATCHDOG_PHYS_BASE, 0x08),
899 static struct platform_device ep93xx_wdt_device = {
900 .name = "ep93xx-wdt",
901 .id = -1,
902 .num_resources = ARRAY_SIZE(ep93xx_wdt_resources),
903 .resource = ep93xx_wdt_resources,
906 void __init ep93xx_init_devices(void)
908 /* Disallow access to MaverickCrunch initially */
909 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
911 /* Get the GPIO working early, other devices need it */
912 platform_device_register(&ep93xx_gpio_device);
914 amba_device_register(&uart1_device, &iomem_resource);
915 amba_device_register(&uart2_device, &iomem_resource);
916 amba_device_register(&uart3_device, &iomem_resource);
918 platform_device_register(&ep93xx_rtc_device);
919 platform_device_register(&ep93xx_ohci_device);
920 platform_device_register(&ep93xx_leds);
921 platform_device_register(&ep93xx_wdt_device);
924 void ep93xx_restart(char mode, const char *cmd)
927 * Set then clear the SWRST bit to initiate a software reset
929 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST);
930 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST);
932 while (1)