Re: [U-Boot] [PATCH v2 4/4] updates for DFU and atmel usba udc

2011-02-15 Thread Marcel Janssen
Dear Remy and Reinhard,

> Hmm, Let's make it even more black/white: I do not have to like the
> board code. ;-)
> Reinhard is the Atmel maintainer. He needs to pull in the Board code.
> I only care about generic USB code... ;-)))
> 
> Please make 2 unrelated patch series (1 series for USB DFU support, 1
> series for board support), or it will never hit mainline...
> AND: I would really recommend to build a decent USB/DFU patch series
> first. Forget the board for now. The board seems to depend on DFU
> support, not the other way around.
> If generic DFU code is really generic and acceptable, I will pull it
> in my tree. I am willing to fix small issues in the series to assist
> you, but I will not do major redesigns...

I tried compiling everything against the rework tree. Unfortunately I don't 
know how to solve the reset_timer issue and my NAND won't work.
Although Reinhard just commented on that, I have no clue yet how to fix it.

I can't finish this work today and really have no time left for it, so I have 
to quit on the code for now.

I will have to thank you for you assistance for now and have to get back on 
this in a couple of months if I do find the time again.

Hopefully someone picks up the v2 patch and continues from there. It's not 
very difficult to make it work in Reinhard's tree I think.

Best regards,
Marcel

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 4/4] add icnova sam9g45 board

2011-02-15 Thread Marcel Janssen
On Tuesday, February 15, 2011 01:00:50 am Reinhard Meyer wrote:
> Dear Marcel Janssen,
> 
> > Hi Remy and Reinhard,
> > 
> >> To make it easy for you: It is up to you if you choose '
> >> rework_110202'
> 
> ...
> 
> > It looks like if at91sam9g45.h has not been updated. Is that right ?
> > If so, should all be changed to ATMEL_ID  and ATMEL_BASE ?
> 
> That is correct. Only 9260/1/3 are reworked so far.
> 
> If someone would rework the 9g45 in the spirit of the 9260 it would be
> great. Please as a separate patch. Same goes for the other SoCs ;)

I did most of that. I just hit this :

