Received: from mail.onstor.com (66.201.51.107) by exch1.onstor.net
 (10.0.0.225) with Microsoft SMTP Server id 8.1.311.2; Mon, 25 May 2009
 06:04:53 -0700
Received: from psmtp.com ([64.18.0.42]) by mail.onstor.com with Microsoft
 SMTPSVC(6.0.3790.3959);	 Mon, 25 May 2009 06:04:53 -0700
Received: from source ([213.58.128.207]) by exprod5mx196.postini.com
 ([64.18.4.11]) with SMTP;	Mon, 25 May 2009 06:04:52 PDT
Received: from localhost.localdomain ([127.0.0.1]:44488 "EHLO
	ftp.linux-mips.org" rhost-flags-OK-OK-OK-FAIL) by ftp.linux-mips.org	with
 ESMTP id S20022037AbZEYNEd (ORCPT	<rfc822;andy.sharp@onstor.com>); Mon, 25
 May 2009 14:04:33 +0100
Received: with ECARTIS (v1.0.0; list linux-mips); Mon, 25 May 2009 14:04:15
 +0100 (BST)
Received: from mba.ocn.ne.jp ([122.1.235.107]:52260 "HELO smtp.mba.ocn.ne.jp"
	rhost-flags-OK-OK-OK-OK) by ftp.linux-mips.org with SMTP	id S20023596AbZEYNEJ
 (ORCPT <rfc822;linux-mips@linux-mips.org>);	Mon, 25 May 2009 14:04:09 +0100
Received: from localhost.localdomain (p4108-ipad204funabasi.chiba.ocn.ne.jp
 [222.146.91.108])	by smtp.mba.ocn.ne.jp (Postfix) with ESMTP	id 3D441AA89;
 Mon, 25 May 2009 22:04:02 +0900 (JST)
From: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
To: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>
CC: "ralf@linux-mips.org" <ralf@linux-mips.org>
Sender: "linux-mips-bounce@linux-mips.org" <linux-mips-bounce@linux-mips.org>
Date: Mon, 25 May 2009 06:04:02 -0700
Subject: [PATCH] TXx9: Add SRAMC support
Thread-Topic: [PATCH] TXx9: Add SRAMC support
Thread-Index: AcndOWVwg+8FPCpwQO+jsqqPhntHLg==
Message-ID: <1243256642-4880-1-git-send-email-anemo@mba.ocn.ne.jp>
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 0b
X-MS-Exchange-Organization-AuthSource: exch1.onstor.net
X-MS-Has-Attach:
X-Auto-Response-Suppress: All
X-MS-TNEF-Correlator:
x-originalarrivaltime: 25 May 2009 13:04:53.0204 (UTC)
 FILETIME=[64DFE940:01C9DD39]
x-ems-stamp: Hdg3VWG3L5w6RKgspLJ8fw==
x-ems-proccessed: 2K3Xl1OQTInXD6xxuA8z3Q==
errors-to: linux-mips-bounce@linux-mips.org
x-pstn-levels: (S:59.23648/99.90000 CV:99.9000 FC:95.5390 LC:95.5390
 R:95.9108 P:95.9108 M:97.0282 C:98.6951 )
x-list: linux-mips
x-archive-position: 22957
x-ecartis-version: Ecartis v1.0.0
x-original-sender: anemo@mba.ocn.ne.jp
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0

Add a sysdev to access SRAM in TXx9 SoCs via sysfs.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
 arch/mips/include/asm/txx9/generic.h  |    1 +
 arch/mips/include/asm/txx9/tx4938.h   |    1 +
 arch/mips/include/asm/txx9/tx4939.h   |    1 +
 arch/mips/txx9/generic/setup.c        |   84 +++++++++++++++++++++++++++++=
++++
 arch/mips/txx9/generic/setup_tx4938.c |    6 ++
 arch/mips/txx9/generic/setup_tx4939.c |    6 ++
 arch/mips/txx9/rbtx4938/setup.c       |    1 +
 arch/mips/txx9/rbtx4939/setup.c       |    1 +
 8 files changed, 101 insertions(+), 0 deletions(-)

diff --git a/arch/mips/include/asm/txx9/generic.h b/arch/mips/include/asm/t=
xx9/generic.h
index 8169477..827dc22 100644
--- a/arch/mips/include/asm/txx9/generic.h
+++ b/arch/mips/include/asm/txx9/generic.h
@@ -95,5 +95,6 @@ void __init txx9_aclc_init(unsigned long baseaddr, int ir=
q,
 			   unsigned int dmac_id,
 			   unsigned int dma_chan_out,
 			   unsigned int dma_chan_in);
+void __init txx9_sramc_init(struct resource *r);
=20
 #endif /* __ASM_TXX9_GENERIC_H */
diff --git a/arch/mips/include/asm/txx9/tx4938.h b/arch/mips/include/asm/tx=
x9/tx4938.h
index 54e4674..8a178f1 100644
--- a/arch/mips/include/asm/txx9/tx4938.h
+++ b/arch/mips/include/asm/txx9/tx4938.h
@@ -307,5 +307,6 @@ struct tx4938ide_platform_info {
 void tx4938_ata_init(unsigned int irq, unsigned int shift, int tune);
 void tx4938_dmac_init(int memcpy_chan0, int memcpy_chan1);
 void tx4938_aclc_init(void);
+void tx4938_sramc_init(void);
=20
 #endif
diff --git a/arch/mips/include/asm/txx9/tx4939.h b/arch/mips/include/asm/tx=
x9/tx4939.h
index f13b708..050364d 100644
--- a/arch/mips/include/asm/txx9/tx4939.h
+++ b/arch/mips/include/asm/txx9/tx4939.h
@@ -546,5 +546,6 @@ void tx4939_ndfmc_init(unsigned int hold, unsigned int =
spw,
 		       unsigned char ch_mask, unsigned char wide_mask);
 void tx4939_dmac_init(int memcpy_chan0, int memcpy_chan1);
 void tx4939_aclc_init(void);
+void tx4939_sramc_init(void);
=20
 #endif /* __ASM_TXX9_TX4939_H */
diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.=
c
index 7f91012..3b7d77d 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -24,6 +24,7 @@
 #include <linux/serial_core.h>
 #include <linux/mtd/physmap.h>
 #include <linux/leds.h>
+#include <linux/sysdev.h>
 #include <asm/bootinfo.h>
 #include <asm/time.h>
 #include <asm/reboot.h>
@@ -912,3 +913,86 @@ void __init txx9_aclc_init(unsigned long baseaddr, int=
 irq,
 		platform_device_put(pdev);
 #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 =3D bin_attr->private;
+	size_t ramsize =3D bin_attr->size;
+
+	if (pos >=3D ramsize)
+		return 0;
+	if (pos + size > ramsize)
+		size =3D 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 =3D bin_attr->private;
+	size_t ramsize =3D bin_attr->size;
+
+	if (pos >=3D ramsize)
+		return 0;
+	if (pos + size > ramsize)
+		size =3D 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 =3D "txx9_sram";
+		err =3D sysdev_class_register(&txx9_sramc_sysdev_class);
+		if (err) {
+			txx9_sramc_sysdev_class.name =3D NULL;
+			return;
+		}
+	}
+	dev =3D kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return;
+	size =3D resource_size(r);
+	dev->base =3D ioremap(r->start, size);
+	if (!dev->base)
+		goto exit;
+	dev->dev.cls =3D &txx9_sramc_sysdev_class;
+	dev->bindata_attr.attr.name =3D "bindata";
+	dev->bindata_attr.attr.mode =3D S_IRUSR | S_IWUSR;
+	dev->bindata_attr.read =3D txx9_sram_read;
+	dev->bindata_attr.write =3D txx9_sram_write;
+	dev->bindata_attr.size =3D size;
+	dev->bindata_attr.private =3D dev;
+	err =3D sysdev_register(&dev->dev);
+	if (err)
+		goto exit;
+	err =3D 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);
+	}
+}
diff --git a/arch/mips/txx9/generic/setup_tx4938.c b/arch/mips/txx9/generic=
/setup_tx4938.c
index 4dfdb52..eb20801 100644
--- a/arch/mips/txx9/generic/setup_tx4938.c
+++ b/arch/mips/txx9/generic/setup_tx4938.c
@@ -425,6 +425,12 @@ void __init tx4938_aclc_init(void)
 			       1, 0, 1);
 }
