Skip to content
Snippets Groups Projects
Commit e98f39be authored by Troy Kisky's avatar Troy Kisky
Browse files

xhci-imx8m: add CONFIG_DM_USB support

parent 01e1bed7
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,15 @@
*/
#include <common.h>
#include <asm-generic/gpio.h>
#include <clk.h>
#include <usb.h>
#include <linux/errno.h>
#include <linux/compat.h>
#include <linux/usb/dwc3.h>
#include <asm/arch/sys_proto.h>
#include "xhci.h"
#include <dm.h>
/* Declare global data pointer */
DECLARE_GLOBAL_DATA_PTR;
......@@ -47,10 +50,22 @@ struct imx8m_usbctrl_data {
u32 usb_id;
unsigned long ctr_addr;
};
#ifdef CONFIG_DM_USB
struct xhci_imx8m_priv {
struct xhci_ctrl xhci;
struct clk_bulk clks;
#ifdef CONFIG_DM_GPIO
struct gpio_desc reset_gpio;
#endif
};
#else
static struct imx8m_usbctrl_data ctr_data[] = {
{0, USB1_BASE_ADDR},
{1, USB2_BASE_ADDR},
};
#endif
static void imx8m_usb_phy_init(struct imx8m_usbmix *usbmix_reg)
{
......@@ -135,6 +150,98 @@ int imx8m_usb_common_init(void *base, struct xhci_hccr **hccr, struct xhci_hcor
return ret;
}
#ifdef CONFIG_DM_USB
static int imx8_of_clk_init(struct udevice *dev,
struct xhci_imx8m_priv *priv)
{
int ret;
ret = clk_get_bulk(dev, &priv->clks);
if (ret == -ENOSYS)
return 0;
if (ret)
return ret;
#if CONFIG_IS_ENABLED(CLK)
ret = clk_enable_bulk(&priv->clks);
if (ret) {
clk_release_bulk(&priv->clks);
return ret;
}
#endif
return 0;
}
#ifdef CONFIG_DM_GPIO
static void imx8_of_reset_gpio_init(struct udevice *dev,
struct xhci_imx8m_priv *priv)
{
gpio_request_by_name(dev, "reset-gpios", 0, &priv->reset_gpio,
GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
if (dm_gpio_is_valid(&priv->reset_gpio)) {
udelay(500);
/* release reset */
dm_gpio_set_value(&priv->reset_gpio, 0);
}
}
#else
static void imx8_of_reset_gpio_init(struct udevice *dev,
struct xhci_imx8m_priv *priv)
{
}
#endif
static int imx8m_xhci_probe(struct udevice *dev)
{
struct xhci_imx8m_priv *priv = dev_get_priv(dev);
struct xhci_hccr *hccr;
struct xhci_hcor *hcor;
fdt_addr_t hcd_base;
int ret = 0;
/*
* Get the base address for XHCI controller from the device node
*/
hcd_base = devfdt_get_addr(dev);
if (hcd_base == FDT_ADDR_T_NONE) {
printf("Can't get the XHCI register base address\n");
return -ENXIO;
}
imx8m_usb_power(hcd_base == USB1_BASE_ADDR ? 0 : 1, true);
imx8_of_clk_init(dev, priv);
imx8_of_reset_gpio_init(dev, priv);
ret = imx8m_usb_common_init((void *)hcd_base, &hccr, &hcor);
if (ret < 0)
return ret;
return xhci_register(dev, hccr, hcor);
}
static int imx8m_xhci_remove(struct udevice *dev)
{
return xhci_deregister(dev);
}
static const struct udevice_id xhci_usb_ids[] = {
{ .compatible = "fsl,imx8mq-dwc3", },
{ }
};
U_BOOT_DRIVER(imx8m_xhci) = {
.name = "imx8m_xhci",
.id = UCLASS_USB,
.of_match = xhci_usb_ids,
.probe = imx8m_xhci_probe,
.remove = imx8m_xhci_remove,
.ops = &xhci_usb_ops,
.platdata_auto_alloc_size = sizeof(struct usb_platdata),
.priv_auto_alloc_size = sizeof(struct xhci_imx8m_priv),
.flags = DM_FLAG_ALLOC_PRIV_DMA,
};
#else
int xhci_hcd_init(int index, struct xhci_hccr **hccr, struct xhci_hcor **hcor)
{
int ret = 0;
......@@ -152,3 +259,4 @@ void xhci_hcd_stop(int index)
{
board_usb_cleanup(ctr_data[index].usb_id, USB_INIT_HOST);
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment