Re: [alsa-devel] [PATCH 1/4 v2] MFD: twl4030: add twl4030_codec MFD as a new child to the core

2009-10-25 Thread Mark Brown
On Fri, Oct 23, 2009 at 04:07:05PM +0200, Samuel Ortiz wrote:

 As agreed, Mark is taking this one. So:
 Acked-by: Samuel Ortiz sa...@linux.intel.com

Applied all, if there's a merge problem with the MFD code then there's a
twl4030-mfd branch at

  git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git

which I'm happy for you to merge if it makes life easier.  Due to other
changes the patches end up depending on (just textually I think) there's
a big raft of other stuff in there too, sadly.
--
To unsubscribe from this list: send the line unsubscribe linux-omap in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/4 v2] MFD: twl4030: add twl4030_codec MFD as a new child to the core

2009-10-23 Thread Samuel Ortiz
Hi Peter,

On Thu, Oct 22, 2009 at 01:26:45PM +0300, Peter Ujfalusi wrote:
 New MFD child to twl4030 MFD device.
 
 Reason for the twl4030_codec MFD: the vibra control is actually in the codec
 part of the twl4030. If both the vibra and the audio functionality is needed
 from the twl4030 at the same time, than they need to control the codec power
 and APLL at the same time without breaking the other driver.
 Also these two has to be able to work without the need for the other driver.
 
 This MFD device will be used by the drivers, which needs resources
 from the twl4030 codec like audio and vibra.
 
 The platform specific configuration data is passed along to the
 child drivers (audio, vibra).
 
 Signed-off-by: Peter Ujfalusi peter.ujfal...@nokia.com
As agreed, Mark is taking this one. So:
Acked-by: Samuel Ortiz sa...@linux.intel.com

