Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 |
| 4 | * Atmel Semiconductor <www.atmel.com> |
| 5 | * Written-by: Bo Shen <voice.shen@atmel.com> |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 8 | #include <clk.h> |
| 9 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 10 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 11 | #include <malloc.h> |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 12 | #include <usb.h> |
| 13 | #include <asm/io.h> |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 14 | #include <asm/arch/clk.h> |
| 15 | |
| 16 | #include "ehci.h" |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 17 | |
Sven Schwermer | 8a3cb9f1 | 2018-11-21 08:43:56 +0100 | [diff] [blame] | 18 | #if !CONFIG_IS_ENABLED(DM_USB) |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 19 | |
Troy Kisky | 7d6bbb9 | 2013-10-10 15:27:57 -0700 | [diff] [blame] | 20 | int ehci_hcd_init(int index, enum usb_init_type init, |
| 21 | struct ehci_hccr **hccr, struct ehci_hcor **hcor) |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 22 | { |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 23 | /* Enable UTMI PLL */ |
Wenyou Yang | 2f7be64 | 2016-02-02 11:11:53 +0800 | [diff] [blame] | 24 | if (at91_upll_clk_enable()) |
| 25 | return -1; |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 26 | |
| 27 | /* Enable USB Host clock */ |
Bo Shen | a2a637d | 2014-08-06 17:24:57 +0800 | [diff] [blame] | 28 | at91_periph_clk_enable(ATMEL_ID_UHPHS); |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 29 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 30 | *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI; |
| 31 | *hcor = (struct ehci_hcor *)((uint32_t)*hccr + |
| 32 | HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase))); |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
Lucas Stach | 3494a4c | 2012-09-26 00:14:35 +0200 | [diff] [blame] | 37 | int ehci_hcd_stop(int index) |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 38 | { |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 39 | /* Disable USB Host Clock */ |
Bo Shen | a2a637d | 2014-08-06 17:24:57 +0800 | [diff] [blame] | 40 | at91_periph_clk_disable(ATMEL_ID_UHPHS); |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 41 | |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 42 | /* Disable UTMI PLL */ |
Wenyou Yang | 2f7be64 | 2016-02-02 11:11:53 +0800 | [diff] [blame] | 43 | if (at91_upll_clk_disable()) |
| 44 | return -1; |
Bo Shen | c0eede0 | 2012-06-27 21:58:20 +0000 | [diff] [blame] | 45 | |
| 46 | return 0; |
| 47 | } |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 48 | |
| 49 | #else |
| 50 | |
| 51 | struct ehci_atmel_priv { |
| 52 | struct ehci_ctrl ehci; |
| 53 | }; |
| 54 | |
| 55 | static int ehci_atmel_enable_clk(struct udevice *dev) |
| 56 | { |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 57 | struct clk clk; |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 58 | int ret; |
| 59 | |
| 60 | ret = clk_get_by_index(dev, 0, &clk); |
| 61 | if (ret) |
| 62 | return ret; |
| 63 | |
| 64 | ret = clk_enable(&clk); |
| 65 | if (ret) |
| 66 | return ret; |
| 67 | |
| 68 | ret = clk_get_by_index(dev, 1, &clk); |
| 69 | if (ret) |
| 70 | return -EINVAL; |
| 71 | |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 72 | return clk_enable(&clk); |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | static int ehci_atmel_probe(struct udevice *dev) |
| 76 | { |
| 77 | struct ehci_hccr *hccr; |
| 78 | struct ehci_hcor *hcor; |
| 79 | fdt_addr_t hcd_base; |
| 80 | int ret; |
| 81 | |
| 82 | ret = ehci_atmel_enable_clk(dev); |
| 83 | if (ret) { |
| 84 | debug("Failed to enable USB Host clock\n"); |
| 85 | return ret; |
| 86 | } |
| 87 | |
| 88 | /* |
| 89 | * Get the base address for EHCI controller from the device node |
| 90 | */ |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 91 | hcd_base = dev_read_addr(dev); |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 92 | if (hcd_base == FDT_ADDR_T_NONE) { |
| 93 | debug("Can't get the EHCI register base address\n"); |
| 94 | return -ENXIO; |
| 95 | } |
| 96 | |
| 97 | hccr = (struct ehci_hccr *)hcd_base; |
| 98 | hcor = (struct ehci_hcor *) |
| 99 | ((u32)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 100 | |
| 101 | debug("echi-atmel: init hccr %x and hcor %x hc_length %d\n", |
| 102 | (u32)hccr, (u32)hcor, |
| 103 | (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase))); |
| 104 | |
| 105 | return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST); |
| 106 | } |
| 107 | |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 108 | static const struct udevice_id ehci_usb_ids[] = { |
| 109 | { .compatible = "atmel,at91sam9g45-ehci", }, |
| 110 | { } |
| 111 | }; |
| 112 | |
| 113 | U_BOOT_DRIVER(ehci_atmel) = { |
| 114 | .name = "ehci_atmel", |
| 115 | .id = UCLASS_USB, |
| 116 | .of_match = ehci_usb_ids, |
| 117 | .probe = ehci_atmel_probe, |
Masahiro Yamada | d41919b | 2016-09-06 22:17:34 +0900 | [diff] [blame] | 118 | .remove = ehci_deregister, |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 119 | .ops = &ehci_usb_ops, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 120 | .plat_auto = sizeof(struct usb_plat), |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 121 | .priv_auto = sizeof(struct ehci_atmel_priv), |
Wenyou Yang | 11e2665 | 2016-08-05 08:57:35 +0800 | [diff] [blame] | 122 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 123 | }; |
| 124 | |
| 125 | #endif |