linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mfd/stmpe: Add SPI interface support
@ 2011-11-08  7:05 Viresh Kumar
  2011-11-08  7:05 ` [PATCH 1/2] mfd/stmpe: separate out controller and interface specific code Viresh Kumar
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Viresh Kumar @ 2011-11-08  7:05 UTC (permalink / raw)
  To: rabin.vincent, linus.walleij, linux-kernel, sameo
  Cc: armando.visconti, shiraz.hashim, vipin.kumar, rajeev-dlh.kumar,
	deepak.sikri, vipulkumar.samar, amit.virdi, viresh.kumar,
	pratyush.anand, bhupesh.sharma, viresh.linux, bhavna.yadav,
	vincenzo.frascino, mirko.gardi, srinidhi.kasagar

Few STMPE controller can have register interface over SPI or I2C. Current
implementation only supports I2C and all code is present in a single file
stmpe.c.

This patchset separates out code into three files
- stmpe: specific to controller only
- stmpe-i2c: specific to i2c interface
- stmpe-spi: specific to spi interface

In order to rebase it cleanly, please apply earlier floated patch 
	"mfd/stmpe: Add support for irq over gpio pin"

Viresh Kumar (2):
  mfd/stmpe: separate out controller and interface specific code
  mfd/stmpe: Add support for SPI interface

 drivers/mfd/Kconfig       |   19 ++++++-
 drivers/mfd/Makefile      |    2 +
 drivers/mfd/stmpe-i2c.c   |  116 +++++++++++++++++++++++++++++++++++
 drivers/mfd/stmpe-spi.c   |  147 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/stmpe.c       |  128 ++++++++++++---------------------------
 drivers/mfd/stmpe.h       |   34 ++++++++++
 include/linux/mfd/stmpe.h |    7 ++-
 7 files changed, 361 insertions(+), 92 deletions(-)
 create mode 100644 drivers/mfd/stmpe-i2c.c
 create mode 100644 drivers/mfd/stmpe-spi.c

-- 
1.7.2.2


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

* [PATCH 1/2] mfd/stmpe: separate out controller and interface specific code
  2011-11-08  7:05 [PATCH 0/2] mfd/stmpe: Add SPI interface support Viresh Kumar
@ 2011-11-08  7:05 ` Viresh Kumar
  2011-11-08  7:05 ` [PATCH 2/2] mfd/stmpe: Add support for SPI interface Viresh Kumar
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Viresh Kumar @ 2011-11-08  7:05 UTC (permalink / raw)
  To: rabin.vincent, linus.walleij, linux-kernel, sameo
  Cc: armando.visconti, shiraz.hashim, vipin.kumar, rajeev-dlh.kumar,
	deepak.sikri, vipulkumar.samar, amit.virdi, viresh.kumar,
	pratyush.anand, bhupesh.sharma, viresh.linux, bhavna.yadav,
	vincenzo.frascino, mirko.gardi, srinidhi.kasagar

Few STMPE controller can have register interface over SPI or I2C. Current
implementation only supports I2C and all code is present in a single file
stmpe.c. It would be better to separate out I2C interface specific code from
controller specific code. Later SPI specific code can be added in a separate
file.

This patch separates out I2C and controller specific code into separate files,
making stmpe.c independent of I2C.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/mfd/Kconfig       |   11 ++++
 drivers/mfd/Makefile      |    1 +
 drivers/mfd/stmpe-i2c.c   |  116 ++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/stmpe.c       |  128 ++++++++++++++-------------------------------
 drivers/mfd/stmpe.h       |   33 ++++++++++++
 include/linux/mfd/stmpe.h |    7 ++-
 6 files changed, 205 insertions(+), 91 deletions(-)
 create mode 100644 drivers/mfd/stmpe-i2c.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index a67adcb..2f8561a 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -293,6 +293,17 @@ config MFD_STMPE
 		Keypad: stmpe-keypad
 		Touchscreen: stmpe-ts
 
+menu "STMPE Interface Drivers"
+depends on MFD_STMPE
+
+config STMPE_I2C
+	bool "STMPE I2C Inteface"
+	depends on I2C
+	default y
+	help
+	  This is used to enable I2C interface of STMPE
+endmenu
+
 config MFD_TC3589X
 	bool "Support Toshiba TC35892 and variants"
 	depends on I2C=y && GENERIC_HARDIRQS
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index c580203..24ee9bb 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_MFD_DM355EVM_MSP)	+= dm355evm_msp.o
 obj-$(CONFIG_MFD_TI_SSP)	+= ti-ssp.o
 
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
+obj-$(CONFIG_STMPE_I2C)		+= stmpe-i2c.o
 obj-$(CONFIG_MFD_TC3589X)	+= tc3589x.o
 obj-$(CONFIG_MFD_T7L66XB)	+= t7l66xb.o tmio_core.o
 obj-$(CONFIG_MFD_TC6387XB)	+= tc6387xb.o tmio_core.o
diff --git a/drivers/mfd/stmpe-i2c.c b/drivers/mfd/stmpe-i2c.c
new file mode 100644
index 0000000..72fa08b
--- /dev/null
+++ b/drivers/mfd/stmpe-i2c.c
@@ -0,0 +1,116 @@
+/*
+ * ST Microelectronics MFD: stmpe's i2c client specific driver
+ *
+ * Copyright (C) ST-Ericsson SA 2010
+ * Copyright (C) ST Microelectronics SA 2011
+ *
+ * License Terms: GNU General Public License, version 2
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ * Author: Viresh Kumar <viresh.kumar@st.com> for ST Microelectronics
+ */
+
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include "stmpe.h"
+
+static int i2c_reg_read(struct stmpe *stmpe, u8 reg)
+{
+	struct i2c_client *i2c = stmpe->client;
+
+	return i2c_smbus_read_byte_data(i2c, reg);
+}
+
+static int i2c_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
+{
+	struct i2c_client *i2c = stmpe->client;
+
+	return i2c_smbus_write_byte_data(i2c, reg, val);
+}
+
+static int i2c_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
+{
+	struct i2c_client *i2c = stmpe->client;
+
+	return i2c_smbus_read_i2c_block_data(i2c, reg, length, values);
+}
+
+static int i2c_block_write(struct stmpe *stmpe, u8 reg, u8 length,
+		const u8 *values)
+{
+	struct i2c_client *i2c = stmpe->client;
+
+	return i2c_smbus_write_i2c_block_data(i2c, reg, length, values);
+}
+
+static void i2c_init(struct stmpe *stmpe)
+{
+	struct i2c_device_id *id = stmpe->ci->data;
+
+	stmpe->partnum = id->driver_data;
+	dev_set_drvdata(stmpe->dev, stmpe);
+}
+
+static struct stmpe_client_info i2c_ci = {
+	.read_byte = i2c_reg_read,
+	.write_byte = i2c_reg_write,
+	.read_block = i2c_block_read,
+	.write_block = i2c_block_write,
+	.init = i2c_init,
+};
+
+static int __devinit
+stmpe_i2c_probe(struct i2c_client *i2c, const struct i2c_device_id *id)
+{
+	i2c_ci.data = (void *)id;
+	i2c_ci.irq = i2c->irq;
+	i2c_ci.client = i2c;
+	i2c_ci.dev = &i2c->dev;
+
+	return stmpe_probe(&i2c_ci);
+}
+
+static int __devexit stmpe_i2c_remove(struct i2c_client *i2c)
+{
+	struct stmpe *stmpe = dev_get_drvdata(&i2c->dev);
+
+	return stmpe_remove(stmpe);
+}
+
+static const struct i2c_device_id stmpe_i2c_id[] = {
+	{ "stmpe811", STMPE811 },
+	{ "stmpe1601", STMPE1601 },
+	{ "stmpe2401", STMPE2401 },
+	{ "stmpe2403", STMPE2403 },
+	{ }
+};
+MODULE_DEVICE_TABLE(i2c, stmpe_id);
+
+static struct i2c_driver stmpe_i2c_driver = {
+	.driver.name	= "stmpe-i2c",
+	.driver.owner	= THIS_MODULE,
+#ifdef CONFIG_PM
+	.driver.pm	= &stmpe_dev_pm_ops,
+#endif
+	.probe		= stmpe_i2c_probe,
+	.remove		= __devexit_p(stmpe_i2c_remove),
+	.id_table	= stmpe_i2c_id,
+};
+
+static int __init stmpe_init(void)
+{
+	return i2c_add_driver(&stmpe_i2c_driver);
+}
+subsys_initcall(stmpe_init);
+
+static void __exit stmpe_exit(void)
+{
+	i2c_del_driver(&stmpe_i2c_driver);
+}
+module_exit(stmpe_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("STMPE MFD core driver");
+MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/mfd/stmpe.c b/drivers/mfd/stmpe.c
index 39efa62..3ff2edb 100644
--- a/drivers/mfd/stmpe.c
+++ b/drivers/mfd/stmpe.c
@@ -1,4 +1,6 @@
 /*
+ * ST Microelectronics MFD: stmpe's driver
+ *
  * Copyright (C) ST-Ericsson SA 2010
  *
  * License Terms: GNU General Public License, version 2
@@ -7,13 +9,11 @@
 
 #include <linux/gpio.h>
 #include <linux/kernel.h>
-#include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/pm.h>
 #include <linux/slab.h>
-#include <linux/i2c.h>
 #include <linux/mfd/core.h>
-#include <linux/mfd/stmpe.h>
 #include "stmpe.h"
 
 static int __stmpe_enable(struct stmpe *stmpe, unsigned int blocks)
@@ -30,10 +30,9 @@ static int __stmpe_reg_read(struct stmpe *stmpe, u8 reg)
 {
 	int ret;
 
-	ret = i2c_smbus_read_byte_data(stmpe->i2c, reg);
+	ret = stmpe->ci->read_byte(stmpe, reg);
 	if (ret < 0)
-		dev_err(stmpe->dev, "failed to read reg %#x: %d\n",
-			reg, ret);
+		dev_err(stmpe->dev, "failed to read reg %#x: %d\n", reg, ret);
 
 	dev_vdbg(stmpe->dev, "rd: reg %#x => data %#x\n", reg, ret);
 
@@ -46,10 +45,9 @@ static int __stmpe_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
 
 	dev_vdbg(stmpe->dev, "wr: reg %#x <= %#x\n", reg, val);
 
-	ret = i2c_smbus_write_byte_data(stmpe->i2c, reg, val);
+	ret = stmpe->ci->write_byte(stmpe, reg, val);
 	if (ret < 0)
-		dev_err(stmpe->dev, "failed to write reg %#x: %d\n",
-			reg, ret);
+		dev_err(stmpe->dev, "failed to write reg %#x: %d\n", reg, ret);
 
 	return ret;
 }
@@ -73,10 +71,9 @@ static int __stmpe_block_read(struct stmpe *stmpe, u8 reg, u8 length,
 {
 	int ret;
 
-	ret = i2c_smbus_read_i2c_block_data(stmpe->i2c, reg, length, values);
+	ret = stmpe->ci->read_block(stmpe, reg, length, values);
 	if (ret < 0)
-		dev_err(stmpe->dev, "failed to read regs %#x: %d\n",
-			reg, ret);
+		dev_err(stmpe->dev, "failed to read regs %#x: %d\n", reg, ret);
 
 	dev_vdbg(stmpe->dev, "rd: reg %#x (%d) => ret %#x\n", reg, length, ret);
 	stmpe_dump_bytes("stmpe rd: ", values, length);
@@ -92,11 +89,9 @@ static int __stmpe_block_write(struct stmpe *stmpe, u8 reg, u8 length,
 	dev_vdbg(stmpe->dev, "wr: regs %#x (%d)\n", reg, length);
 	stmpe_dump_bytes("stmpe wr: ", values, length);
 
-	ret = i2c_smbus_write_i2c_block_data(stmpe->i2c, reg, length,
-					     values);
+	ret = stmpe->ci->write_block(stmpe, reg, length, values);
 	if (ret < 0)
-		dev_err(stmpe->dev, "failed to write regs %#x: %d\n",
-			reg, ret);
+		dev_err(stmpe->dev, "failed to write regs %#x: %d\n", reg, ret);
 
 	return ret;
 }
@@ -874,34 +869,10 @@ static int __devinit stmpe_devices_init(struct stmpe *stmpe)
 	return ret;
 }
 
-#ifdef CONFIG_PM
-static int stmpe_suspend(struct device *dev)
-{
-	struct i2c_client *i2c = to_i2c_client(dev);
-	struct stmpe *stmpe = i2c_get_clientdata(i2c);
-
-	if (device_may_wakeup(&i2c->dev))
-		enable_irq_wake(stmpe->irq);
-
-	return 0;
-}
-
-static int stmpe_resume(struct device *dev)
+/* Called from client specific probe routines */
+int stmpe_probe(struct stmpe_client_info *ci)
 {
-	struct i2c_client *i2c = to_i2c_client(dev);
-	struct stmpe *stmpe = i2c_get_clientdata(i2c);
-
-	if (device_may_wakeup(&i2c->dev))
-		disable_irq_wake(stmpe->irq);
-
-	return 0;
-}
-#endif
-
-static int __devinit stmpe_probe(struct i2c_client *i2c,
-				 const struct i2c_device_id *id)
-{
-	struct stmpe_platform_data *pdata = i2c->dev.platform_data;
+	struct stmpe_platform_data *pdata = dev_get_platdata(ci->dev);
 	struct stmpe *stmpe;
 	int ret;
 
@@ -915,18 +886,16 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
 	mutex_init(&stmpe->irq_lock);
 	mutex_init(&stmpe->lock);
 
-	stmpe->dev = &i2c->dev;
-	stmpe->i2c = i2c;
-
+	stmpe->dev = ci->dev;
+	stmpe->client = ci->client;
 	stmpe->pdata = pdata;
 	stmpe->irq_base = pdata->irq_base;
-
-	stmpe->partnum = id->driver_data;
+	stmpe->ci = ci;
 	stmpe->variant = stmpe_variant_info[stmpe->partnum];
 	stmpe->regs = stmpe->variant->regs;
 	stmpe->num_gpios = stmpe->variant->num_gpios;
 
-	i2c_set_clientdata(i2c, stmpe);
+	ci->init(stmpe);
 
 	if (pdata->irq_over_gpio) {
 		ret = gpio_request_one(pdata->irq_gpio, GPIOF_DIR_IN, "stmpe");
@@ -938,7 +907,7 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
 
 		stmpe->irq = gpio_to_irq(pdata->irq_gpio);
 	} else {
-		stmpe->irq = i2c->irq;
+		stmpe->irq = ci->irq;
 	}
 
 	ret = stmpe_chip_init(stmpe);
@@ -950,8 +919,7 @@ static int __devinit stmpe_probe(struct i2c_client *i2c,
 		goto free_gpio;
 
 	ret = request_threaded_irq(stmpe->irq, NULL, stmpe_irq,
-				   pdata->irq_trigger | IRQF_ONESHOT,
-				   "stmpe", stmpe);
+			pdata->irq_trigger | IRQF_ONESHOT, "stmpe", stmpe);
 	if (ret) {
 		dev_err(stmpe->dev, "failed to request IRQ: %d\n", ret);
 		goto out_removeirq;
@@ -978,10 +946,8 @@ out_free:
 	return ret;
 }
 
-static int __devexit stmpe_remove(struct i2c_client *client)
+int stmpe_remove(struct stmpe *stmpe)
 {
-	struct stmpe *stmpe = i2c_get_clientdata(client);
-
 	mfd_remove_devices(stmpe->dev);
 
 	free_irq(stmpe->irq, stmpe);
@@ -995,45 +961,29 @@ static int __devexit stmpe_remove(struct i2c_client *client)
 	return 0;
 }
 
-static const struct i2c_device_id stmpe_id[] = {
-	{ "stmpe811", STMPE811 },
-	{ "stmpe1601", STMPE1601 },
-	{ "stmpe2401", STMPE2401 },
-	{ "stmpe2403", STMPE2403 },
-	{ }
-};
-MODULE_DEVICE_TABLE(i2c, stmpe_id);
-
 #ifdef CONFIG_PM
-static const struct dev_pm_ops stmpe_dev_pm_ops = {
-	.suspend	= stmpe_suspend,
-	.resume		= stmpe_resume,
-};
-#endif
+static int stmpe_suspend(struct device *dev)
+{
+	struct stmpe *stmpe = dev_get_drvdata(dev);
 
-static struct i2c_driver stmpe_driver = {
-	.driver.name	= "stmpe",
-	.driver.owner	= THIS_MODULE,
-#ifdef CONFIG_PM
-	.driver.pm	= &stmpe_dev_pm_ops,
-#endif
-	.probe		= stmpe_probe,
-	.remove		= __devexit_p(stmpe_remove),
-	.id_table	= stmpe_id,
-};
+	if (device_may_wakeup(dev))
+		enable_irq_wake(stmpe->irq);
 
-static int __init stmpe_init(void)
-{
-	return i2c_add_driver(&stmpe_driver);
+	return 0;
 }
-subsys_initcall(stmpe_init);
 
-static void __exit stmpe_exit(void)
+static int stmpe_resume(struct device *dev)
 {
-	i2c_del_driver(&stmpe_driver);
+	struct stmpe *stmpe = dev_get_drvdata(dev);
+
+	if (device_may_wakeup(dev))
+		disable_irq_wake(stmpe->irq);
+
+	return 0;
 }
-module_exit(stmpe_exit);
 
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("STMPE MFD core driver");
-MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
+const struct dev_pm_ops stmpe_dev_pm_ops = {
+	.suspend	= stmpe_suspend,
+	.resume		= stmpe_resume,
+};
+#endif
diff --git a/drivers/mfd/stmpe.h b/drivers/mfd/stmpe.h
index e4ee3895..c716044 100644
--- a/drivers/mfd/stmpe.h
+++ b/drivers/mfd/stmpe.h
@@ -8,6 +8,14 @@
 #ifndef __STMPE_H
 #define __STMPE_H
 
+#include <linux/device.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/stmpe.h>
+#include <linux/printk.h>
+#include <linux/types.h>
+
+extern const struct dev_pm_ops stmpe_dev_pm_ops;
+
 #ifdef STMPE_DUMP_BYTES
 static inline void stmpe_dump_bytes(const char *str, const void *buf,
 				    size_t len)
@@ -67,6 +75,31 @@ struct stmpe_variant_info {
 	int (*enable_autosleep)(struct stmpe *stmpe, int autosleep_timeout);
 };
 
+/**
+ * struct stmpe_client_info - i2c or spi specific routines/info
+ * @data: client specific data
+ * @read_byte: read single byte
+ * @write_byte: write single byte
+ * @read_block: read block or multiple bytes
+ * @write_block: write block or multiple bytes
+ * @init: client init routine, called during probe
+ */
+struct stmpe_client_info {
+	void *data;
+	int irq;
+	void *client;
+	struct device *dev;
+	int (*read_byte)(struct stmpe *stmpe, u8 reg);
+	int (*write_byte)(struct stmpe *stmpe, u8 reg, u8 val);
+	int (*read_block)(struct stmpe *stmpe, u8 reg, u8 len, u8 *values);
+	int (*write_block)(struct stmpe *stmpe, u8 reg, u8 len,
+			const u8 *values);
+	void (*init)(struct stmpe *stmpe);
+};
+
+int stmpe_probe(struct stmpe_client_info *ci);
+int stmpe_remove(struct stmpe *stmpe);
+
 #define STMPE_ICR_LSB_HIGH	(1 << 2)
 #define STMPE_ICR_LSB_EDGE	(1 << 1)
 #define STMPE_ICR_LSB_GIM	(1 << 0)
diff --git a/include/linux/mfd/stmpe.h b/include/linux/mfd/stmpe.h
index 270d661..babc6b2 100644
--- a/include/linux/mfd/stmpe.h
+++ b/include/linux/mfd/stmpe.h
@@ -50,13 +50,15 @@ enum {
 
 
 struct stmpe_variant_info;
+struct stmpe_client_info;
 
 /**
  * struct stmpe - STMPE MFD structure
  * @lock: lock protecting I/O operations
  * @irq_lock: IRQ bus lock
  * @dev: device, mostly for dev_dbg()
- * @i2c: i2c client
+ * @client: client - i2c or spi
+ * @ci: client specific information
  * @partnum: part number
  * @variant: the detected STMPE model number
  * @regs: list of addresses of registers which are at different addresses on
@@ -72,7 +74,8 @@ struct stmpe {
 	struct mutex lock;
 	struct mutex irq_lock;
 	struct device *dev;
-	struct i2c_client *i2c;
+	void *client;
+	struct stmpe_client_info *ci;
 	enum stmpe_partnum partnum;
 	struct stmpe_variant_info *variant;
 	const u8 *regs;
-- 
1.7.2.2


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

* [PATCH 2/2] mfd/stmpe: Add support for SPI interface
  2011-11-08  7:05 [PATCH 0/2] mfd/stmpe: Add SPI interface support Viresh Kumar
  2011-11-08  7:05 ` [PATCH 1/2] mfd/stmpe: separate out controller and interface specific code Viresh Kumar
