Newer
Older
/*
* Most of this source has been derived from the Linux USB
* project:
* (C) Copyright Linus Torvalds 1999
* (C) Copyright Johannes Erdfelt 1999-2001
* (C) Copyright Andreas Gal 1999
* (C) Copyright Gregory P. Smith 1999
* (C) Copyright Deti Fliegl 1999 (new USB architecture)
* (C) Copyright Randy Dunlap 2000
* (C) Copyright David Brownell 2000 (kernel hotplug, usb_device_id)
* (C) Copyright Yggdrasil Computing, Inc. 2000
* (usb_device_id matching changes by Adam J. Richter)
*
* Adapted for U-Boot:
* (C) Copyright 2001 Denis Peter, MPL AG Switzerland
* SPDX-License-Identifier: GPL-2.0+
*/
/*
* How it works:
*
* Since this is a bootloader, the devices will not be automatic
* (re)configured on hotplug, but after a restart of the USB the
* device should work.
*
* For each transfer (except "Interrupt") we wait for completion.
*/
#include <common.h>
#include <command.h>
#include <asm/processor.h>
#include <linux/ctype.h>
#include <asm/byteorder.h>
#include <asm/unaligned.h>
#include <asm/4xx_pci.h>
static struct usb_device usb_dev[USB_MAX_DEVICE];
static int dev_index;
static int asynch_allowed;
char usb_started; /* flag for the started/stopped USB status */
#ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
#define CONFIG_USB_MAX_CONTROLLER_COUNT 1
#endif
/***************************************************************************
* Init USB Device
*/
int usb_init(void)
{
void *ctrl;
struct usb_device *dev;
int i, start_index = 0;
Hans de Goede
committed
int controllers_initialized = 0;
dev_index = 0;
asynch_allowed = 1;
/* first make all devices unknown */
for (i = 0; i < USB_MAX_DEVICE; i++) {
memset(&usb_dev[i], 0, sizeof(struct usb_device));
usb_dev[i].devnum = -1;
}
for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
/* init low_level USB */
printf("USB%d: ", i);
ret = usb_lowlevel_init(i, USB_INIT_HOST, &ctrl);
if (ret == -ENODEV) { /* No such device. */
puts("Port not available.\n");
Hans de Goede
committed
controllers_initialized++;
continue;
}
if (ret) { /* Other error. */
puts("lowlevel init failed\n");
continue;
}
/*
* lowlevel init is OK, now scan the bus for devices
* i.e. search HUBs and configure them
*/
Hans de Goede
committed
controllers_initialized++;
start_index = dev_index;
printf("scanning bus %d for devices... ", i);
dev = usb_alloc_new_device(ctrl);
/*
* device 0 is always present
* (root hub, so let it analyze)
*/
if (dev)
usb_new_device(dev);
if (start_index == dev_index)
puts("No USB Device found\n");
else
printf("%d USB Device(s) found\n",
dev_index - start_index);
usb_started = 1;
debug("scan end\n");
/* if we were not able to find at least one working bus, bail out */
Hans de Goede
committed
if (controllers_initialized == 0)
puts("USB error: all controllers failed lowlevel init\n");
Hans de Goede
committed
return usb_started ? 0 : -1;
}
/******************************************************************************
* Stop USB this stops the LowLevel Part and deregisters USB devices.
*/
int usb_stop(void)
{
if (usb_started) {
asynch_allowed = 1;
usb_started = 0;
usb_hub_reset();
for (i = 0; i < CONFIG_USB_MAX_CONTROLLER_COUNT; i++) {
if (usb_lowlevel_stop(i))
printf("failed to stop USB controller %d\n", i);
}
}
/*
* disables the asynch behaviour of the control message. This is used for data
* transfers that uses the exclusiv access to the control and bulk messages.
* Returns the old value so it can be restored later.
}
/*-------------------------------------------------------------------
* Message wrappers.
*
*/
/*
* submits an Interrupt Message
*/
int usb_submit_int_msg(struct usb_device *dev, unsigned long pipe,
void *buffer, int transfer_len, int interval)
return submit_int_msg(dev, pipe, buffer, transfer_len, interval);
}
/*
* submits a control message and waits for comletion (at least timeout * 1ms)
* If timeout is 0, we don't wait for completion (used as example to set and
* clear keyboards LEDs). For data transfers, (storage transfers) we don't
* allow control messages with 0 timeout, by previousely resetting the flag
* asynch_allowed (usb_disable_asynch(1)).
* returns the transfered length if OK or -1 if error. The transfered length
* and the current status are stored in the dev->act_len and dev->status.
*/
int usb_control_msg(struct usb_device *dev, unsigned int pipe,
unsigned char request, unsigned char requesttype,
unsigned short value, unsigned short index,
void *data, unsigned short size, int timeout)
{
ALLOC_CACHE_ALIGN_BUFFER(struct devrequest, setup_packet, 1);
if ((timeout == 0) && (!asynch_allowed)) {
/* request for a asynch control pipe is not allowed */
setup_packet->requesttype = requesttype;
setup_packet->request = request;
setup_packet->value = cpu_to_le16(value);
setup_packet->index = cpu_to_le16(index);
setup_packet->length = cpu_to_le16(size);
debug("usb_control_msg: request: 0x%X, requesttype: 0x%X, " \
"value 0x%X index 0x%X length 0x%X\n",
request, requesttype, value, index, size);
Loading
Loading full blame…