drivers/pinctrl/pinctrl-generic-mux.c
Source file repositories/reference/linux-study-clean/drivers/pinctrl/pinctrl-generic-mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pinctrl/pinctrl-generic-mux.c- Extension
.c- Size
- 4715 bytes
- Lines
- 185
- Domain
- Driver Families
- Bucket
- drivers/pinctrl
- 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/cleanup.hlinux/module.hlinux/of.hlinux/mutex.hlinux/mux/consumer.hlinux/platform_device.hlinux/pinctrl/pinconf-generic.hlinux/pinctrl/pinctrl.hlinux/pinctrl/pinmux.hlinux/slab.hcore.hpinconf.hpinmux.hpinctrl-utils.h
Detected Declarations
struct mux_pin_functionstruct mux_pinctrlfunction mux_pinmux_dt_node_to_mapfunction mux_pinmux_set_muxfunction mux_pinmux_release_muxfunction mux_pinctrl_probe
Annotated Snippet
struct mux_pin_function {
struct mux_state *mux_state;
};
struct mux_pinctrl {
struct device *dev;
struct pinctrl_dev *pctl;
/* mutex protect [pinctrl|pinmux]_generic functions */
struct mutex lock;
};
static int
mux_pinmux_dt_node_to_map(struct pinctrl_dev *pctldev,
struct device_node *np_config,
struct pinctrl_map **maps, unsigned int *num_maps)
{
unsigned int num_reserved_maps = 0;
struct mux_pin_function *function;
const char **group_names;
int ret;
function = devm_kzalloc(pctldev->dev, sizeof(*function), GFP_KERNEL);
if (!function)
return -ENOMEM;
group_names = devm_kcalloc(pctldev->dev, 1, sizeof(*group_names), GFP_KERNEL);
if (!group_names)
return -ENOMEM;
function->mux_state = devm_mux_state_get_from_np(pctldev->dev, NULL, np_config);
if (IS_ERR(function->mux_state))
return PTR_ERR(function->mux_state);
ret = pinctrl_generic_to_map(pctldev, np_config, np_config, maps,
num_maps, &num_reserved_maps, group_names,
0, &np_config->name, NULL, 0);
if (ret)
return ret;
ret = pinmux_generic_add_function(pctldev, np_config->name, group_names,
1, function);
if (ret < 0) {
pinctrl_utils_free_map(pctldev, *maps, *num_maps);
return ret;
}
return 0;
}
static const struct pinctrl_ops mux_pinctrl_ops = {
.get_groups_count = pinctrl_generic_get_group_count,
.get_group_name = pinctrl_generic_get_group_name,
.get_group_pins = pinctrl_generic_get_group_pins,
.dt_node_to_map = mux_pinmux_dt_node_to_map,
.dt_free_map = pinctrl_utils_free_map,
};
static int mux_pinmux_set_mux(struct pinctrl_dev *pctldev,
unsigned int func_selector,
unsigned int group_selector)
{
struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
const struct function_desc *function;
struct mux_pin_function *func;
int ret;
guard(mutex)(&mpctl->lock);
function = pinmux_generic_get_function(pctldev, func_selector);
func = function->data;
ret = mux_state_select(func->mux_state);
if (ret)
return ret;
return 0;
}
static void mux_pinmux_release_mux(struct pinctrl_dev *pctldev,
unsigned int func_selector,
unsigned int group_selector)
{
struct mux_pinctrl *mpctl = pinctrl_dev_get_drvdata(pctldev);
const struct function_desc *function;
struct mux_pin_function *func;
guard(mutex)(&mpctl->lock);
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/module.h`, `linux/of.h`, `linux/mutex.h`, `linux/mux/consumer.h`, `linux/platform_device.h`, `linux/pinctrl/pinconf-generic.h`, `linux/pinctrl/pinctrl.h`.
- Detected declarations: `struct mux_pin_function`, `struct mux_pinctrl`, `function mux_pinmux_dt_node_to_map`, `function mux_pinmux_set_mux`, `function mux_pinmux_release_mux`, `function mux_pinctrl_probe`.
- Atlas domain: Driver Families / drivers/pinctrl.
- 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.