Re: [PATCH v2] regmap: Add regmap dummy driver

2012-08-06 Thread Mark Brown
On Sat, Aug 04, 2012 at 01:43:42PM +0100, Dimitris Papastamos wrote:
> On Sat, Aug 04, 2012 at 11:05:23AM +0100, Mark Brown wrote:

> > Any reason not to put this in the tools directory?

> At the moment the repo is very bare bones.  I was thinking more of
> an automated testing framework written in sh or similar.  So it might
> grow out into its own repository anyhow.

It'd need to be pretty enormous for that I'd expect.

> > All these functions just seem to be implementing the default behaviour,
> > why are they needed?

> Hm will remove them for now but it would be useful for these to be set by
> the user via debugfs or similar.  These were mainly stubs for that sort
> of thing.

I figured that was the idea but until there's code controlling them it's
better to just not have anything.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] regmap: Add regmap dummy driver

2012-08-06 Thread Mark Brown
On Sat, Aug 04, 2012 at 01:43:42PM +0100, Dimitris Papastamos wrote:
 On Sat, Aug 04, 2012 at 11:05:23AM +0100, Mark Brown wrote:

  Any reason not to put this in the tools directory?

 At the moment the repo is very bare bones.  I was thinking more of
 an automated testing framework written in sh or similar.  So it might
 grow out into its own repository anyhow.

It'd need to be pretty enormous for that I'd expect.

  All these functions just seem to be implementing the default behaviour,
  why are they needed?

 Hm will remove them for now but it would be useful for these to be set by
 the user via debugfs or similar.  These were mainly stubs for that sort
 of thing.

I figured that was the idea but until there's code controlling them it's
better to just not have anything.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] regmap: Add regmap dummy driver

2012-08-04 Thread Dimitris Papastamos
On Sat, Aug 04, 2012 at 11:05:23AM +0100, Mark Brown wrote:
> On Fri, Jul 27, 2012 at 02:58:20PM +0100, Dimitris Papastamos wrote:
> > Add a pseudo-driver for debugging and stress-testing the
> > regmap/regcache APIs.  A standard set of tools for working
> 
> Overall this looks good, most of the stuff below is fairly small.  As a
> very high level comment it'd be really helpful to split this into a
> series of commits, for example adding just the dummy device then
> building out the functionality.  It'd make review much easier.
> 
> > with this driver (mainly sh scripts) will be put in a repo
> > at https://github.com/quantumdream/regmap-tools
> 
> Any reason not to put this in the tools directory?

At the moment the repo is very bare bones.  I was thinking more of
an automated testing framework written in sh or similar.  So it might
grow out into its own repository anyhow.

> > Some of these tests will require one to build with
> > REGMAP_ALLOW_WRITE_DEBUGFS defined.
> 
> Can we add a write mechanism specifically for this dummy driver?

Sure yes.

> > +   /* Set when regdummy defaults have been modified.
> > +* This is useful to know so we don't reinit the
> > +* cache if there is no reason to do so. */
> > +   unsigned int dirty:1;
> 
> Should we perhaps just reinit anyway?  It's not like this is performance
> critical...

Yea will remove it for simplicity.

> > +/* Default volatile register callback, this should
> > + * normally be configured by the user via a debugfs
> > + * entry */
> > +static bool regdummy_volatile_reg(struct device *dev,
> > + unsigned int reg)
> > +{
> > +   return false;
> > +}
> 
> All these functions just seem to be implementing the default behaviour,
> why are they needed?

Hm will remove them for now but it would be useful for these to be set by
the user via debugfs or similar.  These were mainly stubs for that sort
of thing.

> > +   /* If we're in the region the user is trying to read */
> > +   if (p >= *ppos) {
> > +   /* ...but not beyond it */
> > +   if (buf_pos >= count - 1 - tot_len)
> > +   break;
> 
> Any potential for code reuse?  This stuff does look awfully familiar!

Might factor some of these things into a separate regmap-utils.c.

> > +   /* Allocate the new register defaults */
> > +   regdef_num_new = rdevp->regs_size_new / config->reg_stride;
> > +   regdef_num_raw_new = regdef_num_new * sizeof(*regdef_new);
> > +   regdef_new = kzalloc(regdef_num_raw_new, GFP_KERNEL);
> 
> Can we factor this stuff out - there's a lot of overlap with the vanilla
> init?

Sure.

> > +static struct platform_device regdummy_device = {
> > +   .name = "regdummy",
> > +   .id = 0,
> > +};
> 
> Set id to -1 if there's only one of them.

Ok.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] regmap: Add regmap dummy driver

2012-08-04 Thread Mark Brown
On Fri, Jul 27, 2012 at 02:58:20PM +0100, Dimitris Papastamos wrote:
> Add a pseudo-driver for debugging and stress-testing the
> regmap/regcache APIs.  A standard set of tools for working

Overall this looks good, most of the stuff below is fairly small.  As a
very high level comment it'd be really helpful to split this into a
series of commits, for example adding just the dummy device then
building out the functionality.  It'd make review much easier.

> with this driver (mainly sh scripts) will be put in a repo
> at https://github.com/quantumdream/regmap-tools

Any reason not to put this in the tools directory?

> Some of these tests will require one to build with
> REGMAP_ALLOW_WRITE_DEBUGFS defined.

Can we add a write mechanism specifically for this dummy driver?

> + /* Set when regdummy defaults have been modified.
> +  * This is useful to know so we don't reinit the
> +  * cache if there is no reason to do so. */
> + unsigned int dirty:1;

Should we perhaps just reinit anyway?  It's not like this is performance
critical...

> +/* Default volatile register callback, this should
> + * normally be configured by the user via a debugfs
> + * entry */
> +static bool regdummy_volatile_reg(struct device *dev,
> +   unsigned int reg)
> +{
> + return false;
> +}

All these functions just seem to be implementing the default behaviour,
why are they needed?

