pb1500.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Pb1500 board support.
  3. *
  4. * Copyright (C) 2009 Manuel Lauss
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include <linux/delay.h>
  21. #include <linux/dma-mapping.h>
  22. #include <linux/gpio.h>
  23. #include <linux/init.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/platform_device.h>
  26. #include <asm/mach-au1x00/au1000.h>
  27. #include <asm/mach-db1x00/bcsr.h>
  28. #include <prom.h>
  29. #include "platform.h"
  30. const char *get_system_type(void)
  31. {
  32. return "PB1500";
  33. }
  34. void __init board_setup(void)
  35. {
  36. u32 pin_func;
  37. u32 sys_freqctrl, sys_clksrc;
  38. bcsr_init(DB1000_BCSR_PHYS_ADDR,
  39. DB1000_BCSR_PHYS_ADDR + DB1000_BCSR_HEXLED_OFS);
  40. sys_clksrc = sys_freqctrl = pin_func = 0;
  41. /* Set AUX clock to 12 MHz * 8 = 96 MHz */
  42. au_writel(8, SYS_AUXPLL);
  43. alchemy_gpio1_input_enable();
  44. udelay(100);
  45. /* GPIO201 is input for PCMCIA card detect */
  46. /* GPIO203 is input for PCMCIA interrupt request */
  47. alchemy_gpio_direction_input(201);
  48. alchemy_gpio_direction_input(203);
  49. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  50. /* Zero and disable FREQ2 */
  51. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  52. sys_freqctrl &= ~0xFFF00000;
  53. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  54. /* zero and disable USBH/USBD clocks */
  55. sys_clksrc = au_readl(SYS_CLKSRC);
  56. sys_clksrc &= ~(SYS_CS_CUD | SYS_CS_DUD | SYS_CS_MUD_MASK |
  57. SYS_CS_CUH | SYS_CS_DUH | SYS_CS_MUH_MASK);
  58. au_writel(sys_clksrc, SYS_CLKSRC);
  59. sys_freqctrl = au_readl(SYS_FREQCTRL0);
  60. sys_freqctrl &= ~0xFFF00000;
  61. sys_clksrc = au_readl(SYS_CLKSRC);
  62. sys_clksrc &= ~(SYS_CS_CUD | SYS_CS_DUD | SYS_CS_MUD_MASK |
  63. SYS_CS_CUH | SYS_CS_DUH | SYS_CS_MUH_MASK);
  64. /* FREQ2 = aux/2 = 48 MHz */
  65. sys_freqctrl |= (0 << SYS_FC_FRDIV2_BIT) | SYS_FC_FE2 | SYS_FC_FS2;
  66. au_writel(sys_freqctrl, SYS_FREQCTRL0);
  67. /*
  68. * Route 48MHz FREQ2 into USB Host and/or Device
  69. */
  70. sys_clksrc |= SYS_CS_MUX_FQ2 << SYS_CS_MUH_BIT;
  71. au_writel(sys_clksrc, SYS_CLKSRC);
  72. pin_func = au_readl(SYS_PINFUNC) & ~SYS_PF_USB;
  73. /* 2nd USB port is USB host */
  74. pin_func |= SYS_PF_USB;
  75. au_writel(pin_func, SYS_PINFUNC);
  76. #endif /* defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE) */
  77. #ifdef CONFIG_PCI
  78. {
  79. void __iomem *base =
  80. (void __iomem *)KSEG1ADDR(AU1500_PCI_PHYS_ADDR);
  81. /* Setup PCI bus controller */
  82. __raw_writel(0x00003fff, base + PCI_REG_CMEM);
  83. __raw_writel(0xf0000000, base + PCI_REG_MWMASK_DEV);
  84. __raw_writel(0, base + PCI_REG_MWBASE_REV_CCL);
  85. __raw_writel(0x02a00356, base + PCI_REG_STATCMD);
  86. __raw_writel(0x00003c04, base + PCI_REG_PARAM);
  87. __raw_writel(0x00000008, base + PCI_REG_MBAR);
  88. wmb();
  89. }
  90. #endif
  91. /* Enable sys bus clock divider when IDLE state or no bus activity. */
  92. au_writel(au_readl(SYS_POWERCTRL) | (0x3 << 5), SYS_POWERCTRL);
  93. /* Enable the RTC if not already enabled */
  94. if (!(au_readl(0xac000028) & 0x20)) {
  95. printk(KERN_INFO "enabling clock ...\n");
  96. au_writel((au_readl(0xac000028) | 0x20), 0xac000028);
  97. }
  98. /* Put the clock in BCD mode */
  99. if (au_readl(0xac00002c) & 0x4) { /* reg B */
  100. au_writel(au_readl(0xac00002c) & ~0x4, 0xac00002c);
  101. au_sync();
  102. }
  103. }
  104. /******************************************************************************/
  105. static int pb1500_map_pci_irq(const struct pci_dev *d, u8 slot, u8 pin)
  106. {
  107. if ((slot < 12) || (slot > 13) || pin == 0)
  108. return -1;
  109. if (slot == 12)
  110. return (pin == 1) ? AU1500_PCI_INTA : 0xff;
  111. if (slot == 13) {
  112. switch (pin) {
  113. case 1: return AU1500_PCI_INTA;
  114. case 2: return AU1500_PCI_INTB;
  115. case 3: return AU1500_PCI_INTC;
  116. case 4: return AU1500_PCI_INTD;
  117. }
  118. }
  119. return -1;
  120. }
  121. static struct resource alchemy_pci_host_res[] = {
  122. [0] = {
  123. .start = AU1500_PCI_PHYS_ADDR,
  124. .end = AU1500_PCI_PHYS_ADDR + 0xfff,
  125. .flags = IORESOURCE_MEM,
  126. },
  127. };
  128. static struct alchemy_pci_platdata pb1500_pci_pd = {
  129. .board_map_irq = pb1500_map_pci_irq,
  130. .pci_cfg_set = PCI_CONFIG_AEN | PCI_CONFIG_R2H | PCI_CONFIG_R1H |
  131. PCI_CONFIG_CH |
  132. #if defined(__MIPSEB__)
  133. PCI_CONFIG_SIC_HWA_DAT | PCI_CONFIG_SM,
  134. #else
  135. 0,
  136. #endif
  137. };
  138. static struct platform_device pb1500_pci_host = {
  139. .dev.platform_data = &pb1500_pci_pd,
  140. .name = "alchemy-pci",
  141. .id = 0,
  142. .num_resources = ARRAY_SIZE(alchemy_pci_host_res),
  143. .resource = alchemy_pci_host_res,
  144. };
  145. static int __init pb1500_dev_init(void)
  146. {
  147. int swapped;
  148. irq_set_irq_type(AU1500_GPIO9_INT, IRQF_TRIGGER_LOW); /* CD0# */
  149. irq_set_irq_type(AU1500_GPIO10_INT, IRQF_TRIGGER_LOW); /* CARD0 */
  150. irq_set_irq_type(AU1500_GPIO11_INT, IRQF_TRIGGER_LOW); /* STSCHG0# */
  151. irq_set_irq_type(AU1500_GPIO204_INT, IRQF_TRIGGER_HIGH);
  152. irq_set_irq_type(AU1500_GPIO201_INT, IRQF_TRIGGER_LOW);
  153. irq_set_irq_type(AU1500_GPIO202_INT, IRQF_TRIGGER_LOW);
  154. irq_set_irq_type(AU1500_GPIO203_INT, IRQF_TRIGGER_LOW);
  155. irq_set_irq_type(AU1500_GPIO205_INT, IRQF_TRIGGER_LOW);
  156. /* PCMCIA. single socket, identical to Pb1100 */
  157. db1x_register_pcmcia_socket(
  158. AU1000_PCMCIA_ATTR_PHYS_ADDR,
  159. AU1000_PCMCIA_ATTR_PHYS_ADDR + 0x000400000 - 1,
  160. AU1000_PCMCIA_MEM_PHYS_ADDR,
  161. AU1000_PCMCIA_MEM_PHYS_ADDR + 0x000400000 - 1,
  162. AU1000_PCMCIA_IO_PHYS_ADDR,
  163. AU1000_PCMCIA_IO_PHYS_ADDR + 0x000010000 - 1,
  164. AU1500_GPIO11_INT, AU1500_GPIO9_INT, /* card / insert */
  165. /*AU1500_GPIO10_INT*/0, 0, 0); /* stschg / eject / id */
  166. swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_DB1000_SWAPBOOT;
  167. db1x_register_norflash(64 * 1024 * 1024, 4, swapped);
  168. platform_device_register(&pb1500_pci_host);
  169. return 0;
  170. }
  171. arch_initcall(pb1500_dev_init);