platform_device.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. 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. extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
  166. int (*probe)(struct platform_device *),
  167. struct resource *res, unsigned int n_res,
  168. const void *data, size_t size);
  169. /* early platform driver interface */
  170. struct early_platform_driver {
  171. const char *class_str;
  172. struct platform_driver *pdrv;
  173. struct list_head list;
  174. int requested_id;
  175. char *buffer;
  176. int bufsize;
  177. };
  178. #define EARLY_PLATFORM_ID_UNSET -2
  179. #define EARLY_PLATFORM_ID_ERROR -3
  180. extern int early_platform_driver_register(struct early_platform_driver *epdrv,
  181. char *buf);
  182. extern void early_platform_add_devices(struct platform_device **devs, int num);
  183. static inline int is_early_platform_device(struct platform_device *pdev)
  184. {
  185. return !pdev->dev.driver;
  186. }
  187. extern void early_platform_driver_register_all(char *class_str);
  188. extern int early_platform_driver_probe(char *class_str,
  189. int nr_probe, int user_only);
  190. extern void early_platform_cleanup(void);
  191. #define early_platform_init(class_string, platdrv) \
  192. early_platform_init_buffer(class_string, platdrv, NULL, 0)
  193. #ifndef MODULE
  194. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  195. static __initdata struct early_platform_driver early_driver = { \
  196. .class_str = class_string, \
  197. .buffer = buf, \
  198. .bufsize = bufsiz, \
  199. .pdrv = platdrv, \
  200. .requested_id = EARLY_PLATFORM_ID_UNSET, \
  201. }; \
  202. static int __init early_platform_driver_setup_func(char *buffer) \
  203. { \
  204. return early_platform_driver_register(&early_driver, buffer); \
  205. } \
  206. early_param(class_string, early_platform_driver_setup_func)
  207. #else /* MODULE */
  208. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  209. static inline char *early_platform_driver_setup_func(void) \
  210. { \
  211. return bufsiz ? buf : NULL; \
  212. }
  213. #endif /* MODULE */
  214. #ifdef CONFIG_PM_SLEEP
  215. extern int platform_pm_prepare(struct device *dev);
  216. extern void platform_pm_complete(struct device *dev);
  217. #else
  218. #define platform_pm_prepare NULL
  219. #define platform_pm_complete NULL
  220. #endif
  221. #ifdef CONFIG_SUSPEND
  222. extern int platform_pm_suspend(struct device *dev);
  223. extern int platform_pm_suspend_noirq(struct device *dev);
  224. extern int platform_pm_resume(struct device *dev);
  225. extern int platform_pm_resume_noirq(struct device *dev);
  226. #else
  227. #define platform_pm_suspend NULL
  228. #define platform_pm_resume NULL
  229. #define platform_pm_suspend_noirq NULL
  230. #define platform_pm_resume_noirq NULL
  231. #endif
  232. #ifdef CONFIG_HIBERNATE_CALLBACKS
  233. extern int platform_pm_freeze(struct device *dev);
  234. extern int platform_pm_freeze_noirq(struct device *dev);
  235. extern int platform_pm_thaw(struct device *dev);
  236. extern int platform_pm_thaw_noirq(struct device *dev);
  237. extern int platform_pm_poweroff(struct device *dev);
  238. extern int platform_pm_poweroff_noirq(struct device *dev);
  239. extern int platform_pm_restore(struct device *dev);
  240. extern int platform_pm_restore_noirq(struct device *dev);
  241. #else
  242. #define platform_pm_freeze NULL
  243. #define platform_pm_thaw NULL
  244. #define platform_pm_poweroff NULL
  245. #define platform_pm_restore NULL
  246. #define platform_pm_freeze_noirq NULL
  247. #define platform_pm_thaw_noirq NULL
  248. #define platform_pm_poweroff_noirq NULL
  249. #define platform_pm_restore_noirq NULL
  250. #endif
  251. #ifdef CONFIG_PM_SLEEP
  252. #define USE_PLATFORM_PM_SLEEP_OPS \
  253. .prepare = platform_pm_prepare, \
  254. .complete = platform_pm_complete, \
  255. .suspend = platform_pm_suspend, \
  256. .resume = platform_pm_resume, \
  257. .freeze = platform_pm_freeze, \
  258. .thaw = platform_pm_thaw, \
  259. .poweroff = platform_pm_poweroff, \
  260. .restore = platform_pm_restore, \
  261. .suspend_noirq = platform_pm_suspend_noirq, \
  262. .resume_noirq = platform_pm_resume_noirq, \
  263. .freeze_noirq = platform_pm_freeze_noirq, \
  264. .thaw_noirq = platform_pm_thaw_noirq, \
  265. .poweroff_noirq = platform_pm_poweroff_noirq, \
  266. .restore_noirq = platform_pm_restore_noirq,
  267. #else
  268. #define USE_PLATFORM_PM_SLEEP_OPS
  269. #endif
  270. #endif /* _PLATFORM_DEVICE_H_ */