Commit Graph

839614 Commits

Author SHA1 Message Date
Finley Xiao
4a67123cc7 clk: rockchip: rk3228: Fix sclk_wifi div_width
Change-Id: I8e216249fbd588ce55660eba9911fc59aedc920d
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:20:36 +08:00
Liang Chen
0a3b4eb464 clk: rockchip: Add adaptive frequency scaling for pll_rk3036
Change-Id: Ifd035967afc1852df81daa2b15afea764c5b851d
Signed-off-by: Liang Chen <cl@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:20:11 +08:00
Finley Xiao
b8daed0133 clk: rockchip: Fix cpu frequency overflowing
If change parent to alternate parent and the old parent clock speed is less
than the clock speed of the alternate parent, add dividers first and then
select alternate parent.

If change parent to primary parent, select primary parent first and then
remove dividers.

Change-Id: Ib82de9a936effe5c885639799f3bb5629dc89f8d
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:15:36 +08:00
Finley Xiao
aa8173513c clk: rockchip: rk3328: Fix clk_cif_src parent
Change-Id: I0ea209224880b8c51a385ed46827bb0d8f7dd219
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:15:12 +08:00
Finley Xiao
488ffe507e clk: rockchip: px30: fix gpu clk
Remove clk_gpu_divnp5.
Fix gpu frequency overflowing.

Change-Id: I67f47f5fdd7873c22b1349e3aeb80b7157c7844c
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:15:03 +08:00
Finley Xiao
1497e5c949 clk: rockchip: rk3288: Add TSP clock
Change-Id: I02185c5ab7a1072d271cd51161f6d4b05d327673
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:14:08 +08:00
Finley Xiao
eff5ccdefb clk: rockchip: rk3128: Add sclk_hsadc_tsp
Change-Id: I842869a7ea79730daa6616f1cf2a8f5db7165ceb
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:14:00 +08:00
Finley Xiao
7293bb6e68 clk: rockchip: rk3328: Fix aclk_gmac select register
Change-Id: Ie800d876644f1a7abac3f7d7f8352ba405a9537a
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:13:52 +08:00
Xinhuang Li
0f3337613e clk: rockchip: rk3328: the group of softrst is 12
Change-Id: Idec7baa6bb0bb5824270e9cd8f3c6ed38d47ecc1
Signed-off-by: Xinhuang Li <buluess.li@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:12:54 +08:00
Rocky Hao
25ddf5bcd3 thermal: rockchip: add tsadc support for rk3308
Change-Id: Ibf1782ca471c8ad4b14d6fd64eeb123181903adc
Signed-off-by: Rocky Hao <rocky.hao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:07:11 +08:00
Rocky Hao
b7372154d4 thermal: rockchip: add shutdown callback function
Tsadc has a tshut pin which is designed to reset the pmic or soc,
when the temperature inside soc is too high. we should switch off
the tshut function and change the pin to gpio function in reboot
process, eg, software reset. If not, the tsadc module will WRONGLY
pull high the tshut pin during its reset process and then WRONGLY
reset the pmic or soc, which incurred a hardware reset. The hardware
reset will reset everything inside soc, even includes the power on
reason flag, which is set by software before reboot process.

we also change over-temperature protection mode to cru mode,
since the tshut pin have be changed to gpio function.

Change-Id: Iac3dacf55a4b5536fccd2eb05a6a9e6923a082c0
Signed-off-by: Rocky Hao <rocky.hao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:07:10 +08:00
Rocky Hao
265e89a8bf thermal: rockchip: add tsadc support for px30
Change-Id: I46ac8ebd4a92367acb610fb96c18a487c67602d4
Signed-off-by: Rocky Hao <rocky.hao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:07:10 +08:00
Finley Xiao
148e9ae288 soc: rockchip: power-domain: Fix restore error qos value
Change-Id: I74692018652ed2aa45b666f1598662146beec92e
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:02:37 +08:00
Finley Xiao
743525f3c9 soc: rockchip: power-domain: Add support to ignore on/off
Change-Id: I96c3ae8ae53b9ae95f6f896363b761798a534821
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:01:06 +08:00
Finley Xiao
ce842d4e62 soc: rockchip: power-domain: export qos save and restore
Change-Id: I89af4462f561fa06ace7761e20cf522b5954aaed
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
Signed-off-by: Elaine Zhang <zhangqing@rock-chips.com>
2019-03-12 20:00:49 +08:00
Frank Wang
9f2fb93354 phy: rockchip-inno-usb2: add wake_lock function
Prevent the system from entering suspend when usb cable is connecetd.

