pmac_pfunc.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. #ifndef __PMAC_PFUNC_H__
  2. #define __PMAC_PFUNC_H__
  3. #include <linux/types.h>
  4. #include <linux/list.h>
  5. /* Flags in command lists */
  6. #define PMF_FLAGS_ON_INIT 0x80000000u
  7. #define PMF_FLGAS_ON_TERM 0x40000000u
  8. #define PMF_FLAGS_ON_SLEEP 0x20000000u
  9. #define PMF_FLAGS_ON_WAKE 0x10000000u
  10. #define PMF_FLAGS_ON_DEMAND 0x08000000u
  11. #define PMF_FLAGS_INT_GEN 0x04000000u
  12. #define PMF_FLAGS_HIGH_SPEED 0x02000000u
  13. #define PMF_FLAGS_LOW_SPEED 0x01000000u
  14. #define PMF_FLAGS_SIDE_EFFECTS 0x00800000u
  15. /*
  16. * Arguments to a platform function call.
  17. *
  18. * NOTE: By convention, pointer arguments point to an u32
  19. */
  20. struct pmf_args {
  21. union {
  22. u32 v;
  23. u32 *p;
  24. } u[4];
  25. unsigned int count;
  26. };
  27. /*
  28. * A driver capable of interpreting commands provides a handlers
  29. * structure filled with whatever handlers are implemented by this
  30. * driver. Non implemented handlers are left NULL.
  31. *
  32. * PMF_STD_ARGS are the same arguments that are passed to the parser
  33. * and that gets passed back to the various handlers.
  34. *
  35. * Interpreting a given function always start with a begin() call which
  36. * returns an instance data to be passed around subsequent calls, and
  37. * ends with an end() call. This allows the low level driver to implement
  38. * locking policy or per-function instance data.
  39. *
  40. * For interrupt capable functions, irq_enable() is called when a client
  41. * registers, and irq_disable() is called when the last client unregisters
  42. * Note that irq_enable & irq_disable are called within a semaphore held
  43. * by the core, thus you should not try to register yourself to some other
  44. * pmf interrupt during those calls.
  45. */
  46. #define PMF_STD_ARGS struct pmf_function *func, void *instdata, \
  47. struct pmf_args *args
  48. struct pmf_function;
  49. struct pmf_handlers {
  50. void * (*begin)(struct pmf_function *func, struct pmf_args *args);
  51. void (*end)(struct pmf_function *func, void *instdata);
  52. int (*irq_enable)(struct pmf_function *func);
  53. int (*irq_disable)(struct pmf_function *func);
  54. int (*write_gpio)(PMF_STD_ARGS, u8 value, u8 mask);
  55. int (*read_gpio)(PMF_STD_ARGS, u8 mask, int rshift, u8 xor);
  56. int (*write_reg32)(PMF_STD_ARGS, u32 offset, u32 value, u32 mask);
  57. int (*read_reg32)(PMF_STD_ARGS, u32 offset);
  58. int (*write_reg16)(PMF_STD_ARGS, u32 offset, u16 value, u16 mask);
  59. int (*read_reg16)(PMF_STD_ARGS, u32 offset);
  60. int (*write_reg8)(PMF_STD_ARGS, u32 offset, u8 value, u8 mask);
  61. int (*read_reg8)(PMF_STD_ARGS, u32 offset);
  62. int (*delay)(PMF_STD_ARGS, u32 duration);
  63. int (*wait_reg32)(PMF_STD_ARGS, u32 offset, u32 value, u32 mask);
  64. int (*wait_reg16)(PMF_STD_ARGS, u32 offset, u16 value, u16 mask);
  65. int (*wait_reg8)(PMF_STD_ARGS, u32 offset, u8 value, u8 mask);
  66. int (*read_i2c)(PMF_STD_ARGS, u32 len);
  67. int (*write_i2c)(PMF_STD_ARGS, u32 len, const u8 *data);
  68. int (*rmw_i2c)(PMF_STD_ARGS, u32 masklen, u32 valuelen, u32 totallen,
  69. const u8 *maskdata, const u8 *valuedata);
  70. int (*read_cfg)(PMF_STD_ARGS, u32 offset, u32 len);
  71. int (*write_cfg)(PMF_STD_ARGS, u32 offset, u32 len, const u8 *data);
  72. int (*rmw_cfg)(PMF_STD_ARGS, u32 offset, u32 masklen, u32 valuelen,
  73. u32 totallen, const u8 *maskdata, const u8 *valuedata);
  74. int (*read_i2c_sub)(PMF_STD_ARGS, u8 subaddr, u32 len);
  75. int (*write_i2c_sub)(PMF_STD_ARGS, u8 subaddr, u32 len, const u8 *data);
  76. int (*set_i2c_mode)(PMF_STD_ARGS, int mode);
  77. int (*rmw_i2c_sub)(PMF_STD_ARGS, u8 subaddr, u32 masklen, u32 valuelen,
  78. u32 totallen, const u8 *maskdata,
  79. const u8 *valuedata);
  80. int (*read_reg32_msrx)(PMF_STD_ARGS, u32 offset, u32 mask, u32 shift,
  81. u32 xor);
  82. int (*read_reg16_msrx)(PMF_STD_ARGS, u32 offset, u32 mask, u32 shift,
  83. u32 xor);
  84. int (*read_reg8_msrx)(PMF_STD_ARGS, u32 offset, u32 mask, u32 shift,
  85. u32 xor);
  86. int (*write_reg32_slm)(PMF_STD_ARGS, u32 offset, u32 shift, u32 mask);
  87. int (*write_reg16_slm)(PMF_STD_ARGS, u32 offset, u32 shift, u32 mask);
  88. int (*write_reg8_slm)(PMF_STD_ARGS, u32 offset, u32 shift, u32 mask);
  89. int (*mask_and_compare)(PMF_STD_ARGS, u32 len, const u8 *maskdata,
  90. const u8 *valuedata);
  91. struct module *owner;
  92. };
  93. /*
  94. * Drivers who expose platform functions register at init time, this
  95. * causes the platform functions for that device node to be parsed in
  96. * advance and associated with the device. The data structures are
  97. * partially public so a driver can walk the list of platform functions
  98. * and eventually inspect the flags
  99. */
  100. struct pmf_device;
  101. struct pmf_function {
  102. /* All functions for a given driver are linked */
  103. struct list_head link;
  104. /* Function node & driver data */
  105. struct device_node *node;
  106. void *driver_data;
  107. /* For internal use by core */
  108. struct pmf_device *dev;
  109. /* The name is the "xxx" in "platform-do-xxx", this is how
  110. * platform functions are identified by this code. Some functions
  111. * only operate for a given target, in which case the phandle is
  112. * here (or 0 if the filter doesn't apply)
  113. */
  114. const char *name;
  115. u32 phandle;
  116. /* The flags for that function. You can have several functions
  117. * with the same name and different flag
  118. */
  119. u32 flags;
  120. /* The actual tokenized function blob */
  121. const void *data;
  122. unsigned int length;
  123. /* Interrupt clients */
  124. struct list_head irq_clients;
  125. /* Refcounting */
  126. struct kref ref;
  127. };
  128. /*
  129. * For platform functions that are interrupts, one can register
  130. * irq_client structures. You canNOT use the same structure twice
  131. * as it contains a link member. Also, the callback is called with
  132. * a spinlock held, you must not call back into any of the pmf_* functions
  133. * from within that callback
  134. */
  135. struct pmf_irq_client {
  136. void (*handler)(void *data);
  137. void *data;
  138. struct module *owner;
  139. struct list_head link;
  140. struct pmf_function *func;
  141. };
  142. /*
  143. * Register/Unregister a function-capable driver and its handlers
  144. */
  145. extern int pmf_register_driver(struct device_node *np,
  146. struct pmf_handlers *handlers,
  147. void *driverdata);
  148. extern void pmf_unregister_driver(struct device_node *np);
  149. /*
  150. * Register/Unregister interrupt clients
  151. */
  152. extern int pmf_register_irq_client(struct device_node *np,
  153. const char *name,
  154. struct pmf_irq_client *client);
  155. extern void pmf_unregister_irq_client(struct pmf_irq_client *client);
  156. /*
  157. * Called by the handlers when an irq happens
  158. */
  159. extern void pmf_do_irq(struct pmf_function *func);
  160. /*
  161. * Low level call to platform functions.
  162. *
  163. * The phandle can filter on the target object for functions that have
  164. * multiple targets, the flags allow you to restrict the call to a given
  165. * combination of flags.
  166. *
  167. * The args array contains as many arguments as is required by the function,
  168. * this is dependent on the function you are calling, unfortunately Apple
  169. * mechanism provides no way to encode that so you have to get it right at
  170. * the call site. Some functions require no args, in which case, you can
  171. * pass NULL.
  172. *
  173. * You can also pass NULL to the name. This will match any function that has
  174. * the appropriate combination of flags & phandle or you can pass 0 to the
  175. * phandle to match any
  176. */
  177. extern int pmf_do_functions(struct device_node *np, const char *name,
  178. u32 phandle, u32 flags, struct pmf_args *args);
  179. /*
  180. * High level call to a platform function.
  181. *
  182. * This one looks for the platform-xxx first so you should call it to the
  183. * actual target if any. It will fallback to platform-do-xxx if it can't
  184. * find one. It will also exclusively target functions that have
  185. * the "OnDemand" flag.
  186. */
  187. extern int pmf_call_function(struct device_node *target, const char *name,
  188. struct pmf_args *args);
  189. /*
  190. * For low latency interrupt usage, you can lookup for on-demand functions
  191. * using the functions below
  192. */
  193. extern struct pmf_function *pmf_find_function(struct device_node *target,
  194. const char *name);
  195. extern struct pmf_function * pmf_get_function(struct pmf_function *func);
  196. extern void pmf_put_function(struct pmf_function *func);
  197. extern int pmf_call_one(struct pmf_function *func, struct pmf_args *args);
  198. /* Suspend/resume code called by via-pmu directly for now */
  199. extern void pmac_pfunc_base_suspend(void);
  200. extern void pmac_pfunc_base_resume(void);
  201. #endif /* __PMAC_PFUNC_H__ */