fsl_85xx_l2ctlr.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. return 0; /* fall back to L2 cache only */
  78. rem = l2cache_size % sram_params.sram_size;
  79. ways = LOCK_WAYS_FULL * sram_params.sram_size / l2cache_size;
  80. if (rem || (ways & (ways - 1))) {
  81. dev_err(&dev->dev, "Illegal cache-sram-size in command line\n");
  82. return -EINVAL;
  83. }
  84. l2ctlr = of_iomap(dev->dev.of_node, 0);
  85. if (!l2ctlr) {
  86. dev_err(&dev->dev, "Can't map L2 controller\n");
  87. return -EINVAL;
  88. }
  89. /*
  90. * Write bits[0-17] to srbar0
  91. */
  92. out_be32(&l2ctlr->srbar0,
  93. lower_32_bits(sram_params.sram_offset) & L2SRAM_BAR_MSK_LO18);
  94. /*
  95. * Write bits[18-21] to srbare0
  96. */
  97. #ifdef CONFIG_PHYS_64BIT
  98. out_be32(&l2ctlr->srbarea0,
  99. upper_32_bits(sram_params.sram_offset) & L2SRAM_BARE_MSK_HI4);
  100. #endif
  101. clrsetbits_be32(&l2ctlr->ctl, L2CR_L2E, L2CR_L2FI);
  102. switch (ways) {
  103. case LOCK_WAYS_EIGHTH:
  104. setbits32(&l2ctlr->ctl,
  105. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_EIGHTH);
  106. break;
  107. case LOCK_WAYS_TWO_EIGHTH:
  108. setbits32(&l2ctlr->ctl,
  109. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_QUART);
  110. break;
  111. case LOCK_WAYS_HALF:
  112. setbits32(&l2ctlr->ctl,
  113. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_HALF);
  114. break;
  115. case LOCK_WAYS_FULL:
  116. default:
  117. setbits32(&l2ctlr->ctl,
  118. L2CR_L2E | L2CR_L2FI | L2CR_SRAM_FULL);
  119. break;
  120. }
  121. eieio();
  122. rval = instantiate_cache_sram(dev, sram_params);
  123. if (rval < 0) {
  124. dev_err(&dev->dev, "Can't instantiate Cache-SRAM\n");
  125. iounmap(l2ctlr);
  126. return -EINVAL;
  127. }
  128. return 0;
  129. }
  130. static int mpc85xx_l2ctlr_of_remove(struct platform_device *dev)
  131. {
  132. BUG_ON(!l2ctlr);
  133. iounmap(l2ctlr);
  134. remove_cache_sram(dev);
  135. dev_info(&dev->dev, "MPC85xx L2 controller unloaded\n");
  136. return 0;
  137. }
  138. static const struct of_device_id mpc85xx_l2ctlr_of_match[] = {
  139. {
  140. .compatible = "fsl,p2020-l2-cache-controller",
  141. },
  142. {
  143. .compatible = "fsl,p2010-l2-cache-controller",
  144. },
  145. {
  146. .compatible = "fsl,p1020-l2-cache-controller",
  147. },
  148. {
  149. .compatible = "fsl,p1011-l2-cache-controller",
  150. },
  151. {
  152. .compatible = "fsl,p1013-l2-cache-controller",
  153. },
  154. {
  155. .compatible = "fsl,p1022-l2-cache-controller",
  156. },
  157. {
  158. .compatible = "fsl,mpc8548-l2-cache-controller",
  159. },
  160. { .compatible = "fsl,mpc8544-l2-cache-controller",},
  161. { .compatible = "fsl,mpc8572-l2-cache-controller",},
  162. { .compatible = "fsl,mpc8536-l2-cache-controller",},
  163. { .compatible = "fsl,p1021-l2-cache-controller",},
  164. { .compatible = "fsl,p1012-l2-cache-controller",},
  165. { .compatible = "fsl,p1025-l2-cache-controller",},
  166. { .compatible = "fsl,p1016-l2-cache-controller",},
  167. { .compatible = "fsl,p1024-l2-cache-controller",},
  168. { .compatible = "fsl,p1015-l2-cache-controller",},
  169. { .compatible = "fsl,p1010-l2-cache-controller",},
  170. { .compatible = "fsl,bsc9131-l2-cache-controller",},
  171. {},
  172. };
  173. static struct platform_driver mpc85xx_l2ctlr_of_platform_driver = {
  174. .driver = {
  175. .name = "fsl-l2ctlr",
  176. .of_match_table = mpc85xx_l2ctlr_of_match,
  177. },
  178. .probe = mpc85xx_l2ctlr_of_probe,
  179. .remove = mpc85xx_l2ctlr_of_remove,
  180. };
  181. static __init int mpc85xx_l2ctlr_of_init(void)
  182. {
  183. return platform_driver_register(&mpc85xx_l2ctlr_of_platform_driver);
  184. }
  185. static void __exit mpc85xx_l2ctlr_of_exit(void)
  186. {
  187. platform_driver_unregister(&mpc85xx_l2ctlr_of_platform_driver);
  188. }
  189. subsys_initcall(mpc85xx_l2ctlr_of_init);
  190. module_exit(mpc85xx_l2ctlr_of_exit);
  191. MODULE_DESCRIPTION("Freescale MPC85xx L2 controller init");
  192. MODULE_LICENSE("GPL v2");