dragonboard410c.c 4.5 KB

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