mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] misc Kconfig: always ask for misc devices
@ 2014-01-29  9:29 Sascha Hauer
  2014-01-29  9:30 ` [PATCH 2/2] misc: Add devicetree SRAM driver Sascha Hauer
  0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2014-01-29  9:29 UTC (permalink / raw)
  To: barebox

The "Misc devices" menu does not enable anything by itself, so make it a
regular menu rather than a menuconfig.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/misc/Kconfig | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 606490b..e59c4f1 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -2,17 +2,11 @@
 # Misc strange devices
 #
 
-menuconfig MISC_DEVICES
-	bool "Misc devices"
-	help
-	  Add support for misc strange devices
-
-if MISC_DEVICES
+menu "Misc devices"
 
 config JTAG
 	tristate "JTAG Bitbang driver"
 	depends on GENERIC_GPIO
 	help
 	  Controls JTAG chains connected to I/O pins
-
-endif # MISC_DEVICES
+endmenu
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-29  9:29 [PATCH 1/2] misc Kconfig: always ask for misc devices Sascha Hauer
@ 2014-01-29  9:30 ` Sascha Hauer
  2014-01-29 10:26   ` Alexander Shiyan
  2014-01-30  6:47   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 2 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-01-29  9:30 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/misc/Kconfig  |  6 +++++
 drivers/misc/Makefile |  1 +
 drivers/misc/sram.c   | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+)
 create mode 100644 drivers/misc/sram.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index e59c4f1..c34a4af 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -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
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b085577..908c8cb 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -3,3 +3,4 @@
 #
 
 obj-$(CONFIG_JTAG)		+= jtag.o
+obj-$(CONFIG_SRAM)		+= sram.o
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
new file mode 100644
index 0000000..7ea23b7
--- /dev/null
+++ b/drivers/misc/sram.c
@@ -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);
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-29  9:30 ` [PATCH 2/2] misc: Add devicetree SRAM driver Sascha Hauer
@ 2014-01-29 10:26   ` Alexander Shiyan
  2014-01-29 20:35     ` Sascha Hauer
  2014-01-30  6:47   ` Jean-Christophe PLAGNIOL-VILLARD
  1 sibling, 1 reply; 8+ messages in thread
From: Alexander Shiyan @ 2014-01-29 10:26 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Среда, 29 января 2014, 10:30 +01:00 от Sascha Hauer <s.hauer@pengutronix.de>:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
...
> +++ b/drivers/misc/sram.c
> @@ -0,0 +1,75 @@
> +/*
> + * drivers/misc/sram.c - generic memory mapped SRAM driver
...
> +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;
> +}

Probably we should include clock handling in this driver to make it
compatible with kernel version of this driver.

---
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-29 10:26   ` Alexander Shiyan
@ 2014-01-29 20:35     ` Sascha Hauer
  2014-01-30  6:35       ` Alexander Shiyan
  0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2014-01-29 20:35 UTC (permalink / raw)
  To: Alexander Shiyan; +Cc: barebox

On Wed, Jan 29, 2014 at 02:26:45PM +0400, Alexander Shiyan wrote:
> Среда, 29 января 2014, 10:30 +01:00 от Sascha Hauer <s.hauer@pengutronix.de>:
> > +	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;
> > +}
> 
> Probably we should include clock handling in this driver to make it
> compatible with kernel version of this driver.

Can we delay this until someone actually needs it?

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-29 20:35     ` Sascha Hauer
@ 2014-01-30  6:35       ` Alexander Shiyan
  0 siblings, 0 replies; 8+ messages in thread
From: Alexander Shiyan @ 2014-01-30  6:35 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

Среда, 29 января 2014, 21:35 +01:00 от Sascha Hauer <s.hauer@pengutronix.de>:
> On Wed, Jan 29, 2014 at 02:26:45PM +0400, Alexander Shiyan wrote:
> > Среда, 29 января 2014, 10:30 +01:00 от Sascha Hauer
> <s.hauer@pengutronix.de>:
> > > +	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;
> > > +}
> > 
> > Probably we should include clock handling in this driver to make it
> > compatible with kernel version of this driver.
> 
> Can we delay this until someone actually needs it?

Sure.

