lite5200.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Freescale Lite5200 board support
  3. *
  4. * Written by: Grant Likely <grant.likely@secretlab.ca>
  5. *
  6. * Copyright (C) Secret Lab Technologies Ltd. 2006. All rights reserved.
  7. * Copyright (C) Freescale Semicondutor, Inc. 2006. All rights reserved.
  8. *
  9. * Description:
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #undef DEBUG
  16. #include <linux/init.h>
  17. #include <linux/pci.h>
  18. #include <linux/of.h>
  19. #include <linux/root_dev.h>
  20. #include <linux/initrd.h>
  21. #include <asm/time.h>
  22. #include <asm/io.h>
  23. #include <asm/machdep.h>
  24. #include <asm/prom.h>
  25. #include <asm/mpc52xx.h>
  26. /* ************************************************************************
  27. *
  28. * Setup the architecture
  29. *
  30. */
  31. /* mpc5200 device tree match tables */
  32. static struct of_device_id mpc5200_cdm_ids[] __initdata = {
  33. { .compatible = "fsl,mpc5200-cdm", },
  34. { .compatible = "mpc5200-cdm", },
  35. {}
  36. };
  37. static struct of_device_id mpc5200_gpio_ids[] __initdata = {
  38. { .compatible = "fsl,mpc5200-gpio", },
  39. { .compatible = "mpc5200-gpio", },
  40. {}
  41. };
  42. /*
  43. * Fix clock configuration.
  44. *
  45. * Firmware is supposed to be responsible for this. If you are creating a
  46. * new board port, do *NOT* duplicate this code. Fix your boot firmware
  47. * to set it correctly in the first place
  48. */
  49. static void __init
  50. lite5200_fix_clock_config(void)
  51. {
  52. struct device_node *np;
  53. struct mpc52xx_cdm __iomem *cdm;
  54. /* Map zones */
  55. np = of_find_matching_node(NULL, mpc5200_cdm_ids);
  56. cdm = of_iomap(np, 0);
  57. of_node_put(np);
  58. if (!cdm) {
  59. printk(KERN_ERR "%s() failed; expect abnormal behaviour\n",
  60. __func__);
  61. return;
  62. }
  63. /* Use internal 48 Mhz */
  64. out_8(&cdm->ext_48mhz_en, 0x00);
  65. out_8(&cdm->fd_enable, 0x01);
  66. if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
  67. out_be16(&cdm->fd_counters, 0x0001);
  68. else
  69. out_be16(&cdm->fd_counters, 0x5555);
  70. /* Unmap the regs */
  71. iounmap(cdm);
  72. }
  73. /*
  74. * Fix setting of port_config register.
  75. *
  76. * Firmware is supposed to be responsible for this. If you are creating a
  77. * new board port, do *NOT* duplicate this code. Fix your boot firmware
  78. * to set it correctly in the first place
  79. */
  80. static void __init
  81. lite5200_fix_port_config(void)
  82. {
  83. struct device_node *np;
  84. struct mpc52xx_gpio __iomem *gpio;
  85. u32 port_config;
  86. np = of_find_matching_node(NULL, mpc5200_gpio_ids);
  87. gpio = of_iomap(np, 0);
  88. of_node_put(np);
  89. if (!gpio) {
  90. printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
  91. __func__);
  92. return;
  93. }
  94. /* Set port config */
  95. port_config = in_be32(&gpio->port_config);
  96. port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */
  97. port_config &= ~0x00007000; /* USB port : Differential mode */
  98. port_config |= 0x00001000; /* USB 1 only */
  99. port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
  100. port_config |= 0x01000000;
  101. pr_debug("port_config: old:%x new:%x\n",
  102. in_be32(&gpio->port_config), port_config);
  103. out_be32(&gpio->port_config, port_config);
  104. /* Unmap zone */
  105. iounmap(gpio);
  106. }
  107. #ifdef CONFIG_PM
  108. static void lite5200_suspend_prepare(void __iomem *mbar)
  109. {
  110. u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */
  111. u8 level = 0; /* wakeup on low level */
  112. mpc52xx_set_wakeup_gpio(pin, level);
  113. /*
  114. * power down usb port
  115. * this needs to be called before of-ohci suspend code
  116. */
  117. /* set ports to "power switched" and "powered at the same time"
  118. * USB Rh descriptor A: NPS = 0, PSM = 0 */
  119. out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300);
  120. /* USB Rh status: LPS = 1 - turn off power */
  121. out_be32(mbar + 0x1050, 0x00000001);
  122. }
  123. static void lite5200_resume_finish(void __iomem *mbar)
  124. {
  125. /* USB Rh status: LPSC = 1 - turn on power */
  126. out_be32(mbar + 0x1050, 0x00010000);
  127. }
  128. #endif
  129. static void __init lite5200_setup_arch(void)
  130. {
  131. if (ppc_md.progress)
  132. ppc_md.progress("lite5200_setup_arch()", 0);
  133. /* Map important registers from the internal memory map */
  134. mpc52xx_map_common_devices();
  135. /* Some mpc5200 & mpc5200b related configuration */
  136. mpc5200_setup_xlb_arbiter();
  137. /* Fix things that firmware should have done. */
  138. lite5200_fix_clock_config();
  139. lite5200_fix_port_config();
  140. #ifdef CONFIG_PM
  141. mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
  142. mpc52xx_suspend.board_resume_finish = lite5200_resume_finish;
  143. lite5200_pm_init();
  144. #endif
  145. mpc52xx_setup_pci();
  146. }
  147. /*
  148. * Called very early, MMU is off, device-tree isn't unflattened
  149. */
  150. static int __init lite5200_probe(void)
  151. {
  152. unsigned long node = of_get_flat_dt_root();
  153. const char *model = of_get_flat_dt_prop(node, "model", NULL);
  154. if (!of_flat_dt_is_compatible(node, "fsl,lite5200") &&
  155. !of_flat_dt_is_compatible(node, "fsl,lite5200b"))
  156. return 0;
  157. pr_debug("%s board found\n", model ? model : "unknown");
  158. return 1;
  159. }
  160. define_machine(lite5200) {
  161. .name = "lite5200",
  162. .probe = lite5200_probe,
  163. .setup_arch = lite5200_setup_arch,
  164. .init = mpc52xx_declare_of_platform_devices,
  165. .init_IRQ = mpc52xx_init_irq,
  166. .get_irq = mpc52xx_get_irq,
  167. .restart = mpc52xx_restart,
  168. .calibrate_decr = generic_calibrate_decr,
  169. };