drivers/clk/sunxi/clk-usb.c
Source file repositories/reference/linux-study-clean/drivers/clk/sunxi/clk-usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/sunxi/clk-usb.c- Extension
.c- Size
- 6854 bytes
- Lines
- 253
- Domain
- Driver Families
- Bucket
- drivers/clk
- 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/clk.hlinux/clk-provider.hlinux/io.hlinux/of.hlinux/of_address.hlinux/reset-controller.hlinux/slab.hlinux/spinlock.h
Detected Declarations
struct usb_reset_datastruct usb_clk_datafunction sunxi_usb_reset_assertfunction sunxi_usb_reset_deassertfunction sunxi_usb_clk_setupfunction for_each_set_bitfunction sun4i_a10_usb_setupfunction sun5i_a13_usb_setupfunction sun6i_a31_usb_setupfunction sun8i_a23_usb_setupfunction sun8i_h3_usb_setupfunction sun9i_a80_usb_mod_setupfunction sun9i_a80_usb_phy_setup
Annotated Snippet
struct usb_reset_data {
void __iomem *reg;
spinlock_t *lock;
struct clk *clk;
struct reset_controller_dev rcdev;
};
static int sunxi_usb_reset_assert(struct reset_controller_dev *rcdev,
unsigned long id)
{
struct usb_reset_data *data = container_of(rcdev,
struct usb_reset_data,
rcdev);
unsigned long flags;
u32 reg;
clk_prepare_enable(data->clk);
spin_lock_irqsave(data->lock, flags);
reg = readl(data->reg);
writel(reg & ~BIT(id), data->reg);
spin_unlock_irqrestore(data->lock, flags);
clk_disable_unprepare(data->clk);
return 0;
}
static int sunxi_usb_reset_deassert(struct reset_controller_dev *rcdev,
unsigned long id)
{
struct usb_reset_data *data = container_of(rcdev,
struct usb_reset_data,
rcdev);
unsigned long flags;
u32 reg;
clk_prepare_enable(data->clk);
spin_lock_irqsave(data->lock, flags);
reg = readl(data->reg);
writel(reg | BIT(id), data->reg);
spin_unlock_irqrestore(data->lock, flags);
clk_disable_unprepare(data->clk);
return 0;
}
static const struct reset_control_ops sunxi_usb_reset_ops = {
.assert = sunxi_usb_reset_assert,
.deassert = sunxi_usb_reset_deassert,
};
#define SUNXI_USB_MAX_SIZE 32
struct usb_clk_data {
u32 clk_mask;
u32 reset_mask;
bool reset_needs_clk;
};
/**
* sunxi_usb_clk_setup() - Setup function for usb gate clocks
* @node: &struct device_node for the clock
* @data: &struct usb_clk_data for the clock
* @lock: spinlock for the clock
*/
static void __init sunxi_usb_clk_setup(struct device_node *node,
const struct usb_clk_data *data,
spinlock_t *lock)
{
struct clk_onecell_data *clk_data;
struct usb_reset_data *reset_data;
const char *clk_parent;
const char *clk_name;
void __iomem *reg;
int qty;
int i = 0;
int j = 0;
reg = of_io_request_and_map(node, 0, of_node_full_name(node));
if (IS_ERR(reg))
return;
clk_parent = of_clk_get_parent_name(node, 0);
if (!clk_parent)
return;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/clk-provider.h`, `linux/io.h`, `linux/of.h`, `linux/of_address.h`, `linux/reset-controller.h`, `linux/slab.h`, `linux/spinlock.h`.
- Detected declarations: `struct usb_reset_data`, `struct usb_clk_data`, `function sunxi_usb_reset_assert`, `function sunxi_usb_reset_deassert`, `function sunxi_usb_clk_setup`, `function for_each_set_bit`, `function sun4i_a10_usb_setup`, `function sun5i_a13_usb_setup`, `function sun6i_a31_usb_setup`, `function sun8i_a23_usb_setup`.
- Atlas domain: Driver Families / drivers/clk.
- 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.