fsl_85xx_l2ctlr.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Copyright 2009-2010, 2012 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/module.h>
  24. #include <linux/of_platform.h>
  25. #include <asm/io.h>
  26. #include "fsl_85xx_cache_ctlr.h"
  27. static char *sram_size;
  28. static char *sram_offset;
  29. struct mpc85xx_l2ctlr __iomem *l2ctlr;
  30. static int get_cache_sram_params(struct sram_parameters *sram_params)
  31. {
  32. unsigned long long addr;
  33. unsigned int size;
  34. if (!sram_size || (kstrtouint(sram_size, 0, &size) < 0))
  35. return -EINVAL;
  36. if (!sram_offset || (kstrtoull(sram_offset, 0, &addr) < 0))
  37. return -EINVAL;
  38. sram_params->sram_offset = addr;
  39. sram_params->sram_size = size;
  40. return 0;
  41. }
  42. static int __init get_size_from_cmdline(char *str)
  43. {
  44. if (!str)
  45. return 0;
  46. sram_size = str;
  47. return 1;
  48. }
  49. static int __init get_offset_from_cmdline(char *str)
  50. {
  51. if (!str)
  52. return 0;
  53. sram_offset = str;
  54. return 1;
  55. }
  56. __setup("cache-sram-size=", get_size_from_cmdline);
  57. __setup("cache-sram-offset=", get_offset_from_cmdline);
  58. static int mpc85xx_l2ctlr_of_probe(struct platform_device *dev)
  59. {
  60. long rval;
  61. unsigned int rem;
  62. unsigned char ways;
  63. const unsigned int *prop;
  64. unsigned int l2cache_size;
  65. struct sram_parameters sram_params;
  66. if (!dev->dev.of_node) {
  67. dev_err(&dev->dev, "Device's OF-node is NULL\n");
  68. return -EINVAL;
  69. }
  70. prop = of_get_property(dev->dev.of_node, "cache-size", NULL);
  71. if (!prop) {
  72. dev_err(&dev->dev, "Missing L2 cache-size\n");
  73. return -EINVAL;
  74. }
  75. l2cache_size = *prop;
  76. if (get_cache_sram_params(&sram_params)) {
  77. dev_err(&dev->dev,
  78. "Entire L2 as cache, provide valid sram offset and size\n");
  79. return -EINVAL;
  80. }
  81. rem = l2cache_size % sram_params.sram_size;
  82. ways = LOCK_WAYS_FULL * sram_params.sram_size / l2cache_size;
  83. if (rem || (ways & (ways - 1))) {
  84. dev_err(&dev->dev, "Illegal cache-sram-size in command line\n");
  85. return -EINVAL;
  86. }
  87. l2ctlr = of_iomap(dev->dev.of_node, 0);
  88. if (!l2ctlr) {
  89. dev_err(&dev->dev, "Can't map L2 controller\n");
  90. return -EINVAL;
  91. }
  92. /*
  93. * Write bits[0-17] to srbar0
  94. */
  95. out_be32(&l2ctlr->srbar0,
  96. lower_32_bits(sram_params.sram_offset) & L2SRAM_BAR_MSK_LO18);
  97. /*
  98. * Write bits[18-21] to srbare0
  99. */
  100. #ifdef CONFIG_PHYS_64BIT
  101. out_be32(&l2ctlr->srbarea0,
  102. upper_32_bits(sram_params.sram_offset) & L2SRAM_BARE_MSK_HI4);
  103. #endif
  104. clrsetbits_be32(&l2ctlr->ctl, L2CR_L2E, L2CR_L2FI);
  105. switch (ways) {
  106. case LOCK_WAYS_EIGHTH:
  107. setbits32(&l2ctlr->ctl,
  108. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_EIGHTH);
  109. break;
  110. case LOCK_WAYS_TWO_EIGHTH:
  111. setbits32(&l2ctlr->ctl,
  112. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_QUART);
  113. break;
  114. case LOCK_WAYS_HALF:
  115. setbits32(&l2ctlr->ctl,
  116. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_HALF);
  117. break;
  118. case LOCK_WAYS_FULL:
  119. default:
  120. setbits32(&l2ctlr->ctl,
  121. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_FULL);
  122. break;
  123. }
  124. eieio();
  125. rval = instantiate_cache_sram(dev, sram_params);
  126. if (rval < 0) {
  127. dev_err(&dev->dev, "Can't instantiate Cache-SRAM\n");
  128. iounmap(l2ctlr);
  129. return -EINVAL;
  130. }
  131. return 0;
  132. }
  133. static int mpc85xx_l2ctlr_of_remove(struct platform_device *dev)
  134. {
  135. BUG_ON(!l2ctlr);
  136. iounmap(l2ctlr);
  137. remove_cache_sram(dev);
  138. dev_info(&dev->dev, "MPC85xx L2 controller unloaded\n");
  139. return 0;
  140. }
  141. static const struct of_device_id mpc85xx_l2ctlr_of_match[] = {
  142. {
  143. .compatible = "fsl,p2020-l2-cache-controller",
  144. },
  145. {
  146. .compatible = "fsl,p2010-l2-cache-controller",
  147. },
  148. {
  149. .compatible = "fsl,p1020-l2-cache-controller",
  150. },
  151. {
  152. .compatible = "fsl,p1011-l2-cache-controller",
  153. },
  154. {
  155. .compatible = "fsl,p1013-l2-cache-controller",
  156. },
  157. {
  158. .compatible = "fsl,p1022-l2-cache-controller",
  159. },
  160. {
  161. .compatible = "fsl,mpc8548-l2-cache-controller",
  162. },
  163. { .compatible = "fsl,mpc8544-l2-cache-controller",},
  164. { .compatible = "fsl,mpc8572-l2-cache-controller",},
  165. { .compatible = "fsl,mpc8536-l2-cache-controller",},
  166. { .compatible = "fsl,p1021-l2-cache-controller",},
  167. { .compatible = "fsl,p1012-l2-cache-controller",},
  168. { .compatible = "fsl,p1025-l2-cache-controller",},
  169. { .compatible = "fsl,p1016-l2-cache-controller",},
  170. { .compatible = "fsl,p1024-l2-cache-controller",},
  171. { .compatible = "fsl,p1015-l2-cache-controller",},
  172. { .compatible = "fsl,p1010-l2-cache-controller",},
  173. { .compatible = "fsl,bsc9131-l2-cache-controller",},
  174. {},
  175. };
  176. static struct platform_driver mpc85xx_l2ctlr_of_platform_driver = {
  177. .driver = {
  178. .name = "fsl-l2ctlr",
  179. .of_match_table = mpc85xx_l2ctlr_of_match,
  180. },
  181. .probe = mpc85xx_l2ctlr_of_probe,
  182. .remove = mpc85xx_l2ctlr_of_remove,
  183. };
  184. static __init int mpc85xx_l2ctlr_of_init(void)
  185. {
  186. return platform_driver_register(&mpc85xx_l2ctlr_of_platform_driver);
  187. }
  188. static void __exit mpc85xx_l2ctlr_of_exit(void)
  189. {
  190. platform_driver_unregister(&mpc85xx_l2ctlr_of_platform_driver);
  191. }
  192. subsys_initcall(mpc85xx_l2ctlr_of_init);
  193. module_exit(mpc85xx_l2ctlr_of_exit);
  194. MODULE_DESCRIPTION("Freescale MPC85xx L2 controller init");
  195. MODULE_LICENSE("GPL v2");