⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 platform.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/** *	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);}EXPORT_SYMBOL_GPL(platform_device_unregister);/** *	platform_device_register_simple *	@name:  base name of the device we're adding *	@id:    instance id *	@res:   set of resources that needs to be allocated for the device *	@num:	number of resources * *	This function creates a simple platform device that requires minimal *	resource and memory management. Canned release function freeing *	memory allocated for the device allows drivers using such devices *	to be unloaded without waiting for the last reference to the device *	to be dropped. * *	This interface is primarily intended for use with legacy drivers *	which probe hardware directly.  Because such drivers create sysfs *	device nodes themselves, rather than letting system infrastructure *	handle such device enumeration tasks, they don't fully conform to *	the Linux driver model.  In particular, when such drivers are built *	as modules, they can't be "hotplugged". */struct platform_device *platform_device_register_simple(char *name, int id,							struct resource *res, unsigned int num){	struct platform_device *pdev;	int retval;	pdev = platform_device_alloc(name, id);	if (!pdev) {		retval = -ENOMEM;		goto error;	}	if (num) {		retval = platform_device_add_resources(pdev, res, num);		if (retval)			goto error;	}	retval = platform_device_add(pdev);	if (retval)		goto error;	return pdev;error:	platform_device_put(pdev);	return ERR_PTR(retval);}EXPORT_SYMBOL_GPL(platform_device_register_simple);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);	return drv->probe(dev);}static int platform_drv_probe_fail(struct device *_dev){	return -ENXIO;}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);	return drv->remove(dev);}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);	drv->shutdown(dev);}static int platform_drv_suspend(struct device *_dev, pm_message_t state){	struct platform_driver *drv = to_platform_driver(_dev->driver);	struct platform_device *dev = to_platform_device(_dev);	return drv->suspend(dev, state);}static int platform_drv_resume(struct device *_dev){	struct platform_driver *drv = to_platform_driver(_dev->driver);	struct platform_device *dev = to_platform_device(_dev);	return drv->resume(dev);}/** *	platform_driver_register *	@drv: platform driver structure */int platform_driver_register(struct platform_driver *drv){	drv->driver.bus = &platform_bus_type;	if (drv->probe)		drv->driver.probe = platform_drv_probe;	if (drv->remove)		drv->driver.remove = platform_drv_remove;	if (drv->shutdown)		drv->driver.shutdown = platform_drv_shutdown;	if (drv->suspend)		drv->driver.suspend = platform_drv_suspend;	if (drv->resume)		drv->driver.resume = platform_drv_resume;	return driver_register(&drv->driver);}EXPORT_SYMBOL_GPL(platform_driver_register);/** *	platform_driver_unregister *	@drv: platform driver structure */void platform_driver_unregister(struct platform_driver *drv){	driver_unregister(&drv->driver);}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 * * 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. * * 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 *)){	int retval, code;	/* temporary section violation during probe() */	drv->probe = probe;	retval = code = platform_driver_register(drv);	/* 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(&platform_bus_type.klist_drivers.k_lock);	drv->probe = NULL;	if (code == 0 && list_empty(&drv->driver.klist_devices.k_list))		retval = -ENODEV;	drv->driver.probe = platform_drv_probe_fail;	spin_unlock(&platform_bus_type.klist_drivers.k_lock);	if (code != retval)		platform_driver_unregister(drv);	return retval;}EXPORT_SYMBOL_GPL(platform_driver_probe);/* 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_tmodalias_show(struct device *dev, struct device_attribute *a, char *buf){	struct platform_device	*pdev = to_platform_device(dev);	int len = snprintf(buf, PAGE_SIZE, "platform:%s\n", pdev->name);	return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len;}static struct device_attribute platform_dev_attrs[] = {	__ATTR_RO(modalias),	__ATTR_NULL,};static int platform_uevent(struct device *dev, struct kobj_uevent_env *env){	struct platform_device	*pdev = to_platform_device(dev);	add_uevent_var(env, "MODALIAS=platform:%s", pdev->name);	return 0;}/** *	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 = container_of(dev, struct platform_device, dev);	return (strncmp(pdev->name, drv->name, BUS_ID_SIZE) == 0);}static int platform_suspend(struct device *dev, pm_message_t mesg){	int ret = 0;	if (dev->driver && dev->driver->suspend)		ret = dev->driver->suspend(dev, mesg);	return ret;}static int platform_suspend_late(struct device *dev, pm_message_t mesg){	struct platform_driver *drv = to_platform_driver(dev->driver);	struct platform_device *pdev = container_of(dev, struct platform_device, dev);	int ret = 0;	if (dev->driver && drv->suspend_late)		ret = drv->suspend_late(pdev, mesg);	return ret;}static int platform_resume_early(struct device *dev){	struct platform_driver *drv = to_platform_driver(dev->driver);	struct platform_device *pdev = container_of(dev, struct platform_device, dev);	int ret = 0;	if (dev->driver && drv->resume_early)		ret = drv->resume_early(pdev);	return ret;}static int platform_resume(struct device * dev){	int ret = 0;	if (dev->driver && dev->driver->resume)		ret = dev->driver->resume(dev);	return ret;}struct bus_type platform_bus_type = {	.name		= "platform",	.dev_attrs	= platform_dev_attrs,	.match		= platform_match,	.uevent		= platform_uevent,	.suspend	= platform_suspend,	.suspend_late	= platform_suspend_late,	.resume_early	= platform_resume_early,	.resume		= platform_resume,};EXPORT_SYMBOL_GPL(platform_bus_type);int __init platform_bus_init(void){	int error;	error = device_register(&platform_bus);	if (error)		return error;	error =  bus_register(&platform_bus_type);	if (error)		device_unregister(&platform_bus);	return error;}#ifndef ARCH_HAS_DMA_GET_REQUIRED_MASKu64 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 & *dev->dma_mask;}EXPORT_SYMBOL_GPL(dma_get_required_mask);#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -