dragonboard820c.c 3.5 KB

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