mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-05 17:13:47 +01:00
If a device have sleep and idle states in addition to the default state, look up these in the core and stash them in the pinctrl state container. Add accessor functions for pinctrl consumers to put the pins into "default", "sleep" and "idle" states passing nothing but the struct device * affected. Solution suggested by Kevin Hilman, Mark Brown and Dmitry Torokhov in response to a patch series from Hebbar Gururaja. Cc: Hebbar Gururaja <[email protected]> Cc: Dmitry Torokhov <[email protected]> Cc: Stephen Warren <[email protected]> Acked-by: Wolfram Sang <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Mark Brown <[email protected]> Reviewed-by: Kevin Hilman <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
89 lines
2.2 KiB
C
89 lines
2.2 KiB
C
/*
|
|
* Driver core interface to the pinctrl subsystem.
|
|
*
|
|
* Copyright (C) 2012 ST-Ericsson SA
|
|
* Written on behalf of Linaro for ST-Ericsson
|
|
* Based on bits of regulator core, gpio core and clk core
|
|
*
|
|
* Author: Linus Walleij <[email protected]>
|
|
*
|
|
* License terms: GNU General Public License (GPL) version 2
|
|
*/
|
|
|
|
#include <linux/device.h>
|
|
#include <linux/pinctrl/devinfo.h>
|
|
#include <linux/pinctrl/consumer.h>
|
|
#include <linux/slab.h>
|
|
|
|
/**
|
|
* pinctrl_bind_pins() - called by the device core before probe
|
|
* @dev: the device that is just about to probe
|
|
*/
|
|
int pinctrl_bind_pins(struct device *dev)
|
|
{
|
|
int ret;
|
|
|
|
dev->pins = devm_kzalloc(dev, sizeof(*(dev->pins)), GFP_KERNEL);
|
|
if (!dev->pins)
|
|
return -ENOMEM;
|
|
|
|
dev->pins->p = devm_pinctrl_get(dev);
|
|
if (IS_ERR(dev->pins->p)) {
|
|
dev_dbg(dev, "no pinctrl handle\n");
|
|
ret = PTR_ERR(dev->pins->p);
|
|
goto cleanup_alloc;
|
|
}
|
|
|
|
dev->pins->default_state = pinctrl_lookup_state(dev->pins->p,
|
|
PINCTRL_STATE_DEFAULT);
|
|
if (IS_ERR(dev->pins->default_state)) {
|
|
dev_dbg(dev, "no default pinctrl state\n");
|
|
ret = 0;
|
|
goto cleanup_get;
|
|
}
|
|
|
|
ret = pinctrl_select_state(dev->pins->p, dev->pins->default_state);
|
|
if (ret) {
|
|
dev_dbg(dev, "failed to activate default pinctrl state\n");
|
|
goto cleanup_get;
|
|
}
|
|
|
|
#ifdef CONFIG_PM
|
|
/*
|
|
* If power management is enabled, we also look for the optional
|
|
* sleep and idle pin states, with semantics as defined in
|
|
* <linux/pinctrl/pinctrl-state.h>
|
|
*/
|
|
dev->pins->sleep_state = pinctrl_lookup_state(dev->pins->p,
|
|
PINCTRL_STATE_SLEEP);
|
|
if (IS_ERR(dev->pins->sleep_state))
|
|
/* Not supplying this state is perfectly legal */
|
|
dev_dbg(dev, "no sleep pinctrl state\n");
|
|
|
|
dev->pins->idle_state = pinctrl_lookup_state(dev->pins->p,
|
|
PINCTRL_STATE_IDLE);
|
|
if (IS_ERR(dev->pins->idle_state))
|
|
/* Not supplying this state is perfectly legal */
|
|
dev_dbg(dev, "no idle pinctrl state\n");
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
/*
|
|
* If no pinctrl handle or default state was found for this device,
|
|
* let's explicitly free the pin container in the device, there is
|
|
* no point in keeping it around.
|
|
*/
|
|
cleanup_get:
|
|
devm_pinctrl_put(dev->pins->p);
|
|
cleanup_alloc:
|
|
devm_kfree(dev, dev->pins);
|
|
dev->pins = NULL;
|
|
|
|
/* Only return deferrals */
|
|
if (ret != -EPROBE_DEFER)
|
|
ret = 0;
|
|
|
|
return ret;
|
|
}
|