Change-Id: I50c4a09d9142ebeb2d4e2a0ab2df59f98ef99737
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
153538b270 phy: rockchip-inno-usb2: add bypass uart cfgs for rk1808
This patch adds bypass uart cfgs for rk1808 USB 3.0 OTG
port. In addition, please note that it needs to set the
uart2 rx/tx io selection in the reg "BUS_GRF_IOFUNC_CON0"
bit 15:14.

Change-Id: I77ea461be299c0454f5caee1349110b6f2714c30
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
3e79e9c0c4 phy: rockchip-inno-usb2: add phy configurations for rk1808
RK1808 SoC has an usb 2.0 comb phy with one otg-port and one
host-port. This patch adds port configurations for them.

Change-Id: Id4d117929ec0e327c8f2cc1a06d4caaa2d584f06
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
2d19e6806b phy: rockchip-inno-usb2: register 480MHz clk at the end of probe
We find an usb phy 480MHz clk prepare fail issue on PX30/RK3326
platforms with RK819 PMIC. On PX30/RK3326 platforms, we set the
usb480m clk to critical because GPU 480M is from usb480m and the
source clocks should be always on. And the usb phy 480MHz clk is
parent of usb480m clk, so the clk framework will prepare the usb
phy 480MHz clk when register it.

This logic works well if the usb phy probe only once. But if the
usb phy needs to probe twice or more because of some reasons (e.g.
fail to get vbus regulator from RK819), the usb phy 480MHz clk will
be unregistered and registered again, however, the clk framework
doesn't prepare the usb phy 480MHz clk except the first time register
operation. So we move the 480MHz clk register to the end of probe,
and make sure only register it once.

Change-Id: If69378b49035746a7c0107c6a363c4d91dfc15e5
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Bin Yang <yangbin@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
42ee2ffcde phy: rockchip: rockchip-inno-usb2: and otg cfg for rk3368
This patch adds rk3368 otg-port phy configurations.
But actually, we don't use the otg phy configurations
for the time being, because we use dwc_otg_310 driver
for rk3368 otg controller, and this driver doesn't use
generic phy. This patch is useful if we switch to dwc2
driver for rk3368 otg in the feature.

Change-Id: Ibed3fde4ef64ad25e933ac4560f956b7c9f5c476
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
f7a26c41a7 phy: rockchip: rockchip-inno-usb2: check iddig upon resume
Because USB OTG id irq is disabled during system suspend
and enabled after resume, so the usb2 phy doesn't notice
any id status change upon resume. It may cause two issues:

1. Plug in OTG cable and USB device when system enter
   suspend, it will fail to detect the OTG cable and
   USB device after resume.

2. Plug out OTG cable and USB device when system enter
   suspend, and then connect USB to PC or USB charger
   after resume, it will fail to detect USB charge type.

This patch restores the OTG id status before enter suspend,
and check the id status upon resume, and set the extcon
state and vbus if id status has changed.

Change-Id: Iaca14841cc287e7d82e1cffd64ff18bba86d3ba4
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
9eb67154eb phy: rockchip: rockchip-inno-usb2: flush otg work when exit
The controller will be reinit when suspend and resume in device
mode if not connect to PC. And the U2PHY must be keep in power
on state during the init process. But The 'otg_sm_work' may be
schedule immediately and power off the U2PHY if system suspend
and resume between the delay time of schedule 'otg_sm_work', so
it will result in the error when init controller as below:

dwc2_core_reset() HANG! Soft Reset GRSTCTL=80000001

