mpc52xx_common.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. *
  3. * Utility functions for the Freescale MPC52xx.
  4. *
  5. * Copyright (C) 2006 Sylvain Munaut <tnt@246tNt.com>
  6. *
  7. * This file is licensed under the terms of the GNU General Public License
  8. * version 2. This program is licensed "as is" without any warranty of any
  9. * kind, whether express or implied.
  10. *
  11. */
  12. #undef DEBUG
  13. #include <linux/kernel.h>
  14. #include <linux/of_platform.h>
  15. #include <asm/io.h>
  16. #include <asm/prom.h>
  17. #include <asm/mpc52xx.h>
  18. static void __iomem *
  19. mpc52xx_map_node(struct device_node *ofn)
  20. {
  21. const u32 *regaddr_p;
  22. u64 regaddr64, size64;
  23. if (!ofn)
  24. return NULL;
  25. regaddr_p = of_get_address(ofn, 0, &size64, NULL);
  26. if (!regaddr_p) {
  27. of_node_put(ofn);
  28. return NULL;
  29. }
  30. regaddr64 = of_translate_address(ofn, regaddr_p);
  31. of_node_put(ofn);
  32. return ioremap((u32)regaddr64, (u32)size64);
  33. }
  34. void __iomem *
  35. mpc52xx_find_and_map(const char *compatible)
  36. {
  37. return mpc52xx_map_node(
  38. of_find_compatible_node(NULL, NULL, compatible));
  39. }
  40. EXPORT_SYMBOL(mpc52xx_find_and_map);
  41. void __iomem *
  42. mpc52xx_find_and_map_path(const char *path)
  43. {
  44. return mpc52xx_map_node(of_find_node_by_path(path));
  45. }
  46. EXPORT_SYMBOL(mpc52xx_find_and_map_path);
  47. /**
  48. * mpc52xx_find_ipb_freq - Find the IPB bus frequency for a device
  49. * @node: device node
  50. *
  51. * Returns IPB bus frequency, or 0 if the bus frequency cannot be found.
  52. */
  53. unsigned int
  54. mpc52xx_find_ipb_freq(struct device_node *node)
  55. {
  56. struct device_node *np;
  57. const unsigned int *p_ipb_freq = NULL;
  58. of_node_get(node);
  59. while (node) {
  60. p_ipb_freq = of_get_property(node, "bus-frequency", NULL);
  61. if (p_ipb_freq)
  62. break;
  63. np = of_get_parent(node);
  64. of_node_put(node);
  65. node = np;
  66. }
  67. if (node)
  68. of_node_put(node);
  69. return p_ipb_freq ? *p_ipb_freq : 0;
  70. }
  71. EXPORT_SYMBOL(mpc52xx_find_ipb_freq);
  72. /*
  73. * Configure the XLB arbiter settings to match what Linux expects.
  74. */
  75. void __init
  76. mpc5200_setup_xlb_arbiter(void)
  77. {
  78. struct mpc52xx_xlb __iomem *xlb;
  79. xlb = mpc52xx_find_and_map("mpc5200-xlb");
  80. if (!xlb) {
  81. printk(KERN_ERR __FILE__ ": "
  82. "Error mapping XLB in mpc52xx_setup_cpu(). "
  83. "Expect some abnormal behavior\n");
  84. return;
  85. }
  86. /* Configure the XLB Arbiter priorities */
  87. out_be32(&xlb->master_pri_enable, 0xff);
  88. out_be32(&xlb->master_priority, 0x11111111);
  89. /* Disable XLB pipelining
  90. * (cfr errate 292. We could do this only just before ATA PIO
  91. * transaction and re-enable it afterwards ...)
  92. */
  93. out_be32(&xlb->config, in_be32(&xlb->config) | MPC52xx_XLB_CFG_PLDIS);
  94. iounmap(xlb);
  95. }
  96. void __init
  97. mpc52xx_declare_of_platform_devices(void)
  98. {
  99. /* Find every child of the SOC node and add it to of_platform */
  100. if (of_platform_bus_probe(NULL, NULL, NULL))
  101. printk(KERN_ERR __FILE__ ": "
  102. "Error while probing of_platform bus\n");
  103. }