drivers/phy/sophgo/phy-cv1800-usb2.c
Source file repositories/reference/linux-study-clean/drivers/phy/sophgo/phy-cv1800-usb2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/phy/sophgo/phy-cv1800-usb2.c- Extension
.c- Size
- 4302 bytes
- Lines
- 170
- Domain
- Driver Families
- Bucket
- drivers/phy
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/bitfield.hlinux/debugfs.hlinux/kernel.hlinux/mfd/syscon.hlinux/module.hlinux/of.hlinux/of_address.hlinux/platform_device.hlinux/phy/phy.hlinux/regmap.hlinux/spinlock.h
Detected Declarations
struct cv1800_usb_phyfunction cv1800_usb_phy_set_modefunction cv1800_usb_phy_set_clockfunction cv1800_usb_phy_probe
Annotated Snippet
struct cv1800_usb_phy {
struct phy *phy;
struct regmap *syscon;
spinlock_t lock;
struct clk *usb_app_clk;
struct clk *usb_lpm_clk;
struct clk *usb_stb_clk;
bool support_otg;
};
static int cv1800_usb_phy_set_mode(struct phy *_phy,
enum phy_mode mode, int submode)
{
struct cv1800_usb_phy *phy = phy_get_drvdata(_phy);
unsigned int regval = 0;
int ret;
dev_info(&phy->phy->dev, "set mode %d", (int)mode);
switch (mode) {
case PHY_MODE_USB_DEVICE:
regval = PHY_ID_OVERWRITE_EN | PHY_ID_OVERWRITE_MODE_DEVICE;
regmap_clear_bits(phy->syscon, REG_USB_PHY_CTRL, PHY_VBUS_POWER);
break;
case PHY_MODE_USB_HOST:
regval = PHY_ID_OVERWRITE_EN | PHY_ID_OVERWRITE_MODE_HOST;
regmap_set_bits(phy->syscon, REG_USB_PHY_CTRL, PHY_VBUS_POWER);
break;
case PHY_MODE_USB_OTG:
if (!phy->support_otg)
return 0;
ret = regmap_read(phy->syscon, REG_USB_PHY_CTRL, ®val);
if (ret)
return ret;
regval = FIELD_GET(PHY_ID_OVERWRITE_MODE, regval);
break;
default:
return -EINVAL;
}
return regmap_update_bits(phy->syscon, REG_USB_PHY_CTRL,
PHY_ID_OVERWRITE_EN | PHY_ID_OVERWRITE_MODE,
regval);
}
static int cv1800_usb_phy_set_clock(struct cv1800_usb_phy *phy)
{
int ret;
ret = clk_set_rate(phy->usb_app_clk, PHY_APP_CLK_RATE);
if (ret)
return ret;
ret = clk_set_rate(phy->usb_lpm_clk, PHY_LPM_CLK_RATE);
if (ret)
return ret;
return clk_set_rate(phy->usb_stb_clk, PHY_STB_CLK_RATE);
}
static const struct phy_ops cv1800_usb_phy_ops = {
.set_mode = cv1800_usb_phy_set_mode,
.owner = THIS_MODULE,
};
static int cv1800_usb_phy_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device *parent = dev->parent;
struct cv1800_usb_phy *phy;
struct phy_provider *phy_provider;
int ret;
if (!parent)
return -ENODEV;
phy = devm_kmalloc(dev, sizeof(*phy), GFP_KERNEL);
if (!phy)
return -ENOMEM;
phy->syscon = syscon_node_to_regmap(parent->of_node);
if (IS_ERR_OR_NULL(phy->syscon))
return -ENODEV;
phy->support_otg = false;
spin_lock_init(&phy->lock);
Annotation
- Immediate include surface: `linux/clk.h`, `linux/bitfield.h`, `linux/debugfs.h`, `linux/kernel.h`, `linux/mfd/syscon.h`, `linux/module.h`, `linux/of.h`, `linux/of_address.h`.
- Detected declarations: `struct cv1800_usb_phy`, `function cv1800_usb_phy_set_mode`, `function cv1800_usb_phy_set_clock`, `function cv1800_usb_phy_probe`.
- Atlas domain: Driver Families / drivers/phy.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.