linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [RFC] [PATCH] usb: gadget: fix dtd dma confusion
       [not found]                 ` <CAOMZO5C729Ki0Bequ+s1nnrgt4NZWvwg3Wnjk4kHp=d9BtkeXw@mail.gmail.com>
@ 2012-05-09  0:02                   ` Christoph Fritz
  2012-05-09  1:50                     ` Neil Zhang
  2012-05-13 22:51                     ` Christoph Fritz
  0 siblings, 2 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-05-09  0:02 UTC (permalink / raw)
  To: Fabio Estevam, Neil Zhang, Li Yang, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb, linuxppc-dev, Hans J. Koch,
	Daniel Mack
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Chen Peter-B29397,
	Sascha Hauer, Nicolas Ferre, Haojian Zhuang,
	Estevam Fabio-R49496, Ido Shayevitz, Ben Dooks, Thomas Dahlmann,
	Russell King

On Wed, Apr 11, 2012 at 10:15:49AM -0300, Fabio Estevam wrote:
> On Wed, Apr 11, 2012 at 4:39 AM, Christoph Fritz
> <chf.fritz@googlemail.com> wrote:
> 
> > Can you approve this behaviour of g_ether/usbnet when using iperf?
> 
> I am not very familiar with iperf, so I will let others comment.

Hi to All,

after a while of testing and searching I can come up with a patch
that fixes g_ether <-> iperf for fsl_udc on ARM i.MX35.

The sad part is that this kind of fix is already implemented for
marvell mv_udc driver since last year but still _not_ in the ~15
other *udc.c drivers.

See here:
daec765da767e4a6a30e1298862b28f2cae9a73f
usb: gadget: mv_udc: fix dtd dma confusion

So hereby I'm CC-ing all *udc.c maintainers to point out that this
issue maybe affects you too.

And maybe someone can explain if this: 
+				if (curr_td->next_td_ptr == EP_QUEUE_HEAD_NEXT_TERMINATE) {
is necessary and why (please see below).


Thanks,
 -- Christoph

---
Subject: [PATCH] usb: gadget: fsl_udc: fix dtd dma confusion

The controller will hang when doing testings with g_ether and iperf
(tool for measuring maximum TCP and UDP bandwidth).  This patch adds a
delay to wait for controller to release dtd dma before freeing it.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 55abfb6..fc86108 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1638,6 +1638,15 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
 			status = REQ_UNCOMPLETE;
 			return status;
 		} else if (remaining_length) {
+			/* wait controller release dtd dma */
+			while ((curr_qh->curr_dtd_ptr == curr_td->td_dma)) {
+				if (curr_td->next_td_ptr ==
+						EP_QUEUE_HEAD_NEXT_TERMINATE) {
+					udelay(100);
+					break;
+				}
+				udelay(1);
+			}
 			if (direction) {
 				VDBG("Transmit dTD remaining length not zero");
 				status = -EPROTO;
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* RE: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  0:02                   ` [RFC] [PATCH] usb: gadget: fix dtd dma confusion Christoph Fritz
@ 2012-05-09  1:50                     ` Neil Zhang
  2012-05-09  2:11                       ` Chen Peter-B29397
  2012-05-13 22:51                     ` Christoph Fritz
  1 sibling, 1 reply; 42+ messages in thread
From: Neil Zhang @ 2012-05-09  1:50 UTC (permalink / raw)
  To: Christoph Fritz, Fabio Estevam, Li Yang, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb, linuxppc-dev, Hans J. Koch,
	Daniel Mack
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Chen Peter-B29397,
	Sascha Hauer, Nicolas Ferre, Haojian Zhuang,
	Estevam Fabio-R49496, Ido Shayevitz, Ben Dooks, Thomas Dahlmann,
	Russell King, Chao Xie

SGkgQ2hyaXN0b3BoLA0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IENo
cmlzdG9waCBGcml0eiBbbWFpbHRvOmNoZi5mcml0ekBnb29nbGVtYWlsLmNvbV0NCj4gU2VudDog
MjAxMsTqNdTCOcjVIDg6MDINCj4gVG86IEZhYmlvIEVzdGV2YW07IE5laWwgWmhhbmc7IExpIFlh
bmc7IEZlbGlwZSBCYWxiaTsgR3JlZyBLcm9haC0NCj4gSGFydG1hbjsgbGludXgtdXNiQHZnZXIu
a2VybmVsLm9yZzsgbGludXhwcGMtZGV2QGxpc3RzLm96bGFicy5vcmc7IEhhbnMNCj4gSi4gS29j
aDsgRGFuaWVsIE1hY2sNCj4gQ2M6IFRob21hcyBEYWhsbWFubjsgTmljb2xhcyBGZXJyZTsgRXJp
YyBNaWFvOyBSdXNzZWxsIEtpbmc7IEhhb2ppYW4NCj4gWmh1YW5nOyBCZW4gRG9va3M7IEt1a2pp
biBLaW07IFNhc2NoYSBIYXVlcjsgT2xpdmVyIE5ldWt1bTsgQ2hlbiBQZXRlci0NCj4gQjI5Mzk3
OyBJZG8gU2hheWV2aXR6OyBFc3RldmFtIEZhYmlvLVI0OTQ5Ng0KPiBTdWJqZWN0OiBbUkZDXSBb
UEFUQ0hdIHVzYjogZ2FkZ2V0OiBmaXggZHRkIGRtYSBjb25mdXNpb24NCj4gDQo+IE9uIFdlZCwg
QXByIDExLCAyMDEyIGF0IDEwOjE1OjQ5QU0gLTAzMDAsIEZhYmlvIEVzdGV2YW0gd3JvdGU6DQo+
ID4gT24gV2VkLCBBcHIgMTEsIDIwMTIgYXQgNDozOSBBTSwgQ2hyaXN0b3BoIEZyaXR6DQo+ID4g
PGNoZi5mcml0ekBnb29nbGVtYWlsLmNvbT4gd3JvdGU6DQo+ID4NCj4gPiA+IENhbiB5b3UgYXBw
cm92ZSB0aGlzIGJlaGF2aW91ciBvZiBnX2V0aGVyL3VzYm5ldCB3aGVuIHVzaW5nIGlwZXJmPw0K
PiA+DQo+ID4gSSBhbSBub3QgdmVyeSBmYW1pbGlhciB3aXRoIGlwZXJmLCBzbyBJIHdpbGwgbGV0
IG90aGVycyBjb21tZW50Lg0KPiANCj4gSGkgdG8gQWxsLA0KPiANCj4gYWZ0ZXIgYSB3aGlsZSBv
ZiB0ZXN0aW5nIGFuZCBzZWFyY2hpbmcgSSBjYW4gY29tZSB1cCB3aXRoIGEgcGF0Y2gNCj4gdGhh
dCBmaXhlcyBnX2V0aGVyIDwtPiBpcGVyZiBmb3IgZnNsX3VkYyBvbiBBUk0gaS5NWDM1Lg0KPiAN
Cj4gVGhlIHNhZCBwYXJ0IGlzIHRoYXQgdGhpcyBraW5kIG9mIGZpeCBpcyBhbHJlYWR5IGltcGxl
bWVudGVkIGZvcg0KPiBtYXJ2ZWxsIG12X3VkYyBkcml2ZXIgc2luY2UgbGFzdCB5ZWFyIGJ1dCBz
dGlsbCBfbm90XyBpbiB0aGUgfjE1DQo+IG90aGVyICp1ZGMuYyBkcml2ZXJzLg0KPiANCj4gU2Vl
IGhlcmU6DQo+IGRhZWM3NjVkYTc2N2U0YTZhMzBlMTI5ODg2MmIyOGYyY2FlOWE3M2YNCj4gdXNi
OiBnYWRnZXQ6IG12X3VkYzogZml4IGR0ZCBkbWEgY29uZnVzaW9uDQo+IA0KPiBTbyBoZXJlYnkg
SSdtIENDLWluZyBhbGwgKnVkYy5jIG1haW50YWluZXJzIHRvIHBvaW50IG91dCB0aGF0IHRoaXMN
Cj4gaXNzdWUgbWF5YmUgYWZmZWN0cyB5b3UgdG9vLg0KPiANCj4gQW5kIG1heWJlIHNvbWVvbmUg
Y2FuIGV4cGxhaW4gaWYgdGhpczoNCj4gKwkJCQlpZiAoY3Vycl90ZC0+bmV4dF90ZF9wdHIgPT0N
Cj4gRVBfUVVFVUVfSEVBRF9ORVhUX1RFUk1JTkFURSkgew0KPiBpcyBuZWNlc3NhcnkgYW5kIHdo
eSAocGxlYXNlIHNlZSBiZWxvdykuDQo+IA0KIA0KVGhlIG91dGVyIGxvb3AgaXMgdG8gY2hlY2sg
d2hldGhlciB0aGUgY29udHJvbGxlciBzdGlsbCBwb2ludCB0byB0aGUgY3VycmVudCBkdGQuDQpJ
ZiBzbywgd2Ugc2hvdWxkIHdhaXQgaXQgdG8gbW92ZSBvbnRvIHRoZSBuZXh0IGR0ZC4NCkJ1dCB0
aGVyZSBpcyBhbiBleGNlcHRpb24sIGlmIHRoZSBjdXJyZW50IGR0ZCBpcyB0aGUgbGFzdCBkdGQg
b24gdGhpcyBlcCBxdWV1ZSwgDQp0aGVuIHRoZSBjb250cm9sbGVyIGNhbiBuZXZlciBtb3ZlIG9u
Lg0KRm9ydHVuYXRlbHksIHdlIGNhbiBjaGVjayByZWdpc3RlciBlcHN0YXR1cyAob2Zmc2V0OiAw
eDFiOCkgdG8gc2VlIHdoZXRoZXIgdGhlIGJ1ZmZlciBpcyBmcmVlIGFnYWluLg0KDQo+IFRoYW5r
cywNCj4gIC0tIENocmlzdG9waA0KPiANCj4gLS0tDQo+IFN1YmplY3Q6IFtQQVRDSF0gdXNiOiBn
YWRnZXQ6IGZzbF91ZGM6IGZpeCBkdGQgZG1hIGNvbmZ1c2lvbg0KPiANCj4gVGhlIGNvbnRyb2xs
ZXIgd2lsbCBoYW5nIHdoZW4gZG9pbmcgdGVzdGluZ3Mgd2l0aCBnX2V0aGVyIGFuZCBpcGVyZg0K
PiAodG9vbCBmb3IgbWVhc3VyaW5nIG1heGltdW0gVENQIGFuZCBVRFAgYmFuZHdpZHRoKS4gIFRo
aXMgcGF0Y2ggYWRkcyBhDQo+IGRlbGF5IHRvIHdhaXQgZm9yIGNvbnRyb2xsZXIgdG8gcmVsZWFz
ZSBkdGQgZG1hIGJlZm9yZSBmcmVlaW5nIGl0Lg0KPiANCj4gU2lnbmVkLW9mZi1ieTogQ2hyaXN0
b3BoIEZyaXR6IDxjaGYuZnJpdHpAZ29vZ2xlbWFpbC5jb20+DQo+IC0tLQ0KPiAgZHJpdmVycy91
c2IvZ2FkZ2V0L2ZzbF91ZGNfY29yZS5jIHwgICAgOSArKysrKysrKysNCj4gIDEgZmlsZXMgY2hh
bmdlZCwgOSBpbnNlcnRpb25zKCspLCAwIGRlbGV0aW9ucygtKQ0KPiANCj4gZGlmZiAtLWdpdCBh
L2RyaXZlcnMvdXNiL2dhZGdldC9mc2xfdWRjX2NvcmUuYw0KPiBiL2RyaXZlcnMvdXNiL2dhZGdl
dC9mc2xfdWRjX2NvcmUuYw0KPiBpbmRleCA1NWFiZmI2Li5mYzg2MTA4IDEwMDY0NA0KPiAtLS0g
YS9kcml2ZXJzL3VzYi9nYWRnZXQvZnNsX3VkY19jb3JlLmMNCj4gKysrIGIvZHJpdmVycy91c2Iv
Z2FkZ2V0L2ZzbF91ZGNfY29yZS5jDQo+IEBAIC0xNjM4LDYgKzE2MzgsMTUgQEAgc3RhdGljIGlu
dCBwcm9jZXNzX2VwX3JlcShzdHJ1Y3QgZnNsX3VkYyAqdWRjLA0KPiBpbnQgcGlwZSwNCj4gIAkJ
CXN0YXR1cyA9IFJFUV9VTkNPTVBMRVRFOw0KPiAgCQkJcmV0dXJuIHN0YXR1czsNCj4gIAkJfSBl
bHNlIGlmIChyZW1haW5pbmdfbGVuZ3RoKSB7DQo+ICsJCQkvKiB3YWl0IGNvbnRyb2xsZXIgcmVs
ZWFzZSBkdGQgZG1hICovDQo+ICsJCQl3aGlsZSAoKGN1cnJfcWgtPmN1cnJfZHRkX3B0ciA9PSBj
dXJyX3RkLT50ZF9kbWEpKSB7DQo+ICsJCQkJaWYgKGN1cnJfdGQtPm5leHRfdGRfcHRyID09DQo+
ICsJCQkJCQlFUF9RVUVVRV9IRUFEX05FWFRfVEVSTUlOQVRFKSB7DQo+ICsJCQkJCXVkZWxheSgx
MDApOw0KPiArCQkJCQlicmVhazsNCj4gKwkJCQl9DQo+ICsJCQkJdWRlbGF5KDEpOw0KPiArCQkJ
fQ0KPiAgCQkJaWYgKGRpcmVjdGlvbikgew0KPiAgCQkJCVZEQkcoIlRyYW5zbWl0IGRURCByZW1h
aW5pbmcgbGVuZ3RoIG5vdCB6ZXJvIik7DQo+ICAJCQkJc3RhdHVzID0gLUVQUk9UTzsNCj4gLS0N
Cj4gMS43LjIuNQ0KPiANCg0KQmVzdCBSZWdhcmRzLA0KTmVpbCBaaGFuZw0K

^ permalink raw reply	[flat|nested] 42+ messages in thread

* RE: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  1:50                     ` Neil Zhang
@ 2012-05-09  2:11                       ` Chen Peter-B29397
  2012-05-09  5:38                         ` Christoph Fritz
  0 siblings, 1 reply; 42+ messages in thread
From: Chen Peter-B29397 @ 2012-05-09  2:11 UTC (permalink / raw)
  To: Neil Zhang, Christoph Fritz, Fabio Estevam, Li Yang-R58472,
	Felipe Balbi, Greg Kroah-Hartman, linux-usb, linuxppc-dev,
	Hans J. Koch, Daniel Mack
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Estevam Fabio-R49496,
	Sascha Hauer, Nicolas Ferre, Haojian Zhuang, Ido Shayevitz,
	Ben Dooks, Thomas Dahlmann, Russell King, Chao Xie


=20
> >
> > after a while of testing and searching I can come up with a patch
> > that fixes g_ether <-> iperf for fsl_udc on ARM i.MX35.
> >
> > The sad part is that this kind of fix is already implemented for
> > marvell mv_udc driver since last year but still _not_ in the ~15
> > other *udc.c drivers.
> >
=20
It is a controller limitation (bug?) for chipidea controller when using
dtd list to handle multi-dtds situation. The controller will read dtd's
next pointer after this dtd's active bit has already been cleared.

Freescale has an errata for this problem's description and solution.
http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
See 2858

BR,
Peter

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  2:11                       ` Chen Peter-B29397
@ 2012-05-09  5:38                         ` Christoph Fritz
  2012-05-09  5:43                           ` Chen Peter-B29397
  2012-05-09  5:45                           ` Neil Zhang
  0 siblings, 2 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-05-09  5:38 UTC (permalink / raw)
  To: Chen Peter-B29397, Chao Xie
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, Sascha Hauer, linux-usb, Nicolas Ferre,
	linuxppc-dev, Felipe Balbi, Ido Shayevitz, Estevam Fabio-R49496,
	Hans J. Koch, Haojian Zhuang, Daniel Mack, Thomas Dahlmann,
	Russell King, Neil Zhang, Fabio Estevam, Ben Dooks

Hi Peter,

 thanks you for your help.

On Wed, May 09, 2012 at 02:11:56AM +0000, Chen Peter-B29397 wrote:
> 
>  
> > >
> > > after a while of testing and searching I can come up with a patch
> > > that fixes g_ether <-> iperf for fsl_udc on ARM i.MX35.
> > >
> > > The sad part is that this kind of fix is already implemented for
> > > marvell mv_udc driver since last year but still _not_ in the ~15
> > > other *udc.c drivers.
> > >
>  
> It is a controller limitation (bug?) for chipidea controller when using
> dtd list to handle multi-dtds situation. The controller will read dtd's
> next pointer after this dtd's active bit has already been cleared.
> 
> Freescale has an errata for this problem's description and solution.
> http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> See 2858

I'm hacking here an i.MX35 not an i.MX23. So I already had a look at its
errata sheet http://cache.freescale.com/files/dsp/doc/errata/IMX35CE.pdf
but didn't find a similar "limitation" as you now pointed out by errata
number 2858 for i.MX23.

What about the fix for mv_udc, shouldn't they have a similar
"limitation"? How do you explain?
Or maybe someone from Marvell has an answer?


Thanks,
 -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* RE: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  5:38                         ` Christoph Fritz
@ 2012-05-09  5:43                           ` Chen Peter-B29397
  2012-05-09  5:56                             ` Christoph Fritz
  2012-05-09  5:45                           ` Neil Zhang
  1 sibling, 1 reply; 42+ messages in thread
From: Chen Peter-B29397 @ 2012-05-09  5:43 UTC (permalink / raw)
  To: Christoph Fritz, Chao Xie
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, Sascha Hauer, linux-usb, Nicolas Ferre,
	linuxppc-dev, Felipe Balbi, Ido Shayevitz, Estevam Fabio-R49496,
	Hans J. Koch, Haojian Zhuang, Daniel Mack, Thomas Dahlmann,
	Russell King, Neil Zhang, Fabio Estevam, Ben Dooks

=20
>=20
> I'm hacking here an i.MX35 not an i.MX23. So I already had a look at its
> errata sheet http://cache.freescale.com/files/dsp/doc/errata/IMX35CE.pdf
> but didn't find a similar "limitation" as you now pointed out by errata
> number 2858 for i.MX23.
>

i.mx35 and i.mx23 uses the same controller.
=20
> What about the fix for mv_udc, shouldn't they have a similar
> "limitation"? How do you explain?
> Or maybe someone from Marvell has an answer?
>
It is probably that others who use chipidea core have the same problem,
but it needs to get confirm from them. =20

>=20
> Thanks,
>  -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* RE: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  5:38                         ` Christoph Fritz
  2012-05-09  5:43                           ` Chen Peter-B29397
@ 2012-05-09  5:45                           ` Neil Zhang
  2012-05-09  6:04                             ` Christoph Fritz
  1 sibling, 1 reply; 42+ messages in thread
From: Neil Zhang @ 2012-05-09  5:45 UTC (permalink / raw)
  To: Christoph Fritz, Chen Peter-B29397, Chao Xie
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, Sascha Hauer, linux-usb, Nicolas Ferre,
	linuxppc-dev, Felipe Balbi, Ido Shayevitz, Estevam Fabio-R49496,
	Hans J. Koch, Haojian Zhuang, Daniel Mack, Thomas Dahlmann,
	Russell King, Fabio Estevam, Ben Dooks

DQoNCg0KDQo+IC0tLS0tT3JpZ2luYWwgTWVzc2FnZS0tLS0tDQo+IEZyb206IENocmlzdG9waCBG
cml0eiBbbWFpbHRvOmNoZi5mcml0ekBnb29nbGVtYWlsLmNvbV0NCj4gU2VudDogMjAxMsTqNdTC
OcjVIDEzOjM4DQo+IFRvOiBDaGVuIFBldGVyLUIyOTM5NzsgQ2hhbyBYaWUNCj4gQ2M6IE5laWwg
Wmhhbmc7IEZhYmlvIEVzdGV2YW07IExpIFlhbmctUjU4NDcyOyBGZWxpcGUgQmFsYmk7IEdyZWcN
Cj4gS3JvYWgtSGFydG1hbjsgbGludXgtdXNiQHZnZXIua2VybmVsLm9yZzsgbGludXhwcGMtZGV2
QGxpc3RzLm96bGFicy5vcmc7DQo+IEhhbnMgSi4gS29jaDsgRGFuaWVsIE1hY2s7IFRob21hcyBE
YWhsbWFubjsgTmljb2xhcyBGZXJyZTsgRXJpYyBNaWFvOw0KPiBSdXNzZWxsIEtpbmc7IEhhb2pp
YW4gWmh1YW5nOyBCZW4gRG9va3M7IEt1a2ppbiBLaW07IFNhc2NoYSBIYXVlcjsNCj4gT2xpdmVy
IE5ldWt1bTsgSWRvIFNoYXlldml0ejsgRXN0ZXZhbSBGYWJpby1SNDk0OTYNCj4gU3ViamVjdDog
UmU6IFtSRkNdIFtQQVRDSF0gdXNiOiBnYWRnZXQ6IGZpeCBkdGQgZG1hIGNvbmZ1c2lvbg0KPiAN
Cj4gSGkgUGV0ZXIsDQo+IA0KPiAgdGhhbmtzIHlvdSBmb3IgeW91ciBoZWxwLg0KPiANCj4gT24g
V2VkLCBNYXkgMDksIDIwMTIgYXQgMDI6MTE6NTZBTSArMDAwMCwgQ2hlbiBQZXRlci1CMjkzOTcg
d3JvdGU6DQo+ID4NCj4gPg0KPiA+ID4gPg0KPiA+ID4gPiBhZnRlciBhIHdoaWxlIG9mIHRlc3Rp
bmcgYW5kIHNlYXJjaGluZyBJIGNhbiBjb21lIHVwIHdpdGggYSBwYXRjaA0KPiA+ID4gPiB0aGF0
IGZpeGVzIGdfZXRoZXIgPC0+IGlwZXJmIGZvciBmc2xfdWRjIG9uIEFSTSBpLk1YMzUuDQo+ID4g
PiA+DQo+ID4gPiA+IFRoZSBzYWQgcGFydCBpcyB0aGF0IHRoaXMga2luZCBvZiBmaXggaXMgYWxy
ZWFkeSBpbXBsZW1lbnRlZCBmb3INCj4gPiA+ID4gbWFydmVsbCBtdl91ZGMgZHJpdmVyIHNpbmNl
IGxhc3QgeWVhciBidXQgc3RpbGwgX25vdF8gaW4gdGhlIH4xNQ0KPiA+ID4gPiBvdGhlciAqdWRj
LmMgZHJpdmVycy4NCj4gPiA+ID4NCj4gPg0KPiA+IEl0IGlzIGEgY29udHJvbGxlciBsaW1pdGF0
aW9uIChidWc/KSBmb3IgY2hpcGlkZWEgY29udHJvbGxlciB3aGVuDQo+IHVzaW5nDQo+ID4gZHRk
IGxpc3QgdG8gaGFuZGxlIG11bHRpLWR0ZHMgc2l0dWF0aW9uLiBUaGUgY29udHJvbGxlciB3aWxs
IHJlYWQNCj4gZHRkJ3MNCj4gPiBuZXh0IHBvaW50ZXIgYWZ0ZXIgdGhpcyBkdGQncyBhY3RpdmUg
Yml0IGhhcyBhbHJlYWR5IGJlZW4gY2xlYXJlZC4NCj4gPg0KPiA+IEZyZWVzY2FsZSBoYXMgYW4g
ZXJyYXRhIGZvciB0aGlzIHByb2JsZW0ncyBkZXNjcmlwdGlvbiBhbmQgc29sdXRpb24uDQo+ID4g
aHR0cDovL2NhY2hlLmZyZWVzY2FsZS5jb20vZmlsZXMvZHNwL2RvYy9lcnJhdGEvSU1YMjNDRS5w
ZGYNCj4gPiBTZWUgMjg1OA0KPiANCj4gSSdtIGhhY2tpbmcgaGVyZSBhbiBpLk1YMzUgbm90IGFu
IGkuTVgyMy4gU28gSSBhbHJlYWR5IGhhZCBhIGxvb2sgYXQNCj4gaXRzDQo+IGVycmF0YSBzaGVl
dA0KPiBodHRwOi8vY2FjaGUuZnJlZXNjYWxlLmNvbS9maWxlcy9kc3AvZG9jL2VycmF0YS9JTVgz
NUNFLnBkZg0KPiBidXQgZGlkbid0IGZpbmQgYSBzaW1pbGFyICJsaW1pdGF0aW9uIiBhcyB5b3Ug
bm93IHBvaW50ZWQgb3V0IGJ5IGVycmF0YQ0KPiBudW1iZXIgMjg1OCBmb3IgaS5NWDIzLg0KPiAN
Cj4gV2hhdCBhYm91dCB0aGUgZml4IGZvciBtdl91ZGMsIHNob3VsZG4ndCB0aGV5IGhhdmUgYSBz
aW1pbGFyDQo+ICJsaW1pdGF0aW9uIj8gSG93IGRvIHlvdSBleHBsYWluPw0KPiBPciBtYXliZSBz
b21lb25lIGZyb20gTWFydmVsbCBoYXMgYW4gYW5zd2VyPw0KPiANCg0KWWVzLCB3ZSBlbmNvdW50
ZXJlZCB0aGUgc2FtZSBpc3N1ZSwgYW5kIEkgaGF2ZSBhbnN3ZXJlZCB5b3VyIHF1ZXN0aW9uIHNl
dmVyYWwgaG91cnMgYWdvLg0KUGxlYXNlIGhhdmUgYSBsb29rLg0KDQo+IA0KPiBUaGFua3MsDQo+
ICAtLSBDaHJpc3RvcGgNCg0KQmVzdCBSZWdhcmRzLA0KTmVpbCBaaGFuZw0K

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  5:43                           ` Chen Peter-B29397
@ 2012-05-09  5:56                             ` Christoph Fritz
  0 siblings, 0 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-05-09  5:56 UTC (permalink / raw)
  To: Chen Peter-B29397
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, Sascha Hauer, linux-usb, Nicolas Ferre,
	linuxppc-dev, Felipe Balbi, Ido Shayevitz, Ben Dooks,
	Estevam Fabio-R49496, Hans J. Koch, Haojian Zhuang, Daniel Mack,
	Thomas Dahlmann, Russell King, Neil Zhang, Fabio Estevam,
	Chao Xie

On Wed, May 09, 2012 at 05:43:11AM +0000, Chen Peter-B29397 wrote:
>  
> > 
> > I'm hacking here an i.MX35 not an i.MX23. So I already had a look at its
> > errata sheet http://cache.freescale.com/files/dsp/doc/errata/IMX35CE.pdf
> > but didn't find a similar "limitation" as you now pointed out by errata
> > number 2858 for i.MX23.
> >
> 
> i.mx35 and i.mx23 uses the same controller.

A link or short note in i.MX35 its errata sheet to the i.MX23 one
would be nice.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  5:45                           ` Neil Zhang
@ 2012-05-09  6:04                             ` Christoph Fritz
  0 siblings, 0 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-05-09  6:04 UTC (permalink / raw)
  To: Neil Zhang
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Li Yang-R58472,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Nicolas Ferre,
	linuxppc-dev, Felipe Balbi, Ido Shayevitz, Thomas Dahlmann,
	Estevam Fabio-R49496, Hans J. Koch, Haojian Zhuang, Daniel Mack,
	Greg Kroah-Hartman, Russell King, Ben Dooks, Fabio Estevam,
	Chao Xie

Hi Neil,

 thanks for you help.

> > 
> > What about the fix for mv_udc, shouldn't they have a similar
> > "limitation"? How do you explain?
> > Or maybe someone from Marvell has an answer?
> > 
> 
> Yes, we encountered the same issue, and I have answered your question several hours ago.
> Please have a look.

Thanks for that.
Relating to the other *udc.c driver, do you think they should implement
a similar workaround there too or at least check their errataS?

Thanks,
 -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-09  0:02                   ` [RFC] [PATCH] usb: gadget: fix dtd dma confusion Christoph Fritz
  2012-05-09  1:50                     ` Neil Zhang
@ 2012-05-13 22:51                     ` Christoph Fritz
  2012-05-14  1:11                       ` Chen Peter-B29397
  2012-05-14  4:21                       ` Greg Kroah-Hartman
  1 sibling, 2 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-05-13 22:51 UTC (permalink / raw)
  To: Fabio Estevam, Neil Zhang, Li Yang, Felipe Balbi,
	Greg Kroah-Hartman, linux-usb, linuxppc-dev, Hans J. Koch,
	Daniel Mack
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Chen Peter-B29397,
	Sascha Hauer, Nicolas Ferre, Haojian Zhuang,
	Estevam Fabio-R49496, Ido Shayevitz, Ben Dooks, Thomas Dahlmann,
	Russell King

On Wed, May 09, 2012 at 02:02:22AM +0200, Christoph Fritz wrote:
> 
> Hi to All,
> 
> after a while of testing and searching I can come up with a patch
> that fixes g_ether <-> iperf for fsl_udc on ARM i.MX35.
> 
> The sad part is that this kind of fix is already implemented for
> marvell mv_udc driver since last year but still _not_ in the ~15
> other *udc.c drivers.
> 
> See here:
> daec765da767e4a6a30e1298862b28f2cae9a73f
> usb: gadget: mv_udc: fix dtd dma confusion
> 
> So hereby I'm CC-ing all *udc.c maintainers to point out that this
> issue maybe affects you too.
> 
> 
> ---
> Subject: [PATCH] usb: gadget: fsl_udc: fix dtd dma confusion
> 
> The controller will hang when doing testings with g_ether and iperf
> (tool for measuring maximum TCP and UDP bandwidth).  This patch adds a
> delay to wait for controller to release dtd dma before freeing it.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 55abfb6..fc86108 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -1638,6 +1638,15 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
>  			status = REQ_UNCOMPLETE;
>  			return status;
>  		} else if (remaining_length) {
> +			/* wait controller release dtd dma */
> +			while ((curr_qh->curr_dtd_ptr == curr_td->td_dma)) {
> +				if (curr_td->next_td_ptr ==
> +						EP_QUEUE_HEAD_NEXT_TERMINATE) {
> +					udelay(100);
> +					break;
> +				}
> +				udelay(1);
> +			}
>  			if (direction) {
>  				VDBG("Transmit dTD remaining length not zero");
>  				status = -EPROTO;
> -- 
> 1.7.2.5

 ping  -  what about this patch? Will it be applied?

Thanks,
 -- Christoph
 

^ permalink raw reply	[flat|nested] 42+ messages in thread

* RE: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-13 22:51                     ` Christoph Fritz
@ 2012-05-14  1:11                       ` Chen Peter-B29397
  2012-05-14  4:21                       ` Greg Kroah-Hartman
  1 sibling, 0 replies; 42+ messages in thread
From: Chen Peter-B29397 @ 2012-05-14  1:11 UTC (permalink / raw)
  To: Christoph Fritz, Fabio Estevam, Neil Zhang, Li Yang-R58472,
	Felipe Balbi, Greg Kroah-Hartman, linux-usb, linuxppc-dev,
	Hans J. Koch, Daniel Mack
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Estevam Fabio-R49496,
	Sascha Hauer, Nicolas Ferre, Haojian Zhuang, Ido Shayevitz,
	Ben Dooks, Thomas Dahlmann, Russell King

=20


=20
> > See here:
> > daec765da767e4a6a30e1298862b28f2cae9a73f
> > usb: gadget: mv_udc: fix dtd dma confusion
> >
> > So hereby I'm CC-ing all *udc.c maintainers to point out that this
> > issue maybe affects you too.
> >
> >
> > ---
> > Subject: [PATCH] usb: gadget: fsl_udc: fix dtd dma confusion
> >
> > The controller will hang when doing testings with g_ether and iperf
> > (tool for measuring maximum TCP and UDP bandwidth).  This patch adds a
> > delay to wait for controller to release dtd dma before freeing it.
> >
> > Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> > ---
> >  drivers/usb/gadget/fsl_udc_core.c |    9 +++++++++
> >  1 files changed, 9 insertions(+), 0 deletions(-)
> >
> > diff --git a/drivers/usb/gadget/fsl_udc_core.c
> b/drivers/usb/gadget/fsl_udc_core.c
> > index 55abfb6..fc86108 100644
> > --- a/drivers/usb/gadget/fsl_udc_core.c
> > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > @@ -1638,6 +1638,15 @@ static int process_ep_req(struct fsl_udc *udc,
> int pipe,
> >  			status =3D REQ_UNCOMPLETE;
> >  			return status;
> >  		} else if (remaining_length) {
> > +			/* wait controller release dtd dma */
> > +			while ((curr_qh->curr_dtd_ptr =3D=3D curr_td->td_dma)) {
> > +				if (curr_td->next_td_ptr =3D=3D
> > +						EP_QUEUE_HEAD_NEXT_TERMINATE) {
> > +					udelay(100);
> > +					break;
> > +				}
> > +				udelay(1);
> > +			}
> >  			if (direction) {
> >  				VDBG("Transmit dTD remaining length not zero");
> >  				status =3D -EPROTO;
> > --
> > 1.7.2.5
>=20
>  ping  -  what about this patch? Will it be applied?
>=20
Christoph, it is better use errata suggests workaround (postpone free dtd m=
emory),
and you can find related code at:=20

http://git.freescale.com/git/cgit.cgi/imx/linux-2.6-imx.git/tree/
drivers/usb/gadget/arcotg_udc.c?h=3Dimx_3.0.15

The code is defined with POSTPONE_FREE_LAST_DTD

> Thanks,
>  -- Christoph
>=20

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [RFC] [PATCH] usb: gadget: fix dtd dma confusion
  2012-05-13 22:51                     ` Christoph Fritz
  2012-05-14  1:11                       ` Chen Peter-B29397
@ 2012-05-14  4:21                       ` Greg Kroah-Hartman
  2012-05-20 23:17                         ` [PATCH] usb: fsl_udc: errata - postpone freeing current dTD Christoph Fritz
  1 sibling, 1 reply; 42+ messages in thread
From: Greg Kroah-Hartman @ 2012-05-14  4:21 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Oliver Neukum, Eric Miao, Ben Dooks, linuxppc-dev, Sascha Hauer,
	linux-usb, Nicolas Ferre, Felipe Balbi, Ido Shayevitz,
	Chen Peter-B29397, Estevam Fabio-R49496, Hans J. Koch,
	Haojian Zhuang, Daniel Mack, Thomas Dahlmann, Russell King,
	Neil Zhang, Fabio Estevam, Kukjin Kim

On Mon, May 14, 2012 at 12:51:26AM +0200, Christoph Fritz wrote:
> On Wed, May 09, 2012 at 02:02:22AM +0200, Christoph Fritz wrote:
> > 
> > Hi to All,
> > 
> > after a while of testing and searching I can come up with a patch
> > that fixes g_ether <-> iperf for fsl_udc on ARM i.MX35.
> > 
> > The sad part is that this kind of fix is already implemented for
> > marvell mv_udc driver since last year but still _not_ in the ~15
> > other *udc.c drivers.
> > 
> > See here:
> > daec765da767e4a6a30e1298862b28f2cae9a73f
> > usb: gadget: mv_udc: fix dtd dma confusion
> > 
> > So hereby I'm CC-ing all *udc.c maintainers to point out that this
> > issue maybe affects you too.
> > 
> > 
> > ---
> > Subject: [PATCH] usb: gadget: fsl_udc: fix dtd dma confusion
> > 
> > The controller will hang when doing testings with g_ether and iperf
> > (tool for measuring maximum TCP and UDP bandwidth).  This patch adds a
> > delay to wait for controller to release dtd dma before freeing it.
> > 
> > Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> > ---
> >  drivers/usb/gadget/fsl_udc_core.c |    9 +++++++++
> >  1 files changed, 9 insertions(+), 0 deletions(-)
> > 
> > diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> > index 55abfb6..fc86108 100644
> > --- a/drivers/usb/gadget/fsl_udc_core.c
> > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > @@ -1638,6 +1638,15 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
> >  			status = REQ_UNCOMPLETE;
> >  			return status;
> >  		} else if (remaining_length) {
> > +			/* wait controller release dtd dma */
> > +			while ((curr_qh->curr_dtd_ptr == curr_td->td_dma)) {
> > +				if (curr_td->next_td_ptr ==
> > +						EP_QUEUE_HEAD_NEXT_TERMINATE) {
> > +					udelay(100);
> > +					break;
> > +				}
> > +				udelay(1);
> > +			}
> >  			if (direction) {
> >  				VDBG("Transmit dTD remaining length not zero");
> >  				status = -EPROTO;
> > -- 
> > 1.7.2.5
> 
>  ping  -  what about this patch? Will it be applied?

RFC patches are never applied, as you are asking for comments, not for
the patch to actually be applied...

Submit it properly if you wish it to be accepted.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-14  4:21                       ` Greg Kroah-Hartman
@ 2012-05-20 23:17                         ` Christoph Fritz
  2012-05-21  1:05                           ` Chen Peter-B29397
  0 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-05-20 23:17 UTC (permalink / raw)
  To: Li Yang, Felipe Balbi, Greg Kroah-Hartman, Chen Peter-B29397
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Ben Dooks, Fabio Estevam,
	Sascha Hauer, linux-usb, Nicolas Ferre, Haojian Zhuang,
	Ido Shayevitz, Thomas Dahlmann, Estevam Fabio-R49496,
	Hans J. Koch, Daniel Mack, Christian Hemp, Russell King,
	Neil Zhang, linuxppc-dev

USB controller may access a wrong address for the dTD (endpoint transfer
descriptor) and then hang. This happens a lot when doing tests with
g_ether module and iperf, a tool for measuring maximum TCP and UDP
bandwidth.

This hardware bug is explained in detail by errata number 2858 for i.MX23:
http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf

mv_udc_core fixes this bug by commit daec765. There still may be unfixed
drivers.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Signed-off-by: Christian Hemp <c.hemp@phytec.de>
---
 drivers/usb/gadget/fsl_udc_core.c |   22 ++++++++++++++++++++++
 drivers/usb/gadget/fsl_usb2_udc.h |    6 ++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 55abfb6..f9bfafd 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -65,6 +65,9 @@ static struct usb_sys_interface *usb_sys_regs;
 /* it is initialized in probe()  */
 static struct fsl_udc *udc_controller = NULL;
 
+#ifdef POSTPONE_FREE_LAST_DTD
+static struct ep_td_struct *last_free_td;
+#endif
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -180,8 +183,18 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
 		curr_td = next_td;
 		if (j != req->dtd_count - 1) {
 			next_td = curr_td->next_td_virt;
+#ifdef POSTPONE_FREE_LAST_DTD
+			dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
+		} else {
+			if (last_free_td != NULL)
+				dma_pool_free(udc->td_pool, last_free_td,
+						last_free_td->td_dma);
+			last_free_td = curr_td;
+		}
+#else
 		}
 		dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
+#endif
 	}
 
 	if (req->mapped) {
@@ -2579,6 +2592,10 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		goto err_unregister;
 	}
 
+#ifdef POSTPONE_FREE_LAST_DTD
+	last_free_td = NULL;
+#endif
+
 	ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
 	if (ret)
 		goto err_del_udc;
@@ -2633,6 +2650,11 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
 	kfree(udc_controller->status_req);
 	kfree(udc_controller->eps);
 
+#ifdef POSTPONE_FREE_LAST_DTD
+	if (last_free_td != NULL)
+		dma_pool_free(udc_controller->td_pool, last_free_td,
+				last_free_td->td_dma);
+#endif
 	dma_pool_destroy(udc_controller->td_pool);
 	free_irq(udc_controller->irq, udc_controller);
 	iounmap(dr_regs);
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index e651469..03ae07f 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -4,6 +4,12 @@
 #ifndef __FSL_USB2_UDC_H
 #define __FSL_USB2_UDC_H
 
+#if defined CONFIG_ARCH_MX51 || defined CONFIG_SOC_IMX35
+#define POSTPONE_FREE_LAST_DTD
+#else
+#undef POSTPONE_FREE_LAST_DTD
+#endif
+
 /* ### define USB registers here
  */
 #define USB_MAX_CTRL_PAYLOAD		64
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* RE: [PATCH] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-20 23:17                         ` [PATCH] usb: fsl_udc: errata - postpone freeing current dTD Christoph Fritz
@ 2012-05-21  1:05                           ` Chen Peter-B29397
  2012-05-21  6:53                             ` Christoph Fritz
  0 siblings, 1 reply; 42+ messages in thread
From: Chen Peter-B29397 @ 2012-05-21  1:05 UTC (permalink / raw)
  To: Christoph Fritz, Li Yang-R58472, Felipe Balbi, Greg Kroah-Hartman
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Ben Dooks, Fabio Estevam,
	Sascha Hauer, linux-usb, Nicolas Ferre, Haojian Zhuang,
	Ido Shayevitz, Thomas Dahlmann, Estevam Fabio-R49496,
	Hans J. Koch, Daniel Mack, Christian Hemp, Russell King,
	Neil Zhang, linuxppc-dev



=20
>=20
> USB controller may access a wrong address for the dTD (endpoint transfer
> descriptor) and then hang. This happens a lot when doing tests with
> g_ether module and iperf, a tool for measuring maximum TCP and UDP
> bandwidth.
>=20
> This hardware bug is explained in detail by errata number 2858 for i.MX23=
:
> http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
>=20

Does this patch fix your problem?
=20
> +#if defined CONFIG_ARCH_MX51 || defined CONFIG_SOC_IMX35
> +#define POSTPONE_FREE_LAST_DTD
> +#else
> +#undef POSTPONE_FREE_LAST_DTD
> +#endif
> +
All i.mx SoC has this problem, if PowerPC also has this problem, you can=20
delete #if defined. Else, you can define it for all i.mx SoC=20
(CONFIG_ARCH_MXC | CONFIG_ARCH_MXS)

>  /* ### define USB registers here
>   */
>  #define USB_MAX_CTRL_PAYLOAD		64
> --
> 1.7.2.5
>=20
>=20

^ permalink raw reply	[flat|nested] 42+ messages in thread

* RE: [PATCH] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-21  1:05                           ` Chen Peter-B29397
@ 2012-05-21  6:53                             ` Christoph Fritz
  2012-05-21  6:57                               ` [PATCH v2] " Christoph Fritz
  0 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-05-21  6:53 UTC (permalink / raw)
  To: Chen Peter-B29397
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, Sascha Hauer, linux-usb, Nicolas Ferre,
	linuxppc-dev, Felipe Balbi, Ido Shayevitz, Thomas Dahlmann,
	Estevam Fabio-R49496, Hans J. Koch, Haojian Zhuang, Daniel Mack,
	Christian Hemp, Russell King, Neil Zhang, Fabio Estevam,
	Ben Dooks

Hi Chen,

On Mon, 2012-05-21 at 01:05 +0000, Chen Peter-B29397 wrote:
> 
>  
> > 
> > USB controller may access a wrong address for the dTD (endpoint transfer
> > descriptor) and then hang. This happens a lot when doing tests with
> > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > bandwidth.
> > 
> > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > 
> 
> Does this patch fix your problem?

yes, it does! :-)

