Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __PMAC_PFUNC_H__
0003 #define __PMAC_PFUNC_H__
0004 
0005 #include <linux/types.h>
0006 #include <linux/list.h>
0007 
0008 /* Flags in command lists */
0009 #define PMF_FLAGS_ON_INIT       0x80000000u
0010 #define PMF_FLGAS_ON_TERM       0x40000000u
0011 #define PMF_FLAGS_ON_SLEEP      0x20000000u
0012 #define PMF_FLAGS_ON_WAKE       0x10000000u
0013 #define PMF_FLAGS_ON_DEMAND     0x08000000u
0014 #define PMF_FLAGS_INT_GEN       0x04000000u
0015 #define PMF_FLAGS_HIGH_SPEED        0x02000000u
0016 #define PMF_FLAGS_LOW_SPEED     0x01000000u
0017 #define PMF_FLAGS_SIDE_EFFECTS      0x00800000u
0018 
0019 /*
0020  * Arguments to a platform function call.
0021  *
0022  * NOTE: By convention, pointer arguments point to an u32
0023  */
0024 struct pmf_args {
0025     union {
0026         u32 v;
0027         u32 *p;
0028     } u[4];
0029     unsigned int count;
0030 };
0031 
0032 /*
0033  * A driver capable of interpreting commands provides a handlers
0034  * structure filled with whatever handlers are implemented by this
0035  * driver. Non implemented handlers are left NULL.
0036  *
0037  * PMF_STD_ARGS are the same arguments that are passed to the parser
0038  * and that gets passed back to the various handlers.
0039  *
0040  * Interpreting a given function always start with a begin() call which
0041  * returns an instance data to be passed around subsequent calls, and
0042  * ends with an end() call. This allows the low level driver to implement
0043  * locking policy or per-function instance data.
0044  *
0045  * For interrupt capable functions, irq_enable() is called when a client
0046  * registers, and irq_disable() is called when the last client unregisters
0047  * Note that irq_enable & irq_disable are called within a semaphore held
0048  * by the core, thus you should not try to register yourself to some other
0049  * pmf interrupt during those calls.
0050  */
0051 
0052 #define PMF_STD_ARGS    struct pmf_function *func, void *instdata, \
0053                 struct pmf_args *args
0054 
0055 struct pmf_function;
0056 
0057 struct pmf_handlers {
0058     void * (*begin)(struct pmf_function *func, struct pmf_args *args);
0059     void (*end)(struct pmf_function *func, void *instdata);
0060 
0061     int (*irq_enable)(struct pmf_function *func);
0062     int (*irq_disable)(struct pmf_function *func);
0063 
0064     int (*write_gpio)(PMF_STD_ARGS, u8 value, u8 mask);
0065     int (*read_gpio)(PMF_STD_ARGS, u8 mask, int rshift, u8 xor);
0066 
0067     int (*write_reg32)(PMF_STD_ARGS, u32 offset, u32 value, u32 mask);
0068     int (*read_reg32)(PMF_STD_ARGS, u32 offset);
0069     int (*write_reg16)(PMF_STD_ARGS, u32 offset, u16 value, u16 mask);
0070     int (*read_reg16)(PMF_STD_ARGS, u32 offset);
0071     int (*write_reg8)(PMF_STD_ARGS, u32 offset, u8 value, u8 mask);
0072     int (*read_reg8)(PMF_STD_ARGS, u32 offset);
0073 
0074     int (*delay)(PMF_STD_ARGS, u32 duration);
0075 
0076     int (*wait_reg32)(PMF_STD_ARGS, u32 offset, u32 value, u32 mask);
0077     int (*wait_reg16)(PMF_STD_ARGS, u32 offset, u16 value, u16 mask);
0078     int (*wait_reg8)(PMF_STD_ARGS, u32 offset, u8 value, u8 mask);
0079 
0080     int (*read_i2c)(PMF_STD_ARGS, u32 len);
0081     int (*write_i2c)(PMF_STD_ARGS, u32 len, const u8 *data);
0082     int (*rmw_i2c)(PMF_STD_ARGS, u32 masklen, u32 valuelen, u32 totallen,
0083                const u8 *maskdata, const u8 *valuedata);
0084 
0085     int (*read_cfg)(PMF_STD_ARGS, u32 offset, u32 len);
0086     int (*write_cfg)(PMF_STD_ARGS, u32 offset, u32 len, const u8 *data);
0087     int (*rmw_cfg)(PMF_STD_ARGS, u32 offset, u32 masklen, u32 valuelen,
0088                u32 totallen, const u8 *maskdata, const u8 *valuedata);
0089 
0090     int (*read_i2c_sub)(PMF_STD_ARGS, u8 subaddr, u32 len);
0091     int (*write_i2c_sub)(PMF_STD_ARGS, u8 subaddr, u32 len, const u8 *data);
0092     int (*set_i2c_mode)(PMF_STD_ARGS, int mode);
0093     int (*rmw_i2c_sub)(PMF_STD_ARGS, u8 subaddr, u32 masklen, u32 valuelen,
0094                u32 totallen, const u8 *maskdata,
0095                const u8 *valuedata);
0096 
0097     int (*read_reg32_msrx)(PMF_STD_ARGS, u32 offset, u32 mask, u32 shift,
0098                    u32 xor);
0099     int (*read_reg16_msrx)(PMF_STD_ARGS, u32 offset, u32 mask, u32 shift,
0100                    u32 xor);
0101     int (*read_reg8_msrx)(PMF_STD_ARGS, u32 offset, u32 mask, u32 shift,
0102                   u32 xor);
0103 
0104     int (*write_reg32_slm)(PMF_STD_ARGS, u32 offset, u32 shift, u32 mask);
0105     int (*write_reg16_slm)(PMF_STD_ARGS, u32 offset, u32 shift, u32 mask);
0106     int (*write_reg8_slm)(PMF_STD_ARGS, u32 offset, u32 shift, u32 mask);
0107 
0108     int (*mask_and_compare)(PMF_STD_ARGS, u32 len, const u8 *maskdata,
0109                 const u8 *valuedata);
0110 
0111     struct module *owner;
0112 };
0113 
0114 
0115 /*
0116  * Drivers who expose platform functions register at init time, this
0117  * causes the platform functions for that device node to be parsed in
0118  * advance and associated with the device. The data structures are
0119  * partially public so a driver can walk the list of platform functions
0120  * and eventually inspect the flags
0121  */
0122 struct pmf_device;
0123 
0124 struct pmf_function {
0125     /* All functions for a given driver are linked */
0126     struct list_head    link;
0127 
0128     /* Function node & driver data */
0129     struct device_node  *node;
0130     void            *driver_data;
0131 
0132     /* For internal use by core */
0133     struct pmf_device   *dev;
0134 
0135     /* The name is the "xxx" in "platform-do-xxx", this is how
0136      * platform functions are identified by this code. Some functions
0137      * only operate for a given target, in which case the phandle is
0138      * here (or 0 if the filter doesn't apply)
0139      */
0140     const char      *name;
0141     u32         phandle;
0142 
0143     /* The flags for that function. You can have several functions
0144      * with the same name and different flag
0145      */
0146     u32         flags;
0147 
0148     /* The actual tokenized function blob */
0149     const void      *data;
0150     unsigned int        length;
0151 
0152     /* Interrupt clients */
0153     struct list_head    irq_clients;
0154 
0155     /* Refcounting */
0156     struct kref     ref;
0157 };
0158 
0159 /*
0160  * For platform functions that are interrupts, one can register
0161  * irq_client structures. You canNOT use the same structure twice
0162  * as it contains a link member. Also, the callback is called with
0163  * a spinlock held, you must not call back into any of the pmf_* functions
0164  * from within that callback
0165  */
0166 struct pmf_irq_client {
0167     void            (*handler)(void *data);
0168     void            *data;
0169     struct module       *owner;
0170     struct list_head    link;
0171     struct pmf_function *func;
0172 };
0173 
0174 
0175 /*
0176  * Register/Unregister a function-capable driver and its handlers
0177  */
0178 extern int pmf_register_driver(struct device_node *np,
0179                   struct pmf_handlers *handlers,
0180                   void *driverdata);
0181 
0182 extern void pmf_unregister_driver(struct device_node *np);
0183 
0184 
0185 /*
0186  * Register/Unregister interrupt clients
0187  */
0188 extern int pmf_register_irq_client(struct device_node *np,
0189                    const char *name,
0190                    struct pmf_irq_client *client);
0191 
0192 extern void pmf_unregister_irq_client(struct pmf_irq_client *client);
0193 
0194 /*
0195  * Called by the handlers when an irq happens
0196  */
0197 extern void pmf_do_irq(struct pmf_function *func);
0198 
0199 
0200 /*
0201  * Low level call to platform functions.
0202  *
0203  * The phandle can filter on the target object for functions that have
0204  * multiple targets, the flags allow you to restrict the call to a given
0205  * combination of flags.
0206  *
0207  * The args array contains as many arguments as is required by the function,
0208  * this is dependent on the function you are calling, unfortunately Apple
0209  * mechanism provides no way to encode that so you have to get it right at
0210  * the call site. Some functions require no args, in which case, you can
0211  * pass NULL.
0212  *
0213  * You can also pass NULL to the name. This will match any function that has
0214  * the appropriate combination of flags & phandle or you can pass 0 to the
0215  * phandle to match any
0216  */
0217 extern int pmf_do_functions(struct device_node *np, const char *name,
0218                 u32 phandle, u32 flags, struct pmf_args *args);
0219 
0220 
0221 
0222 /*
0223  * High level call to a platform function.
0224  *
0225  * This one looks for the platform-xxx first so you should call it to the
0226  * actual target if any. It will fallback to platform-do-xxx if it can't
0227  * find one. It will also exclusively target functions that have
0228  * the "OnDemand" flag.
0229  */
0230 
0231 extern int pmf_call_function(struct device_node *target, const char *name,
0232                  struct pmf_args *args);
0233 
0234 
0235 /*
0236  * For low latency interrupt usage, you can lookup for on-demand functions
0237  * using the functions below
0238  */
0239 
0240 extern struct pmf_function *pmf_find_function(struct device_node *target,
0241                           const char *name);
0242 
0243 extern struct pmf_function * pmf_get_function(struct pmf_function *func);
0244 extern void pmf_put_function(struct pmf_function *func);
0245 
0246 extern int pmf_call_one(struct pmf_function *func, struct pmf_args *args);
0247 
0248 int pmac_pfunc_base_install(void);
0249 
0250 /* Suspend/resume code called by via-pmu directly for now */
0251 extern void pmac_pfunc_base_suspend(void);
0252 extern void pmac_pfunc_base_resume(void);
0253 
0254 #endif /* __PMAC_PFUNC_H__ */