misc: Add devicetree SRAM driver
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
27da1665d3
commit
ae39ba29c6
|
@ -9,4 +9,10 @@ config JTAG
|
|||
depends on GENERIC_GPIO
|
||||
help
|
||||
Controls JTAG chains connected to I/O pins
|
||||
|
||||
config SRAM
|
||||
bool "Generic SRAM driver"
|
||||
help
|
||||
This driver adds support for memory mapped SRAM.
|
||||
|
||||
endmenu
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
#
|
||||
|
||||
obj-$(CONFIG_JTAG) += jtag.o
|
||||
obj-$(CONFIG_SRAM) += sram.o
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* drivers/misc/sram.c - generic memory mapped SRAM driver
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <common.h>
|
||||
#include <errno.h>
|
||||
#include <driver.h>
|
||||
#include <malloc.h>
|
||||
#include <init.h>
|
||||
|
||||
struct sram {
|
||||
struct resource *res;
|
||||
char *name;
|
||||
struct cdev cdev;
|
||||
};
|
||||
|
||||
static struct file_operations memops = {
|
||||
.read = mem_read,
|
||||
.write = mem_write,
|
||||
.memmap = generic_memmap_rw,
|
||||
.lseek = dev_lseek_default,
|
||||
};
|
||||
|
||||
static int sram_probe(struct device_d *dev)
|
||||
{
|
||||
struct sram *sram;
|
||||
struct resource *res;
|
||||
void __iomem *base;
|
||||
int ret;
|
||||
|
||||
base = dev_request_mem_region(dev, 0);
|
||||
if (!base)
|
||||
return -EBUSY;
|
||||
|
||||
sram = xzalloc(sizeof(*sram));
|
||||
|
||||
sram->cdev.name = asprintf("sram%d",
|
||||
cdev_find_free_index("sram"));
|
||||
|
||||
res = dev_get_resource(dev, 0);
|
||||
|
||||
sram->cdev.size = (unsigned long)resource_size(res);
|
||||
sram->cdev.ops = &memops;
|
||||
sram->cdev.dev = dev;
|
||||
|
||||
ret = devfs_create(&sram->cdev);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __maybe_unused struct of_device_id sram_dt_ids[] = {
|
||||
{
|
||||
.compatible = "mmio-sram",
|
||||
}, {
|
||||
},
|
||||
};
|
||||
|
||||
static struct driver_d sram_driver = {
|
||||
.name = "mmio-sram",
|
||||
.probe = sram_probe,
|
||||
.of_compatible = sram_dt_ids,
|
||||
};
|
||||
device_platform_driver(sram_driver);
|
Loading…
Reference in New Issue