upower_api.h 72 KB

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