Re: [PATCH v2 2/2] clk: at91: Fix for PLL set_rate changes not being actually written to PLL peripheral bits

2018-04-10 Thread Boris Brezillon
Hi Marcin,

On Mon, 9 Apr 2018 20:16:49 -0400
Marcin Ziemianowicz  wrote:

> When a USB device is connected to the USB host port on the SAM9N12 then
> you get "-62" error which seems to indicate USB replies from the device
> are timing out. Looking around, I saw the USB bus was running at half
> speed. Going further, it seems that in ..._set_rate() the PLL wasn't
> actually being adjusted. Writing the multiplier and divider values to
> the peripheral fixes the bus running at half speed.
> 
> Signed-off-by: Marcin Ziemianowicz 
> ---
>  drivers/clk/at91/clk-pll.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/clk/at91/clk-pll.c b/drivers/clk/at91/clk-pll.c
> index 534961766ae5..db7155fe9346 100644
> --- a/drivers/clk/at91/clk-pll.c
> +++ b/drivers/clk/at91/clk-pll.c
> @@ -288,6 +288,14 @@ static int clk_pll_set_rate(struct clk_hw *hw, unsigned 
> long rate,
>   pll->div = div;
>   pll->mul = mul;
>  
> + // Set the PLL as per above div and mil values.
^ mul

Please do not use C++-style comments, use /* comment */ instead.

> + regmap_update_bits(pll->regmap, AT91_CKGR_PLLBR,

You hardcode the PLL ID here. What if this function if called for PLLA?

> + AT91_PMC_DIV | AT91_PMC_MUL,

You should use PLL_MUL_MASK(layout) and PLL_DIV_MASK to do that.

> + (div << 0) | (mul << 16));

This is wrong. The clk has the CLK_SET_RATE_GATE set, which means the
rate cannot be updated if the PLL is not gated, and if you look at
clk_pll_prepare(), you'll see that div and mul fields are updated
there. Now, maybe there's a bug in clk_pll_prepare(), but
clk_pll_set_rate() is definitely not the place where we want ->div and
->mul to be written to the register.

> +
> + pr_debug("clk-pll: setting new rate, (%lu hz / %u) * %u = %lu hz\n",
> + parent_rate, div, mul, rate);
> +
>   return 0;
>  }
>  

Regards,

Boris
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 1/2] clk: at91: Added more information logging.

2018-04-10 Thread Boris Brezillon
Hi Marcin,

On Mon, 9 Apr 2018 20:16:21 -0400
Marcin Ziemianowicz  wrote:

> I noticed that when debugging some USB clocking issue that there weren't
> many ways to tell what the state of the USB clocking system was. This
> adds a few logging statements to see what the relevant code is trying to
> do.
> 
> Signed-off-by: Marcin Ziemianowicz 
> ---
>  drivers/clk/at91/clk-pll.c   |  6 +-
>  drivers/clk/at91/clk-usb.c   | 10 --
>  drivers/usb/host/ohci-at91.c | 16 ++--

This should be split in 2 patches (one adding traces to clk drivers and
another doing it for the USB host driver), so that those patches can be
merged independently by the clk and usb maintainers.

>  3 files changed, 23 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/clk/at91/clk-pll.c b/drivers/clk/at91/clk-pll.c
> index 7d3223fc7161..534961766ae5 100644
> --- a/drivers/clk/at91/clk-pll.c
> +++ b/drivers/clk/at91/clk-pll.c
> @@ -133,6 +133,7 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw 
> *hw,
>  {
>   struct clk_pll *pll = to_clk_pll(hw);
>   unsigned int pllr;
> + unsigned long recalcedrate;

Just name it 'rate' or 'realrate'.

>   u16 mul;
>   u8 div;
>  
> @@ -144,7 +145,10 @@ static unsigned long clk_pll_recalc_rate(struct clk_hw 
> *hw,
>   if (!div || !mul)
>   return 0;
>  
> - return (parent_rate / div) * (mul + 1);
> + recalcedrate = (parent_rate / div) * (mul + 1);
> + pr_debug("clk-pll: calculating new rate, (%lu hz / %u) * %u = %lu hz\n",

If the prefix is alway "clk-pll: " you could define pr_fmt() to add it
to all your pr_xxx() messages.

BTW, it's not about calculating the new rate, but retrieving the
actual rate.

> + parent_rate, div, mul, recalcedrate);

Add an empty line here.

> + return recalcedrate;
>  }
>  
>  static long clk_pll_get_best_div_mul(struct clk_pll *pll, unsigned long rate,
> diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
> index 791770a563fc..2fa877e99bac 100644
> --- a/drivers/clk/at91/clk-usb.c
> +++ b/drivers/clk/at91/clk-usb.c
> @@ -48,11 +48,15 @@ static unsigned long 
> at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw,
>   struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
>   unsigned int usbr;
>   u8 usbdiv;
> + unsigned int calcdclock;

Ditto: s/calcdclock/realrate/, and make it unsigned long.

>  
>   regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
>   usbdiv = (usbr & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
>  
> - return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
> + calcdclock = DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
> + pr_debug("clk-usb: calculating new rate, %lu hz / %u = %u hz\n",
> + parent_rate, usbdiv + 1, calcdclock);

Empty line here too.

> + return calcdclock;
>  }
>  
>  static int at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw,
> @@ -98,7 +102,6 @@ static int at91sam9x5_clk_usb_determine_rate(struct clk_hw 
> *hw,
>   if (!best_diff)
>   break;
>   }
> -
>   if (best_rate < 0)
>   return best_rate;
>  
> @@ -142,6 +145,9 @@ static int at91sam9x5_clk_usb_set_rate(struct clk_hw *hw, 
> unsigned long rate,
>   if (div > SAM9X5_USB_MAX_DIV + 1 || !div)
>   return -EINVAL;
>  
> + pr_debug("clk-usb: setting USB clock divider to %lu hz / %lu = %lu 
> hz\n",

The formulation is weird. Maybe you should just remove 'divider' here:

"setting USB clock to %lu hz / %lu = %lu hz"

> + parent_rate, div, rate);
> +
>   regmap_update_bits(usb->regmap, AT91_PMC_USB, AT91_PMC_OHCIUSBDIV,
>  (div - 1) << SAM9X5_USB_DIV_SHIFT);
>  
> diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
> index 5ad9e9bdc8ee..c57a239918f9 100644
> --- a/drivers/usb/host/ohci-at91.c
> +++ b/drivers/usb/host/ohci-at91.c
> @@ -70,11 +70,13 @@ static const struct ohci_driver_overrides 
> ohci_at91_drv_overrides __initconst =
>  
>  /*-*/
>  
> -static void at91_start_clock(struct ohci_at91_priv *ohci_at91)
> +static void at91_start_clock(struct ohci_at91_priv *ohci_at91,
> + struct device *dev)

Maybe you could just pass a pdev or dev pointer and let the function
extract the ohci_at91 object with:

struct usb_hcd *hcd = platform_get_drvdata(pdev);
struct ohci_at91_priv *ohci_at91 = hcd_to_ohci_at91_priv(hcd);

>  {
>   if (ohci_at91->clocked)
>   return;
>  
> + dev_dbg(dev, "Enabling hclk, iclk, and setting fclk to 48 Mhz\n");

Add an empty line here.

>   clk_set_rate(ohci_at91->fclk, 4800);
>   clk_prepare_enable(ohci_at91->hclk);
>   clk_prepare_enable(ohci_at91->iclk);
> @@ -82,11 +84,13 @@ static void at91_start_clock(struct ohci_at91_priv 
> *ohci_at91)
>   ohci_at91->clocked = true;
>  }
>  
> -static void

Re: [PATCH v2 0/2] clk: at91: Added more information logging

2018-04-10 Thread Boris Brezillon
Hi Marcin

On Mon, 9 Apr 2018 20:15:51 -0400
Marcin Ziemianowicz  wrote:

> This is a series of patches which resolves set_rate() for the PLL not
> having any effect and therefore the USB Host port not working. Also, a
> few messages were added which may be helpful in the future when others
> are working with USB clocking.

Can you please send patch series in a threaded manner (the cover
letter being the mail email and patches 1 to X being tagged as
'In-reply-to')? Normally, git send-email takes care of that for you if
you do

# git send-email *.patch

> 
> Changes since V1:
>   Added patch set cover letter
>   Shortened lines which were over >80 characters long
>   > Comment by Greg Kroah-Hartman about "from" field in email addressed
>   > Comment by Alan Stern about redundant debug lines addressed  
> 
> hak8or (2):
>   clk: at91: Added more information logging.
>   clk: at91: Fix for PLL set_rate changes not being actually written to
> PLL peripheral bits
> 
>  drivers/clk/at91/clk-pll.c   | 14 +-
>  drivers/clk/at91/clk-usb.c   | 10 --
>  drivers/usb/host/ohci-at91.c | 16 ++--
>  3 files changed, 31 insertions(+), 9 deletions(-)
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 00/47] arch-removal: device drivers

2018-03-14 Thread Boris Brezillon
Hi Arnd,

On Wed, 14 Mar 2018 16:35:13 +0100
Arnd Bergmann  wrote:

> Hi driver maintainers,
> 
> I just posted one series with the removal of eight architectures,
> see https://lkml.org/lkml/2018/3/14/505 for details, or
> https://lwn.net/Articles/748074/ for more background.
> 
> These are the device drivers that go along with them. I have already
> picked up the drivers for arch/metag/ into my tree, they were reviewed
> earlier.
> 
> Please let me know if you have any concerns with the patch, or if you
> prefer to pick up the patches in your respective trees.  I created
> the patches with 'git format-patch -D', so they will not apply without
> manually removing those files.
> 
> For anything else, I'd keep the removal patches in my asm-generic tree
> and will send a pull request for 4.17 along with the actual arch removal.
> 
>Arnd
> 
> Arnd Bergmann
>   edac: remove tile driver
>   net: tile: remove ethernet drivers
>   net: adi: remove blackfin ethernet drivers
>   net: 8390: remove m32r specific bits
>   net: remove cris etrax ethernet driver
>   net: smsc: remove m32r specific smc91x configuration
>   raid: remove tile specific raid6 implementation
>   rtc: remove tile driver
>   rtc: remove bfin driver
>   char: remove obsolete ds1302 rtc driver
>   char: remove tile-srom.c
>   char: remove blackfin OTP driver
>   pcmcia: remove m32r drivers
>   pcmcia: remove blackfin driver
>   ASoC: remove blackfin drivers
>   video/logo: remove obsolete logo files
>   fbdev: remove blackfin drivers
>   fbdev: s1d13xxxfb: remove m32r specific hacks
>   crypto: remove blackfin CRC driver
>   media: platform: remove blackfin capture driver
>   media: platform: remove m32r specific arv driver
>   cpufreq: remove blackfin driver
>   cpufreq: remove cris specific drivers
>   gpio: remove etraxfs driver
>   pinctrl: remove adi2/blackfin drivers
>   ata: remove bf54x driver
>   input: keyboard: remove bf54x driver
>   input: misc: remove blackfin rotary driver
>   mmc: remove bfin_sdh driver
>   can: remove bfin_can driver
>   watchdog: remove bfin_wdt driver
>   mtd: maps: remove bfin-async-flash driver
>   mtd: nand: remove bf5xx_nand driver

If you don't mind, I'd like to take the mtd patches through the MTD
tree. As you've probably noticed, nand code has been moved around and
it's easier for me to carry those 2 simple changes in my tree than
creating an immutable branch.

Let me know if this is a problem.

Regards,

Boris

-- 
Boris Brezillon, Bootlin (formerly Free Electrons)
Embedded Linux and Kernel engineering
https://bootlin.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 4/8] mtd: nand: atmel: Avoid ECC errors when leaving backup mode

2017-10-05 Thread Boris Brezillon
On Thu, 28 Sep 2017 11:46:23 +0200
Romain Izard  wrote:

> During backup mode, the contents of all registers will be cleared as the
> SoC will be completely powered down. For a product that boots on NAND
> Flash memory, the bootloader will obviously use the related controller
> to read the Flash and correct any detected error in the memory, before
> handling back control to the kernel's resuming entry point.
> 
> But it does not clean the NAND controller registers after use and on its
> side the kernel driver expects the error locator to be powered down and
> in a clean state. Add a resume hook for the PMECC error locator, and
> reset its registers.
> 
> Signed-off-by: Romain Izard 

Applied.

Thanks,

Boris

> ---
> Changes in v3:
> * keep the PMECC disabled when not in use, and use atmel_pmecc_resume to
>   reset the controller after the bootloader has left it enabled.
> 
> Changes in v4:
> * export atmel_pmecc_reset instead of atmel_pmecc_resume
> * use the correct pointer in atmel_nand_controller_resume
> 
>  drivers/mtd/nand/atmel/nand-controller.c |  3 +++
>  drivers/mtd/nand/atmel/pmecc.c   | 17 +
>  drivers/mtd/nand/atmel/pmecc.h   |  1 +
>  3 files changed, 13 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mtd/nand/atmel/nand-controller.c 
> b/drivers/mtd/nand/atmel/nand-controller.c
> index f25eca79f4e5..8afcff9a66ea 100644
> --- a/drivers/mtd/nand/atmel/nand-controller.c
> +++ b/drivers/mtd/nand/atmel/nand-controller.c
> @@ -2530,6 +2530,9 @@ static __maybe_unused int 
> atmel_nand_controller_resume(struct device *dev)
>   struct atmel_nand_controller *nc = dev_get_drvdata(dev);
>   struct atmel_nand *nand;
>  
> + if (nc->pmecc)
> + atmel_pmecc_reset(nc->pmecc);
> +
>   list_for_each_entry(nand, &nc->chips, node) {
>   int i;
>  
> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
> index 146af8218314..0a3f12141c45 100644
> --- a/drivers/mtd/nand/atmel/pmecc.c
> +++ b/drivers/mtd/nand/atmel/pmecc.c
> @@ -765,6 +765,13 @@ void atmel_pmecc_get_generated_eccbytes(struct 
> atmel_pmecc_user *user,
>  }
>  EXPORT_SYMBOL_GPL(atmel_pmecc_get_generated_eccbytes);
>  
> +void atmel_pmecc_reset(struct atmel_pmecc *pmecc)
> +{
> + writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> + writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
> +}
> +EXPORT_SYMBOL_GPL(atmel_pmecc_reset);
> +
>  int atmel_pmecc_enable(struct atmel_pmecc_user *user, int op)
>  {
>   struct atmel_pmecc *pmecc = user->pmecc;
> @@ -797,10 +804,7 @@ EXPORT_SYMBOL_GPL(atmel_pmecc_enable);
>  
>  void atmel_pmecc_disable(struct atmel_pmecc_user *user)
>  {
> - struct atmel_pmecc *pmecc = user->pmecc;
> -
> - writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> - writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
> + atmel_pmecc_reset(user->pmecc);
>   mutex_unlock(&user->pmecc->lock);
>  }
>  EXPORT_SYMBOL_GPL(atmel_pmecc_disable);
> @@ -855,10 +859,7 @@ static struct atmel_pmecc *atmel_pmecc_create(struct 
> platform_device *pdev,
>  
>   /* Disable all interrupts before registering the PMECC handler. */
>   writel(0x, pmecc->regs.base + ATMEL_PMECC_IDR);
> -
> - /* Reset the ECC engine */
> - writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> - writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
> + atmel_pmecc_reset(pmecc);
>  
>   return pmecc;
>  }
> diff --git a/drivers/mtd/nand/atmel/pmecc.h b/drivers/mtd/nand/atmel/pmecc.h
> index a8ddbfca2ea5..817e0dd9fd15 100644
> --- a/drivers/mtd/nand/atmel/pmecc.h
> +++ b/drivers/mtd/nand/atmel/pmecc.h
> @@ -61,6 +61,7 @@ atmel_pmecc_create_user(struct atmel_pmecc *pmecc,
>   struct atmel_pmecc_user_req *req);
>  void atmel_pmecc_destroy_user(struct atmel_pmecc_user *user);
>  
> +void atmel_pmecc_reset(struct atmel_pmecc *pmecc);
>  int atmel_pmecc_enable(struct atmel_pmecc_user *user, int op);
>  void atmel_pmecc_disable(struct atmel_pmecc_user *user);
>  int atmel_pmecc_wait_rdy(struct atmel_pmecc_user *user);

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 4/8] mtd: nand: atmel: Avoid ECC errors when leaving backup mode

2017-09-27 Thread Boris Brezillon
On Wed, 27 Sep 2017 10:35:51 +0200
Romain Izard  wrote:

> During backup mode, the contents of all registers will be cleared as the
> SoC will be completely powered down. For a product that boots on NAND
> Flash memory, the bootloader will obviously use the related controller
> to read the Flash and correct any detected error in the memory, before
> handling back control to the kernel's resuming entry point.
> 
> But it does not clean the NAND controller registers after use and on its
> side the kernel driver expects the error locator to be powered down and
> in a clean state. Add a resume hook for the PMECC error locator, and
> reset its registers.
> 
> Signed-off-by: Romain Izard 
> ---
> Change in v3:
> * keep the PMECC disabled when not in use, and use atmel_pmecc_resume to
>   reset the controller after the bootloader has left it enabled.
> 
>  drivers/mtd/nand/atmel/nand-controller.c |  3 +++
>  drivers/mtd/nand/atmel/pmecc.c   | 22 ++
>  drivers/mtd/nand/atmel/pmecc.h   |  1 +
>  3 files changed, 18 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mtd/nand/atmel/nand-controller.c 
> b/drivers/mtd/nand/atmel/nand-controller.c
> index f25eca79f4e5..86c2199380c2 100644
> --- a/drivers/mtd/nand/atmel/nand-controller.c
> +++ b/drivers/mtd/nand/atmel/nand-controller.c
> @@ -2530,6 +2530,9 @@ static __maybe_unused int 
> atmel_nand_controller_resume(struct device *dev)
>   struct atmel_nand_controller *nc = dev_get_drvdata(dev);
>   struct atmel_nand *nand;
>  
> + if (nand->pmecc)
> + atmel_pmecc_resume(nand->pmecc);
> +

nand is used uninitialized here, and atmel_pmecc_resume() should be
passed a atmel_pmecc object not a atmel_pmecc_user.

if (nc->pmecc)
atmel_pmecc_resume(nc->pmecc);

>   list_for_each_entry(nand, &nc->chips, node) {
>   int i;
>  
> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
> index 146af8218314..ff09c0f25dd4 100644
> --- a/drivers/mtd/nand/atmel/pmecc.c
> +++ b/drivers/mtd/nand/atmel/pmecc.c
> @@ -765,6 +765,12 @@ void atmel_pmecc_get_generated_eccbytes(struct 
> atmel_pmecc_user *user,
>  }
>  EXPORT_SYMBOL_GPL(atmel_pmecc_get_generated_eccbytes);
>  
> +void atmel_pmecc_reset(struct atmel_pmecc *pmecc)
> +{
> + writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> + writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
> +}

It's not used outside of this file, so it should have a static
specifier. Anyway, I wonder why you don't expose atmel_pmecc_reset()
directly instead of creating this atmel_pmecc_resume() wrapper.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 5/9] mtd: nand: atmel: Report PMECC failures as errors

2017-09-18 Thread Boris Brezillon
Hi Romain,

On Fri, 15 Sep 2017 16:04:07 +0200
Romain Izard  wrote:

> It is not normal for the PMECC to fail when trying to fix ECC errors.
> Report these cases as errors.

I'm not sure we want to have ECC error messages at this level. ECC
errors are rather unusual but not impossible, and sometimes it's even
not a real error (I'm thinking of bitflips in erased pages for
example, which are not necessarily detected/fixed in hardware).

If we decide to print error messages when unfixable bitflips are
detected, it should be done in the nand-controller driver (somewhere
along those lines [1]).

Regards,

Boris

[1]http://elixir.free-electrons.com/linux/latest/source/drivers/mtd/nand/atmel/nand-controller.c#L827

> 
> Signed-off-by: Romain Izard 
> ---
>  drivers/mtd/nand/atmel/pmecc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
> index 8d1208f38025..2a23f1ff945f 100644
> --- a/drivers/mtd/nand/atmel/pmecc.c
> +++ b/drivers/mtd/nand/atmel/pmecc.c
> @@ -687,6 +687,8 @@ static int atmel_pmecc_err_location(struct 
> atmel_pmecc_user *user)
>* Number of roots does not match the degree of smu
>* unable to correct error.
>*/
> + dev_err(pmecc->dev,
> + "PMECC: Impossible to calculate error location.\n");
>   return -EBADMSG;
>  }
>  
> @@ -729,7 +731,7 @@ int atmel_pmecc_correct_sector(struct atmel_pmecc_user 
> *user, int sector,
>   ptr = ecc + byte - sectorsize;
>   area = "ECC";
>   } else {
> - dev_dbg(pmecc->dev,
> + dev_err(pmecc->dev,
>   "Invalid errpos value (%d, max is %d)\n",
>   errpos, (sectorsize + eccbytes) * 8);
>   return -EINVAL;

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 4/9] mtd: nand: atmel: Avoid ECC errors when leaving backup mode

2017-09-18 Thread Boris Brezillon
Hi Romain,

On Fri, 15 Sep 2017 16:04:06 +0200
Romain Izard  wrote:

> During backup mode, the contents of all registers will be cleared as the
> SoC will be completely powered down. For a product that boots on NAND
> Flash memory, the bootloader will obviously use the related controller
> to read the Flash and correct any detected error in the memory, before
> handling back control to the kernel's resuming entry point.
> 
> In normal devices, it is up to the driver's suspend/resume code to
> restore the registers in a valid state. But the PMECC is not a regular
> device in the driver model when used with the legacy device tree binding
> for the Atmel NAND controller, and suspend/resume code is not called.
> 
> As in my case the bootloader leaves the PMECC controller in a programmed
> state, and the controller is only reset at boot or after a NAND access,
> the first NAND Flash access with the Atmel controller will report
> uncorrectable ECC errors.
> 
> To avoid this, systematically reset the PMECC controller before using
> it.
> 
> Signed-off-by: Romain Izard 
> ---
>  drivers/mtd/nand/atmel/pmecc.c | 11 +++
>  1 file changed, 3 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/mtd/nand/atmel/pmecc.c b/drivers/mtd/nand/atmel/pmecc.c
> index 8c210a5776bc..8d1208f38025 100644
> --- a/drivers/mtd/nand/atmel/pmecc.c
> +++ b/drivers/mtd/nand/atmel/pmecc.c
> @@ -777,6 +777,9 @@ int atmel_pmecc_enable(struct atmel_pmecc_user *user, int 
> op)
>  
>   mutex_lock(&user->pmecc->lock);
>  
> + writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> + writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
> +
>   cfg = user->cache.cfg;
>   if (op == NAND_ECC_WRITE)
>   cfg |= PMECC_CFG_WRITE_OP;
> @@ -797,10 +800,6 @@ EXPORT_SYMBOL_GPL(atmel_pmecc_enable);
>  
>  void atmel_pmecc_disable(struct atmel_pmecc_user *user)
>  {
> - struct atmel_pmecc *pmecc = user->pmecc;
> -
> - writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> - writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);

So know you leave the ECC engine enabled even when it's not in use? Not
sure what kind of implication this has on power-consumption, but I
think I'd prefer to keep the write RST+DISABLE sequence in the disable
path.

How about creating a atmel_pmecc_reset() function that you'd call from
the nand-controller resume hook. Something like:

void atmel_pmecc_reset(struct atmel_pmecc *pmecc)
{
writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
}

This way you can re-use the same function and call it from the probe
and disable path as well.

Regards,

Boris

>   mutex_unlock(&user->pmecc->lock);
>  }
>  EXPORT_SYMBOL_GPL(atmel_pmecc_disable);
> @@ -856,10 +855,6 @@ static struct atmel_pmecc *atmel_pmecc_create(struct 
> platform_device *pdev,
>   /* Disable all interrupts before registering the PMECC handler. */
>   writel(0x, pmecc->regs.base + ATMEL_PMECC_IDR);
>  
> - /* Reset the ECC engine */
> - writel(PMECC_CTRL_RST, pmecc->regs.base + ATMEL_PMECC_CTRL);
> - writel(PMECC_CTRL_DISABLE, pmecc->regs.base + ATMEL_PMECC_CTRL);
> -
>   return pmecc;
>  }
>  

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/15] mtd: make device_type const

2017-08-21 Thread Boris Brezillon
Le Sat, 19 Aug 2017 13:52:17 +0530,
Bhumika Goyal  a écrit :

> Make this const as it is only stored in the type field of a device
> structure, which is const.
> Done using Coccinelle.
> 

Applied to l2-mtd/master.

Thanks,

Boris

> Signed-off-by: Bhumika Goyal 
> ---
>  drivers/mtd/mtdcore.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index f872a99..e7ea842 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -340,7 +340,7 @@ static ssize_t mtd_bbtblocks_show(struct device *dev,
>  };
>  ATTRIBUTE_GROUPS(mtd);
>  
> -static struct device_type mtd_devtype = {
> +static const struct device_type mtd_devtype = {
>   .name   = "mtd",
>   .groups = mtd_groups,
>   .release= mtd_release,

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: gadget: udc: atmel: Fix check in usba_ep_enable()

2016-12-07 Thread Boris Brezillon
On Tue,  6 Dec 2016 22:59:43 +0100
Boris Brezillon  wrote:

> desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK is not necessarily
> equal to ep->index and that's perfectly fine. The usba endpoint index is
> just an internal identifier used by the driver to know which registers
> to use for a USB endpoint.
> 
> Enforcing this constraint is not only useless, but can also lead to
> errors since nothing guarantees that the endpoint number and index are
> matching when an endpoint is selected for a specific descriptor, thus
> leading to errors at ->enable() time when it's already too late to choose
> another endpoint.

Please ignore this patch. The real bug has been fixed in commit
bbe097f092b0 ("usb: gadget: udc: atmel: fix endpoint name").

> 
> Signed-off-by: Boris Brezillon 
> ---
> Hi,
> 
> I intentionally didn't add the Cc stable and Fixes tags because this
> bug dates back to the drivers creation, and I fear the index <->
> epnum constraint was actually required at that time.
> 
> Note that I discovered this bug thanks to the WARN_ON_ONCE() in
> usb_ep_queue() [1] which was introduced in 4.5.
> It might appear that this problem was silently ignored before that
> (with part of the usba_ep_enable() code being skipped without any
> notice).
> 
> Regards,
> 
> Boris
> 
> [1]http://lxr.free-electrons.com/source/drivers/usb/gadget/udc/core.c#L264
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 7 ++-
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index bb1f6c8f0f01..981d2639d413 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -531,11 +531,8 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
> usb_endpoint_descriptor *desc)
>  
>   maxpacket = usb_endpoint_maxp(desc) & 0x7ff;
>  
> - if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index)
> - || ep->index == 0
> - || desc->bDescriptorType != USB_DT_ENDPOINT
> - || maxpacket == 0
> - || maxpacket > ep->fifo_size) {
> + if (ep->index == 0 || desc->bDescriptorType != USB_DT_ENDPOINT ||
> + maxpacket == 0 || maxpacket > ep->fifo_size) {
>   DBG(DBG_ERR, "ep_enable: Invalid argument");
>   return -EINVAL;
>   }

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: gadget: udc: atmel: Fix check in usba_ep_enable()

2016-12-06 Thread Boris Brezillon
Hi Felipe,

I realize I sent this patch to your old @ti.com email address. Do you
want me to resend it?

Regards,

Boris

On Tue,  6 Dec 2016 22:59:43 +0100
Boris Brezillon  wrote:

> desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK is not necessarily
> equal to ep->index and that's perfectly fine. The usba endpoint index is
> just an internal identifier used by the driver to know which registers
> to use for a USB endpoint.
> 
> Enforcing this constraint is not only useless, but can also lead to
> errors since nothing guarantees that the endpoint number and index are
> matching when an endpoint is selected for a specific descriptor, thus
> leading to errors at ->enable() time when it's already too late to choose
> another endpoint.
> 
> Signed-off-by: Boris Brezillon 
> ---
> Hi,
> 
> I intentionally didn't add the Cc stable and Fixes tags because this
> bug dates back to the drivers creation, and I fear the index <->
> epnum constraint was actually required at that time.
> 
> Note that I discovered this bug thanks to the WARN_ON_ONCE() in
> usb_ep_queue() [1] which was introduced in 4.5.
> It might appear that this problem was silently ignored before that
> (with part of the usba_ep_enable() code being skipped without any
> notice).
> 
> Regards,
> 
> Boris
> 
> [1]http://lxr.free-electrons.com/source/drivers/usb/gadget/udc/core.c#L264
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 7 ++-
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index bb1f6c8f0f01..981d2639d413 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -531,11 +531,8 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
> usb_endpoint_descriptor *desc)
>  
>   maxpacket = usb_endpoint_maxp(desc) & 0x7ff;
>  
> - if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index)
> - || ep->index == 0
> - || desc->bDescriptorType != USB_DT_ENDPOINT
> - || maxpacket == 0
> - || maxpacket > ep->fifo_size) {
> + if (ep->index == 0 || desc->bDescriptorType != USB_DT_ENDPOINT ||
> + maxpacket == 0 || maxpacket > ep->fifo_size) {
>   DBG(DBG_ERR, "ep_enable: Invalid argument");
>   return -EINVAL;
>   }

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: gadget: udc: atmel: Fix check in usba_ep_enable()

2016-12-06 Thread Boris Brezillon
desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK is not necessarily
equal to ep->index and that's perfectly fine. The usba endpoint index is
just an internal identifier used by the driver to know which registers
to use for a USB endpoint.

Enforcing this constraint is not only useless, but can also lead to
errors since nothing guarantees that the endpoint number and index are
matching when an endpoint is selected for a specific descriptor, thus
leading to errors at ->enable() time when it's already too late to choose
another endpoint.

Signed-off-by: Boris Brezillon 
---
Hi,

I intentionally didn't add the Cc stable and Fixes tags because this
bug dates back to the drivers creation, and I fear the index <->
epnum constraint was actually required at that time.

Note that I discovered this bug thanks to the WARN_ON_ONCE() in
usb_ep_queue() [1] which was introduced in 4.5.
It might appear that this problem was silently ignored before that
(with part of the usba_ep_enable() code being skipped without any
notice).

Regards,

Boris

[1]http://lxr.free-electrons.com/source/drivers/usb/gadget/udc/core.c#L264
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index bb1f6c8f0f01..981d2639d413 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -531,11 +531,8 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
 
maxpacket = usb_endpoint_maxp(desc) & 0x7ff;
 
-   if (((desc->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK) != ep->index)
-   || ep->index == 0
-   || desc->bDescriptorType != USB_DT_ENDPOINT
-   || maxpacket == 0
-   || maxpacket > ep->fifo_size) {
+   if (ep->index == 0 || desc->bDescriptorType != USB_DT_ENDPOINT ||
+   maxpacket == 0 || maxpacket > ep->fifo_size) {
DBG(DBG_ERR, "ep_enable: Invalid argument");
return -EINVAL;
}
-- 
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: gadget: atmel_usba_udc: Expose correct device speed

2015-11-16 Thread Boris Brezillon
From: Douglas Gilbert 

Following changes that appeared in lk 4.0.0, the gadget udc driver for
some ARM based Atmel SoCs (e.g. at91sam9x5 and sama5d3 families)
incorrectly deduced full-speed USB link speed even when the hardware
had negotiated a high-speed link. The fix is to make sure that the
UDPHS Interrupt Enable Register value does not mask the SPEED bit
in the Interrupt Status Register.

For a mass storage gadget this problem lead to failures when the host
had a USB 3 port with the xhci_hcd driver. If the host was a USB 2
port using the ehci_hcd driver then the mass storage gadget worked
(but probably at a lower speed than it should have).

Signed-of-by: Douglas Gilbert 
Reviewed-by: Boris Brezillon 
Cc:  #4.0+
Fixes: 9870d895ad87 ("usb: atmel_usba_udc: Mask status with enabled irqs")
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index f0f2b06..f92f5af 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1633,7 +1633,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
spin_lock(&udc->lock);
 
int_enb = usba_int_enb_get(udc);
-   status = usba_readl(udc, INT_STA) & int_enb;
+   status = usba_readl(udc, INT_STA) & (int_enb | USBA_HIGH_SPEED);
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: at91sam9x5: USB mass storage gadget problems

2015-11-16 Thread Boris Brezillon
Hi Felipe,

On Mon, 16 Nov 2015 11:17:56 -0600
Felipe Balbi  wrote:

> 
> Hi,
> 
> Boris Brezillon  writes:
> > Hi Douglas,
> >
> > On Sat, 14 Nov 2015 14:15:30 -0500
> > Douglas Gilbert  wrote:
> >
> >> On 15-11-12 05:18 PM, Alan Stern wrote:
> >> > On Thu, 12 Nov 2015, Douglas Gilbert wrote:
> >> >
> >> >> Yes, the X201 has USB 2.0 host ports. It is running a stock Ubuntu
> >> >> 15.10 kernel: 4.2.0-18-generic and the log indicates that the
> >> >> ehci_pci driver is being used. Part of the X201's syslog is
> >> >> attached in which a driver complains about the invalid maxpacket
> >> >> values of 64.
> >> >>
> >> >> So its seems that the ehci drivers as used on the X201 can work
> >> >> around the invalid maxpacket value (64) while the xhci drivers
> >> >> used by the X240 (due to the USB 3.0 host ports) get tripped up.
> >> >
> >> > Yes, I think that's right.  The restriction that high speed bulk
> >> > endpoints must have a maxpacket size of 512 is enforced by the xHCI
> >> > hardware but not by the EHCI hardware; this explains why ehci-hcd is
> >> > able to work around such violations while xhci-hcd isn't.
> >> >
> >> >> Still looking at drivers/usb/gadget/udc/atmel_usba_udc.c which
> >> >> has lots of changes between lk 3.19.0-rc4 and 4.0.0-rc4 . The
> >> >> maxpacket value seems (to me) to be related to the fifo-size
> >> >> in the gadget section of this dts include file:
> >> >> arch/arm/boot/dts/at91sam9x5.dtsi
> >> >> which has 1024 for ep1 through ep5 and 64 for ep0.
> >> >
> >> > The assignment of endpoints isn't done in the UDC driver; it is carried
> >> > out by epautoconf.c in drivers/usb/gadget/.  So you may need to expand
> >> > your bisection search beyond the single UDC driver source file.
> >> >
> >> > Have you tried enabling debugging in the gadget drivers and checking
> >> > out the kernel log on the gadget?
> >> >
> >> >> So it looks like 1.5 bugs:
> >> >> - one in atmel's udc driver for the at91sam9x5 family, and
> >> >> - the inconsistency between the ehci driver working around
> >> >>   invalid maxpacket values and the xhci driver behaving
> >> >>   badly (lots of bus resets and a badly made SCSI storage
> >> >>   device [e.g. INQUIRY works but READ(10) fails]).
> >> >
> >> > The first is clearly a bug, although at the moment we can't be sure
> >> > where.  The second is an unavoidable hardware restriction, not a bug.
> >> > Anyway, if you fix the first problem then the second won't be an issue.
> >> 
> >> Found the udc driver bug. A shadow register value was introduced
> >> around lk 4.0 for the Atmel 9x5/sama5d3 UDPHS driver
> >> (atmel_usba_udc.c) for the interrupt status register. It used the
> >> interrupt enable register (last written) value as a mask. At least
> >> for the at91sam9g25 that works apart from the SPEED bit (bit 0)
> >> which is only present in the interrupt status register.
> >> 
> >> It seems that USB negotiates the link speed during resets and at
> >> the G25 end, even though the hardware had negotiated a "high
> >> speed" link with the host, the logic in usba_udc_irq() deduced it
> >> was only a full speed link (due to the above bug). Thereafter
> >> there was confusion which the ehci_hcd host driver could handle
> >> but the xhci_pci driver could not. In the xhci_pci case there
> >> were multiple high speed link resets in the host log, matched
> >> at the device (G25) end with a similar number of reported _full_
> >> speed resets.
> >> 
> >> The author of the changes to the code that caused this is
> >> cc-ed on this post. He might like to consider the attached
> >> patch which fixed my problem. However the shadow mask register
> >> technique might have other subtle issues that I'm not
> >> qualified to address.
> >
> > Looks good to me, and sorry for the inconvenience.
> >
> >> 
> >> If I don't hear anything on this issue then I can produce
> >> a patch. Does it go through the ARM or USB (or both) trees?
> >
> > You can go ahead and send a patch to the ARM and USB MLs (+
> > appropriate maintainers), unless you want me to do it.
> >
> >> 
> >> If my patch is sufficient, then perhaps it should also be
> >> issued against the lk 4.0, 4.1, 4.2 and 4.3 kernels that are
> >> still actively maintained.
> >
> > Yep, adding the following line after your SoB should do the trick:
> >
> > Cc:  #4.0+
> 
> please send this out as a real patch, otherwise I can't apply.
> 

I'll take care of that.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: at91sam9x5: USB mass storage gadget problems

2015-11-14 Thread Boris Brezillon
Hi Douglas,

On Sat, 14 Nov 2015 14:15:30 -0500
Douglas Gilbert  wrote:

> On 15-11-12 05:18 PM, Alan Stern wrote:
> > On Thu, 12 Nov 2015, Douglas Gilbert wrote:
> >
> >> Yes, the X201 has USB 2.0 host ports. It is running a stock Ubuntu
> >> 15.10 kernel: 4.2.0-18-generic and the log indicates that the
> >> ehci_pci driver is being used. Part of the X201's syslog is
> >> attached in which a driver complains about the invalid maxpacket
> >> values of 64.
> >>
> >> So its seems that the ehci drivers as used on the X201 can work
> >> around the invalid maxpacket value (64) while the xhci drivers
> >> used by the X240 (due to the USB 3.0 host ports) get tripped up.
> >
> > Yes, I think that's right.  The restriction that high speed bulk
> > endpoints must have a maxpacket size of 512 is enforced by the xHCI
> > hardware but not by the EHCI hardware; this explains why ehci-hcd is
> > able to work around such violations while xhci-hcd isn't.
> >
> >> Still looking at drivers/usb/gadget/udc/atmel_usba_udc.c which
> >> has lots of changes between lk 3.19.0-rc4 and 4.0.0-rc4 . The
> >> maxpacket value seems (to me) to be related to the fifo-size
> >> in the gadget section of this dts include file:
> >> arch/arm/boot/dts/at91sam9x5.dtsi
> >> which has 1024 for ep1 through ep5 and 64 for ep0.
> >
> > The assignment of endpoints isn't done in the UDC driver; it is carried
> > out by epautoconf.c in drivers/usb/gadget/.  So you may need to expand
> > your bisection search beyond the single UDC driver source file.
> >
> > Have you tried enabling debugging in the gadget drivers and checking
> > out the kernel log on the gadget?
> >
> >> So it looks like 1.5 bugs:
> >> - one in atmel's udc driver for the at91sam9x5 family, and
> >> - the inconsistency between the ehci driver working around
> >>   invalid maxpacket values and the xhci driver behaving
> >>   badly (lots of bus resets and a badly made SCSI storage
> >>   device [e.g. INQUIRY works but READ(10) fails]).
> >
> > The first is clearly a bug, although at the moment we can't be sure
> > where.  The second is an unavoidable hardware restriction, not a bug.
> > Anyway, if you fix the first problem then the second won't be an issue.
> 
> Found the udc driver bug. A shadow register value was introduced
> around lk 4.0 for the Atmel 9x5/sama5d3 UDPHS driver
> (atmel_usba_udc.c) for the interrupt status register. It used the
> interrupt enable register (last written) value as a mask. At least
> for the at91sam9g25 that works apart from the SPEED bit (bit 0)
> which is only present in the interrupt status register.
> 
> It seems that USB negotiates the link speed during resets and at
> the G25 end, even though the hardware had negotiated a "high
> speed" link with the host, the logic in usba_udc_irq() deduced it
> was only a full speed link (due to the above bug). Thereafter
> there was confusion which the ehci_hcd host driver could handle
> but the xhci_pci driver could not. In the xhci_pci case there
> were multiple high speed link resets in the host log, matched
> at the device (G25) end with a similar number of reported _full_
> speed resets.
> 
> The author of the changes to the code that caused this is
> cc-ed on this post. He might like to consider the attached
> patch which fixed my problem. However the shadow mask register
> technique might have other subtle issues that I'm not
> qualified to address.

Looks good to me, and sorry for the inconvenience.

> 
> If I don't hear anything on this issue then I can produce
> a patch. Does it go through the ARM or USB (or both) trees?

You can go ahead and send a patch to the ARM and USB MLs (+
appropriate maintainers), unless you want me to do it.

> 
> If my patch is sufficient, then perhaps it should also be
> issued against the lk 4.0, 4.1, 4.2 and 4.3 kernels that are
> still actively maintained.

Yep, adding the following line after your SoB should do the trick:

Cc:  #4.0+

Thanks,

Boris



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [BUG] usb/at91: usb hub does not work

2015-06-16 Thread Boris Brezillon
Hi Jiri,

On Tue, 16 Jun 2015 10:51:55 +0200
Jiří Prchal  wrote:

> 
> 
> On 13.6.2015 13:13, Boris Brezillon wrote:
> > On Sat, 13 Jun 2015 13:09:56 +0200
> > Boris Brezillon  wrote:
> >
> >> Hi Jiri,
> >>
> >> On Fri, 12 Jun 2015 11:30:20 +0200
> >> Jiří Prchal  wrote:
> >>
> >>>
> >>>
> >>> On 11.6.2015 15:53, Alan Stern wrote:
> >>>> On Thu, 11 Jun 2015, Jiří Prchal wrote:
> >>>>
> >>>>> Hi all,
> >>>>> I discovered some bug when I change kernel from 3.18.13 to 3.18.14. I 
> >>>>> have board with usb hub CY7C65632 on it.
> >>>>> In .13 it works fine but in .14 it repeats this message:
> >>>>> [   19.17] usb 2-3: new full-speed USB device number 56 using 
> >>>>> at91_ohci
> >>>>> and devices connected to usb through hub doesn't appear at all.
> >>>>
> >>>>> Any idea?
> >>>>
> >>>> Try using git bisect to find the commit which caused this problem to
> >>>> start.
> >>>
> >>> This is result:
> >>> Bisecting: 0 revisions left to test after this (roughly 0 steps)
> >>> [ae74ea64ccdb8b99ee2618b58020263d5b1d9b22] clk: at91: usb: propagate rate 
> >>> modification to the parent clk
> >>
> >>
> >> Actually when bisecting you found a bug that has been fixed before
> >> 3.18.14 was released (see this commit [1]).
> >> This being said, the prototype mismatch fix does not seem to fix all
> >> the mismatches (seems the ->determine_rate() has been changed in 3.19
> >> too, and the prototype mismatch patch was a backport of a 3.19 fix).
> >>
> >> Anyway, you'll find below a patch supposed to fix the remaining bug.
> >
> > I forgot to disable the line wrapper in my email client, here is the
> > same patch without the wrapped lines:
> 
> Aplied to 3.18.14 and it helped!


Thanks for testing, I'll send this patch to Sacha and the stable ML.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [BUG] usb/at91: usb hub does not work

2015-06-13 Thread Boris Brezillon
On Sat, 13 Jun 2015 13:09:56 +0200
Boris Brezillon  wrote:

> Hi Jiri,
> 
> On Fri, 12 Jun 2015 11:30:20 +0200
> Jiří Prchal  wrote:
> 
> > 
> > 
> > On 11.6.2015 15:53, Alan Stern wrote:
> > > On Thu, 11 Jun 2015, Jiří Prchal wrote:
> > >
> > >> Hi all,
> > >> I discovered some bug when I change kernel from 3.18.13 to 3.18.14. I 
> > >> have board with usb hub CY7C65632 on it.
> > >> In .13 it works fine but in .14 it repeats this message:
> > >> [   19.17] usb 2-3: new full-speed USB device number 56 using 
> > >> at91_ohci
> > >> and devices connected to usb through hub doesn't appear at all.
> > >
> > >> Any idea?
> > >
> > > Try using git bisect to find the commit which caused this problem to
> > > start.
> > 
> > This is result:
> > Bisecting: 0 revisions left to test after this (roughly 0 steps)
> > [ae74ea64ccdb8b99ee2618b58020263d5b1d9b22] clk: at91: usb: propagate rate 
> > modification to the parent clk
> 
> 
> Actually when bisecting you found a bug that has been fixed before
> 3.18.14 was released (see this commit [1]).
> This being said, the prototype mismatch fix does not seem to fix all
> the mismatches (seems the ->determine_rate() has been changed in 3.19
> too, and the prototype mismatch patch was a backport of a 3.19 fix).
> 
> Anyway, you'll find below a patch supposed to fix the remaining bug.

I forgot to disable the line wrapper in my email client, here is the
same patch without the wrapped lines:

-- >8 --

>From 7392429d074f43ef61d41e33db63f0f5d804bdd4 Mon Sep 17 00:00:00 2001
Subject: [PATCH] clk: at91: fix determine_rate prototype (again)

Commit ae74ea64ccdb8b99ee2618b58020263d5b1d9b22 was a backport of a bug
fix applied in 4.0, but in the meantime the ->determine_rate() prototype
has changed, thus introduction a prototype mismatch bug in pre-4.0
kernels. This prototype mismatch was supposed to be fixed by commit
76723e7ed589998384a080e29204df4659c67cf2, which fix the bug on 3.19 kernels,
but the ->determine_rate() has also changed between 3.18 and 3.19.
Hopefully this patch will definitely fix the prototype mismatch for 3.18.

Signed-off-by: Boris Brezillon 
---
 drivers/clk/at91/clk-usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 0283a57..d0d335d 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -59,7 +59,7 @@ static unsigned long at91sam9x5_clk_usb_recalc_rate(struct 
clk_hw *hw,
 static long at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw,
  unsigned long rate,
  unsigned long *best_parent_rate,
- struct clk_hw **best_parent_hw)
+ struct clk **best_parent_clk)
 {
struct clk *parent = NULL;
long best_rate = -EINVAL;
@@ -91,7 +91,7 @@ static long at91sam9x5_clk_usb_determine_rate(struct clk_hw 
*hw,
best_rate = tmp_rate;
best_diff = tmp_diff;
*best_parent_rate = tmp_parent_rate;
-   *best_parent_hw = __clk_get_hw(parent);
+   *best_parent_clk = parent;
}
 
if (!best_diff || tmp_rate < rate)
-- 
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [BUG] usb/at91: usb hub does not work

2015-06-13 Thread Boris Brezillon
Hi Jiri,

On Fri, 12 Jun 2015 11:30:20 +0200
Jiří Prchal  wrote:

> 
> 
> On 11.6.2015 15:53, Alan Stern wrote:
> > On Thu, 11 Jun 2015, Jiří Prchal wrote:
> >
> >> Hi all,
> >> I discovered some bug when I change kernel from 3.18.13 to 3.18.14. I have 
> >> board with usb hub CY7C65632 on it.
> >> In .13 it works fine but in .14 it repeats this message:
> >> [   19.17] usb 2-3: new full-speed USB device number 56 using at91_ohci
> >> and devices connected to usb through hub doesn't appear at all.
> >
> >> Any idea?
> >
> > Try using git bisect to find the commit which caused this problem to
> > start.
> 
> This is result:
> Bisecting: 0 revisions left to test after this (roughly 0 steps)
> [ae74ea64ccdb8b99ee2618b58020263d5b1d9b22] clk: at91: usb: propagate rate 
> modification to the parent clk


Actually when bisecting you found a bug that has been fixed before
3.18.14 was released (see this commit [1]).
This being said, the prototype mismatch fix does not seem to fix all
the mismatches (seems the ->determine_rate() has been changed in 3.19
too, and the prototype mismatch patch was a backport of a 3.19 fix).

Anyway, you'll find below a patch supposed to fix the remaining bug.
Can you try to apply it and let me know if it fixes your problem.

Best Regards,

Boris

[1]https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/commit/drivers/clk/at91/clk-usb.c?id=76723e7ed589998384a080e29204df4659c67cf2

-- >8 --

>From 7392429d074f43ef61d41e33db63f0f5d804bdd4 Mon Sep 17 00:00:00 2001
Subject: [PATCH] clk: at91: fix determine_rate prototype (again)

Commit ae74ea64ccdb8b99ee2618b58020263d5b1d9b22 was a backport of a bug
fix applied in 4.0, but in the meantime the ->determine_rate() prototype
has changed, thus introduction a prototype mismatch bug in pre-4.0
kernels. This prototype mismatch was supposed to be fixed by commit
76723e7ed589998384a080e29204df4659c67cf2, which fix the bug on 3.19
kernels, but the ->determine_rate() has also changed between 3.18 and
3.19. Hopefully this patch will definitely fix the prototype mismatch
for 3.18.

Signed-off-by: Boris Brezillon 
---
 drivers/clk/at91/clk-usb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/at91/clk-usb.c b/drivers/clk/at91/clk-usb.c
index 0283a57..d0d335d 100644
--- a/drivers/clk/at91/clk-usb.c
+++ b/drivers/clk/at91/clk-usb.c
@@ -59,7 +59,7 @@ static unsigned long
at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw, static long
at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw, unsigned long rate,
  unsigned long
*best_parent_rate,
- struct clk_hw
**best_parent_hw)
+ struct clk
**best_parent_clk) {
struct clk *parent = NULL;
long best_rate = -EINVAL;
@@ -91,7 +91,7 @@ static long at91sam9x5_clk_usb_determine_rate(struct
clk_hw *hw, best_rate = tmp_rate;
best_diff = tmp_diff;
*best_parent_rate = tmp_parent_rate;
-   *best_parent_hw = __clk_get_hw(parent);
+   *best_parent_clk = parent;
}
 
if (!best_diff || tmp_rate < rate)
-- 
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/5] USB: host: ohci-at91: remove useless uclk clock

