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/module.h>
16 #include <linux/init.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/bootmem.h>
19 #include <linux/err.h>
20 #include <linux/slab.h>
21 #include <linux/pm_runtime.h>
25 #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
28 struct device platform_bus
= {
29 .init_name
= "platform",
31 EXPORT_SYMBOL_GPL(platform_bus
);
34 * platform_get_resource - get a resource for a device
35 * @dev: platform device
36 * @type: resource type
37 * @num: resource index
39 struct resource
*platform_get_resource(struct platform_device
*dev
,
40 unsigned int type
, unsigned int num
)
44 for (i
= 0; i
< dev
->num_resources
; i
++) {
45 struct resource
*r
= &dev
->resource
[i
];
47 if (type
== resource_type(r
) && num
-- == 0)
52 EXPORT_SYMBOL_GPL(platform_get_resource
);
55 * platform_get_irq - get an IRQ for a device
56 * @dev: platform device
57 * @num: IRQ number index
59 int platform_get_irq(struct platform_device
*dev
, unsigned int num
)
61 struct resource
*r
= platform_get_resource(dev
, IORESOURCE_IRQ
, num
);
63 return r
? r
->start
: -ENXIO
;
65 EXPORT_SYMBOL_GPL(platform_get_irq
);
68 * platform_get_resource_byname - get a resource for a device by name
69 * @dev: platform device
70 * @type: resource type
71 * @name: resource name
73 struct resource
*platform_get_resource_byname(struct platform_device
*dev
,
79 for (i
= 0; i
< dev
->num_resources
; i
++) {
80 struct resource
*r
= &dev
->resource
[i
];
82 if (type
== resource_type(r
) && !strcmp(r
->name
, name
))
87 EXPORT_SYMBOL_GPL(platform_get_resource_byname
);
90 * platform_get_irq - get an IRQ for a device
91 * @dev: platform device
94 int platform_get_irq_byname(struct platform_device
*dev
, const char *name
)
96 struct resource
*r
= platform_get_resource_byname(dev
, IORESOURCE_IRQ
,
99 return r
? r
->start
: -ENXIO
;
101 EXPORT_SYMBOL_GPL(platform_get_irq_byname
);
104 * platform_add_devices - add a numbers of platform devices
105 * @devs: array of platform devices to add
106 * @num: number of platform devices in array
108 int platform_add_devices(struct platform_device
**devs
, int num
)
112 for (i
= 0; i
< num
; i
++) {
113 ret
= platform_device_register(devs
[i
]);
116 platform_device_unregister(devs
[i
]);
123 EXPORT_SYMBOL_GPL(platform_add_devices
);
125 struct platform_object
{
126 struct platform_device pdev
;
131 * platform_device_put
132 * @pdev: platform device to free
134 * Free all memory associated with a platform device. This function must
135 * _only_ be externally called in error cases. All other usage is a bug.
137 void platform_device_put(struct platform_device
*pdev
)
140 put_device(&pdev
->dev
);
142 EXPORT_SYMBOL_GPL(platform_device_put
);
144 static void platform_device_release(struct device
*dev
)
146 struct platform_object
*pa
= container_of(dev
, struct platform_object
,
149 kfree(pa
->pdev
.dev
.platform_data
);
150 kfree(pa
->pdev
.resource
);
155 * platform_device_alloc
156 * @name: base name of the device we're adding
159 * Create a platform device object which can have other objects attached
160 * to it, and which will have attached objects freed when it is released.
162 struct platform_device
*platform_device_alloc(const char *name
, int id
)
164 struct platform_object
*pa
;
166 pa
= kzalloc(sizeof(struct platform_object
) + strlen(name
), GFP_KERNEL
);
168 strcpy(pa
->name
, name
);
169 pa
->pdev
.name
= pa
->name
;
171 device_initialize(&pa
->pdev
.dev
);
172 pa
->pdev
.dev
.release
= platform_device_release
;
175 return pa
? &pa
->pdev
: NULL
;
177 EXPORT_SYMBOL_GPL(platform_device_alloc
);
180 * platform_device_add_resources
181 * @pdev: platform device allocated by platform_device_alloc to add resources to
182 * @res: set of resources that needs to be allocated for the device
183 * @num: number of resources
185 * Add a copy of the resources to the platform device. The memory
186 * associated with the resources will be freed when the platform device is
189 int platform_device_add_resources(struct platform_device
*pdev
,
190 struct resource
*res
, unsigned int num
)
194 r
= kmalloc(sizeof(struct resource
) * num
, GFP_KERNEL
);
196 memcpy(r
, res
, sizeof(struct resource
) * num
);
198 pdev
->num_resources
= num
;
200 return r
? 0 : -ENOMEM
;
202 EXPORT_SYMBOL_GPL(platform_device_add_resources
);
205 * platform_device_add_data
206 * @pdev: platform device allocated by platform_device_alloc to add resources to
207 * @data: platform specific data for this platform device
208 * @size: size of platform specific data
210 * Add a copy of platform specific data to the platform device's
211 * platform_data pointer. The memory associated with the platform data
212 * will be freed when the platform device is released.
214 int platform_device_add_data(struct platform_device
*pdev
, const void *data
,
217 void *d
= kmemdup(data
, size
, GFP_KERNEL
);
220 pdev
->dev
.platform_data
= d
;
225 EXPORT_SYMBOL_GPL(platform_device_add_data
);
228 * platform_device_add - add a platform device to device hierarchy
229 * @pdev: platform device we're adding
231 * This is part 2 of platform_device_register(), though may be called
232 * separately _iff_ pdev was allocated by platform_device_alloc().
234 int platform_device_add(struct platform_device
*pdev
)
241 if (!pdev
->dev
.parent
)
242 pdev
->dev
.parent
= &platform_bus
;
244 pdev
->dev
.bus
= &platform_bus_type
;
247 dev_set_name(&pdev
->dev
, "%s.%d", pdev
->name
, pdev
->id
);
249 dev_set_name(&pdev
->dev
, "%s", pdev
->name
);
251 for (i
= 0; i
< pdev
->num_resources
; i
++) {
252 struct resource
*p
, *r
= &pdev
->resource
[i
];
255 r
->name
= dev_name(&pdev
->dev
);
259 if (resource_type(r
) == IORESOURCE_MEM
)
261 else if (resource_type(r
) == IORESOURCE_IO
)
262 p
= &ioport_resource
;
265 if (p
&& insert_resource(p
, r
)) {
267 "%s: failed to claim resource %d\n",
268 dev_name(&pdev
->dev
), i
);
274 pr_debug("Registering platform device '%s'. Parent at %s\n",
275 dev_name(&pdev
->dev
), dev_name(pdev
->dev
.parent
));
277 ret
= device_add(&pdev
->dev
);
283 struct resource
*r
= &pdev
->resource
[i
];
284 unsigned long type
= resource_type(r
);
286 if (type
== IORESOURCE_MEM
|| type
== IORESOURCE_IO
)
292 EXPORT_SYMBOL_GPL(platform_device_add
);
295 * platform_device_del - remove a platform-level device
296 * @pdev: platform device we're removing
298 * Note that this function will also release all memory- and port-based
299 * resources owned by the device (@dev->resource). This function must
300 * _only_ be externally called in error cases. All other usage is a bug.
302 void platform_device_del(struct platform_device
*pdev
)
307 device_del(&pdev
->dev
);
309 for (i
= 0; i
< pdev
->num_resources
; i
++) {
310 struct resource
*r
= &pdev
->resource
[i
];
311 unsigned long type
= resource_type(r
);
313 if (type
== IORESOURCE_MEM
|| type
== IORESOURCE_IO
)
318 EXPORT_SYMBOL_GPL(platform_device_del
);
321 * platform_device_register - add a platform-level device
322 * @pdev: platform device we're adding
324 int platform_device_register(struct platform_device
*pdev
)
326 device_initialize(&pdev
->dev
);
327 return platform_device_add(pdev
);
329 EXPORT_SYMBOL_GPL(platform_device_register
);
332 * platform_device_unregister - unregister a platform-level device
333 * @pdev: platform device we're unregistering
335 * Unregistration is done in 2 steps. First we release all resources
336 * and remove it from the subsystem, then we drop reference count by
337 * calling platform_device_put().
339 void platform_device_unregister(struct platform_device
*pdev
)
341 platform_device_del(pdev
);
342 platform_device_put(pdev
);
344 EXPORT_SYMBOL_GPL(platform_device_unregister
);
347 * platform_device_register_simple
348 * @name: base name of the device we're adding
350 * @res: set of resources that needs to be allocated for the device
351 * @num: number of resources
353 * This function creates a simple platform device that requires minimal
354 * resource and memory management. Canned release function freeing memory
355 * allocated for the device allows drivers using such devices to be
356 * unloaded without waiting for the last reference to the device to be
359 * This interface is primarily intended for use with legacy drivers which
360 * probe hardware directly. Because such drivers create sysfs device nodes
361 * themselves, rather than letting system infrastructure handle such device
362 * enumeration tasks, they don't fully conform to the Linux driver model.
363 * In particular, when such drivers are built as modules, they can't be
366 struct platform_device
*platform_device_register_simple(const char *name
,
368 struct resource
*res
,
371 struct platform_device
*pdev
;
374 pdev
= platform_device_alloc(name
, id
);
381 retval
= platform_device_add_resources(pdev
, res
, num
);
386 retval
= platform_device_add(pdev
);
393 platform_device_put(pdev
);
394 return ERR_PTR(retval
);
396 EXPORT_SYMBOL_GPL(platform_device_register_simple
);
399 * platform_device_register_data
400 * @parent: parent device for the device we're adding
401 * @name: base name of the device we're adding
403 * @data: platform specific data for this platform device
404 * @size: size of platform specific data
406 * This function creates a simple platform device that requires minimal
407 * resource and memory management. Canned release function freeing memory
408 * allocated for the device allows drivers using such devices to be
409 * unloaded without waiting for the last reference to the device to be
412 struct platform_device
*platform_device_register_data(
413 struct device
*parent
,
414 const char *name
, int id
,
415 const void *data
, size_t size
)
417 struct platform_device
*pdev
;
420 pdev
= platform_device_alloc(name
, id
);
426 pdev
->dev
.parent
= parent
;
429 retval
= platform_device_add_data(pdev
, data
, size
);
434 retval
= platform_device_add(pdev
);
441 platform_device_put(pdev
);
442 return ERR_PTR(retval
);
445 static int platform_drv_probe(struct device
*_dev
)
447 struct platform_driver
*drv
= to_platform_driver(_dev
->driver
);
448 struct platform_device
*dev
= to_platform_device(_dev
);
450 return drv
->probe(dev
);
453 static int platform_drv_probe_fail(struct device
*_dev
)
458 static int platform_drv_remove(struct device
*_dev
)
460 struct platform_driver
*drv
= to_platform_driver(_dev
->driver
);
461 struct platform_device
*dev
= to_platform_device(_dev
);
463 return drv
->remove(dev
);
466 static void platform_drv_shutdown(struct device
*_dev
)
468 struct platform_driver
*drv
= to_platform_driver(_dev
->driver
);
469 struct platform_device
*dev
= to_platform_device(_dev
);
475 * platform_driver_register
476 * @drv: platform driver structure
478 int platform_driver_register(struct platform_driver
*drv
)
480 drv
->driver
.bus
= &platform_bus_type
;
482 drv
->driver
.probe
= platform_drv_probe
;
484 drv
->driver
.remove
= platform_drv_remove
;
486 drv
->driver
.shutdown
= platform_drv_shutdown
;
488 return driver_register(&drv
->driver
);
490 EXPORT_SYMBOL_GPL(platform_driver_register
);
493 * platform_driver_unregister
494 * @drv: platform driver structure
496 void platform_driver_unregister(struct platform_driver
*drv
)
498 driver_unregister(&drv
->driver
);
500 EXPORT_SYMBOL_GPL(platform_driver_unregister
);
503 * platform_driver_probe - register driver for non-hotpluggable device
504 * @drv: platform driver structure
505 * @probe: the driver probe routine, probably from an __init section
507 * Use this instead of platform_driver_register() when you know the device
508 * is not hotpluggable and has already been registered, and you want to
509 * remove its run-once probe() infrastructure from memory after the driver
510 * has bound to the device.
512 * One typical use for this would be with drivers for controllers integrated
513 * into system-on-chip processors, where the controller devices have been
514 * configured as part of board setup.
516 * Returns zero if the driver registered and bound to a device, else returns
517 * a negative error code and with the driver not registered.
519 int __init_or_module
platform_driver_probe(struct platform_driver
*drv
,
520 int (*probe
)(struct platform_device
*))
524 /* temporary section violation during probe() */
526 retval
= code
= platform_driver_register(drv
);
528 /* Fixup that section violation, being paranoid about code scanning
529 * the list of drivers in order to probe new devices. Check to see
530 * if the probe was successful, and make sure any forced probes of
533 spin_lock(&platform_bus_type
.p
->klist_drivers
.k_lock
);
535 if (code
== 0 && list_empty(&drv
->driver
.p
->klist_devices
.k_list
))
537 drv
->driver
.probe
= platform_drv_probe_fail
;
538 spin_unlock(&platform_bus_type
.p
->klist_drivers
.k_lock
);
541 platform_driver_unregister(drv
);
544 EXPORT_SYMBOL_GPL(platform_driver_probe
);
546 /* modalias support enables more hands-off userspace setup:
547 * (a) environment variable lets new-style hotplug events work once system is
548 * fully running: "modprobe $MODALIAS"
549 * (b) sysfs attribute lets new-style coldplug recover from hotplug events
550 * mishandled before system is fully running: "modprobe $(cat modalias)"
552 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*a
,
555 struct platform_device
*pdev
= to_platform_device(dev
);
556 int len
= snprintf(buf
, PAGE_SIZE
, "platform:%s\n", pdev
->name
);
558 return (len
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : len
;
561 static struct device_attribute platform_dev_attrs
[] = {
566 static int platform_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
568 struct platform_device
*pdev
= to_platform_device(dev
);
570 add_uevent_var(env
, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX
,
571 (pdev
->id_entry
) ? pdev
->id_entry
->name
: pdev
->name
);
575 static const struct platform_device_id
*platform_match_id(
576 struct platform_device_id
*id
,
577 struct platform_device
*pdev
)
579 while (id
->name
[0]) {
580 if (strcmp(pdev
->name
, id
->name
) == 0) {
590 * platform_match - bind platform device to platform driver.
594 * Platform device IDs are assumed to be encoded like this:
595 * "<name><instance>", where <name> is a short description of the type of
596 * device, like "pci" or "floppy", and <instance> is the enumerated
597 * instance of the device, like '0' or '42'. Driver IDs are simply
598 * "<name>". So, extract the <name> from the platform_device structure,
599 * and compare it against the name of the driver. Return whether they match
602 static int platform_match(struct device
*dev
, struct device_driver
*drv
)
604 struct platform_device
*pdev
= to_platform_device(dev
);
605 struct platform_driver
*pdrv
= to_platform_driver(drv
);
607 /* match against the id table first */
609 return platform_match_id(pdrv
->id_table
, pdev
) != NULL
;
611 /* fall-back to driver name match */
612 return (strcmp(pdev
->name
, drv
->name
) == 0);
615 #ifdef CONFIG_PM_SLEEP
617 static int platform_legacy_suspend(struct device
*dev
, pm_message_t mesg
)
619 struct platform_driver
*pdrv
= to_platform_driver(dev
->driver
);
620 struct platform_device
*pdev
= to_platform_device(dev
);
623 if (dev
->driver
&& pdrv
->suspend
)
624 ret
= pdrv
->suspend(pdev
, mesg
);
629 static int platform_legacy_resume(struct device
*dev
)
631 struct platform_driver
*pdrv
= to_platform_driver(dev
->driver
);
632 struct platform_device
*pdev
= to_platform_device(dev
);
635 if (dev
->driver
&& pdrv
->resume
)
636 ret
= pdrv
->resume(pdev
);
641 static int platform_pm_prepare(struct device
*dev
)
643 struct device_driver
*drv
= dev
->driver
;
646 if (drv
&& drv
->pm
&& drv
->pm
->prepare
)
647 ret
= drv
->pm
->prepare(dev
);
652 static void platform_pm_complete(struct device
*dev
)
654 struct device_driver
*drv
= dev
->driver
;
656 if (drv
&& drv
->pm
&& drv
->pm
->complete
)
657 drv
->pm
->complete(dev
);
660 #else /* !CONFIG_PM_SLEEP */
662 #define platform_pm_prepare NULL
663 #define platform_pm_complete NULL
665 #endif /* !CONFIG_PM_SLEEP */
667 #ifdef CONFIG_SUSPEND
669 static int platform_pm_suspend(struct device
*dev
)
671 struct device_driver
*drv
= dev
->driver
;
678 if (drv
->pm
->suspend
)
679 ret
= drv
->pm
->suspend(dev
);
681 ret
= platform_legacy_suspend(dev
, PMSG_SUSPEND
);
687 static int platform_pm_suspend_noirq(struct device
*dev
)
689 struct device_driver
*drv
= dev
->driver
;
696 if (drv
->pm
->suspend_noirq
)
697 ret
= drv
->pm
->suspend_noirq(dev
);
703 static int platform_pm_resume(struct device
*dev
)
705 struct device_driver
*drv
= dev
->driver
;
713 ret
= drv
->pm
->resume(dev
);
715 ret
= platform_legacy_resume(dev
);
721 static int platform_pm_resume_noirq(struct device
*dev
)
723 struct device_driver
*drv
= dev
->driver
;
730 if (drv
->pm
->resume_noirq
)
731 ret
= drv
->pm
->resume_noirq(dev
);
737 #else /* !CONFIG_SUSPEND */
739 #define platform_pm_suspend NULL
740 #define platform_pm_resume NULL
741 #define platform_pm_suspend_noirq NULL
742 #define platform_pm_resume_noirq NULL
744 #endif /* !CONFIG_SUSPEND */
746 #ifdef CONFIG_HIBERNATION
748 static int platform_pm_freeze(struct device
*dev
)
750 struct device_driver
*drv
= dev
->driver
;
758 ret
= drv
->pm
->freeze(dev
);
760 ret
= platform_legacy_suspend(dev
, PMSG_FREEZE
);
766 static int platform_pm_freeze_noirq(struct device
*dev
)
768 struct device_driver
*drv
= dev
->driver
;
775 if (drv
->pm
->freeze_noirq
)
776 ret
= drv
->pm
->freeze_noirq(dev
);
782 static int platform_pm_thaw(struct device
*dev
)
784 struct device_driver
*drv
= dev
->driver
;
792 ret
= drv
->pm
->thaw(dev
);
794 ret
= platform_legacy_resume(dev
);
800 static int platform_pm_thaw_noirq(struct device
*dev
)
802 struct device_driver
*drv
= dev
->driver
;
809 if (drv
->pm
->thaw_noirq
)
810 ret
= drv
->pm
->thaw_noirq(dev
);
816 static int platform_pm_poweroff(struct device
*dev
)
818 struct device_driver
*drv
= dev
->driver
;
825 if (drv
->pm
->poweroff
)
826 ret
= drv
->pm
->poweroff(dev
);
828 ret
= platform_legacy_suspend(dev
, PMSG_HIBERNATE
);
834 static int platform_pm_poweroff_noirq(struct device
*dev
)
836 struct device_driver
*drv
= dev
->driver
;
843 if (drv
->pm
->poweroff_noirq
)
844 ret
= drv
->pm
->poweroff_noirq(dev
);
850 static int platform_pm_restore(struct device
*dev
)
852 struct device_driver
*drv
= dev
->driver
;
859 if (drv
->pm
->restore
)
860 ret
= drv
->pm
->restore(dev
);
862 ret
= platform_legacy_resume(dev
);
868 static int platform_pm_restore_noirq(struct device
*dev
)
870 struct device_driver
*drv
= dev
->driver
;
877 if (drv
->pm
->restore_noirq
)
878 ret
= drv
->pm
->restore_noirq(dev
);
884 #else /* !CONFIG_HIBERNATION */
886 #define platform_pm_freeze NULL
887 #define platform_pm_thaw NULL
888 #define platform_pm_poweroff NULL
889 #define platform_pm_restore NULL
890 #define platform_pm_freeze_noirq NULL
891 #define platform_pm_thaw_noirq NULL
892 #define platform_pm_poweroff_noirq NULL
893 #define platform_pm_restore_noirq NULL
895 #endif /* !CONFIG_HIBERNATION */
897 #ifdef CONFIG_PM_RUNTIME
899 int __weak
platform_pm_runtime_suspend(struct device
*dev
)
904 int __weak
platform_pm_runtime_resume(struct device
*dev
)
909 int __weak
platform_pm_runtime_idle(struct device
*dev
)
914 #else /* !CONFIG_PM_RUNTIME */
916 #define platform_pm_runtime_suspend NULL
917 #define platform_pm_runtime_resume NULL
918 #define platform_pm_runtime_idle NULL
920 #endif /* !CONFIG_PM_RUNTIME */
922 static const struct dev_pm_ops platform_dev_pm_ops
= {
923 .prepare
= platform_pm_prepare
,
924 .complete
= platform_pm_complete
,
925 .suspend
= platform_pm_suspend
,
926 .resume
= platform_pm_resume
,
927 .freeze
= platform_pm_freeze
,
928 .thaw
= platform_pm_thaw
,
929 .poweroff
= platform_pm_poweroff
,
930 .restore
= platform_pm_restore
,
931 .suspend_noirq
= platform_pm_suspend_noirq
,
932 .resume_noirq
= platform_pm_resume_noirq
,
933 .freeze_noirq
= platform_pm_freeze_noirq
,
934 .thaw_noirq
= platform_pm_thaw_noirq
,
935 .poweroff_noirq
= platform_pm_poweroff_noirq
,
936 .restore_noirq
= platform_pm_restore_noirq
,
937 .runtime_suspend
= platform_pm_runtime_suspend
,
938 .runtime_resume
= platform_pm_runtime_resume
,
939 .runtime_idle
= platform_pm_runtime_idle
,
942 struct bus_type platform_bus_type
= {
944 .dev_attrs
= platform_dev_attrs
,
945 .match
= platform_match
,
946 .uevent
= platform_uevent
,
947 .pm
= &platform_dev_pm_ops
,
949 EXPORT_SYMBOL_GPL(platform_bus_type
);
951 int __init
platform_bus_init(void)
955 early_platform_cleanup();
957 error
= device_register(&platform_bus
);
960 error
= bus_register(&platform_bus_type
);
962 device_unregister(&platform_bus
);
966 #ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
967 u64
dma_get_required_mask(struct device
*dev
)
969 u32 low_totalram
= ((max_pfn
- 1) << PAGE_SHIFT
);
970 u32 high_totalram
= ((max_pfn
- 1) >> (32 - PAGE_SHIFT
));
973 if (!high_totalram
) {
974 /* convert to mask just covering totalram */
975 low_totalram
= (1 << (fls(low_totalram
) - 1));
976 low_totalram
+= low_totalram
- 1;
979 high_totalram
= (1 << (fls(high_totalram
) - 1));
980 high_totalram
+= high_totalram
- 1;
981 mask
= (((u64
)high_totalram
) << 32) + 0xffffffff;
985 EXPORT_SYMBOL_GPL(dma_get_required_mask
);
988 static __initdata
LIST_HEAD(early_platform_driver_list
);
989 static __initdata
LIST_HEAD(early_platform_device_list
);
992 * early_platform_driver_register
993 * @epdrv: early_platform driver structure
994 * @buf: string passed from early_param()
996 int __init
early_platform_driver_register(struct early_platform_driver
*epdrv
,
1002 /* Simply add the driver to the end of the global list.
1003 * Drivers will by default be put on the list in compiled-in order.
1005 if (!epdrv
->list
.next
) {
1006 INIT_LIST_HEAD(&epdrv
->list
);
1007 list_add_tail(&epdrv
->list
, &early_platform_driver_list
);
1010 /* If the user has specified device then make sure the driver
1011 * gets prioritized. The driver of the last device specified on
1012 * command line will be put first on the list.
1014 n
= strlen(epdrv
->pdrv
->driver
.name
);
1015 if (buf
&& !strncmp(buf
, epdrv
->pdrv
->driver
.name
, n
)) {
1016 list_move(&epdrv
->list
, &early_platform_driver_list
);
1018 if (!strcmp(buf
, epdrv
->pdrv
->driver
.name
))
1019 epdrv
->requested_id
= -1;
1020 else if (buf
[n
] == '.' && strict_strtoul(&buf
[n
+ 1], 10,
1022 epdrv
->requested_id
= index
;
1024 epdrv
->requested_id
= EARLY_PLATFORM_ID_ERROR
;
1031 * early_platform_add_devices - add a numbers of early platform devices
1032 * @devs: array of early platform devices to add
1033 * @num: number of early platform devices in array
1035 void __init
early_platform_add_devices(struct platform_device
**devs
, int num
)
1040 /* simply add the devices to list */
1041 for (i
= 0; i
< num
; i
++) {
1042 dev
= &devs
[i
]->dev
;
1044 if (!dev
->devres_head
.next
) {
1045 INIT_LIST_HEAD(&dev
->devres_head
);
1046 list_add_tail(&dev
->devres_head
,
1047 &early_platform_device_list
);
1053 * early_platform_driver_register_all
1054 * @class_str: string to identify early platform driver class
1056 void __init
early_platform_driver_register_all(char *class_str
)
1058 /* The "class_str" parameter may or may not be present on the kernel
1059 * command line. If it is present then there may be more than one
1060 * matching parameter.
1062 * Since we register our early platform drivers using early_param()
1063 * we need to make sure that they also get registered in the case
1064 * when the parameter is missing from the kernel command line.
1066 * We use parse_early_options() to make sure the early_param() gets
1067 * called at least once. The early_param() may be called more than
1068 * once since the name of the preferred device may be specified on
1069 * the kernel command line. early_platform_driver_register() handles
1072 parse_early_options(class_str
);
1076 * early_platform_match
1077 * @epdrv: early platform driver structure
1078 * @id: id to match against
1080 static __init
struct platform_device
*
1081 early_platform_match(struct early_platform_driver
*epdrv
, int id
)
1083 struct platform_device
*pd
;
1085 list_for_each_entry(pd
, &early_platform_device_list
, dev
.devres_head
)
1086 if (platform_match(&pd
->dev
, &epdrv
->pdrv
->driver
))
1094 * early_platform_left
1095 * @epdrv: early platform driver structure
1096 * @id: return true if id or above exists
1098 static __init
int early_platform_left(struct early_platform_driver
*epdrv
,
1101 struct platform_device
*pd
;
1103 list_for_each_entry(pd
, &early_platform_device_list
, dev
.devres_head
)
1104 if (platform_match(&pd
->dev
, &epdrv
->pdrv
->driver
))
1112 * early_platform_driver_probe_id
1113 * @class_str: string to identify early platform driver class
1114 * @id: id to match against
1115 * @nr_probe: number of platform devices to successfully probe before exiting
1117 static int __init
early_platform_driver_probe_id(char *class_str
,
1121 struct early_platform_driver
*epdrv
;
1122 struct platform_device
*match
;
1127 list_for_each_entry(epdrv
, &early_platform_driver_list
, list
) {
1128 /* only use drivers matching our class_str */
1129 if (strcmp(class_str
, epdrv
->class_str
))
1133 match_id
= epdrv
->requested_id
;
1138 left
+= early_platform_left(epdrv
, id
);
1140 /* skip requested id */
1141 switch (epdrv
->requested_id
) {
1142 case EARLY_PLATFORM_ID_ERROR
:
1143 case EARLY_PLATFORM_ID_UNSET
:
1146 if (epdrv
->requested_id
== id
)
1147 match_id
= EARLY_PLATFORM_ID_UNSET
;
1152 case EARLY_PLATFORM_ID_ERROR
:
1153 pr_warning("%s: unable to parse %s parameter\n",
1154 class_str
, epdrv
->pdrv
->driver
.name
);
1156 case EARLY_PLATFORM_ID_UNSET
:
1160 match
= early_platform_match(epdrv
, match_id
);
1164 if (epdrv
->pdrv
->probe(match
))
1165 pr_warning("%s: unable to probe %s early.\n",
1166 class_str
, match
->name
);
1182 * early_platform_driver_probe
1183 * @class_str: string to identify early platform driver class
1184 * @nr_probe: number of platform devices to successfully probe before exiting
1185 * @user_only: only probe user specified early platform devices
1187 int __init
early_platform_driver_probe(char *class_str
,
1194 for (i
= -2; n
< nr_probe
; i
++) {
1195 k
= early_platform_driver_probe_id(class_str
, i
, nr_probe
- n
);
1210 * early_platform_cleanup - clean up early platform code
1212 void __init
early_platform_cleanup(void)
1214 struct platform_device
*pd
, *pd2
;
1216 /* clean up the devres list used to chain devices */
1217 list_for_each_entry_safe(pd
, pd2
, &early_platform_device_list
,
1219 list_del(&pd
->dev
.devres_head
);
1220 memset(&pd
->dev
.devres_head
, 0, sizeof(pd
->dev
.devres_head
));