fsl_85xx_l2ctlr.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /*
  2. * Copyright 2009-2010 Freescale Semiconductor, Inc.
  3. *
  4. * QorIQ (P1/P2) L2 controller init for Cache-SRAM instantiation
  5. *
  6. * Author: Vivek Mahajan <vivek.mahajan@freescale.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/of_platform.h>
  24. #include <asm/io.h>
  25. #include "fsl_85xx_cache_ctlr.h"
  26. static char *sram_size;
  27. static char *sram_offset;
  28. struct mpc85xx_l2ctlr __iomem *l2ctlr;
  29. static long get_cache_sram_size(void)
  30. {
  31. unsigned long val;
  32. if (!sram_size || (strict_strtoul(sram_size, 0, &val) < 0))
  33. return -EINVAL;
  34. return val;
  35. }
  36. static long get_cache_sram_offset(void)
  37. {
  38. unsigned long val;
  39. if (!sram_offset || (strict_strtoul(sram_offset, 0, &val) < 0))
  40. return -EINVAL;
  41. return val;
  42. }
  43. static int __init get_size_from_cmdline(char *str)
  44. {
  45. if (!str)
  46. return 0;
  47. sram_size = str;
  48. return 1;
  49. }
  50. static int __init get_offset_from_cmdline(char *str)
  51. {
  52. if (!str)
  53. return 0;
  54. sram_offset = str;
  55. return 1;
  56. }
  57. __setup("cache-sram-size=", get_size_from_cmdline);
  58. __setup("cache-sram-offset=", get_offset_from_cmdline);
  59. static int __devinit mpc85xx_l2ctlr_of_probe(struct platform_device *dev)
  60. {
  61. long rval;
  62. unsigned int rem;
  63. unsigned char ways;
  64. const unsigned int *prop;
  65. unsigned int l2cache_size;
  66. struct sram_parameters sram_params;
  67. if (!dev->dev.of_node) {
  68. dev_err(&dev->dev, "Device's OF-node is NULL\n");
  69. return -EINVAL;
  70. }
  71. prop = of_get_property(dev->dev.of_node, "cache-size", NULL);
  72. if (!prop) {
  73. dev_err(&dev->dev, "Missing L2 cache-size\n");
  74. return -EINVAL;
  75. }
  76. l2cache_size = *prop;
  77. sram_params.sram_size = get_cache_sram_size();
  78. if ((int)sram_params.sram_size <= 0) {
  79. dev_err(&dev->dev,
  80. "Entire L2 as cache, Aborting Cache-SRAM stuff\n");
  81. return -EINVAL;
  82. }
  83. sram_params.sram_offset = get_cache_sram_offset();
  84. if ((int64_t)sram_params.sram_offset <= 0) {
  85. dev_err(&dev->dev,
  86. "Entire L2 as cache, provide a valid sram offset\n");
  87. return -EINVAL;
  88. }
  89. rem = l2cache_size % sram_params.sram_size;
  90. ways = LOCK_WAYS_FULL * sram_params.sram_size / l2cache_size;
  91. if (rem || (ways & (ways - 1))) {
  92. dev_err(&dev->dev, "Illegal cache-sram-size in command line\n");
  93. return -EINVAL;
  94. }
  95. l2ctlr = of_iomap(dev->dev.of_node, 0);
  96. if (!l2ctlr) {
  97. dev_err(&dev->dev, "Can't map L2 controller\n");
  98. return -EINVAL;
  99. }
  100. /*
  101. * Write bits[0-17] to srbar0
  102. */
  103. out_be32(&l2ctlr->srbar0,
  104. sram_params.sram_offset & L2SRAM_BAR_MSK_LO18);
  105. /*
  106. * Write bits[18-21] to srbare0
  107. */
  108. #ifdef CONFIG_PHYS_64BIT
  109. out_be32(&l2ctlr->srbarea0,
  110. (sram_params.sram_offset >> 32) & L2SRAM_BARE_MSK_HI4);
  111. #endif
  112. clrsetbits_be32(&l2ctlr->ctl, L2CR_L2E, L2CR_L2FI);
  113. switch (ways) {
  114. case LOCK_WAYS_EIGHTH:
  115. setbits32(&l2ctlr->ctl,
  116. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_EIGHTH);
  117. break;
  118. case LOCK_WAYS_TWO_EIGHTH:
  119. setbits32(&l2ctlr->ctl,
  120. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_QUART);
  121. break;
  122. case LOCK_WAYS_HALF:
  123. setbits32(&l2ctlr->ctl,
  124. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_HALF);
  125. break;
  126. case LOCK_WAYS_FULL:
  127. default:
  128. setbits32(&l2ctlr->ctl,
  129. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_FULL);
  130. break;
  131. }
  132. eieio();
  133. rval = instantiate_cache_sram(dev, sram_params);
  134. if (rval < 0) {
  135. dev_err(&dev->dev, "Can't instantiate Cache-SRAM\n");
  136. iounmap(l2ctlr);
  137. return -EINVAL;
  138. }
  139. return 0;
  140. }
  141. static int __devexit mpc85xx_l2ctlr_of_remove(struct platform_device *dev)
  142. {
  143. BUG_ON(!l2ctlr);
  144. iounmap(l2ctlr);
  145. remove_cache_sram(dev);
  146. dev_info(&dev->dev, "MPC85xx L2 controller unloaded\n");
  147. return 0;
  148. }
  149. static struct of_device_id mpc85xx_l2ctlr_of_match[] = {
  150. {
  151. .compatible = "fsl,p2020-l2-cache-controller",
  152. },
  153. {
  154. .compatible = "fsl,p2010-l2-cache-controller",
  155. },
  156. {
  157. .compatible = "fsl,p1020-l2-cache-controller",
  158. },
  159. {
  160. .compatible = "fsl,p1011-l2-cache-controller",
  161. },
  162. {
  163. .compatible = "fsl,p1013-l2-cache-controller",
  164. },
  165. {
  166. .compatible = "fsl,p1022-l2-cache-controller",
  167. },
  168. {},
  169. };
  170. static struct platform_driver mpc85xx_l2ctlr_of_platform_driver = {
  171. .driver = {
  172. .name = "fsl-l2ctlr",
  173. .owner = THIS_MODULE,
  174. .of_match_table = mpc85xx_l2ctlr_of_match,
  175. },
  176. .probe = mpc85xx_l2ctlr_of_probe,
  177. .remove = __devexit_p(mpc85xx_l2ctlr_of_remove),
  178. };
  179. static __init int mpc85xx_l2ctlr_of_init(void)
  180. {
  181. return platform_driver_register(&mpc85xx_l2ctlr_of_platform_driver);
  182. }
  183. static void __exit mpc85xx_l2ctlr_of_exit(void)
  184. {
  185. platform_driver_unregister(&mpc85xx_l2ctlr_of_platform_driver);
  186. }
  187. subsys_initcall(mpc85xx_l2ctlr_of_init);
  188. module_exit(mpc85xx_l2ctlr_of_exit);
  189. MODULE_DESCRIPTION("Freescale MPC85xx L2 controller init");
  190. MODULE_LICENSE("GPL v2");