2015-03-17 Thread Boris Brezillon
Now that the system clock driver is forwarding set_rate request to the
parent clock, we can safely call clk_set_rate on the system clk and get
rid of the uclk field.

Signed-off-by: Boris Brezillon 
---
 drivers/usb/host/ohci-at91.c | 18 +++---
 1 file changed, 3 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 7cce85a..15df00c 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -39,7 +39,6 @@
 struct ohci_at91_priv {
struct clk *iclk;
struct clk *fclk;
-   struct clk *uclk;
struct clk *hclk;
bool clocked;
bool wakeup;/* Saved wake-up state for resume */
@@ -64,10 +63,8 @@ static void at91_start_clock(struct ohci_at91_priv 
*ohci_at91)
 {
if (ohci_at91->clocked)
return;
-   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   clk_set_rate(ohci_at91->uclk, 4800);
-   clk_prepare_enable(ohci_at91->uclk);
-   }
+
+   clk_set_rate(ohci_at91->fclk, 4800);
clk_prepare_enable(ohci_at91->hclk);
clk_prepare_enable(ohci_at91->iclk);
clk_prepare_enable(ohci_at91->fclk);
@@ -78,11 +75,10 @@ static void at91_stop_clock(struct ohci_at91_priv 
*ohci_at91)
 {
if (!ohci_at91->clocked)
return;
+
clk_disable_unprepare(ohci_at91->fclk);
clk_disable_unprepare(ohci_at91->iclk);
clk_disable_unprepare(ohci_at91->hclk);
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_disable_unprepare(ohci_at91->uclk);
ohci_at91->clocked = false;
 }
 
@@ -191,14 +187,6 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
retval = PTR_ERR(ohci_at91->hclk);
goto err;
}
-   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   ohci_at91->uclk = devm_clk_get(dev, "usb_clk");
-   if (IS_ERR(ohci_at91->uclk)) {
-   dev_err(dev, "failed to get uclk\n");
-   retval = PTR_ERR(ohci_at91->uclk);
-   goto err;
-   }
-   }
 
board = hcd->self.controller->platform_data;
ohci = hcd_to_ohci(hcd);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/5] USB: atmel: rework clock handling

2015-03-17 Thread Boris Brezillon
Hello,

This series reworks clock handling in atmel USB host drivers, and while
doing so fixes a regression introduced by 3440ef1 (ARM: at91/dt: fix USB
high-speed clock to select UTMI).

Best Regards,

Boris

Boris Brezillon (5):
  USB: ehci-atmel: rework clk handling
  USB: host: ohci-at91: remove useless uclk clock
  USB: atmel: update DT bindings documentation
  ARM: at91/dt: remove useless uhpck clock references from ehci
defintions
  ARM: at91/dt: remove useless usb clock

 .../devicetree/bindings/usb/atmel-usb.txt  | 25 ++
 arch/arm/boot/dts/at91rm9200.dtsi  |  4 +--
 arch/arm/boot/dts/at91sam9260.dtsi |  4 +--
 arch/arm/boot/dts/at91sam9261.dtsi |  4 +--
 arch/arm/boot/dts/at91sam9263.dtsi |  4 +--
 arch/arm/boot/dts/at91sam9g45.dtsi |  8 +++---
 arch/arm/boot/dts/at91sam9n12.dtsi |  5 ++--
 arch/arm/boot/dts/at91sam9x5.dtsi  |  8 +++---
 arch/arm/boot/dts/sama5d3.dtsi |  9 +++
 arch/arm/boot/dts/sama5d4.dtsi |  9 +++
 drivers/usb/host/ehci-atmel.c  | 30 +++---
 drivers/usb/host/ohci-at91.c   | 18 +++--
 12 files changed, 63 insertions(+), 65 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/5] USB: ehci-atmel: rework clk handling

2015-03-17 Thread Boris Brezillon
The EHCI IP only needs the UTMI/UPLL (uclk) and the peripheral (iclk)
clocks to work properly. Remove the useless system clock (fclk).

Avoid calling set_rate on the fixed rate UTMI/IPLL clock and remove
useless IS_ENABLED(CONFIG_COMMON_CLK) tests (all at91 platforms have been
moved to the CCF).

This patch also fixes a bug introduced by 3440ef1 (ARM: at91/dt: fix USB
high-speed clock to select UTMI), which was leaving the usb clock
uninitialized and preventing the OHCI driver from setting the usb clock
rate to 48MHz.
This bug was caused by several things:
1/ usb clock drivers set the CLK_SET_RATE_GATE flag, which means the rate
   cannot be changed once the clock is prepared
2/ The EHCI driver was retrieving and preparing/enabling the uhpck
   clock which was in turn preparing its parent clock (the usb clock),
   thus preventing any rate change because of 1/

Signed-off-by: Boris Brezillon 
---
 drivers/usb/host/ehci-atmel.c | 30 +-
 1 file changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
index 663f790..be0964a 100644
--- a/drivers/usb/host/ehci-atmel.c
+++ b/drivers/usb/host/ehci-atmel.c
@@ -34,7 +34,6 @@ static const char hcd_name[] = "ehci-atmel";
 
 struct atmel_ehci_priv {
struct clk *iclk;
-   struct clk *fclk;
struct clk *uclk;
bool clocked;
 };
@@ -51,12 +50,9 @@ static void atmel_start_clock(struct atmel_ehci_priv 
*atmel_ehci)
 {
if (atmel_ehci->clocked)
return;
-   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   clk_set_rate(atmel_ehci->uclk, 4800);
-   clk_prepare_enable(atmel_ehci->uclk);
-   }
+
+   clk_prepare_enable(atmel_ehci->uclk);
clk_prepare_enable(atmel_ehci->iclk);
-   clk_prepare_enable(atmel_ehci->fclk);
atmel_ehci->clocked = true;
 }
 
@@ -64,10 +60,9 @@ static void atmel_stop_clock(struct atmel_ehci_priv 
*atmel_ehci)
 {
if (!atmel_ehci->clocked)
return;
-   clk_disable_unprepare(atmel_ehci->fclk);
+
clk_disable_unprepare(atmel_ehci->iclk);
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_disable_unprepare(atmel_ehci->uclk);
+   clk_disable_unprepare(atmel_ehci->uclk);
atmel_ehci->clocked = false;
 }
 
@@ -146,20 +141,13 @@ static int ehci_atmel_drv_probe(struct platform_device 
*pdev)
retval = -ENOENT;
goto fail_request_resource;
}
-   atmel_ehci->fclk = devm_clk_get(&pdev->dev, "uhpck");
-   if (IS_ERR(atmel_ehci->fclk)) {
-   dev_err(&pdev->dev, "Error getting function clock\n");
-   retval = -ENOENT;
+
+   atmel_ehci->uclk = devm_clk_get(&pdev->dev, "usb_clk");
+   if (IS_ERR(atmel_ehci->uclk)) {
+   dev_err(&pdev->dev, "failed to get uclk\n");
+   retval = PTR_ERR(atmel_ehci->uclk);
goto fail_request_resource;
}
-   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   atmel_ehci->uclk = devm_clk_get(&pdev->dev, "usb_clk");
-   if (IS_ERR(atmel_ehci->uclk)) {
-   dev_err(&pdev->dev, "failed to get uclk\n");
-   retval = PTR_ERR(atmel_ehci->uclk);
-   goto fail_request_resource;
-   }
-   }
 
ehci = hcd_to_ehci(hcd);
/* registers start at offset 0x0 */
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/5] USB: atmel: update DT bindings documentation

2015-03-17 Thread Boris Brezillon
Add documentation for the missing clocks, clock-names, reg and interrupts
properties.

Signed-off-by: Boris Brezillon 
---
 .../devicetree/bindings/usb/atmel-usb.txt  | 25 ++
 1 file changed, 25 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index e180d56..1be8d7a 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -5,6 +5,13 @@ OHCI
 Required properties:
  - compatible: Should be "atmel,at91rm9200-ohci" for USB controllers
used in host mode.
+ - reg: Address and length of the register set for the device
+ - interrupts: Should contain ehci interrupt
+ - clocks: Should reference the peripheral, host and system clocks
+ - clock-names: Should contains two strings
+   "ohci_clk" for the peripheral clock
+   "hclk" for the host clock
+   "uhpck" for the system clock
  - num-ports: Number of ports.
  - atmel,vbus-gpio: If present, specifies a gpio that needs to be
activated for the bus to be powered.
@@ -14,6 +21,8 @@ Required properties:
 usb0: ohci@0050 {
compatible = "atmel,at91rm9200-ohci", "usb-ohci";
reg = <0x0050 0x10>;
+   clocks = <&uhphs_clk>, <&uhphs_clk>, <&uhpck>;
+   clock-names = "ohci_clk", "hclk", "uhpck";
interrupts = <20 4>;
num-ports = <2>;
 };
@@ -23,11 +32,19 @@ EHCI
 Required properties:
  - compatible: Should be "atmel,at91sam9g45-ehci" for USB controllers
used in host mode.
+ - reg: Address and length of the register set for the device
+ - interrupts: Should contain ehci interrupt
+ - clocks: Should reference the peripheral and the UTMI clocks
+ - clock-names: Should contains two strings
+   "ehci_clk" for the peripheral clock
+   "usb_clk" for the UTMI clock
 
 usb1: ehci@0080 {
compatible = "atmel,at91sam9g45-ehci", "usb-ehci";
reg = <0x0080 0x10>;
interrupts = <22 4>;
+   clocks = <&utmi>, <&uhphs_clk>;
+   clock-names = "usb_clk", "ehci_clk";
 };
 
 AT91 USB device controller
@@ -53,6 +70,8 @@ usb1: gadget@fffa4000 {
compatible = "atmel,at91rm9200-udc";
reg = <0xfffa4000 0x4000>;
interrupts = <10 4>;
+   clocks = <&udc_clk>, <&udpck>;
+   clock-names = "pclk", "hclk";
atmel,vbus-gpio = <&pioC 5 0>;
 };
 
@@ -65,6 +84,10 @@ Required properties:
   "sama5d3-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain usba interrupt
+ - clocks: Should reference the peripheral and host clocks
+ - clock-names: Should contains two strings
+   "pclk" for the peripheral clock
+   "hclk" for the host clock
  - ep childnode: To specify the number of endpoints and their properties.
 
 Optional properties:
@@ -86,6 +109,8 @@ usb2: gadget@fff78000 {
reg = <0x0060 0x8
   0xfff78000 0x400>;
interrupts = <27 4 0>;
+   clocks = <&utmi>, <&udphs_clk>;
+   clock-names = "hclk", "pclk";
atmel,vbus-gpio = <&pioB 19 0>;
 
ep0 {
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/5] ARM: at91/dt: remove useless uhpck clock references from ehci defintions

2015-03-17 Thread Boris Brezillon
The uhpck is useless for High-Speed communications, remove the reference
to this clock in all ehci definitions.

Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91sam9g45.dtsi | 4 ++--
 arch/arm/boot/dts/at91sam9x5.dtsi  | 4 ++--
 arch/arm/boot/dts/sama5d3.dtsi | 4 ++--
 arch/arm/boot/dts/sama5d4.dtsi | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi 
b/arch/arm/boot/dts/at91sam9g45.dtsi
index 488af63..a5895f3 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -1300,8 +1300,8 @@
compatible = "atmel,at91sam9g45-ehci", "usb-ehci";
reg = <0x0080 0x10>;
interrupts = <22 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&utmi>, <&uhphs_clk>, <&uhphs_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ehci_clk", "hclk", "uhpck";
+   clocks = <&utmi>, <&uhphs_clk>;
+   clock-names = "usb_clk", "ehci_clk";
status = "disabled";
};
};
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi 
b/arch/arm/boot/dts/at91sam9x5.dtsi
index d221179..9a74a90 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -1185,8 +1185,8 @@
compatible = "atmel,at91sam9g45-ehci", "usb-ehci";
reg = <0x0070 0x10>;
interrupts = <22 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&utmi>, <&uhphs_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ehci_clk", "uhpck";
+   clocks = <&utmi>, <&uhphs_clk>;
+   clock-names = "usb_clk", "ehci_clk";
status = "disabled";
};
};
diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
index 367af53..a266a39 100644
--- a/arch/arm/boot/dts/sama5d3.dtsi
+++ b/arch/arm/boot/dts/sama5d3.dtsi
@@ -1415,8 +1415,8 @@
compatible = "atmel,at91sam9g45-ehci", "usb-ehci";
reg = <0x0070 0x10>;
interrupts = <32 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&utmi>, <&uhphs_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ehci_clk", "uhpck";
+   clocks = <&utmi>, <&uhphs_clk>;
+   clock-names = "usb_clk", "ehci_clk";
status = "disabled";
};
 
diff --git a/arch/arm/boot/dts/sama5d4.dtsi b/arch/arm/boot/dts/sama5d4.dtsi
index 4303874..4bfe7c1 100644
--- a/arch/arm/boot/dts/sama5d4.dtsi
+++ b/arch/arm/boot/dts/sama5d4.dtsi
@@ -260,8 +260,8 @@
compatible = "atmel,at91sam9g45-ehci", "usb-ehci";
reg = <0x0060 0x10>;
interrupts = <46 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&utmi>, <&uhphs_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ehci_clk", "uhpck";
+   clocks = <&utmi>, <&uhphs_clk>;
+   clock-names = "usb_clk", "ehci_clk";
status = "disabled";
};
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 5/5] ARM: at91/dt: remove useless usb clock

2015-03-17 Thread Boris Brezillon
The ohci driver now calls clk_set_rate on the uhpck clock (which forwards
set_rate requests to its parent: the usb clock).
Remove useless references to usb clocks from ohci definitions.

Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91rm9200.dtsi  | 4 ++--
 arch/arm/boot/dts/at91sam9260.dtsi | 4 ++--
 arch/arm/boot/dts/at91sam9261.dtsi | 4 ++--
 arch/arm/boot/dts/at91sam9263.dtsi | 4 ++--
 arch/arm/boot/dts/at91sam9g45.dtsi | 4 ++--
 arch/arm/boot/dts/at91sam9n12.dtsi | 5 ++---
 arch/arm/boot/dts/at91sam9x5.dtsi  | 4 ++--
 arch/arm/boot/dts/sama5d3.dtsi | 5 ++---
 arch/arm/boot/dts/sama5d4.dtsi | 5 ++---
 9 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/arch/arm/boot/dts/at91rm9200.dtsi 
b/arch/arm/boot/dts/at91rm9200.dtsi
index 21c2b50..31892a1 100644
--- a/arch/arm/boot/dts/at91rm9200.dtsi
+++ b/arch/arm/boot/dts/at91rm9200.dtsi
@@ -936,8 +936,8 @@
compatible = "atmel,at91rm9200-ohci", "usb-ohci";
reg = <0x0030 0x10>;
interrupts = <23 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&usb>, <&ohci_clk>, <&ohci_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ohci_clk", "hclk", "uhpck";
+   clocks = <&ohci_clk>, <&ohci_clk>, <&uhpck>;
+   clock-names = "ohci_clk", "hclk", "uhpck";
status = "disabled";
};
};
diff --git a/arch/arm/boot/dts/at91sam9260.dtsi 
b/arch/arm/boot/dts/at91sam9260.dtsi
index e7f0a4a..2dabe77 100644
--- a/arch/arm/boot/dts/at91sam9260.dtsi
+++ b/arch/arm/boot/dts/at91sam9260.dtsi
@@ -1008,8 +1008,8 @@
compatible = "atmel,at91rm9200-ohci", "usb-ohci";
reg = <0x0050 0x10>;
interrupts = <20 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&usb>, <&ohci_clk>, <&ohci_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ohci_clk", "hclk", "uhpck";
+   clocks = <&ohci_clk>, <&ohci_clk>, <&uhpck>;
+   clock-names = "ohci_clk", "hclk", "uhpck";
status = "disabled";
};
};
diff --git a/arch/arm/boot/dts/at91sam9261.dtsi 
b/arch/arm/boot/dts/at91sam9261.dtsi
index d55fdf2..db811f9 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -75,8 +75,8 @@
compatible = "atmel,at91rm9200-ohci", "usb-ohci";
reg = <0x0050 0x10>;
interrupts = <20 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&usb>, <&ohci_clk>, <&hclk0>, <&uhpck>;
-   clock-names = "usb_clk", "ohci_clk", "hclk", "uhpck";
+   clocks = <&ohci_clk>, <&hclk0>, <&uhpck>;
+   clock-names = "ohci_clk", "hclk", "uhpck";
status = "disabled";
};
 
diff --git a/arch/arm/boot/dts/at91sam9263.dtsi 
b/arch/arm/boot/dts/at91sam9263.dtsi
index fce301c..aa981cd 100644
--- a/arch/arm/boot/dts/at91sam9263.dtsi
+++ b/arch/arm/boot/dts/at91sam9263.dtsi
@@ -1010,8 +1010,8 @@
compatible = "atmel,at91rm9200-ohci", "usb-ohci";
reg = <0x00a0 0x10>;
interrupts = <29 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&usb>, <&ohci_clk>, <&ohci_clk>, <&uhpck>;
-   clock-names = "usb_clk", "ohci_clk", "hclk", "uhpck";
+   clocks = <&ohci_clk>, <&ohci_clk>, <&uhpck>;
+   clock-names = "ohci_clk", "hclk", "uhpck";
status = "disabled";
};
};
diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi 
b/arch/arm/boot/dts/at91sam9g45.dtsi
index a5895f3..644570e 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -1291,8 +1291,8 @@
compatible = "atmel,at91rm9200-ohci", "usb-ohci";
reg = <0x0070 0x10>;
interrupts = <22 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&usb>, 

Re: [PATCH] udc: gadget: atmel_usba_udc: depend on COMMON_CLK_AT91

2015-03-03 Thread Boris Brezillon
Hi Alexandre,

On Tue,  3 Mar 2015 08:42:47 +0100
Alexandre Belloni  wrote:

> Since the addition of the errata handling for at91sam9rl and at91sam9g45, the
> atmel_usba_udc depends on the pmc driver being present. Explicitly set that
> dependency.
> 
> Signed-off-by: Alexandre Belloni 
> ---
>  drivers/usb/gadget/udc/Kconfig | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
> index 9a3a6b00391a..b04206fdba11 100644
> --- a/drivers/usb/gadget/udc/Kconfig
> +++ b/drivers/usb/gadget/udc/Kconfig
> @@ -55,7 +55,7 @@ config USB_LPC32XX
>  
>  config USB_ATMEL_USBA
>   tristate "Atmel USBA"
> - depends on AVR32 || ARCH_AT91
> + depends on AVR32 || ARCH_AT91 && COMMON_CLK_AT91

I guess you should add parenthesis to make it clearer ?

depends on AVR32 || (ARCH_AT91 && COMMON_CLK_AT91)

And I wonder why you need that. I though this option was selected by all
at91 platforms ?

Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv6 4/5] USB: gadget: atmel_usba_udc: Prepare for IRQ single edge support

2015-02-08 Thread Boris Brezillon
On Sat, 7 Feb 2015 20:37:23 +0100
Sylvain Rochet  wrote:

> Hello Nicolas,
> 
> 
> On Thu, Feb 05, 2015 at 06:19:55PM +0100, Nicolas Ferre wrote:
> > Le 22/01/2015 18:14, Boris Brezillon a écrit :
> > > On Thu, 22 Jan 2015 17:56:44 +0100
> > > Sylvain Rochet  wrote:
> > > 
> > > > -static const struct usba_udc_errata at91sam9g45_errata = {
> > > > +static const struct usba_udc_caps at91sam9g45_caps = {
> > > > .pulse_bias = at91sam9g45_pulse_bias,
> > > > +   .irq_single_edge_support = true,
> > 
> > Nope! at91sam9g45 doesn't have this property. You'll have to create
> > another compatible string and capabilities structure
> > ("atmel,at91sam9x5-udc")
> 
> Oops.
> 
> 
> > But still, I don't know if it's the proper approach. The possibility to
> > trigger an IRQ on both edges or a single edge is a capacity of the gpio
> > controller, not the USBA IP. So, it's a little bit strange to have this
> > capability here.
> 
> I agree.

Me too (even if I'm the one who proposed this approach in the first
place ;-)).

> 
> 
> > I don't know if it's actually feasible but trying to configure the IRQ
> > on a single edge, testing if it's accepted by the GPIO irq controller
> > and if not, falling back to a "both edge" pattern. Doesn't it look like
> > a way to workaround this issue nicely? Can you give it a try?
> 
> Tried, it works, but it displays the following message from 
> __irq_set_trigger() [1] during devm_request_threaded_irq(…, 
> IRQF_TRIGGER_RISING, …) on boards which does not support single-edge 
> IRQ:
> 
> genirq: Setting trigger mode 1 for irq 176 failed (gpio_irq_type+0x0/0x34)
> 
> Is it acceptable ?

IMHO it's not.

> If not, is udc->caps->irq_single_edge_support boolean acceptable ?

Do you mean keeping the current approach ?
If you do, then maybe you can rework a bit the way you detect the GPIO
controller you depends on: instead of linking this information to the
usba compatible string you could link it to the gpio controller
compatible string.

You can find the gpio controller node thanks to your "vbus-gpio"
property: use the phandle defined in this property to find the gpio
controller node, and once you have the device_node referencing the gpio
controller you can match it with your internal device_id table
(containing 2 entries: one for the at91rm9200 IP and the other for the
at91sam9x5 IP).

Another solution would be to add an irq_try_set_irq_type function that
would not complain when it fails to set the requested trigger.

Thomas, I know you did not follow the whole thread, but would you mind
adding this irq_try_set_irq_type function (here is a reference
implementation [1]), to prevent this error trace from happening when
we're just trying a configuration ?

> If not, I am ok to drop the feature, this is only a bonus.

That could be a short term solution, to get this series accepted. We
could then find a proper way to support that optimization.


Best Regards,

Boris

[1]http://code.bulix.org/z4bu9k-87846

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv6 4/5] USB: gadget: atmel_usba_udc: Prepare for IRQ single edge support

2015-01-22 Thread Boris Brezillon
On Thu, 22 Jan 2015 17:56:44 +0100
Sylvain Rochet  wrote:

> Renamed struct usba_udc_errata to struct usba_udc_caps, we are adding a
> new property which is not about errata, this way the struct is not
> misnamed.
> 
> New struct usba_udc_caps property: irq_single_edge_support, boolean,
> set to true if the board supports IRQ_TYPE_EDGE_FALLING and
> IRQ_TYPE_EDGE_RISING, otherwise set to false.
> 
> Signed-off-by: Sylvain Rochet 

Acked-by: Boris Brezillon 

> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 25 +++--
>  drivers/usb/gadget/udc/atmel_usba_udc.h |  5 +++--
>  2 files changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index d554106..361f740 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -338,8 +338,8 @@ static int vbus_is_present(struct usba_udc *udc)
>  
>  static void toggle_bias(struct usba_udc *udc, int is_on)
>  {
> - if (udc->errata && udc->errata->toggle_bias)
> - udc->errata->toggle_bias(udc, is_on);
> + if (udc->caps && udc->caps->toggle_bias)
> + udc->caps->toggle_bias(udc, is_on);
>  }
>  
>  static void generate_bias_pulse(struct usba_udc *udc)
> @@ -347,8 +347,8 @@ static void generate_bias_pulse(struct usba_udc *udc)
>   if (!udc->bias_pulse_needed)
>   return;
>  
> - if (udc->errata && udc->errata->pulse_bias)
> - udc->errata->pulse_bias(udc);
> + if (udc->caps && udc->caps->pulse_bias)
> + udc->caps->pulse_bias(udc);
>  
>   udc->bias_pulse_needed = false;
>  }
> @@ -1901,18 +1901,23 @@ static void at91sam9g45_pulse_bias(struct usba_udc 
> *udc)
>   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
>  }
>  
> -static const struct usba_udc_errata at91sam9rl_errata = {
> +static const struct usba_udc_caps at91sam9rl_caps = {
>   .toggle_bias = at91sam9rl_toggle_bias,
>  };
>  
> -static const struct usba_udc_errata at91sam9g45_errata = {
> +static const struct usba_udc_caps at91sam9g45_caps = {
>   .pulse_bias = at91sam9g45_pulse_bias,
> + .irq_single_edge_support = true,
> +};
> +
> +static const struct usba_udc_caps sama5d3_caps = {
> + .irq_single_edge_support = true,
>  };
>  
>  static const struct of_device_id atmel_udc_dt_ids[] = {
> - { .compatible = "atmel,at91sam9rl-udc", .data = &at91sam9rl_errata },
> - { .compatible = "atmel,at91sam9g45-udc", .data = &at91sam9g45_errata },
> - { .compatible = "atmel,sama5d3-udc" },
> + { .compatible = "atmel,at91sam9rl-udc", .data = &at91sam9rl_caps },
> + { .compatible = "atmel,at91sam9g45-udc", .data = &at91sam9g45_caps },
> + { .compatible = "atmel,sama5d3-udc", .data = &sama5d3_caps },
>   { /* sentinel */ }
>  };
>  
> @@ -1934,7 +1939,7 @@ static struct usba_ep * atmel_udc_of_init(struct 
> platform_device *pdev,
>   if (!match)
>   return ERR_PTR(-EINVAL);
>  
> - udc->errata = match->data;
> + udc->caps = match->data;
>  
>   udc->num_ep = 0;
>  
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h 
> b/drivers/usb/gadget/udc/atmel_usba_udc.h
> index 085749a..4fe4c87 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.h
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
> @@ -304,9 +304,10 @@ struct usba_request {
>   unsigned intmapped:1;
>  };
>  
> -struct usba_udc_errata {
> +struct usba_udc_caps {
>   void (*toggle_bias)(struct usba_udc *udc, int is_on);
>   void (*pulse_bias)(struct usba_udc *udc);
> + bool irq_single_edge_support;
>  };
>  
>  struct usba_udc {
> @@ -322,7 +323,7 @@ struct usba_udc {
>   struct usb_gadget gadget;
>   struct usb_gadget_driver *driver;
>   struct platform_device *pdev;
> - const struct usba_udc_errata *errata;
> + const struct usba_udc_caps *caps;
>   int irq;
>   int vbus_pin;
>   int vbus_pin_inverted;



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv5 0/4] USB: gadget: atmel_usba_udc: Driver improvements

2015-01-21 Thread Boris Brezillon
Hi Sylvain,

On Wed, 21 Jan 2015 20:31:10 +0100
Sylvain Rochet  wrote:

> Start clocks on rising edge of the Vbus signal, stop clocks on falling 
> edge of the Vbus signal.
> 
> Add suspend/resume with wakeup support.

Apart from the minor comment I made on patch 4, you can add my:

Acked-by: Boris Brezillon 

to the whole series.

Thanks for your patience.

Best Regards,

Boris

> 
> Changes since v4:
>   * Now using IRQ_NOAUTOEN flag to remove the unused check for 
> udc->driver is not NULL in the Vbus IRQ.
>   * Reworked the start/stop of clocks on Vbus edges to prepare for 
> suspend/resume support, factorised start and stop procedures
>   * New patch, suspend/resume for USBA with wakeup support
> 
> Changes since v3:
>   * Added stable tag for the first patch
>   * As suggested, removed the unused check for udc->driver is not NULL in
> Vbus IRQ by requesting IRQ after udc->driver is set and by releasing
> IRQ before udc->driver is cleared
>   * Rebased the core patch of this series against the just explained changes
> 
> Changes since v2:
>   * Use spin_lock_irqsave/unlock_irqrestore instead of spin_lock/unlock in
> threaded interrupt because we are not in irq context anymore
>   * Removed useless and probably harmful IRQF_NO_SUSPEND from
> devm_request_threaded_irq() flags
> 
> Changes since v1:
>   * Using a threaded irq and mutex instead of spinclock as suggested
>   * Moved a silently fixed bug in a separate patch (1/2)
> 
> Sylvain Rochet (4):
>   USB: gadget: atmel_usba_udc: Fixed vbus_prev initial state
>   USB: gadget: atmel_usba_udc: Request an auto disabled Vbus signal IRQ
> instead of an auto enabled IRQ request followed by IRQ disable
>   USB: gadget: atmel_usba_udc: Start clocks on rising edge of the Vbus
> signal, stop clocks on falling edge of the Vbus signal
>   USB: gadget: atmel_usba_udc: Add suspend/resume with wakeup support
> 
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 214 
> ----
>  drivers/usb/gadget/udc/atmel_usba_udc.h |   4 +
>  2 files changed, 165 insertions(+), 53 deletions(-)
> 



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv5 4/4] USB: gadget: atmel_usba_udc: Add suspend/resume with wakeup support

2015-01-21 Thread Boris Brezillon
Hi Sylvain,

On Wed, 21 Jan 2015 20:31:14 +0100
Sylvain Rochet  wrote:

> This patch add suspend/resume with wakeup support for Atmel USBA.
> 
> On suspend: We stay continuously clocked if Vbus signal is not
> available. If Vbus signal is available we set the Vbus signal as a wake
> up source then we stop the USBA itself and all clocks used by USBA.
> 
> On resume: We recover clocks and USBA we stopped them. If a device is
> connected, i.e. connected while we were suspended without wakeup
> enabled, we enable the controller.
> 
> Signed-off-by: Sylvain Rochet 
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 61 
> +
>  1 file changed, 61 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index 963e398..326725e 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -2115,6 +2115,7 @@ static int usba_udc_probe(struct platform_device *pdev)
>   ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
>   if (ret)
>   return ret;
> + device_init_wakeup(&pdev->dev, 1);
>  
>   usba_init_debugfs(udc);
>   for (i = 1; i < udc->num_ep; i++)
> @@ -2130,6 +2131,7 @@ static int __exit usba_udc_remove(struct 
> platform_device *pdev)
>  
>   udc = platform_get_drvdata(pdev);
>  
> + device_init_wakeup(&pdev->dev, 0);
>   usb_del_gadget_udc(&udc->gadget);
>  
>   for (i = 1; i < udc->num_ep; i++)
> @@ -2139,6 +2141,62 @@ static int __exit usba_udc_remove(struct 
> platform_device *pdev)
>   return 0;
>  }
>  
> +#ifdef CONFIG_PM
> +static int usba_udc_suspend(struct device *dev)
> +{
> + struct usba_udc *udc = dev_get_drvdata(dev);
> +
> + /* Not started */
> + if (!udc->driver)
> + return 0;
> +
> + if (!device_may_wakeup(dev)) {
> + usba_stop(udc);
> + return 0;
> + }
> +
> + /*
> +  * Device may wake up. We stay clocked if we failed
> +  * to request vbus irq, assuming always on.
> +  */
> + if (gpio_is_valid(udc->vbus_pin)) {
> + usba_stop(udc);
> + /* Only wake up on device connection */
> + irq_set_irq_type(gpio_to_irq(udc->vbus_pin),
> + udc->vbus_pin_inverted ?
> + IRQ_TYPE_EDGE_FALLING : IRQ_TYPE_EDGE_RISING);

If I'm correct, you're testing on a at91sam9x5 platform. Be careful,
this driver is used by older SoCs (at91sam9rl and avr32 SoCs) which do
not support configuring the interrupt on a specific edge (they trigger
on both edges).

This leaves two solutions here:
1) keep the IRQ_TYPE_EDGE_BOTH setting.
2) add new compatible strings to this driver and make this specific
edge change dependent on the SoC capability.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv4 2/3] USB: gadget: atmel_usba_udc: Enable Vbus signal IRQ in UDC start instead of UDC probe

2015-01-21 Thread Boris Brezillon
Hi Sylvain,

On Tue, 20 Jan 2015 22:23:29 +0100
Sylvain Rochet  wrote:

> Vbus IRQ handler needs a started UDC driver to work because it uses
> udc->driver, which is set by the UDC start handler. The previous way
> chosen was to return from interrupt if udc->driver is NULL using a
> spinlock.
> 
> This patch now request the Vbus signal IRQ in UDC start instead of UDC
> probe and release the IRQ in UDC stop before udc->driver is set back to
> NULL. This way we don't need the check about udc->driver in interruption
> handler, therefore we don't need the spinlock as well anymore.
> 
> This was chosen against using set_irq_flags() to request a not auto
> enabled IRQ (IRQF_NOAUTOEN flag) because set_irq_flags() can't change
> just one flag, therefore it must be called with all flags, without
> respecting what the AIC previously did. Naively copying IRQ flags
> currently set by the AIC looked like error-prone if defaults flags
> change at some point in the future.
> 
> Signed-off-by: Sylvain Rochet 
> Suggested-by: Boris Brezillon 
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 64 
> -
>  1 file changed, 32 insertions(+), 32 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index e207d75..546da63 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -1729,10 +1729,6 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
>  
>   spin_lock(&udc->lock);
>  
> - /* May happen if Vbus pin toggles during probe() */
> - if (!udc->driver)
> - goto out;
> -
>   vbus = vbus_is_present(udc);
>   if (vbus != udc->vbus_prev) {
>   if (vbus) {
> @@ -1753,7 +1749,6 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
>   udc->vbus_prev = vbus;
>   }
>  
> -out:
>   spin_unlock(&udc->lock);
>  
>   return IRQ_HANDLED;
> @@ -1767,23 +1762,27 @@ static int atmel_usba_start(struct usb_gadget *gadget,
>   unsigned long flags;
>  
>   spin_lock_irqsave(&udc->lock, flags);
> -
>   udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
>   udc->driver = driver;
>   spin_unlock_irqrestore(&udc->lock, flags);
>  
>   ret = clk_prepare_enable(udc->pclk);
>   if (ret)
> - return ret;
> + goto err_pclk;
>   ret = clk_prepare_enable(udc->hclk);
> - if (ret) {
> - clk_disable_unprepare(udc->pclk);
> - return ret;
> - }
> + if (ret)
> + goto err_hclk;
>  
>   udc->vbus_prev = 0;
> - if (gpio_is_valid(udc->vbus_pin))
> - enable_irq(gpio_to_irq(udc->vbus_pin));
> + if (gpio_is_valid(udc->vbus_pin)) {
> + ret = request_irq(gpio_to_irq(udc->vbus_pin),
> + usba_vbus_irq, 0,
> + "atmel_usba_udc", udc);
> + if (ret) {
> + udc->vbus_pin = -ENODEV;

I guess you're trying to protect against free_irq by changing the
vbus_pin value (making it an invalid gpio id), but I think you should
leave it unchanged for two reasons:
1) If the request_irq call temporary fails (an ENOMEM for example) then
you should be able to retry later, and modifying the vbus_pin value
will prevent that.
2) atmel_usba_stop will never be called if the atmel_usba_start failed,
so there's no need to protect against this free_irq.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv6 0/6] USB: host: Atmel OHCI and EHCI drivers improvements

2015-01-20 Thread Boris Brezillon
On Mon, 19 Jan 2015 12:06:01 +0100
Sylvain Rochet  wrote:

> USB: host: Atmel OHCI and EHCI drivers improvements
> 
> Suspend/resume support for EHCI.
> struct dev_pm_ops for OHCI.
> Removed global variables from both.
> Fixed OHCI wake up support for STANDBY(wake-up enabled) and MEM(wake-up
> disabled) sleep targets.

To the whole series:

Acked-by: Boris Brezillon 

> 
> Changes since v5:
>   * Don't overwrite device wakeup flag with device_init_wakeup(),
> now using a private wakeup bool instead.
> 
> Changes since v4:
>   * Re-add at91_suspend_entering_slow_clock() to OHCI, we can't naively
> remove this one, this device needs to be continuously clocked to
> provide wake up support.
> The removal of at91_suspend_entering_slow_clock() actually lighted up
> an issue on wake up support, which is now fixed.
> 
> Changes since v3:
>   * Using struct dev_pm_ops instead of static struct platform_driver
> resume and suspend bindings for both EHCI and OHCI
>   * Fixed inconsistency in patch subjects, _ intead of - for file names
>   * Patch cleaning with the help of checkpatch.pl, fixed lines over
> 80 characters
> 
> Changes since v2:
>   * Added patchs from an other submission, because this series
> depended on this one
> * EHCI: Move global variables to private struct
> * OHCI: Move global variables to private struct
>   * Using ohci->priv and ehci->priv instead of hcd->hcd_priv,
> which were not the right way to do that
> 
> Changes since v1:
>   * Don't use at91_suspend_entering_slow_clock() on EHCI,
> we are trying to get read of this of this function
>   * Removed at91_suspend_entering_slow_clock() from OHCI
> 
> Sylvain Rochet (6):
>   USB: host: ehci-atmel: Add suspend/resume support
>   USB: host: ohci-at91: Use struct dev_pm_ops instead of struct
> platform_driver
>   USB: host: ehci-atmel: Move global variables to private struct
>   USB: host: ohci-at91: Move global variables to private struct
>   USB: host: ohci-at91: usb_hcd_at91_probe(), remove useless stack
> initialisation
>   USB: host: ohci-at91: Fix wake-up support
> 
>  drivers/usb/host/ehci-atmel.c | 102 +++++-
>  drivers/usb/host/ohci-at91.c  | 126 
> ++
>  2 files changed, 154 insertions(+), 74 deletions(-)
> 



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv3 2/2] USB: gadget: atmel_usba_udc: Enable/disable USB PLL on Vbus change

2015-01-19 Thread Boris Brezillon
On Mon, 19 Jan 2015 18:46:31 +0100
Sylvain Rochet  wrote:

> Hello Nicolas,
> 
> 
> On Mon, Jan 19, 2015 at 05:55:18PM +0100, Nicolas Ferre wrote:
> > Le 18/01/2015 18:24, Sylvain Rochet a écrit :
> > > Prepare_enable on rising edge, disable_unprepare on falling edge. Reduce
> >
> > Please re-write which "edge" we are talking about: "... falling edge of
> > the Vbus signal" for example.
> >
> > > power consumption if USB PLL is not already necessary for OHCI or EHCI.
> >
> > Is a verb missing in the previous sentence?
> >
> > > If USB host is not connected we can sleep with USB PLL stopped.
> > >
> > > This driver does not support suspend/resume yet, not suspending if we
> > > are still attached to an USB host is fine for what I need, this patch
> > > allow suspending with USB PLL stopped when USB device is not currently
> > > used.
> >
> > Can you please make it more clear. Several separated sentences seem
> > necessary here.
> 
> Maybe :)
> 
> 
> Proposal:
> 
> Start clocks on rising edge of the Vbus signal, stop clocks on 
> falling edge of the Vbus signal.
> 
> If USB PLL is not necessary for other USB drivers (e.g. OHCI and EHCI) 
> it will reduce power consumption by switching off the USB PLL if no USB 
> Host is currently connected to this USB Device.
> 
> We are using Vbus GPIO signal to detect Host presence. If Vbus signal is 
> not available then the device stay continuously clocked.
> 
> Note this driver does not support suspend/resume yet, it may stay 
> clocked if USB Host is still connected when suspending. For what I need, 
> forbidding suspend from userland if we are still attached to an USB host 
> is fine, but we might as well add suspend/resume to this driver in the 
> future.
> 
> 
> 
> > >   /* May happen if Vbus pin toggles during probe() */
> > > - if (!udc->driver)
> > > + spin_lock_irqsave(&udc->lock, flags);
> > > + if (!udc->driver) {
> > > + spin_unlock_irqrestore(&udc->lock, flags);
> > >   goto out;
> > > + }
> > > + spin_unlock_irqrestore(&udc->lock, flags);
> > 
> > I'm not sure that the protection by spin_lock is needed above.
> 
> I'm not sure too, it was already in a spinlock area, I obviously kept it 
> because it was not the purpose of this patch.

According to the comment placed above this test it's here to prevent
any action triggered by the vbus pin irq while the driver is not
properly probed yet.
You could use:

set_irq_flags(vbus_irq, IRQF_NOAUTOEN);

before calling devm_request_threaded_irq.
This will keep the irq disabled instead of enabling it at request time.
Moreover, this simplify the vbus_irq request code (which disables the
irq just after requesting it).

> 
> This seem to be in mirror of atmel_usba_start() which does:
> 
>   spin_lock_irqsave(&udc->lock, flags);
>   udc->devstatus = 1 << USB_DEVICE_SELF_POWERED;
>   udc->driver = driver;
>   spin_unlock_irqrestore(&udc->lock, flags);
> 
> … but vbus_pin IRQ is not yet enabled.
> 
> 
> Same for atmel_usba_stop() which disable vbus_pin IRQ before setting 
> udc->driver to NULL, but without spinlock this time (why?, this should 
> be consistent IMHO).
> 
> 
> I don't know if it is guaranteed that IRQ does not fire nor continue to 
> run after disable_irq() returns, especially for threaded IRQ.

And yes, disable_irq waits for all irq handler termination, including
threaded irqs: see [1], [2]. 

> 
> 
> If the following sequence might happen:
>   atmel_usba_stop()
> disable_irq(vbus)
>   usba_vbus_irq_thread() called lately
> check for (!udc->driver) and continue
> udc->driver = NULL;
> if (udc->driver->disconnect)
>  *CRASH*
> 
> Then the patch should be modified to protect udc->driver with the vbus 
> mutex.
> 
> In this case the previous implementation wasn't perfect too, the 
> atmel_usba_stop() does not lock around the NULLification of driver, 
> 
> Moreover the spinlock is (and was) unlocked in VBUS interrupt just 
> before calling udc->driver->disconnect, which makes udc->driver actually 
> not locked anywere.
> 
> If the previous sequence possible ?  If no, udc->driver does not need 
> locking, if yes, it is currently not locked enough.

If you rework the vbus_irq request as I suggested I think you can get
rid of this !udc->driver test, and thus drop the locking around it ;-).

Best Regards,

Boris

[1]http://lxr.free-electrons.com/source/kernel/irq/manage.c#L432
[2]http://lxr.free-electrons.com/source/kernel/irq/manage.c#L92



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] USB: gadget: atmel_usba_udc: Enable/disable USB PLL on Vbus change