Cheers,
Samuel.

 ---
  drivers/mfd/Kconfig   |6 +
  drivers/mfd/Makefile  |1 +
  drivers/mfd/twl4030-codec.c   |  241 +
  drivers/mfd/twl4030-core.c|   14 ++
  include/linux/i2c/twl4030.h   |   18 +++
  include/linux/mfd/twl4030-codec.h |  271 
 +
  6 files changed, 551 insertions(+), 0 deletions(-)
  create mode 100644 drivers/mfd/twl4030-codec.c
  create mode 100644 include/linux/mfd/twl4030-codec.h
 
 diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
 index 570be13..08f2d07 100644
 --- a/drivers/mfd/Kconfig
 +++ b/drivers/mfd/Kconfig
 @@ -121,6 +121,12 @@ config TWL4030_POWER
 and load scripts controling which resources are switched off/on
 or reset when a sleep, wakeup or warm reset event occurs.
 
 +config TWL4030_CODEC
 + bool
 + depends on TWL4030_CORE
 + select MFD_CORE
 + default n
 +
  config MFD_TMIO
   bool
   default n
 diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
 index f3b277b..af0fc90 100644
 --- a/drivers/mfd/Makefile
 +++ b/drivers/mfd/Makefile
 @@ -26,6 +26,7 @@ obj-$(CONFIG_MENELAUS)  += menelaus.o
 
  obj-$(CONFIG_TWL4030_CORE)   += twl4030-core.o twl4030-irq.o
  obj-$(CONFIG_TWL4030_POWER)+= twl4030-power.o
 +obj-$(CONFIG_TWL4030_CODEC)  += twl4030-codec.o
 
  obj-$(CONFIG_MFD_MC13783)+= mc13783-core.o
 
 diff --git a/drivers/mfd/twl4030-codec.c b/drivers/mfd/twl4030-codec.c
 new file mode 100644
 index 000..9710307
 --- /dev/null
 +++ b/drivers/mfd/twl4030-codec.c
 @@ -0,0 +1,241 @@
 +/*
 + * MFD driver for twl4030 codec submodule
 + *
 + * Author:   Peter Ujfalusi peter.ujfal...@nokia.com
 + *
 + * Copyright:   (C) 2009 Nokia Corporation
 + *
 + * 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.
 + *
 + * 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.
 + *
 + * You should have received a copy of the GNU General Public License
 + * along with this program; if not, write to the Free Software
 + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 + * 02110-1301 USA
 + *
 + */
 +
 +#include linux/module.h
 +#include linux/types.h
 +#include linux/kernel.h
 +#include linux/fs.h
 +#include linux/platform_device.h
 +#include linux/i2c/twl4030.h
 +#include linux/mfd/core.h
 +#include linux/mfd/twl4030-codec.h
 +
 +#define TWL4030_CODEC_CELLS  2
 +
 +static struct platform_device *twl4030_codec_dev;
 +
 +struct twl4030_codec_resource {
 + int request_count;
 + u8 reg;
 + u8 mask;
 +};
 +
 +struct twl4030_codec {
 + struct mutex mutex;
 + struct twl4030_codec_resource resource[TWL4030_CODEC_RES_MAX];
 + struct mfd_cell cells[TWL4030_CODEC_CELLS];
 +};
 +
 +/*
 + * Modify the resource, the function returns the content of the register
 + * after the modification.
 + */
 +static int twl4030_codec_set_resource(enum twl4030_codec_res id, int enable)
 +{
 + struct twl4030_codec *codec = platform_get_drvdata(twl4030_codec_dev);
 + u8 val;
 +
 + twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, val,
 + codec-resource[id].reg);
 +
 + if (enable)
 + val |= codec-resource[id].mask;
 + else
 + val = ~codec-resource[id].mask;
 +
 + twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
 + val, codec-resource[id].reg);
 +
 + return val;
 +}
 +
 +static inline int twl4030_codec_get_resource(enum twl4030_codec_res id)
 +{
 + struct twl4030_codec *codec = platform_get_drvdata(twl4030_codec_dev);
 + u8 val;
 +
 + twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, val,
 + codec-resource[id].reg);
 +
 + return val;
 +}
 +
 +/*
 + * Enable the resource.
 + * The function returns with error 

[PATCH 1/4 v2] MFD: twl4030: add twl4030_codec MFD as a new child to the core

2009-10-22 Thread Peter Ujfalusi
New MFD child to twl4030 MFD device.

Reason for the twl4030_codec MFD: the vibra control is actually in the codec
part of the twl4030. If both the vibra and the audio functionality is needed
from the twl4030 at the same time, than they need to control the codec power
and APLL at the same time without breaking the other driver.
Also these two has to be able to work without the need for the other driver.

This MFD device will be used by the drivers, which needs resources
from the twl4030 codec like audio and vibra.

The platform specific configuration data is passed along to the
child drivers (audio, vibra).

Signed-off-by: Peter Ujfalusi peter.ujfal...@nokia.com
---
 drivers/mfd/Kconfig   |6 +
 drivers/mfd/Makefile  |1 +
 drivers/mfd/twl4030-codec.c   |  241 +
 drivers/mfd/twl4030-core.c|   14 ++
 include/linux/i2c/twl4030.h   |   18 +++
 include/linux/mfd/twl4030-codec.h |  271 +
 6 files changed, 551 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/twl4030-codec.c
 create mode 100644 include/linux/mfd/twl4030-codec.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 570be13..08f2d07 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -121,6 +121,12 @@ config TWL4030_POWER
  and load scripts controling which resources are switched off/on
  or reset when a sleep, wakeup or warm reset event occurs.

+config TWL4030_CODEC
+   bool
+   depends on TWL4030_CORE
+   select MFD_CORE
+   default n
+
 config MFD_TMIO
bool
default n
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f3b277b..af0fc90 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -26,6 +26,7 @@ obj-$(CONFIG_MENELAUS)+= menelaus.o

 obj-$(CONFIG_TWL4030_CORE) += twl4030-core.o twl4030-irq.o
 obj-$(CONFIG_TWL4030_POWER)+= twl4030-power.o
+obj-$(CONFIG_TWL4030_CODEC)+= twl4030-codec.o

 obj-$(CONFIG_MFD_MC13783)  += mc13783-core.o

diff --git a/drivers/mfd/twl4030-codec.c b/drivers/mfd/twl4030-codec.c
new file mode 100644
index 000..9710307
--- /dev/null
+++ b/drivers/mfd/twl4030-codec.c
@@ -0,0 +1,241 @@
+/*
+ * MFD driver for twl4030 codec submodule
+ *
+ * Author: Peter Ujfalusi peter.ujfal...@nokia.com
+ *
+ * Copyright:   (C) 2009 Nokia Corporation
+ *
+ * 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.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include linux/module.h
+#include linux/types.h
+#include linux/kernel.h
+#include linux/fs.h
+#include linux/platform_device.h
+#include linux/i2c/twl4030.h
+#include linux/mfd/core.h
+#include linux/mfd/twl4030-codec.h
+
+#define TWL4030_CODEC_CELLS2
+
+static struct platform_device *twl4030_codec_dev;
+
+struct twl4030_codec_resource {
+   int request_count;
+   u8 reg;
+   u8 mask;
+};
+
+struct twl4030_codec {
+   struct mutex mutex;
+   struct twl4030_codec_resource resource[TWL4030_CODEC_RES_MAX];
+   struct mfd_cell cells[TWL4030_CODEC_CELLS];
+};
+
+/*
+ * Modify the resource, the function returns the content of the register
+ * after the modification.
+ */
+static int twl4030_codec_set_resource(enum twl4030_codec_res id, int enable)
+{
+   struct twl4030_codec *codec = platform_get_drvdata(twl4030_codec_dev);
+   u8 val;
+
+   twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, val,
+   codec-resource[id].reg);
+
+   if (enable)
+   val |= codec-resource[id].mask;
+   else
+   val = ~codec-resource[id].mask;
+
+   twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
+   val, codec-resource[id].reg);
+
+   return val;
+}
+
+static inline int twl4030_codec_get_resource(enum twl4030_codec_res id)
+{
+   struct twl4030_codec *codec = platform_get_drvdata(twl4030_codec_dev);
+   u8 val;
+
+   twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, val,
+   codec-resource[id].reg);
+
+   return val;
+}
+
+/*
+ * Enable the resource.
+ * The function returns with error or the content of the register
+ */
+int twl4030_codec_enable_resource(enum twl4030_codec_res id)
+{
+   struct twl4030_codec *codec = platform_get_drvdata(twl4030_codec_dev);
+   int val;
+
+   if (id = TWL4030_CODEC_RES_MAX) {
+