Add Broadcom STB USB phy driver
Subsystems (4)
Al Cooper
maintainerv6 cover Add Broadcom STB USB phy driver
Add a new USB Phy driver for Broadcom STB SoCs. This driver supports Broadcom STB ARM 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 BDC gadget driver.
Changes since v5:
- Fixed over 50 CHECK warnings from checkpatch.pl --strict.
Changes since v4:
- MIPS support was dropped, so remove MIPS specific code in the brcmusb_readl/brcmusb_writel routines.
- Use readl/writel instead of readl_relaxed/writel_relaxed.
- Remove double blank lines between some functions.
- Remove support for obselete phy phandle argument.
Changes since v3:
- Removed MIPS support because there is such a small amount of code that is common to both ARM and MIPS. I'll create a separate MIPS driver in the future.
- Have the Kconfig selection for this driver also select "CONFIG_SOC_BRCMSTB" which contains needed functions.
- Change device tree properties to use "brcm,has_xhci" and "brcm,has_eohci" to determine if the phy contains a xhci phy, and e/ohci phy or both.
- Change the phy xlate routine to return an error instead of NULL for a requested phy that doesn't exist.
- Moved some probe functionality into it's own funtion to simplify the many "if (has_xhci)" statements.
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 | 43 + MAINTAINERS | 7 + drivers/phy/broadcom/Kconfig | 13 + drivers/phy/broadcom/Makefile | 3 + drivers/phy/broadcom/phy-brcm-usb-init.c | 1018 ++++++++++++++++++++ drivers/phy/broadcom/phy-brcm-usb-init.h | 50 + drivers/phy/broadcom/phy-brcm-usb.c | 459 +++++++++ drivers/soc/bcm/brcmstb/common.c | 12 + include/linux/soc/brcmstb/brcmstb.h | 17 + 9 files changed, 1622 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 v6 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 | 17 +++++++++++++++++ 2 files changed, 29 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 +17 -0
@@ -1,10 +1,27 @@#ifndef __BRCMSTB_SOC_H#define __BRCMSTB_SOC_H +static inline u32 BRCM_ID (u32 reg) +{ +return reg >>28 ? reg >>16 : reg >>8 ; +} + +static inline u32 BRCM_REV (u32 reg) +{ +return 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
Al Cooper
maintainerPATCH v6 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 | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/brcm,brcmstb-usb-phy.txt
Documentation/devicetree/bindings/phy/brcm,brcmstb-usb-phy.txt new file +43 -0
@@ -0,0 +1,43 @@ +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) +NOTE: one or both of the following two properties must be set +- brcm,has-xhci: Boolean indicating the phy has an XHCI phy. +- brcm,has-eohci: Boolean indicating the phy has an EHCI/OHCI phy. +- 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; + brcm,has-eohci; + clocks = <&usb20>, <&usb30>; + clock-names = "sw_usb", "sw_usb3"; +};
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH v6 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 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 BDC gadget driver.
--- MAINTAINERS | 7 + drivers/phy/broadcom/Kconfig | 13 + drivers/phy/broadcom/Makefile | 3 + drivers/phy/broadcom/phy-brcm-usb-init.c | 1018 ++++++++++++++++++++++++++++++ drivers/phy/broadcom/phy-brcm-usb-init.h | 50 ++ drivers/phy/broadcom/phy-brcm-usb.c | 374 +++++++++++ 6 files changed, 1465 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
@@ -2885,6 +2885,13 @@ S: Supported F: drivers/gpio/gpio-brcmstb.c F: Documentation/devicetree/bindings/gpio/brcm,brcmstb-gpio.txt +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 GENET ETHERNET DRIVER M: Florian Fainelli <[email protected]> L: netdev at vger.kernel.org
drivers/phy/broadcom/Kconfig +13 -0
@@ -67,3 +67,16 @@ 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 + depends on OF + select GENERIC_PHY + select SOC_BRCMSTB + default ARCH_BRCMSTB + 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 +1018 -0
1,018 lines not on this page · raw message
drivers/phy/broadcom/phy-brcm-usb-init.h new file +50 -0
50 lines not on this page · raw message
drivers/phy/broadcom/phy-brcm-usb.c new file +374 -0
374 lines not on this page · raw message
Signature · 1 line
1.9.0.138.g2de3478
Al Cooper
maintainerPATCH v6 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;
@@ -161,6 +169,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_dvr_init (struct device *dev,struct brcm_usb_phy_data *priv,struct device_node *dn)
@@ -277,6 +352,16 @@ static int brcm_usb_phy_probe(struct platform_device *pdev)/* make sure invert settings are correct */ 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 (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