drivers/mtd/cfi_flash.c:576: undefined reference to `reset_timer'

Any idea how to fix it ?

regards,
Marcel
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 1/4] Add Atmel USBA UDC

2011-02-15 Thread Marcel Janssen
Hi Remy,

> Continuing producing some remarks:
> 
> 2011/2/13 Marcel Janssen :
> > From: Marcel 
> > 
> > Atmel USBA UDC cleanup
> > 
> > Atmel USBA UDC cleanup
> > 
> > more cleanup of Atmel USBA UDC
> > 
> > Some more cleaning of Atmel USBA UDC
> > 
> > further cleaning of Atmel USBA UDC
> 
> Strange header.
> 
> > Signed-off-by: Marcel 
> > ---
> >  drivers/usb/gadget/Makefile |1 +
> >  drivers/usb/gadget/atmel_usba_udc.c | 1438
> > +++ include/usb/atmel_usba_udc.h  
> >  |  398 ++
> >  3 files changed, 1837 insertions(+), 0 deletions(-)
> >  create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
> >  create mode 100644 include/usb/atmel_usba_udc.h
> > 
> > diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
> > index 0846233..024844d 100644
> > --- a/drivers/usb/gadget/Makefile
> > +++ b/drivers/usb/gadget/Makefile
> > @@ -29,6 +29,7 @@ LIB   := $(obj)libusb_gadget.o
> >  ifdef CONFIG_USB_ETHER
> >  COBJS-y += ether.o epautoconf.o config.o usbstring.o
> >  COBJS-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
> > +COBJS-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
> >  else
> >  # Devices not related to the new gadget layer depend on
> > CONFIG_USB_DEVICE ifdef CONFIG_USB_DEVICE
> > diff --git a/drivers/usb/gadget/atmel_usba_udc.c
> > b/drivers/usb/gadget/atmel_usba_udc.c new file mode 100644
> > index 000..6d02de6
> > --- /dev/null
> > +++ b/drivers/usb/gadget/atmel_usba_udc.c
> > @@ -0,0 +1,1438 @@
> > +/*
> > + * Driver for the Atmel USBA high speed USB device controller
> > + *
> > + * Copyright (C) 2011 Marcel Janssen, Admesy B.V.
> > + * Copyright (C) 2005-2007 Atmel Corporation
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> 
> Is this GPLv2 only from its origin? I thought only GPLv2+ code was
> acceptable. See
> http://www.denx.de/wiki/view/U-Boot/Patches#Attributing_Code_Copyrights_Si
> gn

Wow, there's something I completely missed.
I would need to check on that. The original code comes from kernel 2.6.33 and 
I didn't change that part.

> > +   if (!(ptr->in_use))
> > +   debug("%s: ptr not marked as \"in_use\"\n",
> > __func__); +
> > +   hang();
> 
> Is hang required? Is there no recovery to the terminal possible?

I guess not.

> > +   if (!ptr)
> > +   DBG("panic: no more free req buffers\n");
> 
> Cool. A panic in a debug printf that is removed by the preprocessor.
> Is it really panic?

Actually I think this should never be hit unless someone calls it wrong.

> > +   udc->regs = (unsigned *) AT91SAM9G45_BASE_UDPHS;
> > +   udc->fifo = (unsigned *) AT91SAM9G45_UDPHS_FIFO;
> 
> Is at91sam9g45 the only SoC that has this UDP-USBA controller?
> Make it a generic define. Globally.

So far I haven't seen others than the at91sam9g45 and at91sam9g45m10

> Please fix the double empty lines globally as well.
>
> This patch looks relatively clean compared to the reset of the series.
> Please rework comments.

I see what I can do.

Best regards,
Marcel

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 4/4] updates for DFU and atmel usba udc

2011-02-15 Thread Marcel Janssen
Hi Remy,

> 2011/2/15 Marcel Janssen :
> > On Tuesday, February 15, 2011 07:43:34 pm Remy Bohmer wrote:
> >> Hi,
> >> 
> >> 2011/2/13 Marcel Janssen :
> >> > From: Marcel 
> >> > 
> >> > Signed-off-by: Marcel 
> >> > ---
> >> >  arch/arm/cpu/arm926ejs/at91/led.c   |  119
> >> > +-
> >> 
> >> Why is this part if this patch?
> >> It does not seem to be related to USB stuff. Please make it a seperate
> >> patch.
> > 
> > I optionally use the LED's in DFU mode so that there's interaction while
> > upgrading the board.
> 
> U-boot has a terminal/monitor. It is not up to the driver to control
> LEDs that might or might not be on a board.

OK, good to know. I'll check that out, but not today.
For now I can remove the LED code I think. Than in a couple of months I can 
can check how to use the monitor code.

> > You might believe the host could handle this, but I like
> > the device to indicate activity as well.
> > Somehow I couldn't get it working without changing led.c I think, but I
> > may have missed something.
> 
> The problem is here that you mix up sub-systems.
> Modifying LED code should be independent from USB driver code, and
> really not in the same patch.
>
> >> >  common/Makefile |1 +
> >> >  common/update_dfu.c |2 -
> >> >  drivers/usb/gadget/usbdfu.c |   14 +++--
> 
> These files should be completely generic code, that even would work on
> X86, PowerPC and so on.

Agree on that. It would be optiomal. Not everything is, the first time :-)

> >> >  drivers/usb/gadget/atmel_usba_udc.c |8 +-
> 
> Only this driver file should be Atmel USBA specific, but NOT SoC
> specific, and absolutely not board or board config related.

ok.

> >> Please, only make a patch series with only USB-DFU stuff in it, drop
> >> the add-board code from this series. The board code is not acceptable
> >> for mainstream since it does not follow the new
> >> u-boot-atmel->rework110202 tree style of adding at91 boards. It will
> >> take you a huge amount of effort to make it suitable.
> >> Further, both parts of the patch series are not related and you are
> >> now creating a link between the Atmel tree and the USB tree, which
> >> makes it even more difficult.
> > 
> > I'm actually busy fixing the board code for u-boot-atmel->rework110202
> > 
> > Most of it is working so I hope I can create the patches as you like
> > them.
> 
> Hmm, Let's make it even more black/white: I do not have to like the
> board code. ;-)
> Reinhard is the Atmel maintainer. He needs to pull in the Board code.
> I only care about generic USB code... ;-)))

hmmm.
The black and white this is that after today I don't have a single hour to 
spend on this code :-)

> Please make 2 unrelated patch series (1 series for USB DFU support, 1
> series for board support), or it will never hit mainline...
> AND: I would really recommend to build a decent USB/DFU patch series
> first. Forget the board for now. The board seems to depend on DFU
> support, not the other way around.
> If generic DFU code is really generic and acceptable, I will pull it
> in my tree. I am willing to fix small issues in the series to assist
> you, but I will not do major redesigns...

Well, the board  does not depend on DFU. Not even the USBD controller is 
activated in the board config. It is left up to a script to handle that though 
update_dfu.c which defines a command for that. I may have left some parts in 
that don't really belong there, I haven't check it yet.

Best regards,
Marcel






___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 4/4] updates for DFU and atmel usba udc

2011-02-15 Thread Marcel Janssen
On Tuesday, February 15, 2011 07:43:34 pm Remy Bohmer wrote:
> Hi,
> 
> 2011/2/13 Marcel Janssen :
> > From: Marcel 
> > 
> > Signed-off-by: Marcel 
> > ---
> >  arch/arm/cpu/arm926ejs/at91/led.c   |  119
> > +-
> 
> Why is this part if this patch?
> It does not seem to be related to USB stuff. Please make it a seperate
> patch.

I optionally use the LED's in DFU mode so that there's interaction while 
upgrading the board. You might believe the host could handle this, but I like 
the device to indicate activity as well.
Somehow I couldn't get it working without changing led.c I think, but I may 
have missed something.

> >  common/Makefile |1 +
> >  common/update_dfu.c |2 -
> >  drivers/usb/gadget/atmel_usba_udc.c |8 +-
> >  drivers/usb/gadget/usbdfu.c |   14 +++--
> >  5 files changed, 128 insertions(+), 16 deletions(-)
> > 
> > diff --git a/arch/arm/cpu/arm926ejs/at91/led.c
> > b/arch/arm/cpu/arm926ejs/at91/led.c index 0a315c4..0638a2e 100644
> > --- a/arch/arm/cpu/arm926ejs/at91/led.c
> > +++ b/arch/arm/cpu/arm926ejs/at91/led.c
> > @@ -28,38 +28,149 @@
> >  #include 
> >  #include 
> > 
> > +static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
> > +   STATUS_LED_OFF, STATUS_LED_OFF};
> > +
> > +void coloured_LED_init(void)
> > +{
> > +   /* Enable clock */
> > +   at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9G45_ID_PIODE);
> 
> at91_sys_write is deprecated, please use register access by struct

Already noticed that.

> Why is modification of the generic at91 led code required? It is not clear.
> 
> Please, only make a patch series with only USB-DFU stuff in it, drop
> the add-board code from this series. The board code is not acceptable
> for mainstream since it does not follow the new
> u-boot-atmel->rework110202 tree style of adding at91 boards. It will
> take you a huge amount of effort to make it suitable.
> Further, both parts of the patch series are not related and you are
> now creating a link between the Atmel tree and the USB tree, which
> makes it even more difficult.

I'm actually busy fixing the board code for u-boot-atmel->rework110202

Most of it is working so I hope I can create the patches as you like them.

best regards,
Marcel











___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 3/4] Add In-Circuit sam9g45_oem board

2011-02-15 Thread Marcel Janssen
On Tuesday, February 15, 2011 07:45:36 pm Remy Bohmer wrote:
> Hi,
> 
> 2011/2/13 Marcel Janssen :
> > From: Marcel 
> > 
> > sam9g45_oem cleanup phase1
> > 
> > sam9g45_oem cleanup phase2
> > 
> > sam9g45_oem cleanup phase3
> 
> Not a very descriptive patch header...
> Please fix.

Basically cleaning a lot of whitespaces only and some other things checkpatch 
complained about.  Since it where so many, I needed a few times to clean all. 
Anyway, When I post new patches I hope to be able to skip the cleaning of 
whitespaces.

regards,
Marcel
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH v2 4/4] updates for DFU and atmel usba udc

2011-02-13 Thread Marcel Janssen
Hi,

Sorry to post this one twice.
It's seems exactly the same patch.

> From: Marcel 
> 
> Signed-off-by: Marcel 
> ---
>  arch/arm/cpu/arm926ejs/at91/led.c   |  119
> +- common/Makefile |  
>  1 +
>  common/update_dfu.c |2 -
>  drivers/usb/gadget/atmel_usba_udc.c |8 +-
>  drivers/usb/gadget/usbdfu.c |   14 +++--
>  5 files changed, 128 insertions(+), 16 deletions(-)
> 
> diff --git a/arch/arm/cpu/arm926ejs/at91/led.c
> b/arch/arm/cpu/arm926ejs/at91/led.c index 0a315c4..0638a2e 100644
> --- a/arch/arm/cpu/arm926ejs/at91/led.c
> +++ b/arch/arm/cpu/arm926ejs/at91/led.c
> @@ -28,38 +28,149 @@
>  #include 
>  #include 
> 
> +static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
> + STATUS_LED_OFF, STATUS_LED_OFF};
> +
> +void coloured_LED_init(void)
> +{
> + /* Enable clock */
> + at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9G45_ID_PIODE);
> +
> +#ifdef CONFIG_RED_LED
> + at91_set_gpio_output(CONFIG_RED_LED, 1);
> + at91_set_gpio_value(CONFIG_RED_LED, 1);
> +#endif
> +#ifdef CONFIG_GREEN_LED
> + at91_set_gpio_output(CONFIG_GREEN_LED, 1);
> + at91_set_gpio_value(CONFIG_GREEN_LED, 1);
> +#endif
> +#ifdef CONFIG_YELLOW_LED
> + at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
> + at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
> +#endif
> +#ifdef CONFIG_BLUE_LED
> + at91_set_gpio_output(CONFIG_BLUE_LED, 1);
> + at91_set_gpio_value(CONFIG_BLUE_LED, 1);
> +#endif
> +}
> +
>  #ifdef CONFIG_RED_LED
>  void red_LED_on(void)
>  {
>   at91_set_gpio_value(CONFIG_RED_LED, 1);
> + saved_state[STATUS_LED_RED] = STATUS_LED_ON;
>  }
> 
>  void red_LED_off(void)
>  {
>   at91_set_gpio_value(CONFIG_RED_LED, 0);
> + saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
>  }
>  #endif
> 
>  #ifdef CONFIG_GREEN_LED
>  void green_LED_on(void)
>  {
> - at91_set_gpio_value(CONFIG_GREEN_LED, 0);
> + at91_set_gpio_value(CONFIG_GREEN_LED, 1);
> + saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
>  }
> 
>  void green_LED_off(void)
>  {
> - at91_set_gpio_value(CONFIG_GREEN_LED, 1);
> + at91_set_gpio_value(CONFIG_GREEN_LED, 0);
> + saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
>  }
>  #endif
> 
>  #ifdef CONFIG_YELLOW_LED
>  void yellow_LED_on(void)
>  {
> - at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
> + at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
> + saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
>  }
> 
>  void yellow_LED_off(void)
>  {
> - at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
> + at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
> + saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
>  }
>  #endif
> +
> +void __led_init(led_id_t mask, int state)
> +{
> + __led_set(mask, state);
> +}
> +
> +void __led_toggle(led_id_t mask)
> +{
> +
> +#ifdef CONFIG_RED_LED
> + if (STATUS_LED_RED == mask) {
> + if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
> + red_LED_off();
> + else
> + red_LED_on();
> + }
> +#endif
> +#ifdef CONFIG_BLUE_LED
> + else if (STATUS_LED_BLUE == mask) {
> + if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
> + blue_LED_off();
> + else
> + blue_LED_on();
> + }
> +#endif
> +#ifdef CONFIG_GREEN_LED
> + else if (STATUS_LED_GREEN == mask) {
> + if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
> + green_LED_off();
> + else
> + green_LED_on();
> + }
> +#endif
> +#ifdef CONFIG_YELLOW_LED
> + else if (STATUS_LED_YELLOW == mask) {
> + if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
> + yellow_LED_off();
> + else
> + yellow_LED_on();
> + }
> +#endif
> +}
> +
> +void __led_set(led_id_t mask, int state)
> +{
> +#ifdef CONFIG_RED_LED
> + if (STATUS_LED_RED == mask) {
> + if (STATUS_LED_ON == state)
> + red_LED_on();
> + else
> + red_LED_off();
> + }
> +#endif
> +#ifdef CONFIG_BLUE_LED
> +else if (STATUS_LED_BLUE == mask) {
> + if (STATUS_LED_ON == state)
> + blue_LED_on();
> + else
> + blue_LED_off();
> + }
> +#endif
> +#ifdef CONFIG_GREEN_LED
> + else if (STATUS_LED_GREEN == mask) {
> + if (STATUS_LED_ON == state)
> + green_LED_on();
> + else
> + green_LED_off();
> + }
> +#endif
> +#ifdef CONFIG_YELLOW_LED
> + else if (STATUS_LED_YELLOW == mask) {
> + if (STATUS_LED_ON == state)
> + yellow_LED_on();
> + else
> + yellow_LED_off();
> + }
> +#endif
> +}
> +
> diff --git a/common/Makefile b/common/Makefile
> index 048df0c..a653c1e 100644
> --- a/common/Makefile
> +++ b

Re: [U-Boot] [PATCH v2 0/4] DFU implementation for Atmel SAM9G45

2011-02-13 Thread Marcel Janssen
Hi,

I hope this one gets through correctly.

I know it's know what optimal as it should apply to the current 'work'
but I had some issues doing that and no time to find out what the issue is.

If possible, please apply to cdc-at91
If not, than I will be reviewing it in a couple of months I guess.

The code I send is compiling in cdc-at91 branch and working well for my board 
and should work as well for at91_udc boards I think.

If anyone likes to help out on this, please go ahead !

btw, thanks again to all people who already helped. 
I perhaps have a few hours left this week to work on this, but no more than 
that. I hope for someone to take over from me at this point.

Best regards,
Marcel

> From: Marcel 
> 
> These patches apply to u-boot-usb, cdc-at91 branch.
> They contain a working implementation of USB DFU.
> Most is documented in README.dfu.
> 
> A little background on the implementation :
> The controller code (atmel_usba_udc) should also work with the gadget
> ethernet driver. I tested it a couple of weeks ago to be fully functional.
> However, haven't used this driver since, as I focussed on getting DFU to
> work.
> 
> I included some verdor specific command in the DFU code. This is purely
> ment as an example where to add such code. However, it is a usefull
> example so I left it in the code.
> Further, my original code relies on the use of the GPBR to write to from
> Linux. This code has not been included in the patches yet because of lack
> of time. I can however send it in later this week perhaps. It's basic
> purpose is just to reboot from Linux and let u-boot know what to do (wait
> for a DFU download). U-boot than read the GPBR register and acts depending
> on it's value, meaning either wait for TFTP action or DFU action.
> 
> The patches have been checked by checkpatch and produce a few warnings
> (so do some other files already in git). I currently don't have the time
> to fix them, but hope someone else can work on this. If not, I will pick
> up on this in a couple of weeks/months. Sorry guys, did my best to fix them
> all, but some slipped.
> 
> This week I'm still available for comments on the above mail address.
> After that I can't use the above email for the next couple of weeks/months
> and also won't be reading the mailing list. If anyone needs my help, please
> see below for my email address.
> 
> I'm very sorry if I didn't comply to all suggested changes. I tried, but
> time is my biggest enemy in this. I rather post something that works for me
> than post nothing as I may not be able to post for the next couple of
> months. Since the cdc-at91 brach is not mainstream, I guess it would be ok
> to apply these patches so that they can be used and fixed by anyone who
> likes it.
> 
> Unfortunately some last minute fixed in the last patch, but this shoudn't
> be a big issue I think. I did work off-tree for my impementation which
> caused this.
> 
> The current patches have been checked to compile and work for my board.
> 
> Best regards,
> Marcel (marcel_dot_janssen_at_admesy_dot_nl)
> 
> 
> Marcel (4):
>   Add Atmel USBA UDC
>   USB DFU driver added
>   Add In-Circuit sam9g45_oem board
>   updates for DFU and atmel usba udc
> 
>  arch/arm/cpu/arm926ejs/at91/led.c|  119 +++-
>  board/in-circuit/icnova/Makefile |   50 +
>  board/in-circuit/icnova/icnova_sam9g45.c |  242 +
>  boards.cfg   |1 +
>  common/Makefile  |1 +
>  common/update_dfu.c  |   87 ++
>  doc/README.dfu   |  129 +++
>  drivers/usb/gadget/Makefile  |   10 +
>  drivers/usb/gadget/atmel_usba_udc.c  | 1438
> ++ drivers/usb/gadget/usbdfu.c  |
> 1338 +++ include/configs/icnova_sam9g45.h
> |  253 ++
>  include/usb/atmel_usba_udc.h |  398 +
>  include/usb_dfu.h|  128 +++
>  include/usb_dfu_descriptors.h|  100 ++
>  14 files changed, 4290 insertions(+), 4 deletions(-)
>  create mode 100644 board/in-circuit/icnova/Makefile
>  create mode 100644 board/in-circuit/icnova/icnova_sam9g45.c
>  create mode 100644 common/update_dfu.c
>  create mode 100644 doc/README.dfu
>  create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
>  create mode 100644 drivers/usb/gadget/usbdfu.c
>  create mode 100644 include/configs/icnova_sam9g45.h
>  create mode 100644 include/usb/atmel_usba_udc.h
>  create mode 100644 include/usb_dfu.h
>  create mode 100644 include/usb_dfu_descriptors.h
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 4/4] updates for DFU and atmel usba udc

2011-02-13 Thread Marcel Janssen
From: Marcel 

Signed-off-by: Marcel 
---
 arch/arm/cpu/arm926ejs/at91/led.c   |  119 +-
 common/Makefile |1 +
 common/update_dfu.c |2 -
 drivers/usb/gadget/atmel_usba_udc.c |8 +-
 drivers/usb/gadget/usbdfu.c |   14 +++--
 5 files changed, 128 insertions(+), 16 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/at91/led.c 
b/arch/arm/cpu/arm926ejs/at91/led.c
index 0a315c4..0638a2e 100644
--- a/arch/arm/cpu/arm926ejs/at91/led.c
+++ b/arch/arm/cpu/arm926ejs/at91/led.c
@@ -28,38 +28,149 @@
 #include 
 #include 
 
+static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
+   STATUS_LED_OFF, STATUS_LED_OFF};
+
+void coloured_LED_init(void)
+{
+   /* Enable clock */
+   at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9G45_ID_PIODE);
+
+#ifdef CONFIG_RED_LED  
+   at91_set_gpio_output(CONFIG_RED_LED, 1);
+   at91_set_gpio_value(CONFIG_RED_LED, 1);
+#endif 
+#ifdef CONFIG_GREEN_LED
+   at91_set_gpio_output(CONFIG_GREEN_LED, 1);
+   at91_set_gpio_value(CONFIG_GREEN_LED, 1);
+#endif
+#ifdef CONFIG_YELLOW_LED
+   at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
+   at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
+#endif
+#ifdef CONFIG_BLUE_LED 
+   at91_set_gpio_output(CONFIG_BLUE_LED, 1);
+   at91_set_gpio_value(CONFIG_BLUE_LED, 1);
+#endif  
+}
+
 #ifdef CONFIG_RED_LED
 void red_LED_on(void)
 {
at91_set_gpio_value(CONFIG_RED_LED, 1);
+   saved_state[STATUS_LED_RED] = STATUS_LED_ON;
 }
 
 void red_LED_off(void)
 {
at91_set_gpio_value(CONFIG_RED_LED, 0);
+   saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
 }
 #endif
 
 #ifdef CONFIG_GREEN_LED
 void green_LED_on(void)
 {
-   at91_set_gpio_value(CONFIG_GREEN_LED, 0);
+   at91_set_gpio_value(CONFIG_GREEN_LED, 1);
+   saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
 }
 
 void green_LED_off(void)
 {
-   at91_set_gpio_value(CONFIG_GREEN_LED, 1);
+   at91_set_gpio_value(CONFIG_GREEN_LED, 0);
+   saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
 }
 #endif
 
 #ifdef CONFIG_YELLOW_LED
 void yellow_LED_on(void)
 {
-   at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
+   at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
+   saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
 }
 
 void yellow_LED_off(void)
 {
-   at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
+   at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
+   saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
 }
 #endif
+
+void __led_init(led_id_t mask, int state)
+{
+   __led_set(mask, state);
+}
+
+void __led_toggle(led_id_t mask)
+{
+
+#ifdef CONFIG_RED_LED  
+   if (STATUS_LED_RED == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
+   red_LED_off();
+   else
+   red_LED_on();
+   } 
+#endif
+#ifdef CONFIG_BLUE_LED
+   else if (STATUS_LED_BLUE == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
+   blue_LED_off();
+   else
+   blue_LED_on();
+   } 
+#endif
+#ifdef CONFIG_GREEN_LED
+   else if (STATUS_LED_GREEN == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
+   green_LED_off();
+   else
+   green_LED_on();
+   } 
+#endif
+#ifdef CONFIG_YELLOW_LED
+   else if (STATUS_LED_YELLOW == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
+   yellow_LED_off();
+   else
+   yellow_LED_on();
+   }
+#endif
+}
+
+void __led_set(led_id_t mask, int state)
+{
+#ifdef CONFIG_RED_LED  
+   if (STATUS_LED_RED == mask) {
+   if (STATUS_LED_ON == state)
+   red_LED_on();
+   else
+   red_LED_off();
+   } 
+#endif
+#ifdef CONFIG_BLUE_LED 
+else if (STATUS_LED_BLUE == mask) {
+   if (STATUS_LED_ON == state)
+   blue_LED_on();
+   else
+   blue_LED_off();
+   } 
+#endif
+#ifdef CONFIG_GREEN_LED
+   else if (STATUS_LED_GREEN == mask) {
+   if (STATUS_LED_ON == state)
+   green_LED_on();
+   else
+   green_LED_off();
+   } 
+#endif
+#ifdef CONFIG_YELLOW_LED   
+   else if (STATUS_LED_YELLOW == mask) {
+   if (STATUS_LED_ON == state)
+   yellow_LED_on();
+   else
+   yellow_LED_off();
+   }
+#endif
+}
+
diff --git a/common/Makefile b/common/Makefile
index 048df0c..a653c1e 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -163,6 +163,7 @@ COBJS-$(CONFIG_LCD) += lcd.o
 COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
 COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o
 COBJS-$(CONFIG_UPDATE_TFTP) += update.o
+COBJS-$(CONFIG_USBD_DFU)+= update

[U-Boot] [PATCH v2 4/4] updates for DFU and atmel usba udc

2011-02-13 Thread Marcel Janssen
From: Marcel 

Signed-off-by: Marcel 
---
 arch/arm/cpu/arm926ejs/at91/led.c   |  119 +-
 common/Makefile |1 +
 common/update_dfu.c |2 -
 drivers/usb/gadget/atmel_usba_udc.c |8 +-
 drivers/usb/gadget/usbdfu.c |   14 +++--
 5 files changed, 128 insertions(+), 16 deletions(-)

diff --git a/arch/arm/cpu/arm926ejs/at91/led.c 
b/arch/arm/cpu/arm926ejs/at91/led.c
index 0a315c4..0638a2e 100644
--- a/arch/arm/cpu/arm926ejs/at91/led.c
+++ b/arch/arm/cpu/arm926ejs/at91/led.c
@@ -28,38 +28,149 @@
 #include 
 #include 
 
+static unsigned int saved_state[4] = {STATUS_LED_OFF, STATUS_LED_OFF,
+   STATUS_LED_OFF, STATUS_LED_OFF};
+
+void coloured_LED_init(void)
+{
+   /* Enable clock */
+   at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9G45_ID_PIODE);
+
+#ifdef CONFIG_RED_LED  
+   at91_set_gpio_output(CONFIG_RED_LED, 1);
+   at91_set_gpio_value(CONFIG_RED_LED, 1);
+#endif 
+#ifdef CONFIG_GREEN_LED
+   at91_set_gpio_output(CONFIG_GREEN_LED, 1);
+   at91_set_gpio_value(CONFIG_GREEN_LED, 1);
+#endif
+#ifdef CONFIG_YELLOW_LED
+   at91_set_gpio_output(CONFIG_YELLOW_LED, 1);
+   at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
+#endif
+#ifdef CONFIG_BLUE_LED 
+   at91_set_gpio_output(CONFIG_BLUE_LED, 1);
+   at91_set_gpio_value(CONFIG_BLUE_LED, 1);
+#endif  
+}
+
 #ifdef CONFIG_RED_LED
 void red_LED_on(void)
 {
at91_set_gpio_value(CONFIG_RED_LED, 1);
+   saved_state[STATUS_LED_RED] = STATUS_LED_ON;
 }
 
 void red_LED_off(void)
 {
at91_set_gpio_value(CONFIG_RED_LED, 0);
+   saved_state[STATUS_LED_RED] = STATUS_LED_OFF;
 }
 #endif
 
 #ifdef CONFIG_GREEN_LED
 void green_LED_on(void)
 {
-   at91_set_gpio_value(CONFIG_GREEN_LED, 0);
+   at91_set_gpio_value(CONFIG_GREEN_LED, 1);
+   saved_state[STATUS_LED_GREEN] = STATUS_LED_ON;
 }
 
 void green_LED_off(void)
 {
-   at91_set_gpio_value(CONFIG_GREEN_LED, 1);
+   at91_set_gpio_value(CONFIG_GREEN_LED, 0);
+   saved_state[STATUS_LED_GREEN] = STATUS_LED_OFF;
 }
 #endif
 
 #ifdef CONFIG_YELLOW_LED
 void yellow_LED_on(void)
 {
-   at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
+   at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
+   saved_state[STATUS_LED_YELLOW] = STATUS_LED_ON;
 }
 
 void yellow_LED_off(void)
 {
-   at91_set_gpio_value(CONFIG_YELLOW_LED, 1);
+   at91_set_gpio_value(CONFIG_YELLOW_LED, 0);
+   saved_state[STATUS_LED_YELLOW] = STATUS_LED_OFF;
 }
 #endif
+
+void __led_init(led_id_t mask, int state)
+{
+   __led_set(mask, state);
+}
+
+void __led_toggle(led_id_t mask)
+{
+
+#ifdef CONFIG_RED_LED  
+   if (STATUS_LED_RED == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_RED])
+   red_LED_off();
+   else
+   red_LED_on();
+   } 
+#endif
+#ifdef CONFIG_BLUE_LED
+   else if (STATUS_LED_BLUE == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_BLUE])
+   blue_LED_off();
+   else
+   blue_LED_on();
+   } 
+#endif
+#ifdef CONFIG_GREEN_LED
+   else if (STATUS_LED_GREEN == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_GREEN])
+   green_LED_off();
+   else
+   green_LED_on();
+   } 
+#endif
+#ifdef CONFIG_YELLOW_LED
+   else if (STATUS_LED_YELLOW == mask) {
+   if (STATUS_LED_ON == saved_state[STATUS_LED_YELLOW])
+   yellow_LED_off();
+   else
+   yellow_LED_on();
+   }
+#endif
+}
+
+void __led_set(led_id_t mask, int state)
+{
+#ifdef CONFIG_RED_LED  
+   if (STATUS_LED_RED == mask) {
+   if (STATUS_LED_ON == state)
+   red_LED_on();
+   else
+   red_LED_off();
+   } 
+#endif
+#ifdef CONFIG_BLUE_LED 
+else if (STATUS_LED_BLUE == mask) {
+   if (STATUS_LED_ON == state)
+   blue_LED_on();
+   else
+   blue_LED_off();
+   } 
+#endif
+#ifdef CONFIG_GREEN_LED
+   else if (STATUS_LED_GREEN == mask) {
+   if (STATUS_LED_ON == state)
+   green_LED_on();
+   else
+   green_LED_off();
+   } 
+#endif
+#ifdef CONFIG_YELLOW_LED   
+   else if (STATUS_LED_YELLOW == mask) {
+   if (STATUS_LED_ON == state)
+   yellow_LED_on();
+   else
+   yellow_LED_off();
+   }
+#endif
+}
+
diff --git a/common/Makefile b/common/Makefile
index 048df0c..a653c1e 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -163,6 +163,7 @@ COBJS-$(CONFIG_LCD) += lcd.o
 COBJS-$(CONFIG_LYNXKDI) += lynxkdi.o
 COBJS-$(CONFIG_MODEM_SUPPORT) += modem.o
 COBJS-$(CONFIG_UPDATE_TFTP) += update.o
+COBJS-$(CONFIG_USBD_DFU)+= update

[U-Boot] [PATCH v2 3/4] Add In-Circuit sam9g45_oem board

2011-02-13 Thread Marcel Janssen
From: Marcel 

sam9g45_oem cleanup phase1

sam9g45_oem cleanup phase2

sam9g45_oem cleanup phase3

Signed-off-by: Marcel 
---
 board/in-circuit/icnova/Makefile |   50 ++
 board/in-circuit/icnova/icnova_sam9g45.c |  242 
 boards.cfg   |1 +
 include/configs/icnova_sam9g45.h |  253 ++
 4 files changed, 546 insertions(+), 0 deletions(-)
 create mode 100644 board/in-circuit/icnova/Makefile
 create mode 100644 board/in-circuit/icnova/icnova_sam9g45.c
 create mode 100644 include/configs/icnova_sam9g45.h

diff --git a/board/in-circuit/icnova/Makefile b/board/in-circuit/icnova/Makefile
new file mode 100644
index 000..bf64680
--- /dev/null
+++ b/board/in-circuit/icnova/Makefile
@@ -0,0 +1,50 @@
+# (C) Copyright 2011 Marcel Janssen, Admesy B.V.
+# (C) Copyright 2001-2006
+# Wolfgang Denk, DENX Software Engineering, w...@denx.de.
+#
+# Copyright (C) 2005-2006 Atmel Corporation
+#
+# (C) 2008 - 2010 Benjamin Tietz, In-Circuit benjamin.ti...@in-circuit.de
+# (C) 2011Marcel Janssen, Admesy B.V.
+#
+# See file CREDITS for list of people who contributed to this
+# project.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation; either version 2 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+# MA 02111-1307 USA
+
+include $(TOPDIR)/config.mk
+include $(TOPDIR)/include/config.mk
+
+LIB:= $(obj)lib$(BOARD).o
+
+COBJS := icnova_sam9g45.o
+
+COBJS-y += $(COBJS)
+SRCS   := $(SOBJS:.o=.S) $(COBJS-y:.o=.c)
+OBJS   := $(addprefix $(obj),$(SOBJS) $(COBJS-y))
+
+# $(obj).depend
+$(LIB): $(OBJS)
+   $(AR) $(ARFLAGS) $@ $(OBJS)
+
+#
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#
diff --git a/board/in-circuit/icnova/icnova_sam9g45.c 
b/board/in-circuit/icnova/icnova_sam9g45.c
new file mode 100644
index 000..8407b0b
--- /dev/null
+++ b/board/in-circuit/icnova/icnova_sam9g45.c
@@ -0,0 +1,242 @@
+/*
+ * (C) 2010 Benjamin Tietz, In-Circuit 
+ *
+ * (C) Copyright 2007-2008
+ * Stelian Pop 
+ * Lead Tech Design 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#ifdef CONFIG_USBD_DFU
+#include 
+#endif
+
+#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
+#include 
+#endif
+#include 
+
+#if defined(CONFIG_USB_GADGET_ATMEL_USBA) && !defined(CONFIG_USB_GADGET)
+#error "Need CONFIG_USB_GADGET when CONFIG_USB_GADGET_ATMEL_USBA enabled"
+#endif
+
+
+DECLARE_GLOBAL_DATA_PTR;
+char bootbuf[20];
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+struct platform_data brd = {
+   .board = {
+   .vbus_pin   = AT91_PIN_PC0,
+   .pullup_pin = 1,
+   },
+   .udc_clk = AT91SAM9G45_ID_UDPHS,
+};
+#endif
+
+#ifdef CONFIG_CMD_NAND
+static void icnova_nand_hw_init(void)
+{
+   unsigned long csa;
+
+   /* Enable CS3 */
+   csa = at91_sys_read(AT91_MATRIX_EBICSA);
+   at91_sys_write(AT91_MATRIX_EBICSA,
+  csa | AT91_MATRIX_EBI_CS3A_SMC_SMARTMEDIA);
+
+   /* Configure SMC CS3 for NAND/SmartMedia */
+   at91_sys_write(AT91_SMC_SETUP(3),
+  AT91_SMC_NWESETUP_(8) | AT91_SMC_NCS_WRSETUP_(0) |
+  AT91_SMC_NRDSETUP_(8) | AT91_SMC_NCS_RDSETUP_(0));
+   at91_sys_write(AT91_SMC_PULSE(3),
+  AT91_SMC_NWEPULSE_(28) 

[U-Boot] [PATCH v2 2/4] USB DFU driver added

2011-02-13 Thread Marcel Janssen
From: Marcel 

USB DFU driver cleaning phase1

USB DFU driver cleaning phase2

USB DFU driver cleaning phase3

USB DFU driver cleaning phase4

Signed-off-by: Marcel 
---
 common/update_dfu.c   |   89 +++
 doc/README.dfu|  129 
 drivers/usb/gadget/Makefile   |9 +
 drivers/usb/gadget/usbdfu.c   | 1336 +
 include/usb_dfu.h |  128 
 include/usb_dfu_descriptors.h |  100 +++
 6 files changed, 1791 insertions(+), 0 deletions(-)
 create mode 100644 common/update_dfu.c
 create mode 100644 doc/README.dfu
 create mode 100644 drivers/usb/gadget/usbdfu.c
 create mode 100644 include/usb_dfu.h
 create mode 100644 include/usb_dfu_descriptors.h

diff --git a/common/update_dfu.c b/common/update_dfu.c
new file mode 100644
index 000..f1ceccf
--- /dev/null
+++ b/common/update_dfu.c
@@ -0,0 +1,89 @@
+/*
+ * (C) Copyright 2011 Marcel Janssen, Admesy B.V.
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include 
+DECLARE_GLOBAL_DATA_PTR;
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+#include 
+#endif
+#ifdef CONFIG_USB_GADGET_AT91
+#include 
+#endif
+#include 
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+struct platform_data dfubrd = {
+   .board = {
+   .vbus_pin   = AT91_PIN_PC0,
+   .pullup_pin = 1,
+   },
+   .udc_clk = AT91SAM9G45_ID_UDPHS,
+};
+#endif
+
+int dfu_loop(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+   int rcv;
+
+   dfu_finished = 0;
+
+   /* initialize the USBD controller */
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+   usba_udc_probe(&dfubrd);
+   udelay(10);
+#endif
+#ifdef CONFIG_USB_GADGET_AT91
+   at91udc_probe(&dfubrd);
+   udelay(10);
+#endif
+   if (usb_dfu_init() == 0) {
+   while (1) {
+   /* Handle control-c and timeouts */
+   rcv = usb_gadget_handle_interrupts();
+   if (rcv)
+   if (ctrlc())
+   goto dfu_end;
+   }
+   return 0;
+   }
+   return -1;
+dfu_end:
+   return -1;
+}
+
+U_BOOT_CMD(
+   dfu,CONFIG_SYS_MAXARGS, 1,  dfu_loop,
+   "Start DFU function",
+   "No params, see README.dfu"
+);
diff --git a/doc/README.dfu b/doc/README.dfu
new file mode 100644
index 000..363c7a2
--- /dev/null
+++ b/doc/README.dfu
@@ -0,0 +1,129 @@
+USBD DFU mode
+
+Initially written by Marcel Janssen, Admesy B.V.
+Based on parts from OpenMoko, ether.c and update.c
+
+
+
+
+This describes the DFU implementation in u-boot.
+
+The implementation works with dfu-utils to upgrade NAND partitions defined by
+mtdparts.
+The board configuration file needs serveral CONFIG options to be set.
+DFU is implemented to be executed as a command "dfu" (common/update_dfu.c).
+This command should start the USB device controller and the DFU driver.
+A typical implementation would be that a script is executed, that will check
+whether DFU should be started. If so, it can execute 'dfu" and the device will
+announce itself to the host as a DFU capable device.
+dfu-util can than be used to upgrade the partitions defined by mtdparts.
+
+Description of flow :
+dfu-utils sets the alternate interface which corresponds to the selected
+partition.
+The file (uImage, rootfs.arm.jffs2) is loaded fully to RAM first.
+U-boot nand routines are used to write from RAM to NAND.
+
+LED usage :
+Status LED's can be defined to show DFU action.
+Define the RED and GREEN leds to make this happen.
+
+Initial testing example :
+This was done on the in-circuit icnova_sam9g45 board.
+This board uses atmel_usbd_udc.c
+
+
+
+
+
+To make DFU work you need a working USB controller, for example at91_udc or
+atmel_usba_udc. Make sure to set it in the board config file.
+
+
+USBD CONFIG options
+
+
+#define CONFIG_USB_GADGET

[U-Boot] [PATCH v2 1/4] Add Atmel USBA UDC

2011-02-13 Thread Marcel Janssen
From: Marcel 

Atmel USBA UDC cleanup

Atmel USBA UDC cleanup

more cleanup of Atmel USBA UDC

Some more cleaning of Atmel USBA UDC

further cleaning of Atmel USBA UDC

Signed-off-by: Marcel 
---
 drivers/usb/gadget/Makefile |1 +
 drivers/usb/gadget/atmel_usba_udc.c | 1438 +++
 include/usb/atmel_usba_udc.h|  398 ++
 3 files changed, 1837 insertions(+), 0 deletions(-)
 create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
 create mode 100644 include/usb/atmel_usba_udc.h

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 0846233..024844d 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -29,6 +29,7 @@ LIB   := $(obj)libusb_gadget.o
 ifdef CONFIG_USB_ETHER
 COBJS-y += ether.o epautoconf.o config.o usbstring.o
 COBJS-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
+COBJS-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
 else
 # Devices not related to the new gadget layer depend on CONFIG_USB_DEVICE
 ifdef CONFIG_USB_DEVICE
diff --git a/drivers/usb/gadget/atmel_usba_udc.c 
b/drivers/usb/gadget/atmel_usba_udc.c
new file mode 100644
index 000..6d02de6
--- /dev/null
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -0,0 +1,1438 @@
+/*
+ * Driver for the Atmel USBA high speed USB device controller
+ *
+ * Copyright (C) 2011 Marcel Janssen, Admesy B.V.
+ * Copyright (C) 2005-2007 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#define __iomem
+
+#define memcpy_toio(a, b, c)memcpy((a), (b), (c))
+#define memcpy_fromio(a, b, c)  memcpy((a), (b), (c))
+#define REQ_COUNT 8
+#define MAX_REQ (REQ_COUNT-1)
+
+static struct usba_udc the_udc;
+#define true 1
+#define false 0
+static const char driver_name[] = "atmel_usba_udc";
+static const char ep0name[] = "ep0";
+
+
+static void next_fifo_transaction(struct usba_ep *ep, struct usba_request *req)
+{
+   unsigned int transaction_len;
+
+   transaction_len = req->req.length - req->req.actual;
+   req->last_transaction = 1;
+   if (transaction_len > ep->ep.maxpacket) {
+   transaction_len = ep->ep.maxpacket;
+   req->last_transaction = 0;
+   } else if (transaction_len == ep->ep.maxpacket && req->req.zero)
+   req->last_transaction = 0;
+
+   debug("%s: submit_transaction, req %p (length %d)%s\n",
+   ep->ep.name, req, transaction_len,
+   req->last_transaction ? ", done" : "");
+
+   memcpy_toio(ep->fifo, req->req.buf + req->req.actual, transaction_len);
+   usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
+   req->req.actual += transaction_len;
+}
+
+static void submit_request(struct usba_ep *ep, struct usba_request *req)
+{
+
+   req->req.actual = 0;
+   req->submitted = 1;
+
+   debug("%s : submit_request: req %p (length %d)\n",
+   ep->ep.name, req, req->req.length);
+   next_fifo_transaction(ep, req);
+   if (req->last_transaction) {
+   usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY);
+   usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
+   } else {
+   usba_ep_writel(ep, CTL_DIS, USBA_TX_COMPLETE);
+   usba_ep_writel(ep, CTL_ENB, USBA_TX_PK_RDY);
+   }
+}
+
+static void submit_next_request(struct usba_ep *ep)
+{
+   struct usba_request *req;
+
+   if (list_empty(&ep->queue)) {
+   usba_ep_writel(ep, CTL_DIS, USBA_TX_PK_RDY | USBA_RX_BK_RDY);
+   return;
+   }
+   req = list_entry(ep->queue.next, struct usba_request, queue);
+   if (!req->submitted)
+   submit_request(ep, req);
+   debug("%s : submit_next_request: req %p (length %d)\n",
+   ep->ep.name, req, req->req.length);
+}
+
+static void send_status(struct usba_udc *udc, struct usba_ep *ep)
+{
+   debug("Send USBA status\n");
+   ep->state = STATUS_STAGE_IN;
+   usba_ep_writel(ep, SET_STA, USBA_TX_PK_RDY);
+   usba_ep_writel(ep, CTL_ENB, USBA_TX_COMPLETE);
+}
+
+static void receive_data(struct usba_ep *ep)
+{
+   struct usba_udc *udc = ep->udc;
+   struct usba_request *req;
+   unsigned long status;
+   unsigned int bytecount, nr_busy;
+   int is_complete = 0;
+
+   status = usba_ep_readl(ep, STA);
+   nr_busy = USBA_BFEXT(BUSY_BANKS, status);
+
+   debug("receive data: nr_busy=%u\n", 

[U-Boot] [PATCH v2 0/4] DFU implementation for Atmel SAM9G45

2011-02-13 Thread Marcel Janssen
From: Marcel 

These patches apply to u-boot-usb, cdc-at91 branch.
They contain a working implementation of USB DFU.
Most is documented in README.dfu.

A little background on the implementation :
The controller code (atmel_usba_udc) should also work with the gadget ethernet
driver. I tested it a couple of weeks ago to be fully functional. However, 
haven't
used this driver since, as I focussed on getting DFU to work.

I included some verdor specific command in the DFU code. This is purely ment as 
an
example where to add such code. However, it is a usefull example so I left it 
in 
the code.
Further, my original code relies on the use of the GPBR to write to from Linux.
This code has not been included in the patches yet because of lack of time.
I can however send it in later this week perhaps. It's basic purpose is just
to reboot from Linux and let u-boot know what to do (wait for a DFU download).
U-boot than read the GPBR register and acts depending on it's value, meaning 
either
wait for TFTP action or DFU action.

The patches have been checked by checkpatch and produce a few warnings
(so do some other files already in git). I currently don't have the time
to fix them, but hope someone else can work on this. If not, I will pick
up on this in a couple of weeks/months. Sorry guys, did my best to fix them 
all, 
but some slipped.

This week I'm still available for comments on the above mail address.
After that I can't use the above email for the next couple of weeks/months
and also won't be reading the mailing list. If anyone needs my help, please
see below for my email address.

I'm very sorry if I didn't comply to all suggested changes. I tried, but
time is my biggest enemy in this. I rather post something that works for me
than post nothing as I may not be able to post for the next couple of months.
Since the cdc-at91 brach is not mainstream, I guess it would be ok to
apply these patches so that they can be used and fixed by anyone who likes it.

Unfortunately some last minute fixed in the last patch, but this shoudn't be a 
big issue I think. I did work off-tree for my impementation which caused this.

The current patches have been checked to compile and work for my board.

Best regards,
Marcel (marcel_dot_janssen_at_admesy_dot_nl)


Marcel (4):
  Add Atmel USBA UDC
  USB DFU driver added
  Add In-Circuit sam9g45_oem board
  updates for DFU and atmel usba udc

 arch/arm/cpu/arm926ejs/at91/led.c|  119 +++-
 board/in-circuit/icnova/Makefile |   50 +
 board/in-circuit/icnova/icnova_sam9g45.c |  242 +
 boards.cfg   |1 +
 common/Makefile  |1 +
 common/update_dfu.c  |   87 ++
 doc/README.dfu   |  129 +++
 drivers/usb/gadget/Makefile  |   10 +
 drivers/usb/gadget/atmel_usba_udc.c  | 1438 ++
 drivers/usb/gadget/usbdfu.c  | 1338 +++
 include/configs/icnova_sam9g45.h |  253 ++
 include/usb/atmel_usba_udc.h |  398 +
 include/usb_dfu.h|  128 +++
 include/usb_dfu_descriptors.h|  100 ++
 14 files changed, 4290 insertions(+), 4 deletions(-)
 create mode 100644 board/in-circuit/icnova/Makefile
 create mode 100644 board/in-circuit/icnova/icnova_sam9g45.c
 create mode 100644 common/update_dfu.c
 create mode 100644 doc/README.dfu
 create mode 100644 drivers/usb/gadget/atmel_usba_udc.c
 create mode 100644 drivers/usb/gadget/usbdfu.c
 create mode 100644 include/configs/icnova_sam9g45.h
 create mode 100644 include/usb/atmel_usba_udc.h
 create mode 100644 include/usb_dfu.h
 create mode 100644 include/usb_dfu_descriptors.h

-- 
1.7.3.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 3/3] add icnova sam9g45 board

2011-02-12 Thread Marcel Janssen
s1) & 0x4040) {
+   printf("Flash write error at address 0x%p: "
+  "0x%02x != 0x%02x\n",
+  p, status,word);
+   ret = ERR_PROG_ERROR;
+   writew(0xf0f0, base);
+   readw(base);
+   break;
+   }
+
+   writew(0xf0f0, base);
+   readw(base);
+   }
+
+   if (flags)
+   enable_interrupts();
+
+   return ret;
+}
diff --git a/board/in-circuit/icnova/icnova_arm.c 
b/board/in-circuit/icnova/icnova_arm.c
new file mode 100644
index 000..6b68a6e
--- /dev/null
+++ b/board/in-circuit/icnova/icnova_arm.c
@@ -0,0 +1,259 @@
+/*
+ * (C) 2011 Marcel Janssen, Admesy B.V.
+ * (C) 2010 Benjamin Tietz, In-Circuit 
+ *
+ * (C) Copyright 2007-2008
+ * Stelian Pop 
+ * Lead Tech Design 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#ifdef CONFIG_USBD_DFU 
+#include 
+#endif
+//#include 
+#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
+#include 
+#endif
+#include 
+#include "nand.h"
+
+#if defined(CONFIG_USB_GADGET_ATMEL_USBA) && !defined(CONFIG_USB_GADGET)
+#error "Need CONFIG_USB_GADGET when CONFIG_USB_GADGET_ATMEL_USBA enabled"
+#endif
+int dfu_loop(void);
+
+DECLARE_GLOBAL_DATA_PTR;
+char bootbuf[20];
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+struct platform_data brd = {
+   .board = {
+   //.vbus_pin   = AT91_PIN_PC9,// AT91_PIN_PC0, },
+   .vbus_pin   = AT91_PIN_PC0,
+   .pullup_pin = 1,
+   },
+   .udc_clk = AT91SAM9G45_ID_UDPHS,
+};
+#endif
+
+#ifdef CONFIG_MACB
+static void icnova_arm9_macb_hw_init(void)
+{  
+   /*
+* Disable pull-up on:
+*  RXDV (PA15) => PHY normal mode (not Test mode)
+*  ERX0 (PA12) => PHY ADDR0
+*  ERX1 (PA13) => PHY ADDR1 
+*  ERX2 (PA8) => PHY ADDR2
+*  ERX3 (PA9) => PHY ADDR3
+*  ECRS (PA29) => PHY ADDR4 => PHYADDR = 0x0
+*  ECOL  (PA30) => full MII interface
+*  ERXER (PA16) => no repeater
+*  ETXCLK (PA17) => no isolate
+*/
+   unsigned long phy_mask = 0;
+   /* Reset and pdwn-pins */
+   unsigned long rst = pin_to_mask(AT91_PIN_PA27);
+   unsigned long pdwn = 0;
+   phy_mask = pin_to_mask(AT91_PIN_PA15) |
+pin_to_mask(AT91_PIN_PA8) | 
+pin_to_mask(AT91_PIN_PA9) |
+pin_to_mask(AT91_PIN_PA12) | 
+pin_to_mask(AT91_PIN_PA13) |
+pin_to_mask(AT91_PIN_PA29) | 
+pin_to_mask(AT91_PIN_PA30) |
+pin_to_mask(AT91_PIN_PA16) | 
+pin_to_mask(AT91_PIN_PA17);
+   /* Reset and pdwn-pins */
+   rst = pin_to_mask(AT91_PIN_PA26);
+   pdwn = pin_to_mask(AT91_PIN_PA25);
+   /* Enable clock */
+   at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9G45_ID_EMAC);
+   /*
+* Set up Pins
+*/
+   writel(rst | pdwn | phy_mask,
+  pin_to_controller(AT91_PIN_PA0) + PIO_PER);
+   writel(rst | pdwn | phy_mask,
+  pin_to_controller(AT91_PIN_PA0) + PIO_OER);
+   writel(rst | pdwn | phy_mask,
+  pin_to_controller(AT91_PIN_PA0) + PIO_CODR);
+   udelay(1000);
+   writel(rst,
+  pin_to_controller(AT91_PIN_PA0) + PIO_SODR);
+   udelay(50);
+   // phy-mask will be resetted by internal hardware 
+
+#if 0
+   rstc = readl(AT91_BASE_SYS + AT91_RSTC_MR);
+
+   /* Need to reset PHY -> 500ms reset */
+   writel(AT91_BASE_SYS + AT91_RSTC_MR, AT91_RSTC_KEY |
+(AT91_RSTC_ERSTL & (0x0D << 8)) |
+AT91_RSTC_URSTEN);
+
+   writel(AT91_BASE_SYS + AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST

[U-Boot] [PATCH 2/3] add USB DFU driver

2011-02-12 Thread Marcel Janssen
From: Marcel 

Signed-off-by: Marcel 
---
 common/update_dfu.c |   90 +++
 doc/README.dfu  |  129 
 drivers/usb/gadget/Makefile |   10 +-
 drivers/usb/gadget/usbdfu.c | 1470 +++
 4 files changed, 1697 insertions(+), 2 deletions(-)
 create mode 100644 common/update_dfu.c
 create mode 100644 doc/README.dfu
 create mode 100644 drivers/usb/gadget/usbdfu.c

diff --git a/common/update_dfu.c b/common/update_dfu.c
new file mode 100644
index 000..5f8da42
--- /dev/null
+++ b/common/update_dfu.c
@@ -0,0 +1,90 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * Written by: Rafal Czubak 
+ * Bartlomiej Sieka 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include 
+DECLARE_GLOBAL_DATA_PTR;
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+int dfu_finished;
+int usb_dfu_init(void);
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+struct platform_data dfubrd = {
+   .board = {
+   //.vbus_pin   = AT91_PIN_PC9,// AT91_PIN_PC0, },
+   .vbus_pin   = AT91_PIN_PC0,
+   .pullup_pin = 1,
+   },
+   .udc_clk = AT91SAM9G45_ID_UDPHS,
+};
+#endif
+
+int dfu_loop(void)
+{
+   int rcv;
+   
+   dfu_finished = 0;
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+   usba_udc_probe(&dfubrd);
+#endif 
+#ifdef CONFIG_USB_GADGET_AT91
+   at91udc_probe(&dfubrd);
+#endif
+   udelay(10);
+
+   if(usb_dfu_init() == 0)
+   {
+   
+ while (!dfu_finished ) {
+   /* Handle control-c and timeouts */
+   rcv = usb_gadget_handle_interrupts();
+   if(rcv) 
+   if (ctrlc()) goto dfu_end;
+ }
+ return 0;
+   }
+   return -1;
+dfu_end:
+   return -1;
+}
+
+U_BOOT_CMD(
+   dfu,1,  0,  dfu_loop,
+   "Start DFU function",
+   "No params, see README.dfu"
+);
+ 
\ No newline at end of file
diff --git a/doc/README.dfu b/doc/README.dfu
new file mode 100644
index 000..04b7b76
--- /dev/null
+++ b/doc/README.dfu
@@ -0,0 +1,129 @@
+USBD DFU mode 
+
+Initially written by Marcel Janssen (marcel.jans...@admesy.nl).
+Based on parts from OpenMoko, ether.c and update.c
+
+
+
+
+This describes the DFU implementation in u-boot.
+
+The implementation works with dfu-utils to upgrade NAND partitions defined by 
mtdparts.
+The board configuration file needs serveral CONFIG options to be set.
+DFU is implemented to be executed as a command "dfu". This command should 
start the USB device
+controller and the DFU driver. This is done in common/update_dfu.c
+
+A typical implementation would be that a script is executed, that will check 
whether DFU should 
+be started. If so, it executes 'dfu" and the device will announce itself to 
the host as a DFU
+capable device. dfu-util can than be used to upgrade the partitions defined by 
mtdparts.
+
+Description of flow :
+dfu-utils sets the alternate interface which corresponds to the selected 
partition.
+The file (uImage, rootfs.arm.jffs2) is loaded fully to RAM first.
+U-boot nand routines are used to write from RAM to NAND.
+
+LED usage :
+Status LED's can be defined to show DFU action.
+Define the RED and GREEN leds to make this happen.
+
+Initial testing example :
+This was done on the in-circuit sam9g45_oem board. This board uses 
atmel_usbd_udc.c
+
+
+
+
+
+To make DFU work you need a working USB controller, for example at91_udc or 
atmel_usba_udc.
+Make sure to set it in the board config file 
+
+
+USBD CONFIG options 
+
+
+#define CONFIG_USB_GADGET  
+#define CONFIG_USB_GADGET_ATMEL_USBA   (or  #define CONFIG_USB_GADGET_AT91_UDC 
)
+#define CONFIG_USB_GADGET_DUALSPEED 
+
+
+USBD CONFIG options end
+
+
+
+
+The DFU driver has a few options. 
+Make sure that CONFIG_USBD_DFU_XFER_SIZE does not exceed your USB_BUFSIZE.
+
+===

[U-Boot] [PATCH 4/4] add icnova sam9g45 board

2011-02-12 Thread Marcel Janssen
printf("Flash write error at address 0x%p: "
+  "0x%02x != 0x%02x\n",
+  p, status,word);
+   ret = ERR_PROG_ERROR;
+   writew(0xf0f0, base);
+   readw(base);
+   break;
+   }
+
+   writew(0xf0f0, base);
+   readw(base);
+   }
+
+   if (flags)
+   enable_interrupts();
+
+   return ret;
+}
diff --git a/board/in-circuit/icnova/icnova_arm.c 
b/board/in-circuit/icnova/icnova_arm.c
new file mode 100644
index 000..6b68a6e
--- /dev/null
+++ b/board/in-circuit/icnova/icnova_arm.c
@@ -0,0 +1,259 @@
+/*
+ * (C) 2011 Marcel Janssen, Admesy B.V.
+ * (C) 2010 Benjamin Tietz, In-Circuit 
+ *
+ * (C) Copyright 2007-2008
+ * Stelian Pop 
+ * Lead Tech Design 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#ifdef CONFIG_USBD_DFU 
+#include 
+#endif
+//#include 
+#if defined(CONFIG_RESET_PHY_R) && defined(CONFIG_MACB)
+#include 
+#endif
+#include 
+#include "nand.h"
+
+#if defined(CONFIG_USB_GADGET_ATMEL_USBA) && !defined(CONFIG_USB_GADGET)
+#error "Need CONFIG_USB_GADGET when CONFIG_USB_GADGET_ATMEL_USBA enabled"
+#endif
+int dfu_loop(void);
+
+DECLARE_GLOBAL_DATA_PTR;
+char bootbuf[20];
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+struct platform_data brd = {
+   .board = {
+   //.vbus_pin   = AT91_PIN_PC9,// AT91_PIN_PC0, },
+   .vbus_pin   = AT91_PIN_PC0,
+   .pullup_pin = 1,
+   },
+   .udc_clk = AT91SAM9G45_ID_UDPHS,
+};
+#endif
+
+#ifdef CONFIG_MACB
+static void icnova_arm9_macb_hw_init(void)
+{  
+   /*
+* Disable pull-up on:
+*  RXDV (PA15) => PHY normal mode (not Test mode)
+*  ERX0 (PA12) => PHY ADDR0
+*  ERX1 (PA13) => PHY ADDR1 
+*  ERX2 (PA8) => PHY ADDR2
+*  ERX3 (PA9) => PHY ADDR3
+*  ECRS (PA29) => PHY ADDR4 => PHYADDR = 0x0
+*  ECOL  (PA30) => full MII interface
+*  ERXER (PA16) => no repeater
+*  ETXCLK (PA17) => no isolate
+*/
+   unsigned long phy_mask = 0;
+   /* Reset and pdwn-pins */
+   unsigned long rst = pin_to_mask(AT91_PIN_PA27);
+   unsigned long pdwn = 0;
+   phy_mask = pin_to_mask(AT91_PIN_PA15) |
+pin_to_mask(AT91_PIN_PA8) | 
+pin_to_mask(AT91_PIN_PA9) |
+pin_to_mask(AT91_PIN_PA12) | 
+pin_to_mask(AT91_PIN_PA13) |
+pin_to_mask(AT91_PIN_PA29) | 
+pin_to_mask(AT91_PIN_PA30) |
+pin_to_mask(AT91_PIN_PA16) | 
+pin_to_mask(AT91_PIN_PA17);
+   /* Reset and pdwn-pins */
+   rst = pin_to_mask(AT91_PIN_PA26);
+   pdwn = pin_to_mask(AT91_PIN_PA25);
+   /* Enable clock */
+   at91_sys_write(AT91_PMC_PCER, 1 << AT91SAM9G45_ID_EMAC);
+   /*
+* Set up Pins
+*/
+   writel(rst | pdwn | phy_mask,
+  pin_to_controller(AT91_PIN_PA0) + PIO_PER);
+   writel(rst | pdwn | phy_mask,
+  pin_to_controller(AT91_PIN_PA0) + PIO_OER);
+   writel(rst | pdwn | phy_mask,
+  pin_to_controller(AT91_PIN_PA0) + PIO_CODR);
+   udelay(1000);
+   writel(rst,
+  pin_to_controller(AT91_PIN_PA0) + PIO_SODR);
+   udelay(50);
+   // phy-mask will be resetted by internal hardware 
+
+#if 0
+   rstc = readl(AT91_BASE_SYS + AT91_RSTC_MR);
+
+   /* Need to reset PHY -> 500ms reset */
+   writel(AT91_BASE_SYS + AT91_RSTC_MR, AT91_RSTC_KEY |
+(AT91_RSTC_ERSTL & (0x0D << 8)) |
+AT91_RSTC_URSTEN);
+
+   writel(AT91_BASE_SYS + AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_EXTRST);
+
+   /* Wait for end hardware reset */

[U-Boot] [PATCH 3/4] add USB DFU driver

2011-02-12 Thread Marcel Janssen
From: Marcel 

Signed-off-by: Marcel 
---
 common/update_dfu.c |   90 +++
 doc/README.dfu  |  129 
 drivers/usb/gadget/Makefile |   10 +-
 drivers/usb/gadget/usbdfu.c | 1470 +++
 4 files changed, 1697 insertions(+), 2 deletions(-)
 create mode 100644 common/update_dfu.c
 create mode 100644 doc/README.dfu
 create mode 100644 drivers/usb/gadget/usbdfu.c

diff --git a/common/update_dfu.c b/common/update_dfu.c
new file mode 100644
index 000..5f8da42
--- /dev/null
+++ b/common/update_dfu.c
@@ -0,0 +1,90 @@
+/*
+ * (C) Copyright 2008 Semihalf
+ *
+ * Written by: Rafal Czubak 
+ * Bartlomiej Sieka 
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ *
+ */
+
+#include 
+DECLARE_GLOBAL_DATA_PTR;
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+int dfu_finished;
+int usb_dfu_init(void);
+
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+struct platform_data dfubrd = {
+   .board = {
+   //.vbus_pin   = AT91_PIN_PC9,// AT91_PIN_PC0, },
+   .vbus_pin   = AT91_PIN_PC0,
+   .pullup_pin = 1,
+   },
+   .udc_clk = AT91SAM9G45_ID_UDPHS,
+};
+#endif
+
+int dfu_loop(void)
+{
+   int rcv;
+   
+   dfu_finished = 0;
+#ifdef CONFIG_USB_GADGET_ATMEL_USBA
+   usba_udc_probe(&dfubrd);
+#endif 
+#ifdef CONFIG_USB_GADGET_AT91
+   at91udc_probe(&dfubrd);
+#endif
+   udelay(10);
+
+   if(usb_dfu_init() == 0)
+   {
+   
+ while (!dfu_finished ) {
+   /* Handle control-c and timeouts */
+   rcv = usb_gadget_handle_interrupts();
+   if(rcv) 
+   if (ctrlc()) goto dfu_end;
+ }
+ return 0;
+   }
+   return -1;
+dfu_end:
+   return -1;
+}
+
+U_BOOT_CMD(
+   dfu,1,  0,  dfu_loop,
+   "Start DFU function",
+   "No params, see README.dfu"
+);
+ 
\ No newline at end of file
diff --git a/doc/README.dfu b/doc/README.dfu
new file mode 100644
index 000..04b7b76
--- /dev/null
+++ b/doc/README.dfu
@@ -0,0 +1,129 @@
+USBD DFU mode 
+
+Initially written by Marcel Janssen (marcel.jans...@admesy.nl).
+Based on parts from OpenMoko, ether.c and update.c
+
+
+
+
+This describes the DFU implementation in u-boot.
+
+The implementation works with dfu-utils to upgrade NAND partitions defined by 
mtdparts.
+The board configuration file needs serveral CONFIG options to be set.
+DFU is implemented to be executed as a command "dfu". This command should 
start the USB device
+controller and the DFU driver. This is done in common/update_dfu.c
+
+A typical implementation would be that a script is executed, that will check 
whether DFU should 
+be started. If so, it executes 'dfu" and the device will announce itself to 
the host as a DFU
+capable device. dfu-util can than be used to upgrade the partitions defined by 
mtdparts.
+
+Description of flow :
+dfu-utils sets the alternate interface which corresponds to the selected 
partition.
+The file (uImage, rootfs.arm.jffs2) is loaded fully to RAM first.
+U-boot nand routines are used to write from RAM to NAND.
+
+LED usage :
+Status LED's can be defined to show DFU action.
+Define the RED and GREEN leds to make this happen.
+
+Initial testing example :
+This was done on the in-circuit sam9g45_oem board. This board uses 
atmel_usbd_udc.c
+
+
+
+
+
+To make DFU work you need a working USB controller, for example at91_udc or 
atmel_usba_udc.
+Make sure to set it in the board config file 
+
+
+USBD CONFIG options 
+
+
+#define CONFIG_USB_GADGET  
+#define CONFIG_USB_GADGET_ATMEL_USBA   (or  #define CONFIG_USB_GADGET_AT91_UDC 
)
+#define CONFIG_USB_GADGET_DUALSPEED 
+
+
+USBD CONFIG options end
+
+
+
+
+The DFU driver has a few options. 
+Make sure that CONFIG_USBD_DFU_XFER_SIZE does not exceed your USB_BUFSIZE.
+
+===

[U-Boot] [PATCH 2/4] Add Atmel USBA UDC

2011-02-12 Thread Marcel Janssen
From: Marcel 

Signed-off-by: Marcel 
---
 drivers/usb/gadget/Makefile |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 0846233..024844d 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -29,6 +29,7 @@ LIB   := $(obj)libusb_gadget.o
 ifdef CONFIG_USB_ETHER
 COBJS-y += ether.o epautoconf.o config.o usbstring.o
 COBJS-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
+COBJS-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
 else
 # Devices not related to the new gadget layer depend on CONFIG_USB_DEVICE
 ifdef CONFIG_USB_DEVICE
-- 
1.7.3.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH 2/2] Add Atmel USBA UDC

2011-02-12 Thread Marcel Janssen
From: Marcel 

Signed-off-by: Marcel 
---
 drivers/usb/gadget/Makefile |1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index 0846233..024844d 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -29,6 +29,7 @@ LIB   := $(obj)libusb_gadget.o
 ifdef CONFIG_USB_ETHER
 COBJS-y += ether.o epautoconf.o config.o usbstring.o
 COBJS-$(CONFIG_USB_GADGET_AT91) += at91_udc.o
+COBJS-$(CONFIG_USB_GADGET_ATMEL_USBA) += atmel_usba_udc.o
 else
 # Devices not related to the new gadget layer depend on CONFIG_USB_DEVICE
 ifdef CONFIG_USB_DEVICE
-- 
1.7.3.4

___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot