dragonboard820c.c 3.4 KB

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