public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: Samuel Ortiz <sameo@openedhand.com>, Liam Girdwood <lrg@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>
Subject: [PATCH 09/13] mfd: Add I2C control support for WM8350
Date: Mon,  6 Oct 2008 13:38:04 +0100	[thread overview]
Message-ID: <1223296688-9960-9-git-send-email-broonie@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1223296688-9960-8-git-send-email-broonie@opensource.wolfsonmicro.com>

Implement the I2C control interface for the WM8350. This code was
originally written by Liam Girdwood and has been updated for submission
by Mark Brown.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/mfd/Kconfig      |   11 ++++
 drivers/mfd/Makefile     |    1 +
 drivers/mfd/wm8350-i2c.c |  120 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/wm8350-i2c.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index c32d676..b2930cc 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -133,6 +133,17 @@ config MFD_WM8350_CONFIG_MODE_3
 	  
 	  If unsure say Y
 
+config MFD_WM8350_I2C
+	tristate "Support Wolfson Microelectronics WM8350 with I2C"
+	select MFD_WM8350
+	depends on I2C
+	help
+	  The WM8350 is an integrated audio and power management
+	  subsystem with watchdog and RTC functionality for embedded
+	  systems.  This option enables core support for the WM8350 with
+	  I2C as the control interface.  Additional options must be
+	  selected to enable support for the functionality of the chip.
+
 endmenu
 
 menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index b0adca0..746d37b 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -15,6 +15,7 @@ obj-$(CONFIG_MFD_TC6393XB)	+= tc6393xb.o
 obj-$(CONFIG_MFD_WM8400)	+= wm8400-core.o
 wm8350-objs			:= wm8350-core.o wm8350-regmap.o
 obj-$(CONFIG_MFD_WM8350)	+= wm8350.o