2015-01-18 Thread Boris Brezillon
On Sun, 18 Jan 2015 15:51:21 +0100
Sylvain Rochet  wrote:

> Prepare_enable on rising edge, disable_unprepare on falling edge. Reduce
> power consumption if USB PLL is not already necessary for OHCI or EHCI.
> If USB host is not connected we can sleep with USB PLL stopped.
> 
> This driver does not support suspend/resume yet, not suspending if we
> are still attached to an USB host is fine for what I need, this patch
> allow suspending with USB PLL stopped when USB device is not currently
> used.
> 
> Signed-off-by: Sylvain Rochet 
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 95 
> -
>  drivers/usb/gadget/udc/atmel_usba_udc.h |  4 ++
>  2 files changed, 73 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index e207d75..986677b 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -315,6 +315,38 @@ static inline void usba_cleanup_debugfs(struct usba_udc 
> *udc)
>  }
>  #endif
>  

[...]

>  
>   if (gpio_is_valid(udc->vbus_pin)) {
>   if (!devm_gpio_request(&pdev->dev, udc->vbus_pin, 
> "atmel_usba_udc")) {
> - ret = devm_request_irq(&pdev->dev,
> - gpio_to_irq(udc->vbus_pin),
> - usba_vbus_irq, 0,
> + ret = devm_request_threaded_irq(&pdev->dev,
> + gpio_to_irq(udc->vbus_pin), NULL,
> + usba_vbus_irq_thread, IRQF_NO_SUSPEND | 
> IRQF_ONESHOT,

You should drop the IRQF_NO_SUSPEND flag. If you want to wakeup on VBUS
change you should use enable_irq_wake instead.



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] USB: gadget: atmel_usba_udc: Enable/disable USB PLL on Vbus change

2015-01-18 Thread Boris Brezillon
On Sun, 18 Jan 2015 15:51:21 +0100
Sylvain Rochet  wrote:

> Prepare_enable on rising edge, disable_unprepare on falling edge. Reduce
> power consumption if USB PLL is not already necessary for OHCI or EHCI.
> If USB host is not connected we can sleep with USB PLL stopped.
> 
> This driver does not support suspend/resume yet, not suspending if we
> are still attached to an USB host is fine for what I need, this patch
> allow suspending with USB PLL stopped when USB device is not currently
> used.
> 
> Signed-off-by: Sylvain Rochet 
> ---
>  drivers/usb/gadget/udc/atmel_usba_udc.c | 95 
> -
>  drivers/usb/gadget/udc/atmel_usba_udc.h |  4 ++
>  2 files changed, 73 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> b/drivers/usb/gadget/udc/atmel_usba_udc.c
> index e207d75..986677b 100644
> --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> @@ -315,6 +315,38 @@ static inline void usba_cleanup_debugfs(struct usba_udc 
> *udc)
>  }
>  #endif
>  
> +static int start_clock(struct usba_udc *udc)
> +{
> + int ret;
> +
> + if (udc->clocked)
> + return 0;
> +
> + ret = clk_prepare_enable(udc->pclk);
> + if (ret)
> + return ret;
> + ret = clk_prepare_enable(udc->hclk);
> + if (ret) {
> + clk_disable_unprepare(udc->pclk);
> + return ret;
> + }
> +
> + udc->clocked = true;
> + return ret;
> +}
> +
> +static int stop_clock(struct usba_udc *udc)
> +{
> + if (!udc->clocked)
> + return 0;
> +
> + clk_disable_unprepare(udc->hclk);
> + clk_disable_unprepare(udc->pclk);
> +
> + udc->clocked = false;
> + return 0;
> +}
> +
>  static int vbus_is_present(struct usba_udc *udc)
>  {
>   if (gpio_is_valid(udc->vbus_pin))
> @@ -1719,42 +1751,55 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
>   return IRQ_HANDLED;
>  }
>  
> -static irqreturn_t usba_vbus_irq(int irq, void *devid)
> +static irqreturn_t usba_vbus_irq_thread(int irq, void *devid)
>  {
>   struct usba_udc *udc = devid;
>   int vbus;
> + int ret;
>  
>   /* debounce */
>   udelay(10);
>  
> - spin_lock(&udc->lock);
> + mutex_lock(&udc->vbus_mutex);
>  
>   /* May happen if Vbus pin toggles during probe() */
> - if (!udc->driver)
> + spin_lock(&udc->lock);

Since this lock is taken in irq context (usba_udc_irq) and this
handler is not called in irq context anymore you should use
spin_lock_irqsave/unlock_irqrestore here.

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/12] mfd: syscon: Add atmel-matrix registers definition

2015-01-18 Thread Boris Brezillon
Hi Lee,

On Sun, 18 Jan 2015 12:52:59 +
Lee Jones  wrote:

> On Wed, 14 Jan 2015, Alexandre Belloni wrote:
> 
> > From: Boris Brezillon 
> > 
> > AT91 SoCs have a memory range reserved for internal bus configuration.
> > Expose those registers so that drivers can make use of the matrix syscon
> > declared in at91 DTs.
> > 
> > Signed-off-by: Boris Brezillon 
> > Acked-by: Lee Jones 
> > ---
> >  include/linux/mfd/syscon/atmel-matrix.h | 117 
> > 
> >  1 file changed, 117 insertions(+)
> >  create mode 100644 include/linux/mfd/syscon/atmel-matrix.h
> 
> Applied, thanks.

Actually Nicolas took all the patches in his tree and already sent a PR
to the arm-soc maintainers [1].

Best Regards,

Boris

[1]https://lkml.org/lkml/2015/1/15/542

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv3 1/5] USB: host: ehci_atmel: Add suspend/resume support

2015-01-18 Thread Boris Brezillon
Hi Sylvain,

On Sat, 17 Jan 2015 23:49:00 +0100
Sylvain Rochet  wrote:

> Hi Sergei,
> 
> 
> On Sun, Jan 18, 2015 at 01:22:38AM +0300, Sergei Shtylyov wrote:
> > 
> >There's little inconsistency in your patch subjects: you're using
> > '_' but the files you're modifying are named using '-'...
> 
> Indeed.
> 
> 
> > >@@ -187,6 +217,8 @@ static struct platform_driver ehci_atmel_driver = {
> > >   .probe  = ehci_atmel_drv_probe,
> > >   .remove = ehci_atmel_drv_remove,
> > >   .shutdown   = usb_hcd_platform_shutdown,
> > >+  .suspend= ehci_atmel_drv_suspend,
> > >+  .resume = ehci_atmel_drv_resume,
> > 
> >I think you should use 'struct dev_pm_ops' now.
> 
> This way ?
> 
> static int ehci_atmel_drv_suspend(struct device *dev)
> {
>   struct usb_hcd *hcd = dev_get_drvdata(dev);
> (...)
> 
> 
> static SIMPLE_DEV_PM_OPS(ehci_atmel_pm_ops, ehci_atmel_drv_suspend, 
> ehci_atmel_drv_resume);
> 
> (...)
>   .driver = {
>   .pm = &ehci_atmel_pm_ops,
>   }
> (...)
> 
> 
> Should I send a v4 or can I send this change separately on top of the 
> previous change ?

I think it's better to send a v4 reworking this patch (you'll have to
change your commit subject anyway ;-)).

Best Regards,

Boris


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 1/3] USB: host: ehci_atmel: Move global variables to private struct

2015-01-17 Thread Boris Brezillon
Hi Sylvain,

On Sat, 17 Jan 2015 19:23:31 +0100
Sylvain Rochet  wrote:

> This patch move Atmel EHCI global variables (clocks ptr and clocked
> boolean) to private struct atmel_ehci, appended at the end of the parent
> struct usb_hcd.

Maybe you should add a cover letter to clearly state that this series
depends on another one: [1].

Anyway, thanks for removing these global variables.

> 
> Signed-off-by: Sylvain Rochet 

To the whole series:

Acked-by: Boris Brezillon 

[1]https://www.mail-archive.com/linux-usb@vger.kernel.org/msg54675.html


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2 2/2] USB: host: ohci_at91: Stop/start USB PLL for all sleep modes

2015-01-17 Thread Boris Brezillon
On Sat, 17 Jan 2015 16:36:35 +0100
Sylvain Rochet  wrote:

> Disable/unprepare clocks without testing the sleep target_state, removed
> the at91_suspend_entering_slow_clock() call (which is only a
> target_state == PM_SUSPEND_MEM).
> 
> Other kind of suspend now benefit from the power save induced by this
> PLL deactivation. The resume penalty is about 500 us, which is not
> negligible but acceptable considering the amount of power we are saving.
> 
> Signed-off-by: Sylvain Rochet 
> Reported-by: Boris Brezillon 

Acked-by: Boris Brezillon 

> ---
>  drivers/usb/host/ohci-at91.c | 25 +
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
> index dc9e4e6..f0da734 100644
> --- a/drivers/usb/host/ohci-at91.c
> +++ b/drivers/usb/host/ohci-at91.c
> @@ -49,6 +49,8 @@ extern int usb_disabled(void);
>  
>  static void at91_start_clock(void)
>  {
> + if (clocked)
> + return;
>   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
>   clk_set_rate(uclk, 4800);
>   clk_prepare_enable(uclk);
> @@ -61,6 +63,8 @@ static void at91_start_clock(void)
>  
>  static void at91_stop_clock(void)
>  {
> + if (!clocked)
> + return;
>   clk_disable_unprepare(fclk);
>   clk_disable_unprepare(iclk);
>   clk_disable_unprepare(hclk);
> @@ -615,16 +619,14 @@ ohci_hcd_at91_drv_suspend(struct platform_device *pdev, 
> pm_message_t mesg)
>*
>* REVISIT: some boards will be able to turn VBUS off...
>*/
> - if (at91_suspend_entering_slow_clock()) {
> - ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
> - ohci->hc_control &= OHCI_CTRL_RWC;
> - ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
> - ohci->rh_state = OHCI_RH_HALTED;
> -
> - /* flush the writes */
> - (void) ohci_readl (ohci, &ohci->regs->control);
> - at91_stop_clock();
> - }
> + ohci->hc_control = ohci_readl(ohci, &ohci->regs->control);
> + ohci->hc_control &= OHCI_CTRL_RWC;
> + ohci_writel(ohci, ohci->hc_control, &ohci->regs->control);
> + ohci->rh_state = OHCI_RH_HALTED;
> +
> + /* flush the writes */
> + (void) ohci_readl (ohci, &ohci->regs->control);
> + at91_stop_clock();
>  
>   return ret;
>  }
> @@ -636,8 +638,7 @@ static int ohci_hcd_at91_drv_resume(struct 
> platform_device *pdev)
>   if (device_may_wakeup(&pdev->dev))
>   disable_irq_wake(hcd->irq);
>  
> - if (!clocked)
> - at91_start_clock();
> + at91_start_clock();
>  
>   ohci_resume(hcd, false);
>   return 0;



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv2 1/2] USB: host: ehci_atmel: Add suspend/resume support

2015-01-17 Thread Boris Brezillon
On Sat, 17 Jan 2015 16:36:34 +0100
Sylvain Rochet  wrote:

> This patch add suspend/resume support for Atmel EHCI, mostly
> about disabling and unpreparing clocks so USB PLL is stopped
> before entering sleep state.
> 
> Signed-off-by: Sylvain Rochet 

Acked-by: Boris Brezillon 

> ---
>  drivers/usb/host/ehci-atmel.c | 32 
>  1 file changed, 32 insertions(+)
> 
> diff --git a/drivers/usb/host/ehci-atmel.c b/drivers/usb/host/ehci-atmel.c
> index 56a8850..2e0043b 100644
> --- a/drivers/usb/host/ehci-atmel.c
> +++ b/drivers/usb/host/ehci-atmel.c
> @@ -37,6 +37,8 @@ static int clocked;
>  
>  static void atmel_start_clock(void)
>  {
> + if (clocked)
> + return;
>   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
>   clk_set_rate(uclk, 4800);
>   clk_prepare_enable(uclk);
> @@ -48,6 +50,8 @@ static void atmel_start_clock(void)
>  
>  static void atmel_stop_clock(void)
>  {
> + if (!clocked)
> + return;
>   clk_disable_unprepare(fclk);
>   clk_disable_unprepare(iclk);
>   if (IS_ENABLED(CONFIG_COMMON_CLK))
> @@ -174,6 +178,32 @@ static int ehci_atmel_drv_remove(struct platform_device 
> *pdev)
>   return 0;
>  }
>  
> +#ifdef CONFIG_PM
> +static int ehci_atmel_drv_suspend(struct platform_device *pdev, pm_message_t 
> mesg)
> +{
> + struct usb_hcd *hcd = platform_get_drvdata(pdev);
> + int ret;
> +
> + ret = ehci_suspend(hcd, false);
> + if (ret)
> + return ret;
> +
> + atmel_stop_clock();
> + return 0;
> +}
> +
> +static int ehci_atmel_drv_resume(struct platform_device *pdev)
> +{
> + struct usb_hcd *hcd = platform_get_drvdata(pdev);
> +
> + atmel_start_clock();
> + return ehci_resume(hcd, false);
> +}
> +#else
> +#define ehci_atmel_drv_suspend NULL
> +#define ehci_atmel_drv_resume  NULL
> +#endif
> +
>  #ifdef CONFIG_OF
>  static const struct of_device_id atmel_ehci_dt_ids[] = {
>   { .compatible = "atmel,at91sam9g45-ehci" },
> @@ -187,6 +217,8 @@ static struct platform_driver ehci_atmel_driver = {
>   .probe  = ehci_atmel_drv_probe,
>   .remove = ehci_atmel_drv_remove,
>   .shutdown   = usb_hcd_platform_shutdown,
> + .suspend    = ehci_atmel_drv_suspend,
> + .resume = ehci_atmel_drv_resume,
>   .driver = {
>   .name   = "atmel-ehci",
>   .of_match_table = of_match_ptr(atmel_ehci_dt_ids),



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 3/5] ARM: at91/dt: update udc compatible strings

2015-01-12 Thread Boris Brezillon
On Mon, 12 Jan 2015 13:31:26 -0600
Felipe Balbi  wrote:

> On Mon, Jan 12, 2015 at 08:18:16PM +0100, Boris Brezillon wrote:
> > Hi Felipe,
> > 
> > On Mon, 12 Jan 2015 12:23:49 -0600
> > Felipe Balbi  wrote:
> > 
> > > On Mon, Jan 12, 2015 at 11:57:56AM +0100, Boris Brezillon wrote:
> > > > at91sam9g45, at91sam9x5 and sama5 SoCs should not use
> > > > "atmel,at91sam9rl-udc" for their USB device compatible property since
> > > > this compatible is attached to a specific hardware bug fix.
> > > > 
> > > > Signed-off-by: Boris Brezillon 
> > > > Acked-by: Alexandre Belloni 
> > > 
> > > WARNING: DT compatible string "atmel,at91sam9g45-udc" appears 
> > > un-documented -- check ./Documentation/devicetree/bindings/
> > > #177: FILE: drivers/usb/gadget/udc/atmel_usba_udc.c:1827:
> > > +   { .compatible = "atmel,at91sam9g45-udc" },
> > > 
> > > WARNING: DT compatible string "atmel,sama5d3-udc" appears un-documented 
> > > -- check ./Documentation/devicetree/bindings/
> > > #178: FILE: drivers/usb/gadget/udc/atmel_usba_udc.c:1828:
> > > +   { .compatible = "atmel,sama5d3-udc" },
> > > 
> > > please fix and resend. Also, when resending, could you add Nicolas'
> > > Acked-by since he's already given it ?
> > 
> > Actually these compatible strings are documented in the first patch
> > (where they were introduced), but I'll send a v4 with Nicolas' ack.
> 
> heh, checkpatch stupidity :-) My bad.
> 

You took v3 of the first patch instead of v4.
Don't know if you can replace it (anyway, that's not such a big deal
since the only change is the commit message)...


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3 3/5] ARM: at91/dt: update udc compatible strings

2015-01-12 Thread Boris Brezillon
Hi Felipe,

On Mon, 12 Jan 2015 12:23:49 -0600
Felipe Balbi  wrote:

> On Mon, Jan 12, 2015 at 11:57:56AM +0100, Boris Brezillon wrote:
> > at91sam9g45, at91sam9x5 and sama5 SoCs should not use
> > "atmel,at91sam9rl-udc" for their USB device compatible property since
> > this compatible is attached to a specific hardware bug fix.
> > 
> > Signed-off-by: Boris Brezillon 
> > Acked-by: Alexandre Belloni 
> 
> WARNING: DT compatible string "atmel,at91sam9g45-udc" appears un-documented 
> -- check ./Documentation/devicetree/bindings/
> #177: FILE: drivers/usb/gadget/udc/atmel_usba_udc.c:1827:
> +   { .compatible = "atmel,at91sam9g45-udc" },
> 
> WARNING: DT compatible string "atmel,sama5d3-udc" appears un-documented -- 
> check ./Documentation/devicetree/bindings/
> #178: FILE: drivers/usb/gadget/udc/atmel_usba_udc.c:1828:
> +   { .compatible = "atmel,sama5d3-udc" },
> 
> please fix and resend. Also, when resending, could you add Nicolas'
> Acked-by since he's already given it ?

Actually these compatible strings are documented in the first patch
(where they were introduced), but I'll send a v4 with Nicolas' ack.

Thanks,

Boris



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/5] usb: atmel_usba_udc: Rework at91sam9rl errata handling

2015-01-12 Thread Boris Brezillon
at91sam9rl SoC has an erratum forcing us to toggle the BIAS on USB
suspend/resume events.

This specific handling was only activated when CONFIG_ARCH_AT91SAM9RL
was set, but commit bcf8c7e7703b ("ARM: at91: remove at91sam9rl legacy
board support") removed this option.

Rework the toggle_bias implementation to attach it to the "at91sam9rl-udc"
compatible string.

Add new compatible strings to avoid executing at91sam9rl erratum handling
on other SoCs.

Reported-by: Paul Bolle 
Signed-off-by: Boris Brezillon 
Acked-by: Alexandre Belloni 
Acked-by: Nicolas Ferre 
---

Changes since v3:
- rework commit message

 .../devicetree/bindings/usb/atmel-usb.txt  |  5 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 78 --
 drivers/usb/gadget/udc/atmel_usba_udc.h|  5 ++
 3 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index bcc..38fee0f 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -51,7 +51,10 @@ usb1: gadget@fffa4000 {
 Atmel High-Speed USB device controller
 
 Required properties:
- - compatible: Should be "atmel,at91sam9rl-udc"
+ - compatible: Should be one of the following
+  "at91sam9rl-udc"
+  "at91sam9g45-udc"
+  "sama5d3-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain usba interrupt
  - ep childnode: To specify the number of endpoints and their properties.
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ce88237..36fd34b 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -324,28 +325,12 @@ static int vbus_is_present(struct usba_udc *udc)
return 1;
 }
 
-#if defined(CONFIG_ARCH_AT91SAM9RL)
-
-#include 
-
-static void toggle_bias(int is_on)
-{
-   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
-
-   if (is_on)
-   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
-   else
-   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
-}
-
-#else
-
-static void toggle_bias(int is_on)
+static void toggle_bias(struct usba_udc *udc, int is_on)
 {
+   if (udc->errata && udc->errata->toggle_bias)
+   udc->errata->toggle_bias(udc, is_on);
 }
 
-#endif /* CONFIG_ARCH_AT91SAM9RL */
-
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1620,7 +1605,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1632,7 +1617,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
}
 
if (status & USBA_WAKE_UP) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
@@ -1736,13 +1721,13 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
vbus = vbus_is_present(udc);
if (vbus != udc->vbus_prev) {
if (vbus) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
} else {
udc->gadget.speed = USB_SPEED_UNKNOWN;
reset_all_endpoints(udc);
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, CTRL, USBA_DISABLE_MASK);
if (udc->driver->disconnect) {
spin_unlock(&udc->lock);
@@ -1788,7 +1773,7 @@ static int atmel_usba_start(struct usb_gadget *gadget,
/* If Vbus is present, enable the controller and wait for reset */
spin_lock_irqsave(&udc->lock, flags);
if (vbus_is_present(udc) && udc->vbus_prev == 0) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
}
@@ -1811,7 +1796,7 @@ static int atmel_usba_stop(struct usb_gadge

Re: [PATCH v3 1/5] usb: atmel_usba_udc: Rework at91sam9rl errata handling

2015-01-12 Thread Boris Brezillon
Hi Paul,

On Mon, 12 Jan 2015 13:15:58 +0100
Paul Bolle  wrote:

> On Mon, 2015-01-12 at 11:57 +0100, Boris Brezillon wrote:
> > at91sam9rl SoC has an erratum forcing us to toggle the BIAS on USB
> > suspend/resume events.
> > 
> > This specific handling is only activated when CONFIG_ARCH_AT91SAM9RL is
> > set and this option is only set when building a non-DT kernel, which is
> > problematic since non-DT support for at91sam9rl SoC has been removed.
> 
> This sentence is not entirely correct. Commit bcf8c7e7703b ("ARM: at91:
> remove at91sam9rl legacy board support") actually removed the Kconfig
> symbol ARCH_AT91SAM9RL entirely. So the check for CONFIG_ARCH_AT91SAM9RL
> has been pointless since (next-20141110 and) v3.19-rc1. See my report at
> https://lkml.org/lkml/2014/11/10/232 .

I'll rework my commit message.

> 
> (I stumbled on this patch because I contemplated sending a patch to
> simply remove the check for CONFIG_ARCH_AT91SAM9RL and the currently
> useless function toggle_bias.)

Sorry, I forgot to add you in Cc of this series :-(, I'll do it it for
the future iterations.

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/5] ARM: at91/dt: update udc compatible strings

2015-01-12 Thread Boris Brezillon
at91sam9g45, at91sam9x5 and sama5 SoCs should not use
"atmel,at91sam9rl-udc" for their USB device compatible property since
this compatible is attached to a specific hardware bug fix.

Signed-off-by: Boris Brezillon 
Acked-by: Alexandre Belloni 
---
 arch/arm/boot/dts/at91sam9g45.dtsi | 2 +-
 arch/arm/boot/dts/at91sam9x5.dtsi  | 2 +-
 arch/arm/boot/dts/sama5d3.dtsi | 2 +-
 arch/arm/boot/dts/sama5d4.dtsi | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi 
b/arch/arm/boot/dts/at91sam9g45.dtsi
index 2a8da8a..acd90eb 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -1144,7 +1144,7 @@
usb2: gadget@fff78000 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,at91sam9g45-udc";
reg = <0x0060 0x8
   0xfff78000 0x400>;
interrupts = <27 IRQ_TYPE_LEVEL_HIGH 0>;
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi 
b/arch/arm/boot/dts/at91sam9x5.dtsi
index bbb3ba6..d213147 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -1057,7 +1057,7 @@
usb2: gadget@f803c000 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,at91sam9g45-udc";
reg = <0x0050 0x8
   0xf803c000 0x400>;
interrupts = <23 IRQ_TYPE_LEVEL_HIGH 0>;
diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
index 5f4144d..2b407a4 100644
--- a/arch/arm/boot/dts/sama5d3.dtsi
+++ b/arch/arm/boot/dts/sama5d3.dtsi
@@ -1264,7 +1264,7 @@
usb0: gadget@0050 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,sama5d3-udc";
reg = <0x0050 0x10
   0xf803 0x4000>;
interrupts = <33 IRQ_TYPE_LEVEL_HIGH 2>;
diff --git a/arch/arm/boot/dts/sama5d4.dtsi b/arch/arm/boot/dts/sama5d4.dtsi
index 1b0f30c..52dce24 100644
--- a/arch/arm/boot/dts/sama5d4.dtsi
+++ b/arch/arm/boot/dts/sama5d4.dtsi
@@ -112,7 +112,7 @@
usb0: gadget@0040 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,sama5d3-udc";
reg = <0x0040 0x10
   0xfc02c000 0x4000>;
interrupts = <47 IRQ_TYPE_LEVEL_HIGH 2>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 2/5] usb: atmel_usba_udc: Add at91sam9g45 and at91sam9x5 errata handling

2015-01-12 Thread Boris Brezillon
at91sam9g45 and at91sam9x5 SoCs have an hardware bug forcing us to
generate a pulse on the BIAS signal on "USB end of reset" and
"USB end of resume" events.

Reported-by: Patrice VILCHEZ 
Signed-off-by: Boris Brezillon 
Acked-by: Alexandre Belloni 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 28 +++-
 drivers/usb/gadget/udc/atmel_usba_udc.h |  2 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 36fd34b..55c8dde 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -331,6 +331,17 @@ static void toggle_bias(struct usba_udc *udc, int is_on)
udc->errata->toggle_bias(udc, is_on);
 }
 
+static void generate_bias_pulse(struct usba_udc *udc)
+{
+   if (!udc->bias_pulse_needed)
+   return;
+
+   if (udc->errata && udc->errata->pulse_bias)
+   udc->errata->pulse_bias(udc);
+
+   udc->bias_pulse_needed = false;
+}
+
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1607,6 +1618,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
+   udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
&& udc->driver && udc->driver->suspend) {
@@ -1624,6 +1636,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 
if (status & USBA_END_OF_RESUME) {
usba_writel(udc, INT_CLR, USBA_END_OF_RESUME);
+   generate_bias_pulse(udc);
DBG(DBG_BUS, "Resume detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
&& udc->driver && udc->driver->resume) {
@@ -1659,6 +1672,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
struct usba_ep *ep0;
 
usba_writel(udc, INT_CLR, USBA_END_OF_RESET);
+   generate_bias_pulse(udc);
reset_all_endpoints(udc);
 
if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) {
@@ -1818,13 +1832,25 @@ static void at91sam9rl_toggle_bias(struct usba_udc 
*udc, int is_on)
at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
 }
 
+static void at91sam9g45_pulse_bias(struct usba_udc *udc)
+{
+   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
+
+   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
+   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
+}
+
 static const struct usba_udc_errata at91sam9rl_errata = {
.toggle_bias = at91sam9rl_toggle_bias,
 };
 
+static const struct usba_udc_errata at91sam9g45_errata = {
+   .pulse_bias = at91sam9g45_pulse_bias,
+};
+
 static const struct of_device_id atmel_udc_dt_ids[] = {
{ .compatible = "atmel,at91sam9rl-udc", .data = &at91sam9rl_errata },
-   { .compatible = "atmel,at91sam9g45-udc" },
+   { .compatible = "atmel,at91sam9g45-udc", .data = &at91sam9g45_errata },
{ .compatible = "atmel,sama5d3-udc" },
{ /* sentinel */ }
 };
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h 
b/drivers/usb/gadget/udc/atmel_usba_udc.h
index 456899e..72b3537 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.h
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
@@ -306,6 +306,7 @@ struct usba_request {
 
 struct usba_udc_errata {
void (*toggle_bias)(struct usba_udc *udc, int is_on);
+   void (*pulse_bias)(struct usba_udc *udc);
 };
 
 struct usba_udc {
@@ -326,6 +327,7 @@ struct usba_udc {
struct clk *pclk;
struct clk *hclk;
struct usba_ep *usba_ep;
+   bool bias_pulse_needed;
 
u16 devstatus;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 4/5] usb: atmel_usba_udc: Mask status with enabled irqs

2015-01-12 Thread Boris Brezillon
Avoid interpreting useless status flags when we're not waiting for such
events by masking the status variable with the interrupt enabled register
value.

Reported-by: Patrice VILCHEZ 
Signed-off-by: Boris Brezillon 
Acked-by: Alexandre Belloni 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 55c8dde..bc3a532 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1612,12 +1612,14 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 
spin_lock(&udc->lock);
 
-   status = usba_readl(udc, INT_STA);
+   status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
+   usba_writel(udc, INT_ENB,
+   usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1631,6 +1633,8 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_WAKE_UP) {
toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
+   usba_writel(udc, INT_ENB,
+   usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 5/5] usb: gadget: atmel_usba: Cache INT_ENB register value

2015-01-12 Thread Boris Brezillon
Cache INT_ENB register value in order to avoid uncached iomem access, and
thus improve access time to INT_ENB value.

Signed-off-by: Boris Brezillon 
Acked-by: Alexandre Belloni 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 52 ++---
 drivers/usb/gadget/udc/atmel_usba_udc.h |  2 ++
 2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index bc3a532..6dfe17b 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -316,6 +316,17 @@ static inline void usba_cleanup_debugfs(struct usba_udc 
*udc)
 }
 #endif
 
+static inline u32 usba_int_enb_get(struct usba_udc *udc)
+{
+   return udc->int_enb_cache;
+}
+
+static inline void usba_int_enb_set(struct usba_udc *udc, u32 val)
+{
+   usba_writel(udc, INT_ENB, val);
+   udc->int_enb_cache = val;
+}
+
 static int vbus_is_present(struct usba_udc *udc)
 {
if (gpio_is_valid(udc->vbus_pin))
@@ -597,16 +608,14 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
if (ep->can_dma) {
u32 ctrl;
 
-   usba_writel(udc, INT_ENB,
-   (usba_readl(udc, INT_ENB)
-   | USBA_BF(EPT_INT, 1 << ep->index)
-   | USBA_BF(DMA_INT, 1 << ep->index)));
+   usba_int_enb_set(udc, usba_int_enb_get(udc) |
+ USBA_BF(EPT_INT, 1 << ep->index) |
+ USBA_BF(DMA_INT, 1 << ep->index));
ctrl = USBA_AUTO_VALID | USBA_INTDIS_DMA;
usba_ep_writel(ep, CTL_ENB, ctrl);
} else {
-   usba_writel(udc, INT_ENB,
-   (usba_readl(udc, INT_ENB)
-   | USBA_BF(EPT_INT, 1 << ep->index)));
+   usba_int_enb_set(udc, usba_int_enb_get(udc) |
+ USBA_BF(EPT_INT, 1 << ep->index));
}
 
spin_unlock_irqrestore(&udc->lock, flags);
@@ -614,7 +623,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
(unsigned long)usba_ep_readl(ep, CFG));
DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
-   (unsigned long)usba_readl(udc, INT_ENB));
+   (unsigned long)usba_int_enb_get(udc));
 
return 0;
 }
@@ -650,9 +659,8 @@ static int usba_ep_disable(struct usb_ep *_ep)
usba_dma_readl(ep, STATUS);
}
usba_ep_writel(ep, CTL_DIS, USBA_EPT_ENABLE);
-   usba_writel(udc, INT_ENB,
-   usba_readl(udc, INT_ENB)
-   & ~USBA_BF(EPT_INT, 1 << ep->index));
+   usba_int_enb_set(udc, usba_int_enb_get(udc) &
+ ~USBA_BF(EPT_INT, 1 << ep->index));
 
