mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 08/23] usb: imx: Make usb-misc multi instance safe
Date: Mon, 16 Jan 2017 11:50:53 +0100	[thread overview]
Message-ID: <20170116105108.13617-9-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20170116105108.13617-1-s.hauer@pengutronix.de>

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>
---
 drivers/usb/imx/chipidea-imx.c |  9 +++++++--
 drivers/usb/imx/imx-usb-misc.c | 34 +++++++++++++++++++++-------------
 include/usb/chipidea-imx.h     |  4 ++--
 3 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/imx/chipidea-imx.c b/drivers/usb/imx/chipidea-imx.c
index ed00ff4a1..f4354876c 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 7c18ca2a1..16fb38018 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;
@@ -524,35 +529,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);
@@ -562,9 +569,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 64f086af6..640ae0694 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 */
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-01-16 10:51 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16 10:50 i.MX7 support Sascha Hauer
2017-01-16 10:50 ` [PATCH 01/23] imx-usb-loader: let constant data be const Sascha Hauer
2017-01-16 10:50 ` [PATCH 02/23] imx-usb-loader: this table is used internally only, so keep it static Sascha Hauer
2017-01-16 11:29   ` Juergen Borleis
2017-01-16 10:50 ` [PATCH 03/23] imx-usb-loader: add i.MX7S support Sascha Hauer
2017-01-16 10:50 ` [PATCH 04/23] ARM: Makefile: format fix Sascha Hauer
2017-01-16 10:50 ` [PATCH 05/23] i2c: i.MX: Enable clock Sascha Hauer
2017-01-16 10:50 ` [PATCH 06/23] mci: imx-esdhc: " Sascha Hauer
2017-01-16 10:50 ` [PATCH 07/23] serial: i.MX: " Sascha Hauer
2017-01-16 10:50 ` Sascha Hauer [this message]
2017-01-16 10:50 ` [PATCH 09/23] usb: imx: Add usbmisc support for i.MX7 Sascha Hauer
2017-01-16 10:50 ` [PATCH 10/23] usb: imx: Add clock support Sascha Hauer
2017-01-16 10:50 ` [PATCH 11/23] phy: usb-nop-xceiv: " Sascha Hauer
2017-01-16 10:50 ` [PATCH 12/23] of: partitions: force "partitions" subnode Sascha Hauer
2017-01-16 10:50 ` [PATCH 13/23] mci: Allow to partition eMMC boot partitions Sascha Hauer
2017-01-16 10:50 ` [PATCH 14/23] mci: imx-esdhci: remove wrong write protection test Sascha Hauer
2017-01-16 10:51 ` [PATCH 15/23] ARM: i.MX: Add i.MX7 base architecture support Sascha Hauer
2017-01-16 10:51 ` [PATCH 16/23] clk: i.MX: pllv3: Add support for the i.MX7 enet pll Sascha Hauer
2017-01-16 10:51 ` [PATCH 17/23] clk: imx: Add clk-cpu support Sascha Hauer
2017-01-16 10:51 ` [PATCH 18/23] clk: i.MX: Add clock support for i.MX7 Sascha Hauer
2017-01-16 10:51 ` [PATCH 19/23] clk: i.MX7: Add missing USB clocks Sascha Hauer
2017-01-16 10:51 ` [PATCH 20/23] ARM: i.MX: gpt: Add i.MX7 support Sascha Hauer
2017-01-16 11:35   ` Juergen Borleis
2017-01-16 10:51 ` [PATCH 21/23] pinmmux: i.MX: add pin mux support for i.MX7 Sascha Hauer
2017-01-16 10:51 ` [PATCH 22/23] serial: i.MX: add i.MX7 support Sascha Hauer
2017-01-16 10:51 ` [PATCH 23/23] ARM: i.MX: Add WaRP7 board support Sascha Hauer
2017-01-16 10:58 ` i.MX7 support Fabio Estevam
2017-01-16 12:58   ` Sascha Hauer
2017-01-17 12:07     ` Fabio Estevam
2017-01-18  7:07       ` Sascha Hauer
2017-01-18  9:36         ` Fabio Estevam
2017-01-19  9:14           ` Sascha Hauer
2017-01-19 11:54             ` Fabio Estevam
2017-01-19 12:38               ` Sascha Hauer
2017-01-19 17:32                 ` Fabio Estevam
2017-01-16 11:02 ` Belisko Marek
2017-01-16 11:38   ` Robert Schwebel
2017-01-16 11:51     ` Belisko Marek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170116105108.13617-9-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox