Ajay Agarwal | 1ef6469 | 2018-01-23 19:46:25 +0530 | [diff] [blame] | 1 | /* include/linux/usb/msm_hsusb.h |
| 2 | * |
| 3 | * Copyright (C) 2008 Google, Inc. |
| 4 | * Author: Brian Swetland <swetland@google.com> |
| 5 | * Copyright (c) 2009-2018, The Linux Foundation. All rights reserved. |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #ifndef __ASM_ARCH_MSM_HSUSB_H |
| 19 | #define __ASM_ARCH_MSM_HSUSB_H |
| 20 | |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/usb/ch9.h> |
| 23 | #include <linux/usb/gadget.h> |
| 24 | #include <linux/usb/otg.h> |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/pm_qos.h> |
| 27 | #include <linux/hrtimer.h> |
| 28 | #include <linux/power_supply.h> |
| 29 | #include <linux/cdev.h> |
| 30 | #include <linux/usb_bam.h> |
| 31 | #include <linux/extcon.h> |
| 32 | #include <linux/regulator/driver.h> |
| 33 | /** |
| 34 | * Requested USB votes for NOC frequency |
| 35 | * |
| 36 | * USB_NOC_NOM_VOTE Vote for NOM set of NOC frequencies |
| 37 | * USB_NOC_SVS_VOTE Vote for SVS set of NOC frequencies |
| 38 | * |
| 39 | */ |
| 40 | enum usb_noc_mode { |
| 41 | USB_NOC_NOM_VOTE = 0, |
| 42 | USB_NOC_SVS_VOTE, |
| 43 | USB_NOC_NUM_VOTE, |
| 44 | }; |
| 45 | |
| 46 | /** |
| 47 | * Different states involved in USB charger detection. |
| 48 | * |
| 49 | * USB_CHG_STATE_UNDEFINED USB charger is not connected or detection |
| 50 | * process is not yet started. |
| 51 | * USB_CHG_STATE_IN_PROGRESS Charger detection in progress |
| 52 | * USB_CHG_STATE_WAIT_FOR_DCD Waiting for Data pins contact. |
| 53 | * USB_CHG_STATE_DCD_DONE Data pin contact is detected. |
| 54 | * USB_CHG_STATE_PRIMARY_DONE Primary detection is completed (Detects |
| 55 | * between SDP and DCP/CDP). |
| 56 | * USB_CHG_STATE_SECONDARY_DONE Secondary detection is completed (Detects |
| 57 | * between DCP and CDP). |
| 58 | * USB_CHG_STATE_DETECTED USB charger type is determined. |
| 59 | * |
| 60 | */ |
| 61 | enum usb_chg_state { |
| 62 | USB_CHG_STATE_UNDEFINED = 0, |
| 63 | USB_CHG_STATE_IN_PROGRESS, |
| 64 | USB_CHG_STATE_WAIT_FOR_DCD, |
| 65 | USB_CHG_STATE_DCD_DONE, |
| 66 | USB_CHG_STATE_PRIMARY_DONE, |
| 67 | USB_CHG_STATE_SECONDARY_DONE, |
| 68 | USB_CHG_STATE_DETECTED, |
| 69 | }; |
| 70 | |
| 71 | /** |
| 72 | * USB charger types |
| 73 | * |
| 74 | * USB_INVALID_CHARGER Invalid USB charger. |
| 75 | * USB_SDP_CHARGER Standard downstream port. Refers to a downstream port |
| 76 | * on USB2.0 compliant host/hub. |
| 77 | * USB_DCP_CHARGER Dedicated charger port (AC charger/ Wall charger). |
| 78 | * USB_CDP_CHARGER Charging downstream port. Enumeration can happen and |
| 79 | * IDEV_CHG_MAX can be drawn irrespective of USB state. |
| 80 | * USB_NONCOMPLIANT_CHARGER A non-compliant charger pull DP and DM to specific |
| 81 | * voltages between 2.0-3.3v for identification. |
| 82 | * |
| 83 | */ |
| 84 | enum usb_chg_type { |
| 85 | USB_INVALID_CHARGER = 0, |
| 86 | USB_SDP_CHARGER, |
| 87 | USB_DCP_CHARGER, |
| 88 | USB_CDP_CHARGER, |
| 89 | USB_NONCOMPLIANT_CHARGER, |
| 90 | USB_FLOATED_CHARGER, |
| 91 | }; |
| 92 | |
| 93 | /** |
| 94 | * Maintain state for hvdcp external charger status |
| 95 | * DEFAULT This is used when DCP is detected |
| 96 | * ACTIVE This is used when ioctl is called to block LPM |
| 97 | * INACTIVE This is used when ioctl is called to unblock LPM |
| 98 | */ |
| 99 | |
| 100 | enum usb_ext_chg_status { |
| 101 | DEFAULT = 1, |
| 102 | ACTIVE, |
| 103 | INACTIVE, |
| 104 | }; |
| 105 | |
| 106 | /** |
| 107 | * USB ID state |
| 108 | */ |
| 109 | enum usb_id_state { |
| 110 | USB_ID_GROUND = 0, |
| 111 | USB_ID_FLOAT, |
| 112 | }; |
| 113 | |
| 114 | #define USB_NUM_BUS_CLOCKS 3 |
| 115 | |
| 116 | /** |
| 117 | * struct msm_otg: OTG driver data. Shared by HCD and DCD. |
| 118 | * @otg: USB OTG Transceiver structure. |
| 119 | * @pdata: otg device platform data. |
| 120 | * @irq: IRQ number assigned for HSUSB controller. |
| 121 | * @async_irq: IRQ number used by some controllers during low power state |
| 122 | * @phy_irq: IRQ number assigned for PHY to notify events like id and line |
| 123 | state changes. |
| 124 | * @pclk: clock struct of iface_clk. |
| 125 | * @core_clk: clock struct of core_bus_clk. |
| 126 | * @sleep_clk: clock struct of sleep_clk for USB PHY. |
| 127 | * @phy_reset_clk: clock struct of phy_reset_clk for USB PHY. This clock is |
| 128 | a reset only clock and resets the PHY, ULPI bridge and |
| 129 | CSR wrapper. |
| 130 | * @phy_por_clk: clock struct of phy_por_clk for USB PHY. This clock is |
| 131 | a reset only clock and resets only the PHY (POR). |
| 132 | * @phy_csr_clk: clock struct of phy_csr_clk for USB PHY. This clock is |
| 133 | required to access PHY CSR registers via AHB2PHY interface. |
| 134 | * @bus_clks: bimc/snoc/pcnoc clock struct. |
| 135 | * @core_reset: Reset control for core_clk |
| 136 | * @phy_reset: Reset control for phy_reset_clk |
| 137 | * @phy_por_reset: Reset control for phy_por_clk |
| 138 | * @default_noc_mode: default frequency for NOC clocks - SVS or NOM |
| 139 | * @core_clk_rate: core clk max frequency |
| 140 | * @regs: ioremapped register base address. |
| 141 | * @usb_phy_ctrl_reg: relevant PHY_CTRL_REG register base address. |
| 142 | * @inputs: OTG state machine inputs(Id, SessValid etc). |
| 143 | * @sm_work: OTG state machine work. |
| 144 | * @sm_work_pending: OTG state machine work is pending, queued post pm_resume |
| 145 | * @resume_pending: USB h/w lpm_exit pending. Done on next sm_work run |
| 146 | * @pm_suspended: OTG device is system(PM) suspended. |
| 147 | * @pm_notify: Notifier to receive system wide PM transition events. |
| 148 | It is used to defer wakeup events processing until |
| 149 | system is RESUMED. |
| 150 | * @in_lpm: indicates low power mode (LPM) state. |
| 151 | * @async_int: IRQ line on which ASYNC interrupt arrived in LPM. |
| 152 | * @cur_power: The amount of mA available from downstream port. |
| 153 | * @otg_wq: Strict order otg workqueue for OTG works (SM/ID/SUSPEND). |
| 154 | * @chg_work: Charger detection work. |
| 155 | * @chg_state: The state of charger detection process. |
| 156 | * @chg_type: The type of charger attached. |
| 157 | * @bus_perf_client: Bus performance client handle to request BUS bandwidth |
| 158 | * @host_bus_suspend: indicates host bus suspend or not. |
| 159 | * @device_bus_suspend: indicates device bus suspend or not. |
| 160 | * @bus_clks_enabled: indicates pcnoc/snoc/bimc clocks are on or not. |
| 161 | * @chg_check_timer: The timer used to implement the workaround to detect |
| 162 | * very slow plug in of wall charger. |
| 163 | * @bc1p2_current_max: Max charging current allowed as per bc1.2 chg detection |
| 164 | * @typec_current_max: Max charging current allowed as per type-c chg detection |
| 165 | * @is_ext_chg_dcp: To indicate whether charger detected by external entity |
| 166 | SMB hardware is DCP charger or not. |
| 167 | * @ext_id_irq: IRQ for ID interrupt. |
| 168 | * @phy_irq_pending: Gets set when PHY IRQ arrives in LPM. |
| 169 | * @id_state: Indicates USBID line status. |
| 170 | * @rm_pulldown: Indicates pulldown status on D+ and D- data lines. |
| 171 | * @extcon_vbus: Used for VBUS notification registration. |
| 172 | * @extcon_id: Used for ID notification registration. |
| 173 | * @vbus_nb: Notification callback for VBUS event. |
| 174 | * @id_nb: Notification callback for ID event. |
| 175 | * @dpdm_desc: Regulator descriptor for D+ and D- voting. |
| 176 | * @dpdm_rdev: Regulator class device for dpdm regulator. |
| 177 | * @dbg_idx: Dynamic debug buffer Index. |
| 178 | * @dbg_lock: Dynamic debug buffer Lock. |
| 179 | * @buf: Dynamic Debug Buffer. |
| 180 | * @max_nominal_system_clk_rate: max freq at which system clock can run in |
| 181 | nominal mode. |
| 182 | */ |
| 183 | struct msm_otg { |
| 184 | struct usb_phy phy; |
| 185 | struct msm_otg_platform_data *pdata; |
| 186 | struct platform_device *pdev; |
| 187 | int irq; |
| 188 | int async_irq; |
| 189 | int phy_irq; |
| 190 | struct clk *xo_clk; |
| 191 | struct clk *pclk; |
| 192 | struct clk *core_clk; |
| 193 | struct clk *sleep_clk; |
| 194 | struct clk *phy_reset_clk; |
| 195 | struct clk *phy_por_clk; |
| 196 | struct clk *phy_csr_clk; |
| 197 | struct clk *bus_clks[USB_NUM_BUS_CLOCKS]; |
| 198 | struct clk *phy_ref_clk; |
| 199 | struct reset_control *core_reset; |
| 200 | struct reset_control *phy_reset; |
| 201 | struct reset_control *phy_por_reset; |
| 202 | long core_clk_rate; |
| 203 | long core_clk_svs_rate; |
| 204 | long core_clk_nominal_rate; |
| 205 | enum usb_noc_mode default_noc_mode; |
| 206 | struct resource *io_res; |
| 207 | void __iomem *regs; |
| 208 | void __iomem *phy_csr_regs; |
| 209 | void __iomem *usb_phy_ctrl_reg; |
| 210 | #define ID 0 |
| 211 | #define B_SESS_VLD 1 |
| 212 | #define A_BUS_SUSPEND 14 |
| 213 | #define B_FALSE_SDP 18 |
| 214 | unsigned long inputs; |
| 215 | struct work_struct sm_work; |
| 216 | bool sm_work_pending; |
| 217 | bool resume_pending; |
| 218 | atomic_t pm_suspended; |
| 219 | struct notifier_block pm_notify; |
| 220 | atomic_t in_lpm; |
| 221 | bool err_event_seen; |
| 222 | int async_int; |
| 223 | unsigned int cur_power; |
| 224 | struct workqueue_struct *otg_wq; |
| 225 | struct delayed_work chg_work; |
| 226 | struct delayed_work id_status_work; |
| 227 | enum usb_chg_state chg_state; |
| 228 | enum usb_chg_type chg_type; |
| 229 | unsigned int dcd_time; |
| 230 | unsigned long caps; |
| 231 | uint32_t bus_perf_client; |
| 232 | bool host_bus_suspend; |
| 233 | bool device_bus_suspend; |
| 234 | bool bus_clks_enabled; |
| 235 | struct timer_list chg_check_timer; |
| 236 | /* |
| 237 | * Allowing PHY power collpase turns off the HSUSB 3.3v and 1.8v |
| 238 | * analog regulators while going to low power mode. |
| 239 | * Currently only 28nm PHY has the support to allowing PHY |
| 240 | * power collapse since it doesn't have leakage currents while |
| 241 | * turning off the power rails. |
| 242 | */ |
| 243 | #define ALLOW_PHY_POWER_COLLAPSE BIT(0) |
| 244 | /* |
| 245 | * Allow PHY RETENTION mode before turning off the digital |
| 246 | * voltage regulator(VDDCX). |
| 247 | */ |
| 248 | #define ALLOW_PHY_RETENTION BIT(1) |
| 249 | /* |
| 250 | * Allow putting the core in Low Power mode, when |
| 251 | * USB bus is suspended but cable is connected. |
| 252 | */ |
| 253 | #define ALLOW_LPM_ON_DEV_SUSPEND BIT(2) |
| 254 | /* |
| 255 | * Allowing PHY regulators LPM puts the HSUSB 3.3v and 1.8v |
| 256 | * analog regulators into LPM while going to USB low power mode. |
| 257 | */ |
| 258 | #define ALLOW_PHY_REGULATORS_LPM BIT(3) |
| 259 | /* |
| 260 | * Allow PHY RETENTION mode before turning off the digital |
| 261 | * voltage regulator(VDDCX) during host mode. |
| 262 | */ |
| 263 | #define ALLOW_HOST_PHY_RETENTION BIT(4) |
| 264 | /* |
| 265 | * Allow VDD minimization without putting PHY into retention |
| 266 | * for fixing PHY current leakage issue when LDOs ar turned off. |
| 267 | */ |
| 268 | #define ALLOW_VDD_MIN_WITH_RETENTION_DISABLED BIT(5) |
| 269 | |
| 270 | /* |
| 271 | * PHY can keep D+ pull-up during peripheral bus suspend and |
| 272 | * D+/D- pull-down during host bus suspend without any |
| 273 | * re-work. This is possible only when PHY DVDD is supplied |
| 274 | * by a PMIC LDO (unlike VDDCX/VDDMX). |
| 275 | */ |
| 276 | #define ALLOW_BUS_SUSPEND_WITHOUT_REWORK BIT(6) |
| 277 | unsigned long lpm_flags; |
| 278 | #define PHY_PWR_COLLAPSED BIT(0) |
| 279 | #define PHY_RETENTIONED BIT(1) |
| 280 | #define XO_SHUTDOWN BIT(2) |
| 281 | #define CLOCKS_DOWN BIT(3) |
| 282 | #define PHY_REGULATORS_LPM BIT(4) |
| 283 | int reset_counter; |
| 284 | unsigned int online; |
| 285 | unsigned int host_mode; |
| 286 | unsigned int bc1p2_current_max; |
| 287 | unsigned int typec_current_max; |
| 288 | |
| 289 | dev_t ext_chg_dev; |
| 290 | struct cdev ext_chg_cdev; |
| 291 | struct class *ext_chg_class; |
| 292 | struct device *ext_chg_device; |
| 293 | bool ext_chg_opened; |
| 294 | enum usb_ext_chg_status ext_chg_active; |
| 295 | struct completion ext_chg_wait; |
| 296 | struct pinctrl *phy_pinctrl; |
| 297 | bool is_ext_chg_dcp; |
| 298 | struct qpnp_vadc_chip *vadc_dev; |
| 299 | int ext_id_irq; |
| 300 | bool phy_irq_pending; |
| 301 | enum usb_id_state id_state; |
| 302 | bool rm_pulldown; |
| 303 | struct extcon_dev *extcon_vbus; |
| 304 | struct extcon_dev *extcon_id; |
| 305 | struct notifier_block vbus_nb; |
| 306 | struct notifier_block id_nb; |
| 307 | struct regulator_desc dpdm_rdesc; |
| 308 | struct regulator_dev *dpdm_rdev; |
| 309 | /* Maximum debug message length */ |
| 310 | #define DEBUG_MSG_LEN 128UL |
| 311 | /* Maximum number of messages */ |
| 312 | #define DEBUG_MAX_MSG 256UL |
| 313 | unsigned int dbg_idx; |
| 314 | rwlock_t dbg_lock; |
| 315 | |
| 316 | char (buf[DEBUG_MAX_MSG])[DEBUG_MSG_LEN]; /* buffer */ |
| 317 | unsigned int vbus_state; |
| 318 | unsigned int usb_irq_count; |
| 319 | int pm_qos_latency; |
| 320 | struct pm_qos_request pm_qos_req_dma; |
| 321 | struct delayed_work perf_vote_work; |
| 322 | }; |
| 323 | |
| 324 | struct ci13xxx_platform_data { |
| 325 | u8 usb_core_id; |
| 326 | /* |
| 327 | * value of 2^(log2_itc-1) will be used as the interrupt threshold |
| 328 | * (ITC), when log2_itc is between 1 to 7. |
| 329 | */ |
| 330 | int log2_itc; |
| 331 | bool l1_supported; |
| 332 | bool enable_ahb2ahb_bypass; |
| 333 | bool enable_streaming; |
| 334 | bool enable_axi_prefetch; |
| 335 | }; |
| 336 | |
| 337 | #ifdef CONFIG_USB_BAM |
| 338 | void msm_bam_set_usb_host_dev(struct device *dev); |
| 339 | bool msm_usb_bam_enable(enum usb_ctrl ctrl, bool bam_enable); |
| 340 | int msm_do_bam_disable_enable(enum usb_ctrl ctrl); |
| 341 | #else |
| 342 | static inline void msm_bam_set_usb_host_dev(struct device *dev) {} |
| 343 | static inline bool msm_usb_bam_enable(enum usb_ctrl ctrl, bool bam_enable) |
| 344 | { |
| 345 | return true; |
| 346 | } |
| 347 | int msm_do_bam_disable_enable(enum usb_ctrl ctrl) { return true; } |
| 348 | #endif |
| 349 | #ifdef CONFIG_USB_CI13XXX_MSM |
| 350 | void msm_hw_soft_reset(void); |
| 351 | #else |
| 352 | static inline void msm_hw_soft_reset(void) |
| 353 | { |
| 354 | } |
| 355 | #endif |
| 356 | |
| 357 | #endif |