2 * linux/arch/arm/mach-mmp/sram.c
4 * based on mach-davinci/sram.c - DaVinci simple SRAM allocator
6 * Copyright (c) 2011 Marvell Semiconductors Inc.
9 * Add for mmp sram support - Leo Yan <leoy@marvell.com>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
17 #include <linux/module.h>
18 #include <linux/mod_devicetable.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
22 #include <linux/err.h>
23 #include <linux/slab.h>
24 #include <linux/genalloc.h>
26 #include <linux/platform_data/dma-mmp_tdma.h>
28 struct sram_bank_info {
30 struct gen_pool *gpool;
33 phys_addr_t sram_phys;
34 void __iomem *sram_virt;
37 struct list_head node;
40 static DEFINE_MUTEX(sram_lock);
41 static LIST_HEAD(sram_bank_list);
43 struct gen_pool *sram_get_gpool(char *pool_name)
45 struct sram_bank_info *info = NULL;
50 mutex_lock(&sram_lock);
52 list_for_each_entry(info, &sram_bank_list, node)
53 if (!strcmp(pool_name, info->pool_name))
56 mutex_unlock(&sram_lock);
58 if (&info->node == &sram_bank_list)
63 EXPORT_SYMBOL(sram_get_gpool);
65 static int sram_probe(struct platform_device *pdev)
67 struct sram_platdata *pdata = pdev->dev.platform_data;
68 struct sram_bank_info *info;
72 if (!pdata || !pdata->pool_name)
75 info = kzalloc(sizeof(*info), GFP_KERNEL);
79 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
81 dev_err(&pdev->dev, "no memory resource defined\n");
86 if (!resource_size(res))
89 info->sram_phys = (phys_addr_t)res->start;
90 info->sram_size = resource_size(res);
91 info->sram_virt = ioremap(info->sram_phys, info->sram_size);
92 info->pool_name = kstrdup(pdata->pool_name, GFP_KERNEL);
93 info->granularity = pdata->granularity;
95 info->gpool = gen_pool_create(ilog2(info->granularity), -1);
97 dev_err(&pdev->dev, "create pool failed\n");
102 ret = gen_pool_add_virt(info->gpool, (unsigned long)info->sram_virt,
103 info->sram_phys, info->sram_size, -1);
105 dev_err(&pdev->dev, "add new chunk failed\n");
110 mutex_lock(&sram_lock);
111 list_add(&info->node, &sram_bank_list);
112 mutex_unlock(&sram_lock);
114 platform_set_drvdata(pdev, info);
116 dev_info(&pdev->dev, "initialized\n");
120 gen_pool_destroy(info->gpool);
122 iounmap(info->sram_virt);
123 kfree(info->pool_name);
129 static int sram_remove(struct platform_device *pdev)
131 struct sram_bank_info *info;
133 info = platform_get_drvdata(pdev);
137 mutex_lock(&sram_lock);
138 list_del(&info->node);
139 mutex_unlock(&sram_lock);
141 gen_pool_destroy(info->gpool);
142 iounmap(info->sram_virt);
143 kfree(info->pool_name);
148 static const struct platform_device_id sram_id_table[] = {
149 { "asram", MMP_ASRAM },
150 { "isram", MMP_ISRAM },
154 static struct platform_driver sram_driver = {
156 .remove = sram_remove,
160 .id_table = sram_id_table,
163 static int __init sram_init(void)
165 return platform_driver_register(&sram_driver);
167 core_initcall(sram_init);
169 MODULE_LICENSE("GPL");