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