platform_device.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*
  2. * platform_device.h - generic, centralized driver model
  3. *
  4. * Copyright (c) 2001-2003 Patrick Mochel <mochel@osdl.org>
  5. *
  6. * This file is released under the GPLv2
  7. *
  8. * See Documentation/driver-model/ for more information.
  9. */
  10. #ifndef _PLATFORM_DEVICE_H_
  11. #define _PLATFORM_DEVICE_H_
  12. #include <linux/device.h>
  13. #include <linux/mod_devicetable.h>
  14. struct mfd_cell;
  15. struct platform_device {
  16. const char * name;
  17. int id;
  18. struct device dev;
  19. u32 num_resources;
  20. struct resource * resource;
  21. const struct platform_device_id *id_entry;
  22. /* MFD cell pointer */
  23. struct mfd_cell *mfd_cell;
  24. /* arch specific additions */
  25. struct pdev_archdata archdata;
  26. };
  27. #define platform_get_device_id(pdev) ((pdev)->id_entry)
  28. #define to_platform_device(x) container_of((x), struct platform_device, dev)
  29. extern int platform_device_register(struct platform_device *);
  30. extern void platform_device_unregister(struct platform_device *);
  31. extern struct bus_type platform_bus_type;
  32. extern struct device platform_bus;
  33. extern void arch_setup_pdev_archdata(struct platform_device *);
  34. extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
  35. extern int platform_get_irq(struct platform_device *, unsigned int);
  36. extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);
  37. extern int platform_get_irq_byname(struct platform_device *, const char *);
  38. extern int platform_add_devices(struct platform_device **, int);
  39. extern struct platform_device *platform_device_register_resndata(
  40. struct device *parent, const char *name, int id,
  41. const struct resource *res, unsigned int num,
  42. const void *data, size_t size);
  43. /**
  44. * platform_device_register_simple - add a platform-level device and its resources
  45. * @name: base name of the device we're adding
  46. * @id: instance id
  47. * @res: set of resources that needs to be allocated for the device
  48. * @num: number of resources
  49. *
  50. * This function creates a simple platform device that requires minimal
  51. * resource and memory management. Canned release function freeing memory
  52. * allocated for the device allows drivers using such devices to be
  53. * unloaded without waiting for the last reference to the device to be
  54. * dropped.
  55. *
  56. * This interface is primarily intended for use with legacy drivers which
  57. * probe hardware directly. Because such drivers create sysfs device nodes
  58. * themselves, rather than letting system infrastructure handle such device
  59. * enumeration tasks, they don't fully conform to the Linux driver model.
  60. * In particular, when such drivers are built as modules, they can't be
  61. * "hotplugged".
  62. *
  63. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  64. */
  65. static inline struct platform_device *platform_device_register_simple(
  66. const char *name, int id,
  67. const struct resource *res, unsigned int num)
  68. {
  69. return platform_device_register_resndata(NULL, name, id,
  70. res, num, NULL, 0);
  71. }
  72. /**
  73. * platform_device_register_data - add a platform-level device with platform-specific data
  74. * @parent: parent device for the device we're adding
  75. * @name: base name of the device we're adding
  76. * @id: instance id
  77. * @data: platform specific data for this platform device
  78. * @size: size of platform specific data
  79. *
  80. * This function creates a simple platform device that requires minimal
  81. * resource and memory management. Canned release function freeing memory
  82. * allocated for the device allows drivers using such devices to be
  83. * unloaded without waiting for the last reference to the device to be
  84. * dropped.
  85. *
  86. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  87. */
  88. static inline struct platform_device *platform_device_register_data(
  89. struct device *parent, const char *name, int id,
  90. const void *data, size_t size)
  91. {
  92. return platform_device_register_resndata(parent, name, id,
  93. NULL, 0, data, size);
  94. }
  95. extern struct platform_device *platform_device_alloc(const char *name, int id);
  96. extern int platform_device_add_resources(struct platform_device *pdev,
  97. const struct resource *res,
  98. unsigned int num);
  99. extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size);
  100. extern int platform_device_add(struct platform_device *pdev);
  101. extern void platform_device_del(struct platform_device *pdev);
  102. extern void platform_device_put(struct platform_device *pdev);
  103. struct platform_driver {
  104. int (*probe)(struct platform_device *);
  105. int (*remove)(struct platform_device *);
  106. void (*shutdown)(struct platform_device *);
  107. int (*suspend)(struct platform_device *, pm_message_t state);
  108. int (*resume)(struct platform_device *);
  109. struct device_driver driver;
  110. const struct platform_device_id *id_table;
  111. };
  112. extern int platform_driver_register(struct platform_driver *);
  113. extern void platform_driver_unregister(struct platform_driver *);
  114. /* non-hotpluggable platform devices may use this so that probe() and
  115. * its support may live in __init sections, conserving runtime memory.
  116. */
  117. extern int platform_driver_probe(struct platform_driver *driver,
  118. int (*probe)(struct platform_device *));
  119. static inline void *platform_get_drvdata(const struct platform_device *pdev)
  120. {
  121. return dev_get_drvdata(&pdev->dev);
  122. }
  123. static inline void platform_set_drvdata(struct platform_device *pdev, void *data)
  124. {
  125. dev_set_drvdata(&pdev->dev, data);
  126. }
  127. /* module_platform_driver() - Helper macro for drivers that don't do
  128. * anything special in module init/exit. This eliminates a lot of
  129. * boilerplate. Each module may only use this macro once, and
  130. * calling it replaces module_init() and module_exit()
  131. */
  132. #define module_platform_driver(__platform_driver) \
  133. static int __init __platform_driver##_init(void) \
  134. { \
  135. return platform_driver_register(&(__platform_driver)); \
  136. } \
  137. module_init(__platform_driver##_init); \
  138. static void __exit __platform_driver##_exit(void) \
  139. { \
  140. platform_driver_unregister(&(__platform_driver)); \
  141. } \
  142. module_exit(__platform_driver##_exit);
  143. extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
  144. int (*probe)(struct platform_device *),
  145. struct resource *res, unsigned int n_res,
  146. const void *data, size_t size);
  147. /* early platform driver interface */
  148. struct early_platform_driver {
  149. const char *class_str;
  150. struct platform_driver *pdrv;
  151. struct list_head list;
  152. int requested_id;
  153. char *buffer;
  154. int bufsize;
  155. };
  156. #define EARLY_PLATFORM_ID_UNSET -2
  157. #define EARLY_PLATFORM_ID_ERROR -3
  158. extern int early_platform_driver_register(struct early_platform_driver *epdrv,
  159. char *buf);
  160. extern void early_platform_add_devices(struct platform_device **devs, int num);
  161. static inline int is_early_platform_device(struct platform_device *pdev)
  162. {
  163. return !pdev->dev.driver;
  164. }
  165. extern void early_platform_driver_register_all(char *class_str);
  166. extern int early_platform_driver_probe(char *class_str,
  167. int nr_probe, int user_only);
  168. extern void early_platform_cleanup(void);
  169. #define early_platform_init(class_string, platdrv) \
  170. early_platform_init_buffer(class_string, platdrv, NULL, 0)
  171. #ifndef MODULE
  172. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  173. static __initdata struct early_platform_driver early_driver = { \
  174. .class_str = class_string, \
  175. .buffer = buf, \
  176. .bufsize = bufsiz, \
  177. .pdrv = platdrv, \
  178. .requested_id = EARLY_PLATFORM_ID_UNSET, \
  179. }; \
  180. static int __init early_platform_driver_setup_func(char *buffer) \
  181. { \
  182. return early_platform_driver_register(&early_driver, buffer); \
  183. } \
  184. early_param(class_string, early_platform_driver_setup_func)
  185. #else /* MODULE */
  186. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  187. static inline char *early_platform_driver_setup_func(void) \
  188. { \
  189. return bufsiz ? buf : NULL; \
  190. }
  191. #endif /* MODULE */
  192. #ifdef CONFIG_PM_SLEEP
  193. extern int platform_pm_prepare(struct device *dev);
  194. extern void platform_pm_complete(struct device *dev);
  195. #else
  196. #define platform_pm_prepare NULL
  197. #define platform_pm_complete NULL
  198. #endif
  199. #ifdef CONFIG_SUSPEND
  200. extern int platform_pm_suspend(struct device *dev);
  201. extern int platform_pm_suspend_noirq(struct device *dev);
  202. extern int platform_pm_resume(struct device *dev);
  203. extern int platform_pm_resume_noirq(struct device *dev);
  204. #else
  205. #define platform_pm_suspend NULL
  206. #define platform_pm_resume NULL
  207. #define platform_pm_suspend_noirq NULL
  208. #define platform_pm_resume_noirq NULL
  209. #endif
  210. #ifdef CONFIG_HIBERNATE_CALLBACKS
  211. extern int platform_pm_freeze(struct device *dev);
  212. extern int platform_pm_freeze_noirq(struct device *dev);
  213. extern int platform_pm_thaw(struct device *dev);
  214. extern int platform_pm_thaw_noirq(struct device *dev);
  215. extern int platform_pm_poweroff(struct device *dev);
  216. extern int platform_pm_poweroff_noirq(struct device *dev);
  217. extern int platform_pm_restore(struct device *dev);
  218. extern int platform_pm_restore_noirq(struct device *dev);
  219. #else
  220. #define platform_pm_freeze NULL
  221. #define platform_pm_thaw NULL
  222. #define platform_pm_poweroff NULL
  223. #define platform_pm_restore NULL
  224. #define platform_pm_freeze_noirq NULL
  225. #define platform_pm_thaw_noirq NULL
  226. #define platform_pm_poweroff_noirq NULL
  227. #define platform_pm_restore_noirq NULL
  228. #endif
  229. #ifdef CONFIG_PM_SLEEP
  230. #define USE_PLATFORM_PM_SLEEP_OPS \
  231. .prepare = platform_pm_prepare, \
  232. .complete = platform_pm_complete, \
  233. .suspend = platform_pm_suspend, \
  234. .resume = platform_pm_resume, \
  235. .freeze = platform_pm_freeze, \
  236. .thaw = platform_pm_thaw, \
  237. .poweroff = platform_pm_poweroff, \
  238. .restore = platform_pm_restore, \
  239. .suspend_noirq = platform_pm_suspend_noirq, \
  240. .resume_noirq = platform_pm_resume_noirq, \
  241. .freeze_noirq = platform_pm_freeze_noirq, \
  242. .thaw_noirq = platform_pm_thaw_noirq, \
  243. .poweroff_noirq = platform_pm_poweroff_noirq, \
  244. .restore_noirq = platform_pm_restore_noirq,
  245. #else
  246. #define USE_PLATFORM_PM_SLEEP_OPS
  247. #endif
  248. #endif /* _PLATFORM_DEVICE_H_ */