platform_device.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. extern const struct dev_pm_ops * platform_bus_get_pm_ops(void);
  131. extern void platform_bus_set_pm_ops(const struct dev_pm_ops *pm);
  132. /* early platform driver interface */
  133. struct early_platform_driver {
  134. const char *class_str;
  135. struct platform_driver *pdrv;
  136. struct list_head list;
  137. int requested_id;
  138. char *buffer;
  139. int bufsize;
  140. };
  141. #define EARLY_PLATFORM_ID_UNSET -2
  142. #define EARLY_PLATFORM_ID_ERROR -3
  143. extern int early_platform_driver_register(struct early_platform_driver *epdrv,
  144. char *buf);
  145. extern void early_platform_add_devices(struct platform_device **devs, int num);
  146. static inline int is_early_platform_device(struct platform_device *pdev)
  147. {
  148. return !pdev->dev.driver;
  149. }
  150. extern void early_platform_driver_register_all(char *class_str);
  151. extern int early_platform_driver_probe(char *class_str,
  152. int nr_probe, int user_only);
  153. extern void early_platform_cleanup(void);
  154. #define early_platform_init(class_string, platdrv) \
  155. early_platform_init_buffer(class_string, platdrv, NULL, 0)
  156. #ifndef MODULE
  157. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  158. static __initdata struct early_platform_driver early_driver = { \
  159. .class_str = class_string, \
  160. .buffer = buf, \
  161. .bufsize = bufsiz, \
  162. .pdrv = platdrv, \
  163. .requested_id = EARLY_PLATFORM_ID_UNSET, \
  164. }; \
  165. static int __init early_platform_driver_setup_func(char *buffer) \
  166. { \
  167. return early_platform_driver_register(&early_driver, buffer); \
  168. } \
  169. early_param(class_string, early_platform_driver_setup_func)
  170. #else /* MODULE */
  171. #define early_platform_init_buffer(class_string, platdrv, buf, bufsiz) \
  172. static inline char *early_platform_driver_setup_func(void) \
  173. { \
  174. return bufsiz ? buf : NULL; \
  175. }
  176. #endif /* MODULE */
  177. #endif /* _PLATFORM_DEVICE_H_ */