Lines Matching +full:platform +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
3 * platform.c - platform 'pseudo' bus for legacy devices
5 * Copyright (c) 2002-3 Patrick Mochel
6 * Copyright (c) 2002-3 Open Source Development Labs
8 * Please see Documentation/driver-api/driver-model/platform.rst for more
20 #include <linux/dma-mapping.h>
28 #include <linux/clk/clk-conf.h>
34 #include <linux/dma-map-ops.h>
43 .init_name = "platform",
48 * platform_get_resource - get a resource for a device
49 * @dev: platform device
60 for (i = 0; i < dev->num_resources; i++) { in platform_get_resource()
61 struct resource *r = &dev->resource[i]; in platform_get_resource()
63 if (type == resource_type(r) && num-- == 0) in platform_get_resource()
75 for (i = 0; i < dev->num_resources; i++) { in platform_get_mem_or_io()
76 struct resource *r = &dev->resource[i]; in platform_get_mem_or_io()
78 if ((resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) && num-- == 0) in platform_get_mem_or_io()
87 * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
88 * platform device and get resource
90 * @pdev: platform device to use both for memory resource lookup as well as
107 return devm_ioremap_resource(&pdev->dev, r); in devm_platform_get_and_ioremap_resource()
112 * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
115 * @pdev: platform device to use both for memory resource lookup as well as
130 * devm_platform_ioremap_resource_byname - call devm_ioremap_resource for
131 * a platform device, retrieve the
132 * resource by name
134 * @pdev: platform device to use both for memory resource lookup as well as
136 * @name: name of the resource
143 const char *name) in devm_platform_ioremap_resource_byname() argument
147 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); in devm_platform_ioremap_resource_byname()
148 return devm_ioremap_resource(&pdev->dev, res); in devm_platform_ioremap_resource_byname()
154 * platform_get_irq_optional - get an optional IRQ for a device
155 * @dev: platform device
158 * Gets an IRQ for a platform device. Device drivers should check the return
169 * Return: non-zero IRQ number on success, negative error number on failure.
176 if (!dev || num >= dev->archdata.num_irqs) in platform_get_irq_optional()
178 ret = dev->archdata.irqs[num]; in platform_get_irq_optional()
181 struct fwnode_handle *fwnode = dev_fwnode(&dev->dev); in platform_get_irq_optional()
186 if (ret > 0 || ret == -EPROBE_DEFER) in platform_get_irq_optional()
192 if (r && r->flags & IORESOURCE_DISABLED) { in platform_get_irq_optional()
202 * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER* in platform_get_irq_optional()
205 if (r && r->flags & IORESOURCE_BITS) { in platform_get_irq_optional()
208 irqd = irq_get_irq_data(r->start); in platform_get_irq_optional()
211 irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS); in platform_get_irq_optional()
215 ret = r->start; in platform_get_irq_optional()
228 /* Our callers expect -ENXIO for missing IRQs. */ in platform_get_irq_optional()
229 if (ret >= 0 || ret == -EPROBE_DEFER) in platform_get_irq_optional()
235 ret = -ENXIO; in platform_get_irq_optional()
238 return -EINVAL; in platform_get_irq_optional()
244 * platform_get_irq - get an IRQ for a device
245 * @dev: platform device
248 * Gets an IRQ for a platform device and prints an error message if finding the
258 * Return: non-zero IRQ number on success, negative error number on failure.
266 return dev_err_probe(&dev->dev, ret, in platform_get_irq()
274 * platform_irq_count - Count the number of IRQs a platform device uses
275 * @dev: platform device
277 * Return: Number of IRQs a platform device uses or EPROBE_DEFER
286 if (ret == -EPROBE_DEFER) in platform_irq_count()
313 for (i = 0; i < ptr->count; i++) { in devm_platform_get_irqs_affinity_release()
314 irq_dispose_mapping(ptr->irq[i]); in devm_platform_get_irqs_affinity_release()
322 * devm_platform_get_irqs_affinity - devm method to get a set of IRQs for a
324 * @dev: platform device pointer
330 * Gets a set of IRQs for a platform device, and updates IRQ afffinty according
347 return -EPERM; in devm_platform_get_irqs_affinity()
350 return -ERANGE; in devm_platform_get_irqs_affinity()
357 return -ENOSPC; in devm_platform_get_irqs_affinity()
361 return -ENOSPC; in devm_platform_get_irqs_affinity()
370 return -ENOMEM; in devm_platform_get_irqs_affinity()
372 ptr->count = nvec; in devm_platform_get_irqs_affinity()
380 ptr->irq[i] = irq; in devm_platform_get_irqs_affinity()
385 ret = -ENOMEM; in devm_platform_get_irqs_affinity()
390 ret = irq_update_affinity_desc(ptr->irq[i], &desc[i]); in devm_platform_get_irqs_affinity()
392 dev_err(&dev->dev, "failed to update irq%d affinity descriptor (%d)\n", in devm_platform_get_irqs_affinity()
393 ptr->irq[i], ret); in devm_platform_get_irqs_affinity()
398 devres_add(&dev->dev, ptr); in devm_platform_get_irqs_affinity()
402 *irqs = ptr->irq; in devm_platform_get_irqs_affinity()
415 * platform_get_resource_byname - get a resource for a device by name
416 * @dev: platform device
418 * @name: resource name
422 const char *name) in platform_get_resource_byname() argument
426 for (i = 0; i < dev->num_resources; i++) { in platform_get_resource_byname()
427 struct resource *r = &dev->resource[i]; in platform_get_resource_byname()
429 if (unlikely(!r->name)) in platform_get_resource_byname()
432 if (type == resource_type(r) && !strcmp(r->name, name)) in platform_get_resource_byname()
440 const char *name) in __platform_get_irq_byname() argument
445 ret = fwnode_irq_get_byname(dev_fwnode(&dev->dev), name); in __platform_get_irq_byname()
446 if (ret > 0 || ret == -EPROBE_DEFER) in __platform_get_irq_byname()
449 r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); in __platform_get_irq_byname()
451 if (WARN(!r->start, "0 is an invalid IRQ number\n")) in __platform_get_irq_byname()
452 return -EINVAL; in __platform_get_irq_byname()
453 return r->start; in __platform_get_irq_byname()
456 return -ENXIO; in __platform_get_irq_byname()
460 * platform_get_irq_byname - get an IRQ for a device by name
461 * @dev: platform device
462 * @name: IRQ name
464 * Get an IRQ like platform_get_irq(), but then by name rather then by index.
466 * Return: non-zero IRQ number on success, negative error number on failure.
468 int platform_get_irq_byname(struct platform_device *dev, const char *name) in platform_get_irq_byname() argument
472 ret = __platform_get_irq_byname(dev, name); in platform_get_irq_byname()
474 return dev_err_probe(&dev->dev, ret, "IRQ %s not found\n", in platform_get_irq_byname()
475 name); in platform_get_irq_byname()
481 * platform_get_irq_byname_optional - get an optional IRQ for a device by name
482 * @dev: platform device
483 * @name: IRQ name
485 * Get an optional IRQ by name like platform_get_irq_byname(). Except that it
488 * Return: non-zero IRQ number on success, negative error number on failure.
491 const char *name) in platform_get_irq_byname_optional() argument
493 return __platform_get_irq_byname(dev, name); in platform_get_irq_byname_optional()
498 * platform_add_devices - add a numbers of platform devices
499 * @devs: array of platform devices to add
500 * @num: number of platform devices in array
511 while (--i >= 0) in platform_add_devices()
523 char name[]; member
527 * Set up default DMA mask for platform devices if the they weren't
532 pdev->dev.dma_parms = &pdev->dma_parms; in setup_pdev_dma_masks()
534 if (!pdev->dev.coherent_dma_mask) in setup_pdev_dma_masks()
535 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); in setup_pdev_dma_masks()
536 if (!pdev->dev.dma_mask) { in setup_pdev_dma_masks()
537 pdev->platform_dma_mask = DMA_BIT_MASK(32); in setup_pdev_dma_masks()
538 pdev->dev.dma_mask = &pdev->platform_dma_mask; in setup_pdev_dma_masks()
543 * platform_device_put - destroy a platform device
544 * @pdev: platform device to free
546 * Free all memory associated with a platform device. This function must
552 put_device(&pdev->dev); in platform_device_put()
561 of_node_put(pa->pdev.dev.of_node); in platform_device_release()
562 kfree(pa->pdev.dev.platform_data); in platform_device_release()
563 kfree(pa->pdev.mfd_cell); in platform_device_release()
564 kfree(pa->pdev.resource); in platform_device_release()
565 kfree(pa->pdev.driver_override); in platform_device_release()
570 * platform_device_alloc - create a platform device
571 * @name: base name of the device we're adding
574 * Create a platform device object which can have other objects attached
577 struct platform_device *platform_device_alloc(const char *name, int id) in platform_device_alloc() argument
581 pa = kzalloc(sizeof(*pa) + strlen(name) + 1, GFP_KERNEL); in platform_device_alloc()
583 strcpy(pa->name, name); in platform_device_alloc()
584 pa->pdev.name = pa->name; in platform_device_alloc()
585 pa->pdev.id = id; in platform_device_alloc()
586 device_initialize(&pa->pdev.dev); in platform_device_alloc()
587 pa->pdev.dev.release = platform_device_release; in platform_device_alloc()
588 setup_pdev_dma_masks(&pa->pdev); in platform_device_alloc()
591 return pa ? &pa->pdev : NULL; in platform_device_alloc()
596 * platform_device_add_resources - add resources to a platform device
597 * @pdev: platform device allocated by platform_device_alloc to add resources to
601 * Add a copy of the resources to the platform device. The memory
602 * associated with the resources will be freed when the platform device is
613 return -ENOMEM; in platform_device_add_resources()
616 kfree(pdev->resource); in platform_device_add_resources()
617 pdev->resource = r; in platform_device_add_resources()
618 pdev->num_resources = num; in platform_device_add_resources()
624 * platform_device_add_data - add platform-specific data to a platform device
625 * @pdev: platform device allocated by platform_device_alloc to add resources to
626 * @data: platform specific data for this platform device
627 * @size: size of platform specific data
629 * Add a copy of platform specific data to the platform device's
630 * platform_data pointer. The memory associated with the platform data
631 * will be freed when the platform device is released.
641 return -ENOMEM; in platform_device_add_data()
644 kfree(pdev->dev.platform_data); in platform_device_add_data()
645 pdev->dev.platform_data = d; in platform_device_add_data()
651 * platform_device_add - add a platform device to device hierarchy
652 * @pdev: platform device we're adding
659 struct device *dev = &pdev->dev; in platform_device_add()
663 if (!dev->parent) in platform_device_add()
664 dev->parent = &platform_bus; in platform_device_add()
666 dev->bus = &platform_bus_type; in platform_device_add()
668 switch (pdev->id) { in platform_device_add()
670 dev_set_name(dev, "%s.%d", pdev->name, pdev->id); in platform_device_add()
673 dev_set_name(dev, "%s", pdev->name); in platform_device_add()
684 pdev->id = ret; in platform_device_add()
685 pdev->id_auto = true; in platform_device_add()
686 dev_set_name(dev, "%s.%d.auto", pdev->name, pdev->id); in platform_device_add()
690 for (i = 0; i < pdev->num_resources; i++) { in platform_device_add()
691 struct resource *p, *r = &pdev->resource[i]; in platform_device_add()
693 if (r->name == NULL) in platform_device_add()
694 r->name = dev_name(dev); in platform_device_add()
696 p = r->parent; in platform_device_add()
713 pr_debug("Registering platform device '%s'. Parent at %s\n", dev_name(dev), in platform_device_add()
714 dev_name(dev->parent)); in platform_device_add()
723 if (pdev->id_auto) { in platform_device_add()
724 ida_free(&platform_devid_ida, pdev->id); in platform_device_add()
725 pdev->id = PLATFORM_DEVID_AUTO; in platform_device_add()
728 while (i--) { in platform_device_add()
729 struct resource *r = &pdev->resource[i]; in platform_device_add()
730 if (r->parent) in platform_device_add()
739 * platform_device_del - remove a platform-level device
740 * @pdev: platform device we're removing
742 * Note that this function will also release all memory- and port-based
743 * resources owned by the device (@dev->resource). This function must
751 device_del(&pdev->dev); in platform_device_del()
753 if (pdev->id_auto) { in platform_device_del()
754 ida_free(&platform_devid_ida, pdev->id); in platform_device_del()
755 pdev->id = PLATFORM_DEVID_AUTO; in platform_device_del()
758 for (i = 0; i < pdev->num_resources; i++) { in platform_device_del()
759 struct resource *r = &pdev->resource[i]; in platform_device_del()
760 if (r->parent) in platform_device_del()
768 * platform_device_register - add a platform-level device
769 * @pdev: platform device we're adding
777 device_initialize(&pdev->dev); in platform_device_register()
784 * platform_device_unregister - unregister a platform-level device
785 * @pdev: platform device we're unregistering
799 * platform_device_register_full - add a platform-level device with
800 * resources and platform-specific data
812 pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id); in platform_device_register_full()
814 return ERR_PTR(-ENOMEM); in platform_device_register_full()
816 pdev->dev.parent = pdevinfo->parent; in platform_device_register_full()
817 pdev->dev.fwnode = pdevinfo->fwnode; in platform_device_register_full()
818 pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode)); in platform_device_register_full()
819 pdev->dev.of_node_reused = pdevinfo->of_node_reused; in platform_device_register_full()
821 if (pdevinfo->dma_mask) { in platform_device_register_full()
822 pdev->platform_dma_mask = pdevinfo->dma_mask; in platform_device_register_full()
823 pdev->dev.dma_mask = &pdev->platform_dma_mask; in platform_device_register_full()
824 pdev->dev.coherent_dma_mask = pdevinfo->dma_mask; in platform_device_register_full()
828 pdevinfo->res, pdevinfo->num_res); in platform_device_register_full()
833 pdevinfo->data, pdevinfo->size_data); in platform_device_register_full()
837 if (pdevinfo->properties) { in platform_device_register_full()
838 ret = device_create_managed_software_node(&pdev->dev, in platform_device_register_full()
839 pdevinfo->properties, NULL); in platform_device_register_full()
847 ACPI_COMPANION_SET(&pdev->dev, NULL); in platform_device_register_full()
857 * __platform_driver_register - register a driver for platform-level devices
858 * @drv: platform driver structure
864 drv->driver.owner = owner; in __platform_driver_register()
865 drv->driver.bus = &platform_bus_type; in __platform_driver_register()
867 return driver_register(&drv->driver); in __platform_driver_register()
872 * platform_driver_unregister - unregister a driver for platform-level devices
873 * @drv: platform driver structure
877 driver_unregister(&drv->driver); in platform_driver_unregister()
883 return -ENXIO; in platform_probe_fail()
888 if (dev->driver == driver) in is_bound_to_driver()
894 * __platform_driver_probe - register driver for non-hotpluggable device
895 * @drv: platform driver structure
901 * remove its run-once probe() infrastructure from memory after the driver
905 * into system-on-chip processors, where the controller devices have been
918 if (drv->driver.probe_type == PROBE_PREFER_ASYNCHRONOUS) { in __platform_driver_probe()
920 drv->driver.name, __func__); in __platform_driver_probe()
921 return -EINVAL; in __platform_driver_probe()
929 drv->driver.probe_type = PROBE_FORCE_SYNCHRONOUS; in __platform_driver_probe()
935 drv->prevent_deferred_probe = true; in __platform_driver_probe()
938 drv->driver.suppress_bind_attrs = true; in __platform_driver_probe()
941 drv->probe = probe; in __platform_driver_probe()
947 drv->probe = platform_probe_fail; in __platform_driver_probe()
949 /* Walk all platform devices and see if any actually bound to this driver. in __platform_driver_probe()
952 if (!bus_for_each_dev(&platform_bus_type, NULL, &drv->driver, is_bound_to_driver)) { in __platform_driver_probe()
953 retval = -ENODEV; in __platform_driver_probe()
962 * __platform_create_bundle - register driver and create corresponding device
963 * @driver: platform driver structure
967 * @data: platform specific data for this platform device
968 * @size: size of platform specific data
971 * Use this in legacy-style modules that probe hardware directly and
972 * register a single platform device and corresponding platform driver.
985 pdev = platform_device_alloc(driver->driver.name, -1); in __platform_create_bundle()
987 error = -ENOMEM; in __platform_create_bundle()
1019 * __platform_register_drivers - register an array of platform drivers
1024 * Registers platform drivers specified by an array. On failure to register a
1038 pr_debug("registering platform driver %ps\n", drivers[i]); in __platform_register_drivers()
1042 pr_err("failed to register platform driver %ps: %d\n", in __platform_register_drivers()
1051 while (i--) { in __platform_register_drivers()
1052 pr_debug("unregistering platform driver %ps\n", drivers[i]); in __platform_register_drivers()
1061 * platform_unregister_drivers - unregister an array of platform drivers
1065 * Unregisters platform drivers specified by an array. This is typically used
1072 while (count--) { in platform_unregister_drivers()
1073 pr_debug("unregistering platform driver %ps\n", drivers[count]); in platform_unregister_drivers()
1083 while (id->name[0]) { in platform_match_id()
1084 if (strcmp(pdev->name, id->name) == 0) { in platform_match_id()
1085 pdev->id_entry = id; in platform_match_id()
1097 struct platform_driver *pdrv = to_platform_driver(dev->driver); in platform_legacy_suspend()
1101 if (dev->driver && pdrv->suspend) in platform_legacy_suspend()
1102 ret = pdrv->suspend(pdev, mesg); in platform_legacy_suspend()
1109 struct platform_driver *pdrv = to_platform_driver(dev->driver); in platform_legacy_resume()
1113 if (dev->driver && pdrv->resume) in platform_legacy_resume()
1114 ret = pdrv->resume(pdev); in platform_legacy_resume()
1125 const struct device_driver *drv = dev->driver; in platform_pm_suspend()
1131 if (drv->pm) { in platform_pm_suspend()
1132 if (drv->pm->suspend) in platform_pm_suspend()
1133 ret = drv->pm->suspend(dev); in platform_pm_suspend()
1143 const struct device_driver *drv = dev->driver; in platform_pm_resume()
1149 if (drv->pm) { in platform_pm_resume()
1150 if (drv->pm->resume) in platform_pm_resume()
1151 ret = drv->pm->resume(dev); in platform_pm_resume()
1165 const struct device_driver *drv = dev->driver; in platform_pm_freeze()
1171 if (drv->pm) { in platform_pm_freeze()
1172 if (drv->pm->freeze) in platform_pm_freeze()
1173 ret = drv->pm->freeze(dev); in platform_pm_freeze()
1183 const struct device_driver *drv = dev->driver; in platform_pm_thaw()
1189 if (drv->pm) { in platform_pm_thaw()
1190 if (drv->pm->thaw) in platform_pm_thaw()
1191 ret = drv->pm->thaw(dev); in platform_pm_thaw()
1201 const struct device_driver *drv = dev->driver; in platform_pm_poweroff()
1207 if (drv->pm) { in platform_pm_poweroff()
1208 if (drv->pm->poweroff) in platform_pm_poweroff()
1209 ret = drv->pm->poweroff(dev); in platform_pm_poweroff()
1219 const struct device_driver *drv = dev->driver; in platform_pm_restore()
1225 if (drv->pm) { in platform_pm_restore()
1226 if (drv->pm->restore) in platform_pm_restore()
1227 ret = drv->pm->restore(dev); in platform_pm_restore()
1237 /* modalias support enables more hands-off userspace setup:
1238 * (a) environment variable lets new-style hotplug events work once system is
1240 * (b) sysfs attribute lets new-style coldplug recover from hotplug events
1250 if (len != -ENODEV) in modalias_show()
1253 len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1); in modalias_show()
1254 if (len != -ENODEV) in modalias_show()
1257 return sysfs_emit(buf, "platform:%s\n", pdev->name); in modalias_show()
1275 len = sysfs_emit(buf, "%s\n", pdev->driver_override); in driver_override_show()
1288 ret = driver_set_override(dev, &pdev->driver_override, buf, count); in driver_override_store()
1312 return a->mode; in platform_dev_attrs_visible()
1323 * platform_match - bind platform device to platform driver.
1327 * Platform device IDs are assumed to be encoded like this:
1328 * "<name><instance>", where <name> is a short description of the type of
1331 * "<name>". So, extract the <name> from the platform_device structure,
1332 * and compare it against the name of the driver. Return whether they match
1341 if (pdev->driver_override) in platform_match()
1342 return !strcmp(pdev->driver_override, drv->name); in platform_match()
1353 if (pdrv->id_table) in platform_match()
1354 return platform_match_id(pdrv->id_table, pdev) != NULL; in platform_match()
1356 /* fall-back to driver name match */ in platform_match()
1357 return (strcmp(pdev->name, drv->name) == 0); in platform_match()
1365 /* Some devices have extra OF data and an OF-style MODALIAS */ in platform_uevent()
1367 if (rc != -ENODEV) in platform_uevent()
1371 if (rc != -ENODEV) in platform_uevent()
1375 pdev->name); in platform_uevent()
1381 struct platform_driver *drv = to_platform_driver(_dev->driver); in platform_probe()
1392 if (unlikely(drv->probe == platform_probe_fail)) in platform_probe()
1393 return -ENXIO; in platform_probe()
1395 ret = of_clk_set_defaults(_dev->of_node, false); in platform_probe()
1403 if (drv->probe) { in platform_probe()
1404 ret = drv->probe(dev); in platform_probe()
1410 if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) { in platform_probe()
1412 ret = -ENXIO; in platform_probe()
1420 struct platform_driver *drv = to_platform_driver(_dev->driver); in platform_remove()
1423 if (drv->remove) in platform_remove()
1424 drv->remove(dev); in platform_remove()
1433 if (!_dev->driver) in platform_shutdown()
1436 drv = to_platform_driver(_dev->driver); in platform_shutdown()
1437 if (drv->shutdown) in platform_shutdown()
1438 drv->shutdown(dev); in platform_shutdown()
1443 struct platform_driver *drv = to_platform_driver(dev->driver); in platform_dma_configure()
1454 if (ret || drv->driver_managed_dma) in platform_dma_configure()
1466 struct platform_driver *drv = to_platform_driver(dev->driver); in platform_dma_cleanup()
1468 if (!drv->driver_managed_dma) in platform_dma_cleanup()
1478 .name = "platform",
1497 * platform_find_device_by_driver - Find a platform device with a given