soc.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * Copyright (c) 2016 Open-RnD Sp. z o.o.
  3. * Copyright (c) 2016 Linaro Limited.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0
  6. */
  7. /**
  8. * @file
  9. * @brief System/hardware module for ATJ215X processor
  10. */
  11. #include <device.h>
  12. #include <init.h>
  13. #include <arch/cpu.h>
  14. #include "soc.h"
  15. //#include <arch/arm/aarch32/cortex_m/cmsis.h>
  16. static void jtag_config(unsigned int group_id)
  17. {
  18. printk("jtag switch to group=%d\n", group_id);
  19. if (group_id < 3)
  20. sys_write32((sys_read32(JTAG_CTL) & ~(3 << 0)) | (group_id << 0) | (1 << 4), JTAG_CTL);
  21. }
  22. void jtag_set(void)
  23. {
  24. jtag_config(0);
  25. }
  26. /**
  27. * \brief clear watchdog
  28. */
  29. void soc_watchdog_clear(void)
  30. {
  31. sys_set_bit(WD_CTL, 0);
  32. }
  33. int soc_dvfs_opt(void)
  34. {
  35. return (sys_read32(UID1) >> 17) & 0x7;
  36. }
  37. #define GPION(x) GPIO_REG_CTL(GPIO_REG_BASE, x)
  38. #define GPIO_BSR(x) GPIO_REG_BSR(GPIO_REG_BASE, x)
  39. #define GPIO_BRR(x) GPIO_REG_BRR(GPIO_REG_BASE, x)
  40. #define GPIO_IDATA(x) GPIO_REG_IDAT(GPIO_REG_BASE, x)
  41. int check_adfu_connect(unsigned int gpio_in, unsigned int gpio_out)
  42. {
  43. unsigned int checksum, org_checksum = 0x55aa55aa;
  44. unsigned int rdat, sumdat = 0;
  45. unsigned int gpio_rx_bak, gpio_tx_bak, i;
  46. printk("check txrx adfu\n");
  47. gpio_rx_bak= sys_read32(GPION(gpio_in));
  48. gpio_tx_bak= sys_read32(GPION(gpio_out));
  49. /* RX - INPUT */
  50. sys_write32(0x3880, GPION(gpio_in));
  51. /* TX - OUTPUT */
  52. sys_write32(0x3840, GPION(gpio_out));
  53. checksum = org_checksum;
  54. for (i = 0; i < 32; i++) {
  55. /* write data */
  56. if(checksum & 0x1){
  57. sys_write32(GPIO_BIT(gpio_out), GPIO_BSR(gpio_out));
  58. }else{
  59. sys_write32(GPIO_BIT(gpio_out), GPIO_BRR(gpio_out));
  60. }
  61. soc_udelay(500);
  62. /* read data */
  63. if(sys_read32(GPIO_IDATA(gpio_in)) & GPIO_BIT(gpio_in))
  64. rdat = 1;
  65. else
  66. rdat = 0;
  67. sumdat |= (rdat << i);
  68. checksum >>= 1;
  69. }
  70. sys_write32(gpio_rx_bak, GPION(gpio_in));
  71. sys_write32(gpio_tx_bak, GPION(gpio_out));
  72. if (org_checksum == sumdat){
  73. printk("txrx enter adfu\n");
  74. return 1;/*enter adfu*/
  75. }
  76. return 0;
  77. }
  78. int check_adfu_gpiokey(unsigned int gpio)
  79. {
  80. int ret;
  81. unsigned int gpio_bak;
  82. if(gpio >= GPIO_MAX_PIN_NUM)
  83. return 0;
  84. printk("check gpio adfu\n");
  85. gpio_bak= sys_read32(GPION(gpio));
  86. /* INPUT */
  87. sys_write32(0x3880, GPION(gpio));
  88. k_busy_wait(10);
  89. if(sys_read32(GPIO_IDATA(gpio)) & GPIO_BIT(gpio)){
  90. ret = 0;
  91. }else{
  92. printk("gpio key enter adfu\n");
  93. ret = 1;
  94. }
  95. sys_write32(gpio_bak, GPION(gpio));
  96. return ret;
  97. }
  98. /**
  99. * @brief Perform basic hardware initialization at boot.
  100. *
  101. * This needs to be run from the very beginning.
  102. * So the init priority has to be 0 (zero).
  103. *
  104. * @return 0
  105. */
  106. static int leopard_init(const struct device *arg)
  107. {
  108. uint32_t key;
  109. ARG_UNUSED(arg);
  110. key = irq_lock();
  111. /* Install default handler that simply resets the CPU
  112. * if configured in the kernel, NOP otherwise
  113. */
  114. NMI_INIT();
  115. irq_unlock(key);
  116. sys_write32(0x10e, CMU_GPUCLK);//COREPLL/1.5
  117. acts_clock_peripheral_enable(CLOCK_ID_GPU); //for the gpu reset, because the gpu is in an unstable state
  118. soc_udelay(1);
  119. acts_reset_peripheral_deassert(RESET_ID_GPU);
  120. soc_udelay(1);
  121. acts_reset_peripheral_assert(RESET_ID_GPU);//
  122. soc_udelay(2);
  123. acts_clock_peripheral_disable(CLOCK_ID_GPU);//
  124. /* disable gpu power gating */
  125. sys_write32(sys_read32(PWRGATE_DIG) & ~(0x1 << 25), PWRGATE_DIG);
  126. /* Update CMSIS SystemCoreClock variable (HCLK) */
  127. /* At reset, system core clock is set to 16 MHz from HSI */
  128. //SystemCoreClock = 16000000;
  129. //while(!arg);
  130. /*for lowpower*/
  131. //sys_write32(0x30F, SPI1_CLKGATING);
  132. /* init ppi */
  133. ppi_init();
  134. /* Initialize SDMA */
  135. acts_reset_peripheral_assert(RESET_ID_SDMA);
  136. acts_clock_peripheral_enable(CLOCK_ID_SDMA);
  137. acts_reset_peripheral_deassert(RESET_ID_SDMA);
  138. /* Enable SDMA, DE access SPI0 NOR and SPI1 PSRAM, and GPU accessing SPI1 PSRAM */
  139. sys_write32(sys_read32(SPICACHE_CTL) | BIT(10) | BIT(11), SPICACHE_CTL);
  140. sys_write32(sys_read32(SPI1_CACHE_CTL) | BIT(8) | BIT(10) | BIT(11) | BIT(14) /*| BIT(15)*/, SPI1_CACHE_CTL);
  141. sys_write32(BIT(24) | (0<<4) | (0xa<<8) | (0x1<<0), SPI1_GPU_CTL);
  142. return 0;
  143. }
  144. SYS_INIT(leopard_init, PRE_KERNEL_1, 0);