LCOV - code coverage report
Current view: top level - include/linux - platform_device.h (source / functions) Hit Total Coverage
Test: combined.info Lines: 7 11 63.6 %
Date: 2022-04-01 14:17:54 Functions: 2 2 100.0 %
Branches: 0 2 0.0 %

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

Generated by: LCOV version 1.14