zynqmp_pm_api_sys.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825
  1. /*
  2. * Copyright (c) 2013-2022, Arm Limited and Contributors. All rights reserved.
  3. * Copyright (c) 2022-2024, Advanced Micro Devices, Inc. All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. /*
  8. * ZynqMP system level PM-API functions and communication with PMU via
  9. * IPI interrupts
  10. */
  11. #include <arch_helpers.h>
  12. #include <plat/common/platform.h>
  13. #include "pm_api_clock.h"
  14. #include "pm_api_ioctl.h"
  15. #include "pm_api_pinctrl.h"
  16. #include "pm_client.h"
  17. #include "pm_common.h"
  18. #include "pm_ipi.h"
  19. #include "zynqmp_pm_api_sys.h"
  20. #define PM_QUERY_FEATURE_BITMASK ( \
  21. (1ULL << (uint64_t)PM_QID_CLOCK_GET_NAME) | \
  22. (1ULL << (uint64_t)PM_QID_CLOCK_GET_TOPOLOGY) | \
  23. (1ULL << (uint64_t)PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS) | \
  24. (1ULL << (uint64_t)PM_QID_CLOCK_GET_PARENTS) | \
  25. (1ULL << (uint64_t)PM_QID_CLOCK_GET_ATTRIBUTES) | \
  26. (1ULL << (uint64_t)PM_QID_PINCTRL_GET_NUM_PINS) | \
  27. (1ULL << (uint64_t)PM_QID_PINCTRL_GET_NUM_FUNCTIONS) | \
  28. (1ULL << (uint64_t)PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS) | \
  29. (1ULL << (uint64_t)PM_QID_PINCTRL_GET_FUNCTION_NAME) | \
  30. (1ULL << (uint64_t)PM_QID_PINCTRL_GET_FUNCTION_GROUPS) | \
  31. (1ULL << (uint64_t)PM_QID_PINCTRL_GET_PIN_GROUPS) | \
  32. (1ULL << (uint64_t)PM_QID_CLOCK_GET_NUM_CLOCKS) | \
  33. (1ULL << (uint64_t)PM_QID_CLOCK_GET_MAX_DIVISOR))
  34. /**
  35. * typedef eemi_api_dependency - Dependent EEMI APIs which are implemented
  36. * on both the TF-A and firmware.
  37. * @id: EEMI API id or IOCTL id to be checked.
  38. * @api_id: Dependent EEMI API.
  39. *
  40. */
  41. typedef struct __attribute__((packed)) {
  42. uint8_t id;
  43. uint8_t api_id;
  44. } eemi_api_dependency;
  45. /* Dependent APIs for TF-A to check their version from firmware */
  46. static const eemi_api_dependency api_dep_table[] = {
  47. {
  48. .id = PM_SELF_SUSPEND,
  49. .api_id = PM_SELF_SUSPEND,
  50. },
  51. {
  52. .id = PM_REQ_WAKEUP,
  53. .api_id = PM_REQ_WAKEUP,
  54. },
  55. {
  56. .id = PM_ABORT_SUSPEND,
  57. .api_id = PM_ABORT_SUSPEND,
  58. },
  59. {
  60. .id = PM_SET_WAKEUP_SOURCE,
  61. .api_id = PM_SET_WAKEUP_SOURCE,
  62. },
  63. {
  64. .id = PM_SYSTEM_SHUTDOWN,
  65. .api_id = PM_SYSTEM_SHUTDOWN,
  66. },
  67. {
  68. .id = PM_GET_API_VERSION,
  69. .api_id = PM_GET_API_VERSION,
  70. },
  71. {
  72. .id = PM_CLOCK_ENABLE,
  73. .api_id = PM_PLL_SET_MODE,
  74. },
  75. {
  76. .id = PM_CLOCK_ENABLE,
  77. .api_id = PM_CLOCK_ENABLE,
  78. },
  79. {
  80. .id = PM_CLOCK_DISABLE,
  81. .api_id = PM_PLL_SET_MODE,
  82. },
  83. {
  84. .id = PM_CLOCK_DISABLE,
  85. .api_id = PM_CLOCK_DISABLE,
  86. },
  87. {
  88. .id = PM_CLOCK_GETSTATE,
  89. .api_id = PM_PLL_GET_MODE,
  90. },
  91. {
  92. .id = PM_CLOCK_GETSTATE,
  93. .api_id = PM_CLOCK_GETSTATE,
  94. },
  95. {
  96. .id = PM_CLOCK_SETDIVIDER,
  97. .api_id = PM_PLL_SET_PARAMETER,
  98. },
  99. {
  100. .id = PM_CLOCK_SETDIVIDER,
  101. .api_id = PM_CLOCK_SETDIVIDER,
  102. },
  103. {
  104. .id = PM_CLOCK_GETDIVIDER,
  105. .api_id = PM_PLL_GET_PARAMETER,
  106. },
  107. {
  108. .id = PM_CLOCK_GETDIVIDER,
  109. .api_id = PM_CLOCK_GETDIVIDER,
  110. },
  111. {
  112. .id = PM_CLOCK_SETPARENT,
  113. .api_id = PM_PLL_SET_PARAMETER,
  114. },
  115. {
  116. .id = PM_CLOCK_SETPARENT,
  117. .api_id = PM_CLOCK_SETPARENT,
  118. },
  119. {
  120. .id = PM_CLOCK_GETPARENT,
  121. .api_id = PM_PLL_GET_PARAMETER,
  122. },
  123. {
  124. .id = PM_CLOCK_GETPARENT,
  125. .api_id = PM_CLOCK_GETPARENT,
  126. },
  127. {
  128. .id = PM_PLL_SET_PARAMETER,
  129. .api_id = PM_PLL_SET_PARAMETER,
  130. },
  131. {
  132. .id = PM_PLL_GET_PARAMETER,
  133. .api_id = PM_PLL_GET_PARAMETER,
  134. },
  135. {
  136. .id = PM_PLL_SET_MODE,
  137. .api_id = PM_PLL_SET_MODE,
  138. },
  139. {
  140. .id = PM_PLL_GET_MODE,
  141. .api_id = PM_PLL_GET_MODE,
  142. },
  143. {
  144. .id = PM_REGISTER_ACCESS,
  145. .api_id = PM_MMIO_WRITE,
  146. },
  147. {
  148. .id = PM_REGISTER_ACCESS,
  149. .api_id = PM_MMIO_READ,
  150. },
  151. {
  152. .id = PM_FEATURE_CHECK,
  153. .api_id = PM_FEATURE_CHECK,
  154. },
  155. {
  156. .id = IOCTL_SET_TAPDELAY_BYPASS,
  157. .api_id = PM_MMIO_WRITE,
  158. },
  159. {
  160. .id = IOCTL_SD_DLL_RESET,
  161. .api_id = PM_MMIO_WRITE,
  162. },
  163. {
  164. .id = IOCTL_SET_SD_TAPDELAY,
  165. .api_id = PM_MMIO_WRITE,
  166. },
  167. {
  168. .id = IOCTL_SET_SD_TAPDELAY,
  169. .api_id = PM_MMIO_READ,
  170. },
  171. {
  172. .id = IOCTL_SET_PLL_FRAC_DATA,
  173. .api_id = PM_PLL_SET_PARAMETER,
  174. },
  175. {
  176. .id = IOCTL_GET_PLL_FRAC_DATA,
  177. .api_id = PM_PLL_GET_PARAMETER,
  178. },
  179. {
  180. .id = IOCTL_WRITE_GGS,
  181. .api_id = PM_MMIO_WRITE,
  182. },
  183. {
  184. .id = IOCTL_READ_GGS,
  185. .api_id = PM_MMIO_READ,
  186. },
  187. {
  188. .id = IOCTL_WRITE_PGGS,
  189. .api_id = PM_MMIO_WRITE,
  190. },
  191. {
  192. .id = IOCTL_READ_PGGS,
  193. .api_id = PM_MMIO_READ,
  194. },
  195. {
  196. .id = IOCTL_ULPI_RESET,
  197. .api_id = PM_MMIO_WRITE,
  198. },
  199. {
  200. .id = IOCTL_SET_BOOT_HEALTH_STATUS,
  201. .api_id = PM_MMIO_WRITE,
  202. },
  203. {
  204. .id = IOCTL_AFI,
  205. .api_id = PM_MMIO_WRITE,
  206. },
  207. };
  208. /* Expected firmware API version to TF-A */
  209. static const uint8_t tfa_expected_ver_id[] = {
  210. [PM_SELF_SUSPEND] = FW_API_BASE_VERSION,
  211. [PM_REQ_WAKEUP] = FW_API_BASE_VERSION,
  212. [PM_ABORT_SUSPEND] = FW_API_BASE_VERSION,
  213. [PM_SET_WAKEUP_SOURCE] = FW_API_BASE_VERSION,
  214. [PM_SYSTEM_SHUTDOWN] = FW_API_BASE_VERSION,
  215. [PM_GET_API_VERSION] = FW_API_BASE_VERSION,
  216. [PM_PLL_SET_MODE] = FW_API_BASE_VERSION,
  217. [PM_PLL_GET_MODE] = FW_API_BASE_VERSION,
  218. [PM_CLOCK_ENABLE] = FW_API_BASE_VERSION,
  219. [PM_CLOCK_DISABLE] = FW_API_BASE_VERSION,
  220. [PM_CLOCK_GETSTATE] = FW_API_BASE_VERSION,
  221. [PM_PLL_SET_PARAMETER] = FW_API_BASE_VERSION,
  222. [PM_PLL_GET_PARAMETER] = FW_API_BASE_VERSION,
  223. [PM_CLOCK_SETDIVIDER] = FW_API_BASE_VERSION,
  224. [PM_CLOCK_GETDIVIDER] = FW_API_BASE_VERSION,
  225. [PM_CLOCK_SETPARENT] = FW_API_BASE_VERSION,
  226. [PM_CLOCK_GETPARENT] = FW_API_BASE_VERSION,
  227. [PM_MMIO_WRITE] = FW_API_BASE_VERSION,
  228. [PM_MMIO_READ] = FW_API_BASE_VERSION,
  229. [PM_FEATURE_CHECK] = FW_API_VERSION_2,
  230. };
  231. /* default shutdown/reboot scope is system(2) */
  232. static uint32_t pm_shutdown_scope = PMF_SHUTDOWN_SUBTYPE_SYSTEM;
  233. /**
  234. * pm_get_shutdown_scope() - Get the currently set shutdown scope.
  235. *
  236. * Return: Shutdown scope value.
  237. *
  238. */
  239. uint32_t pm_get_shutdown_scope(void)
  240. {
  241. return pm_shutdown_scope;
  242. }
  243. /**
  244. * pm_self_suspend() - PM call for processor to suspend itself.
  245. * @nid: Node id of the processor or subsystem.
  246. * @latency: Requested maximum wakeup latency (not supported).
  247. * @state: Requested state.
  248. * @address: Resume address.
  249. *
  250. * This is a blocking call, it will return only once PMU has responded.
  251. * On a wakeup, resume address will be automatically set by PMU.
  252. *
  253. * Return: Returns status, either success or error+reason.
  254. *
  255. */
  256. enum pm_ret_status pm_self_suspend(enum pm_node_id nid,
  257. uint32_t latency,
  258. uint32_t state,
  259. uintptr_t address)
  260. {
  261. (void)nid;
  262. uint32_t payload[PAYLOAD_ARG_CNT];
  263. uint32_t cpuid = plat_my_core_pos();
  264. const struct pm_proc *proc = pm_get_proc(cpuid);
  265. if (proc == NULL) {
  266. WARN("Failed to get proc %d\n", cpuid);
  267. return PM_RET_ERROR_INTERNAL;
  268. }
  269. /*
  270. * Do client specific suspend operations
  271. * (e.g. set powerdown request bit)
  272. */
  273. pm_client_suspend(proc, state);
  274. /* Send request to the PMU */
  275. PM_PACK_PAYLOAD6(payload, PM_SELF_SUSPEND, proc->node_id, latency,
  276. state, address, (address >> 32));
  277. return pm_ipi_send_sync(proc, payload, NULL, 0);
  278. }
  279. /**
  280. * pm_req_suspend() - PM call to request for another PU or subsystem to
  281. * be suspended gracefully.
  282. * @target: Node id of the targeted PU or subsystem.
  283. * @ack: Flag to specify whether acknowledge is requested.
  284. * @latency: Requested wakeup latency (not supported).
  285. * @state: Requested state (not supported).
  286. *
  287. * Return: Returns status, either success or error+reason.
  288. *
  289. */
  290. enum pm_ret_status pm_req_suspend(enum pm_node_id target,
  291. enum pm_request_ack ack,
  292. uint32_t latency, uint32_t state)
  293. {
  294. uint32_t payload[PAYLOAD_ARG_CNT];
  295. /* Send request to the PMU */
  296. PM_PACK_PAYLOAD5(payload, PM_REQ_SUSPEND, target, ack, latency, state);
  297. if (ack == REQ_ACK_BLOCKING) {
  298. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  299. } else {
  300. return pm_ipi_send(primary_proc, payload);
  301. }
  302. }
  303. /**
  304. * pm_req_wakeup() - PM call for processor to wake up selected processor
  305. * or subsystem.
  306. * @target: Node id of the processor or subsystem to wake up.
  307. * @ack: Flag to specify whether acknowledge requested.
  308. * @set_address: Resume address presence indicator.
  309. * 1 resume address specified, 0 otherwise.
  310. * @address: Resume address.
  311. *
  312. * This API function is either used to power up another APU core for SMP
  313. * (by PSCI) or to power up an entirely different PU or subsystem, such
  314. * as RPU0, RPU, or PL_CORE_xx. Resume address for the target PU will be
  315. * automatically set by PMU.
  316. *
  317. * Return: Returns status, either success or error+reason.
  318. *
  319. */
  320. enum pm_ret_status pm_req_wakeup(enum pm_node_id target,
  321. uint32_t set_address,
  322. uintptr_t address,
  323. enum pm_request_ack ack)
  324. {
  325. uint32_t payload[PAYLOAD_ARG_CNT];
  326. uint64_t encoded_address;
  327. /* encode set Address into 1st bit of address */
  328. encoded_address = address;
  329. encoded_address |= !!set_address;
  330. /* Send request to the PMU to perform the wake of the PU */
  331. PM_PACK_PAYLOAD5(payload, PM_REQ_WAKEUP, target, encoded_address,
  332. encoded_address >> 32, ack);
  333. if (ack == REQ_ACK_BLOCKING) {
  334. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  335. } else {
  336. return pm_ipi_send(primary_proc, payload);
  337. }
  338. }
  339. /**
  340. * pm_force_powerdown() - PM call to request for another PU or subsystem to
  341. * be powered down forcefully.
  342. * @target: Node id of the targeted PU or subsystem.
  343. * @ack: Flag to specify whether acknowledge is requested.
  344. *
  345. * Return: Returns status, either success or error+reason.
  346. *
  347. */
  348. enum pm_ret_status pm_force_powerdown(enum pm_node_id target,
  349. enum pm_request_ack ack)
  350. {
  351. uint32_t payload[PAYLOAD_ARG_CNT];
  352. /* Send request to the PMU */
  353. PM_PACK_PAYLOAD3(payload, PM_FORCE_POWERDOWN, target, ack);
  354. if (ack == REQ_ACK_BLOCKING) {
  355. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  356. } else {
  357. return pm_ipi_send(primary_proc, payload);
  358. }
  359. }
  360. /**
  361. * pm_abort_suspend() - PM call to announce that a prior suspend request
  362. * is to be aborted.
  363. * @reason: Reason for the abort.
  364. *
  365. * Calling PU expects the PMU to abort the initiated suspend procedure.
  366. * This is a non-blocking call without any acknowledge.
  367. *
  368. * Return: Returns status, either success or error+reason
  369. *
  370. */
  371. enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason)
  372. {
  373. uint32_t payload[PAYLOAD_ARG_CNT];
  374. /*
  375. * Do client specific abort suspend operations
  376. * (e.g. enable interrupts and clear powerdown request bit)
  377. */
  378. pm_client_abort_suspend();
  379. /* Send request to the PMU */
  380. /* TODO: allow passing the node ID of the affected CPU */
  381. PM_PACK_PAYLOAD3(payload, PM_ABORT_SUSPEND, reason,
  382. primary_proc->node_id);
  383. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  384. }
  385. /**
  386. * pm_set_wakeup_source() - PM call to specify the wakeup source while
  387. * suspended.
  388. * @target: Node id of the targeted PU or subsystem.
  389. * @wkup_node: Node id of the wakeup peripheral.
  390. * @enable: Enable or disable the specified peripheral as wake source.
  391. *
  392. * Return: Returns status, either success or error+reason.
  393. *
  394. */
  395. enum pm_ret_status pm_set_wakeup_source(enum pm_node_id target,
  396. enum pm_node_id wkup_node,
  397. uint32_t enable)
  398. {
  399. uint32_t payload[PAYLOAD_ARG_CNT];
  400. PM_PACK_PAYLOAD4(payload, PM_SET_WAKEUP_SOURCE, target, wkup_node,
  401. enable);
  402. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  403. }
  404. /**
  405. * pm_system_shutdown() - PM call to request a system shutdown or restart.
  406. * @type: Shutdown or restart? 0=shutdown, 1=restart, 2=setscope.
  407. * @subtype: Scope: 0=APU-subsystem, 1=PS, 2=system.
  408. *
  409. * Return: Returns status, either success or error+reason.
  410. *
  411. */
  412. enum pm_ret_status pm_system_shutdown(uint32_t type, uint32_t subtype)
  413. {
  414. uint32_t payload[PAYLOAD_ARG_CNT];
  415. if (type == PMF_SHUTDOWN_TYPE_SETSCOPE_ONLY) {
  416. /* Setting scope for subsequent PSCI reboot or shutdown */
  417. pm_shutdown_scope = subtype;
  418. return PM_RET_SUCCESS;
  419. }
  420. PM_PACK_PAYLOAD3(payload, PM_SYSTEM_SHUTDOWN, type, subtype);
  421. return pm_ipi_send_non_blocking(primary_proc, payload);
  422. }
  423. /* APIs for managing PM slaves: */
  424. /**
  425. * pm_req_node() - PM call to request a node with specific capabilities.
  426. * @nid: Node id of the slave.
  427. * @capabilities: Requested capabilities of the slave.
  428. * @qos: Quality of service (not supported).
  429. * @ack: Flag to specify whether acknowledge is requested.
  430. *
  431. * Return: Returns status, either success or error+reason.
  432. *
  433. */
  434. enum pm_ret_status pm_req_node(enum pm_node_id nid,
  435. uint32_t capabilities,
  436. uint32_t qos,
  437. enum pm_request_ack ack)
  438. {
  439. uint32_t payload[PAYLOAD_ARG_CNT];
  440. PM_PACK_PAYLOAD5(payload, PM_REQ_NODE, nid, capabilities, qos, ack);
  441. if (ack == REQ_ACK_BLOCKING) {
  442. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  443. } else {
  444. return pm_ipi_send(primary_proc, payload);
  445. }
  446. }
  447. /**
  448. * pm_set_requirement() - PM call to set requirement for PM slaves.
  449. * @nid: Node id of the slave.
  450. * @capabilities: Requested capabilities of the slave.
  451. * @qos: Quality of service (not supported).
  452. * @ack: Flag to specify whether acknowledge is requested.
  453. *
  454. * This API function is to be used for slaves a PU already has requested.
  455. *
  456. * Return: Returns status, either success or error+reason.
  457. *
  458. */
  459. enum pm_ret_status pm_set_requirement(enum pm_node_id nid,
  460. uint32_t capabilities,
  461. uint32_t qos,
  462. enum pm_request_ack ack)
  463. {
  464. uint32_t payload[PAYLOAD_ARG_CNT];
  465. PM_PACK_PAYLOAD5(payload, PM_SET_REQUIREMENT, nid, capabilities, qos,
  466. ack);
  467. if (ack == REQ_ACK_BLOCKING) {
  468. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  469. } else {
  470. return pm_ipi_send(primary_proc, payload);
  471. }
  472. }
  473. /* Miscellaneous API functions */
  474. /**
  475. * pm_get_api_version() - Get version number of PMU PM firmware.
  476. * @version: Returns 32-bit version number of PMU Power Management Firmware.
  477. *
  478. * Return: Returns status, either success or error+reason.
  479. *
  480. */
  481. enum pm_ret_status pm_get_api_version(uint32_t *version)
  482. {
  483. uint32_t payload[PAYLOAD_ARG_CNT];
  484. /* Send request to the PMU */
  485. PM_PACK_PAYLOAD1(payload, PM_GET_API_VERSION);
  486. return pm_ipi_send_sync(primary_proc, payload, version, 1);
  487. }
  488. /**
  489. * pm_get_node_status() - PM call to request a node's current status.
  490. * @nid: Node id.
  491. * @ret_buff: Buffer for the return values
  492. * [0] - Current power state of the node
  493. * [1] - Current requirements for the node (slave nodes only)
  494. * [2] - Current usage status for the node (slave nodes only)
  495. *
  496. * Return: Returns status, either success or error+reason.
  497. *
  498. */
  499. enum pm_ret_status pm_get_node_status(enum pm_node_id nid,
  500. uint32_t *ret_buff)
  501. {
  502. uint32_t payload[PAYLOAD_ARG_CNT];
  503. PM_PACK_PAYLOAD2(payload, PM_GET_NODE_STATUS, nid);
  504. return pm_ipi_send_sync(primary_proc, payload, ret_buff, 3);
  505. }
  506. /**
  507. * pm_mmio_write() - Perform write to protected mmio.
  508. * @address: Address to write to.
  509. * @mask: Mask to apply.
  510. * @value: Value to write.
  511. *
  512. * This function provides access to PM-related control registers
  513. * that may not be directly accessible by a particular PU.
  514. *
  515. * Return: Returns status, either success or error+reason.
  516. *
  517. */
  518. enum pm_ret_status pm_mmio_write(uintptr_t address,
  519. uint32_t mask,
  520. uint32_t value)
  521. {
  522. uint32_t payload[PAYLOAD_ARG_CNT];
  523. /* Send request to the PMU */
  524. PM_PACK_PAYLOAD4(payload, PM_MMIO_WRITE, address, mask, value);
  525. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  526. }
  527. /**
  528. * pm_mmio_read() - Read value from protected mmio.
  529. * @address: Address to write to.
  530. * @value: Value to write.
  531. *
  532. * This function provides access to PM-related control registers
  533. * that may not be directly accessible by a particular PU.
  534. *
  535. * Return: Returns status, either success or error+reason.
  536. *
  537. */
  538. enum pm_ret_status pm_mmio_read(uintptr_t address, uint32_t *value)
  539. {
  540. uint32_t payload[PAYLOAD_ARG_CNT];
  541. /* Send request to the PMU */
  542. PM_PACK_PAYLOAD2(payload, PM_MMIO_READ, address);
  543. return pm_ipi_send_sync(primary_proc, payload, value, 1);
  544. }
  545. /**
  546. * pm_fpga_load() - Load the bitstream into the PL. This function provides
  547. * access to the xilfpga library to load the Bit-stream
  548. * into PL.
  549. * @address_low: lower 32-bit Linear memory space address.
  550. * @address_high: higher 32-bit Linear memory space address.
  551. * @size: Number of 32bit words.
  552. * @flags: Additional flags or settings for the fpga operation.
  553. *
  554. * Return: Returns status, either success or error+reason.
  555. *
  556. */
  557. enum pm_ret_status pm_fpga_load(uint32_t address_low,
  558. uint32_t address_high,
  559. uint32_t size,
  560. uint32_t flags)
  561. {
  562. uint32_t payload[PAYLOAD_ARG_CNT];
  563. /* Send request to the PMU */
  564. PM_PACK_PAYLOAD5(payload, PM_FPGA_LOAD, address_high, address_low,
  565. size, flags);
  566. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  567. }
  568. /**
  569. * pm_fpga_get_status() - Read value from fpga status register.
  570. * @value: Value to read.
  571. *
  572. * This function provides access to the xilfpga library to get
  573. * the fpga status.
  574. *
  575. * Return: Returns status, either success or error+reason.
  576. *
  577. */
  578. enum pm_ret_status pm_fpga_get_status(uint32_t *value)
  579. {
  580. uint32_t payload[PAYLOAD_ARG_CNT];
  581. /* Send request to the PMU */
  582. PM_PACK_PAYLOAD1(payload, PM_FPGA_GET_STATUS);
  583. return pm_ipi_send_sync(primary_proc, payload, value, 1);
  584. }
  585. /**
  586. * pm_get_chipid() - Read silicon ID registers.
  587. * @value: Buffer for return values. Must be large enough to hold 8 bytes.
  588. *
  589. * Return: Returns silicon ID registers.
  590. *
  591. */
  592. enum pm_ret_status pm_get_chipid(uint32_t *value)
  593. {
  594. uint32_t payload[PAYLOAD_ARG_CNT];
  595. /* Send request to the PMU */
  596. PM_PACK_PAYLOAD1(payload, PM_GET_CHIPID);
  597. return pm_ipi_send_sync(primary_proc, payload, value, 2);
  598. }
  599. /**
  600. * pm_secure_rsaaes() - Load the secure images.
  601. * @address_low: lower 32-bit Linear memory space address.
  602. * @address_high: higher 32-bit Linear memory space address.
  603. * @size: Number of 32bit words.
  604. * @flags: Additional flags or settings for the fpga operation.
  605. *
  606. * This function provides access to the xilsecure library to load the
  607. * authenticated, encrypted, and authenticated/encrypted images.
  608. *
  609. * Return: Returns status, either success or error+reason.
  610. *
  611. */
  612. enum pm_ret_status pm_secure_rsaaes(uint32_t address_low,
  613. uint32_t address_high,
  614. uint32_t size,
  615. uint32_t flags)
  616. {
  617. uint32_t payload[PAYLOAD_ARG_CNT];
  618. /* Send request to the PMU */
  619. PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA_AES, address_high, address_low,
  620. size, flags);
  621. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  622. }
  623. /**
  624. * pm_aes_engine() - Aes data blob encryption/decryption.
  625. * @address_low: lower 32-bit address of the AesParams structure.
  626. * @address_high: higher 32-bit address of the AesParams structure.
  627. * @value: Returned output value.
  628. *
  629. * This function provides access to the xilsecure library to
  630. * encrypt/decrypt data blobs.
  631. *
  632. * Return: Returns status, either success or error+reason.
  633. *
  634. */
  635. enum pm_ret_status pm_aes_engine(uint32_t address_high,
  636. uint32_t address_low,
  637. uint32_t *value)
  638. {
  639. uint32_t payload[PAYLOAD_ARG_CNT];
  640. /* Send request to the PMU */
  641. PM_PACK_PAYLOAD3(payload, PM_SECURE_AES, address_high, address_low);
  642. return pm_ipi_send_sync(primary_proc, payload, value, 1);
  643. }
  644. /**
  645. * pm_get_callbackdata() - Read from IPI response buffer.
  646. * @data: array of PAYLOAD_ARG_CNT elements.
  647. * @count: Number of values to return.
  648. *
  649. * Read value from ipi buffer response buffer.
  650. * Return: Returns status, either success or error.
  651. *
  652. */
  653. enum pm_ret_status pm_get_callbackdata(uint32_t *data, size_t count)
  654. {
  655. enum pm_ret_status ret = PM_RET_SUCCESS;
  656. /* Return if interrupt is not from PMU */
  657. if (!pm_ipi_irq_status(primary_proc)) {
  658. return ret;
  659. }
  660. ret = pm_ipi_buff_read_callb(data, count);
  661. pm_ipi_irq_clear(primary_proc);
  662. return ret;
  663. }
  664. /**
  665. * pm_ioctl() - PM IOCTL API for device control and configs.
  666. * @nid: Node ID of the device.
  667. * @ioctl_id: ID of the requested IOCTL.
  668. * @arg1: Argument 1 to requested IOCTL call.
  669. * @arg2: Argument 2 to requested IOCTL call.
  670. * @value: Returned output value.
  671. *
  672. * This function calls IOCTL to firmware for device control and configuration.
  673. *
  674. * Return: Returns status, either success or error+reason.
  675. *
  676. */
  677. enum pm_ret_status pm_ioctl(enum pm_node_id nid,
  678. uint32_t ioctl_id,
  679. uint32_t arg1,
  680. uint32_t arg2,
  681. uint32_t *value)
  682. {
  683. return pm_api_ioctl(nid, ioctl_id, arg1, arg2, value);
  684. }
  685. /**
  686. * fw_api_version() - Returns API version implemented in firmware.
  687. * @id: API ID to check.
  688. * @version: Returned supported API version.
  689. * @len: Number of words to be returned.
  690. *
  691. * Return: Returns status, either success or error+reason.
  692. *
  693. */
  694. static enum pm_ret_status fw_api_version(uint32_t id, uint32_t *version,
  695. uint32_t len)
  696. {
  697. uint32_t payload[PAYLOAD_ARG_CNT];
  698. PM_PACK_PAYLOAD2(payload, PM_FEATURE_CHECK, id);
  699. return pm_ipi_send_sync(primary_proc, payload, version, len);
  700. }
  701. /**
  702. * check_api_dependency() - API to check dependent EEMI API version.
  703. * @id: EEMI API ID to check.
  704. *
  705. * Return: Returns status, either success or error+reason.
  706. *
  707. */
  708. enum pm_ret_status check_api_dependency(uint8_t id)
  709. {
  710. uint8_t i;
  711. uint32_t version_type;
  712. int ret;
  713. for (i = 0U; i < ARRAY_SIZE(api_dep_table); i++) {
  714. if (api_dep_table[i].id == id) {
  715. if (api_dep_table[i].api_id == 0U) {
  716. break;
  717. }
  718. ret = fw_api_version(api_dep_table[i].api_id,
  719. &version_type, 1);
  720. if (ret != PM_RET_SUCCESS) {
  721. return ret;
  722. }
  723. /* Check if fw version matches TF-A expected version */
  724. if (version_type != tfa_expected_ver_id[api_dep_table[i].api_id]) {
  725. return PM_RET_ERROR_NOTSUPPORTED;
  726. }
  727. }
  728. }
  729. return PM_RET_SUCCESS;
  730. }
  731. /**
  732. * feature_check_tfa() - These are API's completely implemented in TF-A.
  733. * @api_id: API ID to check.
  734. * @version: Returned supported API version.
  735. * @bit_mask: Returned supported IOCTL id version.
  736. *
  737. * Return: Returns status, either success or error+reason.
  738. *
  739. */
  740. static enum pm_ret_status feature_check_tfa(uint32_t api_id, uint32_t *version,
  741. uint32_t *bit_mask)
  742. {
  743. switch (api_id) {
  744. case PM_QUERY_DATA:
  745. *version = TFA_API_QUERY_DATA_VERSION;
  746. bit_mask[0] = (uint32_t)(PM_QUERY_FEATURE_BITMASK);
  747. bit_mask[1] = (uint32_t)(PM_QUERY_FEATURE_BITMASK >> 32);
  748. return PM_RET_SUCCESS;
  749. case PM_GET_CALLBACK_DATA:
  750. case PM_GET_TRUSTZONE_VERSION:
  751. case PM_SET_SUSPEND_MODE:
  752. *version = TFA_API_BASE_VERSION;
  753. return PM_RET_SUCCESS;
  754. default:
  755. return PM_RET_ERROR_NO_FEATURE;
  756. }
  757. }
  758. /**
  759. * get_tfa_version_for_partial_apis() - Return TF-A version for partially.
  760. * implemented APIs
  761. * @api_id: API ID to check.
  762. * @version: Returned supported API version.
  763. *
  764. * Return: Returns status, either success or error+reason.
  765. *
  766. */
  767. static enum pm_ret_status get_tfa_version_for_partial_apis(uint32_t api_id,
  768. uint32_t *version)
  769. {
  770. switch (api_id) {
  771. case PM_SELF_SUSPEND:
  772. case PM_REQ_WAKEUP:
  773. case PM_ABORT_SUSPEND:
  774. case PM_SET_WAKEUP_SOURCE:
  775. case PM_SYSTEM_SHUTDOWN:
  776. case PM_GET_API_VERSION:
  777. case PM_CLOCK_ENABLE:
  778. case PM_CLOCK_DISABLE:
  779. case PM_CLOCK_GETSTATE:
  780. case PM_CLOCK_SETDIVIDER:
  781. case PM_CLOCK_GETDIVIDER:
  782. case PM_CLOCK_SETPARENT:
  783. case PM_CLOCK_GETPARENT:
  784. case PM_PLL_SET_PARAMETER:
  785. case PM_PLL_GET_PARAMETER:
  786. case PM_PLL_SET_MODE:
  787. case PM_PLL_GET_MODE:
  788. case PM_REGISTER_ACCESS:
  789. *version = TFA_API_BASE_VERSION;
  790. return PM_RET_SUCCESS;
  791. case PM_FEATURE_CHECK:
  792. *version = FW_API_VERSION_2;
  793. return PM_RET_SUCCESS;
  794. default:
  795. return PM_RET_ERROR_ARGS;
  796. }
  797. }
  798. /**
  799. * feature_check_partial() - These are API's partially implemented in
  800. * TF-A and firmware both.
  801. * @api_id: API ID to check.
  802. * @version: Returned supported API version.
  803. *
  804. * Return: Returns status, either success or error+reason.
  805. *
  806. */
  807. static enum pm_ret_status feature_check_partial(uint32_t api_id,
  808. uint32_t *version)
  809. {
  810. uint32_t status;
  811. switch (api_id) {
  812. case PM_SELF_SUSPEND:
  813. case PM_REQ_WAKEUP:
  814. case PM_ABORT_SUSPEND:
  815. case PM_SET_WAKEUP_SOURCE:
  816. case PM_SYSTEM_SHUTDOWN:
  817. case PM_GET_API_VERSION:
  818. case PM_CLOCK_ENABLE:
  819. case PM_CLOCK_DISABLE:
  820. case PM_CLOCK_GETSTATE:
  821. case PM_CLOCK_SETDIVIDER:
  822. case PM_CLOCK_GETDIVIDER:
  823. case PM_CLOCK_SETPARENT:
  824. case PM_CLOCK_GETPARENT:
  825. case PM_PLL_SET_PARAMETER:
  826. case PM_PLL_GET_PARAMETER:
  827. case PM_PLL_SET_MODE:
  828. case PM_PLL_GET_MODE:
  829. case PM_REGISTER_ACCESS:
  830. case PM_FEATURE_CHECK:
  831. status = check_api_dependency(api_id);
  832. if (status != PM_RET_SUCCESS) {
  833. return status;
  834. }
  835. return get_tfa_version_for_partial_apis(api_id, version);
  836. default:
  837. return PM_RET_ERROR_NO_FEATURE;
  838. }
  839. }
  840. /**
  841. * pm_feature_check() - Returns the supported API version if supported.
  842. * @api_id: API ID to check.
  843. * @version: Returned supported API version.
  844. * @bit_mask: Returned supported IOCTL id version.
  845. * @len: Number of bytes to be returned in bit_mask variable.
  846. *
  847. * Return: Returns status, either success or error+reason.
  848. *
  849. */
  850. enum pm_ret_status pm_feature_check(uint32_t api_id, uint32_t *version,
  851. uint32_t *bit_mask, uint8_t len)
  852. {
  853. uint32_t ret_payload[RET_PAYLOAD_ARG_CNT] = {0U};
  854. uint32_t status;
  855. /* Get API version implemented in TF-A */
  856. status = feature_check_tfa(api_id, version, bit_mask);
  857. if (status != PM_RET_ERROR_NO_FEATURE) {
  858. return status;
  859. }
  860. /* Get API version implemented by firmware and TF-A both */
  861. status = feature_check_partial(api_id, version);
  862. if (status != PM_RET_ERROR_NO_FEATURE) {
  863. return status;
  864. }
  865. /* Get API version implemented by firmware */
  866. status = fw_api_version(api_id, ret_payload, 3);
  867. /* IOCTL call may return failure whose ID is not implemented in
  868. * firmware but implemented in TF-A
  869. */
  870. if ((api_id != PM_IOCTL) && (status != PM_RET_SUCCESS)) {
  871. return status;
  872. }
  873. *version = ret_payload[0];
  874. /* Update IOCTL bit mask which are implemented in TF-A */
  875. if ((api_id == PM_IOCTL) || (api_id == PM_GET_OP_CHARACTERISTIC)) {
  876. if (len < 2) {
  877. return PM_RET_ERROR_ARGS;
  878. }
  879. bit_mask[0] = ret_payload[1];
  880. bit_mask[1] = ret_payload[2];
  881. if (api_id == PM_IOCTL) {
  882. /* Get IOCTL's implemented by TF-A */
  883. status = tfa_ioctl_bitmask(bit_mask);
  884. }
  885. } else {
  886. /* Requires for MISRA */
  887. }
  888. return status;
  889. }
  890. /**
  891. * pm_clock_get_max_divisor - PM call to get max divisor.
  892. * @clock_id: Clock ID.
  893. * @div_type: Divisor ID (TYPE_DIV1 or TYPE_DIV2).
  894. * @max_div: Maximum supported divisor.
  895. *
  896. * This function is used by master to get maximum supported value.
  897. *
  898. * Return: Returns status, either success or error+reason.
  899. *
  900. */
  901. static enum pm_ret_status pm_clock_get_max_divisor(uint32_t clock_id,
  902. uint8_t div_type,
  903. uint32_t *max_div)
  904. {
  905. return pm_api_clock_get_max_divisor(clock_id, div_type, max_div);
  906. }
  907. /**
  908. * pm_clock_get_num_clocks - PM call to request number of clocks.
  909. * @nclocks: Number of clocks.
  910. *
  911. * This function is used by master to get number of clocks.
  912. *
  913. * Return: Returns status, either success or error+reason.
  914. *
  915. */
  916. static enum pm_ret_status pm_clock_get_num_clocks(uint32_t *nclocks)
  917. {
  918. return pm_api_clock_get_num_clocks(nclocks);
  919. }
  920. /**
  921. * pm_clock_get_name() - PM call to request a clock's name.
  922. * @clock_id: Clock ID.
  923. * @name: Name of clock (max 16 bytes).
  924. *
  925. * This function is used by master to get nmae of clock specified
  926. * by given clock ID.
  927. *
  928. */
  929. static void pm_clock_get_name(uint32_t clock_id, char *name)
  930. {
  931. pm_api_clock_get_name(clock_id, name);
  932. }
  933. /**
  934. * pm_clock_get_topology() - PM call to request a clock's topology.
  935. * @clock_id: Clock ID.
  936. * @index: Topology index for next toplogy node.
  937. * @topology: Buffer to store nodes in topology and flags.
  938. *
  939. * This function is used by master to get topology information for the
  940. * clock specified by given clock ID. Each response would return 3
  941. * topology nodes. To get next nodes, caller needs to call this API with
  942. * index of next node. Index starts from 0.
  943. *
  944. * Return: Returns status, either success or error+reason.
  945. *
  946. */
  947. static enum pm_ret_status pm_clock_get_topology(uint32_t clock_id,
  948. uint32_t index,
  949. uint32_t *topology)
  950. {
  951. return pm_api_clock_get_topology(clock_id, index, topology);
  952. }
  953. /**
  954. * pm_clock_get_fixedfactor_params() - PM call to request a clock's fixed factor
  955. * parameters for fixed clock.
  956. * @clock_id: Clock ID.
  957. * @mul: Multiplication value.
  958. * @div: Divisor value.
  959. *
  960. * This function is used by master to get fixed factor parameers for the
  961. * fixed clock. This API is application only for the fixed clock.
  962. *
  963. * Return: Returns status, either success or error+reason.
  964. *
  965. */
  966. static enum pm_ret_status pm_clock_get_fixedfactor_params(uint32_t clock_id,
  967. uint32_t *mul,
  968. uint32_t *div)
  969. {
  970. return pm_api_clock_get_fixedfactor_params(clock_id, mul, div);
  971. }
  972. /**
  973. * pm_clock_get_parents() - PM call to request a clock's first 3 parents.
  974. * @clock_id: Clock ID.
  975. * @index: Index of next parent.
  976. * @parents: Parents of the given clock.
  977. *
  978. * This function is used by master to get clock's parents information.
  979. * This API will return 3 parents with a single response. To get other
  980. * parents, master should call same API in loop with new parent index
  981. * till error is returned.
  982. *
  983. * E.g First call should have index 0 which will return parents 0, 1 and
  984. * 2. Next call, index should be 3 which will return parent 3,4 and 5 and
  985. * so on.
  986. *
  987. * Return: Returns status, either success or error+reason.
  988. *
  989. */
  990. static enum pm_ret_status pm_clock_get_parents(uint32_t clock_id,
  991. uint32_t index,
  992. uint32_t *parents)
  993. {
  994. return pm_api_clock_get_parents(clock_id, index, parents);
  995. }
  996. /**
  997. * pm_clock_get_attributes() - PM call to request a clock's attributes.
  998. * @clock_id: Clock ID.
  999. * @attr: Clock attributes.
  1000. *
  1001. * This function is used by master to get clock's attributes
  1002. * (e.g. valid, clock type, etc).
  1003. *
  1004. * Return: Returns status, either success or error+reason.
  1005. *
  1006. */
  1007. static enum pm_ret_status pm_clock_get_attributes(uint32_t clock_id,
  1008. uint32_t *attr)
  1009. {
  1010. return pm_api_clock_get_attributes(clock_id, attr);
  1011. }
  1012. /**
  1013. * pm_clock_gate() - Configure clock gate.
  1014. * @clock_id: Id of the clock to be configured.
  1015. * @enable: Flag 0=disable (gate the clock), !0=enable (activate the clock).
  1016. *
  1017. * Return: Error if an argument is not valid or status as returned by the
  1018. * PM controller (PMU).
  1019. *
  1020. */
  1021. static enum pm_ret_status pm_clock_gate(uint32_t clock_id,
  1022. uint8_t enable)
  1023. {
  1024. uint32_t payload[PAYLOAD_ARG_CNT];
  1025. enum pm_ret_status status;
  1026. enum pm_api_id api_id;
  1027. /* Check if clock ID is valid and return an error if it is not */
  1028. status = pm_clock_id_is_valid(clock_id);
  1029. if (status != PM_RET_SUCCESS) {
  1030. return status;
  1031. }
  1032. if (enable != 0U) {
  1033. api_id = PM_CLOCK_ENABLE;
  1034. } else {
  1035. api_id = PM_CLOCK_DISABLE;
  1036. }
  1037. /* Send request to the PMU */
  1038. PM_PACK_PAYLOAD2(payload, api_id, clock_id);
  1039. status = pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1040. /* If action fails due to the lack of permissions filter the error */
  1041. if (status == PM_RET_ERROR_ACCESS) {
  1042. status = PM_RET_SUCCESS;
  1043. }
  1044. return status;
  1045. }
  1046. /**
  1047. * pm_clock_enable() - Enable the clock for given id.
  1048. * @clock_id: Id of the clock to be enabled.
  1049. *
  1050. * This function is used by master to enable the clock
  1051. * including peripherals and PLL clocks.
  1052. *
  1053. * Return: Error if an argument is not valid or status as returned by the
  1054. * pm_clock_gate.
  1055. *
  1056. */
  1057. enum pm_ret_status pm_clock_enable(uint32_t clock_id)
  1058. {
  1059. struct pm_pll *pll;
  1060. /* First try to handle it as a PLL */
  1061. pll = pm_clock_get_pll(clock_id);
  1062. if (pll != NULL) {
  1063. return pm_clock_pll_enable(pll);
  1064. }
  1065. /* It's an on-chip clock, PMU should configure clock's gate */
  1066. return pm_clock_gate(clock_id, 1);
  1067. }
  1068. /**
  1069. * pm_clock_disable - Disable the clock for given id.
  1070. * @clock_id: Id of the clock to be disable.
  1071. *
  1072. * This function is used by master to disable the clock
  1073. * including peripherals and PLL clocks.
  1074. *
  1075. * Return: Error if an argument is not valid or status as returned by the
  1076. * pm_clock_gate
  1077. *
  1078. */
  1079. enum pm_ret_status pm_clock_disable(uint32_t clock_id)
  1080. {
  1081. struct pm_pll *pll;
  1082. /* First try to handle it as a PLL */
  1083. pll = pm_clock_get_pll(clock_id);
  1084. if (pll != NULL) {
  1085. return pm_clock_pll_disable(pll);
  1086. }
  1087. /* It's an on-chip clock, PMU should configure clock's gate */
  1088. return pm_clock_gate(clock_id, 0);
  1089. }
  1090. /**
  1091. * pm_clock_getstate - Get the clock state for given id.
  1092. * @clock_id: Id of the clock to be queried.
  1093. * @state: 1/0 (Enabled/Disabled).
  1094. *
  1095. * This function is used by master to get the state of clock
  1096. * including peripherals and PLL clocks.
  1097. *
  1098. * Return: Returns status, either success or error+reason.
  1099. *
  1100. */
  1101. enum pm_ret_status pm_clock_getstate(uint32_t clock_id,
  1102. uint32_t *state)
  1103. {
  1104. struct pm_pll *pll;
  1105. uint32_t payload[PAYLOAD_ARG_CNT];
  1106. enum pm_ret_status status;
  1107. /* First try to handle it as a PLL */
  1108. pll = pm_clock_get_pll(clock_id);
  1109. if (pll != NULL) {
  1110. return pm_clock_pll_get_state(pll, state);
  1111. }
  1112. /* Check if clock ID is a valid on-chip clock */
  1113. status = pm_clock_id_is_valid(clock_id);
  1114. if (status != PM_RET_SUCCESS) {
  1115. return status;
  1116. }
  1117. /* Send request to the PMU */
  1118. PM_PACK_PAYLOAD2(payload, PM_CLOCK_GETSTATE, clock_id);
  1119. return pm_ipi_send_sync(primary_proc, payload, state, 1);
  1120. }
  1121. /**
  1122. * pm_clock_setdivider - Set the clock divider for given id.
  1123. * @clock_id: Id of the clock.
  1124. * @divider: divider value.
  1125. *
  1126. * This function is used by master to set divider for any clock
  1127. * to achieve desired rate.
  1128. *
  1129. * Return: Returns status, either success or error+reason.
  1130. *
  1131. */
  1132. enum pm_ret_status pm_clock_setdivider(uint32_t clock_id,
  1133. uint32_t divider)
  1134. {
  1135. enum pm_ret_status status;
  1136. enum pm_node_id nid;
  1137. enum pm_clock_div_id div_id;
  1138. uint32_t payload[PAYLOAD_ARG_CNT];
  1139. const uint32_t div0 = 0xFFFF0000;
  1140. const uint32_t div1 = 0x0000FFFF;
  1141. uint32_t val;
  1142. /* Get PLL node ID using PLL clock ID */
  1143. status = pm_clock_get_pll_node_id(clock_id, &nid);
  1144. if (status == PM_RET_SUCCESS) {
  1145. return pm_pll_set_parameter(nid, PM_PLL_PARAM_FBDIV, divider);
  1146. }
  1147. /* Check if clock ID is a valid on-chip clock */
  1148. status = pm_clock_id_is_valid(clock_id);
  1149. if (status != PM_RET_SUCCESS) {
  1150. return status;
  1151. }
  1152. if (div0 == (divider & div0)) {
  1153. div_id = PM_CLOCK_DIV0_ID;
  1154. val = divider & ~div0;
  1155. } else if (div1 == (divider & div1)) {
  1156. div_id = PM_CLOCK_DIV1_ID;
  1157. val = (divider & ~div1) >> 16;
  1158. } else {
  1159. return PM_RET_ERROR_ARGS;
  1160. }
  1161. /* Send request to the PMU */
  1162. PM_PACK_PAYLOAD4(payload, PM_CLOCK_SETDIVIDER, clock_id, div_id, val);
  1163. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1164. }
  1165. /**
  1166. * pm_clock_getdivider - Get the clock divider for given id.
  1167. * @clock_id: Id of the clock.
  1168. * @divider: divider value.
  1169. *
  1170. * This function is used by master to get divider values
  1171. * for any clock.
  1172. *
  1173. * Return: Returns status, either success or error+reason.
  1174. *
  1175. */
  1176. enum pm_ret_status pm_clock_getdivider(uint32_t clock_id,
  1177. uint32_t *divider)
  1178. {
  1179. enum pm_ret_status status;
  1180. enum pm_node_id nid;
  1181. uint32_t payload[PAYLOAD_ARG_CNT];
  1182. uint32_t val;
  1183. /* Get PLL node ID using PLL clock ID */
  1184. status = pm_clock_get_pll_node_id(clock_id, &nid);
  1185. if (status == PM_RET_SUCCESS) {
  1186. return pm_pll_get_parameter(nid, PM_PLL_PARAM_FBDIV, divider);
  1187. }
  1188. /* Check if clock ID is a valid on-chip clock */
  1189. status = pm_clock_id_is_valid(clock_id);
  1190. if (status != PM_RET_SUCCESS) {
  1191. return status;
  1192. }
  1193. if ((pm_clock_has_div(clock_id, PM_CLOCK_DIV0_ID)) != 0U) {
  1194. /* Send request to the PMU to get div0 */
  1195. PM_PACK_PAYLOAD3(payload, PM_CLOCK_GETDIVIDER, clock_id,
  1196. PM_CLOCK_DIV0_ID);
  1197. status = pm_ipi_send_sync(primary_proc, payload, &val, 1);
  1198. if (status != PM_RET_SUCCESS) {
  1199. return status;
  1200. }
  1201. *divider = val;
  1202. }
  1203. if ((pm_clock_has_div(clock_id, PM_CLOCK_DIV1_ID)) != 0U) {
  1204. /* Send request to the PMU to get div1 */
  1205. PM_PACK_PAYLOAD3(payload, PM_CLOCK_GETDIVIDER, clock_id,
  1206. PM_CLOCK_DIV1_ID);
  1207. status = pm_ipi_send_sync(primary_proc, payload, &val, 1);
  1208. if (status != PM_RET_SUCCESS) {
  1209. return status;
  1210. }
  1211. *divider |= val << 16;
  1212. }
  1213. return status;
  1214. }
  1215. /**
  1216. * pm_clock_setparent - Set the clock parent for given id.
  1217. * @clock_id: Id of the clock.
  1218. * @parent_index: Index of the parent clock into clock's parents array.
  1219. *
  1220. * This function is used by master to set parent for any clock.
  1221. *
  1222. * Return: Returns status, either success or error+reason.
  1223. *
  1224. */
  1225. enum pm_ret_status pm_clock_setparent(uint32_t clock_id,
  1226. uint32_t parent_index)
  1227. {
  1228. struct pm_pll *pll;
  1229. uint32_t payload[PAYLOAD_ARG_CNT];
  1230. enum pm_ret_status status;
  1231. /* First try to handle it as a PLL */
  1232. pll = pm_clock_get_pll_by_related_clk(clock_id);
  1233. if (pll != NULL) {
  1234. return pm_clock_pll_set_parent(pll, clock_id, parent_index);
  1235. }
  1236. /* Check if clock ID is a valid on-chip clock */
  1237. status = pm_clock_id_is_valid(clock_id);
  1238. if (status != PM_RET_SUCCESS) {
  1239. return status;
  1240. }
  1241. /* Send request to the PMU */
  1242. PM_PACK_PAYLOAD3(payload, PM_CLOCK_SETPARENT, clock_id, parent_index);
  1243. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1244. }
  1245. /**
  1246. * pm_clock_getparent - Get the clock parent for given id.
  1247. * @clock_id: Id of the clock.
  1248. * @parent_index: parent index.
  1249. *
  1250. * This function is used by master to get parent index
  1251. * for any clock.
  1252. *
  1253. * Return: Returns status, either success or error+reason.
  1254. *
  1255. */
  1256. enum pm_ret_status pm_clock_getparent(uint32_t clock_id,
  1257. uint32_t *parent_index)
  1258. {
  1259. struct pm_pll *pll;
  1260. uint32_t payload[PAYLOAD_ARG_CNT];
  1261. enum pm_ret_status status;
  1262. /* First try to handle it as a PLL */
  1263. pll = pm_clock_get_pll_by_related_clk(clock_id);
  1264. if (pll != NULL) {
  1265. return pm_clock_pll_get_parent(pll, clock_id, parent_index);
  1266. }
  1267. /* Check if clock ID is a valid on-chip clock */
  1268. status = pm_clock_id_is_valid(clock_id);
  1269. if (status != PM_RET_SUCCESS) {
  1270. return status;
  1271. }
  1272. /* Send request to the PMU */
  1273. PM_PACK_PAYLOAD2(payload, PM_CLOCK_GETPARENT, clock_id);
  1274. return pm_ipi_send_sync(primary_proc, payload, parent_index, 1);
  1275. }
  1276. /**
  1277. * pm_pinctrl_get_num_pins - PM call to request number of pins.
  1278. * @npins: Number of pins.
  1279. *
  1280. * This function is used by master to get number of pins.
  1281. *
  1282. * Return: Returns status, either success or error+reason.
  1283. *
  1284. */
  1285. static enum pm_ret_status pm_pinctrl_get_num_pins(uint32_t *npins)
  1286. {
  1287. return pm_api_pinctrl_get_num_pins(npins);
  1288. }
  1289. /**
  1290. * pm_pinctrl_get_num_functions - PM call to request number of functions.
  1291. * @nfuncs: Number of functions.
  1292. *
  1293. * This function is used by master to get number of functions.
  1294. *
  1295. * Return: Returns status, either success or error+reason.
  1296. *
  1297. */
  1298. static enum pm_ret_status pm_pinctrl_get_num_functions(uint32_t *nfuncs)
  1299. {
  1300. return pm_api_pinctrl_get_num_functions(nfuncs);
  1301. }
  1302. /**
  1303. * pm_pinctrl_get_num_function_groups - PM call to request number of
  1304. * function groups.
  1305. * @fid: Id of function.
  1306. * @ngroups: Number of function groups.
  1307. *
  1308. * This function is used by master to get number of function groups specified
  1309. * by given function Id.
  1310. *
  1311. * Return: Returns status, either success or error+reason.
  1312. *
  1313. */
  1314. static enum pm_ret_status pm_pinctrl_get_num_function_groups(uint32_t fid,
  1315. uint32_t *ngroups)
  1316. {
  1317. return pm_api_pinctrl_get_num_func_groups(fid, ngroups);
  1318. }
  1319. /**
  1320. * pm_pinctrl_get_function_name - PM call to request function name.
  1321. * @fid: Id of function.
  1322. * @name: Name of function.
  1323. *
  1324. * This function is used by master to get name of function specified
  1325. * by given function Id.
  1326. *
  1327. */
  1328. static void pm_pinctrl_get_function_name(uint32_t fid, char *name)
  1329. {
  1330. pm_api_pinctrl_get_function_name(fid, name);
  1331. }
  1332. /**
  1333. * pm_pinctrl_get_function_groups - PM call to request function groups.
  1334. * @fid: Id of function.
  1335. * @index: Index of next function groups.
  1336. * @groups: Function groups.
  1337. *
  1338. * This function is used by master to get function groups specified
  1339. * by given function Id. This API will return 6 function groups with
  1340. * a single response. To get other function groups, master should call
  1341. * same API in loop with new function groups index till error is returned.
  1342. *
  1343. * E.g First call should have index 0 which will return function groups
  1344. * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
  1345. * function groups 6, 7, 8, 9, 10 and 11 and so on.
  1346. *
  1347. * Return: Returns status, either success or error+reason.
  1348. *
  1349. */
  1350. static enum pm_ret_status pm_pinctrl_get_function_groups(uint32_t fid,
  1351. uint32_t index,
  1352. uint16_t *groups)
  1353. {
  1354. return pm_api_pinctrl_get_function_groups(fid, index, groups);
  1355. }
  1356. /**
  1357. * pm_pinctrl_get_pin_groups - PM call to request pin groups.
  1358. * @pin_id: Id of pin.
  1359. * @index: Index of next pin groups.
  1360. * @groups: pin groups.
  1361. *
  1362. * This function is used by master to get pin groups specified
  1363. * by given pin Id. This API will return 6 pin groups with
  1364. * a single response. To get other pin groups, master should call
  1365. * same API in loop with new pin groups index till error is returned.
  1366. *
  1367. * E.g First call should have index 0 which will return pin groups
  1368. * 0, 1, 2, 3, 4 and 5. Next call, index should be 6 which will return
  1369. * pin groups 6, 7, 8, 9, 10 and 11 and so on.
  1370. *
  1371. * Return: Returns status, either success or error+reason.
  1372. *
  1373. */
  1374. static enum pm_ret_status pm_pinctrl_get_pin_groups(uint32_t pin_id,
  1375. uint32_t index,
  1376. uint16_t *groups)
  1377. {
  1378. return pm_api_pinctrl_get_pin_groups(pin_id, index, groups);
  1379. }
  1380. /**
  1381. * pm_query_data() - PM API for querying firmware data.
  1382. * @qid: represents the query identifiers for PM.
  1383. * @arg1: Argument 1 to requested IOCTL call.
  1384. * @arg2: Argument 2 to requested IOCTL call.
  1385. * @arg3: Argument 3 to requested IOCTL call.
  1386. * @data: Returned output data.
  1387. *
  1388. * This function returns requested data.
  1389. *
  1390. */
  1391. void pm_query_data(enum pm_query_ids qid, uint32_t arg1, uint32_t arg2,
  1392. uint32_t arg3, uint32_t *data)
  1393. {
  1394. (void)arg3;
  1395. switch (qid) {
  1396. case PM_QID_CLOCK_GET_NAME:
  1397. pm_clock_get_name(arg1, (char *)data);
  1398. break;
  1399. case PM_QID_CLOCK_GET_TOPOLOGY:
  1400. data[0] = pm_clock_get_topology(arg1, arg2, &data[1]);
  1401. break;
  1402. case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
  1403. data[0] = pm_clock_get_fixedfactor_params(arg1, &data[1],
  1404. &data[2]);
  1405. break;
  1406. case PM_QID_CLOCK_GET_PARENTS:
  1407. data[0] = pm_clock_get_parents(arg1, arg2, &data[1]);
  1408. break;
  1409. case PM_QID_CLOCK_GET_ATTRIBUTES:
  1410. data[0] = pm_clock_get_attributes(arg1, &data[1]);
  1411. break;
  1412. case PM_QID_PINCTRL_GET_NUM_PINS:
  1413. data[0] = pm_pinctrl_get_num_pins(&data[1]);
  1414. break;
  1415. case PM_QID_PINCTRL_GET_NUM_FUNCTIONS:
  1416. data[0] = pm_pinctrl_get_num_functions(&data[1]);
  1417. break;
  1418. case PM_QID_PINCTRL_GET_NUM_FUNCTION_GROUPS:
  1419. data[0] = pm_pinctrl_get_num_function_groups(arg1, &data[1]);
  1420. break;
  1421. case PM_QID_PINCTRL_GET_FUNCTION_NAME:
  1422. pm_pinctrl_get_function_name(arg1, (char *)data);
  1423. break;
  1424. case PM_QID_PINCTRL_GET_FUNCTION_GROUPS:
  1425. data[0] = pm_pinctrl_get_function_groups(arg1, arg2,
  1426. (uint16_t *)&data[1]);
  1427. break;
  1428. case PM_QID_PINCTRL_GET_PIN_GROUPS:
  1429. data[0] = pm_pinctrl_get_pin_groups(arg1, arg2,
  1430. (uint16_t *)&data[1]);
  1431. break;
  1432. case PM_QID_CLOCK_GET_NUM_CLOCKS:
  1433. data[0] = pm_clock_get_num_clocks(&data[1]);
  1434. break;
  1435. case PM_QID_CLOCK_GET_MAX_DIVISOR:
  1436. data[0] = pm_clock_get_max_divisor(arg1, arg2, &data[1]);
  1437. break;
  1438. default:
  1439. data[0] = PM_RET_ERROR_ARGS;
  1440. WARN("Unimplemented query service call: 0x%x\n", qid);
  1441. break;
  1442. }
  1443. }
  1444. enum pm_ret_status pm_sha_hash(uint32_t address_high,
  1445. uint32_t address_low,
  1446. uint32_t size,
  1447. uint32_t flags)
  1448. {
  1449. uint32_t payload[PAYLOAD_ARG_CNT];
  1450. /* Send request to the PMU */
  1451. PM_PACK_PAYLOAD5(payload, PM_SECURE_SHA, address_high, address_low,
  1452. size, flags);
  1453. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1454. }
  1455. enum pm_ret_status pm_rsa_core(uint32_t address_high,
  1456. uint32_t address_low,
  1457. uint32_t size,
  1458. uint32_t flags)
  1459. {
  1460. uint32_t payload[PAYLOAD_ARG_CNT];
  1461. /* Send request to the PMU */
  1462. PM_PACK_PAYLOAD5(payload, PM_SECURE_RSA, address_high, address_low,
  1463. size, flags);
  1464. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1465. }
  1466. enum pm_ret_status pm_secure_image(uint32_t address_low,
  1467. uint32_t address_high,
  1468. uint32_t key_lo,
  1469. uint32_t key_hi,
  1470. uint32_t *value)
  1471. {
  1472. uint32_t payload[PAYLOAD_ARG_CNT];
  1473. /* Send request to the PMU */
  1474. PM_PACK_PAYLOAD5(payload, PM_SECURE_IMAGE, address_high, address_low,
  1475. key_hi, key_lo);
  1476. return pm_ipi_send_sync(primary_proc, payload, value, 2);
  1477. }
  1478. /**
  1479. * pm_fpga_read - Perform the fpga configuration readback.
  1480. * @reg_numframes: Configuration register offset (or) Number of frames to read.
  1481. * @address_low: lower 32-bit Linear memory space address.
  1482. * @address_high: higher 32-bit Linear memory space address.
  1483. * @readback_type: Type of fpga readback operation.
  1484. * 0 -- Configuration Register readback.
  1485. * 1 -- Configuration Data readback.
  1486. * @value: Value to read.
  1487. *
  1488. * This function provides access to the xilfpga library to read
  1489. * the PL configuration.
  1490. *
  1491. * Return: Returns status, either success or error+reason.
  1492. *
  1493. */
  1494. enum pm_ret_status pm_fpga_read(uint32_t reg_numframes,
  1495. uint32_t address_low,
  1496. uint32_t address_high,
  1497. uint32_t readback_type,
  1498. uint32_t *value)
  1499. {
  1500. uint32_t payload[PAYLOAD_ARG_CNT];
  1501. /* Send request to the PMU */
  1502. PM_PACK_PAYLOAD5(payload, PM_FPGA_READ, reg_numframes, address_low,
  1503. address_high, readback_type);
  1504. return pm_ipi_send_sync(primary_proc, payload, value, 1);
  1505. }
  1506. /*
  1507. * pm_pll_set_parameter() - Set the PLL parameter value.
  1508. * @nid: Node id of the target PLL.
  1509. * @param_id: ID of the PLL parameter.
  1510. * @value: Parameter value to be set.
  1511. *
  1512. * Setting the parameter will have physical effect once the PLL mode is set to
  1513. * integer or fractional.
  1514. *
  1515. * Return: Error if an argument is not valid or status as returned by the
  1516. * PM controller (PMU).
  1517. *
  1518. */
  1519. enum pm_ret_status pm_pll_set_parameter(enum pm_node_id nid,
  1520. enum pm_pll_param param_id,
  1521. uint32_t value)
  1522. {
  1523. uint32_t payload[PAYLOAD_ARG_CNT];
  1524. /* Check if given node ID is a PLL node */
  1525. if ((nid < NODE_APLL) || (nid > NODE_IOPLL)) {
  1526. return PM_RET_ERROR_ARGS;
  1527. }
  1528. /* Check if parameter ID is valid and return an error if it's not */
  1529. if (param_id >= PM_PLL_PARAM_MAX) {
  1530. return PM_RET_ERROR_ARGS;
  1531. }
  1532. /* Send request to the PMU */
  1533. PM_PACK_PAYLOAD4(payload, PM_PLL_SET_PARAMETER, nid, param_id, value);
  1534. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1535. }
  1536. /**
  1537. * pm_pll_get_parameter() - Get the PLL parameter value.
  1538. * @nid: Node id of the target PLL.
  1539. * @param_id: ID of the PLL parameter.
  1540. * @value: Location to store the parameter value.
  1541. *
  1542. * Return: Error if an argument is not valid or status as returned by the
  1543. * PM controller (PMU).
  1544. *
  1545. */
  1546. enum pm_ret_status pm_pll_get_parameter(enum pm_node_id nid,
  1547. enum pm_pll_param param_id,
  1548. uint32_t *value)
  1549. {
  1550. uint32_t payload[PAYLOAD_ARG_CNT];
  1551. /* Check if given node ID is a PLL node */
  1552. if ((nid < NODE_APLL) || (nid > NODE_IOPLL)) {
  1553. return PM_RET_ERROR_ARGS;
  1554. }
  1555. /* Check if parameter ID is valid and return an error if it's not */
  1556. if (param_id >= PM_PLL_PARAM_MAX) {
  1557. return PM_RET_ERROR_ARGS;
  1558. }
  1559. /* Send request to the PMU */
  1560. PM_PACK_PAYLOAD3(payload, PM_PLL_GET_PARAMETER, nid, param_id);
  1561. return pm_ipi_send_sync(primary_proc, payload, value, 1);
  1562. }
  1563. /**
  1564. * pm_pll_set_mode() - Set the PLL mode.
  1565. * @nid: Node id of the target PLL.
  1566. * @mode: PLL mode to be set.
  1567. *
  1568. * If reset mode is set the PM controller will first bypass the PLL and then
  1569. * assert the reset. If integer or fractional mode is set the PM controller will
  1570. * ensure that the complete PLL programming sequence is satisfied. After this
  1571. * function returns success the PLL is locked and its bypass is deasserted.
  1572. *
  1573. * Return: Error if an argument is not valid or status as returned by the
  1574. * PM controller (PMU).
  1575. *
  1576. */
  1577. enum pm_ret_status pm_pll_set_mode(enum pm_node_id nid, enum pm_pll_mode mode)
  1578. {
  1579. uint32_t payload[PAYLOAD_ARG_CNT];
  1580. /* Check if given node ID is a PLL node */
  1581. if ((nid < NODE_APLL) || (nid > NODE_IOPLL)) {
  1582. return PM_RET_ERROR_ARGS;
  1583. }
  1584. /* Check if PLL mode is valid */
  1585. if (mode >= PM_PLL_MODE_MAX) {
  1586. return PM_RET_ERROR_ARGS;
  1587. }
  1588. /* Send request to the PMU */
  1589. PM_PACK_PAYLOAD3(payload, PM_PLL_SET_MODE, nid, mode);
  1590. return pm_ipi_send_sync(primary_proc, payload, NULL, 0);
  1591. }
  1592. /**
  1593. * pm_pll_get_mode() - Get the PLL mode.
  1594. * @nid: Node id of the target PLL.
  1595. * @mode: Location to store the mode of the PLL.
  1596. *
  1597. * Return: Error if an argument is not valid or status as returned by the
  1598. * PM controller (PMU).
  1599. *
  1600. */
  1601. enum pm_ret_status pm_pll_get_mode(enum pm_node_id nid, enum pm_pll_mode *mode)
  1602. {
  1603. uint32_t payload[PAYLOAD_ARG_CNT];
  1604. /* Check if given node ID is a PLL node */
  1605. if ((nid < NODE_APLL) || (nid > NODE_IOPLL)) {
  1606. return PM_RET_ERROR_ARGS;
  1607. }
  1608. /* Send request to the PMU */
  1609. PM_PACK_PAYLOAD2(payload, PM_PLL_GET_MODE, nid);
  1610. return pm_ipi_send_sync(primary_proc, payload, mode, 1);
  1611. }
  1612. /**
  1613. * pm_register_access() - PM API for register read/write access data.
  1614. * @register_access_id: Register_access_id which says register read/write.
  1615. * @address: Address of the register to be accessed.
  1616. * @mask: Mask value to be used while writing value.
  1617. * @value: Value to be written to register.
  1618. * @out: Returned output data.
  1619. *
  1620. * This function returns requested data.
  1621. *
  1622. * Return: Returns status, either success or error+reason.
  1623. *
  1624. */
  1625. enum pm_ret_status pm_register_access(uint32_t register_access_id,
  1626. uint32_t address,
  1627. uint32_t mask,
  1628. uint32_t value,
  1629. uint32_t *out)
  1630. {
  1631. enum pm_ret_status ret;
  1632. if (((ZYNQMP_CSU_BASEADDR & address) != ZYNQMP_CSU_BASEADDR) &&
  1633. ((CSUDMA_BASE & address) != CSUDMA_BASE) &&
  1634. ((RSA_CORE_BASE & address) != RSA_CORE_BASE) &&
  1635. ((PMU_GLOBAL_BASE & address) != PMU_GLOBAL_BASE)) {
  1636. return PM_RET_ERROR_ACCESS;
  1637. }
  1638. switch (register_access_id) {
  1639. case CONFIG_REG_WRITE:
  1640. ret = pm_mmio_write(address, mask, value);
  1641. break;
  1642. case CONFIG_REG_READ:
  1643. ret = pm_mmio_read(address, out);
  1644. break;
  1645. default:
  1646. ret = PM_RET_ERROR_ARGS;
  1647. WARN("Unimplemented register_access call\n\r");
  1648. break;
  1649. }
  1650. return ret;
  1651. }
  1652. /**
  1653. * pm_efuse_access() - To program or read efuse bits. This function provides
  1654. * access to the xilskey library to program/read
  1655. * efuse bits.
  1656. * @address_low: lower 32-bit Linear memory space address.
  1657. * @address_high: higher 32-bit Linear memory space address.
  1658. * @value: Returned output value.
  1659. *
  1660. * Return: Returns status, either success or error+reason.
  1661. *
  1662. */
  1663. enum pm_ret_status pm_efuse_access(uint32_t address_high,
  1664. uint32_t address_low,
  1665. uint32_t *value)
  1666. {
  1667. uint32_t payload[PAYLOAD_ARG_CNT];
  1668. /* Send request to the PMU */
  1669. PM_PACK_PAYLOAD3(payload, PM_EFUSE_ACCESS, address_high, address_low);
  1670. return pm_ipi_send_sync(primary_proc, payload, value, 1);
  1671. }