0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _PLATFORM_DEVICE_H_
0011 #define _PLATFORM_DEVICE_H_
0012
0013 #include <linux/device.h>
0014
0015 #define PLATFORM_DEVID_NONE (-1)
0016 #define PLATFORM_DEVID_AUTO (-2)
0017
0018 struct irq_affinity;
0019 struct mfd_cell;
0020 struct property_entry;
0021 struct platform_device_id;
0022
0023 struct platform_device {
0024 const char *name;
0025 int id;
0026 bool id_auto;
0027 struct device dev;
0028 u64 platform_dma_mask;
0029 struct device_dma_parameters dma_parms;
0030 u32 num_resources;
0031 struct resource *resource;
0032
0033 const struct platform_device_id *id_entry;
0034
0035
0036
0037
0038 const char *driver_override;
0039
0040
0041 struct mfd_cell *mfd_cell;
0042
0043
0044 struct pdev_archdata archdata;
0045 };
0046
0047 #define platform_get_device_id(pdev) ((pdev)->id_entry)
0048
0049 #define dev_is_platform(dev) ((dev)->bus == &platform_bus_type)
0050 #define to_platform_device(x) container_of((x), struct platform_device, dev)
0051
0052 extern int platform_device_register(struct platform_device *);
0053 extern void platform_device_unregister(struct platform_device *);
0054
0055 extern struct bus_type platform_bus_type;
0056 extern struct device platform_bus;
0057
0058 extern struct resource *platform_get_resource(struct platform_device *,
0059 unsigned int, unsigned int);
0060 extern struct resource *platform_get_mem_or_io(struct platform_device *,
0061 unsigned int);
0062
0063 extern struct device *
0064 platform_find_device_by_driver(struct device *start,
0065 const struct device_driver *drv);
0066 extern void __iomem *
0067 devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
0068 unsigned int index, struct resource **res);
0069 extern void __iomem *
0070 devm_platform_ioremap_resource(struct platform_device *pdev,
0071 unsigned int index);
0072 extern void __iomem *
0073 devm_platform_ioremap_resource_byname(struct platform_device *pdev,
0074 const char *name);
0075 extern int platform_get_irq(struct platform_device *, unsigned int);
0076 extern int platform_get_irq_optional(struct platform_device *, unsigned int);
0077 extern int platform_irq_count(struct platform_device *);
0078 extern int devm_platform_get_irqs_affinity(struct platform_device *dev,
0079 struct irq_affinity *affd,
0080 unsigned int minvec,
0081 unsigned int maxvec,
0082 int **irqs);
0083 extern struct resource *platform_get_resource_byname(struct platform_device *,
0084 unsigned int,
0085 const char *);
0086 extern int platform_get_irq_byname(struct platform_device *, const char *);
0087 extern int platform_get_irq_byname_optional(struct platform_device *dev,
0088 const char *name);
0089 extern int platform_add_devices(struct platform_device **, int);
0090
0091 struct platform_device_info {
0092 struct device *parent;
0093 struct fwnode_handle *fwnode;
0094 bool of_node_reused;
0095
0096 const char *name;
0097 int id;
0098
0099 const struct resource *res;
0100 unsigned int num_res;
0101
0102 const void *data;
0103 size_t size_data;
0104 u64 dma_mask;
0105
0106 const struct property_entry *properties;
0107 };
0108 extern struct platform_device *platform_device_register_full(
0109 const struct platform_device_info *pdevinfo);
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125 static inline struct platform_device *platform_device_register_resndata(
0126 struct device *parent, const char *name, int id,
0127 const struct resource *res, unsigned int num,
0128 const void *data, size_t size) {
0129
0130 struct platform_device_info pdevinfo = {
0131 .parent = parent,
0132 .name = name,
0133 .id = id,
0134 .res = res,
0135 .num_res = num,
0136 .data = data,
0137 .size_data = size,
0138 .dma_mask = 0,
0139 };
0140
0141 return platform_device_register_full(&pdevinfo);
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166 static inline struct platform_device *platform_device_register_simple(
0167 const char *name, int id,
0168 const struct resource *res, unsigned int num)
0169 {
0170 return platform_device_register_resndata(NULL, name, id,
0171 res, num, NULL, 0);
0172 }
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190 static inline struct platform_device *platform_device_register_data(
0191 struct device *parent, const char *name, int id,
0192 const void *data, size_t size)
0193 {
0194 return platform_device_register_resndata(parent, name, id,
0195 NULL, 0, data, size);
0196 }
0197
0198 extern struct platform_device *platform_device_alloc(const char *name, int id);
0199 extern int platform_device_add_resources(struct platform_device *pdev,
0200 const struct resource *res,
0201 unsigned int num);
0202 extern int platform_device_add_data(struct platform_device *pdev,
0203 const void *data, size_t size);
0204 extern int platform_device_add(struct platform_device *pdev);
0205 extern void platform_device_del(struct platform_device *pdev);
0206 extern void platform_device_put(struct platform_device *pdev);
0207
0208 struct platform_driver {
0209 int (*probe)(struct platform_device *);
0210 int (*remove)(struct platform_device *);
0211 void (*shutdown)(struct platform_device *);
0212 int (*suspend)(struct platform_device *, pm_message_t state);
0213 int (*resume)(struct platform_device *);
0214 struct device_driver driver;
0215 const struct platform_device_id *id_table;
0216 bool prevent_deferred_probe;
0217
0218
0219
0220
0221
0222
0223
0224 bool driver_managed_dma;
0225 };
0226
0227 #define to_platform_driver(drv) (container_of((drv), struct platform_driver, \
0228 driver))
0229
0230
0231
0232
0233 #define platform_driver_register(drv) \
0234 __platform_driver_register(drv, THIS_MODULE)
0235 extern int __platform_driver_register(struct platform_driver *,
0236 struct module *);
0237 extern void platform_driver_unregister(struct platform_driver *);
0238
0239
0240
0241
0242 #define platform_driver_probe(drv, probe) \
0243 __platform_driver_probe(drv, probe, THIS_MODULE)
0244 extern int __platform_driver_probe(struct platform_driver *driver,
0245 int (*probe)(struct platform_device *), struct module *module);
0246
0247 static inline void *platform_get_drvdata(const struct platform_device *pdev)
0248 {
0249 return dev_get_drvdata(&pdev->dev);
0250 }
0251
0252 static inline void platform_set_drvdata(struct platform_device *pdev,
0253 void *data)
0254 {
0255 dev_set_drvdata(&pdev->dev, data);
0256 }
0257
0258
0259
0260
0261
0262
0263 #define module_platform_driver(__platform_driver) \
0264 module_driver(__platform_driver, platform_driver_register, \
0265 platform_driver_unregister)
0266
0267
0268
0269
0270
0271
0272
0273 #define builtin_platform_driver(__platform_driver) \
0274 builtin_driver(__platform_driver, platform_driver_register)
0275
0276
0277
0278
0279
0280
0281 #define module_platform_driver_probe(__platform_driver, __platform_probe) \
0282 static int __init __platform_driver##_init(void) \
0283 { \
0284 return platform_driver_probe(&(__platform_driver), \
0285 __platform_probe); \
0286 } \
0287 module_init(__platform_driver##_init); \
0288 static void __exit __platform_driver##_exit(void) \
0289 { \
0290 platform_driver_unregister(&(__platform_driver)); \
0291 } \
0292 module_exit(__platform_driver##_exit);
0293
0294
0295
0296
0297
0298
0299
0300 #define builtin_platform_driver_probe(__platform_driver, __platform_probe) \
0301 static int __init __platform_driver##_init(void) \
0302 { \
0303 return platform_driver_probe(&(__platform_driver), \
0304 __platform_probe); \
0305 } \
0306 device_initcall(__platform_driver##_init); \
0307
0308 #define platform_create_bundle(driver, probe, res, n_res, data, size) \
0309 __platform_create_bundle(driver, probe, res, n_res, data, size, THIS_MODULE)
0310 extern struct platform_device *__platform_create_bundle(
0311 struct platform_driver *driver, int (*probe)(struct platform_device *),
0312 struct resource *res, unsigned int n_res,
0313 const void *data, size_t size, struct module *module);
0314
0315 int __platform_register_drivers(struct platform_driver * const *drivers,
0316 unsigned int count, struct module *owner);
0317 void platform_unregister_drivers(struct platform_driver * const *drivers,
0318 unsigned int count);
0319
0320 #define platform_register_drivers(drivers, count) \
0321 __platform_register_drivers(drivers, count, THIS_MODULE)
0322
0323 #ifdef CONFIG_SUSPEND
0324 extern int platform_pm_suspend(struct device *dev);
0325 extern int platform_pm_resume(struct device *dev);
0326 #else
0327 #define platform_pm_suspend NULL
0328 #define platform_pm_resume NULL
0329 #endif
0330
0331 #ifdef CONFIG_HIBERNATE_CALLBACKS
0332 extern int platform_pm_freeze(struct device *dev);
0333 extern int platform_pm_thaw(struct device *dev);
0334 extern int platform_pm_poweroff(struct device *dev);
0335 extern int platform_pm_restore(struct device *dev);
0336 #else
0337 #define platform_pm_freeze NULL
0338 #define platform_pm_thaw NULL
0339 #define platform_pm_poweroff NULL
0340 #define platform_pm_restore NULL
0341 #endif
0342
0343 #ifdef CONFIG_PM_SLEEP
0344 #define USE_PLATFORM_PM_SLEEP_OPS \
0345 .suspend = platform_pm_suspend, \
0346 .resume = platform_pm_resume, \
0347 .freeze = platform_pm_freeze, \
0348 .thaw = platform_pm_thaw, \
0349 .poweroff = platform_pm_poweroff, \
0350 .restore = platform_pm_restore,
0351 #else
0352 #define USE_PLATFORM_PM_SLEEP_OPS
0353 #endif
0354
0355 #ifndef CONFIG_SUPERH
0356
0357
0358
0359
0360
0361 static inline int is_sh_early_platform_device(struct platform_device *pdev)
0362 {
0363 return 0;
0364 }
0365 #endif
0366
0367
0368 void early_platform_cleanup(void);
0369
0370 #endif