blob: eda9f698d9bc767f1d4a67b48d57d5288a002afa [file] [log] [blame]
Roman Byshko8d154002014-07-27 19:32:44 +02001/*
2 * Copyright (C) 2014 Roman Byshko
3 *
4 * Roman Byshko <rbyshko@gmail.com>
5 *
6 * Based on code from
7 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
8 *
9 * SPDX-License-Identifier: GPL-2.0+
10 */
11
Hans de Goede0eccec42015-01-07 15:08:43 +010012#include <asm/arch/usbc.h>
Roman Byshko8d154002014-07-27 19:32:44 +020013#include <common.h>
14#include "ehci.h"
15
Roman Byshko8d154002014-07-27 19:32:44 +020016int ehci_hcd_init(int index, enum usb_init_type init, struct ehci_hccr **hccr,
17 struct ehci_hcor **hcor)
18{
Hans de Goede44fd5912014-10-31 17:04:52 +010019 int err;
Roman Byshko8d154002014-07-27 19:32:44 +020020
Hans de Goede0eccec42015-01-07 15:08:43 +010021 err = sunxi_usbc_request_resources(index + 1);
22 if (err)
23 return err;
Hans de Goede115200c2014-11-07 16:09:00 +010024
Hans de Goede0eccec42015-01-07 15:08:43 +010025 sunxi_usbc_enable(index + 1);
26 sunxi_usbc_vbus_enable(index + 1);
Roman Byshko8d154002014-07-27 19:32:44 +020027
Hans de Goede0eccec42015-01-07 15:08:43 +010028 *hccr = sunxi_usbc_get_io_base(index + 1);
Roman Byshko8d154002014-07-27 19:32:44 +020029
30 *hcor = (struct ehci_hcor *)((uint32_t) *hccr
31 + HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
32
33 debug("sunxi-ehci: init hccr %x and hcor %x hc_length %d\n",
34 (uint32_t)*hccr, (uint32_t)*hcor,
35 (uint32_t)HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
36
Roman Byshko8d154002014-07-27 19:32:44 +020037 return 0;
38}
39
40int ehci_hcd_stop(int index)
41{
Hans de Goede0eccec42015-01-07 15:08:43 +010042 sunxi_usbc_vbus_disable(index + 1);
43 sunxi_usbc_disable(index + 1);
Roman Byshko8d154002014-07-27 19:32:44 +020044
Hans de Goede0eccec42015-01-07 15:08:43 +010045 return sunxi_usbc_free_resources(index + 1);
Roman Byshko8d154002014-07-27 19:32:44 +020046}