.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * phy-brcm-usb.c - Broadcom USB Phy Driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright (C) 2015-2017 Broadcom |
---|
5 | | - * |
---|
6 | | - * This software is licensed under the terms of the GNU General Public |
---|
7 | | - * License version 2, as published by the Free Software Foundation, and |
---|
8 | | - * may be copied, distributed, and modified under those terms. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | 6 | */ |
---|
15 | 7 | |
---|
16 | 8 | #include <linux/clk.h> |
---|
.. | .. |
---|
24 | 16 | #include <linux/interrupt.h> |
---|
25 | 17 | #include <linux/soc/brcmstb/brcmstb.h> |
---|
26 | 18 | #include <dt-bindings/phy/phy.h> |
---|
| 19 | +#include <linux/mfd/syscon.h> |
---|
| 20 | +#include <linux/suspend.h> |
---|
27 | 21 | |
---|
28 | 22 | #include "phy-brcm-usb-init.h" |
---|
29 | 23 | |
---|
.. | .. |
---|
40 | 34 | const char *name; |
---|
41 | 35 | }; |
---|
42 | 36 | |
---|
43 | | -static struct value_to_name_map brcm_dr_mode_to_name[] = { |
---|
| 37 | +struct match_chip_info { |
---|
| 38 | + void *init_func; |
---|
| 39 | + u8 required_regs[BRCM_REGS_MAX + 1]; |
---|
| 40 | + u8 optional_reg; |
---|
| 41 | +}; |
---|
| 42 | + |
---|
| 43 | +static const struct value_to_name_map brcm_dr_mode_to_name[] = { |
---|
44 | 44 | { USB_CTLR_MODE_HOST, "host" }, |
---|
45 | 45 | { USB_CTLR_MODE_DEVICE, "peripheral" }, |
---|
46 | 46 | { USB_CTLR_MODE_DRD, "drd" }, |
---|
47 | 47 | { USB_CTLR_MODE_TYPEC_PD, "typec-pd" } |
---|
48 | 48 | }; |
---|
49 | 49 | |
---|
50 | | -static struct value_to_name_map brcm_dual_mode_to_name[] = { |
---|
| 50 | +static const struct value_to_name_map brcm_dual_mode_to_name[] = { |
---|
51 | 51 | { 0, "host" }, |
---|
52 | 52 | { 1, "device" }, |
---|
53 | 53 | { 2, "auto" }, |
---|
.. | .. |
---|
65 | 65 | bool has_xhci; |
---|
66 | 66 | struct clk *usb_20_clk; |
---|
67 | 67 | struct clk *usb_30_clk; |
---|
| 68 | + struct clk *suspend_clk; |
---|
68 | 69 | struct mutex mutex; /* serialize phy init */ |
---|
69 | 70 | int init_count; |
---|
| 71 | + int wake_irq; |
---|
70 | 72 | struct brcm_usb_phy phys[BRCM_USB_PHY_ID_MAX]; |
---|
| 73 | + struct notifier_block pm_notifier; |
---|
| 74 | + bool pm_active; |
---|
71 | 75 | }; |
---|
| 76 | + |
---|
| 77 | +static s8 *node_reg_names[BRCM_REGS_MAX] = { |
---|
| 78 | + "crtl", "xhci_ec", "xhci_gbl", "usb_phy", "usb_mdio", "bdc_ec" |
---|
| 79 | +}; |
---|
| 80 | + |
---|
| 81 | +static int brcm_pm_notifier(struct notifier_block *notifier, |
---|
| 82 | + unsigned long pm_event, |
---|
| 83 | + void *unused) |
---|
| 84 | +{ |
---|
| 85 | + struct brcm_usb_phy_data *priv = |
---|
| 86 | + container_of(notifier, struct brcm_usb_phy_data, pm_notifier); |
---|
| 87 | + |
---|
| 88 | + switch (pm_event) { |
---|
| 89 | + case PM_HIBERNATION_PREPARE: |
---|
| 90 | + case PM_SUSPEND_PREPARE: |
---|
| 91 | + priv->pm_active = true; |
---|
| 92 | + break; |
---|
| 93 | + case PM_POST_RESTORE: |
---|
| 94 | + case PM_POST_HIBERNATION: |
---|
| 95 | + case PM_POST_SUSPEND: |
---|
| 96 | + priv->pm_active = false; |
---|
| 97 | + break; |
---|
| 98 | + } |
---|
| 99 | + return NOTIFY_DONE; |
---|
| 100 | +} |
---|
| 101 | + |
---|
| 102 | +static irqreturn_t brcm_usb_phy_wake_isr(int irq, void *dev_id) |
---|
| 103 | +{ |
---|
| 104 | + struct device *dev = dev_id; |
---|
| 105 | + |
---|
| 106 | + pm_wakeup_event(dev, 0); |
---|
| 107 | + |
---|
| 108 | + return IRQ_HANDLED; |
---|
| 109 | +} |
---|
72 | 110 | |
---|
73 | 111 | static int brcm_usb_phy_init(struct phy *gphy) |
---|
74 | 112 | { |
---|
.. | .. |
---|
76 | 114 | struct brcm_usb_phy_data *priv = |
---|
77 | 115 | container_of(phy, struct brcm_usb_phy_data, phys[phy->id]); |
---|
78 | 116 | |
---|
| 117 | + if (priv->pm_active) |
---|
| 118 | + return 0; |
---|
| 119 | + |
---|
79 | 120 | /* |
---|
80 | 121 | * Use a lock to make sure a second caller waits until |
---|
81 | 122 | * the base phy is inited before using it. |
---|
82 | 123 | */ |
---|
83 | 124 | mutex_lock(&priv->mutex); |
---|
84 | 125 | if (priv->init_count++ == 0) { |
---|
85 | | - clk_enable(priv->usb_20_clk); |
---|
86 | | - clk_enable(priv->usb_30_clk); |
---|
| 126 | + clk_prepare_enable(priv->usb_20_clk); |
---|
| 127 | + clk_prepare_enable(priv->usb_30_clk); |
---|
| 128 | + clk_prepare_enable(priv->suspend_clk); |
---|
87 | 129 | brcm_usb_init_common(&priv->ini); |
---|
88 | 130 | } |
---|
89 | 131 | mutex_unlock(&priv->mutex); |
---|
.. | .. |
---|
104 | 146 | struct brcm_usb_phy_data *priv = |
---|
105 | 147 | container_of(phy, struct brcm_usb_phy_data, phys[phy->id]); |
---|
106 | 148 | |
---|
| 149 | + if (priv->pm_active) |
---|
| 150 | + return 0; |
---|
| 151 | + |
---|
107 | 152 | dev_dbg(&gphy->dev, "EXIT\n"); |
---|
108 | 153 | if (phy->id == BRCM_USB_PHY_2_0) |
---|
109 | 154 | brcm_usb_uninit_eohci(&priv->ini); |
---|
.. | .. |
---|
114 | 159 | mutex_lock(&priv->mutex); |
---|
115 | 160 | if (--priv->init_count == 0) { |
---|
116 | 161 | brcm_usb_uninit_common(&priv->ini); |
---|
117 | | - clk_disable(priv->usb_20_clk); |
---|
118 | | - clk_disable(priv->usb_30_clk); |
---|
| 162 | + clk_disable_unprepare(priv->usb_20_clk); |
---|
| 163 | + clk_disable_unprepare(priv->usb_30_clk); |
---|
| 164 | + clk_disable_unprepare(priv->suspend_clk); |
---|
119 | 165 | } |
---|
120 | 166 | mutex_unlock(&priv->mutex); |
---|
121 | 167 | phy->inited = false; |
---|
122 | 168 | return 0; |
---|
123 | 169 | } |
---|
124 | 170 | |
---|
125 | | -static struct phy_ops brcm_usb_phy_ops = { |
---|
| 171 | +static const struct phy_ops brcm_usb_phy_ops = { |
---|
126 | 172 | .init = brcm_usb_phy_init, |
---|
127 | 173 | .exit = brcm_usb_phy_exit, |
---|
128 | 174 | .owner = THIS_MODULE, |
---|
.. | .. |
---|
154 | 200 | return ERR_PTR(-ENODEV); |
---|
155 | 201 | } |
---|
156 | 202 | |
---|
157 | | -static int name_to_value(struct value_to_name_map *table, int count, |
---|
| 203 | +static int name_to_value(const struct value_to_name_map *table, int count, |
---|
158 | 204 | const char *name, int *value) |
---|
159 | 205 | { |
---|
160 | 206 | int x; |
---|
.. | .. |
---|
169 | 215 | return -EINVAL; |
---|
170 | 216 | } |
---|
171 | 217 | |
---|
172 | | -static const char *value_to_name(struct value_to_name_map *table, int count, |
---|
| 218 | +static const char *value_to_name(const struct value_to_name_map *table, int count, |
---|
173 | 219 | int value) |
---|
174 | 220 | { |
---|
175 | 221 | if (value >= count) |
---|
.. | .. |
---|
202 | 248 | res = name_to_value(&brcm_dual_mode_to_name[0], |
---|
203 | 249 | ARRAY_SIZE(brcm_dual_mode_to_name), buf, &value); |
---|
204 | 250 | if (!res) { |
---|
205 | | - brcm_usb_init_set_dual_select(&priv->ini, value); |
---|
| 251 | + brcm_usb_set_dual_select(&priv->ini, value); |
---|
206 | 252 | res = len; |
---|
207 | 253 | } |
---|
208 | 254 | mutex_unlock(&sysfs_lock); |
---|
.. | .. |
---|
217 | 263 | int value; |
---|
218 | 264 | |
---|
219 | 265 | mutex_lock(&sysfs_lock); |
---|
220 | | - value = brcm_usb_init_get_dual_select(&priv->ini); |
---|
| 266 | + value = brcm_usb_get_dual_select(&priv->ini); |
---|
221 | 267 | mutex_unlock(&sysfs_lock); |
---|
222 | 268 | return sprintf(buf, "%s\n", |
---|
223 | 269 | value_to_name(&brcm_dual_mode_to_name[0], |
---|
.. | .. |
---|
236 | 282 | .attrs = brcm_usb_phy_attrs, |
---|
237 | 283 | }; |
---|
238 | 284 | |
---|
239 | | -static int brcm_usb_phy_dvr_init(struct device *dev, |
---|
| 285 | +static const struct match_chip_info chip_info_7216 = { |
---|
| 286 | + .init_func = &brcm_usb_dvr_init_7216, |
---|
| 287 | + .required_regs = { |
---|
| 288 | + BRCM_REGS_CTRL, |
---|
| 289 | + BRCM_REGS_XHCI_EC, |
---|
| 290 | + BRCM_REGS_XHCI_GBL, |
---|
| 291 | + -1, |
---|
| 292 | + }, |
---|
| 293 | +}; |
---|
| 294 | + |
---|
| 295 | +static const struct match_chip_info chip_info_7211b0 = { |
---|
| 296 | + .init_func = &brcm_usb_dvr_init_7211b0, |
---|
| 297 | + .required_regs = { |
---|
| 298 | + BRCM_REGS_CTRL, |
---|
| 299 | + BRCM_REGS_XHCI_EC, |
---|
| 300 | + BRCM_REGS_XHCI_GBL, |
---|
| 301 | + BRCM_REGS_USB_PHY, |
---|
| 302 | + BRCM_REGS_USB_MDIO, |
---|
| 303 | + -1, |
---|
| 304 | + }, |
---|
| 305 | + .optional_reg = BRCM_REGS_BDC_EC, |
---|
| 306 | +}; |
---|
| 307 | + |
---|
| 308 | +static const struct match_chip_info chip_info_7445 = { |
---|
| 309 | + .init_func = &brcm_usb_dvr_init_7445, |
---|
| 310 | + .required_regs = { |
---|
| 311 | + BRCM_REGS_CTRL, |
---|
| 312 | + BRCM_REGS_XHCI_EC, |
---|
| 313 | + -1, |
---|
| 314 | + }, |
---|
| 315 | +}; |
---|
| 316 | + |
---|
| 317 | +static const struct of_device_id brcm_usb_dt_ids[] = { |
---|
| 318 | + { |
---|
| 319 | + .compatible = "brcm,bcm7216-usb-phy", |
---|
| 320 | + .data = &chip_info_7216, |
---|
| 321 | + }, |
---|
| 322 | + { |
---|
| 323 | + .compatible = "brcm,bcm7211-usb-phy", |
---|
| 324 | + .data = &chip_info_7211b0, |
---|
| 325 | + }, |
---|
| 326 | + { |
---|
| 327 | + .compatible = "brcm,brcmstb-usb-phy", |
---|
| 328 | + .data = &chip_info_7445, |
---|
| 329 | + }, |
---|
| 330 | + { /* sentinel */ } |
---|
| 331 | +}; |
---|
| 332 | + |
---|
| 333 | +static int brcm_usb_get_regs(struct platform_device *pdev, |
---|
| 334 | + enum brcmusb_reg_sel regs, |
---|
| 335 | + struct brcm_usb_init_params *ini, |
---|
| 336 | + bool optional) |
---|
| 337 | +{ |
---|
| 338 | + struct resource *res; |
---|
| 339 | + |
---|
| 340 | + /* Older DT nodes have ctrl and optional xhci_ec by index only */ |
---|
| 341 | + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, |
---|
| 342 | + node_reg_names[regs]); |
---|
| 343 | + if (res == NULL) { |
---|
| 344 | + if (regs == BRCM_REGS_CTRL) { |
---|
| 345 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
| 346 | + } else if (regs == BRCM_REGS_XHCI_EC) { |
---|
| 347 | + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
---|
| 348 | + /* XHCI_EC registers are optional */ |
---|
| 349 | + if (res == NULL) |
---|
| 350 | + return 0; |
---|
| 351 | + } |
---|
| 352 | + if (res == NULL) { |
---|
| 353 | + if (optional) { |
---|
| 354 | + dev_dbg(&pdev->dev, |
---|
| 355 | + "Optional reg %s not found\n", |
---|
| 356 | + node_reg_names[regs]); |
---|
| 357 | + return 0; |
---|
| 358 | + } |
---|
| 359 | + dev_err(&pdev->dev, "can't get %s base addr\n", |
---|
| 360 | + node_reg_names[regs]); |
---|
| 361 | + return 1; |
---|
| 362 | + } |
---|
| 363 | + } |
---|
| 364 | + ini->regs[regs] = devm_ioremap_resource(&pdev->dev, res); |
---|
| 365 | + if (IS_ERR(ini->regs[regs])) { |
---|
| 366 | + dev_err(&pdev->dev, "can't map %s register space\n", |
---|
| 367 | + node_reg_names[regs]); |
---|
| 368 | + return 1; |
---|
| 369 | + } |
---|
| 370 | + return 0; |
---|
| 371 | +} |
---|
| 372 | + |
---|
| 373 | +static int brcm_usb_phy_dvr_init(struct platform_device *pdev, |
---|
240 | 374 | struct brcm_usb_phy_data *priv, |
---|
241 | 375 | struct device_node *dn) |
---|
242 | 376 | { |
---|
243 | | - struct phy *gphy; |
---|
| 377 | + struct device *dev = &pdev->dev; |
---|
| 378 | + struct phy *gphy = NULL; |
---|
244 | 379 | int err; |
---|
245 | 380 | |
---|
246 | 381 | priv->usb_20_clk = of_clk_get_by_name(dn, "sw_usb"); |
---|
247 | 382 | if (IS_ERR(priv->usb_20_clk)) { |
---|
| 383 | + if (PTR_ERR(priv->usb_20_clk) == -EPROBE_DEFER) |
---|
| 384 | + return -EPROBE_DEFER; |
---|
248 | 385 | dev_info(dev, "Clock not found in Device Tree\n"); |
---|
249 | 386 | priv->usb_20_clk = NULL; |
---|
250 | 387 | } |
---|
.. | .. |
---|
275 | 412 | |
---|
276 | 413 | priv->usb_30_clk = of_clk_get_by_name(dn, "sw_usb3"); |
---|
277 | 414 | if (IS_ERR(priv->usb_30_clk)) { |
---|
| 415 | + if (PTR_ERR(priv->usb_30_clk) == -EPROBE_DEFER) |
---|
| 416 | + return -EPROBE_DEFER; |
---|
278 | 417 | dev_info(dev, |
---|
279 | 418 | "USB3.0 clock not found in Device Tree\n"); |
---|
280 | 419 | priv->usb_30_clk = NULL; |
---|
.. | .. |
---|
283 | 422 | if (err) |
---|
284 | 423 | return err; |
---|
285 | 424 | } |
---|
| 425 | + |
---|
| 426 | + priv->suspend_clk = clk_get(dev, "usb0_freerun"); |
---|
| 427 | + if (IS_ERR(priv->suspend_clk)) { |
---|
| 428 | + if (PTR_ERR(priv->suspend_clk) == -EPROBE_DEFER) |
---|
| 429 | + return -EPROBE_DEFER; |
---|
| 430 | + dev_err(dev, "Suspend Clock not found in Device Tree\n"); |
---|
| 431 | + priv->suspend_clk = NULL; |
---|
| 432 | + } |
---|
| 433 | + |
---|
| 434 | + priv->wake_irq = platform_get_irq_byname(pdev, "wake"); |
---|
| 435 | + if (priv->wake_irq < 0) |
---|
| 436 | + priv->wake_irq = platform_get_irq_byname(pdev, "wakeup"); |
---|
| 437 | + if (priv->wake_irq >= 0) { |
---|
| 438 | + err = devm_request_irq(dev, priv->wake_irq, |
---|
| 439 | + brcm_usb_phy_wake_isr, 0, |
---|
| 440 | + dev_name(dev), dev); |
---|
| 441 | + if (err < 0) |
---|
| 442 | + return err; |
---|
| 443 | + device_set_wakeup_capable(dev, 1); |
---|
| 444 | + } else { |
---|
| 445 | + dev_info(dev, |
---|
| 446 | + "Wake interrupt missing, system wake not supported\n"); |
---|
| 447 | + } |
---|
| 448 | + |
---|
286 | 449 | return 0; |
---|
287 | 450 | } |
---|
288 | 451 | |
---|
289 | 452 | static int brcm_usb_phy_probe(struct platform_device *pdev) |
---|
290 | 453 | { |
---|
291 | | - struct resource *res; |
---|
292 | 454 | struct device *dev = &pdev->dev; |
---|
293 | 455 | struct brcm_usb_phy_data *priv; |
---|
294 | 456 | struct phy_provider *phy_provider; |
---|
295 | 457 | struct device_node *dn = pdev->dev.of_node; |
---|
296 | 458 | int err; |
---|
297 | 459 | const char *mode; |
---|
| 460 | + const struct of_device_id *match; |
---|
| 461 | + void (*dvr_init)(struct brcm_usb_init_params *params); |
---|
| 462 | + const struct match_chip_info *info; |
---|
| 463 | + struct regmap *rmap; |
---|
| 464 | + int x; |
---|
298 | 465 | |
---|
299 | 466 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
---|
300 | 467 | if (!priv) |
---|
.. | .. |
---|
303 | 470 | |
---|
304 | 471 | priv->ini.family_id = brcmstb_get_family_id(); |
---|
305 | 472 | priv->ini.product_id = brcmstb_get_product_id(); |
---|
306 | | - brcm_usb_set_family_map(&priv->ini); |
---|
| 473 | + |
---|
| 474 | + match = of_match_node(brcm_usb_dt_ids, dev->of_node); |
---|
| 475 | + info = match->data; |
---|
| 476 | + dvr_init = info->init_func; |
---|
| 477 | + (*dvr_init)(&priv->ini); |
---|
| 478 | + |
---|
307 | 479 | dev_dbg(dev, "Best mapping table is for %s\n", |
---|
308 | 480 | priv->ini.family_name); |
---|
309 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
310 | | - if (!res) { |
---|
311 | | - dev_err(dev, "can't get USB_CTRL base address\n"); |
---|
312 | | - return -EINVAL; |
---|
313 | | - } |
---|
314 | | - priv->ini.ctrl_regs = devm_ioremap_resource(dev, res); |
---|
315 | | - if (IS_ERR(priv->ini.ctrl_regs)) { |
---|
316 | | - dev_err(dev, "can't map CTRL register space\n"); |
---|
317 | | - return -EINVAL; |
---|
318 | | - } |
---|
319 | | - |
---|
320 | | - /* The XHCI EC registers are optional */ |
---|
321 | | - res = platform_get_resource(pdev, IORESOURCE_MEM, 1); |
---|
322 | | - if (res) { |
---|
323 | | - priv->ini.xhci_ec_regs = |
---|
324 | | - devm_ioremap_resource(dev, res); |
---|
325 | | - if (IS_ERR(priv->ini.xhci_ec_regs)) { |
---|
326 | | - dev_err(dev, "can't map XHCI EC register space\n"); |
---|
327 | | - return -EINVAL; |
---|
328 | | - } |
---|
329 | | - } |
---|
330 | 481 | |
---|
331 | 482 | of_property_read_u32(dn, "brcm,ipp", &priv->ini.ipp); |
---|
332 | 483 | of_property_read_u32(dn, "brcm,ioc", &priv->ini.ioc); |
---|
.. | .. |
---|
343 | 494 | if (of_property_read_bool(dn, "brcm,has-eohci")) |
---|
344 | 495 | priv->has_eohci = true; |
---|
345 | 496 | |
---|
346 | | - err = brcm_usb_phy_dvr_init(dev, priv, dn); |
---|
| 497 | + for (x = 0; x < BRCM_REGS_MAX; x++) { |
---|
| 498 | + if (info->required_regs[x] >= BRCM_REGS_MAX) |
---|
| 499 | + break; |
---|
| 500 | + |
---|
| 501 | + err = brcm_usb_get_regs(pdev, info->required_regs[x], |
---|
| 502 | + &priv->ini, false); |
---|
| 503 | + if (err) |
---|
| 504 | + return -EINVAL; |
---|
| 505 | + } |
---|
| 506 | + if (info->optional_reg) { |
---|
| 507 | + err = brcm_usb_get_regs(pdev, info->optional_reg, |
---|
| 508 | + &priv->ini, true); |
---|
| 509 | + if (err) |
---|
| 510 | + return -EINVAL; |
---|
| 511 | + } |
---|
| 512 | + |
---|
| 513 | + err = brcm_usb_phy_dvr_init(pdev, priv, dn); |
---|
347 | 514 | if (err) |
---|
348 | 515 | return err; |
---|
| 516 | + |
---|
| 517 | + priv->pm_notifier.notifier_call = brcm_pm_notifier; |
---|
| 518 | + register_pm_notifier(&priv->pm_notifier); |
---|
349 | 519 | |
---|
350 | 520 | mutex_init(&priv->mutex); |
---|
351 | 521 | |
---|
.. | .. |
---|
362 | 532 | if (err) |
---|
363 | 533 | dev_warn(dev, "Error creating sysfs attributes\n"); |
---|
364 | 534 | |
---|
| 535 | + /* Get piarbctl syscon if it exists */ |
---|
| 536 | + rmap = syscon_regmap_lookup_by_phandle(dev->of_node, |
---|
| 537 | + "syscon-piarbctl"); |
---|
| 538 | + if (IS_ERR(rmap)) |
---|
| 539 | + rmap = syscon_regmap_lookup_by_phandle(dev->of_node, |
---|
| 540 | + "brcm,syscon-piarbctl"); |
---|
| 541 | + if (!IS_ERR(rmap)) |
---|
| 542 | + priv->ini.syscon_piarbctl = rmap; |
---|
| 543 | + |
---|
365 | 544 | /* start with everything off */ |
---|
366 | 545 | if (priv->has_xhci) |
---|
367 | 546 | brcm_usb_uninit_xhci(&priv->ini); |
---|
368 | 547 | if (priv->has_eohci) |
---|
369 | 548 | brcm_usb_uninit_eohci(&priv->ini); |
---|
370 | 549 | brcm_usb_uninit_common(&priv->ini); |
---|
371 | | - clk_disable(priv->usb_20_clk); |
---|
372 | | - clk_disable(priv->usb_30_clk); |
---|
| 550 | + clk_disable_unprepare(priv->usb_20_clk); |
---|
| 551 | + clk_disable_unprepare(priv->usb_30_clk); |
---|
373 | 552 | |
---|
374 | 553 | phy_provider = devm_of_phy_provider_register(dev, brcm_usb_phy_xlate); |
---|
375 | | - if (IS_ERR(phy_provider)) |
---|
376 | | - return PTR_ERR(phy_provider); |
---|
377 | 554 | |
---|
378 | | - return 0; |
---|
| 555 | + return PTR_ERR_OR_ZERO(phy_provider); |
---|
379 | 556 | } |
---|
380 | 557 | |
---|
381 | 558 | static int brcm_usb_phy_remove(struct platform_device *pdev) |
---|
382 | 559 | { |
---|
| 560 | + struct brcm_usb_phy_data *priv = dev_get_drvdata(&pdev->dev); |
---|
| 561 | + |
---|
383 | 562 | sysfs_remove_group(&pdev->dev.kobj, &brcm_usb_phy_group); |
---|
| 563 | + unregister_pm_notifier(&priv->pm_notifier); |
---|
384 | 564 | |
---|
385 | 565 | return 0; |
---|
386 | 566 | } |
---|
.. | .. |
---|
391 | 571 | struct brcm_usb_phy_data *priv = dev_get_drvdata(dev); |
---|
392 | 572 | |
---|
393 | 573 | if (priv->init_count) { |
---|
394 | | - clk_disable(priv->usb_20_clk); |
---|
395 | | - clk_disable(priv->usb_30_clk); |
---|
| 574 | + dev_dbg(dev, "SUSPEND\n"); |
---|
| 575 | + priv->ini.wake_enabled = device_may_wakeup(dev); |
---|
| 576 | + if (priv->phys[BRCM_USB_PHY_3_0].inited) |
---|
| 577 | + brcm_usb_uninit_xhci(&priv->ini); |
---|
| 578 | + if (priv->phys[BRCM_USB_PHY_2_0].inited) |
---|
| 579 | + brcm_usb_uninit_eohci(&priv->ini); |
---|
| 580 | + brcm_usb_uninit_common(&priv->ini); |
---|
| 581 | + |
---|
| 582 | + /* |
---|
| 583 | + * Handle the clocks unless needed for wake. This has |
---|
| 584 | + * to work for both older XHCI->3.0-clks, EOHCI->2.0-clks |
---|
| 585 | + * and newer XHCI->2.0-clks/3.0-clks. |
---|
| 586 | + */ |
---|
| 587 | + |
---|
| 588 | + if (!priv->ini.suspend_with_clocks) { |
---|
| 589 | + if (priv->phys[BRCM_USB_PHY_3_0].inited) |
---|
| 590 | + clk_disable_unprepare(priv->usb_30_clk); |
---|
| 591 | + if (priv->phys[BRCM_USB_PHY_2_0].inited || |
---|
| 592 | + !priv->has_eohci) |
---|
| 593 | + clk_disable_unprepare(priv->usb_20_clk); |
---|
| 594 | + } |
---|
| 595 | + if (priv->wake_irq >= 0) |
---|
| 596 | + enable_irq_wake(priv->wake_irq); |
---|
396 | 597 | } |
---|
397 | 598 | return 0; |
---|
398 | 599 | } |
---|
.. | .. |
---|
401 | 602 | { |
---|
402 | 603 | struct brcm_usb_phy_data *priv = dev_get_drvdata(dev); |
---|
403 | 604 | |
---|
404 | | - clk_enable(priv->usb_20_clk); |
---|
405 | | - clk_enable(priv->usb_30_clk); |
---|
| 605 | + clk_prepare_enable(priv->usb_20_clk); |
---|
| 606 | + clk_prepare_enable(priv->usb_30_clk); |
---|
406 | 607 | brcm_usb_init_ipp(&priv->ini); |
---|
407 | 608 | |
---|
408 | 609 | /* |
---|
.. | .. |
---|
410 | 611 | * Uninitialize anything that wasn't previously initialized. |
---|
411 | 612 | */ |
---|
412 | 613 | if (priv->init_count) { |
---|
| 614 | + dev_dbg(dev, "RESUME\n"); |
---|
| 615 | + if (priv->wake_irq >= 0) |
---|
| 616 | + disable_irq_wake(priv->wake_irq); |
---|
413 | 617 | brcm_usb_init_common(&priv->ini); |
---|
414 | 618 | if (priv->phys[BRCM_USB_PHY_2_0].inited) { |
---|
415 | 619 | brcm_usb_init_eohci(&priv->ini); |
---|
416 | 620 | } else if (priv->has_eohci) { |
---|
417 | 621 | brcm_usb_uninit_eohci(&priv->ini); |
---|
418 | | - clk_disable(priv->usb_20_clk); |
---|
| 622 | + clk_disable_unprepare(priv->usb_20_clk); |
---|
419 | 623 | } |
---|
420 | 624 | if (priv->phys[BRCM_USB_PHY_3_0].inited) { |
---|
421 | 625 | brcm_usb_init_xhci(&priv->ini); |
---|
422 | 626 | } else if (priv->has_xhci) { |
---|
423 | 627 | brcm_usb_uninit_xhci(&priv->ini); |
---|
424 | | - clk_disable(priv->usb_30_clk); |
---|
| 628 | + clk_disable_unprepare(priv->usb_30_clk); |
---|
| 629 | + if (!priv->has_eohci) |
---|
| 630 | + clk_disable_unprepare(priv->usb_20_clk); |
---|
425 | 631 | } |
---|
426 | 632 | } else { |
---|
427 | 633 | if (priv->has_xhci) |
---|
.. | .. |
---|
429 | 635 | if (priv->has_eohci) |
---|
430 | 636 | brcm_usb_uninit_eohci(&priv->ini); |
---|
431 | 637 | brcm_usb_uninit_common(&priv->ini); |
---|
432 | | - clk_disable(priv->usb_20_clk); |
---|
433 | | - clk_disable(priv->usb_30_clk); |
---|
| 638 | + clk_disable_unprepare(priv->usb_20_clk); |
---|
| 639 | + clk_disable_unprepare(priv->usb_30_clk); |
---|
434 | 640 | } |
---|
435 | | - |
---|
| 641 | + priv->ini.wake_enabled = false; |
---|
436 | 642 | return 0; |
---|
437 | 643 | } |
---|
438 | 644 | #endif /* CONFIG_PM_SLEEP */ |
---|
439 | 645 | |
---|
440 | 646 | static const struct dev_pm_ops brcm_usb_phy_pm_ops = { |
---|
441 | 647 | SET_LATE_SYSTEM_SLEEP_PM_OPS(brcm_usb_phy_suspend, brcm_usb_phy_resume) |
---|
442 | | -}; |
---|
443 | | - |
---|
444 | | -static const struct of_device_id brcm_usb_dt_ids[] = { |
---|
445 | | - { .compatible = "brcm,brcmstb-usb-phy" }, |
---|
446 | | - { /* sentinel */ } |
---|
447 | 648 | }; |
---|
448 | 649 | |
---|
449 | 650 | MODULE_DEVICE_TABLE(of, brcm_usb_dt_ids); |
---|
.. | .. |
---|
453 | 654 | .remove = brcm_usb_phy_remove, |
---|
454 | 655 | .driver = { |
---|
455 | 656 | .name = "brcmstb-usb-phy", |
---|
456 | | - .owner = THIS_MODULE, |
---|
457 | 657 | .pm = &brcm_usb_phy_pm_ops, |
---|
458 | 658 | .of_match_table = brcm_usb_dt_ids, |
---|
459 | 659 | }, |
---|