platform_device.h 9.5 KB

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