drivers/phy/phy-common-props.c
Source file repositories/reference/linux-study-clean/drivers/phy/phy-common-props.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/phy/phy-common-props.c- Extension
.c- Size
- 6827 bytes
- Lines
- 210
- Domain
- Driver Families
- Bucket
- drivers/phy
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/fwnode.hlinux/phy/phy-common-props.hlinux/printk.hlinux/property.hlinux/slab.h
Detected Declarations
function elementsfunction phy_get_polarity_for_modefunction phy_get_rx_polarityfunction phy_get_tx_polarityfunction phy_get_manual_rx_polarityfunction phy_get_manual_tx_polarityexport phy_get_rx_polarityexport phy_get_tx_polarityexport phy_get_manual_rx_polarityexport phy_get_manual_tx_polarity
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* phy-common-props.c -- Common PHY properties
*
* Copyright 2025-2026 NXP
*/
#include <linux/export.h>
#include <linux/fwnode.h>
#include <linux/phy/phy-common-props.h>
#include <linux/printk.h>
#include <linux/property.h>
#include <linux/slab.h>
/**
* fwnode_get_u32_prop_for_name - Find u32 property by name, or default value
* @fwnode: Pointer to firmware node, or NULL to use @default_val
* @name: Property name used as lookup key in @names_title (must not be NULL)
* @props_title: Name of u32 array property holding values
* @names_title: Name of string array property holding lookup keys
* @default_val: Default value if @fwnode is NULL or @props_title is empty
* @val: Pointer to store the returned value
*
* This function retrieves a u32 value from @props_title based on a name lookup
* in @names_title. The value stored in @val is determined as follows:
*
* - If @fwnode is NULL or @props_title is empty: @default_val is used
* - If @props_title has exactly one element and @names_title is empty:
* that element is used
* - Otherwise: @val is set to the element at the same index where @name is
* found in @names_title.
* - If @name is not found, the function looks for a "default" entry in
* @names_title and uses the corresponding value from @props_title
*
* When both @props_title and @names_title are present, they must have the
* same number of elements (except when @props_title has exactly one element).
*
* Return: zero on success, negative error on failure.
*/
static int fwnode_get_u32_prop_for_name(struct fwnode_handle *fwnode,
const char *name,
const char *props_title,
const char *names_title,
unsigned int default_val,
unsigned int *val)
{
int err, n_props, n_names, idx;
u32 *props;
if (!name) {
pr_err("Lookup key inside \"%s\" is mandatory\n", names_title);
return -EINVAL;
}
n_props = fwnode_property_count_u32(fwnode, props_title);
if (n_props <= 0) {
/* fwnode is NULL, or is missing requested property */
*val = default_val;
return 0;
}
n_names = fwnode_property_string_array_count(fwnode, names_title);
if (n_names >= 0 && n_props != n_names) {
pr_err("%pfw mismatch between \"%s\" and \"%s\" property count (%d vs %d)\n",
fwnode, props_title, names_title, n_props, n_names);
return -EINVAL;
}
idx = fwnode_property_match_string(fwnode, names_title, name);
if (idx < 0)
idx = fwnode_property_match_string(fwnode, names_title, "default");
/*
* If the mode name is missing, it can only mean the specified property
* is the default one for all modes, so reject any other property count
* than 1.
*/
if (idx < 0 && n_props != 1) {
pr_err("%pfw \"%s \" property has %d elements, but cannot find \"%s\" in \"%s\" and there is no default value\n",
fwnode, props_title, n_props, name, names_title);
return -EINVAL;
}
if (n_props == 1) {
err = fwnode_property_read_u32(fwnode, props_title, val);
if (err)
return err;
return 0;
}
/* We implicitly know idx >= 0 here */
Annotation
- Immediate include surface: `linux/export.h`, `linux/fwnode.h`, `linux/phy/phy-common-props.h`, `linux/printk.h`, `linux/property.h`, `linux/slab.h`.
- Detected declarations: `function elements`, `function phy_get_polarity_for_mode`, `function phy_get_rx_polarity`, `function phy_get_tx_polarity`, `function phy_get_manual_rx_polarity`, `function phy_get_manual_tx_polarity`, `export phy_get_rx_polarity`, `export phy_get_tx_polarity`, `export phy_get_manual_rx_polarity`, `export phy_get_manual_tx_polarity`.
- Atlas domain: Driver Families / drivers/phy.
- Implementation status: integration 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.