mpc52xx_common.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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 <asm/io.h>
  15. #include <asm/prom.h>
  16. #include <asm/of_platform.h>
  17. #include <asm/mpc52xx.h>
  18. void __iomem *
  19. mpc52xx_find_and_map(const char *compatible)
  20. {
  21. struct device_node *ofn;
  22. const u32 *regaddr_p;
  23. u64 regaddr64, size64;
  24. ofn = of_find_compatible_node(NULL, NULL, compatible);
  25. if (!ofn)
  26. return NULL;
  27. regaddr_p = of_get_address(ofn, 0, &size64, NULL);
  28. if (!regaddr_p) {
  29. of_node_put(ofn);
  30. return NULL;
  31. }
  32. regaddr64 = of_translate_address(ofn, regaddr_p);
  33. of_node_put(ofn);
  34. return ioremap((u32)regaddr64, (u32)size64);
  35. }
  36. EXPORT_SYMBOL(mpc52xx_find_and_map);
  37. /**
  38. * mpc52xx_find_ipb_freq - Find the IPB bus frequency for a device
  39. * @node: device node
  40. *
  41. * Returns IPB bus frequency, or 0 if the bus frequency cannot be found.
  42. */
  43. unsigned int
  44. mpc52xx_find_ipb_freq(struct device_node *node)
  45. {
  46. struct device_node *np;
  47. const unsigned int *p_ipb_freq = NULL;
  48. of_node_get(node);
  49. while (node) {
  50. p_ipb_freq = get_property(node, "bus-frequency", NULL);
  51. if (p_ipb_freq)
  52. break;
  53. np = of_get_parent(node);
  54. of_node_put(node);
  55. node = np;
  56. }
  57. if (node)
  58. of_node_put(node);
  59. return p_ipb_freq ? *p_ipb_freq : 0;
  60. }
  61. EXPORT_SYMBOL(mpc52xx_find_ipb_freq);
  62. void __init
  63. mpc52xx_setup_cpu(void)
  64. {
  65. struct mpc52xx_cdm __iomem *cdm;
  66. struct mpc52xx_xlb __iomem *xlb;
  67. /* Map zones */
  68. cdm = mpc52xx_find_and_map("mpc52xx-cdm");
  69. xlb = mpc52xx_find_and_map("mpc52xx-xlb");
  70. if (!cdm || !xlb) {
  71. printk(KERN_ERR __FILE__ ": "
  72. "Error while mapping CDM/XLB during mpc52xx_setup_cpu. "
  73. "Expect some abnormal behavior\n");
  74. goto unmap_regs;
  75. }
  76. /* Use internal 48 Mhz */
  77. out_8(&cdm->ext_48mhz_en, 0x00);
  78. out_8(&cdm->fd_enable, 0x01);
  79. if (in_be32(&cdm->rstcfg) & 0x40) /* Assumes 33Mhz clock */
  80. out_be16(&cdm->fd_counters, 0x0001);
  81. else
  82. out_be16(&cdm->fd_counters, 0x5555);
  83. /* Configure the XLB Arbiter priorities */
  84. out_be32(&xlb->master_pri_enable, 0xff);
  85. out_be32(&xlb->master_priority, 0x11111111);
  86. /* Disable XLB pipelining */
  87. /* (cfr errate 292. We could do this only just before ATA PIO
  88. transaction and re-enable it afterwards ...) */
  89. out_be32(&xlb->config, in_be32(&xlb->config) | MPC52xx_XLB_CFG_PLDIS);
  90. /* Unmap zones */
  91. unmap_regs:
  92. if (cdm) iounmap(cdm);
  93. if (xlb) iounmap(xlb);
  94. }
  95. void __init
  96. mpc52xx_declare_of_platform_devices(void)
  97. {
  98. /* Find every child of the SOC node and add it to of_platform */
  99. if (of_platform_bus_probe(NULL, NULL, NULL))
  100. printk(KERN_ERR __FILE__ ": "
  101. "Error while probing of_platform bus\n");
  102. }