dragonboard410c.c 4.4 KB

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