Path: blob/master/arch/powerpc/sysdev/fsl_85xx_l2ctlr.c
10817 views
/*1* Copyright 2009-2010 Freescale Semiconductor, Inc.2*3* QorIQ (P1/P2) L2 controller init for Cache-SRAM instantiation4*5* Author: Vivek Mahajan <[email protected]>6*7* This program is free software; you can redistribute it and/or modify it8* under the terms of the GNU General Public License as published by the9* Free Software Foundation; either version 2 of the License, or (at your10* option) any later version.11*12* This program is distributed in the hope that it will be useful,13* but WITHOUT ANY WARRANTY; without even the implied warranty of14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15* GNU General Public License for more details.16*17* You should have received a copy of the GNU General Public License18* along with this program; if not, write to the Free Software19* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.20*/2122#include <linux/kernel.h>23#include <linux/of_platform.h>24#include <asm/io.h>2526#include "fsl_85xx_cache_ctlr.h"2728static char *sram_size;29static char *sram_offset;30struct mpc85xx_l2ctlr __iomem *l2ctlr;3132static long get_cache_sram_size(void)33{34unsigned long val;3536if (!sram_size || (strict_strtoul(sram_size, 0, &val) < 0))37return -EINVAL;3839return val;40}4142static long get_cache_sram_offset(void)43{44unsigned long val;4546if (!sram_offset || (strict_strtoul(sram_offset, 0, &val) < 0))47return -EINVAL;4849return val;50}5152static int __init get_size_from_cmdline(char *str)53{54if (!str)55return 0;5657sram_size = str;58return 1;59}6061static int __init get_offset_from_cmdline(char *str)62{63if (!str)64return 0;6566sram_offset = str;67return 1;68}6970__setup("cache-sram-size=", get_size_from_cmdline);71__setup("cache-sram-offset=", get_offset_from_cmdline);7273static int __devinit mpc85xx_l2ctlr_of_probe(struct platform_device *dev)74{75long rval;76unsigned int rem;77unsigned char ways;78const unsigned int *prop;79unsigned int l2cache_size;80struct sram_parameters sram_params;8182if (!dev->dev.of_node) {83dev_err(&dev->dev, "Device's OF-node is NULL\n");84return -EINVAL;85}8687prop = of_get_property(dev->dev.of_node, "cache-size", NULL);88if (!prop) {89dev_err(&dev->dev, "Missing L2 cache-size\n");90return -EINVAL;91}92l2cache_size = *prop;9394sram_params.sram_size = get_cache_sram_size();95if ((int)sram_params.sram_size <= 0) {96dev_err(&dev->dev,97"Entire L2 as cache, Aborting Cache-SRAM stuff\n");98return -EINVAL;99}100101sram_params.sram_offset = get_cache_sram_offset();102if ((int64_t)sram_params.sram_offset <= 0) {103dev_err(&dev->dev,104"Entire L2 as cache, provide a valid sram offset\n");105return -EINVAL;106}107108109rem = l2cache_size % sram_params.sram_size;110ways = LOCK_WAYS_FULL * sram_params.sram_size / l2cache_size;111if (rem || (ways & (ways - 1))) {112dev_err(&dev->dev, "Illegal cache-sram-size in command line\n");113return -EINVAL;114}115116l2ctlr = of_iomap(dev->dev.of_node, 0);117if (!l2ctlr) {118dev_err(&dev->dev, "Can't map L2 controller\n");119return -EINVAL;120}121122/*123* Write bits[0-17] to srbar0124*/125out_be32(&l2ctlr->srbar0,126sram_params.sram_offset & L2SRAM_BAR_MSK_LO18);127128/*129* Write bits[18-21] to srbare0130*/131#ifdef CONFIG_PHYS_64BIT132out_be32(&l2ctlr->srbarea0,133(sram_params.sram_offset >> 32) & L2SRAM_BARE_MSK_HI4);134#endif135136clrsetbits_be32(&l2ctlr->ctl, L2CR_L2E, L2CR_L2FI);137138switch (ways) {139case LOCK_WAYS_EIGHTH:140setbits32(&l2ctlr->ctl,141L2CR_L2E | L2CR_L2FI | L2CR_SRAM_EIGHTH);142break;143144case LOCK_WAYS_TWO_EIGHTH:145setbits32(&l2ctlr->ctl,146L2CR_L2E | L2CR_L2FI | L2CR_SRAM_QUART);147break;148149case LOCK_WAYS_HALF:150setbits32(&l2ctlr->ctl,151L2CR_L2E | L2CR_L2FI | L2CR_SRAM_HALF);152break;153154case LOCK_WAYS_FULL:155default:156setbits32(&l2ctlr->ctl,157L2CR_L2E | L2CR_L2FI | L2CR_SRAM_FULL);158break;159}160eieio();161162rval = instantiate_cache_sram(dev, sram_params);163if (rval < 0) {164dev_err(&dev->dev, "Can't instantiate Cache-SRAM\n");165iounmap(l2ctlr);166return -EINVAL;167}168169return 0;170}171172static int __devexit mpc85xx_l2ctlr_of_remove(struct platform_device *dev)173{174BUG_ON(!l2ctlr);175176iounmap(l2ctlr);177remove_cache_sram(dev);178dev_info(&dev->dev, "MPC85xx L2 controller unloaded\n");179180return 0;181}182183static struct of_device_id mpc85xx_l2ctlr_of_match[] = {184{185.compatible = "fsl,p2020-l2-cache-controller",186},187{188.compatible = "fsl,p2010-l2-cache-controller",189},190{191.compatible = "fsl,p1020-l2-cache-controller",192},193{194.compatible = "fsl,p1011-l2-cache-controller",195},196{197.compatible = "fsl,p1013-l2-cache-controller",198},199{200.compatible = "fsl,p1022-l2-cache-controller",201},202{},203};204205static struct platform_driver mpc85xx_l2ctlr_of_platform_driver = {206.driver = {207.name = "fsl-l2ctlr",208.owner = THIS_MODULE,209.of_match_table = mpc85xx_l2ctlr_of_match,210},211.probe = mpc85xx_l2ctlr_of_probe,212.remove = __devexit_p(mpc85xx_l2ctlr_of_remove),213};214215static __init int mpc85xx_l2ctlr_of_init(void)216{217return platform_driver_register(&mpc85xx_l2ctlr_of_platform_driver);218}219220static void __exit mpc85xx_l2ctlr_of_exit(void)221{222platform_driver_unregister(&mpc85xx_l2ctlr_of_platform_driver);223}224225subsys_initcall(mpc85xx_l2ctlr_of_init);226module_exit(mpc85xx_l2ctlr_of_exit);227228MODULE_DESCRIPTION("Freescale MPC85xx L2 controller init");229MODULE_LICENSE("GPL v2");230231232