Pin Control APIs

This topic provides details for the pinctrl APIs.

pinctrl_get

Synopsis
struct pinctrl *pinctrl_get(struct device *dev)
Description Obtains a handle to the pin control resources for the specified device
Parameter dev: The target device
Return
  • Success: Pinctrl handle
  • Failure: Error code

pinctrl_put

This interface can be used only after pinctrl_get has been used. Otherwise, its use is invalid.

Synopsis
void pinctrl_put(struct pinctrl *p)
Description Discounts usage on a previously claimed pin control handle. It must be used in pair with the pinctrl_get() function.
Parameter p: The pinctrl handle to release.
Return None

devm_pinctrl_get

Synopsis
struct pinctrl *devm_pinctrl_get(struct device *dev)
Description Equal to pinctrl_get, but with resource management capabilities.
Parameter dev: The device to which the pin operation applies.
Return
  • Success: Pin control handle
  • Failure: Error code
Example The following call example obtains a handle to the pin control resources for the PCIe device.
  struct device *dev = &pcie->pdev->dev;

        pcie->pinctrl = devm_pinctrl_get(dev);
        if (IS_ERR_OR_NULL(pcie->pinctrl)) {
                dev_err(dev, "Getting pinctrl handle failed\n");
                return -EINVAL;
        }

devm_pinctrl_put

This interface can be used only after pinctrl_get has been used. Otherwise, its use is invalid. Normally, you may not need this function, as it may release all resources.

Synopsis
void devm_pinctrl_put(struct pinctrl *p)
Description Equal to pinctrl_put, but with resource management capabilities. You can de-allocate a struct pinctrl obtained via devm_pinctrl_get()
Parameter p: The pinctrl handle to release.
Return None

pinctrl_lookup_state

Synopsis
struct pinctrl_state *pinctrl_lookup_state(struct pinctrl *p, const char *name)
Description Looks up named pin states from the handle you obtained with devm_pinctrl_get().
Parameter
  • p: The target pinctrl handle
  • name: The name of the state you want to retrieve
Return
  • Success: The state handle from a pin control handle.
  • Failure: Error codes
Example The following call example looks for the states named "perst-default", "perst-active" and "power-active".
pcie->perst_state_def
                = pinctrl_lookup_state(pcie->pinctrl, "perst-default");
        if (IS_ERR_OR_NULL(pcie->perst_state_def)) {
                dev_err(dev, "Failed to get the perst-default pinctrl han-dle\n");
                return -EINVAL;
        }

        pcie->perst_state_active
                = pinctrl_lookup_state(pcie->pinctrl, "perst-active");
        if (IS_ERR_OR_NULL(pcie->perst_state_active)) {
                dev_err(dev, "Failed to get the perst-active pinctrl handle\n");
                return -EINVAL;
        }

        pcie->power_state_active
                = pinctrl_lookup_state(pcie->pinctrl, "power-active");
        if (IS_ERR_OR_NULL(pcie->power_state_active)) {
                dev_err(dev, "Failed to get the power-default pinctrl han-dle\n");
                return -EINVAL;
        }

pinctrl_select_state

Synopsis
int pinctrl_select_state(struct pinctrl *p, struct pinctrl_state *state)
Description Selects, activates or programs a pin control state to the hardware.
Parameter
  • p: The pinctrl handle that requests configuration
  • state: The state handle you want to select, activate or program.
Return
  • Success: 0.
  • Failure: Error code.
Example The following call example sets the PCIe power pin to active (high) and the PCIe reset pin to active (low).
 if (pcie->power_state_active) {
                ret = pinctrl_select_state(pcie->pinctrl, pcie->power_state_active);
                if (ret)
                        dev_err(dev, "Cannot set power pin to high\n");
        }

        if (pcie->perst_state_active) {
                ret = pinctrl_select_state(pcie->pinctrl, pcie->perst_state_active);
                if (ret)
                        dev_err(dev, "Cannot set reset pin to low\n");
        }