@ 2011-11-08  7:05 ` Viresh Kumar
  2011-11-08  8:43 ` [PATCH 0/2] mfd/stmpe: Add SPI interface support Linus Walleij
  2011-11-11  9:43 ` Rabin Vincent
  3 siblings, 0 replies; 10+ messages in thread
From: Viresh Kumar @ 2011-11-08  7:05 UTC (permalink / raw)
  To: rabin.vincent, linus.walleij, linux-kernel, sameo
  Cc: armando.visconti, shiraz.hashim, vipin.kumar, rajeev-dlh.kumar,
	deepak.sikri, vipulkumar.samar, amit.virdi, viresh.kumar,
	pratyush.anand, bhupesh.sharma, viresh.linux, bhavna.yadav,
	vincenzo.frascino, mirko.gardi, srinidhi.kasagar

Few STMPE controller can have register interface over SPI or I2C. Current
implementation only supports I2C.

This patch adds support for SPI interface for accessing STMPE's address space.

Signed-off-by: Viresh Kumar <viresh.kumar@st.com>
---
 drivers/mfd/Kconfig     |    8 ++-
 drivers/mfd/Makefile    |    1 +
 drivers/mfd/stmpe-spi.c |  147 +++++++++++++++++++++++++++++++++++++++++++++++
 drivers/mfd/stmpe.h     |    1 +
 4 files changed, 156 insertions(+), 1 deletions(-)
 create mode 100644 drivers/mfd/stmpe-spi.c

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 2f8561a..ebfb296 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -272,7 +272,7 @@ config TWL6040_CORE
 
 config MFD_STMPE
 	bool "Support STMicroelectronics STMPE"
-	depends on I2C=y && GENERIC_HARDIRQS
+	depends on (I2C=y || SPI_MASTER=y) && GENERIC_HARDIRQS
 	select MFD_CORE
 	help
 	  Support for the STMPE family of I/O Expanders from
@@ -302,6 +302,12 @@ config STMPE_I2C
 	default y
 	help
 	  This is used to enable I2C interface of STMPE
+
+config STMPE_SPI
+	bool "STMPE SPI Inteface"
+	depends on SPI_MASTER
+	help
+	  This is used to enable SPI interface of STMPE
 endmenu
 
 config MFD_TC3589X
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 24ee9bb..eac1e9f 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_MFD_TI_SSP)	+= ti-ssp.o
 
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
 obj-$(CONFIG_STMPE_I2C)		+= stmpe-i2c.o
+obj-$(CONFIG_STMPE_SPI)		+= stmpe-spi.o
 obj-$(CONFIG_MFD_TC3589X)	+= tc3589x.o
 obj-$(CONFIG_MFD_T7L66XB)	+= t7l66xb.o tmio_core.o
 obj-$(CONFIG_MFD_TC6387XB)	+= tc6387xb.o tmio_core.o
diff --git a/drivers/mfd/stmpe-spi.c b/drivers/mfd/stmpe-spi.c
new file mode 100644
index 0000000..6f1c0ad3
--- /dev/null
+++ b/drivers/mfd/stmpe-spi.c
@@ -0,0 +1,147 @@
+/*
+ * ST Microelectronics MFD: stmpe's spi client specific driver
+ *
+ * Copyright (C) ST Microelectronics SA 2011
+ *
+ * License Terms: GNU General Public License, version 2
+ * Author: Viresh Kumar <viresh.kumar@st.com> for ST Microelectronics
+ */
+
+#include <linux/spi/spi.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/types.h>
+#include "stmpe.h"
+
+#define READ_CMD	(1 << 7)
+
+static int spi_reg_read(struct stmpe *stmpe, u8 reg)
+{
+	struct spi_device *spi = stmpe->client;
+	int status = spi_w8r16(spi, reg | READ_CMD);
+
+	return (status < 0) ? status : status >> 8;
+}
+
+static int spi_reg_write(struct stmpe *stmpe, u8 reg, u8 val)
+{
+	struct spi_device *spi = stmpe->client;
+	u16 cmd = (val << 8) | reg;
+
+	return spi_write(spi, (const u8 *)&cmd, 2);
+}
+
+static int spi_block_read(struct stmpe *stmpe, u8 reg, u8 length, u8 *values)
+{
+	int ret, i;
+
+	for (i = 0; i < length; i++) {
+		ret = spi_reg_read(stmpe, reg + i);
+		if (ret < 0)
+			return ret;
+		*(values + i) = ret;
+	}
+
+	return 0;
+}
+
+static int spi_block_write(struct stmpe *stmpe, u8 reg, u8 length,
+		const u8 *values)
+{
+	int ret = 0, i;
+
+	for (i = length; i > 0; i--, reg++) {
+		ret = spi_reg_write(stmpe, reg, *(values + i - 1));
+		if (ret < 0)
+			return ret;
+	}
+
+	return ret;
+}
+
+static void spi_init(struct stmpe *stmpe)
+{
+	struct spi_device *spi = stmpe->client;
+
+	dev_set_drvdata(stmpe->dev, stmpe);
+	spi->bits_per_word = 8;
+
+	/* This register is only present for stmpe811 */
+	if (stmpe->variant->id_val == 0x0811)
+		spi_reg_write(stmpe, STMPE811_REG_SPI_CFG, spi->mode);
+
+	if (spi_setup(spi) < 0)
+		dev_dbg(&spi->dev, "spi_setup failed\n");
+}
+
+static struct stmpe_client_info spi_ci = {
+	.read_byte = spi_reg_read,
+	.write_byte = spi_reg_write,
+	.read_block = spi_block_read,
+	.write_block = spi_block_write,
+	.init = spi_init,
+};
+
+static int __devinit
+stmpe_spi_probe(struct spi_device *spi)
+{
+	/* don't exceed max specified rate - 1MHz - Limitation of STMPE */
+	if (spi->max_speed_hz > 1000000) {
+		dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
+				(spi->max_speed_hz/1000));
+		return -EINVAL;
+	}
+
+	spi_ci.irq = spi->irq;
+	spi_ci.client = spi;
+	spi_ci.dev = &spi->dev;
+
+	return stmpe_probe(&spi_ci);
+}
+
+static int __devexit stmpe_spi_remove(struct spi_device *spi)
+{
+	struct stmpe *stmpe = dev_get_drvdata(&spi->dev);
+
+	return stmpe_remove(stmpe);
+}
+
+static const struct spi_device_id stmpe_spi_id[] = {
+	{ "stmpe811", STMPE811 },
+	{ "stmpe1601", STMPE1601 },
+	{ "stmpe2401", STMPE2401 },
+	{ "stmpe2403", STMPE2403 },
+	{ }
+};
+MODULE_DEVICE_TABLE(spi, stmpe_id);
+
+static struct spi_driver stmpe_spi_driver = {
+	.driver = {
+		.name	= "stmpe-spi",
+		.bus	= &spi_bus_type,
+		.owner	= THIS_MODULE,
+#ifdef CONFIG_PM
+		.pm	= &stmpe_dev_pm_ops,
+#endif
+	},
+	.probe		= stmpe_spi_probe,
+	.remove		= __devexit_p(stmpe_spi_remove),
+	.id_table	= stmpe_spi_id,
+};
+
+static int __init stmpe_init(void)
+{
+	return spi_register_driver(&stmpe_spi_driver);
+}
+subsys_initcall(stmpe_init);
+
+static void __exit stmpe_exit(void)
+{
+	spi_unregister_driver(&stmpe_spi_driver);
+}
+module_exit(stmpe_exit);
+
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("STMPE MFD core driver");
+MODULE_AUTHOR("Rabin Vincent <rabin.vincent@stericsson.com>");
diff --git a/drivers/mfd/stmpe.h b/drivers/mfd/stmpe.h
index c716044..908f482 100644
--- a/drivers/mfd/stmpe.h
+++ b/drivers/mfd/stmpe.h
@@ -120,6 +120,7 @@ int stmpe_remove(struct stmpe *stmpe);
 
 #define STMPE811_REG_CHIP_ID		0x00
 #define STMPE811_REG_SYS_CTRL2		0x04
+#define STMPE811_REG_SPI_CFG		0x08
 #define STMPE811_REG_INT_CTRL		0x09
 #define STMPE811_REG_INT_EN		0x0A
 #define STMPE811_REG_INT_STA		0x0B
-- 
1.7.2.2


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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-11-08  7:05 [PATCH 0/2] mfd/stmpe: Add SPI interface support Viresh Kumar
  2011-11-08  7:05 ` [PATCH 1/2] mfd/stmpe: separate out controller and interface specific code Viresh Kumar
  2011-11-08  7:05 ` [PATCH 2/2] mfd/stmpe: Add support for SPI interface Viresh Kumar
@ 2011-11-08  8:43 ` Linus Walleij
  2011-11-11  9:43 ` Rabin Vincent
  3 siblings, 0 replies; 10+ messages in thread
From: Linus Walleij @ 2011-11-08  8:43 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: rabin.vincent, linus.walleij, linux-kernel, sameo,
	armando.visconti, shiraz.hashim, vipin.kumar, rajeev-dlh.kumar,
	deepak.sikri, vipulkumar.samar, amit.virdi, pratyush.anand,
	bhupesh.sharma, viresh.linux, bhavna.yadav, vincenzo.frascino,
	mirko.gardi, srinidhi.kasagar

On Tue, Nov 8, 2011 at 8:05 AM, Viresh Kumar <viresh.kumar@st.com> wrote:

> Few STMPE controller can have register interface over SPI or I2C. Current
> implementation only supports I2C and all code is present in a single file
> stmpe.c.
>
> This patchset separates out code into three files
> - stmpe: specific to controller only
> - stmpe-i2c: specific to i2c interface
> - stmpe-spi: specific to spi interface
>
> In order to rebase it cleanly, please apply earlier floated patch
>        "mfd/stmpe: Add support for irq over gpio pin"

Patches look clean and nice to me.
Acked-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-11-08  7:05 [PATCH 0/2] mfd/stmpe: Add SPI interface support Viresh Kumar
                   ` (2 preceding siblings ...)
  2011-11-08  8:43 ` [PATCH 0/2] mfd/stmpe: Add SPI interface support Linus Walleij
@ 2011-11-11  9:43 ` Rabin Vincent
  2011-11-11 10:29   ` Viresh Kumar
  3 siblings, 1 reply; 10+ messages in thread
From: Rabin Vincent @ 2011-11-11  9:43 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: linus.walleij, linux-kernel, sameo, armando.visconti,
	shiraz.hashim, vipin.kumar, rajeev-dlh.kumar, deepak.sikri,
	vipulkumar.samar, amit.virdi, pratyush.anand, bhupesh.sharma,
	viresh.linux, bhavna.yadav, vincenzo.frascino, mirko.gardi,
	srinidhi.kasagar

On Tue, Nov 8, 2011 at 12:35, Viresh Kumar <viresh.kumar@st.com> wrote:
> Few STMPE controller can have register interface over SPI or I2C. Current
> implementation only supports I2C and all code is present in a single file
> stmpe.c.
>
> This patchset separates out code into three files
> - stmpe: specific to controller only
> - stmpe-i2c: specific to i2c interface
> - stmpe-spi: specific to spi interface
>
> In order to rebase it cleanly, please apply earlier floated patch
>        "mfd/stmpe: Add support for irq over gpio pin"
>
> Viresh Kumar (2):
>  mfd/stmpe: separate out controller and interface specific code
>  mfd/stmpe: Add support for SPI interface

Could you instead convert stmpe to use the register map API, and then
add the SPI interface?  Converting to regmap should both simplify the
existing code as well as make it possible to add the second interface
with fewer lines of code.

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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-11-11  9:43 ` Rabin Vincent
@ 2011-11-11 10:29   ` Viresh Kumar
  2011-11-11 11:32     ` Rabin Vincent
  0 siblings, 1 reply; 10+ messages in thread
From: Viresh Kumar @ 2011-11-11 10:29 UTC (permalink / raw)
  To: Rabin Vincent
  Cc: Linus WALLEIJ, linux-kernel, sameo, Armando VISCONTI,
	Shiraz HASHIM, Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI,
	Vipul Kumar SAMAR, Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
	viresh.linux, Bhavna YADAV, Vincenzo FRASCINO, Mirko GARDI,
	Srinidhi KASAGAR

On 11/11/2011 3:13 PM, Rabin Vincent wrote:
> Could you instead convert stmpe to use the register map API, and then
> add the SPI interface?  Converting to regmap should both simplify the
> existing code as well as make it possible to add the second interface
> with fewer lines of code.

Sorry Rabin, but i couldn't get your comment completely. :(
Can you please spend few lines on "what do you mean by register map API"?

-- 
viresh

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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-11-11 10:29   ` Viresh Kumar
@ 2011-11-11 11:32     ` Rabin Vincent
  2011-11-11 11:37       ` Viresh Kumar
  0 siblings, 1 reply; 10+ messages in thread
From: Rabin Vincent @ 2011-11-11 11:32 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Linus WALLEIJ, linux-kernel, sameo, Armando VISCONTI,
	Shiraz HASHIM, Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI,
	Vipul Kumar SAMAR, Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
	viresh.linux, Bhavna YADAV, Vincenzo FRASCINO, Mirko GARDI,
	Srinidhi KASAGAR

On Fri, Nov 11, 2011 at 15:59, Viresh Kumar <viresh.kumar@st.com> wrote:
> On 11/11/2011 3:13 PM, Rabin Vincent wrote:
>> Could you instead convert stmpe to use the register map API, and then
>> add the SPI interface?  Converting to regmap should both simplify the
>> existing code as well as make it possible to add the second interface
>> with fewer lines of code.
>
> Sorry Rabin, but i couldn't get your comment completely. :(
> Can you please spend few lines on "what do you mean by register map API"?

drivers/base/regmap, added in b83a313bf25 ("regmap: Add generic
non-memory mapped register access API").

Several MFDs are already using it (git grep regmap drivers/mfd/), and
patches to convert more are making the rounds on the lists.

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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-11-11 11:32     ` Rabin Vincent
@ 2011-11-11 11:37       ` Viresh Kumar
  2011-12-12 11:36         ` Samuel Ortiz
  0 siblings, 1 reply; 10+ messages in thread
From: Viresh Kumar @ 2011-11-11 11:37 UTC (permalink / raw)
  To: Rabin Vincent
  Cc: Linus WALLEIJ, linux-kernel, sameo, Armando VISCONTI,
	Shiraz HASHIM, Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI,
	Vipul Kumar SAMAR, Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
	viresh.linux, Bhavna YADAV, Vincenzo FRASCINO, Mirko GARDI,
	Srinidhi KASAGAR

On 11/11/2011 5:02 PM, Rabin Vincent wrote:
> On Fri, Nov 11, 2011 at 15:59, Viresh Kumar <viresh.kumar@st.com> wrote:
>> On 11/11/2011 3:13 PM, Rabin Vincent wrote:
>>> Could you instead convert stmpe to use the register map API, and then
>>> add the SPI interface?  Converting to regmap should both simplify the
>>> existing code as well as make it possible to add the second interface
>>> with fewer lines of code.
>>
>> Sorry Rabin, but i couldn't get your comment completely. :(
>> Can you please spend few lines on "what do you mean by register map API"?
> 
> drivers/base/regmap, added in b83a313bf25 ("regmap: Add generic
> non-memory mapped register access API").
> 
> Several MFDs are already using it (git grep regmap drivers/mfd/), and
> patches to convert more are making the rounds on the lists.

Ok. Got it now. :)

