Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* Copyright (c) 2018, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Inspired by dwc3-of-simple.c |
| 5 | */ |
| 6 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 7 | #include <linux/acpi.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8 | #include <linux/io.h> |
| 9 | #include <linux/of.h> |
| 10 | #include <linux/clk.h> |
| 11 | #include <linux/irq.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 12 | #include <linux/of_clk.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/extcon.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 16 | #include <linux/interconnect.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 17 | #include <linux/of_platform.h> |
| 18 | #include <linux/platform_device.h> |
| 19 | #include <linux/phy/phy.h> |
| 20 | #include <linux/usb/of.h> |
| 21 | #include <linux/reset.h> |
| 22 | #include <linux/iopoll.h> |
| 23 | |
| 24 | #include "core.h" |
| 25 | |
| 26 | /* USB QSCRATCH Hardware registers */ |
| 27 | #define QSCRATCH_HS_PHY_CTRL 0x10 |
| 28 | #define UTMI_OTG_VBUS_VALID BIT(20) |
| 29 | #define SW_SESSVLD_SEL BIT(28) |
| 30 | |
| 31 | #define QSCRATCH_SS_PHY_CTRL 0x30 |
| 32 | #define LANE0_PWR_PRESENT BIT(24) |
| 33 | |
| 34 | #define QSCRATCH_GENERAL_CFG 0x08 |
| 35 | #define PIPE_UTMI_CLK_SEL BIT(0) |
| 36 | #define PIPE3_PHYSTATUS_SW BIT(3) |
| 37 | #define PIPE_UTMI_CLK_DIS BIT(8) |
| 38 | |
| 39 | #define PWR_EVNT_IRQ_STAT_REG 0x58 |
| 40 | #define PWR_EVNT_LPM_IN_L2_MASK BIT(4) |
| 41 | #define PWR_EVNT_LPM_OUT_L2_MASK BIT(5) |
| 42 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 43 | #define SDM845_QSCRATCH_BASE_OFFSET 0xf8800 |
| 44 | #define SDM845_QSCRATCH_SIZE 0x400 |
| 45 | #define SDM845_DWC3_CORE_SIZE 0xcd00 |
| 46 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 47 | /* Interconnect path bandwidths in MBps */ |
| 48 | #define USB_MEMORY_AVG_HS_BW MBps_to_icc(240) |
| 49 | #define USB_MEMORY_PEAK_HS_BW MBps_to_icc(700) |
| 50 | #define USB_MEMORY_AVG_SS_BW MBps_to_icc(1000) |
| 51 | #define USB_MEMORY_PEAK_SS_BW MBps_to_icc(2500) |
| 52 | #define APPS_USB_AVG_BW 0 |
| 53 | #define APPS_USB_PEAK_BW MBps_to_icc(40) |
| 54 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 55 | struct dwc3_acpi_pdata { |
| 56 | u32 qscratch_base_offset; |
| 57 | u32 qscratch_base_size; |
| 58 | u32 dwc3_core_base_size; |
| 59 | int hs_phy_irq_index; |
| 60 | int dp_hs_phy_irq_index; |
| 61 | int dm_hs_phy_irq_index; |
| 62 | int ss_phy_irq_index; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 63 | bool is_urs; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 66 | struct dwc3_qcom { |
| 67 | struct device *dev; |
| 68 | void __iomem *qscratch_base; |
| 69 | struct platform_device *dwc3; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 70 | struct platform_device *urs_usb; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 71 | struct clk **clks; |
| 72 | int num_clocks; |
| 73 | struct reset_control *resets; |
| 74 | |
| 75 | int hs_phy_irq; |
| 76 | int dp_hs_phy_irq; |
| 77 | int dm_hs_phy_irq; |
| 78 | int ss_phy_irq; |
| 79 | |
| 80 | struct extcon_dev *edev; |
| 81 | struct extcon_dev *host_edev; |
| 82 | struct notifier_block vbus_nb; |
| 83 | struct notifier_block host_nb; |
| 84 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 85 | const struct dwc3_acpi_pdata *acpi_pdata; |
| 86 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 87 | enum usb_dr_mode mode; |
| 88 | bool is_suspended; |
| 89 | bool pm_suspended; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 90 | struct icc_path *icc_path_ddr; |
| 91 | struct icc_path *icc_path_apps; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val) |
| 95 | { |
| 96 | u32 reg; |
| 97 | |
| 98 | reg = readl(base + offset); |
| 99 | reg |= val; |
| 100 | writel(reg, base + offset); |
| 101 | |
| 102 | /* ensure that above write is through */ |
| 103 | readl(base + offset); |
| 104 | } |
| 105 | |
| 106 | static inline void dwc3_qcom_clrbits(void __iomem *base, u32 offset, u32 val) |
| 107 | { |
| 108 | u32 reg; |
| 109 | |
| 110 | reg = readl(base + offset); |
| 111 | reg &= ~val; |
| 112 | writel(reg, base + offset); |
| 113 | |
| 114 | /* ensure that above write is through */ |
| 115 | readl(base + offset); |
| 116 | } |
| 117 | |
| 118 | static void dwc3_qcom_vbus_overrride_enable(struct dwc3_qcom *qcom, bool enable) |
| 119 | { |
| 120 | if (enable) { |
| 121 | dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, |
| 122 | LANE0_PWR_PRESENT); |
| 123 | dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, |
| 124 | UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); |
| 125 | } else { |
| 126 | dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_SS_PHY_CTRL, |
| 127 | LANE0_PWR_PRESENT); |
| 128 | dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_HS_PHY_CTRL, |
| 129 | UTMI_OTG_VBUS_VALID | SW_SESSVLD_SEL); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | static int dwc3_qcom_vbus_notifier(struct notifier_block *nb, |
| 134 | unsigned long event, void *ptr) |
| 135 | { |
| 136 | struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, vbus_nb); |
| 137 | |
| 138 | /* enable vbus override for device mode */ |
| 139 | dwc3_qcom_vbus_overrride_enable(qcom, event); |
| 140 | qcom->mode = event ? USB_DR_MODE_PERIPHERAL : USB_DR_MODE_HOST; |
| 141 | |
| 142 | return NOTIFY_DONE; |
| 143 | } |
| 144 | |
| 145 | static int dwc3_qcom_host_notifier(struct notifier_block *nb, |
| 146 | unsigned long event, void *ptr) |
| 147 | { |
| 148 | struct dwc3_qcom *qcom = container_of(nb, struct dwc3_qcom, host_nb); |
| 149 | |
| 150 | /* disable vbus override in host mode */ |
| 151 | dwc3_qcom_vbus_overrride_enable(qcom, !event); |
| 152 | qcom->mode = event ? USB_DR_MODE_HOST : USB_DR_MODE_PERIPHERAL; |
| 153 | |
| 154 | return NOTIFY_DONE; |
| 155 | } |
| 156 | |
| 157 | static int dwc3_qcom_register_extcon(struct dwc3_qcom *qcom) |
| 158 | { |
| 159 | struct device *dev = qcom->dev; |
| 160 | struct extcon_dev *host_edev; |
| 161 | int ret; |
| 162 | |
| 163 | if (!of_property_read_bool(dev->of_node, "extcon")) |
| 164 | return 0; |
| 165 | |
| 166 | qcom->edev = extcon_get_edev_by_phandle(dev, 0); |
| 167 | if (IS_ERR(qcom->edev)) |
| 168 | return PTR_ERR(qcom->edev); |
| 169 | |
| 170 | qcom->vbus_nb.notifier_call = dwc3_qcom_vbus_notifier; |
| 171 | |
| 172 | qcom->host_edev = extcon_get_edev_by_phandle(dev, 1); |
| 173 | if (IS_ERR(qcom->host_edev)) |
| 174 | qcom->host_edev = NULL; |
| 175 | |
| 176 | ret = devm_extcon_register_notifier(dev, qcom->edev, EXTCON_USB, |
| 177 | &qcom->vbus_nb); |
| 178 | if (ret < 0) { |
| 179 | dev_err(dev, "VBUS notifier register failed\n"); |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | if (qcom->host_edev) |
| 184 | host_edev = qcom->host_edev; |
| 185 | else |
| 186 | host_edev = qcom->edev; |
| 187 | |
| 188 | qcom->host_nb.notifier_call = dwc3_qcom_host_notifier; |
| 189 | ret = devm_extcon_register_notifier(dev, host_edev, EXTCON_USB_HOST, |
| 190 | &qcom->host_nb); |
| 191 | if (ret < 0) { |
| 192 | dev_err(dev, "Host notifier register failed\n"); |
| 193 | return ret; |
| 194 | } |
| 195 | |
| 196 | /* Update initial VBUS override based on extcon state */ |
| 197 | if (extcon_get_state(qcom->edev, EXTCON_USB) || |
| 198 | !extcon_get_state(host_edev, EXTCON_USB_HOST)) |
| 199 | dwc3_qcom_vbus_notifier(&qcom->vbus_nb, true, qcom->edev); |
| 200 | else |
| 201 | dwc3_qcom_vbus_notifier(&qcom->vbus_nb, false, qcom->edev); |
| 202 | |
| 203 | return 0; |
| 204 | } |
| 205 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 206 | static int dwc3_qcom_interconnect_enable(struct dwc3_qcom *qcom) |
| 207 | { |
| 208 | int ret; |
| 209 | |
| 210 | ret = icc_enable(qcom->icc_path_ddr); |
| 211 | if (ret) |
| 212 | return ret; |
| 213 | |
| 214 | ret = icc_enable(qcom->icc_path_apps); |
| 215 | if (ret) |
| 216 | icc_disable(qcom->icc_path_ddr); |
| 217 | |
| 218 | return ret; |
| 219 | } |
| 220 | |
| 221 | static int dwc3_qcom_interconnect_disable(struct dwc3_qcom *qcom) |
| 222 | { |
| 223 | int ret; |
| 224 | |
| 225 | ret = icc_disable(qcom->icc_path_ddr); |
| 226 | if (ret) |
| 227 | return ret; |
| 228 | |
| 229 | ret = icc_disable(qcom->icc_path_apps); |
| 230 | if (ret) |
| 231 | icc_enable(qcom->icc_path_ddr); |
| 232 | |
| 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * dwc3_qcom_interconnect_init() - Get interconnect path handles |
| 238 | * and set bandwidhth. |
| 239 | * @qcom: Pointer to the concerned usb core. |
| 240 | * |
| 241 | */ |
| 242 | static int dwc3_qcom_interconnect_init(struct dwc3_qcom *qcom) |
| 243 | { |
| 244 | struct device *dev = qcom->dev; |
| 245 | int ret; |
| 246 | |
| 247 | if (has_acpi_companion(dev)) |
| 248 | return 0; |
| 249 | |
| 250 | qcom->icc_path_ddr = of_icc_get(dev, "usb-ddr"); |
| 251 | if (IS_ERR(qcom->icc_path_ddr)) { |
| 252 | dev_err(dev, "failed to get usb-ddr path: %ld\n", |
| 253 | PTR_ERR(qcom->icc_path_ddr)); |
| 254 | return PTR_ERR(qcom->icc_path_ddr); |
| 255 | } |
| 256 | |
| 257 | qcom->icc_path_apps = of_icc_get(dev, "apps-usb"); |
| 258 | if (IS_ERR(qcom->icc_path_apps)) { |
| 259 | dev_err(dev, "failed to get apps-usb path: %ld\n", |
| 260 | PTR_ERR(qcom->icc_path_apps)); |
| 261 | return PTR_ERR(qcom->icc_path_apps); |
| 262 | } |
| 263 | |
| 264 | if (usb_get_maximum_speed(&qcom->dwc3->dev) >= USB_SPEED_SUPER || |
| 265 | usb_get_maximum_speed(&qcom->dwc3->dev) == USB_SPEED_UNKNOWN) |
| 266 | ret = icc_set_bw(qcom->icc_path_ddr, |
| 267 | USB_MEMORY_AVG_SS_BW, USB_MEMORY_PEAK_SS_BW); |
| 268 | else |
| 269 | ret = icc_set_bw(qcom->icc_path_ddr, |
| 270 | USB_MEMORY_AVG_HS_BW, USB_MEMORY_PEAK_HS_BW); |
| 271 | |
| 272 | if (ret) { |
| 273 | dev_err(dev, "failed to set bandwidth for usb-ddr path: %d\n", ret); |
| 274 | return ret; |
| 275 | } |
| 276 | |
| 277 | ret = icc_set_bw(qcom->icc_path_apps, |
| 278 | APPS_USB_AVG_BW, APPS_USB_PEAK_BW); |
| 279 | if (ret) { |
| 280 | dev_err(dev, "failed to set bandwidth for apps-usb path: %d\n", ret); |
| 281 | return ret; |
| 282 | } |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * dwc3_qcom_interconnect_exit() - Release interconnect path handles |
| 289 | * @qcom: Pointer to the concerned usb core. |
| 290 | * |
| 291 | * This function is used to release interconnect path handle. |
| 292 | */ |
| 293 | static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom) |
| 294 | { |
| 295 | icc_put(qcom->icc_path_ddr); |
| 296 | icc_put(qcom->icc_path_apps); |
| 297 | } |
| 298 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 299 | static void dwc3_qcom_disable_interrupts(struct dwc3_qcom *qcom) |
| 300 | { |
| 301 | if (qcom->hs_phy_irq) { |
| 302 | disable_irq_wake(qcom->hs_phy_irq); |
| 303 | disable_irq_nosync(qcom->hs_phy_irq); |
| 304 | } |
| 305 | |
| 306 | if (qcom->dp_hs_phy_irq) { |
| 307 | disable_irq_wake(qcom->dp_hs_phy_irq); |
| 308 | disable_irq_nosync(qcom->dp_hs_phy_irq); |
| 309 | } |
| 310 | |
| 311 | if (qcom->dm_hs_phy_irq) { |
| 312 | disable_irq_wake(qcom->dm_hs_phy_irq); |
| 313 | disable_irq_nosync(qcom->dm_hs_phy_irq); |
| 314 | } |
| 315 | |
| 316 | if (qcom->ss_phy_irq) { |
| 317 | disable_irq_wake(qcom->ss_phy_irq); |
| 318 | disable_irq_nosync(qcom->ss_phy_irq); |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom) |
| 323 | { |
| 324 | if (qcom->hs_phy_irq) { |
| 325 | enable_irq(qcom->hs_phy_irq); |
| 326 | enable_irq_wake(qcom->hs_phy_irq); |
| 327 | } |
| 328 | |
| 329 | if (qcom->dp_hs_phy_irq) { |
| 330 | enable_irq(qcom->dp_hs_phy_irq); |
| 331 | enable_irq_wake(qcom->dp_hs_phy_irq); |
| 332 | } |
| 333 | |
| 334 | if (qcom->dm_hs_phy_irq) { |
| 335 | enable_irq(qcom->dm_hs_phy_irq); |
| 336 | enable_irq_wake(qcom->dm_hs_phy_irq); |
| 337 | } |
| 338 | |
| 339 | if (qcom->ss_phy_irq) { |
| 340 | enable_irq(qcom->ss_phy_irq); |
| 341 | enable_irq_wake(qcom->ss_phy_irq); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | static int dwc3_qcom_suspend(struct dwc3_qcom *qcom) |
| 346 | { |
| 347 | u32 val; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 348 | int i, ret; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 349 | |
| 350 | if (qcom->is_suspended) |
| 351 | return 0; |
| 352 | |
| 353 | val = readl(qcom->qscratch_base + PWR_EVNT_IRQ_STAT_REG); |
| 354 | if (!(val & PWR_EVNT_LPM_IN_L2_MASK)) |
| 355 | dev_err(qcom->dev, "HS-PHY not in L2\n"); |
| 356 | |
| 357 | for (i = qcom->num_clocks - 1; i >= 0; i--) |
| 358 | clk_disable_unprepare(qcom->clks[i]); |
| 359 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 360 | ret = dwc3_qcom_interconnect_disable(qcom); |
| 361 | if (ret) |
| 362 | dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret); |
| 363 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 364 | if (device_may_wakeup(qcom->dev)) |
| 365 | dwc3_qcom_enable_interrupts(qcom); |
| 366 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 367 | qcom->is_suspended = true; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 368 | |
| 369 | return 0; |
| 370 | } |
| 371 | |
| 372 | static int dwc3_qcom_resume(struct dwc3_qcom *qcom) |
| 373 | { |
| 374 | int ret; |
| 375 | int i; |
| 376 | |
| 377 | if (!qcom->is_suspended) |
| 378 | return 0; |
| 379 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 380 | if (device_may_wakeup(qcom->dev)) |
| 381 | dwc3_qcom_disable_interrupts(qcom); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 382 | |
| 383 | for (i = 0; i < qcom->num_clocks; i++) { |
| 384 | ret = clk_prepare_enable(qcom->clks[i]); |
| 385 | if (ret < 0) { |
| 386 | while (--i >= 0) |
| 387 | clk_disable_unprepare(qcom->clks[i]); |
| 388 | return ret; |
| 389 | } |
| 390 | } |
| 391 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 392 | ret = dwc3_qcom_interconnect_enable(qcom); |
| 393 | if (ret) |
| 394 | dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret); |
| 395 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 396 | /* Clear existing events from PHY related to L2 in/out */ |
| 397 | dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG, |
| 398 | PWR_EVNT_LPM_IN_L2_MASK | PWR_EVNT_LPM_OUT_L2_MASK); |
| 399 | |
| 400 | qcom->is_suspended = false; |
| 401 | |
| 402 | return 0; |
| 403 | } |
| 404 | |
| 405 | static irqreturn_t qcom_dwc3_resume_irq(int irq, void *data) |
| 406 | { |
| 407 | struct dwc3_qcom *qcom = data; |
| 408 | struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3); |
| 409 | |
| 410 | /* If pm_suspended then let pm_resume take care of resuming h/w */ |
| 411 | if (qcom->pm_suspended) |
| 412 | return IRQ_HANDLED; |
| 413 | |
| 414 | if (dwc->xhci) |
| 415 | pm_runtime_resume(&dwc->xhci->dev); |
| 416 | |
| 417 | return IRQ_HANDLED; |
| 418 | } |
| 419 | |
| 420 | static void dwc3_qcom_select_utmi_clk(struct dwc3_qcom *qcom) |
| 421 | { |
| 422 | /* Configure dwc3 to use UTMI clock as PIPE clock not present */ |
| 423 | dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, |
| 424 | PIPE_UTMI_CLK_DIS); |
| 425 | |
| 426 | usleep_range(100, 1000); |
| 427 | |
| 428 | dwc3_qcom_setbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, |
| 429 | PIPE_UTMI_CLK_SEL | PIPE3_PHYSTATUS_SW); |
| 430 | |
| 431 | usleep_range(100, 1000); |
| 432 | |
| 433 | dwc3_qcom_clrbits(qcom->qscratch_base, QSCRATCH_GENERAL_CFG, |
| 434 | PIPE_UTMI_CLK_DIS); |
| 435 | } |
| 436 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 437 | static int dwc3_qcom_get_irq(struct platform_device *pdev, |
| 438 | const char *name, int num) |
| 439 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 440 | struct dwc3_qcom *qcom = platform_get_drvdata(pdev); |
| 441 | struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : pdev; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 442 | struct device_node *np = pdev->dev.of_node; |
| 443 | int ret; |
| 444 | |
| 445 | if (np) |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 446 | ret = platform_get_irq_byname(pdev_irq, name); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 447 | else |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 448 | ret = platform_get_irq(pdev_irq, num); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 449 | |
| 450 | return ret; |
| 451 | } |
| 452 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 453 | static int dwc3_qcom_setup_irq(struct platform_device *pdev) |
| 454 | { |
| 455 | struct dwc3_qcom *qcom = platform_get_drvdata(pdev); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 456 | const struct dwc3_acpi_pdata *pdata = qcom->acpi_pdata; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 457 | int irq; |
| 458 | int ret; |
| 459 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 460 | irq = dwc3_qcom_get_irq(pdev, "hs_phy_irq", |
| 461 | pdata ? pdata->hs_phy_irq_index : -1); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 462 | if (irq > 0) { |
| 463 | /* Keep wakeup interrupts disabled until suspend */ |
| 464 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 465 | ret = devm_request_threaded_irq(qcom->dev, irq, NULL, |
| 466 | qcom_dwc3_resume_irq, |
| 467 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 468 | "qcom_dwc3 HS", qcom); |
| 469 | if (ret) { |
| 470 | dev_err(qcom->dev, "hs_phy_irq failed: %d\n", ret); |
| 471 | return ret; |
| 472 | } |
| 473 | qcom->hs_phy_irq = irq; |
| 474 | } |
| 475 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 476 | irq = dwc3_qcom_get_irq(pdev, "dp_hs_phy_irq", |
| 477 | pdata ? pdata->dp_hs_phy_irq_index : -1); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 478 | if (irq > 0) { |
| 479 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 480 | ret = devm_request_threaded_irq(qcom->dev, irq, NULL, |
| 481 | qcom_dwc3_resume_irq, |
| 482 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 483 | "qcom_dwc3 DP_HS", qcom); |
| 484 | if (ret) { |
| 485 | dev_err(qcom->dev, "dp_hs_phy_irq failed: %d\n", ret); |
| 486 | return ret; |
| 487 | } |
| 488 | qcom->dp_hs_phy_irq = irq; |
| 489 | } |
| 490 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 491 | irq = dwc3_qcom_get_irq(pdev, "dm_hs_phy_irq", |
| 492 | pdata ? pdata->dm_hs_phy_irq_index : -1); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 493 | if (irq > 0) { |
| 494 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 495 | ret = devm_request_threaded_irq(qcom->dev, irq, NULL, |
| 496 | qcom_dwc3_resume_irq, |
| 497 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 498 | "qcom_dwc3 DM_HS", qcom); |
| 499 | if (ret) { |
| 500 | dev_err(qcom->dev, "dm_hs_phy_irq failed: %d\n", ret); |
| 501 | return ret; |
| 502 | } |
| 503 | qcom->dm_hs_phy_irq = irq; |
| 504 | } |
| 505 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 506 | irq = dwc3_qcom_get_irq(pdev, "ss_phy_irq", |
| 507 | pdata ? pdata->ss_phy_irq_index : -1); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 508 | if (irq > 0) { |
| 509 | irq_set_status_flags(irq, IRQ_NOAUTOEN); |
| 510 | ret = devm_request_threaded_irq(qcom->dev, irq, NULL, |
| 511 | qcom_dwc3_resume_irq, |
| 512 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, |
| 513 | "qcom_dwc3 SS", qcom); |
| 514 | if (ret) { |
| 515 | dev_err(qcom->dev, "ss_phy_irq failed: %d\n", ret); |
| 516 | return ret; |
| 517 | } |
| 518 | qcom->ss_phy_irq = irq; |
| 519 | } |
| 520 | |
| 521 | return 0; |
| 522 | } |
| 523 | |
| 524 | static int dwc3_qcom_clk_init(struct dwc3_qcom *qcom, int count) |
| 525 | { |
| 526 | struct device *dev = qcom->dev; |
| 527 | struct device_node *np = dev->of_node; |
| 528 | int i; |
| 529 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 530 | if (!np || !count) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 531 | return 0; |
| 532 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 533 | if (count < 0) |
| 534 | return count; |
| 535 | |
| 536 | qcom->num_clocks = count; |
| 537 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 538 | qcom->clks = devm_kcalloc(dev, qcom->num_clocks, |
| 539 | sizeof(struct clk *), GFP_KERNEL); |
| 540 | if (!qcom->clks) |
| 541 | return -ENOMEM; |
| 542 | |
| 543 | for (i = 0; i < qcom->num_clocks; i++) { |
| 544 | struct clk *clk; |
| 545 | int ret; |
| 546 | |
| 547 | clk = of_clk_get(np, i); |
| 548 | if (IS_ERR(clk)) { |
| 549 | while (--i >= 0) |
| 550 | clk_put(qcom->clks[i]); |
| 551 | return PTR_ERR(clk); |
| 552 | } |
| 553 | |
| 554 | ret = clk_prepare_enable(clk); |
| 555 | if (ret < 0) { |
| 556 | while (--i >= 0) { |
| 557 | clk_disable_unprepare(qcom->clks[i]); |
| 558 | clk_put(qcom->clks[i]); |
| 559 | } |
| 560 | clk_put(clk); |
| 561 | |
| 562 | return ret; |
| 563 | } |
| 564 | |
| 565 | qcom->clks[i] = clk; |
| 566 | } |
| 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 571 | static const struct property_entry dwc3_qcom_acpi_properties[] = { |
| 572 | PROPERTY_ENTRY_STRING("dr_mode", "host"), |
| 573 | {} |
| 574 | }; |
| 575 | |
| 576 | static int dwc3_qcom_acpi_register_core(struct platform_device *pdev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 577 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 578 | struct dwc3_qcom *qcom = platform_get_drvdata(pdev); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 579 | struct device *dev = &pdev->dev; |
| 580 | struct resource *res, *child_res = NULL; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 581 | struct platform_device *pdev_irq = qcom->urs_usb ? qcom->urs_usb : |
| 582 | pdev; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 583 | int irq; |
| 584 | int ret; |
| 585 | |
| 586 | qcom->dwc3 = platform_device_alloc("dwc3", PLATFORM_DEVID_AUTO); |
| 587 | if (!qcom->dwc3) |
| 588 | return -ENOMEM; |
| 589 | |
| 590 | qcom->dwc3->dev.parent = dev; |
| 591 | qcom->dwc3->dev.type = dev->type; |
| 592 | qcom->dwc3->dev.dma_mask = dev->dma_mask; |
| 593 | qcom->dwc3->dev.dma_parms = dev->dma_parms; |
| 594 | qcom->dwc3->dev.coherent_dma_mask = dev->coherent_dma_mask; |
| 595 | |
| 596 | child_res = kcalloc(2, sizeof(*child_res), GFP_KERNEL); |
| 597 | if (!child_res) |
| 598 | return -ENOMEM; |
| 599 | |
| 600 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 601 | if (!res) { |
| 602 | dev_err(&pdev->dev, "failed to get memory resource\n"); |
| 603 | ret = -ENODEV; |
| 604 | goto out; |
| 605 | } |
| 606 | |
| 607 | child_res[0].flags = res->flags; |
| 608 | child_res[0].start = res->start; |
| 609 | child_res[0].end = child_res[0].start + |
| 610 | qcom->acpi_pdata->dwc3_core_base_size; |
| 611 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 612 | irq = platform_get_irq(pdev_irq, 0); |
| 613 | if (irq < 0) { |
| 614 | ret = irq; |
| 615 | goto out; |
| 616 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 617 | child_res[1].flags = IORESOURCE_IRQ; |
| 618 | child_res[1].start = child_res[1].end = irq; |
| 619 | |
| 620 | ret = platform_device_add_resources(qcom->dwc3, child_res, 2); |
| 621 | if (ret) { |
| 622 | dev_err(&pdev->dev, "failed to add resources\n"); |
| 623 | goto out; |
| 624 | } |
| 625 | |
| 626 | ret = platform_device_add_properties(qcom->dwc3, |
| 627 | dwc3_qcom_acpi_properties); |
| 628 | if (ret < 0) { |
| 629 | dev_err(&pdev->dev, "failed to add properties\n"); |
| 630 | goto out; |
| 631 | } |
| 632 | |
| 633 | ret = platform_device_add(qcom->dwc3); |
| 634 | if (ret) |
| 635 | dev_err(&pdev->dev, "failed to add device\n"); |
| 636 | |
| 637 | out: |
| 638 | kfree(child_res); |
| 639 | return ret; |
| 640 | } |
| 641 | |
| 642 | static int dwc3_qcom_of_register_core(struct platform_device *pdev) |
| 643 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 644 | struct dwc3_qcom *qcom = platform_get_drvdata(pdev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 645 | struct device_node *np = pdev->dev.of_node, *dwc3_np; |
| 646 | struct device *dev = &pdev->dev; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 647 | int ret; |
| 648 | |
| 649 | dwc3_np = of_get_child_by_name(np, "dwc3"); |
| 650 | if (!dwc3_np) { |
| 651 | dev_err(dev, "failed to find dwc3 core child\n"); |
| 652 | return -ENODEV; |
| 653 | } |
| 654 | |
| 655 | ret = of_platform_populate(np, NULL, NULL, dev); |
| 656 | if (ret) { |
| 657 | dev_err(dev, "failed to register dwc3 core - %d\n", ret); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 658 | goto node_put; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | qcom->dwc3 = of_find_device_by_node(dwc3_np); |
| 662 | if (!qcom->dwc3) { |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 663 | ret = -ENODEV; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 664 | dev_err(dev, "failed to get dwc3 platform device\n"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 667 | node_put: |
| 668 | of_node_put(dwc3_np); |
| 669 | |
| 670 | return ret; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 671 | } |
| 672 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 673 | static struct platform_device * |
| 674 | dwc3_qcom_create_urs_usb_platdev(struct device *dev) |
| 675 | { |
| 676 | struct fwnode_handle *fwh; |
| 677 | struct acpi_device *adev; |
| 678 | char name[8]; |
| 679 | int ret; |
| 680 | int id; |
| 681 | |
| 682 | /* Figure out device id */ |
| 683 | ret = sscanf(fwnode_get_name(dev->fwnode), "URS%d", &id); |
| 684 | if (!ret) |
| 685 | return NULL; |
| 686 | |
| 687 | /* Find the child using name */ |
| 688 | snprintf(name, sizeof(name), "USB%d", id); |
| 689 | fwh = fwnode_get_named_child_node(dev->fwnode, name); |
| 690 | if (!fwh) |
| 691 | return NULL; |
| 692 | |
| 693 | adev = to_acpi_device_node(fwh); |
| 694 | if (!adev) |
| 695 | return NULL; |
| 696 | |
| 697 | return acpi_create_platform_device(adev, NULL); |
| 698 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 699 | |
| 700 | static int dwc3_qcom_probe(struct platform_device *pdev) |
| 701 | { |
| 702 | struct device_node *np = pdev->dev.of_node; |
| 703 | struct device *dev = &pdev->dev; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 704 | struct dwc3_qcom *qcom; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 705 | struct resource *res, *parent_res = NULL; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 706 | int ret, i; |
| 707 | bool ignore_pipe_clk; |
| 708 | |
| 709 | qcom = devm_kzalloc(&pdev->dev, sizeof(*qcom), GFP_KERNEL); |
| 710 | if (!qcom) |
| 711 | return -ENOMEM; |
| 712 | |
| 713 | platform_set_drvdata(pdev, qcom); |
| 714 | qcom->dev = &pdev->dev; |
| 715 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 716 | if (has_acpi_companion(dev)) { |
| 717 | qcom->acpi_pdata = acpi_device_get_match_data(dev); |
| 718 | if (!qcom->acpi_pdata) { |
| 719 | dev_err(&pdev->dev, "no supporting ACPI device data\n"); |
| 720 | return -EINVAL; |
| 721 | } |
| 722 | } |
| 723 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 724 | qcom->resets = devm_reset_control_array_get_optional_exclusive(dev); |
| 725 | if (IS_ERR(qcom->resets)) { |
| 726 | ret = PTR_ERR(qcom->resets); |
| 727 | dev_err(&pdev->dev, "failed to get resets, err=%d\n", ret); |
| 728 | return ret; |
| 729 | } |
| 730 | |
| 731 | ret = reset_control_assert(qcom->resets); |
| 732 | if (ret) { |
| 733 | dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret); |
| 734 | return ret; |
| 735 | } |
| 736 | |
| 737 | usleep_range(10, 1000); |
| 738 | |
| 739 | ret = reset_control_deassert(qcom->resets); |
| 740 | if (ret) { |
| 741 | dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret); |
| 742 | goto reset_assert; |
| 743 | } |
| 744 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 745 | ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np)); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 746 | if (ret) { |
| 747 | dev_err(dev, "failed to get clocks\n"); |
| 748 | goto reset_assert; |
| 749 | } |
| 750 | |
| 751 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 752 | |
| 753 | if (np) { |
| 754 | parent_res = res; |
| 755 | } else { |
| 756 | parent_res = kmemdup(res, sizeof(struct resource), GFP_KERNEL); |
| 757 | if (!parent_res) |
| 758 | return -ENOMEM; |
| 759 | |
| 760 | parent_res->start = res->start + |
| 761 | qcom->acpi_pdata->qscratch_base_offset; |
| 762 | parent_res->end = parent_res->start + |
| 763 | qcom->acpi_pdata->qscratch_base_size; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 764 | |
| 765 | if (qcom->acpi_pdata->is_urs) { |
| 766 | qcom->urs_usb = dwc3_qcom_create_urs_usb_platdev(dev); |
| 767 | if (IS_ERR_OR_NULL(qcom->urs_usb)) { |
| 768 | dev_err(dev, "failed to create URS USB platdev\n"); |
| 769 | if (!qcom->urs_usb) |
| 770 | return -ENODEV; |
| 771 | else |
| 772 | return PTR_ERR(qcom->urs_usb); |
| 773 | } |
| 774 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | qcom->qscratch_base = devm_ioremap_resource(dev, parent_res); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 778 | if (IS_ERR(qcom->qscratch_base)) { |
| 779 | dev_err(dev, "failed to map qscratch, err=%d\n", ret); |
| 780 | ret = PTR_ERR(qcom->qscratch_base); |
| 781 | goto clk_disable; |
| 782 | } |
| 783 | |
| 784 | ret = dwc3_qcom_setup_irq(pdev); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 785 | if (ret) { |
| 786 | dev_err(dev, "failed to setup IRQs, err=%d\n", ret); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 787 | goto clk_disable; |
| 788 | } |
| 789 | |
| 790 | /* |
| 791 | * Disable pipe_clk requirement if specified. Used when dwc3 |
| 792 | * operates without SSPHY and only HS/FS/LS modes are supported. |
| 793 | */ |
| 794 | ignore_pipe_clk = device_property_read_bool(dev, |
| 795 | "qcom,select-utmi-as-pipe-clk"); |
| 796 | if (ignore_pipe_clk) |
| 797 | dwc3_qcom_select_utmi_clk(qcom); |
| 798 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 799 | if (np) |
| 800 | ret = dwc3_qcom_of_register_core(pdev); |
| 801 | else |
| 802 | ret = dwc3_qcom_acpi_register_core(pdev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 803 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 804 | if (ret) { |
| 805 | dev_err(dev, "failed to register DWC3 Core, err=%d\n", ret); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 806 | goto depopulate; |
| 807 | } |
| 808 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 809 | ret = dwc3_qcom_interconnect_init(qcom); |
| 810 | if (ret) |
| 811 | goto depopulate; |
| 812 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 813 | qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev); |
| 814 | |
| 815 | /* enable vbus override for device mode */ |
| 816 | if (qcom->mode == USB_DR_MODE_PERIPHERAL) |
| 817 | dwc3_qcom_vbus_overrride_enable(qcom, true); |
| 818 | |
| 819 | /* register extcon to override sw_vbus on Vbus change later */ |
| 820 | ret = dwc3_qcom_register_extcon(qcom); |
| 821 | if (ret) |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 822 | goto interconnect_exit; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 823 | |
| 824 | device_init_wakeup(&pdev->dev, 1); |
| 825 | qcom->is_suspended = false; |
| 826 | pm_runtime_set_active(dev); |
| 827 | pm_runtime_enable(dev); |
| 828 | pm_runtime_forbid(dev); |
| 829 | |
| 830 | return 0; |
| 831 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 832 | interconnect_exit: |
| 833 | dwc3_qcom_interconnect_exit(qcom); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 834 | depopulate: |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 835 | if (np) |
| 836 | of_platform_depopulate(&pdev->dev); |
| 837 | else |
| 838 | platform_device_put(pdev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 839 | clk_disable: |
| 840 | for (i = qcom->num_clocks - 1; i >= 0; i--) { |
| 841 | clk_disable_unprepare(qcom->clks[i]); |
| 842 | clk_put(qcom->clks[i]); |
| 843 | } |
| 844 | reset_assert: |
| 845 | reset_control_assert(qcom->resets); |
| 846 | |
| 847 | return ret; |
| 848 | } |
| 849 | |
| 850 | static int dwc3_qcom_remove(struct platform_device *pdev) |
| 851 | { |
| 852 | struct dwc3_qcom *qcom = platform_get_drvdata(pdev); |
| 853 | struct device *dev = &pdev->dev; |
| 854 | int i; |
| 855 | |
| 856 | of_platform_depopulate(dev); |
| 857 | |
| 858 | for (i = qcom->num_clocks - 1; i >= 0; i--) { |
| 859 | clk_disable_unprepare(qcom->clks[i]); |
| 860 | clk_put(qcom->clks[i]); |
| 861 | } |
| 862 | qcom->num_clocks = 0; |
| 863 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 864 | dwc3_qcom_interconnect_exit(qcom); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 865 | reset_control_assert(qcom->resets); |
| 866 | |
| 867 | pm_runtime_allow(dev); |
| 868 | pm_runtime_disable(dev); |
| 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | static int __maybe_unused dwc3_qcom_pm_suspend(struct device *dev) |
| 874 | { |
| 875 | struct dwc3_qcom *qcom = dev_get_drvdata(dev); |
| 876 | int ret = 0; |
| 877 | |
| 878 | ret = dwc3_qcom_suspend(qcom); |
| 879 | if (!ret) |
| 880 | qcom->pm_suspended = true; |
| 881 | |
| 882 | return ret; |
| 883 | } |
| 884 | |
| 885 | static int __maybe_unused dwc3_qcom_pm_resume(struct device *dev) |
| 886 | { |
| 887 | struct dwc3_qcom *qcom = dev_get_drvdata(dev); |
| 888 | int ret; |
| 889 | |
| 890 | ret = dwc3_qcom_resume(qcom); |
| 891 | if (!ret) |
| 892 | qcom->pm_suspended = false; |
| 893 | |
| 894 | return ret; |
| 895 | } |
| 896 | |
| 897 | static int __maybe_unused dwc3_qcom_runtime_suspend(struct device *dev) |
| 898 | { |
| 899 | struct dwc3_qcom *qcom = dev_get_drvdata(dev); |
| 900 | |
| 901 | return dwc3_qcom_suspend(qcom); |
| 902 | } |
| 903 | |
| 904 | static int __maybe_unused dwc3_qcom_runtime_resume(struct device *dev) |
| 905 | { |
| 906 | struct dwc3_qcom *qcom = dev_get_drvdata(dev); |
| 907 | |
| 908 | return dwc3_qcom_resume(qcom); |
| 909 | } |
| 910 | |
| 911 | static const struct dev_pm_ops dwc3_qcom_dev_pm_ops = { |
| 912 | SET_SYSTEM_SLEEP_PM_OPS(dwc3_qcom_pm_suspend, dwc3_qcom_pm_resume) |
| 913 | SET_RUNTIME_PM_OPS(dwc3_qcom_runtime_suspend, dwc3_qcom_runtime_resume, |
| 914 | NULL) |
| 915 | }; |
| 916 | |
| 917 | static const struct of_device_id dwc3_qcom_of_match[] = { |
| 918 | { .compatible = "qcom,dwc3" }, |
| 919 | { .compatible = "qcom,msm8996-dwc3" }, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 920 | { .compatible = "qcom,msm8998-dwc3" }, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 921 | { .compatible = "qcom,sdm845-dwc3" }, |
| 922 | { } |
| 923 | }; |
| 924 | MODULE_DEVICE_TABLE(of, dwc3_qcom_of_match); |
| 925 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 926 | #ifdef CONFIG_ACPI |
| 927 | static const struct dwc3_acpi_pdata sdm845_acpi_pdata = { |
| 928 | .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET, |
| 929 | .qscratch_base_size = SDM845_QSCRATCH_SIZE, |
| 930 | .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE, |
| 931 | .hs_phy_irq_index = 1, |
| 932 | .dp_hs_phy_irq_index = 4, |
| 933 | .dm_hs_phy_irq_index = 3, |
| 934 | .ss_phy_irq_index = 2 |
| 935 | }; |
| 936 | |
| 937 | static const struct dwc3_acpi_pdata sdm845_acpi_urs_pdata = { |
| 938 | .qscratch_base_offset = SDM845_QSCRATCH_BASE_OFFSET, |
| 939 | .qscratch_base_size = SDM845_QSCRATCH_SIZE, |
| 940 | .dwc3_core_base_size = SDM845_DWC3_CORE_SIZE, |
| 941 | .hs_phy_irq_index = 1, |
| 942 | .dp_hs_phy_irq_index = 4, |
| 943 | .dm_hs_phy_irq_index = 3, |
| 944 | .ss_phy_irq_index = 2, |
| 945 | .is_urs = true, |
| 946 | }; |
| 947 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 948 | static const struct acpi_device_id dwc3_qcom_acpi_match[] = { |
| 949 | { "QCOM2430", (unsigned long)&sdm845_acpi_pdata }, |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 950 | { "QCOM0304", (unsigned long)&sdm845_acpi_urs_pdata }, |
| 951 | { "QCOM0497", (unsigned long)&sdm845_acpi_urs_pdata }, |
| 952 | { "QCOM04A6", (unsigned long)&sdm845_acpi_pdata }, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 953 | { }, |
| 954 | }; |
| 955 | MODULE_DEVICE_TABLE(acpi, dwc3_qcom_acpi_match); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 956 | #endif |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 957 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 958 | static struct platform_driver dwc3_qcom_driver = { |
| 959 | .probe = dwc3_qcom_probe, |
| 960 | .remove = dwc3_qcom_remove, |
| 961 | .driver = { |
| 962 | .name = "dwc3-qcom", |
| 963 | .pm = &dwc3_qcom_dev_pm_ops, |
| 964 | .of_match_table = dwc3_qcom_of_match, |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 965 | .acpi_match_table = ACPI_PTR(dwc3_qcom_acpi_match), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 966 | }, |
| 967 | }; |
| 968 | |
| 969 | module_platform_driver(dwc3_qcom_driver); |
| 970 | |
| 971 | MODULE_LICENSE("GPL v2"); |
| 972 | MODULE_DESCRIPTION("DesignWare DWC3 QCOM Glue Driver"); |