usb: dwc3-msm: Update USB power supply's 'type' property

USB power supply type represents type of charger connected e.g.
standard host PC i.e. USB, or wall-charger i.e. USB_DCP. Userspace
code might be interested in distinguishing between standard host PC
and DCP chargers. Hence, update the type accordingly whenever power
supply's type changes.

CRs-Fixed: 458183
Change-Id: I6045d020394eb4baba17244bf9c9d5be7bbb1de6
Signed-off-by: Manu Gautam <mgautam@codeaurora.org>
USB: dwc3-msm: Implement VOLTAGE_NOW property for usb power supply

Implement VOLTAGE_NOW property for power supply so that usb_in
value can be read at any time through this sysfs entry by
userspace.

To read usb_in value,
	cat /sys/class/power_supply/usb/voltage_now

CRs-Fixed: 599547
Change-Id: I106ce9219c7a04c2b7436221732a6fca0cc85245
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3: Fix compilation error when debugfs is disabled

The code does not compile with debugfs disabled. Fix this.

Change-Id: I19b784495b57e7fc0c57b455dd80a63b79177569
Signed-off-by: Olav Haugan <ohaugan@codeaurora.org>
USB: dwc3: debugfs: Enable logging of control endpoint events by default

Enable logging of EP0 control events, which will be useful for analyzing
the USB issues like crash. Also add more required events wherever required.

Change-Id: I0fd3edfa2cd8711928cd480e99abbf8e6f907774
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3-msm: Enable async irq wakeup capability only if required

If driver is depending on PMIC for VBUS and ID events, then async
interrupt is not required to set wakeup capable during cable
disconnect or when dcp is connected. Otherwise this interrupt can be
fired before PMIC notification during system suspend and could mess up
run time pm counters. Hence enable async irq wakeup capability
during bus suspend and disable it during device resume.

CRs-Fixed: 634833
Change-Id: Ifea0150ee947823ba4f8183af911e150fde61f1f
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3: msm: Fix bug during STM enable/disable for QDSS

commit "I0fdc5d703b3fd445e83226534f07743461c96f4c:usb: dwc3-msm:
remove use of global context variable (DBM)" is required for adding
support multiple instances in dwc3-msm driver. This added an incorrect
condition check in the driver before reinitiating USB reconnection
for STM enable/disable. Due to this, QDSS doesn't work when STM tracing
is disabled and enabled. Hence Fix this issue by using proper check.

CRs-Fixed: 523344
Change-Id: I6302396c7bf03cd2313e5d571e0aef51648a2258
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3_msm: Disable all events before error recovery for Erratic event

Currently as part of Erratic event handling, dumping all relevant registers
and then scheduling work for block reset. This does lead to erratic event
getting fired continuously and might result in watchdog crash. Hence
disable all events in DEVTEN regiser before doing block reset and reenable
the events once block reset is completed.

Change-Id: Ib2644ea8471cb87792a9524dc5103b61b2d0a74c
Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3-msm: Fix USB connection issue after DCP charger disconnection

Commit "6e3630b5f28c60c403af8c6b3c87679d3d98d6af: usb: dwc3-msm: Support
external charging detection " has added check not to start charger
detection in case charger detection is done by external circuit. when otg
driver calls charger_detection API to set charger type to invalid as part
of VBUS disconnect handling, this check prevents to do that. This results
next charger detection not happening after DCP charger disconnection.
Hence fix the issue by moving down the check in the charger_detection API.

Change-Id: I5c614a208f22e4cd9f334c80dae6831bcff64ada
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
USB: dwc3: gadget: Add support for sending zero length packets

Currently driver is not honouring req->zero flag even though
function driver sets this flag. If device has to send IN data back
to host and length is multiple of endpoint maximum packet size, it
should send additional zero length packet at the end to terminate
transfer.

CRs-Fixed: 592504
Change-Id: I5a8aecc504098ed386a9a9d19f4f5b78c911a376
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
usb: gadget: Fix synchronization issue between f_audio_source

Race is happening when both audio_pcm_close() and audio_send()
executes in parallel.
When the PCM session is closed, the substream attribute of the
audio_dev structure is set to NULL in audio_pcm_close().
As there is no synchronization protection for the audio_dev subtream
attributes in audio_send(), it is causing NULL pointer dereference.
Hence fixing the issue by adding proper synchronization protection
for the audio_dev subtream attributes in audio_send().

CRs-Fixed: 613498
Change-Id: Id9ab0d4e347b8bb2f551f9033829e541bdcaf0e8
Signed-off-by: ChandanaKishori Chiluveru <cchilu@codeaurora.org>
USB: gadget: f_mtp: Fix bug in receive_file work

If cable is disconnected while receive_file work is in progress,
there is a case where mtp driver returns -ECANCELLED instead of
-EIO. This results in mtp server thread not getting disconnect
notification and mtp release will not be called. Due to this, mtp
server will not start mtp connection after next USB connection.

CRs-Fixed: 590055
Change-Id: I909bebe0d22c19329cebb0a4a76424e08c82328c
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>