=20
+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)
 {
 	__u64 pcfg, rst =3D 0, ckd =3D 0;
diff --git a/arch/mips/txx9/generic/setup_tx4939.c b/arch/mips/txx9/generic=
/setup_tx4939.c
index 7139686..df13a89 100644
--- a/arch/mips/txx9/generic/setup_tx4939.c
+++ b/arch/mips/txx9/generic/setup_tx4939.c
@@ -494,6 +494,12 @@ void __init tx4939_aclc_init(void)
 			       TXX9_IRQ_BASE + TX4939_IR_ACLC, 1, 0, 1);
 }
=20
+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)
 {
 	__u64 pcfg, rst =3D 0, ckd =3D 0;
diff --git a/arch/mips/txx9/rbtx4938/setup.c b/arch/mips/txx9/rbtx4938/setu=
p.c
index 8da66e9..d66509b 100644
--- a/arch/mips/txx9/rbtx4938/setup.c
+++ b/arch/mips/txx9/rbtx4938/setup.c
@@ -358,6 +358,7 @@ static void __init rbtx4938_device_init(void)
 	tx4938_dmac_init(0, 2);
 	tx4938_aclc_init();
 	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);
 }
=20
diff --git a/arch/mips/txx9/rbtx4939/setup.c b/arch/mips/txx9/rbtx4939/setu=
p.c
index d5ad5ab..b919696 100644
--- a/arch/mips/txx9/rbtx4939/setup.c
+++ b/arch/mips/txx9/rbtx4939/setup.c
@@ -501,6 +501,7 @@ static void __init rbtx4939_device_init(void)
 	tx4939_dmac_init(0, 2);
 	tx4939_aclc_init();
 	platform_device_register_simple("txx9aclc-generic", -1, NULL, 0);
+	tx4939_sramc_init();
 }
=20
 static void __init rbtx4939_setup(void)
--=20
1.5.6.5


