atl2c.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0
  2. // Copyright (C) 2005-2017 Andes Technology Corporation
  3. #include <linux/compiler.h>
  4. #include <linux/of_address.h>
  5. #include <linux/of_fdt.h>
  6. #include <linux/of_platform.h>
  7. #include <asm/l2_cache.h>
  8. void __iomem *atl2c_base;
  9. static const struct of_device_id atl2c_ids[] __initconst = {
  10. {.compatible = "andestech,atl2c",}
  11. };
  12. static int __init atl2c_of_init(void)
  13. {
  14. struct device_node *np;
  15. struct resource res;
  16. unsigned long tmp = 0;
  17. unsigned long l2set, l2way, l2clsz;
  18. if (!(__nds32__mfsr(NDS32_SR_MSC_CFG) & MSC_CFG_mskL2C))
  19. return -ENODEV;
  20. np = of_find_matching_node(NULL, atl2c_ids);
  21. if (!np)
  22. return -ENODEV;
  23. if (of_address_to_resource(np, 0, &res))
  24. return -ENODEV;
  25. atl2c_base = ioremap(res.start, resource_size(&res));
  26. if (!atl2c_base)
  27. return -ENOMEM;
  28. l2set =
  29. 64 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >>
  30. L2_CA_CONF_offL2SET);
  31. l2way =
  32. 1 +
  33. ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >>
  34. L2_CA_CONF_offL2WAY);
  35. l2clsz =
  36. 4 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >>
  37. L2_CA_CONF_offL2CLSZ);
  38. pr_info("L2:%luKB/%luS/%luW/%luB\n",
  39. l2set * l2way * l2clsz / 1024, l2set, l2way, l2clsz);
  40. tmp = L2C_R_REG(L2CC_PROT_OFF);
  41. tmp &= ~L2CC_PROT_mskMRWEN;
  42. L2C_W_REG(L2CC_PROT_OFF, tmp);
  43. tmp = L2C_R_REG(L2CC_SETUP_OFF);
  44. tmp &= ~L2CC_SETUP_mskPART;
  45. L2C_W_REG(L2CC_SETUP_OFF, tmp);
  46. tmp = L2C_R_REG(L2CC_CTRL_OFF);
  47. tmp |= L2CC_CTRL_mskEN;
  48. L2C_W_REG(L2CC_CTRL_OFF, tmp);
  49. return 0;
  50. }
  51. subsys_initcall(atl2c_of_init);