request_complete_list(ep, &req_list, -ESHUTDOWN);
 
@@ -1606,20 +1614,20 @@ static void usba_dma_irq(struct usba_udc *udc, struct 
usba_ep *ep)
 static irqreturn_t usba_udc_irq(int irq, void *devid)
 {
struct usba_udc *udc = devid;
-   u32 status;
+   u32 status, int_enb;
u32 dma_status;
u32 ep_status;
 
spin_lock(&udc->lock);
 
-   status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
+   int_enb = usba_int_enb_get(udc);
+   status = usba_readl(udc, INT_STA) & int_enb;
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
-   usba_writel(udc, INT_ENB,
-   usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
+   usba_int_enb_set(udc, int_enb | USBA_WAKE_UP);
udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1633,8 +1641,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_WAKE_UP) {
toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
-   usba_writel(udc, INT_ENB,
-   usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
+   usba_int_enb_set(udc, int_enb & ~USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
 
@@ -1702,11 +1709,8 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
| USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
usba_ep_writel(ep0, CTL_ENB,
 

[PATCH v3 0/5] usb: atmel_usba_udc: Rework errata handling

2015-01-12 Thread Boris Brezillon
Hello,

Here is a set of patches porting existing at91sam9rl erratum handling to
DT and adding new code to handle at91sam9g45/9x5 erratum.
It also adds several compatible strings to differentiate those errata.

These patches should be backported to 3.17 and 3.18 stable releases but
they do not apply cleanly on those stable branches.
I'll send a backport of this series once it is merged in mainline.

Regards,

Boris

Changes since v2:
- remove UTF8 character in commit message of patch 2

Changes since v1:
- cache INT_ENB value to speedup INT_ENB read operations

Boris Brezillon (5):
  usb: atmel_usba_udc: Rework at91sam9rl errata handling
  usb: atmel_usba_udc: Add at91sam9g45 and at91sam9x5 errata handling
  ARM: at91/dt: update udc compatible strings
  usb: atmel_usba_udc: Mask status with enabled irqs
  usb: gadget: atmel_usba: Cache INT_ENB register value

 .../devicetree/bindings/usb/atmel-usb.txt  |   5 +-
 arch/arm/boot/dts/at91sam9g45.dtsi |   2 +-
 arch/arm/boot/dts/at91sam9x5.dtsi  |   2 +-
 arch/arm/boot/dts/sama5d3.dtsi |   2 +-
 arch/arm/boot/dts/sama5d4.dtsi |   2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 146 +
 drivers/usb/gadget/udc/atmel_usba_udc.h|   9 ++
 7 files changed, 111 insertions(+), 57 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/5] usb: atmel_usba_udc: Rework at91sam9rl errata handling

2015-01-12 Thread Boris Brezillon
at91sam9rl SoC has an erratum forcing us to toggle the BIAS on USB
suspend/resume events.

This specific handling is only activated when CONFIG_ARCH_AT91SAM9RL is
set and this option is only set when building a non-DT kernel, which is
problematic since non-DT support for at91sam9rl SoC has been removed.

Rework the toggle_bias implementation to attach it to the "at91sam9rl-udc"
compatible string.

Add new compatible strings to avoid executing at91sam9rl erratum handling
on other SoCs.

Signed-off-by: Boris Brezillon 
Acked-by: Alexandre Belloni 
---
 .../devicetree/bindings/usb/atmel-usb.txt  |  5 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 78 --
 drivers/usb/gadget/udc/atmel_usba_udc.h|  5 ++
 3 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index bcc..38fee0f 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -51,7 +51,10 @@ usb1: gadget@fffa4000 {
 Atmel High-Speed USB device controller
 
 Required properties:
- - compatible: Should be "atmel,at91sam9rl-udc"
+ - compatible: Should be one of the following
+  "at91sam9rl-udc"
+  "at91sam9g45-udc"
+  "sama5d3-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain usba interrupt
  - ep childnode: To specify the number of endpoints and their properties.
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ce88237..36fd34b 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -324,28 +325,12 @@ static int vbus_is_present(struct usba_udc *udc)
return 1;
 }
 
-#if defined(CONFIG_ARCH_AT91SAM9RL)
-
-#include 
-
-static void toggle_bias(int is_on)
-{
-   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
-
-   if (is_on)
-   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
-   else
-   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
-}
-
-#else
-
-static void toggle_bias(int is_on)
+static void toggle_bias(struct usba_udc *udc, int is_on)
 {
+   if (udc->errata && udc->errata->toggle_bias)
+   udc->errata->toggle_bias(udc, is_on);
 }
 
-#endif /* CONFIG_ARCH_AT91SAM9RL */
-
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1620,7 +1605,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1632,7 +1617,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
}
 
if (status & USBA_WAKE_UP) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
@@ -1736,13 +1721,13 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
vbus = vbus_is_present(udc);
if (vbus != udc->vbus_prev) {
if (vbus) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
} else {
udc->gadget.speed = USB_SPEED_UNKNOWN;
reset_all_endpoints(udc);
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, CTRL, USBA_DISABLE_MASK);
if (udc->driver->disconnect) {
spin_unlock(&udc->lock);
@@ -1788,7 +1773,7 @@ static int atmel_usba_start(struct usb_gadget *gadget,
/* If Vbus is present, enable the controller and wait for reset */
spin_lock_irqsave(&udc->lock, flags);
if (vbus_is_present(udc) && udc->vbus_prev == 0) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
}
@@ -1811,7 +1796,7 @@ static int atmel_usba_stop(struct usb_gadget *gadget)
spin_unlock_irqrestore(&udc->lock, 

[PATCH v2 3/5] ARM: at91/dt: update udc compatible strings

2015-01-06 Thread Boris Brezillon
at91sam9g45, at91sam9x5 and sama5 SoCs should not use
"atmel,at91sam9rl-udc" for their USB device compatible property since
this compatible is attached to a specific hardware bug fix.

Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91sam9g45.dtsi | 2 +-
 arch/arm/boot/dts/at91sam9x5.dtsi  | 2 +-
 arch/arm/boot/dts/sama5d3.dtsi | 2 +-
 arch/arm/boot/dts/sama5d4.dtsi | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi 
b/arch/arm/boot/dts/at91sam9g45.dtsi
index 2a8da8a..acd90eb 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -1144,7 +1144,7 @@
usb2: gadget@fff78000 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,at91sam9g45-udc";
reg = <0x0060 0x8
   0xfff78000 0x400>;
interrupts = <27 IRQ_TYPE_LEVEL_HIGH 0>;
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi 
b/arch/arm/boot/dts/at91sam9x5.dtsi
index bbb3ba6..d213147 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -1057,7 +1057,7 @@
usb2: gadget@f803c000 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,at91sam9g45-udc";
reg = <0x0050 0x8
   0xf803c000 0x400>;
interrupts = <23 IRQ_TYPE_LEVEL_HIGH 0>;
diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
index 5f4144d..2b407a4 100644
--- a/arch/arm/boot/dts/sama5d3.dtsi
+++ b/arch/arm/boot/dts/sama5d3.dtsi
@@ -1264,7 +1264,7 @@
usb0: gadget@0050 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,sama5d3-udc";
reg = <0x0050 0x10
   0xf803 0x4000>;
interrupts = <33 IRQ_TYPE_LEVEL_HIGH 2>;
diff --git a/arch/arm/boot/dts/sama5d4.dtsi b/arch/arm/boot/dts/sama5d4.dtsi
index 1b0f30c..52dce24 100644
--- a/arch/arm/boot/dts/sama5d4.dtsi
+++ b/arch/arm/boot/dts/sama5d4.dtsi
@@ -112,7 +112,7 @@
usb0: gadget@0040 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,sama5d3-udc";
reg = <0x0040 0x10
   0xfc02c000 0x4000>;
interrupts = <47 IRQ_TYPE_LEVEL_HIGH 2>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/5] usb: atmel_usba_udc: Mask status with enabled irqs

2015-01-06 Thread Boris Brezillon
Avoid interpreting useless status flags when we're not waiting for such
events by masking the status variable with the interrupt enabled register
value.

Reported-by: Patrice VILCHEZ 
Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 55c8dde..bc3a532 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1612,12 +1612,14 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 
spin_lock(&udc->lock);
 
-   status = usba_readl(udc, INT_STA);
+   status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
+   usba_writel(udc, INT_ENB,
+   usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1631,6 +1633,8 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_WAKE_UP) {
toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
+   usba_writel(udc, INT_ENB,
+   usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/5] usb: atmel_usba_udc: Add at91sam9g45 and at91sam9x5 errata handling

2015-01-06 Thread Boris Brezillon
at91sam9g45 and at91sam9x5 SoCs have an hardware bug forcing us to
generate a pulse on the BIAS signal on "USB end of reset” and
“USB end of resume" events.

Reported-by: Patrice VILCHEZ 
Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 28 +++-
 drivers/usb/gadget/udc/atmel_usba_udc.h |  2 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 36fd34b..55c8dde 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -331,6 +331,17 @@ static void toggle_bias(struct usba_udc *udc, int is_on)
udc->errata->toggle_bias(udc, is_on);
 }
 
+static void generate_bias_pulse(struct usba_udc *udc)
+{
+   if (!udc->bias_pulse_needed)
+   return;
+
+   if (udc->errata && udc->errata->pulse_bias)
+   udc->errata->pulse_bias(udc);
+
+   udc->bias_pulse_needed = false;
+}
+
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1607,6 +1618,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
+   udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
&& udc->driver && udc->driver->suspend) {
@@ -1624,6 +1636,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 
if (status & USBA_END_OF_RESUME) {
usba_writel(udc, INT_CLR, USBA_END_OF_RESUME);
+   generate_bias_pulse(udc);
DBG(DBG_BUS, "Resume detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
&& udc->driver && udc->driver->resume) {
@@ -1659,6 +1672,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
struct usba_ep *ep0;
 
usba_writel(udc, INT_CLR, USBA_END_OF_RESET);
+   generate_bias_pulse(udc);
reset_all_endpoints(udc);
 
if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) {
@@ -1818,13 +1832,25 @@ static void at91sam9rl_toggle_bias(struct usba_udc 
*udc, int is_on)
at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
 }
 
+static void at91sam9g45_pulse_bias(struct usba_udc *udc)
+{
+   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
+
+   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
+   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
+}
+
 static const struct usba_udc_errata at91sam9rl_errata = {
.toggle_bias = at91sam9rl_toggle_bias,
 };
 
+static const struct usba_udc_errata at91sam9g45_errata = {
+   .pulse_bias = at91sam9g45_pulse_bias,
+};
+
 static const struct of_device_id atmel_udc_dt_ids[] = {
{ .compatible = "atmel,at91sam9rl-udc", .data = &at91sam9rl_errata },
-   { .compatible = "atmel,at91sam9g45-udc" },
+   { .compatible = "atmel,at91sam9g45-udc", .data = &at91sam9g45_errata },
{ .compatible = "atmel,sama5d3-udc" },
{ /* sentinel */ }
 };
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h 
b/drivers/usb/gadget/udc/atmel_usba_udc.h
index 456899e..72b3537 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.h
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
@@ -306,6 +306,7 @@ struct usba_request {
 
 struct usba_udc_errata {
void (*toggle_bias)(struct usba_udc *udc, int is_on);
+   void (*pulse_bias)(struct usba_udc *udc);
 };
 
 struct usba_udc {
@@ -326,6 +327,7 @@ struct usba_udc {
struct clk *pclk;
struct clk *hclk;
struct usba_ep *usba_ep;
+   bool bias_pulse_needed;
 
u16 devstatus;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 1/5] usb: atmel_usba_udc: Rework at91sam9rl errata handling

2015-01-06 Thread Boris Brezillon
at91sam9rl SoC has an erratum forcing us to toggle the BIAS on USB
suspend/resume events.

This specific handling is only activated when CONFIG_ARCH_AT91SAM9RL is
set and this option is only set when building a non-DT kernel, which is
problematic since non-DT support for at91sam9rl SoC has been removed.

Rework the toggle_bias implementation to attach it to the "at91sam9rl-udc"
compatible string.

Add new compatible strings to avoid executing at91sam9rl erratum handling
on other SoCs.

Signed-off-by: Boris Brezillon 
---
 .../devicetree/bindings/usb/atmel-usb.txt  |  5 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 78 --
 drivers/usb/gadget/udc/atmel_usba_udc.h|  5 ++
 3 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index bcc..38fee0f 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -51,7 +51,10 @@ usb1: gadget@fffa4000 {
 Atmel High-Speed USB device controller
 
 Required properties:
- - compatible: Should be "atmel,at91sam9rl-udc"
+ - compatible: Should be one of the following
+  "at91sam9rl-udc"
+  "at91sam9g45-udc"
+  "sama5d3-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain usba interrupt
  - ep childnode: To specify the number of endpoints and their properties.
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ce88237..36fd34b 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -324,28 +325,12 @@ static int vbus_is_present(struct usba_udc *udc)
return 1;
 }
 
-#if defined(CONFIG_ARCH_AT91SAM9RL)
-
-#include 
-
-static void toggle_bias(int is_on)
-{
-   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
-
-   if (is_on)
-   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
-   else
-   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
-}
-
-#else
-
-static void toggle_bias(int is_on)
+static void toggle_bias(struct usba_udc *udc, int is_on)
 {
+   if (udc->errata && udc->errata->toggle_bias)
+   udc->errata->toggle_bias(udc, is_on);
 }
 
-#endif /* CONFIG_ARCH_AT91SAM9RL */
-
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1620,7 +1605,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1632,7 +1617,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
}
 
if (status & USBA_WAKE_UP) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
@@ -1736,13 +1721,13 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
vbus = vbus_is_present(udc);
if (vbus != udc->vbus_prev) {
if (vbus) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
} else {
udc->gadget.speed = USB_SPEED_UNKNOWN;
reset_all_endpoints(udc);
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, CTRL, USBA_DISABLE_MASK);
if (udc->driver->disconnect) {
spin_unlock(&udc->lock);
@@ -1788,7 +1773,7 @@ static int atmel_usba_start(struct usb_gadget *gadget,
/* If Vbus is present, enable the controller and wait for reset */
spin_lock_irqsave(&udc->lock, flags);
if (vbus_is_present(udc) && udc->vbus_prev == 0) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
}
@@ -1811,7 +1796,7 @@ static int atmel_usba_stop(struct usb_gadget *gadget)
spin_unlock_irqrestore(&udc->lock, flags);
 
/* This will also disable 

[PATCH v2 5/5] usb: gadget: atmel_usba: Cache INT_ENB register value

2015-01-06 Thread Boris Brezillon
Cache INT_ENB register value in order to avoid uncached iomem access, and
thus improve access time to INT_ENB value.

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 52 ++---
 drivers/usb/gadget/udc/atmel_usba_udc.h |  2 ++
 2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index bc3a532..6dfe17b 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -316,6 +316,17 @@ static inline void usba_cleanup_debugfs(struct usba_udc 
*udc)
 }
 #endif
 
+static inline u32 usba_int_enb_get(struct usba_udc *udc)
+{
+   return udc->int_enb_cache;
+}
+
+static inline void usba_int_enb_set(struct usba_udc *udc, u32 val)
+{
+   usba_writel(udc, INT_ENB, val);
+   udc->int_enb_cache = val;
+}
+
 static int vbus_is_present(struct usba_udc *udc)
 {
if (gpio_is_valid(udc->vbus_pin))
@@ -597,16 +608,14 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
if (ep->can_dma) {
u32 ctrl;
 
-   usba_writel(udc, INT_ENB,
-   (usba_readl(udc, INT_ENB)
-   | USBA_BF(EPT_INT, 1 << ep->index)
-   | USBA_BF(DMA_INT, 1 << ep->index)));
+   usba_int_enb_set(udc, usba_int_enb_get(udc) |
+ USBA_BF(EPT_INT, 1 << ep->index) |
+ USBA_BF(DMA_INT, 1 << ep->index));
ctrl = USBA_AUTO_VALID | USBA_INTDIS_DMA;
usba_ep_writel(ep, CTL_ENB, ctrl);
} else {
-   usba_writel(udc, INT_ENB,
-   (usba_readl(udc, INT_ENB)
-   | USBA_BF(EPT_INT, 1 << ep->index)));
+   usba_int_enb_set(udc, usba_int_enb_get(udc) |
+ USBA_BF(EPT_INT, 1 << ep->index));
}
 
spin_unlock_irqrestore(&udc->lock, flags);
@@ -614,7 +623,7 @@ usba_ep_enable(struct usb_ep *_ep, const struct 
usb_endpoint_descriptor *desc)
DBG(DBG_HW, "EPT_CFG%d after init: %#08lx\n", ep->index,
(unsigned long)usba_ep_readl(ep, CFG));
DBG(DBG_HW, "INT_ENB after init: %#08lx\n",
-   (unsigned long)usba_readl(udc, INT_ENB));
+   (unsigned long)usba_int_enb_get(udc));
 
return 0;
 }
@@ -650,9 +659,8 @@ static int usba_ep_disable(struct usb_ep *_ep)
usba_dma_readl(ep, STATUS);
}
usba_ep_writel(ep, CTL_DIS, USBA_EPT_ENABLE);
-   usba_writel(udc, INT_ENB,
-   usba_readl(udc, INT_ENB)
-   & ~USBA_BF(EPT_INT, 1 << ep->index));
+   usba_int_enb_set(udc, usba_int_enb_get(udc) &
+ ~USBA_BF(EPT_INT, 1 << ep->index));
 
request_complete_list(ep, &req_list, -ESHUTDOWN);
 
@@ -1606,20 +1614,20 @@ static void usba_dma_irq(struct usba_udc *udc, struct 
usba_ep *ep)
 static irqreturn_t usba_udc_irq(int irq, void *devid)
 {
struct usba_udc *udc = devid;
-   u32 status;
+   u32 status, int_enb;
u32 dma_status;
u32 ep_status;
 
spin_lock(&udc->lock);
 
-   status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
+   int_enb = usba_int_enb_get(udc);
+   status = usba_readl(udc, INT_STA) & int_enb;
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
-   usba_writel(udc, INT_ENB,
-   usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
+   usba_int_enb_set(udc, int_enb | USBA_WAKE_UP);
udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1633,8 +1641,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_WAKE_UP) {
toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
-   usba_writel(udc, INT_ENB,
-   usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
+   usba_int_enb_set(udc, int_enb & ~USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
 
@@ -1702,11 +1709,8 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
| USBA_BF(BK_NUMBER, USBA_BK_NUMBER_ONE)));
usba_ep_writel(ep0, CTL_ENB,
USBA_EPT_ENABLE | USBA_RX_SETUP);
-  

[PATCH v2 0/5] usb: atmel_usba_udc: Rework errata handling

2015-01-06 Thread Boris Brezillon
Hello,

Here is a set of patches porting existing at91sam9rl erratum handling to
DT and adding new code to handle at91sam9g45/9x5 erratum.
It also adds several compatible strings to differentiate those errata.

These patches should be backported to 3.17 and 3.18 stable releases but
they do not apply cleanly on those stable branches.
I'll send a backport of this series once it is merged in mainline.

Regards,

Boris

Changes since v1:
- cache INT_ENB value to speedup INT_ENB read operations

Boris Brezillon (5):
  usb: atmel_usba_udc: Rework at91sam9rl errata handling
  usb: atmel_usba_udc: Add at91sam9g45 and at91sam9x5 errata handling
  ARM: at91/dt: update udc compatible strings
  usb: atmel_usba_udc: Mask status with enabled irqs
  usb: gadget: atmel_usba: Cache INT_ENB register value

 .../devicetree/bindings/usb/atmel-usb.txt  |   5 +-
 arch/arm/boot/dts/at91sam9g45.dtsi |   2 +-
 arch/arm/boot/dts/at91sam9x5.dtsi  |   2 +-
 arch/arm/boot/dts/sama5d3.dtsi |   2 +-
 arch/arm/boot/dts/sama5d4.dtsi |   2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 146 +
 drivers/usb/gadget/udc/atmel_usba_udc.h|   9 ++
 7 files changed, 111 insertions(+), 57 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/4] usb: atmel_usba_udc: mask status with enabled irqs

2014-12-15 Thread Boris Brezillon
On Mon, 15 Dec 2014 17:22:04 +
David Laight  wrote:

> From: Boris Brezillon
> > Hi David,
> > 
> > On Mon, 15 Dec 2014 13:34:56 +
> > David Laight  wrote:
> > 
> > > From: Sergei Shtylyov
> > > > Hello.
> > > >
> > > > On 12/15/2014 4:03 PM, Boris Brezillon wrote:
> > > >
> > > > > Avoid interpreting useless status flags when we're not waiting for 
> > > > > such
> > > > > events by masking the status variable with the interrupt enabled 
> > > > > register
> > > > > value.
> > > >
> > > > > Reported-by: Patrice VILCHEZ 
> > > > > Signed-off-by: Boris Brezillon 
> > > > > ---
> > > > >   drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +-
> > > > >   1 file changed, 5 insertions(+), 1 deletion(-)
> > > >
> > > > > diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> > > > > b/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > > > index 55c8dde..bc3a532 100644
> > > > > --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > > > +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > > > @@ -1612,12 +1612,14 @@ static irqreturn_t usba_udc_irq(int irq, void 
> > > > > *devid)
> > > > >
> > > > >   spin_lock(&udc->lock);
> > > > >
> > > > > - status = usba_readl(udc, INT_STA);
> > > > > + status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
> ...
> > > > Looks like t make sense to read the INT_ENB register into a separate
> > > > variable, to save on extra reads?
> > >
> > >
> > > Better still remember the written value in one of the structures so
> > > that it doesn't have to be read at all.
> > 
> > Hmm, I'm getting back to this suggestion.
> > While I definitely understand why I should use a local variable to
> > store INT_ENB value in usba_udc_irq, I don't see the point of mirroring
> > INT_EN status in an udc struct field (after all, INT_EN will always
> > contain the value we previously set).
> 
> This is exactly why it makes sense to mirror it locally.

Absolutely.

> 
> > Is this a performance concern ?
> 
> Absolutely, you really don't want to know how many cpu cycles it is
> likely to take to do a read from an io device.
> At best it is a uncached read of a fast on-chip peripheral.
> If you are reading from a PCIe device then you are looking at hundreds
> (if not thousands) of cpu clock cycles.

I know there is a perf penalty when accessing IO memory regions (in this
case an uncached memory access) compared to standard memory accesses (in
other words a cached accesses), just don't know the exact numbers.
My point was, is the performance improvement worth the addition of this
new field and the code modification (addition of a wrapper function to
modify the interrupt register) ?

I take your answer as a yes ;-).

Thanks,

Boris


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/4] usb: atmel_usba_udc: mask status with enabled irqs

2014-12-15 Thread Boris Brezillon
Hi David,

On Mon, 15 Dec 2014 13:34:56 +
David Laight  wrote:

> From: Sergei Shtylyov
> > Hello.
> > 
> > On 12/15/2014 4:03 PM, Boris Brezillon wrote:
> > 
> > > Avoid interpreting useless status flags when we're not waiting for such
> > > events by masking the status variable with the interrupt enabled register
> > > value.
> > 
> > > Reported-by: Patrice VILCHEZ 
> > > Signed-off-by: Boris Brezillon 
> > > ---
> > >   drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +-
> > >   1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > > diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> > > b/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > index 55c8dde..bc3a532 100644
> > > --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > @@ -1612,12 +1612,14 @@ static irqreturn_t usba_udc_irq(int irq, void 
> > > *devid)
> > >
> > >   spin_lock(&udc->lock);
> > >
> > > - status = usba_readl(udc, INT_STA);
> > > + status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
> > >   DBG(DBG_INT, "irq, status=%#08x\n", status);
> > >
> > >   if (status & USBA_DET_SUSPEND) {
> > >   toggle_bias(udc, 0);
> > >   usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
> > > + usba_writel(udc, INT_ENB,
> > > + usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
> > >   udc->bias_pulse_needed = true;
> > >   DBG(DBG_BUS, "Suspend detected\n");
> > >   if (udc->gadget.speed != USB_SPEED_UNKNOWN
> > > @@ -1631,6 +1633,8 @@ static irqreturn_t usba_udc_irq(int irq, void 
> > > *devid)
> > >   if (status & USBA_WAKE_UP) {
> > >   toggle_bias(udc, 1);
> > >   usba_writel(udc, INT_CLR, USBA_WAKE_UP);
> > > + usba_writel(udc, INT_ENB,
> > > + usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
> > >   DBG(DBG_BUS, "Wake Up CPU detected\n");
> > >   }
> > 
> > Looks like t make sense to read the INT_ENB register into a separate
> > variable, to save on extra reads?
> 
> 
> Better still remember the written value in one of the structures so
> that it doesn't have to be read at all.

Hmm, I'm getting back to this suggestion.
While I definitely understand why I should use a local variable to
store INT_ENB value in usba_udc_irq, I don't see the point of mirroring
INT_EN status in an udc struct field (after all, INT_EN will always
contain the value we previously set).
Is this a performance concern ?

Regards,

Boris


-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 4/4] usb: atmel_usba_udc: mask status with enabled irqs

2014-12-15 Thread Boris Brezillon
On Mon, 15 Dec 2014 13:34:56 +
David Laight  wrote:

> From: Sergei Shtylyov
> > Hello.
> > 
> > On 12/15/2014 4:03 PM, Boris Brezillon wrote:
> > 
> > > Avoid interpreting useless status flags when we're not waiting for such
> > > events by masking the status variable with the interrupt enabled register
> > > value.
> > 
> > > Reported-by: Patrice VILCHEZ 
> > > Signed-off-by: Boris Brezillon 
> > > ---
> > >   drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +-
> > >   1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > > diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
> > > b/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > index 55c8dde..bc3a532 100644
> > > --- a/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
> > > @@ -1612,12 +1612,14 @@ static irqreturn_t usba_udc_irq(int irq, void 
> > > *devid)
> > >
> > >   spin_lock(&udc->lock);
> > >
> > > - status = usba_readl(udc, INT_STA);
> > > + status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
> > >   DBG(DBG_INT, "irq, status=%#08x\n", status);
> > >
> > >   if (status & USBA_DET_SUSPEND) {
> > >   toggle_bias(udc, 0);
> > >   usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
> > > + usba_writel(udc, INT_ENB,
> > > + usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
> > >   udc->bias_pulse_needed = true;
> > >   DBG(DBG_BUS, "Suspend detected\n");
> > >   if (udc->gadget.speed != USB_SPEED_UNKNOWN
> > > @@ -1631,6 +1633,8 @@ static irqreturn_t usba_udc_irq(int irq, void 
> > > *devid)
> > >   if (status & USBA_WAKE_UP) {
> > >   toggle_bias(udc, 1);
> > >   usba_writel(udc, INT_CLR, USBA_WAKE_UP);
> > > + usba_writel(udc, INT_ENB,
> > > + usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
> > >   DBG(DBG_BUS, "Wake Up CPU detected\n");
> > >   }
> > 
> > Looks like t make sense to read the INT_ENB register into a separate
> > variable, to save on extra reads?
> 
> 
> Better still remember the written value in one of the structures so
> that it doesn't have to be read at all.

Sure, I'll modify the code accordingly.

Thanks,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 3/4] ARM: at91/dt: update udc compatible strings

2014-12-15 Thread Boris Brezillon
at91sam9g45, at91sam9x5 and sama5 SoCs should not use
"atmel,at91sam9rl-udc" for their USB device compatible property since
this compatible is attached to a specific hardware bug fix.

Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91sam9g45.dtsi | 2 +-
 arch/arm/boot/dts/at91sam9x5.dtsi  | 2 +-
 arch/arm/boot/dts/sama5d3.dtsi | 2 +-
 arch/arm/boot/dts/sama5d4.dtsi | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9g45.dtsi 
b/arch/arm/boot/dts/at91sam9g45.dtsi
index 6c0637a..cf53155 100644
--- a/arch/arm/boot/dts/at91sam9g45.dtsi
+++ b/arch/arm/boot/dts/at91sam9g45.dtsi
@@ -1112,7 +1112,7 @@
usb2: gadget@fff78000 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,at91sam9g45-udc";
reg = <0x0060 0x8
   0xfff78000 0x400>;
interrupts = <27 IRQ_TYPE_LEVEL_HIGH 0>;
diff --git a/arch/arm/boot/dts/at91sam9x5.dtsi 
b/arch/arm/boot/dts/at91sam9x5.dtsi
index bbb3ba6..d213147 100644
--- a/arch/arm/boot/dts/at91sam9x5.dtsi
+++ b/arch/arm/boot/dts/at91sam9x5.dtsi
@@ -1057,7 +1057,7 @@
usb2: gadget@f803c000 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,at91sam9g45-udc";
reg = <0x0050 0x8
   0xf803c000 0x400>;
interrupts = <23 IRQ_TYPE_LEVEL_HIGH 0>;
diff --git a/arch/arm/boot/dts/sama5d3.dtsi b/arch/arm/boot/dts/sama5d3.dtsi
index 5f4144d..2b407a4 100644
--- a/arch/arm/boot/dts/sama5d3.dtsi
+++ b/arch/arm/boot/dts/sama5d3.dtsi
@@ -1264,7 +1264,7 @@
usb0: gadget@0050 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,sama5d3-udc";
reg = <0x0050 0x10
   0xf803 0x4000>;
interrupts = <33 IRQ_TYPE_LEVEL_HIGH 2>;
diff --git a/arch/arm/boot/dts/sama5d4.dtsi b/arch/arm/boot/dts/sama5d4.dtsi
index e0157b0..0896efe 100644
--- a/arch/arm/boot/dts/sama5d4.dtsi
+++ b/arch/arm/boot/dts/sama5d4.dtsi
@@ -111,7 +111,7 @@
usb0: gadget@0040 {
#address-cells = <1>;
#size-cells = <0>;
-   compatible = "atmel,at91sam9rl-udc";
+   compatible = "atmel,sama5d3-udc";
reg = <0x0040 0x10
   0xfc02c000 0x4000>;
interrupts = <47 IRQ_TYPE_LEVEL_HIGH 2>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 4/4] usb: atmel_usba_udc: mask status with enabled irqs

2014-12-15 Thread Boris Brezillon
Avoid interpreting useless status flags when we're not waiting for such
events by masking the status variable with the interrupt enabled register
value.

Reported-by: Patrice VILCHEZ 
Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 55c8dde..bc3a532 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1612,12 +1612,14 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 
spin_lock(&udc->lock);
 
-   status = usba_readl(udc, INT_STA);
+   status = usba_readl(udc, INT_STA) & usba_readl(udc, INT_ENB);
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
+   usba_writel(udc, INT_ENB,
+   usba_readl(udc, INT_ENB) | USBA_WAKE_UP);
udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1631,6 +1633,8 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_WAKE_UP) {
toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
+   usba_writel(udc, INT_ENB,
+   usba_readl(udc, INT_ENB) & ~USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/4] usb: atmel_usba_udc: Add at91sam9g45 and at91sam9x5 errata handling

2014-12-15 Thread Boris Brezillon
at91sam9g45 and at91sam9x5 SoCs have an hardware bug forcing us to
generate a pulse on the BIAS signal on "USB end of reset” and
“USB end of resume" events.

Reported-by: Patrice VILCHEZ 
Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 28 +++-
 drivers/usb/gadget/udc/atmel_usba_udc.h |  2 ++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 36fd34b..55c8dde 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -331,6 +331,17 @@ static void toggle_bias(struct usba_udc *udc, int is_on)
udc->errata->toggle_bias(udc, is_on);
 }
 
+static void generate_bias_pulse(struct usba_udc *udc)
+{
+   if (!udc->bias_pulse_needed)
+   return;
+
+   if (udc->errata && udc->errata->pulse_bias)
+   udc->errata->pulse_bias(udc);
+
+   udc->bias_pulse_needed = false;
+}
+
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1607,6 +1618,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
if (status & USBA_DET_SUSPEND) {
toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
+   udc->bias_pulse_needed = true;
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
&& udc->driver && udc->driver->suspend) {
@@ -1624,6 +1636,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
 
if (status & USBA_END_OF_RESUME) {
usba_writel(udc, INT_CLR, USBA_END_OF_RESUME);
+   generate_bias_pulse(udc);
DBG(DBG_BUS, "Resume detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
&& udc->driver && udc->driver->resume) {
@@ -1659,6 +1672,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
struct usba_ep *ep0;
 
usba_writel(udc, INT_CLR, USBA_END_OF_RESET);
+   generate_bias_pulse(udc);
reset_all_endpoints(udc);
 
if (udc->gadget.speed != USB_SPEED_UNKNOWN && udc->driver) {
@@ -1818,13 +1832,25 @@ static void at91sam9rl_toggle_bias(struct usba_udc 
*udc, int is_on)
at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
 }
 
+static void at91sam9g45_pulse_bias(struct usba_udc *udc)
+{
+   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
+
+   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
+   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
+}
+
 static const struct usba_udc_errata at91sam9rl_errata = {
.toggle_bias = at91sam9rl_toggle_bias,
 };
 
+static const struct usba_udc_errata at91sam9g45_errata = {
+   .pulse_bias = at91sam9g45_pulse_bias,
+};
+
 static const struct of_device_id atmel_udc_dt_ids[] = {
{ .compatible = "atmel,at91sam9rl-udc", .data = &at91sam9rl_errata },
-   { .compatible = "atmel,at91sam9g45-udc" },
+   { .compatible = "atmel,at91sam9g45-udc", .data = &at91sam9g45_errata },
{ .compatible = "atmel,sama5d3-udc" },
{ /* sentinel */ }
 };
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.h 
b/drivers/usb/gadget/udc/atmel_usba_udc.h
index 456899e..72b3537 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.h
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.h
@@ -306,6 +306,7 @@ struct usba_request {
 
 struct usba_udc_errata {
void (*toggle_bias)(struct usba_udc *udc, int is_on);
+   void (*pulse_bias)(struct usba_udc *udc);
 };
 
 struct usba_udc {
@@ -326,6 +327,7 @@ struct usba_udc {
struct clk *pclk;
struct clk *hclk;
struct usba_ep *usba_ep;
+   bool bias_pulse_needed;
 
u16 devstatus;
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 0/4] usb: atmel_usba_udc: Rework errata handling

2014-12-15 Thread Boris Brezillon
Hello,

Here is a set of patches porting existing at91sam9rl erratum handling to
DT and adding new code to handle at91sam9g45/9x5 erratum.
It also adds several compatible strings to differentiate those errata.

These patches should be backported to 3.17 and 3.18 stable releases but
they do not apply cleanly on those stable branches.
I'll send a backport of this series once it is merged in mainline.

Regards,

Boris


Boris Brezillon (4):
  usb: atmel_usba_udc: Rework at91sam9rl errata handling
  usb: atmel_usba_udc: Add at91sam9g45 and at91sam9x5 errata handling
  ARM: at91/dt: update udc compatible strings
  usb: atmel_usba_udc: mask status with enabled irqs

 .../devicetree/bindings/usb/atmel-usb.txt  |   5 +-
 arch/arm/boot/dts/at91sam9g45.dtsi |   2 +-
 arch/arm/boot/dts/at91sam9x5.dtsi  |   2 +-
 arch/arm/boot/dts/sama5d3.dtsi |   2 +-
 arch/arm/boot/dts/sama5d4.dtsi |   2 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 104 ++---
 drivers/usb/gadget/udc/atmel_usba_udc.h|   7 ++
 7 files changed, 86 insertions(+), 38 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 1/4] usb: atmel_usba_udc: Rework at91sam9rl errata handling

2014-12-15 Thread Boris Brezillon
at91sam9rl SoC has an erratum forcing us to toggle the BIAS on USB
suspend/resume events.

This specific handling is only activated when CONFIG_ARCH_AT91SAM9RL is
set and this option is only set when building a non-DT kernel, which is
problematic since non-DT support for at91sam9rl SoC has been removed.

Rework the toggle_bias implementation to attach it to the "at91sam9rl-udc"
compatible string.

Add new compatible strings to avoid executing at91sam9rl erratum handling
on other SoCs.

Signed-off-by: Boris Brezillon 
---
 .../devicetree/bindings/usb/atmel-usb.txt  |  5 +-
 drivers/usb/gadget/udc/atmel_usba_udc.c| 78 --
 drivers/usb/gadget/udc/atmel_usba_udc.h|  5 ++
 3 files changed, 52 insertions(+), 36 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index bcc..38fee0f 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -51,7 +51,10 @@ usb1: gadget@fffa4000 {
 Atmel High-Speed USB device controller
 
 Required properties:
- - compatible: Should be "atmel,at91sam9rl-udc"
+ - compatible: Should be one of the following
+  "at91sam9rl-udc"
+  "at91sam9g45-udc"
+  "sama5d3-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain usba interrupt
  - ep childnode: To specify the number of endpoints and their properties.
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c 
b/drivers/usb/gadget/udc/atmel_usba_udc.c
index ce88237..36fd34b 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -8,6 +8,7 @@
  * published by the Free Software Foundation.
  */
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -324,28 +325,12 @@ static int vbus_is_present(struct usba_udc *udc)
return 1;
 }
 
-#if defined(CONFIG_ARCH_AT91SAM9RL)
-
-#include 
-
-static void toggle_bias(int is_on)
-{
-   unsigned int uckr = at91_pmc_read(AT91_CKGR_UCKR);
-
-   if (is_on)
-   at91_pmc_write(AT91_CKGR_UCKR, uckr | AT91_PMC_BIASEN);
-   else
-   at91_pmc_write(AT91_CKGR_UCKR, uckr & ~(AT91_PMC_BIASEN));
-}
-
-#else
-
-static void toggle_bias(int is_on)
+static void toggle_bias(struct usba_udc *udc, int is_on)
 {
+   if (udc->errata && udc->errata->toggle_bias)
+   udc->errata->toggle_bias(udc, is_on);
 }
 
-#endif /* CONFIG_ARCH_AT91SAM9RL */
-
 static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
 {
unsigned int transaction_len;
@@ -1620,7 +1605,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
DBG(DBG_INT, "irq, status=%#08x\n", status);
 
if (status & USBA_DET_SUSPEND) {
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, INT_CLR, USBA_DET_SUSPEND);
DBG(DBG_BUS, "Suspend detected\n");
if (udc->gadget.speed != USB_SPEED_UNKNOWN
@@ -1632,7 +1617,7 @@ static irqreturn_t usba_udc_irq(int irq, void *devid)
}
 
if (status & USBA_WAKE_UP) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, INT_CLR, USBA_WAKE_UP);
DBG(DBG_BUS, "Wake Up CPU detected\n");
}
@@ -1736,13 +1721,13 @@ static irqreturn_t usba_vbus_irq(int irq, void *devid)
vbus = vbus_is_present(udc);
if (vbus != udc->vbus_prev) {
if (vbus) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
} else {
udc->gadget.speed = USB_SPEED_UNKNOWN;
reset_all_endpoints(udc);
-   toggle_bias(0);
+   toggle_bias(udc, 0);
usba_writel(udc, CTRL, USBA_DISABLE_MASK);
if (udc->driver->disconnect) {
spin_unlock(&udc->lock);
@@ -1788,7 +1773,7 @@ static int atmel_usba_start(struct usb_gadget *gadget,
/* If Vbus is present, enable the controller and wait for reset */
spin_lock_irqsave(&udc->lock, flags);
if (vbus_is_present(udc) && udc->vbus_prev == 0) {
-   toggle_bias(1);
+   toggle_bias(udc, 1);
usba_writel(udc, CTRL, USBA_ENABLE_MASK);
usba_writel(udc, INT_ENB, USBA_END_OF_RESET);
}
@@ -1811,7 +1796,7 @@ static int atmel_usba_stop(struct usb_gadget *gadget)
spin_unlock_irqrestore(&udc->lock, flags);
 
/* This will also disable 

[PATCH 01/11] usb: gadget: at91_udc: Fix clock names

2014-12-03 Thread Boris Brezillon
The driver is requesting clock by their global name (those declared in the
clk_lookup list), but this only works with !CCF kernels.

Now that all SoCs have moved to CCF, fix the driver to use local names
(hclk and pclk).

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/at91_udc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c 
b/drivers/usb/gadget/udc/at91_udc.c
index 0716c19..ca6a4b8 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1766,8 +1766,8 @@ static int at91udc_probe(struct platform_device *pdev)
udc_reinit(udc);
 
/* get interface and function clocks */
-   udc->iclk = clk_get(dev, "udc_clk");
-   udc->fclk = clk_get(dev, "udpck");
+   udc->iclk = clk_get(dev, "pclk");
+   udc->fclk = clk_get(dev, "hclk");
if (IS_ENABLED(CONFIG_COMMON_CLK))
udc->uclk = clk_get(dev, "usb_clk");
if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) ||
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/11] usb: gadget: at91_udc: Document DT clocks and clock-names property

2014-12-03 Thread Boris Brezillon
The at91_udc driver request 2 clocks, and thus need them to be defined in
the device tree.
Document the clocks and clock-names properties so that everybody use the
correct names.

Signed-off-by: Boris Brezillon 
---
 Documentation/devicetree/bindings/usb/atmel-usb.txt | 4 
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index bcc..6007231 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -36,6 +36,10 @@ Required properties:
  - compatible: Should be "atmel,at91rm9200-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain macb interrupt
+ - clocks: Should reference the peripheral and the AHB clocks
+ - clock-names: Should contains two strings
+   "pclk" for the peripheral clock
+   "hclk" for the AHB clock
 
 Optional properties:
  - atmel,vbus-gpio: If present, specifies a gpio that needs to be
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/11] usb: gadget: at91_udc: Drop uclk clock

2014-12-03 Thread Boris Brezillon
Now that at91 system clocks forward set_rate request to their parent we
can remove the uclk clock and directly call clk_set_rate on fclk.

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/at91_udc.c | 27 +++
 drivers/usb/gadget/udc/at91_udc.h |  2 +-
 2 files changed, 4 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c 
b/drivers/usb/gadget/udc/at91_udc.c
index ca6a4b8..4ecb576 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -870,8 +870,6 @@ static void clk_on(struct at91_udc *udc)
return;
udc->clocked = 1;
 
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_enable(udc->uclk);
clk_enable(udc->iclk);
clk_enable(udc->fclk);
 }
@@ -884,8 +882,6 @@ static void clk_off(struct at91_udc *udc)
udc->gadget.speed = USB_SPEED_UNKNOWN;
clk_disable(udc->fclk);
clk_disable(udc->iclk);
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_disable(udc->uclk);
 }
 
 /*
@@ -1768,25 +1764,17 @@ static int at91udc_probe(struct platform_device *pdev)
/* get interface and function clocks */
udc->iclk = clk_get(dev, "pclk");
udc->fclk = clk_get(dev, "hclk");
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   udc->uclk = clk_get(dev, "usb_clk");
-   if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk) ||
-   (IS_ENABLED(CONFIG_COMMON_CLK) && IS_ERR(udc->uclk))) {
+   if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
DBG("clocks missing\n");
retval = -ENODEV;
goto fail1;
}
 
/* don't do anything until we have both gadget driver and VBUS */
-   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   clk_set_rate(udc->uclk, 4800);
-   retval = clk_prepare(udc->uclk);
-   if (retval)
-   goto fail1;
-   }
+   clk_set_rate(udc->fclk, 4800);
retval = clk_prepare(udc->fclk);
if (retval)
-   goto fail1a;
+   goto fail1;
 
