[Sony Cross-Device General] munjeni:
I'm close to get it. Curently I found a way how to get diferencie between pc usb source and ac usb source but curently unable to fix isue, this is my atempt:

diff --git a/drivers/usb/dwc3/dwc3-msm.c b/drivers/usb/dwc3/dwc3-msm.c
index 3c3fec6..ff88e5f 100644
--- a/drivers/usb/dwc3/dwc3-msm.c
+++ b/drivers/usb/dwc3/dwc3-msm.c
@@ -1504,6 +1504,8 @@ static void dwc3_chg_enable_primary_det(struct dwc3_msm *mdwc)
dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x30);
}

+static short pc_usb_src = 0;
+
static inline bool dwc3_chg_check_dcd(struct dwc3_msm *mdwc)
{
u32 chg_state;
@@ -1512,6 +1514,9 @@ static inline bool dwc3_chg_check_dcd(struct dwc3_msm *mdwc)
chg_state = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG);
ret = chg_state & 2;

+ printk("DDDD=%u\n", chg_state);
+ pc_usb_src = (chg_state == 2) ? 1 : 0;
+
return ret;
}

@@ -1642,15 +1647,31 @@ get_prop_proprietary_charger(struct dwc3_msm *mdwc)
dp = get_prop_usb_dp_voltage_now(mdwc);
if (IS_ERR_VALUE(dp)) {
dev_err(mdwc->dev, "%s: read D+ voltage fail\n", __func__);
- return dp;
+ //return dp;
}

dm = get_prop_usb_dm_voltage_now(mdwc);
if (IS_ERR_VALUE(dm)) {
dev_err(mdwc->dev, "%s: read D- voltage fail\n", __func__);
- return dm;
+ //return dm;
+ }
+
+ // workaround for msm8974
+ if (IS_ERR_VALUE(dp) && IS_ERR_VALUE(dm)) {
+ if (pc_usb_src)
+ return DWC3_SDP_CHARGER;
+ else {
+ ret = DWC3_INVALID_CHARGER;
+ goto workornd;
+ }
}

+ if (IS_ERR_VALUE(dp))
+ return dp;
+
+ if (IS_ERR_VALUE(dm))
+ return dm;
+
ret = DWC3_INVALID_CHARGER;
for (i = 0; i < (sizeof(chgs) / sizeof(chgs[0])); i++) {
if (IN_RANGE(dp, chgs[i].dp.hi, chgs[i].dp.lo) &&
@@ -1662,6 +1683,7 @@ get_prop_proprietary_charger(struct dwc3_msm *mdwc)
}
}

+workornd:
if (ret == DWC3_INVALID_CHARGER) {
dev_warn(mdwc->dev, "%s: voltage not in range, D+=%d, D-=%d\n",
__func__, dp, dm);
@@ -1691,6 +1713,7 @@ static void dwc3_chg_detect_work(struct work_struct *w)
break;
case USB_CHG_STATE_WAIT_FOR_DCD:
is_dcd = dwc3_chg_check_dcd(mdwc);
+ printk("PC USBSOURCE=%d\n", pc_usb_src);
tmout = ++mdwc->dcd_retries == DWC3_CHG_DCD_MAX_RETRIES;
if (is_dcd || tmout) {
#ifdef CONFIG_SONY_USB_EXTENSIONS
@@ -1727,6 +1750,7 @@ static void dwc3_chg_detect_work(struct work_struct *w)
break;
case USB_CHG_STATE_DCD_DONE:
vout = dwc3_chg_det_check_output(mdwc);
+
if (vout) {
dwc3_chg_enable_secondary_det(mdwc);
delay = DWC3_CHG_SECONDARY_DET_TIME;
@@ -1751,6 +1775,7 @@ static void dwc3_chg_detect_work(struct work_struct *w)
break;
case USB_CHG_STATE_PRIMARY_DONE:
vout = dwc3_chg_det_check_output(mdwc);
+
if (vout)
mdwc->charger.chg_type = DWC3_DCP_CHARGER;
else
@@ -1771,10 +1796,11 @@ static void dwc3_chg_detect_work(struct work_struct *w)
mdwc->ext_chg_active = true;
}
}
- dev_dbg(mdwc->dev, "chg_type = %s\n",
+ printk("chg_type = %s\n",
chg_to_string(mdwc->charger.chg_type));
mdwc->charger.notify_detection_complete(mdwc->otg_xceiv->otg,
&mdwc->charger);
+ return;
default:
pm_runtime_put_sync(mdwc->dev);
return;
@@ -2756,7 +2782,7 @@ static int dwc3_msm_power_set_property_usb(struct power_supply *psy,
if (mdwc->charger.chg_type != DWC3_INVALID_CHARGER)
mdwc->chg_state = USB_CHG_STATE_DETECTED;

- dev_dbg(mdwc->dev, "%s: charger type: %s\n", __func__,
+ printk("%s: charger type: %s\n", __func__,
chg_to_string(mdwc->charger.chg_type));
break;
case POWER_SUPPLY_PROP_HEALTH:
r

hope somebody find a proper workaround.