2015-12-02 09:32:02 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-01-25 06:00:36 +00:00
|
|
|
#include <clk.h>
|
2016-09-21 02:29:02 +00:00
|
|
|
#include <reset.h>
|
2016-01-23 20:04:46 +00:00
|
|
|
#include <asm/io.h>
|
2015-12-02 09:32:02 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include "ehci.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Even though here we don't explicitly use "struct ehci_ctrl"
|
|
|
|
* ehci_register() expects it to be the first thing that resides in
|
|
|
|
* device's private data.
|
|
|
|
*/
|
|
|
|
struct generic_ehci {
|
|
|
|
struct ehci_ctrl ctrl;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ehci_usb_probe(struct udevice *dev)
|
|
|
|
{
|
2016-01-23 20:04:46 +00:00
|
|
|
struct ehci_hccr *hccr;
|
2015-12-02 09:32:02 +00:00
|
|
|
struct ehci_hcor *hcor;
|
2016-01-25 06:00:36 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; ; i++) {
|
2016-06-17 15:44:00 +00:00
|
|
|
struct clk clk;
|
|
|
|
int ret;
|
2016-01-25 06:00:36 +00:00
|
|
|
|
2016-06-17 15:44:00 +00:00
|
|
|
ret = clk_get_by_index(dev, i, &clk);
|
|
|
|
if (ret < 0)
|
2016-01-25 06:00:36 +00:00
|
|
|
break;
|
2016-06-17 15:44:00 +00:00
|
|
|
if (clk_enable(&clk))
|
2017-07-18 09:57:09 +00:00
|
|
|
error("failed to enable clock %d\n", i);
|
2016-06-17 15:44:00 +00:00
|
|
|
clk_free(&clk);
|
2016-01-25 06:00:36 +00:00
|
|
|
}
|
2015-12-02 09:32:02 +00:00
|
|
|
|
2016-09-21 02:29:02 +00:00
|
|
|
for (i = 0; ; i++) {
|
|
|
|
struct reset_ctl reset;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = reset_get_by_index(dev, i, &reset);
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
if (reset_deassert(&reset))
|
2017-07-18 09:57:09 +00:00
|
|
|
error("failed to deassert reset %d\n", i);
|
2016-09-21 02:29:02 +00:00
|
|
|
reset_free(&reset);
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:18:05 +00:00
|
|
|
hccr = map_physmem(devfdt_get_addr(dev), 0x100, MAP_NOCACHE);
|
2015-12-02 09:32:02 +00:00
|
|
|
hcor = (struct ehci_hcor *)((uintptr_t)hccr +
|
|
|
|
HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
|
|
|
|
|
|
|
|
return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct udevice_id ehci_usb_ids[] = {
|
|
|
|
{ .compatible = "generic-ehci" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(ehci_generic) = {
|
|
|
|
.name = "ehci_generic",
|
|
|
|
.id = UCLASS_USB,
|
|
|
|
.of_match = ehci_usb_ids,
|
|
|
|
.probe = ehci_usb_probe,
|
2016-09-06 13:17:34 +00:00
|
|
|
.remove = ehci_deregister,
|
2015-12-02 09:32:02 +00:00
|
|
|
.ops = &ehci_usb_ops,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct generic_ehci),
|
|
|
|
.flags = DM_FLAG_ALLOC_PRIV_DMA,
|
|
|
|
};
|