upower_soc_defs.h 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /**
  3. * Copyright 2019-2024 NXP
  4. *
  5. * KEYWORDS: micro-power uPower driver API
  6. * -----------------------------------------------------------------------------
  7. * PURPOSE: SoC-dependent uPower driver API #defines and typedefs shared
  8. * with the firmware
  9. * -----------------------------------------------------------------------------
  10. * PARAMETERS:
  11. * PARAM NAME RANGE:DESCRIPTION: DEFAULTS: UNITS
  12. * -----------------------------------------------------------------------------
  13. * REUSE ISSUES: no reuse issues
  14. */
  15. #ifndef UPWR_SOC_DEFS_H
  16. #define UPWR_SOC_DEFS_H
  17. #include <stdbool.h>
  18. #include <stdint.h>
  19. #include "upower_defs.h"
  20. #define UPWR_MU_MSG_SIZE (2U) /* words */
  21. #ifdef NUM_PMC_SWT_WORDS
  22. #define UPWR_PMC_SWT_WORDS NUM_PMC_SWT_WORDS
  23. #endif
  24. #ifdef NUM_PMC_RAM_WORDS
  25. #define UPWR_PMC_MEM_WORDS NUM_PMC_RAM_WORDS
  26. #endif
  27. #ifndef UPWR_DRAM_SHARED_BASE_ADDR
  28. #define UPWR_DRAM_SHARED_BASE_ADDR (0x28330000U)
  29. #endif
  30. #ifndef UPWR_DRAM_SHARED_SIZE
  31. #define UPWR_DRAM_SHARED_SIZE (2048U)
  32. #endif
  33. #define UPWR_DRAM_SHARED_ENDPLUS (UPWR_DRAM_SHARED_BASE_ADDR+\
  34. UPWR_DRAM_SHARED_SIZE)
  35. #ifndef UPWR_API_BUFFER_BASE
  36. #define UPWR_API_BUFFER_BASE (0x28330600U)
  37. #endif
  38. #ifndef UPWR_API_BUFFER_ENDPLUS
  39. #define UPWR_API_BUFFER_ENDPLUS (UPWR_DRAM_SHARED_ENDPLUS - 64U)
  40. #endif
  41. #ifndef UPWR_PMC_SWT_WORDS
  42. #define UPWR_PMC_SWT_WORDS (1U)
  43. #endif
  44. #ifndef UPWR_PMC_MEM_WORDS
  45. #define UPWR_PMC_MEM_WORDS (2U)
  46. #endif
  47. #define UPWR_OSC_HI_FREQ (64U) // MHz
  48. #define UPWR_OSC_LO_FREQ (16U) // MHz
  49. #ifndef UPWR_I2C_FREQ
  50. #define UPWR_I2C_FREQ (UPWR_OSC_HI_FREQ * 1000000U)
  51. #endif
  52. /*
  53. * i.MX8ULP-dependent uPower API Definition
  54. *
  55. * This chapter documents the API definitions that are specific to the
  56. * i.MX8ULP SoC.
  57. *
  58. */
  59. /**---------------------------------------------------------------
  60. * INITIALIZATION, CONFIGURATION
  61. *
  62. * i.MX8ULP provides only one Message Unit (MU) for each core domain:
  63. * Real Time Domain (RTD) and Application Domain (APD), which has two A35 cores.
  64. * Both A35 cores in APD must share the same API instance, meaning upwr_init
  65. * must be called only once for each domain. The API does not provide any
  66. * mutually exclusion or locking mechanism for concurrent accesses from both
  67. * APD cores, so any API arbitration, if needed, must be implemented by the
  68. * API user code.
  69. *
  70. * A domain must not go to Power Down (PD) or Deep Power Down (DPD) power modes
  71. * with any service still pending (response not received).
  72. *
  73. * Next sections describe the i.MX8ULP particularities of service calls.
  74. *
  75. */
  76. /**+
  77. * upwr_start()
  78. *
  79. * i.MX8ULP ROM firmware provides only the launch option 0, which has no
  80. * power mode transition support and provides the following services:
  81. * - upwr_xcp_config
  82. * - upwr_xcp_sw_alarm
  83. * - upwr_pwm_param
  84. * - upwr_pwm_power_on
  85. * - upwr_pwm_power-off
  86. * - upwr_pwm_mem_retain
  87. * - upwr_pwm_chng_dom_bias
  88. * - upwr_pwm_chng_mem_bias
  89. *
  90. * i.MX8ULP RAM firmware provides 2 launch options:
  91. *
  92. * 1. starts all tasks, services and power mode ones;
  93. * this is the full-featured firmware option.
  94. * 2. starts only the power mode tasks; services are not available with
  95. * this option, and futher calls to upwr_start (from either domain)
  96. * have no response; this option is mostly used to accelerate power mode
  97. * mixed-signal simulations, and not intended to be used with silicon.
  98. *
  99. * Note: option 0 is also available if the RAM firmware is loaded.
  100. */
  101. /* service upwr_pwm_set_domain_pmic_rail message argument fields*/
  102. typedef struct {
  103. uint32_t domain : 16U;
  104. uint32_t rail : 16U;
  105. } upwr_pwm_dom_pmic_rail_args;
  106. #define UPWR_FILL_DOMBIAS_ARGS(dom, bias, args) \
  107. do { \
  108. (args).B.domapply = (args).B.avdapply = 0U; \
  109. switch ((bias)->apply) { \
  110. case BIAS_APPLY_RTD_AVD: \
  111. (args).B.avdapply = 1U; \
  112. /* fall through */ \
  113. case BIAS_APPLY_RTD: \
  114. (dom) = (uint32_t)RTD_DOMAIN; \
  115. (args).B.domapply = 1U; \
  116. break; \
  117. case BIAS_APPLY_APD_AVD: \
  118. (args).B.avdapply = 1U; \
  119. /* fall through */ \
  120. case BIAS_APPLY_APD: \
  121. (dom) = (uint32_t)APD_DOMAIN; \
  122. (args).B.domapply = 1U; \
  123. break; \
  124. case BIAS_APPLY_AVD: \
  125. (args).B.avdapply = 1U; \
  126. break; \
  127. default: \
  128. break; \
  129. } \
  130. (args).B.dommode = (uint32_t)((bias)->dommode); \
  131. (args).B.avdmode = (uint32_t)((bias)->avdmode); \
  132. uint32_t sat = UPWR_BIAS2MILIV((1UL << UPWR_DOMBIAS_RBB_BITS) - 1UL);\
  133. (args).B.domrbbn = ((bias)->dombias.rbbn > sat) ? sat : \
  134. UPWR_BIAS_MILIV((bias)->dombias.rbbn); \
  135. (args).B.domrbbp = ((bias)->dombias.rbbp > sat) ? sat : \
  136. UPWR_BIAS_MILIV((bias)->dombias.rbbp); \
  137. (args).B.avdrbbn = ((bias)->avdbias.rbbn > sat) ? sat : \
  138. UPWR_BIAS_MILIV((bias)->avdbias.rbbn); \
  139. (args).B.avdrbbp = ((bias)->avdbias.rbbp > sat) ? sat : \
  140. UPWR_BIAS_MILIV((bias)->avdbias.rbbp); \
  141. } while (false)
  142. #define UPWR_FILL_MEMBIAS_ARGS(bias, args) \
  143. do { \
  144. (args).B.en = (bias)->en; \
  145. } while (false)
  146. #define UPWR_APD_CORES (2U)
  147. #define UPWR_RTD_CORES (1U)
  148. #define RTD_DOMAIN (0U)
  149. #define APD_DOMAIN (1U)
  150. #define UPWR_MAIN_DOMAINS (2U)
  151. #define AVD_DOMAIN (2U)
  152. #define UPWR_DOMAIN_COUNT (3U)
  153. #define PSD_DOMAIN (3U)
  154. #define UPWR_ALL_DOMAINS (4U)
  155. typedef uint32_t soc_domain_t;
  156. /*=========================================================================
  157. * UNIT CONVERSION MACROS
  158. * These macros convert physical units to the values passed as arguments
  159. * in API functions.
  160. *=========================================================================
  161. */
  162. #define UPWR_VOLT_MILIV(v) (v) /* voltage in mV to argument value */
  163. #define UPWR_VOLT_MICROV(v)((v) / 1000U) /* voltage in uV to argument value */
  164. #define UPWR_BIAS_MILIV(v) (((v) + 49UL) / 50UL) /* bias voltage(mV) to argument value */
  165. #define UPWR_BIAS2MILIV(v) ((v) * 50UL) /* inverse of UPWR_BIAS_MILIV */
  166. #define UPWR_FREQ_KHZ(f) (f) /* frequency (kHz) to argument value */
  167. #define UPWR_DOMBIAS_MAX_MV (UPWR_BIAS2MILIV((1U << UPWR_DOMBIAS_RBB_BITS) - 1U))
  168. /**---------------------------------------------------------------
  169. * EXCEPTION SERVICE GROUP
  170. */
  171. /**+
  172. * upwr_xcp_config()
  173. *
  174. * The i.MX8ULP uPower configuration struct contains the following bitfields:
  175. *
  176. * - ALARM_INT (1 bit): tells which RTD MU interrupt should be used for alarms;
  177. * 1= MU GPI1; 0= MU GPI0; APD alarms always use GPI0.
  178. * - CFG_IOMUX (1 bit): determintes if uPower configures i.MX8ULP IOMUX for
  179. * I2C and mode pins used to control an external PMIC;
  180. * 1= uPower firmware or PMIC driver configures i.MX8ULP IOMUX and mode pins;
  181. * 0= i.MX8ULP IOMUX and mode pins not configured by uPower;
  182. * - DGNBUFBITS (4 bits): determines the diagnostic buffer size according to
  183. * the formula: size = 2^(DGNBUFBITS+3) bytes;
  184. *
  185. * Defaults are all zeroes; all other bits are reserved, and must be written 0.
  186. */
  187. typedef union {
  188. uint32_t R;
  189. struct {
  190. uint32_t ALARM_INT : 1U;
  191. uint32_t CFG_IOMUX : 1U;
  192. uint32_t DGNBUFBITS : 4U;
  193. uint32_t RSV : 26U;
  194. } B;
  195. } upwr_xcp_config_t;
  196. /**+
  197. * upwr_xcp_sw_alarm()
  198. *
  199. * Argument code is defined by the enum upwr_alarm_t, with the values:
  200. * - UPWR_ALARM_INTERNAL: internal software error
  201. * - UPWR_ALARM_EXCEPTION: uPower core exception, either illegal instruction or
  202. * bus error
  203. * - UPWR_ALARM_SLACK: delay path too slow, meaning a timing violation occurred
  204. * or is iminent.
  205. * - UPWR_ALARM_VOLTAGE: one of the measured voltages is below safety margins.
  206. *
  207. * Note that this service emulates an alarm that would normally be issued by
  208. * uPower when it detects one of the causes above. A request to alarm the APD
  209. * domain when it is powered off returns success, but is ineffective.
  210. *
  211. */
  212. #define UPWR_ALARM_INTERNAL (0U) /* internal error */
  213. #define UPWR_ALARM_EXCEPTION (1U) /* core exception */
  214. #define UPWR_ALARM_SLACK (2U) /* delay path too slow */
  215. #define UPWR_ALARM_VOLTAGE (3U) /* voltage drop */
  216. #define UPWR_ALARM_LAST UPWR_ALARM_VOLTAGE
  217. typedef uint32_t upwr_alarm_t;
  218. /**---------------------------------------------------------------
  219. * POWER MANAGEMENT SERVICE GROUP
  220. */
  221. /* values in mV: */
  222. #define UPWR_RTD_RBBN_MAX (1300U) /* max. RTD Reverse Back Bias N-Well */
  223. #define UPWR_RTD_RBBN_MIN (100U) /* min. RTD Reverse Back Bias N-Well */
  224. #define UPWR_RTD_RBBP_MAX (1300U) /* max. RTD Reverse Back Bias P-Well */
  225. #define UPWR_RTD_RBBP_MIN (100U) /* min. RTD Reverse Back Bias P-Well */
  226. /* APD bias can only two values (mV): */
  227. #define UPWR_APD_RBBN_LO (1000U) /* low APD Reverse Back Bias N-Well */
  228. #define UPWR_APD_RBBN_HI (1300U) /* high APD Reverse Back Bias N-Well */
  229. #define UPWR_APD_RBBP_LO (1000U) /* low APD Reverse Back Bias P-Well */
  230. #define UPWR_APD_RBBP_HI (1300U) /* high APD Reverse Back Bias P-Well */
  231. /* AVD bias can only two values (mV): */
  232. #define UPWR_AVD_RBBN_LO (1000U) /* low AVD Reverse Back Bias N-Well */
  233. #define UPWR_AVD_RBBN_HI (1300U) /* high AVD Reverse Back Bias N-Well */
  234. #define UPWR_AVD_RBBP_LO (1000U) /* low AVD Reverse Back Bias P-Well */
  235. #define UPWR_AVD_RBBP_HI (1300U) /* high AVD Reverse Back Bias P-Well */
  236. /**+
  237. * upwr_pwm_param()
  238. *
  239. * Argument param is defined by the struct/union upwr_pwm_param_t with the
  240. * following i.MX8ULP-specific bitfields:
  241. * - DPD_ALLOW (1 bit): 1= allows uPower power mode to go Deep Power Down (DPD);
  242. * uPower DPD also depends on other conditions, but if this bit is 0 uPower
  243. * won't go DPD even if those conditions are met; it can go either Sleep or
  244. * Deep Sleep (DSL) depending on the other configurations.
  245. * - DSL_DIS (1 bit): if this bit is 1, uPower power mode won't go Deep Sleep
  246. * (DSL) even if the other conditions for that are met;
  247. * it may go Sleep instead.
  248. * - SLP_ALLOW (1 bit): if this bit is 1, uPower power mode will go Sleep if
  249. * the conditions for Partial Active are met; it may also go Deep Sleep if bit
  250. * DSL_DIS=1.
  251. * - DSL_BGAP_OFF (1 bit): 1= turns bandgap off when uPower goes Deep Sleep;
  252. * 0= leaves bandgap on when uPower goes Deep Sleep (DSL).
  253. * - DPD_BGAP_ON (1 bit): 1= leaves bandgap on when uPower goes Deep Power Down
  254. * (DPD); 0= powers off bandgap when uPower goes Deep Power Down (DPD).
  255. *
  256. * Defaults are all zeroes; all other bits are reserved, and must be written 0.
  257. */
  258. typedef union {
  259. uint32_t R;
  260. struct {
  261. uint32_t DPD_ALLOW : 1U;
  262. uint32_t DSL_DIS : 1U;
  263. uint32_t SLP_ALLOW : 1U;
  264. uint32_t DSL_BGAP_OFF : 1U;
  265. uint32_t DPD_BGAP_ON : 1U;
  266. uint32_t RSV : 27U;
  267. } B;
  268. } upwr_pwm_param_t;
  269. /**+
  270. * upwr_pwm_chng_reg_voltage()
  271. *
  272. * Argument reg is defined by the enum upwr_pmc_reg_t, with regulator ids:
  273. * - RTD_PMC_REG: RTD regulator
  274. * - APD_PMC_REG: APD regulator
  275. * - RTD_BIAS_PMC_REG: RTD bias regulator
  276. * - APD_BIAS_PMC_REG: APD bias regulator
  277. * - RTD_LVD_PMC_MON: RTD LVD regulator
  278. * - APD_LVD_PMC_MON: APD LVD regulator
  279. * - AVD_LVD_PMC_MON: AVD LVD regulator
  280. *
  281. * Argument volt is defined by the formula:
  282. *
  283. * argument = 92.30797633*V - 55.000138, rounded to the nearest integer,
  284. * where V is the value in Volts, with a minimum of 0.595833 V (argument = 0).
  285. *
  286. */
  287. /* Regulator ids */
  288. typedef enum {
  289. RTD_PMC_REG,
  290. APD_PMC_REG,
  291. RTD_BIAS_PMC_REG,
  292. APD_BIAS_PMC_REG,
  293. RTD_LVD_PMC_MON,
  294. APD_LVD_PMC_MON,
  295. AVD_LVD_PMC_MON
  296. } upwr_pmc_reg_t;
  297. /**+
  298. * upwr_pwm_freq_setup()
  299. *
  300. * Argument domain is either RTD_DOMAIN or APD_DOMAIN.
  301. * Arguments nextfq and currfq are to be defined (TBD).
  302. */
  303. /**+
  304. * upwr_pwm_dom_power_on()
  305. *
  306. * The arguments must comply with the restrictions below, otherwise the service
  307. * is not executed and returns error UPWR_RESP_BAD_REQ:
  308. * - argument domain can only be APD_DOMAIN, because in i.MX8ULP it is not
  309. * possible APD powered on (calling the service) with RTD completely
  310. * powered off.
  311. * - the call can only be made from the RTD domain, for the same reason.
  312. * - argument boot can only be 1, because in i.MX8ULP it is not possible to
  313. * power on the APD domain without starting the core boot.
  314. *
  315. * If APD is already powered on and booting/booted when the service is called,
  316. * it returns success without doing anything.
  317. */
  318. /**+
  319. * upwr_pwm_boot_start()
  320. *
  321. * The arguments must comply with the restrictions below, otherwise the service
  322. * is not executed and returns error UPWR_RESP_BAD_REQ:
  323. * - argument domain can only be APD_DOMAIN, because in i.MX8ULP it is not
  324. * possible APD powered on (calling the service) with RTD completely
  325. * powered off.
  326. * - the call can only be made from the RTD domain, for the same reason.
  327. *
  328. * If APD is already booted when the service is called, it returns success
  329. * without doing anything. Otherwise, it returns the error UPWR_RESP_BAD_STATE,
  330. * because in i.MX8ULP APD cannot be booted separately from power on.
  331. */
  332. /**+
  333. * upwr_pwm_power_on(),
  334. * upwr_pwm_power_off(),
  335. * upwr_pwm_mem_retain()
  336. *
  337. * These three service functions use the same arguments:
  338. *
  339. * argument swt is an array of one 32-bit word: uint32_t swt[1];
  340. * naturally the pointer to a single uint32_t variable may be passed.
  341. * Each bit of the word corresponds to a switch, according to the i.MX8ULP
  342. * Reference Manual Rev B draft 2 table 64 Power switch reset state,
  343. * and the following formula:
  344. *
  345. * if switch number < 10 bit number = switch number;
  346. * if switch number > 9 bit number = switch number + 3;
  347. *
  348. * bits 9, 10, 11 and 12 must have the same value (corresponding to switch 9)
  349. *
  350. * Note: this argument is not used in upwr_pwm_mem_retain.
  351. *
  352. * argument mem is an array of two 32-bit words: uint32_t mem[2];
  353. * naturally the pointer to a single uint64_t variable may be passed, since
  354. * both ARM and RISC-V are little endian architectures.
  355. * Each bit of the words corresponds to a memory, according to the i.MX8ULP
  356. * Reference Manual table "Memory Partitions".
  357. *
  358. * Turning a memory completely on (array and peripheral) will automatically
  359. * turn on its power switch, even if not explicitly commanded.
  360. * Turning a memory's power switch off will automatically turn off its array
  361. * and peripheral beforehand, even if not explicitly commanded.
  362. *
  363. * Argument restrictions:
  364. *
  365. * The swt and mem arguments must comply with the restrictions below, otherwise
  366. * the service is not executed (no switch/memory is changed) and returns error
  367. * UPWR_RESP_BAD_REQ:
  368. * 1. one must not put a memory in retention coming from an off state.
  369. * 2. switches 9, 10, 11 and 12 must be turned on/off simultaneously.
  370. * 3. an AVD switch can only be turned off if all AVD switches belong to the
  371. * domain requesting the service (as defined by registers SYSCTRL0,
  372. * LPAV_MASTER_ALLOC_CTRL and LPAV_SLAVE_ALLOC_CTRL);
  373. * there is no such restriction to turn the switch on.
  374. * 4. an AVD memory can only be turned off or put in retention if all
  375. * AVD memories belong to the domain requesting the service
  376. * (as defined by registers SYSCTRL0, LPAV_MASTER_ALLOC_CTRL and
  377. * LPAV_SLAVE_ALLOC_CTRL); there is no such restriction to turn on the
  378. * memories.
  379. * 5. EdgeLock RAMs must not be turned off, unless RTD domain is in
  380. * Deep Power Down (DPD).
  381. * 6. Power Switch 19 must be on to turn on switches 17 (MIPI/DSI),
  382. * 18 (MIPI/CSI), and all AVD power switches.
  383. *
  384. * Service Errors:
  385. *
  386. * Besides the error UPWR_RESP_BAD_REQ caused by violations of the restrictions
  387. * above, the services may fail with error UPWR_RESP_RESOURCE if a power mode
  388. * transition or a similar service is executing at the same time.
  389. * This error should be interpreted as a "try later" response, as the service
  390. * will succeed once those concurrent executions are done, and no other is
  391. * started.
  392. */
  393. /**+
  394. * upwr_pwm_chng_switch_mem()
  395. *
  396. * The bit numbers in the argument struct mask and on/off state fields
  397. * are the same as for services upwr_pwm_power_on, upwr_pwm_power_off and
  398. * upwr_pwm_mem_retain.
  399. *
  400. * Turning a memory completely on (array and peripheral) will automatically
  401. * turn on its power switch, even if not explicitly commanded.
  402. *
  403. * Argument restrictions:
  404. *
  405. * Same argument restrictions as services upwr_pwm_power_on, upwr_pwm_power_off
  406. * and upwr_pwm_mem_retain, plus the following:
  407. *
  408. * 1. one must not turn a memory peripheral on and a memory array off.
  409. * 2. one must not put a memory in retention and switch its power switch off.
  410. *
  411. * Service Errors:
  412. *
  413. * Besides the error UPWR_RESP_BAD_REQ caused by violations of the restrictions
  414. * above, the service may fail with error UPWR_RESP_RESOURCE if a power mode
  415. * transition or a similar service is executing at the same time.
  416. * This error should be interpreted as a "try later" response, as the service
  417. * will succeed once those concurrent executions are done, and no other is
  418. * started.
  419. */
  420. /**+
  421. * upwr_pwm_pmode_config()
  422. *
  423. * The same power switch and memory restrictions of service
  424. * upwr_pwm_chng_switch_mem apply between power modes, however they are not
  425. * enforced by this service, that is, it does not return service error.
  426. *
  427. * The default power mode configurations for RTD and APD are documented in the
  428. * i.MX8ULP Reference Manual sections "Power mode details (real-time domain)"
  429. * and "Power mode details (application domain)", respectively.
  430. * If those configurations are satisfactory, this service does not have
  431. * to be called.
  432. *
  433. * Power Mode Configuration Structure:
  434. *
  435. * Follows a description of the power mode configuration structure elements.
  436. * - dom_swts: the same switch configuration structures used in service
  437. * upwr_pwm_chng_switch_mem argument swt.
  438. * - mem_swts: the same memory configuration structures used in service
  439. * upwr_pwm_chng_switch_mem argument mem.
  440. * - regs: an array of structs base_reg_cfg_t (see upower_soc_defs.h),
  441. * one element for each regulator; base_reg_cfg_t has fields
  442. * mode (regulator-dependent), lvl (voltage level in uV),
  443. * comp (regulator-dependent complamentary info).
  444. * - pads: pad configuration in low power; see pad_cfg_t definition below.
  445. * - mons: domain monitors (LVD and HVD) configuration;
  446. * see mon_cfg_t definition below.
  447. * - avd_mons: same as mons for the AVD domain; see mon_cfg_t definition below.
  448. * - dom_bbias: back-bias configuration for the domain;
  449. * see base_bbias_cfg_t definition below.
  450. * - avd_bbias: back-bias configuration for the AVD domain;
  451. * see base_bbias_cfg_t definition below.
  452. * - mem_bbias: back-bias configuration for the memory;
  453. * see base_bbias_cfg_t definition below.
  454. * - mem_fbias: forward-bias configuration for the memory;
  455. * see base_fbias_cfg_t definition below.
  456. * - pmic: PMIC-specific configuration
  457. *
  458. * Structure pad_cfg_t:
  459. *
  460. * Pad control for low power modes (power off, etc), 1 bit per pad segment.
  461. * - rst : put pad segment in reset.
  462. * - iso : put pad segment in isolation.
  463. * - compl: specific pad segment information.
  464. * - msk : select which pads will be updated.
  465. *
  466. * Structure mon_cfg_t:
  467. *
  468. * Configures a voltage monitor and its actions.
  469. * There are monitors for RTD, APD and AVD, monitoring LVD and HVD.
  470. * - lvl : Voltage level (in uV).
  471. * - mode : Mode of monitor (ON, OFF, LP, etc).
  472. * - compl: Extra info for the monitor.
  473. *
  474. * Structure base_bbias_cfg_t:
  475. *
  476. * Configures back-bias (for domain or memory).
  477. * - mode : Back bias mode (OFF, RBB, ARBB, etc).
  478. * - p_lvl: Voltage level of p-well (in mV).
  479. * - n_lvl: Voltage level of n-well (in mV).
  480. * - compl: Complementary bias-specific (enable reset, interrupt, clamp, etc).
  481. *
  482. * Structure base_fbias_cfg_t:
  483. *
  484. * Configure memory forward bias for a memory segment.
  485. *
  486. * - mode : Forward bias mode (OFF, ON).
  487. * - msk : Selects which memory will be updated
  488. *
  489. */
  490. /*=========================================================================
  491. * Domain bias
  492. *=========================================================================
  493. */
  494. /**+
  495. * upwr_pwm_chng_dom_bias()
  496. *
  497. * Argument bias is a pointer to a struct with fields:
  498. * - apply: tells to which domains the bias must be applied;
  499. * options are RTD only (BIAS_APPLY_RTD), RTD and AVD (BIAS_APPLY_RTD_AVD),
  500. * APD only (BIAS_APPLY_APD), APD and AVD (BIAS_APPLY_APD_AVD),
  501. * AVD only (BIAS_APPLY_AVD)
  502. * - dommode: bias mode of the main domain (RTD or APD, determined by apply);
  503. * options are disabled (NBB_BIAS_MODE), reverse back bias (RBB_BIAS_MODE),
  504. * asymmetrical forward bias (AFBB_BIAS_MODE), asymmetrical reverse bias
  505. * (ARBB_BIAS_MODE).
  506. * - avdmode: bias mode of Audio-Video Domain (AVD);
  507. * options are the same as dommode.
  508. * - dombias: bias voltage level(s) for the main domain (RTD or APD,
  509. * determined by apply); it is a structure with 2 fields, rbbn and rbbp,
  510. * for the N-well and P-well voltages, respectively; values are in mV.
  511. * - avdbias: bias voltage level(s) for the Audio-Video Domain (AVD);
  512. * same fields as dombias;
  513. *
  514. * Argument restrictions:
  515. *
  516. * Voltage levels must comply with the #define-determined limits/options:
  517. * between UPWR_RTD_RBBN_MIN and UPWR_RTD_RBBN_MAX (inclusive) for RTD N-well;
  518. * between UPWR_RTD_RBBP_MIN and UPWR_RTD_RBBP_MAX (inclusive) for RTD P-well;
  519. * either UPWR_APD_RBBN_LO or UPWR_APD_RBBN_HI for APD N-well;
  520. * either UPWR_APD_RBBP_LO or UPWR_APD_RBBP_HI for APD P-well;
  521. * either UPWR_AVD_RBBN_LO or UPWR_AVD_RBBN_HI for AVD N-well;
  522. * either UPWR_AVD_RBBP_LO or UPWR_AVD_RBBP_HI for AVD P-well;
  523. *
  524. * But note that the limits/options above do not apply to all bias modes:
  525. * rbbn is used and checked only in mode RBB_BIAS_MODE;
  526. * rbbp is used and checked only in modes RBB_BIAS_MODE and ARBB_BIAS_MODE;
  527. * modes AFBB_BIAS_MODE and NBB_BIAS_MODE use or check neither rbbn nor rbbp;
  528. *
  529. * Service error UPWR_RESP_BAD_REQ is returned if the voltage limits/options
  530. * above are violated.
  531. */
  532. /* argument struct for service upwr_pwm_chng_dom_bias:
  533. */
  534. typedef enum { /* bias modes (both domain and memory): */
  535. NBB_BIAS_MODE = 0, /* bias disabled */
  536. RBB_BIAS_MODE = 1, /* reverse back bias enabled */
  537. AFBB_BIAS_MODE = 2, /* asymmetrical forward bias */
  538. ARBB_BIAS_MODE = 3 /* asymmetrical reverse bias */
  539. } upwr_bias_mode_t;
  540. /* Domain Bias config (one per domain) */
  541. typedef enum {
  542. BIAS_APPLY_RTD, /* apply to RTD only */
  543. BIAS_APPLY_RTD_AVD, /* apply to RTD and AVD */
  544. BIAS_APPLY_APD, /* apply to APD only */
  545. BIAS_APPLY_APD_AVD, /* apply to APD and AVD */
  546. BIAS_APPLY_AVD, /* apply to AVD only */
  547. BIAS_APPLY_COUNT /* number of apply options */
  548. } upwr_bias_apply_t;
  549. typedef struct {
  550. uint16_t rbbn; /* reverse back bias N well (mV) */
  551. uint16_t rbbp; /* reverse back bias P well (mV) */
  552. } upwr_rbb_t;
  553. struct upwr_dom_bias_cfg_t {
  554. upwr_bias_apply_t apply; /* bias application option */
  555. upwr_bias_mode_t dommode; /* RTD/APD bias mode config */
  556. upwr_bias_mode_t avdmode; /* AVD bias mode config */
  557. upwr_rbb_t dombias; /* RTD/APD reverse back bias */
  558. upwr_rbb_t avdbias; /* AVD reverse back bias */
  559. };
  560. /* bias struct used in power mode config definitions */
  561. /**
  562. * When write power mode transition program, please read below comments carefully.
  563. * The structure and logic is complex, There is a lot of extension and reuse.
  564. *
  565. * First, for mode, extend "uint32_t mode" to a union struct, add support for AVD:
  566. * typedef union {
  567. * uint32_t R;
  568. * struct {
  569. * uint32_t mode : 8;
  570. * uint32_t rsrv_1 : 8;
  571. * uint32_t avd_mode : 8;
  572. * uint32_t rsrv_2 : 8;
  573. * } B;
  574. * } dom_bias_mode_cfg_t;
  575. Second, if mode is AFBB mode, no need to configure rbbn and rbbp, uPower firmware
  576. will configure all SRAM_AFBB_0 or SRAM_AFBB_1 for corresponding domain.
  577. Third, if mode is RBB mode, extend "uint32_t rbbn" and "uint32_t rbbp" to a union
  578. struct, add support for AVD:
  579. typedef union {
  580. uint32_t R;
  581. struct {
  582. uint32_t lvl : 8;
  583. uint32_t rsrv_1 : 8;
  584. uint32_t avd_lvl : 8;
  585. uint32_t rsrv_2 : 8;
  586. } B;
  587. } dom_bias_lvl_cfg_t;
  588. *
  589. */
  590. typedef struct {
  591. uint32_t mode; /* Domain bias mode config, extend to dom_bias_mode_cfg_t to support RTD, APD, AVD */
  592. uint32_t rbbn; /* reverse back bias N well */
  593. uint32_t rbbp; /* reverse back bias P well */
  594. } UPWR_DOM_BIAS_CFG_T;
  595. /*=========================================================================
  596. * Memory bias
  597. *=========================================================================
  598. */
  599. /**+
  600. * upwr_pwm_chng_mem_bias()
  601. *
  602. * Argument struct contains only the field en, which can be either 1 (bias
  603. * enabled) or 0 (bias disabled).
  604. *
  605. * Argument domain must be either RTD_DOMAIN (Real Time Domain) or APD_DOMAIN
  606. * (Application Domain).
  607. */
  608. /* Memory Bias config */
  609. struct upwr_mem_bias_cfg_t {
  610. uint32_t en; /* Memory bias enable config */
  611. };
  612. /* bias struct used in power mode config definitions */
  613. typedef struct {
  614. uint32_t en; /* Memory bias enable config */
  615. } UPWR_MEM_BIAS_CFG_T;
  616. /* Split different Bias */
  617. struct upwr_pmc_bias_cfg_t {
  618. UPWR_DOM_BIAS_CFG_T dombias_cfg; /* Domain Bias config */
  619. UPWR_MEM_BIAS_CFG_T membias_cfg; /* Memory Bias config */
  620. };
  621. /*=========================================================================
  622. * Power modes
  623. *=========================================================================
  624. */
  625. /* from msb->lsb: Azure bit, dual boot bit, low power boot bit */
  626. typedef enum {
  627. SOC_BOOT_SINGLE = 0,
  628. SOC_BOOT_LOW_PWR = 1,
  629. SOC_BOOT_DUAL = 2,
  630. SOC_BOOT_AZURE = 4
  631. } SOC_BOOT_TYPE_T;
  632. #ifdef UPWR_COMP_RAM
  633. /* Power modes for RTD domain */
  634. typedef enum {
  635. DPD_RTD_PWR_MODE, /* Real Time Deep Power Down mode */
  636. PD_RTD_PWR_MODE, /* Real Time Power Down mode */
  637. DSL_RTD_PWR_MODE, /* Real Time Domain Deep Sleep Mode */
  638. HLD_RTD_PWR_MODE, /* Real Time Domain Hold Mode */
  639. SLP_RTD_PWR_MODE, /* Sleep Mode */
  640. ADMA_RTD_PWR_MODE,/* Active DMA Mode */
  641. ACT_RTD_PWR_MODE, /* Active Domain Mode */
  642. NUM_RTD_PWR_MODES
  643. } upwr_ps_rtd_pwr_mode_t;
  644. /* Abstract power modes */
  645. typedef enum {
  646. DPD_PWR_MODE,
  647. PD_PWR_MODE,
  648. PACT_PWR_MODE,
  649. DSL_PWR_MODE,
  650. HLD_PWR_MODE,
  651. SLP_PWR_MODE,
  652. ADMA_PWR_MODE,
  653. ACT_PWR_MODE,
  654. NUM_PWR_MODES,
  655. NUM_APD_PWR_MODES = NUM_PWR_MODES,
  656. TRANS_PWR_MODE = NUM_PWR_MODES,
  657. INVALID_PWR_MODE = TRANS_PWR_MODE + 1
  658. } abs_pwr_mode_t;
  659. #else /* UPWR_COMP_RAM */
  660. /* Power modes for RTD domain */
  661. #define DPD_RTD_PWR_MODE (0U) /* Real Time Deep Power Down mode */
  662. #define PD_RTD_PWR_MODE (1U) /* Real Time Power Down mode */
  663. #define DSL_RTD_PWR_MODE (2U) /* Real Time Domain Deep Sleep Mode */
  664. #define HLD_RTD_PWR_MODE (3U) /* Real Time Domain Hold Mode */
  665. #define SLP_RTD_PWR_MODE (4U) /* Sleep Mode */
  666. #define ADMA_RTD_PWR_MODE (5U) /* Active DMA Mode */
  667. #define ACT_RTD_PWR_MODE (6U) /* Active Domain Mode */
  668. #define NUM_RTD_PWR_MODES (7U)
  669. typedef uint32_t upwr_ps_rtd_pwr_mode_t;
  670. /* Abstract power modes */
  671. #define DPD_PWR_MODE (0U)
  672. #define PD_PWR_MODE (1U)
  673. #define PACT_PWR_MODE (2U)
  674. #define DSL_PWR_MODE (3U)
  675. #define HLD_PWR_MODE (4U)
  676. #define SLP_PWR_MODE (5U)
  677. #define ADMA_PWR_MODE (6U)
  678. #define ACT_PWR_MODE (7U)
  679. #define NUM_PWR_MODES (8U)
  680. #define NUM_APD_PWR_MODES NUM_PWR_MODES
  681. #define TRANS_PWR_MODE NUM_PWR_MODES
  682. #define INVALID_PWR_MODE (TRANS_PWR_MODE + 1U)
  683. typedef uint32_t abs_pwr_mode_t;
  684. #endif /* UPWR_COMP_RAM */
  685. typedef struct {
  686. abs_pwr_mode_t mode;
  687. bool ok;
  688. } pch_trans_t;
  689. typedef pch_trans_t rtd_trans_t;
  690. typedef struct {
  691. abs_pwr_mode_t mode;
  692. pch_trans_t core[UPWR_APD_CORES];
  693. } apd_trans_t;
  694. /* Codes for APD pwr mode as programmed in LPMODE reg */
  695. typedef enum {
  696. ACT_APD_LPM,
  697. SLP_APD_LPM = 1,
  698. DSL_APD_LPM = 3,
  699. PACT_APD_LPM = 7,
  700. PD_APD_LPM = 15,
  701. DPD_APD_LPM = 31,
  702. HLD_APD_LPM = 63
  703. } upwr_apd_lpm_t;
  704. /* PowerSys low power config */
  705. struct upwr_powersys_cfg_t {
  706. uint32_t lpm_mode; /* Powersys low power mode */
  707. };
  708. /*=*************************************************************************
  709. * RTD
  710. *=*************************************************************************/
  711. /* Config pmc PADs */
  712. struct upwr_pmc_pad_cfg_t {
  713. uint32_t pad_close; /* PMC PAD close config */
  714. uint32_t pad_reset; /* PMC PAD reset config */
  715. uint32_t pad_tqsleep; /* PMC PAD TQ Sleep config */
  716. };
  717. /* Config regulator (internal and external) */
  718. struct upwr_reg_cfg_t {
  719. uint32_t volt; /* Regulator voltage config */
  720. uint32_t mode; /* Regulator mode config */
  721. };
  722. /* Config pmc monitors */
  723. struct upwr_pmc_mon_cfg_t {
  724. uint32_t mon_hvd_en; /* PMC mon HVD */
  725. uint32_t mon_lvd_en; /* PMC mon LVD */
  726. uint32_t mon_lvdlvl; /* PMC mon LVDLVL */
  727. };
  728. /* Same monitor config for RTD (for compatibility) */
  729. #define upwr_pmc_mon_rtd_cfg_t upwr_pmc_mon_cfg_t
  730. typedef swt_config_t ps_rtd_swt_cfgs_t[NUM_RTD_PWR_MODES];
  731. typedef swt_config_t ps_apd_swt_cfgs_t[NUM_APD_PWR_MODES];
  732. /*=*************************************************************************
  733. * APD
  734. *=*************************************************************************/
  735. /* PowerSys PMIC config */
  736. struct upwr_pmic_cfg_t {
  737. uint32_t volt;
  738. uint32_t mode;
  739. uint32_t mode_msk;
  740. };
  741. typedef uint32_t offs_t;
  742. struct ps_apd_pwr_mode_cfg_t {
  743. #ifdef UPWR_SIMULATOR_ONLY
  744. struct upwr_switch_board_t *swt_board_offs;
  745. struct upwr_mem_switches_t *swt_mem_offs;
  746. #else
  747. offs_t swt_board_offs;
  748. offs_t swt_mem_offs;
  749. #endif
  750. struct upwr_pmic_cfg_t pmic_cfg;
  751. struct upwr_pmc_pad_cfg_t pad_cfg;
  752. struct upwr_pmc_bias_cfg_t bias_cfg;
  753. };
  754. /* Get the pointer to swt config */
  755. static inline struct upwr_switch_board_t*
  756. get_apd_swt_cfg(volatile struct ps_apd_pwr_mode_cfg_t *cfg)
  757. {
  758. char *ptr;
  759. ptr = (char *)cfg;
  760. ptr += (uint64_t)cfg->swt_board_offs;
  761. return (struct upwr_switch_board_t *)ptr;
  762. }
  763. /* Get the pointer to mem config */
  764. static inline struct upwr_mem_switches_t*
  765. get_apd_mem_cfg(volatile struct ps_apd_pwr_mode_cfg_t *cfg)
  766. {
  767. char *ptr;
  768. ptr = (char *)cfg;
  769. ptr += (uint64_t)cfg->swt_mem_offs;
  770. return (struct upwr_mem_switches_t *)ptr;
  771. }
  772. /* Power Mode configuration */
  773. #define ps_rtd_pwr_mode_cfg_t upwr_power_mode_cfg_t
  774. /* these typedefs are just for RISC-V sizeof purpose */
  775. typedef uint32_t swt_board_ptr_t;
  776. typedef uint32_t swt_mem_ptr_t;
  777. struct upwr_power_mode_cfg_t {
  778. #ifdef UPWR_SIMULATOR_ONLY
  779. struct upwr_switch_board_t *swt_board; /* Swt board for mem. */
  780. struct upwr_mem_switches_t *swt_mem; /* Swt to mem. arrays, perif */
  781. #else
  782. #ifdef __LP64__
  783. uint32_t swt_board;
  784. uint32_t swt_mem;
  785. #else
  786. struct upwr_switch_board_t *swt_board; /* Swt board for mem. */
  787. struct upwr_mem_switches_t *swt_mem; /* Swt to mem. arrays, perif */
  788. #endif
  789. #endif
  790. struct upwr_reg_cfg_t in_reg_cfg; /* internal regulator config*/
  791. struct upwr_reg_cfg_t pmic_cfg; /* external regulator - pmic*/
  792. struct upwr_pmc_pad_cfg_t pad_cfg; /* Pad conf for power trans*/
  793. struct upwr_pmc_mon_rtd_cfg_t mon_cfg; /*monitor configuration */
  794. struct upwr_pmc_bias_cfg_t bias_cfg; /* Memory/Domain Bias conf */
  795. struct upwr_powersys_cfg_t pwrsys_lpm_cfg; /* pwrsys low power config*/
  796. };
  797. static inline unsigned int upwr_sizeof_pmode_cfg(uint32_t domain)
  798. {
  799. switch (domain) {
  800. case RTD_DOMAIN:
  801. return sizeof(struct upwr_power_mode_cfg_t) +
  802. (sizeof(struct upwr_switch_board_t)*
  803. UPWR_PMC_SWT_WORDS) +
  804. (sizeof(struct upwr_mem_switches_t)*
  805. UPWR_PMC_MEM_WORDS) -
  806. 2U * (sizeof(void *) - sizeof(swt_board_ptr_t));
  807. /* fall through */
  808. case APD_DOMAIN:
  809. return sizeof(struct ps_apd_pwr_mode_cfg_t) +
  810. (sizeof(struct upwr_switch_board_t)*
  811. UPWR_PMC_SWT_WORDS) +
  812. (sizeof(struct upwr_mem_switches_t)*
  813. UPWR_PMC_MEM_WORDS);
  814. /* fall through */
  815. default:
  816. break;
  817. }
  818. return 0;
  819. }
  820. /*=*************************************************************************
  821. * All configs
  822. *=*************************************************************************/
  823. /* LVD/HVD monitor config for a single domain */
  824. /* Domain + AVD monitor config
  825. * For RTD, mapped in mon_cfg.mon_hvd_en
  826. * For APD, mapped temporarily in pad_cfg.pad_tqsleep
  827. */
  828. typedef union upwr_mon_cfg_union_t {
  829. volatile uint32_t R;
  830. struct {
  831. /* Original config, not change */
  832. volatile uint32_t rsrv_1 : 8;
  833. /* DOM */
  834. volatile uint32_t dom_lvd_irq_ena : 1;
  835. volatile uint32_t dom_lvd_rst_ena : 1;
  836. volatile uint32_t dom_hvd_irq_ena : 1;
  837. volatile uint32_t dom_hvd_rst_ena : 1;
  838. volatile uint32_t dom_lvd_lvl : 4;
  839. volatile uint32_t dom_lvd_ena : 1;
  840. volatile uint32_t dom_hvd_ena : 1;
  841. /* AVD */
  842. volatile uint32_t avd_lvd_irq_ena : 1;
  843. volatile uint32_t avd_lvd_rst_ena : 1;
  844. volatile uint32_t avd_hvd_irq_ena : 1;
  845. volatile uint32_t avd_hvd_rst_ena : 1;
  846. volatile uint32_t avd_lvd_lvl : 4;
  847. volatile uint32_t avd_lvd_ena : 1;
  848. volatile uint32_t avd_hvd_ena : 1;
  849. } B;
  850. } upwr_mon_cfg_t;
  851. /* Get the monitor config word from RAM (domaind and AVD) */
  852. static inline uint32_t get_mon_cfg(uint8_t dom, void *mode_cfg)
  853. {
  854. if (dom == RTD_DOMAIN) {
  855. return ((struct ps_rtd_pwr_mode_cfg_t *)mode_cfg)->mon_cfg.mon_hvd_en;
  856. } else {
  857. return ((struct ps_apd_pwr_mode_cfg_t *)mode_cfg)->pad_cfg.pad_tqsleep;
  858. }
  859. }
  860. /* Set the monitor config word in RAM (domaind and AVD) */
  861. static inline void set_mon_cfg(uint8_t dom, void *mode_cfg,
  862. upwr_mon_cfg_t mon_cfg)
  863. {
  864. uint32_t *cfg;
  865. if (dom == RTD_DOMAIN) {
  866. cfg = (uint32_t *)&((struct ps_rtd_pwr_mode_cfg_t *)mode_cfg)->mon_cfg.mon_hvd_en;
  867. } else {
  868. cfg = (uint32_t *)&((struct ps_apd_pwr_mode_cfg_t *)mode_cfg)->pad_cfg.pad_tqsleep;
  869. }
  870. *cfg = mon_cfg.R;
  871. }
  872. #define PMIC_REG_VALID_TAG 0xAAU
  873. /**
  874. * limit the max pmic register->value count to 8
  875. * each data cost 4 Bytes, totally 32 Bytes
  876. */
  877. #define MAX_PMIC_REG_COUNT 0x8U
  878. /**
  879. * the configuration structure for PMIC register setting
  880. *
  881. * @ tag: The TAG number to judge if the data is valid or not, valid tag is PMIC_REG_VALID_TAG
  882. * @ power_mode : corresponding to each domain's power mode
  883. * RTD refer to upwr_ps_rtd_pwr_mode_t
  884. * APD refer to abs_pwr_mode_t
  885. * @ i2c_addr : i2c address
  886. * @ i2c_data : i2c data value
  887. */
  888. struct ps_pmic_reg_data_cfg_t {
  889. uint32_t tag : 8;
  890. uint32_t power_mode : 8;
  891. uint32_t i2c_addr : 8;
  892. uint32_t i2c_data : 8;
  893. };
  894. /* Uniformize access to PMIC cfg for RTD and APD */
  895. typedef union {
  896. struct upwr_reg_cfg_t RTD;
  897. struct upwr_pmic_cfg_t APD;
  898. } pmic_cfg_t;
  899. /* Access to PMIC mode mask and AVD mode */
  900. typedef union {
  901. uint32_t R;
  902. struct {
  903. uint8_t mode; /* Domain PMIC mode */
  904. uint8_t msk; /* Domain PMIC mode mask */
  905. uint8_t avd_mode; /* AVD PMIC mode */
  906. uint8_t avd_msk; /* AVD PMIC mode mask */
  907. } B;
  908. } pmic_mode_cfg_t;
  909. /* Access RTD, APD and AVD modes and masks */
  910. static inline pmic_mode_cfg_t *get_pmic_mode_cfg(uint8_t dom, pmic_cfg_t *cfg)
  911. {
  912. uint32_t *mode_cfg;
  913. if (dom == RTD_DOMAIN) {
  914. mode_cfg = &cfg->RTD.mode;
  915. } else {
  916. mode_cfg = &cfg->APD.mode;
  917. }
  918. return (pmic_mode_cfg_t *)mode_cfg;
  919. }
  920. static inline uint8_t get_pmic_mode(uint8_t dom, pmic_cfg_t *cfg)
  921. {
  922. return get_pmic_mode_cfg(dom, cfg)->B.mode;
  923. }
  924. static inline void set_pmic_mode(uint8_t dom, pmic_cfg_t *cfg, uint8_t mode)
  925. {
  926. get_pmic_mode_cfg(dom, cfg)->B.mode = mode;
  927. }
  928. static inline uint32_t get_pmic_mode_msk(uint8_t dom, pmic_cfg_t *cfg)
  929. {
  930. pmic_mode_cfg_t *mode_cfg;
  931. if (dom == RTD_DOMAIN) {
  932. mode_cfg = (pmic_mode_cfg_t *)&cfg->RTD.mode;
  933. return mode_cfg->B.msk;
  934. } else {
  935. return cfg->APD.mode_msk;
  936. }
  937. }
  938. /* Getters and setters for AVD mode and mask */
  939. static inline uint8_t get_avd_pmic_mode(uint8_t dom, pmic_cfg_t *cfg)
  940. {
  941. return get_pmic_mode_cfg(dom, cfg)->B.avd_mode;
  942. }
  943. static inline void set_avd_pmic_mode(uint8_t dom, pmic_cfg_t *cfg, uint8_t mode)
  944. {
  945. get_pmic_mode_cfg(dom, cfg)->B.avd_mode = mode;
  946. }
  947. static inline uint8_t get_avd_pmic_mode_msk(uint8_t dom, pmic_cfg_t *cfg)
  948. {
  949. return get_pmic_mode_cfg(dom, cfg)->B.avd_msk;
  950. }
  951. static inline void set_avd_pmic_mode_msk(uint8_t dom,
  952. pmic_cfg_t *cfg,
  953. uint8_t msk)
  954. {
  955. get_pmic_mode_cfg(dom, cfg)->B.avd_msk = msk;
  956. }
  957. struct ps_delay_cfg_t {
  958. uint32_t tag : 8U;
  959. uint32_t rsv : 8U;
  960. uint32_t exitdelay : 16U; // exit delay in us
  961. };
  962. #define PS_DELAY_TAG 0xA5U
  963. /* max exit delay = 0xffff = 65535 us = 65.5 ms (it is enough...) */
  964. /* with 8 bits, 256 -> not enough */
  965. typedef struct ps_delay_cfg_t ps_rtd_delay_cfgs_t[NUM_RTD_PWR_MODES];
  966. typedef struct ps_delay_cfg_t ps_apd_delay_cfgs_t[NUM_APD_PWR_MODES];
  967. typedef struct ps_rtd_pwr_mode_cfg_t ps_rtd_pwr_mode_cfgs_t[NUM_RTD_PWR_MODES];
  968. typedef struct ps_apd_pwr_mode_cfg_t ps_apd_pwr_mode_cfgs_t[NUM_APD_PWR_MODES];
  969. typedef struct ps_pmic_reg_data_cfg_t ps_rtd_pmic_reg_data_cfgs_t[MAX_PMIC_REG_COUNT];
  970. typedef struct ps_pmic_reg_data_cfg_t ps_apd_pmic_reg_data_cfgs_t[MAX_PMIC_REG_COUNT];
  971. struct ps_pwr_mode_cfg_t {
  972. ps_rtd_pwr_mode_cfgs_t ps_rtd_pwr_mode_cfg;
  973. ps_rtd_swt_cfgs_t ps_rtd_swt_cfg;
  974. ps_apd_pwr_mode_cfgs_t ps_apd_pwr_mode_cfg;
  975. ps_apd_swt_cfgs_t ps_apd_swt_cfg;
  976. ps_rtd_pmic_reg_data_cfgs_t ps_rtd_pmic_reg_data_cfg;
  977. ps_apd_pmic_reg_data_cfgs_t ps_apd_pmic_reg_data_cfg;
  978. ps_rtd_delay_cfgs_t ps_rtd_delay_cfg;
  979. ps_apd_delay_cfgs_t ps_apd_delay_cfg;
  980. };
  981. #define UPWR_XCP_MIN_ADDR (0x28350000U)
  982. #define UPWR_XCP_MAX_ADDR (0x2836FFFCU)
  983. struct upwr_reg_access_t {
  984. uint32_t addr;
  985. uint32_t data;
  986. uint32_t mask; /* mask=0 commands read */
  987. };
  988. typedef upwr_pointer_msg upwr_xcp_access_msg;
  989. /* unions for the shared memory buffer */
  990. typedef union {
  991. struct upwr_reg_access_t reg_access;
  992. } upwr_xcp_union_t;
  993. typedef union {
  994. struct {
  995. struct ps_rtd_pwr_mode_cfg_t rtd_struct;
  996. struct upwr_switch_board_t rtd_switch;
  997. struct upwr_mem_switches_t rtd_memory;
  998. } rtd_pwr_mode;
  999. struct {
  1000. struct ps_apd_pwr_mode_cfg_t apd_struct;
  1001. struct upwr_switch_board_t apd_switch;
  1002. struct upwr_mem_switches_t apd_memory;
  1003. } apd_pwr_mode;
  1004. } upwr_pwm_union_t;
  1005. #define MAX_SG_EXCEPT_MEM_SIZE sizeof(upwr_xcp_union_t)
  1006. #define MAX_SG_PWRMGMT_MEM_SIZE sizeof(upwr_pwm_union_t)
  1007. /**
  1008. * VOLTM group need shared memory for PMIC IC configuration
  1009. * 256 Bytes is enough for PMIC register array
  1010. */
  1011. #define MAX_SG_VOLTM_MEM_SIZE 256U
  1012. #endif /* UPWR_SOC_DEFS_H */