edison.c 2.0 KB

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