So flush the otg work in exit function to finish power control
of U2PHY.

Change-Id: I79c4b6a877196abd2f2201b2f984c9ea22e48fec
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
009901098a phy: rockchip-inno-usb2: fix comparison warnings
This patches fixes comparison between signed and unsigned values.

Change-Id: Ie417fdb8092463890a67bce7efa11f3ef20d5871
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
5319b2a3bb phy: rockchip-inno-usb2: fix a clang warning
This patch fix the following clang warning:
[clang]drivers/phy/rockchip/phy-rockchip-inno-usb2.c:1255:3:
warning: Value stored to 'delay' is never read

Change-Id: I8c70975e1bc2b24a78d0934ccefc9d67fe3a5da9
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
86e7f9572c phy: rockchip-inno-usb2: reduce the otg schedule delay time
Reduce the otg schedule delay time from 6s to 1s to do
the first time usb charger detection earlier when power
on system with usb cable connect to PC USB. Because the
usb connection willed be disconnectted during usb charger
detection.

And the patch also makes the phy detect the usb disconnetion
more quickly after usb cable plug out.

Change-Id: I9b55317ab3592f517fdf590fea85c4ed403bbd8d
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
a96c31bfe6 phy: rockchip-inno-usb2: open pre-emphasize for rk3228
Open pre-emphasize in non-chirp state for rk3228 USB
PHY0 otg port to increase HS slew rate.

Change-Id: Ia565746286a750a251619a83cbbead99c0ddecbd
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
6bf52fb9a6 phy: rockchip-inno-usb2: make u2phy enter low power mode
Make u2phy enter low power mode when suspend. If config the DT of
u2phy port with "rockchip,low-power-mode" property, the port will
be config to lower power state when suspend.

Bvalid irq and linestate irq will be disabled in this mode.

Change-Id: Ie7d40a9a181b0622b1f8d062a741661548cabd59
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
2f6076d7bf Documentation: bindings: add rockchip,low-power-mode property for u2phy
Change-Id: Id99aeb68aa5b6174a3a97f413f09270d893cef4e
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
e4fe585d6b phy: rockchip-inno-usb2: open pre-emphasize for rk3308/rk3328
Open pre-emphasize in non-chirp state for rk3308 and
rk3328 usb otg and host ports to increase HS slew rate.

Change-Id: I16435d67b9994cef0fd5e6edbae00c41cc02c48b
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Frank Wang
0f997af5aa phy: rockchip-inno-usb2: add usb-phy support for rk3308
This change adds usb-phy support for rk3308 SoC and amend related
phy Documentation.

Change-Id: I953af94fb4d55d79ae1cba624a04fb4b84e019f6
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Frank Wang
ca9f99df15 phy: rockchip-inno-usb2: add rk3328 tuning support
Due to usb-phy tuning framework is not added in UPSTREAM codes, so
rk3328 tuning is striped in mainline, this commit make a supplement.

Change-Id: Id8103d65951515b9b21baab14f7125420cea78eb
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
f964e1bae5 phy: rockchip-inno-usb2: use fixed-regulator for vbus power
This patch uses a fixed-regulator instead of GPIO pin for
usb vbus power. It doesn't fix any issue, but it makes more
sense to convert the GPIO code into a fixed-regulator.

Change-Id: I7196a9cd592dbb3fab3ef8b9e99babc613a42869
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
5401b4f956 phy: rockchip: rockchip-inno-usb2: tuning pre-emphasize for rk3399
In current code, the pre-emphasize in eop state and chirp state are
disabled only if we add “rockchip,u2phy-tuning” property in RK3399 dts,
But we find that if we enable the pre-emphasize of sop/eop/chirp state
for rk3399 by default, it will cause usb2 compliance test item - EL_8
and EL_9 failure, so disable the pre-emphasize of sop/eop/chirp state
by default. And this can also help to avoid mis-trigger the disconnect
detection or high-speed handshake failure.

Change-Id: I5ceac9c88de4cdae5af904e973124c194f7718f6
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
364682a772 phy: rockchip-inno-usb2: don't power off phy if connect to usb charger
The usb2 phy driver will power off phy if it detects
usb connecting with usb charger. And then it schedule
a delayed work to check the connection state until the
usb disconnect from usb charger.

On rockchip platform, the usb2 controller utmi clk and
480MHz clk come from usb2 phy, so if we power off the
usb2 phy, the usb2 controller should not be accessed.

However, it's difficult to synchronize the phy state
between the usb2 phy driver and usb2 controller. We
find one synchronization problem in the following
case:

1. Test on rk312x platform;
2. Connect otg port with usb charger, then do suspend/
   resume stress test.
3. We will find the following error log, and then the
   usb controller work abnormally.

   dwc2 10180000.usb: resuming usb gadget configfs-gadget
   dwc2 10180000.usb: dwc2_core_reset() HANG! Soft Reset GRSTCTL=80000001

This because in dwc2 driver, it will do dwc2 core reset
during resume, although it also power on usb2 phy before
do core reset, but the otg_sm_work in the usb2 phy driver
may power off the usb2 phy again asynchronously, this will
cause dwc2 core reset failure.

So we should not power off the usb2 phy if connect to
usb charger, this patch will increase the usb2 phy power
consumption in runtime, but it don't affect the power
consumption in system standby mode, because the usb
controller can power off phy by itself during suspend.

Change-Id: I3b05c06988b7939ebf949ced34b9a6bb37ffa42a
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
4bffa7c5ea phy: rockchip-inno-usb2: turn off differential receiver in suspend mode
Turn off differential receiver in suspend mode to save power

Change-Id: Idd9b4c2d7d9d78915c94946ced99737683a2ce91
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
864f960310 phy: rockchip-inno-usb2: reinit charge state when usb disconnect
When detect the usb peripheral disconnect from PC usb
host port or usb charger, we need to reinit the charge
state immediately, then it can do usb battery charge
detect work to get correct charge type if usb re-plug
in again in a short time.

Change-Id: I187f1d23a11b00f57e0a3699b6174cd7a59be3f1
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Wu Liang feng
9301172324 phy: rockchip-inno-usb2: support usb bypass uart function
Most of rockchip SoCs USB 2.0 DP/DM can be bypassed to UART,
it's useful for those platforms without UART interface to
print log via USB interface.

For the time being, we just support for rk312x and rk3399 in
this driver. And we will support for more SoCs in the feature.

With this patch, the user still can't use this bypass function.
It needs to add the property "rockchip,bypass-uart" in the DT
as following:

u2phy0_otg: otg-port {
	...
	rockchip,bypass-uart;
	...
};

And it also needs a special USB cable integrated with an USB
to UART chip.

Note: this function can only be used in debug stage.

Change-Id: Icdab516ff7b327f4a98c3b24bbaf953a605f5278
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
9f42e95372 phy: rockchip-inno-usb2: add support for rk3128
The rk312x use different config data which incluce control
register address and value. The patch add config data of
rk312x and match table to support rk3128.

