Linux Audio

Check our new training course

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