dragonboard410c.c 4.4 KB

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