platform_device.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 platform_device {
  15. const char * name;
  16. int id;
  17. struct device dev;
  18. u32 num_resources;
  19. struct resource * resource;
  20. const struct platform_device_id *id_entry;
  21. /* arch specific additions */
  22. struct pdev_archdata archdata;
  23. };
  24. #define platform_get_device_id(pdev) ((pdev)->id_entry)
  25. #define to_platform_device(x) container_of((x), struct platform_device, dev)
  26. extern int platform_device_register(struct platform_device *);
  27. extern void platform_device_unregister(struct platform_device *);
  28. extern struct bus_type platform_bus_type;
  29. extern struct device platform_bus;
  30. extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
  31. extern int platform_get_irq(struct platform_device *, unsigned int);
  32. extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);
  33. extern int platform_get_irq_byname(struct platform_device *, const char *);
  34. extern int platform_add_devices(struct platform_device **, int);
  35. extern struct platform_device *platform_device_register_resndata(
  36. struct device *parent, const char *name, int id,
  37. const struct resource *res, unsigned int num,
  38. const void *data, size_t size);
  39. /**
  40. * platform_device_register_simple - add a platform-level device and its resources
  41. * @name: base name of the device we're adding
  42. * @id: instance id
  43. * @res: set of resources that needs to be allocated for the device
  44. * @num: number of resources
  45. *
  46. * This function creates a simple platform device that requires minimal
  47. * resource and memory management. Canned release function freeing memory
  48. * allocated for the device allows drivers using such devices to be
  49. * unloaded without waiting for the last reference to the device to be
  50. * dropped.
  51. *
  52. * This interface is primarily intended for use with legacy drivers which
  53. * probe hardware directly. Because such drivers create sysfs device nodes
  54. * themselves, rather than letting system infrastructure handle such device
  55. * enumeration tasks, they don't fully conform to the Linux driver model.
  56. * In particular, when such drivers are built as modules, they can't be
  57. * "hotplugged".
  58. *
  59. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  60. */
  61. static inline struct platform_device *platform_device_register_simple(
  62. const char *name, int id,
  63. const struct resource *res, unsigned int num)
  64. {
  65. return platform_device_register_resndata(NULL, name, id,
  66. res, num, NULL, 0);
  67. }
  68. /**
  69. * platform_device_register_data - add a platform-level device with platform-specific data
  70. * @parent: parent device for the device we're adding
  71. * @name: base name of the device we're adding
  72. * @id: instance id
  73. * @data: platform specific data for this platform device
  74. * @size: size of platform specific data
  75. *
  76. * This function creates a simple platform device that requires minimal
  77. * resource and memory management. Canned release function freeing memory
  78. * allocated for the device allows drivers using such devices to be
  79. * unloaded without waiting for the last reference to the device to be
  80. * dropped.
  81. *
  82. * Returns &struct platform_device pointer on success, or ERR_PTR() on error.
  83. */
  84. static inline struct platform_device *platform_device_register_data(
  85. struct device *parent, const char *name, int id,
  86. const void *data, size_t size)
  87. {
  88. return platform_device_register_resndata(parent, name, id,
  89. NULL, 0, data, size);
  90. }
  91. extern struct platform_device *platform_device_alloc(const char *name, int id);
  92. extern int platform_device_add_resources(struct platform_device *pdev,
  93. const struct resource *res,
  94. unsigned int num);
  95. extern int platform_device_add_data(struct platform_device *pdev, const void *data, size_t size);
  96. extern int platform_device_add(struct platform_device *pdev);
  97. extern void platform_device_del(struct platform_device *pdev);
  98. extern void platform_device_put(struct platform_device *pdev);
  99. struct platform_driver {
  100. int (*probe)(struct platform_device *);
  101. int (*remove)(struct platform_device *);
  102. void (*shutdown)(struct platform_device *);
  103. int (*suspend)(struct platform_device *, pm_message_t state);
  104. int (*resume)(struct platform_device *);
  105. struct device_driver driver;
  106. const struct platform_device_id *id_table;
  107. };
  108. extern int platform_driver_register(struct platform_driver *);
  109. extern void platform_driver_unregister(struct platform_driver *);
  110. /* non-hotpluggable platform devices may use this so that probe() and
  111. * its support may live in __init sections, conserving runtime memory.
  112. */
  113. extern int platform_driver_probe(struct platform_driver *driver,
  114. int (*probe)(struct platform_device *));
  115. static inline void *platform_get_drvdata(const struct platform_device *pdev)
  116. {
  117. return dev_get_drvdata(&pdev->dev);
  118. }
  119. static inline void platform_set_drvdata(struct platform_device *pdev, void *data)
  120. {
  121. dev_set_drvdata(&pdev->dev, data);
  122. }
  123. extern struct platform_device *platform_create_bundle(struct platform_driver *driver,
  124. int (*probe)(struct platform_device *),
  125. struct resource *res, unsigned int n_res,
  126. const void *data, size_t size);
  127. extern const struct dev_pm_ops * platform_bus_get_pm_ops(void);
  128. extern void platform_bus_set_pm_ops(const struct dev_pm_ops *pm);
  129. /* early platform driver interface */
  130. struct early_platform_driver {
  131. const char *class_str;
  132. struct platform_driver *pdrv;
  133. struct list_head list;
  134. int requested_id;
  135. char *buffer;
  136. int bufsize;
  137. };
  138. #define EARLY_PLATFORM_ID_UNSET -2
  139. #define EARLY_PLATFORM_ID_ERROR -3
  140. extern int early_platform_driver_register(struct early_platform_driver *epdrv,
  141. char *buf);
  142. extern void early_platform_add_devices(struct platform_device **devs, int num);
  143. static inline int is_early_platform_device(struct platform_device *pdev)
  144. {
  145. return !pdev->dev.driver;
  146. }
  147. extern void early_platform_driver_register_all(char *class_str);
  148. extern int early_platform_driver_probe(char *class_str,
  149. int nr_probe, int user_only);
  150. extern void early_platform_cleanup(void);
  151. #define early_platform_init(class_string, platdrv) \
  152. early_platform_init_buffer(class_string, platdrv, NULL, 0)
  153. #ifndef MODULE
  154. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  155. static __initdata struct early_platform_driver early_driver = { \
  156. .class_str = class_string, \
  157. .buffer = buf, \
  158. .bufsize = bufsiz, \
  159. .pdrv = platdrv, \
  160. .requested_id = EARLY_PLATFORM_ID_UNSET, \
  161. }; \
  162. static int __init early_platform_driver_setup_func(char *buffer) \
  163. { \
  164. return early_platform_driver_register(&early_driver, buffer); \
  165. } \
  166. early_param(class_string, early_platform_driver_setup_func)
  167. #else /* MODULE */
  168. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  169. static inline char *early_platform_driver_setup_func(void) \
  170. { \
  171. return bufsiz ? buf : NULL; \
  172. }
  173. #endif /* MODULE */
  174. #endif /* _PLATFORM_DEVICE_H_ */