edison.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (c) 2017 Intel Corporation
  4. */
  5. #include <common.h>
  6. #include <dwc3-uboot.h>
  7. #include <env.h>
  8. #include <environment.h>
  9. #include <mmc.h>
  10. #include <u-boot/md5.h>
  11. #include <usb.h>
  12. #include <watchdog.h>
  13. #include <linux/usb/gadget.h>
  14. #include <asm/cache.h>
  15. #include <asm/pmu.h>
  16. #include <asm/scu.h>
  17. #include <asm/u-boot-x86.h>
  18. /* List of Intel Tangier LSSs */
  19. #define PMU_LSS_TANGIER_SDIO0_01 1
  20. int board_early_init_r(void)
  21. {
  22. pmu_turn_power(PMU_LSS_TANGIER_SDIO0_01, true);
  23. return 0;
  24. }
  25. static struct dwc3_device dwc3_device_data = {
  26. .maximum_speed = USB_SPEED_HIGH,
  27. .base = CONFIG_SYS_USB_OTG_BASE,
  28. .dr_mode = USB_DR_MODE_PERIPHERAL,
  29. .index = 0,
  30. };
  31. int usb_gadget_handle_interrupts(int controller_index)
  32. {
  33. dwc3_uboot_handle_interrupt(controller_index);
  34. WATCHDOG_RESET();
  35. return 0;
  36. }
  37. int board_usb_init(int index, enum usb_init_type init)
  38. {
  39. if (index == 0 && init == USB_INIT_DEVICE)
  40. return dwc3_uboot_init(&dwc3_device_data);
  41. return -EINVAL;
  42. }
  43. int board_usb_cleanup(int index, enum usb_init_type init)
  44. {
  45. if (index == 0 && init == USB_INIT_DEVICE) {
  46. dwc3_uboot_exit(index);
  47. return 0;
  48. }
  49. return -EINVAL;
  50. }
  51. static void assign_serial(void)
  52. {
  53. struct mmc *mmc = find_mmc_device(0);
  54. unsigned char ssn[16];
  55. char usb0addr[18];
  56. char serial[33];
  57. int i;
  58. if (!mmc)
  59. return;
  60. md5((unsigned char *)mmc->cid, sizeof(mmc->cid), ssn);
  61. snprintf(usb0addr, sizeof(usb0addr), "02:00:86:%02x:%02x:%02x",
  62. ssn[13], ssn[14], ssn[15]);
  63. env_set("usb0addr", usb0addr);
  64. for (i = 0; i < 16; i++)
  65. snprintf(&serial[2 * i], 3, "%02x", ssn[i]);
  66. env_set("serial#", serial);
  67. #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
  68. env_save();
  69. #endif
  70. }
  71. static void assign_hardware_id(void)
  72. {
  73. struct ipc_ifwi_version v;
  74. char hardware_id[4];
  75. int ret;
  76. ret = scu_ipc_command(IPCMSG_GET_FW_REVISION, 1, NULL, 0, (u32 *)&v, 4);
  77. if (ret < 0)
  78. printf("Can't retrieve hardware revision\n");
  79. snprintf(hardware_id, sizeof(hardware_id), "%02X", v.hardware_id);
  80. env_set("hardware_id", hardware_id);
  81. #if defined(CONFIG_CMD_SAVEENV) && !defined(CONFIG_ENV_IS_NOWHERE)
  82. env_save();
  83. #endif
  84. }
  85. int board_late_init(void)
  86. {
  87. if (!env_get("serial#"))
  88. assign_serial();
  89. if (!env_get("hardware_id"))
  90. assign_hardware_id();
  91. return 0;
  92. }