staging:iio:Documentation gyro -> anglvel updates in attribute names
[zen-stable.git] / arch / powerpc / sysdev / fsl_85xx_l2ctlr.c
blob5f88797dce73cecc191312a81b27b7f97b67043e
1 /*
2 * Copyright 2009-2010 Freescale Semiconductor, Inc.
4 * QorIQ (P1/P2) L2 controller init for Cache-SRAM instantiation
6 * Author: Vivek Mahajan <vivek.mahajan@freescale.com>
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.
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.
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.
23 #include <linux/kernel.h>
24 #include <linux/of_platform.h>
25 #include <asm/io.h>
27 #include "fsl_85xx_cache_ctlr.h"
29 static char *sram_size;
30 static char *sram_offset;
31 struct mpc85xx_l2ctlr __iomem *l2ctlr;
33 static long get_cache_sram_size(void)
35 unsigned long val;
37 if (!sram_size || (strict_strtoul(sram_size, 0, &val) < 0))
38 return -EINVAL;
40 return val;
43 static long get_cache_sram_offset(void)
45 unsigned long val;
47 if (!sram_offset || (strict_strtoul(sram_offset, 0, &val) < 0))
48 return -EINVAL;
50 return val;
53 static int __init get_size_from_cmdline(char *str)
55 if (!str)
56 return 0;
58 sram_size = str;
59 return 1;
62 static int __init get_offset_from_cmdline(char *str)
64 if (!str)
65 return 0;
67 sram_offset = str;
68 return 1;
71 __setup("cache-sram-size=", get_size_from_cmdline);
72 __setup("cache-sram-offset=", get_offset_from_cmdline);
74 static int __devinit mpc85xx_l2ctlr_of_probe(struct platform_device *dev)
76 long rval;
77 unsigned int rem;
78 unsigned char ways;
79 const unsigned int *prop;
80 unsigned int l2cache_size;
81 struct sram_parameters sram_params;
83 if (!dev->dev.of_node) {
84 dev_err(&dev->dev, "Device's OF-node is NULL\n");
85 return -EINVAL;
88 prop = of_get_property(dev->dev.of_node, "cache-size", NULL);
89 if (!prop) {
90 dev_err(&dev->dev, "Missing L2 cache-size\n");
91 return -EINVAL;
93 l2cache_size = *prop;
95 sram_params.sram_size = get_cache_sram_size();
96 if ((int)sram_params.sram_size <= 0) {
97 dev_err(&dev->dev,
98 "Entire L2 as cache, Aborting Cache-SRAM stuff\n");
99 return -EINVAL;
102 sram_params.sram_offset = get_cache_sram_offset();
103 if ((int64_t)sram_params.sram_offset <= 0) {
104 dev_err(&dev->dev,
105 "Entire L2 as cache, provide a valid sram offset\n");
106 return -EINVAL;
110 rem = l2cache_size % sram_params.sram_size;
111 ways = LOCK_WAYS_FULL * sram_params.sram_size / l2cache_size;
112 if (rem || (ways & (ways - 1))) {
113 dev_err(&dev->dev, "Illegal cache-sram-size in command line\n");
114 return -EINVAL;
117 l2ctlr = of_iomap(dev->dev.of_node, 0);
118 if (!l2ctlr) {
119 dev_err(&dev->dev, "Can't map L2 controller\n");
120 return -EINVAL;
124 * Write bits[0-17] to srbar0
126 out_be32(&l2ctlr->srbar0,
127 sram_params.sram_offset & L2SRAM_BAR_MSK_LO18);
130 * Write bits[18-21] to srbare0
132 #ifdef CONFIG_PHYS_64BIT
133 out_be32(&l2ctlr->srbarea0,
134 (sram_params.sram_offset >> 32) & L2SRAM_BARE_MSK_HI4);
135 #endif
137 clrsetbits_be32(&l2ctlr->ctl, L2CR_L2E, L2CR_L2FI);
139 switch (ways) {
140 case LOCK_WAYS_EIGHTH:
141 setbits32(&l2ctlr->ctl,
142 L2CR_L2E | L2CR_L2FI | L2CR_SRAM_EIGHTH);
143 break;
145 case LOCK_WAYS_TWO_EIGHTH:
146 setbits32(&l2ctlr->ctl,
147 L2CR_L2E | L2CR_L2FI | L2CR_SRAM_QUART);
148 break;
150 case LOCK_WAYS_HALF:
151 setbits32(&l2ctlr->ctl,
152 L2CR_L2E | L2CR_L2FI | L2CR_SRAM_HALF);
153 break;
155 case LOCK_WAYS_FULL:
156 default:
157 setbits32(&l2ctlr->ctl,
158 L2CR_L2E | L2CR_L2FI | L2CR_SRAM_FULL);
159 break;
161 eieio();
163 rval = instantiate_cache_sram(dev, sram_params);
164 if (rval < 0) {
165 dev_err(&dev->dev, "Can't instantiate Cache-SRAM\n");
166 iounmap(l2ctlr);
167 return -EINVAL;
170 return 0;
173 static int __devexit mpc85xx_l2ctlr_of_remove(struct platform_device *dev)
175 BUG_ON(!l2ctlr);
177 iounmap(l2ctlr);
178 remove_cache_sram(dev);
179 dev_info(&dev->dev, "MPC85xx L2 controller unloaded\n");
181 return 0;
184 static struct of_device_id mpc85xx_l2ctlr_of_match[] = {
186 .compatible = "fsl,p2020-l2-cache-controller",
189 .compatible = "fsl,p2010-l2-cache-controller",
192 .compatible = "fsl,p1020-l2-cache-controller",
195 .compatible = "fsl,p1011-l2-cache-controller",
198 .compatible = "fsl,p1013-l2-cache-controller",
201 .compatible = "fsl,p1022-l2-cache-controller",
206 static struct platform_driver mpc85xx_l2ctlr_of_platform_driver = {
207 .driver = {
208 .name = "fsl-l2ctlr",
209 .owner = THIS_MODULE,
210 .of_match_table = mpc85xx_l2ctlr_of_match,
212 .probe = mpc85xx_l2ctlr_of_probe,
213 .remove = __devexit_p(mpc85xx_l2ctlr_of_remove),
216 static __init int mpc85xx_l2ctlr_of_init(void)
218 return platform_driver_register(&mpc85xx_l2ctlr_of_platform_driver);
221 static void __exit mpc85xx_l2ctlr_of_exit(void)
223 platform_driver_unregister(&mpc85xx_l2ctlr_of_platform_driver);
226 subsys_initcall(mpc85xx_l2ctlr_of_init);
227 module_exit(mpc85xx_l2ctlr_of_exit);
229 MODULE_DESCRIPTION("Freescale MPC85xx L2 controller init");
230 MODULE_LICENSE("GPL v2");