> > +#if defined CONFIG_ARCH_MX51 || defined CONFIG_SOC_IMX35
> > +#define POSTPONE_FREE_LAST_DTD
> > +#else
> > +#undef POSTPONE_FREE_LAST_DTD
> > +#endif
> > +
> All i.mx SoC has this problem, if PowerPC also has this problem, you can 
> delete #if defined. Else, you can define it for all i.mx SoC 
> (CONFIG_ARCH_MXC | CONFIG_ARCH_MXS)

I was unsure about this too. I can only test imx35. And mx51 was defined
in your tree. So these two should be defined anyway.

Marvell doesn't use any defines in mv_udc_core for their fix, so I would
be fine without ifdefs too. Any objections? Please see next mail with
patch v2.


Thanks,
 -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-21  6:53                             ` Christoph Fritz
@ 2012-05-21  6:57                               ` Christoph Fritz
  2012-05-21  7:25                                 ` Chen Peter-B29397
  2012-05-21 19:04                                 ` Felipe Balbi
  0 siblings, 2 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-05-21  6:57 UTC (permalink / raw)
  To: Chen Peter-B29397, Li Yang-R58472, Felipe Balbi, Greg Kroah-Hartman
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Ben Dooks, Fabio Estevam,
	Sascha Hauer, linux-usb, Nicolas Ferre, Haojian Zhuang,
	Ido Shayevitz, Thomas Dahlmann, Estevam Fabio-R49496,
	Hans J. Koch, Daniel Mack, Christian Hemp, Russell King,
	Neil Zhang, linuxppc-dev

USB controller may access a wrong address for the dTD (endpoint transfer
descriptor) and then hang. This happens a lot when doing tests with
g_ether module and iperf, a tool for measuring maximum TCP and UDP
bandwidth.

This hardware bug is explained in detail by errata number 2858 for i.MX23:
http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf

All (?) SOCs with an IP from chipidea suffer from this problem.
mv_udc_core fixes this bug by commit daec765.  There still may be
unfixed drivers.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Signed-off-by: Christian Hemp <c.hemp@phytec.de>
---
 drivers/usb/gadget/fsl_udc_core.c |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 55abfb6..72f2139 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -65,6 +65,8 @@ static struct usb_sys_interface *usb_sys_regs;
 /* it is initialized in probe()  */
 static struct fsl_udc *udc_controller = NULL;
 
+static struct ep_td_struct *last_free_td;
+
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -180,8 +182,13 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
 		curr_td = next_td;
 		if (j != req->dtd_count - 1) {
 			next_td = curr_td->next_td_virt;
+			dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
+		} else {
+			if (last_free_td != NULL)
+				dma_pool_free(udc->td_pool, last_free_td,
+						last_free_td->td_dma);
+			last_free_td = curr_td;
 		}
-		dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
 	}
 
 	if (req->mapped) {
@@ -2579,6 +2586,8 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		goto err_unregister;
 	}
 
+	last_free_td = NULL;
+
 	ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
 	if (ret)
 		goto err_del_udc;
@@ -2633,6 +2642,10 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
 	kfree(udc_controller->status_req);
 	kfree(udc_controller->eps);
 
+	if (last_free_td != NULL)
+		dma_pool_free(udc_controller->td_pool, last_free_td,
+				last_free_td->td_dma);
+
 	dma_pool_destroy(udc_controller->td_pool);
 	free_irq(udc_controller->irq, udc_controller);
 	iounmap(dr_regs);
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* RE: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-21  6:57                               ` [PATCH v2] " Christoph Fritz
@ 2012-05-21  7:25                                 ` Chen Peter-B29397
  2012-05-21 19:04                                 ` Felipe Balbi
  1 sibling, 0 replies; 42+ messages in thread
From: Chen Peter-B29397 @ 2012-05-21  7:25 UTC (permalink / raw)
  To: Christoph Fritz, Li Yang-R58472, Felipe Balbi, Greg Kroah-Hartman
  Cc: Oliver Neukum, Kukjin Kim, Eric Miao, Ben Dooks, Fabio Estevam,
	Sascha Hauer, linux-usb, Nicolas Ferre, Haojian Zhuang,
	Ido Shayevitz, Thomas Dahlmann, Estevam Fabio-R49496,
	Hans J. Koch, Daniel Mack, Christian Hemp, Russell King,
	Neil Zhang, linuxppc-dev

=20
>=20
> USB controller may access a wrong address for the dTD (endpoint transfer
> descriptor) and then hang. This happens a lot when doing tests with
> g_ether module and iperf, a tool for measuring maximum TCP and UDP
> bandwidth.
>=20
> This hardware bug is explained in detail by errata number 2858 for i.MX23=
:
> http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
>=20

> All (?) SOCs with an IP from chipidea suffer from this problem.
> mv_udc_core fixes this bug by commit daec765.  There still may be
> unfixed drivers.
>=20
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> Signed-off-by: Christian Hemp <c.hemp@phytec.de>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |   15 ++++++++++++++-
>  1 files changed, 14 insertions(+), 1 deletions(-)
>=20
> diff --git a/drivers/usb/gadget/fsl_udc_core.c
> b/drivers/usb/gadget/fsl_udc_core.c
> index 55abfb6..72f2139 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -65,6 +65,8 @@ static struct usb_sys_interface *usb_sys_regs;
>  /* it is initialized in probe()  */
>  static struct fsl_udc *udc_controller =3D NULL;
>=20
> +static struct ep_td_struct *last_free_td;
> +
>  static const struct usb_endpoint_descriptor
>  fsl_ep0_desc =3D {
>  	.bLength =3D		USB_DT_ENDPOINT_SIZE,
> @@ -180,8 +182,13 @@ static void done(struct fsl_ep *ep, struct fsl_req
> *req, int status)
>  		curr_td =3D next_td;
>  		if (j !=3D req->dtd_count - 1) {
>  			next_td =3D curr_td->next_td_virt;
> +			dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
> +		} else {
> +			if (last_free_td !=3D NULL)
> +				dma_pool_free(udc->td_pool, last_free_td,
> +						last_free_td->td_dma);
> +			last_free_td =3D curr_td;
>  		}
> -		dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
>  	}
>=20
>  	if (req->mapped) {
> @@ -2579,6 +2586,8 @@ static int __init fsl_udc_probe(struct
> platform_device *pdev)
>  		goto err_unregister;
>  	}
>=20
> +	last_free_td =3D NULL;
> +
>  	ret =3D usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
>  	if (ret)
>  		goto err_del_udc;
> @@ -2633,6 +2642,10 @@ static int __exit fsl_udc_remove(struct
> platform_device *pdev)
>  	kfree(udc_controller->status_req);
>  	kfree(udc_controller->eps);
>=20
> +	if (last_free_td !=3D NULL)
> +		dma_pool_free(udc_controller->td_pool, last_free_td,
> +				last_free_td->td_dma);
> +
>  	dma_pool_destroy(udc_controller->td_pool);
>  	free_irq(udc_controller->irq, udc_controller);
>  	iounmap(dr_regs);

Reviewed-by: Peter Chen <peter.chen@freescale.com>
> --
> 1.7.2.5
>=20
>=20

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-21  6:57                               ` [PATCH v2] " Christoph Fritz
  2012-05-21  7:25                                 ` Chen Peter-B29397
@ 2012-05-21 19:04                                 ` Felipe Balbi
  2012-06-04 11:30                                   ` Christoph Fritz
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
  1 sibling, 2 replies; 42+ messages in thread
From: Felipe Balbi @ 2012-05-21 19:04 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Fabio Estevam, Kukjin Kim, Russell King, Thomas Dahlmann,
	Sascha Hauer, Christian Hemp, Haojian Zhuang, Daniel Mack,
	Neil Zhang, Oliver Neukum, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, linux-usb, Felipe Balbi, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1891 bytes --]

Hi,

On Mon, May 21, 2012 at 08:57:22AM +0200, Christoph Fritz wrote:
> USB controller may access a wrong address for the dTD (endpoint transfer
> descriptor) and then hang. This happens a lot when doing tests with
> g_ether module and iperf, a tool for measuring maximum TCP and UDP
> bandwidth.
> 
> This hardware bug is explained in detail by errata number 2858 for i.MX23:
> http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> 
> All (?) SOCs with an IP from chipidea suffer from this problem.
> mv_udc_core fixes this bug by commit daec765.  There still may be
> unfixed drivers.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> Signed-off-by: Christian Hemp <c.hemp@phytec.de>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |   15 ++++++++++++++-
>  1 files changed, 14 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 55abfb6..72f2139 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -65,6 +65,8 @@ static struct usb_sys_interface *usb_sys_regs;
>  /* it is initialized in probe()  */
>  static struct fsl_udc *udc_controller = NULL;
>  
> +static struct ep_td_struct *last_free_td;

I don't want to see global variables anymore. In fact, please convert
this to the new udc_start()/udc_stop() calls and use the generic
map/unmap routines.

That'll help you get rid of a bunch of useless code on the driver. After
that you should remove all <asm/*> header includes and drop the ARCH
dependency.

You can also drop the big-/little-endian helpers as you can make use of
generic writel()/readl() routines.

Please make sure these series comes in with enough time to reach v3.6
merge window in about 3 months.

You can put this fix together on that series after you drop the global.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-05-21 19:04                                 ` Felipe Balbi
@ 2012-06-04 11:30                                   ` Christoph Fritz
  2012-06-04 11:37                                     ` Christoph Fritz
  2012-06-04 14:59                                     ` Felipe Balbi
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
  1 sibling, 2 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-06-04 11:30 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Fabio Estevam, Kukjin Kim, Russell King, Thomas Dahlmann,
	Sascha Hauer, Christian Hemp, Haojian Zhuang, Daniel Mack,
	Neil Zhang, linux-arm-kernel, Oliver Neukum, Eric Miao,
	Li Yang-R58472, Greg Kroah-Hartman, linux-usb, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

Hi,

On Mon, 2012-05-21 at 22:04 +0300, Felipe Balbi wrote:
> On Mon, May 21, 2012 at 08:57:22AM +0200, Christoph Fritz wrote:
> > USB controller may access a wrong address for the dTD (endpoint transfer
> > descriptor) and then hang. This happens a lot when doing tests with
> > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > bandwidth.
> > 
> > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > 
> > All (?) SOCs with an IP from chipidea suffer from this problem.
> > mv_udc_core fixes this bug by commit daec765.  There still may be
> > unfixed drivers.
> > 
> > Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> > Signed-off-by: Christian Hemp <c.hemp@phytec.de>
> > ---
> >  drivers/usb/gadget/fsl_udc_core.c |   15 ++++++++++++++-
> >  1 files changed, 14 insertions(+), 1 deletions(-)
> > 
> > diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> > index 55abfb6..72f2139 100644
> > --- a/drivers/usb/gadget/fsl_udc_core.c
> > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > @@ -65,6 +65,8 @@ static struct usb_sys_interface *usb_sys_regs;
> >  /* it is initialized in probe()  */
> >  static struct fsl_udc *udc_controller = NULL;
> >  
> > +static struct ep_td_struct *last_free_td;
> 
> I don't want to see global variables anymore. In fact, please convert
> this to the new udc_start()/udc_stop() calls and use the generic
> map/unmap routines.
> 
> That'll help you get rid of a bunch of useless code on the driver. After
> that you should remove all <asm/*> header includes and drop the ARCH
> dependency.
> 
> You can also drop the big-/little-endian helpers as you can make use of
> generic writel()/readl() routines.
> 
> Please make sure these series comes in with enough time to reach v3.6
> merge window in about 3 months.
> 
> You can put this fix together on that series after you drop the global.

Before I came to do the proposed changes, I stumbled upon this:

In file included from drivers/usb/gadget/fsl_udc_core.c:49:
drivers/usb/gadget/fsl_usb2_udc.h: In function ‘get_qh_by_ep’:
drivers/usb/gadget/fsl_usb2_udc.h:585: error: ‘struct fsl_ep’ has no member named ‘desc’
drivers/usb/gadget/fsl_udc_core.c: In function ‘done’:
drivers/usb/gadget/fsl_udc_core.c:187: error: ‘struct fsl_ep’ has no member named ‘desc’
drivers/usb/gadget/fsl_udc_core.c:187: error: ‘struct fsl_ep’ has no member named ‘desc’
<snip>

my proposed regression patch:
---
From: Christoph Fritz <chf.fritz@googlemail.com>
Date: Mon, 4 Jun 2012 12:58:21 +0200
Subject: [PATCH] usb: gadget: regression fix - useage of usb_ep

This patch removes redundant pointer to struct usb_endpoint_descriptor which
were missed in commit 79149b8:

 usb: gadget: Update fsl_udc_core to use usb_endpoint_descriptor inside the
 struct usb_ep

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |    2 +-
 drivers/usb/gadget/fsl_usb2_udc.h |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 2831685..678ec4d 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2575,7 +2575,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 	/* for ep0: the desc defined here;
 	 * for other eps, gadget layer called ep_enable with defined desc
 	 */
-	udc_controller->eps[0].desc = &fsl_ep0_desc;
+	udc_controller->eps[0].ep.desc = &fsl_ep0_desc;
 	udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
 
 	/* setup the udc->eps[] for non-control endpoints and link
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 5cd7b7e..f61a967 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -568,10 +568,10 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
 /*
  * ### internal used help routines.
  */
-#define ep_index(EP)		((EP)->desc->bEndpointAddress&0xF)
+#define ep_index(EP)		((EP)->ep.desc->bEndpointAddress&0xF)
 #define ep_maxpacket(EP)	((EP)->ep.maxpacket)
 #define ep_is_in(EP)	( (ep_index(EP) == 0) ? (EP->udc->ep0_dir == \
-			USB_DIR_IN ):((EP)->desc->bEndpointAddress \
+			USB_DIR_IN) : ((EP)->ep.desc->bEndpointAddress \
 			& USB_DIR_IN)==USB_DIR_IN)
 #define get_ep_by_pipe(udc, pipe)	((pipe == 1)? &udc->eps[0]: \
 					&udc->eps[pipe])
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-06-04 11:30                                   ` Christoph Fritz
@ 2012-06-04 11:37                                     ` Christoph Fritz
  2012-06-10 18:41                                       ` Fabio Estevam
  2012-06-04 14:59                                     ` Felipe Balbi
  1 sibling, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-06-04 11:37 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Fabio Estevam, Kukjin Kim, Russell King, Thomas Dahlmann,
	Christian Hemp, Haojian Zhuang, Daniel Mack, Neil Zhang,
	linux-arm-kernel, Oliver Neukum, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, linux-usb, Felipe Balbi, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

On Mon, 2012-06-04 at 13:30 +0200, Christoph Fritz wrote:
> Hi,
> 
> On Mon, 2012-05-21 at 22:04 +0300, Felipe Balbi wrote:
> > On Mon, May 21, 2012 at 08:57:22AM +0200, Christoph Fritz wrote:
> > > USB controller may access a wrong address for the dTD (endpoint transfer
> > > descriptor) and then hang. This happens a lot when doing tests with
> > > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > > bandwidth.
> > > 
> > > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > > 
> > > All (?) SOCs with an IP from chipidea suffer from this problem.
> > > mv_udc_core fixes this bug by commit daec765.  There still may be
> > > unfixed drivers.
> > > 
> > > Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> > > Signed-off-by: Christian Hemp <c.hemp@phytec.de>
> > > ---
> > >  drivers/usb/gadget/fsl_udc_core.c |   15 ++++++++++++++-
> > >  1 files changed, 14 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> > > index 55abfb6..72f2139 100644
> > > --- a/drivers/usb/gadget/fsl_udc_core.c
> > > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > > @@ -65,6 +65,8 @@ static struct usb_sys_interface *usb_sys_regs;
> > >  /* it is initialized in probe()  */
> > >  static struct fsl_udc *udc_controller = NULL;
> > >  
> > > +static struct ep_td_struct *last_free_td;
> > 
> > I don't want to see global variables anymore. In fact, please convert
> > this to the new udc_start()/udc_stop() calls and use the generic
> > map/unmap routines.
> > 
> > That'll help you get rid of a bunch of useless code on the driver. After
> > that you should remove all <asm/*> header includes and drop the ARCH
> > dependency.
> > 
> > You can also drop the big-/little-endian helpers as you can make use of
> > generic writel()/readl() routines.
> > 
> > Please make sure these series comes in with enough time to reach v3.6
> > merge window in about 3 months.
> > 
> > You can put this fix together on that series after you drop the global.
> 
> Before I came to do the proposed changes, I stumbled upon this:
> 
> In file included from drivers/usb/gadget/fsl_udc_core.c:49:
> drivers/usb/gadget/fsl_usb2_udc.h: In function ‘get_qh_by_ep’:
> drivers/usb/gadget/fsl_usb2_udc.h:585: error: ‘struct fsl_ep’ has no member named ‘desc’
> drivers/usb/gadget/fsl_udc_core.c: In function ‘done’:
> drivers/usb/gadget/fsl_udc_core.c:187: error: ‘struct fsl_ep’ has no member named ‘desc’
> drivers/usb/gadget/fsl_udc_core.c:187: error: ‘struct fsl_ep’ has no member named ‘desc’
> <snip>
> 
> my proposed regression patch:
> ---
> From: Christoph Fritz <chf.fritz@googlemail.com>
> Date: Mon, 4 Jun 2012 12:58:21 +0200
> Subject: [PATCH] usb: gadget: regression fix - useage of usb_ep
<snip>

After that, I stumbled upon this dmesg:

Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)
fsl-usb2-udc fsl-usb2-udc: clk_get("usb") failed
fsl-usb2-udc: probe of fsl-usb2-udc failed with error -2

Sascha, could you give me a hint?

 Thanks,
  -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-06-04 11:30                                   ` Christoph Fritz
  2012-06-04 11:37                                     ` Christoph Fritz
@ 2012-06-04 14:59                                     ` Felipe Balbi
  2012-06-04 15:24                                       ` [PATCH] usb: gadget: regression fix - useage of usb_ep Christoph Fritz
  1 sibling, 1 reply; 42+ messages in thread
From: Felipe Balbi @ 2012-06-04 14:59 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Fabio Estevam, Kukjin Kim, Russell King, Thomas Dahlmann,
	Sascha Hauer, Christian Hemp, Haojian Zhuang, Daniel Mack,
	Neil Zhang, linux-arm-kernel, Oliver Neukum, Eric Miao,
	Li Yang-R58472, Greg Kroah-Hartman, linux-usb, Felipe Balbi,
	Ido Shayevitz, Estevam Fabio-R49496, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 4985 bytes --]

On Mon, Jun 04, 2012 at 01:30:24PM +0200, Christoph Fritz wrote:
> Hi,
> 
> On Mon, 2012-05-21 at 22:04 +0300, Felipe Balbi wrote:
> > On Mon, May 21, 2012 at 08:57:22AM +0200, Christoph Fritz wrote:
> > > USB controller may access a wrong address for the dTD (endpoint transfer
> > > descriptor) and then hang. This happens a lot when doing tests with
> > > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > > bandwidth.
> > > 
> > > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > > 
> > > All (?) SOCs with an IP from chipidea suffer from this problem.
> > > mv_udc_core fixes this bug by commit daec765.  There still may be
> > > unfixed drivers.
> > > 
> > > Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> > > Signed-off-by: Christian Hemp <c.hemp@phytec.de>
> > > ---
> > >  drivers/usb/gadget/fsl_udc_core.c |   15 ++++++++++++++-
> > >  1 files changed, 14 insertions(+), 1 deletions(-)
> > > 
> > > diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> > > index 55abfb6..72f2139 100644
> > > --- a/drivers/usb/gadget/fsl_udc_core.c
> > > +++ b/drivers/usb/gadget/fsl_udc_core.c
> > > @@ -65,6 +65,8 @@ static struct usb_sys_interface *usb_sys_regs;
> > >  /* it is initialized in probe()  */
> > >  static struct fsl_udc *udc_controller = NULL;
> > >  
> > > +static struct ep_td_struct *last_free_td;
> > 
> > I don't want to see global variables anymore. In fact, please convert
> > this to the new udc_start()/udc_stop() calls and use the generic
> > map/unmap routines.
> > 
> > That'll help you get rid of a bunch of useless code on the driver. After
> > that you should remove all <asm/*> header includes and drop the ARCH
> > dependency.
> > 
> > You can also drop the big-/little-endian helpers as you can make use of
> > generic writel()/readl() routines.
> > 
> > Please make sure these series comes in with enough time to reach v3.6
> > merge window in about 3 months.
> > 
> > You can put this fix together on that series after you drop the global.
> 
> Before I came to do the proposed changes, I stumbled upon this:
> 
> In file included from drivers/usb/gadget/fsl_udc_core.c:49:
> drivers/usb/gadget/fsl_usb2_udc.h: In function ‘get_qh_by_ep’:
> drivers/usb/gadget/fsl_usb2_udc.h:585: error: ‘struct fsl_ep’ has no member named ‘desc’
> drivers/usb/gadget/fsl_udc_core.c: In function ‘done’:
> drivers/usb/gadget/fsl_udc_core.c:187: error: ‘struct fsl_ep’ has no member named ‘desc’
> drivers/usb/gadget/fsl_udc_core.c:187: error: ‘struct fsl_ep’ has no member named ‘desc’
> <snip>
> 
> my proposed regression patch:
> ---
> From: Christoph Fritz <chf.fritz@googlemail.com>
> Date: Mon, 4 Jun 2012 12:58:21 +0200
> Subject: [PATCH] usb: gadget: regression fix - useage of usb_ep
> 
> This patch removes redundant pointer to struct usb_endpoint_descriptor which
> were missed in commit 79149b8:
> 
>  usb: gadget: Update fsl_udc_core to use usb_endpoint_descriptor inside the
>  struct usb_ep
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |    2 +-
>  drivers/usb/gadget/fsl_usb2_udc.h |    4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 2831685..678ec4d 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -2575,7 +2575,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	/* for ep0: the desc defined here;
>  	 * for other eps, gadget layer called ep_enable with defined desc
>  	 */
> -	udc_controller->eps[0].desc = &fsl_ep0_desc;
> +	udc_controller->eps[0].ep.desc = &fsl_ep0_desc;
>  	udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
>  
>  	/* setup the udc->eps[] for non-control endpoints and link
> diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
> index 5cd7b7e..f61a967 100644
> --- a/drivers/usb/gadget/fsl_usb2_udc.h
> +++ b/drivers/usb/gadget/fsl_usb2_udc.h
> @@ -568,10 +568,10 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
>  /*
>   * ### internal used help routines.
>   */
> -#define ep_index(EP)		((EP)->desc->bEndpointAddress&0xF)
> +#define ep_index(EP)		((EP)->ep.desc->bEndpointAddress&0xF)
>  #define ep_maxpacket(EP)	((EP)->ep.maxpacket)
>  #define ep_is_in(EP)	( (ep_index(EP) == 0) ? (EP->udc->ep0_dir == \
> -			USB_DIR_IN ):((EP)->desc->bEndpointAddress \
> +			USB_DIR_IN) : ((EP)->ep.desc->bEndpointAddress \
>  			& USB_DIR_IN)==USB_DIR_IN)
>  #define get_ep_by_pipe(udc, pipe)	((pipe == 1)? &udc->eps[0]: \
>  					&udc->eps[pipe])
> -- 
> 1.7.2.5

Please send as a proper patch so I can apply.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH] usb: gadget: regression fix - useage of usb_ep
  2012-06-04 14:59                                     ` Felipe Balbi
