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/init.h>
19 #include <linux/platform_device.h>
21 #include <linux/err.h>
22 #include <linux/slab.h>
23 #include <linux/genalloc.h>
25 #include <mach/sram.h>
27 struct sram_bank_info
{
29 struct gen_pool
*gpool
;
32 phys_addr_t sram_phys
;
33 void __iomem
*sram_virt
;
36 struct list_head node
;
39 static DEFINE_MUTEX(sram_lock
);
40 static LIST_HEAD(sram_bank_list
);
42 struct gen_pool
*sram_get_gpool(char *pool_name
)
44 struct sram_bank_info
*info
= NULL
;
49 mutex_lock(&sram_lock
);
51 list_for_each_entry(info
, &sram_bank_list
, node
)
52 if (!strcmp(pool_name
, info
->pool_name
))
55 mutex_unlock(&sram_lock
);
57 if (&info
->node
== &sram_bank_list
)
62 EXPORT_SYMBOL(sram_get_gpool
);
64 static int __devinit
sram_probe(struct platform_device
*pdev
)
66 struct sram_platdata
*pdata
= pdev
->dev
.platform_data
;
67 struct sram_bank_info
*info
;
71 if (!pdata
&& !pdata
->pool_name
)
74 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
78 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
80 dev_err(&pdev
->dev
, "no memory resource defined\n");
85 if (!resource_size(res
))
88 info
->sram_phys
= (phys_addr_t
)res
->start
;
89 info
->sram_size
= resource_size(res
);
90 info
->sram_virt
= ioremap(info
->sram_phys
, info
->sram_size
);
91 info
->pool_name
= kstrdup(pdata
->pool_name
, GFP_KERNEL
);
92 info
->granularity
= pdata
->granularity
;
94 info
->gpool
= gen_pool_create(ilog2(info
->granularity
), -1);
96 dev_err(&pdev
->dev
, "create pool failed\n");
101 ret
= gen_pool_add_virt(info
->gpool
, (unsigned long)info
->sram_virt
,
102 info
->sram_phys
, info
->sram_size
, -1);
104 dev_err(&pdev
->dev
, "add new chunk failed\n");
109 mutex_lock(&sram_lock
);
110 list_add(&info
->node
, &sram_bank_list
);
111 mutex_unlock(&sram_lock
);
113 platform_set_drvdata(pdev
, info
);
115 dev_info(&pdev
->dev
, "initialized\n");
119 gen_pool_destroy(info
->gpool
);
121 iounmap(info
->sram_virt
);
122 kfree(info
->pool_name
);
128 static int __devexit
sram_remove(struct platform_device
*pdev
)
130 struct sram_bank_info
*info
;
132 info
= platform_get_drvdata(pdev
);
136 mutex_lock(&sram_lock
);
137 list_del(&info
->node
);
138 mutex_unlock(&sram_lock
);
140 gen_pool_destroy(info
->gpool
);
141 iounmap(info
->sram_virt
);
142 kfree(info
->pool_name
);
147 static const struct platform_device_id sram_id_table
[] = {
148 { "asram", MMP_ASRAM
},
149 { "isram", MMP_ISRAM
},
153 static struct platform_driver sram_driver
= {
155 .remove
= sram_remove
,
159 .id_table
= sram_id_table
,
162 static int __init
sram_init(void)
164 return platform_driver_register(&sram_driver
);
166 core_initcall(sram_init
);
168 MODULE_LICENSE("GPL");