dragonboard410c.c 4.2 KB

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