cregit-Linux how code gets into the kernel

Release 4.11 drivers/base/platform.c

Directory: drivers/base
/*
 * platform.c - platform 'pseudo' bus for legacy devices
 *
 * Copyright (c) 2002-3 Patrick Mochel
 * Copyright (c) 2002-3 Open Source Development Labs
 *
 * This file is released under the GPLv2
 *
 * Please see Documentation/driver-model/platform.txt for more
 * information.
 */

#include <linux/string.h>
#include <linux/platform_device.h>
#include <linux/of_device.h>
#include <linux/of_irq.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/dma-mapping.h>
#include <linux/bootmem.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/pm_runtime.h>
#include <linux/pm_domain.h>
#include <linux/idr.h>
#include <linux/acpi.h>
#include <linux/clk/clk-conf.h>
#include <linux/limits.h>
#include <linux/property.h>

#include "base.h"
#include "power/power.h"

/* For automatically allocated device IDs */
static DEFINE_IDA(platform_devid_ida);


struct device platform_bus = {
	.init_name	= "platform",
};

EXPORT_SYMBOL_GPL(platform_bus);

/**
 * arch_setup_pdev_archdata - Allow manipulation of archdata before its used
 * @pdev: platform device
 *
 * This is called before platform_device_add() such that any pdev_archdata may
 * be setup before the platform_notifier is called.  So if a user needs to
 * manipulate any relevant information in the pdev_archdata they can do:
 *
 *      platform_device_alloc()
 *      ... manipulate ...
 *      platform_device_add()
 *
 * And if they don't care they can just call platform_device_register() and
 * everything will just work out.
 */

void __weak arch_setup_pdev_archdata(struct platform_device *pdev) { }

Contributors

PersonTokensPropCommitsCommitProp
Kumar Gala10100.00%1100.00%
Total10100.00%1100.00%

/** * platform_get_resource - get a resource for a device * @dev: platform device * @type: resource type * @num: resource index */
struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsigned int num) { int i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; if (type == resource_type(r) && num-- == 0) return r; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King6791.78%150.00%
Magnus Damm68.22%150.00%
Total73100.00%2100.00%

EXPORT_SYMBOL_GPL(platform_get_resource); /** * platform_get_irq - get an IRQ for a device * @dev: platform device * @num: IRQ number index */
int platform_get_irq(struct platform_device *dev, unsigned int num) { #ifdef CONFIG_SPARC /* sparc does not have irqs represented as IORESOURCE_IRQ resources */ if (!dev || num >= dev->archdata.num_irqs) return -ENXIO; return dev->archdata.irqs[num]; #else struct resource *r; if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) { int ret; ret = of_irq_get(dev->dev.of_node, num); if (ret > 0 || ret == -EPROBE_DEFER) return ret; } r = platform_get_resource(dev, IORESOURCE_IRQ, num); if (has_acpi_companion(&dev->dev)) { if (r && r->flags & IORESOURCE_DISABLED) { int ret; ret = acpi_irq_get(ACPI_HANDLE(&dev->dev), num, r); if (ret) return ret; } } /* * The resources may pass trigger flags to the irqs that need * to be set up. It so happens that the trigger flags for * IORESOURCE_BITS correspond 1-to-1 to the IRQF_TRIGGER* * settings. */ if (r && r->flags & IORESOURCE_BITS) { struct irq_data *irqd; irqd = irq_get_irq_data(r->start); if (!irqd) return -ENXIO; irqd_set_trigger_type(irqd, r->flags & IORESOURCE_BITS); } return r ? r->start : -ENXIO; #endif }

Contributors

PersonTokensPropCommitsCommitProp
Agustin Vega-Frias5123.39%111.11%
Guenter Roeck4219.27%222.22%
Andreas Larsson3516.06%111.11%
Russell King3415.60%111.11%
Rob Herring2812.84%111.11%
Linus Walleij2511.47%111.11%
David Vrabel20.92%111.11%
Sergei Shtylyov10.46%111.11%
Total218100.00%9100.00%

EXPORT_SYMBOL_GPL(platform_get_irq); /** * platform_irq_count - Count the number of IRQs a platform device uses * @dev: platform device * * Return: Number of IRQs a platform device uses or EPROBE_DEFER */
int platform_irq_count(struct platform_device *dev) { int ret, nr = 0; while ((ret = platform_get_irq(dev, nr)) >= 0) nr++; if (ret == -EPROBE_DEFER) return ret; return nr; }

Contributors

PersonTokensPropCommitsCommitProp
Stephen Boyd48100.00%1100.00%
Total48100.00%1100.00%

EXPORT_SYMBOL_GPL(platform_irq_count); /** * platform_get_resource_byname - get a resource for a device by name * @dev: platform device * @type: resource type * @name: resource name */
struct resource *platform_get_resource_byname(struct platform_device *dev, unsigned int type, const char *name) { int i; for (i = 0; i < dev->num_resources; i++) { struct resource *r = &dev->resource[i]; if (unlikely(!r->name)) continue; if (type == resource_type(r) && !strcmp(r->name, name)) return r; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Kumar Gala7280.00%125.00%
Peter Ujfalusi1112.22%125.00%
Magnus Damm66.67%125.00%
Linus Walleij11.11%125.00%
Total90100.00%4100.00%

EXPORT_SYMBOL_GPL(platform_get_resource_byname); /** * platform_get_irq_byname - get an IRQ for a device by name * @dev: platform device * @name: IRQ name */
int platform_get_irq_byname(struct platform_device *dev, const char *name) { struct resource *r; if (IS_ENABLED(CONFIG_OF_IRQ) && dev->dev.of_node) { int ret; ret = of_irq_get_byname(dev->dev.of_node, name); if (ret > 0 || ret == -EPROBE_DEFER) return ret; } r = platform_get_resource_byname(dev, IORESOURCE_IRQ, name); return r ? r->start : -ENXIO; }

Contributors

PersonTokensPropCommitsCommitProp
Kumar Gala3439.53%116.67%
Grygorii Strashko2832.56%116.67%
Guenter Roeck2023.26%116.67%
David Vrabel22.33%116.67%
Linus Walleij11.16%116.67%
Sergei Shtylyov11.16%116.67%
Total86100.00%6100.00%

EXPORT_SYMBOL_GPL(platform_get_irq_byname); /** * platform_add_devices - add a numbers of platform devices * @devs: array of platform devices to add * @num: number of platform devices in array */
int platform_add_devices(struct platform_device **devs, int num) { int i, ret = 0; for (i = 0; i < num; i++) { ret = platform_device_register(devs[i]); if (ret) { while (--i >= 0) platform_device_unregister(devs[i]); break; } } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King71100.00%2100.00%
Total71100.00%2100.00%

EXPORT_SYMBOL_GPL(platform_add_devices); struct platform_object { struct platform_device pdev; char name[]; }; /** * platform_device_put - destroy a platform device * @pdev: platform device to free * * Free all memory associated with a platform device. This function must * _only_ be externally called in error cases. All other usage is a bug. */
void platform_device_put(struct platform_device *pdev) { if (pdev) put_device(&pdev->dev); }

Contributors

PersonTokensPropCommitsCommitProp
Russell King22100.00%1100.00%
Total22100.00%1100.00%

EXPORT_SYMBOL_GPL(platform_device_put);
static void platform_device_release(struct device *dev) { struct platform_object *pa = container_of(dev, struct platform_object, pdev.dev); of_device_node_put(&pa->pdev.dev); kfree(pa->pdev.dev.platform_data); kfree(pa->pdev.mfd_cell); kfree(pa->pdev.resource); kfree(pa->pdev.driver_override); kfree(pa); }

Contributors

PersonTokensPropCommitsCommitProp
Russell King5365.43%125.00%
Grant C. Likely1012.35%125.00%
Kim Phillips911.11%125.00%
Samuel Ortiz911.11%125.00%
Total81100.00%4100.00%

/** * platform_device_alloc - create a platform device * @name: base name of the device we're adding * @id: instance id * * Create a platform device object which can have other objects attached * to it, and which will have attached objects freed when it is released. */
struct platform_device *platform_device_alloc(const char *name, int id) { struct platform_object *pa; pa = kzalloc(sizeof(*pa) + strlen(name) + 1, GFP_KERNEL); if (pa) { strcpy(pa->name, name); pa->pdev.name = pa->name; pa->pdev.id = id; device_initialize(&pa->pdev.dev); pa->pdev.dev.release = platform_device_release; arch_setup_pdev_archdata(&pa->pdev); } return pa ? &pa->pdev : NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King9888.29%125.00%
Kumar Gala87.21%125.00%
Yann Droneaud43.60%125.00%
Patrick Mochel10.90%125.00%
Total111100.00%4100.00%

EXPORT_SYMBOL_GPL(platform_device_alloc); /** * platform_device_add_resources - add resources to a platform device * @pdev: platform device allocated by platform_device_alloc to add resources to * @res: set of resources that needs to be allocated for the device * @num: number of resources * * Add a copy of the resources to the platform device. The memory * associated with the resources will be freed when the platform device is * released. */
int platform_device_add_resources(struct platform_device *pdev, const struct resource *res, unsigned int num) { struct resource *r = NULL; if (res) { r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); if (!r) return -ENOMEM; } kfree(pdev->resource); pdev->resource = r; pdev->num_resources = num; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King5567.90%116.67%
Uwe Kleine-König2125.93%350.00%
Anton Vorontsov44.94%116.67%
Geert Uytterhoeven11.23%116.67%
Total81100.00%6100.00%

EXPORT_SYMBOL_GPL(platform_device_add_resources); /** * platform_device_add_data - add platform-specific data to a platform device * @pdev: platform device allocated by platform_device_alloc to add resources to * @data: platform specific data for this platform device * @size: size of platform specific data * * Add a copy of platform specific data to the platform device's * platform_data pointer. The memory associated with the platform data * will be freed when the platform device is released. */
int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size) { void *d = NULL; if (data) { d = kmemdup(data, size, GFP_KERNEL); if (!d) return -ENOMEM; } kfree(pdev->dev.platform_data); pdev->dev.platform_data = d; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King3854.29%116.67%
Uwe Kleine-König1825.71%233.33%
Anton Vorontsov811.43%116.67%
Andrew Morton57.14%116.67%
Scott Wood11.43%116.67%
Total70100.00%6100.00%

EXPORT_SYMBOL_GPL(platform_device_add_data); /** * platform_device_add_properties - add built-in properties to a platform device * @pdev: platform device to add properties to * @properties: null terminated array of properties to add * * The function will take deep copy of @properties and attach the copy to the * platform device. The memory associated with properties will be freed when the * platform device is released. */
int platform_device_add_properties(struct platform_device *pdev, struct property_entry *properties) { return device_add_properties(&pdev->dev, properties); }

Contributors

PersonTokensPropCommitsCommitProp
Mika Westerberg2284.62%150.00%
Heikki Krogerus415.38%150.00%
Total26100.00%2100.00%

EXPORT_SYMBOL_GPL(platform_device_add_properties); /** * platform_device_add - add a platform device to device hierarchy * @pdev: platform device we're adding * * This is part 2 of platform_device_register(), though may be called * separately _iff_ pdev was allocated by platform_device_alloc(). */
int platform_device_add(struct platform_device *pdev) { int i, ret; if (!pdev) return -EINVAL; if (!pdev->dev.parent) pdev->dev.parent = &platform_bus; pdev->dev.bus = &platform_bus_type; switch (pdev->id) { default: dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id); break; case PLATFORM_DEVID_NONE: dev_set_name(&pdev->dev, "%s", pdev->name); break; case PLATFORM_DEVID_AUTO: /* * Automatically allocated device ID. We mark it as such so * that we remember it must be freed, and we append a suffix * to avoid namespace collision with explicit IDs. */ ret = ida_simple_get(&platform_devid_ida, 0, 0, GFP_KERNEL); if (ret < 0) goto err_out; pdev->id = ret; pdev->id_auto = true; dev_set_name(&pdev->dev, "%s.%d.auto", pdev->name, pdev->id); break; } for (i = 0; i < pdev->num_resources; i++) { struct resource *p, *r = &pdev->resource[i]; if (r->name == NULL) r->name = dev_name(&pdev->dev); p = r->parent; if (!p) { if (resource_type(r) == IORESOURCE_MEM) p = &iomem_resource; else if (resource_type(r) == IORESOURCE_IO) p = &ioport_resource; } if (p && insert_resource(p, r)) { dev_err(&pdev->dev, "failed to claim resource %d: %pR\n", i, r); ret = -EBUSY; goto failed; } } pr_debug("Registering platform device '%s'. Parent at %s\n", dev_name(&pdev->dev), dev_name(pdev->dev.parent)); ret = device_add(&pdev->dev); if (ret == 0) return ret; failed: if (pdev->id_auto) { ida_simple_remove(&platform_devid_ida, pdev->id); pdev->id = PLATFORM_DEVID_AUTO; } while (--i >= 0) { struct resource *r = &pdev->resource[i]; if (r->parent) release_resource(r); } err_out: return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King9524.36%314.29%
Greg Kroah-Hartman8521.79%419.05%
Patrick Mochel8020.51%14.76%
Jean Delvare6717.18%29.52%
Kay Sievers174.36%14.76%
Dmitry Torokhov153.85%14.76%
David Brownell102.56%14.76%
Kumar Gala82.05%14.76%
Chen Yu30.77%14.76%
Grant C. Likely30.77%14.76%
Fabio Porcedda20.51%14.76%
Magnus Damm20.51%14.76%
Ricardo Ribalda Delgado20.51%29.52%
Andrew Morton10.26%14.76%
Total390100.00%21100.00%

EXPORT_SYMBOL_GPL(platform_device_add); /** * platform_device_del - remove a platform-level device * @pdev: platform device we're removing * * Note that this function will also release all memory- and port-based * resources owned by the device (@dev->resource). This function must * _only_ be externally called in error cases. All other usage is a bug. */
void platform_device_del(struct platform_device *pdev) { int i; if (pdev) { device_remove_properties(&pdev->dev); device_del(&pdev->dev); if (pdev->id_auto) { ida_simple_remove(&platform_devid_ida, pdev->id); pdev->id = PLATFORM_DEVID_AUTO; } for (i = 0; i < pdev->num_resources; i++) { struct resource *r = &pdev->resource[i]; if (r->parent) release_resource(r); } } }

Contributors

PersonTokensPropCommitsCommitProp
Greg Kroah-Hartman6060.00%111.11%
Patrick Mochel1212.00%111.11%
Jean Delvare99.00%222.22%
Jerome Marchand88.00%111.11%
Russell King66.00%111.11%
Grant C. Likely33.00%111.11%
Dmitry Torokhov11.00%111.11%
Ricardo Ribalda Delgado11.00%111.11%
Total100100.00%9100.00%

EXPORT_SYMBOL_GPL(platform_device_del); /** * platform_device_register - add a platform-level device * @pdev: platform device we're adding */
int platform_device_register(struct platform_device *pdev) { device_initialize(&pdev->dev); arch_setup_pdev_archdata(pdev); return platform_device_add(pdev); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov2379.31%250.00%
Kumar Gala517.24%125.00%
Russell King13.45%125.00%
Total29100.00%4100.00%

EXPORT_SYMBOL_GPL(platform_device_register); /** * platform_device_unregister - unregister a platform-level device * @pdev: platform device we're unregistering * * Unregistration is done in 2 steps. First we release all resources * and remove it from the subsystem, then we drop reference count by * calling platform_device_put(). */
void platform_device_unregister(struct platform_device *pdev) { platform_device_del(pdev); platform_device_put(pdev); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov1995.00%150.00%
Patrick Mochel15.00%150.00%
Total20100.00%2100.00%

EXPORT_SYMBOL_GPL(platform_device_unregister); /** * platform_device_register_full - add a platform-level device with * resources and platform-specific data * * @pdevinfo: data used to create device * * Returns &struct platform_device pointer on success, or ERR_PTR() on error. */
struct platform_device *platform_device_register_full( const struct platform_device_info *pdevinfo) { int ret = -ENOMEM; struct platform_device *pdev; pdev = platform_device_alloc(pdevinfo->name, pdevinfo->id); if (!pdev) goto err_alloc; pdev->dev.parent = pdevinfo->parent; pdev->dev.fwnode = pdevinfo->fwnode; if (pdevinfo->dma_mask) { /* * This memory isn't freed when the device is put, * I don't have a nice idea for that though. Conceptually * dma_mask in struct device should not be a pointer. * See http://thread.gmane.org/gmane.linux.kernel.pci/9081 */ pdev->dev.dma_mask = kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL); if (!pdev->dev.dma_mask) goto err; *pdev->dev.dma_mask = pdevinfo->dma_mask; pdev->dev.coherent_dma_mask = pdevinfo->dma_mask; } ret = platform_device_add_resources(pdev, pdevinfo->res, pdevinfo->num_res); if (ret) goto err; ret = platform_device_add_data(pdev, pdevinfo->data, pdevinfo->size_data); if (ret) goto err; if (pdevinfo->properties) { ret = platform_device_add_properties(pdev, pdevinfo->properties); if (ret) goto err; } ret = platform_device_add(pdev); if (ret) { err: ACPI_COMPANION_SET(&pdev->dev, NULL); kfree(pdev->dev.dma_mask); err_alloc: platform_device_put(pdev); return ERR_PTR(ret); } return pdev; }

Contributors

PersonTokensPropCommitsCommitProp
Uwe Kleine-König12650.81%327.27%
Dmitry Baryshkov3514.11%19.09%
Dmitry Torokhov2610.48%19.09%
Mika Westerberg249.68%19.09%
Rafael J. Wysocki208.06%327.27%
Russell King156.05%19.09%
Heikki Krogerus20.81%19.09%
Total248100.00%11100.00%

EXPORT_SYMBOL_GPL(platform_device_register_full);
static int platform_drv_probe(struct device *_dev) { struct platform_driver *drv = to_platform_driver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); int ret; ret = of_clk_set_defaults(_dev->of_node, false); if (ret < 0) return ret; ret = dev_pm_domain_attach(_dev, true); if (ret != -EPROBE_DEFER) { if (drv->probe) { ret = drv->probe(dev); if (ret) dev_pm_domain_detach(_dev, true); } else { /* don't fail if just dev_pm_domain_attach failed */ ret = 0; } } if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) { dev_warn(_dev, "probe deferral not supported\n"); ret = -ENXIO; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King4028.99%114.29%
Johan Hovold2518.12%114.29%
Rafael J. Wysocki2417.39%114.29%
Sylwester Nawrocki2014.49%114.29%
Ulf Hansson139.42%114.29%
Martin Wilck139.42%114.29%
Uwe Kleine-König32.17%114.29%
Total138100.00%7100.00%


static int platform_drv_probe_fail(struct device *_dev) { return -ENXIO; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell15100.00%1100.00%
Total15100.00%1100.00%


static int platform_drv_remove(struct device *_dev) { struct platform_driver *drv = to_platform_driver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); int ret = 0; if (drv->remove) ret = drv->remove(dev); dev_pm_domain_detach(_dev, true); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Russell King4063.49%125.00%
Rafael J. Wysocki1422.22%125.00%
Uwe Kleine-König812.70%125.00%
Ulf Hansson11.59%125.00%
Total63100.00%4100.00%


static void platform_drv_shutdown(struct device *_dev) { struct platform_driver *drv = to_platform_driver(_dev->driver); struct platform_device *dev = to_platform_device(_dev); if (drv->shutdown) drv->shutdown(dev); }

Contributors

PersonTokensPropCommitsCommitProp
Russell King4086.96%150.00%
Uwe Kleine-König613.04%150.00%
Total46100.00%2100.00%

/** * __platform_driver_register - register a driver for platform-level devices * @drv: platform driver structure * @owner: owning module/driver */
int __platform_driver_register(struct platform_driver *drv, struct module *owner) { drv->driver.owner = owner; drv->driver.bus = &platform_bus_type; drv->driver.probe = platform_drv_probe; drv->driver.remove = platform_drv_remove; drv->driver.shutdown = platform_drv_shutdown; return driver_register(&drv->driver); }

Contributors

PersonTokensPropCommitsCommitProp
Russell King5178.46%150.00%
Libo Chen1421.54%150.00%
Total65100.00%2100.00%

EXPORT_SYMBOL_GPL(__platform_driver_register); /** * platform_driver_unregister - unregister a driver for platform-level devices * @drv: platform driver structure */
void platform_driver_unregister(struct platform_driver *drv) { driver_unregister(&drv->driver); }

Contributors

PersonTokensPropCommitsCommitProp
Russell King18100.00%1100.00%
Total18100.00%1100.00%

EXPORT_SYMBOL_GPL(platform_driver_unregister); /** * __platform_driver_probe - register driver for non-hotpluggable device * @drv: platform driver structure * @probe: the driver probe routine, probably from an __init section * @module: module which will be the owner of the driver * * Use this instead of platform_driver_register() when you know the device * is not hotpluggable and has already been registered, and you want to * remove its run-once probe() infrastructure from memory after the driver * has bound to the device. * * One typical use for this would be with drivers for controllers integrated * into system-on-chip processors, where the controller devices have been * configured as part of board setup. * * Note that this is incompatible with deferred probing. * * Returns zero if the driver registered and bound to a device, else returns * a negative error code and with the driver not registered. */
int __init_or_module __platform_driver_probe(struct platform_driver *drv, int (*probe)(struct platform_device *), struct module *module) { int retval, code; if (drv->driver.probe_type == PROBE_PREFER_ASYNCHRONOUS) { pr_err("%s: drivers registered with %s can not be probed asynchronously\n", drv->driver.name, __func__); return -EINVAL; } /* * We have to run our probes synchronously because we check if * we find any devices to bind to and exit with error if there * are any. */ drv->driver.probe_type = PROBE_FORCE_SYNCHRONOUS; /* * Prevent driver from requesting probe deferral to avoid further * futile probe attempts. */ drv->prevent_deferred_probe = true; /* make sure driver won't have bind/unbind attributes */ drv->driver.suppress_bind_attrs = true; /* temporary section violation during probe() */ drv->probe = probe; retval = code = __platform_driver_register(drv, module); /* * Fixup that section violation, being paranoid about code scanning * the list of drivers in order to probe new devices. Check to see * if the probe was successful, and make sure any forced probes of * new devices fail. */ spin_lock(&drv->driver.bus->p->klist_drivers.k_lock); drv->probe = NULL; if (code == 0 && list_empty(&drv->driver.p->klist_devices.k_list)) retval = -ENODEV; drv->driver.probe = platform_drv_probe_fail; spin_unlock(&drv->driver.bus->p->klist_drivers.k_lock); if (code != retval) platform_driver_unregister(drv); return retval; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell10957.37%111.11%
Dmitry Torokhov4825.26%222.22%
Patrick Pannuto105.26%111.11%
Wolfram Sang94.74%111.11%
Johan Hovold73.68%111.11%
Greg Kroah-Hartman63.16%222.22%
Andrew Morton10.53%111.11%
Total190100.00%9100.00%

EXPORT_SYMBOL_GPL(__platform_driver_probe); /** * __platform_create_bundle - register driver and create corresponding device * @driver: platform driver structure * @probe: the driver probe routine, probably from an __init section * @res: set of resources that needs to be allocated for the device * @n_res: number of resources * @data: platform specific data for this platform device * @size: size of platform specific data * @module: module which will be the owner of the driver * * Use this in legacy-style modules that probe hardware directly and * register a single platform device and corresponding platform driver. * * Returns &struct platform_device pointer on success, or ERR_PTR() on error. */
struct platform_device * __init_or_module __platform_create_bundle( struct platform_driver *driver, int (*probe)(struct platform_device *), struct resource *res, unsigned int n_res, const void *data, size_t size, struct module *module) { struct platform_device *pdev; int error; pdev = platform_device_alloc(driver->driver.name, -1); if (!pdev) { error = -ENOMEM; goto err_out; } error = platform_device_add_resources(pdev, res, n_res); if (error) goto err_pdev_put; error = platform_device_add_data(pdev, data, size); if (error) goto err_pdev_put; error = platform_device_add(pdev); if (error) goto err_pdev_put; error = __platform_driver_probe(driver, probe, module); if (error) goto err_pdev_del; return pdev; err_pdev_del: platform_device_del(pdev); err_pdev_put: platform_device_put(pdev); err_out: return ERR_PTR(error); }

Contributors

PersonTokensPropCommitsCommitProp
Dmitry Torokhov16794.89%150.00%
Wolfram Sang95.11%150.00%
Total176100.00%2100.00%

EXPORT_SYMBOL_GPL(__platform_create_bundle); /** * __platform_register_drivers - register an array of platform drivers * @drivers: an array of drivers to register * @count: the number of drivers to register * @owner: module owning the drivers * * Registers platform drivers specified by an array. On failure to register a * driver, all previously registered drivers will be unregistered. Callers of * this API should use platform_unregister_drivers() to unregister drivers in * the reverse order. * * Returns: 0 on success or a negative error code on failure. */
int __platform_register_drivers(struct platform_driver * const *drivers, unsigned int count, struct module *owner) { unsigned int i; int err; for (i = 0; i < count; i++) { pr_debug("registering platform driver %ps\n", drivers[i]); err = __platform_driver_register(drivers[i], owner); if (err < 0) { pr_err("failed to register platform driver %ps: %d\n", drivers[i], err); goto error; } } return 0; error: while (i--) { pr_debug("unregistering platform driver %ps\n", drivers[i]); platform_driver_unregister(drivers[i]); } return err; }

Contributors

PersonTokensPropCommitsCommitProp
Thierry Reding121100.00%1100.00%
Total121100.00%1100.00%

EXPORT_SYMBOL_GPL(__platform_register_drivers); /** * platform_unregister_drivers - unregister an array of platform drivers * @drivers: an array of drivers to unregister * @count: the number of drivers to unregister * * Unegisters platform drivers specified by an array. This is typically used * to complement an earlier call to platform_register_drivers(). Drivers are * unregistered in the reverse order in which they were registered. */
void platform_unregister_drivers(struct platform_driver * const *drivers, unsigned int count) { while (count--) { pr_debug("unregistering platform driver %ps\n", drivers[count]); platform_driver_unregister(drivers[count]); } }

Contributors

PersonTokensPropCommitsCommitProp
Thierry Reding41100.00%1100.00%
Total41100.00%1100.00%

EXPORT_SYMBOL_GPL(platform_unregister_drivers); /* modalias support enables more hands-off userspace setup: * (a) environment variable lets new-style hotplug events work once system is * fully running: "modprobe $MODALIAS" * (b) sysfs attribute lets new-style coldplug recover from hotplug events * mishandled before system is fully running: "modprobe $(cat modalias)" */
static ssize_t modalias_show(struct device *dev, struct device_attribute *a, char *buf) { struct platform_device *pdev = to_platform_device(dev); int len; len = of_device_get_modalias(dev, buf, PAGE_SIZE -1); if (len != -ENODEV) return len; len = acpi_device_modalias(dev, buf, PAGE_SIZE -1); if (len != -ENODEV) return len; len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name); return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell5853.21%125.00%
Rui Zhang5045.87%250.00%
Kay Sievers10.92%125.00%
Total109100.00%4100.00%

static DEVICE_ATTR_RO(modalias);
static ssize_t driver_override_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct platform_device *pdev = to_platform_device(dev); char *driver_override, *old = pdev->driver_override, *cp; if (count > PATH_MAX) return -EINVAL; driver_override = kstrndup(buf, count, GFP_KERNEL); if (!driver_override) return -ENOMEM; cp = strchr(driver_override, '\n'); if (cp) *cp = '\0'; if (strlen(driver_override)) { pdev->driver_override = driver_override; } else { kfree(driver_override); pdev->driver_override = NULL; } kfree(old); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Kim Phillips133100.00%1100.00%
Total133100.00%1100.00%


static ssize_t driver_override_show(struct device *dev, struct device_attribute *attr, char *buf) { struct platform_device *pdev = to_platform_device(dev); return sprintf(buf, "%s\n", pdev->driver_override); }

Contributors

PersonTokensPropCommitsCommitProp
Kim Phillips42100.00%1100.00%
Total42100.00%1100.00%

static DEVICE_ATTR_RW(driver_override); static struct attribute *platform_dev_attrs[] = { &dev_attr_modalias.attr, &dev_attr_driver_override.attr, NULL, }; ATTRIBUTE_GROUPS(platform_dev);
static int platform_uevent(struct device *dev, struct kobj_uevent_env *env) { struct platform_device *pdev = to_platform_device(dev); int rc; /* Some devices have extra OF data and an OF-style MODALIAS */ rc = of_device_uevent_modalias(dev, env); if (rc != -ENODEV) return rc; rc = acpi_device_uevent_modalias(dev, env); if (rc != -ENODEV) return rc; add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX, pdev->name); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell3440.48%116.67%
Grant C. Likely2327.38%233.33%
Rui Zhang1922.62%116.67%
Kay Sievers55.95%116.67%
Eric Miao33.57%116.67%
Total84100.00%6100.00%


static const struct platform_device_id *platform_match_id( const struct platform_device_id *id, struct platform_device *pdev) { while (id->name[0]) { if (strcmp(pdev->name, id->name) == 0) { pdev->id_entry = id; return id; } id++; } return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Eric Miao6298.41%150.00%
Uwe Kleine-König11.59%150.00%
Total63100.00%2100.00%

/** * platform_match - bind platform device to platform driver. * @dev: device. * @drv: driver. * * Platform device IDs are assumed to be encoded like this: * "<name><instance>", where <name> is a short description of the type of * device, like "pci" or "floppy", and <instance> is the enumerated * instance of the device, like '0' or '42'. Driver IDs are simply * "<name>". So, extract the <name> from the platform_device structure, * and compare it against the name of the driver. Return whether they match * or not. */
static int platform_match(struct device *dev, struct device_driver *drv) { struct platform_device *pdev = to_platform_device(dev); struct platform_driver *pdrv = to_platform_driver(drv); /* When driver_override is set, only bind to the matching driver */ if (pdev->driver_override) return !strcmp(pdev->driver_override, drv->name); /* Attempt an OF style match first */ if (of_driver_match_device(dev, drv)) return 1; /* Then try ACPI style match */ if (acpi_driver_match_device(dev, drv)) return 1; /* Then try to match against the id table */ if (pdrv->id_table) return platform_match_id(pdrv->id_table, pdev) != NULL; /* fall-back to driver name match */ return (strcmp(pdev->name, drv->name) == 0); }

Contributors

PersonTokensPropCommitsCommitProp
Patrick Mochel3832.20%333.33%
Eric Miao3227.12%222.22%
Kim Phillips2016.95%111.11%
Grant C. Likely1411.86%111.11%
Mika Westerberg1311.02%111.11%
Kay Sievers10.85%111.11%
Total118100.00%9100.00%

#ifdef CONFIG_PM_SLEEP
static int platform_legacy_suspend(struct device *dev, pm_message_t mesg) { struct platform_driver *pdrv = to_platform_driver(dev->driver); struct platform_device *pdev = to_platform_device(dev); int ret = 0; if (dev->driver && pdrv->suspend) ret = pdrv->suspend(pdev, mesg); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick Mochel3046.15%120.00%
Magnus Damm2538.46%120.00%
David Brownell812.31%120.00%
Rafael J. Wysocki11.54%120.00%
Pavel Machek11.54%120.00%
Total65100.00%5100.00%


static int platform_legacy_resume(struct device *dev) { struct platform_driver *pdrv = to_platform_driver(dev->driver); struct platform_device *pdev = to_platform_device(dev); int ret = 0; if (dev->driver && pdrv->resume) ret = pdrv->resume(pdev); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Patrick Mochel3456.67%133.33%
Magnus Damm2541.67%133.33%
Rafael J. Wysocki11.67%133.33%
Total60100.00%3100.00%

#endif /* CONFIG_PM_SLEEP */ #ifdef CONFIG_SUSPEND
int platform_pm_suspend(struct device *dev) { struct device_driver *drv = dev->driver; int ret = 0; if (!drv) return 0; if (drv->pm) { if (drv->pm->suspend) ret = drv->pm->suspend(dev); } else { ret = platform_legacy_suspend(dev, PMSG_SUSPEND); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki7195.95%250.00%
Patrick Mochel22.70%125.00%
David Brownell11.35%125.00%
Total74100.00%4100.00%


int platform_pm_resume(struct device *dev) { struct device_driver *drv = dev->driver; int ret = 0; if (!drv) return 0; if (drv->pm) { if (drv->pm->resume) ret = drv->pm->resume(dev); } else { ret = platform_legacy_resume(dev); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki72100.00%2100.00%
Total72100.00%2100.00%

#endif /* CONFIG_SUSPEND */ #ifdef CONFIG_HIBERNATE_CALLBACKS
int platform_pm_freeze(struct device *dev) { struct device_driver *drv = dev->driver; int ret = 0; if (!drv) return 0; if (drv->pm) { if (drv->pm->freeze) ret = drv->pm->freeze(dev); } else { ret = platform_legacy_suspend(dev, PMSG_FREEZE); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki74100.00%1100.00%
Total74100.00%1100.00%


int platform_pm_thaw(struct device *dev) { struct device_driver *drv = dev->driver; int ret = 0; if (!drv) return 0; if (drv->pm) { if (drv->pm->thaw) ret = drv->pm->thaw(dev); } else { ret = platform_legacy_resume(dev); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki72100.00%2100.00%
Total72100.00%2100.00%


int platform_pm_poweroff(struct device *dev) { struct device_driver *drv = dev->driver; int ret = 0; if (!drv) return 0; if (drv->pm) { if (drv->pm->poweroff) ret = drv->pm->poweroff(dev); } else { ret = platform_legacy_suspend(dev, PMSG_HIBERNATE); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki74100.00%2100.00%
Total74100.00%2100.00%


int platform_pm_restore(struct device *dev) { struct device_driver *drv = dev->driver; int ret = 0; if (!drv) return 0; if (drv->pm) { if (drv->pm->restore) ret = drv->pm->restore(dev); } else { ret = platform_legacy_resume(dev); } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Rafael J. Wysocki72100.00%2100.00%
Total72100.00%2100.00%

#endif /* CONFIG_HIBERNATE_CALLBACKS */ static const struct dev_pm_ops platform_dev_pm_ops = { .runtime_suspend = pm_generic_runtime_suspend, .runtime_resume = pm_generic_runtime_resume, USE_PLATFORM_PM_SLEEP_OPS }; struct bus_type platform_bus_type = { .name = "platform", .dev_groups = platform_dev_groups, .match = platform_match, .uevent = platform_uevent, .pm = &platform_dev_pm_ops, }; EXPORT_SYMBOL_GPL(platform_bus_type);
int __init platform_bus_init(void) { int error; early_platform_cleanup(); error = device_register(&platform_bus); if (error) return error; error = bus_register(&platform_bus_type); if (error) device_unregister(&platform_bus); of_platform_register_reconfig_notifier(); return error; }

Contributors

PersonTokensPropCommitsCommitProp
Cornelia Huck2649.06%116.67%
Patrick Mochel2037.74%233.33%
Pantelis Antoniou35.66%116.67%
Magnus Damm35.66%116.67%
Andrew Morton11.89%116.67%
Total53100.00%6100.00%

#ifndef ARCH_HAS_DMA_GET_REQUIRED_MASK
u64 dma_get_required_mask(struct device *dev) { u32 low_totalram = ((max_pfn - 1) << PAGE_SHIFT); u32 high_totalram = ((max_pfn - 1) >> (32 - PAGE_SHIFT)); u64 mask; if (!high_totalram) { /* convert to mask just covering totalram */ low_totalram = (1 << (fls(low_totalram) - 1)); low_totalram += low_totalram - 1; mask = low_totalram; } else { high_totalram = (1 << (fls(high_totalram) - 1)); high_totalram += high_totalram - 1; mask = (((u64)high_totalram) << 32) + 0xffffffff; } return mask; }

Contributors

PersonTokensPropCommitsCommitProp
James Bottomley118100.00%1100.00%
Total118100.00%1100.00%

EXPORT_SYMBOL_GPL(dma_get_required_mask); #endif static __initdata LIST_HEAD(early_platform_driver_list); static __initdata LIST_HEAD(early_platform_device_list); /** * early_platform_driver_register - register early platform driver * @epdrv: early_platform driver structure * @buf: string passed from early_param() * * Helper function for early_platform_init() / early_platform_init_buffer() */
int __init early_platform_driver_register(struct early_platform_driver *epdrv, char *buf) { char *tmp; int n; /* Simply add the driver to the end of the global list. * Drivers will by default be put on the list in compiled-in order. */ if (!epdrv->list.next) { INIT_LIST_HEAD(&epdrv->list); list_add_tail(&epdrv->list, &early_platform_driver_list); } /* If the user has specified device then make sure the driver * gets prioritized. The driver of the last device specified on * command line will be put first on the list. */ n = strlen(epdrv->pdrv->driver.name); if (buf && !strncmp(buf, epdrv->pdrv->driver.name, n)) { list_move(&epdrv->list, &early_platform_driver_list); /* Allow passing parameters after device name */ if (buf[n] == '\0' || buf[n] == ',') epdrv->requested_id = -1; else { epdrv->requested_id = simple_strtoul(&buf[n + 1], &tmp, 10); if (buf[n] != '.' || (tmp == &buf[n + 1])) { epdrv->requested_id = EARLY_PLATFORM_ID_ERROR; n = 0; } else n += strcspn(&buf[n + 1], ",") + 1; } if (buf[n] == ',') n++; if (epdrv->bufsize) { memcpy(epdrv->buffer, &buf[n], min_t(int, epdrv->bufsize, strlen(&buf[n]) + 1)); epdrv->buffer[epdrv->bufsize - 1] = '\0'; } } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm267100.00%2100.00%
Total267100.00%2100.00%

/** * early_platform_add_devices - adds a number of early platform devices * @devs: array of early platform devices to add * @num: number of early platform devices in array * * Used by early architecture code to register early platform devices and * their platform data. */
void __init early_platform_add_devices(struct platform_device **devs, int num) { struct device *dev; int i; /* simply add the devices to list */ for (i = 0; i < num; i++) { dev = &devs[i]->dev; if (!dev->devres_head.next) { pm_runtime_early_init(dev); INIT_LIST_HEAD(&dev->devres_head); list_add_tail(&dev->devres_head, &early_platform_device_list); } } }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm7994.05%150.00%
Rafael J. Wysocki55.95%150.00%
Total84100.00%2100.00%

/** * early_platform_driver_register_all - register early platform drivers * @class_str: string to identify early platform driver class * * Used by architecture code to register all early platform drivers * for a certain class. If omitted then only early platform drivers * with matching kernel command line class parameters will be registered. */
void __init early_platform_driver_register_all(char *class_str) { /* The "class_str" parameter may or may not be present on the kernel * command line. If it is present then there may be more than one * matching parameter. * * Since we register our early platform drivers using early_param() * we need to make sure that they also get registered in the case * when the parameter is missing from the kernel command line. * * We use parse_early_options() to make sure the early_param() gets * called at least once. The early_param() may be called more than * once since the name of the preferred device may be specified on * the kernel command line. early_platform_driver_register() handles * this case for us. */ parse_early_options(class_str); }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm16100.00%1100.00%
Total16100.00%1100.00%

/** * early_platform_match - find early platform device matching driver * @epdrv: early platform driver structure * @id: id to match against */
static struct platform_device * __init early_platform_match(struct early_platform_driver *epdrv, int id) { struct platform_device *pd; list_for_each_entry(pd, &early_platform_device_list, dev.devres_head) if (platform_match(&pd->dev, &epdrv->pdrv->driver)) if (pd->id == id) return pd; return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm4472.13%150.00%
Hanjun Guo1727.87%150.00%
Total61100.00%2100.00%

/** * early_platform_left - check if early platform driver has matching devices * @epdrv: early platform driver structure * @id: return true if id or above exists */
static int __init early_platform_left(struct early_platform_driver *epdrv, int id) { struct platform_device *pd; list_for_each_entry(pd, &early_platform_device_list, dev.devres_head) if (platform_match(&pd->dev, &epdrv->pdrv->driver)) if (pd->id >= id) return 1; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm5796.61%150.00%
Hanjun Guo23.39%150.00%
Total59100.00%2100.00%

/** * early_platform_driver_probe_id - probe drivers matching class_str and id * @class_str: string to identify early platform driver class * @id: id to match against * @nr_probe: number of platform devices to successfully probe before exiting */
static int __init early_platform_driver_probe_id(char *class_str, int id, int nr_probe) { struct early_platform_driver *epdrv; struct platform_device *match; int match_id; int n = 0; int left = 0; list_for_each_entry(epdrv, &early_platform_driver_list, list) { /* only use drivers matching our class_str */ if (strcmp(class_str, epdrv->class_str)) continue; if (id == -2) { match_id = epdrv->requested_id; left = 1; } else { match_id = id; left += early_platform_left(epdrv, id); /* skip requested id */ switch (epdrv->requested_id) { case EARLY_PLATFORM_ID_ERROR: case EARLY_PLATFORM_ID_UNSET: break; default: if (epdrv->requested_id == id) match_id = EARLY_PLATFORM_ID_UNSET; } } switch (match_id) { case EARLY_PLATFORM_ID_ERROR: pr_warn("%s: unable to parse %s parameter\n", class_str, epdrv->pdrv->driver.name); /* fall-through */ case EARLY_PLATFORM_ID_UNSET: match = NULL; break; default: match = early_platform_match(epdrv, match_id); } if (match) { /* * Set up a sensible init_name to enable * dev_name() and others to be used before the * rest of the driver core is initialized. */ if (!match->dev.init_name && slab_is_available()) { if (match->id != -1) match->dev.init_name = kasprintf(GFP_KERNEL, "%s.%d", match->name, match->id); else match->dev.init_name = kasprintf(GFP_KERNEL, "%s", match->name); if (!match->dev.init_name) return -ENOMEM; } if (epdrv->pdrv->probe(match)) pr_warn("%s: unable to probe %s early.\n", class_str, match->name); else n++; } if (n >= nr_probe) break; } if (left) return n; else return -ENODEV; }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm21973.74%120.00%
Paul Mundt7625.59%360.00%
Fabio Porcedda20.67%120.00%
Total297100.00%5100.00%

/** * early_platform_driver_probe - probe a class of registered drivers * @class_str: string to identify early platform driver class * @nr_probe: number of platform devices to successfully probe before exiting * @user_only: only probe user specified early platform devices * * Used by architecture code to probe registered early platform drivers * within a certain class. For probe to happen a registered early platform * device matching a registered early platform driver is needed. */
int __init early_platform_driver_probe(char *class_str, int nr_probe, int user_only) { int k, n, i; n = 0; for (i = -2; n < nr_probe; i++) { k = early_platform_driver_probe_id(class_str, i, nr_probe - n); if (k < 0) break; n += k; if (user_only) break; } return n; }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm75100.00%1100.00%
Total75100.00%1100.00%

/** * early_platform_cleanup - clean up early platform code */
void __init early_platform_cleanup(void) { struct platform_device *pd, *pd2; /* clean up the devres list used to chain devices */ list_for_each_entry_safe(pd, pd2, &early_platform_device_list, dev.devres_head) { list_del(&pd->dev.devres_head); memset(&pd->dev.devres_head, 0, sizeof(pd->dev.devres_head)); } }

Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm60100.00%1100.00%
Total60100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Magnus Damm92017.61%64.55%
Russell King79115.14%64.55%
Rafael J. Wysocki55510.63%107.58%
Dmitry Torokhov3586.85%107.58%
David Brownell2494.77%43.03%
Patrick Mochel2384.56%64.55%
Kim Phillips2184.17%10.76%
Uwe Kleine-König1853.54%107.58%
Greg Kroah-Hartman1803.45%86.06%
Thierry Reding1743.33%10.76%
Kumar Gala1372.62%21.52%
James Bottomley1332.55%10.76%
Eric Miao971.86%21.52%
Jean Delvare861.65%32.27%
Paul Mundt761.46%32.27%
Mika Westerberg701.34%21.52%
Rui Zhang691.32%21.52%
Guenter Roeck621.19%21.52%
Grant C. Likely561.07%53.79%
Stephen Boyd541.03%10.76%
Agustin Vega-Frias510.98%10.76%
Andreas Larsson350.67%10.76%
Dmitry Baryshkov350.67%10.76%
Johan Hovold320.61%10.76%
Rob Herring310.59%10.76%
Grygorii Strashko280.54%10.76%
Linus Walleij270.52%21.52%
Cornelia Huck260.50%10.76%
Kay Sievers250.48%32.27%
Sylwester Nawrocki230.44%10.76%
Wolfram Sang230.44%32.27%
Hanjun Guo190.36%10.76%
Ulf Hansson170.33%21.52%
Libo Chen150.29%10.76%
Andrew Morton130.25%32.27%
Martin Wilck130.25%10.76%
Anton Vorontsov120.23%10.76%
Peter Ujfalusi110.21%10.76%
Patrick Pannuto100.19%10.76%
Samuel Ortiz90.17%10.76%
Jerome Marchand80.15%10.76%
Heikki Krogerus70.13%10.76%
Yann Droneaud50.10%10.76%
Fabio Porcedda50.10%10.76%
Ben Hutchings50.10%10.76%
David Vrabel40.08%10.76%
Michael Hennerich40.08%10.76%
Ben Dooks30.06%10.76%
Tim Schmielau30.06%10.76%
Ricardo Ribalda Delgado30.06%21.52%
Chen Yu30.06%10.76%
Pantelis Antoniou30.06%10.76%
Sergei Shtylyov20.04%10.76%
Randy Dunlap10.02%10.76%
Geert Uytterhoeven10.02%10.76%
Adrian Bunk10.02%10.76%
Pavel Machek10.02%10.76%
Scott Wood10.02%10.76%
Total5223100.00%132100.00%
Directory: drivers/base
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.