/* * 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/idr.h>#include<linux/acpi.h>#include<linux/clk/clk-conf.h>#include<linux/limits.h>#include"base.h"#include"power/power.h"/* For automatically allocated device IDs */staticDEFINE_IDA(platform_devid_ida);structdeviceplatform_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__weakarch_setup_pdev_archdata(structplatform_device*pdev){}/** * platform_get_resource - get a resource for a device * @dev: platform device * @type: resource type * @num: resource index */structresource*platform_get_resource(structplatform_device*dev,unsignedinttype,unsignedintnum){inti;for(i=0;i<dev->num_resources;i++){structresource*r=&dev->resource[i];if(type==resource_type(r)&&num--==0)returnr;}returnNULL;}EXPORT_SYMBOL_GPL(platform_get_resource);/** * platform_get_irq - get an IRQ for a device * @dev: platform device * @num: IRQ number index */intplatform_get_irq(structplatform_device*dev,unsignedintnum){#ifdef CONFIG_SPARC/* sparc does not have irqs represented as IORESOURCE_IRQ resources */if(!dev||num>=dev->archdata.num_irqs)return-ENXIO;returndev->archdata.irqs[num];#elsestructresource*r;if(IS_ENABLED(CONFIG_OF_IRQ)&&dev->dev.of_node){intret;ret=of_irq_get(dev->dev.of_node,num);if(ret>=0||ret==-EPROBE_DEFER