diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c index 566665931a04..c05799d1cc21 100644 --- a/drivers/pinctrl/pinctrl-sx150x.c +++ b/drivers/pinctrl/pinctrl-sx150x.c @@ -1,5 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* + * Copyright (c) 2019, The Linux Foundation. All rights reserved. + * * Copyright (c) 2016, BayLibre, SAS. All rights reserved. * Author: Neil Armstrong * @@ -1243,10 +1245,47 @@ static int sx150x_probe(struct i2c_client *client, return 0; } +#ifdef CONFIG_PM_SLEEP +static int sx150x_restore(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sx150x_pinctrl *pctl = i2c_get_clientdata(client); + int ret; + + ret = sx150x_init_hw(pctl); + if (ret) + return ret; + + ret = pinctrl_force_default(pctl->pctldev); + if (ret) { + dev_err(dev, "Failed to enable pinctrl device\n"); + return ret; + } + + if (client->irq > 0) { + mutex_lock(&pctl->lock); + regmap_write(pctl->regmap, + pctl->data->reg_irq_mask, pctl->irq.masked); + regmap_write(pctl->regmap, + pctl->data->reg_sense, pctl->irq.sense); + mutex_unlock(&pctl->lock); + } + + return 0; +} + +static const struct dev_pm_ops sx150x_pm = { + .restore = sx150x_restore, +}; +#endif + static struct i2c_driver sx150x_driver = { .driver = { .name = "sx150x-pinctrl", .of_match_table = of_match_ptr(sx150x_of_match), +#ifdef CONFIG_PM_SLEEP + .pm = &sx150x_pm, +#endif }, .probe = sx150x_probe, .id_table = sx150x_id,