dragonboard820c.c 3.5 KB

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