hal_iomux.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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_IOMUX_H_
  13. #define _HAL_IOMUX_H_
  14. #include "hal_config.h"
  15. #include "osi_compiler.h"
  16. #include "osi_api.h"
  17. #if defined(CONFIG_SOC_8910)
  18. #include "8910/hal_iomux_pin.h"
  19. #elif defined(CONFIG_SOC_8811)
  20. #include "8811/hal_iomux_pin.h"
  21. #elif defined(CONFIG_SOC_8850)
  22. #include "8850/hal_iomux_pin.h"
  23. #endif
  24. OSI_EXTERN_C_BEGIN
  25. /**
  26. * \brief helper for GPIO function
  27. *
  28. * It will be ensured that GPIO function macros are contiguous.
  29. */
  30. #define HAL_IOMUX_FUN_GPIO(n) (HAL_IOMUX_FUN_GPIO_0 + (n))
  31. /**
  32. * \brief helper for GPIO pad
  33. *
  34. * It will be ensured that GPIO pad macros are contiguous. The shift is
  35. * magic, due to pad index is start from bit12.
  36. */
  37. #define HAL_IOMUX_PAD_GPIO(n) (HAL_IOMUX_PAD_GPIO_0 + ((n) << 12))
  38. /**
  39. * \brief helper for PMIC GPIO function
  40. *
  41. * It will be ensured that PMIC GPIO function macros are contiguous.
  42. */
  43. #define HAL_IOMUX_FUN_PMIC_GPIO(n) (HAL_IOMUX_FUN_PMIC_GPIO_0 + (n))
  44. /**
  45. * \brief helper for PMIC GPIO pad
  46. *
  47. * It will be ensured that PMIC GPIO pad macros are contiguous. The
  48. * shift is magic, due to pad index is start from bit12.
  49. */
  50. #define HAL_IOMUX_PAD_PMIC_GPIO(n) (HAL_IOMUX_PAD_PMIC_GPIO_0 + ((n) << 12))
  51. /**
  52. * \brief helper for GPO function
  53. *
  54. * It will be ensured that GPO function macros are contiguous.
  55. */
  56. #define HAL_IOMUX_FUN_GPO(n) (HAL_IOMUX_FUN_GPO_0 + (n))
  57. /**
  58. * \brief force pull up/down options
  59. *
  60. * Each function has default pull up/down property. In most cases, the
  61. * default property should be used. When it is really needed to override
  62. * the default property, *force* property can be set.
  63. *
  64. * For 8910, all pads can support pull up strength 1 and 2. And only a part
  65. * of pads can support strength 3. The typical resistance is 20k/4.7k/1.8k
  66. * for the three level of pull up strength.
  67. *
  68. * Refer to datasheet about the pull up/down resistance, and supported
  69. * pull up strengthes.
  70. */
  71. typedef enum
  72. {
  73. /** not force pull up/down, use function default */
  74. HAL_IOMUX_PULL_DEFAULT = 0,
  75. /** force pull, with neither pull up nor pull down */
  76. HAL_IOMUX_FORCE_PULL_NONE,
  77. /** force pull down */
  78. HAL_IOMUX_FORCE_PULL_DOWN,
  79. /** force pull up */
  80. HAL_IOMUX_FORCE_PULL_UP,
  81. /** force pull up with weakest strength (largest resistance) */
  82. HAL_IOMUX_FORCE_PULL_UP_1 = HAL_IOMUX_FORCE_PULL_UP,
  83. /** force pull up with smaller resistance */
  84. HAL_IOMUX_FORCE_PULL_UP_2,
  85. /** force pull up with smaller resistance */
  86. HAL_IOMUX_FORCE_PULL_UP_3,
  87. } halIomuxPullType_t;
  88. /**
  89. * \brief force output options
  90. *
  91. * Each function has default direction property. In most cases, the
  92. * default property should be used. When it is really needed to override
  93. * the default property, *force* property can be set.
  94. */
  95. typedef enum
  96. {
  97. /** not force output, use function default */
  98. HAL_IOMUX_INOUT_DEFAULT = 0,
  99. /** force input */
  100. HAL_IOMUX_FORCE_INPUT,
  101. /** force output */
  102. HAL_IOMUX_FORCE_OUTPUT,
  103. /** force output high */
  104. HAL_IOMUX_FORCE_OUTPUT_HI,
  105. /** force output low */
  106. HAL_IOMUX_FORCE_OUTPUT_LO,
  107. } halIomuxInoutType_t;
  108. /**
  109. * \brief pad mode at psm sleep
  110. */
  111. typedef enum
  112. {
  113. /** No special handle at sleep, usually with normal function */
  114. HAL_IOMUX_PAD_PSM_NORMAL,
  115. /** Not used at sleep, input with pull none */
  116. HAL_IOMUX_PAD_PSM_NOT_USE,
  117. /** Output at sleep, keep the level before sleep */
  118. HAL_IOMUX_PAD_PSM_OUT_KEEP,
  119. /** Output high at sleep */
  120. HAL_IOMUX_PAD_PSM_OUT_HI,
  121. /** Output low at sleep */
  122. HAL_IOMUX_PAD_PSM_OUT_LO,
  123. /** Input sleep with pull up, and wakeup at falling edge */
  124. HAL_IOMUX_PAD_PSM_WAKE_FALL_EDGE,
  125. /** Input sleep with pull down, and wakeup at rising edge */
  126. HAL_IOMUX_PAD_PSM_WAKE_RISE_EDGE,
  127. /** Input sleep with pull none, and wakeup at falling or rising edge */
  128. HAL_IOMUX_PAD_PSM_WAKE_ANY_EDGE,
  129. /** Input sleep with pull none, and wakeup at falling edge. */
  130. HAL_IOMUX_PAD_PSM_WAKE_FALL_EDGE_NO_PULLUP,
  131. /** Input sleep with pull none, and wakeup at rising edge */
  132. HAL_IOMUX_PAD_PSM_WAKE_RISE_EDGE_NO_PULLDOWN,
  133. } halIomuxPadPsmMode_t;
  134. /**
  135. * @brief IOMUX module initialization
  136. */
  137. void halIomuxInit(void);
  138. /**
  139. * @brief software should write 0 to release after iomux reinitial
  140. */
  141. void halIomuxG4LatchRelease(void);
  142. /**
  143. * \brief set initial iomux configuration
  144. *
  145. * It will be called in \p halIomuxInit. Usually, it is not needed to be
  146. * called again.
  147. *
  148. * \return
  149. * - true on success
  150. * - false on invalid initial configuration
  151. */
  152. bool halIomuxSetInitConfig(void);
  153. /**
  154. * \brief set pad function
  155. *
  156. * \p fun_pad can be:
  157. * - function: It will set function to default pad, with default function
  158. * properties.
  159. * - (function pad): it will set function to specified pad, with default
  160. * function properties.
  161. *
  162. * When default function properties doesn't match pad properties (for
  163. * example, pad doesn't support the driving strength of the function default
  164. * property), the closest pad property will be applied, and not be regarded
  165. * as error.
  166. *
  167. * \param fun_pad function and pad
  168. * \return
  169. * - true on sucess
  170. * - false on fail, invalid parameter
  171. */
  172. bool halIomuxSetFunction(unsigned fun_pad);
  173. /**
  174. * \brief set function default pad
  175. *
  176. * Typically, function default properties are static configured. And this
  177. * can overwite function default pad.
  178. *
  179. * \param fun function
  180. * \param pad default pad of the function
  181. * \return
  182. * - true on success
  183. * - false on fail, invalid parameters
  184. */
  185. bool halIomuxSetFunDefaultPad(unsigned fun, unsigned pad);
  186. /**
  187. * \brief set function default input/output type
  188. *
  189. * Typically, function default properties are static configured. And this
  190. * can overwite function default input/output type.
  191. *
  192. * \param fun function
  193. * \param inout input/output type
  194. * \return
  195. * - true on success
  196. * - false on fail, invalid parameters
  197. */
  198. bool halIomuxSetFunDefaultInout(unsigned fun, halIomuxInoutType_t inout);
  199. /**
  200. * \brief set function default pull up/down
  201. *
  202. * Typically, function default properties are static configured. And this
  203. * can overwite function default pull up/down.
  204. *
  205. * \param fun function
  206. * \param pull pull up/down type
  207. * \return
  208. * - true on success
  209. * - false on fail, invalid parameters
  210. */
  211. bool halIomuxSetFunDefaultPull(unsigned fun, halIomuxPullType_t pull);
  212. /**
  213. * \brief set function default driving strength
  214. *
  215. * Typically, function default properties are static configured. And this
  216. * can overwite function default driving strength.
  217. *
  218. * \param fun function
  219. * \param driving driving strength
  220. * \return
  221. * - true on success
  222. * - false on fail, invalid parameters
  223. */
  224. bool halIomuxSetFunDefaultDriving(unsigned fun, unsigned driving);
  225. /**
  226. * \brief set pad driving strength
  227. *
  228. * \p fun_pad can be:
  229. * - function: It will change function default pad properties
  230. * - pad: Just use the pad
  231. * - function and pad: Just use the pad, and ignore function
  232. *
  233. * When the driving strength doesn't match pad properties, it will be
  234. * regarded as an error, and return false.
  235. *
  236. * \param fun_pad function and pad
  237. * \param driving driving strength
  238. * \return
  239. * - true on sucess
  240. * - false on fail, invalid parameter
  241. */
  242. bool halIomuxSetPadDriving(unsigned fun_pad, unsigned driving);
  243. /**
  244. * \brief set pad pull up/down
  245. *
  246. * Refer to \p halIomuxSetPadDriving for parameter \p fun_pad.
  247. *
  248. * When the pull up/down doesn't match pad properties, it will be
  249. * regarded as an error, and return false.
  250. *
  251. * \param fun_pad function and pad
  252. * \param pull pull up/down type
  253. * \return
  254. * - true on sucess
  255. * - false on fail, invalid parameter
  256. */
  257. bool halIomuxSetPadPull(unsigned fun_pad, halIomuxPullType_t pull);
  258. #ifdef CONFIG_SOC_8850
  259. typedef enum
  260. {
  261. HAL_IOMUX_SLEEP_NONE = 0,
  262. HAL_IOMUX_SLEEP_INPUT,
  263. HAL_IOMUX_SLEEP_OUTPUT,
  264. } halIomuxSleepDirectionType_t;
  265. typedef enum
  266. {
  267. HAL_IOMUX_SLEEP_PULL_NONE = 0,
  268. HAL_IOMUX_SLEEP_PULL_DOWN,
  269. HAL_IOMUX_SLEEP_PULL_UP,
  270. } halIomuxSleepPullType_t;
  271. /**
  272. * \brief set pad sleep input/output ,pull up/down
  273. *
  274. * Refer to \p halIomuxSetPadDriving for parameter \p fun_pad.
  275. *
  276. * When the pull up/down doesn't match pad properties, it will be
  277. * regarded as an error, and return false.
  278. *
  279. * \param fun_pad function and pad
  280. * \param input input/output type
  281. * \return
  282. * - true on sucess
  283. * - false on fail, invalid parameter
  284. */
  285. bool halIomuxSetPadSleepInout(unsigned fun_pad, halIomuxSleepDirectionType_t input);
  286. /**
  287. * \brief set pad sleep input/output ,pull up/down
  288. *
  289. * Refer to \p halIomuxSetPadDriving for parameter \p fun_pad.
  290. *
  291. * When the pull up/down doesn't match pad properties, it will be
  292. * regarded as an error, and return false.
  293. *
  294. * \param fun_pad function and pad
  295. * \param pull pull up/down type
  296. * \return
  297. * - true on sucess
  298. * - false on fail, invalid parameter
  299. */
  300. bool halIomuxSetPadSleepPull(unsigned fun_pad, halIomuxSleepPullType_t pull);
  301. #endif
  302. /**
  303. * \brief set pad input/output type
  304. *
  305. * Refer to \p halIomuxSetPadDriving for parameter \p fun_pad.
  306. *
  307. * \param fun_pad function and pad
  308. * \param inout input/output type
  309. * \return
  310. * - true on sucess
  311. * - false on fail, invalid parameter
  312. */
  313. bool halIomuxSetPadInout(unsigned fun_pad, halIomuxInoutType_t inout);
  314. /**
  315. * \brief set pad psm sleep mode
  316. *
  317. * It is just a configuration, and the configuration will be applied before
  318. * entering psm sleep.
  319. *
  320. * \param fun_pad function and pad, should be PMIC_GPIO for 8811
  321. * \param mode pad mode at psm sleep
  322. * \return
  323. * - true on success
  324. * - false on fail, invalid parameters
  325. */
  326. bool halIomuxSetPadPsmMode(unsigned fun_pad, halIomuxPadPsmMode_t mode);
  327. /**
  328. * \brief set A-Die pad to tri state
  329. * D-Die pad should be separated from A-Die pad, applied at appstart.
  330. */
  331. void halSetPmicPadTriState(void);
  332. /**
  333. * \brief callback before entering psm sleep
  334. */
  335. void halIomuxEnterPsmSleep(void);
  336. /**
  337. * \brief callback when psm sleep failed
  338. */
  339. void halIomuxAbortPsmSleep(void);
  340. /**
  341. * \brief iomux suspend callback
  342. *
  343. * Explicit suspend and resume call will be used, in case the order of iomux
  344. * suspend/resume is sensitive.
  345. *
  346. * \param mode suspend mode
  347. */
  348. void halIomuxSuspend(osiSuspendMode_t mode);
  349. /**
  350. * \brief iomux resume callback
  351. *
  352. * Explicit suspend and resume call will be used, in case the order of iomux
  353. * suspend/resume is sensitive.
  354. *
  355. * \param mode suspend mode
  356. * \param source wakeup source
  357. */
  358. void halIomuxResume(osiSuspendMode_t mode, uint32_t source);
  359. /**
  360. * \brief get fun_pad of specified function
  361. *
  362. * Though it should be avoid to assign function to multiple pads, it is
  363. * possible that a function has already assigned to multiple pads.
  364. *
  365. * When \p pads is NULL, it will only return the count. When \p pads is
  366. * not NULL, it should be large enough to hold all pads. The returned values
  367. * in \p pads is in format of \p fun_pad.
  368. *
  369. * \param fun function
  370. * \param pads fun_pad have selected the specified function
  371. * \return count of pads with specified function
  372. */
  373. unsigned halIomuxGetFunPads(unsigned fun, unsigned *pads);
  374. /**
  375. * \brief get fun_pad of specified pad
  376. *
  377. * The returned value contains both function and pad information, and can
  378. * be used as parameter for \p halIomuxSetFunction and etc. In case to
  379. * change pad function temporally, this can be used to get current
  380. * configuration. For example:
  381. *
  382. * \code{.cpp}
  383. * unsigned fun_pad = halIomuxGetPadFun(pad);
  384. * halIomuxSetFunction(another_fun); // set another function
  385. * // ...
  386. * halIomuxSetFunction(fun_pad); // restore previous configuration
  387. * \endcode
  388. *
  389. * \param pad pad
  390. * \return fun_pad of the specified pad, or 0 on invalid parameter
  391. */
  392. unsigned halIomuxGetPadFun(unsigned pad);
  393. /**
  394. * \brief function name string
  395. *
  396. * Most likely, it will only be used for debug purpose.
  397. *
  398. * \param fun function
  399. * \return
  400. * - function name string
  401. * - empty string ("") for invalid parameter
  402. */
  403. const char *halIomuxFunName(unsigned fun);
  404. /**
  405. * \brief pad name string
  406. *
  407. * Most likely, it will only be used for debug purpose.
  408. *
  409. * \param pad pad
  410. * \return
  411. * - pad name string
  412. * - empty string ("") for invalid parameter
  413. */
  414. const char *halIomuxPadName(unsigned pad);
  415. /**
  416. * \brief show iomux information in log
  417. *
  418. * Most likely, it will only be used for debug purpose.
  419. */
  420. void halIomuxShowInfo(void);
  421. OSI_EXTERN_C_END
  422. #endif