Can we get this patchset pushed as it is and i will do this regmap stuff
later in a separate patchset? Actually i am a bit busy currently with
some other activities and can come back to it after some time.

-- 
viresh

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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-11-11 11:37       ` Viresh Kumar
@ 2011-12-12 11:36         ` Samuel Ortiz
  2011-12-12 11:48           ` Viresh Kumar
  0 siblings, 1 reply; 10+ messages in thread
From: Samuel Ortiz @ 2011-12-12 11:36 UTC (permalink / raw)
  To: Viresh Kumar
  Cc: Rabin Vincent, Linus WALLEIJ, linux-kernel, Armando VISCONTI,
	Shiraz HASHIM, Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI,
	Vipul Kumar SAMAR, Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
	viresh.linux, Bhavna YADAV, Vincenzo FRASCINO, Mirko GARDI,
	Srinidhi KASAGAR

Hi Viresh,

On Fri, Nov 11, 2011 at 05:07:11PM +0530, Viresh Kumar wrote:
> On 11/11/2011 5:02 PM, Rabin Vincent wrote:
> > On Fri, Nov 11, 2011 at 15:59, Viresh Kumar <viresh.kumar@st.com> wrote:
> >> On 11/11/2011 3:13 PM, Rabin Vincent wrote:
> >>> Could you instead convert stmpe to use the register map API, and then
> >>> add the SPI interface?  Converting to regmap should both simplify the
> >>> existing code as well as make it possible to add the second interface
> >>> with fewer lines of code.
> >>
> >> Sorry Rabin, but i couldn't get your comment completely. :(
> >> Can you please spend few lines on "what do you mean by register map API"?
> > 
> > drivers/base/regmap, added in b83a313bf25 ("regmap: Add generic
> > non-memory mapped register access API").
> > 
> > Several MFDs are already using it (git grep regmap drivers/mfd/), and
> > patches to convert more are making the rounds on the lists.
> 
> Ok. Got it now. :)
> 
> Can we get this patchset pushed as it is and i will do this regmap stuff
> later in a separate patchset? Actually i am a bit busy currently with
> some other activities and can come back to it after some time.
Ok, but I really hope you will be able to get back at it. I applied your
patchset to my for-next branch for now.

Cheers,
Samuel.

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

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

* Re: [PATCH 0/2] mfd/stmpe: Add SPI interface support
  2011-12-12 11:36         ` Samuel Ortiz
