dragonboard410c.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. #include <environment.h>
  13. #include <asm/arch/dram.h>
  14. #include <asm/arch/misc.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. /* pointer to the device tree ammended by the firmware */
  17. extern void *fw_dtb;
  18. void *board_fdt_blob_setup(void)
  19. {
  20. if (fdt_magic(fw_dtb) != FDT_MAGIC) {
  21. printf("Firmware provided invalid dtb!\n");
  22. return NULL;
  23. }
  24. return fw_dtb;
  25. }
  26. int dram_init(void)
  27. {
  28. gd->ram_size = PHYS_SDRAM_1_SIZE;
  29. return 0;
  30. }
  31. int dram_init_banksize(void)
  32. {
  33. gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
  34. gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
  35. return 0;
  36. }
  37. int board_usb_init(int index, enum usb_init_type init)
  38. {
  39. static struct udevice *pmic_gpio;
  40. static struct gpio_desc hub_reset, usb_sel;
  41. int ret = 0, node;
  42. if (!pmic_gpio) {
  43. ret = uclass_get_device_by_name(UCLASS_GPIO,
  44. "pm8916_gpios@c000",
  45. &pmic_gpio);
  46. if (ret < 0) {
  47. printf("Failed to find pm8916_gpios@c000 node.\n");
  48. return ret;
  49. }
  50. }
  51. /* Try to request gpios needed to start usb host on dragonboard */
  52. if (!dm_gpio_is_valid(&hub_reset)) {
  53. node = fdt_subnode_offset(gd->fdt_blob,
  54. dev_of_offset(pmic_gpio),
  55. "usb_hub_reset_pm");
  56. if (node < 0) {
  57. printf("Failed to find usb_hub_reset_pm dt node.\n");
  58. return node;
  59. }
  60. ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
  61. "gpios", 0, &hub_reset, 0);
  62. if (ret < 0) {
  63. printf("Failed to request usb_hub_reset_pm gpio.\n");
  64. return ret;
  65. }
  66. }
  67. if (!dm_gpio_is_valid(&usb_sel)) {
  68. node = fdt_subnode_offset(gd->fdt_blob,
  69. dev_of_offset(pmic_gpio),
  70. "usb_sw_sel_pm");
  71. if (node < 0) {
  72. printf("Failed to find usb_sw_sel_pm dt node.\n");
  73. return 0;
  74. }
  75. ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
  76. "gpios", 0, &usb_sel, 0);
  77. if (ret < 0) {
  78. printf("Failed to request usb_sw_sel_pm gpio.\n");
  79. return ret;
  80. }
  81. }
  82. if (init == USB_INIT_HOST) {
  83. /* Start USB Hub */
  84. dm_gpio_set_dir_flags(&hub_reset,
  85. GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
  86. mdelay(100);
  87. /* Switch usb to host connectors */
  88. dm_gpio_set_dir_flags(&usb_sel,
  89. GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
  90. mdelay(100);
  91. } else { /* Device */
  92. /* Disable hub */
  93. dm_gpio_set_dir_flags(&hub_reset, GPIOD_IS_OUT);
  94. /* Switch back to device connector */
  95. dm_gpio_set_dir_flags(&usb_sel, GPIOD_IS_OUT);
  96. }
  97. return 0;
  98. }
  99. /* Check for vol- button - if pressed - stop autoboot */
  100. int misc_init_r(void)
  101. {
  102. struct udevice *pon;
  103. struct gpio_desc resin;
  104. int node, ret;
  105. ret = uclass_get_device_by_name(UCLASS_GPIO, "pm8916_pon@800", &pon);
  106. if (ret < 0) {
  107. printf("Failed to find PMIC pon node. Check device tree\n");
  108. return 0;
  109. }
  110. node = fdt_subnode_offset(gd->fdt_blob, dev_of_offset(pon),
  111. "key_vol_down");
  112. if (node < 0) {
  113. printf("Failed to find key_vol_down node. Check device tree\n");
  114. return 0;
  115. }
  116. if (gpio_request_by_name_nodev(offset_to_ofnode(node), "gpios", 0,
  117. &resin, 0)) {
  118. printf("Failed to request key_vol_down button.\n");
  119. return 0;
  120. }
  121. if (dm_gpio_get_value(&resin)) {
  122. env_set("bootdelay", "-1");
  123. env_set("bootcmd", "fastboot 0");
  124. printf("key_vol_down pressed - Starting fastboot.\n");
  125. }
  126. return 0;
  127. }
  128. int board_init(void)
  129. {
  130. return 0;
  131. }
  132. int board_late_init(void)
  133. {
  134. char serial[16];
  135. memset(serial, 0, 16);
  136. snprintf(serial, 13, "%x", msm_board_serial());
  137. env_set("serial#", serial);
  138. return 0;
  139. }
  140. /* Fixup of DTB for Linux Kernel
  141. * 1. Fixup installed DRAM.
  142. * 2. Fixup WLAN/BT Mac address:
  143. * First, check if MAC addresses for WLAN/BT exists as environemnt
  144. * variables wlanaddr,btaddr. if not, generate a unique address.
  145. */
  146. int ft_board_setup(void *blob, bd_t *bd)
  147. {
  148. u8 mac[ARP_HLEN];
  149. msm_fixup_memory(blob);
  150. if (!eth_env_get_enetaddr("wlanaddr", mac)) {
  151. msm_generate_mac_addr(mac);
  152. };
  153. do_fixup_by_compat(blob, "qcom,wcnss-wlan",
  154. "local-mac-address", mac, ARP_HLEN, 1);
  155. if (!eth_env_get_enetaddr("btaddr", mac)) {
  156. msm_generate_mac_addr(mac);
  157. /* The BD address is same as WLAN MAC address but with
  158. * least significant bit flipped.
  159. */
  160. mac[0] ^= 0x01;
  161. };
  162. do_fixup_by_compat(blob, "qcom,wcnss-bt",
  163. "local-bd-address", mac, ARP_HLEN, 1);
  164. return 0;
  165. }
  166. void reset_cpu(ulong addr)
  167. {
  168. psci_system_reset();
  169. }