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 | |
| 4 | #include <common.h> |
| 5 | #include <dm.h> |
| 6 | #include <generic-phy.h> |
| 7 | #include <linux/bitops.h> |
| 8 | #include <power/pmic.h> |
| 9 | #include <power/ab8500.h> |
| 10 | |
| 11 | #define AB8500_USB_PHY_CTRL_REG AB8500_USB(0x8A) |
| 12 | #define AB8500_BIT_PHY_CTRL_HOST_EN BIT(0) |
| 13 | #define AB8500_BIT_PHY_CTRL_DEVICE_EN BIT(1) |
| 14 | #define AB8500_USB_PHY_CTRL_MASK (AB8500_BIT_PHY_CTRL_HOST_EN |\ |
| 15 | AB8500_BIT_PHY_CTRL_DEVICE_EN) |
| 16 | |
| 17 | static int ab8500_usb_phy_power_on(struct phy *phy) |
| 18 | { |
| 19 | struct udevice *dev = phy->dev; |
| 20 | uint set = AB8500_BIT_PHY_CTRL_DEVICE_EN; |
| 21 | |
| 22 | if (CONFIG_IS_ENABLED(USB_MUSB_HOST)) |
| 23 | set = AB8500_BIT_PHY_CTRL_HOST_EN; |
| 24 | |
| 25 | return pmic_clrsetbits(dev->parent, AB8500_USB_PHY_CTRL_REG, |
| 26 | AB8500_USB_PHY_CTRL_MASK, set); |
| 27 | } |
| 28 | |
| 29 | static int ab8500_usb_phy_power_off(struct phy *phy) |
| 30 | { |
| 31 | struct udevice *dev = phy->dev; |
| 32 | |
| 33 | return pmic_clrsetbits(dev->parent, AB8500_USB_PHY_CTRL_REG, |
| 34 | AB8500_USB_PHY_CTRL_MASK, 0); |
| 35 | } |
| 36 | |
| 37 | struct phy_ops ab8500_usb_phy_ops = { |
| 38 | .power_on = ab8500_usb_phy_power_on, |
| 39 | .power_off = ab8500_usb_phy_power_off, |
| 40 | }; |
| 41 | |
| 42 | static const struct udevice_id ab8500_usb_phy_ids[] = { |
| 43 | { .compatible = "stericsson,ab8500-usb" }, |
| 44 | { } |
| 45 | }; |
| 46 | |
| 47 | U_BOOT_DRIVER(ab8500_usb_phy) = { |
| 48 | .name = "ab8500_usb_phy", |
| 49 | .id = UCLASS_PHY, |
| 50 | .of_match = ab8500_usb_phy_ids, |
| 51 | .ops = &ab8500_usb_phy_ops, |
| 52 | }; |