linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] cbus/retu drivers to mainline
@ 2012-08-28 21:34 Aaro Koskinen
  2012-08-28 21:34 ` [RFC PATCH 1/5] i2c: introduce i2c-cbus driver Aaro Koskinen
                   ` (6 more replies)
  0 siblings, 7 replies; 18+ messages in thread
From: Aaro Koskinen @ 2012-08-28 21:34 UTC (permalink / raw)
  To: linux-omap

Hi,

I would like to start converting cbus drivers from linux-omap cbus branch
for mainline inclusion. Currently e.g. watchdog support is missing at
least on Nokia N800, so you cannot run the mainline kernel for longer
than ~60 seconds (and there is no way to disable the watchdog).

My proposal is to make cbus an i2c bus driver. For other drivers, it
should be easier to find a proper place in the tree. Here's a first
quickly made attempt to provide watchdog driver functionality for
N800. Please comment.

Aaro Koskinen (5):
  i2c: introduce i2c-cbus driver
  mfd: introduce retu-mfd driver
  watchdog: introduce retu_wdt driver
  arm: omap: n8x0: add i2c-cbus platform data
  arm: omap: n8x0: enable retu

 arch/arm/mach-omap2/board-n8x0.c |   35 ++++
 drivers/i2c/busses/Kconfig       |   10 +
 drivers/i2c/busses/Makefile      |    1 +
 drivers/i2c/busses/i2c-cbus.c    |  342 ++++++++++++++++++++++++++++++++++++++
 drivers/mfd/Kconfig              |    8 +
 drivers/mfd/Makefile             |    1 +
 drivers/mfd/retu-mfd.c           |  114 +++++++++++++
 drivers/watchdog/Kconfig         |   12 ++
 drivers/watchdog/Makefile        |    1 +
 drivers/watchdog/retu_wdt.c      |  191 +++++++++++++++++++++
 include/linux/i2c-cbus.h         |   27 +++
 include/linux/mfd/retu.h         |   20 +++
 12 files changed, 762 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-cbus.c
 create mode 100644 drivers/mfd/retu-mfd.c
 create mode 100644 drivers/watchdog/retu_wdt.c
 create mode 100644 include/linux/i2c-cbus.h
 create mode 100644 include/linux/mfd/retu.h

-- 
1.7.2.5


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

* [RFC PATCH 1/5] i2c: introduce i2c-cbus driver
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
@ 2012-08-28 21:34 ` Aaro Koskinen
  2012-08-29 23:35   ` Tony Lindgren
       [not found]   ` <1346189667-32330-2-git-send-email-aaro.koskinen-X3B1VOXEql0@public.gmane.org>
  2012-08-28 21:34 ` [RFC PATCH 2/5] mfd: introduce retu-mfd driver Aaro Koskinen
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Aaro Koskinen @ 2012-08-28 21:34 UTC (permalink / raw)
  To: linux-omap; +Cc: linux-i2c

Add i2c driver to enable access to devices behind CBUS on Nokia Internet
Tablets.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: linux-i2c@vger.kernel.org
---
 drivers/i2c/busses/Kconfig    |   10 ++
 drivers/i2c/busses/Makefile   |    1 +
 drivers/i2c/busses/i2c-cbus.c |  342 +++++++++++++++++++++++++++++++++++++++++
 include/linux/i2c-cbus.h      |   27 ++++
 4 files changed, 380 insertions(+), 0 deletions(-)
 create mode 100644 drivers/i2c/busses/i2c-cbus.c
 create mode 100644 include/linux/i2c-cbus.h

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index b4aaa1b..184ef43 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -331,6 +331,16 @@ config I2C_BLACKFIN_TWI_CLK_KHZ
 	help
 	  The unit of the TWI clock is kHz.
 
+config I2C_CBUS
+	tristate "CBUS I2C driver"
+	depends on GENERIC_GPIO
+	help
+	  Support for CBUS access using I2C API. Mostly relevant for Nokia
+	  Internet Tablets (770, N800 and N810).
+
+	  This driver can also be built as a module.  If so, the module
+	  will be called i2c-cbus.
+
 config I2C_CPM
 	tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)"
 	depends on (CPM1 || CPM2) && OF_I2C
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ce3c2be..44dbfd1 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_I2C_POWERMAC)	+= i2c-powermac.o
 obj-$(CONFIG_I2C_AT91)		+= i2c-at91.o
 obj-$(CONFIG_I2C_AU1550)	+= i2c-au1550.o
 obj-$(CONFIG_I2C_BLACKFIN_TWI)	+= i2c-bfin-twi.o
+obj-$(CONFIG_I2C_CBUS)		+= i2c-cbus.o
 obj-$(CONFIG_I2C_CPM)		+= i2c-cpm.o
 obj-$(CONFIG_I2C_DAVINCI)	+= i2c-davinci.o
 obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM)	+= i2c-designware-platform.o
diff --git a/drivers/i2c/busses/i2c-cbus.c b/drivers/i2c/busses/i2c-cbus.c
new file mode 100644
index 0000000..3cc5be4
--- /dev/null
+++ b/drivers/i2c/busses/i2c-cbus.c
@@ -0,0 +1,342 @@
+/*
+ * CBUS I2C driver for Nokia Internet Tablets.
+ *
+ * Copyright (C) 2004-2010 Nokia Corporation
+ *
+ * Based on code written by Juha Yrjölä, David Weinehall, Mikko Ylinen and
+ * Felipe Balbi. Converted to I2C driver by Aaro Koskinen.
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * 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 <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/platform_device.h>
+#include <linux/i2c.h>
+#include <linux/i2c-cbus.h>
+#include <linux/io.h>
+
+struct cbus_host {
+	/* host lock */
+	spinlock_t	lock;
+
+	struct device	*dev;
+
+	int		clk_gpio;
+	int		dat_gpio;
+	int		sel_gpio;
+};
+
+/**
+ * cbus_send_bit - sends one bit over the bus
+ * @host: the host we're using
+ * @bit: one bit of information to send
+ * @input: whether to set data pin as input after sending
+ */
+static int cbus_send_bit(struct cbus_host *host, unsigned bit,
+		unsigned input)
+{
+	int ret = 0;
+
+	gpio_set_value(host->dat_gpio, bit ? 1 : 0);
+	gpio_set_value(host->clk_gpio, 1);
+
+	/* The data bit is read on the rising edge of CLK */
+	if (input)
+		ret = gpio_direction_input(host->dat_gpio);
+
+	gpio_set_value(host->clk_gpio, 0);
+
+	return ret;
+}
+
+/**
+ * cbus_send_data - sends @len amount of data over the bus
+ * @host: the host we're using
+ * @data: the data to send
+ * @len: size of the transfer
+ * @input: whether to set data pin as input after sending
+ */
+static int cbus_send_data(struct cbus_host *host, unsigned data, unsigned len,
+		unsigned input)
+{
+	int ret = 0;
+	int i;
+
+	for (i = len; i > 0; i--) {
+		ret = cbus_send_bit(host, data & (1 << (i - 1)),
+				input && (i == 1));
+		if (ret < 0)
+			goto out;
+	}
+
+out:
+	return ret;
+}
+
+/**
+ * cbus_receive_bit - receives one bit from the bus
+ * @host: the host we're using
+ */
+static int cbus_receive_bit(struct cbus_host *host)
+{
+	int ret;
+
+	gpio_set_value(host->clk_gpio, 1);
+	ret = gpio_get_value(host->dat_gpio);
+	if (ret < 0)
+		goto out;
+	gpio_set_value(host->clk_gpio, 0);
+
+out:
+	return ret;
+}
+
+/**
+ * cbus_receive_word - receives 16-bit word from the bus
+ * @host: the host we're using
+ */
+static int cbus_receive_word(struct cbus_host *host)
+{
+	int ret = 0;
+	int i;
+
+	for (i = 16; i > 0; i--) {
+		int bit = cbus_receive_bit(host);
+
+		if (bit < 0)
+			goto out;
+
+		if (bit)
+			ret |= 1 << (i - 1);
+	}
+
+out:
+	return ret;
+}
+
+/**
+ * cbus_transfer - transfers data over the bus
+ * @host: the host we're using
+ * @rw: read/write flag
+ * @dev: device address
+ * @reg: register address
+ * @data: if @rw == I2C_SBUS_WRITE data to send otherwise 0
+ */
+static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev,
+			 unsigned reg, unsigned data)
+{
+	unsigned long flags;
+	int ret;
+
+	/* We don't want interrupts disturbing our transfer */
+	spin_lock_irqsave(&host->lock, flags);
+
+	/* Reset state and start of transfer, SEL stays down during transfer */
+	gpio_set_value(host->sel_gpio, 0);
+
+	/* Set the DAT pin to output */
+	gpio_direction_output(host->dat_gpio, 1);
+
+	/* Send the device address */
+	ret = cbus_send_data(host, dev, 3, 0);
+	if (ret < 0) {
+		dev_dbg(host->dev, "failed sending device addr\n");
+		goto out;
+	}
+
+	/* Send the rw flag */
+	ret = cbus_send_bit(host, rw == I2C_SMBUS_READ, 0);
+	if (ret < 0) {
+		dev_dbg(host->dev, "failed sending read/write flag\n");
+		goto out;
+	}
+
+	/* Send the device address */
+	ret = cbus_send_data(host, reg, 5, rw == I2C_SMBUS_READ);
+	if (ret < 0) {
+		dev_dbg(host->dev, "failed sending register addr\n");
+		goto out;
+	}
+
+	if (rw == I2C_SMBUS_WRITE) {
+		ret = cbus_send_data(host, data, 16, 0);
+		if (ret < 0) {
+			dev_dbg(host->dev, "failed sending data\n");
+			goto out;
+		}
+	} else {
+		gpio_set_value(host->clk_gpio, 1);
+
+		ret = cbus_receive_word(host);
+		if (ret < 0) {
+			dev_dbg(host->dev, "failed receiving data\n");
+			goto out;
+		}
+	}
+
+	/* Indicate end of transfer, SEL goes up until next transfer */
+	gpio_set_value(host->sel_gpio, 1);
+	gpio_set_value(host->clk_gpio, 1);
+	gpio_set_value(host->clk_gpio, 0);
+
+out:
+	spin_unlock_irqrestore(&host->lock, flags);
+
+	return ret;
+}
+
+static int cbus_i2c_smbus_xfer(struct i2c_adapter	*adapter,
+			       u16			addr,
+			       unsigned short		flags,
+			       char			read_write,
+			       u8			command,
+			       int			size,
+			       union i2c_smbus_data	*data)
+{
+	struct cbus_host *chost = i2c_get_adapdata(adapter);
+	int ret;
+
+	if (size != I2C_SMBUS_WORD_DATA)
+		return -EINVAL;
+
+	ret = cbus_transfer(chost, read_write == I2C_SMBUS_READ, addr,
+			    command, data->word);
+	if (ret < 0)
+		return ret;
+
+	if (read_write == I2C_SMBUS_READ)
+		data->word = ret;
+
+	return 0;
+}
+
+static u32 cbus_i2c_func(struct i2c_adapter *adapter)
+{
+	return I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
+}
+
+static const struct i2c_algorithm cbus_i2c_algo = {
+	.smbus_xfer	= cbus_i2c_smbus_xfer,
+	.functionality	= cbus_i2c_func,
+};
+
+static int cbus_i2c_remove(struct platform_device *pdev)
+{
+	struct i2c_adapter *adapter = platform_get_drvdata(pdev);
+	struct cbus_host *chost = i2c_get_adapdata(adapter);
+	int ret;
+
+	ret = i2c_del_adapter(adapter);
+	if (ret)
+		return ret;
+	gpio_free(chost->clk_gpio);
+	gpio_free(chost->dat_gpio);
+	gpio_free(chost->sel_gpio);
+	kfree(chost);
+	kfree(adapter);
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static int cbus_i2c_probe(struct platform_device *pdev)
+{
+	struct i2c_cbus_platform_data *pdata = pdev->dev.platform_data;
+	struct i2c_adapter *adapter;
+	struct cbus_host *chost;
+	struct gpio gpios[3];
+	int ret;
+
+	adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
+	if (!adapter) {
+		ret = -ENOMEM;
+		goto error;
+	}
+
+	chost = kzalloc(sizeof(*chost), GFP_KERNEL);
+	if (!chost) {
+		ret = -ENOMEM;
+		goto error_mem;
+	}
+
+	adapter->owner		= THIS_MODULE;
+	adapter->class		= I2C_CLASS_HWMON;
+	adapter->dev.parent	= &pdev->dev;
+	adapter->nr		= pdev->id;
+	adapter->timeout	= HZ;
+	adapter->algo		= &cbus_i2c_algo;
+	strlcpy(adapter->name, "CBUS I2C adapter", sizeof(adapter->name));
+
+	spin_lock_init(&chost->lock);
+	chost->dev = &pdev->dev;
+
+	gpios[0].gpio  = chost->clk_gpio = pdata->clk_gpio;
+	gpios[0].flags = GPIOF_OUT_INIT_LOW;
+	gpios[0].label = "CBUS clk";
+
+	gpios[1].gpio  = chost->dat_gpio = pdata->dat_gpio;
+	gpios[1].flags = GPIOF_IN;
+	gpios[1].label = "CBUS data";
+
+	gpios[2].gpio  = chost->sel_gpio = pdata->sel_gpio;
+	gpios[2].flags = GPIOF_OUT_INIT_HIGH;
+	gpios[2].label = "CBUS sel";
+
+	ret = gpio_request_array(gpios, ARRAY_SIZE(gpios));
+	if (ret)
+		goto error_gpio;
+
+	gpio_set_value(chost->clk_gpio, 1);
+	gpio_set_value(chost->clk_gpio, 0);
+
+	i2c_set_adapdata(adapter, chost);
+	platform_set_drvdata(pdev, adapter);
+
+	ret = i2c_add_numbered_adapter(adapter);
+	if (ret)
+		goto error_i2c;
+
+	return 0;
+
+error_i2c:
+	gpio_free_array(gpios, ARRAY_SIZE(gpios));
+error_gpio:
+	kfree(chost);
+error_mem:
+	kfree(adapter);
+error:
+	return ret;
+}
+
+static struct platform_driver cbus_i2c_driver = {
+	.probe	= cbus_i2c_probe,
+	.remove	= cbus_i2c_remove,
+	.driver	= {
+		.owner	= THIS_MODULE,
+		.name	= "i2c-cbus",
+	},
+};
+module_platform_driver(cbus_i2c_driver);
+
+MODULE_ALIAS("platform:i2c-cbus");
+MODULE_DESCRIPTION("CBUS I2C driver");
+MODULE_AUTHOR("Juha Yrjölä");
+MODULE_AUTHOR("David Weinehall");
+MODULE_AUTHOR("Mikko Ylinen");
+MODULE_AUTHOR("Felipe Balbi <felipe.balbi@nokia.com>");
+MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/i2c-cbus.h b/include/linux/i2c-cbus.h
new file mode 100644
index 0000000..636d726
--- /dev/null
+++ b/include/linux/i2c-cbus.h
@@ -0,0 +1,27 @@
+/*
+ * i2c-cbus.h - CBUS I2C platform_data definition
+ *
+ * Copyright (C) 2004-2009 Nokia Corporation
+ *
+ * Written by Felipe Balbi and Aaro Koskinen.
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * 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.
+ */
+
+#ifndef __INCLUDE_LINUX_I2C_CBUS_H
+#define __INCLUDE_LINUX_I2C_CBUS_H
+
+struct i2c_cbus_platform_data {
+	int dat_gpio;
+	int clk_gpio;
+	int sel_gpio;
+};
+
+#endif /* __INCLUDE_LINUX_I2C_CBUS_H */
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [RFC PATCH 2/5] mfd: introduce retu-mfd driver
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
  2012-08-28 21:34 ` [RFC PATCH 1/5] i2c: introduce i2c-cbus driver Aaro Koskinen
@ 2012-08-28 21:34 ` Aaro Koskinen
  2012-08-29 23:37   ` Tony Lindgren
                     ` (2 more replies)
  2012-08-28 21:34 ` [RFC PATCH 3/5] watchdog: introduce retu_wdt driver Aaro Koskinen
                   ` (4 subsequent siblings)
  6 siblings, 3 replies; 18+ messages in thread
From: Aaro Koskinen @ 2012-08-28 21:34 UTC (permalink / raw)
  To: linux-omap; +Cc: sameo

Retu is a multi-function device found on Nokia Internet Tablets
implementing at least watchdog, RTC, headset detection and power button
functionality.

This patch implements a minimum functionality providing only register
access functions.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: sameo@linux.intel.com
---
 drivers/mfd/Kconfig      |    8 +++
 drivers/mfd/Makefile     |    1 +
 drivers/mfd/retu-mfd.c   |  114 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/retu.h |   20 ++++++++
 4 files changed, 143 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/retu-mfd.c
 create mode 100644 include/linux/mfd/retu.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index b1a1462..8ca1270 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1003,6 +1003,14 @@ config MFD_PALMAS
 	  If you say yes here you get support for the Palmas
 	  series of PMIC chips from Texas Instruments.
 
+config MFD_RETU
+	tristate "Support for Retu multi-function device"
+	select MFD_CORE
+	depends on I2C
+	help
+	  Retu is a multi-function device found on Nokia Internet Tables
+	  (770, N800 and N810).
+
 endmenu
 endif
 
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 79dd22d..962ec9d 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -132,3 +132,4 @@ obj-$(CONFIG_MFD_RC5T583)	+= rc5t583.o rc5t583-irq.o
 obj-$(CONFIG_MFD_SEC_CORE)	+= sec-core.o sec-irq.o
 obj-$(CONFIG_MFD_ANATOP)	+= anatop-mfd.o
 obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
+obj-$(CONFIG_MFD_RETU)		+= retu-mfd.o
diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c
new file mode 100644
index 0000000..f0097d7
--- /dev/null
+++ b/drivers/mfd/retu-mfd.c
@@ -0,0 +1,114 @@
+/*
+ * Retu MFD driver
+ *
+ * Copyright (C) 2004, 2005 Nokia Corporation
+ *
+ * Based on code written by Juha Yrjölä, David Weinehall and Mikko Ylinen.
+ * Rewritten to MFD/I2C driver by Aaro Koskinen.
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * 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 <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/mutex.h>
+#include <linux/module.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/retu.h>
+#include <linux/moduleparam.h>
+
+/* Registers */
+#define RETU_REG_ASICR		0x00		/* ASIC ID and revision */
+#define RETU_REG_ASICR_VILMA	(1 << 7)	/* Bit indicating Vilma */
+
+static struct mfd_cell retu_devs[] = {
+	{ .name = "retu-wdt" },
+};
+
+int retu_read(struct retu_dev *rdev, u8 reg)
+{
+	return i2c_smbus_read_word_data(rdev->i2c, reg);
+}
+EXPORT_SYMBOL_GPL(retu_read);
+
+int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
+{
+	return i2c_smbus_write_word_data(rdev->i2c, reg, data);
+}
+EXPORT_SYMBOL_GPL(retu_write);
+
+static int __devinit retu_probe(struct i2c_client *i2c,
+				const struct i2c_device_id *id)
+{
+	struct retu_dev *rdev;
+	int ret;
+
+	rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
+	if (rdev == NULL)
+		return -ENOMEM;
+
+	i2c_set_clientdata(i2c, rdev);
+	rdev->dev = &i2c->dev;
+	rdev->i2c = i2c;
+
+	ret = retu_read(rdev, RETU_REG_ASICR);
+	if (ret < 0) {
+		dev_err(rdev->dev, "could not read Retu revision: %d\n", ret);
+		return -EIO;
+	}
+
+	dev_info(rdev->dev, "Retu%s v%d.%d found\n",
+		 (ret & RETU_REG_ASICR_VILMA) ? " & Vilma" : "",
+		 (ret >> 4) & 0x7, ret & 0xf);
+
+	ret = mfd_add_devices(rdev->dev, -1, retu_devs, ARRAY_SIZE(retu_devs),
+			      NULL, 0);
+	if (ret < 0)
+		goto error;
+
+	return ret;
+
+error:
+	kfree(rdev);
+	return ret;
+}
+
+static int __devexit retu_remove(struct i2c_client *i2c)
+{
+	struct retu_dev *rdev = i2c_get_clientdata(i2c);
+
+	mfd_remove_devices(rdev->dev);
+	kfree(rdev);
+
+	return 0;
+}
+
+static const struct i2c_device_id retu_id[] = {
+	{ "retu-mfd", 0 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, retu_id);
+
+static struct i2c_driver retu_driver = {
+	.driver		= {
+		.name = "retu-mfd",
+		.owner = THIS_MODULE,
+	},
+	.probe		= retu_probe,
+	.remove		= retu_remove,
+	.id_table	= retu_id,
+};
+module_i2c_driver(retu_driver);
+
+MODULE_DESCRIPTION("Retu MFD driver");
+MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/mfd/retu.h b/include/linux/mfd/retu.h
new file mode 100644
index 0000000..e1b3600
--- /dev/null
+++ b/include/linux/mfd/retu.h
@@ -0,0 +1,20 @@
+/*
+ * Retu MFD driver interface
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ */
+
+#ifndef __LINUX_MFD_RETU_H
+#define __LINUX_MFD_RETU_H
+
+struct retu_dev {
+	struct device *dev;
+	struct i2c_client *i2c;
+};
+
+int retu_read(struct retu_dev *, u8);
+int retu_write(struct retu_dev *, u8, u16);
+
+#endif /* __LINUX_MFD_RETU_H */
-- 
1.7.2.5

--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [RFC PATCH 3/5] watchdog: introduce retu_wdt driver
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
  2012-08-28 21:34 ` [RFC PATCH 1/5] i2c: introduce i2c-cbus driver Aaro Koskinen
  2012-08-28 21:34 ` [RFC PATCH 2/5] mfd: introduce retu-mfd driver Aaro Koskinen
@ 2012-08-28 21:34 ` Aaro Koskinen
  2012-08-29 23:38   ` Tony Lindgren
  2012-08-28 21:34 ` [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data Aaro Koskinen
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 18+ messages in thread
From: Aaro Koskinen @ 2012-08-28 21:34 UTC (permalink / raw)
  To: linux-omap; +Cc: linux-watchdog

Introduce Retu watchdog driver.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: linux-watchdog@vger.kernel.org
---
 drivers/watchdog/Kconfig    |   12 +++
 drivers/watchdog/Makefile   |    1 +
 drivers/watchdog/retu_wdt.c |  191 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 204 insertions(+), 0 deletions(-)
 create mode 100644 drivers/watchdog/retu_wdt.c

diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig
index 53d7571..0526c7a 100644
--- a/drivers/watchdog/Kconfig
+++ b/drivers/watchdog/Kconfig
@@ -352,6 +352,18 @@ config IMX2_WDT
 	  To compile this driver as a module, choose M here: the
 	  module will be called imx2_wdt.
 
+config RETU_WATCHDOG
+	tristate "Retu watchdog"
+	depends on MFD_RETU
+	select WATCHDOG_CORE
+	help
+	  Retu watchdog driver for Nokia Internet Tablets (700, N800,
+	  N810). At least on N800 the watchdog cannot be disabled, so
+	  this driver is essential and you should enable it.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called retu_wdt.
+
 # AVR32 Architecture
 
 config AT32AP700X_WDT
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile
index 572b39b..d2f1c0c 100644
--- a/drivers/watchdog/Makefile
+++ b/drivers/watchdog/Makefile
@@ -52,6 +52,7 @@ obj-$(CONFIG_STMP3XXX_WATCHDOG) += stmp3xxx_wdt.o
 obj-$(CONFIG_NUC900_WATCHDOG) += nuc900_wdt.o
 obj-$(CONFIG_TS72XX_WATCHDOG) += ts72xx_wdt.o
 obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
+obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
 
 # AVR32 Architecture
 obj-$(CONFIG_AT32AP700X_WDT) += at32ap700x_wdt.o
diff --git a/drivers/watchdog/retu_wdt.c b/drivers/watchdog/retu_wdt.c
new file mode 100644
index 0000000..4a3ae00
--- /dev/null
+++ b/drivers/watchdog/retu_wdt.c
@@ -0,0 +1,191 @@
+/*
+ * Retu watchdog driver
+ *
+ * Copyright (C) 2004, 2005 Nokia Corporation
+ *
+ * Based on code written by Amit Kucheria and Michael Buesch. Rewritten
+ * to use Retu MFD driver and new watchdog core by Aaro Koskinen.
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * 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 <linux/init.h>
+#include <linux/slab.h>
+#include <linux/errno.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/mfd/retu.h>
+#include <linux/watchdog.h>
+#include <linux/platform_device.h>
+
+/* Watchdog timer values in seconds */
+#define RETU_WDT_MAX_TIMER	63
+
+/* Registers */
+#define RETU_REG_WATCHDOG	0x17
+
+struct retu_wdt_dev {
+	struct retu_dev		*rdev;
+	struct device		*dev;
+	struct delayed_work	ping_work;
+};
+
+/*
+ * Since Retu watchdog cannot be disabled in hardware, we must kick it
+ * with a timer until userspace watchdog software takes over. If
+ * CONFIG_WATCHDOG_NOWAYOUT is set, we never start the feeding.
+ */
+static void retu_wdt_ping_enable(struct retu_wdt_dev *wdev)
+{
+	retu_write(wdev->rdev, RETU_REG_WATCHDOG, RETU_WDT_MAX_TIMER);
+	schedule_delayed_work(&wdev->ping_work,
+			round_jiffies_relative(RETU_WDT_MAX_TIMER * HZ / 2));
+}
+
+static void retu_wdt_ping_disable(struct retu_wdt_dev *wdev)
+{
+	retu_write(wdev->rdev, RETU_REG_WATCHDOG, RETU_WDT_MAX_TIMER);
+	cancel_delayed_work_sync(&wdev->ping_work);
+}
+
+static void retu_wdt_ping_work(struct work_struct *work)
+{
+	struct retu_wdt_dev *wdev = container_of(to_delayed_work(work),
+						struct retu_wdt_dev, ping_work);
+	retu_wdt_ping_enable(wdev);
+}
+
+static int retu_wdt_start(struct watchdog_device *wdog)
+{
+	struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
+
+	retu_wdt_ping_disable(wdev);
+
+	return retu_write(wdev->rdev, RETU_REG_WATCHDOG, wdog->timeout);
+}
+
+static int retu_wdt_stop(struct watchdog_device *wdog)
+{
+	struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
+
+	retu_wdt_ping_enable(wdev);
+
+	return 0;
+}
+
+static int retu_wdt_ping(struct watchdog_device *wdog)
+{
+	struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
+
+	return retu_write(wdev->rdev, RETU_REG_WATCHDOG, wdog->timeout);
+}
+
+static int retu_wdt_set_timeout(struct watchdog_device *wdog,
+				unsigned int timeout)
+{
+	struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
+
+	wdog->timeout = timeout;
+	return retu_write(wdev->rdev, RETU_REG_WATCHDOG, wdog->timeout);
+}
+
+static const struct watchdog_info retu_wdt_info = {
+	.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
+	.identity = "Retu watchdog",
+};
+
+static const struct watchdog_ops retu_wdt_ops = {
+	.owner		= THIS_MODULE,
+	.start		= retu_wdt_start,
+	.stop		= retu_wdt_stop,
+	.ping		= retu_wdt_ping,
+	.set_timeout	= retu_wdt_set_timeout,
+};
+
+static int __devinit retu_wdt_probe(struct platform_device *pdev)
+{
+	struct retu_dev *rdev = dev_get_drvdata(pdev->dev.parent);
+	bool nowayout = WATCHDOG_NOWAYOUT;
+	struct watchdog_device *retu_wdt;
+	struct retu_wdt_dev *wdev;
+	int ret;
+
+	retu_wdt = kzalloc(sizeof(*retu_wdt), GFP_KERNEL);
+	if (!retu_wdt)
+		return -ENOMEM;
+
+	wdev = kzalloc(sizeof(*wdev), GFP_KERNEL);
+	if (!wdev) {
+		ret = -ENOMEM;
+		goto error_mem;
+	}
+
+	retu_wdt->info		= &retu_wdt_info;
+	retu_wdt->ops		= &retu_wdt_ops;
+	retu_wdt->timeout	= RETU_WDT_MAX_TIMER;
+	retu_wdt->min_timeout	= 0;
+	retu_wdt->max_timeout	= RETU_WDT_MAX_TIMER;
+
+	watchdog_set_drvdata(retu_wdt, wdev);
+	watchdog_set_nowayout(retu_wdt, nowayout);
+
+	wdev->rdev		= rdev;
+	wdev->dev		= &pdev->dev;
+
+	INIT_DELAYED_WORK(&wdev->ping_work, retu_wdt_ping_work);
+
+	ret = watchdog_register_device(retu_wdt);
+	if (ret < 0)
+		goto error_reg;
+
+	if (nowayout)
+		retu_wdt_ping(retu_wdt);
+	else
+		retu_wdt_ping_enable(wdev);
+
+	platform_set_drvdata(pdev, retu_wdt);
+
+	return 0;
+
+error_reg:
+	kfree(wdev);
+error_mem:
+	kfree(retu_wdt);
+	return ret;
+}
+
+static int __devexit retu_wdt_remove(struct platform_device *pdev)
+{
+	struct watchdog_device *wdog = platform_get_drvdata(pdev);
+	struct retu_wdt_dev *wdev = watchdog_get_drvdata(wdog);
+
+	watchdog_unregister_device(wdog);
+	cancel_delayed_work_sync(&wdev->ping_work);
+	kfree(wdev);
+	kfree(wdog);
+
+	return 0;
+}
+
+static struct platform_driver retu_wdt_driver = {
+	.probe		= retu_wdt_probe,
+	.remove		= __devexit_p(retu_wdt_remove),
+	.driver		= {
+		.name	= "retu-wdt",
+	},
+};
+module_platform_driver(retu_wdt_driver);
+
+MODULE_ALIAS("platform:retu-wdt");
+MODULE_DESCRIPTION("Retu watchdog");
+MODULE_AUTHOR("Amit Kucheria");
+MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
+MODULE_LICENSE("GPL");
-- 
1.7.2.5


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

* [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
                   ` (2 preceding siblings ...)
  2012-08-28 21:34 ` [RFC PATCH 3/5] watchdog: introduce retu_wdt driver Aaro Koskinen
@ 2012-08-28 21:34 ` Aaro Koskinen
  2012-08-29 23:39   ` Tony Lindgren
  2012-08-30 15:38   ` Felipe Balbi
  2012-08-28 21:34 ` [RFC PATCH 5/5] arm: omap: n8x0: enable retu Aaro Koskinen
                   ` (2 subsequent siblings)
  6 siblings, 2 replies; 18+ messages in thread
From: Aaro Koskinen @ 2012-08-28 21:34 UTC (permalink / raw)
  To: linux-omap

Add platform data to enable i2c-cbus on N8x0. It will be I2C bus #3.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 arch/arm/mach-omap2/board-n8x0.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
index 677357f..8ea0dea 100644
--- a/arch/arm/mach-omap2/board-n8x0.c
+++ b/arch/arm/mach-omap2/board-n8x0.c
@@ -18,6 +18,7 @@
 #include <linux/io.h>
 #include <linux/stddef.h>
 #include <linux/i2c.h>
+#include <linux/i2c-cbus.h>
 #include <linux/spi/spi.h>
 #include <linux/usb/musb.h>
 #include <sound/tlv320aic3x.h>
@@ -42,6 +43,31 @@
 #define TUSB6010_GPIO_ENABLE	0
 #define TUSB6010_DMACHAN	0x3f
 
+#if defined(CONFIG_I2C_CBUS) || defined(CONFIG_I2C_CBUS_MODULE)
+static struct i2c_cbus_platform_data n8x0_cbus_data = {
+	.clk_gpio = 66,
+	.dat_gpio = 65,
+	.sel_gpio = 64,
+};
+
+static struct platform_device n8x0_cbus_device = {
+	.name	= "i2c-cbus",
+	.id	= 3,
+	.dev	= {
+		.platform_data = &n8x0_cbus_data,
+	},
+};
+
+static void __init n8x0_cbus_init(void)
+{
+	platform_device_register(&n8x0_cbus_device);
+}
+#else /* CONFIG_I2C_CBUS */
+static void __init n8x0_cbus_init(void)
+{
+}
+#endif /* CONFIG_I2C_CBUS */
+
 #if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_TUSB6010_MODULE)
 /*
  * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and
@@ -681,6 +707,7 @@ static void __init n8x0_init_machine(void)
 	gpmc_onenand_init(board_onenand_data);
 	n8x0_mmc_init();
 	n8x0_usb_init();
+	n8x0_cbus_init();
 }
 
 MACHINE_START(NOKIA_N800, "Nokia N800")
-- 
1.7.2.5


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

* [RFC PATCH 5/5] arm: omap: n8x0: enable retu
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
                   ` (3 preceding siblings ...)
  2012-08-28 21:34 ` [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data Aaro Koskinen
@ 2012-08-28 21:34 ` Aaro Koskinen
  2012-08-29 23:40   ` Tony Lindgren
  2012-08-30 15:39   ` Felipe Balbi
  2012-08-29 23:28 ` [RFC PATCH 0/5] cbus/retu drivers to mainline Tony Lindgren
  2012-08-30 15:39 ` Felipe Balbi
  6 siblings, 2 replies; 18+ messages in thread
From: Aaro Koskinen @ 2012-08-28 21:34 UTC (permalink / raw)
  To: linux-omap

Add Retu configuration.

Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
---
 arch/arm/mach-omap2/board-n8x0.c |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
index 8ea0dea..6ac8cd9 100644
--- a/arch/arm/mach-omap2/board-n8x0.c
+++ b/arch/arm/mach-omap2/board-n8x0.c
@@ -58,8 +58,16 @@ static struct platform_device n8x0_cbus_device = {
 	},
 };
 
+static struct i2c_board_info n8x0_i2c_board_info_3[] __initdata = {
+	{
+		I2C_BOARD_INFO("retu-mfd", 0x01),
+	},
+};
+
 static void __init n8x0_cbus_init(void)
 {
+	i2c_register_board_info(3, n8x0_i2c_board_info_3,
+				ARRAY_SIZE(n8x0_i2c_board_info_3));
 	platform_device_register(&n8x0_cbus_device);
 }
 #else /* CONFIG_I2C_CBUS */
-- 
1.7.2.5


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

* Re: [RFC PATCH 0/5] cbus/retu drivers to mainline
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
                   ` (4 preceding siblings ...)
  2012-08-28 21:34 ` [RFC PATCH 5/5] arm: omap: n8x0: enable retu Aaro Koskinen
@ 2012-08-29 23:28 ` Tony Lindgren
  2012-08-30 15:39 ` Felipe Balbi
  6 siblings, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-08-29 23:28 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

* Aaro Koskinen <aaro.koskinen@iki.fi> [120828 14:35]:
> Hi,
> 
> I would like to start converting cbus drivers from linux-omap cbus branch
> for mainline inclusion. Currently e.g. watchdog support is missing at
> least on Nokia N800, so you cannot run the mainline kernel for longer
> than ~60 seconds (and there is no way to disable the watchdog).
> 
> My proposal is to make cbus an i2c bus driver. For other drivers, it
> should be easier to find a proper place in the tree. Here's a first
> quickly made attempt to provide watchdog driver functionality for
> N800. Please comment.

Excellent! This will remove the last remaining patches from linux-omap
that we've carried around. (Not counting the few board-*.c files that
we still carry for testing though)

Regaqrds,

Tony

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

* Re: [RFC PATCH 1/5] i2c: introduce i2c-cbus driver
  2012-08-28 21:34 ` [RFC PATCH 1/5] i2c: introduce i2c-cbus driver Aaro Koskinen
@ 2012-08-29 23:35   ` Tony Lindgren
       [not found]   ` <1346189667-32330-2-git-send-email-aaro.koskinen-X3B1VOXEql0@public.gmane.org>
  1 sibling, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-08-29 23:35 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap, linux-i2c

* Aaro Koskinen <aaro.koskinen@iki.fi> [120828 14:35]:
> Add i2c driver to enable access to devices behind CBUS on Nokia Internet
> Tablets.

Can you please do also a separate patch for the device tree binding for
getting the GPIO pins for this controller? 

Other than that thanks for doing this and:

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [RFC PATCH 2/5] mfd: introduce retu-mfd driver
  2012-08-28 21:34 ` [RFC PATCH 2/5] mfd: introduce retu-mfd driver Aaro Koskinen
@ 2012-08-29 23:37   ` Tony Lindgren
  2012-08-30 15:36   ` Felipe Balbi
  2012-09-19 15:30   ` Samuel Ortiz
  2 siblings, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-08-29 23:37 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap, sameo

* Aaro Koskinen <aaro.koskinen@iki.fi> [120828 14:35]:
> Retu is a multi-function device found on Nokia Internet Tablets
> implementing at least watchdog, RTC, headset detection and power button
> functionality.
> 
> This patch implements a minimum functionality providing only register
> access functions.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> Cc: sameo@linux.intel.com

Probably makes sense to merge this along with the I2C patch?

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [RFC PATCH 3/5] watchdog: introduce retu_wdt driver
  2012-08-28 21:34 ` [RFC PATCH 3/5] watchdog: introduce retu_wdt driver Aaro Koskinen
@ 2012-08-29 23:38   ` Tony Lindgren
  0 siblings, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-08-29 23:38 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap, linux-watchdog

* Aaro Koskinen <aaro.koskinen@iki.fi> [120828 14:35]:
> Introduce Retu watchdog driver.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> Cc: linux-watchdog@vger.kernel.org

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data
  2012-08-28 21:34 ` [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data Aaro Koskinen
@ 2012-08-29 23:39   ` Tony Lindgren
  2012-08-30 15:38   ` Felipe Balbi
  1 sibling, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-08-29 23:39 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

* Aaro Koskinen <aaro.koskinen@iki.fi> [120828 14:35]:
> Add platform data to enable i2c-cbus on N8x0. It will be I2C bus #3.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [RFC PATCH 5/5] arm: omap: n8x0: enable retu
  2012-08-28 21:34 ` [RFC PATCH 5/5] arm: omap: n8x0: enable retu Aaro Koskinen
@ 2012-08-29 23:40   ` Tony Lindgren
  2012-08-30 15:39   ` Felipe Balbi
  1 sibling, 0 replies; 18+ messages in thread
From: Tony Lindgren @ 2012-08-29 23:40 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

* Aaro Koskinen <aaro.koskinen@iki.fi> [120828 14:35]:
> Add Retu configuration.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> ---
>  arch/arm/mach-omap2/board-n8x0.c |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
> index 8ea0dea..6ac8cd9 100644
> --- a/arch/arm/mach-omap2/board-n8x0.c
> +++ b/arch/arm/mach-omap2/board-n8x0.c
> @@ -58,8 +58,16 @@ static struct platform_device n8x0_cbus_device = {
>  	},
>  };
>  
> +static struct i2c_board_info n8x0_i2c_board_info_3[] __initdata = {
> +	{
> +		I2C_BOARD_INFO("retu-mfd", 0x01),
> +	},
> +};
> +
>  static void __init n8x0_cbus_init(void)
>  {
> +	i2c_register_board_info(3, n8x0_i2c_board_info_3,
> +				ARRAY_SIZE(n8x0_i2c_board_info_3));
>  	platform_device_register(&n8x0_cbus_device);
>  }
>  #else /* CONFIG_I2C_CBUS */

I suggest merging patches 4 & 5 into patch 1 and merge it via the
i2c list:

Acked-by: Tony Lindgren <tony@atomide.com>

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

* Re: [RFC PATCH 1/5] i2c: introduce i2c-cbus driver
       [not found]   ` <1346189667-32330-2-git-send-email-aaro.koskinen-X3B1VOXEql0@public.gmane.org>
@ 2012-08-30 15:34     ` Felipe Balbi
  0 siblings, 0 replies; 18+ messages in thread
From: Felipe Balbi @ 2012-08-30 15:34 UTC (permalink / raw)
  To: Aaro Koskinen
  Cc: linux-omap-u79uwXL29TY76Z2rM5mHXA,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 12750 bytes --]

On Wed, Aug 29, 2012 at 12:34:23AM +0300, Aaro Koskinen wrote:
> Add i2c driver to enable access to devices behind CBUS on Nokia Internet
> Tablets.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen-X3B1VOXEql0@public.gmane.org>
> Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

Acked-by: Felipe Balbi <balbi-l0cyMroinI0@public.gmane.org>

> ---
>  drivers/i2c/busses/Kconfig    |   10 ++
>  drivers/i2c/busses/Makefile   |    1 +
>  drivers/i2c/busses/i2c-cbus.c |  342 +++++++++++++++++++++++++++++++++++++++++
>  include/linux/i2c-cbus.h      |   27 ++++
>  4 files changed, 380 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/i2c/busses/i2c-cbus.c
>  create mode 100644 include/linux/i2c-cbus.h
> 
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index b4aaa1b..184ef43 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -331,6 +331,16 @@ config I2C_BLACKFIN_TWI_CLK_KHZ
>  	help
>  	  The unit of the TWI clock is kHz.
>  
> +config I2C_CBUS
> +	tristate "CBUS I2C driver"
> +	depends on GENERIC_GPIO
> +	help
> +	  Support for CBUS access using I2C API. Mostly relevant for Nokia
> +	  Internet Tablets (770, N800 and N810).
> +
> +	  This driver can also be built as a module.  If so, the module
> +	  will be called i2c-cbus.
> +
>  config I2C_CPM
>  	tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)"
>  	depends on (CPM1 || CPM2) && OF_I2C
> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
> index ce3c2be..44dbfd1 100644
> --- a/drivers/i2c/busses/Makefile
> +++ b/drivers/i2c/busses/Makefile
> @@ -31,6 +31,7 @@ obj-$(CONFIG_I2C_POWERMAC)	+= i2c-powermac.o
>  obj-$(CONFIG_I2C_AT91)		+= i2c-at91.o
>  obj-$(CONFIG_I2C_AU1550)	+= i2c-au1550.o
>  obj-$(CONFIG_I2C_BLACKFIN_TWI)	+= i2c-bfin-twi.o
> +obj-$(CONFIG_I2C_CBUS)		+= i2c-cbus.o
>  obj-$(CONFIG_I2C_CPM)		+= i2c-cpm.o
>  obj-$(CONFIG_I2C_DAVINCI)	+= i2c-davinci.o
>  obj-$(CONFIG_I2C_DESIGNWARE_PLATFORM)	+= i2c-designware-platform.o
> diff --git a/drivers/i2c/busses/i2c-cbus.c b/drivers/i2c/busses/i2c-cbus.c
> new file mode 100644
> index 0000000..3cc5be4
> --- /dev/null
> +++ b/drivers/i2c/busses/i2c-cbus.c
> @@ -0,0 +1,342 @@
> +/*
> + * CBUS I2C driver for Nokia Internet Tablets.
> + *
> + * Copyright (C) 2004-2010 Nokia Corporation
> + *
> + * Based on code written by Juha Yrjölä, David Weinehall, Mikko Ylinen and
> + * Felipe Balbi. Converted to I2C driver by Aaro Koskinen.
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * 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 <linux/gpio.h>
> +#include <linux/interrupt.h>
> +#include <linux/kernel.h>
> +#include <linux/module.h>
> +#include <linux/delay.h>
> +#include <linux/slab.h>
> +#include <linux/init.h>
> +#include <linux/errno.h>
> +#include <linux/platform_device.h>
> +#include <linux/i2c.h>
> +#include <linux/i2c-cbus.h>
> +#include <linux/io.h>
> +
> +struct cbus_host {
> +	/* host lock */
> +	spinlock_t	lock;
> +
> +	struct device	*dev;
> +
> +	int		clk_gpio;
> +	int		dat_gpio;
> +	int		sel_gpio;
> +};
> +
> +/**
> + * cbus_send_bit - sends one bit over the bus
> + * @host: the host we're using
> + * @bit: one bit of information to send
> + * @input: whether to set data pin as input after sending
> + */
> +static int cbus_send_bit(struct cbus_host *host, unsigned bit,
> +		unsigned input)
> +{
> +	int ret = 0;
> +
> +	gpio_set_value(host->dat_gpio, bit ? 1 : 0);
> +	gpio_set_value(host->clk_gpio, 1);
> +
> +	/* The data bit is read on the rising edge of CLK */
> +	if (input)
> +		ret = gpio_direction_input(host->dat_gpio);
> +
> +	gpio_set_value(host->clk_gpio, 0);
> +
> +	return ret;
> +}
> +
> +/**
> + * cbus_send_data - sends @len amount of data over the bus
> + * @host: the host we're using
> + * @data: the data to send
> + * @len: size of the transfer
> + * @input: whether to set data pin as input after sending
> + */
> +static int cbus_send_data(struct cbus_host *host, unsigned data, unsigned len,
> +		unsigned input)
> +{
> +	int ret = 0;
> +	int i;
> +
> +	for (i = len; i > 0; i--) {
> +		ret = cbus_send_bit(host, data & (1 << (i - 1)),
> +				input && (i == 1));
> +		if (ret < 0)
> +			goto out;
> +	}
> +
> +out:
> +	return ret;
> +}
> +
> +/**
> + * cbus_receive_bit - receives one bit from the bus
> + * @host: the host we're using
> + */
> +static int cbus_receive_bit(struct cbus_host *host)
> +{
> +	int ret;
> +
> +	gpio_set_value(host->clk_gpio, 1);
> +	ret = gpio_get_value(host->dat_gpio);
> +	if (ret < 0)
> +		goto out;
> +	gpio_set_value(host->clk_gpio, 0);
> +
> +out:
> +	return ret;
> +}
> +
> +/**
> + * cbus_receive_word - receives 16-bit word from the bus
> + * @host: the host we're using
> + */
> +static int cbus_receive_word(struct cbus_host *host)
> +{
> +	int ret = 0;
> +	int i;
> +
> +	for (i = 16; i > 0; i--) {
> +		int bit = cbus_receive_bit(host);
> +
> +		if (bit < 0)
> +			goto out;
> +
> +		if (bit)
> +			ret |= 1 << (i - 1);
> +	}
> +
> +out:
> +	return ret;
> +}
> +
> +/**
> + * cbus_transfer - transfers data over the bus
> + * @host: the host we're using
> + * @rw: read/write flag
> + * @dev: device address
> + * @reg: register address
> + * @data: if @rw == I2C_SBUS_WRITE data to send otherwise 0
> + */
> +static int cbus_transfer(struct cbus_host *host, char rw, unsigned dev,
> +			 unsigned reg, unsigned data)
> +{
> +	unsigned long flags;
> +	int ret;
> +
> +	/* We don't want interrupts disturbing our transfer */
> +	spin_lock_irqsave(&host->lock, flags);
> +
> +	/* Reset state and start of transfer, SEL stays down during transfer */
> +	gpio_set_value(host->sel_gpio, 0);
> +
> +	/* Set the DAT pin to output */
> +	gpio_direction_output(host->dat_gpio, 1);
> +
> +	/* Send the device address */
> +	ret = cbus_send_data(host, dev, 3, 0);
> +	if (ret < 0) {
> +		dev_dbg(host->dev, "failed sending device addr\n");
> +		goto out;
> +	}
> +
> +	/* Send the rw flag */
> +	ret = cbus_send_bit(host, rw == I2C_SMBUS_READ, 0);
> +	if (ret < 0) {
> +		dev_dbg(host->dev, "failed sending read/write flag\n");
> +		goto out;
> +	}
> +
> +	/* Send the device address */
> +	ret = cbus_send_data(host, reg, 5, rw == I2C_SMBUS_READ);
> +	if (ret < 0) {
> +		dev_dbg(host->dev, "failed sending register addr\n");
> +		goto out;
> +	}
> +
> +	if (rw == I2C_SMBUS_WRITE) {
> +		ret = cbus_send_data(host, data, 16, 0);
> +		if (ret < 0) {
> +			dev_dbg(host->dev, "failed sending data\n");
> +			goto out;
> +		}
> +	} else {
> +		gpio_set_value(host->clk_gpio, 1);
> +
> +		ret = cbus_receive_word(host);
> +		if (ret < 0) {
> +			dev_dbg(host->dev, "failed receiving data\n");
> +			goto out;
> +		}
> +	}
> +
> +	/* Indicate end of transfer, SEL goes up until next transfer */
> +	gpio_set_value(host->sel_gpio, 1);
> +	gpio_set_value(host->clk_gpio, 1);
> +	gpio_set_value(host->clk_gpio, 0);
> +
> +out:
> +	spin_unlock_irqrestore(&host->lock, flags);
> +
> +	return ret;
> +}
> +
> +static int cbus_i2c_smbus_xfer(struct i2c_adapter	*adapter,
> +			       u16			addr,
> +			       unsigned short		flags,
> +			       char			read_write,
> +			       u8			command,
> +			       int			size,
> +			       union i2c_smbus_data	*data)
> +{
> +	struct cbus_host *chost = i2c_get_adapdata(adapter);
> +	int ret;
> +
> +	if (size != I2C_SMBUS_WORD_DATA)
> +		return -EINVAL;
> +
> +	ret = cbus_transfer(chost, read_write == I2C_SMBUS_READ, addr,
> +			    command, data->word);
> +	if (ret < 0)
> +		return ret;
> +
> +	if (read_write == I2C_SMBUS_READ)
> +		data->word = ret;
> +
> +	return 0;
> +}
> +
> +static u32 cbus_i2c_func(struct i2c_adapter *adapter)
> +{
> +	return I2C_FUNC_SMBUS_READ_WORD_DATA | I2C_FUNC_SMBUS_WRITE_WORD_DATA;
> +}
> +
> +static const struct i2c_algorithm cbus_i2c_algo = {
> +	.smbus_xfer	= cbus_i2c_smbus_xfer,
> +	.functionality	= cbus_i2c_func,
> +};
> +
> +static int cbus_i2c_remove(struct platform_device *pdev)
> +{
> +	struct i2c_adapter *adapter = platform_get_drvdata(pdev);
> +	struct cbus_host *chost = i2c_get_adapdata(adapter);
> +	int ret;
> +
> +	ret = i2c_del_adapter(adapter);
> +	if (ret)
> +		return ret;
> +	gpio_free(chost->clk_gpio);
> +	gpio_free(chost->dat_gpio);
> +	gpio_free(chost->sel_gpio);
> +	kfree(chost);
> +	kfree(adapter);
> +	platform_set_drvdata(pdev, NULL);
> +
> +	return 0;
> +}
> +
> +static int cbus_i2c_probe(struct platform_device *pdev)
> +{
> +	struct i2c_cbus_platform_data *pdata = pdev->dev.platform_data;
> +	struct i2c_adapter *adapter;
> +	struct cbus_host *chost;
> +	struct gpio gpios[3];
> +	int ret;
> +
> +	adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
> +	if (!adapter) {
> +		ret = -ENOMEM;
> +		goto error;
> +	}
> +
> +	chost = kzalloc(sizeof(*chost), GFP_KERNEL);
> +	if (!chost) {
> +		ret = -ENOMEM;
> +		goto error_mem;
> +	}
> +
> +	adapter->owner		= THIS_MODULE;
> +	adapter->class		= I2C_CLASS_HWMON;
> +	adapter->dev.parent	= &pdev->dev;
> +	adapter->nr		= pdev->id;
> +	adapter->timeout	= HZ;
> +	adapter->algo		= &cbus_i2c_algo;
> +	strlcpy(adapter->name, "CBUS I2C adapter", sizeof(adapter->name));
> +
> +	spin_lock_init(&chost->lock);
> +	chost->dev = &pdev->dev;
> +
> +	gpios[0].gpio  = chost->clk_gpio = pdata->clk_gpio;
> +	gpios[0].flags = GPIOF_OUT_INIT_LOW;
> +	gpios[0].label = "CBUS clk";
> +
> +	gpios[1].gpio  = chost->dat_gpio = pdata->dat_gpio;
> +	gpios[1].flags = GPIOF_IN;
> +	gpios[1].label = "CBUS data";
> +
> +	gpios[2].gpio  = chost->sel_gpio = pdata->sel_gpio;
> +	gpios[2].flags = GPIOF_OUT_INIT_HIGH;
> +	gpios[2].label = "CBUS sel";
> +
> +	ret = gpio_request_array(gpios, ARRAY_SIZE(gpios));
> +	if (ret)
> +		goto error_gpio;
> +
> +	gpio_set_value(chost->clk_gpio, 1);
> +	gpio_set_value(chost->clk_gpio, 0);
> +
> +	i2c_set_adapdata(adapter, chost);
> +	platform_set_drvdata(pdev, adapter);
> +
> +	ret = i2c_add_numbered_adapter(adapter);
> +	if (ret)
> +		goto error_i2c;
> +
> +	return 0;
> +
> +error_i2c:
> +	gpio_free_array(gpios, ARRAY_SIZE(gpios));
> +error_gpio:
> +	kfree(chost);
> +error_mem:
> +	kfree(adapter);
> +error:
> +	return ret;
> +}
> +
> +static struct platform_driver cbus_i2c_driver = {
> +	.probe	= cbus_i2c_probe,
> +	.remove	= cbus_i2c_remove,
> +	.driver	= {
> +		.owner	= THIS_MODULE,
> +		.name	= "i2c-cbus",
> +	},
> +};
> +module_platform_driver(cbus_i2c_driver);
> +
> +MODULE_ALIAS("platform:i2c-cbus");
> +MODULE_DESCRIPTION("CBUS I2C driver");
> +MODULE_AUTHOR("Juha Yrjölä");
> +MODULE_AUTHOR("David Weinehall");
> +MODULE_AUTHOR("Mikko Ylinen");
> +MODULE_AUTHOR("Felipe Balbi <felipe.balbi-xNZwKgViW5gAvxtiuMwx3w@public.gmane.org>");
> +MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen-X3B1VOXEql0@public.gmane.org>");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/i2c-cbus.h b/include/linux/i2c-cbus.h
> new file mode 100644
> index 0000000..636d726
> --- /dev/null
> +++ b/include/linux/i2c-cbus.h
> @@ -0,0 +1,27 @@
> +/*
> + * i2c-cbus.h - CBUS I2C platform_data definition
> + *
> + * Copyright (C) 2004-2009 Nokia Corporation
> + *
> + * Written by Felipe Balbi and Aaro Koskinen.
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * 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.
> + */
> +
> +#ifndef __INCLUDE_LINUX_I2C_CBUS_H
> +#define __INCLUDE_LINUX_I2C_CBUS_H
> +
> +struct i2c_cbus_platform_data {
> +	int dat_gpio;
> +	int clk_gpio;
> +	int sel_gpio;
> +};
> +
> +#endif /* __INCLUDE_LINUX_I2C_CBUS_H */
> -- 
> 1.7.2.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [RFC PATCH 2/5] mfd: introduce retu-mfd driver
  2012-08-28 21:34 ` [RFC PATCH 2/5] mfd: introduce retu-mfd driver Aaro Koskinen
  2012-08-29 23:37   ` Tony Lindgren
@ 2012-08-30 15:36   ` Felipe Balbi
  2012-09-19 15:30   ` Samuel Ortiz
  2 siblings, 0 replies; 18+ messages in thread
From: Felipe Balbi @ 2012-08-30 15:36 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap, sameo

[-- Attachment #1: Type: text/plain, Size: 6177 bytes --]

On Wed, Aug 29, 2012 at 12:34:24AM +0300, Aaro Koskinen wrote:
> Retu is a multi-function device found on Nokia Internet Tablets
> implementing at least watchdog, RTC, headset detection and power button
> functionality.
> 
> This patch implements a minimum functionality providing only register
> access functions.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> Cc: sameo@linux.intel.com
> ---
>  drivers/mfd/Kconfig      |    8 +++
>  drivers/mfd/Makefile     |    1 +
>  drivers/mfd/retu-mfd.c   |  114 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/mfd/retu.h |   20 ++++++++
>  4 files changed, 143 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/mfd/retu-mfd.c
>  create mode 100644 include/linux/mfd/retu.h
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index b1a1462..8ca1270 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1003,6 +1003,14 @@ config MFD_PALMAS
>  	  If you say yes here you get support for the Palmas
>  	  series of PMIC chips from Texas Instruments.
>  
> +config MFD_RETU
> +	tristate "Support for Retu multi-function device"
> +	select MFD_CORE
> +	depends on I2C
> +	help
> +	  Retu is a multi-function device found on Nokia Internet Tables
								  ^^^^^^
								  tablets



> +	  (770, N800 and N810).
> +
>  endmenu
>  endif
>  
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index 79dd22d..962ec9d 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -132,3 +132,4 @@ obj-$(CONFIG_MFD_RC5T583)	+= rc5t583.o rc5t583-irq.o
>  obj-$(CONFIG_MFD_SEC_CORE)	+= sec-core.o sec-irq.o
>  obj-$(CONFIG_MFD_ANATOP)	+= anatop-mfd.o
>  obj-$(CONFIG_MFD_LM3533)	+= lm3533-core.o lm3533-ctrlbank.o
> +obj-$(CONFIG_MFD_RETU)		+= retu-mfd.o
> diff --git a/drivers/mfd/retu-mfd.c b/drivers/mfd/retu-mfd.c
> new file mode 100644
> index 0000000..f0097d7
> --- /dev/null
> +++ b/drivers/mfd/retu-mfd.c
> @@ -0,0 +1,114 @@
> +/*
> + * Retu MFD driver
> + *
> + * Copyright (C) 2004, 2005 Nokia Corporation
> + *
> + * Based on code written by Juha Yrjölä, David Weinehall and Mikko Ylinen.
> + * Rewritten to MFD/I2C driver by Aaro Koskinen.
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * 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 <linux/err.h>
> +#include <linux/i2c.h>
> +#include <linux/init.h>
> +#include <linux/slab.h>
> +#include <linux/mutex.h>
> +#include <linux/module.h>
> +#include <linux/mfd/core.h>
> +#include <linux/mfd/retu.h>
> +#include <linux/moduleparam.h>
> +
> +/* Registers */
> +#define RETU_REG_ASICR		0x00		/* ASIC ID and revision */
> +#define RETU_REG_ASICR_VILMA	(1 << 7)	/* Bit indicating Vilma */
> +
> +static struct mfd_cell retu_devs[] = {
> +	{ .name = "retu-wdt" },
> +};
> +
> +int retu_read(struct retu_dev *rdev, u8 reg)
> +{
> +	return i2c_smbus_read_word_data(rdev->i2c, reg);
> +}
> +EXPORT_SYMBOL_GPL(retu_read);
> +
> +int retu_write(struct retu_dev *rdev, u8 reg, u16 data)
> +{
> +	return i2c_smbus_write_word_data(rdev->i2c, reg, data);
> +}
> +EXPORT_SYMBOL_GPL(retu_write);
> +
> +static int __devinit retu_probe(struct i2c_client *i2c,
> +				const struct i2c_device_id *id)
> +{
> +	struct retu_dev *rdev;
> +	int ret;
> +
> +	rdev = kzalloc(sizeof(*rdev), GFP_KERNEL);
> +	if (rdev == NULL)
> +		return -ENOMEM;
> +
> +	i2c_set_clientdata(i2c, rdev);
> +	rdev->dev = &i2c->dev;
> +	rdev->i2c = i2c;
> +
> +	ret = retu_read(rdev, RETU_REG_ASICR);
> +	if (ret < 0) {
> +		dev_err(rdev->dev, "could not read Retu revision: %d\n", ret);
> +		return -EIO;
> +	}
> +
> +	dev_info(rdev->dev, "Retu%s v%d.%d found\n",
> +		 (ret & RETU_REG_ASICR_VILMA) ? " & Vilma" : "",
> +		 (ret >> 4) & 0x7, ret & 0xf);
> +
> +	ret = mfd_add_devices(rdev->dev, -1, retu_devs, ARRAY_SIZE(retu_devs),
> +			      NULL, 0);
> +	if (ret < 0)
> +		goto error;
> +
> +	return ret;
> +
> +error:
> +	kfree(rdev);
> +	return ret;
> +}

looks like this misses the entire irq_chip... maybe on later patches (?)

> +static int __devexit retu_remove(struct i2c_client *i2c)
> +{
> +	struct retu_dev *rdev = i2c_get_clientdata(i2c);
> +
> +	mfd_remove_devices(rdev->dev);
> +	kfree(rdev);
> +
> +	return 0;
> +}
> +
> +static const struct i2c_device_id retu_id[] = {
> +	{ "retu-mfd", 0 },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, retu_id);
> +
> +static struct i2c_driver retu_driver = {
> +	.driver		= {
> +		.name = "retu-mfd",
> +		.owner = THIS_MODULE,
> +	},
> +	.probe		= retu_probe,
> +	.remove		= retu_remove,
> +	.id_table	= retu_id,
> +};
> +module_i2c_driver(retu_driver);
> +
> +MODULE_DESCRIPTION("Retu MFD driver");
> +MODULE_AUTHOR("Aaro Koskinen <aaro.koskinen@iki.fi>");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/mfd/retu.h b/include/linux/mfd/retu.h
> new file mode 100644
> index 0000000..e1b3600
> --- /dev/null
> +++ b/include/linux/mfd/retu.h
> @@ -0,0 +1,20 @@
> +/*
> + * Retu MFD driver interface
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + */
> +
> +#ifndef __LINUX_MFD_RETU_H
> +#define __LINUX_MFD_RETU_H
> +
> +struct retu_dev {
> +	struct device *dev;
> +	struct i2c_client *i2c;
> +};
> +
> +int retu_read(struct retu_dev *, u8);
> +int retu_write(struct retu_dev *, u8, u16);
> +
> +#endif /* __LINUX_MFD_RETU_H */
> -- 
> 1.7.2.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data
  2012-08-28 21:34 ` [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data Aaro Koskinen
  2012-08-29 23:39   ` Tony Lindgren
@ 2012-08-30 15:38   ` Felipe Balbi
  1 sibling, 0 replies; 18+ messages in thread
From: Felipe Balbi @ 2012-08-30 15:38 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

[-- Attachment #1: Type: text/plain, Size: 2153 bytes --]

On Wed, Aug 29, 2012 at 12:34:26AM +0300, Aaro Koskinen wrote:
> Add platform data to enable i2c-cbus on N8x0. It will be I2C bus #3.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>

Acked-by: Felipe Balbi <balbi@ti.com>

> ---
>  arch/arm/mach-omap2/board-n8x0.c |   27 +++++++++++++++++++++++++++
>  1 files changed, 27 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
> index 677357f..8ea0dea 100644
> --- a/arch/arm/mach-omap2/board-n8x0.c
> +++ b/arch/arm/mach-omap2/board-n8x0.c
> @@ -18,6 +18,7 @@
>  #include <linux/io.h>
>  #include <linux/stddef.h>
>  #include <linux/i2c.h>
> +#include <linux/i2c-cbus.h>
>  #include <linux/spi/spi.h>
>  #include <linux/usb/musb.h>
>  #include <sound/tlv320aic3x.h>
> @@ -42,6 +43,31 @@
>  #define TUSB6010_GPIO_ENABLE	0
>  #define TUSB6010_DMACHAN	0x3f
>  
> +#if defined(CONFIG_I2C_CBUS) || defined(CONFIG_I2C_CBUS_MODULE)
> +static struct i2c_cbus_platform_data n8x0_cbus_data = {
> +	.clk_gpio = 66,
> +	.dat_gpio = 65,
> +	.sel_gpio = 64,
> +};
> +
> +static struct platform_device n8x0_cbus_device = {
> +	.name	= "i2c-cbus",
> +	.id	= 3,
> +	.dev	= {
> +		.platform_data = &n8x0_cbus_data,
> +	},
> +};
> +
> +static void __init n8x0_cbus_init(void)
> +{
> +	platform_device_register(&n8x0_cbus_device);
> +}
> +#else /* CONFIG_I2C_CBUS */
> +static void __init n8x0_cbus_init(void)
> +{
> +}
> +#endif /* CONFIG_I2C_CBUS */
> +
>  #if defined(CONFIG_USB_MUSB_TUSB6010) || defined(CONFIG_USB_MUSB_TUSB6010_MODULE)
>  /*
>   * Enable or disable power to TUSB6010. When enabling, turn on 3.3 V and
> @@ -681,6 +707,7 @@ static void __init n8x0_init_machine(void)
>  	gpmc_onenand_init(board_onenand_data);
>  	n8x0_mmc_init();
>  	n8x0_usb_init();
> +	n8x0_cbus_init();
>  }
>  
>  MACHINE_START(NOKIA_N800, "Nokia N800")
> -- 
> 1.7.2.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [RFC PATCH 5/5] arm: omap: n8x0: enable retu
  2012-08-28 21:34 ` [RFC PATCH 5/5] arm: omap: n8x0: enable retu Aaro Koskinen
  2012-08-29 23:40   ` Tony Lindgren
@ 2012-08-30 15:39   ` Felipe Balbi
  1 sibling, 0 replies; 18+ messages in thread
From: Felipe Balbi @ 2012-08-30 15:39 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

[-- Attachment #1: Type: text/plain, Size: 1222 bytes --]

On Wed, Aug 29, 2012 at 12:34:27AM +0300, Aaro Koskinen wrote:
> Add Retu configuration.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>

Acked-by: Felipe Balbi <balbi@ti.com>

> ---
>  arch/arm/mach-omap2/board-n8x0.c |    8 ++++++++
>  1 files changed, 8 insertions(+), 0 deletions(-)
> 
> diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
> index 8ea0dea..6ac8cd9 100644
> --- a/arch/arm/mach-omap2/board-n8x0.c
> +++ b/arch/arm/mach-omap2/board-n8x0.c
> @@ -58,8 +58,16 @@ static struct platform_device n8x0_cbus_device = {
>  	},
>  };
>  
> +static struct i2c_board_info n8x0_i2c_board_info_3[] __initdata = {
> +	{
> +		I2C_BOARD_INFO("retu-mfd", 0x01),
> +	},
> +};
> +
>  static void __init n8x0_cbus_init(void)
>  {
> +	i2c_register_board_info(3, n8x0_i2c_board_info_3,
> +				ARRAY_SIZE(n8x0_i2c_board_info_3));
>  	platform_device_register(&n8x0_cbus_device);
>  }
>  #else /* CONFIG_I2C_CBUS */
> -- 
> 1.7.2.5
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [RFC PATCH 0/5] cbus/retu drivers to mainline
  2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
                   ` (5 preceding siblings ...)
  2012-08-29 23:28 ` [RFC PATCH 0/5] cbus/retu drivers to mainline Tony Lindgren
@ 2012-08-30 15:39 ` Felipe Balbi
  6 siblings, 0 replies; 18+ messages in thread
From: Felipe Balbi @ 2012-08-30 15:39 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

Hi,

On Wed, Aug 29, 2012 at 12:34:22AM +0300, Aaro Koskinen wrote:
> Hi,
> 
> I would like to start converting cbus drivers from linux-omap cbus branch
> for mainline inclusion. Currently e.g. watchdog support is missing at
> least on Nokia N800, so you cannot run the mainline kernel for longer
> than ~60 seconds (and there is no way to disable the watchdog).
> 
> My proposal is to make cbus an i2c bus driver. For other drivers, it
> should be easier to find a proper place in the tree. Here's a first
> quickly made attempt to provide watchdog driver functionality for
> N800. Please comment.
> 
> Aaro Koskinen (5):
>   i2c: introduce i2c-cbus driver
>   mfd: introduce retu-mfd driver
>   watchdog: introduce retu_wdt driver
>   arm: omap: n8x0: add i2c-cbus platform data
>   arm: omap: n8x0: enable retu

Very good to see these going upstream :-)

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

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

* Re: [RFC PATCH 2/5] mfd: introduce retu-mfd driver
  2012-08-28 21:34 ` [RFC PATCH 2/5] mfd: introduce retu-mfd driver Aaro Koskinen
  2012-08-29 23:37   ` Tony Lindgren
  2012-08-30 15:36   ` Felipe Balbi
@ 2012-09-19 15:30   ` Samuel Ortiz
  2 siblings, 0 replies; 18+ messages in thread
From: Samuel Ortiz @ 2012-09-19 15:30 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: linux-omap

Hi Aaro,

On Wed, Aug 29, 2012 at 12:34:24AM +0300, Aaro Koskinen wrote:
> Retu is a multi-function device found on Nokia Internet Tablets
> implementing at least watchdog, RTC, headset detection and power button
> functionality.
> 
> This patch implements a minimum functionality providing only register
> access functions.
> 
> Signed-off-by: Aaro Koskinen <aaro.koskinen@iki.fi>
> Cc: sameo@linux.intel.com
> ---
>  drivers/mfd/Kconfig      |    8 +++
>  drivers/mfd/Makefile     |    1 +
>  drivers/mfd/retu-mfd.c   |  114 ++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/mfd/retu.h |   20 ++++++++
>  4 files changed, 143 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/mfd/retu-mfd.c
>  create mode 100644 include/linux/mfd/retu.h
Besides Felipe's comments, you probably want to use regmap I2C for this
driver.


> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index b1a1462..8ca1270 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -1003,6 +1003,14 @@ config MFD_PALMAS
>  	  If you say yes here you get support for the Palmas
>  	  series of PMIC chips from Texas Instruments.
>  
> +config MFD_RETU
> +	tristate "Support for Retu multi-function device"
> +	select MFD_CORE
> +	depends on I2C
> +	help
> +	  Retu is a multi-function device found on Nokia Internet Tables
> +	  (770, N800 and N810).
Which sub devices does it come with ?

Cheers,
Samuel.

-- 
Intel Open Source Technology Centre
http://oss.intel.com/

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

end of thread, other threads:[~2012-09-19 15:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-28 21:34 [RFC PATCH 0/5] cbus/retu drivers to mainline Aaro Koskinen
2012-08-28 21:34 ` [RFC PATCH 1/5] i2c: introduce i2c-cbus driver Aaro Koskinen
2012-08-29 23:35   ` Tony Lindgren
     [not found]   ` <1346189667-32330-2-git-send-email-aaro.koskinen-X3B1VOXEql0@public.gmane.org>
2012-08-30 15:34     ` Felipe Balbi
2012-08-28 21:34 ` [RFC PATCH 2/5] mfd: introduce retu-mfd driver Aaro Koskinen
2012-08-29 23:37   ` Tony Lindgren
2012-08-30 15:36   ` Felipe Balbi
2012-09-19 15:30   ` Samuel Ortiz
2012-08-28 21:34 ` [RFC PATCH 3/5] watchdog: introduce retu_wdt driver Aaro Koskinen
2012-08-29 23:38   ` Tony Lindgren
2012-08-28 21:34 ` [RFC PATCH 4/5] arm: omap: n8x0: add i2c-cbus platform data Aaro Koskinen
2012-08-29 23:39   ` Tony Lindgren
2012-08-30 15:38   ` Felipe Balbi
2012-08-28 21:34 ` [RFC PATCH 5/5] arm: omap: n8x0: enable retu Aaro Koskinen
2012-08-29 23:40   ` Tony Lindgren
2012-08-30 15:39   ` Felipe Balbi
2012-08-29 23:28 ` [RFC PATCH 0/5] cbus/retu drivers to mainline Tony Lindgren
2012-08-30 15:39 ` Felipe Balbi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).