mini2440 not working as usb device

Fabio
Guys,

I need to configure mini2440 to work as an Ethernet gadget, that is, a
device that when connected with a PC through a USB A-B cable (the one used
by printers) works as an Ethernet node with the host. 

I searched many sites to discover how to do that and I found out that all I
needed to do was to enable three configurations at mini2440 Linux kernel



1) CONFIG_USB_GADGET to indicate to kernel that this will be a USB gadget


2) CONFIG_USB_GADGET_S3C2410 to compile the driver for the USB Device
Controller found at s3c2440 chip. S3C2410 is correct, as we can see at the
first lines of u-boot execution:

U-Boot 1.3.2-mini2440 (Mar  5 2012 - 08:19:46)

I2C:   ready
DRAM:  64 MB
NOR Flash not found. Use hardware switch and 'flinit'
Flash:  0 kB
NAND:  128 MiB
Found Environment offset in OOB..
USB:   S3C2410 USB Deviced


3) CONFIG_USB_ETH to compile the g_ether module, the driver that makes it
behave as a Ethernet USB gadget (I tried this as module and statically as
well)



I did it, I could configure mini2440 to have an IP address at the usb0
interface, so I'm ok with this. 

However, when I connect to PC and try to configure the other end, it shows
me:

$ sudo ifconfig usb0 192.168.254.2
SIOCSIFADDR: No such device
usb0: ERROR while getting interface flags: No such device



I tried running "lsusb" at host and found out it does not show up the
device. Not even if I do a loopback, linking mini2440 USB host with
mini2440 USB device. Some messages during kernel load made me think that
perhaps USB Device Controller is not enabled at s3c2440 chip. Two ports
were detected at the same hub: 


hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected



Looking at the s3c2440 data sheet I found out that there is a MISCCR
register that controls the configuration of the second USB port - whether
it is a host or device (it is in page 298 of the datasheet). I tried
forcing the SEL_USBPAD bit to be "0" (that makes it be a device) but the
kernel kept showing those messages and lsusb raised the same results. 


Do you have any ideas of what else can be tried here? 

Thanks!

Fabio
I've got to the solution. It is hard to understand what do we need to do to
enable USB Device using the USB_ENABLE pin using only the FriendlyARM
documentation. But here it goes. Don't mess up with MISCCR, it is correct.
The drivers compilation is also correct. 

Actually we need to do two operations to change the state of USB_ENABLE
pin, more specifically at the GPCCON and GPCDAT registers. See s3c2440
datasheet for more information about them. 

GPCCON is for configuration only: in the GPC port the pins can perform as
Input (00), Output(01) or their factory specific role (10). The
configuration (11) is reserved. So what we need to do is to configure the
two bits that relate to USB_ENABLE pin (GPC5) to "01". This way we will be
free to output data to bus through it. 

Then we are able to write to GPCDAT. If we assign "1" to the bit in GPCDAT
that corresponds to GPC5 it will raise the electrical voltage of this pin
to 3.3V and the USB Device will enable. 

Those operations can be done both in kernel, calling gpio related functions
available in the kernel platform s3c24XX folder or at the user mode,
following the LED example of E.L.L.K. 

Hope this help.