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.

Dependency Surface

Detected Declarations

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

Implementation Notes