retval = clk_prepare_enable(udc->iclk);
if (retval)
@@ -1860,12 +1848,7 @@ fail1c:
clk_unprepare(udc->iclk);
 fail1b:
clk_unprepare(udc->fclk);
-fail1a:
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_unprepare(udc->uclk);
 fail1:
-   if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk))
-   clk_put(udc->uclk);
if (!IS_ERR(udc->fclk))
clk_put(udc->fclk);
if (!IS_ERR(udc->iclk))
@@ -1911,15 +1894,11 @@ static int __exit at91udc_remove(struct platform_device 
*pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
release_mem_region(res->start, resource_size(res));
 
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_unprepare(udc->uclk);
clk_unprepare(udc->fclk);
clk_unprepare(udc->iclk);
 
clk_put(udc->iclk);
clk_put(udc->fclk);
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(udc->uclk);
 
return 0;
 }
diff --git a/drivers/usb/gadget/udc/at91_udc.h 
b/drivers/usb/gadget/udc/at91_udc.h
index 0175246..e647d1c 100644
--- a/drivers/usb/gadget/udc/at91_udc.h
+++ b/drivers/usb/gadget/udc/at91_udc.h
@@ -126,7 +126,7 @@ struct at91_udc {
unsignedactive_suspend:1;
u8  addr;
struct at91_udc_databoard;
-   struct clk  *iclk, *fclk, *uclk;
+   struct clk  *iclk, *fclk;
struct platform_device  *pdev;
struct proc_dir_entry   *pde;
void __iomem*udp_baseaddr;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/11] usb: gadget: at91_udc: Simplify probe and remove functions

2014-12-03 Thread Boris Brezillon
Make use of devm_ functions to simplify probe and remove code.

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/at91_udc.c | 116 +-
 1 file changed, 39 insertions(+), 77 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c 
b/drivers/usb/gadget/udc/at91_udc.c
index e7984c0..ef1ee07 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1697,15 +1697,6 @@ static int at91udc_probe(struct platform_device *pdev)
int retval;
struct resource *res;
 
-   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   if (!res)
-   return -ENXIO;
-
-   if (!request_mem_region(res->start, resource_size(res), driver_name)) {
-   DBG("someone's using UDC memory\n");
-   return -EBUSY;
-   }
-
/* init software state */
udc = &controller;
udc->gadget.dev.parent = dev;
@@ -1718,13 +1709,13 @@ static int at91udc_probe(struct platform_device *pdev)
if (cpu_is_at91rm9200()) {
if (!gpio_is_valid(udc->board.pullup_pin)) {
DBG("no D+ pullup?\n");
-   retval = -ENODEV;
-   goto fail0;
+   return -ENODEV;
}
-   retval = gpio_request(udc->board.pullup_pin, "udc_pullup");
+   retval = devm_gpio_request(dev, udc->board.pullup_pin,
+  "udc_pullup");
if (retval) {
DBG("D+ pullup is busy\n");
-   goto fail0;
+   return retval;
}
gpio_direction_output(udc->board.pullup_pin,
udc->board.pullup_active_low);
@@ -1743,32 +1734,32 @@ static int at91udc_probe(struct platform_device *pdev)
udc->ep[3].maxpacket = 64;
}
 
-   udc->udp_baseaddr = ioremap(res->start, resource_size(res));
-   if (!udc->udp_baseaddr) {
-   retval = -ENOMEM;
-   goto fail0a;
-   }
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   udc->udp_baseaddr = devm_ioremap_resource(dev, res);
+   if (IS_ERR(udc->udp_baseaddr))
+   return PTR_ERR(udc->udp_baseaddr);
 
udc_reinit(udc);
 
/* get interface and function clocks */
-   udc->iclk = clk_get(dev, "pclk");
-   udc->fclk = clk_get(dev, "hclk");
-   if (IS_ERR(udc->iclk) || IS_ERR(udc->fclk)) {
-   DBG("clocks missing\n");
-   retval = -ENODEV;
-   goto fail1;
-   }
+   udc->iclk = devm_clk_get(dev, "pclk");
+   if (IS_ERR(udc->iclk))
+   return PTR_ERR(udc->iclk);
+
+   udc->fclk = devm_clk_get(dev, "hclk");
+   if (IS_ERR(udc->fclk))
+   return PTR_ERR(udc->fclk);
 
/* don't do anything until we have both gadget driver and VBUS */
clk_set_rate(udc->fclk, 4800);
retval = clk_prepare(udc->fclk);
if (retval)
-   goto fail1;
+   return retval;
 
retval = clk_prepare_enable(udc->iclk);
if (retval)
-   goto fail1b;
+   goto err_unprepare_fclk;
+
at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
at91_udp_write(udc, AT91_UDP_IDR, 0x);
/* Clear all pending interrupts - UDP may be used by bootloader. */
@@ -1777,18 +1768,21 @@ static int at91udc_probe(struct platform_device *pdev)
 
/* request UDC and maybe VBUS irqs */
udc->udp_irq = platform_get_irq(pdev, 0);
-   retval = request_irq(udc->udp_irq, at91_udc_irq,
-   0, driver_name, udc);
-   if (retval < 0) {
+   retval = devm_request_irq(dev, udc->udp_irq, at91_udc_irq, 0,
+ driver_name, udc);
+   if (retval) {
DBG("request irq %d failed\n", udc->udp_irq);
-   goto fail1c;
+   goto err_unprepare_iclk;
}
+
if (gpio_is_valid(udc->board.vbus_pin)) {
-   retval = gpio_request(udc->board.vbus_pin, "udc_vbus");
-   if (retval < 0) {
+   retval = devm_gpio_request(dev, udc->board.vbus_pin,
+  "udc_vbus");
+   if (retval) {
DBG("request vbus pin failed\n");
-   goto fail2;
+   goto err_unprepare_iclk;
}
+
gpio_direction_input(udc->board.vbus_pin);
 
/*
@@ -1805,12 +1799,13 @@ static int at91udc_probe(struct platform_device *pdev)
  

[PATCH 04/11] ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc definition

2014-12-03 Thread Boris Brezillon
Peripheral clock is named pclk and system clock is named hclk (those are
the names expected by the at91_udc driver).

Drop the deprecated usb_clk (formerly used to configure the usb clock rate
which is now directly configurable through hclk).

Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91sam9261.dtsi | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9261.dtsi 
b/arch/arm/boot/dts/at91sam9261.dtsi
index a81aab4..7119f1f 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -122,8 +122,8 @@
compatible = "atmel,at91rm9200-udc";
reg = <0xfffa4000 0x4000>;
interrupts = <10 IRQ_TYPE_LEVEL_HIGH 2>;
-   clocks = <&usb>, <&udc_clk>, <&udpck>;
-   clock-names = "usb_clk", "udc_clk", "udpck";
+   clocks = <&udc_clk>, <&udpck>;
+   clock-names = "pclk", "hclk";
status = "disabled";
};
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/11] usb: gadget: at91_udc: Remove non-DT handling code

2014-12-03 Thread Boris Brezillon
Since non-DT board support has been removed from the at91 architecture we
can safely remove non-DT handling code.

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/Kconfig|  1 +
 drivers/usb/gadget/udc/at91_udc.c | 16 ++--
 2 files changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index 217365d..36a598d 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -32,6 +32,7 @@ menu "USB Peripheral Controller"
 config USB_AT91
tristate "Atmel AT91 USB Device Port"
depends on ARCH_AT91
+   depends on OF || COMPILE_TEST
help
   Many Atmel AT91 processors (such as the AT91RM2000) have a
   full speed USB Device Port with support for five configurable
diff --git a/drivers/usb/gadget/udc/at91_udc.c 
b/drivers/usb/gadget/udc/at91_udc.c
index 4ecb576..e7984c0 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -1697,12 +1697,6 @@ static int at91udc_probe(struct platform_device *pdev)
int retval;
struct resource *res;
 
-   if (!dev_get_platdata(dev) && !pdev->dev.of_node) {
-   /* small (so we copy it) but critical! */
-   DBG("missing platform_data\n");
-   return -ENODEV;
-   }
-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res)
return -ENXIO;
@@ -1715,11 +1709,7 @@ static int at91udc_probe(struct platform_device *pdev)
/* init software state */
udc = &controller;
udc->gadget.dev.parent = dev;
-   if (IS_ENABLED(CONFIG_OF) && pdev->dev.of_node)
-   at91udc_of_init(udc, pdev->dev.of_node);
-   else
-   memcpy(&udc->board, dev_get_platdata(dev),
-  sizeof(struct at91_udc_data));
+   at91udc_of_init(udc, pdev->dev.of_node);
udc->pdev = pdev;
udc->enabled = 0;
spin_lock_init(&udc->lock);
@@ -1955,14 +1945,12 @@ static int at91udc_resume(struct platform_device *pdev)
 #defineat91udc_resume  NULL
 #endif
 
-#if defined(CONFIG_OF)
 static const struct of_device_id at91_udc_dt_ids[] = {
{ .compatible = "atmel,at91rm9200-udc" },
{ /* sentinel */ }
 };
 
 MODULE_DEVICE_TABLE(of, at91_udc_dt_ids);
-#endif
 
 static struct platform_driver at91_udc_driver = {
.remove = __exit_p(at91udc_remove),
@@ -1972,7 +1960,7 @@ static struct platform_driver at91_udc_driver = {
.driver = {
.name   = (char *) driver_name,
.owner  = THIS_MODULE,
-   .of_match_table = of_match_ptr(at91_udc_dt_ids),
+   .of_match_table = at91_udc_dt_ids,
},
 };
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/11] usb: gadget: at91_udc: Rework for multi-platform support

2014-12-03 Thread Boris Brezillon
Hello,

This series reworks the at91_udc driver to prepare at91 for multi-platform
support.

It also include several fixes:
 - fix clock names to be consistent with other USB drivers
 - document clocks and clock-names properties in atmel-usb DT bindings doc

and some cleanup changes:
 - remove useless usb_clk
 - allocate at91_udc instance instead of using the statically defined one
 - simplify the probe and remove functions by using devm_ helpers
 - remove !DT specific code

The series depends on this patch [1] (which adds matrix registers definition).

Regards,

Boris

[1]https://lkml.org/lkml/2014/12/3/230

Boris Brezillon (11):
  usb: gadget: at91_udc: Fix clock names
  usb: gadget: at91_udc: Drop uclk clock
  usb: gadget: at91_udc: Document DT clocks and clock-names property
  ARM: at91/dt: at91sam9261: fix clocks and clock-names in udc
definition
  usb: gadget: at91_udc: Remove non-DT handling code
  usb: gadget: at91_udc: Simplify probe and remove functions
  usb: gadget: at91_udc: Rework for multi-platform kernel support
  usb: gadget: at91_udc: Update DT binding documentation
  usb: gadget: at91_udc: Allocate udc instance
  ARM: at91/dt: declare matrix node as a syscon device
  ARM: at91/dt: fix at91 udc compatible strings

 .../devicetree/bindings/usb/atmel-usb.txt  |  10 +-
 arch/arm/boot/dts/at91sam9260.dtsi |   2 +-
 arch/arm/boot/dts/at91sam9261.dtsi |   9 +-
 arch/arm/boot/dts/at91sam9263.dtsi |   2 +-
 drivers/usb/gadget/udc/Kconfig |   1 +
 drivers/usb/gadget/udc/at91_udc.c  | 530 +++--
 drivers/usb/gadget/udc/at91_udc.h  |   9 +-
 7 files changed, 298 insertions(+), 265 deletions(-)

-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/11] usb: gadget: at91_udc: Rework for multi-platform kernel support

