Commit c3b28ae2 authored by Atsushi Nemoto's avatar Atsushi Nemoto Committed by Ralf Baechle

MIPS: TXx9: Add SRAMC support

Add a sysdev to access SRAM in TXx9 SoCs via sysfs.
Signed-off-by: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: default avatarRalf Baechle <ralf@linux-mips.org>
parent 05f94eeb
...@@ -95,5 +95,6 @@ void __init txx9_aclc_init(unsigned long baseaddr, int irq, ...@@ -95,5 +95,6 @@ void __init txx9_aclc_init(unsigned long baseaddr, int irq,
unsigned int dmac_id, unsigned int dmac_id,
unsigned int dma_chan_out, unsigned int dma_chan_out,
unsigned int dma_chan_in); unsigned int dma_chan_in);
void __init txx9_sramc_init(struct resource *r);
#endif /* __ASM_TXX9_GENERIC_H */ #endif /* __ASM_TXX9_GENERIC_H */
...@@ -307,5 +307,6 @@ struct tx4938ide_platform_info { ...@@ -307,5 +307,6 @@ struct tx4938ide_platform_info {
void tx4938_ata_init(unsigned int irq, unsigned int shift, int tune); void tx4938_ata_init(unsigned int irq, unsigned int shift, int tune);
void tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1); void tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1);
void tx4938_aclc_init(void); void tx4938_aclc_init(void);
void tx4938_sramc_init(void);
#endif #endif
...@@ -546,5 +546,6 @@ void tx4939_ndfmc_init(unsigned int hold, unsigned int spw, ...@@ -546,5 +546,6 @@ void tx4939_ndfmc_init(unsigned int hold, unsigned int spw,
unsigned char ch_mask, unsigned char wide_mask); unsigned char ch_mask, unsigned char wide_mask);
void tx4939_dmac_init(int memcpy_chan0, int memcpy_chan1); void tx4939_dmac_init(int memcpy_chan0, int memcpy_chan1);
void tx4939_aclc_init(void); void tx4939_aclc_init(void);
void tx4939_sramc_init(void);
#endif /* __ASM_TXX9_TX4939_H */ #endif /* __ASM_TXX9_TX4939_H */
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include <linux/serial_core.h> #include <linux/serial_core.h>
#include <linux/mtd/physmap.h> #include <linux/mtd/physmap.h>
#include <linux/leds.h> #include <linux/leds.h>
#include <linux/sysdev.h>
#include <asm/bootinfo.h> #include <asm/bootinfo.h>
#include <asm/time.h> #include <asm/time.h>
#include <asm/reboot.h> #include <asm/reboot.h>
...@@ -912,3 +913,86 @@ void __init txx9_aclc_init(unsigned long baseaddr, int irq, ...@@ -912,3 +913,86 @@ void __init txx9_aclc_init(unsigned long baseaddr, int irq,
platform_device_put(pdev); platform_device_put(pdev);
#endif #endif
} }
static struct sysdev_class txx9_sramc_sysdev_class;
struct txx9_sramc_sysdev {
struct sys_device dev;
struct bin_attribute bindata_attr;
void __iomem *base;
};
static ssize_t txx9_sram_read(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct txx9_sramc_sysdev *dev = bin_attr->private;
size_t ramsize = bin_attr->size;
if (pos >= ramsize)
return 0;
if (pos + size > ramsize)
size = ramsize - pos;
memcpy_fromio(buf, dev->base + pos, size);
return size;
}
static ssize_t txx9_sram_write(struct kobject *kobj,
struct bin_attribute *bin_attr,
char *buf, loff_t pos, size_t size)
{
struct txx9_sramc_sysdev *dev = bin_attr->private;
size_t ramsize = bin_attr->size;
if (pos >= ramsize)
return 0;
if (pos + size > ramsize)
size = ramsize - pos;
memcpy_toio(dev->base + pos, buf, size);
return size;
}
void __init txx9_sramc_init(struct resource *r)
{
struct txx9_sramc_sysdev *dev;
size_t size;
int err;
if (!txx9_sramc_sysdev_class.name) {
txx9_sramc_sysdev_class.name = "txx9_sram";
err = sysdev_class_register(&txx9_sramc_sysdev_class);
if (err) {
txx9_sramc_sysdev_class.name = NULL;
return;
}
}
dev = kzalloc(sizeof(*dev), GFP_KERNEL);
if (!dev)
return;
size = resource_size(r);
dev->base = ioremap(r->start, size);
if (!dev->base)
goto exit;
dev->dev.cls = &txx9_sramc_sysdev_class;
dev->bindata_attr.attr.name = "bindata";
dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
dev->bindata_attr.read = txx9_sram_read;
dev->bindata_attr.write = txx9_sram_write;
dev->bindata_attr.size = size;
dev->bindata_attr.private = dev;
err = sysdev_register(&dev->dev);
if (err)
goto exit;
err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
if (err) {
sysdev_unregister(&dev->dev);
goto exit;
}
return;
exit:
if (dev) {
if (dev->base)
iounmap(dev->base);
kfree(dev);
}
}
...@@ -425,6 +425,12 @@ void __init tx4938_aclc_init(void) ...@@ -425,6 +425,12 @@ void __init tx4938_aclc_init(void)
1, 0, 1); 1, 0, 1);
} }
void __init tx4938_sramc_init(void)
{
if (tx4938_sram_resource.start)
txx9_sramc_init(&tx4938_sram_resource);
}
static void __init tx4938_stop_unused_modules(void) static void __init tx4938_stop_unused_modules(void)
{ {
__u64 pcfg, rst = 0, ckd = 0; __u64 pcfg, rst = 0, ckd = 0;
......
...@@ -494,6 +494,12 @@ void __init tx4939_aclc_init(void) ...@@ -494,6 +494,12 @@ void __init tx4939_aclc_init(void)
TXX9_IRQ_BASE + TX4939_IR_ACLC, 1, 0, 1); TXX9_IRQ_BASE + TX4939_IR_ACLC, 1, 0, 1);
} }
void __init tx4939_sramc_init(void)
{
if (tx4939_sram_resource.start)
txx9_sramc_init(&tx4939_sram_resource);
}
static void __init tx4939_stop_unused_modules(void) static void __init tx4939_stop_unused_modules(void)
{ {
__u64 pcfg, rst = 0, ckd = 0; __u64 pcfg, rst = 0, ckd = 0;
......
...@@ -358,6 +358,7 @@ static void __init rbtx4938_device_init(void) ...@@ -358,6 +358,7 @@ static void __init rbtx4938_device_init(void)
tx4938_dmac_init(0, 2); tx4938_dmac_init(0, 2);
tx4938_aclc_init(); tx4938_aclc_init();
platform_device_register_simple("txx9aclc-generic", -1, NULL, 0); platform_device_register_simple("txx9aclc-generic", -1, NULL, 0);
tx4938_sramc_init();
txx9_iocled_init(RBTX4938_LED_ADDR - IO_BASE, -1, 8, 1, "green", NULL); txx9_iocled_init(RBTX4938_LED_ADDR - IO_BASE, -1, 8, 1, "green", NULL);
} }
......
...@@ -501,6 +501,7 @@ static void __init rbtx4939_device_init(void) ...@@ -501,6 +501,7 @@ static void __init rbtx4939_device_init(void)
tx4939_dmac_init(0, 2); tx4939_dmac_init(0, 2);
tx4939_aclc_init(); tx4939_aclc_init();
platform_device_register_simple("txx9aclc-generic", -1, NULL, 0); platform_device_register_simple("txx9aclc-generic", -1, NULL, 0);
tx4939_sramc_init();
} }
static void __init rbtx4939_setup(void) static void __init rbtx4939_setup(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment