Skip to contentSkip to conversation

MIPI HSI device support for OMAP platforms

RFC PATCH In review Sebastien Jan 2 participants 15 messages Oct 30, 2009

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover MIPI HSI device support for OMAP platforms

This is an RFC for a series of patch to add the support of MIPI HSI and SSI devices to OMAP platforms.
The patch includes the HSI device driver and the device files for MIPI HSI and SSI.

The driver is made of 2 distinct modules:
- omap_hsi: is the Low-Level Driver (or hardware driver). It provides a kernel functional interface, to be used by other kernel modules and abstracts the HW.
This part of the patch is based on Nokia SSI driver, already submitted as RFC by Carlos Chinea [1].
- hsi-char: is a char device driver proposing a user-space interface for using the HSI and relies on omap_hsi.
This part of the patch is based on a development from Andras Domokos.
The intent is to propose a single HSI driver that can support MIPI HSI 1.1 as well as previous implementations (SSI) for OMAP platforms (OMAP3 / OMAP4).

The driver core functionalities are there and ready for review. The following updates will come in the following weeks / months:
- Clocks and Power Management support for OMAP4 platform (HSI device file)
- HSI-char interface documentation

Validation: The driver is validated on 3430 SDP (with a HW loopback on the SSI device), and is being validated on 4430 Virtio platform (MIPI HSI device).

[1] http://lwn.net/Articles/301918/

Thanks for your comments!

Sebastien JAN

Sebastien Jan (9):
HSI: Low Level Driver interface
HSI: Low Level Driver core
HSI: Low Level Driver device management
HSI: Low Level Driver debugfs support
HSI: Low Level Driver documentation
HSI: character driver interface
HSI: character driver low level interface
HSI: HSI device support
HSI: SSI device support and integration on 3430SDP platform

 Documentation/hsi/hsi.txt             |  319 ++++++++++++++++
 arch/arm/mach-omap2/Makefile          |    2 +
 arch/arm/mach-omap2/board-3430sdp.c   |   12 +
 arch/arm/mach-omap2/hsi.c             |  497 +++++++++++++++++++++++++
 arch/arm/mach-omap2/mux.c             |   17 +
 arch/arm/mach-omap2/ssi.c             |  530 ++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/hsi.h |  432 ++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/mux.h |   10 +
 drivers/Kconfig                       |    2 +
 drivers/Makefile                      |    1 +
 drivers/hsi/Kconfig                   |   58 +++
 drivers/hsi/Makefile                  |   17 +
 drivers/hsi/hsi-char.c                |  526 ++++++++++++++++++++++++++
 drivers/hsi/hsi-char.h                |   31 ++
 drivers/hsi/hsi-if.c                  |  642 ++++++++++++++++++++++++++++++++
 drivers/hsi/hsi-if.h                  |   65 ++++
 drivers/hsi/hsi_driver.c              |  644 ++++++++++++++++++++++++++++++++
 drivers/hsi/hsi_driver.h              |  308 +++++++++++++++
 drivers/hsi/hsi_driver_bus.c          |  182 +++++++++
 drivers/hsi/hsi_driver_debugfs.c      |  486 ++++++++++++++++++++++++
 drivers/hsi/hsi_driver_dma.c          |  469 +++++++++++++++++++++++
 drivers/hsi/hsi_driver_fifo.c         |  289 +++++++++++++++
 drivers/hsi/hsi_driver_gpio.c         |   79 ++++
 drivers/hsi/hsi_driver_if.c           |  657 +++++++++++++++++++++++++++++++++
 drivers/hsi/hsi_driver_int.c          |  339 +++++++++++++++++
 include/linux/hsi_char.h              |   71 ++++
 include/linux/hsi_driver_if.h         |  180 +++++++++
 27 files changed, 6865 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hsi/hsi.txt
 create mode 100644 arch/arm/mach-omap2/hsi.c
 create mode 100644 arch/arm/mach-omap2/ssi.c
 create mode 100644 arch/arm/plat-omap/include/mach/hsi.h
 create mode 100644 drivers/hsi/Kconfig
 create mode 100644 drivers/hsi/Makefile
 create mode 100644 drivers/hsi/hsi-char.c
 create mode 100644 drivers/hsi/hsi-char.h
 create mode 100644 drivers/hsi/hsi-if.c
 create mode 100644 drivers/hsi/hsi-if.h
 create mode 100644 drivers/hsi/hsi_driver.c
 create mode 100644 drivers/hsi/hsi_driver.h
 create mode 100644 drivers/hsi/hsi_driver_bus.c
 create mode 100644 drivers/hsi/hsi_driver_debugfs.c
 create mode 100644 drivers/hsi/hsi_driver_dma.c
 create mode 100644 drivers/hsi/hsi_driver_fifo.c
 create mode 100644 drivers/hsi/hsi_driver_gpio.c
 create mode 100644 drivers/hsi/hsi_driver_if.c
 create mode 100644 drivers/hsi/hsi_driver_int.c
 create mode 100644 include/linux/hsi_char.h
 create mode 100644 include/linux/hsi_driver_if.h
#1 lore raw

RFC PATCH 1/9 HSI: Low Level Driver interface

Driver kernel interface headers and implementation Driver Makefile and configuration integration

---
 drivers/Makefile              |    1 +
 drivers/hsi/Kconfig           |   44 +++
 drivers/hsi/Makefile          |   14 +
 drivers/hsi/hsi_driver_if.c   |  657 +++++++++++++++++++++++++++++++++++++++++
 include/linux/hsi_driver_if.h |  180 +++++++++++
 5 files changed, 896 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hsi/Kconfig
 create mode 100644 drivers/hsi/Makefile
 create mode 100644 drivers/hsi/hsi_driver_if.c
 create mode 100644 include/linux/hsi_driver_if.h
drivers/Makefile +1 -0
index 086857c..05b4190 100644
@@ -111,3 +111,4 @@ obj-$(CONFIG_VLYNQ)		+= vlynq/
 obj-$(CONFIG_STAGING)		+= staging/
 obj-y				+= platform/
 obj-y				+= ieee802154/
+obj-$(CONFIG_OMAP_HSI)		+= hsi/
drivers/hsi/Kconfig new file +44 -0

44 lines not on this page · raw message

drivers/hsi/Makefile new file +14 -0
new file mode 100644
index 0000000..a7f579b
@@ -0,0 +1,14 @@
+#
+# Makefile for HSI drivers
+#
+EXTRA_CFLAGS :=
+
+omap_hsi-objs	:=	hsi_driver.o hsi_driver_dma.o hsi_driver_int.o \
+			hsi_driver_if.o hsi_driver_bus.o hsi_driver_gpio.o \
+			hsi_driver_fifo.o
+
+ifeq ($(CONFIG_DEBUG_FS), y)
+	omap_hsi-objs += hsi_driver_debugfs.o
+endif
+
+obj-$(CONFIG_OMAP_HSI)	+= omap_hsi.o
drivers/hsi/hsi_driver_if.c new file +657 -0

657 lines not on this page · raw message

include/linux/hsi_driver_if.h new file +180 -0

180 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#2 lore raw

Re: [RFC PATCH 1/9] HSI: Low Level Driver interface

Hi,

drivers/Makefile obj-$(CONFIG_VLYNQ) += vlynq/ · line 114

Quoted 9 lines · ext Sebastien Jan
drivers/Makefile +1 -0
index 086857c..05b4190 100644
@@ -111,3 +111,4 @@ obj-$(CONFIG_VLYNQ)         += vlynq/
 obj-$(CONFIG_STAGING)          += staging/
 obj-y                          += platform/
 obj-y                          += ieee802154/
+obj-$(CONFIG_OMAP_HSI)         += hsi/

not omap specific.

drivers/hsi/Kconfig line 2

Quoted 8 lines
drivers/hsi/Kconfig new file +2 -0
new file mode 100644
index 0000000..e10b522
@@ -0,0 +1,44 @@
+#
+# OMAP HSI driver configuration

this shouldn't be omap specific. The comment is misleading.

Quoted 6 lines
drivers/hsi/Makefile new file +0 -0
new file mode 100644
index 0000000..a7f579b

drivers/hsi/Makefile line 8

Quoted 8 lines
drivers/hsi/Makefile new file +8 -0
@@ -0,0 +1,14 @@
+#
+# Makefile for HSI drivers
+#
+EXTRA_CFLAGS :=
+
+omap_hsi-objs  :=      hsi_driver.o hsi_driver_dma.o hsi_driver_int.o \
+                       hsi_driver_if.o hsi_driver_bus.o hsi_driver_gpio.o \
+                       hsi_driver_fifo.o

this should a more generic bus driver and it shouldn't know about how the hardware handles e.g. reset signals.

What I suggest you to do is:

Bus Layer
hsi.ko -> MIPI HSI Bus Driver (like i2c-core.c or usbcore, etc etc)

HW Layer
hsi-omap.ko-> OMAP HSI Controller (like i2c-omap.c)

Clients Layer
any protocol driver using the HSI bus

