hal_chip.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _HAL_CHIP_H_
  13. #define _HAL_CHIP_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "hal_config.h"
  18. #include "osi_compiler.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. #define HAL_CHIP_ID_UNKNOWN (0xffff0000)
  23. #define HAL_CHIP_ID_8955 (0x89550000)
  24. #define HAL_CHIP_ID_8909 (0x89090000)
  25. #define HAL_CHIP_ID_8910 (0x89100000)
  26. #define HAL_CHIP_ID_8811 (0x88110000)
  27. #define HAL_FREQ_16K (16384)
  28. #define HAL_FREQ_32K (32768)
  29. #define HAL_FREQ_1M (1000000)
  30. #define HAL_FREQ_2M (2000000)
  31. #define HAL_FREQ_6P5M (6500000)
  32. #define HAL_FREQ_13M (13 * 1000000)
  33. #define HAL_FREQ_20M (20 * 1000000)
  34. #define HAL_FREQ_26M (26 * 1000000)
  35. #define HAL_FREQ_39M (39 * 1000000)
  36. #define HAL_FREQ_45M (45 * 1000000)
  37. #define HAL_FREQ_52M (52 * 1000000)
  38. #define HAL_FREQ_57M (57 * 1000000)
  39. #define HAL_FREQ_62M (62 * 1000000)
  40. #define HAL_FREQ_69M (69 * 1000000)
  41. #define HAL_FREQ_78M (78 * 1000000)
  42. #define HAL_FREQ_89M (89 * 1000000)
  43. #define HAL_FREQ_104M (104 * 1000000)
  44. #define HAL_FREQ_113M (113 * 1000000)
  45. #define HAL_FREQ_125M (125 * 1000000)
  46. #define HAL_FREQ_139M (139 * 1000000)
  47. #define HAL_FREQ_156M (156 * 1000000)
  48. #define HAL_FREQ_178M (178 * 1000000)
  49. #define HAL_FREQ_208M (208 * 1000000)
  50. #define HAL_FREQ_250M (250 * 1000000)
  51. #define HAL_FREQ_312M (312 * 1000000)
  52. #define HAL_NAME_DMA OSI_MAKE_TAG('D', 'M', 'A', ' ')
  53. #define HAL_NAME_SIM OSI_MAKE_TAG('S', 'I', 'M', ' ')
  54. #define HAL_NAME_XCV OSI_MAKE_TAG('X', 'C', 'V', ' ')
  55. #define HAL_NAME_CALIB OSI_MAKE_TAG('C', 'A', 'L', 'I')
  56. #define HAL_NAME_PAL OSI_MAKE_TAG('P', 'A', 'L', ' ')
  57. #define HAL_NAME_USB OSI_MAKE_TAG('U', 'S', 'B', ' ')
  58. #define HAL_NAME_NETCARD OSI_MAKE_TAG('N', 'E', 'T', 'C')
  59. #define HAL_NAME_CAM OSI_MAKE_TAG('C', 'A', 'M', ' ')
  60. #define HAL_NAME_PWM OSI_MAKE_TAG('P', 'W', 'M', ' ')
  61. #define REG_APPLY_TYPE_END 0
  62. #define REG_APPLY_TYPE_UDELAY 1
  63. #define REG_APPLY_WRITE(address, value) (uint32_t)(address), (uint32_t)(value)
  64. #define REG_APPLY_UDELAY(us) (uint32_t)(REG_APPLY_TYPE_UDELAY), (uint32_t)(us)
  65. #define REG_APPLY_END REG_APPLY_TYPE_END
  66. #define HAL_FLASH_OFFSET(address) ((unsigned)(address)&0xffffff)
  67. #define HAL_FLASH_DEVICE_NAME(address) HAL_CHIP_FLASH_DEVICE_NAME((uintptr_t)(address))
  68. #define HAL_ADDR_IS_ADI(address) HAL_CHIP_ADDR_IS_ADI((uintptr_t)(address))
  69. #define HAL_ADDR_IS_SRAM(address) HAL_CHIP_ADDR_IS_SRAM((uintptr_t)(address))
  70. #define HAL_ADDR_IS_RAM(address) HAL_CHIP_ADDR_IS_RAM((uintptr_t)(address))
  71. #define HAL_ADDR_IS_SRAM_RAM(address) HAL_CHIP_ADDR_IS_SRAM_RAM((uintptr_t)(address))
  72. enum
  73. {
  74. HAL_CLK_DIV1P0 = 2,
  75. HAL_CLK_DIV1P5 = 3,
  76. HAL_CLK_DIV2P0 = 4,
  77. HAL_CLK_DIV2P5 = 5,
  78. HAL_CLK_DIV3P0 = 6,
  79. HAL_CLK_DIV3P5 = 7,
  80. HAL_CLK_DIV4P0 = 8,
  81. HAL_CLK_DIV4P5 = 9,
  82. HAL_CLK_DIV5P0 = 10,
  83. HAL_CLK_DIV5P5 = 11,
  84. HAL_CLK_DIV6P0 = 12,
  85. HAL_CLK_DIV7P0 = 14,
  86. HAL_CLK_DIV8P0 = 16,
  87. HAL_CLK_DIV12P0 = 24,
  88. HAL_CLK_DIV16P0 = 32,
  89. HAL_CLK_DIV24P0 = 48,
  90. };
  91. enum
  92. {
  93. HAL_METAL_ID_U01 = 1,
  94. HAL_METAL_ID_U02,
  95. HAL_METAL_ID_U03,
  96. HAL_METAL_ID_U04,
  97. };
  98. enum
  99. {
  100. HAL_METAL_ID_AA = 1,
  101. HAL_METAL_ID_AB,
  102. HAL_METAL_ID_AC,
  103. HAL_METAL_ID_AD,
  104. };
  105. #define HAL_METAL_BEFORE(metal, n) ((metal) < (n))
  106. #define HAL_METAL_FROM(metal, n) ((metal) >= (n))
  107. enum
  108. {
  109. HAL_VCORE_USER_SYS,
  110. HAL_VCORE_USER_VOC,
  111. HAL_VCORE_USER_COUNT,
  112. };
  113. enum
  114. {
  115. HAL_VCORE_LEVEL_LOW,
  116. HAL_VCORE_LEVEL_MEDIUM,
  117. HAL_VCORE_LEVEL_HIGH,
  118. HAL_VCORE_LEVEL_COUNT,
  119. };
  120. enum
  121. {
  122. HAL_VCORE_MODE_LDO,
  123. HAL_VCORE_MODE_DCDC
  124. };
  125. typedef enum
  126. {
  127. PM0_POWER_MODE_POWERDOWN,
  128. PM0_POWER_MODE_POWERUP,
  129. PM0_POWER_MODE_LOWPOWER
  130. } pm0PowerMode_t;
  131. enum
  132. {
  133. HAL_POWER_DCDC_GEN = OSI_MAKE_TAG('D', 'C', 'D', 'C'),
  134. HAL_POWER_CORE = OSI_MAKE_TAG('C', 'O', 'R', 'E'),
  135. HAL_POWER_BUCK_PA = OSI_MAKE_TAG('D', 'C', 'P', 'A'),
  136. HAL_POWER_SPIMEM = OSI_MAKE_TAG('S', 'P', 'I', 'M'),
  137. HAL_POWER_MEM = OSI_MAKE_TAG('M', 'E', 'M', ' '),
  138. HAL_POWER_AVDD18 = OSI_MAKE_TAG('A', 'V', '1', '8'),
  139. HAL_POWER_RF15 = OSI_MAKE_TAG('R', 'F', '1', '5'),
  140. HAL_POWER_WCN = OSI_MAKE_TAG('W', 'C', 'N', ' '),
  141. HAL_POWER_DDR12 = OSI_MAKE_TAG('D', 'D', 'R', '1'),
  142. HAL_POWER_CAMD = OSI_MAKE_TAG('C', 'A', 'M', 'D'),
  143. HAL_POWER_CAMA = OSI_MAKE_TAG('C', 'A', 'M', 'A'),
  144. HAL_POWER_USB = OSI_MAKE_TAG('U', 'S', 'B', ' '),
  145. HAL_POWER_LCD = OSI_MAKE_TAG('L', 'C', 'D', ' '),
  146. HAL_POWER_SD = OSI_MAKE_TAG('S', 'D', ' ', ' '),
  147. HAL_POWER_SIM0 = OSI_MAKE_TAG('S', 'I', 'M', '0'),
  148. HAL_POWER_SIM1 = OSI_MAKE_TAG('S', 'I', 'M', '1'),
  149. HAL_POWER_VIBR = OSI_MAKE_TAG('V', 'I', 'B', 'R'),
  150. HAL_POWER_DCXO = OSI_MAKE_TAG('D', 'C', 'X', 'O'),
  151. HAL_POWER_VDD28 = OSI_MAKE_TAG('V', 'D', 'D', '2'),
  152. HAL_POWER_VIO18 = OSI_MAKE_TAG('V', 'I', 'O', '1'),
  153. HAL_POWER_VIO33 = OSI_MAKE_TAG('V', 'I', 'O', '3'),
  154. HAL_POWER_KEYLED = OSI_MAKE_TAG('K', 'E', 'Y', 'L'),
  155. HAL_POWER_BACK_LIGHT = OSI_MAKE_TAG('B', 'A', 'C', 'K'),
  156. HAL_POWER_ANALOG = OSI_MAKE_TAG('A', 'N', 'A', 'L'),
  157. HAL_POWER_CAMFLASH = OSI_MAKE_TAG('C', 'A', 'M', 'F'),
  158. HAL_POWER_VBAT_RF = OSI_MAKE_TAG('V', 'B', 'R', 'F'),
  159. HAL_POWER_DCDC_VRF = OSI_MAKE_TAG('D', 'C', 'R', 'F'),
  160. HAL_POWER_RF12 = OSI_MAKE_TAG('R', 'F', '1', '2'),
  161. HAL_POWER_LP18 = OSI_MAKE_TAG('L', 'P', '1', '8'),
  162. HAL_POWER_EMM = OSI_MAKE_TAG('E', 'M', 'M', ' '),
  163. HAL_POWER_CP = OSI_MAKE_TAG('C', 'P', ' ', ' '),
  164. HAL_POWER_VPA = OSI_MAKE_TAG('V', 'P', 'A', ' '),
  165. #ifdef CONFIG_QUEC_PROJECT_FEATURE_GPIO
  166. HAL_POWER_NONE = OSI_MAKE_TAG('N', 'O', 'N', 'E'),
  167. #endif
  168. };
  169. typedef enum
  170. {
  171. HAL_SIM_VOLT_CLASS_A = 0, // 5v
  172. HAL_SIM_VOLT_CLASS_B = 1, // 3.3v
  173. HAL_SIM_VOLT_CLASS_C = 2, // 1.8v
  174. HAL_SIM_VOLT_OFF = 3,
  175. } halSimVoltClass_t;
  176. typedef enum
  177. {
  178. SENSOR_VDD_3300MV = 3300,
  179. SENSOR_VDD_3000MV = 3000,
  180. SENSOR_VDD_2800MV = 2800,
  181. SENSOR_VDD_2500MV = 2500,
  182. SENSOR_VDD_1800MV = 1800,
  183. SENSOR_VDD_1500MV = 1500,
  184. SENSOR_VDD_1300MV = 1300,
  185. SENSOR_VDD_1200MV = 1200,
  186. SENSOR_VDD_CLOSED,
  187. SENSOR_VDD_UNUSED
  188. } cameraVDD_t;
  189. typedef enum
  190. {
  191. WCN_VDD_1800MV = 1800,
  192. WCN_VDD_1700MV = 1700,
  193. WCN_VDD_1600MV = 1600,
  194. WCN_VDD_1500MV = 1500, //default
  195. WCN_VDD_1400MV = 1400,
  196. WCN_VDD_1300MV = 1300,
  197. WCN_VDD_1200MV = 1200,
  198. WCN_VDD_1100MV = 1100,
  199. WCN_VDD_UNUSED
  200. } wcnVDD_t;
  201. typedef enum
  202. {
  203. POWER_LEVEL_3200MV = 3200,
  204. POWER_LEVEL_3100MV = 3100,
  205. POWER_LEVEL_3000MV = 3000,
  206. POWER_LEVEL_2900MV = 2900,
  207. POWER_LEVEL_2800MV = 2800,
  208. POWER_LEVEL_2700MV = 2700,
  209. POWER_LEVEL_2600MV = 2600,
  210. POWER_LEVEL_2500MV = 2500,
  211. POWER_LEVEL_2400MV = 2400,
  212. POWER_LEVEL_2300MV = 2300,
  213. POWER_LEVEL_2200MV = 2200,
  214. POWER_LEVEL_2100MV = 2100,
  215. POWER_LEVEL_2000MV = 2000,
  216. POWER_LEVEL_1900MV = 1900,
  217. POWER_LEVEL_1800MV = 1800,
  218. POWER_LEVEL_1700MV = 1700,
  219. POWER_LEVEL_1600MV = 1600,
  220. POWER_LEVEL_1500MV = 1500,
  221. POWER_LEVEL_1400MV = 1400,
  222. POWER_LEVEL_1300MV = 1300,
  223. POWER_LEVEL_1200MV = 1200,
  224. POWER_LEVEL_1100MV = 1100,
  225. POWER_LEVEL_UNUSED
  226. } powerLevel_t;
  227. typedef enum
  228. {
  229. HAL_CLK32K_SRC_RC,
  230. HAL_CLK32K_SRC_XTAL32K,
  231. HAL_CLK32K_SRC_XTAL26M,
  232. } halClk32kSource_t;
  233. typedef enum
  234. {
  235. PM2_POWER_MODE_POWERDOWN,
  236. PM2_POWER_MODE_LOWPOWER
  237. } pm2PowerMode_t;
  238. typedef enum
  239. {
  240. PM3_POWER_MODE_POWERDOWN,
  241. PM3_POWER_MODE_LOWPOWER
  242. } pm3PowerMode_t;
  243. typedef enum
  244. {
  245. HAL_CLOCK_INIT_BOOTLOADER,
  246. HAL_CLOCK_INIT_FDL,
  247. HAL_CLOCK_INIT_APP,
  248. HAL_CLOCK_INIT_OPENCPU,
  249. HAL_CLOCK_INIT_PM2BOOT,
  250. } halClockInitCase_t;
  251. typedef struct
  252. {
  253. uintptr_t reg;
  254. uint32_t value;
  255. } halRegValue_t;
  256. typedef struct
  257. {
  258. uintptr_t reg;
  259. uint32_t mask;
  260. uint32_t value;
  261. } halRegMaskValue_t;
  262. typedef struct
  263. {
  264. unsigned num;
  265. unsigned denom;
  266. } halFracDividerValue_t;
  267. /**
  268. * \brief global variable for build revision
  269. *
  270. * Though it is constant, it is by design to put it in data section. It will
  271. * appear in blue screen dump when it is in data section.
  272. */
  273. extern char gBuildRevision[];
  274. /**
  275. * \brief read chip id
  276. *
  277. * The returned chip id is not the raw data of hardware registers, it is the
  278. * *logical* chip id.
  279. *
  280. * Due to the method to detect chip id is different among various chips, the
  281. * implementation depends on chip. When the hardware register is unexpected,
  282. * it returns \p HAL_CHIP_ID_UNKNOWN.
  283. *
  284. * \return *logical* chip id
  285. */
  286. uint32_t halGetChipId(void);
  287. /**
  288. * \brief read chip metal id
  289. *
  290. * When the hardware register is unexpected, the returned value is the value
  291. * the latest metal id. For example, when current revision is \p U02, all
  292. * unexpected values will be regarded as \p U02.
  293. *
  294. * When it is needed to distinguish metal id, **never** use the raw hardware
  295. * register, and always use macros for metal id check. Examples:
  296. *
  297. * - HAL_METAL_BEFORE(metal, HAL_METAL_ID_U02): true for metal id *less than*
  298. * U02, and not including U02.
  299. * - HAL_METAL_FROM(metal, HAL_METAL_ID_U02): true for metal id
  300. * *larger or equal than* U02, and including U02.
  301. *
  302. * \return *logical* metal id
  303. */
  304. uint32_t halGetMetalId(void);
  305. /**
  306. * \brief read chip A-DIE metal id
  307. *
  308. * Similar to \p halGetMetalId, just for the metal id of A-DIE.
  309. *
  310. * \return *logical* metal id
  311. */
  312. uint32_t halGetAdieMetalId(void);
  313. /**
  314. * \brief bare metal boot initialization
  315. *
  316. * This will be called before run time initialization. Only the small piece of
  317. * codes are copied from flash into SRAM, namely *.sramboottext* section. All
  318. * *.data* and *.bss* sections are not initialized. Typically, it can access:
  319. *
  320. * - stack
  321. * - flash codes
  322. * - osiDebugEvent, osiDelayUS, halApplyRegisters, halApplyRegisterList
  323. */
  324. void halChipPreBoot(void);
  325. /**
  326. * \brief clock and memory initialization
  327. *
  328. * When this is called, only partial run time is initialized. All sections on
  329. * SRAM can be accessed, and sections on external RAM (PSRAM or DDR) can't be
  330. * accessed.
  331. *
  332. * It may be called in various senario, and it is possible there are
  333. * differences among them.
  334. *
  335. * \param whence caller secario
  336. */
  337. void halClockInit(unsigned whence);
  338. /**
  339. * \brief PSRAM/DDR initialization at cold boot
  340. */
  341. void halRamInit(void);
  342. /**
  343. * \brief PSRAM/DDR initialization at resume
  344. *
  345. * This is called when system is power off, power of PSRAM is kept. Also,
  346. * the content of RAM should be kept.
  347. */
  348. void halRamWakeInit(void);
  349. /**
  350. * \brief PSRAM/DDR suspend
  351. *
  352. * When PSRAM half sleep is supported, it will be processed inside.
  353. */
  354. void halRamSuspend(void);
  355. /**
  356. * \brief PSRAM/DDR suspend abort
  357. */
  358. void halRamSuspendAbort(void);
  359. /**
  360. * \brief batch write write registers, and executed on SRAM
  361. *
  362. * This function should be located in *.sramboottext* section, and the section
  363. * will be loaded to SRAM at the beginning of boot.
  364. *
  365. * The main purpose of this is to write registers which may affect memory
  366. * access. For example, it will make flash unaccessible to write some flash
  367. * controller registers.
  368. *
  369. * It use variadic variables. The variadic variable format is:
  370. *
  371. * - (address, value): write the value to specified register
  372. * - (REG_APPLY_TYPE_UDELAY, value): delay specified microseconds
  373. * - (REG_APPLY_TYPE_END): indicate the end of variadic variables
  374. *
  375. * \param [in] address register address, or REG_APPLY_TYPE_UDELAY,
  376. * REG_APPLY_TYPE_END
  377. */
  378. void halApplyRegisters(uint32_t address, ...);
  379. /**
  380. * \brief batch write write registers, and executed on SRAM
  381. *
  382. * This function should be located in *.sramboottext* section, and the section
  383. * will be loaded to SRAM at the beginning of boot.
  384. *
  385. * It is similar to \p halApplyRegisters, just the parameters are located in
  386. * memory pointed by \p data.
  387. *
  388. * \param [in ] data batch write parameter pointer
  389. */
  390. void halApplyRegisterList(const uint32_t *data);
  391. /**
  392. * \brief calculate 32bits divider
  393. *
  394. * The divider is: output = (input * num) / denom
  395. * - [9:0]: num
  396. * - [29:16]: denom
  397. *
  398. * It is used in UART divider calculation.
  399. *
  400. * \param input input clock frequency
  401. * \param output output clock frequency
  402. * \return
  403. * - caclulated divider
  404. * - 0 on failed
  405. */
  406. unsigned halCalcDivider32(unsigned input, unsigned output);
  407. /**
  408. * \brief calculate 24bits divider
  409. *
  410. * The divider is: output = (input * num) / denom
  411. * - [9:0]: num
  412. * - [23:10]: denom
  413. *
  414. * It is used in UART divider calculation.
  415. *
  416. * \param input input clock frequency
  417. * \param output output clock frequency
  418. * \return
  419. * - caclulated divider
  420. * - 0 on failed
  421. */
  422. unsigned halCalcDivider24(unsigned input, unsigned output);
  423. /**
  424. * \brief calculate fraction divider
  425. *
  426. * The divider is: output = (input * num) / denom
  427. *
  428. * \param input input clock frequency
  429. * \param output output clock frequency, can't be larger than \p input
  430. * \param num_bits bits of num
  431. * \param denom_bits bits of denom
  432. * \return
  433. * - caclulated divider
  434. * - (0, 0) on failed
  435. */
  436. halFracDividerValue_t halCalcFracDivider(unsigned input, unsigned output,
  437. unsigned num_bits,
  438. unsigned denom_bits);
  439. /**
  440. * \brief output frequency of 24bits divider
  441. *
  442. * \param input input clock frequency
  443. * \param divider divider setting
  444. * \result output frequency
  445. */
  446. unsigned halDivider24OutFreq(unsigned input, unsigned divider);
  447. /**
  448. * \brief calculate 20bits divider
  449. *
  450. * The divider is: output = input / (div * set)
  451. * - [15:0]: div - 1, div >= 2
  452. * - [19:16]: set - 1, set >= 6
  453. *
  454. * It is better to choose larger set. And it is used in ARM UART divider
  455. * calculation.
  456. *
  457. * \param input input clock frequency
  458. * \param output output clock frequency
  459. * \return
  460. * - caclulated divider
  461. * - 0 on failed
  462. */
  463. unsigned halCalcDivider20(unsigned input, unsigned output);
  464. /**
  465. * \brief output frequency of 20bits divider
  466. *
  467. * \param input input clock frequency
  468. * \param divider divider setting
  469. * \result output frequency
  470. */
  471. unsigned halDivider20OutFreq(unsigned input, unsigned divider);
  472. /**
  473. * \brief calculate half divider
  474. *
  475. * Half divider is 4 bits, and the real divider is:
  476. * 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5
  477. * 5.0, 5.5, 6.0, 7.0, 8.0, 12.0, 16.0, 24.0
  478. *
  479. * \return half divider setting
  480. */
  481. unsigned halCalHalfDivider(unsigned input, unsigned output);
  482. /**
  483. * \brief output frequency of half divider
  484. *
  485. * \param input input clock frequency
  486. * \param divider divider setting
  487. * \result output frequency
  488. */
  489. unsigned halHalfDividerOutFreq(unsigned input, unsigned divider);
  490. /**
  491. * \brief power on external flash
  492. *
  493. * The implementation may be empty. It should be implemented according to
  494. * board connection and flash type.
  495. *
  496. * When external flash isn't supported, or CONFIG_BOARD_WITH_EXT_FLASH is
  497. * not defined, it should be implemented as empty.
  498. */
  499. void halPmuExtFlashPowerOn(void);
  500. /**
  501. * \brief select clk_32k source
  502. * \param src clk_32k source
  503. * \return
  504. * - true on success
  505. * - false on error, invalid parameter
  506. */
  507. bool halSelectClk32KSource(halClk32kSource_t src);
  508. /**
  509. * \brief get clk_32k source by read register
  510. * \return clk_32k source
  511. */
  512. halClk32kSource_t halGetClk32kSource(void);
  513. /**
  514. * \brief prepare PSM module
  515. *
  516. * This is called before PSM sleep or power down. PSM counter should be
  517. * started here. The PSM counter will be used to measure PSM duration.
  518. */
  519. void halPmuPsmPrepare(void);
  520. /**
  521. * \brief read boot mode magic in pmic
  522. *
  523. * To distinguish various boot mode, magic word will be written in pmic
  524. * register, which will be always power on. This will read it.
  525. *
  526. * Boot mode magic will be cleared in application boot. So, caller should
  527. * make sure it isn't cleared at reading.
  528. *
  529. * \return magic word in always on boot mode register
  530. */
  531. uint32_t halPmuReadBootMode(void);
  532. /**
  533. * \brief write boot mode magic to pmic
  534. *
  535. * \param mode boot mode magic word
  536. */
  537. void halPmuWriteBootMode(uint32_t mode);
  538. /**
  539. * \brief write calibration boot mode magic to pwr
  540. *
  541. * \param calibration mode boot mode magic word
  542. */
  543. void halPmuWriteNbCalibBootMode(uint32_t mode);
  544. /**
  545. * \brief read boot mode magic in pwr
  546. *
  547. * \return calibration boot mode register
  548. */
  549. uint32_t halPmuReadNbCalibBootMode();
  550. /**
  551. * \brief write RTC epoch time in milliseconds
  552. *
  553. * \p ms should be inside bwteen \p CONFIG_KERNEL_MIN_UTC_SECOND and
  554. * \p CONFIG_KERNEL_MAX_UTC_SECOND.
  555. *
  556. * \param ms epoch time in milliseconds
  557. * \return
  558. * - true on success
  559. * - false on fail, invalid parameter
  560. */
  561. bool halPmuWriteRtc(int64_t ms);
  562. /**
  563. * \brief read RTC epoch time in milliseconds
  564. *
  565. * The returned epoch time may be outside of valid range. The calibration
  566. * ratio of clk32k is compensated inside.
  567. *
  568. * \return epoch time in milliseconds
  569. */
  570. int64_t halPmuReadRtc(void);
  571. /**
  572. * \brief read raw RTC epoch time in milliseconds
  573. *
  574. * Comparing \p halPmuReadRtcRaw, the calibration ratio of clk32k isn't
  575. * compensated. Typical usage is for debug only.
  576. *
  577. * \return epoch time in milliseconds
  578. */
  579. int64_t halPmuReadRtcRaw(void);
  580. /**
  581. * \brief unset (disable) RTC alarm
  582. */
  583. void halPmuUnsetAlarm(void);
  584. /**
  585. * \brief set (enable) RTC alarm epoch time in milliseconds
  586. *
  587. * \p ms should be inside valid range.
  588. *
  589. * It doesn't check whether \p ms is in reasonable future of current RTC
  590. * epoch time. Caller should check it.
  591. *
  592. * \param ms alarm epoch time
  593. * \return
  594. * - true on success
  595. * - false on fail, invalid parameter
  596. */
  597. bool halPmuSetAlarm(int64_t ms);
  598. /**
  599. * \brief enter psm sleep (if supported)
  600. *
  601. * On success, this won't return. It will only return on fail. Typical
  602. * reason is there are wake source during entering psm sleep.
  603. *
  604. * \param wake_uptime expected wakeup time, related to uptime.
  605. * \p INT64_MAX for sleep forever.
  606. */
  607. void halPsmSleep(int64_t wake_uptime);
  608. /**
  609. * \brief enter PM2 cold boot sleep (if supported)
  610. *
  611. * \param wake_uptime expected wakeup time, related to uptime.
  612. * \p INT64_MAX for sleep forever.
  613. */
  614. void halPm2BootSleep(int64_t wake_uptime);
  615. /**
  616. * \brief system shutdown into various mode
  617. *
  618. * It will never return. \p wake_uptime will only be used in
  619. * \p OSI_SHUTDOWN_POWER_OFF.
  620. *
  621. * Caller should ensure \p mode is supported. For all unsupported mode,
  622. * it will ba handled as \p OSI_SHUTDOWN_RESET.
  623. *
  624. * \param mode shutdown mode, refer to \p osiShutdownMode_t
  625. * \param wake_uptime expected wakeup time, related to uptime.
  626. * \p INT64_MAX for power off forever.
  627. */
  628. OSI_NO_RETURN void halShutdown(int mode, int64_t wake_uptime);
  629. /**
  630. * \brief enable or disable PMU wake source
  631. *
  632. * Refer to \p HAL_RESUME_SRC_xxx for wake source definition. And this
  633. * only change PMU wake sources.
  634. *
  635. * \param sources one or more wakeup sources
  636. * \param enable true to enable wakeup
  637. */
  638. void halPmuSetWakeupEnable(unsigned sources, bool enable);
  639. /**
  640. * \brief enable or disable device clock
  641. *
  642. * It is only operates the clock gate, not consider the clock tree. On
  643. * different platforms, the valid \p name are different.
  644. *
  645. * Ussually, not all hardware clock gate are exposed to this API.
  646. *
  647. * \param name hardware module name
  648. * \param enable true for enable clock, false for disable clock
  649. */
  650. void halSetDeviceClockEnable(unsigned name, bool enable);
  651. /**
  652. * \brief configure sys_wdt
  653. *
  654. * sys_wdt is used to generate interrupt, and system will come to blue
  655. * screen on this interrupt. It won't reset system, and pmic_wdt will
  656. * reset system.
  657. *
  658. * The main purpose is to monitor system hang, for example, dead loop in
  659. * ISR. And context will be saved in blue screen.
  660. *
  661. * It should be called before \p halSysWdtStart.
  662. *
  663. * In 8910, SYS_IRQ_ID_TIMER_1_OS will be configured as FIQ, and it is
  664. * used for sys_wdt. In 8811, hwp_sysWdt is used.
  665. *
  666. * \param intr_ms timeout to generate sys_wdt interrupt
  667. */
  668. void halSysWdtConfig(unsigned intr_ms);
  669. /**
  670. * \brief enable or disable sys_wdt
  671. *
  672. * In rare cases, it is known that system will be busy for very long time,
  673. * and there are no opportunity to call \p halSysWdtStart in low priority
  674. * thread, this can be called to disable sys_wdt.
  675. *
  676. * Typically, it will be called to disable sys_wdt in unittests.
  677. *
  678. * \param enable true for enable sys_wdt, false for disable
  679. */
  680. void halSysWdtSetEnable(bool enable);
  681. /**
  682. * \brief start or restart sys_wdt
  683. *
  684. * On restart, sys_wdt counting will be cleared.
  685. */
  686. void halSysWdtStart(void);
  687. /**
  688. * \brief stop sys_wdt
  689. */
  690. void halSysWdtStop(void);
  691. /**
  692. * \brief get the supported real frequency by the request frequency
  693. *
  694. * There are reasons that the real frequency will be different from request
  695. * frequency:
  696. * - The request frequency is higher than maximum supported frequency.
  697. * - The divider can't provide exact frequency.
  698. *
  699. * \param freq the request frequency
  700. * \return the real supported frequency
  701. */
  702. uint32_t halSysClkSupportedFreq(uint32_t freq);
  703. /**
  704. * \brief change sys_clk frequency
  705. *
  706. * \param freq the request frequency
  707. */
  708. void halChangeSysClk(uint32_t freq);
  709. /**
  710. * \brief get clk_sys frequency by read registers
  711. *
  712. * \return clk_sys frequency
  713. */
  714. unsigned halGetSysClkFreq(void);
  715. /**
  716. * \brief save blue screen registers
  717. *
  718. * Typically, some of blue screen registers are save in blue screen entry
  719. * assembly. And the remaining will be saved inside.
  720. */
  721. void halSaveBlueScreenReg(void);
  722. /**
  723. * \brief set warm boot entry
  724. * \param entry warm boot entry, NULL for clear
  725. */
  726. void halSetWarmBootEntry(void *entry);
  727. /**
  728. * \brief convert anti-rollback efuse value to integer version
  729. *
  730. * \param verbits efuse anti-rollback value
  731. * \return version in [0, 64]
  732. */
  733. unsigned halFromEfuseAntiRollback64(const uint32_t verbits[2]);
  734. /**
  735. * \brief convert integer version to anti-rollback efuse value
  736. *
  737. * \param ver version number
  738. * \param verbits output efuse anti-rollback value
  739. * \return
  740. * - true on success
  741. * - false on fail, invalie version number
  742. */
  743. bool halToEfuseAntiRollback64(unsigned ver, uint32_t verbits[2]);
  744. uint32_t halFreqToPllDivider(uint32_t freq);
  745. void hal_SysSetBBClock(uint32_t freq);
  746. void hal_SysStartBcpu(void *bcpu_main, void *stack_start_addr);
  747. void halIspiInit(void);
  748. uint16_t halPmuRead(volatile uint32_t *reg);
  749. void halPmuWrite(volatile uint32_t *reg, uint16_t value);
  750. uint16_t halAbbRead(volatile uint32_t *reg);
  751. void halAbbWrite(volatile uint32_t *reg, uint16_t value);
  752. void halPmuInit(unsigned whence);
  753. uint32_t halGetVcoreMode(void);
  754. uint32_t halGetVcoreLevel(void);
  755. uint8_t halRequestVcoreRegs(uint32_t id, uint32_t level, uint16_t *addr, uint16_t *value);
  756. #if defined(CONFIG_SOC_8910) || defined(CONFIG_SOC_8850)
  757. bool halPmuSwitchPower(uint32_t id, bool enabled, bool lp_enabled);
  758. #endif
  759. #if defined(CONFIG_SOC_8850)
  760. bool halPmuSwitchPowerPm2(uint32_t id, bool pm2);
  761. #endif
  762. #ifdef CONFIG_SOC_8811
  763. bool halPmuSwitchPower(uint32_t id, pm0PowerMode_t pm0_mode, pm2PowerMode_t pm2_mode, pm3PowerMode_t pm3_mode);
  764. #endif
  765. bool halPmuSetPowerLevel(uint32_t id, uint32_t mv);
  766. bool halPmuSetCamFlashLevel(uint8_t level);
  767. void halPmuEnterPm1(void);
  768. void halPmuAbortPm1(void);
  769. void halPmuExitPm1(void);
  770. void halPmuEnterPm2(void);
  771. void halPmuAbortPm2(void);
  772. void halPmuExitPm2(void);
  773. bool halPmuSetSimVolt(int idx, halSimVoltClass_t volt);
  774. bool halPmuSelectSim(int idx);
  775. void halPmuSet7sReset(bool enable);
  776. uint32_t GetabnormalCauses(void);
  777. #if defined(CONFIG_SOC_8910)
  778. #include "8910/hal_chip_8910.h"
  779. #elif defined(CONFIG_SOC_8811)
  780. #include "8811/hal_chip_8811.h"
  781. #elif defined(CONFIG_SOC_8850)
  782. #include "8850/hal_chip_8850.h"
  783. #endif
  784. #ifdef __cplusplus
  785. }
  786. #endif
  787. #endif