> + /* If we're in the region the user is trying to read */
> + if (p >= *ppos) {
> + /* ...but not beyond it */
> + if (buf_pos >= count - 1 - tot_len)
> + break;

Any potential for code reuse?  This stuff does look awfully familiar!

> + /* Allocate the new register defaults */
> + regdef_num_new = rdevp->regs_size_new / config->reg_stride;
> + regdef_num_raw_new = regdef_num_new * sizeof(*regdef_new);
> + regdef_new = kzalloc(regdef_num_raw_new, GFP_KERNEL);

Can we factor this stuff out - there's a lot of overlap with the vanilla
init?

> +static struct platform_device regdummy_device = {
> + .name = "regdummy",
> + .id = 0,
> +};

Set id to -1 if there's only one of them.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] regmap: Add regmap dummy driver

2012-08-04 Thread Mark Brown
On Fri, Jul 27, 2012 at 02:58:20PM +0100, Dimitris Papastamos wrote:
 Add a pseudo-driver for debugging and stress-testing the
 regmap/regcache APIs.  A standard set of tools for working

Overall this looks good, most of the stuff below is fairly small.  As a
very high level comment it'd be really helpful to split this into a
series of commits, for example adding just the dummy device then
building out the functionality.  It'd make review much easier.

 with this driver (mainly sh scripts) will be put in a repo
 at https://github.com/quantumdream/regmap-tools

Any reason not to put this in the tools directory?

 Some of these tests will require one to build with
 REGMAP_ALLOW_WRITE_DEBUGFS defined.

Can we add a write mechanism specifically for this dummy driver?

 + /* Set when regdummy defaults have been modified.
 +  * This is useful to know so we don't reinit the
 +  * cache if there is no reason to do so. */
 + unsigned int dirty:1;

Should we perhaps just reinit anyway?  It's not like this is performance
critical...

 +/* Default volatile register callback, this should
 + * normally be configured by the user via a debugfs
 + * entry */
 +static bool regdummy_volatile_reg(struct device *dev,
 +   unsigned int reg)
 +{
 + return false;
 +}

All these functions just seem to be implementing the default behaviour,
why are they needed?

 + /* If we're in the region the user is trying to read */
 + if (p = *ppos) {
 + /* ...but not beyond it */
 + if (buf_pos = count - 1 - tot_len)
 + break;

Any potential for code reuse?  This stuff does look awfully familiar!

 + /* Allocate the new register defaults */
 + regdef_num_new = rdevp-regs_size_new / config-reg_stride;
 + regdef_num_raw_new = regdef_num_new * sizeof(*regdef_new);
 + regdef_new = kzalloc(regdef_num_raw_new, GFP_KERNEL);

Can we factor this stuff out - there's a lot of overlap with the vanilla
init?

 +static struct platform_device regdummy_device = {
 + .name = regdummy,
 + .id = 0,
 +};

Set id to -1 if there's only one of them.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] regmap: Add regmap dummy driver

2012-08-04 Thread Dimitris Papastamos
On Sat, Aug 04, 2012 at 11:05:23AM +0100, Mark Brown wrote:
 On Fri, Jul 27, 2012 at 02:58:20PM +0100, Dimitris Papastamos wrote:
  Add a pseudo-driver for debugging and stress-testing the
  regmap/regcache APIs.  A standard set of tools for working
 
 Overall this looks good, most of the stuff below is fairly small.  As a
 very high level comment it'd be really helpful to split this into a
 series of commits, for example adding just the dummy device then
 building out the functionality.  It'd make review much easier.
 
  with this driver (mainly sh scripts) will be put in a repo
  at https://github.com/quantumdream/regmap-tools
 
 Any reason not to put this in the tools directory?

At the moment the repo is very bare bones.  I was thinking more of
an automated testing framework written in sh or similar.  So it might
grow out into its own repository anyhow.

  Some of these tests will require one to build with
  REGMAP_ALLOW_WRITE_DEBUGFS defined.
 
 Can we add a write mechanism specifically for this dummy driver?

Sure yes.

  +   /* Set when regdummy defaults have been modified.
  +* This is useful to know so we don't reinit the
  +* cache if there is no reason to do so. */
  +   unsigned int dirty:1;
 
 Should we perhaps just reinit anyway?  It's not like this is performance
 critical...

Yea will remove it for simplicity.

  +/* Default volatile register callback, this should
  + * normally be configured by the user via a debugfs
  + * entry */
  +static bool regdummy_volatile_reg(struct device *dev,
  + unsigned int reg)
  +{
  +   return false;
  +}
 
 All these functions just seem to be implementing the default behaviour,
 why are they needed?

Hm will remove them for now but it would be useful for these to be set by
the user via debugfs or similar.  These were mainly stubs for that sort
of thing.

  +   /* If we're in the region the user is trying to read */
  +   if (p = *ppos) {
  +   /* ...but not beyond it */
  +   if (buf_pos = count - 1 - tot_len)
  +   break;
 
 Any potential for code reuse?  This stuff does look awfully familiar!

Might factor some of these things into a separate regmap-utils.c.

  +   /* Allocate the new register defaults */
  +   regdef_num_new = rdevp-regs_size_new / config-reg_stride;
  +   regdef_num_raw_new = regdef_num_new * sizeof(*regdef_new);
  +   regdef_new = kzalloc(regdef_num_raw_new, GFP_KERNEL);
 
 Can we factor this stuff out - there's a lot of overlap with the vanilla
 init?

Sure.

  +static struct platform_device regdummy_device = {
  +   .name = regdummy,
  +   .id = 0,
  +};
 
 Set id to -1 if there's only one of them.

Ok.
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2] regmap: Add regmap dummy driver

2012-07-27 Thread Dimitris Papastamos
Add a pseudo-driver for debugging and stress-testing the
regmap/regcache APIs.  A standard set of tools for working
with this driver (mainly sh scripts) will be put in a repo
at https://github.com/quantumdream/regmap-tools

Some of these tests will require one to build with
REGMAP_ALLOW_WRITE_DEBUGFS defined.

Signed-off-by: Dimitris Papastamos 
---
 This is an initial implementation of the regdummy driver for regmap.
 This is mainly useful for debugging/stress-testing regcache as it
 removes the need for real hardware and can be done in an emulated
 environment very easily.

 There'll be incremental patches adding more features such as,
 support for configurable volatile/readable/etc. registers via
 debugfs entries.

 v2 updates:
 - Factored out the access to the MMIO region into a separate
 function.
 - Removed bogus Change-Id

 drivers/base/regmap/Kconfig|   8 +
 drivers/base/regmap/Makefile   |   1 +
 drivers/base/regmap/regmap-dummy.c | 609 +
 3 files changed, 618 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-dummy.c

diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig
index 6be390b..5a1ab02 100644
--- a/drivers/base/regmap/Kconfig
+++ b/drivers/base/regmap/Kconfig
@@ -20,3 +20,11 @@ config REGMAP_MMIO
 
 config REGMAP_IRQ
bool
+
+config REGMAP_DUMMY
+   tristate
+   select REGMAP_MMIO
+   help
+ Say Y or M if you want to add the regdummy driver for regmap.
+ This is a pseudo-driver used for debugging and stress-testing
+ the regmap/regcache APIs.
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile
index 5e75d1b..c5d70f1 100644
--- a/drivers/base/regmap/Makefile
+++ b/drivers/base/regmap/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
 obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
 obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
 obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
+obj-$(CONFIG_REGMAP_DUMMY) += regmap-dummy.o
diff --git a/drivers/base/regmap/regmap-dummy.c 
b/drivers/base/regmap/regmap-dummy.c
new file mode 100644
index 000..078e090
--- /dev/null
+++ b/drivers/base/regmap/regmap-dummy.c
@@ -0,0 +1,609 @@
+/*
+ * Register map access API - Dummy regmap driver
+ *
+ * Copyright 2012 Wolfson Microelectronics PLC.
+ *
+ * Author: Dimitris Papastamos 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEFAULT_REGS_SIZE 1024
+
+struct regdummy_dev {
+   struct device *dev;
+   struct mutex lock;
+
+   /* Set when regdummy defaults have been modified.
+* This is useful to know so we don't reinit the
+* cache if there is no reason to do so. */
+   unsigned int dirty:1;
+
+   void *regs;
+   unsigned int regs_size;
+   unsigned int regs_size_new;
+
+   struct regmap *map;
+   struct regmap_config *config;
+   struct reg_default *regdef;
+};
+
+static struct dentry *regdummy_debugfs_root;
+
+/* Default volatile register callback, this should
+ * normally be configured by the user via a debugfs
+ * entry */
+static bool regdummy_volatile_reg(struct device *dev,
+ unsigned int reg)
+{
+   return false;
+}
+
+/* Default readable register callback, this should
+ * normally be configured by the user via a debugfs
+ * entry */
+static bool regdummy_readable_reg(struct device *dev,
+ unsigned int reg)
+{
+   return true;
+}
+
+/* Default precious register callback, this should
+ * normally be configured by the user via a debugfs
+ * entry */
+static bool regdummy_precious_reg(struct device *dev,
+ unsigned int reg)
+{
+   return false;
+}
+
+/* Calculate the length of a fixed format  */
+static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
+{
+   snprintf(buf, buf_size, "%x", max_val);
+   return strlen(buf);
+}
+
+static ssize_t regdummy_defaults_read_file(struct file *file, char __user 
*user_buf,
+  size_t count, loff_t *ppos)
+{
+   int reg_len, val_len, tot_len;
+   size_t buf_pos = 0;
+   loff_t p = 0;
+   ssize_t ret;
+   int i;
+   struct regdummy_dev *rdevp = file->private_data;
+   struct regmap_config *config;
+   struct reg_default *regdef;
+   unsigned int val;
+   unsigned int j;
+   unsigned int regdef_num;
+   char *buf;
+
+   if (*ppos < 0 || !count)
+   return -EINVAL;
+
+   buf = kmalloc(count, GFP_KERNEL);
+   if (!buf)
+   return -ENOMEM;
+
+   mutex_lock(>lock);
+
+   config = rdevp->config;
+   regdef = rdevp->regdef;
+   regdef_num = 

[PATCH v2] regmap: Add regmap dummy driver

2012-07-27 Thread Dimitris Papastamos
Add a pseudo-driver for debugging and stress-testing the
regmap/regcache APIs.  A standard set of tools for working
with this driver (mainly sh scripts) will be put in a repo
at https://github.com/quantumdream/regmap-tools

Some of these tests will require one to build with
REGMAP_ALLOW_WRITE_DEBUGFS defined.

Signed-off-by: Dimitris Papastamos d...@opensource.wolfsonmicro.com
---
 This is an initial implementation of the regdummy driver for regmap.
 This is mainly useful for debugging/stress-testing regcache as it
 removes the need for real hardware and can be done in an emulated
 environment very easily.

 There'll be incremental patches adding more features such as,
 support for configurable volatile/readable/etc. registers via
 debugfs entries.

 v2 updates:
 - Factored out the access to the MMIO region into a separate
 function.
 - Removed bogus Change-Id

 drivers/base/regmap/Kconfig|   8 +
 drivers/base/regmap/Makefile   |   1 +
 drivers/base/regmap/regmap-dummy.c | 609 +
 3 files changed, 618 insertions(+)
 create mode 100644 drivers/base/regmap/regmap-dummy.c

diff --git a/drivers/base/regmap/Kconfig b/drivers/base/regmap/Kconfig
index 6be390b..5a1ab02 100644
--- a/drivers/base/regmap/Kconfig
+++ b/drivers/base/regmap/Kconfig
@@ -20,3 +20,11 @@ config REGMAP_MMIO
 
 config REGMAP_IRQ
bool
+
+config REGMAP_DUMMY
+   tristate
+   select REGMAP_MMIO
+   help
+ Say Y or M if you want to add the regdummy driver for regmap.
+ This is a pseudo-driver used for debugging and stress-testing
+ the regmap/regcache APIs.
diff --git a/drivers/base/regmap/Makefile b/drivers/base/regmap/Makefile
index 5e75d1b..c5d70f1 100644
--- a/drivers/base/regmap/Makefile
+++ b/drivers/base/regmap/Makefile
@@ -5,3 +5,4 @@ obj-$(CONFIG_REGMAP_I2C) += regmap-i2c.o
 obj-$(CONFIG_REGMAP_SPI) += regmap-spi.o
 obj-$(CONFIG_REGMAP_MMIO) += regmap-mmio.o
 obj-$(CONFIG_REGMAP_IRQ) += regmap-irq.o
+obj-$(CONFIG_REGMAP_DUMMY) += regmap-dummy.o
diff --git a/drivers/base/regmap/regmap-dummy.c 
b/drivers/base/regmap/regmap-dummy.c
new file mode 100644
index 000..078e090
--- /dev/null
+++ b/drivers/base/regmap/regmap-dummy.c
@@ -0,0 +1,609 @@
+/*
+ * Register map access API - Dummy regmap driver
+ *
+ * Copyright 2012 Wolfson Microelectronics PLC.
+ *
+ * Author: Dimitris Papastamos d...@opensource.wolfsonmicro.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/kernel.h
+#include linux/module.h
+#include linux/init.h
+#include linux/uaccess.h
+#include linux/platform_device.h
+#include linux/device.h
+#include linux/slab.h
+#include linux/debugfs.h
+#include linux/mutex.h
+#include linux/regmap.h
+
+#define DEFAULT_REGS_SIZE 1024
+
+struct regdummy_dev {
+   struct device *dev;
+   struct mutex lock;
+
+   /* Set when regdummy defaults have been modified.
+* This is useful to know so we don't reinit the
+* cache if there is no reason to do so. */
+   unsigned int dirty:1;
+
+   void *regs;
+   unsigned int regs_size;
+   unsigned int regs_size_new;
+
+   struct regmap *map;
+   struct regmap_config *config;
+   struct reg_default *regdef;
+};
+
+static struct dentry *regdummy_debugfs_root;
+
+/* Default volatile register callback, this should
+ * normally be configured by the user via a debugfs
+ * entry */
+static bool regdummy_volatile_reg(struct device *dev,
+ unsigned int reg)
+{
+   return false;
+}
+
+/* Default readable register callback, this should
+ * normally be configured by the user via a debugfs
+ * entry */
+static bool regdummy_readable_reg(struct device *dev,
+ unsigned int reg)
+{
+   return true;
+}
+
+/* Default precious register callback, this should
+ * normally be configured by the user via a debugfs
+ * entry */
+static bool regdummy_precious_reg(struct device *dev,
+ unsigned int reg)
+{
+   return false;
+}
+
+/* Calculate the length of a fixed format  */
+static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
+{
+   snprintf(buf, buf_size, %x, max_val);
+   return strlen(buf);
+}
+
+static ssize_t regdummy_defaults_read_file(struct file *file, char __user 
*user_buf,
+  size_t count, loff_t *ppos)
+{
+   int reg_len, val_len, tot_len;
+   size_t buf_pos = 0;
+   loff_t p = 0;
+   ssize_t ret;
+   int i;
+   struct regdummy_dev *rdevp = file-private_data;
+   struct regmap_config *config;
+   struct reg_default *regdef;
+   unsigned int val;
+   unsigned int j;
+   unsigned int regdef_num;
+   char *buf;
+
+   if (*ppos  0 || !count)
+   return -EINVAL;
+
+