dragonboard820c.c 3.4 KB

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