mpc512x_shared.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * Copyright (C) 2007,2008 Freescale Semiconductor, Inc. All rights reserved.
  3. *
  4. * Author: John Rigby <jrigby@freescale.com>
  5. *
  6. * Description:
  7. * MPC512x Shared code
  8. *
  9. * This is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/io.h>
  16. #include <linux/irq.h>
  17. #include <linux/of_platform.h>
  18. #include <asm/machdep.h>
  19. #include <asm/ipic.h>
  20. #include <asm/prom.h>
  21. #include <asm/time.h>
  22. #include <asm/mpc5121.h>
  23. #include <asm/mpc52xx_psc.h>
  24. #include "mpc512x.h"
  25. static struct mpc512x_reset_module __iomem *reset_module_base;
  26. static void __init mpc512x_restart_init(void)
  27. {
  28. struct device_node *np;
  29. np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-reset");
  30. if (!np)
  31. return;
  32. reset_module_base = of_iomap(np, 0);
  33. of_node_put(np);
  34. }
  35. void mpc512x_restart(char *cmd)
  36. {
  37. if (reset_module_base) {
  38. /* Enable software reset "RSTE" */
  39. out_be32(&reset_module_base->rpr, 0x52535445);
  40. /* Set software hard reset */
  41. out_be32(&reset_module_base->rcr, 0x2);
  42. } else {
  43. pr_err("Restart module not mapped.\n");
  44. }
  45. for (;;)
  46. ;
  47. }
  48. void __init mpc512x_init_IRQ(void)
  49. {
  50. struct device_node *np;
  51. np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-ipic");
  52. if (!np)
  53. return;
  54. ipic_init(np, 0);
  55. of_node_put(np);
  56. /*
  57. * Initialize the default interrupt mapping priorities,
  58. * in case the boot rom changed something on us.
  59. */
  60. ipic_set_default_priority();
  61. }
  62. /*
  63. * Nodes to do bus probe on, soc and localbus
  64. */
  65. static struct of_device_id __initdata of_bus_ids[] = {
  66. { .compatible = "fsl,mpc5121-immr", },
  67. { .compatible = "fsl,mpc5121-localbus", },
  68. {},
  69. };
  70. void __init mpc512x_declare_of_platform_devices(void)
  71. {
  72. struct device_node *np;
  73. if (of_platform_bus_probe(NULL, of_bus_ids, NULL))
  74. printk(KERN_ERR __FILE__ ": "
  75. "Error while probing of_platform bus\n");
  76. np = of_find_compatible_node(NULL, NULL, "fsl,mpc5121-nfc");
  77. if (np) {
  78. of_platform_device_create(np, NULL, NULL);
  79. of_node_put(np);
  80. }
  81. }
  82. #define DEFAULT_FIFO_SIZE 16
  83. static unsigned int __init get_fifo_size(struct device_node *np,
  84. char *prop_name)
  85. {
  86. const unsigned int *fp;
  87. fp = of_get_property(np, prop_name, NULL);
  88. if (fp)
  89. return *fp;
  90. pr_warning("no %s property in %s node, defaulting to %d\n",
  91. prop_name, np->full_name, DEFAULT_FIFO_SIZE);
  92. return DEFAULT_FIFO_SIZE;
  93. }
  94. #define FIFOC(_base) ((struct mpc512x_psc_fifo __iomem *) \
  95. ((u32)(_base) + sizeof(struct mpc52xx_psc)))
  96. /* Init PSC FIFO space for TX and RX slices */
  97. void __init mpc512x_psc_fifo_init(void)
  98. {
  99. struct device_node *np;
  100. void __iomem *psc;
  101. unsigned int tx_fifo_size;
  102. unsigned int rx_fifo_size;
  103. int fifobase = 0; /* current fifo address in 32 bit words */
  104. for_each_compatible_node(np, NULL, "fsl,mpc5121-psc") {
  105. tx_fifo_size = get_fifo_size(np, "fsl,tx-fifo-size");
  106. rx_fifo_size = get_fifo_size(np, "fsl,rx-fifo-size");
  107. /* size in register is in 4 byte units */
  108. tx_fifo_size /= 4;
  109. rx_fifo_size /= 4;
  110. if (!tx_fifo_size)
  111. tx_fifo_size = 1;
  112. if (!rx_fifo_size)
  113. rx_fifo_size = 1;
  114. psc = of_iomap(np, 0);
  115. if (!psc) {
  116. pr_err("%s: Can't map %s device\n",
  117. __func__, np->full_name);
  118. continue;
  119. }
  120. /* FIFO space is 4KiB, check if requested size is available */
  121. if ((fifobase + tx_fifo_size + rx_fifo_size) > 0x1000) {
  122. pr_err("%s: no fifo space available for %s\n",
  123. __func__, np->full_name);
  124. iounmap(psc);
  125. /*
  126. * chances are that another device requests less
  127. * fifo space, so we continue.
  128. */
  129. continue;
  130. }
  131. /* set tx and rx fifo size registers */
  132. out_be32(&FIFOC(psc)->txsz, (fifobase << 16) | tx_fifo_size);
  133. fifobase += tx_fifo_size;
  134. out_be32(&FIFOC(psc)->rxsz, (fifobase << 16) | rx_fifo_size);
  135. fifobase += rx_fifo_size;
  136. /* reset and enable the slices */
  137. out_be32(&FIFOC(psc)->txcmd, 0x80);
  138. out_be32(&FIFOC(psc)->txcmd, 0x01);
  139. out_be32(&FIFOC(psc)->rxcmd, 0x80);
  140. out_be32(&FIFOC(psc)->rxcmd, 0x01);
  141. iounmap(psc);
  142. }
  143. }
  144. void __init mpc512x_init(void)
  145. {
  146. mpc512x_declare_of_platform_devices();
  147. mpc5121_clk_init();
  148. mpc512x_restart_init();
  149. mpc512x_psc_fifo_init();
  150. }