Store driver data in per-device private variable as opposed to storing it in global vairables.
Signed-off-by: Andrey Smirnov <andrew.smir...@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 c70d898..57ca86a 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 'iclk'\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 'fclk'\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, ®s->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, ®s->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