drivers/pinctrl/pinmux.c
Source file repositories/reference/linux-study-clean/drivers/pinctrl/pinmux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/pinctrl/pinmux.c- Extension
.c- Size
- 26403 bytes
- Lines
- 1020
- Domain
- Driver Families
- Bucket
- drivers/pinctrl
- 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.
- 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/array_size.hlinux/ctype.hlinux/cleanup.hlinux/debugfs.hlinux/device.hlinux/err.hlinux/init.hlinux/list.hlinux/module.hlinux/radix-tree.hlinux/seq_file.hlinux/slab.hlinux/string.hlinux/pinctrl/machine.hlinux/pinctrl/pinctrl.hlinux/pinctrl/pinmux.hcore.hpinmux.h
Detected Declarations
function Copyrightfunction pinmux_validate_mapfunction pinmux_can_be_used_for_gpiofunction pin_requestfunction scoped_guardfunction scoped_guardfunction pin_freefunction scoped_guardfunction pinmux_request_gpiofunction pinmux_free_gpiofunction pinmux_gpio_directionfunction pinmux_func_name_to_selectorfunction pinmux_map_to_settingfunction pinmux_free_settingfunction pinmux_disable_settingfunction pinmux_functions_showfunction pinmux_pins_showfunction scoped_guardfunction pinmux_show_mapfunction pinmux_show_settingfunction pinmux_select_showfunction pinmux_select_writefunction pinmux_init_device_debugfsfunction pinmux_generic_get_function_countfunction pinmux_generic_get_function_namefunction pinmux_generic_get_function_groupsfunction pinmux_generic_get_functionfunction pinmux_generic_function_is_gpiofunction pinmux_generic_add_functionfunction pinmux_generic_add_pinfunctionfunction pinmux_generic_remove_functionfunction pinmux_generic_free_functionsexport pinmux_generic_get_function_countexport pinmux_generic_get_function_nameexport pinmux_generic_get_function_groupsexport pinmux_generic_get_functionexport pinmux_generic_function_is_gpioexport pinmux_generic_add_functionexport pinmux_generic_add_pinfunctionexport pinmux_generic_remove_function
Annotated Snippet
if (!fname) {
dev_err(pctldev->dev, "pinmux ops has no name for function%u\n",
selector);
return -EINVAL;
}
selector++;
}
return 0;
}
int pinmux_validate_map(const struct pinctrl_map *map, int i)
{
if (!map->data.mux.function) {
pr_err("failed to register map %s (%d): no function given\n",
map->name, i);
return -EINVAL;
}
return 0;
}
/**
* pinmux_can_be_used_for_gpio() - check if a specific pin
* is either muxed to a different function or used as gpio.
*
* @pctldev: the associated pin controller device
* @pin: the pin number in the global pin space
*
* Controllers not defined as strict will always return true,
* menaning that the gpio can be used.
*/
bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned int pin)
{
struct pin_desc *desc = pin_desc_get(pctldev, pin);
const struct pinmux_ops *ops = pctldev->desc->pmxops;
const struct pinctrl_setting_mux *mux_setting;
bool func_is_gpio = false;
/* Can't inspect pin, assume it can be used */
if (!desc || !ops)
return true;
mux_setting = desc->mux_setting;
guard(mutex)(&desc->mux_lock);
if (mux_setting && ops->function_is_gpio)
func_is_gpio = ops->function_is_gpio(pctldev, mux_setting->func);
if (ops->strict && desc->mux_usecount && !func_is_gpio)
return false;
return !(ops->strict && !!desc->gpio_owner);
}
/**
* pin_request() - request a single pin to be muxed in, typically for GPIO
* @pctldev: the associated pin controller device
* @pin: the pin number in the global pin space
* @owner: a representation of the owner of this pin; typically the device
* name that controls its mux function, or the requested GPIO name
* @gpio_range: the range matching the GPIO pin if this is a request for a
* single GPIO pin
*/
static int pin_request(struct pinctrl_dev *pctldev,
int pin, const char *owner,
struct pinctrl_gpio_range *gpio_range)
{
struct pin_desc *desc;
const struct pinmux_ops *ops = pctldev->desc->pmxops;
const struct pinctrl_setting_mux *mux_setting;
int status = -EINVAL;
bool gpio_ok = false;
desc = pin_desc_get(pctldev, pin);
if (desc == NULL) {
dev_err(pctldev->dev,
"pin %d is not registered so it cannot be requested\n",
pin);
goto out;
}
mux_setting = desc->mux_setting;
dev_dbg(pctldev->dev, "request pin %d (%s) for %s\n",
pin, desc->name, owner);
scoped_guard(mutex, &desc->mux_lock) {
if (mux_setting) {
if (ops->function_is_gpio)
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/ctype.h`, `linux/cleanup.h`, `linux/debugfs.h`, `linux/device.h`, `linux/err.h`, `linux/init.h`, `linux/list.h`.
- Detected declarations: `function Copyright`, `function pinmux_validate_map`, `function pinmux_can_be_used_for_gpio`, `function pin_request`, `function scoped_guard`, `function scoped_guard`, `function pin_free`, `function scoped_guard`, `function pinmux_request_gpio`, `function pinmux_free_gpio`.
- Atlas domain: Driver Families / drivers/pinctrl.
- Implementation status: integration 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.