Commit Graph

29639 Commits

Author SHA1 Message Date
Simon Glass 0566e2403d dm: usb: Allow USB drivers to be declared and auto-probed
USB devices in U-Boot are currently probed only after all devices have
been enumerated. Each type of device is probed by custom code, e.g.:

- USB storage
- Keyboard
- Ethernet

With driver model this approach doesn't work very well. We could build
a picture of the bus and then go back and add the devices later, but
this means that the data structures are incomplete for quite a while.
It also does not follow the model of being able to bind a device when we
discover it.

We would prefer to have devices automatically be bound as the device is
enumerated. This allows us to attach drivers to particular USB classes
or product/vendor IDs. This is the method used by Linux.

Add the required #defines from Linux, a way of declaring a USB driver and
the logic to locate the correct driver given the USB device's descriptors.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:25 -06:00
Simon Glass 46b01797f4 dm: usb: Add driver model support to EHCI
Add a way for EHCI controller drivers to support driver model. Drivers can
call ehci_register() to register themselves in their probe() methods.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:25 -06:00
Simon Glass aeca43e388 dm: usb: Change ehci_reset() to use a pointer
The index cannot be used with driver model, and isn't needed anyway. Change
the parameter to a pointer.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:24 -06:00
Simon Glass deb8508c51 dm: usb: Drop the EHCI weak functions
These are a pain with driver model because we might have different EHCI
drivers which want to implement them differently. Now that they use
consistent function signatures, we can in good conscience move them to
a struct.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
Fix non-driver-model EHCI to set up the EHCI operations correctly:
Signed-off-by: Tom Rini <trini@konsulko.com>
2015-04-18 11:11:24 -06:00
Simon Glass 7372b5bd31 dm: usb: Refactor EHCI init
Move the bulk of the code in usb_lowlevel_init() into a separate function
which will also be used by driver model. Keep the CONFIG options out of
this function by providing a tweak flag for Faraday. We need to avoid using
CONFIG options in driver model code where possible, since it makes it
impossible to use multiple controllers in that code where they have
different options.

The CONFIG_EHCI_HCD_INIT_AFTER_RESET option is also kept out of the
common init function. With driver model the controller will be able to
perform this extra init itself after registering with the EHCI layer.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:24 -06:00
Simon Glass 24ed894fc0 dm: usb: ehci: Use a function to find the controller from struct udevice
With driver model we want to remove the controller pointer in struct udevice
and use driver model data structures instead. To prepare for this, move
access to this field to a function which can provide a different
implementation for driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:24 -06:00
Simon Glass 6a1a8162c6 dm: usb: Pass EHCI controller pointer to ehci_get_portsc_register()
Adjust this function so that it is passed an EHCI controller pointer so that
implementations can look up their controller. This makes the weak functions
use a consistent API.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:24 -06:00
Simon Glass 11d18a1946 dm: usb: Pass EHCI controller pointer to ehci_set_usbmode()
Adjust this function so that it is passed an EHCI controller pointer so that
implementations can look up their controller. This makes the weak functions
use a consistent API.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:24 -06:00
Simon Glass 56d4273045 dm: usb: tegra: Drop use of global controller variable
We don't need this anymore, so adjust the code to avoid using it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass 727fce369e dm: usb: Pass EHCI controller pointer to ehci_powerup_fixup()
Adjust this function so that it is passed an EHCI controller pointer so that
implementations can look up their controller.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass 27f782b6a1 dm: usb: tegra: Store the controller type explicitly
At present the tegra driver uses a separate pointer to know which controller
type is in use. This works because only one controller type is used at a
time.

With driver model we want to make the controller state hermetic in the sense
that it is not necessary to look elsewhere to know the controller type. This
will permit a controller to implement the EHCI weak functions without
reference to global data structures.

To achieve this, define an enum for the controller type and store it with
the information on each EHCI controller.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass c4a3141d55 dm: usb: Allow ECHI to hold private data for the controller
Add a private data pointer that clients of EHCI can use to access their
private information. This establishes a link between struct ehci_ctrl and
its associated controller data structure.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass 7338287d58 dm: usb: Pass EHCI controller pointer to ehci_get_port_speed()
Adjust this function so that it is passed an EHCI controller pointer so that
implementations can look up their controller.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass aac064f76b dm: usb: Move all the EHCI weak functions together and declare them
Put these at the top of the file so they are in one place. Also add function
prototypes to the header file to avoid call site mismatches.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass acf277af68 dm: usb: Convert usb_storage to driver model
Add support for scanning USB storage devices with driver model. This mostly
involves adding a USB device ID for storage devices.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:23 -06:00
Simon Glass 91557579af dm: usb: Move storage device scanning into its own function
The usb_stor_scan() function is quite long, so split out the code that scans
each device into its own function. Also, rather than setting up the block
device list once at the start, set it up as each device is scanned. This
makes it possible to use this code from driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:22 -06:00
Simon Glass 7fc2c1ea7b Revert "usb_storage : scan all interfaces to find a storage device"
This reverts commit cd749658d5.

The conflicts with this commit are hard for me to figure out. I will re-apply
it later.
2015-04-18 11:11:22 -06:00
Simon Glass 051081323f dm: usb: Adjust usb_storage to work with sandbox
With a few tweaks we can compile this code with sandbox and enable testing
of the USB storage layer.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:22 -06:00
Simon Glass 84073b6f3c dm: usb: Simply device finding code in usb_storage
The for() loop is not needed since the value is immediately accessible.
Use this instead to simplify the code.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:22 -06:00
Simon Glass 1d5827a12e dm: usb: Fix type problems in usb_stor_get_info()
This function assumes that unsigned long is 32-bits wide, but it is not
on 64-bit machines. Use the correct type, and add a few debug() lines also.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:22 -06:00
Simon Glass 2e17c87ebb dm: usb: Move USB storage definitions to usb_defs.h
These are better off in a header file so they can be used by other code (e.g.
the sandbox USB storage emulator).

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:22 -06:00
Simon Glass 054fe48eb2 dm: usb: Add driver model support for hubs
Adjust the existing hub code to support driver model, and add a USB driver
for hubs.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:21 -06:00
Simon Glass 361ad6afc4 dm: usb: Split hub detection into its own function
Split out the hub detection logic so it can be used by driver model. Also
adjust the code to return errors correctly.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:21 -06:00
Simon Glass 95fbfe4298 dm: usb: Convert core usb.c file to support driver model
Add the required #ifdefs and remove unwanted data structures so that the
USB uclass will be able to use this file.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:21 -06:00
Simon Glass 0ed27905ce dm: usb: Complete the splitting up of usb_new_device()
This function now calls usb_setup_device() to set up the device and
usb_hub_probe() to check if it is a hub. The XHCI special case is now a
parameter to usb_setup_device(). The latter will be used by the USB uclass
when it is added, since it does not rely on any CONFIGs or legacy data
structures.

Signed-off-by: Simon Glass <sjg@chromium.org>
Bug-fixes for descriptor reading and usb_new_device() return value
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Marek Vasut <marex@denx.de>
Tested-by: Tom Rini <trini@konsulko.com>
2015-04-18 11:11:21 -06:00
Simon Glass 91398f9854 dm: usb: Split out more code from usb_new_device()
Move the code that sets up the device with a new address into its own
function, usb_prepare_device().

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:21 -06:00
Simon Glass 128fcac087 dm: usb: Move descriptor setup code into its own function
usb_new_device() is far too long and does far too much. As a first step, move
the code that does initial setup and reads a descriptor into its own function
called usb_setup_descriptor().

For XHCI the init order is different - we set up the device but don't
actually read the descriptor until after we set an address. Support this
option as a parameter to usb_setup_descriptor().

