mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-03 13:46:38 +07:00
ed032c1bed
Commitab78029ecc
("drivers/pinctrl: grab default handles from device core") added automatic pin-control management to driver core by looking up and setting any default pinctrl state found in device tree while a device is being probed. This obviously runs into problems as soon as device-tree nodes are reused for child devices which are later also probed as pins would already have been claimed by the ancestor device. For example if a USB host controller claims a pin, its root hub would consequently fail to probe when its device-tree node is set to the node of the controller: pinctrl-single 48002030.pinmux: pin PIN204 already requested by 48064800.ehci; cannot claim for usb1 pinctrl-single 48002030.pinmux: pin-204 (usb1) status -22 pinctrl-single 48002030.pinmux: could not request pin 204 (PIN204) from group usb_dbg_pins on device pinctrl-single usb usb1: Error applying setting, reverse things back usb: probe of usb1 failed with error -22 Fix this by checking the new of_node_reused flag and skipping automatic pinctrl configuration during probe if set. Note that the flag is checked in driver core rather than in pinctrl (e.g. in pinctrl_dt_to_map()) which would specifically have prevented intentional use of a parent's pinctrl properties by a child device (should such a need ever arise). Fixes:ab78029ecc
("drivers/pinctrl: grab default handles from device core") Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Johan Hovold <johan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
107 lines
2.7 KiB
C
107 lines
2.7 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 <linus.walleij@linaro.org>
|
|
*
|
|
* 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;
|
|
|
|
if (dev->of_node_reused)
|
|
return 0;
|
|
|
|
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;
|
|
}
|
|
|
|
dev->pins->init_state = pinctrl_lookup_state(dev->pins->p,
|
|
PINCTRL_STATE_INIT);
|
|
if (IS_ERR(dev->pins->init_state)) {
|
|
/* Not supplying this state is perfectly legal */
|
|
dev_dbg(dev, "no init pinctrl state\n");
|
|
|
|
ret = pinctrl_select_state(dev->pins->p,
|
|
dev->pins->default_state);
|
|
} else {
|
|
ret = pinctrl_select_state(dev->pins->p, dev->pins->init_state);
|
|
}
|
|
|
|
if (ret) {
|
|
dev_dbg(dev, "failed to activate initial 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;
|
|
|
|
/* Return deferrals */
|
|
if (ret == -EPROBE_DEFER)
|
|
return ret;
|
|
/* Return serious errors */
|
|
if (ret == -EINVAL)
|
|
return ret;
|
|
/* We ignore errors like -ENOENT meaning no pinctrl state */
|
|
|
|
return 0;
|
|
}
|