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/platform_device.h>
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/bootmem.h>
18 #include <linux/err.h>
19 #include <linux/slab.h>
23 #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
26 struct device platform_bus
= {
27 .init_name
= "platform",
29 EXPORT_SYMBOL_GPL(platform_bus
);
32 * platform_get_resource - get a resource for a device
33 * @dev: platform device
34 * @type: resource type
35 * @num: resource index
37 struct resource
*platform_get_resource(struct platform_device
*dev
,
38 unsigned int type
, unsigned int num
)
42 for (i
= 0; i
< dev
->num_resources
; i
++) {
43 struct resource
*r
= &dev
->resource
[i
];
45 if (type
== resource_type(r
) && num
-- == 0)
50 EXPORT_SYMBOL_GPL(platform_get_resource
);
53 * platform_get_irq - get an IRQ for a device
54 * @dev: platform device
55 * @num: IRQ number index
57 int platform_get_irq(struct platform_device
*dev
, unsigned int num
)
59 struct resource
*r
= platform_get_resource(dev
, IORESOURCE_IRQ
, num
);
61 return r
? r
->start
: -ENXIO
;
63 EXPORT_SYMBOL_GPL(platform_get_irq
);
66 * platform_get_resource_byname - get a resource for a device by name
67 * @dev: platform device
68 * @type: resource type
69 * @name: resource name
71 struct resource
*platform_get_resource_byname(struct platform_device
*dev
,
77 for (i
= 0; i
< dev
->num_resources
; i
++) {
78 struct resource
*r
= &dev
->resource
[i
];
80 if (type
== resource_type(r
) && !strcmp(r
->name
, name
))
85 EXPORT_SYMBOL_GPL(platform_get_resource_byname
);
88 * platform_get_irq - get an IRQ for a device
89 * @dev: platform device
92 int platform_get_irq_byname(struct platform_device
*dev
, const char *name
)
94 struct resource
*r
= platform_get_resource_byname(dev
, IORESOURCE_IRQ
,
97 return r
? r
->start
: -ENXIO
;
99 EXPORT_SYMBOL_GPL(platform_get_irq_byname
);
102 * platform_add_devices - add a numbers of platform devices
103 * @devs: array of platform devices to add
104 * @num: number of platform devices in array
106 int platform_add_devices(struct platform_device
**devs
, int num
)
110 for (i
= 0; i
< num
; i
++) {
111 ret
= platform_device_register(devs
[i
]);
114 platform_device_unregister(devs
[i
]);
121 EXPORT_SYMBOL_GPL(platform_add_devices
);
123 struct platform_object
{
124 struct platform_device pdev
;
129 * platform_device_put
130 * @pdev: platform device to free
132 * Free all memory associated with a platform device. This function must
133 * _only_ be externally called in error cases. All other usage is a bug.
135 void platform_device_put(struct platform_device
*pdev
)
138 put_device(&pdev
->dev
);
140 EXPORT_SYMBOL_GPL(platform_device_put
);
142 static void platform_device_release(struct device
*dev
)
144 struct platform_object
*pa
= container_of(dev
, struct platform_object
,
147 kfree(pa
->pdev
.dev
.platform_data
);
148 kfree(pa
->pdev
.resource
);
153 * platform_device_alloc
154 * @name: base name of the device we're adding
157 * Create a platform device object which can have other objects attached
158 * to it, and which will have attached objects freed when it is released.
160 struct platform_device
*platform_device_alloc(const char *name
, int id
)
162 struct platform_object
*pa
;
164 pa
= kzalloc(sizeof(struct platform_object
) + strlen(name
), GFP_KERNEL
);
166 strcpy(pa
->name
, name
);
167 pa
->pdev
.name
= pa
->name
;
169 device_initialize(&pa
->pdev
.dev
);
170 pa
->pdev
.dev
.release
= platform_device_release
;
173 return pa
? &pa
->pdev
: NULL
;
175 EXPORT_SYMBOL_GPL(platform_device_alloc
);
178 * platform_device_add_resources
179 * @pdev: platform device allocated by platform_device_alloc to add resources to
180 * @res: set of resources that needs to be allocated for the device
181 * @num: number of resources
183 * Add a copy of the resources to the platform device. The memory
184 * associated with the resources will be freed when the platform device is
187 int platform_device_add_resources(struct platform_device
*pdev
,
188 struct resource
*res
, unsigned int num
)
192 r
= kmalloc(sizeof(struct resource
) * num
, GFP_KERNEL
);
194 memcpy(r
, res
, sizeof(struct resource
) * num
);
196 pdev
->num_resources
= num
;
198 return r
? 0 : -ENOMEM
;
200 EXPORT_SYMBOL_GPL(platform_device_add_resources
);
203 * platform_device_add_data
204 * @pdev: platform device allocated by platform_device_alloc to add resources to
205 * @data: platform specific data for this platform device
206 * @size: size of platform specific data
208 * Add a copy of platform specific data to the platform device's
209 * platform_data pointer. The memory associated with the platform data
210 * will be freed when the platform device is released.
212 int platform_device_add_data(struct platform_device
*pdev
, const void *data
,
217 d
= kmalloc(size
, GFP_KERNEL
);
219 memcpy(d
, data
, size
);
220 pdev
->dev
.platform_data
= d
;
222 return d
? 0 : -ENOMEM
;
224 EXPORT_SYMBOL_GPL(platform_device_add_data
);
227 * platform_device_add - add a platform device to device hierarchy
228 * @pdev: platform device we're adding
230 * This is part 2 of platform_device_register(), though may be called
231 * separately _iff_ pdev was allocated by platform_device_alloc().
233 int platform_device_add(struct platform_device
*pdev
)
240 if (!pdev
->dev
.parent
)
241 pdev
->dev
.parent
= &platform_bus
;
243 pdev
->dev
.bus
= &platform_bus_type
;
246 dev_set_name(&pdev
->dev
, "%s.%d", pdev
->name
, pdev
->id
);
248 dev_set_name(&pdev
->dev
, "%s", pdev
->name
);
250 for (i
= 0; i
< pdev
->num_resources
; i
++) {
251 struct resource
*p
, *r
= &pdev
->resource
[i
];
254 r
->name
= dev_name(&pdev
->dev
);
258 if (resource_type(r
) == IORESOURCE_MEM
)
260 else if (resource_type(r
) == IORESOURCE_IO
)
261 p
= &ioport_resource
;
264 if (p
&& insert_resource(p
, r
)) {
266 "%s: failed to claim resource %d\n",
267 dev_name(&pdev
->dev
), i
);
273 pr_debug("Registering platform device '%s'. Parent at %s\n",
274 dev_name(&pdev
->dev
), dev_name(pdev
->dev
.parent
));
276 ret
= device_add(&pdev
->dev
);
282 struct resource
*r
= &pdev
->resource
[i
];
283 unsigned long type
= resource_type(r
);
285 if (type
== IORESOURCE_MEM
|| type
== IORESOURCE_IO
)
291 EXPORT_SYMBOL_GPL(platform_device_add
);
294 * platform_device_del - remove a platform-level device
295 * @pdev: platform device we're removing
297 * Note that this function will also release all memory- and port-based
298 * resources owned by the device (@dev->resource). This function must
299 * _only_ be externally called in error cases. All other usage is a bug.
301 void platform_device_del(struct platform_device
*pdev
)
306 device_del(&pdev
->dev
);
308 for (i
= 0; i
< pdev
->num_resources
; i
++) {
309 struct resource
*r
= &pdev
->resource
[i
];
310 unsigned long type
= resource_type(r
);
312 if (type
== IORESOURCE_MEM
|| type
== IORESOURCE_IO
)
317 EXPORT_SYMBOL_GPL(platform_device_del
);
320 * platform_device_register - add a platform-level device
321 * @pdev: platform device we're adding
323 int platform_device_register(struct platform_device
*pdev
)
325 device_initialize(&pdev
->dev
);
326 return platform_device_add(pdev
);
328 EXPORT_SYMBOL_GPL(platform_device_register
);
331 * platform_device_unregister - unregister a platform-level device
332 * @pdev: platform device we're unregistering
334 * Unregistration is done in 2 steps. First we release all resources
335 * and remove it from the subsystem, then we drop reference count by
336 * calling platform_device_put().
338 void platform_device_unregister(struct platform_device
*pdev
)
340 platform_device_del(pdev
);
341 platform_device_put(pdev
);
343 EXPORT_SYMBOL_GPL(platform_device_unregister
);
346 * platform_device_register_simple
347 * @name: base name of the device we're adding
349 * @res: set of resources that needs to be allocated for the device
350 * @num: number of resources
352 * This function creates a simple platform device that requires minimal
353 * resource and memory management. Canned release function freeing memory
354 * allocated for the device allows drivers using such devices to be
355 * unloaded without waiting for the last reference to the device to be
358 * This interface is primarily intended for use with legacy drivers which
359 * probe hardware directly. Because such drivers create sysfs device nodes
360 * themselves, rather than letting system infrastructure handle such device
361 * enumeration tasks, they don't fully conform to the Linux driver model.
362 * In particular, when such drivers are built as modules, they can't be
365 struct platform_device
*platform_device_register_simple(const char *name
,
367 struct resource
*res
,
370 struct platform_device
*pdev
;
373 pdev
= platform_device_alloc(name
, id
);
380 retval
= platform_device_add_resources(pdev
, res
, num
);
385 retval
= platform_device_add(pdev
);
392 platform_device_put(pdev
);
393 return ERR_PTR(retval
);
395 EXPORT_SYMBOL_GPL(platform_device_register_simple
);
398 * platform_device_register_data
399 * @parent: parent device for the device we're adding
400 * @name: base name of the device we're adding
402 * @data: platform specific data for this platform device
403 * @size: size of platform specific data
405 * This function creates a simple platform device that requires minimal
406 * resource and memory management. Canned release function freeing memory
407 * allocated for the device allows drivers using such devices to be
408 * unloaded without waiting for the last reference to the device to be
411 struct platform_device
*platform_device_register_data(
412 struct device
*parent
,
413 const char *name
, int id
,
414 const void *data
, size_t size
)
416 struct platform_device
*pdev
;
419 pdev
= platform_device_alloc(name
, id
);
425 pdev
->dev
.parent
= parent
;
428 retval
= platform_device_add_data(pdev
, data
, size
);
433 retval
= platform_device_add(pdev
);
440 platform_device_put(pdev
);
441 return ERR_PTR(retval
);
444 static int platform_drv_probe(struct device
*_dev
)
446 struct platform_driver
*drv
= to_platform_driver(_dev
->driver
);
447 struct platform_device
*dev
= to_platform_device(_dev
);
449 return drv
->probe(dev
);
452 static int platform_drv_probe_fail(struct device
*_dev
)
457 static int platform_drv_remove(struct device
*_dev
)
459 struct platform_driver
*drv
= to_platform_driver(_dev
->driver
);
460 struct platform_device
*dev
= to_platform_device(_dev
);
462 return drv
->remove(dev
);
465 static void platform_drv_shutdown(struct device
*_dev
)
467 struct platform_driver
*drv
= to_platform_driver(_dev
->driver
);
468 struct platform_device
*dev
= to_platform_device(_dev
);
474 * platform_driver_register
475 * @drv: platform driver structure
477 int platform_driver_register(struct platform_driver
*drv
)
479 drv
->driver
.bus
= &platform_bus_type
;
481 drv
->driver
.probe
= platform_drv_probe
;
483 drv
->driver
.remove
= platform_drv_remove
;
485 drv
->driver
.shutdown
= platform_drv_shutdown
;
486 if (drv
->suspend
|| drv
->resume
)
487 pr_warning("Platform driver '%s' needs updating - please use "
488 "dev_pm_ops\n", drv
->driver
.name
);
490 return driver_register(&drv
->driver
);
492 EXPORT_SYMBOL_GPL(platform_driver_register
);
495 * platform_driver_unregister
496 * @drv: platform driver structure
498 void platform_driver_unregister(struct platform_driver
*drv
)
500 driver_unregister(&drv
->driver
);
502 EXPORT_SYMBOL_GPL(platform_driver_unregister
);
505 * platform_driver_probe - register driver for non-hotpluggable device
506 * @drv: platform driver structure
507 * @probe: the driver probe routine, probably from an __init section
509 * Use this instead of platform_driver_register() when you know the device
510 * is not hotpluggable and has already been registered, and you want to
511 * remove its run-once probe() infrastructure from memory after the driver
512 * has bound to the device.
514 * One typical use for this would be with drivers for controllers integrated
515 * into system-on-chip processors, where the controller devices have been
516 * configured as part of board setup.
518 * Returns zero if the driver registered and bound to a device, else returns
519 * a negative error code and with the driver not registered.
521 int __init_or_module
platform_driver_probe(struct platform_driver
*drv
,
522 int (*probe
)(struct platform_device
*))
526 /* temporary section violation during probe() */
528 retval
= code
= platform_driver_register(drv
);
530 /* Fixup that section violation, being paranoid about code scanning
531 * the list of drivers in order to probe new devices. Check to see
532 * if the probe was successful, and make sure any forced probes of
535 spin_lock(&platform_bus_type
.p
->klist_drivers
.k_lock
);
537 if (code
== 0 && list_empty(&drv
->driver
.p
->klist_devices
.k_list
))
539 drv
->driver
.probe
= platform_drv_probe_fail
;
540 spin_unlock(&platform_bus_type
.p
->klist_drivers
.k_lock
);
543 platform_driver_unregister(drv
);
546 EXPORT_SYMBOL_GPL(platform_driver_probe
);
548 /* modalias support enables more hands-off userspace setup:
549 * (a) environment variable lets new-style hotplug events work once system is
550 * fully running: "modprobe $MODALIAS"
551 * (b) sysfs attribute lets new-style coldplug recover from hotplug events
552 * mishandled before system is fully running: "modprobe $(cat modalias)"
554 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*a
,
557 struct platform_device
*pdev
= to_platform_device(dev
);
558 int len
= snprintf(buf
, PAGE_SIZE
, "platform:%s\n", pdev
->name
);
560 return (len
>= PAGE_SIZE
) ? (PAGE_SIZE
- 1) : len
;
563 static struct device_attribute platform_dev_attrs
[] = {
568 static int platform_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
570 struct platform_device
*pdev
= to_platform_device(dev
);
572 add_uevent_var(env
, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX
,
573 (pdev
->id_entry
) ? pdev
->id_entry
->name
: pdev
->name
);
577 static const struct platform_device_id
*platform_match_id(
578 struct platform_device_id
*id
,
579 struct platform_device
*pdev
)
581 while (id
->name
[0]) {
582 if (strcmp(pdev
->name
, id
->name
) == 0) {
592 * platform_match - bind platform device to platform driver.
596 * Platform device IDs are assumed to be encoded like this:
597 * "<name><instance>", where <name> is a short description of the type of
598 * device, like "pci" or "floppy", and <instance> is the enumerated
599 * instance of the device, like '0' or '42'. Driver IDs are simply
600 * "<name>". So, extract the <name> from the platform_device structure,
601 * and compare it against the name of the driver. Return whether they match
604 static int platform_match(struct device
*dev
, struct device_driver
*drv
)
606 struct platform_device
*pdev
= to_platform_device(dev
);
607 struct platform_driver
*pdrv
= to_platform_driver(drv
);
609 /* match against the id table first */
611 return platform_match_id(pdrv
->id_table
, pdev
) != NULL
;
613 /* fall-back to driver name match */
614 return (strcmp(pdev
->name
, drv
->name
) == 0);
617 #ifdef CONFIG_PM_SLEEP
619 static int platform_legacy_suspend(struct device
*dev
, pm_message_t mesg
)
621 struct platform_driver
*pdrv
= to_platform_driver(dev
->driver
);
622 struct platform_device
*pdev
= to_platform_device(dev
);
625 if (dev
->driver
&& pdrv
->suspend
)
626 ret
= pdrv
->suspend(pdev
, mesg
);
631 static int platform_legacy_resume(struct device
*dev
)
633 struct platform_driver
*pdrv
= to_platform_driver(dev
->driver
);
634 struct platform_device
*pdev
= to_platform_device(dev
);
637 if (dev
->driver
&& pdrv
->resume
)
638 ret
= pdrv
->resume(pdev
);
643 static int platform_pm_prepare(struct device
*dev
)
645 struct device_driver
*drv
= dev
->driver
;
648 if (drv
&& drv
->pm
&& drv
->pm
->prepare
)
649 ret
= drv
->pm
->prepare(dev
);
654 static void platform_pm_complete(struct device
*dev
)
656 struct device_driver
*drv
= dev
->driver
;
658 if (drv
&& drv
->pm
&& drv
->pm
->complete
)
659 drv
->pm
->complete(dev
);
662 #ifdef CONFIG_SUSPEND
664 static int platform_pm_suspend(struct device
*dev
)
666 struct device_driver
*drv
= dev
->driver
;
673 if (drv
->pm
->suspend
)
674 ret
= drv
->pm
->suspend(dev
);
676 ret
= platform_legacy_suspend(dev
, PMSG_SUSPEND
);
682 static int platform_pm_suspend_noirq(struct device
*dev
)
684 struct device_driver
*drv
= dev
->driver
;
691 if (drv
->pm
->suspend_noirq
)
692 ret
= drv
->pm
->suspend_noirq(dev
);
698 static int platform_pm_resume(struct device
*dev
)
700 struct device_driver
*drv
= dev
->driver
;
708 ret
= drv
->pm
->resume(dev
);
710 ret
= platform_legacy_resume(dev
);
716 static int platform_pm_resume_noirq(struct device
*dev
)
718 struct device_driver
*drv
= dev
->driver
;
725 if (drv
->pm
->resume_noirq
)
726 ret
= drv
->pm
->resume_noirq(dev
);
732 #else /* !CONFIG_SUSPEND */
734 #define platform_pm_suspend NULL
735 #define platform_pm_resume NULL
736 #define platform_pm_suspend_noirq NULL
737 #define platform_pm_resume_noirq NULL
739 #endif /* !CONFIG_SUSPEND */
741 #ifdef CONFIG_HIBERNATION
743 static int platform_pm_freeze(struct device
*dev
)
745 struct device_driver
*drv
= dev
->driver
;
753 ret
= drv
->pm
->freeze(dev
);
755 ret
= platform_legacy_suspend(dev
, PMSG_FREEZE
);
761 static int platform_pm_freeze_noirq(struct device
*dev
)
763 struct device_driver
*drv
= dev
->driver
;
770 if (drv
->pm
->freeze_noirq
)
771 ret
= drv
->pm
->freeze_noirq(dev
);
777 static int platform_pm_thaw(struct device
*dev
)
779 struct device_driver
*drv
= dev
->driver
;
787 ret
= drv
->pm
->thaw(dev
);
789 ret
= platform_legacy_resume(dev
);
795 static int platform_pm_thaw_noirq(struct device
*dev
)
797 struct device_driver
*drv
= dev
->driver
;
804 if (drv
->pm
->thaw_noirq
)
805 ret
= drv
->pm
->thaw_noirq(dev
);
811 static int platform_pm_poweroff(struct device
*dev
)
813 struct device_driver
*drv
= dev
->driver
;
820 if (drv
->pm
->poweroff
)
821 ret
= drv
->pm
->poweroff(dev
);
823 ret
= platform_legacy_suspend(dev
, PMSG_HIBERNATE
);
829 static int platform_pm_poweroff_noirq(struct device
*dev
)
831 struct device_driver
*drv
= dev
->driver
;
838 if (drv
->pm
->poweroff_noirq
)
839 ret
= drv
->pm
->poweroff_noirq(dev
);
845 static int platform_pm_restore(struct device
*dev
)
847 struct device_driver
*drv
= dev
->driver
;
854 if (drv
->pm
->restore
)
855 ret
= drv
->pm
->restore(dev
);
857 ret
= platform_legacy_resume(dev
);
863 static int platform_pm_restore_noirq(struct device
*dev
)
865 struct device_driver
*drv
= dev
->driver
;
872 if (drv
->pm
->restore_noirq
)
873 ret
= drv
->pm
->restore_noirq(dev
);
879 #else /* !CONFIG_HIBERNATION */
881 #define platform_pm_freeze NULL
882 #define platform_pm_thaw NULL
883 #define platform_pm_poweroff NULL
884 #define platform_pm_restore NULL
885 #define platform_pm_freeze_noirq NULL
886 #define platform_pm_thaw_noirq NULL
887 #define platform_pm_poweroff_noirq NULL
888 #define platform_pm_restore_noirq NULL
890 #endif /* !CONFIG_HIBERNATION */
892 static struct dev_pm_ops platform_dev_pm_ops
= {
893 .prepare
= platform_pm_prepare
,
894 .complete
= platform_pm_complete
,
895 .suspend
= platform_pm_suspend
,
896 .resume
= platform_pm_resume
,
897 .freeze
= platform_pm_freeze
,
898 .thaw
= platform_pm_thaw
,
899 .poweroff
= platform_pm_poweroff
,
900 .restore
= platform_pm_restore
,
901 .suspend_noirq
= platform_pm_suspend_noirq
,
902 .resume_noirq
= platform_pm_resume_noirq
,
903 .freeze_noirq
= platform_pm_freeze_noirq
,
904 .thaw_noirq
= platform_pm_thaw_noirq
,
905 .poweroff_noirq
= platform_pm_poweroff_noirq
,
906 .restore_noirq
= platform_pm_restore_noirq
,
909 #define PLATFORM_PM_OPS_PTR (&platform_dev_pm_ops)
911 #else /* !CONFIG_PM_SLEEP */
913 #define PLATFORM_PM_OPS_PTR NULL
915 #endif /* !CONFIG_PM_SLEEP */
917 struct bus_type platform_bus_type
= {
919 .dev_attrs
= platform_dev_attrs
,
920 .match
= platform_match
,
921 .uevent
= platform_uevent
,
922 .pm
= PLATFORM_PM_OPS_PTR
,
924 EXPORT_SYMBOL_GPL(platform_bus_type
);
926 int __init
platform_bus_init(void)
930 early_platform_cleanup();
932 error
= device_register(&platform_bus
);
935 error
= bus_register(&platform_bus_type
);
937 device_unregister(&platform_bus
);
941 #ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
942 u64
dma_get_required_mask(struct device
*dev
)
944 u32 low_totalram
= ((max_pfn
- 1) << PAGE_SHIFT
);
945 u32 high_totalram
= ((max_pfn
- 1) >> (32 - PAGE_SHIFT
));
948 if (!high_totalram
) {
949 /* convert to mask just covering totalram */
950 low_totalram
= (1 << (fls(low_totalram
) - 1));
951 low_totalram
+= low_totalram
- 1;
954 high_totalram
= (1 << (fls(high_totalram
) - 1));
955 high_totalram
+= high_totalram
- 1;
956 mask
= (((u64
)high_totalram
) << 32) + 0xffffffff;
960 EXPORT_SYMBOL_GPL(dma_get_required_mask
);
963 static __initdata
LIST_HEAD(early_platform_driver_list
);
964 static __initdata
LIST_HEAD(early_platform_device_list
);
967 * early_platform_driver_register
968 * @epdrv: early_platform driver structure
969 * @buf: string passed from early_param()
971 int __init
early_platform_driver_register(struct early_platform_driver
*epdrv
,
977 /* Simply add the driver to the end of the global list.
978 * Drivers will by default be put on the list in compiled-in order.
980 if (!epdrv
->list
.next
) {
981 INIT_LIST_HEAD(&epdrv
->list
);
982 list_add_tail(&epdrv
->list
, &early_platform_driver_list
);
985 /* If the user has specified device then make sure the driver
986 * gets prioritized. The driver of the last device specified on
987 * command line will be put first on the list.
989 n
= strlen(epdrv
->pdrv
->driver
.name
);
990 if (buf
&& !strncmp(buf
, epdrv
->pdrv
->driver
.name
, n
)) {
991 list_move(&epdrv
->list
, &early_platform_driver_list
);
993 if (!strcmp(buf
, epdrv
->pdrv
->driver
.name
))
994 epdrv
->requested_id
= -1;
995 else if (buf
[n
] == '.' && strict_strtoul(&buf
[n
+ 1], 10,
997 epdrv
->requested_id
= index
;
999 epdrv
->requested_id
= EARLY_PLATFORM_ID_ERROR
;
1006 * early_platform_add_devices - add a numbers of early platform devices
1007 * @devs: array of early platform devices to add
1008 * @num: number of early platform devices in array
1010 void __init
early_platform_add_devices(struct platform_device
**devs
, int num
)
1015 /* simply add the devices to list */
1016 for (i
= 0; i
< num
; i
++) {
1017 dev
= &devs
[i
]->dev
;
1019 if (!dev
->devres_head
.next
) {
1020 INIT_LIST_HEAD(&dev
->devres_head
);
1021 list_add_tail(&dev
->devres_head
,
1022 &early_platform_device_list
);
1028 * early_platform_driver_register_all
1029 * @class_str: string to identify early platform driver class
1031 void __init
early_platform_driver_register_all(char *class_str
)
1033 /* The "class_str" parameter may or may not be present on the kernel
1034 * command line. If it is present then there may be more than one
1035 * matching parameter.
1037 * Since we register our early platform drivers using early_param()
1038 * we need to make sure that they also get registered in the case
1039 * when the parameter is missing from the kernel command line.
1041 * We use parse_early_options() to make sure the early_param() gets
1042 * called at least once. The early_param() may be called more than
1043 * once since the name of the preferred device may be specified on
1044 * the kernel command line. early_platform_driver_register() handles
1047 parse_early_options(class_str
);
1051 * early_platform_match
1052 * @epdrv: early platform driver structure
1053 * @id: id to match against
1055 static __init
struct platform_device
*
1056 early_platform_match(struct early_platform_driver
*epdrv
, int id
)
1058 struct platform_device
*pd
;
1060 list_for_each_entry(pd
, &early_platform_device_list
, dev
.devres_head
)
1061 if (platform_match(&pd
->dev
, &epdrv
->pdrv
->driver
))
1069 * early_platform_left
1070 * @epdrv: early platform driver structure
1071 * @id: return true if id or above exists
1073 static __init
int early_platform_left(struct early_platform_driver
*epdrv
,
1076 struct platform_device
*pd
;
1078 list_for_each_entry(pd
, &early_platform_device_list
, dev
.devres_head
)
1079 if (platform_match(&pd
->dev
, &epdrv
->pdrv
->driver
))
1087 * early_platform_driver_probe_id
1088 * @class_str: string to identify early platform driver class
1089 * @id: id to match against
1090 * @nr_probe: number of platform devices to successfully probe before exiting
1092 static int __init
early_platform_driver_probe_id(char *class_str
,
1096 struct early_platform_driver
*epdrv
;
1097 struct platform_device
*match
;
1102 list_for_each_entry(epdrv
, &early_platform_driver_list
, list
) {
1103 /* only use drivers matching our class_str */
1104 if (strcmp(class_str
, epdrv
->class_str
))
1108 match_id
= epdrv
->requested_id
;
1113 left
+= early_platform_left(epdrv
, id
);
1115 /* skip requested id */
1116 switch (epdrv
->requested_id
) {
1117 case EARLY_PLATFORM_ID_ERROR
:
1118 case EARLY_PLATFORM_ID_UNSET
:
1121 if (epdrv
->requested_id
== id
)
1122 match_id
= EARLY_PLATFORM_ID_UNSET
;
1127 case EARLY_PLATFORM_ID_ERROR
:
1128 pr_warning("%s: unable to parse %s parameter\n",
1129 class_str
, epdrv
->pdrv
->driver
.name
);
1131 case EARLY_PLATFORM_ID_UNSET
:
1135 match
= early_platform_match(epdrv
, match_id
);
1139 if (epdrv
->pdrv
->probe(match
))
1140 pr_warning("%s: unable to probe %s early.\n",
1141 class_str
, match
->name
);
1157 * early_platform_driver_probe
1158 * @class_str: string to identify early platform driver class
1159 * @nr_probe: number of platform devices to successfully probe before exiting
1160 * @user_only: only probe user specified early platform devices
1162 int __init
early_platform_driver_probe(char *class_str
,
1169 for (i
= -2; n
< nr_probe
; i
++) {
1170 k
= early_platform_driver_probe_id(class_str
, i
, nr_probe
- n
);
1185 * early_platform_cleanup - clean up early platform code
1187 void __init
early_platform_cleanup(void)
1189 struct platform_device
*pd
, *pd2
;
1191 /* clean up the devres list used to chain devices */
1192 list_for_each_entry_safe(pd
, pd2
, &early_platform_device_list
,
1194 list_del(&pd
->dev
.devres_head
);
1195 memset(&pd
->dev
.devres_head
, 0, sizeof(pd
->dev
.devres_head
));