atl2c.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. };
  13. static int __init atl2c_of_init(void)
  14. {
  15. struct device_node *np;
  16. struct resource res;
  17. unsigned long tmp = 0;
  18. unsigned long l2set, l2way, l2clsz;
  19. if (!(__nds32__mfsr(NDS32_SR_MSC_CFG) & MSC_CFG_mskL2C))
  20. return -ENODEV;
  21. np = of_find_matching_node(NULL, atl2c_ids);
  22. if (!np)
  23. return -ENODEV;
  24. if (of_address_to_resource(np, 0, &res))
  25. return -ENODEV;
  26. atl2c_base = ioremap(res.start, resource_size(&res));
  27. if (!atl2c_base)
  28. return -ENOMEM;
  29. l2set =
  30. 64 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2SET) >>
  31. L2_CA_CONF_offL2SET);
  32. l2way =
  33. 1 +
  34. ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2WAY) >>
  35. L2_CA_CONF_offL2WAY);
  36. l2clsz =
  37. 4 << ((L2C_R_REG(L2_CA_CONF_OFF) & L2_CA_CONF_mskL2CLSZ) >>
  38. L2_CA_CONF_offL2CLSZ);
  39. pr_info("L2:%luKB/%luS/%luW/%luB\n",
  40. l2set * l2way * l2clsz / 1024, l2set, l2way, l2clsz);
  41. tmp = L2C_R_REG(L2CC_PROT_OFF);
  42. tmp &= ~L2CC_PROT_mskMRWEN;
  43. L2C_W_REG(L2CC_PROT_OFF, tmp);
  44. tmp = L2C_R_REG(L2CC_SETUP_OFF);
  45. tmp &= ~L2CC_SETUP_mskPART;
  46. L2C_W_REG(L2CC_SETUP_OFF, tmp);
  47. tmp = L2C_R_REG(L2CC_CTRL_OFF);
  48. tmp |= L2CC_CTRL_mskEN;
  49. L2C_W_REG(L2CC_CTRL_OFF, tmp);
  50. return 0;
  51. }
  52. subsys_initcall(atl2c_of_init);