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.

Dependency Surface

Detected Declarations

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, &regval);
		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

Implementation Notes