2 * platform.c - platform 'pseudo' bus for legacy devices
4 * Copyright (c) 2002-3 Patrick Mochel
5 * Copyright (c) 2002-3 Open Source Development Labs
7 * This file is released under the GPLv2
9 * Please see Documentation/driver-model/platform.txt for more
13 #include <linux/string.h>
14 #include <linux/platform_device.h>
15 #include <linux/of_device.h>
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/bootmem.h>
20 #include <linux/err.h>
21 #include <linux/slab.h>
22 #include <linux/pm_runtime.h>
26 #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
29 struct device platform_bus = {
30 .init_name = "platform",
32 EXPORT_SYMBOL_GPL(platform_bus);
35 * platform_get_resource - get a resource for a device
36 * @dev: platform device
37 * @type: resource type
38 * @num: resource index
40 struct resource *platform_get_resource(struct platform_device *dev,
41 unsigned int type, unsigned int num)
45 for (i = 0; i < dev->num_resources; i++) {
46 struct resource *r = &dev->resource[i];
48 if (type == resource_type(r) && num-- == 0)
53 EXPORT_SYMBOL_GPL(platform_get_resource);
56 * platform_get_irq - get an IRQ for a device
57 * @dev: platform device
58 * @num: IRQ number index
60 int platform_get_irq(struct platform_device *dev, unsigned int num)
62 struct resource *r = platform_get_resource(dev, IORESOURCE_IRQ, num);
64 return r ? r->start : -ENXIO;
66 EXPORT_SYMBOL_GPL(platform_get_irq);
69 * platform_get_resource_byname - get a resource for a device by name
70 * @dev: platform device
71 * @type: resource type
72 * @name: resource name
74 struct resource *platform_get_resource_byname(struct platform_device *dev,
80 for (i = 0; i < dev->num_resources; i++) {
81 struct resource *r = &dev->resource[i];
83 if (type == resource_type(r) && !strcmp(r->name, name))
88 EXPORT_SYMBOL_GPL(platform_get_resource_byname);
91 * platform_get_irq - get an IRQ for a device
92 * @dev: platform device
95 int platform_get_irq_byname(struct platform_device *dev, const char *name)
97 struct resource *r = platform_get_resource_byname(dev, IORESOURCE_IRQ,
100 return r ? r->start : -ENXIO;
102 EXPORT_SYMBOL_GPL(platform_get_irq_byname);
105 * platform_add_devices - add a numbers of platform devices
106 * @devs: array of platform devices to add
107 * @num: number of platform devices in array
109 int platform_add_devices(struct platform_device **devs, int num)
113 for (i = 0; i < num; i++) {
114 ret = platform_device_register(devs[i]);
117 platform_device_unregister(devs[i]);
124 EXPORT_SYMBOL_GPL(platform_add_devices);
126 struct platform_object {
127 struct platform_device pdev;
132 * platform_device_put - destroy a platform device
133 * @pdev: platform device to free
135 * Free all memory associated with a platform device. This function must
136 * _only_ be externally called in error cases. All other usage is a bug.
138 void platform_device_put(struct platform_device *pdev)
141 put_device(&pdev->dev);
143 EXPORT_SYMBOL_GPL(platform_device_put);
145 static void platform_device_release(struct device *dev)
147 struct platform_object *pa = container_of(dev, struct platform_object,
150 of_device_node_put(&pa->pdev.dev);
151 kfree(pa->pdev.dev.platform_data);
152 kfree(pa->pdev.mfd_cell);
153 kfree(pa->pdev.resource);
158 * platform_device_alloc - create a platform device
159 * @name: base name of the device we're adding
162 * Create a platform device object which can have other objects attached
163 * to it, and which will have attached objects freed when it is released.
165 struct platform_device *platform_device_alloc(const char *name, int id)
167 struct platform_object *pa;
169 pa = kzalloc(sizeof(struct platform_object) + strlen(name), GFP_KERNEL);
171 strcpy(pa->name, name);
172 pa->pdev.name = pa->name;
174 device_initialize(&pa->pdev.dev);
175 pa->pdev.dev.release = platform_device_release;
178 return pa ? &pa->pdev : NULL;
180 EXPORT_SYMBOL_GPL(platform_device_alloc);
183 * platform_device_add_resources - add resources to a platform device
184 * @pdev: platform device allocated by platform_device_alloc to add resources to
185 * @res: set of resources that needs to be allocated for the device
186 * @num: number of resources
188 * Add a copy of the resources to the platform device. The memory
189 * associated with the resources will be freed when the platform device is
192 int platform_device_add_resources(struct platform_device *pdev,
193 const struct resource *res, unsigned int num)
195 struct resource *r = NULL;
198 r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
203 kfree(pdev->resource);
205 pdev->num_resources = num;
208 EXPORT_SYMBOL_GPL(platform_device_add_resources);
211 * platform_device_add_data - add platform-specific data to a platform device
212 * @pdev: platform device allocated by platform_device_alloc to add resources to
213 * @data: platform specific data for this platform device
214 * @size: size of platform specific data
216 * Add a copy of platform specific data to the platform device's
217 * platform_data pointer. The memory associated with the platform data
218 * will be freed when the platform device is released.
220 int platform_device_add_data(struct platform_device *pdev, const void *data,
226 d = kmemdup(data, size, GFP_KERNEL);
231 kfree(pdev->dev.platform_data);
232 pdev->dev.platform_data = d;
235 EXPORT_SYMBOL_GPL(platform_device_add_data);
238 * platform_device_add - add a platform device to device hierarchy
239 * @pdev: platform device we're adding
241 * This is part 2 of platform_device_register(), though may be called
242 * separately _iff_ pdev was allocated by platform_device_alloc().
244 int platform_device_add(struct platform_device *pdev)
251 if (!pdev->dev.parent)
252 pdev->dev.parent = &platform_bus;
254 pdev->dev.bus = &platform_bus_type;
257 dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
259 dev_set_name(&pdev->dev, "%s", pdev->name);
261 for (i = 0; i < pdev->num_resources; i++) {
262 struct resource *p, *r = &pdev->resource[i];
265 r->name = dev_name(&pdev->dev);
269 if (resource_type(r) == IORESOURCE_MEM)
271 else if (resource_type(r) == IORESOURCE_IO)
272 p = &ioport_resource;
275 if (p && insert_resource(p, r)) {
277 "%s: failed to claim resource %d\n",
278 dev_name(&pdev->dev), i);
284 pr_debug("Registering platform device '%s'. Parent at %s\n",
285 dev_name(&pdev->dev), dev_name(pdev->dev.parent));
287 ret = device_add(&pdev->dev);
293 struct resource *r = &pdev->resource[i];
294 unsigned long type = resource_type(r);
296 if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
302 EXPORT_SYMBOL_GPL(platform_device_add);
305 * platform_device_del - remove a platform-level device
306 * @pdev: platform device we're removing
308 * Note that this function will also release all memory- and port-based
309 * resources owned by the device (@dev->resource). This function must
310 * _only_ be externally called in error cases. All other usage is a bug.
312 void platform_device_del(struct platform_device *pdev)
317 device_del(&pdev->dev);
319 for (i = 0; i < pdev->num_resources; i++) {
320 struct resource *r = &pdev->resource[i];
321 unsigned long type = resource_type(r);
323 if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
328 EXPORT_SYMBOL_GPL(platform_device_del);
331 * platform_device_register - add a platform-level device
332 * @pdev: platform device we're adding
334 int platform_device_register(struct platform_device *pdev)
336 device_initialize(&pdev->dev);
337 return platform_device_add(pdev);
339 EXPORT_SYMBOL_GPL(platform_device_register);
342 * platform_device_unregister - unregister a platform-level device
343 * @pdev: platform device we're unregistering
345 * Unregistration is done in 2 steps. First we release all resources
346 * and remove it from the subsystem, then we drop reference count by
347 * calling platform_device_put().
349 void platform_device_unregister(struct platform_device *pdev)
351 platform_device_del(pdev);
352 platform_device_put(pdev);
354 EXPORT_SYMBOL_GPL(platform_device_unregister);
357 * platform_device_register_resndata - add a platform-level device with
358 * resources and platform-specific data
360 * @parent: parent device for the device we're adding
361 * @name: base name of the device we're adding
363 * @res: set of resources that needs to be allocated for the device
364 * @num: number of resources
365 * @data: platform specific data for this platform device
366 * @size: size of platform specific data
368 * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
370 struct platform_device *platform_device_register_resndata(
371 struct device *parent,
372 const char *name, int id,
373 const struct resource *res, unsigned int num,
374 const void *data, size_t size)
377 struct platform_device *pdev;
379 pdev = platform_device_alloc(name, id);
383 pdev->dev.parent = parent;
385 ret = platform_device_add_resources(pdev, res, num);
389 ret = platform_device_add_data(pdev, data, size);
393 ret = platform_device_add(pdev);
396 platform_device_put(pdev);
402 EXPORT_SYMBOL_GPL(platform_device_register_resndata);
404 static int platform_drv_probe(struct device *_dev)
406 struct platform_driver *drv = to_platform_driver(_dev->driver);
407 struct platform_device *dev = to_platform_device(_dev);
409 return drv->probe(dev);
412 static int platform_drv_probe_fail(struct device *_dev)
417 static int platform_drv_remove(struct device *_dev)
419 struct platform_driver *drv = to_platform_driver(_dev->driver);
420 struct platform_device *dev = to_platform_device(_dev);
422 return drv->remove(dev);
425 static void platform_drv_shutdown(struct device *_dev)
427 struct platform_driver *drv = to_platform_driver(_dev->driver);
428 struct platform_device *dev = to_platform_device(_dev);
434 * platform_driver_register - register a driver for platform-level devices
435 * @drv: platform driver structure
437 int platform_driver_register(struct platform_driver *drv)
439 drv->driver.bus = &platform_bus_type;
441 drv->driver.probe = platform_drv_probe;
443 drv->driver.remove = platform_drv_remove;
445 drv->driver.shutdown = platform_drv_shutdown;
447 return driver_register(&drv->driver);
449 EXPORT_SYMBOL_GPL(platform_driver_register);
452 * platform_driver_unregister - unregister a driver for platform-level devices
453 * @drv: platform driver structure
455 void platform_driver_unregister(struct platform_driver *drv)
457 driver_unregister(&drv->driver);
459 EXPORT_SYMBOL_GPL(platform_driver_unregister);
462 * platform_driver_probe - register driver for non-hotpluggable device
463 * @drv: platform driver structure
464 * @probe: the driver probe routine, probably from an __init section
466 * Use this instead of platform_driver_register() when you know the device
467 * is not hotpluggable and has already been registered, and you want to
468 * remove its run-once probe() infrastructure from memory after the driver
469 * has bound to the device.
471 * One typical use for this would be with drivers for controllers integrated
472 * into system-on-chip processors, where the controller devices have been
473 * configured as part of board setup.
475 * Returns zero if the driver registered and bound to a device, else returns
476 * a negative error code and with the driver not registered.
478 int __init_or_module platform_driver_probe(struct platform_driver *drv,
479 int (*probe)(struct platform_device *))
483 /* make sure driver won't have bind/unbind attributes */
484 drv->driver.suppress_bind_attrs = true;
486 /* temporary section violation during probe() */
488 retval = code = platform_driver_register(drv);
491 * Fixup that section violation, being paranoid about code scanning
492 * the list of drivers in order to probe new devices. Check to see
493 * if the probe was successful, and make sure any forced probes of
496 spin_lock(&drv->driver.bus->p->klist_drivers.k_lock);
498 if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
500 drv->driver.probe = platform_drv_probe_fail;
501 spin_unlock(&drv->driver.bus->p->klist_drivers.k_lock);
504 platform_driver_unregister(drv);
507 EXPORT_SYMBOL_GPL(platform_driver_probe);
510 * platform_create_bundle - register driver and create corresponding device
511 * @driver: platform driver structure
512 * @probe: the driver probe routine, probably from an __init section
513 * @res: set of resources that needs to be allocated for the device
514 * @n_res: number of resources
515 * @data: platform specific data for this platform device
516 * @size: size of platform specific data
518 * Use this in legacy-style modules that probe hardware directly and
519 * register a single platform device and corresponding platform driver.
521 * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
523 struct platform_device * __init_or_module platform_create_bundle(
524 struct platform_driver *driver,
525 int (*probe)(struct platform_device *),
526 struct resource *res, unsigned int n_res,
527 const void *data, size_t size)
529 struct platform_device *pdev;
532 pdev = platform_device_alloc(driver->driver.name, -1);
538 error = platform_device_add_resources(pdev, res, n_res);
542 error = platform_device_add_data(pdev, data, size);
546 error = platform_device_add(pdev);
550 error = platform_driver_probe(driver, probe);
557 platform_device_del(pdev);
559 platform_device_put(pdev);
561 return ERR_PTR(error);
563 EXPORT_SYMBOL_GPL(platform_create_bundle);
565 /* modalias support enables more hands-off userspace setup:
566 * (a) environment variable lets new-style hotplug events work once system is
567 * fully running: "modprobe $MODALIAS"
568 * (b) sysfs attribute lets new-style coldplug recover from hotplug events
569 * mishandled before system is fully running: "modprobe $(cat modalias)"
571 static ssize_t modalias_show(struct device *dev, struct device_attribute *a,
574 struct platform_device *pdev = to_platform_device(dev);
575 int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);
577 return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;
580 static struct device_attribute platform_dev_attrs[] = {
585 static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
587 struct platform_device *pdev = to_platform_device(dev);
590 /* Some devices have extra OF data and an OF-style MODALIAS */
591 rc = of_device_uevent(dev,env);
595 add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
596 (pdev->id_entry) ? pdev->id_entry->name : pdev->name);
600 static const struct platform_device_id *platform_match_id(
601 const struct platform_device_id *id,
602 struct platform_device *pdev)
604 while (id->name[0]) {
605 if (strcmp(pdev->name, id->name) == 0) {
615 * platform_match - bind platform device to platform driver.
619 * Platform device IDs are assumed to be encoded like this:
620 * "<name><instance>", where <name> is a short description of the type of
621 * device, like "pci" or "floppy", and <instance> is the enumerated
622 * instance of the device, like '0' or '42'. Driver IDs are simply
623 * "<name>". So, extract the <name> from the platform_device structure,
624 * and compare it against the name of the driver. Return whether they match
627 static int platform_match(struct device *dev, struct device_driver *drv)
629 struct platform_device *pdev = to_platform_device(dev);
630 struct platform_driver *pdrv = to_platform_driver(drv);
632 /* Attempt an OF style match first */
633 if (of_driver_match_device(dev, drv))
636 /* Then try to match against the id table */
638 return platform_match_id(pdrv->id_table, pdev) != NULL;
640 /* fall-back to driver name match */
641 return (strcmp(pdev->name, drv->name) == 0);
644 #ifdef CONFIG_PM_SLEEP
646 static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
648 struct platform_driver *pdrv = to_platform_driver(dev->driver);
649 struct platform_device *pdev = to_platform_device(dev);
652 if (dev->driver && pdrv->suspend)
653 ret = pdrv->suspend(pdev, mesg);
658 static int platform_legacy_resume(struct device *dev)
660 struct platform_driver *pdrv = to_platform_driver(dev->driver);
661 struct platform_device *pdev = to_platform_device(dev);
664 if (dev->driver && pdrv->resume)
665 ret = pdrv->resume(pdev);
670 int platform_pm_prepare(struct device *dev)
672 struct device_driver *drv = dev->driver;
675 if (drv && drv->pm && drv->pm->prepare)
676 ret = drv->pm->prepare(dev);
681 void platform_pm_complete(struct device *dev)
683 struct device_driver *drv = dev->driver;
685 if (drv && drv->pm && drv->pm->complete)
686 drv->pm->complete(dev);
689 #endif /* CONFIG_PM_SLEEP */
691 #ifdef CONFIG_SUSPEND
693 int platform_pm_suspend(struct device *dev)
695 struct device_driver *drv = dev->driver;
702 if (drv->pm->suspend)
703 ret = drv->pm->suspend(dev);
705 ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
711 int platform_pm_suspend_noirq(struct device *dev)
713 struct device_driver *drv = dev->driver;
720 if (drv->pm->suspend_noirq)
721 ret = drv->pm->suspend_noirq(dev);
727 int platform_pm_resume(struct device *dev)
729 struct device_driver *drv = dev->driver;
737 ret = drv->pm->resume(dev);
739 ret = platform_legacy_resume(dev);
745 int platform_pm_resume_noirq(struct device *dev)
747 struct device_driver *drv = dev->driver;
754 if (drv->pm->resume_noirq)
755 ret = drv->pm->resume_noirq(dev);
761 #endif /* CONFIG_SUSPEND */
763 #ifdef CONFIG_HIBERNATE_CALLBACKS
765 int platform_pm_freeze(struct device *dev)
767 struct device_driver *drv = dev->driver;
775 ret = drv->pm->freeze(dev);
777 ret = platform_legacy_suspend(dev, PMSG_FREEZE);
783 int platform_pm_freeze_noirq(struct device *dev)
785 struct device_driver *drv = dev->driver;
792 if (drv->pm->freeze_noirq)
793 ret = drv->pm->freeze_noirq(dev);
799 int platform_pm_thaw(struct device *dev)
801 struct device_driver *drv = dev->driver;
809 ret = drv->pm->thaw(dev);
811 ret = platform_legacy_resume(dev);
817 int platform_pm_thaw_noirq(struct device *dev)
819 struct device_driver *drv = dev->driver;
826 if (drv->pm->thaw_noirq)
827 ret = drv->pm->thaw_noirq(dev);
833 int platform_pm_poweroff(struct device *dev)
835 struct device_driver *drv = dev->driver;
842 if (drv->pm->poweroff)
843 ret = drv->pm->poweroff(dev);
845 ret = platform_legacy_suspend(dev, PMSG_HIBERNATE);
851 int platform_pm_poweroff_noirq(struct device *dev)
853 struct device_driver *drv = dev->driver;
860 if (drv->pm->poweroff_noirq)
861 ret = drv->pm->poweroff_noirq(dev);
867 int platform_pm_restore(struct device *dev)
869 struct device_driver *drv = dev->driver;
876 if (drv->pm->restore)
877 ret = drv->pm->restore(dev);
879 ret = platform_legacy_resume(dev);
885 int platform_pm_restore_noirq(struct device *dev)
887 struct device_driver *drv = dev->driver;
894 if (drv->pm->restore_noirq)
895 ret = drv->pm->restore_noirq(dev);
901 #endif /* CONFIG_HIBERNATE_CALLBACKS */
903 static const struct dev_pm_ops platform_dev_pm_ops = {
904 .runtime_suspend = pm_generic_runtime_suspend,
905 .runtime_resume = pm_generic_runtime_resume,
906 .runtime_idle = pm_generic_runtime_idle,
907 USE_PLATFORM_PM_SLEEP_OPS
910 struct bus_type platform_bus_type = {
912 .dev_attrs = platform_dev_attrs,
913 .match = platform_match,
914 .uevent = platform_uevent,
915 .pm = &platform_dev_pm_ops,
917 EXPORT_SYMBOL_GPL(platform_bus_type);
919 int __init platform_bus_init(void)
923 early_platform_cleanup();
925 error = device_register(&platform_bus);
928 error = bus_register(&platform_bus_type);
930 device_unregister(&platform_bus);
934 #ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
935 u64 dma_get_required_mask(struct device *dev)
937 u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT);
938 u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT));
941 if (!high_totalram) {
942 /* convert to mask just covering totalram */
943 low_totalram = (1 << (fls(low_totalram) - 1));
944 low_totalram += low_totalram - 1;
947 high_totalram = (1 << (fls(high_totalram) - 1));
948 high_totalram += high_totalram - 1;
949 mask = (((u64)high_totalram) << 32) + 0xffffffff;
953 EXPORT_SYMBOL_GPL(dma_get_required_mask);
956 static __initdata LIST_HEAD(early_platform_driver_list);
957 static __initdata LIST_HEAD(early_platform_device_list);
960 * early_platform_driver_register - register early platform driver
961 * @epdrv: early_platform driver structure
962 * @buf: string passed from early_param()
964 * Helper function for early_platform_init() / early_platform_init_buffer()
966 int __init early_platform_driver_register(struct early_platform_driver *epdrv,
972 /* Simply add the driver to the end of the global list.
973 * Drivers will by default be put on the list in compiled-in order.
975 if (!epdrv->list.next) {
976 INIT_LIST_HEAD(&epdrv->list);
977 list_add_tail(&epdrv->list, &early_platform_driver_list);
980 /* If the user has specified device then make sure the driver
981 * gets prioritized. The driver of the last device specified on
982 * command line will be put first on the list.
984 n = strlen(epdrv->pdrv->driver.name);
985 if (buf && !strncmp(buf, epdrv->pdrv->driver.name, n)) {
986 list_move(&epdrv->list, &early_platform_driver_list);
988 /* Allow passing parameters after device name */
989 if (buf[n] == '\0' || buf[n] == ',')
990 epdrv->requested_id = -1;
992 epdrv->requested_id = simple_strtoul(&buf[n + 1],
995 if (buf[n] != '.' || (tmp == &buf[n + 1])) {
996 epdrv->requested_id = EARLY_PLATFORM_ID_ERROR;
999 n += strcspn(&buf[n + 1], ",") + 1;
1005 if (epdrv->bufsize) {
1006 memcpy(epdrv->buffer, &buf[n],
1007 min_t(int, epdrv->bufsize, strlen(&buf[n]) + 1));
1008 epdrv->buffer[epdrv->bufsize - 1] = '\0';
1016 * early_platform_add_devices - adds a number of early platform devices
1017 * @devs: array of early platform devices to add
1018 * @num: number of early platform devices in array
1020 * Used by early architecture code to register early platform devices and
1021 * their platform data.
1023 void __init early_platform_add_devices(struct platform_device **devs, int num)
1028 /* simply add the devices to list */
1029 for (i = 0; i < num; i++) {
1030 dev = &devs[i]->dev;
1032 if (!dev->devres_head.next) {
1033 INIT_LIST_HEAD(&dev->devres_head);
1034 list_add_tail(&dev->devres_head,
1035 &early_platform_device_list);
1041 * early_platform_driver_register_all - register early platform drivers
1042 * @class_str: string to identify early platform driver class
1044 * Used by architecture code to register all early platform drivers
1045 * for a certain class. If omitted then only early platform drivers
1046 * with matching kernel command line class parameters will be registered.
1048 void __init early_platform_driver_register_all(char *class_str)
1050 /* The "class_str" parameter may or may not be present on the kernel
1051 * command line. If it is present then there may be more than one
1052 * matching parameter.
1054 * Since we register our early platform drivers using early_param()
1055 * we need to make sure that they also get registered in the case
1056 * when the parameter is missing from the kernel command line.
1058 * We use parse_early_options() to make sure the early_param() gets
1059 * called at least once. The early_param() may be called more than
1060 * once since the name of the preferred device may be specified on
1061 * the kernel command line. early_platform_driver_register() handles
1064 parse_early_options(class_str);
1068 * early_platform_match - find early platform device matching driver
1069 * @epdrv: early platform driver structure
1070 * @id: id to match against
1072 static __init struct platform_device *
1073 early_platform_match(struct early_platform_driver *epdrv, int id)
1075 struct platform_device *pd;
1077 list_for_each_entry(pd, &early_platform_device_list, dev.devres_head)
1078 if (platform_match(&pd->dev, &epdrv->pdrv->driver))
1086 * early_platform_left - check if early platform driver has matching devices
1087 * @epdrv: early platform driver structure
1088 * @id: return true if id or above exists
1090 static __init int early_platform_left(struct early_platform_driver *epdrv,
1093 struct platform_device *pd;
1095 list_for_each_entry(pd, &early_platform_device_list, dev.devres_head)
1096 if (platform_match(&pd->dev, &epdrv->pdrv->driver))
1104 * early_platform_driver_probe_id - probe drivers matching class_str and id
1105 * @class_str: string to identify early platform driver class
1106 * @id: id to match against
1107 * @nr_probe: number of platform devices to successfully probe before exiting
1109 static int __init early_platform_driver_probe_id(char *class_str,
1113 struct early_platform_driver *epdrv;
1114 struct platform_device *match;
1119 list_for_each_entry(epdrv, &early_platform_driver_list, list) {
1120 /* only use drivers matching our class_str */
1121 if (strcmp(class_str, epdrv->class_str))
1125 match_id = epdrv->requested_id;
1130 left += early_platform_left(epdrv, id);
1132 /* skip requested id */
1133 switch (epdrv->requested_id) {
1134 case EARLY_PLATFORM_ID_ERROR:
1135 case EARLY_PLATFORM_ID_UNSET:
1138 if (epdrv->requested_id == id)
1139 match_id = EARLY_PLATFORM_ID_UNSET;
1144 case EARLY_PLATFORM_ID_ERROR:
1145 pr_warning("%s: unable to parse %s parameter\n",
1146 class_str, epdrv->pdrv->driver.name);
1148 case EARLY_PLATFORM_ID_UNSET:
1152 match = early_platform_match(epdrv, match_id);
1157 * Set up a sensible init_name to enable
1158 * dev_name() and others to be used before the
1159 * rest of the driver core is initialized.
1161 if (!match->dev.init_name && slab_is_available()) {
1162 if (match->id != -1)
1163 match->dev.init_name =
1164 kasprintf(GFP_KERNEL, "%s.%d",
1168 match->dev.init_name =
1169 kasprintf(GFP_KERNEL, "%s",
1172 if (!match->dev.init_name)
1176 if (epdrv->pdrv->probe(match))
1177 pr_warning("%s: unable to probe %s early.\n",
1178 class_str, match->name);
1194 * early_platform_driver_probe - probe a class of registered drivers
1195 * @class_str: string to identify early platform driver class
1196 * @nr_probe: number of platform devices to successfully probe before exiting
1197 * @user_only: only probe user specified early platform devices
1199 * Used by architecture code to probe registered early platform drivers
1200 * within a certain class. For probe to happen a registered early platform
1201 * device matching a registered early platform driver is needed.
1203 int __init early_platform_driver_probe(char *class_str,
1210 for (i = -2; n < nr_probe; i++) {
1211 k = early_platform_driver_probe_id(class_str, i, nr_probe - n);
1226 * early_platform_cleanup - clean up early platform code
1228 void __init early_platform_cleanup(void)
1230 struct platform_device *pd, *pd2;
1232 /* clean up the devres list used to chain devices */
1233 list_for_each_entry_safe(pd, pd2, &early_platform_device_list,
1235 list_del(&pd->dev.devres_head);
1236 memset(&pd->dev.devres_head, 0, sizeof(pd->dev.devres_head));