Lines Matching +full:num +full:- +full:vectors

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>
48 * platform_get_resource - get a resource for a device
51 * @num: resource index
56 unsigned int type, unsigned int num) in platform_get_resource() argument
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()
71 unsigned int num) in platform_get_mem_or_io() argument
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
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
130 * devm_platform_ioremap_resource_byname - call devm_ioremap_resource for
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
156 * @num: IRQ number index
169 * Return: non-zero IRQ number on success, negative error number on failure.
171 int platform_get_irq_optional(struct platform_device *dev, unsigned int num) in platform_get_irq_optional() argument
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()
185 ret = of_irq_get(to_of_node(fwnode), num); in platform_get_irq_optional()
186 if (ret > 0 || ret == -EPROBE_DEFER) in platform_get_irq_optional()
190 r = platform_get_resource(dev, IORESOURCE_IRQ, num); in platform_get_irq_optional()
192 if (r && r->flags & IORESOURCE_DISABLED) { in platform_get_irq_optional()
193 ret = acpi_irq_get(ACPI_HANDLE_FWNODE(fwnode), num, r); 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()
226 if (num == 0 && is_acpi_device_node(fwnode)) { in platform_get_irq_optional()
227 ret = acpi_dev_gpio_irq_get(to_acpi_device_node(fwnode), num); 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
246 * @num: IRQ number index
258 * Return: non-zero IRQ number on success, negative error number on failure.
260 int platform_get_irq(struct platform_device *dev, unsigned int num) in platform_get_irq() argument
264 ret = platform_get_irq_optional(dev, num); in platform_get_irq()
266 return dev_err_probe(&dev->dev, ret, in platform_get_irq()
267 "IRQ index %u not found\n", num); in platform_get_irq()
274 * platform_irq_count - Count the number of IRQs a platform device uses
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
326 * @minvec: minimum count of interrupt vectors
327 * @maxvec: maximum count of interrupt vectors
333 * Return: Number of vectors on success, negative error number on failure.
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
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()
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()
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
466 * Return: non-zero IRQ number on success, negative error number on failure.
474 return dev_err_probe(&dev->dev, ret, "IRQ %s not found\n", in platform_get_irq_byname()
481 * platform_get_irq_byname_optional - get an optional IRQ for a device by name
488 * Return: non-zero IRQ number on success, negative error number on failure.
498 * platform_add_devices - add a numbers of platform devices
500 * @num: number of platform devices in array
504 int platform_add_devices(struct platform_device **devs, int num) in platform_add_devices() argument
508 for (i = 0; i < num; i++) { in platform_add_devices()
511 while (--i >= 0) in platform_add_devices()
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
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
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
599 * @num: number of resources
606 const struct resource *res, unsigned int num) in platform_device_add_resources() argument
611 r = kmemdup_array(res, num, sizeof(*r), GFP_KERNEL); in platform_device_add_resources()
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
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
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()
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
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
777 device_initialize(&pdev->dev); in platform_device_register()
784 * platform_device_unregister - unregister a platform-level device
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
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
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
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()
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
971 * Use this in legacy-style modules that probe hardware directly and
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
1051 while (i--) { in __platform_register_drivers()
1061 * platform_unregister_drivers - unregister an array of platform drivers
1072 while (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.
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()
1497 * platform_find_device_by_driver - Find a platform device with a given