Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at ed78aeebef05212ef7dca93bd931e4eff67c113f 396 lines 14 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-only */ 2/* 3 * platform_device.h - generic, centralized driver model 4 * 5 * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org> 6 * 7 * See Documentation/driver-api/driver-model/ for more information. 8 */ 9 10#ifndef _PLATFORM_DEVICE_H_ 11#define _PLATFORM_DEVICE_H_ 12 13#include <linux/device.h> 14 15#define PLATFORM_DEVID_NONE (-1) 16#define PLATFORM_DEVID_AUTO (-2) 17 18struct irq_affinity; 19struct mfd_cell; 20struct property_entry; 21struct platform_device_id; 22 23struct platform_device { 24 const char *name; 25 int id; 26 bool id_auto; 27 struct device dev; 28 u64 platform_dma_mask; 29 struct device_dma_parameters dma_parms; 30 u32 num_resources; 31 struct resource *resource; 32 33 const struct platform_device_id *id_entry; 34 35 /* MFD cell pointer */ 36 struct mfd_cell *mfd_cell; 37 38 /* arch specific additions */ 39 struct pdev_archdata archdata; 40}; 41 42#define platform_get_device_id(pdev) ((pdev)->id_entry) 43 44#define dev_is_platform(dev) ((dev)->bus == &platform_bus_type) 45#define to_platform_device(x) container_of((x), struct platform_device, dev) 46 47extern int platform_device_register(struct platform_device *); 48extern void platform_device_unregister(struct platform_device *); 49 50extern const struct bus_type platform_bus_type; 51extern struct device platform_bus; 52 53extern struct resource *platform_get_resource(struct platform_device *, 54 unsigned int, unsigned int); 55extern struct resource *platform_get_mem_or_io(struct platform_device *, 56 unsigned int); 57 58extern struct device * 59platform_find_device_by_driver(struct device *start, 60 const struct device_driver *drv); 61 62#ifdef CONFIG_HAS_IOMEM 63extern void __iomem * 64devm_platform_get_and_ioremap_resource(struct platform_device *pdev, 65 unsigned int index, struct resource **res); 66extern void __iomem * 67devm_platform_ioremap_resource(struct platform_device *pdev, 68 unsigned int index); 69extern void __iomem * 70devm_platform_ioremap_resource_byname(struct platform_device *pdev, 71 const char *name); 72#else 73 74static inline void __iomem * 75devm_platform_get_and_ioremap_resource(struct platform_device *pdev, 76 unsigned int index, struct resource **res) 77{ 78 return IOMEM_ERR_PTR(-EINVAL); 79} 80 81 82static inline void __iomem * 83devm_platform_ioremap_resource(struct platform_device *pdev, 84 unsigned int index) 85{ 86 return IOMEM_ERR_PTR(-EINVAL); 87} 88 89static inline void __iomem * 90devm_platform_ioremap_resource_byname(struct platform_device *pdev, 91 const char *name) 92{ 93 return IOMEM_ERR_PTR(-EINVAL); 94} 95 96#endif 97 98extern int platform_get_irq(struct platform_device *, unsigned int); 99extern int platform_get_irq_optional(struct platform_device *, unsigned int); 100extern int platform_get_irq_affinity(struct platform_device *, unsigned int, 101 const struct cpumask **); 102extern int platform_irq_count(struct platform_device *); 103extern int devm_platform_get_irqs_affinity(struct platform_device *dev, 104 struct irq_affinity *affd, 105 unsigned int minvec, 106 unsigned int maxvec, 107 int **irqs); 108extern struct resource *platform_get_resource_byname(struct platform_device *, 109 unsigned int, 110 const char *); 111extern int platform_get_irq_byname(struct platform_device *, const char *); 112extern int platform_get_irq_byname_optional(struct platform_device *dev, 113 const char *name); 114extern int platform_add_devices(struct platform_device **, int); 115 116struct platform_device_info { 117 struct device *parent; 118 struct fwnode_handle *fwnode; 119 bool of_node_reused; 120 121 const char *name; 122 int id; 123 124 const struct resource *res; 125 unsigned int num_res; 126 127 const void *data; 128 size_t size_data; 129 u64 dma_mask; 130 131 const struct property_entry *properties; 132}; 133extern struct platform_device *platform_device_register_full( 134 const struct platform_device_info *pdevinfo); 135 136/** 137 * platform_device_register_resndata - add a platform-level device with 138 * resources and platform-specific data 139 * 140 * @parent: parent device for the device we're adding 141 * @name: base name of the device we're adding 142 * @id: instance id 143 * @res: set of resources that needs to be allocated for the device 144 * @num: number of resources 145 * @data: platform specific data for this platform device 146 * @size: size of platform specific data 147 * 148 * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 149 */ 150static inline struct platform_device *platform_device_register_resndata( 151 struct device *parent, const char *name, int id, 152 const struct resource *res, unsigned int num, 153 const void *data, size_t size) { 154 155 struct platform_device_info pdevinfo = { 156 .parent = parent, 157 .name = name, 158 .id = id, 159 .res = res, 160 .num_res = num, 161 .data = data, 162 .size_data = size, 163 .dma_mask = 0, 164 }; 165 166 return platform_device_register_full(&pdevinfo); 167} 168 169/** 170 * platform_device_register_simple - add a platform-level device and its resources 171 * @name: base name of the device we're adding 172 * @id: instance id 173 * @res: set of resources that needs to be allocated for the device 174 * @num: number of resources 175 * 176 * This function creates a simple platform device that requires minimal 177 * resource and memory management. Canned release function freeing memory 178 * allocated for the device allows drivers using such devices to be 179 * unloaded without waiting for the last reference to the device to be 180 * dropped. 181 * 182 * This interface is primarily intended for use with legacy drivers which 183 * probe hardware directly. Because such drivers create sysfs device nodes 184 * themselves, rather than letting system infrastructure handle such device 185 * enumeration tasks, they don't fully conform to the Linux driver model. 186 * In particular, when such drivers are built as modules, they can't be 187 * "hotplugged". 188 * 189 * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 190 */ 191static inline struct platform_device *platform_device_register_simple( 192 const char *name, int id, 193 const struct resource *res, unsigned int num) 194{ 195 return platform_device_register_resndata(NULL, name, id, 196 res, num, NULL, 0); 197} 198 199/** 200 * platform_device_register_data - add a platform-level device with platform-specific data 201 * @parent: parent device for the device we're adding 202 * @name: base name of the device we're adding 203 * @id: instance id 204 * @data: platform specific data for this platform device 205 * @size: size of platform specific data 206 * 207 * This function creates a simple platform device that requires minimal 208 * resource and memory management. Canned release function freeing memory 209 * allocated for the device allows drivers using such devices to be 210 * unloaded without waiting for the last reference to the device to be 211 * dropped. 212 * 213 * Returns &struct platform_device pointer on success, or ERR_PTR() on error. 214 */ 215static inline struct platform_device *platform_device_register_data( 216 struct device *parent, const char *name, int id, 217 const void *data, size_t size) 218{ 219 return platform_device_register_resndata(parent, name, id, 220 NULL, 0, data, size); 221} 222 223extern struct platform_device *platform_device_alloc(const char *name, int id); 224extern int platform_device_add_resources(struct platform_device *pdev, 225 const struct resource *res, 226 unsigned int num); 227extern int platform_device_add_data(struct platform_device *pdev, 228 const void *data, size_t size); 229extern int platform_device_add(struct platform_device *pdev); 230extern void platform_device_del(struct platform_device *pdev); 231extern void platform_device_put(struct platform_device *pdev); 232DEFINE_FREE(platform_device_put, struct platform_device *, if (_T) platform_device_put(_T)) 233 234struct platform_driver { 235 int (*probe)(struct platform_device *); 236 void (*remove)(struct platform_device *); 237 void (*shutdown)(struct platform_device *); 238 int (*suspend)(struct platform_device *, pm_message_t state); 239 int (*resume)(struct platform_device *); 240 struct device_driver driver; 241 const struct platform_device_id *id_table; 242 bool prevent_deferred_probe; 243 /* 244 * For most device drivers, no need to care about this flag as long as 245 * all DMAs are handled through the kernel DMA API. For some special 246 * ones, for example VFIO drivers, they know how to manage the DMA 247 * themselves and set this flag so that the IOMMU layer will allow them 248 * to setup and manage their own I/O address space. 249 */ 250 bool driver_managed_dma; 251}; 252 253#define to_platform_driver(drv) (container_of((drv), struct platform_driver, \ 254 driver)) 255 256/* 257 * use a macro to avoid include chaining to get THIS_MODULE 258 */ 259#define platform_driver_register(drv) \ 260 __platform_driver_register(drv, THIS_MODULE) 261extern int __platform_driver_register(struct platform_driver *, 262 struct module *); 263extern void platform_driver_unregister(struct platform_driver *); 264 265/* non-hotpluggable platform devices may use this so that probe() and 266 * its support may live in __init sections, conserving runtime memory. 267 */ 268#define platform_driver_probe(drv, probe) \ 269 __platform_driver_probe(drv, probe, THIS_MODULE) 270extern int __platform_driver_probe(struct platform_driver *driver, 271 int (*probe)(struct platform_device *), struct module *module); 272 273static inline void *platform_get_drvdata(const struct platform_device *pdev) 274{ 275 return dev_get_drvdata(&pdev->dev); 276} 277 278static inline void platform_set_drvdata(struct platform_device *pdev, 279 void *data) 280{ 281 dev_set_drvdata(&pdev->dev, data); 282} 283 284/* module_platform_driver() - Helper macro for drivers that don't do 285 * anything special in module init/exit. This eliminates a lot of 286 * boilerplate. Each module may only use this macro once, and 287 * calling it replaces module_init() and module_exit() 288 */ 289#define module_platform_driver(__platform_driver) \ 290 module_driver(__platform_driver, platform_driver_register, \ 291 platform_driver_unregister) 292 293/* builtin_platform_driver() - Helper macro for builtin drivers that 294 * don't do anything special in driver init. This eliminates some 295 * boilerplate. Each driver may only use this macro once, and 296 * calling it replaces device_initcall(). Note this is meant to be 297 * a parallel of module_platform_driver() above, but w/o _exit stuff. 298 */ 299#define builtin_platform_driver(__platform_driver) \ 300 builtin_driver(__platform_driver, platform_driver_register) 301 302/* module_platform_driver_probe() - Helper macro for drivers that don't do 303 * anything special in module init/exit. This eliminates a lot of 304 * boilerplate. Each module may only use this macro once, and 305 * calling it replaces module_init() and module_exit() 306 */ 307#define module_platform_driver_probe(__platform_driver, __platform_probe) \ 308static int __init __platform_driver##_init(void) \ 309{ \ 310 return platform_driver_probe(&(__platform_driver), \ 311 __platform_probe); \ 312} \ 313module_init(__platform_driver##_init); \ 314static void __exit __platform_driver##_exit(void) \ 315{ \ 316 platform_driver_unregister(&(__platform_driver)); \ 317} \ 318module_exit(__platform_driver##_exit); 319 320/* builtin_platform_driver_probe() - Helper macro for drivers that don't do 321 * anything special in device init. This eliminates some boilerplate. Each 322 * driver may only use this macro once, and using it replaces device_initcall. 323 * This is meant to be a parallel of module_platform_driver_probe above, but 324 * without the __exit parts. 325 */ 326#define builtin_platform_driver_probe(__platform_driver, __platform_probe) \ 327static int __init __platform_driver##_init(void) \ 328{ \ 329 return platform_driver_probe(&(__platform_driver), \ 330 __platform_probe); \ 331} \ 332device_initcall(__platform_driver##_init); \ 333 334#define platform_create_bundle(driver, probe, res, n_res, data, size) \ 335 __platform_create_bundle(driver, probe, res, n_res, data, size, THIS_MODULE) 336extern struct platform_device *__platform_create_bundle( 337 struct platform_driver *driver, int (*probe)(struct platform_device *), 338 struct resource *res, unsigned int n_res, 339 const void *data, size_t size, struct module *module); 340 341int __platform_register_drivers(struct platform_driver * const *drivers, 342 unsigned int count, struct module *owner); 343void platform_unregister_drivers(struct platform_driver * const *drivers, 344 unsigned int count); 345 346#define platform_register_drivers(drivers, count) \ 347 __platform_register_drivers(drivers, count, THIS_MODULE) 348 349#ifdef CONFIG_SUSPEND 350extern int platform_pm_suspend(struct device *dev); 351extern int platform_pm_resume(struct device *dev); 352#else 353#define platform_pm_suspend NULL 354#define platform_pm_resume NULL 355#endif 356 357#ifdef CONFIG_HIBERNATE_CALLBACKS 358extern int platform_pm_freeze(struct device *dev); 359extern int platform_pm_thaw(struct device *dev); 360extern int platform_pm_poweroff(struct device *dev); 361extern int platform_pm_restore(struct device *dev); 362#else 363#define platform_pm_freeze NULL 364#define platform_pm_thaw NULL 365#define platform_pm_poweroff NULL 366#define platform_pm_restore NULL 367#endif 368 369#ifdef CONFIG_PM_SLEEP 370#define USE_PLATFORM_PM_SLEEP_OPS \ 371 .suspend = platform_pm_suspend, \ 372 .resume = platform_pm_resume, \ 373 .freeze = platform_pm_freeze, \ 374 .thaw = platform_pm_thaw, \ 375 .poweroff = platform_pm_poweroff, \ 376 .restore = platform_pm_restore, 377#else 378#define USE_PLATFORM_PM_SLEEP_OPS 379#endif 380 381#ifndef CONFIG_SUPERH 382/* 383 * REVISIT: This stub is needed for all non-SuperH users of early platform 384 * drivers. It should go away once we introduce the new platform_device-based 385 * early driver framework. 386 */ 387static inline int is_sh_early_platform_device(struct platform_device *pdev) 388{ 389 return 0; 390} 391#endif /* CONFIG_SUPERH */ 392 393/* For now only SuperH uses it */ 394void early_platform_cleanup(void); 395 396#endif /* _PLATFORM_DEVICE_H_ */