edison.c 2.2 KB

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