1 /* 2 * DBAu1000/1500/1100 PBAu1100/1500 board support 3 * 4 * Copyright 2000, 2008 MontaVista Software Inc. 5 * Author: MontaVista Software, Inc. <source@mvista.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation; either version 2 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 */ 21 22 #include <linux/clk.h> 23 #include <linux/dma-mapping.h> 24 #include <linux/gpio.h> 25 #include <linux/gpio/machine.h> 26 #include <linux/init.h> 27 #include <linux/interrupt.h> 28 #include <linux/leds.h> 29 #include <linux/mmc/host.h> 30 #include <linux/module.h> 31 #include <linux/platform_device.h> 32 #include <linux/pm.h> 33 #include <linux/spi/spi.h> 34 #include <linux/spi/spi_gpio.h> 35 #include <linux/spi/ads7846.h> 36 #include <asm/mach-au1x00/au1000.h> 37 #include <asm/mach-au1x00/gpio-au1000.h> 38 #include <asm/mach-au1x00/au1000_dma.h> 39 #include <asm/mach-au1x00/au1100_mmc.h> 40 #include <asm/mach-db1x00/bcsr.h> 41 #include <asm/reboot.h> 42 #include <prom.h> 43 #include "platform.h" 44 45 #define F_SWAPPED (bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1000_SWAPBOOT) 46 47 const char *get_system_type(void); 48 49 int __init db1000_board_setup(void) 50 { 51 /* initialize board register space */ 52 bcsr_init(DB1000_BCSR_PHYS_ADDR, 53 DB1000_BCSR_PHYS_ADDR + DB1000_BCSR_HEXLED_OFS); 54 55 switch (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI))) { 56 case BCSR_WHOAMI_DB1000: 57 case BCSR_WHOAMI_DB1500: 58 case BCSR_WHOAMI_DB1100: 59 case BCSR_WHOAMI_PB1500: 60 case BCSR_WHOAMI_PB1500R2: 61 case BCSR_WHOAMI_PB1100: 62 pr_info("AMD Alchemy %s Board\n", get_system_type()); 63 return 0; 64 } 65 return -ENODEV; 66 } 67 68 static int db1500_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin) 69 { 70 if ((slot < 12) || (slot > 13) || pin == 0) 71 return -1; 72 if (slot == 12) 73 return (pin == 1) ? AU1500_PCI_INTA : 0xff; 74 if (slot == 13) { 75 switch (pin) { 76 case 1: return AU1500_PCI_INTA; 77 case 2: return AU1500_PCI_INTB; 78 case 3: return AU1500_PCI_INTC; 79 case 4: return AU1500_PCI_INTD; 80 } 81 } 82 return -1; 83 } 84 85 static struct resource alchemy_pci_host_res[] = { 86 [0] = { 87 .start = AU1500_PCI_PHYS_ADDR, 88 .end = AU1500_PCI_PHYS_ADDR + 0xfff, 89 .flags = IORESOURCE_MEM, 90 }, 91 }; 92 93 static struct alchemy_pci_platdata db1500_pci_pd = { 94 .board_map_irq = db1500_map_pci_irq, 95 }; 96 97 static struct platform_device db1500_pci_host_dev = { 98 .dev.platform_data = &db1500_pci_pd, 99 .name = "alchemy-pci", 100 .id = 0, 101 .num_resources = ARRAY_SIZE(alchemy_pci_host_res), 102 .resource = alchemy_pci_host_res, 103 }; 104 105 int __init db1500_pci_setup(void) 106 { 107 return platform_device_register(&db1500_pci_host_dev); 108 } 109 110 static struct resource au1100_lcd_resources[] = { 111 [0] = { 112 .start = AU1100_LCD_PHYS_ADDR, 113 .end = AU1100_LCD_PHYS_ADDR + 0x800 - 1, 114 .flags = IORESOURCE_MEM, 115 }, 116 [1] = { 117 .start = AU1100_LCD_INT, 118 .end = AU1100_LCD_INT, 119 .flags = IORESOURCE_IRQ, 120 } 121 }; 122 123 static u64 au1100_lcd_dmamask = DMA_BIT_MASK(32); 124 125 static struct platform_device au1100_lcd_device = { 126 .name = "au1100-lcd", 127 .id = 0, 128 .dev = { 129 .dma_mask = &au1100_lcd_dmamask, 130 .coherent_dma_mask = DMA_BIT_MASK(32), 131 }, 132 .num_resources = ARRAY_SIZE(au1100_lcd_resources), 133 .resource = au1100_lcd_resources, 134 }; 135 136 static struct resource alchemy_ac97c_res[] = { 137 [0] = { 138 .start = AU1000_AC97_PHYS_ADDR, 139 .end = AU1000_AC97_PHYS_ADDR + 0xfff, 140 .flags = IORESOURCE_MEM, 141 }, 142 [1] = { 143 .start = DMA_ID_AC97C_TX, 144 .end = DMA_ID_AC97C_TX, 145 .flags = IORESOURCE_DMA, 146 }, 147 [2] = { 148 .start = DMA_ID_AC97C_RX, 149 .end = DMA_ID_AC97C_RX, 150 .flags = IORESOURCE_DMA, 151 }, 152 }; 153 154 static struct platform_device alchemy_ac97c_dev = { 155 .name = "alchemy-ac97c", 156 .id = -1, 157 .resource = alchemy_ac97c_res, 158 .num_resources = ARRAY_SIZE(alchemy_ac97c_res), 159 }; 160 161 static struct platform_device alchemy_ac97c_dma_dev = { 162 .name = "alchemy-pcm-dma", 163 .id = 0, 164 }; 165 166 static struct platform_device db1x00_codec_dev = { 167 .name = "ac97-codec", 168 .id = -1, 169 }; 170 171 static struct platform_device db1x00_audio_dev = { 172 .name = "db1000-audio", 173 }; 174 175 /******************************************************************************/ 176 177 static irqreturn_t db1100_mmc_cd(int irq, void *ptr) 178 { 179 void (*mmc_cd)(struct mmc_host *, unsigned long); 180 /* link against CONFIG_MMC=m */ 181 mmc_cd = symbol_get(mmc_detect_change); 182 mmc_cd(ptr, msecs_to_jiffies(500)); 183 symbol_put(mmc_detect_change); 184 185 return IRQ_HANDLED; 186 } 187 188 static int db1100_mmc_cd_setup(void *mmc_host, int en) 189 { 190 int ret = 0, irq; 191 192 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) 193 irq = AU1100_GPIO19_INT; 194 else 195 irq = AU1100_GPIO14_INT; /* PB1100 SD0 CD# */ 196 197 if (en) { 198 irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); 199 ret = request_irq(irq, db1100_mmc_cd, 0, 200 "sd0_cd", mmc_host); 201 } else 202 free_irq(irq, mmc_host); 203 return ret; 204 } 205 206 static int db1100_mmc1_cd_setup(void *mmc_host, int en) 207 { 208 int ret = 0, irq; 209 210 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) 211 irq = AU1100_GPIO20_INT; 212 else 213 irq = AU1100_GPIO15_INT; /* PB1100 SD1 CD# */ 214 215 if (en) { 216 irq_set_irq_type(irq, IRQ_TYPE_EDGE_BOTH); 217 ret = request_irq(irq, db1100_mmc_cd, 0, 218 "sd1_cd", mmc_host); 219 } else 220 free_irq(irq, mmc_host); 221 return ret; 222 } 223 224 static int db1100_mmc_card_readonly(void *mmc_host) 225 { 226 /* testing suggests that this bit is inverted */ 227 return (bcsr_read(BCSR_STATUS) & BCSR_STATUS_SD0WP) ? 0 : 1; 228 } 229 230 static int db1100_mmc_card_inserted(void *mmc_host) 231 { 232 return !alchemy_gpio_get_value(19); 233 } 234 235 static void db1100_mmc_set_power(void *mmc_host, int state) 236 { 237 int bit; 238 239 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) 240 bit = BCSR_BOARD_SD0PWR; 241 else 242 bit = BCSR_BOARD_PB1100_SD0PWR; 243 244 if (state) { 245 bcsr_mod(BCSR_BOARD, 0, bit); 246 msleep(400); /* stabilization time */ 247 } else 248 bcsr_mod(BCSR_BOARD, bit, 0); 249 } 250 251 static void db1100_mmcled_set(struct led_classdev *led, enum led_brightness b) 252 { 253 if (b != LED_OFF) 254 bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED0, 0); 255 else 256 bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED0); 257 } 258 259 static struct led_classdev db1100_mmc_led = { 260 .brightness_set = db1100_mmcled_set, 261 }; 262 263 static int db1100_mmc1_card_readonly(void *mmc_host) 264 { 265 return (bcsr_read(BCSR_BOARD) & BCSR_BOARD_SD1WP) ? 1 : 0; 266 } 267 268 static int db1100_mmc1_card_inserted(void *mmc_host) 269 { 270 return !alchemy_gpio_get_value(20); 271 } 272 273 static void db1100_mmc1_set_power(void *mmc_host, int state) 274 { 275 int bit; 276 277 if (BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)) == BCSR_WHOAMI_DB1100) 278 bit = BCSR_BOARD_SD1PWR; 279 else 280 bit = BCSR_BOARD_PB1100_SD1PWR; 281 282 if (state) { 283 bcsr_mod(BCSR_BOARD, 0, bit); 284 msleep(400); /* stabilization time */ 285 } else 286 bcsr_mod(BCSR_BOARD, bit, 0); 287 } 288 289 static void db1100_mmc1led_set(struct led_classdev *led, enum led_brightness b) 290 { 291 if (b != LED_OFF) 292 bcsr_mod(BCSR_LEDS, BCSR_LEDS_LED1, 0); 293 else 294 bcsr_mod(BCSR_LEDS, 0, BCSR_LEDS_LED1); 295 } 296 297 static struct led_classdev db1100_mmc1_led = { 298 .brightness_set = db1100_mmc1led_set, 299 }; 300 301 static struct au1xmmc_platform_data db1100_mmc_platdata[2] = { 302 [0] = { 303 .cd_setup = db1100_mmc_cd_setup, 304 .set_power = db1100_mmc_set_power, 305 .card_inserted = db1100_mmc_card_inserted, 306 .card_readonly = db1100_mmc_card_readonly, 307 .led = &db1100_mmc_led, 308 }, 309 [1] = { 310 .cd_setup = db1100_mmc1_cd_setup, 311 .set_power = db1100_mmc1_set_power, 312 .card_inserted = db1100_mmc1_card_inserted, 313 .card_readonly = db1100_mmc1_card_readonly, 314 .led = &db1100_mmc1_led, 315 }, 316 }; 317 318 static struct resource au1100_mmc0_resources[] = { 319 [0] = { 320 .start = AU1100_SD0_PHYS_ADDR, 321 .end = AU1100_SD0_PHYS_ADDR + 0xfff, 322 .flags = IORESOURCE_MEM, 323 }, 324 [1] = { 325 .start = AU1100_SD_INT, 326 .end = AU1100_SD_INT, 327 .flags = IORESOURCE_IRQ, 328 }, 329 [2] = { 330 .start = DMA_ID_SD0_TX, 331 .end = DMA_ID_SD0_TX, 332 .flags = IORESOURCE_DMA, 333 }, 334 [3] = { 335 .start = DMA_ID_SD0_RX, 336 .end = DMA_ID_SD0_RX, 337 .flags = IORESOURCE_DMA, 338 } 339 }; 340 341 static u64 au1xxx_mmc_dmamask = DMA_BIT_MASK(32); 342 343 static struct platform_device db1100_mmc0_dev = { 344 .name = "au1xxx-mmc", 345 .id = 0, 346 .dev = { 347 .dma_mask = &au1xxx_mmc_dmamask, 348 .coherent_dma_mask = DMA_BIT_MASK(32), 349 .platform_data = &db1100_mmc_platdata[0], 350 }, 351 .num_resources = ARRAY_SIZE(au1100_mmc0_resources), 352 .resource = au1100_mmc0_resources, 353 }; 354 355 static struct resource au1100_mmc1_res[] = { 356 [0] = { 357 .start = AU1100_SD1_PHYS_ADDR, 358 .end = AU1100_SD1_PHYS_ADDR + 0xfff, 359 .flags = IORESOURCE_MEM, 360 }, 361 [1] = { 362 .start = AU1100_SD_INT, 363 .end = AU1100_SD_INT, 364 .flags = IORESOURCE_IRQ, 365 }, 366 [2] = { 367 .start = DMA_ID_SD1_TX, 368 .end = DMA_ID_SD1_TX, 369 .flags = IORESOURCE_DMA, 370 }, 371 [3] = { 372 .start = DMA_ID_SD1_RX, 373 .end = DMA_ID_SD1_RX, 374 .flags = IORESOURCE_DMA, 375 } 376 }; 377 378 static struct platform_device db1100_mmc1_dev = { 379 .name = "au1xxx-mmc", 380 .id = 1, 381 .dev = { 382 .dma_mask = &au1xxx_mmc_dmamask, 383 .coherent_dma_mask = DMA_BIT_MASK(32), 384 .platform_data = &db1100_mmc_platdata[1], 385 }, 386 .num_resources = ARRAY_SIZE(au1100_mmc1_res), 387 .resource = au1100_mmc1_res, 388 }; 389 390 /******************************************************************************/ 391 392 static struct ads7846_platform_data db1100_touch_pd = { 393 .model = 7846, 394 .vref_mv = 3300, 395 .gpio_pendown = 21, 396 }; 397 398 static struct spi_gpio_platform_data db1100_spictl_pd = { 399 .num_chipselect = 1, 400 }; 401 402 static struct spi_board_info db1100_spi_info[] __initdata = { 403 [0] = { 404 .modalias = "ads7846", 405 .max_speed_hz = 3250000, 406 .bus_num = 0, 407 .chip_select = 0, 408 .mode = 0, 409 .irq = AU1100_GPIO21_INT, 410 .platform_data = &db1100_touch_pd, 411 }, 412 }; 413 414 static struct platform_device db1100_spi_dev = { 415 .name = "spi_gpio", 416 .id = 0, 417 .dev = { 418 .platform_data = &db1100_spictl_pd, 419 }, 420 }; 421 422 /* 423 * Alchemy GPIO 2 has its base at 200 so the GPIO lines 424 * 207 thru 210 are GPIOs at offset 7 thru 10 at this chip. 425 */ 426 static struct gpiod_lookup_table db1100_spi_gpiod_table = { 427 .dev_id = "spi_gpio", 428 .table = { 429 GPIO_LOOKUP("alchemy-gpio2", 9, 430 "sck", GPIO_ACTIVE_HIGH), 431 GPIO_LOOKUP("alchemy-gpio2", 8, 432 "mosi", GPIO_ACTIVE_HIGH), 433 GPIO_LOOKUP("alchemy-gpio2", 7, 434 "miso", GPIO_ACTIVE_HIGH), 435 GPIO_LOOKUP("alchemy-gpio2", 10, 436 "cs", GPIO_ACTIVE_HIGH), 437 { }, 438 }, 439 }; 440 441 static struct platform_device *db1x00_devs[] = { 442 &db1x00_codec_dev, 443 &alchemy_ac97c_dma_dev, 444 &alchemy_ac97c_dev, 445 &db1x00_audio_dev, 446 }; 447 448 static struct platform_device *db1100_devs[] = { 449 &au1100_lcd_device, 450 &db1100_mmc0_dev, 451 &db1100_mmc1_dev, 452 }; 453 454 int __init db1000_dev_setup(void) 455 { 456 int board = BCSR_WHOAMI_BOARD(bcsr_read(BCSR_WHOAMI)); 457 int c0, c1, d0, d1, s0, s1, flashsize = 32, twosocks = 1; 458 unsigned long pfc; 459 struct clk *c, *p; 460 461 if (board == BCSR_WHOAMI_DB1500) { 462 c0 = AU1500_GPIO2_INT; 463 c1 = AU1500_GPIO5_INT; 464 d0 = 0; /* GPIO number, NOT irq! */ 465 d1 = 3; /* GPIO number, NOT irq! */ 466 s0 = AU1500_GPIO1_INT; 467 s1 = AU1500_GPIO4_INT; 468 } else if (board == BCSR_WHOAMI_DB1100) { 469 c0 = AU1100_GPIO2_INT; 470 c1 = AU1100_GPIO5_INT; 471 d0 = 0; /* GPIO number, NOT irq! */ 472 d1 = 3; /* GPIO number, NOT irq! */ 473 s0 = AU1100_GPIO1_INT; 474 s1 = AU1100_GPIO4_INT; 475 476 gpio_request(19, "sd0_cd"); 477 gpio_request(20, "sd1_cd"); 478 gpio_direction_input(19); /* sd0 cd# */ 479 gpio_direction_input(20); /* sd1 cd# */ 480 481 /* spi_gpio on SSI0 pins */ 482 pfc = alchemy_rdsys(AU1000_SYS_PINFUNC); 483 pfc |= (1 << 0); /* SSI0 pins as GPIOs */ 484 alchemy_wrsys(pfc, AU1000_SYS_PINFUNC); 485 486 spi_register_board_info(db1100_spi_info, 487 ARRAY_SIZE(db1100_spi_info)); 488 489 /* link LCD clock to AUXPLL */ 490 p = clk_get(NULL, "auxpll_clk"); 491 c = clk_get(NULL, "lcd_intclk"); 492 if (!IS_ERR(c) && !IS_ERR(p)) { 493 clk_set_parent(c, p); 494 clk_set_rate(c, clk_get_rate(p)); 495 } 496 if (!IS_ERR(c)) 497 clk_put(c); 498 if (!IS_ERR(p)) 499 clk_put(p); 500 501 platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs)); 502 gpiod_add_lookup_table(&db1100_spi_gpiod_table); 503 platform_device_register(&db1100_spi_dev); 504 } else if (board == BCSR_WHOAMI_DB1000) { 505 c0 = AU1000_GPIO2_INT; 506 c1 = AU1000_GPIO5_INT; 507 d0 = 0; /* GPIO number, NOT irq! */ 508 d1 = 3; /* GPIO number, NOT irq! */ 509 s0 = AU1000_GPIO1_INT; 510 s1 = AU1000_GPIO4_INT; 511 } else if ((board == BCSR_WHOAMI_PB1500) || 512 (board == BCSR_WHOAMI_PB1500R2)) { 513 c0 = AU1500_GPIO203_INT; 514 d0 = 1; /* GPIO number, NOT irq! */ 515 s0 = AU1500_GPIO202_INT; 516 twosocks = 0; 517 flashsize = 64; 518 /* RTC and daughtercard irqs */ 519 irq_set_irq_type(AU1500_GPIO204_INT, IRQ_TYPE_LEVEL_LOW); 520 irq_set_irq_type(AU1500_GPIO205_INT, IRQ_TYPE_LEVEL_LOW); 521 /* EPSON S1D13806 0x1b000000 522 * SRAM 1MB/2MB 0x1a000000 523 * DS1693 RTC 0x0c000000 524 */ 525 } else if (board == BCSR_WHOAMI_PB1100) { 526 c0 = AU1100_GPIO11_INT; 527 d0 = 9; /* GPIO number, NOT irq! */ 528 s0 = AU1100_GPIO10_INT; 529 twosocks = 0; 530 flashsize = 64; 531 /* pendown, rtc, daughtercard irqs */ 532 irq_set_irq_type(AU1100_GPIO8_INT, IRQ_TYPE_LEVEL_LOW); 533 irq_set_irq_type(AU1100_GPIO12_INT, IRQ_TYPE_LEVEL_LOW); 534 irq_set_irq_type(AU1100_GPIO13_INT, IRQ_TYPE_LEVEL_LOW); 535 /* EPSON S1D13806 0x1b000000 536 * SRAM 1MB/2MB 0x1a000000 537 * DiskOnChip 0x0d000000 538 * DS1693 RTC 0x0c000000 539 */ 540 platform_add_devices(db1100_devs, ARRAY_SIZE(db1100_devs)); 541 } else 542 return 0; /* unknown board, no further dev setup to do */ 543 544 irq_set_irq_type(c0, IRQ_TYPE_LEVEL_LOW); 545 irq_set_irq_type(s0, IRQ_TYPE_LEVEL_LOW); 546 547 db1x_register_pcmcia_socket( 548 AU1000_PCMCIA_ATTR_PHYS_ADDR, 549 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1, 550 AU1000_PCMCIA_MEM_PHYS_ADDR, 551 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1, 552 AU1000_PCMCIA_IO_PHYS_ADDR, 553 AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1, 554 c0, d0, /*s0*/0, 0, 0); 555 556 if (twosocks) { 557 irq_set_irq_type(c1, IRQ_TYPE_LEVEL_LOW); 558 irq_set_irq_type(s1, IRQ_TYPE_LEVEL_LOW); 559 560 db1x_register_pcmcia_socket( 561 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004000000, 562 AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x004400000 - 1, 563 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004000000, 564 AU1000_PCMCIA_MEM_PHYS_ADDR + 0x004400000 - 1, 565 AU1000_PCMCIA_IO_PHYS_ADDR + 0x004000000, 566 AU1000_PCMCIA_IO_PHYS_ADDR + 0x004010000 - 1, 567 c1, d1, /*s1*/0, 0, 1); 568 } 569 570 platform_add_devices(db1x00_devs, ARRAY_SIZE(db1x00_devs)); 571 db1x_register_norflash(flashsize << 20, 4 /* 32bit */, F_SWAPPED); 572 return 0; 573 } 574