2014-12-03 Thread Boris Brezillon
cpu_is_at91xxx are a set of macros defined in mach/cpu.h and are here used
to detect the SoC we are booting on.
Use compatible string + a caps structure to replace those cpu_is_xxx tests.

Remove all mach and asm headers (which are now unused).

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/at91_udc.c | 288 --
 drivers/usb/gadget/udc/at91_udc.h |   7 +
 2 files changed, 218 insertions(+), 77 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c 
b/drivers/usb/gadget/udc/at91_udc.c
index ef1ee07..f870c03 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -31,16 +31,9 @@
 #include 
 #include 
 #include 
-
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
+#include 
+#include 
+#include 
 
 #include "at91_udc.h"
 
@@ -890,8 +883,6 @@ static void clk_off(struct at91_udc *udc)
  */
 static void pullup(struct at91_udc *udc, int is_on)
 {
-   int active = !udc->board.pullup_active_low;
-
if (!udc->enabled || !udc->vbus)
is_on = 0;
DBG("%sactive\n", is_on ? "" : "in");
@@ -900,40 +891,15 @@ static void pullup(struct at91_udc *udc, int is_on)
clk_on(udc);
at91_udp_write(udc, AT91_UDP_ICR, AT91_UDP_RXRSM);
at91_udp_write(udc, AT91_UDP_TXVC, 0);
-   if (cpu_is_at91rm9200())
-   gpio_set_value(udc->board.pullup_pin, active);
-   else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || 
cpu_is_at91sam9g20()) {
-   u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
-
-   txvc |= AT91_UDP_TXVC_PUON;
-   at91_udp_write(udc, AT91_UDP_TXVC, txvc);
-   } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
-   u32 usbpucr;
-
-   usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR);
-   usbpucr |= AT91_MATRIX_USBPUCR_PUON;
-   at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr);
-   }
} else {
stop_activity(udc);
at91_udp_write(udc, AT91_UDP_IDR, AT91_UDP_RXRSM);
at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
-   if (cpu_is_at91rm9200())
-   gpio_set_value(udc->board.pullup_pin, !active);
-   else if (cpu_is_at91sam9260() || cpu_is_at91sam9263() || 
cpu_is_at91sam9g20()) {
-   u32 txvc = at91_udp_read(udc, AT91_UDP_TXVC);
-
-   txvc &= ~AT91_UDP_TXVC_PUON;
-   at91_udp_write(udc, AT91_UDP_TXVC, txvc);
-   } else if (cpu_is_at91sam9261() || cpu_is_at91sam9g10()) {
-   u32 usbpucr;
-
-   usbpucr = at91_matrix_read(AT91_MATRIX_USBPUCR);
-   usbpucr &= ~AT91_MATRIX_USBPUCR_PUON;
-   at91_matrix_write(AT91_MATRIX_USBPUCR, usbpucr);
-   }
clk_off(udc);
}
+
+   if (udc->caps && udc->caps->pullup)
+   udc->caps->pullup(udc, is_on);
 }
 
 /* vbus is here!  turn everything on that's ready */
@@ -1670,12 +1636,202 @@ static void at91udc_shutdown(struct platform_device 
*dev)
spin_unlock_irqrestore(&udc->lock, flags);
 }
 
-static void at91udc_of_init(struct at91_udc *udc,
-struct device_node *np)
+static int at91rm9200_udc_init(struct at91_udc *udc)
+{
+   struct at91_ep *ep;
+   int ret;
+   int i;
+
+   for (i = 0; i < NUM_ENDPOINTS; i++) {
+   ep = &udc->ep[i];
+
+   switch (i) {
+   case 0:
+   case 3:
+   ep->maxpacket = 8;
+   break;
+   case 1 ... 2:
+   ep->maxpacket = 64;
+   break;
+   case 4 ... 5:
+   ep->maxpacket = 256;
+   break;
+   }
+   }
+
+   if (!gpio_is_valid(udc->board.pullup_pin)) {
+   DBG("no D+ pullup?\n");
+   return -ENODEV;
+   }
+
+   ret = devm_gpio_request(&udc->pdev->dev, udc->board.pullup_pin,
+   "udc_pullup");
+   if (ret) {
+   DBG("D+ pullup is busy\n");
+   return ret;
+   }
+
+   gpio_direction_output(udc->board.pullup_pin,
+ udc->board.pullup_active_low);
+
+   return 0;
+}
+
+static void at91rm9200_udc_pullup(struct at91_udc *udc, int is_on)
+{
+   int active = !udc->board.pullup_active_low;
+
+   if (is_on)
+   gpio_set_value(udc->board.pullup_pin, active);
+

[PATCH 09/11] usb: gadget: at91_udc: Allocate udc instance

2014-12-03 Thread Boris Brezillon
Allocate udc structure instead of relying on the statically declared
object.

Signed-off-by: Boris Brezillon 
---
 drivers/usb/gadget/udc/at91_udc.c | 101 ++
 1 file changed, 27 insertions(+), 74 deletions(-)

diff --git a/drivers/usb/gadget/udc/at91_udc.c 
b/drivers/usb/gadget/udc/at91_udc.c
index f870c03..2b20dd7 100644
--- a/drivers/usb/gadget/udc/at91_udc.c
+++ b/drivers/usb/gadget/udc/at91_udc.c
@@ -59,7 +59,15 @@
 #defineDRIVER_VERSION  "3 May 2006"
 
 static const char driver_name [] = "at91_udc";
-static const char ep0name[] = "ep0";
+static const char * const ep_names[] = {
+   "ep0",
+   "ep1",
+   "ep2",
+   "ep3-int",
+   "ep4",
+   "ep5",
+};
+#define ep0nameep_names[0]
 
 #define VBUS_POLL_TIMEOUT  msecs_to_jiffies(1000)
 
@@ -1477,78 +1485,6 @@ static void nop_release(struct device *dev)
/* nothing to free */
 }
 
-static struct at91_udc controller = {
-   .gadget = {
-   .ops= &at91_udc_ops,
-   .ep0= &controller.ep[0].ep,
-   .name   = driver_name,
-   .dev= {
-   .init_name = "gadget",
-   .release = nop_release,
-   }
-   },
-   .ep[0] = {
-   .ep = {
-   .name   = ep0name,
-   .ops= &at91_ep_ops,
-   },
-   .udc= &controller,
-   .maxpacket  = 8,
-   .int_mask   = 1 << 0,
-   },
-   .ep[1] = {
-   .ep = {
-   .name   = "ep1",
-   .ops= &at91_ep_ops,
-   },
-   .udc= &controller,
-   .is_pingpong= 1,
-   .maxpacket  = 64,
-   .int_mask   = 1 << 1,
-   },
-   .ep[2] = {
-   .ep = {
-   .name   = "ep2",
-   .ops= &at91_ep_ops,
-   },
-   .udc= &controller,
-   .is_pingpong= 1,
-   .maxpacket  = 64,
-   .int_mask   = 1 << 2,
-   },
-   .ep[3] = {
-   .ep = {
-   /* could actually do bulk too */
-   .name   = "ep3-int",
-   .ops= &at91_ep_ops,
-   },
-   .udc= &controller,
-   .maxpacket  = 8,
-   .int_mask   = 1 << 3,
-   },
-   .ep[4] = {
-   .ep = {
-   .name   = "ep4",
-   .ops= &at91_ep_ops,
-   },
-   .udc= &controller,
-   .is_pingpong= 1,
-   .maxpacket  = 256,
-   .int_mask   = 1 << 4,
-   },
-   .ep[5] = {
-   .ep = {
-   .name   = "ep5",
-   .ops= &at91_ep_ops,
-   },
-   .udc= &controller,
-   .is_pingpong= 1,
-   .maxpacket  = 256,
-   .int_mask   = 1 << 5,
-   },
-   /* ep6 and ep7 are also reserved (custom silicon might use them) */
-};
-
 static void at91_vbus_update(struct at91_udc *udc, unsigned value)
 {
value ^= udc->board.vbus_active_low;
@@ -1859,15 +1795,32 @@ static int at91udc_probe(struct platform_device *pdev)
struct at91_ep  *ep;
int i;
 
+   udc = devm_kzalloc(dev, sizeof(*udc), GFP_KERNEL);
+   if (!udc)
+   return -ENOMEM;
+
/* init software state */
-   udc = &controller;
udc->gadget.dev.parent = dev;
at91udc_of_init(udc, pdev->dev.of_node);
udc->pdev = pdev;
udc->enabled = 0;
spin_lock_init(&udc->lock);
 
+   udc->gadget.ops = &at91_udc_ops;
+   udc->gadget.ep0 = &udc->ep[0].ep;
+   udc->gadget.name = driver_name;
+   udc->gadget.dev.init_name = "gadget";
+   udc->gadget.dev.release = nop_release;
 
+   for (i = 0; i < NUM_ENDPOINTS; i++) {
+   ep = &udc->ep[i];
+   ep->ep.name = ep_names[i];
+   ep->ep.ops = &at91_ep_ops;
+   ep->udc = udc;
+   ep->int_mask = BIT(i);
+   if (i != 0 && i != 3)
+   ep->is_pingpong = 1;
+   }
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
udc->udp_baseaddr = devm_ioremap_resource(dev, res);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/11] usb: gadget: at91_udc: Update DT binding documentation

2014-12-03 Thread Boris Brezillon
Three compatible strings have been added to the at91_udc driver.
Update the documentation accordingly.

Signed-off-by: Boris Brezillon 
---
 Documentation/devicetree/bindings/usb/atmel-usb.txt | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/atmel-usb.txt 
b/Documentation/devicetree/bindings/usb/atmel-usb.txt
index 6007231..54a8121 100644
--- a/Documentation/devicetree/bindings/usb/atmel-usb.txt
+++ b/Documentation/devicetree/bindings/usb/atmel-usb.txt
@@ -33,7 +33,11 @@ usb1: ehci@0080 {
 AT91 USB device controller
 
 Required properties:
- - compatible: Should be "atmel,at91rm9200-udc"
+ - compatible: Should be one of the following
+  "atmel,at91rm9200-udc"
+  "atmel,at91sam9260-udc"
+  "atmel,at91sam9261-udc"
+  "atmel,at91sam9263-udc"
  - reg: Address and length of the register set for the device
  - interrupts: Should contain macb interrupt
  - clocks: Should reference the peripheral and the AHB clocks
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 10/11] ARM: at91/dt: declare matrix node as a syscon device

2014-12-03 Thread Boris Brezillon
Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91sam9261.dtsi | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/at91sam9261.dtsi 
b/arch/arm/boot/dts/at91sam9261.dtsi
index 7119f1f..e52ae97 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -257,7 +257,7 @@
};
 
matrix: matrix@ee00 {
-   compatible = "atmel,at91sam9260-bus-matrix";
+   compatible = "atmel,at91sam9260-bus-matrix", 
"syscon";
reg = <0xee00 0x200>;
};
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/11] ARM: at91/dt: fix at91 udc compatible strings

2014-12-03 Thread Boris Brezillon
The at91rm9200, at91sam9260, at91sam9261 and at91sam9263 SoCs have slightly
different UDC IPs.
Those differences were previously handled with cpu_is_at91xx macro which
are about to be dropped for multi-platform support, thus we need to
change compatible strings.

Signed-off-by: Boris Brezillon 
---
 arch/arm/boot/dts/at91sam9260.dtsi | 2 +-
 arch/arm/boot/dts/at91sam9261.dtsi | 3 ++-
 arch/arm/boot/dts/at91sam9263.dtsi | 2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/arm/boot/dts/at91sam9260.dtsi 
b/arch/arm/boot/dts/at91sam9260.dtsi
index cb100b0..b43de88 100644
--- a/arch/arm/boot/dts/at91sam9260.dtsi
+++ b/arch/arm/boot/dts/at91sam9260.dtsi
@@ -848,7 +848,7 @@
};
 
usb1: gadget@fffa4000 {
-   compatible = "atmel,at91rm9200-udc";
+   compatible = "atmel,at91sam9260-udc";
reg = <0xfffa4000 0x4000>;
interrupts = <10 IRQ_TYPE_LEVEL_HIGH 2>;
clocks = <&udc_clk>, <&udpck>;
diff --git a/arch/arm/boot/dts/at91sam9261.dtsi 
b/arch/arm/boot/dts/at91sam9261.dtsi
index e52ae97..90f0b59 100644
--- a/arch/arm/boot/dts/at91sam9261.dtsi
+++ b/arch/arm/boot/dts/at91sam9261.dtsi
@@ -119,11 +119,12 @@
};
 
usb1: gadget@fffa4000 {
-   compatible = "atmel,at91rm9200-udc";
+   compatible = "atmel,at91sam9261-udc";
reg = <0xfffa4000 0x4000>;
interrupts = <10 IRQ_TYPE_LEVEL_HIGH 2>;
clocks = <&udc_clk>, <&udpck>;
clock-names = "pclk", "hclk";
+   atmel,matrix = <&matrix>;
status = "disabled";
};
 
diff --git a/arch/arm/boot/dts/at91sam9263.dtsi 
b/arch/arm/boot/dts/at91sam9263.dtsi
index 51416c7d..2c7ed05 100644
--- a/arch/arm/boot/dts/at91sam9263.dtsi
+++ b/arch/arm/boot/dts/at91sam9263.dtsi
@@ -817,7 +817,7 @@
};
 
usb1: gadget@fff78000 {
-   compatible = "atmel,at91rm9200-udc";
+   compatible = "atmel,at91sam9263-udc";
reg = <0xfff78000 0x4000>;
interrupts = <24 IRQ_TYPE_LEVEL_HIGH 2>;
clocks = <&udc_clk>, <&udpck>;
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: gadget: at91_udc: move prepare clk into process context

2014-08-13 Thread Boris BREZILLON
On Fri,  8 Aug 2014 11:42:42 +0200
Ronald Wahl  wrote:

> Commit 7628083227b6bc4a7e33d7c381d7a4e558424b6b (usb: gadget: at91_udc:
> prepare clk before calling enable) added clock preparation in interrupt
> context. This is not allowed as it might sleep. Also setting the clock
> rate is unsafe to call from there for the same reason. Move clock
> preparation and setting clock rate into process context (at91udc_probe).
> 
> Signed-off-by: Ronald Wahl 

Acked-by: Boris Brezillon 

> ---
> v3 -> v4:
> - no code changes
> - update commit message
> - add changelog
> 
> v2 -> v3: (NOTE: this patch was also send with the v2 tag)
> - moved setting the clock rate into process context as well as it may
>   also sleep
> - update commit message
> 
> v1 -> v2:
> - no changes (first v2 got out accidently)
> 
>  drivers/usb/gadget/udc/at91_udc.c | 44 
> ---
>  1 file changed, 32 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/usb/gadget/udc/at91_udc.c 
> b/drivers/usb/gadget/udc/at91_udc.c
> index cfd18bc..0d685d0 100644
> --- a/drivers/usb/gadget/udc/at91_udc.c
> +++ b/drivers/usb/gadget/udc/at91_udc.c
> @@ -870,12 +870,10 @@ static void clk_on(struct at91_udc *udc)
>   return;
>   udc->clocked = 1;
>  
> - if (IS_ENABLED(CONFIG_COMMON_CLK)) {
> - clk_set_rate(udc->uclk, 4800);
> - clk_prepare_enable(udc->uclk);
> - }
> - clk_prepare_enable(udc->iclk);
> - clk_prepare_enable(udc->fclk);
> + if (IS_ENABLED(CONFIG_COMMON_CLK))
> + clk_enable(udc->uclk);
> + clk_enable(udc->iclk);
> + clk_enable(udc->fclk);
>  }
>  
>  static void clk_off(struct at91_udc *udc)
> @@ -884,10 +882,10 @@ static void clk_off(struct at91_udc *udc)
>   return;
>   udc->clocked = 0;
>   udc->gadget.speed = USB_SPEED_UNKNOWN;
> - clk_disable_unprepare(udc->fclk);
> - clk_disable_unprepare(udc->iclk);
> + clk_disable(udc->fclk);
> + clk_disable(udc->iclk);
>   if (IS_ENABLED(CONFIG_COMMON_CLK))
> - clk_disable_unprepare(udc->uclk);
> + clk_disable(udc->uclk);
>  }
>  
>  /*
> @@ -1780,14 +1778,24 @@ static int at91udc_probe(struct platform_device *pdev)
>   }
>  
>   /* don't do anything until we have both gadget driver and VBUS */
> + if (IS_ENABLED(CONFIG_COMMON_CLK)) {
> + clk_set_rate(udc->uclk, 4800);
> + retval = clk_prepare(udc->uclk);
> + if (retval)
> + goto fail1;
> + }
> + retval = clk_prepare(udc->fclk);
> + if (retval)
> + goto fail1a;
> +
>   retval = clk_prepare_enable(udc->iclk);
>   if (retval)
> - goto fail1;
> + goto fail1b;
>   at91_udp_write(udc, AT91_UDP_TXVC, AT91_UDP_TXVC_TXVDIS);
>   at91_udp_write(udc, AT91_UDP_IDR, 0x);
>   /* Clear all pending interrupts - UDP may be used by bootloader. */
>   at91_udp_write(udc, AT91_UDP_ICR, 0x);
> - clk_disable_unprepare(udc->iclk);
> + clk_disable(udc->iclk);
>  
>   /* request UDC and maybe VBUS irqs */
>   udc->udp_irq = platform_get_irq(pdev, 0);
> @@ -1795,7 +1803,7 @@ static int at91udc_probe(struct platform_device *pdev)
>   0, driver_name, udc);
>   if (retval < 0) {
>   DBG("request irq %d failed\n", udc->udp_irq);
> - goto fail1;
> + goto fail1c;
>   }
>   if (gpio_is_valid(udc->board.vbus_pin)) {
>   retval = gpio_request(udc->board.vbus_pin, "udc_vbus");
> @@ -1848,6 +1856,13 @@ fail3:
>   gpio_free(udc->board.vbus_pin);
>  fail2:
>   free_irq(udc->udp_irq, udc);
> +fail1c:
> + clk_unprepare(udc->iclk);
> +fail1b:
> + clk_unprepare(udc->fclk);
> +fail1a:
> + if (IS_ENABLED(CONFIG_COMMON_CLK))
> + clk_unprepare(udc->uclk);
>  fail1:
>   if (IS_ENABLED(CONFIG_COMMON_CLK) && !IS_ERR(udc->uclk))
>   clk_put(udc->uclk);
> @@ -1896,6 +1911,11 @@ static int __exit at91udc_remove(struct 
> platform_device *pdev)
>   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>   release_mem_region(res->start, resource_size(res));
>  
> + if (IS_ENABLED(CONFIG_COMMON_CLK))
> + clk_unprepare(udc->uclk);
> + clk_unprepare(udc->fclk);
> + clk_unprepare(udc->iclk);
> +
>   clk_put(udc->iclk);
>   clk_put(udc->fclk);
>   if (IS_ENABLED(CONFIG_COMMON_CLK))



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] usb: gadget: at91_udc: move prepare clk into process context

2014-08-07 Thread Boris BREZILLON
On Thu, 07 Aug 2014 14:43:32 +0200
Ronald Wahl  wrote:

> On 07.08.2014 09:59, Boris BREZILLON wrote:
> > On Thu, 7 Aug 2014 09:52:31 +0200
> > Boris BREZILLON  wrote:
> >> On Wed,  6 Aug 2014 15:11:42 +0200
> >> Ronald Wahl  wrote:
> >>
> >>> Commit 7628083227b6bc4a7e33d7c381d7a4e558424b6b added clock preparation in
> >>> interrupt context. This is not allowed as it might sleep. Move clock
> >>> preparation into process context (at91udc_probe).
> >>> ---
> >>>   drivers/usb/gadget/udc/at91_udc.c | 39 
> >>> ++-
> >>>   1 file changed, 30 insertions(+), 9 deletions(-)
> >>>
> >>> diff --git a/drivers/usb/gadget/udc/at91_udc.c 
> >>> b/drivers/usb/gadget/udc/at91_udc.c
> >>> index cfd18bc..0b347a0 100644
> >>> --- a/drivers/usb/gadget/udc/at91_udc.c
> >>> +++ b/drivers/usb/gadget/udc/at91_udc.c
> >>> @@ -872,10 +872,10 @@ static void clk_on(struct at91_udc *udc)
> >>>
> >>>   if (IS_ENABLED(CONFIG_COMMON_CLK)) {
> >>>   clk_set_rate(udc->uclk, 4800);
> >>> - clk_prepare_enable(udc->uclk);
> >>> + clk_enable(udc->uclk);
> >>>   }
> >>> - clk_prepare_enable(udc->iclk);
> >>> - clk_prepare_enable(udc->fclk);
> >>> + clk_enable(udc->iclk);
> >>> + clk_enable(udc->fclk);
> >>>   }
> >>>
> >>>   static void clk_off(struct at91_udc *udc)
> >>> @@ -884,10 +884,10 @@ static void clk_off(struct at91_udc *udc)
> >>>   return;
> >>>   udc->clocked = 0;
> >>>   udc->gadget.speed = USB_SPEED_UNKNOWN;
> >>> - clk_disable_unprepare(udc->fclk);
> >>> - clk_disable_unprepare(udc->iclk);
> >>> + clk_disable(udc->fclk);
> >>> + clk_disable(udc->iclk);
> >>>   if (IS_ENABLED(CONFIG_COMMON_CLK))
> >>> - clk_disable_unprepare(udc->uclk);
> >>> + clk_disable(udc->uclk);
> >>>   }
> >>
> >> As you stated prepare and unprepare should never be called in interrupt
> >> context.
> >>
> >> My concern here is that PLLB (which is often used as USB clock
> >> parent) will never be gated/disabled (because all this work is
> >> done in its unprepare method), and thus your power consumption will be
> >> higher (when entering suspend mode) than if you'd done a
> >> disable_unprepare call.
> >>
> >> How about leaving the clk_on/off unchanged and use a threaded irq
> >> instead of a normal irq ?
> 
> Even with threaded interrupts things are still called while interrupts 
> are disabled by one or more layers of spin_lock_irqsave. There are also 
> different code paths from where clk_on() is called.

You're right (I only had a quick look at it). Let's fix this as a first
step and we'll figure out how to optimize power consumption later.
BTW, clk_set_rate can sleep too (AFAIK clk_enable and clk_disable
are the only one that can be called in atomic context).

Best Regards,

Boris

-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] usb: gadget: at91_udc: move prepare clk into process context

2014-08-07 Thread Boris BREZILLON
Adding USB and Atmel Maintainers in Cc.

On Thu, 7 Aug 2014 09:52:31 +0200
Boris BREZILLON  wrote:

> Hi Ronald,
> 
> On Wed,  6 Aug 2014 15:11:42 +0200
> Ronald Wahl  wrote:
> 
> > Commit 7628083227b6bc4a7e33d7c381d7a4e558424b6b added clock preparation in
> > interrupt context. This is not allowed as it might sleep. Move clock
> > preparation into process context (at91udc_probe).
> > ---
> >  drivers/usb/gadget/udc/at91_udc.c | 39 
> > ++-
> >  1 file changed, 30 insertions(+), 9 deletions(-)
> > 
> > diff --git a/drivers/usb/gadget/udc/at91_udc.c 
> > b/drivers/usb/gadget/udc/at91_udc.c
> > index cfd18bc..0b347a0 100644
> > --- a/drivers/usb/gadget/udc/at91_udc.c
> > +++ b/drivers/usb/gadget/udc/at91_udc.c
> > @@ -872,10 +872,10 @@ static void clk_on(struct at91_udc *udc)
> >  
> > if (IS_ENABLED(CONFIG_COMMON_CLK)) {
> > clk_set_rate(udc->uclk, 4800);
> > -   clk_prepare_enable(udc->uclk);
> > +   clk_enable(udc->uclk);
> > }
> > -   clk_prepare_enable(udc->iclk);
> > -   clk_prepare_enable(udc->fclk);
> > +   clk_enable(udc->iclk);
> > +   clk_enable(udc->fclk);
> >  }
> >  
> >  static void clk_off(struct at91_udc *udc)
> > @@ -884,10 +884,10 @@ static void clk_off(struct at91_udc *udc)
> > return;
> > udc->clocked = 0;
> > udc->gadget.speed = USB_SPEED_UNKNOWN;
> > -   clk_disable_unprepare(udc->fclk);
> > -   clk_disable_unprepare(udc->iclk);
> > +   clk_disable(udc->fclk);
> > +   clk_disable(udc->iclk);
> > if (IS_ENABLED(CONFIG_COMMON_CLK))
> > -   clk_disable_unprepare(udc->uclk);
> > +   clk_disable(udc->uclk);
> >  }
> 
> As you stated prepare and unprepare should never be called in interrupt
> context. 
> 
> My concern here is that PLLB (which is often used as USB clock
> parent) will never be gated/disabled (because all this work is
> done in its unprepare method), and thus your power consumption will be
> higher (when entering suspend mode) than if you'd done a
> disable_unprepare call.
> 
> How about leaving the clk_on/off unchanged and use a threaded irq
> instead of a normal irq ?
> 
> 
> Best Regards,
> 
> Boris
> 



-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: ohci-at91 mismerge build error

2014-01-07 Thread boris brezillon

Hello Arnd,

On 07/01/2014 12:54, Arnd Bergmann wrote:

After commit 99f14bd4d1 "Merge 3.13-rc5 into usb-next" (in linux-next as of
today), I'm getting this error building any at91 kernel:

drivers/usb/host/ohci-at91.c: In function 'usb_hcd_at91_probe':
drivers/usb/host/ohci-at91.c:190:4: error: label 'err' used but not defined
 goto err;
 ^
drivers/usb/host/ohci-at91.c: At top level:
drivers/usb/host/ohci-at91.c:206:2: warning: data definition has no type or 
storage class [enabled by default]
   at91_stop_hc(pdev);
   ^
...

The problem is obviously a mismerge between two unrelated changes that
resulted in missing opening braces.


Thanks for fixing this: I was about to propose the same patch to resolve
the issue introduced by this merge (reported by Olof yesterday).


Signed-off-by: Arnd Bergmann 

Acked-by: Boris BREZILLON 

---
Please just ignore if this has been reported before

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 2d0ee5e..091ae49 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -197,7 +197,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
at91_start_hc(pdev);
  
  	retval = usb_add_hcd(hcd, irq, IRQF_SHARED);

-   if (retval == 0)
+   if (retval == 0) {
device_wakeup_enable(hcd->self.controller);
return retval;
}



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 1/3] usb: ohci-at91: replace request_mem_region + ioremap by devm_ioremap_resource

2014-01-06 Thread boris brezillon

Hello Olof,

On 06/01/2014 19:08, Olof Johansson wrote:

Boris,

On Mon, Dec 9, 2013 at 12:51 AM, Boris BREZILLON
 wrote:

Replace the request_mem_region + ioremap calls by the
devm_ioremap_resource call which does the same things but with device
managed resources.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 

Did you build these patches?


Yes, I did.


There's several breakages due to them in
last night's next. I'm a little puzzled how they passed testing before
you submitted?
This one fails with:

drivers/usb/host/ohci-at91.c: In function 'usb_hcd_at91_probe':
drivers/usb/host/ohci-at91.c:157:36: error: 'dev' undeclared (first
use in this function)
   hcd->regs = devm_ioremap_resource(dev, res);
 ^
drivers/usb/host/ohci-at91.c:157:36: note: each undeclared identifier
is reported only once for each function it appears in
drivers/usb/host/ohci-at91.c:157:41: error: 'res' undeclared (first
use in this function)
   hcd->regs = devm_ioremap_resource(dev, res);


Actually this patch series depends on another patch :
"usb: ohci-at91: fix irq and iomem resource retrieval"
commit fb5f1834c3221e459324c6885eaad75429f722a5.

This patch was taken out to ease integration in 3.13-rc5.

Sorry, I should have stated it in my cover letter.

Which next are you using ?
I took a look at linux-next and the dev variable is declared.


There are more too, the original one I was bisecting for was the below
one, but the above hit first:

drivers/usb/host/ohci-at91.c: In function 'usb_hcd_at91_probe':
drivers/usb/host/ohci-at91.c:190:4: error: label 'err' used but not defined
drivers/usb/host/ohci-at91.c: At top level:
drivers/usb/host/ohci-at91.c:206:2: warning: data definition has no
type or storage class [enabled by default]
drivers/usb/host/ohci-at91.c:206:2: error: type defaults to 'int' in
declaration of 'at91_stop_hc' [-Werror=implicit-int]
drivers/usb/host/ohci-at91.c:206:2: warning: parameter names (without
types) in function declaration [enabled by default]
drivers/usb/host/ohci-at91.c:206:2: error: conflicting types for 'at91_stop_hc'
drivers/usb/host/ohci-at91.c:97:13: note: previous definition of
'at91_stop_hc' was here
drivers/usb/host/ohci-at91.c:208:5: error: expected '=', ',', ';',
'asm' or '__attribute__' before ':' token
drivers/usb/host/ohci-at91.c:210:2: error: expected identifier or '('
before 'return'
drivers/usb/host/ohci-at91.c:211:1: error: expected identifier or '('
before '}' token
drivers/usb/host/ohci-at91.c:97:13: warning: 'at91_stop_hc' defined
but not used [-Wunused-function]
  static void at91_stop_hc(struct platform_device *pdev)


These errors come from merge commit 
99f14bd4d1b2a1b1b6cd508e08efdbc5e3919198.


There is a missing brace on the last retval test.

Best Regards,

Boris

Somewhat spectacular.  Greg, can you please drop these until he's
sorted out his submission? :(


-Olof


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4] usb: ohci-at91: fix irq and iomem resource retrieval

2013-12-17 Thread boris brezillon

Hello Greg,

Just a reminder to let you know this patch fixes a bug in the at91 ohci 
driver

which appenrently showed up in 3.13-rc1 release, but is caused by bad
assumptions on platform device resources order.

Without this patch the ohci usb host controller is completely unusable 
on at91

platforms.

Best Regards,

Boris

On 08/12/2013 15:59, Boris BREZILLON wrote:

When using dt resources retrieval (interrupts and reg properties) there is
no predefined order for these resources in the platform dev resources
table.

Retrieve resources using platform_get_resource and platform_get_irq
functions instead of direct resource table entries to avoid resource type
mismatch.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
Reviewed-by: Tomasz Figa 
---
Changes since v3:
  - replace platform_get_resource call with IORESOURCE_IRQ argument by
platform_get_irq

Changes since v2:
  - split the patch series to isolate the urgent fix provided by this patch

Changes since v1:
  - none

  drivers/usb/host/ohci-at91.c |   26 +++---
  1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 418444e..8c356af 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -136,23 +136,27 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
struct ohci_hcd *ohci;
int retval;
struct usb_hcd *hcd = NULL;
-
-   if (pdev->num_resources != 2) {
-   pr_debug("hcd probe: invalid num_resources");
-   return -ENODEV;
+   struct device *dev = &pdev->dev;
+   struct resource *res;
+   int irq;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!res) {
+   dev_dbg(dev, "hcd probe: missing memory resource\n");
+   return -ENXIO;
}
  
-	if ((pdev->resource[0].flags != IORESOURCE_MEM)

-   || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
-   pr_debug("hcd probe: invalid resource type\n");
-   return -ENODEV;
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0) {
+   dev_dbg(dev, "hcd probe: missing irq resource\n");
+   return irq;
}
  
  	hcd = usb_create_hcd(driver, &pdev->dev, "at91");

if (!hcd)
return -ENOMEM;
-   hcd->rsrc_start = pdev->resource[0].start;
-   hcd->rsrc_len = resource_size(&pdev->resource[0]);
+   hcd->rsrc_start = res->start;
+   hcd->rsrc_len = resource_size(res);
  
  	if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {

pr_debug("request_mem_region failed\n");
@@ -199,7 +203,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
ohci->num_ports = board->ports;
at91_start_hc(pdev);
  
-	retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);

+   retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (retval == 0)
return retval;
  


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 0/3] usb: ohci-at91: various improvements

2013-12-09 Thread Boris BREZILLON
Hello,

This patch series moves the different driver resources (clks and iomem)
retrieval to the device managed versions (devm_ functions).

Best Regards,

Boris

Changes since v4:
 - remove unneeded debug trace in case devm_ioremap_resource fails
   (an error message is already printed within this function)

Changes since v3:
 - replace devm_request_and_ioremap call by devm_ioremap_resource

Changes since v2:
 - split urgent fix and resource retrieval improvements

Boris BREZILLON (3):
  usb: ohci-at91: replace request_mem_region + ioremap by
devm_ioremap_resource
  usb: ohci-at91: use dev variable instead of &pdev->dev
  usb: ohci-at91: use device managed clk retrieval

 drivers/usb/host/ohci-at91.c |   67 --
 1 file changed, 18 insertions(+), 49 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 3/3] usb: ohci-at91: use device managed clk retrieval

2013-12-09 Thread Boris BREZILLON
Replace clk_get calls by devm_clk_get calls.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 8c0c4a4..9aa485e 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -164,30 +164,30 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(dev, "ohci_clk");
+   iclk = devm_clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(dev, "uhpck");
+   fclk = devm_clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
-   goto err4;
+   goto err;
}
-   hclk = clk_get(dev, "hclk");
+   hclk = devm_clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
-   goto err5;
+   goto err;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(dev, "usb_clk");
+   uclk = devm_clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
-   goto err6;
+   goto err;
}
}
 
@@ -203,15 +203,6 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
/* Error handling */
at91_stop_hc(pdev);
 
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
- err6:
-   clk_put(hclk);
- err5:
-   clk_put(fclk);
- err4:
-   clk_put(iclk);
-
  err:
usb_put_hcd(hcd);
return retval;
@@ -236,13 +227,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
usb_put_hcd(hcd);
-
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
-   clk_put(hclk);
-   clk_put(fclk);
-   clk_put(iclk);
-   fclk = iclk = hclk = NULL;
 }
 
 /*-*/
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 1/3] usb: ohci-at91: replace request_mem_region + ioremap by devm_ioremap_resource

2013-12-09 Thread Boris BREZILLON
Replace the request_mem_region + ioremap calls by the
devm_ioremap_resource call which does the same things but with device
managed resources.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   27 ++-
 1 file changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 8c356af..9dc50f8 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -158,24 +158,17 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
hcd->rsrc_start = res->start;
hcd->rsrc_len = resource_size(res);
 
-   if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-   pr_debug("request_mem_region failed\n");
-   retval = -EBUSY;
-   goto err1;
-   }
-
-   hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
-   if (!hcd->regs) {
-   pr_debug("ioremap failed\n");
-   retval = -EIO;
-   goto err2;
+   hcd->regs = devm_ioremap_resource(dev, res);
+   if (IS_ERR(hcd->regs)) {
+   retval = PTR_ERR(hcd->regs);
+   goto err;
}
 
iclk = clk_get(&pdev->dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(&pdev->dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
-   goto err3;
+   goto err;
}
fclk = clk_get(&pdev->dev, "uhpck");
if (IS_ERR(fclk)) {
@@ -219,13 +212,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
  err4:
clk_put(iclk);
 
- err3:
-   iounmap(hcd->regs);
-
- err2:
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-
- err1:
+ err:
usb_put_hcd(hcd);
return retval;
 }
@@ -248,8 +235,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
 {
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
-   iounmap(hcd->regs);
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd);
 
if (IS_ENABLED(CONFIG_COMMON_CLK))
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


linux-usb@vger.kernel.org

2013-12-09 Thread Boris BREZILLON
Make use of the dev variable instead of referencing the dev field of the
pdev struct.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 9dc50f8..8c0c4a4 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -152,7 +152,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
return irq;
}
 
-   hcd = usb_create_hcd(driver, &pdev->dev, "at91");
+   hcd = usb_create_hcd(driver, dev, "at91");
if (!hcd)
return -ENOMEM;
hcd->rsrc_start = res->start;
@@ -164,28 +164,28 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(&pdev->dev, "ohci_clk");
+   iclk = clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
-   dev_err(&pdev->dev, "failed to get ohci_clk\n");
+   dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(&pdev->dev, "uhpck");
+   fclk = clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
-   dev_err(&pdev->dev, "failed to get uhpck\n");
+   dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
goto err4;
}
-   hclk = clk_get(&pdev->dev, "hclk");
+   hclk = clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
-   dev_err(&pdev->dev, "failed to get hclk\n");
+   dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
goto err5;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(&pdev->dev, "usb_clk");
+   uclk = clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
-   dev_err(&pdev->dev, "failed to get uclk\n");
+   dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
goto err6;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 1/3] usb: ohci-at91: replace request_mem_region + ioremap by devm_ioremap_resource

2013-12-08 Thread boris brezillon

Hello,

Le 08/12/2013 19:31, Sergei Shtylyov a écrit :

Hello.

On 12/08/2013 06:02 PM, Boris BREZILLON wrote:


Replace the request_mem_region + ioremap calls by the
devm_ioremap_resource call which does the same things but with device
managed resources.



Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
  drivers/usb/host/ohci-at91.c |   28 +++-
  1 file changed, 7 insertions(+), 21 deletions(-)



diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 8c356af..fe2ecc5 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -158,24 +158,18 @@ static int usb_hcd_at91_probe(const struct 
hc_driver *driver,

  hcd->rsrc_start = res->start;
  hcd->rsrc_len = resource_size(res);

-if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, 
hcd_name)) {

-pr_debug("request_mem_region failed\n");
-retval = -EBUSY;
-goto err1;
-}
-
-hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
-if (!hcd->regs) {
-pr_debug("ioremap failed\n");
-retval = -EIO;
-goto err2;
+hcd->regs = devm_ioremap_resource(dev, res);
+if (IS_ERR(hcd->regs)) {
+dev_dbg(dev, "devm_ioremap_resource failed\n");


   I've already told you devm_ioremap_resource() prints the detailed 
error message. No need to duplicate it.




Oops, sorry, this is an oversight.
I'll send a new version removing this line.

Best Regards,

Boris


+retval = PTR_ERR(hcd->regs);
+goto err;
  }


WBR, Sergei



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4] usb: ohci-at91: fix irq and iomem resource retrieval

2013-12-08 Thread Boris BREZILLON
When using dt resources retrieval (interrupts and reg properties) there is
no predefined order for these resources in the platform dev resources
table.

Retrieve resources using platform_get_resource and platform_get_irq
functions instead of direct resource table entries to avoid resource type
mismatch.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
Reviewed-by: Tomasz Figa 
---
Changes since v3:
 - replace platform_get_resource call with IORESOURCE_IRQ argument by
   platform_get_irq

Changes since v2:
 - split the patch series to isolate the urgent fix provided by this patch

Changes since v1:
 - none

 drivers/usb/host/ohci-at91.c |   26 +++---
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 418444e..8c356af 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -136,23 +136,27 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
struct ohci_hcd *ohci;
int retval;
struct usb_hcd *hcd = NULL;
-
-   if (pdev->num_resources != 2) {
-   pr_debug("hcd probe: invalid num_resources");
-   return -ENODEV;
+   struct device *dev = &pdev->dev;
+   struct resource *res;
+   int irq;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!res) {
+   dev_dbg(dev, "hcd probe: missing memory resource\n");
+   return -ENXIO;
}
 
-   if ((pdev->resource[0].flags != IORESOURCE_MEM)
-   || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
-   pr_debug("hcd probe: invalid resource type\n");
-   return -ENODEV;
+   irq = platform_get_irq(pdev, 0);
+   if (irq < 0) {
+   dev_dbg(dev, "hcd probe: missing irq resource\n");
+   return irq;
}
 
hcd = usb_create_hcd(driver, &pdev->dev, "at91");
if (!hcd)
return -ENOMEM;
-   hcd->rsrc_start = pdev->resource[0].start;
-   hcd->rsrc_len = resource_size(&pdev->resource[0]);
+   hcd->rsrc_start = res->start;
+   hcd->rsrc_len = resource_size(res);
 
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
pr_debug("request_mem_region failed\n");
@@ -199,7 +203,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
ohci->num_ports = board->ports;
at91_start_hc(pdev);
 
-   retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
+   retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
if (retval == 0)
return retval;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


linux-usb@vger.kernel.org

2013-12-08 Thread Boris BREZILLON
Make use of the dev variable instead of referencing the dev field of the
pdev struct.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index fe2ecc5..30f1445 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -152,7 +152,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
return irq;
}
 
-   hcd = usb_create_hcd(driver, &pdev->dev, "at91");
+   hcd = usb_create_hcd(driver, dev, "at91");
if (!hcd)
return -ENOMEM;
hcd->rsrc_start = res->start;
@@ -165,28 +165,28 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(&pdev->dev, "ohci_clk");
+   iclk = clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
-   dev_err(&pdev->dev, "failed to get ohci_clk\n");
+   dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(&pdev->dev, "uhpck");
+   fclk = clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
-   dev_err(&pdev->dev, "failed to get uhpck\n");
+   dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
goto err4;
}
-   hclk = clk_get(&pdev->dev, "hclk");
+   hclk = clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
-   dev_err(&pdev->dev, "failed to get hclk\n");
+   dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
goto err5;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(&pdev->dev, "usb_clk");
+   uclk = clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
-   dev_err(&pdev->dev, "failed to get uclk\n");
+   dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
goto err6;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 3/3] usb: ohci-at91: use device managed clk retrieval

2013-12-08 Thread Boris BREZILLON
Replace clk_get calls by devm_clk_get calls.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 30f1445..9db3954 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -165,30 +165,30 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(dev, "ohci_clk");
+   iclk = devm_clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(dev, "uhpck");
+   fclk = devm_clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
-   goto err4;
+   goto err;
}
-   hclk = clk_get(dev, "hclk");
+   hclk = devm_clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
-   goto err5;
+   goto err;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(dev, "usb_clk");
+   uclk = devm_clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
-   goto err6;
+   goto err;
}
}
 
@@ -204,15 +204,6 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
/* Error handling */
at91_stop_hc(pdev);
 
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
- err6:
-   clk_put(hclk);
- err5:
-   clk_put(fclk);
- err4:
-   clk_put(iclk);
-
  err:
usb_put_hcd(hcd);
return retval;
@@ -237,13 +228,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
usb_put_hcd(hcd);
-
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
-   clk_put(hclk);
-   clk_put(fclk);
-   clk_put(iclk);
-   fclk = iclk = hclk = NULL;
 }
 
 /*-*/
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 1/3] usb: ohci-at91: replace request_mem_region + ioremap by devm_ioremap_resource

2013-12-08 Thread Boris BREZILLON
Replace the request_mem_region + ioremap calls by the
devm_ioremap_resource call which does the same things but with device
managed resources.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   28 +++-
 1 file changed, 7 insertions(+), 21 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 8c356af..fe2ecc5 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -158,24 +158,18 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
hcd->rsrc_start = res->start;
hcd->rsrc_len = resource_size(res);
 
-   if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-   pr_debug("request_mem_region failed\n");
-   retval = -EBUSY;
-   goto err1;
-   }
-
-   hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
-   if (!hcd->regs) {
-   pr_debug("ioremap failed\n");
-   retval = -EIO;
-   goto err2;
+   hcd->regs = devm_ioremap_resource(dev, res);
+   if (IS_ERR(hcd->regs)) {
+   dev_dbg(dev, "devm_ioremap_resource failed\n");
+   retval = PTR_ERR(hcd->regs);
+   goto err;
}
 
iclk = clk_get(&pdev->dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(&pdev->dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
-   goto err3;
+   goto err;
}
fclk = clk_get(&pdev->dev, "uhpck");
if (IS_ERR(fclk)) {
@@ -219,13 +213,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
  err4:
clk_put(iclk);
 
- err3:
-   iounmap(hcd->regs);
-
- err2:
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-
- err1:
+ err:
usb_put_hcd(hcd);
return retval;
 }
@@ -248,8 +236,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
 {
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
-   iounmap(hcd->regs);
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd);
 
if (IS_ENABLED(CONFIG_COMMON_CLK))
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v4 0/3] usb: ohci-at91: various improvements

2013-12-08 Thread Boris BREZILLON
Hello,

This patch series moves the different driver resources (clks and iomem)
retrieval to the device managed versions (devm_ functions).

Best Regards,

Boris

Changes since v3:
 - replace devm_request_and_ioremap call by devm_ioremap_resource

Changes since v2:
 - split urgent fix and resource retrieval improvements

Boris BREZILLON (3):
  usb: ohci-at91: replace request_mem_region + ioremap by
devm_ioremap_resource
  usb: ohci-at91: use dev variable instead of &pdev->dev
  usb: ohci-at91: use device managed clk retrieval

 drivers/usb/host/ohci-at91.c |   68 --
 1 file changed, 19 insertions(+), 49 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 3/3] usb: ohci-at91: use device managed clk retrieval

2013-12-05 Thread Boris BREZILLON
Replace clk_get calls by devm_clk_get calls.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 2a86e32..7b2ccd3 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -164,30 +164,30 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(dev, "ohci_clk");
+   iclk = devm_clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(dev, "uhpck");
+   fclk = devm_clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
-   goto err4;
+   goto err;
}
-   hclk = clk_get(dev, "hclk");
+   hclk = devm_clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
-   goto err5;
+   goto err;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(dev, "usb_clk");
+   uclk = devm_clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
-   goto err6;
+   goto err;
}
}
 
@@ -203,15 +203,6 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
/* Error handling */
at91_stop_hc(pdev);
 
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
- err6:
-   clk_put(hclk);
- err5:
-   clk_put(fclk);
- err4:
-   clk_put(iclk);
-
  err:
usb_put_hcd(hcd);
return retval;
@@ -236,13 +227,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
usb_put_hcd(hcd);
-
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
-   clk_put(hclk);
-   clk_put(fclk);
-   clk_put(iclk);
-   fclk = iclk = hclk = NULL;
 }
 
 /*-*/
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


linux-usb@vger.kernel.org

2013-12-05 Thread Boris BREZILLON
Make use of the dev variable instead of referencing the dev field of the
pdev struct.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 8528895..2a86e32 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -151,7 +151,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
return -ENODEV;
}
 
-   hcd = usb_create_hcd(driver, &pdev->dev, "at91");
+   hcd = usb_create_hcd(driver, dev, "at91");
if (!hcd)
return -ENOMEM;
hcd->rsrc_start = mem_r->start;
@@ -164,28 +164,28 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(&pdev->dev, "ohci_clk");
+   iclk = clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
-   dev_err(&pdev->dev, "failed to get ohci_clk\n");
+   dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(&pdev->dev, "uhpck");
+   fclk = clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
-   dev_err(&pdev->dev, "failed to get uhpck\n");
+   dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
goto err4;
}
-   hclk = clk_get(&pdev->dev, "hclk");
+   hclk = clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
-   dev_err(&pdev->dev, "failed to get hclk\n");
+   dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
goto err5;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(&pdev->dev, "usb_clk");
+   uclk = clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
-   dev_err(&pdev->dev, "failed to get uclk\n");
+   dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
goto err6;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 1/3] usb: ohci-at91: replace request_mem_region + ioremap by devm_request_and_ioremap

2013-12-05 Thread Boris BREZILLON
Replace the request_mem_region + ioremap calls by the
devm_request_and_ioremap call which does the same things but with device
managed resources.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
 drivers/usb/host/ohci-at91.c |   24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 7aec6ca..8528895 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -157,24 +157,18 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
hcd->rsrc_start = mem_r->start;
hcd->rsrc_len = resource_size(mem_r);
 
-   if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-   pr_debug("request_mem_region failed\n");
-   retval = -EBUSY;
-   goto err1;
-   }
-
-   hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
+   hcd->regs = devm_request_and_ioremap(dev, mem_r);
if (!hcd->regs) {
-   pr_debug("ioremap failed\n");
+   dev_dbg(dev, "devm_request_and_ioremap failed\n");
retval = -EIO;
-   goto err2;
+   goto err;
}
 
iclk = clk_get(&pdev->dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(&pdev->dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
-   goto err3;
+   goto err;
}
fclk = clk_get(&pdev->dev, "uhpck");
if (IS_ERR(fclk)) {
@@ -218,13 +212,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
  err4:
clk_put(iclk);
 
- err3:
-   iounmap(hcd->regs);
-
- err2:
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-
- err1:
+ err:
usb_put_hcd(hcd);
return retval;
 }
@@ -247,8 +235,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
 {
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
-   iounmap(hcd->regs);
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd);
 
if (IS_ENABLED(CONFIG_COMMON_CLK))
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3 0/3] usb: ohci-at91: various improvements

2013-12-05 Thread Boris BREZILLON
Hello,

This patch series moves the different driver resources (clks and iomem)
retrieval to the device managed versions (devm_ functions).

Best Regards,

Boris

Changes since v2:
 - split urgent fix and resource retrieval improvements

Boris BREZILLON (3):
  usb: ohci-at91: replace request_mem_region + ioremap by
devm_request_and_ioremap
  usb: ohci-at91: use dev variable instead of &pdev->dev
  usb: ohci-at91: use device managed clk retrieval

 drivers/usb/host/ohci-at91.c |   64 +++---
 1 file changed, 17 insertions(+), 47 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v3] usb: ohci-at91: fix irq and iomem resource retrieval

2013-12-05 Thread Boris BREZILLON
When using dt resources retrieval (interrupts and reg properties) there is
no predefined order for these resources in the platform dev resources
table.

Retrieve resources using the platform_get_resource function instead of
direct resource table entries to avoid resource type mismatch.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre 
Signed-off-by: Alan Stern 
---
Changes since v2:
 - split the patch series to isolate the urgent fix provided by this patch

Changes since v1:
 - none

 drivers/usb/host/ohci-at91.c |   19 +++
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 418444e..7aec6ca 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -136,23 +136,26 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
struct ohci_hcd *ohci;
int retval;
struct usb_hcd *hcd = NULL;
+   struct device *dev = &pdev->dev;
+   struct resource *mem_r, *irq_r;
 
-   if (pdev->num_resources != 2) {
-   pr_debug("hcd probe: invalid num_resources");
+   mem_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   if (!mem_r) {
+   dev_dbg(dev, "hcd probe: missing memory resource\n");
return -ENODEV;
}
 
-   if ((pdev->resource[0].flags != IORESOURCE_MEM)
-   || (pdev->resource[1].flags != IORESOURCE_IRQ)) {
-   pr_debug("hcd probe: invalid resource type\n");
+   irq_r = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+   if (!irq_r) {
+   dev_dbg(dev, "hcd probe: missing irq resource\n");
return -ENODEV;
}
 
hcd = usb_create_hcd(driver, &pdev->dev, "at91");
if (!hcd)
return -ENOMEM;
-   hcd->rsrc_start = pdev->resource[0].start;
-   hcd->rsrc_len = resource_size(&pdev->resource[0]);
+   hcd->rsrc_start = mem_r->start;
+   hcd->rsrc_len = resource_size(mem_r);
 
if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
pr_debug("request_mem_region failed\n");
@@ -199,7 +202,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
ohci->num_ports = board->ports;
at91_start_hc(pdev);
 
-   retval = usb_add_hcd(hcd, pdev->resource[1].start, IRQF_SHARED);
+   retval = usb_add_hcd(hcd, irq_r->start, IRQF_SHARED);
if (retval == 0)
return retval;
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 3/3] usb: ohci-at91: use device managed clk retrieval

2013-12-04 Thread boris brezillon

Hello Alan,

On 03/12/2013 16:32, Alan Stern wrote:

On Tue, 3 Dec 2013, Nicolas Ferre wrote:


On 03/12/2013 15:07, Boris BREZILLON :

Replace clk_get calls by devm_clk_get calls.

Signed-off-by: Boris BREZILLON 
Tested-by: Robert Nelson 

Acked-by: Nicolas Ferre 

Thanks Boris for these fixes.

Alan, Greg, can you take the whole series as fixes for 3.13?

Signed-off-by: Alan Stern 

Sorry, but I forgot to add your Signed-off-by in the 2nd version of this
series.


The patches look fine to me.  But only the 1/3 patch fixes a bug; the
others merely change the resource management.


Do you want me to split this series ?
 1) the 1st patch that should be merged in 3.13
 2) patches 2 to 4 that might be applied later

Best Regards,

Boris



Alan Stern



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 2/4] usb: ohci-at91: replace request_mem_region + ioremap by devm_request_and_ioremap

2013-12-03 Thread Boris BREZILLON
Replace the request_mem_region + ioremap calls by the
devm_request_and_ioremap call which does the same things but with device
managed resources.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre  
---
 drivers/usb/host/ohci-at91.c |   24 +---
 1 file changed, 5 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 7aec6ca..8528895 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -157,24 +157,18 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
hcd->rsrc_start = mem_r->start;
hcd->rsrc_len = resource_size(mem_r);
 
-   if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
-   pr_debug("request_mem_region failed\n");
-   retval = -EBUSY;
-   goto err1;
-   }
-
-   hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
+   hcd->regs = devm_request_and_ioremap(dev, mem_r);
if (!hcd->regs) {
-   pr_debug("ioremap failed\n");
+   dev_dbg(dev, "devm_request_and_ioremap failed\n");
retval = -EIO;
-   goto err2;
+   goto err;
}
 
iclk = clk_get(&pdev->dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(&pdev->dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
-   goto err3;
+   goto err;
}
fclk = clk_get(&pdev->dev, "uhpck");
if (IS_ERR(fclk)) {
@@ -218,13 +212,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
  err4:
clk_put(iclk);
 
- err3:
-   iounmap(hcd->regs);
-
- err2:
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
-
- err1:
+ err:
usb_put_hcd(hcd);
return retval;
 }
@@ -247,8 +235,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
 {
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
-   iounmap(hcd->regs);
-   release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
usb_put_hcd(hcd);
 
if (IS_ENABLED(CONFIG_COMMON_CLK))
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 4/4] usb: ohci-at91: use device managed clk retrieval

2013-12-03 Thread Boris BREZILLON
Replace clk_get calls by devm_clk_get calls.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre  
---
 drivers/usb/host/ohci-at91.c |   30 +++---
 1 file changed, 7 insertions(+), 23 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 2a86e32..7b2ccd3 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -164,30 +164,30 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(dev, "ohci_clk");
+   iclk = devm_clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(dev, "uhpck");
+   fclk = devm_clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
-   goto err4;
+   goto err;
}
-   hclk = clk_get(dev, "hclk");
+   hclk = devm_clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
-   goto err5;
+   goto err;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(dev, "usb_clk");
+   uclk = devm_clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
-   goto err6;
+   goto err;
}
}
 
@@ -203,15 +203,6 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
/* Error handling */
at91_stop_hc(pdev);
 
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
- err6:
-   clk_put(hclk);
- err5:
-   clk_put(fclk);
- err4:
-   clk_put(iclk);
-
  err:
usb_put_hcd(hcd);
return retval;
@@ -236,13 +227,6 @@ static void usb_hcd_at91_remove(struct usb_hcd *hcd,
usb_remove_hcd(hcd);
at91_stop_hc(pdev);
usb_put_hcd(hcd);
-
-   if (IS_ENABLED(CONFIG_COMMON_CLK))
-   clk_put(uclk);
-   clk_put(hclk);
-   clk_put(fclk);
-   clk_put(iclk);
-   fclk = iclk = hclk = NULL;
 }
 
 /*-*/
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


linux-usb@vger.kernel.org

2013-12-03 Thread Boris BREZILLON
Make use of the dev variable instead of referencing the dev field of the
pdev struct.

Signed-off-by: Boris BREZILLON 
Acked-by: Nicolas Ferre  
---
 drivers/usb/host/ohci-at91.c |   18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/host/ohci-at91.c b/drivers/usb/host/ohci-at91.c
index 8528895..2a86e32 100644
--- a/drivers/usb/host/ohci-at91.c
+++ b/drivers/usb/host/ohci-at91.c
@@ -151,7 +151,7 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
return -ENODEV;
}
 
-   hcd = usb_create_hcd(driver, &pdev->dev, "at91");
+   hcd = usb_create_hcd(driver, dev, "at91");
if (!hcd)
return -ENOMEM;
hcd->rsrc_start = mem_r->start;
@@ -164,28 +164,28 @@ static int usb_hcd_at91_probe(const struct hc_driver 
*driver,
goto err;
}
 
-   iclk = clk_get(&pdev->dev, "ohci_clk");
+   iclk = clk_get(dev, "ohci_clk");
if (IS_ERR(iclk)) {
-   dev_err(&pdev->dev, "failed to get ohci_clk\n");
+   dev_err(dev, "failed to get ohci_clk\n");
retval = PTR_ERR(iclk);
goto err;
}
-   fclk = clk_get(&pdev->dev, "uhpck");
+   fclk = clk_get(dev, "uhpck");
if (IS_ERR(fclk)) {
-   dev_err(&pdev->dev, "failed to get uhpck\n");
+   dev_err(dev, "failed to get uhpck\n");
retval = PTR_ERR(fclk);
goto err4;
}
-   hclk = clk_get(&pdev->dev, "hclk");
+   hclk = clk_get(dev, "hclk");
if (IS_ERR(hclk)) {
-   dev_err(&pdev->dev, "failed to get hclk\n");
+   dev_err(dev, "failed to get hclk\n");
retval = PTR_ERR(hclk);
goto err5;
}
if (IS_ENABLED(CONFIG_COMMON_CLK)) {
-   uclk = clk_get(&pdev->dev, "usb_clk");
+   uclk = clk_get(dev, "usb_clk");
if (IS_ERR(uclk)) {
-   dev_err(&pdev->dev, "failed to get uclk\n");
+   dev_err(dev, "failed to get uclk\n");
retval = PTR_ERR(uclk);
goto err6;
}
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   3   >