Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Alexey Brodkin <abrodkin@synopsys.com> |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 7 | #include <clk.h> |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 8 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 11 | #include <dm/devres.h> |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 12 | #include <dm/ofnode.h> |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 13 | #include <generic-phy.h> |
Patrice Chotard | 170229e | 2017-07-18 11:57:13 +0200 | [diff] [blame] | 14 | #include <reset.h> |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 15 | #include "ohci.h" |
| 16 | |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 17 | struct generic_ohci { |
| 18 | ohci_t ohci; |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 19 | struct clk_bulk clocks; /* clock list */ |
| 20 | struct reset_ctl_bulk resets; /* reset list */ |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 21 | struct phy phy; |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | static int ohci_usb_probe(struct udevice *dev) |
| 25 | { |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 26 | struct ohci_regs *regs = dev_read_addr_ptr(dev); |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 27 | struct generic_ohci *priv = dev_get_priv(dev); |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 28 | int err, ret; |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 29 | |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 30 | ret = clk_get_bulk(dev, &priv->clocks); |
| 31 | if (ret && ret != -ENOENT) { |
| 32 | dev_err(dev, "Failed to get clocks (ret=%d)\n", ret); |
| 33 | return ret; |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 34 | } |
| 35 | |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 36 | err = clk_enable_bulk(&priv->clocks); |
| 37 | if (err) { |
| 38 | dev_err(dev, "Failed to enable clocks (err=%d)\n", err); |
| 39 | goto clk_err; |
| 40 | } |
Patrice Chotard | 170229e | 2017-07-18 11:57:13 +0200 | [diff] [blame] | 41 | |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 42 | err = reset_get_bulk(dev, &priv->resets); |
| 43 | if (err && err != -ENOENT) { |
| 44 | dev_err(dev, "failed to get resets (err=%d)\n", err); |
Patrice Chotard | 170229e | 2017-07-18 11:57:13 +0200 | [diff] [blame] | 45 | goto clk_err; |
| 46 | } |
| 47 | |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 48 | err = reset_deassert_bulk(&priv->resets); |
| 49 | if (err) { |
| 50 | dev_err(dev, "failed to deassert resets (err=%d)\n", err); |
| 51 | goto reset_err; |
| 52 | } |
| 53 | |
Patrice Chotard | cb9f1e4 | 2022-09-06 08:15:27 +0200 | [diff] [blame] | 54 | err = generic_setup_phy(dev, &priv->phy, 0); |
Patrice Chotard | ab0b205e | 2018-03-14 17:48:57 +0100 | [diff] [blame] | 55 | if (err) |
Patrice Chotard | ab0b205e | 2018-03-14 17:48:57 +0100 | [diff] [blame] | 56 | goto reset_err; |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 57 | |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 58 | err = ohci_register(dev, regs); |
| 59 | if (err) |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 60 | goto phy_err; |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 61 | |
| 62 | return 0; |
| 63 | |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 64 | phy_err: |
Patrice Chotard | cb9f1e4 | 2022-09-06 08:15:27 +0200 | [diff] [blame] | 65 | ret = generic_shutdown_phy(&priv->phy); |
Patrice Chotard | ab0b205e | 2018-03-14 17:48:57 +0100 | [diff] [blame] | 66 | if (ret) |
| 67 | dev_err(dev, "failed to shutdown usb phy\n"); |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 68 | |
Patrice Chotard | 170229e | 2017-07-18 11:57:13 +0200 | [diff] [blame] | 69 | reset_err: |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 70 | ret = reset_release_bulk(&priv->resets); |
Patrice Chotard | 170229e | 2017-07-18 11:57:13 +0200 | [diff] [blame] | 71 | if (ret) |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 72 | dev_err(dev, "failed to release resets (ret=%d)\n", ret); |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 73 | clk_err: |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 74 | ret = clk_release_bulk(&priv->clocks); |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 75 | if (ret) |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 76 | dev_err(dev, "failed to release clocks (ret=%d)\n", ret); |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 77 | |
| 78 | return err; |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static int ohci_usb_remove(struct udevice *dev) |
| 82 | { |
Patrice Chotard | 37a197a | 2017-07-18 11:57:12 +0200 | [diff] [blame] | 83 | struct generic_ohci *priv = dev_get_priv(dev); |
| 84 | int ret; |
| 85 | |
| 86 | ret = ohci_deregister(dev); |
| 87 | if (ret) |
| 88 | return ret; |
| 89 | |
Patrice Chotard | cb9f1e4 | 2022-09-06 08:15:27 +0200 | [diff] [blame] | 90 | ret = generic_shutdown_phy(&priv->phy); |
Patrice Chotard | ab0b205e | 2018-03-14 17:48:57 +0100 | [diff] [blame] | 91 | if (ret) |
| 92 | return ret; |
Patrice Chotard | c6e19d3 | 2017-07-18 11:57:14 +0200 | [diff] [blame] | 93 | |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 94 | ret = reset_release_bulk(&priv->resets); |
Patrice Chotard | 170229e | 2017-07-18 11:57:13 +0200 | [diff] [blame] | 95 | if (ret) |
| 96 | return ret; |
| 97 | |
Fabrice Gasnier | 19a383a | 2023-09-04 14:20:21 +0200 | [diff] [blame] | 98 | return clk_release_bulk(&priv->clocks); |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | static const struct udevice_id ohci_usb_ids[] = { |
| 102 | { .compatible = "generic-ohci" }, |
| 103 | { } |
| 104 | }; |
| 105 | |
| 106 | U_BOOT_DRIVER(ohci_generic) = { |
| 107 | .name = "ohci_generic", |
| 108 | .id = UCLASS_USB, |
| 109 | .of_match = ohci_usb_ids, |
| 110 | .probe = ohci_usb_probe, |
| 111 | .remove = ohci_usb_remove, |
| 112 | .ops = &ohci_usb_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 113 | .priv_auto = sizeof(struct generic_ohci), |
Alexey Brodkin | 83fd312 | 2015-12-14 17:18:50 +0300 | [diff] [blame] | 114 | .flags = DM_FLAG_ALLOC_PRIV_DMA, |
| 115 | }; |