13 #include <linux/string.h>
16 #include <linux/module.h>
21 #include <linux/slab.h>
26 #include "power/power.h"
31 #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
35 .init_name =
"platform",
65 unsigned int type,
unsigned int num)
88 if (!dev || num >= dev->
archdata.num_irqs)
147 for (i = 0; i < num; i++) {
179 static void platform_device_release(
struct device *
dev)
184 of_device_node_put(&pa->
pdev.dev);
209 pa->
pdev.dev.release = platform_device_release;
267 pdev->
dev.platform_data =
d;
286 if (!pdev->
dev.parent)
317 r->
name = dev_name(&pdev->
dev);
329 "%s: failed to claim resource %d\n",
330 dev_name(&pdev->
dev), i);
336 pr_debug(
"Registering platform device '%s'. Parent at %s\n",
337 dev_name(&pdev->
dev), dev_name(pdev->
dev.parent));
449 if (!pdev->
dev.dma_mask)
480 static int platform_drv_probe(
struct device *_dev)
485 return drv->
probe(dev);
488 static int platform_drv_probe_fail(
struct device *_dev)
493 static int platform_drv_remove(
struct device *_dev)
501 static void platform_drv_shutdown(
struct device *_dev)
517 drv->
driver.probe = platform_drv_probe;
519 drv->
driver.remove = platform_drv_remove;
521 drv->
driver.shutdown = platform_drv_shutdown;
560 drv->
driver.suppress_bind_attrs =
true;
572 spin_lock(&drv->
driver.bus->p->klist_drivers.k_lock);
574 if (code == 0 && list_empty(&drv->
driver.p->klist_devices.k_list))
576 drv->
driver.probe = platform_drv_probe_fail;
577 spin_unlock(&drv->
driver.bus->p->klist_drivers.k_lock);
637 return ERR_PTR(error);
680 while (id->
name[0]) {
709 if (of_driver_match_device(dev, drv))
720 #ifdef CONFIG_PM_SLEEP
729 ret = pdrv->
suspend(pdev, mesg);
734 static int platform_legacy_resume(
struct device *dev)
748 #ifdef CONFIG_SUSPEND
759 if (drv->
pm->suspend)
760 ret = drv->
pm->suspend(dev);
778 ret = drv->
pm->resume(dev);
780 ret = platform_legacy_resume(dev);
788 #ifdef CONFIG_HIBERNATE_CALLBACKS
800 ret = drv->
pm->freeze(dev);
818 ret = drv->
pm->thaw(dev);
820 ret = platform_legacy_resume(dev);
835 if (drv->
pm->poweroff)
836 ret = drv->
pm->poweroff(dev);
853 if (drv->
pm->restore)
854 ret = drv->
pm->restore(dev);
856 ret = platform_legacy_resume(dev);
864 static const struct dev_pm_ops platform_dev_pm_ops = {
865 .runtime_suspend = pm_generic_runtime_suspend,
866 .runtime_resume = pm_generic_runtime_resume,
867 .runtime_idle = pm_generic_runtime_idle,
873 .dev_attrs = platform_dev_attrs,
874 .match = platform_match,
875 .uevent = platform_uevent,
876 .pm = &platform_dev_pm_ops,
895 #ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
902 if (!high_totalram) {
904 low_totalram = (1 << (fls(low_totalram) - 1));
905 low_totalram += low_totalram - 1;
908 high_totalram = (1 << (fls(high_totalram) - 1));
909 high_totalram += high_totalram - 1;
910 mask = (((
u64)high_totalram) << 32) + 0xffffffff;
936 if (!epdrv->
list.next) {
937 INIT_LIST_HEAD(&epdrv->
list);
946 if (buf && !
strncmp(buf, epdrv->
pdrv->driver.name, n)) {
947 list_move(&epdrv->
list, &early_platform_driver_list);
950 if (buf[n] ==
'\0' || buf[n] ==
',')
956 if (buf[n] !=
'.' || (tmp == &buf[n + 1])) {
960 n +=
strcspn(&buf[n + 1],
",") + 1;
990 for (i = 0; i < num; i++) {
994 pm_runtime_early_init(dev);
997 &early_platform_device_list);
1040 if (platform_match(&pd->dev, &epdrv->pdrv->driver))
1058 if (platform_match(&pd->dev, &epdrv->pdrv->driver))
1071 static
int __init early_platform_driver_probe_id(
char *class_str,
1092 left += early_platform_left(epdrv,
id);
1107 pr_warning(
"%s: unable to parse %s parameter\n",
1108 class_str, epdrv->
pdrv->driver.name);
1114 match = early_platform_match(epdrv, match_id);
1124 if (match->
id != -1)
1125 match->
dev.init_name =
1130 match->
dev.init_name =
1134 if (!match->
dev.init_name)
1138 if (epdrv->
pdrv->probe(match))
1139 pr_warning(
"%s: unable to probe %s early.\n",
1140 class_str, match->
name);
1172 for (i = -2; n < nr_probe; i++) {
1173 k = early_platform_driver_probe_id(class_str, i, nr_probe - n);
1198 memset(&pd->
dev.devres_head, 0,
sizeof(pd->
dev.devres_head));