1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2009-2010, 2012 Freescale Semiconductor, Inc.
5 * QorIQ (P1/P2) L2 controller init for Cache-SRAM instantiation
7 * Author: Vivek Mahajan <vivek.mahajan@freescale.com>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/of_platform.h>
15 #include "fsl_85xx_cache_ctlr.h"
17 static char *sram_size
;
18 static char *sram_offset
;
19 struct mpc85xx_l2ctlr __iomem
*l2ctlr
;
21 static int get_cache_sram_params(struct sram_parameters
*sram_params
)
23 unsigned long long addr
;
26 if (!sram_size
|| (kstrtouint(sram_size
, 0, &size
) < 0))
29 if (!sram_offset
|| (kstrtoull(sram_offset
, 0, &addr
) < 0))
32 sram_params
->sram_offset
= addr
;
33 sram_params
->sram_size
= size
;
38 static int __init
get_size_from_cmdline(char *str
)
47 static int __init
get_offset_from_cmdline(char *str
)
56 __setup("cache-sram-size=", get_size_from_cmdline
);
57 __setup("cache-sram-offset=", get_offset_from_cmdline
);
59 static int mpc85xx_l2ctlr_of_probe(struct platform_device
*dev
)
64 const unsigned int *prop
;
65 unsigned int l2cache_size
;
66 struct sram_parameters sram_params
;
68 if (!dev
->dev
.of_node
) {
69 dev_err(&dev
->dev
, "Device's OF-node is NULL\n");
73 prop
= of_get_property(dev
->dev
.of_node
, "cache-size", NULL
);
75 dev_err(&dev
->dev
, "Missing L2 cache-size\n");
80 if (get_cache_sram_params(&sram_params
))
81 return 0; /* fall back to L2 cache only */
83 rem
= l2cache_size
% sram_params
.sram_size
;
84 ways
= LOCK_WAYS_FULL
* sram_params
.sram_size
/ l2cache_size
;
85 if (rem
|| (ways
& (ways
- 1))) {
86 dev_err(&dev
->dev
, "Illegal cache-sram-size in command line\n");
90 l2ctlr
= of_iomap(dev
->dev
.of_node
, 0);
92 dev_err(&dev
->dev
, "Can't map L2 controller\n");
97 * Write bits[0-17] to srbar0
99 out_be32(&l2ctlr
->srbar0
,
100 lower_32_bits(sram_params
.sram_offset
) & L2SRAM_BAR_MSK_LO18
);
103 * Write bits[18-21] to srbare0
105 #ifdef CONFIG_PHYS_64BIT
106 out_be32(&l2ctlr
->srbarea0
,
107 upper_32_bits(sram_params
.sram_offset
) & L2SRAM_BARE_MSK_HI4
);
110 clrsetbits_be32(&l2ctlr
->ctl
, L2CR_L2E
, L2CR_L2FI
);
113 case LOCK_WAYS_EIGHTH
:
114 setbits32(&l2ctlr
->ctl
,
115 L2CR_L2E
| L2CR_L2FI
| L2CR_SRAM_EIGHTH
);
118 case LOCK_WAYS_TWO_EIGHTH
:
119 setbits32(&l2ctlr
->ctl
,
120 L2CR_L2E
| L2CR_L2FI
| L2CR_SRAM_QUART
);
124 setbits32(&l2ctlr
->ctl
,
125 L2CR_L2E
| L2CR_L2FI
| L2CR_SRAM_HALF
);
130 setbits32(&l2ctlr
->ctl
,
131 L2CR_L2E
| L2CR_L2FI
| L2CR_SRAM_FULL
);
136 rval
= instantiate_cache_sram(dev
, sram_params
);
138 dev_err(&dev
->dev
, "Can't instantiate Cache-SRAM\n");
146 static int mpc85xx_l2ctlr_of_remove(struct platform_device
*dev
)
151 remove_cache_sram(dev
);
152 dev_info(&dev
->dev
, "MPC85xx L2 controller unloaded\n");
157 static const struct of_device_id mpc85xx_l2ctlr_of_match
[] = {
159 .compatible
= "fsl,p2020-l2-cache-controller",
162 .compatible
= "fsl,p2010-l2-cache-controller",
165 .compatible
= "fsl,p1020-l2-cache-controller",
168 .compatible
= "fsl,p1011-l2-cache-controller",
171 .compatible
= "fsl,p1013-l2-cache-controller",
174 .compatible
= "fsl,p1022-l2-cache-controller",
177 .compatible
= "fsl,mpc8548-l2-cache-controller",
179 { .compatible
= "fsl,mpc8544-l2-cache-controller",},
180 { .compatible
= "fsl,mpc8572-l2-cache-controller",},
181 { .compatible
= "fsl,mpc8536-l2-cache-controller",},
182 { .compatible
= "fsl,p1021-l2-cache-controller",},
183 { .compatible
= "fsl,p1012-l2-cache-controller",},
184 { .compatible
= "fsl,p1025-l2-cache-controller",},
185 { .compatible
= "fsl,p1016-l2-cache-controller",},
186 { .compatible
= "fsl,p1024-l2-cache-controller",},
187 { .compatible
= "fsl,p1015-l2-cache-controller",},
188 { .compatible
= "fsl,p1010-l2-cache-controller",},
189 { .compatible
= "fsl,bsc9131-l2-cache-controller",},
193 static struct platform_driver mpc85xx_l2ctlr_of_platform_driver
= {
195 .name
= "fsl-l2ctlr",
196 .of_match_table
= mpc85xx_l2ctlr_of_match
,
198 .probe
= mpc85xx_l2ctlr_of_probe
,
199 .remove
= mpc85xx_l2ctlr_of_remove
,
202 static __init
int mpc85xx_l2ctlr_of_init(void)
204 return platform_driver_register(&mpc85xx_l2ctlr_of_platform_driver
);
207 static void __exit
mpc85xx_l2ctlr_of_exit(void)
209 platform_driver_unregister(&mpc85xx_l2ctlr_of_platform_driver
);
212 subsys_initcall(mpc85xx_l2ctlr_of_init
);
213 module_exit(mpc85xx_l2ctlr_of_exit
);
215 MODULE_DESCRIPTION("Freescale MPC85xx L2 controller init");
216 MODULE_LICENSE("GPL v2");