Firmware for MNT ZZ9000 graphics and ARM coprocessor card for Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usb.c 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * MNT ZZ9000 Amiga Graphics and Coprocessor Card Operating System (ZZ9000OS)
  3. *
  4. * Copyright (C) 2019, Lukas F. Hartmann <lukas@mntre.com>
  5. * MNT Research GmbH, Berlin
  6. * https://mntre.com
  7. *
  8. * More Info: https://mntre.com/zz9000
  9. *
  10. * SPDX-License-Identifier: GPL-3.0-or-later
  11. * GNU General Public License v3.0 or later
  12. *
  13. * https://spdx.org/licenses/GPL-3.0-or-later.html
  14. *
  15. * Some portions (from example code, weird custom license) Copyright (C) 2010 - 2015 Xilinx, Inc.
  16. *
  17. */
  18. #include <stdio.h>
  19. #include "platform.h"
  20. #include <xil_printf.h>
  21. #include <xil_cache.h>
  22. #include <xil_mmu.h>
  23. #include "sleep.h"
  24. #include "xparameters.h"
  25. #include <xscugic.h>
  26. #include "usb/ehci.h"
  27. #include "usb/usb.h"
  28. #include "ethernet.h"
  29. struct zynq_ehci_priv _zynq_ehci;
  30. /*
  31. * https://www.cypress.com/file/134171/download
  32. * https://elixir.bootlin.com/u-boot/latest/source/common/usb_storage.c#L653
  33. *
  34. * "Enumeration directly follows the device detection, and is the process
  35. of assigning a unique address to a newly attached device. Configuration is the process of determining a device‘s
  36. capabilities by an exchange of device requests. The requests that the host uses to learn about a device are called
  37. standard requests and must support these requests on all USB devices."
  38. */
  39. // returns 1 if storage device available
  40. int zz_usb_init() {
  41. printf("[USB] trying to probe zynq ehci...\n");
  42. ehci_zynq_probe(&_zynq_ehci);
  43. printf("[USB] probed!\n");
  44. usb_init();
  45. printf("[USB] initialized!\n");
  46. if (!usb_stor_scan(1)) {
  47. return 1;
  48. }
  49. return 0;
  50. }
  51. unsigned long zz_usb_read_blocks(int dev_index, unsigned long blknr, unsigned long blkcnt, void *buffer) {
  52. int res = usb_stor_read_direct(dev_index, blknr, blkcnt, buffer);
  53. //printf("[USB] read %lu blocks at %lu: %d\n",blkcnt,blknr,res);
  54. return res;
  55. }
  56. unsigned long zz_usb_write_blocks(int dev_index, unsigned long blknr, unsigned long blkcnt, void *buffer) {
  57. int res = usb_stor_write_direct(dev_index, blknr, blkcnt, buffer);
  58. //printf("[USB] write %lu blocks at %lu: %d\n",blkcnt,blknr,res);
  59. return res;
  60. }
  61. unsigned long zz_usb_storage_capacity(int dev_index) {
  62. unsigned long cap = usb_stor_get_capacity(dev_index);
  63. printf("[USB] get capacity: %lx\n",cap);
  64. return cap;
  65. }