Skip to contentSkip to conversation

tnetv107x ssp drivers

PATCH Superseded Cyril Chemparathy 8 participants 37 messages Nov 15, 2010 – Nov 25, 2010

Subsystems (8)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover tnetv107x ssp drivers

TI's sequencer serial port (TI-SSP) is a jack-of-all-trades type of serial port device. It has a built-in programmable execution engine that can be programmed to operate as almost any serial bus (I2C, SPI, EasyScale, and others).

This patch series implements a driver stack that looks like the following:

                             +--------+
                             | eeprom | . . .
                             +--------+
   +-----------+             +--------------+ +---------+
   | regulator | . . .       |   i2c-gpio   | | 1-wire  | . . .
   +-----------+             +--------------+ +---------+
   +----------------------+  +--------------------------------+
   |       ssp-spi        |  |           ssp-gpio             |
   +----------------------+  +--------------------------------+
   +----------------------------------------------------------+
   |                            ssp                           |
   +----------------------------------------------------------+

Changes between v5 and v4 of this series:
- Moved drivers from misc/gpio/spi to mfd
- Removed implicit init-time iosel setup
- Minor cleanups in backlight driver

Changes between v3 and v4 of this series:
- Replaced polled wait for sequence termination with interrupt
- Improved locking within SSP driver
- Other minor cleanups

Changes between v2 and v3 of this series:
- Minor cleanups in Kconfig and Makefile ordering

Changes between v1 and v2 of this series:
- Replaced open()/close() semantics with dynamic platform_device registration on SSP probe.
- Removed user-land interface to regulator registers
- More sensible regulator constraints
- Other minor cleanups

Cyril Chemparathy (12):
misc: add driver for sequencer serial port
davinci: add tnetv107x ssp platform device
davinci: add ssp config for tnetv107x evm board
spi: add ti-ssp spi master driver
davinci: add spi devices on tnetv107x evm
regulator: add driver for tps6524x regulator
davinci: add tnetv107x evm regulators
gpio: add ti-ssp gpio driver
davinci: add tnetv107x evm ti-ssp gpio device
backlight: add support for tps6116x controller
davinci: add tnetv107x evm backlight device
davinci: add tnetv107x evm i2c eeprom device

 arch/arm/mach-davinci/board-tnetv107x-evm.c    |  192 +++++++
 arch/arm/mach-davinci/devices-tnetv107x.c      |   25 +
 arch/arm/mach-davinci/include/mach/tnetv107x.h |    2 +
 arch/arm/mach-davinci/tnetv107x.c              |    2 +-
 drivers/mfd/Kconfig                            |   31 +
 drivers/mfd/Makefile                           |    3 +
 drivers/mfd/ti-ssp-gpio.c                      |  205 +++++++
 drivers/mfd/ti-ssp-spi.c                       |  402 ++++++++++++++
 drivers/mfd/ti-ssp.c                           |  475 ++++++++++++++++
 drivers/regulator/Kconfig                      |   10 +
 drivers/regulator/Makefile                     |    1 +
 drivers/regulator/tps6524x-regulator.c         |  692 ++++++++++++++++++++++++
 drivers/video/backlight/Kconfig                |    7 +
 drivers/video/backlight/Makefile               |    2 +-
 drivers/video/backlight/tps6116x.c             |  339 ++++++++++++
 include/linux/mfd/ti_ssp.h                     |   97 ++++
 16 files changed, 2483 insertions(+), 2 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp-gpio.c
 create mode 100644 drivers/mfd/ti-ssp-spi.c
 create mode 100644 drivers/mfd/ti-ssp.c
 create mode 100644 drivers/regulator/tps6524x-regulator.c
 create mode 100644 drivers/video/backlight/tps6116x.c
 create mode 100644 include/linux/mfd/ti_ssp.h
#1 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

TI's sequencer serial port (TI-SSP) is a jack-of-all-trades type of serial port device. It has a built-in programmable execution engine that can be programmed to operate as almost any serial bus (I2C, SPI, EasyScale, and others).

This patch adds a driver for this controller device. The driver does not expose a user-land interface. Protocol drivers built on top of this layer are expected to remain in-kernel.

---
 drivers/mfd/Kconfig        |   11 +
 drivers/mfd/Makefile       |    1 +
 drivers/mfd/ti-ssp.c       |  475 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ti_ssp.h |   87 ++++++++
 4 files changed, 574 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp.c
 create mode 100644 include/linux/mfd/ti_ssp.h
drivers/mfd/Kconfig +11 -0
index db51ea1..6bedf53 100644
@@ -81,6 +81,17 @@ config MFD_DM355EVM_MSP
 	  boards.  MSP430 firmware manages resets and power sequencing,
 	  inputs from buttons and the IR remote, LEDs, an RTC, and more.
 
+config MFD_TI_SSP
+	tristate "TI Sequencer Serial Port support"
+	depends on ARCH_DAVINCI_TNETV107X
+	select MFD_CORE
+	---help---
+	  Say Y here if you want support for the Sequencer Serial Port
+	  in a Texas Instruments TNETV107X SoC.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ti-ssp.
+
 config HTC_EGPIO
 	bool "HTC EGPIO support"
 	depends on GENERIC_HARDIRQS && GPIOLIB && ARM
drivers/mfd/Makefile +1 -0
index feaeeae..098a932 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_HTC_I2CPLD)	+= htc-i2cpld.o
 
 obj-$(CONFIG_MFD_DAVINCI_VOICECODEC)	+= davinci_voicecodec.o
 obj-$(CONFIG_MFD_DM355EVM_MSP)	+= dm355evm_msp.o
+obj-$(CONFIG_MFD_TI_SSP)	+= ti-ssp.o
 
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
 obj-$(CONFIG_MFD_TC35892)	+= tc35892.o
drivers/mfd/ti-ssp.c new file +475 -0

475 lines not on this page · raw message

include/linux/mfd/ti_ssp.h new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

Quoted 146 lines · Cyril Chemparathy

TI's sequencer serial port (TI-SSP) is a jack-of-all-trades type of serial port device. It has a built-in programmable execution engine that can be programmed to operate as almost any serial bus (I2C, SPI, EasyScale, and others).

This patch adds a driver for this controller device. The driver does not expose a user-land interface. Protocol drivers built on top of this layer are expected to remain in-kernel.

---
 drivers/mfd/Kconfig        |   11 +
 drivers/mfd/Makefile       |    1 +
 drivers/mfd/ti-ssp.c       |  475 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ti_ssp.h |   87 ++++++++
 4 files changed, 574 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp.c
 create mode 100644 include/linux/mfd/ti_ssp.h
drivers/mfd/Kconfig +11 -0
index db51ea1..6bedf53 100644
@@ -81,6 +81,17 @@ config MFD_DM355EVM_MSP
 	  boards.  MSP430 firmware manages resets and power sequencing,
 	  inputs from buttons and the IR remote, LEDs, an RTC, and more.
 
+config MFD_TI_SSP
+	tristate "TI Sequencer Serial Port support"
+	depends on ARCH_DAVINCI_TNETV107X
+	select MFD_CORE
+	---help---
+	  Say Y here if you want support for the Sequencer Serial Port
+	  in a Texas Instruments TNETV107X SoC.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ti-ssp.
+
 config HTC_EGPIO
 	bool "HTC EGPIO support"
 	depends on GENERIC_HARDIRQS && GPIOLIB && ARM
drivers/mfd/Makefile +1 -0
index feaeeae..098a932 100644
@@ -14,6 +14,7 @@ obj-$(CONFIG_HTC_I2CPLD)	+= htc-i2cpld.o
 
 obj-$(CONFIG_MFD_DAVINCI_VOICECODEC)	+= davinci_voicecodec.o
 obj-$(CONFIG_MFD_DM355EVM_MSP)	+= dm355evm_msp.o
+obj-$(CONFIG_MFD_TI_SSP)	+= ti-ssp.o
 
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
 obj-$(CONFIG_MFD_TC35892)	+= tc35892.o
drivers/mfd/ti-ssp.c new file +88 -0
new file mode 100644
index 0000000..ac3171a
@@ -0,0 +1,475 @@
+/*
+ * Sequencer Serial Port (SSP) driver for Texas Instruments' SoCs
+ *
+ * Copyright (C) 2010 Texas Instruments Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/err.h>
+#include <linux/init.h>
+#include <linux/wait.h>
+#include <linux/clk.h>
+#include <linux/interrupt.h>
+#include <linux/device.h>
+#include <linux/spinlock.h>
+#include <linux/platform_device.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/ti_ssp.h>
+
+/* Register Offsets */
+#define REG_REV		0x00
+#define REG_IOSEL_1	0x04
+#define REG_IOSEL_2	0x08
+#define REG_PREDIV	0x0c
+#define REG_INTR_ST	0x10
+#define REG_INTR_EN	0x14
+#define REG_TEST_CTRL	0x18
+
+/* Per port registers */
+#define PORT_CFG_2	0x00
+#define PORT_ADDR	0x04
+#define PORT_DATA	0x08
+#define PORT_CFG_1	0x0c
+#define PORT_STATE	0x10
+
+#define SSP_PORT_CONFIG_MASK	(SSP_EARLY_DIN | SSP_DELAY_DOUT)
+#define SSP_PORT_CLKRATE_MASK	0x0f
+
+#define SSP_SEQRAM_WR_EN	BIT(4)
+#define SSP_SEQRAM_RD_EN	BIT(5)
+#define SSP_START		BIT(15)
+#define SSP_BUSY		BIT(10)
+#define SSP_PORT_ASL		BIT(7)
+#define SSP_PORT_CFO1		BIT(6)
+
+#define SSP_PORT_SEQRAM_SIZE	32
+
+static const int ssp_port_base[]   = {0x040, 0x080};
+static const int ssp_port_seqram[] = {0x100, 0x180};
+
+struct ti_ssp {
+	struct resource		*res;
+	struct device		*dev;
+	void __iomem		*regs;
+	spinlock_t		lock;
+	struct clk		*clk;
+	int			irq;
+	wait_queue_head_t	wqh;
+};
+
+static inline struct ti_ssp *dev_to_ssp(struct device *dev)
+{
+	return dev_get_drvdata(dev->parent);
+}
+
+static inline int dev_to_port(struct device *dev)
+{
+	return to_platform_device(dev)->id;
+}
+

drivers/mfd/ti-ssp.c line 98

Quoted 10 lines
drivers/mfd/ti-ssp.c new file +10 -0
+/* Register Access Helpers, rmw() functions need to run locked */
+static inline u32 ssp_read(struct ti_ssp *ssp, int reg)
+{
+	return __raw_readl(ssp->regs + reg);
+}
+
+static inline void ssp_write(struct ti_ssp *ssp, int reg, u32 val)
+{
+	__raw_writel(val, ssp->regs + reg);
+}

I'm pretty sure it was resolved that __raw_ versions should not be used here.

drivers/mfd/ti-ssp.c line 105

