Merge "msm8974: board: add gpiomux configuration for SDC3/SDC4 slot GPIOs"
diff --git a/arch/arm/mach-msm/mpm-of.c b/arch/arm/mach-msm/mpm-of.c
index e4c0e4e..430bda1 100644
--- a/arch/arm/mach-msm/mpm-of.c
+++ b/arch/arm/mach-msm/mpm-of.c
@@ -179,6 +179,9 @@
 
 		reg = MSM_MPM_REG_POLARITY;
 		msm_mpm_write(reg, i, msm_mpm_polarity[i]);
+
+		reg = MSM_MPM_REG_STATUS;
+		msm_mpm_write(reg, i, 0);
 	}
 
 	/*
diff --git a/drivers/mmc/host/msm_sdcc.c b/drivers/mmc/host/msm_sdcc.c
index f3598cf..e8f3d38 100644
--- a/drivers/mmc/host/msm_sdcc.c
+++ b/drivers/mmc/host/msm_sdcc.c
@@ -2182,13 +2182,7 @@
 	spin_lock_irqsave(&host->lock, flags);
 
 	if (host->eject) {
-		if (mrq->data && !(mrq->data->flags & MMC_DATA_READ)) {
-			mrq->cmd->error = 0;
-			mrq->data->bytes_xfered = mrq->data->blksz *
-						  mrq->data->blocks;
-		} else
-			mrq->cmd->error = -ENOMEDIUM;
-
+		mrq->cmd->error = -ENOMEDIUM;
 		spin_unlock_irqrestore(&host->lock, flags);
 		mmc_request_done(mmc, mrq);
 		return;
diff --git a/drivers/power/bq28400_battery.c b/drivers/power/bq28400_battery.c
index 77e74fa..1852687 100644
--- a/drivers/power/bq28400_battery.c
+++ b/drivers/power/bq28400_battery.c
@@ -395,7 +395,7 @@
 
 /*
  * Return the battery Relative-State-Of-Charge 0..100 %
- * Or 0 if something fails.
+ * Or negative value if something fails.
  */
 static int bq28400_read_rsoc(struct i2c_client *client)
 {
@@ -404,8 +404,10 @@
 	/* This register is only 1 byte */
 	percentage = i2c_smbus_read_byte_data(client, SBS_RSOC);
 
-	if (percentage < 0)
-		return 0;
+	if (percentage < 0) {
+		pr_err("I2C failure when reading rsoc.\n");
+		return percentage;
+	}
 
 	pr_debug("percentage = %d.\n", percentage);
 
@@ -646,6 +648,8 @@
 		break;
 	case POWER_SUPPLY_PROP_CAPACITY:
 		val->intval = bq28400_read_rsoc(client);
+		if (val->intval < 0)
+			ret = -EINVAL;
 		break;
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		/* Positive current indicates drawing */
diff --git a/drivers/usb/dwc3/dwc3-msm.c b/drivers/usb/dwc3/dwc3-msm.c
index a3abe23..bcacf7a 100644
--- a/drivers/usb/dwc3/dwc3-msm.c
+++ b/drivers/usb/dwc3/dwc3-msm.c
@@ -697,6 +697,7 @@
 		list_del(&req->list);
 		return ret;
 	}
+	dep->flags |= DWC3_EP_BUSY;
 
 	return ret;
 }
@@ -763,14 +764,16 @@
 		return -EPERM;
 	}
 
