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