Add Broadcom STB USB phy driver
Subsystems (4)
Al Cooper
maintainerv3 cover Add Broadcom STB USB phy driver
Add a new USB Phy driver for Broadcom STB SoCs. This driver supports Broadcom STB ARM and MIPS SoCs. This driver in combination with the Broadcom STB ohci, ehci and xhci drivers will enable USB1.1, USB2.0 and USB3.0 support. This Phy driver also supports the Broadcom UDC gadget driver.
Changes since v2:
- Fix kbuild errors by changing Kconfig so the driver only builds for ARCH_BRCMSTB || BMIPS_GENERIC systems
Changes since v1:
- Rebased to next
- Add Kconfig entry to build the driver
- Commented all delays
- Split out sysfs functionality in separate patch
- Removed parsing of old obselete device tree properties
- Changed device property "device" to "dr_mode" using standard values "host" and "peripheral" along with new values "drd" and "typec-pd"
- Add ability to handle the standard PHY_TYPE_USB2 and PHY_TYPE_USB3 arguments passed in by phy consumers.
- Moved phy_provider_register() to end of probe routine
Al Cooper (4):
soc: brcmstb: Add Product ID and Family ID helper functions
dt-bindings: Add Broadcom STB USB PHY binding document
phy: usb: phy-brcm-usb: Add Broadcom STB USB phy driver
phy: usb: phy-brcm-usb: Add ability to force DRD mode to host or
device
.../bindings/phy/brcm,brcmstb-usb-phy.txt | 42 + MAINTAINERS | 7 + drivers/phy/broadcom/Kconfig | 12 + drivers/phy/broadcom/Makefile | 3 + drivers/phy/broadcom/phy-brcm-usb-init.c | 1125 ++++++++++++++++++++ drivers/phy/broadcom/phy-brcm-usb-init.h | 95 ++ drivers/phy/broadcom/phy-brcm-usb.c | 444 ++++++++ drivers/soc/bcm/brcmstb/common.c | 12 + include/linux/soc/brcmstb/brcmstb.h | 10 + 9 files changed, 1750 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/brcm,brcmstb-usb-phy.txt create mode 100644 drivers/phy/broadcom/phy-brcm-usb-init.c create mode 100644 drivers/phy/broadcom/phy-brcm-usb-init.h create mode 100644 drivers/phy/broadcom/phy-brcm-usb.c
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH v3 1/4 soc: brcmstb: Add Product ID and Family ID helper functions
--- drivers/soc/bcm/brcmstb/common.c | 12 ++++++++++++ include/linux/soc/brcmstb/brcmstb.h | 10 ++++++++++ 2 files changed, 22 insertions(+)
drivers/soc/bcm/brcmstb/common.c +12 -0
@@ -40,6 +40,18 @@ bool soc_is_brcmstb(void)return of_match_node (brcmstb_machine_match, root) !=NULL ; } +u32 brcmstb_get_family_id (void ) +{ +return family_id; +} +EXPORT_SYMBOL (brcmstb_get_family_id); + +u32 brcmstb_get_product_id (void ) +{ +return product_id; +} +EXPORT_SYMBOL (brcmstb_get_product_id); +static const struct of_device_id sun_top_ctrl_match[] = { { .compatible ="brcm,bcm7125-sun-top-ctrl" , }, { .compatible ="brcm,bcm7346-sun-top-ctrl" , },
include/linux/soc/brcmstb/brcmstb.h +10 -0
@@ -1,10 +1,20 @@#ifndef __BRCMSTB_SOC_H#define __BRCMSTB_SOC_H +#define BRCM_ID (reg) ((u32)reg >> 28 ? (u32)reg >> 16 : (u32)reg >> 8) +#define BRCM_REV (reg) ((u32)reg & 0xff) +/* * Bus Interface Unit control register setup, must happen early during boot, * before SMP is brought up, called by machine entry point. */ void brcmstb_biuctrl_init (void ); +/* +* Helper functions for getting family or product id from the +* SoC driver. +*/ +u32 brcmstb_get_family_id (void ); +u32 brcmstb_get_product_id (void ); +#endif /* __BRCMSTB_SOC_H */
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH v3 1/4] soc: brcmstb: Add Product ID and Family ID helper functions
Quoted 1 line · Al Cooper
Signed-off-by Al Cooper <[email protected]>
Kishon, feel free to merge that through your tree. Thanks!
Quoted 54 lines
--- drivers/soc/bcm/brcmstb/common.c | 12 ++++++++++++ include/linux/soc/brcmstb/brcmstb.h | 10 ++++++++++ 2 files changed, 22 insertions(+)drivers/soc/bcm/brcmstb/common.c +12
-0@@ -40,6 +40,18 @@ bool soc_is_brcmstb(void)return of_match_node (brcmstb_machine_match, root) !=NULL ; } +u32 brcmstb_get_family_id (void ) +{ +return family_id; +} +EXPORT_SYMBOL (brcmstb_get_family_id); + +u32 brcmstb_get_product_id (void ) +{ +return product_id; +} +EXPORT_SYMBOL (brcmstb_get_product_id); +static const struct of_device_id sun_top_ctrl_match[] = { { .compatible ="brcm,bcm7125-sun-top-ctrl" , }, { .compatible ="brcm,bcm7346-sun-top-ctrl" , },include/linux/soc/brcmstb/brcmstb.h +10
-0@@ -1,10 +1,20 @@#ifndef __BRCMSTB_SOC_H#define __BRCMSTB_SOC_H +#define BRCM_ID (reg) ((u32)reg >> 28 ? (u32)reg >> 16 : (u32)reg >> 8) +#define BRCM_REV (reg) ((u32)reg & 0xff) +/* * Bus Interface Unit control register setup, must happen early during boot, * before SMP is brought up, called by machine entry point. */ void brcmstb_biuctrl_init (void ); +/* +* Helper functions for getting family or product id from the +* SoC driver. +*/ +u32 brcmstb_get_family_id (void ); +u32 brcmstb_get_product_id (void ); +#endif /* __BRCMSTB_SOC_H */
Signature · 1 line
Florian
Al Cooper
maintainerPATCH v3 2/4 dt-bindings: Add Broadcom STB USB PHY binding document
In reply to Al CooperAdd DT bindings document for Broadcom STB USB PHYs
--- .../bindings/phy/brcm,brcmstb-usb-phy.txt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/brcm,brcmstb-usb-phy.txt
Documentation/devicetree/bindings/phy/brcm,brcmstb-usb-phy.txt new file +42 -0
@@ -0,0 +1,42 @@ +Broadcom STB USB PHY + +Required properties: + - compatible: brcm,brcmstb-usb-phy + - reg: two offset and length pairs. + The first pair specifies a manditory set of memory mapped + registers used for general control of the PHY. + The second pair specifies optional registers used by some of + the SoCs that support USB 3.x + - #phy-cells: Shall be 1 as it expects one argument for setting + the type of the PHY. Possible values are: + - PHY_TYPE_USB2 for USB1.1/2.0 PHY + - PHY_TYPE_USB3 for USB3.x PHY + +Optional Properties: +- clocks : clock phandles. +- clock-names: String, clock name. +- brcm,ipp: Boolean, Invert Port Power. + Possible values are: 0 (Don't invert), 1 (Invert) +- brcm,ioc: Boolean, Invert Over Current detection. + Possible values are: 0 (Don't invert), 1 (Invert) +- brcm,has-xhci: Boolean indicating an optional 3.x only XHCI controller. +- brcm,has-xhci-only: Boolean indicating an XHCI controller that supports + 1.1, 2.0 and 3.0 devices +- dr_mode: String, PHY Device mode. + Possible values are: "host", "peripheral ", "drd" or "typec-pd" + If this property is not defined, the phy will default to "host" mode. + +Example: + +usbphy_0: usb-phy at f0470200 { + reg = <0xf0470200 0xb8>, + <0xf0471940 0x6c0>; + compatible = "brcm,brcmstb-usb-phy"; + #phy-cells = <1>; + dr_mode = "host" + brcm,ioc = <1>; + brcm,ipp = <1>; + brcm,has-xhci; + clocks = <&usb20>, <&usb30>; + clock-names = "sw_usb", "sw_usb3"; +};
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH v3 3/4 phy: usb: phy-brcm-usb: Add Broadcom STB USB phy driver
In reply to Al CooperAdd a new USB Phy driver for Broadcom STB SoCs. This driver supports Broadcom STB ARM and MIPS SoCs. This driver in combination with the Broadcom STB ohci, ehci and xhci drivers will enable USB1.1, USB2.0 and USB3.0 support. This Phy driver also supports the Broadcom UDC gadget driver.
--- MAINTAINERS | 7 + drivers/phy/broadcom/Kconfig | 12 + drivers/phy/broadcom/Makefile | 3 + drivers/phy/broadcom/phy-brcm-usb-init.c | 1125 ++++++++++++++++++++++++++++++ drivers/phy/broadcom/phy-brcm-usb-init.h | 95 +++ drivers/phy/broadcom/phy-brcm-usb.c | 359 ++++++++++ 6 files changed, 1601 insertions(+) create mode 100644 drivers/phy/broadcom/phy-brcm-usb-init.c create mode 100644 drivers/phy/broadcom/phy-brcm-usb-init.h create mode 100644 drivers/phy/broadcom/phy-brcm-usb.c
MAINTAINERS +7 -0
@@ -2774,6 +2774,13 @@ L: linux-pm at vger.kernel.org S: Maintained F: drivers/cpufreq/bmips-cpufreq.c +BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER +M: Al Cooper <[email protected]> +L: linux-kernel at vger.kernel.org +L: bcm-kernel-feedback-list at broadcom.com +S: Maintained +F: drivers/phy/broadcom/phy-brcm-usb* + BROADCOM TG3 GIGABIT ETHERNET DRIVER M: Siva Reddy Kallam <[email protected]> M: Prashant Sreedharan <[email protected]>
drivers/phy/broadcom/Kconfig +12 -0
@@ -66,3 +66,15 @@ config PHY_BRCM_SATA help Enable this to support the Broadcom SATA PHY. If unsure, say N. + +config PHY_BRCM_USB + tristate "Broadcom STB USB PHY driver" + depends on ARCH_BRCMSTB || BMIPS_GENERIC + depends on OF + select GENERIC_PHY + default ARCH_BRCMSTB || BMIPS_GENERIC + help + Enable this to support the Broadcom STB USB PHY. + This driver is required by the USB XHCI, EHCI and OHCI + drivers. + If unsure, say N.
drivers/phy/broadcom/Makefile +3 -0
@@ -5,3 +5,6 @@ obj-$(CONFIG_PHY_BCM_NS_USB3) += phy-bcm-ns-usb3.o obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o obj-$(CONFIG_PHY_NS2_USB_DRD) += phy-bcm-ns2-usbdrd.o obj-$(CONFIG_PHY_BRCM_SATA) += phy-brcm-sata.o +obj-$(CONFIG_PHY_BRCM_USB) += phy-brcm-usb-dvr.o + +phy-brcm-usb-dvr-objs := phy-brcm-usb.o phy-brcm-usb-init.o
drivers/phy/broadcom/phy-brcm-usb-init.c new file +1125 -0
1,125 lines not on this page · raw message
drivers/phy/broadcom/phy-brcm-usb-init.h new file +95 -0
95 lines not on this page · raw message
drivers/phy/broadcom/phy-brcm-usb.c new file +359 -0
359 lines not on this page · raw message
Signature · 1 line
1.9.0.138.g2de3478
Re: [PATCH v3 3/4] phy: usb: phy-brcm-usb: Add Broadcom STB USB phy driver
Hi,
Quoted 63 lines · Al Cooper
Add a new USB Phy driver for Broadcom STB SoCs. This driver supports Broadcom STB ARM and MIPS SoCs. This driver in combination with the Broadcom STB ohci, ehci and xhci drivers will enable USB1.1, USB2.0 and USB3.0 support. This Phy driver also supports the Broadcom UDC gadget driver.
Signed-off-by Al Cooper <[email protected]>--- MAINTAINERS | 7 + drivers/phy/broadcom/Kconfig | 12 + drivers/phy/broadcom/Makefile | 3 + drivers/phy/broadcom/phy-brcm-usb-init.c | 1125 ++++++++++++++++++++++++++++++ drivers/phy/broadcom/phy-brcm-usb-init.h | 95 +++ drivers/phy/broadcom/phy-brcm-usb.c | 359 ++++++++++ 6 files changed, 1601 insertions(+) create mode 100644 drivers/phy/broadcom/phy-brcm-usb-init.c create mode 100644 drivers/phy/broadcom/phy-brcm-usb-init.h create mode 100644 drivers/phy/broadcom/phy-brcm-usb.cMAINTAINERS +7
-0@@ -2774,6 +2774,13 @@ L: linux-pm at vger.kernel.org S: Maintained F: drivers/cpufreq/bmips-cpufreq.c +BROADCOM BRCMSTB USB2 and USB3 PHY DRIVER +M: Al Cooper <[email protected]> +L: linux-kernel at vger.kernel.org +L: bcm-kernel-feedback-list at broadcom.com +S: Maintained +F: drivers/phy/broadcom/phy-brcm-usb* + BROADCOM TG3 GIGABIT ETHERNET DRIVER M: Siva Reddy Kallam <[email protected]> M: Prashant Sreedharan <[email protected]>drivers/phy/broadcom/Kconfig +12
-0@@ -66,3 +66,15 @@ config PHY_BRCM_SATA help Enable this to support the Broadcom SATA PHY. If unsure, say N. + +config PHY_BRCM_USB + tristate "Broadcom STB USB PHY driver" + depends on ARCH_BRCMSTB || BMIPS_GENERIC + depends on OF + select GENERIC_PHY + default ARCH_BRCMSTB || BMIPS_GENERIC + help + Enable this to support the Broadcom STB USB PHY. + This driver is required by the USB XHCI, EHCI and OHCI + drivers. + If unsure, say N.drivers/phy/broadcom/Makefile +0
-0
drivers/phy/broadcom/Makefile obj-$(CONFIG_PHY_BCM_NS_USB3) += phy-bcm-ns-usb3.o · line 10
Quoted 6 lines
drivers/phy/broadcom/Makefile +3
-0@@ -5,3 +5,6 @@ obj-$(CONFIG_PHY_BCM_NS_USB3) += phy-bcm-ns-usb3.o obj-$(CONFIG_PHY_NS2_PCIE) += phy-bcm-ns2-pcie.o obj-$(CONFIG_PHY_NS2_USB_DRD) += phy-bcm-ns2-usbdrd.o obj-$(CONFIG_PHY_BRCM_SATA) += phy-brcm-sata.o +obj-$(CONFIG_PHY_BRCM_USB) += phy-brcm-usb-dvr.o + +phy-brcm-usb-dvr-objs := phy-brcm-usb.o phy-brcm-usb-init.o
.
.
<snip>
.
.
Quoted 89 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +83
-0@@ -0,0 +1,95 @@ +/* +* Copyright (C) 2014-2017 Broadcom +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _USB_BRCM_COMMON_INIT_H +#define _USB_BRCM_COMMON_INIT_H + +#define USB_CTLR_MODE_HOST 0 +#define USB_CTLR_MODE_DEVICE 1 +#define USB_CTLR_MODE_DRD 2 +#define USB_CTLR_MODE_TYPEC_PD 3 + +struct brcm_usb_init_params ; + +struct brcm_usb_init_ops { +void (*init_ipp)(struct brcm_usb_init_params *params); +void (*init_common)(struct brcm_usb_init_params *params); +void (*init_eohci)(struct brcm_usb_init_params *params); +void (*init_xhci)(struct brcm_usb_init_params *params); +void (*uninit_common)(struct brcm_usb_init_params *params); +void (*uninit_eohci)(struct brcm_usb_init_params *params); +void (*uninit_xhci)(struct brcm_usb_init_params *params); +}; + +struct brcm_usb_init_params { +void __iomem *ctrl_regs; +void __iomem *xhci_ec_regs; +int ioc; +int ipp; +int mode; +u32 family_id; +u32 product_id; +int selected_family; +const char *family_name; +const u32 *usb_reg_bits_map; +const struct brcm_usb_init_ops *ops; +}; + +void brcm_usb_set_family_map (struct brcm_usb_init_params *params); +int brcm_usb_init_get_dual_select (struct brcm_usb_init_params *params); +void brcm_usb_init_set_dual_select (struct brcm_usb_init_params *params, +int mode); + +static inline void brcm_usb_init_ipp (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_ipp) + ini->ops->init_ipp (ini); +} + +static inline void brcm_usb_init_common (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_common) + ini->ops->init_common (ini); +} + +static inline void brcm_usb_init_eohci (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_eohci) + ini->ops->init_eohci (ini); +} + +static inline void brcm_usb_init_xhci (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_xhci) + ini->ops->init_xhci (ini); +} + +static inline void brcm_usb_uninit_common (struct brcm_usb_init_params *ini) +{ +if (ini->ops->uninit_common) + ini->ops->uninit_common (ini); +} + +static inline void brcm_usb_uninit_eohci (struct brcm_usb_init_params *ini)
drivers/phy/broadcom/phy-brcm-usb-init.h line 93
Quoted 10 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +10
-0+{ +if (ini->ops->uninit_eohci) + ini->ops->uninit_eohci (ini); +} + +static inline void brcm_usb_uninit_xhci (struct brcm_usb_init_params *ini) +{ +if (ini->ops->uninit_xhci) + ini->ops->uninit_xhci (ini); +}
I'm not sure if we need all this callback ops since arm and mips really doesn't have a different set of ops. mips only have few ops missing. That can be managed with a flag IMO.
Quoted 174 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +2
-0+ +#endif /* _USB_BRCM_COMMON_INIT_H */ drivers/phy/broadcom/phy-brcm-usb.c new file +166
-0@@ -0,0 +1,359 @@ +/* +* phy-brcm-usb.c - Broadcom USB Phy Driver +* +* Copyright (C) 2015-2017 Broadcom +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/clk.h> +#include <linux/delay.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/phy/phy.h> +#include <linux/platform_device.h> +#include <linux/interrupt.h> +#include <linux/soc/brcmstb/brcmstb.h> +#include <dt-bindings/phy/phy.h> + +#include "phy-brcm-usb-init.h" + +enum brcm_usb_phy_id { +BRCM_USB_PHY_2_0 =0 , +BRCM_USB_PHY_3_0 , +BRCM_USB_PHY_ID_MAX +}; + +struct value_to_name_map { +int value; +const char *name; +}; + +static struct value_to_name_map brcm_dr_mode_to_name[] = { + {USB_CTLR_MODE_HOST ,"host" }, + {USB_CTLR_MODE_DEVICE ,"peripheral" }, + {USB_CTLR_MODE_DRD ,"drd" }, + {USB_CTLR_MODE_TYPEC_PD ,"typec-pd" } +}; + +struct brcm_usb_phy { +struct phy *phy; +unsigned int id; +bool inited; +}; + +struct brcm_usb_phy_data { +struct brcm_usb_init_params ini; +bool has_eohci; +bool has_xhci; +struct clk *usb_20_clk; +struct clk *usb_30_clk; +struct mutex mutex; +int init_count; +struct brcm_usb_phy phys[BRCM_USB_PHY_ID_MAX ]; +}; + +#define to_brcm_usb_phy_data (phy) \ + container_of((phy), struct brcm_usb_phy_data, phys[(phy)->id]) + +static int brcm_usb_phy_init (struct phy *gphy) +{ +struct brcm_usb_phy *phy =phy_get_drvdata (gphy); +struct brcm_usb_phy_data *priv =to_brcm_usb_phy_data (phy); + +/* +* Use a lock to make sure a second caller waits until +* the base phy is inited before using it. +*/ +mutex_lock (&priv->mutex); +if (priv->init_count++ ==0 ) { +clk_enable (priv->usb_20_clk); +clk_enable (priv->usb_30_clk); +brcm_usb_init_common (&priv->ini); + } +mutex_unlock (&priv->mutex); +if (phy->id ==BRCM_USB_PHY_2_0 ) +brcm_usb_init_eohci (&priv->ini); +else if (phy->id ==BRCM_USB_PHY_3_0 ) +brcm_usb_init_xhci (&priv->ini); + phy->inited = true; +dev_dbg (&gphy->dev,"INIT, id: %d, total: %d\n" , phy->id, + priv->init_count); + +return 0 ; +} + +static int brcm_usb_phy_exit (struct phy *gphy) +{ +struct brcm_usb_phy *phy =phy_get_drvdata (gphy); +struct brcm_usb_phy_data *priv =to_brcm_usb_phy_data (phy); + +dev_dbg (&gphy->dev,"EXIT\n" ); +if (phy->id ==BRCM_USB_PHY_2_0 ) +brcm_usb_uninit_eohci (&priv->ini); +if (phy->id ==BRCM_USB_PHY_3_0 ) +brcm_usb_uninit_xhci (&priv->ini); + +/* If both xhci and eohci are gone, reset everything else */ +mutex_lock (&priv->mutex); +if (--priv->init_count ==0 ) { +brcm_usb_uninit_common (&priv->ini); +clk_disable (priv->usb_20_clk); +clk_disable (priv->usb_30_clk); + } +mutex_unlock (&priv->mutex); + phy->inited = false; +return 0 ; +} + +static struct phy_ops brcm_usb_phy_ops = { + .init = brcm_usb_phy_init, + .exit = brcm_usb_phy_exit, + .owner =THIS_MODULE , +}; + +static struct phy *brcm_usb_phy_xlate (struct device *dev, +struct of_phandle_args *args) +{ +struct brcm_usb_phy_data *data =dev_get_drvdata (dev); + +/* +* values 0 and 1 are for backward compatibility with +* device tree nodes from older bootloaders. +*/ +switch (args->args[0 ]) { +case 0 : +case PHY_TYPE_USB2 : +return data->phys[BRCM_USB_PHY_2_0 ].phy; +case 1 : +case PHY_TYPE_USB3 : +return data->phys[BRCM_USB_PHY_3_0 ].phy; + } +return ERR_PTR (-ENODEV ); +} + +static int name_to_value (struct value_to_name_map *table,int count, +const char *name,int *value) +{ +int x; + + *value =0 ; +for (x =0 ; x < count; x++) { +if (sysfs_streq (name, table[x].name)) { + *value = x; +return 0 ; + } + } +return -EINVAL ; +} + +static int brcm_usb_phy_probe (struct platform_device *pdev) +{ +struct resource *res; +struct device *dev = &pdev->dev; +struct brcm_usb_phy_data *priv; +struct phy *gphy; +struct phy_provider *phy_provider; +struct device_node *dn = pdev->dev.of_node;
drivers/phy/broadcom/phy-brcm-usb.c line 176
Quoted 10 lines
drivers/phy/broadcom/phy-brcm-usb.c new file +10
-0+int err; +const char *mode; + + priv =devm_kzalloc (dev,sizeof (*priv),GFP_KERNEL ); +if (!priv) +return -ENOMEM ; +platform_set_drvdata (pdev, priv); + + priv->ini.family_id =brcmstb_get_family_id (); + priv->ini.product_id =brcmstb_get_product_id ();
These APIs can be invoked only if CONFIG_SOC_BRCMSTB is set right? Can't we get these ids directly from device tree?
Quoted 33 lines
drivers/phy/broadcom/phy-brcm-usb.c new file +33
-0+brcm_usb_set_family_map (&priv->ini); +dev_dbg (&pdev->dev,"Best mapping table is for %s\n" , + priv->ini.family_name); + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (res ==NULL ) { +dev_err (&pdev->dev,"can't get USB_CTRL base address\n" ); +return -EINVAL ; + } + priv->ini.ctrl_regs =devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (priv->ini.ctrl_regs)) { +dev_err (dev,"can't map CTRL register space\n" ); +return -EINVAL ; + } + +/* The XHCI EC registers are optional */ + res =platform_get_resource (pdev,IORESOURCE_MEM ,1 ); +if (res !=NULL ) { + priv->ini.xhci_ec_regs = +devm_ioremap_resource (&pdev->dev, res); +if (IS_ERR (priv->ini.xhci_ec_regs)) { +dev_err (dev,"can't map XHCI EC register space\n" ); +return -EINVAL ; + } + } + +of_property_read_u32 (dn,"brcm,ipp" , &priv->ini.ipp); +of_property_read_u32 (dn,"brcm,ioc" , &priv->ini.ioc); + + priv->ini.mode =USB_CTLR_MODE_HOST ; + err =of_property_read_string (dn,"dr_mode" , &mode); +if (err ==0 ) { + name_to_value(&brcm_dr_mode_to_name[0], + ARRAY_SIZE(brcm_dr_mode_to_name),
drivers/phy/broadcom/phy-brcm-usb.c line 219
Quoted 10 lines
drivers/phy/broadcom/phy-brcm-usb.c new file +10
-0+ mode, &priv->ini.mode); + } + +if (of_property_read_bool (dn,"has_xhci_only" )) { + priv->has_xhci = true; + }else { + priv->has_eohci = true; +if (of_property_read_bool (dn,"has_xhci" )) + priv->has_xhci = true; + }
the dt binding documentation has mentioned brcm,has-xhci-only, brcm,has-xhci. I think instead of having has_xhci_only property, there can be a sub-node for each phy. So if there is only xhci, there can be a single sub-node and if there are more, there can be multiple sub-nodes.
Quoted 32 lines
drivers/phy/broadcom/phy-brcm-usb.c new file +32
-0+if (priv->has_eohci) { + gphy =devm_phy_create (dev,NULL , &brcm_usb_phy_ops); +if (IS_ERR (gphy)) { +dev_err (dev,"failed to create EHCI/OHCI PHY\n" ); +return PTR_ERR (gphy); + } + priv->phys[BRCM_USB_PHY_2_0 ].phy = gphy; + priv->phys[BRCM_USB_PHY_2_0 ].id =BRCM_USB_PHY_2_0 ; +phy_set_drvdata (gphy, &priv->phys[BRCM_USB_PHY_2_0 ]); + } +if (priv->has_xhci) { + gphy =devm_phy_create (dev,NULL , &brcm_usb_phy_ops); +if (IS_ERR (gphy)) { +dev_err (dev,"failed to create XHCI PHY\n" ); +return PTR_ERR (gphy); + } + priv->phys[BRCM_USB_PHY_3_0 ].phy = gphy; + priv->phys[BRCM_USB_PHY_3_0 ].id =BRCM_USB_PHY_3_0 ; +phy_set_drvdata (gphy, &priv->phys[BRCM_USB_PHY_3_0 ]); + } +mutex_init (&priv->mutex); + priv->usb_20_clk =of_clk_get_by_name (dn,"sw_usb" ); +if (IS_ERR (priv->usb_20_clk)) { +dev_info (&pdev->dev,"Clock not found in Device Tree\n" ); + priv->usb_20_clk =NULL ; + } + err =clk_prepare_enable (priv->usb_20_clk); +if (err) +return err; + +/* Get the USB3.0 clocks if we have XHCI */ +if (priv->has_xhci) {
drivers/phy/broadcom/phy-brcm-usb.c line 261
Quoted 10 lines
drivers/phy/broadcom/phy-brcm-usb.c new file +10
-0+ priv->usb_30_clk =of_clk_get_by_name (dn,"sw_usb3" ); +if (IS_ERR (priv->usb_30_clk)) { +dev_info (&pdev->dev, +"USB3.0 clock not found in Device Tree\n" ); + priv->usb_30_clk =NULL ; + } + err =clk_prepare_enable (priv->usb_30_clk); +if (err) +return err; + }
Instead of having has_xhci checks all over probe, can't we have a single function that performs all the initialization.
Quoted 99 lines
drivers/phy/broadcom/phy-brcm-usb.c new file +98
-0+ +brcm_usb_init_ipp (&priv->ini); + +/* start with everything off */ +if (priv->has_xhci) +brcm_usb_uninit_xhci (&priv->ini); +if (priv->has_eohci) +brcm_usb_uninit_eohci (&priv->ini); +brcm_usb_uninit_common (&priv->ini); +clk_disable (priv->usb_20_clk); +clk_disable (priv->usb_30_clk); + + phy_provider =devm_of_phy_provider_register (dev, brcm_usb_phy_xlate); +if (IS_ERR (phy_provider)) +return PTR_ERR (phy_provider); + +return 0 ; +} + +#ifdef CONFIG_PM_SLEEP +static int brcm_usb_phy_suspend (struct device *dev) +{ +struct brcm_usb_phy_data *priv =dev_get_drvdata (dev); + +if (priv->init_count) { +clk_disable (priv->usb_20_clk); +clk_disable (priv->usb_30_clk); + } +return 0 ; +} + +static int brcm_usb_phy_resume (struct device *dev) +{ +struct brcm_usb_phy_data *priv =dev_get_drvdata (dev); + +clk_enable (priv->usb_20_clk); +clk_enable (priv->usb_30_clk); +brcm_usb_init_ipp (&priv->ini); + +/* +* Initialize anything that was previously initialized. +* Uninitialize anything that wasn't previously initialized. +*/ +if (priv->init_count) { +brcm_usb_init_common (&priv->ini); +if (priv->phys[BRCM_USB_PHY_2_0 ].inited) { +brcm_usb_init_eohci (&priv->ini); + }else if (priv->has_eohci) { +brcm_usb_uninit_eohci (&priv->ini); +clk_disable (priv->usb_20_clk); + } +if (priv->phys[BRCM_USB_PHY_3_0 ].inited) { +brcm_usb_init_xhci (&priv->ini); + }else if (priv->has_xhci) { +brcm_usb_uninit_xhci (&priv->ini); +clk_disable (priv->usb_30_clk); + } + }else { +if (priv->has_xhci) +brcm_usb_uninit_xhci (&priv->ini); +if (priv->has_eohci) +brcm_usb_uninit_eohci (&priv->ini); +brcm_usb_uninit_common (&priv->ini); +clk_disable (priv->usb_20_clk); +clk_disable (priv->usb_30_clk); + } + +return 0 ; +} +#endif /* CONFIG_PM_SLEEP */ + +static const struct dev_pm_ops brcm_usb_phy_pm_ops = { +SET_LATE_SYSTEM_SLEEP_PM_OPS (brcm_usb_phy_suspend, brcm_usb_phy_resume) +}; + +static const struct of_device_id brcm_usb_dt_ids[] = { + { .compatible ="brcm,brcmstb-usb-phy" }, + {/* sentinel */ } +}; + +MODULE_DEVICE_TABLE (of, brcm_usb_dt_ids); + +static struct platform_driver brcm_usb_driver = { + .probe = brcm_usb_phy_probe, + .driver = { + .name ="brcmstb-usb-phy" , + .owner =THIS_MODULE , + .pm = &brcm_usb_phy_pm_ops, + .of_match_table = brcm_usb_dt_ids, + }, +}; + +module_platform_driver (brcm_usb_driver); + +MODULE_ALIAS ("platform:brcmstb-usb-phy" ); +MODULE_AUTHOR ("Al Cooper <[email protected]>" ); +MODULE_DESCRIPTION ("BRCM USB PHY driver" ); +MODULE_LICENSE ("GPL v2" );
Re: [PATCH v3 3/4] phy: usb: phy-brcm-usb: Add Broadcom STB USB phy driver
Quoted 98 lines · Kishon Vijay Abraham I' via BCM-KERNEL-FEEDBACK-LIST,PDL
Hi,
Quoted 95 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +89
-0@@ -0,0 +1,95 @@ +/* +* Copyright (C) 2014-2017 Broadcom +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#ifndef _USB_BRCM_COMMON_INIT_H +#define _USB_BRCM_COMMON_INIT_H + +#define USB_CTLR_MODE_HOST 0 +#define USB_CTLR_MODE_DEVICE 1 +#define USB_CTLR_MODE_DRD 2 +#define USB_CTLR_MODE_TYPEC_PD 3 + +struct brcm_usb_init_params ; + +struct brcm_usb_init_ops { +void (*init_ipp)(struct brcm_usb_init_params *params); +void (*init_common)(struct brcm_usb_init_params *params); +void (*init_eohci)(struct brcm_usb_init_params *params); +void (*init_xhci)(struct brcm_usb_init_params *params); +void (*uninit_common)(struct brcm_usb_init_params *params); +void (*uninit_eohci)(struct brcm_usb_init_params *params); +void (*uninit_xhci)(struct brcm_usb_init_params *params); +}; + +struct brcm_usb_init_params { +void __iomem *ctrl_regs; +void __iomem *xhci_ec_regs; +int ioc; +int ipp; +int mode; +u32 family_id; +u32 product_id; +int selected_family; +const char *family_name; +const u32 *usb_reg_bits_map; +const struct brcm_usb_init_ops *ops; +}; + +void brcm_usb_set_family_map (struct brcm_usb_init_params *params); +int brcm_usb_init_get_dual_select (struct brcm_usb_init_params *params); +void brcm_usb_init_set_dual_select (struct brcm_usb_init_params *params, +int mode); + +static inline void brcm_usb_init_ipp (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_ipp) + ini->ops->init_ipp (ini); +} + +static inline void brcm_usb_init_common (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_common) + ini->ops->init_common (ini); +} + +static inline void brcm_usb_init_eohci (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_eohci) + ini->ops->init_eohci (ini); +} + +static inline void brcm_usb_init_xhci (struct brcm_usb_init_params *ini) +{ +if (ini->ops->init_xhci) + ini->ops->init_xhci (ini); +} + +static inline void brcm_usb_uninit_common (struct brcm_usb_init_params *ini) +{ +if (ini->ops->uninit_common) + ini->ops->uninit_common (ini); +} + +static inline void brcm_usb_uninit_eohci (struct brcm_usb_init_params *ini) +{ +if (ini->ops->uninit_eohci) + ini->ops->uninit_eohci (ini); +} + +static inline void brcm_usb_uninit_xhci (struct brcm_usb_init_params *ini)
Quoted 8 lines
drivers/phy/broadcom/phy-brcm-usb-init.h line 93
Quoted 4 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +4
-0+{ +if (ini->ops->uninit_xhci) + ini->ops->uninit_xhci (ini); +}I'm not sure if we need all this callback ops since arm and mips really doesn't have a different set of ops. mips only have few ops missing. That can be managed with a flag IMO.
Now that I look at how little there is in common between our ARM and MIPS, I'm going to remove the MIPS support and add a separate, much smaller, MIPS driver later.
Quoted 6 lines
drivers/phy/broadcom/phy-brcm-usb-init.h
Quoted 3 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +3
-0+ + priv->ini.family_id =brcmstb_get_family_id (); + priv->ini.product_id =brcmstb_get_product_id ();These APIs can be invoked only if
CONFIG_SOC_BRCMSTBis set right? Can't we get these ids directly from device tree?
These routines get the family and product id out of device tree. These are common to all brcmstb SOCs. We have various drivers that need to do this so it seems better to have this functionality in a single separate function than have each driver with the same code. I'll have the Kconfig selection for this phy set CONFIG_SOC_BRCMSTB
Quoted 8 lines
drivers/phy/broadcom/phy-brcm-usb-init.h
Quoted 8 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +8
-0+ +if (of_property_read_bool (dn,"has_xhci_only" )) { + priv->has_xhci = true; + }else { + priv->has_eohci = true; +if (of_property_read_bool (dn,"has_xhci" )) + priv->has_xhci = true; + }
Quoted 4 lines
the dt binding documentation has mentioned brcm,has-xhci-only, brcm,has-xhci. I think instead of having
has_xhci_onlyproperty, there can be a sub-node for each phy. So if there is only xhci, there can be a single sub-node and if there are more, there can be multiple sub-nodes.
The register block for phy control is a randomly ordered mix of XHCI, E/OHCI, registers common to both and even some registers that mix these in different fields. I need a single top level driver so that it can enable the common portion if either XHCI or E/OHCI is being used and can disable the common portion when neither is being used. If the order is not done correctly we get bus errors accessing some of these registers. What if I simplify the properties a little by using "has_xhci" and "has_eohci"?
Quoted 44 lines
Quoted 33 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +32
-0+if (priv->has_eohci) { + gphy =devm_phy_create (dev,NULL , &brcm_usb_phy_ops); +if (IS_ERR (gphy)) { +dev_err (dev,"failed to create EHCI/OHCI PHY\n" ); +return PTR_ERR (gphy); + } + priv->phys[BRCM_USB_PHY_2_0 ].phy = gphy; + priv->phys[BRCM_USB_PHY_2_0 ].id =BRCM_USB_PHY_2_0 ; +phy_set_drvdata (gphy, &priv->phys[BRCM_USB_PHY_2_0 ]); + } +if (priv->has_xhci) { + gphy =devm_phy_create (dev,NULL , &brcm_usb_phy_ops); +if (IS_ERR (gphy)) { +dev_err (dev,"failed to create XHCI PHY\n" ); +return PTR_ERR (gphy); + } + priv->phys[BRCM_USB_PHY_3_0 ].phy = gphy; + priv->phys[BRCM_USB_PHY_3_0 ].id =BRCM_USB_PHY_3_0 ; +phy_set_drvdata (gphy, &priv->phys[BRCM_USB_PHY_3_0 ]); + } +mutex_init (&priv->mutex); + priv->usb_20_clk =of_clk_get_by_name (dn,"sw_usb" ); +if (IS_ERR (priv->usb_20_clk)) { +dev_info (&pdev->dev,"Clock not found in Device Tree\n" ); + priv->usb_20_clk =NULL ; + } + err =clk_prepare_enable (priv->usb_20_clk); +if (err) +return err; + +/* Get the USB3.0 clocks if we have XHCI */ +if (priv->has_xhci) {drivers/phy/broadcom/phy-brcm-usb-init.h
Quoted 10 lines
drivers/phy/broadcom/phy-brcm-usb-init.h new file +10
-0+ priv->usb_30_clk =of_clk_get_by_name (dn,"sw_usb3" ); +if (IS_ERR (priv->usb_30_clk)) { +dev_info (&pdev->dev, +"USB3.0 clock not found in Device Tree\n" ); + priv->usb_30_clk =NULL ; + } + err =clk_prepare_enable (priv->usb_30_clk); +if (err) +return err; + }
Quoted 2 lines
Instead of having
has_xhcichecks all over probe, can't we have a single function that performs all the initialization.
I'll restructure this.
Thanks
Al
Al Cooper
maintainerPATCH v3 4/4 phy: usb: phy-brcm-usb: Add ability to force DRD mode to host or device
In reply to Al CooperFrom: Al Cooper <[email protected]>
When the usb phy device mode is set to "drd", the USB port will switch between device and host modes depending on what's plugged into the port. Customers have asked for the ability to force host or device mode from software. This commit adds sysfs entries to the phy device that allow this. The sysfs for the phy device can be found at:/sys/bus/platform/drivers/brcmstb-usb-phy/*.usb-phy
The following sysfs entries were added:
- "dr_mode" (RO) - The current phy "dr_mode" setting. It will be set to one of the following values:
- "host" - host mode
- "peripheral " - device mode
- "drd" - switch between device and host mode based on installed device
- "typec-pd" - device/host mode is controller by the USB Type-C PD protocol.
If "dr_mode" is "drd"
- "drd_select" (RW) -
It will be set to one of the following values:
- "host" - force host mode
- "device" - force device mode
- "auto" - allow normal auto selection of host/device based on inserted USB device
--- drivers/phy/broadcom/phy-brcm-usb.c | 85 +++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+)
drivers/phy/broadcom/phy-brcm-usb.c +85 -0
@@ -27,6 +27,8 @@#include "phy-brcm-usb-init.h" +static DEFINE_MUTEX (sysfs_lock); +enum brcm_usb_phy_id {BRCM_USB_PHY_2_0 =0 ,BRCM_USB_PHY_3_0 ,
@@ -45,6 +47,12 @@ struct value_to_name_map { { USB_CTLR_MODE_TYPEC_PD, "typec-pd" } }; +static struct value_to_name_map brcm_dual_mode_to_name[] = { + {0 ,"host" }, + {1 ,"device" }, + {2 ,"auto" }, +}; +struct brcm_usb_phy {struct phy *phy;unsigned int id;
@@ -156,6 +164,73 @@ static int name_to_value(struct value_to_name_map *table, int count,return -EINVAL ; } +static const char *value_to_name (struct value_to_name_map *table,int count, +int value) +{ +if (value >= count) +return "unknown" ; +return table[value].name; +} + +static ssize_t dr_mode_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct brcm_usb_phy_data *priv =dev_get_drvdata (dev); + +return sprintf (buf,"%s\n" , +value_to_name (&brcm_dr_mode_to_name[0 ], +ARRAY_SIZE (brcm_dr_mode_to_name), + priv->ini.mode)); +} +static DEVICE_ATTR_RO (dr_mode); + +static ssize_t dual_select_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t len) +{ +struct brcm_usb_phy_data *priv =dev_get_drvdata (dev); +int value; +int res; + +mutex_lock (&sysfs_lock); + res =name_to_value (&brcm_dual_mode_to_name[0 ], +ARRAY_SIZE (brcm_dual_mode_to_name), buf, &value); +if (!res) { +brcm_usb_init_set_dual_select (&priv->ini, value); + res = len; + } +mutex_unlock (&sysfs_lock); +return res; +} + +static ssize_t dual_select_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct brcm_usb_phy_data *priv =dev_get_drvdata (dev); +int value; + +mutex_lock (&sysfs_lock); + value =brcm_usb_init_get_dual_select (&priv->ini); +mutex_unlock (&sysfs_lock); +return sprintf (buf,"%s\n" , +value_to_name (&brcm_dual_mode_to_name[0 ], +ARRAY_SIZE (brcm_dual_mode_to_name), + value)); +} +static DEVICE_ATTR_RW (dual_select); + +static struct attribute *brcm_usb_phy_attrs[] = { + &dev_attr_dr_mode.attr, + &dev_attr_dual_select.attr, +NULL +}; + +static const struct attribute_group brcm_usb_phy_group = { + .attrs = brcm_usb_phy_attrs, +}; +static int brcm_usb_phy_probe (struct platform_device *pdev) {struct resource *res;
@@ -262,6 +337,16 @@ static int brcm_usb_phy_probe(struct platform_device *pdev)brcm_usb_init_ipp (&priv->ini); +/* +* Create sysfs entries for mode. +* Remove "dual_select" attribute if not in dual mode +*/ +if (priv->ini.mode !=USB_CTLR_MODE_DRD ) + brcm_usb_phy_attrs[1 ] =NULL ; + err =sysfs_create_group (&dev->kobj, &brcm_usb_phy_group); +if (err) +dev_warn (&pdev->dev,"Error creating sysfs attributes\n" ); +/* start with everything off */ if (priv->has_xhci)brcm_usb_uninit_xhci (&priv->ini);
Signature · 1 line
1.9.0.138.g2de3478