1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /**
3  * Copyright 2019-2023 NXP
4  *
5  * KEYWORDS: micro-power uPower driver API
6  * -----------------------------------------------------------------------------
7  * PURPOSE: uPower driver API
8  * -----------------------------------------------------------------------------
9  * PARAMETERS:
10  * PARAM NAME RANGE:DESCRIPTION:       DEFAULTS:                           UNITS
11  * -----------------------------------------------------------------------------
12  * REUSE ISSUES: no reuse issues
13  */
14 
15 #ifndef _UPWR_API_H_
16 #define _UPWR_API_H_
17 
18 #ifdef UPWR_BLOCK_LEVEL
19 
20 #include <stdint.h> /* this include breaks the SoC compile - TBD why? */
21 
22 /* Includes/defines for use in block level simulation */
23 
24 #include "upmu.hh" /* emulated structure */
25 
26 #else
27 
28 /* Includes/definitions for use in production code */
29 
30 #include "upmu.h"
31 
32 #endif /* UPWR_BLOCK_LEVEL */
33 
34 /* Includes/definitions for use in both block level simulation and production */
35 
36 #include "upower_defs.h"
37 
38 #ifdef  __cplusplus
39 #ifndef UPWR_NAMESPACE /* extern "C" 'cancels' the effect of namespace */
40 extern "C" {
41 #endif
42 #endif
43 
44 /******************************************************************************
45  * uPower API Overview and Concepts
46  *
47  * Copyright 2019-2023 NXP
48  *
49  * This API is intended to be used by the OS drivers (Linux, FreeRTOS etc)
50  * as well as bare metal drivers to command and use services from the uPower.
51  * It aims to be OS-independent.
52  *
53  * The API functions fall in 3 categories:
54  *  - initialization/start-up
55  *  - service requests
56  *  - auxiliary
57  *
58  * The communication with the uPower is mostly made through the Message Unit
59  * (MU) IP. uPower provides one MU for each CPU cluster in a different
60  * power domain. An API instance runs on each CPU cluster.
61  *
62  * The API assumes each SoC power domain/CPU cluster receives 2 interrupts
63  * from the uPower MU:
64  *  1. Tx/Rx, which is issued on both transmission and reception
65  *  2. Exception interrupt, to handle critical alams, catastrophic errors, etc.
66  *     This interrupt should have a high priority, preferably an NMI.
67  *
68  * The normal uPower operation is done by service requests. There is an API
69  * function for each service request, and all service requests send back a
70  * response, at least to indicate success/failure.
71  * The service request functions are non-blocking, and their completion can be
72  * tracked in two ways:
73  *  1. by a callback, registered when the service request call is made by
74  *     passing the callback function pointer; a NULL pointer may be passed,
75  *     in which case no callback is made.
76  *  2. by polling, using the auxiliary functions upwr_req_status or
77  *     upwr_poll_req_status;
78  *     polling must be used if no callback is registered, but callbacks and
79  *     polling are completely independent.
80  *
81  * Note: a service request must not be started from a callback.
82  *
83  * uPower service requests are classified in Service Groups.
84  * Each Service Group has a set of related functions, named upwr_XXX_,
85  * where XXX is a 3-letter service group mnemonic. The service groups are:
86  *  - Exception Service Group - upwr_xcp_*
87  *     ~ gathers functions that deal with errors and other processes outside
88  *       the functional scope.
89  *  - Power Management Service Group - upwr_pwm_*
90  *     ~ functions to control switches, configure power modes, set internal voltage etc
91  *  - Delay Measurement Service Group - upwr_dlm_*
92  *     ~ delay measurements function using the process monitor and delay meter
93  *  - Voltage Measurement Service Group - upwr_vtm_*
94  *     ~ functions for voltage measurements, comparisons, alarms, power meter, set PMIC rail voltage
95  *  - Temperature Measurement Service Group - upwr_tpm_*
96  *     ~ functions for temperature measurements, comparisons, alarms
97  *  - Current Measurement Service Group  - upwr_crm_*
98  *     ~ functions for current and charge measurement
99  *  - Diagnostic Service Group - upwr_dgn_*
100  *     ~ functions for log configuration and statistics collecting
101  *
102  * Service requests follow this "golden rule":
103  * *** No two requests run simultaneously for the same service group,
104  *     on the same domain ***
105  * They can run simultaneously on different domains (RTD/APD), and can also run
106  * simultaneously if belong to different service groups (even on same domain).
107  * Therefore, requests to the same service group on the same domain must be
108  * serialized. A service request call returns error if there is another request
109  * on the same service group pending, waiting a response (on the same domain).
110  *
111  * A request for continuous service does not block the service group.
112  * For instance, a request to "measure the temperature each 10 miliseconds"
113  * responds quickly, unlocks the service group, and the temperature
114  * continues to be measured as requested, every 10 miliseconds from then on.
115  *
116  * Service Groups have a fixed priority in the API, from higher to lower:
117  *  1. Exception
118  *  2. Power Management
119  *  3. Delay Measurement
120  *  4. Voltage Measurement
121  *  5. Current Measurement
122  *  6. Temperature Measurement
123  *  7. Diagnostics
124  *
125  * The priority above only affects the order in which requests are sent to the
126  * uPower firmware: request to the higher priority Service Group is sent first,
127  * even if the call was made later, if there is an MU transmission pending,
128  * blocking it. The service priorities in the firmware depend on other factors.
129  *
130  * Services are requested using API functions. A service function returns with
131  * no error if a request was successfully made, but it doesn't mean the service
132  * was completed. The service is executed asynchronously, and returns a result
133  * (at least success/fail) via a callback or polling for service status.
134  * The possible service response codes are:
135  * - UPWR_RESP_OK = 0,     : no error
136  * - UPWR_RESP_SG_BUSY     : service group is busy
137  * - UPWR_RESP_SHUTDOWN    : services not up or shutting down
138  * - UPWR_RESP_BAD_REQ     : invalid request (usually invalid argumnents)
139  * - UPWR_RESP_BAD_STATE   : system state doesn't allow perform the request
140  * - UPWR_RESP_UNINSTALLD  : service or function not installed
141  * - UPWR_RESP_UNINSTALLED : service or function not installed (alias)
142  * - UPWR_RESP_RESOURCE    : resource not available
143  * - UPWR_RESP_TIMEOUT     : service timeout
144  */
145 
146 /**
147  * upwr_callb()-generic function pointer for a request return callback;
148  * @sg: request service group
149  * @func: service request function id.
150  * @errcode: error code.
151  * @ret: return value, if any. Note that a request may return a value even if
152  * service error is returned (errcode != UPWR_RESP_OK); that is dependent on
153  * the specific service.
154  *
155  * Context: no sleep, no locks taken/released.
156  * Return: none (void)
157  */
158 typedef void (*upwr_callb)(upwr_sg_t     sg,
159 			   uint32_t      func,
160 			   upwr_resp_t   errcode,
161 			   int           ret);
162 
163 /**---------------------------------------------------------------
164  * INITIALIZATION, CONFIGURATION
165  *
166  * A reference uPower initialization sequence goes as follows:
167  *
168  * 1. host CPU calls upwr_init.
169  * 2. (optional) host checks the ROM version and SoC code calling upwr_vers(...)
170  *    and optionally performs any configuration or workaround accordingly.
171  * 3. host CPU calls upwr_start to start the uPower services, passing a
172  *    service option number.
173  *    If no RAM code is loaded or it has no service options, the launch option
174  *    number passed must be 0, which will start the services available in ROM.
175  *    upwr_start also receives a pointer to a callback called by the API
176  *    when the firmware is ready to receive service requests.
177  *    The callback may be replaced by polling, calling upwr_req_status in a loop
178  *    or upwr_poll_req_status; in this case the callback pointer may be NULL.
179  *    A host may call upwr_start even if the services were already started by
180  *    any host: if the launch option is the same, the response will be ok,
181  *    but will indicate error if the services were already started with a
182  *    different launch option.
183  * 4. host waits for the callback calling, or polling finishing;
184  *    if no error is returned, it can start making service calls using the API.
185  *
186  * Variations on that reference sequence are possible:
187  *  - the uPower services can be started using the ROM code only, which includes
188  *    the basic Power Management services, among others, with launch option
189  *    number = 0.
190  *    The code RAM can be loaded while these services are running and,
191  *    when the loading is done, the services can be re-started with these 2
192  *    requests executed in order: upwr_xcp_shutdown and upwr_start,
193  *    using the newly loaded RAM code (launch option > 0).
194  *
195  * NOTE: the initialization call upwr_init is not effective and
196  *       returns error when called after the uPower services are started.
197  */
198 
199 /**
200  * upwr_init() - API initialization; must be the first API call after reset.
201  * @domain: SoC-dependent CPU domain id; identifier used by the firmware in
202  * many services. Defined by SoC-dependent type soc_domain_t found in
203  * upower_soc_defs.h.
204  * @muptr: pointer to the MU instance.
205  * @mallocptr: pointer to the memory allocation function
206  * @physaddrptr: pointer to the function to convert pointers to
207  * physical addresses. If NULL, no conversion is made (pointer=physical address)
208  * @isrinstptr: pointer to the function to install the uPower ISR callbacks;
209  * the function receives the pointers to the MU tx/rx and Exception ISRs
210  * callbacks, which must be called from the actual system ISRs.
211  * The function pointed by isrinstptr must also enable the interrupt at the
212  * core/interrupt controller, but must not enable the interrupt at the MU IP.
213  * The system ISRs are responsible for dealing with the interrupt controller,
214  * performing any other context save/restore, and any other housekeeping.
215  * @lockptr: pointer to a function that prevents MU interrupts (if argrument=1)
216  * or allows it (if argument=0). The API calls this function to make small
217  * specific code portions thread safe. Only MU interrupts must be avoided,
218  * the code may be suspended for other reasons.
219  * If no MU interrupts can happen during the execution of an API call or
220  * callback, even if enabled, for some other reason (e.g. interrupt priority),
221  * then this argument may be NULL.
222  *
223  * Context: no sleep, no locks taken/released.
224  * Return: 0 if ok,
225  *        -1 if failed to allocate memory, or use some other resource.
226  *        -2 if any argument is invalid.
227  *        -3 if failed to send the ping message.
228  *        -4 if failed to receive the initialization message, or was invalid
229  */
230 
231 /* malloc function ptr */
232 typedef void* (*upwr_malloc_ptr_t)(long unsigned int size);
233 
234 /* pointer->physical address conversion function ptr */
235 typedef void* (*upwr_phyadr_ptr_t)(const void* addr);
236 
237 typedef uint32_t upwr_api_state_t;
238 
239 extern volatile upwr_api_state_t api_state;
240 
241 /*
242  * upwr_lock_ptr_t: pointer to a function that prevents MU interrupts
243  * (if argrument lock=1) or allows it (if argument lock=0).
244  * The API calls this function to make small specific code portions thread safe.
245  * Only MU interrupts must be avoided, the code may be suspended for other
246  * reasons.
247  */
248 typedef void  (*upwr_lock_ptr_t)(int lock);
249 
250 typedef void (*upwr_isr_callb)(void);
251 
252 typedef void (*upwr_inst_isr_ptr_t)(upwr_isr_callb txrx_isr,
253 				    upwr_isr_callb excp_isr);
254 
255 void upwr_start_callb(void);
256 
257 int upwr_init(	soc_domain_t               domain,
258 		struct MU_tag*             muptr,
259 		const  upwr_malloc_ptr_t   mallocptr,
260 		const  upwr_phyadr_ptr_t   phyadrptr,
261 		const  upwr_inst_isr_ptr_t isrinstptr,
262 		const  upwr_lock_ptr_t     lockptr);
263 
264 /**
265  * upwr_start() - Starts the uPower services.
266  * @launchopt: a number to select between multiple launch options,
267  * that may define, among other things, which services will be started,
268  * or which services implementations, features etc.
269  * launchopt = 0 selects a subset of services implemented in ROM;
270  * any other number selects service sets implemented in RAM, launched
271  * by the firmware function ram_launch; if an invalid launchopt value is passed,
272  * no services are started, and the callback returns error (see below).
273  * @rdycallb: pointer to the callback to be called when the uPower is ready
274  * to receive service requests. NULL if no callback needed.
275  * The callback receives as arguments the RAM firmware version numbers.
276  * If all 3 numbers (vmajor, vminor, vfixes) are 0, that means the
277  * service launching failed.
278  * Firmware version numbers will be the same as ROM if launchopt = 0,
279  * selecting the ROM services.
280  *
281  * upwr_start can be called by any domain even if the services are already
282  * started: it has no effect, returning success, if the launch option is the
283  * same as the one that actually started the service, and returns error if
284  * called with a different option.
285  *
286  * A callback can be optionally registered, and will be called upon the arrival
287  * of the request response from the uPower firmware, telling if it succeeded or
288  * not.
289  * A callback may not be registered (NULL pointer), in which case polling has
290  * to be used to check the response, by calling upwr_req_status or
291  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
292  *
293  * Context: no sleep, no locks taken/released.
294  * Return: 0 if ok,
295  *        -1 if a resource failed,
296  *        -2 if the domain passed is the same as the caller,
297  *        -3 if called in an invalid API state
298  */
299 
300 extern void upwr_txrx_isr(void);
301 
302 typedef void (*upwr_rdy_callb)(uint32_t vmajor,uint32_t vminor,uint32_t vfixes);
303 
304 int upwr_start(	uint32_t                launchopt,
305 		const upwr_rdy_callb    rdycallb);
306 
307 
308 /**---------------------------------------------------------------
309  * EXCEPTION SERVICE GROUP
310  */
311 
312 /**
313  * upwr_xcp_config() - Applies general uPower configurations.
314  * @config: pointer to the uPower SoC-dependent configuration struct
315  * upwr_xcp_config_t defined in upower_soc_defs.h. NULL may be passed, meaning
316  * a request to read the configuration, in which case it appears in the callback
317  * argument ret, or can be pointed by argument retptr in the upwr_req_status and
318  * upwr_poll_req_status calls, casted to upwr_xcp_config_t.
319  * @callb: pointer to the callback to be called when the uPower has finished
320  * the configuration, or NULL if no callback needed (polling used instead).
321  *
322  * Some configurations are targeted for a specific domain (see the struct
323  * upwr_xcp_config_t definition in upower_soc_defs.h); this call has implicit
324  * domain target (the same domain from which is called).
325  *
326  * The return value is always the current configuration value, either in a
327  * read-only request (config = NULL) or after setting a new cnfiguration
328  * (non-NULL config).
329  *
330  * A callback can be optionally registered, and will be called upon the arrival
331  * of the request response from the uPower firmware, telling if it succeeded or
332  * not.
333  * A callback may not be registered (NULL pointer), in which case polling has
334  * to be used to check the response, by calling upwr_req_status or
335  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
336  *
337  * Context: no sleep, no locks taken/released.
338  * Return: 0 if ok,
339  *        -1 if service group is busy,
340  *        -3 if called in an invalid API state
341  */
342 
343 int upwr_xcp_config(const upwr_xcp_config_t* config, const upwr_callb callb);
344 
345 /**
346  * upwr_xcp_sw_alarm() - Makes uPower issue an alarm interrupt to given domain.
347  * @domain: identifier of the domain to alarm. Defined by SoC-dependent type
348  * soc_domain_t found in upower_soc_defs.h.
349  * @code: alarm code. Defined by SoC-dependent type upwr_alarm_t found in
350  * upower_soc_defs.h.
351  * @callb: pointer to the callback to be called when the uPower has finished
352  * the alarm, or NULL if no callback needed (polling used instead).
353  *
354  * The function requests the uPower to issue an alarm of the given code as if
355  * it had originated internally. This service is useful mainly to test the
356  * system response to such alarms, or to make the system handle a similar alarm
357  * situation detected externally to uPower.
358  *
359  * The system ISR/code handling the alarm may retrieve the alarm code by calling
360  * the auxiliary function upwr_alarm_code.
361  *
362  * A callback can be optionally registered, and will be called upon the arrival
363  * of the request response from the uPower firmware, telling if it succeeded or
364  * not.
365  * A callback may not be registered (NULL pointer), in which case polling has
366  * to be used to check the response, by calling upwr_req_status or
367  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
368  *
369  * Context: no sleep, no locks taken/released.
370  * Return: 0 if ok,
371  *        -1 if service group is busy,
372  *        -3 if called in an invalid API state
373  */
374 
375 int upwr_xcp_sw_alarm(soc_domain_t     domain,
376 		      upwr_alarm_t     code,
377 		      const upwr_callb callb);
378 
379 /**
380  * upwr_xcp_set_ddr_retention() - M33/A35 can use this API to set/clear ddr retention
381  * @domain: identifier of the caller domain.
382  * soc_domain_t found in upower_soc_defs.h.
383  * @enable: true, means that set ddr retention, false clear ddr retention.
384  * @callb: NULL
385  *
386  * A callback may not be registered (NULL pointer), in which case polling has
387  * to be used to check the response, by calling upwr_req_status or
388  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
389  *
390  * Context: no sleep, no locks taken/released.
391  * Return: 0 if ok,
392  *        -1 if service group is busy,
393  *        -3 if called in an invalid API state
394  */
395 
396 int upwr_xcp_set_ddr_retention(soc_domain_t     domain,
397                         uint32_t enable,
398                         const upwr_callb callb);
399 
400 /**
401  * upwr_xcp_set_rtd_use_ddr() - M33 call this API to inform uPower, M33 is using ddr
402  * @domain: identifier of the caller domain.
403  * soc_domain_t found in upower_soc_defs.h.
404  * @is_use_ddr: not 0, true, means that RTD is using ddr. 0, false, means that, RTD is not using ddr.
405  * @callb: NULL
406  *
407  * A callback may not be registered (NULL pointer), in which case polling has
408  * to be used to check the response, by calling upwr_req_status or
409  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
410  *
411  * Context: no sleep, no locks taken/released.
412  * Return: 0 if ok,
413  *        -1 if service group is busy,
414  *        -3 if called in an invalid API state
415  */
416 
417 int upwr_xcp_set_rtd_use_ddr(soc_domain_t     domain,
418                         uint32_t is_use_ddr,
419                         const upwr_callb callb);
420 
421 /**
422  * upwr_xcp_set_rtd_apd_llwu() - M33/A35 can use this API to set/clear rtd_llwu apd_llwu
423  * @domain: set which domain (RTD_DOMAIN, APD_DOMAIN) LLWU.
424  * soc_domain_t found in upower_soc_defs.h.
425  * @enable: true, means that set rtd_llwu or apd_llwu, false clear rtd_llwu or apd_llwu.
426  * @callb: NULL
427  *
428  * A callback may not be registered (NULL pointer), in which case polling has
429  * to be used to check the response, by calling upwr_req_status or
430  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
431  *
432  * Context: no sleep, no locks taken/released.
433  * Return: 0 if ok,
434  *        -1 if service group is busy,
435  *        -3 if called in an invalid API state
436  */
437 
438 int upwr_xcp_set_rtd_apd_llwu(soc_domain_t     domain,
439                         uint32_t enable,
440                         const upwr_callb callb);
441 /**
442  * upwr_xcp_shutdown() - Shuts down all uPower services and power mode tasks.
443  * @callb: pointer to the callback to be called when the uPower has finished
444  * the shutdown, or NULL if no callback needed
445  * (polling used instead).
446  *
447  * A callback can be optionally registered, and will be called upon the arrival
448  * of the request response from the uPower firmware, telling if it succeeded or
449  * not.
450  * A callback may not be registered (NULL pointer), in which case polling has
451  * to be used to check the response, by calling upwr_req_status or
452  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
453  *
454  * At the callback the uPower/API is back to initialization/start-up phase,
455  * so service request calls return error.
456  *
457  * Context: no sleep, no locks taken/released.
458  * Return: 0 if ok,
459  *        -1 if service group is busy,
460  *        -3 if called in an invalid API state
461  */
462 
463 int upwr_xcp_shutdown(const upwr_callb callb);
464 
465 /**
466  * upwr_xcp_i2c_access() - Performs an access through the uPower I2C interface.
467  * @addr: I2C slave address, up to 10 bits.
468  * @data_size: determines the access direction and data size in bytes, up to 4;
469  * negetive data_size determines a read  access with size -data_size;
470  * positive data_size determines a write access with size  data_size;
471  * data_size=0 is invalid, making the service return error UPWR_RESP_BAD_REQ.
472  * @subaddr_size: size of the sub-address in bytes, up to 4; if subaddr_size=0,
473  * no subaddress is used.
474  * @subaddr: sub-address, only used if subaddr_size > 0.
475  * @wdata: write data, up to 4 bytes; ignored if data_size < 0 (read)
476  * @callb: pointer to the callback to be called when the uPower has finished
477  * the access, or NULL if no callback needed
478  * (polling used instead).
479  *
480  * A callback can be optionally registered, and will be called upon the arrival
481  * of the request response from the uPower firmware, telling if it succeeded or
482  * not.
483  * A callback may not be registered (NULL pointer), in which case polling has
484  * to be used to check the response, by calling upwr_req_status or
485  * upwr_poll_req_status, using UPWR_SG_EXCEPT as the service group argument.
486  *
487  * The service performs a read (data_size < 0) or a write (data_size > 0) of
488  * up to 4 bytes on the uPower I2C interface. The data read from I2C comes via
489  * the callback argument ret, or written to the variable pointed by retptr,
490  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
491  * ret (or *retptr) also returns the data written on writes.
492  *
493  * Sub-addressing is supported, with sub-address size determined by the argument
494  * subaddr_size, up to 4 bytes. Sub-addressing is not used if subaddr_size=0.
495  *
496  * Context: no sleep, no locks taken/released.
497  * Return: 0 if ok,
498  *        -1 if service group is busy,
499  *        -3 if called in an invalid API state
500  */
501 
502 int upwr_xcp_i2c_access(uint16_t         addr,
503 			int8_t           data_size,
504 			uint8_t          subaddr_size,
505 			uint32_t         subaddr,
506 			uint32_t         wdata,
507 			const upwr_callb callb);
508 
509 
510 /**---------------------------------------------------------------
511  * POWER MANAGEMENT SERVICE GROUP
512  */
513 
514 /**
515  * upwr_pwm_dom_power_on() - Commands uPower to power on the platform of other
516  * domain (not necessarily its core(s)); does not release the core reset.
517  * @domain: identifier of the domain to power on. Defined by SoC-dependent type
518  * soc_domain_t found in upower_soc_defs.h.
519  * @boot_start: must be 1 to start the domain core(s) boot(s), releasing
520  * its (their) resets, or 0 otherwise.
521  * @pwroncallb: pointer to the callback to be called when the uPower has
522  * finished the power on procedure, or NULL if no callback needed
523  * (polling used instead).
524  *
525  * A callback can be optionally registered, and will be called upon the arrival
526  * of the request response from the uPower firmware, telling if it succeeded or
527  * not.
528  * A callback may not be registered (NULL pointer), in which case polling has
529  * to be used to check the response, by calling upwr_req_status or
530  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
531  *
532  * Context: no sleep, no locks taken/released.
533  * Return: 0 if ok,
534  *        -1 if service group is busy,
535  *        -2 if the domain passed is the same as the caller,
536  *        -3 if called in an invalid API state
537  */
538 
539 int upwr_pwm_dom_power_on(soc_domain_t      domain,
540                           int               boot_start,
541                           const upwr_callb  pwroncallb);
542 
543 /**
544  * upwr_pwm_boot_start() - Commands uPower to release the reset of other CPU(s),
545  * starting their boots.
546  * @domain: identifier of the domain to release the reset. Defined by
547  * SoC-dependent type soc_domain_t found in upower_soc_defs.h.
548  * @bootcallb: pointer to the callback to be called when the uPower has finished
549  * the boot start procedure, or NULL if no callback needed
550  * (polling used instead).
551  *
552  * A callback can be optionally registered, and will be called upon the arrival
553  * of the request response from the uPower firmware, telling if it succeeded or
554  * not.
555  * A callback may not be registered (NULL pointer), in which case polling has
556  * to be used to check the response, by calling upwr_req_status or
557  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
558  *
559  * The callback calling doesn't mean the CPUs boots have finished:
560  * it only indicates that uPower released the CPUs resets, and can receive
561  * other power management service group requests.
562  *
563  * Context: no sleep, no locks taken/released.
564  * Return: 0 if ok,
565  *        -1 if service group is busy,
566  *        -2 if the domain passed is the same as the caller,
567  *        -3 if called in an invalid API state
568  */
569 
570 int upwr_pwm_boot_start(soc_domain_t domain, const upwr_callb  bootcallb);
571 
572 /**
573  * upwr_pwm_param() - Changes Power Management parameters.
574  * @param: pointer to a parameter structure upwr_pwm_param_t, SoC-dependent,
575  * defined in upwr_soc_defines.h. NULL may be passed, meaning
576  * a request to read the parameter set, in which case it appears in the callback
577  * argument ret, or can be pointed by argument retptr in the upwr_req_status and
578  * upwr_poll_req_status calls, casted to upwr_pwm_param_t.
579  * @callb: response callback pointer; NULL if no callback needed.
580  *
581  * The return value is always the current parameter set value, either in a
582  * read-only request (param = NULL) or after setting a new parameter
583  * (non-NULL param).
584  *
585  * Some parameters may be targeted for a specific domain (see the struct
586  * upwr_pwm_param_t definition in upower_soc_defs.h); this call has implicit
587  * domain target (the same domain from which is called).
588  *
589  * A callback can be optionally registered, and will be called upon the arrival
590  * of the request response from the uPower firmware, telling if it succeeded or
591  * not.
592  * A callback may not be registered (NULL pointer), in which case polling has
593  * to be used to check the response, by calling upwr_req_status or
594  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
595  *
596  * Context: no sleep, no locks taken/released.
597  * Return: 0 if ok,
598  *        -1 if service group is busy,
599  *        -3 if called in an invalid API state
600  */
601 
602 int upwr_pwm_param(upwr_pwm_param_t* param, const upwr_callb  callb);
603 
604 /**
605  * upwr_pwm_chng_reg_voltage() - Changes the voltage at a given regulator.
606  * @reg: regulator id.
607  * @volt: voltage value; value unit is SoC-dependent, converted from mV by the
608  * macro UPWR_VOLT_MILIV, or from micro-Volts by the macro UPWR_VOLT_MICROV,
609  * both macros in upower_soc_defs.h
610  * @callb: response callback pointer; NULL if no callback needed.
611  *
612  * The function requests uPower to change the voltage of the given regulator.
613  * The request is executed if arguments are within range, with no protections
614  * regarding the adequate voltage value for the given domain process,
615  * temperature and frequency.
616  *
617  * A callback can be optionally registered, and will be called upon the arrival
618  * of the request response from the uPower firmware, telling if it succeeded
619  * or not.
620  *
621  * A callback may not be registered (NULL pointer), in which case polling has
622  * to be used to check the response, by calling upwr_req_status or
623  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
624  *
625  * Context: no sleep, no locks taken/released.
626  * Return: 0 if ok,
627  *        -1 if service group is busy,
628  *        -3 if called in an invalid API state
629  * Note that this is not the error response from the request itself:
630  * it only tells if the request was successfully sent to the uPower.
631  */
632 
633 int upwr_pwm_chng_reg_voltage(uint32_t reg, uint32_t volt, upwr_callb callb);
634 
635 /**
636  * upwr_pwm_freq_setup() - Determines the next frequency target for a given
637  *                         domain and current frequency.
638  * @domain: identifier of the domain to change frequency. Defined by
639  * SoC-dependent type soc_domain_t found in upower_soc_defs.h.
640  * @rail: the pmic regulator number for the target domain.
641  * @stage: DVA adjust stage
642  * refer to upower_defs.h "DVA adjust stage"
643  * @target_freq: the target adjust frequency, accurate to MHz
644  *
645  * refer to upower_defs.h structure definition upwr_pwm_freq_msg
646  *
647  * @callb: response callback pointer; NULL if no callback needed.
648  *
649  * The DVA algorithm is broken down into two phases.
650  * The first phase uses a look up table to get a safe operating voltage
651  * for the requested frequency.
652  * This voltage is guaranteed to work over process and temperature.
653  *
654  * The second step of the second phase is to measure the temperature
655  * using the uPower Temperature Sensor module.
656  * This is accomplished by doing a binary search of the TSEL bit field
657  * in the Temperature Measurement Register (TMR).
658  * The search is repeated until the THIGH bit fields in the same register change value.
659  * There are 3 temperature sensors in 8ULP (APD, AVD, and RTD).
660  *
661  *
662  * The second phase is the fine adjust of the voltage.
663  * This stage is entered only when the new frequency requested
664  * by application was already set as well as the voltage for that frequency.
665  * The first step of the fine adjust is to find what is the current margins
666  * for the monitored critical paths, or, in other words,
667  * how many delay cells will be necessary to generate a setup-timing violation.
668  * The function informs uPower that the given domain frequency has changed or
669  * will change to the given value. uPower firmware will then adjust voltage and
670  * bias to cope with the new frequency (if decreasing) or prepare for it
671  * (if increasing). The function must be called after decreasing the frequency,
672  * and before increasing it. The actual increase in frequency must not occur
673  * before the service returns its response.
674  *
675  * So, for increase clock frequency case, user need to call this API twice,
676  * the first stage gross adjust and the second stage fine adjust.
677  *
678  * for reduce clock frequency case, user can only call this API once,
679  * full stage (combine gross stage and fine adjust)
680  *
681  * The request is executed if arguments are within range.
682  *
683  * A callback can be optionally registered, and will be called upon the arrival
684  * of the request response from the uPower firmware, telling if it succeeded
685  * or not.
686  *
687  * A callback may not be registered (NULL pointer), in which case polling has
688  * to be used to check the response, by calling upwr_req_status or
689  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
690  *
691  * Context: no sleep, no locks taken/released.
692  * Return: 0 if ok,
693  *        -1 if service group is busy,
694  *        -3 if called in an invalid API state
695  * Note that this is not the error response from the request itself:
696  * it only tells if the request was successfully sent to the uPower.
697  */
698 int upwr_pwm_freq_setup(soc_domain_t domain, uint32_t rail, uint32_t stage, uint32_t target_freq, upwr_callb   callb);
699 
700 /**
701  * upwr_pwm_power_on()- Powers on (not off) one or more switches and ROM/RAMs.
702  * @swton: pointer to an array of words that tells which power switches to
703  *  turn on. Each word in the array has 1 bit for each switch.
704  *  A bit=1 means the respective switch must be turned on,
705  *  bit = 0 means it will stay unchanged (on or off).
706  *  The pointer may be set to NULL, in which case no switch will be changed,
707  *  unless a memory that it feeds must be turned on.
708  *  WARNING: swton must not point to the first shared memory address.
709  * @memon: pointer to an array of words that tells which memories to turn on.
710  *  Each word in the array has 1 bit for each switch.
711  *  A bit=1 means the respective memory must be turned on, both array and
712  *  periphery logic;
713  *  bit = 0 means it will stay unchanged (on or off).
714  *  The pointer may be set to NULL, in which case no memory will be changed.
715  *  WARNING: memon must not point to the first shared memory address.
716  * @callb: pointer to the callback called when configurations are applyed.
717  * NULL if no callback is required.
718  *
719  * The function requests uPower to turn on the PMC and memory array/peripheral
720  * switches that control their power, as specified above.
721  * The request is executed if arguments are within range, with no protections
722  * regarding the adequate memory power state related to overall system state.
723  *
724  * If a memory is requested to turn on, but the power switch that feeds that
725  * memory is not, the power switch will be turned on anyway, if the pwron
726  * array is not provided (that is, if pwron is NULL).
727  *
728  * A callback can be optionally registered, and will be called upon the arrival
729  * of the request response from the uPower firmware, telling if it succeeded
730  * or not.
731  *
732  * A callback may not be registered (NULL pointer), in which case polling has
733  * to be used to check the response, by calling upwr_req_status or
734  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
735  *
736  * Callback or polling may return error if the service contends for a resource
737  * already being used by a power mode transition or an ongoing service in
738  * another domain.
739  *
740  * Context: no sleep, no locks taken/released.
741  * Return: 0 if ok, -1 if service group is busy,
742  *        -2 if a pointer conversion to physical address failed,
743  *        -3 if called in an invalid API state.
744  * Note that this is not the error response from the request itself:
745  * it only tells if the request was successfully sent to the uPower.
746  */
747 
748 int upwr_pwm_power_on(const uint32_t swton[],
749 		      const uint32_t memon[],
750 		      upwr_callb     callb);
751 
752 /**
753  * upwr_pwm_power_off()- Powers off (not on) one or more switches and ROM/RAMs.
754  * @swtoff: pointer to an array of words that tells which power switches to
755  *  turn off. Each word in the array has 1 bit for each switch.
756  *  A bit=1 means the respective switch must be turned off,
757  *  bit = 0 means it will stay unchanged (on or off).
758  *  The pointer may be set to NULL, in which case no switch will be changed.
759  *  WARNING: swtoff must not point to the first shared memory address.
760  * @memoff: pointer to an array of words that tells which memories to turn off.
761  *  Each word in the array has 1 bit for each switch.
762  *  A bit=1 means the respective memory must be turned off, both array and
763  *  periphery logic;
764  *  bit = 0 means it will stay unchanged (on or off).
765  *  The pointer may be set to NULL, in which case no memory will be changed,
766  *  but notice it may be turned off if the switch that feeds it is powered off.
767  *  WARNING: memoff must not point to the first shared memory address.
768  * @callb: pointer to the callback called when configurations are applyed.
769  * NULL if no callback is required.
770  *
771  * The function requests uPower to turn off the PMC and memory array/peripheral
772  * switches that control their power, as specified above.
773  * The request is executed if arguments are within range, with no protections
774  * regarding the adequate memory power state related to overall system state.
775  *
776  * A callback can be optionally registered, and will be called upon the arrival
777  * of the request response from the uPower firmware, telling if it succeeded
778  * or not.
779  *
780  * A callback may not be registered (NULL pointer), in which case polling has
781  * to be used to check the response, by calling upwr_req_status or
782  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
783  *
784  * Callback or polling may return error if the service contends for a resource
785  * already being used by a power mode transition or an ongoing service in
786  * another domain.
787  *
788  * Context: no sleep, no locks taken/released.
789  * Return: 0 if ok, -1 if service group is busy,
790  *        -2 if a pointer conversion to physical address failed,
791  *        -3 if called in an invalid API state.
792  * Note that this is not the error response from the request itself:
793  * it only tells if the request was successfully sent to the uPower.
794  */
795 
796 int upwr_pwm_power_off(const uint32_t swtoff[],
797 		       const uint32_t memoff[],
798 		       upwr_callb     callb);
799 
800 /**
801  * upwr_pwm_mem_retain()- Configures one or more memory power switches to
802  * retain its contents, having the power array on, while its peripheral logic
803  * is turned off.
804  * @mem: pointer to an array of words that tells which memories to put in a
805  *  retention state. Each word in the array has 1 bit for each memory.
806  *  A bit=1 means the respective memory must be put in retention state,
807  *  bit = 0 means it will stay unchanged (retention, fully on or off).
808  * @callb: pointer to the callback called when configurations are applyed.
809  * NULL if no callback is required.
810  *
811  * The function requests uPower to turn off the memory peripheral and leave
812  * its array on, as specified above.
813  * The request is executed if arguments are within range.
814  *
815  * A callback can be optionally registered, and will be called upon the arrival
816  * of the request response from the uPower firmware, telling if it succeeded
817  * or not.
818  *
819  * A callback may not be registered (NULL pointer), in which case polling has
820  * to be used to check the response, by calling upwr_req_status or
821  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
822  *
823  * Callback or polling may return error if the service contends for a resource
824  * already being used by a power mode transition or an ongoing service in
825  * another domain.
826  *
827  * Context: no sleep, no locks taken/released.
828  * Return: 0 if ok, -1 if service group is busy,
829  *        -2 if a pointer conversion to physical address failed,
830  *        -3 if called in an invalid API state.
831  * Note that this is not the error response from the request itself:
832  * it only tells if the request was successfully sent to the uPower.
833  */
834 
835 int upwr_pwm_mem_retain(const uint32_t mem[], upwr_callb callb);
836 
837 /**
838  * upwr_pwm_chng_switch_mem() - Turns on/off power on one or more PMC switches
839  * and memories, including their array and peripheral logic.
840  * @swt: pointer to a list of PMC switches to be opened/closed.
841  *  The list is structured as an array of struct upwr_switch_board_t
842  *  (see upower_defs.h), each one containing a word for up to 32 switches,
843  *  one per bit. A bit = 1 means switch closed, bit = 0 means switch open.
844  *  struct upwr_switch_board_t also specifies a mask with 1 bit for each
845  *  respective switch: mask bit = 1 means the open/close action is applied,
846  *  mask bit = 0 means the switch stays unchanged.
847  *  The pointer may be set to NULL, in which case no switch will be changed,
848  *  unless a memory that it feeds must be turned on.
849  *  WARNING: swt must not point to the first shared memory address.
850  * @mem: pointer to a list of switches to be turned on/off.
851  *  The list is structured as an array of struct upwr_mem_switches_t
852  *  (see upower_defs.h), each one containing 2 word for up to 32 switches,
853  *  one per bit, one word for the RAM array power switch, other for the
854  *  RAM peripheral logic power switch. A bit = 1 means switch closed,
855  *  bit = 0 means switch open.
856  *  struct upwr_mem_switches_t also specifies a mask with 1 bit for each
857  *  respective switch: mask bit = 1 means the open/close action is applied,
858  *  mask bit = 0 means the switch stays unchanged.
859  *  The pointer may be set to NULL, in which case no memory switch will be
860  *  changed, but notice it may be turned off if the switch that feeds it is
861  *  powered off.
862  *  WARNING: mem must not point to the first shared memory address.
863  * @callb: pointer to the callback called when the configurations are applied.
864  * NULL if no callback is required.
865  *
866  * The function requests uPower to change the PMC switches and/or memory power
867  * as specified above.
868  * The request is executed if arguments are within range, with no protections
869  * regarding the adequate switch combinations and overall system state.
870  *
871  * If a memory is requested to turn on, but the power switch that feeds that
872  * memory is not, the power switch will be turned on anyway, if the swt
873  * array is not provided (that is, if swt is NULL).
874  *
875  * A callback can be optionally registered, and will be called upon the arrival
876  * of the request response from the uPower firmware, telling if it succeeded
877  * or not.
878  *
879  * A callback may not be registered (NULL pointer), in which case polling has
880  * to be used to check the response, by calling upwr_req_status or
881  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
882  *
883  * Callback or polling may return error if the service contends for a resource
884  * already being used by a power mode transition or an ongoing service in
885  * another domain.
886  *
887  * Context: no sleep, no locks taken/released.
888  * Return: 0 if ok, -1 if service group is busy.
889  *        -2 if a pointer conversion to physical address failed,
890  *        -3 if called in an invalid API state.
891  * Note that this is not the error response from the request itself:
892  * it only tells if the request was successfully sent to the uPower.
893  */
894 
895 int upwr_pwm_chng_switch_mem(const struct upwr_switch_board_t  swt[],
896 			     const struct upwr_mem_switches_t  mem[],
897 			     upwr_callb                        callb);
898 
899 /**
900  * upwr_pwm_pmode_config() - Configures a given power mode in a given domain.
901  * @domain: identifier of the domain to which the power mode belongs.
902  * Defined by SoC-dependent type soc_domain_t found in upower_soc_defs.h.
903  * @pmode: SoC-dependent power mode identifier defined by type abs_pwr_mode_t
904  * found in upower_soc_defs.h.
905  * @config: pointer to an SoC-dependent struct defining the power mode
906  * configuration, found in upower_soc_defs.h.
907  * @callb: pointer to the callback called when configurations are applied.
908  * NULL if no callback is required.
909  *
910  * The function requests uPower to change the power mode configuration as
911  * specified above. The request is executed if arguments are within range,
912  * and complies with SoC-dependent restrictions on value combinations.
913  *
914  * A callback can be optionally registered, and will be called upon the arrival
915  * of the request response from the uPower firmware, telling if it succeeded
916  * or not.
917  *
918  * A callback may not be registered (NULL pointer), in which case polling has
919  * to be used to check the response, by calling upwr_req_status or
920  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
921  *
922  * Context: no sleep, no locks taken/released.
923  * Return: 0 if ok, -1 if service group is busy,
924  *        -2 if the pointer conversion to physical address failed,
925  *        -3 if called in an invalid API state.
926  * Note that this is not the error response from the request itself:
927  * it only tells if the request was successfully sent to the uPower.
928  */
929 
930 int upwr_pwm_pmode_config(soc_domain_t   domain,
931 			  abs_pwr_mode_t pmode,
932 			  const void*    config,
933 			  upwr_callb     callb);
934 
935 
936 
937 /**
938  * upwr_pwm_reg_config() - Configures the uPower internal regulators.
939  * @config: pointer to the struct defining the regulator configuration;
940  * the struct upwr_reg_config_t is defined in the file upower_defs.h.
941  * @callb: pointer to the callback called when configurations are applied.
942  * NULL if no callback is required.
943  *
944  * The function requests uPower to change/define the configurations of the
945  * internal regulators.
946  *
947  * A callback can be optionally registered, and will be called upon the arrival
948  * of the request response from the uPower firmware, telling if it succeeded
949  * or not.
950  *
951  * A callback may not be registered (NULL pointer), in which case polling has
952  * to be used to check the response, by calling upwr_req_status or
953  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
954  *
955  * The service may fail with error UPWR_RESP_RESOURCE if a power mode transition
956  * or the same service (called from another domain) is executing simultaneously.
957  * This error should be interpreted as a "try later" response, as the service
958  * will succeed once those concurrent executions are done, and no other is
959  * started.
960  *
961  * Context: no sleep, no locks taken/released.
962  * Return: 0 if ok, -1 if service group is busy,
963  *        -2 if the pointer conversion to physical address failed,
964  *        -3 if called in an invalid API state.
965  * Note that this is not the error response from the request itself:
966  * it only tells if the request was successfully sent to the uPower.
967  */
968 
969 int upwr_pwm_reg_config(const struct upwr_reg_config_t* config,
970 			upwr_callb   callb);
971 
972 /**
973  * upwr_pwm_chng_dom_bias() - Changes the domain bias.
974  * @bias: pointer to a domain bias configuration struct (see upower_soc_defs.h).
975  * @callb: pointer to the callback called when configurations are applied.
976  * NULL if no callback is required.
977  *
978  * The function requests uPower to change the domain bias configuration as
979  * specified above. The request is executed if arguments are within range,
980  * with no protections regarding the adequate value combinations and
981  * overall system state.
982  *
983  * A callback can be optionally registered, and will be called upon the arrival
984  * of the request response from the uPower firmware, telling if it succeeded
985  * or not.
986  *
987  * A callback may not be registered (NULL pointer), in which case polling has
988  * to be used to check the response, by calling upwr_req_status or
989  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
990  *
991  * Context: no sleep, no locks taken/released.
992  * Return: 0 if ok, -1 if service group is busy,
993  *        -3 if called in an invalid API state.
994  * Note that this is not the error response from the request itself:
995  * it only tells if the request was successfully sent to the uPower.
996  */
997 
998 int upwr_pwm_chng_dom_bias(const struct upwr_dom_bias_cfg_t* bias,
999 			   upwr_callb                        callb);
1000 
1001 /**
1002  * upwr_pwm_chng_mem_bias()- Changes a ROM/RAM power bias.
1003  * @domain: identifier of the domain upon which the bias is applied.
1004  * Defined by SoC-dependent type soc_domain_t found in upower_soc_defs.h.
1005  * @bias: pointer to a memory bias configuration struct (see upower_soc_defs.h).
1006  * @callb: pointer to the callback called when configurations are applied.
1007  * NULL if no callback is required.
1008  *
1009  * The function requests uPower to change the memory bias configuration as
1010  * specified above. The request is executed if arguments are within range,
1011  * with no protections regarding the adequate value combinations and
1012  * overall system state.
1013  *
1014  * A callback can be optionally registered, and will be called upon the arrival
1015  * of the request response from the uPower firmware, telling if it succeeded
1016  * or not.
1017  *
1018  * A callback may not be registered (NULL pointer), in which case polling has
1019  * to be used to check the response, by calling upwr_req_status or
1020  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
1021  *
1022  * Context: no sleep, no locks taken/released.
1023  * Return: 0 if ok, -1 if service group is busy,
1024  *        -3 if called in an invalid API state.
1025  * Note that this is not the error response from the request itself:
1026  * it only tells if the request was successfully sent to the uPower.
1027  */
1028 
1029 int upwr_pwm_chng_mem_bias(soc_domain_t                      domain,
1030 			   const struct upwr_mem_bias_cfg_t* bias,
1031 			   upwr_callb                        callb);
1032 
1033 /**---------------------------------------------------------------
1034  * VOLTAGE MANAGEMENT SERVICE GROUP
1035  */
1036 
1037 /**
1038  * upwr_vtm_pmic_cold_reset() -request cold reset the pmic
1039  * pmic will power cycle all the regulators
1040  * @callb: response callback pointer; NULL if no callback needed.
1041  *
1042  * The function requests uPower to cold reset the pmic.
1043  * The request is executed if arguments are within range, with no protections
1044  * regarding the adequate voltage value for the given domain process,
1045  * temperature and frequency.
1046  *
1047  * A callback can be optionally registered, and will be called upon the arrival
1048  * of the request response from the uPower firmware, telling if it succeeded
1049  * or not.
1050  *
1051  * A callback may not be registered (NULL pointer), in which case polling has
1052  * to be used to check the response, by calling upwr_req_status or
1053  * upwr_poll_req_status, using UPWR_SG_VOLTM as the service group argument.
1054  *
1055  * Context: no sleep, no locks taken/released.
1056  * Return: 0 if ok,
1057  *        -1 if service group is busy,
1058  *        -3 if called in an invalid API state
1059  * Note that this is not the error response from the request itself:
1060  * it only tells if the request was successfully sent to the uPower.
1061  */
1062 int upwr_vtm_pmic_cold_reset(upwr_callb callb);
1063 
1064 /**
1065  * upwr_vtm_set_pmic_mode() -request uPower set pmic mode
1066  * @pmic_mode: the target mode need to be set
1067  * @callb: response callback pointer; NULL if no callback needed.
1068  *
1069  * The function requests uPower to set pmic mode
1070  * The request is executed if arguments are within range, with no protections
1071  * regarding the adequate voltage value for the given domain process,
1072  * temperature and frequency.
1073  *
1074  * A callback can be optionally registered, and will be called upon the arrival
1075  * of the request response from the uPower firmware, telling if it succeeded
1076  * or not.
1077  *
1078  * A callback may not be registered (NULL pointer), in which case polling has
1079  * to be used to check the response, by calling upwr_req_status or
1080  * upwr_poll_req_status, using UPWR_SG_VOLTM as the service group argument.
1081  *
1082  * Context: no sleep, no locks taken/released.
1083  * Return: 0 if ok,
1084  *        -1 if service group is busy,
1085  *        -3 if called in an invalid API state
1086  * Note that this is not the error response from the request itself:
1087  * it only tells if the request was successfully sent to the uPower.
1088  */
1089 int upwr_vtm_set_pmic_mode(uint32_t pmic_mode, upwr_callb callb);
1090 
1091 /**
1092  * upwr_vtm_chng_pmic_voltage() - Changes the voltage of a given rail.
1093  * @rail: pmic rail id.
1094  * @volt: the target voltage of the given rail, accurate to uV
1095  * If pass volt value 0, means that power off this rail.
1096  * @callb: response callback pointer; NULL if no callback needed.
1097  *
1098  * The function requests uPower to change the voltage of the given rail.
1099  * The request is executed if arguments are within range, with no protections
1100  * regarding the adequate voltage value for the given domain process,
1101  * temperature and frequency.
1102  *
1103  * A callback can be optionally registered, and will be called upon the arrival
1104  * of the request response from the uPower firmware, telling if it succeeded
1105  * or not.
1106  *
1107  * A callback may not be registered (NULL pointer), in which case polling has
1108  * to be used to check the response, by calling upwr_req_status or
1109  * upwr_poll_req_status, using UPWR_SG_VOLTM as the service group argument.
1110  *
1111  * Context: no sleep, no locks taken/released.
1112  * Return: 0 if ok,
1113  *        -1 if service group is busy,
1114  *        -3 if called in an invalid API state
1115  * Note that this is not the error response from the request itself:
1116  * it only tells if the request was successfully sent to the uPower.
1117  */
1118 
1119 int upwr_vtm_chng_pmic_voltage(uint32_t rail, uint32_t volt, upwr_callb callb);
1120 
1121 /**
1122  * upwr_vtm_get_pmic_voltage() - Get the voltage of a given ral.
1123  * @rail: pmic rail id.
1124  * @callb: response callback pointer; NULL if no callback needed.
1125  * (polling used instead)
1126  *
1127  * The function requests uPower to get the voltage of the given rail.
1128  * The request is executed if arguments are within range, with no protections
1129  * regarding the adequate voltage value for the given domain process,
1130  * temperature and frequency.
1131  *
1132  * A callback can be optionally registered, and will be called upon the arrival
1133  * of the request response from the uPower firmware, telling if it succeeded
1134  * or not.
1135  *
1136  * A callback may not be registered (NULL pointer), in which case polling has
1137  * to be used to check the response, by calling upwr_req_status or
1138  * upwr_poll_req_status, using UPWR_SG_VOLTM as the service group argument.
1139  *
1140  * The voltage data read from uPower via
1141  * the callback argument ret, or written to the variable pointed by retptr,
1142  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1143  * ret (or *retptr) also returns the data written on writes.
1144  *
1145  * Context: no sleep, no locks taken/released.
1146  * Return: 0 if ok,
1147  *        -1 if service group is busy,
1148  *        -3 if called in an invalid API state
1149  * Note that this is not the error response from the request itself:
1150  * it only tells if the request was successfully sent to the uPower.
1151  */
1152 
1153 int upwr_vtm_get_pmic_voltage(uint32_t rail, upwr_callb callb);
1154 
1155 
1156 /**
1157  * upwr_vtm_power_measure() - request uPower to measure power consumption
1158  * @ssel: This field determines which power switches will have their currents sampled to be accounted for a
1159 current/power measurement. Support 0~7
1160 
1161 SSEL bit #	Power Switch
1162 0	M33 core complex/platform/peripherals
1163 1	Fusion Core and Peripherals
1164 2	A35[0] core complex
1165 3	A35[1] core complex
1166 4	3DGPU
1167 5	HiFi4
1168 6	DDR Controller (PHY and PLL NOT included)
1169 7	PXP, EPDC
1170 
1171  * @callb: response callback pointer; NULL if no callback needed.
1172  * (polling used instead)
1173  *
1174  * The function requests uPower to measure power consumption
1175  * The request is executed if arguments are within range, with no protections
1176  * regarding the adequate voltage value for the given domain process,
1177  * temperature and frequency.
1178  *
1179  * A callback can be optionally registered, and will be called upon the arrival
1180  * of the request response from the uPower firmware, telling if it succeeded
1181  * or not.
1182  *
1183  * A callback may not be registered (NULL pointer), in which case polling has
1184  * to be used to check the response, by calling upwr_req_status or
1185  * upwr_poll_req_status, using UPWR_SG_VOLTM as the service group argument.
1186  *
1187  * The power consumption data read from uPower via
1188  * the callback argument ret, or written to the variable pointed by retptr,
1189  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1190  * ret (or *retptr) also returns the data written on writes.
1191  * upower fw needs support cocurrent request from M33 and A35.
1192  *
1193  * Accurate to uA
1194  *
1195  * Context: no sleep, no locks taken/released.
1196  * Return: 0 if ok,
1197  *        -1 if service group is busy,
1198  *        -3 if called in an invalid API state
1199  * Note that this is not the error response from the request itself:
1200  * it only tells if the request was successfully sent to the uPower.
1201  */
1202 int upwr_vtm_power_measure(uint32_t ssel, upwr_callb callb);
1203 
1204 /**
1205  * upwr_vtm_vmeter_measure() - request uPower to measure voltage
1206  * @vdetsel: Voltage Detector Selector, support 0~3
1207  * 00b - RTD sense point
1208    01b - LDO output
1209    10b - APD domain sense point
1210    11b - AVD domain sense point
1211    Refer to upower_defs.h
1212  * @callb: response callback pointer; NULL if no callback needed.
1213  * (polling used instead)
1214  *
1215  * The function requests uPower to use vmeter to measure voltage
1216  * The request is executed if arguments are within range, with no protections
1217  * regarding the adequate voltage value for the given domain process,
1218  * temperature and frequency.
1219  *
1220  * A callback can be optionally registered, and will be called upon the arrival
1221  * of the request response from the uPower firmware, telling if it succeeded
1222  * or not.
1223  *
1224  * A callback may not be registered (NULL pointer), in which case polling has
1225  * to be used to check the response, by calling upwr_req_status or
1226  * upwr_poll_req_status, using UPWR_SG_VOLTM as the service group argument.
1227  *
1228  * The voltage data read from uPower via
1229  * the callback argument ret, or written to the variable pointed by retptr,
1230  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1231  * ret (or *retptr) also returns the data written on writes.
1232  * upower fw needs support cocurrent request from M33 and A35.
1233  *
1234  * Refer to RM COREREGVL (Core Regulator Voltage Level)
1235  * uPower return VDETLVL to user, user can calculate the real voltage:
1236  *
1237 0b000000(0x00) - 0.595833V
1238 0b100110(0x26) - 1.007498V
1239 <value> - 0.595833V + <value>x10.8333mV
1240 0b110010(0x32) - 1.138V
1241  *
1242  * Context: no sleep, no locks taken/released.
1243  * Return: 0 if ok,
1244  *        -1 if service group is busy,
1245  *        -3 if called in an invalid API state
1246  * Note that this is not the error response from the request itself:
1247  * it only tells if the request was successfully sent to the uPower.
1248  */
1249 int upwr_vtm_vmeter_measure(uint32_t vdetsel, upwr_callb callb);
1250 
1251 /**
1252  * upwr_vtm_pmic_config() - Configures the SoC PMIC (Power Management IC).
1253  * @config: pointer to a PMIC-dependent struct defining the PMIC configuration.
1254  * @size:   size of the struct pointed by config, in bytes.
1255  * @callb: pointer to the callback called when configurations are applied.
1256  * NULL if no callback is required.
1257  *
1258  * The function requests uPower to change/define the PMIC configuration.
1259  *
1260  * A callback can be optionally registered, and will be called upon the arrival
1261  * of the request response from the uPower firmware, telling if it succeeded
1262  * or not.
1263  *
1264  * A callback may not be registered (NULL pointer), in which case polling has
1265  * to be used to check the response, by calling upwr_req_status or
1266  * upwr_poll_req_status, using UPWR_SG_PWRMGMT as the service group argument.
1267  *
1268  * Context: no sleep, no locks taken/released.
1269  * Return: 0 if ok, -1 if service group is busy,
1270  *        -2 if the pointer conversion to physical address failed,
1271  *        -3 if called in an invalid API state.
1272  * Note that this is not the error response from the request itself:
1273  * it only tells if the request was successfully sent to the uPower.
1274  *
1275  * Sample code:
1276 
1277 The tag value is fixed 0x706D6963, used by uPower PMIC driver to judge if the config data are valid.
1278 #define PMIC_CONFIG_TAG 0x706D6963
1279 
1280 used to define reg_addr_data_arry, user can modify this value
1281 or you can use variable-length array
1282 or zero-length array
1283 or other C language technology skills
1284 #define PMIC_CONFIG_REG_ARRAY_SIZE  8
1285 
1286 struct pmic_reg_addr_data
1287 {
1288     uint32_t reg;
1289     uint32_t data;
1290 };
1291 
1292 struct pmic_config_struct
1293 {
1294     uint32_t cfg_tag;
1295     uint32_t cfg_reg_size;
1296     struct pmic_reg_addr_data reg_addr_data_array[PMIC_CONFIG_REG_ARRAY_SIZE];
1297 };
1298 
1299 
1300     struct pmic_config_struct pmic_config_struct_data;
1301     pmic_config_struct_data.cfg_tag = PMIC_CONFIG_TAG;
1302     pmic_config_struct_data.cfg_reg_size = 3;
1303 
1304     pmic_config_struct_data.reg_addr_data_array[0].reg = 0x31 ;
1305     pmic_config_struct_data.reg_addr_data_array[0].data = 0x83;
1306     pmic_config_struct_data.reg_addr_data_array[1].reg = 0x36;
1307     pmic_config_struct_data.reg_addr_data_array[1].data = 0x03;
1308     pmic_config_struct_data.reg_addr_data_array[2].reg = 0x38;
1309     pmic_config_struct_data.reg_addr_data_array[2].data = 0x03;
1310 
1311     int size = sizeof(pmic_config_struct_data.cfg_tag) +
1312                 sizeof(pmic_config_struct_data.cfg_reg_size) +
1313                 pmic_config_struct_data.cfg_reg_size *  (sizeof(uint32_t) + sizeof(uint32_t));
1314 
1315     upower_pwm_chng_pmic_config((void *)&pmic_config_struct_data, size);
1316 
1317 
1318 
1319  *
1320  * Please must notice that, it will take very long time to finish,
1321  * beause it will send many I2C commands to pmic chip.
1322  */
1323 int upwr_vtm_pmic_config(const void* config, uint32_t size, upwr_callb callb);
1324 
1325 /**---------------------------------------------------------------
1326  * TEMPERATURE MANAGEMENT SERVICE GROUP
1327  */
1328 
1329 /**
1330  * upwr_tpm_get_temperature() - request uPower to get temperature of one temperature sensor
1331  * @sensor_id: temperature sensor ID, support 0~2
1332  * @callb: response callback pointer; NULL if no callback needed.
1333  * (polling used instead)
1334  *
1335  * The function requests uPower to measure temperature
1336  * The request is executed if arguments are within range, with no protections
1337  * regarding the adequate voltage value for the given domain process,
1338  * temperature and frequency.
1339  *
1340  * A callback can be optionally registered, and will be called upon the arrival
1341  * of the request response from the uPower firmware, telling if it succeeded
1342  * or not.
1343  *
1344  * A callback may not be registered (NULL pointer), in which case polling has
1345  * to be used to check the response, by calling upwr_req_status or
1346  * upwr_poll_req_status, using UPWR_SG_TEMPM as the service group argument.
1347  *
1348  * The temperature data read from uPower via
1349  * the callback argument ret, or written to the variable pointed by retptr,
1350  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1351  * ret (or *retptr) also returns the data written on writes.
1352  *
1353  * uPower return TSEL to the caller (M33 or A35), caller calculate the real temperature
1354  * Tsh = 0.000002673049*TSEL[7:0]^3 + 0.0003734262*TSEL[7:0]^2 +
1355 0.4487042*TSEL[7:0] - 46.98694
1356  *
1357  * upower fw needs support cocurrent request from M33 and A35.
1358  *
1359  * Context: no sleep, no locks taken/released.
1360  * Return: 0 if ok,
1361  *        -1 if service group is busy,
1362  *        -3 if called in an invalid API state
1363  * Note that this is not the error response from the request itself:
1364  * it only tells if the request was successfully sent to the uPower.
1365  */
1366 int upwr_tpm_get_temperature(uint32_t sensor_id, upwr_callb callb);
1367 
1368 /**---------------------------------------------------------------
1369  * DELAY MANAGEMENT SERVICE GROUP
1370  */
1371 
1372 /**
1373  * upwr_dlm_get_delay_margin() - request uPower to get delay margin
1374  * @path: The critical path
1375  * @index: Use whitch delay meter
1376  * @callb: response callback pointer; NULL if no callback needed.
1377  * (polling used instead)
1378  *
1379  * The function requests uPower to get delay margin
1380  * The request is executed if arguments are within range, with no protections
1381  * regarding the adequate voltage value for the given domain process,
1382  * temperature and frequency.
1383  *
1384  * A callback can be optionally registered, and will be called upon the arrival
1385  * of the request response from the uPower firmware, telling if it succeeded
1386  * or not.
1387  *
1388  * A callback may not be registered (NULL pointer), in which case polling has
1389  * to be used to check the response, by calling upwr_req_status or
1390  * upwr_poll_req_status, using UPWR_SG_DELAYM as the service group argument.
1391  *
1392  * The delay margin data read from uPower via
1393  * the callback argument ret, or written to the variable pointed by retptr,
1394  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1395  * ret (or *retptr) also returns the data written on writes.
1396  * upower fw needs support cocurrent request from M33 and A35.
1397  *
1398  * Context: no sleep, no locks taken/released.
1399  * Return: 0 if ok,
1400  *        -1 if service group is busy,
1401  *        -3 if called in an invalid API state
1402  * Note that this is not the error response from the request itself:
1403  * it only tells if the request was successfully sent to the uPower.
1404  */
1405 int upwr_dlm_get_delay_margin(uint32_t path, uint32_t index, upwr_callb callb);
1406 
1407 /**
1408  * upwr_dlm_set_delay_margin() - request uPower to set delay margin
1409  * @path: The critical path
1410  * @index: Use whitch delay meter
1411  * @delay_margin: the value of delay margin
1412  * @callb: response callback pointer; NULL if no callback needed.
1413  * (polling used instead)
1414  *
1415  * The function requests uPower to set delay margin
1416  * The request is executed if arguments are within range, with no protections
1417  * regarding the adequate voltage value for the given domain process,
1418  * temperature and frequency.
1419  *
1420  * A callback can be optionally registered, and will be called upon the arrival
1421  * of the request response from the uPower firmware, telling if it succeeded
1422  * or not.
1423  *
1424  * A callback may not be registered (NULL pointer), in which case polling has
1425  * to be used to check the response, by calling upwr_req_status or
1426  * upwr_poll_req_status, using UPWR_SG_DELAYM as the service group argument.
1427  *
1428  * The result of the corresponding critical path,  failed or not  read from uPower via
1429  * the callback argument ret, or written to the variable pointed by retptr,
1430  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1431  * ret (or *retptr) also returns the data written on writes.
1432  * upower fw needs support cocurrent request from M33 and A35.
1433  *
1434  * Context: no sleep, no locks taken/released.
1435  * Return: 0 if ok,
1436  *        -1 if service group is busy,
1437  *        -3 if called in an invalid API state
1438  * Note that this is not the error response from the request itself:
1439  * it only tells if the request was successfully sent to the uPower.
1440  */
1441 int upwr_dlm_set_delay_margin(uint32_t path, uint32_t index, uint32_t delay_margin, upwr_callb callb);
1442 
1443 /**
1444  * upwr_dlm_process_monitor() - request uPower to do process monitor
1445  * @chain_sel: Chain Cell Type Selection
1446  * Select the chain to be used for the clock signal generation.
1447  * Support two types chain cell, 0~1
1448 0b - P4 type delay cells selected
1449 1b - P16 type delay cells selected
1450  * @callb: response callback pointer; NULL if no callback needed.
1451  * (polling used instead)
1452  *
1453  * The function requests uPower to do process monitor
1454  * The request is executed if arguments are within range, with no protections
1455  * regarding the adequate voltage value for the given domain process,
1456  * temperature and frequency.
1457  *
1458  * A callback can be optionally registered, and will be called upon the arrival
1459  * of the request response from the uPower firmware, telling if it succeeded
1460  * or not.
1461  *
1462  * A callback may not be registered (NULL pointer), in which case polling has
1463  * to be used to check the response, by calling upwr_req_status or
1464  * upwr_poll_req_status, using UPWR_SG_DELAYM as the service group argument.
1465  *
1466  * The result of process monitor,  failed or not  read from uPower via
1467  * the callback argument ret, or written to the variable pointed by retptr,
1468  * if polling is used (calls upwr_req_status or upwr_poll_req_status).
1469  * ret (or *retptr) also returns the data written on writes.
1470  * upower fw needs support cocurrent request from M33 and A35.
1471  *
1472  * Context: no sleep, no locks taken/released.
1473  * Return: 0 if ok,
1474  *        -1 if service group is busy,
1475  *        -3 if called in an invalid API state
1476  * Note that this is not the error response from the request itself:
1477  * it only tells if the request was successfully sent to the uPower.
1478  */
1479 int upwr_dlm_process_monitor(uint32_t chain_sel, upwr_callb callb);
1480 
1481 /**---------------------------------------------------------------
1482  * DIAGNOSE SERVICE GROUP
1483  */
1484 
1485 /**
1486  * upwr_dgn_mode() - Sets the diagnostic mode.
1487  * @mode:  diagnostic mode, which can be:
1488  *  - UPWR_DGN_NONE:   no diagnostic recorded
1489  *  - UPWR_DGN_TRACE:  warnings, errors, service, internal activity recorded
1490  *  - UPWR_DGN_SRVREQ: warnings, errors, service activity recorded
1491  *  - UPWR_DGN_WARN:   warnings and errors recorded
1492  *  - UPWR_DGN_ALL:    trace, service, warnings, errors, task state recorded
1493  *  - UPWR_DGN_ERROR:  only errors recorded
1494  *  - UPWR_DGN_ALL2ERR: record all until an error occurs,
1495  *    freeze recording on error
1496  *  - UPWR_DGN_ALL2HLT: record all until an error occurs,
1497  *    executes an ebreak on error, which halts the core if enabled through
1498  *    the debug interface
1499  * @callb: pointer to the callback called when mode is changed.
1500  * NULL if no callback is required.
1501  *
1502  * Context: no sleep, no locks taken/released.
1503  * Return: 0 if ok,
1504  *        -1 if service group is busy,
1505  *        -3 if called in an invalid API state
1506  */
1507 
1508 int upwr_dgn_mode(upwr_dgn_mode_t mode, const upwr_callb callb);
1509 
1510 /**---------------------------------------------------------------
1511  * AUXILIARY CALLS
1512  */
1513 
1514 /**
1515  * upwr_rom_version() - informs the ROM firwmware version.
1516  * @vmajor: pointer to the variable to get the firmware major version number.
1517  * @vminor: pointer to the variable to get the firmware minor version number.
1518  * @vfixes: pointer to the variable to get the firmware fixes number.
1519  *
1520  * Context: no sleep, no locks taken/released.
1521  * Return: SoC id.
1522  */
1523 
1524 uint32_t upwr_rom_version(uint32_t *vmajor, uint32_t *vminor, uint32_t *vfixes);
1525 
1526 /**
1527  * upwr_ram_version() - informs the RAM firwmware version.
1528  * @vminor: pointer to the variable to get the firmware minor version number.
1529  * @vfixes: pointer to the variable to get the firmware fixes number.
1530  *
1531  * The 3 values returned are 0 if no RAM firmwmare was loaded and initialized.
1532  *
1533  * Context: no sleep, no locks taken/released.
1534  * Return: firmware major version number.
1535  */
1536 
1537 uint32_t upwr_ram_version(uint32_t* vminor, uint32_t *vfixes);
1538 
1539 /**
1540  * upwr_req_status() - tells the status of the service group request, and
1541  *                     returns a request return value, if any.
1542  * @sg: service group of the request
1543  * @sgfptr: pointer to the variable that will hold the function id of
1544  * the last request completed; can be NULL, in which case it is not used.
1545  * @errptr: pointer to the variable that will hold the error code;
1546  * can be NULL, in which case it is not used.
1547  * @retptr: pointer to the variable that will hold the value returned
1548  * by the last request completed (invalid if the last request completed didn't
1549  * return any value); can be NULL, in which case it is not used.
1550  * Note that a request may return a value even if service error is returned
1551  * (*errptr != UPWR_RESP_OK): that is dependent on the specific service.
1552  *
1553  * This call can be used in a poll loop of a service request completion in case
1554  * a callback was not registered.
1555  *
1556  * Context: no sleep, no locks taken/released.
1557  * Return: service request status: succeeded, failed, or ongoing (busy)
1558  */
1559 
1560 /* service request status */
1561 
1562 typedef enum {
1563 	UPWR_REQ_OK,     /* request succeeded */
1564 	UPWR_REQ_ERR,    /* request failed */
1565 	UPWR_REQ_BUSY    /* request execution ongoing */
1566 } upwr_req_status_t;
1567 
1568 upwr_req_status_t upwr_req_status(upwr_sg_t     sg,
1569 				  uint32_t*     sgfptr,
1570 				  upwr_resp_t*  errptr,
1571 				  int*          retptr);
1572 
1573 /**
1574  * upwr_poll_req_status() - polls the status of the service group request, and
1575  *                          returns a request return value, if any.
1576  * @sg: service group of the request
1577  * @sgfptr: pointer to the variable that will hold the function id of
1578  * the last request completed; can be NULL, in which case it is not used.
1579  * @errptr: pointer to the variable that will hold the error code;
1580  * can be NULL, in which case it is not used.
1581  * @retptr: pointer to the variable that will hold the value returned
1582  * by the last request completed (invalid if the last request completed didn't
1583  * return any value); can be NULL, in which case it is not used.
1584  * Note that a request may return a value even if service error is returned
1585  * (*errptr != UPWR_RESP_OK): that is dependent on the specific service.
1586  * @attempts: maximum number of polling attempts; if attempts > 0 and is
1587  * reached with no service response received, upwr_poll_req_status returns
1588  * UPWR_REQ_BUSY and variables pointed by sgfptr, retptr and errptr are not
1589  * updated; if attempts = 0, upwr_poll_req_status waits "forever".
1590  *
1591  * This call can be used to poll a service request completion in case a
1592  * callback was not registered.
1593  *
1594  * Context: no sleep, no locks taken/released.
1595  * Return: service request status: succeeded, failed, or ongoing (busy)
1596  */
1597 
1598 upwr_req_status_t upwr_poll_req_status(upwr_sg_t     sg,
1599 				       uint32_t*     sgfptr,
1600 				       upwr_resp_t*  errptr,
1601 				       int*          retptr,
1602 				       uint32_t      attempts);
1603 
1604 /**
1605  * upwr_alarm_code() - returns the alarm code of the last alarm occurrence.
1606  *
1607  * The value returned is not meaningful if no alarm was issued by uPower.
1608  *
1609  * Context: no sleep, no locks taken/released.
1610  * Return: alarm code, as defined by the type upwr_alarm_t in upwr_soc_defines.h
1611  */
1612 
1613 upwr_alarm_t upwr_alarm_code(void);
1614 
1615 /**---------------------------------------------------------------
1616  * TRANSMIT/RECEIVE PRIMITIVES
1617  * ---------------------------------------------------------------
1618  */
1619 
1620 typedef void (*UPWR_TX_CALLB_FUNC_T)(void);
1621 typedef void (*UPWR_RX_CALLB_FUNC_T)(void);
1622 
1623 /**
1624  * upwr_tx() - queues a message for transmission.
1625  * @msg : pointer to the message sent.
1626  * @size: message size in 32-bit words
1627  * @callback: pointer to a function to be called when transmission done;
1628  *            can be NULL, in which case no callback is done.
1629  *
1630  * This is an auxiliary function used by the rest of the API calls.
1631  * It is normally not called by the driver code, unless maybe for test purposes.
1632  *
1633  * Context: no sleep, no locks taken/released.
1634  * Return: number of vacant positions left in the trasmission queue, or
1635  *         -1 if the queue was already full when upwr_tx was called, or
1636  *         -2 if any argument is invalid (like size off-range)
1637  */
1638 
1639 int upwr_tx(const uint32_t*         msg,
1640             unsigned int            size,
1641             UPWR_TX_CALLB_FUNC_T    callback);
1642 
1643 /**
1644  * upwr_rx() - unqueues a received message from the reception queue.
1645  * @msg: pointer to the message destination buffer.
1646  * @size: pointer to variable to hold message size in 32-bit words.
1647  *
1648  * This is an auxiliary function used by the rest of the API calls.
1649  * It is normally not called by the driver code, unless maybe for test purposes.
1650  *
1651  * Context: no sleep, no locks taken/released.
1652  * Return: number of messages remaining in the reception queue, or
1653  *         -1 if the queue was already empty when upwr_rx was called, or
1654  *         -2 if any argument is invalid (like mu off-range)
1655  */
1656 
1657 int upwr_rx(char *msg, unsigned int *size);
1658 
1659 /**
1660  * upwr_rx_callback() - sets up a callback for a message receiving event.
1661  * @callback: pointer to a function to be called when a message arrives;
1662  *            can be NULL, in which case no callback is done.
1663  *
1664  * This is an auxiliary function used by the rest of the API calls.
1665  * It is normally not called by the driver code, unless maybe for test purposes.
1666  *
1667  * Context: no sleep, no locks taken/released.
1668  * Return: 0 if ok; -2 if any argument is invalid (mu off-range).
1669  */
1670 
1671 int upwr_rx_callback(UPWR_RX_CALLB_FUNC_T    callback);
1672 
1673 /**
1674  * msg_copy() - copies a message.
1675  * @dest: pointer to the destination message.
1676  * @src : pointer to the source message.
1677  * @size: message size in words.
1678  *
1679  * This is an auxiliary function used by the rest of the API calls.
1680  * It is normally not called by the driver code, unless maybe for test purposes.
1681  *
1682  * Context: no sleep, no locks taken/released.
1683  * Return: none (void)
1684  */
1685 
1686 void msg_copy(char* dest, char* src, unsigned int size);
1687 
1688 /**
1689   */
1690 
1691 #ifdef UPWR_VERIFICATION
1692 #include "upower_api_verif.h"
1693 #endif
1694 
1695 #ifdef  __cplusplus
1696 #ifndef UPWR_NAMESPACE /* extern "C" 'cancels' the effect of namespace */
1697 } /* extern "C" */
1698 #endif
1699 #endif
1700 
1701 #endif /* _UPWR_API_H_ */
1702