dragonboard820c.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board init file for Dragonboard 820C
  4. *
  5. * (C) Copyright 2017 Jorge Ramirez-Ortiz <jorge.ramirez-ortiz@linaro.org>
  6. */
  7. #include <cpu_func.h>
  8. #include <init.h>
  9. #include <asm/arch/sysmap-apq8096.h>
  10. #include <env.h>
  11. #include <asm/cache.h>
  12. #include <linux/arm-smccc.h>
  13. #include <linux/psci.h>
  14. #include <common.h>
  15. #include <dm.h>
  16. #include <asm/io.h>
  17. #include <linux/bitops.h>
  18. #include <asm/psci.h>
  19. #include <asm/gpio.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. int dram_init(void)
  22. {
  23. gd->ram_size = PHYS_SDRAM_SIZE;
  24. return 0;
  25. }
  26. int dram_init_banksize(void)
  27. {
  28. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  29. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  30. gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
  31. gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
  32. return 0;
  33. }
  34. static void sdhci_power_init(void)
  35. {
  36. const u32 TLMM_PULL_MASK = 0x3;
  37. const u32 TLMM_HDRV_MASK = 0x7;
  38. struct tlmm_cfg {
  39. u32 bit; /* bit in the register */
  40. u8 mask; /* mask clk/dat/cmd control */
  41. u8 val;
  42. };
  43. /* bit offsets in the sdc tlmm register */
  44. enum { SDC1_DATA_HDRV = 0,
  45. SDC1_CMD_HDRV = 3,
  46. SDC1_CLK_HDRV = 6,
  47. SDC1_DATA_PULL = 9,
  48. SDC1_CMD_PULL = 11,
  49. SDC1_CLK_PULL = 13,
  50. SDC1_RCLK_PULL = 15,
  51. };
  52. enum { TLMM_PULL_DOWN = 0x1,
  53. TLMM_PULL_UP = 0x3,
  54. TLMM_NO_PULL = 0x0,
  55. };
  56. enum { TLMM_CUR_VAL_10MA = 0x04,
  57. TLMM_CUR_VAL_16MA = 0x07,
  58. };
  59. int i;
  60. /* drive strength configs for sdhc pins */
  61. const struct tlmm_cfg hdrv[] = {
  62. { SDC1_CLK_HDRV, TLMM_CUR_VAL_16MA, TLMM_HDRV_MASK, },
  63. { SDC1_CMD_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
  64. { SDC1_DATA_HDRV, TLMM_CUR_VAL_10MA, TLMM_HDRV_MASK, },
  65. };
  66. /* pull configs for sdhc pins */
  67. const struct tlmm_cfg pull[] = {
  68. { SDC1_CLK_PULL, TLMM_NO_PULL, TLMM_PULL_MASK, },
  69. { SDC1_CMD_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
  70. { SDC1_DATA_PULL, TLMM_PULL_UP, TLMM_PULL_MASK, },
  71. };
  72. const struct tlmm_cfg rclk[] = {
  73. { SDC1_RCLK_PULL, TLMM_PULL_DOWN, TLMM_PULL_MASK,},
  74. };
  75. for (i = 0; i < ARRAY_SIZE(hdrv); i++)
  76. clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
  77. hdrv[i].mask << hdrv[i].bit,
  78. hdrv[i].val << hdrv[i].bit);
  79. for (i = 0; i < ARRAY_SIZE(pull); i++)
  80. clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
  81. pull[i].mask << pull[i].bit,
  82. pull[i].val << pull[i].bit);
  83. for (i = 0; i < ARRAY_SIZE(rclk); i++)
  84. clrsetbits_le32(SDC1_HDRV_PULL_CTL_REG,
  85. rclk[i].mask << rclk[i].bit,
  86. rclk[i].val << rclk[i].bit);
  87. }
  88. static void show_psci_version(void)
  89. {
  90. struct arm_smccc_res res;
  91. arm_smccc_smc(ARM_PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0, 0, 0, 0, 0, &res);
  92. printf("PSCI: v%ld.%ld\n",
  93. PSCI_VERSION_MAJOR(res.a0),
  94. PSCI_VERSION_MINOR(res.a0));
  95. }
  96. int board_init(void)
  97. {
  98. sdhci_power_init();
  99. show_psci_version();
  100. return 0;
  101. }
  102. void reset_cpu(ulong addr)
  103. {
  104. psci_system_reset();
  105. }
  106. /* Check for vol- button - if pressed - stop autoboot */
  107. int misc_init_r(void)
  108. {
  109. struct udevice *pon;
  110. struct gpio_desc resin;
  111. int node, ret;
  112. ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8994_pon@800", &pon);
  113. if (ret < 0) {
  114. printf("Failed to find PMIC pon node. Check device tree\n");
  115. return 0;
  116. }
  117. node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
  118. "key_vol_down");
  119. if (node < 0) {
  120. printf("Failed to find key_vol_down node. Check device tree\n");
  121. return 0;
  122. }
  123. if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
  124. &resin, 0)) {
  125. printf("Failed to request key_vol_down button.\n");
  126. return 0;
  127. }
  128. if (dm_gpio_get_value(&resin)) {
  129. env_set("bootdelay", "-1");
  130. printf("Power button pressed - dropping to console.\n");
  131. }
  132. return 0;
  133. }