lite5200.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 2006 Freescale Semiconductor, Inc. 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/of_address.h>
  20. #include <linux/root_dev.h>
  21. #include <linux/initrd.h>
  22. #include <asm/time.h>
  23. #include <asm/io.h>
  24. #include <asm/machdep.h>
  25. #include <asm/prom.h>
  26. #include <asm/mpc52xx.h>
  27. /* ************************************************************************
  28. *
  29. * Setup the architecture
  30. *
  31. */
  32. /* mpc5200 device tree match tables */
  33. static const struct of_device_id mpc5200_cdm_ids[] __initconst = {
  34. { .compatible = "fsl,mpc5200-cdm", },
  35. { .compatible = "mpc5200-cdm", },
  36. {}
  37. };
  38. static const struct of_device_id mpc5200_gpio_ids[] __initconst = {
  39. { .compatible = "fsl,mpc5200-gpio", },
  40. { .compatible = "mpc5200-gpio", },
  41. {}
  42. };
  43. /*
  44. * Fix clock configuration.
  45. *
  46. * Firmware is supposed to be responsible for this. If you are creating a
  47. * new board port, do *NOT* duplicate this code. Fix your boot firmware
  48. * to set it correctly in the first place
  49. */
  50. static void __init
  51. lite5200_fix_clock_config(void)
  52. {
  53. struct device_node *np;
  54. struct mpc52xx_cdm __iomem *cdm;
  55. /* Map zones */
  56. np = of_find_matching_node(NULL, mpc5200_cdm_ids);
  57. cdm = of_iomap(np, 0);
  58. of_node_put(np);
  59. if (!cdm) {
  60. printk(KERN_ERR "%s() failed; expect abnormal behaviour\n",
  61. __func__);
  62. return;
  63. }
  64. /* Use internal 48 Mhz */
  65. out_8(&cdm->ext_48mhz_en, 0x00);
  66. out_8(&cdm->fd_enable, 0x01);
  67. if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
  68. out_be16(&cdm->fd_counters, 0x0001);
  69. else
  70. out_be16(&cdm->fd_counters, 0x5555);
  71. /* Unmap the regs */
  72. iounmap(cdm);
  73. }
  74. /*
  75. * Fix setting of port_config register.
  76. *
  77. * Firmware is supposed to be responsible for this. If you are creating a
  78. * new board port, do *NOT* duplicate this code. Fix your boot firmware
  79. * to set it correctly in the first place
  80. */
  81. static void __init
  82. lite5200_fix_port_config(void)
  83. {
  84. struct device_node *np;
  85. struct mpc52xx_gpio __iomem *gpio;
  86. u32 port_config;
  87. np = of_find_matching_node(NULL, mpc5200_gpio_ids);
  88. gpio = of_iomap(np, 0);
  89. of_node_put(np);
  90. if (!gpio) {
  91. printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
  92. __func__);
  93. return;
  94. }
  95. /* Set port config */
  96. port_config = in_be32(&gpio->port_config);
  97. port_config &= ~0x00800000; /* 48Mhz internal, pin is GPIO */
  98. port_config &= ~0x00007000; /* USB port : Differential mode */
  99. port_config |= 0x00001000; /* USB 1 only */
  100. port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
  101. port_config |= 0x01000000;
  102. pr_debug("port_config: old:%x new:%x\n",
  103. in_be32(&gpio->port_config), port_config);
  104. out_be32(&gpio->port_config, port_config);
  105. /* Unmap zone */
  106. iounmap(gpio);
  107. }
  108. #ifdef CONFIG_PM
  109. static void lite5200_suspend_prepare(void __iomem *mbar)
  110. {
  111. u8 pin = 1; /* GPIO_WKUP_1 (GPIO_PSC2_4) */
  112. u8 level = 0; /* wakeup on low level */
  113. mpc52xx_set_wakeup_gpio(pin, level);
  114. /*
  115. * power down usb port
  116. * this needs to be called before of-ohci suspend code
  117. */
  118. /* set ports to "power switched" and "powered at the same time"
  119. * USB Rh descriptor A: NPS = 0, PSM = 0 */
  120. out_be32(mbar + 0x1048, in_be32(mbar + 0x1048) & ~0x300);
  121. /* USB Rh status: LPS = 1 - turn off power */
  122. out_be32(mbar + 0x1050, 0x00000001);
  123. }
  124. static void lite5200_resume_finish(void __iomem *mbar)
  125. {
  126. /* USB Rh status: LPSC = 1 - turn on power */
  127. out_be32(mbar + 0x1050, 0x00010000);
  128. }
  129. #endif
  130. static void __init lite5200_setup_arch(void)
  131. {
  132. if (ppc_md.progress)
  133. ppc_md.progress("lite5200_setup_arch()", 0);
  134. /* Map important registers from the internal memory map */
  135. mpc52xx_map_common_devices();
  136. /* Some mpc5200 & mpc5200b related configuration */
  137. mpc5200_setup_xlb_arbiter();
  138. /* Fix things that firmware should have done. */
  139. lite5200_fix_clock_config();
  140. lite5200_fix_port_config();
  141. #ifdef CONFIG_PM
  142. mpc52xx_suspend.board_suspend_prepare = lite5200_suspend_prepare;
  143. mpc52xx_suspend.board_resume_finish = lite5200_resume_finish;
  144. lite5200_pm_init();
  145. #endif
  146. mpc52xx_setup_pci();
  147. }
  148. static const char * const board[] __initconst = {
  149. "fsl,lite5200",
  150. "fsl,lite5200b",
  151. NULL,
  152. };
  153. /*
  154. * Called very early, MMU is off, device-tree isn't unflattened
  155. */
  156. static int __init lite5200_probe(void)
  157. {
  158. return of_flat_dt_match(of_get_flat_dt_root(), board);
  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. };