drivers/usb/typec/mux/tusb1046.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/mux/tusb1046.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/mux/tusb1046.c- Extension
.c- Size
- 4818 bytes
- Lines
- 197
- 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/bits.hlinux/i2c.hlinux/usb/typec_mux.hlinux/usb/typec_dp.hlinux/usb/typec_altmode.hlinux/module.hlinux/mod_devicetable.hlinux/err.hlinux/of_device.hlinux/device.hlinux/mutex.h
Detected Declarations
struct tusb1046_privfunction tusb1046_mux_setfunction tusb1046_switch_setfunction tusb1046_i2c_probefunction tusb1046_i2c_remove
Annotated Snippet
struct tusb1046_priv {
struct i2c_client *client;
struct typec_switch_dev *sw;
struct typec_mux_dev *mux;
/* Lock General register during accesses */
struct mutex general_reg_lock;
};
static int tusb1046_mux_set(struct typec_mux_dev *mux,
struct typec_mux_state *state)
{
struct tusb1046_priv *priv = typec_mux_get_drvdata(mux);
struct i2c_client *client = priv->client;
struct device *dev = &client->dev;
int mode, val, ret = 0;
if (state->mode >= TYPEC_STATE_MODAL &&
state->alt->svid != USB_TYPEC_DP_SID)
return -EINVAL;
dev_dbg(dev, "mux mode requested: %lu\n", state->mode);
mutex_lock(&priv->general_reg_lock);
val = i2c_smbus_read_byte_data(client, TUSB1046_REG_GENERAL);
if (val < 0) {
dev_err(dev, "failed to read ctlsel status, err %d\n", val);
ret = val;
goto out_unlock;
}
switch (state->mode) {
case TYPEC_STATE_USB:
mode = TUSB1046_CTLSEL_USB3;
break;
case TYPEC_DP_STATE_C:
case TYPEC_DP_STATE_E:
mode = TUSB1046_CTLSEL_4LANE_DP;
break;
case TYPEC_DP_STATE_D:
mode = TUSB1046_CTLSEL_USB3_AND_2LANE_DP;
break;
case TYPEC_STATE_SAFE:
default:
mode = TUSB1046_CTLSEL_DISABLED;
break;
}
val &= ~TUSB1046_GENERAL_CTLSEL;
val |= mode;
ret = i2c_smbus_write_byte_data(client, TUSB1046_REG_GENERAL, val);
out_unlock:
mutex_unlock(&priv->general_reg_lock);
return ret;
}
static int tusb1046_switch_set(struct typec_switch_dev *sw,
enum typec_orientation orientation)
{
struct tusb1046_priv *priv = typec_switch_get_drvdata(sw);
struct i2c_client *client = priv->client;
struct device *dev = &client->dev;
int val, ret = 0;
dev_dbg(dev, "setting USB3.0 lane flip for orientation %d\n", orientation);
mutex_lock(&priv->general_reg_lock);
val = i2c_smbus_read_byte_data(client, TUSB1046_REG_GENERAL);
if (val < 0) {
dev_err(dev, "failed to read flipsel status, err %d\n", val);
ret = val;
goto out_unlock;
}
if (orientation == TYPEC_ORIENTATION_REVERSE)
val |= TUSB1046_GENERAL_FLIPSEL;
else
val &= ~TUSB1046_GENERAL_FLIPSEL;
ret = i2c_smbus_write_byte_data(client, TUSB1046_REG_GENERAL, val);
out_unlock:
mutex_unlock(&priv->general_reg_lock);
return ret;
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/i2c.h`, `linux/usb/typec_mux.h`, `linux/usb/typec_dp.h`, `linux/usb/typec_altmode.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/err.h`.
- Detected declarations: `struct tusb1046_priv`, `function tusb1046_mux_set`, `function tusb1046_switch_set`, `function tusb1046_i2c_probe`, `function tusb1046_i2c_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.