mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 12/20] usb: ohci-at91: Convert global variables to private data
Date: Wed,  8 Mar 2017 14:09:01 -0800	[thread overview]
Message-ID: <20170308220909.4560-13-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <20170308220909.4560-1-andrew.smirnov@gmail.com>

Store driver data in per-device private variable as opposed to storing
it in global vairables.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/usb/host/ohci-at91.c | 59 +++++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index ca583ff..cd7b321 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -27,66 +27,81 @@
 
 #include "ohci.h"
 
-/* interface and function clocks; sometimes also an AHB clock */
-static struct clk *iclk, *fclk;
+struct ohci_at91_priv {
+	struct device_d *dev;
+	struct clk *iclk;
+	struct clk *fclk;
+	struct ohci_regs __iomem *regs;
+};
 
-static void at91_start_clock(void)
+static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
 {
-	clk_enable(iclk);
-	clk_enable(fclk);
+	clk_enable(ohci_at91->iclk);
+	clk_enable(ohci_at91->fclk);
 }
 
-static void at91_stop_clock(void)
+static void at91_stop_clock(struct ohci_at91_priv *ohci_at91)
 {
-	clk_disable(fclk);
-	clk_disable(iclk);
+	clk_disable(ohci_at91->fclk);
+	clk_disable(ohci_at91->iclk);
 }
 
 static int at91_ohci_probe(struct device_d *dev)
 {
-	struct ohci_regs __iomem *regs = (struct ohci_regs __iomem *)dev->resource[0].start;
+	struct resource *io;
+	struct ohci_at91_priv *ohci_at91 = xzalloc(sizeof(*ohci_at91));
+
+	dev->priv = ohci_at91;
+	ohci_at91->dev = dev;
+
+	io = dev_get_resource(dev, IORESOURCE_MEM, 0);
+	if (IS_ERR(io)) {
+		dev_err(dev, "Failed to get IORESOURCE_MEM\n");
+		return PTR_ERR(io);
+	}
+	ohci_at91->regs = IOMEM(io->start);
 
-	iclk = clk_get(NULL, "ohci_clk");
-	if (IS_ERR(iclk)) {
+	ohci_at91->iclk = clk_get(NULL, "ohci_clk");
+	if (IS_ERR(ohci_at91->iclk)) {
 		dev_err(dev, "Failed to get 'ohci_clk'\n");
-		return PTR_ERR(iclk);
+		return PTR_ERR(ohci_at91->iclk);
 	}
 
-	fclk = clk_get(NULL, "uhpck");
-	if (IS_ERR(fclk)) {
+	ohci_at91->fclk = clk_get(NULL, "uhpck");
+	if (IS_ERR(ohci_at91->fclk)) {
 		dev_err(dev, "Failed to get 'uhpck'\n");
-		return PTR_ERR(fclk);
+		return PTR_ERR(ohci_at91->fclk);
 	}
 
 	/*
 	 * Start the USB clocks.
 	 */
-	at91_start_clock();
+	at91_start_clock(ohci_at91);
 
 	/*
 	 * The USB host controller must remain in reset.
 	 */
-	writel(0, &regs->control);
+	writel(0, &ohci_at91->regs->control);
 
-	add_generic_device("ohci", DEVICE_ID_DYNAMIC, NULL, dev->resource[0].start,
-			   resource_size(&dev->resource[0]), IORESOURCE_MEM, NULL);
+	add_generic_device("ohci", DEVICE_ID_DYNAMIC, NULL, io->start,
+			   resource_size(io), IORESOURCE_MEM, NULL);
 
 	return 0;
 }
 
 static void at91_ohci_remove(struct device_d *dev)
 {
-	struct ohci_regs __iomem *regs = (struct ohci_regs __iomem *)dev->resource[0].start;
+	struct ohci_at91_priv *ohci_at91 = dev->priv;
 
 	/*
 	 * Put the USB host controller into reset.
 	 */
-	writel(0, &regs->control);
+	writel(0, &ohci_at91->regs->control);
 
 	/*
 	 * Stop the USB clocks.
 	 */
-	at91_stop_clock();
+	at91_stop_clock(ohci_at91);
 }
 
 static struct driver_d at91_ohci_driver = {
-- 
2.9.3


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

  parent reply	other threads:[~2017-03-08 22:09 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-08 22:08 [PATCH 00/20] AT91, at91sam9x5ek updates (part I/III) Andrey Smirnov
2017-03-08 22:08 ` [PATCH 01/20] at91: Fix bug/typo in debug_ll.h Andrey Smirnov
2017-03-08 22:08 ` [PATCH 02/20] regmap: Implement syscon_node_to_regmap() Andrey Smirnov
2017-03-08 22:08 ` [PATCH 03/20] pinctrl: at91: Fix a bug in at91_pinctrl_set_conf() Andrey Smirnov
2017-03-08 22:08 ` [PATCH 04/20] pinctrl: at91: Fix a bug in at91_pinctrl_set_state() Andrey Smirnov
2017-03-08 22:08 ` [PATCH 05/20] pinctrl: at91: Implement .get_direction hook Andrey Smirnov
2017-03-08 22:08 ` [PATCH 06/20] clk: Port two helper functions from Linux Andrey Smirnov
2017-03-08 22:08 ` [PATCH 07/20] clk: Make COMMON_CLK_OF_PROVIDER depend on OFTREE Andrey Smirnov
2017-03-08 22:08 ` [PATCH 08/20] clk: No-op CLK_OF_DECLARE if not enabled Andrey Smirnov
2017-03-09 10:54   ` Sascha Hauer
2017-03-08 22:08 ` [PATCH 09/20] of: base: Use scoring in DT device matching Andrey Smirnov
2017-03-08 22:08 ` [PATCH 10/20] serial: atmel: Check result of clk_get() Andrey Smirnov
2017-03-08 22:09 ` [PATCH 11/20] usb: ohci-at91: " Andrey Smirnov
2017-03-08 22:09 ` Andrey Smirnov [this message]
2017-03-08 22:09 ` [PATCH 13/20] usb: ohci-at91: Check result of clk_enable() Andrey Smirnov
2017-03-08 22:09 ` [PATCH 14/20] usb: ehci-atmel: " Andrey Smirnov
2017-03-08 22:09 ` [PATCH 15/20] usb: echi-atmel: Convert global variables to private data Andrey Smirnov
2017-03-08 22:09 ` [PATCH 16/20] usb: ehci-atmel: Zero ehci_data before using it Andrey Smirnov
2017-03-08 22:09 ` [PATCH 17/20] usb: echi-atmel: Check result of ehci_register() Andrey Smirnov
2017-03-08 22:09 ` [PATCH 18/20] spi: atmel_spi: Configure CS GPIO as output Andrey Smirnov
2017-03-08 22:09 ` [PATCH 19/20] spi: atmel_spi: Use VERSION register instead of CPU type Andrey Smirnov
2017-03-08 22:09 ` [PATCH 20/20] clocksource: at91: Move to 'drivers/clocksource' Andrey Smirnov
2017-03-09  7:19 ` [PATCH 00/20] AT91, at91sam9x5ek updates (part I/III) Sascha Hauer

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=20170308220909.4560-13-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --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