9
0
Fork 0

usb: ohci-at91: Convert global variables to private data

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>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Andrey Smirnov 2017-03-08 14:09:01 -08:00 committed by Sascha Hauer
parent 56f3bd1cd3
commit fb1ff1794a
1 changed files with 37 additions and 22 deletions

View File

@ -27,66 +27,81 @@
#include "ohci.h" #include "ohci.h"
/* interface and function clocks; sometimes also an AHB clock */ struct ohci_at91_priv {
static struct clk *iclk, *fclk; 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(ohci_at91->iclk);
clk_enable(fclk); 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(ohci_at91->fclk);
clk_disable(iclk); clk_disable(ohci_at91->iclk);
} }
static int at91_ohci_probe(struct device_d *dev) 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));
iclk = clk_get(NULL, "ohci_clk"); dev->priv = ohci_at91;
if (IS_ERR(iclk)) { 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);
ohci_at91->iclk = clk_get(NULL, "ohci_clk");
if (IS_ERR(ohci_at91->iclk)) {
dev_err(dev, "Failed to get 'ohci_clk'\n"); dev_err(dev, "Failed to get 'ohci_clk'\n");
return PTR_ERR(iclk); return PTR_ERR(ohci_at91->iclk);
} }
fclk = clk_get(NULL, "uhpck"); ohci_at91->fclk = clk_get(NULL, "uhpck");
if (IS_ERR(fclk)) { if (IS_ERR(ohci_at91->fclk)) {
dev_err(dev, "Failed to get 'uhpck'\n"); dev_err(dev, "Failed to get 'uhpck'\n");
return PTR_ERR(fclk); return PTR_ERR(ohci_at91->fclk);
} }
/* /*
* Start the USB clocks. * Start the USB clocks.
*/ */
at91_start_clock(); at91_start_clock(ohci_at91);
/* /*
* The USB host controller must remain in reset. * 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, add_generic_device("ohci", DEVICE_ID_DYNAMIC, NULL, io->start,
resource_size(&dev->resource[0]), IORESOURCE_MEM, NULL); resource_size(io), IORESOURCE_MEM, NULL);
return 0; return 0;
} }
static void at91_ohci_remove(struct device_d *dev) 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. * Put the USB host controller into reset.
*/ */
writel(0, &regs->control); writel(0, &ohci_at91->regs->control);
/* /*
* Stop the USB clocks. * Stop the USB clocks.
*/ */
at91_stop_clock(); at91_stop_clock(ohci_at91);
} }
static struct driver_d at91_ohci_driver = { static struct driver_d at91_ohci_driver = {