edison.c 2.1 KB

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