^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * platform.c - platform 'pseudo' bus for legacy devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2002-3 Patrick Mochel
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2002-3 Open Source Development Labs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Please see Documentation/driver-api/driver-model/platform.rst for more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/pm_domain.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/idr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/clk/clk-conf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/property.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/kmemleak.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include "base.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include "power/power.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* For automatically allocated device IDs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static DEFINE_IDA(platform_devid_ida);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct device platform_bus = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .init_name = "platform",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) EXPORT_SYMBOL_GPL(platform_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * platform_get_resource - get a resource for a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * @type: resource type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * @num: resource index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * Return: a pointer to the resource or NULL on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct resource *platform_get_resource(struct platform_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) unsigned int type, unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) for (i = 0; i < dev->num_resources; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct resource *r = &dev->resource[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (type == resource_type(r) && num-- == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) EXPORT_SYMBOL_GPL(platform_get_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #ifdef CONFIG_HAS_IOMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) * platform device and get resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * @pdev: platform device to use both for memory resource lookup as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * @index: resource index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @res: optional output parameter to store a pointer to the obtained resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) void __iomem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) unsigned int index, struct resource **res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) r = platform_get_resource(pdev, IORESOURCE_MEM, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) if (res)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *res = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return devm_ioremap_resource(&pdev->dev, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) EXPORT_SYMBOL_GPL(devm_platform_get_and_ioremap_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * devm_platform_ioremap_resource - call devm_ioremap_resource() for a platform
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * @pdev: platform device to use both for memory resource lookup as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) * @index: resource index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void __iomem *devm_platform_ioremap_resource(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) return devm_platform_get_and_ioremap_resource(pdev, index, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * devm_platform_ioremap_resource_wc - write-combined variant of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * devm_platform_ioremap_resource()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) * @pdev: platform device to use both for memory resource lookup as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) * resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * @index: resource index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) * on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) void __iomem *devm_platform_ioremap_resource_wc(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) unsigned int index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) res = platform_get_resource(pdev, IORESOURCE_MEM, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return devm_ioremap_resource_wc(&pdev->dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * devm_platform_ioremap_resource_byname - call devm_ioremap_resource for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * a platform device, retrieve the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * resource by name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * @pdev: platform device to use both for memory resource lookup as well as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * resource management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * @name: name of the resource
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * Return: a pointer to the remapped memory or an ERR_PTR() encoded error code
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) void __iomem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) devm_platform_ioremap_resource_byname(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct resource *res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return devm_ioremap_resource(&pdev->dev, res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) EXPORT_SYMBOL_GPL(devm_platform_ioremap_resource_byname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) #endif /* CONFIG_HAS_IOMEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * platform_get_irq_optional - get an optional IRQ for a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * @num: IRQ number index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * Gets an IRQ for a platform device. Device drivers should check the return
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * value for errors so as to not pass a negative integer value to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * request_irq() APIs. This is the same as platform_get_irq(), except that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * does not print an error message if an IRQ can not be obtained.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * For example::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * int irq = platform_get_irq_optional(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) * Return: non-zero IRQ number on success, negative error number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) int platform_get_irq_optional(struct platform_device *dev, unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) #ifdef CONFIG_SPARC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /* sparc does not have irqs represented as IORESOURCE_IRQ resources */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (!dev || num >= dev->archdata.num_irqs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) ret = dev->archdata.irqs[num];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) ret = of_irq_get(dev->dev.of_node, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) if (ret > 0 || ret == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) r = platform_get_resource(dev, IORESOURCE_IRQ, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (has_acpi_companion(&dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) if (r && r->flags & IORESOURCE_DISABLED) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) ret = acpi_irq_get(ACPI_HANDLE(&dev->dev), num, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) * The resources may pass trigger flags to the irqs that need
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * to be set up. It so happens that the trigger flags for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * settings.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (r && r->flags & IORESOURCE_BITS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct irq_data *irqd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) irqd = irq_get_irq_data(r->start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!irqd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) ret = r->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) * For the index 0 interrupt, allow falling back to GpioInt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * resources. While a device could have both Interrupt and GpioInt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * resources, making this fallback ambiguous, in many common cases
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) * the device will only expose one IRQ, and this fallback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * allows a common code path across either kind of resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (num == 0 && has_acpi_companion(&dev->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) ret = acpi_dev_gpio_irq_get(ACPI_COMPANION(&dev->dev), num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Our callers expect -ENXIO for missing IRQs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if (ret >= 0 || ret == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) WARN(ret == 0, "0 is an invalid IRQ number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) EXPORT_SYMBOL_GPL(platform_get_irq_optional);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) * platform_get_irq - get an IRQ for a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) * @num: IRQ number index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) * Gets an IRQ for a platform device and prints an error message if finding the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) * IRQ fails. Device drivers should check the return value for errors so as to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) * not pass a negative integer value to the request_irq() APIs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) * For example::
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) * int irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) * if (irq < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) * return irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * Return: non-zero IRQ number on success, negative error number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) int platform_get_irq(struct platform_device *dev, unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) ret = platform_get_irq_optional(dev, num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) if (ret < 0 && ret != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) dev_err(&dev->dev, "IRQ index %u not found\n", num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) EXPORT_SYMBOL_GPL(platform_get_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * platform_irq_count - Count the number of IRQs a platform device uses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * Return: Number of IRQs a platform device uses or EPROBE_DEFER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int platform_irq_count(struct platform_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int ret, nr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) while ((ret = platform_get_irq_optional(dev, nr)) >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) nr++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (ret == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) EXPORT_SYMBOL_GPL(platform_irq_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) * platform_get_resource_byname - get a resource for a device by name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) * @type: resource type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * @name: resource name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct resource *platform_get_resource_byname(struct platform_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) unsigned int type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) for (i = 0; i < dev->num_resources; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) struct resource *r = &dev->resource[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) if (unlikely(!r->name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) if (type == resource_type(r) && !strcmp(r->name, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) EXPORT_SYMBOL_GPL(platform_get_resource_byname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) static int __platform_get_irq_byname(struct platform_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct resource *r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) ret = of_irq_get_byname(dev->dev.of_node, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (ret > 0 || ret == -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) WARN(r->start == 0, "0 is an invalid IRQ number\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return r->start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) * platform_get_irq_byname - get an IRQ for a device by name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * @name: IRQ name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) * Get an IRQ like platform_get_irq(), but then by name rather then by index.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) * Return: non-zero IRQ number on success, negative error number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) int platform_get_irq_byname(struct platform_device *dev, const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) ret = __platform_get_irq_byname(dev, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) if (ret < 0 && ret != -EPROBE_DEFER)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) dev_err(&dev->dev, "IRQ %s not found\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) EXPORT_SYMBOL_GPL(platform_get_irq_byname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * platform_get_irq_byname_optional - get an optional IRQ for a device by name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * @dev: platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * @name: IRQ name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) * Get an optional IRQ by name like platform_get_irq_byname(). Except that it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * does not print an error message if an IRQ can not be obtained.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * Return: non-zero IRQ number on success, negative error number on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) int platform_get_irq_byname_optional(struct platform_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return __platform_get_irq_byname(dev, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) EXPORT_SYMBOL_GPL(platform_get_irq_byname_optional);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) * platform_add_devices - add a numbers of platform devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) * @devs: array of platform devices to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) * @num: number of platform devices in array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) int platform_add_devices(struct platform_device **devs, int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int i, ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) for (i = 0; i < num; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) ret = platform_device_register(devs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) platform_device_unregister(devs[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) EXPORT_SYMBOL_GPL(platform_add_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) struct platform_object {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) struct platform_device pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) char name[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) * Set up default DMA mask for platform devices if the they weren't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) * previously set by the architecture / DT.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) static void setup_pdev_dma_masks(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) pdev->dev.dma_parms = &pdev->dma_parms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (!pdev->dev.coherent_dma_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) if (!pdev->dev.dma_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) pdev->platform_dma_mask = DMA_BIT_MASK(32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) pdev->dev.dma_mask = &pdev->platform_dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) * platform_device_put - destroy a platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * @pdev: platform device to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) * Free all memory associated with a platform device. This function must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * _only_ be externally called in error cases. All other usage is a bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) void platform_device_put(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) if (!IS_ERR_OR_NULL(pdev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) put_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) EXPORT_SYMBOL_GPL(platform_device_put);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static void platform_device_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) struct platform_object *pa = container_of(dev, struct platform_object,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) pdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) of_device_node_put(&pa->pdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) kfree(pa->pdev.dev.platform_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) kfree(pa->pdev.mfd_cell);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) kfree(pa->pdev.resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) kfree(pa->pdev.driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) kfree(pa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) * platform_device_alloc - create a platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) * @name: base name of the device we're adding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) * @id: instance id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) * Create a platform device object which can have other objects attached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) * to it, and which will have attached objects freed when it is released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) struct platform_device *platform_device_alloc(const char *name, int id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) struct platform_object *pa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) pa = kzalloc(sizeof(*pa) + strlen(name) + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) if (pa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) strcpy(pa->name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) pa->pdev.name = pa->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) pa->pdev.id = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) device_initialize(&pa->pdev.dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) pa->pdev.dev.release = platform_device_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) setup_pdev_dma_masks(&pa->pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return pa ? &pa->pdev : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) EXPORT_SYMBOL_GPL(platform_device_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) * platform_device_add_resources - add resources to a platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) * @pdev: platform device allocated by platform_device_alloc to add resources to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) * @res: set of resources that needs to be allocated for the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) * @num: number of resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) * Add a copy of the resources to the platform device. The memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) * associated with the resources will be freed when the platform device is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int platform_device_add_resources(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) const struct resource *res, unsigned int num)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) struct resource *r = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) if (res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (!r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) kfree(pdev->resource);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) pdev->resource = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) pdev->num_resources = num;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) EXPORT_SYMBOL_GPL(platform_device_add_resources);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * platform_device_add_data - add platform-specific data to a platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) * @pdev: platform device allocated by platform_device_alloc to add resources to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) * @data: platform specific data for this platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) * @size: size of platform specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) * Add a copy of platform specific data to the platform device's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) * platform_data pointer. The memory associated with the platform data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * will be freed when the platform device is released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) int platform_device_add_data(struct platform_device *pdev, const void *data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) size_t size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) void *d = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) d = kmemdup(data, size, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if (!d)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) kfree(pdev->dev.platform_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) pdev->dev.platform_data = d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) EXPORT_SYMBOL_GPL(platform_device_add_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) * platform_device_add_properties - add built-in properties to a platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) * @pdev: platform device to add properties to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * @properties: null terminated array of properties to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * The function will take deep copy of @properties and attach the copy to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * platform device. The memory associated with properties will be freed when the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) * platform device is released.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) int platform_device_add_properties(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) const struct property_entry *properties)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) return device_add_properties(&pdev->dev, properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) EXPORT_SYMBOL_GPL(platform_device_add_properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) * platform_device_add - add a platform device to device hierarchy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) * @pdev: platform device we're adding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * This is part 2 of platform_device_register(), though may be called
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) * separately _iff_ pdev was allocated by platform_device_alloc().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) int platform_device_add(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) if (!pdev->dev.parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pdev->dev.parent = &platform_bus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) pdev->dev.bus = &platform_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) switch (pdev->id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) case PLATFORM_DEVID_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) dev_set_name(&pdev->dev, "%s", pdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) case PLATFORM_DEVID_AUTO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * Automatically allocated device ID. We mark it as such so
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * that we remember it must be freed, and we append a suffix
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * to avoid namespace collision with explicit IDs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) ret = ida_alloc(&platform_devid_ida, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) pdev->id = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) pdev->id_auto = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) for (i = 0; i < pdev->num_resources; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) struct resource *p, *r = &pdev->resource[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) if (r->name == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) r->name = dev_name(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) p = r->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) if (!p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (resource_type(r) == IORESOURCE_MEM)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) p = &iomem_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) else if (resource_type(r) == IORESOURCE_IO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) p = &ioport_resource;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) if (p) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) ret = insert_resource(p, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) dev_err(&pdev->dev, "failed to claim resource %d: %pR\n", i, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) goto failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) pr_debug("Registering platform device '%s'. Parent at %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) dev_name(&pdev->dev), dev_name(pdev->dev.parent));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) ret = device_add(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (pdev->id_auto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) ida_free(&platform_devid_ida, pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) pdev->id = PLATFORM_DEVID_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) while (i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct resource *r = &pdev->resource[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) if (r->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) release_resource(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) EXPORT_SYMBOL_GPL(platform_device_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) * platform_device_del - remove a platform-level device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) * @pdev: platform device we're removing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * Note that this function will also release all memory- and port-based
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) * resources owned by the device (@dev->resource). This function must
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) * _only_ be externally called in error cases. All other usage is a bug.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) void platform_device_del(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) u32 i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (!IS_ERR_OR_NULL(pdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) device_del(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (pdev->id_auto) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) ida_free(&platform_devid_ida, pdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) pdev->id = PLATFORM_DEVID_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) for (i = 0; i < pdev->num_resources; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct resource *r = &pdev->resource[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (r->parent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) release_resource(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) EXPORT_SYMBOL_GPL(platform_device_del);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * platform_device_register - add a platform-level device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * @pdev: platform device we're adding
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) int platform_device_register(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) device_initialize(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) setup_pdev_dma_masks(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) return platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) EXPORT_SYMBOL_GPL(platform_device_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) * platform_device_unregister - unregister a platform-level device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * @pdev: platform device we're unregistering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) * Unregistration is done in 2 steps. First we release all resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * and remove it from the subsystem, then we drop reference count by
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * calling platform_device_put().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) void platform_device_unregister(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) platform_device_del(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) EXPORT_SYMBOL_GPL(platform_device_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) * platform_device_register_full - add a platform-level device with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) * resources and platform-specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * @pdevinfo: data used to create device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) struct platform_device *platform_device_register_full(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) const struct platform_device_info *pdevinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) if (!pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) pdev->dev.parent = pdevinfo->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) pdev->dev.fwnode = pdevinfo->fwnode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) pdev->dev.of_node = of_node_get(to_of_node(pdev->dev.fwnode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) pdev->dev.of_node_reused = pdevinfo->of_node_reused;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) if (pdevinfo->dma_mask) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) pdev->platform_dma_mask = pdevinfo->dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) pdev->dev.dma_mask = &pdev->platform_dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) pdev->dev.coherent_dma_mask = pdevinfo->dma_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) ret = platform_device_add_resources(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) pdevinfo->res, pdevinfo->num_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) ret = platform_device_add_data(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) pdevinfo->data, pdevinfo->size_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) if (pdevinfo->properties) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) ret = platform_device_add_properties(pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) pdevinfo->properties);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) ret = platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) ACPI_COMPANION_SET(&pdev->dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return ERR_PTR(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) return pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) EXPORT_SYMBOL_GPL(platform_device_register_full);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) static int platform_drv_probe(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct platform_driver *drv = to_platform_driver(_dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) struct platform_device *dev = to_platform_device(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) ret = of_clk_set_defaults(_dev->of_node, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) ret = dev_pm_domain_attach(_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) if (drv->probe) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) ret = drv->probe(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) dev_pm_domain_detach(_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) dev_warn(_dev, "probe deferral not supported\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) ret = -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) static int platform_drv_probe_fail(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) return -ENXIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) static int platform_drv_remove(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct platform_driver *drv = to_platform_driver(_dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) struct platform_device *dev = to_platform_device(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) if (drv->remove)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) ret = drv->remove(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) dev_pm_domain_detach(_dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) static void platform_drv_shutdown(struct device *_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) struct platform_driver *drv = to_platform_driver(_dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) struct platform_device *dev = to_platform_device(_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) if (drv->shutdown)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) drv->shutdown(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) * __platform_driver_register - register a driver for platform-level devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) * @drv: platform driver structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) * @owner: owning module/driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) int __platform_driver_register(struct platform_driver *drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) drv->driver.owner = owner;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) drv->driver.bus = &platform_bus_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) drv->driver.probe = platform_drv_probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) drv->driver.remove = platform_drv_remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) drv->driver.shutdown = platform_drv_shutdown;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) return driver_register(&drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) EXPORT_SYMBOL_GPL(__platform_driver_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) * platform_driver_unregister - unregister a driver for platform-level devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) * @drv: platform driver structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) void platform_driver_unregister(struct platform_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) driver_unregister(&drv->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) EXPORT_SYMBOL_GPL(platform_driver_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) * __platform_driver_probe - register driver for non-hotpluggable device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832) * @drv: platform driver structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) * @probe: the driver probe routine, probably from an __init section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) * @module: module which will be the owner of the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) * Use this instead of platform_driver_register() when you know the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) * is not hotpluggable and has already been registered, and you want to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) * remove its run-once probe() infrastructure from memory after the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) * has bound to the device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) * One typical use for this would be with drivers for controllers integrated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) * into system-on-chip processors, where the controller devices have been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) * configured as part of board setup.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) * Note that this is incompatible with deferred probing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * Returns zero if the driver registered and bound to a device, else returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) * a negative error code and with the driver not registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) int __init_or_module __platform_driver_probe(struct platform_driver *drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) int (*probe)(struct platform_device *), struct module *module)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) int retval, code;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) if (drv->driver.probe_type == PROBE_PREFER_ASYNCHRONOUS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) pr_err("%s: drivers registered with %s can not be probed asynchronously\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) drv->driver.name, __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) * We have to run our probes synchronously because we check if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) * we find any devices to bind to and exit with error if there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) * are any.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) drv->driver.probe_type = PROBE_FORCE_SYNCHRONOUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) * Prevent driver from requesting probe deferral to avoid further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) * futile probe attempts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) drv->prevent_deferred_probe = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) /* make sure driver won't have bind/unbind attributes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) drv->driver.suppress_bind_attrs = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) /* temporary section violation during probe() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) drv->probe = probe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) retval = code = __platform_driver_register(drv, module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) * Fixup that section violation, being paranoid about code scanning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * the list of drivers in order to probe new devices. Check to see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) * if the probe was successful, and make sure any forced probes of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) * new devices fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) spin_lock(&drv->driver.bus->p->klist_drivers.k_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) drv->probe = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) retval = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) drv->driver.probe = platform_drv_probe_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) spin_unlock(&drv->driver.bus->p->klist_drivers.k_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) if (code != retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) platform_driver_unregister(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) EXPORT_SYMBOL_GPL(__platform_driver_probe);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) * __platform_create_bundle - register driver and create corresponding device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) * @driver: platform driver structure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) * @probe: the driver probe routine, probably from an __init section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) * @res: set of resources that needs to be allocated for the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * @n_res: number of resources
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * @data: platform specific data for this platform device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * @size: size of platform specific data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * @module: module which will be the owner of the driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * Use this in legacy-style modules that probe hardware directly and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * register a single platform device and corresponding platform driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct platform_device * __init_or_module __platform_create_bundle(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) struct platform_driver *driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) int (*probe)(struct platform_device *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) struct resource *res, unsigned int n_res,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) const void *data, size_t size, struct module *module)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) struct platform_device *pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) pdev = platform_device_alloc(driver->driver.name, -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) if (!pdev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) error = platform_device_add_resources(pdev, res, n_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) goto err_pdev_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) error = platform_device_add_data(pdev, data, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) goto err_pdev_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) error = platform_device_add(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) goto err_pdev_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944) error = __platform_driver_probe(driver, probe, module);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) goto err_pdev_del;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) return pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) err_pdev_del:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) platform_device_del(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) err_pdev_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) platform_device_put(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) return ERR_PTR(error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) EXPORT_SYMBOL_GPL(__platform_create_bundle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) * __platform_register_drivers - register an array of platform drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) * @drivers: an array of drivers to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) * @count: the number of drivers to register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) * @owner: module owning the drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965) * Registers platform drivers specified by an array. On failure to register a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) * driver, all previously registered drivers will be unregistered. Callers of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) * this API should use platform_unregister_drivers() to unregister drivers in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) * the reverse order.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) * Returns: 0 on success or a negative error code on failure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) int __platform_register_drivers(struct platform_driver * const *drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973) unsigned int count, struct module *owner)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) pr_debug("registering platform driver %ps\n", drivers[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) err = __platform_driver_register(drivers[i], owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) pr_err("failed to register platform driver %ps: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) drivers[i], err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985) goto error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) while (i--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993) pr_debug("unregistering platform driver %ps\n", drivers[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) platform_driver_unregister(drivers[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) EXPORT_SYMBOL_GPL(__platform_register_drivers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) * platform_unregister_drivers - unregister an array of platform drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) * @drivers: an array of drivers to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) * @count: the number of drivers to unregister
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) * Unregisters platform drivers specified by an array. This is typically used
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) * to complement an earlier call to platform_register_drivers(). Drivers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) * unregistered in the reverse order in which they were registered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) void platform_unregister_drivers(struct platform_driver * const *drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) unsigned int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) pr_debug("unregistering platform driver %ps\n", drivers[count]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) platform_driver_unregister(drivers[count]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) EXPORT_SYMBOL_GPL(platform_unregister_drivers);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) /* modalias support enables more hands-off userspace setup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) * (a) environment variable lets new-style hotplug events work once system is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) * fully running: "modprobe $MODALIAS"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) * (b) sysfs attribute lets new-style coldplug recover from hotplug events
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) * mishandled before system is fully running: "modprobe $(cat modalias)"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) static ssize_t modalias_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) len = of_device_modalias(dev, buf, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) if (len != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) len = acpi_device_modalias(dev, buf, PAGE_SIZE - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) if (len != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) return sysfs_emit(buf, "platform:%s\n", pdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) static DEVICE_ATTR_RO(modalias);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static ssize_t driver_override_store(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) char *driver_override, *old, *cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) /* We need to keep extra room for a newline */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) if (count >= (PAGE_SIZE - 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) driver_override = kstrndup(buf, count, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) if (!driver_override)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) cp = strchr(driver_override, '\n');
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) if (cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) *cp = '\0';
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) old = pdev->driver_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) if (strlen(driver_override)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) pdev->driver_override = driver_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) kfree(driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) pdev->driver_override = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) kfree(old);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) static ssize_t driver_override_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) ssize_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) device_lock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) len = sysfs_emit(buf, "%s\n", pdev->driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) device_unlock(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) static DEVICE_ATTR_RW(driver_override);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) static ssize_t numa_node_show(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) return sysfs_emit(buf, "%d\n", dev_to_node(dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) static DEVICE_ATTR_RO(numa_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) static umode_t platform_dev_attrs_visible(struct kobject *kobj, struct attribute *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) struct device *dev = container_of(kobj, typeof(*dev), kobj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) if (a == &dev_attr_numa_node.attr &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) dev_to_node(dev) == NUMA_NO_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) return a->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) static struct attribute *platform_dev_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) &dev_attr_modalias.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) &dev_attr_numa_node.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) &dev_attr_driver_override.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) static struct attribute_group platform_dev_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) .attrs = platform_dev_attrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) .is_visible = platform_dev_attrs_visible,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) __ATTRIBUTE_GROUPS(platform_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) /* Some devices have extra OF data and an OF-style MODALIAS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) rc = of_device_uevent_modalias(dev, env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) if (rc != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) rc = acpi_device_uevent_modalias(dev, env);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) if (rc != -ENODEV)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) pdev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) static const struct platform_device_id *platform_match_id(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) const struct platform_device_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) while (id->name[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) if (strcmp(pdev->name, id->name) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) pdev->id_entry = id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) return id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) id++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) * platform_match - bind platform device to platform driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) * @dev: device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) * @drv: driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) * Platform device IDs are assumed to be encoded like this:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) * "<name><instance>", where <name> is a short description of the type of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) * device, like "pci" or "floppy", and <instance> is the enumerated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) * instance of the device, like '0' or '42'. Driver IDs are simply
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) * "<name>". So, extract the <name> from the platform_device structure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) * and compare it against the name of the driver. Return whether they match
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) * or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) static int platform_match(struct device *dev, struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) struct platform_driver *pdrv = to_platform_driver(drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) /* When driver_override is set, only bind to the matching driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) if (pdev->driver_override)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) return !strcmp(pdev->driver_override, drv->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) /* Attempt an OF style match first */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) if (of_driver_match_device(dev, drv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) /* Then try ACPI style match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) if (acpi_driver_match_device(dev, drv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) /* Then try to match against the id table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (pdrv->id_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) return platform_match_id(pdrv->id_table, pdev) != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) /* fall-back to driver name match */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) return (strcmp(pdev->name, drv->name) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) struct platform_driver *pdrv = to_platform_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) if (dev->driver && pdrv->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) ret = pdrv->suspend(pdev, mesg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) static int platform_legacy_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) struct platform_driver *pdrv = to_platform_driver(dev->driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) struct platform_device *pdev = to_platform_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) if (dev->driver && pdrv->resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) ret = pdrv->resume(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) #endif /* CONFIG_PM_SLEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) #ifdef CONFIG_SUSPEND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) int platform_pm_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) struct device_driver *drv = dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) if (drv->pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) if (drv->pm->suspend)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) ret = drv->pm->suspend(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) ret = platform_legacy_suspend(dev, PMSG_SUSPEND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) int platform_pm_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) struct device_driver *drv = dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) if (drv->pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) if (drv->pm->resume)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) ret = drv->pm->resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) ret = platform_legacy_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) #endif /* CONFIG_SUSPEND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) #ifdef CONFIG_HIBERNATE_CALLBACKS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) int platform_pm_freeze(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) struct device_driver *drv = dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) if (drv->pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) if (drv->pm->freeze)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) ret = drv->pm->freeze(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) ret = platform_legacy_suspend(dev, PMSG_FREEZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) int platform_pm_thaw(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) struct device_driver *drv = dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) if (drv->pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) if (drv->pm->thaw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) ret = drv->pm->thaw(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) ret = platform_legacy_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) int platform_pm_poweroff(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) struct device_driver *drv = dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) if (drv->pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (drv->pm->poweroff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) ret = drv->pm->poweroff(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) ret = platform_legacy_suspend(dev, PMSG_HIBERNATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) int platform_pm_restore(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) struct device_driver *drv = dev->driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) if (!drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (drv->pm) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) if (drv->pm->restore)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) ret = drv->pm->restore(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) ret = platform_legacy_resume(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) #endif /* CONFIG_HIBERNATE_CALLBACKS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) int platform_dma_configure(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) enum dev_dma_attr attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) if (dev->of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) ret = of_dma_configure(dev, dev->of_node, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) } else if (has_acpi_companion(dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) attr = acpi_get_dma_attr(to_acpi_device_node(dev->fwnode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) ret = acpi_dma_configure(dev, attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) static const struct dev_pm_ops platform_dev_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) .runtime_suspend = pm_generic_runtime_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) .runtime_resume = pm_generic_runtime_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) USE_PLATFORM_PM_SLEEP_OPS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) struct bus_type platform_bus_type = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) .name = "platform",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) .dev_groups = platform_dev_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) .match = platform_match,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) .uevent = platform_uevent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) .dma_configure = platform_dma_configure,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) .pm = &platform_dev_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) EXPORT_SYMBOL_GPL(platform_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) static inline int __platform_match(struct device *dev, const void *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) return platform_match(dev, (struct device_driver *)drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) * platform_find_device_by_driver - Find a platform device with a given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) * driver.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) * @start: The device to start the search from.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) * @drv: The device driver to look for.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) struct device *platform_find_device_by_driver(struct device *start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) const struct device_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) return bus_find_device(&platform_bus_type, start, drv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) __platform_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) EXPORT_SYMBOL_GPL(platform_find_device_by_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) void __weak __init early_platform_cleanup(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) int __init platform_bus_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) early_platform_cleanup();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) error = device_register(&platform_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) put_device(&platform_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) error = bus_register(&platform_bus_type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) device_unregister(&platform_bus);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) of_platform_register_reconfig_notifier();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }