drivers/usb/typec/hd3ss3220.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/hd3ss3220.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/hd3ss3220.c- Extension
.c- Size
- 14652 bytes
- Lines
- 548
- Domain
- Driver Families
- Bucket
- drivers/usb
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/i2c.hlinux/usb/role.hlinux/irqreturn.hlinux/interrupt.hlinux/regmap.hlinux/slab.hlinux/usb/typec.hlinux/delay.hlinux/workqueue.hlinux/gpio/consumer.hlinux/regulator/consumer.hlinux/of_graph.h
Detected Declarations
struct hd3ss3220function hd3ss3220_set_power_opmodefunction hd3ss3220_set_port_typefunction hd3ss3220_set_source_preffunction hd3ss3220_get_attached_statefunction hd3ss3220_try_rolefunction hd3ss3220_port_type_setfunction hd3ss3220_regulator_controlfunction hd3ss3220_set_rolefunction output_poll_executefunction hd3ss3220_irqfunction hd3ss3220_irq_handlerfunction hd3ss3220_configure_power_opmodefunction hd3ss3220_configure_port_typefunction hd3ss3220_configure_source_preffunction hd3ss3220_id_isrfunction hd3ss3220_probefunction hd3ss3220_remove
Annotated Snippet
struct hd3ss3220 {
struct device *dev;
struct regmap *regmap;
struct usb_role_switch *role_sw;
struct typec_port *port;
struct delayed_work output_poll_work;
enum usb_role role_state;
bool poll;
struct gpio_desc *id_gpiod;
int id_irq;
struct regulator *vbus;
};
static int hd3ss3220_set_power_opmode(struct hd3ss3220 *hd3ss3220, int power_opmode)
{
int current_mode;
switch (power_opmode) {
case TYPEC_PWR_MODE_USB:
current_mode = HD3SS3220_REG_CN_STAT_CURRENT_MODE_DEFAULT;
break;
case TYPEC_PWR_MODE_1_5A:
current_mode = HD3SS3220_REG_CN_STAT_CURRENT_MODE_MID;
break;
case TYPEC_PWR_MODE_3_0A:
current_mode = HD3SS3220_REG_CN_STAT_CURRENT_MODE_HIGH;
break;
case TYPEC_PWR_MODE_PD: /* Power delivery not supported */
default:
dev_err(hd3ss3220->dev, "bad power operation mode: %d\n", power_opmode);
return -EINVAL;
}
return regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_CN_STAT,
HD3SS3220_REG_CN_STAT_CURRENT_MODE_MASK,
current_mode);
}
static int hd3ss3220_set_port_type(struct hd3ss3220 *hd3ss3220, int type)
{
int mode_select, err;
switch (type) {
case TYPEC_PORT_SRC:
mode_select = HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DFP;
break;
case TYPEC_PORT_SNK:
mode_select = HD3SS3220_REG_GEN_CTRL_MODE_SELECT_UFP;
break;
case TYPEC_PORT_DRP:
mode_select = HD3SS3220_REG_GEN_CTRL_MODE_SELECT_DRP;
break;
default:
dev_err(hd3ss3220->dev, "bad port type: %d\n", type);
return -EINVAL;
}
/* Disable termination before changing MODE_SELECT as required by datasheet */
err = regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL,
HD3SS3220_REG_GEN_CTRL_DISABLE_TERM,
HD3SS3220_REG_GEN_CTRL_DISABLE_TERM);
if (err < 0) {
dev_err(hd3ss3220->dev, "Failed to disable port for mode change: %d\n", err);
return err;
}
err = regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL,
HD3SS3220_REG_GEN_CTRL_MODE_SELECT_MASK,
mode_select);
if (err < 0) {
dev_err(hd3ss3220->dev, "Failed to change mode: %d\n", err);
regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL,
HD3SS3220_REG_GEN_CTRL_DISABLE_TERM, 0);
return err;
}
err = regmap_update_bits(hd3ss3220->regmap, HD3SS3220_REG_GEN_CTRL,
HD3SS3220_REG_GEN_CTRL_DISABLE_TERM, 0);
if (err < 0)
dev_err(hd3ss3220->dev, "Failed to re-enable port after mode change: %d\n", err);
return err;
}
static int hd3ss3220_set_source_pref(struct hd3ss3220 *hd3ss3220, int prefer_role)
{
int src_pref;
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/usb/role.h`, `linux/irqreturn.h`, `linux/interrupt.h`, `linux/regmap.h`, `linux/slab.h`, `linux/usb/typec.h`.
- Detected declarations: `struct hd3ss3220`, `function hd3ss3220_set_power_opmode`, `function hd3ss3220_set_port_type`, `function hd3ss3220_set_source_pref`, `function hd3ss3220_get_attached_state`, `function hd3ss3220_try_role`, `function hd3ss3220_port_type_set`, `function hd3ss3220_regulator_control`, `function hd3ss3220_set_role`, `function output_poll_execute`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.