drivers/usb/misc/usb4604.c
Source file repositories/reference/linux-study-clean/drivers/usb/misc/usb4604.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/misc/usb4604.c- Extension
.c- Size
- 3436 bytes
- Lines
- 164
- 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.
- 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/i2c.hlinux/delay.hlinux/slab.hlinux/module.hlinux/gpio/consumer.h
Detected Declarations
struct usb4604enum usb4604_modefunction usb4604_resetfunction usb4604_connectfunction usb4604_switch_modefunction usb4604_probefunction usb4604_i2c_probefunction usb4604_i2c_suspendfunction usb4604_i2c_resume
Annotated Snippet
struct usb4604 {
enum usb4604_mode mode;
struct device *dev;
struct gpio_desc *gpio_reset;
};
static void usb4604_reset(struct usb4604 *hub, int state)
{
gpiod_set_value_cansleep(hub->gpio_reset, state);
/* Wait for i2c logic to come up */
if (state)
msleep(250);
}
static int usb4604_connect(struct usb4604 *hub)
{
struct device *dev = hub->dev;
struct i2c_client *client = to_i2c_client(dev);
int err;
u8 connect_cmd[] = { 0xaa, 0x55, 0x00 };
usb4604_reset(hub, 1);
err = i2c_master_send(client, connect_cmd, ARRAY_SIZE(connect_cmd));
if (err < 0) {
usb4604_reset(hub, 0);
return err;
}
hub->mode = USB4604_MODE_HUB;
dev_dbg(dev, "switched to HUB mode\n");
return 0;
}
static int usb4604_switch_mode(struct usb4604 *hub, enum usb4604_mode mode)
{
struct device *dev = hub->dev;
int err = 0;
switch (mode) {
case USB4604_MODE_HUB:
err = usb4604_connect(hub);
break;
case USB4604_MODE_STANDBY:
usb4604_reset(hub, 0);
dev_dbg(dev, "switched to STANDBY mode\n");
break;
default:
dev_err(dev, "unknown mode is requested\n");
err = -EINVAL;
break;
}
return err;
}
static int usb4604_probe(struct usb4604 *hub)
{
struct device *dev = hub->dev;
struct device_node *np = dev->of_node;
struct gpio_desc *gpio;
u32 mode = USB4604_MODE_HUB;
gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
if (IS_ERR(gpio))
return PTR_ERR(gpio);
hub->gpio_reset = gpio;
if (of_property_read_u32(np, "initial-mode", &hub->mode))
hub->mode = mode;
return usb4604_switch_mode(hub, hub->mode);
}
static int usb4604_i2c_probe(struct i2c_client *i2c)
{
struct usb4604 *hub;
hub = devm_kzalloc(&i2c->dev, sizeof(*hub), GFP_KERNEL);
if (!hub)
return -ENOMEM;
i2c_set_clientdata(i2c, hub);
hub->dev = &i2c->dev;
return usb4604_probe(hub);
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/delay.h`, `linux/slab.h`, `linux/module.h`, `linux/gpio/consumer.h`.
- Detected declarations: `struct usb4604`, `enum usb4604_mode`, `function usb4604_reset`, `function usb4604_connect`, `function usb4604_switch_mode`, `function usb4604_probe`, `function usb4604_i2c_probe`, `function usb4604_i2c_suspend`, `function usb4604_i2c_resume`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
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.