edison.c 2.0 KB

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