Avoid changing this torturous code more than necessary to make it easy to
review.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:21 -06:00
Simon Glass 862e75c0db dm: usb: Refactor port resets
Move the port reset code into its own function. Rename usb_hub_reset() to
indicate that is is now a legacy function.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:20 -06:00
Simon Glass 53d8aa0f61 dm: usb: Drop the legacy USB init sequence
This CONFIG is not used anywhere in U-Boot, so drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Acked-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:20 -06:00
Simon Glass 6a1b206dc4 dm: usb: Convert 'usb' command to support driver model
Adjust this command to work with the new driver model uclass. It needs to
iterate through multiple independent controllers to find hubs, and work
through their children recursively in a different way. Otherwise the
functionality is much the same.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:20 -06:00
Simon Glass 79b5888729 dm: usb: Adjust usb_alloc_new_device() to return an error
This function returns NULL on error at present. Adjust it so that we can
return a real error, as is needed with driver model. Also improve the
error handling in its caller, usb_hub_port_connect_change(), and adjust
the code order to prepare for driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:20 -06:00
Simon Glass cad4291cd0 dm: usb: Adjust usb command to prepare for driver model
Use 'udev' instead of 'dev' in a few places, reserving 'dev' for driver
model's struct udevice. Also adjust the code in a few minor ways to make
it easier to plumb in driver model.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:20 -06:00
Simon Glass de31213fb8 dm: usb: Add a uclass for USB controllers
Add a uclass that can represent a USB controller. For now we do not create
devices for things attached to the controller. This will be added later.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:20 -06:00
Simon Glass 56a71f891b dm: gpio: Add an implementation for gpio_get_number()
This has a prototype but no implementation. It returns the global GPIO number
given a gpio_desc. It is useful for debugging in some cases.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass c5785673bc dm: core: Add device children and sibling functions
Add some utility functions to check for children and for the last sibling in
a device's parent.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass 206d4d2b4b dm: core: Mark device as active before calling uclass probe() methods
The uclass pre-probe functions may end up calling back into the device in
some circumstances. This can fail if recursion takes place. Adjust the
ordering so that we mark the device as active early, then retract this
later if needed.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass 39de843352 dm: core: Rename driver data function to dev_get_driver_data()
The existing get_get_of_data() function provides access to both the driver's
compatible string and its driver data. However only the latter is actually
useful. Update the interface to reflect this and fix up existing users.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass 3479253dad dm: core: Convert driver_bind() to use const
The driver is not modified by driver model, so update driver_bind() to
recognise that.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass 2c03c4633b dm: core: Support allocating driver-private data for DMA
Some driver want to put DMA buffers in their private data. Add a flag
to tell driver model to align driver-private data to a cache boundary so
that DMA will work correctly in this case.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass e23eb614a4 dm: test: bus: Use a local variable to simplify code
Adjust this test to avoid repeating the same code too often.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:19 -06:00
Simon Glass 887bd4164d sandbox: Fix comment for os_open()
This has the wrong #define in the function comment. Fix it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:18 -06:00
Simon Glass 72538f4c3e linker_lists: Add a function to access a linker list entry
Once declared, you cannot access a linker_list entry since you do not have
a symbol name for it. Add llsym() macro to provide this. This avoids
searching for the symbol at run-time based on name.

An example usage is to declare a driver with U_BOOT_DRIVER(), then obtain
a pointer to that driver later.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Marek Vasut <marex@denx.de>
2015-04-18 11:11:18 -06:00
Joe Hershberger 63c9729a13 dm: eth: Provide a way for drivers to manage packet buffers
Some drivers need a chance to manage their receive buffers after the
packet has been handled by the network stack. Add an operation that
will allow the driver to be called in that case.

Reported-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Joe Hershberger <joe.hershberger@ni.com>
Acked-by: Simon Glass <sjg@chromium.org>
Tested-by: Simon Glass <sjg@chromium.org>
Tested-on: pcduino3
2015-04-18 11:11:18 -06:00
Haikun.Wang@freescale.com 5bc4830896 dm: spi: Convert Freescale QSPI driver to driver model
Move the Freescale QSPI driver over to driver model.

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Tested-by: Peng Fan <Peng.Fan@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:18 -06:00
Haikun.Wang@freescale.com a891937110 dm: spi: Convert Freescale DSPI driver to driver model
Move the Freescale DSPI driver over to driver model.

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:18 -06:00
Haikun.Wang@freescale.com 863b4e1b9d dm: ls1021a: dts: Add QSPI dts node
Add QSPI controller dts node in ls1021a.dtsi.
Add QSPI slave device dts node in ls1021a-twr.dts and ls1021a-qds.dts.

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:18 -06:00
Haikun.Wang@freescale.com 6db79c4465 dm: ls1021a: dts: Update DSPI node to support DM SPI
Update DSPI controller node in ls1021a.dtsi.
Update flash device node in ls1021a-qds.dts.
Ls1021a-twr board doesn't support DSPI, so remove DSPI node
in ls1021a-twr.dts.

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:17 -06:00
haikun ce35fc17f0 dm: ls1021a: dts: Change address_cells and size_cells from 2 to 1
Change address_cells and size_cells of root node and 'soc' node
from 2 to 1.

We backport ls1021a device tree source files from kernel to u-boot.
Kernel files set address_cells and size_cells to 2 in order to access
more than 4GB space.
But we don't have this requirement now and u-boot fdtdec_get_xxx interfaces
can't support property whose size is 'u64' completely.
So make this change.

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:17 -06:00
haikun ddf79f3623 dm: ls1021a: Bring in ls1021a dts files from linux kernel
Bring in required device tree files for ls1021a from Linux.
These are initially unchanged and have a number of pieces not needed by U-Boot.

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:17 -06:00
Haikun.Wang@freescale.com b6286a1f54 dm: arm: Bring in skeleton64 device tree file from Linux
Backport of kernel commits:
	7c14f6c719de092d69c81877786e83ce7ae1a860
	35faad2a1563b3d4dc983a82ac41033fe053870c

Signed-off-by: Haikun Wang <Haikun.Wang@freescale.com>
Acked-by: Simon Glass <sjg@chromium.org>
2015-04-18 11:11:17 -06:00