@ 2011-12-12 11:48           ` Viresh Kumar
  0 siblings, 0 replies; 10+ messages in thread
From: Viresh Kumar @ 2011-12-12 11:48 UTC (permalink / raw)
  To: Samuel Ortiz
  Cc: Rabin Vincent, Linus WALLEIJ, linux-kernel, Armando VISCONTI,
	Shiraz HASHIM, Vipin KUMAR, Rajeev KUMAR, Deepak SIKRI,
	Vipul Kumar SAMAR, Amit VIRDI, Pratyush ANAND, Bhupesh SHARMA,
	viresh.linux, Bhavna YADAV, Vincenzo FRASCINO, Mirko GARDI,
	Srinidhi KASAGAR

On 12/12/2011 5:06 PM, Samuel Ortiz wrote:
> Ok, but I really hope you will be able to get back at it. I applied your
> patchset to my for-next branch for now.

I will surely like to do it as soon as i get some time.

-- 
viresh

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

end of thread, other threads:[~2011-12-12 11:48 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-08  7:05 [PATCH 0/2] mfd/stmpe: Add SPI interface support Viresh Kumar
2011-11-08  7:05 ` [PATCH 1/2] mfd/stmpe: separate out controller and interface specific code Viresh Kumar
2011-11-08  7:05 ` [PATCH 2/2] mfd/stmpe: Add support for SPI interface Viresh Kumar
2011-11-08  8:43 ` [PATCH 0/2] mfd/stmpe: Add SPI interface support Linus Walleij
2011-11-11  9:43 ` Rabin Vincent
2011-11-11 10:29   ` Viresh Kumar
2011-11-11 11:32     ` Rabin Vincent
2011-11-11 11:37       ` Viresh Kumar
2011-12-12 11:36         ` Samuel Ortiz
2011-12-12 11:48           ` Viresh Kumar

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).