drivers/usb/typec/mux/gpio-sbu-mux.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/mux/gpio-sbu-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/mux/gpio-sbu-mux.c- Extension
.c- Size
- 4050 bytes
- Lines
- 172
- 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
linux/device.hlinux/module.hlinux/mutex.hlinux/gpio/consumer.hlinux/platform_device.hlinux/usb/typec_dp.hlinux/usb/typec_mux.h
Detected Declarations
struct gpio_sbu_muxfunction gpio_sbu_switch_setfunction gpio_sbu_mux_setfunction gpio_sbu_mux_probefunction gpio_sbu_mux_remove
Annotated Snippet
struct gpio_sbu_mux {
struct gpio_desc *enable_gpio;
struct gpio_desc *select_gpio;
struct typec_switch_dev *sw;
struct typec_mux_dev *mux;
struct mutex lock; /* protect enabled and swapped */
bool enabled;
bool swapped;
};
static int gpio_sbu_switch_set(struct typec_switch_dev *sw,
enum typec_orientation orientation)
{
struct gpio_sbu_mux *sbu_mux = typec_switch_get_drvdata(sw);
bool enabled;
bool swapped;
mutex_lock(&sbu_mux->lock);
enabled = sbu_mux->enabled;
swapped = sbu_mux->swapped;
switch (orientation) {
case TYPEC_ORIENTATION_NONE:
enabled = false;
break;
case TYPEC_ORIENTATION_NORMAL:
swapped = false;
break;
case TYPEC_ORIENTATION_REVERSE:
swapped = true;
break;
}
if (enabled != sbu_mux->enabled)
gpiod_set_value_cansleep(sbu_mux->enable_gpio, enabled);
if (swapped != sbu_mux->swapped)
gpiod_set_value_cansleep(sbu_mux->select_gpio, swapped);
sbu_mux->enabled = enabled;
sbu_mux->swapped = swapped;
mutex_unlock(&sbu_mux->lock);
return 0;
}
static int gpio_sbu_mux_set(struct typec_mux_dev *mux,
struct typec_mux_state *state)
{
struct gpio_sbu_mux *sbu_mux = typec_mux_get_drvdata(mux);
if (!sbu_mux->enable_gpio)
return -EOPNOTSUPP;
mutex_lock(&sbu_mux->lock);
switch (state->mode) {
case TYPEC_STATE_SAFE:
case TYPEC_STATE_USB:
sbu_mux->enabled = false;
break;
case TYPEC_DP_STATE_C:
case TYPEC_DP_STATE_D:
case TYPEC_DP_STATE_E:
sbu_mux->enabled = true;
break;
default:
break;
}
gpiod_set_value_cansleep(sbu_mux->enable_gpio, sbu_mux->enabled);
mutex_unlock(&sbu_mux->lock);
return 0;
}
static int gpio_sbu_mux_probe(struct platform_device *pdev)
{
struct typec_switch_desc sw_desc = { };
struct typec_mux_desc mux_desc = { };
struct device *dev = &pdev->dev;
struct gpio_sbu_mux *sbu_mux;
sbu_mux = devm_kzalloc(dev, sizeof(*sbu_mux), GFP_KERNEL);
if (!sbu_mux)
Annotation
- Immediate include surface: `linux/device.h`, `linux/module.h`, `linux/mutex.h`, `linux/gpio/consumer.h`, `linux/platform_device.h`, `linux/usb/typec_dp.h`, `linux/usb/typec_mux.h`.
- Detected declarations: `struct gpio_sbu_mux`, `function gpio_sbu_switch_set`, `function gpio_sbu_mux_set`, `function gpio_sbu_mux_probe`, `function gpio_sbu_mux_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.