blob: 871bbcc2d9919f39ec6fe12cec19c274d21ac943 [file] [log] [blame]
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -07001/* Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
Joonwoo Park8ef69192014-06-09 16:54:15 -07002
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
Channagoud Kadabi4517eb12015-09-02 18:43:13 -070028#include <arch/defines.h>
Joonwoo Park8ef69192014-06-09 16:54:15 -070029#include <platform/iomap.h>
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070030#include <qusb2_phy.h>
Joonwoo Park8ef69192014-06-09 16:54:15 -070031#include <reg.h>
32#include <bits.h>
33#include <debug.h>
Veera Sundaram Sankaran00181512014-12-09 11:23:39 -080034#include <qtimer.h>
Joonwoo Park8ef69192014-06-09 16:54:15 -070035
Channagoud Kadabi12b96932014-09-23 15:18:11 -070036__WEAK int platform_is_msm8994()
37{
38 return 0;
39}
40
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070041__WEAK int platform_is_msm8996()
42{
43 return 0;
44}
45
Joonwoo Park8ef69192014-06-09 16:54:15 -070046void qusb2_phy_reset(void)
47{
48 uint32_t val;
Channagoud Kadabid1e2cc22015-08-13 12:48:37 -070049 /* Default tune value */
50 uint8_t tune2 = 0xB3;
Joonwoo Park8ef69192014-06-09 16:54:15 -070051
52 /* Block Reset */
53 val = readl(GCC_QUSB2_PHY_BCR) | BIT(0);
54 writel(val, GCC_QUSB2_PHY_BCR);
55 udelay(10);
56 writel(val & ~BIT(0), GCC_QUSB2_PHY_BCR);
57
Channagoud Kadabi4517eb12015-09-02 18:43:13 -070058 /* configure the abh2 phy to wait state */
59 writel(0x11, PERIPH_SS_AHB2PHY_TOP_CFG);
60 dmb();
61
Tanya Finkele7aa4272014-08-08 23:41:34 +030062 /* set CLAMP_N_EN and stay with disabled USB PHY */
63 writel(0x23, QUSB2PHY_PORT_POWERDOWN);
64
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070065 if (platform_is_msm8996())
66 {
67 writel(0xF8, QUSB2PHY_PORT_TUNE1);
Channagoud Kadabid1e2cc22015-08-13 12:48:37 -070068 /* Upper nibble of tune2 register should be updated based on the fuse value.
69 * Read the bits 21..24 from fuse and update the upper nibble with this value
70 */
71#if QFPROM_CORR_CALIB_ROW12_MSB
72 uint8_t fuse_val = (readl(QFPROM_CORR_CALIB_ROW12_MSB) & 0x1E00000) >> 21;
73 /* If fuse value is non zero then update the upper nibble with the fuse value
74 * otherwise use the default value
75 */
76 if (fuse_val)
77 tune2 = (tune2 & 0x0f) | (fuse_val << 4);
78#endif
79 writel(tune2, QUSB2PHY_PORT_TUNE2);
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070080 writel(0x93, QUSB2PHY_PORT_TUNE3);
81 writel(0xC0, QUSB2PHY_PORT_TUNE4);
82 writel(0x30, QUSB2PHY_PLL_TUNE);
83 writel(0x79, QUSB2PHY_PLL_USER_CTL1);
84 writel(0x21, QUSB2PHY_PLL_USER_CTL2);
85 writel(0x14, QUSB2PHY_PORT_TEST2);
86 }
87 else
88 {
89 /* Set HS impedance to 42ohms */
90 writel(0xA0, QUSB2PHY_PORT_TUNE1);
Tanya Finkele7aa4272014-08-08 23:41:34 +030091
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070092 /* Set TX current to 19mA, TX SR and TX bias current to 1, 1 */
93 writel(0xA5, QUSB2PHY_PORT_TUNE2);
Tanya Finkele7aa4272014-08-08 23:41:34 +030094
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070095 /* Increase autocalibration bias circuit settling time
96 * and enable utocalibration */
97 writel(0x81, QUSB2PHY_PORT_TUNE3);
Tanya Finkele7aa4272014-08-08 23:41:34 +030098
Channagoud Kadabi7164ddf2015-04-09 16:27:36 -070099 writel(0x85, QUSB2PHY_PORT_TUNE4);
100 }
101
Tanya Finkele7aa4272014-08-08 23:41:34 +0300102 /* Wait for tuning params to take effect right before re-enabling power*/
Joonwoo Park8ef69192014-06-09 16:54:15 -0700103 udelay(10);
104
Tanya Finkele7aa4272014-08-08 23:41:34 +0300105 /* Disable the PHY */
106 writel(0x23, QUSB2PHY_PORT_POWERDOWN);
107 /* Enable ULPI mode */
Channagoud Kadabi12b96932014-09-23 15:18:11 -0700108 if (platform_is_msm8994())
109 writel(0x0, QUSB2PHY_PORT_UTMI_CTRL2);
Tanya Finkele7aa4272014-08-08 23:41:34 +0300110 /* Enable PHY */
111 /* set CLAMP_N_EN and USB PHY is enabled*/
Joonwoo Park8ef69192014-06-09 16:54:15 -0700112 writel(0x22, QUSB2PHY_PORT_POWERDOWN);
113}