platform_device.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. struct platform_device_info {
  40. struct device *parent;
  41. const char *name;
  42. int id;
  43. const struct resource *res;
  44. unsigned int num_res;
  45. const void *data;
  46. size_t size_data;
  47. u64 dma_mask;
  48. };
  49. extern struct platform_device *platform_device_register_full(
  50. const struct platform_device_info *pdevinfo);
  51. /**
  52. * platform_device_register_resndata - add a platform-level device with
  53. * resources and platform-specific data
  54. *
  55. * @parent: parent device for the device we're adding
  56. * @name: base name of the device we're adding
  57. * @id: instance id
  58. * @res: set of resources that needs to be allocated for the device
  59. * @num: number of resources
  60. * @data: platform specific data for this platform device
  61. * @size: size of platform specific data
  62. *
  63. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  64. */
  65. static inline struct platform_device *platform_device_register_resndata(
  66. struct device *parent, const char *name, int id,
  67. const struct resource *res, unsigned int num,
  68. const void *data, size_t size) {
  69. struct platform_device_info pdevinfo = {
  70. .parent = parent,
  71. .name = name,
  72. .id = id,
  73. .res = res,
  74. .num_res = num,
  75. .data = data,
  76. .size_data = size,
  77. .dma_mask = 0,
  78. };
  79. return platform_device_register_full(&pdevinfo);
  80. }
  81. /**
  82. * platform_device_register_simple - add a platform-level device and its resources
  83. * @name: base name of the device we're adding
  84. * @id: instance id
  85. * @res: set of resources that needs to be allocated for the device
  86. * @num: number of resources
  87. *
  88. * This function creates a simple platform device that requires minimal
  89. * resource and memory management. Canned release function freeing memory
  90. * allocated for the device allows drivers using such devices to be
  91. * unloaded without waiting for the last reference to the device to be
  92. * dropped.
  93. *
  94. * This interface is primarily intended for use with legacy drivers which
  95. * probe hardware directly. Because such drivers create sysfs device nodes
  96. * themselves, rather than letting system infrastructure handle such device
  97. * enumeration tasks, they don't fully conform to the Linux driver model.
  98. * In particular, when such drivers are built as modules, they can't be
  99. * "hotplugged".
  100. *
  101. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  102. */
  103. static inline struct platform_device *platform_device_register_simple(
  104. const char *name, int id,
  105. const struct resource *res, unsigned int num)
  106. {
  107. return platform_device_register_resndata(NULL, name, id,
  108. res, num, NULL, 0);
  109. }
  110. /**
  111. * platform_device_register_data - add a platform-level device with platform-specific data
  112. * @parent: parent device for the device we're adding
  113. * @name: base name of the device we're adding
  114. * @id: instance id
  115. * @data: platform specific data for this platform device
  116. * @size: size of platform specific data
  117. *
  118. * This function creates a simple platform device that requires minimal
  119. * resource and memory management. Canned release function freeing memory
  120. * allocated for the device allows drivers using such devices to be
  121. * unloaded without waiting for the last reference to the device to be
  122. * dropped.
  123. *
  124. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  125. */
  126. static inline struct platform_device *platform_device_register_data(
  127. struct device *parent, const char *name, int id,
  128. const void *data, size_t size)
  129. {
  130. return platform_device_register_resndata(parent, name, id,
  131. NULL, 0, data, size);
  132. }
  133. extern struct platform_device *platform_device_alloc(const char *name, int id);
  134. extern int platform_device_add_resources(struct platform_device *pdev,
  135. const struct resource *res,
  136. unsigned int num);
  137. extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size);
  138. extern int platform_device_add(struct platform_device *pdev);
  139. extern void platform_device_del(struct platform_device *pdev);
  140. extern void platform_device_put(struct platform_device *pdev);
  141. struct platform_driver {
  142. int (*probe)(struct platform_device *);
  143. int (*remove)(struct platform_device *);
  144. void (*shutdown)(struct platform_device *);
  145. int (*suspend)(struct platform_device *, pm_message_t state);
  146. int (*resume)(struct platform_device *);
  147. struct device_driver driver;
  148. const struct platform_device_id *id_table;
  149. };
  150. extern int platform_driver_register(struct platform_driver *);
  151. extern void platform_driver_unregister(struct platform_driver *);
  152. /* non-hotpluggable platform devices may use this so that probe() and
  153. * its support may live in __init sections, conserving runtime memory.
  154. */
  155. extern int platform_driver_probe(struct platform_driver *driver,
  156. int (*probe)(struct platform_device *));
  157. static inline void *platform_get_drvdata(const struct platform_device *pdev)
  158. {
  159. return dev_get_drvdata(&pdev->dev);
  160. }
  161. static inline void platform_set_drvdata(struct platform_device *pdev, void *data)
  162. {
  163. dev_set_drvdata(&pdev->dev, data);
  164. }
  165. /* module_platform_driver() - Helper macro for drivers that don't do
  166. * anything special in module init/exit. This eliminates a lot of
  167. * boilerplate. Each module may only use this macro once, and
  168. * calling it replaces module_init() and module_exit()
  169. */
  170. #define module_platform_driver(__platform_driver) \
  171. module_driver(__platform_driver, platform_driver_register, \
  172. platform_driver_unregister)
  173. extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
  174. int (*probe)(struct platform_device *),
  175. struct resource *res, unsigned int n_res,
  176. const void *data, size_t size);
  177. /* early platform driver interface */
  178. struct early_platform_driver {
  179. const char *class_str;
  180. struct platform_driver *pdrv;
  181. struct list_head list;
  182. int requested_id;
  183. char *buffer;
  184. int bufsize;
  185. };
  186. #define EARLY_PLATFORM_ID_UNSET -2
  187. #define EARLY_PLATFORM_ID_ERROR -3
  188. extern int early_platform_driver_register(struct early_platform_driver *epdrv,
  189. char *buf);
  190. extern void early_platform_add_devices(struct platform_device **devs, int num);
  191. static inline int is_early_platform_device(struct platform_device *pdev)
  192. {
  193. return !pdev->dev.driver;
  194. }
  195. extern void early_platform_driver_register_all(char *class_str);
  196. extern int early_platform_driver_probe(char *class_str,
  197. int nr_probe, int user_only);
  198. extern void early_platform_cleanup(void);
  199. #define early_platform_init(class_string, platdrv) \
  200. early_platform_init_buffer(class_string, platdrv, NULL, 0)
  201. #ifndef MODULE
  202. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  203. static __initdata struct early_platform_driver early_driver = { \
  204. .class_str = class_string, \
  205. .buffer = buf, \
  206. .bufsize = bufsiz, \
  207. .pdrv = platdrv, \
  208. .requested_id = EARLY_PLATFORM_ID_UNSET, \
  209. }; \
  210. static int __init early_platform_driver_setup_func(char *buffer) \
  211. { \
  212. return early_platform_driver_register(&early_driver, buffer); \
  213. } \
  214. early_param(class_string, early_platform_driver_setup_func)
  215. #else /* MODULE */
  216. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  217. static inline char *early_platform_driver_setup_func(void) \
  218. { \
  219. return bufsiz ? buf : NULL; \
  220. }
  221. #endif /* MODULE */
  222. #ifdef CONFIG_SUSPEND
  223. extern int platform_pm_suspend(struct device *dev);
  224. extern int platform_pm_resume(struct device *dev);
  225. #else
  226. #define platform_pm_suspend NULL
  227. #define platform_pm_resume NULL
  228. #endif
  229. #ifdef CONFIG_HIBERNATE_CALLBACKS
  230. extern int platform_pm_freeze(struct device *dev);
  231. extern int platform_pm_thaw(struct device *dev);
  232. extern int platform_pm_poweroff(struct device *dev);
  233. extern int platform_pm_restore(struct device *dev);
  234. #else
  235. #define platform_pm_freeze NULL
  236. #define platform_pm_thaw NULL
  237. #define platform_pm_poweroff NULL
  238. #define platform_pm_restore NULL
  239. #endif
  240. #ifdef CONFIG_PM_SLEEP
  241. #define USE_PLATFORM_PM_SLEEP_OPS \
  242. .suspend = platform_pm_suspend, \
  243. .resume = platform_pm_resume, \
  244. .freeze = platform_pm_freeze, \
  245. .thaw = platform_pm_thaw, \
  246. .poweroff = platform_pm_poweroff, \
  247. .restore = platform_pm_restore,
  248. #else
  249. #define USE_PLATFORM_PM_SLEEP_OPS
  250. #endif
  251. #endif /* _PLATFORM_DEVICE_H_ */