drivers/usb/typec/mux/ptn36502.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/mux/ptn36502.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/mux/ptn36502.c- Extension
.c- Size
- 11418 bytes
- Lines
- 432
- 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.
- 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
drm/bridge/aux-bridge.hlinux/bitfield.hlinux/i2c.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/of_graph.hlinux/regmap.hlinux/regulator/consumer.hlinux/usb/typec_dp.hlinux/usb/typec_mux.hlinux/usb/typec_retimer.h
Detected Declarations
struct ptn36502function ptn36502_setfunction ptn36502_sw_setfunction ptn36502_retimer_setfunction ptn36502_detectfunction ptn36502_probefunction ptn36502_remove
Annotated Snippet
struct ptn36502 {
struct i2c_client *client;
struct regulator *vdd18_supply;
struct regmap *regmap;
struct typec_switch_dev *sw;
struct typec_retimer *retimer;
struct typec_switch *typec_switch;
struct typec_mux *typec_mux;
struct mutex lock; /* protect non-concurrent retimer & switch */
enum typec_orientation orientation;
unsigned long mode;
unsigned int svid;
};
static int ptn36502_set(struct ptn36502 *ptn)
{
bool reverse = (ptn->orientation == TYPEC_ORIENTATION_REVERSE);
unsigned int ctrl1_val = 0;
unsigned int lane_ctrl_val = 0;
unsigned int link_ctrl_val = 0;
switch (ptn->mode) {
case TYPEC_STATE_SAFE:
/* Deep power saving state */
regmap_write(ptn->regmap, PTN36502_MODE_CTRL1_REG,
FIELD_PREP(PTN36502_MODE_CTRL1_MODE_MASK,
PTN36502_MODE_CTRL1_MODE_OFF));
return 0;
case TYPEC_STATE_USB:
/*
* Normal Orientation (CC1)
* A -> USB RX
* B -> USB TX
* C -> X
* D -> X
* Flipped Orientation (CC2)
* A -> X
* B -> X
* C -> USB TX
* D -> USB RX
*/
/* USB 3.1 Gen 1 only */
ctrl1_val = FIELD_PREP(PTN36502_MODE_CTRL1_MODE_MASK,
PTN36502_MODE_CTRL1_MODE_USB_ONLY);
if (reverse)
ctrl1_val |= FIELD_PREP(PTN36502_MODE_CTRL1_PLUG_ORIENT_MASK,
PTN36502_MODE_CTRL1_PLUG_ORIENT_REVERSE);
regmap_write(ptn->regmap, PTN36502_MODE_CTRL1_REG, ctrl1_val);
return 0;
default:
if (ptn->svid != USB_TYPEC_DP_SID)
return -EINVAL;
break;
}
/* DP Altmode Setup */
switch (ptn->mode) {
case TYPEC_DP_STATE_C:
case TYPEC_DP_STATE_E:
/*
* Normal Orientation (CC1)
* A -> DP3
* B -> DP2
* C -> DP1
* D -> DP0
* Flipped Orientation (CC2)
* A -> DP0
* B -> DP1
* C -> DP2
* D -> DP3
*/
/* 4-lane DP */
ctrl1_val |= FIELD_PREP(PTN36502_MODE_CTRL1_MODE_MASK,
PTN36502_MODE_CTRL1_MODE_DP);
link_ctrl_val |= FIELD_PREP(PTN36502_DP_LINK_CTRL_LANES_MASK,
PTN36502_DP_LINK_CTRL_LANES_4);
break;
case TYPEC_DP_STATE_D:
case TYPEC_DP_STATE_F: /* State F is deprecated */
Annotation
- Immediate include surface: `drm/bridge/aux-bridge.h`, `linux/bitfield.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/of_graph.h`, `linux/regmap.h`.
- Detected declarations: `struct ptn36502`, `function ptn36502_set`, `function ptn36502_sw_set`, `function ptn36502_retimer_set`, `function ptn36502_detect`, `function ptn36502_probe`, `function ptn36502_remove`.
- Atlas domain: Driver Families / drivers/usb.
- 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.