@ 2012-06-04 15:24                                       ` Christoph Fritz
  0 siblings, 0 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-06-04 15:24 UTC (permalink / raw)
  To: balbi
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Fabio Estevam, Kukjin Kim, Russell King, Thomas Dahlmann,
	Sascha Hauer, Christian Hemp, Haojian Zhuang, Daniel Mack,
	Neil Zhang, linux-arm-kernel, Oliver Neukum, Eric Miao,
	Li Yang-R58472, Greg Kroah-Hartman, linux-usb, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

This patch removes redundant pointer to struct usb_endpoint_descriptor which
were missed in commit 79149b8:

 usb: gadget: Update fsl_udc_core to use usb_endpoint_descriptor inside the
 struct usb_ep

Due to clock framework regressions, this patch is only compile tested!

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |    2 +-
 drivers/usb/gadget/fsl_usb2_udc.h |    4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 2831685..678ec4d 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -2575,7 +2575,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 	/* for ep0: the desc defined here;
 	 * for other eps, gadget layer called ep_enable with defined desc
 	 */
-	udc_controller->eps[0].desc = &fsl_ep0_desc;
+	udc_controller->eps[0].ep.desc = &fsl_ep0_desc;
 	udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
 
 	/* setup the udc->eps[] for non-control endpoints and link
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 5cd7b7e..f61a967 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -568,10 +568,10 @@ static void dump_msg(const char *label, const u8 * buf, unsigned int length)
 /*
  * ### internal used help routines.
  */
-#define ep_index(EP)		((EP)->desc->bEndpointAddress&0xF)
+#define ep_index(EP)		((EP)->ep.desc->bEndpointAddress&0xF)
 #define ep_maxpacket(EP)	((EP)->ep.maxpacket)
 #define ep_is_in(EP)	( (ep_index(EP) == 0) ? (EP->udc->ep0_dir == \
-			USB_DIR_IN ):((EP)->desc->bEndpointAddress \
+			USB_DIR_IN) : ((EP)->ep.desc->bEndpointAddress \
 			& USB_DIR_IN)==USB_DIR_IN)
 #define get_ep_by_pipe(udc, pipe)	((pipe == 1)? &udc->eps[0]: \
 					&udc->eps[pipe])
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-06-04 11:37                                     ` Christoph Fritz
@ 2012-06-10 18:41                                       ` Fabio Estevam
  2012-06-12 19:40                                         ` Christoph Fritz
  0 siblings, 1 reply; 42+ messages in thread
From: Fabio Estevam @ 2012-06-10 18:41 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Kukjin Kim, Russell King, Thomas Dahlmann, Sascha Hauer,
	Christian Hemp, Haojian Zhuang, Daniel Mack, Neil Zhang,
	linux-arm-kernel, Oliver Neukum, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, linux-usb, Felipe Balbi, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

Hi Christoph,

On Mon, Jun 4, 2012 at 8:37 AM, Christoph Fritz
<chf.fritz@googlemail.com> wrote:

> After that, I stumbled upon this dmesg:
>
> Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)
> fsl-usb2-udc fsl-usb2-udc: clk_get("usb") failed
> fsl-usb2-udc: probe of fsl-usb2-udc failed with error -2
>
> Sascha, could you give me a hint?

Does the patch below fix your problem?

 drivers/usb/gadget/fsl_mxc_udc.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/usb/gadget/fsl_mxc_udc.c b/drivers/usb/gadget/fsl_mxc_udc.c
index dcbc0a2..c3ade6b 100644
--- a/drivers/usb/gadget/fsl_mxc_udc.c
+++ b/drivers/usb/gadget/fsl_mxc_udc.c
@@ -36,21 +36,21 @@ int fsl_udc_clk_init(struct platform_device *pdev)
 	pdata = pdev->dev.platform_data;

 	if (!cpu_is_mx35() && !cpu_is_mx25()) {
-		mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb");
+		mxc_ahb_clk = clk_get(&pdev->dev, "ipg");
 		if (IS_ERR(mxc_ahb_clk))
 			return PTR_ERR(mxc_ahb_clk);

-		ret = clk_enable(mxc_ahb_clk);
+		ret = clk_prepare_enable(mxc_ahb_clk);
 		if (ret < 0) {
-			dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n");
+			dev_err(&pdev->dev, "clk_enable(\"ipg\") failed\n");
 			goto eenahb;
 		}
 	}

 	/* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
-	mxc_usb_clk = clk_get(&pdev->dev, "usb");
+	mxc_usb_clk = clk_get(&pdev->dev, "per");
 	if (IS_ERR(mxc_usb_clk)) {
-		dev_err(&pdev->dev, "clk_get(\"usb\") failed\n");
+		dev_err(&pdev->dev, "clk_get(\"per\") failed\n");
 		ret = PTR_ERR(mxc_usb_clk);
 		goto egusb;
 	}
@@ -65,7 +65,7 @@ int fsl_udc_clk_init(struct platform_device *pdev)
 		}
 	}

-	ret = clk_enable(mxc_usb_clk);
+	ret = clk_prepare_enable(mxc_usb_clk);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "clk_enable(\"usb_clk\") failed\n");
 		goto eenusb;
@@ -79,7 +79,7 @@ eclkrate:
 	mxc_usb_clk = NULL;
 egusb:
 	if (!cpu_is_mx35())
-		clk_disable(mxc_ahb_clk);
+		clk_disable_unprepare(mxc_ahb_clk);
 eenahb:
 	if (!cpu_is_mx35())
 		clk_put(mxc_ahb_clk);
@@ -104,7 +104,7 @@ void fsl_udc_clk_finalize(struct platform_device *pdev)

 	/* ULPI transceivers don't need usbpll */
 	if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
-		clk_disable(mxc_usb_clk);
+		clk_disable_unprepare(mxc_usb_clk);
 		clk_put(mxc_usb_clk);
 		mxc_usb_clk = NULL;
 	}
@@ -113,11 +113,11 @@ void fsl_udc_clk_finalize(struct platform_device *pdev)
 void fsl_udc_clk_release(void)
 {
 	if (mxc_usb_clk) {
-		clk_disable(mxc_usb_clk);
+		clk_disable_unprepare(mxc_usb_clk);
 		clk_put(mxc_usb_clk);
 	}
 	if (!cpu_is_mx35()) {
-		clk_disable(mxc_ahb_clk);
+		clk_disable_unprepare(mxc_ahb_clk);
 		clk_put(mxc_ahb_clk);
 	}
 }
--

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-06-10 18:41                                       ` Fabio Estevam
@ 2012-06-12 19:40                                         ` Christoph Fritz
  2012-06-13  1:17                                           ` Fabio Estevam
  0 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-06-12 19:40 UTC (permalink / raw)
  To: Fabio Estevam
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Kukjin Kim, Russell King, Thomas Dahlmann, Sascha Hauer,
	Christian Hemp, Haojian Zhuang, Daniel Mack, Neil Zhang,
	linux-arm-kernel, Oliver Neukum, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, linux-usb, Felipe Balbi, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

Hi Fabio

On Sun, 2012-06-10 at 15:41 -0300, Fabio Estevam wrote:
> Hi Christoph,
> 
> On Mon, Jun 4, 2012 at 8:37 AM, Christoph Fritz
> <chf.fritz@googlemail.com> wrote:
> 
> > After that, I stumbled upon this dmesg:
> >
> > Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)
> > fsl-usb2-udc fsl-usb2-udc: clk_get("usb") failed
> > fsl-usb2-udc: probe of fsl-usb2-udc failed with error -2
> >
> > Sascha, could you give me a hint?
> 
> Does the patch below fix your problem?

Thanks for your patch. It does indeed load
"Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)"
fine - but now when I want to use it:

modprobe g_ether
[   17.099363] g_ether gadget: using random self ethernet address
[   17.105316] g_ether gadget: using random host ethernet address
[   17.111974] usb0: MAC 1a:c7:9e:76:cc:45
[   17.115866] usb0: HOST MAC 66:a2:4a:0a:46:17
[   17.120199] g_ether gadget: Ethernet Gadget, version: Memorial Day 2008
[   17.126861] g_ether gadget: g_ether ready

these are "the last words": System hangs completely. Same behavior with
g_serial (these two I've tested).

Currently I can't investigate this further, not because of a bug - but a
flu.


Thanks,
 -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH v2] usb: fsl_udc: errata - postpone freeing current dTD
  2012-06-12 19:40                                         ` Christoph Fritz
@ 2012-06-13  1:17                                           ` Fabio Estevam
  0 siblings, 0 replies; 42+ messages in thread
From: Fabio Estevam @ 2012-06-13  1:17 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Ben Dooks, Chen Peter-B29397, Nicolas Ferre, Hans J. Koch,
	Kukjin Kim, Russell King, Thomas Dahlmann, Sascha Hauer,
	Christian Hemp, Haojian Zhuang, Daniel Mack, Neil Zhang,
	linux-arm-kernel, Oliver Neukum, Eric Miao, Li Yang-R58472,
	Greg Kroah-Hartman, linux-usb, Felipe Balbi, Ido Shayevitz,
	Estevam Fabio-R49496, linuxppc-dev

On Tue, Jun 12, 2012 at 4:40 PM, Christoph Fritz
<chf.fritz@googlemail.com> wrote:

> Thanks for your patch. It does indeed load
> "Freescale High-Speed USB SOC Device Controller driver (Apr 20, 2007)"
> fine - but now when I want to use it:
>
> modprobe g_ether
> [ =C2=A0 17.099363] g_ether gadget: using random self ethernet address
> [ =C2=A0 17.105316] g_ether gadget: using random host ethernet address
> [ =C2=A0 17.111974] usb0: MAC 1a:c7:9e:76:cc:45
> [ =C2=A0 17.115866] usb0: HOST MAC 66:a2:4a:0a:46:17
> [ =C2=A0 17.120199] g_ether gadget: Ethernet Gadget, version: Memorial Da=
y 2008
> [ =C2=A0 17.126861] g_ether gadget: g_ether ready
>
> these are "the last words": System hangs completely. Same behavior with
> g_serial (these two I've tested).

Ok, I just sent a new patch to the linux-usb mailing list.

Tested it on a mx31 and mx51 and it probed g_ether fine. I don't have
a mx35 handy.

>
> Currently I can't investigate this further, not because of a bug - but a
> flu.

Hope you get better soon.

Regards,

Fabio Estevam

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH 0/7] update USB gadget driver fsl-usb2-udc
  2012-05-21 19:04                                 ` Felipe Balbi
  2012-06-04 11:30                                   ` Christoph Fritz
@ 2012-10-19 10:22                                   ` Christoph Fritz
  2012-10-19 10:24                                     ` [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init Christoph Fritz
                                                       ` (7 more replies)
  1 sibling, 8 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:22 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

This series updates USB gadget driver fsl-usb2-udc.

Christoph Fritz (7):
  usb: gadget: fsl_udc: simplify driver init
  usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
  usb: gadget: fsl_udc: convert to new ulc style
  usb: gadget: fsl_udc: drop ARCH dependency
  usb: gadget: fsl_udc: postpone freeing current dTD
  usb: gadget: fsl_udc: purge global pointer usb_sys_regs
  usb: gadget: fsl_udc: purge global pointer dr_regs

 drivers/usb/gadget/fsl_udc_core.c |  755 ++++++++++++++++---------------------
 drivers/usb/gadget/fsl_usb2_udc.h |    4 +
 2 files changed, 322 insertions(+), 437 deletions(-)

-- 
1.7.2.5

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init
  2012-10-19 10:24                                     ` [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init Christoph Fritz
@ 2012-10-19 10:24                                       ` Felipe Balbi
  0 siblings, 0 replies; 42+ messages in thread
From: Felipe Balbi @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 1995 bytes --]

Hi,