+obj-$(CONFIG_MFD_WM8350_I2C)	+= wm8350-i2c.o
 
 obj-$(CONFIG_MFD_CORE)		+= mfd-core.o
 
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
new file mode 100644
index 0000000..2b0569c
--- /dev/null
+++ b/drivers/mfd/wm8350-i2c.c
@@ -0,0 +1,120 @@
+/*
+ * wm8350-i2c.c  --  Generic I2C driver for Wolfson WM8350 PMIC
+ *
+ * This driver defines and configures the WM8350 for the Freescale i.MX32ADS.
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood
+ *         linux@wolfsonmicro.com
+ *
+ *  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.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/wm8350/core.h>
+
+static int wm8350_i2c_read_device(struct wm8350 *wm8350, char reg,
+				  int bytes, void *dest)
+{
+	int ret;
+
+	ret = i2c_master_send(wm8350->i2c_client, &reg, 1);
+	if (ret < 0)
+		return ret;
+	return i2c_master_recv(wm8350->i2c_client, dest, bytes);
+}
+
+static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
+				   int bytes, void *src)
+{
+	/* we add 1 byte for device register */
+	u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
+
+	if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
+		return -EINVAL;
+
+	msg[0] = reg;
+	memcpy(&msg[1], src, bytes);
+	return i2c_master_send(wm8350->i2c_client, msg, bytes + 1);
+}
+
+static int wm8350_i2c_probe(struct i2c_client *i2c,
+			    const struct i2c_device_id *id)
+{
+	struct wm8350 *wm8350;
+	int ret = 0;
+
+	wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL);
+	if (wm8350 == NULL) {
+		kfree(i2c);
+		return -ENOMEM;
+	}
+
+	i2c_set_clientdata(i2c, wm8350);
+	wm8350->dev = &i2c->dev;
+	wm8350->i2c_client = i2c;
+	wm8350->read_dev = wm8350_i2c_read_device;
+	wm8350->write_dev = wm8350_i2c_write_device;
+
+	ret = wm8350_device_init(wm8350);
+	if (ret < 0)
+		goto err;
+
+	return ret;
+
+err:
+	kfree(wm8350);
+	return ret;
+}
+
+static int wm8350_i2c_remove(struct i2c_client *i2c)
+{
+	struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
+
+	wm8350_device_exit(wm8350);
+	kfree(wm8350);
+
+	return 0;
+}
+
+static const struct i2c_device_id wm8350_i2c_id[] = {
+       { "wm8350", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
+
+
+static struct i2c_driver wm8350_i2c_driver = {
+	.driver = {
+		   .name = "wm8350",
+		   .owner = THIS_MODULE,
+	},
+	.probe = wm8350_i2c_probe,
+	.remove = wm8350_i2c_remove,
+	.id_table = wm8350_i2c_id,
+};
+
+static int __init wm8350_i2c_init(void)
+{
+	return i2c_add_driver(&wm8350_i2c_driver);
+}
+/* init early so consumer devices can complete system boot */
+subsys_initcall(wm8350_i2c_init);
+
+static void __exit wm8350_i2c_exit(void)
+{
+	i2c_del_driver(&wm8350_i2c_driver);
+}
+module_exit(wm8350_i2c_exit);
+
+MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
+MODULE_LICENSE("GPL");
-- 
1.5.6.5


  reply	other threads:[~2008-10-06 12:40 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-06 12:32 [PATCH 0/13] WM8350 support Mark Brown
2008-10-06 12:37 ` [PATCH 01/13] mfd: Add WM8350 audio register definitions Mark Brown
2008-10-06 12:37   ` [PATCH 02/13] mfd: Add WM8350 GPIO " Mark Brown
2008-10-06 12:37     ` [PATCH 03/13] mfd: Add WM8350 PMIC " Mark Brown
2008-10-06 12:37       ` [PATCH 04/13] mfd: Add WM8350 PMU " Mark Brown
2008-10-06 12:38         ` [PATCH 05/13] mfd: Add WM8350 comparator " Mark Brown
2008-10-06 12:38           ` [PATCH 06/13] mfd: Add WM8350 RTC " Mark Brown
2008-10-06 12:38             ` [PATCH 07/13] mfd: Add WM8350 watchdog " Mark Brown
2008-10-06 12:38               ` [PATCH 08/13] mfd: Core support for the WM8350 AudioPlus PMIC Mark Brown
2008-10-06 12:38                 ` Mark Brown [this message]
2008-10-06 12:38                   ` [PATCH 10/13] mfd: Add GPIO pin configuration support for WM8350 Mark Brown
2008-10-06 12:38                     ` [PATCH 11/13] mfd: Add initialisation callback " Mark Brown
2008-10-06 12:38                       ` [PATCH 12/13] mfd: Add WM8350 interrupt support Mark Brown
2008-10-06 12:38                         ` [PATCH 13/13] regulator: Add WM8350 regulator support Mark Brown
2008-10-09 12:05                 ` [PATCH 08/13] mfd: Core support for the WM8350 AudioPlus PMIC Liam Girdwood
2008-10-09 12:53                   ` Mark Brown
2008-10-10 14:24 ` [PATCH 0/13] WM8350 support Liam Girdwood
2008-10-10 14:31   ` Samuel Ortiz
2008-10-10 14:38     ` Mark Brown
2008-10-10 14:45       ` Liam Girdwood
2008-10-10 14:58         ` [PATCH 01/14] mfd: Add WM8350 audio register definitions Mark Brown
2008-10-10 14:58           ` [PATCH 02/14] mfd: Add WM8350 GPIO " Mark Brown
2008-10-10 14:58             ` [PATCH 03/14] mfd: Add WM8350 PMIC " Mark Brown
2008-10-10 14:58               ` [PATCH 04/14] mfd: Add WM8350 PMU " Mark Brown
2008-10-10 14:58                 ` [PATCH 05/14] mfd: Add WM8350 comparator " Mark Brown
2008-10-10 14:58                   ` [PATCH 06/14] mfd: Add WM8350 RTC " Mark Brown
2008-10-10 14:58                     ` [PATCH 07/14] mfd: Add WM8350 watchdog " Mark Brown
2008-10-10 14:58                       ` [PATCH 08/14] mfd: Core support for the WM8350 AudioPlus PMIC Mark Brown
2008-10-10 14:58                         ` [PATCH 09/14] mfd: Add I2C control support for WM8350 Mark Brown
2008-10-10 14:58                           ` [PATCH 10/14] mfd: Add GPIO pin configuration " Mark Brown
2008-10-10 14:58                             ` [PATCH 11/14] mfd: Add initialisation callback " Mark Brown
2008-10-10 14:58                               ` [PATCH 12/14] mfd: Add WM8350 interrupt support Mark Brown
2008-10-10 14:58                                 ` [PATCH 13/14] regulator: Add WM8350 regulator support Mark Brown
2008-10-10 14:58                                   ` [PATCH 14/14] mfd: Add WM8350 subdevice registration helper Mark Brown
2008-10-11 14:18                                     ` Samuel Ortiz
2008-10-11 15:38                                       ` Mark Brown
2008-10-11 14:09                             ` [PATCH 10/14] mfd: Add GPIO pin configuration support for WM8350 Samuel Ortiz
2008-10-11 14:46                               ` Mark Brown
2008-10-11 14:23         ` [PATCH 0/13] WM8350 support Samuel Ortiz
2008-10-10 14:48       ` Samuel Ortiz
2008-10-10 14:38     ` Liam Girdwood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1223296688-9960-9-git-send-email-broonie@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@kernel.org \
    --cc=sameo@openedhand.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox