drivers/clk/at91/clk-usb.c
Source file repositories/reference/linux-study-clean/drivers/clk/at91/clk-usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/clk/at91/clk-usb.c- Extension
.c- Size
- 10016 bytes
- Lines
- 425
- 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.
- 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-provider.hlinux/clkdev.hlinux/clk/at91_pmc.hlinux/of.hlinux/mfd/syscon.hlinux/regmap.hpmc.h
Detected Declarations
struct at91sam9x5_clk_usbstruct at91rm9200_clk_usbfunction at91sam9x5_clk_usb_recalc_ratefunction at91sam9x5_clk_usb_determine_ratefunction at91sam9x5_clk_usb_set_parentfunction at91sam9x5_clk_usb_get_parentfunction at91sam9x5_clk_usb_set_ratefunction at91sam9x5_usb_save_contextfunction at91sam9x5_usb_restore_contextfunction at91sam9n12_clk_usb_enablefunction at91sam9n12_clk_usb_disablefunction at91sam9n12_clk_usb_is_enabledfunction _at91sam9x5_clk_register_usbfunction at91sam9x5_clk_register_usbfunction sam9x60_clk_register_usbfunction at91sam9n12_clk_register_usbfunction at91rm9200_clk_usb_recalc_ratefunction at91rm9200_clk_usb_determine_ratefunction at91rm9200_clk_usb_set_ratefunction at91rm9200_clk_register_usb
Annotated Snippet
struct at91sam9x5_clk_usb {
struct clk_hw hw;
struct regmap *regmap;
struct at91_clk_pms pms;
u32 usbs_mask;
u8 num_parents;
};
#define to_at91sam9x5_clk_usb(hw) \
container_of(hw, struct at91sam9x5_clk_usb, hw)
struct at91rm9200_clk_usb {
struct clk_hw hw;
struct regmap *regmap;
u32 divisors[4];
};
#define to_at91rm9200_clk_usb(hw) \
container_of(hw, struct at91rm9200_clk_usb, hw)
static unsigned long at91sam9x5_clk_usb_recalc_rate(struct clk_hw *hw,
unsigned long parent_rate)
{
struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
unsigned int usbr;
u8 usbdiv;
regmap_read(usb->regmap, AT91_PMC_USB, &usbr);
usbdiv = (usbr & AT91_PMC_OHCIUSBDIV) >> SAM9X5_USB_DIV_SHIFT;
return DIV_ROUND_CLOSEST(parent_rate, (usbdiv + 1));
}
static int at91sam9x5_clk_usb_determine_rate(struct clk_hw *hw,
struct clk_rate_request *req)
{
struct clk_hw *parent;
long best_rate = -EINVAL;
unsigned long tmp_rate;
int best_diff = -1;
int tmp_diff;
int i;
for (i = 0; i < clk_hw_get_num_parents(hw); i++) {
int div;
parent = clk_hw_get_parent_by_index(hw, i);
if (!parent)
continue;
for (div = 1; div < SAM9X5_USB_MAX_DIV + 2; div++) {
unsigned long tmp_parent_rate;
tmp_parent_rate = req->rate * div;
tmp_parent_rate = clk_hw_round_rate(parent,
tmp_parent_rate);
if (!tmp_parent_rate)
continue;
tmp_rate = DIV_ROUND_CLOSEST(tmp_parent_rate, div);
if (tmp_rate < req->rate)
tmp_diff = req->rate - tmp_rate;
else
tmp_diff = tmp_rate - req->rate;
if (best_diff < 0 || best_diff > tmp_diff) {
best_rate = tmp_rate;
best_diff = tmp_diff;
req->best_parent_rate = tmp_parent_rate;
req->best_parent_hw = parent;
}
if (!best_diff || tmp_rate < req->rate)
break;
}
if (!best_diff)
break;
}
if (best_rate < 0)
return best_rate;
req->rate = best_rate;
return 0;
}
static int at91sam9x5_clk_usb_set_parent(struct clk_hw *hw, u8 index)
{
struct at91sam9x5_clk_usb *usb = to_at91sam9x5_clk_usb(hw);
Annotation
- Immediate include surface: `linux/clk-provider.h`, `linux/clkdev.h`, `linux/clk/at91_pmc.h`, `linux/of.h`, `linux/mfd/syscon.h`, `linux/regmap.h`, `pmc.h`.
- Detected declarations: `struct at91sam9x5_clk_usb`, `struct at91rm9200_clk_usb`, `function at91sam9x5_clk_usb_recalc_rate`, `function at91sam9x5_clk_usb_determine_rate`, `function at91sam9x5_clk_usb_set_parent`, `function at91sam9x5_clk_usb_get_parent`, `function at91sam9x5_clk_usb_set_rate`, `function at91sam9x5_usb_save_context`, `function at91sam9x5_usb_restore_context`, `function at91sam9n12_clk_usb_enable`.
- Atlas domain: Driver Families / drivers/clk.
- 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.