On Fri, Oct 19, 2012 at 12:24:39PM +0200, Christoph Fritz wrote:
> To initialize this driver use 'module_platform_driver' instead
> of '__init' and '__exit'.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |   37 +++++++++++--------------------------
>  1 files changed, 11 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 6ae70cb..340451d 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -49,13 +49,14 @@
>  
>  #include "fsl_usb2_udc.h"
>  
> +#define	DRIVER_NAME	"fsl-usb2-udc"
>  #define	DRIVER_DESC	"Freescale High-Speed USB SOC Device Controller driver"
>  #define	DRIVER_AUTHOR	"Li Yang/Jiang Bo"
>  #define	DRIVER_VERSION	"Apr 20, 2007"
>  
>  #define	DMA_ADDR_INVALID	(~(dma_addr_t)0)
>  
> -static const char driver_name[] = "fsl-usb2-udc";
> +static const char driver_name[] = DRIVER_NAME;
>  static const char driver_desc[] = DRIVER_DESC;
>  
>  static struct usb_dr_device *dr_regs;
> @@ -2761,35 +2762,19 @@ static int fsl_udc_otg_resume(struct device *dev)
>  	Register entry point for the peripheral controller driver
>  --------------------------------------------------------------------------*/
>  
> -static struct platform_driver udc_driver = {
> -	.remove  = __exit_p(fsl_udc_remove),
> -	/* these suspend and resume are not usb suspend and resume */
> -	.suspend = fsl_udc_suspend,
> -	.resume  = fsl_udc_resume,
> -	.driver  = {
> -		.name = (char *)driver_name,
> -		.owner = THIS_MODULE,
> -		/* udc suspend/resume called from OTG driver */
> +static struct platform_driver fsl_udc_driver = {
> +	.probe		= fsl_udc_probe,

NAK, probe() lies in .init.text section. You need to change __init to
__devinit. Likewise for all functions which are only called during
probe() and for remove() which needs s/__exit/__devexit.

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 10:24                                       ` Felipe Balbi
  2012-10-19 10:24                                     ` [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock Christoph Fritz
                                                       ` (6 subsequent siblings)
  7 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

To initialize this driver use 'module_platform_driver' instead
of '__init' and '__exit'.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |   37 +++++++++++--------------------------
 1 files changed, 11 insertions(+), 26 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 6ae70cb..340451d 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -49,13 +49,14 @@
 
 #include "fsl_usb2_udc.h"
 
+#define	DRIVER_NAME	"fsl-usb2-udc"
 #define	DRIVER_DESC	"Freescale High-Speed USB SOC Device Controller driver"
 #define	DRIVER_AUTHOR	"Li Yang/Jiang Bo"
 #define	DRIVER_VERSION	"Apr 20, 2007"
 
 #define	DMA_ADDR_INVALID	(~(dma_addr_t)0)
 
-static const char driver_name[] = "fsl-usb2-udc";
+static const char driver_name[] = DRIVER_NAME;
 static const char driver_desc[] = DRIVER_DESC;
 
 static struct usb_dr_device *dr_regs;
@@ -2761,35 +2762,19 @@ static int fsl_udc_otg_resume(struct device *dev)
 	Register entry point for the peripheral controller driver
 --------------------------------------------------------------------------*/
 
-static struct platform_driver udc_driver = {
-	.remove  = __exit_p(fsl_udc_remove),
-	/* these suspend and resume are not usb suspend and resume */
-	.suspend = fsl_udc_suspend,
-	.resume  = fsl_udc_resume,
-	.driver  = {
-		.name = (char *)driver_name,
-		.owner = THIS_MODULE,
-		/* udc suspend/resume called from OTG driver */
+static struct platform_driver fsl_udc_driver = {
+	.probe		= fsl_udc_probe,
+	.remove		= __devexit_p(fsl_udc_remove),
+	.suspend	= fsl_udc_suspend,
+	.resume		= fsl_udc_resume,
+	.driver		= {
+		.name	= DRIVER_NAME,
+		.owner	= THIS_MODULE,
 		.suspend = fsl_udc_otg_suspend,
 		.resume  = fsl_udc_otg_resume,
 	},
 };
-
-static int __init udc_init(void)
-{
-	printk(KERN_INFO "%s (%s)\n", driver_desc, DRIVER_VERSION);
-	return platform_driver_probe(&udc_driver, fsl_udc_probe);
-}
-
-module_init(udc_init);
-
-static void __exit udc_exit(void)
-{
-	platform_driver_unregister(&udc_driver);
-	printk(KERN_WARNING "%s unregistered\n", driver_desc);
-}
-
-module_exit(udc_exit);
+module_platform_driver(fsl_udc_driver);
 
 MODULE_DESCRIPTION(DRIVER_DESC);
 MODULE_AUTHOR(DRIVER_AUTHOR);
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
  2012-10-19 10:24                                     ` [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 10:25                                       ` Felipe Balbi
  2012-10-19 10:24                                     ` [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style Christoph Fritz
                                                       ` (5 subsequent siblings)
  7 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

This patch reworks fsl_pullup() against the background of switching over
to udc_start()/udc_stop() style:

Protect function fsl_pullup() with a spin_lock. Also set vbus_active as
default to true. This prevents disabling USB controller if there is no
driver support for an external transceiver (or GPIO) that detects a VBUS
power session starting.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 340451d..0a0d6a6 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -1242,8 +1242,10 @@ static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
 static int fsl_pullup(struct usb_gadget *gadget, int is_on)
 {
 	struct fsl_udc *udc;
+	unsigned long flags;
 
 	udc = container_of(gadget, struct fsl_udc, gadget);
+	spin_lock_irqsave(&udc->lock, flags);
 	udc->softconnect = (is_on != 0);
 	if (can_pullup(udc))
 		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
@@ -1251,6 +1253,7 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
 	else
 		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
 				&dr_regs->usbcmd);
+	spin_unlock_irqrestore(&udc->lock, flags);
 
 	return 0;
 }
@@ -2557,6 +2560,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&udc_controller->gadget.ep_list);
 	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
 	udc_controller->gadget.name = driver_name;
+	udc->vbus_active = true;
 
 	/* Setup gadget.dev and register with kernel */
 	dev_set_name(&udc_controller->gadget.dev, "gadget");
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
  2012-10-19 10:24                                     ` [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init Christoph Fritz
  2012-10-19 10:24                                     ` [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 10:27                                       ` Felipe Balbi
  2012-10-19 10:24                                     ` [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency Christoph Fritz
                                                       ` (4 subsequent siblings)
  7 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

Convert to new UDC style registration and remove
global 'udc_controller' pointer.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |  289 +++++++++++++++++--------------------
 1 files changed, 131 insertions(+), 158 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 0a0d6a6..d113f39 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -63,9 +63,6 @@ static struct usb_dr_device *dr_regs;
 
 static struct usb_sys_interface *usb_sys_regs;
 
-/* it is initialized in probe()  */
-static struct fsl_udc *udc_controller = NULL;
-
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -783,12 +780,14 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
 }
 
 /* Fill in the dTD structure
+ * @udc: driver private data
  * @req: request that the transfer belongs to
  * @length: return actually data length of the dTD
  * @dma: return dma address of the dTD
  * @is_last: return flag if it is the last dTD of the request
  * return: pointer to the built dTD */
-static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
+static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
+		struct fsl_req *req, unsigned *length,
 		dma_addr_t *dma, int *is_last, gfp_t gfp_flags)
 {
 	u32 swap_temp;
@@ -798,7 +797,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
 	*length = min(req->req.length - req->req.actual,
 			(unsigned)EP_MAX_LENGTH_TRANSFER);
 
-	dtd = dma_pool_alloc(udc_controller->td_pool, gfp_flags, dma);
+	dtd = dma_pool_alloc(udc->td_pool, gfp_flags, dma);
 	if (dtd == NULL)
 		return dtd;
 
@@ -848,7 +847,8 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
 }
 
 /* Generate dtd chain for a request */
-static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
+static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
+		gfp_t gfp_flags)
 {
 	unsigned	count;
 	int		is_last;
@@ -857,7 +857,8 @@ static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
 	dma_addr_t dma;
 
 	do {
-		dtd = fsl_build_dtd(req, &count, &dma, &is_last, gfp_flags);
+		dtd = fsl_build_dtd(udc, req, &count, &dma, &is_last,
+				gfp_flags);
 		if (dtd == NULL)
 			return -ENOMEM;
 
@@ -932,7 +933,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
 	req->dtd_count = 0;
 
 	/* build dtds and push them to device queue */
-	if (!fsl_req_to_dtd(req, gfp_flags)) {
+	if (!fsl_req_to_dtd(udc, req, gfp_flags)) {
 		spin_lock_irqsave(&udc->lock, flags);
 		fsl_queue_td(ep, req);
 	} else {
@@ -1258,9 +1259,10 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
 	return 0;
 }
 
-static int fsl_start(struct usb_gadget_driver *driver,
-		int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
-static int fsl_stop(struct usb_gadget_driver *driver);
+static int fsl_udc_start(struct usb_gadget *gadget,
+		struct usb_gadget_driver *driver);
+static int fsl_udc_stop(struct usb_gadget *gadget,
+		struct usb_gadget_driver *driver);
 /* defined in gadget.h */
 static struct usb_gadget_ops fsl_gadget_ops = {
 	.get_frame = fsl_get_frame,
@@ -1269,8 +1271,8 @@ static struct usb_gadget_ops fsl_gadget_ops = {
 	.vbus_session = fsl_vbus_session,
 	.vbus_draw = fsl_vbus_draw,
 	.pullup = fsl_pullup,
-	.start = fsl_start,
-	.stop = fsl_stop,
+	.udc_start = fsl_udc_start,
+	.udc_stop = fsl_udc_stop,
 };
 
 /* Set protocol stall on ep0, protocol stall will automatically be cleared
@@ -1314,7 +1316,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
 			ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
 	req->mapped = 1;
 
-	if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0)
+	if (fsl_req_to_dtd(udc, req, GFP_ATOMIC) == 0)
 		fsl_queue_td(ep, req);
 	else
 		return -ENOMEM;
@@ -1398,7 +1400,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
 	req->mapped = 1;
 
 	/* prime the data phase */
-	if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0))
+	if ((fsl_req_to_dtd(udc, req, GFP_ATOMIC) == 0))
 		fsl_queue_td(ep, req);
 	else			/* no mem */
 		goto stall;
@@ -1422,7 +1424,7 @@ static void setup_received_irq(struct fsl_udc *udc,
 
 	udc_reset_ep_queue(udc, 0);
 
-	/* We process some stardard setup requests here */
+	/* We process some standard setup requests here */
 	switch (setup->bRequest) {
 	case USB_REQ_GET_STATUS:
 		/* Data+Status phase from udc */
@@ -1954,114 +1956,82 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
  * Hook to gadget drivers
  * Called by initialization code of gadget drivers
 *----------------------------------------------------------------*/
-static int fsl_start(struct usb_gadget_driver *driver,
-		int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
+static int fsl_udc_start(struct usb_gadget *gadget,
+	struct usb_gadget_driver *driver)
 {
+	struct fsl_udc *udc;
 	int retval = -ENODEV;
-	unsigned long flags = 0;
+	unsigned long flags;
 
-	if (!udc_controller)
+	udc = container_of(gadget, struct fsl_udc, gadget);
+	if (!udc)
 		return -ENODEV;
 
 	if (!driver || driver->max_speed < USB_SPEED_FULL
-			|| !bind || !driver->disconnect || !driver->setup)
+			|| !driver->disconnect || !driver->setup)
 		return -EINVAL;
 
-	if (udc_controller->driver)
-		return -EBUSY;
-
 	/* lock is needed but whether should use this lock or another */
-	spin_lock_irqsave(&udc_controller->lock, flags);
+	spin_lock_irqsave(&udc->lock, flags);
 
 	driver->driver.bus = NULL;
-	/* hook up the driver */
-	udc_controller->driver = driver;
-	udc_controller->gadget.dev.driver = &driver->driver;
-	spin_unlock_irqrestore(&udc_controller->lock, flags);
-
-	/* bind udc driver to gadget driver */
-	retval = bind(&udc_controller->gadget, driver);
-	if (retval) {
-		VDBG("bind to %s --> %d", driver->driver.name, retval);
-		udc_controller->gadget.dev.driver = NULL;
-		udc_controller->driver = NULL;
-		goto out;
-	}
 
-	if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
+	if (!IS_ERR_OR_NULL(udc->transceiver)) {
 		/* Suspend the controller until OTG enable it */
-		udc_controller->stopped = 1;
+		udc->stopped = 1;
 		printk(KERN_INFO "Suspend udc for OTG auto detect\n");
 
 		/* connect to bus through transceiver */
-		if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
-			retval = otg_set_peripheral(
-					udc_controller->transceiver->otg,
-						    &udc_controller->gadget);
+		if (!IS_ERR_OR_NULL(udc->transceiver)) {
+			retval = otg_set_peripheral(udc->transceiver->otg,
+					&udc->gadget);
 			if (retval < 0) {
 				ERR("can't bind to transceiver\n");
-				driver->unbind(&udc_controller->gadget);
-				udc_controller->gadget.dev.driver = 0;
-				udc_controller->driver = 0;
 				return retval;
 			}
 		}
 	} else {
-		/* Enable DR IRQ reg and set USBCMD reg Run bit */
-		dr_controller_run(udc_controller);
-		udc_controller->usb_state = USB_STATE_ATTACHED;
-		udc_controller->ep0_state = WAIT_FOR_SETUP;
-		udc_controller->ep0_dir = 0;
+		/* hook up the driver */
+		udc->driver = driver;
+		udc->gadget.dev.driver = &driver->driver;
+		dr_controller_run(udc);
+		udc->usb_state = USB_STATE_ATTACHED;
+		udc->ep0_state = WAIT_FOR_SETUP;
+		udc->ep0_dir = USB_DIR_OUT;
 	}
-	printk(KERN_INFO "%s: bind to driver %s\n",
-			udc_controller->gadget.name, driver->driver.name);
+	spin_unlock_irqrestore(&udc->lock, flags);
 
-out:
-	if (retval)
-		printk(KERN_WARNING "gadget driver register failed %d\n",
-		       retval);
-	return retval;
+	return 0;
 }
 
 /* Disconnect from gadget driver */
-static int fsl_stop(struct usb_gadget_driver *driver)
+static int fsl_udc_stop(struct usb_gadget *gadget,
+	struct usb_gadget_driver *driver)
 {
+	struct fsl_udc *udc;
 	struct fsl_ep *loop_ep;
 	unsigned long flags;
 
-	if (!udc_controller)
-		return -ENODEV;
-
-	if (!driver || driver != udc_controller->driver || !driver->unbind)
-		return -EINVAL;
-
-	if (!IS_ERR_OR_NULL(udc_controller->transceiver))
-		otg_set_peripheral(udc_controller->transceiver->otg, NULL);
+	udc = container_of(gadget, struct fsl_udc, gadget);
 
 	/* stop DR, disable intr */
-	dr_controller_stop(udc_controller);
+	dr_controller_stop(udc);
 
 	/* in fact, no needed */
-	udc_controller->usb_state = USB_STATE_ATTACHED;
-	udc_controller->ep0_state = WAIT_FOR_SETUP;
-	udc_controller->ep0_dir = 0;
+	udc->usb_state = USB_STATE_ATTACHED;
+	udc->ep0_state = WAIT_FOR_SETUP;
+	udc->ep0_dir = USB_DIR_OUT;
 
 	/* stand operation */
-	spin_lock_irqsave(&udc_controller->lock, flags);
-	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
-	nuke(&udc_controller->eps[0], -ESHUTDOWN);
-	list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list,
-			ep.ep_list)
+	spin_lock_irqsave(&udc->lock, flags);
+	udc->gadget.speed = USB_SPEED_UNKNOWN;
+	nuke(&udc->eps[0], -ESHUTDOWN);
+	list_for_each_entry(loop_ep, &udc->gadget.ep_list, ep.ep_list)
 		nuke(loop_ep, -ESHUTDOWN);
-	spin_unlock_irqrestore(&udc_controller->lock, flags);
-
-	/* report disconnect; the controller is already quiesced */
-	driver->disconnect(&udc_controller->gadget);
+	spin_unlock_irqrestore(&udc->lock, flags);
 
-	/* unbind gadget and unhook driver. */
-	driver->unbind(&udc_controller->gadget);
-	udc_controller->gadget.dev.driver = NULL;
-	udc_controller->driver = NULL;
+	udc->gadget.dev.driver = NULL;
+	udc->driver = NULL;
 
 	printk(KERN_WARNING "unregistered gadget driver '%s'\n",
 	       driver->driver.name);
@@ -2088,8 +2058,8 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	u32 tmp_reg;
 	struct fsl_ep *ep = NULL;
 	struct fsl_req *req;
+	struct fsl_udc *udc = _dev;
 
-	struct fsl_udc *udc = udc_controller;
 	if (off != 0)
 		return 0;
 
@@ -2318,7 +2288,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 }
 
 #define create_proc_file()	create_proc_read_entry(proc_filename, \
-				0, NULL, fsl_proc_read, NULL)
+				0, NULL, fsl_proc_read, udc)
 
 #define remove_proc_file()	remove_proc_entry(proc_filename, NULL)
 
@@ -2334,10 +2304,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 /* Release udc structures */
 static void fsl_udc_release(struct device *dev)
 {
-	complete(udc_controller->done);
-	dma_free_coherent(dev->parent, udc_controller->ep_qh_size,
-			udc_controller->ep_qh, udc_controller->ep_qh_dma);
-	kfree(udc_controller);
+	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
+
+	complete(udc->done);
+	dma_free_coherent(dev->parent, udc->ep_qh_size,
+			udc->ep_qh, udc->ep_qh_dma);
+	kfree(udc);
 }
 
 /******************************************************************
@@ -2436,6 +2408,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,
  */
 static int __init fsl_udc_probe(struct platform_device *pdev)
 {
+	struct fsl_udc *udc;
 	struct fsl_usb2_platform_data *pdata;
 	struct resource *res;
 	int ret = -ENODEV;
@@ -2447,21 +2420,21 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		return -ENODEV;
 	}
 
-	udc_controller = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
-	if (udc_controller == NULL) {
+	udc = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
+	if (udc == NULL) {
 		ERR("malloc udc failed\n");
 		return -ENOMEM;
 	}
 
 	pdata = pdev->dev.platform_data;
-	udc_controller->pdata = pdata;
-	spin_lock_init(&udc_controller->lock);
-	udc_controller->stopped = 1;
+	udc->pdata = pdata;
+	spin_lock_init(&udc->lock);
+	udc->stopped = 1;
 
 #ifdef CONFIG_USB_OTG
 	if (pdata->operating_mode == FSL_USB2_DR_OTG) {
-		udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
-		if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
+		udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
+		if (IS_ERR_OR_NULL(udc->transceiver)) {
 			ERR("Can't find OTG driver!\n");
 			ret = -ENODEV;
 			goto err_kfree;
@@ -2522,90 +2495,90 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 	}
 	/* Get max device endpoints */
 	/* DEN is bidirectional ep number, max_ep doubles the number */
-	udc_controller->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2;
+	udc->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2;
 
-	udc_controller->irq = platform_get_irq(pdev, 0);
-	if (!udc_controller->irq) {
+	udc->irq = platform_get_irq(pdev, 0);
+	if (!udc->irq) {
 		ret = -ENODEV;
 		goto err_iounmap;
 	}
 
-	ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED,
-			driver_name, udc_controller);
+	ret = request_irq(udc->irq, fsl_udc_irq, IRQF_SHARED,
+			driver_name, udc);
 	if (ret != 0) {
 		ERR("cannot request irq %d err %d\n",
-				udc_controller->irq, ret);
+				udc->irq, ret);
 		goto err_iounmap;
 	}
 
 	/* Initialize the udc structure including QH member and other member */
-	if (struct_udc_setup(udc_controller, pdev)) {
+	if (struct_udc_setup(udc, pdev)) {
 		ERR("Can't initialize udc data structure\n");
 		ret = -ENOMEM;
 		goto err_free_irq;
 	}
 
-	if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
+	if (IS_ERR_OR_NULL(udc->transceiver)) {
 		/* initialize usb hw reg except for regs for EP,
 		 * leave usbintr reg untouched */
-		dr_controller_setup(udc_controller);
+		dr_controller_setup(udc);
 	}
 
 	fsl_udc_clk_finalize(pdev);
 
 	/* Setup gadget structure */
-	udc_controller->gadget.ops = &fsl_gadget_ops;
-	udc_controller->gadget.max_speed = USB_SPEED_HIGH;
-	udc_controller->gadget.ep0 = &udc_controller->eps[0].ep;
-	INIT_LIST_HEAD(&udc_controller->gadget.ep_list);
-	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
-	udc_controller->gadget.name = driver_name;
+	udc->gadget.ops = &fsl_gadget_ops;
+	udc->gadget.max_speed = USB_SPEED_HIGH;
+	udc->gadget.ep0 = &udc->eps[0].ep;
+	INIT_LIST_HEAD(&udc->gadget.ep_list);
+	udc->gadget.speed = USB_SPEED_UNKNOWN;
+	udc->gadget.name = driver_name;
 	udc->vbus_active = true;
 
 	/* Setup gadget.dev and register with kernel */
-	dev_set_name(&udc_controller->gadget.dev, "gadget");
-	udc_controller->gadget.dev.release = fsl_udc_release;
-	udc_controller->gadget.dev.parent = &pdev->dev;
-	udc_controller->gadget.dev.of_node = pdev->dev.of_node;
-	ret = device_register(&udc_controller->gadget.dev);
+	dev_set_name(&udc->gadget.dev, "gadget");
+	udc->gadget.dev.release = fsl_udc_release;
+	udc->gadget.dev.parent = &pdev->dev;
+	udc->gadget.dev.of_node = pdev->dev.of_node;
+	ret = device_register(&udc->gadget.dev);
 	if (ret < 0)
 		goto err_free_irq;
 
-	if (!IS_ERR_OR_NULL(udc_controller->transceiver))
-		udc_controller->gadget.is_otg = 1;
+	if (!IS_ERR_OR_NULL(udc->transceiver))
+		udc->gadget.is_otg = 1;
 
 	/* setup QH and epctrl for ep0 */
-	ep0_setup(udc_controller);
+	ep0_setup(udc);
 
 	/* setup udc->eps[] for ep0 */
-	struct_ep_setup(udc_controller, 0, "ep0", 0);
+	struct_ep_setup(udc, 0, "ep0", 0);
 	/* for ep0: the desc defined here;
 	 * for other eps, gadget layer called ep_enable with defined desc
 	 */
-	udc_controller->eps[0].ep.desc = &fsl_ep0_desc;
-	udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
+	udc->eps[0].ep.desc = &fsl_ep0_desc;
+	udc->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
 
 	/* setup the udc->eps[] for non-control endpoints and link
 	 * to gadget.ep_list */
-	for (i = 1; i < (int)(udc_controller->max_ep / 2); i++) {
+	for (i = 1; i < (int)(udc->max_ep / 2); i++) {
 		char name[14];
 
 		sprintf(name, "ep%dout", i);
-		struct_ep_setup(udc_controller, i * 2, name, 1);
+		struct_ep_setup(udc, i * 2, name, 1);
 		sprintf(name, "ep%din", i);
-		struct_ep_setup(udc_controller, i * 2 + 1, name, 1);
+		struct_ep_setup(udc, i * 2 + 1, name, 1);
 	}
 
 	/* use dma_pool for TD management */
-	udc_controller->td_pool = dma_pool_create("udc_td", &pdev->dev,
+	udc->td_pool = dma_pool_create("udc_td", &pdev->dev,
 			sizeof(struct ep_td_struct),
 			DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
-	if (udc_controller->td_pool == NULL) {
+	if (udc->td_pool == NULL) {
 		ret = -ENOMEM;
 		goto err_unregister;
 	}
 
-	ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
+	ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
 	if (ret)
 		goto err_del_udc;
 
@@ -2613,11 +2586,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 	return 0;
 
 err_del_udc:
-	dma_pool_destroy(udc_controller->td_pool);
+	dma_pool_destroy(udc->td_pool);
 err_unregister:
-	device_unregister(&udc_controller->gadget.dev);
+	device_unregister(&udc->gadget.dev);
 err_free_irq:
-	free_irq(udc_controller->irq, udc_controller);
+	free_irq(udc->irq, udc);
 err_iounmap:
 	if (pdata->exit)
 		pdata->exit(pdev);
@@ -2628,8 +2601,7 @@ err_release_mem_region:
 	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
 		release_mem_region(res->start, resource_size(res));
 err_kfree:
-	kfree(udc_controller);
-	udc_controller = NULL;
+	kfree(udc);
 	return ret;
 }
 
@@ -2638,16 +2610,13 @@ err_kfree:
  */
 static int __exit fsl_udc_remove(struct platform_device *pdev)
 {
+	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
 	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
-
 	DECLARE_COMPLETION(done);
 
-	if (!udc_controller)
-		return -ENODEV;
-
-	usb_del_gadget_udc(&udc_controller->gadget);
-	udc_controller->done = &done;
+	usb_del_gadget_udc(&udc->gadget);
+	udc->done = &done;
 
 	fsl_udc_clk_release();
 
@@ -2655,17 +2624,17 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
 	remove_proc_file();
 
 	/* Free allocated memory */
-	kfree(udc_controller->status_req->req.buf);
-	kfree(udc_controller->status_req);
-	kfree(udc_controller->eps);
+	kfree(udc->status_req->req.buf);
+	kfree(udc->status_req);
+	kfree(udc->eps);
 
-	dma_pool_destroy(udc_controller->td_pool);
-	free_irq(udc_controller->irq, udc_controller);
+	dma_pool_destroy(udc->td_pool);
+	free_irq(udc->irq, udc);
 	iounmap(dr_regs);
 	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
 		release_mem_region(res->start, resource_size(res));
 
-	device_unregister(&udc_controller->gadget.dev);
+	device_unregister(&udc->gadget.dev);
 	/* free udc --wait for the release() finished */
 	wait_for_completion(&done);
 
@@ -2685,7 +2654,8 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
  -----------------------------------------------------------------*/
 static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-	dr_controller_stop(udc_controller);
+	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
+	dr_controller_stop(udc);
 	return 0;
 }
 
@@ -2695,20 +2665,21 @@ static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state)
  *-----------------------------------------------------------------*/
 static int fsl_udc_resume(struct platform_device *pdev)
 {
+	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
 	/* Enable DR irq reg and set controller Run */
-	if (udc_controller->stopped) {
-		dr_controller_setup(udc_controller);
-		dr_controller_run(udc_controller);
+	if (udc->stopped) {
+		dr_controller_setup(udc);
+		dr_controller_run(udc);
 	}
-	udc_controller->usb_state = USB_STATE_ATTACHED;
-	udc_controller->ep0_state = WAIT_FOR_SETUP;
-	udc_controller->ep0_dir = 0;
+	udc->usb_state = USB_STATE_ATTACHED;
+	udc->ep0_state = WAIT_FOR_SETUP;
+	udc->ep0_dir = USB_DIR_OUT;
 	return 0;
 }
 
 static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 {
-	struct fsl_udc *udc = udc_controller;
+	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
 	u32 mode, usbcmd;
 
 	mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
@@ -2744,15 +2715,17 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 
 static int fsl_udc_otg_resume(struct device *dev)
 {
+	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
+
 	pr_debug("%s(): stopped %d  already_stopped %d\n", __func__,
-		 udc_controller->stopped, udc_controller->already_stopped);
+		 udc->stopped, udc->already_stopped);
 
 	/*
 	 * If the controller was stopped at suspend time, then
 	 * don't resume it now.
 	 */
-	if (udc_controller->already_stopped) {
-		udc_controller->already_stopped = 0;
+	if (udc->already_stopped) {
+		udc->already_stopped = 0;
 		pr_debug("gadget was already stopped, leaving early\n");
 		return 0;
 	}
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
                                                       ` (2 preceding siblings ...)
  2012-10-19 10:24                                     ` [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 10:29                                       ` Felipe Balbi
  2012-10-19 10:24                                     ` [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD Christoph Fritz
                                                       ` (3 subsequent siblings)
  7 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

Drop the big-/little-endian helpers and make use of generic
writel()/readl() routines.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |  331 +++++++++++++------------------------
 1 files changed, 118 insertions(+), 213 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index d113f39..53df9c0 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -20,32 +20,14 @@
 #undef VERBOSE
 
 #include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/ioport.h>
-#include <linux/types.h>
-#include <linux/errno.h>
-#include <linux/err.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-#include <linux/list.h>
 #include <linux/interrupt.h>
 #include <linux/proc_fs.h>
-#include <linux/mm.h>
-#include <linux/moduleparam.h>
-#include <linux/device.h>
-#include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/otg.h>
 #include <linux/dma-mapping.h>
 #include <linux/platform_device.h>
 #include <linux/fsl_devices.h>
 #include <linux/dmapool.h>
-#include <linux/delay.h>
-
-#include <asm/byteorder.h>
-#include <asm/io.h>
-#include <asm/unaligned.h>
-#include <asm/dma.h>
 
 #include "fsl_usb2_udc.h"
 
@@ -74,78 +56,6 @@ fsl_ep0_desc = {
 
 static void fsl_ep_fifo_flush(struct usb_ep *_ep);
 
-#ifdef CONFIG_PPC32
-/*
- * On some SoCs, the USB controller registers can be big or little endian,
- * depending on the version of the chip. In order to be able to run the
- * same kernel binary on 2 different versions of an SoC, the BE/LE decision
- * must be made at run time. _fsl_readl and fsl_writel are pointers to the
- * BE or LE readl() and writel() functions, and fsl_readl() and fsl_writel()
- * call through those pointers. Platform code for SoCs that have BE USB
- * registers should set pdata->big_endian_mmio flag.
- *
- * This also applies to controller-to-cpu accessors for the USB descriptors,
- * since their endianness is also SoC dependant. Platform code for SoCs that
- * have BE USB descriptors should set pdata->big_endian_desc flag.
- */
-static u32 _fsl_readl_be(const unsigned __iomem *p)
-{
-	return in_be32(p);
-}
-
-static u32 _fsl_readl_le(const unsigned __iomem *p)
-{
-	return in_le32(p);
-}
-
-static void _fsl_writel_be(u32 v, unsigned __iomem *p)
-{
-	out_be32(p, v);
-}
-
-static void _fsl_writel_le(u32 v, unsigned __iomem *p)
-{
-	out_le32(p, v);
-}
-
-static u32 (*_fsl_readl)(const unsigned __iomem *p);
-static void (*_fsl_writel)(u32 v, unsigned __iomem *p);
-
-#define fsl_readl(p)		(*_fsl_readl)((p))
-#define fsl_writel(v, p)	(*_fsl_writel)((v), (p))
-
-static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata)
-{
-	if (pdata->big_endian_mmio) {
-		_fsl_readl = _fsl_readl_be;
-		_fsl_writel = _fsl_writel_be;
-	} else {
-		_fsl_readl = _fsl_readl_le;
-		_fsl_writel = _fsl_writel_le;
-	}
-}
-
-static inline u32 cpu_to_hc32(const u32 x)
-{
-	return udc_controller->pdata->big_endian_desc
-		? (__force u32)cpu_to_be32(x)
-		: (__force u32)cpu_to_le32(x);
-}
-
-static inline u32 hc32_to_cpu(const u32 x)
-{
-	return udc_controller->pdata->big_endian_desc
-		? be32_to_cpu((__force __be32)x)
-		: le32_to_cpu((__force __le32)x);
-}
-#else /* !CONFIG_PPC32 */
-static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata) {}
-
-#define fsl_readl(addr)		readl(addr)
-#define fsl_writel(val32, addr) writel(val32, addr)
-#define cpu_to_hc32(x)		cpu_to_le32(x)
-#define hc32_to_cpu(x)		le32_to_cpu(x)
-#endif /* CONFIG_PPC32 */
 
 /********************************************************************
  *	Internal Used Function
@@ -248,7 +158,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
 #define FSL_UDC_RESET_TIMEOUT 1000
 
 	/* Config PHY interface */
-	portctrl = fsl_readl(&dr_regs->portsc1);
+	portctrl = readl(&dr_regs->portsc1);
 	portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH);
 	switch (udc->phy_mode) {
 	case FSL_USB2_PHY_ULPI:
@@ -286,20 +196,20 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	default:
 		return -EINVAL;
 	}
-	fsl_writel(portctrl, &dr_regs->portsc1);
+	writel(portctrl, &dr_regs->portsc1);
 
 	/* Stop and reset the usb controller */
-	tmp = fsl_readl(&dr_regs->usbcmd);
+	tmp = readl(&dr_regs->usbcmd);
 	tmp &= ~USB_CMD_RUN_STOP;
-	fsl_writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &dr_regs->usbcmd);
 
-	tmp = fsl_readl(&dr_regs->usbcmd);
+	tmp = readl(&dr_regs->usbcmd);
 	tmp |= USB_CMD_CTRL_RESET;
-	fsl_writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &dr_regs->usbcmd);
 
 	/* Wait for reset to complete */
 	timeout = jiffies + FSL_UDC_RESET_TIMEOUT;
-	while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
+	while (readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
 		if (time_after(jiffies, timeout)) {
 			ERR("udc reset timeout!\n");
 			return -ETIMEDOUT;
@@ -308,33 +218,33 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	}
 
 	/* Set the controller as device mode */
-	tmp = fsl_readl(&dr_regs->usbmode);
+	tmp = readl(&dr_regs->usbmode);
 	tmp &= ~USB_MODE_CTRL_MODE_MASK;	/* clear mode bits */
 	tmp |= USB_MODE_CTRL_MODE_DEVICE;
 	/* Disable Setup Lockout */
 	tmp |= USB_MODE_SETUP_LOCK_OFF;
 	if (udc->pdata->es)
 		tmp |= USB_MODE_ES;
-	fsl_writel(tmp, &dr_regs->usbmode);
+	writel(tmp, &dr_regs->usbmode);
 
 	/* Clear the setup status */
-	fsl_writel(0, &dr_regs->usbsts);
+	writel(0, &dr_regs->usbsts);
 
 	tmp = udc->ep_qh_dma;
 	tmp &= USB_EP_LIST_ADDRESS_MASK;
-	fsl_writel(tmp, &dr_regs->endpointlistaddr);
+	writel(tmp, &dr_regs->endpointlistaddr);
 
 	VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x",
 		udc->ep_qh, (int)tmp,
-		fsl_readl(&dr_regs->endpointlistaddr));
+		readl(&dr_regs->endpointlistaddr));
 
-	max_no_of_ep = (0x0000001F & fsl_readl(&dr_regs->dccparams));
+	max_no_of_ep = (0x0000001F & readl(&dr_regs->dccparams));
 	for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) {
-		tmp = fsl_readl(&dr_regs->endptctrl[ep_num]);
+		tmp = readl(&dr_regs->endptctrl[ep_num]);
 		tmp &= ~(EPCTRL_TX_TYPE | EPCTRL_RX_TYPE);
 		tmp |= (EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT)
 		| (EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT);
-		fsl_writel(tmp, &dr_regs->endptctrl[ep_num]);
+		writel(tmp, &dr_regs->endptctrl[ep_num]);
 	}
 	/* Config control enable i/o output, cpu endian register */
 #ifndef CONFIG_ARCH_MXC
@@ -371,20 +281,20 @@ static void dr_controller_run(struct fsl_udc *udc)
 		| USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN
 		| USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN;
 
-	fsl_writel(temp, &dr_regs->usbintr);
+	writel(temp, &dr_regs->usbintr);
 
 	/* Clear stopped bit */
 	udc->stopped = 0;
 
 	/* Set the controller as device mode */
-	temp = fsl_readl(&dr_regs->usbmode);
+	temp = readl(&dr_regs->usbmode);
 	temp |= USB_MODE_CTRL_MODE_DEVICE;
-	fsl_writel(temp, &dr_regs->usbmode);
+	writel(temp, &dr_regs->usbmode);
 
 	/* Set controller to Run */
-	temp = fsl_readl(&dr_regs->usbcmd);
+	temp = readl(&dr_regs->usbcmd);
 	temp |= USB_CMD_RUN_STOP;
-	fsl_writel(temp, &dr_regs->usbcmd);
+	writel(temp, &dr_regs->usbcmd);
 }
 
 static void dr_controller_stop(struct fsl_udc *udc)
@@ -398,14 +308,14 @@ static void dr_controller_stop(struct fsl_udc *udc)
 	 * ehci driver
 	 */
 	if (udc->gadget.is_otg) {
-		if (!(fsl_readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
+		if (!(readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
 			pr_debug("udc: Leaving early\n");
 			return;
 		}
 	}
 
 	/* disable all INTR */
-	fsl_writel(0, &dr_regs->usbintr);
+	writel(0, &dr_regs->usbintr);
 
 	/* Set stopped bit for isr */
 	udc->stopped = 1;
@@ -414,9 +324,9 @@ static void dr_controller_stop(struct fsl_udc *udc)
 /*	usb_sys_regs->control = 0; */
 
 	/* set controller to Stop */
-	tmp = fsl_readl(&dr_regs->usbcmd);
+	tmp = readl(&dr_regs->usbcmd);
 	tmp &= ~USB_CMD_RUN_STOP;
-	fsl_writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &dr_regs->usbcmd);
 }
 
 static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
@@ -424,7 +334,7 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
 {
 	unsigned int tmp_epctrl = 0;
 
-	tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
+	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
 	if (dir) {
 		if (ep_num)
 			tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
@@ -441,7 +351,7 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
 				<< EPCTRL_RX_EP_TYPE_SHIFT);
 	}
 
-	fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
 }
 
 static void
@@ -449,7 +359,7 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
 {
 	u32 tmp_epctrl = 0;
 
-	tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
+	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
 
 	if (value) {
 		/* set the stall bit */
@@ -467,7 +377,7 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
 			tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
 		}
 	}
-	fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
 }
 
 /* Get stall status of a specific ep
@@ -476,7 +386,7 @@ static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir)
 {
 	u32 epctrl;
 
-	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&dr_regs->endptctrl[ep_num]);
 	if (dir)
 		return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0;
 	else
@@ -522,7 +432,7 @@ static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num,
 	if (zlt)
 		tmp |= EP_QUEUE_HEAD_ZLT_SEL;
 
-	p_QH->max_pkt_length = cpu_to_hc32(tmp);
+	p_QH->max_pkt_length = cpu_to_le32(tmp);
 	p_QH->next_dtd_ptr = 1;
 	p_QH->size_ioc_int_sts = 0;
 }
@@ -658,7 +568,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
 
 	/* disable ep on controller */
 	ep_num = ep_index(ep);
-	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep)) {
 		epctrl &= ~(EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE);
 		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT;
@@ -666,7 +576,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
 		epctrl &= ~(EPCTRL_RX_ENABLE | EPCTRL_TX_TYPE);
 		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT;
 	}
-	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &dr_regs->endptctrl[ep_num]);
 
 	udc = (struct fsl_udc *)ep->udc;
 	spin_lock_irqsave(&udc->lock, flags);
@@ -718,18 +628,18 @@ static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
 	struct ep_queue_head *qh = get_qh_by_ep(ep);
 
 	/* Write dQH next pointer and terminate bit to 0 */
-	qh->next_dtd_ptr = cpu_to_hc32(td->td_dma
+	qh->next_dtd_ptr = cpu_to_le32(td->td_dma
 			& EP_QUEUE_HEAD_NEXT_POINTER_MASK);
 
 	/* Clear active and halt bit */
-	qh->size_ioc_int_sts &= cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
+	qh->size_ioc_int_sts &= cpu_to_le32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
 					| EP_QUEUE_HEAD_STATUS_HALT));
 
 	/* Ensure that updates to the QH will occur before priming. */
 	wmb();
 
 	/* Prime endpoint by writing correct bit to ENDPTPRIME */
-	fsl_writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
+	writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
 			: (1 << (ep_index(ep))), &dr_regs->endpointprime);
 }
 
@@ -751,26 +661,26 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
 		struct fsl_req *lastreq;
 		lastreq = list_entry(ep->queue.prev, struct fsl_req, queue);
 		lastreq->tail->next_td_ptr =
-			cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
+			cpu_to_le32(req->head->td_dma & DTD_ADDR_MASK);
 		/* Ensure dTD's next dtd pointer to be updated */
 		wmb();
 		/* Read prime bit, if 1 goto done */
-		if (fsl_readl(&dr_regs->endpointprime) & bitmask)
+		if (readl(&dr_regs->endpointprime) & bitmask)
 			return;
 
 		do {
 			/* Set ATDTW bit in USBCMD */
-			temp = fsl_readl(&dr_regs->usbcmd);
-			fsl_writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
+			temp = readl(&dr_regs->usbcmd);
+			writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
 
 			/* Read correct status bit */
-			tmp_stat = fsl_readl(&dr_regs->endptstatus) & bitmask;
+			tmp_stat = readl(&dr_regs->endptstatus) & bitmask;
 
-		} while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
+		} while (!(readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
 
 		/* Write ATDTW bit to 0 */
-		temp = fsl_readl(&dr_regs->usbcmd);
-		fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
+		temp = readl(&dr_regs->usbcmd);
+		writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
 
 		if (tmp_stat)
 			return;
@@ -803,17 +713,17 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
 
 	dtd->td_dma = *dma;
 	/* Clear reserved field */
-	swap_temp = hc32_to_cpu(dtd->size_ioc_sts);
+	swap_temp = dtd->size_ioc_sts;
 	swap_temp &= ~DTD_RESERVED_FIELDS;
-	dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
+	dtd->size_ioc_sts = cpu_to_le32(swap_temp);
 
 	/* Init all of buffer page pointers */
 	swap_temp = (u32) (req->req.dma + req->req.actual);
-	dtd->buff_ptr0 = cpu_to_hc32(swap_temp);
-	dtd->buff_ptr1 = cpu_to_hc32(swap_temp + 0x1000);
-	dtd->buff_ptr2 = cpu_to_hc32(swap_temp + 0x2000);
-	dtd->buff_ptr3 = cpu_to_hc32(swap_temp + 0x3000);
-	dtd->buff_ptr4 = cpu_to_hc32(swap_temp + 0x4000);
+	dtd->buff_ptr0 = cpu_to_le32(swap_temp);
+	dtd->buff_ptr1 = cpu_to_le32(swap_temp + 0x1000);
+	dtd->buff_ptr2 = cpu_to_le32(swap_temp + 0x2000);
+	dtd->buff_ptr3 = cpu_to_le32(swap_temp + 0x3000);
+	dtd->buff_ptr4 = cpu_to_le32(swap_temp + 0x4000);
 
 	req->req.actual += *length;
 
@@ -837,7 +747,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
 	if (*is_last && !req->req.no_interrupt)
 		swap_temp |= DTD_IOC;
 
-	dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
+	dtd->size_ioc_sts = cpu_to_le32(swap_temp);
 
 	mb();
 
@@ -866,7 +776,7 @@ static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
 			is_first = 0;
 			req->head = dtd;
 		} else {
-			last_dtd->next_td_ptr = cpu_to_hc32(dma);
+			last_dtd->next_td_ptr = cpu_to_le32(dma);
 			last_dtd->next_td_virt = dtd;
 		}
 		last_dtd = dtd;
@@ -874,7 +784,7 @@ static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
 		req->dtd_count++;
 	} while (!is_last);
 
-	dtd->next_td_ptr = cpu_to_hc32(DTD_NEXT_TERMINATE);
+	dtd->next_td_ptr = cpu_to_le32(DTD_NEXT_TERMINATE);
 
 	req->tail = dtd;
 
@@ -966,12 +876,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	/* Stop the ep before we deal with the queue */
 	ep->stopped = 1;
 	ep_num = ep_index(ep);
-	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep))
 		epctrl &= ~EPCTRL_TX_ENABLE;
 	else
 		epctrl &= ~EPCTRL_RX_ENABLE;
-	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &dr_regs->endptctrl[ep_num]);
 
 	/* make sure it's actually queued on this endpoint */
 	list_for_each_entry(req, &ep->queue, queue) {
@@ -1009,12 +919,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	done(ep, req, -ECONNRESET);
 
 	/* Enable EP */
-out:	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
+out:	epctrl = readl(&dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep))
 		epctrl |= EPCTRL_TX_ENABLE;
 	else
 		epctrl |= EPCTRL_RX_ENABLE;
-	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &dr_regs->endptctrl[ep_num]);
 	ep->stopped = stopped;
 
 	spin_unlock_irqrestore(&ep->udc->lock, flags);
@@ -1096,7 +1006,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
 	bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
 	    (1 << (ep_index(ep)));
 
-	if (fsl_readl(&dr_regs->endptstatus) & bitmask)
+	if (readl(&dr_regs->endptstatus) & bitmask)
 		size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
 		    >> DTD_LENGTH_BIT_POS;
 
@@ -1131,10 +1041,10 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 
 	timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT;
 	do {
-		fsl_writel(bits, &dr_regs->endptflush);
+		writel(bits, &dr_regs->endptflush);
 
 		/* Wait until flush complete */
-		while (fsl_readl(&dr_regs->endptflush)) {
+		while (readl(&dr_regs->endptflush)) {
 			if (time_after(jiffies, timeout)) {
 				ERR("ep flush timeout\n");
 				return;
@@ -1142,7 +1052,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 			cpu_relax();
 		}
 		/* See if we need to flush again */
-	} while (fsl_readl(&dr_regs->endptstatus) & bits);
+	} while (readl(&dr_regs->endptstatus) & bits);
 }
 
 static struct usb_ep_ops fsl_ep_ops = {
@@ -1169,7 +1079,7 @@ static struct usb_ep_ops fsl_ep_ops = {
  *----------------------------------------------------------------------*/
 static int fsl_get_frame(struct usb_gadget *gadget)
 {
-	return (int)(fsl_readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
+	return (int)(readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
 }
 
 /*-----------------------------------------------------------------------
@@ -1184,13 +1094,13 @@ static int fsl_wakeup(struct usb_gadget *gadget)
 	if (!udc->remote_wakeup)
 		return -ENOTSUPP;
 
-	portsc = fsl_readl(&dr_regs->portsc1);
+	portsc = readl(&dr_regs->portsc1);
 	/* not suspended? */
 	if (!(portsc & PORTSCX_PORT_SUSPEND))
 		return 0;
 	/* trigger force resume */
 	portsc |= PORTSCX_PORT_FORCE_RESUME;
-	fsl_writel(portsc, &dr_regs->portsc1);
+	writel(portsc, &dr_regs->portsc1);
 	return 0;
 }
 
@@ -1211,10 +1121,10 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
 	VDBG("VBUS %s", is_active ? "on" : "off");
 	udc->vbus_active = (is_active != 0);
 	if (can_pullup(udc))
-		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
 				&dr_regs->usbcmd);
 	else
-		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
+		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
 				&dr_regs->usbcmd);
 	spin_unlock_irqrestore(&udc->lock, flags);
 	return 0;
@@ -1249,10 +1159,10 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
 	spin_lock_irqsave(&udc->lock, flags);
 	udc->softconnect = (is_on != 0);
 	if (can_pullup(udc))
-		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
 				&dr_regs->usbcmd);
 	else
-		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
+		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
 				&dr_regs->usbcmd);
 	spin_unlock_irqrestore(&udc->lock, flags);
 
@@ -1282,9 +1192,9 @@ static void ep0stall(struct fsl_udc *udc)
 	u32 tmp;
 
 	/* must set tx and rx to stall at the same time */
-	tmp = fsl_readl(&dr_regs->endptctrl[0]);
+	tmp = readl(&dr_regs->endptctrl[0]);
 	tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL;
-	fsl_writel(tmp, &dr_regs->endptctrl[0]);
+	writel(tmp, &dr_regs->endptctrl[0]);
 	udc->ep0_state = WAIT_FOR_SETUP;
 	udc->ep0_dir = 0;
 }
@@ -1494,8 +1404,8 @@ static void setup_received_irq(struct fsl_udc *udc,
 			u32 tmp;
 
 			mdelay(10);
-			tmp = fsl_readl(&dr_regs->portsc1) | (ptc << 16);
-			fsl_writel(tmp, &dr_regs->portsc1);
+			tmp = readl(&dr_regs->portsc1) | (ptc << 16);
+			writel(tmp, &dr_regs->portsc1);
 			printk(KERN_INFO "udc: switch to test mode %d.\n", ptc);
 		}
 
@@ -1546,7 +1456,7 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
 	if (udc->usb_state == USB_STATE_ADDRESS) {
 		/* Set the new address */
 		u32 new_address = (u32) udc->device_address;
-		fsl_writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
+		writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
 				&dr_regs->deviceaddr);
 	}
 
@@ -1585,14 +1495,14 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
 	qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
 
 	/* Clear bit in ENDPTSETUPSTAT */
-	temp = fsl_readl(&dr_regs->endptsetupstat);
-	fsl_writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
+	temp = readl(&dr_regs->endptsetupstat);
+	writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
 
 	/* while a hazard exists when setup package arrives */
 	do {
 		/* Set Setup Tripwire */
-		temp = fsl_readl(&dr_regs->usbcmd);
-		fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
+		temp = readl(&dr_regs->usbcmd);
+		writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
 
 		/* Copy the setup packet to local buffer */
 		if (pdata->le_setup_buf) {
@@ -1605,11 +1515,11 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
 		} else {
 			memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
 		}
-	} while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
+	} while (!(readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
 
 	/* Clear Setup Tripwire */
-	temp = fsl_readl(&dr_regs->usbcmd);
-	fsl_writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
+	temp = readl(&dr_regs->usbcmd);
+	writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
 }
 
 /* process-ep_req(): free the completed Tds for this req */
@@ -1628,19 +1538,18 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
 	actual = curr_req->req.length;
 
 	for (j = 0; j < curr_req->dtd_count; j++) {
-		remaining_length = (hc32_to_cpu(curr_td->size_ioc_sts)
-					& DTD_PACKET_SIZE)
+		remaining_length = (curr_td->size_ioc_sts & DTD_PACKET_SIZE)
 				>> DTD_LENGTH_BIT_POS;
 		actual -= remaining_length;
 
-		errors = hc32_to_cpu(curr_td->size_ioc_sts);
+		errors = curr_td->size_ioc_sts;
 		if (errors & DTD_ERROR_MASK) {
 			if (errors & DTD_STATUS_HALTED) {
 				ERR("dTD error %08x QH=%d\n", errors, pipe);
 				/* Clear the errors and Halt condition */
-				tmp = hc32_to_cpu(curr_qh->size_ioc_int_sts);
+				tmp = curr_qh->size_ioc_int_sts;
 				tmp &= ~errors;
-				curr_qh->size_ioc_int_sts = cpu_to_hc32(tmp);
+				curr_qh->size_ioc_int_sts = cpu_to_le32(tmp);
 				status = -EPIPE;
 				/* FIXME: continue with next queued TD? */
 
@@ -1658,8 +1567,7 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
 				ERR("Unknown error has occurred (0x%x)!\n",
 					errors);
 
-		} else if (hc32_to_cpu(curr_td->size_ioc_sts)
-				& DTD_STATUS_ACTIVE) {
+		} else if (curr_td->size_ioc_sts & DTD_STATUS_ACTIVE) {
 			VDBG("Request not complete");
 			status = REQ_UNCOMPLETE;
 			return status;
@@ -1698,8 +1606,8 @@ static void dtd_complete_irq(struct fsl_udc *udc)
 	struct fsl_req *curr_req, *temp_req;
 
 	/* Clear the bits in the register */
-	bit_pos = fsl_readl(&dr_regs->endptcomplete);
-	fsl_writel(bit_pos, &dr_regs->endptcomplete);
+	bit_pos = readl(&dr_regs->endptcomplete);
+	writel(bit_pos, &dr_regs->endptcomplete);
 
 	if (!bit_pos)
 		return;
@@ -1763,10 +1671,10 @@ static void port_change_irq(struct fsl_udc *udc)
 		udc->bus_reset = 0;
 
 	/* Bus resetting is finished */
-	if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
+	if (!(readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
 		/* Get the speed */
 		udc->gadget.speed =
-			portscx_device_speed(fsl_readl(&dr_regs->portsc1));
+			portscx_device_speed(readl(&dr_regs->portsc1));
 
 	/* Update USB state */
 	if (!udc->resume_state)
@@ -1817,8 +1725,8 @@ static void reset_irq(struct fsl_udc *udc)
 	unsigned long timeout;
 
 	/* Clear the device address */
-	temp = fsl_readl(&dr_regs->deviceaddr);
-	fsl_writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
+	temp = readl(&dr_regs->deviceaddr);
+	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
 
 	udc->device_address = 0;
 
@@ -1832,15 +1740,15 @@ static void reset_irq(struct fsl_udc *udc)
 	udc->gadget.a_alt_hnp_support = 0;
 
 	/* Clear all the setup token semaphores */
-	temp = fsl_readl(&dr_regs->endptsetupstat);
-	fsl_writel(temp, &dr_regs->endptsetupstat);
+	temp = readl(&dr_regs->endptsetupstat);
+	writel(temp, &dr_regs->endptsetupstat);
 
 	/* Clear all the endpoint complete status bits */
-	temp = fsl_readl(&dr_regs->endptcomplete);
-	fsl_writel(temp, &dr_regs->endptcomplete);
+	temp = readl(&dr_regs->endptcomplete);
+	writel(temp, &dr_regs->endptcomplete);
 
 	timeout = jiffies + 100;
-	while (fsl_readl(&dr_regs->endpointprime)) {
+	while (readl(&dr_regs->endpointprime)) {
 		/* Wait until all endptprime bits cleared */
 		if (time_after(jiffies, timeout)) {
 			ERR("Timeout for reset\n");
@@ -1850,9 +1758,9 @@ static void reset_irq(struct fsl_udc *udc)
 	}
 
 	/* Write 1s to the flush register */
-	fsl_writel(0xffffffff, &dr_regs->endptflush);
+	writel(0xffffffff, &dr_regs->endptflush);
 
-	if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
+	if (readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
 		VDBG("Bus reset");
 		/* Bus is reseting */
 		udc->bus_reset = 1;
@@ -1891,22 +1799,22 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
 	if (udc->stopped)
 		return IRQ_NONE;
 	spin_lock_irqsave(&udc->lock, flags);
-	irq_src = fsl_readl(&dr_regs->usbsts) & fsl_readl(&dr_regs->usbintr);
+	irq_src = readl(&dr_regs->usbsts) & readl(&dr_regs->usbintr);
 	/* Clear notification bits */
-	fsl_writel(irq_src, &dr_regs->usbsts);
+	writel(irq_src, &dr_regs->usbsts);
 
 	/* VDBG("irq_src [0x%8x]", irq_src); */
 
 	/* Need to resume? */
 	if (udc->usb_state == USB_STATE_SUSPENDED)
-		if ((fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
+		if ((readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
 			bus_resume(udc);
 
 	/* USB Interrupt */
 	if (irq_src & USB_STS_INT) {
 		VDBG("Packet int");
 		/* Setup package, we only support ep0 as control ep */
-		if (fsl_readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
+		if (readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
 			tripwire_handler(udc, 0,
 					(u8 *) (&udc->local_setup_buff));
 			setup_received_irq(udc, &udc->local_setup_buff);
@@ -1914,7 +1822,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
 		}
 
 		/* completion of dtd */
-		if (fsl_readl(&dr_regs->endptcomplete)) {
+		if (readl(&dr_regs->endptcomplete)) {
 			dtd_complete_irq(udc);
 			status = IRQ_HANDLED;
 		}
@@ -2076,7 +1984,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	next += t;
 
 	/* ------ DR Registers ----- */
-	tmp_reg = fsl_readl(&dr_regs->usbcmd);
+	tmp_reg = readl(&dr_regs->usbcmd);
 	t = scnprintf(next, size,
 			"USBCMD reg:\n"
 			"SetupTW: %d\n"
@@ -2086,7 +1994,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->usbsts);
+	tmp_reg = readl(&dr_regs->usbsts);
 	t = scnprintf(next, size,
 			"USB Status Reg:\n"
 			"Dr Suspend: %d Reset Received: %d System Error: %s "
@@ -2098,7 +2006,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->usbintr);
+	tmp_reg = readl(&dr_regs->usbintr);
 	t = scnprintf(next, size,
 			"USB Intrrupt Enable Reg:\n"
 			"Sleep Enable: %d SOF Received Enable: %d "
@@ -2116,21 +2024,21 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->frindex);
+	tmp_reg = readl(&dr_regs->frindex);
 	t = scnprintf(next, size,
 			"USB Frame Index Reg: Frame Number is 0x%x\n\n",
 			(tmp_reg & USB_FRINDEX_MASKS));
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->deviceaddr);
+	tmp_reg = readl(&dr_regs->deviceaddr);
 	t = scnprintf(next, size,
 			"USB Device Address Reg: Device Addr is 0x%x\n\n",
 			(tmp_reg & USB_DEVICE_ADDRESS_MASK));
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->endpointlistaddr);
+	tmp_reg = readl(&dr_regs->endpointlistaddr);
 	t = scnprintf(next, size,
 			"USB Endpoint List Address Reg: "
 			"Device Addr is 0x%x\n\n",
@@ -2138,7 +2046,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->portsc1);
+	tmp_reg = readl(&dr_regs->portsc1);
 	t = scnprintf(next, size,
 		"USB Port Status&Control Reg:\n"
 		"Port Transceiver Type : %s Port Speed: %s\n"
@@ -2177,7 +2085,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->usbmode);
+	tmp_reg = readl(&dr_regs->usbmode);
 	t = scnprintf(next, size,
 			"USB Mode Reg: Controller Mode is: %s\n\n", ( {
 				char *s;
@@ -2196,7 +2104,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = fsl_readl(&dr_regs->endptsetupstat);
+	tmp_reg = readl(&dr_regs->endptsetupstat);
 	t = scnprintf(next, size,
 			"Endpoint Setup Status Reg: SETUP on ep 0x%x\n\n",
 			(tmp_reg & EP_SETUP_STATUS_MASK));
@@ -2204,13 +2112,13 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	next += t;
 
 	for (i = 0; i < udc->max_ep / 2; i++) {
-		tmp_reg = fsl_readl(&dr_regs->endptctrl[i]);
+		tmp_reg = readl(&dr_regs->endptctrl[i]);
 		t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n",
 				i, tmp_reg);
 		size -= t;
 		next += t;
 	}
-	tmp_reg = fsl_readl(&dr_regs->endpointprime);
+	tmp_reg = readl(&dr_regs->endpointprime);
 	t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n\n", tmp_reg);
 	size -= t;
 	next += t;
@@ -2473,9 +2381,6 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		goto err_iounmap_noclk;
 	}
 
-	/* Set accessors only after pdata->init() ! */
-	fsl_set_accessors(pdata);
-
 #ifndef CONFIG_ARCH_MXC
 	if (pdata->have_sysif_regs)
 		usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
@@ -2487,7 +2392,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		goto err_iounmap_noclk;
 
 	/* Read Device Controller Capability Parameters register */
-	dccparams = fsl_readl(&dr_regs->dccparams);
+	dccparams = readl(&dr_regs->dccparams);
 	if (!(dccparams & DCCPARAMS_DC)) {
 		ERR("This SOC doesn't support device role\n");
 		ret = -ENODEV;
@@ -2682,7 +2587,7 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
 	u32 mode, usbcmd;
 
-	mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
+	mode = readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
 
 	pr_debug("%s(): mode 0x%x stopped %d\n", __func__, mode, udc->stopped);
 
@@ -2703,8 +2608,8 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 	}
 
 	/* stop the controller */
-	usbcmd = fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
-	fsl_writel(usbcmd, &dr_regs->usbcmd);
+	usbcmd = readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
+	writel(usbcmd, &dr_regs->usbcmd);
 
 	udc->stopped = 1;
 
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
                                                       ` (3 preceding siblings ...)
  2012-10-19 10:24                                     ` [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 10:30                                       ` Felipe Balbi
  2012-10-19 10:24                                     ` [PATCH 6/7] usb: gadget: fsl_udc: purge global pointer usb_sys_regs Christoph Fritz
                                                       ` (2 subsequent siblings)
  7 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

USB controller may access a wrong address for the dTD (endpoint transfer
descriptor) and then hang. This happens a lot when doing tests with
g_ether module and iperf, a tool for measuring maximum TCP and UDP
bandwidth.

This hardware bug is explained in detail by errata number 2858 for i.MX23:
http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf

All (?) SOCs with an IP from chipidea suffer from this problem.
mv_udc_core fixes this bug by commit daec765.  There still may be
unfixed drivers.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Signed-off-by: Christian Hemp <c.hemp@phytec.de>
Reviewed-by: Peter Chen <peter.chen@freescale.com>
---
 drivers/usb/gadget/fsl_udc_core.c |   12 +++++++++++-
 drivers/usb/gadget/fsl_usb2_udc.h |    2 ++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 53df9c0..deaab62 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -88,8 +88,13 @@ static void done(struct fsl_ep *ep, struct fsl_req *req, int status)
 		curr_td = next_td;
 		if (j != req->dtd_count - 1) {
 			next_td = curr_td->next_td_virt;
+			dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
+		} else {
+			if (udc->last_free_td != NULL)
+				dma_pool_free(udc->td_pool, udc->last_free_td,
+						udc->last_free_td->td_dma);
+			udc->last_free_td = curr_td;
 		}
-		dma_pool_free(udc->td_pool, curr_td, curr_td->td_dma);
 	}
 
 	if (req->mapped) {
@@ -2439,6 +2444,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 	udc->gadget.speed = USB_SPEED_UNKNOWN;
 	udc->gadget.name = driver_name;
 	udc->vbus_active = true;
+	udc->last_free_td = NULL;
 
 	/* Setup gadget.dev and register with kernel */
 	dev_set_name(&udc->gadget.dev, "gadget");
@@ -2533,6 +2539,10 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
 	kfree(udc->status_req);
 	kfree(udc->eps);
 
+	if (udc->last_free_td != NULL)
+		dma_pool_free(udc->td_pool, udc->last_free_td,
+			udc->last_free_td->td_dma);
+
 	dma_pool_destroy(udc->td_pool);
 	free_irq(udc->irq, udc);
 	iounmap(dr_regs);
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index f61a967..a0123ae 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -497,6 +497,8 @@ struct fsl_udc {
 	size_t ep_qh_size;		/* size after alignment adjustment*/
 	dma_addr_t ep_qh_dma;		/* dma address of QH */
 
+	struct ep_td_struct *last_free_td;
+
 	u32 max_pipes;          /* Device max pipes */
 	u32 bus_reset;		/* Device is bus resetting */
 	u32 resume_state;	/* USB state to resume */
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 6/7] usb: gadget: fsl_udc: purge global pointer usb_sys_regs
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
                                                       ` (4 preceding siblings ...)
  2012-10-19 10:24                                     ` [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 10:24                                     ` [PATCH 7/7] usb: gadget: fsl_udc: purge global pointer dr_regs Christoph Fritz
  2012-10-19 15:36                                     ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Sascha Hauer
  7 siblings, 0 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

Move global driver pointer usb_sys_regs to private struct fsl_udc.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
Reviewed-by: Teresa Gamez <T.Gamez@phytec.de>
---
 drivers/usb/gadget/fsl_udc_core.c |   26 ++++++++++++--------------
 drivers/usb/gadget/fsl_usb2_udc.h |    1 +
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index deaab62..35ebcd4 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -43,8 +43,6 @@ static const char driver_desc[] = DRIVER_DESC;
 
 static struct usb_dr_device *dr_regs;
 
-static struct usb_sys_interface *usb_sys_regs;
-
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -170,10 +168,10 @@ static int dr_controller_setup(struct fsl_udc *udc)
 		if (udc->pdata->have_sysif_regs) {
 			if (udc->pdata->controller_ver) {
 				/* controller version 1.6 or above */
-				ctrl = __raw_readl(&usb_sys_regs->control);
+				ctrl = readl(&udc->usb_sys_regs->control);
 				ctrl &= ~USB_CTRL_UTMI_PHY_EN;
 				ctrl |= USB_CTRL_USB_EN;
-				__raw_writel(ctrl, &usb_sys_regs->control);
+				writel(ctrl, &udc->usb_sys_regs->control);
 			}
 		}
 		portctrl |= PORTSCX_PTS_ULPI;
@@ -185,10 +183,10 @@ static int dr_controller_setup(struct fsl_udc *udc)
 		if (udc->pdata->have_sysif_regs) {
 			if (udc->pdata->controller_ver) {
 				/* controller version 1.6 or above */
-				ctrl = __raw_readl(&usb_sys_regs->control);
+				ctrl = readl(&udc->usb_sys_regs->control);
 				ctrl |= (USB_CTRL_UTMI_PHY_EN |
 					USB_CTRL_USB_EN);
-				__raw_writel(ctrl, &usb_sys_regs->control);
+				writel(ctrl, &udc->usb_sys_regs->control);
 				mdelay(FSL_UTMI_PHY_DLY); /* Delay for UTMI
 					PHY CLK to become stable - 10ms*/
 			}
@@ -254,9 +252,9 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	/* Config control enable i/o output, cpu endian register */
 #ifndef CONFIG_ARCH_MXC
 	if (udc->pdata->have_sysif_regs) {
-		ctrl = __raw_readl(&usb_sys_regs->control);
+		ctrl = readl(&udc->usb_sys_regs->control);
 		ctrl |= USB_CTRL_IOENB;
-		__raw_writel(ctrl, &usb_sys_regs->control);
+		writel(ctrl, &udc->usb_sys_regs->control);
 	}
 #endif
 
@@ -267,9 +265,9 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	if (udc->pdata->have_sysif_regs) {
 		/* Setup Snooping for all the 4GB space */
 		tmp = SNOOP_SIZE_2GB;	/* starts from 0x0, size 2G */
-		__raw_writel(tmp, &usb_sys_regs->snoop1);
+		writel(tmp, &udc->usb_sys_regs->snoop1);
 		tmp |= 0x80000000;	/* starts from 0x8000000, size 2G */
-		__raw_writel(tmp, &usb_sys_regs->snoop2);
+		writel(tmp, &udc->usb_sys_regs->snoop2);
 	}
 #endif
 
@@ -326,7 +324,7 @@ static void dr_controller_stop(struct fsl_udc *udc)
 	udc->stopped = 1;
 
 	/* disable IO output */
-/*	usb_sys_regs->control = 0; */
+/*	udc->usb_sys_regs->control = 0; */
 
 	/* set controller to Stop */
 	tmp = readl(&dr_regs->usbcmd);
@@ -2130,12 +2128,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 
 #ifndef CONFIG_ARCH_MXC
 	if (udc->pdata->have_sysif_regs) {
-		tmp_reg = usb_sys_regs->snoop1;
+		tmp_reg = udc->usb_sys_regs->snoop1;
 		t = scnprintf(next, size, "Snoop1 Reg : = [0x%x]\n\n", tmp_reg);
 		size -= t;
 		next += t;
 
-		tmp_reg = usb_sys_regs->control;
+		tmp_reg = udc->usb_sys_regs->control;
 		t = scnprintf(next, size, "General Control Reg : = [0x%x]\n\n",
 				tmp_reg);
 		size -= t;
@@ -2388,7 +2386,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 
 #ifndef CONFIG_ARCH_MXC
 	if (pdata->have_sysif_regs)
-		usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
+		udc->usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
 #endif
 
 	/* Initialize USB clocks */
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index a0123ae..0d888f4 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -498,6 +498,7 @@ struct fsl_udc {
 	dma_addr_t ep_qh_dma;		/* dma address of QH */
 
 	struct ep_td_struct *last_free_td;
+	struct usb_sys_interface *usb_sys_regs;
 
 	u32 max_pipes;          /* Device max pipes */
 	u32 bus_reset;		/* Device is bus resetting */
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 7/7] usb: gadget: fsl_udc: purge global pointer dr_regs
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
                                                       ` (5 preceding siblings ...)
  2012-10-19 10:24                                     ` [PATCH 6/7] usb: gadget: fsl_udc: purge global pointer usb_sys_regs Christoph Fritz
@ 2012-10-19 10:24                                     ` Christoph Fritz
  2012-10-19 15:36                                     ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Sascha Hauer
  7 siblings, 0 replies; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:24 UTC (permalink / raw)
  To: Felipe Balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

Move global driver pointer dr_regs to private struct fsl_udc.

Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
---
 drivers/usb/gadget/fsl_udc_core.c |  252 +++++++++++++++++++------------------
 drivers/usb/gadget/fsl_usb2_udc.h |    1 +
 2 files changed, 130 insertions(+), 123 deletions(-)

diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
index 35ebcd4..f9c4eb9 100644
--- a/drivers/usb/gadget/fsl_udc_core.c
+++ b/drivers/usb/gadget/fsl_udc_core.c
@@ -41,8 +41,6 @@
 static const char driver_name[] = DRIVER_NAME;
 static const char driver_desc[] = DRIVER_DESC;
 
-static struct usb_dr_device *dr_regs;
-
 static const struct usb_endpoint_descriptor
 fsl_ep0_desc = {
 	.bLength =		USB_DT_ENDPOINT_SIZE,
@@ -161,7 +159,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
 #define FSL_UDC_RESET_TIMEOUT 1000
 
 	/* Config PHY interface */
-	portctrl = readl(&dr_regs->portsc1);
+	portctrl = readl(&udc->dr_regs->portsc1);
 	portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH);
 	switch (udc->phy_mode) {
 	case FSL_USB2_PHY_ULPI:
@@ -199,20 +197,20 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	default:
 		return -EINVAL;
 	}
-	writel(portctrl, &dr_regs->portsc1);
+	writel(portctrl, &udc->dr_regs->portsc1);
 
 	/* Stop and reset the usb controller */
-	tmp = readl(&dr_regs->usbcmd);
+	tmp = readl(&udc->dr_regs->usbcmd);
 	tmp &= ~USB_CMD_RUN_STOP;
-	writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &udc->dr_regs->usbcmd);
 
-	tmp = readl(&dr_regs->usbcmd);
+	tmp = readl(&udc->dr_regs->usbcmd);
 	tmp |= USB_CMD_CTRL_RESET;
-	writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &udc->dr_regs->usbcmd);
 
 	/* Wait for reset to complete */
 	timeout = jiffies + FSL_UDC_RESET_TIMEOUT;
-	while (readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
+	while (readl(&udc->dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
 		if (time_after(jiffies, timeout)) {
 			ERR("udc reset timeout!\n");
 			return -ETIMEDOUT;
@@ -221,33 +219,33 @@ static int dr_controller_setup(struct fsl_udc *udc)
 	}
 
 	/* Set the controller as device mode */
-	tmp = readl(&dr_regs->usbmode);
+	tmp = readl(&udc->dr_regs->usbmode);
 	tmp &= ~USB_MODE_CTRL_MODE_MASK;	/* clear mode bits */
 	tmp |= USB_MODE_CTRL_MODE_DEVICE;
 	/* Disable Setup Lockout */
 	tmp |= USB_MODE_SETUP_LOCK_OFF;
 	if (udc->pdata->es)
 		tmp |= USB_MODE_ES;
-	writel(tmp, &dr_regs->usbmode);
+	writel(tmp, &udc->dr_regs->usbmode);
 
 	/* Clear the setup status */
-	writel(0, &dr_regs->usbsts);
+	writel(0, &udc->dr_regs->usbsts);
 
 	tmp = udc->ep_qh_dma;
 	tmp &= USB_EP_LIST_ADDRESS_MASK;
-	writel(tmp, &dr_regs->endpointlistaddr);
+	writel(tmp, &udc->dr_regs->endpointlistaddr);
 
 	VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x",
 		udc->ep_qh, (int)tmp,
-		readl(&dr_regs->endpointlistaddr));
+		readl(&udc->dr_regs->endpointlistaddr));
 
-	max_no_of_ep = (0x0000001F & readl(&dr_regs->dccparams));
+	max_no_of_ep = (0x0000001F & readl(&udc->dr_regs->dccparams));
 	for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) {
-		tmp = readl(&dr_regs->endptctrl[ep_num]);
+		tmp = readl(&udc->dr_regs->endptctrl[ep_num]);
 		tmp &= ~(EPCTRL_TX_TYPE | EPCTRL_RX_TYPE);
 		tmp |= (EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT)
 		| (EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT);
-		writel(tmp, &dr_regs->endptctrl[ep_num]);
+		writel(tmp, &udc->dr_regs->endptctrl[ep_num]);
 	}
 	/* Config control enable i/o output, cpu endian register */
 #ifndef CONFIG_ARCH_MXC
@@ -284,20 +282,20 @@ static void dr_controller_run(struct fsl_udc *udc)
 		| USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN
 		| USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN;
 
-	writel(temp, &dr_regs->usbintr);
+	writel(temp, &udc->dr_regs->usbintr);
 
 	/* Clear stopped bit */
 	udc->stopped = 0;
 
 	/* Set the controller as device mode */
-	temp = readl(&dr_regs->usbmode);
+	temp = readl(&udc->dr_regs->usbmode);
 	temp |= USB_MODE_CTRL_MODE_DEVICE;
-	writel(temp, &dr_regs->usbmode);
+	writel(temp, &udc->dr_regs->usbmode);
 
 	/* Set controller to Run */
-	temp = readl(&dr_regs->usbcmd);
+	temp = readl(&udc->dr_regs->usbcmd);
 	temp |= USB_CMD_RUN_STOP;
-	writel(temp, &dr_regs->usbcmd);
+	writel(temp, &udc->dr_regs->usbcmd);
 }
 
 static void dr_controller_stop(struct fsl_udc *udc)
@@ -311,14 +309,14 @@ static void dr_controller_stop(struct fsl_udc *udc)
 	 * ehci driver
 	 */
 	if (udc->gadget.is_otg) {
-		if (!(readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
+		if (!(readl(&udc->dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
 			pr_debug("udc: Leaving early\n");
 			return;
 		}
 	}
 
 	/* disable all INTR */
-	writel(0, &dr_regs->usbintr);
+	writel(0, &udc->dr_regs->usbintr);
 
 	/* Set stopped bit for isr */
 	udc->stopped = 1;
@@ -327,17 +325,17 @@ static void dr_controller_stop(struct fsl_udc *udc)
 /*	udc->usb_sys_regs->control = 0; */
 
 	/* set controller to Stop */
-	tmp = readl(&dr_regs->usbcmd);
+	tmp = readl(&udc->dr_regs->usbcmd);
 	tmp &= ~USB_CMD_RUN_STOP;
-	writel(tmp, &dr_regs->usbcmd);
+	writel(tmp, &udc->dr_regs->usbcmd);
 }
 
-static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
-			unsigned char ep_type)
+static void dr_ep_setup(struct fsl_udc *udc, unsigned char ep_num,
+		unsigned char dir, unsigned char ep_type)
 {
 	unsigned int tmp_epctrl = 0;
 
-	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	tmp_epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (dir) {
 		if (ep_num)
 			tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
@@ -354,15 +352,15 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
 				<< EPCTRL_RX_EP_TYPE_SHIFT);
 	}
 
-	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(tmp_epctrl, &udc->dr_regs->endptctrl[ep_num]);
 }
 
-static void
-dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
+static void dr_ep_change_stall(struct fsl_udc *udc, unsigned char ep_num,
+		unsigned char dir, int value)
 {
 	u32 tmp_epctrl = 0;
 
-	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	tmp_epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 
 	if (value) {
 		/* set the stall bit */
@@ -380,16 +378,17 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
 			tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
 		}
 	}
-	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(tmp_epctrl, &udc->dr_regs->endptctrl[ep_num]);
 }
 
 /* Get stall status of a specific ep
    Return: 0: not stalled; 1:stalled */
-static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir)
+static int dr_ep_get_stall(struct fsl_udc *udc, unsigned char ep_num,
+		unsigned char dir)
 {
 	u32 epctrl;
 
-	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (dir)
 		return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0;
 	else
@@ -449,8 +448,8 @@ static void ep0_setup(struct fsl_udc *udc)
 			USB_MAX_CTRL_PAYLOAD, 0, 0);
 	struct_ep_qh_setup(udc, 0, USB_SEND, USB_ENDPOINT_XFER_CONTROL,
 			USB_MAX_CTRL_PAYLOAD, 0, 0);
-	dr_ep_setup(0, USB_RECV, USB_ENDPOINT_XFER_CONTROL);
-	dr_ep_setup(0, USB_SEND, USB_ENDPOINT_XFER_CONTROL);
+	dr_ep_setup(udc, 0, USB_RECV, USB_ENDPOINT_XFER_CONTROL);
+	dr_ep_setup(udc, 0, USB_SEND, USB_ENDPOINT_XFER_CONTROL);
 
 	return;
 
@@ -534,7 +533,7 @@ static int fsl_ep_enable(struct usb_ep *_ep,
 			max, zlt, mult);
 
 	/* Init endpoint ctrl register */
-	dr_ep_setup((unsigned char) ep_index(ep),
+	dr_ep_setup(udc, (unsigned char) ep_index(ep),
 			(unsigned char) ((desc->bEndpointAddress & USB_DIR_IN)
 					? USB_SEND : USB_RECV),
 			(unsigned char) (desc->bmAttributes
@@ -571,7 +570,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
 
 	/* disable ep on controller */
 	ep_num = ep_index(ep);
-	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep)) {
 		epctrl &= ~(EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE);
 		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT;
@@ -579,7 +578,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
 		epctrl &= ~(EPCTRL_RX_ENABLE | EPCTRL_TX_TYPE);
 		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT;
 	}
-	writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &udc->dr_regs->endptctrl[ep_num]);
 
 	udc = (struct fsl_udc *)ep->udc;
 	spin_lock_irqsave(&udc->lock, flags);
@@ -629,6 +628,7 @@ static void fsl_free_request(struct usb_ep *_ep, struct usb_request *_req)
 static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
 {
 	struct ep_queue_head *qh = get_qh_by_ep(ep);
+	struct fsl_udc *udc = ep->udc;
 
 	/* Write dQH next pointer and terminate bit to 0 */
 	qh->next_dtd_ptr = cpu_to_le32(td->td_dma
@@ -643,13 +643,14 @@ static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
 
 	/* Prime endpoint by writing correct bit to ENDPTPRIME */
 	writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
-			: (1 << (ep_index(ep))), &dr_regs->endpointprime);
+			: (1 << (ep_index(ep))), &udc->dr_regs->endpointprime);
 }
 
 /* Add dTD chain to the dQH of an EP */
 static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
 {
 	u32 temp, bitmask, tmp_stat;
+	struct fsl_udc *udc = ep->udc;
 
 	/* VDBG("QH addr Register 0x%8x", dr_regs->endpointlistaddr);
 	VDBG("ep_qh[%d] addr is 0x%8x", i, (u32)&(ep->udc->ep_qh[i])); */
@@ -668,22 +669,22 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
 		/* Ensure dTD's next dtd pointer to be updated */
 		wmb();
 		/* Read prime bit, if 1 goto done */
-		if (readl(&dr_regs->endpointprime) & bitmask)
+		if (readl(&udc->dr_regs->endpointprime) & bitmask)
 			return;
 
 		do {
 			/* Set ATDTW bit in USBCMD */
-			temp = readl(&dr_regs->usbcmd);
-			writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
+			temp = readl(&udc->dr_regs->usbcmd);
+			writel(temp | USB_CMD_ATDTW, &udc->dr_regs->usbcmd);
 
 			/* Read correct status bit */
-			tmp_stat = readl(&dr_regs->endptstatus) & bitmask;
+			tmp_stat = readl(&udc->dr_regs->endptstatus) & bitmask;
 
-		} while (!(readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
+		} while (!(readl(&udc->dr_regs->usbcmd) & USB_CMD_ATDTW));
 
 		/* Write ATDTW bit to 0 */
-		temp = readl(&dr_regs->usbcmd);
-		writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
+		temp = readl(&udc->dr_regs->usbcmd);
+		writel(temp & ~USB_CMD_ATDTW, &udc->dr_regs->usbcmd);
 
 		if (tmp_stat)
 			return;
@@ -866,6 +867,7 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 {
 	struct fsl_ep *ep = container_of(_ep, struct fsl_ep, ep);
 	struct fsl_req *req;
+	struct fsl_udc *udc = ep->udc;
 	unsigned long flags;
 	int ep_num, stopped, ret = 0;
 	u32 epctrl;
@@ -873,18 +875,18 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	if (!_ep || !_req)
 		return -EINVAL;
 
-	spin_lock_irqsave(&ep->udc->lock, flags);
+	spin_lock_irqsave(&udc->lock, flags);
 	stopped = ep->stopped;
 
 	/* Stop the ep before we deal with the queue */
 	ep->stopped = 1;
 	ep_num = ep_index(ep);
-	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep))
 		epctrl &= ~EPCTRL_TX_ENABLE;
 	else
 		epctrl &= ~EPCTRL_RX_ENABLE;
-	writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &udc->dr_regs->endptctrl[ep_num]);
 
 	/* make sure it's actually queued on this endpoint */
 	list_for_each_entry(req, &ep->queue, queue) {
@@ -922,12 +924,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 	done(ep, req, -ECONNRESET);
 
 	/* Enable EP */
-out:	epctrl = readl(&dr_regs->endptctrl[ep_num]);
+out:	epctrl = readl(&udc->dr_regs->endptctrl[ep_num]);
 	if (ep_is_in(ep))
 		epctrl |= EPCTRL_TX_ENABLE;
 	else
 		epctrl |= EPCTRL_RX_ENABLE;
-	writel(epctrl, &dr_regs->endptctrl[ep_num]);
+	writel(epctrl, &udc->dr_regs->endptctrl[ep_num]);
 	ep->stopped = stopped;
 
 	spin_unlock_irqrestore(&ep->udc->lock, flags);
@@ -973,7 +975,7 @@ static int fsl_ep_set_halt(struct usb_ep *_ep, int value)
 	ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV;
 	ep_num = (unsigned char)(ep_index(ep));
 	spin_lock_irqsave(&ep->udc->lock, flags);
-	dr_ep_change_stall(ep_num, ep_dir, value);
+	dr_ep_change_stall(udc, ep_num, ep_dir, value);
 	spin_unlock_irqrestore(&ep->udc->lock, flags);
 
 	if (ep_index(ep) == 0) {
@@ -1009,7 +1011,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
 	bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
 	    (1 << (ep_index(ep)));
 
-	if (readl(&dr_regs->endptstatus) & bitmask)
+	if (readl(&udc->dr_regs->endptstatus) & bitmask)
 		size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
 		    >> DTD_LENGTH_BIT_POS;
 
@@ -1019,6 +1021,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
 
 static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 {
+	struct fsl_udc *udc;
 	struct fsl_ep *ep;
 	int ep_num, ep_dir;
 	u32 bits;
@@ -1031,6 +1034,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 		ep = container_of(_ep, struct fsl_ep, ep);
 		if (!ep->ep.desc)
 			return;
+		udc = ep->udc;
 	}
 	ep_num = ep_index(ep);
 	ep_dir = ep_is_in(ep) ? USB_SEND : USB_RECV;
@@ -1044,10 +1048,10 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 
 	timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT;
 	do {
-		writel(bits, &dr_regs->endptflush);
+		writel(bits, &udc->dr_regs->endptflush);
 
 		/* Wait until flush complete */
-		while (readl(&dr_regs->endptflush)) {
+		while (readl(&udc->dr_regs->endptflush)) {
 			if (time_after(jiffies, timeout)) {
 				ERR("ep flush timeout\n");
 				return;
@@ -1055,7 +1059,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
 			cpu_relax();
 		}
 		/* See if we need to flush again */
-	} while (readl(&dr_regs->endptstatus) & bits);
+	} while (readl(&udc->dr_regs->endptstatus) & bits);
 }
 
 static struct usb_ep_ops fsl_ep_ops = {
@@ -1082,7 +1086,8 @@ static struct usb_ep_ops fsl_ep_ops = {
  *----------------------------------------------------------------------*/
 static int fsl_get_frame(struct usb_gadget *gadget)
 {
-	return (int)(readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
+	struct fsl_udc *udc = container_of(gadget, struct fsl_udc, gadget);
+	return (int)(readl(&udc->dr_regs->frindex) & USB_FRINDEX_MASKS);
 }
 
 /*-----------------------------------------------------------------------
@@ -1097,13 +1102,13 @@ static int fsl_wakeup(struct usb_gadget *gadget)
 	if (!udc->remote_wakeup)
 		return -ENOTSUPP;
 
-	portsc = readl(&dr_regs->portsc1);
+	portsc = readl(&udc->dr_regs->portsc1);
 	/* not suspended? */
 	if (!(portsc & PORTSCX_PORT_SUSPEND))
 		return 0;
 	/* trigger force resume */
 	portsc |= PORTSCX_PORT_FORCE_RESUME;
-	writel(portsc, &dr_regs->portsc1);
+	writel(portsc, &udc->dr_regs->portsc1);
 	return 0;
 }
 
@@ -1124,11 +1129,11 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
 	VDBG("VBUS %s", is_active ? "on" : "off");
 	udc->vbus_active = (is_active != 0);
 	if (can_pullup(udc))
-		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	else
-		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	spin_unlock_irqrestore(&udc->lock, flags);
 	return 0;
 }
@@ -1162,11 +1167,11 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
 	spin_lock_irqsave(&udc->lock, flags);
 	udc->softconnect = (is_on != 0);
 	if (can_pullup(udc))
-		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) | USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	else
-		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
-				&dr_regs->usbcmd);
+		writel((readl(&udc->dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
+				&udc->dr_regs->usbcmd);
 	spin_unlock_irqrestore(&udc->lock, flags);
 
 	return 0;
@@ -1195,9 +1200,9 @@ static void ep0stall(struct fsl_udc *udc)
 	u32 tmp;
 
 	/* must set tx and rx to stall at the same time */
-	tmp = readl(&dr_regs->endptctrl[0]);
+	tmp = readl(&udc->dr_regs->endptctrl[0]);
 	tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL;
-	writel(tmp, &dr_regs->endptctrl[0]);
+	writel(tmp, &udc->dr_regs->endptctrl[0]);
 	udc->ep0_state = WAIT_FOR_SETUP;
 	udc->ep0_dir = 0;
 }
@@ -1290,8 +1295,8 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
 		/* stall if endpoint doesn't exist */
 		if (!target_ep->ep.desc)
 			goto stall;
-		tmp = dr_ep_get_stall(ep_index(target_ep), ep_is_in(target_ep))
-				<< USB_ENDPOINT_HALT;
+		tmp = dr_ep_get_stall(udc, ep_index(target_ep),
+				ep_is_in(target_ep)) << USB_ENDPOINT_HALT;
 	}
 
 	udc->ep0_dir = USB_DIR_IN;
@@ -1407,8 +1412,8 @@ static void setup_received_irq(struct fsl_udc *udc,
 			u32 tmp;
 
 			mdelay(10);
-			tmp = readl(&dr_regs->portsc1) | (ptc << 16);
-			writel(tmp, &dr_regs->portsc1);
+			tmp = readl(&udc->dr_regs->portsc1) | (ptc << 16);
+			writel(tmp, &udc->dr_regs->portsc1);
 			printk(KERN_INFO "udc: switch to test mode %d.\n", ptc);
 		}
 
@@ -1460,7 +1465,7 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
 		/* Set the new address */
 		u32 new_address = (u32) udc->device_address;
 		writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
-				&dr_regs->deviceaddr);
+				&udc->dr_regs->deviceaddr);
 	}
 
 	done(ep0, req, 0);
@@ -1498,14 +1503,14 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
 	qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
 
 	/* Clear bit in ENDPTSETUPSTAT */
-	temp = readl(&dr_regs->endptsetupstat);
-	writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
+	temp = readl(&udc->dr_regs->endptsetupstat);
+	writel(temp | (1 << ep_num), &udc->dr_regs->endptsetupstat);
 
 	/* while a hazard exists when setup package arrives */
 	do {
 		/* Set Setup Tripwire */
-		temp = readl(&dr_regs->usbcmd);
-		writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
+		temp = readl(&udc->dr_regs->usbcmd);
+		writel(temp | USB_CMD_SUTW, &udc->dr_regs->usbcmd);
 
 		/* Copy the setup packet to local buffer */
 		if (pdata->le_setup_buf) {
@@ -1518,11 +1523,11 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
 		} else {
 			memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
 		}
-	} while (!(readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
+	} while (!(readl(&udc->dr_regs->usbcmd) & USB_CMD_SUTW));
 
 	/* Clear Setup Tripwire */
-	temp = readl(&dr_regs->usbcmd);
-	writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
+	temp = readl(&udc->dr_regs->usbcmd);
+	writel(temp & ~USB_CMD_SUTW, &udc->dr_regs->usbcmd);
 }
 
 /* process-ep_req(): free the completed Tds for this req */
@@ -1609,8 +1614,8 @@ static void dtd_complete_irq(struct fsl_udc *udc)
 	struct fsl_req *curr_req, *temp_req;
 
 	/* Clear the bits in the register */
-	bit_pos = readl(&dr_regs->endptcomplete);
-	writel(bit_pos, &dr_regs->endptcomplete);
+	bit_pos = readl(&udc->dr_regs->endptcomplete);
+	writel(bit_pos, &udc->dr_regs->endptcomplete);
 
 	if (!bit_pos)
 		return;
@@ -1674,10 +1679,10 @@ static void port_change_irq(struct fsl_udc *udc)
 		udc->bus_reset = 0;
 
 	/* Bus resetting is finished */
-	if (!(readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
+	if (!(readl(&udc->dr_regs->portsc1) & PORTSCX_PORT_RESET))
 		/* Get the speed */
 		udc->gadget.speed =
-			portscx_device_speed(readl(&dr_regs->portsc1));
+			portscx_device_speed(readl(&udc->dr_regs->portsc1));
 
 	/* Update USB state */
 	if (!udc->resume_state)
@@ -1728,8 +1733,8 @@ static void reset_irq(struct fsl_udc *udc)
 	unsigned long timeout;
 
 	/* Clear the device address */
-	temp = readl(&dr_regs->deviceaddr);
-	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
+	temp = readl(&udc->dr_regs->deviceaddr);
+	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &udc->dr_regs->deviceaddr);
 
 	udc->device_address = 0;
 
@@ -1743,15 +1748,15 @@ static void reset_irq(struct fsl_udc *udc)
 	udc->gadget.a_alt_hnp_support = 0;
 
 	/* Clear all the setup token semaphores */
-	temp = readl(&dr_regs->endptsetupstat);
-	writel(temp, &dr_regs->endptsetupstat);
+	temp = readl(&udc->dr_regs->endptsetupstat);
+	writel(temp, &udc->dr_regs->endptsetupstat);
 
 	/* Clear all the endpoint complete status bits */
-	temp = readl(&dr_regs->endptcomplete);
-	writel(temp, &dr_regs->endptcomplete);
+	temp = readl(&udc->dr_regs->endptcomplete);
+	writel(temp, &udc->dr_regs->endptcomplete);
 
 	timeout = jiffies + 100;
-	while (readl(&dr_regs->endpointprime)) {
+	while (readl(&udc->dr_regs->endpointprime)) {
 		/* Wait until all endptprime bits cleared */
 		if (time_after(jiffies, timeout)) {
 			ERR("Timeout for reset\n");
@@ -1761,9 +1766,9 @@ static void reset_irq(struct fsl_udc *udc)
 	}
 
 	/* Write 1s to the flush register */
-	writel(0xffffffff, &dr_regs->endptflush);
+	writel(0xffffffff, &udc->dr_regs->endptflush);
 
-	if (readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
+	if (readl(&udc->dr_regs->portsc1) & PORTSCX_PORT_RESET) {
 		VDBG("Bus reset");
 		/* Bus is reseting */
 		udc->bus_reset = 1;
@@ -1802,22 +1807,23 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
 	if (udc->stopped)
 		return IRQ_NONE;
 	spin_lock_irqsave(&udc->lock, flags);
-	irq_src = readl(&dr_regs->usbsts) & readl(&dr_regs->usbintr);
+	irq_src = readl(&udc->dr_regs->usbsts) & readl(&udc->dr_regs->usbintr);
 	/* Clear notification bits */
-	writel(irq_src, &dr_regs->usbsts);
+	writel(irq_src, &udc->dr_regs->usbsts);
 
 	/* VDBG("irq_src [0x%8x]", irq_src); */
 
 	/* Need to resume? */
 	if (udc->usb_state == USB_STATE_SUSPENDED)
-		if ((readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
+		if ((readl(&udc->dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
 			bus_resume(udc);
 
 	/* USB Interrupt */
 	if (irq_src & USB_STS_INT) {
 		VDBG("Packet int");
 		/* Setup package, we only support ep0 as control ep */
-		if (readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
+		if (readl(&udc->dr_regs->endptsetupstat) &
+				EP_SETUP_STATUS_EP0) {
 			tripwire_handler(udc, 0,
 					(u8 *) (&udc->local_setup_buff));
 			setup_received_irq(udc, &udc->local_setup_buff);
@@ -1825,7 +1831,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
 		}
 
 		/* completion of dtd */
-		if (readl(&dr_regs->endptcomplete)) {
+		if (readl(&udc->dr_regs->endptcomplete)) {
 			dtd_complete_irq(udc);
 			status = IRQ_HANDLED;
 		}
@@ -1987,7 +1993,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	next += t;
 
 	/* ------ DR Registers ----- */
-	tmp_reg = readl(&dr_regs->usbcmd);
+	tmp_reg = readl(&udc->dr_regs->usbcmd);
 	t = scnprintf(next, size,
 			"USBCMD reg:\n"
 			"SetupTW: %d\n"
@@ -1997,7 +2003,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->usbsts);
+	tmp_reg = readl(&udc->dr_regs->usbsts);
 	t = scnprintf(next, size,
 			"USB Status Reg:\n"
 			"Dr Suspend: %d Reset Received: %d System Error: %s "
@@ -2009,7 +2015,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->usbintr);
+	tmp_reg = readl(&udc->dr_regs->usbintr);
 	t = scnprintf(next, size,
 			"USB Intrrupt Enable Reg:\n"
 			"Sleep Enable: %d SOF Received Enable: %d "
@@ -2027,21 +2033,21 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->frindex);
+	tmp_reg = readl(&udc->dr_regs->frindex);
 	t = scnprintf(next, size,
 			"USB Frame Index Reg: Frame Number is 0x%x\n\n",
 			(tmp_reg & USB_FRINDEX_MASKS));
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->deviceaddr);
+	tmp_reg = readl(&udc->dr_regs->deviceaddr);
 	t = scnprintf(next, size,
 			"USB Device Address Reg: Device Addr is 0x%x\n\n",
 			(tmp_reg & USB_DEVICE_ADDRESS_MASK));
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->endpointlistaddr);
+	tmp_reg = readl(&udc->dr_regs->endpointlistaddr);
 	t = scnprintf(next, size,
 			"USB Endpoint List Address Reg: "
 			"Device Addr is 0x%x\n\n",
@@ -2049,7 +2055,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->portsc1);
+	tmp_reg = readl(&udc->dr_regs->portsc1);
 	t = scnprintf(next, size,
 		"USB Port Status&Control Reg:\n"
 		"Port Transceiver Type : %s Port Speed: %s\n"
@@ -2088,7 +2094,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->usbmode);
+	tmp_reg = readl(&udc->dr_regs->usbmode);
 	t = scnprintf(next, size,
 			"USB Mode Reg: Controller Mode is: %s\n\n", ( {
 				char *s;
@@ -2107,7 +2113,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	size -= t;
 	next += t;
 
-	tmp_reg = readl(&dr_regs->endptsetupstat);
+	tmp_reg = readl(&udc->dr_regs->endptsetupstat);
 	t = scnprintf(next, size,
 			"Endpoint Setup Status Reg: SETUP on ep 0x%x\n\n",
 			(tmp_reg & EP_SETUP_STATUS_MASK));
@@ -2115,13 +2121,13 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
 	next += t;
 
 	for (i = 0; i < udc->max_ep / 2; i++) {
-		tmp_reg = readl(&dr_regs->endptctrl[i]);
+		tmp_reg = readl(&udc->dr_regs->endptctrl[i]);
 		t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n",
 				i, tmp_reg);
 		size -= t;
 		next += t;
 	}
-	tmp_reg = readl(&dr_regs->endpointprime);
+	tmp_reg = readl(&udc->dr_regs->endpointprime);
 	t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n\n", tmp_reg);
 	size -= t;
 	next += t;
@@ -2368,13 +2374,13 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		}
 	}
 
-	dr_regs = ioremap(res->start, resource_size(res));
-	if (!dr_regs) {
+	udc->dr_regs = ioremap(res->start, resource_size(res));
+	if (!udc->dr_regs) {
 		ret = -ENOMEM;
 		goto err_release_mem_region;
 	}
 
-	pdata->regs = (void *)dr_regs;
+	pdata->regs = (void *)udc->dr_regs;
 
 	/*
 	 * do platform specific init: check the clock, grab/config pins, etc.
@@ -2386,7 +2392,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 
 #ifndef CONFIG_ARCH_MXC
 	if (pdata->have_sysif_regs)
-		udc->usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
+		udc->usb_sys_regs = (void *)udc->dr_regs + USB_DR_SYS_OFFSET;
 #endif
 
 	/* Initialize USB clocks */
@@ -2395,7 +2401,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
 		goto err_iounmap_noclk;
 
 	/* Read Device Controller Capability Parameters register */
-	dccparams = readl(&dr_regs->dccparams);
+	dccparams = readl(&udc->dr_regs->dccparams);
 	if (!(dccparams & DCCPARAMS_DC)) {
 		ERR("This SOC doesn't support device role\n");
 		ret = -ENODEV;
@@ -2505,7 +2511,7 @@ err_iounmap:
 		pdata->exit(pdev);
 	fsl_udc_clk_release();
 err_iounmap_noclk:
-	iounmap(dr_regs);
+	iounmap(udc->dr_regs);
 err_release_mem_region:
 	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
 		release_mem_region(res->start, resource_size(res));
@@ -2543,7 +2549,7 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
 
 	dma_pool_destroy(udc->td_pool);
 	free_irq(udc->irq, udc);
-	iounmap(dr_regs);
+	iounmap(udc->dr_regs);
 	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
 		release_mem_region(res->start, resource_size(res));
 
@@ -2595,7 +2601,7 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
 	u32 mode, usbcmd;
 
-	mode = readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
+	mode = readl(&udc->dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
 
 	pr_debug("%s(): mode 0x%x stopped %d\n", __func__, mode, udc->stopped);
 
@@ -2616,8 +2622,8 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
 	}
 
 	/* stop the controller */
-	usbcmd = readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
-	writel(usbcmd, &dr_regs->usbcmd);
+	usbcmd = readl(&udc->dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
+	writel(usbcmd, &udc->dr_regs->usbcmd);
 
 	udc->stopped = 1;
 
diff --git a/drivers/usb/gadget/fsl_usb2_udc.h b/drivers/usb/gadget/fsl_usb2_udc.h
index 0d888f4..3b2a5ff 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.h
+++ b/drivers/usb/gadget/fsl_usb2_udc.h
@@ -499,6 +499,7 @@ struct fsl_udc {
 
 	struct ep_td_struct *last_free_td;
 	struct usb_sys_interface *usb_sys_regs;
+	struct usb_dr_device *dr_regs;
 
 	u32 max_pipes;          /* Device max pipes */
 	u32 bus_reset;		/* Device is bus resetting */
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
  2012-10-19 10:24                                     ` [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock Christoph Fritz
@ 2012-10-19 10:25                                       ` Felipe Balbi
  0 siblings, 0 replies; 42+ messages in thread
From: Felipe Balbi @ 2012-10-19 10:25 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 2057 bytes --]

Hi,

On Fri, Oct 19, 2012 at 12:24:40PM +0200, Christoph Fritz wrote:
> This patch reworks fsl_pullup() against the background of switching over
> to udc_start()/udc_stop() style:
> 
> Protect function fsl_pullup() with a spin_lock. Also set vbus_active as
> default to true. This prevents disabling USB controller if there is no

the vbus_active part should be in a separate patch as it has no relation
with $SUBJECT

> driver support for an external transceiver (or GPIO) that detects a VBUS
> power session starting.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 340451d..0a0d6a6 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -1242,8 +1242,10 @@ static int fsl_vbus_draw(struct usb_gadget *gadget, unsigned mA)
>  static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  {
>  	struct fsl_udc *udc;
> +	unsigned long flags;
>  
>  	udc = container_of(gadget, struct fsl_udc, gadget);
> +	spin_lock_irqsave(&udc->lock, flags);
>  	udc->softconnect = (is_on != 0);
>  	if (can_pullup(udc))
>  		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
> @@ -1251,6 +1253,7 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  	else
>  		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
> +	spin_unlock_irqrestore(&udc->lock, flags);
>  
>  	return 0;
>  }
> @@ -2557,6 +2560,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	INIT_LIST_HEAD(&udc_controller->gadget.ep_list);
>  	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
>  	udc_controller->gadget.name = driver_name;
> +	udc->vbus_active = true;
>  
>  	/* Setup gadget.dev and register with kernel */
>  	dev_set_name(&udc_controller->gadget.dev, "gadget");
> -- 
> 1.7.2.5
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style
  2012-10-19 10:24                                     ` [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style Christoph Fritz
@ 2012-10-19 10:27                                       ` Felipe Balbi
  0 siblings, 0 replies; 42+ messages in thread
From: Felipe Balbi @ 2012-10-19 10:27 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 22496 bytes --]

Hi,

typo on Subject. Should be udc, not ulc.

On Fri, Oct 19, 2012 at 12:24:41PM +0200, Christoph Fritz wrote:
> Convert to new UDC style registration and remove
> global 'udc_controller' pointer.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |  289 +++++++++++++++++--------------------
>  1 files changed, 131 insertions(+), 158 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index 0a0d6a6..d113f39 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -63,9 +63,6 @@ static struct usb_dr_device *dr_regs;
>  
>  static struct usb_sys_interface *usb_sys_regs;
>  
> -/* it is initialized in probe()  */
> -static struct fsl_udc *udc_controller = NULL;
> -
>  static const struct usb_endpoint_descriptor
>  fsl_ep0_desc = {
>  	.bLength =		USB_DT_ENDPOINT_SIZE,
> @@ -783,12 +780,14 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
>  }
>  
>  /* Fill in the dTD structure
> + * @udc: driver private data
>   * @req: request that the transfer belongs to
>   * @length: return actually data length of the dTD
>   * @dma: return dma address of the dTD
>   * @is_last: return flag if it is the last dTD of the request
>   * return: pointer to the built dTD */
> -static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
> +static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
> +		struct fsl_req *req, unsigned *length,
>  		dma_addr_t *dma, int *is_last, gfp_t gfp_flags)

I would split this patch a little. First I would patch the missing
arguments to these functions under the excuse that a later patch will
get rid of the udc_controller pointer, then the next patch would do the
conversion to new style.

It will be a lot easier to review ;-)

>  {
>  	u32 swap_temp;
> @@ -798,7 +797,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
>  	*length = min(req->req.length - req->req.actual,
>  			(unsigned)EP_MAX_LENGTH_TRANSFER);
>  
> -	dtd = dma_pool_alloc(udc_controller->td_pool, gfp_flags, dma);
> +	dtd = dma_pool_alloc(udc->td_pool, gfp_flags, dma);
>  	if (dtd == NULL)
>  		return dtd;
>  
> @@ -848,7 +847,8 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_req *req, unsigned *length,
>  }
>  
>  /* Generate dtd chain for a request */
> -static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
> +static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
> +		gfp_t gfp_flags)
>  {
>  	unsigned	count;
>  	int		is_last;
> @@ -857,7 +857,8 @@ static int fsl_req_to_dtd(struct fsl_req *req, gfp_t gfp_flags)
>  	dma_addr_t dma;
>  
>  	do {
> -		dtd = fsl_build_dtd(req, &count, &dma, &is_last, gfp_flags);
> +		dtd = fsl_build_dtd(udc, req, &count, &dma, &is_last,
> +				gfp_flags);
>  		if (dtd == NULL)
>  			return -ENOMEM;
>  
> @@ -932,7 +933,7 @@ fsl_ep_queue(struct usb_ep *_ep, struct usb_request *_req, gfp_t gfp_flags)
>  	req->dtd_count = 0;
>  
>  	/* build dtds and push them to device queue */
> -	if (!fsl_req_to_dtd(req, gfp_flags)) {
> +	if (!fsl_req_to_dtd(udc, req, gfp_flags)) {
>  		spin_lock_irqsave(&udc->lock, flags);
>  		fsl_queue_td(ep, req);
>  	} else {
> @@ -1258,9 +1259,10 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  	return 0;
>  }
>  
> -static int fsl_start(struct usb_gadget_driver *driver,
> -		int (*bind)(struct usb_gadget *, struct usb_gadget_driver *));
> -static int fsl_stop(struct usb_gadget_driver *driver);
> +static int fsl_udc_start(struct usb_gadget *gadget,
> +		struct usb_gadget_driver *driver);
> +static int fsl_udc_stop(struct usb_gadget *gadget,
> +		struct usb_gadget_driver *driver);
>  /* defined in gadget.h */
>  static struct usb_gadget_ops fsl_gadget_ops = {
>  	.get_frame = fsl_get_frame,
> @@ -1269,8 +1271,8 @@ static struct usb_gadget_ops fsl_gadget_ops = {
>  	.vbus_session = fsl_vbus_session,
>  	.vbus_draw = fsl_vbus_draw,
>  	.pullup = fsl_pullup,
> -	.start = fsl_start,
> -	.stop = fsl_stop,
> +	.udc_start = fsl_udc_start,
> +	.udc_stop = fsl_udc_stop,
>  };
>  
>  /* Set protocol stall on ep0, protocol stall will automatically be cleared
> @@ -1314,7 +1316,7 @@ static int ep0_prime_status(struct fsl_udc *udc, int direction)
>  			ep_is_in(ep) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);
>  	req->mapped = 1;
>  
> -	if (fsl_req_to_dtd(req, GFP_ATOMIC) == 0)
> +	if (fsl_req_to_dtd(udc, req, GFP_ATOMIC) == 0)
>  		fsl_queue_td(ep, req);
>  	else
>  		return -ENOMEM;
> @@ -1398,7 +1400,7 @@ static void ch9getstatus(struct fsl_udc *udc, u8 request_type, u16 value,
>  	req->mapped = 1;
>  
>  	/* prime the data phase */
> -	if ((fsl_req_to_dtd(req, GFP_ATOMIC) == 0))
> +	if ((fsl_req_to_dtd(udc, req, GFP_ATOMIC) == 0))
>  		fsl_queue_td(ep, req);
>  	else			/* no mem */
>  		goto stall;
> @@ -1422,7 +1424,7 @@ static void setup_received_irq(struct fsl_udc *udc,
>  
>  	udc_reset_ep_queue(udc, 0);
>  
> -	/* We process some stardard setup requests here */
> +	/* We process some standard setup requests here */
>  	switch (setup->bRequest) {
>  	case USB_REQ_GET_STATUS:
>  		/* Data+Status phase from udc */
> @@ -1954,114 +1956,82 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
>   * Hook to gadget drivers
>   * Called by initialization code of gadget drivers
>  *----------------------------------------------------------------*/
> -static int fsl_start(struct usb_gadget_driver *driver,
> -		int (*bind)(struct usb_gadget *, struct usb_gadget_driver *))
> +static int fsl_udc_start(struct usb_gadget *gadget,
> +	struct usb_gadget_driver *driver)
>  {
> +	struct fsl_udc *udc;
>  	int retval = -ENODEV;
> -	unsigned long flags = 0;
> +	unsigned long flags;
>  
> -	if (!udc_controller)
> +	udc = container_of(gadget, struct fsl_udc, gadget);
> +	if (!udc)
>  		return -ENODEV;
>  
>  	if (!driver || driver->max_speed < USB_SPEED_FULL
> -			|| !bind || !driver->disconnect || !driver->setup)
> +			|| !driver->disconnect || !driver->setup)
>  		return -EINVAL;
>  
> -	if (udc_controller->driver)
> -		return -EBUSY;
> -
>  	/* lock is needed but whether should use this lock or another */
> -	spin_lock_irqsave(&udc_controller->lock, flags);
> +	spin_lock_irqsave(&udc->lock, flags);
>  
>  	driver->driver.bus = NULL;
> -	/* hook up the driver */
> -	udc_controller->driver = driver;
> -	udc_controller->gadget.dev.driver = &driver->driver;
> -	spin_unlock_irqrestore(&udc_controller->lock, flags);
> -
> -	/* bind udc driver to gadget driver */
> -	retval = bind(&udc_controller->gadget, driver);
> -	if (retval) {
> -		VDBG("bind to %s --> %d", driver->driver.name, retval);
> -		udc_controller->gadget.dev.driver = NULL;
> -		udc_controller->driver = NULL;
> -		goto out;
> -	}
>  
> -	if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
> +	if (!IS_ERR_OR_NULL(udc->transceiver)) {
>  		/* Suspend the controller until OTG enable it */
> -		udc_controller->stopped = 1;
> +		udc->stopped = 1;
>  		printk(KERN_INFO "Suspend udc for OTG auto detect\n");
>  
>  		/* connect to bus through transceiver */
> -		if (!IS_ERR_OR_NULL(udc_controller->transceiver)) {
> -			retval = otg_set_peripheral(
> -					udc_controller->transceiver->otg,
> -						    &udc_controller->gadget);
> +		if (!IS_ERR_OR_NULL(udc->transceiver)) {
> +			retval = otg_set_peripheral(udc->transceiver->otg,
> +					&udc->gadget);
>  			if (retval < 0) {
>  				ERR("can't bind to transceiver\n");
> -				driver->unbind(&udc_controller->gadget);
> -				udc_controller->gadget.dev.driver = 0;
> -				udc_controller->driver = 0;
>  				return retval;
>  			}
>  		}
>  	} else {
> -		/* Enable DR IRQ reg and set USBCMD reg Run bit */
> -		dr_controller_run(udc_controller);
> -		udc_controller->usb_state = USB_STATE_ATTACHED;
> -		udc_controller->ep0_state = WAIT_FOR_SETUP;
> -		udc_controller->ep0_dir = 0;
> +		/* hook up the driver */
> +		udc->driver = driver;
> +		udc->gadget.dev.driver = &driver->driver;
> +		dr_controller_run(udc);
> +		udc->usb_state = USB_STATE_ATTACHED;
> +		udc->ep0_state = WAIT_FOR_SETUP;
> +		udc->ep0_dir = USB_DIR_OUT;
>  	}
> -	printk(KERN_INFO "%s: bind to driver %s\n",
> -			udc_controller->gadget.name, driver->driver.name);
> +	spin_unlock_irqrestore(&udc->lock, flags);
>  
> -out:
> -	if (retval)
> -		printk(KERN_WARNING "gadget driver register failed %d\n",
> -		       retval);
> -	return retval;
> +	return 0;
>  }
>  
>  /* Disconnect from gadget driver */
> -static int fsl_stop(struct usb_gadget_driver *driver)
> +static int fsl_udc_stop(struct usb_gadget *gadget,
> +	struct usb_gadget_driver *driver)
>  {
> +	struct fsl_udc *udc;
>  	struct fsl_ep *loop_ep;
>  	unsigned long flags;
>  
> -	if (!udc_controller)
> -		return -ENODEV;
> -
> -	if (!driver || driver != udc_controller->driver || !driver->unbind)
> -		return -EINVAL;
> -
> -	if (!IS_ERR_OR_NULL(udc_controller->transceiver))
> -		otg_set_peripheral(udc_controller->transceiver->otg, NULL);
> +	udc = container_of(gadget, struct fsl_udc, gadget);
>  
>  	/* stop DR, disable intr */
> -	dr_controller_stop(udc_controller);
> +	dr_controller_stop(udc);
>  
>  	/* in fact, no needed */
> -	udc_controller->usb_state = USB_STATE_ATTACHED;
> -	udc_controller->ep0_state = WAIT_FOR_SETUP;
> -	udc_controller->ep0_dir = 0;
> +	udc->usb_state = USB_STATE_ATTACHED;
> +	udc->ep0_state = WAIT_FOR_SETUP;
> +	udc->ep0_dir = USB_DIR_OUT;
>  
>  	/* stand operation */
> -	spin_lock_irqsave(&udc_controller->lock, flags);
> -	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
> -	nuke(&udc_controller->eps[0], -ESHUTDOWN);
> -	list_for_each_entry(loop_ep, &udc_controller->gadget.ep_list,
> -			ep.ep_list)
> +	spin_lock_irqsave(&udc->lock, flags);
> +	udc->gadget.speed = USB_SPEED_UNKNOWN;
> +	nuke(&udc->eps[0], -ESHUTDOWN);
> +	list_for_each_entry(loop_ep, &udc->gadget.ep_list, ep.ep_list)
>  		nuke(loop_ep, -ESHUTDOWN);
> -	spin_unlock_irqrestore(&udc_controller->lock, flags);
> -
> -	/* report disconnect; the controller is already quiesced */
> -	driver->disconnect(&udc_controller->gadget);
> +	spin_unlock_irqrestore(&udc->lock, flags);
>  
> -	/* unbind gadget and unhook driver. */
> -	driver->unbind(&udc_controller->gadget);
> -	udc_controller->gadget.dev.driver = NULL;
> -	udc_controller->driver = NULL;
> +	udc->gadget.dev.driver = NULL;
> +	udc->driver = NULL;
>  
>  	printk(KERN_WARNING "unregistered gadget driver '%s'\n",
>  	       driver->driver.name);
> @@ -2088,8 +2058,8 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	u32 tmp_reg;
>  	struct fsl_ep *ep = NULL;
>  	struct fsl_req *req;
> +	struct fsl_udc *udc = _dev;
>  
> -	struct fsl_udc *udc = udc_controller;
>  	if (off != 0)
>  		return 0;
>  
> @@ -2318,7 +2288,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  }
>  
>  #define create_proc_file()	create_proc_read_entry(proc_filename, \
> -				0, NULL, fsl_proc_read, NULL)
> +				0, NULL, fsl_proc_read, udc)
>  
>  #define remove_proc_file()	remove_proc_entry(proc_filename, NULL)
>  
> @@ -2334,10 +2304,12 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  /* Release udc structures */
>  static void fsl_udc_release(struct device *dev)
>  {
> -	complete(udc_controller->done);
> -	dma_free_coherent(dev->parent, udc_controller->ep_qh_size,
> -			udc_controller->ep_qh, udc_controller->ep_qh_dma);
> -	kfree(udc_controller);
> +	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
> +
> +	complete(udc->done);
> +	dma_free_coherent(dev->parent, udc->ep_qh_size,
> +			udc->ep_qh, udc->ep_qh_dma);
> +	kfree(udc);
>  }
>  
>  /******************************************************************
> @@ -2436,6 +2408,7 @@ static int __init struct_ep_setup(struct fsl_udc *udc, unsigned char index,
>   */
>  static int __init fsl_udc_probe(struct platform_device *pdev)
>  {
> +	struct fsl_udc *udc;
>  	struct fsl_usb2_platform_data *pdata;
>  	struct resource *res;
>  	int ret = -ENODEV;
> @@ -2447,21 +2420,21 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  		return -ENODEV;
>  	}
>  
> -	udc_controller = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
> -	if (udc_controller == NULL) {
> +	udc = kzalloc(sizeof(struct fsl_udc), GFP_KERNEL);
> +	if (udc == NULL) {
>  		ERR("malloc udc failed\n");
>  		return -ENOMEM;
>  	}
>  
>  	pdata = pdev->dev.platform_data;
> -	udc_controller->pdata = pdata;
> -	spin_lock_init(&udc_controller->lock);
> -	udc_controller->stopped = 1;
> +	udc->pdata = pdata;
> +	spin_lock_init(&udc->lock);
> +	udc->stopped = 1;
>  
>  #ifdef CONFIG_USB_OTG
>  	if (pdata->operating_mode == FSL_USB2_DR_OTG) {
> -		udc_controller->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
> -		if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
> +		udc->transceiver = usb_get_phy(USB_PHY_TYPE_USB2);
> +		if (IS_ERR_OR_NULL(udc->transceiver)) {
>  			ERR("Can't find OTG driver!\n");
>  			ret = -ENODEV;
>  			goto err_kfree;
> @@ -2522,90 +2495,90 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	}
>  	/* Get max device endpoints */
>  	/* DEN is bidirectional ep number, max_ep doubles the number */
> -	udc_controller->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2;
> +	udc->max_ep = (dccparams & DCCPARAMS_DEN_MASK) * 2;
>  
> -	udc_controller->irq = platform_get_irq(pdev, 0);
> -	if (!udc_controller->irq) {
> +	udc->irq = platform_get_irq(pdev, 0);
> +	if (!udc->irq) {
>  		ret = -ENODEV;
>  		goto err_iounmap;
>  	}
>  
> -	ret = request_irq(udc_controller->irq, fsl_udc_irq, IRQF_SHARED,
> -			driver_name, udc_controller);
> +	ret = request_irq(udc->irq, fsl_udc_irq, IRQF_SHARED,
> +			driver_name, udc);
>  	if (ret != 0) {
>  		ERR("cannot request irq %d err %d\n",
> -				udc_controller->irq, ret);
> +				udc->irq, ret);
>  		goto err_iounmap;
>  	}
>  
>  	/* Initialize the udc structure including QH member and other member */
> -	if (struct_udc_setup(udc_controller, pdev)) {
> +	if (struct_udc_setup(udc, pdev)) {
>  		ERR("Can't initialize udc data structure\n");
>  		ret = -ENOMEM;
>  		goto err_free_irq;
>  	}
>  
> -	if (IS_ERR_OR_NULL(udc_controller->transceiver)) {
> +	if (IS_ERR_OR_NULL(udc->transceiver)) {
>  		/* initialize usb hw reg except for regs for EP,
>  		 * leave usbintr reg untouched */
> -		dr_controller_setup(udc_controller);
> +		dr_controller_setup(udc);
>  	}
>  
>  	fsl_udc_clk_finalize(pdev);
>  
>  	/* Setup gadget structure */
> -	udc_controller->gadget.ops = &fsl_gadget_ops;
> -	udc_controller->gadget.max_speed = USB_SPEED_HIGH;
> -	udc_controller->gadget.ep0 = &udc_controller->eps[0].ep;
> -	INIT_LIST_HEAD(&udc_controller->gadget.ep_list);
> -	udc_controller->gadget.speed = USB_SPEED_UNKNOWN;
> -	udc_controller->gadget.name = driver_name;
> +	udc->gadget.ops = &fsl_gadget_ops;
> +	udc->gadget.max_speed = USB_SPEED_HIGH;
> +	udc->gadget.ep0 = &udc->eps[0].ep;
> +	INIT_LIST_HEAD(&udc->gadget.ep_list);
> +	udc->gadget.speed = USB_SPEED_UNKNOWN;
> +	udc->gadget.name = driver_name;
>  	udc->vbus_active = true;
>  
>  	/* Setup gadget.dev and register with kernel */
> -	dev_set_name(&udc_controller->gadget.dev, "gadget");
> -	udc_controller->gadget.dev.release = fsl_udc_release;
> -	udc_controller->gadget.dev.parent = &pdev->dev;
> -	udc_controller->gadget.dev.of_node = pdev->dev.of_node;
> -	ret = device_register(&udc_controller->gadget.dev);
> +	dev_set_name(&udc->gadget.dev, "gadget");
> +	udc->gadget.dev.release = fsl_udc_release;
> +	udc->gadget.dev.parent = &pdev->dev;
> +	udc->gadget.dev.of_node = pdev->dev.of_node;
> +	ret = device_register(&udc->gadget.dev);
>  	if (ret < 0)
>  		goto err_free_irq;
>  
> -	if (!IS_ERR_OR_NULL(udc_controller->transceiver))
> -		udc_controller->gadget.is_otg = 1;
> +	if (!IS_ERR_OR_NULL(udc->transceiver))
> +		udc->gadget.is_otg = 1;
>  
>  	/* setup QH and epctrl for ep0 */
> -	ep0_setup(udc_controller);
> +	ep0_setup(udc);
>  
>  	/* setup udc->eps[] for ep0 */
> -	struct_ep_setup(udc_controller, 0, "ep0", 0);
> +	struct_ep_setup(udc, 0, "ep0", 0);
>  	/* for ep0: the desc defined here;
>  	 * for other eps, gadget layer called ep_enable with defined desc
>  	 */
> -	udc_controller->eps[0].ep.desc = &fsl_ep0_desc;
> -	udc_controller->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
> +	udc->eps[0].ep.desc = &fsl_ep0_desc;
> +	udc->eps[0].ep.maxpacket = USB_MAX_CTRL_PAYLOAD;
>  
>  	/* setup the udc->eps[] for non-control endpoints and link
>  	 * to gadget.ep_list */
> -	for (i = 1; i < (int)(udc_controller->max_ep / 2); i++) {
> +	for (i = 1; i < (int)(udc->max_ep / 2); i++) {
>  		char name[14];
>  
>  		sprintf(name, "ep%dout", i);
> -		struct_ep_setup(udc_controller, i * 2, name, 1);
> +		struct_ep_setup(udc, i * 2, name, 1);
>  		sprintf(name, "ep%din", i);
> -		struct_ep_setup(udc_controller, i * 2 + 1, name, 1);
> +		struct_ep_setup(udc, i * 2 + 1, name, 1);
>  	}
>  
>  	/* use dma_pool for TD management */
> -	udc_controller->td_pool = dma_pool_create("udc_td", &pdev->dev,
> +	udc->td_pool = dma_pool_create("udc_td", &pdev->dev,
>  			sizeof(struct ep_td_struct),
>  			DTD_ALIGNMENT, UDC_DMA_BOUNDARY);
> -	if (udc_controller->td_pool == NULL) {
> +	if (udc->td_pool == NULL) {
>  		ret = -ENOMEM;
>  		goto err_unregister;
>  	}
>  
> -	ret = usb_add_gadget_udc(&pdev->dev, &udc_controller->gadget);
> +	ret = usb_add_gadget_udc(&pdev->dev, &udc->gadget);
>  	if (ret)
>  		goto err_del_udc;
>  
> @@ -2613,11 +2586,11 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  	return 0;
>  
>  err_del_udc:
> -	dma_pool_destroy(udc_controller->td_pool);
> +	dma_pool_destroy(udc->td_pool);
>  err_unregister:
> -	device_unregister(&udc_controller->gadget.dev);
> +	device_unregister(&udc->gadget.dev);
>  err_free_irq:
> -	free_irq(udc_controller->irq, udc_controller);
> +	free_irq(udc->irq, udc);
>  err_iounmap:
>  	if (pdata->exit)
>  		pdata->exit(pdev);
> @@ -2628,8 +2601,7 @@ err_release_mem_region:
>  	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
>  		release_mem_region(res->start, resource_size(res));
>  err_kfree:
> -	kfree(udc_controller);
> -	udc_controller = NULL;
> +	kfree(udc);
>  	return ret;
>  }
>  
> @@ -2638,16 +2610,13 @@ err_kfree:
>   */
>  static int __exit fsl_udc_remove(struct platform_device *pdev)
>  {
> +	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
>  	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
> -
>  	DECLARE_COMPLETION(done);
>  
> -	if (!udc_controller)
> -		return -ENODEV;
> -
> -	usb_del_gadget_udc(&udc_controller->gadget);
> -	udc_controller->done = &done;
> +	usb_del_gadget_udc(&udc->gadget);
> +	udc->done = &done;
>  
>  	fsl_udc_clk_release();
>  
> @@ -2655,17 +2624,17 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
>  	remove_proc_file();
>  
>  	/* Free allocated memory */
> -	kfree(udc_controller->status_req->req.buf);
> -	kfree(udc_controller->status_req);
> -	kfree(udc_controller->eps);
> +	kfree(udc->status_req->req.buf);
> +	kfree(udc->status_req);
> +	kfree(udc->eps);
>  
> -	dma_pool_destroy(udc_controller->td_pool);
> -	free_irq(udc_controller->irq, udc_controller);
> +	dma_pool_destroy(udc->td_pool);
> +	free_irq(udc->irq, udc);
>  	iounmap(dr_regs);
>  	if (pdata->operating_mode == FSL_USB2_DR_DEVICE)
>  		release_mem_region(res->start, resource_size(res));
>  
> -	device_unregister(&udc_controller->gadget.dev);
> +	device_unregister(&udc->gadget.dev);
>  	/* free udc --wait for the release() finished */
>  	wait_for_completion(&done);
>  
> @@ -2685,7 +2654,8 @@ static int __exit fsl_udc_remove(struct platform_device *pdev)
>   -----------------------------------------------------------------*/
>  static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state)
>  {
> -	dr_controller_stop(udc_controller);
> +	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
> +	dr_controller_stop(udc);
>  	return 0;
>  }
>  
> @@ -2695,20 +2665,21 @@ static int fsl_udc_suspend(struct platform_device *pdev, pm_message_t state)
>   *-----------------------------------------------------------------*/
>  static int fsl_udc_resume(struct platform_device *pdev)
>  {
> +	struct fsl_udc *udc = dev_get_drvdata(&pdev->dev);
>  	/* Enable DR irq reg and set controller Run */
> -	if (udc_controller->stopped) {
> -		dr_controller_setup(udc_controller);
> -		dr_controller_run(udc_controller);
> +	if (udc->stopped) {
> +		dr_controller_setup(udc);
> +		dr_controller_run(udc);
>  	}
> -	udc_controller->usb_state = USB_STATE_ATTACHED;
> -	udc_controller->ep0_state = WAIT_FOR_SETUP;
> -	udc_controller->ep0_dir = 0;
> +	udc->usb_state = USB_STATE_ATTACHED;
> +	udc->ep0_state = WAIT_FOR_SETUP;
> +	udc->ep0_dir = USB_DIR_OUT;
>  	return 0;
>  }
>  
>  static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  {
> -	struct fsl_udc *udc = udc_controller;
> +	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
>  	u32 mode, usbcmd;
>  
>  	mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
> @@ -2744,15 +2715,17 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  
>  static int fsl_udc_otg_resume(struct device *dev)
>  {
> +	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
> +
>  	pr_debug("%s(): stopped %d  already_stopped %d\n", __func__,
> -		 udc_controller->stopped, udc_controller->already_stopped);
> +		 udc->stopped, udc->already_stopped);
>  
>  	/*
>  	 * If the controller was stopped at suspend time, then
>  	 * don't resume it now.
>  	 */
> -	if (udc_controller->already_stopped) {
> -		udc_controller->already_stopped = 0;
> +	if (udc->already_stopped) {
> +		udc->already_stopped = 0;
>  		pr_debug("gadget was already stopped, leaving early\n");
>  		return 0;
>  	}
> -- 
> 1.7.2.5
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency
  2012-10-19 10:24                                     ` [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency Christoph Fritz
@ 2012-10-19 10:29                                       ` Felipe Balbi
  0 siblings, 0 replies; 42+ messages in thread
From: Felipe Balbi @ 2012-10-19 10:29 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 33369 bytes --]

On Fri, Oct 19, 2012 at 12:24:42PM +0200, Christoph Fritz wrote:
> Drop the big-/little-endian helpers and make use of generic
> writel()/readl() routines.
> 
> Signed-off-by: Christoph Fritz <chf.fritz@googlemail.com>
> ---
>  drivers/usb/gadget/fsl_udc_core.c |  331 +++++++++++++------------------------
>  1 files changed, 118 insertions(+), 213 deletions(-)
> 
> diff --git a/drivers/usb/gadget/fsl_udc_core.c b/drivers/usb/gadget/fsl_udc_core.c
> index d113f39..53df9c0 100644
> --- a/drivers/usb/gadget/fsl_udc_core.c
> +++ b/drivers/usb/gadget/fsl_udc_core.c
> @@ -20,32 +20,14 @@
>  #undef VERBOSE
>  
>  #include <linux/module.h>
> -#include <linux/kernel.h>
> -#include <linux/ioport.h>
> -#include <linux/types.h>
> -#include <linux/errno.h>
> -#include <linux/err.h>
> -#include <linux/slab.h>
> -#include <linux/init.h>
> -#include <linux/list.h>

you don't mention removal of these registers anywhere. Why are you
doing this ? Are those really unnecessary or are you now depending on
indirect inclusion of the headers ?

Also, $SUBJECT is a bit misleading since you don't touch Kconfig to
actually drop the ARCH dependency. Maybe rephrase $SUBJECT a little ?

>  #include <linux/interrupt.h>
>  #include <linux/proc_fs.h>
> -#include <linux/mm.h>
> -#include <linux/moduleparam.h>
> -#include <linux/device.h>
> -#include <linux/usb/ch9.h>
>  #include <linux/usb/gadget.h>
>  #include <linux/usb/otg.h>
>  #include <linux/dma-mapping.h>
>  #include <linux/platform_device.h>
>  #include <linux/fsl_devices.h>
>  #include <linux/dmapool.h>
> -#include <linux/delay.h>
> -
> -#include <asm/byteorder.h>
> -#include <asm/io.h>
> -#include <asm/unaligned.h>
> -#include <asm/dma.h>
>  
>  #include "fsl_usb2_udc.h"
>  
> @@ -74,78 +56,6 @@ fsl_ep0_desc = {
>  
>  static void fsl_ep_fifo_flush(struct usb_ep *_ep);
>  
> -#ifdef CONFIG_PPC32
> -/*
> - * On some SoCs, the USB controller registers can be big or little endian,
> - * depending on the version of the chip. In order to be able to run the
> - * same kernel binary on 2 different versions of an SoC, the BE/LE decision
> - * must be made at run time. _fsl_readl and fsl_writel are pointers to the
> - * BE or LE readl() and writel() functions, and fsl_readl() and fsl_writel()
> - * call through those pointers. Platform code for SoCs that have BE USB
> - * registers should set pdata->big_endian_mmio flag.
> - *
> - * This also applies to controller-to-cpu accessors for the USB descriptors,
> - * since their endianness is also SoC dependant. Platform code for SoCs that
> - * have BE USB descriptors should set pdata->big_endian_desc flag.
> - */
> -static u32 _fsl_readl_be(const unsigned __iomem *p)
> -{
> -	return in_be32(p);
> -}
> -
> -static u32 _fsl_readl_le(const unsigned __iomem *p)
> -{
> -	return in_le32(p);
> -}
> -
> -static void _fsl_writel_be(u32 v, unsigned __iomem *p)
> -{
> -	out_be32(p, v);
> -}
> -
> -static void _fsl_writel_le(u32 v, unsigned __iomem *p)
> -{
> -	out_le32(p, v);
> -}
> -
> -static u32 (*_fsl_readl)(const unsigned __iomem *p);
> -static void (*_fsl_writel)(u32 v, unsigned __iomem *p);
> -
> -#define fsl_readl(p)		(*_fsl_readl)((p))
> -#define fsl_writel(v, p)	(*_fsl_writel)((v), (p))
> -
> -static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata)
> -{
> -	if (pdata->big_endian_mmio) {
> -		_fsl_readl = _fsl_readl_be;
> -		_fsl_writel = _fsl_writel_be;
> -	} else {
> -		_fsl_readl = _fsl_readl_le;
> -		_fsl_writel = _fsl_writel_le;
> -	}
> -}
> -
> -static inline u32 cpu_to_hc32(const u32 x)
> -{
> -	return udc_controller->pdata->big_endian_desc
> -		? (__force u32)cpu_to_be32(x)
> -		: (__force u32)cpu_to_le32(x);
> -}
> -
> -static inline u32 hc32_to_cpu(const u32 x)
> -{
> -	return udc_controller->pdata->big_endian_desc
> -		? be32_to_cpu((__force __be32)x)
> -		: le32_to_cpu((__force __le32)x);
> -}
> -#else /* !CONFIG_PPC32 */
> -static inline void fsl_set_accessors(struct fsl_usb2_platform_data *pdata) {}
> -
> -#define fsl_readl(addr)		readl(addr)
> -#define fsl_writel(val32, addr) writel(val32, addr)
> -#define cpu_to_hc32(x)		cpu_to_le32(x)
> -#define hc32_to_cpu(x)		le32_to_cpu(x)
> -#endif /* CONFIG_PPC32 */
>  
>  /********************************************************************
>   *	Internal Used Function
> @@ -248,7 +158,7 @@ static int dr_controller_setup(struct fsl_udc *udc)
>  #define FSL_UDC_RESET_TIMEOUT 1000
>  
>  	/* Config PHY interface */
> -	portctrl = fsl_readl(&dr_regs->portsc1);
> +	portctrl = readl(&dr_regs->portsc1);
>  	portctrl &= ~(PORTSCX_PHY_TYPE_SEL | PORTSCX_PORT_WIDTH);
>  	switch (udc->phy_mode) {
>  	case FSL_USB2_PHY_ULPI:
> @@ -286,20 +196,20 @@ static int dr_controller_setup(struct fsl_udc *udc)
>  	default:
>  		return -EINVAL;
>  	}
> -	fsl_writel(portctrl, &dr_regs->portsc1);
> +	writel(portctrl, &dr_regs->portsc1);
>  
>  	/* Stop and reset the usb controller */
> -	tmp = fsl_readl(&dr_regs->usbcmd);
> +	tmp = readl(&dr_regs->usbcmd);
>  	tmp &= ~USB_CMD_RUN_STOP;
> -	fsl_writel(tmp, &dr_regs->usbcmd);
> +	writel(tmp, &dr_regs->usbcmd);
>  
> -	tmp = fsl_readl(&dr_regs->usbcmd);
> +	tmp = readl(&dr_regs->usbcmd);
>  	tmp |= USB_CMD_CTRL_RESET;
> -	fsl_writel(tmp, &dr_regs->usbcmd);
> +	writel(tmp, &dr_regs->usbcmd);
>  
>  	/* Wait for reset to complete */
>  	timeout = jiffies + FSL_UDC_RESET_TIMEOUT;
> -	while (fsl_readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
> +	while (readl(&dr_regs->usbcmd) & USB_CMD_CTRL_RESET) {
>  		if (time_after(jiffies, timeout)) {
>  			ERR("udc reset timeout!\n");
>  			return -ETIMEDOUT;
> @@ -308,33 +218,33 @@ static int dr_controller_setup(struct fsl_udc *udc)
>  	}
>  
>  	/* Set the controller as device mode */
> -	tmp = fsl_readl(&dr_regs->usbmode);
> +	tmp = readl(&dr_regs->usbmode);
>  	tmp &= ~USB_MODE_CTRL_MODE_MASK;	/* clear mode bits */
>  	tmp |= USB_MODE_CTRL_MODE_DEVICE;
>  	/* Disable Setup Lockout */
>  	tmp |= USB_MODE_SETUP_LOCK_OFF;
>  	if (udc->pdata->es)
>  		tmp |= USB_MODE_ES;
> -	fsl_writel(tmp, &dr_regs->usbmode);
> +	writel(tmp, &dr_regs->usbmode);
>  
>  	/* Clear the setup status */
> -	fsl_writel(0, &dr_regs->usbsts);
> +	writel(0, &dr_regs->usbsts);
>  
>  	tmp = udc->ep_qh_dma;
>  	tmp &= USB_EP_LIST_ADDRESS_MASK;
> -	fsl_writel(tmp, &dr_regs->endpointlistaddr);
> +	writel(tmp, &dr_regs->endpointlistaddr);
>  
>  	VDBG("vir[qh_base] is %p phy[qh_base] is 0x%8x reg is 0x%8x",
>  		udc->ep_qh, (int)tmp,
> -		fsl_readl(&dr_regs->endpointlistaddr));
> +		readl(&dr_regs->endpointlistaddr));
>  
> -	max_no_of_ep = (0x0000001F & fsl_readl(&dr_regs->dccparams));
> +	max_no_of_ep = (0x0000001F & readl(&dr_regs->dccparams));
>  	for (ep_num = 1; ep_num < max_no_of_ep; ep_num++) {
> -		tmp = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +		tmp = readl(&dr_regs->endptctrl[ep_num]);
>  		tmp &= ~(EPCTRL_TX_TYPE | EPCTRL_RX_TYPE);
>  		tmp |= (EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT)
>  		| (EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT);
> -		fsl_writel(tmp, &dr_regs->endptctrl[ep_num]);
> +		writel(tmp, &dr_regs->endptctrl[ep_num]);
>  	}
>  	/* Config control enable i/o output, cpu endian register */
>  #ifndef CONFIG_ARCH_MXC
> @@ -371,20 +281,20 @@ static void dr_controller_run(struct fsl_udc *udc)
>  		| USB_INTR_PTC_DETECT_EN | USB_INTR_RESET_EN
>  		| USB_INTR_DEVICE_SUSPEND | USB_INTR_SYS_ERR_EN;
>  
> -	fsl_writel(temp, &dr_regs->usbintr);
> +	writel(temp, &dr_regs->usbintr);
>  
>  	/* Clear stopped bit */
>  	udc->stopped = 0;
>  
>  	/* Set the controller as device mode */
> -	temp = fsl_readl(&dr_regs->usbmode);
> +	temp = readl(&dr_regs->usbmode);
>  	temp |= USB_MODE_CTRL_MODE_DEVICE;
> -	fsl_writel(temp, &dr_regs->usbmode);
> +	writel(temp, &dr_regs->usbmode);
>  
>  	/* Set controller to Run */
> -	temp = fsl_readl(&dr_regs->usbcmd);
> +	temp = readl(&dr_regs->usbcmd);
>  	temp |= USB_CMD_RUN_STOP;
> -	fsl_writel(temp, &dr_regs->usbcmd);
> +	writel(temp, &dr_regs->usbcmd);
>  }
>  
>  static void dr_controller_stop(struct fsl_udc *udc)
> @@ -398,14 +308,14 @@ static void dr_controller_stop(struct fsl_udc *udc)
>  	 * ehci driver
>  	 */
>  	if (udc->gadget.is_otg) {
> -		if (!(fsl_readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
> +		if (!(readl(&dr_regs->otgsc) & OTGSC_STS_USB_ID)) {
>  			pr_debug("udc: Leaving early\n");
>  			return;
>  		}
>  	}
>  
>  	/* disable all INTR */
> -	fsl_writel(0, &dr_regs->usbintr);
> +	writel(0, &dr_regs->usbintr);
>  
>  	/* Set stopped bit for isr */
>  	udc->stopped = 1;
> @@ -414,9 +324,9 @@ static void dr_controller_stop(struct fsl_udc *udc)
>  /*	usb_sys_regs->control = 0; */
>  
>  	/* set controller to Stop */
> -	tmp = fsl_readl(&dr_regs->usbcmd);
> +	tmp = readl(&dr_regs->usbcmd);
>  	tmp &= ~USB_CMD_RUN_STOP;
> -	fsl_writel(tmp, &dr_regs->usbcmd);
> +	writel(tmp, &dr_regs->usbcmd);
>  }
>  
>  static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
> @@ -424,7 +334,7 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
>  {
>  	unsigned int tmp_epctrl = 0;
>  
> -	tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (dir) {
>  		if (ep_num)
>  			tmp_epctrl |= EPCTRL_TX_DATA_TOGGLE_RST;
> @@ -441,7 +351,7 @@ static void dr_ep_setup(unsigned char ep_num, unsigned char dir,
>  				<< EPCTRL_RX_EP_TYPE_SHIFT);
>  	}
>  
> -	fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
>  }
>  
>  static void
> @@ -449,7 +359,7 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
>  {
>  	u32 tmp_epctrl = 0;
>  
> -	tmp_epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	tmp_epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  
>  	if (value) {
>  		/* set the stall bit */
> @@ -467,7 +377,7 @@ dr_ep_change_stall(unsigned char ep_num, unsigned char dir, int value)
>  			tmp_epctrl |= EPCTRL_RX_DATA_TOGGLE_RST;
>  		}
>  	}
> -	fsl_writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(tmp_epctrl, &dr_regs->endptctrl[ep_num]);
>  }
>  
>  /* Get stall status of a specific ep
> @@ -476,7 +386,7 @@ static int dr_ep_get_stall(unsigned char ep_num, unsigned char dir)
>  {
>  	u32 epctrl;
>  
> -	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (dir)
>  		return (epctrl & EPCTRL_TX_EP_STALL) ? 1 : 0;
>  	else
> @@ -522,7 +432,7 @@ static void struct_ep_qh_setup(struct fsl_udc *udc, unsigned char ep_num,
>  	if (zlt)
>  		tmp |= EP_QUEUE_HEAD_ZLT_SEL;
>  
> -	p_QH->max_pkt_length = cpu_to_hc32(tmp);
> +	p_QH->max_pkt_length = cpu_to_le32(tmp);
>  	p_QH->next_dtd_ptr = 1;
>  	p_QH->size_ioc_int_sts = 0;
>  }
> @@ -658,7 +568,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
>  
>  	/* disable ep on controller */
>  	ep_num = ep_index(ep);
> -	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (ep_is_in(ep)) {
>  		epctrl &= ~(EPCTRL_TX_ENABLE | EPCTRL_TX_TYPE);
>  		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_TX_EP_TYPE_SHIFT;
> @@ -666,7 +576,7 @@ static int fsl_ep_disable(struct usb_ep *_ep)
>  		epctrl &= ~(EPCTRL_RX_ENABLE | EPCTRL_TX_TYPE);
>  		epctrl |= EPCTRL_EP_TYPE_BULK << EPCTRL_RX_EP_TYPE_SHIFT;
>  	}
> -	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(epctrl, &dr_regs->endptctrl[ep_num]);
>  
>  	udc = (struct fsl_udc *)ep->udc;
>  	spin_lock_irqsave(&udc->lock, flags);
> @@ -718,18 +628,18 @@ static void fsl_prime_ep(struct fsl_ep *ep, struct ep_td_struct *td)
>  	struct ep_queue_head *qh = get_qh_by_ep(ep);
>  
>  	/* Write dQH next pointer and terminate bit to 0 */
> -	qh->next_dtd_ptr = cpu_to_hc32(td->td_dma
> +	qh->next_dtd_ptr = cpu_to_le32(td->td_dma
>  			& EP_QUEUE_HEAD_NEXT_POINTER_MASK);
>  
>  	/* Clear active and halt bit */
> -	qh->size_ioc_int_sts &= cpu_to_hc32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
> +	qh->size_ioc_int_sts &= cpu_to_le32(~(EP_QUEUE_HEAD_STATUS_ACTIVE
>  					| EP_QUEUE_HEAD_STATUS_HALT));
>  
>  	/* Ensure that updates to the QH will occur before priming. */
>  	wmb();
>  
>  	/* Prime endpoint by writing correct bit to ENDPTPRIME */
> -	fsl_writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
> +	writel(ep_is_in(ep) ? (1 << (ep_index(ep) + 16))
>  			: (1 << (ep_index(ep))), &dr_regs->endpointprime);
>  }
>  
> @@ -751,26 +661,26 @@ static void fsl_queue_td(struct fsl_ep *ep, struct fsl_req *req)
>  		struct fsl_req *lastreq;
>  		lastreq = list_entry(ep->queue.prev, struct fsl_req, queue);
>  		lastreq->tail->next_td_ptr =
> -			cpu_to_hc32(req->head->td_dma & DTD_ADDR_MASK);
> +			cpu_to_le32(req->head->td_dma & DTD_ADDR_MASK);
>  		/* Ensure dTD's next dtd pointer to be updated */
>  		wmb();
>  		/* Read prime bit, if 1 goto done */
> -		if (fsl_readl(&dr_regs->endpointprime) & bitmask)
> +		if (readl(&dr_regs->endpointprime) & bitmask)
>  			return;
>  
>  		do {
>  			/* Set ATDTW bit in USBCMD */
> -			temp = fsl_readl(&dr_regs->usbcmd);
> -			fsl_writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
> +			temp = readl(&dr_regs->usbcmd);
> +			writel(temp | USB_CMD_ATDTW, &dr_regs->usbcmd);
>  
>  			/* Read correct status bit */
> -			tmp_stat = fsl_readl(&dr_regs->endptstatus) & bitmask;
> +			tmp_stat = readl(&dr_regs->endptstatus) & bitmask;
>  
> -		} while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
> +		} while (!(readl(&dr_regs->usbcmd) & USB_CMD_ATDTW));
>  
>  		/* Write ATDTW bit to 0 */
> -		temp = fsl_readl(&dr_regs->usbcmd);
> -		fsl_writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
> +		temp = readl(&dr_regs->usbcmd);
> +		writel(temp & ~USB_CMD_ATDTW, &dr_regs->usbcmd);
>  
>  		if (tmp_stat)
>  			return;
> @@ -803,17 +713,17 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
>  
>  	dtd->td_dma = *dma;
>  	/* Clear reserved field */
> -	swap_temp = hc32_to_cpu(dtd->size_ioc_sts);
> +	swap_temp = dtd->size_ioc_sts;
>  	swap_temp &= ~DTD_RESERVED_FIELDS;
> -	dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
> +	dtd->size_ioc_sts = cpu_to_le32(swap_temp);
>  
>  	/* Init all of buffer page pointers */
>  	swap_temp = (u32) (req->req.dma + req->req.actual);
> -	dtd->buff_ptr0 = cpu_to_hc32(swap_temp);
> -	dtd->buff_ptr1 = cpu_to_hc32(swap_temp + 0x1000);
> -	dtd->buff_ptr2 = cpu_to_hc32(swap_temp + 0x2000);
> -	dtd->buff_ptr3 = cpu_to_hc32(swap_temp + 0x3000);
> -	dtd->buff_ptr4 = cpu_to_hc32(swap_temp + 0x4000);
> +	dtd->buff_ptr0 = cpu_to_le32(swap_temp);
> +	dtd->buff_ptr1 = cpu_to_le32(swap_temp + 0x1000);
> +	dtd->buff_ptr2 = cpu_to_le32(swap_temp + 0x2000);
> +	dtd->buff_ptr3 = cpu_to_le32(swap_temp + 0x3000);
> +	dtd->buff_ptr4 = cpu_to_le32(swap_temp + 0x4000);
>  
>  	req->req.actual += *length;
>  
> @@ -837,7 +747,7 @@ static struct ep_td_struct *fsl_build_dtd(struct fsl_udc *udc,
>  	if (*is_last && !req->req.no_interrupt)
>  		swap_temp |= DTD_IOC;
>  
> -	dtd->size_ioc_sts = cpu_to_hc32(swap_temp);
> +	dtd->size_ioc_sts = cpu_to_le32(swap_temp);
>  
>  	mb();
>  
> @@ -866,7 +776,7 @@ static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
>  			is_first = 0;
>  			req->head = dtd;
>  		} else {
> -			last_dtd->next_td_ptr = cpu_to_hc32(dma);
> +			last_dtd->next_td_ptr = cpu_to_le32(dma);
>  			last_dtd->next_td_virt = dtd;
>  		}
>  		last_dtd = dtd;
> @@ -874,7 +784,7 @@ static int fsl_req_to_dtd(struct fsl_udc *udc, struct fsl_req *req,
>  		req->dtd_count++;
>  	} while (!is_last);
>  
> -	dtd->next_td_ptr = cpu_to_hc32(DTD_NEXT_TERMINATE);
> +	dtd->next_td_ptr = cpu_to_le32(DTD_NEXT_TERMINATE);
>  
>  	req->tail = dtd;
>  
> @@ -966,12 +876,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
>  	/* Stop the ep before we deal with the queue */
>  	ep->stopped = 1;
>  	ep_num = ep_index(ep);
> -	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (ep_is_in(ep))
>  		epctrl &= ~EPCTRL_TX_ENABLE;
>  	else
>  		epctrl &= ~EPCTRL_RX_ENABLE;
> -	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(epctrl, &dr_regs->endptctrl[ep_num]);
>  
>  	/* make sure it's actually queued on this endpoint */
>  	list_for_each_entry(req, &ep->queue, queue) {
> @@ -1009,12 +919,12 @@ static int fsl_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
>  	done(ep, req, -ECONNRESET);
>  
>  	/* Enable EP */
> -out:	epctrl = fsl_readl(&dr_regs->endptctrl[ep_num]);
> +out:	epctrl = readl(&dr_regs->endptctrl[ep_num]);
>  	if (ep_is_in(ep))
>  		epctrl |= EPCTRL_TX_ENABLE;
>  	else
>  		epctrl |= EPCTRL_RX_ENABLE;
> -	fsl_writel(epctrl, &dr_regs->endptctrl[ep_num]);
> +	writel(epctrl, &dr_regs->endptctrl[ep_num]);
>  	ep->stopped = stopped;
>  
>  	spin_unlock_irqrestore(&ep->udc->lock, flags);
> @@ -1096,7 +1006,7 @@ static int fsl_ep_fifo_status(struct usb_ep *_ep)
>  	bitmask = (ep_is_in(ep)) ? (1 << (ep_index(ep) + 16)) :
>  	    (1 << (ep_index(ep)));
>  
> -	if (fsl_readl(&dr_regs->endptstatus) & bitmask)
> +	if (readl(&dr_regs->endptstatus) & bitmask)
>  		size = (qh->size_ioc_int_sts & DTD_PACKET_SIZE)
>  		    >> DTD_LENGTH_BIT_POS;
>  
> @@ -1131,10 +1041,10 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
>  
>  	timeout = jiffies + FSL_UDC_FLUSH_TIMEOUT;
>  	do {
> -		fsl_writel(bits, &dr_regs->endptflush);
> +		writel(bits, &dr_regs->endptflush);
>  
>  		/* Wait until flush complete */
> -		while (fsl_readl(&dr_regs->endptflush)) {
> +		while (readl(&dr_regs->endptflush)) {
>  			if (time_after(jiffies, timeout)) {
>  				ERR("ep flush timeout\n");
>  				return;
> @@ -1142,7 +1052,7 @@ static void fsl_ep_fifo_flush(struct usb_ep *_ep)
>  			cpu_relax();
>  		}
>  		/* See if we need to flush again */
> -	} while (fsl_readl(&dr_regs->endptstatus) & bits);
> +	} while (readl(&dr_regs->endptstatus) & bits);
>  }
>  
>  static struct usb_ep_ops fsl_ep_ops = {
> @@ -1169,7 +1079,7 @@ static struct usb_ep_ops fsl_ep_ops = {
>   *----------------------------------------------------------------------*/
>  static int fsl_get_frame(struct usb_gadget *gadget)
>  {
> -	return (int)(fsl_readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
> +	return (int)(readl(&dr_regs->frindex) & USB_FRINDEX_MASKS);
>  }
>  
>  /*-----------------------------------------------------------------------
> @@ -1184,13 +1094,13 @@ static int fsl_wakeup(struct usb_gadget *gadget)
>  	if (!udc->remote_wakeup)
>  		return -ENOTSUPP;
>  
> -	portsc = fsl_readl(&dr_regs->portsc1);
> +	portsc = readl(&dr_regs->portsc1);
>  	/* not suspended? */
>  	if (!(portsc & PORTSCX_PORT_SUSPEND))
>  		return 0;
>  	/* trigger force resume */
>  	portsc |= PORTSCX_PORT_FORCE_RESUME;
> -	fsl_writel(portsc, &dr_regs->portsc1);
> +	writel(portsc, &dr_regs->portsc1);
>  	return 0;
>  }
>  
> @@ -1211,10 +1121,10 @@ static int fsl_vbus_session(struct usb_gadget *gadget, int is_active)
>  	VDBG("VBUS %s", is_active ? "on" : "off");
>  	udc->vbus_active = (is_active != 0);
>  	if (can_pullup(udc))
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	else
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	spin_unlock_irqrestore(&udc->lock, flags);
>  	return 0;
> @@ -1249,10 +1159,10 @@ static int fsl_pullup(struct usb_gadget *gadget, int is_on)
>  	spin_lock_irqsave(&udc->lock, flags);
>  	udc->softconnect = (is_on != 0);
>  	if (can_pullup(udc))
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) | USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	else
> -		fsl_writel((fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
> +		writel((readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP),
>  				&dr_regs->usbcmd);
>  	spin_unlock_irqrestore(&udc->lock, flags);
>  
> @@ -1282,9 +1192,9 @@ static void ep0stall(struct fsl_udc *udc)
>  	u32 tmp;
>  
>  	/* must set tx and rx to stall at the same time */
> -	tmp = fsl_readl(&dr_regs->endptctrl[0]);
> +	tmp = readl(&dr_regs->endptctrl[0]);
>  	tmp |= EPCTRL_TX_EP_STALL | EPCTRL_RX_EP_STALL;
> -	fsl_writel(tmp, &dr_regs->endptctrl[0]);
> +	writel(tmp, &dr_regs->endptctrl[0]);
>  	udc->ep0_state = WAIT_FOR_SETUP;
>  	udc->ep0_dir = 0;
>  }
> @@ -1494,8 +1404,8 @@ static void setup_received_irq(struct fsl_udc *udc,
>  			u32 tmp;
>  
>  			mdelay(10);
> -			tmp = fsl_readl(&dr_regs->portsc1) | (ptc << 16);
> -			fsl_writel(tmp, &dr_regs->portsc1);
> +			tmp = readl(&dr_regs->portsc1) | (ptc << 16);
> +			writel(tmp, &dr_regs->portsc1);
>  			printk(KERN_INFO "udc: switch to test mode %d.\n", ptc);
>  		}
>  
> @@ -1546,7 +1456,7 @@ static void ep0_req_complete(struct fsl_udc *udc, struct fsl_ep *ep0,
>  	if (udc->usb_state == USB_STATE_ADDRESS) {
>  		/* Set the new address */
>  		u32 new_address = (u32) udc->device_address;
> -		fsl_writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
> +		writel(new_address << USB_DEVICE_ADDRESS_BIT_POS,
>  				&dr_regs->deviceaddr);
>  	}
>  
> @@ -1585,14 +1495,14 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
>  	qh = &udc->ep_qh[ep_num * 2 + EP_DIR_OUT];
>  
>  	/* Clear bit in ENDPTSETUPSTAT */
> -	temp = fsl_readl(&dr_regs->endptsetupstat);
> -	fsl_writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
> +	temp = readl(&dr_regs->endptsetupstat);
> +	writel(temp | (1 << ep_num), &dr_regs->endptsetupstat);
>  
>  	/* while a hazard exists when setup package arrives */
>  	do {
>  		/* Set Setup Tripwire */
> -		temp = fsl_readl(&dr_regs->usbcmd);
> -		fsl_writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
> +		temp = readl(&dr_regs->usbcmd);
> +		writel(temp | USB_CMD_SUTW, &dr_regs->usbcmd);
>  
>  		/* Copy the setup packet to local buffer */
>  		if (pdata->le_setup_buf) {
> @@ -1605,11 +1515,11 @@ static void tripwire_handler(struct fsl_udc *udc, u8 ep_num, u8 *buffer_ptr)
>  		} else {
>  			memcpy(buffer_ptr, (u8 *) qh->setup_buffer, 8);
>  		}
> -	} while (!(fsl_readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
> +	} while (!(readl(&dr_regs->usbcmd) & USB_CMD_SUTW));
>  
>  	/* Clear Setup Tripwire */
> -	temp = fsl_readl(&dr_regs->usbcmd);
> -	fsl_writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
> +	temp = readl(&dr_regs->usbcmd);
> +	writel(temp & ~USB_CMD_SUTW, &dr_regs->usbcmd);
>  }
>  
>  /* process-ep_req(): free the completed Tds for this req */
> @@ -1628,19 +1538,18 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
>  	actual = curr_req->req.length;
>  
>  	for (j = 0; j < curr_req->dtd_count; j++) {
> -		remaining_length = (hc32_to_cpu(curr_td->size_ioc_sts)
> -					& DTD_PACKET_SIZE)
> +		remaining_length = (curr_td->size_ioc_sts & DTD_PACKET_SIZE)
>  				>> DTD_LENGTH_BIT_POS;
>  		actual -= remaining_length;
>  
> -		errors = hc32_to_cpu(curr_td->size_ioc_sts);
> +		errors = curr_td->size_ioc_sts;
>  		if (errors & DTD_ERROR_MASK) {
>  			if (errors & DTD_STATUS_HALTED) {
>  				ERR("dTD error %08x QH=%d\n", errors, pipe);
>  				/* Clear the errors and Halt condition */
> -				tmp = hc32_to_cpu(curr_qh->size_ioc_int_sts);
> +				tmp = curr_qh->size_ioc_int_sts;
>  				tmp &= ~errors;
> -				curr_qh->size_ioc_int_sts = cpu_to_hc32(tmp);
> +				curr_qh->size_ioc_int_sts = cpu_to_le32(tmp);
>  				status = -EPIPE;
>  				/* FIXME: continue with next queued TD? */
>  
> @@ -1658,8 +1567,7 @@ static int process_ep_req(struct fsl_udc *udc, int pipe,
>  				ERR("Unknown error has occurred (0x%x)!\n",
>  					errors);
>  
> -		} else if (hc32_to_cpu(curr_td->size_ioc_sts)
> -				& DTD_STATUS_ACTIVE) {
> +		} else if (curr_td->size_ioc_sts & DTD_STATUS_ACTIVE) {
>  			VDBG("Request not complete");
>  			status = REQ_UNCOMPLETE;
>  			return status;
> @@ -1698,8 +1606,8 @@ static void dtd_complete_irq(struct fsl_udc *udc)
>  	struct fsl_req *curr_req, *temp_req;
>  
>  	/* Clear the bits in the register */
> -	bit_pos = fsl_readl(&dr_regs->endptcomplete);
> -	fsl_writel(bit_pos, &dr_regs->endptcomplete);
> +	bit_pos = readl(&dr_regs->endptcomplete);
> +	writel(bit_pos, &dr_regs->endptcomplete);
>  
>  	if (!bit_pos)
>  		return;
> @@ -1763,10 +1671,10 @@ static void port_change_irq(struct fsl_udc *udc)
>  		udc->bus_reset = 0;
>  
>  	/* Bus resetting is finished */
> -	if (!(fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
> +	if (!(readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET))
>  		/* Get the speed */
>  		udc->gadget.speed =
> -			portscx_device_speed(fsl_readl(&dr_regs->portsc1));
> +			portscx_device_speed(readl(&dr_regs->portsc1));
>  
>  	/* Update USB state */
>  	if (!udc->resume_state)
> @@ -1817,8 +1725,8 @@ static void reset_irq(struct fsl_udc *udc)
>  	unsigned long timeout;
>  
>  	/* Clear the device address */
> -	temp = fsl_readl(&dr_regs->deviceaddr);
> -	fsl_writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
> +	temp = readl(&dr_regs->deviceaddr);
> +	writel(temp & ~USB_DEVICE_ADDRESS_MASK, &dr_regs->deviceaddr);
>  
>  	udc->device_address = 0;
>  
> @@ -1832,15 +1740,15 @@ static void reset_irq(struct fsl_udc *udc)
>  	udc->gadget.a_alt_hnp_support = 0;
>  
>  	/* Clear all the setup token semaphores */
> -	temp = fsl_readl(&dr_regs->endptsetupstat);
> -	fsl_writel(temp, &dr_regs->endptsetupstat);
> +	temp = readl(&dr_regs->endptsetupstat);
> +	writel(temp, &dr_regs->endptsetupstat);
>  
>  	/* Clear all the endpoint complete status bits */
> -	temp = fsl_readl(&dr_regs->endptcomplete);
> -	fsl_writel(temp, &dr_regs->endptcomplete);
> +	temp = readl(&dr_regs->endptcomplete);
> +	writel(temp, &dr_regs->endptcomplete);
>  
>  	timeout = jiffies + 100;
> -	while (fsl_readl(&dr_regs->endpointprime)) {
> +	while (readl(&dr_regs->endpointprime)) {
>  		/* Wait until all endptprime bits cleared */
>  		if (time_after(jiffies, timeout)) {
>  			ERR("Timeout for reset\n");
> @@ -1850,9 +1758,9 @@ static void reset_irq(struct fsl_udc *udc)
>  	}
>  
>  	/* Write 1s to the flush register */
> -	fsl_writel(0xffffffff, &dr_regs->endptflush);
> +	writel(0xffffffff, &dr_regs->endptflush);
>  
> -	if (fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
> +	if (readl(&dr_regs->portsc1) & PORTSCX_PORT_RESET) {
>  		VDBG("Bus reset");
>  		/* Bus is reseting */
>  		udc->bus_reset = 1;
> @@ -1891,22 +1799,22 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
>  	if (udc->stopped)
>  		return IRQ_NONE;
>  	spin_lock_irqsave(&udc->lock, flags);
> -	irq_src = fsl_readl(&dr_regs->usbsts) & fsl_readl(&dr_regs->usbintr);
> +	irq_src = readl(&dr_regs->usbsts) & readl(&dr_regs->usbintr);
>  	/* Clear notification bits */
> -	fsl_writel(irq_src, &dr_regs->usbsts);
> +	writel(irq_src, &dr_regs->usbsts);
>  
>  	/* VDBG("irq_src [0x%8x]", irq_src); */
>  
>  	/* Need to resume? */
>  	if (udc->usb_state == USB_STATE_SUSPENDED)
> -		if ((fsl_readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
> +		if ((readl(&dr_regs->portsc1) & PORTSCX_PORT_SUSPEND) == 0)
>  			bus_resume(udc);
>  
>  	/* USB Interrupt */
>  	if (irq_src & USB_STS_INT) {
>  		VDBG("Packet int");
>  		/* Setup package, we only support ep0 as control ep */
> -		if (fsl_readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
> +		if (readl(&dr_regs->endptsetupstat) & EP_SETUP_STATUS_EP0) {
>  			tripwire_handler(udc, 0,
>  					(u8 *) (&udc->local_setup_buff));
>  			setup_received_irq(udc, &udc->local_setup_buff);
> @@ -1914,7 +1822,7 @@ static irqreturn_t fsl_udc_irq(int irq, void *_udc)
>  		}
>  
>  		/* completion of dtd */
> -		if (fsl_readl(&dr_regs->endptcomplete)) {
> +		if (readl(&dr_regs->endptcomplete)) {
>  			dtd_complete_irq(udc);
>  			status = IRQ_HANDLED;
>  		}
> @@ -2076,7 +1984,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	next += t;
>  
>  	/* ------ DR Registers ----- */
> -	tmp_reg = fsl_readl(&dr_regs->usbcmd);
> +	tmp_reg = readl(&dr_regs->usbcmd);
>  	t = scnprintf(next, size,
>  			"USBCMD reg:\n"
>  			"SetupTW: %d\n"
> @@ -2086,7 +1994,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->usbsts);
> +	tmp_reg = readl(&dr_regs->usbsts);
>  	t = scnprintf(next, size,
>  			"USB Status Reg:\n"
>  			"Dr Suspend: %d Reset Received: %d System Error: %s "
> @@ -2098,7 +2006,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->usbintr);
> +	tmp_reg = readl(&dr_regs->usbintr);
>  	t = scnprintf(next, size,
>  			"USB Intrrupt Enable Reg:\n"
>  			"Sleep Enable: %d SOF Received Enable: %d "
> @@ -2116,21 +2024,21 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->frindex);
> +	tmp_reg = readl(&dr_regs->frindex);
>  	t = scnprintf(next, size,
>  			"USB Frame Index Reg: Frame Number is 0x%x\n\n",
>  			(tmp_reg & USB_FRINDEX_MASKS));
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->deviceaddr);
> +	tmp_reg = readl(&dr_regs->deviceaddr);
>  	t = scnprintf(next, size,
>  			"USB Device Address Reg: Device Addr is 0x%x\n\n",
>  			(tmp_reg & USB_DEVICE_ADDRESS_MASK));
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->endpointlistaddr);
> +	tmp_reg = readl(&dr_regs->endpointlistaddr);
>  	t = scnprintf(next, size,
>  			"USB Endpoint List Address Reg: "
>  			"Device Addr is 0x%x\n\n",
> @@ -2138,7 +2046,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->portsc1);
> +	tmp_reg = readl(&dr_regs->portsc1);
>  	t = scnprintf(next, size,
>  		"USB Port Status&Control Reg:\n"
>  		"Port Transceiver Type : %s Port Speed: %s\n"
> @@ -2177,7 +2085,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->usbmode);
> +	tmp_reg = readl(&dr_regs->usbmode);
>  	t = scnprintf(next, size,
>  			"USB Mode Reg: Controller Mode is: %s\n\n", ( {
>  				char *s;
> @@ -2196,7 +2104,7 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	size -= t;
>  	next += t;
>  
> -	tmp_reg = fsl_readl(&dr_regs->endptsetupstat);
> +	tmp_reg = readl(&dr_regs->endptsetupstat);
>  	t = scnprintf(next, size,
>  			"Endpoint Setup Status Reg: SETUP on ep 0x%x\n\n",
>  			(tmp_reg & EP_SETUP_STATUS_MASK));
> @@ -2204,13 +2112,13 @@ static int fsl_proc_read(char *page, char **start, off_t off, int count,
>  	next += t;
>  
>  	for (i = 0; i < udc->max_ep / 2; i++) {
> -		tmp_reg = fsl_readl(&dr_regs->endptctrl[i]);
> +		tmp_reg = readl(&dr_regs->endptctrl[i]);
>  		t = scnprintf(next, size, "EP Ctrl Reg [0x%x]: = [0x%x]\n",
>  				i, tmp_reg);
>  		size -= t;
>  		next += t;
>  	}
> -	tmp_reg = fsl_readl(&dr_regs->endpointprime);
> +	tmp_reg = readl(&dr_regs->endpointprime);
>  	t = scnprintf(next, size, "EP Prime Reg = [0x%x]\n\n", tmp_reg);
>  	size -= t;
>  	next += t;
> @@ -2473,9 +2381,6 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  		goto err_iounmap_noclk;
>  	}
>  
> -	/* Set accessors only after pdata->init() ! */
> -	fsl_set_accessors(pdata);
> -
>  #ifndef CONFIG_ARCH_MXC
>  	if (pdata->have_sysif_regs)
>  		usb_sys_regs = (void *)dr_regs + USB_DR_SYS_OFFSET;
> @@ -2487,7 +2392,7 @@ static int __init fsl_udc_probe(struct platform_device *pdev)
>  		goto err_iounmap_noclk;
>  
>  	/* Read Device Controller Capability Parameters register */
> -	dccparams = fsl_readl(&dr_regs->dccparams);
> +	dccparams = readl(&dr_regs->dccparams);
>  	if (!(dccparams & DCCPARAMS_DC)) {
>  		ERR("This SOC doesn't support device role\n");
>  		ret = -ENODEV;
> @@ -2682,7 +2587,7 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  	struct fsl_udc *udc = container_of(dev, struct fsl_udc, gadget.dev);
>  	u32 mode, usbcmd;
>  
> -	mode = fsl_readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
> +	mode = readl(&dr_regs->usbmode) & USB_MODE_CTRL_MODE_MASK;
>  
>  	pr_debug("%s(): mode 0x%x stopped %d\n", __func__, mode, udc->stopped);
>  
> @@ -2703,8 +2608,8 @@ static int fsl_udc_otg_suspend(struct device *dev, pm_message_t state)
>  	}
>  
>  	/* stop the controller */
> -	usbcmd = fsl_readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
> -	fsl_writel(usbcmd, &dr_regs->usbcmd);
> +	usbcmd = readl(&dr_regs->usbcmd) & ~USB_CMD_RUN_STOP;
> +	writel(usbcmd, &dr_regs->usbcmd);
>  
>  	udc->stopped = 1;
>  
> -- 
> 1.7.2.5
> 

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
  2012-10-19 10:24                                     ` [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD Christoph Fritz
@ 2012-10-19 10:30                                       ` Felipe Balbi
  2012-10-19 10:46                                         ` Christoph Fritz
  0 siblings, 1 reply; 42+ messages in thread
From: Felipe Balbi @ 2012-10-19 10:30 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Felipe Balbi,
	Hans J. Koch, Daniel Mack, Christian Hemp, linuxppc-dev,
	Teresa Gamez, Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 894 bytes --]

On Fri, Oct 19, 2012 at 12:24:43PM +0200, Christoph Fritz wrote:
> USB controller may access a wrong address for the dTD (endpoint transfer
> descriptor) and then hang. This happens a lot when doing tests with
> g_ether module and iperf, a tool for measuring maximum TCP and UDP
> bandwidth.
> 
> This hardware bug is explained in detail by errata number 2858 for i.MX23:
> http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> 
> All (?) SOCs with an IP from chipidea suffer from this problem.
> mv_udc_core fixes this bug by commit daec765.  There still may be
> unfixed drivers.

why aren't you using that driver instead ? Is it really necessary to
keep this driver around ? I would really like to see uniformization
towards that, if you use the same IP, then the same driver ought to
suffice.

What's the reason for not using drivers/usb/chipidea ?

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
  2012-10-19 10:46                                         ` Christoph Fritz
@ 2012-10-19 10:44                                           ` Felipe Balbi
  2012-10-20 19:12                                             ` Christoph Fritz
  0 siblings, 1 reply; 42+ messages in thread
From: Felipe Balbi @ 2012-10-19 10:44 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, balbi, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 1334 bytes --]

Hi,

On Fri, Oct 19, 2012 at 12:46:48PM +0200, Christoph Fritz wrote:
> On Fri, 2012-10-19 at 13:30 +0300, Felipe Balbi wrote:
> > On Fri, Oct 19, 2012 at 12:24:43PM +0200, Christoph Fritz wrote:
> > > USB controller may access a wrong address for the dTD (endpoint transfer
> > > descriptor) and then hang. This happens a lot when doing tests with
> > > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > > bandwidth.
> > > 
> > > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > > 
> > > All (?) SOCs with an IP from chipidea suffer from this problem.
> > > mv_udc_core fixes this bug by commit daec765.  There still may be
> > > unfixed drivers.
> > 
> > why aren't you using that driver instead ? Is it really necessary to
> > keep this driver around ? I would really like to see uniformization
> > towards that, if you use the same IP, then the same driver ought to
> > suffice.
> > 
> > What's the reason for not using drivers/usb/chipidea ?
> > 
> 
> I thought about this too but wasn't able to use chipidea with
> MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.

that's a matter of writing the PHY driver, right ;-) It has nothing to
do with chipidea, actually :-)

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
  2012-10-19 10:30                                       ` Felipe Balbi
@ 2012-10-19 10:46                                         ` Christoph Fritz
  2012-10-19 10:44                                           ` Felipe Balbi
  0 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-19 10:46 UTC (permalink / raw)
  To: balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

On Fri, 2012-10-19 at 13:30 +0300, Felipe Balbi wrote:
> On Fri, Oct 19, 2012 at 12:24:43PM +0200, Christoph Fritz wrote:
> > USB controller may access a wrong address for the dTD (endpoint transfer
> > descriptor) and then hang. This happens a lot when doing tests with
> > g_ether module and iperf, a tool for measuring maximum TCP and UDP
> > bandwidth.
> > 
> > This hardware bug is explained in detail by errata number 2858 for i.MX23:
> > http://cache.freescale.com/files/dsp/doc/errata/IMX23CE.pdf
> > 
> > All (?) SOCs with an IP from chipidea suffer from this problem.
> > mv_udc_core fixes this bug by commit daec765.  There still may be
> > unfixed drivers.
> 
> why aren't you using that driver instead ? Is it really necessary to
> keep this driver around ? I would really like to see uniformization
> towards that, if you use the same IP, then the same driver ought to
> suffice.
> 
> What's the reason for not using drivers/usb/chipidea ?
> 

I thought about this too but wasn't able to use chipidea with
MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.

Sascha, do you know if i.mx35 works with usb/chipidea?

Thanks
 -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 0/7] update USB gadget driver fsl-usb2-udc
  2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
                                                       ` (6 preceding siblings ...)
  2012-10-19 10:24                                     ` [PATCH 7/7] usb: gadget: fsl_udc: purge global pointer dr_regs Christoph Fritz
@ 2012-10-19 15:36                                     ` Sascha Hauer
  7 siblings, 0 replies; 42+ messages in thread
From: Sascha Hauer @ 2012-10-19 15:36 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sebastian Andrzej Siewior, linux-usb,
	Felipe Balbi, Hans J. Koch, Daniel Mack, Christian Hemp,
	linuxppc-dev, Teresa Gamez

Hi Christoph,

What system are you working on? If it's i.MX you should use/work on the
chipidea driver instead.

Sascha

On Fri, Oct 19, 2012 at 12:22:36PM +0200, Christoph Fritz wrote:
> This series updates USB gadget driver fsl-usb2-udc.
> 
> Christoph Fritz (7):
>   usb: gadget: fsl_udc: simplify driver init
>   usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock
>   usb: gadget: fsl_udc: convert to new ulc style
>   usb: gadget: fsl_udc: drop ARCH dependency
>   usb: gadget: fsl_udc: postpone freeing current dTD
>   usb: gadget: fsl_udc: purge global pointer usb_sys_regs
>   usb: gadget: fsl_udc: purge global pointer dr_regs
> 
>  drivers/usb/gadget/fsl_udc_core.c |  755 ++++++++++++++++---------------------
>  drivers/usb/gadget/fsl_usb2_udc.h |    4 +
>  2 files changed, 322 insertions(+), 437 deletions(-)
> 
> -- 
> 1.7.2.5
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
  2012-10-19 10:44                                           ` Felipe Balbi
@ 2012-10-20 19:12                                             ` Christoph Fritz
  2012-10-22  7:54                                               ` Felipe Balbi
  0 siblings, 1 reply; 42+ messages in thread
From: Christoph Fritz @ 2012-10-20 19:12 UTC (permalink / raw)
  To: balbi
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

On Fri, 2012-10-19 at 13:44 +0300, Felipe Balbi wrote:
> > I thought about this too but wasn't able to use chipidea with
> > MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.
> 
> that's a matter of writing the PHY driver, right ;-) It has nothing to
> do with chipidea, actually :-)

Okay, I'll do. But then we should purge the old buggy fsl_udc.

 Thanks
   -- Christoph

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD
  2012-10-20 19:12                                             ` Christoph Fritz
@ 2012-10-22  7:54                                               ` Felipe Balbi
  0 siblings, 0 replies; 42+ messages in thread
From: Felipe Balbi @ 2012-10-22  7:54 UTC (permalink / raw)
  To: Christoph Fritz
  Cc: Estevam Fabio-R49496, Li Yang-R58472, Greg Kroah-Hartman,
	Chen Peter-B29397, Sascha Hauer, linux-usb, balbi, Hans J. Koch,
	Daniel Mack, Christian Hemp, linuxppc-dev, Teresa Gamez,
	Sebastian Andrzej Siewior

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

Hi,

On Sat, Oct 20, 2012 at 09:12:27PM +0200, Christoph Fritz wrote:
> On Fri, 2012-10-19 at 13:44 +0300, Felipe Balbi wrote:
> > > I thought about this too but wasn't able to use chipidea with
> > > MXC_EHCI_INTERNAL_PHY as it's called in fsl_udc.
> > 
> > that's a matter of writing the PHY driver, right ;-) It has nothing to
> > do with chipidea, actually :-)
> 
> Okay, I'll do. But then we should purge the old buggy fsl_udc.

I'm all for that. We shouldn't have multiple copies of a single driver
hanging around.

cheers

-- 
balbi

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2012-10-22  8:00 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1333796272.3450.92.camel@lovely>
     [not found] ` <F281D0F91ED19E4D8E63A7504E8A64980AFFE3@039-SN2MPN1-022.039d.mgd.msft.net>
     [not found]   ` <CAOMZO5AjQsNw7_4ETkB38mmuBXj4pnCwJwAsi4zC4b_83=Enfw@mail.gmail.com>
     [not found]     ` <20120409200656.GD2640@local>
     [not found]       ` <CAOMZO5BTrA8G6wwQZ3e6bydJX7UtG7jj2c29Ln7u_3_jyUGB+w@mail.gmail.com>
     [not found]         ` <20120410001017.GF2640@local>
     [not found]           ` <CAOMZO5A=sHeyoQ0PCd=09qGGKb0NjXi-kF5qyG+3U-GhD7rhzg@mail.gmail.com>
     [not found]             ` <20120410021151.GB23044@lovely.krouter>
     [not found]               ` <20120411073918.GA9180@lovely.krouter>
     [not found]                 ` <CAOMZO5C729Ki0Bequ+s1nnrgt4NZWvwg3Wnjk4kHp=d9BtkeXw@mail.gmail.com>
2012-05-09  0:02                   ` [RFC] [PATCH] usb: gadget: fix dtd dma confusion Christoph Fritz
2012-05-09  1:50                     ` Neil Zhang
2012-05-09  2:11                       ` Chen Peter-B29397
2012-05-09  5:38                         ` Christoph Fritz
2012-05-09  5:43                           ` Chen Peter-B29397
2012-05-09  5:56                             ` Christoph Fritz
2012-05-09  5:45                           ` Neil Zhang
2012-05-09  6:04                             ` Christoph Fritz
2012-05-13 22:51                     ` Christoph Fritz
2012-05-14  1:11                       ` Chen Peter-B29397
2012-05-14  4:21                       ` Greg Kroah-Hartman
2012-05-20 23:17                         ` [PATCH] usb: fsl_udc: errata - postpone freeing current dTD Christoph Fritz
2012-05-21  1:05                           ` Chen Peter-B29397
2012-05-21  6:53                             ` Christoph Fritz
2012-05-21  6:57                               ` [PATCH v2] " Christoph Fritz
2012-05-21  7:25                                 ` Chen Peter-B29397
2012-05-21 19:04                                 ` Felipe Balbi
2012-06-04 11:30                                   ` Christoph Fritz
2012-06-04 11:37                                     ` Christoph Fritz
2012-06-10 18:41                                       ` Fabio Estevam
2012-06-12 19:40                                         ` Christoph Fritz
2012-06-13  1:17                                           ` Fabio Estevam
2012-06-04 14:59                                     ` Felipe Balbi
2012-06-04 15:24                                       ` [PATCH] usb: gadget: regression fix - useage of usb_ep Christoph Fritz
2012-10-19 10:22                                   ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Christoph Fritz
2012-10-19 10:24                                     ` [PATCH 1/7] usb: gadget: fsl_udc: simplify driver init Christoph Fritz
2012-10-19 10:24                                       ` Felipe Balbi
2012-10-19 10:24                                     ` [PATCH 2/7] usb: gadget: fsl_udc: protect fsl_pullup() with spin_lock Christoph Fritz
2012-10-19 10:25                                       ` Felipe Balbi
2012-10-19 10:24                                     ` [PATCH 3/7] usb: gadget: fsl_udc: convert to new ulc style Christoph Fritz
2012-10-19 10:27                                       ` Felipe Balbi
2012-10-19 10:24                                     ` [PATCH 4/7] usb: gadget: fsl_udc: drop ARCH dependency Christoph Fritz
2012-10-19 10:29                                       ` Felipe Balbi
2012-10-19 10:24                                     ` [PATCH 5/7] usb: gadget: fsl_udc: postpone freeing current dTD Christoph Fritz
2012-10-19 10:30                                       ` Felipe Balbi
2012-10-19 10:46                                         ` Christoph Fritz
2012-10-19 10:44                                           ` Felipe Balbi
2012-10-20 19:12                                             ` Christoph Fritz
2012-10-22  7:54                                               ` Felipe Balbi
2012-10-19 10:24                                     ` [PATCH 6/7] usb: gadget: fsl_udc: purge global pointer usb_sys_regs Christoph Fritz
2012-10-19 10:24                                     ` [PATCH 7/7] usb: gadget: fsl_udc: purge global pointer dr_regs Christoph Fritz
2012-10-19 15:36                                     ` [PATCH 0/7] update USB gadget driver fsl-usb2-udc Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).