Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/dma-mapping.h> |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 19 | #include <linux/pm_runtime.h> |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 20 | #include <linux/ratelimit.h> |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 21 | #include <linux/interrupt.h> |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 22 | #include <linux/ioport.h> |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 23 | #include <linux/clk.h> |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 24 | #include <linux/io.h> |
| 25 | #include <linux/module.h> |
| 26 | #include <linux/types.h> |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 27 | #include <linux/delay.h> |
| 28 | #include <linux/of.h> |
Vijayavardhan Vennapusa | 8eb6873 | 2013-03-26 13:05:38 +0530 | [diff] [blame] | 29 | #include <linux/of_platform.h> |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 30 | #include <linux/list.h> |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
| 32 | #include <linux/uaccess.h> |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 33 | #include <linux/usb/ch9.h> |
| 34 | #include <linux/usb/gadget.h> |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 35 | #include <linux/qpnp-misc.h> |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 36 | #include <linux/usb/msm_hsusb.h> |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 37 | #include <linux/usb/msm_ext_chg.h> |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 38 | #include <linux/regulator/consumer.h> |
Jack Pham | 924cbe87 | 2013-07-10 16:40:55 -0700 | [diff] [blame] | 39 | #include <linux/pm_wakeup.h> |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 40 | #include <linux/power_supply.h> |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 41 | #include <linux/qpnp/qpnp-adc.h> |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 42 | #include <linux/cdev.h> |
| 43 | #include <linux/completion.h> |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 44 | |
| 45 | #include <mach/rpm-regulator.h> |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 46 | #include <mach/rpm-regulator-smd.h> |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 47 | #include <mach/msm_bus.h> |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 48 | #include <mach/clk.h> |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 49 | |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 50 | #include "dwc3_otg.h" |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 51 | #include "core.h" |
| 52 | #include "gadget.h" |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 53 | #include "debug.h" |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 54 | |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 55 | /* ADC threshold values */ |
| 56 | static int adc_low_threshold = 700; |
| 57 | module_param(adc_low_threshold, int, S_IRUGO | S_IWUSR); |
| 58 | MODULE_PARM_DESC(adc_low_threshold, "ADC ID Low voltage threshold"); |
| 59 | |
| 60 | static int adc_high_threshold = 950; |
| 61 | module_param(adc_high_threshold, int, S_IRUGO | S_IWUSR); |
| 62 | MODULE_PARM_DESC(adc_high_threshold, "ADC ID High voltage threshold"); |
| 63 | |
| 64 | static int adc_meas_interval = ADC_MEAS1_INTERVAL_1S; |
| 65 | module_param(adc_meas_interval, int, S_IRUGO | S_IWUSR); |
| 66 | MODULE_PARM_DESC(adc_meas_interval, "ADC ID polling period"); |
| 67 | |
Vijayavardhan Vennapusa | 26a4960 | 2012-12-18 13:51:45 +0530 | [diff] [blame] | 68 | static int override_phy_init; |
| 69 | module_param(override_phy_init, int, S_IRUGO|S_IWUSR); |
| 70 | MODULE_PARM_DESC(override_phy_init, "Override HSPHY Init Seq"); |
| 71 | |
Jack Pham | 9b4606b | 2013-04-02 17:32:25 -0700 | [diff] [blame] | 72 | /* Enable Proprietary charger detection */ |
| 73 | static bool prop_chg_detect; |
| 74 | module_param(prop_chg_detect, bool, S_IRUGO | S_IWUSR); |
| 75 | MODULE_PARM_DESC(prop_chg_detect, "Enable Proprietary charger detection"); |
| 76 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 77 | /** |
| 78 | * USB DBM Hardware registers. |
| 79 | * |
| 80 | */ |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 81 | #define DBM_BASE 0x000F8000 |
| 82 | #define DBM_EP_CFG(n) (DBM_BASE + (0x00 + 4 * (n))) |
| 83 | #define DBM_DATA_FIFO(n) (DBM_BASE + (0x10 + 4 * (n))) |
| 84 | #define DBM_DATA_FIFO_SIZE(n) (DBM_BASE + (0x20 + 4 * (n))) |
| 85 | #define DBM_DATA_FIFO_EN (DBM_BASE + (0x30)) |
| 86 | #define DBM_GEVNTADR (DBM_BASE + (0x34)) |
| 87 | #define DBM_GEVNTSIZ (DBM_BASE + (0x38)) |
| 88 | #define DBM_DBG_CNFG (DBM_BASE + (0x3C)) |
| 89 | #define DBM_HW_TRB0_EP(n) (DBM_BASE + (0x40 + 4 * (n))) |
| 90 | #define DBM_HW_TRB1_EP(n) (DBM_BASE + (0x50 + 4 * (n))) |
| 91 | #define DBM_HW_TRB2_EP(n) (DBM_BASE + (0x60 + 4 * (n))) |
| 92 | #define DBM_HW_TRB3_EP(n) (DBM_BASE + (0x70 + 4 * (n))) |
| 93 | #define DBM_PIPE_CFG (DBM_BASE + (0x80)) |
| 94 | #define DBM_SOFT_RESET (DBM_BASE + (0x84)) |
| 95 | #define DBM_GEN_CFG (DBM_BASE + (0x88)) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * USB DBM Hardware registers bitmask. |
| 99 | * |
| 100 | */ |
| 101 | /* DBM_EP_CFG */ |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 102 | #define DBM_EN_EP 0x00000001 |
| 103 | #define USB3_EPNUM 0x0000003E |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 104 | #define DBM_BAM_PIPE_NUM 0x000000C0 |
| 105 | #define DBM_PRODUCER 0x00000100 |
| 106 | #define DBM_DISABLE_WB 0x00000200 |
| 107 | #define DBM_INT_RAM_ACC 0x00000400 |
| 108 | |
| 109 | /* DBM_DATA_FIFO_SIZE */ |
| 110 | #define DBM_DATA_FIFO_SIZE_MASK 0x0000ffff |
| 111 | |
| 112 | /* DBM_GEVNTSIZ */ |
| 113 | #define DBM_GEVNTSIZ_MASK 0x0000ffff |
| 114 | |
| 115 | /* DBM_DBG_CNFG */ |
| 116 | #define DBM_ENABLE_IOC_MASK 0x0000000f |
| 117 | |
| 118 | /* DBM_SOFT_RESET */ |
| 119 | #define DBM_SFT_RST_EP0 0x00000001 |
| 120 | #define DBM_SFT_RST_EP1 0x00000002 |
| 121 | #define DBM_SFT_RST_EP2 0x00000004 |
| 122 | #define DBM_SFT_RST_EP3 0x00000008 |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 123 | #define DBM_SFT_RST_EPS_MASK 0x0000000F |
| 124 | #define DBM_SFT_RST_MASK 0x80000000 |
| 125 | #define DBM_EN_MASK 0x00000002 |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 126 | |
| 127 | #define DBM_MAX_EPS 4 |
| 128 | |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 129 | /* DBM TRB configurations */ |
| 130 | #define DBM_TRB_BIT 0x80000000 |
| 131 | #define DBM_TRB_DATA_SRC 0x40000000 |
| 132 | #define DBM_TRB_DMA 0x20000000 |
| 133 | #define DBM_TRB_EP_NUM(ep) (ep<<24) |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 134 | |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 135 | #define USB3_PORTSC (0x430) |
| 136 | #define PORT_PE (0x1 << 1) |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 137 | /** |
| 138 | * USB QSCRATCH Hardware registers |
| 139 | * |
| 140 | */ |
| 141 | #define QSCRATCH_REG_OFFSET (0x000F8800) |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 142 | #define QSCRATCH_CTRL_REG (QSCRATCH_REG_OFFSET + 0x04) |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 143 | #define QSCRATCH_GENERAL_CFG (QSCRATCH_REG_OFFSET + 0x08) |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 144 | #define QSCRATCH_RAM1_REG (QSCRATCH_REG_OFFSET + 0x0C) |
Manu Gautam | bd0e578 | 2012-08-30 10:39:01 -0700 | [diff] [blame] | 145 | #define HS_PHY_CTRL_REG (QSCRATCH_REG_OFFSET + 0x10) |
Vijayavardhan Vennapusa | 26a4960 | 2012-12-18 13:51:45 +0530 | [diff] [blame] | 146 | #define PARAMETER_OVERRIDE_X_REG (QSCRATCH_REG_OFFSET + 0x14) |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 147 | #define CHARGING_DET_CTRL_REG (QSCRATCH_REG_OFFSET + 0x18) |
| 148 | #define CHARGING_DET_OUTPUT_REG (QSCRATCH_REG_OFFSET + 0x1C) |
| 149 | #define ALT_INTERRUPT_EN_REG (QSCRATCH_REG_OFFSET + 0x20) |
| 150 | #define HS_PHY_IRQ_STAT_REG (QSCRATCH_REG_OFFSET + 0x24) |
Manu Gautam | d4108b7 | 2012-12-14 17:35:18 +0530 | [diff] [blame] | 151 | #define CGCTL_REG (QSCRATCH_REG_OFFSET + 0x28) |
Manu Gautam | bd0e578 | 2012-08-30 10:39:01 -0700 | [diff] [blame] | 152 | #define SS_PHY_CTRL_REG (QSCRATCH_REG_OFFSET + 0x30) |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 153 | #define SS_PHY_PARAM_CTRL_1 (QSCRATCH_REG_OFFSET + 0x34) |
| 154 | #define SS_PHY_PARAM_CTRL_2 (QSCRATCH_REG_OFFSET + 0x38) |
Vijayavardhan Vennapusa | d81aed3 | 2012-12-05 17:30:40 +0530 | [diff] [blame] | 155 | #define SS_CR_PROTOCOL_DATA_IN_REG (QSCRATCH_REG_OFFSET + 0x3C) |
| 156 | #define SS_CR_PROTOCOL_DATA_OUT_REG (QSCRATCH_REG_OFFSET + 0x40) |
| 157 | #define SS_CR_PROTOCOL_CAP_ADDR_REG (QSCRATCH_REG_OFFSET + 0x44) |
| 158 | #define SS_CR_PROTOCOL_CAP_DATA_REG (QSCRATCH_REG_OFFSET + 0x48) |
| 159 | #define SS_CR_PROTOCOL_READ_REG (QSCRATCH_REG_OFFSET + 0x4C) |
| 160 | #define SS_CR_PROTOCOL_WRITE_REG (QSCRATCH_REG_OFFSET + 0x50) |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 161 | #define PWR_EVNT_IRQ_STAT_REG (QSCRATCH_REG_OFFSET + 0x58) |
| 162 | #define PWR_EVNT_IRQ_MASK_REG (QSCRATCH_REG_OFFSET + 0x5C) |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 163 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 164 | struct dwc3_msm_req_complete { |
| 165 | struct list_head list_item; |
| 166 | struct usb_request *req; |
| 167 | void (*orig_complete)(struct usb_ep *ep, |
| 168 | struct usb_request *req); |
| 169 | }; |
| 170 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 171 | struct dwc3_msm { |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 172 | struct device *dev; |
| 173 | void __iomem *base; |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 174 | struct resource *io_res; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 175 | int dbm_num_eps; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 176 | u8 ep_num_mapping[DBM_MAX_EPS]; |
| 177 | const struct usb_ep_ops *original_ep_ops[DWC3_ENDPOINTS_NUM]; |
| 178 | struct list_head req_complete_list; |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 179 | struct clk *xo_clk; |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 180 | struct clk *ref_clk; |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 181 | struct clk *core_clk; |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 182 | struct clk *iface_clk; |
| 183 | struct clk *sleep_clk; |
| 184 | struct clk *hsphy_sleep_clk; |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 185 | struct clk *utmi_clk; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 186 | struct regulator *hsusb_3p3; |
| 187 | struct regulator *hsusb_1p8; |
| 188 | struct regulator *hsusb_vddcx; |
| 189 | struct regulator *ssusb_1p8; |
| 190 | struct regulator *ssusb_vddcx; |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 191 | struct regulator *dwc3_gdsc; |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 192 | |
| 193 | /* VBUS regulator if no OTG and running in host only mode */ |
| 194 | struct regulator *vbus_otg; |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 195 | struct dwc3_ext_xceiv ext_xceiv; |
| 196 | bool resume_pending; |
| 197 | atomic_t pm_suspended; |
| 198 | atomic_t in_lpm; |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 199 | int hs_phy_irq; |
Vijayavardhan Vennapusa | 26a4960 | 2012-12-18 13:51:45 +0530 | [diff] [blame] | 200 | int hsphy_init_seq; |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 201 | bool lpm_irq_seen; |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 202 | struct delayed_work resume_work; |
Manu Gautam | 6eb13e3 | 2013-02-01 15:19:15 +0530 | [diff] [blame] | 203 | struct work_struct restart_usb_work; |
Vijayavardhan Vennapusa | ddd0474 | 2013-09-26 19:47:18 +0530 | [diff] [blame] | 204 | struct work_struct usb_block_reset_work; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 205 | struct dwc3_charger charger; |
| 206 | struct usb_phy *otg_xceiv; |
| 207 | struct delayed_work chg_work; |
| 208 | enum usb_chg_state chg_state; |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 209 | int pmic_id_irq; |
| 210 | struct work_struct id_work; |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 211 | struct qpnp_adc_tm_btm_param adc_param; |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 212 | struct qpnp_adc_tm_chip *adc_tm_dev; |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 213 | struct delayed_work init_adc_work; |
| 214 | bool id_adc_detect; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 215 | u8 dcd_retries; |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 216 | u32 bus_perf_client; |
| 217 | struct msm_bus_scale_pdata *bus_scale_table; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 218 | struct power_supply usb_psy; |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 219 | struct power_supply *ext_vbus_psy; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 220 | unsigned int online; |
| 221 | unsigned int host_mode; |
Pavankumar Kondeti | fbd4b14 | 2013-07-16 11:13:05 +0530 | [diff] [blame] | 222 | unsigned int voltage_max; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 223 | unsigned int current_max; |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 224 | unsigned int vdd_no_vol_level; |
| 225 | unsigned int vdd_low_vol_level; |
| 226 | unsigned int vdd_high_vol_level; |
Vijayavardhan Vennapusa | fc3db60 | 2013-08-20 17:54:54 +0530 | [diff] [blame] | 227 | unsigned int tx_fifo_size; |
| 228 | unsigned int qdss_tx_fifo_size; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 229 | bool vbus_active; |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 230 | bool ext_inuse; |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 231 | enum dwc3_id_state id_state; |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 232 | unsigned long lpm_flags; |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 233 | #define MDWC3_PHY_REF_AND_CORECLK_OFF BIT(0) |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 234 | #define MDWC3_TCXO_SHUTDOWN BIT(1) |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 235 | |
| 236 | u32 qscratch_ctl_val; |
| 237 | dev_t ext_chg_dev; |
| 238 | struct cdev ext_chg_cdev; |
| 239 | struct class *ext_chg_class; |
| 240 | struct device *ext_chg_device; |
| 241 | bool ext_chg_opened; |
| 242 | bool ext_chg_active; |
| 243 | struct completion ext_chg_wait; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | #define USB_HSPHY_3P3_VOL_MIN 3050000 /* uV */ |
| 247 | #define USB_HSPHY_3P3_VOL_MAX 3300000 /* uV */ |
| 248 | #define USB_HSPHY_3P3_HPM_LOAD 16000 /* uA */ |
| 249 | |
| 250 | #define USB_HSPHY_1P8_VOL_MIN 1800000 /* uV */ |
| 251 | #define USB_HSPHY_1P8_VOL_MAX 1800000 /* uV */ |
| 252 | #define USB_HSPHY_1P8_HPM_LOAD 19000 /* uA */ |
| 253 | |
| 254 | #define USB_SSPHY_1P8_VOL_MIN 1800000 /* uV */ |
| 255 | #define USB_SSPHY_1P8_VOL_MAX 1800000 /* uV */ |
| 256 | #define USB_SSPHY_1P8_HPM_LOAD 23000 /* uA */ |
| 257 | |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 258 | static struct usb_ext_notification *usb_ext; |
| 259 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 260 | /** |
| 261 | * |
| 262 | * Read register with debug info. |
| 263 | * |
| 264 | * @base - DWC3 base virtual address. |
| 265 | * @offset - register offset. |
| 266 | * |
| 267 | * @return u32 |
| 268 | */ |
| 269 | static inline u32 dwc3_msm_read_reg(void *base, u32 offset) |
| 270 | { |
| 271 | u32 val = ioread32(base + offset); |
| 272 | return val; |
| 273 | } |
| 274 | |
| 275 | /** |
| 276 | * Read register masked field with debug info. |
| 277 | * |
| 278 | * @base - DWC3 base virtual address. |
| 279 | * @offset - register offset. |
| 280 | * @mask - register bitmask. |
| 281 | * |
| 282 | * @return u32 |
| 283 | */ |
| 284 | static inline u32 dwc3_msm_read_reg_field(void *base, |
| 285 | u32 offset, |
| 286 | const u32 mask) |
| 287 | { |
| 288 | u32 shift = find_first_bit((void *)&mask, 32); |
| 289 | u32 val = ioread32(base + offset); |
| 290 | val &= mask; /* clear other bits */ |
| 291 | val >>= shift; |
| 292 | return val; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * |
| 297 | * Write register with debug info. |
| 298 | * |
| 299 | * @base - DWC3 base virtual address. |
| 300 | * @offset - register offset. |
| 301 | * @val - value to write. |
| 302 | * |
| 303 | */ |
| 304 | static inline void dwc3_msm_write_reg(void *base, u32 offset, u32 val) |
| 305 | { |
| 306 | iowrite32(val, base + offset); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Write register masked field with debug info. |
| 311 | * |
| 312 | * @base - DWC3 base virtual address. |
| 313 | * @offset - register offset. |
| 314 | * @mask - register bitmask. |
| 315 | * @val - value to write. |
| 316 | * |
| 317 | */ |
| 318 | static inline void dwc3_msm_write_reg_field(void *base, u32 offset, |
| 319 | const u32 mask, u32 val) |
| 320 | { |
| 321 | u32 shift = find_first_bit((void *)&mask, 32); |
| 322 | u32 tmp = ioread32(base + offset); |
| 323 | |
| 324 | tmp &= ~mask; /* clear written bits */ |
| 325 | val = tmp | (val << shift); |
| 326 | iowrite32(val, base + offset); |
| 327 | } |
| 328 | |
| 329 | /** |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 330 | * Write register and read back masked value to confirm it is written |
| 331 | * |
| 332 | * @base - DWC3 base virtual address. |
| 333 | * @offset - register offset. |
| 334 | * @mask - register bitmask specifying what should be updated |
| 335 | * @val - value to write. |
| 336 | * |
| 337 | */ |
| 338 | static inline void dwc3_msm_write_readback(void *base, u32 offset, |
| 339 | const u32 mask, u32 val) |
| 340 | { |
| 341 | u32 write_val, tmp = ioread32(base + offset); |
| 342 | |
| 343 | tmp &= ~mask; /* retain other bits */ |
| 344 | write_val = tmp | val; |
| 345 | |
| 346 | iowrite32(write_val, base + offset); |
| 347 | |
| 348 | /* Read back to see if val was written */ |
| 349 | tmp = ioread32(base + offset); |
| 350 | tmp &= mask; /* clear other bits */ |
| 351 | |
| 352 | if (tmp != val) |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 353 | pr_err("%s: write: %x to QSCRATCH: %x FAILED\n", |
| 354 | __func__, val, offset); |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /** |
Vijayavardhan Vennapusa | d81aed3 | 2012-12-05 17:30:40 +0530 | [diff] [blame] | 358 | * |
| 359 | * Write SSPHY register with debug info. |
| 360 | * |
| 361 | * @base - DWC3 base virtual address. |
| 362 | * @addr - SSPHY address to write. |
| 363 | * @val - value to write. |
| 364 | * |
| 365 | */ |
| 366 | static void dwc3_msm_ssusb_write_phycreg(void *base, u32 addr, u32 val) |
| 367 | { |
| 368 | iowrite32(addr, base + SS_CR_PROTOCOL_DATA_IN_REG); |
| 369 | iowrite32(0x1, base + SS_CR_PROTOCOL_CAP_ADDR_REG); |
| 370 | while (ioread32(base + SS_CR_PROTOCOL_CAP_ADDR_REG)) |
| 371 | cpu_relax(); |
| 372 | |
| 373 | iowrite32(val, base + SS_CR_PROTOCOL_DATA_IN_REG); |
| 374 | iowrite32(0x1, base + SS_CR_PROTOCOL_CAP_DATA_REG); |
| 375 | while (ioread32(base + SS_CR_PROTOCOL_CAP_DATA_REG)) |
| 376 | cpu_relax(); |
| 377 | |
| 378 | iowrite32(0x1, base + SS_CR_PROTOCOL_WRITE_REG); |
| 379 | while (ioread32(base + SS_CR_PROTOCOL_WRITE_REG)) |
| 380 | cpu_relax(); |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * |
| 385 | * Read SSPHY register with debug info. |
| 386 | * |
| 387 | * @base - DWC3 base virtual address. |
| 388 | * @addr - SSPHY address to read. |
| 389 | * |
| 390 | */ |
| 391 | static u32 dwc3_msm_ssusb_read_phycreg(void *base, u32 addr) |
| 392 | { |
Vijayavardhan Vennapusa | 9620121 | 2013-06-12 19:59:27 +0530 | [diff] [blame] | 393 | bool first_read = true; |
| 394 | |
Vijayavardhan Vennapusa | d81aed3 | 2012-12-05 17:30:40 +0530 | [diff] [blame] | 395 | iowrite32(addr, base + SS_CR_PROTOCOL_DATA_IN_REG); |
| 396 | iowrite32(0x1, base + SS_CR_PROTOCOL_CAP_ADDR_REG); |
| 397 | while (ioread32(base + SS_CR_PROTOCOL_CAP_ADDR_REG)) |
| 398 | cpu_relax(); |
| 399 | |
Vijayavardhan Vennapusa | 9620121 | 2013-06-12 19:59:27 +0530 | [diff] [blame] | 400 | /* |
| 401 | * Due to hardware bug, first read of SSPHY register might be |
| 402 | * incorrect. Hence as workaround, SW should perform SSPHY register |
| 403 | * read twice, but use only second read and ignore first read. |
| 404 | */ |
| 405 | retry: |
Vijayavardhan Vennapusa | d81aed3 | 2012-12-05 17:30:40 +0530 | [diff] [blame] | 406 | iowrite32(0x1, base + SS_CR_PROTOCOL_READ_REG); |
| 407 | while (ioread32(base + SS_CR_PROTOCOL_READ_REG)) |
| 408 | cpu_relax(); |
| 409 | |
Vijayavardhan Vennapusa | 9620121 | 2013-06-12 19:59:27 +0530 | [diff] [blame] | 410 | if (first_read) { |
| 411 | ioread32(base + SS_CR_PROTOCOL_DATA_OUT_REG); |
| 412 | first_read = false; |
| 413 | goto retry; |
| 414 | } |
| 415 | |
Vijayavardhan Vennapusa | d81aed3 | 2012-12-05 17:30:40 +0530 | [diff] [blame] | 416 | return ioread32(base + SS_CR_PROTOCOL_DATA_OUT_REG); |
| 417 | } |
| 418 | |
| 419 | /** |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 420 | * Dump all QSCRATCH registers. |
| 421 | * |
| 422 | */ |
| 423 | static void dwc3_msm_dump_phy_info(struct dwc3_msm *mdwc) |
| 424 | { |
| 425 | |
| 426 | dbg_print_reg("SSPHY_CTRL_REG", dwc3_msm_read_reg(mdwc->base, |
| 427 | SS_PHY_CTRL_REG)); |
| 428 | dbg_print_reg("HSPHY_CTRL_REG", dwc3_msm_read_reg(mdwc->base, |
| 429 | HS_PHY_CTRL_REG)); |
| 430 | dbg_print_reg("QSCRATCH_CTRL_REG", dwc3_msm_read_reg(mdwc->base, |
| 431 | QSCRATCH_CTRL_REG)); |
| 432 | dbg_print_reg("QSCRATCH_GENERAL_CFG", dwc3_msm_read_reg(mdwc->base, |
| 433 | QSCRATCH_GENERAL_CFG)); |
| 434 | dbg_print_reg("PARAMETER_OVERRIDE_X_REG", dwc3_msm_read_reg(mdwc->base, |
| 435 | PARAMETER_OVERRIDE_X_REG)); |
| 436 | dbg_print_reg("HS_PHY_IRQ_STAT_REG", dwc3_msm_read_reg(mdwc->base, |
| 437 | HS_PHY_IRQ_STAT_REG)); |
| 438 | dbg_print_reg("SS_PHY_PARAM_CTRL_1", dwc3_msm_read_reg(mdwc->base, |
| 439 | SS_PHY_PARAM_CTRL_1)); |
| 440 | dbg_print_reg("SS_PHY_PARAM_CTRL_2", dwc3_msm_read_reg(mdwc->base, |
| 441 | SS_PHY_PARAM_CTRL_2)); |
| 442 | dbg_print_reg("QSCRATCH_RAM1_REG", dwc3_msm_read_reg(mdwc->base, |
| 443 | QSCRATCH_RAM1_REG)); |
| 444 | dbg_print_reg("PWR_EVNT_IRQ_STAT_REG", dwc3_msm_read_reg(mdwc->base, |
| 445 | PWR_EVNT_IRQ_STAT_REG)); |
| 446 | dbg_print_reg("PWR_EVNT_IRQ_MASK_REG", dwc3_msm_read_reg(mdwc->base, |
| 447 | PWR_EVNT_IRQ_MASK_REG)); |
| 448 | } |
| 449 | |
| 450 | /** |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 451 | * Return DBM EP number according to usb endpoint number. |
| 452 | * |
| 453 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 454 | static int dwc3_msm_find_matching_dbm_ep(struct dwc3_msm *mdwc, u8 usb_ep) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 455 | { |
| 456 | int i; |
| 457 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 458 | for (i = 0; i < mdwc->dbm_num_eps; i++) |
| 459 | if (mdwc->ep_num_mapping[i] == usb_ep) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 460 | return i; |
| 461 | |
| 462 | return -ENODEV; /* Not found */ |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * Return number of configured DBM endpoints. |
| 467 | * |
| 468 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 469 | static int dwc3_msm_configured_dbm_ep_num(struct dwc3_msm *mdwc) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 470 | { |
| 471 | int i; |
| 472 | int count = 0; |
| 473 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 474 | for (i = 0; i < mdwc->dbm_num_eps; i++) |
| 475 | if (mdwc->ep_num_mapping[i]) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 476 | count++; |
| 477 | |
| 478 | return count; |
| 479 | } |
| 480 | |
| 481 | /** |
| 482 | * Configure the DBM with the USB3 core event buffer. |
| 483 | * This function is called by the SNPS UDC upon initialization. |
| 484 | * |
| 485 | * @addr - address of the event buffer. |
| 486 | * @size - size of the event buffer. |
| 487 | * |
| 488 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 489 | static int dwc3_msm_event_buffer_config(struct dwc3_msm *mdwc, |
| 490 | u32 addr, u16 size) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 491 | { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 492 | dev_dbg(mdwc->dev, "%s\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 493 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 494 | dwc3_msm_write_reg(mdwc->base, DBM_GEVNTADR, addr); |
| 495 | dwc3_msm_write_reg_field(mdwc->base, DBM_GEVNTSIZ, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 496 | DBM_GEVNTSIZ_MASK, size); |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /** |
| 502 | * Reset the DBM registers upon initialization. |
| 503 | * |
| 504 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 505 | static int dwc3_msm_dbm_soft_reset(struct dwc3_msm *mdwc, int enter_reset) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 506 | { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 507 | dev_dbg(mdwc->dev, "%s\n", __func__); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 508 | if (enter_reset) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 509 | dev_dbg(mdwc->dev, "enter DBM reset\n"); |
| 510 | dwc3_msm_write_reg_field(mdwc->base, DBM_SOFT_RESET, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 511 | DBM_SFT_RST_MASK, 1); |
| 512 | } else { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 513 | dev_dbg(mdwc->dev, "exit DBM reset\n"); |
| 514 | dwc3_msm_write_reg_field(mdwc->base, DBM_SOFT_RESET, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 515 | DBM_SFT_RST_MASK, 0); |
| 516 | /*enable DBM*/ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 517 | dwc3_msm_write_reg_field(mdwc->base, QSCRATCH_GENERAL_CFG, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 518 | DBM_EN_MASK, 0x1); |
| 519 | } |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | /** |
| 525 | * Soft reset specific DBM ep. |
| 526 | * This function is called by the function driver upon events |
| 527 | * such as transfer aborting, USB re-enumeration and USB |
| 528 | * disconnection. |
| 529 | * |
| 530 | * @dbm_ep - DBM ep number. |
| 531 | * @enter_reset - should we enter a reset state or get out of it. |
| 532 | * |
| 533 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 534 | static int dwc3_msm_dbm_ep_soft_reset(struct dwc3_msm *mdwc, |
| 535 | u8 dbm_ep, bool enter_reset) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 536 | { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 537 | dev_dbg(mdwc->dev, "%s\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 538 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 539 | if (dbm_ep >= mdwc->dbm_num_eps) { |
| 540 | dev_err(mdwc->dev, "%s: Invalid DBM ep index\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 541 | return -ENODEV; |
| 542 | } |
| 543 | |
| 544 | if (enter_reset) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 545 | dwc3_msm_write_reg_field(mdwc->base, DBM_SOFT_RESET, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 546 | DBM_SFT_RST_EPS_MASK & 1 << dbm_ep, 1); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 547 | } else { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 548 | dwc3_msm_write_reg_field(mdwc->base, DBM_SOFT_RESET, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 549 | DBM_SFT_RST_EPS_MASK & 1 << dbm_ep, 0); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 550 | } |
| 551 | |
| 552 | return 0; |
| 553 | } |
| 554 | |
| 555 | /** |
| 556 | * Configure a USB DBM ep to work in BAM mode. |
| 557 | * |
| 558 | * |
| 559 | * @usb_ep - USB physical EP number. |
| 560 | * @producer - producer/consumer. |
| 561 | * @disable_wb - disable write back to system memory. |
| 562 | * @internal_mem - use internal USB memory for data fifo. |
| 563 | * @ioc - enable interrupt on completion. |
| 564 | * |
| 565 | * @return int - DBM ep number. |
| 566 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 567 | static int dwc3_msm_dbm_ep_config(struct dwc3_msm *mdwc, u8 usb_ep, u8 bam_pipe, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 568 | bool producer, bool disable_wb, |
| 569 | bool internal_mem, bool ioc) |
| 570 | { |
| 571 | u8 dbm_ep; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 572 | u32 ep_cfg; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 573 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 574 | dev_dbg(mdwc->dev, "%s\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 575 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 576 | dbm_ep = dwc3_msm_find_matching_dbm_ep(mdwc, usb_ep); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 577 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 578 | if (dbm_ep < 0) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 579 | dev_err(mdwc->dev, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 580 | "%s: Invalid usb ep index\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 581 | return -ENODEV; |
| 582 | } |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 583 | /* First, reset the dbm endpoint */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 584 | dwc3_msm_dbm_ep_soft_reset(mdwc, dbm_ep, 0); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 585 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 586 | /* Set ioc bit for dbm_ep if needed */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 587 | dwc3_msm_write_reg_field(mdwc->base, DBM_DBG_CNFG, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 588 | DBM_ENABLE_IOC_MASK & 1 << dbm_ep, ioc ? 1 : 0); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 589 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 590 | ep_cfg = (producer ? DBM_PRODUCER : 0) | |
| 591 | (disable_wb ? DBM_DISABLE_WB : 0) | |
| 592 | (internal_mem ? DBM_INT_RAM_ACC : 0); |
| 593 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 594 | dwc3_msm_write_reg_field(mdwc->base, DBM_EP_CFG(dbm_ep), |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 595 | DBM_PRODUCER | DBM_DISABLE_WB | DBM_INT_RAM_ACC, ep_cfg >> 8); |
| 596 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 597 | dwc3_msm_write_reg_field(mdwc->base, DBM_EP_CFG(dbm_ep), USB3_EPNUM, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 598 | usb_ep); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 599 | dwc3_msm_write_reg_field(mdwc->base, DBM_EP_CFG(dbm_ep), |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 600 | DBM_BAM_PIPE_NUM, bam_pipe); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 601 | dwc3_msm_write_reg_field(mdwc->base, DBM_PIPE_CFG, 0x000000ff, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 602 | 0xe4); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 603 | dwc3_msm_write_reg_field(mdwc->base, DBM_EP_CFG(dbm_ep), DBM_EN_EP, |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 604 | 1); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 605 | |
| 606 | return dbm_ep; |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Configure a USB DBM ep to work in normal mode. |
| 611 | * |
| 612 | * @usb_ep - USB ep number. |
| 613 | * |
| 614 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 615 | static int dwc3_msm_dbm_ep_unconfig(struct dwc3_msm *mdwc, u8 usb_ep) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 616 | { |
| 617 | u8 dbm_ep; |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 618 | u32 data; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 619 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 620 | dev_dbg(mdwc->dev, "%s\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 621 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 622 | dbm_ep = dwc3_msm_find_matching_dbm_ep(mdwc, usb_ep); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 623 | |
| 624 | if (dbm_ep < 0) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 625 | dev_err(mdwc->dev, "%s: Invalid usb ep index\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 626 | return -ENODEV; |
| 627 | } |
| 628 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 629 | mdwc->ep_num_mapping[dbm_ep] = 0; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 630 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 631 | data = dwc3_msm_read_reg(mdwc->base, DBM_EP_CFG(dbm_ep)); |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 632 | data &= (~0x1); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 633 | dwc3_msm_write_reg(mdwc->base, DBM_EP_CFG(dbm_ep), data); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 634 | |
| 635 | /* Reset the dbm endpoint */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 636 | dwc3_msm_dbm_ep_soft_reset(mdwc, dbm_ep, true); |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 637 | /* |
| 638 | * 10 usec delay is required before deasserting DBM endpoint reset |
| 639 | * according to hardware programming guide. |
| 640 | */ |
| 641 | udelay(10); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 642 | dwc3_msm_dbm_ep_soft_reset(mdwc, dbm_ep, false); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | /** |
| 648 | * Configure the DBM with the BAM's data fifo. |
| 649 | * This function is called by the USB BAM Driver |
| 650 | * upon initialization. |
| 651 | * |
| 652 | * @ep - pointer to usb endpoint. |
| 653 | * @addr - address of data fifo. |
| 654 | * @size - size of data fifo. |
| 655 | * |
| 656 | */ |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 657 | int msm_data_fifo_config(struct usb_ep *ep, u32 addr, u32 size, u8 dst_pipe_idx) |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 658 | { |
| 659 | u8 dbm_ep; |
| 660 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 661 | struct dwc3 *dwc = dep->dwc; |
| 662 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 663 | u8 bam_pipe = dst_pipe_idx; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 664 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 665 | dev_dbg(mdwc->dev, "%s\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 666 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 667 | dbm_ep = bam_pipe; |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 668 | mdwc->ep_num_mapping[dbm_ep] = dep->number; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 669 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 670 | dwc3_msm_write_reg(mdwc->base, DBM_DATA_FIFO(dbm_ep), addr); |
| 671 | dwc3_msm_write_reg_field(mdwc->base, DBM_DATA_FIFO_SIZE(dbm_ep), |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 672 | DBM_DATA_FIFO_SIZE_MASK, size); |
| 673 | |
| 674 | return 0; |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * Cleanups for msm endpoint on request complete. |
| 679 | * |
| 680 | * Also call original request complete. |
| 681 | * |
| 682 | * @usb_ep - pointer to usb_ep instance. |
| 683 | * @request - pointer to usb_request instance. |
| 684 | * |
| 685 | * @return int - 0 on success, negetive on error. |
| 686 | */ |
| 687 | static void dwc3_msm_req_complete_func(struct usb_ep *ep, |
| 688 | struct usb_request *request) |
| 689 | { |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 690 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 691 | struct dwc3 *dwc = dep->dwc; |
| 692 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 693 | struct dwc3_msm_req_complete *req_complete = NULL; |
| 694 | |
| 695 | /* Find original request complete function and remove it from list */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 696 | list_for_each_entry(req_complete, &mdwc->req_complete_list, list_item) { |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 697 | if (req_complete->req == request) |
| 698 | break; |
| 699 | } |
| 700 | if (!req_complete || req_complete->req != request) { |
| 701 | dev_err(dep->dwc->dev, "%s: could not find the request\n", |
| 702 | __func__); |
| 703 | return; |
| 704 | } |
| 705 | list_del(&req_complete->list_item); |
| 706 | |
| 707 | /* |
| 708 | * Release another one TRB to the pool since DBM queue took 2 TRBs |
| 709 | * (normal and link), and the dwc3/gadget.c :: dwc3_gadget_giveback |
| 710 | * released only one. |
| 711 | */ |
Manu Gautam | 55d3422 | 2012-12-19 16:49:47 +0530 | [diff] [blame] | 712 | dep->busy_slot++; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 713 | |
| 714 | /* Unconfigure dbm ep */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 715 | dwc3_msm_dbm_ep_unconfig(mdwc, dep->number); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 716 | |
| 717 | /* |
| 718 | * If this is the last endpoint we unconfigured, than reset also |
| 719 | * the event buffers. |
| 720 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 721 | if (0 == dwc3_msm_configured_dbm_ep_num(mdwc)) |
| 722 | dwc3_msm_event_buffer_config(mdwc, 0, 0); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 723 | |
| 724 | /* |
| 725 | * Call original complete function, notice that dwc->lock is already |
| 726 | * taken by the caller of this function (dwc3_gadget_giveback()). |
| 727 | */ |
| 728 | request->complete = req_complete->orig_complete; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 729 | if (request->complete) |
| 730 | request->complete(ep, request); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 731 | |
| 732 | kfree(req_complete); |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Helper function. |
| 737 | * See the header of the dwc3_msm_ep_queue function. |
| 738 | * |
| 739 | * @dwc3_ep - pointer to dwc3_ep instance. |
| 740 | * @req - pointer to dwc3_request instance. |
| 741 | * |
| 742 | * @return int - 0 on success, negetive on error. |
| 743 | */ |
| 744 | static int __dwc3_msm_ep_queue(struct dwc3_ep *dep, struct dwc3_request *req) |
| 745 | { |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 746 | struct dwc3_trb *trb; |
| 747 | struct dwc3_trb *trb_link; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 748 | struct dwc3_gadget_ep_cmd_params params; |
| 749 | u32 cmd; |
| 750 | int ret = 0; |
| 751 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 752 | /* We push the request to the dep->req_queued list to indicate that |
| 753 | * this request is issued with start transfer. The request will be out |
| 754 | * from this list in 2 cases. The first is that the transfer will be |
| 755 | * completed (not if the transfer is endless using a circular TRBs with |
| 756 | * with link TRB). The second case is an option to do stop stransfer, |
| 757 | * this can be initiated by the function driver when calling dequeue. |
| 758 | */ |
| 759 | req->queued = true; |
| 760 | list_add_tail(&req->list, &dep->req_queued); |
| 761 | |
| 762 | /* First, prepare a normal TRB, point to the fake buffer */ |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 763 | trb = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 764 | dep->free_slot++; |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 765 | memset(trb, 0, sizeof(*trb)); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 766 | |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 767 | req->trb = trb; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 768 | trb->bph = DBM_TRB_BIT | DBM_TRB_DMA | DBM_TRB_EP_NUM(dep->number); |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 769 | trb->size = DWC3_TRB_SIZE_LENGTH(req->request.length); |
| 770 | trb->ctrl = DWC3_TRBCTL_NORMAL | DWC3_TRB_CTRL_HWO | DWC3_TRB_CTRL_CHN; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 771 | req->trb_dma = dwc3_trb_dma_offset(dep, trb); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 772 | |
| 773 | /* Second, prepare a Link TRB that points to the first TRB*/ |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 774 | trb_link = &dep->trb_pool[dep->free_slot & DWC3_TRB_MASK]; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 775 | dep->free_slot++; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 776 | memset(trb_link, 0, sizeof *trb_link); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 777 | |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 778 | trb_link->bpl = lower_32_bits(req->trb_dma); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 779 | trb_link->bph = DBM_TRB_BIT | |
Ido Shayevitz | fa65a58 | 2012-06-06 14:39:54 +0300 | [diff] [blame] | 780 | DBM_TRB_DMA | DBM_TRB_EP_NUM(dep->number); |
| 781 | trb_link->size = 0; |
| 782 | trb_link->ctrl = DWC3_TRBCTL_LINK_TRB | DWC3_TRB_CTRL_HWO; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 783 | |
| 784 | /* |
| 785 | * Now start the transfer |
| 786 | */ |
| 787 | memset(¶ms, 0, sizeof(params)); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 788 | params.param0 = 0; /* TDAddr High */ |
| 789 | params.param1 = lower_32_bits(req->trb_dma); /* DAddr Low */ |
| 790 | |
Manu Gautam | 5b2bf9a | 2012-10-18 10:52:50 +0530 | [diff] [blame] | 791 | /* DBM requires IOC to be set */ |
| 792 | cmd = DWC3_DEPCMD_STARTTRANSFER | DWC3_DEPCMD_CMDIOC; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 793 | ret = dwc3_send_gadget_ep_cmd(dep->dwc, dep->number, cmd, ¶ms); |
| 794 | if (ret < 0) { |
| 795 | dev_dbg(dep->dwc->dev, |
| 796 | "%s: failed to send STARTTRANSFER command\n", |
| 797 | __func__); |
| 798 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 799 | list_del(&req->list); |
| 800 | return ret; |
| 801 | } |
Manu Gautam | 4a51a06 | 2012-12-07 11:24:39 +0530 | [diff] [blame] | 802 | dep->flags |= DWC3_EP_BUSY; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 803 | |
| 804 | return ret; |
| 805 | } |
| 806 | |
| 807 | /** |
| 808 | * Queue a usb request to the DBM endpoint. |
| 809 | * This function should be called after the endpoint |
| 810 | * was enabled by the ep_enable. |
| 811 | * |
| 812 | * This function prepares special structure of TRBs which |
| 813 | * is familier with the DBM HW, so it will possible to use |
| 814 | * this endpoint in DBM mode. |
| 815 | * |
| 816 | * The TRBs prepared by this function, is one normal TRB |
| 817 | * which point to a fake buffer, followed by a link TRB |
| 818 | * that points to the first TRB. |
| 819 | * |
| 820 | * The API of this function follow the regular API of |
| 821 | * usb_ep_queue (see usb_ep_ops in include/linuk/usb/gadget.h). |
| 822 | * |
| 823 | * @usb_ep - pointer to usb_ep instance. |
| 824 | * @request - pointer to usb_request instance. |
| 825 | * @gfp_flags - possible flags. |
| 826 | * |
| 827 | * @return int - 0 on success, negetive on error. |
| 828 | */ |
| 829 | static int dwc3_msm_ep_queue(struct usb_ep *ep, |
| 830 | struct usb_request *request, gfp_t gfp_flags) |
| 831 | { |
| 832 | struct dwc3_request *req = to_dwc3_request(request); |
| 833 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
| 834 | struct dwc3 *dwc = dep->dwc; |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 835 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 836 | struct dwc3_msm_req_complete *req_complete; |
| 837 | unsigned long flags; |
| 838 | int ret = 0; |
| 839 | u8 bam_pipe; |
| 840 | bool producer; |
| 841 | bool disable_wb; |
| 842 | bool internal_mem; |
| 843 | bool ioc; |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 844 | u8 speed; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 845 | |
| 846 | if (!(request->udc_priv & MSM_SPS_MODE)) { |
| 847 | /* Not SPS mode, call original queue */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 848 | dev_vdbg(mdwc->dev, "%s: not sps mode, use regular queue\n", |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 849 | __func__); |
| 850 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 851 | return (mdwc->original_ep_ops[dep->number])->queue(ep, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 852 | request, |
| 853 | gfp_flags); |
| 854 | } |
| 855 | |
| 856 | if (!dep->endpoint.desc) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 857 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 858 | "%s: trying to queue request %p to disabled ep %s\n", |
| 859 | __func__, request, ep->name); |
| 860 | return -EPERM; |
| 861 | } |
| 862 | |
| 863 | if (dep->number == 0 || dep->number == 1) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 864 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 865 | "%s: trying to queue dbm request %p to control ep %s\n", |
| 866 | __func__, request, ep->name); |
| 867 | return -EPERM; |
| 868 | } |
| 869 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 870 | |
Manu Gautam | 4a51a06 | 2012-12-07 11:24:39 +0530 | [diff] [blame] | 871 | if (dep->busy_slot != dep->free_slot || !list_empty(&dep->request_list) |
| 872 | || !list_empty(&dep->req_queued)) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 873 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 874 | "%s: trying to queue dbm request %p tp ep %s\n", |
| 875 | __func__, request, ep->name); |
| 876 | return -EPERM; |
Manu Gautam | 4a51a06 | 2012-12-07 11:24:39 +0530 | [diff] [blame] | 877 | } else { |
| 878 | dep->busy_slot = 0; |
| 879 | dep->free_slot = 0; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /* |
| 883 | * Override req->complete function, but before doing that, |
| 884 | * store it's original pointer in the req_complete_list. |
| 885 | */ |
| 886 | req_complete = kzalloc(sizeof(*req_complete), GFP_KERNEL); |
| 887 | if (!req_complete) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 888 | dev_err(mdwc->dev, "%s: not enough memory\n", __func__); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 889 | return -ENOMEM; |
| 890 | } |
| 891 | req_complete->req = request; |
| 892 | req_complete->orig_complete = request->complete; |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 893 | list_add_tail(&req_complete->list_item, &mdwc->req_complete_list); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 894 | request->complete = dwc3_msm_req_complete_func; |
| 895 | |
| 896 | /* |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 897 | * Configure the DBM endpoint |
| 898 | */ |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 899 | bam_pipe = request->udc_priv & MSM_PIPE_ID_MASK; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 900 | producer = ((request->udc_priv & MSM_PRODUCER) ? true : false); |
| 901 | disable_wb = ((request->udc_priv & MSM_DISABLE_WB) ? true : false); |
| 902 | internal_mem = ((request->udc_priv & MSM_INTERNAL_MEM) ? true : false); |
| 903 | ioc = ((request->udc_priv & MSM_ETD_IOC) ? true : false); |
| 904 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 905 | ret = dwc3_msm_dbm_ep_config(mdwc, dep->number, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 906 | bam_pipe, producer, |
| 907 | disable_wb, internal_mem, ioc); |
| 908 | if (ret < 0) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 909 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 910 | "error %d after calling dwc3_msm_dbm_ep_config\n", |
| 911 | ret); |
| 912 | return ret; |
| 913 | } |
| 914 | |
| 915 | dev_vdbg(dwc->dev, "%s: queing request %p to ep %s length %d\n", |
| 916 | __func__, request, ep->name, request->length); |
| 917 | |
| 918 | /* |
| 919 | * We must obtain the lock of the dwc3 core driver, |
| 920 | * including disabling interrupts, so we will be sure |
| 921 | * that we are the only ones that configure the HW device |
| 922 | * core and ensure that we queuing the request will finish |
| 923 | * as soon as possible so we will release back the lock. |
| 924 | */ |
| 925 | spin_lock_irqsave(&dwc->lock, flags); |
| 926 | ret = __dwc3_msm_ep_queue(dep, req); |
| 927 | spin_unlock_irqrestore(&dwc->lock, flags); |
| 928 | if (ret < 0) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 929 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 930 | "error %d after calling __dwc3_msm_ep_queue\n", ret); |
| 931 | return ret; |
| 932 | } |
| 933 | |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 934 | speed = dwc3_readl(dwc->regs, DWC3_DSTS) & DWC3_DSTS_CONNECTSPD; |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 935 | dwc3_msm_write_reg(mdwc->base, DBM_GEN_CFG, speed >> 2); |
Shimrit Malichi | a00d732 | 2012-08-05 13:56:28 +0300 | [diff] [blame] | 936 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 937 | return 0; |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * Configure MSM endpoint. |
| 942 | * This function do specific configurations |
| 943 | * to an endpoint which need specific implementaion |
| 944 | * in the MSM architecture. |
| 945 | * |
| 946 | * This function should be called by usb function/class |
| 947 | * layer which need a support from the specific MSM HW |
| 948 | * which wrap the USB3 core. (like DBM specific endpoints) |
| 949 | * |
| 950 | * @ep - a pointer to some usb_ep instance |
| 951 | * |
| 952 | * @return int - 0 on success, negetive on error. |
| 953 | */ |
| 954 | int msm_ep_config(struct usb_ep *ep) |
| 955 | { |
| 956 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 957 | struct dwc3 *dwc = dep->dwc; |
| 958 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 959 | struct usb_ep_ops *new_ep_ops; |
| 960 | |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 961 | dwc3_msm_event_buffer_config(mdwc, |
| 962 | dwc3_msm_read_reg(mdwc->base, DWC3_GEVNTADRLO(0)), |
| 963 | dwc3_msm_read_reg(mdwc->base, DWC3_GEVNTSIZ(0))); |
Manu Gautam | a302f61 | 2012-12-18 17:33:06 +0530 | [diff] [blame] | 964 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 965 | /* Save original ep ops for future restore*/ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 966 | if (mdwc->original_ep_ops[dep->number]) { |
| 967 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 968 | "ep [%s,%d] already configured as msm endpoint\n", |
| 969 | ep->name, dep->number); |
| 970 | return -EPERM; |
| 971 | } |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 972 | mdwc->original_ep_ops[dep->number] = ep->ops; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 973 | |
| 974 | /* Set new usb ops as we like */ |
| 975 | new_ep_ops = kzalloc(sizeof(struct usb_ep_ops), GFP_KERNEL); |
| 976 | if (!new_ep_ops) { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 977 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 978 | "%s: unable to allocate mem for new usb ep ops\n", |
| 979 | __func__); |
| 980 | return -ENOMEM; |
| 981 | } |
| 982 | (*new_ep_ops) = (*ep->ops); |
| 983 | new_ep_ops->queue = dwc3_msm_ep_queue; |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 984 | new_ep_ops->disable = ep->ops->disable; |
| 985 | |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 986 | ep->ops = new_ep_ops; |
| 987 | |
| 988 | /* |
| 989 | * Do HERE more usb endpoint configurations |
| 990 | * which are specific to MSM. |
| 991 | */ |
| 992 | |
| 993 | return 0; |
| 994 | } |
| 995 | EXPORT_SYMBOL(msm_ep_config); |
| 996 | |
| 997 | /** |
| 998 | * Un-configure MSM endpoint. |
| 999 | * Tear down configurations done in the |
| 1000 | * dwc3_msm_ep_config function. |
| 1001 | * |
| 1002 | * @ep - a pointer to some usb_ep instance |
| 1003 | * |
| 1004 | * @return int - 0 on success, negetive on error. |
| 1005 | */ |
| 1006 | int msm_ep_unconfig(struct usb_ep *ep) |
| 1007 | { |
| 1008 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1009 | struct dwc3 *dwc = dep->dwc; |
| 1010 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 1011 | struct usb_ep_ops *old_ep_ops; |
| 1012 | |
| 1013 | /* Restore original ep ops */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1014 | if (!mdwc->original_ep_ops[dep->number]) { |
| 1015 | dev_err(mdwc->dev, |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 1016 | "ep [%s,%d] was not configured as msm endpoint\n", |
| 1017 | ep->name, dep->number); |
| 1018 | return -EINVAL; |
| 1019 | } |
| 1020 | old_ep_ops = (struct usb_ep_ops *)ep->ops; |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1021 | ep->ops = mdwc->original_ep_ops[dep->number]; |
| 1022 | mdwc->original_ep_ops[dep->number] = NULL; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 1023 | kfree(old_ep_ops); |
| 1024 | |
| 1025 | /* |
| 1026 | * Do HERE more usb endpoint un-configurations |
| 1027 | * which are specific to MSM. |
| 1028 | */ |
| 1029 | |
| 1030 | return 0; |
| 1031 | } |
| 1032 | EXPORT_SYMBOL(msm_ep_unconfig); |
| 1033 | |
Vijayavardhan Vennapusa | fc3db60 | 2013-08-20 17:54:54 +0530 | [diff] [blame] | 1034 | void dwc3_tx_fifo_resize_request(struct usb_ep *ep, bool qdss_enabled) |
| 1035 | { |
| 1036 | struct dwc3_ep *dep = to_dwc3_ep(ep); |
| 1037 | struct dwc3 *dwc = dep->dwc; |
| 1038 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
| 1039 | |
| 1040 | if (qdss_enabled) |
| 1041 | dwc->tx_fifo_size = mdwc->qdss_tx_fifo_size; |
| 1042 | else |
| 1043 | dwc->tx_fifo_size = mdwc->tx_fifo_size; |
| 1044 | } |
| 1045 | EXPORT_SYMBOL(dwc3_tx_fifo_resize_request); |
| 1046 | |
Manu Gautam | 6eb13e3 | 2013-02-01 15:19:15 +0530 | [diff] [blame] | 1047 | static void dwc3_restart_usb_work(struct work_struct *w) |
| 1048 | { |
| 1049 | struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, |
| 1050 | restart_usb_work); |
| 1051 | |
| 1052 | dev_dbg(mdwc->dev, "%s\n", __func__); |
| 1053 | |
| 1054 | if (atomic_read(&mdwc->in_lpm) || !mdwc->otg_xceiv) { |
| 1055 | dev_err(mdwc->dev, "%s failed!!!\n", __func__); |
| 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | if (!mdwc->ext_xceiv.bsv) { |
| 1060 | dev_dbg(mdwc->dev, "%s bailing out in disconnect\n", __func__); |
| 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | /* Reset active USB connection */ |
| 1065 | mdwc->ext_xceiv.bsv = false; |
| 1066 | queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0); |
| 1067 | /* Make sure disconnect is processed before sending connect */ |
| 1068 | flush_delayed_work(&mdwc->resume_work); |
| 1069 | |
| 1070 | mdwc->ext_xceiv.bsv = true; |
| 1071 | queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0); |
| 1072 | } |
| 1073 | |
| 1074 | /** |
| 1075 | * Reset USB peripheral connection |
| 1076 | * Inform OTG for Vbus LOW followed by Vbus HIGH notification. |
| 1077 | * This performs full hardware reset and re-initialization which |
| 1078 | * might be required by some DBM client driver during uninit/cleanup. |
| 1079 | */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1080 | void msm_dwc3_restart_usb_session(struct usb_gadget *gadget) |
Manu Gautam | 6eb13e3 | 2013-02-01 15:19:15 +0530 | [diff] [blame] | 1081 | { |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1082 | struct dwc3 *dwc = container_of(gadget, struct dwc3, gadget); |
| 1083 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
| 1084 | |
| 1085 | if (mdwc) |
| 1086 | return; |
Manu Gautam | 6eb13e3 | 2013-02-01 15:19:15 +0530 | [diff] [blame] | 1087 | |
| 1088 | dev_dbg(mdwc->dev, "%s\n", __func__); |
| 1089 | queue_work(system_nrt_wq, &mdwc->restart_usb_work); |
Manu Gautam | 6eb13e3 | 2013-02-01 15:19:15 +0530 | [diff] [blame] | 1090 | } |
| 1091 | EXPORT_SYMBOL(msm_dwc3_restart_usb_session); |
| 1092 | |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 1093 | /** |
| 1094 | * msm_register_usb_ext_notification: register for event notification |
| 1095 | * @info: pointer to client usb_ext_notification structure. May be NULL. |
| 1096 | * |
| 1097 | * @return int - 0 on success, negative on error |
| 1098 | */ |
| 1099 | int msm_register_usb_ext_notification(struct usb_ext_notification *info) |
| 1100 | { |
| 1101 | pr_debug("%s usb_ext: %p\n", __func__, info); |
| 1102 | |
| 1103 | if (info) { |
| 1104 | if (usb_ext) { |
| 1105 | pr_err("%s: already registered\n", __func__); |
| 1106 | return -EEXIST; |
| 1107 | } |
| 1108 | |
| 1109 | if (!info->notify) { |
| 1110 | pr_err("%s: notify is NULL\n", __func__); |
| 1111 | return -EINVAL; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | usb_ext = info; |
| 1116 | return 0; |
| 1117 | } |
| 1118 | EXPORT_SYMBOL(msm_register_usb_ext_notification); |
| 1119 | |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1120 | /* HSPHY */ |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1121 | static int dwc3_hsusb_config_vddcx(struct dwc3_msm *dwc, int high) |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1122 | { |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 1123 | int min_vol, max_vol, ret; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1124 | |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 1125 | max_vol = dwc->vdd_high_vol_level; |
| 1126 | min_vol = high ? dwc->vdd_low_vol_level : dwc->vdd_no_vol_level; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1127 | ret = regulator_set_voltage(dwc->hsusb_vddcx, min_vol, max_vol); |
| 1128 | if (ret) { |
| 1129 | dev_err(dwc->dev, "unable to set voltage for HSUSB_VDDCX\n"); |
| 1130 | return ret; |
| 1131 | } |
| 1132 | |
| 1133 | dev_dbg(dwc->dev, "%s: min_vol:%d max_vol:%d\n", __func__, |
| 1134 | min_vol, max_vol); |
| 1135 | |
| 1136 | return ret; |
| 1137 | } |
| 1138 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1139 | static int dwc3_hsusb_ldo_init(struct dwc3_msm *dwc, int init) |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1140 | { |
| 1141 | int rc = 0; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1142 | |
| 1143 | if (!init) { |
| 1144 | regulator_set_voltage(dwc->hsusb_1p8, 0, USB_HSPHY_1P8_VOL_MAX); |
| 1145 | regulator_set_voltage(dwc->hsusb_3p3, 0, USB_HSPHY_3P3_VOL_MAX); |
| 1146 | return 0; |
| 1147 | } |
| 1148 | |
| 1149 | dwc->hsusb_3p3 = devm_regulator_get(dwc->dev, "HSUSB_3p3"); |
| 1150 | if (IS_ERR(dwc->hsusb_3p3)) { |
| 1151 | dev_err(dwc->dev, "unable to get hsusb 3p3\n"); |
| 1152 | return PTR_ERR(dwc->hsusb_3p3); |
| 1153 | } |
| 1154 | |
| 1155 | rc = regulator_set_voltage(dwc->hsusb_3p3, |
| 1156 | USB_HSPHY_3P3_VOL_MIN, USB_HSPHY_3P3_VOL_MAX); |
| 1157 | if (rc) { |
| 1158 | dev_err(dwc->dev, "unable to set voltage for hsusb 3p3\n"); |
| 1159 | return rc; |
| 1160 | } |
| 1161 | dwc->hsusb_1p8 = devm_regulator_get(dwc->dev, "HSUSB_1p8"); |
| 1162 | if (IS_ERR(dwc->hsusb_1p8)) { |
| 1163 | dev_err(dwc->dev, "unable to get hsusb 1p8\n"); |
| 1164 | rc = PTR_ERR(dwc->hsusb_1p8); |
| 1165 | goto devote_3p3; |
| 1166 | } |
| 1167 | rc = regulator_set_voltage(dwc->hsusb_1p8, |
| 1168 | USB_HSPHY_1P8_VOL_MIN, USB_HSPHY_1P8_VOL_MAX); |
| 1169 | if (rc) { |
| 1170 | dev_err(dwc->dev, "unable to set voltage for hsusb 1p8\n"); |
| 1171 | goto devote_3p3; |
| 1172 | } |
| 1173 | |
| 1174 | return 0; |
| 1175 | |
| 1176 | devote_3p3: |
| 1177 | regulator_set_voltage(dwc->hsusb_3p3, 0, USB_HSPHY_3P3_VOL_MAX); |
| 1178 | |
| 1179 | return rc; |
| 1180 | } |
| 1181 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1182 | static int dwc3_hsusb_ldo_enable(struct dwc3_msm *dwc, int on) |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1183 | { |
| 1184 | int rc = 0; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1185 | |
| 1186 | dev_dbg(dwc->dev, "reg (%s)\n", on ? "HPM" : "LPM"); |
| 1187 | |
| 1188 | if (!on) |
| 1189 | goto disable_regulators; |
| 1190 | |
| 1191 | |
| 1192 | rc = regulator_set_optimum_mode(dwc->hsusb_1p8, USB_HSPHY_1P8_HPM_LOAD); |
| 1193 | if (rc < 0) { |
| 1194 | dev_err(dwc->dev, "Unable to set HPM of regulator HSUSB_1p8\n"); |
| 1195 | return rc; |
| 1196 | } |
| 1197 | |
| 1198 | rc = regulator_enable(dwc->hsusb_1p8); |
| 1199 | if (rc) { |
| 1200 | dev_err(dwc->dev, "Unable to enable HSUSB_1p8\n"); |
| 1201 | goto put_1p8_lpm; |
| 1202 | } |
| 1203 | |
| 1204 | rc = regulator_set_optimum_mode(dwc->hsusb_3p3, USB_HSPHY_3P3_HPM_LOAD); |
| 1205 | if (rc < 0) { |
| 1206 | dev_err(dwc->dev, "Unable to set HPM of regulator HSUSB_3p3\n"); |
| 1207 | goto disable_1p8; |
| 1208 | } |
| 1209 | |
| 1210 | rc = regulator_enable(dwc->hsusb_3p3); |
| 1211 | if (rc) { |
| 1212 | dev_err(dwc->dev, "Unable to enable HSUSB_3p3\n"); |
| 1213 | goto put_3p3_lpm; |
| 1214 | } |
| 1215 | |
| 1216 | return 0; |
| 1217 | |
| 1218 | disable_regulators: |
| 1219 | rc = regulator_disable(dwc->hsusb_3p3); |
| 1220 | if (rc) |
| 1221 | dev_err(dwc->dev, "Unable to disable HSUSB_3p3\n"); |
| 1222 | |
| 1223 | put_3p3_lpm: |
| 1224 | rc = regulator_set_optimum_mode(dwc->hsusb_3p3, 0); |
| 1225 | if (rc < 0) |
| 1226 | dev_err(dwc->dev, "Unable to set LPM of regulator HSUSB_3p3\n"); |
| 1227 | |
| 1228 | disable_1p8: |
| 1229 | rc = regulator_disable(dwc->hsusb_1p8); |
| 1230 | if (rc) |
| 1231 | dev_err(dwc->dev, "Unable to disable HSUSB_1p8\n"); |
| 1232 | |
| 1233 | put_1p8_lpm: |
| 1234 | rc = regulator_set_optimum_mode(dwc->hsusb_1p8, 0); |
| 1235 | if (rc < 0) |
| 1236 | dev_err(dwc->dev, "Unable to set LPM of regulator HSUSB_1p8\n"); |
| 1237 | |
| 1238 | return rc < 0 ? rc : 0; |
| 1239 | } |
| 1240 | |
| 1241 | /* SSPHY */ |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1242 | static int dwc3_ssusb_config_vddcx(struct dwc3_msm *dwc, int high) |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1243 | { |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 1244 | int min_vol, max_vol, ret; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1245 | |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 1246 | max_vol = dwc->vdd_high_vol_level; |
| 1247 | min_vol = high ? dwc->vdd_low_vol_level : dwc->vdd_no_vol_level; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1248 | ret = regulator_set_voltage(dwc->ssusb_vddcx, min_vol, max_vol); |
| 1249 | if (ret) { |
| 1250 | dev_err(dwc->dev, "unable to set voltage for SSUSB_VDDCX\n"); |
| 1251 | return ret; |
| 1252 | } |
| 1253 | |
| 1254 | dev_dbg(dwc->dev, "%s: min_vol:%d max_vol:%d\n", __func__, |
| 1255 | min_vol, max_vol); |
| 1256 | return ret; |
| 1257 | } |
| 1258 | |
| 1259 | /* 3.3v supply not needed for SS PHY */ |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1260 | static int dwc3_ssusb_ldo_init(struct dwc3_msm *dwc, int init) |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1261 | { |
| 1262 | int rc = 0; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1263 | |
| 1264 | if (!init) { |
| 1265 | regulator_set_voltage(dwc->ssusb_1p8, 0, USB_SSPHY_1P8_VOL_MAX); |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | dwc->ssusb_1p8 = devm_regulator_get(dwc->dev, "SSUSB_1p8"); |
| 1270 | if (IS_ERR(dwc->ssusb_1p8)) { |
| 1271 | dev_err(dwc->dev, "unable to get ssusb 1p8\n"); |
| 1272 | return PTR_ERR(dwc->ssusb_1p8); |
| 1273 | } |
| 1274 | rc = regulator_set_voltage(dwc->ssusb_1p8, |
| 1275 | USB_SSPHY_1P8_VOL_MIN, USB_SSPHY_1P8_VOL_MAX); |
| 1276 | if (rc) |
| 1277 | dev_err(dwc->dev, "unable to set voltage for ssusb 1p8\n"); |
| 1278 | |
| 1279 | return rc; |
| 1280 | } |
| 1281 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1282 | static int dwc3_ssusb_ldo_enable(struct dwc3_msm *dwc, int on) |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1283 | { |
| 1284 | int rc = 0; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1285 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1286 | dev_dbg(dwc->dev, "reg (%s)\n", on ? "HPM" : "LPM"); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 1287 | |
| 1288 | if (!on) |
| 1289 | goto disable_regulators; |
| 1290 | |
| 1291 | |
| 1292 | rc = regulator_set_optimum_mode(dwc->ssusb_1p8, USB_SSPHY_1P8_HPM_LOAD); |
| 1293 | if (rc < 0) { |
| 1294 | dev_err(dwc->dev, "Unable to set HPM of SSUSB_1p8\n"); |
| 1295 | return rc; |
| 1296 | } |
| 1297 | |
| 1298 | rc = regulator_enable(dwc->ssusb_1p8); |
| 1299 | if (rc) { |
| 1300 | dev_err(dwc->dev, "Unable to enable SSUSB_1p8\n"); |
| 1301 | goto put_1p8_lpm; |
| 1302 | } |
| 1303 | |
| 1304 | return 0; |
| 1305 | |
| 1306 | disable_regulators: |
| 1307 | rc = regulator_disable(dwc->ssusb_1p8); |
| 1308 | if (rc) |
| 1309 | dev_err(dwc->dev, "Unable to disable SSUSB_1p8\n"); |
| 1310 | |
| 1311 | put_1p8_lpm: |
| 1312 | rc = regulator_set_optimum_mode(dwc->ssusb_1p8, 0); |
| 1313 | if (rc < 0) |
| 1314 | dev_err(dwc->dev, "Unable to set LPM of SSUSB_1p8\n"); |
| 1315 | |
| 1316 | return rc < 0 ? rc : 0; |
| 1317 | } |
| 1318 | |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1319 | /* |
| 1320 | * Config Global Distributed Switch Controller (GDSC) |
| 1321 | * to support controller power collapse |
| 1322 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1323 | static int dwc3_msm_config_gdsc(struct dwc3_msm *mdwc, int on) |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1324 | { |
| 1325 | int ret = 0; |
| 1326 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1327 | if (IS_ERR(mdwc->dwc3_gdsc)) |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1328 | return 0; |
| 1329 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1330 | if (!mdwc->dwc3_gdsc) { |
| 1331 | mdwc->dwc3_gdsc = devm_regulator_get(mdwc->dev, |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1332 | "USB3_GDSC"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1333 | if (IS_ERR(mdwc->dwc3_gdsc)) |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1334 | return 0; |
| 1335 | } |
| 1336 | |
| 1337 | if (on) { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1338 | ret = regulator_enable(mdwc->dwc3_gdsc); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1339 | if (ret) { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1340 | dev_err(mdwc->dev, "unable to enable usb3 gdsc\n"); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1341 | return ret; |
| 1342 | } |
| 1343 | } else { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1344 | regulator_disable(mdwc->dwc3_gdsc); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1350 | static int dwc3_msm_link_clk_reset(struct dwc3_msm *mdwc, bool assert) |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1351 | { |
| 1352 | int ret = 0; |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1353 | |
| 1354 | if (assert) { |
| 1355 | /* Using asynchronous block reset to the hardware */ |
| 1356 | dev_dbg(mdwc->dev, "block_reset ASSERT\n"); |
| 1357 | clk_disable_unprepare(mdwc->ref_clk); |
| 1358 | clk_disable_unprepare(mdwc->iface_clk); |
| 1359 | clk_disable_unprepare(mdwc->core_clk); |
| 1360 | ret = clk_reset(mdwc->core_clk, CLK_RESET_ASSERT); |
| 1361 | if (ret) |
| 1362 | dev_err(mdwc->dev, "dwc3 core_clk assert failed\n"); |
| 1363 | } else { |
| 1364 | dev_dbg(mdwc->dev, "block_reset DEASSERT\n"); |
| 1365 | ret = clk_reset(mdwc->core_clk, CLK_RESET_DEASSERT); |
| 1366 | ndelay(200); |
| 1367 | clk_prepare_enable(mdwc->core_clk); |
| 1368 | clk_prepare_enable(mdwc->ref_clk); |
| 1369 | clk_prepare_enable(mdwc->iface_clk); |
| 1370 | if (ret) |
| 1371 | dev_err(mdwc->dev, "dwc3 core_clk deassert failed\n"); |
| 1372 | } |
| 1373 | |
| 1374 | return ret; |
| 1375 | } |
| 1376 | |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1377 | /* Reinitialize SSPHY parameters by overriding using QSCRATCH CR interface */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1378 | static void dwc3_msm_ss_phy_reg_init(struct dwc3_msm *mdwc) |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1379 | { |
| 1380 | u32 data = 0; |
| 1381 | |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1382 | /* |
| 1383 | * WORKAROUND: There is SSPHY suspend bug due to which USB enumerates |
| 1384 | * in HS mode instead of SS mode. Workaround it by asserting |
| 1385 | * LANE0.TX_ALT_BLOCK.EN_ALT_BUS to enable TX to use alt bus mode |
| 1386 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1387 | data = dwc3_msm_ssusb_read_phycreg(mdwc->base, 0x102D); |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1388 | data |= (1 << 7); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1389 | dwc3_msm_ssusb_write_phycreg(mdwc->base, 0x102D, data); |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1390 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1391 | data = dwc3_msm_ssusb_read_phycreg(mdwc->base, 0x1010); |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1392 | data &= ~0xFF0; |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 1393 | data |= 0x20; |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1394 | dwc3_msm_ssusb_write_phycreg(mdwc->base, 0x1010, data); |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 1395 | |
| 1396 | /* |
| 1397 | * Fix RX Equalization setting as follows |
| 1398 | * LANE0.RX_OVRD_IN_HI. RX_EQ_EN set to 0 |
| 1399 | * LANE0.RX_OVRD_IN_HI.RX_EQ_EN_OVRD set to 1 |
| 1400 | * LANE0.RX_OVRD_IN_HI.RX_EQ set to 3 |
| 1401 | * LANE0.RX_OVRD_IN_HI.RX_EQ_OVRD set to 1 |
| 1402 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1403 | data = dwc3_msm_ssusb_read_phycreg(mdwc->base, 0x1006); |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 1404 | data &= ~(1 << 6); |
| 1405 | data |= (1 << 7); |
| 1406 | data &= ~(0x7 << 8); |
| 1407 | data |= (0x3 << 8); |
| 1408 | data |= (0x1 << 11); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1409 | dwc3_msm_ssusb_write_phycreg(mdwc->base, 0x1006, data); |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 1410 | |
| 1411 | /* |
| 1412 | * Set EQ and TX launch amplitudes as follows |
| 1413 | * LANE0.TX_OVRD_DRV_LO.PREEMPH set to 22 |
| 1414 | * LANE0.TX_OVRD_DRV_LO.AMPLITUDE set to 127 |
| 1415 | * LANE0.TX_OVRD_DRV_LO.EN set to 1. |
| 1416 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1417 | data = dwc3_msm_ssusb_read_phycreg(mdwc->base, 0x1002); |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 1418 | data &= ~0x3F80; |
| 1419 | data |= (0x16 << 7); |
| 1420 | data &= ~0x7F; |
| 1421 | data |= (0x7F | (1 << 14)); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1422 | dwc3_msm_ssusb_write_phycreg(mdwc->base, 0x1002, data); |
Vijayavardhan Vennapusa | 164b0f4 | 2013-01-17 19:33:53 +0530 | [diff] [blame] | 1423 | |
Jack Pham | 63c8c70 | 2013-04-24 19:21:33 -0700 | [diff] [blame] | 1424 | /* |
| 1425 | * Set the QSCRATCH SS_PHY_PARAM_CTRL1 parameters as follows |
| 1426 | * TX_FULL_SWING [26:20] amplitude to 127 |
| 1427 | * TX_DEEMPH_3_5DB [13:8] to 22 |
| 1428 | * LOS_BIAS [2:0] to 0x5 |
| 1429 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1430 | dwc3_msm_write_readback(mdwc->base, SS_PHY_PARAM_CTRL_1, |
Jack Pham | 63c8c70 | 2013-04-24 19:21:33 -0700 | [diff] [blame] | 1431 | 0x07f03f07, 0x07f01605); |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1432 | } |
| 1433 | |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1434 | /* Initialize QSCRATCH registers for HSPHY and SSPHY operation */ |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1435 | static void dwc3_msm_qscratch_reg_init(struct dwc3_msm *mdwc, |
| 1436 | unsigned event_status) |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1437 | { |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1438 | if (event_status == DWC3_CONTROLLER_POST_RESET_EVENT) { |
| 1439 | dwc3_msm_ss_phy_reg_init(mdwc); |
| 1440 | return; |
| 1441 | } |
| 1442 | |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1443 | /* SSPHY Initialization: Use ref_clk from pads and set its parameters */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1444 | dwc3_msm_write_reg(mdwc->base, SS_PHY_CTRL_REG, 0x10210002); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1445 | msleep(30); |
| 1446 | /* Assert SSPHY reset */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1447 | dwc3_msm_write_reg(mdwc->base, SS_PHY_CTRL_REG, 0x10210082); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1448 | usleep_range(2000, 2200); |
| 1449 | /* De-assert SSPHY reset - power and ref_clock must be ON */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1450 | dwc3_msm_write_reg(mdwc->base, SS_PHY_CTRL_REG, 0x10210002); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1451 | usleep_range(2000, 2200); |
| 1452 | /* Ref clock must be stable now, enable ref clock for HS mode */ |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1453 | dwc3_msm_write_reg(mdwc->base, SS_PHY_CTRL_REG, 0x11210102); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1454 | usleep_range(2000, 2200); |
| 1455 | /* |
| 1456 | * HSPHY Initialization: Enable UTMI clock and clamp enable HVINTs, |
| 1457 | * and disable RETENTION (power-on default is ENABLED) |
| 1458 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1459 | dwc3_msm_write_reg(mdwc->base, HS_PHY_CTRL_REG, 0x5220bb2); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1460 | usleep_range(2000, 2200); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1461 | /* Set XHCI_REV bit (2) to 1 - XHCI version 1.0 */ |
| 1462 | dwc3_msm_write_reg(mdwc->base, QSCRATCH_GENERAL_CFG, 0x4); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1463 | /* |
| 1464 | * write HSPHY init value to QSCRATCH reg to set HSPHY parameters like |
| 1465 | * VBUS valid threshold, disconnect valid threshold, DC voltage level, |
| 1466 | * preempasis and rise/fall time. |
| 1467 | */ |
| 1468 | if (override_phy_init) |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1469 | mdwc->hsphy_init_seq = override_phy_init; |
| 1470 | if (mdwc->hsphy_init_seq) |
| 1471 | dwc3_msm_write_readback(mdwc->base, |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1472 | PARAMETER_OVERRIDE_X_REG, 0x03FFFFFF, |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1473 | mdwc->hsphy_init_seq & 0x03FFFFFF); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1474 | |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1475 | /* |
| 1476 | * Enable master clock for RAMs to allow BAM to access RAMs when |
| 1477 | * RAM clock gating is enabled via DWC3's GCTL. Otherwise issues |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1478 | * are seen where RAM clocks get turned OFF in SS mode |
| 1479 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1480 | dwc3_msm_write_reg(mdwc->base, CGCTL_REG, |
| 1481 | dwc3_msm_read_reg(mdwc->base, CGCTL_REG) | 0x18); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1482 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 1483 | /* |
| 1484 | * This is required to restore the POR value after userspace |
| 1485 | * is done with charger detection. |
| 1486 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 1487 | mdwc->qscratch_ctl_val = |
| 1488 | dwc3_msm_read_reg(mdwc->base, QSCRATCH_CTRL_REG); |
Vijayavardhan Vennapusa | 5b28632 | 2013-04-12 12:15:00 +0530 | [diff] [blame] | 1489 | } |
| 1490 | |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 1491 | static void dwc3_msm_notify_event(struct dwc3 *dwc, unsigned event) |
| 1492 | { |
| 1493 | struct dwc3_msm *mdwc = dev_get_drvdata(dwc->dev->parent); |
| 1494 | |
| 1495 | switch (event) { |
| 1496 | case DWC3_CONTROLLER_ERROR_EVENT: |
| 1497 | dev_info(mdwc->dev, "DWC3_CONTROLLER_ERROR_EVENT received\n"); |
| 1498 | dwc3_msm_dump_phy_info(mdwc); |
Vijayavardhan Vennapusa | ddd0474 | 2013-09-26 19:47:18 +0530 | [diff] [blame] | 1499 | /* |
| 1500 | * schedule work for doing block reset for recovery from erratic |
| 1501 | * error event. |
| 1502 | */ |
| 1503 | queue_work(system_nrt_wq, &mdwc->usb_block_reset_work); |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 1504 | break; |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1505 | case DWC3_CONTROLLER_RESET_EVENT: |
| 1506 | dev_dbg(mdwc->dev, "DWC3_CONTROLLER_RESET_EVENT received\n"); |
| 1507 | dwc3_msm_qscratch_reg_init(mdwc, DWC3_CONTROLLER_RESET_EVENT); |
| 1508 | break; |
| 1509 | case DWC3_CONTROLLER_POST_RESET_EVENT: |
| 1510 | dev_dbg(mdwc->dev, |
| 1511 | "DWC3_CONTROLLER_POST_RESET_EVENT received\n"); |
| 1512 | dwc3_msm_qscratch_reg_init(mdwc, |
| 1513 | DWC3_CONTROLLER_POST_RESET_EVENT); |
Vijayavardhan Vennapusa | fc3db60 | 2013-08-20 17:54:54 +0530 | [diff] [blame] | 1514 | dwc->tx_fifo_size = mdwc->tx_fifo_size; |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1515 | break; |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 1516 | default: |
| 1517 | dev_dbg(mdwc->dev, "unknown dwc3 event\n"); |
| 1518 | break; |
| 1519 | } |
| 1520 | } |
| 1521 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1522 | static void dwc3_msm_block_reset(struct dwc3_ext_xceiv *xceiv, bool core_reset) |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1523 | { |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1524 | struct dwc3_msm *mdwc = container_of(xceiv, struct dwc3_msm, ext_xceiv); |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1525 | int ret = 0; |
| 1526 | |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 1527 | if (core_reset) { |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1528 | ret = dwc3_msm_link_clk_reset(mdwc, 1); |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 1529 | if (ret) |
| 1530 | return; |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1531 | |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 1532 | usleep_range(1000, 1200); |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1533 | ret = dwc3_msm_link_clk_reset(mdwc, 0); |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 1534 | if (ret) |
| 1535 | return; |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1536 | |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 1537 | usleep_range(10000, 12000); |
Vijayavardhan Vennapusa | f7c01a4 | 2013-03-15 15:29:11 +0530 | [diff] [blame] | 1538 | } |
Manu Gautam | a302f61 | 2012-12-18 17:33:06 +0530 | [diff] [blame] | 1539 | |
| 1540 | /* Reset the DBM */ |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1541 | dwc3_msm_dbm_soft_reset(mdwc, 1); |
Manu Gautam | a302f61 | 2012-12-18 17:33:06 +0530 | [diff] [blame] | 1542 | usleep_range(1000, 1200); |
Jack Pham | 62c19a4 | 2013-07-09 17:55:09 -0700 | [diff] [blame] | 1543 | dwc3_msm_dbm_soft_reset(mdwc, 0); |
Vijayavardhan Vennapusa | b743456 | 2012-12-12 16:48:49 +0530 | [diff] [blame] | 1544 | } |
| 1545 | |
Vijayavardhan Vennapusa | ddd0474 | 2013-09-26 19:47:18 +0530 | [diff] [blame] | 1546 | static void dwc3_block_reset_usb_work(struct work_struct *w) |
| 1547 | { |
| 1548 | struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, |
| 1549 | usb_block_reset_work); |
| 1550 | |
| 1551 | dev_dbg(mdwc->dev, "%s\n", __func__); |
| 1552 | |
| 1553 | dwc3_msm_block_reset(&mdwc->ext_xceiv, true); |
| 1554 | } |
| 1555 | |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1556 | static void dwc3_chg_enable_secondary_det(struct dwc3_msm *mdwc) |
| 1557 | { |
| 1558 | u32 chg_ctrl; |
| 1559 | |
| 1560 | /* Turn off VDP_SRC */ |
| 1561 | dwc3_msm_write_reg(mdwc->base, CHARGING_DET_CTRL_REG, 0x0); |
| 1562 | msleep(20); |
| 1563 | |
| 1564 | /* Before proceeding make sure VDP_SRC is OFF */ |
| 1565 | chg_ctrl = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_CTRL_REG); |
| 1566 | if (chg_ctrl & 0x3F) |
| 1567 | dev_err(mdwc->dev, "%s Unable to reset chg_det block: %x\n", |
| 1568 | __func__, chg_ctrl); |
| 1569 | /* |
| 1570 | * Configure DM as current source, DP as current sink |
| 1571 | * and enable battery charging comparators. |
| 1572 | */ |
| 1573 | dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x34); |
| 1574 | } |
| 1575 | |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1576 | static bool dwc3_chg_det_check_linestate(struct dwc3_msm *mdwc) |
| 1577 | { |
| 1578 | u32 chg_det; |
Jack Pham | 9b4606b | 2013-04-02 17:32:25 -0700 | [diff] [blame] | 1579 | |
| 1580 | if (!prop_chg_detect) |
| 1581 | return false; |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1582 | |
| 1583 | chg_det = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG); |
Jack Pham | 9b4606b | 2013-04-02 17:32:25 -0700 | [diff] [blame] | 1584 | return chg_det & (3 << 8); |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1585 | } |
| 1586 | |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1587 | static bool dwc3_chg_det_check_output(struct dwc3_msm *mdwc) |
| 1588 | { |
| 1589 | u32 chg_det; |
| 1590 | bool ret = false; |
| 1591 | |
| 1592 | chg_det = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG); |
| 1593 | ret = chg_det & 1; |
| 1594 | |
| 1595 | return ret; |
| 1596 | } |
| 1597 | |
| 1598 | static void dwc3_chg_enable_primary_det(struct dwc3_msm *mdwc) |
| 1599 | { |
| 1600 | /* |
| 1601 | * Configure DP as current source, DM as current sink |
| 1602 | * and enable battery charging comparators. |
| 1603 | */ |
| 1604 | dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x30); |
| 1605 | } |
| 1606 | |
| 1607 | static inline bool dwc3_chg_check_dcd(struct dwc3_msm *mdwc) |
| 1608 | { |
| 1609 | u32 chg_state; |
| 1610 | bool ret = false; |
| 1611 | |
| 1612 | chg_state = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_OUTPUT_REG); |
| 1613 | ret = chg_state & 2; |
| 1614 | |
| 1615 | return ret; |
| 1616 | } |
| 1617 | |
| 1618 | static inline void dwc3_chg_disable_dcd(struct dwc3_msm *mdwc) |
| 1619 | { |
| 1620 | dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x0); |
| 1621 | } |
| 1622 | |
| 1623 | static inline void dwc3_chg_enable_dcd(struct dwc3_msm *mdwc) |
| 1624 | { |
| 1625 | /* Data contact detection enable, DCDENB */ |
| 1626 | dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, 0x3F, 0x2); |
| 1627 | } |
| 1628 | |
| 1629 | static void dwc3_chg_block_reset(struct dwc3_msm *mdwc) |
| 1630 | { |
| 1631 | u32 chg_ctrl; |
| 1632 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 1633 | dwc3_msm_write_reg(mdwc->base, QSCRATCH_CTRL_REG, |
| 1634 | mdwc->qscratch_ctl_val); |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1635 | /* Clear charger detecting control bits */ |
| 1636 | dwc3_msm_write_reg(mdwc->base, CHARGING_DET_CTRL_REG, 0x0); |
| 1637 | |
| 1638 | /* Clear alt interrupt latch and enable bits */ |
| 1639 | dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0xFFF); |
| 1640 | dwc3_msm_write_reg(mdwc->base, ALT_INTERRUPT_EN_REG, 0x0); |
| 1641 | |
| 1642 | udelay(100); |
| 1643 | |
| 1644 | /* Before proceeding make sure charger block is RESET */ |
| 1645 | chg_ctrl = dwc3_msm_read_reg(mdwc->base, CHARGING_DET_CTRL_REG); |
| 1646 | if (chg_ctrl & 0x3F) |
| 1647 | dev_err(mdwc->dev, "%s Unable to reset chg_det block: %x\n", |
| 1648 | __func__, chg_ctrl); |
| 1649 | } |
| 1650 | |
| 1651 | static const char *chg_to_string(enum dwc3_chg_type chg_type) |
| 1652 | { |
| 1653 | switch (chg_type) { |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1654 | case DWC3_SDP_CHARGER: return "USB_SDP_CHARGER"; |
| 1655 | case DWC3_DCP_CHARGER: return "USB_DCP_CHARGER"; |
| 1656 | case DWC3_CDP_CHARGER: return "USB_CDP_CHARGER"; |
| 1657 | case DWC3_PROPRIETARY_CHARGER: return "USB_PROPRIETARY_CHARGER"; |
Vijayavardhan Vennapusa | b11d7fd | 2013-07-01 16:40:57 +0530 | [diff] [blame] | 1658 | case DWC3_FLOATED_CHARGER: return "USB_FLOATED_CHARGER"; |
Vijayavardhan Vennapusa | a04e0c9 | 2013-06-04 12:37:10 +0530 | [diff] [blame] | 1659 | default: return "UNKNOWN_CHARGER"; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | #define DWC3_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */ |
| 1664 | #define DWC3_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */ |
| 1665 | #define DWC3_CHG_PRIMARY_DET_TIME (50 * HZ/1000) /* TVDPSRC_ON */ |
| 1666 | #define DWC3_CHG_SECONDARY_DET_TIME (50 * HZ/1000) /* TVDMSRC_ON */ |
| 1667 | |
| 1668 | static void dwc3_chg_detect_work(struct work_struct *w) |
| 1669 | { |
| 1670 | struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, chg_work.work); |
| 1671 | bool is_dcd = false, tmout, vout; |
Vijayavardhan Vennapusa | b11d7fd | 2013-07-01 16:40:57 +0530 | [diff] [blame] | 1672 | static bool dcd; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1673 | unsigned long delay; |
| 1674 | |
| 1675 | dev_dbg(mdwc->dev, "chg detection work\n"); |
| 1676 | switch (mdwc->chg_state) { |
| 1677 | case USB_CHG_STATE_UNDEFINED: |
| 1678 | dwc3_chg_block_reset(mdwc); |
| 1679 | dwc3_chg_enable_dcd(mdwc); |
| 1680 | mdwc->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 1681 | mdwc->dcd_retries = 0; |
| 1682 | delay = DWC3_CHG_DCD_POLL_TIME; |
| 1683 | break; |
| 1684 | case USB_CHG_STATE_WAIT_FOR_DCD: |
| 1685 | is_dcd = dwc3_chg_check_dcd(mdwc); |
| 1686 | tmout = ++mdwc->dcd_retries == DWC3_CHG_DCD_MAX_RETRIES; |
| 1687 | if (is_dcd || tmout) { |
Vijayavardhan Vennapusa | b11d7fd | 2013-07-01 16:40:57 +0530 | [diff] [blame] | 1688 | if (is_dcd) |
| 1689 | dcd = true; |
| 1690 | else |
| 1691 | dcd = false; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1692 | dwc3_chg_disable_dcd(mdwc); |
Vijayavardhan Vennapusa | b11d7fd | 2013-07-01 16:40:57 +0530 | [diff] [blame] | 1693 | usleep_range(1000, 1200); |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1694 | if (dwc3_chg_det_check_linestate(mdwc)) { |
Vijayavardhan Vennapusa | b11d7fd | 2013-07-01 16:40:57 +0530 | [diff] [blame] | 1695 | mdwc->charger.chg_type = |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1696 | DWC3_PROPRIETARY_CHARGER; |
| 1697 | mdwc->chg_state = USB_CHG_STATE_DETECTED; |
| 1698 | delay = 0; |
| 1699 | break; |
| 1700 | } |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1701 | dwc3_chg_enable_primary_det(mdwc); |
| 1702 | delay = DWC3_CHG_PRIMARY_DET_TIME; |
| 1703 | mdwc->chg_state = USB_CHG_STATE_DCD_DONE; |
| 1704 | } else { |
| 1705 | delay = DWC3_CHG_DCD_POLL_TIME; |
| 1706 | } |
| 1707 | break; |
| 1708 | case USB_CHG_STATE_DCD_DONE: |
| 1709 | vout = dwc3_chg_det_check_output(mdwc); |
| 1710 | if (vout) { |
| 1711 | dwc3_chg_enable_secondary_det(mdwc); |
| 1712 | delay = DWC3_CHG_SECONDARY_DET_TIME; |
| 1713 | mdwc->chg_state = USB_CHG_STATE_PRIMARY_DONE; |
| 1714 | } else { |
Vijayavardhan Vennapusa | b11d7fd | 2013-07-01 16:40:57 +0530 | [diff] [blame] | 1715 | /* |
| 1716 | * Detect floating charger only if propreitary |
| 1717 | * charger detection is enabled. |
| 1718 | */ |
| 1719 | if (!dcd && prop_chg_detect) |
| 1720 | mdwc->charger.chg_type = |
| 1721 | DWC3_FLOATED_CHARGER; |
| 1722 | else |
| 1723 | mdwc->charger.chg_type = DWC3_SDP_CHARGER; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1724 | mdwc->chg_state = USB_CHG_STATE_DETECTED; |
| 1725 | delay = 0; |
| 1726 | } |
| 1727 | break; |
| 1728 | case USB_CHG_STATE_PRIMARY_DONE: |
| 1729 | vout = dwc3_chg_det_check_output(mdwc); |
| 1730 | if (vout) |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1731 | mdwc->charger.chg_type = DWC3_DCP_CHARGER; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1732 | else |
Manu Gautam | a1e331d | 2013-02-07 14:55:05 +0530 | [diff] [blame] | 1733 | mdwc->charger.chg_type = DWC3_CDP_CHARGER; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1734 | mdwc->chg_state = USB_CHG_STATE_SECONDARY_DONE; |
| 1735 | /* fall through */ |
| 1736 | case USB_CHG_STATE_SECONDARY_DONE: |
| 1737 | mdwc->chg_state = USB_CHG_STATE_DETECTED; |
| 1738 | /* fall through */ |
| 1739 | case USB_CHG_STATE_DETECTED: |
| 1740 | dwc3_chg_block_reset(mdwc); |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1741 | /* Enable VDP_SRC */ |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 1742 | if (mdwc->charger.chg_type == DWC3_DCP_CHARGER) { |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1743 | dwc3_msm_write_readback(mdwc->base, |
| 1744 | CHARGING_DET_CTRL_REG, 0x1F, 0x10); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 1745 | if (mdwc->ext_chg_opened) { |
| 1746 | init_completion(&mdwc->ext_chg_wait); |
| 1747 | mdwc->ext_chg_active = true; |
| 1748 | } |
| 1749 | } |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1750 | dev_dbg(mdwc->dev, "chg_type = %s\n", |
| 1751 | chg_to_string(mdwc->charger.chg_type)); |
| 1752 | mdwc->charger.notify_detection_complete(mdwc->otg_xceiv->otg, |
| 1753 | &mdwc->charger); |
| 1754 | return; |
| 1755 | default: |
| 1756 | return; |
| 1757 | } |
| 1758 | |
| 1759 | queue_delayed_work(system_nrt_wq, &mdwc->chg_work, delay); |
| 1760 | } |
| 1761 | |
| 1762 | static void dwc3_start_chg_det(struct dwc3_charger *charger, bool start) |
| 1763 | { |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 1764 | struct dwc3_msm *mdwc = container_of(charger, struct dwc3_msm, charger); |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1765 | |
| 1766 | if (start == false) { |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 1767 | dev_dbg(mdwc->dev, "canceling charging detection work\n"); |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 1768 | cancel_delayed_work_sync(&mdwc->chg_work); |
| 1769 | mdwc->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1770 | charger->chg_type = DWC3_INVALID_CHARGER; |
| 1771 | return; |
| 1772 | } |
| 1773 | |
| 1774 | mdwc->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1775 | charger->chg_type = DWC3_INVALID_CHARGER; |
| 1776 | queue_delayed_work(system_nrt_wq, &mdwc->chg_work, 0); |
| 1777 | } |
| 1778 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1779 | static int dwc3_msm_suspend(struct dwc3_msm *mdwc) |
| 1780 | { |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 1781 | int ret; |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1782 | bool dcp; |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1783 | bool host_bus_suspend; |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1784 | bool host_ss_active; |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1785 | bool host_ss_suspend; |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 1786 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1787 | dev_dbg(mdwc->dev, "%s: entering lpm\n", __func__); |
| 1788 | |
| 1789 | if (atomic_read(&mdwc->in_lpm)) { |
| 1790 | dev_dbg(mdwc->dev, "%s: Already suspended\n", __func__); |
| 1791 | return 0; |
| 1792 | } |
| 1793 | |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1794 | host_ss_active = dwc3_msm_read_reg(mdwc->base, USB3_PORTSC) & PORT_PE; |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1795 | if (mdwc->hs_phy_irq) |
| 1796 | disable_irq(mdwc->hs_phy_irq); |
| 1797 | |
Manu Gautam | 98013c2 | 2012-11-20 17:42:42 +0530 | [diff] [blame] | 1798 | if (cancel_delayed_work_sync(&mdwc->chg_work)) |
| 1799 | dev_dbg(mdwc->dev, "%s: chg_work was pending\n", __func__); |
| 1800 | if (mdwc->chg_state != USB_CHG_STATE_DETECTED) { |
| 1801 | /* charger detection wasn't complete; re-init flags */ |
| 1802 | mdwc->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1803 | mdwc->charger.chg_type = DWC3_INVALID_CHARGER; |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1804 | dwc3_msm_write_readback(mdwc->base, CHARGING_DET_CTRL_REG, |
| 1805 | 0x37, 0x0); |
Manu Gautam | 98013c2 | 2012-11-20 17:42:42 +0530 | [diff] [blame] | 1806 | } |
| 1807 | |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 1808 | dcp = ((mdwc->charger.chg_type == DWC3_DCP_CHARGER) || |
Vijayavardhan Vennapusa | c497486 | 2013-07-23 17:36:37 +0530 | [diff] [blame] | 1809 | (mdwc->charger.chg_type == DWC3_PROPRIETARY_CHARGER) || |
| 1810 | (mdwc->charger.chg_type == DWC3_FLOATED_CHARGER)); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1811 | host_bus_suspend = mdwc->host_mode == 1; |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1812 | host_ss_suspend = host_bus_suspend && host_ss_active; |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1813 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 1814 | if (!dcp && !host_bus_suspend) |
| 1815 | dwc3_msm_write_reg(mdwc->base, QSCRATCH_CTRL_REG, |
| 1816 | mdwc->qscratch_ctl_val); |
| 1817 | |
Vijayavardhan Vennapusa | 4188de2 | 2012-11-06 15:20:18 +0530 | [diff] [blame] | 1818 | /* Sequence to put SSPHY in low power state: |
| 1819 | * 1. Clear REF_SS_PHY_EN in SS_PHY_CTRL_REG |
| 1820 | * 2. Clear REF_USE_PAD in SS_PHY_CTRL_REG |
| 1821 | * 3. Set TEST_POWERED_DOWN in SS_PHY_CTRL_REG to enable PHY retention |
| 1822 | * 4. Disable SSPHY ref clk |
| 1823 | */ |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1824 | if (!host_ss_suspend) { |
| 1825 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 8), |
| 1826 | 0x0); |
| 1827 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 28), |
| 1828 | 0x0); |
| 1829 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 26), |
Vijayavardhan Vennapusa | 4188de2 | 2012-11-06 15:20:18 +0530 | [diff] [blame] | 1830 | (1 << 26)); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1831 | } |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1832 | usleep_range(1000, 1200); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1833 | if (!host_ss_suspend) |
| 1834 | clk_disable_unprepare(mdwc->ref_clk); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1835 | |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1836 | if (host_bus_suspend) { |
| 1837 | /* Sequence for host bus suspend case: |
| 1838 | * 1. Set suspend and sleep bits in GUSB2PHYCONFIG reg |
| 1839 | * 2. Clear interrupt latch register and enable BSV, ID HV intr |
| 1840 | * 3. Enable DP and DM HV interrupts in ALT_INTERRUPT_EN_REG |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1841 | */ |
| 1842 | dwc3_msm_write_reg(mdwc->base, DWC3_GUSB2PHYCFG(0), |
| 1843 | dwc3_msm_read_reg(mdwc->base, DWC3_GUSB2PHYCFG(0)) | |
| 1844 | 0x00000140); |
| 1845 | dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0xFFF); |
| 1846 | if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability)) |
| 1847 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, |
| 1848 | 0x18000, 0x18000); |
Vijayavardhan Vennapusa | 98bccc5 | 2013-01-24 13:07:34 +0530 | [diff] [blame] | 1849 | dwc3_msm_write_reg(mdwc->base, ALT_INTERRUPT_EN_REG, 0xFC0); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1850 | udelay(5); |
| 1851 | } else { |
| 1852 | /* Sequence to put hardware in low power state: |
| 1853 | * 1. Set OTGDISABLE to disable OTG block in HSPHY (saves power) |
| 1854 | * 2. Clear charger detection control fields (performed above) |
| 1855 | * 3. SUSPEND PHY and turn OFF core clock after some delay |
| 1856 | * 4. Clear interrupt latch register and enable BSV, ID HV intr |
| 1857 | * 5. Enable PHY retention |
| 1858 | */ |
| 1859 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, 0x1000, |
| 1860 | 0x1000); |
| 1861 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, |
| 1862 | 0xC00000, 0x800000); |
| 1863 | dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0xFFF); |
| 1864 | if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability)) |
| 1865 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, |
| 1866 | 0x18000, 0x18000); |
| 1867 | if (!dcp) |
| 1868 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, |
| 1869 | 0x2, 0x0); |
| 1870 | } |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1871 | |
| 1872 | /* make sure above writes are completed before turning off clocks */ |
| 1873 | wmb(); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1874 | |
| 1875 | /* remove vote for controller power collapse */ |
| 1876 | if (!host_bus_suspend) |
| 1877 | dwc3_msm_config_gdsc(mdwc, 0); |
| 1878 | |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1879 | if (!host_ss_suspend) { |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1880 | clk_disable_unprepare(mdwc->core_clk); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1881 | mdwc->lpm_flags |= MDWC3_PHY_REF_AND_CORECLK_OFF; |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1882 | } |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1883 | clk_disable_unprepare(mdwc->iface_clk); |
| 1884 | |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1885 | if (!host_bus_suspend) |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 1886 | clk_disable_unprepare(mdwc->utmi_clk); |
| 1887 | |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1888 | if (!host_bus_suspend) { |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 1889 | /* USB PHY no more requires TCXO */ |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 1890 | clk_disable_unprepare(mdwc->xo_clk); |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1891 | mdwc->lpm_flags |= MDWC3_TCXO_SHUTDOWN; |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 1892 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1893 | |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 1894 | if (mdwc->bus_perf_client) { |
| 1895 | ret = msm_bus_scale_client_update_request( |
| 1896 | mdwc->bus_perf_client, 0); |
| 1897 | if (ret) |
| 1898 | dev_err(mdwc->dev, "Failed to reset bus bw vote\n"); |
| 1899 | } |
| 1900 | |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1901 | if (mdwc->otg_xceiv && mdwc->ext_xceiv.otg_capability && !dcp && |
| 1902 | !host_bus_suspend) |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1903 | dwc3_hsusb_ldo_enable(mdwc, 0); |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 1904 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1905 | dwc3_ssusb_ldo_enable(mdwc, 0); |
| 1906 | dwc3_ssusb_config_vddcx(mdwc, 0); |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 1907 | if (!host_bus_suspend && !dcp) |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1908 | dwc3_hsusb_config_vddcx(mdwc, 0); |
Jack Pham | 924cbe87 | 2013-07-10 16:40:55 -0700 | [diff] [blame] | 1909 | pm_relax(mdwc->dev); |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1910 | atomic_set(&mdwc->in_lpm, 1); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1911 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1912 | dev_info(mdwc->dev, "DWC3 in low power mode\n"); |
| 1913 | |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 1914 | if (mdwc->hs_phy_irq) { |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1915 | enable_irq(mdwc->hs_phy_irq); |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 1916 | /* with DCP we dont require wakeup using HS_PHY_IRQ */ |
| 1917 | if (dcp) |
| 1918 | disable_irq_wake(mdwc->hs_phy_irq); |
| 1919 | } |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1920 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1921 | return 0; |
| 1922 | } |
| 1923 | |
| 1924 | static int dwc3_msm_resume(struct dwc3_msm *mdwc) |
| 1925 | { |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 1926 | int ret; |
Manu Gautam | a48296e | 2012-12-05 17:37:56 +0530 | [diff] [blame] | 1927 | bool dcp; |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1928 | bool host_bus_suspend; |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1929 | bool resume_from_core_clk_off = false; |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 1930 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 1931 | dev_dbg(mdwc->dev, "%s: exiting lpm\n", __func__); |
| 1932 | |
| 1933 | if (!atomic_read(&mdwc->in_lpm)) { |
| 1934 | dev_dbg(mdwc->dev, "%s: Already resumed\n", __func__); |
| 1935 | return 0; |
| 1936 | } |
| 1937 | |
Jack Pham | 924cbe87 | 2013-07-10 16:40:55 -0700 | [diff] [blame] | 1938 | pm_stay_awake(mdwc->dev); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1939 | |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1940 | if (mdwc->lpm_flags & MDWC3_PHY_REF_AND_CORECLK_OFF) |
| 1941 | resume_from_core_clk_off = true; |
| 1942 | |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 1943 | if (mdwc->bus_perf_client) { |
| 1944 | ret = msm_bus_scale_client_update_request( |
| 1945 | mdwc->bus_perf_client, 1); |
| 1946 | if (ret) |
| 1947 | dev_err(mdwc->dev, "Failed to vote for bus scaling\n"); |
| 1948 | } |
| 1949 | |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 1950 | dcp = ((mdwc->charger.chg_type == DWC3_DCP_CHARGER) || |
Vijayavardhan Vennapusa | c497486 | 2013-07-23 17:36:37 +0530 | [diff] [blame] | 1951 | (mdwc->charger.chg_type == DWC3_PROPRIETARY_CHARGER) || |
| 1952 | (mdwc->charger.chg_type == DWC3_FLOATED_CHARGER)); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1953 | host_bus_suspend = mdwc->host_mode == 1; |
Vijayavardhan Vennapusa | 98bccc5 | 2013-01-24 13:07:34 +0530 | [diff] [blame] | 1954 | |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1955 | if (mdwc->lpm_flags & MDWC3_TCXO_SHUTDOWN) { |
Vijayavardhan Vennapusa | 98bccc5 | 2013-01-24 13:07:34 +0530 | [diff] [blame] | 1956 | /* Vote for TCXO while waking up USB HSPHY */ |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 1957 | ret = clk_prepare_enable(mdwc->xo_clk); |
Vijayavardhan Vennapusa | 98bccc5 | 2013-01-24 13:07:34 +0530 | [diff] [blame] | 1958 | if (ret) |
| 1959 | dev_err(mdwc->dev, "%s failed to vote TCXO buffer%d\n", |
| 1960 | __func__, ret); |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1961 | mdwc->lpm_flags &= ~MDWC3_TCXO_SHUTDOWN; |
Vijayavardhan Vennapusa | 98bccc5 | 2013-01-24 13:07:34 +0530 | [diff] [blame] | 1962 | } |
| 1963 | |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 1964 | /* add vote for controller power collapse */ |
| 1965 | if (!host_bus_suspend) |
| 1966 | dwc3_msm_config_gdsc(mdwc, 1); |
| 1967 | |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1968 | if (!host_bus_suspend) |
| 1969 | clk_prepare_enable(mdwc->utmi_clk); |
| 1970 | |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1971 | if (mdwc->otg_xceiv && mdwc->ext_xceiv.otg_capability && !dcp && |
| 1972 | !host_bus_suspend) |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1973 | dwc3_hsusb_ldo_enable(mdwc, 1); |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 1974 | |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1975 | dwc3_ssusb_ldo_enable(mdwc, 1); |
| 1976 | dwc3_ssusb_config_vddcx(mdwc, 1); |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 1977 | |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 1978 | if (!host_bus_suspend && !dcp) |
Jack Pham | 4b00e70 | 2013-07-03 17:10:36 -0700 | [diff] [blame] | 1979 | dwc3_hsusb_config_vddcx(mdwc, 1); |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 1980 | |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1981 | if (mdwc->lpm_flags & MDWC3_PHY_REF_AND_CORECLK_OFF) |
| 1982 | clk_prepare_enable(mdwc->ref_clk); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1983 | usleep_range(1000, 1200); |
| 1984 | |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 1985 | clk_prepare_enable(mdwc->iface_clk); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1986 | if (mdwc->lpm_flags & MDWC3_PHY_REF_AND_CORECLK_OFF) { |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1987 | clk_prepare_enable(mdwc->core_clk); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 1988 | mdwc->lpm_flags &= ~MDWC3_PHY_REF_AND_CORECLK_OFF; |
Vijayavardhan Vennapusa | a00a506 | 2013-04-19 12:31:07 +0530 | [diff] [blame] | 1989 | } |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1990 | |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1991 | if (host_bus_suspend) { |
| 1992 | /* Disable HV interrupt */ |
| 1993 | if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability)) |
| 1994 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, |
| 1995 | 0x18000, 0x0); |
| 1996 | /* Clear interrupt latch register */ |
| 1997 | dwc3_msm_write_reg(mdwc->base, HS_PHY_IRQ_STAT_REG, 0x000); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 1998 | |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 1999 | /* Disable DP and DM HV interrupt */ |
| 2000 | dwc3_msm_write_reg(mdwc->base, ALT_INTERRUPT_EN_REG, 0x000); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 2001 | } else { |
| 2002 | /* Disable HV interrupt */ |
| 2003 | if (mdwc->otg_xceiv && (!mdwc->ext_xceiv.otg_capability)) |
| 2004 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, |
| 2005 | 0x18000, 0x0); |
| 2006 | /* Disable Retention */ |
| 2007 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, 0x2, 0x2); |
| 2008 | |
| 2009 | dwc3_msm_write_reg(mdwc->base, DWC3_GUSB2PHYCFG(0), |
| 2010 | dwc3_msm_read_reg(mdwc->base, DWC3_GUSB2PHYCFG(0)) | |
| 2011 | 0xF0000000); |
| 2012 | /* 10usec delay required before de-asserting PHY RESET */ |
| 2013 | udelay(10); |
| 2014 | dwc3_msm_write_reg(mdwc->base, DWC3_GUSB2PHYCFG(0), |
| 2015 | dwc3_msm_read_reg(mdwc->base, DWC3_GUSB2PHYCFG(0)) & |
| 2016 | 0x7FFFFFFF); |
| 2017 | |
| 2018 | /* Bring PHY out of suspend */ |
| 2019 | dwc3_msm_write_readback(mdwc->base, HS_PHY_CTRL_REG, 0xC00000, |
| 2020 | 0x0); |
| 2021 | |
| 2022 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2023 | |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 2024 | if (resume_from_core_clk_off) { |
| 2025 | /* Assert SS PHY RESET */ |
| 2026 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 7), |
Vijayavardhan Vennapusa | 4188de2 | 2012-11-06 15:20:18 +0530 | [diff] [blame] | 2027 | (1 << 7)); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 2028 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 28), |
Vijayavardhan Vennapusa | 4188de2 | 2012-11-06 15:20:18 +0530 | [diff] [blame] | 2029 | (1 << 28)); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 2030 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 8), |
Vijayavardhan Vennapusa | 4188de2 | 2012-11-06 15:20:18 +0530 | [diff] [blame] | 2031 | (1 << 8)); |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 2032 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 26), |
| 2033 | 0x0); |
| 2034 | /* 10usec delay required before de-asserting SS PHY RESET */ |
| 2035 | udelay(10); |
| 2036 | dwc3_msm_write_readback(mdwc->base, SS_PHY_CTRL_REG, (1 << 7), |
| 2037 | 0x0); |
Vijayavardhan Vennapusa | 4188de2 | 2012-11-06 15:20:18 +0530 | [diff] [blame] | 2038 | |
Vijayavardhan Vennapusa | ba79f6b | 2013-07-30 13:39:52 +0530 | [diff] [blame] | 2039 | /* |
| 2040 | * Reinitilize SSPHY parameters as SS_PHY RESET will reset |
| 2041 | * the internal registers to default values. |
| 2042 | */ |
| 2043 | dwc3_msm_ss_phy_reg_init(mdwc); |
| 2044 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2045 | atomic_set(&mdwc->in_lpm, 0); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2046 | |
| 2047 | /* match disable_irq call from isr */ |
| 2048 | if (mdwc->lpm_irq_seen && mdwc->hs_phy_irq) { |
| 2049 | enable_irq(mdwc->hs_phy_irq); |
| 2050 | mdwc->lpm_irq_seen = false; |
| 2051 | } |
Manu Gautam | 840f4fe | 2013-04-16 16:50:30 +0530 | [diff] [blame] | 2052 | /* it must DCP disconnect, re-enable HS_PHY wakeup IRQ */ |
| 2053 | if (mdwc->hs_phy_irq && dcp) |
| 2054 | enable_irq_wake(mdwc->hs_phy_irq); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2055 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2056 | dev_info(mdwc->dev, "DWC3 exited from low power mode\n"); |
| 2057 | |
| 2058 | return 0; |
| 2059 | } |
| 2060 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2061 | static void dwc3_wait_for_ext_chg_done(struct dwc3_msm *mdwc) |
| 2062 | { |
| 2063 | unsigned long t; |
| 2064 | |
| 2065 | /* |
| 2066 | * Defer next cable connect event till external charger |
| 2067 | * detection is completed. |
| 2068 | */ |
| 2069 | |
| 2070 | if (mdwc->ext_chg_active && (mdwc->ext_xceiv.bsv || |
| 2071 | !mdwc->ext_xceiv.id)) { |
| 2072 | |
| 2073 | dev_dbg(mdwc->dev, "before ext chg wait\n"); |
| 2074 | |
| 2075 | t = wait_for_completion_timeout(&mdwc->ext_chg_wait, |
| 2076 | msecs_to_jiffies(3000)); |
| 2077 | if (!t) |
| 2078 | dev_err(mdwc->dev, "ext chg wait timeout\n"); |
| 2079 | else |
| 2080 | dev_dbg(mdwc->dev, "ext chg wait done\n"); |
| 2081 | } |
| 2082 | |
| 2083 | } |
| 2084 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2085 | static void dwc3_resume_work(struct work_struct *w) |
| 2086 | { |
| 2087 | struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, |
| 2088 | resume_work.work); |
| 2089 | |
| 2090 | dev_dbg(mdwc->dev, "%s: dwc3 resume work\n", __func__); |
| 2091 | /* handle any event that was queued while work was already running */ |
| 2092 | if (!atomic_read(&mdwc->in_lpm)) { |
| 2093 | dev_dbg(mdwc->dev, "%s: notifying xceiv event\n", __func__); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2094 | if (mdwc->otg_xceiv) { |
| 2095 | dwc3_wait_for_ext_chg_done(mdwc); |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2096 | mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg, |
| 2097 | DWC3_EVENT_XCEIV_STATE); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2098 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2099 | return; |
| 2100 | } |
| 2101 | |
| 2102 | /* bail out if system resume in process, else initiate RESUME */ |
| 2103 | if (atomic_read(&mdwc->pm_suspended)) { |
| 2104 | mdwc->resume_pending = true; |
| 2105 | } else { |
| 2106 | pm_runtime_get_sync(mdwc->dev); |
| 2107 | if (mdwc->otg_xceiv) |
| 2108 | mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg, |
| 2109 | DWC3_EVENT_PHY_RESUME); |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 2110 | pm_runtime_put_noidle(mdwc->dev); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2111 | if (mdwc->otg_xceiv && (mdwc->ext_xceiv.otg_capability)) { |
| 2112 | dwc3_wait_for_ext_chg_done(mdwc); |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2113 | mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg, |
| 2114 | DWC3_EVENT_XCEIV_STATE); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2115 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2119 | static u32 debug_id = true, debug_bsv, debug_connect; |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2120 | |
| 2121 | static int dwc3_connect_show(struct seq_file *s, void *unused) |
| 2122 | { |
| 2123 | if (debug_connect) |
| 2124 | seq_printf(s, "true\n"); |
| 2125 | else |
| 2126 | seq_printf(s, "false\n"); |
| 2127 | |
| 2128 | return 0; |
| 2129 | } |
| 2130 | |
| 2131 | static int dwc3_connect_open(struct inode *inode, struct file *file) |
| 2132 | { |
| 2133 | return single_open(file, dwc3_connect_show, inode->i_private); |
| 2134 | } |
| 2135 | |
| 2136 | static ssize_t dwc3_connect_write(struct file *file, const char __user *ubuf, |
| 2137 | size_t count, loff_t *ppos) |
| 2138 | { |
| 2139 | struct seq_file *s = file->private_data; |
| 2140 | struct dwc3_msm *mdwc = s->private; |
| 2141 | char buf[8]; |
| 2142 | |
| 2143 | memset(buf, 0x00, sizeof(buf)); |
| 2144 | |
| 2145 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 2146 | return -EFAULT; |
| 2147 | |
| 2148 | if (!strncmp(buf, "enable", 6) || !strncmp(buf, "true", 4)) { |
| 2149 | debug_connect = true; |
| 2150 | } else { |
| 2151 | debug_connect = debug_bsv = false; |
| 2152 | debug_id = true; |
| 2153 | } |
| 2154 | |
| 2155 | mdwc->ext_xceiv.bsv = debug_bsv; |
| 2156 | mdwc->ext_xceiv.id = debug_id ? DWC3_ID_FLOAT : DWC3_ID_GROUND; |
| 2157 | |
| 2158 | if (atomic_read(&mdwc->in_lpm)) { |
| 2159 | dev_dbg(mdwc->dev, "%s: calling resume_work\n", __func__); |
| 2160 | dwc3_resume_work(&mdwc->resume_work.work); |
| 2161 | } else { |
| 2162 | dev_dbg(mdwc->dev, "%s: notifying xceiv event\n", __func__); |
| 2163 | if (mdwc->otg_xceiv) |
| 2164 | mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg, |
| 2165 | DWC3_EVENT_XCEIV_STATE); |
| 2166 | } |
| 2167 | |
| 2168 | return count; |
| 2169 | } |
| 2170 | |
| 2171 | const struct file_operations dwc3_connect_fops = { |
| 2172 | .open = dwc3_connect_open, |
| 2173 | .read = seq_read, |
| 2174 | .write = dwc3_connect_write, |
| 2175 | .llseek = seq_lseek, |
| 2176 | .release = single_release, |
| 2177 | }; |
| 2178 | |
| 2179 | static struct dentry *dwc3_debugfs_root; |
| 2180 | |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 2181 | static void dwc3_msm_debugfs_init(struct dwc3_msm *mdwc) |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2182 | { |
| 2183 | dwc3_debugfs_root = debugfs_create_dir("msm_dwc3", NULL); |
| 2184 | |
| 2185 | if (!dwc3_debugfs_root || IS_ERR(dwc3_debugfs_root)) |
| 2186 | return; |
| 2187 | |
| 2188 | if (!debugfs_create_bool("id", S_IRUGO | S_IWUSR, dwc3_debugfs_root, |
Vijayavardhan Vennapusa | 54be1d6 | 2012-10-06 18:32:06 +0530 | [diff] [blame] | 2189 | &debug_id)) |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2190 | goto error; |
| 2191 | |
| 2192 | if (!debugfs_create_bool("bsv", S_IRUGO | S_IWUSR, dwc3_debugfs_root, |
Vijayavardhan Vennapusa | 54be1d6 | 2012-10-06 18:32:06 +0530 | [diff] [blame] | 2193 | &debug_bsv)) |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2194 | goto error; |
| 2195 | |
| 2196 | if (!debugfs_create_file("connect", S_IRUGO | S_IWUSR, |
| 2197 | dwc3_debugfs_root, mdwc, &dwc3_connect_fops)) |
| 2198 | goto error; |
| 2199 | |
| 2200 | return; |
| 2201 | |
| 2202 | error: |
| 2203 | debugfs_remove_recursive(dwc3_debugfs_root); |
| 2204 | } |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 2205 | |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2206 | static irqreturn_t msm_dwc3_irq(int irq, void *data) |
| 2207 | { |
| 2208 | struct dwc3_msm *mdwc = data; |
| 2209 | |
| 2210 | if (atomic_read(&mdwc->in_lpm)) { |
| 2211 | dev_dbg(mdwc->dev, "%s received in LPM\n", __func__); |
| 2212 | mdwc->lpm_irq_seen = true; |
| 2213 | disable_irq_nosync(irq); |
| 2214 | queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0); |
| 2215 | } else { |
| 2216 | pr_info_ratelimited("%s: IRQ outside LPM\n", __func__); |
| 2217 | } |
| 2218 | |
| 2219 | return IRQ_HANDLED; |
| 2220 | } |
| 2221 | |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2222 | static int dwc3_msm_power_get_property_usb(struct power_supply *psy, |
| 2223 | enum power_supply_property psp, |
| 2224 | union power_supply_propval *val) |
| 2225 | { |
| 2226 | struct dwc3_msm *mdwc = container_of(psy, struct dwc3_msm, |
| 2227 | usb_psy); |
| 2228 | switch (psp) { |
| 2229 | case POWER_SUPPLY_PROP_SCOPE: |
| 2230 | val->intval = mdwc->host_mode; |
| 2231 | break; |
Pavankumar Kondeti | fbd4b14 | 2013-07-16 11:13:05 +0530 | [diff] [blame] | 2232 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: |
| 2233 | val->intval = mdwc->voltage_max; |
| 2234 | break; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2235 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
| 2236 | val->intval = mdwc->current_max; |
| 2237 | break; |
| 2238 | case POWER_SUPPLY_PROP_PRESENT: |
| 2239 | val->intval = mdwc->vbus_active; |
| 2240 | break; |
| 2241 | case POWER_SUPPLY_PROP_ONLINE: |
| 2242 | val->intval = mdwc->online; |
| 2243 | break; |
Manu Gautam | fa40cae | 2013-03-01 16:37:12 +0530 | [diff] [blame] | 2244 | case POWER_SUPPLY_PROP_TYPE: |
| 2245 | val->intval = psy->type; |
| 2246 | break; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2247 | default: |
| 2248 | return -EINVAL; |
| 2249 | } |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
| 2253 | static int dwc3_msm_power_set_property_usb(struct power_supply *psy, |
| 2254 | enum power_supply_property psp, |
| 2255 | const union power_supply_propval *val) |
| 2256 | { |
| 2257 | static bool init; |
| 2258 | struct dwc3_msm *mdwc = container_of(psy, struct dwc3_msm, |
| 2259 | usb_psy); |
| 2260 | |
| 2261 | switch (psp) { |
| 2262 | case POWER_SUPPLY_PROP_SCOPE: |
| 2263 | mdwc->host_mode = val->intval; |
| 2264 | break; |
| 2265 | /* Process PMIC notification in PRESENT prop */ |
| 2266 | case POWER_SUPPLY_PROP_PRESENT: |
| 2267 | dev_dbg(mdwc->dev, "%s: notify xceiv event\n", __func__); |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2268 | if (mdwc->otg_xceiv && !mdwc->ext_inuse && |
| 2269 | (mdwc->ext_xceiv.otg_capability || !init)) { |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2270 | mdwc->ext_xceiv.bsv = val->intval; |
Manu Gautam | f71d9cb | 2013-02-07 13:52:12 +0530 | [diff] [blame] | 2271 | queue_delayed_work(system_nrt_wq, |
Jack Pham | 4d91aab | 2013-03-08 10:02:16 -0800 | [diff] [blame] | 2272 | &mdwc->resume_work, 20); |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2273 | |
| 2274 | if (!init) |
| 2275 | init = true; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2276 | } |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2277 | mdwc->vbus_active = val->intval; |
| 2278 | break; |
| 2279 | case POWER_SUPPLY_PROP_ONLINE: |
| 2280 | mdwc->online = val->intval; |
| 2281 | break; |
Pavankumar Kondeti | fbd4b14 | 2013-07-16 11:13:05 +0530 | [diff] [blame] | 2282 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: |
| 2283 | mdwc->voltage_max = val->intval; |
| 2284 | break; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2285 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
| 2286 | mdwc->current_max = val->intval; |
| 2287 | break; |
Manu Gautam | fa40cae | 2013-03-01 16:37:12 +0530 | [diff] [blame] | 2288 | case POWER_SUPPLY_PROP_TYPE: |
| 2289 | psy->type = val->intval; |
| 2290 | break; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2291 | default: |
| 2292 | return -EINVAL; |
| 2293 | } |
| 2294 | |
| 2295 | power_supply_changed(&mdwc->usb_psy); |
| 2296 | return 0; |
| 2297 | } |
| 2298 | |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2299 | static void dwc3_msm_external_power_changed(struct power_supply *psy) |
| 2300 | { |
| 2301 | struct dwc3_msm *mdwc = container_of(psy, struct dwc3_msm, usb_psy); |
| 2302 | union power_supply_propval ret = {0,}; |
| 2303 | |
| 2304 | if (!mdwc->ext_vbus_psy) |
| 2305 | mdwc->ext_vbus_psy = power_supply_get_by_name("ext-vbus"); |
| 2306 | |
| 2307 | if (!mdwc->ext_vbus_psy) { |
| 2308 | pr_err("%s: Unable to get ext_vbus power_supply\n", __func__); |
| 2309 | return; |
| 2310 | } |
| 2311 | |
| 2312 | mdwc->ext_vbus_psy->get_property(mdwc->ext_vbus_psy, |
| 2313 | POWER_SUPPLY_PROP_ONLINE, &ret); |
| 2314 | if (ret.intval) { |
| 2315 | dwc3_start_chg_det(&mdwc->charger, false); |
| 2316 | mdwc->ext_vbus_psy->get_property(mdwc->ext_vbus_psy, |
| 2317 | POWER_SUPPLY_PROP_CURRENT_MAX, &ret); |
| 2318 | power_supply_set_current_limit(&mdwc->usb_psy, ret.intval); |
| 2319 | } |
| 2320 | |
| 2321 | power_supply_set_online(&mdwc->usb_psy, ret.intval); |
| 2322 | power_supply_changed(&mdwc->usb_psy); |
| 2323 | } |
| 2324 | |
Pavankumar Kondeti | fbd4b14 | 2013-07-16 11:13:05 +0530 | [diff] [blame] | 2325 | static int |
| 2326 | dwc3_msm_property_is_writeable(struct power_supply *psy, |
| 2327 | enum power_supply_property psp) |
| 2328 | { |
| 2329 | switch (psp) { |
| 2330 | case POWER_SUPPLY_PROP_VOLTAGE_MAX: |
| 2331 | return 1; |
| 2332 | default: |
| 2333 | break; |
| 2334 | } |
| 2335 | |
| 2336 | return 0; |
| 2337 | } |
| 2338 | |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2339 | |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2340 | static char *dwc3_msm_pm_power_supplied_to[] = { |
| 2341 | "battery", |
| 2342 | }; |
| 2343 | |
| 2344 | static enum power_supply_property dwc3_msm_pm_power_props_usb[] = { |
| 2345 | POWER_SUPPLY_PROP_PRESENT, |
| 2346 | POWER_SUPPLY_PROP_ONLINE, |
Pavankumar Kondeti | fbd4b14 | 2013-07-16 11:13:05 +0530 | [diff] [blame] | 2347 | POWER_SUPPLY_PROP_VOLTAGE_MAX, |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2348 | POWER_SUPPLY_PROP_CURRENT_MAX, |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2349 | POWER_SUPPLY_PROP_TYPE, |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2350 | POWER_SUPPLY_PROP_SCOPE, |
| 2351 | }; |
| 2352 | |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2353 | static void dwc3_init_adc_work(struct work_struct *w); |
| 2354 | |
Jack Pham | b720915 | 2013-07-03 17:04:53 -0700 | [diff] [blame] | 2355 | static void dwc3_ext_notify_online(void *ctx, int on) |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2356 | { |
Jack Pham | b720915 | 2013-07-03 17:04:53 -0700 | [diff] [blame] | 2357 | struct dwc3_msm *mdwc = ctx; |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2358 | bool notify_otg = false; |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2359 | |
| 2360 | if (!mdwc) { |
| 2361 | pr_err("%s: DWC3 driver already removed\n", __func__); |
| 2362 | return; |
| 2363 | } |
| 2364 | |
| 2365 | dev_dbg(mdwc->dev, "notify %s%s\n", on ? "" : "dis", "connected"); |
| 2366 | |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2367 | if (!mdwc->ext_vbus_psy) |
| 2368 | mdwc->ext_vbus_psy = power_supply_get_by_name("ext-vbus"); |
| 2369 | |
| 2370 | mdwc->ext_inuse = on; |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2371 | if (on) { |
| 2372 | /* force OTG to exit B-peripheral state */ |
| 2373 | mdwc->ext_xceiv.bsv = false; |
| 2374 | notify_otg = true; |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2375 | dwc3_start_chg_det(&mdwc->charger, false); |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2376 | } else { |
| 2377 | /* external client offline; tell OTG about cached ID/BSV */ |
| 2378 | if (mdwc->ext_xceiv.id != mdwc->id_state) { |
| 2379 | mdwc->ext_xceiv.id = mdwc->id_state; |
| 2380 | notify_otg = true; |
| 2381 | } |
| 2382 | |
| 2383 | mdwc->ext_xceiv.bsv = mdwc->vbus_active; |
| 2384 | notify_otg |= mdwc->vbus_active; |
| 2385 | } |
Jack Pham | 9354c6a | 2012-12-20 19:19:32 -0800 | [diff] [blame] | 2386 | |
| 2387 | if (mdwc->ext_vbus_psy) |
| 2388 | power_supply_set_present(mdwc->ext_vbus_psy, on); |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2389 | |
| 2390 | if (notify_otg) |
| 2391 | queue_delayed_work(system_nrt_wq, &mdwc->resume_work, 0); |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2392 | } |
| 2393 | |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2394 | static void dwc3_id_work(struct work_struct *w) |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2395 | { |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2396 | struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, id_work); |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2397 | int ret; |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2398 | |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2399 | /* Give external client a chance to handle */ |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2400 | if (!mdwc->ext_inuse && usb_ext) { |
| 2401 | if (mdwc->pmic_id_irq) |
| 2402 | disable_irq(mdwc->pmic_id_irq); |
| 2403 | |
| 2404 | ret = usb_ext->notify(usb_ext->ctxt, mdwc->id_state, |
Jack Pham | b720915 | 2013-07-03 17:04:53 -0700 | [diff] [blame] | 2405 | dwc3_ext_notify_online, mdwc); |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2406 | dev_dbg(mdwc->dev, "%s: external handler returned %d\n", |
| 2407 | __func__, ret); |
| 2408 | |
| 2409 | if (mdwc->pmic_id_irq) { |
Vijayavardhan Vennapusa | 242eaf0 | 2013-07-01 12:39:31 +0530 | [diff] [blame] | 2410 | unsigned long flags; |
| 2411 | local_irq_save(flags); |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2412 | /* ID may have changed while IRQ disabled; update it */ |
| 2413 | mdwc->id_state = !!irq_read_line(mdwc->pmic_id_irq); |
Vijayavardhan Vennapusa | 242eaf0 | 2013-07-01 12:39:31 +0530 | [diff] [blame] | 2414 | local_irq_restore(flags); |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2415 | enable_irq(mdwc->pmic_id_irq); |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2416 | } |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2417 | |
| 2418 | mdwc->ext_inuse = (ret == 0); |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2419 | } |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2420 | |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2421 | if (!mdwc->ext_inuse) { /* notify OTG */ |
| 2422 | mdwc->ext_xceiv.id = mdwc->id_state; |
| 2423 | dwc3_resume_work(&mdwc->resume_work.work); |
| 2424 | } |
| 2425 | } |
| 2426 | |
| 2427 | static irqreturn_t dwc3_pmic_id_irq(int irq, void *data) |
| 2428 | { |
| 2429 | struct dwc3_msm *mdwc = data; |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2430 | enum dwc3_id_state id; |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2431 | |
| 2432 | /* If we can't read ID line state for some reason, treat it as float */ |
Jack Pham | 5c58506 | 2013-03-25 18:39:12 -0700 | [diff] [blame] | 2433 | id = !!irq_read_line(irq); |
| 2434 | if (mdwc->id_state != id) { |
| 2435 | mdwc->id_state = id; |
| 2436 | queue_work(system_nrt_wq, &mdwc->id_work); |
| 2437 | } |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2438 | |
| 2439 | return IRQ_HANDLED; |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2440 | } |
| 2441 | |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2442 | static void dwc3_adc_notification(enum qpnp_tm_state state, void *ctx) |
| 2443 | { |
| 2444 | struct dwc3_msm *mdwc = ctx; |
| 2445 | |
| 2446 | if (state >= ADC_TM_STATE_NUM) { |
| 2447 | pr_err("%s: invalid notification %d\n", __func__, state); |
| 2448 | return; |
| 2449 | } |
| 2450 | |
| 2451 | dev_dbg(mdwc->dev, "%s: state = %s\n", __func__, |
| 2452 | state == ADC_TM_HIGH_STATE ? "high" : "low"); |
| 2453 | |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2454 | /* save ID state, but don't necessarily notify OTG */ |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2455 | if (state == ADC_TM_HIGH_STATE) { |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2456 | mdwc->id_state = DWC3_ID_FLOAT; |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2457 | mdwc->adc_param.state_request = ADC_TM_LOW_THR_ENABLE; |
| 2458 | } else { |
Jack Pham | f12b7e1 | 2012-12-28 14:27:26 -0800 | [diff] [blame] | 2459 | mdwc->id_state = DWC3_ID_GROUND; |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2460 | mdwc->adc_param.state_request = ADC_TM_HIGH_THR_ENABLE; |
| 2461 | } |
| 2462 | |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2463 | dwc3_id_work(&mdwc->id_work); |
| 2464 | |
Jack Pham | fadd643 | 2012-12-07 19:03:41 -0800 | [diff] [blame] | 2465 | /* re-arm ADC interrupt */ |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 2466 | qpnp_adc_tm_usbid_configure(mdwc->adc_tm_dev, &mdwc->adc_param); |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | static void dwc3_init_adc_work(struct work_struct *w) |
| 2470 | { |
| 2471 | struct dwc3_msm *mdwc = container_of(w, struct dwc3_msm, |
| 2472 | init_adc_work.work); |
| 2473 | int ret; |
| 2474 | |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 2475 | mdwc->adc_tm_dev = qpnp_get_adc_tm(mdwc->dev, "dwc_usb3-adc_tm"); |
| 2476 | if (IS_ERR(mdwc->adc_tm_dev)) { |
| 2477 | if (PTR_ERR(mdwc->adc_tm_dev) == -EPROBE_DEFER) |
| 2478 | queue_delayed_work(system_nrt_wq, to_delayed_work(w), |
Jack Pham | 90b4d12 | 2012-12-13 11:46:22 -0800 | [diff] [blame] | 2479 | msecs_to_jiffies(100)); |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 2480 | else |
| 2481 | mdwc->adc_tm_dev = NULL; |
| 2482 | |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2483 | return; |
| 2484 | } |
| 2485 | |
| 2486 | mdwc->adc_param.low_thr = adc_low_threshold; |
| 2487 | mdwc->adc_param.high_thr = adc_high_threshold; |
| 2488 | mdwc->adc_param.timer_interval = adc_meas_interval; |
| 2489 | mdwc->adc_param.state_request = ADC_TM_HIGH_LOW_THR_ENABLE; |
Siddartha Mohanadoss | a3e3551 | 2013-02-22 17:06:07 -0800 | [diff] [blame] | 2490 | mdwc->adc_param.btm_ctx = mdwc; |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2491 | mdwc->adc_param.threshold_notification = dwc3_adc_notification; |
| 2492 | |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 2493 | ret = qpnp_adc_tm_usbid_configure(mdwc->adc_tm_dev, &mdwc->adc_param); |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2494 | if (ret) { |
| 2495 | dev_err(mdwc->dev, "%s: request ADC error %d\n", __func__, ret); |
| 2496 | return; |
| 2497 | } |
| 2498 | |
| 2499 | mdwc->id_adc_detect = true; |
| 2500 | } |
| 2501 | |
| 2502 | static ssize_t adc_enable_show(struct device *dev, |
| 2503 | struct device_attribute *attr, char *buf) |
| 2504 | { |
Jack Pham | 84fc1ac | 2013-07-09 17:51:41 -0700 | [diff] [blame] | 2505 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 2506 | |
| 2507 | if (!mdwc) |
| 2508 | return -EINVAL; |
| 2509 | |
| 2510 | return snprintf(buf, PAGE_SIZE, "%s\n", mdwc->id_adc_detect ? |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2511 | "enabled" : "disabled"); |
| 2512 | } |
| 2513 | |
| 2514 | static ssize_t adc_enable_store(struct device *dev, |
| 2515 | struct device_attribute *attr, const char |
| 2516 | *buf, size_t size) |
| 2517 | { |
Jack Pham | 84fc1ac | 2013-07-09 17:51:41 -0700 | [diff] [blame] | 2518 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 2519 | |
| 2520 | if (!mdwc) |
| 2521 | return -EINVAL; |
| 2522 | |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2523 | if (!strnicmp(buf, "enable", 6)) { |
Jack Pham | 84fc1ac | 2013-07-09 17:51:41 -0700 | [diff] [blame] | 2524 | if (!mdwc->id_adc_detect) |
| 2525 | dwc3_init_adc_work(&mdwc->init_adc_work.work); |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2526 | return size; |
| 2527 | } else if (!strnicmp(buf, "disable", 7)) { |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 2528 | qpnp_adc_tm_usbid_end(mdwc->adc_tm_dev); |
Jack Pham | 84fc1ac | 2013-07-09 17:51:41 -0700 | [diff] [blame] | 2529 | mdwc->id_adc_detect = false; |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2530 | return size; |
| 2531 | } |
| 2532 | |
| 2533 | return -EINVAL; |
| 2534 | } |
| 2535 | |
| 2536 | static DEVICE_ATTR(adc_enable, S_IRUGO | S_IWUSR, adc_enable_show, |
| 2537 | adc_enable_store); |
| 2538 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2539 | static int dwc3_msm_ext_chg_open(struct inode *inode, struct file *file) |
| 2540 | { |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2541 | struct dwc3_msm *mdwc = |
| 2542 | container_of(inode->i_cdev, struct dwc3_msm, ext_chg_cdev); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2543 | |
| 2544 | pr_debug("dwc3-msm ext chg open\n"); |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2545 | file->private_data = mdwc; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2546 | mdwc->ext_chg_opened = true; |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2547 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2548 | return 0; |
| 2549 | } |
| 2550 | |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2551 | static long |
| 2552 | dwc3_msm_ext_chg_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2553 | { |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2554 | struct dwc3_msm *mdwc = file->private_data; |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2555 | struct msm_usb_chg_info info = {0}; |
| 2556 | int ret = 0, val; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2557 | |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2558 | switch (cmd) { |
| 2559 | case MSM_USB_EXT_CHG_INFO: |
| 2560 | info.chg_block_type = USB_CHG_BLOCK_QSCRATCH; |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2561 | info.page_offset = (mdwc->io_res->start + |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2562 | QSCRATCH_REG_OFFSET) & ~PAGE_MASK; |
| 2563 | /* |
| 2564 | * The charger block register address space is only |
| 2565 | * 512 bytes. But mmap() works on PAGE granularity. |
| 2566 | */ |
| 2567 | info.length = PAGE_SIZE; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2568 | |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2569 | if (copy_to_user((void __user *)arg, &info, sizeof(info))) { |
| 2570 | pr_err("%s: copy to user failed\n\n", __func__); |
| 2571 | ret = -EFAULT; |
| 2572 | } |
| 2573 | break; |
| 2574 | case MSM_USB_EXT_CHG_BLOCK_LPM: |
| 2575 | if (get_user(val, (int __user *)arg)) { |
| 2576 | pr_err("%s: get_user failed\n\n", __func__); |
| 2577 | ret = -EFAULT; |
| 2578 | break; |
| 2579 | } |
| 2580 | pr_debug("%s: LPM block request %d\n", __func__, val); |
| 2581 | if (val) { /* block LPM */ |
| 2582 | if (mdwc->charger.chg_type == DWC3_DCP_CHARGER) { |
| 2583 | pm_runtime_get_sync(mdwc->dev); |
| 2584 | } else { |
| 2585 | mdwc->ext_chg_active = false; |
| 2586 | complete(&mdwc->ext_chg_wait); |
| 2587 | ret = -ENODEV; |
| 2588 | } |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2589 | } else { |
| 2590 | mdwc->ext_chg_active = false; |
| 2591 | complete(&mdwc->ext_chg_wait); |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2592 | pm_runtime_put(mdwc->dev); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2593 | } |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2594 | break; |
| 2595 | default: |
| 2596 | ret = -EINVAL; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2597 | } |
| 2598 | |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2599 | return ret; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | static int dwc3_msm_ext_chg_mmap(struct file *file, struct vm_area_struct *vma) |
| 2603 | { |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2604 | struct dwc3_msm *mdwc = file->private_data; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2605 | unsigned long vsize = vma->vm_end - vma->vm_start; |
| 2606 | int ret; |
| 2607 | |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2608 | if (vma->vm_pgoff != 0 || vsize > PAGE_SIZE) |
| 2609 | return -EINVAL; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2610 | |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2611 | vma->vm_pgoff = __phys_to_pfn(mdwc->io_res->start + |
| 2612 | QSCRATCH_REG_OFFSET); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2613 | vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); |
| 2614 | |
| 2615 | ret = io_remap_pfn_range(vma, vma->vm_start, vma->vm_pgoff, |
| 2616 | vsize, vma->vm_page_prot); |
| 2617 | if (ret < 0) |
| 2618 | pr_err("%s: failed with return val %d\n", __func__, ret); |
| 2619 | |
| 2620 | return ret; |
| 2621 | } |
| 2622 | |
| 2623 | static int dwc3_msm_ext_chg_release(struct inode *inode, struct file *file) |
| 2624 | { |
Jack Pham | ea382b7 | 2013-07-09 17:50:20 -0700 | [diff] [blame] | 2625 | struct dwc3_msm *mdwc = file->private_data; |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2626 | |
| 2627 | pr_debug("dwc3-msm ext chg release\n"); |
| 2628 | |
| 2629 | mdwc->ext_chg_opened = false; |
| 2630 | |
| 2631 | return 0; |
| 2632 | } |
| 2633 | |
| 2634 | static const struct file_operations dwc3_msm_ext_chg_fops = { |
| 2635 | .owner = THIS_MODULE, |
| 2636 | .open = dwc3_msm_ext_chg_open, |
Pavankumar Kondeti | 17b52e7 | 2013-06-28 10:54:18 +0530 | [diff] [blame] | 2637 | .unlocked_ioctl = dwc3_msm_ext_chg_ioctl, |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 2638 | .mmap = dwc3_msm_ext_chg_mmap, |
| 2639 | .release = dwc3_msm_ext_chg_release, |
| 2640 | }; |
| 2641 | |
| 2642 | static int dwc3_msm_setup_cdev(struct dwc3_msm *mdwc) |
| 2643 | { |
| 2644 | int ret; |
| 2645 | |
| 2646 | ret = alloc_chrdev_region(&mdwc->ext_chg_dev, 0, 1, "usb_ext_chg"); |
| 2647 | if (ret < 0) { |
| 2648 | pr_err("Fail to allocate usb ext char dev region\n"); |
| 2649 | return ret; |
| 2650 | } |
| 2651 | mdwc->ext_chg_class = class_create(THIS_MODULE, "dwc_ext_chg"); |
| 2652 | if (ret < 0) { |
| 2653 | pr_err("Fail to create usb ext chg class\n"); |
| 2654 | goto unreg_chrdev; |
| 2655 | } |
| 2656 | cdev_init(&mdwc->ext_chg_cdev, &dwc3_msm_ext_chg_fops); |
| 2657 | mdwc->ext_chg_cdev.owner = THIS_MODULE; |
| 2658 | |
| 2659 | ret = cdev_add(&mdwc->ext_chg_cdev, mdwc->ext_chg_dev, 1); |
| 2660 | if (ret < 0) { |
| 2661 | pr_err("Fail to add usb ext chg cdev\n"); |
| 2662 | goto destroy_class; |
| 2663 | } |
| 2664 | mdwc->ext_chg_device = device_create(mdwc->ext_chg_class, |
| 2665 | NULL, mdwc->ext_chg_dev, NULL, |
| 2666 | "usb_ext_chg"); |
| 2667 | if (IS_ERR(mdwc->ext_chg_device)) { |
| 2668 | pr_err("Fail to create usb ext chg device\n"); |
| 2669 | ret = PTR_ERR(mdwc->ext_chg_device); |
| 2670 | mdwc->ext_chg_device = NULL; |
| 2671 | goto del_cdev; |
| 2672 | } |
| 2673 | |
| 2674 | pr_debug("dwc3 msm ext chg cdev setup success\n"); |
| 2675 | return 0; |
| 2676 | |
| 2677 | del_cdev: |
| 2678 | cdev_del(&mdwc->ext_chg_cdev); |
| 2679 | destroy_class: |
| 2680 | class_destroy(mdwc->ext_chg_class); |
| 2681 | unreg_chrdev: |
| 2682 | unregister_chrdev_region(mdwc->ext_chg_dev, 1); |
| 2683 | |
| 2684 | return ret; |
| 2685 | } |
| 2686 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2687 | static int __devinit dwc3_msm_probe(struct platform_device *pdev) |
| 2688 | { |
| 2689 | struct device_node *node = pdev->dev.of_node; |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2690 | struct dwc3_msm *mdwc; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2691 | struct resource *res; |
Ido Shayevitz | 7ad8ded | 2012-08-28 04:30:58 +0300 | [diff] [blame] | 2692 | void __iomem *tcsr; |
Manu Gautam | f08f7b6 | 2013-04-02 16:09:42 +0530 | [diff] [blame] | 2693 | unsigned long flags; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2694 | int ret = 0; |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2695 | int len = 0; |
| 2696 | u32 tmp[3]; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2697 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2698 | mdwc = devm_kzalloc(&pdev->dev, sizeof(*mdwc), GFP_KERNEL); |
| 2699 | if (!mdwc) { |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2700 | dev_err(&pdev->dev, "not enough memory\n"); |
| 2701 | return -ENOMEM; |
| 2702 | } |
| 2703 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2704 | platform_set_drvdata(pdev, mdwc); |
| 2705 | mdwc->dev = &pdev->dev; |
Ido Shayevitz | 9fb8345 | 2012-04-01 17:45:58 +0300 | [diff] [blame] | 2706 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2707 | INIT_LIST_HEAD(&mdwc->req_complete_list); |
| 2708 | INIT_DELAYED_WORK(&mdwc->chg_work, dwc3_chg_detect_work); |
| 2709 | INIT_DELAYED_WORK(&mdwc->resume_work, dwc3_resume_work); |
| 2710 | INIT_WORK(&mdwc->restart_usb_work, dwc3_restart_usb_work); |
Vijayavardhan Vennapusa | ddd0474 | 2013-09-26 19:47:18 +0530 | [diff] [blame] | 2711 | INIT_WORK(&mdwc->usb_block_reset_work, dwc3_block_reset_usb_work); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2712 | INIT_WORK(&mdwc->id_work, dwc3_id_work); |
| 2713 | INIT_DELAYED_WORK(&mdwc->init_adc_work, dwc3_init_adc_work); |
| 2714 | init_completion(&mdwc->ext_chg_wait); |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2715 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2716 | ret = dwc3_msm_config_gdsc(mdwc, 1); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 2717 | if (ret) { |
| 2718 | dev_err(&pdev->dev, "unable to configure usb3 gdsc\n"); |
| 2719 | return ret; |
| 2720 | } |
| 2721 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2722 | mdwc->xo_clk = clk_get(&pdev->dev, "xo"); |
| 2723 | if (IS_ERR(mdwc->xo_clk)) { |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2724 | dev_err(&pdev->dev, "%s unable to get TCXO buffer handle\n", |
| 2725 | __func__); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2726 | ret = PTR_ERR(mdwc->xo_clk); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 2727 | goto disable_dwc3_gdsc; |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2728 | } |
| 2729 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2730 | ret = clk_prepare_enable(mdwc->xo_clk); |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2731 | if (ret) { |
| 2732 | dev_err(&pdev->dev, "%s failed to vote for TCXO buffer%d\n", |
| 2733 | __func__, ret); |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 2734 | goto put_xo; |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2735 | } |
| 2736 | |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 2737 | /* |
| 2738 | * DWC3 Core requires its CORE CLK (aka master / bus clk) to |
| 2739 | * run at 125Mhz in SSUSB mode and >60MHZ for HSUSB mode. |
| 2740 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2741 | mdwc->core_clk = devm_clk_get(&pdev->dev, "core_clk"); |
| 2742 | if (IS_ERR(mdwc->core_clk)) { |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 2743 | dev_err(&pdev->dev, "failed to get core_clk\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2744 | ret = PTR_ERR(mdwc->core_clk); |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 2745 | goto disable_xo; |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 2746 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2747 | clk_set_rate(mdwc->core_clk, 125000000); |
| 2748 | clk_prepare_enable(mdwc->core_clk); |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 2749 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2750 | mdwc->iface_clk = devm_clk_get(&pdev->dev, "iface_clk"); |
| 2751 | if (IS_ERR(mdwc->iface_clk)) { |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2752 | dev_err(&pdev->dev, "failed to get iface_clk\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2753 | ret = PTR_ERR(mdwc->iface_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2754 | goto disable_core_clk; |
| 2755 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2756 | clk_prepare_enable(mdwc->iface_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2757 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2758 | mdwc->sleep_clk = devm_clk_get(&pdev->dev, "sleep_clk"); |
| 2759 | if (IS_ERR(mdwc->sleep_clk)) { |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2760 | dev_err(&pdev->dev, "failed to get sleep_clk\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2761 | ret = PTR_ERR(mdwc->sleep_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2762 | goto disable_iface_clk; |
| 2763 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2764 | clk_prepare_enable(mdwc->sleep_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2765 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2766 | mdwc->hsphy_sleep_clk = devm_clk_get(&pdev->dev, "sleep_a_clk"); |
| 2767 | if (IS_ERR(mdwc->hsphy_sleep_clk)) { |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2768 | dev_err(&pdev->dev, "failed to get sleep_a_clk\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2769 | ret = PTR_ERR(mdwc->hsphy_sleep_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2770 | goto disable_sleep_clk; |
| 2771 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2772 | clk_prepare_enable(mdwc->hsphy_sleep_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2773 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2774 | mdwc->utmi_clk = devm_clk_get(&pdev->dev, "utmi_clk"); |
| 2775 | if (IS_ERR(mdwc->utmi_clk)) { |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 2776 | dev_err(&pdev->dev, "failed to get utmi_clk\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2777 | ret = PTR_ERR(mdwc->utmi_clk); |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 2778 | goto disable_sleep_a_clk; |
| 2779 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2780 | clk_prepare_enable(mdwc->utmi_clk); |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 2781 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2782 | mdwc->ref_clk = devm_clk_get(&pdev->dev, "ref_clk"); |
| 2783 | if (IS_ERR(mdwc->ref_clk)) { |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2784 | dev_err(&pdev->dev, "failed to get ref_clk\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2785 | ret = PTR_ERR(mdwc->ref_clk); |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 2786 | goto disable_utmi_clk; |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2787 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2788 | clk_prepare_enable(mdwc->ref_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2789 | |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2790 | of_get_property(node, "qcom,vdd-voltage-level", &len); |
| 2791 | if (len == sizeof(tmp)) { |
| 2792 | of_property_read_u32_array(node, "qcom,vdd-voltage-level", |
| 2793 | tmp, len/sizeof(*tmp)); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2794 | mdwc->vdd_no_vol_level = tmp[0]; |
| 2795 | mdwc->vdd_low_vol_level = tmp[1]; |
| 2796 | mdwc->vdd_high_vol_level = tmp[2]; |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2797 | } else { |
| 2798 | dev_err(&pdev->dev, "no qcom,vdd-voltage-level property\n"); |
| 2799 | ret = -EINVAL; |
| 2800 | goto disable_ref_clk; |
| 2801 | } |
| 2802 | |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2803 | /* SS PHY */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2804 | mdwc->ssusb_vddcx = devm_regulator_get(&pdev->dev, "ssusb_vdd_dig"); |
| 2805 | if (IS_ERR(mdwc->ssusb_vddcx)) { |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2806 | dev_err(&pdev->dev, "unable to get ssusb vddcx\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2807 | ret = PTR_ERR(mdwc->ssusb_vddcx); |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2808 | goto disable_ref_clk; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2809 | } |
| 2810 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2811 | ret = dwc3_ssusb_config_vddcx(mdwc, 1); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2812 | if (ret) { |
| 2813 | dev_err(&pdev->dev, "ssusb vddcx configuration failed\n"); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 2814 | goto disable_ref_clk; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2815 | } |
| 2816 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2817 | ret = regulator_enable(mdwc->ssusb_vddcx); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2818 | if (ret) { |
| 2819 | dev_err(&pdev->dev, "unable to enable the ssusb vddcx\n"); |
| 2820 | goto unconfig_ss_vddcx; |
| 2821 | } |
| 2822 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2823 | ret = dwc3_ssusb_ldo_init(mdwc, 1); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2824 | if (ret) { |
| 2825 | dev_err(&pdev->dev, "ssusb vreg configuration failed\n"); |
| 2826 | goto disable_ss_vddcx; |
| 2827 | } |
| 2828 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2829 | ret = dwc3_ssusb_ldo_enable(mdwc, 1); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2830 | if (ret) { |
| 2831 | dev_err(&pdev->dev, "ssusb vreg enable failed\n"); |
| 2832 | goto free_ss_ldo_init; |
| 2833 | } |
| 2834 | |
| 2835 | /* HS PHY */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2836 | mdwc->hsusb_vddcx = devm_regulator_get(&pdev->dev, "hsusb_vdd_dig"); |
| 2837 | if (IS_ERR(mdwc->hsusb_vddcx)) { |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2838 | dev_err(&pdev->dev, "unable to get hsusb vddcx\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2839 | ret = PTR_ERR(mdwc->hsusb_vddcx); |
Vijayavardhan Vennapusa | 993798a | 2012-11-09 15:11:21 +0530 | [diff] [blame] | 2840 | goto disable_ss_ldo; |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2841 | } |
| 2842 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2843 | ret = dwc3_hsusb_config_vddcx(mdwc, 1); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2844 | if (ret) { |
| 2845 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
| 2846 | goto disable_ss_ldo; |
| 2847 | } |
| 2848 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2849 | ret = regulator_enable(mdwc->hsusb_vddcx); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2850 | if (ret) { |
| 2851 | dev_err(&pdev->dev, "unable to enable the hsusb vddcx\n"); |
| 2852 | goto unconfig_hs_vddcx; |
| 2853 | } |
| 2854 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2855 | ret = dwc3_hsusb_ldo_init(mdwc, 1); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2856 | if (ret) { |
| 2857 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
| 2858 | goto disable_hs_vddcx; |
| 2859 | } |
| 2860 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2861 | ret = dwc3_hsusb_ldo_enable(mdwc, 1); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2862 | if (ret) { |
| 2863 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
| 2864 | goto free_hs_ldo_init; |
| 2865 | } |
| 2866 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2867 | mdwc->id_state = mdwc->ext_xceiv.id = DWC3_ID_FLOAT; |
| 2868 | mdwc->ext_xceiv.otg_capability = of_property_read_bool(node, |
Manu Gautam | 6c0ff03 | 2012-11-02 14:55:35 +0530 | [diff] [blame] | 2869 | "qcom,otg-capability"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2870 | mdwc->charger.charging_disabled = of_property_read_bool(node, |
Manu Gautam | 6c0ff03 | 2012-11-02 14:55:35 +0530 | [diff] [blame] | 2871 | "qcom,charging-disabled"); |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 2872 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2873 | mdwc->charger.skip_chg_detect = of_property_read_bool(node, |
Hemant Kumar | 6d7b724 | 2013-04-18 16:44:38 -0700 | [diff] [blame] | 2874 | "qcom,skip-charger-detection"); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 2875 | /* |
| 2876 | * DWC3 has separate IRQ line for OTG events (ID/BSV) and for |
| 2877 | * DP and DM linestate transitions during low power mode. |
| 2878 | */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2879 | mdwc->hs_phy_irq = platform_get_irq_byname(pdev, "hs_phy_irq"); |
| 2880 | if (mdwc->hs_phy_irq < 0) { |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 2881 | dev_dbg(&pdev->dev, "pget_irq for hs_phy_irq failed\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2882 | mdwc->hs_phy_irq = 0; |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 2883 | } else { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2884 | ret = devm_request_irq(&pdev->dev, mdwc->hs_phy_irq, |
Jack Pham | 56a0a63 | 2013-03-08 13:18:42 -0800 | [diff] [blame] | 2885 | msm_dwc3_irq, IRQF_TRIGGER_RISING, |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2886 | "msm_dwc3", mdwc); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 2887 | if (ret) { |
| 2888 | dev_err(&pdev->dev, "irqreq HSPHYINT failed\n"); |
| 2889 | goto disable_hs_ldo; |
| 2890 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2891 | enable_irq_wake(mdwc->hs_phy_irq); |
Vijayavardhan Vennapusa | 4514588 | 2013-01-03 14:11:58 +0530 | [diff] [blame] | 2892 | } |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2893 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2894 | if (mdwc->ext_xceiv.otg_capability) { |
| 2895 | mdwc->pmic_id_irq = |
| 2896 | platform_get_irq_byname(pdev, "pmic_id_irq"); |
| 2897 | if (mdwc->pmic_id_irq > 0) { |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 2898 | /* check if PMIC ID IRQ is supported */ |
| 2899 | ret = qpnp_misc_irqs_available(&pdev->dev); |
| 2900 | |
| 2901 | if (ret == -EPROBE_DEFER) { |
| 2902 | /* qpnp hasn't probed yet; defer dwc probe */ |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2903 | goto disable_hs_ldo; |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 2904 | } else if (ret == 0) { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2905 | mdwc->pmic_id_irq = 0; |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 2906 | } else { |
| 2907 | ret = devm_request_irq(&pdev->dev, |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2908 | mdwc->pmic_id_irq, |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 2909 | dwc3_pmic_id_irq, |
| 2910 | IRQF_TRIGGER_RISING | |
| 2911 | IRQF_TRIGGER_FALLING, |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2912 | "dwc3_msm_pmic_id", |
| 2913 | mdwc); |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 2914 | if (ret) { |
| 2915 | dev_err(&pdev->dev, "irqreq IDINT failed\n"); |
| 2916 | goto disable_hs_ldo; |
| 2917 | } |
Jack Pham | 9198d9f | 2013-04-09 17:54:54 -0700 | [diff] [blame] | 2918 | |
Manu Gautam | f08f7b6 | 2013-04-02 16:09:42 +0530 | [diff] [blame] | 2919 | local_irq_save(flags); |
| 2920 | /* Update initial ID state */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2921 | mdwc->id_state = |
| 2922 | !!irq_read_line(mdwc->pmic_id_irq); |
| 2923 | if (mdwc->id_state == DWC3_ID_GROUND) |
Jack Pham | 9198d9f | 2013-04-09 17:54:54 -0700 | [diff] [blame] | 2924 | queue_work(system_nrt_wq, |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2925 | &mdwc->id_work); |
Manu Gautam | f08f7b6 | 2013-04-02 16:09:42 +0530 | [diff] [blame] | 2926 | local_irq_restore(flags); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2927 | enable_irq_wake(mdwc->pmic_id_irq); |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2928 | } |
David Keitel | ad4a028 | 2013-03-19 18:04:27 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2931 | if (mdwc->pmic_id_irq <= 0) { |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2932 | /* If no PMIC ID IRQ, use ADC for ID pin detection */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2933 | queue_work(system_nrt_wq, &mdwc->init_adc_work.work); |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2934 | device_create_file(&pdev->dev, &dev_attr_adc_enable); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2935 | mdwc->pmic_id_irq = 0; |
Jack Pham | 0cca941 | 2013-03-08 13:22:42 -0800 | [diff] [blame] | 2936 | } |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 2937 | } |
| 2938 | |
Ido Shayevitz | 7ad8ded | 2012-08-28 04:30:58 +0300 | [diff] [blame] | 2939 | res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
| 2940 | if (!res) { |
| 2941 | dev_dbg(&pdev->dev, "missing TCSR memory resource\n"); |
| 2942 | } else { |
| 2943 | tcsr = devm_ioremap_nocache(&pdev->dev, res->start, |
| 2944 | resource_size(res)); |
| 2945 | if (!tcsr) { |
| 2946 | dev_dbg(&pdev->dev, "tcsr ioremap failed\n"); |
| 2947 | } else { |
| 2948 | /* Enable USB3 on the primary USB port. */ |
| 2949 | writel_relaxed(0x1, tcsr); |
| 2950 | /* |
| 2951 | * Ensure that TCSR write is completed before |
| 2952 | * USB registers initialization. |
| 2953 | */ |
| 2954 | mb(); |
| 2955 | } |
| 2956 | } |
| 2957 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2958 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2959 | if (!res) { |
| 2960 | dev_err(&pdev->dev, "missing memory base resource\n"); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2961 | ret = -ENODEV; |
Jack Pham | 56a0a63 | 2013-03-08 13:18:42 -0800 | [diff] [blame] | 2962 | goto disable_hs_ldo; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2963 | } |
| 2964 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2965 | mdwc->base = devm_ioremap_nocache(&pdev->dev, res->start, |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2966 | resource_size(res)); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2967 | if (!mdwc->base) { |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2968 | dev_err(&pdev->dev, "ioremap failed\n"); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 2969 | ret = -ENODEV; |
Jack Pham | 56a0a63 | 2013-03-08 13:18:42 -0800 | [diff] [blame] | 2970 | goto disable_hs_ldo; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2971 | } |
| 2972 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2973 | mdwc->io_res = res; /* used to calculate chg block offset */ |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2974 | |
Vijayavardhan Vennapusa | 26a4960 | 2012-12-18 13:51:45 +0530 | [diff] [blame] | 2975 | if (of_property_read_u32(node, "qcom,dwc-hsphy-init", |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2976 | &mdwc->hsphy_init_seq)) |
Vijayavardhan Vennapusa | 26a4960 | 2012-12-18 13:51:45 +0530 | [diff] [blame] | 2977 | dev_dbg(&pdev->dev, "unable to read hsphy init seq\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2978 | else if (!mdwc->hsphy_init_seq) |
Vijayavardhan Vennapusa | 26a4960 | 2012-12-18 13:51:45 +0530 | [diff] [blame] | 2979 | dev_warn(&pdev->dev, "incorrect hsphyinitseq.Using PORvalue\n"); |
| 2980 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2981 | pm_runtime_set_active(mdwc->dev); |
| 2982 | pm_runtime_enable(mdwc->dev); |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 2983 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2984 | if (of_property_read_u32(node, "qcom,dwc-usb3-msm-dbm-eps", |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2985 | &mdwc->dbm_num_eps)) { |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2986 | dev_err(&pdev->dev, |
| 2987 | "unable to read platform data num of dbm eps\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2988 | mdwc->dbm_num_eps = DBM_MAX_EPS; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2989 | } |
| 2990 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2991 | if (mdwc->dbm_num_eps > DBM_MAX_EPS) { |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2992 | dev_err(&pdev->dev, |
| 2993 | "Driver doesn't support number of DBM EPs. " |
| 2994 | "max: %d, dbm_num_eps: %d\n", |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 2995 | DBM_MAX_EPS, mdwc->dbm_num_eps); |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2996 | ret = -ENODEV; |
Vijayavardhan Vennapusa | 8eb6873 | 2013-03-26 13:05:38 +0530 | [diff] [blame] | 2997 | goto disable_hs_ldo; |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 2998 | } |
Vijayavardhan Vennapusa | fc3db60 | 2013-08-20 17:54:54 +0530 | [diff] [blame] | 2999 | |
| 3000 | if (of_property_read_u32(node, "qcom,dwc-usb3-msm-tx-fifo-size", |
| 3001 | &mdwc->tx_fifo_size)) |
| 3002 | dev_err(&pdev->dev, |
| 3003 | "unable to read platform data tx fifo size\n"); |
| 3004 | |
| 3005 | if (of_property_read_u32(node, "qcom,dwc-usb3-msm-qdss-tx-fifo-size", |
| 3006 | &mdwc->qdss_tx_fifo_size)) |
| 3007 | dev_err(&pdev->dev, |
| 3008 | "unable to read platform data qdss tx fifo size\n"); |
| 3009 | |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 3010 | dwc3_set_notifier(&dwc3_msm_notify_event); |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3011 | /* usb_psy required only for vbus_notifications or charging support */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3012 | if (mdwc->ext_xceiv.otg_capability || |
| 3013 | !mdwc->charger.charging_disabled) { |
| 3014 | mdwc->usb_psy.name = "usb"; |
| 3015 | mdwc->usb_psy.type = POWER_SUPPLY_TYPE_USB; |
| 3016 | mdwc->usb_psy.supplied_to = dwc3_msm_pm_power_supplied_to; |
| 3017 | mdwc->usb_psy.num_supplicants = ARRAY_SIZE( |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3018 | dwc3_msm_pm_power_supplied_to); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3019 | mdwc->usb_psy.properties = dwc3_msm_pm_power_props_usb; |
| 3020 | mdwc->usb_psy.num_properties = |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3021 | ARRAY_SIZE(dwc3_msm_pm_power_props_usb); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3022 | mdwc->usb_psy.get_property = dwc3_msm_power_get_property_usb; |
| 3023 | mdwc->usb_psy.set_property = dwc3_msm_power_set_property_usb; |
| 3024 | mdwc->usb_psy.external_power_changed = |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3025 | dwc3_msm_external_power_changed; |
Pavankumar Kondeti | fbd4b14 | 2013-07-16 11:13:05 +0530 | [diff] [blame] | 3026 | mdwc->usb_psy.property_is_writeable = |
| 3027 | dwc3_msm_property_is_writeable; |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 3028 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3029 | ret = power_supply_register(&pdev->dev, &mdwc->usb_psy); |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3030 | if (ret < 0) { |
| 3031 | dev_err(&pdev->dev, |
| 3032 | "%s:power_supply_register usb failed\n", |
| 3033 | __func__); |
| 3034 | goto disable_hs_ldo; |
| 3035 | } |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 3036 | } |
| 3037 | |
Vijayavardhan Vennapusa | 8eb6873 | 2013-03-26 13:05:38 +0530 | [diff] [blame] | 3038 | if (node) { |
| 3039 | ret = of_platform_populate(node, NULL, NULL, &pdev->dev); |
| 3040 | if (ret) { |
| 3041 | dev_err(&pdev->dev, |
| 3042 | "failed to add create dwc3 core\n"); |
| 3043 | goto put_psupply; |
| 3044 | } |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3045 | } |
| 3046 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3047 | mdwc->bus_scale_table = msm_bus_cl_get_pdata(pdev); |
| 3048 | if (!mdwc->bus_scale_table) { |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 3049 | dev_err(&pdev->dev, "bus scaling is disabled\n"); |
| 3050 | } else { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3051 | mdwc->bus_perf_client = |
| 3052 | msm_bus_scale_register_client(mdwc->bus_scale_table); |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 3053 | ret = msm_bus_scale_client_update_request( |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3054 | mdwc->bus_perf_client, 1); |
Manu Gautam | 2617deb | 2012-08-31 17:50:06 -0700 | [diff] [blame] | 3055 | if (ret) |
| 3056 | dev_err(&pdev->dev, "Failed to vote for bus scaling\n"); |
| 3057 | } |
| 3058 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3059 | mdwc->otg_xceiv = usb_get_transceiver(); |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3060 | /* Register with OTG if present, ignore USB2 OTG using other PHY */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3061 | if (mdwc->otg_xceiv && |
| 3062 | !(mdwc->otg_xceiv->flags & ENABLE_SECONDARY_PHY)) { |
Hemant Kumar | 6d7b724 | 2013-04-18 16:44:38 -0700 | [diff] [blame] | 3063 | /* Skip charger detection for simulator targets */ |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3064 | if (!mdwc->charger.skip_chg_detect) { |
| 3065 | mdwc->charger.start_detection = dwc3_start_chg_det; |
| 3066 | ret = dwc3_set_charger(mdwc->otg_xceiv->otg, |
| 3067 | &mdwc->charger); |
| 3068 | if (ret || !mdwc->charger.notify_detection_complete) { |
Hemant Kumar | 6d7b724 | 2013-04-18 16:44:38 -0700 | [diff] [blame] | 3069 | dev_err(&pdev->dev, |
| 3070 | "failed to register charger: %d\n", |
| 3071 | ret); |
| 3072 | goto put_xcvr; |
| 3073 | } |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 3074 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3075 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3076 | if (mdwc->ext_xceiv.otg_capability) |
| 3077 | mdwc->ext_xceiv.ext_block_reset = dwc3_msm_block_reset; |
| 3078 | ret = dwc3_set_ext_xceiv(mdwc->otg_xceiv->otg, |
| 3079 | &mdwc->ext_xceiv); |
| 3080 | if (ret || !mdwc->ext_xceiv.notify_ext_events) { |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3081 | dev_err(&pdev->dev, "failed to register xceiver: %d\n", |
| 3082 | ret); |
| 3083 | goto put_xcvr; |
| 3084 | } |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 3085 | } else { |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3086 | dev_dbg(&pdev->dev, "No OTG, DWC3 running in host only mode\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3087 | mdwc->host_mode = 1; |
| 3088 | mdwc->vbus_otg = devm_regulator_get(&pdev->dev, "vbus_dwc3"); |
| 3089 | if (IS_ERR(mdwc->vbus_otg)) { |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3090 | dev_dbg(&pdev->dev, "Failed to get vbus regulator\n"); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3091 | mdwc->vbus_otg = 0; |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3092 | } else { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3093 | ret = regulator_enable(mdwc->vbus_otg); |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3094 | if (ret) { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3095 | mdwc->vbus_otg = 0; |
Manu Gautam | bb825d7 | 2013-03-12 16:25:42 +0530 | [diff] [blame] | 3096 | dev_err(&pdev->dev, "Failed to enable vbus_otg\n"); |
| 3097 | } |
| 3098 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3099 | mdwc->otg_xceiv = NULL; |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 3100 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3101 | if (mdwc->ext_xceiv.otg_capability && mdwc->charger.start_detection) { |
| 3102 | ret = dwc3_msm_setup_cdev(mdwc); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 3103 | if (ret) |
| 3104 | dev_err(&pdev->dev, "Fail to setup dwc3 setup cdev\n"); |
| 3105 | } |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 3106 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3107 | device_init_wakeup(mdwc->dev, 1); |
| 3108 | pm_stay_awake(mdwc->dev); |
Vijayavardhan Vennapusa | 8a011c9 | 2013-07-29 09:06:48 +0530 | [diff] [blame] | 3109 | dwc3_msm_debugfs_init(mdwc); |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3110 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3111 | return 0; |
| 3112 | |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 3113 | put_xcvr: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3114 | usb_put_transceiver(mdwc->otg_xceiv); |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 3115 | put_psupply: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3116 | if (mdwc->usb_psy.dev) |
| 3117 | power_supply_unregister(&mdwc->usb_psy); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3118 | disable_hs_ldo: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3119 | dwc3_hsusb_ldo_enable(mdwc, 0); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3120 | free_hs_ldo_init: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3121 | dwc3_hsusb_ldo_init(mdwc, 0); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3122 | disable_hs_vddcx: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3123 | regulator_disable(mdwc->hsusb_vddcx); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3124 | unconfig_hs_vddcx: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3125 | dwc3_hsusb_config_vddcx(mdwc, 0); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3126 | disable_ss_ldo: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3127 | dwc3_ssusb_ldo_enable(mdwc, 0); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3128 | free_ss_ldo_init: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3129 | dwc3_ssusb_ldo_init(mdwc, 0); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3130 | disable_ss_vddcx: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3131 | regulator_disable(mdwc->ssusb_vddcx); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3132 | unconfig_ss_vddcx: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3133 | dwc3_ssusb_config_vddcx(mdwc, 0); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 3134 | disable_ref_clk: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3135 | clk_disable_unprepare(mdwc->ref_clk); |
Jack Pham | 22698b8 | 2013-02-13 17:45:06 -0800 | [diff] [blame] | 3136 | disable_utmi_clk: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3137 | clk_disable_unprepare(mdwc->utmi_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 3138 | disable_sleep_a_clk: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3139 | clk_disable_unprepare(mdwc->hsphy_sleep_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 3140 | disable_sleep_clk: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3141 | clk_disable_unprepare(mdwc->sleep_clk); |
Manu Gautam | 3e9ad35 | 2012-08-16 14:44:47 -0700 | [diff] [blame] | 3142 | disable_iface_clk: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3143 | clk_disable_unprepare(mdwc->iface_clk); |
Manu Gautam | 1742db2 | 2012-06-19 13:33:24 +0530 | [diff] [blame] | 3144 | disable_core_clk: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3145 | clk_disable_unprepare(mdwc->core_clk); |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 3146 | disable_xo: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3147 | clk_disable_unprepare(mdwc->xo_clk); |
Vijayavardhan Vennapusa | dec1fe6 | 2013-02-12 16:05:14 +0530 | [diff] [blame] | 3148 | put_xo: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3149 | clk_put(mdwc->xo_clk); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 3150 | disable_dwc3_gdsc: |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3151 | dwc3_msm_config_gdsc(mdwc, 0); |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3152 | |
| 3153 | return ret; |
| 3154 | } |
| 3155 | |
| 3156 | static int __devexit dwc3_msm_remove(struct platform_device *pdev) |
| 3157 | { |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3158 | struct dwc3_msm *mdwc = platform_get_drvdata(pdev); |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3159 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3160 | if (!mdwc->ext_chg_device) { |
| 3161 | device_destroy(mdwc->ext_chg_class, mdwc->ext_chg_dev); |
| 3162 | cdev_del(&mdwc->ext_chg_cdev); |
| 3163 | class_destroy(mdwc->ext_chg_class); |
| 3164 | unregister_chrdev_region(mdwc->ext_chg_dev, 1); |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 3165 | } |
| 3166 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3167 | if (mdwc->id_adc_detect) |
Siddartha Mohanadoss | 88a3fde | 2013-06-24 16:18:52 -0700 | [diff] [blame] | 3168 | qpnp_adc_tm_usbid_end(mdwc->adc_tm_dev); |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3169 | if (dwc3_debugfs_root) |
| 3170 | debugfs_remove_recursive(dwc3_debugfs_root); |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3171 | if (mdwc->otg_xceiv) { |
| 3172 | dwc3_start_chg_det(&mdwc->charger, false); |
| 3173 | usb_put_transceiver(mdwc->otg_xceiv); |
Manu Gautam | 8c64281 | 2012-06-07 10:35:10 +0530 | [diff] [blame] | 3174 | } |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3175 | if (mdwc->usb_psy.dev) |
| 3176 | power_supply_unregister(&mdwc->usb_psy); |
| 3177 | if (mdwc->vbus_otg) |
| 3178 | regulator_disable(mdwc->vbus_otg); |
Jack Pham | 0fc1233 | 2012-11-19 13:14:22 -0800 | [diff] [blame] | 3179 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3180 | pm_runtime_disable(mdwc->dev); |
| 3181 | device_init_wakeup(mdwc->dev, 0); |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3182 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3183 | dwc3_hsusb_ldo_enable(mdwc, 0); |
| 3184 | dwc3_hsusb_ldo_init(mdwc, 0); |
| 3185 | regulator_disable(mdwc->hsusb_vddcx); |
| 3186 | dwc3_hsusb_config_vddcx(mdwc, 0); |
| 3187 | dwc3_ssusb_ldo_enable(mdwc, 0); |
| 3188 | dwc3_ssusb_ldo_init(mdwc, 0); |
| 3189 | regulator_disable(mdwc->ssusb_vddcx); |
| 3190 | dwc3_ssusb_config_vddcx(mdwc, 0); |
| 3191 | clk_disable_unprepare(mdwc->core_clk); |
| 3192 | clk_disable_unprepare(mdwc->iface_clk); |
| 3193 | clk_disable_unprepare(mdwc->sleep_clk); |
| 3194 | clk_disable_unprepare(mdwc->hsphy_sleep_clk); |
| 3195 | clk_disable_unprepare(mdwc->ref_clk); |
| 3196 | clk_disable_unprepare(mdwc->xo_clk); |
| 3197 | clk_put(mdwc->xo_clk); |
Manu Gautam | 60e0135 | 2012-05-29 09:00:34 +0530 | [diff] [blame] | 3198 | |
Jack Pham | 8016246 | 2013-07-10 11:59:01 -0700 | [diff] [blame] | 3199 | dwc3_msm_config_gdsc(mdwc, 0); |
Hemant Kumar | 086bf6b | 2013-06-10 19:29:27 -0700 | [diff] [blame] | 3200 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3201 | return 0; |
| 3202 | } |
| 3203 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3204 | static int dwc3_msm_pm_suspend(struct device *dev) |
| 3205 | { |
| 3206 | int ret = 0; |
| 3207 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 3208 | |
| 3209 | dev_dbg(dev, "dwc3-msm PM suspend\n"); |
| 3210 | |
Manu Gautam | 8d98a57 | 2013-01-21 16:34:50 +0530 | [diff] [blame] | 3211 | flush_delayed_work_sync(&mdwc->resume_work); |
| 3212 | if (!atomic_read(&mdwc->in_lpm)) { |
| 3213 | dev_err(mdwc->dev, "Abort PM suspend!! (USB is outside LPM)\n"); |
| 3214 | return -EBUSY; |
| 3215 | } |
| 3216 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3217 | ret = dwc3_msm_suspend(mdwc); |
| 3218 | if (!ret) |
| 3219 | atomic_set(&mdwc->pm_suspended, 1); |
| 3220 | |
| 3221 | return ret; |
| 3222 | } |
| 3223 | |
| 3224 | static int dwc3_msm_pm_resume(struct device *dev) |
| 3225 | { |
| 3226 | int ret = 0; |
| 3227 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 3228 | |
| 3229 | dev_dbg(dev, "dwc3-msm PM resume\n"); |
| 3230 | |
| 3231 | atomic_set(&mdwc->pm_suspended, 0); |
| 3232 | if (mdwc->resume_pending) { |
| 3233 | mdwc->resume_pending = false; |
| 3234 | |
| 3235 | ret = dwc3_msm_resume(mdwc); |
| 3236 | /* Update runtime PM status */ |
| 3237 | pm_runtime_disable(dev); |
| 3238 | pm_runtime_set_active(dev); |
| 3239 | pm_runtime_enable(dev); |
| 3240 | |
| 3241 | /* Let OTG know about resume event and update pm_count */ |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 3242 | if (mdwc->otg_xceiv) { |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3243 | mdwc->ext_xceiv.notify_ext_events(mdwc->otg_xceiv->otg, |
| 3244 | DWC3_EVENT_PHY_RESUME); |
Vijayavardhan Vennapusa | d2993b8 | 2012-10-22 13:08:21 +0530 | [diff] [blame] | 3245 | if (mdwc->ext_xceiv.otg_capability) |
| 3246 | mdwc->ext_xceiv.notify_ext_events( |
| 3247 | mdwc->otg_xceiv->otg, |
| 3248 | DWC3_EVENT_XCEIV_STATE); |
| 3249 | } |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | return ret; |
| 3253 | } |
| 3254 | |
| 3255 | static int dwc3_msm_runtime_idle(struct device *dev) |
| 3256 | { |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 3257 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 3258 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3259 | dev_dbg(dev, "DWC3-msm runtime idle\n"); |
| 3260 | |
Pavankumar Kondeti | 08693e7 | 2013-05-03 11:55:48 +0530 | [diff] [blame] | 3261 | if (mdwc->ext_chg_active) { |
| 3262 | dev_dbg(dev, "Deferring LPM\n"); |
| 3263 | /* |
| 3264 | * Charger detection may happen in user space. |
| 3265 | * Delay entering LPM by 3 sec. Otherwise we |
| 3266 | * have to exit LPM when user space begins |
| 3267 | * charger detection. |
| 3268 | * |
| 3269 | * This timer will be canceled when user space |
| 3270 | * votes against LPM by incrementing PM usage |
| 3271 | * counter. We enter low power mode when |
| 3272 | * PM usage counter is decremented. |
| 3273 | */ |
| 3274 | pm_schedule_suspend(dev, 3000); |
| 3275 | return -EAGAIN; |
| 3276 | } |
| 3277 | |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3278 | return 0; |
| 3279 | } |
| 3280 | |
| 3281 | static int dwc3_msm_runtime_suspend(struct device *dev) |
| 3282 | { |
| 3283 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 3284 | |
| 3285 | dev_dbg(dev, "DWC3-msm runtime suspend\n"); |
| 3286 | |
| 3287 | return dwc3_msm_suspend(mdwc); |
| 3288 | } |
| 3289 | |
| 3290 | static int dwc3_msm_runtime_resume(struct device *dev) |
| 3291 | { |
| 3292 | struct dwc3_msm *mdwc = dev_get_drvdata(dev); |
| 3293 | |
| 3294 | dev_dbg(dev, "DWC3-msm runtime resume\n"); |
| 3295 | |
| 3296 | return dwc3_msm_resume(mdwc); |
| 3297 | } |
| 3298 | |
| 3299 | static const struct dev_pm_ops dwc3_msm_dev_pm_ops = { |
| 3300 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_msm_pm_suspend, dwc3_msm_pm_resume) |
| 3301 | SET_RUNTIME_PM_OPS(dwc3_msm_runtime_suspend, dwc3_msm_runtime_resume, |
| 3302 | dwc3_msm_runtime_idle) |
| 3303 | }; |
| 3304 | |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3305 | static const struct of_device_id of_dwc3_matach[] = { |
| 3306 | { |
| 3307 | .compatible = "qcom,dwc-usb3-msm", |
| 3308 | }, |
| 3309 | { }, |
| 3310 | }; |
| 3311 | MODULE_DEVICE_TABLE(of, of_dwc3_matach); |
| 3312 | |
| 3313 | static struct platform_driver dwc3_msm_driver = { |
| 3314 | .probe = dwc3_msm_probe, |
| 3315 | .remove = __devexit_p(dwc3_msm_remove), |
| 3316 | .driver = { |
| 3317 | .name = "msm-dwc3", |
Manu Gautam | b506727 | 2012-07-02 09:53:41 +0530 | [diff] [blame] | 3318 | .pm = &dwc3_msm_dev_pm_ops, |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3319 | .of_match_table = of_dwc3_matach, |
| 3320 | }, |
| 3321 | }; |
| 3322 | |
Manu Gautam | 377821c | 2012-09-28 16:53:24 +0530 | [diff] [blame] | 3323 | MODULE_LICENSE("GPL v2"); |
Ido Shayevitz | ef72ddd | 2012-03-28 18:55:55 +0200 | [diff] [blame] | 3324 | MODULE_DESCRIPTION("DesignWare USB3 MSM Glue Layer"); |
| 3325 | |
| 3326 | static int __devinit dwc3_msm_init(void) |
| 3327 | { |
| 3328 | return platform_driver_register(&dwc3_msm_driver); |
| 3329 | } |
| 3330 | module_init(dwc3_msm_init); |
| 3331 | |
| 3332 | static void __exit dwc3_msm_exit(void) |
| 3333 | { |
| 3334 | platform_driver_unregister(&dwc3_msm_driver); |
| 3335 | } |
| 3336 | module_exit(dwc3_msm_exit); |