drivers/usb/phy/phy.c

Source file repositories/reference/linux-study-clean/drivers/usb/phy/phy.c

File Facts

System
Linux kernel
Corpus path
drivers/usb/phy/phy.c
Extension
.c
Size
19112 bytes
Lines
749
Domain
Driver Families
Bucket
drivers/usb
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 phy_devm {
	struct usb_phy *phy;
	struct notifier_block *nb;
};

static const char *const usb_chger_type[] = {
	[UNKNOWN_TYPE]			= "USB_CHARGER_UNKNOWN_TYPE",
	[SDP_TYPE]			= "USB_CHARGER_SDP_TYPE",
	[CDP_TYPE]			= "USB_CHARGER_CDP_TYPE",
	[DCP_TYPE]			= "USB_CHARGER_DCP_TYPE",
	[ACA_TYPE]			= "USB_CHARGER_ACA_TYPE",
};

static const char *const usb_chger_state[] = {
	[USB_CHARGER_DEFAULT]	= "USB_CHARGER_DEFAULT",
	[USB_CHARGER_PRESENT]	= "USB_CHARGER_PRESENT",
	[USB_CHARGER_ABSENT]	= "USB_CHARGER_ABSENT",
};

static struct usb_phy *__usb_find_phy(struct list_head *list,
	enum usb_phy_type type)
{
	struct usb_phy  *phy = NULL;

	list_for_each_entry(phy, list, head) {
		if (phy->type != type)
			continue;

		return phy;
	}

	return ERR_PTR(-ENODEV);
}

static struct usb_phy *__of_usb_find_phy(struct device_node *node)
{
	struct usb_phy  *phy;

	if (!of_device_is_available(node))
		return ERR_PTR(-ENODEV);

	list_for_each_entry(phy, &phy_list, head) {
		if (node != phy->dev->of_node)
			continue;

		return phy;
	}

	return ERR_PTR(-EPROBE_DEFER);
}

static struct usb_phy *__device_to_usb_phy(const struct device *dev)
{
	struct usb_phy *usb_phy;

	list_for_each_entry(usb_phy, &phy_list, head) {
		if (usb_phy->dev == dev)
			return usb_phy;
	}

	return NULL;
}

static void usb_phy_set_default_current(struct usb_phy *usb_phy)
{
	usb_phy->chg_cur.sdp_min = DEFAULT_SDP_CUR_MIN;
	usb_phy->chg_cur.sdp_max = DEFAULT_SDP_CUR_MAX;
	usb_phy->chg_cur.dcp_min = DEFAULT_DCP_CUR_MIN;
	usb_phy->chg_cur.dcp_max = DEFAULT_DCP_CUR_MAX;
	usb_phy->chg_cur.cdp_min = DEFAULT_CDP_CUR_MIN;
	usb_phy->chg_cur.cdp_max = DEFAULT_CDP_CUR_MAX;
	usb_phy->chg_cur.aca_min = DEFAULT_ACA_CUR_MIN;
	usb_phy->chg_cur.aca_max = DEFAULT_ACA_CUR_MAX;
}

/**
 * usb_phy_notify_charger_work - notify the USB charger state
 * @work: the charger work to notify the USB charger state
 *
 * This work can be issued when USB charger state has been changed or
 * USB charger current has been changed, then we can notify the current
 * what can be drawn to power user and the charger state to userspace.
 *
 * If we get the charger type from extcon subsystem, we can notify the
 * charger state to power user automatically by usb_phy_get_charger_type()
 * issuing from extcon subsystem.
 *
 * If we get the charger type from ->charger_detect() instead of extcon
 * subsystem, the usb phy driver should issue usb_phy_set_charger_state()
 * to set charger state when the charger state has been changed.

Annotation

Implementation Notes