Quoted 17 lines
drivers/hsi/hsi_driver_if.c new file +11 -0
new file mode 100644
index 0000000..fb0035d
@@ -0,0 +1,657 @@
+/*
+ * hsi_driver_if.c
+ *
+ * Implements HSI hardware driver interfaces for the upper layers.
+ *
+ * Copyright (C) 2007-2008 Nokia Corporation. All rights reserved.
+ * Copyright (C) 2009 Texas Instruments, Inc.
+ *
+ * Author: Carlos Chinea <[email protected]>
+ * Author: Sebastien JAN <[email protected]>
+ *

drivers/hsi/hsi_driver_if.c line 21

Quoted 10 lines
drivers/hsi/hsi_driver_if.c new file +10 -0
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include "hsi_driver.h"

should be including something like:

#include <linux/hsi/driver.h>

or even

#include <linux/hsi.h>

drivers/hsi/hsi_driver_if.c

Quoted 11 lines
drivers/hsi/hsi_driver_if.c new file +10 -0
+int hsi_register_driver(struct hsi_device_driver *driver);
+void hsi_unregister_driver(struct hsi_device_driver *driver);
 
+int hsi_open(struct hsi_device *dev);
+int hsi_write(struct hsi_device *dev, u32 *addr, unsigned int size);
+void hsi_write_cancel(struct hsi_device *dev);
+int hsi_read(struct hsi_device *dev, u32 *addr, unsigned int size);
+void hsi_read_cancel(struct hsi_device *dev);
+int hsi_poll(struct hsi_device *dev);
+int hsi_ioctl(struct hsi_device *dev, unsigned int command, void *arg);
+void hsi_close(struct hsi_device *dev);

are these used on some file_operations structure ?

they should be implemented by the client driver if when it needs instead of letting the bus driver dictacte so much of the design.

drivers/hsi/hsi_driver_if.c

Quoted 7 lines
drivers/hsi/hsi_driver_if.c new file +7 -0
+void hsi_set_read_cb(struct hsi_device *dev,
+               void (*read_cb)(struct hsi_device *dev, unsigned int size));
+void hsi_set_write_cb(struct hsi_device *dev,
+               void (*write_cb)(struct hsi_device *dev, unsigned int size));
+void hsi_set_port_event_cb(struct hsi_device *dev,
+                               void (*port_event_cb)(struct hsi_device *dev,
+                                       unsigned int event, void *arg));

I wouldn't do it like this. If this is what I'm guessing, you're using these functions to be sure when a transfer has completed like ?

I remember suggesting this to be done more like the usb gadget framework:

struct hsi_request {
	void		*buf;
	dma_addr_t	dma;
	unsigned	length;
	unsigned	direction;

	void		(*complete)(struct hsi_device *hsi, struct
					hsi_channel *channel, struct
					hsi_request *req);
};

then, you send the data and when you get a complete irq, you call request->complete();

maybe that would be better ??

Signature · 1 line
balbi
#3 lore raw

RFC PATCH 2/9 HSI: Low Level Driver core

In reply to Sebastien Jan

Driver core implementation (driver registration, ...) Driver types definitions
HSI bus implementation

---
 drivers/hsi/hsi_driver.c     |  644 ++++++++++++++++++++++++++++++++++++++++++
 drivers/hsi/hsi_driver.h     |  308 ++++++++++++++++++++
 drivers/hsi/hsi_driver_bus.c |  182 ++++++++++++
 3 files changed, 1134 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hsi/hsi_driver.c
 create mode 100644 drivers/hsi/hsi_driver.h
 create mode 100644 drivers/hsi/hsi_driver_bus.c
drivers/hsi/hsi_driver.c new file +644 -0
new file mode 100644
index 0000000..4abaf08
@@ -0,0 +1,644 @@
+/*
+ * hsi_driver.c
+ *
+ * Implements HSI module interface, initialization, and PM related functions.
+ *
+ * Copyright (C) 2007-2008 Nokia Corporation. All rights reserved.
+ * Copyright (C) 2009 Texas Instruments, Inc.
+ *
+ * Author: Carlos Chinea <[email protected]>
+ * Author: Sebastien JAN <[email protected]>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/gpio.h>
+#include <linux/list.h>
+#include <mach/clock.h>
+#include "hsi_driver.h"
+
+#define	HSI_DRIVER_VERSION	"0.1"
+#define HSI_RESETDONE_TIMEOUT	10	/* 10 ms */
+#define HSI_RESETDONE_RETRIES	20	/* => max 200 ms waiting for reset */
+
+/* NOTE: Function called in interrupt context */
+int hsi_port_event_handler(struct hsi_port *p, unsigned int event, void *arg)
+{
+	struct hsi_channel *hsi_channel;
+	int ch;
+
+	if (event == HSI_EVENT_HSR_DATAAVAILABLE) {
+		/* The data-available event is channel-specific and must not be
+		 * broadcasted
+		 */
+		hsi_channel = p->hsi_channel + (int)arg;
+		read_lock(&hsi_channel->rw_lock);
+		if ((hsi_channel->dev) && (hsi_channel->port_event))
+			hsi_channel->port_event(hsi_channel->dev, event, arg);
+		read_unlock(&hsi_channel->rw_lock);
+	} else {
+		for (ch = 0; ch < p->max_ch; ch++) {
+			hsi_channel = p->hsi_channel + ch;
+			read_lock(&hsi_channel->rw_lock);
+			if ((hsi_channel->dev) && (hsi_channel->port_event))
+				hsi_channel->port_event(hsi_channel->dev,
+								event, arg);
+			read_unlock(&hsi_channel->rw_lock);
+		}
+	}
+	return 0;
+}
+
+static int hsi_clk_event(struct notifier_block *nb, unsigned long event,
+			 void *data)
+{
+/* TODO - implement support for clocks changes
+	switch (event) {
+	case CLK_PRE_RATE_CHANGE:
+		break;
+	case CLK_ABORT_RATE_CHANGE:
+		break;
+	case CLK_POST_RATE_CHANGE:
+		break;
+	default:
+		break;
+	}
+*/
+
+	/*
+	 * TODO: At this point we may emit a port event warning about the
+	 * clk frequency change to the upper layers.
+	 */
+	return NOTIFY_DONE;
+}
+
+static void hsi_dev_release(struct device *dev)
+{
+	/* struct device kfree is already made in unregister_hsi_devices().
+	 * Registering this function is necessary to avoid an error from
+	 * the device_release() function.
+	 */
+}
+
+static int __init reg_hsi_dev_ch(struct hsi_dev *hsi_ctrl, unsigned int p,
+				 unsigned int ch)
+{
+	struct hsi_device *dev;
+	struct hsi_port *port = &hsi_ctrl->hsi_port[p];
+	int err;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	dev->n_ctrl = hsi_ctrl->id;
+	dev->n_p = p;
+	dev->n_ch = ch;
+	dev->ch = &port->hsi_channel[ch];
+	dev->device.bus = &hsi_bus_type;
+	dev->device.parent = hsi_ctrl->dev;
+	dev->device.release = hsi_dev_release;
+	if (dev->n_ctrl < 0)
+		dev_set_name(&dev->device, "omap_hsi-p%u.c%u", p, ch);
+	else
+		dev_set_name(&dev->device, "omap_hsi%d-p%u.c%u", dev->n_ctrl, p,
+			     ch);
+
+	err = device_register(&dev->device);
+	if (err >= 0) {
+		write_lock_bh(&port->hsi_channel[ch].rw_lock);
+		port->hsi_channel[ch].dev = dev;
+		write_unlock_bh(&port->hsi_channel[ch].rw_lock);
+	} else {
+		kfree(dev);
+	}
+	return err;
+}
+
+static int __init register_hsi_devices(struct hsi_dev *hsi_ctrl)
+{
+	int port;
+	int ch;
+	int err;
+
+	for (port = 0; port < hsi_ctrl->max_p; port++)
+		for (ch = 0; ch < hsi_ctrl->hsi_port[port].max_ch; ch++) {
+			err = reg_hsi_dev_ch(hsi_ctrl, port, ch);
+			if (err < 0)
+				return err;
+		}
+
+	return 0;
+}
+
+static int __init hsi_softreset(struct hsi_dev *hsi_ctrl)
+{
+	int ind = 0;
+	void __iomem *base = hsi_ctrl->base;
+	u32 status;
+
+	hsi_outl_or(HSI_SOFTRESET, base, HSI_SYS_SYSCONFIG_REG);
+
+	status = hsi_inl(base, HSI_SYS_SYSSTATUS_REG);
+	while ((!(status & HSI_RESETDONE)) && (ind < HSI_RESETDONE_RETRIES)) {
+		set_current_state(TASK_UNINTERRUPTIBLE);
+		schedule_timeout(msecs_to_jiffies(HSI_RESETDONE_TIMEOUT));
+		status = hsi_inl(base, HSI_SYS_SYSSTATUS_REG);
+		ind++;
+	}
+
+	if (ind >= HSI_RESETDONE_RETRIES)
+		return -EIO;
+
+	/* Reseting GDD */
+	hsi_outl_or(HSI_SWRESET, base, HSI_GDD_GRST_REG);
+
+	return 0;
+}
+
+static void __init set_hsi_ports_default(struct hsi_dev *hsi_ctrl,
+					 struct platform_device *pd)
+{
+	struct port_ctx *cfg;
+	struct hsi_platform_data *pdata = pd->dev.platform_data;
+	unsigned int port = 0;
+	void __iomem *base = hsi_ctrl->base;
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+
+	for (port = 1; port <= pdata->num_ports; port++) {
+		cfg = &pdata->ctx.pctx[port - 1];
+		hsi_outl(cfg->hst.mode | cfg->hst.flow | HSI_MODE_WAKE_CTRL_SW,
+			 base, HSI_HST_MODE_REG(port));
+		if (!hsi_driver_device_is_hsi(pdev))
+			hsi_outl(cfg->hst.frame_size, base,
+						 HSI_HST_FRAMESIZE_REG(port));
+		hsi_outl(cfg->hst.divisor, base, HSI_HST_DIVISOR_REG(port));
+		hsi_outl(cfg->hst.channels, base, HSI_HST_CHANNELS_REG(port));
+		hsi_outl(cfg->hst.arb_mode, base, HSI_HST_ARBMODE_REG(port));
+
+		hsi_outl(cfg->hsr.mode | cfg->hsr.flow, base,
+			 HSI_HSR_MODE_REG(port));
+		hsi_outl(cfg->hsr.frame_size, base,
+			 HSI_HSR_FRAMESIZE_REG(port));
+		hsi_outl(cfg->hsr.channels, base, HSI_HSR_CHANNELS_REG(port));
+		if (hsi_driver_device_is_hsi(pdev))
+			hsi_outl(cfg->hsr.divisor, base,
+						HSI_HSR_DIVISOR_REG(port));
+		hsi_outl(cfg->hsr.timeout, base, HSI_HSR_COUNTERS_REG(port));
+	}
+
+	if (hsi_driver_device_is_hsi(pdev)) {
+		/* SW strategy for HSI fifo management can be changed here */
+		hsi_fifo_mapping(hsi_ctrl, HSI_FIFO_MAPPING_DEFAULT);
+	}
+}
+
+static int __init hsi_port_channels_init(struct hsi_port *port)
+{
+	struct hsi_channel *ch;
+	unsigned int ch_i;
+
+	for (ch_i = 0; ch_i < port->max_ch; ch_i++) {
+		ch = &port->hsi_channel[ch_i];
+		ch->channel_number = ch_i;
+		rwlock_init(&ch->rw_lock);
+		ch->flags = 0;
+		ch->hsi_port = port;
+		ch->read_data.addr = NULL;
+		ch->read_data.size = 0;
+		ch->read_data.lch = -1;
+		ch->write_data.addr = NULL;
+		ch->write_data.size = 0;
+		ch->write_data.lch = -1;
+		ch->dev = NULL;
+		ch->read_done = NULL;
+		ch->write_done = NULL;
+		ch->port_event = NULL;
+	}
+
+	return 0;
+}
+
+static void hsi_ports_exit(struct hsi_dev *hsi_ctrl, unsigned int max_ports)
+{
+	struct hsi_port *hsi_p;
+	unsigned int port;
+
+	for (port = 0; port < max_ports; port++) {
+		hsi_p = &hsi_ctrl->hsi_port[port];
+		hsi_mpu_exit(hsi_p);
+		hsi_cawake_exit(hsi_p);
+	}
+}
+
+static int __init hsi_request_mpu_irq(struct hsi_port *hsi_p)
+{
+	struct hsi_dev *hsi_ctrl = hsi_p->hsi_controller;
+	struct platform_device *pd = to_platform_device(hsi_ctrl->dev);
+	struct resource *mpu_irq;
+
+	if (hsi_driver_device_is_hsi(pd))
+		mpu_irq = platform_get_resource(pd, IORESOURCE_IRQ,
+					hsi_p->port_number - 1);
+	else /* SSI support 2 IRQs per port */
+		mpu_irq = platform_get_resource(pd, IORESOURCE_IRQ,
+					(hsi_p->port_number - 1) * 2);
+
+	if (!mpu_irq) {
+		dev_err(hsi_ctrl->dev, "HSI misses info for MPU IRQ on"
+			" port %d\n", hsi_p->port_number);
+		return -ENXIO;
+	}
+	hsi_p->n_irq = 0;	/* We only use one irq line */
+	hsi_p->irq = mpu_irq->start;
+	return hsi_mpu_init(hsi_p, mpu_irq->name);
+}
+
+static int __init hsi_request_cawake_irq(struct hsi_port *hsi_p)
+{
+	struct hsi_dev *hsi_ctrl = hsi_p->hsi_controller;
+	struct platform_device *pd = to_platform_device(hsi_ctrl->dev);
+	struct resource *cawake_irq;
+
+	if (hsi_driver_device_is_hsi(pd)) {
+		hsi_p->cawake_gpio = -1;
+		return 0;
+	} else {
+		cawake_irq = platform_get_resource(pd, IORESOURCE_IRQ,
+					   4 + hsi_p->port_number);
+	}
+
+	if (!cawake_irq) {
+		dev_err(hsi_ctrl->dev, "SSI device misses info for CAWAKE"
+			"IRQ on port %d\n", hsi_p->port_number);
+		return -ENXIO;
+	}
+
+	if (cawake_irq->flags & IORESOURCE_UNSET) {
+		dev_info(hsi_ctrl->dev, "No CAWAKE GPIO support\n");
+		hsi_p->cawake_gpio = -1;
+		return 0;
+	}
+
+	hsi_p->cawake_gpio_irq = cawake_irq->start;
+	hsi_p->cawake_gpio = irq_to_gpio(cawake_irq->start);
+	return hsi_cawake_init(hsi_p, cawake_irq->name);
+}
+
+static int __init hsi_ports_init(struct hsi_dev *hsi_ctrl)
+{
+	struct platform_device *pd = to_platform_device(hsi_ctrl->dev);
+	struct hsi_platform_data *pdata = pd->dev.platform_data;
+	struct hsi_port *hsi_p;
+	unsigned int port;
+	int err;
+
+	for (port = 0; port < hsi_ctrl->max_p; port++) {
+		hsi_p = &hsi_ctrl->hsi_port[port];
+		hsi_p->port_number = port + 1;
+		hsi_p->hsi_controller = hsi_ctrl;
+		hsi_p->max_ch = hsi_driver_device_is_hsi(pd) ?
+				HSI_CHANNELS_MAX : HSI_SSI_CHANNELS_MAX;
+		hsi_p->max_ch = min(hsi_p->max_ch, (u8) HSI_PORT_MAX_CH);
+		hsi_p->irq = 0;
+		hsi_p->counters_on = 1;
+		hsi_p->reg_counters = pdata->ctx.pctx[port].hsr.timeout;
+		spin_lock_init(&hsi_p->lock);
+		err = hsi_port_channels_init(&hsi_ctrl->hsi_port[port]);
+		if (err < 0)
+			goto rback1;
+		err = hsi_request_mpu_irq(hsi_p);
+		if (err < 0)
+			goto rback2;
+		err = hsi_request_cawake_irq(hsi_p);
+		if (err < 0)
+			goto rback3;
+	}
+	return 0;
+rback3:
+	hsi_mpu_exit(hsi_p);
+rback2:
+	hsi_ports_exit(hsi_ctrl, port + 1);
+rback1:
+	return err;
+}
+
+static int __init hsi_request_gdd_irq(struct hsi_dev *hsi_ctrl)
+{
+	struct platform_device *pd = to_platform_device(hsi_ctrl->dev);
+	struct resource *gdd_irq;
+
+	if (hsi_driver_device_is_hsi(pd))
+		gdd_irq = platform_get_resource(pd, IORESOURCE_IRQ, 2);
+	else
+		gdd_irq = platform_get_resource(pd, IORESOURCE_IRQ, 4);
+
+	if (!gdd_irq) {
+		dev_err(hsi_ctrl->dev, "HSI has no GDD IRQ resource\n");
+		return -ENXIO;
+	}
+
+	hsi_ctrl->gdd_irq = gdd_irq->start;
+	return hsi_gdd_init(hsi_ctrl, gdd_irq->name);
+}
+
+static void __init hsi_init_gdd_chan_count(struct hsi_dev *hsi_ctrl)
+{
+	struct platform_device *pd = to_platform_device(hsi_ctrl->dev);
+	struct resource *gdd_chan_count;
+	int i;
+
+	gdd_chan_count = platform_get_resource(pd, IORESOURCE_DMA, 0);
+
+	if (!gdd_chan_count) {
+		dev_warn(hsi_ctrl->dev, "HSI device has no GDD channel count "
+					"resource (use 8 as default)\n");
+		hsi_ctrl->gdd_chan_count = 8;
+	} else {
+		hsi_ctrl->gdd_chan_count = gdd_chan_count->start;
+		/* Check that the number of channels is power of 2 */
+		for (i = 0; i < 16; i++) {
+			if (hsi_ctrl->gdd_chan_count == (1 << i))
+				break;
+		}
+		if (i >= 16)
+			dev_err(hsi_ctrl->dev, "The Number of DMA channels "
+					"shall be a power of 2! (=%d)\n",
+					hsi_ctrl->gdd_chan_count);
+	}
+}
+
+static int __init hsi_controller_init(struct hsi_dev *hsi_ctrl,
+				      struct platform_device *pd)
+{
+	struct hsi_platform_data *pdata = pd->dev.platform_data;
+	struct resource *mem, *ioarea;
+	int err;
+
+	mem = platform_get_resource(pd, IORESOURCE_MEM, 0);
+	if (!mem) {
+		dev_err(&pd->dev, "HSI device does not have "
+			"HSI IO memory region information\n");
+		return -ENXIO;
+	}
+
+	ioarea = devm_request_mem_region(&pd->dev, mem->start,
+					 (mem->end - mem->start) + 1,
+					 dev_name(&pd->dev));
+	if (!ioarea) {
+		dev_err(&pd->dev, "Unable to request HSI IO mem region\n");
+		return -EBUSY;
+	}
+
+	hsi_ctrl->phy_base = mem->start;
+	hsi_ctrl->base = devm_ioremap(&pd->dev, mem->start,
+				      (mem->end - mem->start) + 1);
+	if (!hsi_ctrl->base) {
+		dev_err(&pd->dev, "Unable to ioremap HSI base IO address\n");
+		return -ENXIO;
+	}
+
+	hsi_ctrl->id = pd->id;
+	if (pdata->num_ports > HSI_MAX_PORTS) {
+		dev_err(&pd->dev, "The HSI driver does not support enough "
+		"ports!\n");
+		return -ENXIO;
+	}
+	hsi_ctrl->max_p = pdata->num_ports;
+	hsi_ctrl->dev = &pd->dev;
+	spin_lock_init(&hsi_ctrl->lock);
+	hsi_ctrl->hsi_clk = clk_get(&pd->dev, "hsi_clk");
+	hsi_init_gdd_chan_count(hsi_ctrl);
+
+	if (IS_ERR(hsi_ctrl->hsi_clk)) {
+		dev_err(hsi_ctrl->dev, "Unable to get HSI clocks\n");
+		return PTR_ERR(hsi_ctrl->hsi_clk);
+	}
+
+	if (pdata->clk_notifier_register) {
+		hsi_ctrl->hsi_nb.notifier_call = hsi_clk_event;
+		hsi_ctrl->hsi_nb.priority = INT_MAX; /* Let's try to be first */
+		err = pdata->clk_notifier_register(hsi_ctrl->hsi_clk,
+						   &hsi_ctrl->hsi_nb);
+		if (err < 0)
+			goto rback1;
+	}
+
+	err = hsi_ports_init(hsi_ctrl);
+	if (err < 0)
+		goto rback2;
+
+	err = hsi_request_gdd_irq(hsi_ctrl);
+	if (err < 0)
+		goto rback3;
+
+	return 0;
+rback3:
+	hsi_ports_exit(hsi_ctrl, hsi_ctrl->max_p);
+rback2:
+	if (pdata->clk_notifier_unregister)
+		pdata->clk_notifier_unregister(hsi_ctrl->hsi_clk,
+					       &hsi_ctrl->hsi_nb);
+rback1:
+	clk_put(hsi_ctrl->hsi_clk);
+	dev_err(&pd->dev, "Error on hsi_controller initialization\n");
+	return err;
+}
+
+static void hsi_controller_exit(struct hsi_dev *hsi_ctrl)
+{
+	struct hsi_platform_data *pdata = hsi_ctrl->dev->platform_data;
+
+	hsi_gdd_exit(hsi_ctrl);
+	hsi_ports_exit(hsi_ctrl, hsi_ctrl->max_p);
+	if (pdata->clk_notifier_unregister)
+		pdata->clk_notifier_unregister(hsi_ctrl->hsi_clk,
+					       &hsi_ctrl->hsi_nb);
+	clk_put(hsi_ctrl->hsi_clk);
+}
+
+static int __init hsi_probe(struct platform_device *pd)
+{
+	struct hsi_platform_data *pdata = pd->dev.platform_data;
+	struct hsi_dev *hsi_ctrl;
+	u32 revision;
+	int err;
+
+	dev_dbg(&pd->dev, "The platform device probed is an %s\n",
+			hsi_driver_device_is_hsi(pd) ? "HSI" : "SSI");
+
+	if (!pdata) {
+		pr_err(LOG_NAME "No platform_data found on hsi device\n");
+		return -ENXIO;
+	}
+
+	hsi_ctrl = kzalloc(sizeof(*hsi_ctrl), GFP_KERNEL);
+	if (hsi_ctrl == NULL) {
+		dev_err(&pd->dev, "Could not allocate memory for"
+			" struct hsi_dev\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pd, hsi_ctrl);
+	err = hsi_controller_init(hsi_ctrl, pd);
+	if (err < 0) {
+		dev_err(&pd->dev, "Could not initialize hsi controller:"
+			" %d\n", err);
+		goto rollback1;
+	}
+
+	clk_enable(hsi_ctrl->hsi_clk);
+
+	err = hsi_softreset(hsi_ctrl);
+	if (err < 0)
+		goto rollback2;
+
+	/* Set default PM settings */
+	hsi_outl((HSI_AUTOIDLE | HSI_SIDLEMODE_SMART | HSI_MIDLEMODE_SMART),
+		 hsi_ctrl->base, HSI_SYS_SYSCONFIG_REG);
+	hsi_outl(HSI_CLK_AUTOGATING_ON, hsi_ctrl->base, HSI_GDD_GCR_REG);
+
+	/* Configure HSI ports */
+	set_hsi_ports_default(hsi_ctrl, pd);
+
+	/* Gather info from registers for the driver.(REVISION) */
+	revision = hsi_inl(hsi_ctrl->base, HSI_SYS_REVISION_REG);
+	if (hsi_driver_device_is_hsi(pd))
+		dev_info(hsi_ctrl->dev, "HSI Hardware REVISION 0x%x\n",
+								revision);
+	else
+		dev_info(hsi_ctrl->dev, "SSI Hardware REVISION %d.%d\n",
+					(revision & HSI_SSI_REV_MAJOR) >> 4,
+					(revision & HSI_SSI_REV_MINOR));
+
+
+	err = hsi_debug_add_ctrl(hsi_ctrl);
+	if (err < 0)
+		goto rollback2;
+
+	err = register_hsi_devices(hsi_ctrl);
+	if (err < 0)
+		goto rollback3;
+
+	clk_disable(hsi_ctrl->hsi_clk);
+
+	return err;
+
+rollback3:
+	hsi_debug_remove_ctrl(hsi_ctrl);
+rollback2:
+	clk_disable(hsi_ctrl->hsi_clk);
+	hsi_controller_exit(hsi_ctrl);
+rollback1:
+	kfree(hsi_ctrl);
+	return err;
+}
+
+static void __exit unregister_hsi_devices(struct hsi_dev *hsi_ctrl)
+{
+	struct hsi_port *hsi_p;
+	struct hsi_device *device;
+	unsigned int port;
+	unsigned int ch;
+
+	for (port = 0; port < hsi_ctrl->max_p; port++) {
+		hsi_p = &hsi_ctrl->hsi_port[port];
+		for (ch = 0; ch < hsi_p->max_ch; ch++) {
+			device = hsi_p->hsi_channel[ch].dev;
+			hsi_close(device);
+			device_unregister(&device->device);
+			kfree(device);
+		}
+	}
+}
+
+static int __exit hsi_remove(struct platform_device *pd)
+{
+	struct hsi_dev *hsi_ctrl = platform_get_drvdata(pd);
+
+	if (!hsi_ctrl)
+		return 0;
+
+	unregister_hsi_devices(hsi_ctrl);
+	hsi_debug_remove_ctrl(hsi_ctrl);
+	hsi_controller_exit(hsi_ctrl);
+	kfree(hsi_ctrl);
+
+	return 0;
+}
+
+int hsi_driver_device_is_hsi(struct platform_device *dev)
+{
+	struct platform_device_id *id = platform_get_device_id(dev);
+	return (id->driver_data == HSI_DRV_DEVICE_HSI);
+}
+
+/* List of devices supported by this driver */
+static struct platform_device_id hsi_id_table[] = {
+	{ "omap_hsi",	HSI_DRV_DEVICE_HSI },
+	{ "omap_ssi",	HSI_DRV_DEVICE_SSI },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, hsi_id_table);
+
+static struct platform_driver hsi_pdriver = {
+	.probe = hsi_probe,
+	.remove = __exit_p(hsi_remove),
+	.driver = {
+		   .name = "omap_hsi",
+		   .owner = THIS_MODULE,
+		   },
+	.id_table = hsi_id_table
+};
+
+static int __init hsi_driver_init(void)
+{
+	int err = 0;
+
+	pr_info("HSI DRIVER Version " HSI_DRIVER_VERSION "\n");
+
+	hsi_bus_init();
+	err = hsi_debug_init();
+	if (err < 0) {
+		pr_err(LOG_NAME "HSI Debugfs failed %d\n", err);
+		goto rback1;
+	}
+	err = platform_driver_probe(&hsi_pdriver, hsi_probe);
+	if (err < 0) {
+		pr_err(LOG_NAME "Platform DRIVER register FAILED: %d\n", err);
+		goto rback2;
+	}
+
+	return 0;
+rback2:
+	hsi_debug_exit();
+rback1:
+	hsi_bus_exit();
+	return err;
+}
+
+static void __exit hsi_driver_exit(void)
+{
+	platform_driver_unregister(&hsi_pdriver);
+	hsi_debug_exit();
+	hsi_bus_exit();
+
+	pr_info("HSI DRIVER removed\n");
+}
+
+module_init(hsi_driver_init);
+module_exit(hsi_driver_exit);
+
+MODULE_ALIAS("platform:omap_hsi");
+MODULE_AUTHOR("Carlos Chinea / Nokia");
+MODULE_AUTHOR("Sebastien JAN / Texas Instruments");
+MODULE_DESCRIPTION("MIPI High-speed Synchronous Serial Interface (HSI) Driver");
+MODULE_LICENSE("GPL");
drivers/hsi/hsi_driver.h new file +308 -0

308 lines not on this page · raw message

drivers/hsi/hsi_driver_bus.c new file +182 -0

182 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#4 lore raw

Re: [RFC PATCH 2/9] HSI: Low Level Driver core

Hi,

Quoted 24 lines · ext Sebastien Jan
drivers/hsi/hsi_driver.c new file +24 -0
+static int __init reg_hsi_dev_ch(struct hsi_dev *hsi_ctrl, unsigned int p,
+                                unsigned int ch)
+{
+       struct hsi_device *dev;
+       struct hsi_port *port = &hsi_ctrl->hsi_port[p];
+       int err;
+
+       dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+       if (!dev)
+               return -ENOMEM;
+
+       dev->n_ctrl = hsi_ctrl->id;
+       dev->n_p = p;
+       dev->n_ch = ch;
+       dev->ch = &port->hsi_channel[ch];
+       dev->device.bus = &hsi_bus_type;
+       dev->device.parent = hsi_ctrl->dev;
+       dev->device.release = hsi_dev_release;
+       if (dev->n_ctrl < 0)
+               dev_set_name(&dev->device, "omap_hsi-p%u.c%u", p, ch);
+       else
+               dev_set_name(&dev->device, "omap_hsi%d-p%u.c%u", dev->n_ctrl, p,
+                            ch);
+

drivers/hsi/hsi_driver.c line 124

Quoted 10 lines
drivers/hsi/hsi_driver.c new file +10 -0
+       err = device_register(&dev->device);
+       if (err >= 0) {
+               write_lock_bh(&port->hsi_channel[ch].rw_lock);
+               port->hsi_channel[ch].dev = dev;
+               write_unlock_bh(&port->hsi_channel[ch].rw_lock);
+       } else {
+               kfree(dev);
+       }
+       return err;
+}

this will make a client's probe() function to be called twice, no ??

you should/could have a hsi_new_dummy() like on i2c ??

Quoted 1 line

+static int __init hsi_request_mpu_irq(struct hsi_port *hsi_p)

this should be done by hsi-omap.ko driver.

Quoted 1 line

+static int __init hsi_request_cawake_irq(struct hsi_port *hsi_p)

ditto.

Quoted 1 line

+static int __init hsi_ports_init(struct hsi_dev *hsi_ctrl)

ditto.

Quoted 1 line

+static int __init hsi_request_gdd_irq(struct hsi_dev *hsi_ctrl)

ditto.

drivers/hsi/hsi_driver.c line 380

Quoted 2 lines
drivers/hsi/hsi_driver.c new file +2 -0
+static int __init hsi_controller_init(struct hsi_dev *hsi_ctrl,
+                                     struct platform_device *pd)

ditto.

Signature · 1 line
balbi
#5 lore raw

RFC PATCH 3/9 HSI: Low Level Driver device management

In reply to Sebastien Jan

Low-level managment of interrupts, DMA, GPIO (SSI) and FIFO (HSI).

---
 drivers/hsi/hsi_driver_dma.c  |  469 +++++++++++++++++++++++++++++++++++++++++
 drivers/hsi/hsi_driver_fifo.c |  289 +++++++++++++++++++++++++
 drivers/hsi/hsi_driver_gpio.c |   79 +++++++
 drivers/hsi/hsi_driver_int.c  |  339 +++++++++++++++++++++++++++++
 4 files changed, 1176 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hsi/hsi_driver_dma.c
 create mode 100644 drivers/hsi/hsi_driver_fifo.c
 create mode 100644 drivers/hsi/hsi_driver_gpio.c
 create mode 100644 drivers/hsi/hsi_driver_int.c
drivers/hsi/hsi_driver_dma.c new file +469 -0
new file mode 100644
index 0000000..4514e98
@@ -0,0 +1,469 @@
+/*
+ * hsi_driver_dma.c
+ *
+ * Implements HSI low level interface driver functionality with DMA support.
+ *
+ * Copyright (C) 2007-2008 Nokia Corporation. All rights reserved.
+ * Copyright (C) 2009 Texas Instruments, Inc.
+ *
+ * Author: Carlos Chinea <[email protected]>
+ * Author: Sebastien JAN <[email protected]>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <linux/dma-mapping.h>
+#include "hsi_driver.h"
+
+#define HSI_SYNC_WRITE	0
+#define HSI_SYNC_READ	1
+#define HSI_L3_TPUT	13428 /* 13428 KiB/s => ~110 Mbit/s*/
+
+static unsigned char hsi_sync_table[2][2][8] = {
+	{
+		{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08},
+		{0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00}
+	}, {
+		{0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17},
+		{0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f}
+	}
+};
+
+/**
+ * hsi_get_free_lch - Get a free GDD(DMA)logical channel
+ * @hsi_ctrl- HSI controller of the GDD.
+ *
+ * Needs to be called holding the hsi_controller lock
+ *
+ * Return a free logical channel number. If there is no free lch
+ * then returns an out of range value
+ */
+static unsigned int hsi_get_free_lch(struct hsi_dev *hsi_ctrl)
+{
+	unsigned int enable_reg;
+	unsigned int i;
+	unsigned int lch = hsi_ctrl->last_gdd_lch;
+
+	enable_reg = hsi_inl(hsi_ctrl->base, HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	for (i = 1; i <= hsi_ctrl->gdd_chan_count; i++) {
+		lch = (lch + i) & (hsi_ctrl->gdd_chan_count - 1);
+		if (!(enable_reg & HSI_GDD_LCH(lch))) {
+			hsi_ctrl->last_gdd_lch = lch;
+			return lch;
+		}
+	}
+
+	return lch;
+}
+
+/**
+ * hsi_driver_write_dma - Program GDD [DMA] to write data from memory to
+ * the hsi channel buffer.
+ * @hsi_channel - pointer to the hsi_channel to write data to.
+ * @data - 32-bit word pointer to the data.
+ * @size - Number of 32bit words to be transfered.
+ *
+ * hsi_controller lock must be held before calling this function.
+ *
+ * Return 0 on success and < 0 on error.
+ */
+int hsi_driver_write_dma(struct hsi_channel *hsi_channel, u32 *data,
+			 unsigned int size)
+{
+	struct hsi_dev *hsi_ctrl = hsi_channel->hsi_port->hsi_controller;
+	void __iomem *base = hsi_ctrl->base;
+	unsigned int port = hsi_channel->hsi_port->port_number;
+	unsigned int channel = hsi_channel->channel_number;
+	unsigned int sync;
+	long buff_offset;
+	int lch;
+	dma_addr_t dma_data;
+	dma_addr_t s_addr;
+	u16 tmp;
+
+	if ((size < 1) || (data == NULL))
+		return -EINVAL;
+
+	clk_enable(hsi_ctrl->hsi_clk);
+
+	lch = hsi_get_free_lch(hsi_ctrl);
+	if (lch >= hsi_ctrl->gdd_chan_count) {
+		dev_err(hsi_ctrl->dev, "No free GDD logical channels.\n");
+		clk_disable(hsi_ctrl->hsi_clk);
+		return -EBUSY;	/* No free GDD logical channels. */
+	}
+
+	/* NOTE: Getting a free gdd logical channel and
+	 * reserve it must be done atomicaly. */
+	hsi_channel->write_data.lch = lch;
+
+	/* Sync is required for SSI but not for HSI */
+	sync = hsi_sync_table[HSI_SYNC_WRITE][port - 1][channel];
+
+	dma_data = dma_map_single(hsi_ctrl->dev, data, size * 4,
+					DMA_TO_DEVICE);
+
+	tmp = HSI_SRC_SINGLE_ACCESS0 |
+		HSI_SRC_MEMORY_PORT |
+		HSI_DST_SINGLE_ACCESS0 |
+		HSI_DST_PERIPHERAL_PORT |
+		HSI_DATA_TYPE_S32;
+	hsi_outw(tmp, base, HSI_GDD_CSDP_REG(lch));
+
+	tmp = HSI_SRC_AMODE_POSTINC | HSI_DST_AMODE_CONST | sync;
+	hsi_outw(tmp, base, HSI_GDD_CCR_REG(lch));
+
+	hsi_outw((HSI_BLOCK_IE | HSI_TOUT_IE), base, HSI_GDD_CICR_REG(lch));
+
+	buff_offset = hsi_hst_buffer_reg(hsi_ctrl, port, channel);
+	if (buff_offset < 0)
+		return buff_offset;
+	s_addr = hsi_ctrl->phy_base + buff_offset;
+
+	hsi_outl(s_addr, base, HSI_GDD_CDSA_REG(lch));
+
+	hsi_outl(dma_data, base, HSI_GDD_CSSA_REG(lch));
+	hsi_outw(size, base, HSI_GDD_CEN_REG(lch));
+
+	hsi_outl_or(HSI_GDD_LCH(lch), base, HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	hsi_outw_or(HSI_CCR_ENABLE, base, HSI_GDD_CCR_REG(lch));
+
+	return 0;
+}
+
+/**
+ * hsi_driver_read_dma - Program GDD [DMA] to write data to memory from
+ * the hsi channel buffer.
+ * @hsi_channel - pointer to the hsi_channel to read data from.
+ * @data - 32-bit word pointer where to store the incoming data.
+ * @size - Number of 32bit words to be transfered to the buffer.
+ *
+ * hsi_controller lock must be held before calling this function.
+ *
+ * Return 0 on success and < 0 on error.
+ */
+int hsi_driver_read_dma(struct hsi_channel *hsi_channel, u32 *data,
+			unsigned int count)
+{
+	struct hsi_dev *hsi_ctrl = hsi_channel->hsi_port->hsi_controller;
+	void __iomem *base = hsi_ctrl->base;
+	unsigned int port = hsi_channel->hsi_port->port_number;
+	unsigned int channel = hsi_channel->channel_number;
+	unsigned int sync;
+	unsigned int lch;
+	long buff_offset;
+	dma_addr_t dma_data;
+	dma_addr_t d_addr;
+	u16 tmp;
+
+	clk_enable(hsi_ctrl->hsi_clk);
+	lch = hsi_get_free_lch(hsi_ctrl);
+	if (lch >= hsi_ctrl->gdd_chan_count) {
+		dev_err(hsi_ctrl->dev, "No free GDD logical channels.\n");
+		clk_disable(hsi_ctrl->hsi_clk);
+		return -EBUSY;	/* No free GDD logical channels. */
+	}
+
+	/* When DMA is used for Rx, disable the Rx Interrupt.
+	 * (else DATAAVAILLABLE event would get triggered on first
+	 * received data word)
+	 * (By default, Rx interrupt is active for polling feature)
+	 */
+	hsi_driver_disable_read_interrupt(hsi_channel);
+
+	/*
+	 * NOTE: Gettting a free gdd logical channel and
+	 * reserve it must be done atomicaly.
+	 */
+	hsi_channel->read_data.lch = lch;
+
+	/* Sync is required for SSI but not for HSI */
+	sync = hsi_sync_table[HSI_SYNC_READ][port - 1][channel];
+
+	dma_data = dma_map_single(hsi_ctrl->dev, data, count * 4,
+					DMA_FROM_DEVICE);
+
+	tmp = HSI_DST_SINGLE_ACCESS0 |
+		HSI_DST_MEMORY_PORT |
+		HSI_SRC_SINGLE_ACCESS0 |
+		HSI_SRC_PERIPHERAL_PORT |
+		HSI_DATA_TYPE_S32;
+	hsi_outw(tmp, base, HSI_GDD_CSDP_REG(lch));
+
+	tmp = HSI_DST_AMODE_POSTINC | HSI_SRC_AMODE_CONST | sync;
+	hsi_outw(tmp, base, HSI_GDD_CCR_REG(lch));
+
+	hsi_outw((HSI_BLOCK_IE | HSI_TOUT_IE), base, HSI_GDD_CICR_REG(lch));
+
+	buff_offset = hsi_hsr_buffer_reg(hsi_ctrl, port, channel);
+	if (buff_offset < 0)
+		return buff_offset;
+	d_addr = hsi_ctrl->phy_base + buff_offset;
+
+	hsi_outl(d_addr, base, HSI_GDD_CSSA_REG(lch));
+
+	hsi_outl(dma_data, base, HSI_GDD_CDSA_REG(lch));
+	hsi_outw(count, base, HSI_GDD_CEN_REG(lch));
+
+	hsi_outl_or(HSI_GDD_LCH(lch), base, HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	hsi_outw_or(HSI_CCR_ENABLE, base, HSI_GDD_CCR_REG(lch));
+
+	return 0;
+}
+
+void hsi_driver_cancel_write_dma(struct hsi_channel *hsi_ch)
+{
+	int lch = hsi_ch->write_data.lch;
+	unsigned int port = hsi_ch->hsi_port->port_number;
+	unsigned int channel = hsi_ch->channel_number;
+	struct hsi_dev *hsi_ctrl = hsi_ch->hsi_port->hsi_controller;
+	u32 ccr;
+	long buff_offset;
+
+	if (lch < 0)
+		return;
+
+	clk_enable(hsi_ctrl->hsi_clk);
+	ccr = hsi_inw(hsi_ctrl->base, HSI_GDD_CCR_REG(lch));
+	if (!(ccr & HSI_CCR_ENABLE)) {
+		dev_dbg(&hsi_ch->dev->device, LOG_NAME "Write cancel on not "
+		"enabled logical channel %d CCR REG 0x%08X\n", lch, ccr);
+		clk_disable(hsi_ctrl->hsi_clk);
+		return;
+	}
+
+	hsi_outw_and(~HSI_CCR_ENABLE, hsi_ctrl->base, HSI_GDD_CCR_REG(lch));
+	hsi_outl_and(~HSI_GDD_LCH(lch), hsi_ctrl->base,
+						HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	hsi_outl(HSI_GDD_LCH(lch), hsi_ctrl->base,
+						HSI_SYS_GDD_MPU_IRQ_STATUS_REG);
+
+	buff_offset = hsi_hst_bufstate_f_reg(hsi_ctrl, port, channel);
+	if (buff_offset >= 0)
+		hsi_outl_and(~HSI_BUFSTATE_CHANNEL(channel), hsi_ctrl->base,
+								buff_offset);
+
+	hsi_reset_ch_write(hsi_ch);
+	clk_disable(hsi_ctrl->hsi_clk);
+	clk_disable(hsi_ctrl->hsi_clk); /* FIXME - check if can be removed */
+}
+
+void hsi_driver_cancel_read_dma(struct hsi_channel *hsi_ch)
+{
+	int lch = hsi_ch->read_data.lch;
+	struct hsi_dev *hsi_ctrl = hsi_ch->hsi_port->hsi_controller;
+	unsigned int port = hsi_ch->hsi_port->port_number;
+	unsigned int channel = hsi_ch->channel_number;
+	u32 reg;
+	long buff_offset;
+
+	if (lch < 0)
+		return;
+
+	/* DMA transfer is over, re-enable default mode
+	 * (Interrupts for polling feature)
+	 */
+	hsi_driver_read_interrupt(hsi_ch, NULL);
+
+	clk_enable(hsi_ctrl->hsi_clk);
+	reg = hsi_inw(hsi_ctrl->base, HSI_GDD_CCR_REG(lch));
+	if (!(reg & HSI_CCR_ENABLE)) {
+		dev_dbg(&hsi_ch->dev->device, LOG_NAME "Read cancel on not "
+		"enable logical channel %d CCR REG 0x%08X\n", lch, reg);
+		clk_disable(hsi_ctrl->hsi_clk);
+		return;
+	}
+
+	hsi_outw_and(~HSI_CCR_ENABLE, hsi_ctrl->base, HSI_GDD_CCR_REG(lch));
+	hsi_outl_and(~HSI_GDD_LCH(lch), hsi_ctrl->base,
+						HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	hsi_outl(HSI_GDD_LCH(lch), hsi_ctrl->base,
+						HSI_SYS_GDD_MPU_IRQ_STATUS_REG);
+
+	buff_offset = hsi_hsr_bufstate_f_reg(hsi_ctrl, port, channel);
+	if (buff_offset >= 0)
+		hsi_outl_and(~HSI_BUFSTATE_CHANNEL(channel), hsi_ctrl->base,
+								buff_offset);
+
+	hsi_reset_ch_read(hsi_ch);
+	clk_disable(hsi_ctrl->hsi_clk);
+	clk_disable(hsi_ctrl->hsi_clk); /* FIXME - check if can be removed */
+}
+
+/**
+ * hsi_get_info_from_gdd_lch - Retrieve channels information from DMA channel
+ * @hsi_ctrl - HSI device control structure
+ * @lch - DMA logical channel
+ * @port - HSI port
+ * @channel - HSI channel
+ * @is_read_path - channel is used for reading
+ *
+ * Updates the port, channel and is_read_path parameters depending on the
+ * lch DMA channel status.
+ *
+ * Return 0 on success and < 0 on error.
+ */
+int hsi_get_info_from_gdd_lch(struct hsi_dev *hsi_ctrl, unsigned int lch,
+	unsigned int *port, unsigned int *channel, unsigned int *is_read_path)
+{
+	int i_ports;
+	int i_chans;
+	int err = -1;
+
+	for (i_ports = 0; i_ports < HSI_MAX_PORTS; i_ports++)
+		for (i_chans = 0; i_chans < HSI_PORT_MAX_CH; i_chans++)
+			if (hsi_ctrl->hsi_port[i_ports].
+				hsi_channel[i_chans].read_data.lch == lch) {
+				*is_read_path = 1;
+				*port = i_ports + 1;
+				*channel = i_chans;
+				err = 0;
+				goto get_info_bk;
+			} else if (hsi_ctrl->hsi_port[i_ports].
+				hsi_channel[i_chans].write_data.lch == lch) {
+				*is_read_path = 0;
+				*port = i_ports + 1;
+				*channel = i_chans;
+				err = 0;
+				goto get_info_bk;
+			}
+get_info_bk:
+	return err;
+}
+
+static void do_hsi_gdd_lch(struct hsi_dev *hsi_ctrl, unsigned int gdd_lch)
+{
+	void __iomem *base = hsi_ctrl->base;
+	struct hsi_channel *ch;
+	unsigned int port;
+	unsigned int channel;
+	unsigned int is_read_path;
+	u32 gdd_csr;
+	dma_addr_t dma_h;
+	size_t size;
+
+	if (hsi_get_info_from_gdd_lch(hsi_ctrl, gdd_lch, &port, &channel,
+							&is_read_path) < 0) {
+		dev_err(hsi_ctrl->dev, "Unable to match the DMA channel %d with"
+						" an HSI channel\n", gdd_lch);
+		return;
+	}
+/* FIXME: to remove when validated: */
+	else {
+		dev_dbg(hsi_ctrl->dev, "DMA event on gdd_lch=%d => port=%d, "
+			"channel=%d, read=%d\n", gdd_lch, port, channel,
+								is_read_path);
+	}
+
+	spin_lock(&hsi_ctrl->lock);
+
+	hsi_outl_and(~HSI_GDD_LCH(gdd_lch), base,
+						HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	gdd_csr = hsi_inw(base, HSI_GDD_CSR_REG(gdd_lch));
+
+	if (!(gdd_csr & HSI_CSR_TOUT)) {
+		if (is_read_path) { /* Read path */
+			dma_h = hsi_inl(base, HSI_GDD_CDSA_REG(gdd_lch));
+			size = hsi_inw(base, HSI_GDD_CEN_REG(gdd_lch)) * 4;
+			dma_sync_single_for_cpu(hsi_ctrl->dev, dma_h, size,
+							DMA_FROM_DEVICE);
+			dma_unmap_single(hsi_ctrl->dev, dma_h, size,
+						DMA_FROM_DEVICE);
+			ch = ctrl_get_ch(hsi_ctrl, port, channel);
+			hsi_reset_ch_read(ch);
+			/* DMA transfer is over, re-enable default mode
+			 * (interrupts for polling feature)
+			 */
+			hsi_driver_read_interrupt(ch, NULL);
+			spin_unlock(&hsi_ctrl->lock);
+			ch->read_done(ch->dev, size);
+		} else {
+			dma_h = hsi_inl(base, HSI_GDD_CSSA_REG(gdd_lch));
+			size = hsi_inw(base, HSI_GDD_CEN_REG(gdd_lch)) * 4;
+			dma_unmap_single(hsi_ctrl->dev, dma_h, size,
+						DMA_TO_DEVICE);
+			ch = ctrl_get_ch(hsi_ctrl, port, channel);
+			hsi_reset_ch_write(ch);
+			spin_unlock(&hsi_ctrl->lock);
+			ch->write_done(ch->dev, size);
+		}
+	} else {
+		dev_err(hsi_ctrl->dev, "Error  on GDD transfer "
+				"on gdd channel %d\n", gdd_lch);
+		spin_unlock(&hsi_ctrl->lock);
+		hsi_port_event_handler(&hsi_ctrl->hsi_port[port - 1],
+							HSI_EVENT_ERROR, NULL);
+	}
+
+	/* Decrease clk usecount which was increased in
+	 * hsi_driver_{read,write}_dma() */
+	clk_disable(hsi_ctrl->hsi_clk);
+}
+
+static void do_hsi_gdd_tasklet(unsigned long device)
+{
+	struct hsi_dev *hsi_ctrl = (struct hsi_dev *)device;
+	void __iomem *base = hsi_ctrl->base;
+	unsigned int gdd_lch = 0;
+	u32 status_reg = 0;
+	u32 lch_served = 0;
+	unsigned int gdd_max_count = hsi_ctrl->gdd_chan_count;
+
+	clk_enable(hsi_ctrl->hsi_clk);
+
+	status_reg = hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_STATUS_REG);
+
+	for (gdd_lch = 0; gdd_lch < gdd_max_count; gdd_lch++) {
+		if (status_reg & HSI_GDD_LCH(gdd_lch)) {
+			do_hsi_gdd_lch(hsi_ctrl, gdd_lch);
+			lch_served |= HSI_GDD_LCH(gdd_lch);
+		}
+	}
+
+	hsi_outl(lch_served, base, HSI_SYS_GDD_MPU_IRQ_STATUS_REG);
+
+	status_reg = hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_STATUS_REG);
+	status_reg &= hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_ENABLE_REG);
+	clk_disable(hsi_ctrl->hsi_clk);
+
+	if (status_reg)
+		tasklet_hi_schedule(&hsi_ctrl->hsi_gdd_tasklet);
+	else
+		enable_irq(hsi_ctrl->gdd_irq);
+}
+
+static irqreturn_t hsi_gdd_mpu_handler(int irq, void *hsi_controller)
+{
+	struct hsi_dev *hsi_ctrl = hsi_controller;
+
+	tasklet_hi_schedule(&hsi_ctrl->hsi_gdd_tasklet);
+	disable_irq_nosync(hsi_ctrl->gdd_irq);
+
+	return IRQ_HANDLED;
+}
+
+int __init hsi_gdd_init(struct hsi_dev *hsi_ctrl, const char *irq_name)
+{
+	tasklet_init(&hsi_ctrl->hsi_gdd_tasklet, do_hsi_gdd_tasklet,
+						(unsigned long)hsi_ctrl);
+	if (request_irq(hsi_ctrl->gdd_irq, hsi_gdd_mpu_handler, IRQF_DISABLED,
+						irq_name, hsi_ctrl) < 0) {
+		dev_err(hsi_ctrl->dev, "FAILED to request GDD IRQ %d\n",
+							hsi_ctrl->gdd_irq);
+		return -EBUSY;
+	}
+
+	return 0;
+}
+
+void hsi_gdd_exit(struct hsi_dev *hsi_ctrl)
+{
+	tasklet_disable(&hsi_ctrl->hsi_gdd_tasklet);
+	free_irq(hsi_ctrl->gdd_irq, hsi_ctrl);
+}
drivers/hsi/hsi_driver_fifo.c new file +289 -0

289 lines not on this page · raw message

drivers/hsi/hsi_driver_gpio.c new file +79 -0

79 lines not on this page · raw message

drivers/hsi/hsi_driver_int.c new file +339 -0

339 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#6 lore raw

RFC PATCH 4/9 HSI: Low Level Driver debugfs support

In reply to Sebastien Jan

All registers dump, and counters configuration

---
 drivers/hsi/hsi_driver_debugfs.c |  486 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 486 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hsi/hsi_driver_debugfs.c
drivers/hsi/hsi_driver_debugfs.c new file +486 -0
new file mode 100644
index 0000000..d600a88
@@ -0,0 +1,486 @@
+/*
+ * hsi_driver_debugfs.c
+ *
+ * Implements HSI debugfs.
+ *
+ * Copyright (C) 2007-2008 Nokia Corporation. All rights reserved.
+ * Copyright (C) 2009 Texas Instruments, Inc.
+ *
+ * Author: Carlos Chinea <[email protected]>
+ * Author: Sebastien JAN <[email protected]>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <linux/err.h>
+#include <linux/list.h>
+#include <mach/clock.h>
+#include <linux/uaccess.h>
+#include <linux/ctype.h>
+#include "hsi_driver.h"
+
+#define HSI_DIR_NAME_SIZE	64
+
+static struct dentry *hsi_dir;
+
+static int hsi_debug_show(struct seq_file *m, void *p)
+{
+	struct hsi_dev *hsi_ctrl = m->private;
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+
+	clk_enable(hsi_ctrl->hsi_clk);
+
+	seq_printf(m, "REVISION\t: 0x%08x\n",
+				hsi_inl(hsi_ctrl->base, HSI_SYS_REVISION_REG));
+	if (hsi_driver_device_is_hsi(pdev))
+		seq_printf(m, "HWINFO\t\t: 0x%08x\n",
+				hsi_inl(hsi_ctrl->base, HSI_SYS_HWINFO_REG));
+	seq_printf(m, "SYSCONFIG\t: 0x%08x\n",
+				hsi_inl(hsi_ctrl->base, HSI_SYS_SYSCONFIG_REG));
+	seq_printf(m, "SYSSTATUS\t: 0x%08x\n",
+				hsi_inl(hsi_ctrl->base, HSI_SYS_SYSSTATUS_REG));
+
+	clk_disable(hsi_ctrl->hsi_clk);
+	return 0;
+}
+
+static int hsi_debug_port_show(struct seq_file *m, void *p)
+{
+	struct hsi_port *hsi_port = m->private;
+	struct hsi_dev *hsi_ctrl = hsi_port->hsi_controller;
+	void __iomem *base = hsi_ctrl->base;
+	unsigned int port = hsi_port->port_number;
+	int ch, fifo;
+	long buff_offset;
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+
+	clk_enable(hsi_ctrl->hsi_clk);
+
+	if (hsi_port->cawake_gpio >= 0)
+		seq_printf(m, "CAWAKE\t\t: %d\n", hsi_cawake(hsi_port));
+
+	seq_printf(m, "WAKE\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_SYS_WAKE_REG(port)));
+	seq_printf(m, "MPU_ENABLE_IRQ%d\t: 0x%08x\n", hsi_port->n_irq,
+		hsi_inl(base, HSI_SYS_MPU_ENABLE_REG(port, hsi_port->n_irq)));
+	seq_printf(m, "MPU_STATUS_IRQ%d\t: 0x%08x\n", hsi_port->n_irq,
+		hsi_inl(base, HSI_SYS_MPU_STATUS_REG(port, hsi_port->n_irq)));
+	if (hsi_driver_device_is_hsi(pdev)) {
+		seq_printf(m, "MPU_U_ENABLE_IRQ%d\t: 0x%08x\n",
+			hsi_port->n_irq,
+			hsi_inl(base, HSI_SYS_MPU_U_ENABLE_REG(port,
+							hsi_port->n_irq)));
+		seq_printf(m, "MPU_U_STATUS_IRQ%d\t: 0x%08x\n",
+			hsi_port->n_irq,
+			hsi_inl(base, HSI_SYS_MPU_U_STATUS_REG(port,
+							hsi_port->n_irq)));
+	}
+	/* HST */
+	seq_printf(m, "\nHST\n===\n");
+	seq_printf(m, "MODE\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_HST_MODE_REG(port)));
+	seq_printf(m, "FRAMESIZE\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_FRAMESIZE_REG(port)));
+	seq_printf(m, "DIVISOR\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_DIVISOR_REG(port)));
+	seq_printf(m, "CHANNELS\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_CHANNELS_REG(port)));
+	seq_printf(m, "ARBMODE\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_ARBMODE_REG(port)));
+	seq_printf(m, "TXSTATE\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_TXSTATE_REG(port)));
+	if (hsi_driver_device_is_hsi(pdev)) {
+		seq_printf(m, "BUFSTATE P1\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_BUFSTATE_REG(1)));
+		seq_printf(m, "BUFSTATE P2\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_BUFSTATE_REG(2)));
+	} else {
+		seq_printf(m, "BUFSTATE\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_BUFSTATE_REG(port)));
+	}
+	seq_printf(m, "BREAK\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HST_BREAK_REG(port)));
+	for (ch = 0; ch < hsi_port->max_ch; ch++) {
+		buff_offset = hsi_hst_buffer_reg(hsi_ctrl, port, ch);
+		if (buff_offset >= 0)
+			seq_printf(m, "BUFFER_CH%d\t: 0x%08x\n", ch,
+						hsi_inl(base, buff_offset));
+	}
+	if (hsi_driver_device_is_hsi(pdev)) {
+		for (fifo = 0; fifo < HSI_HST_FIFO_COUNT; fifo++) {
+			seq_printf(m, "FIFO MAPPING%d\t: 0x%08x\n", fifo,
+			hsi_inl(base, HSI_HST_MAPPING_FIFO_REG(fifo)));
+		}
+	}
+	/* HSR */
+	seq_printf(m, "\nHSR\n===\n");
+	seq_printf(m, "MODE\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_HSR_MODE_REG(port)));
+	seq_printf(m, "FRAMESIZE\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_FRAMESIZE_REG(port)));
+	seq_printf(m, "CHANNELS\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_CHANNELS_REG(port)));
+	seq_printf(m, "COUNTERS\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_COUNTERS_REG(port)));
+	seq_printf(m, "RXSTATE\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_RXSTATE_REG(port)));
+	if (hsi_driver_device_is_hsi(pdev)) {
+		seq_printf(m, "BUFSTATE P1\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_BUFSTATE_REG(1)));
+		seq_printf(m, "BUFSTATE P2\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_BUFSTATE_REG(2)));
+	} else {
+		seq_printf(m, "BUFSTATE\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_BUFSTATE_REG(port)));
+	}
+	seq_printf(m, "BREAK\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_BREAK_REG(port)));
+	seq_printf(m, "ERROR\t\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_ERROR_REG(port)));
+	seq_printf(m, "ERRORACK\t: 0x%08x\n",
+				hsi_inl(base, HSI_HSR_ERRORACK_REG(port)));
+	for (ch = 0; ch < hsi_port->max_ch; ch++) {
+		buff_offset = hsi_hsr_buffer_reg(hsi_ctrl, port, ch);
+		if (buff_offset >= 0)
+			seq_printf(m, "BUFFER_CH%d\t: 0x%08x\n", ch,
+						hsi_inl(base, buff_offset));
+	}
+	if (hsi_driver_device_is_hsi(pdev)) {
+		for (fifo = 0; fifo < HSI_HSR_FIFO_COUNT; fifo++) {
+			seq_printf(m, "FIFO MAPPING%d\t: 0x%08x\n", fifo,
+				hsi_inl(base,
+					HSI_HSR_MAPPING_FIFO_REG(fifo)));
+		}
+		seq_printf(m, "DLL\t: 0x%08x\n",
+					hsi_inl(base, HSI_HSR_DLL_REG(port)));
+		seq_printf(m, "DIVISOR\t: 0x%08x\n",
+						hsi_inl(base,
+						HSI_HSR_DIVISOR_REG(port)));
+	}
+	clk_disable(hsi_ctrl->hsi_clk);
+	return 0;
+}
+
+static int hsi_debug_gdd_show(struct seq_file *m, void *p)
+{
+	struct hsi_dev *hsi_ctrl = m->private;
+	void __iomem *base = hsi_ctrl->base;
+	int lch;
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+
+	clk_enable(hsi_ctrl->hsi_clk);
+
+	seq_printf(m, "GDD_MPU_STATUS\t: 0x%08x\n",
+				hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_STATUS_REG));
+	seq_printf(m, "GDD_MPU_ENABLE\t: 0x%08x\n\n",
+				hsi_inl(base, HSI_SYS_GDD_MPU_IRQ_ENABLE_REG));
+
+	if (!hsi_driver_device_is_hsi(pdev)) {
+		seq_printf(m, "HW_ID\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_SSI_GDD_HW_ID_REG));
+		seq_printf(m, "PPORT_ID\t: 0x%08x\n",
+				hsi_inl(base, HSI_SSI_GDD_PPORT_ID_REG));
+		seq_printf(m, "MPORT_ID\t: 0x%08x\n",
+				hsi_inl(base, HSI_SSI_GDD_MPORT_ID_REG));
+		seq_printf(m, "TEST\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_SSI_GDD_TEST_REG));
+	}
+
+	seq_printf(m, "GCR\t\t: 0x%08x\n", hsi_inl(base, HSI_GDD_GCR_REG));
+
+	for (lch = 0; lch < hsi_ctrl->gdd_chan_count; lch++) {
+		seq_printf(m, "\nGDD LCH %d\n=========\n", lch);
+		seq_printf(m, "CSDP\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CSDP_REG(lch)));
+		seq_printf(m, "CCR\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CCR_REG(lch)));
+		seq_printf(m, "CICR\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CICR_REG(lch)));
+		seq_printf(m, "CSR\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CSR_REG(lch)));
+		seq_printf(m, "CSSA\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_GDD_CSSA_REG(lch)));
+		seq_printf(m, "CDSA\t\t: 0x%08x\n",
+					hsi_inl(base, HSI_GDD_CDSA_REG(lch)));
+		seq_printf(m, "CEN\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CEN_REG(lch)));
+		seq_printf(m, "CSAC\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CSAC_REG(lch)));
+		seq_printf(m, "CDAC\t\t: 0x%04x\n",
+					hsi_inw(base, HSI_GDD_CDAC_REG(lch)));
+		if (!hsi_driver_device_is_hsi(pdev))
+			seq_printf(m, "CLNK_CTRL\t: 0x%04x\n",
+				hsi_inw(base, HSI_SSI_GDD_CLNK_CTRL_REG(lch)));
+	}
+
+	clk_disable(hsi_ctrl->hsi_clk);
+	return 0;
+}
+
+
+static int hsi_port_counters_open(struct inode *inode, struct file *file)
+{
+	file->private_data = inode->i_private;
+	return 0;
+}
+
+static int hsi_port_counters_release(struct inode *inode, struct file *file)
+{
+	return 0;
+}
+
+static loff_t hsi_port_counters_seek(struct file *file, loff_t off, int whence)
+{
+	return 0;
+}
+
+static ssize_t hsi_port_counters_read(struct file *filep, char __user *buff,
+						size_t count, loff_t *offp)
+{
+	ssize_t ret;
+	struct hsi_port *hsi_port = filep->private_data;
+	struct hsi_dev *hsi_ctrl = hsi_port->hsi_controller;
+	void __iomem *base = hsi_ctrl->base;
+	unsigned int port = hsi_port->port_number;
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+	char str[50];
+	unsigned long reg;
+
+	if (*offp > 0) {
+		ret = 0;
+		goto hsi_cnt_rd_bk;
+	}
+
+	clk_enable(hsi_ctrl->hsi_clk);
+	reg = hsi_inl(base, HSI_HSR_COUNTERS_REG(port));
+	clk_disable(hsi_ctrl->hsi_clk);
+
+	if (hsi_driver_device_is_hsi(pdev)) {
+		sprintf(str, "FT:%d, TB:%d, FB:%d\n",
+		(int) (reg & HSI_COUNTERS_FT_MASK) >> HSI_COUNTERS_FT_OFFSET,
+		(int) (reg & HSI_COUNTERS_TB_MASK) >> HSI_COUNTERS_TB_OFFSET,
+		(int) (reg & HSI_COUNTERS_FB_MASK) >> HSI_COUNTERS_FB_OFFSET);
+	} else {
+		sprintf(str, "timeout:%d\n", (int) reg);
+	}
+
+	ret = strlen(str);
+	if (copy_to_user((void __user *)buff, str, ret)) {
+		dev_err(hsi_ctrl->dev, "copy_to_user failed\n");
+		ret = 0;
+	} else {
+		*offp = ret;
+	}
+
+hsi_cnt_rd_bk:
+	return ret;
+}
+
+/*
+ * Split the buffer `buf' into space-separated words.
+ * Return the number of words or <0 on error.
+ */
+static int hsi_debug_tokenize(char *buf, char *words[], int maxwords)
+{
+	int nwords = 0;
+
+	while (*buf) {
+		char *end;
+
+		/* Skip leading whitespace */
+		while (*buf && isspace(*buf))
+			buf++;
+		if (!*buf)
+			break;	/* oh, it was trailing whitespace */
+
+		/* Run `end' over a word */
+		for (end = buf ; *end && !isspace(*end) ; end++)
+			;
+		/* `buf' is the start of the word, `end' is one past the end */
+
+		if (nwords == maxwords)
+			return -EINVAL;	/* ran out of words[] before bytes */
+		if (*end)
+			*end++ = '\0';	/* terminate the word */
+		words[nwords++] = buf;
+		buf = end;
+	}
+	return nwords;
+}
+
+static ssize_t hsi_port_counters_write(struct file *filep,
+			const char __user *buff, size_t count, loff_t *offp)
+{
+	ssize_t ret;
+	struct hsi_port *hsi_port = filep->private_data;
+	struct hsi_dev *hsi_ctrl = hsi_port->hsi_controller;
+	void __iomem *base = hsi_ctrl->base;
+	unsigned int port = hsi_port->port_number;
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+#define MAXWORDS 4
+	int nwords;
+	char *words[MAXWORDS];
+	char tmpbuf[256];
+	unsigned long reg, ft, tb, fb;
+
+	if (count == 0)
+		return 0;
+	if (count > sizeof(tmpbuf)-1)
+		return -E2BIG;
+	if (copy_from_user(tmpbuf, buff, count))
+		return -EFAULT;
+	tmpbuf[count] = '\0';
+	dev_dbg(hsi_ctrl->dev, "%s: read %d bytes from userspace\n",
+			__func__, (int)count);
+
+	nwords = hsi_debug_tokenize(tmpbuf, words, MAXWORDS);
+	if (nwords < 0) {
+		dev_warn(hsi_ctrl->dev,
+		"HSI counters write usage: echo <values> > counters\n");
+		return -EINVAL;
+	}
+
+	clk_enable(hsi_ctrl->hsi_clk);
+	if (hsi_driver_device_is_hsi(pdev)) {
+		if (nwords != 3) {
+			dev_warn(hsi_ctrl->dev, "HSI counters write usage: "
+					"echo \"FT TB FB\" > counters\n");
+			ret =  -EINVAL;
+			goto hsi_cnt_w_bk1;
+		}
+		strict_strtoul(words[0], 0, &ft);
+		strict_strtoul(words[1], 0, &tb);
+		strict_strtoul(words[2], 0, &fb);
+		reg = ((ft << HSI_COUNTERS_FT_OFFSET & HSI_COUNTERS_FT_MASK) |
+			(tb << HSI_COUNTERS_TB_OFFSET & HSI_COUNTERS_TB_MASK) |
+			(fb << HSI_COUNTERS_FB_OFFSET & HSI_COUNTERS_FB_MASK));
+	} else {
+		if (nwords != 1) {
+			dev_warn(hsi_ctrl->dev, "HSI counters write usage: "
+					"echo \"timeout\" > counters\n");
+			ret =  -EINVAL;
+			goto hsi_cnt_w_bk1;
+		}
+		strict_strtoul(words[0], 0, &reg);
+	}
+	hsi_outl(reg, base, HSI_HSR_COUNTERS_REG(port));
+	ret = count;
+	*offp += count;
+
+hsi_cnt_w_bk1:
+	clk_disable(hsi_ctrl->hsi_clk);
+
+	return ret;
+}
+
+static int hsi_regs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, hsi_debug_show, inode->i_private);
+}
+
+static int hsi_port_regs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, hsi_debug_port_show, inode->i_private);
+}
+
+static int hsi_gdd_regs_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, hsi_debug_gdd_show, inode->i_private);
+}
+
+static const struct file_operations hsi_regs_fops = {
+	.open		= hsi_regs_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
+static const struct file_operations hsi_port_regs_fops = {
+	.open		= hsi_port_regs_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
+static const struct file_operations hsi_port_counters_fops = {
+	.open		= hsi_port_counters_open,
+	.read		= hsi_port_counters_read,
+	.write		= hsi_port_counters_write,
+	.llseek		= hsi_port_counters_seek,
+	.release	= hsi_port_counters_release,
+};
+
+static const struct file_operations hsi_gdd_regs_fops = {
+	.open		= hsi_gdd_regs_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
+int __init hsi_debug_add_ctrl(struct hsi_dev *hsi_ctrl)
+{
+	struct platform_device *pdev = to_platform_device(hsi_ctrl->dev);
+	unsigned char dir_name[HSI_DIR_NAME_SIZE];
+	struct dentry *dir;
+	unsigned int port;
+
+	if (pdev->id < 0) {
+		hsi_ctrl->dir = debugfs_create_dir(pdev->name, hsi_dir);
+	} else {
+		snprintf(dir_name, sizeof(dir_name), "%s%d", pdev->name,
+								pdev->id);
+		hsi_ctrl->dir = debugfs_create_dir(dir_name, hsi_dir);
+	}
+	if (IS_ERR(hsi_ctrl->dir))
+		return PTR_ERR(hsi_ctrl->dir);
+
+	debugfs_create_file("regs", S_IRUGO, hsi_ctrl->dir, hsi_ctrl,
+								&hsi_regs_fops);
+
+	for (port = 0; port < hsi_ctrl->max_p; port++) {
+		snprintf(dir_name, sizeof(dir_name), "port%d", port + 1);
+		dir = debugfs_create_dir(dir_name, hsi_ctrl->dir);
+		if (IS_ERR(dir))
+			goto rback;
+		debugfs_create_file("regs", S_IRUGO, dir,
+				&hsi_ctrl->hsi_port[port], &hsi_port_regs_fops);
+		debugfs_create_file("counters", S_IRUGO | S_IWUGO, dir,
+				&hsi_ctrl->hsi_port[port],
+						&hsi_port_counters_fops);
+	}
+
+	dir = debugfs_create_dir("gdd", hsi_ctrl->dir);
+	if (IS_ERR(dir))
+		goto rback;
+	debugfs_create_file("regs", S_IRUGO, dir, hsi_ctrl, &hsi_gdd_regs_fops);
+
+	return 0;
+rback:
+	debugfs_remove_recursive(hsi_ctrl->dir);
+	return PTR_ERR(dir);
+}
+
+void hsi_debug_remove_ctrl(struct hsi_dev *hsi_ctrl)
+{
+	debugfs_remove_recursive(hsi_ctrl->dir);
+}
+
+int __init hsi_debug_init(void)
+{
+	hsi_dir = debugfs_create_dir("hsi", NULL);
+	if (IS_ERR(hsi_dir))
+		return PTR_ERR(hsi_dir);
+
+	return 0;
+}
+
+void hsi_debug_exit(void)
+{
+	debugfs_remove_recursive(hsi_dir);
+}
Signature · 1 line
1.6.0.4
#7 lore raw

RFC PATCH 5/9 HSI: Low Level Driver documentation

In reply to Sebastien Jan
---
 Documentation/hsi/hsi.txt |  319 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 319 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/hsi/hsi.txt
Documentation/hsi/hsi.txt new file +319 -0
new file mode 100644
index 0000000..0890cff
@@ -0,0 +1,319 @@
+OMAP HSI API's How To
+=====================
+
+The MIPI High Speed Synchronous Serial Interface (HSI) is a high speed
+communication interface that is used for connecting OMAP to a cellular modem
+engine.
+It is specified by the MIPI alliance (www.mipi.org). An introduction to the
+MIPI HSI working group can be found here: http://www.mipi.org/wgoverview.shtml
+
+The HSI interface supports full duplex communication over multiple channels and
+is capable of reaching speeds up to 200 Mbit/s.
+
+The OMAP HSI driver supports both OMAP MIPI HSI (as defined in
+MIPI documentation mipi_HSI-PL_specification_v01-01-00a.pdf) and OMAP SSI
+devices through different device files, and a generic SW driver.
+
+Please refer to the MIPI specifications for more details on this device.
+
+
+I OMAP HSI driver API overview
+-----------------------------
+
+A) HSI Bus, HSI channels and protocol drivers overview.
+
+The OMAP HSI driver implements the low-level support for the HSI device. It
+abstracts device specifics and provides a simple interface inside the kernel
+for data transmission on the HSI channels.
+The OMAP HSI driver does not implement any communication protocol.
+The SW layers using the OMAP HSI driver may implement a communication protocol
+if required, and are commonly called 'protocol drivers' in this document.
+
+The OMAP HSI abstracts the concept of HSI channels by creating an HSI bus and
+attaching HSI channel devices to it. (see Figure 1)
+
+Protocol drivers will then claim one or more HSI channels, after registering
+with the OMAP HSI driver.
+
+	+---------------------+		+----------------+
+	+  HSI channel device +		+  HSI protocol  +
+	+  (omap_hsi.pX-cY)   +	<-------+  driver        +
+	+---------------------+		+----------------+
+		|				|
+(/sys/bus/hsi/devices/omap_hsi.pX-cy)	(/sys/bus/hsi/drivers/hsi_protocol)
+		|				|
++----------------------------------------------------------------+
++			HSI bus					 +
++----------------------------------------------------------------+
+
+			Figure 1.
+
+(NOTE: omap_hsi.pX-cY represents the HSI channel Y on port X from the omap_hsi
+device)
+
+B) Data transfers
+
+The OMAP HSI driver exports an asynchronous interface for sending and receiving
+data over the HSI channels. Protocol drivers will register a set of read and
+write completion callbacks for each HSI channel they use.
+
+Protocol drivers call hsi_write/hsi_read functions to signal the OMAP HSI driver
+that is willing to write/read data to/from a channel. Transfers are completed
+only when the OMAP HSI driver calls the completion callback.
+
+An HSI channel can simultaneously have both a read and a write request
+pending, however, requests cannot be queued.
+
+It is safe to call hsi_write/hsi_read functions inside the callback functions.
+In fact, a protocol driver should normally re-issue the read request from within
+the read callback, in order to not miss any incoming messages.
+
+Note on read / write operations:
+A read or write is performed using a HSI internal DMA channel, unless the size
+of data to transmit is one 32bits Word, where the transmission is directly
+managed through interrupts.
+
+C) Error handling
+
+HSI is a multi channel interface but the channels share the same physical wires.
+Therefore, any transmission error potentially affects all the protocol drivers
+that sit on top of the HSI driver. Whenever an error occurs, it is broadcast
+to all protocol drivers.
+
+Errors are signaled to the protocol drivers through the port_event callback.
+
+Completion callbacks functions are only called when a transfer has succeess.
+
+D) Supported modes of operation
+
+The driver supports stream and frame transmission modes and synchronized and
+pipelined data flows.
+The driver implements the HSI support for the core MPU and not for the
+potential co-processors.
+
+
+II OMAP HSI API's
+-----------------
+
+A) Include
+
+#include<linux/hsi_driver_if.h>
+
+B) int hsi_register_driver(struct hsi_device_driver *driver);
+
+  Description: Register an HSI protocol driver
+
+  Parameter: A protocol driver declaration (see struct hsi_device_driver)
+
+C) void hsi_unregister_driver(struct hsi_device_driver *driver);
+
+  Description: Unregister an HSI protocol driver
+
+  Parameter: A protocol driver declaration (see struct hsi_device_driver)
+
+D) int hsi_open(struct hsi_device *dev);
+
+  Description: Open an HSI device channel
+
+  Parameter: The HSI channel
+
+E) int hsi_write(struct hsi_device *dev, u32 *data, unsigned int count);
+
+  Description: Send data through an HSI channel. The transfer is only completed
+  when the write_complete callback is called
+
+  Parameters:
+	- dev: HSI channel
+	- data: pointer to the data to send
+	- count: number of 32-bit words to be sent
+
+F) void hsi_write_cancel(struct hsi_device *dev);
+
+  Description: Cancel current pending write operation
+
+  Parameters: HSI channel
+
+G) int hsi_read(struct hsi_device *dev, u32 *data, unsigned int count);
+
+  Description: Receive data through an HSI channel. The transfer is only
+  completed when the read_complete callback is called
+
+  Parameters:
+	- dev: HSI channel
+	- data: pointer where to store the data
+	- count: number of 32-bit words to be read
+
+H) void hsi_read_cancel(struct hsi_device *dev);
+
+  Description: Cancel current pending read operation
+
+  Parameters: HSI channel
+
+I) int hsi_ioctl(struct hsi_device *dev, unsigned int command, void *arg);
+
+  Description: Apply some control command to the port associated to the given
+  HSI channel
+
+  Parameters:
+	- dev: HSI channel
+	- command: command to execute
+	- arg: parameter for the control command
+
+  Commands:
+	- HSI_IOCTL_WAKE_UP:
+		Description: Set HSI wakeup line for the channel
+		Parameters: None
+	- HSI_IOCTL_WAKE_DOWN:
+		Description: Unset HSI wakeup line for the channel
+		Parameters: None
+	- HSI_IOCTL_SEND_BREAK:
+		Description: Send a HW BREAK frame in FRAME mode
+		Parameters: None
+	- HSI_IOCTL_WAKE:
+		Description: Get HST WAKE line status
+		Parameters: Pointer to a u32 variable to return result
+		(Result: 0 means wakeline DOWN, other result means wakeline UP)
+	- HSI_IOCTL_FLUSH_RX:
+		Description: Force the HSR to idle state
+		Parameters: None
+	- HSI_IOCTL_FLUSH_TX:
+		Description: Force the HST to idle state
+		Parameters: None
+	- HSI_IOCTL_CAWAKE:
+		Description: Get CAWAKE (HSR) line status
+		Parameters: Pointer to a u32 variable to return result
+		(Result: 0 means wakeline DOWN, other result means wakeline UP)
+	- HSI_IOCTL_SET_RX:
+		Description: Set HSR configuration
+		Parameters: Pointer to a hsr_ctx structure describing
+		configurable HSR parameters (mode, frame size, channels,
+		data flow type, bit-rate divisor)
+		Notes:
+		HSI: A special value (0x1000) can be passed as bit-rate divisor
+		to request the HSR so switch to auto-divisor mode (in this mode,
+		the HSR can receive at any speed, but the error detection is
+		deactivated). To exit this RX auto-divisor mode, a new divisor
+		must be programmed for HSI (can be 0), and the error-detection
+		is re-enabled.
+		SSI: The same special 0x1000 value is used to deactivate the SSR
+		timeout counter. This counter can be re-enabled by programming
+		the 0x1001 value as bit-rate divisor. The SSI does not accept
+		any other SSR bit-rate divisor values.
+	- HSI_IOCTL_GET_RX:
+		Description: Get HSR configuration
+		Parameters: Pointer to a Hsr_ctx structure describing
+		configurable HSR parameters (mode, frame size, channels,
+		data flow type, bit-rate divisor)
+	- HSI_IOCTL_SET_TX:
+		Description: Set HST configuration
+		Parameters: Pointer to a hst_ctx structure describing
+		configurable HST parameters (mode, frame size, divisor,
+		arb_mode, channels, data flow type)
+	- HSI_IOCTL_GET_TX:
+		Description: Get HST configuration
+		Parameters: Pointer to a hst_ctx structure describing
+		configurable SSR parameters (mode, frame size, divisor,
+		arb_mode, channels, data flow type)
+	Note that the Rx and Tx transmission speeds are configured through the
+	bit-rate divisor parameters. The HSI driver user shall take care of the
+	functional clock provided to the HSI and program the divisors
+	accordingly. Depending on the required speed and HSI device, some
+	constraints on OPP may have to be handled. This shall be managed by the
+	HSI driver user.
+
+J) void hsi_close(struct hsi_device *dev);
+
+  Description: Close an HSI channel
+
+  Parameters: The HSI channel to close
+
+K) Callback configuration functions:
+void hsi_set_read_cb(struct hsi_device *dev,
+				void (*read_cb)(struct hsi_device *dev));
+void hsi_set_write_cb(struct hsi_device *dev,
+				void (*write_cb)(struct hsi_device *dev));
+void hsi_set_port_event_cb(struct hsi_device *dev,
+				void (*port_event_cb)(struct hsi_device *dev,
+						unsigned int event, void *arg));
+
+  Description: Set the read, write and port-event callbacks for the HSI channel.
+  These functions are usually called in the probe function of the HSI protocol
+  driver to set completion callbacks for the asynchronous read and write
+  transfer, and manage the other HSI events.
+
+  Parameters:
+	- dev: HSI channel
+	- read_cb: Pointer to a callback function to signal that a read transfer
+		is completed
+	- write_cb: Pointer to a callback function to signal that a write
+		transfer is completed
+	- port_event_cb: Pointer to a callback function to signal that a HSI
+		event has happened (events can be: Break frame detected, error,
+		cawake-up, cawake-down or HSR-data-available).
+
+
+L) struct hsi_device_driver
+
+Description: Protocol drivers pass this struct to the hsi_register_driver
+function in order to register with the OMAP HSI driver. Among other things it
+tells the OMAP HSI driver which channels the protocol driver wants to allocate
+for its use
+
+Declaration:
+struct hsi_device_driver {
+	unsigned long		ctrl_mask;
+	unsigned long		ch_mask[HSI_MAX_PORTS];
+	void			(*port_event) (struct hsi_device *dev,
+						unsigned int event, void *arg);
+	int			(*probe)(struct hsi_device *dev);
+	int			(*remove)(struct hsi_device *dev);
+	int			(*suspend)(struct hsi_device *dev,
+						pm_message_t mesg);
+	int			(*resume)(struct hsi_device *dev);
+	struct device_driver 	driver;
+};
+
+Fields description:
+	ctrl_mask: HSI block ids to use
+	ch_mask[HSI_MAX_PORTS]: HSI channels to use
+	port_event: Function callback for notifying HSI events
+		   (i.e.: error transfer)
+		Parameters:
+			dev: HSI channel
+			event: Event code
+			event: Event argument
+	probe: Probe function
+		Parameters: HSI channel
+	remove: Remove function
+		Parameters: HSI channel
+
+Example:
+
+static struct hsi_device_driver hsi_protocol_driver = {
+	.ctrl_mask = ANY_HSI_CONTROLLER,
+	.ch_mask[0] = CHANNEL(0) | CHANNEL(1),
+	.port_event = port_event_callback,
+	.probe = hsi_proto_probe,
+	.remove = __devexit_p(hsi_proto_remove),
+	.driver = {
+			.name = "hsi_protocol",
+	},
+};
+
+
+III) FUTURE WORK
+----------------
+ - Power management update and validation on OMAP 3430
+ - Clocks and power management implementation on OMAP 4430
+ - Validation on OMAP 4430
+ - hsi-char documentation
+
+
+=================================================
+Acknowledgements: The OMAP HSI driver is based on OMAP SSI driver, written by
+Carlos Chinea <[email protected]>.
+
+Contact: Sebastien Jan <[email protected]>
+
+Copyright (C) 2008 Nokia Corporation.
+Copyright (C) 2009 Texas Instruments, Inc.
Signature · 1 line
1.6.0.4
#8 lore raw

RFC PATCH 6/9 HSI: character driver interface

In reply to Sebastien Jan

Character driver header and interface implementation Integration in the build and configuration

---
 drivers/Kconfig          |    2 +
 drivers/hsi/Kconfig      |   14 ++
 drivers/hsi/Makefile     |    3 +
 drivers/hsi/hsi-char.c   |  526 ++++++++++++++++++++++++++++++++++++++++++++++
 drivers/hsi/hsi-char.h   |   31 +++
 include/linux/hsi_char.h |   71 +++++++
 6 files changed, 647 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hsi/hsi-char.c
 create mode 100644 drivers/hsi/hsi-char.h
 create mode 100644 include/linux/hsi_char.h
drivers/Kconfig +2 -0
index 48bbdbe..8fc1c36 100644
@@ -52,6 +52,8 @@ source "drivers/i2c/Kconfig"
 
 source "drivers/spi/Kconfig"
 
+source "drivers/hsi/Kconfig"
+
 source "drivers/pps/Kconfig"
 
 source "drivers/gpio/Kconfig"
drivers/hsi/Kconfig +14 -0
index e10b522..79e0e02 100644
@@ -42,3 +42,17 @@ config OMAP_SSI_DEVICE
 	bool "SSI (OMAP SSI)"
 
 endchoice
+
+#
+# OMAP HSI char device kernel configuration
+#
+
+config HSI_CHAR
+	tristate "HSI character driver"
+	depends on OMAP_HSI
+	---help---
+	  If you say Y here, you will enable the HSI character driver.
+	  This driver provides a simple character device interface for
+	  serial communication over the HSI bus.
+
+endif # HSI
drivers/hsi/Makefile +3 -0
index a7f579b..81270ec 100644
@@ -11,4 +11,7 @@ ifeq ($(CONFIG_DEBUG_FS), y)
 	omap_hsi-objs += hsi_driver_debugfs.o
 endif
 
+hsi_char-objs	:=	hsi-char.o hsi-if.o
+
 obj-$(CONFIG_OMAP_HSI)	+= omap_hsi.o
+obj-$(CONFIG_HSI_CHAR)	+= hsi_char.o
drivers/hsi/hsi-char.c new file +526 -0

526 lines not on this page · raw message

drivers/hsi/hsi-char.h new file +31 -0
new file mode 100644
index 0000000..d37018f
@@ -0,0 +1,31 @@
+/*
+ * hsi-char.h
+ *
+ * HSI character driver private declaration header file.
+ *
+ * Copyright (C) 2009 Nokia Corporation. All rights reserved.
+ * Copyright (C) 2009 Texas Instruments, Inc.
+ *
+ * Author: Andras Domokos <[email protected]>
+ * Author: Sebastien JAN <[email protected]>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef _HSI_CHAR_H
+#define _HSI_CHAR_H
+
+#include "hsi-if.h"
+
+/* how many char devices would be created at most */
+#define HSI_MAX_CHAR_DEVS	8
+
+void if_notify(int ch, struct hsi_event *ev);
+
+#endif /* _HSI_CHAR_H */
include/linux/hsi_char.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#9 lore raw

RFC PATCH 7/9 HSI: character driver low level interface

In reply to Sebastien Jan

Character driver interface with omap_hsi driver (LLD)

---
 drivers/hsi/hsi-if.c |  642 ++++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/hsi/hsi-if.h |   65 +++++
 2 files changed, 707 insertions(+), 0 deletions(-)
 create mode 100644 drivers/hsi/hsi-if.c
 create mode 100644 drivers/hsi/hsi-if.h
drivers/hsi/hsi-if.c new file +642 -0
new file mode 100644
index 0000000..2c9ba0c
@@ -0,0 +1,642 @@
+/*
+ * hsi-if.c
+ *
+ * Part of the HSI character driver, implements the HSI interface.
+ *
+ * Copyright (C) 2009 Nokia Corporation. All rights reserved.
+ * Copyright (C) 2009 Texas Instruments, Inc.
+ *
+ * Author: Andras Domokos <[email protected]>
+ * Author: Sebastien JAN <[email protected]>
+ *
+ * This package is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <asm/mach-types.h>
+#include <linux/ioctl.h>
+#include <linux/delay.h>
+#include <linux/ktime.h>
+#include <linux/bitmap.h>
+
+#include <linux/hsi_driver_if.h>
+#include <linux/hsi_char.h>
+
+#include "hsi-char.h"
+#include "hsi-if.h"
+
+#define HSI_CHANNEL_STATE_UNAVAIL	(1 << 0)
+#define HSI_CHANNEL_STATE_READING	(1 << 1)
+#define HSI_CHANNEL_STATE_WRITING	(1 << 2)
+
+#define PORT1	0
+#define PORT2	1
+
+#define RXCONV(dst, src) \
+	do { \
+		(dst)->mode = (src)->mode; \
+		(dst)->flow = (src)->flow; \
+		(dst)->frame_size = (src)->frame_size; \
+		(dst)->channels = (src)->channels; \
+		(dst)->divisor = (src)->divisor; \
+	} while (0)
+
+#define TXCONV(dst, src) \
+	do { \
+		(dst)->mode = (src)->mode; \
+		(dst)->flow = (src)->flow; \
+		(dst)->frame_size = (src)->frame_size; \
+		(dst)->channels = (src)->channels; \
+		(dst)->divisor = (src)->divisor; \
+		(dst)->arb_mode = (src)->arb_mode; \
+	} while (0)
+
+struct if_hsi_channel {
+	struct hsi_device *dev;
+	unsigned int channel_id;
+	u32 *tx_data;
+	unsigned int tx_count;
+	u32 *rx_data;
+	unsigned int rx_count;
+	unsigned int opened;
+	unsigned int state;
+	spinlock_t lock; /* Serializes access to channel data */
+};
+
+struct if_hsi_iface {
+	struct if_hsi_channel channels[HSI_MAX_CHAR_DEVS];
+	int bootstrap;
+	unsigned long init_chan_map;
+	spinlock_t lock; /* Serializes access to HSI functional interface */
+};
+
+static void if_hsi_port_event(struct hsi_device *dev, unsigned int event,
+				void *arg);
+static int __devinit if_hsi_probe(struct hsi_device *dev);
+static int __devexit if_hsi_remove(struct hsi_device *dev);
+
+static struct hsi_device_driver if_hsi_char_driver = {
+	.ctrl_mask = ANY_HSI_CONTROLLER,
+	.probe = if_hsi_probe,
+	.remove = __devexit_p(if_hsi_remove),
+	.driver = {
+		.name = "hsi_char"
+	},
+};
+
+static struct if_hsi_iface hsi_iface;
+
+static int if_hsi_read_on(int ch, u32 *data, unsigned int count)
+{
+	struct if_hsi_channel *channel;
+	int ret;
+
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+
+	spin_lock(&channel->lock);
+	if (channel->state & HSI_CHANNEL_STATE_READING) {
+		pr_err("Read still pending on channel %d\n", ch);
+		spin_unlock(&channel->lock);
+		return -EBUSY;
+	}
+	channel->state |= HSI_CHANNEL_STATE_READING;
+	channel->rx_data = data;
+	channel->rx_count = count;
+	spin_unlock(&channel->lock);
+
+	ret = hsi_read(channel->dev, data, count/4);
+	dev_dbg(&channel->dev->device, "%s, ch = %d, ret = %d\n", __func__, ch,
+									ret);
+
+	return ret;
+}
+
+static void if_hsi_read_done(struct hsi_device *dev, unsigned int size)
+{
+	struct if_hsi_channel *channel;
+	struct hsi_event ev;
+
+	channel = &hsi_iface.channels[dev->n_ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, dev->n_ch);
+	spin_lock(&channel->lock);
+	channel->state &= ~HSI_CHANNEL_STATE_READING;
+	ev.event = HSI_EV_IN;
+	ev.data = channel->rx_data;
+	ev.count = size;
+	spin_unlock(&channel->lock);
+	if_notify(dev->n_ch, &ev);
+}
+
+int if_hsi_read(int ch, u32 *data, unsigned int count)
+{
+	int ret = 0;
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	ret = if_hsi_read_on(ch, data, count);
+	spin_unlock_bh(&hsi_iface.lock);
+	return ret;
+}
+
+int if_hsi_poll(int ch)
+{
+	struct if_hsi_channel *channel;
+	int ret = 0;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	ret = hsi_poll(channel->dev);
+	spin_unlock_bh(&hsi_iface.lock);
+	return ret;
+}
+
+static int if_hsi_write_on(int ch, u32 *address, unsigned int count)
+{
+	struct if_hsi_channel *channel;
+	int ret;
+
+	channel = &hsi_iface.channels[ch];
+
+	spin_lock(&channel->lock);
+	if (channel->state & HSI_CHANNEL_STATE_WRITING) {
+		pr_err("Write still pending on channel %d\n", ch);
+		spin_unlock(&channel->lock);
+		return -EBUSY;
+	}
+
+	channel->tx_data = address;
+	channel->tx_count = count;
+	channel->state |= HSI_CHANNEL_STATE_WRITING;
+	spin_unlock(&channel->lock);
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	ret = hsi_write(channel->dev, address, count/4);
+	return ret;
+}
+
+static void if_hsi_write_done(struct hsi_device *dev, unsigned int size)
+{
+	struct if_hsi_channel *channel;
+	struct hsi_event ev;
+
+	channel = &hsi_iface.channels[dev->n_ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, dev->n_ch);
+
+	spin_lock(&channel->lock);
+	channel->state &= ~HSI_CHANNEL_STATE_WRITING;
+	ev.event = HSI_EV_OUT;
+	ev.data = channel->tx_data;
+	ev.count = size;
+	spin_unlock(&channel->lock);
+	if_notify(dev->n_ch, &ev);
+}
+
+int if_hsi_write(int ch, u32 *data, unsigned int count)
+{
+	int ret = 0;
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	ret = if_hsi_write_on(ch, data, count);
+	spin_unlock_bh(&hsi_iface.lock);
+	return ret;
+}
+
+void if_hsi_send_break(int ch)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, HSI_IOCTL_SEND_BREAK, NULL);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+void if_hsi_flush_rx(int ch)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, HSI_IOCTL_FLUSH_RX, NULL);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+void if_hsi_flush_ch(int ch)
+{
+	/* FIXME - Check the purpose of this function */
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	spin_lock(&channel->lock);
+	spin_unlock(&channel->lock);
+}
+
+void if_hsi_flush_tx(int ch)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, HSI_IOCTL_FLUSH_TX, NULL);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+void if_hsi_get_wakeline(int ch, unsigned int *state)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, HSI_IOCTL_WAKE, state);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+void if_hsi_set_wakeline(int ch, unsigned int state)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, state, NULL);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+int if_hsi_set_rx(int ch, struct hsi_rx_config *cfg)
+{
+	int ret;
+	struct if_hsi_channel *channel;
+	struct hsr_ctx ctx;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	RXCONV(&ctx, cfg);
+	spin_lock_bh(&hsi_iface.lock);
+	ret = hsi_ioctl(channel->dev, HSI_IOCTL_SET_RX, &ctx);
+	spin_unlock_bh(&hsi_iface.lock);
+	return ret;
+}
+
+void if_hsi_get_rx(int ch, struct hsi_rx_config *cfg)
+{
+	struct if_hsi_channel *channel;
+	struct hsr_ctx ctx;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, HSI_IOCTL_GET_RX, &ctx);
+	RXCONV(cfg, &ctx);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+int if_hsi_set_tx(int ch, struct hsi_tx_config *cfg)
+{
+	int ret;
+	struct if_hsi_channel *channel;
+	struct hst_ctx ctx;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	TXCONV(&ctx, cfg);
+	spin_lock_bh(&hsi_iface.lock);
+	ret = hsi_ioctl(channel->dev, HSI_IOCTL_SET_TX, &ctx);
+	spin_unlock_bh(&hsi_iface.lock);
+	return ret;
+}
+
+void if_hsi_get_tx(int ch, struct hsi_tx_config *cfg)
+{
+	struct if_hsi_channel *channel;
+	struct hst_ctx ctx;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	hsi_ioctl(channel->dev, HSI_IOCTL_GET_TX, &ctx);
+	TXCONV(cfg, &ctx);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+void if_hsi_cancel_read(int ch)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock(&channel->lock);
+	if (channel->state & HSI_CHANNEL_STATE_READING)
+		hsi_read_cancel(channel->dev);
+	channel->state &= ~HSI_CHANNEL_STATE_READING;
+	spin_unlock(&channel->lock);
+}
+
+void if_hsi_cancel_write(int ch)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock(&channel->lock);
+	if (channel->state & HSI_CHANNEL_STATE_WRITING)
+		hsi_write_cancel(channel->dev);
+	channel->state &= ~HSI_CHANNEL_STATE_WRITING;
+	spin_unlock(&channel->lock);
+}
+
+static int if_hsi_openchannel(struct if_hsi_channel *channel)
+{
+	int ret = 0;
+
+	spin_lock(&channel->lock);
+
+	if (channel->state == HSI_CHANNEL_STATE_UNAVAIL)
+		return -ENODEV;
+
+	if (channel->opened) {
+		ret = -EBUSY;
+		goto leave;
+	}
+
+	if (!channel->dev) {
+		pr_err("Channel %d is not ready??\n",
+				channel->channel_id);
+		ret = -ENODEV;
+		goto leave;
+	}
+
+	ret = hsi_open(channel->dev);
+	if (ret < 0) {
+		pr_err("Could not open channel %d\n",
+				channel->channel_id);
+		goto leave;
+	}
+
+	channel->opened = 1;
+
+leave:
+	spin_unlock(&channel->lock);
+	return ret;
+}
+
+
+static int if_hsi_closechannel(struct if_hsi_channel *channel)
+{
+	int ret = 0;
+
+	spin_lock(&channel->lock);
+
+	if (!channel->opened)
+		goto leave;
+
+	if (!channel->dev) {
+		pr_err("Channel %d is not ready??\n",
+				channel->channel_id);
+		ret = -ENODEV;
+		goto leave;
+	}
+
+	/* Stop any pending read/write */
+	if (channel->state & HSI_CHANNEL_STATE_READING) {
+		hsi_read_cancel(channel->dev);
+		channel->state &= ~HSI_CHANNEL_STATE_READING;
+	}
+	if (channel->state & HSI_CHANNEL_STATE_WRITING) {
+		hsi_write_cancel(channel->dev);
+		channel->state &= ~HSI_CHANNEL_STATE_WRITING;
+	}
+
+	hsi_close(channel->dev);
+
+	channel->opened = 0;
+leave:
+	spin_unlock(&channel->lock);
+	return ret;
+}
+
+
+int if_hsi_start(int ch)
+{
+	struct if_hsi_channel *channel;
+	int ret = 0;
+
+	channel = &hsi_iface.channels[ch];
+	dev_dbg(&channel->dev->device, "%s, ch = %d\n", __func__, ch);
+	spin_lock_bh(&hsi_iface.lock);
+	channel->state = 0;
+	ret = if_hsi_openchannel(channel);
+	if (ret < 0) {
+		pr_err("Could not open channel %d\n", ch);
+		spin_unlock_bh(&hsi_iface.lock);
+		goto error;
+	}
+	spin_unlock_bh(&hsi_iface.lock);
+	if_hsi_poll(ch);
+
+error:
+	return ret;
+}
+
+void if_hsi_stop(int ch)
+{
+	struct if_hsi_channel *channel;
+	channel = &hsi_iface.channels[ch];
+	if_hsi_set_wakeline(ch, 1);
+	spin_lock_bh(&hsi_iface.lock);
+	if_hsi_closechannel(channel);
+	spin_unlock_bh(&hsi_iface.lock);
+}
+
+static int __devinit if_hsi_probe(struct hsi_device *dev)
+{
+	struct if_hsi_channel *channel;
+	unsigned long *address;
+	int ret = -ENXIO, port;
+
+	for (port = 0; port < HSI_MAX_PORTS; port++) {
+		if (if_hsi_char_driver.ch_mask[port])
+			break;
+	}
+
+	if (port == HSI_MAX_PORTS)
+		return -ENXIO;
+
+	if (dev->n_ch >= HSI_MAX_CHAR_DEVS) {
+		pr_err("HSI char driver cannot handle channel %d\n", dev->n_ch);
+		return -ENXIO;
+	}
+
+	address = &if_hsi_char_driver.ch_mask[port];
+
+	spin_lock_bh(&hsi_iface.lock);
+	if (test_bit(dev->n_ch, address) && (dev->n_p == port)) {
+		hsi_set_read_cb(dev, if_hsi_read_done);
+		hsi_set_write_cb(dev, if_hsi_write_done);
+		hsi_set_port_event_cb(dev, if_hsi_port_event);
+		channel = &hsi_iface.channels[dev->n_ch];
+		channel->dev = dev;
+		channel->state = 0;
+		ret = 0;
+		hsi_iface.init_chan_map ^= (1 << dev->n_ch);
+	}
+	spin_unlock_bh(&hsi_iface.lock);
+
+	return ret;
+}
+
+static int __devexit if_hsi_remove(struct hsi_device *dev)
+{
+	struct if_hsi_channel *channel;
+	unsigned long *address;
+	int ret = -ENXIO, port;
+
+	for (port = 0; port < HSI_MAX_PORTS; port++) {
+		if (if_hsi_char_driver.ch_mask[port])
+			break;
+	}
+
+	if (port == HSI_MAX_PORTS)
+		return -ENXIO;
+
+	address = &if_hsi_char_driver.ch_mask[port];
+
+	spin_lock_bh(&hsi_iface.lock);
+	if (test_bit(dev->n_ch, address) && (dev->n_p == port)) {
+		hsi_set_read_cb(dev, NULL);
+		hsi_set_write_cb(dev, NULL);
+		channel = &hsi_iface.channels[dev->n_ch];
+		channel->dev = NULL;
+		channel->state = HSI_CHANNEL_STATE_UNAVAIL;
+		ret = 0;
+	}
+	spin_unlock_bh(&hsi_iface.lock);
+
+	return ret;
+}
+
+static void if_hsi_port_event(struct hsi_device *dev, unsigned int event,
+				void *arg)
+{
+	struct hsi_event ev;
+	int i;
+
+	ev.event = HSI_EV_EXCEP;
+	ev.data = (u32 *)0;
+	ev.count = 0;
+
+	switch (event) {
+	case HSI_EVENT_BREAK_DETECTED:
+		pr_debug("%s, HWBREAK detected\n", __func__);
+		ev.data = (u32 *)HSI_HWBREAK;
+		spin_lock_bh(&hsi_iface.lock);
+		for (i = 0; i < HSI_MAX_CHAR_DEVS; i++) {
+			if (hsi_iface.channels[i].opened)
+				if_notify(i, &ev);
+		}
+		spin_unlock_bh(&hsi_iface.lock);
+		break;
+	case HSI_EVENT_HSR_DATAAVAILABLE:
+		i = (int)arg;
+		pr_debug("%s, HSI_EVENT_HSR_DATAAVAILABLE channel = %d\n",
+								__func__, i);
+		ev.event = HSI_EV_AVAIL;
+		spin_lock_bh(&hsi_iface.lock);
+		if (hsi_iface.channels[i].opened)
+			if_notify(i, &ev);
+		spin_unlock_bh(&hsi_iface.lock);
+		break;
+	case HSI_EVENT_CAWAKE_UP:
+		pr_debug("%s, CAWAKE up\n", __func__);
+		break;
+	case HSI_EVENT_CAWAKE_DOWN:
+		pr_debug("%s, CAWAKE down\n", __func__);
+		break;
+	case HSI_EVENT_ERROR:
+		pr_debug("%s, HSI ERROR occured\n", __func__);
+		break;
+	default:
+		pr_warning("%s, Unknown event(%d)\n", __func__, event);
+		break;
+	}
+}
+
+int __init if_hsi_init(unsigned int port, unsigned int *channels_map)
+{
+	struct if_hsi_channel *channel;
+	int	i, ret = 0;
+
+	port -= 1;
+	if (port >= HSI_MAX_PORTS)
+		return -EINVAL;
+
+	hsi_iface.bootstrap = 1;
+	spin_lock_init(&hsi_iface.lock);
+
+	for (i = 0; i < HSI_MAX_PORTS; i++)
+		if_hsi_char_driver.ch_mask[i] = 0;
+
+	for (i = 0; i < HSI_MAX_CHAR_DEVS; i++) {
+		channel = &hsi_iface.channels[i];
+		channel->dev = NULL;
+		channel->opened = 0;
+		channel->state = 0;
+		channel->channel_id = i;
+		spin_lock_init(&channel->lock);
+		channel->state = HSI_CHANNEL_STATE_UNAVAIL;
+	}
+
+	for (i = 0; (i < HSI_MAX_CHAR_DEVS) && channels_map[i]; i++) {
+		pr_debug("%s, port = %d, channels_map[i] = %d\n", __func__,
+							port, channels_map[i]);
+		if ((channels_map[i] - 1) < HSI_MAX_CHAR_DEVS)
+			if_hsi_char_driver.ch_mask[port] |=
+						(1 << ((channels_map[i] - 1)));
+		else {
+			pr_err("Channel %d cannot be handled by the HSI "
+						"driver.\n", channels_map[i]);
+			return -EINVAL;
+		}
+
+	}
+	hsi_iface.init_chan_map = if_hsi_char_driver.ch_mask[port];
+
+	ret = hsi_register_driver(&if_hsi_char_driver);
+	if (ret)
+		pr_err("Error while registering HSI driver %d", ret);
+
+	if (hsi_iface.init_chan_map) {
+		ret = -ENXIO;
+		pr_err("HSI: Some channels could not be registered (out of "
+					"range or already registered?)\n");
+	}
+	return ret;
+}
+
+int __exit if_hsi_exit(void)
+{
+	struct if_hsi_channel *channel;
+	unsigned long *address;
+	int i, port;
+
+	for (port = 0; port < HSI_MAX_PORTS; port++) {
+		if (if_hsi_char_driver.ch_mask[port])
+			break;
+	}
+
+	if (port == HSI_MAX_PORTS)
+		return -ENXIO;
+
+	address = &if_hsi_char_driver.ch_mask[port];
+
+	for (i = 0; i < HSI_MAX_CHAR_DEVS; i++) {
+		channel = &hsi_iface.channels[i];
+		if (channel->opened) {
+			if_hsi_set_wakeline(i, 1);
+			if_hsi_closechannel(channel);
+		}
+	}
+	hsi_unregister_driver(&if_hsi_char_driver);
+	return 0;
+}
drivers/hsi/hsi-if.h new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#10 lore raw

RFC PATCH 8/9 HSI: HSI device support

In reply to Sebastien Jan

Common registers definition for HSI like devices (common to MIPI HSI and SSI for OMAP platforms)
HSI device definition

---
 arch/arm/mach-omap2/Makefile          |    1 +
 arch/arm/mach-omap2/hsi.c             |  497 +++++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/hsi.h |  432 ++++++++++++++++++++++++++++
 3 files changed, 930 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/hsi.c
 create mode 100644 arch/arm/plat-omap/include/mach/hsi.h
arch/arm/mach-omap2/Makefile +1 -0
index 6b7702f..3de1c20 100644
@@ -87,3 +87,4 @@ obj-y					+= $(onenand-m) $(onenand-y)
 
 smc91x-$(CONFIG_SMC91X)			:= gpmc-smc91x.o
 obj-y					+= $(smc91x-m) $(smc91x-y)
+obj-$(CONFIG_OMAP_HSI_DEVICE)		+= hsi.o
arch/arm/mach-omap2/hsi.c new file +497 -0

497 lines not on this page · raw message

arch/arm/plat-omap/include/mach/hsi.h new file +432 -0

432 lines not on this page · raw message

Signature · 1 line
1.6.0.4
#11 lore raw

RFC PATCH 9/9 HSI: SSI device support and integration on 3430SDP platform

In reply to Sebastien Jan

SSI device definition
Integration on 3430 SDP (pin muxing, platform init)

---
 arch/arm/mach-omap2/Makefile          |    1 +
 arch/arm/mach-omap2/board-3430sdp.c   |   12 +
 arch/arm/mach-omap2/mux.c             |   17 +
 arch/arm/mach-omap2/ssi.c             |  530 +++++++++++++++++++++++++++++++++
 arch/arm/plat-omap/include/mach/mux.h |   10 +
 5 files changed, 570 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/mach-omap2/ssi.c
arch/arm/mach-omap2/Makefile +1 -0
index 3de1c20..34d3e7f 100644
@@ -87,4 +87,5 @@ obj-y					+= $(onenand-m) $(onenand-y)
 
 smc91x-$(CONFIG_SMC91X)			:= gpmc-smc91x.o
 obj-y					+= $(smc91x-m) $(smc91x-y)
+obj-$(CONFIG_OMAP_SSI_DEVICE)		+= ssi.o
 obj-$(CONFIG_OMAP_HSI_DEVICE)		+= hsi.o
arch/arm/mach-omap2/board-3430sdp.c +12 -0
index 2dfab17..f982fd1 100644
@@ -40,6 +40,7 @@
 #include <mach/control.h>
 #include <mach/keypad.h>
 #include <mach/gpmc-smc91x.h>
+#include <mach/hsi.h>
 
 #include "sdram-qimonda-hyb18m512160af-6.h"
 #include "mmc-twl4030.h"
@@ -496,6 +497,13 @@ static struct ehci_hcd_omap_platform_data ehci_pdata __initconst = {
 	.reset_gpio_port[2]  = -EINVAL
 };
 
+#ifdef CONFIG_OMAP_SSI_DEVICE
+static struct omap_ssi_board_config ssi_board_config = {
+	.num_ports = 1,
+	.cawake_gpio = { 151 },
+};
+#endif
+
 static void __init omap_3430sdp_init(void)
 {
 	omap3430_i2c_init();
@@ -513,6 +521,10 @@ static void __init omap_3430sdp_init(void)
 	board_smc91x_init();
 	enable_board_wakeup_source();
 	usb_ehci_init(&ehci_pdata);
+
+#ifdef CONFIG_OMAP_SSI_DEVICE
+	omap_ssi_config(&ssi_board_config);
+#endif
 }
 
 static void __init omap_3430sdp_map_io(void)
arch/arm/mach-omap2/mux.c +17 -0
index b5fac32..8464034 100644
@@ -451,6 +451,23 @@ MUX_CFG_34XX("AD2_3430_USB3FS_PHY_MM3_TXDAT", 0x188,
 MUX_CFG_34XX("AC1_3430_USB3FS_PHY_MM3_TXEN_N", 0x18a,
 		OMAP34XX_MUX_MODE6 | OMAP34XX_PIN_OUTPUT)
 
+/* SSI support */
+MUX_CFG_34XX("AA8_3430_SSI1_DAT_TX", 0x17c,
+		OMAP34XX_MUX_MODE1) /* AC Data */
+MUX_CFG_34XX("AA9_3430_SSI1_FLAG_TX", 0x17e,
+		OMAP34XX_MUX_MODE1) /* AC Flag */
+MUX_CFG_34XX("W8_3430_SSI1_RDY_TX", 0x180,
+		OMAP34XX_MUX_MODE1 | OMAP3_INPUT_EN) /* CA Ready */
+MUX_CFG_34XX("Y8_3430_GPIO_151", 0x182,
+		OMAP34XX_MUX_MODE4 | OMAP3_INPUT_EN) /* CA Wake */
+MUX_CFG_34XX("AE1_3430_SSI1_DAT_RX", 0x184,
+		OMAP34XX_MUX_MODE1 | OMAP3_INPUT_EN) /* CA Data */
+MUX_CFG_34XX("AD1_3430_SSI1_FLAG_RX", 0x186,
+		OMAP34XX_MUX_MODE1 | OMAP3_INPUT_EN) /* CA Flag */
+MUX_CFG_34XX("AD2_3430_SSI1_RDY_RX", 0x188,
+		OMAP34XX_MUX_MODE1) /* AC Ready */
+MUX_CFG_34XX("AC1_3430_SSI1_WAKE", 0x18a,
+		OMAP34XX_MUX_MODE1) /* AC Wake */
 
 /* 34XX GPIO - bidirectional, unless the name has an "_OUT" suffix.
  * (Always specify PIN_INPUT, except for names suffixed by "_OUT".)
arch/arm/mach-omap2/ssi.c new file +530 -0

530 lines not on this page · raw message

arch/arm/plat-omap/include/mach/mux.h +10 -0
index f3c1d8a..4d2d9e4 100644
@@ -782,6 +782,16 @@ enum omap34xx_index {
 	AD2_3430_USB3FS_PHY_MM3_TXDAT,
 	AC1_3430_USB3FS_PHY_MM3_TXEN_N,
 
+	/* SSI support */
+	AA8_3430_SSI1_DAT_TX,
+	AA9_3430_SSI1_FLAG_TX,
+	W8_3430_SSI1_RDY_TX,
+	Y8_3430_GPIO_151,
+	AE1_3430_SSI1_DAT_RX,
+	AD1_3430_SSI1_FLAG_RX,
+	AD2_3430_SSI1_RDY_RX,
+	AC1_3430_SSI1_WAKE,
+
 	/* 34xx GPIO
 	 *  - normally these are bidirectional, no internal pullup/pulldown
 	 *  - "_UP" suffix (GPIO3_UP) if internal pullup is configured
Signature · 1 line
1.6.0.4
#12 lore raw
In reply to Sebastien Jan
Quoted 22 lines · ext Sebastien Jan

This is an RFC for a series of patch to add the support of MIPI HSI and SSI devices to OMAP platforms.
The patch includes the HSI device driver and the device files for MIPI HSI and SSI.

The driver is made of 2 distinct modules:
- omap_hsi: is the Low-Level Driver (or hardware driver). It provides a kernel functional interface, to be used by other kernel modules and abstracts the HW.
This part of the patch is based on Nokia SSI driver, already submitted as RFC by Carlos Chinea [1].
- hsi-char: is a char device driver proposing a user-space interface for using the HSI and relies on omap_hsi.
This part of the patch is based on a development from Andras Domokos.
The intent is to propose a single HSI driver that can support MIPI HSI 1.1 as well as previous implementations (SSI) for OMAP platforms (OMAP3 / OMAP4).

The driver core functionalities are there and ready for review. The following updates will come in the following weeks / months:
- Clocks and Power Management support for OMAP4 platform (HSI device file)
- HSI-char interface documentation

Quoted 4 lines

Validation: The driver is validated on 3430 SDP (with a HW loopback on the SSI device), and is being validated on 4430 Virtio platform (MIPI HSI device).

[1] http://lwn.net/Articles/301918/

pass all your drivers on checkpatch.pl --strict and to sparse as well.

Signature · 1 line
balbi
#13 lore raw
Quoted 24 lines · On Friday 30 October 2009 13:57:50 Felipe Balbi wrote:
Quoted 23 lines · ext Sebastien Jan

This is an RFC for a series of patch to add the support of MIPI HSI and SSI devices to OMAP platforms.
The patch includes the HSI device driver and the device files for MIPI HSI and SSI.

The driver is made of 2 distinct modules:
- omap_hsi: is the Low-Level Driver (or hardware driver). It provides a kernel functional interface, to be used by other kernel modules and abstracts the HW.
This part of the patch is based on Nokia SSI driver, already submitted
as RFC by Carlos Chinea [1].
- hsi-char: is a char device driver proposing a user-space interface for using the HSI and relies on omap_hsi.
This part of the patch is based on a development from Andras Domokos.
The intent is to propose a single HSI driver that can support MIPI HSI 1.1 as well as previous implementations (SSI) for OMAP platforms (OMAP3 / OMAP4).

The driver core functionalities are there and ready for review. The following updates will come in the following weeks / months:
- Clocks and Power Management support for OMAP4 platform (HSI device
file) - HSI-char interface documentation

Quoted 7 lines
Quoted 5 lines

Validation: The driver is validated on 3430 SDP (with a HW loopback on the SSI device), and is being validated on 4430 Virtio platform (MIPI HSI device).

[1] http://lwn.net/Articles/301918/

pass all your drivers on checkpatch.pl --strict and to sparse as well.

Thanks to point this out: I forgot to mention that I did run checkpatch.pl -- strict and sparse on these patches.

#14 lore raw
Quoted 29 lines · ext Sebastien Jan
Quoted 28 lines · On Friday 30 October 2009 13:57:50 Felipe Balbi wrote:
Quoted 27 lines · ext Sebastien Jan

This is an RFC for a series of patch to add the support of MIPI HSI and SSI devices to OMAP platforms.
The patch includes the HSI device driver and the device files for MIPI HSI and SSI.

The driver is made of 2 distinct modules:
- omap_hsi: is the Low-Level Driver (or hardware driver). It provides a kernel functional interface, to be used by other kernel modules and abstracts the HW.
This part of the patch is based on Nokia SSI driver, already submitted
as RFC by Carlos Chinea [1].
- hsi-char: is a char device driver proposing a user-space interface for using the HSI and relies on omap_hsi.
This part of the patch is based on a development from Andras Domokos.
The intent is to propose a single HSI driver that can support MIPI HSI 1.1 as well as previous implementations (SSI) for OMAP platforms (OMAP3 / OMAP4).

The driver core functionalities are there and ready for review. The following updates will come in the following weeks / months:
- Clocks and Power Management support for OMAP4 platform (HSI device
file) - HSI-char interface documentation

Validation: The driver is validated on 3430 SDP (with a HW loopback on the SSI device), and is being validated on 4430 Virtio platform (MIPI HSI device).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

[1] http://lwn.net/Articles/301918/

pass all your drivers on checkpatch.pl --strict and to sparse as well.

Thanks to point this out: I forgot to mention that I did run checkpatch.pl -- strict and sparse on these patches.

Weird they passed. Just looking over the patches I saw some weird comments here and there.

Signature · 1 line
balbi