aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/platform.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-03-26 14:17:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-03-26 14:17:04 -0400
commit0c93ea4064a209cdc36de8a9a3003d43d08f46f7 (patch)
treeff19952407c523a1349ef56c05993416dd28437e /drivers/base/platform.c
parentbc2fd381d8f9dbeb181f82286cdca1567e3d0def (diff)
parente6e66b02e11563abdb7f69dcb7a2efbd8d577e77 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core-2.6: (61 commits) Dynamic debug: fix pr_fmt() build error Dynamic debug: allow simple quoting of words dynamic debug: update docs dynamic debug: combine dprintk and dynamic printk sysfs: fix some bin_vm_ops errors kobject: don't block for each kobject_uevent sysfs: only allow one scheduled removal callback per kobj Driver core: Fix device_move() vs. dpm list ordering, v2 Driver core: some cleanup on drivers/base/sys.c Driver core: implement uevent suppress in kobject vcs: hook sysfs devices into object lifetime instead of "binding" driver core: fix passing platform_data driver core: move platform_data into platform_device sysfs: don't block indefinitely for unmapped files. driver core: move knode_bus into private structure driver core: move knode_driver into private structure driver core: move klist_children into private structure driver core: create a private portion of struct device driver core: remove polling for driver_probe_done(v5) sysfs: reference sysfs_dirent from sysfs inodes ... Fixed conflicts in drivers/sh/maple/maple.c manually
Diffstat (limited to 'drivers/base/platform.c')
-rw-r--r--drivers/base/platform.c60
1 files changed, 47 insertions, 13 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 349a1013603f..d2198f64ad4e 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -217,6 +217,7 @@ int platform_device_add_data(struct platform_device *pdev, const void *data,
217 if (d) { 217 if (d) {
218 memcpy(d, data, size); 218 memcpy(d, data, size);
219 pdev->dev.platform_data = d; 219 pdev->dev.platform_data = d;
220 pdev->platform_data = d;
220 } 221 }
221 return d ? 0 : -ENOMEM; 222 return d ? 0 : -ENOMEM;
222} 223}
@@ -246,6 +247,21 @@ int platform_device_add(struct platform_device *pdev)
246 else 247 else
247 dev_set_name(&pdev->dev, pdev->name); 248 dev_set_name(&pdev->dev, pdev->name);
248 249
250 /* We will remove platform_data field from struct device
251 * if all platform devices pass its platform specific data
252 * from platform_device. The conversion is going to be a
253 * long time, so we allow the two cases coexist to make
254 * this kind of fix more easily*/
255 if (pdev->platform_data && pdev->dev.platform_data) {
256 printk(KERN_ERR
257 "%s: use which platform_data?\n",
258 dev_name(&pdev->dev));
259 } else if (pdev->platform_data) {
260 pdev->dev.platform_data = pdev->platform_data;
261 } else if (pdev->dev.platform_data) {
262 pdev->platform_data = pdev->dev.platform_data;
263 }
264
249 for (i = 0; i < pdev->num_resources; i++) { 265 for (i = 0; i < pdev->num_resources; i++) {
250 struct resource *p, *r = &pdev->resource[i]; 266 struct resource *p, *r = &pdev->resource[i];
251 267
@@ -584,10 +600,25 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
584{ 600{
585 struct platform_device *pdev = to_platform_device(dev); 601 struct platform_device *pdev = to_platform_device(dev);
586 602
587 add_uevent_var(env, "MODALIAS=platform:%s", pdev->name); 603 add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
604 (pdev->id_entry) ? pdev->id_entry->name : pdev->name);
588 return 0; 605 return 0;
589} 606}
590 607
608static const struct platform_device_id *platform_match_id(
609 struct platform_device_id *id,
610 struct platform_device *pdev)
611{
612 while (id->name[0]) {
613 if (strcmp(pdev->name, id->name) == 0) {
614 pdev->id_entry = id;
615 return id;
616 }
617 id++;
618 }
619 return NULL;
620}
621
591/** 622/**
592 * platform_match - bind platform device to platform driver. 623 * platform_match - bind platform device to platform driver.
593 * @dev: device. 624 * @dev: device.
@@ -603,9 +634,14 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
603 */ 634 */
604static int platform_match(struct device *dev, struct device_driver *drv) 635static int platform_match(struct device *dev, struct device_driver *drv)
605{ 636{
606 struct platform_device *pdev; 637 struct platform_device *pdev = to_platform_device(dev);
638 struct platform_driver *pdrv = to_platform_driver(drv);
607 639
608 pdev = container_of(dev, struct platform_device, dev); 640 /* match against the id table first */
641 if (pdrv->id_table)
642 return platform_match_id(pdrv->id_table, pdev) != NULL;
643
644 /* fall-back to driver name match */
609 return (strcmp(pdev->name, drv->name) == 0); 645 return (strcmp(pdev->name, drv->name) == 0);
610} 646}
611 647
@@ -623,26 +659,24 @@ static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
623 659
624static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg) 660static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg)
625{ 661{
626 struct platform_driver *drv = to_platform_driver(dev->driver); 662 struct platform_driver *pdrv = to_platform_driver(dev->driver);
627 struct platform_device *pdev; 663 struct platform_device *pdev = to_platform_device(dev);
628 int ret = 0; 664 int ret = 0;
629 665
630 pdev = container_of(dev, struct platform_device, dev); 666 if (dev->driver && pdrv->suspend_late)
631 if (dev->driver && drv->suspend_late) 667 ret = pdrv->suspend_late(pdev, mesg);
632 ret = drv->suspend_late(pdev, mesg);
633 668
634 return ret; 669 return ret;
635} 670}
636 671
637static int platform_legacy_resume_early(struct device *dev) 672static int platform_legacy_resume_early(struct device *dev)
638{ 673{
639 struct platform_driver *drv = to_platform_driver(dev->driver); 674 struct platform_driver *pdrv = to_platform_driver(dev->driver);
640 struct platform_device *pdev; 675 struct platform_device *pdev = to_platform_device(dev);
641 int ret = 0; 676 int ret = 0;
642 677
643 pdev = container_of(dev, struct platform_device, dev); 678 if (dev->driver && pdrv->resume_early)
644 if (dev->driver && drv->resume_early) 679 ret = pdrv->resume_early(pdev);
645 ret = drv->resume_early(pdev);
646 680
647 return ret; 681 return ret;
648} 682}