tsif: tsif1 initialization bug fix

When using CONFIG_MSM_USE_TSIF1 to enable the second tsif instance,
the device initialization failed because of a errant device ID. The
check has been updated to accept the correct device ID range (0..1)

Signed-off-by: Joel Nider <jnider@codeaurora.org>
diff --git a/drivers/misc/tsif.c b/drivers/misc/tsif.c
index 53d4ef2..90e65b4 100644
--- a/drivers/misc/tsif.c
+++ b/drivers/misc/tsif.c
@@ -91,6 +91,7 @@
 #define TSIF_CHUNKS_IN_BUF        (tsif_device->chunks_per_buf)
 #define TSIF_PKTS_IN_BUF          (TSIF_PKTS_IN_CHUNK * TSIF_CHUNKS_IN_BUF)
 #define TSIF_BUF_SIZE             (TSIF_PKTS_IN_BUF * TSIF_PKT_SIZE)
+#define TSIF_MAX_ID               1
 
 #define ROW_RESET                 (MSM_CLK_CTL_BASE + 0x214)
 #define GLBL_CLK_ENA              (MSM_CLK_CTL_BASE + 0x000)
@@ -1267,8 +1268,8 @@
 		rc = -EINVAL;
 		goto out;
 	}
-/*TODO macro for max. id*/
-	if ((pdev->id < 0) || (pdev->id > 0)) {
+
+	if ((pdev->id < 0) || (pdev->id > TSIF_MAX_ID)) {
 		dev_err(&pdev->dev, "Invalid device ID %d\n", pdev->id);
 		rc = -EINVAL;
 		goto out;
@@ -1426,9 +1427,21 @@
 
 /* public API */
 
+int tsif_get_active(void)
+{
+	struct msm_tsif_device *tsif_device;
+	list_for_each_entry(tsif_device, &tsif_devices, devlist) {
+		return tsif_device->pdev->id;
+	}
+	return -ENODEV;
+}
+EXPORT_SYMBOL(tsif_get_active);
+
 void *tsif_attach(int id, void (*notify)(void *client_data), void *data)
 {
 	struct msm_tsif_device *tsif_device = tsif_find_by_id(id);
+	if (!tsif_device)
+		return ERR_PTR(-ENODEV);
 	if (tsif_device->client_notify || tsif_device->client_data)
 		return ERR_PTR(-EBUSY);
 	tsif_device->client_notify = notify;
diff --git a/drivers/misc/tsif_chrdev.c b/drivers/misc/tsif_chrdev.c
index 4068ac3..122c7ed 100644
--- a/drivers/misc/tsif_chrdev.c
+++ b/drivers/misc/tsif_chrdev.c
@@ -4,7 +4,7 @@
  * Character device that, being read
  * returns stream of TSIF packets.
  *
- * Copyright (c) 2009-2010, Code Aurora Forum. All rights
+ * Copyright (c) 2009-2011, Code Aurora Forum. All rights
  * reserved.
  *
  * This program is free software; you can redistribute it and/or modify
@@ -186,6 +186,7 @@
 static int __init mod_init(void)
 {
 	int rc;
+	int instance;
 	rc = alloc_chrdev_region(&tsif_dev, 0, TSIF_NUM_DEVS, "tsif");
 	if (rc) {
 		pr_err("alloc_chrdev_region failed: %d\n", rc);
@@ -198,7 +199,11 @@
 		pr_err("Error creating tsif class: %d\n", rc);
 		goto err_class;
 	}
-	rc = tsif_init_one(&the_devices[0], 0);
+	instance = tsif_get_active();
+	if (instance >= 0)
+		rc = tsif_init_one(&the_devices[0], instance);
+	else
+		rc = instance;
 	if (rc)
 		goto err_init1;
 	return 0;
diff --git a/include/linux/tsif_api.h b/include/linux/tsif_api.h
index 3142b7b..fc4d20b 100644
--- a/include/linux/tsif_api.h
+++ b/include/linux/tsif_api.h
@@ -105,6 +105,13 @@
 };
 
 /**
+ * tsif_get_active - return active tsif hardware instance
+ *
+ * Return     TSIF instance to use (selected by CONFIG_MSM_USE_TSIF1)
+ */
+int tsif_get_active(void);
+
+/**
  * tsif_attach - Attach to the device.
  * @id:       TSIF device ID, used to identify TSIF instance.
  * @notify:   client callback, called when