aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ Freyensee <james_p_freyensee@linux.intel.com>2010-12-08 10:57:34 +0000
committerAlan Cox <alan@linux.intel.com>2010-12-08 10:57:34 +0000
commit66d4bf1d02be2c18d201ee661b3d988800fbead2 (patch)
treee73170bef337d12f040c05bfd06e365119f12dd2
parentcc3d5d375ce462167c8205c5bef3af915dae725d (diff)
downloadmrst-s0i3-test-66d4bf1d02be2c18d201ee661b3d988800fbead2.tar.gz
mrst-s0i3-test-66d4bf1d02be2c18d201ee661b3d988800fbead2.tar.xz
mrst-s0i3-test-66d4bf1d02be2c18d201ee661b3d988800fbead2.zip
From: J Freyensee <james_p_freyensee@linux.intel.com>
pti: Intel PTI driver The PTI (Parallel Trace Interface) driver directs trace data routed from various parts in the system out through an Intel Penwell PTI port and out of the mobile device for analysis with a debugging tool. Signed-off-by: Alan Cox <alan@linux.intel.com>
-rw-r--r--drivers/char/Kconfig13
-rw-r--r--drivers/misc/Kconfig12
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/pti.c754
-rw-r--r--include/linux/pti.h38
5 files changed, 818 insertions, 0 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 43d3395325c..f286f48d503 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -110,6 +110,19 @@ config BFIN_JTAG_COMM_CONSOLE
bool "Console on Blackfin JTAG"
depends on BFIN_JTAG_COMM=y
+config PTI_ROUTER
+ tristate "Trace data router for MIPI P1149.7 cJTAG standard"
+ depends on INTEL_MID_PTI
+ ---help---
+ The PTI router uses the Linux tty line discipline framework to route
+ trace data coming from a HW Modem to a PTI (Parallel Trace Inferface)
+ port. This is part of a solution for the MIPI P1149.7, compact JTAG,
+ standard, which is for debugging mobile devices. The PTI
+ Driver is also needed for this solution.
+
+ You should select this driver if the target kernel is meant for
+ a mobile device containing a MIPI P1149.7 standard implementation.
+
config SERIAL_NONSTANDARD
bool "Non-standard serial port support"
depends on HAS_IOMEM
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 4d073f1e450..8ce395f22df 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -452,6 +452,18 @@ config PCH_PHUB
To compile this driver as a module, choose M here: the module will
be called pch_phub.
+config INTEL_MID_PTI
+ tristate "Parallel Trace Interface for MIPI P1149.7 cJTAG standard"
+ help
+ The PTI (Parallel Trace Interface) driver directs
+ trace data routed from various parts in the system out
+ through an Intel Penwell PTI port and out of the mobile
+ device for analysis with a debugging tool (Lauterbach or Fido).
+
+ You should select this driver if the target kernel is meant for
+ an Intel Atom (non-netbook) mobile device containing a MIPI
+ P1149.7 standard implementation.
+
source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 98009cc20cb..78243e5e092 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -4,6 +4,7 @@
obj-$(CONFIG_IBM_ASM) += ibmasm/
obj-$(CONFIG_AD525X_DPOT) += ad525x_dpot.o
+obj-$(CONFIG_INTEL_MID_PTI) += pti.o
obj-$(CONFIG_AD525X_DPOT_I2C) += ad525x_dpot-i2c.o
obj-$(CONFIG_AD525X_DPOT_SPI) += ad525x_dpot-spi.o
obj-$(CONFIG_ATMEL_PWM) += atmel_pwm.o
diff --git a/drivers/misc/pti.c b/drivers/misc/pti.c
new file mode 100644
index 00000000000..f1b5e4b3578
--- /dev/null
+++ b/drivers/misc/pti.c
@@ -0,0 +1,754 @@
+/*
+ * pti.c - PTI driver for cJTAG data extration
+ *
+ * Copyright (C) Intel 2010
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA
+ */
+
+
+/*
+ * The PTI (Parallel Trace Interface) driver directs trace data routed from
+ * various parts in the system out through the Intel Penwell PTI port and
+ * out of the mobile device for analysis with a debugging tool
+ * (Lauterbach, Fido). This is part of a solution for the MIPI P1149.7,
+ * compact JTAG, standard.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/tty.h>
+#include <linux/tty_driver.h>
+#include <linux/pci.h>
+#include <linux/mutex.h>
+#include <linux/miscdevice.h>
+#include <linux/pti.h>
+
+#define DRIVERNAME "pti"
+#define PCINAME "pciPTI"
+#define TTYNAME "ttyPTI"
+#define CHARNAME "pti"
+#define MAX_APP_IDS 256
+#define MAX_OS_IDS 128
+#define OS_BASE_ID 72 /* base OS master ID address */
+#define APP_BASE_ID 80 /* base App master ID address */
+
+struct pti_tty {
+ struct masterchannel *mc;
+};
+
+struct pti_dev {
+ struct tty_port port;
+ unsigned long pti_addr;
+ unsigned long aperture_base;
+ void __iomem *pti_ioaddr;
+ unsigned long pti_iolen;
+ u8 IA_App[MAX_APP_IDS];
+ u8 IA_OS[MAX_OS_IDS];
+};
+
+
+static DEFINE_MUTEX(alloclock);
+
+static struct pci_device_id pci_ids[] __devinitconst = {
+ { PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x82B) },
+ {}
+};
+
+static struct tty_driver *pti_tty_driver;
+
+static struct pti_dev *drv_data;
+
+
+#define DTS 0x30 /* offset for last dword of a PTI message */
+
+/**
+ * pti_write_to_aperture() - THE private write function to PTI HW.
+ * @mc: The 'aperture'. It's part of a write address that holds
+ * a master and channel ID.
+ * @buf: Data being written to the HW that will ultimately be seen
+ * in a debugging tool (Fido, Lauterbach).
+ * @len: Size of buffer.
+ *
+ * Since each aperture is specified by a unique
+ * master/channel ID, no two processes will be writing
+ * to the same aperture at the same time so no lock is required. The
+ * PTI-Output agent will send these out in the order that they arrived, and
+ * thus, it will intermix these messages. The debug tool can then later
+ * regroup the appropriate message segments together reconstituting each
+ * message.
+ */
+static void pti_write_to_aperture(struct masterchannel *mc, u8 *buf, int len)
+{
+ int dwordcnt, final, i;
+ union {
+ u32 val;
+ u8 c[4];
+ } ptiword;
+ u8 *p;
+ u32 __iomem *aperture;
+
+ p = buf;
+
+ /*
+ calculate the aperture offset from the base using the master and
+ channel id's.
+ */
+ aperture = drv_data->pti_ioaddr + (mc->master << 15)
+ + (mc->channel << 8);
+
+ dwordcnt = len >> 2;
+ final = len - (dwordcnt << 2); /* final = trailing bytes */
+ if (final == 0 && dwordcnt != 0) { /* always have a final dword */
+ final += 4;
+ dwordcnt--;
+ }
+
+ /*
+ FIXME: This algorithm builds the dword from the input buffer.
+ This algorithm does work correctly with the PTI HW
+ and Fido debugging HW. However, this got flagged in upstream
+ review not conforming to proper endian practices.
+ u32 ptiword = cpu_to_le32(*(u32 *)p);
+ was tried but was incorrect endianess. Then the Fido
+ HW used to test this code broke. The goal is to submit
+ something known to work and then fix this when it can be tested.
+ */
+ for (i = 0; i < dwordcnt; i++) {
+ ptiword.c[3] = *p++;
+ ptiword.c[2] = *p++;
+ ptiword.c[1] = *p++;
+ ptiword.c[0] = *p++;
+ pr_debug("%s(%d): PTI aperture: master(%d), channel(%d)\n",
+ __func__, __LINE__, mc->master, mc->channel);
+ pr_debug("%s(%d): PTI double word: %#x\n\n",
+ __func__, __LINE__, ptiword.val);
+ iowrite32(ptiword.val, aperture);
+ }
+
+ aperture += DTS; /* adding DTS signals that is EOM */
+ ptiword.val = 0;
+ /*
+ FIXME: This has the same issue as stated in other FIXME.
+ u32 ptiword |= *p++ << (8 * i); was tried and had the
+ same character-swapping endianess problem.
+ */
+ for (i = 0; i < final; i++)
+ ptiword.c[3-i] = *p++;
+
+ pr_debug("%s(%d): PTI aperture: master(%d), channel(%d)\n",
+ __func__, __LINE__, mc->master, mc->channel);
+ pr_debug("%s(%d): Final PTI double word: %#x\n\n",
+ __func__, __LINE__, ptiword.val);
+ iowrite32(ptiword.val, aperture);
+
+ return;
+}
+
+/**
+ * getID(): Allocate a master and channel ID.
+ *
+ * @IDarray:
+ * @max_IDS: The max amount of available write IDs to use.
+ * @baseID: The starting SW channel ID, based on the Intel
+ * PTI arch.
+ *
+ * @return: masterchannel struct containing master, channel ID address,
+ * or 0 for error.
+ *
+ * Each bit in the arrays IA_App and IA_OS correspond to a master and
+ * channel id. The bit is one if the id is taken and 0 if free. For
+ * every master there are 128 channel id's.
+ */
+static struct masterchannel *getID(u8 *IDarray, int max_IDS, int baseID)
+{
+ struct masterchannel *mc;
+ int i, j, mask;
+
+ mc = kmalloc(sizeof(struct masterchannel), GFP_KERNEL);
+ if (mc == NULL)
+ return 0;
+
+ /* look for a byte with a free bit */
+ for (i = 0; i < max_IDS; i++)
+ if (IDarray[i] != 0xff)
+ break;
+ if (i == max_IDS)
+ return 0;
+ /* find the bit */
+ mask = 0x80;
+ for (j = 0; j < 8; j++) {
+ if ((IDarray[i] & mask) == 0)
+ break;
+ mask >>= 1;
+ }
+
+ /* grab it */
+ IDarray[i] |= mask;
+ mc->master = (i>>4)+baseID;
+ mc->channel = ((i & 0xf)<<3) + j;
+ return mc;
+}
+
+/*
+ The following three functions:
+ mipi_request_mastercahannel(), mipi_release masterchannel()
+ and mipi_write_data() are an API for other kernel drivers to
+ access PTI.
+*/
+
+/**
+ * mipi_request_masterchannel() - Kernel API function used to allocate
+ * a master, channel ID address to write to
+ * PTI HW.
+ * @type: 0- request Application master, channel aperture ID write address.
+ * 1- request OS master, channel aperture ID write address.
+ * Other values, error.
+ * @return: masterchannel struct or 0 for error.
+ *
+ */
+struct masterchannel *mipi_request_masterchannel(u8 type)
+{
+ struct masterchannel *mc;
+
+ mutex_lock(&alloclock);
+
+ switch (type) {
+
+ case 0:
+ mc = getID(drv_data->IA_App, MAX_APP_IDS, APP_BASE_ID);
+ break;
+
+ case 1:
+ mc = getID(drv_data->IA_OS, MAX_OS_IDS, OS_BASE_ID);
+ break;
+
+ default:
+ mutex_unlock(&alloclock);
+ return 0;
+ }
+
+ mutex_unlock(&alloclock);
+ return mc;
+}
+EXPORT_SYMBOL(mipi_request_masterchannel);
+
+/**
+ * mipi_release_masterchannel() - Kernel API function used to release
+ * a master, channel ID address
+ * used to write to PTI HW.
+ * @mc: master, channel apeture ID address to be released.
+ *
+ */
+void mipi_release_masterchannel(struct masterchannel *mc)
+{
+ u8 master, channel, i;
+ if (mc) {
+ master = mc->master;
+ channel = mc->channel;
+
+ if (master >= 80) {
+ i = ((master-80) << 4) + (channel>>3);
+ drv_data->IA_App[i] &= ~(0x80>>(channel & 0x7));
+ }
+ if (master >= 72) {
+ i = ((master-72) << 4) + (channel>>3);
+ drv_data->IA_OS[i] &= ~(0x80>>(channel & 0x7));
+ }
+
+ kfree(mc);
+ }
+}
+EXPORT_SYMBOL(mipi_release_masterchannel);
+
+/**
+ * mipi_pti_writedata() - Kernel API function used to write trace
+ * debugging data to PTI HW.
+ *
+ * @mc: Master, channel aperture ID address to write to.
+ * Null value will return with no write occurring.
+ * @buf: Trace debuging data to write to the PTI HW.
+ * Null value will return with no write occurring.
+ * @count: Size of buf. Value of 0 or a negative number will
+ * retrn with no write occuring.
+ */
+void mipi_pti_writedata(struct masterchannel *mc, u8 *buf, int count)
+{
+ /*
+ since this function is exported, this is treated like an
+ API function, thus, all parameters should
+ be checked for validity.
+ */
+ if ((mc != NULL) && (buf != NULL) && (count > 0)) {
+ pti_write_to_aperture(mc, buf, count);
+ pr_debug("%s(%d): buf: %s, len: %d\n", __func__, __LINE__,
+ buf, count);
+ }
+ return;
+}
+EXPORT_SYMBOL(mipi_pti_writedata);
+
+static const struct tty_port_operations tty_port_ops = {
+};
+
+static void __devexit pti_pci_remove(struct pci_dev *pdev)
+{
+ struct pti_dev *drv_data;
+
+ drv_data = pci_get_drvdata(pdev);
+ if (drv_data != NULL) {
+ pci_iounmap(pdev, drv_data->pti_ioaddr);
+ pci_set_drvdata(pdev, NULL);
+ kfree(drv_data);
+ pci_release_region(pdev, 0);
+ pci_disable_device(pdev);
+ }
+}
+
+/*
+ for the tty_driver_*() basic function descriptions, see tty_driver.h.
+ Specific header comments made for PTI-related specifics.
+*/
+
+/**
+ * pti_tty_driver_open()- Open an Application master, channel aperture
+ * ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_open() call.
+ *
+ * @return int : Success = 0, otherwise fail.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static int pti_tty_driver_open(struct tty_struct *tty, struct file *filp)
+{
+ struct pti_tty *pti_tty_data;
+ struct masterchannel *mc;
+ int ret = 0;
+
+ pr_debug("%s %s(%d): Called.\n", __FILE__, __func__, __LINE__);
+
+ /*
+ we actually want to allocate a new channel per open, per
+ system arch. HW gives more than plenty channels for a single
+ system task to have its own channel to write trace data. This
+ also removes a locking requirement for the actual write
+ procedure.
+ */
+ ret = tty_port_open(&drv_data->port, tty, filp);
+ pti_tty_data = tty->driver_data;
+ mc = mipi_request_masterchannel(0);
+ pti_tty_data->mc = mc;
+
+ return ret;
+}
+
+/**
+ * pti_tty_driver_close()- close tty device and release Application
+ * master, channel aperture ID to the PTI device via tty device.
+ *
+ * @param tty: tty interface.
+ * @param filp: filp interface pased to tty_port_close() call.
+ *
+ * The main purpose of using the tty device interface is to route
+ * syslog daemon messages to the PTI HW and out of the handheld platform
+ * and to the Fido/Lauterbach device.
+ */
+static void pti_tty_driver_close(struct tty_struct *tty, struct file *filp)
+{
+ struct pti_tty *pti_tty_data;
+ struct masterchannel *mc;
+
+ pr_debug("%s(%d): Called.\n", __func__, __LINE__);
+
+ pti_tty_data = tty->driver_data;
+ if (pti_tty_data != NULL) {
+ mc = pti_tty_data->mc;
+ mipi_release_masterchannel(mc);
+ }
+
+ tty_port_close(&drv_data->port, tty, filp);
+
+ return;
+}
+
+static int pti_tty_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+ int idx = tty->index;
+ struct pti_tty *pti_tty_data;
+
+ int ret = tty_init_termios(tty);
+
+ if (ret == 0) {
+ tty_driver_kref_get(driver);
+ tty->count++;
+ driver->ttys[idx] = tty;
+
+ pti_tty_data = kmalloc(sizeof(struct pti_tty), GFP_KERNEL);
+ if (pti_tty_data == NULL)
+ return -ENOMEM;
+
+ tty->driver_data = pti_tty_data;
+ }
+
+ return ret;
+}
+
+static void pti_tty_cleanup(struct tty_struct *tty)
+{
+ struct pti_tty *pti_tty_data;
+
+ pti_tty_data = tty->driver_data;
+ if (pti_tty_data != NULL)
+ kfree(pti_tty_data);
+
+ tty->driver_data = NULL;
+}
+
+/**
+ * pti_tty_driver_write(): Write trace debugging data through the char
+ * interface to the PTI HW. Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ * master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len: # of byte to write.
+ * @param ppose: Not used in this function implementation.
+ * @return int : # of bytes written, or error. -EMSGSIZE is
+ * returned if length is beyond 8k.
+ */
+int pti_tty_driver_write(struct tty_struct *tty,
+ const unsigned char *buf, int len)
+{
+ struct masterchannel *mc;
+ struct pti_tty *pti_tty_data;
+
+ pr_debug("%s(%d): buf: %s, len: %d\n", __func__, __LINE__, buf, len);
+
+ pti_tty_data = tty->driver_data;
+ mc = pti_tty_data->mc;
+ pti_write_to_aperture(mc, (u8 *)buf, len);
+
+ return len;
+}
+
+int pti_tty_write_room(struct tty_struct *tty)
+{
+ return 2048;
+}
+
+/**
+ * pti_char_open()- Open an Application master, channel aperture
+ * ID to the PTI device. Part of the misc device implementation.
+ *
+ * @param inode: not used.
+ * @param filp: Output- will have a masterchannel struct set containing
+ * the allocated application PTI aperture write address.
+ *
+ * @return int : Success = 0, otherwise fail. As of right now,
+ * it is not sure what needs to really be initialized
+ * for open(), so it always returns 0.
+ */
+int pti_char_open(struct inode *inode, struct file *filp)
+{
+ struct masterchannel *mc;
+
+ mc = mipi_request_masterchannel(0);
+ if (mc == NULL)
+ return -ENOMEM;
+ filp->private_data = mc;
+ return 0;
+}
+
+/**
+ * pti_char_release()- Close a char channel to the PTI device. Part
+ * of the misc device implementation.
+ *
+ * @param inode: Not used in this implementaiton.
+ * @param filp: Contains private_data that contains the master, channel
+ * ID to be released by the PTI device.
+ *
+ * @return int : Success = 0
+ */
+int pti_char_release(struct inode *inode, struct file *filp)
+{
+ mipi_release_masterchannel(filp->private_data);
+
+ return 0;
+}
+
+/**
+ * pti_char_write(): Write trace debugging data through the char
+ * interface to the PTI HW. Part of the misc device implementation.
+ *
+ * @param filp: Contains private data which is used to obtain
+ * master, channel write ID.
+ * @param data: trace data to be written.
+ * @param len: # of byte to write.
+ * @param ppose: Not used in this function implementation.
+ * @return int : # of bytes written, or error. -EMSGSIZE is
+ * returned if length is beyond 8k.
+ */
+ssize_t pti_char_write(struct file *filp, const char *data, size_t len,
+ loff_t *ppose)
+{
+ int retval;
+
+ struct masterchannel *mc;
+ void *kbuf;
+
+ /*
+ adding a limit on the size of the buffer, since this
+ is a value that can be passed in by a user and we want to
+ minimize the chance of crashing alloc. Returning
+ EMSGSIZE actually seems to be the best error code
+ for a user to figure out what happened.
+ */
+ if (len > 8192)
+ return -EMSGSIZE;
+
+ mc = filp->private_data;
+
+ kbuf = kmalloc(len, GFP_KERNEL);
+ if (kbuf == NULL)
+ return 0;
+ retval = copy_from_user(kbuf, data, len);
+ if (retval) {
+ kfree(kbuf);
+ return -EFAULT;
+ }
+
+ pr_debug("%s(%d): buf: %s, len: %d\n", __func__, __LINE__, data, len);
+ pti_write_to_aperture(mc, kbuf, len);
+ kfree(kbuf);
+ kbuf = 0;
+
+ return len;
+}
+
+const struct tty_operations pti_tty_driver_ops = {
+ .open = pti_tty_driver_open,
+ .close = pti_tty_driver_close,
+ .write = pti_tty_driver_write,
+ .write_room = pti_tty_write_room,
+ .install = pti_tty_install,
+ .cleanup = pti_tty_cleanup
+};
+
+const struct file_operations pti_char_driver_ops = {
+ .owner = THIS_MODULE,
+ .open = pti_char_open,
+ .release = pti_char_release,
+ .write = pti_char_write,
+};
+
+static struct miscdevice pti_char_driver = {
+ .minor = MISC_DYNAMIC_MINOR,
+ .name = CHARNAME,
+ .fops = &pti_char_driver_ops
+};
+
+/*
+ Note the _probe() call sets everything up and ties the char and tty
+ to successfully detecting the PTI device on the pci bus.
+*/
+
+static int __devinit pti_pci_probe(struct pci_dev *pdev,
+ const struct pci_device_id *ent)
+{
+ int retval = -EINVAL;
+ int pci_bar = 1;
+
+ dev_dbg(&pdev->dev, "%s %s(%d): PTI PCI ID %04x:%04x\n", __FILE__,
+ __func__, __LINE__, pdev->vendor, pdev->device);
+
+ retval = pci_enable_device(pdev);
+ if (retval != 0) {
+ dev_err(&pdev->dev,
+ "%s: pci_enable_device() returned error %d\n",
+ __func__, retval);
+ return retval;
+ }
+
+ drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+
+ if (drv_data == NULL) {
+ retval = -ENOMEM;
+ dev_err(&pdev->dev,
+ "%s(%d): kmalloc() returned NULL memory.\n",
+ __func__, __LINE__);
+ return retval;
+ }
+ drv_data->pti_addr = pci_resource_start(pdev, pci_bar);
+
+ retval = pci_request_region(pdev, pci_bar, dev_name(&pdev->dev));
+ if (retval != 0) {
+ dev_err(&pdev->dev,
+ "%s(%d): pci_request_region() returned error %d\n",
+ __func__, __LINE__, retval);
+ kfree(drv_data);
+ return retval;
+ }
+ drv_data->pti_iolen = pci_resource_len(pdev, pci_bar);
+ drv_data->aperture_base = drv_data->pti_addr+APERTURE_14;
+ drv_data->pti_ioaddr =
+ ioremap_nocache((u32)drv_data->aperture_base,
+ APERTURE_LEN);
+ if (!drv_data->pti_ioaddr) {
+ pci_release_region(pdev, pci_bar);
+ retval = -ENOMEM;
+ kfree(drv_data);
+ return retval;
+ }
+
+ pci_set_drvdata(pdev, drv_data);
+
+ tty_port_init(&drv_data->port);
+ drv_data->port.ops = &tty_port_ops;
+
+ tty_register_device(pti_tty_driver, 0, NULL);
+
+ retval = misc_register(&pti_char_driver);
+ if (retval) {
+ pr_err("%s(%d): CHAR registration failed of pti driver\n",
+ __func__, __LINE__);
+ pr_err("%s(%d): Error value returned: %d\n",
+ __func__, __LINE__, retval);
+ return retval;
+ }
+
+ return retval;
+}
+
+static struct pci_driver pti_pci_driver = {
+ .name = PCINAME,
+ .id_table = pci_ids,
+ .probe = pti_pci_probe,
+ .remove = pti_pci_remove,
+};
+
+/**
+ *
+ * pti_init():
+ *
+ * @return int __init: 0 for success, any other value error.
+ *
+ */
+static int __init pti_init(void)
+{
+ int retval = -EINVAL;
+
+ /* First register module as tty device */
+
+ pti_tty_driver = alloc_tty_driver(1);
+ if (pti_tty_driver == NULL) {
+ pr_err("%s(%d): Memory allocation failed for ptiTTY driver\n",
+ __func__, __LINE__);
+ return -ENOMEM;
+ }
+
+ pti_tty_driver->owner = THIS_MODULE;
+ pti_tty_driver->magic = TTY_DRIVER_MAGIC;
+ pti_tty_driver->driver_name = DRIVERNAME;
+ pti_tty_driver->name = TTYNAME;
+ pti_tty_driver->major = 0;
+ pti_tty_driver->minor_start = 0;
+ pti_tty_driver->minor_num = 1;
+ pti_tty_driver->num = 1;
+ pti_tty_driver->type = TTY_DRIVER_TYPE_SYSTEM;
+ pti_tty_driver->subtype = SYSTEM_TYPE_SYSCONS;
+ pti_tty_driver->flags = TTY_DRIVER_REAL_RAW |
+ TTY_DRIVER_DYNAMIC_DEV;
+ pti_tty_driver->init_termios = tty_std_termios;
+
+ tty_set_operations(pti_tty_driver, &pti_tty_driver_ops);
+
+ retval = tty_register_driver(pti_tty_driver);
+ if (retval) {
+ pr_err("%s(%d): TTY registration failed of pti driver\n",
+ __func__, __LINE__);
+ pr_err("%s(%d): Error value returned: %d\n",
+ __func__, __LINE__, retval);
+
+ pti_tty_driver = 0;
+ return retval;
+ }
+
+ retval = pci_register_driver(&pti_pci_driver);
+
+ if (retval) {
+ pr_err("%s(%d): PCI registration failed of pti driver\n",
+ __func__, __LINE__);
+ pr_err("%s(%d): Error value returned: %d\n",
+ __func__, __LINE__, retval);
+
+ tty_unregister_driver(pti_tty_driver);
+ pr_err("%s(%d): Unregistering TTY part of pti driver\n",
+ __func__, __LINE__);
+ pti_tty_driver = 0;
+ return retval;
+ }
+
+ return retval;
+}
+
+/**
+ * pti_exit(): Unregisters this module as a tty and pci driver.
+ */
+static void __exit pti_exit(void)
+{
+ int retval;
+
+ /* If some thead is hanging onto the alloclock, force it to release
+ * it because we are shutting down.
+ */
+ if (mutex_is_locked(&alloclock) == 1)
+ mutex_unlock(&alloclock);
+ mutex_destroy(&alloclock);
+
+ retval = misc_deregister(&pti_char_driver);
+ if (retval) {
+ pr_err("%s(%d): CHAR unregistration failed of pti driver\n",
+ __func__, __LINE__);
+ pr_err("%s(%d): Error value returned: %d\n",
+ __func__, __LINE__, retval);
+ }
+
+ tty_unregister_device(pti_tty_driver, 0);
+
+ retval = tty_unregister_driver(pti_tty_driver);
+ if (retval) {
+ pr_err("%s(%d): TTY unregistration failed of pti driver\n",
+ __func__, __LINE__);
+ pr_err("%s(%d): Error value returned: %d\n",
+ __func__, __LINE__, retval);
+ }
+
+ kfree(drv_data);
+
+ return;
+}
+
+module_init(pti_init);
+module_exit(pti_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Ken Mills, Jay Freyensee");
+MODULE_DESCRIPTION("PTI Driver");
+
diff --git a/include/linux/pti.h b/include/linux/pti.h
new file mode 100644
index 00000000000..07c73b70529
--- /dev/null
+++ b/include/linux/pti.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) Intel 2010
+ * Ken Mills <ken.k.mills@intel.com>
+ *
+ * This program 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 program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ * USA
+ *
+ */
+
+#ifndef PTI_H_
+#define PTI_H_
+
+
+struct masterchannel {
+ u8 master;
+ u8 channel;
+};
+
+
+void mipi_pti_writedata(struct masterchannel *mc, u8 *cp, int count);
+struct masterchannel *mipi_request_masterchannel(u8 kerneluser);
+void mipi_release_masterchannel(struct masterchannel *mc);
+
+#define APERTURE_14 0x3800000
+#define APERTURE_LEN 0x400000
+
+#endif /*PTI_H_*/