board.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file
  8. * @brief board init functions
  9. */
  10. #include <kernel.h>
  11. #include <init.h>
  12. #include <device.h>
  13. #include <soc.h>
  14. #include "board.h"
  15. #include <drivers/gpio.h>
  16. #include <board_cfg.h>
  17. #define CONFIG_GPIO_HIGHZ (0x1000)
  18. static const struct acts_pin_config board_pin_config[] = {
  19. /*UART0 */
  20. #if IS_ENABLED(CONFIG_UART_0)
  21. /* uart0 tx */
  22. PIN_MFP_SET(GPIO_28, UART0_MFP_CFG),
  23. /* uart0 rx */
  24. PIN_MFP_SET(GPIO_29, UART0_MFP_CFG),
  25. #endif
  26. /*UART1 */
  27. #if IS_ENABLED(CONFIG_UART_1)
  28. /* uart1 tx */
  29. PIN_MFP_SET(GPIO_16, UART1_MFP_CFG),
  30. /* uart1 rx */
  31. PIN_MFP_SET(GPIO_17, UART1_MFP_CFG),
  32. #endif
  33. /*UART2 */
  34. #if IS_ENABLED(CONFIG_UART_2)
  35. /* uart1 tx */
  36. PIN_MFP_SET(GPIO_63, UART2_MFP_SEL),
  37. /* uart1 rx */
  38. PIN_MFP_SET(GPIO_62, UART2_MFP_SEL),
  39. #endif
  40. #if IS_ENABLED(CONFIG_SPI_FLASH_0)
  41. /* SPI0 CS */
  42. PIN_MFP_SET(GPIO_0, SPINOR_MFP_CFG),
  43. /* SPI0 MISO */
  44. PIN_MFP_SET(GPIO_1, SPINOR_MFP_CFG),
  45. /* SPI0 CLK */
  46. PIN_MFP_SET(GPIO_2, SPINOR_MFP_CFG),
  47. /* SPI0 MOSI */
  48. PIN_MFP_SET(GPIO_3, SPINOR_MFP_CFG),
  49. /* SPI0 IO2 */
  50. PIN_MFP_SET(GPIO_6, SPINOR_MFP_PU_CFG),
  51. /* SPI0 IO3 */
  52. PIN_MFP_SET(GPIO_7, SPINOR_MFP_PU_CFG),
  53. #endif
  54. #if IS_ENABLED(CONFIG_I2CMT_0)
  55. /* I2C CLK*/
  56. PIN_MFP_SET(GPIO_18, I2CMT_MFP_CFG(MFP0_I2CMT)),
  57. /* I2C DATA*/
  58. PIN_MFP_SET(GPIO_19, I2CMT_MFP_CFG(MFP0_I2CMT)),
  59. #endif
  60. #if IS_ENABLED(CONFIG_I2CMT_1)
  61. /* I2C CLK*/
  62. PIN_MFP_SET(GPIO_55, I2CMT_MFP_CFG(MFP1_I2CMT)),
  63. /* I2C DATA*/
  64. PIN_MFP_SET(GPIO_56, I2CMT_MFP_CFG(MFP1_I2CMT)),
  65. #endif
  66. #if IS_ENABLED(CONFIG_I2C_0)
  67. /* I2C CLK*/
  68. PIN_MFP_SET(GPIO_57, I2C_MFP_CFG(MFP0_I2C)),
  69. /* I2C DATA*/
  70. PIN_MFP_SET(GPIO_58, I2C_MFP_CFG(MFP0_I2C)),
  71. #endif
  72. #if IS_ENABLED(CONFIG_I2C_1)
  73. /* I2C CLK*/
  74. PIN_MFP_SET(GPIO_51, I2C_MFP_CFG(MFP1_I2C)),
  75. /* I2C DATA*/
  76. PIN_MFP_SET(GPIO_52, I2C_MFP_CFG(MFP1_I2C)),
  77. #endif
  78. #if IS_ENABLED(CONFIG_I2C_2)
  79. /* I2C CLK*/
  80. PIN_MFP_SET(GPIO_5, I2C_MFP_CFG(MFP2_I2C)),
  81. /* I2C DATA*/
  82. PIN_MFP_SET(GPIO_4, I2C_MFP_CFG(MFP2_I2C)),
  83. #endif
  84. #if IS_ENABLED(CONFIG_I2C_3)
  85. /* I2C CLK*/
  86. PIN_MFP_SET(GPIO_60, I2C_MFP_CFG(MFP3_I2C)),
  87. /* I2C DATA*/
  88. PIN_MFP_SET(GPIO_59, I2C_MFP_CFG(MFP3_I2C)),
  89. #endif
  90. #if IS_ENABLED(CONFIG_CEC)
  91. PIN_MFP_SET(GPIO_12, CEC_MFP_CFG),
  92. #endif
  93. #if IS_ENABLED(CONFIG_AUDIO_I2SRX_0)
  94. /*I2SRX0 mclk*/
  95. PIN_MFP_SET(GPIO_53, I2SRX_MFP_CFG),
  96. /*I2SRX0 bclk*/
  97. PIN_MFP_SET(GPIO_54, I2SRX_MFP_CFG),
  98. /*I2SRX0 lrclk*/
  99. PIN_MFP_SET(GPIO_55, I2SRX_MFP_CFG),
  100. /*I2SRX0 d0*/
  101. PIN_MFP_SET(GPIO_56, I2SRX_MFP_CFG),
  102. #endif
  103. #if IS_ENABLED(CONFIG_SPI_1)
  104. /*SPI SS*/
  105. PIN_MFP_SET(GPIO_24, SPI_MFP_CFG(MFP_SPI1)),
  106. /* SPI CLK*/
  107. PIN_MFP_SET(GPIO_25, SPI_MFP_CFG(MFP_SPI1)),
  108. /* SPI MISO*/
  109. PIN_MFP_SET(GPIO_26, SPI_MFP_CFG(MFP_SPI1)),
  110. /* SPI MOSI*/
  111. PIN_MFP_SET(GPIO_27, SPI_MFP_CFG(MFP_SPI1)),
  112. #endif
  113. #if IS_ENABLED(CONFIG_SPI_2)
  114. /*SPI SS*/
  115. PIN_MFP_SET(GPIO_30, SPI_MFP_CFG(MFP_SPI2)),
  116. /* SPI CLK*/
  117. PIN_MFP_SET(GPIO_31, SPI_MFP_CFG(MFP_SPI2)),
  118. /* SPI MISO*/
  119. PIN_MFP_SET(GPIO_32, SPI_MFP_CFG(MFP_SPI2)),
  120. /* SPI MOSI*/
  121. PIN_MFP_SET(GPIO_33, SPI_MFP_CFG(MFP_SPI2)),
  122. #endif
  123. #if IS_ENABLED(CONFIG_SPI_3)
  124. /*SPI SS*/
  125. PIN_MFP_SET(GPIO_20, SPI_MFP_CFG(MFP_SPI3)),
  126. /* SPI CLK*/
  127. PIN_MFP_SET(GPIO_21, SPI_MFP_CFG(MFP_SPI3)),
  128. /* SPI MISO*/
  129. PIN_MFP_SET(GPIO_22, SPI_MFP_CFG(MFP_SPI3)),
  130. /* SPI MOSI*/
  131. PIN_MFP_SET(GPIO_23, SPI_MFP_CFG(MFP_SPI3)),
  132. #endif
  133. #if IS_ENABLED(CONFIG_SPIMT_0)
  134. /* SPI SS*/
  135. PIN_MFP_SET(GPIO_49, SPIMT_MFP_CFG(MFP0_SPIMT)),
  136. /* SPI CLK*/
  137. PIN_MFP_SET(GPIO_50, SPIMT_MFP_CFG(MFP0_SPIMT)),
  138. /* SPI MISO*/
  139. PIN_MFP_SET(GPIO_51, SPIMT_MFP_CFG(MFP0_SPIMT)),
  140. /* SPI MOSI*/
  141. PIN_MFP_SET(GPIO_52, SPIMT_MFP_CFG(MFP0_SPIMT)),
  142. /* SPI SS1*/
  143. PIN_MFP_SET(GPIO_61, SPIMT_MFP_CFG(MFP0_SPIMT)),
  144. #endif
  145. #if IS_ENABLED(CONFIG_SPIMT_1)
  146. /* SPI SS*/
  147. PIN_MFP_SET(GPIO_53, SPIMT_MFP_CFG(MFP1_SPIMT)),
  148. /* SPI CLK*/
  149. PIN_MFP_SET(GPIO_54, SPIMT_MFP_CFG(MFP1_SPIMT)),
  150. /* SPI MISO*/
  151. PIN_MFP_SET(GPIO_55, SPIMT_MFP_CFG(MFP1_SPIMT)),
  152. /* SPI MOSI*/
  153. PIN_MFP_SET(GPIO_56, SPIMT_MFP_CFG(MFP1_SPIMT)),
  154. #endif
  155. };
  156. #if IS_ENABLED(CONFIG_MMC_0)
  157. static const struct acts_pin_config board_mmc0_config[] = {
  158. /* MMC0 CMD*/
  159. PIN_MFP_SET(GPIO_25, SDC0_MFP_CFG_VAL),
  160. /* MMC0 CLK*/
  161. PIN_MFP_SET(GPIO_24, (GPIO_CTL_MFP(SDC0_MFP_SEL)|GPIO_CTL_PADDRV_LEVEL(3))),
  162. /* MMC0 DATA0 */
  163. PIN_MFP_SET(GPIO_18, SDC0_MFP_CFG_VAL),
  164. /* MMC0 DATA1 */
  165. PIN_MFP_SET(GPIO_19, SDC0_MFP_CFG_VAL),
  166. /* MMC0 DATA2 */
  167. PIN_MFP_SET(GPIO_20, SDC0_MFP_CFG_VAL),
  168. /* MMC0 DATA3 */
  169. PIN_MFP_SET(GPIO_21, SDC0_MFP_CFG_VAL),
  170. };
  171. #endif
  172. #if IS_ENABLED(CONFIG_AUDIO_SPDIFTX_0)
  173. static const struct acts_pin_config board_spdiftx0_config[] = {
  174. PIN_MFP_SET(GPIO_9, SPDIFTX_MFP_CFG),
  175. };
  176. #endif
  177. #if IS_ENABLED(CONFIG_AUDIO_SPDIFRX_0)
  178. static const struct acts_pin_config board_spdifrx0_config[] = {
  179. PIN_MFP_SET(GPIO_13, SPDIFRX_MFP_CFG)
  180. };
  181. #endif
  182. #if IS_ENABLED(CONFIG_AUDIO_I2STX_0)
  183. static const struct acts_pin_config board_i2stx0_config[] = {
  184. /*I2STX0 mclk*/
  185. PIN_MFP_SET(GPIO_49, I2STX_MFP_CFG),
  186. /*I2STX0 bclk*/
  187. PIN_MFP_SET(GPIO_50, I2STX_MFP_CFG),
  188. /*I2STX0 lrclk*/
  189. PIN_MFP_SET(GPIO_51, I2STX_MFP_CFG),
  190. /*I2STX0 d0*/
  191. PIN_MFP_SET(GPIO_52, I2STX_MFP_CFG),
  192. };
  193. #endif
  194. #if IS_ENABLED(CONFIG_SPINAND_3)
  195. static const struct acts_pin_config board_spinand_spi3_config[] = {
  196. /* IOVCC1 poweron */
  197. PIN_MFP_SET(CONFIG_SPINAND_POWER_GPIO, 0x1F),
  198. /*SPI3 IO2*/
  199. PIN_MFP_SET(GPIO_8, SPINAND_MFP_PU_CFG),
  200. /*SPI3 IO3*/
  201. PIN_MFP_SET(GPIO_9, SPINAND_MFP_PU_CFG),
  202. /*SPI3 SS*/
  203. PIN_MFP_SET(GPIO_10, SPINAND_MFP_CFG),
  204. /*SPI3 CLK*/
  205. PIN_MFP_SET(GPIO_11, SPINAND_MFP_CFG),
  206. /*SPI3 IO1*/
  207. PIN_MFP_SET(GPIO_12, SPINAND_MFP_CFG),
  208. /*SPI3 IO0*/
  209. PIN_MFP_SET(GPIO_13, SPINAND_MFP_CFG),
  210. };
  211. static const struct acts_pin_config board_spinand_spi3_gpiohighz_config[] = {
  212. /* IOVCC1 poweroff */
  213. PIN_MFP_SET(CONFIG_SPINAND_POWER_GPIO, CONFIG_GPIO_HIGHZ),
  214. /*SPI3 IO2*/
  215. PIN_MFP_SET(GPIO_8, CONFIG_GPIO_HIGHZ),
  216. /*SPI3 IO3*/
  217. PIN_MFP_SET(GPIO_9, CONFIG_GPIO_HIGHZ),
  218. /*SPI3 SS*/
  219. PIN_MFP_SET(GPIO_10, CONFIG_GPIO_HIGHZ),
  220. /*SPI3 CLK*/
  221. PIN_MFP_SET(GPIO_11, CONFIG_GPIO_HIGHZ),
  222. /*SPI3 IO1*/
  223. PIN_MFP_SET(GPIO_12, CONFIG_GPIO_HIGHZ),
  224. /*SPI3 IO0*/
  225. PIN_MFP_SET(GPIO_13, CONFIG_GPIO_HIGHZ),
  226. };
  227. #endif
  228. #if IS_ENABLED(CONFIG_PWM)
  229. /* Look at CONFIG_PWM_PIN_CHAN_MAP select the available pwm gpio */
  230. static const struct pwm_acts_pin_config board_pwm_config[] = {
  231. /* GPIO57 used as pwm channel 1*/
  232. PWM_PIN_MFP_SET(GPIO_57, 1, PWM_MFP_CFG),
  233. };
  234. #endif
  235. #if IS_ENABLED(CONFIG_ACTS_BATTERY_NTC)
  236. /* GPIO20 and GPIO_23 are used as lradc2, they can't be used at the same time */
  237. static const struct acts_pin_config board_ntc_config[] = {
  238. PIN_MFP_SET(GPIO_20, BATNTC_MFP_CFG),
  239. PIN_MFP_SET(GPIO_23, CONFIG_GPIO_HIGHZ),
  240. };
  241. static const struct acts_pin_config board_ntc_ref_config[] = {
  242. PIN_MFP_SET(GPIO_20, CONFIG_GPIO_HIGHZ),
  243. /* GPIO23 must be a not use GPIO, use as lradc2 to get ntc scale value */
  244. PIN_MFP_SET(GPIO_23, BATNTC_REF_MFP_CFG),
  245. };
  246. static const struct acts_pin_config board_ntc_disable_config[] = {
  247. PIN_MFP_SET(GPIO_20, CONFIG_GPIO_HIGHZ),
  248. PIN_MFP_SET(GPIO_23, CONFIG_GPIO_HIGHZ),
  249. };
  250. #endif
  251. #if IS_ENABLED(CONFIG_PANEL)
  252. static const struct acts_pin_config board_lcd_pin_config[] = {
  253. /* lcd cs */
  254. PIN_MFP_SET(GPIO_30, (GPIO_CTL_MFP(LCD_MFP_SEL)|GPIO_CTL_PULLUP)),
  255. /* lcd scl */
  256. PIN_MFP_SET(GPIO_34, LCD_MFP_CLK_SEL),
  257. /* lcd_d0*/
  258. PIN_MFP_SET(GPIO_14, LCD_MFP_SEL),
  259. /* lcd_d1*/
  260. PIN_MFP_SET(GPIO_15, LCD_MFP_SEL),
  261. /* lcd_d2*/
  262. PIN_MFP_SET(GPIO_16, LCD_MFP_SEL),
  263. /* lcd_d3*/
  264. PIN_MFP_SET(GPIO_17, LCD_MFP_SEL),
  265. /* lcd power: IOVCC2 */
  266. PIN_MFP_SET(GPIO_33, 0x1F),
  267. };
  268. #endif
  269. #if IS_ENABLED(CONFIG_ADCKEY)
  270. #define CONFIG_ADCKEY_GPIO
  271. #ifdef CONFIG_ADCKEY_GPIO
  272. #define CONFIG_ADCKEY_GPIO_NUM (GPIO_21)
  273. #else
  274. #define CONFIG_ADCKEY_WIO_NUM (WIO_0)
  275. #define CONFIG_ADCKEY_WIO_MFP (3)
  276. #endif
  277. static void board_adckey_pinmux_init(void)
  278. {
  279. #ifdef CONFIG_ADCKEY_GPIO
  280. acts_pinmux_set(CONFIG_ADCKEY_GPIO_NUM, ADCKEY_MFP_CFG);
  281. #else
  282. sys_write32(CONFIG_ADCKEY_WIO_MFP, WIO0_CTL + (CONFIG_ADCKEY_WIO_NUM * 4));
  283. #endif
  284. }
  285. #endif
  286. static int board_early_init(const struct device *arg)
  287. {
  288. ARG_UNUSED(arg);
  289. acts_pinmux_setup_pins(board_pin_config, ARRAY_SIZE(board_pin_config));
  290. #if IS_ENABLED(CONFIG_MMC_0)
  291. acts_pinmux_setup_pins(board_mmc0_config, ARRAY_SIZE(board_mmc0_config));
  292. #endif
  293. #if IS_ENABLED(CONFIG_ADCKEY)
  294. board_adckey_pinmux_init();
  295. #endif
  296. #if IS_ENABLED(CONFIG_PANEL)
  297. acts_pinmux_setup_pins(board_lcd_pin_config, ARRAY_SIZE(board_lcd_pin_config));
  298. #endif
  299. #ifdef CONFIG_RTT_CONSOLE
  300. jtag_set();
  301. #endif
  302. #ifdef CONFIG_ACTS_LEOPARD_BATTERY_SUPPLY_EXTERNAL
  303. /*if use external charger, set vd12 and vc18 to dcdc*/
  304. sys_write32(sys_read32(VOUT_CTL0) | (1<<18) | (1<<17), VOUT_CTL0);
  305. /*if use external charger, close internal charger*/
  306. sys_write32(sys_read32(CHG_CTL_SVCC) & ~(1<<10), CHG_CTL_SVCC);
  307. sys_write32(sys_read32(WIO1_CTL) | (1 << 25), WIO1_CTL);
  308. /*set wio1 as a wakeup src, for poweroff unnormal */
  309. sys_write32(sys_read32(WKEN_CTL_SVCC) | (1 << 5), WKEN_CTL_SVCC);
  310. #endif
  311. return 0;
  312. }
  313. static int board_later_init(const struct device *arg)
  314. {
  315. ARG_UNUSED(arg);
  316. printk("%s %d: \n", __func__, __LINE__);
  317. return 0;
  318. }
  319. /* UART registers struct */
  320. struct acts_uart_reg {
  321. volatile uint32_t ctrl;
  322. volatile uint32_t rxdat;
  323. volatile uint32_t txdat;
  324. volatile uint32_t stat;
  325. volatile uint32_t br;
  326. } ;
  327. void uart_poll_out_ch(int c)
  328. {
  329. struct acts_uart_reg *uart = (struct acts_uart_reg*)UART0_REG_BASE;
  330. /* Wait for transmitter to be ready */
  331. while (uart->stat & BIT(6));
  332. /* send a character */
  333. uart->txdat = (uint32_t)c;
  334. }
  335. /*for early printk*/
  336. int arch_printk_char_out(int c)
  337. {
  338. if ('\n' == c)
  339. uart_poll_out_ch('\r');
  340. uart_poll_out_ch(c);
  341. return 0;
  342. }
  343. #if 1 //TODO:
  344. static const audio_input_map_t board_audio_input_map[] = {
  345. {AUDIO_LINE_IN0, ADC_CH_INPUT0P, ADC_CH_DISABLE, ADC_CH_INPUT0N, ADC_CH_DISABLE},
  346. {AUDIO_LINE_IN1, ADC_CH_INPUT0NP_DIFF, ADC_CH_INPUT1NP_DIFF, ADC_CH_DISABLE, ADC_CH_DISABLE},
  347. {AUDIO_LINE_IN2, ADC_CH_DISABLE, ADC_CH_INPUT1P, ADC_CH_DISABLE, ADC_CH_INPUT1N},
  348. {AUDIO_ANALOG_MIC0, ADC_CH_INPUT0NP_DIFF, ADC_CH_DISABLE, ADC_CH_DISABLE, ADC_CH_DISABLE},
  349. {AUDIO_ANALOG_MIC1, ADC_CH_INPUT0NP_DIFF, ADC_CH_DISABLE, ADC_CH_DISABLE, ADC_CH_DISABLE},
  350. {AUDIO_ANALOG_MIC2, ADC_CH_INPUT0NP_DIFF, ADC_CH_INPUT1NP_DIFF, ADC_CH_DISABLE, ADC_CH_DISABLE},
  351. {AUDIO_ANALOG_FM0, ADC_CH_INPUT0P, ADC_CH_DISABLE, ADC_CH_INPUT0N, ADC_CH_DISABLE},
  352. {AUDIO_DIGITAL_MIC0, ADC_CH_DMIC, ADC_CH_DMIC, ADC_CH_DISABLE, ADC_CH_DISABLE},
  353. };
  354. int board_audio_device_mapping(audio_input_map_t *input_map)
  355. {
  356. int i;
  357. if (!input_map)
  358. return -EINVAL;
  359. for (i = 0; i < ARRAY_SIZE(board_audio_input_map); i++) {
  360. if (input_map->audio_dev == board_audio_input_map[i].audio_dev) {
  361. input_map->ch0_input = board_audio_input_map[i].ch0_input;
  362. input_map->ch1_input = board_audio_input_map[i].ch1_input;
  363. input_map->ch2_input = board_audio_input_map[i].ch2_input;
  364. input_map->ch3_input = board_audio_input_map[i].ch3_input;
  365. break;
  366. }
  367. }
  368. if (i == ARRAY_SIZE(board_audio_input_map)) {
  369. printk("can not find out audio dev 0x%x\n", input_map->audio_dev);
  370. return -ENOENT;
  371. }
  372. return 0;
  373. }
  374. #endif
  375. #ifdef CONFIG_BOARD_EXTERNAL_PA_ENABLE
  376. #define EXTERN_PA_CTL1_PIN 53
  377. #define EXTERN_PA_CTL_SLEEP_OFF_TIME_MS 160
  378. #define EXTERN_PA_CTL_SLEEP_ON_TIME_MS 20
  379. //#define EXTERN_PA_EIO_CTRL_PIN (0)
  380. //#define EXTERN_PA_EIO_CTRL_PIN_NAME CONFIG_EXTEND_GPIO_NAME
  381. int board_extern_pa_ctl(u8_t pa_class, bool is_on)
  382. {
  383. #ifdef EXTERN_PA_CTL1_PIN
  384. const struct device *pa_gpio_dev;
  385. pa_gpio_dev = device_get_binding(CONFIG_GPIO_PIN2NAME(EXTERN_PA_CTL1_PIN));
  386. if (!pa_gpio_dev)
  387. return -EINVAL;
  388. #endif
  389. #ifdef EXTERN_PA_EIO_CTRL_PIN
  390. const struct device *egpio_dev;
  391. egpio_dev = device_get_binding(EXTERN_PA_EIO_CTRL_PIN_NAME);
  392. if (!egpio_dev)
  393. return -EINVAL;
  394. #endif
  395. if (!is_on) {
  396. /* external PA power off */
  397. printk("audio external PA power off\n");
  398. #ifdef EXTERN_PA_CTL1_PIN
  399. gpio_pin_configure(pa_gpio_dev, EXTERN_PA_CTL1_PIN % 32, GPIO_OUTPUT);
  400. gpio_pin_set(pa_gpio_dev, EXTERN_PA_CTL1_PIN % 32, 0);
  401. /* XA7191D PA spec depicts that shall disable PA for above 150ms when switch work mode */
  402. k_sleep(K_MSEC(EXTERN_PA_CTL_SLEEP_OFF_TIME_MS));
  403. #endif
  404. #ifdef EXTERN_PA_EIO_CTRL_PIN
  405. gpio_pin_configure(egpio_dev, EXTERN_PA_EIO_CTRL_PIN % 32, GPIO_OUTPUT);
  406. gpio_pin_set(egpio_dev, EXTERN_PA_EIO_CTRL_PIN % 32, 0);
  407. #endif
  408. } else {
  409. /* external PA power off */
  410. printk("audio external PA power on\n");
  411. #ifdef EXTERN_PA_CTL1_PIN
  412. gpio_pin_configure(pa_gpio_dev, EXTERN_PA_CTL1_PIN % 32, GPIO_OUTPUT);
  413. gpio_pin_set(pa_gpio_dev, EXTERN_PA_CTL1_PIN % 32, 1);
  414. k_sleep(K_MSEC(EXTERN_PA_CTL_SLEEP_ON_TIME_MS));
  415. #endif
  416. #ifdef EXTERN_PA_EIO_CTRL_PIN
  417. gpio_pin_configure(egpio_dev, EXTERN_PA_EIO_CTRL_PIN % 32, GPIO_OUTPUT);
  418. gpio_pin_set(egpio_dev, EXTERN_PA_EIO_CTRL_PIN % 32, 1);
  419. #endif
  420. }
  421. return 0;
  422. }
  423. #endif
  424. #if IS_ENABLED(CONFIG_GPS)
  425. #define GPS_POWER095_CTL_PIN 57
  426. #define GPS_POWER_CTL_PIN 58
  427. #define GPS_RESET_CTL_PIN 59
  428. #define GPS_WAKE_UP_CTL_PIN 60
  429. #define GPS_RTC_CTL_PIN 61
  430. #define GPS_POWE_CTL_SLEEP_OFF_TIME_MS 160
  431. #define GPS_POWE_CTL_SLEEP_ON_TIME_MS 20
  432. int gps_power095_pin_ctl( bool is_on)
  433. {
  434. const struct device *gps_gpio_dev;
  435. gps_gpio_dev = device_get_binding(CONFIG_GPIO_PIN2NAME(GPS_POWER095_CTL_PIN));
  436. if (!gps_gpio_dev)
  437. return -EINVAL;
  438. if (!is_on) {
  439. printk("gps power095 off\n");
  440. gpio_pin_configure(gps_gpio_dev, GPS_POWER095_CTL_PIN % 32, GPIO_OUTPUT);
  441. gpio_pin_set(gps_gpio_dev, GPS_POWER095_CTL_PIN % 32, 0);
  442. k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_OFF_TIME_MS));
  443. } else {
  444. printk("gps power095 on\n");
  445. gpio_pin_configure(gps_gpio_dev, GPS_POWER095_CTL_PIN % 32, GPIO_OUTPUT);
  446. gpio_pin_set(gps_gpio_dev, GPS_POWER095_CTL_PIN % 32, 1);
  447. k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_ON_TIME_MS));
  448. }
  449. return 0;
  450. }
  451. int gps_power_pin_ctl( bool is_on)
  452. {
  453. const struct device *gps_gpio_dev;
  454. gps_gpio_dev = device_get_binding(CONFIG_GPIO_PIN2NAME(GPS_POWER_CTL_PIN));
  455. if (!gps_gpio_dev)
  456. return -EINVAL;
  457. if (!is_on) {
  458. printk("gps power off\n");
  459. gpio_pin_configure(gps_gpio_dev, GPS_POWER_CTL_PIN % 32, GPIO_OUTPUT);
  460. gpio_pin_set(gps_gpio_dev, GPS_POWER_CTL_PIN % 32, 0);
  461. k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_OFF_TIME_MS));
  462. } else {
  463. printk("gps power on\n");
  464. gpio_pin_configure(gps_gpio_dev, GPS_POWER_CTL_PIN % 32, GPIO_OUTPUT);
  465. gpio_pin_set(gps_gpio_dev, GPS_POWER_CTL_PIN % 32, 1);
  466. k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_ON_TIME_MS));
  467. }
  468. return 0;
  469. }
  470. // int gps_reset_pin_ctl()
  471. // {
  472. // const struct device *gps_gpio_dev;
  473. // gps_gpio_dev = device_get_binding(CONFIG_GPIO_PIN2NAME(GPS_RESET_CTL_PIN));
  474. // if (!gps_gpio_dev)
  475. // return -EINVAL;
  476. // gpio_pin_configure(gps_gpio_dev, GPS_RESET_CTL_PIN % 32, GPIO_OUTPUT);
  477. // gpio_pin_set(gps_gpio_dev, GPS_RESET_CTL_PIN % 32, 0);
  478. // k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_OFF_TIME_MS));
  479. // gpio_pin_set(gps_gpio_dev, GPS_RESET_CTL_PIN % 32, 1);
  480. // return 0;
  481. // }
  482. int gps_wake_up_pin_ctl( bool is_on)
  483. {
  484. const struct device *gps_gpio_dev;
  485. gps_gpio_dev = device_get_binding(CONFIG_GPIO_PIN2NAME(GPS_WAKE_UP_CTL_PIN));
  486. if (!gps_gpio_dev)
  487. return -EINVAL;
  488. if (!is_on) {
  489. printk("gps suspended\n");
  490. gpio_pin_configure(gps_gpio_dev, GPS_WAKE_UP_CTL_PIN % 32, GPIO_OUTPUT);
  491. gpio_pin_set(gps_gpio_dev, GPS_WAKE_UP_CTL_PIN % 32, 0);
  492. k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_OFF_TIME_MS));
  493. } else {
  494. printk("gps wake up\n");
  495. gpio_pin_configure(gps_gpio_dev, GPS_WAKE_UP_CTL_PIN % 32, GPIO_OUTPUT);
  496. gpio_pin_set(gps_gpio_dev, GPS_WAKE_UP_CTL_PIN % 32, 1);
  497. k_sleep(K_MSEC(GPS_POWE_CTL_SLEEP_ON_TIME_MS));
  498. }
  499. return 0;
  500. }
  501. #endif
  502. void board_get_mmc0_pinmux_info(struct board_pinmux_info *pinmux_info)
  503. {
  504. #if IS_ENABLED(CONFIG_MMC_0)
  505. pinmux_info->pins_config = board_mmc0_config;
  506. pinmux_info->pins_num = ARRAY_SIZE(board_mmc0_config);
  507. #endif
  508. }
  509. void board_get_spdiftx0_pinmux_info(struct board_pinmux_info *pinmux_info)
  510. {
  511. #if IS_ENABLED(CONFIG_AUDIO_SPDIFTX_0)
  512. pinmux_info->pins_config = board_spdiftx0_config;
  513. pinmux_info->pins_num = ARRAY_SIZE(board_spdiftx0_config);
  514. #endif
  515. }
  516. void board_get_spdifrx0_pinmux_info(struct board_pinmux_info *pinmux_info)
  517. {
  518. #if IS_ENABLED(CONFIG_AUDIO_SPDIFRX_0)
  519. pinmux_info->pins_config = board_spdifrx0_config;
  520. pinmux_info->pins_num = ARRAY_SIZE(board_spdifrx0_config);
  521. #endif
  522. }
  523. void board_get_i2stx0_pinmux_info(struct board_pinmux_info *pinmux_info)
  524. {
  525. #if IS_ENABLED(CONFIG_AUDIO_I2STX_0)
  526. pinmux_info->pins_config = board_i2stx0_config;
  527. pinmux_info->pins_num = ARRAY_SIZE(board_i2stx0_config);
  528. #endif
  529. }
  530. void board_get_pwm_pinmux_info(struct board_pwm_pinmux_info *pinmux_info)
  531. {
  532. #if IS_ENABLED(CONFIG_PWM)
  533. pinmux_info->pins_config = board_pwm_config;
  534. pinmux_info->pins_num = ARRAY_SIZE(board_pwm_config);
  535. #endif
  536. }
  537. void board_get_spinand_pinmux_info(struct board_pinmux_info *pinmux_info)
  538. {
  539. #if IS_ENABLED(CONFIG_SPINAND_3)
  540. pinmux_info->pins_config = board_spinand_spi3_config;
  541. pinmux_info->pins_num = ARRAY_SIZE(board_spinand_spi3_config);
  542. #endif
  543. }
  544. void board_get_spinand_gpiohighz_info(struct board_pinmux_info *pinmux_info)
  545. {
  546. #if IS_ENABLED(CONFIG_SPINAND_3)
  547. pinmux_info->pins_config = board_spinand_spi3_gpiohighz_config;
  548. pinmux_info->pins_num = ARRAY_SIZE(board_spinand_spi3_gpiohighz_config);
  549. #endif
  550. }
  551. void board_set_ntc_pinmux_info(bool enable, bool use_as_ntc)
  552. {
  553. #if IS_ENABLED(CONFIG_ACTS_BATTERY_NTC)
  554. if (enable) {
  555. if (use_as_ntc)
  556. acts_pinmux_setup_pins(board_ntc_config, ARRAY_SIZE(board_ntc_config));
  557. else
  558. acts_pinmux_setup_pins(board_ntc_ref_config, ARRAY_SIZE(board_ntc_ref_config));
  559. } else {
  560. acts_pinmux_setup_pins(board_ntc_disable_config, ARRAY_SIZE(board_ntc_disable_config));
  561. }
  562. #endif
  563. }
  564. #if IS_ENABLED(CONFIG_PANEL)
  565. static uint32_t lcd_pin_backup[3];
  566. void board_lcd_suspend(bool aod_en, bool early_suspend)
  567. {
  568. if (early_suspend) {
  569. lcd_pin_backup[0] = sys_read32(GPION_CTL(35)); /* lcd te */
  570. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(35));
  571. if (aod_en == false) {
  572. lcd_pin_backup[1] = sys_read32(GPION_CTL(21)); /* lcd power */
  573. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(21));
  574. lcd_pin_backup[2] = sys_read32(GPION_CTL(32)); /* lcd reset */
  575. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(32));
  576. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(30)); /* lcd cs */
  577. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(33)); /* lcd power IOVCC2 */
  578. }
  579. }
  580. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(34)); /* lcd scl */
  581. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(14)); /* lcd d0 */
  582. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(15)); /* lcd d1 */
  583. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(16)); /* lcd d2 */
  584. sys_write32(CONFIG_GPIO_HIGHZ, GPION_CTL(17)); /* lcd d3 */
  585. }
  586. void board_lcd_resume(bool aod_en, bool late_resume)
  587. {
  588. acts_pinmux_setup_pins(board_lcd_pin_config, ARRAY_SIZE(board_lcd_pin_config));
  589. if (late_resume) {
  590. sys_write32(lcd_pin_backup[0], GPION_CTL(35)); /* lcd te */
  591. if (aod_en == false) {
  592. sys_write32(lcd_pin_backup[1], GPION_CTL(21)); /* lcd GND_LEDK */
  593. sys_write32(lcd_pin_backup[2], GPION_CTL(32)); /* lcd reset */
  594. }
  595. }
  596. }
  597. #endif /* CONFIG_PANEL */
  598. SYS_INIT(board_early_init, PRE_KERNEL_1, 5);
  599. SYS_INIT(board_later_init, POST_KERNEL, 5);