drivers/thunderbolt/lc.c
Source file repositories/reference/linux-study-clean/drivers/thunderbolt/lc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/thunderbolt/lc.c- Extension
.c- Size
- 16136 bytes
- Lines
- 718
- Domain
- Driver Families
- Bucket
- drivers/thunderbolt
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.htb.h
Detected Declarations
function Copyrightfunction read_lc_descfunction find_port_lc_capfunction tb_lc_reset_portfunction tb_lc_set_port_configuredfunction tb_lc_configure_portfunction tb_lc_unconfigure_portfunction tb_lc_set_xdomain_configuredfunction tb_lc_configure_xdomainfunction tb_lc_unconfigure_xdomainfunction tb_lc_start_lane_initializationfunction tb_lc_is_clx_supportedfunction tb_lc_is_usb_pluggedfunction tb_lc_is_xhci_connectedfunction __tb_lc_xhci_connectfunction tb_lc_xhci_connectfunction tb_lc_xhci_disconnectfunction tb_lc_set_wake_onefunction tb_lc_set_wakefunction tb_lc_set_sleepfunction tb_lc_lane_bonding_possiblefunction tb_lc_dp_sink_from_portfunction tb_lc_dp_sink_availablefunction tb_lc_dp_sink_queryfunction tb_lc_dp_sink_allocfunction tb_lc_dp_sink_deallocfunction tb_lc_force_power
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Thunderbolt link controller support
*
* Copyright (C) 2019, Intel Corporation
* Author: Mika Westerberg <mika.westerberg@linux.intel.com>
*/
#include <linux/delay.h>
#include "tb.h"
/**
* tb_lc_read_uuid() - Read switch UUID from link controller common register
* @sw: Switch whose UUID is read
* @uuid: UUID is placed here
*
* Return: %0 on success, negative errno otherwise.
*/
int tb_lc_read_uuid(struct tb_switch *sw, u32 *uuid)
{
if (!sw->cap_lc)
return -EINVAL;
return tb_sw_read(sw, uuid, TB_CFG_SWITCH, sw->cap_lc + TB_LC_FUSE, 4);
}
static int read_lc_desc(struct tb_switch *sw, u32 *desc)
{
if (!sw->cap_lc)
return -EINVAL;
return tb_sw_read(sw, desc, TB_CFG_SWITCH, sw->cap_lc + TB_LC_DESC, 1);
}
static int find_port_lc_cap(struct tb_port *port)
{
struct tb_switch *sw = port->sw;
int start, phys, ret, size;
u32 desc;
ret = read_lc_desc(sw, &desc);
if (ret)
return ret;
/* Start of port LC registers */
start = (desc & TB_LC_DESC_SIZE_MASK) >> TB_LC_DESC_SIZE_SHIFT;
size = (desc & TB_LC_DESC_PORT_SIZE_MASK) >> TB_LC_DESC_PORT_SIZE_SHIFT;
phys = tb_phy_port_from_link(port->port);
return sw->cap_lc + start + phys * size;
}
/**
* tb_lc_reset_port() - Trigger downstream port reset through LC
* @port: Port that is reset
*
* Triggers downstream port reset through link controller registers.
* Only supports non-USB4 routers with link controller (that's
* Thunderbolt 2 and Thunderbolt 3).
*
* Return: %0 on success, negative errno otherwise.
*/
int tb_lc_reset_port(struct tb_port *port)
{
struct tb_switch *sw = port->sw;
int cap, ret;
u32 mode;
if (sw->generation < 2)
return -EINVAL;
cap = find_port_lc_cap(port);
if (cap < 0)
return cap;
ret = tb_sw_read(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
if (ret)
return ret;
mode |= TB_LC_PORT_MODE_DPR;
ret = tb_sw_write(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
if (ret)
return ret;
fsleep(10000);
ret = tb_sw_read(sw, &mode, TB_CFG_SWITCH, cap + TB_LC_PORT_MODE, 1);
if (ret)
return ret;
Annotation
- Immediate include surface: `linux/delay.h`, `tb.h`.
- Detected declarations: `function Copyright`, `function read_lc_desc`, `function find_port_lc_cap`, `function tb_lc_reset_port`, `function tb_lc_set_port_configured`, `function tb_lc_configure_port`, `function tb_lc_unconfigure_port`, `function tb_lc_set_xdomain_configured`, `function tb_lc_configure_xdomain`, `function tb_lc_unconfigure_xdomain`.
- Atlas domain: Driver Families / drivers/thunderbolt.
- 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.