USB Cannot Detect Device Attachment

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

USB Cannot Detect Device Attachment

Post by neato »

In reference to: http://download.intel.com/technology/usb/UHCI11D.pdf & USB 1.1.

I first scan the PCI bus until I find the USB Controller with an Interface of UHCI using an I/O Address. I have two on this machine. My hopes are that when I attach a drive, that my hdc_dev_attach() function will detect it by checking that bit 0 and bit 1 (PRTSC1 & PRTSC2, see UHCI11D.pdf: "USB I/O Registers") are both 1. In VMWare, they are always set to 1, even when no device is attached. On real hardware, they are never one, but always zero. I have checked that my I/O Address is correct (0x20C0) and I am reading a WORD from I/O Address Base+0x10 & Base+0x20 with absolutely no luck. I have tried to reset the HC, I tried to reset and then enable the port, and when I just print the PRTSC1 & PRTSC2 register in VMWARE the return is always 0x83, and on real hardware it is always 0x80; those values never change no matter if the device is attached or detached at anytime, no matter if I enable or disable the ports or reset the HC. I am at a total loss here. Any ideas?
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: USB Cannot Detect Device Attachment

Post by XanClic »

Did you switch off the legacy support? This is necessary in order to detect devices on real hardware (it took me a long time to discover that...).
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

Re: USB Cannot Detect Device Attachment

Post by neato »

OK, I will try to disable SMI and post back if I run into any more trouble. Thanks
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: USB Cannot Detect Device Attachment

Post by XanClic »

Disabling SMI is not enough (though necessary)---you have to disable all the legacy support (see section 5.2 of the specification for more information about the according registers, or have a look into the linux code if you're writing a GPL'ed OS).
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: USB Cannot Detect Device Attachment

Post by Dex »

Here is what i have found, if you have no EHCI the code works fine, but with it you need switch to UHCI .
If you get my os, there a USB test app (its on the download site as usb.zip) that beeps when a usb device is pluged in and out.
This does not have the fix, so if it works you do not need to do the next bit, on your PC.
See this topic to how to fix the problem:
http://forum.osdev.org/viewtopic.php?f= ... hilit=EHCI
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

Re: USB Cannot Detect Device Attachment

Post by neato »

From OSDEV WIKI: USB - "The host queries more information from the hub to determine that a device has been attached, and to which port." (USB Device Enumeration)

Can someone elaborate on this a little more? What registers does it check, which bits, etc?

What I have done: (pseudo)

Code: Select all

//pci.c
function pci_enum()
{
    if(!find_uhci())
    {
		return FAIL;
    }
    /*UHCI FOUND*/
	fill_uhci_struct();
	turn_on_hdc_timer();
}

//timer.c
function hdc_timer()
{
	if(ticks==WAIT)
	{
		if(check_status_port01()) { hdc_dev_attach(port01); } else { hdc_dev_detach(port01); }
		if(check_status_port02()) { hdc_dev_attach(port02); } else { hdc_dev_detach(port02); }
	}
}

//hdc.c
function check_status_port01()
{
	i=readpci32(PRTSC1);
	if(i & 0x01) { return OK; } else { return FAIL; }
}

function check_status_port02()
{
	i=readpci32(PRTSC2);
	if(i & 0x01) { return OK; } else { return FAIL; }
}
Returns:
function check_status_port01->i->vmware = 0x83
function check_status_port02->i->vmware = 0x83
function check_status_port01->i->real = was 0x80, now unknown
function check_status_port02->i->real = was 0x80, now unknown

I am writing this driver in stages, it's much too difficult to think of it in the "big picture". I have the PCI driver, my Timer, and a part of the HDC written. Right now, I am focusing on the UHCI and trying to detect when a device is attached to a port with power. I want to know which controller and port, because I have two UHCI controllers on this machine. I have prepared my structs accordingly to handle that. My results are still the same, in VMWare, I receive Status 0x83, ALWAYS, no matter what happens. On real hardware, I was getting 0x80, but now (the last time I checked) I am not able to detect the UHCI controllers... lol.. it's a nightmare. I have a feeling it is an alignment issue, but I can deal with that. I just need help detecting when a device has been attached and detached from its port. So, please pseudo code, steps, advice, suggestions, all needed. Thanks in advance.

P.s. Dex, I'll take a look at your example. Thanks
User avatar
XanClic
Member
Member
Posts: 138
Joined: Wed Feb 13, 2008 9:38 am

Re: USB Cannot Detect Device Attachment

Post by XanClic »

I can't help you on finding the UHCI, but did you try to disable SMI (specification states clearly how to do that, afair) and legacy mode? If not, it's no miracle that real hardware doesn't show you any attached devices (as I stated above).

Your code seems to do neither one of those.
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

Re: USB Cannot Detect Device Attachment

Post by neato »

Hi, I did, but I may have gotten it wrong. The document seems to state that the Legacy register is mostly disabled by default, but I did this anyway:

Code: Select all

i=pciread32(0xc0);
i&=0x2000;
pciwrite32(0xC0,i);
I can find the UHCI again, but haven't gotten to test if the port status is correct as my fix for the pci driver broke my hdc. Let me know if I am missing something on the Legacy disable code. It seems right. Thanks
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

Re: USB Cannot Detect Device Attachment [SOLVED]

Post by neato »

I finally got it working! It is detecting the detachment and attachment of devices from both controllers on both ports on real hardware! It was a combination of timing and alignment which once corrected solved my issue. Thanks XanClic and Dex for offering up some help.

Steps to Configure Device (UHCI):
00. Disable Legacy [see UHCI11D.pdf - "USB I/O Registers"]
01. Reset the HC by setting b2 to 1 and wait 100 ms
02. Reset both ports (0x10 & 0x12) [see UHCI11D.pdf - "USB I/O Registers"] and wait 100 ms
03. Read both the PORTSC1 and PORTSC2 registers b0 and b1. 0x01=Disconnected, 0x11=Connected

Hope this helps.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Re: USB Cannot Detect Device Attachment

Post by Dex »

As a side note to this topic, some codes may find this link useful
http://www.fysnet.net/hugi/compoold.htm

NOTE: See the "Hugi Size Coding Competition #28 - The "Hugi USB" Compo "
neato
Member
Member
Posts: 75
Joined: Fri Jan 15, 2010 2:46 am

Re: USB Cannot Detect Device Attachment

Post by neato »

That example should be made into a tutorial. Great find! =D>
Post Reply