0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #define pr_fmt(fmt) "ep93xx " KBUILD_MODNAME ": " fmt
0014
0015 #include <linux/kernel.h>
0016 #include <linux/init.h>
0017 #include <linux/platform_device.h>
0018 #include <linux/interrupt.h>
0019 #include <linux/dma-mapping.h>
0020 #include <linux/sys_soc.h>
0021 #include <linux/irq.h>
0022 #include <linux/io.h>
0023 #include <linux/gpio.h>
0024 #include <linux/leds.h>
0025 #include <linux/termios.h>
0026 #include <linux/amba/bus.h>
0027 #include <linux/amba/serial.h>
0028 #include <linux/mtd/physmap.h>
0029 #include <linux/i2c.h>
0030 #include <linux/gpio/machine.h>
0031 #include <linux/spi/spi.h>
0032 #include <linux/export.h>
0033 #include <linux/irqchip/arm-vic.h>
0034 #include <linux/reboot.h>
0035 #include <linux/usb/ohci_pdriver.h>
0036 #include <linux/random.h>
0037
0038 #include "hardware.h"
0039 #include <linux/platform_data/video-ep93xx.h>
0040 #include <linux/platform_data/keypad-ep93xx.h>
0041 #include <linux/platform_data/spi-ep93xx.h>
0042 #include <linux/soc/cirrus/ep93xx.h>
0043
0044 #include "gpio-ep93xx.h"
0045
0046 #include <asm/mach/arch.h>
0047 #include <asm/mach/map.h>
0048
0049 #include "soc.h"
0050 #include "irqs.h"
0051
0052
0053
0054
0055 static struct map_desc ep93xx_io_desc[] __initdata = {
0056 {
0057 .virtual = EP93XX_AHB_VIRT_BASE,
0058 .pfn = __phys_to_pfn(EP93XX_AHB_PHYS_BASE),
0059 .length = EP93XX_AHB_SIZE,
0060 .type = MT_DEVICE,
0061 }, {
0062 .virtual = EP93XX_APB_VIRT_BASE,
0063 .pfn = __phys_to_pfn(EP93XX_APB_PHYS_BASE),
0064 .length = EP93XX_APB_SIZE,
0065 .type = MT_DEVICE,
0066 },
0067 };
0068
0069 void __init ep93xx_map_io(void)
0070 {
0071 iotable_init(ep93xx_io_desc, ARRAY_SIZE(ep93xx_io_desc));
0072 }
0073
0074
0075
0076
0077 void __init ep93xx_init_irq(void)
0078 {
0079 vic_init(EP93XX_VIC1_BASE, IRQ_EP93XX_VIC0, EP93XX_VIC1_VALID_IRQ_MASK, 0);
0080 vic_init(EP93XX_VIC2_BASE, IRQ_EP93XX_VIC1, EP93XX_VIC2_VALID_IRQ_MASK, 0);
0081 }
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092 static DEFINE_SPINLOCK(syscon_swlock);
0093
0094 void ep93xx_syscon_swlocked_write(unsigned int val, void __iomem *reg)
0095 {
0096 unsigned long flags;
0097
0098 spin_lock_irqsave(&syscon_swlock, flags);
0099
0100 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
0101 __raw_writel(val, reg);
0102
0103 spin_unlock_irqrestore(&syscon_swlock, flags);
0104 }
0105
0106 void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
0107 {
0108 unsigned long flags;
0109 unsigned int val;
0110
0111 spin_lock_irqsave(&syscon_swlock, flags);
0112
0113 val = __raw_readl(EP93XX_SYSCON_DEVCFG);
0114 val &= ~clear_bits;
0115 val |= set_bits;
0116 __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
0117 __raw_writel(val, EP93XX_SYSCON_DEVCFG);
0118
0119 spin_unlock_irqrestore(&syscon_swlock, flags);
0120 }
0121
0122
0123
0124
0125
0126
0127 unsigned int ep93xx_chip_revision(void)
0128 {
0129 unsigned int v;
0130
0131 v = __raw_readl(EP93XX_SYSCON_SYSCFG);
0132 v &= EP93XX_SYSCON_SYSCFG_REV_MASK;
0133 v >>= EP93XX_SYSCON_SYSCFG_REV_SHIFT;
0134 return v;
0135 }
0136 EXPORT_SYMBOL_GPL(ep93xx_chip_revision);
0137
0138
0139
0140
0141 static struct resource ep93xx_gpio_resource[] = {
0142 DEFINE_RES_MEM(EP93XX_GPIO_PHYS_BASE, 0xcc),
0143 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO_AB),
0144 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO0MUX),
0145 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO1MUX),
0146 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO2MUX),
0147 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO3MUX),
0148 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO4MUX),
0149 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO5MUX),
0150 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO6MUX),
0151 DEFINE_RES_IRQ(IRQ_EP93XX_GPIO7MUX),
0152 };
0153
0154 static struct platform_device ep93xx_gpio_device = {
0155 .name = "gpio-ep93xx",
0156 .id = -1,
0157 .num_resources = ARRAY_SIZE(ep93xx_gpio_resource),
0158 .resource = ep93xx_gpio_resource,
0159 };
0160
0161
0162
0163
0164 #define EP93XX_UART_MCR_OFFSET (0x0100)
0165
0166 static void ep93xx_uart_set_mctrl(struct amba_device *dev,
0167 void __iomem *base, unsigned int mctrl)
0168 {
0169 unsigned int mcr;
0170
0171 mcr = 0;
0172 if (mctrl & TIOCM_RTS)
0173 mcr |= 2;
0174 if (mctrl & TIOCM_DTR)
0175 mcr |= 1;
0176
0177 __raw_writel(mcr, base + EP93XX_UART_MCR_OFFSET);
0178 }
0179
0180 static struct amba_pl010_data ep93xx_uart_data = {
0181 .set_mctrl = ep93xx_uart_set_mctrl,
0182 };
0183
0184 static AMBA_APB_DEVICE(uart1, "apb:uart1", 0x00041010, EP93XX_UART1_PHYS_BASE,
0185 { IRQ_EP93XX_UART1 }, &ep93xx_uart_data);
0186
0187 static AMBA_APB_DEVICE(uart2, "apb:uart2", 0x00041010, EP93XX_UART2_PHYS_BASE,
0188 { IRQ_EP93XX_UART2 }, NULL);
0189
0190 static AMBA_APB_DEVICE(uart3, "apb:uart3", 0x00041010, EP93XX_UART3_PHYS_BASE,
0191 { IRQ_EP93XX_UART3 }, &ep93xx_uart_data);
0192
0193 static struct resource ep93xx_rtc_resource[] = {
0194 DEFINE_RES_MEM(EP93XX_RTC_PHYS_BASE, 0x10c),
0195 };
0196
0197 static struct platform_device ep93xx_rtc_device = {
0198 .name = "ep93xx-rtc",
0199 .id = -1,
0200 .num_resources = ARRAY_SIZE(ep93xx_rtc_resource),
0201 .resource = ep93xx_rtc_resource,
0202 };
0203
0204
0205
0206
0207
0208 static struct clk *ep93xx_ohci_host_clock;
0209
0210 static int ep93xx_ohci_power_on(struct platform_device *pdev)
0211 {
0212 if (!ep93xx_ohci_host_clock) {
0213 ep93xx_ohci_host_clock = devm_clk_get(&pdev->dev, NULL);
0214 if (IS_ERR(ep93xx_ohci_host_clock))
0215 return PTR_ERR(ep93xx_ohci_host_clock);
0216 }
0217
0218 return clk_prepare_enable(ep93xx_ohci_host_clock);
0219 }
0220
0221 static void ep93xx_ohci_power_off(struct platform_device *pdev)
0222 {
0223 clk_disable(ep93xx_ohci_host_clock);
0224 }
0225
0226 static struct usb_ohci_pdata ep93xx_ohci_pdata = {
0227 .power_on = ep93xx_ohci_power_on,
0228 .power_off = ep93xx_ohci_power_off,
0229 .power_suspend = ep93xx_ohci_power_off,
0230 };
0231
0232 static struct resource ep93xx_ohci_resources[] = {
0233 DEFINE_RES_MEM(EP93XX_USB_PHYS_BASE, 0x1000),
0234 DEFINE_RES_IRQ(IRQ_EP93XX_USB),
0235 };
0236
0237 static u64 ep93xx_ohci_dma_mask = DMA_BIT_MASK(32);
0238
0239 static struct platform_device ep93xx_ohci_device = {
0240 .name = "ohci-platform",
0241 .id = -1,
0242 .num_resources = ARRAY_SIZE(ep93xx_ohci_resources),
0243 .resource = ep93xx_ohci_resources,
0244 .dev = {
0245 .dma_mask = &ep93xx_ohci_dma_mask,
0246 .coherent_dma_mask = DMA_BIT_MASK(32),
0247 .platform_data = &ep93xx_ohci_pdata,
0248 },
0249 };
0250
0251
0252
0253
0254 static struct physmap_flash_data ep93xx_flash_data;
0255
0256 static struct resource ep93xx_flash_resource = {
0257 .flags = IORESOURCE_MEM,
0258 };
0259
0260 static struct platform_device ep93xx_flash = {
0261 .name = "physmap-flash",
0262 .id = 0,
0263 .dev = {
0264 .platform_data = &ep93xx_flash_data,
0265 },
0266 .num_resources = 1,
0267 .resource = &ep93xx_flash_resource,
0268 };
0269
0270
0271
0272
0273
0274
0275
0276 void __init ep93xx_register_flash(unsigned int width,
0277 resource_size_t start, resource_size_t size)
0278 {
0279 ep93xx_flash_data.width = width;
0280
0281 ep93xx_flash_resource.start = start;
0282 ep93xx_flash_resource.end = start + size - 1;
0283
0284 platform_device_register(&ep93xx_flash);
0285 }
0286
0287
0288
0289
0290
0291 static struct ep93xx_eth_data ep93xx_eth_data;
0292
0293 static struct resource ep93xx_eth_resource[] = {
0294 DEFINE_RES_MEM(EP93XX_ETHERNET_PHYS_BASE, 0x10000),
0295 DEFINE_RES_IRQ(IRQ_EP93XX_ETHERNET),
0296 };
0297
0298 static u64 ep93xx_eth_dma_mask = DMA_BIT_MASK(32);
0299
0300 static struct platform_device ep93xx_eth_device = {
0301 .name = "ep93xx-eth",
0302 .id = -1,
0303 .dev = {
0304 .platform_data = &ep93xx_eth_data,
0305 .coherent_dma_mask = DMA_BIT_MASK(32),
0306 .dma_mask = &ep93xx_eth_dma_mask,
0307 },
0308 .num_resources = ARRAY_SIZE(ep93xx_eth_resource),
0309 .resource = ep93xx_eth_resource,
0310 };
0311
0312
0313
0314
0315
0316
0317
0318 void __init ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr)
0319 {
0320 if (copy_addr)
0321 memcpy_fromio(data->dev_addr, EP93XX_ETHERNET_BASE + 0x50, 6);
0322
0323 ep93xx_eth_data = *data;
0324 platform_device_register(&ep93xx_eth_device);
0325 }
0326
0327
0328
0329
0330
0331
0332
0333 static struct gpiod_lookup_table ep93xx_i2c_gpiod_table = {
0334 .dev_id = "i2c-gpio.0",
0335 .table = {
0336
0337 GPIO_LOOKUP_IDX("G", 1, NULL, 0,
0338 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
0339 GPIO_LOOKUP_IDX("G", 0, NULL, 1,
0340 GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN),
0341 },
0342 };
0343
0344 static struct platform_device ep93xx_i2c_device = {
0345 .name = "i2c-gpio",
0346 .id = 0,
0347 .dev = {
0348 .platform_data = NULL,
0349 },
0350 };
0351
0352
0353
0354
0355
0356
0357 void __init ep93xx_register_i2c(struct i2c_board_info *devices, int num)
0358 {
0359
0360
0361
0362
0363
0364
0365
0366
0367 __raw_writel((0 << 1) | (0 << 0),
0368 EP93XX_GPIO_EEDRIVE);
0369
0370 i2c_register_board_info(0, devices, num);
0371 gpiod_add_lookup_table(&ep93xx_i2c_gpiod_table);
0372 platform_device_register(&ep93xx_i2c_device);
0373 }
0374
0375
0376
0377
0378 static struct ep93xx_spi_info ep93xx_spi_master_data;
0379
0380 static struct resource ep93xx_spi_resources[] = {
0381 DEFINE_RES_MEM(EP93XX_SPI_PHYS_BASE, 0x18),
0382 DEFINE_RES_IRQ(IRQ_EP93XX_SSP),
0383 };
0384
0385 static u64 ep93xx_spi_dma_mask = DMA_BIT_MASK(32);
0386
0387 static struct platform_device ep93xx_spi_device = {
0388 .name = "ep93xx-spi",
0389 .id = 0,
0390 .dev = {
0391 .platform_data = &ep93xx_spi_master_data,
0392 .coherent_dma_mask = DMA_BIT_MASK(32),
0393 .dma_mask = &ep93xx_spi_dma_mask,
0394 },
0395 .num_resources = ARRAY_SIZE(ep93xx_spi_resources),
0396 .resource = ep93xx_spi_resources,
0397 };
0398
0399
0400
0401
0402
0403
0404
0405
0406
0407
0408 void __init ep93xx_register_spi(struct ep93xx_spi_info *info,
0409 struct spi_board_info *devices, int num)
0410 {
0411
0412
0413
0414
0415 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONSSP);
0416
0417 ep93xx_spi_master_data = *info;
0418 spi_register_board_info(devices, num);
0419 platform_device_register(&ep93xx_spi_device);
0420 }
0421
0422
0423
0424
0425 static const struct gpio_led ep93xx_led_pins[] __initconst = {
0426 {
0427 .name = "platform:grled",
0428 .gpio = EP93XX_GPIO_LINE_GRLED,
0429 }, {
0430 .name = "platform:rdled",
0431 .gpio = EP93XX_GPIO_LINE_RDLED,
0432 },
0433 };
0434
0435 static const struct gpio_led_platform_data ep93xx_led_data __initconst = {
0436 .num_leds = ARRAY_SIZE(ep93xx_led_pins),
0437 .leds = ep93xx_led_pins,
0438 };
0439
0440
0441
0442
0443 static struct resource ep93xx_pwm0_resource[] = {
0444 DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE, 0x10),
0445 };
0446
0447 static struct platform_device ep93xx_pwm0_device = {
0448 .name = "ep93xx-pwm",
0449 .id = 0,
0450 .num_resources = ARRAY_SIZE(ep93xx_pwm0_resource),
0451 .resource = ep93xx_pwm0_resource,
0452 };
0453
0454 static struct resource ep93xx_pwm1_resource[] = {
0455 DEFINE_RES_MEM(EP93XX_PWM_PHYS_BASE + 0x20, 0x10),
0456 };
0457
0458 static struct platform_device ep93xx_pwm1_device = {
0459 .name = "ep93xx-pwm",
0460 .id = 1,
0461 .num_resources = ARRAY_SIZE(ep93xx_pwm1_resource),
0462 .resource = ep93xx_pwm1_resource,
0463 };
0464
0465 void __init ep93xx_register_pwm(int pwm0, int pwm1)
0466 {
0467 if (pwm0)
0468 platform_device_register(&ep93xx_pwm0_device);
0469
0470
0471 if (pwm1)
0472 platform_device_register(&ep93xx_pwm1_device);
0473 }
0474
0475 int ep93xx_pwm_acquire_gpio(struct platform_device *pdev)
0476 {
0477 int err;
0478
0479 if (pdev->id == 0) {
0480 err = 0;
0481 } else if (pdev->id == 1) {
0482 err = gpio_request(EP93XX_GPIO_LINE_EGPIO14,
0483 dev_name(&pdev->dev));
0484 if (err)
0485 return err;
0486 err = gpio_direction_output(EP93XX_GPIO_LINE_EGPIO14, 0);
0487 if (err)
0488 goto fail;
0489
0490
0491 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_PONG);
0492 } else {
0493 err = -ENODEV;
0494 }
0495
0496 return err;
0497
0498 fail:
0499 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
0500 return err;
0501 }
0502 EXPORT_SYMBOL(ep93xx_pwm_acquire_gpio);
0503
0504 void ep93xx_pwm_release_gpio(struct platform_device *pdev)
0505 {
0506 if (pdev->id == 1) {
0507 gpio_direction_input(EP93XX_GPIO_LINE_EGPIO14);
0508 gpio_free(EP93XX_GPIO_LINE_EGPIO14);
0509
0510
0511 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_PONG);
0512 }
0513 }
0514 EXPORT_SYMBOL(ep93xx_pwm_release_gpio);
0515
0516
0517
0518
0519
0520 static struct ep93xxfb_mach_info ep93xxfb_data;
0521
0522 static struct resource ep93xx_fb_resource[] = {
0523 DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE, 0x800),
0524 };
0525
0526 static struct platform_device ep93xx_fb_device = {
0527 .name = "ep93xx-fb",
0528 .id = -1,
0529 .dev = {
0530 .platform_data = &ep93xxfb_data,
0531 .coherent_dma_mask = DMA_BIT_MASK(32),
0532 .dma_mask = &ep93xx_fb_device.dev.coherent_dma_mask,
0533 },
0534 .num_resources = ARRAY_SIZE(ep93xx_fb_resource),
0535 .resource = ep93xx_fb_resource,
0536 };
0537
0538
0539 #define EP93XX_RASTER_REG_BRIGHTNESS 0x20
0540
0541 static struct resource ep93xx_bl_resources[] = {
0542 DEFINE_RES_MEM(EP93XX_RASTER_PHYS_BASE +
0543 EP93XX_RASTER_REG_BRIGHTNESS, 0x04),
0544 };
0545
0546 static struct platform_device ep93xx_bl_device = {
0547 .name = "ep93xx-bl",
0548 .id = -1,
0549 .num_resources = ARRAY_SIZE(ep93xx_bl_resources),
0550 .resource = ep93xx_bl_resources,
0551 };
0552
0553
0554
0555
0556
0557 void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
0558 {
0559 ep93xxfb_data = *data;
0560 platform_device_register(&ep93xx_fb_device);
0561 platform_device_register(&ep93xx_bl_device);
0562 }
0563
0564
0565
0566
0567
0568 static struct ep93xx_keypad_platform_data ep93xx_keypad_data;
0569
0570 static struct resource ep93xx_keypad_resource[] = {
0571 DEFINE_RES_MEM(EP93XX_KEY_MATRIX_PHYS_BASE, 0x0c),
0572 DEFINE_RES_IRQ(IRQ_EP93XX_KEY),
0573 };
0574
0575 static struct platform_device ep93xx_keypad_device = {
0576 .name = "ep93xx-keypad",
0577 .id = -1,
0578 .dev = {
0579 .platform_data = &ep93xx_keypad_data,
0580 },
0581 .num_resources = ARRAY_SIZE(ep93xx_keypad_resource),
0582 .resource = ep93xx_keypad_resource,
0583 };
0584
0585
0586
0587
0588
0589 void __init ep93xx_register_keypad(struct ep93xx_keypad_platform_data *data)
0590 {
0591 ep93xx_keypad_data = *data;
0592 platform_device_register(&ep93xx_keypad_device);
0593 }
0594
0595 int ep93xx_keypad_acquire_gpio(struct platform_device *pdev)
0596 {
0597 int err;
0598 int i;
0599
0600 for (i = 0; i < 8; i++) {
0601 err = gpio_request(EP93XX_GPIO_LINE_C(i), dev_name(&pdev->dev));
0602 if (err)
0603 goto fail_gpio_c;
0604 err = gpio_request(EP93XX_GPIO_LINE_D(i), dev_name(&pdev->dev));
0605 if (err)
0606 goto fail_gpio_d;
0607 }
0608
0609
0610 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_KEYS |
0611 EP93XX_SYSCON_DEVCFG_GONK);
0612
0613 return 0;
0614
0615 fail_gpio_d:
0616 gpio_free(EP93XX_GPIO_LINE_C(i));
0617 fail_gpio_c:
0618 for (--i; i >= 0; --i) {
0619 gpio_free(EP93XX_GPIO_LINE_C(i));
0620 gpio_free(EP93XX_GPIO_LINE_D(i));
0621 }
0622 return err;
0623 }
0624 EXPORT_SYMBOL(ep93xx_keypad_acquire_gpio);
0625
0626 void ep93xx_keypad_release_gpio(struct platform_device *pdev)
0627 {
0628 int i;
0629
0630 for (i = 0; i < 8; i++) {
0631 gpio_free(EP93XX_GPIO_LINE_C(i));
0632 gpio_free(EP93XX_GPIO_LINE_D(i));
0633 }
0634
0635
0636 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
0637 EP93XX_SYSCON_DEVCFG_GONK);
0638 }
0639 EXPORT_SYMBOL(ep93xx_keypad_release_gpio);
0640
0641
0642
0643
0644 static struct resource ep93xx_i2s_resource[] = {
0645 DEFINE_RES_MEM(EP93XX_I2S_PHYS_BASE, 0x100),
0646 DEFINE_RES_IRQ(IRQ_EP93XX_SAI),
0647 };
0648
0649 static struct platform_device ep93xx_i2s_device = {
0650 .name = "ep93xx-i2s",
0651 .id = -1,
0652 .num_resources = ARRAY_SIZE(ep93xx_i2s_resource),
0653 .resource = ep93xx_i2s_resource,
0654 };
0655
0656 static struct platform_device ep93xx_pcm_device = {
0657 .name = "ep93xx-pcm-audio",
0658 .id = -1,
0659 };
0660
0661 void __init ep93xx_register_i2s(void)
0662 {
0663 platform_device_register(&ep93xx_i2s_device);
0664 platform_device_register(&ep93xx_pcm_device);
0665 }
0666
0667 #define EP93XX_SYSCON_DEVCFG_I2S_MASK (EP93XX_SYSCON_DEVCFG_I2SONSSP | \
0668 EP93XX_SYSCON_DEVCFG_I2SONAC97)
0669
0670 #define EP93XX_I2SCLKDIV_MASK (EP93XX_SYSCON_I2SCLKDIV_ORIDE | \
0671 EP93XX_SYSCON_I2SCLKDIV_SPOL)
0672
0673 int ep93xx_i2s_acquire(void)
0674 {
0675 unsigned val;
0676
0677 ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_I2SONAC97,
0678 EP93XX_SYSCON_DEVCFG_I2S_MASK);
0679
0680
0681
0682
0683
0684
0685
0686 val = __raw_readl(EP93XX_SYSCON_I2SCLKDIV);
0687 val &= ~EP93XX_I2SCLKDIV_MASK;
0688 val |= EP93XX_SYSCON_I2SCLKDIV_ORIDE | EP93XX_SYSCON_I2SCLKDIV_SPOL;
0689 ep93xx_syscon_swlocked_write(val, EP93XX_SYSCON_I2SCLKDIV);
0690
0691 return 0;
0692 }
0693 EXPORT_SYMBOL(ep93xx_i2s_acquire);
0694
0695 void ep93xx_i2s_release(void)
0696 {
0697 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2S_MASK);
0698 }
0699 EXPORT_SYMBOL(ep93xx_i2s_release);
0700
0701
0702
0703
0704 static struct resource ep93xx_ac97_resources[] = {
0705 DEFINE_RES_MEM(EP93XX_AAC_PHYS_BASE, 0xac),
0706 DEFINE_RES_IRQ(IRQ_EP93XX_AACINTR),
0707 };
0708
0709 static struct platform_device ep93xx_ac97_device = {
0710 .name = "ep93xx-ac97",
0711 .id = -1,
0712 .num_resources = ARRAY_SIZE(ep93xx_ac97_resources),
0713 .resource = ep93xx_ac97_resources,
0714 };
0715
0716 void __init ep93xx_register_ac97(void)
0717 {
0718
0719
0720
0721 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_I2SONAC97);
0722
0723 platform_device_register(&ep93xx_ac97_device);
0724 platform_device_register(&ep93xx_pcm_device);
0725 }
0726
0727
0728
0729
0730 static struct resource ep93xx_wdt_resources[] = {
0731 DEFINE_RES_MEM(EP93XX_WATCHDOG_PHYS_BASE, 0x08),
0732 };
0733
0734 static struct platform_device ep93xx_wdt_device = {
0735 .name = "ep93xx-wdt",
0736 .id = -1,
0737 .num_resources = ARRAY_SIZE(ep93xx_wdt_resources),
0738 .resource = ep93xx_wdt_resources,
0739 };
0740
0741
0742
0743
0744 static struct resource ep93xx_ide_resources[] = {
0745 DEFINE_RES_MEM(EP93XX_IDE_PHYS_BASE, 0x38),
0746 DEFINE_RES_IRQ(IRQ_EP93XX_EXT3),
0747 };
0748
0749 static struct platform_device ep93xx_ide_device = {
0750 .name = "ep93xx-ide",
0751 .id = -1,
0752 .dev = {
0753 .dma_mask = &ep93xx_ide_device.dev.coherent_dma_mask,
0754 .coherent_dma_mask = DMA_BIT_MASK(32),
0755 },
0756 .num_resources = ARRAY_SIZE(ep93xx_ide_resources),
0757 .resource = ep93xx_ide_resources,
0758 };
0759
0760 void __init ep93xx_register_ide(void)
0761 {
0762 platform_device_register(&ep93xx_ide_device);
0763 }
0764
0765 int ep93xx_ide_acquire_gpio(struct platform_device *pdev)
0766 {
0767 int err;
0768 int i;
0769
0770 err = gpio_request(EP93XX_GPIO_LINE_EGPIO2, dev_name(&pdev->dev));
0771 if (err)
0772 return err;
0773 err = gpio_request(EP93XX_GPIO_LINE_EGPIO15, dev_name(&pdev->dev));
0774 if (err)
0775 goto fail_egpio15;
0776 for (i = 2; i < 8; i++) {
0777 err = gpio_request(EP93XX_GPIO_LINE_E(i), dev_name(&pdev->dev));
0778 if (err)
0779 goto fail_gpio_e;
0780 }
0781 for (i = 4; i < 8; i++) {
0782 err = gpio_request(EP93XX_GPIO_LINE_G(i), dev_name(&pdev->dev));
0783 if (err)
0784 goto fail_gpio_g;
0785 }
0786 for (i = 0; i < 8; i++) {
0787 err = gpio_request(EP93XX_GPIO_LINE_H(i), dev_name(&pdev->dev));
0788 if (err)
0789 goto fail_gpio_h;
0790 }
0791
0792
0793 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
0794 EP93XX_SYSCON_DEVCFG_GONIDE |
0795 EP93XX_SYSCON_DEVCFG_HONIDE);
0796 return 0;
0797
0798 fail_gpio_h:
0799 for (--i; i >= 0; --i)
0800 gpio_free(EP93XX_GPIO_LINE_H(i));
0801 i = 8;
0802 fail_gpio_g:
0803 for (--i; i >= 4; --i)
0804 gpio_free(EP93XX_GPIO_LINE_G(i));
0805 i = 8;
0806 fail_gpio_e:
0807 for (--i; i >= 2; --i)
0808 gpio_free(EP93XX_GPIO_LINE_E(i));
0809 gpio_free(EP93XX_GPIO_LINE_EGPIO15);
0810 fail_egpio15:
0811 gpio_free(EP93XX_GPIO_LINE_EGPIO2);
0812 return err;
0813 }
0814 EXPORT_SYMBOL(ep93xx_ide_acquire_gpio);
0815
0816 void ep93xx_ide_release_gpio(struct platform_device *pdev)
0817 {
0818 int i;
0819
0820 for (i = 2; i < 8; i++)
0821 gpio_free(EP93XX_GPIO_LINE_E(i));
0822 for (i = 4; i < 8; i++)
0823 gpio_free(EP93XX_GPIO_LINE_G(i));
0824 for (i = 0; i < 8; i++)
0825 gpio_free(EP93XX_GPIO_LINE_H(i));
0826 gpio_free(EP93XX_GPIO_LINE_EGPIO15);
0827 gpio_free(EP93XX_GPIO_LINE_EGPIO2);
0828
0829
0830
0831 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_EONIDE |
0832 EP93XX_SYSCON_DEVCFG_GONIDE |
0833 EP93XX_SYSCON_DEVCFG_HONIDE);
0834 }
0835 EXPORT_SYMBOL(ep93xx_ide_release_gpio);
0836
0837
0838
0839
0840 static struct resource ep93xx_adc_resources[] = {
0841 DEFINE_RES_MEM(EP93XX_ADC_PHYS_BASE, 0x28),
0842 DEFINE_RES_IRQ(IRQ_EP93XX_TOUCH),
0843 };
0844
0845 static struct platform_device ep93xx_adc_device = {
0846 .name = "ep93xx-adc",
0847 .id = -1,
0848 .num_resources = ARRAY_SIZE(ep93xx_adc_resources),
0849 .resource = ep93xx_adc_resources,
0850 };
0851
0852 void __init ep93xx_register_adc(void)
0853 {
0854
0855 ep93xx_devcfg_set_clear(EP93XX_SYSCON_DEVCFG_TIN,
0856 EP93XX_SYSCON_DEVCFG_ADCPD);
0857
0858 platform_device_register(&ep93xx_adc_device);
0859 }
0860
0861
0862
0863
0864
0865
0866
0867
0868
0869
0870
0871 #define EP93XX_SECURITY_REG(x) (EP93XX_SECURITY_BASE + (x))
0872 #define EP93XX_SECURITY_SECFLG EP93XX_SECURITY_REG(0x2400)
0873 #define EP93XX_SECURITY_FUSEFLG EP93XX_SECURITY_REG(0x2410)
0874 #define EP93XX_SECURITY_UNIQID EP93XX_SECURITY_REG(0x2440)
0875 #define EP93XX_SECURITY_UNIQCHK EP93XX_SECURITY_REG(0x2450)
0876 #define EP93XX_SECURITY_UNIQVAL EP93XX_SECURITY_REG(0x2460)
0877 #define EP93XX_SECURITY_SECID1 EP93XX_SECURITY_REG(0x2500)
0878 #define EP93XX_SECURITY_SECID2 EP93XX_SECURITY_REG(0x2504)
0879 #define EP93XX_SECURITY_SECCHK1 EP93XX_SECURITY_REG(0x2520)
0880 #define EP93XX_SECURITY_SECCHK2 EP93XX_SECURITY_REG(0x2524)
0881 #define EP93XX_SECURITY_UNIQID2 EP93XX_SECURITY_REG(0x2700)
0882 #define EP93XX_SECURITY_UNIQID3 EP93XX_SECURITY_REG(0x2704)
0883 #define EP93XX_SECURITY_UNIQID4 EP93XX_SECURITY_REG(0x2708)
0884 #define EP93XX_SECURITY_UNIQID5 EP93XX_SECURITY_REG(0x270c)
0885
0886 static char ep93xx_soc_id[33];
0887
0888 static const char __init *ep93xx_get_soc_id(void)
0889 {
0890 unsigned int id, id2, id3, id4, id5;
0891
0892 if (__raw_readl(EP93XX_SECURITY_UNIQVAL) != 1)
0893 return "bad Hamming code";
0894
0895 id = __raw_readl(EP93XX_SECURITY_UNIQID);
0896 id2 = __raw_readl(EP93XX_SECURITY_UNIQID2);
0897 id3 = __raw_readl(EP93XX_SECURITY_UNIQID3);
0898 id4 = __raw_readl(EP93XX_SECURITY_UNIQID4);
0899 id5 = __raw_readl(EP93XX_SECURITY_UNIQID5);
0900
0901 if (id != id2)
0902 return "invalid";
0903
0904
0905 add_device_randomness(&id2, 4);
0906 add_device_randomness(&id3, 4);
0907 add_device_randomness(&id4, 4);
0908 add_device_randomness(&id5, 4);
0909
0910 snprintf(ep93xx_soc_id, sizeof(ep93xx_soc_id),
0911 "%08x%08x%08x%08x", id2, id3, id4, id5);
0912
0913 return ep93xx_soc_id;
0914 }
0915
0916 static const char __init *ep93xx_get_soc_rev(void)
0917 {
0918 int rev = ep93xx_chip_revision();
0919
0920 switch (rev) {
0921 case EP93XX_CHIP_REV_D0:
0922 return "D0";
0923 case EP93XX_CHIP_REV_D1:
0924 return "D1";
0925 case EP93XX_CHIP_REV_E0:
0926 return "E0";
0927 case EP93XX_CHIP_REV_E1:
0928 return "E1";
0929 case EP93XX_CHIP_REV_E2:
0930 return "E2";
0931 default:
0932 return "unknown";
0933 }
0934 }
0935
0936 static const char __init *ep93xx_get_machine_name(void)
0937 {
0938 return kasprintf(GFP_KERNEL,"%s", machine_desc->name);
0939 }
0940
0941 static struct device __init *ep93xx_init_soc(void)
0942 {
0943 struct soc_device_attribute *soc_dev_attr;
0944 struct soc_device *soc_dev;
0945
0946 soc_dev_attr = kzalloc(sizeof(*soc_dev_attr), GFP_KERNEL);
0947 if (!soc_dev_attr)
0948 return NULL;
0949
0950 soc_dev_attr->machine = ep93xx_get_machine_name();
0951 soc_dev_attr->family = "Cirrus Logic EP93xx";
0952 soc_dev_attr->revision = ep93xx_get_soc_rev();
0953 soc_dev_attr->soc_id = ep93xx_get_soc_id();
0954
0955 soc_dev = soc_device_register(soc_dev_attr);
0956 if (IS_ERR(soc_dev)) {
0957 kfree(soc_dev_attr->machine);
0958 kfree(soc_dev_attr);
0959 return NULL;
0960 }
0961
0962 return soc_device_to_device(soc_dev);
0963 }
0964
0965 struct device __init *ep93xx_init_devices(void)
0966 {
0967 struct device *parent;
0968
0969
0970 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_CPENA);
0971
0972
0973 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_KEYS |
0974 EP93XX_SYSCON_DEVCFG_GONK |
0975 EP93XX_SYSCON_DEVCFG_EONIDE |
0976 EP93XX_SYSCON_DEVCFG_GONIDE |
0977 EP93XX_SYSCON_DEVCFG_HONIDE);
0978
0979 parent = ep93xx_init_soc();
0980
0981
0982 platform_device_register(&ep93xx_gpio_device);
0983
0984 amba_device_register(&uart1_device, &iomem_resource);
0985 amba_device_register(&uart2_device, &iomem_resource);
0986 amba_device_register(&uart3_device, &iomem_resource);
0987
0988 platform_device_register(&ep93xx_rtc_device);
0989 platform_device_register(&ep93xx_ohci_device);
0990 platform_device_register(&ep93xx_wdt_device);
0991
0992 gpio_led_register_device(-1, &ep93xx_led_data);
0993
0994 return parent;
0995 }
0996
0997 void ep93xx_restart(enum reboot_mode mode, const char *cmd)
0998 {
0999
1000
1001
1002 ep93xx_devcfg_set_bits(EP93XX_SYSCON_DEVCFG_SWRST);
1003 ep93xx_devcfg_clear_bits(EP93XX_SYSCON_DEVCFG_SWRST);
1004
1005 while (1)
1006 ;
1007 }