Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'phy-for-v4.2' of git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy into usb-next

Kishon writes:

phy: for 4.2 merge window

*) new Broadcom SATA3 PHY driver for Broadcom STB SoCs
*) new phy API to get PHY by index which is used in EHCI and
OHCI controller drivers
*) support specifying supply at port level used for multi-port PHYs
*) sparse warning fixes in miphy PHYs
*) fix pm_runtime issues in twl4030 driver

Signed-off-by: Kishon Vijay Abraham I <kishon@ti.com>

+415 -139
+8
Documentation/ABI/testing/sysfs-platform-twl4030-usb
··· 1 + What: /sys/bus/platform/devices/*twl4030-usb/vbus 2 + Description: 3 + Read-only status reporting if VBUS (approx 5V) 4 + is being supplied by the USB bus. 5 + 6 + Possible values: "on", "off". 7 + 8 + Changes are notified via select/poll.
+40
Documentation/devicetree/bindings/phy/brcm,brcmstb-sata-phy.txt
··· 1 + * Broadcom SATA3 PHY for STB 2 + 3 + Required properties: 4 + - compatible: should be one or more of 5 + "brcm,bcm7445-sata-phy" 6 + "brcm,phy-sata3" 7 + - address-cells: should be 1 8 + - size-cells: should be 0 9 + - reg: register range for the PHY PCB interface 10 + - reg-names: should be "phy" 11 + 12 + Sub-nodes: 13 + Each port's PHY should be represented as a sub-node. 14 + 15 + Sub-nodes required properties: 16 + - reg: the PHY number 17 + - phy-cells: generic PHY binding; must be 0 18 + Optional: 19 + - brcm,enable-ssc: use spread spectrum clocking (SSC) on this port 20 + 21 + 22 + Example: 23 + 24 + sata-phy@f0458100 { 25 + compatible = "brcm,bcm7445-sata-phy", "brcm,phy-sata3"; 26 + reg = <0xf0458100 0x1e00>, <0xf045804c 0x10>; 27 + reg-names = "phy"; 28 + #address-cells = <1>; 29 + #size-cells = <0>; 30 + 31 + sata-phy@0 { 32 + reg = <0>; 33 + #phy-cells = <0>; 34 + }; 35 + 36 + sata-phy@1 { 37 + reg = <1>; 38 + #phy-cells = <0>; 39 + }; 40 + };
+1
Documentation/devicetree/bindings/phy/rcar-gen2-phy.txt
··· 6 6 Required properties: 7 7 - compatible: "renesas,usb-phy-r8a7790" if the device is a part of R8A7790 SoC. 8 8 "renesas,usb-phy-r8a7791" if the device is a part of R8A7791 SoC. 9 + "renesas,usb-phy-r8a7794" if the device is a part of R8A7794 SoC. 9 10 - reg: offset and length of the register block. 10 11 - #address-cells: number of address cells for the USB channel subnodes, must 11 12 be <1>.
+6 -1
Documentation/phy.txt
··· 76 76 struct phy *phy_optional_get(struct device *dev, const char *string); 77 77 struct phy *devm_phy_get(struct device *dev, const char *string); 78 78 struct phy *devm_phy_optional_get(struct device *dev, const char *string); 79 + struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, 80 + int index); 79 81 80 82 phy_get, phy_optional_get, devm_phy_get and devm_phy_optional_get can 81 83 be used to get the PHY. In the case of dt boot, the string arguments ··· 88 86 the the devres data and devres data is freed. phy_optional_get and 89 87 devm_phy_optional_get should be used when the phy is optional. These 90 88 two functions will never return -ENODEV, but instead returns NULL when 91 - the phy cannot be found. 89 + the phy cannot be found.Some generic drivers, such as ehci, may use multiple 90 + phys and for such drivers referencing phy(s) by name(s) does not make sense. In 91 + this case, devm_of_phy_get_by_index can be used to get a phy reference based on 92 + the index. 92 93 93 94 It should be noted that NULL is a valid phy reference. All phy 94 95 consumer calls on the NULL phy become NOPs. That is the release calls,
+9
drivers/phy/Kconfig
··· 316 316 help 317 317 Support for TI TUSB1210 USB ULPI PHY. 318 318 319 + config PHY_BRCMSTB_SATA 320 + tristate "Broadcom STB SATA PHY driver" 321 + depends on ARCH_BRCMSTB 322 + depends on OF 323 + select GENERIC_PHY 324 + help 325 + Enable this to support the SATA3 PHY on 28nm Broadcom STB SoCs. 326 + Likely useful only with CONFIG_SATA_BRCMSTB enabled. 327 + 319 328 endmenu
+1
drivers/phy/Makefile
··· 41 41 obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-20nm.o 42 42 obj-$(CONFIG_PHY_QCOM_UFS) += phy-qcom-ufs-qmp-14nm.o 43 43 obj-$(CONFIG_PHY_TUSB1210) += phy-tusb1210.o 44 + obj-$(CONFIG_PHY_BRCMSTB_SATA) += phy-brcmstb-sata.o
+216
drivers/phy/phy-brcmstb-sata.c
··· 1 + /* 2 + * Broadcom SATA3 AHCI Controller PHY Driver 3 + * 4 + * Copyright © 2009-2015 Broadcom Corporation 5 + * 6 + * This program is free software; you can redistribute it and/or modify 7 + * it under the terms of the GNU General Public License as published by 8 + * the Free Software Foundation; either version 2, or (at your option) 9 + * any later version. 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 + #include <linux/device.h> 18 + #include <linux/init.h> 19 + #include <linux/interrupt.h> 20 + #include <linux/io.h> 21 + #include <linux/kernel.h> 22 + #include <linux/module.h> 23 + #include <linux/of.h> 24 + #include <linux/phy/phy.h> 25 + #include <linux/platform_device.h> 26 + 27 + #define SATA_MDIO_BANK_OFFSET 0x23c 28 + #define SATA_MDIO_REG_OFFSET(ofs) ((ofs) * 4) 29 + #define SATA_MDIO_REG_SPACE_SIZE 0x1000 30 + #define SATA_MDIO_REG_LENGTH 0x1f00 31 + 32 + #define MAX_PORTS 2 33 + 34 + /* Register offset between PHYs in PCB space */ 35 + #define SATA_MDIO_REG_SPACE_SIZE 0x1000 36 + 37 + struct brcm_sata_port { 38 + int portnum; 39 + struct phy *phy; 40 + struct brcm_sata_phy *phy_priv; 41 + bool ssc_en; 42 + }; 43 + 44 + struct brcm_sata_phy { 45 + struct device *dev; 46 + void __iomem *phy_base; 47 + 48 + struct brcm_sata_port phys[MAX_PORTS]; 49 + }; 50 + 51 + enum sata_mdio_phy_regs_28nm { 52 + PLL_REG_BANK_0 = 0x50, 53 + PLL_REG_BANK_0_PLLCONTROL_0 = 0x81, 54 + 55 + TXPMD_REG_BANK = 0x1a0, 56 + TXPMD_CONTROL1 = 0x81, 57 + TXPMD_CONTROL1_TX_SSC_EN_FRC = BIT(0), 58 + TXPMD_CONTROL1_TX_SSC_EN_FRC_VAL = BIT(1), 59 + TXPMD_TX_FREQ_CTRL_CONTROL1 = 0x82, 60 + TXPMD_TX_FREQ_CTRL_CONTROL2 = 0x83, 61 + TXPMD_TX_FREQ_CTRL_CONTROL2_FMIN_MASK = 0x3ff, 62 + TXPMD_TX_FREQ_CTRL_CONTROL3 = 0x84, 63 + TXPMD_TX_FREQ_CTRL_CONTROL3_FMAX_MASK = 0x3ff, 64 + }; 65 + 66 + static inline void __iomem *brcm_sata_phy_base(struct brcm_sata_port *port) 67 + { 68 + struct brcm_sata_phy *priv = port->phy_priv; 69 + 70 + return priv->phy_base + (port->portnum * SATA_MDIO_REG_SPACE_SIZE); 71 + } 72 + 73 + static void brcm_sata_mdio_wr(void __iomem *addr, u32 bank, u32 ofs, 74 + u32 msk, u32 value) 75 + { 76 + u32 tmp; 77 + 78 + writel(bank, addr + SATA_MDIO_BANK_OFFSET); 79 + tmp = readl(addr + SATA_MDIO_REG_OFFSET(ofs)); 80 + tmp = (tmp & msk) | value; 81 + writel(tmp, addr + SATA_MDIO_REG_OFFSET(ofs)); 82 + } 83 + 84 + /* These defaults were characterized by H/W group */ 85 + #define FMIN_VAL_DEFAULT 0x3df 86 + #define FMAX_VAL_DEFAULT 0x3df 87 + #define FMAX_VAL_SSC 0x83 88 + 89 + static void brcm_sata_cfg_ssc_28nm(struct brcm_sata_port *port) 90 + { 91 + void __iomem *base = brcm_sata_phy_base(port); 92 + struct brcm_sata_phy *priv = port->phy_priv; 93 + u32 tmp; 94 + 95 + /* override the TX spread spectrum setting */ 96 + tmp = TXPMD_CONTROL1_TX_SSC_EN_FRC_VAL | TXPMD_CONTROL1_TX_SSC_EN_FRC; 97 + brcm_sata_mdio_wr(base, TXPMD_REG_BANK, TXPMD_CONTROL1, ~tmp, tmp); 98 + 99 + /* set fixed min freq */ 100 + brcm_sata_mdio_wr(base, TXPMD_REG_BANK, TXPMD_TX_FREQ_CTRL_CONTROL2, 101 + ~TXPMD_TX_FREQ_CTRL_CONTROL2_FMIN_MASK, 102 + FMIN_VAL_DEFAULT); 103 + 104 + /* set fixed max freq depending on SSC config */ 105 + if (port->ssc_en) { 106 + dev_info(priv->dev, "enabling SSC on port %d\n", port->portnum); 107 + tmp = FMAX_VAL_SSC; 108 + } else { 109 + tmp = FMAX_VAL_DEFAULT; 110 + } 111 + 112 + brcm_sata_mdio_wr(base, TXPMD_REG_BANK, TXPMD_TX_FREQ_CTRL_CONTROL3, 113 + ~TXPMD_TX_FREQ_CTRL_CONTROL3_FMAX_MASK, tmp); 114 + } 115 + 116 + static int brcm_sata_phy_init(struct phy *phy) 117 + { 118 + struct brcm_sata_port *port = phy_get_drvdata(phy); 119 + 120 + brcm_sata_cfg_ssc_28nm(port); 121 + 122 + return 0; 123 + } 124 + 125 + static struct phy_ops phy_ops_28nm = { 126 + .init = brcm_sata_phy_init, 127 + .owner = THIS_MODULE, 128 + }; 129 + 130 + static const struct of_device_id brcm_sata_phy_of_match[] = { 131 + { .compatible = "brcm,bcm7445-sata-phy" }, 132 + {}, 133 + }; 134 + MODULE_DEVICE_TABLE(of, brcm_sata_phy_of_match); 135 + 136 + static int brcm_sata_phy_probe(struct platform_device *pdev) 137 + { 138 + struct device *dev = &pdev->dev; 139 + struct device_node *dn = dev->of_node, *child; 140 + struct brcm_sata_phy *priv; 141 + struct resource *res; 142 + struct phy_provider *provider; 143 + int count = 0; 144 + 145 + if (of_get_child_count(dn) == 0) 146 + return -ENODEV; 147 + 148 + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 149 + if (!priv) 150 + return -ENOMEM; 151 + dev_set_drvdata(dev, priv); 152 + priv->dev = dev; 153 + 154 + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy"); 155 + priv->phy_base = devm_ioremap_resource(dev, res); 156 + if (IS_ERR(priv->phy_base)) 157 + return PTR_ERR(priv->phy_base); 158 + 159 + for_each_available_child_of_node(dn, child) { 160 + unsigned int id; 161 + struct brcm_sata_port *port; 162 + 163 + if (of_property_read_u32(child, "reg", &id)) { 164 + dev_err(dev, "missing reg property in node %s\n", 165 + child->name); 166 + return -EINVAL; 167 + } 168 + 169 + if (id >= MAX_PORTS) { 170 + dev_err(dev, "invalid reg: %u\n", id); 171 + return -EINVAL; 172 + } 173 + if (priv->phys[id].phy) { 174 + dev_err(dev, "already registered port %u\n", id); 175 + return -EINVAL; 176 + } 177 + 178 + port = &priv->phys[id]; 179 + port->portnum = id; 180 + port->phy_priv = priv; 181 + port->phy = devm_phy_create(dev, child, &phy_ops_28nm); 182 + port->ssc_en = of_property_read_bool(child, "brcm,enable-ssc"); 183 + if (IS_ERR(port->phy)) { 184 + dev_err(dev, "failed to create PHY\n"); 185 + return PTR_ERR(port->phy); 186 + } 187 + 188 + phy_set_drvdata(port->phy, port); 189 + count++; 190 + } 191 + 192 + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 193 + if (IS_ERR(provider)) { 194 + dev_err(dev, "could not register PHY provider\n"); 195 + return PTR_ERR(provider); 196 + } 197 + 198 + dev_info(dev, "registered %d port(s)\n", count); 199 + 200 + return 0; 201 + } 202 + 203 + static struct platform_driver brcm_sata_phy_driver = { 204 + .probe = brcm_sata_phy_probe, 205 + .driver = { 206 + .of_match_table = brcm_sata_phy_of_match, 207 + .name = "brcmstb-sata-phy", 208 + } 209 + }; 210 + module_platform_driver(brcm_sata_phy_driver); 211 + 212 + MODULE_DESCRIPTION("Broadcom STB SATA PHY driver"); 213 + MODULE_LICENSE("GPL"); 214 + MODULE_AUTHOR("Marc Carino"); 215 + MODULE_AUTHOR("Brian Norris"); 216 + MODULE_ALIAS("platform:phy-brcmstb-sata");
+52 -15
drivers/phy/phy-core.c
··· 367 367 phy_provider = of_phy_provider_lookup(args.np); 368 368 if (IS_ERR(phy_provider) || !try_module_get(phy_provider->owner)) { 369 369 phy = ERR_PTR(-EPROBE_DEFER); 370 - goto err0; 370 + goto out_unlock; 371 + } 372 + 373 + if (!of_device_is_available(args.np)) { 374 + dev_warn(phy_provider->dev, "Requested PHY is disabled\n"); 375 + phy = ERR_PTR(-ENODEV); 376 + goto out_put_module; 371 377 } 372 378 373 379 phy = phy_provider->of_xlate(phy_provider->dev, &args); 380 + 381 + out_put_module: 374 382 module_put(phy_provider->owner); 375 383 376 - err0: 384 + out_unlock: 377 385 mutex_unlock(&phy_provider_mutex); 378 386 of_node_put(args.np); 379 387 ··· 631 623 EXPORT_SYMBOL_GPL(devm_of_phy_get); 632 624 633 625 /** 626 + * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by index. 627 + * @dev: device that requests this phy 628 + * @np: node containing the phy 629 + * @index: index of the phy 630 + * 631 + * Gets the phy using _of_phy_get(), and associates a device with it using 632 + * devres. On driver detach, release function is invoked on the devres data, 633 + * then, devres data is freed. 634 + * 635 + */ 636 + struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, 637 + int index) 638 + { 639 + struct phy **ptr, *phy; 640 + 641 + ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL); 642 + if (!ptr) 643 + return ERR_PTR(-ENOMEM); 644 + 645 + phy = _of_phy_get(np, index); 646 + if (!IS_ERR(phy)) { 647 + *ptr = phy; 648 + devres_add(dev, ptr); 649 + } else { 650 + devres_free(ptr); 651 + } 652 + 653 + return phy; 654 + } 655 + EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); 656 + 657 + /** 634 658 * phy_create() - create a new phy 635 659 * @dev: device that is creating the new phy 636 660 * @node: device node of the phy ··· 691 651 goto free_phy; 692 652 } 693 653 694 - /* phy-supply */ 695 - phy->pwr = regulator_get_optional(dev, "phy"); 696 - if (IS_ERR(phy->pwr)) { 697 - if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) { 698 - ret = -EPROBE_DEFER; 699 - goto free_ida; 700 - } 701 - phy->pwr = NULL; 702 - } 703 - 704 654 device_initialize(&phy->dev); 705 655 mutex_init(&phy->mutex); 706 656 ··· 703 673 ret = dev_set_name(&phy->dev, "phy-%s.%d", dev_name(dev), id); 704 674 if (ret) 705 675 goto put_dev; 676 + 677 + /* phy-supply */ 678 + phy->pwr = regulator_get_optional(&phy->dev, "phy"); 679 + if (IS_ERR(phy->pwr)) { 680 + ret = PTR_ERR(phy->pwr); 681 + if (ret == -EPROBE_DEFER) 682 + goto put_dev; 683 + 684 + phy->pwr = NULL; 685 + } 706 686 707 687 ret = device_add(&phy->dev); 708 688 if (ret) ··· 728 688 put_dev: 729 689 put_device(&phy->dev); /* calls phy_release() which frees resources */ 730 690 return ERR_PTR(ret); 731 - 732 - free_ida: 733 - ida_simple_remove(&phy_ida, phy->id); 734 691 735 692 free_phy: 736 693 kfree(phy);
+2 -7
drivers/phy/phy-miphy28lp.c
··· 367 367 368 368 static inline void miphy28lp_set_reset(struct miphy28lp_phy *miphy_phy) 369 369 { 370 - void *base = miphy_phy->base; 370 + void __iomem *base = miphy_phy->base; 371 371 u8 val; 372 372 373 373 /* Putting Macro in reset */ ··· 391 391 static inline void miphy28lp_pll_calibration(struct miphy28lp_phy *miphy_phy, 392 392 struct pll_ratio *pll_ratio) 393 393 { 394 - void *base = miphy_phy->base; 394 + void __iomem *base = miphy_phy->base; 395 395 u8 val; 396 396 397 397 /* Applying PLL Settings */ ··· 1106 1106 struct miphy28lp_phy *miphy_phy = NULL; 1107 1107 struct device_node *phynode = args->np; 1108 1108 int ret, index = 0; 1109 - 1110 - if (!of_device_is_available(phynode)) { 1111 - dev_warn(dev, "Requested PHY is disabled\n"); 1112 - return ERR_PTR(-ENODEV); 1113 - } 1114 1109 1115 1110 if (args->args_count != 1) { 1116 1111 dev_err(dev, "Invalid number of cells in 'phy' property\n");
+2 -7
drivers/phy/phy-miphy365x.c
··· 441 441 return ret; 442 442 } 443 443 444 - int miphy365x_get_addr(struct device *dev, struct miphy365x_phy *miphy_phy, 445 - int index) 444 + static int miphy365x_get_addr(struct device *dev, 445 + struct miphy365x_phy *miphy_phy, int index) 446 446 { 447 447 struct device_node *phynode = miphy_phy->phy->dev.of_node; 448 448 const char *name; ··· 475 475 struct miphy365x_phy *miphy_phy = NULL; 476 476 struct device_node *phynode = args->np; 477 477 int ret, index; 478 - 479 - if (!of_device_is_available(phynode)) { 480 - dev_warn(dev, "Requested PHY is disabled\n"); 481 - return ERR_PTR(-ENODEV); 482 - } 483 478 484 479 if (args->args_count != 1) { 485 480 dev_err(dev, "Invalid number of cells in 'phy' property\n");
+1 -5
drivers/phy/phy-rcar-gen2.c
··· 195 195 static const struct of_device_id rcar_gen2_phy_match_table[] = { 196 196 { .compatible = "renesas,usb-phy-r8a7790" }, 197 197 { .compatible = "renesas,usb-phy-r8a7791" }, 198 + { .compatible = "renesas,usb-phy-r8a7794" }, 198 199 { } 199 200 }; 200 201 MODULE_DEVICE_TABLE(of, rcar_gen2_phy_match_table); ··· 206 205 struct rcar_gen2_phy_driver *drv; 207 206 struct device_node *np = args->np; 208 207 int i; 209 - 210 - if (!of_device_is_available(np)) { 211 - dev_warn(dev, "Requested PHY is disabled\n"); 212 - return ERR_PTR(-ENODEV); 213 - } 214 208 215 209 drv = dev_get_drvdata(dev); 216 210 if (!drv)
+20 -14
drivers/phy/phy-twl4030-usb.c
··· 144 144 #define PMBR1 0x0D 145 145 #define GPIO_USB_4PIN_ULPI_2430C (3 << 0) 146 146 147 + /* 148 + * If VBUS is valid or ID is ground, then we know a 149 + * cable is present and we need to be runtime-enabled 150 + */ 151 + static inline bool cable_present(enum omap_musb_vbus_id_status stat) 152 + { 153 + return stat == OMAP_MUSB_VBUS_VALID || 154 + stat == OMAP_MUSB_ID_GROUND; 155 + } 156 + 147 157 struct twl4030_usb { 148 158 struct usb_phy phy; 149 159 struct device *dev; ··· 396 386 struct twl4030_usb *twl = dev_get_drvdata(dev); 397 387 398 388 dev_dbg(twl->dev, "%s\n", __func__); 399 - if (pm_runtime_suspended(dev)) 400 - return 0; 401 389 402 390 __twl4030_phy_power(twl, 0); 403 391 regulator_disable(twl->usb1v5); ··· 411 403 int res; 412 404 413 405 dev_dbg(twl->dev, "%s\n", __func__); 414 - if (pm_runtime_active(dev)) 415 - return 0; 416 406 417 407 res = regulator_enable(twl->usb3v1); 418 408 if (res) ··· 542 536 543 537 mutex_lock(&twl->lock); 544 538 if (status >= 0 && status != twl->linkstat) { 539 + status_changed = 540 + cable_present(twl->linkstat) != 541 + cable_present(status); 545 542 twl->linkstat = status; 546 - status_changed = true; 547 543 } 548 544 mutex_unlock(&twl->lock); 549 545 ··· 561 553 * USB_LINK_VBUS state. musb_hdrc won't care until it 562 554 * starts to handle softconnect right. 563 555 */ 564 - if ((status == OMAP_MUSB_VBUS_VALID) || 565 - (status == OMAP_MUSB_ID_GROUND)) { 566 - if (pm_runtime_suspended(twl->dev)) 567 - pm_runtime_get_sync(twl->dev); 556 + if (cable_present(status)) { 557 + pm_runtime_get_sync(twl->dev); 568 558 } else { 569 - if (pm_runtime_active(twl->dev)) { 570 - pm_runtime_mark_last_busy(twl->dev); 571 - pm_runtime_put_autosuspend(twl->dev); 572 - } 559 + pm_runtime_mark_last_busy(twl->dev); 560 + pm_runtime_put_autosuspend(twl->dev); 573 561 } 574 562 omap_musb_mailbox(status); 575 563 } ··· 715 711 pm_runtime_use_autosuspend(&pdev->dev); 716 712 pm_runtime_set_autosuspend_delay(&pdev->dev, 2000); 717 713 pm_runtime_enable(&pdev->dev); 718 - pm_runtime_get_sync(&pdev->dev); 719 714 720 715 /* Our job is to use irqs and status from the power module 721 716 * to keep the transceiver disabled when nothing's connected. ··· 770 767 771 768 /* disable complete OTG block */ 772 769 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); 770 + 771 + if (cable_present(twl->linkstat)) 772 + pm_runtime_put_noidle(twl->dev); 773 773 pm_runtime_mark_last_busy(twl->dev); 774 774 pm_runtime_put(twl->dev); 775 775
+24 -45
drivers/usb/host/ehci-platform.c
··· 88 88 } 89 89 90 90 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { 91 - if (priv->phys[phy_num]) { 92 - ret = phy_init(priv->phys[phy_num]); 93 - if (ret) 94 - goto err_exit_phy; 95 - ret = phy_power_on(priv->phys[phy_num]); 96 - if (ret) { 97 - phy_exit(priv->phys[phy_num]); 98 - goto err_exit_phy; 99 - } 91 + ret = phy_init(priv->phys[phy_num]); 92 + if (ret) 93 + goto err_exit_phy; 94 + ret = phy_power_on(priv->phys[phy_num]); 95 + if (ret) { 96 + phy_exit(priv->phys[phy_num]); 97 + goto err_exit_phy; 100 98 } 101 99 } 102 100 ··· 102 104 103 105 err_exit_phy: 104 106 while (--phy_num >= 0) { 105 - if (priv->phys[phy_num]) { 106 - phy_power_off(priv->phys[phy_num]); 107 - phy_exit(priv->phys[phy_num]); 108 - } 107 + phy_power_off(priv->phys[phy_num]); 108 + phy_exit(priv->phys[phy_num]); 109 109 } 110 110 err_disable_clks: 111 111 while (--clk >= 0) ··· 119 123 int clk, phy_num; 120 124 121 125 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { 122 - if (priv->phys[phy_num]) { 123 - phy_power_off(priv->phys[phy_num]); 124 - phy_exit(priv->phys[phy_num]); 125 - } 126 + phy_power_off(priv->phys[phy_num]); 127 + phy_exit(priv->phys[phy_num]); 126 128 } 127 129 128 130 for (clk = EHCI_MAX_CLKS - 1; clk >= 0; clk--) ··· 148 154 struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); 149 155 struct ehci_platform_priv *priv; 150 156 struct ehci_hcd *ehci; 151 - const char *phy_name; 152 157 int err, irq, phy_num, clk = 0; 153 158 154 159 if (usb_disabled()) ··· 201 208 202 209 priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, 203 210 "phys", "#phy-cells"); 204 - priv->num_phys = priv->num_phys > 0 ? priv->num_phys : 1; 205 211 206 - priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, 207 - sizeof(struct phy *), GFP_KERNEL); 208 - if (!priv->phys) 209 - return -ENOMEM; 212 + if (priv->num_phys > 0) { 213 + priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, 214 + sizeof(struct phy *), GFP_KERNEL); 215 + if (!priv->phys) 216 + return -ENOMEM; 217 + } else 218 + priv->num_phys = 0; 210 219 211 220 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { 212 - err = of_property_read_string_index( 213 - dev->dev.of_node, 214 - "phy-names", phy_num, 215 - &phy_name); 216 - 217 - if (err < 0) { 218 - if (priv->num_phys > 1) { 219 - dev_err(&dev->dev, "phy-names not provided"); 220 - goto err_put_hcd; 221 - } else 222 - phy_name = "usb"; 223 - } 224 - 225 - priv->phys[phy_num] = devm_phy_get(&dev->dev, 226 - phy_name); 227 - if (IS_ERR(priv->phys[phy_num])) { 228 - err = PTR_ERR(priv->phys[phy_num]); 229 - if ((priv->num_phys > 1) || 230 - (err == -EPROBE_DEFER)) 231 - goto err_put_hcd; 232 - priv->phys[phy_num] = NULL; 233 - } 221 + priv->phys[phy_num] = devm_of_phy_get_by_index( 222 + &dev->dev, dev->dev.of_node, phy_num); 223 + if (IS_ERR(priv->phys[phy_num])) { 224 + err = PTR_ERR(priv->phys[phy_num]); 225 + goto err_put_hcd; 226 + } 234 227 } 235 228 236 229 for (clk = 0; clk < EHCI_MAX_CLKS; clk++) {
+24 -45
drivers/usb/host/ohci-platform.c
··· 57 57 } 58 58 59 59 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { 60 - if (priv->phys[phy_num]) { 61 - ret = phy_init(priv->phys[phy_num]); 62 - if (ret) 63 - goto err_exit_phy; 64 - ret = phy_power_on(priv->phys[phy_num]); 65 - if (ret) { 66 - phy_exit(priv->phys[phy_num]); 67 - goto err_exit_phy; 68 - } 60 + ret = phy_init(priv->phys[phy_num]); 61 + if (ret) 62 + goto err_exit_phy; 63 + ret = phy_power_on(priv->phys[phy_num]); 64 + if (ret) { 65 + phy_exit(priv->phys[phy_num]); 66 + goto err_exit_phy; 69 67 } 70 68 } 71 69 ··· 71 73 72 74 err_exit_phy: 73 75 while (--phy_num >= 0) { 74 - if (priv->phys[phy_num]) { 75 - phy_power_off(priv->phys[phy_num]); 76 - phy_exit(priv->phys[phy_num]); 77 - } 76 + phy_power_off(priv->phys[phy_num]); 77 + phy_exit(priv->phys[phy_num]); 78 78 } 79 79 err_disable_clks: 80 80 while (--clk >= 0) ··· 88 92 int clk, phy_num; 89 93 90 94 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { 91 - if (priv->phys[phy_num]) { 92 - phy_power_off(priv->phys[phy_num]); 93 - phy_exit(priv->phys[phy_num]); 94 - } 95 + phy_power_off(priv->phys[phy_num]); 96 + phy_exit(priv->phys[phy_num]); 95 97 } 96 98 97 99 for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--) ··· 117 123 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); 118 124 struct ohci_platform_priv *priv; 119 125 struct ohci_hcd *ohci; 120 - const char *phy_name; 121 126 int err, irq, phy_num, clk = 0; 122 127 123 128 if (usb_disabled()) ··· 167 174 168 175 priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, 169 176 "phys", "#phy-cells"); 170 - priv->num_phys = priv->num_phys > 0 ? priv->num_phys : 1; 171 177 172 - priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, 173 - sizeof(struct phy *), GFP_KERNEL); 174 - if (!priv->phys) 175 - return -ENOMEM; 178 + if (priv->num_phys > 0) { 179 + priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, 180 + sizeof(struct phy *), GFP_KERNEL); 181 + if (!priv->phys) 182 + return -ENOMEM; 183 + } else 184 + priv->num_phys = 0; 176 185 177 186 for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { 178 - err = of_property_read_string_index( 179 - dev->dev.of_node, 180 - "phy-names", phy_num, 181 - &phy_name); 182 - 183 - if (err < 0) { 184 - if (priv->num_phys > 1) { 185 - dev_err(&dev->dev, "phy-names not provided"); 186 - goto err_put_hcd; 187 - } else 188 - phy_name = "usb"; 189 - } 190 - 191 - priv->phys[phy_num] = devm_phy_get(&dev->dev, 192 - phy_name); 193 - if (IS_ERR(priv->phys[phy_num])) { 194 - err = PTR_ERR(priv->phys[phy_num]); 195 - if ((priv->num_phys > 1) || 196 - (err == -EPROBE_DEFER)) 197 - goto err_put_hcd; 198 - priv->phys[phy_num] = NULL; 199 - } 187 + priv->phys[phy_num] = devm_of_phy_get_by_index( 188 + &dev->dev, dev->dev.of_node, phy_num); 189 + if (IS_ERR(priv->phys[phy_num])) { 190 + err = PTR_ERR(priv->phys[phy_num]); 191 + goto err_put_hcd; 192 + } 200 193 } 201 194 202 195 for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
+9
include/linux/phy/phy.h
··· 133 133 struct phy *devm_phy_optional_get(struct device *dev, const char *string); 134 134 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np, 135 135 const char *con_id); 136 + struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node *np, 137 + int index); 136 138 void phy_put(struct phy *phy); 137 139 void devm_phy_put(struct device *dev, struct phy *phy); 138 140 struct phy *of_phy_get(struct device_node *np, const char *con_id); ··· 259 257 static inline struct phy *devm_of_phy_get(struct device *dev, 260 258 struct device_node *np, 261 259 const char *con_id) 260 + { 261 + return ERR_PTR(-ENOSYS); 262 + } 263 + 264 + static inline struct phy *devm_of_phy_get_by_index(struct device *dev, 265 + struct device_node *np, 266 + int index) 262 267 { 263 268 return ERR_PTR(-ENOSYS); 264 269 }