summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-01-13 12:10:04 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-01-19 15:16:30 +0100
commitfc10539f7dc088f2466cfcf21899a461f93feedf (patch)
tree4dbd1568e8f58b6cb8ace68f6ea65327a5b33953
parent1bcd04831eaa2e05fece0eb0c604516bdd242d6a (diff)
downloadbarebox-fc10539f7dc088f2466cfcf21899a461f93feedf.tar.gz
usb: imx: Make usb-misc multi instance safe
i.MX7 has two usbmisc devices, so we cannot use global instance variables anymore. Create a driver private data struct for it. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/usb/imx/chipidea-imx.c9
-rw-r--r--drivers/usb/imx/imx-usb-misc.c34
-rw-r--r--include/usb/chipidea-imx.h4
3 files changed, 30 insertions, 17 deletions
diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index ed00ff4..f435487 100644
--- a/drivers/usb/imx/chipidea-imx.c
+++ b/drivers/usb/imx/chipidea-imx.c
@@ -37,6 +37,7 @@ struct imx_chipidea {
unsigned long flags;
uint32_t mode;
int portno;
+ struct device_d *usbmisc;
enum usb_phy_interface phymode;
struct param_d *param_mode;
int role_registered;
@@ -67,7 +68,7 @@ static int imx_chipidea_port_init(void *drvdata)
return ret;
}
- ret = imx_usbmisc_port_init(ci->portno, ci->flags);
+ ret = imx_usbmisc_port_init(ci->usbmisc, ci->portno, ci->flags);
if (ret)
dev_err(ci->dev, "misc init failed: %s\n", strerror(-ret));
@@ -79,7 +80,7 @@ static int imx_chipidea_port_post_init(void *drvdata)
struct imx_chipidea *ci = drvdata;
int ret;
- ret = imx_usbmisc_port_post_init(ci->portno, ci->flags);
+ ret = imx_usbmisc_port_post_init(ci->usbmisc, ci->portno, ci->flags);
if (ret)
dev_err(ci->dev, "post misc init failed: %s\n", strerror(-ret));
@@ -95,6 +96,10 @@ static int imx_chipidea_probe_dt(struct imx_chipidea *ci)
"#index-cells", 0, &out_args))
return -ENODEV;
+ ci->usbmisc = of_find_device_by_node(out_args.np);
+ if (!ci->usbmisc)
+ return -ENODEV;
+
ci->portno = out_args.args[0];
ci->flags = MXC_EHCI_MODE_UTMI_8BIT;
diff --git a/drivers/usb/imx/imx-usb-misc.c b/drivers/usb/imx/imx-usb-misc.c
index 9cae440..b7606e2 100644
--- a/drivers/usb/imx/imx-usb-misc.c
+++ b/drivers/usb/imx/imx-usb-misc.c
@@ -43,6 +43,11 @@ struct imx_usb_misc_data {
int (*post_init)(void __iomem *base, int port, unsigned int flags);
};
+struct imx_usb_misc_priv {
+ struct imx_usb_misc_data *data;
+ void __iomem *base;
+};
+
static __maybe_unused int mx25_initialize_usb_hw(void __iomem *base, int port, unsigned int flags)
{
unsigned int v;
@@ -552,35 +557,37 @@ static __maybe_unused struct of_device_id imx_usbmisc_dt_ids[] = {
},
};
-static struct imx_usb_misc_data *imxusbmisc_data;
-static void __iomem *usbmisc_base;
-
-int imx_usbmisc_port_init(int port, unsigned flags)
+int imx_usbmisc_port_init(struct device_d *dev, int port, unsigned flags)
{
- if (!imxusbmisc_data)
+ struct imx_usb_misc_priv *usbmisc = dev->priv;
+
+ if (!usbmisc)
return -ENODEV;
- if (!imxusbmisc_data->init)
+ if (!usbmisc->data->init)
return 0;
- return imxusbmisc_data->init(usbmisc_base, port, flags);
+ return usbmisc->data->init(usbmisc->base, port, flags);
}
-int imx_usbmisc_port_post_init(int port, unsigned flags)
+int imx_usbmisc_port_post_init(struct device_d *dev, int port, unsigned flags)
{
- if (!imxusbmisc_data)
+ struct imx_usb_misc_priv *usbmisc = dev->priv;
+
+ if (!usbmisc)
return -ENODEV;
- if (!imxusbmisc_data->post_init)
+ if (!usbmisc->data->post_init)
return 0;
- return imxusbmisc_data->post_init(usbmisc_base, port, flags);
+ return usbmisc->data->post_init(usbmisc->base, port, flags);
}
static int imx_usbmisc_probe(struct device_d *dev)
{
struct resource *iores;
struct imx_usb_misc_data *devtype;
+ struct imx_usb_misc_priv *usbmisc = dev->priv;
int ret;
ret = dev_get_drvdata(dev, (const void **)&devtype);
@@ -590,9 +597,10 @@ static int imx_usbmisc_probe(struct device_d *dev)
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
return PTR_ERR(iores);
- usbmisc_base = IOMEM(iores->start);
- imxusbmisc_data = devtype;
+ usbmisc = xzalloc(sizeof(*usbmisc));
+ usbmisc->base = IOMEM(iores->start);
+ usbmisc->data = devtype;
return 0;
}
diff --git a/include/usb/chipidea-imx.h b/include/usb/chipidea-imx.h
index 64f086a..640ae06 100644
--- a/include/usb/chipidea-imx.h
+++ b/include/usb/chipidea-imx.h
@@ -48,7 +48,7 @@ struct imxusb_platformdata {
enum imx_usb_mode mode;
};
-int imx_usbmisc_port_init(int port, unsigned flags);
-int imx_usbmisc_port_post_init(int port, unsigned flags);
+int imx_usbmisc_port_init(struct device_d *dev, int port, unsigned flags);
+int imx_usbmisc_port_post_init(struct device_d *dev, int port, unsigned flags);
#endif /* __USB_CHIPIDEA_IMX_H */