-	if (dep->free_slot > 0 || dep->busy_slot > 0 ||
-		!list_empty(&dep->request_list) ||
-		!list_empty(&dep->req_queued)) {
 
+	if (dep->busy_slot != dep->free_slot || !list_empty(&dep->request_list)
+					 || !list_empty(&dep->req_queued)) {
 		dev_err(dwc->dev,
 			"%s: trying to queue dbm request %p tp ep %s\n",
 			__func__, request, ep->name);
 		return -EPERM;
+	} else {
+		dep->busy_slot = 0;
+		dep->free_slot = 0;
 	}
 
 	/*
diff --git a/drivers/usb/gadget/f_qdss.c b/drivers/usb/gadget/f_qdss.c
index fd4f352..c3eddcc 100644
--- a/drivers/usb/gadget/f_qdss.c
+++ b/drivers/usb/gadget/f_qdss.c
@@ -460,6 +460,7 @@
 {
 	struct f_qdss	*qdss = func_to_qdss(f);
 	unsigned long flags;
+	int status;
 
 	pr_debug("qdss_disable\n");
 
@@ -467,6 +468,10 @@
 	qdss->usb_connected = 0;
 	spin_unlock_irqrestore(&qdss->lock, flags);
 
+	status = uninit_data(qdss->data);
+	if (status)
+		pr_err("%s: uninit_data error\n", __func__);
+
 	/*cancell all active xfers*/
 	qdss_eps_disable(f);
 
diff --git a/drivers/usb/gadget/u_qdss.c b/drivers/usb/gadget/u_qdss.c
index d227c62..028d5e6 100644
--- a/drivers/usb/gadget/u_qdss.c
+++ b/drivers/usb/gadget/u_qdss.c
@@ -129,7 +129,7 @@
 	if (gadget_is_dwc3(gadget)) {
 		res = msm_ep_unconfig(ep);
 		if (res)
-			pr_err("msm_ep_config failed\n");
+			pr_err("msm_ep_unconfig failed\n");
 	}
 
 	return res;
diff --git a/drivers/video/msm/mdss/mdss_hdmi_hdcp.c b/drivers/video/msm/mdss/mdss_hdmi_hdcp.c
index e361510..2e20787 100644
--- a/drivers/video/msm/mdss/mdss_hdmi_hdcp.c
+++ b/drivers/video/msm/mdss/mdss_hdmi_hdcp.c
@@ -31,11 +31,10 @@
 
 struct hdmi_hdcp_ctrl {
 	enum hdmi_hdcp_state hdcp_state;
-	struct work_struct hdcp_auth_work;
+	struct delayed_work hdcp_auth_work;
 	struct work_struct hdcp_int_work;
 	struct completion r0_checked;
 	struct hdmi_hdcp_init_data init_data;
-	struct timer_list hdcp_timer;
 };
 
 const char *hdcp_state_name(enum hdmi_hdcp_state hdcp_state)
@@ -827,25 +826,6 @@
 	return rc;
 } /* hdmi_hdcp_authentication_part2 */
 
-static void hdmi_hdcp_timer(unsigned long data)
-{
-	struct hdmi_hdcp_ctrl *hdcp_ctrl = (struct hdmi_hdcp_ctrl *)data;
-
-	if (!hdcp_ctrl) {
-		DEV_ERR("%s: invalid input\n", __func__);
-		return;
-	}
-
-	if (HDCP_STATE_AUTHENTICATING == hdcp_ctrl->hdcp_state) {
-		DEV_DBG("%s: %s: Queuing work to start HDCP authentication",
-			__func__, HDCP_STATE_NAME);
-		queue_work(hdcp_ctrl->init_data.workq,
-			&hdcp_ctrl->hdcp_auth_work);
-	} else {
-		DEV_DBG("%s: %s: Invalid state\n", __func__, HDCP_STATE_NAME);
-	}
-} /* hdmi_hdcp_timer */
-
 static void hdmi_hdcp_int_work(struct work_struct *work)
 {
 	struct hdmi_hdcp_ctrl *hdcp_ctrl = container_of(work,
@@ -870,7 +850,8 @@
 static void hdmi_hdcp_auth_work(struct work_struct *work)
 {
 	int rc;
-	struct hdmi_hdcp_ctrl *hdcp_ctrl = container_of(work,
+	struct delayed_work *dw = to_delayed_work(work);
+	struct hdmi_hdcp_ctrl *hdcp_ctrl = container_of(dw,
 		struct hdmi_hdcp_ctrl, hdcp_auth_work);
 
 	if (!hdcp_ctrl) {
@@ -949,7 +930,8 @@
 	mutex_lock(hdcp_ctrl->init_data.mutex);
 	hdcp_ctrl->hdcp_state = HDCP_STATE_AUTHENTICATING;
 	mutex_unlock(hdcp_ctrl->init_data.mutex);
-	queue_work(hdcp_ctrl->init_data.workq, &hdcp_ctrl->hdcp_auth_work);
+	queue_delayed_work(hdcp_ctrl->init_data.workq,
+		&hdcp_ctrl->hdcp_auth_work, 0);
 
 	return 0;
 } /* hdmi_hdcp_authenticate */
@@ -996,12 +978,13 @@
 		HDMI_HPD_CTRL) | BIT(28));
 
 	/* Restart authentication attempt */
-	DEV_DBG("%s: %s: Scheduling timer to start HDCP authentication",
+	DEV_DBG("%s: %s: Scheduling work to start HDCP authentication",
 		__func__, HDCP_STATE_NAME);
 	mutex_lock(hdcp_ctrl->init_data.mutex);
 	hdcp_ctrl->hdcp_state = HDCP_STATE_AUTHENTICATING;
 	mutex_unlock(hdcp_ctrl->init_data.mutex);
-	mod_timer(&hdcp_ctrl->hdcp_timer, jiffies + HZ/2);
+	queue_delayed_work(hdcp_ctrl->init_data.workq,
+		&hdcp_ctrl->hdcp_auth_work, HZ/2);
 
 	return 0;
 } /* hdmi_hdcp_reauthenticate */
@@ -1042,11 +1025,7 @@
 	 * No more reauthentiaction attempts will be scheduled since we
 	 * set the currect state to inactive.
 	 */
-	rc = del_timer_sync(&hdcp_ctrl->hdcp_timer);
-	if (rc)
-		DEV_DBG("%s: %s: Deleted hdcp reauth timer\n", __func__,
-			HDCP_STATE_NAME);
-	rc = cancel_work_sync(&hdcp_ctrl->hdcp_auth_work);
+	rc = cancel_delayed_work_sync(&hdcp_ctrl->hdcp_auth_work);
 	if (rc)
 		DEV_DBG("%s: %s: Deleted hdcp auth work\n", __func__,
 			HDCP_STATE_NAME);
@@ -1138,7 +1117,6 @@
 		return;
 	}
 
-	del_timer_sync(&hdcp_ctrl->hdcp_timer);
 	kfree(hdcp_ctrl);
 } /* hdmi_hdcp_deinit */
 
@@ -1162,14 +1140,9 @@
 
 	hdcp_ctrl->init_data = *init_data;
 
-	INIT_WORK(&hdcp_ctrl->hdcp_auth_work, hdmi_hdcp_auth_work);
+	INIT_DELAYED_WORK(&hdcp_ctrl->hdcp_auth_work, hdmi_hdcp_auth_work);
 	INIT_WORK(&hdcp_ctrl->hdcp_int_work, hdmi_hdcp_int_work);
 
-	init_timer(&hdcp_ctrl->hdcp_timer);
-	hdcp_ctrl->hdcp_timer.function = hdmi_hdcp_timer;
-	hdcp_ctrl->hdcp_timer.data = (u32)hdcp_ctrl;
-	hdcp_ctrl->hdcp_timer.expires = 0xffffffffL;
-
 	hdcp_ctrl->hdcp_state = HDCP_STATE_INACTIVE;
 	init_completion(&hdcp_ctrl->r0_checked);
 	DEV_DBG("%s: HDCP module initialized. HDCP_STATE=%s", __func__,
diff --git a/drivers/video/msm/mdss/mdss_hdmi_tx.c b/drivers/video/msm/mdss/mdss_hdmi_tx.c
index 6cbde02..edc3634 100644
--- a/drivers/video/msm/mdss/mdss_hdmi_tx.c
+++ b/drivers/video/msm/mdss/mdss_hdmi_tx.c
@@ -1185,8 +1185,9 @@
 
 static void hdmi_tx_set_mode(struct hdmi_tx_ctrl *hdmi_ctrl, u32 power_on)
 {
-	u32 reg_val = 0;
 	struct dss_io_data *io = NULL;
+	/* Defaults: Disable block, HDMI mode */
+	u32 reg_val = BIT(1);
 
 	if (!hdmi_ctrl) {
 		DEV_ERR("%s: invalid input\n", __func__);
@@ -1199,25 +1200,17 @@
 	}
 
 	if (power_on) {
-		/* ENABLE */
-		reg_val |= BIT(0); /* Enable the block */
+		/* Enable the block */
+		reg_val |= BIT(0);
+
+		/* HDMI Encryption, if HDCP is enabled */
+		if (hdmi_ctrl->hdcp_feature_on && hdmi_ctrl->present_hdcp)
+			reg_val |= BIT(2);
+
+		/* Set transmission mode to DVI based in EDID info */
 		if (hdmi_edid_get_sink_mode(
-			hdmi_ctrl->feature_data[HDMI_TX_FEAT_EDID]) == 0) {
-			if (hdmi_ctrl->hdcp_feature_on &&
-				hdmi_ctrl->present_hdcp)
-				/* HDMI Encryption */
-				reg_val |= BIT(2);
-			reg_val |= BIT(1);
-		} else {
-			if (hdmi_ctrl->hdcp_feature_on &&
-				hdmi_ctrl->present_hdcp)
-				/* HDMI_Encryption_ON */
-				reg_val |= BIT(1) | BIT(2);
-			else
-				reg_val |= BIT(1);
-		}
-	} else {
-		reg_val = BIT(1);
+			hdmi_ctrl->feature_data[HDMI_TX_FEAT_EDID]) == 0)
+			reg_val &= ~BIT(1); /* DVI mode */
 	}
 
 	DSS_REG_W(io, HDMI_CTRL, reg_val);