dragonboard410c.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Board init file for Dragonboard 410C
  4. *
  5. * (C) Copyright 2015 Mateusz Kulikowski <mateusz.kulikowski@gmail.com>
  6. */
  7. #include <common.h>
  8. #include <dm.h>
  9. #include <usb.h>
  10. #include <asm/gpio.h>
  11. #include <fdt_support.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. /* pointer to the device tree ammended by the firmware */
  14. extern void *fw_dtb;
  15. void *board_fdt_blob_setup(void)
  16. {
  17. if (fdt_magic(fw_dtb) != FDT_MAGIC) {
  18. printf("Firmware provided invalid dtb!\n");
  19. return NULL;
  20. }
  21. return fw_dtb;
  22. }
  23. int dram_init(void)
  24. {
  25. gd->ram_size = PHYS_SDRAM_1_SIZE;
  26. return 0;
  27. }
  28. int dram_init_banksize(void)
  29. {
  30. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  31. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  32. return 0;
  33. }
  34. int board_prepare_usb(enum usb_init_type type)
  35. {
  36. static struct udevice *pmic_gpio;
  37. static struct gpio_desc hub_reset, usb_sel;
  38. int ret = 0, node;
  39. if (!pmic_gpio) {
  40. ret = uclass_get_device_by_name(UCLASS_GPIO,
  41. "pm8916_gpios@c000",
  42. &pmic_gpio);
  43. if (ret < 0) {
  44. printf("Failed to find pm8916_gpios@c000 node.\n");
  45. return ret;
  46. }
  47. }
  48. /* Try to request gpios needed to start usb host on dragonboard */
  49. if (!dm_gpio_is_valid(&hub_reset)) {
  50. node = fdt_subnode_offset(gd->fdt_blob,
  51. dev_of_offset(pmic_gpio),
  52. "usb_hub_reset_pm");
  53. if (node < 0) {
  54. printf("Failed to find usb_hub_reset_pm dt node.\n");
  55. return node;
  56. }
  57. ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
  58. "gpios", 0, &hub_reset, 0);
  59. if (ret < 0) {
  60. printf("Failed to request usb_hub_reset_pm gpio.\n");
  61. return ret;
  62. }
  63. }
  64. if (!dm_gpio_is_valid(&usb_sel)) {
  65. node = fdt_subnode_offset(gd->fdt_blob,
  66. dev_of_offset(pmic_gpio),
  67. "usb_sw_sel_pm");
  68. if (node < 0) {
  69. printf("Failed to find usb_sw_sel_pm dt node.\n");
  70. return 0;
  71. }
  72. ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
  73. "gpios", 0, &usb_sel, 0);
  74. if (ret < 0) {
  75. printf("Failed to request usb_sw_sel_pm gpio.\n");
  76. return ret;
  77. }
  78. }
  79. if (type == USB_INIT_HOST) {
  80. /* Start USB Hub */
  81. dm_gpio_set_dir_flags(&hub_reset,
  82. GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
  83. mdelay(100);
  84. /* Switch usb to host connectors */
  85. dm_gpio_set_dir_flags(&usb_sel,
  86. GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
  87. mdelay(100);
  88. } else { /* Device */
  89. /* Disable hub */
  90. dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
  91. /* Switch back to device connector */
  92. dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
  93. }
  94. return 0;
  95. }
  96. /* Check for vol- button - if pressed - stop autoboot */
  97. int misc_init_r(void)
  98. {
  99. struct udevice *pon;
  100. struct gpio_desc resin;
  101. int node, ret;
  102. ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
  103. if (ret < 0) {
  104. printf("Failed to find PMIC pon node. Check device tree\n");
  105. return 0;
  106. }
  107. node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
  108. "key_vol_down");
  109. if (node < 0) {
  110. printf("Failed to find key_vol_down node. Check device tree\n");
  111. return 0;
  112. }
  113. if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
  114. &resin, 0)) {
  115. printf("Failed to request key_vol_down button.\n");
  116. return 0;
  117. }
  118. if (dm_gpio_get_value(&resin)) {
  119. env_set("bootdelay", "-1");
  120. printf("Power button pressed - dropping to console.\n");
  121. }
  122. return 0;
  123. }
  124. int board_init(void)
  125. {
  126. return 0;
  127. }
  128. int ft_board_setup(void *blob, bd_t *bd)
  129. {
  130. int offset, len, i;
  131. const char *mac;
  132. struct {
  133. const char *compatible;
  134. const char *property;
  135. } fix[] = {
  136. [0] = {
  137. /* update the kernel's dtb with wlan mac */
  138. .compatible = "qcom,wcnss-wlan",
  139. .property = "local-mac-address",
  140. },
  141. [1] = {
  142. /* update the kernel's dtb with bt mac */
  143. .compatible = "qcom,wcnss-bt",
  144. .property = "local-bd-address",
  145. },
  146. };
  147. for (i = 0; i < sizeof(fix) / sizeof(fix[0]); i++) {
  148. offset = fdt_node_offset_by_compatible(gd->fdt_blob, -1,
  149. fix[i].compatible);
  150. if (offset < 0)
  151. continue;
  152. mac = fdt_getprop(gd->fdt_blob, offset, fix[i].property, &len);
  153. if (mac)
  154. do_fixup_by_compat(blob, fix[i].compatible,
  155. fix[i].property, mac, ARP_HLEN, 1);
  156. }
  157. return 0;
  158. }
  159. void reset_cpu(ulong addr)
  160. {
  161. psci_system_reset();
  162. }