Change-Id: Idd9a5c885cf5e291517e56232e77066eb5d97138
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Wu Liang feng
d789eb7a26 phy: rockchip-inno-usb2: avoid calling sleeping func from invalid context
Commit 4f519feed0 ("phy: rockchip-inno-usb2: delay suspending
phy if plug out device"), introduced the following issue:

BUG: sleeping function called from invalid context at kernel/workqueue.c:2717
in_atomic(): 1, irqs_disabled(): 128, pid: 4, name: kworker/0:0
INFO: lockdep is turned off.
irq event stamp: 19674
hardirqs last  enabled at (19673): [<ffffff8008cd8818>] _raw_spin_unlock_irqrestore+0x40/0x70
hardirqs last disabled at (19674): [<ffffff8008cd8690>] _raw_spin_lock_irq+0x1c/0x60
softirqs last  enabled at (19664): [<ffffff80088dd1c0>] dw_mci_request+0xe0/0xf0
softirqs last disabled at (19660): [<ffffff80088dd140>] dw_mci_request+0x60/0xf0
CPU: 0 PID: 4 Comm: kworker/0:0 Not tainted 4.4.83 #69
Hardware name: Rockchip RK3399 Evaluation Board v3 (Android) (DT)
Workqueue: fusb302_wq fusb302_work_func
Call trace:
[<ffffff8008089f78>] dump_backtrace+0x0/0x1cc
[<ffffff800808a158>] show_stack+0x14/0x1c
[<ffffff80083ca33c>] dump_stack+0xb8/0xf4
[<ffffff80080cec40>] ___might_sleep+0x1b8/0x1c8
[<ffffff80080cecc0>] __might_sleep+0x70/0x80
[<ffffff80080becbc>] flush_work+0x74/0x270
[<ffffff80080bf09c>] __cancel_work_timer+0x12c/0x1bc
[<ffffff80080bf154>] cancel_delayed_work_sync+0x10/0x18
[<ffffff80083f9de8>] rockchip_otg_event+0x18/0x3c
[<ffffff80080c6380>] notifier_call_chain+0x54/0x88
[<ffffff80080c63dc>] raw_notifier_call_chain+0x14/0x1c
[<ffffff80089a5354>] extcon_sync+0x74/0x1c4
[<ffffff80085ab980>] platform_fusb_notify+0x184/0x204
[<ffffff80085ac4ac>] set_state_unattached+0x5c/0x90
[<ffffff80085ac85c>] fusb302_work_func+0x288/0x1904
[<ffffff80080bdfa4>] process_one_work+0x354/0x6d0
[<ffffff80080bf4a4>] worker_thread+0x2f8/0x414
[<ffffff80080c4e58>] kthread+0xf0/0xf8
[<ffffff80080828d0>] ret_from_fork+0x10/0x40

Actually, we don't need to cancel the otg_sm_work in the
event EXTCON_USB_HOST notifier_call. So just remove the
cancel_delayed_work_sync() in the rockchip_otg_event().

With this patch, we may get USB BC1.2 detection error
if plug in USB peripheral/host cable alternately and
quickly. So we need to reinit chg_state and chg_type
if OTG host cable plug in.

Change-Id: I349d59de3188d39707c527acb858a7be20a999ac
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Wu Liang feng
22d16bc7dc phy: rockchip-inno-usb2: support usb BC1.2 for rk3399 Type-C1
rk3399 Type-C1 USB 2.0 PHY supports USB BC1.2. This patch
adds registers configuration for Type-C1 USB BC1.2.

With this patch, and set dr_mode of Type-C1 USB to "otg" or
"peripheral" in the DTS, then the Type-C1 USB can detect USB
battery charger.

Change-Id: I2f07ae675cc6066db46e428e6e27045b911a0773
Signed-off-by: Wu Liang feng <wulf@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Frank Wang
e27d6a91e2 phy: rockchip-inno-usb2: put phy-port into suspend during probe
Let us put phy-port into suspend mode at initialization time for
saving power consumption, and usb controller will resume it during
probe time if needed.

Change-Id: Id3a66af8ff17612d54fbc80db087bf67eaee7726
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
7a2fe3e532 phy: rockchip-inno-usb2: delay suspending phy if plug out device
The otg_sm_work will suspend the usb2 phy immediately
if it detects disconnection from host. However, the usb2
controller(e.g. DWC2) may need to reinit registers and
reset usb core after usb disconnect, and it needs to
keep the usb2 phy stay in power on state to get utmi clk
for these usb controller operation. We don't have a good
synchronization mechanism to operate usb2 phy between
usb2 phy driver and usb2 controller driver, so we delay
4s to suspend phy if detect otg device disconnect from
host, this can make sure that usb2 controller completes
reinitialization before suspend usb2 phy.

Change-Id: I79288b8c7b141bb16e6d96d80cfee75f7558d2c0
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
6b032113c0 phy: rockchip-inno-usb2: disable id irq in pm suspend
The otg id voltage is provided from usb2 phy power. On some
rockchip platforms (e.g. rk3399), the usb2 phy power will be
turned off when enter pm suspend, this will trigger id fall
interrupt. But current code enable the ID interrupt consistently,
it may result in the mistake of ID changing operation even if
the state of ID pin is not changed. So disable ID irq when
suspend and enable when resume.

Change-Id: Icac35f13861fd639e4b422b31182a68add73836d
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
1f23071540 phy: rockchip-inno-usb2: support to force otg mode
This patch creates an usb2 phy attribute group and
provides an attribute "otg_mode" for otg port to
force otg mode independently of the voltage of otg
id pin.

In order to implement the force mode function, we can
select otg plug indicator output (AKA iddig) from GRF,
and set GRF USB otg plug indicator to "0" or "1" to
control iddig status.

We only support rk322x/rk3328 to force otg mode for
the time being.

And we need to disable usb auto suspend function if
we want to force otg mode. Add 'usbcore.autosuspend=-1'
in cmdline to disable usb auto suspend.

Usage:
[1] Force host mode
    echo host > /sys/devices/platform/<u2phy dev name>/mode

[2] Force peripheral mode
    echo peripheral > /sys/devices/platform/<u2phy dev name>/mode

[3] Force otg mode
    echo otg > /sys/devices/platform/<u2phy dev name>/mode

Legacy Usage:
[1] Force host mode
    echo 1 > /sys/devices/platform/<u2phy dev name>/mode

[2] Force peripheral mode
    echo 2 > /sys/devices/platform/<u2phy dev name>/mode

[3] Force otg mode
    echo 0 > /sys/devices/platform/<u2phy dev name>/mode

Change-Id: I875b60b0390e3bd9af34b740cba8f5d53e1df752
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
9e25727165 phy: rockchip-inno-usb2: fix possibe deadlock
The commit 611ec35fa1 ("phy: rockchip-inno-usb2: fix some
race conditions") use mutex lock to protect charger detect
work, but it will cause the following possible deadlock.

[ INFO: possible circular locking dependency detected ]
4.4.66 #563 Not tainted
-------------------------------------------------------
kworker/3:1/145 is trying to acquire lock:
(&rport->mutex){+.+...}, at: [<ffffff80083f286c>] rockchip_chg_detect_work+0x6c/0x3d0

but task is already holding lock:
((&(&rport->chg_work)->work)){+.+...}, at: [<ffffff80080be6e4>] process_one_work+0x1c4/0x6ac

which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:

-> #1 ((&(&rport->chg_work)->work)){+.+...}:
[<ffffff80080fda40>] __lock_acquire+0x15c0/0x195c
[<ffffff80080fe5e8>] lock_acquire+0x190/0x250
[<ffffff80080bf534>] flush_work+0x4c/0x274
[<ffffff80080bf944>] __cancel_work_timer+0x130/0x1c0
[<ffffff80080bf9fc>] cancel_delayed_work_sync+0x10/0x18
[<ffffff80083f17a8>] rockchip_usb2phy_exit+0x54/0x6c
[<ffffff80083f07ac>] phy_exit+0x64/0xb4
[<ffffff8008772810>] dwc3_core_exit+0x44/0x98
[<ffffff80087728b0>] dwc3_suspend_common+0x4c/0x5c
[<ffffff8008772a68>] dwc3_runtime_suspend+0x38/0x5c
[<ffffff8008571784>] pm_generic_runtime_suspend+0x28/0x38
[<ffffff8008573464>] __rpm_callback+0x40/0x74
[<ffffff80085734f4>] rpm_callback+0x5c/0x80
[<ffffff8008573bc4>] rpm_suspend+0x31c/0x688
[<ffffff80085751ec>] __pm_runtime_suspend+0x58/0xa4
[<ffffff800877efc0>] dwc3_rockchip_probe+0x3f8/0x574
[<ffffff800856bcd0>] platform_drv_probe+0x58/0xa4
[<ffffff8008569bb0>] driver_probe_device+0x118/0x2b0
[<ffffff8008569e9c>] __device_attach_driver+0x88/0x98
[<ffffff8008567f4c>] bus_for_each_drv+0x7c/0xac
[<ffffff80085699e4>] __device_attach+0xa8/0x128
[<ffffff800856a00c>] device_initial_probe+0x10/0x18
[<ffffff8008569000>] bus_probe_device+0x2c/0x90
[<ffffff800856948c>] deferred_probe_work_func+0x78/0xa8
[<ffffff80080be858>] process_one_work+0x338/0x6ac
[<ffffff80080bfd54>] worker_thread+0x300/0x428
[<ffffff80080c5758>] kthread+0x104/0x10c
[<ffffff8008083080>] ret_from_fork+0x10/0x50

-> #0 (&rport->mutex){+.+...}:
[<ffffff80080faacc>] print_circular_bug+0x64/0x2c4
[<ffffff80080fd70c>] __lock_acquire+0x128c/0x195c
[<ffffff80080fe5e8>] lock_acquire+0x190/0x250
[<ffffff8008c67ac0>] mutex_lock_nested+0x80/0x3d0
[<ffffff80083f286c>] rockchip_chg_detect_work+0x6c/0x3d0
[<ffffff80080be858>] process_one_work+0x338/0x6ac
[<ffffff80080bfd54>] worker_thread+0x300/0x428
[<ffffff80080c5758>] kthread+0x104/0x10c
[<ffffff8008083080>] ret_from_fork+0x10/0x50

other info that might help us debug this:

Possible unsafe locking scenario:

        CPU0                    CPU1
        ----                    ----
   lock((&(&rport->chg_work)->work));
                                lock(&rport->mutex);
                                lock((&(&rport->chg_work)->work));
   lock(&rport->mutex);

  *** DEADLOCK ***

2 locks held by kworker/3:1/145:

stack backtrace:
CPU: 3 PID: 145 Comm: kworker/3:1 Not tainted 4.4.66 #563
Hardware name: Rockchip RK3399 Evaluation Board v3 (Android) (DT)
Workqueue: events rockchip_chg_detect_work
Call trace:
[<ffffff800808a814>] dump_backtrace+0x0/0x1c8
[<ffffff800808a9f0>] show_stack+0x14/0x1c
[<ffffff80083c1fa0>] dump_stack+0xb0/0xec
[<ffffff80080fad10>] print_circular_bug+0x2a8/0x2c4
[<ffffff80080fd70c>] __lock_acquire+0x128c/0x195c
[<ffffff80080fe5e8>] lock_acquire+0x190/0x250
[<ffffff8008c67ac0>] mutex_lock_nested+0x80/0x3d0
[<ffffff80083f286c>] rockchip_chg_detect_work+0x6c/0x3d0
[<ffffff80080be858>] process_one_work+0x338/0x6ac
[<ffffff80080bfd54>] worker_thread+0x300/0x428
[<ffffff80080c5758>] kthread+0x104/0x10c
[<ffffff8008083080>] ret_from_fork+0x10/0x50

Change-Id: I4289afb05d334bf79000090f9071cf428817a583
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
a35a09d34f phy: rockchip-inno-usb2: fix some race conditions
There are some race conditions related to phy power on/off
and otg charger detection work, otg sm work. I can find at
least three race conditions at present.

Race condition[1]:
The first race condition involving phy power on/off which
may be caused by the following case.

Test on rk3399 evaluation board Type-C0, connect to PC usb
port with Type-C cable, then phy power on/off operation may
be done twice because of race condition between phy driver
and usb controller driver.

CPU 0:
- rockchip_usb2phy_bvalid_irq()
 - rockchip_usb2phy_otg_sm_work()
  - detect connect to PC usb, do phy power on
   - rockchip_usb2phy_power_on()

CPU 1:
- dwc3 driver do runtime resume process
 - dwc3_runtime_resume()
  - dwc3_core_init()
   - phy_power_on()
    - rockchip_usb2phy_power_on()

Although we use a suspended flag in rockchip_usb2phy_power_on()
to avoid doing the same things twice, but it's not enough to
prevent race condition if phy driver and usb controller driver
access the rockchip_usb2phy_power_on() at the same time. This
race condition may cause clk management unbalanced.

Race condition[2]:
The second race condition related to phy power on/off and otg
charger detection work. We need to keep the usb phy staying in
suspend mode when do usb charger detection. But now it don't
have any protection to prevent the other threads to operate phy
during charger detection.

The problem can also be easily reproduced on rk3399 evaluation
board Type-C0 when connect to PC usb port with Type-C cable.

CPU 0:
- rockchip_chg_detect_work()
 - power off phy and start to do charge detection work

CPU 1:
- dwc3 driver do runtime resume process
 - dwc3_runtime_resume()
  - dwc3_core_init()
   - phy_power_on()
    - power on phy again

This race condition may cause charger detection and later usb
enumeration abnormally.

Race condition[3]:
The third race condition involving otg sm work. The otg sm
work can be interrupted by bvalid irq, and the bvalid irq
handler rockchip_usb2phy_bvalid_irq() will do otg sm work,
which may cause unknown error.

This patch uses mutex lock to protect the phy operations,
otg charger detection work and otg sm work.

Change-Id: Ic6845a10b3e69fe9ae6cf0b2d4e2beb098232abd
Signed-off-by: William Wu <william.wu@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
d20889635f phy: rockchip-inno-usb2: tuning USB 2.0 PHY when resume
The USB 2.0 PHY may lose tuning config after resume if the
PD turn off its power when suspend. So we need to tune USB
2.0 PHY again when resume.

Change-Id: Ib34de165ccd7d22598e77e5ac0fed1233e7adba0
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Meng Dongyang
bf64cf1222 phy: rockchip-inno-usb2: tuning USB 2.0 squelch detection threshold
According to USB 2.0 Spec Table 7-7, the High-speed squelch
detection threshold Min 100mV and Max 150mV, and we set USB
2.0 PHY0 and PHY1 squelch detection threshold to 150mV by
default, so if the amplitude of differential voltage envelope
is < 150 mV, the USB 2.0 PHYs envelope detector will indicate
it as squelch.

On RK3399 box, if we connect usb device with a 4 meter cable,
we can see that the impedance of U2 cable is too big according
to the eye-diagram test report, and this cause serious signal
attenuation at the end of receiver, the amplitude of differential
voltage falls below 150mV.

This patch aims to reduce the PHY0 and PHY1 otg-ports squelch
detection threshold to 125mV (host-ports still use 150mV by
default), this is helpful to increase USB 2.0 PHY compatibility.

Change-Id: Iec8b4043a3440d6f2a5fb18ff59ac0f4988019e9
Signed-off-by: Meng Dongyang <daniel.meng@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
William Wu
b386106951 phy: rockchip-inno-usb2: don't power on otg phy in ls irq handler
The commit c590056b6a ("phy: rockchip-inno-usb2: usb remote
wakeup support") power on otg phy in linestate irq handler,
this will cause usb peripheral fail to connect to PC in the
following case:
1. enable otg linestate irq
2. set system enter deep sleep
3. wakeup system by power key
4. connect usb peripheral to PC, pull up D+ to ~3V, trigger
   linestate irq and power on otg phy.
5. usb peripheral do BC1.2 detect, but PC try to enumerate
   the usb peripheral at the same time and fail at last.

Actually the usb controller drivers (e.g. dwc3 driver)
and otg_sm_work can manage the otg phy power consumption, so
it doesn't need to power on otg phy in linestate irq handler.

Change-Id: Ifd78e4d44ab96f07f75f063ed20af153b4027028
Signed-off-by: William Wu <wulf@rock-chips.com>
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00
Frank Wang
9d765c52e2 phy: rockchip-inno-usb2: amend sm work to support legacy SoC
This adds amend logic of sm work to compatibly support some legacy SoCs,
because _host_utmi_linestate_ and _host_utmi_hostdisconnect_ GRF status
bits which are required for host sm work were not introduced in these
SoCs.

Change-Id: Ib4f499f592618930ac5016a63b7a530674aa6005
Signed-off-by: Frank Wang <frank.wang@rock-chips.com>
2019-03-12 17:12:55 +08:00