---
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-29  9:30 ` [PATCH 2/2] misc: Add devicetree SRAM driver Sascha Hauer
  2014-01-29 10:26   ` Alexander Shiyan
@ 2014-01-30  6:47   ` Jean-Christophe PLAGNIOL-VILLARD
  2014-01-30  7:41     ` Sascha Hauer
  1 sibling, 1 reply; 8+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2014-01-30  6:47 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:30 Wed 29 Jan     , Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  drivers/misc/Kconfig  |  6 +++++
>  drivers/misc/Makefile |  1 +
>  drivers/misc/sram.c   | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++

on at91 we already use the sram

and the sram could be used by any driver for dma (ethernet, framebuffer)

how could handle this in the generic driver?
>  3 files changed, 82 insertions(+)
>  create mode 100644 drivers/misc/sram.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index e59c4f1..c34a4af 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -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
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index b085577..908c8cb 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -3,3 +3,4 @@
>  #
>  
>  obj-$(CONFIG_JTAG)		+= jtag.o
> +obj-$(CONFIG_SRAM)		+= sram.o
> diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
> new file mode 100644
> index 0000000..7ea23b7
> --- /dev/null
> +++ b/drivers/misc/sram.c
> @@ -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);
> -- 
> 1.8.5.3
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-30  6:47   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2014-01-30  7:41     ` Sascha Hauer
  2014-01-31  8:13       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 8+ messages in thread
From: Sascha Hauer @ 2014-01-30  7:41 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Thu, Jan 30, 2014 at 07:47:42AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 10:30 Wed 29 Jan     , Sascha Hauer wrote:
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  drivers/misc/Kconfig  |  6 +++++
> >  drivers/misc/Makefile |  1 +
> >  drivers/misc/sram.c   | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
> 
> on at91 we already use the sram
> 
> and the sram could be used by any driver for dma (ethernet, framebuffer)
> 
> how could handle this in the generic driver?

The generic driver only registers a cdev for accessing it, so you have
to actively corrupt the SRAM on the commandline to break something.
I don't know how AT91 does it, but the mmio-sram driver in the kernel
registers an allocator on the SRAM. Consumers then have a phandle to the
SRAM node and can allocate from the SRAM pool using the phandle. We
could do something similar in barebox should we have to. It's debatable
whether we should remove the cdev once the allocator is used, but let's
see until we get there.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] misc: Add devicetree SRAM driver
  2014-01-30  7:41     ` Sascha Hauer
@ 2014-01-31  8:13       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 8+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2014-01-31  8:13 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 08:41 Thu 30 Jan     , Sascha Hauer wrote:
> On Thu, Jan 30, 2014 at 07:47:42AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 10:30 Wed 29 Jan     , Sascha Hauer wrote:
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > > ---
> > >  drivers/misc/Kconfig  |  6 +++++
> > >  drivers/misc/Makefile |  1 +
> > >  drivers/misc/sram.c   | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++
> > 
> > on at91 we already use the sram
> > 
> > and the sram could be used by any driver for dma (ethernet, framebuffer)
> > 
> > how could handle this in the generic driver?
> 
> The generic driver only registers a cdev for accessing it, so you have
> to actively corrupt the SRAM on the commandline to break something.
> I don't know how AT91 does it, but the mmio-sram driver in the kernel
> registers an allocator on the SRAM.
same on at91
> Consumers then have a phandle to the
> SRAM node and can allocate from the SRAM pool using the phandle. We
> could do something similar in barebox should we have to. It's debatable
> whether we should remove the cdev once the allocator is used, but let's
> see until we get there.

the cdev I do not known too make RO for those pasrt make with a way to
overwrite it if needed
> 
> Sascha
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-01-31  8:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-29  9:29 [PATCH 1/2] misc Kconfig: always ask for misc devices Sascha Hauer
2014-01-29  9:30 ` [PATCH 2/2] misc: Add devicetree SRAM driver Sascha Hauer
2014-01-29 10:26   ` Alexander Shiyan
2014-01-29 20:35     ` Sascha Hauer
2014-01-30  6:35       ` Alexander Shiyan
2014-01-30  6:47   ` Jean-Christophe PLAGNIOL-VILLARD
2014-01-30  7:41     ` Sascha Hauer
2014-01-31  8:13       ` Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox