platform_device.h 9.0 KB

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