--- zzzz-none-000/linux-3.10.107/drivers/pnp/driver.c 2017-06-27 09:49:32.000000000 +0000 +++ scorpion-7490-727/linux-3.10.107/drivers/pnp/driver.c 2021-02-04 17:41:59.000000000 +0000 @@ -58,22 +58,22 @@ int pnp_device_attach(struct pnp_dev *pnp_dev) { - spin_lock(&pnp_lock); + mutex_lock(&pnp_lock); if (pnp_dev->status != PNP_READY) { - spin_unlock(&pnp_lock); + mutex_unlock(&pnp_lock); return -EBUSY; } pnp_dev->status = PNP_ATTACHED; - spin_unlock(&pnp_lock); + mutex_unlock(&pnp_lock); return 0; } void pnp_device_detach(struct pnp_dev *pnp_dev) { - spin_lock(&pnp_lock); + mutex_lock(&pnp_lock); if (pnp_dev->status == PNP_ATTACHED) pnp_dev->status = PNP_READY; - spin_unlock(&pnp_lock); + mutex_unlock(&pnp_lock); pnp_disable_dev(pnp_dev); } @@ -154,7 +154,7 @@ return 1; } -static int pnp_bus_suspend(struct device *dev, pm_message_t state) +static int __pnp_bus_suspend(struct device *dev, pm_message_t state) { struct pnp_dev *pnp_dev = to_pnp_dev(dev); struct pnp_driver *pnp_drv = pnp_dev->driver; @@ -163,6 +163,13 @@ if (!pnp_drv) return 0; + if (pnp_drv->driver.pm && pnp_drv->driver.pm->suspend) { + error = pnp_drv->driver.pm->suspend(dev); + suspend_report_result(pnp_drv->driver.pm->suspend, error); + if (error) + return error; + } + if (pnp_drv->suspend) { error = pnp_drv->suspend(pnp_dev, state); if (error) @@ -175,11 +182,26 @@ return error; } - if (pnp_dev->protocol->suspend) + if (pnp_can_suspend(pnp_dev)) pnp_dev->protocol->suspend(pnp_dev, state); return 0; } +static int pnp_bus_suspend(struct device *dev) +{ + return __pnp_bus_suspend(dev, PMSG_SUSPEND); +} + +static int pnp_bus_freeze(struct device *dev) +{ + return __pnp_bus_suspend(dev, PMSG_FREEZE); +} + +static int pnp_bus_poweroff(struct device *dev) +{ + return __pnp_bus_suspend(dev, PMSG_HIBERNATE); +} + static int pnp_bus_resume(struct device *dev) { struct pnp_dev *pnp_dev = to_pnp_dev(dev); @@ -201,6 +223,12 @@ return error; } + if (pnp_drv->driver.pm && pnp_drv->driver.pm->resume) { + error = pnp_drv->driver.pm->resume(dev); + if (error) + return error; + } + if (pnp_drv->resume) { error = pnp_drv->resume(pnp_dev); if (error) @@ -210,15 +238,25 @@ return 0; } +static const struct dev_pm_ops pnp_bus_dev_pm_ops = { + /* Suspend callbacks */ + .suspend = pnp_bus_suspend, + .resume = pnp_bus_resume, + /* Hibernate callbacks */ + .freeze = pnp_bus_freeze, + .thaw = pnp_bus_resume, + .poweroff = pnp_bus_poweroff, + .restore = pnp_bus_resume, +}; + struct bus_type pnp_bus_type = { .name = "pnp", .match = pnp_bus_match, .probe = pnp_device_probe, .remove = pnp_device_remove, .shutdown = pnp_device_shutdown, - .suspend = pnp_bus_suspend, - .resume = pnp_bus_resume, - .dev_attrs = pnp_interface_attrs, + .pm = &pnp_bus_dev_pm_ops, + .dev_groups = pnp_dev_groups, }; int pnp_register_driver(struct pnp_driver *drv)