pmac_pfunc.h 8.0 KB

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