phy: usb: add support for STM32 usbphyc
Subsystems (7)
cover phy: usb: add support for STM32 usbphyc
This is only USB PHY support. Changes to the DWC2 (OTG) and/or OHCI (Host) are still needed to make USB on the MP1 work.
I haven't yet groked the relation between generic phy and usb phy frameworks, but the code is a straight port from Linux and it seems to work[1], so let's upstream it now to make collaboration easier.
[1]: clock the EHCI and power on the PHY and 20% of the time, the bus
can be enumerated completely. Still needs further debugging, but it's unlikely that the PHY driver is at fault.
Cheers,
Ahmad Fatoum (6):
regulator: import Linux regulator_bulk API
phy: remove unused init_data parameter
phy: populate existing ->pwr member with phy-supply
phy: introduce phy_get_by_index
regulator: port over Linux stm32 PWR regulator driver
phy: port over Linux stm32 usbphyc driver
drivers/phy/Kconfig | 13 + drivers/phy/Makefile | 1 + drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 2 +- drivers/phy/phy-core.c | 29 +- drivers/phy/phy-stm32-usbphyc.c | 434 +++++++++++++++++++++ drivers/phy/usb-nop-xceiv.c | 2 +- drivers/pinctrl/pinctrl-tegra-xusb.c | 4 +- drivers/regulator/Kconfig | 7 + drivers/regulator/Makefile | 1 + drivers/regulator/core.c | 139 +++++++ drivers/regulator/stm32-pwr.c | 215 ++++++++++ drivers/usb/imx/imx-usb-phy.c | 2 +- include/linux/phy/phy.h | 14 +- include/regulator.h | 49 +++ 14 files changed, 897 insertions(+), 15 deletions(-) create mode 100644 drivers/phy/phy-stm32-usbphyc.c create mode 100644 drivers/regulator/stm32-pwr.c
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/6 regulator: import Linux regulator_bulk API
Linux v5.6-rc1 contains 168 references to regultor_bulk_get, which allows getting multiple regulators to set at once. Instead of open coding them when porting code, port over the helpers to barebox.
--- drivers/regulator/core.c | 139 +++++++++++++++++++++++++++++++++++++++ include/regulator.h | 49 ++++++++++++++ 2 files changed, 188 insertions(+)
drivers/regulator/core.c +139 -0
@@ -397,6 +397,145 @@ int regulator_set_voltage(struct regulator *r, int min_uV, int max_uV)return regulator_set_voltage_internal (r->ri, min_uV, max_uV); } +/** +* regulator_bulk_get - get multiple regulator consumers +* +* @dev: Device to supply +* @num_consumers: Number of consumers to register +* @consumers: Configuration of consumers; clients are stored here. +* +* @return 0 on success, an errno on failure. +* +* This helper function allows drivers to get several regulator +* consumers in one operation. If any of the regulators cannot be +* acquired then any regulators that were allocated will be freed +* before returning to the caller. +*/ +int regulator_bulk_get (struct device_d *dev,int num_consumers, +struct regulator_bulk_data *consumers) +{ +int i; +int ret; + +for (i =0 ; i < num_consumers; i++) + consumers[i].consumer =NULL ; + +for (i =0 ; i < num_consumers; i++) { + consumers[i].consumer =regulator_get (dev, + consumers[i].supply); +if (IS_ERR (consumers[i].consumer)) { + ret =PTR_ERR (consumers[i].consumer); + consumers[i].consumer =NULL ; + goto err; + } + } + +return 0 ; + +err: +if (ret != -EPROBE_DEFER ) +dev_err (dev,"Failed to get supply '%s': %d\n" , + consumers[i].supply, ret); +else +dev_dbg (dev,"Failed to get supply '%s', deferring\n" , + consumers[i].supply); + +return ret; +} +EXPORT_SYMBOL_GPL (regulator_bulk_get); + +/** +* regulator_bulk_enable - enable multiple regulator consumers +* +* @num_consumers: Number of consumers +* @consumers: Consumer data; clients are stored here. +* @return 0 on success, an errno on failure +* +* This convenience API allows consumers to enable multiple regulator +* clients in a single API call. If any consumers cannot be enabled +* then any others that were enabled will be disabled again prior to +* return. +*/ +int regulator_bulk_enable (int num_consumers, +struct regulator_bulk_data *consumers) +{ +int ret; +int i; + +for (i =0 ; i < num_consumers; i++) { + ret =regulator_enable (consumers[i].consumer); +if (ret) + goto err; + } + +return 0 ; + +err: +while (--i >=0 ) +regulator_disable (consumers[i].consumer); + +return ret; +} +EXPORT_SYMBOL_GPL (regulator_bulk_enable); + +/** +* regulator_bulk_disable - disable multiple regulator consumers +* +* @num_consumers: Number of consumers +* @consumers: Consumer data; clients are stored here. +* @return 0 on success, an errno on failure +* +* This convenience API allows consumers to disable multiple regulator +* clients in a single API call. If any consumers cannot be disabled +* then any others that were disabled will be enabled again prior to +* return. +*/ +int regulator_bulk_disable (int num_consumers, +struct regulator_bulk_data *consumers) +{ +int i; +int ret, r; + +for (i = num_consumers -1 ; i >=0 ; --i) { + ret =regulator_disable (consumers[i].consumer); +if (ret !=0 ) + goto err; + } + +return 0 ; + +err: +pr_err ("Failed to disable %s: %d\n" , consumers[i].supply, ret); +for (++i; i < num_consumers; ++i) { + r =regulator_enable (consumers[i].consumer); +if (r !=0 ) +pr_err ("Failed to re-enable %s: %d\n" , + consumers[i].supply, r); + } + +return ret; +} +EXPORT_SYMBOL_GPL (regulator_bulk_disable); + +/** +* regulator_bulk_free - free multiple regulator consumers +* +* @num_consumers: Number of consumers +* @consumers: Consumer data; clients are stored here. +* +* This convenience API allows consumers to free multiple regulator +* clients in a single API call. +*/ +void regulator_bulk_free (int num_consumers, +struct regulator_bulk_data *consumers) +{ +int i; + +for (i =0 ; i < num_consumers; i++) + consumers[i].consumer =NULL ; +} +EXPORT_SYMBOL_GPL (regulator_bulk_free); +static void regulator_print_one (struct regulator_internal *ri) {struct regulator *r;
include/regulator.h +49 -0
67 lines not on this page · raw message
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/6 phy: remove unused init_data parameter
In reply to Ahmad FatoumLinux has since migrated to a new lookup API that lacks the init_data parameter. As it's unused in barebox, follow suit.
--- drivers/phy/freescale/phy-fsl-imx8mq-usb.c | 2 +- drivers/phy/phy-core.c | 5 +---- drivers/phy/usb-nop-xceiv.c | 2 +- drivers/pinctrl/pinctrl-tegra-xusb.c | 4 ++-- drivers/usb/imx/imx-usb-phy.c | 2 +- include/linux/phy/phy.h | 8 ++------ 6 files changed, 8 insertions(+), 15 deletions(-)
drivers/phy/freescale/phy-fsl-imx8mq-usb.c +1 -1
@@ -106,7 +106,7 @@ static int imx8mq_usb_phy_probe(struct device_d *dev)if (IS_ERR (imx_phy->base))return PTR_ERR (imx_phy->base); - imx_phy->phy =phy_create (dev,NULL , &imx8mq_usb_phy_ops,NULL ); + imx_phy->phy =phy_create (dev,NULL , &imx8mq_usb_phy_ops);if (IS_ERR (imx_phy->phy))return PTR_ERR (imx_phy->phy);
drivers/phy/phy-core.c +1 -4
@@ -25,13 +25,11 @@ static int phy_ida;* @dev: device that is creating the new phy * @node: device node of the phy * @ops: function pointers for performing phy operations -* @init_data: contains the list of PHY consumers or NULL * * Called to create a phy using phy framework. */ struct phy *phy_create (struct device_d *dev,struct device_node *node, -const struct phy_ops *ops, -struct phy_init_data *init_data) +const struct phy_ops *ops) {int ret;int id;
@@ -52,7 +50,6 @@ struct phy *phy_create(struct device_d *dev, struct device_node *node, phy->dev.device_node = node ?: dev->device_node; phy->id = id; phy->ops = ops; - phy->init_data = init_data; ret =register_device (&phy->dev);if (ret)
drivers/phy/usb-nop-xceiv.c +1 -1
@@ -107,7 +107,7 @@ static int nop_usbphy_probe(struct device_d *dev)/* FIXME: Add vbus-detect-gpio support */ nopphy->usb_phy.dev = dev; - nopphy->phy =phy_create (dev,NULL , &nop_phy_ops,NULL ); + nopphy->phy =phy_create (dev,NULL , &nop_phy_ops);if (IS_ERR (nopphy->phy)) { ret =PTR_ERR (nopphy->phy); goto release_gpio;
drivers/pinctrl/pinctrl-tegra-xusb.c +2 -2
@@ -415,7 +415,7 @@ static int pinctrl_tegra_xusb_probe(struct device_d *dev) goto reset; } - phy =phy_create (dev,NULL , &pcie_phy_ops,NULL ); + phy =phy_create (dev,NULL , &pcie_phy_ops);if (IS_ERR (phy)) { err =PTR_ERR (phy); goto unregister;
@@ -424,7 +424,7 @@ static int pinctrl_tegra_xusb_probe(struct device_d *dev) padctl->phys[TEGRA_XUSB_PADCTL_PCIE ] = phy;phy_set_drvdata (phy, padctl); - phy =phy_create (dev,NULL , &sata_phy_ops,NULL ); + phy =phy_create (dev,NULL , &sata_phy_ops);if (IS_ERR (phy)) { err =PTR_ERR (phy); goto unregister;
drivers/usb/imx/imx-usb-phy.c +1 -1
@@ -174,7 +174,7 @@ static int imx_usbphy_probe(struct device_d *dev) imxphy->usb_phy.dev = dev; imxphy->usb_phy.notify_connect = imx_usbphy_notify_connect; imxphy->usb_phy.notify_disconnect = imx_usbphy_notify_disconnect; - imxphy->phy =phy_create (dev,NULL , &imx_phy_ops,NULL ); + imxphy->phy =phy_create (dev,NULL , &imx_phy_ops);if (IS_ERR (imxphy->phy)) { ret =PTR_ERR (imxphy->phy); goto err_clk;
include/linux/phy/phy.h +2 -6
@@ -49,7 +49,6 @@ struct phy_attrs {* @dev: phy device * @id: id of the phy device * @ops: function pointers for performing phy operations -* @init_data: list of PHY consumers (non-dt only) * @mutex: mutex to protect phy_ops * @init_count: used to protect when the PHY is used by multiple consumers * @power_count: used to protect when the PHY is used by multiple consumers
@@ -59,7 +58,6 @@ struct phy {struct device_d dev;int id;const struct phy_ops *ops; -struct phy_init_data *init_data;int init_count;int power_count;struct phy_attrs attrs;
@@ -144,8 +142,7 @@ struct phy *of_phy_get(struct device_node *np, const char *con_id);struct phy *of_phy_simple_xlate (struct device_d *dev,struct of_phandle_args *args);struct phy *phy_create (struct device_d *dev,struct device_node *node, -const struct phy_ops *ops, -struct phy_init_data *init_data); +const struct phy_ops *ops);void phy_destroy (struct phy *phy); struct phy_provider *__of_phy_provider_register(struct device_d *dev, struct phy * (*of_xlate)(struct device_d *dev,
@@ -225,8 +222,7 @@ static inline struct phy *of_phy_simple_xlate(struct device_d *dev,static inline struct phy *phy_create (struct device_d *dev,struct device_node *node, -const struct phy_ops *ops, -struct phy_init_data *init_data) +const struct phy_ops *ops) {return ERR_PTR (-ENOSYS ); }
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 3/6 phy: populate existing ->pwr member with phy-supply
In reply to Ahmad Fatoumbarebox already enables/disables the ->pwr regulator at the correct places, but doesn't assign a value anywhere. Initialize it with the phy-supply regulator like Linux does.
--- drivers/phy/phy-core.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/phy/phy-core.c +10 -0
@@ -51,6 +51,16 @@ struct phy *phy_create(struct device_d *dev, struct device_node *node, phy->id = id; phy->ops = ops; +/* phy-supply */ + phy->pwr =regulator_get (&phy->dev,"phy" ); +if (IS_ERR (phy->pwr)) { + ret =PTR_ERR (phy->pwr); +if (ret == -EPROBE_DEFER ) + goto free_ida; + + phy->pwr =NULL ; + } + ret =register_device (&phy->dev);if (ret) goto free_ida;
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 4/6 phy: introduce phy_get_by_index
In reply to Ahmad FatoumThe upstream (v5.6-rc1) device tree node of the stm32mp157c-dk2's OHCI has a phys property, but not phy-names. We have no API to reference such a phy easily (passing NULL isn't allowed). Add one.
--- drivers/phy/phy-core.c | 14 ++++++++++++++ include/linux/phy/phy.h | 6 ++++++ 2 files changed, 20 insertions(+)
drivers/phy/phy-core.c +14 -0
@@ -371,3 +371,17 @@ struct phy *phy_optional_get(struct device_d *dev, const char *string)return phy; } +/** +* phy_get_by_index() - lookup and obtain a reference to a phy by index. +* @dev: device with node that references this phy +* @index: index of the phy +* +* Gets the phy using _of_phy_get() +*/ +struct phy *phy_get_by_index (struct device_d *dev,int index) +{ +if (!dev->device_node) +return ERR_PTR (-ENODEV ); + +return _of_phy_get (dev->device_node, index); +}
include/linux/phy/phy.h +6 -0
@@ -149,6 +149,7 @@ struct phy_provider *__of_phy_provider_register(struct device_d *dev, struct of_phandle_args *args));void of_phy_provider_unregister (struct phy_provider *phy_provider);struct usb_phy *phy_to_usbphy (struct phy *phy); +struct phy *phy_get_by_index (struct device_d *dev,int index);#else static inline int phy_init (struct phy *phy) {
@@ -247,6 +248,11 @@ static inline struct usb_phy *phy_to_usbphy(struct phy *phy)return NULL ; } +static struct phy *phy_get_by_index (struct device_d *dev,int index) +{ +return ERR_PTR (-ENODEV ); +} +#endif #endif /* __DRIVERS_PHY_H */
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 5/6 regulator: port over Linux stm32 PWR regulator driver
In reply to Ahmad FatoumThis driver supports internal regulators (1V1, 1V8, 3V3) in the STMicroelectronics STM32 chips. Control of these regulators will be required when adding USB support later on.
Imported here is the Linux v5.6-rc1 state of the driver.
--- drivers/regulator/Kconfig | 7 ++ drivers/regulator/Makefile | 1 + drivers/regulator/stm32-pwr.c | 215 ++++++++++++++++++++++++++++++++++ 3 files changed, 223 insertions(+) create mode 100644 drivers/regulator/stm32-pwr.c
drivers/regulator/Kconfig +7 -0
@@ -21,6 +21,13 @@ config REGULATOR_PFUZE depends on I2C depends on ARCH_IMX6 || ARCH_IMX8MQ +config REGULATOR_STM32_PWR + bool "STMicroelectronics STM32 PWR" + depends on ARCH_STM32MP + help + This driver supports internal regulators (1V1, 1V8, 3V3) in the + STMicroelectronics STM32 chips. + config REGULATOR_STPMIC1 tristate "STMicroelectronics STPMIC1 PMIC Regulators" depends on MFD_STPMIC1
drivers/regulator/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_REGULATOR_BCM283X) += bcm2835.o obj-$(CONFIG_REGULATOR_PFUZE) += pfuze.o obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o obj-$(CONFIG_REGULATOR_ANATOP) += anatop-regulator.o +obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o
drivers/regulator/stm32-pwr.c new file +215 -0
215 lines not on this page · raw message
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 6/6 phy: port over Linux stm32 usbphyc driver
In reply to Ahmad FatoumThis ports over the Linux v5.6-rc1 state of the driver. It'll be needed for both EHCI and DWC2 usb connectivity on the stm32mp1.
--- drivers/phy/Kconfig | 13 + drivers/phy/Makefile | 1 + drivers/phy/phy-stm32-usbphyc.c | 434 ++++++++++++++++++++++++++++++++ 3 files changed, 448 insertions(+) create mode 100644 drivers/phy/phy-stm32-usbphyc.c
drivers/phy/Kconfig +13 -0
@@ -24,4 +24,17 @@ config USB_NOP_XCEIV source "drivers/phy/freescale/Kconfig" +config PHY_STM32_USBPHYC + tristate "STM32 USB HS PHY Controller" + depends on ARCH_STM32MP + help + Enable this to support the High-Speed USB transceivers that are part + of some STMicroelectronics STM32 SoCs. + + This driver controls the entire USB PHY block: the USB PHY controller + (USBPHYC) and the two 8-bit wide UTMI+ interfaces. First interface is + used by an HS USB Host controller, and the second one is shared + between an HS USB OTG controller and an HS USB Host controller, + selected by a USB switch. + endif
drivers/phy/Makefile +1 -0
@@ -5,3 +5,4 @@ obj-$(CONFIG_GENERIC_PHY) += phy-core.o obj-$(CONFIG_USB_NOP_XCEIV) += usb-nop-xceiv.o obj-y += freescale/ +obj-$(CONFIG_PHY_STM32_USBPHYC) += phy-stm32-usbphyc.o
drivers/phy/phy-stm32-usbphyc.c new file +434 -0
434 lines not on this page · raw message
Signature · 7 lines
2.25.0 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Quoted 11 lines · Ahmad Fatoum
This is only USB PHY support. Changes to the DWC2 (OTG) and/or OHCI (Host) are still needed to make USB on the MP1 work.
I haven't yet groked the relation between generic phy and usb phy frameworks, but the code is a straight port from Linux and it seems to work[1], so let's upstream it now to make collaboration easier.
[1]: clock the EHCI and power on the PHY and 20% of the time, the bus
can be enumerated completely. Still needs further debugging, but it's unlikely that the PHY driver is at fault.
Quoted 8 lines
Cheers,
Ahmad Fatoum (6):
regulator: import Linuxregulator_bulkAPI
phy: remove unusedinit_dataparameter
phy: populate existing ->pwr member with phy-supply
phy: introducephy_get_by_index
regulator: port over Linux stm32 PWR regulator driver
phy: port over Linux stm32 usbphyc driver
Applied, thanks
Sascha
Signature · 9 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox