Stephan Gerhold | bd51911 | 2021-07-08 20:33:49 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* Copyright (C) 2019 Stephan Gerhold */ |
| 3 | |
Stephan Gerhold | bd51911 | 2021-07-08 20:33:49 +0200 | [diff] [blame] | 4 | #include <dm.h> |
| 5 | #include <generic-phy.h> |
| 6 | #include <linux/bitops.h> |
| 7 | #include <power/pmic.h> |
| 8 | #include <power/ab8500.h> |
| 9 | |
| 10 | #define AB8500_USB_PHY_CTRL_REG AB8500_USB(0x8A) |
| 11 | #define AB8500_BIT_PHY_CTRL_HOST_EN BIT(0) |
| 12 | #define AB8500_BIT_PHY_CTRL_DEVICE_EN BIT(1) |
| 13 | #define AB8500_USB_PHY_CTRL_MASK (AB8500_BIT_PHY_CTRL_HOST_EN |\ |
| 14 | AB8500_BIT_PHY_CTRL_DEVICE_EN) |
| 15 | |
| 16 | static int ab8500_usb_phy_power_on(struct phy *phy) |
| 17 | { |
| 18 | struct udevice *dev = phy->dev; |
| 19 | uint set = AB8500_BIT_PHY_CTRL_DEVICE_EN; |
| 20 | |
Simon Glass | 84858a6 | 2023-02-05 15:44:26 -0700 | [diff] [blame] | 21 | if (IS_ENABLED(CONFIG_USB_MUSB_HOST)) |
Stephan Gerhold | bd51911 | 2021-07-08 20:33:49 +0200 | [diff] [blame] | 22 | set = AB8500_BIT_PHY_CTRL_HOST_EN; |
| 23 | |
| 24 | return pmic_clrsetbits(dev->parent, AB8500_USB_PHY_CTRL_REG, |
| 25 | AB8500_USB_PHY_CTRL_MASK, set); |
| 26 | } |
| 27 | |
| 28 | static int ab8500_usb_phy_power_off(struct phy *phy) |
| 29 | { |
| 30 | struct udevice *dev = phy->dev; |
| 31 | |
| 32 | return pmic_clrsetbits(dev->parent, AB8500_USB_PHY_CTRL_REG, |
| 33 | AB8500_USB_PHY_CTRL_MASK, 0); |
| 34 | } |
| 35 | |
| 36 | struct phy_ops ab8500_usb_phy_ops = { |
| 37 | .power_on = ab8500_usb_phy_power_on, |
| 38 | .power_off = ab8500_usb_phy_power_off, |
| 39 | }; |
| 40 | |
| 41 | static const struct udevice_id ab8500_usb_phy_ids[] = { |
| 42 | { .compatible = "stericsson,ab8500-usb" }, |
| 43 | { } |
| 44 | }; |
| 45 | |
| 46 | U_BOOT_DRIVER(ab8500_usb_phy) = { |
| 47 | .name = "ab8500_usb_phy", |
| 48 | .id = UCLASS_PHY, |
| 49 | .of_match = ab8500_usb_phy_ids, |
| 50 | .ops = &ab8500_usb_phy_ops, |
| 51 | }; |