Quoted 7 lines
drivers/mfd/ti-ssp.c new file +7 -0
+
+static inline void ssp_rmw(struct ti_ssp *ssp, int reg, u32 mask, u32 bits)
+{
+	u32 val = ssp_read(ssp, reg);
+	val &= ~mask;
+	val |= bits;
+	ssp_write(ssp, reg, val);

or simply:

	ssp_write(ssp, reg, (ssp_read(ssp, reg) & ~mask) | bits);
Quoted 349 lines
drivers/mfd/ti-ssp.c new file +349 -0
+}
+
+static inline u32 ssp_port_read(struct ti_ssp *ssp, int port, int reg)
+{
+	return ssp_read(ssp, ssp_port_base[port] + reg);
+}
+
+static inline void ssp_port_write(struct ti_ssp *ssp, int port, int reg,
+				  u32 val)
+{
+	ssp_write(ssp, ssp_port_base[port] + reg, val);
+}
+
+static inline void ssp_port_rmw(struct ti_ssp *ssp, int port, int reg,
+				u32 mask, u32 bits)
+{
+	ssp_rmw(ssp, ssp_port_base[port] + reg, mask, bits);
+}
+
+static inline void ssp_port_clr_bits(struct ti_ssp *ssp, int port, int reg,
+				     u32 bits)
+{
+	ssp_port_rmw(ssp, port, reg, bits, 0);
+}
+
+static inline void ssp_port_set_bits(struct ti_ssp *ssp, int port, int reg,
+				     u32 bits)
+{
+	ssp_port_rmw(ssp, port, reg, 0, bits);
+}
+
+/* Called to setup port clock mode, caller must hold ssp->lock */
+static int __set_mode(struct ti_ssp *ssp, int port, int mode)
+{
+	mode &= SSP_PORT_CONFIG_MASK;
+	ssp_port_rmw(ssp, port, PORT_CFG_1, SSP_PORT_CONFIG_MASK, mode);
+
+	return 0;
+}
+
+int ti_ssp_set_mode(struct device *dev, int mode)
+{
+	struct ti_ssp *ssp = dev_to_ssp(dev);
+	int port = dev_to_port(dev);
+	int ret;
+
+	spin_lock(&ssp->lock);
+	ret = __set_mode(ssp, port, mode);
+	spin_unlock(&ssp->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(ti_ssp_set_mode);
+
+/* Called to setup port iosel, caller must hold ssp->lock */
+static int __set_iosel(struct ti_ssp *ssp, int port, u32 iosel)
+{
+	unsigned val;
+
+	/* IOSEL1 gets the least significant 16 bits */
+	val = ssp_read(ssp, REG_IOSEL_1);
+	val &= 0xffff << (port ? 0 : 16);
+	val |= (iosel & 0xffff) << (port ? 16 : 0);
+	ssp_write(ssp, REG_IOSEL_1, val);
+
+	/* IOSEL2 gets the most significant 16 bits */
+	val = ssp_read(ssp, REG_IOSEL_2);
+	val &= 0x0007 << (port ? 0 : 16);
+	val |= (iosel & 0x00070000) >> (port ? 0 : 16);
+	ssp_write(ssp, REG_IOSEL_2, val);
+
+	return 0;
+}
+
+int ti_ssp_set_iosel(struct device *dev, u32 iosel)
+{
+	struct ti_ssp *ssp = dev_to_ssp(dev);
+	int port = dev_to_port(dev);
+	int ret;
+
+	spin_lock(&ssp->lock);
+	ret = __set_iosel(ssp, port, iosel);
+	spin_unlock(&ssp->lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(ti_ssp_set_iosel);
+
+int ti_ssp_load(struct device *dev, int offs, u32* prog, int len)
+{
+	struct ti_ssp *ssp = dev_to_ssp(dev);
+	int port = dev_to_port(dev);
+	int i;
+
+	if (len > SSP_PORT_SEQRAM_SIZE)
+		return -ENOSPC;
+
+	spin_lock(&ssp->lock);
+
+	/* Enable SeqRAM access */
+	ssp_port_set_bits(ssp, port, PORT_CFG_2, SSP_SEQRAM_WR_EN);
+
+	/* Copy code */
+	for (i = 0; i < len; i++) {
+		__raw_writel(prog[i], ssp->regs + offs + 4*i +
+			     ssp_port_seqram[port]);
+	}
+
+	/* Disable SeqRAM access */
+	ssp_port_clr_bits(ssp, port, PORT_CFG_2, SSP_SEQRAM_WR_EN);
+
+	spin_unlock(&ssp->lock);
+
+	return 0;
+}
+EXPORT_SYMBOL(ti_ssp_load);
+
+int ti_ssp_raw_read(struct device *dev)
+{
+	struct ti_ssp *ssp = dev_to_ssp(dev);
+	int port = dev_to_port(dev);
+	u32 val;
+
+	val = ssp_read(ssp, REG_IOSEL_2);
+	val >>= (port ? 27 : 11);
+
+	return val & 0x0f;
+}
+EXPORT_SYMBOL(ti_ssp_raw_read);
+
+int ti_ssp_raw_write(struct device *dev, u32 val)
+{
+	struct ti_ssp *ssp = dev_to_ssp(dev);
+	int port = dev_to_port(dev);
+	u32 mask;
+
+	spin_lock(&ssp->lock);
+
+	val &= 0x0f;
+	val <<= (port ? 22 : 6);
+	mask = 0x0f << (port ? 22 : 6);
+	ssp_rmw(ssp, REG_IOSEL_2, mask, val);
+
+	spin_unlock(&ssp->lock);
+
+	return 0;
+}
+EXPORT_SYMBOL(ti_ssp_raw_write);
+
+static inline int __xfer_done(struct ti_ssp *ssp, int port)
+{
+	return !(ssp_port_read(ssp, port, PORT_CFG_1) & SSP_BUSY);
+}
+
+int ti_ssp_run(struct device *dev, u32 pc, u32 input, u32 *output)
+{
+	struct ti_ssp *ssp = dev_to_ssp(dev);
+	int port = dev_to_port(dev);
+	int ret;
+
+	if (pc & ~(0x3f))
+		return -EINVAL;
+
+	/* Grab ssp->lock to serialize rmw on ssp registers */
+	spin_lock(&ssp->lock);
+
+	ssp_port_write(ssp, port, PORT_ADDR, input >> 16);
+	ssp_port_write(ssp, port, PORT_DATA, input & 0xffff);
+	ssp_port_rmw(ssp, port, PORT_CFG_1, 0x3f, pc);
+
+	/* grab wait queue head lock to avoid race with the isr */
+	spin_lock_irq(&ssp->wqh.lock);
+
+	/* kick off sequence execution in hardware */
+	ssp_port_set_bits(ssp, port, PORT_CFG_1, SSP_START);
+
+	/* drop ssp lock; no register writes beyond this */
+	spin_unlock(&ssp->lock);
+
+	ret = wait_event_interruptible_locked_irq(ssp->wqh,
+						  __xfer_done(ssp, port));
+	spin_unlock_irq(&ssp->wqh.lock);
+
+	if (ret < 0)
+		return ret;
+
+	if (output) {
+		*output = (ssp_port_read(ssp, port, PORT_ADDR) << 16) |
+			  (ssp_port_read(ssp, port, PORT_DATA) &  0xffff);
+	}
+
+	ret = ssp_port_read(ssp, port, PORT_STATE) & 0x3f; /* stop address */
+
+	return ret;
+}
+EXPORT_SYMBOL(ti_ssp_run);
+
+static irqreturn_t ti_ssp_interrupt(int irq, void *dev_data)
+{
+	struct ti_ssp *ssp = dev_data;
+
+	spin_lock(&ssp->wqh.lock);
+
+	ssp_write(ssp, REG_INTR_ST, 0x3);
+	wake_up_locked(&ssp->wqh);
+
+	spin_unlock(&ssp->wqh.lock);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit ti_ssp_probe(struct platform_device *pdev)
+{
+	static struct ti_ssp *ssp;
+	const struct ti_ssp_data *pdata = pdev->dev.platform_data;
+	int error = 0, prediv = 0xff, id;
+	unsigned long sysclk;
+	struct device *dev = &pdev->dev;
+	struct mfd_cell cells[2];
+
+	ssp = kzalloc(sizeof(*ssp), GFP_KERNEL);
+	if (!ssp) {
+		dev_err(dev, "cannot allocate device info\n");
+		return -ENOMEM;
+	}
+
+	ssp->dev = dev;
+	dev_set_drvdata(dev, ssp);
+
+	ssp->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!ssp->res) {
+		error = -ENODEV;
+		dev_err(dev, "cannot determine register area\n");
+		goto error_res;
+	}
+
+	if (!request_mem_region(ssp->res->start, resource_size(ssp->res),
+				pdev->name)) {
+		error = -ENOMEM;
+		dev_err(dev, "cannot claim register memory\n");
+		goto error_res;
+	}
+
+	ssp->regs = ioremap(ssp->res->start, resource_size(ssp->res));
+	if (!ssp->regs) {
+		error = -ENOMEM;
+		dev_err(dev, "cannot map register memory\n");
+		goto error_map;
+	}
+
+	ssp->clk = clk_get(dev, NULL);
+	if (IS_ERR(ssp->clk)) {
+		error = PTR_ERR(ssp->clk);
+		dev_err(dev, "cannot claim device clock\n");
+		goto error_clk;
+	}
+
+	ssp->irq = platform_get_irq(pdev, 0);
+	if (ssp->irq < 0) {
+		error = -ENODEV;
+		dev_err(dev, "unknown irq\n");
+		goto error_irq;
+	}
+
+	error = request_threaded_irq(ssp->irq, NULL, ti_ssp_interrupt, 0,
+				   dev_name(dev), ssp);
+	if (error < 0) {
+		dev_err(dev, "cannot acquire irq\n");
+		goto error_irq;
+	}
+
+	spin_lock_init(&ssp->lock);
+	init_waitqueue_head(&ssp->wqh);
+
+	/* Power on and initialize SSP */
+	error = clk_enable(ssp->clk);
+	if (error) {
+		dev_err(dev, "cannot enable device clock\n");
+		goto error_enable;
+	}
+
+	/* Reset registers to a sensible known state */
+	ssp_write(ssp, REG_IOSEL_1, 0);
+	ssp_write(ssp, REG_IOSEL_2, 0);
+	ssp_write(ssp, REG_INTR_EN, 0x3);
+	ssp_write(ssp, REG_INTR_ST, 0x3);
+	ssp_write(ssp, REG_TEST_CTRL, 0);
+	ssp_port_write(ssp, 0, PORT_CFG_1, SSP_PORT_ASL);
+	ssp_port_write(ssp, 1, PORT_CFG_1, SSP_PORT_ASL);
+	ssp_port_write(ssp, 0, PORT_CFG_2, SSP_PORT_CFO1);
+	ssp_port_write(ssp, 1, PORT_CFG_2, SSP_PORT_CFO1);
+
+	sysclk = clk_get_rate(ssp->clk);
+	if (pdata && pdata->out_clock)
+		prediv = (sysclk / pdata->out_clock) - 1;
+	prediv = clamp(prediv, 0, 0xff);
+	ssp_rmw(ssp, REG_PREDIV, 0xff, prediv);
+
+	memset(cells, 0, sizeof(cells));
+	for (id = 0; id < 2; id++) {
+		const struct ti_ssp_dev_data *data = &pdata->dev_data[id];
+
+		cells[id].id		= id;
+		cells[id].name		= data->dev_name;
+		cells[id].platform_data	= data->pdata;
+		cells[id].data_size	= data->pdata_size;
+	}
+
+	error = mfd_add_devices(dev, 0, cells, 2, NULL, 0);
+	if (error < 0) {
+		dev_err(dev, "cannot add mfd cells\n");
+		goto error_enable;
+	}
+
+	return 0;
+
+error_enable:
+	free_irq(ssp->irq, ssp);
+error_irq:
+	clk_put(ssp->clk);
+error_clk:
+	iounmap(ssp->regs);
+error_map:
+	release_mem_region(ssp->res->start, resource_size(ssp->res));
+error_res:
+	kfree(ssp);
+	return error;
+}
+
+static int __devexit ti_ssp_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ti_ssp *ssp = dev_get_drvdata(dev);
+
+	mfd_remove_devices(dev);
+	clk_disable(ssp->clk);
+	free_irq(ssp->irq, ssp);
+	clk_put(ssp->clk);
+	iounmap(ssp->regs);
+	release_mem_region(ssp->res->start, resource_size(ssp->res));
+	kfree(ssp);
+	dev_set_drvdata(dev, NULL);
+	return 0;
+}
+
+static struct platform_driver ti_ssp_driver = {
+	.probe		= ti_ssp_probe,
+	.remove		= __devexit_p(ti_ssp_remove),
+	.driver		= {

drivers/mfd/ti-ssp.c line 464

Quoted 10 lines
drivers/mfd/ti-ssp.c new file +10 -0
+		.name	= "ti-ssp",
+		.owner	= THIS_MODULE,
+	}
+};
+
+static int __init ti_ssp_init(void)
+{
+	return platform_driver_register(&ti_ssp_driver);
+}
+arch_initcall_sync(ti_ssp_init);

This should be module_init(). More on this when I reply to the spi driver.

Quoted 107 lines
drivers/mfd/ti-ssp.c new file +11 -0
+
+static void __exit ti_ssp_exit(void)
+{
+	platform_driver_unregister(&ti_ssp_driver);
+}
+module_exit(ti_ssp_exit);
+
+MODULE_DESCRIPTION("Sequencer Serial Port (SSP) Driver");
+MODULE_AUTHOR("Cyril Chemparathy");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:ti-ssp");
include/linux/mfd/ti_ssp.h new file +87 -0
new file mode 100644
index 0000000..021fe09
@@ -0,0 +1,87 @@
+/*
+ * Sequencer Serial Port (SSP) driver for Texas Instruments' SoCs
+ *
+ * Copyright (C) 2010 Texas Instruments Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef __TI_SSP_H__
+#define __TI_SSP_H__
+
+struct ti_ssp_dev_data {
+	const char	*dev_name;
+	void		*pdata;
+	size_t		pdata_size;
+};
+
+struct ti_ssp_data {
+	unsigned long		out_clock;
+	struct ti_ssp_dev_data	dev_data[2];
+};
+
+/*
+ * Sequencer port IO pin configuration bits.  These do not correlate 1-1 with
+ * the hardware.  The iosel field in the port data combines iosel1 and iosel2,
+ * and is therefore not a direct map to register space.  It is best to use the
+ * macros below to construct iosel values.
+ *
+ * least significant 16 bits --> iosel1
+ * most significant 16 bits  --> iosel2
+ */
+
+#define SSP_IN			0x0000
+#define SSP_DATA		0x0001
+#define SSP_CLOCK		0x0002
+#define SSP_CHIPSEL		0x0003
+#define SSP_OUT			0x0004
+#define SSP_PIN_SEL(pin, v)	((v) << ((pin) * 3))
+#define SSP_PIN_MASK(pin)	SSP_PIN_SEL(pin, 0x7)
+#define SSP_INPUT_SEL(pin)	((pin) << 16)
+
+/* Sequencer port config bits */
+#define SSP_EARLY_DIN		BIT(8)
+#define SSP_DELAY_DOUT		BIT(9)
+
+/* Sequence map definitions */
+#define SSP_CLK_HIGH		BIT(0)
+#define SSP_CLK_LOW		0
+#define SSP_DATA_HIGH		BIT(1)
+#define SSP_DATA_LOW		0
+#define SSP_CS_HIGH		BIT(2)
+#define SSP_CS_LOW		0
+#define SSP_OUT_MODE		BIT(3)
+#define SSP_IN_MODE		0
+#define SSP_DATA_REG		BIT(4)
+#define SSP_ADDR_REG		0
+
+#define SSP_OPCODE_DIRECT	((0x0) << 5)
+#define SSP_OPCODE_TOGGLE	((0x1) << 5)
+#define SSP_OPCODE_SHIFT	((0x2) << 5)
+#define SSP_OPCODE_BRANCH0	((0x4) << 5)
+#define SSP_OPCODE_BRANCH1	((0x5) << 5)
+#define SSP_OPCODE_BRANCH	((0x6) << 5)
+#define SSP_OPCODE_STOP		((0x7) << 5)
+#define SSP_BRANCH(addr)	((addr) << 8)
+#define SSP_COUNT(cycles)	((cycles) << 8)
+
+int ti_ssp_raw_read(struct device *dev);
+int ti_ssp_raw_write(struct device *dev, u32 val);
+int ti_ssp_load(struct device *dev, int offs, u32* prog, int len);
+int ti_ssp_run(struct device *dev, u32 pc, u32 input, u32 *output);
+int ti_ssp_set_mode(struct device *dev, int mode);
+int ti_ssp_set_iosel(struct device *dev, u32 iosel);
+
+#endif /* __TI_SSP_H__ */
Signature · 1 line
1.7.1
#3 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

Quoted 9 lines · Grant Likely
Quoted 8 lines · Cyril Chemparathy

TI's sequencer serial port (TI-SSP) is a jack-of-all-trades type of serial port device. It has a built-in programmable execution engine that can be programmed to operate as almost any serial bus (I2C, SPI, EasyScale, and others).

This patch adds a driver for this controller device. The driver does not expose a user-land interface. Protocol drivers built on top of this layer are expected to remain in-kernel.

[...]

Quoted 7 lines

drivers/mfd/ti-ssp.c line 98

Quoted 4 lines
drivers/mfd/ti-ssp.c new file +4 -0
+static inline void ssp_write(struct ti_ssp *ssp, int reg, u32 val)
+{
+     __raw_writel(val, ssp->regs + reg);
+}

I'm pretty sure it was resolved that __raw_ versions should not be used here.

The endian-swap done by writel/readl are incorrect since these devices are meant to be accessed native-endian at all times.

See [1] below for Russell King's earlier response on this. In this case, I don't think memory-device ordering matters, and therefore the __raw_ variants should be ok. Should I just insert barriers into the read/write wrappers here?

[...]

Regards
Cyril.

[1] http://kerneltrap.org/mailarchive/linux-kernel/2010/10/22/4636289

#4 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

Quoted 19 lines · Cyril Chemparathy
Quoted 9 lines · Grant Likely
Quoted 8 lines · Cyril Chemparathy

TI's sequencer serial port (TI-SSP) is a jack-of-all-trades type of serial port device. ?It has a built-in programmable execution engine that can be programmed to operate as almost any serial bus (I2C, SPI, EasyScale, and others).

This patch adds a driver for this controller device. ?The driver does not expose a user-land interface. ?Protocol drivers built on top of this layer are expected to remain in-kernel.

[...]

Quoted 7 lines

drivers/mfd/ti-ssp.c line 98

Quoted 4 lines
drivers/mfd/ti-ssp.c new file +4 -0
+static inline void ssp_write(struct ti_ssp *ssp, int reg, u32 val)
+{
+ ? ? __raw_writel(val, ssp->regs + reg);
+}

I'm pretty sure it was resolved that __raw_ versions should not be used here.

Quoted 7 lines

The endian-swap done by writel/readl are incorrect since these devices are meant to be accessed native-endian at all times.

See [1] below for Russell King's earlier response on this. ?In this case, I don't think memory-device ordering matters, and therefore the __raw_ variants should be ok. ?Should I just insert barriers into the read/write wrappers here?

I'll let Russel make the decision here; but I must admit I'm puzzled. Are you running an ARMEB machine? the le32_to_cpu macros should be no-ops on little endian. If you do still use the __raw variants, then at the very least the reason for doing so must be well documented.

Personally, I'd rather see the appropriate macros added to io.h ioread32be()/iowrite32be() perhaps? Or am I missing something subtle about the hardware behaviour?

g.

#5 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

Quoted 28 lines · Grant Likely
Quoted 19 lines · Cyril Chemparathy
Quoted 9 lines · Grant Likely
Quoted 8 lines · Cyril Chemparathy

TI's sequencer serial port (TI-SSP) is a jack-of-all-trades type of serial port device. It has a built-in programmable execution engine that can be programmed to operate as almost any serial bus (I2C, SPI, EasyScale, and others).

This patch adds a driver for this controller device. The driver does not expose a user-land interface. Protocol drivers built on top of this layer are expected to remain in-kernel.

[...]

Quoted 7 lines

drivers/mfd/ti-ssp.c line 98

Quoted 4 lines
drivers/mfd/ti-ssp.c new file +4 -0
+static inline void ssp_write(struct ti_ssp *ssp, int reg, u32 val)
+{
+     __raw_writel(val, ssp->regs + reg);
+}

I'm pretty sure it was resolved that __raw_ versions should not be used here.

Quoted 7 lines

The endian-swap done by writel/readl are incorrect since these devices are meant to be accessed native-endian at all times.

See [1] below for Russell King's earlier response on this. In this case, I don't think memory-device ordering matters, and therefore the __raw_ variants should be ok. Should I just insert barriers into the read/write wrappers here?

Quoted 9 lines

I'll let Russel make the decision here; but I must admit I'm puzzled. Are you running an ARMEB machine? the le32_to_cpu macros should be no-ops on little endian. If you do still use the __raw variants, then at the very least the reason for doing so must be well documented.

Personally, I'd rather see the appropriate macros added to io.h ioread32be()/iowrite32be() perhaps? Or am I missing something subtle about the hardware behaviour?

As with most of the davinci series devices, the tnetv107x SOC can "theoretically" run both big and little endian. Since the CPU and SOC endian-ness are tied, on-chip peripherals are to be accessed native-endian (i.e. without swap) at all times.

However, many of these parts do not "officially" support big-endian, and this is the case with tnetv107x as well. Even so, it would be best not to break this, just in case these h/w blocks get reused on some future big-endian capable derivative.

Further, I found this to be common practice across many davinci drivers:

$ find . -name '*davinci*' | xargs grep __raw_ | cut -d: -f1 | uniq
./drivers/input/keyboard/davinci_keyscan.c
./drivers/mtd/nand/davinci_nand.c
./drivers/mfd/davinci_voicecodec.c
./drivers/i2c/busses/i2c-davinci.c
./drivers/usb/musb/davinci.c
./drivers/net/davinci_mdio.c
./drivers/net/davinci_cpdma.c
./sound/soc/davinci/davinci-mcasp.c
./sound/soc/davinci/davinci-i2s.c

Regards
Cyril.

#6 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

In reply to Grant Likely
Quoted 1 line · Grant Likely

I'll let Russel make the decision here; but I must admit I'm puzzled.

                 ^

Grr.

I'm ambivalent over it, provided that the author realises that the __raw variants have no ordering guarantees other than their accesses being ordered only with respect to themselves and nothing else.

If we do want to go down the route of creating some official native endian accessors, then I'm fine with that too.

#7 lore raw

PATCH v5 1/12 misc: add driver for sequencer serial port

Quoted 4 lines · Russell King - ARM Linux
Quoted 1 line · Grant Likely

I'll let Russel make the decision here; but I must admit I'm puzzled.

? ? ? ? ? ? ? ? ^
Grr.

Sorry; typo. I *do* know how to spell your name. :-) I owe you a pint and we'll call it even.

g.

#8 lore raw

PATCH v5 2/12 davinci: add tnetv107x ssp platform device

In reply to Cyril Chemparathy

This patch adds an SSP platform device definition for the tnetv107x soc family. The clock lookup entry has also been updated to match.

---
 arch/arm/mach-davinci/devices-tnetv107x.c      |   25 ++++++++++++++++++++++++
 arch/arm/mach-davinci/include/mach/tnetv107x.h |    2 +
 arch/arm/mach-davinci/tnetv107x.c              |    2 +-
 3 files changed, 28 insertions(+), 1 deletions(-)
arch/arm/mach-davinci/devices-tnetv107x.c +25 -0
index 85503de..6162cae 100644
@@ -35,6 +35,7 @@
 #define TNETV107X_SDIO0_BASE			0x08088700
 #define TNETV107X_SDIO1_BASE			0x08088800
 #define TNETV107X_KEYPAD_BASE			0x08088a00
+#define TNETV107X_SSP_BASE			0x08088c00
 #define TNETV107X_ASYNC_EMIF_CNTRL_BASE		0x08200000
 #define TNETV107X_ASYNC_EMIF_DATA_CE0_BASE	0x30000000
 #define TNETV107X_ASYNC_EMIF_DATA_CE1_BASE	0x40000000
@@ -342,6 +343,25 @@ static struct platform_device tsc_device = {
 	.resource	= tsc_resources,
 };
 
+static struct resource ssp_resources[] = {
+	{
+		.start	= TNETV107X_SSP_BASE,
+		.end	= TNETV107X_SSP_BASE + 0x1ff,
+		.flags	= IORESOURCE_MEM,
+	},
+	{
+		.start	= IRQ_TNETV107X_SSP,
+		.flags	= IORESOURCE_IRQ,
+	},
+};
+
+static struct platform_device ssp_device = {
+	.name		= "ti-ssp",
+	.id		= -1,
+	.num_resources	= ARRAY_SIZE(ssp_resources),
+	.resource	= ssp_resources,
+};
+
 void __init tnetv107x_devices_init(struct tnetv107x_device_info *info)
 {
 	int i, error;
@@ -380,4 +400,9 @@ void __init tnetv107x_devices_init(struct tnetv107x_device_info *info)
 		keypad_device.dev.platform_data = info->keypad_config;
 		platform_device_register(&keypad_device);
 	}
+
+	if (info->ssp_config) {
+		ssp_device.dev.platform_data = info->ssp_config;
+		platform_device_register(&ssp_device);
+	}
 }
arch/arm/mach-davinci/include/mach/tnetv107x.h +2 -0
index 5a681d8..89c1fdc 100644
@@ -34,6 +34,7 @@
 
 #include <linux/serial_8250.h>
 #include <linux/input/matrix_keypad.h>
+#include <linux/mfd/ti_ssp.h>
 
 #include <mach/mmc.h>
 #include <mach/nand.h>
@@ -44,6 +45,7 @@ struct tnetv107x_device_info {
 	struct davinci_mmc_config	*mmc_config[2];  /* 2 controllers */
 	struct davinci_nand_pdata	*nand_config[4]; /* 4 chipsels */
 	struct matrix_keypad_platform_data *keypad_config;
+	struct ti_ssp_data		*ssp_config;
 };
 
 extern struct platform_device tnetv107x_wdt_device;
arch/arm/mach-davinci/tnetv107x.c +1 -1
index 6fcdece..1b28fdd 100644
@@ -278,7 +278,7 @@ static struct clk_lookup clks[] = {
 	CLK(NULL,		"timer1",		&clk_timer1),
 	CLK("tnetv107x_wdt.0",	NULL,			&clk_wdt_arm),
 	CLK(NULL,		"clk_wdt_dsp",		&clk_wdt_dsp),
-	CLK("ti-ssp.0",		NULL,			&clk_ssp),
+	CLK("ti-ssp",		NULL,			&clk_ssp),
 	CLK(NULL,		"clk_tdm0",		&clk_tdm0),
 	CLK(NULL,		"clk_vlynq",		&clk_vlynq),
 	CLK(NULL,		"clk_mcdma",		&clk_mcdma),
Signature · 1 line
1.7.1
#9 lore raw

PATCH v5 3/12 davinci: add ssp config for tnetv107x evm board

In reply to Cyril Chemparathy

This patch adds SSP configuration and pin muxing info for tnetv107x evm boards.

---
 arch/arm/mach-davinci/board-tnetv107x-evm.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-tnetv107x-evm.c +14 -0
index a6db854..ef526b1 100644
@@ -99,6 +99,12 @@ static const short uart1_pins[] __initdata = {
 	-1
 };
 
+static const short ssp_pins[] __initdata = {
+	TNETV107X_SSP0_0, TNETV107X_SSP0_1, TNETV107X_SSP0_2,
+	TNETV107X_SSP1_0, TNETV107X_SSP1_1, TNETV107X_SSP1_2,
+	TNETV107X_SSP1_3, -1
+};
+
 static struct mtd_partition nand_partitions[] = {
 	/* bootloader (U-Boot, etc) in first 12 sectors */
 	{
@@ -196,17 +202,25 @@ static struct matrix_keypad_platform_data keypad_config = {
 	.no_autorepeat	= 0,
 };
 
+static struct ti_ssp_data ssp_config = {
+	.out_clock	= 250 * 1000,
+	.dev_data	= {
+	},
+};
+
 static struct tnetv107x_device_info evm_device_info __initconst = {
 	.serial_config		= &serial_config,
 	.mmc_config[1]		= &mmc_config,	/* controller 1 */
 	.nand_config[0]		= &nand_config,	/* chip select 0 */
 	.keypad_config		= &keypad_config,
+	.ssp_config		= &ssp_config,
 };
 
 static __init void tnetv107x_evm_board_init(void)
 {
 	davinci_cfg_reg_list(sdio1_pins);
 	davinci_cfg_reg_list(uart1_pins);
+	davinci_cfg_reg_list(ssp_pins);
 
 	tnetv107x_devices_init(&evm_device_info);
 }
Signature · 1 line
1.7.1
#10 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Cyril Chemparathy

This patch adds an SPI master implementation that operates on top of an underlying TI-SSP port.

---
 drivers/mfd/Kconfig        |   10 +
 drivers/mfd/Makefile       |    1 +
 drivers/mfd/ti-ssp-spi.c   |  402 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ti_ssp.h |    6 +
 4 files changed, 419 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp-spi.c
drivers/mfd/Kconfig +10 -0
index 6bedf53..7dcc03a 100644
@@ -92,6 +92,16 @@ config MFD_TI_SSP
 	  To compile this driver as a module, choose M here: the
 	  module will be called ti-ssp.
 
+config MFD_TI_SSP_SPI
+	tristate "TI Sequencer Serial Port - SPI Support"
+	depends on SPI_MASTER && MFD_TI_SSP
+	help
+	  This selects an SPI master implementation using a TI sequencer
+	  serial port.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ti-ssp-spi.
+
 config HTC_EGPIO
 	bool "HTC EGPIO support"
 	depends on GENERIC_HARDIRQS && GPIOLIB && ARM
drivers/mfd/Makefile +1 -0
index 098a932..ba97f48 100644
@@ -15,6 +15,7 @@ obj-$(CONFIG_HTC_I2CPLD)	+= htc-i2cpld.o
 obj-$(CONFIG_MFD_DAVINCI_VOICECODEC)	+= davinci_voicecodec.o
 obj-$(CONFIG_MFD_DM355EVM_MSP)	+= dm355evm_msp.o
 obj-$(CONFIG_MFD_TI_SSP)	+= ti-ssp.o
+obj-$(CONFIG_MFD_TI_SSP_SPI)	+= ti-ssp-spi.o
 
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
 obj-$(CONFIG_MFD_TC35892)	+= tc35892.o
drivers/mfd/ti-ssp-spi.c new file +402 -0

402 lines not on this page · raw message

include/linux/mfd/ti_ssp.h +6 -0
index 021fe09..dbb4b43 100644
@@ -32,6 +32,12 @@ struct ti_ssp_data {
 	struct ti_ssp_dev_data	dev_data[2];
 };
 
+struct ti_ssp_spi_data {
+	unsigned long	iosel;
+	int		num_cs;
+	void		(*select)(int cs);
+};
+
 /*
  * Sequencer port IO pin configuration bits.  These do not correlate 1-1 with
  * the hardware.  The iosel field in the port data combines iosel1 and iosel2,
Signature · 1 line
1.7.1
#11 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 11 lines · Cyril Chemparathy

This patch adds an SPI master implementation that operates on top of an underlying TI-SSP port.

---
 drivers/mfd/Kconfig        |   10 +
 drivers/mfd/Makefile       |    1 +
 drivers/mfd/ti-ssp-spi.c   |  402 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ti_ssp.h |    6 +
 4 files changed, 419 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp-spi.c

This should live in drivers/spi rather than drivers/mfd. Each of the drivers which use the TI-SSP core are single function drivers and having them in the appropriate directory makes them easier to find.

The SSP core driver could either live in drivers/mfd or drivers/misc atmel-ssc.c is in drivers/misc for example.

~Ryan

Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

Ryan Mallon         		5 Amuri Park, 404 Barbadoes St
ryan at bluewatersys.com         	PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com	New Zealand
Phone: +64 3 3779127		Freecall: Australia 1800 148 751
Fax:   +64 3 3779135			  USA 1800 261 2934
#12 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Cyril Chemparathy
Quoted 4 lines · Cyril Chemparathy

This patch adds an SPI master implementation that operates on top of an underlying TI-SSP port.

[...]

drivers/mfd/ti-ssp-spi.c line 391

Quoted 5 lines
drivers/mfd/ti-ssp-spi.c new file +5 -0
+static int __init ti_ssp_spi_init(void)
+{
+	return platform_driver_register(&ti_ssp_spi_driver);
+}
+subsys_initcall(ti_ssp_spi_init);

After discussions about device init dependencies at plumbers, and since this is the first SPI device driver I've reviewed since that dicussion, this driver gets to be the first to implement the proposed policy. :-)

Change this to module_initcall(). Many spi and i2c drivers use module or subsys_initcall to try and influence driver probe order so that certain regulator chips get registered before the devices that try to use them. This approach is insane.

Instead, it is now incumbent on the board support code to ensure that any device that depends on another device (including i2c or spi regulators) will defer registration until the prerequisite devices are bound to drivers.

I don't *think* this change will affect anything in this particular patch series, but if it does then let me know and I'll help you work out how to fix it using a bus notifier.

g.

#13 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 22 lines · Grant Likely
Quoted 4 lines · Cyril Chemparathy

This patch adds an SPI master implementation that operates on top of an underlying TI-SSP port.

[...]

drivers/mfd/ti-ssp-spi.c line 391

Quoted 5 lines
drivers/mfd/ti-ssp-spi.c new file +5 -0
+static int __init ti_ssp_spi_init(void)
+{
+ ? ? return platform_driver_register(&ti_ssp_spi_driver);
+}
+subsys_initcall(ti_ssp_spi_init);

After discussions about device init dependencies at plumbers, and since this is the first SPI device driver I've reviewed since that dicussion, this driver gets to be the first to implement the proposed policy. ?:-)

Change this to module_initcall(). ?Many spi and i2c drivers use module or subsys_initcall to try and influence driver probe order so that certain regulator chips get registered before the devices that try to use them. ?This approach is insane.

Quoted 8 lines

Instead, it is now incumbent on the board support code to ensure that any device that depends on another device (including i2c or spi regulators) will defer registration until the prerequisite devices are bound to drivers.

I don't *think* this change will affect anything in this particular patch series, but if it does then let me know and I'll help you work out how to fix it using a bus notifier.

Oh, wait, spoke too soon. You do add a regulator in this series, so this change will require a fixup. The solution is to register an bus_notifier to the spi bus type before you start registering devices. It also requires deferring the musb_hdrc.1 and tps6116x registrations until the bus_notifier callback gets called with an indication that the regulator is bound. It will look something like this:

static int tnetv107x_spi_notifier_call(struct notifier_block *nb,
unsigned long event, void *__dev)

{
	struct device *dev = __dev;

	if ((event == BUS_NOTIFY_BOUND_DRIVER) && (dev == (the-regulator))) {
		register-the-remaining-devices();
		return NOTIFY_STOP;
	};
	return NOTIFY_DONE;
}

static struct notifier_block tnetv107x_spi_nb = {
.notifier_call = tnetv107x_spi_notifier_call,
};

and then in the device registration code, before registering the regulator:

	bus_register_notifier(&spi_bus_type, &tnetv107x_spi_nb);

Let me know if you have any trouble.

g.

#14 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 6 lines · Grant Likely

On Tue, Nov 16, 2010 at 12:22 AM, Grant Likely

Quoted 4 lines

Instead, it is now incumbent on the board support code to ensure that any device that depends on another device (including i2c or spi regulators) will defer registration until the prerequisite devices are bound to drivers.

You did also say you were going to write helpers to make this easier - I do fear that we're going to end up with far too much boiler plate code in machine drivers if we have to open code this. I guess device tree is going to need the helpers anyway :)

Quoted 11 lines
Quoted 3 lines

I don't *think* this change will affect anything in this particular patch series, but if it does then let me know and I'll help you work out how to fix it using a bus notifier.

Oh, wait, spoke too soon. You do add a regulator in this series, so this change will require a fixup. The solution is to register an bus_notifier to the spi bus type before you start registering devices.

It also requires deferring the musb_hdrc.1 and tps6116x registrations until the bus_notifier callback gets called with an indication that the regulator is bound. It will look something like this:

Did you come up with a way of handling situations like cpufreq where we have no device to wait for?

#15 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 8 lines · Mark Brown
Quoted 6 lines · Grant Likely

On Tue, Nov 16, 2010 at 12:22 AM, Grant Likely

Quoted 4 lines

Instead, it is now incumbent on the board support code to ensure that any device that depends on another device (including i2c or spi regulators) will defer registration until the prerequisite devices are bound to drivers.

Quoted 4 lines

You did also say you were going to write helpers to make this easier - I do fear that we're going to end up with far too much boiler plate code in machine drivers if we have to open code this. I guess device tree is going to need the helpers anyway :)

Yup, and I will, but as can be seen the boilerplate required is actually pretty minimal, and I'd like to have a couple of platforms to work with before actually settling on what the helpers need to look like.

Quoted 9 lines
Quoted 8 lines
Quoted 4 lines

I don't *think* this change will affect anything in this particular patch series, but if it does then let me know and I'll help you work out how to fix it using a bus notifier.

Oh, wait, spoke too soon. You do add a regulator in this series, so this change will require a fixup. The solution is to register an bus_notifier to the spi bus type before you start registering devices.

Quoted 6 lines
Quoted 3 lines

It also requires deferring the musb_hdrc.1 and tps6116x registrations until the bus_notifier callback gets called with an indication that the regulator is bound. It will look something like this:

Did you come up with a way of handling situations like cpufreq where we have no device to wait for?

Haven't dug into it yet.

g.

#16 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 11 lines · Grant Likely
Quoted 4 lines · Mark Brown

You did also say you were going to write helpers to make this easier - I do fear that we're going to end up with far too much boiler plate code in machine drivers if we have to open code this. I guess device tree is going to need the helpers anyway :)

Yup, and I will, but as can be seen the boilerplate required is actually pretty minimal, and I'd like to have a couple of platforms to work with before actually settling on what the helpers need to look like.

Yeah, but I do have a bit of nervousness about the scalability of open coding and the possibility that we'll come up with a better approach so I'd be a bit more comfortable if we didn't have code in random board files as they're always the hardest thing to update.

#17 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Grant Likely
Quoted 56 lines · Grant Likely
Quoted 22 lines · Grant Likely
Quoted 4 lines · Cyril Chemparathy

This patch adds an SPI master implementation that operates on top of an underlying TI-SSP port.

[...]

drivers/mfd/ti-ssp-spi.c line 391

Quoted 5 lines
drivers/mfd/ti-ssp-spi.c new file +5 -0
+static int __init ti_ssp_spi_init(void)
+{
+     return platform_driver_register(&ti_ssp_spi_driver);
+}
+subsys_initcall(ti_ssp_spi_init);

After discussions about device init dependencies at plumbers, and since this is the first SPI device driver I've reviewed since that dicussion, this driver gets to be the first to implement the proposed policy. :-)

Change this to module_initcall(). Many spi and i2c drivers use module or subsys_initcall to try and influence driver probe order so that certain regulator chips get registered before the devices that try to use them. This approach is insane.

Quoted 8 lines

Instead, it is now incumbent on the board support code to ensure that any device that depends on another device (including i2c or spi regulators) will defer registration until the prerequisite devices are bound to drivers.

I don't *think* this change will affect anything in this particular patch series, but if it does then let me know and I'll help you work out how to fix it using a bus notifier.

Oh, wait, spoke too soon. You do add a regulator in this series, so this change will require a fixup. The solution is to register an bus_notifier to the spi bus type before you start registering devices. It also requires deferring the musb_hdrc.1 and tps6116x registrations until the bus_notifier callback gets called with an indication that the regulator is bound. It will look something like this:

static int tnetv107x_spi_notifier_call(struct notifier_block *nb,
unsigned long event, void *__dev)

{
	struct device *dev = __dev;

	if ((event == BUS_NOTIFY_BOUND_DRIVER) && (dev == (the-regulator))) {
		register-the-remaining-devices();
		return NOTIFY_STOP;
	};
	return NOTIFY_DONE;
}

static struct notifier_block tnetv107x_spi_nb = {
.notifier_call = tnetv107x_spi_notifier_call,
};

Quoted 6 lines

and then in the device registration code, before registering the regulator:

	bus_register_notifier(&spi_bus_type, &tnetv107x_spi_nb);

Let me know if you have any trouble.

The ability to wait on multiple devices may come handy. In this particular case the backlight driver depends on both ssp-gpio and regulator devices. Ideally, boards should be able to do something like...

platform_device_register_after(&backlight_device, "spi1.0"); platform_device_register_after(&backlight_device, "ti-ssp-gpio.0");

... and the device should get automatically registered once its dependencies have been met.

Crude and incomplete code follows:

struct platform_device_depend {
	struct list_head node;
	const char *dev_name;
	struct platform_device *pdev;
};

LIST_HEAD(platform_device_depend);

static int platform_device_register_after(struct platform_device *pdev,
const char *dev_name)

{
	struct platform_device_depend *dep;

	dep = kzalloc(sizeof(*dep), GFP_KERNEL);
	if (!dep)
		return -ENOMEM;
	dep->dev_name = dev_name;
	dep->pdev = pdev;
	list_add_tail(&dep->node, &platform_device_depend);
	return 0;
}

static int platform_device_try_register(struct platform_device *pdev)

{
	struct platform_device_depend *dep;

	list_for_each_entry(dep, &platform_device_depend, node) {
		if (dep->pdev == pdev)
			return -EBUSY;
	}
	return platform_device_register(pdev);
}

static int bus_notifier_func(struct notifier_block *nb,
unsigned long event, void *__dev)

{
	struct platform_device_depend *dep, *tmp;
	struct device *dev = __dev;

	if (event != BUS_NOTIFY_BOUND_DRIVER)
		return NOTIFY_DONE;

	list_for_each_entry_safe(dep, tmp, &platform_device_depend,
				 node) {
		if (strcmp(dep->dev_name, dev_name(dev)) != 0)
			continue;
		list_del(&dep->node);
		platform_device_try_register(dep->pdev);
		kfree(dep);
	}

	return NOTIFY_OK;
}

Regards
Cyril.

#18 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 1 line · Cyril Chemparathy

The ability to wait on multiple devices may come handy. In this

This is essential for any helpers, otherwise we can't cope easily with mixes of GPIO and power or with regulators from multiple chips (like an extra DCDC, for example).

#19 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 6 lines
Quoted 1 line · Cyril Chemparathy

The ability to wait on multiple devices may come

handy.

... You mean you'd like to add such a
mechanism to the framework?

Or do you want a driver-specific
mechanism (non-portable)?

If I had
to do that, I'd just use existing
kernel mechanisms to wait, and then
issue SPI transactions as needed.
Portable, straightforward.

#20 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 9 lines · David Brownell
Quoted 6 lines
Quoted 1 line · Cyril Chemparathy

The ability to wait on multiple devices may come

handy.

... You mean you'd like to add such a
mechanism to the framework?

Ideally in the framework. This appears to be a common enough problem across platforms.

Regards
Cyril.

#21 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Cyril Chemparathy
Quoted 62 lines · Cyril Chemparathy
Quoted 61 lines · Grant Likely
Quoted 22 lines · Grant Likely
Quoted 4 lines · Cyril Chemparathy

This patch adds an SPI master implementation that operates on top of an underlying TI-SSP port.

[...]

drivers/mfd/ti-ssp-spi.c line 391

Quoted 5 lines
drivers/mfd/ti-ssp-spi.c new file +5 -0
+static int __init ti_ssp_spi_init(void)
+{
+     return platform_driver_register(&ti_ssp_spi_driver);
+}
+subsys_initcall(ti_ssp_spi_init);

After discussions about device init dependencies at plumbers, and since this is the first SPI device driver I've reviewed since that dicussion, this driver gets to be the first to implement the proposed policy. :-)

Change this to module_initcall(). Many spi and i2c drivers use module or subsys_initcall to try and influence driver probe order so that certain regulator chips get registered before the devices that try to use them. This approach is insane.

Quoted 8 lines

Instead, it is now incumbent on the board support code to ensure that any device that depends on another device (including i2c or spi regulators) will defer registration until the prerequisite devices are bound to drivers.

I don't *think* this change will affect anything in this particular patch series, but if it does then let me know and I'll help you work out how to fix it using a bus notifier.

Oh, wait, spoke too soon. You do add a regulator in this series, so this change will require a fixup. The solution is to register an bus_notifier to the spi bus type before you start registering devices. It also requires deferring the musb_hdrc.1 and tps6116x registrations until the bus_notifier callback gets called with an indication that the regulator is bound. It will look something like this:

static int tnetv107x_spi_notifier_call(struct notifier_block *nb,
unsigned long event, void *__dev)

{
	struct device *dev = __dev;

	if ((event == BUS_NOTIFY_BOUND_DRIVER) && (dev == (the-regulator))) {
		register-the-remaining-devices();
		return NOTIFY_STOP;
	};
	return NOTIFY_DONE;
}

static struct notifier_block tnetv107x_spi_nb = {
.notifier_call = tnetv107x_spi_notifier_call,
};

and then in the device registration code, before registering the regulator:

	bus_register_notifier(&spi_bus_type, &tnetv107x_spi_nb);
Quoted 8 lines
Quoted 1 line

Let me know if you have any trouble.

The ability to wait on multiple devices may come handy. In this particular case the backlight driver depends on both ssp-gpio and regulator devices. Ideally, boards should be able to do something like...

platform_device_register_after(&backlight_device, "spi1.0"); platform_device_register_after(&backlight_device, "ti-ssp-gpio.0");

[cc'ing Rafael and Greg since they are certain to be interested in this discussion]

It's a good start. However, I think it can be done more generically

To start, I'm not a fan of matching by name. It's fragile because it makes assumptions about how devices will be names when they actually appear (ie. Sometimes .id is dynamically assigned). Ideally I'd prefer to have direct references (ie. pointers) to the devices that need to be registered, which *shouldn't* be difficult to handle. That guarantees that the correct device is always referenced. (aside: the device-tree use case provides this information by having direct 'phandle' references between dependencies.)

Also, any dependency tracking must work across bus_types. It is not sufficient to only handle the platform_devices use-case. All bus types have this need.

I see a few potential approaches.

Option 1: Add a list of prerequisite devices to struct device and modify driver core so that it defers binding to a driver until all the prerequisites are already bound. This can probably be implemented in a way that works for all bus types transparently. Before binding a driver, the driver core would increase the ref count on each of the prereq devices, and decrease it again when the driver is removed.

Option 2: On a per-bus_type basis have a separate registration and the bus type code would hold the device unregistered in a pending list. This option would also add a prerequisites list to struct device.

Option 3: Don't try to handle it in the bus_type or driver core code at all, but rather provide board support code with helpers to make waiting for other devices easy. Even in this case I think it is probably still a good idea for the dependant devices to increment the refcount of the prereq devices.

Perhaps something that is used like:

void do_second_registration(void)

{
	/* register list of dependant devices */
}

and then in the primary registration function:

	...
	device_notify_when_bound(&prereq_pdev->dev,
				 do_second_registration);
	platform_device_add(prereq_pdev);
	...

which would reduce the boilerplate, but remain flexible. However, while flexable, option 3 doesn't solve the dependency tracking problem, and it still requires some gymnastics to handle multiple dependencies.

On a related issue, it may also be desirable for each device to maintain a list of devices that have claimed dependency on it for the purpose of debugability.

...

some other random comments below.

Quoted 3 lines

... and the device should get automatically registered once its dependencies have been met.

unfortunately it also means that the device is in limbo between when it is "registered" by board support code, and when it is actually registered. ie. It won't show up in sysfs.

Quoted 39 lines

Crude and incomplete code follows:

struct platform_device_depend {
	struct list_head node;
	const char *dev_name;
	struct platform_device *pdev;
};

LIST_HEAD(platform_device_depend);

static int platform_device_register_after(struct platform_device *pdev,
const char *dev_name)

{
	struct platform_device_depend *dep;

	dep = kzalloc(sizeof(*dep), GFP_KERNEL);
	if (!dep)
		return -ENOMEM;
	dep->dev_name = dev_name;
	dep->pdev = pdev;
	list_add_tail(&dep->node, &platform_device_depend);
	return 0;
}

static int platform_device_try_register(struct platform_device *pdev)

{
	struct platform_device_depend *dep;

	list_for_each_entry(dep, &platform_device_depend, node) {
		if (dep->pdev == pdev)
			return -EBUSY;
	}
	return platform_device_register(pdev);
}

static int bus_notifier_func(struct notifier_block *nb,
unsigned long event, void *__dev)

Quoted 13 lines
{
	struct platform_device_depend *dep, *tmp;
	struct device *dev = __dev;

	if (event != BUS_NOTIFY_BOUND_DRIVER)
		return NOTIFY_DONE;

	list_for_each_entry_safe(dep, tmp, &platform_device_depend,
				 node) {
		if (strcmp(dep->dev_name, dev_name(dev)) != 0)
			continue;
		list_del(&dep->node);
		platform_device_try_register(dep->pdev);

Unfortunately this approach means the board support code will never know if there is a problem with registering the device.

Quoted 4 lines
		kfree(dep);
	}

	return NOTIFY_OK;

If it is part of the core platform_bus_type code, then there is no need to use a notifier. The hook can be added directly.

g.

#22 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 5 lines · Grant Likely

To start, I'm not a fan of matching by name. It's fragile because it makes assumptions about how devices will be names when they actually appear (ie. Sometimes .id is dynamically assigned). Ideally I'd prefer to have direct references (ie. pointers) to the devices that need to be registered, which *shouldn't* be difficult to handle. That

Pointers are a complete pain for buses where things are dynamically instantiated, the things you have to point at in machine data aren't the things that end up appearing during device registration when the struct device gets dynamically allocated so you need some way of translating them. This is why everyone ends up using dev_name for this sort of thing ATM, it's easy to put into the code and match against the actual struct device at runtime without needing to know about bus types.

Quoted 3 lines

guarantees that the correct device is always referenced. (aside: the device-tree use case provides this information by having direct 'phandle' references between dependencies.)

Device tree makes this a lot easier.

Quoted 10 lines

Option 1: Add a list of prerequisite devices to struct device and modify driver core so that it defers binding to a driver until all the prerequisites are already bound. This can probably be implemented in a way that works for all bus types transparently. Before binding a driver, the driver core would increase the ref count on each of the prereq devices, and decrease it again when the driver is removed.

Option 2: On a per-bus_type basis have a separate registration and the bus type code would hold the device unregistered in a pending list. This option would also add a prerequisites list to struct device.

Per bus type sounds like a lot of hassle going through all the bus types but we may need to do that to handle autoprobable buses like USB. I do like the idea that the core would know what's going on so that things do become visible for the debuggabilty reasons you mention, though helpers could also provide similar infrastructure.

Quoted 5 lines

Option 3: Don't try to handle it in the bus_type or driver core code at all, but rather provide board support code with helpers to make waiting for other devices easy. Even in this case I think it is probably still a good idea for the dependant devices to increment the refcount of the prereq devices.

Agreed on the refcounting.

#23 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Grant Likely

On 11/17/2010 11:11 AM, Grant Likely wrote:
[...]

Quoted 8 lines

To start, I'm not a fan of matching by name. It's fragile because it makes assumptions about how devices will be names when they actually appear (ie. Sometimes .id is dynamically assigned). Ideally I'd prefer to have direct references (ie. pointers) to the devices that need to be registered, which *shouldn't* be difficult to handle. That guarantees that the correct device is always referenced. (aside: the device-tree use case provides this information by having direct 'phandle' references between dependencies.)

The pointer approach is possibly problematic with devices that get registered by other drivers/masters (mfd, spi, i2c, etc.). With these devices the board doesn't really have a reference to the device in question.

Something along the following lines may be better:

int device_requires(struct device *dev, const char *res); int device_provides(struct device *provider, const char *res);

where res is a string of the form "gpio:25", "regulator:vlcd", or even "dev:<dev_name>".

device_requires() would typically be used by board implementations, and device_provides() would be called by gpiolib, regulator core, device core, etc.

I guess this is somewhat along the lines of an earlier discussion on the PPC list ([1] below), except that the drivers don't get probed until specified prereqs are available.

Regards
Cyril.

[1] http://www.spinics.net/lists/linux-embedded/msg02764.html

#24 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Grant Likely
Quoted 3 lines · Grant Likely

Also, any dependency tracking must work across bus_types. It is not sufficient to only handle the platform_devices use-case. All bus types have this need.

Agreed.

Quoted 8 lines

I see a few potential approaches.

Option 1: Add a list of prerequisite devices to struct device and modify driver core so that it defers binding to a driver until all the prerequisites are already bound. This can probably be implemented in a way that works for all bus types transparently. Before binding a driver, the driver core would increase the ref count on each of the prereq devices, and decrease it again when the driver is removed.

I see loops happening easily that prevent any device from being bound. That could get tricky to debug :(

Quoted 3 lines

Option 2: On a per-bus_type basis have a separate registration and the bus type code would hold the device unregistered in a pending list. This option would also add a prerequisites list to struct device.

When would we process the "pending list"?

I can see something like this working, up to a point. Once device (or driver) registration is complete, we would walk the lists of busses and see if anything new wants to be bound again, now that something new has shown up, instead of just walking the single bus.

But then we have the issue of devices that never are bound to anything, it could get a little "noisy" with them never binding, but we can't rely on the fact that not all devices are not bound to know when to stop trying.

This might be the simplest to try out as we do almost all of this today in the driver core (walk the list and try to bind all unbound devices to a new driver.) Just extend that walking to walk all other busses as well. But this would require that the drivers know when they can't bind to a device due to something not being set up properly, which I don't know if is always true.

Quoted 20 lines

Option 3: Don't try to handle it in the bus_type or driver core code at all, but rather provide board support code with helpers to make waiting for other devices easy. Even in this case I think it is probably still a good idea for the dependant devices to increment the refcount of the prereq devices.

Perhaps something that is used like:

void do_second_registration(void)

{
	/* register list of dependant devices */
}

and then in the primary registration function:

	...
	device_notify_when_bound(&prereq_pdev->dev,
				 do_second_registration);
	platform_device_add(prereq_pdev);
	...
Quoted 8 lines

which would reduce the boilerplate, but remain flexible. However, while flexable, option 3 doesn't solve the dependency tracking problem, and it still requires some gymnastics to handle multiple dependencies.

On a related issue, it may also be desirable for each device to maintain a list of devices that have claimed dependency on it for the purpose of debugability.

That might be the simplest as each "board type" knows which devices it wants to register and in what order, right?

Hm, what about the case for dynamic devices that want to turn on and off different parts and bring them up in specific order depending on what "mode" the user wanted at the moment? That would force stuff to be hard coded in wierd ways I imagine.

Ick, not a simple problem...

greg k-h

#25 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

Quoted 35 lines · Greg KH
Quoted 3 lines · Grant Likely

Also, any dependency tracking must work across bus_types. It is not sufficient to only handle the platform_devices use-case. All bus types have this need.

Agreed.

Quoted 8 lines

I see a few potential approaches.

Option 1: Add a list of prerequisite devices to struct device and modify driver core so that it defers binding to a driver until all the prerequisites are already bound. This can probably be implemented in a way that works for all bus types transparently. Before binding a driver, the driver core would increase the ref count on each of the prereq devices, and decrease it again when the driver is removed.

I see loops happening easily that prevent any device from being bound. That could get tricky to debug :(

Quoted 3 lines

Option 2: On a per-bus_type basis have a separate registration and the bus type code would hold the device unregistered in a pending list. This option would also add a prerequisites list to struct device.

When would we process the "pending list"?

I can see something like this working, up to a point. Once device (or driver) registration is complete, we would walk the lists of busses and see if anything new wants to be bound again, now that something new has shown up, instead of just walking the single bus.

But then we have the issue of devices that never are bound to anything, it could get a little "noisy" with them never binding, but we can't rely on the fact that not all devices are not bound to know when to stop trying.

Quoted 12 lines

This might be the simplest to try out as we do almost all of this today in the driver core (walk the list and try to bind all unbound devices to a new driver.) Just extend that walking to walk all other busses as well. But this would require that the drivers know when they can't bind to a device due to something not being set up properly, which I don't know if is always true.

Quoted 5 lines

Option 3: Don't try to handle it in the bus_type or driver core code at all, but rather provide board support code with helpers to make waiting for other devices easy. Even in this case I think it is probably still a good idea for the dependant devices to increment the refcount of the prereq devices.

That's necessary IMO.

Quoted 19 lines
Quoted 19 lines

Perhaps something that is used like:

void do_second_registration(void)

{
	/* register list of dependant devices */
}

and then in the primary registration function:

	...
	device_notify_when_bound(&prereq_pdev->dev,
				 do_second_registration);
	platform_device_add(prereq_pdev);
	...

which would reduce the boilerplate, but remain flexible. However, while flexable, option 3 doesn't solve the dependency tracking problem, and it still requires some gymnastics to handle multiple dependencies.

Quoted 6 lines
Quoted 3 lines

On a related issue, it may also be desirable for each device to maintain a list of devices that have claimed dependency on it for the purpose of debugability.

That might be the simplest as each "board type" knows which devices it wants to register and in what order, right?

Ironically enough, we also have this problem in ACPI where there are power resources that "regular" devices may depend on in pretty much the same way as discussed here. Those power resources are represented as devices, so the problem is really analogous.

In ACPI, though, basically all devices are registered by the same routine that walks the namespace (which is a tree-like structure) and registers all devices it finds there. Before registering a device it examines its properties and, among other things, it finds what power resources the device depends on. Then, it may invoke itself in a recursive way to register those power resources before registering the device (the recurrence is one-level only, because power resources cannot depend on anything else). Since the driver for power resources has been already registered at that point, we know it will bind to the power resource device objects as soon as they are registered. This is done in a patch series I posted yesterday, actaully.

I'm not sure if this approach can be generalized somehow, but in the ACPI case it works just fine.

Thanks,
Rafael

#26 lore raw

PATCH v5 4/12 spi: add ti-ssp spi master driver

In reply to Grant Likely
Quoted 10 lines · Grant Likely

After discussions about device init dependencies at plumbers, and since this is the first SPI device driver I've reviewed since that dicussion, this driver gets to be the first to implement the proposed policy. :-)

Change this to module_initcall(). Many spi and i2c drivers use module or subsys_initcall to try and influence driver probe order so that certain regulator chips get registered before the devices that try to use them. This approach is insane.

Last I observed the issue ... the situation was that various core drivers were required to be able to say that a key subsystem was functional ... with said subsystem required to boot properly.

The dependency being, that is, driver on subsystem (but that subsystem needed a core/bus driver running before it could work.

What's insane is that Linux *STILL* has no clean way to express that type of system dependency ... where driver dependencies are pure side effects. (Albeit ones that never change on many platforms, but where board-specific differences are routine, and have the same kind of indirect dependencies.

- Dave

#27 lore raw

PATCH v5 5/12 davinci: add spi devices on tnetv107x evm

In reply to Cyril Chemparathy

This patch adds definitions for spi devices on the tnetv107x evm platform.

---
 arch/arm/mach-davinci/board-tnetv107x-evm.c |   43 +++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-tnetv107x-evm.c +43 -0
index ef526b1..1a656e8 100644
@@ -25,6 +25,7 @@
 #include <linux/mtd/partitions.h>
 #include <linux/input.h>
 #include <linux/input/matrix_keypad.h>
+#include <linux/spi/spi.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach-types.h>
@@ -37,6 +38,7 @@
 
 #define EVM_MMC_WP_GPIO		21
 #define EVM_MMC_CD_GPIO		24
+#define EVM_SPI_CS_GPIO		54
 
 static int initialize_gpio(int gpio, char *desc)
 {
@@ -202,9 +204,45 @@ static struct matrix_keypad_platform_data keypad_config = {
 	.no_autorepeat	= 0,
 };
 
+static void spi_select_device(int cs)
+{
+	static int gpio;
+
+	if (!gpio) {
+		int ret;
+		ret = gpio_request(EVM_SPI_CS_GPIO, "spi chipsel");
+		if (ret < 0) {
+			pr_err("cannot open spi chipsel gpio\n");
+			gpio = -ENOSYS;
+			return;
+		} else {
+			gpio = EVM_SPI_CS_GPIO;
+			gpio_direction_output(gpio, 0);
+		}
+	}
+
+	if (gpio < 0)
+		return;
+
+	return gpio_set_value(gpio, cs ? 1 : 0);
+}
+
+static struct ti_ssp_spi_data spi_master_data = {
+	.num_cs	= 2,
+	.select	= spi_select_device,
+	.iosel	= SSP_PIN_SEL(0, SSP_CLOCK)	| SSP_PIN_SEL(1, SSP_DATA) |
+		  SSP_PIN_SEL(2, SSP_CHIPSEL)	| SSP_PIN_SEL(3, SSP_IN)   |
+		  SSP_INPUT_SEL(3),
+};
+
 static struct ti_ssp_data ssp_config = {
 	.out_clock	= 250 * 1000,
 	.dev_data	= {
+		[1] = {
+			.dev_name = "ti-ssp-spi",
+			.pdata = &spi_master_data,
+			.pdata_size = sizeof(spi_master_data),
+		},
 	},
 };
 
@@ -216,6 +254,9 @@ static struct tnetv107x_device_info evm_device_info __initconst = {
 	.ssp_config		= &ssp_config,
 };
 
+static struct spi_board_info spi_info[] __initconst = {
+};
+
 static __init void tnetv107x_evm_board_init(void)
 {
 	davinci_cfg_reg_list(sdio1_pins);
@@ -223,6 +264,8 @@ static __init void tnetv107x_evm_board_init(void)
 	davinci_cfg_reg_list(ssp_pins);
 
 	tnetv107x_devices_init(&evm_device_info);
+
+	spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
 }
 
 #ifdef CONFIG_SERIAL_8250_CONSOLE
Signature · 1 line
1.7.1
#28 lore raw

PATCH v5 6/12 regulator: add driver for tps6524x regulator

In reply to Cyril Chemparathy

TPS6524X provides three step-down converters and two general-purpose LDO voltage regulators. This device is interfaced using SPI.

---
 drivers/regulator/Kconfig              |   10 +
 drivers/regulator/Makefile             |    1 +
 drivers/regulator/tps6524x-regulator.c |  692 ++++++++++++++++++++++++++++++++
 3 files changed, 703 insertions(+), 0 deletions(-)
 create mode 100644 drivers/regulator/tps6524x-regulator.c
drivers/regulator/Kconfig +10 -0
index 172951b..a6f8536 100644
@@ -235,5 +235,15 @@ config REGULATOR_TPS6586X
 	help
 	  This driver supports TPS6586X voltage regulator chips.
 
+config REGULATOR_TPS6524X
+	tristate "TI TPS6524X Power regulators"
+	depends on SPI
+	help
+	  This driver supports TPS6524X voltage regulator chips. TPS6524X
+	  provides three step-down converters and two general-purpose LDO
+	  voltage regulators.  This device is interfaced using a customized
+	  serial interface currently supported on the sequencer serial
+	  port controller.
+
 endif
 
drivers/regulator/Makefile +1 -0
index 8285fd8..a8e5bc0 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o
 
 obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o
 obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o
+obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o
 obj-$(CONFIG_REGULATOR_88PM8607) += 88pm8607.o
 obj-$(CONFIG_REGULATOR_ISL6271A) += isl6271a-regulator.o
 obj-$(CONFIG_REGULATOR_AB8500)	+= ab8500.o
drivers/regulator/tps6524x-regulator.c new file +692 -0

692 lines not on this page · raw message

Signature · 1 line
1.7.1
#29 lore raw

PATCH v5 7/12 davinci: add tnetv107x evm regulators

In reply to Cyril Chemparathy

This patch adds regulator and spi board info definitions for the tps6524x power management IC found on tnetv107x evm boards.

---
 arch/arm/mach-davinci/board-tnetv107x-evm.c |   85 +++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-tnetv107x-evm.c +85 -0
index 1a656e8..ca23516 100644
@@ -26,6 +26,9 @@
 #include <linux/input.h>
 #include <linux/input/matrix_keypad.h>
 #include <linux/spi/spi.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/consumer.h>
+#include <linux/regulator/driver.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach-types.h>
@@ -254,7 +257,89 @@ static struct tnetv107x_device_info evm_device_info __initconst = {
 	.ssp_config		= &ssp_config,
 };
 
+static struct regulator_consumer_supply usb_consumers[] = {
+	REGULATOR_SUPPLY("vbus", "musb_hdrc.1"),
+};
+
+static struct regulator_consumer_supply lcd_consumers[] = {
+	REGULATOR_SUPPLY("vlcd", "tps6116x"),
+};
+
+static struct regulator_init_data regulators[] = {
+	{
+		.constraints		= {
+			.name		= "DCDC1",
+			.min_uV		= 1000000,
+			.max_uV		= 1000000,
+			.always_on	= 1,
+			.boot_on	= 1,
+		},
+	},
+	{
+		.constraints		= {
+			.name		= "DCDC2",
+			.min_uV		= 1800000,
+			.max_uV		= 1800000,
+			.always_on	= 1,
+			.boot_on	= 1,
+		},
+	},
+	{
+		.constraints		= {
+			.name		= "DCDC3",
+			.min_uV		= 3300000,
+			.max_uV		= 3300000,
+			.always_on	= 1,
+			.boot_on	= 1,
+		},
+	},
+	{
+		.constraints		= {
+			.name		= "LDO1",
+			.min_uV		= 4800000,
+			.max_uV		= 4800000,
+			.always_on	= 1,
+			.boot_on	= 1,
+		},
+	},
+	{
+		.constraints		= {
+			.name		= "LDO1",
+			.min_uV		= 3300000,
+			.max_uV		= 3300000,
+			.always_on	= 1,
+			.boot_on	= 1,
+		},
+	},
+	{
+		.num_consumer_supplies	= ARRAY_SIZE(usb_consumers),
+		.consumer_supplies	= usb_consumers,
+		.constraints		= {
+			.name		= "USB",
+			.min_uA		= 200000,
+			.max_uA		= 1000000,
+			.valid_ops_mask	= REGULATOR_CHANGE_CURRENT |
+					  REGULATOR_CHANGE_STATUS,
+		},
+	},
+	{
+		.num_consumer_supplies	= ARRAY_SIZE(lcd_consumers),
+		.consumer_supplies	= lcd_consumers,
+		.constraints		= {
+			.name		= "LCD",
+			.valid_ops_mask	= REGULATOR_CHANGE_STATUS,
+		},
+	},
+};
+
 static struct spi_board_info spi_info[] __initconst = {
+	{
+		.modalias	= "tps6524x",
+		.bus_num	= 1,
+		.chip_select	= 0,
+		.mode		= SPI_MODE_0,
+		.platform_data	= regulators,
+	},
 };
 
 static __init void tnetv107x_evm_board_init(void)
Signature · 1 line
1.7.1
#30 lore raw

PATCH v5 8/12 gpio: add ti-ssp gpio driver

In reply to Cyril Chemparathy

TI's SSP controller pins can be directly read and written to behave like a GPIO. This patch adds a GPIO driver that exposes such functionality.

---
 drivers/mfd/Kconfig        |   10 ++
 drivers/mfd/Makefile       |    1 +
 drivers/mfd/ti-ssp-gpio.c  |  205 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ti_ssp.h |    4 +
 4 files changed, 220 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp-gpio.c
drivers/mfd/Kconfig +10 -0
index 7dcc03a..b193580 100644
@@ -102,6 +102,16 @@ config MFD_TI_SSP_SPI
 	  To compile this driver as a module, choose M here: the
 	  module will be called ti-ssp-spi.
 
+config MFD_TI_SSP_GPIO
+	tristate "TI Sequencer Serial Port - GPIO Support"
+	depends on GPIOLIB && MFD_TI_SSP
+	help
+	  Say yes here to support a GPIO interface on TI SSP port pins.
+	  Each SSP port translates into 4 GPIOs.
+
+	  This driver can also be built as a module. If so, the module
+	  will be called ti-ssp-gpio.
+
 config HTC_EGPIO
 	bool "HTC EGPIO support"
 	depends on GENERIC_HARDIRQS && GPIOLIB && ARM
drivers/mfd/Makefile +1 -0
index ba97f48..87b5de8 100644
@@ -16,6 +16,7 @@ obj-$(CONFIG_MFD_DAVINCI_VOICECODEC)	+= davinci_voicecodec.o
 obj-$(CONFIG_MFD_DM355EVM_MSP)	+= dm355evm_msp.o
 obj-$(CONFIG_MFD_TI_SSP)	+= ti-ssp.o
 obj-$(CONFIG_MFD_TI_SSP_SPI)	+= ti-ssp-spi.o
+obj-$(CONFIG_MFD_TI_SSP_GPIO)	+= ti-ssp-gpio.o
 
 obj-$(CONFIG_MFD_STMPE)		+= stmpe.o
 obj-$(CONFIG_MFD_TC35892)	+= tc35892.o
drivers/mfd/ti-ssp-gpio.c new file +205 -0

205 lines not on this page · raw message

include/linux/mfd/ti_ssp.h +4 -0
index dbb4b43..10c65bb 100644
@@ -38,6 +38,10 @@ struct ti_ssp_spi_data {
 	void		(*select)(int cs);
 };
 
+struct ti_ssp_gpio_data {
+	int		start;
+};
+
 /*
  * Sequencer port IO pin configuration bits.  These do not correlate 1-1 with
  * the hardware.  The iosel field in the port data combines iosel1 and iosel2,
Signature · 1 line
1.7.1
#31 lore raw

PATCH v5 8/12 gpio: add ti-ssp gpio driver

Quoted 11 lines · Cyril Chemparathy

TI's SSP controller pins can be directly read and written to behave like a GPIO. This patch adds a GPIO driver that exposes such functionality.

---
 drivers/mfd/Kconfig        |   10 ++
 drivers/mfd/Makefile       |    1 +
 drivers/mfd/ti-ssp-gpio.c  |  205 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/ti_ssp.h |    4 +
 4 files changed, 220 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mfd/ti-ssp-gpio.c

Should go under drivers/gpio. This is not a multifunction driver.

drivers/mfd/ti-ssp-gpio.c line 31

Quoted 11 lines
drivers/mfd/ti-ssp-gpio.c new file +11 -0
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/err.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/ti_ssp.h>
+
+struct ti_ssp_gpio {

This is a confusing name because it sounds like this struct maps to a single gpio rather than bank. Perhaps a better name is ti_ssp_gpio_chip?

drivers/mfd/ti-ssp-gpio.c line 33

Quoted 2 lines
drivers/mfd/ti-ssp-gpio.c new file +2 -0
+	struct gpio_chip		chip;
+#define chip2gpio(chip)	container_of(chip, struct ti_ssp_gpio, chip)

Please don't put #define's in the middle of a struct. Move it either before or after the structure definition. It is also confusingly named, something like to_ti_ssp_gpio_chip might be better.

drivers/mfd/ti-ssp-gpio.c line 93

Quoted 10 lines
drivers/mfd/ti-ssp-gpio.c new file +10 -0
+static int value_get(struct gpio_chip *chip, unsigned gpio_num)
+{
+	struct ti_ssp_gpio *gpio = chip2gpio(chip);
+	int ret;
+
+	spin_lock(&gpio->lock);
+
+	ret = ti_ssp_raw_read(gpio->dev);
+	if (ret >= 0)
+		ret = (ret & BIT(gpio_num)) ? 1 : 0;
		ret = !!(ret & BIT(gpio_num));
Quoted 27 lines
drivers/mfd/ti-ssp-gpio.c new file +26 -0
+
+	spin_unlock(&gpio->lock);
+	return ret;
+}
 
+static int __devinit ti_ssp_gpio_probe(struct platform_device *pdev)
+{
+	const struct ti_ssp_gpio_data *pdata = pdev->dev.platform_data;
+	struct device *dev = &pdev->dev;
+	struct ti_ssp_gpio *gpio;
+	int error;
+
+	if (!pdata) {
+		dev_err(dev, "platform data not found\n");
+		return -EINVAL;
+	}
+
+	gpio = kzalloc(sizeof(*gpio), GFP_KERNEL);
+	if (!gpio) {
+		dev_err(dev, "cannot allocate driver data\n");
+		return -ENOMEM;
+	}
+
+	gpio->dev = dev;
+	gpio->iosel = SSP_PIN_SEL(0, SSP_IN) | SSP_PIN_SEL(1, SSP_IN) |
+		      SSP_PIN_SEL(2, SSP_IN) | SSP_PIN_SEL(3, SSP_IN);
+	error = ti_ssp_set_iosel(gpio->dev, gpio->iosel);

drivers/mfd/ti-ssp-gpio.c line 146

Quoted 10 lines
drivers/mfd/ti-ssp-gpio.c new file +10 -0
+	if (error < 0) {
+		dev_err(dev, "gpio io setup failed (%d)\n", error);
+		goto error;
+	}
+
+	spin_lock_init(&gpio->lock);
+	platform_set_drvdata(pdev, gpio);
+
+	gpio->chip.base  = pdata->start;
+	gpio->chip.ngpio = 4;

Is this always four or can the SSP peripheral be configured to have varying numbers of gpios. Maybe the number of gpios should be passed via platform data?

Quoted 11 lines
drivers/mfd/ti-ssp-gpio.c new file +11 -0
+	gpio->chip.dev   = &pdev->dev;
+	gpio->chip.label = "ti_ssp_gpio";
+	gpio->chip.owner = THIS_MODULE;
+	gpio->chip.get   = value_get;
+	gpio->chip.set   = value_set;
+	gpio->chip.direction_input  = direction_in;
+	gpio->chip.direction_output = direction_out;
+
+	error = gpiochip_add(&gpio->chip);
+	if (error < 0) {
+		dev_err(dev, "gpio chip registration failed (%d)\n", error);

drivers/mfd/ti-ssp-gpio.c line 167

Quoted 10 lines
drivers/mfd/ti-ssp-gpio.c new file +10 -0
+		goto error;
+	}
+
+	dev_info(dev, "ssp gpio interface registered\n");
+	return 0;
+
+error:
+	kfree(gpio);
+	return error;
+}

~Ryan

Signature · 7 lines
Bluewater Systems Ltd - ARM Technology Solution Centre

Ryan Mallon         		5 Amuri Park, 404 Barbadoes St
ryan at bluewatersys.com         	PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com	New Zealand
Phone: +64 3 3779127		Freecall: Australia 1800 148 751
Fax:   +64 3 3779135			  USA 1800 261 2934
#32 lore raw

PATCH v5 8/12 gpio: add ti-ssp gpio driver

Quoted 6 lines · Ryan Mallon
Quoted 5 lines · Cyril Chemparathy

TI's SSP controller pins can be directly read and written to behave like a GPIO. This patch adds a GPIO driver that exposes such functionality.

---

[...]

Quoted 10 lines

drivers/mfd/ti-ssp-gpio.c line 146

Quoted 5 lines
drivers/mfd/ti-ssp-gpio.c new file +5 -0
+	spin_lock_init(&gpio->lock);
+	platform_set_drvdata(pdev, gpio);
+
+	gpio->chip.base  = pdata->start;
+	gpio->chip.ngpio = 4;

Is this always four or can the SSP peripheral be configured to have varying numbers of gpios. Maybe the number of gpios should be passed via platform data?

This can only be 4 (hw defined per-port limit).

I have changed as per your other comments, and will post an update.

Thanks
Cyril.

#33 lore raw

PATCH v5 9/12 davinci: add tnetv107x evm ti-ssp gpio device

In reply to Cyril Chemparathy

This patch adds definitions to hook up one of the ti-ssp ports to the SSP GPIO driver.

---
 arch/arm/mach-davinci/board-tnetv107x-evm.c |   11 +++++++++++
 1 files changed, 11 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-tnetv107x-evm.c +11 -0
index ca23516..e3863dd 100644
@@ -39,6 +39,8 @@
 #include <mach/cp_intc.h>
 #include <mach/tnetv107x.h>
 
+#define SSP_GPIO_START		128
+
 #define EVM_MMC_WP_GPIO		21
 #define EVM_MMC_CD_GPIO		24
 #define EVM_SPI_CS_GPIO		54
@@ -238,9 +240,18 @@ static struct ti_ssp_spi_data spi_master_data = {
 		  SSP_INPUT_SEL(3),
 };
 
+static struct ti_ssp_gpio_data ssp_gpio_data = {
+	.start		= SSP_GPIO_START,
+};
+
 static struct ti_ssp_data ssp_config = {
 	.out_clock	= 250 * 1000,
 	.dev_data	= {
+		[0] = {
+			.dev_name = "ti-ssp-gpio",
+			.pdata = &ssp_gpio_data,
+			.pdata_size = sizeof(ssp_gpio_data),
+		},
 		[1] = {
 			.dev_name = "ti-ssp-spi",
 			.pdata = &spi_master_data,
Signature · 1 line
1.7.1
#34 lore raw

PATCH v5 10/12 backlight: add support for tps6116x controller

In reply to Cyril Chemparathy

TPS6116x is an EasyScale backlight controller device. This driver supports TPS6116x devices connected on a single GPIO.

---
 drivers/video/backlight/Kconfig    |    7 +
 drivers/video/backlight/Makefile   |    2 +-
 drivers/video/backlight/tps6116x.c |  339 ++++++++++++++++++++++++++++++++++++
 3 files changed, 347 insertions(+), 1 deletions(-)
 create mode 100644 drivers/video/backlight/tps6116x.c
drivers/video/backlight/Kconfig +7 -0
index e54a337..06e868e 100644
@@ -307,6 +307,13 @@ config BACKLIGHT_PCF50633
 	  If you have a backlight driven by a NXP PCF50633 MFD, say Y here to
 	  enable its driver.
 
+config BACKLIGHT_TPS6116X
+	tristate "TPS6116X LCD Backlight"
+	depends on GENERIC_GPIO
+	help
+	  This driver controls the LCD backlight level for EasyScale capable
+	  SSP connected backlight controllers.
+
 endif # BACKLIGHT_CLASS_DEVICE
 
 endif # BACKLIGHT_LCD_SUPPORT
drivers/video/backlight/Makefile +1 -1
index 44c0f81..5d407c8 100644
@@ -35,4 +35,4 @@ obj-$(CONFIG_BACKLIGHT_ADP5520)	+= adp5520_bl.o
 obj-$(CONFIG_BACKLIGHT_ADP8860)	+= adp8860_bl.o
 obj-$(CONFIG_BACKLIGHT_88PM860X) += 88pm860x_bl.o
 obj-$(CONFIG_BACKLIGHT_PCF50633)	+= pcf50633-backlight.o
-
+obj-$(CONFIG_BACKLIGHT_TPS6116X)+= tps6116x.o
drivers/video/backlight/tps6116x.c new file +339 -0

339 lines not on this page · raw message

Signature · 1 line
1.7.1
#35 lore raw

PATCH v5 11/12 davinci: add tnetv107x evm backlight device

In reply to Cyril Chemparathy

The tnetv107x evm board has a backlight device that is connected on one of the SSP ports. This patch adds the board definitions necessary to plug the backlight driver to the GPIO corresponding to this SSP pin.

---
 arch/arm/mach-davinci/board-tnetv107x-evm.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-tnetv107x-evm.c +9 -0
index e3863dd..945a958 100644
@@ -44,6 +44,7 @@
 #define EVM_MMC_WP_GPIO		21
 #define EVM_MMC_CD_GPIO		24
 #define EVM_SPI_CS_GPIO		54
+#define EVM_BACKLIGHT_GPIO	(SSP_GPIO_START + 2)
 
 static int initialize_gpio(int gpio, char *desc)
 {
@@ -353,6 +354,12 @@ static struct spi_board_info spi_info[] __initconst = {
 	},
 };
 
+static struct platform_device backlight_device = {
+	.name		= "tps6116x",
+	.id		= -1,
+	.dev.platform_data = (void *)EVM_BACKLIGHT_GPIO,
+};
+
 static __init void tnetv107x_evm_board_init(void)
 {
 	davinci_cfg_reg_list(sdio1_pins);
@@ -361,6 +368,8 @@ static __init void tnetv107x_evm_board_init(void)
 
 	tnetv107x_devices_init(&evm_device_info);
 
+	platform_device_register(&backlight_device);
+
 	spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
 }
 
Signature · 1 line
1.7.1
#36 lore raw

PATCH v5 12/12 davinci: add tnetv107x evm i2c eeprom device

In reply to Cyril Chemparathy

The tnetv107x evm board has an I2C device connected on one of the SSP ports. This patch adds board definitions for a GPIO based I2C master, as well as definitions for the eeprom device on these boards.

---
 arch/arm/mach-davinci/board-tnetv107x-evm.c |   30 +++++++++++++++++++++++++++
 1 files changed, 30 insertions(+), 0 deletions(-)
arch/arm/mach-davinci/board-tnetv107x-evm.c +30 -0
index 945a958..8059c7d 100644
@@ -29,6 +29,9 @@
 #include <linux/regulator/machine.h>
 #include <linux/regulator/consumer.h>
 #include <linux/regulator/driver.h>
+#include <linux/i2c.h>
+#include <linux/i2c/at24.h>
+#include <linux/i2c-gpio.h>
 
 #include <asm/mach/arch.h>
 #include <asm/mach-types.h>
@@ -44,6 +47,8 @@
 #define EVM_MMC_WP_GPIO		21
 #define EVM_MMC_CD_GPIO		24
 #define EVM_SPI_CS_GPIO		54
+#define EVM_I2C_SDA_GPIO	(SSP_GPIO_START + 0)
+#define EVM_I2C_SCL_GPIO	(SSP_GPIO_START + 1)
 #define EVM_BACKLIGHT_GPIO	(SSP_GPIO_START + 2)
 
 static int initialize_gpio(int gpio, char *desc)
@@ -360,6 +365,29 @@ static struct platform_device backlight_device = {
 	.dev.platform_data = (void *)EVM_BACKLIGHT_GPIO,
 };
 
+struct i2c_gpio_platform_data i2c_data = {
+	.sda_pin	= EVM_I2C_SDA_GPIO,
+	.scl_pin	= EVM_I2C_SCL_GPIO,
+};
+
+static struct platform_device i2c_device = {
+	.name		= "i2c-gpio",
+	.id		= 0,
+	.dev.platform_data = &i2c_data,
+};
+
+static struct at24_platform_data at24_config = {
+	.byte_len	= SZ_16K / 8,
+	.page_size	= 16,
+};
+
+static struct i2c_board_info i2c_info[] __initconst =  {
+	{
+		I2C_BOARD_INFO("24c16", 0x50),
+		.platform_data	= &at24_config,
+	},
+};
+
 static __init void tnetv107x_evm_board_init(void)
 {
 	davinci_cfg_reg_list(sdio1_pins);
@@ -369,8 +397,10 @@ static __init void tnetv107x_evm_board_init(void)
 	tnetv107x_devices_init(&evm_device_info);
 
 	platform_device_register(&backlight_device);
+	platform_device_register(&i2c_device);
 
 	spi_register_board_info(spi_info, ARRAY_SIZE(spi_info));
+	i2c_register_board_info(0, i2c_info, ARRAY_SIZE(i2c_info));
 }
 
 #ifdef CONFIG_SERIAL_8250_CONSOLE
Signature · 1 line
1.7.1