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